@oscarpalmer/abydon 0.17.0 → 0.20.0
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/dist/abydon.full.mjs +304 -90
- package/dist/constants.d.mts +20 -1
- package/dist/constants.mjs +24 -5
- package/dist/fragments.mjs +4 -4
- package/dist/helpers/dom.d.mts +2 -1
- package/dist/helpers/dom.mjs +4 -1
- package/dist/helpers/index.d.mts +2 -1
- package/dist/helpers/index.mjs +3 -6
- package/dist/node/attribute/index.mjs +12 -2
- package/dist/node/attribute/value.mjs +3 -3
- package/dist/node/event.mjs +3 -3
- package/dist/node/index.mjs +24 -2
- package/dist/node/value.mjs +2 -1
- package/package.json +3 -4
- package/src/constants.ts +42 -4
- package/src/fragment.ts +2 -2
- package/src/fragments.ts +10 -4
- package/src/helpers/dom.ts +4 -0
- package/src/helpers/index.ts +13 -10
- package/src/node/attribute/index.ts +27 -1
- package/src/node/attribute/value.ts +11 -6
- package/src/node/event.ts +9 -4
- package/src/node/index.ts +54 -2
- package/src/node/value.ts +3 -2
package/dist/abydon.full.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
//#region node_modules/@oscarpalmer/mora/dist/constants.
|
|
1
|
+
//#region node_modules/@oscarpalmer/mora/dist/constants.mjs
|
|
2
2
|
const ACTIVE = {};
|
|
3
3
|
const BATCH = {
|
|
4
4
|
depth: 0,
|
|
@@ -31,7 +31,7 @@ const NAME_ALL = new Set([
|
|
|
31
31
|
NAME_STORE
|
|
32
32
|
]);
|
|
33
33
|
//#endregion
|
|
34
|
-
//#region node_modules/@oscarpalmer/mora/dist/effect.
|
|
34
|
+
//#region node_modules/@oscarpalmer/mora/dist/effect.mjs
|
|
35
35
|
var Effect = class {
|
|
36
36
|
constructor(callback) {
|
|
37
37
|
Object.defineProperty(this, NAME_MORA, { value: NAME_EFFECT });
|
|
@@ -39,40 +39,70 @@ var Effect = class {
|
|
|
39
39
|
runEffect(this);
|
|
40
40
|
}
|
|
41
41
|
};
|
|
42
|
-
function runEffect(effect
|
|
42
|
+
function runEffect(effect) {
|
|
43
43
|
const previousEffect = ACTIVE.effect;
|
|
44
|
-
ACTIVE.effect = effect
|
|
44
|
+
ACTIVE.effect = effect;
|
|
45
45
|
try {
|
|
46
|
-
effect
|
|
46
|
+
effect.state.callback();
|
|
47
47
|
} finally {
|
|
48
48
|
ACTIVE.effect = previousEffect;
|
|
49
49
|
}
|
|
50
50
|
}
|
|
51
|
+
/**
|
|
52
|
+
* Create an effect
|
|
53
|
+
* @param callback Callback for handling signal effects
|
|
54
|
+
* @returns Effect
|
|
55
|
+
*/
|
|
51
56
|
function effect(callback) {
|
|
52
57
|
return typeof callback === "function" ? new Effect(callback) : void 0;
|
|
53
58
|
}
|
|
54
59
|
//#endregion
|
|
55
|
-
//#region node_modules/@oscarpalmer/mora/dist/helpers/is.
|
|
60
|
+
//#region node_modules/@oscarpalmer/mora/dist/helpers/is.mjs
|
|
61
|
+
/**
|
|
62
|
+
* Is the value a reactive array?
|
|
63
|
+
* @param value Value to check
|
|
64
|
+
* @returns True if value is a {@link ReactiveArray}
|
|
65
|
+
*/
|
|
56
66
|
function isArray(value) {
|
|
57
67
|
return isMora(value, NAME_ARRAY);
|
|
58
68
|
}
|
|
69
|
+
/**
|
|
70
|
+
* Is the value a computed signal?
|
|
71
|
+
* @param value Value to check
|
|
72
|
+
* @returns True if value is a {@link Computed}
|
|
73
|
+
*/
|
|
59
74
|
function isComputed(value) {
|
|
60
75
|
return isMora(value, NAME_COMPUTED);
|
|
61
76
|
}
|
|
77
|
+
/**
|
|
78
|
+
* Is the value an effect?
|
|
79
|
+
* @param value Value to check
|
|
80
|
+
* @returns True if value is an {@link Effect}
|
|
81
|
+
*/
|
|
62
82
|
function isEffect(value) {
|
|
63
83
|
return isMora(value, NAME_EFFECT);
|
|
64
84
|
}
|
|
65
85
|
function isMora(value, name) {
|
|
66
86
|
return typeof value === "object" && value != null && "$mora" in value && (typeof name === "string" ? value["$mora"] === name : name.has(value["$mora"]));
|
|
67
87
|
}
|
|
88
|
+
/**
|
|
89
|
+
* Is the value reactive?
|
|
90
|
+
* @param value Value to check
|
|
91
|
+
* @returns True if value is a {@link Reactive}
|
|
92
|
+
*/
|
|
68
93
|
function isReactive(value) {
|
|
69
94
|
return isMora(value, NAME_ALL);
|
|
70
95
|
}
|
|
96
|
+
/**
|
|
97
|
+
* Is the value a signal?
|
|
98
|
+
* @param value Value to check
|
|
99
|
+
* @returns True if value is a {@link Signal}
|
|
100
|
+
*/
|
|
71
101
|
function isSignal(value) {
|
|
72
102
|
return isMora(value, NAME_SIGNAL);
|
|
73
103
|
}
|
|
74
104
|
//#endregion
|
|
75
|
-
//#region node_modules/@oscarpalmer/mora/dist/batch.
|
|
105
|
+
//#region node_modules/@oscarpalmer/mora/dist/batch.mjs
|
|
76
106
|
function flushHandlers() {
|
|
77
107
|
while (BATCH.depth === 0 && BATCH.handlers.size > 0) {
|
|
78
108
|
const handlers = [...BATCH.handlers];
|
|
@@ -81,15 +111,23 @@ function flushHandlers() {
|
|
|
81
111
|
else handler.callback(handler.state.value);
|
|
82
112
|
}
|
|
83
113
|
}
|
|
114
|
+
/**
|
|
115
|
+
* Start batching effects
|
|
116
|
+
*
|
|
117
|
+
* _(Use {@link stopBatch} to flush and run batched effects)_
|
|
118
|
+
*/
|
|
84
119
|
function startBatch() {
|
|
85
120
|
BATCH.depth += 1;
|
|
86
121
|
}
|
|
122
|
+
/**
|
|
123
|
+
* Stop batching effects and flush _(run)_ them
|
|
124
|
+
*/
|
|
87
125
|
function stopBatch() {
|
|
88
126
|
if (BATCH.depth > 0) BATCH.depth -= 1;
|
|
89
127
|
flushHandlers();
|
|
90
128
|
}
|
|
91
129
|
//#endregion
|
|
92
|
-
//#region node_modules/@oscarpalmer/mora/dist/subscription.
|
|
130
|
+
//#region node_modules/@oscarpalmer/mora/dist/subscription.mjs
|
|
93
131
|
var Subscription = class {
|
|
94
132
|
callback;
|
|
95
133
|
state;
|
|
@@ -116,7 +154,7 @@ function unsubscribe(state, callback) {
|
|
|
116
154
|
state.subscriptions.delete(callback);
|
|
117
155
|
}
|
|
118
156
|
//#endregion
|
|
119
|
-
//#region node_modules/@oscarpalmer/mora/dist/value/reactive.
|
|
157
|
+
//#region node_modules/@oscarpalmer/mora/dist/value/reactive.mjs
|
|
120
158
|
var Reactive = class {
|
|
121
159
|
state = {
|
|
122
160
|
computeds: /* @__PURE__ */ new Set(),
|
|
@@ -130,24 +168,45 @@ var Reactive = class {
|
|
|
130
168
|
if (typeof options === "object" && typeof options.equal === "function") this.state.equal = options.equal;
|
|
131
169
|
Object.defineProperty(this, NAME_MORA, { value: name });
|
|
132
170
|
}
|
|
171
|
+
/**
|
|
172
|
+
* Get the value _(without reactivity)_
|
|
173
|
+
* @return Current value
|
|
174
|
+
*/
|
|
133
175
|
peek() {
|
|
134
176
|
return this.state.value;
|
|
135
177
|
}
|
|
178
|
+
/**
|
|
179
|
+
* Subscribe to changes
|
|
180
|
+
* @param callback Callback for changes
|
|
181
|
+
* @return Unsubscribe callback
|
|
182
|
+
*/
|
|
136
183
|
subscribe(callback) {
|
|
137
184
|
return subscribe(this.state, callback);
|
|
138
185
|
}
|
|
186
|
+
/**
|
|
187
|
+
* JSON representation of the value
|
|
188
|
+
* @return JSON value
|
|
189
|
+
*/
|
|
139
190
|
toJSON() {
|
|
140
191
|
return this.get();
|
|
141
192
|
}
|
|
193
|
+
/**
|
|
194
|
+
* String representation of the value
|
|
195
|
+
* @return Value as string
|
|
196
|
+
*/
|
|
142
197
|
toString() {
|
|
143
198
|
return String(this.get());
|
|
144
199
|
}
|
|
200
|
+
/**
|
|
201
|
+
* Unsubscribe from changes
|
|
202
|
+
* @param callback Callback to unsubscribe
|
|
203
|
+
*/
|
|
145
204
|
unsubscribe(callback) {
|
|
146
205
|
unsubscribe(this.state, callback);
|
|
147
206
|
}
|
|
148
207
|
};
|
|
149
208
|
//#endregion
|
|
150
|
-
//#region node_modules/@oscarpalmer/mora/dist/value/computed.
|
|
209
|
+
//#region node_modules/@oscarpalmer/mora/dist/value/computed.mjs
|
|
151
210
|
var Computed = class extends Reactive {
|
|
152
211
|
effect = {
|
|
153
212
|
dirty: true,
|
|
@@ -163,13 +222,16 @@ var Computed = class extends Reactive {
|
|
|
163
222
|
ACTIVE.computed = previousComputed;
|
|
164
223
|
if (!this.state.equal(this.state.value, value)) {
|
|
165
224
|
this.state.value = value;
|
|
166
|
-
for (const computed
|
|
167
|
-
for (const effect
|
|
225
|
+
for (const computed of this.state.computeds) computed.effect.dirty = true;
|
|
226
|
+
for (const effect of this.state.effects) BATCH.handlers.add(effect);
|
|
168
227
|
for (const [, subscription] of this.state.subscriptions) subscription.callback(value);
|
|
169
228
|
}
|
|
170
229
|
this.effect.dirty = false;
|
|
171
230
|
});
|
|
172
231
|
}
|
|
232
|
+
/**
|
|
233
|
+
* @inheritdoc
|
|
234
|
+
*/
|
|
173
235
|
get() {
|
|
174
236
|
if (ACTIVE.computed != null && this !== ACTIVE.computed) this.state.computeds.add(ACTIVE.computed);
|
|
175
237
|
if (ACTIVE.effect != null && ACTIVE.effect !== this.effect.instance) this.state.effects.add(ACTIVE.effect);
|
|
@@ -177,11 +239,17 @@ var Computed = class extends Reactive {
|
|
|
177
239
|
return this.state.value;
|
|
178
240
|
}
|
|
179
241
|
};
|
|
242
|
+
/**
|
|
243
|
+
* Create a computed value
|
|
244
|
+
* @param callback Callback to compute the value
|
|
245
|
+
* @param options Reactivity options
|
|
246
|
+
* @returns Computed value
|
|
247
|
+
*/
|
|
180
248
|
function computed(callback, options) {
|
|
181
249
|
return new Computed(callback, options);
|
|
182
250
|
}
|
|
183
251
|
//#endregion
|
|
184
|
-
//#region node_modules/@oscarpalmer/mora/dist/helpers/value.
|
|
252
|
+
//#region node_modules/@oscarpalmer/mora/dist/helpers/value.mjs
|
|
185
253
|
function emitValue(state) {
|
|
186
254
|
for (const computed of state.computeds) computed.effect.dirty = true;
|
|
187
255
|
for (const effect of state.effects) BATCH.handlers.add(effect);
|
|
@@ -207,29 +275,46 @@ function getValue$1(state) {
|
|
|
207
275
|
return state.value;
|
|
208
276
|
}
|
|
209
277
|
//#endregion
|
|
210
|
-
//#region node_modules/@oscarpalmer/mora/dist/value/signal.
|
|
278
|
+
//#region node_modules/@oscarpalmer/mora/dist/value/signal.mjs
|
|
211
279
|
var Signal = class extends Reactive {
|
|
212
280
|
constructor(value, options) {
|
|
213
281
|
super(NAME_SIGNAL, value, options);
|
|
214
282
|
}
|
|
283
|
+
/**
|
|
284
|
+
* @inheritdoc
|
|
285
|
+
*/
|
|
215
286
|
get() {
|
|
216
287
|
return getValue$1(this.state);
|
|
217
288
|
}
|
|
289
|
+
/**
|
|
290
|
+
* Set the value
|
|
291
|
+
* @param value New value
|
|
292
|
+
*/
|
|
218
293
|
set(value) {
|
|
219
294
|
if (!this.state.equal(this.state.value, value)) {
|
|
220
295
|
this.state.value = value;
|
|
221
296
|
emitValue(this.state);
|
|
222
297
|
}
|
|
223
298
|
}
|
|
299
|
+
/**
|
|
300
|
+
* Update the value _(based on the current value)_
|
|
301
|
+
* @param callback Callback to update the value
|
|
302
|
+
*/
|
|
224
303
|
update(callback) {
|
|
225
304
|
this.set(callback(this.state.value));
|
|
226
305
|
}
|
|
227
306
|
};
|
|
307
|
+
/**
|
|
308
|
+
* Create a reactive value
|
|
309
|
+
* @param value Initial value
|
|
310
|
+
* @param options Reactivity options
|
|
311
|
+
* @returns Reactive value
|
|
312
|
+
*/
|
|
228
313
|
function signal(value, options) {
|
|
229
314
|
return new Signal(value, options);
|
|
230
315
|
}
|
|
231
316
|
//#endregion
|
|
232
|
-
//#region node_modules/@oscarpalmer/mora/dist/helpers/proxy.
|
|
317
|
+
//#region node_modules/@oscarpalmer/mora/dist/helpers/proxy.mjs
|
|
233
318
|
function emityProxyValues(state, mapped) {
|
|
234
319
|
const values = [...mapped.values()];
|
|
235
320
|
const { length } = values;
|
|
@@ -274,23 +359,29 @@ function setValueInProxy(parameters) {
|
|
|
274
359
|
return true;
|
|
275
360
|
}
|
|
276
361
|
//#endregion
|
|
277
|
-
//#region node_modules/@oscarpalmer/mora/dist/value/array.
|
|
362
|
+
//#region node_modules/@oscarpalmer/mora/dist/value/array.mjs
|
|
278
363
|
var ReactiveArray = class extends Reactive {
|
|
279
364
|
#indiced = /* @__PURE__ */ new Map();
|
|
280
365
|
#size = signal(0);
|
|
366
|
+
/**
|
|
367
|
+
* The length of the array
|
|
368
|
+
*/
|
|
281
369
|
get length() {
|
|
282
370
|
return this.#size.get();
|
|
283
371
|
}
|
|
372
|
+
/**
|
|
373
|
+
* Set the length of the array
|
|
374
|
+
*/
|
|
284
375
|
set length(value) {
|
|
285
376
|
if (typeof value === "number" && value >= 0 && value !== this.state.value.length) this.get().length = value;
|
|
286
377
|
}
|
|
287
378
|
constructor(value, options) {
|
|
288
379
|
super(NAME_ARRAY, new Proxy(value, {
|
|
289
380
|
get: (target, property) => METHODS_UPDATE.has(property) ? updateArray(property, target, this.state, this.#size) : Reflect.get(target, property),
|
|
290
|
-
set: (target, property, value
|
|
381
|
+
set: (target, property, value) => setValueInProxy({
|
|
291
382
|
property,
|
|
292
383
|
target,
|
|
293
|
-
value
|
|
384
|
+
value,
|
|
294
385
|
isArray: true,
|
|
295
386
|
state: this.state,
|
|
296
387
|
length: this.#size
|
|
@@ -298,9 +389,17 @@ var ReactiveArray = class extends Reactive {
|
|
|
298
389
|
}), options);
|
|
299
390
|
this.#size.set(value.length);
|
|
300
391
|
}
|
|
392
|
+
/**
|
|
393
|
+
* Clear the array
|
|
394
|
+
*/
|
|
301
395
|
clear() {
|
|
302
396
|
this.length = 0;
|
|
303
397
|
}
|
|
398
|
+
/**
|
|
399
|
+
* Create a computed, filtered array
|
|
400
|
+
* @param callback Callback to evaluate each item
|
|
401
|
+
* @return Computed array of filtered items
|
|
402
|
+
*/
|
|
304
403
|
filter(callback) {
|
|
305
404
|
return computed(() => this.get().filter(callback));
|
|
306
405
|
}
|
|
@@ -308,9 +407,20 @@ var ReactiveArray = class extends Reactive {
|
|
|
308
407
|
if (typeof first === "number") return getReactiveValueInProxy(this, this.#indiced, first, true).get();
|
|
309
408
|
return first === "length" ? this.length : getValue$1(this.state);
|
|
310
409
|
}
|
|
410
|
+
/**
|
|
411
|
+
* Create a computed, mapped array
|
|
412
|
+
* @param callback Callback to transform each item
|
|
413
|
+
* @return Computed array of mapped items
|
|
414
|
+
*/
|
|
311
415
|
map(callback) {
|
|
312
416
|
return computed(() => this.get().map(callback));
|
|
313
417
|
}
|
|
418
|
+
/**
|
|
419
|
+
* Notify dependents of changes
|
|
420
|
+
*
|
|
421
|
+
* _This bypasses equality checks and will immediately notify dependents.
|
|
422
|
+
* Use this only if you're modifying nested data that would be ignored by equality checks._
|
|
423
|
+
*/
|
|
314
424
|
notify() {
|
|
315
425
|
emityProxyValues(this.state, this.#indiced);
|
|
316
426
|
}
|
|
@@ -318,9 +428,18 @@ var ReactiveArray = class extends Reactive {
|
|
|
318
428
|
if (value === "length") return this.#size.peek();
|
|
319
429
|
return typeof value === "number" ? this.state.value.at(value) : [...this.state.value];
|
|
320
430
|
}
|
|
431
|
+
/**
|
|
432
|
+
* Remove and return the last item of the array
|
|
433
|
+
* @returns Removed item, or `undefined` if the array is empty
|
|
434
|
+
*/
|
|
321
435
|
pop() {
|
|
322
436
|
return this.state.value.pop();
|
|
323
437
|
}
|
|
438
|
+
/**
|
|
439
|
+
* Add items to the end of the array
|
|
440
|
+
* @param items Items to add
|
|
441
|
+
* @returns New array length
|
|
442
|
+
*/
|
|
324
443
|
push(...items) {
|
|
325
444
|
return this.state.value.push(...items);
|
|
326
445
|
}
|
|
@@ -329,9 +448,20 @@ var ReactiveArray = class extends Reactive {
|
|
|
329
448
|
else if (first === "length") this.length = second;
|
|
330
449
|
else if (typeof first === "number" && !Number.isNaN(first)) setAtIndex(this.state.value, first, second);
|
|
331
450
|
}
|
|
451
|
+
/**
|
|
452
|
+
* Remove and return the first item of the array
|
|
453
|
+
* @returns Removed item, or `undefined` if the array is empty
|
|
454
|
+
*/
|
|
332
455
|
shift() {
|
|
333
456
|
return this.state.value.shift();
|
|
334
457
|
}
|
|
458
|
+
/**
|
|
459
|
+
* Remove and return items from the array _(and optionally add new items)_
|
|
460
|
+
* @param from Index to start removing items from
|
|
461
|
+
* @param to Index to stop removing items at _(defaults to the end of the array)_
|
|
462
|
+
* @param items Optional items to add
|
|
463
|
+
* @returns Removed items
|
|
464
|
+
*/
|
|
335
465
|
splice(from, to, ...items) {
|
|
336
466
|
return this.state.value.splice(from, to ?? this.state.value.length, ...items);
|
|
337
467
|
}
|
|
@@ -339,54 +469,105 @@ var ReactiveArray = class extends Reactive {
|
|
|
339
469
|
if (typeof first === "number" && typeof second === "function") return getReactiveValueInProxy(this, this.#indiced, first, true).subscribe(second);
|
|
340
470
|
return typeof first === "function" ? subscribe(this.state, first) : noop$1;
|
|
341
471
|
}
|
|
472
|
+
/**
|
|
473
|
+
* Add items to the beginning of the array
|
|
474
|
+
* @param items Items to add
|
|
475
|
+
* @returns New array length
|
|
476
|
+
*/
|
|
342
477
|
unshift(...items) {
|
|
343
478
|
return this.state.value.unshift(...items);
|
|
344
479
|
}
|
|
480
|
+
/**
|
|
481
|
+
* Update the value _(based on the current value)_
|
|
482
|
+
* @param callback Callback to update the value
|
|
483
|
+
*/
|
|
345
484
|
update(callback) {
|
|
346
485
|
const updated = callback(this.state.value);
|
|
347
486
|
if (updated == null || Array.isArray(updated)) this.set(updated);
|
|
348
487
|
}
|
|
349
488
|
};
|
|
489
|
+
/**
|
|
490
|
+
* Create a reactive array
|
|
491
|
+
* @param value Initial array of items
|
|
492
|
+
* @param options Reactivity options
|
|
493
|
+
* @returns Reactive array
|
|
494
|
+
*/
|
|
350
495
|
function array(value, options) {
|
|
351
496
|
return new ReactiveArray(Array.isArray(value) ? value : [], options);
|
|
352
497
|
}
|
|
353
|
-
function updateArray(type, array
|
|
498
|
+
function updateArray(type, array, state, length) {
|
|
354
499
|
const affectsLength = METHODS_AFFECTING_LENGTH.has(type);
|
|
355
|
-
const previousArray = affectsLength ? [] : [...array
|
|
356
|
-
const previousLength = array
|
|
500
|
+
const previousArray = affectsLength ? [] : [...array];
|
|
501
|
+
const previousLength = array.length;
|
|
357
502
|
return (...args) => {
|
|
358
|
-
const result = array
|
|
359
|
-
if (affectsLength ? array
|
|
503
|
+
const result = array[type](...args);
|
|
504
|
+
if (affectsLength ? array.length !== previousLength : !equalArrays(state, previousArray, array)) {
|
|
360
505
|
emitValue(state);
|
|
361
|
-
length.set(array
|
|
506
|
+
length.set(array.length);
|
|
362
507
|
}
|
|
363
508
|
return result;
|
|
364
509
|
};
|
|
365
510
|
}
|
|
366
|
-
function setAtIndex(array
|
|
367
|
-
const actual = index < 0 ? array
|
|
368
|
-
if (actual > -1) array
|
|
511
|
+
function setAtIndex(array, index, value) {
|
|
512
|
+
const actual = index < 0 ? array.length + index : index;
|
|
513
|
+
if (actual > -1) array[actual] = value;
|
|
369
514
|
}
|
|
370
515
|
//#endregion
|
|
371
|
-
//#region node_modules/@oscarpalmer/
|
|
516
|
+
//#region node_modules/@oscarpalmer/atoms/dist/internal/is.mjs
|
|
517
|
+
/**
|
|
518
|
+
* Is the value a key?
|
|
519
|
+
* @param value Value to check
|
|
520
|
+
* @returns `true` if the value is a `Key` _(`number` or `string`)_, otherwise `false`
|
|
521
|
+
*/
|
|
372
522
|
function isKey(value) {
|
|
373
523
|
return typeof value === "number" || typeof value === "string";
|
|
374
524
|
}
|
|
375
|
-
|
|
525
|
+
/**
|
|
526
|
+
* Is the value a plain object?
|
|
527
|
+
* @param value Value to check
|
|
528
|
+
* @returns `true` if the value is a plain object, otherwise `false`
|
|
529
|
+
*/
|
|
530
|
+
function isPlainObject(value) {
|
|
376
531
|
if (value === null || typeof value !== "object") return false;
|
|
377
532
|
if (Symbol.toStringTag in value || Symbol.iterator in value) return false;
|
|
378
533
|
const prototype = Object.getPrototypeOf(value);
|
|
379
534
|
return prototype === null || prototype === Object.prototype || Object.getPrototypeOf(prototype) === null;
|
|
380
535
|
}
|
|
381
536
|
//#endregion
|
|
382
|
-
//#region node_modules/@oscarpalmer/
|
|
537
|
+
//#region node_modules/@oscarpalmer/atoms/dist/internal/string.mjs
|
|
538
|
+
/**
|
|
539
|
+
* Get the string value from any value
|
|
540
|
+
* @param value Original value
|
|
541
|
+
* @returns String representation of the value
|
|
542
|
+
*/
|
|
543
|
+
function getString(value) {
|
|
544
|
+
if (typeof value === "string") return value;
|
|
545
|
+
if (value == null) return "";
|
|
546
|
+
if (typeof value === "function") return getString(value());
|
|
547
|
+
if (typeof value !== "object") return String(value);
|
|
548
|
+
const asString = String(value.valueOf?.() ?? value);
|
|
549
|
+
return asString.startsWith("[object ") ? JSON.stringify(value) : asString;
|
|
550
|
+
}
|
|
551
|
+
//#endregion
|
|
552
|
+
//#region node_modules/@oscarpalmer/atoms/dist/is.mjs
|
|
553
|
+
/**
|
|
554
|
+
* Is the value `undefined`, `null`, or a whitespace-only string?
|
|
555
|
+
* @param value Value to check
|
|
556
|
+
* @returns `true` if the value is nullable or a whitespace-only string, otherwise `false`
|
|
557
|
+
*/
|
|
558
|
+
function isNullableOrWhitespace(value) {
|
|
559
|
+
return value == null || EXPRESSION_WHITESPACE$1.test(getString(value));
|
|
560
|
+
}
|
|
561
|
+
const EXPRESSION_WHITESPACE$1 = /^\s*$/;
|
|
562
|
+
//#endregion
|
|
563
|
+
//#region node_modules/@oscarpalmer/mora/dist/value/store.mjs
|
|
383
564
|
var Store = class extends Reactive {
|
|
384
565
|
#keyed = /* @__PURE__ */ new Map();
|
|
385
566
|
constructor(value, options) {
|
|
386
|
-
super(NAME_STORE, new Proxy(value, { set: (target, property, value
|
|
567
|
+
super(NAME_STORE, new Proxy(value, { set: (target, property, value) => setValueInProxy({
|
|
387
568
|
target,
|
|
388
569
|
property,
|
|
389
|
-
value
|
|
570
|
+
value,
|
|
390
571
|
isArray: false,
|
|
391
572
|
state: this.state
|
|
392
573
|
}) }), options);
|
|
@@ -394,6 +575,12 @@ var Store = class extends Reactive {
|
|
|
394
575
|
get(key) {
|
|
395
576
|
return isKey(key) ? getReactiveValueInProxy(this, this.#keyed, key, false).get() : getValue$1(this.state);
|
|
396
577
|
}
|
|
578
|
+
/**
|
|
579
|
+
* Notify dependents of changes
|
|
580
|
+
*
|
|
581
|
+
* _This bypasses equality checks and will immediately notify dependents.
|
|
582
|
+
* Use this only if you're modifying nested data that would be ignored by equality checks._
|
|
583
|
+
*/
|
|
397
584
|
notify() {
|
|
398
585
|
emityProxyValues(this.state, this.#keyed);
|
|
399
586
|
}
|
|
@@ -402,59 +589,30 @@ var Store = class extends Reactive {
|
|
|
402
589
|
}
|
|
403
590
|
set(first, second) {
|
|
404
591
|
if (isKey(first)) this.state.value[first] = second;
|
|
405
|
-
else if (first == null || isPlainObject
|
|
592
|
+
else if (first == null || isPlainObject(first)) setProxyValue(this.state.value, first ?? {});
|
|
406
593
|
}
|
|
407
594
|
subscribe(first, second) {
|
|
408
595
|
if (isKey(first) && typeof second === "function") return getReactiveValueInProxy(this, this.#keyed, first, false).subscribe(second);
|
|
409
596
|
return typeof first === "function" ? subscribe(this.state, first) : noop$1;
|
|
410
597
|
}
|
|
598
|
+
/**
|
|
599
|
+
* Update the value _(based on the current value)_
|
|
600
|
+
* @param callback Callback to update the value
|
|
601
|
+
*/
|
|
411
602
|
update(callback) {
|
|
412
603
|
const updated = callback({ ...this.state.value });
|
|
413
|
-
if (updated == null || isPlainObject
|
|
604
|
+
if (updated == null || isPlainObject(updated)) setProxyValue(this.state.value, updated ?? {});
|
|
414
605
|
}
|
|
415
606
|
};
|
|
416
|
-
function store(value, options) {
|
|
417
|
-
return new Store(isPlainObject$1(value) ? value : {}, options);
|
|
418
|
-
}
|
|
419
|
-
//#endregion
|
|
420
|
-
//#region node_modules/@oscarpalmer/atoms/dist/internal/is.mjs
|
|
421
|
-
/**
|
|
422
|
-
* Is the value a plain object?
|
|
423
|
-
* @param value Value to check
|
|
424
|
-
* @returns `true` if the value is a plain object, otherwise `false`
|
|
425
|
-
*/
|
|
426
|
-
function isPlainObject(value) {
|
|
427
|
-
if (value === null || typeof value !== "object") return false;
|
|
428
|
-
if (Symbol.toStringTag in value || Symbol.iterator in value) return false;
|
|
429
|
-
const prototype = Object.getPrototypeOf(value);
|
|
430
|
-
return prototype === null || prototype === Object.prototype || Object.getPrototypeOf(prototype) === null;
|
|
431
|
-
}
|
|
432
|
-
//#endregion
|
|
433
|
-
//#region node_modules/@oscarpalmer/atoms/dist/internal/string.mjs
|
|
434
607
|
/**
|
|
435
|
-
*
|
|
436
|
-
* @param value
|
|
437
|
-
* @
|
|
608
|
+
* Create a reactive store
|
|
609
|
+
* @param value Initial object value
|
|
610
|
+
* @param options Reactivity options
|
|
611
|
+
* @returns Reactive store
|
|
438
612
|
*/
|
|
439
|
-
function
|
|
440
|
-
|
|
441
|
-
if (value == null) return "";
|
|
442
|
-
if (typeof value === "function") return getString(value());
|
|
443
|
-
if (typeof value !== "object") return String(value);
|
|
444
|
-
const asString = String(value.valueOf?.() ?? value);
|
|
445
|
-
return asString.startsWith("[object ") ? JSON.stringify(value) : asString;
|
|
446
|
-
}
|
|
447
|
-
//#endregion
|
|
448
|
-
//#region node_modules/@oscarpalmer/atoms/dist/is.mjs
|
|
449
|
-
/**
|
|
450
|
-
* Is the value `undefined`, `null`, or a whitespace-only string?
|
|
451
|
-
* @param value Value to check
|
|
452
|
-
* @returns `true` if the value is nullable or a whitespace-only string, otherwise `false`
|
|
453
|
-
*/
|
|
454
|
-
function isNullableOrWhitespace(value) {
|
|
455
|
-
return value == null || EXPRESSION_WHITESPACE$1.test(getString(value));
|
|
613
|
+
function store(value, options) {
|
|
614
|
+
return new Store(isPlainObject(value) ? value : {}, options);
|
|
456
615
|
}
|
|
457
|
-
const EXPRESSION_WHITESPACE$1 = /^\s*$/;
|
|
458
616
|
//#endregion
|
|
459
617
|
//#region node_modules/@oscarpalmer/toretto/dist/internal/is.mjs
|
|
460
618
|
/**
|
|
@@ -760,15 +918,24 @@ let parser;
|
|
|
760
918
|
let templates = {};
|
|
761
919
|
//#endregion
|
|
762
920
|
//#region src/constants.ts
|
|
921
|
+
const ARRAY_COMPARISON_ADDED = "added";
|
|
922
|
+
const ARRAY_COMPARISON_DISSIMILAR = "dissimilar";
|
|
923
|
+
const ARRAY_COMPARISON_REMOVED = "removed";
|
|
924
|
+
const ERROR_FRAGMENT = "Fragment function must return a Fragment instance";
|
|
925
|
+
const ERROR_IDENTIFIER_DUPLICATE = "Duplicate identifier found: '<id>'";
|
|
926
|
+
const ERROR_IDENTIFIER_TYPE = "Identifier cannot be null or undefined";
|
|
927
|
+
const EVENT_CHANGE = "change";
|
|
928
|
+
const EVENT_INPUT = "input";
|
|
929
|
+
const EVENT_SUBMIT = "submit";
|
|
763
930
|
const EVENT_DEFAULTS = {
|
|
764
931
|
A: "click",
|
|
765
932
|
BUTTON: "click",
|
|
766
933
|
DETAILS: "toggle",
|
|
767
|
-
FORM:
|
|
768
|
-
SELECT:
|
|
769
|
-
TEXTAREA:
|
|
934
|
+
FORM: EVENT_SUBMIT,
|
|
935
|
+
SELECT: EVENT_CHANGE,
|
|
936
|
+
TEXTAREA: EVENT_INPUT
|
|
770
937
|
};
|
|
771
|
-
const EXPRESSION_ABYDON_ATTRIBUTE_FULL = /(
|
|
938
|
+
const EXPRESSION_ABYDON_ATTRIBUTE_FULL = /(@?[\w-]+)="<!--abydon.(\d+)-->"/g;
|
|
772
939
|
const EXPRESSION_ABYDON_ATTRIBUTE_PREFIX = /^_/;
|
|
773
940
|
const EXPRESSION_ABYDON_CONTENT = /^@?abydon\.(\d+)@?$/;
|
|
774
941
|
const EXPRESSION_ATTRIBUTE_CLASS = /^class\./;
|
|
@@ -781,16 +948,34 @@ const EXPRESSION_EVENT_OPTIONS_CAPTURE = /^c(apture)$/i;
|
|
|
781
948
|
const EXPRESSION_EVENT_OPTIONS_ONCE = /^o(nce)$/i;
|
|
782
949
|
const EXPRESSION_EVENT_PREFIX = /^@/;
|
|
783
950
|
const EXPRESSION_PERIOD = /\./;
|
|
951
|
+
const EXPRESSION_TEXTAREA_VALUE = /<!--abydon\.(\d+)-->/;
|
|
784
952
|
const NAME_FRAGMENT = "$fragment";
|
|
785
953
|
const NAME_FRAGMENTS = "$fragments";
|
|
954
|
+
const PROPERTY_CHECKED = "checked";
|
|
955
|
+
const PROPERTY_VALUE = "value";
|
|
956
|
+
//#endregion
|
|
957
|
+
//#region node_modules/@oscarpalmer/atoms/dist/string/index.mjs
|
|
958
|
+
/**
|
|
959
|
+
* Parse a JSON string into its proper value _(or `undefined` if it fails)_
|
|
960
|
+
* @param value JSON string to parse
|
|
961
|
+
* @param reviver Reviver function to transform the parsed values
|
|
962
|
+
* @returns Parsed value or `undefined` if parsing fails
|
|
963
|
+
*/
|
|
964
|
+
function parse$1(value, reviver) {
|
|
965
|
+
try {
|
|
966
|
+
return JSON.parse(value, reviver);
|
|
967
|
+
} catch {
|
|
968
|
+
return;
|
|
969
|
+
}
|
|
970
|
+
}
|
|
786
971
|
//#endregion
|
|
787
972
|
//#region src/helpers/index.ts
|
|
788
973
|
function compareArrays(first, second) {
|
|
789
974
|
const firstIsLarger = first.length > second.length;
|
|
790
975
|
const from = firstIsLarger ? first : second;
|
|
791
976
|
const to = firstIsLarger ? second : first;
|
|
792
|
-
if (!from.filter((key) => to.includes(key)).every((key, index) => to[index] === key)) return
|
|
793
|
-
return firstIsLarger ?
|
|
977
|
+
if (!from.filter((key) => to.includes(key)).every((key, index) => to[index] === key)) return ARRAY_COMPARISON_DISSIMILAR;
|
|
978
|
+
return firstIsLarger ? ARRAY_COMPARISON_REMOVED : ARRAY_COMPARISON_ADDED;
|
|
794
979
|
}
|
|
795
980
|
function isFragment(value) {
|
|
796
981
|
return isNamed(value, NAME_FRAGMENT);
|
|
@@ -801,9 +986,6 @@ function isFragments(value) {
|
|
|
801
986
|
function isNamed(value, name) {
|
|
802
987
|
return typeof value === "object" && value != null && name in value && value[name] === true;
|
|
803
988
|
}
|
|
804
|
-
const COMPARISON_ADDED = "added";
|
|
805
|
-
const COMPARISON_DISSIMILAR = "dissimilar";
|
|
806
|
-
const COMPARISON_REMOVED = "removed";
|
|
807
989
|
//#endregion
|
|
808
990
|
//#region src/fragments.ts
|
|
809
991
|
var Fragments = class {
|
|
@@ -839,13 +1021,13 @@ function handleItems(state, items) {
|
|
|
839
1021
|
for (let index = 0; index < length; index += 1) {
|
|
840
1022
|
const item = items[index];
|
|
841
1023
|
const identifier = state.identify(item);
|
|
842
|
-
if (identifier == null) throw new
|
|
1024
|
+
if (identifier == null) throw new TypeError(ERROR_IDENTIFIER_TYPE);
|
|
843
1025
|
const key = getString(identifier);
|
|
844
|
-
if (keys.has(key)) throw new Error(
|
|
1026
|
+
if (keys.has(key)) throw new Error(ERROR_IDENTIFIER_DUPLICATE.replace("<>", key));
|
|
845
1027
|
let instance = state.instances[key];
|
|
846
1028
|
if (instance == null) {
|
|
847
1029
|
instance = state.fragment(item);
|
|
848
|
-
if (!isFragment(instance)) throw new Error(
|
|
1030
|
+
if (!isFragment(instance)) throw new Error(ERROR_FRAGMENT);
|
|
849
1031
|
}
|
|
850
1032
|
instance.identify(key);
|
|
851
1033
|
state.instances[key] = instance;
|
|
@@ -886,6 +1068,9 @@ function createNodes(value) {
|
|
|
886
1068
|
if (isChildNode(value)) return [value];
|
|
887
1069
|
return [new Text(getString(value))];
|
|
888
1070
|
}
|
|
1071
|
+
function isInputElement(node) {
|
|
1072
|
+
return node instanceof HTMLInputElement || node instanceof HTMLSelectElement;
|
|
1073
|
+
}
|
|
889
1074
|
function removeNodes(nodes) {
|
|
890
1075
|
const { length } = nodes;
|
|
891
1076
|
for (let index = 0; index < length; index += 1) nodes[index].remove();
|
|
@@ -1023,8 +1208,8 @@ function getOptions(options) {
|
|
|
1023
1208
|
function getType(element, type) {
|
|
1024
1209
|
if (type !== "on") return type;
|
|
1025
1210
|
if (element instanceof HTMLInputElement) {
|
|
1026
|
-
if (EXPRESSION_EVENT_CHANGE_TYPES.test(element.type)) return
|
|
1027
|
-
return element.type === "submit" ?
|
|
1211
|
+
if (EXPRESSION_EVENT_CHANGE_TYPES.test(element.type)) return EVENT_CHANGE;
|
|
1212
|
+
return element.type === "submit" ? EVENT_SUBMIT : EVENT_INPUT;
|
|
1028
1213
|
}
|
|
1029
1214
|
return EVENT_DEFAULTS[element.tagName] ?? type;
|
|
1030
1215
|
}
|
|
@@ -1083,7 +1268,7 @@ function setValue(data, element, name, value) {
|
|
|
1083
1268
|
else callback(element, name, value);
|
|
1084
1269
|
}
|
|
1085
1270
|
function updateChecked(element, name, value) {
|
|
1086
|
-
updateElement(
|
|
1271
|
+
updateElement(EVENT_CHANGE, PROPERTY_CHECKED, element, name, value, value === true);
|
|
1087
1272
|
}
|
|
1088
1273
|
function updateElement(event, property, element, name, value, next) {
|
|
1089
1274
|
if (!(property in element) || element[property] === next) return;
|
|
@@ -1096,7 +1281,7 @@ function updateProperty(element, name, value) {
|
|
|
1096
1281
|
setAttribute$1(element, name, value === true);
|
|
1097
1282
|
}
|
|
1098
1283
|
function updateValue(element, name, value) {
|
|
1099
|
-
updateElement(element instanceof HTMLSelectElement ?
|
|
1284
|
+
updateElement(element instanceof HTMLSelectElement ? EVENT_CHANGE : EVENT_INPUT, PROPERTY_VALUE, element, name, value, String(value));
|
|
1100
1285
|
}
|
|
1101
1286
|
//#endregion
|
|
1102
1287
|
//#region src/node/attribute/index.ts
|
|
@@ -1128,6 +1313,14 @@ function mapAttributes(data, element) {
|
|
|
1128
1313
|
function mapValue$1(data, element, name, value) {
|
|
1129
1314
|
if (typeof value === "function") setComputedAttribute(data, element, name, value);
|
|
1130
1315
|
else setAttribute(data, element, name, value);
|
|
1316
|
+
if (!isInputElement(element) || !isSignal(value)) return;
|
|
1317
|
+
let property;
|
|
1318
|
+
if (name === "checked" && element.type === "checkbox") property = PROPERTY_CHECKED;
|
|
1319
|
+
else if (name === "value") property = PROPERTY_VALUE;
|
|
1320
|
+
if (property != null) mapEvent(element, "@on", () => {
|
|
1321
|
+
const next = element[property];
|
|
1322
|
+
value.set(parse$1(String(next)) ?? next);
|
|
1323
|
+
});
|
|
1131
1324
|
}
|
|
1132
1325
|
function setComputedAttribute(data, element, name, callback) {
|
|
1133
1326
|
const value = computed(callback);
|
|
@@ -1157,7 +1350,7 @@ function handleArray(identifiers, items, nodes) {
|
|
|
1157
1350
|
if (comparison !== "removed") addToArray(identifiers, {
|
|
1158
1351
|
...items,
|
|
1159
1352
|
next
|
|
1160
|
-
}, nodes, comparison ===
|
|
1353
|
+
}, nodes, comparison === ARRAY_COMPARISON_ADDED);
|
|
1161
1354
|
const toRemove = items.fragments?.filter((fragment) => !identifiers.next.has(fragment.identifier)) ?? [];
|
|
1162
1355
|
const { length } = toRemove;
|
|
1163
1356
|
for (let index = 0; index < length; index += 1) toRemove[index].remove();
|
|
@@ -1258,10 +1451,31 @@ function mapNodes(data, nodes) {
|
|
|
1258
1451
|
mapNode(data, node);
|
|
1259
1452
|
continue;
|
|
1260
1453
|
}
|
|
1454
|
+
if (node instanceof HTMLTextAreaElement) mapTextarea(data, node);
|
|
1261
1455
|
if (isHTMLOrSVGElement(node)) mapAttributes(data, node);
|
|
1262
1456
|
if (node.hasChildNodes()) mapNodes(data, [...node.childNodes]);
|
|
1263
1457
|
}
|
|
1264
1458
|
}
|
|
1459
|
+
function mapTextarea(data, element) {
|
|
1460
|
+
const [, index] = EXPRESSION_TEXTAREA_VALUE.exec(element.value) ?? [];
|
|
1461
|
+
if (index == null) return;
|
|
1462
|
+
element.value = "";
|
|
1463
|
+
const value = data.values[Number.parseInt(index, 10)];
|
|
1464
|
+
if (isSignal(value)) {
|
|
1465
|
+
element.value = String(value.peek());
|
|
1466
|
+
mapEvent(element, "@on", () => {
|
|
1467
|
+
value.set(element.value);
|
|
1468
|
+
});
|
|
1469
|
+
return;
|
|
1470
|
+
}
|
|
1471
|
+
let reactive;
|
|
1472
|
+
if (typeof value === "function") reactive = computed(value);
|
|
1473
|
+
else if (isComputed(value)) reactive = value;
|
|
1474
|
+
if (reactive == null) element.value = String(value);
|
|
1475
|
+
else data.mora.subscribers.add(reactive.subscribe((value) => {
|
|
1476
|
+
element.value = String(value);
|
|
1477
|
+
}));
|
|
1478
|
+
}
|
|
1265
1479
|
function mapValue(data, comment, value) {
|
|
1266
1480
|
switch (true) {
|
|
1267
1481
|
case typeof value === "function":
|