essor 0.0.6-beta.2 → 0.0.6-beta.3
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 +26 -25
- package/dist/essor.cjs.js.map +1 -1
- package/dist/essor.d.cts +28 -13
- package/dist/essor.d.ts +28 -13
- package/dist/essor.dev.cjs.js +59 -52
- package/dist/essor.dev.esm.js +59 -53
- package/dist/essor.esm.js +3 -3
- package/dist/essor.esm.js.map +1 -1
- package/package.json +2 -2
- package/types/jsx.d.ts +1 -1
package/dist/essor.dev.cjs.js
CHANGED
|
@@ -16,6 +16,7 @@ var __spreadValues = (a, b) => {
|
|
|
16
16
|
}
|
|
17
17
|
return a;
|
|
18
18
|
};
|
|
19
|
+
var isFunction = (val) => typeof val === "function";
|
|
19
20
|
|
|
20
21
|
// src/signal/signal.ts
|
|
21
22
|
var activeEffect = null;
|
|
@@ -137,21 +138,28 @@ function useEffect(fn) {
|
|
|
137
138
|
activeEffect = null;
|
|
138
139
|
};
|
|
139
140
|
}
|
|
140
|
-
function
|
|
141
|
+
function shouldExclude(key, exclude) {
|
|
142
|
+
return Array.isArray(exclude) ? exclude.includes(key) : isFunction(exclude) ? exclude(key) : false;
|
|
143
|
+
}
|
|
144
|
+
function signalObject(initialValues, exclude) {
|
|
141
145
|
const signals = Object.entries(initialValues).reduce((acc, [key, value]) => {
|
|
142
|
-
acc[key] = isSignal(value) ? value : useSignal(value);
|
|
146
|
+
acc[key] = shouldExclude(key, exclude) || isSignal(value) ? value : useSignal(value);
|
|
143
147
|
return acc;
|
|
144
148
|
}, {});
|
|
145
149
|
return signals;
|
|
146
150
|
}
|
|
147
|
-
function
|
|
151
|
+
function unSignal(signal, exclude) {
|
|
148
152
|
if (!signal)
|
|
149
153
|
return {};
|
|
150
154
|
if (isSignal(signal)) {
|
|
151
155
|
return signal.peek();
|
|
152
156
|
}
|
|
153
157
|
return Object.entries(signal).reduce((acc, [key, value]) => {
|
|
154
|
-
|
|
158
|
+
if (shouldExclude(key, exclude)) {
|
|
159
|
+
acc[key] = value;
|
|
160
|
+
} else {
|
|
161
|
+
acc[key] = isSignal(value) ? value.peek() : value;
|
|
162
|
+
}
|
|
155
163
|
return acc;
|
|
156
164
|
}, {});
|
|
157
165
|
}
|
|
@@ -168,8 +176,8 @@ function createOptionsStore(options) {
|
|
|
168
176
|
const default_actions = {
|
|
169
177
|
patch$(payload) {
|
|
170
178
|
Object.assign(signalState, signalObject(payload));
|
|
171
|
-
subscriptions.forEach((callback) => callback(
|
|
172
|
-
actionCallbacks.forEach((callback) => callback(
|
|
179
|
+
subscriptions.forEach((callback) => callback(unSignal(signalState)));
|
|
180
|
+
actionCallbacks.forEach((callback) => callback(unSignal(signalState)));
|
|
173
181
|
},
|
|
174
182
|
subscribe$(callback) {
|
|
175
183
|
subscriptions.push(callback);
|
|
@@ -211,7 +219,7 @@ function createOptionsStore(options) {
|
|
|
211
219
|
{
|
|
212
220
|
get(_, key) {
|
|
213
221
|
if (key === "state") {
|
|
214
|
-
return
|
|
222
|
+
return unSignal(signalState);
|
|
215
223
|
}
|
|
216
224
|
if (key in states) {
|
|
217
225
|
return states[key];
|
|
@@ -237,13 +245,16 @@ function createStore(options) {
|
|
|
237
245
|
function coerceArray(data) {
|
|
238
246
|
return Array.isArray(data) ? data.flat() : [data];
|
|
239
247
|
}
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
248
|
+
function startsWith(str, searchString) {
|
|
249
|
+
return str.indexOf(searchString) === 0;
|
|
250
|
+
}
|
|
251
|
+
var isObject2 = (val) => val !== null && typeof val === "object";
|
|
252
|
+
var isArray2 = Array.isArray;
|
|
253
|
+
function isNil2(x) {
|
|
243
254
|
return x === null || x === void 0;
|
|
244
255
|
}
|
|
245
|
-
var
|
|
246
|
-
function
|
|
256
|
+
var isFunction2 = (val) => typeof val === "function";
|
|
257
|
+
function isFalsy2(x) {
|
|
247
258
|
return x === false || x === null || x === void 0 || x === "";
|
|
248
259
|
}
|
|
249
260
|
var kebabCase = (string) => {
|
|
@@ -268,7 +279,10 @@ var _ComponentNode = class _ComponentNode {
|
|
|
268
279
|
destroy: /* @__PURE__ */ new Set()
|
|
269
280
|
};
|
|
270
281
|
this.trackMap = /* @__PURE__ */ new Map();
|
|
271
|
-
this.proxyProps = signalObject(
|
|
282
|
+
this.proxyProps = signalObject(
|
|
283
|
+
props,
|
|
284
|
+
(key2) => startsWith(key2, "on") || startsWith(key2, "update:")
|
|
285
|
+
);
|
|
272
286
|
}
|
|
273
287
|
addEventListener() {
|
|
274
288
|
}
|
|
@@ -315,7 +329,7 @@ var _ComponentNode = class _ComponentNode {
|
|
|
315
329
|
}
|
|
316
330
|
mount(parent, before) {
|
|
317
331
|
var _a, _b, _c, _d;
|
|
318
|
-
if (!
|
|
332
|
+
if (!isFunction2(this.template)) {
|
|
319
333
|
throw new Error("Template must be a function");
|
|
320
334
|
}
|
|
321
335
|
if (this.isConnected) {
|
|
@@ -345,19 +359,19 @@ var _ComponentNode = class _ComponentNode {
|
|
|
345
359
|
patchProps(props) {
|
|
346
360
|
var _a, _b, _c, _d, _e;
|
|
347
361
|
for (const [key, prop] of Object.entries(props)) {
|
|
348
|
-
if (key
|
|
362
|
+
if (startsWith(key, "on") && ((_a = this.rootNode) == null ? void 0 : _a.nodes)) {
|
|
349
363
|
const event = key.slice(2).toLowerCase();
|
|
350
364
|
const listener = prop;
|
|
351
365
|
const cleanup = addEventListener(this.rootNode.nodes[0], event, listener);
|
|
352
366
|
this.emitter.add(cleanup);
|
|
353
|
-
} else if (key.indexOf("bind:") === 0) {
|
|
354
|
-
this.proxyProps[key] = useSignal(prop);
|
|
355
367
|
} else if (key === "ref") {
|
|
356
368
|
if (isSignal(prop)) {
|
|
357
369
|
props[key].value = (_b = this.rootNode) == null ? void 0 : _b.nodes[0];
|
|
358
|
-
} else {
|
|
359
|
-
props[key]
|
|
370
|
+
} else if (isFunction2(prop)) {
|
|
371
|
+
props[key]((_c = this.rootNode) == null ? void 0 : _c.nodes[0]);
|
|
360
372
|
}
|
|
373
|
+
} else if (startsWith(key, "update:")) {
|
|
374
|
+
props[key] = isSignal(prop) ? prop.value : prop;
|
|
361
375
|
} else {
|
|
362
376
|
const newValue = (_e = (_d = this.proxyProps)[key]) != null ? _e : _d[key] = useSignal(prop);
|
|
363
377
|
const track2 = this.getNodeTrack(key);
|
|
@@ -375,7 +389,7 @@ var ComponentNode = _ComponentNode;
|
|
|
375
389
|
|
|
376
390
|
// src/template/template.ts
|
|
377
391
|
function h(template2, props, key) {
|
|
378
|
-
return
|
|
392
|
+
return isFunction2(template2) ? new ComponentNode(template2, props, key) : new TemplateNode(template2, props, key);
|
|
379
393
|
}
|
|
380
394
|
function isJsxElement(node) {
|
|
381
395
|
return node instanceof ComponentNode || node instanceof TemplateNode;
|
|
@@ -394,7 +408,7 @@ function coerceNode(data) {
|
|
|
394
408
|
if (isJsxElement(data) || data instanceof Node) {
|
|
395
409
|
return data;
|
|
396
410
|
}
|
|
397
|
-
const text =
|
|
411
|
+
const text = isFalsy2(data) ? "" : String(data);
|
|
398
412
|
return document.createTextNode(text);
|
|
399
413
|
}
|
|
400
414
|
function insertChild(parent, child, before = null) {
|
|
@@ -443,7 +457,7 @@ function setAttribute(element, attr, value) {
|
|
|
443
457
|
}
|
|
444
458
|
return;
|
|
445
459
|
}
|
|
446
|
-
if (
|
|
460
|
+
if (isFalsy2(value)) {
|
|
447
461
|
element.removeAttribute(attr);
|
|
448
462
|
} else if (value === true) {
|
|
449
463
|
element.setAttribute(attr, "");
|
|
@@ -725,7 +739,7 @@ var TemplateNode = class _TemplateNode {
|
|
|
725
739
|
patchNode(key, node, props, isRoot) {
|
|
726
740
|
for (const attr in props) {
|
|
727
741
|
if (attr === "children" && props.children) {
|
|
728
|
-
if (!
|
|
742
|
+
if (!isArray2(props.children)) {
|
|
729
743
|
const trackKey = `${key}:${attr}:${0}`;
|
|
730
744
|
const track2 = this.getNodeTrack(trackKey, true, isRoot);
|
|
731
745
|
patchChild(track2, node, props.children, null);
|
|
@@ -735,8 +749,8 @@ var TemplateNode = class _TemplateNode {
|
|
|
735
749
|
if (!item) {
|
|
736
750
|
return;
|
|
737
751
|
}
|
|
738
|
-
const [child, path] =
|
|
739
|
-
const before =
|
|
752
|
+
const [child, path] = isArray2(item) ? item : [item, null];
|
|
753
|
+
const before = isNil2(path) ? null : (_a = this.treeMap.get(path)) != null ? _a : null;
|
|
740
754
|
const trackKey = `${key}:${attr}:${index}`;
|
|
741
755
|
const track2 = this.getNodeTrack(trackKey, true, isRoot);
|
|
742
756
|
patchChild(track2, node, child, before);
|
|
@@ -745,31 +759,15 @@ var TemplateNode = class _TemplateNode {
|
|
|
745
759
|
} else if (attr === "ref") {
|
|
746
760
|
if (isSignal(props[attr])) {
|
|
747
761
|
props[attr].value = node;
|
|
748
|
-
} else {
|
|
749
|
-
props[attr]
|
|
762
|
+
} else if (isFunction2(props[attr])) {
|
|
763
|
+
props[attr](node);
|
|
750
764
|
}
|
|
751
|
-
} else if (attr
|
|
765
|
+
} else if (startsWith(attr, "on")) {
|
|
752
766
|
const eventName = attr.slice(2).toLocaleLowerCase();
|
|
753
767
|
const track2 = this.getNodeTrack(`${key}:${attr}`);
|
|
754
768
|
const listener = props[attr];
|
|
755
769
|
track2.cleanup = addEventListener(node, eventName, listener);
|
|
756
|
-
} else if (attr
|
|
757
|
-
const bindKey = attr.slice(5).toLocaleLowerCase();
|
|
758
|
-
const val = props[attr];
|
|
759
|
-
const track2 = this.getNodeTrack(`${key}:${attr}`);
|
|
760
|
-
const triggerValue = isSignal(val) ? val : useSignal(val);
|
|
761
|
-
const cleanup = useEffect(() => {
|
|
762
|
-
triggerValue.value = isSignal(val) ? val.value : val;
|
|
763
|
-
node[bindKey] = triggerValue.value;
|
|
764
|
-
});
|
|
765
|
-
const cleanupBind = binNode(node, (value) => {
|
|
766
|
-
props[`update:${bindKey}`](value);
|
|
767
|
-
});
|
|
768
|
-
track2.cleanup = () => {
|
|
769
|
-
cleanup == null ? void 0 : cleanup();
|
|
770
|
-
cleanupBind == null ? void 0 : cleanupBind();
|
|
771
|
-
};
|
|
772
|
-
} else if (attr.indexOf("update:") !== 0) {
|
|
770
|
+
} else if (!startsWith(attr, "update:")) {
|
|
773
771
|
const track2 = this.getNodeTrack(`${key}:${attr}`);
|
|
774
772
|
const val = props[attr];
|
|
775
773
|
const triggerValue = isSignal(val) ? val : useSignal(val);
|
|
@@ -777,8 +775,16 @@ var TemplateNode = class _TemplateNode {
|
|
|
777
775
|
triggerValue.value = isSignal(val) ? val.value : val;
|
|
778
776
|
patchAttribute(track2, node, attr, triggerValue.value);
|
|
779
777
|
});
|
|
778
|
+
let cleanupBind;
|
|
779
|
+
const updateKey = `update:${attr}`;
|
|
780
|
+
if (props[updateKey]) {
|
|
781
|
+
cleanupBind = binNode(node, (value) => {
|
|
782
|
+
props[updateKey](value);
|
|
783
|
+
});
|
|
784
|
+
}
|
|
780
785
|
track2.cleanup = () => {
|
|
781
|
-
cleanup
|
|
786
|
+
cleanup && cleanup();
|
|
787
|
+
cleanupBind && cleanupBind();
|
|
782
788
|
};
|
|
783
789
|
}
|
|
784
790
|
}
|
|
@@ -789,7 +795,7 @@ function patchAttribute(track2, node, attr, data) {
|
|
|
789
795
|
if (!element.setAttribute) {
|
|
790
796
|
return;
|
|
791
797
|
}
|
|
792
|
-
if (
|
|
798
|
+
if (isFunction2(data)) {
|
|
793
799
|
track2.cleanup = useEffect(() => {
|
|
794
800
|
setAttribute(element, attr, data());
|
|
795
801
|
});
|
|
@@ -798,7 +804,7 @@ function patchAttribute(track2, node, attr, data) {
|
|
|
798
804
|
}
|
|
799
805
|
}
|
|
800
806
|
function patchChild(track2, parent, child, before) {
|
|
801
|
-
if (
|
|
807
|
+
if (isFunction2(child)) {
|
|
802
808
|
track2.cleanup = useEffect(() => {
|
|
803
809
|
const nextNodes = coerceArray(child()).map(coerceNode);
|
|
804
810
|
track2.lastNodes = patchChildren(parent, track2.lastNodes, nextNodes, before);
|
|
@@ -862,7 +868,7 @@ function useRef() {
|
|
|
862
868
|
}
|
|
863
869
|
|
|
864
870
|
// src/version.ts
|
|
865
|
-
var __essor_version = "0.0.6-beta.
|
|
871
|
+
var __essor_version = "0.0.6-beta.2";
|
|
866
872
|
|
|
867
873
|
// src/server/index.ts
|
|
868
874
|
function ssrtmpl(templates = []) {
|
|
@@ -875,17 +881,17 @@ function jsonToAttrs(json) {
|
|
|
875
881
|
return Object.entries(json).map(([key, value]) => `${key}=${JSON.stringify(value)}`).join(" ");
|
|
876
882
|
}
|
|
877
883
|
function ssr(template2, props) {
|
|
878
|
-
if (
|
|
884
|
+
if (isFunction2(template2)) {
|
|
879
885
|
return template2(props);
|
|
880
886
|
}
|
|
881
887
|
const childrenMap = {};
|
|
882
888
|
const newTemplate = {};
|
|
883
|
-
if (
|
|
889
|
+
if (isObject2(template2)) {
|
|
884
890
|
Object.entries(template2).forEach(([key, tmpl]) => {
|
|
885
891
|
const prop = props[key];
|
|
886
892
|
if (prop) {
|
|
887
893
|
Object.keys(prop).forEach((propKey) => {
|
|
888
|
-
if (
|
|
894
|
+
if (startsWith(propKey, "on") && isFunction2(prop[propKey])) {
|
|
889
895
|
delete prop[propKey];
|
|
890
896
|
}
|
|
891
897
|
});
|
|
@@ -936,6 +942,7 @@ exports.signalObject = signalObject;
|
|
|
936
942
|
exports.ssr = ssr;
|
|
937
943
|
exports.ssrtmpl = ssrtmpl;
|
|
938
944
|
exports.template = template;
|
|
945
|
+
exports.unSignal = unSignal;
|
|
939
946
|
exports.useComputed = useComputed;
|
|
940
947
|
exports.useEffect = useEffect;
|
|
941
948
|
exports.useInject = useInject;
|
package/dist/essor.dev.esm.js
CHANGED
|
@@ -14,6 +14,7 @@ var __spreadValues = (a, b) => {
|
|
|
14
14
|
}
|
|
15
15
|
return a;
|
|
16
16
|
};
|
|
17
|
+
var isFunction = (val) => typeof val === "function";
|
|
17
18
|
|
|
18
19
|
// src/signal/signal.ts
|
|
19
20
|
var activeEffect = null;
|
|
@@ -135,21 +136,28 @@ function useEffect(fn) {
|
|
|
135
136
|
activeEffect = null;
|
|
136
137
|
};
|
|
137
138
|
}
|
|
138
|
-
function
|
|
139
|
+
function shouldExclude(key, exclude) {
|
|
140
|
+
return Array.isArray(exclude) ? exclude.includes(key) : isFunction(exclude) ? exclude(key) : false;
|
|
141
|
+
}
|
|
142
|
+
function signalObject(initialValues, exclude) {
|
|
139
143
|
const signals = Object.entries(initialValues).reduce((acc, [key, value]) => {
|
|
140
|
-
acc[key] = isSignal(value) ? value : useSignal(value);
|
|
144
|
+
acc[key] = shouldExclude(key, exclude) || isSignal(value) ? value : useSignal(value);
|
|
141
145
|
return acc;
|
|
142
146
|
}, {});
|
|
143
147
|
return signals;
|
|
144
148
|
}
|
|
145
|
-
function
|
|
149
|
+
function unSignal(signal, exclude) {
|
|
146
150
|
if (!signal)
|
|
147
151
|
return {};
|
|
148
152
|
if (isSignal(signal)) {
|
|
149
153
|
return signal.peek();
|
|
150
154
|
}
|
|
151
155
|
return Object.entries(signal).reduce((acc, [key, value]) => {
|
|
152
|
-
|
|
156
|
+
if (shouldExclude(key, exclude)) {
|
|
157
|
+
acc[key] = value;
|
|
158
|
+
} else {
|
|
159
|
+
acc[key] = isSignal(value) ? value.peek() : value;
|
|
160
|
+
}
|
|
153
161
|
return acc;
|
|
154
162
|
}, {});
|
|
155
163
|
}
|
|
@@ -166,8 +174,8 @@ function createOptionsStore(options) {
|
|
|
166
174
|
const default_actions = {
|
|
167
175
|
patch$(payload) {
|
|
168
176
|
Object.assign(signalState, signalObject(payload));
|
|
169
|
-
subscriptions.forEach((callback) => callback(
|
|
170
|
-
actionCallbacks.forEach((callback) => callback(
|
|
177
|
+
subscriptions.forEach((callback) => callback(unSignal(signalState)));
|
|
178
|
+
actionCallbacks.forEach((callback) => callback(unSignal(signalState)));
|
|
171
179
|
},
|
|
172
180
|
subscribe$(callback) {
|
|
173
181
|
subscriptions.push(callback);
|
|
@@ -209,7 +217,7 @@ function createOptionsStore(options) {
|
|
|
209
217
|
{
|
|
210
218
|
get(_, key) {
|
|
211
219
|
if (key === "state") {
|
|
212
|
-
return
|
|
220
|
+
return unSignal(signalState);
|
|
213
221
|
}
|
|
214
222
|
if (key in states) {
|
|
215
223
|
return states[key];
|
|
@@ -235,13 +243,16 @@ function createStore(options) {
|
|
|
235
243
|
function coerceArray(data) {
|
|
236
244
|
return Array.isArray(data) ? data.flat() : [data];
|
|
237
245
|
}
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
246
|
+
function startsWith(str, searchString) {
|
|
247
|
+
return str.indexOf(searchString) === 0;
|
|
248
|
+
}
|
|
249
|
+
var isObject2 = (val) => val !== null && typeof val === "object";
|
|
250
|
+
var isArray2 = Array.isArray;
|
|
251
|
+
function isNil2(x) {
|
|
241
252
|
return x === null || x === void 0;
|
|
242
253
|
}
|
|
243
|
-
var
|
|
244
|
-
function
|
|
254
|
+
var isFunction2 = (val) => typeof val === "function";
|
|
255
|
+
function isFalsy2(x) {
|
|
245
256
|
return x === false || x === null || x === void 0 || x === "";
|
|
246
257
|
}
|
|
247
258
|
var kebabCase = (string) => {
|
|
@@ -266,7 +277,10 @@ var _ComponentNode = class _ComponentNode {
|
|
|
266
277
|
destroy: /* @__PURE__ */ new Set()
|
|
267
278
|
};
|
|
268
279
|
this.trackMap = /* @__PURE__ */ new Map();
|
|
269
|
-
this.proxyProps = signalObject(
|
|
280
|
+
this.proxyProps = signalObject(
|
|
281
|
+
props,
|
|
282
|
+
(key2) => startsWith(key2, "on") || startsWith(key2, "update:")
|
|
283
|
+
);
|
|
270
284
|
}
|
|
271
285
|
addEventListener() {
|
|
272
286
|
}
|
|
@@ -313,7 +327,7 @@ var _ComponentNode = class _ComponentNode {
|
|
|
313
327
|
}
|
|
314
328
|
mount(parent, before) {
|
|
315
329
|
var _a, _b, _c, _d;
|
|
316
|
-
if (!
|
|
330
|
+
if (!isFunction2(this.template)) {
|
|
317
331
|
throw new Error("Template must be a function");
|
|
318
332
|
}
|
|
319
333
|
if (this.isConnected) {
|
|
@@ -343,19 +357,19 @@ var _ComponentNode = class _ComponentNode {
|
|
|
343
357
|
patchProps(props) {
|
|
344
358
|
var _a, _b, _c, _d, _e;
|
|
345
359
|
for (const [key, prop] of Object.entries(props)) {
|
|
346
|
-
if (key
|
|
360
|
+
if (startsWith(key, "on") && ((_a = this.rootNode) == null ? void 0 : _a.nodes)) {
|
|
347
361
|
const event = key.slice(2).toLowerCase();
|
|
348
362
|
const listener = prop;
|
|
349
363
|
const cleanup = addEventListener(this.rootNode.nodes[0], event, listener);
|
|
350
364
|
this.emitter.add(cleanup);
|
|
351
|
-
} else if (key.indexOf("bind:") === 0) {
|
|
352
|
-
this.proxyProps[key] = useSignal(prop);
|
|
353
365
|
} else if (key === "ref") {
|
|
354
366
|
if (isSignal(prop)) {
|
|
355
367
|
props[key].value = (_b = this.rootNode) == null ? void 0 : _b.nodes[0];
|
|
356
|
-
} else {
|
|
357
|
-
props[key]
|
|
368
|
+
} else if (isFunction2(prop)) {
|
|
369
|
+
props[key]((_c = this.rootNode) == null ? void 0 : _c.nodes[0]);
|
|
358
370
|
}
|
|
371
|
+
} else if (startsWith(key, "update:")) {
|
|
372
|
+
props[key] = isSignal(prop) ? prop.value : prop;
|
|
359
373
|
} else {
|
|
360
374
|
const newValue = (_e = (_d = this.proxyProps)[key]) != null ? _e : _d[key] = useSignal(prop);
|
|
361
375
|
const track2 = this.getNodeTrack(key);
|
|
@@ -373,7 +387,7 @@ var ComponentNode = _ComponentNode;
|
|
|
373
387
|
|
|
374
388
|
// src/template/template.ts
|
|
375
389
|
function h(template2, props, key) {
|
|
376
|
-
return
|
|
390
|
+
return isFunction2(template2) ? new ComponentNode(template2, props, key) : new TemplateNode(template2, props, key);
|
|
377
391
|
}
|
|
378
392
|
function isJsxElement(node) {
|
|
379
393
|
return node instanceof ComponentNode || node instanceof TemplateNode;
|
|
@@ -392,7 +406,7 @@ function coerceNode(data) {
|
|
|
392
406
|
if (isJsxElement(data) || data instanceof Node) {
|
|
393
407
|
return data;
|
|
394
408
|
}
|
|
395
|
-
const text =
|
|
409
|
+
const text = isFalsy2(data) ? "" : String(data);
|
|
396
410
|
return document.createTextNode(text);
|
|
397
411
|
}
|
|
398
412
|
function insertChild(parent, child, before = null) {
|
|
@@ -441,7 +455,7 @@ function setAttribute(element, attr, value) {
|
|
|
441
455
|
}
|
|
442
456
|
return;
|
|
443
457
|
}
|
|
444
|
-
if (
|
|
458
|
+
if (isFalsy2(value)) {
|
|
445
459
|
element.removeAttribute(attr);
|
|
446
460
|
} else if (value === true) {
|
|
447
461
|
element.setAttribute(attr, "");
|
|
@@ -723,7 +737,7 @@ var TemplateNode = class _TemplateNode {
|
|
|
723
737
|
patchNode(key, node, props, isRoot) {
|
|
724
738
|
for (const attr in props) {
|
|
725
739
|
if (attr === "children" && props.children) {
|
|
726
|
-
if (!
|
|
740
|
+
if (!isArray2(props.children)) {
|
|
727
741
|
const trackKey = `${key}:${attr}:${0}`;
|
|
728
742
|
const track2 = this.getNodeTrack(trackKey, true, isRoot);
|
|
729
743
|
patchChild(track2, node, props.children, null);
|
|
@@ -733,8 +747,8 @@ var TemplateNode = class _TemplateNode {
|
|
|
733
747
|
if (!item) {
|
|
734
748
|
return;
|
|
735
749
|
}
|
|
736
|
-
const [child, path] =
|
|
737
|
-
const before =
|
|
750
|
+
const [child, path] = isArray2(item) ? item : [item, null];
|
|
751
|
+
const before = isNil2(path) ? null : (_a = this.treeMap.get(path)) != null ? _a : null;
|
|
738
752
|
const trackKey = `${key}:${attr}:${index}`;
|
|
739
753
|
const track2 = this.getNodeTrack(trackKey, true, isRoot);
|
|
740
754
|
patchChild(track2, node, child, before);
|
|
@@ -743,31 +757,15 @@ var TemplateNode = class _TemplateNode {
|
|
|
743
757
|
} else if (attr === "ref") {
|
|
744
758
|
if (isSignal(props[attr])) {
|
|
745
759
|
props[attr].value = node;
|
|
746
|
-
} else {
|
|
747
|
-
props[attr]
|
|
760
|
+
} else if (isFunction2(props[attr])) {
|
|
761
|
+
props[attr](node);
|
|
748
762
|
}
|
|
749
|
-
} else if (attr
|
|
763
|
+
} else if (startsWith(attr, "on")) {
|
|
750
764
|
const eventName = attr.slice(2).toLocaleLowerCase();
|
|
751
765
|
const track2 = this.getNodeTrack(`${key}:${attr}`);
|
|
752
766
|
const listener = props[attr];
|
|
753
767
|
track2.cleanup = addEventListener(node, eventName, listener);
|
|
754
|
-
} else if (attr
|
|
755
|
-
const bindKey = attr.slice(5).toLocaleLowerCase();
|
|
756
|
-
const val = props[attr];
|
|
757
|
-
const track2 = this.getNodeTrack(`${key}:${attr}`);
|
|
758
|
-
const triggerValue = isSignal(val) ? val : useSignal(val);
|
|
759
|
-
const cleanup = useEffect(() => {
|
|
760
|
-
triggerValue.value = isSignal(val) ? val.value : val;
|
|
761
|
-
node[bindKey] = triggerValue.value;
|
|
762
|
-
});
|
|
763
|
-
const cleanupBind = binNode(node, (value) => {
|
|
764
|
-
props[`update:${bindKey}`](value);
|
|
765
|
-
});
|
|
766
|
-
track2.cleanup = () => {
|
|
767
|
-
cleanup == null ? void 0 : cleanup();
|
|
768
|
-
cleanupBind == null ? void 0 : cleanupBind();
|
|
769
|
-
};
|
|
770
|
-
} else if (attr.indexOf("update:") !== 0) {
|
|
768
|
+
} else if (!startsWith(attr, "update:")) {
|
|
771
769
|
const track2 = this.getNodeTrack(`${key}:${attr}`);
|
|
772
770
|
const val = props[attr];
|
|
773
771
|
const triggerValue = isSignal(val) ? val : useSignal(val);
|
|
@@ -775,8 +773,16 @@ var TemplateNode = class _TemplateNode {
|
|
|
775
773
|
triggerValue.value = isSignal(val) ? val.value : val;
|
|
776
774
|
patchAttribute(track2, node, attr, triggerValue.value);
|
|
777
775
|
});
|
|
776
|
+
let cleanupBind;
|
|
777
|
+
const updateKey = `update:${attr}`;
|
|
778
|
+
if (props[updateKey]) {
|
|
779
|
+
cleanupBind = binNode(node, (value) => {
|
|
780
|
+
props[updateKey](value);
|
|
781
|
+
});
|
|
782
|
+
}
|
|
778
783
|
track2.cleanup = () => {
|
|
779
|
-
cleanup
|
|
784
|
+
cleanup && cleanup();
|
|
785
|
+
cleanupBind && cleanupBind();
|
|
780
786
|
};
|
|
781
787
|
}
|
|
782
788
|
}
|
|
@@ -787,7 +793,7 @@ function patchAttribute(track2, node, attr, data) {
|
|
|
787
793
|
if (!element.setAttribute) {
|
|
788
794
|
return;
|
|
789
795
|
}
|
|
790
|
-
if (
|
|
796
|
+
if (isFunction2(data)) {
|
|
791
797
|
track2.cleanup = useEffect(() => {
|
|
792
798
|
setAttribute(element, attr, data());
|
|
793
799
|
});
|
|
@@ -796,7 +802,7 @@ function patchAttribute(track2, node, attr, data) {
|
|
|
796
802
|
}
|
|
797
803
|
}
|
|
798
804
|
function patchChild(track2, parent, child, before) {
|
|
799
|
-
if (
|
|
805
|
+
if (isFunction2(child)) {
|
|
800
806
|
track2.cleanup = useEffect(() => {
|
|
801
807
|
const nextNodes = coerceArray(child()).map(coerceNode);
|
|
802
808
|
track2.lastNodes = patchChildren(parent, track2.lastNodes, nextNodes, before);
|
|
@@ -860,7 +866,7 @@ function useRef() {
|
|
|
860
866
|
}
|
|
861
867
|
|
|
862
868
|
// src/version.ts
|
|
863
|
-
var __essor_version = "0.0.6-beta.
|
|
869
|
+
var __essor_version = "0.0.6-beta.2";
|
|
864
870
|
|
|
865
871
|
// src/server/index.ts
|
|
866
872
|
function ssrtmpl(templates = []) {
|
|
@@ -873,17 +879,17 @@ function jsonToAttrs(json) {
|
|
|
873
879
|
return Object.entries(json).map(([key, value]) => `${key}=${JSON.stringify(value)}`).join(" ");
|
|
874
880
|
}
|
|
875
881
|
function ssr(template2, props) {
|
|
876
|
-
if (
|
|
882
|
+
if (isFunction2(template2)) {
|
|
877
883
|
return template2(props);
|
|
878
884
|
}
|
|
879
885
|
const childrenMap = {};
|
|
880
886
|
const newTemplate = {};
|
|
881
|
-
if (
|
|
887
|
+
if (isObject2(template2)) {
|
|
882
888
|
Object.entries(template2).forEach(([key, tmpl]) => {
|
|
883
889
|
const prop = props[key];
|
|
884
890
|
if (prop) {
|
|
885
891
|
Object.keys(prop).forEach((propKey) => {
|
|
886
|
-
if (
|
|
892
|
+
if (startsWith(propKey, "on") && isFunction2(prop[propKey])) {
|
|
887
893
|
delete prop[propKey];
|
|
888
894
|
}
|
|
889
895
|
});
|
|
@@ -916,4 +922,4 @@ function hydrate(component, root) {
|
|
|
916
922
|
component.mount(root);
|
|
917
923
|
}
|
|
918
924
|
|
|
919
|
-
export { ComponentNode, Fragment, TemplateNode, __essor_version, createStore, h, hydrate, isComputed, isJsxElement, isSignal, nextTick, onDestroy, onMount, renderToString, signalObject, ssr, ssrtmpl, template, useComputed, useEffect, useInject, useProvide, useRef, useSignal };
|
|
925
|
+
export { ComponentNode, Fragment, TemplateNode, __essor_version, createStore, h, hydrate, isComputed, isJsxElement, isSignal, nextTick, onDestroy, onMount, renderToString, signalObject, ssr, ssrtmpl, template, unSignal, useComputed, useEffect, useInject, useProvide, useRef, useSignal };
|
package/dist/essor.esm.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
var ce=Object.defineProperty;var Z=Object.getOwnPropertySymbols;var ue=Object.prototype.hasOwnProperty,le=Object.prototype.propertyIsEnumerable;var q=(t,e,n)=>e in t?ce(t,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[e]=n,Q=(t,e)=>{for(var n in e||(e={}))ue.call(e,n)&&q(t,n,e[n]);if(Z)for(var n of Z(e))le.call(e,n)&&q(t,n,e[n]);return t};var C=null,j=null,F=new Set,K=new WeakMap,R=new Set;function A(t,e){let n=K.get(t);n||(n=new Map,K.set(t,n));let o=n.get(e);o||(o=new Set,n.set(e,o)),C&&o.add(C),j&&F.add(j);}function Y(t,e){F.size>0&&F.forEach(r=>r.run());let n=K.get(t);if(!n)return;let o=n.get(e);o&&o.forEach(r=>R.has(r)&&r());}var L=class{constructor(e){this._value=e;}valueOf(){return A(this,"value"),this._value}toString(){return A(this,"value"),String(this._value)}toJSON(){return this._value}get value(){return A(this,"value"),this._value}set value(e){this._value!==e&&(this._value=e,Y(this,"value"));}peek(){return this._value}update(){Y(this,"value");}};function N(t){return f(t)?t:new L(t)}function f(t){return t instanceof L}var $=class{constructor(e){this.fn=e;let n=j;j=this,A(this,"_value"),this._value=this.fn(),j=n;}peek(){return this._value}run(){let e=this.fn();e!==this._value&&(this._value=e);}get value(){return A(this,"_value"),this._value}};function J(t){return new $(t)}function pe(t){return t instanceof $}function x(t){function e(){let n=C;C=e,t(),C=n;}return R.add(e),e(),()=>{R.delete(e),C=null;}}function k(t){return Object.entries(t).reduce((n,[o,r])=>(n[o]=f(r)?r:N(r),n),{})}function P(t){return t?f(t)?t.peek():Object.entries(t).reduce((e,[n,o])=>(e[n]=f(o)?o.peek():o,e),{}):{}}var O=0,G=new Map;function fe(t){let{state:e,getters:n,actions:o}=t,r=Q({},e!=null?e:{}),i=k(e!=null?e:{}),s=[],a=[],p={patch$(c){Object.assign(i,k(c)),s.forEach(u=>u(P(i))),a.forEach(u=>u(P(i)));},subscribe$(c){s.push(c);},unsubscribe$(c){let u=s.indexOf(c);u!==-1&&s.splice(u,1);},onAction$(c){a.push(c);},reset$(){p.patch$(r);}},l={_id:`store_${O}`};for(let c in n){let u=n[c];u&&(l[c]=J(()=>u.call(i)));}for(let c in o){let u=o[c];u&&(l[c]=u.bind(i));}return G.set(O,N),++O,new Proxy({},{get(c,u){return u==="state"?P(i):u in l?l[u]:u in p?p[u]:i[u].value}})}function de(t){return function(){return G.has(O)?G.get(O):fe(t)}}function I(t){return Array.isArray(t)?t.flat():[t]}var ee=t=>t!==null&&typeof t=="object";var X=Array.isArray;function te(t){return t==null}var v=t=>typeof t=="function";function V(t){return t===!1||t===null||t===void 0||t===""}var ne=t=>t.replaceAll(/[A-Z]+/g,(e,n)=>`${n>0?"-":""}${e.toLocaleLowerCase()}`);var b=class b{constructor(e,n,o){this.template=e;this.props=n;this.key=o;this.proxyProps={};this.context={};this.emitter=new Set;this.mounted=!1;this.rootNode=null;this.hooks={mounted:new Set,destroy:new Set};this.trackMap=new Map;this.proxyProps=k(n);}addEventListener(){}removeEventListener(){}get firstChild(){var e,n;return (n=(e=this.rootNode)==null?void 0:e.firstChild)!=null?n:null}get isConnected(){var e,n;return (n=(e=this.rootNode)==null?void 0:e.isConnected)!=null?n:!1}addHook(e,n){var o;(o=this.hooks[e])==null||o.add(n);}getContext(e){return b.context[e]}setContext(e,n){b.context[e]=n;}inheritNode(e){this.context=e.context,this.hooks=e.hooks,Object.assign(this.proxyProps,e.proxyProps),this.rootNode=e.rootNode,this.trackMap=e.trackMap;let n=this.props;this.props=e.props,this.patchProps(n);}unmount(){var e;this.hooks.destroy.forEach(n=>n()),Object.values(this.hooks).forEach(n=>n.clear()),(e=this.rootNode)==null||e.unmount(),this.rootNode=null,this.proxyProps={},this.mounted=!1,this.emitter.forEach(n=>n()),b.context={};}mount(e,n){var r,i,s,a;if(!v(this.template))throw new Error("Template must be a function");if(this.isConnected)return (i=(r=this.rootNode)==null?void 0:r.mount(e,n))!=null?i:[];b.ref=this,this.rootNode=this.template(this.proxyProps),b.ref=null,this.mounted=!0;let o=(a=(s=this.rootNode)==null?void 0:s.mount(e,n))!=null?a:[];return this.hooks.mounted.forEach(p=>p()),this.patchProps(this.props),o}getNodeTrack(e,n){let o=this.trackMap.get(e);return o||(o={cleanup:()=>{}},this.trackMap.set(e,o)),n||o.cleanup(),o}patchProps(e){var n,o,r,i,s;for(let[a,p]of Object.entries(e))if(a.indexOf("on")===0&&((n=this.rootNode)!=null&&n.nodes)){let l=a.slice(2).toLowerCase(),c=p,u=g(this.rootNode.nodes[0],l,c);this.emitter.add(u);}else if(a.indexOf("bind:")===0)this.proxyProps[a]=N(p);else if(a==="ref")f(p)?e[a].value=(o=this.rootNode)==null?void 0:o.nodes[0]:e[a]=(r=this.rootNode)==null?void 0:r.nodes[0];else {let l=(s=(i=this.proxyProps)[a])!=null?s:i[a]=N(p),c=this.getNodeTrack(a);c.cleanup=x(()=>{l.value=p;});}this.props=e;}};b.ref=null,b.context={};var h=b;function me(t,e,n){return v(t)?new h(t,e,n):new M(t,e,n)}function y(t){return t instanceof h||t instanceof M}function he(t){let e=document.createElement("template");return e.innerHTML=t,e}function ge(t){return t.children}function D(t){if(y(t)||t instanceof Node)return t;let e=V(t)?"":String(t);return document.createTextNode(e)}function T(t,e,n=null){let o=y(n)?n.firstChild:n;y(e)?e.mount(t,o):o?o.before(e):t.append(e);}function S(t){y(t)?t.unmount():t.parentNode&&t.remove();}function z(t,e,n){T(t,e,n),S(n);}function B(t,e,n){if(e==="class"){typeof n=="string"?t.className=n:Array.isArray(n)?t.className=n.join(" "):n&&typeof n=="object"&&(t.className=Object.entries(n).reduce((o,[r,i])=>o+(i?` ${r}`:""),"").trim());return}if(e==="style"){if(typeof n=="string")t.style.cssText=n;else if(n&&typeof n=="object"){let o=n;Object.keys(o).forEach(r=>{t.style.setProperty(ne(r),String(o[r]));});}return}V(n)?t.removeAttribute(e):n===!0?t.setAttribute(e,""):t.setAttribute(e,String(n));}function re(t,e){if(t instanceof HTMLInputElement){if(t.type==="checkbox")return g(t,"change",()=>{e(!!t.checked);});if(t.type==="date")return g(t,"change",()=>{e(t.value?t.value:"");});if(t.type==="file")return g(t,"change",()=>{t.files&&e(t.files);});if(t.type==="number")return g(t,"input",()=>{let n=Number.parseFloat(t.value);e(Number.isNaN(n)?"":String(n));});if(t.type==="radio")return g(t,"change",()=>{e(t.checked?t.value:"");});if(t.type==="text")return g(t,"input",()=>{e(t.value);})}if(t instanceof HTMLSelectElement)return g(t,"change",()=>{e(t.value);});if(t instanceof HTMLTextAreaElement)return g(t,"input",()=>{e(t.value);})}var oe=Promise.resolve();function ye(t){return t?oe.then(t):oe}function g(t,e,n){return t.addEventListener(e,n),()=>t.removeEventListener(e,n)}function ie(t,e,n,o){let r=new Map,i=e.values(),s=t.childNodes.length;if(e.size>0&&n.length===0){if(s===e.size+(o?1:0)){let l=t;l.innerHTML="",o&&T(t,o);}else {let l=document.createRange(),c=i.next().value,u=y(c)?c.firstChild:c;l.setStartBefore(u),o?l.setEndBefore(o):l.setEndAfter(t),l.deleteContents();}return e.forEach(l=>{y(l)&&l.unmount();}),r}let a=[],p=ve(n);for(let[l,c]of n.entries()){let u=i.next().value,E=_(u,l);for(;u&&!p.has(E);)S(u),e.delete(E),u=i.next().value,E=_(u,l);let w=_(c,l),U=e.get(w);if(U&&(c=Ne(t,U,c)),u)if(u){let W=document.createComment("");T(t,W,u),a.push([W,c]);}else T(t,c,o);else T(t,c,o);r.set(w,c);}return a.forEach(([l,c])=>z(t,c,l)),e.forEach((l,c)=>{l.isConnected&&!r.has(c)&&S(l);}),r}function Ne(t,e,n){return e===n?e:y(e)&&y(n)&&e.template===n.template?(n.inheritNode(e),n):e instanceof Text&&n instanceof Text?(e.textContent!==n.textContent&&(e.textContent=n.textContent),e):(z(t,n,e),n)}function ve(t){let e=new Map;for(let[n,o]of t.entries()){let r=_(o,n);e.set(r,o);}return e}function _(t,e){let n=t instanceof Element?t.id:void 0,o=n===""?void 0:n;return o!=null?o:`_$${e}$`}var M=class t{constructor(e,n,o){this.template=e;this.props=n;this.key=o;this.treeMap=new Map;this.mounted=!1;this.nodes=[];this.provides={};this.trackMap=new Map;this.parent=null;}get firstChild(){var e;return (e=this.nodes[0])!=null?e:null}get isConnected(){return this.mounted}addEventListener(){}removeEventListener(){}unmount(){this.trackMap.forEach(e=>{var n,o;(n=e.cleanup)==null||n.call(e),(o=e.lastNodes)==null||o.forEach(r=>{e.isRoot?S(r):r instanceof t&&r.unmount();});}),this.trackMap.clear(),this.treeMap.clear(),this.nodes.forEach(e=>S(e)),this.nodes=[],this.mounted=!1;}mount(e,n){var i;if(this.parent=e,this.isConnected)return this.nodes.forEach(s=>T(e,s,n)),this.nodes;let o=this.template.content.cloneNode(!0),r=o.firstChild;return (i=r==null?void 0:r.hasAttribute)!=null&&i.call(r,"_svg_")&&(r.remove(),r==null||r.childNodes.forEach(s=>{o.append(s);})),this.nodes=Array.from(o.childNodes),this.mapNodeTree(e,o),T(e,o,n),this.patchNodes(this.props),this.mounted=!0,this.nodes}mapNodeTree(e,n){let o=1;this.treeMap.set(0,e);let r=i=>{i.nodeType!==Node.DOCUMENT_FRAGMENT_NODE&&this.treeMap.set(o++,i);let s=i.firstChild;for(;s;)r(s),s=s.nextSibling;};r(n);}patchNodes(e){for(let n in e){let o=Number(n),r=this.treeMap.get(o);if(r){let i=this.props[n];this.patchNode(n,r,i,o===0);}}this.props=e;}getNodeTrack(e,n,o){var i;let r=this.trackMap.get(e);return r||(r={cleanup:()=>{}},n&&(r.lastNodes=new Map),o&&(r.isRoot=!0),this.trackMap.set(e,r)),(i=r.cleanup)==null||i.call(r),r}inheritNode(e){this.mounted=e.mounted,this.nodes=e.nodes,this.trackMap=e.trackMap,this.treeMap=e.treeMap;let n=this.props;this.props=e.props,this.patchNodes(n);}patchNode(e,n,o,r){for(let i in o)if(i==="children"&&o.children)if(X(o.children))o.children.forEach((s,a)=>{var w;if(!s)return;let[p,l]=X(s)?s:[s,null],c=te(l)?null:(w=this.treeMap.get(l))!=null?w:null,u=`${e}:${i}:${a}`,E=this.getNodeTrack(u,!0,r);se(E,n,p,c);});else {let s=`${e}:${i}:0`,a=this.getNodeTrack(s,!0,r);se(a,n,o.children,null);}else if(i==="ref")f(o[i])?o[i].value=n:o[i]=n;else if(i.indexOf("on")===0){let s=i.slice(2).toLocaleLowerCase(),a=this.getNodeTrack(`${e}:${i}`),p=o[i];a.cleanup=g(n,s,p);}else if(i.indexOf("bind:")===0){let s=i.slice(5).toLocaleLowerCase(),a=o[i],p=this.getNodeTrack(`${e}:${i}`),l=f(a)?a:N(a),c=x(()=>{l.value=f(a)?a.value:a,n[s]=l.value;}),u=re(n,E=>{o[`update:${s}`](E);});p.cleanup=()=>{c==null||c(),u==null||u();};}else if(i.indexOf("update:")!==0){let s=this.getNodeTrack(`${e}:${i}`),a=o[i],p=f(a)?a:N(a),l=x(()=>{p.value=f(a)?a.value:a,Te(s,n,i,p.value);});s.cleanup=()=>{l==null||l();};}}};function Te(t,e,n,o){let r=e;r.setAttribute&&(v(o)?t.cleanup=x(()=>{B(r,n,o());}):B(r,n,o));}function se(t,e,n,o){v(n)?t.cleanup=x(()=>{let r=I(n()).map(D);t.lastNodes=ie(e,t.lastNodes,r,o);}):I(n).forEach((r,i)=>{let s=D(r);t.lastNodes.set(String(i),s),T(e,s,o);});}function be(t){var e;H("onMounted"),(e=h.ref)==null||e.addHook("mounted",t);}function xe(t){var e;H("onDestroy"),(e=h.ref)==null||e.addHook("destroy",t);}function H(t){if(!h.ref)throw new Error(`"${t}" can only be called within the component function body
|
|
2
|
-
and cannot be used in asynchronous or deferred calls.`)}function
|
|
1
|
+
var pe=Object.defineProperty;var Q=Object.getOwnPropertySymbols;var fe=Object.prototype.hasOwnProperty,de=Object.prototype.propertyIsEnumerable;var Y=(t,e,n)=>e in t?pe(t,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[e]=n,ee=(t,e)=>{for(var n in e||(e={}))fe.call(e,n)&&Y(t,n,e[n]);if(Q)for(var n of Q(e))de.call(e,n)&&Y(t,n,e[n]);return t};var R=t=>typeof t=="function";var C=null,j=null,K=new Set,J=new WeakMap,G=new Set;function O(t,e){let n=J.get(t);n||(n=new Map,J.set(t,n));let o=n.get(e);o||(o=new Set,n.set(e,o)),C&&o.add(C),j&&K.add(j);}function te(t,e){K.size>0&&K.forEach(r=>r.run());let n=J.get(t);if(!n)return;let o=n.get(e);o&&o.forEach(r=>G.has(r)&&r());}var _=class{constructor(e){this._value=e;}valueOf(){return O(this,"value"),this._value}toString(){return O(this,"value"),String(this._value)}toJSON(){return this._value}get value(){return O(this,"value"),this._value}set value(e){this._value!==e&&(this._value=e,te(this,"value"));}peek(){return this._value}update(){te(this,"value");}};function x(t){return m(t)?t:new _(t)}function m(t){return t instanceof _}var $=class{constructor(e){this.fn=e;let n=j;j=this,O(this,"_value"),this._value=this.fn(),j=n;}peek(){return this._value}run(){let e=this.fn();e!==this._value&&(this._value=e);}get value(){return O(this,"_value"),this._value}};function I(t){return new $(t)}function he(t){return t instanceof $}function E(t){function e(){let n=C;C=e,t(),C=n;}return G.add(e),e(),()=>{G.delete(e),C=null;}}function ne(t,e){return Array.isArray(e)?e.includes(t):R(e)?e(t):!1}function M(t,e){return Object.entries(t).reduce((o,[r,i])=>(o[r]=ne(r,e)||m(i)?i:x(i),o),{})}function L(t,e){return t?m(t)?t.peek():Object.entries(t).reduce((n,[o,r])=>(ne(o,e)?n[o]=r:n[o]=m(r)?r.peek():r,n),{}):{}}var P=0,X=new Map;function ge(t){let{state:e,getters:n,actions:o}=t,r=ee({},e!=null?e:{}),i=M(e!=null?e:{}),s=[],a=[],p={patch$(c){Object.assign(i,M(c)),s.forEach(u=>u(L(i))),a.forEach(u=>u(L(i)));},subscribe$(c){s.push(c);},unsubscribe$(c){let u=s.indexOf(c);u!==-1&&s.splice(u,1);},onAction$(c){a.push(c);},reset$(){p.patch$(r);}},l={_id:`store_${P}`};for(let c in n){let u=n[c];u&&(l[c]=I(()=>u.call(i)));}for(let c in o){let u=o[c];u&&(l[c]=u.bind(i));}return X.set(P,x),++P,new Proxy({},{get(c,u){return u==="state"?L(i):u in l?l[u]:u in p?p[u]:i[u].value}})}function ye(t){return function(){return X.has(P)?X.get(P):ge(t)}}function V(t){return Array.isArray(t)?t.flat():[t]}function v(t,e){return t.indexOf(e)===0}var oe=t=>t!==null&&typeof t=="object";var D=Array.isArray;function re(t){return t==null}var h=t=>typeof t=="function";function W(t){return t===!1||t===null||t===void 0||t===""}var ie=t=>t.replaceAll(/[A-Z]+/g,(e,n)=>`${n>0?"-":""}${e.toLocaleLowerCase()}`);var T=class T{constructor(e,n,o){this.template=e;this.props=n;this.key=o;this.proxyProps={};this.context={};this.emitter=new Set;this.mounted=!1;this.rootNode=null;this.hooks={mounted:new Set,destroy:new Set};this.trackMap=new Map;this.proxyProps=M(n,r=>v(r,"on")||v(r,"update:"));}addEventListener(){}removeEventListener(){}get firstChild(){var e,n;return (n=(e=this.rootNode)==null?void 0:e.firstChild)!=null?n:null}get isConnected(){var e,n;return (n=(e=this.rootNode)==null?void 0:e.isConnected)!=null?n:!1}addHook(e,n){var o;(o=this.hooks[e])==null||o.add(n);}getContext(e){return T.context[e]}setContext(e,n){T.context[e]=n;}inheritNode(e){this.context=e.context,this.hooks=e.hooks,Object.assign(this.proxyProps,e.proxyProps),this.rootNode=e.rootNode,this.trackMap=e.trackMap;let n=this.props;this.props=e.props,this.patchProps(n);}unmount(){var e;this.hooks.destroy.forEach(n=>n()),Object.values(this.hooks).forEach(n=>n.clear()),(e=this.rootNode)==null||e.unmount(),this.rootNode=null,this.proxyProps={},this.mounted=!1,this.emitter.forEach(n=>n()),T.context={};}mount(e,n){var r,i,s,a;if(!h(this.template))throw new Error("Template must be a function");if(this.isConnected)return (i=(r=this.rootNode)==null?void 0:r.mount(e,n))!=null?i:[];T.ref=this,this.rootNode=this.template(this.proxyProps),T.ref=null,this.mounted=!0;let o=(a=(s=this.rootNode)==null?void 0:s.mount(e,n))!=null?a:[];return this.hooks.mounted.forEach(p=>p()),this.patchProps(this.props),o}getNodeTrack(e,n){let o=this.trackMap.get(e);return o||(o={cleanup:()=>{}},this.trackMap.set(e,o)),n||o.cleanup(),o}patchProps(e){var n,o,r,i,s;for(let[a,p]of Object.entries(e))if(v(a,"on")&&((n=this.rootNode)!=null&&n.nodes)){let l=a.slice(2).toLowerCase(),c=p,u=y(this.rootNode.nodes[0],l,c);this.emitter.add(u);}else if(a==="ref")m(p)?e[a].value=(o=this.rootNode)==null?void 0:o.nodes[0]:h(p)&&e[a]((r=this.rootNode)==null?void 0:r.nodes[0]);else if(v(a,"update:"))e[a]=m(p)?p.value:p;else {let l=(s=(i=this.proxyProps)[a])!=null?s:i[a]=x(p),c=this.getNodeTrack(a);c.cleanup=E(()=>{l.value=p;});}this.props=e;}};T.ref=null,T.context={};var g=T;function Ne(t,e,n){return h(t)?new g(t,e,n):new w(t,e,n)}function N(t){return t instanceof g||t instanceof w}function ve(t){let e=document.createElement("template");return e.innerHTML=t,e}function be(t){return t.children}function z(t){if(N(t)||t instanceof Node)return t;let e=W(t)?"":String(t);return document.createTextNode(e)}function b(t,e,n=null){let o=N(n)?n.firstChild:n;N(e)?e.mount(t,o):o?o.before(e):t.append(e);}function k(t){N(t)?t.unmount():t.parentNode&&t.remove();}function B(t,e,n){b(t,e,n),k(n);}function U(t,e,n){if(e==="class"){typeof n=="string"?t.className=n:Array.isArray(n)?t.className=n.join(" "):n&&typeof n=="object"&&(t.className=Object.entries(n).reduce((o,[r,i])=>o+(i?` ${r}`:""),"").trim());return}if(e==="style"){if(typeof n=="string")t.style.cssText=n;else if(n&&typeof n=="object"){let o=n;Object.keys(o).forEach(r=>{t.style.setProperty(ie(r),String(o[r]));});}return}W(n)?t.removeAttribute(e):n===!0?t.setAttribute(e,""):t.setAttribute(e,String(n));}function ae(t,e){if(t instanceof HTMLInputElement){if(t.type==="checkbox")return y(t,"change",()=>{e(!!t.checked);});if(t.type==="date")return y(t,"change",()=>{e(t.value?t.value:"");});if(t.type==="file")return y(t,"change",()=>{t.files&&e(t.files);});if(t.type==="number")return y(t,"input",()=>{let n=Number.parseFloat(t.value);e(Number.isNaN(n)?"":String(n));});if(t.type==="radio")return y(t,"change",()=>{e(t.checked?t.value:"");});if(t.type==="text")return y(t,"input",()=>{e(t.value);})}if(t instanceof HTMLSelectElement)return y(t,"change",()=>{e(t.value);});if(t instanceof HTMLTextAreaElement)return y(t,"input",()=>{e(t.value);})}var se=Promise.resolve();function Te(t){return t?se.then(t):se}function y(t,e,n){return t.addEventListener(e,n),()=>t.removeEventListener(e,n)}function ce(t,e,n,o){let r=new Map,i=e.values(),s=t.childNodes.length;if(e.size>0&&n.length===0){if(s===e.size+(o?1:0)){let l=t;l.innerHTML="",o&&b(t,o);}else {let l=document.createRange(),c=i.next().value,u=N(c)?c.firstChild:c;l.setStartBefore(u),o?l.setEndBefore(o):l.setEndAfter(t),l.deleteContents();}return e.forEach(l=>{N(l)&&l.unmount();}),r}let a=[],p=Se(n);for(let[l,c]of n.entries()){let u=i.next().value,S=F(u,l);for(;u&&!p.has(S);)k(u),e.delete(S),u=i.next().value,S=F(u,l);let A=F(c,l),Z=e.get(A);if(Z&&(c=xe(t,Z,c)),u)if(u){let q=document.createComment("");b(t,q,u),a.push([q,c]);}else b(t,c,o);else b(t,c,o);r.set(A,c);}return a.forEach(([l,c])=>B(t,c,l)),e.forEach((l,c)=>{l.isConnected&&!r.has(c)&&k(l);}),r}function xe(t,e,n){return e===n?e:N(e)&&N(n)&&e.template===n.template?(n.inheritNode(e),n):e instanceof Text&&n instanceof Text?(e.textContent!==n.textContent&&(e.textContent=n.textContent),e):(B(t,n,e),n)}function Se(t){let e=new Map;for(let[n,o]of t.entries()){let r=F(o,n);e.set(r,o);}return e}function F(t,e){let n=t instanceof Element?t.id:void 0,o=n===""?void 0:n;return o!=null?o:`_$${e}$`}var w=class t{constructor(e,n,o){this.template=e;this.props=n;this.key=o;this.treeMap=new Map;this.mounted=!1;this.nodes=[];this.provides={};this.trackMap=new Map;this.parent=null;}get firstChild(){var e;return (e=this.nodes[0])!=null?e:null}get isConnected(){return this.mounted}addEventListener(){}removeEventListener(){}unmount(){this.trackMap.forEach(e=>{var n,o;(n=e.cleanup)==null||n.call(e),(o=e.lastNodes)==null||o.forEach(r=>{e.isRoot?k(r):r instanceof t&&r.unmount();});}),this.trackMap.clear(),this.treeMap.clear(),this.nodes.forEach(e=>k(e)),this.nodes=[],this.mounted=!1;}mount(e,n){var i;if(this.parent=e,this.isConnected)return this.nodes.forEach(s=>b(e,s,n)),this.nodes;let o=this.template.content.cloneNode(!0),r=o.firstChild;return (i=r==null?void 0:r.hasAttribute)!=null&&i.call(r,"_svg_")&&(r.remove(),r==null||r.childNodes.forEach(s=>{o.append(s);})),this.nodes=Array.from(o.childNodes),this.mapNodeTree(e,o),b(e,o,n),this.patchNodes(this.props),this.mounted=!0,this.nodes}mapNodeTree(e,n){let o=1;this.treeMap.set(0,e);let r=i=>{i.nodeType!==Node.DOCUMENT_FRAGMENT_NODE&&this.treeMap.set(o++,i);let s=i.firstChild;for(;s;)r(s),s=s.nextSibling;};r(n);}patchNodes(e){for(let n in e){let o=Number(n),r=this.treeMap.get(o);if(r){let i=this.props[n];this.patchNode(n,r,i,o===0);}}this.props=e;}getNodeTrack(e,n,o){var i;let r=this.trackMap.get(e);return r||(r={cleanup:()=>{}},n&&(r.lastNodes=new Map),o&&(r.isRoot=!0),this.trackMap.set(e,r)),(i=r.cleanup)==null||i.call(r),r}inheritNode(e){this.mounted=e.mounted,this.nodes=e.nodes,this.trackMap=e.trackMap,this.treeMap=e.treeMap;let n=this.props;this.props=e.props,this.patchNodes(n);}patchNode(e,n,o,r){for(let i in o)if(i==="children"&&o.children)if(D(o.children))o.children.forEach((s,a)=>{var A;if(!s)return;let[p,l]=D(s)?s:[s,null],c=re(l)?null:(A=this.treeMap.get(l))!=null?A:null,u=`${e}:${i}:${a}`,S=this.getNodeTrack(u,!0,r);ue(S,n,p,c);});else {let s=`${e}:${i}:0`,a=this.getNodeTrack(s,!0,r);ue(a,n,o.children,null);}else if(i==="ref")m(o[i])?o[i].value=n:h(o[i])&&o[i](n);else if(v(i,"on")){let s=i.slice(2).toLocaleLowerCase(),a=this.getNodeTrack(`${e}:${i}`),p=o[i];a.cleanup=y(n,s,p);}else if(!v(i,"update:")){let s=this.getNodeTrack(`${e}:${i}`),a=o[i],p=m(a)?a:x(a),l=E(()=>{p.value=m(a)?a.value:a,Ee(s,n,i,p.value);}),c,u=`update:${i}`;o[u]&&(c=ae(n,S=>{o[u](S);})),s.cleanup=()=>{l&&l(),c&&c();};}}};function Ee(t,e,n,o){let r=e;r.setAttribute&&(h(o)?t.cleanup=E(()=>{U(r,n,o());}):U(r,n,o));}function ue(t,e,n,o){h(n)?t.cleanup=E(()=>{let r=V(n()).map(z);t.lastNodes=ce(e,t.lastNodes,r,o);}):V(n).forEach((r,i)=>{let s=z(r);t.lastNodes.set(String(i),s),b(e,s,o);});}function ke(t){var e;H("onMounted"),(e=g.ref)==null||e.addHook("mounted",t);}function Ce(t){var e;H("onDestroy"),(e=g.ref)==null||e.addHook("destroy",t);}function H(t){if(!g.ref)throw new Error(`"${t}" can only be called within the component function body
|
|
2
|
+
and cannot be used in asynchronous or deferred calls.`)}function Me(t,e){var n;H("useProvide"),(n=g.ref)==null||n.setContext(t,e);}function we(t,e){var n;return H("useInject"),((n=g.ref)==null?void 0:n.getContext(t))||e}function Ae(){let t=null;return new Proxy({},{get(e,n){return n==="__is_ref"?!0:t},set(e,n,o){return t=o,!0}})}var Vt="0.0.6-beta.2";function Bt(t=[]){return t.reduce((e,n,o)=>(e[o+1]={template:n},e),{})}function je(t){return Object.entries(t).map(([e,n])=>`${e}=${JSON.stringify(n)}`).join(" ")}function le(t,e){if(h(t))return t(e);let n={},o={};return oe(t)&&Object.entries(t).forEach(([r,i])=>{let s=e[r];s&&(Object.keys(s).forEach(a=>{v(a,"on")&&h(s[a])&&delete s[a];}),s.children&&(s.children.forEach(([a,p])=>{n[p]=[...n[p]||[],a];}),delete s.children)),o[r]={template:i.template,prop:s};}),Object.entries(o).map(([r,{template:i,prop:s}])=>{let a=i;return s&&(a+=` ${je(s)}`),n[r]&&(a+=n[r].map(p=>le(p,s)).join("")),a}).join("")}function Ut(t,e){return le(t,e)}function Zt(t,e){e.innerHTML="",t.mount(e);}
|
|
3
3
|
|
|
4
|
-
export {
|
|
4
|
+
export { g as ComponentNode, be as Fragment, w as TemplateNode, Vt as __essor_version, ye as createStore, Ne as h, Zt as hydrate, he as isComputed, N as isJsxElement, m as isSignal, Te as nextTick, Ce as onDestroy, ke as onMount, Ut as renderToString, M as signalObject, le as ssr, Bt as ssrtmpl, ve as template, L as unSignal, I as useComputed, E as useEffect, we as useInject, Me as useProvide, Ae as useRef, x as useSignal };
|
|
5
5
|
//# sourceMappingURL=out.js.map
|
|
6
6
|
//# sourceMappingURL=essor.esm.js.map
|