@casualoffice/sheets 0.11.1 → 0.13.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 CHANGED
@@ -41,8 +41,10 @@ __export(src_exports, {
41
41
  SigningProvider: () => SigningProvider,
42
42
  TypedSignatureField: () => TypedSignatureField,
43
43
  UploadedSignatureField: () => UploadedSignatureField,
44
+ applyReadOnly: () => applyReadOnly,
44
45
  createCasualSheetsAPI: () => createCasualSheetsAPI,
45
46
  createSigningController: () => createSigningController,
47
+ getEditable: () => getEditable,
46
48
  isCasualEnvelope: () => isCasualEnvelope,
47
49
  useSigning: () => useSigning
48
50
  });
@@ -1540,6 +1542,53 @@ function applyAppearance(api, container, appearance) {
1540
1542
  }
1541
1543
  }
1542
1544
 
1545
+ // src/sheets/read-only.ts
1546
+ var import_core3 = require("@univerjs/core");
1547
+ var import_sheets2 = require("@univerjs/sheets");
1548
+ var READONLY_BLOCK = /(set-cell-edit-visible|set-activate-cell-edit|set-range-values|set-style|set-bold|set-italic|set-underline|set-strike|set-font|set-background|set-text|set-horizontal|set-vertical|set-wrap|set-rotation|set-border|set-number-format|insert-|delete-|remove-|clear-selection|cut-content|paste|move-range|move-rows|move-cols|merge|split|add-worksheet|set-worksheet-name|set-worksheet-row|set-worksheet-col|auto-fill|reorder|set-defined-name|set-tab-color|set-frozen-cancel)/;
1549
+ function applyReadOnly(univerApi, unitId, onBlock) {
1550
+ const injector = univerApi._injector;
1551
+ const cmd = injector?.get(import_core3.ICommandService);
1552
+ const vetoDisposable = cmd?.beforeCommandExecuted((info) => {
1553
+ if (READONLY_BLOCK.test(info.id)) {
1554
+ onBlock?.(info.id);
1555
+ throw new import_core3.CustomCommandExecutionError(`read-only: blocked ${info.id}`);
1556
+ }
1557
+ });
1558
+ const svc = injector?.get(import_core3.IPermissionService);
1559
+ const id = new import_sheets2.WorkbookEditablePermission(unitId).id;
1560
+ let prev;
1561
+ if (svc) {
1562
+ try {
1563
+ const existing = svc.getPermissionPoint(id);
1564
+ if (existing) {
1565
+ prev = existing.value;
1566
+ svc.updatePermissionPoint(id, false);
1567
+ } else {
1568
+ const point = new import_sheets2.WorkbookEditablePermission(unitId);
1569
+ point.value = false;
1570
+ svc.addPermissionPoint(point);
1571
+ }
1572
+ } catch {
1573
+ }
1574
+ }
1575
+ return () => {
1576
+ vetoDisposable?.dispose();
1577
+ try {
1578
+ svc?.updatePermissionPoint(id, prev === void 0 ? true : prev);
1579
+ } catch {
1580
+ }
1581
+ };
1582
+ }
1583
+ function getEditable(univerApi, unitId) {
1584
+ const injector = univerApi._injector;
1585
+ const svc = injector?.get(import_core3.IPermissionService);
1586
+ if (!svc) return void 0;
1587
+ const id = new import_sheets2.WorkbookEditablePermission(unitId).id;
1588
+ const point = svc.getPermissionPoint(id);
1589
+ return point ? point.value : void 0;
1590
+ }
1591
+
1543
1592
  // src/sheets/CasualSheetsIframe.tsx
1544
1593
  var import_react5 = require("react");
1545
1594
  var import_jsx_runtime5 = require("react/jsx-runtime");
@@ -1653,7 +1702,7 @@ var CasualSheetsIframe = (0, import_react5.forwardRef)(
1653
1702
  apiRef.current = {
1654
1703
  setViewMode: (mode) => transportRef.current?.sendSetViewMode({ viewMode: mode }),
1655
1704
  iframe: () => iframeRef.current,
1656
- executeCommand: (command) => transportRef.current?.sendCommandExecute({ command })
1705
+ executeCommand: (command, args) => transportRef.current?.sendCommandExecute({ command, args })
1657
1706
  };
1658
1707
  }
1659
1708
  const url = `${embedBasePath}/embed.html?app=sheet&docId=${encodeURIComponent(docId)}&viewMode=${viewMode}`;