@domql/element 2.5.129 → 2.5.130

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
@@ -24,19 +24,19 @@ import {
24
24
  isNode,
25
25
  isUndefined,
26
26
  generateKey,
27
+ checkIfKeyIsComponent,
27
28
  deepCloneWithExtend,
29
+ applyComponentFromContext,
30
+ applyKeyComponentAsExtend,
31
+ isVariant,
28
32
  detectInfiniteLoop
29
33
  } from '@domql/utils'
30
34
 
31
35
  import OPTIONS from './cache/options'
32
36
 
33
37
  import {
34
- applyComponentFromContext,
35
- applyKeyComponentAsExtend,
36
38
  applyVariant,
37
- checkIfKeyIsComponent,
38
- createValidDomqlObjectFromSugar,
39
- isVariant
39
+ createValidDomqlObjectFromSugar
40
40
  } from './utils/component'
41
41
 
42
42
  const ENV = process.env.NODE_ENV
@@ -59,7 +59,7 @@ const create = (element, parent, key, options = import_options.default.create ||
59
59
  const ref = addRef(element, parent, key);
60
60
  ref.__initialProps = (0, import_utils.deepCloneWithExtend)(element.props, []);
61
61
  applyContext(element, parent, options);
62
- (0, import_component.applyComponentFromContext)(element, parent, options);
62
+ (0, import_utils.applyComponentFromContext)(element, parent, options);
63
63
  if (!ref.__skipCreate) {
64
64
  (0, import_extend.applyExtend)(element, parent, options);
65
65
  }
@@ -122,8 +122,8 @@ const redefineElement = (element, parent, key, options) => {
122
122
  else
123
123
  element.syntaxv3 = true;
124
124
  return (0, import_component.createValidDomqlObjectFromSugar)(element, parent, key, options);
125
- } else if ((0, import_component.checkIfKeyIsComponent)(key)) {
126
- return (0, import_component.applyKeyComponentAsExtend)(elementWrapper, parent, key);
125
+ } else if ((0, import_utils.checkIfKeyIsComponent)(key)) {
126
+ return (0, import_utils.applyKeyComponentAsExtend)(elementWrapper, parent, key);
127
127
  }
128
128
  if (checkIfMedia(key)) {
129
129
  return applyMediaProps(elementWrapper, parent, key);
@@ -244,7 +244,7 @@ const addCaching = (element, parent) => {
244
244
  ref.__changes = [];
245
245
  if (!ref.__children)
246
246
  ref.__children = [];
247
- if ((0, import_component.checkIfKeyIsComponent)(key))
247
+ if ((0, import_utils.checkIfKeyIsComponent)(key))
248
248
  ref.__componentKey = key.split("_")[0].split(".")[0].split("+")[0];
249
249
  const hasRoot = parent && parent.key === ":root";
250
250
  if (!ref.root)
@@ -279,7 +279,7 @@ const onlyResolveExtends = (element, parent, key, options) => {
279
279
  (0, import_iterate.throughInitialDefine)(element);
280
280
  (0, import_iterate.throughInitialExec)(element);
281
281
  for (const k in element) {
282
- if ((0, import_utils.isUndefined)(element[k]) || (0, import_methods.isMethod)(k) || (0, import_utils.isObject)(import_mixins.registry[k]) || (0, import_component.isVariant)(k))
282
+ if ((0, import_utils.isUndefined)(element[k]) || (0, import_methods.isMethod)(k) || (0, import_utils.isObject)(import_mixins.registry[k]) || (0, import_utils.isVariant)(k))
283
283
  continue;
284
284
  const hasDefine = element.define && element.define[k];
285
285
  const contextHasDefine = element.context && element.context.define && element.context.define[k];
@@ -33,7 +33,7 @@ const throughInitialExec = (element, exclude = {}) => {
33
33
  if (exclude[param])
34
34
  continue;
35
35
  const prop = element[param];
36
- if ((0, import_utils.isFunction)(prop) && !(0, import_methods.isMethod)(param) && !(0, import_utils2.isVariant)(param)) {
36
+ if ((0, import_utils.isFunction)(prop) && !(0, import_methods.isMethod)(param) && !(0, import_utils.isVariant)(param)) {
37
37
  ref.__exec[param] = prop;
38
38
  element[param] = prop(element, element.state, element.context);
39
39
  }
@@ -52,8 +52,8 @@ const throughUpdatedExec = (element, options = { excludes: import_utils2.METHODS
52
52
  if (prop && prop.node && execReturnsString) {
53
53
  (0, import_utils2.overwrite)(prop, { text: newExec }, options);
54
54
  } else if (newExec !== prop) {
55
- if ((0, import_utils2.checkIfKeyIsComponent)(param)) {
56
- const { extend, ...newElem } = (0, import_utils2.extendizeByKey)(newExec, element, param);
55
+ if ((0, import_utils.checkIfKeyIsComponent)(param)) {
56
+ const { extend, ...newElem } = (0, import_utils.extendizeByKey)(newExec, element, param);
57
57
  (0, import_utils2.overwrite)(prop, newElem, options);
58
58
  } else {
59
59
  ref.__cached[param] = changes[param] = prop;
@@ -73,7 +73,7 @@ const throughInitialDefine = (element) => {
73
73
  defineObj = { ...defineObj, ...context.define };
74
74
  for (const param in defineObj) {
75
75
  let elementProp = element[param];
76
- if ((0, import_utils.isFunction)(elementProp) && !(0, import_methods.isMethod)(param) && !(0, import_utils2.isVariant)(param)) {
76
+ if ((0, import_utils.isFunction)(elementProp) && !(0, import_methods.isMethod)(param) && !(0, import_utils.isVariant)(param)) {
77
77
  ref.__exec[param] = elementProp;
78
78
  const execParam2 = elementProp = (0, import_utils.exec)(elementProp, element);
79
79
  if (execParam2) {
package/dist/cjs/node.js CHANGED
@@ -40,7 +40,6 @@ var import_create = __toESM(require("./create"), 1);
40
40
  var import_iterate = require("./iterate");
41
41
  var import_mixins = require("./mixins");
42
42
  var import_applyParam = require("./utils/applyParam");
43
- var import_utils2 = require("./utils");
44
43
  var import_propEvents = require("./utils/propEvents");
45
44
  const ENV = "development";
46
45
  const createNode = (element, options) => {
@@ -74,7 +73,7 @@ const createNode = (element, options) => {
74
73
  const value = element[param];
75
74
  if (!Object.hasOwnProperty.call(element, param))
76
75
  continue;
77
- if ((0, import_utils.isUndefined)(value) || (0, import_methods.isMethod)(param) || (0, import_utils2.isVariant)(param) || (0, import_utils.isObject)(import_mixins.registry[param]))
76
+ if ((0, import_utils.isUndefined)(value) || (0, import_methods.isMethod)(param) || (0, import_utils.isVariant)(param) || (0, import_utils.isObject)(import_mixins.registry[param]))
78
77
  continue;
79
78
  const isElement = (0, import_applyParam.applyParam)(param, element, options);
80
79
  if (isElement) {
@@ -138,7 +138,7 @@ const update = function(params = {}, opts) {
138
138
  const isInPreventUpdate = (0, import_utils.isArray)(preventUpdate) && preventUpdate.includes(param);
139
139
  const isInPreventDefineUpdate = (0, import_utils.isArray)(preventDefineUpdate) && preventDefineUpdate.includes(param);
140
140
  const hasCollection = element.$collection || element.$stateCollection || element.$propsCollection;
141
- if ((0, import_utils.isUndefined)(prop) || hasOnlyUpdateFalsy || isInPreventUpdate || isInPreventDefineUpdate || preventDefineUpdate === true || preventDefineUpdate === param || preventContentUpdate && param === "content" && !hasCollection || (preventStateUpdate && param) === "state" || (0, import_methods.isMethod)(param) || (0, import_utils.isObject)(import_mixins.registry[param]) || (0, import_utils2.isVariant)(param))
141
+ if ((0, import_utils.isUndefined)(prop) || hasOnlyUpdateFalsy || isInPreventUpdate || isInPreventDefineUpdate || preventDefineUpdate === true || preventDefineUpdate === param || preventContentUpdate && param === "content" && !hasCollection || (preventStateUpdate && param) === "state" || (0, import_methods.isMethod)(param) || (0, import_utils.isObject)(import_mixins.registry[param]) || (0, import_utils.isVariant)(param))
142
142
  continue;
143
143
  if (preventStateUpdate === "once")
144
144
  options.preventStateUpdate = false;
@@ -18,44 +18,14 @@ var __copyProps = (to, from, except, desc) => {
18
18
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
19
  var component_exports = {};
20
20
  __export(component_exports, {
21
- addAdditionalExtend: () => addAdditionalExtend,
22
- applyComponentFromContext: () => applyComponentFromContext,
23
- applyKeyComponentAsExtend: () => applyKeyComponentAsExtend,
24
21
  applyVariant: () => applyVariant,
25
- checkIfKeyIsComponent: () => checkIfKeyIsComponent,
26
- checkIfKeyIsProperty: () => checkIfKeyIsProperty,
27
22
  createValidDomqlObjectFromSugar: () => createValidDomqlObjectFromSugar,
28
- extendizeByKey: () => extendizeByKey,
29
- hasVariantProp: () => hasVariantProp,
30
- isVariant: () => isVariant,
31
23
  overwriteVariant: () => overwriteVariant
32
24
  });
33
25
  module.exports = __toCommonJS(component_exports);
34
26
  var import_utils = require("@domql/utils");
35
27
  var import_extend = require("../extend");
36
28
  var import_mixins = require("../mixins");
37
- const ENV = "development";
38
- const checkIfKeyIsComponent = (key) => {
39
- const isFirstKeyString = (0, import_utils.isString)(key);
40
- if (!isFirstKeyString)
41
- return;
42
- const firstCharKey = key.slice(0, 1);
43
- return /^[A-Z]*$/.test(firstCharKey);
44
- };
45
- const checkIfKeyIsProperty = (key) => {
46
- const isFirstKeyString = (0, import_utils.isString)(key);
47
- if (!isFirstKeyString)
48
- return;
49
- const firstCharKey = key.slice(0, 1);
50
- return /^[a-z]*$/.test(firstCharKey);
51
- };
52
- const addAdditionalExtend = (newExtend, element) => {
53
- const { extend: elementExtend } = element;
54
- const originalArray = (0, import_utils.isArray)(elementExtend) ? elementExtend : [elementExtend];
55
- const receivedArray = (0, import_utils.isArray)(newExtend) ? newExtend : [newExtend];
56
- const extend = (0, import_utils.joinArrays)(receivedArray, originalArray);
57
- return { ...element, extend };
58
- };
59
29
  const replaceOnKeys = (key) => key.replace(/on\w+/g, (match) => match.substring(2));
60
30
  const createValidDomqlObjectFromSugar = (el, parent, key, options) => {
61
31
  const newElem = {
@@ -69,7 +39,7 @@ const createValidDomqlObjectFromSugar = (el, parent, key, options) => {
69
39
  const onKey = replaceOnKeys(prop);
70
40
  newElem.on[onKey] = prop;
71
41
  }
72
- const isComponent = checkIfKeyIsComponent(k);
42
+ const isComponent = (0, import_utils.checkIfKeyIsComponent)(k);
73
43
  const isRegistry = import_mixins.registry[k];
74
44
  if (isComponent || isRegistry) {
75
45
  newElem[k] = prop;
@@ -79,70 +49,6 @@ const createValidDomqlObjectFromSugar = (el, parent, key, options) => {
79
49
  }
80
50
  return newElem;
81
51
  };
82
- const extendizeByKey = (element, parent, key) => {
83
- const { context } = parent;
84
- const { tag, extend, props, attr, state, childExtend, childProps, on, if: condition, data } = element;
85
- const hasComponentAttrs = extend || childExtend || props || state || on || condition || attr || data;
86
- const extendFromKey = key.includes("+") ? key.split("+") : key.includes("_") ? [key.split("_")[0]] : key.includes(".") && !checkIfKeyIsComponent(key.split(".")[1]) ? [key.split(".")[0]] : [key];
87
- const isExtendKeyComponent = context && context.components[extendFromKey];
88
- if (element === isExtendKeyComponent)
89
- return element;
90
- else if (!hasComponentAttrs || childProps) {
91
- return {
92
- extend: extendFromKey,
93
- tag,
94
- props: { ...element }
95
- };
96
- } else if (!extend || extend === true) {
97
- return {
98
- ...element,
99
- tag,
100
- extend: extendFromKey
101
- };
102
- } else if (extend) {
103
- return addAdditionalExtend(extendFromKey, element);
104
- } else if ((0, import_utils.isFunction)(element)) {
105
- return {
106
- extend: extendFromKey,
107
- tag,
108
- props: { ...(0, import_utils.exec)(element, parent) }
109
- };
110
- }
111
- };
112
- const applyKeyComponentAsExtend = (element, parent, key) => {
113
- return extendizeByKey(element, parent, key) || element;
114
- };
115
- const applyComponentFromContext = (element, parent, options) => {
116
- const { context } = element;
117
- if (!context || !context.components)
118
- return;
119
- const { components } = context;
120
- const { extend } = element;
121
- const execExtend = (0, import_utils.exec)(extend, element);
122
- if ((0, import_utils.isString)(execExtend)) {
123
- const componentExists = components[execExtend] || components["smbls." + execExtend];
124
- if (componentExists)
125
- element.extend = componentExists;
126
- else {
127
- if ((ENV === "test" || ENV === "development") && options.verbose) {
128
- console.warn(execExtend, "is not in library", components, element);
129
- console.warn("replacing with ", {});
130
- }
131
- element.extend = {};
132
- }
133
- }
134
- };
135
- const isVariant = (param) => {
136
- if (!(0, import_utils.isString)(param))
137
- return;
138
- const firstCharKey = param.slice(0, 1);
139
- return firstCharKey === ".";
140
- };
141
- const hasVariantProp = (element) => {
142
- const { props } = element;
143
- if ((0, import_utils.isObject)(props) && (0, import_utils.isString)(props.variant))
144
- return true;
145
- };
146
52
  const overwriteVariant = (element, variant, variantProps) => {
147
53
  let variantElement = element[variant];
148
54
  if (!variantElement)
@@ -153,7 +59,7 @@ const overwriteVariant = (element, variant, variantProps) => {
153
59
  extend: [{ props }, variantElement]
154
60
  };
155
61
  } else if (variantElement.extend) {
156
- variantElement = addAdditionalExtend({ props }, variantElement);
62
+ variantElement = (0, import_utils.addAdditionalExtend)({ props }, variantElement);
157
63
  }
158
64
  const extendedVariant = (0, import_extend.applyExtend)(variantElement, element.parent);
159
65
  const { parent, ...rest } = extendedVariant;
@@ -161,11 +67,11 @@ const overwriteVariant = (element, variant, variantProps) => {
161
67
  };
162
68
  const applyVariant = (element) => {
163
69
  const { props } = element;
164
- if (!hasVariantProp(element))
70
+ if (!(0, import_utils.hasVariantProp)(element))
165
71
  return element;
166
72
  const { variant } = props;
167
73
  overwriteVariant(element, `.${variant}`);
168
- const elKeys = Object.keys(element).filter((key) => isVariant(key));
74
+ const elKeys = Object.keys(element).filter((key) => (0, import_utils.isVariant)(key));
169
75
  elKeys.forEach((variant2) => {
170
76
  const slicedVariantElementKey = variant2.slice(1);
171
77
  const variantElementProps = props[slicedVariantElementKey];
package/iterate.js CHANGED
@@ -1,7 +1,17 @@
1
1
  'use strict'
2
2
 
3
- import { isObject, exec, isFunction, isNumber, isString } from '@domql/utils'
4
- import { METHODS_EXL, checkIfKeyIsComponent, extendizeByKey, isVariant, overwrite } from './utils'
3
+ import {
4
+ isObject,
5
+ exec,
6
+ isFunction,
7
+ isNumber,
8
+ isString,
9
+ checkIfKeyIsComponent,
10
+ extendizeByKey,
11
+ isVariant
12
+ } from '@domql/utils'
13
+
14
+ import { METHODS_EXL, overwrite } from './utils'
5
15
  import { isMethod } from './methods'
6
16
 
7
17
  export const throughInitialExec = (element, exclude = {}) => {
package/node.js CHANGED
@@ -1,6 +1,6 @@
1
1
  'use strict'
2
2
 
3
- import { exec, isFunction, isObject, isUndefined } from '@domql/utils'
3
+ import { exec, isFunction, isObject, isUndefined, isVariant } from '@domql/utils'
4
4
  import { applyEventsOnNode, triggerEventOn, applyAnimationFrame } from '@domql/event'
5
5
  import { cacheNode } from '@domql/render'
6
6
  import { isMethod } from './methods'
@@ -13,7 +13,6 @@ import {
13
13
  } from './iterate'
14
14
  import { registry } from './mixins'
15
15
  import { applyParam } from './utils/applyParam'
16
- import { isVariant } from './utils'
17
16
  import { propagateEventsFromProps } from './utils/propEvents'
18
17
  // import { defineSetter } from './methods'
19
18
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@domql/element",
3
- "version": "2.5.129",
3
+ "version": "2.5.130",
4
4
  "license": "MIT",
5
5
  "type": "module",
6
6
  "module": "index.js",
@@ -9,7 +9,8 @@
9
9
  ".": {
10
10
  "kalduna": "./index.js",
11
11
  "default": "./dist/cjs/index.js"
12
- }
12
+ },
13
+ "./utils/component": "./utils/component.js"
13
14
  },
14
15
  "source": "index.js",
15
16
  "files": [
@@ -31,7 +32,7 @@
31
32
  "@domql/state": "latest",
32
33
  "@domql/utils": "latest"
33
34
  },
34
- "gitHead": "a1a3e4b7cc65070a97310196950bb88481741356",
35
+ "gitHead": "88815c621b7aeb9458c779643934c0d2e5305cd2",
35
36
  "devDependencies": {
36
37
  "@babel/core": "^7.12.0"
37
38
  }
package/update.js CHANGED
@@ -10,6 +10,7 @@ import {
10
10
  isString,
11
11
  isUndefined,
12
12
  merge,
13
+ isVariant,
13
14
  overwriteDeep,
14
15
  createSnapshotId
15
16
  } from '@domql/utils'
@@ -24,7 +25,7 @@ import { throughUpdatedDefine, throughUpdatedExec } from './iterate'
24
25
  import { registry } from './mixins'
25
26
  import { applyParam } from './utils/applyParam'
26
27
  import OPTIONS from './cache/options'
27
- import { METHODS_EXL, deepClone, isVariant, deepMerge } from './utils'
28
+ import { METHODS_EXL, deepClone, deepMerge } from './utils' // old utils (current)
28
29
 
29
30
  const snapshot = {
30
31
  snapshotId: createSnapshotId
@@ -1,31 +1,17 @@
1
1
  'use strict'
2
2
 
3
- import { exec, isArray, isFunction, isObject, isString, joinArrays, overwriteDeep } from '@domql/utils'
3
+ import {
4
+ isObject,
5
+ isString,
6
+ overwriteDeep,
7
+ checkIfKeyIsComponent,
8
+ addAdditionalExtend,
9
+ hasVariantProp,
10
+ isVariant
11
+ } from '@domql/utils'
12
+
4
13
  import { applyExtend } from '../extend'
5
14
  import { registry } from '../mixins'
6
- const ENV = process.env.NODE_ENV
7
-
8
- export const checkIfKeyIsComponent = (key) => {
9
- const isFirstKeyString = isString(key)
10
- if (!isFirstKeyString) return
11
- const firstCharKey = key.slice(0, 1)
12
- return /^[A-Z]*$/.test(firstCharKey)
13
- }
14
-
15
- export const checkIfKeyIsProperty = (key) => {
16
- const isFirstKeyString = isString(key)
17
- if (!isFirstKeyString) return
18
- const firstCharKey = key.slice(0, 1)
19
- return /^[a-z]*$/.test(firstCharKey)
20
- }
21
-
22
- export const addAdditionalExtend = (newExtend, element) => {
23
- const { extend: elementExtend } = element
24
- const originalArray = isArray(elementExtend) ? elementExtend : [elementExtend]
25
- const receivedArray = isArray(newExtend) ? newExtend : [newExtend]
26
- const extend = joinArrays(receivedArray, originalArray)
27
- return { ...element, extend }
28
- }
29
15
 
30
16
  const replaceOnKeys = key => key.replace(/on\w+/g, match => match.substring(2))
31
17
 
@@ -54,85 +40,6 @@ export const createValidDomqlObjectFromSugar = (el, parent, key, options) => {
54
40
  return newElem
55
41
  }
56
42
 
57
- export const extendizeByKey = (element, parent, key) => {
58
- const { context } = parent
59
- const { tag, extend, props, attr, state, childExtend, childProps, on, if: condition, data } = element
60
- const hasComponentAttrs = extend || childExtend || props || state || on || condition || attr || data
61
-
62
- const extendFromKey = key.includes('+')
63
- ? key.split('+') // get array of componentKeys
64
- : key.includes('_')
65
- ? [key.split('_')[0]] // get component key split _
66
- : key.includes('.') && !checkIfKeyIsComponent(key.split('.')[1])
67
- ? [key.split('.')[0]] // get component key split .
68
- : [key]
69
-
70
- // console.log(extendFromKey)
71
- // console.log(context, context?.components)
72
- // console.log(element)
73
- const isExtendKeyComponent = context && context.components[extendFromKey]
74
-
75
- if (element === isExtendKeyComponent) return element
76
- else if (!hasComponentAttrs || childProps) {
77
- return {
78
- extend: extendFromKey,
79
- tag,
80
- props: { ...element }
81
- }
82
- } else if (!extend || extend === true) {
83
- return {
84
- ...element,
85
- tag,
86
- extend: extendFromKey
87
- }
88
- } else if (extend) {
89
- return addAdditionalExtend(extendFromKey, element)
90
- } else if (isFunction(element)) {
91
- return {
92
- extend: extendFromKey,
93
- tag,
94
- props: { ...exec(element, parent) }
95
- }
96
- }
97
- }
98
-
99
- export const applyKeyComponentAsExtend = (element, parent, key) => {
100
- return extendizeByKey(element, parent, key) || element
101
- }
102
-
103
- export const applyComponentFromContext = (element, parent, options) => {
104
- const { context } = element
105
-
106
- if (!context || !context.components) return
107
-
108
- const { components } = context
109
- const { extend } = element
110
- const execExtend = exec(extend, element)
111
- if (isString(execExtend)) {
112
- const componentExists = components[execExtend] || components['smbls.' + execExtend]
113
- if (componentExists) element.extend = componentExists
114
- else {
115
- if ((ENV === 'test' || ENV === 'development') && options.verbose) {
116
- console.warn(execExtend, 'is not in library', components, element)
117
- console.warn('replacing with ', {})
118
- }
119
- element.extend = {}
120
- }
121
- }
122
- }
123
-
124
- export const isVariant = (param) => {
125
- if (!isString(param)) return
126
- const firstCharKey = param.slice(0, 1)
127
- // return (firstCharKey === '.' || firstCharKey === '$')
128
- return (firstCharKey === '.')
129
- }
130
-
131
- export const hasVariantProp = (element) => {
132
- const { props } = element
133
- if (isObject(props) && isString(props.variant)) return true
134
- }
135
-
136
43
  export const overwriteVariant = (element, variant, variantProps) => {
137
44
  let variantElement = element[variant]
138
45
  if (!variantElement) return