@domql/element 2.32.0 → 2.32.1

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.
@@ -51,10 +51,12 @@ const removeContent = function(el, opts = {}) {
51
51
  }
52
52
  const { __cached } = ref;
53
53
  if (__cached && __cached[contentElementKey]) {
54
- if (__cached[contentElementKey].tag === "fragment")
55
- __cached[contentElementKey].parent.node.innerHTML = "";
56
- else if (__cached[contentElementKey] && (0, import_utils.isFunction)(__cached[contentElementKey].remove))
57
- __cached[contentElementKey].remove();
54
+ const cachedContent = __cached[contentElementKey];
55
+ if (cachedContent.tag === "fragment")
56
+ cachedContent.parent.node.innerHTML = "";
57
+ else if (cachedContent && (0, import_utils.isFunction)(cachedContent.remove))
58
+ cachedContent.remove();
59
+ delete __cached[contentElementKey];
58
60
  }
59
61
  ref.__children.splice(ref.__children.indexOf(contentElementKey), 1);
60
62
  delete element[contentElementKey];
package/dist/cjs/set.js CHANGED
@@ -33,12 +33,20 @@ var import_event = require("@domql/event");
33
33
  const resetElement = async (params, element, options) => {
34
34
  if (!options.preventRemove) (0, import_content.removeContent)(element, options);
35
35
  const { __ref: ref } = element;
36
- await (0, import_create.create)(params, element, ref.contentElementKey || "content", {
37
- ignoreChildExtend: true,
38
- ...import_mixins.registry.defaultOptions,
39
- ...import_options.OPTIONS.create,
40
- ...options
41
- });
36
+ const contentElementKey = (0, import_utils.setContentKey)(element, options);
37
+ const { __cached } = ref;
38
+ const newContent = await (0, import_create.create)(
39
+ params,
40
+ element,
41
+ ref.contentElementKey || "content",
42
+ {
43
+ ignoreChildExtend: true,
44
+ ...import_mixins.registry.defaultOptions,
45
+ ...import_options.OPTIONS.create,
46
+ ...options
47
+ }
48
+ );
49
+ __cached[contentElementKey] = newContent;
42
50
  };
43
51
  const reset = async (options) => {
44
52
  const element = void 0;
@@ -50,10 +58,9 @@ const reset = async (options) => {
50
58
  });
51
59
  };
