@embedpdf/plugin-ui 2.0.0-next.1 → 2.0.0-next.2

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 (56) hide show
  1. package/dist/index.cjs +1 -1
  2. package/dist/index.cjs.map +1 -1
  3. package/dist/index.js +235 -146
  4. package/dist/index.js.map +1 -1
  5. package/dist/lib/actions.d.ts +31 -15
  6. package/dist/lib/schema.d.ts +51 -10
  7. package/dist/lib/selectors.d.ts +5 -5
  8. package/dist/lib/types.d.ts +39 -23
  9. package/dist/lib/ui-plugin.d.ts +11 -8
  10. package/dist/lib/utils/consts.d.ts +3 -0
  11. package/dist/lib/utils/schema-merger.d.ts +1 -1
  12. package/dist/lib/utils/stylesheet-generator.d.ts +17 -0
  13. package/dist/preact/adapter.d.ts +1 -1
  14. package/dist/preact/index.cjs +1 -1
  15. package/dist/preact/index.cjs.map +1 -1
  16. package/dist/preact/index.js +143 -38
  17. package/dist/preact/index.js.map +1 -1
  18. package/dist/react/adapter.d.ts +1 -1
  19. package/dist/react/index.cjs +1 -1
  20. package/dist/react/index.cjs.map +1 -1
  21. package/dist/react/index.js +143 -38
  22. package/dist/react/index.js.map +1 -1
  23. package/dist/shared/hooks/index.d.ts +1 -0
  24. package/dist/shared/hooks/use-schema-renderer.d.ts +41 -9
  25. package/dist/shared/hooks/use-ui-container.d.ts +39 -0
  26. package/dist/shared/root.d.ts +1 -1
  27. package/dist/shared/types.d.ts +31 -6
  28. package/dist/shared-preact/hooks/index.d.ts +1 -0
  29. package/dist/shared-preact/hooks/use-schema-renderer.d.ts +41 -9
  30. package/dist/shared-preact/hooks/use-ui-container.d.ts +39 -0
  31. package/dist/shared-preact/root.d.ts +1 -1
  32. package/dist/shared-preact/types.d.ts +31 -6
  33. package/dist/shared-react/hooks/index.d.ts +1 -0
  34. package/dist/shared-react/hooks/use-schema-renderer.d.ts +41 -9
  35. package/dist/shared-react/hooks/use-ui-container.d.ts +39 -0
  36. package/dist/shared-react/root.d.ts +1 -1
  37. package/dist/shared-react/types.d.ts +31 -6
  38. package/dist/svelte/hooks/index.d.ts +1 -0
  39. package/dist/svelte/hooks/use-schema-renderer.svelte.d.ts +55 -12
  40. package/dist/svelte/hooks/use-ui-container.svelte.d.ts +41 -0
  41. package/dist/svelte/hooks/use-ui.svelte.d.ts +2 -2
  42. package/dist/svelte/index.cjs +1 -1
  43. package/dist/svelte/index.cjs.map +1 -1
  44. package/dist/svelte/index.js +112 -20
  45. package/dist/svelte/index.js.map +1 -1
  46. package/dist/svelte/types.d.ts +31 -6
  47. package/dist/vue/hooks/index.d.ts +1 -0
  48. package/dist/vue/hooks/use-schema-renderer.d.ts +41 -9
  49. package/dist/vue/hooks/use-ui-container.d.ts +39 -0
  50. package/dist/vue/hooks/use-ui.d.ts +148 -20
  51. package/dist/vue/index.cjs +1 -1
  52. package/dist/vue/index.cjs.map +1 -1
  53. package/dist/vue/index.js +126 -25
  54. package/dist/vue/index.js.map +1 -1
  55. package/dist/vue/types.d.ts +31 -6
  56. package/package.json +12 -12
@@ -4,15 +4,17 @@ export declare const INIT_UI_STATE = "UI/INIT_STATE";
4
4
  export declare const CLEANUP_UI_STATE = "UI/CLEANUP_STATE";
5
5
  export declare const SET_ACTIVE_TOOLBAR = "UI/SET_ACTIVE_TOOLBAR";
6
6
  export declare const CLOSE_TOOLBAR_SLOT = "UI/CLOSE_TOOLBAR_SLOT";
7
- export declare const SET_ACTIVE_PANEL = "UI/SET_ACTIVE_PANEL";
8
- export declare const CLOSE_PANEL_SLOT = "UI/CLOSE_PANEL_SLOT";
9
- export declare const SET_PANEL_TAB = "UI/SET_PANEL_TAB";
7
+ export declare const SET_ACTIVE_SIDEBAR = "UI/SET_ACTIVE_SIDEBAR";
8
+ export declare const CLOSE_SIDEBAR_SLOT = "UI/CLOSE_SIDEBAR_SLOT";
9
+ export declare const SET_SIDEBAR_TAB = "UI/SET_SIDEBAR_TAB";
10
10
  export declare const OPEN_MODAL = "UI/OPEN_MODAL";
11
11
  export declare const CLOSE_MODAL = "UI/CLOSE_MODAL";
12
+ export declare const CLEAR_MODAL = "UI/CLEAR_MODAL";
12
13
  export declare const OPEN_MENU = "UI/OPEN_MENU";
13
14
  export declare const CLOSE_MENU = "UI/CLOSE_MENU";
14
15
  export declare const CLOSE_ALL_MENUS = "UI/CLOSE_ALL_MENUS";
15
16
  export declare const SET_DISABLED_CATEGORIES = "UI/SET_DISABLED_CATEGORIES";
