@domql/element 2.27.0 → 2.27.10
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 +81 -37
- package/dist/cjs/create.js +41 -17
- package/dist/cjs/extend.js +12 -5
- package/dist/cjs/methods/index.js +16 -10
- package/dist/cjs/node.js +4 -3
- package/dist/cjs/utils/extendUtils.js +1 -2
- package/dist/esm/create.js +41 -17
- package/dist/esm/extend.js +13 -6
- package/dist/esm/methods/index.js +26 -11
- package/dist/esm/node.js +11 -4
- package/dist/esm/utils/extendUtils.js +9 -3
- package/extend.js +15 -8
- package/methods/index.js +45 -16
- package/node.js +11 -5
- package/package.json +8 -8
- package/utils/extendUtils.js +26 -11
package/create.js
CHANGED
|
@@ -40,13 +40,18 @@ import {
|
|
|
40
40
|
applyVariant,
|
|
41
41
|
createValidDomqlObjectFromSugar
|
|
42
42
|
} from './utils/component.js'
|
|
43
|
-
|
|
44
|
-
const ENV = process.env.NODE_ENV
|
|
43
|
+
import { isNotProduction } from '@domql/utils/env.js'
|
|
45
44
|
|
|
46
45
|
/**
|
|
47
46
|
* Creating a domQL element using passed parameters
|
|
48
47
|
*/
|
|
49
|
-
export const create = async (
|
|
48
|
+
export const create = async (
|
|
49
|
+
element,
|
|
50
|
+
parent,
|
|
51
|
+
key,
|
|
52
|
+
options = OPTIONS.create || {},
|
|
53
|
+
attachOptions
|
|
54
|
+
) => {
|
|
50
55
|
cacheOptions(element, options)
|
|
51
56
|
|
|
52
57
|
// if element is STRING
|
|
@@ -93,7 +98,8 @@ export const create = async (element, parent, key, options = OPTIONS.create || {
|
|
|
93
98
|
|
|
94
99
|
// apply props settings
|
|
95
100
|
createProps(element, parent, options)
|
|
96
|
-
if (element.scope === 'props' || element.scope === true)
|
|
101
|
+
if (element.scope === 'props' || element.scope === true)
|
|
102
|
+
element.scope = element.props
|
|
97
103
|
|
|
98
104
|
// recatch if it passess props again
|
|
99
105
|
createIfConditionFlag(element, parent)
|
|
@@ -128,13 +134,17 @@ export const create = async (element, parent, key, options = OPTIONS.create || {
|
|
|
128
134
|
const createBasedOnType = (element, parent, key, options) => {
|
|
129
135
|
// if ELEMENT is not given
|
|
130
136
|
if (element === undefined) {
|
|
131
|
-
if (
|
|
132
|
-
console.warn(
|
|
137
|
+
if (isNotProduction()) {
|
|
138
|
+
console.warn(
|
|
139
|
+
key,
|
|
140
|
+
'element is undefined in',
|
|
141
|
+
parent && parent.__ref && parent.__ref.path
|
|
142
|
+
)
|
|
133
143
|
}
|
|
134
144
|
return {}
|
|
135
145
|
}
|
|
136
146
|
if (isString(key) && key.slice(0, 2 === '__')) {
|
|
137
|
-
if (
|
|
147
|
+
if (isNotProduction()) {
|
|
138
148
|
console.warn(key, 'seems like to be in __ref')
|
|
139
149
|
}
|
|
140
150
|
}
|
|
@@ -152,7 +162,11 @@ const createBasedOnType = (element, parent, key, options) => {
|
|
|
152
162
|
const redefineElement = (element, parent, key, options) => {
|
|
153
163
|
const elementWrapper = createBasedOnType(element, parent, key, options)
|
|
154
164
|
|
|
155
|
-
if (
|
|
165
|
+
if (
|
|
166
|
+
options.syntaxv3 ||
|
|
167
|
+
(element.props && element.props.syntaxv3) ||
|
|
168
|
+
(parent && parent.props && parent.props.syntaxv3) /* kalduna guard */
|
|
169
|
+
) {
|
|
156
170
|
if (element.props) element.props.syntaxv3 = true
|
|
157
171
|
else element.syntaxv3 = true
|
|
158
172
|
return createValidDomqlObjectFromSugar(element, parent, key, options)
|
|
@@ -187,12 +201,7 @@ const cacheOptions = (element, options) => {
|
|
|
187
201
|
}
|
|
188
202
|
|
|
189
203
|
const createKey = (element, parent, key) => {
|
|
190
|
-
return (
|
|
191
|
-
exec(key, element) ||
|
|
192
|
-
key ||
|
|
193
|
-
element.key ||
|
|
194
|
-
generateKey()
|
|
195
|
-
).toString()
|
|
204
|
+
return (exec(key, element) || key || element.key || generateKey()).toString()
|
|
196
205
|
}
|
|
197
206
|
|
|
198
207
|
const addRef = (element, parent) => {
|
|
@@ -209,13 +218,15 @@ const switchDefaultOptions = (element, parent, options) => {
|
|
|
209
218
|
}
|
|
210
219
|
|
|
211
220
|
const addElementIntoParentChildren = (element, parent) => {
|
|
212
|
-
if (parent.__ref && parent.__ref.__children)
|
|
221
|
+
if (parent.__ref && parent.__ref.__children)
|
|
222
|
+
parent.__ref.__children.push(element.key)
|
|
213
223
|
}
|
|
214
224
|
|
|
215
225
|
const visitedElements = new WeakMap()
|
|
216
226
|
const renderElement = async (element, parent, options, attachOptions) => {
|
|
217
227
|
if (visitedElements.has(element)) {
|
|
218
|
-
if (
|
|
228
|
+
if (isNotProduction())
|
|
229
|
+
console.warn('Cyclic rendering detected:', element.__ref.path)
|
|
219
230
|
}
|
|
220
231
|
|
|
221
232
|
visitedElements.set(element, true)
|
|
@@ -230,21 +241,34 @@ const renderElement = async (element, parent, options, attachOptions) => {
|
|
|
230
241
|
}
|
|
231
242
|
|
|
232
243
|
// CREATE a real NODE
|
|
233
|
-
if (
|
|
244
|
+
if (isNotProduction()) {
|
|
234
245
|
await createNestedChild()
|
|
235
246
|
} else {
|
|
236
247
|
try {
|
|
237
248
|
await createNestedChild()
|
|
238
249
|
} catch (e) {
|
|
239
250
|
const path = ref.path
|
|
240
|
-
if (path.includes('ComponentsGrid'))
|
|
241
|
-
|
|
251
|
+
if (path.includes('ComponentsGrid'))
|
|
252
|
+
path.splice(0, path.indexOf('ComponentsGrid') + 2)
|
|
253
|
+
if (path.includes('demoComponent'))
|
|
254
|
+
path.splice(0, path.indexOf('demoComponent') + 1)
|
|
242
255
|
const isDemoComponent = element.lookup(el => el.state.key)?.state?.key
|
|
243
|
-
element.warn(
|
|
256
|
+
element.warn(
|
|
257
|
+
'Error happened in:',
|
|
258
|
+
isDemoComponent ? isDemoComponent + ' ' : '' + path.join('.')
|
|
259
|
+
)
|
|
244
260
|
element.verbose()
|
|
245
261
|
element.error(e, options)
|
|
246
|
-
if (element.on?.error)
|
|
247
|
-
|
|
262
|
+
if (element.on?.error)
|
|
263
|
+
element.on.error(e, element, element.state, element.context, options)
|
|
264
|
+
if (element.props?.onError)
|
|
265
|
+
element.props.onError(
|
|
266
|
+
e,
|
|
267
|
+
element,
|
|
268
|
+
element.state,
|
|
269
|
+
element.context,
|
|
270
|
+
options
|
|
271
|
+
)
|
|
248
272
|
}
|
|
249
273
|
}
|
|
250
274
|
|
|
@@ -273,25 +297,32 @@ const renderElement = async (element, parent, options, attachOptions) => {
|
|
|
273
297
|
await triggerEventOn('create', element, options)
|
|
274
298
|
}
|
|
275
299
|
|
|
276
|
-
const checkIfPrimitive =
|
|
300
|
+
const checkIfPrimitive = element => is(element)('string', 'number')
|
|
277
301
|
|
|
278
302
|
const applyValueAsText = (element, parent, key) => {
|
|
279
303
|
const extendTag = element.extend && element.extend.tag
|
|
280
304
|
const childExtendTag = parent.childExtend && parent.childExtend.tag
|
|
281
305
|
const childPropsTag = parent.props.childProps && parent.props.childProps.tag
|
|
282
|
-
const isKeyValidHTMLTag =
|
|
306
|
+
const isKeyValidHTMLTag = HTML_TAGS.body.indexOf(key) > -1 && key
|
|
283
307
|
return {
|
|
284
308
|
text: element,
|
|
285
|
-
tag:
|
|
309
|
+
tag:
|
|
310
|
+
extendTag ||
|
|
311
|
+
childExtendTag ||
|
|
312
|
+
childPropsTag ||
|
|
313
|
+
isKeyValidHTMLTag ||
|
|
314
|
+
'string'
|
|
286
315
|
}
|
|
287
316
|
}
|
|
288
317
|
|
|
289
318
|
const applyContext = (element, parent, options) => {
|
|
290
|
-
const forcedOptionsContext =
|
|
319
|
+
const forcedOptionsContext =
|
|
320
|
+
options.context && !ROOT.context && !element.context
|
|
291
321
|
if (forcedOptionsContext) ROOT.context = options.context
|
|
292
322
|
|
|
293
323
|
// inherit from parent or root
|
|
294
|
-
if (!element.context)
|
|
324
|
+
if (!element.context)
|
|
325
|
+
element.context = parent.context || options.context || ROOT.context
|
|
295
326
|
}
|
|
296
327
|
|
|
297
328
|
// Create scope - shared object across the elements to the own or the nearest parent
|
|
@@ -304,7 +335,10 @@ const createScope = (element, parent) => {
|
|
|
304
335
|
const createIfConditionFlag = (element, parent) => {
|
|
305
336
|
const { __ref: ref } = element
|
|
306
337
|
|
|
307
|
-
if (
|
|
338
|
+
if (
|
|
339
|
+
isFunction(element.if) &&
|
|
340
|
+
!element.if(element, element.state, element.context)
|
|
341
|
+
) {
|
|
308
342
|
delete ref.__if
|
|
309
343
|
} else ref.__if = true
|
|
310
344
|
}
|
|
@@ -337,14 +371,15 @@ const addCaching = (element, parent) => {
|
|
|
337
371
|
// enable CHANGES storing
|
|
338
372
|
if (!ref.__children) ref.__children = []
|
|
339
373
|
|
|
340
|
-
if (checkIfKeyIsComponent(key))
|
|
374
|
+
if (checkIfKeyIsComponent(key))
|
|
375
|
+
ref.__componentKey = key.split('_')[0].split('.')[0].split('+')[0]
|
|
341
376
|
|
|
342
377
|
// Add _root element property
|
|
343
378
|
const hasRoot = parent && parent.key === ':root'
|
|
344
379
|
if (!ref.root) ref.root = hasRoot ? element : parentRef.root
|
|
345
380
|
|
|
346
381
|
// set the PATH array
|
|
347
|
-
// if (
|
|
382
|
+
// if (isNotProduction()) {
|
|
348
383
|
if (!parentRef) parentRef = parent.ref = {}
|
|
349
384
|
if (!parentRef.path) parentRef.path = []
|
|
350
385
|
ref.path = parentRef.path.concat(element.key)
|
|
@@ -367,9 +402,12 @@ const onlyResolveExtends = (element, parent, key, options) => {
|
|
|
367
402
|
|
|
368
403
|
// apply props settings
|
|
369
404
|
createProps(element, parent, options)
|
|
370
|
-
if (element.scope === 'props' || element.scope === true)
|
|
405
|
+
if (element.scope === 'props' || element.scope === true)
|
|
406
|
+
element.scope = element.props
|
|
371
407
|
|
|
372
|
-
if (element.node && ref.__if) {
|
|
408
|
+
if (element.node && ref.__if) {
|
|
409
|
+
parent[key || element.key] = element
|
|
410
|
+
} // Borrowed from assignNode()
|
|
373
411
|
|
|
374
412
|
if (!element.props) element.props = {}
|
|
375
413
|
applyVariant(element, parent)
|
|
@@ -387,16 +425,22 @@ const onlyResolveExtends = (element, parent, key, options) => {
|
|
|
387
425
|
isMethod(k, element) ||
|
|
388
426
|
isObject((registry.default || registry)[k]) ||
|
|
389
427
|
isVariant(k)
|
|
390
|
-
)
|
|
428
|
+
)
|
|
429
|
+
continue
|
|
391
430
|
|
|
392
431
|
const hasDefine = element.define && element.define[k]
|
|
393
|
-
const contextHasDefine =
|
|
394
|
-
|
|
432
|
+
const contextHasDefine =
|
|
433
|
+
element.context && element.context.define && element.context.define[k]
|
|
395
434
|
const optionsHasDefine = options.define && options.define[k]
|
|
396
435
|
|
|
397
436
|
if (!ref.__skipCreate && REGISTRY[k] && !optionsHasDefine) {
|
|
398
437
|
continue
|
|
399
|
-
} else if (
|
|
438
|
+
} else if (
|
|
439
|
+
element[k] &&
|
|
440
|
+
!hasDefine &&
|
|
441
|
+
!optionsHasDefine &&
|
|
442
|
+
!contextHasDefine
|
|
443
|
+
) {
|
|
400
444
|
create(exec(element[k], element), element, k, options)
|
|
401
445
|
}
|
|
402
446
|
}
|
|
@@ -416,7 +460,7 @@ const onlyResolveExtends = (element, parent, key, options) => {
|
|
|
416
460
|
return element
|
|
417
461
|
}
|
|
418
462
|
|
|
419
|
-
const checkIfMedia =
|
|
463
|
+
const checkIfMedia = key => key.slice(0, 1) === '@'
|
|
420
464
|
|
|
421
465
|
const applyMediaProps = (element, parent, key) => {
|
|
422
466
|
const { props } = element
|
package/dist/cjs/create.js
CHANGED
|
@@ -37,7 +37,7 @@ var import_classList = require("./mixins/classList.js");
|
|
|
37
37
|
var import_iterate = require("./iterate.js");
|
|
38
38
|
var import_options = require("./cache/options.js");
|
|
39
39
|
var import_component = require("./utils/component.js");
|
|
40
|
-
|
|
40
|
+
var import_env = require("@domql/utils/env.js");
|
|
41
41
|
const create = async (element, parent, key, options = import_options.OPTIONS.create || {}, attachOptions) => {
|
|
42
42
|
cacheOptions(element, options);
|
|
43
43
|
if (checkIfPrimitive(element)) {
|
|
@@ -66,7 +66,8 @@ const create = async (element, parent, key, options = import_options.OPTIONS.cre
|
|
|
66
66
|
if (element.scope === "state") element.scope = element.state;
|
|
67
67
|
createIfConditionFlag(element, parent);
|
|
68
68
|
(0, import_props.createProps)(element, parent, options);
|
|
69
|
-
if (element.scope === "props" || element.scope === true)
|
|
69
|
+
if (element.scope === "props" || element.scope === true)
|
|
70
|
+
element.scope = element.props;
|
|
70
71
|
createIfConditionFlag(element, parent);
|
|
71
72
|
if (element.node && ref.__if) {
|
|
72
73
|
return (0, import_render.assignNode)(element, parent, key, attachOptions);
|
|
@@ -84,13 +85,17 @@ const create = async (element, parent, key, options = import_options.OPTIONS.cre
|
|
|
84
85
|
};
|
|
85
86
|
const createBasedOnType = (element, parent, key, options) => {
|
|
86
87
|
if (element === void 0) {
|
|
87
|
-
if (
|
|
88
|
-
console.warn(
|
|
88
|
+
if ((0, import_env.isNotProduction)()) {
|
|
89
|
+
console.warn(
|
|
90
|
+
key,
|
|
91
|
+
"element is undefined in",
|
|
92
|
+
parent && parent.__ref && parent.__ref.path
|
|
93
|
+
);
|
|
89
94
|
}
|
|
90
95
|
return {};
|
|
91
96
|
}
|
|
92
97
|
if ((0, import_utils.isString)(key) && key.slice(0, false)) {
|
|
93
|
-
if (
|
|
98
|
+
if ((0, import_env.isNotProduction)()) {
|
|
94
99
|
console.warn(key, "seems like to be in __ref");
|
|
95
100
|
}
|
|
96
101
|
}
|
|
@@ -145,13 +150,15 @@ const switchDefaultOptions = (element, parent, options) => {
|
|
|
145
150
|
}
|
|
146
151
|
};
|
|
147
152
|
const addElementIntoParentChildren = (element, parent) => {
|
|
148
|
-
if (parent.__ref && parent.__ref.__children)
|
|
153
|
+
if (parent.__ref && parent.__ref.__children)
|
|
154
|
+
parent.__ref.__children.push(element.key);
|
|
149
155
|
};
|
|
150
156
|
const visitedElements = /* @__PURE__ */ new WeakMap();
|
|
151
157
|
const renderElement = async (element, parent, options, attachOptions) => {
|
|
152
158
|
var _a, _b, _c, _d;
|
|
153
159
|
if (visitedElements.has(element)) {
|
|
154
|
-
if (
|
|
160
|
+
if ((0, import_env.isNotProduction)())
|
|
161
|
+
console.warn("Cyclic rendering detected:", element.__ref.path);
|
|
155
162
|
}
|
|
156
163
|
visitedElements.set(element, true);
|
|
157
164
|
const { __ref: ref, key } = element;
|
|
@@ -161,21 +168,34 @@ const renderElement = async (element, parent, options, attachOptions) => {
|
|
|
161
168
|
await (0, import_node.createNode)(element, options);
|
|
162
169
|
ref.__uniqId = Math.random();
|
|
163
170
|
};
|
|
164
|
-
if (
|
|
171
|
+
if ((0, import_env.isNotProduction)()) {
|
|
165
172
|
await createNestedChild();
|
|
166
173
|
} else {
|
|
167
174
|
try {
|
|
168
175
|
await createNestedChild();
|
|
169
176
|
} catch (e) {
|
|
170
177
|
const path = ref.path;
|
|
171
|
-
if (path.includes("ComponentsGrid"))
|
|
172
|
-
|
|
178
|
+
if (path.includes("ComponentsGrid"))
|
|
179
|
+
path.splice(0, path.indexOf("ComponentsGrid") + 2);
|
|
180
|
+
if (path.includes("demoComponent"))
|
|
181
|
+
path.splice(0, path.indexOf("demoComponent") + 1);
|
|
173
182
|
const isDemoComponent = (_b = (_a = element.lookup((el) => el.state.key)) == null ? void 0 : _a.state) == null ? void 0 : _b.key;
|
|
174
|
-
element.warn(
|
|
183
|
+
element.warn(
|
|
184
|
+
"Error happened in:",
|
|
185
|
+
isDemoComponent ? isDemoComponent + " " : "" + path.join(".")
|
|
186
|
+
);
|
|
175
187
|
element.verbose();
|
|
176
188
|
element.error(e, options);
|
|
177
|
-
if ((_c = element.on) == null ? void 0 : _c.error)
|
|
178
|
-
|
|
189
|
+
if ((_c = element.on) == null ? void 0 : _c.error)
|
|
190
|
+
element.on.error(e, element, element.state, element.context, options);
|
|
191
|
+
if ((_d = element.props) == null ? void 0 : _d.onError)
|
|
192
|
+
element.props.onError(
|
|
193
|
+
e,
|
|
194
|
+
element,
|
|
195
|
+
element.state,
|
|
196
|
+
element.context,
|
|
197
|
+
options
|
|
198
|
+
);
|
|
179
199
|
}
|
|
180
200
|
}
|
|
181
201
|
if (!ref.__if) {
|
|
@@ -203,7 +223,8 @@ const applyValueAsText = (element, parent, key) => {
|
|
|
203
223
|
const applyContext = (element, parent, options) => {
|
|
204
224
|
const forcedOptionsContext = options.context && !import_tree.ROOT.context && !element.context;
|
|
205
225
|
if (forcedOptionsContext) import_tree.ROOT.context = options.context;
|
|
206
|
-
if (!element.context)
|
|
226
|
+
if (!element.context)
|
|
227
|
+
element.context = parent.context || options.context || import_tree.ROOT.context;
|
|
207
228
|
};
|
|
208
229
|
const createScope = (element, parent) => {
|
|
209
230
|
const { __ref: ref } = element;
|
|
@@ -228,7 +249,8 @@ const addCaching = (element, parent) => {
|
|
|
228
249
|
if (!ref.__attr) ref.__attr = {};
|
|
229
250
|
if (!ref.__changes) ref.__changes = [];
|
|
230
251
|
if (!ref.__children) ref.__children = [];
|
|
231
|
-
if ((0, import_utils.checkIfKeyIsComponent)(key))
|
|
252
|
+
if ((0, import_utils.checkIfKeyIsComponent)(key))
|
|
253
|
+
ref.__componentKey = key.split("_")[0].split(".")[0].split("+")[0];
|
|
232
254
|
const hasRoot = parent && parent.key === ":root";
|
|
233
255
|
if (!ref.root) ref.root = hasRoot ? element : parentRef.root;
|
|
234
256
|
if (!parentRef) parentRef = parent.ref = {};
|
|
@@ -245,7 +267,8 @@ const onlyResolveExtends = (element, parent, key, options) => {
|
|
|
245
267
|
if (element.scope === "state") element.scope = element.state;
|
|
246
268
|
createIfConditionFlag(element, parent);
|
|
247
269
|
(0, import_props.createProps)(element, parent, options);
|
|
248
|
-
if (element.scope === "props" || element.scope === true)
|
|
270
|
+
if (element.scope === "props" || element.scope === true)
|
|
271
|
+
element.scope = element.props;
|
|
249
272
|
if (element.node && ref.__if) {
|
|
250
273
|
parent[key || element.key] = element;
|
|
251
274
|
}
|
|
@@ -257,7 +280,8 @@ const onlyResolveExtends = (element, parent, key, options) => {
|
|
|
257
280
|
(0, import_iterate.throughInitialDefine)(element);
|
|
258
281
|
(0, import_iterate.throughInitialExec)(element);
|
|
259
282
|
for (const k in element) {
|
|
260
|
-
if ((0, import_utils.isUndefined)(element[k]) || (0, import_methods.isMethod)(k, element) || (0, import_utils.isObject)((import_mixins.registry.default || import_mixins.registry)[k]) || (0, import_utils.isVariant)(k))
|
|
283
|
+
if ((0, import_utils.isUndefined)(element[k]) || (0, import_methods.isMethod)(k, element) || (0, import_utils.isObject)((import_mixins.registry.default || import_mixins.registry)[k]) || (0, import_utils.isVariant)(k))
|
|
284
|
+
continue;
|
|
261
285
|
const hasDefine = element.define && element.define[k];
|
|
262
286
|
const contextHasDefine = element.context && element.context.define && element.context.define[k];
|
|
263
287
|
const optionsHasDefine = options.define && options.define[k];
|
package/dist/cjs/extend.js
CHANGED
|
@@ -23,7 +23,6 @@ __export(extend_exports, {
|
|
|
23
23
|
module.exports = __toCommonJS(extend_exports);
|
|
24
24
|
var import_utils = require("@domql/utils");
|
|
25
25
|
var import_utils2 = require("./utils/index.js");
|
|
26
|
-
const ENV = "development";
|
|
27
26
|
let mainExtend;
|
|
28
27
|
const applyExtend = (element, parent, options = {}) => {
|
|
29
28
|
if ((0, import_utils.isFunction)(element)) element = (0, import_utils.exec)(element, parent);
|
|
@@ -33,7 +32,7 @@ const applyExtend = (element, parent, options = {}) => {
|
|
|
33
32
|
const context = element.context || parent.context;
|
|
34
33
|
extend = (0, import_utils2.fallbackStringExtend)(extend, context, options, variant);
|
|
35
34
|
const extendStack = (0, import_utils2.getExtendStack)(extend, context);
|
|
36
|
-
if (
|
|
35
|
+
if ((0, import_utils.isProduction)()) delete element.extend;
|
|
37
36
|
let childExtendStack = [];
|
|
38
37
|
if (parent) {
|
|
39
38
|
element.parent = parent;
|
|
@@ -43,7 +42,10 @@ const applyExtend = (element, parent, options = {}) => {
|
|
|
43
42
|
if (parent.childExtendRecursive && !ignoreChildExtendRecursive) {
|
|
44
43
|
const canExtendRecursive = element.key !== "__text";
|
|
45
44
|
if (canExtendRecursive) {
|
|
46
|
-
const childExtendRecursiveStack = (0, import_utils2.getExtendStack)(
|
|
45
|
+
const childExtendRecursiveStack = (0, import_utils2.getExtendStack)(
|
|
46
|
+
parent.childExtendRecursive,
|
|
47
|
+
context
|
|
48
|
+
);
|
|
47
49
|
childExtendStack = childExtendStack.concat(childExtendRecursiveStack);
|
|
48
50
|
element.childExtendRecursive = parent.childExtendRecursive;
|
|
49
51
|
}
|
|
@@ -62,7 +64,10 @@ const applyExtend = (element, parent, options = {}) => {
|
|
|
62
64
|
} else if (!context.defaultExtends) return element;
|
|
63
65
|
if (context.defaultExtends) {
|
|
64
66
|
if (!mainExtend) {
|
|
65
|
-
const defaultOptionsExtend = (0, import_utils2.getExtendStack)(
|
|
67
|
+
const defaultOptionsExtend = (0, import_utils2.getExtendStack)(
|
|
68
|
+
context.defaultExtends,
|
|
69
|
+
context
|
|
70
|
+
);
|
|
66
71
|
mainExtend = (0, import_utils2.cloneAndMergeArrayExtend)(defaultOptionsExtend);
|
|
67
72
|
delete mainExtend.extend;
|
|
68
73
|
}
|
|
@@ -73,7 +78,9 @@ const applyExtend = (element, parent, options = {}) => {
|
|
|
73
78
|
const COMPONENTS = context && context.components || options.components;
|
|
74
79
|
const component = (0, import_utils.exec)(element.component || mergedExtend.component, element);
|
|
75
80
|
if (component && COMPONENTS && COMPONENTS[component]) {
|
|
76
|
-
const componentExtend = (0, import_utils2.cloneAndMergeArrayExtend)(
|
|
81
|
+
const componentExtend = (0, import_utils2.cloneAndMergeArrayExtend)(
|
|
82
|
+
(0, import_utils2.getExtendStack)(COMPONENTS[component])
|
|
83
|
+
);
|
|
77
84
|
mergedExtend = (0, import_utils2.deepMergeExtend)(componentExtend, mergedExtend);
|
|
78
85
|
}
|
|
79
86
|
const merged = (0, import_utils2.deepMergeExtend)(element, mergedExtend);
|
|
@@ -48,12 +48,12 @@ var import_event = require("@domql/event");
|
|
|
48
48
|
var import_utils = require("@domql/utils");
|
|
49
49
|
var import_tree = require("../tree.js");
|
|
50
50
|
var import_mixins = require("../mixins/index.js");
|
|
51
|
-
const ENV = "development";
|
|
52
51
|
function spotByPath(path) {
|
|
53
52
|
const element = this;
|
|
54
53
|
const arr = [].concat(path);
|
|
55
54
|
let active = import_tree.TREE[arr[0]];
|
|
56
|
-
if (!arr || !arr.length)
|
|
55
|
+
if (!arr || !arr.length)
|
|
56
|
+
return console.log(arr, "on", element.key, "is undefined");
|
|
57
57
|
while (active.key === arr[0]) {
|
|
58
58
|
arr.shift();
|
|
59
59
|
if (!arr.length) break;
|
|
@@ -66,7 +66,8 @@ function lookup(param) {
|
|
|
66
66
|
const el = this;
|
|
67
67
|
let { parent } = el;
|
|
68
68
|
if ((0, import_utils.isFunction)(param)) {
|
|
69
|
-
if (parent.state && param(parent, parent.state, parent.context))
|
|
69
|
+
if (parent.state && param(parent, parent.state, parent.context))
|
|
70
|
+
return parent;
|
|
70
71
|
else if (parent.parent) return parent.lookup(param);
|
|
71
72
|
else return;
|
|
72
73
|
}
|
|
@@ -136,7 +137,11 @@ async function remove(opts) {
|
|
|
136
137
|
element.log();
|
|
137
138
|
}
|
|
138
139
|
delete element.parent[element.key];
|
|
139
|
-
if (element.parent.__ref)
|
|
140
|
+
if (element.parent.__ref)
|
|
141
|
+
element.parent.__ref.__children = (0, import_utils.removeValueFromArray)(
|
|
142
|
+
element.parent.__ref.__children,
|
|
143
|
+
element.key
|
|
144
|
+
);
|
|
140
145
|
await (0, import_event.triggerEventOn)("remove", element, opts);
|
|
141
146
|
}
|
|
142
147
|
function get(param) {
|
|
@@ -184,7 +189,8 @@ function parse(excl = []) {
|
|
|
184
189
|
} else if (v === "props") {
|
|
185
190
|
const { __element, update, ...props } = element[v];
|
|
186
191
|
obj[v] = props;
|
|
187
|
-
} else if ((0, import_utils.isDefined)(val) && Object.hasOwnProperty.call(element, v))
|
|
192
|
+
} else if ((0, import_utils.isDefined)(val) && Object.hasOwnProperty.call(element, v))
|
|
193
|
+
obj[v] = val;
|
|
188
194
|
});
|
|
189
195
|
return obj;
|
|
190
196
|
}
|
|
@@ -200,7 +206,7 @@ function parseDeep(excl = []) {
|
|
|
200
206
|
return obj;
|
|
201
207
|
}
|
|
202
208
|
function verbose(element, ...args) {
|
|
203
|
-
if (
|
|
209
|
+
if ((0, import_utils.isProduction)()) return;
|
|
204
210
|
const parent = this;
|
|
205
211
|
const { __ref: ref } = parent;
|
|
206
212
|
console.groupCollapsed(parent.key);
|
|
@@ -217,18 +223,18 @@ function verbose(element, ...args) {
|
|
|
217
223
|
return parent;
|
|
218
224
|
}
|
|
219
225
|
function log(...params) {
|
|
220
|
-
if (
|
|
226
|
+
if ((0, import_utils.isNotProduction)()) {
|
|
221
227
|
console.log(...params);
|
|
222
228
|
}
|
|
223
229
|
}
|
|
224
230
|
function warn(...params) {
|
|
225
|
-
if (
|
|
231
|
+
if ((0, import_utils.isNotProduction)()) {
|
|
226
232
|
console.warn(...params);
|
|
227
233
|
}
|
|
228
234
|
}
|
|
229
235
|
function error(...params) {
|
|
230
236
|
var _a, _b;
|
|
231
|
-
if (
|
|
237
|
+
if ((0, import_utils.isNotProduction)()) {
|
|
232
238
|
if ((_a = params[params.length - 1]) == null ? void 0 : _a.debugger) debugger;
|
|
233
239
|
if ((_b = params[params.length - 1]) == null ? void 0 : _b.verbose) verbose.call(this, ...params);
|
|
234
240
|
console.error(...params, this);
|
|
@@ -265,7 +271,7 @@ function variables(obj = {}) {
|
|
|
265
271
|
}
|
|
266
272
|
return {
|
|
267
273
|
changed: (cb) => {
|
|
268
|
-
if (!changed) return;
|
|
274
|
+
if (!changed || !varCaches) return;
|
|
269
275
|
const returns = cb(changes, (0, import_utils.deepClone)(varCaches));
|
|
270
276
|
for (const key in changes) {
|
|
271
277
|
varCaches[key] = changes[key];
|
package/dist/cjs/node.js
CHANGED
|
@@ -31,7 +31,7 @@ var import_iterate = require("./iterate.js");
|
|
|
31
31
|
var import_mixins = require("./mixins/index.js");
|
|
32
32
|
var import_applyParam = require("./utils/applyParam.js");
|
|
33
33
|
var import_propEvents = require("./utils/propEvents.js");
|
|
34
|
-
|
|
34
|
+
var import_env = require("@domql/utils/env.js");
|
|
35
35
|
const createNode = async (element, options) => {
|
|
36
36
|
let { node, tag, __ref: ref } = element;
|
|
37
37
|
let isNewNode;
|
|
@@ -43,7 +43,7 @@ const createNode = async (element, options) => {
|
|
|
43
43
|
} else node = element.node = (0, import_render.cacheNode)(element);
|
|
44
44
|
await (0, import_event.triggerEventOn)("attachNode", element, options);
|
|
45
45
|
}
|
|
46
|
-
if (
|
|
46
|
+
if ((0, import_env.isNotProduction)() || options.alowRefReference) {
|
|
47
47
|
node.ref = element;
|
|
48
48
|
if ((0, import_utils.isFunction)(node.setAttribute)) node.setAttribute("key", element.key);
|
|
49
49
|
}
|
|
@@ -59,7 +59,8 @@ const createNode = async (element, options) => {
|
|
|
59
59
|
for (const param in element) {
|
|
60
60
|
const value = element[param];
|
|
61
61
|
if (!Object.hasOwnProperty.call(element, param)) continue;
|
|
62
|
-
if ((0, import_utils.isUndefined)(value) || (0, import_methods.isMethod)(param, element) || (0, import_utils.isVariant)(param) || (0, import_utils.isObject)(import_mixins.REGISTRY[param]))
|
|
62
|
+
if ((0, import_utils.isUndefined)(value) || (0, import_methods.isMethod)(param, element) || (0, import_utils.isVariant)(param) || (0, import_utils.isObject)(import_mixins.REGISTRY[param]))
|
|
63
|
+
continue;
|
|
63
64
|
const isElement = await (0, import_applyParam.applyParam)(param, element, options);
|
|
64
65
|
if (isElement) {
|
|
65
66
|
const { hasDefine, hasContextDefine } = isElement;
|
|
@@ -36,7 +36,6 @@ __export(extendUtils_exports, {
|
|
|
36
36
|
});
|
|
37
37
|
module.exports = __toCommonJS(extendUtils_exports);
|
|
38
38
|
var import_utils = require("@domql/utils");
|
|
39
|
-
const ENV = "development";
|
|
40
39
|
const generateHash = () => Math.random().toString(36).substring(2);
|
|
41
40
|
const extendStackRegistry = {};
|
|
42
41
|
const extendCachedRegistry = {};
|
|
@@ -110,7 +109,7 @@ const fallbackStringExtend = (extend, context, options = {}, variant) => {
|
|
|
110
109
|
if (componentExists) return componentExists;
|
|
111
110
|
else if (pageExists) return pageExists;
|
|
112
111
|
else {
|
|
113
|
-
if (options.verbose && (
|
|
112
|
+
if (options.verbose && (0, import_utils.isNotProduction)()) {
|
|
114
113
|
console.warn("Extend is string but component was not found:", extend);
|
|
115
114
|
}
|
|
116
115
|
return {};
|
package/dist/esm/create.js
CHANGED
|
@@ -33,7 +33,7 @@ import {
|
|
|
33
33
|
applyVariant,
|
|
34
34
|
createValidDomqlObjectFromSugar
|
|
35
35
|
} from "./utils/component.js";
|
|
36
|
-
|
|
36
|
+
import { isNotProduction } from "@domql/utils/env.js";
|
|
37
37
|
const create = async (element, parent, key, options = OPTIONS.create || {}, attachOptions) => {
|
|
38
38
|
cacheOptions(element, options);
|
|
39
39
|
if (checkIfPrimitive(element)) {
|
|
@@ -62,7 +62,8 @@ const create = async (element, parent, key, options = OPTIONS.create || {}, atta
|
|
|
62
62
|
if (element.scope === "state") element.scope = element.state;
|
|
63
63
|
createIfConditionFlag(element, parent);
|
|
64
64
|
createProps(element, parent, options);
|
|
65
|
-
if (element.scope === "props" || element.scope === true)
|
|
65
|
+
if (element.scope === "props" || element.scope === true)
|
|
66
|
+
element.scope = element.props;
|
|
66
67
|
createIfConditionFlag(element, parent);
|
|
67
68
|
if (element.node && ref.__if) {
|
|
68
69
|
return assignNode(element, parent, key, attachOptions);
|
|
@@ -80,13 +81,17 @@ const create = async (element, parent, key, options = OPTIONS.create || {}, atta
|
|
|
80
81
|
};
|
|
81
82
|
const createBasedOnType = (element, parent, key, options) => {
|
|
82
83
|
if (element === void 0) {
|
|
83
|
-
if (
|
|
84
|
-
console.warn(
|
|
84
|
+
if (isNotProduction()) {
|
|
85
|
+
console.warn(
|
|
86
|
+
key,
|
|
87
|
+
"element is undefined in",
|
|
88
|
+
parent && parent.__ref && parent.__ref.path
|
|
89
|
+
);
|
|
85
90
|
}
|
|
86
91
|
return {};
|
|
87
92
|
}
|
|
88
93
|
if (isString(key) && key.slice(0, false)) {
|
|
89
|
-
if (
|
|
94
|
+
if (isNotProduction()) {
|
|
90
95
|
console.warn(key, "seems like to be in __ref");
|
|
91
96
|
}
|
|
92
97
|
}
|
|
@@ -141,13 +146,15 @@ const switchDefaultOptions = (element, parent, options) => {
|
|
|
141
146
|
}
|
|
142
147
|
};
|
|
143
148
|
const addElementIntoParentChildren = (element, parent) => {
|
|
144
|
-
if (parent.__ref && parent.__ref.__children)
|
|
149
|
+
if (parent.__ref && parent.__ref.__children)
|
|
150
|
+
parent.__ref.__children.push(element.key);
|
|
145
151
|
};
|
|
146
152
|
const visitedElements = /* @__PURE__ */ new WeakMap();
|
|
147
153
|
const renderElement = async (element, parent, options, attachOptions) => {
|
|
148
154
|
var _a, _b, _c, _d;
|
|
149
155
|
if (visitedElements.has(element)) {
|
|
150
|
-
if (
|
|
156
|
+
if (isNotProduction())
|
|
157
|
+
console.warn("Cyclic rendering detected:", element.__ref.path);
|
|
151
158
|
}
|
|
152
159
|
visitedElements.set(element, true);
|
|
153
160
|
const { __ref: ref, key } = element;
|
|
@@ -157,21 +164,34 @@ const renderElement = async (element, parent, options, attachOptions) => {
|
|
|
157
164
|
await createNode(element, options);
|
|
158
165
|
ref.__uniqId = Math.random();
|
|
159
166
|
};
|
|
160
|
-
if (
|
|
167
|
+
if (isNotProduction()) {
|
|
161
168
|
await createNestedChild();
|
|
162
169
|
} else {
|
|
163
170
|
try {
|
|
164
171
|
await createNestedChild();
|
|
165
172
|
} catch (e) {
|
|
166
173
|
const path = ref.path;
|
|
167
|
-
if (path.includes("ComponentsGrid"))
|
|
168
|
-
|
|
174
|
+
if (path.includes("ComponentsGrid"))
|
|
175
|
+
path.splice(0, path.indexOf("ComponentsGrid") + 2);
|
|
176
|
+
if (path.includes("demoComponent"))
|
|
177
|
+
path.splice(0, path.indexOf("demoComponent") + 1);
|
|
169
178
|
const isDemoComponent = (_b = (_a = element.lookup((el) => el.state.key)) == null ? void 0 : _a.state) == null ? void 0 : _b.key;
|
|
170
|
-
element.warn(
|
|
179
|
+
element.warn(
|
|
180
|
+
"Error happened in:",
|
|
181
|
+
isDemoComponent ? isDemoComponent + " " : "" + path.join(".")
|
|
182
|
+
);
|
|
171
183
|
element.verbose();
|
|
172
184
|
element.error(e, options);
|
|
173
|
-
if ((_c = element.on) == null ? void 0 : _c.error)
|
|
174
|
-
|
|
185
|
+
if ((_c = element.on) == null ? void 0 : _c.error)
|
|
186
|
+
element.on.error(e, element, element.state, element.context, options);
|
|
187
|
+
if ((_d = element.props) == null ? void 0 : _d.onError)
|
|
188
|
+
element.props.onError(
|
|
189
|
+
e,
|
|
190
|
+
element,
|
|
191
|
+
element.state,
|
|
192
|
+
element.context,
|
|
193
|
+
options
|
|
194
|
+
);
|
|
175
195
|
}
|
|
176
196
|
}
|
|
177
197
|
if (!ref.__if) {
|
|
@@ -199,7 +219,8 @@ const applyValueAsText = (element, parent, key) => {
|
|
|
199
219
|
const applyContext = (element, parent, options) => {
|
|
200
220
|
const forcedOptionsContext = options.context && !ROOT.context && !element.context;
|
|
201
221
|
if (forcedOptionsContext) ROOT.context = options.context;
|
|
202
|
-
if (!element.context)
|
|
222
|
+
if (!element.context)
|
|
223
|
+
element.context = parent.context || options.context || ROOT.context;
|
|
203
224
|
};
|
|
204
225
|
const createScope = (element, parent) => {
|
|
205
226
|
const { __ref: ref } = element;
|
|
@@ -224,7 +245,8 @@ const addCaching = (element, parent) => {
|
|
|
224
245
|
if (!ref.__attr) ref.__attr = {};
|
|
225
246
|
if (!ref.__changes) ref.__changes = [];
|
|
226
247
|
if (!ref.__children) ref.__children = [];
|
|
227
|
-
if (checkIfKeyIsComponent(key))
|
|
248
|
+
if (checkIfKeyIsComponent(key))
|
|
249
|
+
ref.__componentKey = key.split("_")[0].split(".")[0].split("+")[0];
|
|
228
250
|
const hasRoot = parent && parent.key === ":root";
|
|
229
251
|
if (!ref.root) ref.root = hasRoot ? element : parentRef.root;
|
|
230
252
|
if (!parentRef) parentRef = parent.ref = {};
|
|
@@ -241,7 +263,8 @@ const onlyResolveExtends = (element, parent, key, options) => {
|
|
|
241
263
|
if (element.scope === "state") element.scope = element.state;
|
|
242
264
|
createIfConditionFlag(element, parent);
|
|
243
265
|
createProps(element, parent, options);
|
|
244
|
-
if (element.scope === "props" || element.scope === true)
|
|
266
|
+
if (element.scope === "props" || element.scope === true)
|
|
267
|
+
element.scope = element.props;
|
|
245
268
|
if (element.node && ref.__if) {
|
|
246
269
|
parent[key || element.key] = element;
|
|
247
270
|
}
|
|
@@ -253,7 +276,8 @@ const onlyResolveExtends = (element, parent, key, options) => {
|
|
|
253
276
|
throughInitialDefine(element);
|
|
254
277
|
throughInitialExec(element);
|
|
255
278
|
for (const k in element) {
|
|
256
|
-
if (isUndefined(element[k]) || isMethod(k, element) || isObject((registry.default || registry)[k]) || isVariant(k))
|
|
279
|
+
if (isUndefined(element[k]) || isMethod(k, element) || isObject((registry.default || registry)[k]) || isVariant(k))
|
|
280
|
+
continue;
|
|
257
281
|
const hasDefine = element.define && element.define[k];
|
|
258
282
|
const contextHasDefine = element.context && element.context.define && element.context.define[k];
|
|
259
283
|
const optionsHasDefine = options.define && options.define[k];
|
package/dist/esm/extend.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { isFunction, exec } from "@domql/utils";
|
|
1
|
+
import { isFunction, exec, isProduction } from "@domql/utils";
|
|
2
2
|
import {
|
|
3
3
|
getExtendStack,
|
|
4
4
|
jointStacks,
|
|
@@ -6,7 +6,6 @@ import {
|
|
|
6
6
|
deepMergeExtend,
|
|
7
7
|
fallbackStringExtend
|
|
8
8
|
} from "./utils/index.js";
|
|
9
|
-
const ENV = "development";
|
|
10
9
|
let mainExtend;
|
|
11
10
|
const applyExtend = (element, parent, options = {}) => {
|
|
12
11
|
if (isFunction(element)) element = exec(element, parent);
|
|
@@ -16,7 +15,7 @@ const applyExtend = (element, parent, options = {}) => {
|
|
|
16
15
|
const context = element.context || parent.context;
|
|
17
16
|
extend = fallbackStringExtend(extend, context, options, variant);
|
|
18
17
|
const extendStack = getExtendStack(extend, context);
|
|
19
|
-
if (
|
|
18
|
+
if (isProduction()) delete element.extend;
|
|
20
19
|
let childExtendStack = [];
|
|
21
20
|
if (parent) {
|
|
22
21
|
element.parent = parent;
|
|
@@ -26,7 +25,10 @@ const applyExtend = (element, parent, options = {}) => {
|
|
|
26
25
|
if (parent.childExtendRecursive && !ignoreChildExtendRecursive) {
|
|
27
26
|
const canExtendRecursive = element.key !== "__text";
|
|
28
27
|
if (canExtendRecursive) {
|
|
29
|
-
const childExtendRecursiveStack = getExtendStack(
|
|
28
|
+
const childExtendRecursiveStack = getExtendStack(
|
|
29
|
+
parent.childExtendRecursive,
|
|
30
|
+
context
|
|
31
|
+
);
|
|
30
32
|
childExtendStack = childExtendStack.concat(childExtendRecursiveStack);
|
|
31
33
|
element.childExtendRecursive = parent.childExtendRecursive;
|
|
32
34
|
}
|
|
@@ -45,7 +47,10 @@ const applyExtend = (element, parent, options = {}) => {
|
|
|
45
47
|
} else if (!context.defaultExtends) return element;
|
|
46
48
|
if (context.defaultExtends) {
|
|
47
49
|
if (!mainExtend) {
|
|
48
|
-
const defaultOptionsExtend = getExtendStack(
|
|
50
|
+
const defaultOptionsExtend = getExtendStack(
|
|
51
|
+
context.defaultExtends,
|
|
52
|
+
context
|
|
53
|
+
);
|
|
49
54
|
mainExtend = cloneAndMergeArrayExtend(defaultOptionsExtend);
|
|
50
55
|
delete mainExtend.extend;
|
|
51
56
|
}
|
|
@@ -56,7 +61,9 @@ const applyExtend = (element, parent, options = {}) => {
|
|
|
56
61
|
const COMPONENTS = context && context.components || options.components;
|
|
57
62
|
const component = exec(element.component || mergedExtend.component, element);
|
|
58
63
|
if (component && COMPONENTS && COMPONENTS[component]) {
|
|
59
|
-
const componentExtend = cloneAndMergeArrayExtend(
|
|
64
|
+
const componentExtend = cloneAndMergeArrayExtend(
|
|
65
|
+
getExtendStack(COMPONENTS[component])
|
|
66
|
+
);
|
|
60
67
|
mergedExtend = deepMergeExtend(componentExtend, mergedExtend);
|
|
61
68
|
}
|
|
62
69
|
const merged = deepMergeExtend(element, mergedExtend);
|
|
@@ -1,13 +1,22 @@
|
|
|
1
1
|
import { triggerEventOn } from "@domql/event";
|
|
2
|
-
import {
|
|
2
|
+
import {
|
|
3
|
+
isDefined,
|
|
4
|
+
isObject,
|
|
5
|
+
isFunction,
|
|
6
|
+
isObjectLike,
|
|
7
|
+
isProduction,
|
|
8
|
+
removeValueFromArray,
|
|
9
|
+
deepClone,
|
|
10
|
+
isNotProduction
|
|
11
|
+
} from "@domql/utils";
|
|
3
12
|
import { TREE } from "../tree.js";
|
|
4
13
|
import { parseFilters, REGISTRY } from "../mixins/index.js";
|
|
5
|
-
const ENV = "development";
|
|
6
14
|
function spotByPath(path) {
|
|
7
15
|
const element = this;
|
|
8
16
|
const arr = [].concat(path);
|
|
9
17
|
let active = TREE[arr[0]];
|
|
10
|
-
if (!arr || !arr.length)
|
|
18
|
+
if (!arr || !arr.length)
|
|
19
|
+
return console.log(arr, "on", element.key, "is undefined");
|
|
11
20
|
while (active.key === arr[0]) {
|
|
12
21
|
arr.shift();
|
|
13
22
|
if (!arr.length) break;
|
|
@@ -20,7 +29,8 @@ function lookup(param) {
|
|
|
20
29
|
const el = this;
|
|
21
30
|
let { parent } = el;
|
|
22
31
|
if (isFunction(param)) {
|
|
23
|
-
if (parent.state && param(parent, parent.state, parent.context))
|
|
32
|
+
if (parent.state && param(parent, parent.state, parent.context))
|
|
33
|
+
return parent;
|
|
24
34
|
else if (parent.parent) return parent.lookup(param);
|
|
25
35
|
else return;
|
|
26
36
|
}
|
|
@@ -90,7 +100,11 @@ async function remove(opts) {
|
|
|
90
100
|
element.log();
|
|
91
101
|
}
|
|
92
102
|
delete element.parent[element.key];
|
|
93
|
-
if (element.parent.__ref)
|
|
103
|
+
if (element.parent.__ref)
|
|
104
|
+
element.parent.__ref.__children = removeValueFromArray(
|
|
105
|
+
element.parent.__ref.__children,
|
|
106
|
+
element.key
|
|
107
|
+
);
|
|
94
108
|
await triggerEventOn("remove", element, opts);
|
|
95
109
|
}
|
|
96
110
|
function get(param) {
|
|
@@ -138,7 +152,8 @@ function parse(excl = []) {
|
|
|
138
152
|
} else if (v === "props") {
|
|
139
153
|
const { __element, update, ...props } = element[v];
|
|
140
154
|
obj[v] = props;
|
|
141
|
-
} else if (isDefined(val) && Object.hasOwnProperty.call(element, v))
|
|
155
|
+
} else if (isDefined(val) && Object.hasOwnProperty.call(element, v))
|
|
156
|
+
obj[v] = val;
|
|
142
157
|
});
|
|
143
158
|
return obj;
|
|
144
159
|
}
|
|
@@ -154,7 +169,7 @@ function parseDeep(excl = []) {
|
|
|
154
169
|
return obj;
|
|
155
170
|
}
|
|
156
171
|
function verbose(element, ...args) {
|
|
157
|
-
if (
|
|
172
|
+
if (isProduction()) return;
|
|
158
173
|
const parent = this;
|
|
159
174
|
const { __ref: ref } = parent;
|
|
160
175
|
console.groupCollapsed(parent.key);
|
|
@@ -171,18 +186,18 @@ function verbose(element, ...args) {
|
|
|
171
186
|
return parent;
|
|
172
187
|
}
|
|
173
188
|
function log(...params) {
|
|
174
|
-
if (
|
|
189
|
+
if (isNotProduction()) {
|
|
175
190
|
console.log(...params);
|
|
176
191
|
}
|
|
177
192
|
}
|
|
178
193
|
function warn(...params) {
|
|
179
|
-
if (
|
|
194
|
+
if (isNotProduction()) {
|
|
180
195
|
console.warn(...params);
|
|
181
196
|
}
|
|
182
197
|
}
|
|
183
198
|
function error(...params) {
|
|
184
199
|
var _a, _b;
|
|
185
|
-
if (
|
|
200
|
+
if (isNotProduction()) {
|
|
186
201
|
if ((_a = params[params.length - 1]) == null ? void 0 : _a.debugger) debugger;
|
|
187
202
|
if ((_b = params[params.length - 1]) == null ? void 0 : _b.verbose) verbose.call(this, ...params);
|
|
188
203
|
console.error(...params, this);
|
|
@@ -219,7 +234,7 @@ function variables(obj = {}) {
|
|
|
219
234
|
}
|
|
220
235
|
return {
|
|
221
236
|
changed: (cb) => {
|
|
222
|
-
if (!changed) return;
|
|
237
|
+
if (!changed || !varCaches) return;
|
|
223
238
|
const returns = cb(changes, deepClone(varCaches));
|
|
224
239
|
for (const key in changes) {
|
|
225
240
|
varCaches[key] = changes[key];
|
package/dist/esm/node.js
CHANGED
|
@@ -1,4 +1,10 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import {
|
|
2
|
+
exec,
|
|
3
|
+
isFunction,
|
|
4
|
+
isObject,
|
|
5
|
+
isUndefined,
|
|
6
|
+
isVariant
|
|
7
|
+
} from "@domql/utils";
|
|
2
8
|
import { applyEventsOnNode, triggerEventOn } from "@domql/event";
|
|
3
9
|
import { cacheNode } from "@domql/render";
|
|
4
10
|
import { isMethod } from "./methods/index.js";
|
|
@@ -11,7 +17,7 @@ import {
|
|
|
11
17
|
import { REGISTRY } from "./mixins/index.js";
|
|
12
18
|
import { applyParam } from "./utils/applyParam.js";
|
|
13
19
|
import { propagateEventsFromProps } from "./utils/propEvents.js";
|
|
14
|
-
|
|
20
|
+
import { isNotProduction } from "@domql/utils/env.js";
|
|
15
21
|
const createNode = async (element, options) => {
|
|
16
22
|
let { node, tag, __ref: ref } = element;
|
|
17
23
|
let isNewNode;
|
|
@@ -23,7 +29,7 @@ const createNode = async (element, options) => {
|
|
|
23
29
|
} else node = element.node = cacheNode(element);
|
|
24
30
|
await triggerEventOn("attachNode", element, options);
|
|
25
31
|
}
|
|
26
|
-
if (
|
|
32
|
+
if (isNotProduction() || options.alowRefReference) {
|
|
27
33
|
node.ref = element;
|
|
28
34
|
if (isFunction(node.setAttribute)) node.setAttribute("key", element.key);
|
|
29
35
|
}
|
|
@@ -39,7 +45,8 @@ const createNode = async (element, options) => {
|
|
|
39
45
|
for (const param in element) {
|
|
40
46
|
const value = element[param];
|
|
41
47
|
if (!Object.hasOwnProperty.call(element, param)) continue;
|
|
42
|
-
if (isUndefined(value) || isMethod(param, element) || isVariant(param) || isObject(REGISTRY[param]))
|
|
48
|
+
if (isUndefined(value) || isMethod(param, element) || isVariant(param) || isObject(REGISTRY[param]))
|
|
49
|
+
continue;
|
|
43
50
|
const isElement = await applyParam(param, element, options);
|
|
44
51
|
if (isElement) {
|
|
45
52
|
const { hasDefine, hasContextDefine } = isElement;
|
|
@@ -1,5 +1,11 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
1
|
+
import {
|
|
2
|
+
isArray,
|
|
3
|
+
isFunction,
|
|
4
|
+
isObject,
|
|
5
|
+
isString,
|
|
6
|
+
deepClone,
|
|
7
|
+
isNotProduction
|
|
8
|
+
} from "@domql/utils";
|
|
3
9
|
const generateHash = () => Math.random().toString(36).substring(2);
|
|
4
10
|
const extendStackRegistry = {};
|
|
5
11
|
const extendCachedRegistry = {};
|
|
@@ -73,7 +79,7 @@ const fallbackStringExtend = (extend, context, options = {}, variant) => {
|
|
|
73
79
|
if (componentExists) return componentExists;
|
|
74
80
|
else if (pageExists) return pageExists;
|
|
75
81
|
else {
|
|
76
|
-
if (options.verbose && (
|
|
82
|
+
if (options.verbose && isNotProduction()) {
|
|
77
83
|
console.warn("Extend is string but component was not found:", extend);
|
|
78
84
|
}
|
|
79
85
|
return {};
|
package/extend.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
'use strict'
|
|
2
2
|
|
|
3
|
-
import { isFunction, exec } from '@domql/utils'
|
|
3
|
+
import { isFunction, exec, isProduction } from '@domql/utils'
|
|
4
4
|
import {
|
|
5
5
|
getExtendStack,
|
|
6
6
|
jointStacks,
|
|
@@ -9,8 +9,6 @@ import {
|
|
|
9
9
|
fallbackStringExtend
|
|
10
10
|
} from './utils/index.js'
|
|
11
11
|
|
|
12
|
-
const ENV = process.env.NODE_ENV
|
|
13
|
-
|
|
14
12
|
let mainExtend
|
|
15
13
|
|
|
16
14
|
/**
|
|
@@ -29,7 +27,7 @@ export const applyExtend = (element, parent, options = {}) => {
|
|
|
29
27
|
|
|
30
28
|
const extendStack = getExtendStack(extend, context)
|
|
31
29
|
|
|
32
|
-
if (
|
|
30
|
+
if (isProduction()) delete element.extend
|
|
33
31
|
|
|
34
32
|
let childExtendStack = []
|
|
35
33
|
if (parent) {
|
|
@@ -41,11 +39,15 @@ export const applyExtend = (element, parent, options = {}) => {
|
|
|
41
39
|
// if (!options.ignoreChildExtend && !(props && exec(props, element).ignoreChildExtend)) {
|
|
42
40
|
// const ignoreChildExtendRecursive = props && exec(props, element).ignoreChildExtendRecursive
|
|
43
41
|
|
|
44
|
-
const ignoreChildExtendRecursive =
|
|
42
|
+
const ignoreChildExtendRecursive =
|
|
43
|
+
props && props.ignoreChildExtendRecursive
|
|
45
44
|
if (parent.childExtendRecursive && !ignoreChildExtendRecursive) {
|
|
46
45
|
const canExtendRecursive = element.key !== '__text'
|
|
47
46
|
if (canExtendRecursive) {
|
|
48
|
-
const childExtendRecursiveStack = getExtendStack(
|
|
47
|
+
const childExtendRecursiveStack = getExtendStack(
|
|
48
|
+
parent.childExtendRecursive,
|
|
49
|
+
context
|
|
50
|
+
)
|
|
49
51
|
// add error if childExtendRecursive contains element which goes to infinite loop
|
|
50
52
|
childExtendStack = childExtendStack.concat(childExtendRecursiveStack)
|
|
51
53
|
element.childExtendRecursive = parent.childExtendRecursive
|
|
@@ -68,7 +70,10 @@ export const applyExtend = (element, parent, options = {}) => {
|
|
|
68
70
|
|
|
69
71
|
if (context.defaultExtends) {
|
|
70
72
|
if (!mainExtend) {
|
|
71
|
-
const defaultOptionsExtend = getExtendStack(
|
|
73
|
+
const defaultOptionsExtend = getExtendStack(
|
|
74
|
+
context.defaultExtends,
|
|
75
|
+
context
|
|
76
|
+
)
|
|
72
77
|
mainExtend = cloneAndMergeArrayExtend(defaultOptionsExtend)
|
|
73
78
|
delete mainExtend.extend
|
|
74
79
|
}
|
|
@@ -81,7 +86,9 @@ export const applyExtend = (element, parent, options = {}) => {
|
|
|
81
86
|
const COMPONENTS = (context && context.components) || options.components
|
|
82
87
|
const component = exec(element.component || mergedExtend.component, element)
|
|
83
88
|
if (component && COMPONENTS && COMPONENTS[component]) {
|
|
84
|
-
const componentExtend = cloneAndMergeArrayExtend(
|
|
89
|
+
const componentExtend = cloneAndMergeArrayExtend(
|
|
90
|
+
getExtendStack(COMPONENTS[component])
|
|
91
|
+
)
|
|
85
92
|
mergedExtend = deepMergeExtend(componentExtend, mergedExtend)
|
|
86
93
|
}
|
|
87
94
|
|
package/methods/index.js
CHANGED
|
@@ -1,10 +1,18 @@
|
|
|
1
1
|
'use strict'
|
|
2
2
|
|
|
3
3
|
import { triggerEventOn } from '@domql/event'
|
|
4
|
-
import {
|
|
4
|
+
import {
|
|
5
|
+
isDefined,
|
|
6
|
+
isObject,
|
|
7
|
+
isFunction,
|
|
8
|
+
isObjectLike,
|
|
9
|
+
isProduction,
|
|
10
|
+
removeValueFromArray,
|
|
11
|
+
deepClone,
|
|
12
|
+
isNotProduction
|
|
13
|
+
} from '@domql/utils'
|
|
5
14
|
import { TREE } from '../tree.js'
|
|
6
15
|
import { parseFilters, REGISTRY } from '../mixins/index.js'
|
|
7
|
-
const ENV = process.env.NODE_ENV
|
|
8
16
|
|
|
9
17
|
// TODO: update these files
|
|
10
18
|
export function spotByPath (path) {
|
|
@@ -12,7 +20,8 @@ export function spotByPath (path) {
|
|
|
12
20
|
const arr = [].concat(path)
|
|
13
21
|
let active = TREE[arr[0]]
|
|
14
22
|
|
|
15
|
-
if (!arr || !arr.length)
|
|
23
|
+
if (!arr || !arr.length)
|
|
24
|
+
return console.log(arr, 'on', element.key, 'is undefined')
|
|
16
25
|
|
|
17
26
|
while (active.key === arr[0]) {
|
|
18
27
|
arr.shift()
|
|
@@ -30,7 +39,8 @@ export function lookup (param) {
|
|
|
30
39
|
let { parent } = el
|
|
31
40
|
|
|
32
41
|
if (isFunction(param)) {
|
|
33
|
-
if (parent.state && param(parent, parent.state, parent.context))
|
|
42
|
+
if (parent.state && param(parent, parent.state, parent.context))
|
|
43
|
+
return parent
|
|
34
44
|
else if (parent.parent) return parent.lookup(param)
|
|
35
45
|
else return
|
|
36
46
|
}
|
|
@@ -111,7 +121,11 @@ export async function remove (opts) {
|
|
|
111
121
|
element.log()
|
|
112
122
|
}
|
|
113
123
|
delete element.parent[element.key]
|
|
114
|
-
if (element.parent.__ref)
|
|
124
|
+
if (element.parent.__ref)
|
|
125
|
+
element.parent.__ref.__children = removeValueFromArray(
|
|
126
|
+
element.parent.__ref.__children,
|
|
127
|
+
element.key
|
|
128
|
+
)
|
|
115
129
|
await triggerEventOn('remove', element, opts)
|
|
116
130
|
}
|
|
117
131
|
|
|
@@ -148,7 +162,12 @@ export function keys () {
|
|
|
148
162
|
const element = this
|
|
149
163
|
const keys = []
|
|
150
164
|
for (const param in element) {
|
|
151
|
-
if (
|
|
165
|
+
if (
|
|
166
|
+
(REGISTRY[param] && !parseFilters.elementKeys.includes(param)) ||
|
|
167
|
+
!Object.hasOwnProperty.call(element, param)
|
|
168
|
+
) {
|
|
169
|
+
continue
|
|
170
|
+
}
|
|
152
171
|
keys.push(param)
|
|
153
172
|
}
|
|
154
173
|
return keys
|
|
@@ -164,14 +183,17 @@ export function parse (excl = []) {
|
|
|
164
183
|
if (v === 'state') {
|
|
165
184
|
if (element.__ref && !element.__ref.__hasRootState) return
|
|
166
185
|
const parsedVal = isFunction(val && val.parse) ? val.parse() : val
|
|
167
|
-
obj[v] = isFunction(parsedVal)
|
|
186
|
+
obj[v] = isFunction(parsedVal)
|
|
187
|
+
? parsedVal
|
|
188
|
+
: JSON.parse(JSON.stringify(parsedVal || {}))
|
|
168
189
|
} else if (v === 'scope') {
|
|
169
190
|
if (element.__ref && !element.__ref.__hasRootScope) return
|
|
170
191
|
obj[v] = JSON.parse(JSON.stringify(val || {}))
|
|
171
192
|
} else if (v === 'props') {
|
|
172
193
|
const { __element, update, ...props } = element[v]
|
|
173
194
|
obj[v] = props
|
|
174
|
-
} else if (isDefined(val) && Object.hasOwnProperty.call(element, v))
|
|
195
|
+
} else if (isDefined(val) && Object.hasOwnProperty.call(element, v))
|
|
196
|
+
obj[v] = val
|
|
175
197
|
})
|
|
176
198
|
return obj
|
|
177
199
|
}
|
|
@@ -181,13 +203,15 @@ export function parseDeep (excl = []) {
|
|
|
181
203
|
const obj = parse.call(element, excl)
|
|
182
204
|
for (const v in obj) {
|
|
183
205
|
if (excl.includes(v)) return
|
|
184
|
-
if (isObjectLike(obj[v])) {
|
|
206
|
+
if (isObjectLike(obj[v])) {
|
|
207
|
+
obj[v] = parseDeep.call(obj[v], excl)
|
|
208
|
+
}
|
|
185
209
|
}
|
|
186
210
|
return obj
|
|
187
211
|
}
|
|
188
212
|
|
|
189
213
|
export function verbose (element, ...args) {
|
|
190
|
-
if (
|
|
214
|
+
if (isProduction()) return
|
|
191
215
|
|
|
192
216
|
const parent = this
|
|
193
217
|
const { __ref: ref } = parent
|
|
@@ -205,19 +229,19 @@ export function verbose (element, ...args) {
|
|
|
205
229
|
}
|
|
206
230
|
|
|
207
231
|
export function log (...params) {
|
|
208
|
-
if (
|
|
232
|
+
if (isNotProduction()) {
|
|
209
233
|
console.log(...params)
|
|
210
234
|
}
|
|
211
235
|
}
|
|
212
236
|
|
|
213
237
|
export function warn (...params) {
|
|
214
|
-
if (
|
|
238
|
+
if (isNotProduction()) {
|
|
215
239
|
console.warn(...params)
|
|
216
240
|
}
|
|
217
241
|
}
|
|
218
242
|
|
|
219
243
|
export function error (...params) {
|
|
220
|
-
if (
|
|
244
|
+
if (isNotProduction()) {
|
|
221
245
|
if (params[params.length - 1]?.debugger) debugger // eslint-disable-line
|
|
222
246
|
if (params[params.length - 1]?.verbose) verbose.call(this, ...params)
|
|
223
247
|
console.error(...params, this)
|
|
@@ -260,8 +284,8 @@ export function variables (obj = {}) {
|
|
|
260
284
|
}
|
|
261
285
|
}
|
|
262
286
|
return {
|
|
263
|
-
changed:
|
|
264
|
-
if (!changed) return
|
|
287
|
+
changed: cb => {
|
|
288
|
+
if (!changed || !varCaches) return
|
|
265
289
|
const returns = cb(changes, deepClone(varCaches))
|
|
266
290
|
for (const key in changes) {
|
|
267
291
|
varCaches[key] = changes[key]
|
|
@@ -280,7 +304,12 @@ export function variables (obj = {}) {
|
|
|
280
304
|
|
|
281
305
|
export function call (fnKey, ...args) {
|
|
282
306
|
const context = this.context
|
|
283
|
-
return (
|
|
307
|
+
return (
|
|
308
|
+
context.utils[fnKey] ||
|
|
309
|
+
context.functions[fnKey] ||
|
|
310
|
+
context.methods[fnKey] ||
|
|
311
|
+
context.snippets[fnKey]
|
|
312
|
+
)?.call(this, ...args)
|
|
284
313
|
}
|
|
285
314
|
|
|
286
315
|
export const METHODS = [
|
package/node.js
CHANGED
|
@@ -1,6 +1,12 @@
|
|
|
1
1
|
'use strict'
|
|
2
2
|
|
|
3
|
-
import {
|
|
3
|
+
import {
|
|
4
|
+
exec,
|
|
5
|
+
isFunction,
|
|
6
|
+
isObject,
|
|
7
|
+
isUndefined,
|
|
8
|
+
isVariant
|
|
9
|
+
} from '@domql/utils'
|
|
4
10
|
import { applyEventsOnNode, triggerEventOn } from '@domql/event'
|
|
5
11
|
import { cacheNode } from '@domql/render'
|
|
6
12
|
import { isMethod } from './methods/index.js'
|
|
@@ -14,10 +20,9 @@ import {
|
|
|
14
20
|
import { REGISTRY } from './mixins/index.js'
|
|
15
21
|
import { applyParam } from './utils/applyParam.js'
|
|
16
22
|
import { propagateEventsFromProps } from './utils/propEvents.js'
|
|
23
|
+
import { isNotProduction } from '@domql/utils/env.js'
|
|
17
24
|
// import { defineSetter } from './methods'
|
|
18
25
|
|
|
19
|
-
const ENV = process.env.NODE_ENV
|
|
20
|
-
|
|
21
26
|
export const createNode = async (element, options) => {
|
|
22
27
|
// create and assign a node
|
|
23
28
|
let { node, tag, __ref: ref } = element
|
|
@@ -38,7 +43,7 @@ export const createNode = async (element, options) => {
|
|
|
38
43
|
}
|
|
39
44
|
// node.dataset // .key = element.key
|
|
40
45
|
|
|
41
|
-
if (
|
|
46
|
+
if (isNotProduction() || options.alowRefReference) {
|
|
42
47
|
node.ref = element
|
|
43
48
|
if (isFunction(node.setAttribute)) node.setAttribute('key', element.key)
|
|
44
49
|
}
|
|
@@ -70,7 +75,8 @@ export const createNode = async (element, options) => {
|
|
|
70
75
|
isMethod(param, element) ||
|
|
71
76
|
isVariant(param) ||
|
|
72
77
|
isObject(REGISTRY[param])
|
|
73
|
-
)
|
|
78
|
+
)
|
|
79
|
+
continue
|
|
74
80
|
|
|
75
81
|
const isElement = await applyParam(param, element, options)
|
|
76
82
|
if (isElement) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@domql/element",
|
|
3
|
-
"version": "2.27.
|
|
3
|
+
"version": "2.27.10",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"module": "index.js",
|
|
@@ -21,18 +21,18 @@
|
|
|
21
21
|
],
|
|
22
22
|
"scripts": {
|
|
23
23
|
"copy:package:cjs": "cp ../../build/package-cjs.json dist/cjs/package.json",
|
|
24
|
-
"build:esm": "npx esbuild *.js **/*.js --target=es2019 --format=esm --outdir=dist/esm",
|
|
25
|
-
"build:cjs": "npx esbuild *.js **/*.js --target=node16 --format=cjs --outdir=dist/cjs",
|
|
24
|
+
"build:esm": "npx cross-env NODE_ENV=$NODE_ENV npx esbuild *.js **/*.js --target=es2019 --format=esm --outdir=dist/esm",
|
|
25
|
+
"build:cjs": "npx cross-env NODE_ENV=$NODE_ENV npx esbuild *.js **/*.js --target=node16 --format=cjs --outdir=dist/cjs",
|
|
26
26
|
"build": "npx rimraf -I dist; npm run build:cjs; npm run build:esm",
|
|
27
27
|
"prepublish": "npx rimraf -I dist && npm run build && npm run copy:package:cjs"
|
|
28
28
|
},
|
|
29
29
|
"dependencies": {
|
|
30
|
-
"@domql/event": "^2.27.
|
|
31
|
-
"@domql/render": "^2.27.
|
|
32
|
-
"@domql/state": "^2.27.
|
|
33
|
-
"@domql/utils": "^2.27.
|
|
30
|
+
"@domql/event": "^2.27.10",
|
|
31
|
+
"@domql/render": "^2.27.10",
|
|
32
|
+
"@domql/state": "^2.27.10",
|
|
33
|
+
"@domql/utils": "^2.27.10"
|
|
34
34
|
},
|
|
35
|
-
"gitHead": "
|
|
35
|
+
"gitHead": "668d24f518bdb163357897504c5912c085638d3e",
|
|
36
36
|
"devDependencies": {
|
|
37
37
|
"@babel/core": "^7.26.0"
|
|
38
38
|
}
|
package/utils/extendUtils.js
CHANGED
|
@@ -1,7 +1,13 @@
|
|
|
1
1
|
'use strict'
|
|
2
2
|
|
|
3
|
-
import {
|
|
4
|
-
|
|
3
|
+
import {
|
|
4
|
+
isArray,
|
|
5
|
+
isFunction,
|
|
6
|
+
isObject,
|
|
7
|
+
isString,
|
|
8
|
+
deepClone,
|
|
9
|
+
isNotProduction
|
|
10
|
+
} from '@domql/utils'
|
|
5
11
|
|
|
6
12
|
export const generateHash = () => Math.random().toString(36).substring(2)
|
|
7
13
|
|
|
@@ -15,13 +21,17 @@ export const getHashedExtend = extend => {
|
|
|
15
21
|
|
|
16
22
|
export const setHashedExtend = (extend, stack) => {
|
|
17
23
|
const hash = generateHash()
|
|
18
|
-
if (!isString(extend)) {
|
|
24
|
+
if (!isString(extend)) {
|
|
25
|
+
extend.__hash = hash
|
|
26
|
+
}
|
|
19
27
|
extendStackRegistry[hash] = stack
|
|
20
28
|
return stack
|
|
21
29
|
}
|
|
22
30
|
|
|
23
31
|
export const getExtendStackRegistry = (extend, stack) => {
|
|
24
|
-
if (extend.__hash) {
|
|
32
|
+
if (extend.__hash) {
|
|
33
|
+
return stack.concat(getHashedExtend(extend))
|
|
34
|
+
}
|
|
25
35
|
return setHashedExtend(extend, stack) // stack .concat(hashedExtend)
|
|
26
36
|
}
|
|
27
37
|
|
|
@@ -75,20 +85,25 @@ export const cloneAndMergeArrayExtend = stack => {
|
|
|
75
85
|
}, {})
|
|
76
86
|
}
|
|
77
87
|
|
|
78
|
-
export const fallbackStringExtend = (
|
|
88
|
+
export const fallbackStringExtend = (
|
|
89
|
+
extend,
|
|
90
|
+
context,
|
|
91
|
+
options = {},
|
|
92
|
+
variant
|
|
93
|
+
) => {
|
|
79
94
|
const COMPONENTS = (context && context.components) || options.components
|
|
80
95
|
const PAGES = (context && context.pages) || options.pages
|
|
81
96
|
if (isString(extend)) {
|
|
82
|
-
const componentExists =
|
|
83
|
-
COMPONENTS
|
|
84
|
-
COMPONENTS[extend] ||
|
|
85
|
-
|
|
86
|
-
|
|
97
|
+
const componentExists =
|
|
98
|
+
COMPONENTS &&
|
|
99
|
+
(COMPONENTS[extend + '.' + variant] ||
|
|
100
|
+
COMPONENTS[extend] ||
|
|
101
|
+
COMPONENTS['smbls.' + extend])
|
|
87
102
|
const pageExists = PAGES && extend.startsWith('/') && PAGES[extend]
|
|
88
103
|
if (componentExists) return componentExists
|
|
89
104
|
else if (pageExists) return pageExists
|
|
90
105
|
else {
|
|
91
|
-
if (options.verbose && (
|
|
106
|
+
if (options.verbose && isNotProduction()) {
|
|
92
107
|
console.warn('Extend is string but component was not found:', extend)
|
|
93
108
|
}
|
|
94
109
|
return {}
|