@domql/element 3.0.1 → 3.0.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/create.js +0 -13
- package/dist/cjs/create.js +0 -9
- package/dist/cjs/mixins/classList.js +5 -6
- package/dist/cjs/mixins/registry.js +2 -2
- package/dist/cjs/set.js +1 -1
- package/dist/esm/create.js +0 -10
- package/dist/esm/mixins/classList.js +5 -6
- package/dist/esm/mixins/registry.js +3 -3
- package/dist/esm/set.js +1 -1
- package/mixins/classList.js +5 -6
- package/mixins/registry.js +3 -3
- package/package.json +8 -8
- package/set.js +1 -1
- package/dist/cjs/__tests__/checkIfOnUpdate.test.js +0 -73
- package/dist/cjs/__tests__/children.test.js +0 -177
- package/dist/cjs/__tests__/define.test.js +0 -75
- package/dist/cjs/__tests__/inheritStateUpdates.test.js +0 -62
- package/dist/cjs/__tests__/renderElement.test.js +0 -138
- package/dist/cjs/__tests__/resetElement.test.js +0 -35
- package/dist/cjs/__tests__/set.test.js +0 -256
- package/dist/cjs/__tests__/throughExecProps.test.js +0 -62
- package/dist/cjs/__tests__/throughInitialDefine.test.js +0 -79
- package/dist/cjs/__tests__/throughInitialExec.test.js +0 -73
- package/dist/cjs/__tests__/throughUpdatedDefine.test.js +0 -69
- package/dist/cjs/__tests__/throughUpdatedExec.test.js +0 -84
- package/dist/cjs/__tests__/tree.test.js +0 -11
- package/dist/cjs/__tests__/update.test.js +0 -219
- package/dist/esm/__tests__/checkIfOnUpdate.test.js +0 -73
- package/dist/esm/__tests__/children.test.js +0 -177
- package/dist/esm/__tests__/define.test.js +0 -53
- package/dist/esm/__tests__/inheritStateUpdates.test.js +0 -62
- package/dist/esm/__tests__/renderElement.test.js +0 -116
- package/dist/esm/__tests__/resetElement.test.js +0 -35
- package/dist/esm/__tests__/set.test.js +0 -256
- package/dist/esm/__tests__/throughExecProps.test.js +0 -62
- package/dist/esm/__tests__/throughInitialDefine.test.js +0 -79
- package/dist/esm/__tests__/throughInitialExec.test.js +0 -73
- package/dist/esm/__tests__/throughUpdatedDefine.test.js +0 -69
- package/dist/esm/__tests__/throughUpdatedExec.test.js +0 -84
- package/dist/esm/__tests__/tree.test.js +0 -11
- package/dist/esm/__tests__/update.test.js +0 -219
package/create.js
CHANGED
|
@@ -16,7 +16,6 @@ import {
|
|
|
16
16
|
OPTIONS,
|
|
17
17
|
initProps,
|
|
18
18
|
createIfConditionFlag,
|
|
19
|
-
deepClone,
|
|
20
19
|
createRoot
|
|
21
20
|
} from '@domql/utils'
|
|
22
21
|
|
|
@@ -50,16 +49,8 @@ export const create = async (
|
|
|
50
49
|
|
|
51
50
|
createRoot(element, parent) // Call createRoot after addCaching
|
|
52
51
|
|
|
53
|
-
if (element.key === 'BannerHgroup') {
|
|
54
|
-
console.warn(deepClone(element))
|
|
55
|
-
}
|
|
56
|
-
|
|
57
52
|
applyExtends(element, parent, options)
|
|
58
53
|
|
|
59
|
-
if (element.key === 'BannerHgroup') {
|
|
60
|
-
console.warn(deepClone(element))
|
|
61
|
-
}
|
|
62
|
-
|
|
63
54
|
propertizeElement(element, parent)
|
|
64
55
|
|
|
65
56
|
await triggerEventOn('start', element, options)
|
|
@@ -68,10 +59,6 @@ export const create = async (
|
|
|
68
59
|
return onlyResolveExtends(element, parent, key, options)
|
|
69
60
|
}
|
|
70
61
|
|
|
71
|
-
if (element.key === 'BannerHgroup') {
|
|
72
|
-
console.warn(element)
|
|
73
|
-
}
|
|
74
|
-
|
|
75
62
|
resetOptions(element, parent, options)
|
|
76
63
|
|
|
77
64
|
addMethods(element, parent, options)
|
package/dist/cjs/create.js
CHANGED
|
@@ -39,21 +39,12 @@ const create = async (props, parentEl, passedKey, options = import_utils.OPTIONS
|
|
|
39
39
|
if (!element) return;
|
|
40
40
|
const { key, parent, __ref: ref } = element;
|
|
41
41
|
(0, import_utils.createRoot)(element, parent);
|
|
42
|
-
if (element.key === "BannerHgroup") {
|
|
43
|
-
console.warn((0, import_utils.deepClone)(element));
|
|
44
|
-
}
|
|
45
42
|
(0, import_utils.applyExtends)(element, parent, options);
|
|
46
|
-
if (element.key === "BannerHgroup") {
|
|
47
|
-
console.warn((0, import_utils.deepClone)(element));
|
|
48
|
-
}
|
|
49
43
|
(0, import_utils.propertizeElement)(element, parent);
|
|
50
44
|
await (0, import_event.triggerEventOn)("start", element, options);
|
|
51
45
|
if (options.onlyResolveExtends) {
|
|
52
46
|
return onlyResolveExtends(element, parent, key, options);
|
|
53
47
|
}
|
|
54
|
-
if (element.key === "BannerHgroup") {
|
|
55
|
-
console.warn(element);
|
|
56
|
-
}
|
|
57
48
|
resetOptions(element, parent, options);
|
|
58
49
|
(0, import_set.addMethods)(element, parent, options);
|
|
59
50
|
(0, import_utils.createScope)(element, parent);
|
|
@@ -29,9 +29,9 @@ module.exports = __toCommonJS(classList_exports);
|
|
|
29
29
|
var import_utils = require("@domql/utils");
|
|
30
30
|
const assignKeyAsClassname = (element) => {
|
|
31
31
|
const { key } = element;
|
|
32
|
-
if (element.
|
|
33
|
-
else if (!element.
|
|
34
|
-
element.
|
|
32
|
+
if (element.classlist === true) element.classlist = key;
|
|
33
|
+
else if (!element.classlist && typeof key === "string" && key.charAt(0) === "_" && key.charAt(1) !== "_") {
|
|
34
|
+
element.classlist = key.slice(1);
|
|
35
35
|
}
|
|
36
36
|
};
|
|
37
37
|
const classify = (obj, element) => {
|
|
@@ -49,11 +49,10 @@ const classify = (obj, element) => {
|
|
|
49
49
|
const classList = (params, element) => {
|
|
50
50
|
if (!params) return;
|
|
51
51
|
const { key } = element;
|
|
52
|
-
if (params === true) params = element.
|
|
53
|
-
if ((0, import_utils.isString)(params)) params = element.
|
|
52
|
+
if (params === true) params = element.classlist = { key };
|
|
53
|
+
if ((0, import_utils.isString)(params)) params = element.classlist = { default: params };
|
|
54
54
|
if ((0, import_utils.isObject)(params)) params = classify(params, element);
|
|
55
55
|
const className = params.replace(/\s+/g, " ").trim();
|
|
56
|
-
if (element.ref) element.ref.class = className;
|
|
57
56
|
return className;
|
|
58
57
|
};
|
|
59
58
|
const applyClassListOnNode = (params, element, node) => {
|
|
@@ -42,11 +42,11 @@ var import_style = __toESM(require("./style.js"), 1);
|
|
|
42
42
|
var import_text = __toESM(require("./text.js"), 1);
|
|
43
43
|
const REGISTRY = {
|
|
44
44
|
attr: import_attr.default,
|
|
45
|
-
|
|
45
|
+
styles: import_style.default,
|
|
46
46
|
text: import_text.default,
|
|
47
47
|
html: import_html.default,
|
|
48
48
|
data: import_data.default,
|
|
49
|
-
|
|
49
|
+
classlist: import_classList.classList,
|
|
50
50
|
state: import_state.default,
|
|
51
51
|
scope: import_scope.default,
|
|
52
52
|
deps: (param, el) => param || el.parent.deps,
|
package/dist/cjs/set.js
CHANGED
|
@@ -77,7 +77,7 @@ const updateContent = async function(params, opts) {
|
|
|
77
77
|
async function setContent(param, element, opts) {
|
|
78
78
|
const content = await (0, import_utils.execPromise)(param, element);
|
|
79
79
|
if (content && element) {
|
|
80
|
-
set.call(element, content, opts);
|
|
80
|
+
await set.call(element, content, opts);
|
|
81
81
|
}
|
|
82
82
|
}
|
|
83
83
|
const removeContent = function(el, opts = {}) {
|
package/dist/esm/create.js
CHANGED
|
@@ -13,7 +13,6 @@ import {
|
|
|
13
13
|
OPTIONS,
|
|
14
14
|
initProps,
|
|
15
15
|
createIfConditionFlag,
|
|
16
|
-
deepClone,
|
|
17
16
|
createRoot
|
|
18
17
|
} from "@domql/utils";
|
|
19
18
|
import { applyAnimationFrame, triggerEventOn } from "@domql/event";
|
|
@@ -30,21 +29,12 @@ const create = async (props, parentEl, passedKey, options = OPTIONS.create || {}
|
|
|
30
29
|
if (!element) return;
|
|
31
30
|
const { key, parent, __ref: ref } = element;
|
|
32
31
|
createRoot(element, parent);
|
|
33
|
-
if (element.key === "BannerHgroup") {
|
|
34
|
-
console.warn(deepClone(element));
|
|
35
|
-
}
|
|
36
32
|
applyExtends(element, parent, options);
|
|
37
|
-
if (element.key === "BannerHgroup") {
|
|
38
|
-
console.warn(deepClone(element));
|
|
39
|
-
}
|
|
40
33
|
propertizeElement(element, parent);
|
|
41
34
|
await triggerEventOn("start", element, options);
|
|
42
35
|
if (options.onlyResolveExtends) {
|
|
43
36
|
return onlyResolveExtends(element, parent, key, options);
|
|
44
37
|
}
|
|
45
|
-
if (element.key === "BannerHgroup") {
|
|
46
|
-
console.warn(element);
|
|
47
|
-
}
|
|
48
38
|
resetOptions(element, parent, options);
|
|
49
39
|
addMethods(element, parent, options);
|
|
50
40
|
createScope(element, parent);
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { exec, isObject, isString } from "@domql/utils";
|
|
2
2
|
const assignKeyAsClassname = (element) => {
|
|
3
3
|
const { key } = element;
|
|
4
|
-
if (element.
|
|
5
|
-
else if (!element.
|
|
6
|
-
element.
|
|
4
|
+
if (element.classlist === true) element.classlist = key;
|
|
5
|
+
else if (!element.classlist && typeof key === "string" && key.charAt(0) === "_" && key.charAt(1) !== "_") {
|
|
6
|
+
element.classlist = key.slice(1);
|
|
7
7
|
}
|
|
8
8
|
};
|
|
9
9
|
const classify = (obj, element) => {
|
|
@@ -21,11 +21,10 @@ const classify = (obj, element) => {
|
|
|
21
21
|
const classList = (params, element) => {
|
|
22
22
|
if (!params) return;
|
|
23
23
|
const { key } = element;
|
|
24
|
-
if (params === true) params = element.
|
|
25
|
-
if (isString(params)) params = element.
|
|
24
|
+
if (params === true) params = element.classlist = { key };
|
|
25
|
+
if (isString(params)) params = element.classlist = { default: params };
|
|
26
26
|
if (isObject(params)) params = classify(params, element);
|
|
27
27
|
const className = params.replace(/\s+/g, " ").trim();
|
|
28
|
-
if (element.ref) element.ref.class = className;
|
|
29
28
|
return className;
|
|
30
29
|
};
|
|
31
30
|
const applyClassListOnNode = (params, element, node) => {
|
|
@@ -4,15 +4,15 @@ import data from "./data.js";
|
|
|
4
4
|
import html from "./html.js";
|
|
5
5
|
import scope from "./scope.js";
|
|
6
6
|
import state from "./state.js";
|
|
7
|
-
import
|
|
7
|
+
import styles from "./style.js";
|
|
8
8
|
import text from "./text.js";
|
|
9
9
|
const REGISTRY = {
|
|
10
10
|
attr,
|
|
11
|
-
|
|
11
|
+
styles,
|
|
12
12
|
text,
|
|
13
13
|
html,
|
|
14
14
|
data,
|
|
15
|
-
|
|
15
|
+
classlist: classList,
|
|
16
16
|
state,
|
|
17
17
|
scope,
|
|
18
18
|
deps: (param, el) => param || el.parent.deps,
|
package/dist/esm/set.js
CHANGED
|
@@ -47,7 +47,7 @@ const updateContent = async function(params, opts) {
|
|
|
47
47
|
async function setContent(param, element, opts) {
|
|
48
48
|
const content = await execPromise(param, element);
|
|
49
49
|
if (content && element) {
|
|
50
|
-
set.call(element, content, opts);
|
|
50
|
+
await set.call(element, content, opts);
|
|
51
51
|
}
|
|
52
52
|
}
|
|
53
53
|
const removeContent = function(el, opts = {}) {
|
package/mixins/classList.js
CHANGED
|
@@ -4,14 +4,14 @@ import { exec, isObject, isString } from '@domql/utils'
|
|
|
4
4
|
|
|
5
5
|
export const assignKeyAsClassname = element => {
|
|
6
6
|
const { key } = element
|
|
7
|
-
if (element.
|
|
7
|
+
if (element.classlist === true) element.classlist = key
|
|
8
8
|
else if (
|
|
9
|
-
!element.
|
|
9
|
+
!element.classlist &&
|
|
10
10
|
typeof key === 'string' &&
|
|
11
11
|
key.charAt(0) === '_' &&
|
|
12
12
|
key.charAt(1) !== '_'
|
|
13
13
|
) {
|
|
14
|
-
element.
|
|
14
|
+
element.classlist = key.slice(1)
|
|
15
15
|
}
|
|
16
16
|
}
|
|
17
17
|
|
|
@@ -32,12 +32,11 @@ export const classify = (obj, element) => {
|
|
|
32
32
|
export const classList = (params, element) => {
|
|
33
33
|
if (!params) return
|
|
34
34
|
const { key } = element
|
|
35
|
-
if (params === true) params = element.
|
|
36
|
-
if (isString(params)) params = element.
|
|
35
|
+
if (params === true) params = element.classlist = { key }
|
|
36
|
+
if (isString(params)) params = element.classlist = { default: params }
|
|
37
37
|
if (isObject(params)) params = classify(params, element)
|
|
38
38
|
// TODO: fails on string
|
|
39
39
|
const className = params.replace(/\s+/g, ' ').trim()
|
|
40
|
-
if (element.ref) element.ref.class = className // TODO: this check is NOT needed in new DOMQL
|
|
41
40
|
return className
|
|
42
41
|
}
|
|
43
42
|
|
package/mixins/registry.js
CHANGED
|
@@ -6,16 +6,16 @@ import data from './data.js'
|
|
|
6
6
|
import html from './html.js'
|
|
7
7
|
import scope from './scope.js'
|
|
8
8
|
import state from './state.js'
|
|
9
|
-
import
|
|
9
|
+
import styles from './style.js'
|
|
10
10
|
import text from './text.js'
|
|
11
11
|
|
|
12
12
|
export const REGISTRY = {
|
|
13
13
|
attr,
|
|
14
|
-
|
|
14
|
+
styles,
|
|
15
15
|
text,
|
|
16
16
|
html,
|
|
17
17
|
data,
|
|
18
|
-
|
|
18
|
+
classlist: classList,
|
|
19
19
|
state,
|
|
20
20
|
scope,
|
|
21
21
|
deps: (param, el) => param || el.parent.deps,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@domql/element",
|
|
3
|
-
"version": "3.0.
|
|
3
|
+
"version": "3.0.6",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"module": "index.js",
|
|
@@ -21,19 +21,19 @@
|
|
|
21
21
|
],
|
|
22
22
|
"scripts": {
|
|
23
23
|
"copy:package:cjs": "cp ../../build/package-cjs.json dist/cjs/package.json",
|
|
24
|
-
"build:esm": "npx esbuild *.js
|
|
25
|
-
"build:cjs": "npx esbuild *.js
|
|
24
|
+
"build:esm": "npx esbuild \"*.js\" \"utils/**/*.js\" \"mixins/**/*.js\" \"methods/**/*.js\" --target=es2019 --format=esm --outdir=dist/esm",
|
|
25
|
+
"build:cjs": "npx esbuild \"*.js\" \"utils/**/*.js\" \"mixins/**/*.js\" \"methods/**/*.js\" --target=node16 --format=cjs --outdir=dist/cjs",
|
|
26
26
|
"build": "rimraf -I dist; npm run build:cjs; npm run build:esm",
|
|
27
27
|
"prepublish": "rimraf -I dist && npm run build && npm run copy:package:cjs"
|
|
28
28
|
},
|
|
29
29
|
"dependencies": {
|
|
30
|
-
"@domql/event": "^3.0.
|
|
31
|
-
"@domql/render": "^3.0.
|
|
30
|
+
"@domql/event": "^3.0.6",
|
|
31
|
+
"@domql/render": "^3.0.6",
|
|
32
32
|
"@domql/report": "^3.0.0",
|
|
33
|
-
"@domql/state": "^3.0.
|
|
34
|
-
"@domql/utils": "^3.0.
|
|
33
|
+
"@domql/state": "^3.0.6",
|
|
34
|
+
"@domql/utils": "^3.0.6"
|
|
35
35
|
},
|
|
36
|
-
"gitHead": "
|
|
36
|
+
"gitHead": "ef6f7abdb0a8cdaa28559e377bc10a12e76ef8f0",
|
|
37
37
|
"devDependencies": {
|
|
38
38
|
"@babel/core": "^7.12.0"
|
|
39
39
|
}
|
package/set.js
CHANGED
|
@@ -1,73 +0,0 @@
|
|
|
1
|
-
var import_update = require("../update");
|
|
2
|
-
describe("checkIfOnUpdate via update()", () => {
|
|
3
|
-
let element, parent, options;
|
|
4
|
-
beforeEach(() => {
|
|
5
|
-
parent = {
|
|
6
|
-
node: document.createElement("div"),
|
|
7
|
-
props: {},
|
|
8
|
-
state: {}
|
|
9
|
-
};
|
|
10
|
-
element = {
|
|
11
|
-
__ref: {
|
|
12
|
-
__if: void 0,
|
|
13
|
-
__state: null,
|
|
14
|
-
__hasRootState: false,
|
|
15
|
-
__execProps: {},
|
|
16
|
-
contentElementKey: "content"
|
|
17
|
-
},
|
|
18
|
-
parent,
|
|
19
|
-
props: {},
|
|
20
|
-
state: {
|
|
21
|
-
update: (el, st) => {
|
|
22
|
-
return st;
|
|
23
|
-
}
|
|
24
|
-
},
|
|
25
|
-
context: {
|
|
26
|
-
defaultExtends: {}
|
|
27
|
-
},
|
|
28
|
-
node: document.createElement("div"),
|
|
29
|
-
if: () => true,
|
|
30
|
-
previousElement: () => {
|
|
31
|
-
return {};
|
|
32
|
-
},
|
|
33
|
-
nextElement: () => {
|
|
34
|
-
return {};
|
|
35
|
-
},
|
|
36
|
-
removeContent: () => {
|
|
37
|
-
return true;
|
|
38
|
-
}
|
|
39
|
-
};
|
|
40
|
-
options = {};
|
|
41
|
-
});
|
|
42
|
-
it("uses props.if when element.if missing", async () => {
|
|
43
|
-
delete element.if;
|
|
44
|
-
element.props.if = () => false;
|
|
45
|
-
await import_update.update.call(element, {}, options);
|
|
46
|
-
expect(element.node).toEqual(document.createElement("div"));
|
|
47
|
-
});
|
|
48
|
-
it("retains state when __hasRootState=true", async () => {
|
|
49
|
-
element.__ref.__hasRootState = true;
|
|
50
|
-
element.state.critical = true;
|
|
51
|
-
element.__ref.__if = false;
|
|
52
|
-
await import_update.update.call(element, {}, options);
|
|
53
|
-
expect(element.state.critical).toBe(true);
|
|
54
|
-
expect(element.state.preserved).toBeUndefined();
|
|
55
|
-
});
|
|
56
|
-
it("processes nested content with parseDeep", async () => {
|
|
57
|
-
element.content = {
|
|
58
|
-
parseDeep: () => ({ parsed: true }),
|
|
59
|
-
existing: "data"
|
|
60
|
-
};
|
|
61
|
-
await import_update.update.call(element, {}, options);
|
|
62
|
-
expect(element.content.parsed).toBe(true);
|
|
63
|
-
expect(element.content.existing).toBeUndefined();
|
|
64
|
-
});
|
|
65
|
-
it("reattaches after previous sibling", async () => {
|
|
66
|
-
const prevNode = document.createElement("span");
|
|
67
|
-
parent.node.appendChild(prevNode);
|
|
68
|
-
await import_update.update.call(element, {}, options);
|
|
69
|
-
const newElement = parent.node.children[0];
|
|
70
|
-
expect(newElement).toEqual(document.createElement("span"));
|
|
71
|
-
expect(newElement.previousSibling).toBe(null);
|
|
72
|
-
});
|
|
73
|
-
});
|
|
@@ -1,177 +0,0 @@
|
|
|
1
|
-
var import_globals = require("@jest/globals");
|
|
2
|
-
var import_children = require("../children");
|
|
3
|
-
describe("children", () => {
|
|
4
|
-
let element, node;
|
|
5
|
-
beforeEach(() => {
|
|
6
|
-
element = {
|
|
7
|
-
__ref: {},
|
|
8
|
-
state: {},
|
|
9
|
-
props: {},
|
|
10
|
-
call: import_globals.jest.fn(),
|
|
11
|
-
removeContent: import_globals.jest.fn(),
|
|
12
|
-
content: null
|
|
13
|
-
};
|
|
14
|
-
node = {};
|
|
15
|
-
});
|
|
16
|
-
it("handles null/undefined params", async () => {
|
|
17
|
-
const result = await (0, import_children.setChildren)(null, element, node);
|
|
18
|
-
expect(result).toBeUndefined();
|
|
19
|
-
});
|
|
20
|
-
it("handles direct string children", async () => {
|
|
21
|
-
const result = await (0, import_children.setChildren)("Hello World", element, node);
|
|
22
|
-
expect(result).toEqual({ tag: "fragment", 0: { text: "Hello World" } });
|
|
23
|
-
});
|
|
24
|
-
it("handles numeric children", async () => {
|
|
25
|
-
const result = await (0, import_children.setChildren)(42, element, node);
|
|
26
|
-
expect(result).toEqual({ tag: "fragment", 0: { text: 42 } });
|
|
27
|
-
});
|
|
28
|
-
it("handles array of primitive values with childrenAs prop", async () => {
|
|
29
|
-
const result = await (0, import_children.setChildren)(["one", "two"], element, node);
|
|
30
|
-
expect(result).toEqual({
|
|
31
|
-
tag: "fragment",
|
|
32
|
-
0: { text: "one" },
|
|
33
|
-
1: { text: "two" }
|
|
34
|
-
});
|
|
35
|
-
});
|
|
36
|
-
it("handles array of primitive values with childrenAs state", async () => {
|
|
37
|
-
element.props.childrenAs = "state";
|
|
38
|
-
const result = await (0, import_children.setChildren)(["one", "two"], element, node);
|
|
39
|
-
expect(result).toEqual({
|
|
40
|
-
tag: "fragment",
|
|
41
|
-
0: { state: { value: "one" } },
|
|
42
|
-
1: { state: { value: "two" } }
|
|
43
|
-
});
|
|
44
|
-
});
|
|
45
|
-
it("caches children and detects changes", async () => {
|
|
46
|
-
const children1 = [{ id: 1 }, { id: 2 }];
|
|
47
|
-
const children2 = [{ id: 1 }, { id: 2 }];
|
|
48
|
-
const children3 = [{ id: 1 }, { id: 3 }];
|
|
49
|
-
await (0, import_children.setChildren)(children1, element, node);
|
|
50
|
-
expect(element.__ref.__childrenCache).toEqual(children1);
|
|
51
|
-
expect(element.__ref.__noChildrenDifference).toBeUndefined();
|
|
52
|
-
await (0, import_children.setChildren)(children2, element, node);
|
|
53
|
-
expect(element.__ref.__noChildrenDifference).toBe(true);
|
|
54
|
-
await (0, import_children.setChildren)(children3, element, node);
|
|
55
|
-
expect(element.__ref.__noChildrenDifference).toBeUndefined();
|
|
56
|
-
expect(element.__ref.__childrenCache).toEqual(children3);
|
|
57
|
-
});
|
|
58
|
-
it("handles mixed React and normal components", async () => {
|
|
59
|
-
const mixedChildren = [
|
|
60
|
-
{ type: "div", text: "Normal" },
|
|
61
|
-
{ $$typeof: Symbol("react") },
|
|
62
|
-
{ type: "span", text: "Another" }
|
|
63
|
-
];
|
|
64
|
-
await (0, import_children.setChildren)(mixedChildren, element, node);
|
|
65
|
-
expect(element.call).toHaveBeenCalledWith(
|
|
66
|
-
"renderReact",
|
|
67
|
-
[mixedChildren[1]],
|
|
68
|
-
element
|
|
69
|
-
);
|
|
70
|
-
});
|
|
71
|
-
it("handles state-based children", async () => {
|
|
72
|
-
element.state = {
|
|
73
|
-
items: ["a", "b"],
|
|
74
|
-
parse: () => ["parsed a", "parsed b"]
|
|
75
|
-
};
|
|
76
|
-
const result = await (0, import_children.setChildren)("state", element, node);
|
|
77
|
-
expect(result).toEqual({
|
|
78
|
-
tag: "fragment",
|
|
79
|
-
0: { text: "parsed a" },
|
|
80
|
-
1: { text: "parsed b" }
|
|
81
|
-
});
|
|
82
|
-
});
|
|
83
|
-
it("handles async function parameters", async () => {
|
|
84
|
-
const asyncParam = async () => ["async1", "async2"];
|
|
85
|
-
const result = await (0, import_children.setChildren)(asyncParam, element, node);
|
|
86
|
-
expect(result).toEqual({
|
|
87
|
-
tag: "fragment",
|
|
88
|
-
0: { text: "async1" },
|
|
89
|
-
1: { text: "async2" }
|
|
90
|
-
});
|
|
91
|
-
});
|
|
92
|
-
it("handles nested object structures", async () => {
|
|
93
|
-
const nestedChildren = {
|
|
94
|
-
header: { text: "Title" },
|
|
95
|
-
content: {
|
|
96
|
-
nested: { text: "Content" }
|
|
97
|
-
}
|
|
98
|
-
};
|
|
99
|
-
const result = await (0, import_children.setChildren)(nestedChildren, element, node);
|
|
100
|
-
expect(result).toEqual({
|
|
101
|
-
tag: "fragment",
|
|
102
|
-
0: { text: "Title" },
|
|
103
|
-
1: { nested: { text: "Content" } }
|
|
104
|
-
});
|
|
105
|
-
});
|
|
106
|
-
it("handles empty arrays and objects", async () => {
|
|
107
|
-
let result = await (0, import_children.setChildren)([], element, node);
|
|
108
|
-
expect(result).toEqual({
|
|
109
|
-
tag: "fragment"
|
|
110
|
-
});
|
|
111
|
-
result = await (0, import_children.setChildren)({}, element, node);
|
|
112
|
-
expect(result).toEqual({
|
|
113
|
-
tag: "fragment"
|
|
114
|
-
});
|
|
115
|
-
});
|
|
116
|
-
it("handles falsy values in arrays", async () => {
|
|
117
|
-
const result = await (0, import_children.setChildren)(
|
|
118
|
-
[null, void 0, false, 0, ""],
|
|
119
|
-
element,
|
|
120
|
-
node
|
|
121
|
-
);
|
|
122
|
-
expect(result).toEqual({
|
|
123
|
-
tag: "fragment",
|
|
124
|
-
3: { text: 0 },
|
|
125
|
-
4: { text: "" }
|
|
126
|
-
});
|
|
127
|
-
});
|
|
128
|
-
it("handles React components with falsy values in array", async () => {
|
|
129
|
-
const mixedChildren = [
|
|
130
|
-
null,
|
|
131
|
-
{ $$typeof: Symbol("react") },
|
|
132
|
-
void 0,
|
|
133
|
-
{ $$typeof: Symbol("react") },
|
|
134
|
-
false
|
|
135
|
-
];
|
|
136
|
-
await (0, import_children.setChildren)(mixedChildren, element, node);
|
|
137
|
-
expect(element.call).toHaveBeenCalledWith(
|
|
138
|
-
"renderReact",
|
|
139
|
-
[mixedChildren[1], mixedChildren[3]],
|
|
140
|
-
element
|
|
141
|
-
);
|
|
142
|
-
});
|
|
143
|
-
it("handles nested state parsing", async () => {
|
|
144
|
-
element.state = {
|
|
145
|
-
nested: {
|
|
146
|
-
items: ["c", "d"]
|
|
147
|
-
}
|
|
148
|
-
};
|
|
149
|
-
element.state.nested.__proto__.parse = () => ["parsed c", "parsed d"];
|
|
150
|
-
const result = await (0, import_children.setChildren)("nested", element, node);
|
|
151
|
-
expect(result).toEqual({
|
|
152
|
-
tag: "fragment",
|
|
153
|
-
0: { state: ["c", "d"] }
|
|
154
|
-
});
|
|
155
|
-
});
|
|
156
|
-
it("handles mixed state and regular objects", async () => {
|
|
157
|
-
element.state = {
|
|
158
|
-
header: { parse: () => "Header" },
|
|
159
|
-
footer: { parse: () => "Footer" }
|
|
160
|
-
};
|
|
161
|
-
const result = await (0, import_children.setChildren)(
|
|
162
|
-
{
|
|
163
|
-
header: "header",
|
|
164
|
-
content: { text: "Content" },
|
|
165
|
-
footer: "footer"
|
|
166
|
-
},
|
|
167
|
-
element,
|
|
168
|
-
node
|
|
169
|
-
);
|
|
170
|
-
expect(result).toEqual({
|
|
171
|
-
tag: "fragment",
|
|
172
|
-
0: { text: "header" },
|
|
173
|
-
1: { text: "Content" },
|
|
174
|
-
2: { text: "footer" }
|
|
175
|
-
});
|
|
176
|
-
});
|
|
177
|
-
});
|
|
@@ -1,75 +0,0 @@
|
|
|
1
|
-
var __create = Object.create;
|
|
2
|
-
var __defProp = Object.defineProperty;
|
|
3
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
-
var __getProtoOf = Object.getPrototypeOf;
|
|
6
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
-
var __copyProps = (to, from, except, desc) => {
|
|
8
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
9
|
-
for (let key of __getOwnPropNames(from))
|
|
10
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
11
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
12
|
-
}
|
|
13
|
-
return to;
|
|
14
|
-
};
|
|
15
|
-
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
16
|
-
// If the importer is in node compatibility mode or this is not an ESM
|
|
17
|
-
// file that has been converted to a CommonJS file using a Babel-
|
|
18
|
-
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
19
|
-
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
20
|
-
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
21
|
-
mod
|
|
22
|
-
));
|
|
23
|
-
var import_define = __toESM(require("../define"), 1);
|
|
24
|
-
var import_mixins = require("../mixins");
|
|
25
|
-
describe("default function (registry updater)", () => {
|
|
26
|
-
let originalRegistry;
|
|
27
|
-
beforeEach(() => {
|
|
28
|
-
originalRegistry = { ...import_mixins.REGISTRY };
|
|
29
|
-
});
|
|
30
|
-
afterEach(() => {
|
|
31
|
-
Object.keys(import_mixins.REGISTRY).forEach((key) => {
|
|
32
|
-
import_mixins.REGISTRY[key] = originalRegistry[key];
|
|
33
|
-
});
|
|
34
|
-
});
|
|
35
|
-
it("should add new params to REGISTRY when overwrite is true", () => {
|
|
36
|
-
const params = { newKey: "newValue", anotherKey: "anotherValue" };
|
|
37
|
-
const options = { overwrite: true };
|
|
38
|
-
(0, import_define.default)(params, options);
|
|
39
|
-
expect(import_mixins.REGISTRY.newKey).toBe("newValue");
|
|
40
|
-
expect(import_mixins.REGISTRY.anotherKey).toBe("anotherValue");
|
|
41
|
-
});
|
|
42
|
-
it("should not modify REGISTRY when trying to overwrite existing keys without overwrite option", () => {
|
|
43
|
-
const params = { attr: "newValue", text: "newText" };
|
|
44
|
-
try {
|
|
45
|
-
(0, import_define.default)(params);
|
|
46
|
-
} catch (e) {
|
|
47
|
-
}
|
|
48
|
-
expect(import_mixins.REGISTRY.attr).toBe(originalRegistry.attr);
|
|
49
|
-
expect(import_mixins.REGISTRY.text).toBe(originalRegistry.text);
|
|
50
|
-
});
|
|
51
|
-
it("should overwrite existing keys when overwrite is true", () => {
|
|
52
|
-
const params = { attr: "newValue", text: "newText" };
|
|
53
|
-
const options = { overwrite: true };
|
|
54
|
-
(0, import_define.default)(params, options);
|
|
55
|
-
expect(import_mixins.REGISTRY.attr).toBe("newValue");
|
|
56
|
-
expect(import_mixins.REGISTRY.text).toBe("newText");
|
|
57
|
-
});
|
|
58
|
-
it("should handle empty params object without errors", () => {
|
|
59
|
-
const params = {};
|
|
60
|
-
const options = { overwrite: true };
|
|
61
|
-
expect(() => (0, import_define.default)(params, options)).not.toThrow();
|
|
62
|
-
expect(import_mixins.REGISTRY).toEqual(originalRegistry);
|
|
63
|
-
});
|
|
64
|
-
it("should handle empty options object without errors", () => {
|
|
65
|
-
const params = { newKey: "newValue" };
|
|
66
|
-
expect(() => (0, import_define.default)(params, {})).not.toThrow();
|
|
67
|
-
expect(import_mixins.REGISTRY.newKey).toBe("newValue");
|
|
68
|
-
});
|
|
69
|
-
it("should not add new keys when params is empty", () => {
|
|
70
|
-
const params = {};
|
|
71
|
-
const options = { overwrite: true };
|
|
72
|
-
(0, import_define.default)(params, options);
|
|
73
|
-
expect(import_mixins.REGISTRY).toEqual(originalRegistry);
|
|
74
|
-
});
|
|
75
|
-
});
|