essor 0.0.13-beta.7 → 0.0.13
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 +34 -34
- 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 +1173 -663
- package/dist/essor.dev.esm.js +1157 -647
- package/dist/essor.esm.js +6 -6
- package/dist/essor.esm.js.map +1 -1
- package/package.json +4 -4
package/dist/essor.dev.esm.js
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* essor v0.0.13
|
|
2
|
+
* essor v0.0.13
|
|
3
3
|
* (c) 2023-Present jiangxd <jiangxd2016@gmail.com>
|
|
4
4
|
* @license MIT
|
|
5
5
|
**/
|
|
6
6
|
|
|
7
7
|
// src/version.ts
|
|
8
|
-
var essor_version = "0.0.13
|
|
8
|
+
var essor_version = "0.0.13";
|
|
9
9
|
|
|
10
10
|
// ../shared/dist/shared.js
|
|
11
11
|
var isObject = (val) => val !== null && typeof val === "object";
|
|
@@ -31,12 +31,12 @@ function isWeakSet(val) {
|
|
|
31
31
|
function isMap(val) {
|
|
32
32
|
return _toString.call(val) === "[object Map]";
|
|
33
33
|
}
|
|
34
|
-
function isNil(
|
|
35
|
-
return
|
|
34
|
+
function isNil(x) {
|
|
35
|
+
return x === null || x === void 0;
|
|
36
36
|
}
|
|
37
37
|
var isFunction = (val) => typeof val === "function";
|
|
38
|
-
function isFalsy(
|
|
39
|
-
return
|
|
38
|
+
function isFalsy(x) {
|
|
39
|
+
return x === false || x === null || x === void 0;
|
|
40
40
|
}
|
|
41
41
|
var isPrimitive = (val) => ["string", "number", "boolean", "symbol", "undefined"].includes(typeof val) || isNull(val);
|
|
42
42
|
var isPlainObject = (val) => _toString.call(val) === "[object Object]";
|
|
@@ -93,401 +93,855 @@ function warn(msg, ...args) {
|
|
|
93
93
|
console.warn.apply(console, [`[Essor warn]: ${msg}`].concat(args));
|
|
94
94
|
}
|
|
95
95
|
|
|
96
|
-
// ../signal/dist/signal.esm.js
|
|
97
|
-
var
|
|
98
|
-
var
|
|
99
|
-
var
|
|
100
|
-
var
|
|
101
|
-
var
|
|
102
|
-
var
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
96
|
+
// ../signal/dist/signal.dev.esm.js
|
|
97
|
+
var __defProp = Object.defineProperty;
|
|
98
|
+
var __defProps = Object.defineProperties;
|
|
99
|
+
var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
|
|
100
|
+
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
101
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
102
|
+
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
103
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
104
|
+
var __spreadValues = (a, b) => {
|
|
105
|
+
for (var prop in b || (b = {}))
|
|
106
|
+
if (__hasOwnProp.call(b, prop))
|
|
107
|
+
__defNormalProp(a, prop, b[prop]);
|
|
108
|
+
if (__getOwnPropSymbols)
|
|
109
|
+
for (var prop of __getOwnPropSymbols(b)) {
|
|
110
|
+
if (__propIsEnum.call(b, prop))
|
|
111
|
+
__defNormalProp(a, prop, b[prop]);
|
|
112
|
+
}
|
|
113
|
+
return a;
|
|
106
114
|
};
|
|
107
|
-
var
|
|
108
|
-
var
|
|
109
|
-
var
|
|
110
|
-
var
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
115
|
+
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
116
|
+
var queue = [];
|
|
117
|
+
var activePreFlushCbs = [];
|
|
118
|
+
var p = Promise.resolve();
|
|
119
|
+
var isFlushPending = false;
|
|
120
|
+
function nextTick(fn) {
|
|
121
|
+
return fn ? p.then(fn) : p;
|
|
122
|
+
}
|
|
123
|
+
function queueJob(job) {
|
|
124
|
+
if (!queue.includes(job)) {
|
|
125
|
+
queue.push(job);
|
|
126
|
+
queueFlush();
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
function queueFlush() {
|
|
130
|
+
if (isFlushPending) {
|
|
131
|
+
return;
|
|
132
|
+
}
|
|
133
|
+
isFlushPending = true;
|
|
134
|
+
nextTick(flushJobs);
|
|
119
135
|
}
|
|
120
|
-
function
|
|
121
|
-
|
|
136
|
+
function queuePreFlushCb(cb) {
|
|
137
|
+
queueCb(cb, activePreFlushCbs);
|
|
122
138
|
}
|
|
123
|
-
function
|
|
124
|
-
|
|
139
|
+
function queueCb(cb, activeQueue) {
|
|
140
|
+
if (!activeQueue.includes(cb)) {
|
|
141
|
+
activeQueue.push(cb);
|
|
142
|
+
queueFlush();
|
|
143
|
+
}
|
|
125
144
|
}
|
|
126
|
-
function
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
145
|
+
function flushJobs() {
|
|
146
|
+
isFlushPending = false;
|
|
147
|
+
flushPreFlushCbs();
|
|
148
|
+
let job;
|
|
149
|
+
while (job = queue.shift()) {
|
|
150
|
+
if (job) {
|
|
151
|
+
job();
|
|
152
|
+
}
|
|
153
|
+
}
|
|
130
154
|
}
|
|
131
|
-
function
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
155
|
+
function flushPreFlushCbs() {
|
|
156
|
+
while (activePreFlushCbs.length > 0) {
|
|
157
|
+
const cb = activePreFlushCbs.shift();
|
|
158
|
+
if (cb) {
|
|
159
|
+
cb();
|
|
160
|
+
}
|
|
135
161
|
}
|
|
136
162
|
}
|
|
137
|
-
function
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
}
|
|
163
|
+
function createScheduler(effect, flush) {
|
|
164
|
+
if (flush === "sync") {
|
|
165
|
+
return () => effect();
|
|
166
|
+
} else if (flush === "pre") {
|
|
167
|
+
return () => queuePreFlushCb(effect);
|
|
168
|
+
} else {
|
|
169
|
+
return () => {
|
|
170
|
+
nextTick(() => queueJob(effect));
|
|
171
|
+
};
|
|
172
|
+
}
|
|
141
173
|
}
|
|
142
|
-
var
|
|
143
|
-
var
|
|
144
|
-
var
|
|
145
|
-
var
|
|
146
|
-
var
|
|
147
|
-
var
|
|
148
|
-
var
|
|
149
|
-
var
|
|
150
|
-
var
|
|
151
|
-
var
|
|
152
|
-
var
|
|
153
|
-
var
|
|
154
|
-
function
|
|
155
|
-
if (!
|
|
156
|
-
let
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
}
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
174
|
+
var activeEffect = null;
|
|
175
|
+
var triggerMap = /* @__PURE__ */ new WeakMap();
|
|
176
|
+
var reactiveMap = /* @__PURE__ */ new WeakMap();
|
|
177
|
+
var ReactiveSymbol = Symbol("ReactiveSymbol");
|
|
178
|
+
var ReactivePeekSymbol = Symbol("__raw");
|
|
179
|
+
var SignalValueKey = Symbol("SignalValueKey");
|
|
180
|
+
var ComputedValueKey = Symbol("ComputedValueKey");
|
|
181
|
+
var reactiveArrayKey = Symbol("ReactiveArrayKey");
|
|
182
|
+
var ReactiveCollectionKey = Symbol("ReactiveCollectionKey");
|
|
183
|
+
var ReactiveWeakCollectionKey = Symbol("ReactiveWeakCollectionKey");
|
|
184
|
+
var inBatch = false;
|
|
185
|
+
var batchQueue = /* @__PURE__ */ new Set();
|
|
186
|
+
function track(target, key) {
|
|
187
|
+
if (!activeEffect) return;
|
|
188
|
+
let depsMap = triggerMap.get(target);
|
|
189
|
+
if (!depsMap) {
|
|
190
|
+
depsMap = /* @__PURE__ */ new Map();
|
|
191
|
+
triggerMap.set(target, depsMap);
|
|
192
|
+
}
|
|
193
|
+
let dep = depsMap.get(key);
|
|
194
|
+
if (!dep) {
|
|
195
|
+
dep = /* @__PURE__ */ new Set();
|
|
196
|
+
depsMap.set(key, dep);
|
|
197
|
+
}
|
|
198
|
+
dep.add(activeEffect);
|
|
199
|
+
}
|
|
200
|
+
function trigger(target, key) {
|
|
201
|
+
const depsMap = triggerMap.get(target);
|
|
202
|
+
if (!depsMap) return;
|
|
203
|
+
const dep = depsMap.get(key);
|
|
204
|
+
if (dep) {
|
|
205
|
+
dep.forEach((effect) => {
|
|
206
|
+
if (hasOwn(effect, "active") && !effect.active) {
|
|
207
|
+
dep.delete(effect);
|
|
208
|
+
return;
|
|
209
|
+
}
|
|
210
|
+
inBatch ? batchQueue.add(effect) : effect();
|
|
211
|
+
});
|
|
212
|
+
}
|
|
172
213
|
}
|
|
173
|
-
var
|
|
174
|
-
|
|
214
|
+
var Signal = class {
|
|
215
|
+
/**
|
|
216
|
+
* Creates a new Signal instance.
|
|
217
|
+
* @param {T} value - The initial value of the Signal.
|
|
218
|
+
* @param {boolean} [shallow] - Whether to create a shallow Signal.
|
|
219
|
+
*/
|
|
220
|
+
constructor(value, shallow = false) {
|
|
175
221
|
this.__signal = true;
|
|
176
|
-
this.__shallow =
|
|
222
|
+
this.__shallow = shallow;
|
|
223
|
+
this.__value = value;
|
|
177
224
|
}
|
|
225
|
+
/**
|
|
226
|
+
* Gets the current value of the Signal.
|
|
227
|
+
* @returns {T} The current value.
|
|
228
|
+
*/
|
|
178
229
|
get value() {
|
|
179
|
-
|
|
230
|
+
track(this, SignalValueKey);
|
|
231
|
+
if (isObject(this.__value) && !this.__shallow) {
|
|
232
|
+
return reactive(this.__value);
|
|
233
|
+
}
|
|
234
|
+
return this.__value;
|
|
180
235
|
}
|
|
181
|
-
|
|
182
|
-
|
|
236
|
+
/**
|
|
237
|
+
* Sets a new value for the Signal.
|
|
238
|
+
* @param {T} newValue - The new value to set.
|
|
239
|
+
*/
|
|
240
|
+
set value(newValue) {
|
|
241
|
+
if (isSignal(newValue)) {
|
|
242
|
+
newValue = newValue.peek();
|
|
243
|
+
}
|
|
244
|
+
if (hasChanged(newValue, this.__value)) {
|
|
245
|
+
this.__value = newValue;
|
|
246
|
+
trigger(this, SignalValueKey);
|
|
247
|
+
}
|
|
183
248
|
}
|
|
249
|
+
/**
|
|
250
|
+
* Returns the current value without triggering reactivity.
|
|
251
|
+
* @returns {T} The current value.
|
|
252
|
+
*/
|
|
184
253
|
peek() {
|
|
185
254
|
return this.__value;
|
|
186
255
|
}
|
|
187
256
|
};
|
|
188
|
-
function
|
|
189
|
-
|
|
257
|
+
function useSignal(value) {
|
|
258
|
+
if (isSignal(value)) {
|
|
259
|
+
return value;
|
|
260
|
+
}
|
|
261
|
+
return new Signal(value);
|
|
190
262
|
}
|
|
191
|
-
function
|
|
192
|
-
return new
|
|
263
|
+
function useShallowSignal(value) {
|
|
264
|
+
return new Signal(value, true);
|
|
193
265
|
}
|
|
194
|
-
function
|
|
195
|
-
return new
|
|
266
|
+
function shallowSignal(value) {
|
|
267
|
+
return new Signal(value, true);
|
|
196
268
|
}
|
|
197
|
-
function
|
|
198
|
-
return !!(
|
|
269
|
+
function isSignal(value) {
|
|
270
|
+
return !!(value && (value == null ? void 0 : value.__signal));
|
|
199
271
|
}
|
|
200
|
-
var
|
|
201
|
-
constructor(
|
|
202
|
-
this.fn =
|
|
272
|
+
var Computed = class {
|
|
273
|
+
constructor(fn) {
|
|
274
|
+
this.fn = fn;
|
|
203
275
|
this.__computed = true;
|
|
204
|
-
|
|
205
|
-
|
|
276
|
+
const prev = activeEffect;
|
|
277
|
+
activeEffect = this.run.bind(this);
|
|
278
|
+
this.__value = this.fn();
|
|
279
|
+
activeEffect = prev;
|
|
206
280
|
}
|
|
281
|
+
/**
|
|
282
|
+
* Get the current computed value without tracking it.
|
|
283
|
+
*/
|
|
207
284
|
peek() {
|
|
208
285
|
return this.__value;
|
|
209
286
|
}
|
|
287
|
+
/**
|
|
288
|
+
* Run the computed function and update the value if it has changed.
|
|
289
|
+
*/
|
|
210
290
|
run() {
|
|
211
|
-
|
|
212
|
-
hasChanged(
|
|
291
|
+
const newValue = this.fn();
|
|
292
|
+
if (hasChanged(newValue, this.__value)) {
|
|
293
|
+
this.__value = newValue;
|
|
294
|
+
trigger(this, ComputedValueKey);
|
|
295
|
+
}
|
|
213
296
|
}
|
|
297
|
+
/**
|
|
298
|
+
* Get the current computed value and track its usage.
|
|
299
|
+
*/
|
|
214
300
|
get value() {
|
|
215
|
-
|
|
301
|
+
track(this, ComputedValueKey);
|
|
302
|
+
return this.__value;
|
|
216
303
|
}
|
|
217
304
|
};
|
|
218
|
-
function
|
|
219
|
-
return new
|
|
305
|
+
function useComputed(fn) {
|
|
306
|
+
return new Computed(fn);
|
|
307
|
+
}
|
|
308
|
+
function isComputed(value) {
|
|
309
|
+
return !!(value && value.__computed);
|
|
310
|
+
}
|
|
311
|
+
function useEffect(fn, options = {}) {
|
|
312
|
+
const { flush = "pre", onTrack, onTrigger } = options;
|
|
313
|
+
function effectFn() {
|
|
314
|
+
const prev = activeEffect;
|
|
315
|
+
activeEffect = effectFn.init ? effectFn : effectFn.scheduler;
|
|
316
|
+
fn();
|
|
317
|
+
onTrigger && onTrigger();
|
|
318
|
+
activeEffect = prev;
|
|
319
|
+
}
|
|
320
|
+
const scheduler = createScheduler(effectFn, flush);
|
|
321
|
+
effectFn.scheduler = scheduler;
|
|
322
|
+
effectFn.init = true;
|
|
323
|
+
effectFn.active = true;
|
|
324
|
+
onTrack && onTrack();
|
|
325
|
+
effectFn();
|
|
326
|
+
return () => {
|
|
327
|
+
effectFn.active = false;
|
|
328
|
+
activeEffect = null;
|
|
329
|
+
};
|
|
220
330
|
}
|
|
221
|
-
function
|
|
222
|
-
|
|
331
|
+
function signalObject(initialValues, exclude) {
|
|
332
|
+
if (!initialValues || !isObject(initialValues)) {
|
|
333
|
+
{
|
|
334
|
+
warn("initialValues must be an object,will return initial value!", initialValues);
|
|
335
|
+
}
|
|
336
|
+
return initialValues;
|
|
337
|
+
}
|
|
338
|
+
const signals = Object.entries(initialValues).reduce((acc, [key, value]) => {
|
|
339
|
+
acc[key] = isExclude(key, exclude) || isSignal(value) ? value : useSignal(value);
|
|
340
|
+
return acc;
|
|
341
|
+
}, {});
|
|
342
|
+
return signals;
|
|
223
343
|
}
|
|
224
|
-
function
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
T = s.init ? s : s.scheduler, e(), r && r(), T = d;
|
|
344
|
+
function toRaw(value) {
|
|
345
|
+
if (!value) return value;
|
|
346
|
+
if (isReactive(value)) {
|
|
347
|
+
return value[ReactivePeekSymbol];
|
|
229
348
|
}
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
349
|
+
if (isSignal(value)) {
|
|
350
|
+
return value.peek();
|
|
351
|
+
}
|
|
352
|
+
if (isArray(value)) {
|
|
353
|
+
return value.map((value2) => toRaw(value2));
|
|
354
|
+
}
|
|
355
|
+
if (isPlainObject(value)) {
|
|
356
|
+
return Object.fromEntries(
|
|
357
|
+
Object.entries(value).map(([key, value2]) => [key, toRaw(value2)])
|
|
358
|
+
);
|
|
359
|
+
}
|
|
360
|
+
return value;
|
|
361
|
+
}
|
|
362
|
+
function isReactive(obj) {
|
|
363
|
+
return !!(obj && typeof obj === "object" && obj[ReactiveSymbol]);
|
|
364
|
+
}
|
|
365
|
+
function useReactive(initialValue, exclude) {
|
|
366
|
+
return reactive(initialValue, false, exclude);
|
|
367
|
+
}
|
|
368
|
+
function shallowReactive(initialValue, exclude) {
|
|
369
|
+
return reactive(initialValue, true, exclude);
|
|
234
370
|
}
|
|
235
|
-
|
|
236
|
-
return
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
}
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
371
|
+
var basicHandler = (shallow, exclude) => {
|
|
372
|
+
return {
|
|
373
|
+
get(target, key, receiver) {
|
|
374
|
+
if (key === ReactiveSymbol) return true;
|
|
375
|
+
if (key === ReactivePeekSymbol) return target;
|
|
376
|
+
const getValue = Reflect.get(target, key, receiver);
|
|
377
|
+
const value = isSignal(getValue) ? getValue.value : getValue;
|
|
378
|
+
if (isExclude(key, exclude)) {
|
|
379
|
+
return value;
|
|
380
|
+
}
|
|
381
|
+
track(target, key);
|
|
382
|
+
if (isObject(value) && !shallow) {
|
|
383
|
+
return reactive(value);
|
|
384
|
+
}
|
|
385
|
+
return value;
|
|
386
|
+
},
|
|
387
|
+
set(target, key, value, receiver) {
|
|
388
|
+
if (isExclude(key, exclude)) {
|
|
389
|
+
Reflect.set(target, key, value, receiver);
|
|
390
|
+
return true;
|
|
391
|
+
}
|
|
392
|
+
let oldValue = Reflect.get(target, key, receiver);
|
|
393
|
+
if (isSignal(oldValue)) {
|
|
394
|
+
oldValue = oldValue.value;
|
|
395
|
+
}
|
|
396
|
+
if (isSignal(value)) {
|
|
397
|
+
value = value.value;
|
|
398
|
+
}
|
|
399
|
+
const obj = Reflect.set(target, key, value, receiver);
|
|
400
|
+
if (hasChanged(value, oldValue)) {
|
|
401
|
+
trigger(target, key);
|
|
402
|
+
}
|
|
403
|
+
return obj;
|
|
404
|
+
},
|
|
405
|
+
// handle delete
|
|
406
|
+
deleteProperty(target, key) {
|
|
407
|
+
const oldValue = Reflect.get(target, key);
|
|
408
|
+
const result = Reflect.deleteProperty(target, key);
|
|
409
|
+
if (oldValue !== void 0) {
|
|
410
|
+
trigger(target, key);
|
|
411
|
+
}
|
|
412
|
+
return result;
|
|
413
|
+
}
|
|
414
|
+
};
|
|
415
|
+
};
|
|
416
|
+
var arrayInstrumentations = createArrayInstrumentations();
|
|
417
|
+
function createArrayInstrumentations() {
|
|
418
|
+
const instrumentations2 = {};
|
|
419
|
+
["includes", "indexOf", "lastIndexOf"].forEach((key) => {
|
|
420
|
+
instrumentations2[key] = function(...args) {
|
|
421
|
+
const arr = toRaw(this);
|
|
422
|
+
for (let i = 0, l = this.length; i < l; i++) {
|
|
423
|
+
track(arr, `${i}`);
|
|
424
|
+
}
|
|
425
|
+
const res = arr[key](...args);
|
|
426
|
+
if (res === -1 || res === false) {
|
|
427
|
+
return arr[key](...args);
|
|
428
|
+
}
|
|
429
|
+
return res;
|
|
274
430
|
};
|
|
275
|
-
})
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
431
|
+
});
|
|
432
|
+
["push", "pop", "shift", "unshift", "splice", "sort", "reverse"].forEach((key) => {
|
|
433
|
+
instrumentations2[key] = function(...args) {
|
|
434
|
+
const arr = toRaw(this);
|
|
435
|
+
const res = arr[key].apply(this, args);
|
|
436
|
+
trigger(arr, reactiveArrayKey);
|
|
437
|
+
return res;
|
|
279
438
|
};
|
|
280
|
-
})
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
439
|
+
});
|
|
440
|
+
[
|
|
441
|
+
"forEach",
|
|
442
|
+
"map",
|
|
443
|
+
"filter",
|
|
444
|
+
"reduce",
|
|
445
|
+
"reduceRight",
|
|
446
|
+
"some",
|
|
447
|
+
"every",
|
|
448
|
+
"find",
|
|
449
|
+
"findIndex",
|
|
450
|
+
"findLast",
|
|
451
|
+
"findLastIndex",
|
|
452
|
+
"entries",
|
|
453
|
+
"keys",
|
|
454
|
+
"values"
|
|
455
|
+
].forEach((key) => {
|
|
456
|
+
instrumentations2[key] = function(...args) {
|
|
457
|
+
const arr = toRaw(this);
|
|
458
|
+
track(arr, reactiveArrayKey);
|
|
459
|
+
return arr[key].apply(this, args);
|
|
284
460
|
};
|
|
285
|
-
}), e;
|
|
286
|
-
}
|
|
287
|
-
var Ae = (e, t) => ({ get(n, o, r) {
|
|
288
|
-
if (o === x) return true;
|
|
289
|
-
if (o === w) return n;
|
|
290
|
-
if (oe.hasOwnProperty(o)) return Reflect.get(oe, o, r);
|
|
291
|
-
let s = Reflect.get(n, o, r);
|
|
292
|
-
return isExclude(o, t) ? s : (isStringNumber(o) && u(n, o), u(n, "length"), isObject(s) && !e ? v(s) : s);
|
|
293
|
-
}, set(n, o, r, s) {
|
|
294
|
-
let i = Reflect.get(n, o, s), d = Reflect.set(n, o, r, s);
|
|
295
|
-
return hasChanged(r, i) && (isStringNumber(o) && p(n, o), (o === "length" || !i) && p(n, "length")), d;
|
|
296
|
-
} });
|
|
297
|
-
var Ie = { get(e, t) {
|
|
298
|
-
return t === x ? true : t === w ? e : ((t === Symbol.iterator || t === "size") && u(e, f), Reflect.get(hasOwn(re, t) && t in e ? re : e, t, e));
|
|
299
|
-
} };
|
|
300
|
-
var Oe = { get(e, t) {
|
|
301
|
-
return t === x ? true : t === w ? e : Reflect.get(hasOwn(se, t) && t in e ? se : e, t, e);
|
|
302
|
-
} };
|
|
303
|
-
var re = { get(e) {
|
|
304
|
-
let t = c(this);
|
|
305
|
-
return u(t, f), t.get(e);
|
|
306
|
-
}, set(e, t) {
|
|
307
|
-
let n = c(this), o = n.set(e, t);
|
|
308
|
-
return p(n, f), o;
|
|
309
|
-
}, add(e) {
|
|
310
|
-
let t = c(this), n = t.add(e);
|
|
311
|
-
return p(t, f), n;
|
|
312
|
-
}, has(e) {
|
|
313
|
-
let t = c(this);
|
|
314
|
-
return u(t, f), t.has(e);
|
|
315
|
-
}, delete(e) {
|
|
316
|
-
let t = c(this), n = t.has(e), o = t.delete(e);
|
|
317
|
-
return n && p(t, f), o;
|
|
318
|
-
}, clear() {
|
|
319
|
-
let e = c(this), t = e.size > 0, n = e.clear();
|
|
320
|
-
return t && p(e, f), n;
|
|
321
|
-
}, forEach(e, t) {
|
|
322
|
-
let n = c(this);
|
|
323
|
-
u(n, f), n.forEach((o, r) => {
|
|
324
|
-
e.call(t, o, r, n);
|
|
325
461
|
});
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
}
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
},
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
462
|
+
return instrumentations2;
|
|
463
|
+
}
|
|
464
|
+
var ArrayHandler = (shallow, exclude) => {
|
|
465
|
+
return {
|
|
466
|
+
get(target, key, receiver) {
|
|
467
|
+
if (key === ReactiveSymbol) return true;
|
|
468
|
+
if (key === ReactivePeekSymbol) return target;
|
|
469
|
+
if (arrayInstrumentations.hasOwnProperty(key)) {
|
|
470
|
+
return Reflect.get(arrayInstrumentations, key, receiver);
|
|
471
|
+
}
|
|
472
|
+
const value = Reflect.get(target, key, receiver);
|
|
473
|
+
if (isExclude(key, exclude)) {
|
|
474
|
+
return value;
|
|
475
|
+
}
|
|
476
|
+
if (isStringNumber(key)) {
|
|
477
|
+
track(target, key);
|
|
478
|
+
}
|
|
479
|
+
track(target, "length");
|
|
480
|
+
if (isObject(value) && !shallow) {
|
|
481
|
+
return reactive(value);
|
|
482
|
+
}
|
|
483
|
+
return value;
|
|
484
|
+
},
|
|
485
|
+
set(target, key, value, receiver) {
|
|
486
|
+
const oldValue = Reflect.get(target, key, receiver);
|
|
487
|
+
const result = Reflect.set(target, key, value, receiver);
|
|
488
|
+
if (hasChanged(value, oldValue)) {
|
|
489
|
+
if (isStringNumber(key)) {
|
|
490
|
+
trigger(target, key);
|
|
491
|
+
}
|
|
492
|
+
if (key === "length" || !oldValue) {
|
|
493
|
+
trigger(target, "length");
|
|
494
|
+
}
|
|
495
|
+
}
|
|
496
|
+
return result;
|
|
497
|
+
}
|
|
498
|
+
};
|
|
499
|
+
};
|
|
500
|
+
var collectionHandlers = {
|
|
501
|
+
get(target, key) {
|
|
502
|
+
if (key === ReactiveSymbol) return true;
|
|
503
|
+
if (key === ReactivePeekSymbol) return target;
|
|
504
|
+
if (key === Symbol.iterator || key === "size") {
|
|
505
|
+
track(target, ReactiveCollectionKey);
|
|
506
|
+
}
|
|
507
|
+
return Reflect.get(
|
|
508
|
+
hasOwn(instrumentations, key) && key in target ? instrumentations : target,
|
|
509
|
+
key,
|
|
510
|
+
target
|
|
511
|
+
);
|
|
512
|
+
}
|
|
513
|
+
};
|
|
514
|
+
var weakCollectionHandlers = {
|
|
515
|
+
get(target, key) {
|
|
516
|
+
if (key === ReactiveSymbol) return true;
|
|
517
|
+
if (key === ReactivePeekSymbol) return target;
|
|
518
|
+
return Reflect.get(
|
|
519
|
+
hasOwn(weakInstrumentations, key) && key in target ? weakInstrumentations : target,
|
|
520
|
+
key,
|
|
521
|
+
target
|
|
522
|
+
);
|
|
523
|
+
}
|
|
524
|
+
};
|
|
525
|
+
var instrumentations = {
|
|
526
|
+
get(key) {
|
|
527
|
+
const target = toRaw(this);
|
|
528
|
+
track(target, ReactiveCollectionKey);
|
|
529
|
+
return target.get(key);
|
|
530
|
+
},
|
|
531
|
+
set(key, value) {
|
|
532
|
+
const target = toRaw(this);
|
|
533
|
+
const result = target.set(key, value);
|
|
534
|
+
trigger(target, ReactiveCollectionKey);
|
|
535
|
+
return result;
|
|
536
|
+
},
|
|
537
|
+
add(value) {
|
|
538
|
+
const target = toRaw(this);
|
|
539
|
+
const result = target.add(value);
|
|
540
|
+
trigger(target, ReactiveCollectionKey);
|
|
541
|
+
return result;
|
|
542
|
+
},
|
|
543
|
+
has(key) {
|
|
544
|
+
const target = toRaw(this);
|
|
545
|
+
track(target, ReactiveCollectionKey);
|
|
546
|
+
return target.has(key);
|
|
547
|
+
},
|
|
548
|
+
delete(key) {
|
|
549
|
+
const target = toRaw(this);
|
|
550
|
+
const hadKey = target.has(key);
|
|
551
|
+
const result = target.delete(key);
|
|
552
|
+
if (hadKey) {
|
|
553
|
+
trigger(target, ReactiveCollectionKey);
|
|
554
|
+
}
|
|
555
|
+
return result;
|
|
556
|
+
},
|
|
557
|
+
clear() {
|
|
558
|
+
const target = toRaw(this);
|
|
559
|
+
const hadItems = target.size > 0;
|
|
560
|
+
const result = target.clear();
|
|
561
|
+
if (hadItems) {
|
|
562
|
+
trigger(target, ReactiveCollectionKey);
|
|
563
|
+
}
|
|
564
|
+
return result;
|
|
565
|
+
},
|
|
566
|
+
forEach(callback, thisArg) {
|
|
567
|
+
const target = toRaw(this);
|
|
568
|
+
track(target, ReactiveCollectionKey);
|
|
569
|
+
target.forEach((value, key) => {
|
|
570
|
+
callback.call(thisArg, value, key, target);
|
|
370
571
|
});
|
|
371
|
-
}
|
|
572
|
+
},
|
|
573
|
+
get size() {
|
|
574
|
+
const target = toRaw(this);
|
|
575
|
+
track(target, ReactiveCollectionKey);
|
|
576
|
+
return target.size;
|
|
577
|
+
},
|
|
578
|
+
keys() {
|
|
579
|
+
const target = toRaw(this);
|
|
580
|
+
track(target, ReactiveCollectionKey);
|
|
581
|
+
return target.keys();
|
|
582
|
+
},
|
|
583
|
+
values() {
|
|
584
|
+
const target = toRaw(this);
|
|
585
|
+
track(target, ReactiveCollectionKey);
|
|
586
|
+
return target.values();
|
|
587
|
+
},
|
|
588
|
+
entries() {
|
|
589
|
+
const target = toRaw(this);
|
|
590
|
+
track(target, ReactiveCollectionKey);
|
|
591
|
+
return target.entries();
|
|
592
|
+
},
|
|
593
|
+
[Symbol.iterator]() {
|
|
594
|
+
const target = toRaw(this);
|
|
595
|
+
track(target, ReactiveCollectionKey);
|
|
596
|
+
return target[Symbol.iterator]();
|
|
597
|
+
}
|
|
598
|
+
};
|
|
599
|
+
var weakInstrumentations = {
|
|
600
|
+
get(key) {
|
|
601
|
+
const target = toRaw(this);
|
|
602
|
+
track(target, ReactiveWeakCollectionKey);
|
|
603
|
+
return target.get(key);
|
|
604
|
+
},
|
|
605
|
+
set(key, value) {
|
|
606
|
+
const target = toRaw(this);
|
|
607
|
+
const result = target.set(key, value);
|
|
608
|
+
trigger(target, ReactiveWeakCollectionKey);
|
|
609
|
+
return result;
|
|
610
|
+
},
|
|
611
|
+
add(value) {
|
|
612
|
+
const target = toRaw(this);
|
|
613
|
+
const result = target.add(value);
|
|
614
|
+
trigger(target, ReactiveWeakCollectionKey);
|
|
615
|
+
return result;
|
|
616
|
+
},
|
|
617
|
+
has(key) {
|
|
618
|
+
const target = toRaw(this);
|
|
619
|
+
track(target, ReactiveWeakCollectionKey);
|
|
620
|
+
return target.has(key);
|
|
621
|
+
},
|
|
622
|
+
delete(key) {
|
|
623
|
+
const target = toRaw(this);
|
|
624
|
+
const result = target.delete(key);
|
|
625
|
+
trigger(target, ReactiveWeakCollectionKey);
|
|
626
|
+
return result;
|
|
627
|
+
}
|
|
628
|
+
};
|
|
629
|
+
function reactive(initialValue, shallow = false, exclude) {
|
|
630
|
+
if (!isObject(initialValue)) {
|
|
631
|
+
return initialValue;
|
|
632
|
+
}
|
|
633
|
+
if (isReactive(initialValue)) {
|
|
634
|
+
return initialValue;
|
|
635
|
+
}
|
|
636
|
+
if (reactiveMap.has(initialValue)) {
|
|
637
|
+
return reactiveMap.get(initialValue);
|
|
638
|
+
}
|
|
639
|
+
let handler;
|
|
640
|
+
if (isArray(initialValue)) {
|
|
641
|
+
track(initialValue, reactiveArrayKey);
|
|
642
|
+
handler = ArrayHandler(shallow, exclude);
|
|
643
|
+
} else if (isSet(initialValue) || isMap(initialValue)) {
|
|
644
|
+
track(initialValue, ReactiveCollectionKey);
|
|
645
|
+
handler = collectionHandlers;
|
|
646
|
+
} else if (isWeakSet(initialValue) || isWeakMap(initialValue)) {
|
|
647
|
+
track(initialValue, ReactiveWeakCollectionKey);
|
|
648
|
+
handler = weakCollectionHandlers;
|
|
649
|
+
} else {
|
|
650
|
+
handler = basicHandler(shallow, exclude);
|
|
651
|
+
}
|
|
652
|
+
const proxy = new Proxy(initialValue, handler);
|
|
653
|
+
reactiveMap.set(initialValue, proxy);
|
|
654
|
+
return proxy;
|
|
655
|
+
}
|
|
656
|
+
function clearReactive(reactiveObj) {
|
|
657
|
+
if (!isReactive(reactiveObj)) {
|
|
658
|
+
{
|
|
659
|
+
warn("clearReactive: argument must be a reactive object");
|
|
660
|
+
}
|
|
661
|
+
return;
|
|
662
|
+
}
|
|
663
|
+
if (isWeakMap(reactiveObj) || isWeakSet(reactiveObj)) {
|
|
664
|
+
{
|
|
665
|
+
warn("clearReactive: WeakMap and WeakSet are not clearable");
|
|
666
|
+
}
|
|
667
|
+
return;
|
|
668
|
+
}
|
|
669
|
+
useBatch(() => {
|
|
670
|
+
if (isArray(reactiveObj)) {
|
|
671
|
+
reactiveObj.length = 0;
|
|
672
|
+
} else if (isSet(reactiveObj) || isMap(reactiveObj)) {
|
|
673
|
+
reactiveObj.clear();
|
|
674
|
+
} else if (isObject(reactiveObj)) {
|
|
675
|
+
Object.keys(reactiveObj).forEach((key) => {
|
|
676
|
+
delete reactiveObj[key];
|
|
677
|
+
});
|
|
678
|
+
}
|
|
679
|
+
});
|
|
372
680
|
}
|
|
373
|
-
function
|
|
681
|
+
function useBatch(fn) {
|
|
374
682
|
try {
|
|
375
|
-
|
|
683
|
+
inBatch = true;
|
|
684
|
+
fn();
|
|
376
685
|
} finally {
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
}
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
}
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
let
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
}
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
686
|
+
inBatch = false;
|
|
687
|
+
runBatch();
|
|
688
|
+
}
|
|
689
|
+
}
|
|
690
|
+
function runBatch() {
|
|
691
|
+
if (batchQueue.size > 0) {
|
|
692
|
+
batchQueue.forEach((effect) => effect());
|
|
693
|
+
batchQueue.clear();
|
|
694
|
+
}
|
|
695
|
+
}
|
|
696
|
+
function useWatch(source, cb, options) {
|
|
697
|
+
return doWatch(source, cb, options);
|
|
698
|
+
}
|
|
699
|
+
var INITIAL_WATCHER_VALUE = void 0;
|
|
700
|
+
var watcher;
|
|
701
|
+
var flushing = false;
|
|
702
|
+
function queueWatcher(fn) {
|
|
703
|
+
watcher = fn;
|
|
704
|
+
if (!flushing) {
|
|
705
|
+
flushing = true;
|
|
706
|
+
nextTick(flushWatchers);
|
|
707
|
+
}
|
|
708
|
+
}
|
|
709
|
+
function flushWatchers() {
|
|
710
|
+
watcher == null ? void 0 : watcher();
|
|
711
|
+
watcher = null;
|
|
712
|
+
flushing = false;
|
|
713
|
+
}
|
|
714
|
+
function doWatch(source, cb, { deep, immediate } = {}) {
|
|
715
|
+
let getter;
|
|
716
|
+
const isMultiSource = isArray(source);
|
|
717
|
+
if (isSignal(source) || isComputed(source)) {
|
|
718
|
+
getter = () => source.value;
|
|
719
|
+
} else if (isReactive(source)) {
|
|
720
|
+
getter = () => __spreadValues({}, source);
|
|
721
|
+
} else if (isMultiSource) {
|
|
722
|
+
getter = () => source.map((s) => resolveSource(s));
|
|
723
|
+
} else if (isFunction(source)) {
|
|
724
|
+
getter = source;
|
|
725
|
+
} else {
|
|
726
|
+
warn("Invalid source type", source);
|
|
727
|
+
return noop;
|
|
728
|
+
}
|
|
729
|
+
if (cb && deep) {
|
|
730
|
+
const baseGetter = getter;
|
|
731
|
+
const depth = deep === true ? Infinity : deep;
|
|
732
|
+
getter = () => traverse(baseGetter(), depth);
|
|
733
|
+
}
|
|
734
|
+
let oldValue = isMultiSource ? Array.from({ length: source.length }).fill(INITIAL_WATCHER_VALUE) : INITIAL_WATCHER_VALUE;
|
|
735
|
+
let runCb = false;
|
|
736
|
+
const effectFn = () => {
|
|
737
|
+
const newValue = getter();
|
|
738
|
+
if (hasChanged(newValue, oldValue)) {
|
|
739
|
+
if (immediate && cb) {
|
|
740
|
+
cb(newValue, oldValue);
|
|
741
|
+
oldValue = newValue;
|
|
742
|
+
}
|
|
743
|
+
if (runCb && cb) {
|
|
744
|
+
queueWatcher(() => {
|
|
745
|
+
cb(newValue, oldValue);
|
|
746
|
+
oldValue = newValue;
|
|
747
|
+
});
|
|
748
|
+
}
|
|
749
|
+
!runCb && (oldValue = newValue);
|
|
750
|
+
}
|
|
751
|
+
};
|
|
752
|
+
const stop = useEffect(effectFn, { flush: "sync" });
|
|
753
|
+
runCb = true;
|
|
754
|
+
if (immediate) {
|
|
755
|
+
effectFn();
|
|
756
|
+
}
|
|
757
|
+
return stop;
|
|
758
|
+
}
|
|
759
|
+
function resolveSource(s) {
|
|
760
|
+
if (isSignal(s) || isComputed(s)) return s.value;
|
|
761
|
+
if (isReactive(s)) return __spreadValues({}, s);
|
|
762
|
+
if (isFunction(s)) return s();
|
|
763
|
+
warn("Invalid source", s);
|
|
764
|
+
return noop;
|
|
765
|
+
}
|
|
766
|
+
function traverse(value, depth = Infinity, seen) {
|
|
767
|
+
if (depth <= 0 || !isObject(value)) {
|
|
768
|
+
return value;
|
|
769
|
+
}
|
|
770
|
+
seen = seen || /* @__PURE__ */ new Set();
|
|
771
|
+
if (seen.has(value)) {
|
|
772
|
+
return value;
|
|
773
|
+
}
|
|
774
|
+
seen.add(value);
|
|
775
|
+
depth--;
|
|
776
|
+
if (isSignal(value)) {
|
|
777
|
+
traverse(value.value, depth, seen);
|
|
778
|
+
} else if (isArray(value)) {
|
|
779
|
+
for (const element of value) {
|
|
780
|
+
traverse(element, depth, seen);
|
|
781
|
+
}
|
|
782
|
+
} else if (isSet(value) || isMap(value)) {
|
|
783
|
+
value.forEach((v) => {
|
|
784
|
+
traverse(v, depth, seen);
|
|
785
|
+
});
|
|
786
|
+
} else if (isPlainObject(value)) {
|
|
787
|
+
for (const key in value) {
|
|
788
|
+
traverse(value[key], depth, seen);
|
|
789
|
+
}
|
|
790
|
+
}
|
|
791
|
+
return value;
|
|
792
|
+
}
|
|
793
|
+
function createOptionsStore(options) {
|
|
794
|
+
const { state, getters, actions } = options;
|
|
795
|
+
const initState = __spreadValues({}, state);
|
|
796
|
+
const reactiveState = useReactive(state);
|
|
797
|
+
const subscriptions = [];
|
|
798
|
+
const actionCallbacks = [];
|
|
799
|
+
const default_actions = {
|
|
800
|
+
patch$(payload) {
|
|
801
|
+
Object.assign(reactiveState, payload);
|
|
802
|
+
subscriptions.forEach((callback) => callback(reactiveState));
|
|
803
|
+
actionCallbacks.forEach((callback) => callback(reactiveState));
|
|
804
|
+
},
|
|
805
|
+
subscribe$(callback) {
|
|
806
|
+
subscriptions.push(callback);
|
|
807
|
+
},
|
|
808
|
+
unsubscribe$(callback) {
|
|
809
|
+
const index = subscriptions.indexOf(callback);
|
|
810
|
+
if (index !== -1) {
|
|
811
|
+
subscriptions.splice(index, 1);
|
|
812
|
+
}
|
|
813
|
+
},
|
|
814
|
+
onAction$(callback) {
|
|
815
|
+
actionCallbacks.push(callback);
|
|
816
|
+
},
|
|
817
|
+
reset$() {
|
|
818
|
+
Object.assign(reactiveState, initState);
|
|
819
|
+
}
|
|
820
|
+
};
|
|
821
|
+
const store = __spreadValues(__spreadProps(__spreadValues({}, reactiveState), {
|
|
822
|
+
state: reactiveState
|
|
823
|
+
}), default_actions);
|
|
824
|
+
if (getters) {
|
|
825
|
+
for (const key in getters) {
|
|
826
|
+
const getter = getters[key];
|
|
827
|
+
if (getter) {
|
|
828
|
+
Object.defineProperty(store, key, {
|
|
829
|
+
get() {
|
|
830
|
+
return useComputed(() => getter.call(store, reactiveState)).value;
|
|
831
|
+
},
|
|
832
|
+
enumerable: true,
|
|
833
|
+
configurable: true
|
|
834
|
+
});
|
|
835
|
+
}
|
|
836
|
+
}
|
|
837
|
+
}
|
|
838
|
+
if (actions) {
|
|
839
|
+
for (const key in actions) {
|
|
840
|
+
const action = actions[key];
|
|
841
|
+
if (action) {
|
|
842
|
+
store[key] = function(...args) {
|
|
843
|
+
const result = action.apply(reactiveState, args);
|
|
844
|
+
actionCallbacks.forEach((callback) => callback(reactiveState));
|
|
845
|
+
return result;
|
|
846
|
+
};
|
|
847
|
+
}
|
|
848
|
+
}
|
|
849
|
+
}
|
|
850
|
+
return store;
|
|
851
|
+
}
|
|
852
|
+
function createStore(storeDefinition) {
|
|
453
853
|
return function() {
|
|
454
|
-
|
|
854
|
+
let options;
|
|
855
|
+
if (typeof storeDefinition === "function") {
|
|
856
|
+
options = createClassStore(storeDefinition);
|
|
857
|
+
} else {
|
|
858
|
+
options = storeDefinition;
|
|
859
|
+
}
|
|
860
|
+
const store = createOptionsStore(options);
|
|
861
|
+
if (typeof storeDefinition === "function") {
|
|
862
|
+
Object.keys(options.actions || {}).forEach((key) => {
|
|
863
|
+
store[key] = options.actions[key].bind(store);
|
|
864
|
+
});
|
|
865
|
+
}
|
|
866
|
+
return store;
|
|
867
|
+
};
|
|
868
|
+
}
|
|
869
|
+
function createClassStore(StoreClass) {
|
|
870
|
+
const instance = new StoreClass();
|
|
871
|
+
const state = /* @__PURE__ */ Object.create(null);
|
|
872
|
+
const getters = {};
|
|
873
|
+
const actions = {};
|
|
874
|
+
Object.getOwnPropertyNames(instance).forEach((key) => {
|
|
875
|
+
state[key] = instance[key];
|
|
876
|
+
});
|
|
877
|
+
Object.getOwnPropertyNames(StoreClass.prototype).forEach((key) => {
|
|
878
|
+
const descriptor = Object.getOwnPropertyDescriptor(StoreClass.prototype, key);
|
|
879
|
+
if (descriptor) {
|
|
880
|
+
if (typeof descriptor.get === "function") {
|
|
881
|
+
getters[key] = function() {
|
|
882
|
+
return descriptor.get.call(this);
|
|
883
|
+
};
|
|
884
|
+
} else if (typeof descriptor.value === "function" && key !== "constructor") {
|
|
885
|
+
actions[key] = function(...args) {
|
|
886
|
+
return descriptor.value.apply(this, args);
|
|
887
|
+
};
|
|
888
|
+
}
|
|
889
|
+
}
|
|
890
|
+
});
|
|
891
|
+
return {
|
|
892
|
+
state,
|
|
893
|
+
getters,
|
|
894
|
+
actions
|
|
455
895
|
};
|
|
456
896
|
}
|
|
457
897
|
|
|
458
898
|
// ../template/dist/template.dev.esm.js
|
|
459
|
-
var
|
|
899
|
+
var EVENT_PREFIX = "on";
|
|
900
|
+
var UPDATE_PREFIX = "update";
|
|
901
|
+
var CHILDREN_PROP = "children";
|
|
902
|
+
var EMPTY_TEMPLATE = "";
|
|
903
|
+
var FRAGMENT_PROP_KEY = "0";
|
|
904
|
+
var SINGLE_PROP_KEY = "1";
|
|
905
|
+
var PLACEHOLDER = " __PLACEHOLDER__ ";
|
|
460
906
|
var RenderContext = class {
|
|
461
907
|
constructor() {
|
|
462
908
|
this.renderMode = 0;
|
|
463
909
|
}
|
|
910
|
+
// Getter to check if the current mode is SSG
|
|
464
911
|
get isSSG() {
|
|
465
912
|
return this.renderMode === 1;
|
|
466
913
|
}
|
|
914
|
+
// Getter to check if the current mode is SSR
|
|
467
915
|
get isSSR() {
|
|
468
916
|
return this.renderMode === 2;
|
|
469
917
|
}
|
|
918
|
+
// Getter to check if the current mode is Client
|
|
470
919
|
get isClient() {
|
|
471
920
|
return this.renderMode === 0;
|
|
472
921
|
}
|
|
922
|
+
// Set render mode to SSR
|
|
473
923
|
setSSR() {
|
|
474
924
|
this.renderMode = 2;
|
|
475
925
|
}
|
|
926
|
+
// Set render mode to SSG
|
|
476
927
|
setSSG() {
|
|
477
928
|
this.renderMode = 1;
|
|
478
929
|
}
|
|
930
|
+
// Set render mode to Client
|
|
479
931
|
setClient() {
|
|
480
932
|
this.renderMode = 0;
|
|
481
933
|
}
|
|
482
934
|
};
|
|
483
935
|
var renderContext = new RenderContext();
|
|
936
|
+
var componentMap = /* @__PURE__ */ new Map();
|
|
484
937
|
function enterComponent(temp, index) {
|
|
485
938
|
componentMap.set(temp, {
|
|
486
939
|
index
|
|
487
940
|
});
|
|
488
941
|
}
|
|
489
942
|
function getComponentIndex(temp) {
|
|
490
|
-
|
|
943
|
+
var _a;
|
|
944
|
+
return (_a = componentMap.get(temp)) == null ? void 0 : _a.index;
|
|
491
945
|
}
|
|
492
946
|
var _LifecycleContext = class _LifecycleContext2 {
|
|
493
947
|
constructor() {
|
|
@@ -500,22 +954,28 @@ var _LifecycleContext = class _LifecycleContext2 {
|
|
|
500
954
|
}
|
|
501
955
|
removeEventListener() {
|
|
502
956
|
}
|
|
957
|
+
// Add a hook for a specific lifecycle stage
|
|
503
958
|
addHook(hook, cb) {
|
|
504
959
|
var _a;
|
|
505
960
|
(_a = this.hooks[hook]) == null ? void 0 : _a.add(cb);
|
|
506
961
|
}
|
|
962
|
+
// Get a value from the static context
|
|
507
963
|
getContext(context) {
|
|
508
964
|
return _LifecycleContext2.context[context];
|
|
509
965
|
}
|
|
966
|
+
// Set a value in the static context
|
|
510
967
|
setContext(context, value) {
|
|
511
968
|
_LifecycleContext2.context[context] = value;
|
|
512
969
|
}
|
|
970
|
+
// Initialize the static reference
|
|
513
971
|
initRef() {
|
|
514
972
|
_LifecycleContext2.ref = this;
|
|
515
973
|
}
|
|
974
|
+
// Remove the static reference
|
|
516
975
|
removeRef() {
|
|
517
976
|
_LifecycleContext2.ref = null;
|
|
518
977
|
}
|
|
978
|
+
// Clear all hooks
|
|
519
979
|
clearHooks() {
|
|
520
980
|
Object.values(this.hooks).forEach((set) => set.clear());
|
|
521
981
|
}
|
|
@@ -534,29 +994,39 @@ var SSGNode = class extends LifecycleContext {
|
|
|
534
994
|
this.props = props;
|
|
535
995
|
this.key = key;
|
|
536
996
|
enterComponent(template, componentIndex);
|
|
997
|
+
this.templates = this.processTemplate();
|
|
998
|
+
}
|
|
999
|
+
// Process the template and return an array of processed strings
|
|
1000
|
+
processTemplate() {
|
|
537
1001
|
if (isArray(this.template)) {
|
|
538
|
-
const PLACEHOLDER = " __PLACEHOLDER__ ";
|
|
539
1002
|
const htmlString = this.template.join(PLACEHOLDER);
|
|
540
|
-
const processedString =
|
|
541
|
-
|
|
542
|
-
if (p1.includes("data-ci")) return match;
|
|
543
|
-
return p1.replace(/<\s*([\da-z]+)(\s[^>]*)?>/i, (_2, tagName, attrs) => {
|
|
544
|
-
return `<${tagName} data-ci="${componentIndex}"${attrs || ""}>`;
|
|
545
|
-
});
|
|
546
|
-
} else if (p2 && p2.replace(PLACEHOLDER, "").trim()) {
|
|
547
|
-
return `<!--${0}-${componentIndex}-->${p2}<!$>`;
|
|
548
|
-
}
|
|
549
|
-
return match;
|
|
550
|
-
});
|
|
551
|
-
this.template = processedString.split(PLACEHOLDER);
|
|
1003
|
+
const processedString = this.processHtmlString(htmlString);
|
|
1004
|
+
return processedString.split(PLACEHOLDER);
|
|
552
1005
|
}
|
|
1006
|
+
return [];
|
|
1007
|
+
}
|
|
1008
|
+
// Process HTML string by adding component index and handling text nodes
|
|
1009
|
+
processHtmlString(htmlString) {
|
|
1010
|
+
return htmlString.replaceAll(/(<[^>]+>)|([^<]+)/g, (match, p1, p2) => {
|
|
1011
|
+
if (p1) {
|
|
1012
|
+
if (p1.includes("data-ci")) return match;
|
|
1013
|
+
return p1.replace(/<\s*([\da-z]+)(\s[^>]*)?>/i, (_, tagName, attrs) => {
|
|
1014
|
+
return `<${tagName} data-ci="${componentIndex}"${attrs || ""}>`;
|
|
1015
|
+
});
|
|
1016
|
+
} else if (p2 && p2.replace(PLACEHOLDER, "").trim()) {
|
|
1017
|
+
return `<!--${0}-${componentIndex}-->${p2}<!$>`;
|
|
1018
|
+
}
|
|
1019
|
+
return match;
|
|
1020
|
+
});
|
|
553
1021
|
}
|
|
1022
|
+
// Mount the SSGNode and return the rendered string
|
|
554
1023
|
mount() {
|
|
555
1024
|
this.initRef();
|
|
556
1025
|
const output = this.render();
|
|
557
1026
|
this.removeRef();
|
|
558
1027
|
return output;
|
|
559
1028
|
}
|
|
1029
|
+
// Render the SSGNode
|
|
560
1030
|
render() {
|
|
561
1031
|
if (isFunction(this.template)) {
|
|
562
1032
|
const root = this.template(this.props);
|
|
@@ -566,55 +1036,64 @@ var SSGNode = class extends LifecycleContext {
|
|
|
566
1036
|
return String(root);
|
|
567
1037
|
}
|
|
568
1038
|
}
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
const
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
this.template[findIndex] += children;
|
|
580
|
-
});
|
|
1039
|
+
return this.renderTemplate();
|
|
1040
|
+
}
|
|
1041
|
+
// Render the template by processing props and children
|
|
1042
|
+
renderTemplate() {
|
|
1043
|
+
Object.entries(this.props).forEach(([key, cur]) => {
|
|
1044
|
+
const children = cur.children;
|
|
1045
|
+
this.normalizeProps(cur);
|
|
1046
|
+
const findIndex = this.templates.findIndex((t) => t.includes(`data-hk="${key}"`));
|
|
1047
|
+
if (children) {
|
|
1048
|
+
this.renderChildren(children, findIndex);
|
|
581
1049
|
}
|
|
582
|
-
this.
|
|
1050
|
+
this.templates[findIndex] = this.templates[findIndex].replace(
|
|
583
1051
|
`data-hk="${key}"`,
|
|
584
|
-
`data-hk="${key}" ${generateAttributes(cur)}`
|
|
1052
|
+
`data-hk="${key}" ${this.generateAttributes(cur)}`
|
|
585
1053
|
);
|
|
586
1054
|
});
|
|
587
|
-
return
|
|
1055
|
+
return this.templates.join("");
|
|
588
1056
|
}
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
1057
|
+
// Normalize props by removing children and handling signals
|
|
1058
|
+
normalizeProps(props) {
|
|
1059
|
+
Object.entries(props).forEach(([key, value]) => {
|
|
1060
|
+
if (key === "children") {
|
|
1061
|
+
delete props[key];
|
|
1062
|
+
} else if (isFunction(value)) {
|
|
1063
|
+
delete props[key];
|
|
1064
|
+
} else if (isSignal(value)) {
|
|
1065
|
+
props[key] = value.value;
|
|
1066
|
+
}
|
|
1067
|
+
});
|
|
1068
|
+
}
|
|
1069
|
+
// Generate HTML attributes string from props
|
|
1070
|
+
generateAttributes(props) {
|
|
1071
|
+
return Object.entries(props).filter(([key, value]) => key !== "children" && !isFunction(value)).map(([key, value]) => `${key}="${escape(String(value))}"`).join(" ");
|
|
1072
|
+
}
|
|
1073
|
+
// Render children and append them to the template
|
|
1074
|
+
renderChildren(children, findIndex) {
|
|
1075
|
+
children.forEach(([child]) => {
|
|
1076
|
+
componentIndex++;
|
|
1077
|
+
const renderedChild = this.renderChild(child);
|
|
1078
|
+
this.templates[findIndex] += renderedChild;
|
|
1079
|
+
});
|
|
1080
|
+
}
|
|
1081
|
+
// Render a single child node
|
|
1082
|
+
renderChild(child) {
|
|
1083
|
+
if (isFunction(child)) {
|
|
1084
|
+
return this.renderChild(child(this.props));
|
|
1085
|
+
} else if (isSignal(child)) {
|
|
1086
|
+
return `<!--${1}-${componentIndex}-->${child.value}<!$>`;
|
|
1087
|
+
} else if (isSSGNode(child)) {
|
|
1088
|
+
const childResult = child.mount();
|
|
1089
|
+
return isFunction(childResult) ? childResult(this.props) : extractSignal(childResult);
|
|
1090
|
+
} else {
|
|
1091
|
+
return `<!--${1}-${componentIndex}-->${child}<!$>`;
|
|
598
1092
|
}
|
|
599
|
-
});
|
|
600
|
-
}
|
|
601
|
-
function generateAttributes(props) {
|
|
602
|
-
return Object.entries(props).filter(([key, value]) => key !== "children" && !isFunction(value)).map(([key, value]) => `${key}="${escape(String(value))}"`).join(" ");
|
|
603
|
-
}
|
|
604
|
-
function renderChildren(children, prop) {
|
|
605
|
-
if (isFunction(children)) {
|
|
606
|
-
return renderChildren(children(prop), prop);
|
|
607
|
-
} else if (h(children)) {
|
|
608
|
-
return `<!--${1}-${componentIndex}-->${children.value}<!$>`;
|
|
609
|
-
} else if (isSSGNode(children)) {
|
|
610
|
-
const childResult = children.mount();
|
|
611
|
-
return isFunction(childResult) ? childResult(prop) : extractSignal(childResult);
|
|
612
|
-
} else {
|
|
613
|
-
return `<!--${1}-${componentIndex}-->${children}<!$>`;
|
|
614
1093
|
}
|
|
615
|
-
}
|
|
616
|
-
var
|
|
617
|
-
var
|
|
1094
|
+
};
|
|
1095
|
+
var SELF_CLOSING_TAGS = "area,base,br,col,embed,hr,img,input,link,meta,param,source,track,wbr".split(",");
|
|
1096
|
+
var HTML_TAGS = "a,abbr,acronym,address,applet,area,article,aside,audio,b,base,basefont,bdi,bdo,bgsound,big,blink,blockquote,body,br,button,canvas,caption,center,cite,code,col,colgroup,command,content,data,datalist,dd,del,details,dfn,dialog,dir,div,dl,dt,em,embed,fieldset,figcaption,figure,font,footer,form,frame,frameset,h1,h2,h3,h4,h5,h6,head,header,hgroup,hr,html,i,iframe,image,img,input,ins,kbd,keygen,label,legend,li,link,listing,main,map,mark,marquee,menu,menuitem,meta,meter,nav,nobr,noframes,noscript,object,ol,optgroup,option,output,p,param,picture,plaintext,pre,progress,q,rb,rp,rt,rtc,ruby,s,samp,script,section,select,shadow,small,source,spacer,span,strike,strong,style,sub,summary,sup,table,tbody,td,template,textarea,tfoot,th,thead,time,title,tr,track,tt,u,ul,var,video,wbr,xmp".split(
|
|
618
1097
|
","
|
|
619
1098
|
);
|
|
620
1099
|
function coerceNode(data) {
|
|
@@ -651,26 +1130,33 @@ function replaceChild(parent, node, child) {
|
|
|
651
1130
|
}
|
|
652
1131
|
function setAttribute(element, attr, value) {
|
|
653
1132
|
if (attr === "class") {
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
element.className = Object.entries(value).reduce((acc, [key, value2]) => acc + (value2 ? ` ${key}` : ""), "").trim();
|
|
660
|
-
}
|
|
661
|
-
return;
|
|
1133
|
+
setClassAttribute(element, value);
|
|
1134
|
+
} else if (attr === "style") {
|
|
1135
|
+
setStyleAttribute(element, value);
|
|
1136
|
+
} else {
|
|
1137
|
+
setGenericAttribute(element, attr, value);
|
|
662
1138
|
}
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
1139
|
+
}
|
|
1140
|
+
function setClassAttribute(element, value) {
|
|
1141
|
+
if (typeof value === "string") {
|
|
1142
|
+
element.className = value;
|
|
1143
|
+
} else if (isArray(value)) {
|
|
1144
|
+
element.className = value.join(" ");
|
|
1145
|
+
} else if (value && typeof value === "object") {
|
|
1146
|
+
element.className = Object.entries(value).reduce((acc, [key, value2]) => acc + (value2 ? ` ${key}` : ""), "").trim();
|
|
1147
|
+
}
|
|
1148
|
+
}
|
|
1149
|
+
function setStyleAttribute(element, value) {
|
|
1150
|
+
if (typeof value === "string") {
|
|
1151
|
+
element.style.cssText = value;
|
|
1152
|
+
} else if (value && typeof value === "object") {
|
|
1153
|
+
const obj = value;
|
|
1154
|
+
Object.entries(obj).forEach(([key, value2]) => {
|
|
1155
|
+
element.style.setProperty(kebabCase(key), String(value2));
|
|
1156
|
+
});
|
|
673
1157
|
}
|
|
1158
|
+
}
|
|
1159
|
+
function setGenericAttribute(element, attr, value) {
|
|
674
1160
|
if (isFalsy(value)) {
|
|
675
1161
|
element.removeAttribute(attr);
|
|
676
1162
|
} else if (value === true) {
|
|
@@ -753,7 +1239,7 @@ function closeHtmlTags(input) {
|
|
|
753
1239
|
if (tagStack.length > 0) {
|
|
754
1240
|
tagStack.pop();
|
|
755
1241
|
}
|
|
756
|
-
} else if (!
|
|
1242
|
+
} else if (!SELF_CLOSING_TAGS.includes(tagName)) {
|
|
757
1243
|
tagStack.push(tagName);
|
|
758
1244
|
}
|
|
759
1245
|
output.push(fullMatch);
|
|
@@ -768,17 +1254,13 @@ function closeHtmlTags(input) {
|
|
|
768
1254
|
return output.join("");
|
|
769
1255
|
}
|
|
770
1256
|
function isHtmlTagName(tagName) {
|
|
771
|
-
return
|
|
1257
|
+
return HTML_TAGS.includes(tagName);
|
|
772
1258
|
}
|
|
773
1259
|
function convertToHtmlTag(tagName) {
|
|
774
|
-
|
|
775
|
-
return `<${tagName}/>`;
|
|
776
|
-
} else {
|
|
777
|
-
return `<${tagName}></${tagName}>`;
|
|
778
|
-
}
|
|
1260
|
+
return SELF_CLOSING_TAGS.includes(tagName) ? `<${tagName}/>` : `<${tagName}></${tagName}>`;
|
|
779
1261
|
}
|
|
780
1262
|
function extractSignal(signal) {
|
|
781
|
-
if (
|
|
1263
|
+
if (isSignal(signal)) {
|
|
782
1264
|
return signal.value;
|
|
783
1265
|
} else {
|
|
784
1266
|
return signal;
|
|
@@ -793,19 +1275,28 @@ var ComponentNode = class extends LifecycleContext {
|
|
|
793
1275
|
this.emitter = /* @__PURE__ */ new Set();
|
|
794
1276
|
this.rootNode = null;
|
|
795
1277
|
this.trackMap = /* @__PURE__ */ new Map();
|
|
796
|
-
this.
|
|
1278
|
+
this.key || (this.key = props == null ? void 0 : props.key);
|
|
1279
|
+
this.proxyProps = this.createProxyProps(props);
|
|
1280
|
+
}
|
|
1281
|
+
// Create reactive props
|
|
1282
|
+
createProxyProps(props) {
|
|
1283
|
+
if (!props) return {};
|
|
1284
|
+
return useReactive(
|
|
797
1285
|
props,
|
|
798
|
-
(
|
|
799
|
-
)
|
|
1286
|
+
(key) => startsWith(key, EVENT_PREFIX) || startsWith(key, UPDATE_PREFIX) || key === CHILDREN_PROP
|
|
1287
|
+
);
|
|
800
1288
|
}
|
|
1289
|
+
// Getter for the first child node
|
|
801
1290
|
get firstChild() {
|
|
802
1291
|
var _a, _b;
|
|
803
1292
|
return (_b = (_a = this.rootNode) == null ? void 0 : _a.firstChild) != null ? _b : null;
|
|
804
1293
|
}
|
|
1294
|
+
// Getter to check if the node is connected to the DOM
|
|
805
1295
|
get isConnected() {
|
|
806
1296
|
var _a, _b;
|
|
807
1297
|
return (_b = (_a = this.rootNode) == null ? void 0 : _a.isConnected) != null ? _b : false;
|
|
808
1298
|
}
|
|
1299
|
+
// Method to mount the component to the DOM
|
|
809
1300
|
mount(parent, before) {
|
|
810
1301
|
var _a, _b, _c, _d;
|
|
811
1302
|
if (!isFunction(this.template)) {
|
|
@@ -817,32 +1308,37 @@ var ComponentNode = class extends LifecycleContext {
|
|
|
817
1308
|
this.initRef();
|
|
818
1309
|
this.rootNode = this.template(this.proxyProps);
|
|
819
1310
|
const mountedNode = (_d = (_c = this.rootNode) == null ? void 0 : _c.mount(parent, before)) != null ? _d : [];
|
|
820
|
-
this.
|
|
1311
|
+
this.callMountHooks();
|
|
821
1312
|
this.patchProps(this.props);
|
|
822
1313
|
this.removeRef();
|
|
823
1314
|
return mountedNode;
|
|
824
1315
|
}
|
|
1316
|
+
// Method to unmount the component from the DOM
|
|
825
1317
|
unmount() {
|
|
826
1318
|
var _a;
|
|
827
|
-
this.
|
|
1319
|
+
this.callDestroyHooks();
|
|
828
1320
|
this.clearHooks();
|
|
829
1321
|
(_a = this.rootNode) == null ? void 0 : _a.unmount();
|
|
830
1322
|
this.rootNode = null;
|
|
831
1323
|
this.proxyProps = {};
|
|
1324
|
+
this.clearEmitter();
|
|
1325
|
+
}
|
|
1326
|
+
// Private method to call mount hooks
|
|
1327
|
+
callMountHooks() {
|
|
1328
|
+
this.hooks.mounted.forEach((handler) => handler());
|
|
1329
|
+
}
|
|
1330
|
+
// Private method to call destroy hooks
|
|
1331
|
+
callDestroyHooks() {
|
|
1332
|
+
this.hooks.destroy.forEach((handler) => handler());
|
|
1333
|
+
}
|
|
1334
|
+
// Private method to clear the event emitter
|
|
1335
|
+
clearEmitter() {
|
|
832
1336
|
for (const cleanup of this.emitter) {
|
|
833
1337
|
cleanup();
|
|
834
1338
|
}
|
|
835
1339
|
this.emitter.clear();
|
|
836
1340
|
}
|
|
837
|
-
|
|
838
|
-
* Inherit props and state from another ComponentNode.
|
|
839
|
-
* It will:
|
|
840
|
-
* 1. Copy props from the node to this proxyProps.
|
|
841
|
-
* 2. Copy the rootNode, trackMap and hooks from the node.
|
|
842
|
-
* 3. Copy the props from the node to this.
|
|
843
|
-
* 4. Patch props from the props passed in the constructor.
|
|
844
|
-
* @param node The node to inherit from.
|
|
845
|
-
*/
|
|
1341
|
+
// Method to inherit properties from another ComponentNode
|
|
846
1342
|
inheritNode(node) {
|
|
847
1343
|
Object.assign(this.proxyProps, node.proxyProps);
|
|
848
1344
|
this.rootNode = node.rootNode;
|
|
@@ -852,55 +1348,58 @@ var ComponentNode = class extends LifecycleContext {
|
|
|
852
1348
|
this.props = node.props;
|
|
853
1349
|
this.patchProps(props);
|
|
854
1350
|
}
|
|
855
|
-
|
|
856
|
-
* Get a NodeTrack from the trackMap. If the track is not in the trackMap, create a new one.
|
|
857
|
-
* Then, call the cleanup function to remove any previously registered hooks.
|
|
858
|
-
* @param trackKey the key of the node track to get.
|
|
859
|
-
* @returns the NodeTrack, cleaned up and ready to use.
|
|
860
|
-
*/
|
|
1351
|
+
// Private method to get or create a NodeTrack
|
|
861
1352
|
getNodeTrack(trackKey) {
|
|
862
|
-
let
|
|
863
|
-
if (!
|
|
864
|
-
|
|
1353
|
+
let track2 = this.trackMap.get(trackKey);
|
|
1354
|
+
if (!track2) {
|
|
1355
|
+
track2 = { cleanup: () => {
|
|
865
1356
|
} };
|
|
866
|
-
this.trackMap.set(trackKey,
|
|
1357
|
+
this.trackMap.set(trackKey, track2);
|
|
867
1358
|
}
|
|
868
|
-
|
|
869
|
-
return
|
|
1359
|
+
track2.cleanup();
|
|
1360
|
+
return track2;
|
|
870
1361
|
}
|
|
871
|
-
|
|
872
|
-
* Patch the props of this node.
|
|
873
|
-
* It will:
|
|
874
|
-
* 1. Iterate the props and patch it.
|
|
875
|
-
* 2. If the prop is a event handler, add a event listener to the first child of the node.
|
|
876
|
-
* 3. If the prop is a ref, set the first child of the node to the ref.
|
|
877
|
-
* 4. If the prop is a update handler, update the prop in the node's props.
|
|
878
|
-
* 5. If the prop is a normal prop, create a signal for it and then patch it.
|
|
879
|
-
* @param props The props to patch.
|
|
880
|
-
*/
|
|
1362
|
+
// Method to patch props onto the component
|
|
881
1363
|
patchProps(props) {
|
|
882
|
-
var _a
|
|
1364
|
+
var _a;
|
|
883
1365
|
if (!props) {
|
|
884
1366
|
return;
|
|
885
1367
|
}
|
|
886
1368
|
for (const [key, prop] of Object.entries(props)) {
|
|
887
|
-
if (startsWith(key,
|
|
888
|
-
|
|
889
|
-
const cleanup = addEventListener(this.rootNode.nodes[0], event, prop);
|
|
890
|
-
this.emitter.add(cleanup);
|
|
1369
|
+
if (startsWith(key, EVENT_PREFIX) && ((_a = this.rootNode) == null ? void 0 : _a.firstChild)) {
|
|
1370
|
+
this.patchEventListener(key, prop);
|
|
891
1371
|
} else if (key === "ref") {
|
|
892
|
-
|
|
893
|
-
} else if (startsWith(key,
|
|
894
|
-
this.
|
|
895
|
-
} else if (key !==
|
|
896
|
-
|
|
897
|
-
track.cleanup = B(() => {
|
|
898
|
-
this.proxyProps[key] = isFunction(prop) ? prop() : prop;
|
|
899
|
-
});
|
|
1372
|
+
this.patchRef(prop);
|
|
1373
|
+
} else if (startsWith(key, UPDATE_PREFIX)) {
|
|
1374
|
+
this.patchUpdateHandler(key, prop);
|
|
1375
|
+
} else if (key !== CHILDREN_PROP) {
|
|
1376
|
+
this.patchNormalProp(key, prop);
|
|
900
1377
|
}
|
|
901
1378
|
}
|
|
902
1379
|
this.props = props;
|
|
903
1380
|
}
|
|
1381
|
+
// Private method to patch event listeners
|
|
1382
|
+
patchEventListener(key, prop) {
|
|
1383
|
+
const event = key.slice(2).toLowerCase();
|
|
1384
|
+
const cleanup = addEventListener(this.rootNode.nodes[0], event, prop);
|
|
1385
|
+
this.emitter.add(cleanup);
|
|
1386
|
+
}
|
|
1387
|
+
// Private method to patch ref
|
|
1388
|
+
patchRef(prop) {
|
|
1389
|
+
var _a, _b;
|
|
1390
|
+
prop.value = (_b = (_a = this.rootNode) == null ? void 0 : _a.firstChild) != null ? _b : null;
|
|
1391
|
+
}
|
|
1392
|
+
// Private method to patch update handlers
|
|
1393
|
+
patchUpdateHandler(key, prop) {
|
|
1394
|
+
this.props[key] = extractSignal(prop);
|
|
1395
|
+
}
|
|
1396
|
+
// Private method to patch normal props
|
|
1397
|
+
patchNormalProp(key, prop) {
|
|
1398
|
+
const track2 = this.getNodeTrack(key);
|
|
1399
|
+
track2.cleanup = useEffect(() => {
|
|
1400
|
+
this.proxyProps[key] = isFunction(prop) ? prop() : prop;
|
|
1401
|
+
});
|
|
1402
|
+
}
|
|
904
1403
|
};
|
|
905
1404
|
function patchChildren(parent, childrenMap, nextChildren, before) {
|
|
906
1405
|
const result = /* @__PURE__ */ new Map();
|
|
@@ -1023,18 +1522,21 @@ var TemplateNode = class {
|
|
|
1023
1522
|
this.componentIndex = getComponentIndex(this.template);
|
|
1024
1523
|
}
|
|
1025
1524
|
}
|
|
1026
|
-
|
|
1027
|
-
}
|
|
1028
|
-
removeEventListener() {
|
|
1029
|
-
}
|
|
1525
|
+
// Getter for the first child node
|
|
1030
1526
|
get firstChild() {
|
|
1031
1527
|
var _a;
|
|
1032
1528
|
return (_a = this.nodes[0]) != null ? _a : null;
|
|
1033
1529
|
}
|
|
1034
|
-
// is
|
|
1530
|
+
// Getter to check if the node is connected to the DOM
|
|
1035
1531
|
get isConnected() {
|
|
1036
1532
|
return this.mounted;
|
|
1037
1533
|
}
|
|
1534
|
+
// Placeholder methods for event handling
|
|
1535
|
+
addEventListener() {
|
|
1536
|
+
}
|
|
1537
|
+
removeEventListener() {
|
|
1538
|
+
}
|
|
1539
|
+
// Method to mount the node to the DOM
|
|
1038
1540
|
mount(parent, before) {
|
|
1039
1541
|
var _a;
|
|
1040
1542
|
this.parent = parent;
|
|
@@ -1064,44 +1566,45 @@ var TemplateNode = class {
|
|
|
1064
1566
|
this.mounted = true;
|
|
1065
1567
|
return this.nodes;
|
|
1066
1568
|
}
|
|
1569
|
+
// Method to unmount the node from the DOM
|
|
1067
1570
|
unmount() {
|
|
1068
1571
|
var _a, _b;
|
|
1069
|
-
this.trackMap.forEach((
|
|
1572
|
+
this.trackMap.forEach((track2) => {
|
|
1070
1573
|
var _a2;
|
|
1071
|
-
(_a2 =
|
|
1574
|
+
(_a2 = track2.cleanup) == null ? void 0 : _a2.call(track2);
|
|
1072
1575
|
});
|
|
1073
1576
|
this.trackMap.clear();
|
|
1074
1577
|
this.treeMap.clear();
|
|
1075
1578
|
this.nodes.forEach((node) => removeChild(node));
|
|
1076
1579
|
if (!this.template.innerHTML && !this.nodes.length) {
|
|
1077
|
-
(
|
|
1078
|
-
|
|
1079
|
-
if (
|
|
1080
|
-
|
|
1081
|
-
|
|
1082
|
-
if (node.nodeType === Node.TEXT_NODE && node.textContent === `${i}`) {
|
|
1083
|
-
(_a3 = this.parent) == null ? void 0 : _a3.removeChild(node);
|
|
1084
|
-
}
|
|
1580
|
+
const children = (_b = (_a = this.props) == null ? void 0 : _a[FRAGMENT_PROP_KEY]) == null ? void 0 : _b.children;
|
|
1581
|
+
if (children) {
|
|
1582
|
+
if (isArray(children)) {
|
|
1583
|
+
children.forEach((child) => {
|
|
1584
|
+
this.deleteFragmentTextNode(child);
|
|
1085
1585
|
});
|
|
1086
1586
|
} else {
|
|
1087
|
-
|
|
1587
|
+
this.deleteFragmentTextNode(children);
|
|
1088
1588
|
}
|
|
1089
|
-
}
|
|
1589
|
+
}
|
|
1090
1590
|
}
|
|
1091
1591
|
this.nodes = [];
|
|
1092
1592
|
this.mounted = false;
|
|
1093
1593
|
}
|
|
1094
|
-
|
|
1095
|
-
|
|
1096
|
-
|
|
1097
|
-
|
|
1098
|
-
|
|
1099
|
-
|
|
1100
|
-
|
|
1101
|
-
|
|
1102
|
-
|
|
1103
|
-
|
|
1594
|
+
deleteFragmentTextNode(child) {
|
|
1595
|
+
var _a;
|
|
1596
|
+
if (isPrimitive(child)) {
|
|
1597
|
+
(_a = this.parent) == null ? void 0 : _a.childNodes.forEach((node) => {
|
|
1598
|
+
var _a2;
|
|
1599
|
+
if (node.nodeType === Node.TEXT_NODE && node.textContent === `${child}`) {
|
|
1600
|
+
(_a2 = this.parent) == null ? void 0 : _a2.removeChild(node);
|
|
1601
|
+
}
|
|
1602
|
+
});
|
|
1603
|
+
} else {
|
|
1604
|
+
removeChild(child);
|
|
1605
|
+
}
|
|
1104
1606
|
}
|
|
1607
|
+
// Method to inherit properties from another TemplateNode
|
|
1105
1608
|
inheritNode(node) {
|
|
1106
1609
|
this.mounted = node.mounted;
|
|
1107
1610
|
this.nodes = node.nodes;
|
|
@@ -1111,194 +1614,205 @@ var TemplateNode = class {
|
|
|
1111
1614
|
this.props = node.props;
|
|
1112
1615
|
this.patchProps(props);
|
|
1113
1616
|
}
|
|
1617
|
+
// Private method to map SSG node tree
|
|
1114
1618
|
mapSSGNodeTree(parent) {
|
|
1115
1619
|
this.treeMap.set(0, parent);
|
|
1116
|
-
|
|
1117
|
-
var _a;
|
|
1118
|
-
if (node.nodeType !== Node.DOCUMENT_FRAGMENT_NODE) {
|
|
1119
|
-
if (node.nodeType === Node.COMMENT_NODE) {
|
|
1120
|
-
const [type, index] = ((_a = node.textContent) == null ? void 0 : _a.split("-")) || "";
|
|
1121
|
-
if (0 === +type && +index === this.componentIndex) {
|
|
1122
|
-
const textNode = node.nextSibling;
|
|
1123
|
-
this.treeMap.set(+index, textNode);
|
|
1124
|
-
}
|
|
1125
|
-
} else if (node.nodeType !== Node.TEXT_NODE) {
|
|
1126
|
-
const { ci = "-1", hk } = (node == null ? void 0 : node.dataset) || {};
|
|
1127
|
-
if (hk && +ci === this.componentIndex) {
|
|
1128
|
-
this.treeMap.set(+hk, node);
|
|
1129
|
-
}
|
|
1130
|
-
}
|
|
1131
|
-
}
|
|
1132
|
-
let child = node.firstChild;
|
|
1133
|
-
while (child) {
|
|
1134
|
-
walk(child);
|
|
1135
|
-
child = child.nextSibling;
|
|
1136
|
-
}
|
|
1137
|
-
};
|
|
1138
|
-
walk(parent);
|
|
1620
|
+
this.walkNodeTree(parent, this.handleSSGNode.bind(this));
|
|
1139
1621
|
}
|
|
1622
|
+
// Private method to map node tree
|
|
1140
1623
|
mapNodeTree(parent, tree) {
|
|
1141
1624
|
let index = 1;
|
|
1142
1625
|
this.treeMap.set(0, parent);
|
|
1143
|
-
const
|
|
1626
|
+
const handleNode = (node) => {
|
|
1144
1627
|
if (node.nodeType !== Node.DOCUMENT_FRAGMENT_NODE) {
|
|
1145
1628
|
this.treeMap.set(index++, node);
|
|
1146
1629
|
}
|
|
1147
|
-
let child = node.firstChild;
|
|
1148
|
-
while (child) {
|
|
1149
|
-
walk(child);
|
|
1150
|
-
child = child.nextSibling;
|
|
1151
|
-
}
|
|
1152
1630
|
};
|
|
1153
|
-
|
|
1631
|
+
this.walkNodeTree(tree, handleNode);
|
|
1154
1632
|
}
|
|
1155
|
-
|
|
1156
|
-
|
|
1157
|
-
|
|
1158
|
-
|
|
1159
|
-
|
|
1160
|
-
|
|
1161
|
-
|
|
1162
|
-
|
|
1163
|
-
|
|
1633
|
+
// Private method to walk through the node tree
|
|
1634
|
+
walkNodeTree(node, handler) {
|
|
1635
|
+
if (node.nodeType !== Node.DOCUMENT_FRAGMENT_NODE) {
|
|
1636
|
+
handler(node);
|
|
1637
|
+
}
|
|
1638
|
+
let child = node.firstChild;
|
|
1639
|
+
while (child) {
|
|
1640
|
+
this.walkNodeTree(child, handler);
|
|
1641
|
+
child = child.nextSibling;
|
|
1642
|
+
}
|
|
1643
|
+
}
|
|
1644
|
+
// Private method to handle SSG nodes
|
|
1645
|
+
handleSSGNode(node) {
|
|
1164
1646
|
var _a;
|
|
1165
|
-
|
|
1166
|
-
|
|
1167
|
-
|
|
1168
|
-
|
|
1169
|
-
|
|
1170
|
-
track.lastNodes = /* @__PURE__ */ new Map();
|
|
1647
|
+
if (node.nodeType === Node.COMMENT_NODE) {
|
|
1648
|
+
const [type, index] = ((_a = node.textContent) == null ? void 0 : _a.split("-")) || [];
|
|
1649
|
+
if (0 === +type && +index === this.componentIndex) {
|
|
1650
|
+
const textNode = node.nextSibling;
|
|
1651
|
+
this.treeMap.set(+index, textNode);
|
|
1171
1652
|
}
|
|
1172
|
-
|
|
1173
|
-
|
|
1653
|
+
} else if (node.nodeType !== Node.TEXT_NODE) {
|
|
1654
|
+
const { ci = "-1", hk } = (node == null ? void 0 : node.dataset) || {};
|
|
1655
|
+
if (hk && +ci === this.componentIndex) {
|
|
1656
|
+
this.treeMap.set(+hk, node);
|
|
1174
1657
|
}
|
|
1175
|
-
this.trackMap.set(trackKey, track);
|
|
1176
1658
|
}
|
|
1177
|
-
(_a = track.cleanup) == null ? void 0 : _a.call(track);
|
|
1178
|
-
return track;
|
|
1179
1659
|
}
|
|
1660
|
+
// Method to patch props onto the node
|
|
1661
|
+
patchProps(props) {
|
|
1662
|
+
if (!props) return;
|
|
1663
|
+
Object.entries(props).forEach(([key, value]) => {
|
|
1664
|
+
const index = Number(key);
|
|
1665
|
+
const node = this.treeMap.get(index);
|
|
1666
|
+
if (node) {
|
|
1667
|
+
this.patchProp(key, node, value, index === 0);
|
|
1668
|
+
}
|
|
1669
|
+
});
|
|
1670
|
+
this.props = props;
|
|
1671
|
+
}
|
|
1672
|
+
// Private method to patch a single prop
|
|
1180
1673
|
patchProp(key, node, props, isRoot) {
|
|
1181
|
-
|
|
1182
|
-
|
|
1183
|
-
|
|
1184
|
-
|
|
1185
|
-
const track = this.getNodeTrack(trackKey, true, isRoot);
|
|
1186
|
-
patchChild(track, node, props.children, null);
|
|
1187
|
-
} else {
|
|
1188
|
-
props.children.filter(Boolean).forEach((item, index) => {
|
|
1189
|
-
var _a;
|
|
1190
|
-
const [child, path] = isArray(item) ? item : [item, null];
|
|
1191
|
-
const before = isNil(path) ? null : (_a = this.treeMap.get(path)) != null ? _a : null;
|
|
1192
|
-
const trackKey = `${key}:${attr}:${index}`;
|
|
1193
|
-
const track = this.getNodeTrack(trackKey, true, isRoot);
|
|
1194
|
-
patchChild(track, node, child, before);
|
|
1195
|
-
});
|
|
1196
|
-
}
|
|
1674
|
+
if (!props) return;
|
|
1675
|
+
Object.entries(props).forEach(([attr, value]) => {
|
|
1676
|
+
if (attr === CHILDREN_PROP && value) {
|
|
1677
|
+
this.patchChildren(key, node, value, isRoot);
|
|
1197
1678
|
} else if (attr === "ref") {
|
|
1198
1679
|
props[attr].value = node;
|
|
1199
1680
|
} else if (startsWith(attr, "on")) {
|
|
1200
|
-
|
|
1201
|
-
const track = this.getNodeTrack(`${key}:${attr}`);
|
|
1202
|
-
const listener = props[attr];
|
|
1203
|
-
track.cleanup = addEventListener(node, eventName, listener);
|
|
1681
|
+
this.patchEventListener(key, node, attr, value);
|
|
1204
1682
|
} else {
|
|
1205
|
-
|
|
1206
|
-
if (this.bindValueKeys.includes(attr)) {
|
|
1207
|
-
break;
|
|
1208
|
-
}
|
|
1209
|
-
if (props[updateKey]) {
|
|
1210
|
-
this.bindValueKeys.push(updateKey);
|
|
1211
|
-
}
|
|
1212
|
-
const track = this.getNodeTrack(`${key}:${attr}`);
|
|
1213
|
-
const val = props[attr];
|
|
1214
|
-
const triggerValue = h(val) ? val : le(val);
|
|
1215
|
-
patchAttribute(track, node, attr, triggerValue.value);
|
|
1216
|
-
const cleanup = B(() => {
|
|
1217
|
-
triggerValue.value = h(val) ? val.value : val;
|
|
1218
|
-
patchAttribute(track, node, attr, triggerValue.value);
|
|
1219
|
-
});
|
|
1220
|
-
let cleanupBind;
|
|
1221
|
-
if (props[updateKey] && !isComponent(attr)) {
|
|
1222
|
-
cleanupBind = bindNode(node, (value) => {
|
|
1223
|
-
props[updateKey](value);
|
|
1224
|
-
});
|
|
1225
|
-
}
|
|
1226
|
-
track.cleanup = () => {
|
|
1227
|
-
cleanup && cleanup();
|
|
1228
|
-
cleanupBind && cleanupBind();
|
|
1229
|
-
};
|
|
1683
|
+
this.patchAttribute(key, node, attr, value);
|
|
1230
1684
|
}
|
|
1685
|
+
});
|
|
1686
|
+
}
|
|
1687
|
+
// Private method to patch children
|
|
1688
|
+
patchChildren(key, node, children, isRoot) {
|
|
1689
|
+
if (!isArray(children)) {
|
|
1690
|
+
const trackKey = `${key}:${CHILDREN_PROP}:0`;
|
|
1691
|
+
const track2 = this.getNodeTrack(trackKey, true, isRoot);
|
|
1692
|
+
this.patchChild(track2, node, children, null);
|
|
1693
|
+
} else {
|
|
1694
|
+
children.filter(Boolean).forEach((item, index) => {
|
|
1695
|
+
var _a;
|
|
1696
|
+
const [child, path] = isArray(item) ? item : [item, null];
|
|
1697
|
+
const before = isNil(path) ? null : (_a = this.treeMap.get(path)) != null ? _a : null;
|
|
1698
|
+
const trackKey = `${key}:${CHILDREN_PROP}:${index}`;
|
|
1699
|
+
const track2 = this.getNodeTrack(trackKey, true, isRoot);
|
|
1700
|
+
this.patchChild(track2, node, child, before);
|
|
1701
|
+
});
|
|
1231
1702
|
}
|
|
1232
1703
|
}
|
|
1233
|
-
|
|
1234
|
-
|
|
1235
|
-
|
|
1236
|
-
|
|
1237
|
-
|
|
1238
|
-
|
|
1239
|
-
|
|
1240
|
-
|
|
1241
|
-
|
|
1242
|
-
|
|
1243
|
-
|
|
1244
|
-
|
|
1245
|
-
|
|
1246
|
-
|
|
1247
|
-
|
|
1248
|
-
|
|
1249
|
-
|
|
1250
|
-
|
|
1251
|
-
|
|
1252
|
-
|
|
1253
|
-
|
|
1704
|
+
// Private method to patch event listeners
|
|
1705
|
+
patchEventListener(key, node, attr, listener) {
|
|
1706
|
+
const eventName = attr.slice(2).toLowerCase();
|
|
1707
|
+
const track2 = this.getNodeTrack(`${key}:${attr}`);
|
|
1708
|
+
track2.cleanup = addEventListener(node, eventName, listener);
|
|
1709
|
+
}
|
|
1710
|
+
// Private method to patch attributes
|
|
1711
|
+
patchAttribute(key, element, attr, value) {
|
|
1712
|
+
var _a, _b;
|
|
1713
|
+
const updateKey = `update${capitalizeFirstLetter(attr)}`;
|
|
1714
|
+
if (this.bindValueKeys.includes(attr)) {
|
|
1715
|
+
return;
|
|
1716
|
+
}
|
|
1717
|
+
if ((_a = this.props) == null ? void 0 : _a[updateKey]) {
|
|
1718
|
+
this.bindValueKeys.push(updateKey);
|
|
1719
|
+
}
|
|
1720
|
+
const track2 = this.getNodeTrack(`${key}:${attr}`);
|
|
1721
|
+
const triggerValue = isSignal(value) ? value : useSignal(value);
|
|
1722
|
+
setAttribute(element, attr, triggerValue.value);
|
|
1723
|
+
const cleanup = useEffect(() => {
|
|
1724
|
+
triggerValue.value = isSignal(value) ? value.value : value;
|
|
1725
|
+
setAttribute(element, attr, triggerValue.value);
|
|
1254
1726
|
});
|
|
1727
|
+
let cleanupBind;
|
|
1728
|
+
if (((_b = this.props) == null ? void 0 : _b[updateKey]) && !isComponent(attr)) {
|
|
1729
|
+
cleanupBind = bindNode(element, (value2) => {
|
|
1730
|
+
var _a2;
|
|
1731
|
+
(_a2 = this.props) == null ? void 0 : _a2[updateKey](value2);
|
|
1732
|
+
});
|
|
1733
|
+
}
|
|
1734
|
+
track2.cleanup = () => {
|
|
1735
|
+
cleanup && cleanup();
|
|
1736
|
+
cleanupBind && cleanupBind();
|
|
1737
|
+
};
|
|
1255
1738
|
}
|
|
1256
|
-
|
|
1257
|
-
|
|
1258
|
-
|
|
1259
|
-
|
|
1260
|
-
(
|
|
1261
|
-
|
|
1262
|
-
|
|
1263
|
-
|
|
1264
|
-
|
|
1265
|
-
|
|
1266
|
-
|
|
1267
|
-
|
|
1268
|
-
|
|
1269
|
-
|
|
1270
|
-
|
|
1739
|
+
// Private method to get or create a NodeTrack
|
|
1740
|
+
getNodeTrack(trackKey, trackLastNodes, isRoot) {
|
|
1741
|
+
var _a;
|
|
1742
|
+
let track2 = this.trackMap.get(trackKey);
|
|
1743
|
+
if (!track2) {
|
|
1744
|
+
track2 = { cleanup: () => {
|
|
1745
|
+
} };
|
|
1746
|
+
if (trackLastNodes) {
|
|
1747
|
+
track2.lastNodes = /* @__PURE__ */ new Map();
|
|
1748
|
+
}
|
|
1749
|
+
if (isRoot) {
|
|
1750
|
+
track2.isRoot = true;
|
|
1751
|
+
}
|
|
1752
|
+
this.trackMap.set(trackKey, track2);
|
|
1753
|
+
}
|
|
1754
|
+
(_a = track2.cleanup) == null ? void 0 : _a.call(track2);
|
|
1755
|
+
return track2;
|
|
1756
|
+
}
|
|
1757
|
+
// Private method to patch a child node
|
|
1758
|
+
patchChild(track2, parent, child, before) {
|
|
1759
|
+
if (isFunction(child)) {
|
|
1760
|
+
track2.cleanup = useEffect(() => {
|
|
1761
|
+
const nextNodes = coerceArray(child()).map(coerceNode);
|
|
1762
|
+
if (renderContext.isSSR) {
|
|
1763
|
+
track2.lastNodes = this.reconcileChildren(parent, nextNodes, before);
|
|
1764
|
+
} else {
|
|
1765
|
+
track2.lastNodes = patchChildren(parent, track2.lastNodes, nextNodes, before);
|
|
1271
1766
|
}
|
|
1272
1767
|
});
|
|
1273
1768
|
} else {
|
|
1274
|
-
|
|
1769
|
+
coerceArray(child).forEach((node, index) => {
|
|
1770
|
+
const newNode = coerceNode(node);
|
|
1771
|
+
const key = getKey(newNode, index);
|
|
1772
|
+
if (renderContext.isSSR) {
|
|
1773
|
+
track2.lastNodes = this.reconcileChildren(parent, [newNode], before);
|
|
1774
|
+
} else {
|
|
1775
|
+
track2.lastNodes.set(key, newNode);
|
|
1776
|
+
insertChild(parent, newNode, before);
|
|
1777
|
+
}
|
|
1778
|
+
});
|
|
1275
1779
|
}
|
|
1276
|
-
result.set(key, node);
|
|
1277
|
-
});
|
|
1278
|
-
return result;
|
|
1279
|
-
}
|
|
1280
|
-
function patchAttribute(track, node, attr, data) {
|
|
1281
|
-
const element = node;
|
|
1282
|
-
if (!element.setAttribute) {
|
|
1283
|
-
return;
|
|
1284
1780
|
}
|
|
1285
|
-
|
|
1286
|
-
|
|
1287
|
-
|
|
1781
|
+
// Private method to reconcile children nodes
|
|
1782
|
+
reconcileChildren(parent, nextNodes, before) {
|
|
1783
|
+
const result = /* @__PURE__ */ new Map();
|
|
1784
|
+
const textNodes = Array.from(parent.childNodes).filter(
|
|
1785
|
+
(node) => {
|
|
1786
|
+
var _a, _b;
|
|
1787
|
+
return node.nodeType === Node.TEXT_NODE && ((_a = node.previousSibling) == null ? void 0 : _a.nodeType) === Node.COMMENT_NODE && ((_b = node.nextSibling) == null ? void 0 : _b.nodeType) === Node.COMMENT_NODE;
|
|
1788
|
+
}
|
|
1789
|
+
);
|
|
1790
|
+
nextNodes.forEach((node, index) => {
|
|
1791
|
+
const key = getKey(node, index);
|
|
1792
|
+
if (node.nodeType === Node.TEXT_NODE) {
|
|
1793
|
+
textNodes.forEach((ne) => {
|
|
1794
|
+
if (node.textContent === ne.textContent) {
|
|
1795
|
+
parent.replaceChild(node, ne);
|
|
1796
|
+
}
|
|
1797
|
+
});
|
|
1798
|
+
} else {
|
|
1799
|
+
insertChild(parent, node, before);
|
|
1800
|
+
}
|
|
1801
|
+
result.set(key, node);
|
|
1288
1802
|
});
|
|
1289
|
-
|
|
1290
|
-
setAttribute(element, attr, data);
|
|
1803
|
+
return result;
|
|
1291
1804
|
}
|
|
1292
|
-
}
|
|
1293
|
-
function
|
|
1805
|
+
};
|
|
1806
|
+
function h(template, props, key) {
|
|
1294
1807
|
if (isString(template)) {
|
|
1295
1808
|
if (isHtmlTagName(template)) {
|
|
1296
|
-
|
|
1297
|
-
props = {
|
|
1298
|
-
|
|
1299
|
-
|
|
1809
|
+
const htmlTemplate = convertToHtmlTag(template);
|
|
1810
|
+
props = { [SINGLE_PROP_KEY]: props };
|
|
1811
|
+
return new TemplateNode(createTemplate(htmlTemplate), props, key);
|
|
1812
|
+
} else if (template === EMPTY_TEMPLATE) {
|
|
1813
|
+
props = { [FRAGMENT_PROP_KEY]: props };
|
|
1814
|
+
return new TemplateNode(createTemplate(EMPTY_TEMPLATE), props, key);
|
|
1300
1815
|
}
|
|
1301
|
-
template = createTemplate(template);
|
|
1302
1816
|
}
|
|
1303
1817
|
return isFunction(template) ? new ComponentNode(template, props, key) : new TemplateNode(template, props, key);
|
|
1304
1818
|
}
|
|
@@ -1314,19 +1828,17 @@ function createTemplate(html) {
|
|
|
1314
1828
|
return template;
|
|
1315
1829
|
}
|
|
1316
1830
|
function Fragment(props) {
|
|
1317
|
-
return
|
|
1318
|
-
children:
|
|
1831
|
+
return h(EMPTY_TEMPLATE, {
|
|
1832
|
+
children: isArray(props.children) ? props.children.filter(Boolean) : [props.children]
|
|
1319
1833
|
});
|
|
1320
1834
|
}
|
|
1321
1835
|
function onMount(cb) {
|
|
1322
|
-
var _a;
|
|
1323
1836
|
assertInsideComponent("onMounted");
|
|
1324
|
-
|
|
1837
|
+
LifecycleContext.ref && LifecycleContext.ref.addHook("mounted", cb);
|
|
1325
1838
|
}
|
|
1326
1839
|
function onDestroy(cb) {
|
|
1327
|
-
var _a;
|
|
1328
1840
|
assertInsideComponent("onDestroy");
|
|
1329
|
-
|
|
1841
|
+
LifecycleContext.ref && LifecycleContext.ref.addHook("destroy", cb);
|
|
1330
1842
|
}
|
|
1331
1843
|
function assertInsideComponent(hookName, key) {
|
|
1332
1844
|
if (!LifecycleContext.ref && true) {
|
|
@@ -1337,18 +1849,16 @@ function assertInsideComponent(hookName, key) {
|
|
|
1337
1849
|
}
|
|
1338
1850
|
}
|
|
1339
1851
|
function useProvide(key, value) {
|
|
1340
|
-
var _a;
|
|
1341
1852
|
assertInsideComponent("useProvide", key);
|
|
1342
|
-
|
|
1853
|
+
LifecycleContext.ref && LifecycleContext.ref.setContext(key, value);
|
|
1343
1854
|
}
|
|
1344
1855
|
function useInject(key, defaultValue) {
|
|
1345
1856
|
var _a;
|
|
1346
1857
|
assertInsideComponent("useInject", key);
|
|
1347
|
-
return (
|
|
1858
|
+
return (_a = LifecycleContext.ref && LifecycleContext.ref.getContext(key)) != null ? _a : defaultValue;
|
|
1348
1859
|
}
|
|
1349
1860
|
function useRef() {
|
|
1350
|
-
|
|
1351
|
-
return ref;
|
|
1861
|
+
return shallowSignal(null);
|
|
1352
1862
|
}
|
|
1353
1863
|
function renderToString(component, props) {
|
|
1354
1864
|
renderContext.setSSG();
|
|
@@ -1363,14 +1873,14 @@ function hydrate(component, container) {
|
|
|
1363
1873
|
throw new Error(`Could not find container: ${container}`);
|
|
1364
1874
|
}
|
|
1365
1875
|
renderContext.setSSR();
|
|
1366
|
-
|
|
1876
|
+
h(component).mount(rootElement);
|
|
1367
1877
|
renderContext.setClient();
|
|
1368
1878
|
}
|
|
1369
1879
|
function ssg(component, props) {
|
|
1370
1880
|
if (renderContext.isSSG) {
|
|
1371
1881
|
return new SSGNode(component, props);
|
|
1372
1882
|
}
|
|
1373
|
-
return
|
|
1883
|
+
return h(component, props);
|
|
1374
1884
|
}
|
|
1375
1885
|
|
|
1376
1886
|
// src/index.ts
|
|
@@ -1378,14 +1888,14 @@ if (globalThis) {
|
|
|
1378
1888
|
globalThis.__essor_version__ = essor_version;
|
|
1379
1889
|
}
|
|
1380
1890
|
/**
|
|
1381
|
-
* @estjs/signal v0.0.13
|
|
1891
|
+
* @estjs/signal v0.0.13
|
|
1382
1892
|
* (c) 2023-Present jiangxd <jiangxd2016@gmail.com>
|
|
1383
1893
|
* @license MIT
|
|
1384
1894
|
**/
|
|
1385
1895
|
/**
|
|
1386
|
-
* @estjs/template v0.0.13
|
|
1896
|
+
* @estjs/template v0.0.13
|
|
1387
1897
|
* (c) 2023-Present jiangxd <jiangxd2016@gmail.com>
|
|
1388
1898
|
* @license MIT
|
|
1389
1899
|
**/
|
|
1390
1900
|
|
|
1391
|
-
export { Fragment,
|
|
1901
|
+
export { Fragment, clearReactive, createStore, essor_version, h, hydrate, isComponent, isComputed, isJsxElement, isReactive, isSignal, onDestroy, onMount, renderToString, shallowReactive, shallowSignal, signalObject, ssg, createTemplate as template, toRaw, useBatch, useComputed, useEffect, useInject, useProvide, useReactive, useRef, useShallowSignal, useSignal, useWatch };
|