17
+ export declare const SET_HIDDEN_ITEMS = "UI/SET_HIDDEN_ITEMS";
16
18
  export interface InitUIStateAction extends Action {
17
19
  type: typeof INIT_UI_STATE;
18
20
  payload: {
@@ -43,29 +45,29 @@ export interface CloseToolbarSlotAction extends Action {
43
45
  slot: string;
44
46
  };
45
47
  }
46
- export interface SetActivePanelAction extends Action {
47
- type: typeof SET_ACTIVE_PANEL;
48
+ export interface SetActiveSidebarAction extends Action {
49
+ type: typeof SET_ACTIVE_SIDEBAR;
48
50
  payload: {
49
51
  documentId: string;
50
52
  placement: string;
51
53
  slot: string;
52
- panelId: string;
54
+ sidebarId: string;
53
55
  activeTab?: string;
54
56
  };
55
57
  }
56
- export interface ClosePanelSlotAction extends Action {
57
- type: typeof CLOSE_PANEL_SLOT;
58
+ export interface CloseSidebarSlotAction extends Action {
59
+ type: typeof CLOSE_SIDEBAR_SLOT;
58
60
  payload: {
59
61
  documentId: string;
60
62
  placement: string;
61
63
  slot: string;
62
64
  };
63
65
  }
64
- export interface SetPanelTabAction extends Action {
65
- type: typeof SET_PANEL_TAB;
66
+ export interface SetSidebarTabAction extends Action {
67
+ type: typeof SET_SIDEBAR_TAB;
66
68
  payload: {
67
69
  documentId: string;
68
- panelId: string;
70
+ sidebarId: string;
69
71
  tabId: string;
70
72
  };
71
73
  }
@@ -82,6 +84,12 @@ export interface CloseModalAction extends Action {
82
84
  documentId: string;
83
85
  };
84
86
  }
87
+ export interface ClearModalAction extends Action {
88
+ type: typeof CLEAR_MODAL;
89
+ payload: {
90
+ documentId: string;
91
+ };
92
+ }
85
93
  export interface OpenMenuAction extends Action {
86
94
  type: typeof OPEN_MENU;
87
95
  payload: {
@@ -108,17 +116,25 @@ export interface SetDisabledCategoriesAction extends Action {
108
116
  categories: string[];
109
117
  };
110
118
  }
111
- export type UIAction = InitUIStateAction | CleanupUIStateAction | SetActiveToolbarAction | CloseToolbarSlotAction | SetActivePanelAction | ClosePanelSlotAction | SetPanelTabAction | OpenModalAction | CloseModalAction | OpenMenuAction | CloseMenuAction | CloseAllMenusAction | SetDisabledCategoriesAction;
119
+ export interface SetHiddenItemsAction extends Action {
120
+ type: typeof SET_HIDDEN_ITEMS;
121
+ payload: {
122
+ hiddenItems: string[];
123
+ };
124
+ }
125
+ export type UIAction = InitUIStateAction | CleanupUIStateAction | SetActiveToolbarAction | CloseToolbarSlotAction | SetActiveSidebarAction | CloseSidebarSlotAction | SetSidebarTabAction | OpenModalAction | CloseModalAction | ClearModalAction | OpenMenuAction | CloseMenuAction | CloseAllMenusAction | SetDisabledCategoriesAction | SetHiddenItemsAction;
112
126
  export declare const initUIState: (documentId: string, schema: UISchema) => InitUIStateAction;
113
127
  export declare const cleanupUIState: (documentId: string) => CleanupUIStateAction;
114
128
  export declare const setActiveToolbar: (documentId: string, placement: string, slot: string, toolbarId: string) => SetActiveToolbarAction;
115
129
  export declare const closeToolbarSlot: (documentId: string, placement: string, slot: string) => CloseToolbarSlotAction;
116
- export declare const setActivePanel: (documentId: string, placement: string, slot: string, panelId: string, activeTab?: string) => SetActivePanelAction;
117
- export declare const closePanelSlot: (documentId: string, placement: string, slot: string) => ClosePanelSlotAction;
118
- export declare const setPanelTab: (documentId: string, panelId: string, tabId: string) => SetPanelTabAction;
130
+ export declare const setActiveSidebar: (documentId: string, placement: string, slot: string, sidebarId: string, activeTab?: string) => SetActiveSidebarAction;
131
+ export declare const closeSidebarSlot: (documentId: string, placement: string, slot: string) => CloseSidebarSlotAction;
132
+ export declare const setSidebarTab: (documentId: string, sidebarId: string, tabId: string) => SetSidebarTabAction;
119
133
  export declare const openModal: (documentId: string, modalId: string) => OpenModalAction;
120
134
  export declare const closeModal: (documentId: string) => CloseModalAction;
135
+ export declare const clearModal: (documentId: string) => ClearModalAction;
121
136
  export declare const openMenu: (documentId: string, menuState: OpenMenuState) => OpenMenuAction;
122
137
  export declare const closeMenu: (documentId: string, menuId: string) => CloseMenuAction;
123
138
  export declare const closeAllMenus: (documentId: string) => CloseAllMenusAction;
124
139
  export declare const setDisabledCategories: (categories: string[]) => SetDisabledCategoriesAction;
140
+ export declare const setHiddenItems: (hiddenItems: string[]) => SetHiddenItemsAction;
@@ -6,7 +6,9 @@ export interface UISchema {
6
6
  version: string;
7
7
  toolbars: Record<string, ToolbarSchema>;
8
8
  menus: Record<string, MenuSchema>;
9
- panels: Record<string, PanelSchema>;
9
+ sidebars: Record<string, SidebarSchema>;
10
+ modals: Record<string, ModalSchema>;
11
+ overlays?: Record<string, OverlaySchema>;
10
12
  selectionMenus: Record<string, SelectionMenuSchema>;
11
13
  }
12
14
  export interface ToolbarPosition {
@@ -149,30 +151,69 @@ export interface MenuCustomItem {
149
151
  visibilityDependsOn?: VisibilityDependency;
150
152
  }
151
153
  /**
152
- * Panel definition (sidebars, overlays, modals)
154
+ * Sidebar definition - positioned panels with placement/slot
153
155
  */
154
- export interface PanelSchema {
156
+ export interface SidebarSchema {
155
157
  id: string;
156
- type: 'sidebar' | 'overlay' | 'modal' | 'popover';
157
- position?: PanelPosition;
158
+ position: SidebarPosition;
158
159
  content: PanelContent;
159
160
  collapsible?: boolean;
160
161
  defaultOpen?: boolean;
161
- closeOnClickOutside?: boolean;
162
162
  width?: string;
163
163
  height?: string;
164
164
  minWidth?: string;
165
165
  minHeight?: string;
166
- maxWidth?: string;
167
- maxHeight?: string;
168
166
  categories?: string[];
169
167
  visibilityDependsOn?: VisibilityDependency;
170
168
  }
171
- export interface PanelPosition {
169
+ export interface SidebarPosition {
172
170
  placement: 'left' | 'right' | 'top' | 'bottom';
173
- slot?: string;
171
+ slot: string;
174
172
  order?: number;
175
173
  }
174
+ /**
175
+ * Modal definition - global overlays, only one at a time
176
+ */
177
+ export interface ModalSchema {
178
+ id: string;
179
+ content: PanelContent;
180
+ closeOnClickOutside?: boolean;
181
+ closeOnEscape?: boolean;
182
+ width?: string;
183
+ height?: string;
184
+ maxWidth?: string;
185
+ maxHeight?: string;
186
+ categories?: string[];
187
+ visibilityDependsOn?: VisibilityDependency;
188
+ }
189
+ /**
190
+ * Overlay position anchor
191
+ */
192
+ export type OverlayAnchor = 'top-left' | 'top-center' | 'top-right' | 'center-left' | 'center' | 'center-right' | 'bottom-left' | 'bottom-center' | 'bottom-right';
193
+ /**
194
+ * Overlay position configuration
195
+ */
196
+ export interface OverlayPosition {
197
+ anchor: OverlayAnchor;
198
+ offset?: {
199
+ top?: string;
200
+ right?: string;
201
+ bottom?: string;
202
+ left?: string;
203
+ };
204
+ }
205
+ /**
206
+ * Overlay definition - floating components positioned over document content
207
+ * Unlike modals, overlays don't block interaction and multiple can be visible
208
+ */
209
+ export interface OverlaySchema {
210
+ id: string;
211
+ position: OverlayPosition;
212
+ content: ComponentPanelContent;
213
+ defaultEnabled?: boolean;
214
+ categories?: string[];
215
+ visibilityDependsOn?: VisibilityDependency;
216
+ }
176
217
  /**
177
218
  * Panel content types
178
219
  */
@@ -1,4 +1,4 @@
1
- import { UIState, UIDocumentState, ToolbarSlotState, PanelSlotState } from './types';
1
+ import { UIState, UIDocumentState, ToolbarSlotState, SidebarSlotState } from './types';
2
2
  export type PluginsSlice = Record<string, any>;
3
3
  export declare function selectUIState(plugins: PluginsSlice): UIState | null;
4
4
  export declare function selectUIDocumentState(plugins: PluginsSlice, documentId: string): UIDocumentState | null;
@@ -8,9 +8,9 @@ export declare function selectToolbarSlot(plugins: PluginsSlice, documentId: str
8
8
  * If toolbarId is provided, also matches that specific toolbar.
9
9
  */
10
10
  export declare function isToolbarOpen(plugins: PluginsSlice, documentId: string, placement: string, slot: string, toolbarId?: string): boolean;
11
- export declare function selectPanelSlot(plugins: PluginsSlice, documentId: string, placement: string, slot: string): PanelSlotState | null;
11
+ export declare function selectSidebarSlot(plugins: PluginsSlice, documentId: string, placement: string, slot: string): SidebarSlotState | null;
12
12
  /**
13
- * Is a panel open in this slot?
14
- * If panelId is provided, also matches that specific panel.
13
+ * Is a sidebar open in this slot?
14
+ * If sidebarId is provided, also matches that specific sidebar.
15
15
  */
16
- export declare function isPanelOpen(plugins: PluginsSlice, documentId: string, placement: string, slot: string, panelId?: string): boolean;
16
+ export declare function isSidebarOpen(plugins: PluginsSlice, documentId: string, placement: string, slot: string, sidebarId?: string): boolean;
@@ -14,6 +14,8 @@ export interface UIState {
14
14
  documents: Record<string, UIDocumentState>;
15
15
  /** Globally disabled categories */
16
16
  disabledCategories: string[];
17
+ /** Item IDs that are hidden (computed from disabled categories) */
18
+ hiddenItems: string[];
17
19
  }
18
20
  /**
19
21
  * Toolbar slot state
@@ -23,18 +25,25 @@ export interface ToolbarSlotState {
23
25
  isOpen: boolean;
24
26
  }
25
27
  /**
26
- * Panel slot state
28
+ * Sidebar slot state
27
29
  */
28
- export interface PanelSlotState {
29
- panelId: string;
30
+ export interface SidebarSlotState {
31
+ sidebarId: string;
32
+ isOpen: boolean;
33
+ }
34
+ /**
35
+ * Modal slot state - supports animation lifecycle
36
+ */
37
+ export interface ModalSlotState {
38
+ modalId: string;
30
39
  isOpen: boolean;
31
40
  }
32
41
  export interface UIDocumentState {
33
42
  activeToolbars: Record<string, ToolbarSlotState>;
34
- activePanels: Record<string, PanelSlotState>;
35
- activeModal: string | null;
43
+ activeSidebars: Record<string, SidebarSlotState>;
44
+ activeModal: ModalSlotState | null;
36
45
  openMenus: Record<string, OpenMenuState>;
37
- panelTabs: Record<string, string>;
46
+ sidebarTabs: Record<string, string>;
38
47
  }
39
48
  /**
40
49
  * Responsive visibility rule for a single item at a specific breakpoint
@@ -76,16 +85,17 @@ export interface ToolbarChangedData {
76
85
  export interface ToolbarChangedEvent extends ToolbarChangedData {
77
86
  documentId: string;
78
87
  }
79
- export interface PanelChangedData {
88
+ export interface SidebarChangedData {
80
89
  placement: string;
81
90
  slot: string;
82
- panelId: string;
91
+ sidebarId: string;
83
92
  }
84
- export interface PanelChangedEvent extends PanelChangedData {
93
+ export interface SidebarChangedEvent extends SidebarChangedData {
85
94
  documentId: string;
86
95
  }
87
96
  export interface ModalChangedData {
88
97
  modalId: string | null;
98
+ isOpen: boolean;
89
99
  }
90
100
  export interface ModalChangedEvent extends ModalChangedData {
91
101
  documentId: string;
@@ -107,16 +117,18 @@ export interface UIScope {
107
117
  getActiveToolbar(placement: string, slot: string): string | null;
108
118
  closeToolbarSlot(placement: string, slot: string): void;
109
119
  isToolbarOpen(placement: string, slot: string, toolbarId?: string): boolean;
110
- setActivePanel(placement: string, slot: string, panelId: string, activeTab?: string): void;
111
- getActivePanel(placement: string, slot: string): string | null;
112
- closePanelSlot(placement: string, slot: string): void;
113
- togglePanel(placement: string, slot: string, panelId: string, activeTab?: string): void;
114
- setPanelTab(panelId: string, tabId: string): void;
115
- getPanelTab(panelId: string): string | null;
116
- isPanelOpen(placement: string, slot: string, panelId?: string): boolean;
120
+ setActiveSidebar(placement: string, slot: string, sidebarId: string, activeTab?: string): void;
121
+ getActiveSidebar(placement: string, slot: string): string | null;
122
+ closeSidebarSlot(placement: string, slot: string): void;
123
+ toggleSidebar(placement: string, slot: string, sidebarId: string, activeTab?: string): void;
124
+ setSidebarTab(sidebarId: string, tabId: string): void;
125
+ getSidebarTab(sidebarId: string): string | null;
126
+ isSidebarOpen(placement: string, slot: string, sidebarId?: string): boolean;
117
127
  openModal(modalId: string): void;
118
128
  closeModal(): void;
119
- getActiveModal(): string | null;
129
+ clearModal(): void;
130
+ getActiveModal(): ModalSlotState | null;
131
+ isModalOpen(): boolean;
120
132
  openMenu(menuId: string, triggeredByCommandId: string, triggeredByItemId: string): void;
121
133
  closeMenu(menuId: string): void;
122
134
  toggleMenu(menuId: string, triggeredByCommandId: string, triggeredByItemId: string): void;
@@ -130,13 +142,14 @@ export interface UIScope {
130
142
  slot: string;
131
143
  toolbarId: string;
132
144
  }>;
133
- onPanelChanged: EventHook<{
145
+ onSidebarChanged: EventHook<{
134
146
  placement: string;
135
147
  slot: string;
136
- panelId: string;
148
+ sidebarId: string;
137
149
  }>;
138
150
  onModalChanged: EventHook<{
139
151
  modalId: string | null;
152
+ isOpen: boolean;
140
153
  }>;
141
154
  onMenuChanged: EventHook<{
142
155
  menuId: string;
@@ -145,8 +158,8 @@ export interface UIScope {
145
158
  }
146
159
  export interface UICapability {
147
160
  setActiveToolbar(placement: string, slot: string, toolbarId: string, documentId?: string): void;
148
- setActivePanel(placement: string, slot: string, panelId: string, documentId?: string, activeTab?: string): void;
149
- togglePanel(placement: string, slot: string, panelId: string, documentId?: string, activeTab?: string): void;
161
+ setActiveSidebar(placement: string, slot: string, sidebarId: string, documentId?: string, activeTab?: string): void;
162
+ toggleSidebar(placement: string, slot: string, sidebarId: string, documentId?: string, activeTab?: string): void;
150
163
  openModal(modalId: string, documentId?: string): void;
151
164
  openMenu(menuId: string, triggeredByCommandId: string, triggeredByItemId: string, documentId?: string): void;
152
165
  toggleMenu(menuId: string, triggeredByCommandId: string, triggeredByItemId: string, documentId?: string): void;
@@ -159,21 +172,23 @@ export interface UICapability {
159
172
  setDisabledCategories(categories: string[]): void;
160
173
  getDisabledCategories(): string[];
161
174
  isCategoryDisabled(category: string): boolean;
175
+ getHiddenItems(): string[];
162
176
  onToolbarChanged: EventHook<{
163
177
  documentId: string;
164
178
  placement: string;
165
179
  slot: string;
166
180
  toolbarId: string;
167
181
  }>;
168
- onPanelChanged: EventHook<{
182
+ onSidebarChanged: EventHook<{
169
183
  documentId: string;
170
184
  placement: string;
171
185
  slot: string;
172
- panelId: string;
186
+ sidebarId: string;
173
187
  }>;
174
188
  onModalChanged: EventHook<{
175
189
  documentId: string;
176
190
  modalId: string | null;
191
+ isOpen: boolean;
177
192
  }>;
178
193
  onMenuChanged: EventHook<{
179
194
  documentId: string;
@@ -182,5 +197,6 @@ export interface UICapability {
182
197
  }>;
183
198
  onCategoryChanged: EventHook<{
184
199
  disabledCategories: string[];
200
+ hiddenItems: string[];
185
201
  }>;
186
202
  }
@@ -5,6 +5,7 @@ export declare class UIPlugin extends BasePlugin<UIPluginConfig, UICapability, U
5
5
  static readonly id: "ui";
6
6
  private schema;
7
7
  private stylesheetConfig;
8
+ private itemCategories;
8
9
  private cachedStylesheet;
9
10
  private cachedLocale;
10
11
  private i18n;
@@ -12,7 +13,7 @@ export declare class UIPlugin extends BasePlugin<UIPluginConfig, UICapability, U
12
13
  private readonly categoryChanged$;
13
14
  private readonly stylesheetInvalidated$;
14
15
  private readonly toolbarChanged$;
15
- private readonly panelChanged$;
16
+ private readonly sidebarChanged$;
16
17
  private readonly modalChanged$;
17
18
  private readonly menuChanged$;
18
19
  constructor(id: string, registry: PluginRegistry, config: UIPluginConfig);
@@ -52,16 +53,18 @@ export declare class UIPlugin extends BasePlugin<UIPluginConfig, UICapability, U
52
53
  private getToolbarForDocument;
53
54
  private closeToolbarForDocument;
54
55
  private isToolbarOpenForDocument;
55
- private setPanelForDocument;
56
- private getPanelForDocument;
57
- private closePanelForDocument;
58
- private togglePanelForDocument;
59
- private isPanelOpenForDocument;
60
- private setPanelTabForDocument;
61
- private getPanelTabForDocument;
56
+ private setSidebarForDocument;
57
+ private getSidebarForDocument;
58
+ private closeSidebarForDocument;
59
+ private toggleSidebarForDocument;
60
+ private isSidebarOpenForDocument;
61
+ private setSidebarTabForDocument;
62
+ private getSidebarTabForDocument;
62
63
  private openModalForDocument;
63
64
  private closeModalForDocument;
65
+ private clearModalForDocument;
64
66
  private getActiveModalForDocument;
67
+ private isModalOpenForDocument;
65
68
  private openMenuForDocument;
66
69
  private closeMenuForDocument;
67
70
  private toggleMenuForDocument;
@@ -12,6 +12,8 @@ export declare const UI_ATTRIBUTES: {
12
12
  readonly CATEGORIES: "data-epdf-cat";
13
13
  /** Disabled categories list on root element */
14
14
  readonly DISABLED_CATEGORIES: "data-epdf-dis";
15
+ /** Hidden item IDs (computed from disabled categories) */
16
+ readonly HIDDEN_ITEMS: "data-epdf-hid";
15
17
  };
16
18
  /**
17
19
  * CSS selectors derived from attributes
@@ -22,4 +24,5 @@ export declare const UI_SELECTORS: {
22
24
  readonly ITEM: (id: string) => string;
23
25
  readonly CATEGORIES: (category: string) => string;
24
26
  readonly DISABLED_CATEGORY: (category: string) => string;
27
+ readonly HIDDEN_ITEM: (itemId: string) => string;
25
28
  };
@@ -10,6 +10,6 @@ export declare function mergeUISchema(base: UISchema, override: Partial<UISchema
10
10
  export declare function removeFromSchema(schema: UISchema, options: {
11
11
  toolbars?: string[];
12
12
  menus?: string[];
13
- panels?: string[];
13
+ sidebars?: string[];
14
14
  commands?: string[];
15
15
  }): UISchema;
@@ -31,6 +31,23 @@ export declare function generateUIStylesheet(schema: UISchema, options?: Stylesh
31
31
  * @returns Sorted array of unique category names
32
32
  */
33
33
  export declare function extractCategories(schema: UISchema): string[];
34
+ /**
35
+ * Extract a map of item ID -> categories from the schema.
36
+ * Used to compute which items are hidden based on disabled categories.
37
+ *
38
+ * @param schema - The UI schema to extract item categories from
39
+ * @returns Map of item ID to array of categories
40
+ */
41
+ export declare function extractItemCategories(schema: UISchema): Map<string, string[]>;
42
+ /**
43
+ * Compute which items are hidden based on disabled categories.
44
+ * An item is hidden if ANY of its categories is disabled.
45
+ *
46
+ * @param itemCategories - Map of item ID to categories (from extractItemCategories)
47
+ * @param disabledCategories - Array of currently disabled categories
48
+ * @returns Array of hidden item IDs
49
+ */
50
+ export declare function computeHiddenItems(itemCategories: Map<string, string[]>, disabledCategories: string[]): string[];
34
51
  /**
35
52
  * Get the stylesheet configuration with defaults applied.
36
53
  *
@@ -1,7 +1,7 @@
1
1
  import { FunctionComponent } from 'preact';
2
2
  export { Fragment, createContext } from 'preact';
3
3
  export { useEffect, useRef, useState, useCallback, useMemo, useContext } from 'preact/hooks';
4
- export type { ComponentChildren as ReactNode } from 'preact';
4
+ export type { ComponentChildren as ReactNode, RefObject } from 'preact';
5
5
  export type CSSProperties = import('preact').JSX.CSSProperties;
6
6
  export type HTMLAttributes<T = any> = import('preact').JSX.HTMLAttributes<T extends EventTarget ? T : never>;
7
7
  export type ComponentType<P = any> = FunctionComponent<P>;
@@ -1,2 +1,2 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("@embedpdf/core/preact"),n=require("@embedpdf/plugin-ui"),t=require("preact"),r=require("preact/hooks"),o=require("preact/jsx-runtime"),s=()=>e.useCapability(n.UIPlugin.id),u=()=>e.usePlugin(n.UIPlugin.id),l=e=>{const{provides:n}=s(),[t,o]=r.useState(null);return r.useEffect(()=>{if(!n)return;const t=n.forDocument(e);o(t.getState());const r=t.onToolbarChanged(()=>o(t.getState())),s=t.onPanelChanged(()=>o(t.getState())),u=t.onModalChanged(()=>o(t.getState())),l=t.onMenuChanged(()=>o(t.getState()));return()=>{r(),s(),u(),l()}},[n,e]),t},c=t.createContext(null);function i({children:e}){const n=r.useRef(new Map),t={register:r.useCallback((e,t,r)=>{const o=`${e}:${t}`;n.current.set(o,r)},[]),unregister:r.useCallback((e,t)=>{const r=`${e}:${t}`;n.current.delete(r)},[]),getAnchor:r.useCallback((e,t)=>{const r=`${e}:${t}`;return n.current.get(r)||null},[])};return o.jsx(c.Provider,{value:t,children:e})}function a(){const e=r.useContext(c);if(!e)throw new Error("useAnchorRegistry must be used within UIProvider");return e}const d=t.createContext(null);function p({children:e,initialComponents:n={}}){const t=r.useRef(new Map(Object.entries(n))),s={register:r.useCallback((e,n)=>{t.current.set(e,n)},[]),unregister:r.useCallback(e=>{t.current.delete(e)},[]),get:r.useCallback(e=>t.current.get(e),[]),has:r.useCallback(e=>t.current.has(e),[]),getRegisteredIds:r.useCallback(()=>Array.from(t.current.keys()),[])};return o.jsx(d.Provider,{value:s,children:e})}function f(){const e=r.useContext(d);if(!e)throw new Error("useComponentRegistry must be used within UIProvider");return e}const m=t.createContext(null);function h({children:e,renderers:n}){return o.jsx(m.Provider,{value:n,children:e})}function g(){const e=r.useContext(m);if(!e)throw new Error("useRenderers must be used within UIProvider");return e}function I({container:e,documentId:n}){const t=l(n),{provides:u}=s(),c=a(),i=g(),[d,p]=r.useState(null),f=(null==t?void 0:t.openMenus)||{},m=null==u?void 0:u.getSchema();r.useEffect(()=>{const e=Object.keys(f);if(e.length>0){const t=e[0];if(!t)return void p(null);const r=f[t];if(r&&r.triggeredByItemId){const e=c.getAnchor(n,r.triggeredByItemId);p({menuId:t,anchorEl:e})}else p(null)}else p(null)},[f,c,n]);if(!d||!m)return null;const h=m.menus[d.menuId];if(!h)return console.warn(`Menu "${d.menuId}" not found in schema`),null;const I=i.menu;return o.jsx(I,{schema:h,documentId:n,anchorEl:d.anchorEl,onClose:()=>{d&&(null==u||u.forDocument(n).closeMenu(d.menuId))},container:e})}function v({children:e,...t}){const{plugin:l}=u(),{provides:c}=s(),[i,a]=r.useState([]),d=r.useRef(null),p=r.useRef(null),f=r.useRef(null),m=r.useCallback(e=>{const t=f.current;if(f.current=e,e&&e!==t&&l){const t=function(e){const n=e.getRootNode();return n instanceof ShadowRoot?n:document.head}(e);p.current=t;const r=t.querySelector(n.UI_SELECTORS.STYLES);if(r)return d.current=r,void(r.textContent=l.getStylesheet());const o=l.getStylesheet(),s=document.createElement("style");s.setAttribute(n.UI_ATTRIBUTES.STYLES,""),s.textContent=o,t instanceof ShadowRoot?t.insertBefore(s,t.firstChild):t.appendChild(s),d.current=s}},[l]);r.useEffect(()=>()=>{var e;(null==(e=d.current)?void 0:e.parentNode)&&!f.current&&d.current.remove(),d.current=null,p.current=null},[]),r.useEffect(()=>{if(l)return l.onStylesheetInvalidated(()=>{d.current&&(d.current.textContent=l.getStylesheet())})},[l]),r.useEffect(()=>{if(c)return a(c.getDisabledCategories()),c.onCategoryChanged(({disabledCategories:e})=>{a(e)})},[c]);const h=r.useMemo(()=>i.length>0?i.join(" "):void 0,[i]),g={[n.UI_ATTRIBUTES.ROOT]:"",[n.UI_ATTRIBUTES.DISABLED_CATEGORIES]:h};return o.jsx("div",{ref:m,...g,...t,style:{containerType:"inline-size",...t.style},children:e})}exports.AnchorRegistryProvider=i,exports.ComponentRegistryProvider=p,exports.RenderersProvider=h,exports.UIProvider=function({children:e,documentId:n,components:t={},renderers:r,menuContainer:s,...u}){return o.jsx(i,{children:o.jsx(p,{initialComponents:t,children:o.jsx(h,{renderers:r,children:o.jsxs(v,{...u,children:[e,o.jsx(I,{documentId:n,container:s})]})})})})},exports.useAnchorRegistry=a,exports.useComponentRegistry=f,exports.useItemRenderer=function(){const e=f();return{renderCustomComponent:(n,t,r)=>{const s=e.get(n);return s?o.jsx(s,{documentId:t,...r||{}}):(console.error(`Component "${n}" not found in registry`),null)}}},exports.useRegisterAnchor=function(e,n){const t=a(),o=r.useRef(null),s=r.useRef(e),u=r.useRef(n);return s.current=e,u.current=n,r.useCallback(e=>{const n=o.current;o.current=e,e?e!==n&&t.register(s.current,u.current,e):n&&t.unregister(s.current,u.current)},[t])},exports.useRenderers=g,exports.useSchemaRenderer=function(e){const n=g(),{provides:t}=s(),r=null==t?void 0:t.getSchema(),u=l(e);return{renderToolbar:(s,l)=>{if(!r||!t||!u)return null;const c=`${s}-${l}`,i=u.activeToolbars[c];if(!i)return null;const a=r.toolbars[i.toolbarId];if(!a)return console.warn(`Toolbar "${i.toolbarId}" not found in schema`),null;const d=!a.permanent?()=>{t.forDocument(e).closeToolbarSlot(s,l)}:void 0,p=n.toolbar;return o.jsx(p,{schema:a,documentId:e,isOpen:i.isOpen,onClose:d},i.toolbarId)},renderPanel:(s,l)=>{if(!r||!t||!u)return null;const c=`${s}-${l}`,i=u.activePanels[c];if(!i)return null;const a=r.panels[i.panelId];if(!a)return console.warn(`Panel "${i.panelId}" not found in schema`),null;const d=n.panel;return o.jsx(d,{schema:a,documentId:e,isOpen:i.isOpen,onClose:()=>{t.forDocument(e).closePanelSlot(s,l)}},i.panelId)},getActiveToolbars:()=>u?Object.entries(u.activeToolbars).map(([e,n])=>{const[t,r]=e.split("-");return{placement:t,slot:r,toolbarId:n.toolbarId,isOpen:n.isOpen}}):[],getActivePanels:()=>u?Object.entries(u.activePanels).map(([e,n])=>{const[t,r]=e.split("-");return{placement:t,slot:r,panelId:n.panelId,isOpen:n.isOpen}}):[]}},exports.useSelectionMenu=function(e,n){var t;const{provides:u}=s(),l=g(),c=r.useCallback(t=>{var r;const s=null==u?void 0:u.getSchema(),c=null==(r=null==s?void 0:s.selectionMenus)?void 0:r[e];if(!c)return null;if(!t.selected)return null;const i=l.selectionMenu;return o.jsx(i,{schema:c,documentId:n,props:t})},[u,l,e,n]),i=null==u?void 0:u.getSchema();if(null==(t=null==i?void 0:i.selectionMenus)?void 0:t[e])return c},exports.useUICapability=s,exports.useUIPlugin=u,exports.useUISchema=()=>{const{provides:e}=s();return(null==e?void 0:e.getSchema())??null},exports.useUIState=l,Object.keys(n).forEach(e=>{"default"===e||Object.prototype.hasOwnProperty.call(exports,e)||Object.defineProperty(exports,e,{enumerable:!0,get:()=>n[e]})});
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("@embedpdf/core/preact"),n=require("@embedpdf/plugin-ui"),t=require("preact"),r=require("preact/hooks"),o=require("preact/jsx-runtime"),s=()=>e.useCapability(n.UIPlugin.id),u=()=>e.usePlugin(n.UIPlugin.id),l=e=>{const{provides:n}=s(),[t,o]=r.useState(null);return r.useEffect(()=>{if(!n)return;const t=n.forDocument(e);o(t.getState());const r=t.onToolbarChanged(()=>o(t.getState())),s=t.onSidebarChanged(()=>o(t.getState())),u=t.onModalChanged(()=>o(t.getState())),l=t.onMenuChanged(()=>o(t.getState()));return()=>{r(),s(),u(),l()}},[n,e]),t},c=t.createContext(null);const i=t.createContext(null);function d({children:e}){const n=r.useRef(new Map),t={register:r.useCallback((e,t,r)=>{const o=`${e}:${t}`;n.current.set(o,r)},[]),unregister:r.useCallback((e,t)=>{const r=`${e}:${t}`;n.current.delete(r)},[]),getAnchor:r.useCallback((e,t)=>{const r=`${e}:${t}`;return n.current.get(r)||null},[])};return o.jsx(i.Provider,{value:t,children:e})}function a(){const e=r.useContext(i);if(!e)throw new Error("useAnchorRegistry must be used within UIProvider");return e}const f=t.createContext(null);function m({children:e,initialComponents:n={}}){const t=r.useRef(new Map(Object.entries(n))),s={register:r.useCallback((e,n)=>{t.current.set(e,n)},[]),unregister:r.useCallback(e=>{t.current.delete(e)},[]),get:r.useCallback(e=>t.current.get(e),[]),has:r.useCallback(e=>t.current.has(e),[]),getRegisteredIds:r.useCallback(()=>Array.from(t.current.keys()),[])};return o.jsx(f.Provider,{value:s,children:e})}function p(){const e=r.useContext(f);if(!e)throw new Error("useComponentRegistry must be used within UIProvider");return e}const h=t.createContext(null);function g({children:e,renderers:n}){return o.jsx(h.Provider,{value:n,children:e})}function v(){const e=r.useContext(h);if(!e)throw new Error("useRenderers must be used within UIProvider");return e}function b({container:e,documentId:n}){const t=l(n),{provides:u}=s(),c=a(),i=v(),[d,f]=r.useState(null),m=(null==t?void 0:t.openMenus)||{},p=null==u?void 0:u.getSchema();r.useEffect(()=>{const e=Object.keys(m);if(e.length>0){const t=e[0];if(!t)return void f(null);const r=m[t];if(r&&r.triggeredByItemId){const e=c.getAnchor(n,r.triggeredByItemId);f({menuId:t,anchorEl:e})}else f(null)}else f(null)},[m,c,n]);if(!d||!p)return null;const h=p.menus[d.menuId];if(!h)return console.warn(`Menu "${d.menuId}" not found in schema`),null;const g=i.menu;return o.jsx(g,{schema:h,documentId:n,anchorEl:d.anchorEl,onClose:()=>{d&&(null==u||u.forDocument(n).closeMenu(d.menuId))},container:e})}function I({children:e,style:t,...l}){const{plugin:i}=u(),{provides:d}=s(),[a,f]=r.useState([]),[m,p]=r.useState([]),h=r.useRef(null),g=r.useRef(null),v=r.useRef(null),b=r.useRef(null),I=r.useMemo(()=>({containerRef:b,getContainer:()=>b.current}),[]),C=r.useCallback(e=>{const t=v.current;if(v.current=e,b.current=e,e&&e!==t&&i){const t=function(e){const n=e.getRootNode();return n instanceof ShadowRoot?n:document.head}(e);g.current=t;const r=t.querySelector(n.UI_SELECTORS.STYLES);if(r)return h.current=r,void(r.textContent=i.getStylesheet());const o=i.getStylesheet(),s=document.createElement("style");s.setAttribute(n.UI_ATTRIBUTES.STYLES,""),s.textContent=o,t instanceof ShadowRoot?t.insertBefore(s,t.firstChild):t.appendChild(s),h.current=s}},[i]);r.useEffect(()=>()=>{var e;(null==(e=h.current)?void 0:e.parentNode)&&!v.current&&h.current.remove(),h.current=null,g.current=null},[]),r.useEffect(()=>{if(i)return i.onStylesheetInvalidated(()=>{h.current&&(h.current.textContent=i.getStylesheet())})},[i]),r.useEffect(()=>{if(d)return f(d.getDisabledCategories()),p(d.getHiddenItems()),d.onCategoryChanged(({disabledCategories:e,hiddenItems:n})=>{f(e),p(n)})},[d]);const x=r.useMemo(()=>a.length>0?a.join(" "):void 0,[a]),S=r.useMemo(()=>m.length>0?m.join(" "):void 0,[m]),y=r.useMemo(()=>{const e={containerType:"inline-size"};return t&&"object"==typeof t?{...e,...t}:e},[t]),R={[n.UI_ATTRIBUTES.ROOT]:"",[n.UI_ATTRIBUTES.DISABLED_CATEGORIES]:x,[n.UI_ATTRIBUTES.HIDDEN_ITEMS]:S};return o.jsx(c.Provider,{value:I,children:o.jsx("div",{ref:C,...R,...l,style:y,children:e})})}exports.AnchorRegistryProvider=d,exports.ComponentRegistryProvider=m,exports.RenderersProvider=g,exports.UIContainerContext=c,exports.UIProvider=function({children:e,documentId:n,components:t={},renderers:r,menuContainer:s,...u}){return o.jsx(d,{children:o.jsx(m,{initialComponents:t,children:o.jsx(g,{renderers:r,children:o.jsxs(I,{...u,children:[e,o.jsx(b,{documentId:n,container:s})]})})})})},exports.useAnchorRegistry=a,exports.useComponentRegistry=p,exports.useItemRenderer=function(){const e=p();return{renderCustomComponent:(n,t,r)=>{const s=e.get(n);return s?o.jsx(s,{documentId:t,...r||{}}):(console.error(`Component "${n}" not found in registry`),null)}}},exports.useRegisterAnchor=function(e,n){const t=a(),o=r.useRef(null),s=r.useRef(e),u=r.useRef(n);return s.current=e,u.current=n,r.useCallback(e=>{const n=o.current;o.current=e,e?e!==n&&t.register(s.current,u.current,e):n&&t.unregister(s.current,u.current)},[t])},exports.useRenderers=v,exports.useSchemaRenderer=function(e){const n=v(),{provides:t}=s(),r=null==t?void 0:t.getSchema(),u=l(e);return{renderToolbar:(s,l)=>{if(!r||!t||!u)return null;const c=`${s}-${l}`,i=u.activeToolbars[c];if(!i)return null;const d=r.toolbars[i.toolbarId];if(!d)return console.warn(`Toolbar "${i.toolbarId}" not found in schema`),null;const a=!d.permanent?()=>{t.forDocument(e).closeToolbarSlot(s,l)}:void 0,f=n.toolbar;return o.jsx(f,{schema:d,documentId:e,isOpen:i.isOpen,onClose:a},i.toolbarId)},renderSidebar:(s,l)=>{var c;if(!r||!t||!u)return null;const i=`${s}-${l}`,d=u.activeSidebars[i];if(!d)return null;const a=null==(c=r.sidebars)?void 0:c[d.sidebarId];if(!a)return console.warn(`Sidebar "${d.sidebarId}" not found in schema`),null;const f=n.sidebar;return o.jsx(f,{schema:a,documentId:e,isOpen:d.isOpen,onClose:()=>{t.forDocument(e).closeSidebarSlot(s,l)}},d.sidebarId)},renderModal:()=>{var s;if(!r||!t||!(null==u?void 0:u.activeModal))return null;const{modalId:l,isOpen:c}=u.activeModal,i=null==(s=r.modals)?void 0:s[l];if(!i)return console.warn(`Modal "${l}" not found in schema`),null;const d=n.modal;return d?o.jsx(d,{schema:i,documentId:e,isOpen:c,onClose:()=>{t.forDocument(e).closeModal()},onExited:()=>{t.forDocument(e).clearModal()}},l):(console.warn("No modal renderer registered"),null)},getActiveToolbars:()=>u?Object.entries(u.activeToolbars).map(([e,n])=>{const[t,r]=e.split("-");return{placement:t,slot:r,toolbarId:n.toolbarId,isOpen:n.isOpen}}):[],getActiveSidebars:()=>u?Object.entries(u.activeSidebars).map(([e,n])=>{const[t,r]=e.split("-");return{placement:t,slot:r,sidebarId:n.sidebarId,isOpen:n.isOpen}}):[],renderOverlays:()=>{if(!(null==r?void 0:r.overlays)||!t)return null;const s=n.overlay;if(!s)return null;const u=Object.values(r.overlays);return 0===u.length?null:o.jsx(o.Fragment,{children:u.map(n=>o.jsx(s,{schema:n,documentId:e},n.id))})}}},exports.useSelectionMenu=function(e,n){var t;const{provides:u}=s(),l=v(),c=r.useCallback(t=>{var r;const s=null==u?void 0:u.getSchema(),c=null==(r=null==s?void 0:s.selectionMenus)?void 0:r[e];if(!c)return null;if(!t.selected)return null;const i=l.selectionMenu;return o.jsx(i,{schema:c,documentId:n,props:t})},[u,l,e,n]),i=null==u?void 0:u.getSchema();if(null==(t=null==i?void 0:i.selectionMenus)?void 0:t[e])return c},exports.useUICapability=s,exports.useUIContainer=function(){const e=r.useContext(c);if(!e)throw new Error("useUIContainer must be used within a UIProvider");return e},exports.useUIPlugin=u,exports.useUISchema=()=>{const{provides:e}=s();return(null==e?void 0:e.getSchema())??null},exports.useUIState=l,Object.keys(n).forEach(e=>{"default"===e||Object.prototype.hasOwnProperty.call(exports,e)||Object.defineProperty(exports,e,{enumerable:!0,get:()=>n[e]})});
2
2
  //# sourceMappingURL=index.cjs.map