@jxsuite/runtime 1.3.2 → 2.0.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 +228 -66
- package/dist/runtime.js.map +11 -8
- package/package.json +5 -4
- package/src/cookie.ts +104 -0
- package/src/expression.ts +146 -43
- package/src/pointer.ts +130 -0
- package/src/runtime.ts +140 -46
package/dist/runtime.js
CHANGED
|
@@ -44,7 +44,7 @@ var toHandlerKey = cacheStringFunction((str) => {
|
|
|
44
44
|
});
|
|
45
45
|
var hasChanged = (value, oldValue) => !Object.is(value, oldValue);
|
|
46
46
|
var specialBooleanAttrs = `itemscope,allowfullscreen,formnovalidate,ismap,nomodule,novalidate,readonly`;
|
|
47
|
-
var isBooleanAttr = /* @__PURE__ */ makeMap(specialBooleanAttrs + `,async,autofocus,autoplay,controls,default,defer,disabled,
|
|
47
|
+
var isBooleanAttr = /* @__PURE__ */ makeMap(specialBooleanAttrs + `,async,autofocus,autoplay,controls,default,defer,disabled,inert,loop,open,required,reversed,scoped,seamless,checked,muted,multiple,selected`);
|
|
48
48
|
|
|
49
49
|
// ../../node_modules/@vue/reactivity/dist/reactivity.esm-bundler.js
|
|
50
50
|
function warn(msg, ...args) {
|
|
@@ -1384,6 +1384,80 @@ function computed(getterOrOptions, debugOptions, isSSR = false) {
|
|
|
1384
1384
|
return cRef;
|
|
1385
1385
|
}
|
|
1386
1386
|
|
|
1387
|
+
// ../schema/src/intl.ts
|
|
1388
|
+
var DEFAULT_FORMAT_LOCALE = "en-US";
|
|
1389
|
+
var DEFAULT_TIME_ZONE = "UTC";
|
|
1390
|
+
var INTL_HELPERS = [
|
|
1391
|
+
{
|
|
1392
|
+
api: "Intl.NumberFormat",
|
|
1393
|
+
params: ["value", "locale", "options"],
|
|
1394
|
+
path: "Intl/formatNumber",
|
|
1395
|
+
summary: "Format a number for a locale — grouping, decimals, currency, percent, units."
|
|
1396
|
+
},
|
|
1397
|
+
{
|
|
1398
|
+
api: "Intl.DateTimeFormat",
|
|
1399
|
+
params: ["value", "locale", "options"],
|
|
1400
|
+
path: "Intl/formatDate",
|
|
1401
|
+
summary: "Format a date or timestamp for a locale. Pass `timeZone` in options."
|
|
1402
|
+
},
|
|
1403
|
+
{
|
|
1404
|
+
api: "Intl.RelativeTimeFormat",
|
|
1405
|
+
params: ["value", "unit", "locale", "options"],
|
|
1406
|
+
path: "Intl/formatRelativeTime",
|
|
1407
|
+
summary: 'Format a relative time — `-3, "day"` becomes "3 days ago".'
|
|
1408
|
+
},
|
|
1409
|
+
{
|
|
1410
|
+
api: "Intl.ListFormat",
|
|
1411
|
+
params: ["values", "locale", "options"],
|
|
1412
|
+
path: "Intl/formatList",
|
|
1413
|
+
summary: 'Join a list the way a locale does — "a, b, and c", not a hand-written comma join.'
|
|
1414
|
+
},
|
|
1415
|
+
{
|
|
1416
|
+
api: "Intl.PluralRules",
|
|
1417
|
+
params: ["value", "locale", "options"],
|
|
1418
|
+
path: "Intl/plural",
|
|
1419
|
+
summary: 'Which plural category a number falls in ("one", "few", "other") — many languages have ' + "more than two, so a ternary on `n === 1` is wrong outside English."
|
|
1420
|
+
},
|
|
1421
|
+
{
|
|
1422
|
+
api: "Intl.Collator",
|
|
1423
|
+
params: ["a", "b", "locale", "options"],
|
|
1424
|
+
path: "Intl/compare",
|
|
1425
|
+
summary: "Compare two strings for sorting. `<` and `sort()` order by UTF-16 code unit, which puts " + '"Zebra" before "apple" and sorts every accented word into the wrong place.'
|
|
1426
|
+
},
|
|
1427
|
+
{
|
|
1428
|
+
api: "Intl.DisplayNames",
|
|
1429
|
+
params: ["code", "type", "locale", "options"],
|
|
1430
|
+
path: "Intl/displayName",
|
|
1431
|
+
summary: 'The name of a language, region, script or currency in a locale — "de" as "German" or ' + '"Deutsch", from CLDR rather than a hand-kept table.'
|
|
1432
|
+
},
|
|
1433
|
+
{
|
|
1434
|
+
api: "Intl.Segmenter",
|
|
1435
|
+
params: ["value", "granularity", "locale"],
|
|
1436
|
+
path: "Intl/segment",
|
|
1437
|
+
summary: "Split text into graphemes, words or sentences (UAX #29). `[...str]` splits code points, " + "so it cuts an emoji with a skin-tone modifier in half."
|
|
1438
|
+
}
|
|
1439
|
+
];
|
|
1440
|
+
var INTL_HELPER_PATHS = INTL_HELPERS.map((helper) => helper.path);
|
|
1441
|
+
var INTL_LOCALE_PARAM = Object.fromEntries(INTL_HELPERS.map((helper) => [helper.path, helper.params.indexOf("locale")]));
|
|
1442
|
+
|
|
1443
|
+
// src/pointer.ts
|
|
1444
|
+
function unescapeToken(token) {
|
|
1445
|
+
return token.replaceAll("~1", "/").replaceAll("~0", "~");
|
|
1446
|
+
}
|
|
1447
|
+
function refSegments(path) {
|
|
1448
|
+
if (path === "") {
|
|
1449
|
+
return [];
|
|
1450
|
+
}
|
|
1451
|
+
return path.split("/").map((token) => unescapeToken(token));
|
|
1452
|
+
}
|
|
1453
|
+
function readPath(root, path) {
|
|
1454
|
+
let current = root;
|
|
1455
|
+
for (const key of refSegments(path)) {
|
|
1456
|
+
current = current?.[key];
|
|
1457
|
+
}
|
|
1458
|
+
return current;
|
|
1459
|
+
}
|
|
1460
|
+
|
|
1387
1461
|
// src/expression.ts
|
|
1388
1462
|
function scopeMap(state) {
|
|
1389
1463
|
const map = state.$map;
|
|
@@ -1504,15 +1578,42 @@ var BLESSED_GLOBALS = new Set([
|
|
|
1504
1578
|
"Array/of",
|
|
1505
1579
|
"String/fromCharCode",
|
|
1506
1580
|
"String/fromCodePoint",
|
|
1507
|
-
|
|
1508
|
-
"Intl/formatDate",
|
|
1509
|
-
"Intl/formatRelativeTime"
|
|
1581
|
+
...INTL_HELPER_PATHS
|
|
1510
1582
|
]);
|
|
1511
1583
|
var BLESSED_HELPERS = {
|
|
1512
|
-
"Intl/
|
|
1513
|
-
"Intl/
|
|
1514
|
-
|
|
1584
|
+
"Intl/compare": (a, b, locale, options) => new Intl.Collator(locale ?? DEFAULT_FORMAT_LOCALE, options).compare(a, b),
|
|
1585
|
+
"Intl/displayName": (code, type, locale, options) => new Intl.DisplayNames(locale ?? DEFAULT_FORMAT_LOCALE, {
|
|
1586
|
+
...options,
|
|
1587
|
+
type: type ?? "language"
|
|
1588
|
+
}).of(code),
|
|
1589
|
+
"Intl/formatDate": (value, locale, options) => new Intl.DateTimeFormat(locale ?? DEFAULT_FORMAT_LOCALE, {
|
|
1590
|
+
timeZone: DEFAULT_TIME_ZONE,
|
|
1591
|
+
...options
|
|
1592
|
+
}).format(new Date(value)),
|
|
1593
|
+
"Intl/formatList": (values, locale, options) => new Intl.ListFormat(locale ?? DEFAULT_FORMAT_LOCALE, options).format(values),
|
|
1594
|
+
"Intl/formatNumber": (value, locale, options) => new Intl.NumberFormat(locale ?? DEFAULT_FORMAT_LOCALE, options).format(value),
|
|
1595
|
+
"Intl/formatRelativeTime": (value, unit, locale, options) => new Intl.RelativeTimeFormat(locale ?? DEFAULT_FORMAT_LOCALE, options).format(value, unit),
|
|
1596
|
+
"Intl/plural": (value, locale, options) => new Intl.PluralRules(locale ?? DEFAULT_FORMAT_LOCALE, options).select(value),
|
|
1597
|
+
"Intl/segment": (value, granularity, locale) => [
|
|
1598
|
+
...new Intl.Segmenter(locale ?? DEFAULT_FORMAT_LOCALE, {
|
|
1599
|
+
granularity: granularity ?? "grapheme"
|
|
1600
|
+
}).segment(value)
|
|
1601
|
+
].map((part) => part.segment)
|
|
1515
1602
|
};
|
|
1603
|
+
function withPageLocale(path, args, state) {
|
|
1604
|
+
const index = INTL_LOCALE_PARAM[path];
|
|
1605
|
+
if (index === undefined || index < 0 || args[index] != null) {
|
|
1606
|
+
return args;
|
|
1607
|
+
}
|
|
1608
|
+
const page = state.$page;
|
|
1609
|
+
const locale = page?.locale;
|
|
1610
|
+
if (typeof locale !== "string" || locale === "") {
|
|
1611
|
+
return args;
|
|
1612
|
+
}
|
|
1613
|
+
const filled = [...args];
|
|
1614
|
+
filled[index] = locale;
|
|
1615
|
+
return filled;
|
|
1616
|
+
}
|
|
1516
1617
|
function isBlessedGlobal(ref2) {
|
|
1517
1618
|
return ref2.startsWith("window#/") && BLESSED_GLOBALS.has(ref2.slice("window#/".length));
|
|
1518
1619
|
}
|
|
@@ -1584,15 +1685,10 @@ function resolveExprRef(ref2, state, event, iterCtx) {
|
|
|
1584
1685
|
return parts.length > 2 ? getPath(base, parts.slice(2).join("/")) : base;
|
|
1585
1686
|
}
|
|
1586
1687
|
if (ref2.startsWith("#/state/")) {
|
|
1587
|
-
|
|
1588
|
-
const slash = sub.indexOf("/");
|
|
1589
|
-
if (slash === -1) {
|
|
1590
|
-
return state[sub];
|
|
1591
|
-
}
|
|
1592
|
-
return getPath(state[sub.slice(0, slash)], sub.slice(slash + 1));
|
|
1688
|
+
return readPath(state, ref2.slice("#/state/".length));
|
|
1593
1689
|
}
|
|
1594
1690
|
if (ref2.startsWith("parent#/")) {
|
|
1595
|
-
return state
|
|
1691
|
+
return readPath(state, ref2.slice("parent#/".length));
|
|
1596
1692
|
}
|
|
1597
1693
|
if (ref2.startsWith("window#/")) {
|
|
1598
1694
|
return getPath(globalThis.window, ref2.slice("window#/".length));
|
|
@@ -1600,7 +1696,7 @@ function resolveExprRef(ref2, state, event, iterCtx) {
|
|
|
1600
1696
|
if (ref2.startsWith("document#/")) {
|
|
1601
1697
|
return getPath(globalThis.document, ref2.slice("document#/".length));
|
|
1602
1698
|
}
|
|
1603
|
-
return state
|
|
1699
|
+
return readPath(state, ref2) ?? null;
|
|
1604
1700
|
}
|
|
1605
1701
|
function resolveWritableRef(ref2, state, _event, iterCtx) {
|
|
1606
1702
|
if (ref2.startsWith("$map/")) {
|
|
@@ -1632,7 +1728,7 @@ function resolveWritableRef(ref2, state, _event, iterCtx) {
|
|
|
1632
1728
|
if (slash === -1) {
|
|
1633
1729
|
return { key: sub, obj: state };
|
|
1634
1730
|
}
|
|
1635
|
-
const parts = sub
|
|
1731
|
+
const parts = refSegments(sub);
|
|
1636
1732
|
const lastKey = parts.pop();
|
|
1637
1733
|
let obj = state;
|
|
1638
1734
|
for (const p of parts) {
|
|
@@ -1678,7 +1774,7 @@ function evaluateNode(node, state, event, iterCtx, trace) {
|
|
|
1678
1774
|
const globalPath = calleeRef.slice("window#/".length);
|
|
1679
1775
|
const helper = BLESSED_HELPERS[globalPath];
|
|
1680
1776
|
if (helper) {
|
|
1681
|
-
return helper(...argValues);
|
|
1777
|
+
return helper(...withPageLocale(globalPath, argValues, state));
|
|
1682
1778
|
}
|
|
1683
1779
|
const fn = getPath(globalThis.window, globalPath);
|
|
1684
1780
|
const lastSlash = globalPath.lastIndexOf("/");
|
|
@@ -1867,11 +1963,7 @@ function evaluateNode(node, state, event, iterCtx, trace) {
|
|
|
1867
1963
|
return;
|
|
1868
1964
|
}
|
|
1869
1965
|
function getPath(obj, path) {
|
|
1870
|
-
|
|
1871
|
-
for (const k of path.split(/[./]/)) {
|
|
1872
|
-
current = current?.[k];
|
|
1873
|
-
}
|
|
1874
|
-
return current;
|
|
1966
|
+
return readPath(obj, path);
|
|
1875
1967
|
}
|
|
1876
1968
|
function evaluateOperand(operand, state, event, iterCtx) {
|
|
1877
1969
|
return resolveOperand(operand, state, event, iterCtx);
|
|
@@ -1933,6 +2025,12 @@ function paramNames(parameters) {
|
|
|
1933
2025
|
}
|
|
1934
2026
|
return parameters.map((p) => typeof p === "string" ? p : p.name);
|
|
1935
2027
|
}
|
|
2028
|
+
function isTagExpression(tagName) {
|
|
2029
|
+
return isJsonObject(tagName) && isJsonObject(tagName.$expression);
|
|
2030
|
+
}
|
|
2031
|
+
function isPrivateStateKey(key) {
|
|
2032
|
+
return key.startsWith("#");
|
|
2033
|
+
}
|
|
1936
2034
|
|
|
1937
2035
|
// src/statements.ts
|
|
1938
2036
|
function statementKind(statement) {
|
|
@@ -2002,6 +2100,45 @@ async function runStatements(statements, state, event, opts = {}) {
|
|
|
2002
2100
|
}
|
|
2003
2101
|
}
|
|
2004
2102
|
|
|
2103
|
+
// src/cookie.ts
|
|
2104
|
+
var HOST_PREFIX = "__Host-";
|
|
2105
|
+
var SECURE_PREFIX = "__Secure-";
|
|
2106
|
+
function readCookie(header, name) {
|
|
2107
|
+
for (const pair of header.split(";")) {
|
|
2108
|
+
const eq = pair.indexOf("=");
|
|
2109
|
+
if (eq === -1) {
|
|
2110
|
+
continue;
|
|
2111
|
+
}
|
|
2112
|
+
if (pair.slice(0, eq).trim() === name) {
|
|
2113
|
+
return pair.slice(eq + 1);
|
|
2114
|
+
}
|
|
2115
|
+
}
|
|
2116
|
+
return null;
|
|
2117
|
+
}
|
|
2118
|
+
function serializeCookie(name, value, options) {
|
|
2119
|
+
const hostPrefixed = name.startsWith(HOST_PREFIX);
|
|
2120
|
+
const parts = [`${name}=${encodeURIComponent(JSON.stringify(value))}`];
|
|
2121
|
+
if (options.maxAge !== undefined) {
|
|
2122
|
+
parts.push(`Max-Age=${options.maxAge}`);
|
|
2123
|
+
}
|
|
2124
|
+
const path = hostPrefixed ? "/" : options.path;
|
|
2125
|
+
if (path) {
|
|
2126
|
+
parts.push(`Path=${path}`);
|
|
2127
|
+
}
|
|
2128
|
+
if (options.domain && !hostPrefixed) {
|
|
2129
|
+
parts.push(`Domain=${options.domain}`);
|
|
2130
|
+
}
|
|
2131
|
+
const { sameSite } = options;
|
|
2132
|
+
const secure = options.secure === true || hostPrefixed || name.startsWith(SECURE_PREFIX) || sameSite?.toLowerCase() === "none";
|
|
2133
|
+
if (secure) {
|
|
2134
|
+
parts.push("Secure");
|
|
2135
|
+
}
|
|
2136
|
+
if (sameSite) {
|
|
2137
|
+
parts.push(`SameSite=${sameSite}`);
|
|
2138
|
+
}
|
|
2139
|
+
return parts.join("; ");
|
|
2140
|
+
}
|
|
2141
|
+
|
|
2005
2142
|
// src/runtime.ts
|
|
2006
2143
|
var SUPPORTED_SCHEMA_VERSION = 1;
|
|
2007
2144
|
var _schemaVersionWarned = false;
|
|
@@ -2430,7 +2567,7 @@ function renderNode(def2, state, options) {
|
|
|
2430
2567
|
console.warn(`Jx: a $ref child ("${refTarget}") is not a supported component instance; register the ` + `component in $elements and use its custom-element tag instead (spec §13).`);
|
|
2431
2568
|
}
|
|
2432
2569
|
}
|
|
2433
|
-
const tagName = def2.tagName
|
|
2570
|
+
const tagName = resolveTagName(def2.tagName, localState);
|
|
2434
2571
|
const isCustomEl = tagName.includes("-") && customElements.get(tagName);
|
|
2435
2572
|
if (def2.$props && isCustomEl) {
|
|
2436
2573
|
return renderCustomElementWithProps(def2, localState, options, path);
|
|
@@ -2730,9 +2867,23 @@ function renderMappedArrayInto(parentEl, arrayDef, state, options) {
|
|
|
2730
2867
|
});
|
|
2731
2868
|
});
|
|
2732
2869
|
}
|
|
2870
|
+
function resolveTagName(tagName, scope) {
|
|
2871
|
+
if (typeof tagName === "string") {
|
|
2872
|
+
return tagName;
|
|
2873
|
+
}
|
|
2874
|
+
if (!isTagExpression(tagName)) {
|
|
2875
|
+
return "div";
|
|
2876
|
+
}
|
|
2877
|
+
const expression = tagName.$expression;
|
|
2878
|
+
if (expression.operator === "?:") {
|
|
2879
|
+
return evaluateOperand(expression.target, scope, null) ? expression.value : expression.initial;
|
|
2880
|
+
}
|
|
2881
|
+
const key = evaluateOperand(expression.target, scope, null);
|
|
2882
|
+
return expression.cases[String(key)] ?? expression.default;
|
|
2883
|
+
}
|
|
2733
2884
|
function renderSwitch(def2, state, options) {
|
|
2734
2885
|
const path = options?._path ?? [];
|
|
2735
|
-
const container = document.createElement(def2.tagName
|
|
2886
|
+
const container = document.createElement(resolveTagName(def2.tagName, state));
|
|
2736
2887
|
if (options?.onNodeCreated) {
|
|
2737
2888
|
options.onNodeCreated(container, path, def2, state);
|
|
2738
2889
|
}
|
|
@@ -2741,7 +2892,7 @@ function renderSwitch(def2, state, options) {
|
|
|
2741
2892
|
applyAttributes(container, def2.attributes ?? {}, state);
|
|
2742
2893
|
let generation = 0;
|
|
2743
2894
|
effect(() => {
|
|
2744
|
-
container.
|
|
2895
|
+
container.replaceChildren();
|
|
2745
2896
|
if (!isRefObj(def2.$switch)) {
|
|
2746
2897
|
return;
|
|
2747
2898
|
}
|
|
@@ -2751,7 +2902,8 @@ function renderSwitch(def2, state, options) {
|
|
|
2751
2902
|
return;
|
|
2752
2903
|
}
|
|
2753
2904
|
if (isRefObj(caseDef)) {
|
|
2754
|
-
|
|
2905
|
+
generation += 1;
|
|
2906
|
+
const gen = generation;
|
|
2755
2907
|
const { href } = new URL(caseDef.$ref, location.href);
|
|
2756
2908
|
resolve(href).then(async (doc) => {
|
|
2757
2909
|
if (gen !== generation) {
|
|
@@ -2761,7 +2913,7 @@ function renderSwitch(def2, state, options) {
|
|
|
2761
2913
|
if (gen !== generation) {
|
|
2762
2914
|
return;
|
|
2763
2915
|
}
|
|
2764
|
-
container.
|
|
2916
|
+
container.replaceChildren();
|
|
2765
2917
|
const childOpts2 = options ? { ...options, _path: [...path, "cases", key] } : undefined;
|
|
2766
2918
|
container.append(renderNode(doc, childScope, childOpts2));
|
|
2767
2919
|
}).catch((error) => console.error("Jx $switch: failed to load external case", caseDef.$ref, error));
|
|
@@ -2862,36 +3014,19 @@ async function resolvePrototype(def2, state, key, base) {
|
|
|
2862
3014
|
case "Cookie": {
|
|
2863
3015
|
const name = def2.name ?? key;
|
|
2864
3016
|
const read = () => {
|
|
2865
|
-
const
|
|
2866
|
-
if (
|
|
3017
|
+
const raw = readCookie(document.cookie, name);
|
|
3018
|
+
if (raw === null) {
|
|
2867
3019
|
return null;
|
|
2868
3020
|
}
|
|
2869
3021
|
try {
|
|
2870
|
-
return JSON.parse(decodeURIComponent(
|
|
3022
|
+
return JSON.parse(decodeURIComponent(raw));
|
|
2871
3023
|
} catch {
|
|
2872
|
-
return
|
|
3024
|
+
return raw;
|
|
2873
3025
|
}
|
|
2874
3026
|
};
|
|
2875
3027
|
const cookieState = ref(read() ?? def2.default ?? null);
|
|
2876
3028
|
effect(() => {
|
|
2877
|
-
|
|
2878
|
-
let s = `${name}=${encodeURIComponent(JSON.stringify(v))}`;
|
|
2879
|
-
if (def2.maxAge !== undefined) {
|
|
2880
|
-
s += `; Max-Age=${def2.maxAge}`;
|
|
2881
|
-
}
|
|
2882
|
-
if (def2.path) {
|
|
2883
|
-
s += `; Path=${def2.path}`;
|
|
2884
|
-
}
|
|
2885
|
-
if (def2.domain) {
|
|
2886
|
-
s += `; Domain=${def2.domain}`;
|
|
2887
|
-
}
|
|
2888
|
-
if (def2.secure) {
|
|
2889
|
-
s += `; Secure`;
|
|
2890
|
-
}
|
|
2891
|
-
if (def2.sameSite) {
|
|
2892
|
-
s += `; SameSite=${def2.sameSite}`;
|
|
2893
|
-
}
|
|
2894
|
-
document.cookie = s;
|
|
3029
|
+
document.cookie = serializeCookie(name, cookieState.value, def2);
|
|
2895
3030
|
});
|
|
2896
3031
|
return cookieState;
|
|
2897
3032
|
}
|
|
@@ -3299,15 +3434,10 @@ function resolveRef(refPath, state) {
|
|
|
3299
3434
|
return parts.length > 2 ? getPath2(base, parts.slice(2).join("/")) : base;
|
|
3300
3435
|
}
|
|
3301
3436
|
if (refPath.startsWith("#/state/")) {
|
|
3302
|
-
|
|
3303
|
-
const slash = sub.indexOf("/");
|
|
3304
|
-
if (slash === -1) {
|
|
3305
|
-
return state[sub];
|
|
3306
|
-
}
|
|
3307
|
-
return getPath2(state[sub.slice(0, slash)], sub.slice(slash + 1));
|
|
3437
|
+
return readPath(state, refPath.slice("#/state/".length));
|
|
3308
3438
|
}
|
|
3309
3439
|
if (refPath.startsWith("parent#/")) {
|
|
3310
|
-
return state
|
|
3440
|
+
return readPath(state, refPath.slice("parent#/".length));
|
|
3311
3441
|
}
|
|
3312
3442
|
if (refPath.startsWith("window#/")) {
|
|
3313
3443
|
return getPath2(globalThis.window, refPath.slice("window#/".length));
|
|
@@ -3315,7 +3445,7 @@ function resolveRef(refPath, state) {
|
|
|
3315
3445
|
if (refPath.startsWith("document#/")) {
|
|
3316
3446
|
return getPath2(globalThis.document, refPath.slice("document#/".length));
|
|
3317
3447
|
}
|
|
3318
|
-
return state
|
|
3448
|
+
return readPath(state, refPath) ?? null;
|
|
3319
3449
|
}
|
|
3320
3450
|
function isSignal(v) {
|
|
3321
3451
|
return isRef(v);
|
|
@@ -3327,15 +3457,29 @@ function isNestedSelector(k) {
|
|
|
3327
3457
|
return k.startsWith(":") || k.startsWith(".") || k.startsWith("&") || k.startsWith("[");
|
|
3328
3458
|
}
|
|
3329
3459
|
function getPath2(obj, path) {
|
|
3330
|
-
|
|
3331
|
-
|
|
3332
|
-
|
|
3460
|
+
return readPath(obj, path);
|
|
3461
|
+
}
|
|
3462
|
+
var _privatePropWarned = new Set;
|
|
3463
|
+
function refusePrivateProp(key, where) {
|
|
3464
|
+
if (!isPrivateStateKey(key)) {
|
|
3465
|
+
return false;
|
|
3333
3466
|
}
|
|
3334
|
-
|
|
3467
|
+
const seen = where === undefined ? key : `${where}:${key}`;
|
|
3468
|
+
if (!_privatePropWarned.has(seen)) {
|
|
3469
|
+
_privatePropWarned.add(seen);
|
|
3470
|
+
console.warn(`Jx: "${key}" is private state (spec.md §5.6) and cannot be set through $props` + `${where === undefined ? "" : ` (${where})`}. The write was ignored; rename the entry without the leading # to make it part of the component's interface.`);
|
|
3471
|
+
}
|
|
3472
|
+
return true;
|
|
3473
|
+
}
|
|
3474
|
+
function _resetPrivatePropWarnings() {
|
|
3475
|
+
_privatePropWarned.clear();
|
|
3335
3476
|
}
|
|
3336
3477
|
function mergeProps(def2, parentState) {
|
|
3337
3478
|
const child = Object.create(parentState);
|
|
3338
3479
|
for (const [k, v] of Object.entries(def2.$props ?? {})) {
|
|
3480
|
+
if (refusePrivateProp(k, "$props")) {
|
|
3481
|
+
continue;
|
|
3482
|
+
}
|
|
3339
3483
|
child[k] = isRefObj(v) ? resolveRef(v.$ref, parentState) : v;
|
|
3340
3484
|
}
|
|
3341
3485
|
return child;
|
|
@@ -3419,7 +3563,7 @@ function injectHead(entries, _base) {
|
|
|
3419
3563
|
el.setAttribute(k, String(v));
|
|
3420
3564
|
}
|
|
3421
3565
|
if (entry.textContent) {
|
|
3422
|
-
el.textContent = entry.textContent;
|
|
3566
|
+
el.textContent = typeof entry.textContent === "object" ? JSON.stringify(entry.textContent, null, 2) : entry.textContent;
|
|
3423
3567
|
}
|
|
3424
3568
|
document.head.append(el);
|
|
3425
3569
|
}
|
|
@@ -3471,6 +3615,9 @@ async function defineElement(source, baseUrl) {
|
|
|
3471
3615
|
try {
|
|
3472
3616
|
const props = JSON.parse(propsAttr);
|
|
3473
3617
|
for (const [key, val] of Object.entries(props)) {
|
|
3618
|
+
if (refusePrivateProp(key, "data-jx-props")) {
|
|
3619
|
+
continue;
|
|
3620
|
+
}
|
|
3474
3621
|
if (key in (def2.state ?? {})) {
|
|
3475
3622
|
state[key] = val;
|
|
3476
3623
|
}
|
|
@@ -3481,17 +3628,27 @@ async function defineElement(source, baseUrl) {
|
|
|
3481
3628
|
const propAttrNames = this.getAttributeNames().filter((name) => name.startsWith("props.") && name.length > "props.".length);
|
|
3482
3629
|
for (const name of propAttrNames) {
|
|
3483
3630
|
const key = name.slice("props.".length);
|
|
3631
|
+
if (refusePrivateProp(key, "props.* attribute")) {
|
|
3632
|
+
this.removeAttribute(name);
|
|
3633
|
+
continue;
|
|
3634
|
+
}
|
|
3484
3635
|
if (key in (def2.state ?? {})) {
|
|
3485
3636
|
state[key] = this.getAttribute(name);
|
|
3486
3637
|
this.removeAttribute(name);
|
|
3487
3638
|
}
|
|
3488
3639
|
}
|
|
3489
3640
|
for (const key of Object.keys(def2.state ?? {})) {
|
|
3641
|
+
if (isPrivateStateKey(key)) {
|
|
3642
|
+
continue;
|
|
3643
|
+
}
|
|
3490
3644
|
if (key in this && this[key] !== undefined) {
|
|
3491
3645
|
state[key] = this[key];
|
|
3492
3646
|
}
|
|
3493
3647
|
}
|
|
3494
3648
|
for (const key of Object.keys(def2.state ?? {})) {
|
|
3649
|
+
if (isPrivateStateKey(key)) {
|
|
3650
|
+
continue;
|
|
3651
|
+
}
|
|
3495
3652
|
if (!(key in HTMLElement.prototype)) {
|
|
3496
3653
|
Object.defineProperty(this, key, {
|
|
3497
3654
|
configurable: true,
|
|
@@ -3504,7 +3661,7 @@ async function defineElement(source, baseUrl) {
|
|
|
3504
3661
|
}
|
|
3505
3662
|
this._state = state;
|
|
3506
3663
|
const slottedChildren = [...this.childNodes];
|
|
3507
|
-
this.
|
|
3664
|
+
this.replaceChildren();
|
|
3508
3665
|
if (!this.style.display) {
|
|
3509
3666
|
this.style.display = "block";
|
|
3510
3667
|
}
|
|
@@ -3548,11 +3705,14 @@ async function defineElement(source, baseUrl) {
|
|
|
3548
3705
|
customElements.define(tagName, ElementClass);
|
|
3549
3706
|
}
|
|
3550
3707
|
function renderCustomElementWithProps(def2, state, options, path) {
|
|
3551
|
-
const el = document.createElement(def2.tagName
|
|
3708
|
+
const el = document.createElement(resolveTagName(def2.tagName, state));
|
|
3552
3709
|
if (options?.onNodeCreated) {
|
|
3553
3710
|
options.onNodeCreated(el, path ?? [], def2, state);
|
|
3554
3711
|
}
|
|
3555
3712
|
for (const [key, val] of Object.entries(def2.$props ?? {})) {
|
|
3713
|
+
if (refusePrivateProp(key, "$props")) {
|
|
3714
|
+
continue;
|
|
3715
|
+
}
|
|
3556
3716
|
if (isRefObj(val)) {
|
|
3557
3717
|
const refVal = val;
|
|
3558
3718
|
const resolved = resolveRef(refVal.$ref, state);
|
|
@@ -3602,7 +3762,7 @@ function distributeSlots(host, slottedChildren) {
|
|
|
3602
3762
|
const name = slot.getAttribute("name");
|
|
3603
3763
|
const matches = name ? named.get(name) ?? [] : unnamed;
|
|
3604
3764
|
if (matches.length > 0) {
|
|
3605
|
-
slot.
|
|
3765
|
+
slot.replaceChildren();
|
|
3606
3766
|
for (const child of matches) {
|
|
3607
3767
|
slot.append(child);
|
|
3608
3768
|
}
|
|
@@ -3622,6 +3782,7 @@ export {
|
|
|
3622
3782
|
setCanvasDelinkAnchors,
|
|
3623
3783
|
schemeSelectors,
|
|
3624
3784
|
runScoped,
|
|
3785
|
+
resolveTagName,
|
|
3625
3786
|
resolveRef,
|
|
3626
3787
|
resolvePrototype,
|
|
3627
3788
|
resolve,
|
|
@@ -3636,6 +3797,7 @@ export {
|
|
|
3636
3797
|
camelToKebab,
|
|
3637
3798
|
buildScope,
|
|
3638
3799
|
applyStyle,
|
|
3800
|
+
_resetPrivatePropWarnings,
|
|
3639
3801
|
SUPPORTED_SCHEMA_VERSION,
|
|
3640
3802
|
RESERVED_KEYS,
|
|
3641
3803
|
Jx,
|
|
@@ -3643,5 +3805,5 @@ export {
|
|
|
3643
3805
|
COLOR_SCHEME_ATTR
|
|
3644
3806
|
};
|
|
3645
3807
|
|
|
3646
|
-
//# debugId=
|
|
3808
|
+
//# debugId=38D6F60E1C2F6F7A64756E2164756E21
|
|
3647
3809
|
//# sourceMappingURL=runtime.js.map
|