52
60
  const set = async function(params, options = {}, el) {
53
- var _a, _b, _c;
61
+ var _a, _b, _c, _d;
54
62
  const element = el || this;
55
63
  const { __ref: ref } = element;
56
- console.warn(params);
57
64
  if (options.preventContentUpdate || options.preventUpdate && ((_b = (_a = options.preventUpdate).includes) == null ? void 0 : _b.call(_a, "content")))
58
65
  return;
59
66
  if (options.routerContentElement && options.lastElement) {
@@ -63,9 +70,9 @@ const set = async function(params, options = {}, el) {
63
70
  const content = element[contentKey];
64
71
  const __contentRef = content && content.__ref;
65
72
  const lazyLoad = element.props && element.props.lazyLoad;
66
- const hasCollection = element.$collection || element.$stateCollection || element.$propsCollection;
73
+ const hasCollection = element.$collection || element.$stateCollection || element.$propsCollection || ((_c = element.props) == null ? void 0 : _c.children);
67
74
  if (options.preventContentUpdate === true && !hasCollection) return;
68
- if (ref.__noCollectionDifference || __contentRef && __contentRef.__cached && (0, import_utils.deepContains)(params, content)) {
75
+ if (!options.forceReset && (ref.__noCollectionDifference || __contentRef && __contentRef.__cached && (0, import_utils.deepContains)(params, content))) {
69
76
  if (!options.preventBeforeUpdateListener && !options.preventListeners) {
70
77
  const beforeUpdateReturns = await (0, import_event.triggerEventOnUpdate)(
71
78
  "beforeUpdate",
@@ -75,7 +82,7 @@ const set = async function(params, options = {}, el) {
75
82
  );
76
83
  if (beforeUpdateReturns === false) return element;
77
84
  }
78
- if (content == null ? void 0 : content.update) await content.update();
85
+ if (content == null ? void 0 : content.update) await content.update({}, options);
79
86
  if (!options.preventUpdateListener)
80
87
  await (0, import_event.triggerEventOn)("update", element, options);
81
88
  return;
@@ -87,7 +94,7 @@ const set = async function(params, options = {}, el) {
87
94
  params.childExtend = element.childExtend;
88
95
  props.ignoreChildExtend = true;
89
96
  }
90
- if (!(props == null ? void 0 : props.childProps) && ((_c = element.props) == null ? void 0 : _c.childProps)) {
97
+ if (!(props == null ? void 0 : props.childProps) && ((_d = element.props) == null ? void 0 : _d.childProps)) {
91
98
  props.childProps = element.props.childProps;
92
99
  props.ignoreChildProps = true;
93
100
  }
@@ -60,22 +60,22 @@ const update = async function(params = {}, opts) {
60
60
  element,
61
61
  options
62
62
  );
63
- if (snapshotHasUpdated) return;
64
- if (checkIfStorm(element, options)) return;
63
+ if (snapshotHasUpdated) return false;
64
+ if (checkIfStorm(element, options)) return false;
65
65
  if (!options.preventListeners)
66
66
  await (0, import_event.triggerEventOn)("eventStart", element, options);
67
67
  if (!options.preventListeners)
68
68
  await (0, import_event.triggerEventOnUpdate)("startUpdate", params, element, options);
69
69
  if (preventInheritAtCurrentState && preventInheritAtCurrentState.__element === element)
70
- return;
70
+ return false;
71
71
  if (!excludes) (0, import_utils.merge)(options, UPDATE_DEFAULT_OPTIONS);
72
72
  if ((0, import_utils.isString)(params) || (0, import_utils.isNumber)(params)) {
73
73
  params = { text: params };
74
74
  }
75
75
  const inheritState = await inheritStateUpdates(element, options);
76
- if (inheritState === false) return;
76
+ if (inheritState === false) return false;
77
77
  const ifFails = checkIfOnUpdate(element, parent, options);
78
- if (ifFails) return;
78
+ if (ifFails) return false;
79
79
  if (ref.__if && !options.preventPropsUpdate) {
80
80
  const hasParentProps = parent.props && (parent.props[key] || parent.props.childProps);
81
81
  const hasFunctionInProps = ref.__props.filter((v) => (0, import_utils.isFunction)(v));
@@ -100,7 +100,9 @@ const update = async function(params = {}, opts) {
100
100
  }
101
101
  if (!ref.__if) return false;
102
102
  if (!node) {
103
- return;
103
+ return false;
104
+ }
105
+ if (element.tag !== "fragment" && !document.body.contains(node)) {
104
106
  }
105
107
  const {
106
108
  preventUpdate,
@@ -25,10 +25,12 @@ const removeContent = function(el, opts = {}) {
25
25
  }
26
26
  const { __cached } = ref;
27
27
  if (__cached && __cached[contentElementKey]) {
28
- if (__cached[contentElementKey].tag === "fragment")
29
- __cached[contentElementKey].parent.node.innerHTML = "";
30
- else if (__cached[contentElementKey] && isFunction(__cached[contentElementKey].remove))
31
- __cached[contentElementKey].remove();
28
+ const cachedContent = __cached[contentElementKey];
29
+ if (cachedContent.tag === "fragment")
30
+ cachedContent.parent.node.innerHTML = "";
31
+ else if (cachedContent && isFunction(cachedContent.remove))
32
+ cachedContent.remove();
33
+ delete __cached[contentElementKey];
32
34
  }
33
35
  ref.__children.splice(ref.__children.indexOf(contentElementKey), 1);
34
36
  delete element[contentElementKey];
package/dist/esm/set.js CHANGED
@@ -7,12 +7,20 @@ import { triggerEventOn, triggerEventOnUpdate } from "@domql/event";
7
7
  const resetElement = async (params, element, options) => {
8
8
  if (!options.preventRemove) removeContent(element, options);
9
9
  const { __ref: ref } = element;
10
- await create(params, element, ref.contentElementKey || "content", {
11
- ignoreChildExtend: true,
12
- ...registry.defaultOptions,
13
- ...OPTIONS.create,
14
- ...options
15
- });
10
+ const contentElementKey = setContentKey(element, options);
11
+ const { __cached } = ref;
12
+ const newContent = await create(
13
+ params,
14
+ element,
15
+ ref.contentElementKey || "content",
16
+ {
17
+ ignoreChildExtend: true,
18
+ ...registry.defaultOptions,
19
+ ...OPTIONS.create,
20
+ ...options
21
+ }
22
+ );
23
+ __cached[contentElementKey] = newContent;
16
24
  };
17
25
  const reset = async (options) => {
18
26
  const element = void 0;
@@ -24,10 +32,9 @@ const reset = async (options) => {
24
32
  });
25
33
  };
26
34
  const set = async function(params, options = {}, el) {
27
- var _a, _b, _c;
35
+ var _a, _b, _c, _d;
28
36
  const element = el || this;
29
37
  const { __ref: ref } = element;
30
- console.warn(params);
31
38
  if (options.preventContentUpdate || options.preventUpdate && ((_b = (_a = options.preventUpdate).includes) == null ? void 0 : _b.call(_a, "content")))
32
39
  return;
33
40
  if (options.routerContentElement && options.lastElement) {
@@ -37,9 +44,9 @@ const set = async function(params, options = {}, el) {
37
44
  const content = element[contentKey];
38
45
  const __contentRef = content && content.__ref;
39
46
  const lazyLoad = element.props && element.props.lazyLoad;
40
- const hasCollection = element.$collection || element.$stateCollection || element.$propsCollection;
47
+ const hasCollection = element.$collection || element.$stateCollection || element.$propsCollection || ((_c = element.props) == null ? void 0 : _c.children);
41
48
  if (options.preventContentUpdate === true && !hasCollection) return;
42
- if (ref.__noCollectionDifference || __contentRef && __contentRef.__cached && deepContains(params, content)) {
49
+ if (!options.forceReset && (ref.__noCollectionDifference || __contentRef && __contentRef.__cached && deepContains(params, content))) {
43
50
  if (!options.preventBeforeUpdateListener && !options.preventListeners) {
44
51
  const beforeUpdateReturns = await triggerEventOnUpdate(
45
52
  "beforeUpdate",
@@ -49,7 +56,7 @@ const set = async function(params, options = {}, el) {
49
56
  );
50
57
  if (beforeUpdateReturns === false) return element;
51
58
  }
52
- if (content == null ? void 0 : content.update) await content.update();
59
+ if (content == null ? void 0 : content.update) await content.update({}, options);
53
60
  if (!options.preventUpdateListener)
54
61
  await triggerEventOn("update", element, options);
55
62
  return;
@@ -61,7 +68,7 @@ const set = async function(params, options = {}, el) {
61
68
  params.childExtend = element.childExtend;
62
69
  props.ignoreChildExtend = true;
63
70
  }
64
- if (!(props == null ? void 0 : props.childProps) && ((_c = element.props) == null ? void 0 : _c.childProps)) {
71
+ if (!(props == null ? void 0 : props.childProps) && ((_d = element.props) == null ? void 0 : _d.childProps)) {
65
72
  props.childProps = element.props.childProps;
66
73
  props.ignoreChildProps = true;
67
74
  }
@@ -54,22 +54,22 @@ const update = async function(params = {}, opts) {
54
54
  element,
55
55
  options
56
56
  );
57
- if (snapshotHasUpdated) return;
58
- if (checkIfStorm(element, options)) return;
57
+ if (snapshotHasUpdated) return false;
58
+ if (checkIfStorm(element, options)) return false;
59
59
  if (!options.preventListeners)
60
60
  await triggerEventOn("eventStart", element, options);
61
61
  if (!options.preventListeners)
62
62
  await triggerEventOnUpdate("startUpdate", params, element, options);
63
63
  if (preventInheritAtCurrentState && preventInheritAtCurrentState.__element === element)
64
- return;
64
+ return false;
65
65
  if (!excludes) merge(options, UPDATE_DEFAULT_OPTIONS);
66
66
  if (isString(params) || isNumber(params)) {
67
67
  params = { text: params };
68
68
  }
69
69
  const inheritState = await inheritStateUpdates(element, options);
70
- if (inheritState === false) return;
70
+ if (inheritState === false) return false;
71
71
  const ifFails = checkIfOnUpdate(element, parent, options);
72
- if (ifFails) return;
72
+ if (ifFails) return false;
73
73
  if (ref.__if && !options.preventPropsUpdate) {
74
74
  const hasParentProps = parent.props && (parent.props[key] || parent.props.childProps);
75
75
  const hasFunctionInProps = ref.__props.filter((v) => isFunction(v));
@@ -94,7 +94,9 @@ const update = async function(params = {}, opts) {
94
94
  }
95
95
  if (!ref.__if) return false;
96
96
  if (!node) {
97
- return;
97
+ return false;
98
+ }
99
+ if (element.tag !== "fragment" && !document.body.contains(node)) {
98
100
  }
99
101
  const {
100
102
  preventUpdate,
package/mixins/content.js CHANGED
@@ -24,7 +24,7 @@ export const removeContent = function (el, opts = {}) {
24
24
  if (element[contentElementKey]) {
25
25
  if (element[contentElementKey].node && element.node) {
26
26
  if (element[contentElementKey].tag === 'fragment')
27
- element.node.innerHTML = ''
27
+ element.node.innerHTML = '' // TODO: deep check to only remove `content` children and not other children
28
28
  else {
29
29
  const contentNode = element[contentElementKey].node
30
30
  if (contentNode.parentNode === element.node)
@@ -34,13 +34,12 @@ export const removeContent = function (el, opts = {}) {
34
34
 
35
35
  const { __cached } = ref
36
36
  if (__cached && __cached[contentElementKey]) {
37
- if (__cached[contentElementKey].tag === 'fragment')
38
- __cached[contentElementKey].parent.node.innerHTML = ''
39
- else if (
40
- __cached[contentElementKey] &&
41
- isFunction(__cached[contentElementKey].remove)
42
- )
43
- __cached[contentElementKey].remove()
37
+ const cachedContent = __cached[contentElementKey]
38
+ if (cachedContent.tag === 'fragment')
39
+ cachedContent.parent.node.innerHTML = ''
40
+ else if (cachedContent && isFunction(cachedContent.remove))
41
+ cachedContent.remove()
42
+ delete __cached[contentElementKey]
44
43
  }
45
44
 
46
45
  ref.__children.splice(ref.__children.indexOf(contentElementKey), 1)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@domql/element",
3
- "version": "2.32.0",
3
+ "version": "2.32.1",
4
4
  "license": "MIT",
5
5
  "type": "module",
6
6
  "module": "index.js",
@@ -27,12 +27,12 @@
27
27
  "prepublish": "npx rimraf -I dist && npm run build && npm run copy:package:cjs"
28
28
  },
29
29
  "dependencies": {
30
- "@domql/event": "^2.32.0",
31
- "@domql/render": "^2.32.0",
32
- "@domql/state": "^2.32.0",
33
- "@domql/utils": "^2.32.0"
30
+ "@domql/event": "^2.32.1",
31
+ "@domql/render": "^2.32.1",
32
+ "@domql/state": "^2.32.1",
33
+ "@domql/utils": "^2.32.1"
34
34
  },
35
- "gitHead": "6f087b0fe036c41c8f7d620ed67c24d25e371cc6",
35
+ "gitHead": "dacd7cc0abd5d46a1be9c04dc99d6f266521970f",
36
36
  "devDependencies": {
37
37
  "@babel/core": "^7.27.1"
38
38
  }
package/set.js CHANGED
@@ -11,12 +11,20 @@ import { triggerEventOn, triggerEventOnUpdate } from '@domql/event'
11
11
  export const resetElement = async (params, element, options) => {
12
12
  if (!options.preventRemove) removeContent(element, options)
13
13
  const { __ref: ref } = element
14
- await create(params, element, ref.contentElementKey || 'content', {
15
- ignoreChildExtend: true,
16
- ...registry.defaultOptions,
17
- ...OPTIONS.create,
18
- ...options
19
- })
14
+ const contentElementKey = setContentKey(element, options)
15
+ const { __cached } = ref
16
+ const newContent = await create(
17
+ params,
18
+ element,
19
+ ref.contentElementKey || 'content',
20
+ {
21
+ ignoreChildExtend: true,
22
+ ...registry.defaultOptions,
23
+ ...OPTIONS.create,
24
+ ...options
25
+ }
26
+ )
27
+ __cached[contentElementKey] = newContent
20
28
  }
21
29
 
22
30
  export const reset = async (options) => {
@@ -33,7 +41,7 @@ export const set = async function (params, options = {}, el) {
33
41
  const element = el || this
34
42
  const { __ref: ref } = element
35
43
 
36
- console.warn(params)
44
+ // console.warn(params)
37
45
 
38
46
  if (
39
47
  options.preventContentUpdate ||
@@ -51,15 +59,19 @@ export const set = async function (params, options = {}, el) {
51
59
  const lazyLoad = element.props && element.props.lazyLoad
52
60
 
53
61
  const hasCollection =
54
- element.$collection || element.$stateCollection || element.$propsCollection
62
+ element.$collection ||
63
+ element.$stateCollection ||
64
+ element.$propsCollection ||
65
+ element.props?.children
55
66
  if (options.preventContentUpdate === true && !hasCollection) return
56
67
 
57
68
  // console.log(deepClone(params), deepClone(content))
58
69
  // console.log(deepContains(params, content))
59
70
 
60
71
  if (
61
- ref.__noCollectionDifference ||
62
- (__contentRef && __contentRef.__cached && deepContains(params, content))
72
+ !options.forceReset &&
73
+ (ref.__noCollectionDifference ||
74
+ (__contentRef && __contentRef.__cached && deepContains(params, content)))
63
75
  ) {
64
76
  if (!options.preventBeforeUpdateListener && !options.preventListeners) {
65
77
  const beforeUpdateReturns = await triggerEventOnUpdate(
@@ -70,7 +82,7 @@ export const set = async function (params, options = {}, el) {
70
82
  )
71
83
  if (beforeUpdateReturns === false) return element
72
84
  }
73
- if (content?.update) await content.update()
85
+ if (content?.update) await content.update({}, options)
74
86
  if (!options.preventUpdateListener)
75
87
  await triggerEventOn('update', element, options)
76
88
  return
@@ -87,6 +99,7 @@ export const set = async function (params, options = {}, el) {
87
99
  props.childProps = element.props.childProps
88
100
  props.ignoreChildProps = true
89
101
  }
102
+ // TODO: check for fragment and ignore if these attrs ^
90
103
 
91
104
  // console.warn('setting content', ref.path)
92
105
 
package/update.js CHANGED
@@ -70,9 +70,9 @@ export const update = async function (params = {}, opts) {
70
70
  element,
71
71
  options
72
72
  )
73
- if (snapshotHasUpdated) return
73
+ if (snapshotHasUpdated) return false
74
74
 
75
- if (checkIfStorm(element, options)) return
75
+ if (checkIfStorm(element, options)) return false
76
76
 
77
77
  if (!options.preventListeners)
78
78
  await triggerEventOn('eventStart', element, options)
@@ -84,7 +84,7 @@ export const update = async function (params = {}, opts) {
84
84
  preventInheritAtCurrentState &&
85
85
  preventInheritAtCurrentState.__element === element
86
86
  )
87
- return
87
+ return false
88
88
  if (!excludes) merge(options, UPDATE_DEFAULT_OPTIONS)
89
89
 
90
90
  if (isString(params) || isNumber(params)) {
@@ -92,10 +92,10 @@ export const update = async function (params = {}, opts) {
92
92
  }
93
93
 
94
94
  const inheritState = await inheritStateUpdates(element, options)
95
- if (inheritState === false) return
95
+ if (inheritState === false) return false
96
96
 
97
97
  const ifFails = checkIfOnUpdate(element, parent, options)
98
- if (ifFails) return
98
+ if (ifFails) return false
99
99
 
100
100
  if (ref.__if && !options.preventPropsUpdate) {
101
101
  const hasParentProps =
@@ -129,8 +129,13 @@ export const update = async function (params = {}, opts) {
129
129
 
130
130
  if (!ref.__if) return false
131
131
  if (!node) {
132
+ // if (!node || !document.body.contains(node)) {
132
133
  // return createNode(element, options)
133
- return
134
+ return false
135
+ }
136
+
137
+ if (element.tag !== 'fragment' && !document.body.contains(node)) {
138
+ // console.log(element, node)
134
139
  }
135
140
 
136
141
  const {