@stacksjs/stx 0.2.657 → 0.2.662
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/{chunk-mgkrnwjk.js → chunk-1hny5z72.js} +1 -1
- package/dist/{chunk-q68rssa6.js → chunk-3ay916gv.js} +1 -1
- package/dist/chunk-4f4agvd0.js +129 -0
- package/dist/{chunk-xmb4ttnf.js → chunk-4jyehvz3.js} +2 -2
- package/dist/{chunk-tnqbck1r.js → chunk-4xdpeky6.js} +1 -1
- package/dist/chunk-4xfpq9yp.js +2 -0
- package/dist/{chunk-s3t9tmsz.js → chunk-51n5rfsk.js} +1 -1
- package/dist/{chunk-kt3nk905.js → chunk-5m8j11b0.js} +1 -1
- package/dist/{chunk-g3tk83ea.js → chunk-61pvye5k.js} +1 -1
- package/dist/{chunk-m0gd0264.js → chunk-6dz6tpkp.js} +1 -1
- package/dist/chunk-6fbxh1we.js +2 -0
- package/dist/chunk-721ba72m.js +2 -0
- package/dist/{chunk-zvj935ma.js → chunk-7m5sqtq5.js} +1 -1
- package/dist/{chunk-nm1ggj8d.js → chunk-8n78w5kh.js} +1 -1
- package/dist/{chunk-vpmfm04j.js → chunk-9jcxrc6t.js} +1 -1
- package/dist/{chunk-zd23z1j8.js → chunk-a3mmhzpa.js} +1 -1
- package/dist/{chunk-a8aqch0j.js → chunk-adxt8qcy.js} +38 -38
- package/dist/{chunk-f9xed7c1.js → chunk-adzrhca1.js} +1 -1
- package/dist/chunk-ap1sydzw.js +2 -0
- package/dist/{chunk-47qc69v1.js → chunk-creeaceg.js} +1 -1
- package/dist/{chunk-ddtmrma9.js → chunk-d419kwfp.js} +1 -1
- package/dist/{chunk-7nx74hdr.js → chunk-d8kfbhhw.js} +1 -1
- package/dist/{chunk-6w8sjav5.js → chunk-dw5bsya8.js} +1 -1
- package/dist/{chunk-fzxx3rad.js → chunk-e3crw545.js} +3 -3
- package/dist/{chunk-vmwdt8fr.js → chunk-een2wqah.js} +6 -6
- package/dist/chunk-eqrkhc18.js +12 -0
- package/dist/chunk-fdfnk654.js +2 -0
- package/dist/{chunk-7gpxz94n.js → chunk-fr4hs814.js} +1 -1
- package/dist/{chunk-h8h2n247.js → chunk-ftskxb7f.js} +5 -5
- package/dist/{chunk-x29qw59w.js → chunk-h2a40417.js} +1 -1
- package/dist/{chunk-gjwyy7kh.js → chunk-h6633jna.js} +86 -86
- package/dist/{chunk-gg3wbfxa.js → chunk-j0dsavn2.js} +1 -1
- package/dist/{chunk-3zbrmm40.js → chunk-k6fyn9gk.js} +1 -1
- package/dist/{chunk-j8g1v38x.js → chunk-ky5kmg7t.js} +1 -1
- package/dist/{chunk-ndn0rmhs.js → chunk-m2h91ccn.js} +1 -1
- package/dist/{chunk-2mppsbt3.js → chunk-m7wb991z.js} +1 -1
- package/dist/{chunk-pcscq080.js → chunk-m89yndgc.js} +1 -1
- package/dist/{chunk-py28zkeh.js → chunk-mayr8s0x.js} +11 -11
- package/dist/{chunk-pbxq1rwd.js → chunk-msvpb1ax.js} +4 -4
- package/dist/chunk-mxdm8sw0.js +2 -0
- package/dist/{chunk-w6kdpx52.js → chunk-n48cshgz.js} +5 -5
- package/dist/{chunk-zn7ncwb8.js → chunk-pm76dy07.js} +1 -1
- package/dist/{chunk-nr9z0zeq.js → chunk-ptx6n9hd.js} +1 -1
- package/dist/{chunk-3ey8888k.js → chunk-pwjre3b2.js} +1 -1
- package/dist/{chunk-0h3gpwyv.js → chunk-q341v4gv.js} +56 -56
- package/dist/{chunk-aqk9e27b.js → chunk-q5h1reph.js} +1 -1
- package/dist/{chunk-jp4ef6dc.js → chunk-qvdx99py.js} +1 -1
- package/dist/chunk-r1hg1yc4.js +2 -0
- package/dist/{chunk-51kzs978.js → chunk-r6kbpwzd.js} +2 -2
- package/dist/{chunk-3r5rk2rz.js → chunk-rxqv3p90.js} +2 -2
- package/dist/{chunk-h39efd30.js → chunk-sknazxqf.js} +1 -1
- package/dist/{chunk-64ny75zz.js → chunk-smyeg8cr.js} +1 -1
- package/dist/chunk-tr4hseng.js +2 -0
- package/dist/chunk-tywr9wc5.js +2 -0
- package/dist/{chunk-shbabvaz.js → chunk-v0byvxty.js} +1 -1
- package/dist/{chunk-3areak0p.js → chunk-vc2xzscw.js} +2 -2
- package/dist/{chunk-28jtt8hn.js → chunk-vp9hse5k.js} +48 -48
- package/dist/chunk-vpa06pyx.js +2 -0
- package/dist/{chunk-v5981jwt.js → chunk-vsxws200.js} +1 -1
- package/dist/{chunk-sng45f0b.js → chunk-vzk09hvw.js} +8 -8
- package/dist/{chunk-y463z9qf.js → chunk-xz261gkh.js} +39 -39
- package/dist/{chunk-mj3fghaq.js → chunk-z248e3gj.js} +1 -1
- package/dist/{chunk-gb6229zj.js → chunk-zxbw2gr0.js} +2 -2
- package/dist/{chunk-n9dbjget.js → chunk-zzk3a426.js} +1 -1
- package/dist/cli.js +8 -8
- package/dist/craft-entry.js +1 -1
- package/dist/craft.js +1 -1
- package/dist/expressions.js +9 -0
- package/dist/native/bridge/protocol.d.ts +1 -0
- package/dist/native/compiler/bundle.d.ts +1 -0
- package/dist/native/compiler/bundle.js +3 -2
- package/dist/native/compiler/headwind-to-style.d.ts +4 -0
- package/dist/native/compiler/headwind-to-style.js +33 -3
- package/dist/native/compiler/html-to-ir.d.ts +12 -0
- package/dist/native/compiler/html-to-ir.js +56 -5
- package/dist/native/compiler/inline-style.js +13 -0
- package/dist/native/compiler/ir.d.ts +2 -0
- package/dist/native/compiler/render-screen.js +32 -6
- package/dist/native/runtime/binding-tree.js +2 -1
- package/dist/native/runtime/craft-bridge.d.ts +2 -0
- package/dist/native/runtime/craft-bridge.js +13 -3
- package/dist/native/runtime/native-host.d.ts +1 -0
- package/dist/native/runtime/native-host.js +82 -12
- package/dist/native/runtime/shared-screen.js +4 -3
- package/dist/native/runtime/web-navigation.d.ts +18 -0
- package/dist/native/runtime/web-navigation.js +59 -0
- package/dist/native/runtime/web-storage.d.ts +40 -1
- package/dist/native/runtime/web-storage.js +123 -26
- package/dist/native/testing.d.ts +1 -0
- package/dist/native/testing.js +1 -0
- package/dist/native/text-entry.d.ts +51 -0
- package/dist/native/text-entry.js +101 -0
- package/dist/native-build.js +3 -1
- package/dist/pwa.js +1 -1
- package/dist/ssg.js +25 -25
- package/dist/stx-virtual-ts.d.ts +1 -1
- package/dist/stx-virtual-ts.js +3 -1
- package/dist/utils.js +3 -1
- package/package.json +5 -5
- package/dist/chunk-0rs1j4bn.js +0 -2
- package/dist/chunk-1qmc6gg1.js +0 -2
- package/dist/chunk-2e9d0np1.js +0 -2
- package/dist/chunk-62x62wzy.js +0 -2
- package/dist/chunk-7js495j0.js +0 -2
- package/dist/chunk-cbsa2np9.js +0 -2
- package/dist/chunk-egg54kd0.js +0 -12
- package/dist/chunk-ez0s2kvp.js +0 -2
- package/dist/chunk-g884rvhy.js +0 -2
- package/dist/chunk-h42anr8g.js +0 -2
- package/dist/chunk-hz0g9xrq.js +0 -2
- package/dist/chunk-rhzkw6y4.js +0 -128
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { existsSync } from "node:fs";
|
|
2
2
|
import path from "node:path";
|
|
3
3
|
import { loadStxConfig } from "../../config.js";
|
|
4
|
-
import { extractBindingManifest } from "../../binding-manifest.js";
|
|
4
|
+
import { classifyAttribute, extractBindingManifest } from "../../binding-manifest.js";
|
|
5
5
|
import { processDirectives } from "../../process.js";
|
|
6
6
|
import { processScriptSetup } from "../../signal-processing.js";
|
|
7
7
|
import { appThemeCSS } from "./app-theme.js";
|
|
@@ -20,23 +20,25 @@ export function nativePrimitivesDir() {
|
|
|
20
20
|
return candidates[0];
|
|
21
21
|
}
|
|
22
22
|
export async function compileScreenSource(source, filePath, options = {}) {
|
|
23
|
-
const root = options.root ?? path.dirname(filePath), loaded = await loadStxConfig(root), fromRoot = (dir, fallback) => dir ? path.isAbsolute(dir) ? dir : path.resolve(
|
|
23
|
+
const root = options.root ?? path.dirname(filePath), loaded = await loadStxConfig(root), sourceRoot = typeof loaded.root === "string" && loaded.root ? path.resolve(root, loaded.root) : root, fromRoot = (dir, fallback) => dir ? path.isAbsolute(dir) ? dir : path.resolve(sourceRoot, dir) : path.join(sourceRoot, fallback), config = {
|
|
24
24
|
root,
|
|
25
25
|
layoutsDir: fromRoot(loaded.layoutsDir, "layouts"),
|
|
26
26
|
partialsDir: fromRoot(loaded.partialsDir, "partials"),
|
|
27
27
|
storesDir: fromRoot(loaded.storesDir, "stores"),
|
|
28
|
-
componentsDir: options.componentsDir ?? loaded.componentsDir
|
|
28
|
+
componentsDir: options.componentsDir ?? (loaded.componentsDir ? fromRoot(loaded.componentsDir, "components") : path.join(sourceRoot, "components")),
|
|
29
29
|
buildMode: "serve",
|
|
30
30
|
cache: !1,
|
|
31
31
|
_targetComponentDirs: [nativePrimitivesDir()],
|
|
32
|
-
_targetComponentFallbackNames: ["Button", "Checkbox", "Switch"],
|
|
32
|
+
_targetComponentFallbackNames: ["Button", "Checkbox", "Switch", "TextInput"],
|
|
33
33
|
_nativeHostAttrs: !0,
|
|
34
34
|
skipEventDirectives: !0,
|
|
35
35
|
_pluginComponentDirs: loaded._pluginComponentDirs ?? []
|
|
36
|
-
}, context = { ...options.context ?? {}, __stx_inject_css: !1 }, dependencies = new Set([filePath]), renderedHtml = await processDirectives(source, context, filePath, config, dependencies), { html: content, chrome } = await extractLayoutChrome(renderedHtml), { html, manifest } = extractBindingManifest(content), theme = await appThemeCSS(root), { document, diagnostics } = await translateHtmlToDocument(theme ? `<style>${theme}</style>${html}` : html, {
|
|
36
|
+
}, context = { ...options.context ?? {}, __stx_inject_css: !1, __stx_native_screen: !0 }, dependencies = new Set([filePath]), renderedHtml = await processDirectives(source, context, filePath, config, dependencies), { html: content, chrome } = await extractLayoutChrome(renderedHtml), { html, manifest } = extractBindingManifest(content), theme = await appThemeCSS(root), { document, diagnostics } = await translateHtmlToDocument(theme ? `<style>${theme}</style>${html}` : html, {
|
|
37
37
|
source: filePath,
|
|
38
38
|
script: extractClientScript(source)
|
|
39
|
-
})
|
|
39
|
+
});
|
|
40
|
+
enterTemplatedBindings(document.root, manifest);
|
|
41
|
+
const head = context.__stx_runtime_head;
|
|
40
42
|
if (typeof head?.title === "string" && head.title.trim())
|
|
41
43
|
document.title = head.title.trim();
|
|
42
44
|
if (chrome)
|
|
@@ -66,6 +68,30 @@ export async function compileScreenSource(source, filePath, options = {}) {
|
|
|
66
68
|
scripts.unshift({ code: modules });
|
|
67
69
|
return { document, manifest, setup, scripts, diagnostics, html, dependencies: [...dependencies] };
|
|
68
70
|
}
|
|
71
|
+
function enterTemplatedBindings(root, manifest) {
|
|
72
|
+
const entries = new Map(manifest.entries.map((entry) => [entry.id, entry]));
|
|
73
|
+
let next = manifest.entries.reduce((highest, entry) => Math.max(highest, entry.id), -1) + 1;
|
|
74
|
+
const visit = (node) => {
|
|
75
|
+
if (node._templated?.length && node.bindings) {
|
|
76
|
+
if (node.bindingId === void 0 || !entries.has(node.bindingId)) {
|
|
77
|
+
const entry = { id: node.bindingId ?? next++, bindings: [] };
|
|
78
|
+
node.bindingId = entry.id;
|
|
79
|
+
entries.set(entry.id, entry);
|
|
80
|
+
manifest.entries.push(entry);
|
|
81
|
+
}
|
|
82
|
+
const entry = entries.get(node.bindingId);
|
|
83
|
+
for (const name of node._templated) {
|
|
84
|
+
const attribute = `:${name}`, kind = classifyAttribute(attribute);
|
|
85
|
+
if (kind && !entry.bindings.some((binding) => binding.name === attribute))
|
|
86
|
+
entry.bindings.push({ name: attribute, value: node.bindings[name], kind });
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
for (const child of node.children)
|
|
90
|
+
if (typeof child !== "string")
|
|
91
|
+
visit(child);
|
|
92
|
+
};
|
|
93
|
+
visit(root);
|
|
94
|
+
}
|
|
69
95
|
export async function compileScreenFile(filePath, options = {}) {
|
|
70
96
|
return compileScreenSource(await Bun.file(filePath).text(), filePath, options);
|
|
71
97
|
}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { authoredAccessibilityProps } from "../accessibility.js";
|
|
2
|
+
import { authoredTextEntryProps } from "../text-entry.js";
|
|
2
3
|
function decodeBindingValue(value) {
|
|
3
4
|
return value.replace(/</g, "<").replace(/>/g, ">").replace(/"/g, '"').replace(/�?39;/g, "'").replace(/'/gi, "'").replace(/&/g, "&");
|
|
4
5
|
}
|
|
@@ -107,7 +108,7 @@ export function materializeNativeBindingTree(document, manifest, host) {
|
|
|
107
108
|
const node = createBindingNode(id, source.type, runtimeBindings, !0, source._classes, (value) => host.setAttribute(node, "class", value));
|
|
108
109
|
if (source.type === "Checkbox" && source.props.type === "checkbox")
|
|
109
110
|
node.tagName = "INPUT";
|
|
110
|
-
for (const [name, value] of Object.entries(authoredAccessibilityProps(source.props, source._accessibilitySource))) {
|
|
111
|
+
for (const [name, value] of Object.entries(authoredTextEntryProps(authoredAccessibilityProps(source.props, source._accessibilitySource), source._textEntrySource))) {
|
|
111
112
|
if (value === void 0 || value === null || name === "__stxId")
|
|
112
113
|
continue;
|
|
113
114
|
node.setAttribute(name, typeof value === "object" ? JSON.stringify(value) : String(value));
|
|
@@ -2,7 +2,7 @@ import { STXBridge } from "../bridge/protocol.js";
|
|
|
2
2
|
import { createEventSourceClass, createStreamingBody } from "./event-stream.js";
|
|
3
3
|
import { abortError, isNativeDocument, NativeFormData, nativeFormParts, updateNativeDocumentVisibility } from "./jsc-globals.js";
|
|
4
4
|
import { buttonsKey, changedTabItems, chromePath, hostButton, mergeChromeButtons } from "./navigation-chrome.js";
|
|
5
|
-
import { installNativeNavigation } from "./web-navigation.js";
|
|
5
|
+
import { installNativeNavigation, nativeRouteParams } from "./web-navigation.js";
|
|
6
6
|
import { installNativeWebStorage } from "./web-storage.js";
|
|
7
7
|
function capabilityFlags(capabilities) {
|
|
8
8
|
return {
|
|
@@ -186,8 +186,6 @@ export function installCraftBridge(protocol, nativeBridge, target = globalThis,
|
|
|
186
186
|
return request("Storage", "compareAndSet", [key, expectedValue, nextValue]);
|
|
187
187
|
}
|
|
188
188
|
});
|
|
189
|
-
if (isNativeDocument(target.document))
|
|
190
|
-
installNativeWebStorage(target, craft);
|
|
191
189
|
craft.secureStorage = Object.assign({ getSync: () => null }, craft.secureStorage || {}, {
|
|
192
190
|
get: (key) => request("SecureStorage", "get", [key]),
|
|
193
191
|
set: (key, value) => request("SecureStorage", "set", [key, value]),
|
|
@@ -212,6 +210,15 @@ export function installCraftBridge(protocol, nativeBridge, target = globalThis,
|
|
|
212
210
|
callback(token, previous);
|
|
213
211
|
})
|
|
214
212
|
});
|
|
213
|
+
if (isNativeDocument(target.document)) {
|
|
214
|
+
const shareStorage = { ...options.shareStorage, ...nativeBridge.shareStorage }, shared = installNativeWebStorage(target, craft, {
|
|
215
|
+
shareStorage,
|
|
216
|
+
...capabilities.has("secureStorage") ? { secure: () => craft.secureStorage } : {},
|
|
217
|
+
adopted: (key, value) => target.dispatchEvent?.(new target.CustomEvent("craftsharedstorage", { detail: { key, value } }))
|
|
218
|
+
});
|
|
219
|
+
if (shared)
|
|
220
|
+
craft.session.onChange(() => shared.changed(sessionKey));
|
|
221
|
+
}
|
|
215
222
|
craft.snapshots = Object.assign({ get: () => null, set: () => Promise.resolve(!1) }, craft.snapshots || {}, {
|
|
216
223
|
onChange: (callback) => protocol.on("SNAPSHOT_CHANGED", (message) => {
|
|
217
224
|
if (typeof message.payload?.name === "string")
|
|
@@ -709,6 +716,9 @@ export function installCraftBridge(protocol, nativeBridge, target = globalThis,
|
|
|
709
716
|
}
|
|
710
717
|
if (isNativeDocument(target.document)) {
|
|
711
718
|
installNativeNavigation(target, craft, { routeURL: nativeBridge.routeURL, appURL: craft.app?.url });
|
|
719
|
+
const pathParams = options.source ? nativeRouteParams(options.source, String(target.location?.pathname ?? "/")) : {};
|
|
720
|
+
target.__stx_rp = { ...pathParams, ...craft.route.params };
|
|
721
|
+
craft.route.onParams((params) => target.stx?.setRouteParams?.({ ...pathParams, ...params }));
|
|
712
722
|
let title = typeof options.title === "string" ? options.title : "";
|
|
713
723
|
Object.defineProperty(target.document, "title", {
|
|
714
724
|
configurable: !0,
|
|
@@ -23,6 +23,7 @@ export declare interface NativeHostOptions {
|
|
|
23
23
|
send: (operations: NativeMutationOperation[]) => void
|
|
24
24
|
schedule?: (flush: () => void) => void
|
|
25
25
|
followLink?: (href: string) => void
|
|
26
|
+
linkState?: (href: string, match: string | null) => { active: boolean, exact: boolean } | null
|
|
26
27
|
}
|
|
27
28
|
export declare interface NativeHost {
|
|
28
29
|
readonly isNative: true
|
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
import { accessibilityChanges, authoredAccessibilityProps, projectAccessibility } from "../accessibility.js";
|
|
2
|
-
import { compileClassStyles } from "../compiler/headwind-to-style.js";
|
|
2
|
+
import { compileClassStyles, NATIVE_STATE_VARIANTS } from "../compiler/headwind-to-style.js";
|
|
3
3
|
import { resolveIconName } from "../compiler/icons.js";
|
|
4
4
|
import { applyNativeLayoutDefaults, parseNativeStyleLayers } from "../compiler/inline-style.js";
|
|
5
5
|
import { createStyleVariables } from "../compiler/style-variables.js";
|
|
6
6
|
import { affectsGeometry, applySvgAnimation, parseSvgMarkup, parseViewBox, SVG_ANIMATION_ATTRIBUTES, SVG_NODE_TYPES, svgGeometry } from "../compiler/svg.js";
|
|
7
7
|
import { NATIVE_EVENT_NAMES } from "../event-names.js";
|
|
8
8
|
import { nativePropName } from "../prop-names.js";
|
|
9
|
+
import { authoredTextEntryProps, projectTextEntry, TEXT_ENTRY_SOURCES, textEntryChanges } from "../text-entry.js";
|
|
9
10
|
import { cloneNativeBindingNode } from "./binding-tree.js";
|
|
10
11
|
import { NATIVE_FORM_ENTRIES } from "./jsc-globals.js";
|
|
11
12
|
import { createNativeOverlayPresenter } from "./overlay-presenter.js";
|
|
@@ -61,13 +62,36 @@ function followsHref() {}
|
|
|
61
62
|
export function createNativeHost(options) {
|
|
62
63
|
const records = new Map, attributeObservers = new WeakMap, childObservers = new WeakMap, handlers = new Map, eventRegistrations = new WeakMap, componentListeners = new WeakMap, controlsWithDefaultListeners = new WeakSet, formResetCallbacks = new WeakMap;
|
|
63
64
|
let queue = [], scheduled = !1, counter = 0, colorScheme = options.colorScheme ?? "light", viewportWidth = Number.isFinite(options.viewportWidth) ? Math.max(0, options.viewportWidth) : 0, stylesheetVariables = createStyleVariables(options.stylesheetTheme?.[colorScheme] ?? []).computed(), disposed = !1;
|
|
64
|
-
const schedule = options.schedule ?? ((flush) => queueMicrotask(flush)), followLink = options
|
|
65
|
+
const schedule = options.schedule ?? ((flush) => queueMicrotask(flush)), { followLink, linkState } = options, nextId = (prefix) => `${prefix}${++counter}`;
|
|
65
66
|
function notifyAttributes(node, name) {
|
|
66
67
|
for (const observer of attributeObservers.get(node) ?? [])
|
|
67
68
|
if (observer.names.includes(name))
|
|
68
69
|
observer.notify();
|
|
69
70
|
}
|
|
71
|
+
function refreshDividers(parent) {
|
|
72
|
+
const record = parent && descriptorOf(parent);
|
|
73
|
+
if (record)
|
|
74
|
+
refreshDividersOf(record);
|
|
75
|
+
}
|
|
76
|
+
function refreshDividersOf(record) {
|
|
77
|
+
let first = !0;
|
|
78
|
+
for (const child of record.children) {
|
|
79
|
+
if (child.__stxAnchor !== void 0)
|
|
80
|
+
continue;
|
|
81
|
+
const childRecord = descriptorOf(child);
|
|
82
|
+
if (!childRecord)
|
|
83
|
+
continue;
|
|
84
|
+
const divider = record.divide && !first ? { ...record.divide.style, ...colorScheme === "dark" ? record.divide.dark : {} } : void 0;
|
|
85
|
+
if (childRecord.visible)
|
|
86
|
+
first = !1;
|
|
87
|
+
if (JSON.stringify(divider) === JSON.stringify(childRecord.dividerStyle))
|
|
88
|
+
continue;
|
|
89
|
+
childRecord.dividerStyle = divider;
|
|
90
|
+
applyClasses(child.__stxId, childRecord, !0);
|
|
91
|
+
}
|
|
92
|
+
}
|
|
70
93
|
function notifyChildren(node) {
|
|
94
|
+
refreshDividers(node);
|
|
71
95
|
for (let current = node;current; current = current.__stxOwner)
|
|
72
96
|
for (const notify of childObservers.get(current) ?? [])
|
|
73
97
|
notify();
|
|
@@ -105,11 +129,25 @@ export function createNativeHost(options) {
|
|
|
105
129
|
return typeof href === "string" && href ? href : null;
|
|
106
130
|
}
|
|
107
131
|
function installLinkListener(node) {
|
|
132
|
+
markCurrentLink(node);
|
|
108
133
|
if (!followLink)
|
|
109
134
|
return;
|
|
110
135
|
if (isBindingNode(node) && node.attributes.some((attribute) => /^(?::|x-bind:|@bind:|x-)href$/.test(attribute.name)) || typeof descriptorOf(node)?.props.href === "string")
|
|
111
136
|
host.listen(node, "click", followsHref);
|
|
112
137
|
}
|
|
138
|
+
function markCurrentLink(node) {
|
|
139
|
+
const record = descriptorOf(node);
|
|
140
|
+
if (!linkState || !record || record.props["data-stx-link"] === void 0)
|
|
141
|
+
return;
|
|
142
|
+
const href = linkHref(node), state = href === null ? null : linkState(href, typeof record.props["data-stx-active-match"] === "string" ? record.props["data-stx-active-match"] : null);
|
|
143
|
+
if (!state)
|
|
144
|
+
return;
|
|
145
|
+
const words = (value, fallback) => String(typeof value === "string" ? value : fallback).split(/\s+/).filter(Boolean), active = words(record.props["data-stx-active-class"], "active"), exact = words(record.props["data-stx-exact-active-class"], "exact-active"), next = [...record.classes.split(/\s+/).filter((word) => word && !active.includes(word) && !exact.includes(word)), ...state.exact ? exact : [], ...state.active ? active : []].filter((word, index, all) => all.indexOf(word) === index).join(" ");
|
|
146
|
+
if (next === record.classes)
|
|
147
|
+
return;
|
|
148
|
+
record.classes = next;
|
|
149
|
+
applyClasses(node.__stxId, record);
|
|
150
|
+
}
|
|
113
151
|
function retainDetachedDescriptors(node) {
|
|
114
152
|
const record = records.get(node.__stxId);
|
|
115
153
|
if (!record)
|
|
@@ -193,6 +231,12 @@ export function createNativeHost(options) {
|
|
|
193
231
|
return current;
|
|
194
232
|
return null;
|
|
195
233
|
}
|
|
234
|
+
function hostProps(record) {
|
|
235
|
+
return { ...record.props, ...projectAccessibility(record.props), ...projectTextEntry(record.type, record.props) };
|
|
236
|
+
}
|
|
237
|
+
function ariaState(value) {
|
|
238
|
+
return value === !0 || value === "true";
|
|
239
|
+
}
|
|
196
240
|
function disabled(record) {
|
|
197
241
|
return record.props.disabled === !0 || record.props.disabled === "" || record.props.disabled === "true";
|
|
198
242
|
}
|
|
@@ -277,7 +321,7 @@ export function createNativeHost(options) {
|
|
|
277
321
|
node: {
|
|
278
322
|
type: record.type,
|
|
279
323
|
...record.key === void 0 ? {} : { key: record.key },
|
|
280
|
-
props:
|
|
324
|
+
props: hostProps(record),
|
|
281
325
|
style: { ...record.style },
|
|
282
326
|
...Object.keys(record.events).length ? { events: { ...record.events } } : {},
|
|
283
327
|
...record.text === void 0 ? {} : { children: [record.text] }
|
|
@@ -304,6 +348,9 @@ export function createNativeHost(options) {
|
|
|
304
348
|
for (const layer of classes.responsive ?? [])
|
|
305
349
|
if (viewportWidth >= layer.min && (layer.max === void 0 || viewportWidth <= layer.max))
|
|
306
350
|
Object.assign(classStyle, layer.style, colorScheme === "dark" ? layer.dark : {});
|
|
351
|
+
for (const [attribute, layer] of Object.entries(classes.states ?? {}))
|
|
352
|
+
if (ariaState(record.props[attribute]))
|
|
353
|
+
Object.assign(classStyle, layer.style, colorScheme === "dark" ? layer.dark : {});
|
|
307
354
|
if (classes.disabled && disabled(record))
|
|
308
355
|
Object.assign(classStyle, classes.disabled.style, colorScheme === "dark" ? classes.disabled.dark : {});
|
|
309
356
|
for (const layer of [record.focusWithin && classes.focusWithin, record.focused && classes.focus]) {
|
|
@@ -316,7 +363,7 @@ export function createNativeHost(options) {
|
|
|
316
363
|
}
|
|
317
364
|
Object.assign(classStyle, focused);
|
|
318
365
|
}
|
|
319
|
-
return { ...applyNativeLayoutDefaults({ ...classStyle, ...resolved.styles[0], ...record.baseStyle, ...resolved.styles[1], ...resolved.styles[2] }), ...record.visible && !isHiddenInput(record) ? {} : { display: "none" } };
|
|
366
|
+
return { ...applyNativeLayoutDefaults({ ...classStyle, ...record.dividerStyle, ...resolved.styles[0], ...record.baseStyle, ...resolved.styles[1], ...resolved.styles[2] }), ...record.visible && !isHiddenInput(record) ? {} : { display: "none" } };
|
|
320
367
|
}
|
|
321
368
|
function refreshFocusChain(node) {
|
|
322
369
|
for (let current = node;current; current = current.__stxOwner) {
|
|
@@ -390,7 +437,11 @@ export function createNativeHost(options) {
|
|
|
390
437
|
record.style = style;
|
|
391
438
|
if (record.materialized && changed)
|
|
392
439
|
emit({ op: "updateNode", id, patch: { style: { ...patch, ...style } } });
|
|
393
|
-
const classes = compileClassStyles(`${record.classes} ${record.forwardedClasses ?? ""}`, record.variables, { focus: record.type === "TextInput", focusWithin: !0, rules: options.stylesheetRules }),
|
|
440
|
+
const classes = compileClassStyles(`${record.classes} ${record.forwardedClasses ?? ""}`, record.variables, { focus: record.type === "TextInput", focusWithin: !0, rules: options.stylesheetRules }), divideChanged = JSON.stringify(classes.divide) !== JSON.stringify(record.divide);
|
|
441
|
+
record.divide = classes.divide;
|
|
442
|
+
if (divideChanged || record.divide)
|
|
443
|
+
refreshDividersOf(record);
|
|
444
|
+
const unsupported = new Set(classes.unknown);
|
|
394
445
|
for (const name of unsupported)
|
|
395
446
|
if (!record.reportedClasses?.has(name))
|
|
396
447
|
console.warn(`[STX Native] unknown-class: ${id}: ${name}`);
|
|
@@ -503,10 +554,10 @@ export function createNativeHost(options) {
|
|
|
503
554
|
const suffix = /(?:^|\D)(\d+)$/.exec(node.__stxId)?.[1];
|
|
504
555
|
if (suffix)
|
|
505
556
|
counter = Math.max(counter, Number(suffix));
|
|
506
|
-
const classes = descriptor?._classes ?? "",
|
|
557
|
+
const classes = descriptor?._classes ?? "", compiledClasses = compileClassStyles(classes), classStyle = compiledClasses.style, baseStyle = descriptor?._styleSource !== void 0 ? {} : descriptor?._inlineStyle ? { ...descriptor._inlineStyle } : Object.fromEntries(Object.entries(descriptor?.style ?? {}).filter(([key, value]) => classStyle[key] !== value)), record = {
|
|
507
558
|
type,
|
|
508
559
|
key: descriptor?.key,
|
|
509
|
-
props: authoredAccessibilityProps(descriptor?.props ?? {}, descriptor?._accessibilitySource),
|
|
560
|
+
props: authoredTextEntryProps(authoredAccessibilityProps(descriptor?.props ?? {}, descriptor?._accessibilitySource), descriptor?._textEntrySource),
|
|
510
561
|
style: { ...descriptor?.style ?? {} },
|
|
511
562
|
baseStyle,
|
|
512
563
|
styleSource: descriptor?._styleSource,
|
|
@@ -518,8 +569,11 @@ export function createNativeHost(options) {
|
|
|
518
569
|
children: [],
|
|
519
570
|
visible: !0,
|
|
520
571
|
materialized: !0,
|
|
521
|
-
controlDefaults: { value: descriptor?.props.value ?? "", checked: descriptor?.props.checked ?? descriptor?.props.value ?? !1 }
|
|
522
|
-
|
|
572
|
+
controlDefaults: { value: descriptor?.props.value ?? "", checked: descriptor?.props.checked ?? descriptor?.props.value ?? !1 },
|
|
573
|
+
divide: compiledClasses.divide
|
|
574
|
+
}, ownerRecord = owner ? descriptorOf(owner) : void 0;
|
|
575
|
+
if (ownerRecord?.divide && ownerRecord.children.some((child) => child.__stxAnchor === void 0 && descriptorOf(child)?.visible))
|
|
576
|
+
record.dividerStyle = { ...ownerRecord.divide.style, ...colorScheme === "dark" ? ownerRecord.divide.dark : {} };
|
|
523
577
|
record.style = resolveStyle(record, node.__stxId);
|
|
524
578
|
if (descriptor)
|
|
525
579
|
descriptor.style = { ...record.style };
|
|
@@ -636,7 +690,7 @@ export function createNativeHost(options) {
|
|
|
636
690
|
return {
|
|
637
691
|
id: node.__stxId,
|
|
638
692
|
type: record.type,
|
|
639
|
-
props:
|
|
693
|
+
props: hostProps(record),
|
|
640
694
|
style: { ...record.style },
|
|
641
695
|
events: { ...record.events },
|
|
642
696
|
children: record.text === void 0 ? children : [record.text]
|
|
@@ -686,7 +740,7 @@ export function createNativeHost(options) {
|
|
|
686
740
|
applyClasses(node.__stxId, record);
|
|
687
741
|
return;
|
|
688
742
|
}
|
|
689
|
-
const record = recordOf(node), prop = nativePropName(name, record.type), accessibilityBefore = prop === "role" || prop.startsWith("aria-") || prop.startsWith("accessibility") ? projectAccessibility(record.props) : void 0, wasDisabled = disabled(record);
|
|
743
|
+
const record = recordOf(node), prop = nativePropName(name, record.type), accessibilityBefore = prop === "role" || prop.startsWith("aria-") || prop.startsWith("accessibility") ? projectAccessibility(record.props) : void 0, textEntryBefore = TEXT_ENTRY_SOURCES.has(prop) ? projectTextEntry(record.type, record.props) : void 0, wasDisabled = disabled(record);
|
|
690
744
|
record.props[prop] = value;
|
|
691
745
|
if (record.focused && disabled(record)) {
|
|
692
746
|
record.focused = !1;
|
|
@@ -694,14 +748,24 @@ export function createNativeHost(options) {
|
|
|
694
748
|
}
|
|
695
749
|
if (prop === "disabled" && wasDisabled !== disabled(record))
|
|
696
750
|
applyClasses(node.__stxId, record, !0);
|
|
751
|
+
else if (NATIVE_STATE_VARIANTS.has(prop))
|
|
752
|
+
applyClasses(node.__stxId, record, !0);
|
|
697
753
|
if (record.type === "Icon" && prop === "name") {
|
|
698
754
|
const icon = resolveIconName(String(value ?? ""));
|
|
699
755
|
this.setAttribute(node, "iconify", icon.iconify ?? null);
|
|
700
756
|
this.setAttribute(node, "symbol", icon.symbol);
|
|
701
757
|
}
|
|
758
|
+
if (prop === "href")
|
|
759
|
+
markCurrentLink(node);
|
|
702
760
|
const patch = { [prop]: value };
|
|
703
761
|
if (accessibilityBefore)
|
|
704
762
|
Object.assign(patch, accessibilityChanges(record.props, accessibilityBefore, prop));
|
|
763
|
+
if (textEntryBefore) {
|
|
764
|
+
Object.assign(patch, textEntryChanges(record.type, record.props, textEntryBefore));
|
|
765
|
+
const projected = projectTextEntry(record.type, record.props);
|
|
766
|
+
if (prop in projected)
|
|
767
|
+
patch[prop] = projected[prop];
|
|
768
|
+
}
|
|
705
769
|
if (SVG_NODE_TYPES.has(record.type)) {
|
|
706
770
|
if (prop === "strokeDasharray" && value != null && !Array.isArray(value))
|
|
707
771
|
patch[prop] = record.props[prop] = String(value).split(/[\s,]+/).map(Number).filter(Number.isFinite);
|
|
@@ -728,17 +792,21 @@ export function createNativeHost(options) {
|
|
|
728
792
|
this.setAttribute(node, name, "");
|
|
729
793
|
return;
|
|
730
794
|
}
|
|
731
|
-
const record = recordOf(node), prop = nativePropName(name, record.type), accessibilityBefore = prop === "role" || prop.startsWith("aria-") || prop.startsWith("accessibility") ? projectAccessibility(record.props) : void 0;
|
|
795
|
+
const record = recordOf(node), prop = nativePropName(name, record.type), accessibilityBefore = prop === "role" || prop.startsWith("aria-") || prop.startsWith("accessibility") ? projectAccessibility(record.props) : void 0, textEntryBefore = TEXT_ENTRY_SOURCES.has(prop) ? projectTextEntry(record.type, record.props) : void 0;
|
|
732
796
|
delete record.props[prop];
|
|
733
797
|
const patch = { [prop]: null };
|
|
734
798
|
if (accessibilityBefore)
|
|
735
799
|
Object.assign(patch, accessibilityChanges(record.props, accessibilityBefore, prop));
|
|
800
|
+
if (textEntryBefore)
|
|
801
|
+
Object.assign(patch, textEntryChanges(record.type, record.props, textEntryBefore));
|
|
736
802
|
if (affectsGeometry(record.type, prop))
|
|
737
803
|
patch.geometry = record.props.geometry = svgGeometry(record.type, record.props);
|
|
738
804
|
if (record.type === "Animate" && SVG_ANIMATION_ATTRIBUTES.includes(prop))
|
|
739
805
|
Object.assign(patch, applySvgAnimation(record.props));
|
|
740
806
|
if (record.materialized)
|
|
741
807
|
emit({ op: "updateNode", id: node.__stxId, patch: { props: patch } });
|
|
808
|
+
if (NATIVE_STATE_VARIANTS.has(prop))
|
|
809
|
+
applyClasses(node.__stxId, record, !0);
|
|
742
810
|
},
|
|
743
811
|
observeAttributes(node, names, callback) {
|
|
744
812
|
const observers = attributeObservers.get(node) ?? new Set;
|
|
@@ -962,6 +1030,8 @@ export function createNativeHost(options) {
|
|
|
962
1030
|
const display = visible ? irDisplay(record.style.display) : "none";
|
|
963
1031
|
if (record.materialized)
|
|
964
1032
|
emit({ op: "updateNode", id: node.__stxId, patch: { style: { display } } });
|
|
1033
|
+
if (was !== visible)
|
|
1034
|
+
refreshDividers(node.__stxOwner);
|
|
965
1035
|
return was;
|
|
966
1036
|
},
|
|
967
1037
|
anchor(label) {
|
|
@@ -4,7 +4,7 @@ import { materializeNativeBindingTree } from "./binding-tree.js";
|
|
|
4
4
|
import { installCraftBridge } from "./craft-bridge.js";
|
|
5
5
|
import { createNativeHost } from "./native-host.js";
|
|
6
6
|
import { createNativeViewOperations, nativeViewError } from "./view-operations.js";
|
|
7
|
-
import { nativeLinkFollower } from "./web-navigation.js";
|
|
7
|
+
import { nativeLinkFollower, nativeLinkState } from "./web-navigation.js";
|
|
8
8
|
import { startNativeSessionRun } from "./web-storage.js";
|
|
9
9
|
export function prepareSharedNativeScreen(document, manifest, bridge, options = {}) {
|
|
10
10
|
let revision = 0, generation = 0, rendered = !1;
|
|
@@ -13,7 +13,8 @@ export function prepareSharedNativeScreen(document, manifest, bridge, options =
|
|
|
13
13
|
const craft = installCraftBridge(protocol, bridge, globalThis, {
|
|
14
14
|
...options,
|
|
15
15
|
...document.title ? { title: document.title } : {},
|
|
16
|
-
...document.chrome ? { chrome: document.chrome } : {}
|
|
16
|
+
...document.chrome ? { chrome: document.chrome } : {},
|
|
17
|
+
source: document.meta.source
|
|
17
18
|
}), followLink = nativeLinkFollower(craft), host = createNativeHost({
|
|
18
19
|
views: createNativeViewOperations(protocol, bridge.capabilities ?? [], () => {
|
|
19
20
|
if (!rendered)
|
|
@@ -23,7 +24,7 @@ export function prepareSharedNativeScreen(document, manifest, bridge, options =
|
|
|
23
24
|
viewportWidth: Number(bridge.viewportWidth) || 0,
|
|
24
25
|
stylesheetTheme: document.root._stylesheetTheme,
|
|
25
26
|
stylesheetRules: document.root._stylesheetRules,
|
|
26
|
-
...followLink ? { followLink } : {},
|
|
27
|
+
...followLink ? { followLink, linkState: (href, match) => nativeLinkState(href, String(globalThis.location?.href ?? ""), match) } : {},
|
|
27
28
|
send(operations) {
|
|
28
29
|
const baseRevision = revision;
|
|
29
30
|
revision++;
|
|
@@ -8,6 +8,24 @@ export declare function followNativeLink(craft: AnyRecord, href: unknown, base:
|
|
|
8
8
|
/** The link follower `installNativeNavigation` made for this `craft`, if any. */
|
|
9
9
|
export declare function nativeLinkFollower(craft: AnyRecord): ((href: unknown) => boolean) | undefined;
|
|
10
10
|
export declare function installNativeNavigation(target: AnyRecord, craft: AnyRecord, options: NativeNavigationOptions): (href: unknown) => boolean;
|
|
11
|
+
/**
|
|
12
|
+
* Whether a link points at the screen being shown, by the web router's rule
|
|
13
|
+
* (packages/router `linkState`): `active` for its path or a path under it,
|
|
14
|
+
* `exact` for its path alone; a link with a query is current only where each
|
|
15
|
+
* param it names has that value, and one without is exact only where there
|
|
16
|
+
* is no query. `also` (`data-stx-active-match`) names more path prefixes that
|
|
17
|
+
* make it current. Null for a link that is not the app's.
|
|
18
|
+
*/
|
|
19
|
+
export declare function nativeLinkState(href: unknown, here: string, also?: string | null): { active: boolean, exact: boolean } | null;
|
|
20
|
+
/**
|
|
21
|
+
* A file-routed view's params from the address it is shown at: the view
|
|
22
|
+
* `views/plans/[id].stx` at `/plans/12` is `{ id: '12' }`, as the web's
|
|
23
|
+
* server hands them to `useRoute().params`. Segments are matched from the
|
|
24
|
+
* end, so the directory the views live in does not matter; an `index` file
|
|
25
|
+
* is its directory's page, and a final catch-all (`[...slug]`) takes what
|
|
26
|
+
* follows the fixed segment before it.
|
|
27
|
+
*/
|
|
28
|
+
export declare function nativeRouteParams(source: string, pathname: string): Record<string, string>;
|
|
11
29
|
export declare interface NativeNavigationOptions {
|
|
12
30
|
routeURL?: string
|
|
13
31
|
appURL?: string
|
|
@@ -105,3 +105,62 @@ export function installNativeNavigation(target, craft, options) {
|
|
|
105
105
|
}
|
|
106
106
|
return go;
|
|
107
107
|
}
|
|
108
|
+
function normalPath(path) {
|
|
109
|
+
return path.length > 1 && path.endsWith("/") ? path.slice(0, -1) : path;
|
|
110
|
+
}
|
|
111
|
+
export function nativeLinkState(href, here, also) {
|
|
112
|
+
if (typeof href !== "string" || !href || href.startsWith("#"))
|
|
113
|
+
return null;
|
|
114
|
+
const URLClass = globalThis.URL;
|
|
115
|
+
let link, current;
|
|
116
|
+
try {
|
|
117
|
+
current = new URLClass(here);
|
|
118
|
+
link = new URLClass(href, here);
|
|
119
|
+
} catch {
|
|
120
|
+
return null;
|
|
121
|
+
}
|
|
122
|
+
if (link.origin !== current.origin)
|
|
123
|
+
return null;
|
|
124
|
+
const path = normalPath(link.pathname), at = normalPath(current.pathname), have = new URLClass(`https://stx.invalid/${current.search}`).searchParams;
|
|
125
|
+
let query = !0, linkHasQuery = !1;
|
|
126
|
+
link.searchParams.forEach((value, name) => {
|
|
127
|
+
linkHasQuery = !0;
|
|
128
|
+
if (!have.getAll(name).includes(value))
|
|
129
|
+
query = !1;
|
|
130
|
+
});
|
|
131
|
+
const matched = String(also ?? "").split(/\s+/).some((prefix) => {
|
|
132
|
+
const normal = normalPath(prefix);
|
|
133
|
+
return !!normal && (at === normal || at.startsWith(`${normal}/`));
|
|
134
|
+
});
|
|
135
|
+
return {
|
|
136
|
+
exact: query && (linkHasQuery || !current.search) && path === at,
|
|
137
|
+
active: query && (path === "/" ? at === "/" : at === path || at.startsWith(`${path}/`)) || matched
|
|
138
|
+
};
|
|
139
|
+
}
|
|
140
|
+
export function nativeRouteParams(source, pathname) {
|
|
141
|
+
const segments = source.replace(/\\/g, "/").replace(/\.stx$/, "").split("/").filter(Boolean);
|
|
142
|
+
if (segments[segments.length - 1] === "index")
|
|
143
|
+
segments.pop();
|
|
144
|
+
const parts = pathname.split("/").filter(Boolean), params = {}, decode = (value) => {
|
|
145
|
+
try {
|
|
146
|
+
return decodeURIComponent(value);
|
|
147
|
+
} catch {
|
|
148
|
+
return value;
|
|
149
|
+
}
|
|
150
|
+
};
|
|
151
|
+
for (let fromEnd = 0;fromEnd < segments.length; fromEnd++) {
|
|
152
|
+
const segment = segments[segments.length - 1 - fromEnd], name = /^\[(\.\.\.)?([\w-]+)\]$/.exec(segment);
|
|
153
|
+
if (!name)
|
|
154
|
+
continue;
|
|
155
|
+
if (name[1]) {
|
|
156
|
+
const before = segments[segments.length - 2 - fromEnd], at = fromEnd === 0 && before && !before.startsWith("[") ? parts.lastIndexOf(before) : -1;
|
|
157
|
+
if (at !== -1)
|
|
158
|
+
params[name[2]] = parts.slice(at + 1).map(decode).join("/");
|
|
159
|
+
continue;
|
|
160
|
+
}
|
|
161
|
+
const part = parts[parts.length - 1 - fromEnd];
|
|
162
|
+
if (part !== void 0)
|
|
163
|
+
params[name[2]] = decode(part);
|
|
164
|
+
}
|
|
165
|
+
return params;
|
|
166
|
+
}
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Install `localStorage` and `sessionStorage` over `craft.storage`, unless the
|
|
3
3
|
* host gave the context its own. For a native realm only (craft-bridge.ts).
|
|
4
|
+
* Returns the shared keys, when there are any.
|
|
4
5
|
*/
|
|
5
|
-
export declare function installNativeWebStorage(target: AnyRecord, craft: AnyRecord):
|
|
6
|
+
export declare function installNativeWebStorage(target: AnyRecord, craft: AnyRecord, options?: NativeWebStorageOptions): NativeSharedKeys | null;
|
|
6
7
|
/** A new run of the app: what sessionStorage held is gone. The app script calls it once per launch. */
|
|
7
8
|
export declare function startNativeSessionRun(craft: AnyRecord): void;
|
|
8
9
|
/** Where each storage area keeps its values in the app's storage. */
|
|
@@ -12,11 +13,38 @@ export declare const NATIVE_WEB_STORAGE_PREFIX: {
|
|
|
12
13
|
};
|
|
13
14
|
/** The app's current run, which sessionStorage values belong to. */
|
|
14
15
|
export declare const NATIVE_SESSION_RUN_KEY: 'stx.sessionStorage.run';
|
|
16
|
+
/** Hook-free access to an area's values, for the shared keys' bookkeeping. */
|
|
17
|
+
declare const RAW: symbol;
|
|
15
18
|
/** The synchronous half of `craft.storage`. */
|
|
16
19
|
export declare interface NativeSyncStore {
|
|
17
20
|
getSync: (key: string) => unknown
|
|
18
21
|
setSync: (key: string, value: unknown) => void
|
|
19
22
|
}
|
|
23
|
+
declare interface RawArea {
|
|
24
|
+
get: (key: string) => string | null
|
|
25
|
+
set: (key: string, value: string) => void
|
|
26
|
+
remove: (key: string) => void
|
|
27
|
+
}
|
|
28
|
+
/** What an area tells the shared keys (`createSharedKeys`). */
|
|
29
|
+
declare interface SharedHooks {
|
|
30
|
+
read: (key: string) => void
|
|
31
|
+
wrote: (key: string) => void
|
|
32
|
+
readAll: () => void
|
|
33
|
+
}
|
|
34
|
+
/** The native item a shared key is kept in: Craft's secure storage. */
|
|
35
|
+
export declare interface NativeSecureStore {
|
|
36
|
+
getSync: (key: string) => unknown
|
|
37
|
+
set: (key: string, value: string) => unknown
|
|
38
|
+
remove: (key: string) => unknown
|
|
39
|
+
}
|
|
40
|
+
export declare interface NativeWebStorageOptions {
|
|
41
|
+
shareStorage?: Record<string, string>
|
|
42
|
+
secure?: () => NativeSecureStore | null
|
|
43
|
+
adopted?: (key: string, value: string | null) => void
|
|
44
|
+
}
|
|
45
|
+
export declare interface NativeSharedKeys {
|
|
46
|
+
changed: (nativeKey: string) => void
|
|
47
|
+
}
|
|
20
48
|
/**
|
|
21
49
|
* `localStorage` and `sessionStorage` on a native screen.
|
|
22
50
|
*
|
|
@@ -41,11 +69,22 @@ export declare interface NativeSyncStore {
|
|
|
41
69
|
*
|
|
42
70
|
* Neither is scoped to the signed-in account: a site's storage is not, and
|
|
43
71
|
* the token that says which account is signed in is kept here.
|
|
72
|
+
*
|
|
73
|
+
* A key the app shares with its native side (Craft's `shareStorage`, such as
|
|
74
|
+
* `{ auth_token: 'auth.token' }`) is also the Keychain item it names, as it
|
|
75
|
+
* is for Craft's hybrid page: a write in either area keeps the item at the
|
|
76
|
+
* key's value (sessionStorage's, else localStorage's), and a change made
|
|
77
|
+
* elsewhere (a native sign-in, a sign-out on another screen) is adopted into
|
|
78
|
+
* localStorage when the key is next read, and announced as the page's
|
|
79
|
+
* `craftsharedstorage` event. A web view's sign-in is then `craft.session`'s,
|
|
80
|
+
* and a native sign-in is the web view's.
|
|
44
81
|
*/
|
|
45
82
|
declare type AnyRecord = Record<string, any> // eslint-disable-line ts/no-explicit-any;
|
|
46
83
|
/** A `Storage` (the web's interface) kept in `store()`, under `prefix`. */
|
|
47
84
|
export declare class NativeWebStorage {
|
|
48
85
|
constructor(store: () => NativeSyncStore | null, prefix: string, run?: (() => string) | null);
|
|
86
|
+
get [RAW](): RawArea;
|
|
87
|
+
set [RAW](hooks: SharedHooks | null);
|
|
49
88
|
get length(): number;
|
|
50
89
|
key(index: number): string | null;
|
|
51
90
|
getItem(key: string): string | null;
|