@embedpdf/plugin-ui 2.1.2 → 2.3.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.js CHANGED
@@ -5,8 +5,7 @@ const manifest = {
5
5
  name: "UI Plugin",
6
6
  version: "1.0.0",
7
7
  provides: ["ui"],
8
- requires: ["commands"],
9
- // Depends on commands
8
+ requires: [],
10
9
  optional: ["i18n"],
11
10
  defaultConfig: {
12
11
  schema: {
@@ -33,6 +32,7 @@ const CLEAR_MODAL = "UI/CLEAR_MODAL";
33
32
  const OPEN_MENU = "UI/OPEN_MENU";
34
33
  const CLOSE_MENU = "UI/CLOSE_MENU";
35
34
  const CLOSE_ALL_MENUS = "UI/CLOSE_ALL_MENUS";
35
+ const SET_OVERLAY_ENABLED = "UI/SET_OVERLAY_ENABLED";
36
36
  const SET_DISABLED_CATEGORIES = "UI/SET_DISABLED_CATEGORIES";
37
37
  const SET_HIDDEN_ITEMS = "UI/SET_HIDDEN_ITEMS";
38
38
  const initUIState = (documentId, schema) => ({
@@ -87,6 +87,10 @@ const closeAllMenus = (documentId) => ({
87
87
  type: CLOSE_ALL_MENUS,
88
88
  payload: { documentId }
89
89
  });
90
+ const setOverlayEnabled = (documentId, overlayId, enabled) => ({
91
+ type: SET_OVERLAY_ENABLED,
92
+ payload: { documentId, overlayId, enabled }
93
+ });
90
94
  const setDisabledCategories = (categories) => ({
91
95
  type: SET_DISABLED_CATEGORIES,
92
96
  payload: { categories }
@@ -777,6 +781,7 @@ const _UIPlugin = class _UIPlugin extends BasePlugin {
777
781
  (documentId, data) => ({ documentId, ...data }),
778
782
  { cache: false }
779
783
  );
784
+ this.overlayChanged$ = createScopedEmitter((documentId, data) => ({ documentId, ...data }), { cache: false });
780
785
  this.schema = config.schema;
781
786
  this.stylesheetConfig = config.stylesheetConfig || {};
782
787
  this.itemCategories = extractItemCategories(this.schema);
@@ -805,6 +810,7 @@ const _UIPlugin = class _UIPlugin extends BasePlugin {
805
810
  this.sidebarChanged$.clear();
806
811
  this.modalChanged$.clear();
807
812
  this.menuChanged$.clear();
813
+ this.overlayChanged$.clear();
808
814
  this.stylesheetInvalidated$.clear();
809
815
  super.destroy();
810
816
  }
@@ -817,6 +823,7 @@ const _UIPlugin = class _UIPlugin extends BasePlugin {
817
823
  this.sidebarChanged$.clearScope(documentId);
818
824
  this.modalChanged$.clearScope(documentId);
819
825
  this.menuChanged$.clearScope(documentId);
826
+ this.overlayChanged$.clearScope(documentId);
820
827
  }
821
828
  /**
822
829
  * Handle locale changes from i18n plugin.
@@ -917,6 +924,10 @@ const _UIPlugin = class _UIPlugin extends BasePlugin {
917
924
  openModal: (modalId, documentId) => this.openModalForDocument(modalId, documentId),
918
925
  openMenu: (menuId, triggeredByCommandId, triggeredByItemId, documentId) => this.openMenuForDocument(menuId, triggeredByCommandId, triggeredByItemId, documentId),
919
926
  toggleMenu: (menuId, triggeredByCommandId, triggeredByItemId, documentId) => this.toggleMenuForDocument(menuId, triggeredByCommandId, triggeredByItemId, documentId),
927
+ // Overlay operations
928
+ enableOverlay: (overlayId, documentId) => this.enableOverlayForDocument(overlayId, documentId),
929
+ disableOverlay: (overlayId, documentId) => this.disableOverlayForDocument(overlayId, documentId),
930
+ toggleOverlay: (overlayId, documentId) => this.toggleOverlayForDocument(overlayId, documentId),
920
931
  // Document-scoped operations
921
932
  forDocument: (documentId) => this.createUIScope(documentId),
922
933
  // Schema
@@ -937,6 +948,7 @@ const _UIPlugin = class _UIPlugin extends BasePlugin {
937
948
  onSidebarChanged: this.sidebarChanged$.onGlobal,
938
949
  onModalChanged: this.modalChanged$.onGlobal,
939
950
  onMenuChanged: this.menuChanged$.onGlobal,
951
+ onOverlayChanged: this.overlayChanged$.onGlobal,
940
952
  onCategoryChanged: this.categoryChanged$.on
941
953
  };
942
954
  }
@@ -972,6 +984,12 @@ const _UIPlugin = class _UIPlugin extends BasePlugin {
972
984
  closeAllMenus: () => this.closeAllMenusForDocument(documentId),
973
985
  isMenuOpen: (menuId) => this.isMenuOpenForDocument(menuId, documentId),
974
986
  getOpenMenus: () => this.getOpenMenusForDocument(documentId),
987
+ // ───── Overlays ─────
988
+ enableOverlay: (overlayId) => this.enableOverlayForDocument(overlayId, documentId),
989
+ disableOverlay: (overlayId) => this.disableOverlayForDocument(overlayId, documentId),
990
+ toggleOverlay: (overlayId) => this.toggleOverlayForDocument(overlayId, documentId),
991
+ isOverlayEnabled: (overlayId) => this.isOverlayEnabledForDocument(overlayId, documentId),
992
+ getEnabledOverlays: () => this.getEnabledOverlaysForDocument(documentId),
975
993
  // ───── Schema & state ─────
976
994
  getSchema: () => this.schema,
977
995
  getState: () => this.getDocumentStateOrThrow(documentId),
@@ -979,7 +997,8 @@ const _UIPlugin = class _UIPlugin extends BasePlugin {
979
997
  onToolbarChanged: this.toolbarChanged$.forScope(documentId),
980
998
  onSidebarChanged: this.sidebarChanged$.forScope(documentId),
981
999
  onModalChanged: this.modalChanged$.forScope(documentId),
982
- onMenuChanged: this.menuChanged$.forScope(documentId)
1000
+ onMenuChanged: this.menuChanged$.forScope(documentId),
1001
+ onOverlayChanged: this.overlayChanged$.forScope(documentId)
983
1002
  };
984
1003
  }
985
1004
  // ─────────────────────────────────────────────────────────
@@ -1125,6 +1144,36 @@ const _UIPlugin = class _UIPlugin extends BasePlugin {
1125
1144
  getOpenMenusForDocument(documentId) {
1126
1145
  return Object.values(this.getDocumentStateOrThrow(documentId).openMenus);
1127
1146
  }
1147
+ // ─────────────────────────────────────────────────────────
1148
+ // Core Operations - Overlays
1149
+ // ─────────────────────────────────────────────────────────
1150
+ enableOverlayForDocument(overlayId, documentId) {
1151
+ const id = documentId ?? this.getActiveDocumentId();
1152
+ this.dispatch(setOverlayEnabled(id, overlayId, true));
1153
+ this.overlayChanged$.emit(id, { overlayId, isEnabled: true });
1154
+ }
1155
+ disableOverlayForDocument(overlayId, documentId) {
1156
+ const id = documentId ?? this.getActiveDocumentId();
1157
+ this.dispatch(setOverlayEnabled(id, overlayId, false));
1158
+ this.overlayChanged$.emit(id, { overlayId, isEnabled: false });
1159
+ }
1160
+ toggleOverlayForDocument(overlayId, documentId) {
1161
+ const id = documentId ?? this.getActiveDocumentId();
1162
+ const isEnabled = this.isOverlayEnabledForDocument(overlayId, id);
1163
+ if (isEnabled) {
1164
+ this.disableOverlayForDocument(overlayId, id);
1165
+ } else {
1166
+ this.enableOverlayForDocument(overlayId, id);
1167
+ }
1168
+ }
1169
+ isOverlayEnabledForDocument(overlayId, documentId) {
1170
+ const enabledOverlays = this.getDocumentStateOrThrow(documentId).enabledOverlays;
1171
+ return enabledOverlays[overlayId] ?? true;
1172
+ }
1173
+ getEnabledOverlaysForDocument(documentId) {
1174
+ const enabledOverlays = this.getDocumentStateOrThrow(documentId).enabledOverlays;
1175
+ return Object.entries(enabledOverlays).filter(([, enabled]) => enabled).map(([overlayId]) => overlayId);
1176
+ }
1128
1177
  };
1129
1178
  _UIPlugin.id = "ui";
1130
1179
  let UIPlugin = _UIPlugin;
@@ -1133,7 +1182,8 @@ const initialDocumentState = {
1133
1182
  activeSidebars: {},
1134
1183
  activeModal: null,
1135
1184
  openMenus: {},
1136
- sidebarTabs: {}
1185
+ sidebarTabs: {},
1186
+ enabledOverlays: {}
1137
1187
  };
1138
1188
  const initialState = {
1139
1189
  documents: {},
@@ -1156,14 +1206,22 @@ const uiReducer = (state = initialState, action) => {
1156
1206
  };
1157
1207
  }
1158
1208
  });
1209
+ const enabledOverlays = {};
1210
+ if (schema.overlays) {
1211
+ Object.values(schema.overlays).forEach((overlay) => {
1212
+ enabledOverlays[overlay.id] = overlay.defaultEnabled ?? true;
1213
+ });
1214
+ }
1159
1215
  return {
1160
1216
  ...state,
1161
1217
  documents: {
1162
1218
  ...state.documents,
1163
1219
  [documentId]: {
1164
1220
  ...initialDocumentState,
1165
- activeToolbars
1221
+ activeToolbars,
1166
1222
  // Initialize with permanent toolbars
1223
+ enabledOverlays
1224
+ // Initialize with overlay enabled states
1167
1225
  }
1168
1226
  }
1169
1227
  };
@@ -1402,6 +1460,26 @@ const uiReducer = (state = initialState, action) => {
1402
1460
  }
1403
1461
  };
1404
1462
  }
1463
+ // ─────────────────────────────────────────────────────────
1464
+ // Overlay Actions
1465
+ // ─────────────────────────────────────────────────────────
1466
+ case SET_OVERLAY_ENABLED: {
1467
+ const { documentId, overlayId, enabled } = action.payload;
1468
+ const docState = state.documents[documentId] || initialDocumentState;
1469
+ return {
1470
+ ...state,
1471
+ documents: {
1472
+ ...state.documents,
1473
+ [documentId]: {
1474
+ ...docState,
1475
+ enabledOverlays: {
1476
+ ...docState.enabledOverlays,
1477
+ [overlayId]: enabled
1478
+ }
1479
+ }
1480
+ }
1481
+ };
1482
+ }
1405
1483
  case SET_DISABLED_CATEGORIES: {
1406
1484
  return {
1407
1485
  ...state,
@@ -1469,6 +1547,7 @@ export {
1469
1547
  SET_ACTIVE_TOOLBAR,
1470
1548
  SET_DISABLED_CATEGORIES,
1471
1549
  SET_HIDDEN_ITEMS,
1550
+ SET_OVERLAY_ENABLED,
1472
1551
  SET_SIDEBAR_TAB,
1473
1552
  UIPlugin,
1474
1553
  UIPluginPackage,
@@ -1506,6 +1585,7 @@ export {
1506
1585
  setActiveToolbar,
1507
1586
  setDisabledCategories,
1508
1587
  setHiddenItems,
1588
+ setOverlayEnabled,
1509
1589
  setSidebarTab
1510
1590
  };
1511
1591
  //# sourceMappingURL=index.js.map