@embedpdf/plugin-ui 1.4.1 → 2.0.0-next.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.
- package/dist/index.cjs +1 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +1313 -655
- package/dist/index.js.map +1 -1
- package/dist/lib/actions.d.ts +110 -74
- package/dist/lib/index.d.ts +8 -7
- package/dist/lib/reducer.d.ts +5 -5
- package/dist/lib/schema.d.ts +257 -0
- package/dist/lib/selectors.d.ts +16 -0
- package/dist/lib/types.d.ts +185 -202
- package/dist/lib/ui-plugin.d.ts +66 -18
- package/dist/lib/utils/consts.d.ts +25 -0
- package/dist/lib/utils/index.d.ts +5 -0
- package/dist/lib/utils/responsive-utils.d.ts +10 -0
- package/dist/lib/utils/schema-merger.d.ts +15 -0
- package/dist/lib/utils/stylesheet-generator.d.ts +40 -0
- package/dist/lib/utils/ui-props.d.ts +14 -0
- package/dist/preact/adapter.d.ts +4 -2
- package/dist/preact/index.cjs +1 -1
- package/dist/preact/index.cjs.map +1 -1
- package/dist/preact/index.js +450 -49
- package/dist/preact/index.js.map +1 -1
- package/dist/preact/utils.d.ts +1 -0
- package/dist/react/adapter.d.ts +2 -2
- package/dist/react/index.cjs +1 -1
- package/dist/react/index.cjs.map +1 -1
- package/dist/react/index.js +449 -48
- package/dist/react/index.js.map +1 -1
- package/dist/react/utils.d.ts +1 -0
- package/dist/shared/auto-menu-renderer.d.ts +13 -0
- package/dist/shared/hooks/index.d.ts +4 -0
- package/dist/shared/hooks/use-item-renderer.d.ts +14 -0
- package/dist/shared/hooks/use-register-anchor.d.ts +17 -0
- package/dist/shared/hooks/use-schema-renderer.d.ts +61 -0
- package/dist/shared/hooks/use-selection-menu.d.ts +11 -0
- package/dist/shared/hooks/use-ui.d.ts +13 -5
- package/dist/shared/index.d.ts +4 -1
- package/dist/shared/provider.d.ts +68 -0
- package/dist/shared/registries/anchor-registry.d.ts +16 -0
- package/dist/shared/registries/component-registry.d.ts +20 -0
- package/dist/shared/registries/index.d.ts +3 -0
- package/dist/shared/registries/renderers-registry.d.ts +8 -0
- package/dist/shared/root.d.ts +12 -0
- package/dist/shared/types.d.ts +67 -0
- package/dist/shared-preact/auto-menu-renderer.d.ts +13 -0
- package/dist/shared-preact/hooks/index.d.ts +4 -0
- package/dist/shared-preact/hooks/use-item-renderer.d.ts +14 -0
- package/dist/shared-preact/hooks/use-register-anchor.d.ts +17 -0
- package/dist/shared-preact/hooks/use-schema-renderer.d.ts +61 -0
- package/dist/shared-preact/hooks/use-selection-menu.d.ts +11 -0
- package/dist/shared-preact/hooks/use-ui.d.ts +13 -5
- package/dist/shared-preact/index.d.ts +4 -1
- package/dist/shared-preact/provider.d.ts +68 -0
- package/dist/shared-preact/registries/anchor-registry.d.ts +16 -0
- package/dist/shared-preact/registries/component-registry.d.ts +20 -0
- package/dist/shared-preact/registries/index.d.ts +3 -0
- package/dist/shared-preact/registries/renderers-registry.d.ts +8 -0
- package/dist/shared-preact/root.d.ts +12 -0
- package/dist/shared-preact/types.d.ts +67 -0
- package/dist/shared-react/auto-menu-renderer.d.ts +13 -0
- package/dist/shared-react/hooks/index.d.ts +4 -0
- package/dist/shared-react/hooks/use-item-renderer.d.ts +14 -0
- package/dist/shared-react/hooks/use-register-anchor.d.ts +17 -0
- package/dist/shared-react/hooks/use-schema-renderer.d.ts +61 -0
- package/dist/shared-react/hooks/use-selection-menu.d.ts +11 -0
- package/dist/shared-react/hooks/use-ui.d.ts +13 -5
- package/dist/shared-react/index.d.ts +4 -1
- package/dist/shared-react/provider.d.ts +68 -0
- package/dist/shared-react/registries/anchor-registry.d.ts +16 -0
- package/dist/shared-react/registries/component-registry.d.ts +20 -0
- package/dist/shared-react/registries/index.d.ts +3 -0
- package/dist/shared-react/registries/renderers-registry.d.ts +8 -0
- package/dist/shared-react/root.d.ts +12 -0
- package/dist/shared-react/types.d.ts +67 -0
- package/dist/svelte/auto-menu-renderer.svelte.d.ts +15 -0
- package/dist/svelte/hooks/index.d.ts +5 -0
- package/dist/svelte/hooks/use-item-renderer.svelte.d.ts +24 -0
- package/dist/svelte/hooks/use-register-anchor.svelte.d.ts +18 -0
- package/dist/svelte/hooks/use-schema-renderer.svelte.d.ts +78 -0
- package/dist/svelte/hooks/use-selection-menu.svelte.d.ts +9 -0
- package/dist/svelte/hooks/use-ui.svelte.d.ts +34 -0
- package/dist/svelte/index.cjs +2 -0
- package/dist/svelte/index.cjs.map +1 -0
- package/dist/svelte/index.d.ts +6 -0
- package/dist/svelte/index.js +553 -0
- package/dist/svelte/index.js.map +1 -0
- package/dist/svelte/provider.svelte.d.ts +33 -0
- package/dist/svelte/registries/anchor-registry.svelte.d.ts +14 -0
- package/dist/svelte/registries/component-registry.svelte.d.ts +17 -0
- package/dist/svelte/registries/index.d.ts +3 -0
- package/dist/svelte/registries/renderers-registry.svelte.d.ts +3 -0
- package/dist/svelte/root.svelte.d.ts +8 -0
- package/dist/svelte/types.d.ts +67 -0
- package/dist/vue/auto-menu-renderer.vue.d.ts +15 -0
- package/dist/vue/hooks/index.d.ts +5 -0
- package/dist/vue/hooks/use-item-renderer.d.ts +16 -0
- package/dist/vue/hooks/use-register-anchor.d.ts +19 -0
- package/dist/vue/hooks/use-schema-renderer.d.ts +63 -0
- package/dist/vue/hooks/use-selection-menu.d.ts +28 -0
- package/dist/vue/hooks/use-ui.d.ts +940 -0
- package/dist/vue/index.cjs +2 -0
- package/dist/vue/index.cjs.map +1 -0
- package/dist/vue/index.d.ts +6 -0
- package/dist/vue/index.js +544 -0
- package/dist/vue/index.js.map +1 -0
- package/dist/vue/provider.vue.d.ts +43 -0
- package/dist/vue/registries/anchor-registry.d.ts +14 -0
- package/dist/vue/registries/component-registry.d.ts +17 -0
- package/dist/vue/registries/index.d.ts +3 -0
- package/dist/vue/registries/renderers-registry.d.ts +3 -0
- package/dist/vue/root.vue.d.ts +13 -0
- package/dist/vue/types.d.ts +67 -0
- package/package.json +32 -9
- package/dist/lib/menu/menu-manager.d.ts +0 -98
- package/dist/lib/menu/types.d.ts +0 -91
- package/dist/lib/menu/utils.d.ts +0 -6
- package/dist/lib/ui-component.d.ts +0 -30
- package/dist/lib/utils.d.ts +0 -33
- package/dist/shared/components/component-wrapper.d.ts +0 -5
- package/dist/shared/components/index.d.ts +0 -1
- package/dist/shared/components/plugin-ui-provider.d.ts +0 -37
- package/dist/shared-preact/components/component-wrapper.d.ts +0 -5
- package/dist/shared-preact/components/index.d.ts +0 -1
- package/dist/shared-preact/components/plugin-ui-provider.d.ts +0 -37
- package/dist/shared-react/components/component-wrapper.d.ts +0 -5
- package/dist/shared-react/components/index.d.ts +0 -1
- package/dist/shared-react/components/plugin-ui-provider.d.ts +0 -37
package/dist/react/index.js
CHANGED
|
@@ -1,64 +1,465 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import { UIPlugin } from "@embedpdf/plugin-ui";
|
|
1
|
+
import { useCapability, usePlugin } from "@embedpdf/core/react";
|
|
2
|
+
import { UIPlugin, UI_SELECTORS, UI_ATTRIBUTES } from "@embedpdf/plugin-ui";
|
|
4
3
|
export * from "@embedpdf/plugin-ui";
|
|
5
|
-
import { useState, useEffect } from "react";
|
|
6
|
-
|
|
4
|
+
import { useState, useEffect, createContext, useRef, useCallback, useContext, useMemo } from "react";
|
|
5
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
7
6
|
const useUICapability = () => useCapability(UIPlugin.id);
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
const [_, forceUpdate] = useState({});
|
|
7
|
+
const useUIPlugin = () => usePlugin(UIPlugin.id);
|
|
8
|
+
const useUIState = (documentId) => {
|
|
9
|
+
const { provides } = useUICapability();
|
|
10
|
+
const [state, setState] = useState(null);
|
|
13
11
|
useEffect(() => {
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
12
|
+
if (!provides) return;
|
|
13
|
+
const scope = provides.forDocument(documentId);
|
|
14
|
+
setState(scope.getState());
|
|
15
|
+
const unsubToolbar = scope.onToolbarChanged(() => setState(scope.getState()));
|
|
16
|
+
const unsubPanel = scope.onPanelChanged(() => setState(scope.getState()));
|
|
17
|
+
const unsubModal = scope.onModalChanged(() => setState(scope.getState()));
|
|
18
|
+
const unsubMenu = scope.onMenuChanged(() => setState(scope.getState()));
|
|
19
|
+
return () => {
|
|
20
|
+
unsubToolbar();
|
|
21
|
+
unsubPanel();
|
|
22
|
+
unsubModal();
|
|
23
|
+
unsubMenu();
|
|
24
|
+
};
|
|
25
|
+
}, [provides, documentId]);
|
|
26
|
+
return state;
|
|
27
|
+
};
|
|
28
|
+
const useUISchema = () => {
|
|
29
|
+
const { provides } = useUICapability();
|
|
30
|
+
return (provides == null ? void 0 : provides.getSchema()) ?? null;
|
|
31
|
+
};
|
|
32
|
+
const AnchorRegistryContext = createContext(null);
|
|
33
|
+
function AnchorRegistryProvider({ children }) {
|
|
34
|
+
const anchorsRef = useRef(/* @__PURE__ */ new Map());
|
|
35
|
+
const registry = {
|
|
36
|
+
register: useCallback((documentId, itemId, element) => {
|
|
37
|
+
const key = `${documentId}:${itemId}`;
|
|
38
|
+
anchorsRef.current.set(key, element);
|
|
39
|
+
}, []),
|
|
40
|
+
unregister: useCallback((documentId, itemId) => {
|
|
41
|
+
const key = `${documentId}:${itemId}`;
|
|
42
|
+
anchorsRef.current.delete(key);
|
|
43
|
+
}, []),
|
|
44
|
+
getAnchor: useCallback((documentId, itemId) => {
|
|
45
|
+
const key = `${documentId}:${itemId}`;
|
|
46
|
+
return anchorsRef.current.get(key) || null;
|
|
47
|
+
}, [])
|
|
48
|
+
};
|
|
49
|
+
return /* @__PURE__ */ jsx(AnchorRegistryContext.Provider, { value: registry, children });
|
|
50
|
+
}
|
|
51
|
+
function useAnchorRegistry() {
|
|
52
|
+
const context = useContext(AnchorRegistryContext);
|
|
53
|
+
if (!context) {
|
|
54
|
+
throw new Error("useAnchorRegistry must be used within UIProvider");
|
|
24
55
|
}
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
56
|
+
return context;
|
|
57
|
+
}
|
|
58
|
+
function useRegisterAnchor(documentId, itemId) {
|
|
59
|
+
const registry = useAnchorRegistry();
|
|
60
|
+
const elementRef = useRef(null);
|
|
61
|
+
const documentIdRef = useRef(documentId);
|
|
62
|
+
const itemIdRef = useRef(itemId);
|
|
63
|
+
documentIdRef.current = documentId;
|
|
64
|
+
itemIdRef.current = itemId;
|
|
65
|
+
return useCallback(
|
|
66
|
+
(element) => {
|
|
67
|
+
const previousElement = elementRef.current;
|
|
68
|
+
elementRef.current = element;
|
|
69
|
+
if (element) {
|
|
70
|
+
if (element !== previousElement) {
|
|
71
|
+
registry.register(documentIdRef.current, itemIdRef.current, element);
|
|
72
|
+
}
|
|
73
|
+
} else if (previousElement) {
|
|
74
|
+
registry.unregister(documentIdRef.current, itemIdRef.current);
|
|
75
|
+
}
|
|
76
|
+
},
|
|
77
|
+
[registry]
|
|
78
|
+
// Only depend on registry!
|
|
79
|
+
);
|
|
80
|
+
}
|
|
81
|
+
const ComponentRegistryContext = createContext(null);
|
|
82
|
+
function ComponentRegistryProvider({
|
|
83
|
+
children,
|
|
84
|
+
initialComponents = {}
|
|
85
|
+
}) {
|
|
86
|
+
const componentsRef = useRef(
|
|
87
|
+
new Map(Object.entries(initialComponents))
|
|
88
|
+
);
|
|
89
|
+
const registry = {
|
|
90
|
+
register: useCallback((id, component) => {
|
|
91
|
+
componentsRef.current.set(id, component);
|
|
92
|
+
}, []),
|
|
93
|
+
unregister: useCallback((id) => {
|
|
94
|
+
componentsRef.current.delete(id);
|
|
95
|
+
}, []),
|
|
96
|
+
get: useCallback((id) => {
|
|
97
|
+
return componentsRef.current.get(id);
|
|
98
|
+
}, []),
|
|
99
|
+
has: useCallback((id) => {
|
|
100
|
+
return componentsRef.current.has(id);
|
|
101
|
+
}, []),
|
|
102
|
+
getRegisteredIds: useCallback(() => {
|
|
103
|
+
return Array.from(componentsRef.current.keys());
|
|
104
|
+
}, [])
|
|
105
|
+
};
|
|
106
|
+
return /* @__PURE__ */ jsx(ComponentRegistryContext.Provider, { value: registry, children });
|
|
107
|
+
}
|
|
108
|
+
function useComponentRegistry() {
|
|
109
|
+
const context = useContext(ComponentRegistryContext);
|
|
110
|
+
if (!context) {
|
|
111
|
+
throw new Error("useComponentRegistry must be used within UIProvider");
|
|
32
112
|
}
|
|
33
|
-
return
|
|
113
|
+
return context;
|
|
34
114
|
}
|
|
35
|
-
function
|
|
36
|
-
const
|
|
37
|
-
|
|
38
|
-
|
|
115
|
+
function useItemRenderer() {
|
|
116
|
+
const componentRegistry = useComponentRegistry();
|
|
117
|
+
return {
|
|
118
|
+
/**
|
|
119
|
+
* Render a custom component by ID
|
|
120
|
+
*
|
|
121
|
+
* @param componentId - Component ID from schema
|
|
122
|
+
* @param documentId - Document ID
|
|
123
|
+
* @param props - Additional props to pass to component
|
|
124
|
+
* @returns Rendered component or null if not found
|
|
125
|
+
*/
|
|
126
|
+
renderCustomComponent: (componentId, documentId, props) => {
|
|
127
|
+
const Component = componentRegistry.get(componentId);
|
|
128
|
+
if (!Component) {
|
|
129
|
+
console.error(`Component "${componentId}" not found in registry`);
|
|
130
|
+
return null;
|
|
131
|
+
}
|
|
132
|
+
return /* @__PURE__ */ jsx(Component, { documentId, ...props || {} });
|
|
133
|
+
}
|
|
39
134
|
};
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
135
|
+
}
|
|
136
|
+
const RenderersContext = createContext(null);
|
|
137
|
+
function RenderersProvider({ children, renderers }) {
|
|
138
|
+
return /* @__PURE__ */ jsx(RenderersContext.Provider, { value: renderers, children });
|
|
139
|
+
}
|
|
140
|
+
function useRenderers() {
|
|
141
|
+
const context = useContext(RenderersContext);
|
|
142
|
+
if (!context) {
|
|
143
|
+
throw new Error("useRenderers must be used within UIProvider");
|
|
144
|
+
}
|
|
145
|
+
return context;
|
|
146
|
+
}
|
|
147
|
+
function useSchemaRenderer(documentId) {
|
|
148
|
+
const renderers = useRenderers();
|
|
149
|
+
const { provides } = useUICapability();
|
|
150
|
+
const schema = provides == null ? void 0 : provides.getSchema();
|
|
151
|
+
const uiState = useUIState(documentId);
|
|
152
|
+
return {
|
|
153
|
+
/**
|
|
154
|
+
* Render a toolbar by placement and slot
|
|
155
|
+
*
|
|
156
|
+
* Always renders with isOpen state when toolbar exists in slot.
|
|
157
|
+
*
|
|
158
|
+
* @param placement - 'top' | 'bottom' | 'left' | 'right'
|
|
159
|
+
* @param slot - Slot name (e.g. 'main', 'secondary')
|
|
160
|
+
*
|
|
161
|
+
* @example
|
|
162
|
+
* ```tsx
|
|
163
|
+
* {renderToolbar('top', 'main')}
|
|
164
|
+
* {renderToolbar('top', 'secondary')}
|
|
165
|
+
* ```
|
|
166
|
+
*/
|
|
167
|
+
renderToolbar: (placement, slot) => {
|
|
168
|
+
if (!schema || !provides || !uiState) return null;
|
|
169
|
+
const slotKey = `${placement}-${slot}`;
|
|
170
|
+
const toolbarSlot = uiState.activeToolbars[slotKey];
|
|
171
|
+
if (!toolbarSlot) return null;
|
|
172
|
+
const toolbarSchema = schema.toolbars[toolbarSlot.toolbarId];
|
|
173
|
+
if (!toolbarSchema) {
|
|
174
|
+
console.warn(`Toolbar "${toolbarSlot.toolbarId}" not found in schema`);
|
|
175
|
+
return null;
|
|
176
|
+
}
|
|
177
|
+
const isClosable = !toolbarSchema.permanent;
|
|
178
|
+
const handleClose = isClosable ? () => {
|
|
179
|
+
provides.forDocument(documentId).closeToolbarSlot(placement, slot);
|
|
180
|
+
} : void 0;
|
|
181
|
+
const ToolbarRenderer = renderers.toolbar;
|
|
182
|
+
return /* @__PURE__ */ jsx(
|
|
183
|
+
ToolbarRenderer,
|
|
184
|
+
{
|
|
185
|
+
schema: toolbarSchema,
|
|
186
|
+
documentId,
|
|
187
|
+
isOpen: toolbarSlot.isOpen,
|
|
188
|
+
onClose: handleClose
|
|
189
|
+
},
|
|
190
|
+
toolbarSlot.toolbarId
|
|
191
|
+
);
|
|
192
|
+
},
|
|
193
|
+
/**
|
|
194
|
+
* Render a panel by placement and slot
|
|
195
|
+
*
|
|
196
|
+
* ALWAYS renders (when panel exists in slot) with isOpen state.
|
|
197
|
+
* Your renderer controls whether to display or animate.
|
|
198
|
+
*
|
|
199
|
+
* @param placement - 'left' | 'right' | 'top' | 'bottom'
|
|
200
|
+
* @param slot - Slot name (e.g. 'main', 'secondary', 'inspector')
|
|
201
|
+
*
|
|
202
|
+
* @example
|
|
203
|
+
* ```tsx
|
|
204
|
+
* {renderPanel('left', 'main')}
|
|
205
|
+
* {renderPanel('right', 'main')}
|
|
206
|
+
* ```
|
|
207
|
+
*/
|
|
208
|
+
renderPanel: (placement, slot) => {
|
|
209
|
+
if (!schema || !provides || !uiState) return null;
|
|
210
|
+
const slotKey = `${placement}-${slot}`;
|
|
211
|
+
const panelSlot = uiState.activePanels[slotKey];
|
|
212
|
+
if (!panelSlot) return null;
|
|
213
|
+
const panelSchema = schema.panels[panelSlot.panelId];
|
|
214
|
+
if (!panelSchema) {
|
|
215
|
+
console.warn(`Panel "${panelSlot.panelId}" not found in schema`);
|
|
216
|
+
return null;
|
|
217
|
+
}
|
|
218
|
+
const handleClose = () => {
|
|
219
|
+
provides.forDocument(documentId).closePanelSlot(placement, slot);
|
|
220
|
+
};
|
|
221
|
+
const PanelRenderer = renderers.panel;
|
|
222
|
+
return /* @__PURE__ */ jsx(
|
|
223
|
+
PanelRenderer,
|
|
224
|
+
{
|
|
225
|
+
schema: panelSchema,
|
|
226
|
+
documentId,
|
|
227
|
+
isOpen: panelSlot.isOpen,
|
|
228
|
+
onClose: handleClose
|
|
229
|
+
},
|
|
230
|
+
panelSlot.panelId
|
|
231
|
+
);
|
|
232
|
+
},
|
|
233
|
+
/**
|
|
234
|
+
* Helper: Get all active toolbars for this document
|
|
235
|
+
* Useful for batch rendering or debugging
|
|
236
|
+
*/
|
|
237
|
+
getActiveToolbars: () => {
|
|
238
|
+
if (!uiState) return [];
|
|
239
|
+
return Object.entries(uiState.activeToolbars).map(([slotKey, toolbarSlot]) => {
|
|
240
|
+
const [placement, slot] = slotKey.split("-");
|
|
241
|
+
return {
|
|
242
|
+
placement,
|
|
243
|
+
slot,
|
|
244
|
+
toolbarId: toolbarSlot.toolbarId,
|
|
245
|
+
isOpen: toolbarSlot.isOpen
|
|
246
|
+
};
|
|
247
|
+
});
|
|
46
248
|
},
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
249
|
+
/**
|
|
250
|
+
* Helper: Get all active panels for this document
|
|
251
|
+
* Useful for batch rendering or debugging
|
|
252
|
+
*/
|
|
253
|
+
getActivePanels: () => {
|
|
254
|
+
if (!uiState) return [];
|
|
255
|
+
return Object.entries(uiState.activePanels).map(([slotKey, panelSlot]) => {
|
|
256
|
+
const [placement, slot] = slotKey.split("-");
|
|
257
|
+
return {
|
|
258
|
+
placement,
|
|
259
|
+
slot,
|
|
260
|
+
panelId: panelSlot.panelId,
|
|
261
|
+
isOpen: panelSlot.isOpen
|
|
262
|
+
};
|
|
263
|
+
});
|
|
264
|
+
}
|
|
265
|
+
};
|
|
266
|
+
}
|
|
267
|
+
function useSelectionMenu(menuId, documentId) {
|
|
268
|
+
var _a;
|
|
269
|
+
const { provides } = useUICapability();
|
|
270
|
+
const renderers = useRenderers();
|
|
271
|
+
const renderFn = useCallback(
|
|
272
|
+
(props) => {
|
|
273
|
+
var _a2;
|
|
274
|
+
const schema2 = provides == null ? void 0 : provides.getSchema();
|
|
275
|
+
const menuSchema = (_a2 = schema2 == null ? void 0 : schema2.selectionMenus) == null ? void 0 : _a2[menuId];
|
|
276
|
+
if (!menuSchema) {
|
|
277
|
+
return null;
|
|
278
|
+
}
|
|
279
|
+
if (!props.selected) {
|
|
280
|
+
return null;
|
|
281
|
+
}
|
|
282
|
+
const SelectionMenuRenderer = renderers.selectionMenu;
|
|
283
|
+
return /* @__PURE__ */ jsx(SelectionMenuRenderer, { schema: menuSchema, documentId, props });
|
|
50
284
|
},
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
285
|
+
[provides, renderers, menuId, documentId]
|
|
286
|
+
);
|
|
287
|
+
const schema = provides == null ? void 0 : provides.getSchema();
|
|
288
|
+
if (!((_a = schema == null ? void 0 : schema.selectionMenus) == null ? void 0 : _a[menuId])) {
|
|
289
|
+
return void 0;
|
|
290
|
+
}
|
|
291
|
+
return renderFn;
|
|
292
|
+
}
|
|
293
|
+
function AutoMenuRenderer({ container, documentId }) {
|
|
294
|
+
const uiState = useUIState(documentId);
|
|
295
|
+
const { provides } = useUICapability();
|
|
296
|
+
const anchorRegistry = useAnchorRegistry();
|
|
297
|
+
const renderers = useRenderers();
|
|
298
|
+
const [activeMenu, setActiveMenu] = useState(null);
|
|
299
|
+
const openMenus = (uiState == null ? void 0 : uiState.openMenus) || {};
|
|
300
|
+
const schema = provides == null ? void 0 : provides.getSchema();
|
|
301
|
+
useEffect(() => {
|
|
302
|
+
const openMenuIds = Object.keys(openMenus);
|
|
303
|
+
if (openMenuIds.length > 0) {
|
|
304
|
+
const menuId = openMenuIds[0];
|
|
305
|
+
if (!menuId) {
|
|
306
|
+
setActiveMenu(null);
|
|
307
|
+
return;
|
|
308
|
+
}
|
|
309
|
+
const menuState = openMenus[menuId];
|
|
310
|
+
if (menuState && menuState.triggeredByItemId) {
|
|
311
|
+
const anchor = anchorRegistry.getAnchor(documentId, menuState.triggeredByItemId);
|
|
312
|
+
setActiveMenu({ menuId, anchorEl: anchor });
|
|
313
|
+
} else {
|
|
314
|
+
setActiveMenu(null);
|
|
315
|
+
}
|
|
316
|
+
} else {
|
|
317
|
+
setActiveMenu(null);
|
|
318
|
+
}
|
|
319
|
+
}, [openMenus, anchorRegistry, documentId]);
|
|
320
|
+
const handleClose = () => {
|
|
321
|
+
if (activeMenu) {
|
|
322
|
+
provides == null ? void 0 : provides.forDocument(documentId).closeMenu(activeMenu.menuId);
|
|
323
|
+
}
|
|
324
|
+
};
|
|
325
|
+
if (!activeMenu || !schema) {
|
|
326
|
+
return null;
|
|
327
|
+
}
|
|
328
|
+
const menuSchema = schema.menus[activeMenu.menuId];
|
|
329
|
+
if (!menuSchema) {
|
|
330
|
+
console.warn(`Menu "${activeMenu.menuId}" not found in schema`);
|
|
331
|
+
return null;
|
|
332
|
+
}
|
|
333
|
+
const MenuRenderer = renderers.menu;
|
|
334
|
+
return /* @__PURE__ */ jsx(
|
|
335
|
+
MenuRenderer,
|
|
336
|
+
{
|
|
337
|
+
schema: menuSchema,
|
|
338
|
+
documentId,
|
|
339
|
+
anchorEl: activeMenu.anchorEl,
|
|
340
|
+
onClose: handleClose,
|
|
341
|
+
container
|
|
342
|
+
}
|
|
343
|
+
);
|
|
344
|
+
}
|
|
345
|
+
function getStyleTarget(element) {
|
|
346
|
+
const root = element.getRootNode();
|
|
347
|
+
if (root instanceof ShadowRoot) {
|
|
348
|
+
return root;
|
|
349
|
+
}
|
|
350
|
+
return document.head;
|
|
351
|
+
}
|
|
352
|
+
function UIRoot({ children, ...restProps }) {
|
|
353
|
+
const { plugin } = useUIPlugin();
|
|
354
|
+
const { provides } = useUICapability();
|
|
355
|
+
const [disabledCategories, setDisabledCategories] = useState([]);
|
|
356
|
+
const styleElRef = useRef(null);
|
|
357
|
+
const styleTargetRef = useRef(null);
|
|
358
|
+
const previousElementRef = useRef(null);
|
|
359
|
+
const rootRefCallback = useCallback(
|
|
360
|
+
(element) => {
|
|
361
|
+
const previousElement = previousElementRef.current;
|
|
362
|
+
previousElementRef.current = element;
|
|
363
|
+
if (!element) {
|
|
364
|
+
return;
|
|
365
|
+
}
|
|
366
|
+
if (element !== previousElement && plugin) {
|
|
367
|
+
const styleTarget = getStyleTarget(element);
|
|
368
|
+
styleTargetRef.current = styleTarget;
|
|
369
|
+
const existingStyle = styleTarget.querySelector(
|
|
370
|
+
UI_SELECTORS.STYLES
|
|
371
|
+
);
|
|
372
|
+
if (existingStyle) {
|
|
373
|
+
styleElRef.current = existingStyle;
|
|
374
|
+
existingStyle.textContent = plugin.getStylesheet();
|
|
375
|
+
return;
|
|
376
|
+
}
|
|
377
|
+
const stylesheet = plugin.getStylesheet();
|
|
378
|
+
const styleEl = document.createElement("style");
|
|
379
|
+
styleEl.setAttribute(UI_ATTRIBUTES.STYLES, "");
|
|
380
|
+
styleEl.textContent = stylesheet;
|
|
381
|
+
if (styleTarget instanceof ShadowRoot) {
|
|
382
|
+
styleTarget.insertBefore(styleEl, styleTarget.firstChild);
|
|
383
|
+
} else {
|
|
384
|
+
styleTarget.appendChild(styleEl);
|
|
385
|
+
}
|
|
386
|
+
styleElRef.current = styleEl;
|
|
387
|
+
}
|
|
54
388
|
},
|
|
55
|
-
|
|
389
|
+
[plugin]
|
|
390
|
+
);
|
|
391
|
+
useEffect(() => {
|
|
392
|
+
return () => {
|
|
393
|
+
var _a;
|
|
394
|
+
if (((_a = styleElRef.current) == null ? void 0 : _a.parentNode) && !previousElementRef.current) {
|
|
395
|
+
styleElRef.current.remove();
|
|
396
|
+
}
|
|
397
|
+
styleElRef.current = null;
|
|
398
|
+
styleTargetRef.current = null;
|
|
399
|
+
};
|
|
400
|
+
}, []);
|
|
401
|
+
useEffect(() => {
|
|
402
|
+
if (!plugin) return;
|
|
403
|
+
return plugin.onStylesheetInvalidated(() => {
|
|
404
|
+
if (styleElRef.current) {
|
|
405
|
+
styleElRef.current.textContent = plugin.getStylesheet();
|
|
406
|
+
}
|
|
407
|
+
});
|
|
408
|
+
}, [plugin]);
|
|
409
|
+
useEffect(() => {
|
|
410
|
+
if (!provides) return;
|
|
411
|
+
setDisabledCategories(provides.getDisabledCategories());
|
|
412
|
+
return provides.onCategoryChanged(({ disabledCategories: disabledCategories2 }) => {
|
|
413
|
+
setDisabledCategories(disabledCategories2);
|
|
414
|
+
});
|
|
415
|
+
}, [provides]);
|
|
416
|
+
const disabledCategoriesAttr = useMemo(
|
|
417
|
+
() => disabledCategories.length > 0 ? disabledCategories.join(" ") : void 0,
|
|
418
|
+
[disabledCategories]
|
|
419
|
+
);
|
|
420
|
+
const rootProps = {
|
|
421
|
+
[UI_ATTRIBUTES.ROOT]: "",
|
|
422
|
+
[UI_ATTRIBUTES.DISABLED_CATEGORIES]: disabledCategoriesAttr
|
|
56
423
|
};
|
|
57
|
-
return
|
|
424
|
+
return /* @__PURE__ */ jsx(
|
|
425
|
+
"div",
|
|
426
|
+
{
|
|
427
|
+
ref: rootRefCallback,
|
|
428
|
+
...rootProps,
|
|
429
|
+
...restProps,
|
|
430
|
+
style: { containerType: "inline-size", ...restProps.style },
|
|
431
|
+
children
|
|
432
|
+
}
|
|
433
|
+
);
|
|
434
|
+
}
|
|
435
|
+
function UIProvider({
|
|
436
|
+
children,
|
|
437
|
+
documentId,
|
|
438
|
+
components = {},
|
|
439
|
+
renderers,
|
|
440
|
+
menuContainer,
|
|
441
|
+
...restProps
|
|
442
|
+
}) {
|
|
443
|
+
return /* @__PURE__ */ jsx(AnchorRegistryProvider, { children: /* @__PURE__ */ jsx(ComponentRegistryProvider, { initialComponents: components, children: /* @__PURE__ */ jsx(RenderersProvider, { renderers, children: /* @__PURE__ */ jsxs(UIRoot, { ...restProps, children: [
|
|
444
|
+
children,
|
|
445
|
+
/* @__PURE__ */ jsx(AutoMenuRenderer, { documentId, container: menuContainer })
|
|
446
|
+
] }) }) }) });
|
|
58
447
|
}
|
|
59
448
|
export {
|
|
60
|
-
|
|
449
|
+
AnchorRegistryProvider,
|
|
450
|
+
ComponentRegistryProvider,
|
|
451
|
+
RenderersProvider,
|
|
452
|
+
UIProvider,
|
|
453
|
+
useAnchorRegistry,
|
|
454
|
+
useComponentRegistry,
|
|
455
|
+
useItemRenderer,
|
|
456
|
+
useRegisterAnchor,
|
|
457
|
+
useRenderers,
|
|
458
|
+
useSchemaRenderer,
|
|
459
|
+
useSelectionMenu,
|
|
61
460
|
useUICapability,
|
|
62
|
-
useUIPlugin
|
|
461
|
+
useUIPlugin,
|
|
462
|
+
useUISchema,
|
|
463
|
+
useUIState
|
|
63
464
|
};
|
|
64
465
|
//# sourceMappingURL=index.js.map
|
package/dist/react/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sources":["../../src/shared/hooks/use-ui.ts","../../src/shared/components/component-wrapper.tsx","../../src/shared/components/plugin-ui-provider.tsx"],"sourcesContent":["import { useCapability, usePlugin } from '@embedpdf/core/@framework';\nimport { UIPlugin } from '@embedpdf/plugin-ui';\n\nexport const useUIPlugin = () => usePlugin<UIPlugin>(UIPlugin.id);\nexport const useUICapability = () => useCapability<UIPlugin>(UIPlugin.id);\n","import { useState, useEffect } from '@framework';\nimport { childrenFunctionOptions, UIComponent } from '@embedpdf/plugin-ui';\n\nexport function ComponentWrapper({\n component,\n parentContext = {},\n}: {\n component: UIComponent<any>;\n parentContext?: Record<string, any>;\n}) {\n const [_, forceUpdate] = useState({});\n\n useEffect(() => {\n const updateCallback = () => forceUpdate({});\n // If the component had updated before we attach the listener, force one re-render\n if (component.onUpdate(updateCallback)) {\n forceUpdate({});\n }\n return () => component.offUpdate(updateCallback);\n }, [component]);\n\n // Merge contexts from parent + the UIComponent's own child context\n const childContext = component.getChildContext(parentContext);\n\n // Instead of returning `component.render()`, we do the following:\n\n // 1) Look up the \"renderer function\" for this component type\n const renderer = component.getRenderer(); // We'll define getRenderer() below\n\n if (!renderer) {\n throw new Error(`No renderer for type: ${component.getRenderType}`);\n }\n\n // 2) Build a function that returns child wrappers\n function renderChildrenFn(options?: childrenFunctionOptions) {\n const merged = options?.context ? { ...childContext, ...options.context } : childContext;\n return component\n .getChildren()\n .filter(({ id }) => {\n // If filter function is provided, use it to determine if we should include this child\n return !options?.filter || options.filter(id);\n })\n .map(({ component: child, id, className }) =>\n className ? (\n <div className={className}>\n <ComponentWrapper key={id} component={child} parentContext={merged} />\n </div>\n ) : (\n <ComponentWrapper key={id} component={child} parentContext={merged} />\n ),\n );\n }\n\n // 3) Finally call the renderer with (props, childrenFn, context)\n return renderer(component.props, renderChildrenFn, childContext);\n}\n","import { ReactNode } from '@framework';\nimport { useUICapability } from '../hooks';\nimport { ComponentWrapper } from './component-wrapper';\nimport { UIComponent } from '@embedpdf/plugin-ui';\n\n/**\n * Interface for UI components organized by type/location\n */\nexport interface UIComponentsMap {\n headers: {\n top: ReactNode[];\n bottom: ReactNode[];\n left: ReactNode[];\n right: ReactNode[];\n };\n panels: {\n left: ReactNode[];\n right: ReactNode[];\n };\n floating: {\n insideScroller: ReactNode[];\n outsideScroller: ReactNode[];\n };\n commandMenu: ReactNode | null;\n}\n\n/**\n * Props for the PluginUIProvider\n */\nexport interface PluginUIProviderProps {\n /**\n * Render function that receives UI components\n */\n children: (components: UIComponentsMap) => ReactNode;\n}\n\n/**\n * PluginUIProvider collects all components from the UI plugin system\n * and provides them to a render function without imposing any structure.\n *\n * It uses the render props pattern for maximum flexibility.\n */\nexport function PluginUIProvider({ children }: PluginUIProviderProps) {\n const { provides: uiProvides } = useUICapability();\n\n // Helper function to wrap UIComponents as JSX elements\n const wrapComponents = (components: UIComponent<any>[]): ReactNode[] => {\n return components.map((component) => (\n <ComponentWrapper key={component.props.id} component={component} />\n ));\n };\n\n // Collect and wrap all components from UI plugin\n const componentMap: UIComponentsMap = {\n headers: {\n top: wrapComponents(uiProvides?.getHeadersByPlacement('top') || []),\n bottom: wrapComponents(uiProvides?.getHeadersByPlacement('bottom') || []),\n left: wrapComponents(uiProvides?.getHeadersByPlacement('left') || []),\n right: wrapComponents(uiProvides?.getHeadersByPlacement('right') || []),\n },\n panels: {\n left: wrapComponents(uiProvides?.getPanelsByLocation('left') || []),\n right: wrapComponents(uiProvides?.getPanelsByLocation('right') || []),\n },\n floating: {\n insideScroller: wrapComponents(uiProvides?.getFloatingComponents('inside') || []),\n outsideScroller: wrapComponents(uiProvides?.getFloatingComponents('outside') || []),\n },\n commandMenu: uiProvides?.getCommandMenu() ? (\n <ComponentWrapper component={uiProvides.getCommandMenu()!} />\n ) : null,\n };\n\n // Let the consumer determine the layout structure through the render prop\n return children(componentMap);\n}\n"],"names":[],"mappings":";;;;;AAGO,MAAM,cAAc,MAAM,UAAoB,SAAS,EAAE;AACzD,MAAM,kBAAkB,MAAM,cAAwB,SAAS,EAAE;ACDjE,SAAS,iBAAiB;AAAA,EAC/B;AAAA,EACA,gBAAgB,CAAA;AAClB,GAGG;AACD,QAAM,CAAC,GAAG,WAAW,IAAI,SAAS,CAAA,CAAE;AAEpC,YAAU,MAAM;AACd,UAAM,iBAAiB,MAAM,YAAY,EAAE;AAEvC,QAAA,UAAU,SAAS,cAAc,GAAG;AACtC,kBAAY,CAAA,CAAE;AAAA,IAAA;AAET,WAAA,MAAM,UAAU,UAAU,cAAc;AAAA,EAAA,GAC9C,CAAC,SAAS,CAAC;AAGR,QAAA,eAAe,UAAU,gBAAgB,aAAa;AAKtD,QAAA,WAAW,UAAU,YAAY;AAEvC,MAAI,CAAC,UAAU;AACb,UAAM,IAAI,MAAM,yBAAyB,UAAU,aAAa,EAAE;AAAA,EAAA;AAIpE,WAAS,iBAAiB,SAAmC;AACrD,UAAA,UAAS,mCAAS,WAAU,EAAE,GAAG,cAAc,GAAG,QAAQ,QAAA,IAAY;AAC5E,WAAO,UACJ,YAAY,EACZ,OAAO,CAAC,EAAE,SAAS;AAElB,aAAO,EAAC,mCAAS,WAAU,QAAQ,OAAO,EAAE;AAAA,IAC7C,CAAA,EACA;AAAA,MAAI,CAAC,EAAE,WAAW,OAAO,IAAI,UAAU,MACtC,YACE,oBAAC,OAAI,EAAA,WACH,UAAC,oBAAA,kBAAA,EAA0B,WAAW,OAAO,eAAe,OAArC,GAAA,EAA6C,EACtE,CAAA,IAEC,oBAAA,kBAAA,EAA0B,WAAW,OAAO,eAAe,OAAA,GAArC,EAA6C;AAAA,IAExE;AAAA,EAAA;AAIJ,SAAO,SAAS,UAAU,OAAO,kBAAkB,YAAY;AACjE;ACbgB,SAAA,iBAAiB,EAAE,YAAmC;AACpE,QAAM,EAAE,UAAU,WAAW,IAAI,gBAAgB;AAG3C,QAAA,iBAAiB,CAAC,eAAgD;AAC/D,WAAA,WAAW,IAAI,CAAC,cACrB,oBAAC,oBAA0C,aAApB,UAAU,MAAM,EAA0B,CAClE;AAAA,EACH;AAGA,QAAM,eAAgC;AAAA,IACpC,SAAS;AAAA,MACP,KAAK,gBAAe,yCAAY,sBAAsB,WAAU,CAAA,CAAE;AAAA,MAClE,QAAQ,gBAAe,yCAAY,sBAAsB,cAAa,CAAA,CAAE;AAAA,MACxE,MAAM,gBAAe,yCAAY,sBAAsB,YAAW,CAAA,CAAE;AAAA,MACpE,OAAO,gBAAe,yCAAY,sBAAsB,aAAY,CAAE,CAAA;AAAA,IACxE;AAAA,IACA,QAAQ;AAAA,MACN,MAAM,gBAAe,yCAAY,oBAAoB,YAAW,CAAA,CAAE;AAAA,MAClE,OAAO,gBAAe,yCAAY,oBAAoB,aAAY,CAAE,CAAA;AAAA,IACtE;AAAA,IACA,UAAU;AAAA,MACR,gBAAgB,gBAAe,yCAAY,sBAAsB,cAAa,CAAA,CAAE;AAAA,MAChF,iBAAiB,gBAAe,yCAAY,sBAAsB,eAAc,CAAE,CAAA;AAAA,IACpF;AAAA,IACA,cAAa,yCAAY,oBACvB,oBAAC,oBAAiB,WAAW,WAAW,eAAe,EAAA,CAAI,IACzD;AAAA,EACN;AAGA,SAAO,SAAS,YAAY;AAC9B;"}
|
|
1
|
+
{"version":3,"file":"index.js","sources":["../../src/shared/hooks/use-ui.ts","../../src/shared/registries/anchor-registry.tsx","../../src/shared/hooks/use-register-anchor.ts","../../src/shared/registries/component-registry.tsx","../../src/shared/hooks/use-item-renderer.tsx","../../src/shared/registries/renderers-registry.tsx","../../src/shared/hooks/use-schema-renderer.tsx","../../src/shared/hooks/use-selection-menu.tsx","../../src/shared/auto-menu-renderer.tsx","../../src/shared/root.tsx","../../src/shared/provider.tsx"],"sourcesContent":["import { useCapability, usePlugin } from '@embedpdf/core/@framework';\nimport { UIPlugin } from '@embedpdf/plugin-ui';\nimport { useState, useEffect } from '@framework';\nimport { UIDocumentState, UISchema } from '@embedpdf/plugin-ui';\n\nexport const useUICapability = () => useCapability<UIPlugin>(UIPlugin.id);\nexport const useUIPlugin = () => usePlugin<UIPlugin>(UIPlugin.id);\n\n/**\n * Get UI state for a document\n */\nexport const useUIState = (documentId: string) => {\n const { provides } = useUICapability();\n const [state, setState] = useState<UIDocumentState | null>(null);\n\n useEffect(() => {\n if (!provides) return;\n\n const scope = provides.forDocument(documentId);\n setState(scope.getState());\n\n // Subscribe to changes\n const unsubToolbar = scope.onToolbarChanged(() => setState(scope.getState()));\n const unsubPanel = scope.onPanelChanged(() => setState(scope.getState()));\n const unsubModal = scope.onModalChanged(() => setState(scope.getState()));\n const unsubMenu = scope.onMenuChanged(() => setState(scope.getState()));\n\n return () => {\n unsubToolbar();\n unsubPanel();\n unsubModal();\n unsubMenu();\n };\n }, [provides, documentId]);\n\n return state;\n};\n\n/**\n * Get UI schema\n */\nexport const useUISchema = (): UISchema | null => {\n const { provides } = useUICapability();\n return provides?.getSchema() ?? null;\n};\n","import { createContext, useContext, useRef, useCallback } from '@framework';\nimport type { ReactNode } from '@framework';\n\n/**\n * Anchor Registry\n *\n * Tracks DOM elements for menu positioning.\n * Each anchor is scoped by documentId and itemId.\n */\nexport interface AnchorRegistry {\n register(documentId: string, itemId: string, element: HTMLElement): void;\n unregister(documentId: string, itemId: string): void;\n getAnchor(documentId: string, itemId: string): HTMLElement | null;\n}\n\nconst AnchorRegistryContext = createContext<AnchorRegistry | null>(null);\n\nexport function AnchorRegistryProvider({ children }: { children: ReactNode }) {\n const anchorsRef = useRef<Map<string, HTMLElement>>(new Map());\n\n const registry: AnchorRegistry = {\n register: useCallback((documentId: string, itemId: string, element: HTMLElement) => {\n const key = `${documentId}:${itemId}`;\n anchorsRef.current.set(key, element);\n }, []),\n\n unregister: useCallback((documentId: string, itemId: string) => {\n const key = `${documentId}:${itemId}`;\n anchorsRef.current.delete(key);\n }, []),\n\n getAnchor: useCallback((documentId: string, itemId: string) => {\n const key = `${documentId}:${itemId}`;\n return anchorsRef.current.get(key) || null;\n }, []),\n };\n\n return (\n <AnchorRegistryContext.Provider value={registry}>{children}</AnchorRegistryContext.Provider>\n );\n}\n\nexport function useAnchorRegistry(): AnchorRegistry {\n const context = useContext(AnchorRegistryContext);\n if (!context) {\n throw new Error('useAnchorRegistry must be used within UIProvider');\n }\n return context;\n}\n","import { useCallback, useRef } from '@framework';\nimport { useAnchorRegistry } from '../registries/anchor-registry';\n\n/**\n * Register a DOM element as an anchor for menus\n *\n * @param documentId - Document ID\n * @param itemId - Item ID (typically matches the toolbar/menu item ID)\n * @returns Ref callback to attach to the element\n *\n * @example\n * ```tsx\n * function ZoomButton({ documentId }: Props) {\n * const anchorRef = useRegisterAnchor(documentId, 'zoom-button');\n *\n * return <button ref={anchorRef}>Zoom</button>;\n * }\n * ```\n */\nexport function useRegisterAnchor(\n documentId: string,\n itemId: string,\n): (element: HTMLElement | null) => void {\n const registry = useAnchorRegistry();\n const elementRef = useRef<HTMLElement | null>(null);\n const documentIdRef = useRef(documentId);\n const itemIdRef = useRef(itemId);\n\n // Keep refs in sync\n documentIdRef.current = documentId;\n itemIdRef.current = itemId;\n\n // Return stable callback that uses refs\n return useCallback(\n (element: HTMLElement | null) => {\n // Store previous element\n const previousElement = elementRef.current;\n\n // Update ref\n elementRef.current = element;\n\n // Handle registration/unregistration\n if (element) {\n // Register new element\n if (element !== previousElement) {\n registry.register(documentIdRef.current, itemIdRef.current, element);\n }\n } else if (previousElement) {\n // Element is now null, but we had one before - unregister\n registry.unregister(documentIdRef.current, itemIdRef.current);\n }\n },\n [registry], // Only depend on registry!\n );\n}\n","import { createContext, useContext, useRef, useCallback } from '@framework';\nimport type { ComponentType, ReactNode } from '@framework';\nimport { BaseComponentProps } from '../types';\n\n/**\n * Component Registry\n *\n * Stores custom components that can be referenced in the UI schema.\n */\nexport interface ComponentRegistry {\n register(id: string, component: ComponentType<BaseComponentProps>): void;\n unregister(id: string): void;\n get(id: string): ComponentType<BaseComponentProps> | undefined;\n has(id: string): boolean;\n getRegisteredIds(): string[];\n}\n\nconst ComponentRegistryContext = createContext<ComponentRegistry | null>(null);\n\nexport interface ComponentRegistryProviderProps {\n children: ReactNode;\n initialComponents?: Record<string, ComponentType<BaseComponentProps>>;\n}\n\nexport function ComponentRegistryProvider({\n children,\n initialComponents = {},\n}: ComponentRegistryProviderProps) {\n const componentsRef = useRef<Map<string, ComponentType<BaseComponentProps>>>(\n new Map(Object.entries(initialComponents)),\n );\n\n const registry: ComponentRegistry = {\n register: useCallback((id: string, component: ComponentType<BaseComponentProps>) => {\n componentsRef.current.set(id, component);\n }, []),\n\n unregister: useCallback((id: string) => {\n componentsRef.current.delete(id);\n }, []),\n\n get: useCallback((id: string) => {\n return componentsRef.current.get(id);\n }, []),\n\n has: useCallback((id: string) => {\n return componentsRef.current.has(id);\n }, []),\n\n getRegisteredIds: useCallback(() => {\n return Array.from(componentsRef.current.keys());\n }, []),\n };\n\n return (\n <ComponentRegistryContext.Provider value={registry}>\n {children}\n </ComponentRegistryContext.Provider>\n );\n}\n\nexport function useComponentRegistry(): ComponentRegistry {\n const context = useContext(ComponentRegistryContext);\n if (!context) {\n throw new Error('useComponentRegistry must be used within UIProvider');\n }\n return context;\n}\n","import { useComponentRegistry } from '../registries/component-registry';\n\n/**\n * Helper utilities for building renderers\n */\nexport function useItemRenderer() {\n const componentRegistry = useComponentRegistry();\n\n return {\n /**\n * Render a custom component by ID\n *\n * @param componentId - Component ID from schema\n * @param documentId - Document ID\n * @param props - Additional props to pass to component\n * @returns Rendered component or null if not found\n */\n renderCustomComponent: (componentId: string, documentId: string, props?: any) => {\n const Component = componentRegistry.get(componentId);\n\n if (!Component) {\n console.error(`Component \"${componentId}\" not found in registry`);\n return null;\n }\n\n return <Component documentId={documentId} {...(props || {})} />;\n },\n };\n}\n","import { createContext, useContext } from '@framework';\nimport type { ReactNode } from '@framework';\nimport { UIRenderers } from '../types';\n\n/**\n * Renderers Registry\n *\n * Provides access to user-supplied renderers (toolbar, panel, menu).\n */\nconst RenderersContext = createContext<UIRenderers | null>(null);\n\nexport interface RenderersProviderProps {\n children: ReactNode;\n renderers: UIRenderers;\n}\n\nexport function RenderersProvider({ children, renderers }: RenderersProviderProps) {\n return <RenderersContext.Provider value={renderers}>{children}</RenderersContext.Provider>;\n}\n\nexport function useRenderers(): UIRenderers {\n const context = useContext(RenderersContext);\n if (!context) {\n throw new Error('useRenderers must be used within UIProvider');\n }\n return context;\n}\n","import { useUICapability, useUIState } from './use-ui';\nimport { useRenderers } from '../registries/renderers-registry';\n\n/**\n * High-level hook for rendering UI from schema\n *\n * Provides simple functions to render toolbars and panels by placement+slot.\n * Always passes isOpen state to renderers so they can control animations.\n *\n * Automatically subscribes to UI state changes for the given document.\n */\nexport function useSchemaRenderer(documentId: string) {\n const renderers = useRenderers();\n const { provides } = useUICapability();\n const schema = provides?.getSchema();\n const uiState = useUIState(documentId); // Subscribe to state changes\n\n return {\n /**\n * Render a toolbar by placement and slot\n *\n * Always renders with isOpen state when toolbar exists in slot.\n *\n * @param placement - 'top' | 'bottom' | 'left' | 'right'\n * @param slot - Slot name (e.g. 'main', 'secondary')\n *\n * @example\n * ```tsx\n * {renderToolbar('top', 'main')}\n * {renderToolbar('top', 'secondary')}\n * ```\n */\n renderToolbar: (placement: 'top' | 'bottom' | 'left' | 'right', slot: string) => {\n if (!schema || !provides || !uiState) return null;\n\n const slotKey = `${placement}-${slot}`;\n const toolbarSlot = uiState.activeToolbars[slotKey];\n\n // If no toolbar in this slot, nothing to render\n if (!toolbarSlot) return null;\n\n const toolbarSchema = schema.toolbars[toolbarSlot.toolbarId];\n if (!toolbarSchema) {\n console.warn(`Toolbar \"${toolbarSlot.toolbarId}\" not found in schema`);\n return null;\n }\n\n // Check if toolbar is closable\n const isClosable = !toolbarSchema.permanent;\n\n const handleClose = isClosable\n ? () => {\n provides.forDocument(documentId).closeToolbarSlot(placement, slot);\n }\n : undefined;\n\n const ToolbarRenderer = renderers.toolbar;\n\n // ALWAYS render, pass isOpen state\n return (\n <ToolbarRenderer\n key={toolbarSlot.toolbarId}\n schema={toolbarSchema}\n documentId={documentId}\n isOpen={toolbarSlot.isOpen}\n onClose={handleClose}\n />\n );\n },\n\n /**\n * Render a panel by placement and slot\n *\n * ALWAYS renders (when panel exists in slot) with isOpen state.\n * Your renderer controls whether to display or animate.\n *\n * @param placement - 'left' | 'right' | 'top' | 'bottom'\n * @param slot - Slot name (e.g. 'main', 'secondary', 'inspector')\n *\n * @example\n * ```tsx\n * {renderPanel('left', 'main')}\n * {renderPanel('right', 'main')}\n * ```\n */\n renderPanel: (placement: 'left' | 'right' | 'top' | 'bottom', slot: string) => {\n if (!schema || !provides || !uiState) return null;\n const slotKey = `${placement}-${slot}`;\n const panelSlot = uiState.activePanels[slotKey];\n\n // If no panel in this slot, nothing to render\n if (!panelSlot) return null;\n\n const panelSchema = schema.panels[panelSlot.panelId];\n if (!panelSchema) {\n console.warn(`Panel \"${panelSlot.panelId}\" not found in schema`);\n return null;\n }\n\n const handleClose = () => {\n provides.forDocument(documentId).closePanelSlot(placement, slot);\n };\n\n const PanelRenderer = renderers.panel;\n\n // ALWAYS render, pass isOpen state\n // Your renderer decides whether to return null or animate\n return (\n <PanelRenderer\n key={panelSlot.panelId}\n schema={panelSchema}\n documentId={documentId}\n isOpen={panelSlot.isOpen}\n onClose={handleClose}\n />\n );\n },\n\n /**\n * Helper: Get all active toolbars for this document\n * Useful for batch rendering or debugging\n */\n getActiveToolbars: () => {\n if (!uiState) return [];\n return Object.entries(uiState.activeToolbars).map(([slotKey, toolbarSlot]) => {\n const [placement, slot] = slotKey.split('-');\n return {\n placement,\n slot,\n toolbarId: toolbarSlot.toolbarId,\n isOpen: toolbarSlot.isOpen,\n };\n });\n },\n\n /**\n * Helper: Get all active panels for this document\n * Useful for batch rendering or debugging\n */\n getActivePanels: () => {\n if (!uiState) return [];\n return Object.entries(uiState.activePanels).map(([slotKey, panelSlot]) => {\n const [placement, slot] = slotKey.split('-');\n return {\n placement,\n slot,\n panelId: panelSlot.panelId,\n isOpen: panelSlot.isOpen,\n };\n });\n },\n };\n}\n","import { useCallback } from '@framework';\nimport { SelectionMenuPropsBase, SelectionMenuRenderFn } from '@embedpdf/utils/@framework';\nimport { useUICapability } from './use-ui';\nimport { useRenderers } from '../registries/renderers-registry';\n\n/**\n * Creates a render function for a selection menu from the schema\n *\n * @param menuId - The selection menu ID from schema\n * @param documentId - Document ID\n * @returns A render function compatible with layer selectionMenu props\n */\nexport function useSelectionMenu<TContext extends { type: string }>(\n menuId: string,\n documentId: string,\n): SelectionMenuRenderFn<TContext> | undefined {\n const { provides } = useUICapability();\n const renderers = useRenderers();\n\n const renderFn = useCallback(\n (props: SelectionMenuPropsBase<TContext>) => {\n const schema = provides?.getSchema();\n const menuSchema = schema?.selectionMenus?.[menuId];\n\n if (!menuSchema) {\n return null;\n }\n\n if (!props.selected) {\n return null;\n }\n\n const SelectionMenuRenderer = renderers.selectionMenu;\n\n return <SelectionMenuRenderer schema={menuSchema} documentId={documentId} props={props} />;\n },\n [provides, renderers, menuId, documentId],\n );\n\n // Return undefined if schema doesn't have this menu\n const schema = provides?.getSchema();\n if (!schema?.selectionMenus?.[menuId]) {\n return undefined;\n }\n\n return renderFn;\n}\n","import { useState, useEffect } from '@framework';\nimport { useUIState, useUICapability } from './hooks/use-ui';\nimport { useAnchorRegistry } from './registries/anchor-registry';\nimport { useRenderers } from './registries/renderers-registry';\n\n/**\n * Automatically renders menus when opened\n *\n * This component:\n * 1. Listens to UI plugin state for open menus\n * 2. Looks up anchor elements from the anchor registry\n * 3. Renders menus using the user-provided menu renderer\n */\nexport interface AutoMenuRendererProps {\n container?: HTMLElement | null;\n documentId: string; // Which document's menus to render\n}\n\nexport function AutoMenuRenderer({ container, documentId }: AutoMenuRendererProps) {\n const uiState = useUIState(documentId);\n const { provides } = useUICapability();\n const anchorRegistry = useAnchorRegistry();\n const renderers = useRenderers();\n\n const [activeMenu, setActiveMenu] = useState<{\n menuId: string;\n anchorEl: HTMLElement | null;\n } | null>(null);\n\n const openMenus = uiState?.openMenus || {};\n const schema = provides?.getSchema();\n\n // Update active menu when state changes\n useEffect(() => {\n const openMenuIds = Object.keys(openMenus);\n\n if (openMenuIds.length > 0) {\n // Show the first open menu (in practice, should only be one)\n const menuId = openMenuIds[0];\n if (!menuId) {\n setActiveMenu(null);\n return;\n }\n\n const menuState = openMenus[menuId];\n if (menuState && menuState.triggeredByItemId) {\n // Look up anchor with documentId scope\n const anchor = anchorRegistry.getAnchor(documentId, menuState.triggeredByItemId);\n setActiveMenu({ menuId, anchorEl: anchor });\n } else {\n setActiveMenu(null);\n }\n } else {\n setActiveMenu(null);\n }\n }, [openMenus, anchorRegistry, documentId]);\n\n const handleClose = () => {\n if (activeMenu) {\n provides?.forDocument(documentId).closeMenu(activeMenu.menuId);\n }\n };\n\n if (!activeMenu || !schema) {\n return null;\n }\n\n const menuSchema = schema.menus[activeMenu.menuId];\n if (!menuSchema) {\n console.warn(`Menu \"${activeMenu.menuId}\" not found in schema`);\n return null;\n }\n\n // Use the user-provided menu renderer\n const MenuRenderer = renderers.menu;\n\n return (\n <MenuRenderer\n schema={menuSchema}\n documentId={documentId}\n anchorEl={activeMenu.anchorEl}\n onClose={handleClose}\n container={container}\n />\n );\n}\n","import { UI_ATTRIBUTES, UI_SELECTORS } from '@embedpdf/plugin-ui';\nimport { useUICapability, useUIPlugin } from './hooks/use-ui';\nimport {\n useState,\n useEffect,\n useRef,\n useMemo,\n useCallback,\n ReactNode,\n HTMLAttributes,\n} from '@framework';\n\n/**\n * Find the style injection target for an element.\n * Returns the shadow root if inside one, otherwise document.head.\n */\nfunction getStyleTarget(element: HTMLElement): HTMLElement | ShadowRoot {\n const root = element.getRootNode();\n if (root instanceof ShadowRoot) {\n return root;\n }\n return document.head;\n}\n\ninterface UIRootProps extends HTMLAttributes<HTMLDivElement> {\n children: ReactNode;\n}\n\n/**\n * Internal component that handles:\n * 1. Injecting the generated stylesheet (into shadow root or document.head)\n * 2. Managing the data-disabled-categories attribute\n * 3. Updating styles on locale changes\n */\nexport function UIRoot({ children, ...restProps }: UIRootProps) {\n const { plugin } = useUIPlugin();\n const { provides } = useUICapability();\n const [disabledCategories, setDisabledCategories] = useState<string[]>([]);\n const styleElRef = useRef<HTMLStyleElement | null>(null);\n const styleTargetRef = useRef<HTMLElement | ShadowRoot | null>(null);\n const previousElementRef = useRef<HTMLDivElement | null>(null);\n\n // Callback ref that handles style injection when element mounts\n // Handles React Strict Mode by tracking previous element\n const rootRefCallback = useCallback(\n (element: HTMLDivElement | null) => {\n const previousElement = previousElementRef.current;\n\n // Update ref\n previousElementRef.current = element;\n\n // If element is null (unmount), don't do anything yet\n // React Strict Mode will remount, so we'll handle cleanup in useEffect\n if (!element) {\n return;\n }\n\n // If element changed (or is new) and plugin is available, inject styles\n if (element !== previousElement && plugin) {\n const styleTarget = getStyleTarget(element);\n styleTargetRef.current = styleTarget;\n\n // Check if styles already exist in this target\n const existingStyle = styleTarget.querySelector(\n UI_SELECTORS.STYLES,\n ) as HTMLStyleElement | null;\n\n if (existingStyle) {\n styleElRef.current = existingStyle;\n // Update content in case locale changed\n existingStyle.textContent = plugin.getStylesheet();\n return;\n }\n\n // Create and inject stylesheet\n const stylesheet = plugin.getStylesheet();\n const styleEl = document.createElement('style');\n styleEl.setAttribute(UI_ATTRIBUTES.STYLES, '');\n styleEl.textContent = stylesheet;\n\n if (styleTarget instanceof ShadowRoot) {\n // For shadow root, prepend before other content\n styleTarget.insertBefore(styleEl, styleTarget.firstChild);\n } else {\n styleTarget.appendChild(styleEl);\n }\n\n styleElRef.current = styleEl;\n }\n },\n [plugin],\n );\n\n // Cleanup on actual unmount (not Strict Mode remount)\n useEffect(() => {\n return () => {\n // Only cleanup if we're actually unmounting (not just Strict Mode)\n // The style element will be reused if component remounts\n if (styleElRef.current?.parentNode && !previousElementRef.current) {\n styleElRef.current.remove();\n }\n styleElRef.current = null;\n styleTargetRef.current = null;\n };\n }, []);\n\n // Subscribe to stylesheet invalidation (locale changes, schema merges)\n useEffect(() => {\n if (!plugin) return;\n\n return plugin.onStylesheetInvalidated(() => {\n // Update the style element content\n if (styleElRef.current) {\n styleElRef.current.textContent = plugin.getStylesheet();\n }\n });\n }, [plugin]);\n\n // Subscribe to category changes\n useEffect(() => {\n if (!provides) return;\n\n setDisabledCategories(provides.getDisabledCategories());\n\n return provides.onCategoryChanged(({ disabledCategories }) => {\n setDisabledCategories(disabledCategories);\n });\n }, [provides]);\n\n // Build the disabled categories attribute value\n const disabledCategoriesAttr = useMemo(\n () => (disabledCategories.length > 0 ? disabledCategories.join(' ') : undefined),\n [disabledCategories],\n );\n\n const rootProps = {\n [UI_ATTRIBUTES.ROOT]: '',\n [UI_ATTRIBUTES.DISABLED_CATEGORIES]: disabledCategoriesAttr,\n };\n\n return (\n <div\n ref={rootRefCallback}\n {...rootProps}\n {...restProps}\n style={{ containerType: 'inline-size', ...restProps.style }}\n >\n {children}\n </div>\n );\n}\n","import type { ReactNode, ComponentType, HTMLAttributes } from '@framework';\nimport { AnchorRegistryProvider } from './registries/anchor-registry';\nimport { ComponentRegistryProvider } from './registries/component-registry';\nimport { RenderersProvider } from './registries/renderers-registry';\nimport { BaseComponentProps, UIRenderers } from './types';\nimport { AutoMenuRenderer } from './auto-menu-renderer';\nimport { UIRoot } from './root';\n\n/**\n * UIProvider Props\n */\nexport interface UIProviderProps extends HTMLAttributes<HTMLDivElement> {\n children: ReactNode;\n\n /**\n * Document ID for this UI context\n * Required for menu rendering\n */\n documentId: string;\n\n /**\n * Custom component registry\n * Maps component IDs to components\n */\n components?: Record<string, ComponentType<BaseComponentProps>>;\n\n /**\n * REQUIRED: User-provided renderers\n * These define how toolbars, panels, and menus are displayed\n */\n renderers: UIRenderers;\n\n /**\n * Optional: Container for menu portal\n * Defaults to document.body\n */\n menuContainer?: HTMLElement | null;\n}\n\n/**\n * UIProvider - Single provider for all UI plugin functionality\n *\n * Manages:\n * - Anchor registry for menu positioning\n * - Component registry for custom components\n * - Renderers for toolbars, panels, and menus\n * - Automatic menu rendering\n *\n * @example\n * ```tsx\n * <EmbedPDF engine={engine} plugins={plugins}>\n * {({ pluginsReady }) => (\n * pluginsReady && (\n * <DocumentContext>\n * {({ activeDocumentId }) => (\n * activeDocumentId && (\n * <UIProvider\n * documentId={activeDocumentId}\n * components={{\n * 'thumbnail-panel': ThumbnailPanel,\n * 'bookmark-panel': BookmarkPanel,\n * }}\n * renderers={{\n * toolbar: ToolbarRenderer,\n * panel: PanelRenderer,\n * menu: MenuRenderer,\n * }}\n * >\n * <ViewerLayout />\n * </UIProvider>\n * )\n * )}\n * </DocumentContext>\n * )\n * )}\n * </EmbedPDF>\n * ```\n */\nexport function UIProvider({\n children,\n documentId,\n components = {},\n renderers,\n menuContainer,\n ...restProps\n}: UIProviderProps) {\n return (\n <AnchorRegistryProvider>\n <ComponentRegistryProvider initialComponents={components}>\n <RenderersProvider renderers={renderers}>\n <UIRoot {...restProps}>\n {children}\n {/* Automatically render menus for this document */}\n <AutoMenuRenderer documentId={documentId} container={menuContainer} />\n </UIRoot>\n </RenderersProvider>\n </ComponentRegistryProvider>\n </AnchorRegistryProvider>\n );\n}\n"],"names":["schema","disabledCategories"],"mappings":";;;;;AAKO,MAAM,kBAAkB,MAAM,cAAwB,SAAS,EAAE;AACjE,MAAM,cAAc,MAAM,UAAoB,SAAS,EAAE;AAKzD,MAAM,aAAa,CAAC,eAAuB;AAChD,QAAM,EAAE,SAAA,IAAa,gBAAA;AACrB,QAAM,CAAC,OAAO,QAAQ,IAAI,SAAiC,IAAI;AAE/D,YAAU,MAAM;AACd,QAAI,CAAC,SAAU;AAEf,UAAM,QAAQ,SAAS,YAAY,UAAU;AAC7C,aAAS,MAAM,UAAU;AAGzB,UAAM,eAAe,MAAM,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AAA,oBAAC,2BAAA,EAA0B,mBAAmB,YAC5C,UAAA,oBAAC,mBAAA,EAAkB,WACjB,UAAA,qBAAC,QAAA,EAAQ,GAAG,WACT,UAAA;AAAA,IAAA;AAAA,IAED,oBAAC,kBAAA,EAAiB,YAAwB,WAAW,cAAA,CAAe;AAAA,EAAA,GACtE,EAAA,CACF,GACF,GACF;AAEJ;"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from '@embedpdf/utils/react';
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Automatically renders menus when opened
|
|
3
|
+
*
|
|
4
|
+
* This component:
|
|
5
|
+
* 1. Listens to UI plugin state for open menus
|
|
6
|
+
* 2. Looks up anchor elements from the anchor registry
|
|
7
|
+
* 3. Renders menus using the user-provided menu renderer
|
|
8
|
+
*/
|
|
9
|
+
export interface AutoMenuRendererProps {
|
|
10
|
+
container?: HTMLElement | null;
|
|
11
|
+
documentId: string;
|
|
12
|
+
}
|
|
13
|
+
export declare function AutoMenuRenderer({ container, documentId }: AutoMenuRendererProps): import("react/jsx-runtime").JSX.Element | null;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Helper utilities for building renderers
|
|
3
|
+
*/
|
|
4
|
+
export declare function useItemRenderer(): {
|
|
5
|
+
/**
|
|
6
|
+
* Render a custom component by ID
|
|
7
|
+
*
|
|
8
|
+
* @param componentId - Component ID from schema
|
|
9
|
+
* @param documentId - Document ID
|
|
10
|
+
* @param props - Additional props to pass to component
|
|
11
|
+
* @returns Rendered component or null if not found
|
|
12
|
+
*/
|
|
13
|
+
renderCustomComponent: (componentId: string, documentId: string, props?: any) => import("react/jsx-runtime").JSX.Element | null;
|
|
14
|
+
};
|