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