@domql/element 2.29.77 → 2.29.79

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.
@@ -19,6 +19,7 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
19
19
  var methods_exports = {};
20
20
  __export(methods_exports, {
21
21
  METHODS: () => METHODS,
22
+ append: () => append,
22
23
  call: () => call,
23
24
  defineSetter: () => defineSetter,
24
25
  error: () => error,
@@ -49,6 +50,7 @@ var import_event = require("@domql/event");
49
50
  var import_utils = require("@domql/utils");
50
51
  var import_tree = require("../tree.js");
51
52
  var import_mixins = require("../mixins/index.js");
53
+ var import_create = require("../create.js");
52
54
  function spotByPath(path) {
53
55
  const element = this;
54
56
  const arr = [].concat(path);
@@ -219,8 +221,10 @@ function verbose(element, ...args) {
219
221
  const { __ref: ref } = parent;
220
222
  console.groupCollapsed(parent.key);
221
223
  if (args.length) {
222
- args.forEach((v) => console.log(`%c${v}:
223
- `, "font-weight: bold", parent[v]));
224
+ args.forEach(
225
+ (v) => console.log(`%c${v}:
226
+ `, "font-weight: bold", parent[v])
227
+ );
224
228
  } else {
225
229
  console.log(ref.path);
226
230
  const keys2 = parent.keys();
@@ -250,6 +254,9 @@ function nextElement() {
250
254
  const nextChild = __children[currentIndex + 1];
251
255
  return parent[nextChild];
252
256
  }
257
+ async function append(el, key) {
258
+ return await (0, import_create.create)(el, this, key);
259
+ }
253
260
  function previousElement(el) {
254
261
  const element = el || this;
255
262
  const { key, parent } = element;
@@ -331,6 +338,7 @@ const METHODS = [
331
338
  "error",
332
339
  "call",
333
340
  "nextElement",
341
+ "append",
334
342
  "previousElement"
335
343
  ];
336
344
  function isMethod(param, element) {
@@ -52,8 +52,10 @@ const addMethods = (element, parent, options = {}) => {
52
52
  verbose: import_index.verbose,
53
53
  warn: import_index.warn,
54
54
  error: import_index.error,
55
+ append: import_index.append,
55
56
  call: import_index.call
56
57
  };
57
- if (element.context.methods) (options.strict ? import_utils.merge : import_utils.overwrite)(proto, element.context.methods);
58
+ if (element.context.methods)
59
+ (options.strict ? import_utils.merge : import_utils.overwrite)(proto, element.context.methods);
58
60
  Object.setPrototypeOf(element, proto);
59
61
  };
@@ -81,6 +81,8 @@ const REGISTRY = {
81
81
  lookdownAll: {},
82
82
  setNodeStyles: {},
83
83
  spotByPath: {},
84
+ append: {},
85
+ routes: {},
84
86
  keys: {},
85
87
  log: {},
86
88
  parse: {},
@@ -78,6 +78,7 @@ const METHODS = [
78
78
  "getPath",
79
79
  "setNodeStyles",
80
80
  "spotByPath",
81
+ "append",
81
82
  "keys",
82
83
  "parse",
83
84
  "setProps",
@@ -6,11 +6,11 @@ import {
6
6
  isObjectLike,
7
7
  isProduction,
8
8
  removeValueFromArray,
9
- deepClone,
10
- isNotProduction
9
+ deepClone
11
10
  } from "@domql/utils";
12
11
  import { TREE } from "../tree.js";
13
12
  import { parseFilters, REGISTRY } from "../mixins/index.js";
13
+ import { create } from "../create.js";
14
14
  function spotByPath(path) {
15
15
  const element = this;
16
16
  const arr = [].concat(path);
@@ -181,8 +181,10 @@ function verbose(element, ...args) {
181
181
  const { __ref: ref } = parent;
182
182
  console.groupCollapsed(parent.key);
183
183
  if (args.length) {
184
- args.forEach((v) => console.log(`%c${v}:
185
- `, "font-weight: bold", parent[v]));
184
+ args.forEach(
185
+ (v) => console.log(`%c${v}:
186
+ `, "font-weight: bold", parent[v])
187
+ );
186
188
  } else {
187
189
  console.log(ref.path);
188
190
  const keys2 = parent.keys();
@@ -212,6 +214,9 @@ function nextElement() {
212
214
  const nextChild = __children[currentIndex + 1];
213
215
  return parent[nextChild];
214
216
  }
217
+ async function append(el, key) {
218
+ return await create(el, this, key);
219
+ }
215
220
  function previousElement(el) {
216
221
  const element = el || this;
217
222
  const { key, parent } = element;
@@ -293,6 +298,7 @@ const METHODS = [
293
298
  "error",
294
299
  "call",
295
300
  "nextElement",
301
+ "append",
296
302
  "previousElement"
297
303
  ];
298
304
  function isMethod(param, element) {
@@ -301,6 +307,7 @@ function isMethod(param, element) {
301
307
  }
302
308
  export {
303
309
  METHODS,
310
+ append,
304
311
  call,
305
312
  defineSetter,
306
313
  error,
@@ -22,6 +22,7 @@ import {
22
22
  spotByPath,
23
23
  variables,
24
24
  verbose,
25
+ append,
25
26
  warn
26
27
  } from "./index.js";
27
28
  const addMethods = (element, parent, options = {}) => {
@@ -50,9 +51,11 @@ const addMethods = (element, parent, options = {}) => {
50
51
  verbose,
51
52
  warn,
52
53
  error,
54
+ append,
53
55
  call
54
56
  };
55
- if (element.context.methods) (options.strict ? merge : overwrite)(proto, element.context.methods);
57
+ if (element.context.methods)
58
+ (options.strict ? merge : overwrite)(proto, element.context.methods);
56
59
  Object.setPrototypeOf(element, proto);
57
60
  };
58
61
  export {
@@ -55,6 +55,8 @@ const REGISTRY = {
55
55
  lookdownAll: {},
56
56
  setNodeStyles: {},
57
57
  spotByPath: {},
58
+ append: {},
59
+ routes: {},
58
60
  keys: {},
59
61
  log: {},
60
62
  parse: {},
@@ -1,4 +1,10 @@
1
- import { isArray, isObject, isObjectLike, joinArrays, deepClone } from "@domql/utils";
1
+ import {
2
+ isArray,
3
+ isObject,
4
+ isObjectLike,
5
+ joinArrays,
6
+ deepClone
7
+ } from "@domql/utils";
2
8
  import { IGNORE_PROPS_PARAMS } from "../props/index.js";
3
9
  const IGNORE_STATE_PARAMS = [
4
10
  "update",
@@ -45,6 +51,7 @@ const METHODS = [
45
51
  "getPath",
46
52
  "setNodeStyles",
47
53
  "spotByPath",
54
+ "append",
48
55
  "keys",
49
56
  "parse",
50
57
  "setProps",
package/methods/index.js CHANGED
@@ -8,14 +8,14 @@ import {
8
8
  isObjectLike,
9
9
  isProduction,
10
10
  removeValueFromArray,
11
- deepClone,
12
- isNotProduction
11
+ deepClone
13
12
  } from '@domql/utils'
14
13
  import { TREE } from '../tree.js'
15
14
  import { parseFilters, REGISTRY } from '../mixins/index.js'
15
+ import { create } from '../create.js'
16
16
 
17
17
  // TODO: update these files
18
- export function spotByPath (path) {
18
+ export function spotByPath(path) {
19
19
  const element = this
20
20
  const arr = [].concat(path)
21
21
  let active = TREE[arr[0]]
@@ -34,7 +34,7 @@ export function spotByPath (path) {
34
34
  }
35
35
 
36
36
  // TODO: update these files
37
- export function lookup (param) {
37
+ export function lookup(param) {
38
38
  const el = this
39
39
  let { parent } = el
40
40
 
@@ -56,7 +56,7 @@ export function lookup (param) {
56
56
  return parent
57
57
  }
58
58
 
59
- export function lookdown (param) {
59
+ export function lookdown(param) {
60
60
  const el = this
61
61
  const { __ref: ref } = el
62
62
  const children = ref?.__children
@@ -79,7 +79,7 @@ export function lookdown (param) {
79
79
  }
80
80
  }
81
81
 
82
- export function lookdownAll (param, results = []) {
82
+ export function lookdownAll(param, results = []) {
83
83
  const el = this
84
84
  const { __ref: ref } = el
85
85
  const children = ref?.__children
@@ -101,7 +101,7 @@ export function lookdownAll (param, results = []) {
101
101
  return results.length ? results : undefined
102
102
  }
103
103
 
104
- export function setNodeStyles (params = {}) {
104
+ export function setNodeStyles(params = {}) {
105
105
  const el = this
106
106
  if (!el.node?.style) return
107
107
 
@@ -115,7 +115,7 @@ export function setNodeStyles (params = {}) {
115
115
  return el
116
116
  }
117
117
 
118
- export async function remove (opts) {
118
+ export async function remove(opts) {
119
119
  const element = this
120
120
  const beforeRemoveReturns = triggerEventOn('beforeRemove', element, opts)
121
121
  if (beforeRemoveReturns === false) return element
@@ -133,29 +133,29 @@ export async function remove (opts) {
133
133
  await triggerEventOn('remove', element, opts)
134
134
  }
135
135
 
136
- export function get (param) {
136
+ export function get(param) {
137
137
  const element = this
138
138
  return element[param]
139
139
  }
140
140
 
141
- export function setProps (param, options) {
141
+ export function setProps(param, options) {
142
142
  const element = this
143
143
  if (!param || !element.props) return
144
144
  element.update({ props: param }, options)
145
145
  return element
146
146
  }
147
147
 
148
- export function getRef (key) {
148
+ export function getRef(key) {
149
149
  if (key) return this.__ref && this.__ref[key]
150
150
  return this.__ref
151
151
  }
152
152
 
153
- export function getChildren () {
153
+ export function getChildren() {
154
154
  const __children = this.getRef('__children')
155
- return __children.map(k => this[k])
155
+ return __children.map((k) => this[k])
156
156
  }
157
157
 
158
- export function getPath () {
158
+ export function getPath() {
159
159
  return this.getRef().path
160
160
  }
161
161
 
@@ -168,7 +168,7 @@ export function getPath () {
168
168
  export const defineSetter = (element, key, get, set) =>
169
169
  Object.defineProperty(element, key, { get, set })
170
170
 
171
- export function keys () {
171
+ export function keys() {
172
172
  const element = this
173
173
  const keys = []
174
174
  for (const param in element) {
@@ -183,11 +183,11 @@ export function keys () {
183
183
  return keys
184
184
  }
185
185
 
186
- export function parse (excl = []) {
186
+ export function parse(excl = []) {
187
187
  const element = this
188
188
  const obj = {}
189
189
  const keyList = keys.call(element)
190
- keyList.forEach(v => {
190
+ keyList.forEach((v) => {
191
191
  if (excl.includes(v)) return
192
192
  const val = element[v]
193
193
  if (v === 'state') {
@@ -208,7 +208,7 @@ export function parse (excl = []) {
208
208
  return obj
209
209
  }
210
210
 
211
- export function parseDeep (excl = []) {
211
+ export function parseDeep(excl = []) {
212
212
  const element = this
213
213
  const obj = parse.call(element, excl)
214
214
  for (const v in obj) {
@@ -220,37 +220,39 @@ export function parseDeep (excl = []) {
220
220
  return obj
221
221
  }
222
222
 
223
- export function verbose (element, ...args) {
223
+ export function verbose(element, ...args) {
224
224
  if (isProduction()) return
225
225
 
226
226
  const parent = this
227
227
  const { __ref: ref } = parent
228
228
  console.groupCollapsed(parent.key)
229
229
  if (args.length) {
230
- args.forEach(v => console.log(`%c${v}:\n`, 'font-weight: bold', parent[v]))
230
+ args.forEach((v) =>
231
+ console.log(`%c${v}:\n`, 'font-weight: bold', parent[v])
232
+ )
231
233
  } else {
232
234
  console.log(ref.path)
233
235
  const keys = parent.keys()
234
- keys.forEach(v => console.log(`%c${v}:`, 'font-weight: bold', parent[v]))
236
+ keys.forEach((v) => console.log(`%c${v}:`, 'font-weight: bold', parent[v]))
235
237
  }
236
238
  console.log(parent)
237
239
  console.groupEnd(parent.key)
238
240
  return parent
239
241
  }
240
242
 
241
- export function log (...params) {
243
+ export function log(...params) {
242
244
  // if (isNotProduction()) {
243
245
  console.log(...params)
244
246
  // }
245
247
  }
246
248
 
247
- export function warn (...params) {
249
+ export function warn(...params) {
248
250
  // if (isNotProduction()) {
249
251
  console.warn(...params)
250
252
  // }
251
253
  }
252
254
 
253
- export function error (...params) {
255
+ export function error(...params) {
254
256
  // if (isNotProduction()) {
255
257
  if (params[params.length - 1]?.debugger) debugger // eslint-disable-line
256
258
  if (params[params.length - 1]?.verbose) verbose.call(this, ...params)
@@ -258,7 +260,7 @@ export function error (...params) {
258
260
  // }
259
261
  }
260
262
 
261
- export function nextElement () {
263
+ export function nextElement() {
262
264
  const element = this
263
265
  const { key, parent } = element
264
266
  const { __children } = parent.__ref
@@ -269,7 +271,11 @@ export function nextElement () {
269
271
  return parent[nextChild]
270
272
  }
271
273
 
272
- export function previousElement (el) {
274
+ export async function append(el, key) {
275
+ return await create(el, this, key)
276
+ }
277
+
278
+ export function previousElement(el) {
273
279
  const element = el || this
274
280
  const { key, parent } = element
275
281
  const { __children } = parent.__ref
@@ -280,7 +286,7 @@ export function previousElement (el) {
280
286
  return parent[__children[currentIndex - 1]]
281
287
  }
282
288
 
283
- export function variables (obj = {}) {
289
+ export function variables(obj = {}) {
284
290
  const element = this
285
291
  if (!element.data) element.data = {}
286
292
  if (!element.data.varCaches) element.data.varCaches = {}
@@ -294,7 +300,7 @@ export function variables (obj = {}) {
294
300
  }
295
301
  }
296
302
  return {
297
- changed: cb => {
303
+ changed: (cb) => {
298
304
  if (!changed || !varCaches) return
299
305
  const returns = cb(changes, deepClone(varCaches))
300
306
  for (const key in changes) {
@@ -321,7 +327,7 @@ export function variables (obj = {}) {
321
327
  * @param {...any} args - Arguments to pass to the function
322
328
  * @returns {any|Promise} - The result or a Promise to the result
323
329
  */
324
- export function call (fnKey, ...args) {
330
+ export function call(fnKey, ...args) {
325
331
  const fn =
326
332
  this.context.utils?.[fnKey] ||
327
333
  this.context.functions?.[fnKey] ||
@@ -376,9 +382,10 @@ export const METHODS = [
376
382
  'error',
377
383
  'call',
378
384
  'nextElement',
385
+ 'append',
379
386
  'previousElement'
380
387
  ]
381
388
 
382
- export function isMethod (param, element) {
389
+ export function isMethod(param, element) {
383
390
  return METHODS.includes(param) || element?.context?.methods?.[param]
384
391
  }
package/methods/set.js CHANGED
@@ -26,6 +26,7 @@ import {
26
26
  spotByPath,
27
27
  variables,
28
28
  verbose,
29
+ append,
29
30
  warn
30
31
  } from './index.js'
31
32
 
@@ -55,8 +56,10 @@ export const addMethods = (element, parent, options = {}) => {
55
56
  verbose,
56
57
  warn,
57
58
  error,
59
+ append,
58
60
  call
59
61
  }
60
- if (element.context.methods) (options.strict ? merge : overwrite)(proto, element.context.methods)
62
+ if (element.context.methods)
63
+ (options.strict ? merge : overwrite)(proto, element.context.methods)
61
64
  Object.setPrototypeOf(element, proto)
62
65
  }
@@ -60,6 +60,8 @@ export const REGISTRY = {
60
60
  lookdownAll: {},
61
61
  setNodeStyles: {},
62
62
  spotByPath: {},
63
+ append: {},
64
+ routes: {},
63
65
  keys: {},
64
66
  log: {},
65
67
  parse: {},
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@domql/element",
3
- "version": "2.29.77",
3
+ "version": "2.29.79",
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.29.77",
31
- "@domql/render": "^2.29.77",
32
- "@domql/state": "^2.29.77",
33
- "@domql/utils": "^2.29.77"
30
+ "@domql/event": "^2.29.79",
31
+ "@domql/render": "^2.29.79",
32
+ "@domql/state": "^2.29.79",
33
+ "@domql/utils": "^2.29.79"
34
34
  },
35
- "gitHead": "576ad1140f3bbb46be9531ec57c50136bcd5d2f1",
35
+ "gitHead": "aefa41e70ddc76983c23822905afa22a2b944299",
36
36
  "devDependencies": {
37
37
  "@babel/core": "^7.27.1"
38
38
  }
package/utils/object.js CHANGED
@@ -1,6 +1,12 @@
1
1
  'use strict'
2
2
 
3
- import { isArray, isObject, isObjectLike, joinArrays, deepClone } from '@domql/utils'
3
+ import {
4
+ isArray,
5
+ isObject,
6
+ isObjectLike,
7
+ joinArrays,
8
+ deepClone
9
+ } from '@domql/utils'
4
10
  import { IGNORE_PROPS_PARAMS } from '../props/index.js'
5
11
 
6
12
  // breaks server build
@@ -8,10 +14,35 @@ import { IGNORE_PROPS_PARAMS } from '../props/index.js'
8
14
  // import { METHODS } from '../methods'
9
15
 
10
16
  const IGNORE_STATE_PARAMS = [
11
- 'update', 'parse', 'clean', 'create', 'destroy', 'add', 'toggle', 'remove', 'apply', 'set', 'reset',
12
- 'replace', 'quietReplace', 'quietUpdate', 'applyReplace', 'applyFunction',
13
- 'rootUpdate', 'parentUpdate', 'parent', '__element', '__depends', '__ref', '__children', 'root',
14
- 'setByPath', 'setPathCollection', 'removeByPath', 'removePathCollection', 'getByPath'
17
+ 'update',
18
+ 'parse',
19
+ 'clean',
20
+ 'create',
21
+ 'destroy',
22
+ 'add',
23
+ 'toggle',
24
+ 'remove',
25
+ 'apply',
26
+ 'set',
27
+ 'reset',
28
+ 'replace',
29
+ 'quietReplace',
30
+ 'quietUpdate',
31
+ 'applyReplace',
32
+ 'applyFunction',
33
+ 'rootUpdate',
34
+ 'parentUpdate',
35
+ 'parent',
36
+ '__element',
37
+ '__depends',
38
+ '__ref',
39
+ '__children',
40
+ 'root',
41
+ 'setByPath',
42
+ 'setPathCollection',
43
+ 'removeByPath',
44
+ 'removePathCollection',
45
+ 'getByPath'
15
46
  ]
16
47
 
17
48
  export const METHODS = [
@@ -28,6 +59,7 @@ export const METHODS = [
28
59
  'getPath',
29
60
  'setNodeStyles',
30
61
  'spotByPath',
62
+ 'append',
31
63
  'keys',
32
64
  'parse',
33
65
  'setProps',
@@ -145,14 +177,17 @@ export const mergeIfExisted = (a, b) => {
145
177
  /**
146
178
  * Merges array extends
147
179
  */
148
- export const mergeArray = (arr, exclude = ['parent', 'node', '__element', 'state', 'context', '__ref']) => {
180
+ export const mergeArray = (
181
+ arr,
182
+ exclude = ['parent', 'node', '__element', 'state', 'context', '__ref']
183
+ ) => {
149
184
  return arr.reduce((a, c) => deepMerge(a, deepClone(c, { exclude })), {})
150
185
  }
151
186
 
152
187
  /**
153
188
  * Merges array extends
154
189
  */
155
- export const mergeAndCloneIfArray = obj => {
190
+ export const mergeAndCloneIfArray = (obj) => {
156
191
  return isArray(obj) ? mergeArray(obj) : deepClone(obj)
157
192
  }
158
193