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