@juo/blocks 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (153) hide show
  1. package/dist/ExtensionRoot-CZyBNJZY.js +159 -0
  2. package/dist/block-VhmfGB3N.js +51 -0
  3. package/dist/block.d.ts +96 -0
  4. package/dist/block.d.ts.map +1 -0
  5. package/dist/bridge-DQsM97cH.js +490 -0
  6. package/dist/context.d.ts +76 -0
  7. package/dist/context.d.ts.map +1 -0
  8. package/dist/context.test.d.ts +2 -0
  9. package/dist/context.test.d.ts.map +1 -0
  10. package/dist/core.js +1163 -0
  11. package/dist/editor/bridge.d.ts +75 -0
  12. package/dist/editor/bridge.d.ts.map +1 -0
  13. package/dist/editor/bridge.test.d.ts +2 -0
  14. package/dist/editor/bridge.test.d.ts.map +1 -0
  15. package/dist/editor/components.d.ts +31 -0
  16. package/dist/editor/components.d.ts.map +1 -0
  17. package/dist/editor/handler.d.ts +10 -0
  18. package/dist/editor/handler.d.ts.map +1 -0
  19. package/dist/editor/main.d.ts +17 -0
  20. package/dist/editor/main.d.ts.map +1 -0
  21. package/dist/editor/messages.d.ts +233 -0
  22. package/dist/editor/messages.d.ts.map +1 -0
  23. package/dist/editor.js +711 -0
  24. package/dist/flows/MockWorkflowApiAdapter.d.ts +13 -0
  25. package/dist/flows/MockWorkflowApiAdapter.d.ts.map +1 -0
  26. package/dist/flows/WorkflowService.d.ts +175 -0
  27. package/dist/flows/WorkflowService.d.ts.map +1 -0
  28. package/dist/flows/__tests__/WorkflowService.test.d.ts +2 -0
  29. package/dist/flows/__tests__/WorkflowService.test.d.ts.map +1 -0
  30. package/dist/flows/__tests__/defaults.test.d.ts +2 -0
  31. package/dist/flows/__tests__/defaults.test.d.ts.map +1 -0
  32. package/dist/flows/__tests__/juo-workflow.test.d.ts +2 -0
  33. package/dist/flows/__tests__/juo-workflow.test.d.ts.map +1 -0
  34. package/dist/flows/__tests__/overlay-behavior.test.d.ts +2 -0
  35. package/dist/flows/__tests__/overlay-behavior.test.d.ts.map +1 -0
  36. package/dist/flows/__tests__/theme-state-surfaces.test.d.ts +2 -0
  37. package/dist/flows/__tests__/theme-state-surfaces.test.d.ts.map +1 -0
  38. package/dist/flows/defaults.d.ts +15 -0
  39. package/dist/flows/defaults.d.ts.map +1 -0
  40. package/dist/flows/index.d.ts +4 -0
  41. package/dist/flows/index.d.ts.map +1 -0
  42. package/dist/flows/juo-workflow.d.ts +48 -0
  43. package/dist/flows/juo-workflow.d.ts.map +1 -0
  44. package/dist/juo-workflow-RSrOuKUH.js +591 -0
  45. package/dist/main.d.ts +11 -0
  46. package/dist/main.d.ts.map +1 -0
  47. package/dist/preact/block.d.ts +21 -0
  48. package/dist/preact/block.d.ts.map +1 -0
  49. package/dist/preact/block.test.d.ts +2 -0
  50. package/dist/preact/block.test.d.ts.map +1 -0
  51. package/dist/preact/bridge.d.ts +11 -0
  52. package/dist/preact/bridge.d.ts.map +1 -0
  53. package/dist/preact/context.d.ts +31 -0
  54. package/dist/preact/context.d.ts.map +1 -0
  55. package/dist/preact/main.d.ts +11 -0
  56. package/dist/preact/main.d.ts.map +1 -0
  57. package/dist/preact/signals.d.ts +23 -0
  58. package/dist/preact/signals.d.ts.map +1 -0
  59. package/dist/preact.js +230 -0
  60. package/dist/react/block.d.ts +21 -0
  61. package/dist/react/block.d.ts.map +1 -0
  62. package/dist/react/block.test.d.ts +2 -0
  63. package/dist/react/block.test.d.ts.map +1 -0
  64. package/dist/react/bridge.d.ts +11 -0
  65. package/dist/react/bridge.d.ts.map +1 -0
  66. package/dist/react/context.d.ts +28 -0
  67. package/dist/react/context.d.ts.map +1 -0
  68. package/dist/react/main.d.ts +11 -0
  69. package/dist/react/main.d.ts.map +1 -0
  70. package/dist/react/signals.d.ts +23 -0
  71. package/dist/react/signals.d.ts.map +1 -0
  72. package/dist/react.js +205 -0
  73. package/dist/services/index.d.ts +4 -0
  74. package/dist/services/index.d.ts.map +1 -0
  75. package/dist/services/login/index.d.ts +23 -0
  76. package/dist/services/login/index.d.ts.map +1 -0
  77. package/dist/services/login/loginService.d.ts +82 -0
  78. package/dist/services/login/loginService.d.ts.map +1 -0
  79. package/dist/services/product/adapter.d.ts +20 -0
  80. package/dist/services/product/adapter.d.ts.map +1 -0
  81. package/dist/services/product/index.d.ts +5 -0
  82. package/dist/services/product/index.d.ts.map +1 -0
  83. package/dist/services/product/productService.d.ts +12 -0
  84. package/dist/services/product/productService.d.ts.map +1 -0
  85. package/dist/services/product/types.d.ts +32 -0
  86. package/dist/services/product/types.d.ts.map +1 -0
  87. package/dist/services/subscription/adapter.d.ts +49 -0
  88. package/dist/services/subscription/adapter.d.ts.map +1 -0
  89. package/dist/services/subscription/index.d.ts +5 -0
  90. package/dist/services/subscription/index.d.ts.map +1 -0
  91. package/dist/services/subscription/list.d.ts +22 -0
  92. package/dist/services/subscription/list.d.ts.map +1 -0
  93. package/dist/services/subscription/store.d.ts +30 -0
  94. package/dist/services/subscription/store.d.ts.map +1 -0
  95. package/dist/services/subscription/subscriptionService.d.ts +12 -0
  96. package/dist/services/subscription/subscriptionService.d.ts.map +1 -0
  97. package/dist/services/subscription/types.d.ts +76 -0
  98. package/dist/services/subscription/types.d.ts.map +1 -0
  99. package/dist/shared/block.d.ts +17 -0
  100. package/dist/shared/block.d.ts.map +1 -0
  101. package/dist/shared/context.d.ts +16 -0
  102. package/dist/shared/context.d.ts.map +1 -0
  103. package/dist/shared/signals.d.ts +17 -0
  104. package/dist/shared/signals.d.ts.map +1 -0
  105. package/dist/state.d.ts +81 -0
  106. package/dist/state.d.ts.map +1 -0
  107. package/dist/theme-state-BZplRS92.js +886 -0
  108. package/dist/theme-state.d.ts +85 -0
  109. package/dist/theme-state.d.ts.map +1 -0
  110. package/dist/theme-state.locales.test.d.ts +2 -0
  111. package/dist/theme-state.locales.test.d.ts.map +1 -0
  112. package/dist/translation.d.ts +14 -0
  113. package/dist/translation.d.ts.map +1 -0
  114. package/dist/translation.test.d.ts +2 -0
  115. package/dist/translation.test.d.ts.map +1 -0
  116. package/dist/utils/index.d.ts +32 -0
  117. package/dist/utils/index.d.ts.map +1 -0
  118. package/dist/utils/login.d.ts +11 -0
  119. package/dist/utils/login.d.ts.map +1 -0
  120. package/dist/utils/uuid.d.ts +2 -0
  121. package/dist/utils/uuid.d.ts.map +1 -0
  122. package/dist/vue/block.d.ts +7 -0
  123. package/dist/vue/block.d.ts.map +1 -0
  124. package/dist/vue/bridge.d.ts +11 -0
  125. package/dist/vue/bridge.d.ts.map +1 -0
  126. package/dist/vue/context.d.ts +24 -0
  127. package/dist/vue/context.d.ts.map +1 -0
  128. package/dist/vue/main.d.ts +6 -0
  129. package/dist/vue/main.d.ts.map +1 -0
  130. package/dist/vue/signals.d.ts +5 -0
  131. package/dist/vue/signals.d.ts.map +1 -0
  132. package/dist/vue/target.d.ts +2 -0
  133. package/dist/vue/target.d.ts.map +1 -0
  134. package/dist/vue/transform.d.ts +2 -0
  135. package/dist/vue/transform.d.ts.map +1 -0
  136. package/dist/vue.js +254 -0
  137. package/dist/web-components/Block.d.ts +17 -0
  138. package/dist/web-components/Block.d.ts.map +1 -0
  139. package/dist/web-components/Block.test.d.ts +2 -0
  140. package/dist/web-components/Block.test.d.ts.map +1 -0
  141. package/dist/web-components/ExtensionRoot.d.ts +29 -0
  142. package/dist/web-components/ExtensionRoot.d.ts.map +1 -0
  143. package/dist/web-components/editor/InlineText.d.ts +29 -0
  144. package/dist/web-components/editor/InlineText.d.ts.map +1 -0
  145. package/dist/web-components/editor/main.d.ts +2 -0
  146. package/dist/web-components/editor/main.d.ts.map +1 -0
  147. package/dist/web-components/runtime/InlineText.d.ts +6 -0
  148. package/dist/web-components/runtime/InlineText.d.ts.map +1 -0
  149. package/dist/web-components/runtime/main.d.ts +2 -0
  150. package/dist/web-components/runtime/main.d.ts.map +1 -0
  151. package/dist/web-components-editor.js +183 -0
  152. package/dist/web-components-runtime.js +55 -0
  153. package/package.json +62 -0
