@domql/element 2.5.23 → 2.5.29

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 CHANGED
@@ -4,7 +4,7 @@ import createNode from './node'
4
4
  import { ROOT } from './tree'
5
5
  import { TAGS } from '@domql/registry'
6
6
  import { triggerEventOn } from '@domql/event'
7
- import { appendNode, assignNode, cacheNode, detectTag } from '@domql/render'
7
+ import { assignNode, detectTag } from '@domql/render'
8
8
  import { createState } from '@domql/state'
9
9
 
10
10
  import { isMethod } from './methods'
@@ -42,7 +42,7 @@ const ENV = process.env.NODE_ENV
42
42
  /**
43
43
  * Creating a domQL element using passed parameters
44
44
  */
45
- const create = (element, parent, key, options = OPTIONS.create || {}) => {
45
+ const create = (element, parent, key, options = OPTIONS.create || {}, attachOptions) => {
46
46
  cacheOptions(element, options)
47
47
 
48
48
  // if (key === 'Title') debugger
@@ -101,7 +101,7 @@ const create = (element, parent, key, options = OPTIONS.create || {}) => {
101
101
 
102
102
  // if it already HAS a NODE
103
103
  if (element.node && ref.__if) {
104
- return assignNode(element, parent, key)
104
+ return assignNode(element, parent, key, attachOptions)
105
105
  }
106
106
 
107
107
  // apply variants
@@ -115,7 +115,7 @@ const create = (element, parent, key, options = OPTIONS.create || {}) => {
115
115
  // generate a CLASS name
116
116
  assignKeyAsClassname(element)
117
117
 
118
- renderElement(element, parent, options)
118
+ renderElement(element, parent, options, attachOptions)
119
119
 
120
120
  addElementIntoParentChildren(element, parent)
121
121
 
@@ -207,16 +207,19 @@ const addElementIntoParentChildren = (element, parent) => {
207
207
  if (parent.__ref && parent.__ref.__children) parent.__ref.__children.push(element.key)
208
208
  }
209
209
 
210
- const renderElement = (element, parent, options) => {
210
+ const renderElement = (element, parent, options, attachOptions) => {
211
211
  const { __ref: ref, key } = element
212
212
 
213
213
  // CREATE a real NODE
214
214
  createNode(element, options)
215
215
 
216
- if (!ref.__if) return element
216
+ if (!ref.__if) {
217
+ parent[key || element.key] = element
218
+ return element
219
+ }
217
220
 
218
221
  // assign NODE
219
- assignNode(element, parent, key)
222
+ assignNode(element, parent, key, attachOptions)
220
223
 
221
224
  // run `on.renderRouter`
222
225
  triggerEventOn('renderRouter', element, options)
@@ -252,14 +255,8 @@ const createScope = (element, parent) => {
252
255
  const createIfConditionFlag = (element, parent) => {
253
256
  const { __ref: ref } = element
254
257
 
255
- if (isFunction(element.if)) {
256
- // TODO: move as fragment
257
- const ifPassed = element.if(element, element.state)
258
- if (!ifPassed) {
259
- const ifFragment = cacheNode({ tag: 'fragment' })
260
- ref.__ifFragment = appendNode(ifFragment, parent.node)
261
- delete ref.__if
262
- } else ref.__if = true
258
+ if (isFunction(element.if) && !element.if(element, element.state)) {
259
+ delete ref.__if
263
260
  } else ref.__if = true
264
261
  }
265
262
 
@@ -48,7 +48,7 @@ var import_utils = require("@domql/utils");
48
48
  var import_options = __toESM(require("./cache/options"), 1);
49
49
  var import_component = require("./utils/component");
50
50
  const ENV = "development";
51
- const create = (element, parent, key, options = import_options.default.create || {}) => {
51
+ const create = (element, parent, key, options = import_options.default.create || {}, attachOptions) => {
52
52
  cacheOptions(element, options);
53
53
  if (checkIfPrimitive(element)) {
54
54
  element = applyValueAsText(element, parent, key);
@@ -80,7 +80,7 @@ const create = (element, parent, key, options = import_options.default.create ||
80
80
  element.scope = element.props;
81
81
  createIfConditionFlag(element, parent);
82
82
  if (element.node && ref.__if) {
83
- return (0, import_render.assignNode)(element, parent, key);
83
+ return (0, import_render.assignNode)(element, parent, key, attachOptions);
84
84
  }
85
85
  (0, import_component.applyVariant)(element, parent);
86
86
  const onInit = (0, import_event.triggerEventOn)("init", element, options);
@@ -88,7 +88,7 @@ const create = (element, parent, key, options = import_options.default.create ||
88
88
  return element;
89
89
  (0, import_event.triggerEventOn)("beforeClassAssign", element, options);
90
90
  (0, import_classList.assignKeyAsClassname)(element);
91
- renderElement(element, parent, options);
91
+ renderElement(element, parent, options, attachOptions);
92
92
  addElementIntoParentChildren(element, parent);
93
93
  (0, import_event.triggerEventOn)("complete", element, options);
94
94
  return element;
@@ -161,12 +161,14 @@ const addElementIntoParentChildren = (element, parent) => {
161
161
  if (parent.__ref && parent.__ref.__children)
162
162
  parent.__ref.__children.push(element.key);
163
163
  };
164
- const renderElement = (element, parent, options) => {
164
+ const renderElement = (element, parent, options, attachOptions) => {
165
165
  const { __ref: ref, key } = element;
166
166
  (0, import_node.default)(element, options);
167
- if (!ref.__if)
167
+ if (!ref.__if) {
168
+ parent[key || element.key] = element;
168
169
  return element;
169
- (0, import_render.assignNode)(element, parent, key);
170
+ }
171
+ (0, import_render.assignNode)(element, parent, key, attachOptions);
170
172
  (0, import_event.triggerEventOn)("renderRouter", element, options);
171
173
  (0, import_event.triggerEventOn)("render", element, options);
172
174
  };
@@ -195,14 +197,8 @@ const createScope = (element, parent) => {
195
197
  };
196
198
  const createIfConditionFlag = (element, parent) => {
197
199
  const { __ref: ref } = element;
198
- if ((0, import_utils.isFunction)(element.if)) {
199
- const ifPassed = element.if(element, element.state);
200
- if (!ifPassed) {
201
- const ifFragment = (0, import_render.cacheNode)({ tag: "fragment" });
202
- ref.__ifFragment = (0, import_render.appendNode)(ifFragment, parent.node);
203
- delete ref.__if;
204
- } else
205
- ref.__if = true;
200
+ if ((0, import_utils.isFunction)(element.if) && !element.if(element, element.state)) {
201
+ delete ref.__if;
206
202
  } else
207
203
  ref.__if = true;
208
204
  };
@@ -57,6 +57,7 @@ const update = function(params = {}, options = UPDATE_DEFAULT_OPTIONS) {
57
57
  const element = this;
58
58
  const { parent, node, key } = element;
59
59
  const { excludes, preventInheritAtCurrentState } = options;
60
+ (0, import_event.triggerEventOnUpdate)("startUpdate", params, element, options);
60
61
  if (preventInheritAtCurrentState && preventInheritAtCurrentState.__element === element)
61
62
  return;
62
63
  if (!excludes)
@@ -70,12 +71,12 @@ const update = function(params = {}, options = UPDATE_DEFAULT_OPTIONS) {
70
71
  if ((0, import_utils.isString)(params) || (0, import_utils.isNumber)(params)) {
71
72
  params = { text: params };
72
73
  }
73
- const ifFails = checkIfOnUpdate(element, parent, options);
74
- if (ifFails)
75
- return;
76
74
  const inheritState = inheritStateUpdates(element, options);
77
75
  if (inheritState === false)
78
76
  return;
77
+ const ifFails = checkIfOnUpdate(element, parent, options);
78
+ if (ifFails)
79
+ return;
79
80
  if (ref.__if && !options.preventPropsUpdate) {
80
81
  const hasParentProps = parent.props && (parent.props[key] || parent.props.childProps);
81
82
  const hasFunctionInProps = ref.__props.filter((v) => (0, import_utils.isFunction)(v));
@@ -146,7 +147,7 @@ const captureSnapshot = (element, options) => {
146
147
  return [snapshotOnCallee, calleeElement];
147
148
  };
148
149
  const checkIfOnUpdate = (element, parent, options) => {
149
- if (!(0, import_utils.isFunction)(element.if) || !element.state || !parent)
150
+ if (!(0, import_utils.isFunction)(element.if) || !parent)
150
151
  return;
151
152
  const ref = element.__ref;
152
153
  const ifPassed = element.if(element, element.state, element.context, options);
@@ -162,7 +163,16 @@ const checkIfOnUpdate = (element, parent, options) => {
162
163
  if (ref.__state) {
163
164
  element.state = ref.__state;
164
165
  }
165
- const created = (0, import_create.default)(element, parent, element.key, import_options.default.create);
166
+ const previousElement = element.previousElement();
167
+ const nextElement = element.nextElement();
168
+ const hasPrevious = previousElement && previousElement.node;
169
+ const hasNext = nextElement && nextElement.node;
170
+ const attachOptions = {
171
+ position: hasPrevious ? "after" : hasNext ? "before" : null,
172
+ node: hasPrevious || hasNext,
173
+ parentNode: parent.node
174
+ };
175
+ const created = (0, import_create.default)(element, parent, element.key, import_options.default.create, attachOptions);
166
176
  if (options.preventUpdate !== true && element.on && (0, import_utils.isFunction)(element.on.update)) {
167
177
  (0, import_event.applyEvent)(element.on.update, created, created.state);
168
178
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@domql/element",
3
- "version": "2.5.23",
3
+ "version": "2.5.29",
4
4
  "license": "MIT",
5
5
  "type": "module",
6
6
  "module": "index.js",
@@ -31,7 +31,7 @@
31
31
  "@domql/state": "latest",
32
32
  "@domql/utils": "latest"
33
33
  },
34
- "gitHead": "34d9106fa933dde10e587dda3f485418561a3f3c",
34
+ "gitHead": "df470e5a96cda567c9d99cc98337eac0136d0890",
35
35
  "devDependencies": {
36
36
  "@babel/core": "^7.12.0"
37
37
  }
package/update.js CHANGED
@@ -31,6 +31,8 @@ const update = function (params = {}, options = UPDATE_DEFAULT_OPTIONS) {
31
31
  const { parent, node, key } = element
32
32
  const { excludes, preventInheritAtCurrentState } = options
33
33
 
34
+ triggerEventOnUpdate('startUpdate', params, element, options)
35
+
34
36
  if (preventInheritAtCurrentState && preventInheritAtCurrentState.__element === element) return
35
37
  if (!excludes) merge(options, UPDATE_DEFAULT_OPTIONS)
36
38
 
@@ -44,12 +46,12 @@ const update = function (params = {}, options = UPDATE_DEFAULT_OPTIONS) {
44
46
  params = { text: params }
45
47
  }
46
48
 
47
- const ifFails = checkIfOnUpdate(element, parent, options)
48
- if (ifFails) return
49
-
50
49
  const inheritState = inheritStateUpdates(element, options)
51
50
  if (inheritState === false) return
52
51
 
52
+ const ifFails = checkIfOnUpdate(element, parent, options)
53
+ if (ifFails) return
54
+
53
55
  if (ref.__if && !options.preventPropsUpdate) {
54
56
  const hasParentProps = parent.props && (parent.props[key] || parent.props.childProps)
55
57
  const hasFunctionInProps = ref.__props.filter(v => isFunction(v))
@@ -141,7 +143,7 @@ const captureSnapshot = (element, options) => {
141
143
  }
142
144
 
143
145
  const checkIfOnUpdate = (element, parent, options) => {
144
- if (!isFunction(element.if) || !element.state || !parent) return
146
+ if (!isFunction(element.if) || !parent) return
145
147
 
146
148
  const ref = element.__ref
147
149
  const ifPassed = element.if(element, element.state, element.context, options)
@@ -158,7 +160,20 @@ const checkIfOnUpdate = (element, parent, options) => {
158
160
  if (ref.__state) {
159
161
  element.state = ref.__state
160
162
  }
161
- const created = create(element, parent, element.key, OPTIONS.create)
163
+
164
+ const previousElement = element.previousElement()
165
+ const nextElement = element.nextElement()
166
+
167
+ const hasPrevious = previousElement && previousElement.node
168
+ const hasNext = nextElement && nextElement.node
169
+
170
+ const attachOptions = {
171
+ position: hasPrevious ? 'after' : hasNext ? 'before' : null,
172
+ node: hasPrevious || hasNext,
173
+ parentNode: parent.node
174
+ }
175
+
176
+ const created = create(element, parent, element.key, OPTIONS.create, attachOptions)
162
177
  // check preventUpdate for an array (Line: 87)
163
178
  if (options.preventUpdate !== true && element.on && isFunction(element.on.update)) {
164
179
  applyEvent(element.on.update, created, created.state)