@casualoffice/sheets 0.9.0 → 0.10.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.
Files changed (67) hide show
  1. package/dist/api-BI2VLYQ6.d.cts +62 -0
  2. package/dist/api-BI2VLYQ6.d.ts +62 -0
  3. package/dist/chrome.cjs +2569 -0
  4. package/dist/chrome.cjs.map +1 -0
  5. package/dist/chrome.d.cts +96 -0
  6. package/dist/chrome.d.ts +96 -0
  7. package/dist/chrome.js +2556 -0
  8. package/dist/chrome.js.map +1 -0
  9. package/dist/collab.cjs +770 -0
  10. package/dist/collab.cjs.map +1 -0
  11. package/dist/collab.d.cts +248 -0
  12. package/dist/collab.d.ts +248 -0
  13. package/dist/collab.js +737 -0
  14. package/dist/collab.js.map +1 -0
  15. package/dist/embed/embed-runtime.js +128 -128
  16. package/dist/embed.cjs +166 -0
  17. package/dist/embed.cjs.map +1 -1
  18. package/dist/embed.d.cts +78 -3
  19. package/dist/embed.d.ts +78 -3
  20. package/dist/embed.js +166 -0
  21. package/dist/embed.js.map +1 -1
  22. package/dist/index.cjs +262 -165
  23. package/dist/index.cjs.map +1 -1
  24. package/dist/index.d.cts +4 -3
  25. package/dist/index.d.ts +4 -3
  26. package/dist/index.js +271 -168
  27. package/dist/index.js.map +1 -1
  28. package/dist/{protocol--KyBQUjU.d.cts → protocol-Cq4Cdoyi.d.cts} +19 -2
  29. package/dist/{protocol-cEzy7S0i.d.ts → protocol-DqDaG2yG.d.ts} +19 -2
  30. package/dist/sheets.cjs +102 -16
  31. package/dist/sheets.cjs.map +1 -1
  32. package/dist/sheets.d.cts +49 -63
  33. package/dist/sheets.d.ts +49 -63
  34. package/dist/sheets.js +111 -19
  35. package/dist/sheets.js.map +1 -1
  36. package/package.json +28 -3
  37. package/src/chrome/AutoSumPicker.tsx +176 -0
  38. package/src/chrome/BordersPicker.tsx +171 -0
  39. package/src/chrome/ChromeBottom.tsx +18 -0
  40. package/src/chrome/ChromeTop.tsx +21 -0
  41. package/src/chrome/ColorPicker.tsx +220 -0
  42. package/src/chrome/FindReplace.tsx +370 -0
  43. package/src/chrome/FormulaBar.tsx +378 -0
  44. package/src/chrome/Icon.tsx +43 -0
  45. package/src/chrome/MenuBar.tsx +336 -0
  46. package/src/chrome/NameBox.tsx +347 -0
  47. package/src/chrome/SheetTabs.tsx +346 -0
  48. package/src/chrome/StatusBar.tsx +232 -0
  49. package/src/chrome/Toolbar.tsx +401 -0
  50. package/src/chrome/fonts.ts +42 -0
  51. package/src/chrome/index.ts +24 -0
  52. package/src/collab/attachCollab.ts +151 -0
  53. package/src/collab/bridge-helpers.ts +97 -0
  54. package/src/collab/bridge.ts +885 -0
  55. package/src/collab/bridge.unit.test.ts +160 -0
  56. package/src/collab/index.ts +38 -0
  57. package/src/collab/replay-retry.ts +137 -0
  58. package/src/collab/replay-retry.unit.test.ts +223 -0
  59. package/src/collab/ws-url.ts +20 -0
  60. package/src/collab/ws-url.unit.test.ts +35 -0
  61. package/src/embed/EmbedHostTransport.ts +16 -1
  62. package/src/embed/EmbedTransport.ts +16 -0
  63. package/src/embed/EmbedTransport.unit.test.ts +88 -2
  64. package/src/embed/index.ts +7 -0
  65. package/src/embed/protocol.ts +34 -0
  66. package/src/embed-runtime/index.tsx +20 -0
  67. package/src/sheets/CasualSheets.tsx +204 -33
