@tanqory/theme-kit 0.1.0 → 2.0.0-alpha.5
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/LICENSE +21 -0
- package/README.md +98 -10
- package/dist/abi/canvas-live.d.ts +49 -0
- package/dist/abi/canvas-live.js +88 -0
- package/dist/abi/cart.d.ts +48 -0
- package/dist/abi/cart.js +321 -0
- package/dist/abi/convert.d.ts +192 -0
- package/dist/abi/convert.js +670 -0
- package/dist/abi/data-api.d.ts +15 -0
- package/dist/abi/data-api.js +198 -0
- package/dist/abi/jcs.d.ts +6 -0
- package/dist/abi/jcs.js +28 -0
- package/dist/abi/page-data.d.ts +209 -0
- package/dist/abi/page-data.js +583 -0
- package/dist/abi/page.d.ts +23 -0
- package/dist/abi/page.js +46 -0
- package/dist/abi/referrals.d.ts +23 -0
- package/dist/abi/referrals.js +89 -0
- package/dist/abi/rewards.d.ts +27 -0
- package/dist/abi/rewards.js +82 -0
- package/dist/abi/seo.d.ts +47 -0
- package/dist/abi/seo.js +68 -0
- package/dist/abi/shell.d.ts +22 -0
- package/dist/abi/shell.js +10 -0
- package/dist/abi/wire.d.ts +38 -0
- package/dist/abi/wire.js +84 -0
- package/dist/build.d.ts +113 -0
- package/dist/build.js +294 -0
- package/dist/client.d.ts +19 -0
- package/dist/client.js +76 -0
- package/dist/contract.d.ts +6 -0
- package/dist/contract.js +6 -0
- package/dist/headless/ai.d.ts +132 -0
- package/dist/headless/ai.js +99 -0
- package/dist/headless/hooks.d.ts +273 -0
- package/dist/headless/hooks.js +533 -0
- package/dist/headless/i18n.d.ts +13 -0
- package/dist/headless/i18n.js +45 -0
- package/dist/headless/index.d.ts +36 -0
- package/dist/headless/index.js +38 -0
- package/dist/headless/money.d.ts +25 -0
- package/dist/headless/money.js +61 -0
- package/dist/headless/page.d.ts +43 -0
- package/dist/headless/page.js +53 -0
- package/dist/headless/platform.d.ts +55 -0
- package/dist/headless/platform.js +77 -0
- package/dist/headless/primitives/cart.d.ts +90 -0
- package/dist/headless/primitives/cart.js +153 -0
- package/dist/headless/primitives/collection.d.ts +68 -0
- package/dist/headless/primitives/collection.js +80 -0
- package/dist/headless/primitives/product.d.ts +101 -0
- package/dist/headless/primitives/product.js +117 -0
- package/dist/headless/primitives/storefront.d.ts +106 -0
- package/dist/headless/primitives/storefront.js +186 -0
- package/dist/headless/primitives/util.d.ts +19 -0
- package/dist/headless/primitives/util.js +42 -0
- package/dist/headless/strings.d.ts +9 -0
- package/dist/headless/strings.js +186 -0
- package/dist/headless/structured-data.d.ts +31 -0
- package/dist/headless/structured-data.js +57 -0
- package/dist/headless/theme.d.ts +99 -0
- package/dist/headless/theme.js +54 -0
- package/dist/index.d.ts +20 -0
- package/dist/index.js +18 -553
- package/dist/runtime/data/StoreProvider.d.ts +56 -0
- package/dist/runtime/data/StoreProvider.js +308 -0
- package/dist/runtime/data/handle.d.ts +14 -0
- package/dist/runtime/data/handle.js +16 -0
- package/dist/runtime/data/routes.d.ts +87 -0
- package/dist/runtime/data/routes.js +154 -0
- package/dist/runtime/data/to-ui.d.ts +258 -0
- package/dist/runtime/data/to-ui.js +820 -0
- package/dist/runtime/entries/register.d.ts +9 -0
- package/dist/runtime/entries/register.js +9 -0
- package/dist/runtime/entries/sections.d.ts +16 -0
- package/dist/runtime/entries/sections.js +19 -0
- package/dist/{types → runtime/kit}/SectionTree.d.ts +2 -1
- package/dist/runtime/kit/SectionTree.js +100 -0
- package/dist/runtime/kit/analytics.d.ts +63 -0
- package/dist/runtime/kit/analytics.js +233 -0
- package/dist/runtime/kit/cart.d.ts +186 -0
- package/dist/runtime/kit/cart.js +545 -0
- package/dist/{types → runtime/kit}/composition.d.ts +1 -1
- package/dist/runtime/kit/composition.js +3 -0
- package/dist/{types → runtime/kit}/config.d.ts +2 -2
- package/dist/runtime/kit/config.js +6 -0
- package/dist/runtime/kit/consent.d.ts +29 -0
- package/dist/runtime/kit/consent.js +159 -0
- package/dist/runtime/kit/contract/content.d.ts +164 -0
- package/dist/runtime/kit/contract/content.js +83 -0
- package/dist/runtime/kit/contract/field-types.d.ts +290 -0
- package/dist/runtime/kit/contract/field-types.js +129 -0
- package/dist/runtime/kit/contract/groups.d.ts +230 -0
- package/dist/runtime/kit/contract/groups.js +402 -0
- package/dist/runtime/kit/contract/index.d.ts +33 -0
- package/dist/runtime/kit/contract/index.js +33 -0
- package/dist/runtime/kit/contract/transform.d.ts +82 -0
- package/dist/runtime/kit/contract/transform.js +133 -0
- package/dist/runtime/kit/contract/validate.d.ts +67 -0
- package/dist/runtime/kit/contract/validate.js +388 -0
- package/dist/runtime/kit/data.d.ts +636 -0
- package/dist/runtime/kit/data.js +1117 -0
- package/dist/{types → runtime/kit}/defineSection.d.ts +1 -1
- package/dist/runtime/kit/defineSection.js +10 -0
- package/dist/{types → runtime/kit}/dynamic-source.d.ts +4 -4
- package/dist/runtime/kit/dynamic-source.js +143 -0
- package/dist/runtime/kit/index.d.ts +24 -0
- package/dist/runtime/kit/index.js +24 -0
- package/dist/{types → runtime/kit}/jsx-to-json.d.ts +1 -1
- package/dist/runtime/kit/jsx-to-json.js +28 -0
- package/dist/{types → runtime/kit}/mount.d.ts +25 -4
- package/dist/runtime/kit/mount.js +124 -0
- package/dist/{types → runtime/kit}/registry.d.ts +1 -1
- package/dist/runtime/kit/registry.js +12 -0
- package/dist/{types → runtime/kit}/ssg.d.ts +9 -3
- package/dist/runtime/kit/ssg.js +56 -0
- package/dist/runtime/kit/storefront.d.ts +566 -0
- package/dist/runtime/kit/storefront.js +723 -0
- package/dist/{types → runtime/kit}/theme-context.d.ts +8 -2
- package/dist/runtime/kit/theme-context.js +25 -0
- package/dist/runtime/kit/types.d.ts +142 -0
- package/dist/runtime/kit/types.js +1 -0
- package/dist/runtime/platform/TrackingPixels.d.ts +14 -0
- package/dist/runtime/platform/TrackingPixels.js +63 -0
- package/dist/runtime/platform/environment.d.ts +68 -0
- package/dist/runtime/platform/environment.js +85 -0
- package/dist/runtime/platform/locale.d.ts +27 -0
- package/dist/runtime/platform/locale.js +42 -0
- package/dist/runtime/platform/route-analytics.d.ts +15 -0
- package/dist/runtime/platform/route-analytics.js +72 -0
- package/dist/runtime/platform/safe-href.d.ts +25 -0
- package/dist/runtime/platform/safe-href.js +69 -0
- package/dist/runtime/platform/safe-values.d.ts +37 -0
- package/dist/runtime/platform/safe-values.js +140 -0
- package/dist/runtime/render/SectionRenderer.d.ts +4 -0
- package/dist/runtime/render/SectionRenderer.js +111 -0
- package/dist/runtime/render/listing-query.d.ts +47 -0
- package/dist/runtime/render/listing-query.js +114 -0
- package/dist/runtime/render/localized-copy.d.ts +86 -0
- package/dist/runtime/render/localized-copy.js +129 -0
- package/dist/runtime/render/product-listing.d.ts +11 -0
- package/dist/runtime/render/product-listing.js +240 -0
- package/dist/runtime/render/section-actions.d.ts +48 -0
- package/dist/runtime/render/section-actions.js +170 -0
- package/dist/runtime/render/starter.d.ts +11 -0
- package/dist/runtime/render/starter.js +81 -0
- package/dist/runtime/seo/head.d.ts +87 -0
- package/dist/runtime/seo/head.js +224 -0
- package/dist/runtime/seo/structured-data.d.ts +22 -0
- package/dist/runtime/seo/structured-data.js +115 -0
- package/dist/runtime/shell/PageShell.d.ts +18 -0
- package/dist/runtime/shell/PageShell.js +113 -0
- package/dist/runtime/shell/RuntimeBridge.d.ts +14 -0
- package/dist/runtime/shell/RuntimeBridge.js +85 -0
- package/dist/runtime/shell/overlay-state.d.ts +31 -0
- package/dist/runtime/shell/overlay-state.js +59 -0
- package/dist/runtime/shell/preview-mode.d.ts +2 -0
- package/dist/runtime/shell/preview-mode.js +11 -0
- package/dist/runtime/shell/spa-router.d.ts +14 -0
- package/dist/runtime/shell/spa-router.js +76 -0
- package/dist/runtime/shell/url-redirects.d.ts +6 -0
- package/dist/runtime/shell/url-redirects.js +37 -0
- package/dist/runtime/slots.d.ts +74 -0
- package/dist/runtime/slots.js +16 -0
- package/dist/runtime.d.ts +34 -0
- package/dist/runtime.js +40 -0
- package/dist/sdk/index.d.ts +24 -0
- package/dist/sdk/index.js +24 -0
- package/dist/sdk/referrals.d.ts +62 -0
- package/dist/sdk/referrals.js +20 -0
- package/dist/sdk/rewards.d.ts +85 -0
- package/dist/sdk/rewards.js +29 -0
- package/dist/sdk/runtime-context.d.ts +135 -0
- package/dist/sdk/runtime-context.js +73 -0
- package/dist/sdk/schema.d.ts +197 -0
- package/dist/sdk/schema.js +121 -0
- package/dist/sdk/server-render.d.ts +8 -0
- package/dist/sdk/server-render.js +12 -0
- package/dist/sdk/store-lookup.d.ts +27 -0
- package/dist/sdk/store-lookup.js +29 -0
- package/dist/sdk/store.d.ts +115 -0
- package/dist/sdk/store.js +1 -0
- package/dist/sdk/sx.d.ts +40 -0
- package/dist/sdk/sx.js +112 -0
- package/dist/sdk/theme.d.ts +152 -0
- package/dist/sdk/theme.js +10 -0
- package/dist/sdk/types.d.ts +470 -0
- package/dist/sdk/types.js +7 -0
- package/dist/server.d.ts +65 -0
- package/dist/server.js +370 -0
- package/docs/headless-api.md +220 -0
- package/package.json +77 -23
- package/dist/index.js.map +0 -1
- package/dist/ssg-BZ5FYTw7.js +0 -1802
- package/dist/ssg-BZ5FYTw7.js.map +0 -1
- package/dist/ssg.js +0 -8
- package/dist/ssg.js.map +0 -1
- package/dist/types/cart.d.ts +0 -86
- package/dist/types/data.d.ts +0 -357
- package/dist/types/editor.d.ts +0 -5
- package/dist/types/index.d.ts +0 -20
- package/dist/types/preview-bridge.d.ts +0 -9
- package/dist/types/storefront.d.ts +0 -333
- package/dist/types/types.d.ts +0 -44
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import { Fragment as _Fragment, jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { defineSchema, resolveSettings } from '../sdk/schema.js';
|
|
3
|
+
import { kitStrings } from './strings.js';
|
|
4
|
+
/** Declare a block: its persisted type, its settings, and the sections it may be placed in. */
|
|
5
|
+
export function defineBlock(def) {
|
|
6
|
+
return defineSchema({ kind: 'block', name: def.type, family: 'theme', title: def.title, ...(def.description ? { description: def.description } : {}), ...(def.parents ? { parents: def.parents } : {}), ...(def.requires ? { requiresContext: def.requires } : {}) }, def.settings);
|
|
7
|
+
}
|
|
8
|
+
const merged = (schema, raw) => {
|
|
9
|
+
const r = resolveSettings(schema, raw);
|
|
10
|
+
return { ...r.settings, ...r.handles };
|
|
11
|
+
};
|
|
12
|
+
/** Declare a section of a headless theme. */
|
|
13
|
+
export function defineSection(def) {
|
|
14
|
+
const blocks = def.blocks ?? [];
|
|
15
|
+
const schema = defineSchema({ kind: 'section', name: def.type, family: 'theme', ...(blocks.length ? { blocks: blocks.map((b) => b.name) } : {}), title: def.title, ...(def.description ? { description: def.description } : {}) }, def.settings);
|
|
16
|
+
return {
|
|
17
|
+
id: def.type,
|
|
18
|
+
schema,
|
|
19
|
+
blocks,
|
|
20
|
+
component: def.component,
|
|
21
|
+
category: def.category ?? 'content',
|
|
22
|
+
zone: def.zone ?? 'main',
|
|
23
|
+
title: def.title,
|
|
24
|
+
...(def.description ? { description: def.description } : {}),
|
|
25
|
+
...(def.requires ? { requiresContext: def.requires } : {}),
|
|
26
|
+
...(def.presets ? { presets: def.presets.map((p) => ({ name: p.name, settings: p.settings ?? {}, ...(p.blocks ? { blocks: p.blocks } : {}) })) } : {}),
|
|
27
|
+
...(def.ai ? { ai: def.ai } : {}),
|
|
28
|
+
headless: true,
|
|
29
|
+
data: (node) => ({
|
|
30
|
+
settings: merged(schema, node.settings),
|
|
31
|
+
blocks: (node.blocks ?? []).map((b) => {
|
|
32
|
+
const bs = blocks.find((x) => x.name === b.type || x.legacyNames?.includes(b.type));
|
|
33
|
+
return { type: bs?.name ?? b.type, settings: bs ? merged(bs, b.settings) : { ...(b.settings ?? {}) } };
|
|
34
|
+
}),
|
|
35
|
+
}),
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
const Pass = ({ children }) => _jsx(_Fragment, { children: children });
|
|
39
|
+
/** Declare a headless theme. */
|
|
40
|
+
export function defineTheme(def) {
|
|
41
|
+
return {
|
|
42
|
+
name: def.name,
|
|
43
|
+
sections: def.sections,
|
|
44
|
+
Provider: def.Provider ?? Pass,
|
|
45
|
+
Layout: def.Layout ?? Pass,
|
|
46
|
+
labels: def.labels ??
|
|
47
|
+
((locale) => {
|
|
48
|
+
const s = kitStrings(locale);
|
|
49
|
+
return { home: s['breadcrumbs.home'], search: s['search.search'], cart: s['cart.openCart'], account: s['account.title'] };
|
|
50
|
+
}),
|
|
51
|
+
...(def.stylesheets ? { stylesheets: def.stylesheets } : {}),
|
|
52
|
+
...(def.shippedCopy ? { shippedCopy: def.shippedCopy } : {}),
|
|
53
|
+
};
|
|
54
|
+
}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `@tanqory/theme-kit` — the API a Tanqory theme (Theme ABI v2) is written against.
|
|
3
|
+
*
|
|
4
|
+
* schema defineSchema(), field.*, resolveSettings() — a section's persisted settings
|
|
5
|
+
* theme defineTheme(), defineSection() — how a theme describes itself
|
|
6
|
+
* runtime useThemeContext(), useThemeActions(), useSearchSuggestions()
|
|
7
|
+
* types Product, Collection, Cart, Shop, Menu, Image, … — the data a theme renders
|
|
8
|
+
* (the earlier `Nova*` names stay as deprecated aliases)
|
|
9
|
+
* rewards useRewards(), earnPoints(): the store's loyalty program, browser-only
|
|
10
|
+
* referrals useReferrals(), shareTargets(): the shopper's referral link and the friend offer, browser-only
|
|
11
|
+
* store StoreContext + imageFor / menuFor / collectionFor / productFor … —
|
|
12
|
+
* read what the runtime put in the context
|
|
13
|
+
* styles sx(), sxJoin(): dynamic style values as class rules (no `style=""` under the platform CSP)
|
|
14
|
+
*
|
|
15
|
+
* The entries live beside it: `@tanqory/theme-kit/server` (`createRender`) and
|
|
16
|
+
* `@tanqory/theme-kit/client` (`hydrate`). Nothing here fetches or knows how the platform works.
|
|
17
|
+
*/
|
|
18
|
+
export * from './sdk/index.js';
|
|
19
|
+
export type { ThemeBundle } from './runtime/slots.js';
|
|
20
|
+
export type { ContentNode } from './runtime/kit/types.js';
|
package/dist/index.js
CHANGED
|
@@ -1,553 +1,18 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
let node;
|
|
20
|
-
for (const i2 of path) {
|
|
21
|
-
node = nodes[i2];
|
|
22
|
-
nodes = node?.blocks ?? [];
|
|
23
|
-
}
|
|
24
|
-
return node;
|
|
25
|
-
}
|
|
26
|
-
function updateAt(tree, path, fn) {
|
|
27
|
-
const [i2, ...rest] = path;
|
|
28
|
-
return tree.map(
|
|
29
|
-
(n, k2) => k2 !== i2 ? n : rest.length === 0 ? fn(n) : { ...n, blocks: updateAt(n.blocks ?? [], rest, fn) }
|
|
30
|
-
);
|
|
31
|
-
}
|
|
32
|
-
function removeAt(tree, path) {
|
|
33
|
-
const [i2, ...rest] = path;
|
|
34
|
-
if (rest.length === 0) return tree.filter((_, k2) => k2 !== i2);
|
|
35
|
-
return tree.map((n, k2) => k2 !== i2 ? n : { ...n, blocks: removeAt(n.blocks ?? [], rest) });
|
|
36
|
-
}
|
|
37
|
-
function insertChild(tree, parent, node) {
|
|
38
|
-
if (parent.length === 0) return [...tree, node];
|
|
39
|
-
const [i2, ...rest] = parent;
|
|
40
|
-
return tree.map((n, k2) => k2 !== i2 ? n : { ...n, blocks: insertChild(n.blocks ?? [], rest, node) });
|
|
41
|
-
}
|
|
42
|
-
function reorder(tree, parent, from, to) {
|
|
43
|
-
const moveArr = (arr) => {
|
|
44
|
-
const c2 = [...arr];
|
|
45
|
-
const [m] = c2.splice(from, 1);
|
|
46
|
-
c2.splice(to, 0, m);
|
|
47
|
-
return c2;
|
|
48
|
-
};
|
|
49
|
-
if (parent.length === 0) return moveArr(tree);
|
|
50
|
-
const [i2, ...rest] = parent;
|
|
51
|
-
return tree.map((n, k2) => k2 !== i2 ? n : { ...n, blocks: reorder(n.blocks ?? [], rest, from, to) });
|
|
52
|
-
}
|
|
53
|
-
function defaultsFor(type) {
|
|
54
|
-
const out = {};
|
|
55
|
-
for (const [k2, s] of Object.entries(getSection(type)?.attributes ?? {})) if (s.default !== void 0) out[k2] = s.default;
|
|
56
|
-
return out;
|
|
57
|
-
}
|
|
58
|
-
const newNode = (type) => ({ type, id: `${type}-${Date.now()}-${Math.random().toString(36).slice(2, 6)}`, settings: defaultsFor(type) });
|
|
59
|
-
function Field({ name, spec, value, onChange }) {
|
|
60
|
-
const label = spec.label ?? name;
|
|
61
|
-
const c2 = { style: { width: "100%", padding: "6px 8px", boxSizing: "border-box" } };
|
|
62
|
-
let input;
|
|
63
|
-
if (spec.type === "textarea") input = /* @__PURE__ */ jsx("textarea", { ...c2, rows: 3, value: String(value ?? ""), onChange: (e2) => onChange(e2.target.value) });
|
|
64
|
-
else if (spec.type === "color") input = /* @__PURE__ */ jsx("input", { type: "color", value: String(value ?? "#000000"), onChange: (e2) => onChange(e2.target.value) });
|
|
65
|
-
else if (spec.type === "number") input = /* @__PURE__ */ jsx("input", { ...c2, type: "number", value: Number(value ?? 0), onChange: (e2) => onChange(Number(e2.target.value)) });
|
|
66
|
-
else if (spec.type === "boolean") input = /* @__PURE__ */ jsx("input", { type: "checkbox", checked: Boolean(value), onChange: (e2) => onChange(e2.target.checked) });
|
|
67
|
-
else input = /* @__PURE__ */ jsx("input", { ...c2, type: "text", value: String(value ?? ""), onChange: (e2) => onChange(e2.target.value) });
|
|
68
|
-
return /* @__PURE__ */ jsxs("label", { style: { display: "block", margin: "0 0 12px" }, children: [
|
|
69
|
-
/* @__PURE__ */ jsx("span", { style: { display: "block", fontSize: 12, color: "#666", marginBottom: 4 }, children: label }),
|
|
70
|
-
input
|
|
71
|
-
] });
|
|
72
|
-
}
|
|
73
|
-
const btn = (active = false) => ({ border: "1px solid", borderColor: active ? "#111" : "#e5e5e5", borderRadius: 6, background: active ? "#111" : "#fff", color: active ? "#fff" : "#111", cursor: "pointer", font: "inherit" });
|
|
74
|
-
function Editor({ pages, initialPage = "index" }) {
|
|
75
|
-
const pageNames = Object.keys(pages);
|
|
76
|
-
const [trees, setTrees] = useState(pages);
|
|
77
|
-
const [page, setPage] = useState(pageNames.includes(initialPage) ? initialPage : pageNames[0] ?? "index");
|
|
78
|
-
const [sel, setSel] = useState([0]);
|
|
79
|
-
const [addParent, setAddParent] = useState(null);
|
|
80
|
-
const [status, setStatus] = useState("");
|
|
81
|
-
const [drag, setDrag] = useState(null);
|
|
82
|
-
const tree = trees[page] ?? [];
|
|
83
|
-
const setTree = (fn) => setTrees((all) => ({ ...all, [page]: fn(all[page] ?? []) }));
|
|
84
|
-
const node = nodeAt(tree, sel);
|
|
85
|
-
const def = node ? getSection(node.type) : void 0;
|
|
86
|
-
const save = async () => {
|
|
87
|
-
setStatus("saving…");
|
|
88
|
-
const res = await fetch("/__studio/save", {
|
|
89
|
-
method: "POST",
|
|
90
|
-
headers: { "content-type": "application/json" },
|
|
91
|
-
body: JSON.stringify({ page, doc: { sections: trees[page] ?? [] } })
|
|
92
|
-
});
|
|
93
|
-
setStatus(res.ok ? `saved ${page} ✓` : "save failed");
|
|
94
|
-
};
|
|
95
|
-
const onDrop = (parent, to) => {
|
|
96
|
-
if (drag && drag.parent === parent.join(".")) setTree((t) => reorder(t, parent, drag.index, to));
|
|
97
|
-
setDrag(null);
|
|
98
|
-
};
|
|
99
|
-
const inserter = (parent, allow) => {
|
|
100
|
-
const opts = allSections().filter((s) => !allow || allow.includes(s.name));
|
|
101
|
-
return /* @__PURE__ */ jsx("div", { style: { margin: "2px 0 8px", marginLeft: (parent.length + 1) * 14, border: "1px solid #eee", borderRadius: 6, padding: 6 }, children: opts.map((s) => /* @__PURE__ */ jsxs(
|
|
102
|
-
"button",
|
|
103
|
-
{
|
|
104
|
-
onClick: () => {
|
|
105
|
-
setTree((t) => insertChild(t, parent, newNode(s.name)));
|
|
106
|
-
setAddParent(null);
|
|
107
|
-
},
|
|
108
|
-
style: { ...btn(), display: "block", width: "100%", textAlign: "left", padding: "5px 8px", marginBottom: 2 },
|
|
109
|
-
children: [
|
|
110
|
-
s.icon ?? "▪",
|
|
111
|
-
" ",
|
|
112
|
-
s.title
|
|
113
|
-
]
|
|
114
|
-
},
|
|
115
|
-
s.name
|
|
116
|
-
)) });
|
|
117
|
-
};
|
|
118
|
-
const renderList = (nodes, parent) => nodes.map((n, i2) => {
|
|
119
|
-
const path = [...parent, i2];
|
|
120
|
-
const sec = getSection(n.type);
|
|
121
|
-
return /* @__PURE__ */ jsxs("div", { children: [
|
|
122
|
-
/* @__PURE__ */ jsxs(
|
|
123
|
-
"div",
|
|
124
|
-
{
|
|
125
|
-
draggable: true,
|
|
126
|
-
onDragStart: () => setDrag({ parent: parent.join("."), index: i2 }),
|
|
127
|
-
onDragOver: (e2) => e2.preventDefault(),
|
|
128
|
-
onDrop: () => onDrop(parent, i2),
|
|
129
|
-
style: { display: "flex", gap: 4, marginBottom: 4, marginLeft: parent.length * 14 },
|
|
130
|
-
children: [
|
|
131
|
-
/* @__PURE__ */ jsx("span", { style: { cursor: "grab", color: "#bbb", padding: "0 2px" }, children: "⠿" }),
|
|
132
|
-
/* @__PURE__ */ jsxs("button", { onClick: () => setSel(path), style: { ...btn(samePath(path, sel)), flex: 1, textAlign: "left", padding: "6px 8px" }, children: [
|
|
133
|
-
sec?.icon ?? "▪",
|
|
134
|
-
" ",
|
|
135
|
-
sec?.title ?? n.type
|
|
136
|
-
] }),
|
|
137
|
-
sec?.allowedBlocks?.length ? /* @__PURE__ */ jsx("button", { title: "add child", onClick: () => setAddParent(path), style: { ...btn(), width: 26 }, children: "+" }) : null,
|
|
138
|
-
/* @__PURE__ */ jsx("button", { title: "remove", onClick: () => {
|
|
139
|
-
setTree((t) => removeAt(t, path));
|
|
140
|
-
setSel([0]);
|
|
141
|
-
}, style: { ...btn(), width: 26, color: "#c0392b" }, children: "✕" })
|
|
142
|
-
]
|
|
143
|
-
}
|
|
144
|
-
),
|
|
145
|
-
n.blocks?.length ? renderList(n.blocks, path) : null,
|
|
146
|
-
addParent && samePath(addParent, path) ? inserter(path, sec?.allowedBlocks) : null
|
|
147
|
-
] }, n.id ?? i2);
|
|
148
|
-
});
|
|
149
|
-
return /* @__PURE__ */ jsxs("div", { style: { display: "grid", gridTemplateColumns: "300px 1fr 320px", height: "100vh", fontFamily: "system-ui" }, children: [
|
|
150
|
-
/* @__PURE__ */ jsxs("aside", { style: { borderRight: "1px solid #e5e5e5", overflow: "auto", padding: 16 }, children: [
|
|
151
|
-
/* @__PURE__ */ jsx("select", { value: page, onChange: (e2) => {
|
|
152
|
-
setPage(e2.target.value);
|
|
153
|
-
setSel([0]);
|
|
154
|
-
}, style: { width: "100%", padding: "6px 8px", marginBottom: 12 }, children: pageNames.map((p) => /* @__PURE__ */ jsx("option", { value: p, children: p }, p)) }),
|
|
155
|
-
/* @__PURE__ */ jsx("strong", { style: { fontSize: 13 }, children: "SECTIONS — drag ⠿ to reorder" }),
|
|
156
|
-
/* @__PURE__ */ jsx("div", { style: { margin: "8px 0" }, children: renderList(tree, []) }),
|
|
157
|
-
/* @__PURE__ */ jsx("button", { onClick: () => setAddParent([]), style: { ...btn(), padding: "8px 10px", width: "100%" }, children: "+ Add section" }),
|
|
158
|
-
addParent && addParent.length === 0 ? inserter([]) : null,
|
|
159
|
-
/* @__PURE__ */ jsx("button", { onClick: save, style: { marginTop: 16, padding: "10px 16px", border: "none", borderRadius: 6, background: "#111", color: "#fff", cursor: "pointer", width: "100%" }, children: "Save" }),
|
|
160
|
-
/* @__PURE__ */ jsx("div", { style: { fontSize: 12, color: "#666", marginTop: 8 }, children: status })
|
|
161
|
-
] }),
|
|
162
|
-
/* @__PURE__ */ jsx("main", { style: { overflow: "auto" }, children: /* @__PURE__ */ jsx(SectionTree, { tree }) }),
|
|
163
|
-
/* @__PURE__ */ jsx("aside", { style: { borderLeft: "1px solid #e5e5e5", overflow: "auto", padding: 16 }, children: def ? /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
164
|
-
/* @__PURE__ */ jsxs("strong", { style: { fontSize: 13 }, children: [
|
|
165
|
-
def.title.toUpperCase(),
|
|
166
|
-
" SETTINGS"
|
|
167
|
-
] }),
|
|
168
|
-
/* @__PURE__ */ jsx("div", { style: { marginTop: 8 }, children: Object.entries(def.attributes ?? {}).map(([k2, spec]) => /* @__PURE__ */ jsx(
|
|
169
|
-
Field,
|
|
170
|
-
{
|
|
171
|
-
name: k2,
|
|
172
|
-
spec,
|
|
173
|
-
value: node.settings?.[k2] ?? spec.default,
|
|
174
|
-
onChange: (v) => setTree((t) => updateAt(t, sel, (nn) => ({ ...nn, settings: { ...nn.settings, [k2]: v } })))
|
|
175
|
-
},
|
|
176
|
-
k2
|
|
177
|
-
)) })
|
|
178
|
-
] }) : /* @__PURE__ */ jsx("div", { style: { color: "#888", fontSize: 13 }, children: "Select a section in the tree to edit its settings." }) })
|
|
179
|
-
] });
|
|
180
|
-
}
|
|
181
|
-
const isMsg = (m) => !!m && typeof m === "object" && typeof m.type === "string";
|
|
182
|
-
function PreviewBridge({
|
|
183
|
-
pages,
|
|
184
|
-
initialPage,
|
|
185
|
-
Shell
|
|
186
|
-
}) {
|
|
187
|
-
const [tree, setTree] = useState(pages[initialPage] ?? []);
|
|
188
|
-
const [selected, setSelected] = useState(null);
|
|
189
|
-
const data = useData();
|
|
190
|
-
const send = (msg) => {
|
|
191
|
-
try {
|
|
192
|
-
window.parent?.postMessage(msg, "*");
|
|
193
|
-
if (window.top && window.top !== window.parent) window.top.postMessage(msg, "*");
|
|
194
|
-
} catch {
|
|
195
|
-
}
|
|
196
|
-
};
|
|
197
|
-
const treeRef = useRef(tree);
|
|
198
|
-
useEffect(() => {
|
|
199
|
-
treeRef.current = tree;
|
|
200
|
-
}, [tree]);
|
|
201
|
-
const firstRender = useRef(true);
|
|
202
|
-
useEffect(() => {
|
|
203
|
-
if (firstRender.current) {
|
|
204
|
-
firstRender.current = false;
|
|
205
|
-
return;
|
|
206
|
-
}
|
|
207
|
-
send({ type: "tanqory-content-changed", content: { sections: tree } });
|
|
208
|
-
}, [tree]);
|
|
209
|
-
useEffect(() => {
|
|
210
|
-
const onMsg = (e2) => {
|
|
211
|
-
if (!isMsg(e2.data)) return;
|
|
212
|
-
if (e2.data.type === "tanqory-get-content") {
|
|
213
|
-
send({ type: "tanqory-content", requestId: e2.data.requestId ?? null, content: { sections: treeRef.current } });
|
|
214
|
-
} else if (e2.data.type === "tq:set-content") {
|
|
215
|
-
if (Array.isArray(e2.data.doc)) setTree(e2.data.doc);
|
|
216
|
-
else if (typeof e2.data.page === "string" && pages[e2.data.page]) setTree(pages[e2.data.page]);
|
|
217
|
-
} else if (e2.data.type === "tq:select") {
|
|
218
|
-
setSelected(Array.isArray(e2.data.path) ? e2.data.path : null);
|
|
219
|
-
} else if (e2.data.type === "tanqory-preview-update-section") {
|
|
220
|
-
const id = e2.data.sectionId;
|
|
221
|
-
const s = e2.data.settings ?? {};
|
|
222
|
-
const rawBlocks = e2.data.blocks;
|
|
223
|
-
const order = e2.data.order;
|
|
224
|
-
let blocks;
|
|
225
|
-
if (Array.isArray(rawBlocks)) {
|
|
226
|
-
blocks = rawBlocks;
|
|
227
|
-
} else if (rawBlocks && typeof rawBlocks === "object") {
|
|
228
|
-
const ids = Array.isArray(order) && order.length ? order : Object.keys(rawBlocks);
|
|
229
|
-
blocks = ids.filter((bid) => rawBlocks[bid]).map((bid) => ({ ...rawBlocks[bid], id: rawBlocks[bid].id ?? bid }));
|
|
230
|
-
}
|
|
231
|
-
setTree(
|
|
232
|
-
(t) => t.map(
|
|
233
|
-
(n) => n.id === id ? { ...n, settings: { ...n.settings, ...s }, ...blocks ? { blocks } : {} } : n
|
|
234
|
-
)
|
|
235
|
-
);
|
|
236
|
-
} else if (e2.data.type === "tanqory-preview-select") {
|
|
237
|
-
const id = e2.data.sectionId;
|
|
238
|
-
setTree((t) => {
|
|
239
|
-
const i2 = t.findIndex((n) => n.id === id);
|
|
240
|
-
setSelected(i2 >= 0 ? [i2] : null);
|
|
241
|
-
return t;
|
|
242
|
-
});
|
|
243
|
-
if (typeof document !== "undefined" && id) {
|
|
244
|
-
const sel = typeof CSS !== "undefined" && CSS.escape ? CSS.escape(id) : id;
|
|
245
|
-
requestAnimationFrame(() => {
|
|
246
|
-
const wrap = document.querySelector(`[data-tq-section-id="${sel}"]`);
|
|
247
|
-
const target = wrap?.firstElementChild ?? wrap;
|
|
248
|
-
target?.scrollIntoView({ behavior: "smooth", block: "start" });
|
|
249
|
-
});
|
|
250
|
-
}
|
|
251
|
-
} else if (e2.data.type === "tanqory-preview-reorder-sections") {
|
|
252
|
-
const order = e2.data.order;
|
|
253
|
-
if (Array.isArray(order)) {
|
|
254
|
-
setTree((t) => {
|
|
255
|
-
const byId = new Map(t.map((n) => [n.id, n]));
|
|
256
|
-
const next = order.map((id) => byId.get(id)).filter(Boolean);
|
|
257
|
-
for (const n of t) if (!order.includes(n.id)) next.push(n);
|
|
258
|
-
return next.length ? next : t;
|
|
259
|
-
});
|
|
260
|
-
}
|
|
261
|
-
} else if (e2.data.type === "tanqory-preview-remove-section") {
|
|
262
|
-
const id = e2.data.sectionId;
|
|
263
|
-
setTree((t) => t.filter((n) => n.id !== id));
|
|
264
|
-
} else if (e2.data.type === "tanqory-preview-insert-section") {
|
|
265
|
-
const id = e2.data.sectionId;
|
|
266
|
-
const rawBlocks = e2.data.blocks;
|
|
267
|
-
const order = e2.data.order;
|
|
268
|
-
let blocks;
|
|
269
|
-
if (Array.isArray(rawBlocks)) {
|
|
270
|
-
blocks = rawBlocks;
|
|
271
|
-
} else if (rawBlocks && typeof rawBlocks === "object") {
|
|
272
|
-
const ids = Array.isArray(order) && order.length ? order : Object.keys(rawBlocks);
|
|
273
|
-
blocks = ids.filter((bid) => rawBlocks[bid]).map((bid) => ({ ...rawBlocks[bid], id: rawBlocks[bid].id ?? bid }));
|
|
274
|
-
}
|
|
275
|
-
const node = {
|
|
276
|
-
id,
|
|
277
|
-
type: e2.data.sectionType,
|
|
278
|
-
settings: e2.data.settings ?? {},
|
|
279
|
-
...blocks ? { blocks } : {}
|
|
280
|
-
};
|
|
281
|
-
const after = e2.data.afterSectionId;
|
|
282
|
-
setTree((t) => {
|
|
283
|
-
if (t.some((n) => n.id === id)) return t;
|
|
284
|
-
const idx = after ? t.findIndex((n) => n.id === after) : -1;
|
|
285
|
-
const next = [...t];
|
|
286
|
-
next.splice(idx + 1, 0, node);
|
|
287
|
-
return next;
|
|
288
|
-
});
|
|
289
|
-
} else if (e2.data.type === "tanqory-request-collections") {
|
|
290
|
-
const collections = data.allCollections().map((c2) => ({
|
|
291
|
-
handle: c2.handle,
|
|
292
|
-
title: c2.title,
|
|
293
|
-
productCount: c2.products.length
|
|
294
|
-
}));
|
|
295
|
-
send({ type: "tanqory-collections", requestId: e2.data.requestId ?? null, collections });
|
|
296
|
-
} else if (e2.data.type === "tanqory-request-menus") {
|
|
297
|
-
const requestId = e2.data.requestId ?? null;
|
|
298
|
-
void Promise.resolve(data.listMenus?.() ?? []).then((menus) => send({ type: "tanqory-menus", requestId, menus })).catch(() => send({ type: "tanqory-menus", requestId, menus: [] }));
|
|
299
|
-
} else if (e2.data.type === "tanqory-request-products") {
|
|
300
|
-
const seen = /* @__PURE__ */ new Set();
|
|
301
|
-
const products = [];
|
|
302
|
-
for (const c2 of data.allCollections()) {
|
|
303
|
-
for (const p of c2.products) {
|
|
304
|
-
if (seen.has(p.handle)) continue;
|
|
305
|
-
seen.add(p.handle);
|
|
306
|
-
products.push({
|
|
307
|
-
handle: p.handle,
|
|
308
|
-
title: p.title,
|
|
309
|
-
price: p.price?.amount ?? "",
|
|
310
|
-
image: p.featuredImage?.url ?? null
|
|
311
|
-
});
|
|
312
|
-
}
|
|
313
|
-
}
|
|
314
|
-
send({ type: "tanqory-products", requestId: e2.data.requestId ?? null, products });
|
|
315
|
-
}
|
|
316
|
-
};
|
|
317
|
-
window.addEventListener("message", onMsg);
|
|
318
|
-
send({ type: "tq:ready", pages: Object.keys(pages) });
|
|
319
|
-
return () => window.removeEventListener("message", onMsg);
|
|
320
|
-
}, []);
|
|
321
|
-
const onClickCapture = (e2) => {
|
|
322
|
-
const target = e2.target;
|
|
323
|
-
const nodeEl = target.closest("[data-tq-section-id]");
|
|
324
|
-
if (!nodeEl) return;
|
|
325
|
-
const nodeId = nodeEl.dataset.tqSectionId;
|
|
326
|
-
const pathAttr = nodeEl.dataset.tqPath;
|
|
327
|
-
if (target.closest('a, button[type="submit"]')) {
|
|
328
|
-
e2.preventDefault();
|
|
329
|
-
}
|
|
330
|
-
const root = e2.currentTarget;
|
|
331
|
-
const prevBox = root.querySelector("[data-tq-outlined]");
|
|
332
|
-
if (prevBox) {
|
|
333
|
-
prevBox.style.outline = "";
|
|
334
|
-
prevBox.style.outlineOffset = "";
|
|
335
|
-
prevBox.removeAttribute("data-tq-outlined");
|
|
336
|
-
}
|
|
337
|
-
const box = nodeEl.firstElementChild;
|
|
338
|
-
if (box) {
|
|
339
|
-
box.style.outline = "2px solid #2563eb";
|
|
340
|
-
box.style.outlineOffset = "-2px";
|
|
341
|
-
box.setAttribute("data-tq-outlined", "1");
|
|
342
|
-
}
|
|
343
|
-
if (pathAttr) {
|
|
344
|
-
const path = pathAttr.split(".").map(Number);
|
|
345
|
-
setSelected(path);
|
|
346
|
-
send({ type: "tq:select", path });
|
|
347
|
-
}
|
|
348
|
-
const container = e2.currentTarget;
|
|
349
|
-
const isBlock = !!pathAttr && pathAttr.includes(".");
|
|
350
|
-
if (isBlock && nodeId) {
|
|
351
|
-
const sectionPath = pathAttr.split(".")[0];
|
|
352
|
-
const sectionEl = container.querySelector(`[data-tq-path="${sectionPath}"]`) ?? nodeEl.parentElement?.closest("[data-tq-section-id]");
|
|
353
|
-
const sectionId = sectionEl?.dataset.tqSectionId;
|
|
354
|
-
if (sectionId) {
|
|
355
|
-
send({ type: "tanqory-block-selected", sectionId, blockId: nodeId });
|
|
356
|
-
return;
|
|
357
|
-
}
|
|
358
|
-
}
|
|
359
|
-
if (nodeId) {
|
|
360
|
-
send({ type: "tanqory-section-selected", sectionId: nodeId });
|
|
361
|
-
}
|
|
362
|
-
};
|
|
363
|
-
return /* @__PURE__ */ jsx("div", { onClickCapture, "data-tq-selected": selected?.join(".") ?? "", children: /* @__PURE__ */ jsx(Shell, { children: /* @__PURE__ */ jsx(SectionTree, { tree }) }) });
|
|
364
|
-
}
|
|
365
|
-
function defaultsOf(map) {
|
|
366
|
-
return Object.values(map).map((m) => m.default);
|
|
367
|
-
}
|
|
368
|
-
function pickByName(map, name) {
|
|
369
|
-
const hit = Object.entries(map).find(
|
|
370
|
-
([key]) => key.endsWith(`/${name}.json`) || key.endsWith(`/${name}.tsx`)
|
|
371
|
-
);
|
|
372
|
-
return hit ? hit[1].default : void 0;
|
|
373
|
-
}
|
|
374
|
-
function mount(opts) {
|
|
375
|
-
registerSections(defaultsOf(opts.sections));
|
|
376
|
-
const shells = opts.shell ? defaultsOf(opts.shell) : [];
|
|
377
|
-
const Shell = shells[0] ?? (({ children }) => /* @__PURE__ */ jsx(Fragment, { children }));
|
|
378
|
-
const pageDoc = pickByName(opts.pages, opts.page ?? "index") ?? { sections: [] };
|
|
379
|
-
const rootEl = document.getElementById(opts.rootId ?? "root");
|
|
380
|
-
if (!rootEl) throw new Error("[tanqory] mount target not found");
|
|
381
|
-
const params = typeof location !== "undefined" ? new URLSearchParams(location.search) : new URLSearchParams();
|
|
382
|
-
const on = (k2) => {
|
|
383
|
-
const v = params.get(k2);
|
|
384
|
-
return v !== null && v !== "false" && v !== "0";
|
|
385
|
-
};
|
|
386
|
-
const previewHost = typeof location !== "undefined" && /^preview-/.test(location.hostname);
|
|
387
|
-
const previewMode = previewHost || on("preview");
|
|
388
|
-
const editMode = on("edit");
|
|
389
|
-
const pagesByName = {};
|
|
390
|
-
for (const [key, mod] of Object.entries(opts.pages)) {
|
|
391
|
-
const name = key.replace(/^.*\//, "").replace(/\.json$/, "");
|
|
392
|
-
pagesByName[name] = mod.default?.sections ?? [];
|
|
393
|
-
}
|
|
394
|
-
const content = previewMode ? /* @__PURE__ */ jsx(PreviewBridge, { pages: pagesByName, initialPage: opts.page ?? "index", Shell }) : editMode ? /* @__PURE__ */ jsx(Editor, { pages: pagesByName, initialPage: opts.page ?? "index" }) : /* @__PURE__ */ jsx(Shell, { children: /* @__PURE__ */ jsx(SectionTree, { tree: pageDoc.sections }) });
|
|
395
|
-
const Root = () => {
|
|
396
|
-
const [data, setData] = React.useState(opts.data);
|
|
397
|
-
React.useEffect(() => {
|
|
398
|
-
if (!opts.revalidate) return;
|
|
399
|
-
let live = true;
|
|
400
|
-
opts.revalidate().then((fresh) => {
|
|
401
|
-
if (live && fresh) setData(fresh);
|
|
402
|
-
}).catch(() => {
|
|
403
|
-
});
|
|
404
|
-
return () => {
|
|
405
|
-
live = false;
|
|
406
|
-
};
|
|
407
|
-
}, []);
|
|
408
|
-
return /* @__PURE__ */ jsx(DataProvider, { value: data, children: /* @__PURE__ */ jsx(ThemeProvider, { settings: opts.settings, locale: opts.locale, children: /* @__PURE__ */ jsx(CartProvider, { children: content }) }) });
|
|
409
|
-
};
|
|
410
|
-
const app = /* @__PURE__ */ jsx(React.StrictMode, { children: /* @__PURE__ */ jsx(Root, {}) });
|
|
411
|
-
const isStorefront = !previewMode && !editMode;
|
|
412
|
-
const hasSSG = rootEl.firstChild != null;
|
|
413
|
-
if (isStorefront && hasSSG && !opts.forceClientRender) {
|
|
414
|
-
hydrateRoot(rootEl, app);
|
|
415
|
-
} else {
|
|
416
|
-
if (hasSSG) rootEl.replaceChildren();
|
|
417
|
-
createRoot(rootEl).render(app);
|
|
418
|
-
}
|
|
419
|
-
}
|
|
420
|
-
function isBoundSource(v) {
|
|
421
|
-
return typeof v === "object" && v !== null && typeof v["@source"] === "string";
|
|
422
|
-
}
|
|
423
|
-
const ResourceContext = createContext({});
|
|
424
|
-
function DynamicSourceProvider({
|
|
425
|
-
value,
|
|
426
|
-
children
|
|
427
|
-
}) {
|
|
428
|
-
return /* @__PURE__ */ jsx(ResourceContext.Provider, { value, children });
|
|
429
|
-
}
|
|
430
|
-
function useResourceContext() {
|
|
431
|
-
const data = useData();
|
|
432
|
-
const ctx = useContext(ResourceContext);
|
|
433
|
-
return { shop: data.shop, ...ctx };
|
|
434
|
-
}
|
|
435
|
-
const METAOBJECT_RE = /^metaobject:([^:]+):([^.]+)\.(.+)$/;
|
|
436
|
-
function resolveBoundSource(source, ctx) {
|
|
437
|
-
const mo = source.match(METAOBJECT_RE);
|
|
438
|
-
if (mo) {
|
|
439
|
-
const [, type, handle, field] = mo;
|
|
440
|
-
const obj = ctx.metaobject?.(type, handle);
|
|
441
|
-
return obj?.values?.[field] ?? null;
|
|
442
|
-
}
|
|
443
|
-
const parts = source.split(".");
|
|
444
|
-
const root = parts[0];
|
|
445
|
-
const resource = root === "product" ? ctx.product : root === "collection" ? ctx.collection : root === "shop" ? ctx.shop : null;
|
|
446
|
-
if (!resource) return null;
|
|
447
|
-
if (parts[1] === "metafields") {
|
|
448
|
-
const ns = parts[2];
|
|
449
|
-
const key = parts.slice(3).join(".");
|
|
450
|
-
if (!ns || !key) return null;
|
|
451
|
-
return resource.metafields?.[`${ns}.${key}`] ?? null;
|
|
452
|
-
}
|
|
453
|
-
const direct = resource[parts[1]];
|
|
454
|
-
return direct == null ? null : String(direct);
|
|
455
|
-
}
|
|
456
|
-
function useBound(value) {
|
|
457
|
-
const ctx = useResourceContext();
|
|
458
|
-
if (!isBoundSource(value)) return value;
|
|
459
|
-
return resolveBoundSource(value["@source"], ctx);
|
|
460
|
-
}
|
|
461
|
-
function useBoundText(value, fallback = "") {
|
|
462
|
-
const resolved = useBound(value);
|
|
463
|
-
if (resolved == null) return fallback;
|
|
464
|
-
return typeof resolved === "string" ? resolved : String(resolved);
|
|
465
|
-
}
|
|
466
|
-
function collectBoundIdentifiers(nodes) {
|
|
467
|
-
const out = {
|
|
468
|
-
product: [],
|
|
469
|
-
collection: [],
|
|
470
|
-
shop: []
|
|
471
|
-
};
|
|
472
|
-
const seen = /* @__PURE__ */ new Set();
|
|
473
|
-
const visitSettings = (settings) => {
|
|
474
|
-
if (!settings) return;
|
|
475
|
-
for (const v of Object.values(settings)) {
|
|
476
|
-
if (!isBoundSource(v)) continue;
|
|
477
|
-
const parts = v["@source"].split(".");
|
|
478
|
-
const root = parts[0];
|
|
479
|
-
if (parts[1] !== "metafields") continue;
|
|
480
|
-
const namespace = parts[2];
|
|
481
|
-
const key = parts.slice(3).join(".");
|
|
482
|
-
if (!namespace || !key || !(root in out)) continue;
|
|
483
|
-
const dedupe = `${root}:${namespace}.${key}`;
|
|
484
|
-
if (seen.has(dedupe)) continue;
|
|
485
|
-
seen.add(dedupe);
|
|
486
|
-
out[root].push({ namespace, key });
|
|
487
|
-
}
|
|
488
|
-
};
|
|
489
|
-
const toNodes = (v) => {
|
|
490
|
-
if (Array.isArray(v)) return v;
|
|
491
|
-
if (v && typeof v === "object") return Object.values(v);
|
|
492
|
-
return [];
|
|
493
|
-
};
|
|
494
|
-
const walk = (list) => {
|
|
495
|
-
for (const node of toNodes(list)) {
|
|
496
|
-
visitSettings(node.settings);
|
|
497
|
-
walk(node.blocks);
|
|
498
|
-
}
|
|
499
|
-
};
|
|
500
|
-
walk(nodes);
|
|
501
|
-
return out;
|
|
502
|
-
}
|
|
503
|
-
function jsxToJSON(node) {
|
|
504
|
-
return Children.toArray(node).flatMap((el) => {
|
|
505
|
-
if (!isValidElement(el)) return [];
|
|
506
|
-
const name = el.type?.blockName;
|
|
507
|
-
if (!name) return [];
|
|
508
|
-
const props = el.props;
|
|
509
|
-
const out = { type: name };
|
|
510
|
-
if (props.settings) out.settings = props.settings;
|
|
511
|
-
const blocks = jsxToJSON(props.children);
|
|
512
|
-
if (blocks.length) out.blocks = blocks;
|
|
513
|
-
return [out];
|
|
514
|
-
});
|
|
515
|
-
}
|
|
516
|
-
function tag(def) {
|
|
517
|
-
return def.component;
|
|
518
|
-
}
|
|
519
|
-
export {
|
|
520
|
-
CartProvider,
|
|
521
|
-
DataProvider,
|
|
522
|
-
DynamicSourceProvider,
|
|
523
|
-
Editor,
|
|
524
|
-
SectionTree,
|
|
525
|
-
ThemeProvider,
|
|
526
|
-
allSections,
|
|
527
|
-
collectBoundIdentifiers,
|
|
528
|
-
c as createLiveData,
|
|
529
|
-
b as createLiveDataFromSnapshot,
|
|
530
|
-
d as createMockData,
|
|
531
|
-
e as customerTokenStore,
|
|
532
|
-
defineSection,
|
|
533
|
-
defineSettings,
|
|
534
|
-
defineTheme,
|
|
535
|
-
f as formatMoney,
|
|
536
|
-
getSection,
|
|
537
|
-
isBoundSource,
|
|
538
|
-
jsxToJSON,
|
|
539
|
-
mount,
|
|
540
|
-
registerSections,
|
|
541
|
-
h as renderSectionPreviewHTML,
|
|
542
|
-
i as renderStorefrontHTML,
|
|
543
|
-
resolveBoundSource,
|
|
544
|
-
tag,
|
|
545
|
-
useBound,
|
|
546
|
-
useBoundText,
|
|
547
|
-
u as useCart,
|
|
548
|
-
useData,
|
|
549
|
-
useResourceContext,
|
|
550
|
-
k as useSettings,
|
|
551
|
-
l as useT
|
|
552
|
-
};
|
|
553
|
-
//# sourceMappingURL=index.js.map
|
|
1
|
+
/**
|
|
2
|
+
* `@tanqory/theme-kit` — the API a Tanqory theme (Theme ABI v2) is written against.
|
|
3
|
+
*
|
|
4
|
+
* schema defineSchema(), field.*, resolveSettings() — a section's persisted settings
|
|
5
|
+
* theme defineTheme(), defineSection() — how a theme describes itself
|
|
6
|
+
* runtime useThemeContext(), useThemeActions(), useSearchSuggestions()
|
|
7
|
+
* types Product, Collection, Cart, Shop, Menu, Image, … — the data a theme renders
|
|
8
|
+
* (the earlier `Nova*` names stay as deprecated aliases)
|
|
9
|
+
* rewards useRewards(), earnPoints(): the store's loyalty program, browser-only
|
|
10
|
+
* referrals useReferrals(), shareTargets(): the shopper's referral link and the friend offer, browser-only
|
|
11
|
+
* store StoreContext + imageFor / menuFor / collectionFor / productFor … —
|
|
12
|
+
* read what the runtime put in the context
|
|
13
|
+
* styles sx(), sxJoin(): dynamic style values as class rules (no `style=""` under the platform CSP)
|
|
14
|
+
*
|
|
15
|
+
* The entries live beside it: `@tanqory/theme-kit/server` (`createRender`) and
|
|
16
|
+
* `@tanqory/theme-kit/client` (`hydrate`). Nothing here fetches or knows how the platform works.
|
|
17
|
+
*/
|
|
18
|
+
export * from './sdk/index.js';
|