@stacksjs/stx 0.2.422 → 0.2.423
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-ep5jnqdb.js → chunk-02n071n7.js} +6 -6
- package/dist/chunk-03n23sh6.js +2 -0
- package/dist/chunk-07mxghsz.js +2 -0
- package/dist/{chunk-kjkwycce.js → chunk-0bmc75w6.js} +4 -4
- package/dist/{chunk-hyak4dzg.js → chunk-0hhq9hbq.js} +3 -3
- package/dist/{chunk-66k7yxnr.js → chunk-12pvnn1e.js} +4 -4
- package/dist/chunk-1497wcxc.js +2 -0
- package/dist/chunk-17n9e5wk.js +2 -0
- package/dist/chunk-1p8hc1ve.js +2 -0
- package/dist/chunk-1r3ghgsz.js +2 -0
- package/dist/{chunk-681cxw8j.js → chunk-24e7qjb8.js} +2 -2
- package/dist/chunk-259ecbwa.js +2 -0
- package/dist/chunk-26gfsa9w.js +2 -0
- package/dist/{chunk-zp0mg8b2.js → chunk-2bpjq1qz.js} +2 -2
- package/dist/{chunk-11ra3sbc.js → chunk-2x9jd5w0.js} +3 -3
- package/dist/{chunk-k31fwm2w.js → chunk-3hmy75tw.js} +5 -5
- package/dist/{chunk-12b8akfg.js → chunk-3pxp0r0a.js} +3 -3
- package/dist/{chunk-x5ks23vx.js → chunk-3ry9ca1s.js} +2 -2
- package/dist/{chunk-th9s15es.js → chunk-45rfv3a5.js} +2 -2
- package/dist/chunk-47apfsxp.js +2 -0
- package/dist/{chunk-w72p2ak0.js → chunk-48kgnqpk.js} +4 -4
- package/dist/{chunk-rsxvbnp4.js → chunk-4hd5wb8x.js} +3 -3
- package/dist/chunk-535nrr6j.js +2 -0
- package/dist/chunk-5mfhk69g.js +2 -0
- package/dist/{chunk-aync8qmk.js → chunk-5vwg3h5g.js} +2 -2
- package/dist/{chunk-tspmynvh.js → chunk-62chbqev.js} +1 -1
- package/dist/chunk-6c7294j8.js +2 -0
- package/dist/{chunk-qwgdtrhj.js → chunk-6cbvx87h.js} +5 -5
- package/dist/{chunk-q0cehgy2.js → chunk-6fsbny9m.js} +3 -3
- package/dist/chunk-6gh2rvyz.js +2 -0
- package/dist/chunk-6j6gbp0y.js +2 -0
- package/dist/chunk-6jgjmycb.js +2 -0
- package/dist/{chunk-w83djypm.js → chunk-6t278w29.js} +2 -2
- package/dist/{chunk-5vfyxxrp.js → chunk-6t7mxb0b.js} +2 -2
- package/dist/chunk-6wmxrn6x.js +2 -0
- package/dist/chunk-6wweqfg7.js +2 -0
- package/dist/{chunk-ja7znxnz.js → chunk-7a9h7ycs.js} +5 -5
- package/dist/chunk-7pbv9mg7.js +2 -0
- package/dist/{chunk-09hhrjk9.js → chunk-89b2r1q0.js} +6 -6
- package/dist/{chunk-0varh725.js → chunk-8a0r2j8f.js} +3 -3
- package/dist/{chunk-gp8xzbyt.js → chunk-8nsbf2mz.js} +1074 -1074
- package/dist/{chunk-mg13q1kd.js → chunk-8zf5q1m3.js} +2 -2
- package/dist/chunk-9d53d0t6.js +2 -0
- package/dist/chunk-9j72har9.js +2 -0
- package/dist/chunk-9yqz5ge5.js +2 -0
- package/dist/chunk-a5c9n7an.js +2 -0
- package/dist/chunk-a836zn7c.js +2 -0
- package/dist/{chunk-kzkjc12e.js → chunk-a8g6y9kw.js} +5 -5
- package/dist/{chunk-21a7p956.js → chunk-acwgap78.js} +1 -1
- package/dist/{chunk-qx3js9tk.js → chunk-aen2baze.js} +1 -1
- package/dist/chunk-ahgrkva8.js +2 -0
- package/dist/chunk-akbb6j7s.js +2 -0
- package/dist/chunk-avakcrbs.js +2 -0
- package/dist/{chunk-tafebmtg.js → chunk-axydabse.js} +2 -2
- package/dist/{chunk-4n6c5rp5.js → chunk-b7973zvk.js} +2 -2
- package/dist/{chunk-ebkpdc45.js → chunk-bxwe7wxj.js} +10 -10
- package/dist/{chunk-2ewa2sg5.js → chunk-c1dmr865.js} +3 -3
- package/dist/chunk-cenq2n6e.js +2 -0
- package/dist/{chunk-zvh2nnzr.js → chunk-cf6htz63.js} +1 -1
- package/dist/chunk-cnmz9543.js +2 -0
- package/dist/{chunk-h1585jbm.js → chunk-cx2rdew4.js} +13 -13
- package/dist/{chunk-wg1ttvs5.js → chunk-cznsm2n3.js} +2 -2
- package/dist/chunk-d1qzhawc.js +2 -0
- package/dist/chunk-d6hnvwre.js +2 -0
- package/dist/{chunk-7abgzdsm.js → chunk-dcwjxq8n.js} +2 -2
- package/dist/chunk-dhqwg62x.js +2 -0
- package/dist/{chunk-95e3rz88.js → chunk-dmd6yk2x.js} +5 -5
- package/dist/chunk-e18qfegt.js +2 -0
- package/dist/chunk-eej89wkt.js +2 -0
- package/dist/chunk-ekxffxbd.js +2 -0
- package/dist/{chunk-hy9e3ny6.js → chunk-ex0tq6x2.js} +1 -1
- package/dist/{chunk-nqr77pxk.js → chunk-fg5ve6ey.js} +2 -2
- package/dist/{chunk-dejsjk4h.js → chunk-fnt1q1sp.js} +11 -11
- package/dist/chunk-g67gg66e.js +2 -0
- package/dist/chunk-gq16fxc2.js +2 -0
- package/dist/{chunk-5e9zkd65.js → chunk-h3c7z73m.js} +2 -2
- package/dist/chunk-h4avjh3q.js +2 -0
- package/dist/chunk-h7qte7ye.js +2 -0
- package/dist/{chunk-hmdnn9ja.js → chunk-hb9gxad0.js} +3 -3
- package/dist/{chunk-dmxh7zwq.js → chunk-hg4k3nkr.js} +1 -1
- package/dist/{chunk-dhxbjw6k.js → chunk-hnep9jbj.js} +2 -2
- package/dist/chunk-hwycbxg7.js +2 -0
- package/dist/{chunk-34gy5zjm.js → chunk-j1q65enz.js} +2 -2
- package/dist/chunk-j5myfxe8.js +18 -0
- package/dist/{chunk-8jqy69td.js → chunk-j7zywbq0.js} +2 -2
- package/dist/{chunk-788g87ft.js → chunk-jbrdebzs.js} +7 -7
- package/dist/{chunk-wr6b99pw.js → chunk-jj4pyeyj.js} +1 -1
- package/dist/{chunk-g1fxmp9z.js → chunk-k8sqs7j2.js} +4 -4
- package/dist/chunk-mg7jhx5v.js +2 -0
- package/dist/chunk-n16wa755.js +2 -0
- package/dist/chunk-ngv1c807.js +2 -0
- package/dist/{chunk-krr2vb0s.js → chunk-p2x7tjbt.js} +3 -3
- package/dist/{chunk-62r4fa4q.js → chunk-ptjqacjd.js} +2 -2
- package/dist/{chunk-597rfddk.js → chunk-qm1tt8g1.js} +2334 -2334
- package/dist/chunk-r7r5h2eh.js +2 -0
- package/dist/chunk-rhkx17d9.js +2 -0
- package/dist/{chunk-b1fg9vg7.js → chunk-s28eh0jn.js} +2 -2
- package/dist/{chunk-837nb4zv.js → chunk-s295vp9x.js} +3 -3
- package/dist/chunk-sazpw71r.js +4 -0
- package/dist/{chunk-20tdz0zs.js → chunk-sbdzqqr1.js} +6 -6
- package/dist/{chunk-qby6wxat.js → chunk-spx27cs4.js} +2 -2
- package/dist/{chunk-n7jjp08m.js → chunk-stxmwytg.js} +2 -2
- package/dist/{chunk-2tfe2g58.js → chunk-t3wh1jbk.js} +6 -6
- package/dist/{chunk-802pr252.js → chunk-tfexmdkt.js} +2 -2
- package/dist/{chunk-2cn8krpp.js → chunk-tfz95n7j.js} +5 -5
- package/dist/chunk-thdbqsxq.js +2 -0
- package/dist/chunk-tpnfcb83.js +2 -0
- package/dist/chunk-tqkv4th9.js +2 -0
- package/dist/chunk-tznejj9h.js +2 -0
- package/dist/{chunk-ap6fehea.js → chunk-vfk725vm.js} +5 -5
- package/dist/chunk-vsrm9k7p.js +2 -0
- package/dist/chunk-vwms759h.js +2 -0
- package/dist/{chunk-xvzxrt9a.js → chunk-w2085fwx.js} +5 -5
- package/dist/chunk-w252cgnv.js +30 -0
- package/dist/chunk-whdw6dhb.js +2 -0
- package/dist/chunk-wtms9jhs.js +3 -0
- package/dist/chunk-wtqjfar3.js +2 -0
- package/dist/chunk-wx7kfet5.js +2 -0
- package/dist/chunk-wy873fy8.js +2 -0
- package/dist/{chunk-d2z6828s.js → chunk-xa3wsmt5.js} +11 -11
- package/dist/chunk-xrbqf77j.js +2 -0
- package/dist/{chunk-757ec865.js → chunk-yaebdyfr.js} +2 -2
- package/dist/chunk-ycpq3gxc.js +2 -0
- package/dist/chunk-yd50awqp.js +3 -0
- package/dist/{chunk-csjw5esc.js → chunk-ydz7w2mt.js} +2 -2
- package/dist/chunk-yjgbxf26.js +2 -0
- package/dist/{chunk-jjnfj9nf.js → chunk-yqsza22w.js} +2 -2
- package/dist/{chunk-3xm6dyab.js → chunk-zbr333kf.js} +88 -27
- package/dist/chunk-zcyjdcpx.js +33 -0
- package/dist/{chunk-tqnysw0k.js → chunk-zfzcedw4.js} +4 -4
- package/dist/chunk-zm73n103.js +2 -0
- package/dist/cli.js +20 -20
- package/dist/component-renderer.js +54 -2
- package/dist/composables/use-outbox.d.ts +1 -0
- package/dist/composables/use-outbox.js +14 -4
- package/dist/craft-entry.js +2 -2
- package/dist/craft.js +2 -2
- package/dist/database.js +2 -2
- package/dist/native/bridge/protocol.d.ts +5 -0
- package/dist/native/bridge/protocol.js +3 -0
- package/dist/native/cli.js +12 -2
- package/dist/native/compiler/bundle.d.ts +4 -3
- package/dist/native/compiler/bundle.js +46 -51
- package/dist/native/compiler/component-mapping.d.ts +5 -0
- package/dist/native/compiler/component-mapping.js +90 -0
- package/dist/native/compiler/html-to-ir.js +42 -6
- package/dist/native/compiler/ir.d.ts +2 -0
- package/dist/native/compiler/render-screen.d.ts +4 -0
- package/dist/native/compiler/render-screen.js +10 -2
- package/dist/native/compiler/setup-script.d.ts +6 -0
- package/dist/native/compiler/setup-script.js +10 -0
- package/dist/native/components/primitives.d.ts +10 -0
- package/dist/native/index.d.ts +6 -24
- package/dist/native/index.js +1 -17
- package/dist/native/primitives/Button.stx +2 -1
- package/dist/native/primitives/Text.stx +2 -1
- package/dist/native/primitives/TextInput.stx +3 -1
- package/dist/native/prop-names.d.ts +2 -0
- package/dist/native/prop-names.js +71 -0
- package/dist/native/runtime/binding-tree.d.ts +31 -0
- package/dist/native/runtime/binding-tree.js +100 -0
- package/dist/native/runtime/craft-bridge.d.ts +9 -0
- package/dist/native/runtime/craft-bridge.js +231 -0
- package/dist/native/runtime/craft.d.ts +28 -3
- package/dist/native/runtime/jsc-globals.d.ts +16 -0
- package/dist/native/runtime/jsc-globals.js +64 -0
- package/dist/native/runtime/native-host.d.ts +3 -1
- package/dist/native/runtime/native-host.js +183 -33
- package/dist/native/runtime/shared-screen.d.ts +15 -0
- package/dist/native/runtime/shared-screen.js +41 -0
- package/dist/pwa.js +3 -3
- package/dist/signal-processing.d.ts +3 -1
- package/dist/signal-processing.js +4 -3
- package/dist/signals.js +77 -16
- package/dist/ssg.js +28 -28
- package/package.json +5 -5
- package/dist/chunk-10fh9qhe.js +0 -2
- package/dist/chunk-1569v24d.js +0 -2
- package/dist/chunk-18awnp9d.js +0 -2
- package/dist/chunk-1r0c5920.js +0 -30
- package/dist/chunk-2hswgxpb.js +0 -2
- package/dist/chunk-4363reg4.js +0 -2
- package/dist/chunk-48axv7bm.js +0 -2
- package/dist/chunk-50hgr79y.js +0 -2
- package/dist/chunk-54wczcee.js +0 -2
- package/dist/chunk-74gz26zs.js +0 -2
- package/dist/chunk-7906p8zs.js +0 -2
- package/dist/chunk-7dkfjmjw.js +0 -2
- package/dist/chunk-7vr5w75r.js +0 -4
- package/dist/chunk-7zn0yyqk.js +0 -2
- package/dist/chunk-8d2kamh2.js +0 -2
- package/dist/chunk-8ttvazck.js +0 -2
- package/dist/chunk-8y4bqsxz.js +0 -2
- package/dist/chunk-9bpnz431.js +0 -2
- package/dist/chunk-ac033b93.js +0 -2
- package/dist/chunk-aj43359g.js +0 -2
- package/dist/chunk-aj8yq228.js +0 -2
- package/dist/chunk-as72dvvm.js +0 -2
- package/dist/chunk-bfvaxrq0.js +0 -2
- package/dist/chunk-bkaw7sgz.js +0 -2
- package/dist/chunk-d0q2x8e3.js +0 -2
- package/dist/chunk-d2c5727w.js +0 -2
- package/dist/chunk-d5amzers.js +0 -2
- package/dist/chunk-dfchrqw5.js +0 -2
- package/dist/chunk-epv0ahg1.js +0 -2
- package/dist/chunk-f5489ese.js +0 -2
- package/dist/chunk-fqq1w9m1.js +0 -2
- package/dist/chunk-hcgsgnq8.js +0 -2
- package/dist/chunk-hgqcqg1h.js +0 -2
- package/dist/chunk-hjdwf9gp.js +0 -2
- package/dist/chunk-hp7ewdnp.js +0 -2
- package/dist/chunk-jjtzm6dn.js +0 -3
- package/dist/chunk-js79j12f.js +0 -18
- package/dist/chunk-kfsp322p.js +0 -2
- package/dist/chunk-kt557jaj.js +0 -2
- package/dist/chunk-n8kqvzba.js +0 -2
- package/dist/chunk-na70r4sp.js +0 -2
- package/dist/chunk-p083sckk.js +0 -2
- package/dist/chunk-pc178389.js +0 -2
- package/dist/chunk-psqk7932.js +0 -2
- package/dist/chunk-pv5nr9pd.js +0 -2
- package/dist/chunk-q1v0jwr4.js +0 -2
- package/dist/chunk-qeye0901.js +0 -2
- package/dist/chunk-qy59yp2v.js +0 -2
- package/dist/chunk-r5gjb55x.js +0 -2
- package/dist/chunk-tf44jyrh.js +0 -2
- package/dist/chunk-tfypkw4y.js +0 -3
- package/dist/chunk-vv4kkwhn.js +0 -2
- package/dist/chunk-vwhd3h8x.js +0 -2
- package/dist/chunk-vxj8kd2v.js +0 -2
- package/dist/chunk-vzzpvn21.js +0 -2
- package/dist/chunk-w1a2v264.js +0 -2
- package/dist/chunk-wcs7w8wv.js +0 -2
- package/dist/chunk-x6ndnpvr.js +0 -2
- package/dist/chunk-x8rckpyz.js +0 -2
- package/dist/chunk-ya0qecph.js +0 -27
- package/dist/chunk-ykwmqh8z.js +0 -2
- package/dist/chunk-ys71pmrb.js +0 -2
- package/dist/chunk-z5y4qyhg.js +0 -2
- package/dist/chunk-zpcz2kh6.js +0 -2
- package/dist/native/compiler/codegen.d.ts +0 -10
- package/dist/native/compiler/codegen.js +0 -145
- package/dist/native/compiler/parser.d.ts +0 -88
- package/dist/native/compiler/parser.js +0 -753
- package/dist/native/runtime/entry.d.ts +0 -1
- package/dist/native/runtime/entry.js +0 -3
- package/dist/native/runtime/index.d.ts +0 -45
- package/dist/native/runtime/index.js +0 -165
- package/dist/native/runtime/screen.d.ts +0 -43
- package/dist/native/runtime/screen.js +0 -808
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { type BindingManifest } from '../../binding-manifest';
|
|
2
|
+
import { type GeneratedSetupScript } from './setup-script';
|
|
1
3
|
import type { STXDocument } from './ir';
|
|
2
4
|
import type { TranslationDiagnostic } from './html-to-ir';
|
|
3
5
|
/**
|
|
@@ -21,6 +23,8 @@ export declare interface CompileScreenOptions {
|
|
|
21
23
|
}
|
|
22
24
|
export declare interface CompiledScreen {
|
|
23
25
|
document: STXDocument
|
|
26
|
+
manifest: BindingManifest
|
|
27
|
+
setup: GeneratedSetupScript | null
|
|
24
28
|
diagnostics: TranslationDiagnostic[]
|
|
25
29
|
html: string
|
|
26
30
|
}
|
|
@@ -1,8 +1,11 @@
|
|
|
1
1
|
import { existsSync } from "node:fs";
|
|
2
2
|
import path from "node:path";
|
|
3
|
+
import { extractBindingManifest } from "../../binding-manifest.js";
|
|
3
4
|
import { processDirectives } from "../../process.js";
|
|
5
|
+
import { processScriptSetup } from "../../signal-processing.js";
|
|
4
6
|
import { translateHtmlToDocument } from "./html-to-ir.js";
|
|
5
7
|
import { extractClientScript } from "./client-script.js";
|
|
8
|
+
import { extractGeneratedSetupScript } from "./setup-script.js";
|
|
6
9
|
export function nativePrimitivesDir() {
|
|
7
10
|
const candidates = [
|
|
8
11
|
path.join(import.meta.dir, "..", "primitives"),
|
|
@@ -20,11 +23,16 @@ export async function compileScreenSource(source, filePath, options = {}) {
|
|
|
20
23
|
buildMode: "serve",
|
|
21
24
|
cache: !1,
|
|
22
25
|
_pluginComponentDirs: [nativePrimitivesDir()]
|
|
23
|
-
},
|
|
26
|
+
}, context = { ...options.context ?? {}, __stx_inject_css: !1 }, renderedHtml = await processDirectives(source, context, filePath, config, new Set), { html, manifest } = extractBindingManifest(renderedHtml), { document, diagnostics } = await translateHtmlToDocument(html, {
|
|
24
27
|
source: filePath,
|
|
25
28
|
script: extractClientScript(source)
|
|
26
29
|
});
|
|
27
|
-
|
|
30
|
+
let setup = extractGeneratedSetupScript(html);
|
|
31
|
+
if (extractClientScript(source).code.trim()) {
|
|
32
|
+
const forced = await processScriptSetup(source, filePath, options.context, { forceClientSetup: !0 });
|
|
33
|
+
setup = extractGeneratedSetupScript(forced.setupCode ?? "") ?? setup;
|
|
34
|
+
}
|
|
35
|
+
return { document, manifest, setup, diagnostics, html };
|
|
28
36
|
}
|
|
29
37
|
export async function compileScreenFile(filePath, options = {}) {
|
|
30
38
|
return compileScreenSource(await Bun.file(filePath).text(), filePath, options);
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
const SCOPED_SCRIPT = /<script\b[^>]*\bdata-stx-scoped\b[^>]*>([\s\S]*?)<\/script>/gi, SETUP_NAME = /function\s+(__stx_setup_[\w$]+)\s*\(/;
|
|
2
|
+
export function extractGeneratedSetupScript(html) {
|
|
3
|
+
SCOPED_SCRIPT.lastIndex = 0;
|
|
4
|
+
for (const match of html.matchAll(SCOPED_SCRIPT)) {
|
|
5
|
+
const code = match[1].trim(), name = SETUP_NAME.exec(code)?.[1];
|
|
6
|
+
if (name)
|
|
7
|
+
return { name, code };
|
|
8
|
+
}
|
|
9
|
+
return null;
|
|
10
|
+
}
|
|
@@ -148,6 +148,16 @@ export declare interface SliderProps extends BaseProps {
|
|
|
148
148
|
maximumTrackTintColor?: string
|
|
149
149
|
thumbTintColor?: string
|
|
150
150
|
}
|
|
151
|
+
export declare interface PickerOption {
|
|
152
|
+
label: string
|
|
153
|
+
value: string | number
|
|
154
|
+
}
|
|
155
|
+
export declare interface PickerProps extends BaseProps {
|
|
156
|
+
items: PickerOption[]
|
|
157
|
+
selectedValue?: string | number
|
|
158
|
+
onValueChange?: (value: string | number, index: number) => void
|
|
159
|
+
disabled?: boolean
|
|
160
|
+
}
|
|
151
161
|
// ============================================================================
|
|
152
162
|
// Media Components
|
|
153
163
|
// ============================================================================
|
package/dist/native/index.d.ts
CHANGED
|
@@ -18,21 +18,21 @@ export type {
|
|
|
18
18
|
ModalProps,
|
|
19
19
|
SwitchProps,
|
|
20
20
|
SliderProps,
|
|
21
|
+
PickerOption,
|
|
22
|
+
PickerProps,
|
|
21
23
|
} from './components/primitives';
|
|
22
|
-
export type { Token, TokenType } from './compiler/parser';
|
|
23
24
|
export type {
|
|
24
25
|
HotReloadMessage,
|
|
25
26
|
HotReloadState,
|
|
26
27
|
HotReloadCallback,
|
|
27
28
|
ErrorOverlayOptions,
|
|
28
29
|
} from './hot-reload/client';
|
|
29
|
-
export type { RuntimeConfig } from './runtime/index';
|
|
30
30
|
/**
|
|
31
31
|
* `@stacksjs/stx/native`: stx templates as native iOS/Android screens.
|
|
32
32
|
*
|
|
33
|
-
* A `.stx` screen compiles to a
|
|
34
|
-
* UIKit (and Android views)
|
|
35
|
-
*
|
|
33
|
+
* A `.stx` screen compiles to rendered IR plus a binding manifest that Craft
|
|
34
|
+
* draws with UIKit (and Android views). The ordinary stx signals runtime owns
|
|
35
|
+
* client state and sends targeted native-tree mutations without a WebView.
|
|
36
36
|
*
|
|
37
37
|
* @example
|
|
38
38
|
* ```ts
|
|
@@ -51,26 +51,17 @@ export type { RuntimeConfig } from './runtime/index';
|
|
|
51
51
|
// Compiler exports
|
|
52
52
|
export * from './compiler/ir';
|
|
53
53
|
export * from './compiler/headwind-to-style';
|
|
54
|
-
export * from './compiler/parser';
|
|
55
54
|
export * from './compiler/html-to-ir';
|
|
56
55
|
export * from './compiler/client-script';
|
|
57
56
|
export * from './compiler/render-screen';
|
|
58
57
|
export * from './compiler/bundle';
|
|
59
58
|
export * from './compiler/icons';
|
|
60
59
|
export * from './cli';
|
|
60
|
+
export * from './runtime/shared-screen';
|
|
61
61
|
// Bridge exports
|
|
62
62
|
export * from './bridge/protocol';
|
|
63
63
|
// Component exports
|
|
64
64
|
export * from './components/primitives';
|
|
65
|
-
// Parser exports
|
|
66
|
-
export {
|
|
67
|
-
parseSTX,
|
|
68
|
-
parseSTXToNode,
|
|
69
|
-
compileSTX,
|
|
70
|
-
compileSTXFiles,
|
|
71
|
-
mapToNativeComponent,
|
|
72
|
-
transformToNativeComponents,
|
|
73
|
-
} from './compiler/parser';
|
|
74
65
|
// Hot Reload exports
|
|
75
66
|
export {
|
|
76
67
|
getHotReloadClient,
|
|
@@ -79,12 +70,3 @@ export {
|
|
|
79
70
|
HotReloadClient,
|
|
80
71
|
ErrorOverlay,
|
|
81
72
|
} from './hot-reload/client';
|
|
82
|
-
// Runtime exports
|
|
83
|
-
export {
|
|
84
|
-
getRuntime,
|
|
85
|
-
startRuntime,
|
|
86
|
-
render,
|
|
87
|
-
setState,
|
|
88
|
-
getState,
|
|
89
|
-
STXRuntime,
|
|
90
|
-
} from './runtime/index';
|
package/dist/native/index.js
CHANGED
|
@@ -1,22 +1,14 @@
|
|
|
1
1
|
export * from "./compiler/ir.js";
|
|
2
2
|
export * from "./compiler/headwind-to-style.js";
|
|
3
|
-
export * from "./compiler/parser.js";
|
|
4
3
|
export * from "./compiler/html-to-ir.js";
|
|
5
4
|
export * from "./compiler/client-script.js";
|
|
6
5
|
export * from "./compiler/render-screen.js";
|
|
7
6
|
export * from "./compiler/bundle.js";
|
|
8
7
|
export * from "./compiler/icons.js";
|
|
9
8
|
export * from "./cli.js";
|
|
9
|
+
export * from "./runtime/shared-screen.js";
|
|
10
10
|
export * from "./bridge/protocol.js";
|
|
11
11
|
export * from "./components/primitives.js";
|
|
12
|
-
export {
|
|
13
|
-
parseSTX,
|
|
14
|
-
parseSTXToNode,
|
|
15
|
-
compileSTX,
|
|
16
|
-
compileSTXFiles,
|
|
17
|
-
mapToNativeComponent,
|
|
18
|
-
transformToNativeComponents
|
|
19
|
-
} from "./compiler/parser.js";
|
|
20
12
|
export {
|
|
21
13
|
getHotReloadClient,
|
|
22
14
|
getErrorOverlay,
|
|
@@ -24,11 +16,3 @@ export {
|
|
|
24
16
|
HotReloadClient,
|
|
25
17
|
ErrorOverlay
|
|
26
18
|
} from "./hot-reload/client.js";
|
|
27
|
-
export {
|
|
28
|
-
getRuntime,
|
|
29
|
-
startRuntime,
|
|
30
|
-
render,
|
|
31
|
-
setState,
|
|
32
|
-
getState,
|
|
33
|
-
STXRuntime
|
|
34
|
-
} from "./runtime/index.js";
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
{{-- Button: the native type, written as an ordinary stx component. --}}
|
|
2
2
|
<script server>
|
|
3
3
|
const classes = $props.class ?? $props.className ?? ''
|
|
4
|
+
const testID = $props.testID
|
|
4
5
|
</script>
|
|
5
|
-
<button data-native="Button" class="{{ classes }}" type="button"><slot /></button>
|
|
6
|
+
<button data-native="Button" class="{{ classes }}" type="button" @if(testID) testID="{{ testID }}" @endif><slot /></button>
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
{{-- Text: the native type, written as an ordinary stx component. --}}
|
|
2
2
|
<script server>
|
|
3
3
|
const classes = $props.class ?? $props.className ?? ''
|
|
4
|
+
const testID = $props.testID
|
|
4
5
|
</script>
|
|
5
|
-
<span data-native="Text" class="{{ classes }}"><slot /></span>
|
|
6
|
+
<span data-native="Text" class="{{ classes }}" @if(testID) testID="{{ testID }}" @endif><slot /></span>
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
{{-- TextInput: the native type, written as an ordinary stx component. --}}
|
|
2
2
|
<script server>
|
|
3
3
|
const classes = $props.class ?? $props.className ?? ''
|
|
4
|
+
const testID = $props.testID
|
|
5
|
+
const placeholder = $props.placeholder
|
|
4
6
|
</script>
|
|
5
|
-
<input data-native="TextInput" class="{{ classes }}" />
|
|
7
|
+
<input data-native="TextInput" class="{{ classes }}" @if(testID) testID="{{ testID }}" @endif @if(placeholder) placeholder="{{ placeholder }}" @endif />
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
const NATIVE_PROP_NAMES = [
|
|
2
|
+
"accessibilityHint",
|
|
3
|
+
"accessibilityLabel",
|
|
4
|
+
"accessibilityRole",
|
|
5
|
+
"accessibilityState",
|
|
6
|
+
"accessibilityValue",
|
|
7
|
+
"activeOpacity",
|
|
8
|
+
"alwaysBounceHorizontal",
|
|
9
|
+
"alwaysBounceVertical",
|
|
10
|
+
"animationType",
|
|
11
|
+
"autoCapitalize",
|
|
12
|
+
"autoCorrect",
|
|
13
|
+
"autoFocus",
|
|
14
|
+
"blurRadius",
|
|
15
|
+
"contentContainerStyle",
|
|
16
|
+
"defaultSource",
|
|
17
|
+
"defaultValue",
|
|
18
|
+
"ellipsizeMode",
|
|
19
|
+
"fadeDuration",
|
|
20
|
+
"hidesWhenStopped",
|
|
21
|
+
"hitSlop",
|
|
22
|
+
"imageStyle",
|
|
23
|
+
"initialNumToRender",
|
|
24
|
+
"iosBackgroundColor",
|
|
25
|
+
"keyboardDismissMode",
|
|
26
|
+
"keyboardShouldPersistTaps",
|
|
27
|
+
"keyboardType",
|
|
28
|
+
"keyboardVerticalOffset",
|
|
29
|
+
"keyExtractor",
|
|
30
|
+
"maxLength",
|
|
31
|
+
"maximumTrackTintColor",
|
|
32
|
+
"maximumValue",
|
|
33
|
+
"maxToRenderPerBatch",
|
|
34
|
+
"minimumTrackTintColor",
|
|
35
|
+
"minimumValue",
|
|
36
|
+
"numberOfLines",
|
|
37
|
+
"numColumns",
|
|
38
|
+
"onEndReachedThreshold",
|
|
39
|
+
"pagingEnabled",
|
|
40
|
+
"placeholderTextColor",
|
|
41
|
+
"pointerEvents",
|
|
42
|
+
"presentationStyle",
|
|
43
|
+
"pressRetentionOffset",
|
|
44
|
+
"progressBackgroundColor",
|
|
45
|
+
"progressViewOffset",
|
|
46
|
+
"refreshControl",
|
|
47
|
+
"resizeMode",
|
|
48
|
+
"returnKeyType",
|
|
49
|
+
"scrollEnabled",
|
|
50
|
+
"scrollTarget",
|
|
51
|
+
"secureTextEntry",
|
|
52
|
+
"selectedValue",
|
|
53
|
+
"selectionColor",
|
|
54
|
+
"showsHorizontalScrollIndicator",
|
|
55
|
+
"showsVerticalScrollIndicator",
|
|
56
|
+
"statusBarTranslucent",
|
|
57
|
+
"stickyHeaderIndices",
|
|
58
|
+
"testID",
|
|
59
|
+
"thumbColor",
|
|
60
|
+
"thumbTintColor",
|
|
61
|
+
"titleColor",
|
|
62
|
+
"trackColor",
|
|
63
|
+
"underlayColor",
|
|
64
|
+
"windowSize"
|
|
65
|
+
], nativePropNames = new Map(NATIVE_PROP_NAMES.map((name) => [normaliseKey(name), name]));
|
|
66
|
+
function normaliseKey(name) {
|
|
67
|
+
return name.replace(/[-_]/g, "").toLowerCase();
|
|
68
|
+
}
|
|
69
|
+
export function nativePropName(name) {
|
|
70
|
+
return nativePropNames.get(normaliseKey(name)) ?? name;
|
|
71
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import type { BindingManifest } from '../../binding-manifest';
|
|
2
|
+
import type { NativeHost, NativeNode } from './native-host';
|
|
3
|
+
import type { STXDocument } from '../compiler/ir';
|
|
4
|
+
/** Clone the DOM-shaped metadata while the host clones the native descriptor. */
|
|
5
|
+
export declare function cloneNativeBindingNode(source: NativeBindingNode, id: string): NativeBindingNode;
|
|
6
|
+
/** Build host handles and a manifest-id lookup from already translated IR. */
|
|
7
|
+
export declare function materializeNativeBindingTree(document: STXDocument, manifest: BindingManifest, host: NativeHost): NativeBindingTree;
|
|
8
|
+
export declare interface NativeBindingNode extends NativeNode {
|
|
9
|
+
nodeType: 1
|
|
10
|
+
tagName: string
|
|
11
|
+
attributes: Array<{ name: string, value: string }>
|
|
12
|
+
parentNode: NativeBindingNode | null
|
|
13
|
+
parentElement: NativeBindingNode | null
|
|
14
|
+
childNodes: NativeNode[]
|
|
15
|
+
children: NativeNode[]
|
|
16
|
+
readonly nextSibling: NativeNode | null
|
|
17
|
+
readonly nextElementSibling: NativeBindingNode | null
|
|
18
|
+
namespaceURI: string
|
|
19
|
+
isConnected: boolean
|
|
20
|
+
hasAttribute: (name: string) => boolean
|
|
21
|
+
getAttribute: (name: string) => string | null
|
|
22
|
+
setAttribute: (name: string, value: unknown) => void
|
|
23
|
+
removeAttribute: (name: string) => void
|
|
24
|
+
contains: (node: NativeBindingNode) => boolean
|
|
25
|
+
querySelector: (selector: string) => NativeBindingNode | null
|
|
26
|
+
querySelectorAll: (selector: string) => NativeBindingNode[]
|
|
27
|
+
}
|
|
28
|
+
export declare interface NativeBindingTree {
|
|
29
|
+
root: NativeBindingNode
|
|
30
|
+
nodes: Map<number, NativeBindingNode>
|
|
31
|
+
}
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
function decodeBindingValue(value) {
|
|
2
|
+
return value.replace(/</g, "<").replace(/>/g, ">").replace(/"/g, '"').replace(/�?39;/g, "'").replace(/'/gi, "'").replace(/&/g, "&");
|
|
3
|
+
}
|
|
4
|
+
function createBindingNode(id, type, bindings, connected = !0) {
|
|
5
|
+
const attributes = bindings.map((binding) => ({
|
|
6
|
+
name: binding.name,
|
|
7
|
+
value: decodeBindingValue(binding.value)
|
|
8
|
+
})), node = {
|
|
9
|
+
__stxId: id,
|
|
10
|
+
nodeType: 1,
|
|
11
|
+
tagName: type.toUpperCase(),
|
|
12
|
+
attributes,
|
|
13
|
+
parentNode: null,
|
|
14
|
+
parentElement: null,
|
|
15
|
+
childNodes: [],
|
|
16
|
+
children: [],
|
|
17
|
+
nextSibling: null,
|
|
18
|
+
nextElementSibling: null,
|
|
19
|
+
namespaceURI: "",
|
|
20
|
+
isConnected: !0,
|
|
21
|
+
hasAttribute(name) {
|
|
22
|
+
return attributes.some((attribute) => attribute.name === name);
|
|
23
|
+
},
|
|
24
|
+
getAttribute(name) {
|
|
25
|
+
return attributes.find((attribute) => attribute.name === name)?.value ?? null;
|
|
26
|
+
},
|
|
27
|
+
setAttribute(name, value) {
|
|
28
|
+
const existing = attributes.find((attribute) => attribute.name === name);
|
|
29
|
+
if (existing)
|
|
30
|
+
existing.value = String(value);
|
|
31
|
+
else
|
|
32
|
+
attributes.push({ name, value: String(value) });
|
|
33
|
+
},
|
|
34
|
+
removeAttribute(name) {
|
|
35
|
+
const index = attributes.findIndex((attribute) => attribute.name === name);
|
|
36
|
+
if (index !== -1)
|
|
37
|
+
attributes.splice(index, 1);
|
|
38
|
+
},
|
|
39
|
+
contains(candidate) {
|
|
40
|
+
for (let current = candidate;current; current = current.parentNode)
|
|
41
|
+
if (current === node)
|
|
42
|
+
return !0;
|
|
43
|
+
return !1;
|
|
44
|
+
},
|
|
45
|
+
querySelector(selector) {
|
|
46
|
+
return node.querySelectorAll(selector)[0] ?? null;
|
|
47
|
+
},
|
|
48
|
+
querySelectorAll(selector) {
|
|
49
|
+
const found = [], attribute = /^\[([^\]]+)\]$/.exec(selector)?.[1], visit = (candidate) => {
|
|
50
|
+
const element = candidate;
|
|
51
|
+
if (element.nodeType === 1) {
|
|
52
|
+
if (selector === "*" || attribute && element.hasAttribute(attribute))
|
|
53
|
+
found.push(element);
|
|
54
|
+
element.childNodes.forEach(visit);
|
|
55
|
+
}
|
|
56
|
+
};
|
|
57
|
+
node.childNodes.forEach(visit);
|
|
58
|
+
return found;
|
|
59
|
+
}
|
|
60
|
+
};
|
|
61
|
+
node.isConnected = connected;
|
|
62
|
+
return node;
|
|
63
|
+
}
|
|
64
|
+
export function cloneNativeBindingNode(source, id) {
|
|
65
|
+
const bindings = source.attributes.map((attribute) => ({
|
|
66
|
+
name: attribute.name,
|
|
67
|
+
value: attribute.value,
|
|
68
|
+
kind: "attr"
|
|
69
|
+
}));
|
|
70
|
+
return createBindingNode(id, source.tagName, bindings, !1);
|
|
71
|
+
}
|
|
72
|
+
export function materializeNativeBindingTree(document, manifest, host) {
|
|
73
|
+
const entries = new Map(manifest.entries.map((entry) => [entry.id, entry])), nodes = new Map;
|
|
74
|
+
let sequence = 0;
|
|
75
|
+
function visit(source, parent) {
|
|
76
|
+
const id = `n${sequence++}`, runtimeBindings = [...(source.bindingId === void 0 ? void 0 : entries.get(source.bindingId))?.bindings ?? []];
|
|
77
|
+
for (const [name, value] of Object.entries(source.bindings ?? {}))
|
|
78
|
+
if (!runtimeBindings.some((binding) => binding.name.replace(/^[:@]/, "") === name))
|
|
79
|
+
runtimeBindings.push({ name: `:${name}`, value, kind: "attr" });
|
|
80
|
+
const node = createBindingNode(id, source.type, runtimeBindings);
|
|
81
|
+
source.id = id;
|
|
82
|
+
source.props.__stxId = id;
|
|
83
|
+
node.parentNode = parent;
|
|
84
|
+
node.parentElement = parent;
|
|
85
|
+
host.adopt(node, source.type, parent, source);
|
|
86
|
+
if (source.bindingId !== void 0) {
|
|
87
|
+
node.setAttribute("data-stx-b", source.bindingId);
|
|
88
|
+
nodes.set(source.bindingId, node);
|
|
89
|
+
}
|
|
90
|
+
for (const child of source.children) {
|
|
91
|
+
if (typeof child === "string")
|
|
92
|
+
continue;
|
|
93
|
+
const childNode = visit(child, node);
|
|
94
|
+
node.childNodes.push(childNode);
|
|
95
|
+
node.children.push(childNode);
|
|
96
|
+
}
|
|
97
|
+
return node;
|
|
98
|
+
}
|
|
99
|
+
return { root: visit(document.root, null), nodes };
|
|
100
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { STXBridge } from '../bridge/protocol';
|
|
2
|
+
import type { NativeBridgeInterface } from '../bridge/protocol';
|
|
3
|
+
/** Install the Craft capability surface on top of the shared typed bridge. */
|
|
4
|
+
export declare function installCraftBridge(protocol: STXBridge, nativeBridge: NativeBridgeInterface, target?: AnyRecord, options?: CraftBridgeOptions): AnyRecord;
|
|
5
|
+
export declare interface CraftBridgeOptions {
|
|
6
|
+
routeName?: string
|
|
7
|
+
routeNames?: string[]
|
|
8
|
+
}
|
|
9
|
+
declare type AnyRecord = Record<string, any>;
|
|
@@ -0,0 +1,231 @@
|
|
|
1
|
+
import { STXBridge } from "../bridge/protocol.js";
|
|
2
|
+
function capabilityFlags(capabilities) {
|
|
3
|
+
return {
|
|
4
|
+
haptics: capabilities.has("haptics"),
|
|
5
|
+
speechRecognition: !1,
|
|
6
|
+
share: !1,
|
|
7
|
+
camera: !1,
|
|
8
|
+
biometric: capabilities.has("biometric"),
|
|
9
|
+
pushNotifications: !1,
|
|
10
|
+
secureStorage: capabilities.has("secureStorage"),
|
|
11
|
+
storage: capabilities.has("storage"),
|
|
12
|
+
localDatabase: capabilities.has("database"),
|
|
13
|
+
lifecycle: capabilities.has("lifecycle"),
|
|
14
|
+
geolocation: !1,
|
|
15
|
+
clipboard: capabilities.has("clipboard"),
|
|
16
|
+
contacts: !1,
|
|
17
|
+
calendar: !1,
|
|
18
|
+
localNotifications: capabilities.has("notifications"),
|
|
19
|
+
inAppPurchase: !1,
|
|
20
|
+
keepAwake: !1,
|
|
21
|
+
orientationLock: !1,
|
|
22
|
+
deepLinks: capabilities.has("deepLinks"),
|
|
23
|
+
flashlight: !1,
|
|
24
|
+
speech: !1,
|
|
25
|
+
network: !1,
|
|
26
|
+
deviceInfo: capabilities.has("device"),
|
|
27
|
+
fetch: capabilities.has("fetch"),
|
|
28
|
+
badge: !1,
|
|
29
|
+
appReview: !1
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
export function installCraftBridge(protocol, nativeBridge, target = globalThis, options = {}) {
|
|
33
|
+
const craft = target.craft = target.craft || {}, capabilities = new Set(nativeBridge.capabilities || []), request = (module, method, args) => protocol.callNativeAPI(module, method, ...args);
|
|
34
|
+
let appState = nativeBridge.initialAppState || "active", initialDeepLinkClaimed = !1;
|
|
35
|
+
const appStateHandlers = new Set, deepLinkHandlers = new Set, navButtonHandlers = new Set, navButtonPresses = new Map, routeName = options.routeName || "main", routeNames = options.routeNames || [routeName];
|
|
36
|
+
craft.platform = nativeBridge.platform || "unknown";
|
|
37
|
+
craft.capabilityProtocolVersion = Number(nativeBridge.capabilityProtocolVersion || 0);
|
|
38
|
+
craft.capabilities = capabilityFlags(capabilities);
|
|
39
|
+
craft.route = { name: routeName, params: target.__stxNativeParams || {} };
|
|
40
|
+
craft.appearance = { colorScheme: () => nativeBridge.colorScheme === "dark" ? "dark" : "light" };
|
|
41
|
+
craft.device = { getInfo: () => request("Device", "getInfo", []) };
|
|
42
|
+
craft.clipboard = {
|
|
43
|
+
write: (value) => request("Clipboard", "write", [value]),
|
|
44
|
+
read: () => request("Clipboard", "read", [])
|
|
45
|
+
};
|
|
46
|
+
craft.haptic = (style) => request("Haptics", "impact", [style || "medium"]);
|
|
47
|
+
const feedback = (answer) => answer.then(() => {}, (error) => {
|
|
48
|
+
if (error?.code === "CAPABILITY_DISABLED")
|
|
49
|
+
return;
|
|
50
|
+
throw error;
|
|
51
|
+
});
|
|
52
|
+
craft.haptics = {
|
|
53
|
+
impact: (style) => feedback(craft.haptic(style)),
|
|
54
|
+
notification: (type) => feedback(craft.haptic(type === "error" ? "heavy" : type === "warning" ? "medium" : "light")),
|
|
55
|
+
selection: () => feedback(craft.haptic("soft"))
|
|
56
|
+
};
|
|
57
|
+
craft.storage = Object.assign({ getSync: () => null, setSync: () => {
|
|
58
|
+
return;
|
|
59
|
+
} }, craft.storage || {}, {
|
|
60
|
+
get: (key) => request("Storage", "get", [key]),
|
|
61
|
+
set: (key, value) => request("Storage", "set", [key, value]),
|
|
62
|
+
remove: (key) => request("Storage", "remove", [key]),
|
|
63
|
+
clear: () => request("Storage", "clear", []),
|
|
64
|
+
keys: () => request("Storage", "keys", [])
|
|
65
|
+
});
|
|
66
|
+
craft.secureStorage = Object.assign({ getSync: () => null }, craft.secureStorage || {}, {
|
|
67
|
+
get: (key) => request("SecureStorage", "get", [key]),
|
|
68
|
+
set: (key, value) => request("SecureStorage", "set", [key, value]),
|
|
69
|
+
remove: (key) => request("SecureStorage", "remove", [key]),
|
|
70
|
+
delete: (key) => request("SecureStorage", "remove", [key]),
|
|
71
|
+
clear: () => request("SecureStorage", "clear", [])
|
|
72
|
+
});
|
|
73
|
+
craft.snapshots = Object.assign({ get: () => null, set: () => Promise.resolve(!1) }, craft.snapshots || {});
|
|
74
|
+
craft.biometrics = {
|
|
75
|
+
isAvailable: () => request("Biometrics", "isAvailable", []),
|
|
76
|
+
getBiometricType: () => request("Biometrics", "getBiometricType", []),
|
|
77
|
+
authenticate: (reason) => request("Biometrics", "authenticate", [reason || "Authenticate to continue"])
|
|
78
|
+
};
|
|
79
|
+
craft.db = {
|
|
80
|
+
execute: (sql, params = []) => request("Database", "execute", [sql, params]),
|
|
81
|
+
query: (sql, params = []) => request("Database", "query", [sql, params]),
|
|
82
|
+
beginTransaction: () => request("Database", "beginTransaction", []),
|
|
83
|
+
commit: () => request("Database", "commit", []),
|
|
84
|
+
rollback: () => request("Database", "rollback", [])
|
|
85
|
+
};
|
|
86
|
+
craft.notifications = {
|
|
87
|
+
show: (notification) => request("Notifications", "schedule", [notification]),
|
|
88
|
+
schedule: (notification) => request("Notifications", "schedule", [notification]),
|
|
89
|
+
cancel: (id) => request("Notifications", "cancel", [id]),
|
|
90
|
+
cancelAll: () => request("Notifications", "cancelAll", []),
|
|
91
|
+
pending: () => request("Notifications", "pending", [])
|
|
92
|
+
};
|
|
93
|
+
craft.scheduleNotification = craft.notifications.schedule;
|
|
94
|
+
craft.cancelNotification = craft.notifications.cancel;
|
|
95
|
+
craft.cancelAllNotifications = craft.notifications.cancelAll;
|
|
96
|
+
craft.getPendingNotifications = craft.notifications.pending;
|
|
97
|
+
const navigate = (type, screen, params) => {
|
|
98
|
+
if (!routeNames.includes(screen))
|
|
99
|
+
throw Error(`Unknown native screen: ${screen}`);
|
|
100
|
+
if (params !== void 0 && (params === null || typeof params !== "object" || Array.isArray(params)))
|
|
101
|
+
throw TypeError("Navigation params must be an object");
|
|
102
|
+
return protocol.send(type, { screen, params: params || {} });
|
|
103
|
+
}, hostSetOptions = craft.navigation && typeof craft.navigation.setOptions === "function" ? craft.navigation.setOptions.bind(craft.navigation) : null;
|
|
104
|
+
craft.navigation = Object.assign(craft.navigation || {}, {
|
|
105
|
+
push: (screen, params) => navigate("NAVIGATE", screen, params),
|
|
106
|
+
replace: (screen, params) => navigate("NAVIGATE_REPLACE", screen, params),
|
|
107
|
+
back: () => protocol.goBack(),
|
|
108
|
+
open: (path) => {
|
|
109
|
+
if (typeof path !== "string" || !path.trim())
|
|
110
|
+
throw TypeError("navigation.open needs a path, such as /m/workout/42");
|
|
111
|
+
return protocol.send("NAVIGATE_OPEN", { path });
|
|
112
|
+
},
|
|
113
|
+
setOptions: (navigationOptions) => {
|
|
114
|
+
if (!navigationOptions || typeof navigationOptions !== "object")
|
|
115
|
+
throw TypeError("navigation.setOptions needs an object");
|
|
116
|
+
const payload = {};
|
|
117
|
+
for (const key of Object.keys(navigationOptions))
|
|
118
|
+
if (key === "rightButtons" && Array.isArray(navigationOptions.rightButtons)) {
|
|
119
|
+
navButtonPresses.clear();
|
|
120
|
+
payload.rightButtons = navigationOptions.rightButtons.map((button) => {
|
|
121
|
+
const { onPress, ...rest } = button || {};
|
|
122
|
+
if (typeof onPress === "function" && rest.id != null)
|
|
123
|
+
navButtonPresses.set(String(rest.id), onPress);
|
|
124
|
+
return rest;
|
|
125
|
+
});
|
|
126
|
+
} else if (typeof navigationOptions[key] !== "function")
|
|
127
|
+
payload[key] = navigationOptions[key];
|
|
128
|
+
return hostSetOptions ? hostSetOptions(payload) : protocol.send("NAVIGATION_SET_OPTIONS", payload);
|
|
129
|
+
},
|
|
130
|
+
onButton: (callback) => {
|
|
131
|
+
if (typeof callback !== "function")
|
|
132
|
+
throw TypeError("navigation.onButton needs a function");
|
|
133
|
+
navButtonHandlers.add(callback);
|
|
134
|
+
return () => navButtonHandlers.delete(callback);
|
|
135
|
+
}
|
|
136
|
+
});
|
|
137
|
+
const onAppStateChange = (callback) => {
|
|
138
|
+
if (typeof callback !== "function")
|
|
139
|
+
throw TypeError("lifecycle.onStateChange needs a function");
|
|
140
|
+
appStateHandlers.add(callback);
|
|
141
|
+
return () => appStateHandlers.delete(callback);
|
|
142
|
+
};
|
|
143
|
+
craft.lifecycle = { getState: () => appState, onStateChange: onAppStateChange, onChange: onAppStateChange };
|
|
144
|
+
craft.getAppState = craft.lifecycle.getState;
|
|
145
|
+
craft.onAppStateChange = onAppStateChange;
|
|
146
|
+
craft.deepLinks = {
|
|
147
|
+
getInitialURL: () => {
|
|
148
|
+
initialDeepLinkClaimed = !0;
|
|
149
|
+
return request("DeepLinks", "getInitialURL", []);
|
|
150
|
+
},
|
|
151
|
+
onLink: (callback) => {
|
|
152
|
+
if (typeof callback !== "function")
|
|
153
|
+
throw TypeError("deepLinks.onLink needs a function");
|
|
154
|
+
deepLinkHandlers.add(callback);
|
|
155
|
+
return () => deepLinkHandlers.delete(callback);
|
|
156
|
+
}
|
|
157
|
+
};
|
|
158
|
+
protocol.on("APP_STATE", ({ payload }) => {
|
|
159
|
+
if (payload.state === appState)
|
|
160
|
+
return;
|
|
161
|
+
appState = payload.state;
|
|
162
|
+
appStateHandlers.forEach((handler) => handler(appState));
|
|
163
|
+
});
|
|
164
|
+
protocol.on("DEEP_LINK", ({ payload }) => {
|
|
165
|
+
if (initialDeepLinkClaimed && payload.initial)
|
|
166
|
+
return;
|
|
167
|
+
deepLinkHandlers.forEach((handler) => handler(payload));
|
|
168
|
+
});
|
|
169
|
+
const dispatchNavButton = (event) => {
|
|
170
|
+
const id = event?.id == null ? "" : String(event.id);
|
|
171
|
+
navButtonPresses.get(id)?.({ id });
|
|
172
|
+
navButtonHandlers.forEach((handler) => handler({ id }));
|
|
173
|
+
};
|
|
174
|
+
protocol.on("NAV_BUTTON", ({ payload }) => dispatchNavButton(payload));
|
|
175
|
+
protocol.on("EVENT", ({ payload }) => {
|
|
176
|
+
if (payload?.handlerId === "navButton" || payload?.handlerName === "navButton")
|
|
177
|
+
dispatchNavButton(payload.nativeEvent || {});
|
|
178
|
+
});
|
|
179
|
+
if (capabilities.has("fetch") && typeof target.fetch !== "function")
|
|
180
|
+
target.fetch = (input, init = {}) => {
|
|
181
|
+
const source = input && typeof input === "object" ? input : {}, url = typeof input === "string" ? input : String(source.url || input), method = String(init.method || source.method || "GET").toUpperCase(), headers = {}, inputHeaders = init.headers || source.headers, addHeader = (name, value) => {
|
|
182
|
+
headers[String(name).toLowerCase()] = String(value);
|
|
183
|
+
};
|
|
184
|
+
if (Array.isArray(inputHeaders))
|
|
185
|
+
inputHeaders.forEach((pair) => addHeader(pair[0], pair[1]));
|
|
186
|
+
else if (inputHeaders && typeof inputHeaders.forEach === "function")
|
|
187
|
+
inputHeaders.forEach(addHeader);
|
|
188
|
+
else if (inputHeaders && typeof inputHeaders === "object")
|
|
189
|
+
Object.keys(inputHeaders).forEach((name) => addHeader(name, inputHeaders[name]));
|
|
190
|
+
const body = init.body !== void 0 ? init.body : source.body;
|
|
191
|
+
if (body != null && typeof body !== "string")
|
|
192
|
+
return Promise.reject(TypeError("fetch in a native screen sends string bodies only"));
|
|
193
|
+
if (body != null && (method === "GET" || method === "HEAD"))
|
|
194
|
+
return Promise.reject(TypeError("A GET or HEAD request cannot have a body"));
|
|
195
|
+
return request("Network", "fetch", [{ url, method, headers, body: body == null ? null : body }]).then((data) => {
|
|
196
|
+
const responseHeaders = data?.headers && typeof data.headers === "object" ? data.headers : {}, responseBody = data?.body == null ? "" : String(data.body);
|
|
197
|
+
let bodyUsed = !1;
|
|
198
|
+
const consume = () => {
|
|
199
|
+
if (bodyUsed)
|
|
200
|
+
return Promise.reject(TypeError("Body has already been consumed"));
|
|
201
|
+
bodyUsed = !0;
|
|
202
|
+
return Promise.resolve(responseBody);
|
|
203
|
+
};
|
|
204
|
+
return {
|
|
205
|
+
type: "basic",
|
|
206
|
+
url: data?.url || "",
|
|
207
|
+
status: Number(data?.status) || 0,
|
|
208
|
+
statusText: data?.statusText || "",
|
|
209
|
+
ok: Number(data?.status) >= 200 && Number(data?.status) < 300,
|
|
210
|
+
redirected: Boolean(data?.redirected),
|
|
211
|
+
headers: {
|
|
212
|
+
get: (name) => responseHeaders[String(name).toLowerCase()] == null ? null : String(responseHeaders[String(name).toLowerCase()]),
|
|
213
|
+
has: (name) => responseHeaders[String(name).toLowerCase()] != null,
|
|
214
|
+
forEach: (callback) => Object.keys(responseHeaders).forEach((name) => callback(String(responseHeaders[name]), name))
|
|
215
|
+
},
|
|
216
|
+
get bodyUsed() {
|
|
217
|
+
return bodyUsed;
|
|
218
|
+
},
|
|
219
|
+
text: consume,
|
|
220
|
+
json: () => consume().then(JSON.parse)
|
|
221
|
+
};
|
|
222
|
+
}, (error) => {
|
|
223
|
+
if (error?.code === "INVALID_ARGUMENT")
|
|
224
|
+
throw error;
|
|
225
|
+
const failure = TypeError(error?.message || "Network request failed");
|
|
226
|
+
failure.code = error?.code || "NETWORK_ERROR";
|
|
227
|
+
throw failure;
|
|
228
|
+
});
|
|
229
|
+
};
|
|
230
|
+
return craft;
|
|
231
|
+
}
|