essor 0.0.11 → 0.0.12
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/essor.cjs.js +38 -35
- package/dist/essor.cjs.js.map +1 -1
- package/dist/essor.d.cts +1 -1
- package/dist/essor.d.ts +1 -1
- package/dist/essor.dev.cjs.js +719 -263
- package/dist/essor.dev.esm.js +714 -261
- package/dist/essor.esm.js +7 -7
- package/dist/essor.esm.js.map +1 -1
- package/package.json +4 -4
package/dist/essor.dev.cjs.js
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
|
-
* essor v0.0.
|
|
4
|
+
* essor v0.0.12
|
|
5
5
|
* (c) 2023-Present jiangxd <jiangxd2016@gmail.com>
|
|
6
6
|
* @license MIT
|
|
7
7
|
**/
|
|
8
8
|
|
|
9
9
|
// src/version.ts
|
|
10
|
-
var essor_version = "0.0.
|
|
10
|
+
var essor_version = "0.0.12";
|
|
11
11
|
|
|
12
12
|
// ../shared/dist/shared.js
|
|
13
13
|
var isObject = (val) => val !== null && typeof val === "object";
|
|
@@ -15,6 +15,9 @@ var isArray = Array.isArray;
|
|
|
15
15
|
function isString(val) {
|
|
16
16
|
return typeof val === "string";
|
|
17
17
|
}
|
|
18
|
+
function isSymbol(val) {
|
|
19
|
+
return typeof val === "symbol";
|
|
20
|
+
}
|
|
18
21
|
function isNil(x) {
|
|
19
22
|
return x === null || x === void 0;
|
|
20
23
|
}
|
|
@@ -31,6 +34,24 @@ function startsWith(str, searchString) {
|
|
|
31
34
|
}
|
|
32
35
|
return str.indexOf(searchString) === 0;
|
|
33
36
|
}
|
|
37
|
+
function escape(str) {
|
|
38
|
+
return str.replaceAll(/["&'<>]/g, (char) => {
|
|
39
|
+
switch (char) {
|
|
40
|
+
case "&":
|
|
41
|
+
return "&";
|
|
42
|
+
case "<":
|
|
43
|
+
return "<";
|
|
44
|
+
case ">":
|
|
45
|
+
return ">";
|
|
46
|
+
case '"':
|
|
47
|
+
return """;
|
|
48
|
+
case "'":
|
|
49
|
+
return "'";
|
|
50
|
+
default:
|
|
51
|
+
return char;
|
|
52
|
+
}
|
|
53
|
+
});
|
|
54
|
+
}
|
|
34
55
|
var kebabCase = (string) => {
|
|
35
56
|
return string.replaceAll(/[A-Z]+/g, (match, offset) => {
|
|
36
57
|
return `${offset > 0 ? "-" : ""}${match.toLocaleLowerCase()}`;
|
|
@@ -62,9 +83,6 @@ var isArray2 = Array.isArray;
|
|
|
62
83
|
function isString2(val) {
|
|
63
84
|
return typeof val === "string";
|
|
64
85
|
}
|
|
65
|
-
function isNull(val) {
|
|
66
|
-
return val === null;
|
|
67
|
-
}
|
|
68
86
|
function isSet(val) {
|
|
69
87
|
return _toString.call(val) === "[object Set]";
|
|
70
88
|
}
|
|
@@ -78,41 +96,90 @@ function isMap(val) {
|
|
|
78
96
|
return _toString.call(val) === "[object Map]";
|
|
79
97
|
}
|
|
80
98
|
var isFunction2 = (val) => typeof val === "function";
|
|
81
|
-
var
|
|
82
|
-
function
|
|
83
|
-
if (!
|
|
84
|
-
|
|
99
|
+
var isPlainObject = (val) => _toString.call(val) === "[object Object]";
|
|
100
|
+
function isStringNumber(val) {
|
|
101
|
+
if (!isString2(val)) {
|
|
102
|
+
return false;
|
|
103
|
+
}
|
|
104
|
+
return !Number.isNaN(Number(val));
|
|
85
105
|
}
|
|
86
106
|
var _toString = Object.prototype.toString;
|
|
87
107
|
var hasOwnProperty = Object.prototype.hasOwnProperty;
|
|
88
108
|
var hasOwn = (val, key) => hasOwnProperty.call(val, key);
|
|
89
109
|
var hasChanged = (value, oldValue) => value !== oldValue && (value === value || oldValue === oldValue);
|
|
90
110
|
var noop2 = Function.prototype;
|
|
91
|
-
function startsWith2(str, searchString) {
|
|
92
|
-
if (!isString2(str)) {
|
|
93
|
-
return false;
|
|
94
|
-
}
|
|
95
|
-
return str.indexOf(searchString) === 0;
|
|
96
|
-
}
|
|
97
111
|
function isExclude(key, exclude) {
|
|
98
112
|
return Array.isArray(exclude) ? exclude.includes(key) : isFunction2(exclude) ? exclude(key) : false;
|
|
99
113
|
}
|
|
100
114
|
function warn(msg, ...args) {
|
|
101
115
|
console.warn.apply(console, [`[Essor warn]: ${msg}`].concat(args));
|
|
102
116
|
}
|
|
117
|
+
var queue = [];
|
|
118
|
+
var activePreFlushCbs = [];
|
|
119
|
+
var p = Promise.resolve();
|
|
120
|
+
var isFlushPending = false;
|
|
121
|
+
function nextTick(fn) {
|
|
122
|
+
return fn ? p.then(fn) : p;
|
|
123
|
+
}
|
|
124
|
+
function queueJob(job) {
|
|
125
|
+
if (!queue.includes(job)) {
|
|
126
|
+
queue.push(job);
|
|
127
|
+
queueFlush();
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
function queueFlush() {
|
|
131
|
+
if (isFlushPending) {
|
|
132
|
+
return;
|
|
133
|
+
}
|
|
134
|
+
isFlushPending = true;
|
|
135
|
+
nextTick(flushJobs);
|
|
136
|
+
}
|
|
137
|
+
function queuePreFlushCb(cb) {
|
|
138
|
+
queueCb(cb, activePreFlushCbs);
|
|
139
|
+
}
|
|
140
|
+
function queueCb(cb, activeQueue) {
|
|
141
|
+
if (!activeQueue.includes(cb)) {
|
|
142
|
+
activeQueue.push(cb);
|
|
143
|
+
queueFlush();
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
function flushJobs() {
|
|
147
|
+
isFlushPending = false;
|
|
148
|
+
flushPreFlushCbs();
|
|
149
|
+
let job;
|
|
150
|
+
while (job = queue.shift()) {
|
|
151
|
+
if (job) {
|
|
152
|
+
job();
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
function flushPreFlushCbs() {
|
|
157
|
+
while (activePreFlushCbs.length > 0) {
|
|
158
|
+
const cb = activePreFlushCbs.shift();
|
|
159
|
+
if (cb) {
|
|
160
|
+
cb();
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
}
|
|
103
164
|
var activeEffect = null;
|
|
104
165
|
var activeComputed = null;
|
|
105
|
-
var
|
|
106
|
-
var signalMap = /* @__PURE__ */ new WeakMap();
|
|
107
|
-
var effectDeps = /* @__PURE__ */ new Set();
|
|
166
|
+
var triggerMap = /* @__PURE__ */ new WeakMap();
|
|
108
167
|
var reactiveMap = /* @__PURE__ */ new WeakMap();
|
|
109
|
-
var
|
|
168
|
+
var ReactiveSymbol = Symbol("ReactiveSymbol");
|
|
169
|
+
var ReactivePeekSymbol = Symbol("__raw");
|
|
170
|
+
var SignalValueKey = Symbol("SignalValueKey");
|
|
171
|
+
var ComputedValueKey = Symbol("ComputedValueKey");
|
|
172
|
+
var reactiveArrayKey = Symbol("ReactiveArrayKey");
|
|
173
|
+
var ReactiveCollectionKey = Symbol("ReactiveCollectionKey");
|
|
174
|
+
var ReactiveWeakCollectionKey = Symbol("ReactiveWeakCollectionKey");
|
|
175
|
+
var inBatch = false;
|
|
176
|
+
var batchQueue = /* @__PURE__ */ new Set();
|
|
110
177
|
function track(target, key) {
|
|
111
178
|
if (!activeEffect && !activeComputed) return;
|
|
112
|
-
let depsMap =
|
|
179
|
+
let depsMap = triggerMap.get(target);
|
|
113
180
|
if (!depsMap) {
|
|
114
181
|
depsMap = /* @__PURE__ */ new Map();
|
|
115
|
-
|
|
182
|
+
triggerMap.set(target, depsMap);
|
|
116
183
|
}
|
|
117
184
|
let dep = depsMap.get(key);
|
|
118
185
|
if (!dep) {
|
|
@@ -120,75 +187,63 @@ function track(target, key) {
|
|
|
120
187
|
depsMap.set(key, dep);
|
|
121
188
|
}
|
|
122
189
|
if (activeEffect) dep.add(activeEffect);
|
|
123
|
-
let computedDepsMap = computedMap.get(target);
|
|
124
|
-
if (!computedDepsMap) {
|
|
125
|
-
computedDepsMap = /* @__PURE__ */ new Map();
|
|
126
|
-
computedMap.set(target, computedDepsMap);
|
|
127
|
-
}
|
|
128
|
-
let computedDeps = computedDepsMap.get(key);
|
|
129
|
-
if (!computedDeps) {
|
|
130
|
-
computedDeps = /* @__PURE__ */ new Set();
|
|
131
|
-
computedDepsMap.set(key, computedDeps);
|
|
132
|
-
}
|
|
133
|
-
if (activeComputed) {
|
|
134
|
-
computedDeps.add(activeComputed);
|
|
135
|
-
}
|
|
136
190
|
}
|
|
137
191
|
function trigger(target, key) {
|
|
138
|
-
const depsMap =
|
|
192
|
+
const depsMap = triggerMap.get(target);
|
|
139
193
|
if (!depsMap) return;
|
|
140
194
|
const dep = depsMap.get(key);
|
|
141
195
|
if (dep) {
|
|
142
|
-
dep.forEach((effect) =>
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
196
|
+
dep.forEach((effect) => {
|
|
197
|
+
if (hasOwn(effect, "active") && !effect.active) {
|
|
198
|
+
dep.delete(effect);
|
|
199
|
+
return;
|
|
200
|
+
}
|
|
201
|
+
if (inBatch) {
|
|
202
|
+
batchQueue.add(effect);
|
|
203
|
+
} else {
|
|
204
|
+
effect();
|
|
205
|
+
}
|
|
206
|
+
});
|
|
150
207
|
}
|
|
151
208
|
}
|
|
152
209
|
var Signal = class {
|
|
210
|
+
/**
|
|
211
|
+
* Creates a new Signal instance.
|
|
212
|
+
* @param {T} value - The initial value of the Signal.
|
|
213
|
+
* @param {boolean} [shallow] - Whether to create a shallow Signal.
|
|
214
|
+
*/
|
|
153
215
|
constructor(value, shallow = false) {
|
|
154
|
-
this.
|
|
216
|
+
this.__signal = true;
|
|
155
217
|
this._shallow = shallow;
|
|
218
|
+
this._value = value;
|
|
156
219
|
}
|
|
157
220
|
/**
|
|
158
|
-
*
|
|
221
|
+
* Gets the current value of the Signal.
|
|
222
|
+
* @returns {T} The current value.
|
|
159
223
|
*/
|
|
160
224
|
get value() {
|
|
161
|
-
track(this,
|
|
162
|
-
this.
|
|
163
|
-
|
|
164
|
-
}
|
|
165
|
-
/**
|
|
166
|
-
* Trigger reactivity for non-primitive and non-HTMLElement values.
|
|
167
|
-
* Recursively applies reactivity to nested objects.
|
|
168
|
-
*/
|
|
169
|
-
__triggerObject() {
|
|
170
|
-
if (!isPrimitive(this._value) && !isHTMLElement(this._value) && !this._shallow) {
|
|
171
|
-
useReactive(this._value);
|
|
225
|
+
track(this, SignalValueKey);
|
|
226
|
+
if (isObject2(this._value) && !this._shallow) {
|
|
227
|
+
return useReactive(this._value);
|
|
172
228
|
}
|
|
229
|
+
return this._value;
|
|
173
230
|
}
|
|
174
231
|
/**
|
|
175
|
-
*
|
|
232
|
+
* Sets a new value for the Signal.
|
|
233
|
+
* @param {T} newValue - The new value to set.
|
|
176
234
|
*/
|
|
177
235
|
set value(newValue) {
|
|
178
236
|
if (isSignal(newValue)) {
|
|
179
|
-
console.warn("Signal cannot be set to another signal, use .peek() instead");
|
|
180
237
|
newValue = newValue.peek();
|
|
181
238
|
}
|
|
182
239
|
if (hasChanged(newValue, this._value)) {
|
|
183
240
|
this._value = newValue;
|
|
184
|
-
|
|
185
|
-
this.__triggerObject();
|
|
186
|
-
}
|
|
187
|
-
trigger(this, "_sv");
|
|
241
|
+
trigger(this, SignalValueKey);
|
|
188
242
|
}
|
|
189
243
|
}
|
|
190
244
|
/**
|
|
191
|
-
*
|
|
245
|
+
* Returns the current value without triggering reactivity.
|
|
246
|
+
* @returns {T} The current value.
|
|
192
247
|
*/
|
|
193
248
|
peek() {
|
|
194
249
|
return this._value;
|
|
@@ -204,15 +259,16 @@ function shallowSignal(value) {
|
|
|
204
259
|
return new Signal(value, true);
|
|
205
260
|
}
|
|
206
261
|
function isSignal(value) {
|
|
207
|
-
return value
|
|
262
|
+
return !!(value && (value == null ? void 0 : value.__signal));
|
|
208
263
|
}
|
|
209
264
|
var Computed = class {
|
|
210
265
|
constructor(fn) {
|
|
211
266
|
this.fn = fn;
|
|
212
|
-
|
|
213
|
-
|
|
267
|
+
this.__computed = true;
|
|
268
|
+
const prev = activeEffect;
|
|
269
|
+
activeEffect = this.run.bind(this);
|
|
214
270
|
this._value = this.fn();
|
|
215
|
-
|
|
271
|
+
activeEffect = prev;
|
|
216
272
|
}
|
|
217
273
|
/**
|
|
218
274
|
* Get the current computed value without tracking it.
|
|
@@ -227,14 +283,14 @@ var Computed = class {
|
|
|
227
283
|
const newValue = this.fn();
|
|
228
284
|
if (hasChanged(newValue, this._value)) {
|
|
229
285
|
this._value = newValue;
|
|
230
|
-
trigger(this,
|
|
286
|
+
trigger(this, ComputedValueKey);
|
|
231
287
|
}
|
|
232
288
|
}
|
|
233
289
|
/**
|
|
234
290
|
* Get the current computed value and track its usage.
|
|
235
291
|
*/
|
|
236
292
|
get value() {
|
|
237
|
-
track(this,
|
|
293
|
+
track(this, ComputedValueKey);
|
|
238
294
|
return this._value;
|
|
239
295
|
}
|
|
240
296
|
};
|
|
@@ -242,23 +298,46 @@ function useComputed(fn) {
|
|
|
242
298
|
return new Computed(fn);
|
|
243
299
|
}
|
|
244
300
|
function isComputed(value) {
|
|
245
|
-
return value
|
|
301
|
+
return !!(value && value.__computed);
|
|
302
|
+
}
|
|
303
|
+
function createScheduler(effect, flush) {
|
|
304
|
+
if (flush === "sync") {
|
|
305
|
+
return () => effect();
|
|
306
|
+
} else if (flush === "pre") {
|
|
307
|
+
return () => queuePreFlushCb(effect);
|
|
308
|
+
} else {
|
|
309
|
+
return () => {
|
|
310
|
+
nextTick(() => queueJob(effect));
|
|
311
|
+
};
|
|
312
|
+
}
|
|
246
313
|
}
|
|
247
|
-
function useEffect(fn) {
|
|
314
|
+
function useEffect(fn, options = {}) {
|
|
315
|
+
const { flush = "pre", onTrack, onTrigger } = options;
|
|
248
316
|
function effectFn() {
|
|
249
317
|
const prev = activeEffect;
|
|
250
|
-
activeEffect = effectFn;
|
|
318
|
+
activeEffect = effectFn.init ? effectFn : effectFn.scheduler;
|
|
251
319
|
fn();
|
|
320
|
+
onTrigger && onTrigger();
|
|
252
321
|
activeEffect = prev;
|
|
253
322
|
}
|
|
254
|
-
|
|
323
|
+
const scheduler = createScheduler(effectFn, flush);
|
|
324
|
+
effectFn.scheduler = scheduler;
|
|
325
|
+
effectFn.init = true;
|
|
326
|
+
effectFn.active = true;
|
|
327
|
+
onTrack && onTrack();
|
|
255
328
|
effectFn();
|
|
256
329
|
return () => {
|
|
257
|
-
|
|
330
|
+
effectFn.active = false;
|
|
258
331
|
activeEffect = null;
|
|
259
332
|
};
|
|
260
333
|
}
|
|
261
334
|
function signalObject(initialValues, exclude) {
|
|
335
|
+
if (!initialValues || !isObject2(initialValues)) {
|
|
336
|
+
{
|
|
337
|
+
warn("initialValues must be an object,will return initial value!", initialValues);
|
|
338
|
+
}
|
|
339
|
+
return initialValues;
|
|
340
|
+
}
|
|
262
341
|
const signals = Object.entries(initialValues).reduce((acc, [key, value]) => {
|
|
263
342
|
acc[key] = isExclude(key, exclude) || isSignal(value) ? value : useSignal(value);
|
|
264
343
|
return acc;
|
|
@@ -273,7 +352,7 @@ function unSignal(signal, exclude) {
|
|
|
273
352
|
if (isArray2(signal)) {
|
|
274
353
|
return signal.map((value) => unSignal(value, exclude));
|
|
275
354
|
}
|
|
276
|
-
if (
|
|
355
|
+
if (isPlainObject(signal)) {
|
|
277
356
|
return Object.entries(signal).reduce((acc, [key, value]) => {
|
|
278
357
|
if (isExclude(key, exclude)) {
|
|
279
358
|
acc[key] = value;
|
|
@@ -285,33 +364,14 @@ function unSignal(signal, exclude) {
|
|
|
285
364
|
}
|
|
286
365
|
return signal;
|
|
287
366
|
}
|
|
288
|
-
var REACTIVE_MARKER = Symbol("useReactive");
|
|
289
367
|
function isReactive(obj) {
|
|
290
|
-
return obj && obj
|
|
291
|
-
}
|
|
292
|
-
function createArrayProxy(initialValue) {
|
|
293
|
-
arrayMethods.forEach((method) => {
|
|
294
|
-
const originalMethod = Array.prototype[method];
|
|
295
|
-
track(initialValue, "length");
|
|
296
|
-
Object.defineProperty(initialValue, method, {
|
|
297
|
-
value(...args) {
|
|
298
|
-
const result = originalMethod.apply(this, args);
|
|
299
|
-
if (["push", "pop", "shift", "unshift", "splice", "sort", "reverse"].includes(method)) {
|
|
300
|
-
trigger(initialValue, "length");
|
|
301
|
-
}
|
|
302
|
-
return result;
|
|
303
|
-
},
|
|
304
|
-
enumerable: false,
|
|
305
|
-
writable: true,
|
|
306
|
-
configurable: true
|
|
307
|
-
});
|
|
308
|
-
});
|
|
368
|
+
return !!(obj && typeof obj === "object" && obj[ReactiveSymbol]);
|
|
309
369
|
}
|
|
310
370
|
function useReactive(initialValue, exclude) {
|
|
311
|
-
return reactive(initialValue,
|
|
371
|
+
return reactive(initialValue, false, exclude);
|
|
312
372
|
}
|
|
313
373
|
function shallowReactive(initialValue, exclude) {
|
|
314
|
-
return reactive(initialValue,
|
|
374
|
+
return reactive(initialValue, true, exclude);
|
|
315
375
|
}
|
|
316
376
|
function unReactive(target) {
|
|
317
377
|
if (!isObject2(target)) {
|
|
@@ -320,40 +380,13 @@ function unReactive(target) {
|
|
|
320
380
|
if (!isReactive(target)) {
|
|
321
381
|
return target;
|
|
322
382
|
}
|
|
323
|
-
|
|
324
|
-
for (const key in target) {
|
|
325
|
-
if (hasOwn(target, key)) {
|
|
326
|
-
const value = target[key];
|
|
327
|
-
if (isReactive(value)) {
|
|
328
|
-
unReactiveObj[key] = unReactive(value);
|
|
329
|
-
} else if (isSignal(value)) {
|
|
330
|
-
unReactiveObj[key] = value.peek();
|
|
331
|
-
} else {
|
|
332
|
-
unReactiveObj[key] = value;
|
|
333
|
-
}
|
|
334
|
-
}
|
|
335
|
-
}
|
|
336
|
-
return unReactiveObj;
|
|
383
|
+
return target[ReactivePeekSymbol];
|
|
337
384
|
}
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
return initialValue;
|
|
341
|
-
}
|
|
342
|
-
if (isReactive(initialValue)) {
|
|
343
|
-
return initialValue;
|
|
344
|
-
}
|
|
345
|
-
if (reactiveMap.has(initialValue)) {
|
|
346
|
-
return reactiveMap.get(initialValue);
|
|
347
|
-
}
|
|
348
|
-
if (Array.isArray(initialValue)) {
|
|
349
|
-
createArrayProxy(initialValue);
|
|
350
|
-
}
|
|
351
|
-
if (isSet(initialValue) || isMap(initialValue) || isWeakSet(initialValue) || isWeakMap(initialValue)) {
|
|
352
|
-
return initialValue;
|
|
353
|
-
}
|
|
354
|
-
const handler = {
|
|
385
|
+
var basicHandler = (shallow, exclude) => {
|
|
386
|
+
return {
|
|
355
387
|
get(target, key, receiver) {
|
|
356
|
-
if (key ===
|
|
388
|
+
if (key === ReactiveSymbol) return true;
|
|
389
|
+
if (key === ReactivePeekSymbol) return target;
|
|
357
390
|
const getValue = Reflect.get(target, key, receiver);
|
|
358
391
|
const value = isSignal(getValue) ? getValue.value : getValue;
|
|
359
392
|
if (isExclude(key, exclude)) {
|
|
@@ -383,6 +416,7 @@ function reactive(initialValue, exclude, shallow = false) {
|
|
|
383
416
|
}
|
|
384
417
|
return obj;
|
|
385
418
|
},
|
|
419
|
+
// handle delete
|
|
386
420
|
deleteProperty(target, key) {
|
|
387
421
|
const oldValue = Reflect.get(target, key);
|
|
388
422
|
const result = Reflect.deleteProperty(target, key);
|
|
@@ -392,48 +426,386 @@ function reactive(initialValue, exclude, shallow = false) {
|
|
|
392
426
|
return result;
|
|
393
427
|
}
|
|
394
428
|
};
|
|
429
|
+
};
|
|
430
|
+
var arrayInstrumentations = createArrayInstrumentations();
|
|
431
|
+
function createArrayInstrumentations() {
|
|
432
|
+
const instrumentations2 = {};
|
|
433
|
+
["includes", "indexOf", "lastIndexOf"].forEach((key) => {
|
|
434
|
+
instrumentations2[key] = function(...args) {
|
|
435
|
+
const arr = this;
|
|
436
|
+
for (let i = 0, l = this.length; i < l; i++) {
|
|
437
|
+
track(arr, `${i}`);
|
|
438
|
+
}
|
|
439
|
+
const res = arr[key](...args);
|
|
440
|
+
if (res === -1 || res === false) {
|
|
441
|
+
return arr[key](...args);
|
|
442
|
+
}
|
|
443
|
+
return res;
|
|
444
|
+
};
|
|
445
|
+
});
|
|
446
|
+
["push", "pop", "shift", "unshift", "splice", "sort", "reverse", "fill", "copyWithin"].forEach(
|
|
447
|
+
(key) => {
|
|
448
|
+
instrumentations2[key] = function(...args) {
|
|
449
|
+
const arr = unReactive(this);
|
|
450
|
+
const res = arr[key].apply(this, args);
|
|
451
|
+
trigger(arr, reactiveArrayKey);
|
|
452
|
+
return res;
|
|
453
|
+
};
|
|
454
|
+
}
|
|
455
|
+
);
|
|
456
|
+
[
|
|
457
|
+
"forEach",
|
|
458
|
+
"map",
|
|
459
|
+
"filter",
|
|
460
|
+
"reduce",
|
|
461
|
+
"reduceRight",
|
|
462
|
+
"some",
|
|
463
|
+
"every",
|
|
464
|
+
"find",
|
|
465
|
+
"findIndex",
|
|
466
|
+
"findLast",
|
|
467
|
+
"findLastIndex",
|
|
468
|
+
"entries",
|
|
469
|
+
"keys",
|
|
470
|
+
"values"
|
|
471
|
+
].forEach((key) => {
|
|
472
|
+
instrumentations2[key] = function(...args) {
|
|
473
|
+
const arr = unReactive(this);
|
|
474
|
+
track(arr, reactiveArrayKey);
|
|
475
|
+
return arr[key].apply(this, args);
|
|
476
|
+
};
|
|
477
|
+
});
|
|
478
|
+
return instrumentations2;
|
|
479
|
+
}
|
|
480
|
+
var ArrayHandler = (shallow, exclude) => {
|
|
481
|
+
return {
|
|
482
|
+
get(target, key, receiver) {
|
|
483
|
+
if (key === ReactiveSymbol) return true;
|
|
484
|
+
if (key === ReactivePeekSymbol) return target;
|
|
485
|
+
if (arrayInstrumentations.hasOwnProperty(key)) {
|
|
486
|
+
return Reflect.get(arrayInstrumentations, key, receiver);
|
|
487
|
+
}
|
|
488
|
+
const value = Reflect.get(target, key, receiver);
|
|
489
|
+
if (isExclude(key, exclude)) {
|
|
490
|
+
return value;
|
|
491
|
+
}
|
|
492
|
+
if (isStringNumber(key)) {
|
|
493
|
+
track(target, key);
|
|
494
|
+
}
|
|
495
|
+
track(target, "length");
|
|
496
|
+
if (isObject2(value) && !shallow) {
|
|
497
|
+
return reactive(value);
|
|
498
|
+
}
|
|
499
|
+
return value;
|
|
500
|
+
},
|
|
501
|
+
set(target, key, value, receiver) {
|
|
502
|
+
const oldValue = Reflect.get(target, key, receiver);
|
|
503
|
+
const result = Reflect.set(target, key, value, receiver);
|
|
504
|
+
if (hasChanged(value, oldValue)) {
|
|
505
|
+
if (isStringNumber(key)) {
|
|
506
|
+
trigger(target, key);
|
|
507
|
+
}
|
|
508
|
+
if (key === "length") {
|
|
509
|
+
trigger(target, "length");
|
|
510
|
+
}
|
|
511
|
+
}
|
|
512
|
+
return result;
|
|
513
|
+
}
|
|
514
|
+
};
|
|
515
|
+
};
|
|
516
|
+
var collectionHandlers = {
|
|
517
|
+
get(target, key) {
|
|
518
|
+
if (key === ReactiveSymbol) return true;
|
|
519
|
+
if (key === ReactivePeekSymbol) return target;
|
|
520
|
+
if (key === Symbol.iterator || key === "size") {
|
|
521
|
+
track(target, ReactiveCollectionKey);
|
|
522
|
+
}
|
|
523
|
+
return Reflect.get(
|
|
524
|
+
hasOwn(instrumentations, key) && key in target ? instrumentations : target,
|
|
525
|
+
key,
|
|
526
|
+
target
|
|
527
|
+
);
|
|
528
|
+
}
|
|
529
|
+
};
|
|
530
|
+
var weakCollectionHandlers = {
|
|
531
|
+
get(target, key) {
|
|
532
|
+
if (key === ReactiveSymbol) return true;
|
|
533
|
+
if (key === ReactivePeekSymbol) return target;
|
|
534
|
+
return Reflect.get(
|
|
535
|
+
hasOwn(weakInstrumentations, key) && key in target ? weakInstrumentations : target,
|
|
536
|
+
key,
|
|
537
|
+
target
|
|
538
|
+
);
|
|
539
|
+
}
|
|
540
|
+
};
|
|
541
|
+
var instrumentations = {
|
|
542
|
+
get(key) {
|
|
543
|
+
const target = unReactive(this);
|
|
544
|
+
track(target, ReactiveCollectionKey);
|
|
545
|
+
return target.get(key);
|
|
546
|
+
},
|
|
547
|
+
set(key, value) {
|
|
548
|
+
const target = unReactive(this);
|
|
549
|
+
const result = target.set(key, value);
|
|
550
|
+
trigger(target, ReactiveCollectionKey);
|
|
551
|
+
return result;
|
|
552
|
+
},
|
|
553
|
+
add(value) {
|
|
554
|
+
const target = unReactive(this);
|
|
555
|
+
const result = target.add(value);
|
|
556
|
+
trigger(target, ReactiveCollectionKey);
|
|
557
|
+
return result;
|
|
558
|
+
},
|
|
559
|
+
has(key) {
|
|
560
|
+
const target = unReactive(this);
|
|
561
|
+
track(target, ReactiveCollectionKey);
|
|
562
|
+
return target.has(key);
|
|
563
|
+
},
|
|
564
|
+
delete(key) {
|
|
565
|
+
const target = unReactive(this);
|
|
566
|
+
const hadKey = target.has(key);
|
|
567
|
+
const result = target.delete(key);
|
|
568
|
+
if (hadKey) {
|
|
569
|
+
trigger(target, ReactiveCollectionKey);
|
|
570
|
+
}
|
|
571
|
+
return result;
|
|
572
|
+
},
|
|
573
|
+
clear() {
|
|
574
|
+
const target = unReactive(this);
|
|
575
|
+
const hadItems = target.size > 0;
|
|
576
|
+
const result = target.clear();
|
|
577
|
+
if (hadItems) {
|
|
578
|
+
trigger(target, ReactiveCollectionKey);
|
|
579
|
+
}
|
|
580
|
+
return result;
|
|
581
|
+
},
|
|
582
|
+
forEach(callback, thisArg) {
|
|
583
|
+
const target = unReactive(this);
|
|
584
|
+
track(target, ReactiveCollectionKey);
|
|
585
|
+
target.forEach((value, key) => {
|
|
586
|
+
callback.call(thisArg, value, key, target);
|
|
587
|
+
});
|
|
588
|
+
},
|
|
589
|
+
get size() {
|
|
590
|
+
const target = unReactive(this);
|
|
591
|
+
track(target, ReactiveCollectionKey);
|
|
592
|
+
return target.size;
|
|
593
|
+
},
|
|
594
|
+
keys() {
|
|
595
|
+
const target = unReactive(this);
|
|
596
|
+
track(target, ReactiveCollectionKey);
|
|
597
|
+
return target.keys();
|
|
598
|
+
},
|
|
599
|
+
values() {
|
|
600
|
+
const target = unReactive(this);
|
|
601
|
+
track(target, ReactiveCollectionKey);
|
|
602
|
+
return target.values();
|
|
603
|
+
},
|
|
604
|
+
entries() {
|
|
605
|
+
const target = unReactive(this);
|
|
606
|
+
track(target, ReactiveCollectionKey);
|
|
607
|
+
return target.entries();
|
|
608
|
+
},
|
|
609
|
+
[Symbol.iterator]() {
|
|
610
|
+
const target = unReactive(this);
|
|
611
|
+
track(target, ReactiveCollectionKey);
|
|
612
|
+
return target[Symbol.iterator]();
|
|
613
|
+
}
|
|
614
|
+
};
|
|
615
|
+
var weakInstrumentations = {
|
|
616
|
+
get(key) {
|
|
617
|
+
const target = unReactive(this);
|
|
618
|
+
track(target, ReactiveWeakCollectionKey);
|
|
619
|
+
return target.get(key);
|
|
620
|
+
},
|
|
621
|
+
set(key, value) {
|
|
622
|
+
const target = unReactive(this);
|
|
623
|
+
const result = target.set(key, value);
|
|
624
|
+
trigger(target, ReactiveWeakCollectionKey);
|
|
625
|
+
return result;
|
|
626
|
+
},
|
|
627
|
+
add(value) {
|
|
628
|
+
const target = unReactive(this);
|
|
629
|
+
const result = target.add(value);
|
|
630
|
+
trigger(target, ReactiveWeakCollectionKey);
|
|
631
|
+
return result;
|
|
632
|
+
},
|
|
633
|
+
has(key) {
|
|
634
|
+
const target = unReactive(this);
|
|
635
|
+
track(target, ReactiveWeakCollectionKey);
|
|
636
|
+
return target.has(key);
|
|
637
|
+
},
|
|
638
|
+
delete(key) {
|
|
639
|
+
const target = unReactive(this);
|
|
640
|
+
const result = target.delete(key);
|
|
641
|
+
trigger(target, ReactiveWeakCollectionKey);
|
|
642
|
+
return result;
|
|
643
|
+
}
|
|
644
|
+
};
|
|
645
|
+
function reactive(initialValue, shallow = false, exclude) {
|
|
646
|
+
if (!isObject2(initialValue)) {
|
|
647
|
+
return initialValue;
|
|
648
|
+
}
|
|
649
|
+
if (isReactive(initialValue)) {
|
|
650
|
+
return initialValue;
|
|
651
|
+
}
|
|
652
|
+
if (reactiveMap.has(initialValue)) {
|
|
653
|
+
return reactiveMap.get(initialValue);
|
|
654
|
+
}
|
|
655
|
+
let handler;
|
|
656
|
+
if (isArray2(initialValue)) {
|
|
657
|
+
track(initialValue, reactiveArrayKey);
|
|
658
|
+
handler = ArrayHandler(shallow, exclude);
|
|
659
|
+
} else if (isSet(initialValue) || isMap(initialValue)) {
|
|
660
|
+
track(initialValue, ReactiveCollectionKey);
|
|
661
|
+
handler = collectionHandlers;
|
|
662
|
+
} else if (isWeakSet(initialValue) || isWeakMap(initialValue)) {
|
|
663
|
+
track(initialValue, ReactiveWeakCollectionKey);
|
|
664
|
+
handler = weakCollectionHandlers;
|
|
665
|
+
} else {
|
|
666
|
+
handler = basicHandler(shallow, exclude);
|
|
667
|
+
}
|
|
395
668
|
const proxy = new Proxy(initialValue, handler);
|
|
396
669
|
reactiveMap.set(initialValue, proxy);
|
|
397
670
|
return proxy;
|
|
398
671
|
}
|
|
672
|
+
function clearReactive(reactiveObj) {
|
|
673
|
+
if (!isReactive(reactiveObj)) {
|
|
674
|
+
{
|
|
675
|
+
warn("clearReactive: argument must be a reactive object");
|
|
676
|
+
}
|
|
677
|
+
return;
|
|
678
|
+
}
|
|
679
|
+
if (isWeakMap(reactiveObj) || isWeakSet(reactiveObj)) {
|
|
680
|
+
{
|
|
681
|
+
warn("clearReactive: WeakMap and WeakSet are not clearable");
|
|
682
|
+
}
|
|
683
|
+
return;
|
|
684
|
+
}
|
|
685
|
+
useBatch(() => {
|
|
686
|
+
if (isArray2(reactiveObj)) {
|
|
687
|
+
reactiveObj.length = 0;
|
|
688
|
+
} else if (isSet(reactiveObj) || isMap(reactiveObj)) {
|
|
689
|
+
reactiveObj.clear();
|
|
690
|
+
} else if (isObject2(reactiveObj)) {
|
|
691
|
+
Object.keys(reactiveObj).forEach((key) => {
|
|
692
|
+
delete reactiveObj[key];
|
|
693
|
+
});
|
|
694
|
+
}
|
|
695
|
+
});
|
|
696
|
+
}
|
|
697
|
+
function useBatch(fn) {
|
|
698
|
+
try {
|
|
699
|
+
inBatch = true;
|
|
700
|
+
fn();
|
|
701
|
+
} finally {
|
|
702
|
+
inBatch = false;
|
|
703
|
+
runBatch();
|
|
704
|
+
}
|
|
705
|
+
}
|
|
706
|
+
function runBatch() {
|
|
707
|
+
if (batchQueue.size > 0) {
|
|
708
|
+
batchQueue.forEach((effect) => effect());
|
|
709
|
+
batchQueue.clear();
|
|
710
|
+
}
|
|
711
|
+
}
|
|
399
712
|
function useWatch(source, cb, options) {
|
|
400
713
|
return doWatch(source, cb, options);
|
|
401
714
|
}
|
|
402
|
-
|
|
715
|
+
var INITIAL_WATCHER_VALUE = void 0;
|
|
716
|
+
var watcher;
|
|
717
|
+
var flushing = false;
|
|
718
|
+
function queueWatcher(fn) {
|
|
719
|
+
watcher = fn;
|
|
720
|
+
if (!flushing) {
|
|
721
|
+
flushing = true;
|
|
722
|
+
nextTick(flushWatchers);
|
|
723
|
+
}
|
|
724
|
+
}
|
|
725
|
+
function flushWatchers() {
|
|
726
|
+
watcher == null ? void 0 : watcher();
|
|
727
|
+
watcher = null;
|
|
728
|
+
flushing = false;
|
|
729
|
+
}
|
|
730
|
+
function doWatch(source, cb, { deep, immediate } = {}) {
|
|
403
731
|
let getter;
|
|
732
|
+
const isMultiSource = isArray2(source);
|
|
404
733
|
if (isSignal(source) || isComputed(source)) {
|
|
405
734
|
getter = () => source.value;
|
|
406
735
|
} else if (isReactive(source)) {
|
|
407
736
|
getter = () => __spreadValues({}, source);
|
|
408
|
-
} else if (
|
|
409
|
-
getter = () => source.map((s) =>
|
|
410
|
-
if (isSignal(s) || isComputed(s)) return s.value;
|
|
411
|
-
if (isReactive(s)) return __spreadValues({}, s);
|
|
412
|
-
if (isFunction2(s)) return s();
|
|
413
|
-
return warn("Invalid source", s);
|
|
414
|
-
});
|
|
737
|
+
} else if (isMultiSource) {
|
|
738
|
+
getter = () => source.map((s) => resolveSource(s));
|
|
415
739
|
} else if (isFunction2(source)) {
|
|
416
740
|
getter = source;
|
|
417
741
|
} else {
|
|
418
742
|
warn("Invalid source type", source);
|
|
419
|
-
|
|
743
|
+
return noop2;
|
|
420
744
|
}
|
|
421
|
-
|
|
745
|
+
if (cb && deep) {
|
|
746
|
+
const baseGetter = getter;
|
|
747
|
+
const depth = deep === true ? Infinity : deep;
|
|
748
|
+
getter = () => traverse(baseGetter(), depth);
|
|
749
|
+
}
|
|
750
|
+
let oldValue = isMultiSource ? Array.from({ length: source.length }).fill(INITIAL_WATCHER_VALUE) : INITIAL_WATCHER_VALUE;
|
|
751
|
+
let runCb = false;
|
|
422
752
|
const effectFn = () => {
|
|
423
753
|
const newValue = getter();
|
|
424
|
-
if (
|
|
425
|
-
|
|
426
|
-
|
|
754
|
+
if (hasChanged(newValue, oldValue)) {
|
|
755
|
+
if (immediate && cb) {
|
|
756
|
+
cb(newValue, oldValue);
|
|
757
|
+
oldValue = newValue;
|
|
758
|
+
}
|
|
759
|
+
if (runCb && cb) {
|
|
760
|
+
queueWatcher(() => {
|
|
761
|
+
cb(newValue, oldValue);
|
|
762
|
+
oldValue = newValue;
|
|
763
|
+
});
|
|
764
|
+
}
|
|
765
|
+
!runCb && (oldValue = newValue);
|
|
427
766
|
}
|
|
428
767
|
};
|
|
429
|
-
const stop = useEffect(effectFn);
|
|
430
|
-
|
|
768
|
+
const stop = useEffect(effectFn, { flush: "sync" });
|
|
769
|
+
runCb = true;
|
|
770
|
+
if (immediate) {
|
|
431
771
|
effectFn();
|
|
432
772
|
}
|
|
433
773
|
return stop;
|
|
434
774
|
}
|
|
435
|
-
|
|
436
|
-
|
|
775
|
+
function resolveSource(s) {
|
|
776
|
+
if (isSignal(s) || isComputed(s)) return s.value;
|
|
777
|
+
if (isReactive(s)) return __spreadValues({}, s);
|
|
778
|
+
if (isFunction2(s)) return s();
|
|
779
|
+
warn("Invalid source", s);
|
|
780
|
+
return noop2;
|
|
781
|
+
}
|
|
782
|
+
function traverse(value, depth = Infinity, seen) {
|
|
783
|
+
if (depth <= 0 || !isObject2(value)) {
|
|
784
|
+
return value;
|
|
785
|
+
}
|
|
786
|
+
seen = seen || /* @__PURE__ */ new Set();
|
|
787
|
+
if (seen.has(value)) {
|
|
788
|
+
return value;
|
|
789
|
+
}
|
|
790
|
+
seen.add(value);
|
|
791
|
+
depth--;
|
|
792
|
+
if (isSignal(value)) {
|
|
793
|
+
traverse(value.value, depth, seen);
|
|
794
|
+
} else if (isArray2(value)) {
|
|
795
|
+
for (const element of value) {
|
|
796
|
+
traverse(element, depth, seen);
|
|
797
|
+
}
|
|
798
|
+
} else if (isSet(value) || isMap(value)) {
|
|
799
|
+
value.forEach((v) => {
|
|
800
|
+
traverse(v, depth, seen);
|
|
801
|
+
});
|
|
802
|
+
} else if (isPlainObject(value)) {
|
|
803
|
+
for (const key in value) {
|
|
804
|
+
traverse(value[key], depth, seen);
|
|
805
|
+
}
|
|
806
|
+
}
|
|
807
|
+
return value;
|
|
808
|
+
}
|
|
437
809
|
function createOptionsStore(options) {
|
|
438
810
|
const { state, getters, actions } = options;
|
|
439
811
|
const initState = __spreadValues({}, state != null ? state : {});
|
|
@@ -468,8 +840,12 @@ function createOptionsStore(options) {
|
|
|
468
840
|
for (const key in getters) {
|
|
469
841
|
const getter = getters[key];
|
|
470
842
|
if (getter) {
|
|
471
|
-
|
|
472
|
-
|
|
843
|
+
Object.defineProperty(store, key, {
|
|
844
|
+
get() {
|
|
845
|
+
return useComputed(getter.bind(reactiveState, reactiveState)).value;
|
|
846
|
+
},
|
|
847
|
+
enumerable: true,
|
|
848
|
+
configurable: true
|
|
473
849
|
});
|
|
474
850
|
}
|
|
475
851
|
}
|
|
@@ -479,42 +855,79 @@ function createOptionsStore(options) {
|
|
|
479
855
|
store[key] = action.bind(reactiveState);
|
|
480
856
|
}
|
|
481
857
|
}
|
|
482
|
-
StoreMap.set(_id, store);
|
|
483
|
-
++_id;
|
|
484
858
|
return store;
|
|
485
859
|
}
|
|
486
860
|
function createStore(options) {
|
|
487
861
|
return function() {
|
|
488
|
-
if (StoreMap.has(_id)) {
|
|
489
|
-
return StoreMap.get(_id);
|
|
490
|
-
}
|
|
491
862
|
return createOptionsStore(options);
|
|
492
863
|
};
|
|
493
864
|
}
|
|
494
865
|
|
|
495
866
|
// ../template/dist/template.dev.esm.js
|
|
496
|
-
var
|
|
497
|
-
|
|
867
|
+
var __defProp2 = Object.defineProperty;
|
|
868
|
+
var __getOwnPropSymbols2 = Object.getOwnPropertySymbols;
|
|
869
|
+
var __hasOwnProp2 = Object.prototype.hasOwnProperty;
|
|
870
|
+
var __propIsEnum2 = Object.prototype.propertyIsEnumerable;
|
|
871
|
+
var __defNormalProp2 = (obj, key, value) => key in obj ? __defProp2(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
872
|
+
var __spreadValues2 = (a, b) => {
|
|
873
|
+
for (var prop in b || (b = {}))
|
|
874
|
+
if (__hasOwnProp2.call(b, prop))
|
|
875
|
+
__defNormalProp2(a, prop, b[prop]);
|
|
876
|
+
if (__getOwnPropSymbols2)
|
|
877
|
+
for (var prop of __getOwnPropSymbols2(b)) {
|
|
878
|
+
if (__propIsEnum2.call(b, prop))
|
|
879
|
+
__defNormalProp2(a, prop, b[prop]);
|
|
880
|
+
}
|
|
881
|
+
return a;
|
|
882
|
+
};
|
|
883
|
+
var _Hooks = class _Hooks2 {
|
|
884
|
+
constructor() {
|
|
885
|
+
this.hooks = {
|
|
886
|
+
mounted: /* @__PURE__ */ new Set(),
|
|
887
|
+
destroy: /* @__PURE__ */ new Set()
|
|
888
|
+
};
|
|
889
|
+
}
|
|
890
|
+
addEventListener() {
|
|
891
|
+
}
|
|
892
|
+
removeEventListener() {
|
|
893
|
+
}
|
|
894
|
+
addHook(hook, cb) {
|
|
895
|
+
var _a;
|
|
896
|
+
(_a = this.hooks[hook]) == null ? void 0 : _a.add(cb);
|
|
897
|
+
}
|
|
898
|
+
getContext(context) {
|
|
899
|
+
return _Hooks2.context[context];
|
|
900
|
+
}
|
|
901
|
+
setContext(context, value) {
|
|
902
|
+
_Hooks2.context[context] = value;
|
|
903
|
+
}
|
|
904
|
+
initRef() {
|
|
905
|
+
_Hooks2.ref = this;
|
|
906
|
+
}
|
|
907
|
+
removeRef() {
|
|
908
|
+
_Hooks2.ref = null;
|
|
909
|
+
}
|
|
910
|
+
};
|
|
911
|
+
_Hooks.ref = null;
|
|
912
|
+
_Hooks.context = {};
|
|
913
|
+
var Hooks = _Hooks;
|
|
914
|
+
var ComponentNode = class extends Hooks {
|
|
915
|
+
constructor(template2, props, key) {
|
|
916
|
+
super();
|
|
498
917
|
this.template = template2;
|
|
499
918
|
this.props = props;
|
|
919
|
+
this.key = key;
|
|
500
920
|
this.proxyProps = {};
|
|
501
|
-
this.context = {};
|
|
502
921
|
this.emitter = /* @__PURE__ */ new Set();
|
|
503
922
|
this.mounted = false;
|
|
504
923
|
this.rootNode = null;
|
|
505
|
-
this.
|
|
506
|
-
mounted: /* @__PURE__ */ new Set(),
|
|
507
|
-
destroy: /* @__PURE__ */ new Set()
|
|
508
|
-
};
|
|
924
|
+
this.context = {};
|
|
509
925
|
this.trackMap = /* @__PURE__ */ new Map();
|
|
510
926
|
this.proxyProps = signalObject(
|
|
511
927
|
props,
|
|
512
|
-
(
|
|
928
|
+
(key2) => startsWith(key2, "on") || startsWith(key2, "update")
|
|
513
929
|
);
|
|
514
|
-
|
|
515
|
-
addEventListener() {
|
|
516
|
-
}
|
|
517
|
-
removeEventListener() {
|
|
930
|
+
this.key = this.key || props.key;
|
|
518
931
|
}
|
|
519
932
|
get firstChild() {
|
|
520
933
|
var _a, _b;
|
|
@@ -524,16 +937,6 @@ var _ComponentNode = class _ComponentNode2 {
|
|
|
524
937
|
var _a, _b;
|
|
525
938
|
return (_b = (_a = this.rootNode) == null ? void 0 : _a.isConnected) != null ? _b : false;
|
|
526
939
|
}
|
|
527
|
-
addHook(hook, cb) {
|
|
528
|
-
var _a;
|
|
529
|
-
(_a = this.hooks[hook]) == null ? void 0 : _a.add(cb);
|
|
530
|
-
}
|
|
531
|
-
getContext(context) {
|
|
532
|
-
return _ComponentNode2.context[context];
|
|
533
|
-
}
|
|
534
|
-
setContext(context, value) {
|
|
535
|
-
_ComponentNode2.context[context] = value;
|
|
536
|
-
}
|
|
537
940
|
inheritNode(node) {
|
|
538
941
|
this.context = node.context;
|
|
539
942
|
this.hooks = node.hooks;
|
|
@@ -552,9 +955,9 @@ var _ComponentNode = class _ComponentNode2 {
|
|
|
552
955
|
if (this.isConnected) {
|
|
553
956
|
return (_b = (_a = this.rootNode) == null ? void 0 : _a.mount(parent, before)) != null ? _b : [];
|
|
554
957
|
}
|
|
555
|
-
|
|
958
|
+
this.initRef();
|
|
556
959
|
this.rootNode = this.template(useReactive(this.proxyProps, ["children"]));
|
|
557
|
-
|
|
960
|
+
this.removeRef();
|
|
558
961
|
this.mounted = true;
|
|
559
962
|
const mountedNode = (_d = (_c = this.rootNode) == null ? void 0 : _c.mount(parent, before)) != null ? _d : [];
|
|
560
963
|
this.hooks.mounted.forEach((handler) => handler());
|
|
@@ -584,7 +987,7 @@ var _ComponentNode = class _ComponentNode2 {
|
|
|
584
987
|
return track2;
|
|
585
988
|
}
|
|
586
989
|
patchProps(props) {
|
|
587
|
-
var _a, _b, _c, _d
|
|
990
|
+
var _a, _b, _c, _d;
|
|
588
991
|
for (const [key, prop] of Object.entries(props)) {
|
|
589
992
|
if (startsWith(key, "on") && ((_a = this.rootNode) == null ? void 0 : _a.nodes)) {
|
|
590
993
|
const event = key.slice(2).toLowerCase();
|
|
@@ -592,15 +995,11 @@ var _ComponentNode = class _ComponentNode2 {
|
|
|
592
995
|
const cleanup = addEventListener(this.rootNode.nodes[0], event, listener);
|
|
593
996
|
this.emitter.add(cleanup);
|
|
594
997
|
} else if (key === "ref") {
|
|
595
|
-
|
|
596
|
-
props[key].value = (_b = this.rootNode) == null ? void 0 : _b.nodes[0];
|
|
597
|
-
} else if (isFunction(prop)) {
|
|
598
|
-
props[key]((_c = this.rootNode) == null ? void 0 : _c.nodes[0]);
|
|
599
|
-
}
|
|
998
|
+
props[key].value = (_b = this.rootNode) == null ? void 0 : _b.nodes[0];
|
|
600
999
|
} else if (startsWith(key, "update")) {
|
|
601
1000
|
props[key] = isSignal(prop) ? prop.value : prop;
|
|
602
1001
|
} else if (key !== "children") {
|
|
603
|
-
const newValue = (
|
|
1002
|
+
const newValue = (_d = (_c = this.proxyProps)[key]) != null ? _d : _c[key] = useSignal(prop);
|
|
604
1003
|
const track2 = this.getNodeTrack(key);
|
|
605
1004
|
track2.cleanup = useEffect(() => {
|
|
606
1005
|
newValue.value = isFunction(prop) ? prop() : prop;
|
|
@@ -610,10 +1009,7 @@ var _ComponentNode = class _ComponentNode2 {
|
|
|
610
1009
|
this.props = props;
|
|
611
1010
|
}
|
|
612
1011
|
};
|
|
613
|
-
|
|
614
|
-
_ComponentNode.context = {};
|
|
615
|
-
var ComponentNode = _ComponentNode;
|
|
616
|
-
function h(_template, props) {
|
|
1012
|
+
function h(_template, props, key) {
|
|
617
1013
|
if (isString(_template)) {
|
|
618
1014
|
if (isHtmlTagName(_template)) {
|
|
619
1015
|
_template = convertToHtmlTag(_template);
|
|
@@ -628,15 +1024,17 @@ function h(_template, props) {
|
|
|
628
1024
|
}
|
|
629
1025
|
_template = template(_template);
|
|
630
1026
|
}
|
|
631
|
-
return isFunction(_template) ? new ComponentNode(_template, props) : new TemplateNode(_template, props);
|
|
1027
|
+
return isFunction(_template) ? new ComponentNode(_template, props, key) : new TemplateNode(_template, props, key);
|
|
1028
|
+
}
|
|
1029
|
+
function isComponent(node) {
|
|
1030
|
+
return node instanceof ComponentNode;
|
|
632
1031
|
}
|
|
633
1032
|
function isJsxElement(node) {
|
|
634
1033
|
return node instanceof ComponentNode || node instanceof TemplateNode;
|
|
635
1034
|
}
|
|
636
1035
|
function template(html) {
|
|
637
|
-
html = closeHtmlTags(html);
|
|
638
1036
|
const template2 = document.createElement("template");
|
|
639
|
-
template2.innerHTML = html;
|
|
1037
|
+
template2.innerHTML = closeHtmlTags(html);
|
|
640
1038
|
return template2;
|
|
641
1039
|
}
|
|
642
1040
|
function Fragment(props) {
|
|
@@ -752,9 +1150,9 @@ function binNode(node, setter) {
|
|
|
752
1150
|
});
|
|
753
1151
|
}
|
|
754
1152
|
}
|
|
755
|
-
var
|
|
756
|
-
function
|
|
757
|
-
return fn ?
|
|
1153
|
+
var p2 = Promise.resolve();
|
|
1154
|
+
function nextTick2(fn) {
|
|
1155
|
+
return fn ? p2.then(fn) : p2;
|
|
758
1156
|
}
|
|
759
1157
|
function addEventListener(node, eventName, handler) {
|
|
760
1158
|
node.addEventListener(eventName, handler);
|
|
@@ -809,15 +1207,6 @@ function convertToHtmlTag(tagName) {
|
|
|
809
1207
|
return `<${tagName}></${tagName}>`;
|
|
810
1208
|
}
|
|
811
1209
|
}
|
|
812
|
-
function generateShortId() {
|
|
813
|
-
const characters = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
|
|
814
|
-
let result = "";
|
|
815
|
-
const charactersLength = characters.length;
|
|
816
|
-
for (let i = 0; i < 8; i++) {
|
|
817
|
-
result += characters.charAt(Math.floor(Math.random() * charactersLength));
|
|
818
|
-
}
|
|
819
|
-
return result;
|
|
820
|
-
}
|
|
821
1210
|
function patchChildren(parent, childrenMap, nextChildren, before) {
|
|
822
1211
|
const result = /* @__PURE__ */ new Map();
|
|
823
1212
|
const children = Array.from(childrenMap.values());
|
|
@@ -930,6 +1319,7 @@ var TemplateNode = class _TemplateNode {
|
|
|
930
1319
|
this.provides = {};
|
|
931
1320
|
this.trackMap = /* @__PURE__ */ new Map();
|
|
932
1321
|
this.parent = null;
|
|
1322
|
+
this.key = this.key || props.key;
|
|
933
1323
|
}
|
|
934
1324
|
get firstChild() {
|
|
935
1325
|
var _a;
|
|
@@ -949,7 +1339,6 @@ var TemplateNode = class _TemplateNode {
|
|
|
949
1339
|
this.nodes.forEach((node) => insertChild(parent, node, before));
|
|
950
1340
|
return this.nodes;
|
|
951
1341
|
}
|
|
952
|
-
this.key = this.key || generateShortId();
|
|
953
1342
|
const cloneNode = this.template.content.cloneNode(true);
|
|
954
1343
|
const firstChild = cloneNode.firstChild;
|
|
955
1344
|
if ((_a = firstChild == null ? void 0 : firstChild.hasAttribute) == null ? void 0 : _a.call(firstChild, "_svg_")) {
|
|
@@ -1053,11 +1442,7 @@ var TemplateNode = class _TemplateNode {
|
|
|
1053
1442
|
});
|
|
1054
1443
|
}
|
|
1055
1444
|
} else if (attr === "ref") {
|
|
1056
|
-
|
|
1057
|
-
props[attr].value = node;
|
|
1058
|
-
} else if (isFunction(props[attr])) {
|
|
1059
|
-
props[attr](node);
|
|
1060
|
-
}
|
|
1445
|
+
props[attr].value = node;
|
|
1061
1446
|
} else if (startsWith(attr, "on")) {
|
|
1062
1447
|
const eventName = attr.slice(2).toLocaleLowerCase();
|
|
1063
1448
|
const track2 = this.getNodeTrack(`${key}:${attr}`);
|
|
@@ -1117,80 +1502,148 @@ function patchChild(track2, parent, child, before) {
|
|
|
1117
1502
|
function onMount(cb) {
|
|
1118
1503
|
var _a;
|
|
1119
1504
|
throwIfOutsideComponent("onMounted");
|
|
1120
|
-
(_a =
|
|
1505
|
+
(_a = Hooks.ref) == null ? void 0 : _a.addHook("mounted", cb);
|
|
1121
1506
|
}
|
|
1122
1507
|
function onDestroy(cb) {
|
|
1123
1508
|
var _a;
|
|
1124
1509
|
throwIfOutsideComponent("onDestroy");
|
|
1125
|
-
(_a =
|
|
1510
|
+
(_a = Hooks.ref) == null ? void 0 : _a.addHook("destroy", cb);
|
|
1126
1511
|
}
|
|
1127
|
-
function throwIfOutsideComponent(hook) {
|
|
1128
|
-
if (!
|
|
1512
|
+
function throwIfOutsideComponent(hook, key) {
|
|
1513
|
+
if (!Hooks.ref) {
|
|
1129
1514
|
console.error(
|
|
1130
|
-
`"${hook}" can only be called within the component function body
|
|
1515
|
+
`"${hook}"(key: ${isSymbol(key) ? key.toString() : key}) can only be called within the component function body
|
|
1131
1516
|
and cannot be used in asynchronous or deferred calls.`
|
|
1132
1517
|
);
|
|
1133
1518
|
}
|
|
1134
1519
|
}
|
|
1135
1520
|
function useProvide(key, value) {
|
|
1136
1521
|
var _a;
|
|
1137
|
-
throwIfOutsideComponent("useProvide");
|
|
1138
|
-
(_a =
|
|
1522
|
+
throwIfOutsideComponent("useProvide", key);
|
|
1523
|
+
(_a = Hooks.ref) == null ? void 0 : _a.setContext(key, value);
|
|
1139
1524
|
}
|
|
1140
1525
|
function useInject(key, defaultValue) {
|
|
1141
1526
|
var _a;
|
|
1142
|
-
throwIfOutsideComponent("useInject");
|
|
1143
|
-
return ((_a =
|
|
1527
|
+
throwIfOutsideComponent("useInject", key);
|
|
1528
|
+
return ((_a = Hooks.ref) == null ? void 0 : _a.getContext(key)) || defaultValue;
|
|
1529
|
+
}
|
|
1530
|
+
function useRef() {
|
|
1531
|
+
const ref = shallowSignal(null);
|
|
1532
|
+
return ref;
|
|
1533
|
+
}
|
|
1534
|
+
function generateAttributes(props) {
|
|
1535
|
+
return Object.entries(props).map(([key, value]) => {
|
|
1536
|
+
if (key === "children" || isFunction(value)) return "";
|
|
1537
|
+
return `${key}="${escape(String(value))}"`;
|
|
1538
|
+
}).filter(Boolean).join(" ");
|
|
1539
|
+
}
|
|
1540
|
+
function normalizeProps(props) {
|
|
1541
|
+
Object.keys(props).forEach((propKey) => {
|
|
1542
|
+
if (isFunction(props[propKey])) {
|
|
1543
|
+
delete props[propKey];
|
|
1544
|
+
}
|
|
1545
|
+
if (isSignal(props[propKey])) {
|
|
1546
|
+
props[propKey] = props[propKey].value;
|
|
1547
|
+
}
|
|
1548
|
+
});
|
|
1144
1549
|
}
|
|
1145
|
-
function
|
|
1146
|
-
|
|
1550
|
+
function handleChildResult(result, prop, key, tmpl, childNodesMap, path) {
|
|
1551
|
+
if (isSignal(result)) {
|
|
1552
|
+
tmpl.template += result.value;
|
|
1553
|
+
} else if (result instanceof ServerNode) {
|
|
1554
|
+
const mapKey = path ? String(path) : `${key}`;
|
|
1555
|
+
if (!childNodesMap[mapKey]) childNodesMap[mapKey] = [];
|
|
1556
|
+
const childResult = result.mount();
|
|
1557
|
+
childNodesMap[mapKey].push(
|
|
1558
|
+
isFunction(childResult) ? childResult(prop) : isSignal(childResult) ? childResult.value : childResult
|
|
1559
|
+
);
|
|
1560
|
+
} else {
|
|
1561
|
+
tmpl.template += isFunction(result) ? result(prop) : String(result);
|
|
1562
|
+
}
|
|
1147
1563
|
}
|
|
1148
|
-
|
|
1149
|
-
|
|
1150
|
-
|
|
1564
|
+
var ServerNode = class _ServerNode extends Hooks {
|
|
1565
|
+
constructor(template2, props = {}, key) {
|
|
1566
|
+
super();
|
|
1567
|
+
this.template = template2;
|
|
1568
|
+
this.props = props;
|
|
1569
|
+
this.key = key;
|
|
1570
|
+
this.childNodesMap = {};
|
|
1571
|
+
this.processedTemplates = {};
|
|
1151
1572
|
}
|
|
1152
|
-
|
|
1153
|
-
|
|
1154
|
-
|
|
1155
|
-
|
|
1156
|
-
|
|
1157
|
-
|
|
1158
|
-
|
|
1159
|
-
|
|
1160
|
-
|
|
1161
|
-
|
|
1162
|
-
|
|
1163
|
-
|
|
1164
|
-
|
|
1165
|
-
|
|
1166
|
-
|
|
1573
|
+
/**
|
|
1574
|
+
* Mount and render the component
|
|
1575
|
+
*/
|
|
1576
|
+
mount() {
|
|
1577
|
+
this.initRef();
|
|
1578
|
+
const output = this.render();
|
|
1579
|
+
this.removeRef();
|
|
1580
|
+
return output;
|
|
1581
|
+
}
|
|
1582
|
+
/**
|
|
1583
|
+
* Initialize template entries and props
|
|
1584
|
+
*/
|
|
1585
|
+
initTemplates() {
|
|
1586
|
+
const templateCollection = Array.isArray(this.template) ? this.template.reduce((acc, tmpl, index) => {
|
|
1587
|
+
acc[index + 1] = { template: tmpl };
|
|
1588
|
+
return acc;
|
|
1589
|
+
}, {}) : this.template;
|
|
1590
|
+
if (isObject(templateCollection)) {
|
|
1591
|
+
Object.entries(templateCollection).forEach(([key, tmpl]) => {
|
|
1592
|
+
const prop = __spreadValues2({}, this.props[key]);
|
|
1593
|
+
normalizeProps(prop);
|
|
1167
1594
|
if (prop.children) {
|
|
1168
|
-
|
|
1169
|
-
|
|
1170
|
-
|
|
1171
|
-
|
|
1172
|
-
|
|
1595
|
+
prop.children.forEach((item) => {
|
|
1596
|
+
const [child, path] = isArray(item) ? item : [item, null];
|
|
1597
|
+
if (isFunction(child)) {
|
|
1598
|
+
const result = child(prop);
|
|
1599
|
+
handleChildResult(result, prop, key, tmpl, this.childNodesMap, path);
|
|
1600
|
+
} else {
|
|
1601
|
+
tmpl.template += isSignal(child) ? child.value : String(child);
|
|
1602
|
+
}
|
|
1603
|
+
});
|
|
1173
1604
|
}
|
|
1174
|
-
|
|
1175
|
-
|
|
1605
|
+
this.processedTemplates[key] = {
|
|
1606
|
+
template: tmpl.template,
|
|
1607
|
+
props: prop
|
|
1608
|
+
};
|
|
1609
|
+
});
|
|
1176
1610
|
}
|
|
1177
1611
|
}
|
|
1178
|
-
|
|
1179
|
-
|
|
1180
|
-
|
|
1181
|
-
|
|
1612
|
+
/**
|
|
1613
|
+
* Render component and its children into a string
|
|
1614
|
+
*/
|
|
1615
|
+
render() {
|
|
1616
|
+
if (isFunction(this.template)) {
|
|
1617
|
+
const root = this.template(this.props);
|
|
1618
|
+
return root instanceof _ServerNode ? root.mount() : String(root);
|
|
1182
1619
|
}
|
|
1183
|
-
if (
|
|
1184
|
-
|
|
1620
|
+
if (this.template instanceof _ServerNode) {
|
|
1621
|
+
return this.template.mount();
|
|
1185
1622
|
}
|
|
1186
|
-
|
|
1187
|
-
|
|
1623
|
+
this.initTemplates();
|
|
1624
|
+
return Object.entries(this.processedTemplates).map(([key, { template: template2, props }]) => {
|
|
1625
|
+
let content = template2;
|
|
1626
|
+
if (props && Object.keys(props).length > 0) {
|
|
1627
|
+
content += ` ${generateAttributes(props)}`;
|
|
1628
|
+
}
|
|
1629
|
+
if (this.childNodesMap[key]) {
|
|
1630
|
+
content = content.replace("<!>", this.renderChildren(this.childNodesMap[key]));
|
|
1631
|
+
}
|
|
1632
|
+
return content;
|
|
1633
|
+
}).join("");
|
|
1634
|
+
}
|
|
1635
|
+
/**
|
|
1636
|
+
* Render child nodes into a string
|
|
1637
|
+
*/
|
|
1638
|
+
renderChildren(children) {
|
|
1639
|
+
return coerceArray(children).map(String).join("");
|
|
1640
|
+
}
|
|
1641
|
+
};
|
|
1642
|
+
function ssg(component, props) {
|
|
1643
|
+
return new ServerNode(component, props);
|
|
1188
1644
|
}
|
|
1189
1645
|
function renderToString(component, props) {
|
|
1190
|
-
return
|
|
1191
|
-
}
|
|
1192
|
-
function renderSSG(component, root, props = {}) {
|
|
1193
|
-
root.innerHTML = renderTemplate(component, props);
|
|
1646
|
+
return ssg(component, props).mount();
|
|
1194
1647
|
}
|
|
1195
1648
|
|
|
1196
1649
|
// src/index.ts
|
|
@@ -1198,17 +1651,17 @@ if (globalThis) {
|
|
|
1198
1651
|
globalThis.__essor_version__ = essor_version;
|
|
1199
1652
|
}
|
|
1200
1653
|
/**
|
|
1201
|
-
* @estjs/shared v0.0.
|
|
1654
|
+
* @estjs/shared v0.0.12
|
|
1202
1655
|
* (c) 2023-Present jiangxd <jiangxd2016@gmail.com>
|
|
1203
1656
|
* @license MIT
|
|
1204
1657
|
**/
|
|
1205
1658
|
/**
|
|
1206
|
-
* @estjs/signal v0.0.
|
|
1659
|
+
* @estjs/signal v0.0.12
|
|
1207
1660
|
* (c) 2023-Present jiangxd <jiangxd2016@gmail.com>
|
|
1208
1661
|
* @license MIT
|
|
1209
1662
|
**/
|
|
1210
1663
|
/**
|
|
1211
|
-
* @estjs/template v0.0.
|
|
1664
|
+
* @estjs/template v0.0.12
|
|
1212
1665
|
* (c) 2023-Present jiangxd <jiangxd2016@gmail.com>
|
|
1213
1666
|
* @license MIT
|
|
1214
1667
|
**/
|
|
@@ -1216,29 +1669,32 @@ if (globalThis) {
|
|
|
1216
1669
|
exports.ComponentNode = ComponentNode;
|
|
1217
1670
|
exports.Fragment = Fragment;
|
|
1218
1671
|
exports.TemplateNode = TemplateNode;
|
|
1672
|
+
exports.clearReactive = clearReactive;
|
|
1219
1673
|
exports.createStore = createStore;
|
|
1220
1674
|
exports.essor_version = essor_version;
|
|
1221
1675
|
exports.h = h;
|
|
1676
|
+
exports.isComponent = isComponent;
|
|
1222
1677
|
exports.isComputed = isComputed;
|
|
1223
1678
|
exports.isJsxElement = isJsxElement;
|
|
1224
1679
|
exports.isReactive = isReactive;
|
|
1225
1680
|
exports.isSignal = isSignal;
|
|
1226
|
-
exports.nextTick =
|
|
1681
|
+
exports.nextTick = nextTick2;
|
|
1227
1682
|
exports.onDestroy = onDestroy;
|
|
1228
1683
|
exports.onMount = onMount;
|
|
1229
|
-
exports.renderSSG = renderSSG;
|
|
1230
|
-
exports.renderTemplate = renderTemplate;
|
|
1231
1684
|
exports.renderToString = renderToString;
|
|
1232
1685
|
exports.shallowReactive = shallowReactive;
|
|
1233
1686
|
exports.shallowSignal = shallowSignal;
|
|
1234
1687
|
exports.signalObject = signalObject;
|
|
1688
|
+
exports.ssg = ssg;
|
|
1235
1689
|
exports.template = template;
|
|
1236
1690
|
exports.unReactive = unReactive;
|
|
1237
1691
|
exports.unSignal = unSignal;
|
|
1692
|
+
exports.useBatch = useBatch;
|
|
1238
1693
|
exports.useComputed = useComputed;
|
|
1239
1694
|
exports.useEffect = useEffect;
|
|
1240
1695
|
exports.useInject = useInject;
|
|
1241
1696
|
exports.useProvide = useProvide;
|
|
1242
1697
|
exports.useReactive = useReactive;
|
|
1698
|
+
exports.useRef = useRef;
|
|
1243
1699
|
exports.useSignal = useSignal;
|
|
1244
1700
|
exports.useWatch = useWatch;
|