@domql/element 2.5.22 → 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
  };
@@ -42,7 +42,6 @@ var import_iterate = require("./iterate");
42
42
  var import_mixins = require("./mixins");
43
43
  var import_applyParam = require("./applyParam");
44
44
  var import_options = __toESM(require("./cache/options"), 1);
45
- var import_inherit = require("../state/inherit");
46
45
  const snapshot = {
47
46
  snapshotId: import_utils.createSnapshotId
48
47
  };
@@ -58,6 +57,7 @@ const update = function(params = {}, options = UPDATE_DEFAULT_OPTIONS) {
58
57
  const element = this;
59
58
  const { parent, node, key } = element;
60
59
  const { excludes, preventInheritAtCurrentState } = options;
60
+ (0, import_event.triggerEventOnUpdate)("startUpdate", params, element, options);
61
61
  if (preventInheritAtCurrentState && preventInheritAtCurrentState.__element === element)
62
62
  return;
63
63
  if (!excludes)
@@ -71,12 +71,12 @@ const update = function(params = {}, options = UPDATE_DEFAULT_OPTIONS) {
71
71
  if ((0, import_utils.isString)(params) || (0, import_utils.isNumber)(params)) {
72
72
  params = { text: params };
73
73
  }
74
- const ifFails = checkIfOnUpdate(element, parent, options);
75
- if (ifFails)
76
- return;
77
74
  const inheritState = inheritStateUpdates(element, options);
78
75
  if (inheritState === false)
79
76
  return;
77
+ const ifFails = checkIfOnUpdate(element, parent, options);
78
+ if (ifFails)
79
+ return;
80
80
  if (ref.__if && !options.preventPropsUpdate) {
81
81
  const hasParentProps = parent.props && (parent.props[key] || parent.props.childProps);
82
82
  const hasFunctionInProps = ref.__props.filter((v) => (0, import_utils.isFunction)(v));
@@ -147,7 +147,7 @@ const captureSnapshot = (element, options) => {
147
147
  return [snapshotOnCallee, calleeElement];
148
148
  };
149
149
  const checkIfOnUpdate = (element, parent, options) => {
150
- if (!(0, import_utils.isFunction)(element.if) || !element.state || !parent)
150
+ if (!(0, import_utils.isFunction)(element.if) || !parent)
151
151
  return;
152
152
  const ref = element.__ref;
153
153
  const ifPassed = element.if(element, element.state, element.context, options);
@@ -163,7 +163,16 @@ const checkIfOnUpdate = (element, parent, options) => {
163
163
  if (ref.__state) {
164
164
  element.state = ref.__state;
165
165
  }
166
- 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);
167
176
  if (options.preventUpdate !== true && element.on && (0, import_utils.isFunction)(element.on.update)) {
168
177
  (0, import_event.applyEvent)(element.on.update, created, created.state);
169
178
  }
@@ -191,7 +200,7 @@ const inheritStateUpdates = (element, options) => {
191
200
  state.set(execState, { ...options, preventUpdate: true });
192
201
  return;
193
202
  }
194
- const keyInParentState = (0, import_inherit.findInheritedState)(element, element.parent);
203
+ const keyInParentState = (0, import_state.findInheritedState)(element, element.parent);
195
204
  if (!keyInParentState || options.preventInheritedStateUpdate)
196
205
  return;
197
206
  if (!options.preventInitStateUpdateListener) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@domql/element",
3
- "version": "2.5.22",
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": "231fe90e14adace5408e9f5def451463ec1430ae",
34
+ "gitHead": "df470e5a96cda567c9d99cc98337eac0136d0890",
35
35
  "devDependencies": {
36
36
  "@babel/core": "^7.12.0"
37
37
  }
package/update.js CHANGED
@@ -4,7 +4,7 @@ import { window, exec, isArray, isFunction, isNumber, isObject, isString, isUnde
4
4
  import { applyEvent, triggerEventOn, triggerEventOnUpdate } from '@domql/event'
5
5
  import { isMethod } from './methods'
6
6
  import { updateProps } from './props'
7
- import { createState } from '@domql/state'
7
+ import { createState, findInheritedState } from '@domql/state'
8
8
 
9
9
  import { METHODS_EXL, isVariant } from './utils'
10
10
  import create from './create'
@@ -12,7 +12,6 @@ import { throughUpdatedDefine, throughUpdatedExec } from './iterate'
12
12
  import { registry } from './mixins'
13
13
  import { applyParam } from './applyParam'
14
14
  import OPTIONS from './cache/options'
15
- import { findInheritedState } from '../state/inherit'
16
15
 
17
16
  const snapshot = {
18
17
  snapshotId: createSnapshotId
@@ -32,6 +31,8 @@ const update = function (params = {}, options = UPDATE_DEFAULT_OPTIONS) {
32
31
  const { parent, node, key } = element
33
32
  const { excludes, preventInheritAtCurrentState } = options
34
33
 
34
+ triggerEventOnUpdate('startUpdate', params, element, options)
35
+
35
36
  if (preventInheritAtCurrentState && preventInheritAtCurrentState.__element === element) return
36
37
  if (!excludes) merge(options, UPDATE_DEFAULT_OPTIONS)
37
38
 
@@ -45,12 +46,12 @@ const update = function (params = {}, options = UPDATE_DEFAULT_OPTIONS) {
45
46
  params = { text: params }
46
47
  }
47
48
 
48
- const ifFails = checkIfOnUpdate(element, parent, options)
49
- if (ifFails) return
50
-
51
49
  const inheritState = inheritStateUpdates(element, options)
52
50
  if (inheritState === false) return
53
51
 
52
+ const ifFails = checkIfOnUpdate(element, parent, options)
53
+ if (ifFails) return
54
+
54
55
  if (ref.__if && !options.preventPropsUpdate) {
55
56
  const hasParentProps = parent.props && (parent.props[key] || parent.props.childProps)
56
57
  const hasFunctionInProps = ref.__props.filter(v => isFunction(v))
@@ -142,7 +143,7 @@ const captureSnapshot = (element, options) => {
142
143
  }
143
144
 
144
145
  const checkIfOnUpdate = (element, parent, options) => {
145
- if (!isFunction(element.if) || !element.state || !parent) return
146
+ if (!isFunction(element.if) || !parent) return
146
147
 
147
148
  const ref = element.__ref
148
149
  const ifPassed = element.if(element, element.state, element.context, options)
@@ -159,7 +160,20 @@ const checkIfOnUpdate = (element, parent, options) => {
159
160
  if (ref.__state) {
160
161
  element.state = ref.__state
161
162
  }
162
- 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)
163
177
  // check preventUpdate for an array (Line: 87)
164
178
  if (options.preventUpdate !== true && element.on && isFunction(element.on.update)) {
165
179
  applyEvent(element.on.update, created, created.state)