@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
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Register a DOM element as an anchor for menus
|
|
3
|
+
*
|
|
4
|
+
* @param documentId - Document ID
|
|
5
|
+
* @param itemId - Item ID (typically matches the toolbar/menu item ID)
|
|
6
|
+
* @returns Ref callback to attach to the element
|
|
7
|
+
*
|
|
8
|
+
* @example
|
|
9
|
+
* ```tsx
|
|
10
|
+
* function ZoomButton({ documentId }: Props) {
|
|
11
|
+
* const anchorRef = useRegisterAnchor(documentId, 'zoom-button');
|
|
12
|
+
*
|
|
13
|
+
* return <button ref={anchorRef}>Zoom</button>;
|
|
14
|
+
* }
|
|
15
|
+
* ```
|
|
16
|
+
*/
|
|
17
|
+
export declare function useRegisterAnchor(documentId: string, itemId: string): (element: HTMLElement | null) => void;
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* High-level hook for rendering UI from schema
|
|
3
|
+
*
|
|
4
|
+
* Provides simple functions to render toolbars and panels by placement+slot.
|
|
5
|
+
* Always passes isOpen state to renderers so they can control animations.
|
|
6
|
+
*
|
|
7
|
+
* Automatically subscribes to UI state changes for the given document.
|
|
8
|
+
*/
|
|
9
|
+
export declare function useSchemaRenderer(documentId: string): {
|
|
10
|
+
/**
|
|
11
|
+
* Render a toolbar by placement and slot
|
|
12
|
+
*
|
|
13
|
+
* Always renders with isOpen state when toolbar exists in slot.
|
|
14
|
+
*
|
|
15
|
+
* @param placement - 'top' | 'bottom' | 'left' | 'right'
|
|
16
|
+
* @param slot - Slot name (e.g. 'main', 'secondary')
|
|
17
|
+
*
|
|
18
|
+
* @example
|
|
19
|
+
* ```tsx
|
|
20
|
+
* {renderToolbar('top', 'main')}
|
|
21
|
+
* {renderToolbar('top', 'secondary')}
|
|
22
|
+
* ```
|
|
23
|
+
*/
|
|
24
|
+
renderToolbar: (placement: "top" | "bottom" | "left" | "right", slot: string) => import("react/jsx-runtime").JSX.Element | null;
|
|
25
|
+
/**
|
|
26
|
+
* Render a panel by placement and slot
|
|
27
|
+
*
|
|
28
|
+
* ALWAYS renders (when panel exists in slot) with isOpen state.
|
|
29
|
+
* Your renderer controls whether to display or animate.
|
|
30
|
+
*
|
|
31
|
+
* @param placement - 'left' | 'right' | 'top' | 'bottom'
|
|
32
|
+
* @param slot - Slot name (e.g. 'main', 'secondary', 'inspector')
|
|
33
|
+
*
|
|
34
|
+
* @example
|
|
35
|
+
* ```tsx
|
|
36
|
+
* {renderPanel('left', 'main')}
|
|
37
|
+
* {renderPanel('right', 'main')}
|
|
38
|
+
* ```
|
|
39
|
+
*/
|
|
40
|
+
renderPanel: (placement: "left" | "right" | "top" | "bottom", slot: string) => import("react/jsx-runtime").JSX.Element | null;
|
|
41
|
+
/**
|
|
42
|
+
* Helper: Get all active toolbars for this document
|
|
43
|
+
* Useful for batch rendering or debugging
|
|
44
|
+
*/
|
|
45
|
+
getActiveToolbars: () => {
|
|
46
|
+
placement: string;
|
|
47
|
+
slot: string;
|
|
48
|
+
toolbarId: string;
|
|
49
|
+
isOpen: boolean;
|
|
50
|
+
}[];
|
|
51
|
+
/**
|
|
52
|
+
* Helper: Get all active panels for this document
|
|
53
|
+
* Useful for batch rendering or debugging
|
|
54
|
+
*/
|
|
55
|
+
getActivePanels: () => {
|
|
56
|
+
placement: string;
|
|
57
|
+
slot: string;
|
|
58
|
+
panelId: string;
|
|
59
|
+
isOpen: boolean;
|
|
60
|
+
}[];
|
|
61
|
+
};
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { SelectionMenuRenderFn } from '../../react/utils.ts';
|
|
2
|
+
/**
|
|
3
|
+
* Creates a render function for a selection menu from the schema
|
|
4
|
+
*
|
|
5
|
+
* @param menuId - The selection menu ID from schema
|
|
6
|
+
* @param documentId - Document ID
|
|
7
|
+
* @returns A render function compatible with layer selectionMenu props
|
|
8
|
+
*/
|
|
9
|
+
export declare function useSelectionMenu<TContext extends {
|
|
10
|
+
type: string;
|
|
11
|
+
}>(menuId: string, documentId: string): SelectionMenuRenderFn<TContext> | undefined;
|
|
@@ -1,11 +1,19 @@
|
|
|
1
|
-
import { UIPlugin } from '../../index.ts';
|
|
2
|
-
export declare const
|
|
3
|
-
|
|
1
|
+
import { UIPlugin, UIDocumentState, UISchema } from '../../index.ts';
|
|
2
|
+
export declare const useUICapability: () => {
|
|
3
|
+
provides: Readonly<import('../../index.ts').UICapability> | null;
|
|
4
4
|
isLoading: boolean;
|
|
5
5
|
ready: Promise<void>;
|
|
6
6
|
};
|
|
7
|
-
export declare const
|
|
8
|
-
|
|
7
|
+
export declare const useUIPlugin: () => {
|
|
8
|
+
plugin: UIPlugin | null;
|
|
9
9
|
isLoading: boolean;
|
|
10
10
|
ready: Promise<void>;
|
|
11
11
|
};
|
|
12
|
+
/**
|
|
13
|
+
* Get UI state for a document
|
|
14
|
+
*/
|
|
15
|
+
export declare const useUIState: (documentId: string) => UIDocumentState | null;
|
|
16
|
+
/**
|
|
17
|
+
* Get UI schema
|
|
18
|
+
*/
|
|
19
|
+
export declare const useUISchema: () => UISchema | null;
|
package/dist/shared/index.d.ts
CHANGED
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import { ReactNode, ComponentType, HTMLAttributes } from '../react/adapter.ts';
|
|
2
|
+
import { BaseComponentProps, UIRenderers } from './types';
|
|
3
|
+
/**
|
|
4
|
+
* UIProvider Props
|
|
5
|
+
*/
|
|
6
|
+
export interface UIProviderProps extends HTMLAttributes<HTMLDivElement> {
|
|
7
|
+
children: ReactNode;
|
|
8
|
+
/**
|
|
9
|
+
* Document ID for this UI context
|
|
10
|
+
* Required for menu rendering
|
|
11
|
+
*/
|
|
12
|
+
documentId: string;
|
|
13
|
+
/**
|
|
14
|
+
* Custom component registry
|
|
15
|
+
* Maps component IDs to components
|
|
16
|
+
*/
|
|
17
|
+
components?: Record<string, ComponentType<BaseComponentProps>>;
|
|
18
|
+
/**
|
|
19
|
+
* REQUIRED: User-provided renderers
|
|
20
|
+
* These define how toolbars, panels, and menus are displayed
|
|
21
|
+
*/
|
|
22
|
+
renderers: UIRenderers;
|
|
23
|
+
/**
|
|
24
|
+
* Optional: Container for menu portal
|
|
25
|
+
* Defaults to document.body
|
|
26
|
+
*/
|
|
27
|
+
menuContainer?: HTMLElement | null;
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* UIProvider - Single provider for all UI plugin functionality
|
|
31
|
+
*
|
|
32
|
+
* Manages:
|
|
33
|
+
* - Anchor registry for menu positioning
|
|
34
|
+
* - Component registry for custom components
|
|
35
|
+
* - Renderers for toolbars, panels, and menus
|
|
36
|
+
* - Automatic menu rendering
|
|
37
|
+
*
|
|
38
|
+
* @example
|
|
39
|
+
* ```tsx
|
|
40
|
+
* <EmbedPDF engine={engine} plugins={plugins}>
|
|
41
|
+
* {({ pluginsReady }) => (
|
|
42
|
+
* pluginsReady && (
|
|
43
|
+
* <DocumentContext>
|
|
44
|
+
* {({ activeDocumentId }) => (
|
|
45
|
+
* activeDocumentId && (
|
|
46
|
+
* <UIProvider
|
|
47
|
+
* documentId={activeDocumentId}
|
|
48
|
+
* components={{
|
|
49
|
+
* 'thumbnail-panel': ThumbnailPanel,
|
|
50
|
+
* 'bookmark-panel': BookmarkPanel,
|
|
51
|
+
* }}
|
|
52
|
+
* renderers={{
|
|
53
|
+
* toolbar: ToolbarRenderer,
|
|
54
|
+
* panel: PanelRenderer,
|
|
55
|
+
* menu: MenuRenderer,
|
|
56
|
+
* }}
|
|
57
|
+
* >
|
|
58
|
+
* <ViewerLayout />
|
|
59
|
+
* </UIProvider>
|
|
60
|
+
* )
|
|
61
|
+
* )}
|
|
62
|
+
* </DocumentContext>
|
|
63
|
+
* )
|
|
64
|
+
* )}
|
|
65
|
+
* </EmbedPDF>
|
|
66
|
+
* ```
|
|
67
|
+
*/
|
|
68
|
+
export declare function UIProvider({ children, documentId, components, renderers, menuContainer, ...restProps }: UIProviderProps): import("react/jsx-runtime").JSX.Element;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { ReactNode } from '../../react/adapter.ts';
|
|
2
|
+
/**
|
|
3
|
+
* Anchor Registry
|
|
4
|
+
*
|
|
5
|
+
* Tracks DOM elements for menu positioning.
|
|
6
|
+
* Each anchor is scoped by documentId and itemId.
|
|
7
|
+
*/
|
|
8
|
+
export interface AnchorRegistry {
|
|
9
|
+
register(documentId: string, itemId: string, element: HTMLElement): void;
|
|
10
|
+
unregister(documentId: string, itemId: string): void;
|
|
11
|
+
getAnchor(documentId: string, itemId: string): HTMLElement | null;
|
|
12
|
+
}
|
|
13
|
+
export declare function AnchorRegistryProvider({ children }: {
|
|
14
|
+
children: ReactNode;
|
|
15
|
+
}): import("react/jsx-runtime").JSX.Element;
|
|
16
|
+
export declare function useAnchorRegistry(): AnchorRegistry;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { ComponentType, ReactNode } from '../../react/adapter.ts';
|
|
2
|
+
import { BaseComponentProps } from '../types';
|
|
3
|
+
/**
|
|
4
|
+
* Component Registry
|
|
5
|
+
*
|
|
6
|
+
* Stores custom components that can be referenced in the UI schema.
|
|
7
|
+
*/
|
|
8
|
+
export interface ComponentRegistry {
|
|
9
|
+
register(id: string, component: ComponentType<BaseComponentProps>): void;
|
|
10
|
+
unregister(id: string): void;
|
|
11
|
+
get(id: string): ComponentType<BaseComponentProps> | undefined;
|
|
12
|
+
has(id: string): boolean;
|
|
13
|
+
getRegisteredIds(): string[];
|
|
14
|
+
}
|
|
15
|
+
export interface ComponentRegistryProviderProps {
|
|
16
|
+
children: ReactNode;
|
|
17
|
+
initialComponents?: Record<string, ComponentType<BaseComponentProps>>;
|
|
18
|
+
}
|
|
19
|
+
export declare function ComponentRegistryProvider({ children, initialComponents, }: ComponentRegistryProviderProps): import("react/jsx-runtime").JSX.Element;
|
|
20
|
+
export declare function useComponentRegistry(): ComponentRegistry;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { ReactNode } from '../../react/adapter.ts';
|
|
2
|
+
import { UIRenderers } from '../types';
|
|
3
|
+
export interface RenderersProviderProps {
|
|
4
|
+
children: ReactNode;
|
|
5
|
+
renderers: UIRenderers;
|
|
6
|
+
}
|
|
7
|
+
export declare function RenderersProvider({ children, renderers }: RenderersProviderProps): import("react/jsx-runtime").JSX.Element;
|
|
8
|
+
export declare function useRenderers(): UIRenderers;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { ReactNode, HTMLAttributes } from '../react/adapter.ts';
|
|
2
|
+
interface UIRootProps extends HTMLAttributes<HTMLDivElement> {
|
|
3
|
+
children: ReactNode;
|
|
4
|
+
}
|
|
5
|
+
/**
|
|
6
|
+
* Internal component that handles:
|
|
7
|
+
* 1. Injecting the generated stylesheet (into shadow root or document.head)
|
|
8
|
+
* 2. Managing the data-disabled-categories attribute
|
|
9
|
+
* 3. Updating styles on locale changes
|
|
10
|
+
*/
|
|
11
|
+
export declare function UIRoot({ children, ...restProps }: UIRootProps): import("react/jsx-runtime").JSX.Element;
|
|
12
|
+
export {};
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import { ComponentType } from '../react/adapter.ts';
|
|
2
|
+
import { ToolbarSchema, PanelSchema, MenuSchema, SelectionMenuSchema } from '../index.ts';
|
|
3
|
+
import { SelectionMenuPropsBase } from '../react/utils.ts';
|
|
4
|
+
export type { SelectionMenuPropsBase };
|
|
5
|
+
export type UIComponents = Record<string, ComponentType<BaseComponentProps>>;
|
|
6
|
+
/**
|
|
7
|
+
* Base props that all custom components must accept
|
|
8
|
+
*/
|
|
9
|
+
export interface BaseComponentProps {
|
|
10
|
+
documentId: string;
|
|
11
|
+
[key: string]: any;
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* Props for toolbar renderer
|
|
15
|
+
* The app provides a component matching this contract
|
|
16
|
+
*/
|
|
17
|
+
export interface ToolbarRendererProps {
|
|
18
|
+
schema: ToolbarSchema;
|
|
19
|
+
documentId: string;
|
|
20
|
+
isOpen: boolean;
|
|
21
|
+
onClose?: () => void;
|
|
22
|
+
className?: string;
|
|
23
|
+
}
|
|
24
|
+
export type ToolbarRenderer = ComponentType<ToolbarRendererProps>;
|
|
25
|
+
/**
|
|
26
|
+
* Props for panel renderer
|
|
27
|
+
* The app provides a component matching this contract
|
|
28
|
+
*/
|
|
29
|
+
export interface PanelRendererProps {
|
|
30
|
+
schema: PanelSchema;
|
|
31
|
+
documentId: string;
|
|
32
|
+
isOpen: boolean;
|
|
33
|
+
onClose: () => void;
|
|
34
|
+
className?: string;
|
|
35
|
+
}
|
|
36
|
+
export type PanelRenderer = ComponentType<PanelRendererProps>;
|
|
37
|
+
/**
|
|
38
|
+
* Props for menu renderer
|
|
39
|
+
* The app provides a component matching this contract
|
|
40
|
+
*/
|
|
41
|
+
export interface MenuRendererProps {
|
|
42
|
+
schema: MenuSchema;
|
|
43
|
+
documentId: string;
|
|
44
|
+
anchorEl: HTMLElement | null;
|
|
45
|
+
onClose: () => void;
|
|
46
|
+
container?: HTMLElement | null;
|
|
47
|
+
}
|
|
48
|
+
export type MenuRenderer = ComponentType<MenuRendererProps>;
|
|
49
|
+
/**
|
|
50
|
+
* Props for the selection menu renderer component
|
|
51
|
+
*/
|
|
52
|
+
export interface SelectionMenuRendererProps {
|
|
53
|
+
schema: SelectionMenuSchema;
|
|
54
|
+
documentId: string;
|
|
55
|
+
/** Full props from the layer including context */
|
|
56
|
+
props: SelectionMenuPropsBase;
|
|
57
|
+
}
|
|
58
|
+
export type SelectionMenuRenderer = ComponentType<SelectionMenuRendererProps>;
|
|
59
|
+
/**
|
|
60
|
+
* All renderers the app must provide
|
|
61
|
+
*/
|
|
62
|
+
export interface UIRenderers {
|
|
63
|
+
toolbar: ToolbarRenderer;
|
|
64
|
+
panel: PanelRenderer;
|
|
65
|
+
menu: MenuRenderer;
|
|
66
|
+
selectionMenu: SelectionMenuRenderer;
|
|
67
|
+
}
|
|
@@ -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("preact").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("preact").JSX.Element | null;
|
|
14
|
+
};
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Register a DOM element as an anchor for menus
|
|
3
|
+
*
|
|
4
|
+
* @param documentId - Document ID
|
|
5
|
+
* @param itemId - Item ID (typically matches the toolbar/menu item ID)
|
|
6
|
+
* @returns Ref callback to attach to the element
|
|
7
|
+
*
|
|
8
|
+
* @example
|
|
9
|
+
* ```tsx
|
|
10
|
+
* function ZoomButton({ documentId }: Props) {
|
|
11
|
+
* const anchorRef = useRegisterAnchor(documentId, 'zoom-button');
|
|
12
|
+
*
|
|
13
|
+
* return <button ref={anchorRef}>Zoom</button>;
|
|
14
|
+
* }
|
|
15
|
+
* ```
|
|
16
|
+
*/
|
|
17
|
+
export declare function useRegisterAnchor(documentId: string, itemId: string): (element: HTMLElement | null) => void;
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* High-level hook for rendering UI from schema
|
|
3
|
+
*
|
|
4
|
+
* Provides simple functions to render toolbars and panels by placement+slot.
|
|
5
|
+
* Always passes isOpen state to renderers so they can control animations.
|
|
6
|
+
*
|
|
7
|
+
* Automatically subscribes to UI state changes for the given document.
|
|
8
|
+
*/
|
|
9
|
+
export declare function useSchemaRenderer(documentId: string): {
|
|
10
|
+
/**
|
|
11
|
+
* Render a toolbar by placement and slot
|
|
12
|
+
*
|
|
13
|
+
* Always renders with isOpen state when toolbar exists in slot.
|
|
14
|
+
*
|
|
15
|
+
* @param placement - 'top' | 'bottom' | 'left' | 'right'
|
|
16
|
+
* @param slot - Slot name (e.g. 'main', 'secondary')
|
|
17
|
+
*
|
|
18
|
+
* @example
|
|
19
|
+
* ```tsx
|
|
20
|
+
* {renderToolbar('top', 'main')}
|
|
21
|
+
* {renderToolbar('top', 'secondary')}
|
|
22
|
+
* ```
|
|
23
|
+
*/
|
|
24
|
+
renderToolbar: (placement: "top" | "bottom" | "left" | "right", slot: string) => import("preact").JSX.Element | null;
|
|
25
|
+
/**
|
|
26
|
+
* Render a panel by placement and slot
|
|
27
|
+
*
|
|
28
|
+
* ALWAYS renders (when panel exists in slot) with isOpen state.
|
|
29
|
+
* Your renderer controls whether to display or animate.
|
|
30
|
+
*
|
|
31
|
+
* @param placement - 'left' | 'right' | 'top' | 'bottom'
|
|
32
|
+
* @param slot - Slot name (e.g. 'main', 'secondary', 'inspector')
|
|
33
|
+
*
|
|
34
|
+
* @example
|
|
35
|
+
* ```tsx
|
|
36
|
+
* {renderPanel('left', 'main')}
|
|
37
|
+
* {renderPanel('right', 'main')}
|
|
38
|
+
* ```
|
|
39
|
+
*/
|
|
40
|
+
renderPanel: (placement: "left" | "right" | "top" | "bottom", slot: string) => import("preact").JSX.Element | null;
|
|
41
|
+
/**
|
|
42
|
+
* Helper: Get all active toolbars for this document
|
|
43
|
+
* Useful for batch rendering or debugging
|
|
44
|
+
*/
|
|
45
|
+
getActiveToolbars: () => {
|
|
46
|
+
placement: string;
|
|
47
|
+
slot: string;
|
|
48
|
+
toolbarId: string;
|
|
49
|
+
isOpen: boolean;
|
|
50
|
+
}[];
|
|
51
|
+
/**
|
|
52
|
+
* Helper: Get all active panels for this document
|
|
53
|
+
* Useful for batch rendering or debugging
|
|
54
|
+
*/
|
|
55
|
+
getActivePanels: () => {
|
|
56
|
+
placement: string;
|
|
57
|
+
slot: string;
|
|
58
|
+
panelId: string;
|
|
59
|
+
isOpen: boolean;
|
|
60
|
+
}[];
|
|
61
|
+
};
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { SelectionMenuRenderFn } from '../../preact/utils.ts';
|
|
2
|
+
/**
|
|
3
|
+
* Creates a render function for a selection menu from the schema
|
|
4
|
+
*
|
|
5
|
+
* @param menuId - The selection menu ID from schema
|
|
6
|
+
* @param documentId - Document ID
|
|
7
|
+
* @returns A render function compatible with layer selectionMenu props
|
|
8
|
+
*/
|
|
9
|
+
export declare function useSelectionMenu<TContext extends {
|
|
10
|
+
type: string;
|
|
11
|
+
}>(menuId: string, documentId: string): SelectionMenuRenderFn<TContext> | undefined;
|
|
@@ -1,11 +1,19 @@
|
|
|
1
|
-
import { UIPlugin } from '../../lib/index.ts';
|
|
2
|
-
export declare const
|
|
3
|
-
|
|
1
|
+
import { UIPlugin, UIDocumentState, UISchema } from '../../lib/index.ts';
|
|
2
|
+
export declare const useUICapability: () => {
|
|
3
|
+
provides: Readonly<import('../../lib/index.ts').UICapability> | null;
|
|
4
4
|
isLoading: boolean;
|
|
5
5
|
ready: Promise<void>;
|
|
6
6
|
};
|
|
7
|
-
export declare const
|
|
8
|
-
|
|
7
|
+
export declare const useUIPlugin: () => {
|
|
8
|
+
plugin: UIPlugin | null;
|
|
9
9
|
isLoading: boolean;
|
|
10
10
|
ready: Promise<void>;
|
|
11
11
|
};
|
|
12
|
+
/**
|
|
13
|
+
* Get UI state for a document
|
|
14
|
+
*/
|
|
15
|
+
export declare const useUIState: (documentId: string) => UIDocumentState | null;
|
|
16
|
+
/**
|
|
17
|
+
* Get UI schema
|
|
18
|
+
*/
|
|
19
|
+
export declare const useUISchema: () => UISchema | null;
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import { ReactNode, ComponentType, HTMLAttributes } from '../preact/adapter.ts';
|
|
2
|
+
import { BaseComponentProps, UIRenderers } from './types';
|
|
3
|
+
/**
|
|
4
|
+
* UIProvider Props
|
|
5
|
+
*/
|
|
6
|
+
export interface UIProviderProps extends HTMLAttributes<HTMLDivElement> {
|
|
7
|
+
children: ReactNode;
|
|
8
|
+
/**
|
|
9
|
+
* Document ID for this UI context
|
|
10
|
+
* Required for menu rendering
|
|
11
|
+
*/
|
|
12
|
+
documentId: string;
|
|
13
|
+
/**
|
|
14
|
+
* Custom component registry
|
|
15
|
+
* Maps component IDs to components
|
|
16
|
+
*/
|
|
17
|
+
components?: Record<string, ComponentType<BaseComponentProps>>;
|
|
18
|
+
/**
|
|
19
|
+
* REQUIRED: User-provided renderers
|
|
20
|
+
* These define how toolbars, panels, and menus are displayed
|
|
21
|
+
*/
|
|
22
|
+
renderers: UIRenderers;
|
|
23
|
+
/**
|
|
24
|
+
* Optional: Container for menu portal
|
|
25
|
+
* Defaults to document.body
|
|
26
|
+
*/
|
|
27
|
+
menuContainer?: HTMLElement | null;
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* UIProvider - Single provider for all UI plugin functionality
|
|
31
|
+
*
|
|
32
|
+
* Manages:
|
|
33
|
+
* - Anchor registry for menu positioning
|
|
34
|
+
* - Component registry for custom components
|
|
35
|
+
* - Renderers for toolbars, panels, and menus
|
|
36
|
+
* - Automatic menu rendering
|
|
37
|
+
*
|
|
38
|
+
* @example
|
|
39
|
+
* ```tsx
|
|
40
|
+
* <EmbedPDF engine={engine} plugins={plugins}>
|
|
41
|
+
* {({ pluginsReady }) => (
|
|
42
|
+
* pluginsReady && (
|
|
43
|
+
* <DocumentContext>
|
|
44
|
+
* {({ activeDocumentId }) => (
|
|
45
|
+
* activeDocumentId && (
|
|
46
|
+
* <UIProvider
|
|
47
|
+
* documentId={activeDocumentId}
|
|
48
|
+
* components={{
|
|
49
|
+
* 'thumbnail-panel': ThumbnailPanel,
|
|
50
|
+
* 'bookmark-panel': BookmarkPanel,
|
|
51
|
+
* }}
|
|
52
|
+
* renderers={{
|
|
53
|
+
* toolbar: ToolbarRenderer,
|
|
54
|
+
* panel: PanelRenderer,
|
|
55
|
+
* menu: MenuRenderer,
|
|
56
|
+
* }}
|
|
57
|
+
* >
|
|
58
|
+
* <ViewerLayout />
|
|
59
|
+
* </UIProvider>
|
|
60
|
+
* )
|
|
61
|
+
* )}
|
|
62
|
+
* </DocumentContext>
|
|
63
|
+
* )
|
|
64
|
+
* )}
|
|
65
|
+
* </EmbedPDF>
|
|
66
|
+
* ```
|
|
67
|
+
*/
|
|
68
|
+
export declare function UIProvider({ children, documentId, components, renderers, menuContainer, ...restProps }: UIProviderProps): import("preact").JSX.Element;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { ReactNode } from '../../preact/adapter.ts';
|
|
2
|
+
/**
|
|
3
|
+
* Anchor Registry
|
|
4
|
+
*
|
|
5
|
+
* Tracks DOM elements for menu positioning.
|
|
6
|
+
* Each anchor is scoped by documentId and itemId.
|
|
7
|
+
*/
|
|
8
|
+
export interface AnchorRegistry {
|
|
9
|
+
register(documentId: string, itemId: string, element: HTMLElement): void;
|
|
10
|
+
unregister(documentId: string, itemId: string): void;
|
|
11
|
+
getAnchor(documentId: string, itemId: string): HTMLElement | null;
|
|
12
|
+
}
|
|
13
|
+
export declare function AnchorRegistryProvider({ children }: {
|
|
14
|
+
children: ReactNode;
|
|
15
|
+
}): import("preact").JSX.Element;
|
|
16
|
+
export declare function useAnchorRegistry(): AnchorRegistry;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { ComponentType, ReactNode } from '../../preact/adapter.ts';
|
|
2
|
+
import { BaseComponentProps } from '../types';
|
|
3
|
+
/**
|
|
4
|
+
* Component Registry
|
|
5
|
+
*
|
|
6
|
+
* Stores custom components that can be referenced in the UI schema.
|
|
7
|
+
*/
|
|
8
|
+
export interface ComponentRegistry {
|
|
9
|
+
register(id: string, component: ComponentType<BaseComponentProps>): void;
|
|
10
|
+
unregister(id: string): void;
|
|
11
|
+
get(id: string): ComponentType<BaseComponentProps> | undefined;
|
|
12
|
+
has(id: string): boolean;
|
|
13
|
+
getRegisteredIds(): string[];
|
|
14
|
+
}
|
|
15
|
+
export interface ComponentRegistryProviderProps {
|
|
16
|
+
children: ReactNode;
|
|
17
|
+
initialComponents?: Record<string, ComponentType<BaseComponentProps>>;
|
|
18
|
+
}
|
|
19
|
+
export declare function ComponentRegistryProvider({ children, initialComponents, }: ComponentRegistryProviderProps): import("preact").JSX.Element;
|
|
20
|
+
export declare function useComponentRegistry(): ComponentRegistry;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { ReactNode } from '../../preact/adapter.ts';
|
|
2
|
+
import { UIRenderers } from '../types';
|
|
3
|
+
export interface RenderersProviderProps {
|
|
4
|
+
children: ReactNode;
|
|
5
|
+
renderers: UIRenderers;
|
|
6
|
+
}
|
|
7
|
+
export declare function RenderersProvider({ children, renderers }: RenderersProviderProps): import("preact").JSX.Element;
|
|
8
|
+
export declare function useRenderers(): UIRenderers;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { ReactNode, HTMLAttributes } from '../preact/adapter.ts';
|
|
2
|
+
interface UIRootProps extends HTMLAttributes<HTMLDivElement> {
|
|
3
|
+
children: ReactNode;
|
|
4
|
+
}
|
|
5
|
+
/**
|
|
6
|
+
* Internal component that handles:
|
|
7
|
+
* 1. Injecting the generated stylesheet (into shadow root or document.head)
|
|
8
|
+
* 2. Managing the data-disabled-categories attribute
|
|
9
|
+
* 3. Updating styles on locale changes
|
|
10
|
+
*/
|
|
11
|
+
export declare function UIRoot({ children, ...restProps }: UIRootProps): import("preact").JSX.Element;
|
|
12
|
+
export {};
|