Skip to content

Commit 3fee474

Browse files
authored
Merge pull request #1079 from Patternslib/ploneconf-sprint
Cleanup from the Ploneconf Sprint
2 parents 7bc7848 + 1654421 commit 3fee474

12 files changed

+553
-674
lines changed

jest.config.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ const path = require("path");
22
const config = require("@patternslib/dev/jest.config.js");
33

44
config.setupFilesAfterEnv.push(path.resolve(__dirname, "./src/setup-tests.js"));
5-
config.moduleNameMapper["@patternslib/patternslib/(.*)"] = "<rootDir>/$1";
5+
config.moduleNameMapper["@patternslib/patternslib/(.*)"] =
6+
path.resolve(__dirname) + "/$1";
67

78
module.exports = config;

package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,10 @@
2222
"jquery": "^3.6.1",
2323
"jquery-jcrop": "^0.9.13",
2424
"luxon": "2.4.0",
25-
"marked": "^4.1.0",
25+
"marked": "^4.1.1",
2626
"masonry-layout": "^4.2.2",
2727
"moment": "^2.29.4",
28-
"moment-timezone": "^0.5.37",
28+
"moment-timezone": "^0.5.38",
2929
"photoswipe": "^4.1.3",
3030
"pikaday": "^1.8.0",
3131
"prettier": "^2.7.1",
@@ -43,7 +43,7 @@
4343
"whatwg-fetch": "^3.4.0"
4444
},
4545
"devDependencies": {
46-
"@patternslib/dev": "^2.7.2",
46+
"@patternslib/dev": "^3.0.0",
4747
"@patternslib/pat-content-mirror": "^3.0.0",
4848
"@patternslib/pat-doclock": "^3.0.0",
4949
"@patternslib/pat-shopping-cart": "^3.0.0",

src/core/dom.js

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,18 @@ const show = (el) => {
8080
delete el[DATA_STYLE_DISPLAY];
8181
};
8282

83+
/**
84+
* Test, if a element is visible or not.
85+
*
86+
* @param {Node} el - The DOM node to test.
87+
* @returns {Boolean} - True if the element is visible.
88+
*/
89+
const is_visible = (el) => {
90+
// Check, if element is visible in DOM.
91+
// https://stackoverflow.com/a/19808107/1337474
92+
return el.offsetWidth > 0 && el.offsetHeight > 0;
93+
};
94+
8395
/**
8496
* Return all direct parents of ``el`` matching ``selector``.
8597
* This matches against all parents but not the element itself.
@@ -169,12 +181,6 @@ const acquire_attribute = (
169181
}
170182
};
171183

172-
const is_visible = (el) => {
173-
// Check, if element is visible in DOM.
174-
// https://stackoverflow.com/a/19808107/1337474
175-
return el.offsetWidth > 0 && el.offsetHeight > 0;
176-
};
177-
178184
/**
179185
* Return a DocumentFragment from a given string.
180186
*

src/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// Webpack entry point for module federation.
2-
import "../webpack/module_federation";
2+
import "@patternslib/dev/webpack/module_federation";
33
// The next import needs to be kept with parentheses, otherwise we get this error:
44
// "Shared module is not available for eager consumption."
55
import("./patterns");

src/pat/clone-code/clone-code.test.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@ describe("pat-clone-code", () => {
3737
new Pattern(el);
3838
await utils.timeout(1); // wait a tick for async to settle.
3939

40-
console.log(document.body.innerHTML);
4140
const _el = document.body.querySelector(
4241
".pat-clone-code pre code.language-html"
4342
);
@@ -66,7 +65,6 @@ describe("pat-clone-code", () => {
6665
".pat-clone-code pre code.language-html"
6766
);
6867
expect(_el).toBeTruthy();
69-
console.log(document.body.innerHTML);
7068
expect(_el.textContent.trim()).toBe(`<div>
7169
<div>1</div>
7270

src/pat/inject/inject.test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ describe("pat-inject", function () {
6969

7070
expect($div.hasClass("injecting")).toBeTruthy();
7171

72-
answer("<html><body>" + '<div id="someid">repl</div>' + "</body></html>");
72+
answer(`<html><body><div id="someid">repl</div></body></html>`);
7373
await utils.timeout(1); // wait a tick for async to settle.
7474
expect($div.hasClass("injecting")).toBeFalsy();
7575
expect(callback).toHaveBeenCalled();

src/pat/validation/validation.test.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1071,7 +1071,6 @@ describe("pat-validation", function () {
10711071
await utils.timeout(1); // wait a tick for async to settle.
10721072
expect(el.querySelectorAll("em.warning").length).toBe(2);
10731073

1074-
console.log(document.body.innerHTML);
10751074
expect(el.querySelectorAll("em.warning")[0].textContent).toBe(
10761075
"The date must be before woo date"
10771076
);
@@ -1113,7 +1112,6 @@ describe("pat-validation", function () {
11131112
await utils.timeout(1); // wait a tick for async to settle.
11141113
expect(el.querySelectorAll("em.warning").length).toBe(2);
11151114

1116-
console.log(document.body.innerHTML);
11171115
expect(el.querySelectorAll("em.warning")[0].textContent).toBe(
11181116
"The date must be before date2"
11191117
);

src/setup-tests.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,12 @@
33
import jquery from "jquery";
44
global.$ = global.jQuery = jquery;
55

6+
jquery.expr.pseudos.visible = function () {
7+
// Fix jQuery ":visible" selector always returns false in JSDOM.
8+
// https://github.com/jsdom/jsdom/issues/1048#issuecomment-401599392
9+
return true;
10+
};
11+
612
// Do not output error messages
713
import logging from "./core/logging";
814
logging.setLevel(50);
@@ -12,5 +18,5 @@ logging.setLevel(50);
1218
// simply on el.hidden.
1319
import dom from "./core/dom";
1420
dom.is_visible = (el) => {
15-
return !el.hidden;
21+
return !el.hidden && el.style.display !== "none";
1622
};
Lines changed: 1 addition & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -1,40 +1 @@
1-
// Author: Manfred Steyer <[email protected]>
2-
// Author: Johannes Raggam <[email protected]>
3-
4-
// From:
5-
// https://github.com/manfredsteyer/plugin-demo.git
6-
// https://github.com/thet/module-federation-minimaltest.git
7-
8-
/**
9-
* Load remote module / bundle.
10-
*
11-
* Wrapper around webpack runtime API
12-
*
13-
* Usage: get_container("bundle-name-xyz")
14-
*
15-
* @param {string} remote - the remote global name
16-
* @returns {Promise<object>} - Federated Module Container
17-
*/
18-
const container_map = {};
19-
let is_default_scope_initialized = false;
20-
21-
export default async function get_container(remote) {
22-
const container = window[remote];
23-
24-
// Do we still need to initialize the remote?
25-
if (container_map[remote]) {
26-
return container;
27-
}
28-
29-
// Do we still need to initialize the shared scope?
30-
if (!is_default_scope_initialized) {
31-
await __webpack_init_sharing__("default"); // eslint-disable-line no-undef
32-
is_default_scope_initialized = true;
33-
}
34-
35-
await container.init(__webpack_share_scopes__.default); // eslint-disable-line no-undef
36-
37-
// Remember that the container has been initialized.
38-
container_map[remote] = true;
39-
return container;
40-
}
1+
export { get_container } from "@patternslib/dev/webpack/module_federation--dynamic-federation";
Lines changed: 1 addition & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -1,71 +1 @@
1-
// Author: ScriptedAlchemy <[email protected]>
2-
// Author: Johannes Raggam <[email protected]>
3-
4-
// From:
5-
// https://twitter.com/ScriptedAlchemy/status/1505135006158532612
6-
// https://gist.github.com/ScriptedAlchemy/3a24008ef60adc47fad1af7d3299a063
7-
// https://github.com/module-federation/module-federation-examples/blob/master/dynamic-system-host/app1/src/utils/getOrLoadRemote.js
8-
9-
/**
10-
* Load remote module / bundle.
11-
*
12-
* Usage: get_container("bundle-name-xyz", "default", "http://theRemote.com")
13-
*
14-
*
15-
* @param {string} remote - the remote global name
16-
* @param {string} share_scope - the scope key
17-
* @param {string} remote_fallback_url - fallback url for remote module
18-
* @returns {Promise<object>} - Federated Module Container
19-
*/
20-
export default function get_container(
21-
remote,
22-
share_scope = "default",
23-
remote_fallback_url = undefined
24-
) {
25-
new Promise((resolve, reject) => {
26-
if (!window[remote]) {
27-
// Remote not yet globally available.
28-
29-
// onload hook when Module Federated resource is loaded.
30-
const onload = async () => {
31-
// When remote is loaded, initialize it if it wasn't already.
32-
if (!window[remote].__initialized) {
33-
await window[remote].init(__webpack_share_scopes__[share_scope]); // eslint-disable-line no-undef
34-
// Mark remote as initialized.
35-
window[remote].__initialized = true;
36-
}
37-
// Resolve promise so marking remote as loaded.
38-
resolve(window[remote]);
39-
};
40-
41-
// Search dom to see if the remote exists as script tag.
42-
// It might still be loading (async).
43-
const existing_remote = document.querySelector(`[data-webpack="${remote}"]`);
44-
45-
if (existing_remote) {
46-
// If remote exists but was not loaded, hook into its onload
47-
// and wait for it to be ready.
48-
existing_remote.onload = onload;
49-
existing_remote.onerror = reject;
50-
} else if (remote_fallback_url) {
51-
// Inject remote if a fallback exists and call the same onload
52-
// function
53-
const script = document.createElement("script");
54-
script.type = "text/javascript";
55-
// Mark as data-webpack so runtime can track it internally.
56-
script.setAttribute("data-webpack", `${remote}`);
57-
script.async = true;
58-
script.onerror = reject;
59-
script.onload = onload;
60-
script.src = remote_fallback_url;
61-
document.getElementsByTagName("head")[0].appendChild(script);
62-
} else {
63-
// No remote and no fallback exist, reject.
64-
reject(`Cannot Find Remote ${remote} to inject`);
65-
}
66-
} else {
67-
// Remote already instantiated, resolve
68-
resolve(window[remote]);
69-
}
70-
});
71-
}
1+
export { get_container } from "@patternslib/dev/webpack/module_federation--getOrLoadRemote";

0 commit comments

Comments
 (0)