@@ -0,0 +1,11 @@
1
+ /**
2
+ * Preact integration for Blocks
3
+ *
4
+ * This module provides Preact-specific utilities for working with blocks,
5
+ * context, and signals.
6
+ */
7
+ export * from './signals';
8
+ export * from './context';
9
+ export * from './block';
10
+ export * from './bridge';
11
+ //# sourceMappingURL=main.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"main.d.ts","sourceRoot":"","sources":["../../src/preact/main.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,cAAc,WAAW,CAAC;AAC1B,cAAc,WAAW,CAAC;AAC1B,cAAc,SAAS,CAAC;AACxB,cAAc,UAAU,CAAC"}
@@ -0,0 +1,23 @@
1
+ import { Signal } from '../main.ts';
2
+ /**
3
+ * Converts a Preact state or value to an Blocks signal
4
+ *
5
+ * @param value - Preact state or value to convert
6
+ * @returns A Blocks signal that tracks the value
7
+ */
8
+ export { toSignal } from '../shared/signals';
9
+ /**
10
+ * Converts an Blocks signal to Preact state
11
+ *
12
+ * @param signal - Blocks signal or computed function
13
+ * @returns Preact state tuple [value, setValue] that tracks the signal
14
+ */
15
+ export declare function toState<T extends object>(signal: Signal<T> | (() => T)): [T, (value: T) => void];
16
+ /**
17
+ * Hook to use an Blocks signal as Preact state
18
+ *
19
+ * @param signal - Blocks signal or computed function
20
+ * @returns The current value of the signal
21
+ */
22
+ export declare function useSignal<T>(signal: Signal<T> | (() => T)): T;
23
+ //# sourceMappingURL=signals.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"signals.d.ts","sourceRoot":"","sources":["../../src/preact/signals.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAAU,MAAM,EAAE,MAAM,aAAa,CAAC;AAI7C;;;;;GAKG;AACH,OAAO,EAAE,QAAQ,EAAE,MAAM,mBAAmB,CAAC;AAE7C;;;;;GAKG;AACH,wBAAgB,OAAO,CAAC,CAAC,SAAS,MAAM,EACtC,MAAM,EAAE,MAAM,CAAC,CAAC,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC,GAC5B,CAAC,CAAC,EAAE,CAAC,KAAK,EAAE,CAAC,KAAK,IAAI,CAAC,CAkCzB;AAED;;;;;GAKG;AACH,wBAAgB,SAAS,CAAC,CAAC,EAAE,MAAM,EAAE,MAAM,CAAC,CAAC,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC,GAAG,CAAC,CA8B7D"}
package/dist/preact.js ADDED
@@ -0,0 +1,230 @@
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 { effect, provideContext, injectContext, createCeRenderer } from "@juo/blocks";
5
+ import { useState, useRef, useEffect, useContext as useContext$1, useMemo } from "preact/hooks";
6
+ import { g as getSignalValue, s as setSignalValue, w as wrapContext, c as createSlotChildren } from "./block-VhmfGB3N.js";
7
+ import { t } from "./block-VhmfGB3N.js";
8
+ import { createContext, h, render } from "preact";
9
+ import { a as createEditorBridge } from "./bridge-DQsM97cH.js";
10
+ function toState(signal) {
11
+ const [value, setValue] = useState(() => getSignalValue(signal));
12
+ const disposeRef = useRef(null);
13
+ useEffect(() => {
14
+ if (disposeRef.current) {
15
+ disposeRef.current();
16
+ }
17
+ const dispose = effect(() => {
18
+ const newValue = getSignalValue(signal);
19
+ setValue(newValue);
20
+ });
21
+ disposeRef.current = dispose;
22
+ setValue(getSignalValue(signal));
23
+ return () => {
24
+ if (disposeRef.current) {
25
+ disposeRef.current();
26
+ disposeRef.current = null;
27
+ }
28
+ };
29
+ }, [signal]);
30
+ const setSignalValueWrapper = (newValue) => {
31
+ setSignalValue(signal, newValue);
32
+ };
33
+ return [value, setSignalValueWrapper];
34
+ }
35
+ function useSignal(signal) {
36
+ const [value, setValue] = useState(() => getSignalValue(signal));
37
+ const disposeRef = useRef(null);
38
+ useEffect(() => {
39
+ if (disposeRef.current) {
40
+ disposeRef.current();
41
+ }
42
+ const dispose = effect(() => {
43
+ const newValue = getSignalValue(signal);
44
+ setValue(newValue);
45
+ });
46
+ disposeRef.current = dispose;
47
+ setValue(getSignalValue(signal));
48
+ return () => {
49
+ if (disposeRef.current) {
50
+ disposeRef.current();
51
+ disposeRef.current = null;
52
+ }
53
+ };
54
+ }, [signal]);
55
+ return value;
56
+ }
57
+ const ContextProviderContext = createContext(null);
58
+ function ContextProvider({ children }) {
59
+ const [rootElement, setRootElement] = useState(null);
60
+ const [mounted, setMounted] = useState(false);
61
+ const rootRef = (element) => {
62
+ if (element) {
63
+ setRootElement(element);
64
+ setMounted(true);
65
+ console.debug("preact/context-provider:ready");
66
+ }
67
+ };
68
+ return h(
69
+ ContextProviderContext.Provider,
70
+ { value: rootElement },
71
+ h("div", { ref: rootRef, className: "contents" }, mounted ? children : null)
72
+ );
73
+ }
74
+ function useProvideContext(context, init) {
75
+ const root = useContext$1(ContextProviderContext);
76
+ if (root == null) {
77
+ throw new Error("ContextProvider not available");
78
+ }
79
+ provideContext(root, context, init);
80
+ }
81
+ function useContext(context) {
82
+ const root = useContext$1(ContextProviderContext);
83
+ if (root == null) {
84
+ throw new Error("ContextProvider not available");
85
+ }
86
+ return wrapContext(injectContext(root, context), toState);
87
+ }
88
+ function useBlockId() {
89
+ const root = useContext$1(ContextProviderContext);
90
+ return useMemo(() => {
91
+ if (!(root == null ? void 0 : root.parentElement)) {
92
+ return null;
93
+ }
94
+ return root.parentElement.getAttribute("data-block-id");
95
+ }, [root]);
96
+ }
97
+ const PreactSlotWrapper = ({
98
+ block
99
+ }) => {
100
+ const containerRef = useRef(null);
101
+ useEffect(() => {
102
+ if (!containerRef.current) return;
103
+ const children = createSlotChildren(block);
104
+ containerRef.current.replaceChildren(...children);
105
+ }, [block]);
106
+ return h("div", { ref: containerRef });
107
+ };
108
+ function createPreactRenderer(component) {
109
+ function renderSlots(slots) {
110
+ if (!slots) {
111
+ return slots;
112
+ }
113
+ const renderedSlots = {};
114
+ Object.entries(slots).forEach(([key, value]) => {
115
+ renderedSlots[key] = h(PreactSlotWrapper, {
116
+ block: value
117
+ });
118
+ });
119
+ return renderedSlots;
120
+ }
121
+ return (block) => {
122
+ const wrapper = document.createElement("div");
123
+ wrapper.setAttribute("data-block-id", block.id);
124
+ render(
125
+ h(ContextProvider, {
126
+ children: h(
127
+ component,
128
+ { ...block.props, ...renderSlots(block.slots) }
129
+ )
130
+ }),
131
+ wrapper
132
+ );
133
+ return wrapper;
134
+ };
135
+ }
136
+ function createPreactCeRenderer(name, component, { shadowRoot = true } = {}) {
137
+ if (customElements.get(name) != null) {
138
+ console.warn(`Custom element '${name}' already defined`);
139
+ return createCeRenderer(name);
140
+ }
141
+ class PreactCustomElement extends HTMLElement {
142
+ constructor() {
143
+ super(...arguments);
144
+ __publicField(this, "container", null);
145
+ __publicField(this, "mounted", false);
146
+ }
147
+ connectedCallback() {
148
+ if (this.mounted) return;
149
+ this.container = shadowRoot ? this.attachShadow({ mode: "open" }) : this;
150
+ this.mounted = true;
151
+ this.render();
152
+ }
153
+ disconnectedCallback() {
154
+ if (this.container) {
155
+ render(null, this.container);
156
+ }
157
+ this.mounted = false;
158
+ }
159
+ render() {
160
+ if (!this.container || !this.mounted) return;
161
+ const props = {};
162
+ Array.from(this.attributes).forEach((attr) => {
163
+ props[attr.name] = attr.value;
164
+ });
165
+ const slots = {};
166
+ const slotElements = this.querySelectorAll("[slot]");
167
+ slotElements.forEach((el) => {
168
+ const slotName = el.getAttribute("slot") || "default";
169
+ if (!slots[slotName]) {
170
+ slots[slotName] = [];
171
+ }
172
+ slots[slotName].push(el);
173
+ });
174
+ render(
175
+ h(ContextProvider, {
176
+ children: h(component, { ...props, ...slots })
177
+ }),
178
+ this.container
179
+ );
180
+ }
181
+ attributeChangedCallback() {
182
+ if (this.mounted) {
183
+ this.render();
184
+ }
185
+ }
186
+ static get observedAttributes() {
187
+ return [];
188
+ }
189
+ }
190
+ customElements.define(name, PreactCustomElement);
191
+ return createCeRenderer(name);
192
+ }
193
+ const subscriptionMap = /* @__PURE__ */ new Map();
194
+ function useBridge(options) {
195
+ const blockId = useBlockId();
196
+ const editorBridge = useMemo(() => createEditorBridge(), []);
197
+ const callbackRef = useRef(options.onPresetChange);
198
+ callbackRef.current = options.onPresetChange;
199
+ const isEditorMode = blockId !== null;
200
+ useEffect(() => {
201
+ if (!isEditorMode || !blockId) return;
202
+ if (subscriptionMap.has(blockId)) {
203
+ subscriptionMap.get(blockId)();
204
+ subscriptionMap.delete(blockId);
205
+ }
206
+ const { unsubscribe } = editorBridge.onBlockPresetChange(blockId, (preset) => {
207
+ callbackRef.current(preset);
208
+ });
209
+ subscriptionMap.set(blockId, unsubscribe);
210
+ return () => {
211
+ if (subscriptionMap.has(blockId)) {
212
+ subscriptionMap.get(blockId)();
213
+ subscriptionMap.delete(blockId);
214
+ }
215
+ };
216
+ }, [isEditorMode, blockId, editorBridge]);
217
+ return { isEditorMode };
218
+ }
219
+ export {
220
+ ContextProvider,
221
+ createPreactCeRenderer,
222
+ createPreactRenderer,
223
+ t as toSignal,
224
+ toState,
225
+ useBlockId,
226
+ useBridge,
227
+ useContext,
228
+ useProvideContext,
229
+ useSignal
230
+ };
@@ -0,0 +1,21 @@
1
+ import { default as React } from 'react';
2
+ import { BlockInstance } from '../main.ts';
3
+ /**
4
+ * Creates a block renderer for React components
5
+ *
6
+ * @param component - React component to render
7
+ * @returns A block renderer function
8
+ */
9
+ export declare function createReactRenderer<P = any>(component: React.ComponentType<P>): (block: BlockInstance) => HTMLElement;
10
+ /**
11
+ * Creates a custom element renderer for React components
12
+ *
13
+ * @param name - Custom element name
14
+ * @param component - React component to render
15
+ * @param options - Renderer options
16
+ * @returns A block renderer function
17
+ */
18
+ export declare function createReactCeRenderer<P = any>(name: string, component: React.ComponentType<P>, { shadowRoot }?: {
19
+ shadowRoot?: boolean;
20
+ }): (block: BlockInstance) => HTMLElement;
21
+ //# sourceMappingURL=block.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"block.d.ts","sourceRoot":"","sources":["../../src/react/block.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,KAAK,MAAM,OAAO,CAAC;AAE1B,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAuBjD;;;;;GAKG;AACH,wBAAgB,mBAAmB,CAAC,CAAC,GAAG,GAAG,EACzC,SAAS,EAAE,KAAK,CAAC,aAAa,CAAC,CAAC,CAAC,GAChC,CAAC,KAAK,EAAE,aAAa,KAAK,WAAW,CAgCvC;AAED;;;;;;;GAOG;AACH,wBAAgB,qBAAqB,CAAC,CAAC,GAAG,GAAG,EAC3C,IAAI,EAAE,MAAM,EACZ,SAAS,EAAE,KAAK,CAAC,aAAa,CAAC,CAAC,CAAC,EACjC,EAAE,UAAiB,EAAE,GAAE;IAAE,UAAU,CAAC,EAAE,OAAO,CAAA;CAAO,GACnD,CAAC,KAAK,EAAE,aAAa,KAAK,WAAW,CAyEvC"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=block.test.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"block.test.d.ts","sourceRoot":"","sources":["../../src/react/block.test.ts"],"names":[],"mappings":""}
@@ -0,0 +1,11 @@
1
+ import { PresetData, ExtractPresetState, ExtractPresetContext } from '../editor/bridge';
2
+ type PresetChangeCallback<TPresets> = (preset: PresetData<ExtractPresetState<TPresets>, ExtractPresetContext<TPresets>> | null) => void;
3
+ export interface UseBridgeOptions<TPresets = unknown> {
4
+ onPresetChange: PresetChangeCallback<TPresets>;
5
+ }
6
+ export interface BlockBridgeAPI {
7
+ readonly isEditorMode: boolean;
8
+ }
9
+ export declare function useBridge<TPresets = unknown>(options: UseBridgeOptions<TPresets>): BlockBridgeAPI;
10
+ export {};
11
+ //# sourceMappingURL=bridge.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"bridge.d.ts","sourceRoot":"","sources":["../../src/react/bridge.ts"],"names":[],"mappings":"AACA,OAAO,EAEL,KAAK,UAAU,EACf,KAAK,kBAAkB,EACvB,KAAK,oBAAoB,EAC1B,MAAM,kBAAkB,CAAC;AAG1B,KAAK,oBAAoB,CAAC,QAAQ,IAAI,CACpC,MAAM,EAAE,UAAU,CAChB,kBAAkB,CAAC,QAAQ,CAAC,EAC5B,oBAAoB,CAAC,QAAQ,CAAC,CAC/B,GAAG,IAAI,KACL,IAAI,CAAC;AAEV,MAAM,WAAW,gBAAgB,CAAC,QAAQ,GAAG,OAAO;IAClD,cAAc,EAAE,oBAAoB,CAAC,QAAQ,CAAC,CAAC;CAChD;AAED,MAAM,WAAW,cAAc;IAC7B,QAAQ,CAAC,YAAY,EAAE,OAAO,CAAC;CAChC;AAED,wBAAgB,SAAS,CAAC,QAAQ,GAAG,OAAO,EAC1C,OAAO,EAAE,gBAAgB,CAAC,QAAQ,CAAC,GAClC,cAAc,CAiBhB"}
@@ -0,0 +1,28 @@
1
+ import { default as React, ReactNode } from 'react';
2
+ import { ContextType, UnknownContext } from '../main.ts';
3
+ import { Wrap } from '../shared/context';
4
+ /**
5
+ * Context Provider component for React
6
+ *
7
+ * Provides the DOM element reference needed for Blocks context operations.
8
+ */
9
+ export declare function ContextProvider({ children }: {
10
+ children: ReactNode;
11
+ }): React.FunctionComponentElement<React.ProviderProps<HTMLElement | null>>;
12
+ /**
13
+ * Hook to provide context value in React components
14
+ *
15
+ * @param context - The context to provide
16
+ * @param init - The initial value for the context
17
+ */
18
+ export declare function useProvideContext<C extends UnknownContext>(context: C, init: ContextType<C>): void;
19
+ /**
20
+ * Hook to inject context value in React components
21
+ *
22
+ * @param context - The context to inject
23
+ * @returns The context value, with signals automatically converted to React state
24
+ */
25
+ export declare function useContext<C extends UnknownContext>(context: C): Wrap<ContextType<C>>;
26
+ export declare function useBlockId(): string | null;
27
+ export type { Wrap } from '../shared/context';
28
+ //# sourceMappingURL=context.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"context.d.ts","sourceRoot":"","sources":["../../src/react/context.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,KAAK,EAAE,EAKZ,KAAK,SAAS,EACf,MAAM,OAAO,CAAC;AACf,OAAO,EACL,WAAW,EAGX,cAAc,EACf,MAAM,aAAa,CAAC;AAErB,OAAO,EAAe,KAAK,IAAI,EAAE,MAAM,mBAAmB,CAAC;AAI3D;;;;GAIG;AACH,wBAAgB,eAAe,CAAC,EAAE,QAAQ,EAAE,EAAE;IAAE,QAAQ,EAAE,SAAS,CAAA;CAAE,2EAsBpE;AAED;;;;;GAKG;AACH,wBAAgB,iBAAiB,CAAC,CAAC,SAAS,cAAc,EACxD,OAAO,EAAE,CAAC,EACV,IAAI,EAAE,WAAW,CAAC,CAAC,CAAC,GACnB,IAAI,CAON;AAED;;;;;GAKG;AACH,wBAAgB,UAAU,CAAC,CAAC,SAAS,cAAc,EACjD,OAAO,EAAE,CAAC,GACT,IAAI,CAAC,WAAW,CAAC,CAAC,CAAC,CAAC,CAOtB;AAED,wBAAgB,UAAU,IAAI,MAAM,GAAG,IAAI,CAU1C;AAED,YAAY,EAAE,IAAI,EAAE,MAAM,mBAAmB,CAAC"}
@@ -0,0 +1,11 @@
1
+ /**
2
+ * React integration for Blocks
3
+ *
4
+ * This module provides React-specific utilities for working with blocks,
5
+ * context, and signals.
6
+ */
7
+ export * from './signals';
8
+ export * from './context';
9
+ export * from './block';
10
+ export * from './bridge';
11
+ //# sourceMappingURL=main.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"main.d.ts","sourceRoot":"","sources":["../../src/react/main.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,cAAc,WAAW,CAAC;AAC1B,cAAc,WAAW,CAAC;AAC1B,cAAc,SAAS,CAAC;AACxB,cAAc,UAAU,CAAC"}
@@ -0,0 +1,23 @@
1
+ import { Signal } from '../main.ts';
2
+ /**
3
+ * Converts a React state or value to an Blocks signal
4
+ *
5
+ * @param value - React state or value to convert
6
+ * @returns An Blocks signal that tracks the value
7
+ */
8
+ export { toSignal } from '../shared/signals';
9
+ /**
10
+ * Converts an Blocks signal to React state
11
+ *
12
+ * @param signal - Blocks signal or computed function
13
+ * @returns React state tuple [value, setValue] that tracks the signal
14
+ */
15
+ export declare function toState<T extends object>(signal: Signal<T> | (() => T)): [T, (value: T) => void];
16
+ /**
17
+ * Hook to use an Blocks signal as React state
18
+ *
19
+ * @param signal - Blocks signal or computed function
20
+ * @returns The current value of the signal
21
+ */
22
+ export declare function useSignal<T>(signal: Signal<T> | (() => T)): T;
23
+ //# sourceMappingURL=signals.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"signals.d.ts","sourceRoot":"","sources":["../../src/react/signals.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAAU,MAAM,EAAE,MAAM,aAAa,CAAC;AAI7C;;;;;GAKG;AACH,OAAO,EAAE,QAAQ,EAAE,MAAM,mBAAmB,CAAC;AAE7C;;;;;GAKG;AACH,wBAAgB,OAAO,CAAC,CAAC,SAAS,MAAM,EACtC,MAAM,EAAE,MAAM,CAAC,CAAC,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC,GAC5B,CAAC,CAAC,EAAE,CAAC,KAAK,EAAE,CAAC,KAAK,IAAI,CAAC,CAkBzB;AAED;;;;;GAKG;AACH,wBAAgB,SAAS,CAAC,CAAC,EAAE,MAAM,EAAE,MAAM,CAAC,CAAC,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC,GAAG,CAAC,CAY7D"}
package/dist/react.js ADDED
@@ -0,0 +1,205 @@
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 { effect, provideContext, injectContext, createCeRenderer } from "@juo/blocks";
5
+ import React, { useSyncExternalStore, createContext, useState, useContext as useContext$1, useMemo, useRef, useEffect } from "react";
6
+ import { g as getSignalValue, s as setSignalValue, w as wrapContext, c as createSlotChildren } from "./block-VhmfGB3N.js";
7
+ import { t } from "./block-VhmfGB3N.js";
8
+ import { createRoot } from "react-dom/client";
9
+ import { a as createEditorBridge } from "./bridge-DQsM97cH.js";
10
+ function toState(signal) {
11
+ const subscribe = (callback) => {
12
+ const dispose = effect(() => {
13
+ getSignalValue(signal);
14
+ callback();
15
+ });
16
+ return dispose;
17
+ };
18
+ const getSnapshot = () => getSignalValue(signal);
19
+ const value = useSyncExternalStore(subscribe, getSnapshot, getSnapshot);
20
+ const setValue = (newValue) => {
21
+ setSignalValue(signal, newValue);
22
+ };
23
+ return [value, setValue];
24
+ }
25
+ function useSignal(signal) {
26
+ const subscribe = (callback) => {
27
+ const dispose = effect(() => {
28
+ getSignalValue(signal);
29
+ callback();
30
+ });
31
+ return dispose;
32
+ };
33
+ const getSnapshot = () => getSignalValue(signal);
34
+ return useSyncExternalStore(subscribe, getSnapshot, getSnapshot);
35
+ }
36
+ const ContextProviderContext = createContext(null);
37
+ function ContextProvider({ children }) {
38
+ const [rootElement, setRootElement] = useState(null);
39
+ const [mounted, setMounted] = useState(false);
40
+ const rootRef = (element) => {
41
+ if (element) {
42
+ setRootElement(element);
43
+ setMounted(true);
44
+ console.debug("react/context-provider:ready");
45
+ }
46
+ };
47
+ return React.createElement(
48
+ ContextProviderContext.Provider,
49
+ { value: rootElement },
50
+ React.createElement(
51
+ "div",
52
+ // TODO: Replace `contents` class with CSS
53
+ { ref: rootRef, className: "contents" },
54
+ mounted ? children : null
55
+ )
56
+ );
57
+ }
58
+ function useProvideContext(context, init) {
59
+ const root = useContext$1(ContextProviderContext);
60
+ if (root == null) {
61
+ throw new Error("ContextProvider not available");
62
+ }
63
+ provideContext(root, context, init);
64
+ }
65
+ function useContext(context) {
66
+ const root = useContext$1(ContextProviderContext);
67
+ if (root == null) {
68
+ throw new Error("ContextProvider not available");
69
+ }
70
+ return wrapContext(injectContext(root, context), toState);
71
+ }
72
+ function useBlockId() {
73
+ const root = useContext$1(ContextProviderContext);
74
+ return useMemo(() => {
75
+ if (!(root == null ? void 0 : root.parentElement)) {
76
+ return null;
77
+ }
78
+ return root.parentElement.getAttribute("data-block-id");
79
+ }, [root]);
80
+ }
81
+ const ReactSlotWrapper = ({ block }) => {
82
+ const containerRef = React.useRef(null);
83
+ React.useEffect(() => {
84
+ if (!containerRef.current) return;
85
+ const children = createSlotChildren(block);
86
+ containerRef.current.replaceChildren(...children);
87
+ }, [block]);
88
+ return React.createElement("div", { ref: containerRef });
89
+ };
90
+ function createReactRenderer(component) {
91
+ function renderSlots(slots) {
92
+ if (!slots) {
93
+ return slots;
94
+ }
95
+ const renderedSlots = {};
96
+ Object.entries(slots).forEach(([key, value]) => {
97
+ renderedSlots[key] = React.createElement(ReactSlotWrapper, {
98
+ block: value
99
+ });
100
+ });
101
+ return renderedSlots;
102
+ }
103
+ return (block) => {
104
+ const wrapper = document.createElement("div");
105
+ wrapper.setAttribute("data-block-id", block.id);
106
+ const root = createRoot(wrapper);
107
+ root.render(
108
+ React.createElement(ContextProvider, {
109
+ children: React.createElement(
110
+ component,
111
+ { ...block.props, ...renderSlots(block.slots) }
112
+ )
113
+ })
114
+ );
115
+ return wrapper;
116
+ };
117
+ }
118
+ function createReactCeRenderer(name, component, { shadowRoot = true } = {}) {
119
+ if (customElements.get(name) != null) {
120
+ console.warn(`Custom element '${name}' already defined`);
121
+ return createCeRenderer(name);
122
+ }
123
+ class ReactCustomElement extends HTMLElement {
124
+ constructor() {
125
+ super(...arguments);
126
+ __publicField(this, "root", null);
127
+ __publicField(this, "container", null);
128
+ __publicField(this, "mounted", false);
129
+ }
130
+ connectedCallback() {
131
+ if (this.mounted) return;
132
+ this.container = shadowRoot ? this.attachShadow({ mode: "open" }) : this;
133
+ this.root = createRoot(this.container);
134
+ this.mounted = true;
135
+ this.render();
136
+ }
137
+ disconnectedCallback() {
138
+ if (this.root) {
139
+ this.root.unmount();
140
+ this.root = null;
141
+ }
142
+ this.mounted = false;
143
+ }
144
+ render() {
145
+ if (!this.root || !this.mounted) return;
146
+ const props = {};
147
+ Array.from(this.attributes).forEach((attr) => {
148
+ props[attr.name] = attr.value;
149
+ });
150
+ const slots = {};
151
+ const slotElements = this.querySelectorAll("[slot]");
152
+ slotElements.forEach((el) => {
153
+ const slotName = el.getAttribute("slot") || "default";
154
+ if (!slots[slotName]) {
155
+ slots[slotName] = [];
156
+ }
157
+ slots[slotName].push(el);
158
+ });
159
+ this.root.render(
160
+ React.createElement(ContextProvider, {
161
+ children: React.createElement(
162
+ component,
163
+ { ...props, ...slots }
164
+ )
165
+ })
166
+ );
167
+ }
168
+ attributeChangedCallback() {
169
+ if (this.mounted) {
170
+ this.render();
171
+ }
172
+ }
173
+ static get observedAttributes() {
174
+ return [];
175
+ }
176
+ }
177
+ customElements.define(name, ReactCustomElement);
178
+ return createCeRenderer(name);
179
+ }
180
+ function useBridge(options) {
181
+ const blockId = useBlockId();
182
+ const editorBridge = useMemo(() => createEditorBridge(), []);
183
+ const callbackRef = useRef(options.onPresetChange);
184
+ callbackRef.current = options.onPresetChange;
185
+ const isEditorMode = blockId !== null;
186
+ useEffect(() => {
187
+ if (!isEditorMode || !blockId) return;
188
+ return editorBridge.onBlockPresetChange(blockId, (preset) => {
189
+ callbackRef.current(preset);
190
+ }).unsubscribe;
191
+ }, [isEditorMode, blockId, editorBridge]);
192
+ return { isEditorMode };
193
+ }
194
+ export {
195
+ ContextProvider,
196
+ createReactCeRenderer,
197
+ createReactRenderer,
198
+ t as toSignal,
199
+ toState,
200
+ useBlockId,
201
+ useBridge,
202
+ useContext,
203
+ useProvideContext,
204
+ useSignal
205
+ };
@@ -0,0 +1,4 @@
1
+ export * from './login';
2
+ export * from './product';
3
+ export * from './subscription';
4
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/services/index.ts"],"names":[],"mappings":"AAAA,cAAc,SAAS,CAAC;AACxB,cAAc,WAAW,CAAC;AAC1B,cAAc,gBAAgB,CAAC"}
@@ -0,0 +1,23 @@
1
+ import { Signal } from '@preact/signals-core';
2
+ import { Result, ErrorDetails } from '../../utils';
3
+ type LoginService = {
4
+ passwordless: {
5
+ email: {
6
+ start(email: string): Promise<Result<void, ErrorDetails>>;
7
+ verify(email: string, code: string): Promise<Result<void, ErrorDetails>>;
8
+ };
9
+ };
10
+ social: {
11
+ start(provider: "Google" | "Facebook"): Promise<Result<void, ErrorDetails>>;
12
+ verify(code: string): Promise<Result<void, ErrorDetails>>;
13
+ };
14
+ isAuthenticated: Signal<boolean>;
15
+ getToken(): Promise<string | null>;
16
+ handleQueryParams(query: URLSearchParams): Promise<Result<void, ErrorDetails>>;
17
+ logout(): Promise<Result>;
18
+ };
19
+ export declare const LoginServiceContext: {
20
+ __context__: LoginService;
21
+ };
22
+ export { loginService, type LoginServiceDependencies, type ErrorFormatter, AuthenticationError, AuthenticationErrorReason, } from './loginService';
23
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/services/login/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,sBAAsB,CAAC;AAE9C,OAAO,EAAE,MAAM,EAAE,KAAK,YAAY,EAAE,MAAM,aAAa,CAAC;AAExD,KAAK,YAAY,GAAG;IAClB,YAAY,EAAE;QACZ,KAAK,EAAE;YACL,KAAK,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,IAAI,EAAE,YAAY,CAAC,CAAC,CAAC;YAC1D,MAAM,CAAC,KAAK,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,IAAI,EAAE,YAAY,CAAC,CAAC,CAAC;SAC1E,CAAC;KACH,CAAC;IAEF,MAAM,EAAE;QACN,KAAK,CAAC,QAAQ,EAAE,QAAQ,GAAG,UAAU,GAAG,OAAO,CAAC,MAAM,CAAC,IAAI,EAAE,YAAY,CAAC,CAAC,CAAC;QAC5E,MAAM,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,IAAI,EAAE,YAAY,CAAC,CAAC,CAAC;KAC3D,CAAC;IAEF,eAAe,EAAE,MAAM,CAAC,OAAO,CAAC,CAAC;IAEjC,QAAQ,IAAI,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC,CAAC;IAEnC,iBAAiB,CACf,KAAK,EAAE,eAAe,GACrB,OAAO,CAAC,MAAM,CAAC,IAAI,EAAE,YAAY,CAAC,CAAC,CAAC;IAEvC,MAAM,IAAI,OAAO,CAAC,MAAM,CAAC,CAAC;CAC3B,CAAC;AAEF,eAAO,MAAM,mBAAmB;;CACe,CAAC;AAEhD,OAAO,EACL,YAAY,EACZ,KAAK,wBAAwB,EAC7B,KAAK,cAAc,EACnB,mBAAmB,EACnB,yBAAyB,GAC1B,MAAM,gBAAgB,CAAC"}