@domql/element 2.5.94 → 2.5.98

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.
@@ -28,7 +28,8 @@ let mainExtend;
28
28
  const applyExtend = (element, parent, options = {}) => {
29
29
  if ((0, import_utils.isFunction)(element))
30
30
  element = (0, import_utils.exec)(element, parent);
31
- let { extend, props, context, __ref } = element;
31
+ let { extend, props, __ref } = element;
32
+ const context = element.context || parent.context;
32
33
  extend = (0, import_utils2.fallbackStringExtend)(extend, context, options);
33
34
  const extendStack = (0, import_utils2.getExtendStack)(extend, context);
34
35
  if (ENV !== "test" || ENV !== "development")
@@ -24,6 +24,7 @@ __export(methods_exports, {
24
24
  isMethod: () => isMethod,
25
25
  keys: () => keys,
26
26
  log: () => log,
27
+ lookdown: () => lookdown,
27
28
  lookup: () => lookup,
28
29
  nextElement: () => nextElement,
29
30
  parse: () => parse,
@@ -73,6 +74,27 @@ const lookup = function(param) {
73
74
  }
74
75
  return parent;
75
76
  };
77
+ const lookdown = function(param) {
78
+ const el = this;
79
+ const { __ref: ref } = el;
80
+ const children = ref.__children;
81
+ for (let i = 0; i < children.length; i++) {
82
+ const v = children[i];
83
+ const childElem = el[v];
84
+ if (v === param)
85
+ return childElem;
86
+ else if ((0, import_utils.isFunction)(param)) {
87
+ const exec = param(childElem, childElem.state, childElem.context);
88
+ if (childElem.state && exec) {
89
+ return childElem;
90
+ }
91
+ }
92
+ const lookdown2 = childElem.lookdown(param);
93
+ if (lookdown2)
94
+ return lookdown2;
95
+ }
96
+ return null;
97
+ };
76
98
  const remove = function() {
77
99
  const element = this;
78
100
  if ((0, import_utils.isFunction)(element.node.remove))
@@ -183,6 +205,7 @@ const METHODS = [
183
205
  "updateContent",
184
206
  "removeContent",
185
207
  "lookup",
208
+ "lookdown",
186
209
  "spotByPath",
187
210
  "keys",
188
211
  "parse",
@@ -45,6 +45,7 @@ const addMethods = (element, parent) => {
45
45
  removeContent: import_content.removeContent.bind(element),
46
46
  setProps: import__.setProps.bind(element),
47
47
  lookup: import__.lookup.bind(element),
48
+ lookdown: import__.lookdown.bind(element),
48
49
  spotByPath: import__.spotByPath.bind(element),
49
50
  parse: import__.parse.bind(element),
50
51
  parseDeep: import__.parseDeep.bind(element),
@@ -61,6 +61,7 @@ var registry_default = {
61
61
  updateContent: {},
62
62
  removeContent: {},
63
63
  lookup: {},
64
+ lookdown: {},
64
65
  spotByPath: {},
65
66
  keys: {},
66
67
  log: {},
@@ -93,9 +93,10 @@ const createValidDomqlObjectFromSugar = (el, parent, key, options) => {
93
93
  return newElem;
94
94
  };
95
95
  const extendizeByKey = (element, parent, key) => {
96
- const { context, tag, extend, props, attr, state, childExtend, childProps, on, if: condition, data } = element;
96
+ const { context } = parent;
97
+ const { tag, extend, props, attr, state, childExtend, childProps, on, if: condition, data } = element;
97
98
  const hasComponentAttrs = extend || childExtend || props || state || on || condition || attr || data;
98
- const extendFromKey = key.includes("+") ? key.split("+") : key.includes("_") ? key.split("_")[0] : key.includes(".") && !checkIfKeyIsComponent(key.split(".")[1]) ? key.split(".")[0] : [key];
99
+ const extendFromKey = key.includes("+") ? key.split("+") : key.includes("_") ? [key.split("_")[0]] : key.includes(".") && !checkIfKeyIsComponent(key.split(".")[1]) ? [key.split(".")[0]] : [key];
99
100
  const isExtendKeyComponent = context && context.components[extendFromKey];
100
101
  if (element === isExtendKeyComponent)
101
102
  return element;
@@ -167,7 +168,9 @@ const overwriteVariant = (element, variant, variantProps) => {
167
168
  } else if (variantElement.extend) {
168
169
  variantElement = addAdditionalExtend({ props }, variantElement);
169
170
  }
170
- return (0, import_utils.overwriteDeep)(element, (0, import_extend.applyExtend)(variantElement));
171
+ const extendedVariant = (0, import_extend.applyExtend)(variantElement, element.parent);
172
+ const { parent, ...rest } = extendedVariant;
173
+ return (0, import_utils.overwriteDeep)(element, rest);
171
174
  };
172
175
  const applyVariant = (element) => {
173
176
  const { props } = element;
package/extend.js CHANGED
@@ -20,7 +20,8 @@ let mainExtend
20
20
  export const applyExtend = (element, parent, options = {}) => {
21
21
  if (isFunction(element)) element = exec(element, parent)
22
22
 
23
- let { extend, props, context, __ref } = element
23
+ let { extend, props, __ref } = element
24
+ const context = element.context || parent.context
24
25
 
25
26
  extend = fallbackStringExtend(extend, context, options)
26
27
 
package/methods/index.js CHANGED
@@ -42,6 +42,29 @@ export const lookup = function (param) {
42
42
  return parent
43
43
  }
44
44
 
45
+ export const lookdown = function (param) {
46
+ const el = this
47
+ const { __ref: ref } = el
48
+ const children = ref.__children
49
+
50
+ for (let i = 0; i < children.length; i++) {
51
+ const v = children[i]
52
+ const childElem = el[v]
53
+
54
+ if (v === param) return childElem
55
+ else if (isFunction(param)) {
56
+ const exec = param(childElem, childElem.state, childElem.context)
57
+ if (childElem.state && exec) {
58
+ return childElem
59
+ }
60
+ }
61
+ const lookdown = childElem.lookdown(param)
62
+ if (lookdown) return lookdown
63
+ }
64
+
65
+ return null
66
+ }
67
+
45
68
  export const remove = function () {
46
69
  const element = this
47
70
  if (isFunction(element.node.remove)) element.node.remove()
@@ -159,6 +182,7 @@ export const METHODS = [
159
182
  'updateContent',
160
183
  'removeContent',
161
184
  'lookup',
185
+ 'lookdown',
162
186
  'spotByPath',
163
187
  'keys',
164
188
  'parse',
package/methods/set.js CHANGED
@@ -7,6 +7,7 @@ import update from '../update'
7
7
 
8
8
  import {
9
9
  lookup,
10
+ lookdown,
10
11
  setProps,
11
12
  remove,
12
13
  spotByPath,
@@ -29,6 +30,7 @@ export const addMethods = (element, parent) => {
29
30
  removeContent: removeContent.bind(element),
30
31
  setProps: setProps.bind(element),
31
32
  lookup: lookup.bind(element),
33
+ lookdown: lookdown.bind(element),
32
34
  spotByPath: spotByPath.bind(element),
33
35
  parse: parse.bind(element),
34
36
  parseDeep: parseDeep.bind(element),
@@ -45,6 +45,7 @@ export default {
45
45
  updateContent: {},
46
46
  removeContent: {},
47
47
  lookup: {},
48
+ lookdown: {},
48
49
  spotByPath: {},
49
50
  keys: {},
50
51
  log: {},
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@domql/element",
3
- "version": "2.5.94",
3
+ "version": "2.5.98",
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": "76edeab829524b706fd1a0bd3fac3fd5563a3b84",
34
+ "gitHead": "6318fa362595b70f826d48c5eb8fffbc2a6a5443",
35
35
  "devDependencies": {
36
36
  "@babel/core": "^7.12.0"
37
37
  }
@@ -66,17 +66,21 @@ export const createValidDomqlObjectFromSugar = (el, parent, key, options) => {
66
66
  }
67
67
 
68
68
  export const extendizeByKey = (element, parent, key) => {
69
- const { context, tag, extend, props, attr, state, childExtend, childProps, on, if: condition, data } = element
69
+ const { context } = parent
70
+ const { tag, extend, props, attr, state, childExtend, childProps, on, if: condition, data } = element
70
71
  const hasComponentAttrs = extend || childExtend || props || state || on || condition || attr || data
71
72
 
72
73
  const extendFromKey = key.includes('+')
73
74
  ? key.split('+') // get array of componentKeys
74
75
  : key.includes('_')
75
- ? key.split('_')[0] // get component key split _
76
+ ? [key.split('_')[0]] // get component key split _
76
77
  : key.includes('.') && !checkIfKeyIsComponent(key.split('.')[1])
77
- ? key.split('.')[0] // get component key split .
78
+ ? [key.split('.')[0]] // get component key split .
78
79
  : [key]
79
80
 
81
+ // console.log(extendFromKey)
82
+ // console.log(context, context?.components)
83
+ // console.log(element)
80
84
  const isExtendKeyComponent = context && context.components[extendFromKey]
81
85
 
82
86
  if (element === isExtendKeyComponent) return element
@@ -151,7 +155,10 @@ export const overwriteVariant = (element, variant, variantProps) => {
151
155
  } else if (variantElement.extend) {
152
156
  variantElement = addAdditionalExtend({ props }, variantElement)
153
157
  }
154
- return overwriteDeep(element, applyExtend(variantElement)) // TODO: check why string is not working
158
+ const extendedVariant = applyExtend(variantElement, element.parent)
159
+ const { parent, ...rest } = extendedVariant
160
+ return overwriteDeep(element, rest) // TODO: check why string is not working
161
+ // return overwriteDeep(element, applyExtend(variantElement, element.parent)) // TODO: check why string is not working
155
162
  }
156
163
 
157
164
  export const applyVariant = (element) => {