@juo/blocks 1.13.0-alpha.2 → 1.14.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (246) hide show
  1. package/dist/ExtensionRoot-CRJx0Dtr.js +378 -0
  2. package/dist/block.d.ts +0 -50
  3. package/dist/block.d.ts.map +1 -1
  4. package/dist/{bridge-r7Yk8fjY.js → bridge-D838SWmN.js} +147 -42
  5. package/dist/context.d.ts.map +1 -1
  6. package/dist/core.js +1120 -2157
  7. package/dist/css-runtime-DWytAzZ5.js +1532 -0
  8. package/dist/editor/bridge.d.ts +8 -7
  9. package/dist/editor/bridge.d.ts.map +1 -1
  10. package/dist/editor/canvas-mode-signal.d.ts +22 -0
  11. package/dist/editor/canvas-mode-signal.d.ts.map +1 -0
  12. package/dist/editor/canvas-mode.d.ts +15 -0
  13. package/dist/editor/canvas-mode.d.ts.map +1 -0
  14. package/dist/editor/canvas-mode.test.d.ts +2 -0
  15. package/dist/editor/canvas-mode.test.d.ts.map +1 -0
  16. package/dist/editor/components.d.ts +113 -0
  17. package/dist/editor/components.d.ts.map +1 -1
  18. package/dist/editor/components.test.d.ts.map +1 -1
  19. package/dist/editor/handler.d.ts.map +1 -1
  20. package/dist/editor/handler.test.d.ts +2 -0
  21. package/dist/editor/handler.test.d.ts.map +1 -0
  22. package/dist/editor/layout-command-emitter.d.ts +31 -0
  23. package/dist/editor/layout-command-emitter.d.ts.map +1 -0
  24. package/dist/editor/layout-command-emitter.test.d.ts +2 -0
  25. package/dist/editor/layout-command-emitter.test.d.ts.map +1 -0
  26. package/dist/editor/layout-system-signal.d.ts +21 -0
  27. package/dist/editor/layout-system-signal.d.ts.map +1 -0
  28. package/dist/editor/main.d.ts +2 -2
  29. package/dist/editor/main.d.ts.map +1 -1
  30. package/dist/editor/messages.d.ts +90 -14
  31. package/dist/editor/messages.d.ts.map +1 -1
  32. package/dist/editor/surface-context.d.ts +7 -0
  33. package/dist/editor/surface-context.d.ts.map +1 -0
  34. package/dist/editor/surface-context.test.d.ts +2 -0
  35. package/dist/editor/surface-context.test.d.ts.map +1 -0
  36. package/dist/editor/wrapper-shared.d.ts +31 -0
  37. package/dist/editor/wrapper-shared.d.ts.map +1 -0
  38. package/dist/editor.js +887 -88
  39. package/dist/flows/WorkflowService.d.ts +2 -0
  40. package/dist/flows/WorkflowService.d.ts.map +1 -1
  41. package/dist/gridstack-adapter-DreG3XnB.js +5490 -0
  42. package/dist/layout/css-runtime.d.ts +41 -0
  43. package/dist/layout/css-runtime.d.ts.map +1 -0
  44. package/dist/layout/css-runtime.test.d.ts +2 -0
  45. package/dist/layout/css-runtime.test.d.ts.map +1 -0
  46. package/dist/layout/derive.d.ts +4 -0
  47. package/dist/layout/derive.d.ts.map +1 -0
  48. package/dist/layout/derive.test.d.ts +2 -0
  49. package/dist/layout/derive.test.d.ts.map +1 -0
  50. package/dist/layout/dividers.d.ts +34 -0
  51. package/dist/layout/dividers.d.ts.map +1 -0
  52. package/dist/layout/dividers.test.d.ts +2 -0
  53. package/dist/layout/dividers.test.d.ts.map +1 -0
  54. package/dist/layout/engine.d.ts +3 -0
  55. package/dist/layout/engine.d.ts.map +1 -0
  56. package/dist/layout/engine.test.d.ts +2 -0
  57. package/dist/layout/engine.test.d.ts.map +1 -0
  58. package/dist/layout/grid-utils.d.ts +57 -0
  59. package/dist/layout/grid-utils.d.ts.map +1 -0
  60. package/dist/layout/grid-utils.test.d.ts +2 -0
  61. package/dist/layout/grid-utils.test.d.ts.map +1 -0
  62. package/dist/layout/index.d.ts +12 -0
  63. package/dist/layout/index.d.ts.map +1 -0
  64. package/dist/layout/index.test.d.ts +2 -0
  65. package/dist/layout/index.test.d.ts.map +1 -0
  66. package/dist/layout/insert.d.ts +31 -0
  67. package/dist/layout/insert.d.ts.map +1 -0
  68. package/dist/layout/insert.test.d.ts +2 -0
  69. package/dist/layout/insert.test.d.ts.map +1 -0
  70. package/dist/layout/project-css.d.ts +6 -0
  71. package/dist/layout/project-css.d.ts.map +1 -0
  72. package/dist/layout/project-css.test.d.ts +2 -0
  73. package/dist/layout/project-css.test.d.ts.map +1 -0
  74. package/dist/layout/project-gridstack.d.ts +50 -0
  75. package/dist/layout/project-gridstack.d.ts.map +1 -0
  76. package/dist/layout/project-gridstack.test.d.ts +2 -0
  77. package/dist/layout/project-gridstack.test.d.ts.map +1 -0
  78. package/dist/layout/reconcile.d.ts +22 -0
  79. package/dist/layout/reconcile.d.ts.map +1 -0
  80. package/dist/layout/reconcile.test.d.ts +2 -0
  81. package/dist/layout/reconcile.test.d.ts.map +1 -0
  82. package/dist/layout/types.d.ts +118 -0
  83. package/dist/layout/types.d.ts.map +1 -0
  84. package/dist/layout-mode-adapter-BBd4JRQd.js +21 -0
  85. package/dist/main.d.ts +8 -4
  86. package/dist/main.d.ts.map +1 -1
  87. package/dist/morph-Dj-xvrwt.js +182 -0
  88. package/dist/preact.js +1 -1
  89. package/dist/project-gridstack-DYLMKSH1.js +52 -0
  90. package/dist/react.js +1 -1
  91. package/dist/services/customer/customerService.d.ts +2 -3
  92. package/dist/services/customer/customerService.d.ts.map +1 -1
  93. package/dist/services/customer/index.d.ts +0 -1
  94. package/dist/services/customer/index.d.ts.map +1 -1
  95. package/dist/services/customer/types.d.ts +1 -4
  96. package/dist/services/customer/types.d.ts.map +1 -1
  97. package/dist/services/index.d.ts +0 -3
  98. package/dist/services/index.d.ts.map +1 -1
  99. package/dist/services/login/index.d.ts +1 -3
  100. package/dist/services/login/index.d.ts.map +1 -1
  101. package/dist/services/login/loginService.d.ts +2 -6
  102. package/dist/services/login/loginService.d.ts.map +1 -1
  103. package/dist/services/orders/adapter.d.ts +0 -2
  104. package/dist/services/orders/adapter.d.ts.map +1 -1
  105. package/dist/services/orders/index.d.ts +1 -1
  106. package/dist/services/orders/index.d.ts.map +1 -1
  107. package/dist/services/product/adapter.d.ts +2 -27
  108. package/dist/services/product/adapter.d.ts.map +1 -1
  109. package/dist/services/product/index.d.ts +1 -1
  110. package/dist/services/product/index.d.ts.map +1 -1
  111. package/dist/services/product/productService.d.ts.map +1 -1
  112. package/dist/services/product/types.d.ts +0 -68
  113. package/dist/services/product/types.d.ts.map +1 -1
  114. package/dist/services/subscription/adapter.d.ts +2 -77
  115. package/dist/services/subscription/adapter.d.ts.map +1 -1
  116. package/dist/services/subscription/index.d.ts +1 -1
  117. package/dist/services/subscription/index.d.ts.map +1 -1
  118. package/dist/services/subscription/subscriptionService.d.ts +6 -1
  119. package/dist/services/subscription/subscriptionService.d.ts.map +1 -1
  120. package/dist/services/subscription/types.d.ts +9 -220
  121. package/dist/services/subscription/types.d.ts.map +1 -1
  122. package/dist/theme-state.d.ts +17 -2
  123. package/dist/theme-state.d.ts.map +1 -1
  124. package/dist/theme-state.layout.test.d.ts +2 -0
  125. package/dist/theme-state.layout.test.d.ts.map +1 -0
  126. package/dist/theme-state.test.d.ts +2 -0
  127. package/dist/theme-state.test.d.ts.map +1 -0
  128. package/dist/utils/index.d.ts +0 -6
  129. package/dist/utils/index.d.ts.map +1 -1
  130. package/dist/vue/block.d.ts.map +1 -1
  131. package/dist/vue.js +4 -25
  132. package/dist/web-components/ExtensionRoot.d.ts +50 -3
  133. package/dist/web-components/ExtensionRoot.d.ts.map +1 -1
  134. package/dist/web-components/editor/ExtensionRoot.d.ts +11 -0
  135. package/dist/web-components/editor/ExtensionRoot.d.ts.map +1 -0
  136. package/dist/web-components/editor/ExtensionRoot.test.d.ts +2 -0
  137. package/dist/web-components/editor/ExtensionRoot.test.d.ts.map +1 -0
  138. package/dist/web-components/editor/InlineText.d.ts +1 -0
  139. package/dist/web-components/editor/InlineText.d.ts.map +1 -1
  140. package/dist/web-components/editor/editor-layout-controller.d.ts +28 -0
  141. package/dist/web-components/editor/editor-layout-controller.d.ts.map +1 -0
  142. package/dist/web-components/editor/gridstack-adapter.d.ts +3 -0
  143. package/dist/web-components/editor/gridstack-adapter.d.ts.map +1 -0
  144. package/dist/web-components/editor/gridstack-adapter.test.d.ts +2 -0
  145. package/dist/web-components/editor/gridstack-adapter.test.d.ts.map +1 -0
  146. package/dist/web-components/editor/morph.d.ts +32 -0
  147. package/dist/web-components/editor/morph.d.ts.map +1 -0
  148. package/dist/web-components/editor/morph.test.d.ts +2 -0
  149. package/dist/web-components/editor/morph.test.d.ts.map +1 -0
  150. package/dist/web-components/layout/layout-controller.d.ts +55 -0
  151. package/dist/web-components/layout/layout-controller.d.ts.map +1 -0
  152. package/dist/web-components/layout/view-layout-controller.d.ts +17 -0
  153. package/dist/web-components/layout/view-layout-controller.d.ts.map +1 -0
  154. package/dist/web-components/layout/view-layout-controller.test.d.ts +2 -0
  155. package/dist/web-components/layout/view-layout-controller.test.d.ts.map +1 -0
  156. package/dist/web-components/layout-grid.d.ts +47 -0
  157. package/dist/web-components/layout-grid.d.ts.map +1 -0
  158. package/dist/web-components/layout-grid.test.d.ts +2 -0
  159. package/dist/web-components/layout-grid.test.d.ts.map +1 -0
  160. package/dist/web-components/layout-mode-adapter.d.ts +51 -0
  161. package/dist/web-components/layout-mode-adapter.d.ts.map +1 -0
  162. package/dist/web-components/layout-mode-adapter.test.d.ts +2 -0
  163. package/dist/web-components/layout-mode-adapter.test.d.ts.map +1 -0
  164. package/dist/web-components-editor.js +125 -18
  165. package/dist/web-components-runtime.js +4 -4
  166. package/package.json +3 -2
  167. package/dist/ExtensionRoot-peABLAZZ.js +0 -231
  168. package/dist/block-B6s9jL7l.js +0 -966
  169. package/dist/block.devtools.test.d.ts +0 -2
  170. package/dist/block.devtools.test.d.ts.map +0 -1
  171. package/dist/context.devtools.test.d.ts +0 -2
  172. package/dist/context.devtools.test.d.ts.map +0 -1
  173. package/dist/devtools/env.d.ts +0 -3
  174. package/dist/devtools/env.d.ts.map +0 -1
  175. package/dist/devtools/hook.d.ts +0 -35
  176. package/dist/devtools/hook.d.ts.map +0 -1
  177. package/dist/devtools/index.d.ts +0 -4
  178. package/dist/devtools/index.d.ts.map +0 -1
  179. package/dist/devtools/protocol.d.ts +0 -91
  180. package/dist/devtools/protocol.d.ts.map +0 -1
  181. package/dist/devtools.js +0 -44
  182. package/dist/editor/overlays.d.ts +0 -14
  183. package/dist/editor/overlays.d.ts.map +0 -1
  184. package/dist/editor/overlays.test.d.ts +0 -2
  185. package/dist/editor/overlays.test.d.ts.map +0 -1
  186. package/dist/juo-workflow-DY4rd256.js +0 -868
  187. package/dist/overlay-wrapper.d.ts +0 -69
  188. package/dist/overlay-wrapper.d.ts.map +0 -1
  189. package/dist/overlay-wrapper.test.d.ts +0 -2
  190. package/dist/overlay-wrapper.test.d.ts.map +0 -1
  191. package/dist/overlays/OverlayService.d.ts +0 -34
  192. package/dist/overlays/OverlayService.d.ts.map +0 -1
  193. package/dist/overlays/OverlayService.test.d.ts +0 -2
  194. package/dist/overlays/OverlayService.test.d.ts.map +0 -1
  195. package/dist/registry.devtools.test.d.ts +0 -2
  196. package/dist/registry.devtools.test.d.ts.map +0 -1
  197. package/dist/services/customer/adapter.d.ts +0 -8
  198. package/dist/services/customer/adapter.d.ts.map +0 -1
  199. package/dist/services/login/adapter.d.ts +0 -32
  200. package/dist/services/login/adapter.d.ts.map +0 -1
  201. package/dist/services/order/adapter.d.ts +0 -9
  202. package/dist/services/order/adapter.d.ts.map +0 -1
  203. package/dist/services/order/index.d.ts +0 -5
  204. package/dist/services/order/index.d.ts.map +0 -1
  205. package/dist/services/order/orderService.d.ts +0 -7
  206. package/dist/services/order/orderService.d.ts.map +0 -1
  207. package/dist/services/order/types.d.ts +0 -21
  208. package/dist/services/order/types.d.ts.map +0 -1
  209. package/dist/services/product/adapter.test.d.ts +0 -2
  210. package/dist/services/product/adapter.test.d.ts.map +0 -1
  211. package/dist/services/schedules/adapter.d.ts +0 -71
  212. package/dist/services/schedules/adapter.d.ts.map +0 -1
  213. package/dist/services/schedules/adapter.test.d.ts +0 -2
  214. package/dist/services/schedules/adapter.test.d.ts.map +0 -1
  215. package/dist/services/schedules/index.d.ts +0 -5
  216. package/dist/services/schedules/index.d.ts.map +0 -1
  217. package/dist/services/schedules/schedulesService.d.ts +0 -11
  218. package/dist/services/schedules/schedulesService.d.ts.map +0 -1
  219. package/dist/services/schedules/schedulesService.test.d.ts +0 -2
  220. package/dist/services/schedules/schedulesService.test.d.ts.map +0 -1
  221. package/dist/services/schedules/types.d.ts +0 -226
  222. package/dist/services/schedules/types.d.ts.map +0 -1
  223. package/dist/services/settings/index.d.ts +0 -3
  224. package/dist/services/settings/index.d.ts.map +0 -1
  225. package/dist/services/settings/settingsService.d.ts +0 -7
  226. package/dist/services/settings/settingsService.d.ts.map +0 -1
  227. package/dist/services/settings/settingsService.test.d.ts +0 -2
  228. package/dist/services/settings/settingsService.test.d.ts.map +0 -1
  229. package/dist/services/settings/types.d.ts +0 -35
  230. package/dist/services/settings/types.d.ts.map +0 -1
  231. package/dist/services/shop/index.d.ts +0 -3
  232. package/dist/services/shop/index.d.ts.map +0 -1
  233. package/dist/services/shop/shopService.d.ts +0 -12
  234. package/dist/services/shop/shopService.d.ts.map +0 -1
  235. package/dist/services/shop/shopService.test.d.ts +0 -2
  236. package/dist/services/shop/shopService.test.d.ts.map +0 -1
  237. package/dist/services/shop/types.d.ts +0 -7
  238. package/dist/services/shop/types.d.ts.map +0 -1
  239. package/dist/services/subscription/adapter.test.d.ts +0 -2
  240. package/dist/services/subscription/adapter.test.d.ts.map +0 -1
  241. package/dist/services/subscription/types.test.d.ts +0 -2
  242. package/dist/services/subscription/types.test.d.ts.map +0 -1
  243. package/dist/theme-state.params.test.d.ts +0 -2
  244. package/dist/theme-state.params.test.d.ts.map +0 -1
  245. package/dist/theme-state.translations.test.d.ts +0 -2
  246. package/dist/theme-state.translations.test.d.ts.map +0 -1
