@domql/utils 2.5.200 → 3.0.1
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/array.js +26 -13
- package/cache.js +4 -0
- package/component.js +10 -227
- package/cookie.js +27 -24
- package/dist/cjs/array.js +27 -10
- package/dist/cjs/cache.js +26 -0
- package/dist/cjs/component.js +15 -206
- package/dist/cjs/cookie.js +14 -14
- package/dist/cjs/element.js +136 -0
- package/dist/cjs/events.js +37 -0
- package/dist/cjs/extends.js +351 -0
- package/dist/cjs/if.js +30 -0
- package/dist/cjs/index.js +10 -0
- package/dist/cjs/key.js +5 -0
- package/dist/cjs/keys.js +178 -0
- package/dist/cjs/methods.js +305 -0
- package/dist/cjs/object.js +78 -191
- package/dist/cjs/props.js +220 -0
- package/dist/cjs/scope.js +28 -0
- package/dist/cjs/state.js +175 -0
- package/dist/cjs/string.js +27 -15
- package/dist/cjs/update.js +42 -0
- package/dist/esm/array.js +27 -10
- package/dist/esm/cache.js +6 -0
- package/dist/esm/component.js +16 -225
- package/dist/esm/cookie.js +14 -14
- package/dist/esm/element.js +134 -0
- package/dist/esm/events.js +17 -0
- package/dist/esm/extends.js +349 -0
- package/dist/esm/if.js +10 -0
- package/dist/esm/index.js +10 -0
- package/dist/esm/key.js +5 -0
- package/dist/esm/keys.js +158 -0
- package/dist/esm/methods.js +285 -0
- package/dist/esm/object.js +79 -193
- package/dist/esm/props.js +216 -0
- package/dist/esm/scope.js +8 -0
- package/dist/esm/state.js +185 -0
- package/dist/esm/string.js +27 -15
- package/dist/esm/update.js +22 -0
- package/element.js +148 -0
- package/env.js +5 -2
- package/events.js +17 -0
- package/extends.js +425 -0
- package/if.js +14 -0
- package/index.js +10 -0
- package/key.js +6 -0
- package/keys.js +157 -0
- package/log.js +4 -1
- package/methods.js +315 -0
- package/node.js +21 -13
- package/object.js +122 -236
- package/package.json +3 -3
- package/props.js +249 -0
- package/scope.js +8 -0
- package/state.js +208 -0
- package/string.js +66 -30
- package/update.js +27 -0
package/extends.js
ADDED
|
@@ -0,0 +1,425 @@
|
|
|
1
|
+
'use strict'
|
|
2
|
+
|
|
3
|
+
import { joinArrays, removeDuplicatesInArray } from './array.js'
|
|
4
|
+
import { matchesComponentNaming } from './component.js'
|
|
5
|
+
import { deepClone, exec } from './object.js'
|
|
6
|
+
import { isArray, isObject, isString } from './types.js'
|
|
7
|
+
const ENV = process.env.NODE_ENV
|
|
8
|
+
|
|
9
|
+
export const createExtendsFromKeys = key => {
|
|
10
|
+
if (key.includes('+')) {
|
|
11
|
+
return key.split('+').filter(matchesComponentNaming)
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
if (key.includes('_')) {
|
|
15
|
+
const [first] = key.split('_')
|
|
16
|
+
return [first]
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
if (key.includes('.') && !matchesComponentNaming(key.split('.')[1])) {
|
|
20
|
+
const [first] = key.split('.')
|
|
21
|
+
return [first]
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
return [key]
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
// Initial extend creation
|
|
28
|
+
export const createExtends = (element, parent, key) => {
|
|
29
|
+
let __extends = []
|
|
30
|
+
const keyExtends = createExtendsFromKeys(key)
|
|
31
|
+
if (keyExtends) __extends = [...keyExtends]
|
|
32
|
+
const elementExtends = element.extends
|
|
33
|
+
if (elementExtends) {
|
|
34
|
+
__extends = isArray(elementExtends)
|
|
35
|
+
? [...__extends, ...elementExtends]
|
|
36
|
+
: [...__extends, elementExtends]
|
|
37
|
+
}
|
|
38
|
+
return __extends
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
export const addExtends = (newExtends, element) => {
|
|
42
|
+
const { __ref: ref } = element
|
|
43
|
+
let { __extends } = ref
|
|
44
|
+
|
|
45
|
+
if (!newExtends) return __extends
|
|
46
|
+
|
|
47
|
+
// Check if the first extend has a variant in components
|
|
48
|
+
const variant = element.props?.variant
|
|
49
|
+
const context = element.context
|
|
50
|
+
if (
|
|
51
|
+
variant &&
|
|
52
|
+
context?.components &&
|
|
53
|
+
!Array.isArray(newExtends) &&
|
|
54
|
+
typeof newExtends === 'string'
|
|
55
|
+
) {
|
|
56
|
+
const variantKey = `${newExtends}.${variant}`
|
|
57
|
+
if (context.components[variantKey]) {
|
|
58
|
+
newExtends = variantKey
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
if (!__extends.includes(newExtends)) {
|
|
63
|
+
__extends = Array.isArray(newExtends)
|
|
64
|
+
? [...__extends, ...newExtends]
|
|
65
|
+
: [...__extends, newExtends]
|
|
66
|
+
ref.__extends = __extends
|
|
67
|
+
}
|
|
68
|
+
return __extends
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
export const concatAddExtends = (newExtend, element) => {
|
|
72
|
+
if (!newExtend) return element
|
|
73
|
+
const { extend: elementExtend } = element
|
|
74
|
+
const originalArray = isArray(elementExtend) ? elementExtend : [elementExtend]
|
|
75
|
+
const receivedArray = isArray(newExtend) ? newExtend : [newExtend]
|
|
76
|
+
return {
|
|
77
|
+
...element,
|
|
78
|
+
extends: joinArrays(receivedArray, originalArray)
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
export const generateHash = () => Math.random().toString(36).substring(2)
|
|
83
|
+
|
|
84
|
+
// hashing
|
|
85
|
+
export const extendStackRegistry = {}
|
|
86
|
+
export const extendCachedRegistry = {}
|
|
87
|
+
|
|
88
|
+
export const getHashedExtend = extend => {
|
|
89
|
+
return extendStackRegistry[extend.__hash]
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
export const setHashedExtend = (extend, stack) => {
|
|
93
|
+
const hash = generateHash()
|
|
94
|
+
if (!isString(extend)) {
|
|
95
|
+
extend.__hash = hash
|
|
96
|
+
}
|
|
97
|
+
if (!['__proto__', 'constructor', 'prototype'].includes(hash)) {
|
|
98
|
+
extendStackRegistry[hash] = stack
|
|
99
|
+
}
|
|
100
|
+
return stack
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
export const getExtendsStackRegistry = (extend, stack) => {
|
|
104
|
+
if (extend.__hash) {
|
|
105
|
+
return stack.concat(getHashedExtend(extend))
|
|
106
|
+
}
|
|
107
|
+
return setHashedExtend(extend, stack) // stack .concat(hashedExtend)
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
// stacking
|
|
111
|
+
export const extractArrayExtend = (
|
|
112
|
+
extend,
|
|
113
|
+
stack,
|
|
114
|
+
context,
|
|
115
|
+
processed = new Set()
|
|
116
|
+
) => {
|
|
117
|
+
for (const each of extend) {
|
|
118
|
+
if (isArray(each)) {
|
|
119
|
+
extractArrayExtend(each, stack, context, processed)
|
|
120
|
+
} else {
|
|
121
|
+
flattenExtend(each, stack, context, processed)
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
return stack
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
export const deepExtend = (extend, stack, context, processed = new Set()) => {
|
|
128
|
+
const extendOflattenExtend = extend.extends
|
|
129
|
+
// Remove extends property before adding to stack
|
|
130
|
+
const cleanExtend = { ...extend }
|
|
131
|
+
delete cleanExtend.extends
|
|
132
|
+
if (Object.keys(cleanExtend).length > 0) {
|
|
133
|
+
stack.push(cleanExtend)
|
|
134
|
+
}
|
|
135
|
+
if (extendOflattenExtend) {
|
|
136
|
+
flattenExtend(extendOflattenExtend, stack, context, processed)
|
|
137
|
+
}
|
|
138
|
+
return stack
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
export const flattenExtend = (
|
|
142
|
+
extend,
|
|
143
|
+
stack,
|
|
144
|
+
context,
|
|
145
|
+
processed = new Set()
|
|
146
|
+
) => {
|
|
147
|
+
if (!extend) return stack
|
|
148
|
+
if (processed.has(extend)) return stack
|
|
149
|
+
|
|
150
|
+
if (isArray(extend)) {
|
|
151
|
+
return extractArrayExtend(extend, stack, context, processed)
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
if (isString(extend)) {
|
|
155
|
+
extend = mapStringsWithContextComponents(extend, context)
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
processed.add(extend)
|
|
159
|
+
|
|
160
|
+
if (extend?.extends) {
|
|
161
|
+
deepExtend(extend, stack, context, processed)
|
|
162
|
+
} else if (extend) {
|
|
163
|
+
stack.push(extend)
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
return stack
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
export const deepMergeExtends = (element, extend) => {
|
|
170
|
+
// Clone extend to prevent mutations
|
|
171
|
+
extend = deepClone(extend)
|
|
172
|
+
|
|
173
|
+
for (const e in extend) {
|
|
174
|
+
if (['parent', 'node', '__ref'].indexOf(e) > -1) continue
|
|
175
|
+
if (e === '__proto__') continue
|
|
176
|
+
|
|
177
|
+
const elementProp = element[e]
|
|
178
|
+
const extendProp = extend[e]
|
|
179
|
+
|
|
180
|
+
// Skip if the property is undefined in the extend object
|
|
181
|
+
if (extendProp === undefined) continue
|
|
182
|
+
|
|
183
|
+
// Handle only properties that exist in the extend object
|
|
184
|
+
if (
|
|
185
|
+
Object.prototype.hasOwnProperty.call(extend, e) &&
|
|
186
|
+
!['__proto__', 'constructor', 'prototype'].includes(e)
|
|
187
|
+
) {
|
|
188
|
+
if (elementProp === undefined) {
|
|
189
|
+
// For undefined properties in element, copy from extend
|
|
190
|
+
element[e] = isObject(extendProp) ? deepClone(extendProp) : extendProp
|
|
191
|
+
} else if (isObject(elementProp) && isObject(extendProp)) {
|
|
192
|
+
// For objects, merge based on type
|
|
193
|
+
if (matchesComponentNaming(e)) {
|
|
194
|
+
// For components, override base properties with extended ones
|
|
195
|
+
element[e] = deepMergeExtends(elementProp, deepClone(extendProp))
|
|
196
|
+
} else {
|
|
197
|
+
// For other objects, merge normally
|
|
198
|
+
deepMergeExtends(elementProp, extendProp)
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
// If elementProp is defined and not an object, keep it (don't override)
|
|
202
|
+
// This preserves properties from earlier in the extend chain
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
return element
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
export const cloneAndMergeArrayExtend = stack => {
|
|
209
|
+
return stack.reduce((acc, current) => {
|
|
210
|
+
// Clone current extend to avoid mutations
|
|
211
|
+
const cloned = deepClone(current)
|
|
212
|
+
// Merge into accumulator, giving priority to current extend
|
|
213
|
+
return deepMergeExtends(acc, cloned)
|
|
214
|
+
}, {})
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
export const mapStringsWithContextComponents = (
|
|
218
|
+
extend,
|
|
219
|
+
context,
|
|
220
|
+
options = {},
|
|
221
|
+
variant
|
|
222
|
+
) => {
|
|
223
|
+
const COMPONENTS = (context && context.components) || options.components
|
|
224
|
+
const PAGES = (context && context.pages) || options.pages
|
|
225
|
+
if (isString(extend)) {
|
|
226
|
+
const componentExists =
|
|
227
|
+
COMPONENTS &&
|
|
228
|
+
(COMPONENTS[extend + '.' + variant] ||
|
|
229
|
+
COMPONENTS[extend] ||
|
|
230
|
+
COMPONENTS['smbls.' + extend])
|
|
231
|
+
const pageExists = PAGES && extend.startsWith('/') && PAGES[extend]
|
|
232
|
+
if (componentExists) return componentExists
|
|
233
|
+
else if (pageExists) return pageExists
|
|
234
|
+
else {
|
|
235
|
+
if (options.verbose && (ENV === 'test' || ENV === 'development')) {
|
|
236
|
+
console.warn('Extend is string but component was not found:', extend)
|
|
237
|
+
}
|
|
238
|
+
return
|
|
239
|
+
}
|
|
240
|
+
}
|
|
241
|
+
return extend
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
// joint stacks
|
|
245
|
+
export const jointStacks = (extendStack, childExtendsStack) => {
|
|
246
|
+
return []
|
|
247
|
+
.concat(extendStack.slice(0, 1))
|
|
248
|
+
.concat(childExtendsStack.slice(0, 1))
|
|
249
|
+
.concat(extendStack.slice(1))
|
|
250
|
+
.concat(childExtendsStack.slice(1))
|
|
251
|
+
}
|
|
252
|
+
|
|
253
|
+
// init
|
|
254
|
+
export const getExtendsStack = (extend, context) => {
|
|
255
|
+
if (!extend) return []
|
|
256
|
+
if (extend.__hash) return getHashedExtend(extend) || []
|
|
257
|
+
const processed = new Set()
|
|
258
|
+
const stack = flattenExtend(extend, [], context, processed)
|
|
259
|
+
return getExtendsStackRegistry(extend, stack)
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
export const addExtend = (newExtends, elementExtends) => {
|
|
263
|
+
if (!newExtends) return elementExtends
|
|
264
|
+
const receivedArray = isArray(newExtends) ? newExtends : [newExtends]
|
|
265
|
+
return joinArrays(receivedArray, elementExtends)
|
|
266
|
+
}
|
|
267
|
+
|
|
268
|
+
export const getExtendsInElement = obj => {
|
|
269
|
+
let result = []
|
|
270
|
+
|
|
271
|
+
function traverse (o) {
|
|
272
|
+
for (const key in o) {
|
|
273
|
+
if (Object.hasOwnProperty.call(o, key)) {
|
|
274
|
+
// Check if the key starts with a capital letter and exclude keys like @mobileL, $propsCollection
|
|
275
|
+
if (matchesComponentNaming(key)) {
|
|
276
|
+
result.push(key)
|
|
277
|
+
}
|
|
278
|
+
|
|
279
|
+
// Check if the key is "extend" and it's either a string or an array
|
|
280
|
+
if (key === 'extends') {
|
|
281
|
+
// Add the value of the extend key to the result array
|
|
282
|
+
if (typeof o[key] === 'string') {
|
|
283
|
+
result.push(o[key])
|
|
284
|
+
} else if (Array.isArray(o[key])) {
|
|
285
|
+
result = result.concat(o[key])
|
|
286
|
+
}
|
|
287
|
+
}
|
|
288
|
+
|
|
289
|
+
// If the property is an object, traverse it
|
|
290
|
+
if (typeof o[key] === 'object' && o[key] !== null) {
|
|
291
|
+
traverse(o[key])
|
|
292
|
+
}
|
|
293
|
+
}
|
|
294
|
+
}
|
|
295
|
+
}
|
|
296
|
+
|
|
297
|
+
traverse(obj)
|
|
298
|
+
return result
|
|
299
|
+
}
|
|
300
|
+
|
|
301
|
+
export const createElementExtends = (element, parent, options = {}) => {
|
|
302
|
+
const { __ref: ref } = element
|
|
303
|
+
const context = element.context || parent.context
|
|
304
|
+
const variant = element.props?.variant
|
|
305
|
+
|
|
306
|
+
// Add the extends property from element if it exists
|
|
307
|
+
if (element.extends) {
|
|
308
|
+
if (Array.isArray(element.extends) && element.extends.length > 0) {
|
|
309
|
+
// Handle first item in array specially for variant
|
|
310
|
+
const [firstExtend, ...restExtends] = element.extends
|
|
311
|
+
if (typeof firstExtend === 'string' && variant && context?.components) {
|
|
312
|
+
const variantKey = `${firstExtend}.${variant}`
|
|
313
|
+
if (context.components[variantKey]) {
|
|
314
|
+
addExtends([variantKey, ...restExtends], element)
|
|
315
|
+
} else {
|
|
316
|
+
addExtends(element.extends, element)
|
|
317
|
+
}
|
|
318
|
+
} else {
|
|
319
|
+
addExtends(element.extends, element)
|
|
320
|
+
}
|
|
321
|
+
} else if (
|
|
322
|
+
typeof element.extends === 'string' &&
|
|
323
|
+
variant &&
|
|
324
|
+
context?.components
|
|
325
|
+
) {
|
|
326
|
+
const variantKey = `${element.extends}.${variant}`
|
|
327
|
+
if (context.components[variantKey]) {
|
|
328
|
+
addExtends(variantKey, element)
|
|
329
|
+
} else {
|
|
330
|
+
addExtends(element.extends, element)
|
|
331
|
+
}
|
|
332
|
+
} else {
|
|
333
|
+
addExtends(element.extends, element)
|
|
334
|
+
}
|
|
335
|
+
}
|
|
336
|
+
|
|
337
|
+
inheritChildPropsExtends(element, parent, options)
|
|
338
|
+
inheritChildExtends(element, parent, options)
|
|
339
|
+
inheritRecursiveChildExtends(element, parent, options)
|
|
340
|
+
|
|
341
|
+
if (element.component) {
|
|
342
|
+
addExtends(exec(element.component, element), element)
|
|
343
|
+
}
|
|
344
|
+
|
|
345
|
+
if (context.defaultExtends) {
|
|
346
|
+
addExtends(context.defaultExtends, element)
|
|
347
|
+
}
|
|
348
|
+
|
|
349
|
+
return removeDuplicatesInArray(ref.__extends)
|
|
350
|
+
}
|
|
351
|
+
|
|
352
|
+
export const inheritChildPropsExtends = (element, parent, options = {}) => {
|
|
353
|
+
const { props, __ref: ref } = element
|
|
354
|
+
const ignoreChildExtends =
|
|
355
|
+
options.ignoreChildExtends || props?.ignoreChildExtends
|
|
356
|
+
if (!ignoreChildExtends) {
|
|
357
|
+
if (parent.props?.childProps?.extends) {
|
|
358
|
+
addExtends(parent.props?.childProps.extends, element)
|
|
359
|
+
}
|
|
360
|
+
}
|
|
361
|
+
return ref.__extends
|
|
362
|
+
}
|
|
363
|
+
|
|
364
|
+
export const inheritChildExtends = (element, parent, options = {}) => {
|
|
365
|
+
const { props, __ref: ref } = element
|
|
366
|
+
const ignoreChildExtends =
|
|
367
|
+
options.ignoreChildExtends || props?.ignoreChildExtends
|
|
368
|
+
|
|
369
|
+
if (!ignoreChildExtends && parent.childExtends) {
|
|
370
|
+
// Use else if to avoid double-adding
|
|
371
|
+
addExtends(parent.childExtends, element)
|
|
372
|
+
}
|
|
373
|
+
return ref.__extends
|
|
374
|
+
}
|
|
375
|
+
|
|
376
|
+
export const inheritRecursiveChildExtends = (element, parent, options = {}) => {
|
|
377
|
+
const { props, __ref: ref } = element
|
|
378
|
+
const childExtendsRecursive = parent.childExtendsRecursive
|
|
379
|
+
const ignoreChildExtendsRecursive =
|
|
380
|
+
options.ignoreChildExtendsRecursive || props?.ignoreChildExtendsRecursive
|
|
381
|
+
const isText = element.key === '__text'
|
|
382
|
+
if (childExtendsRecursive && !isText && !ignoreChildExtendsRecursive) {
|
|
383
|
+
addExtends(childExtendsRecursive, element)
|
|
384
|
+
}
|
|
385
|
+
return ref.__extends
|
|
386
|
+
}
|
|
387
|
+
|
|
388
|
+
export const createExtendsStack = (element, parent, options = {}) => {
|
|
389
|
+
const { props, __ref: ref } = element
|
|
390
|
+
const context = element.context || parent.context
|
|
391
|
+
|
|
392
|
+
// if (ENV !== 'test' && ENV !== 'development') delete element.extends
|
|
393
|
+
const variant = element.variant || props?.variant
|
|
394
|
+
|
|
395
|
+
const __extends = removeDuplicatesInArray(
|
|
396
|
+
ref.__extends.map((val, i) => {
|
|
397
|
+
return mapStringsWithContextComponents(
|
|
398
|
+
val,
|
|
399
|
+
context,
|
|
400
|
+
options,
|
|
401
|
+
i === 0 && variant
|
|
402
|
+
)
|
|
403
|
+
})
|
|
404
|
+
)
|
|
405
|
+
|
|
406
|
+
const stack = getExtendsStack(__extends, context)
|
|
407
|
+
ref.__extendsStack = stack
|
|
408
|
+
|
|
409
|
+
return ref.__extendsStack
|
|
410
|
+
}
|
|
411
|
+
|
|
412
|
+
export const finalizeExtends = (element, parent, options = {}) => {
|
|
413
|
+
const { __ref: ref } = element
|
|
414
|
+
const { __extendsStack } = ref
|
|
415
|
+
const flattenExtends = cloneAndMergeArrayExtend(__extendsStack)
|
|
416
|
+
|
|
417
|
+
return deepMergeExtends(element, flattenExtends)
|
|
418
|
+
}
|
|
419
|
+
|
|
420
|
+
export const applyExtends = (element, parent, options = {}) => {
|
|
421
|
+
createElementExtends(element, parent, options)
|
|
422
|
+
createExtendsStack(element, parent, options)
|
|
423
|
+
finalizeExtends(element, parent, options)
|
|
424
|
+
return element
|
|
425
|
+
}
|
package/if.js
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
'use strict'
|
|
2
|
+
|
|
3
|
+
import { isFunction } from './types.js'
|
|
4
|
+
|
|
5
|
+
export const createIfConditionFlag = (element, parent) => {
|
|
6
|
+
const { __ref: ref } = element
|
|
7
|
+
|
|
8
|
+
if (
|
|
9
|
+
isFunction(element.if) &&
|
|
10
|
+
!element.if(element, element.state, element.context)
|
|
11
|
+
) {
|
|
12
|
+
delete ref.__if
|
|
13
|
+
} else ref.__if = true
|
|
14
|
+
}
|
package/index.js
CHANGED
|
@@ -7,9 +7,19 @@ export * from './object.js'
|
|
|
7
7
|
export * from './function.js'
|
|
8
8
|
export * from './array.js'
|
|
9
9
|
export * from './node.js'
|
|
10
|
+
export * from './if.js'
|
|
10
11
|
export * from './log.js'
|
|
11
12
|
export * from './string.js'
|
|
12
13
|
export * from './globals.js'
|
|
13
14
|
export * from './cookie.js'
|
|
14
15
|
export * from './tags.js'
|
|
15
16
|
export * from './component.js'
|
|
17
|
+
export * from './props.js'
|
|
18
|
+
export * from './extends.js'
|
|
19
|
+
export * from './element.js'
|
|
20
|
+
export * from './state.js'
|
|
21
|
+
export * from './keys.js'
|
|
22
|
+
export * from './scope.js'
|
|
23
|
+
export * from './methods.js'
|
|
24
|
+
export * from './cache.js'
|
|
25
|
+
export * from './update.js'
|
package/key.js
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
'use strict'
|
|
2
2
|
|
|
3
|
+
import { exec } from './object.js'
|
|
4
|
+
|
|
3
5
|
export const generateKey = (function () {
|
|
4
6
|
let index = 0
|
|
5
7
|
|
|
@@ -12,3 +14,7 @@ export const generateKey = (function () {
|
|
|
12
14
|
})()
|
|
13
15
|
|
|
14
16
|
export const createSnapshotId = generateKey
|
|
17
|
+
|
|
18
|
+
export const createKey = (element, parent, key) => {
|
|
19
|
+
return (exec(key, element) || key || element.key || generateKey()).toString()
|
|
20
|
+
}
|
package/keys.js
ADDED
|
@@ -0,0 +1,157 @@
|
|
|
1
|
+
'use strict'
|
|
2
|
+
|
|
3
|
+
export const DOMQ_PROPERTIES = [
|
|
4
|
+
'attr',
|
|
5
|
+
'style',
|
|
6
|
+
'text',
|
|
7
|
+
'html',
|
|
8
|
+
'content',
|
|
9
|
+
'data',
|
|
10
|
+
'class',
|
|
11
|
+
'state',
|
|
12
|
+
'scope',
|
|
13
|
+
'deps',
|
|
14
|
+
'extends',
|
|
15
|
+
'$router',
|
|
16
|
+
'routes',
|
|
17
|
+
'children',
|
|
18
|
+
'childExtends',
|
|
19
|
+
'childExtendsRecursive',
|
|
20
|
+
'props',
|
|
21
|
+
'if',
|
|
22
|
+
'define',
|
|
23
|
+
'__name',
|
|
24
|
+
'__ref',
|
|
25
|
+
'__hash',
|
|
26
|
+
'__text',
|
|
27
|
+
'key',
|
|
28
|
+
'tag',
|
|
29
|
+
'query',
|
|
30
|
+
'parent',
|
|
31
|
+
'node',
|
|
32
|
+
'variables',
|
|
33
|
+
'on',
|
|
34
|
+
'component',
|
|
35
|
+
'context'
|
|
36
|
+
]
|
|
37
|
+
|
|
38
|
+
export const PARSED_DOMQ_PROPERTIES = [
|
|
39
|
+
'attr',
|
|
40
|
+
'style',
|
|
41
|
+
'text',
|
|
42
|
+
'html',
|
|
43
|
+
'content',
|
|
44
|
+
'data',
|
|
45
|
+
'class',
|
|
46
|
+
'state',
|
|
47
|
+
'scope',
|
|
48
|
+
'children',
|
|
49
|
+
'props',
|
|
50
|
+
'if',
|
|
51
|
+
'key',
|
|
52
|
+
'tag',
|
|
53
|
+
'query',
|
|
54
|
+
'on',
|
|
55
|
+
'context'
|
|
56
|
+
]
|
|
57
|
+
|
|
58
|
+
export const STATE_PROPERTIES = [
|
|
59
|
+
'ref',
|
|
60
|
+
'parent',
|
|
61
|
+
'__element',
|
|
62
|
+
'__depends',
|
|
63
|
+
'__ref',
|
|
64
|
+
'__children',
|
|
65
|
+
'root'
|
|
66
|
+
]
|
|
67
|
+
|
|
68
|
+
export const STATE_METHODS = [
|
|
69
|
+
'update',
|
|
70
|
+
'parse',
|
|
71
|
+
'clean',
|
|
72
|
+
'create',
|
|
73
|
+
'destroy',
|
|
74
|
+
'add',
|
|
75
|
+
'toggle',
|
|
76
|
+
'remove',
|
|
77
|
+
'apply',
|
|
78
|
+
'set',
|
|
79
|
+
'reset',
|
|
80
|
+
'replace',
|
|
81
|
+
'quietReplace',
|
|
82
|
+
'quietUpdate',
|
|
83
|
+
'applyReplace',
|
|
84
|
+
'applyFunction',
|
|
85
|
+
'keys',
|
|
86
|
+
'values',
|
|
87
|
+
'ref',
|
|
88
|
+
'rootUpdate',
|
|
89
|
+
'parentUpdate',
|
|
90
|
+
'parent',
|
|
91
|
+
'__element',
|
|
92
|
+
'__depends',
|
|
93
|
+
'__ref',
|
|
94
|
+
'__children',
|
|
95
|
+
'root',
|
|
96
|
+
'setByPath',
|
|
97
|
+
'setPathCollection',
|
|
98
|
+
'removeByPath',
|
|
99
|
+
'removePathCollection',
|
|
100
|
+
'getByPath'
|
|
101
|
+
]
|
|
102
|
+
|
|
103
|
+
export const PROPS_METHODS = ['update', '__element']
|
|
104
|
+
|
|
105
|
+
export const METHODS = [
|
|
106
|
+
'set',
|
|
107
|
+
'reset',
|
|
108
|
+
'update',
|
|
109
|
+
'remove',
|
|
110
|
+
'updateContent',
|
|
111
|
+
'removeContent',
|
|
112
|
+
'lookup',
|
|
113
|
+
'lookdown',
|
|
114
|
+
'lookdownAll',
|
|
115
|
+
'getRef',
|
|
116
|
+
'getPath',
|
|
117
|
+
'setNodeStyles',
|
|
118
|
+
'spotByPath',
|
|
119
|
+
'keys',
|
|
120
|
+
'parse',
|
|
121
|
+
'setProps',
|
|
122
|
+
'parseDeep',
|
|
123
|
+
'variables',
|
|
124
|
+
'if',
|
|
125
|
+
'log',
|
|
126
|
+
'verbose',
|
|
127
|
+
'warn',
|
|
128
|
+
'error',
|
|
129
|
+
'call',
|
|
130
|
+
'nextElement',
|
|
131
|
+
'previousElement'
|
|
132
|
+
]
|
|
133
|
+
|
|
134
|
+
export const METHODS_EXL = [
|
|
135
|
+
...['node', 'context', 'extends', '__element', '__ref'],
|
|
136
|
+
...METHODS,
|
|
137
|
+
...STATE_METHODS,
|
|
138
|
+
...PROPS_METHODS
|
|
139
|
+
]
|
|
140
|
+
|
|
141
|
+
export const DOMQL_EVENTS = [
|
|
142
|
+
'init',
|
|
143
|
+
'beforeClassAssign',
|
|
144
|
+
'render',
|
|
145
|
+
'renderRouter',
|
|
146
|
+
'attachNode',
|
|
147
|
+
'stateInit',
|
|
148
|
+
'stateCreated',
|
|
149
|
+
'beforeStateUpdate',
|
|
150
|
+
'stateUpdate',
|
|
151
|
+
'beforeUpdate',
|
|
152
|
+
'done',
|
|
153
|
+
'create',
|
|
154
|
+
'complete',
|
|
155
|
+
'frame',
|
|
156
|
+
'update'
|
|
157
|
+
]
|
package/log.js
CHANGED
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
'use strict'
|
|
2
2
|
|
|
3
|
-
export const logIf = (bool, ...arg) => {
|
|
3
|
+
export const logIf = (bool, ...arg) => {
|
|
4
|
+
if (bool) arg.map(v => console.log(v))
|
|
5
|
+
}
|
|
6
|
+
|
|
4
7
|
export const logGroupIf = (bool, key, ...arg) => {
|
|
5
8
|
if (bool) {
|
|
6
9
|
console.group(key)
|