@jxsuite/runtime 0.23.2 → 0.25.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/runtime.js +56 -31
- package/dist/runtime.js.map +5 -5
- package/package.json +8 -6
- package/src/{expression.js → expression.ts} +110 -112
- package/src/{runtime.js → runtime.ts} +297 -275
- package/src/types.ts +14 -0
package/dist/runtime.js
CHANGED
|
@@ -1258,7 +1258,7 @@ function computed(getterOrOptions, debugOptions, isSSR = false) {
|
|
|
1258
1258
|
return cRef;
|
|
1259
1259
|
}
|
|
1260
1260
|
|
|
1261
|
-
// src/expression.
|
|
1261
|
+
// src/expression.ts
|
|
1262
1262
|
var MUTATING_OPS = new Set([
|
|
1263
1263
|
"=",
|
|
1264
1264
|
"+=",
|
|
@@ -1477,21 +1477,30 @@ function evaluateExpression(node, state, event, iterCtx) {
|
|
|
1477
1477
|
}
|
|
1478
1478
|
if (operator === "map") {
|
|
1479
1479
|
return arr.map((item, index) => {
|
|
1480
|
-
return evaluateExpression(value, state, event, {
|
|
1480
|
+
return evaluateExpression(value, state, event, {
|
|
1481
|
+
...iterCtx,
|
|
1482
|
+
item,
|
|
1483
|
+
index
|
|
1484
|
+
});
|
|
1481
1485
|
});
|
|
1482
1486
|
}
|
|
1483
1487
|
if (operator === "filter") {
|
|
1484
1488
|
return arr.filter((item, index) => {
|
|
1485
|
-
return evaluateExpression(value, state, event, {
|
|
1489
|
+
return evaluateExpression(value, state, event, {
|
|
1490
|
+
...iterCtx,
|
|
1491
|
+
item,
|
|
1492
|
+
index
|
|
1493
|
+
});
|
|
1486
1494
|
});
|
|
1487
1495
|
}
|
|
1488
1496
|
}
|
|
1497
|
+
return;
|
|
1489
1498
|
}
|
|
1490
1499
|
function getPath(obj, path) {
|
|
1491
1500
|
return path.split(/[./]/).reduce((o, k) => o?.[k], obj);
|
|
1492
1501
|
}
|
|
1493
1502
|
|
|
1494
|
-
// src/runtime.
|
|
1503
|
+
// src/runtime.ts
|
|
1495
1504
|
async function Jx(source, target = document.body, options) {
|
|
1496
1505
|
const base = typeof source === "string" ? new URL(source, location.href).href : location.href;
|
|
1497
1506
|
const doc = await resolve(source);
|
|
@@ -1510,13 +1519,19 @@ async function Jx(source, target = document.body, options) {
|
|
|
1510
1519
|
state.onMount(state);
|
|
1511
1520
|
return state;
|
|
1512
1521
|
}
|
|
1522
|
+
var _resolveCache = new Map;
|
|
1513
1523
|
async function resolve(source) {
|
|
1514
1524
|
if (typeof source !== "string")
|
|
1515
1525
|
return source;
|
|
1516
|
-
|
|
1517
|
-
|
|
1518
|
-
|
|
1519
|
-
|
|
1526
|
+
if (_resolveCache.has(source))
|
|
1527
|
+
return _resolveCache.get(source);
|
|
1528
|
+
const p = fetch(source).then((res) => {
|
|
1529
|
+
if (!res.ok)
|
|
1530
|
+
throw new Error(`Jx: failed to fetch ${source} (${res.status})`);
|
|
1531
|
+
return res.json();
|
|
1532
|
+
});
|
|
1533
|
+
_resolveCache.set(source, p);
|
|
1534
|
+
return p;
|
|
1520
1535
|
}
|
|
1521
1536
|
var SCHEMA_KEYWORDS = new Set([
|
|
1522
1537
|
"type",
|
|
@@ -1570,17 +1585,18 @@ async function buildScope(doc, parentScope = {}, base = location.href) {
|
|
|
1570
1585
|
continue;
|
|
1571
1586
|
}
|
|
1572
1587
|
if (typeof def2 === "object") {
|
|
1573
|
-
|
|
1588
|
+
const d = def2;
|
|
1589
|
+
if (d.$prototype)
|
|
1574
1590
|
continue;
|
|
1575
|
-
if ("$expression" in
|
|
1591
|
+
if ("$expression" in d)
|
|
1576
1592
|
continue;
|
|
1577
|
-
if (
|
|
1593
|
+
if (d.timing === "server" && d.$src && d.$export)
|
|
1578
1594
|
continue;
|
|
1579
|
-
if ("default" in
|
|
1580
|
-
raw[key] =
|
|
1595
|
+
if ("default" in d) {
|
|
1596
|
+
raw[key] = d.default;
|
|
1581
1597
|
continue;
|
|
1582
1598
|
}
|
|
1583
|
-
if (hasSchemaKeywords(
|
|
1599
|
+
if (hasSchemaKeywords(d))
|
|
1584
1600
|
continue;
|
|
1585
1601
|
raw[key] = def2;
|
|
1586
1602
|
}
|
|
@@ -1818,12 +1834,13 @@ function applyProperties(el, def2, state) {
|
|
|
1818
1834
|
function bindProperty(el, key, val, state) {
|
|
1819
1835
|
const target = el;
|
|
1820
1836
|
if (isRefObj(val)) {
|
|
1837
|
+
const refVal = val;
|
|
1821
1838
|
if (key === "id") {
|
|
1822
|
-
target[key] = resolveRef(
|
|
1839
|
+
target[key] = resolveRef(refVal.$ref, state);
|
|
1823
1840
|
return;
|
|
1824
1841
|
}
|
|
1825
1842
|
effect(() => {
|
|
1826
|
-
target[key] = resolveRef(
|
|
1843
|
+
target[key] = resolveRef(refVal.$ref, state);
|
|
1827
1844
|
});
|
|
1828
1845
|
return;
|
|
1829
1846
|
}
|
|
@@ -2249,6 +2266,10 @@ async function importAndInstantiate(def2, src, exportName, base) {
|
|
|
2249
2266
|
async function resolveClassJson(def2, state, key, base) {
|
|
2250
2267
|
const src = def2.$src;
|
|
2251
2268
|
let classDef;
|
|
2269
|
+
const isBareSpecifier = !src.startsWith(".") && !src.startsWith("/") && !src.startsWith("http") && !src.startsWith("file:");
|
|
2270
|
+
if (isBareSpecifier) {
|
|
2271
|
+
return resolveViaDevProxy(def2, state, key, base);
|
|
2272
|
+
}
|
|
2252
2273
|
try {
|
|
2253
2274
|
const url = base ? new URL(src, base).href : src;
|
|
2254
2275
|
const res = await fetch(url);
|
|
@@ -2581,9 +2602,13 @@ function injectHead(entries, _base) {
|
|
|
2581
2602
|
document.head.appendChild(el);
|
|
2582
2603
|
}
|
|
2583
2604
|
}
|
|
2605
|
+
var _definedSources = new Set;
|
|
2584
2606
|
async function defineElement(source, base) {
|
|
2585
2607
|
if (typeof source === "string") {
|
|
2586
2608
|
base = new URL(source, base ?? location.href).href;
|
|
2609
|
+
if (_definedSources.has(base))
|
|
2610
|
+
return;
|
|
2611
|
+
_definedSources.add(base);
|
|
2587
2612
|
source = await resolve(source);
|
|
2588
2613
|
}
|
|
2589
2614
|
base = base ?? location.href;
|
|
@@ -2601,6 +2626,8 @@ async function defineElement(source, base) {
|
|
|
2601
2626
|
const def2 = source_;
|
|
2602
2627
|
const observedAttrs = def2.observedAttributes ?? [];
|
|
2603
2628
|
const ElementClass = class extends HTMLElement {
|
|
2629
|
+
_jxInitialized = false;
|
|
2630
|
+
_state = null;
|
|
2604
2631
|
static get observedAttributes() {
|
|
2605
2632
|
return observedAttrs;
|
|
2606
2633
|
}
|
|
@@ -2653,29 +2680,26 @@ async function defineElement(source, base) {
|
|
|
2653
2680
|
}
|
|
2654
2681
|
}
|
|
2655
2682
|
disconnectedCallback() {
|
|
2656
|
-
|
|
2657
|
-
|
|
2658
|
-
self2._state.onUnmount(self2._state);
|
|
2683
|
+
if (typeof this._state?.onUnmount === "function") {
|
|
2684
|
+
this._state.onUnmount(this._state);
|
|
2659
2685
|
}
|
|
2660
2686
|
}
|
|
2661
2687
|
adoptedCallback() {
|
|
2662
|
-
|
|
2663
|
-
|
|
2664
|
-
self2._state.onAdopted(self2._state);
|
|
2688
|
+
if (typeof this._state?.onAdopted === "function") {
|
|
2689
|
+
this._state.onAdopted(this._state);
|
|
2665
2690
|
}
|
|
2666
2691
|
}
|
|
2667
2692
|
attributeChangedCallback(name, oldVal, newVal) {
|
|
2668
|
-
|
|
2669
|
-
if (!self2._state || oldVal === newVal)
|
|
2693
|
+
if (!this._state || oldVal === newVal)
|
|
2670
2694
|
return;
|
|
2671
2695
|
const camelKey = name.replace(/-([a-z])/g, (_, c) => c.toUpperCase());
|
|
2672
|
-
const current =
|
|
2696
|
+
const current = this._state[camelKey];
|
|
2673
2697
|
if (typeof current === "number")
|
|
2674
|
-
|
|
2698
|
+
this._state[camelKey] = Number(newVal);
|
|
2675
2699
|
else if (typeof current === "boolean")
|
|
2676
|
-
|
|
2700
|
+
this._state[camelKey] = newVal !== null && newVal !== "false";
|
|
2677
2701
|
else
|
|
2678
|
-
|
|
2702
|
+
this._state[camelKey] = newVal;
|
|
2679
2703
|
}
|
|
2680
2704
|
};
|
|
2681
2705
|
customElements.define(tagName, ElementClass);
|
|
@@ -2686,10 +2710,11 @@ function renderCustomElementWithProps(def2, state, options, path) {
|
|
|
2686
2710
|
options.onNodeCreated(el, path ?? [], def2);
|
|
2687
2711
|
for (const [key, val] of Object.entries(def2.$props ?? {})) {
|
|
2688
2712
|
if (isRefObj(val)) {
|
|
2689
|
-
const
|
|
2713
|
+
const refVal = val;
|
|
2714
|
+
const resolved = resolveRef(refVal.$ref, state);
|
|
2690
2715
|
el[key] = resolved;
|
|
2691
2716
|
effect(() => {
|
|
2692
|
-
el[key] = resolveRef(
|
|
2717
|
+
el[key] = resolveRef(refVal.$ref, state);
|
|
2693
2718
|
});
|
|
2694
2719
|
} else if (isTemplateString(val)) {
|
|
2695
2720
|
effect(() => {
|
|
@@ -2755,5 +2780,5 @@ export {
|
|
|
2755
2780
|
Jx
|
|
2756
2781
|
};
|
|
2757
2782
|
|
|
2758
|
-
//# debugId=
|
|
2783
|
+
//# debugId=980C6F32C0CBE36F64756E2164756E21
|
|
2759
2784
|
//# sourceMappingURL=runtime.js.map
|