@@ -1,868 +0,0 @@
1
- var __defProp = Object.defineProperty;
2
- var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
3
- var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
4
- import { e as createContext, d, f as createBlockInstanceFromObject, g as createBlockInstance, h as getDefinedBlocks, j as serializeBlocks, o as onRegisterBlock, E, k as w, r as registerBlock, l as defineBlock, s as subscribeContext } from "./block-B6s9jL7l.js";
5
- import { reportBlockError } from "./observability.js";
6
- import { c as createEditorBridge, v as createSelectBlockMessage } from "./bridge-r7Yk8fjY.js";
7
- const DEFAULT_GLOBAL_STYLES = {
8
- volume: "comfort",
9
- style: "ghost",
10
- corners: "round",
11
- buttonCorners: "round",
12
- thumbnailCorners: "circle",
13
- theme: "preset",
14
- themeType: "neutral",
15
- colors: {
16
- accent: "#000000",
17
- secondary: "#000000",
18
- tint: "#111111",
19
- callout: "#F5F5F5",
20
- success: "#287a25",
21
- error: "#a93c3c",
22
- information: "#0075a3",
23
- warning: "#8a5e00",
24
- background: "#FFFFFF"
25
- }
26
- };
27
- const ThemeStateContext = createContext("theme-state");
28
- function normalizeLocale(locale) {
29
- return locale.trim().toLowerCase().split("-")[0] || "en";
30
- }
31
- function toStringRecord$1(input) {
32
- if (input == null) return {};
33
- return Object.fromEntries(
34
- Object.entries(input).filter(([, value]) => typeof value === "string")
35
- );
36
- }
37
- function parseBlockLocaleFile(file) {
38
- if (file == null) {
39
- return { defaults: {}, modes: {} };
40
- }
41
- const entries = Object.entries(file).filter(
42
- ([key, value]) => key !== "overrides" && typeof value === "string"
43
- );
44
- const topLevel = Object.fromEntries(entries);
45
- const overrides = toStringRecord$1(file.overrides);
46
- return {
47
- defaults: { ...topLevel, ...overrides },
48
- modes: {
49
- ...Object.fromEntries(
50
- Object.keys(topLevel).map((key) => [key, "default"])
51
- ),
52
- ...Object.fromEntries(
53
- Object.keys(overrides).map((key) => [key, "override"])
54
- )
55
- }
56
- };
57
- }
58
- function indexOverrides(overrides) {
59
- const indexed = {
60
- theme: {},
61
- blocks: {}
62
- };
63
- for (const item of overrides) {
64
- if (item.scope.kind === "theme") {
65
- indexed.theme[item.key] = item.value;
66
- continue;
67
- }
68
- if (indexed.blocks[item.scope.blockId] == null) {
69
- indexed.blocks[item.scope.blockId] = {};
70
- }
71
- indexed.blocks[item.scope.blockId][item.key] = item.value;
72
- }
73
- return indexed;
74
- }
75
- function createThemeState(deps) {
76
- var _a;
77
- const surfaces = {
78
- page: { blocks: d([]) },
79
- overlay: { blocks: d([]) }
80
- };
81
- const locale = d("en");
82
- const catalogs = d(null);
83
- const globalStyles = d(
84
- deps.initialGlobalStyles ?? DEFAULT_GLOBAL_STYLES
85
- );
86
- function setGlobalStyles(styles) {
87
- globalStyles.value = styles;
88
- }
89
- function setInstanceTranslationOverride(blockId, key, value) {
90
- const current = catalogs.value;
91
- if (current == null) return;
92
- catalogs.value = {
93
- ...current,
94
- blocks: {
95
- ...current.blocks,
96
- overrides: {
97
- ...current.blocks.overrides,
98
- [blockId]: { ...current.blocks.overrides[blockId], [key]: value }
99
- }
100
- }
101
- };
102
- }
103
- async function collectBlockDefaults(loc) {
104
- const nextDefaults = {};
105
- const nextModes = {};
106
- for (const block of getDefinedBlocks()) {
107
- if (block.locales == null) continue;
108
- let file = null;
109
- try {
110
- file = await block.locales.load(loc);
111
- } catch {
112
- file = null;
113
- }
114
- const parsed = parseBlockLocaleFile(file);
115
- nextDefaults[block.name] = parsed.defaults;
116
- nextModes[block.name] = parsed.modes;
117
- }
118
- return { defaults: nextDefaults, modes: nextModes };
119
- }
120
- async function setLocale(nextLocaleRaw) {
121
- var _a2;
122
- const nextLocale = normalizeLocale(nextLocaleRaw);
123
- const [blockData, loadedOverrides] = await Promise.all([
124
- collectBlockDefaults(nextLocale),
125
- ((_a2 = deps.translations) == null ? void 0 : _a2.resolveTranslations(nextLocale).catch(() => [])) ?? Promise.resolve([])
126
- ]);
127
- const overrides = loadedOverrides.filter(
128
- (item) => normalizeLocale(item.locale) === nextLocale
129
- );
130
- const indexed = indexOverrides(overrides);
131
- catalogs.value = {
132
- theme: {
133
- defaults: {},
134
- overrides: indexed.theme
135
- },
136
- blocks: {
137
- defaults: blockData.defaults,
138
- modes: blockData.modes,
139
- overrides: indexed.blocks
140
- }
141
- };
142
- locale.value = nextLocale;
143
- }
144
- async function resolve(surface, path, params) {
145
- var _a2, _b, _c, _d, _e, _f, _g, _h;
146
- surfaces[surface].blocks.value = [];
147
- const stored = await deps.resolve(surface, path);
148
- if (stored != null) {
149
- const instances = stored.blocks.flatMap((block) => {
150
- try {
151
- return [createBlockInstanceFromObject(block)];
152
- } catch (error) {
153
- reportBlockError(error, {
154
- site: "theme-state.resolve.hydrate",
155
- extra: {
156
- surface,
157
- path,
158
- blockType: typeof (block == null ? void 0 : block.type) === "string" ? block.type : "(unknown)"
159
- }
160
- });
161
- return [];
162
- }
163
- });
164
- if (surface === "overlay") {
165
- for (const instance of instances) {
166
- if (typeof instance.type !== "string" || !instance.type.startsWith("overlay:")) {
167
- continue;
168
- }
169
- try {
170
- const canonical = createBlockInstance(instance.type);
171
- instance.props = {
172
- ...instance.props ?? {},
173
- layout: (_a2 = canonical.props) == null ? void 0 : _a2.layout,
174
- canAbort: (_b = canonical.props) == null ? void 0 : _b.canAbort
175
- };
176
- } catch (error) {
177
- reportBlockError(error, {
178
- site: "theme-state.resolve.overlay-layout",
179
- extra: { surface, path, blockType: instance.type }
180
- });
181
- }
182
- }
183
- }
184
- if (params != null) {
185
- for (const instance of instances) {
186
- const content = (_c = instance.slots) == null ? void 0 : _c.content;
187
- const child = Array.isArray(content) ? content[0] : void 0;
188
- if (child != null) {
189
- child.props = { ...child.props ?? {}, ...params };
190
- }
191
- }
192
- }
193
- surfaces[surface].blocks.value = instances;
194
- return stored;
195
- }
196
- const blockToUse = surface === "page" ? (_e = (_d = deps.routerService) == null ? void 0 : _d.getPages().find((p) => p.path === path)) == null ? void 0 : _e.block : (_f = getDefinedBlocks().find((b) => b.name === path)) == null ? void 0 : _f.name;
197
- if (blockToUse != null) {
198
- const instance = createBlockInstance(blockToUse);
199
- if (params != null) {
200
- const content = (_g = instance.slots) == null ? void 0 : _g.content;
201
- const child = Array.isArray(content) ? content[0] : void 0;
202
- if (child != null) {
203
- child.props = { ...child.props ?? {}, ...params };
204
- }
205
- }
206
- surfaces[surface].blocks.value = [instance];
207
- const serialized = serializeBlocks([instance]);
208
- (_h = deps.upsertState) == null ? void 0 : _h.call(deps, surface, path, serialized);
209
- return { blocks: serialized };
210
- }
211
- return { blocks: [] };
212
- }
213
- onRegisterBlock(async (_, block) => {
214
- if (block.locales == null || catalogs.value == null) return;
215
- const localeAtLoadStart = locale.value;
216
- let file = null;
217
- try {
218
- file = await block.locales.load(localeAtLoadStart);
219
- } catch {
220
- file = null;
221
- }
222
- if (catalogs.value == null || locale.value !== localeAtLoadStart) return;
223
- const parsed = parseBlockLocaleFile(file);
224
- const current = catalogs.value;
225
- catalogs.value = {
226
- ...current,
227
- blocks: {
228
- ...current.blocks,
229
- defaults: {
230
- ...current.blocks.defaults,
231
- [block.name]: parsed.defaults
232
- },
233
- modes: {
234
- ...current.blocks.modes,
235
- [block.name]: parsed.modes
236
- }
237
- }
238
- };
239
- });
240
- (_a = deps.routerService) == null ? void 0 : _a.subscribe(({ path }) => {
241
- resolve("page", path);
242
- });
243
- return {
244
- page: surfaces.page,
245
- overlay: surfaces.overlay,
246
- locales: { locale, catalogs, setLocale },
247
- globalStyles,
248
- setGlobalStyles,
249
- setInstanceTranslationOverride,
250
- resolve
251
- };
252
- }
253
- const TranslationContext = createContext("translation");
254
- function toStringRecord(input) {
255
- if (input == null) return {};
256
- return Object.fromEntries(
257
- Object.entries(input).filter(([, value]) => typeof value === "string")
258
- );
259
- }
260
- function createTranslationService(locales, options = {}) {
261
- const loadedThemeDefaults = d({});
262
- if (options.loadDefaultTranslations) {
263
- let loadVersion = 0;
264
- E(() => {
265
- const locale = locales.locale.value;
266
- const currentVersion = ++loadVersion;
267
- void options.loadDefaultTranslations(locale).then((result) => toStringRecord(result)).catch(() => ({})).then((result) => {
268
- if (currentVersion !== loadVersion) return;
269
- loadedThemeDefaults.value = result;
270
- });
271
- });
272
- }
273
- return {
274
- locale: locales.locale,
275
- resolve(blockType, blockId, key) {
276
- var _a, _b, _c;
277
- const data = locales.catalogs.value;
278
- const themeDefault = loadedThemeDefaults.value[key] ?? (data == null ? void 0 : data.theme.defaults[key]);
279
- if (data == null) {
280
- return themeDefault ?? key;
281
- }
282
- if (blockId && ((_a = data.blocks.overrides[blockId]) == null ? void 0 : _a[key]) !== void 0) {
283
- return data.blocks.overrides[blockId][key];
284
- }
285
- const blockDefault = blockType != null ? (_b = data.blocks.defaults[blockType]) == null ? void 0 : _b[key] : void 0;
286
- const mode = (blockType != null ? (_c = data.blocks.modes[blockType]) == null ? void 0 : _c[key] : void 0) ?? "override";
287
- if (blockDefault !== void 0 && mode === "override") {
288
- return blockDefault;
289
- }
290
- if (data.theme.overrides[key] !== void 0) {
291
- return data.theme.overrides[key];
292
- }
293
- if (themeDefault !== void 0) {
294
- return themeDefault;
295
- }
296
- if (blockDefault !== void 0) {
297
- return blockDefault;
298
- }
299
- return key;
300
- }
301
- };
302
- }
303
- function getDefaultBlockForAction(actionType, actionConfig, blockId) {
304
- const blockName = `action:${actionType}`;
305
- const definedBlocks = getDefinedBlocks();
306
- const exists = definedBlocks.some((b) => b.name === blockName);
307
- if (!exists) {
308
- throw new Error(
309
- `No default block registered for action type "${actionType}". Expected a block named "${blockName}" to be registered in blocks-extensions.`
310
- );
311
- }
312
- return createBlockInstance(blockName, { props: actionConfig, id: blockId });
313
- }
314
- function hasDefaultBlockForAction(actionType) {
315
- const blockName = `action:${actionType}`;
316
- return getDefinedBlocks().some((b) => b.name === blockName);
317
- }
318
- const WorkflowServiceContext = createContext("services/workflow");
319
- function createWorkflowApiAdapter(sdk) {
320
- return {
321
- async start(flowType, context, workflowId, dryRun) {
322
- const { data } = await sdk.post("/customer/v1/workflows/start", {
323
- flowType,
324
- context,
325
- ...workflowId ? { workflowId } : {},
326
- ...dryRun ? { dryRun: true } : {}
327
- });
328
- return data;
329
- },
330
- async respond(runId, interactionId, responseType, responseData, expectedRunVersion, eventId) {
331
- const { data } = await sdk.post(
332
- "/customer/v1/workflows/{runId}/respond",
333
- {
334
- runId,
335
- interactionId,
336
- responseType,
337
- responseData,
338
- expectedRunVersion,
339
- eventId
340
- }
341
- );
342
- return data;
343
- },
344
- async getState(runId) {
345
- const { data } = await sdk.get("/customer/v1/workflows/{runId}", {
346
- runId
347
- });
348
- return data;
349
- },
350
- async cancel(runId) {
351
- const { data } = await sdk.post("/customer/v1/workflows/{runId}/cancel", {
352
- runId
353
- });
354
- return data;
355
- }
356
- };
357
- }
358
- function createWorkflowService(deps) {
359
- const { api } = deps;
360
- const editor = createEditorBridge();
361
- const urlParams = typeof window !== "undefined" ? new URLSearchParams(window.location.search) : null;
362
- const previewWorkflowTrigger = (urlParams == null ? void 0 : urlParams.get("trigger")) ?? null;
363
- const previewStepId = (urlParams == null ? void 0 : urlParams.get("step-id")) ?? null;
364
- const previewWorkflowId = (urlParams == null ? void 0 : urlParams.get("workflow-id")) ?? null;
365
- const isEditorMode = editor.isEditorMode || previewWorkflowTrigger !== null;
366
- const _state = d({
367
- status: "idle",
368
- flowType: null,
369
- workflowId: null,
370
- workflowVersion: null,
371
- runId: null,
372
- runVersion: null,
373
- currentStepId: null,
374
- currentInteraction: null,
375
- error: null,
376
- result: null,
377
- flowParams: null,
378
- invalidatedResources: [],
379
- outcome: null,
380
- completionData: null,
381
- dryRun: null,
382
- firstPollReason: null
383
- });
384
- const _backendInteractionId = d(null);
385
- const _registeredRootBlocks = /* @__PURE__ */ new Set();
386
- const isActive = w(() => _state.value.status === "active");
387
- const isLoading = w(() => _state.value.status === "loading");
388
- const isCompleted = w(() => _state.value.status === "completed");
389
- const hasError = w(() => _state.value.status === "error");
390
- const currentInteraction = w(() => _state.value.currentInteraction);
391
- const canRespond = w(() => {
392
- const interaction = _state.value.currentInteraction;
393
- const backendId = _backendInteractionId.value;
394
- if (!interaction || !backendId) return false;
395
- return interaction.interactionId === backendId;
396
- });
397
- const currentStepInfo = w(() => {
398
- const interaction = _state.value.currentInteraction;
399
- if (!interaction) return null;
400
- const actionConfig = deps.shopCurrencyCode ? { ...interaction.actionConfig, currency: deps.shopCurrencyCode } : interaction.actionConfig;
401
- return {
402
- interactionId: interaction.interactionId,
403
- stepId: interaction.stepId,
404
- actionType: interaction.actionType,
405
- actionConfig,
406
- availableResponses: interaction.availableResponses
407
- };
408
- });
409
- function updateState(updates) {
410
- _state.value = { ..._state.value, ...updates };
411
- }
412
- function hashString(value) {
413
- let hash = 2166136261;
414
- for (let index = 0; index < value.length; index += 1) {
415
- hash ^= value.charCodeAt(index);
416
- hash = Math.imul(hash, 16777619);
417
- }
418
- return (hash >>> 0).toString(36);
419
- }
420
- function shortenId(value, slugLength = 6) {
421
- const compact = value.toLowerCase().replace(/[^a-z0-9]/g, "");
422
- const slug = (compact || "id").slice(0, slugLength);
423
- return `${slug}-${hashString(value)}`;
424
- }
425
- function createStableStepBlockId(workflowId, stepId) {
426
- return `wf-${shortenId(workflowId)}-${shortenId(stepId)}`;
427
- }
428
- function handleFlowResponse(data) {
429
- var _a, _b, _c, _d, _e, _f, _g;
430
- const mergedInvalidated = [
431
- ..._state.value.invalidatedResources,
432
- ...data.invalidatedResources ?? []
433
- ];
434
- if (data.status === "waiting_interaction") {
435
- const currentStepId = ((_a = data.pendingInteraction) == null ? void 0 : _a.stepId) ?? (isEditorMode ? (_c = (_b = data.interactiveSteps) == null ? void 0 : _b[0]) == null ? void 0 : _c.stepId : null);
436
- _backendInteractionId.value = ((_d = data.pendingInteraction) == null ? void 0 : _d.interactionId) ?? null;
437
- const isInitialResponse = _state.value.runId == null;
438
- updateState({
439
- status: "active",
440
- workflowId: data.workflowId,
441
- workflowVersion: data.workflowVersion,
442
- runId: data.runId,
443
- runVersion: data.runVersion,
444
- currentStepId,
445
- currentInteraction: data.pendingInteraction,
446
- invalidatedResources: mergedInvalidated,
447
- outcome: null
448
- });
449
- if (editor.isEditorMode) {
450
- const displayStepId = isInitialResponse && previewStepId && ((_e = data.interactiveSteps) == null ? void 0 : _e.some((s) => s.stepId === previewStepId)) ? previewStepId : currentStepId;
451
- const overlayBlocks = deps.themeState.overlay.blocks.value;
452
- const rootBlock = overlayBlocks[0];
453
- const stepSlot = displayStepId ? (_f = rootBlock == null ? void 0 : rootBlock.slots) == null ? void 0 : _f[displayStepId] : null;
454
- const stepBlock = Array.isArray(stepSlot) ? stepSlot[0] : null;
455
- const blockId = stepBlock && typeof stepBlock === "object" && "id" in stepBlock ? stepBlock.id : null;
456
- if (blockId) {
457
- editor.sendMessage(
458
- createSelectBlockMessage({ blockId }, blockId)
459
- );
460
- }
461
- }
462
- } else if (data.status === "completed") {
463
- _backendInteractionId.value = null;
464
- updateState({
465
- status: "completed",
466
- currentStepId: null,
467
- currentInteraction: null,
468
- runVersion: data.runVersion,
469
- result: data.result || null,
470
- invalidatedResources: mergedInvalidated,
471
- outcome: data.outcome || null,
472
- completionData: data.completionData || null
473
- });
474
- } else if (data.status === "failed") {
475
- _backendInteractionId.value = null;
476
- handleError(new Error(((_g = data.error) == null ? void 0 : _g.message) || "Flow failed"));
477
- } else if (data.status === "cancelled") {
478
- _backendInteractionId.value = null;
479
- updateState({
480
- status: "idle",
481
- flowType: null,
482
- workflowId: null,
483
- workflowVersion: null,
484
- runId: null,
485
- runVersion: null,
486
- currentStepId: null,
487
- currentInteraction: null,
488
- error: null,
489
- result: null,
490
- invalidatedResources: [],
491
- outcome: null,
492
- completionData: null,
493
- firstPollReason: null
494
- });
495
- }
496
- }
497
- function handleError(error) {
498
- const message = error instanceof Error ? error.message : "Unknown error";
499
- updateState({
500
- status: "error",
501
- error: message
502
- });
503
- }
504
- function maybeApplyPreviewStep(flowType, data) {
505
- var _a;
506
- if (!previewWorkflowTrigger) return;
507
- if (flowType !== previewWorkflowTrigger) return;
508
- if (data.status !== "waiting_interaction") return;
509
- const step = (_a = data.interactiveSteps) == null ? void 0 : _a.find(
510
- (interactiveStep) => interactiveStep.stepId === previewStepId
511
- );
512
- if (!step) return;
513
- updateState({
514
- currentStepId: step.stepId,
515
- currentInteraction: {
516
- interactionId: `preview-${data.runId}-${step.stepId}`,
517
- stepId: step.stepId,
518
- actionType: step.actionType,
519
- actionBehavior: "input",
520
- actionConfig: step.actionConfig,
521
- availableResponses: step.availableResponses,
522
- presentedAt: /* @__PURE__ */ new Date()
523
- }
524
- });
525
- }
526
- function initWorkflowRootBlock(data) {
527
- if (_registeredRootBlocks.has(data.workflowId)) {
528
- return;
529
- }
530
- const allSteps = data.interactiveSteps ?? (data.pendingInteraction ? [
531
- {
532
- stepId: data.pendingInteraction.stepId,
533
- actionType: data.pendingInteraction.actionType,
534
- actionConfig: data.pendingInteraction.actionConfig,
535
- availableResponses: data.pendingInteraction.availableResponses
536
- }
537
- ] : []);
538
- const slotProperties = {};
539
- for (const step of allSteps) {
540
- slotProperties[step.stepId] = {};
541
- }
542
- const presets = {};
543
- const baseLabelFor = (step) => {
544
- var _a;
545
- return ((_a = getDefinedBlocks().find((b) => b.name === `action:${step.actionType}`)) == null ? void 0 : _a.displayName) ?? step.stepId;
546
- };
547
- const totalCounts = /* @__PURE__ */ new Map();
548
- for (const step of allSteps) {
549
- const baseLabel = baseLabelFor(step);
550
- totalCounts.set(baseLabel, (totalCounts.get(baseLabel) ?? 0) + 1);
551
- }
552
- const seenCounts = /* @__PURE__ */ new Map();
553
- for (const step of allSteps) {
554
- const baseLabel = baseLabelFor(step);
555
- const occurrence = (seenCounts.get(baseLabel) ?? 0) + 1;
556
- seenCounts.set(baseLabel, occurrence);
557
- const isDuplicated = (totalCounts.get(baseLabel) ?? 0) > 1;
558
- const label = isDuplicated ? `${baseLabel} (${occurrence})` : baseLabel;
559
- presets[step.stepId] = {
560
- label,
561
- description: step.actionType,
562
- state: step.stepId,
563
- // @ts-expect-error Untyped
564
- context: step
565
- };
566
- }
567
- registerBlock(
568
- defineBlock(`workflow:${data.workflowId}`, {
569
- group: "workflow",
570
- schema: {
571
- type: "object",
572
- properties: {
573
- props: { type: "object" },
574
- slots: {
575
- type: "object",
576
- properties: slotProperties
577
- }
578
- },
579
- required: ["props", "slots"],
580
- additionalProperties: true
581
- },
582
- initialValue: () => ({
583
- props: {},
584
- slots: Object.fromEntries(
585
- allSteps.map((step) => [
586
- step.stepId,
587
- [
588
- getDefaultBlockForAction(
589
- step.actionType,
590
- step.actionConfig,
591
- createStableStepBlockId(data.workflowId, step.stepId)
592
- )
593
- ]
594
- ])
595
- )
596
- }),
597
- presets,
598
- renderer() {
599
- return null;
600
- }
601
- })
602
- );
603
- _registeredRootBlocks.add(data.workflowId);
604
- }
605
- async function initWorkflowState(data) {
606
- const { blocks } = await deps.themeState.resolve(
607
- "overlay",
608
- `workflow:${data.workflowId}`
609
- );
610
- if (blocks.length === 0) return;
611
- editor.onBlockPresetChange(blocks[0].id, (preset) => {
612
- if (!preset) {
613
- return;
614
- }
615
- updateState({
616
- // @ts-expect-error Untyped
617
- currentStepId: preset.state,
618
- // @ts-expect-error Untyped
619
- currentInteraction: { ...preset == null ? void 0 : preset.context }
620
- });
621
- });
622
- }
623
- const service = {
624
- // State signals (readonly)
625
- state: _state,
626
- /** True when the portal is running inside the Blocks Editor (editorMode dep
627
- * or ?trigger=... URL param). Consumers use this to suppress auto-start. */
628
- isPreviewMode: isEditorMode,
629
- // Computed signals
630
- isActive,
631
- isLoading,
632
- isCompleted,
633
- hasError,
634
- canRespond,
635
- currentInteraction,
636
- currentStepInfo,
637
- // Methods
638
- async startFlow(flowType, context, workflowId) {
639
- const isDryRun = isEditorMode;
640
- updateState({
641
- status: "loading",
642
- error: null,
643
- flowParams: context,
644
- flowType,
645
- dryRun: isDryRun,
646
- firstPollReason: null
647
- });
648
- try {
649
- const data = await api.start(
650
- flowType,
651
- context,
652
- workflowId,
653
- isDryRun || void 0
654
- );
655
- if (data.status === "no_workflow") {
656
- service.reset();
657
- return;
658
- }
659
- if (data.status === "completed_silently") {
660
- updateState({
661
- status: "completed",
662
- currentStepId: null,
663
- currentInteraction: null,
664
- result: null,
665
- invalidatedResources: data.invalidatedResources ?? [],
666
- outcome: data.outcome || null,
667
- completionData: data.completionData || null
668
- });
669
- return;
670
- }
671
- initWorkflowRootBlock(data);
672
- await initWorkflowState(data);
673
- handleFlowResponse(data);
674
- maybeApplyPreviewStep(flowType, data);
675
- } catch (error) {
676
- handleError(error);
677
- }
678
- },
679
- async respond(responseType, responseData) {
680
- const { runId, runVersion, currentInteraction: currentInteraction2 } = _state.value;
681
- if (!runId || !currentInteraction2) {
682
- throw new Error("No active interaction to respond to");
683
- }
684
- updateState({ status: "loading" });
685
- try {
686
- const data = await api.respond(
687
- runId,
688
- currentInteraction2.interactionId,
689
- responseType,
690
- responseData,
691
- runVersion ?? void 0
692
- );
693
- if (_state.value.firstPollReason == null && currentInteraction2.actionType === "poll") {
694
- const reason = responseData == null ? void 0 : responseData.reason;
695
- if (typeof reason === "string" && reason.length > 0) {
696
- updateState({ firstPollReason: reason });
697
- }
698
- }
699
- handleFlowResponse(data);
700
- } catch (error) {
701
- handleError(error);
702
- }
703
- },
704
- async cancel() {
705
- const { runId, status } = _state.value;
706
- const isTerminal = status === "completed" || status === "error";
707
- if (runId && !isTerminal) {
708
- try {
709
- const data = await api.cancel(runId);
710
- if (data.outcome) {
711
- updateState({
712
- status: "completed",
713
- flowType: null,
714
- workflowId: null,
715
- workflowVersion: null,
716
- runId: null,
717
- runVersion: null,
718
- currentStepId: null,
719
- currentInteraction: null,
720
- error: null,
721
- result: null,
722
- flowParams: null,
723
- invalidatedResources: data.invalidatedResources ?? [],
724
- outcome: data.outcome || null,
725
- dryRun: null
726
- });
727
- return;
728
- }
729
- } catch {
730
- }
731
- }
732
- service.reset();
733
- },
734
- reset() {
735
- _backendInteractionId.value = null;
736
- updateState({
737
- status: "idle",
738
- flowType: null,
739
- workflowId: null,
740
- workflowVersion: null,
741
- runId: null,
742
- runVersion: null,
743
- currentStepId: null,
744
- currentInteraction: null,
745
- error: null,
746
- result: null,
747
- flowParams: null,
748
- invalidatedResources: [],
749
- outcome: null,
750
- completionData: null,
751
- firstPollReason: null
752
- });
753
- },
754
- async refresh() {
755
- const { runId } = _state.value;
756
- if (!runId) return;
757
- try {
758
- const data = await api.getState(runId);
759
- handleFlowResponse(data);
760
- } catch (error) {
761
- handleError(error);
762
- }
763
- }
764
- };
765
- if (previewWorkflowTrigger) {
766
- void service.startFlow(
767
- previewWorkflowTrigger,
768
- {},
769
- previewWorkflowId ?? void 0
770
- );
771
- }
772
- return service;
773
- }
774
- class JuoWorkflowElement extends HTMLElement {
775
- constructor() {
776
- super(...arguments);
777
- __publicField(this, "workflowService", null);
778
- __publicField(this, "unsubscribeContext", null);
779
- __publicField(this, "unsubscribeEffect", null);
780
- /** Tracks which step is currently mounted to avoid unnecessary DOM teardown. */
781
- __publicField(this, "renderedStepId", null);
782
- /**
783
- * Optional function to wrap rendered content (step blocks).
784
- * Must be set before workflow becomes active for correct behavior.
785
- */
786
- __publicField(this, "blockWrapper", null);
787
- }
788
- connectedCallback() {
789
- this.style.display = "contents";
790
- this.unsubscribeContext = subscribeContext(
791
- this,
792
- WorkflowServiceContext,
793
- (service) => {
794
- this.workflowService = service;
795
- this.setupSubscription();
796
- }
797
- );
798
- }
799
- disconnectedCallback() {
800
- var _a, _b;
801
- (_a = this.unsubscribeContext) == null ? void 0 : _a.call(this);
802
- (_b = this.unsubscribeEffect) == null ? void 0 : _b.call(this);
803
- this.unsubscribeContext = null;
804
- this.unsubscribeEffect = null;
805
- this.renderedStepId = null;
806
- }
807
- setupSubscription() {
808
- var _a;
809
- if (!this.workflowService) return;
810
- (_a = this.unsubscribeEffect) == null ? void 0 : _a.call(this);
811
- this.unsubscribeEffect = E(() => {
812
- var _a2, _b;
813
- const status = ((_a2 = this.workflowService) == null ? void 0 : _a2.state.value.status) ?? "idle";
814
- const stepInfo = (_b = this.workflowService) == null ? void 0 : _b.currentStepInfo.value;
815
- const stepId = (stepInfo == null ? void 0 : stepInfo.stepId) ?? null;
816
- queueMicrotask(() => {
817
- if (this.isConnected) {
818
- this.render(status, stepId);
819
- }
820
- });
821
- });
822
- }
823
- render(status, stepId) {
824
- var _a;
825
- if ((status === "active" || status === "loading") && stepId) {
826
- if (this.renderedStepId !== stepId) {
827
- this.innerHTML = "";
828
- this.renderedStepId = stepId;
829
- const extensionRoot = document.createElement(
830
- "juo-extension-root"
831
- );
832
- extensionRoot.setAttribute("surface", "overlay");
833
- extensionRoot.setAttribute("name", stepId);
834
- extensionRoot.blockWrapper = this.blockWrapper;
835
- this.appendChild(extensionRoot);
836
- }
837
- return;
838
- }
839
- this.innerHTML = "";
840
- this.renderedStepId = null;
841
- if (status === "error") {
842
- const error = ((_a = this.workflowService) == null ? void 0 : _a.state.value.error) ?? "Unknown error";
843
- this.dispatchEvent(
844
- new CustomEvent("juo-workflow-error", {
845
- bubbles: true,
846
- composed: true,
847
- detail: { error }
848
- })
849
- );
850
- }
851
- }
852
- }
853
- if (typeof customElements !== "undefined" && !customElements.get("juo-workflow")) {
854
- customElements.define("juo-workflow", JuoWorkflowElement);
855
- }
856
- export {
857
- DEFAULT_GLOBAL_STYLES as D,
858
- TranslationContext as T,
859
- WorkflowServiceContext as W,
860
- ThemeStateContext as a,
861
- createTranslationService as b,
862
- createThemeState as c,
863
- createWorkflowApiAdapter as d,
864
- createWorkflowService as e,
865
- getDefaultBlockForAction as g,
866
- hasDefaultBlockForAction as h,
867
- indexOverrides as i
868
- };