@@ -0,0 +1,97 @@
1
+ /**
2
+ * Pure helpers extracted from bridge.ts so they're testable without
3
+ * pulling Univer / Yjs / Vite-only globals into a Node test runner.
4
+ *
5
+ * Anything stateless and Univer-free that bridge.ts needs should live
6
+ * here. Stateful bridge logic (Yjs observers, command service hooks,
7
+ * compaction) stays in bridge.ts itself.
8
+ */
9
+
10
+ /**
11
+ * Substitute `localUnitId` for every `unitId` string property anywhere
12
+ * in `value` — including nested objects and arrays — and return a
13
+ * structurally cloned copy. Returns the input by reference when no
14
+ * change is needed, so callers can identity-compare before re-encoding.
15
+ *
16
+ * Walks plain objects and arrays only. Class instances are left alone
17
+ * because Univer mutation params are required to be JSON-friendly.
18
+ */
19
+ /**
20
+ * Drawing mutations (sheets-drawing + drawing plugins) carry an
21
+ * `op` field that's a json1 patch — a positional array whose first
22
+ * element is the unitId. `deepRewriteUnitId` only rewrites the
23
+ * `unitId` KEY in objects; the json1 path is a bare array of strings
24
+ * so the unitId at position 0 stays as the OWNER's id and the apply
25
+ * fails on the joiner with no useful message ("Error" at
26
+ * json1.type.apply).
27
+ *
28
+ * This walks the op shape — single JSONOp (array of mixed strings +
29
+ * numbers + a final mutation component object) OR JSONOpList (array
30
+ * of JSONOps) — and substitutes the leading unitId where it matches.
31
+ * Returns a fresh structure on change so peers can identity-compare.
32
+ *
33
+ * Scope deliberately narrow: only checks element [0] of each op
34
+ * (where the unitId always lives in our path schema). A deeper
35
+ * path-rewrite would invent semantics the Univer source doesn't
36
+ * document.
37
+ */
38
+ export function rewriteJson1OpPathUnitId(
39
+ op: unknown,
40
+ oldUnitId: string,
41
+ newUnitId: string,
42
+ ): unknown {
43
+ if (oldUnitId === newUnitId) return op;
44
+ if (!Array.isArray(op)) return op;
45
+ // Distinguish single JSONOp (path...component) from JSONOpList
46
+ // (array of JSONOps). A JSONOp's elements are strings, numbers, or
47
+ // a single trailing component object. A JSONOpList's elements are
48
+ // themselves arrays.
49
+ const looksLikeOpList = op.length > 0 && Array.isArray(op[0]);
50
+ if (looksLikeOpList) {
51
+ let changed = false;
52
+ const next = op.map((entry) => {
53
+ const r = rewriteJson1OpPathUnitId(entry, oldUnitId, newUnitId);
54
+ if (r !== entry) changed = true;
55
+ return r;
56
+ });
57
+ return changed ? next : op;
58
+ }
59
+ // Single JSONOp — substitute element [0] if it matches.
60
+ if (op[0] === oldUnitId) {
61
+ const next = [...op];
62
+ next[0] = newUnitId;
63
+ return next;
64
+ }
65
+ return op;
66
+ }
67
+
68
+ export function deepRewriteUnitId(value: unknown, localUnitId: string): unknown {
69
+ if (Array.isArray(value)) {
70
+ let changed = false;
71
+ const next = value.map((item) => {
72
+ const r = deepRewriteUnitId(item, localUnitId);
73
+ if (r !== item) changed = true;
74
+ return r;
75
+ });
76
+ return changed ? next : value;
77
+ }
78
+ if (value && typeof value === 'object' && Object.getPrototypeOf(value) === Object.prototype) {
79
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
80
+ const obj = value as Record<string, any>;
81
+ let changed = false;
82
+ const out: Record<string, unknown> = {};
83
+ for (const key of Object.keys(obj)) {
84
+ const v = obj[key];
85
+ if (key === 'unitId' && typeof v === 'string' && v !== localUnitId) {
86
+ out[key] = localUnitId;
87
+ changed = true;
88
+ } else {
89
+ const r = deepRewriteUnitId(v, localUnitId);
90
+ if (r !== v) changed = true;
91
+ out[key] = r;
92
+ }
93
+ }
94
+ return changed ? out : value;
95
+ }
96
+ return value;
97
+ }