@rowsncolumns/y-spreadsheet 16.1.0 → 17.0.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 (46) hide show
  1. package/Readme.md +21 -6
  2. package/dist/cjs/helpers-v5.d.ts +11 -11
  3. package/dist/cjs/helpers-v5.d.ts.map +1 -1
  4. package/dist/cjs/helpers-v5.js +46 -33
  5. package/dist/cjs/helpers.d.ts +17 -19
  6. package/dist/cjs/helpers.d.ts.map +1 -1
  7. package/dist/cjs/helpers.js +89 -86
  8. package/dist/cjs/observables.d.ts +7 -7
  9. package/dist/cjs/observables.d.ts.map +1 -1
  10. package/dist/cjs/observables.js +34 -46
  11. package/dist/cjs/tsconfig.cjs.tsbuildinfo +1 -1
  12. package/dist/cjs/types.d.ts +96 -19
  13. package/dist/cjs/types.d.ts.map +1 -1
  14. package/dist/cjs/use-yspreadsheet-v2.d.ts +11 -10
  15. package/dist/cjs/use-yspreadsheet-v2.d.ts.map +1 -1
  16. package/dist/cjs/use-yspreadsheet-v2.js +79 -90
  17. package/dist/cjs/use-yspreadsheet.d.ts +6 -6
  18. package/dist/cjs/use-yspreadsheet.d.ts.map +1 -1
  19. package/dist/cjs/use-yspreadsheet.js +38 -74
  20. package/dist/cjs/yjs-runtime.js +5 -5
  21. package/dist/cjs/ynodes.d.ts +61 -0
  22. package/dist/cjs/ynodes.d.ts.map +1 -0
  23. package/dist/cjs/ynodes.js +224 -0
  24. package/dist/esm/helpers-v5.d.ts +11 -11
  25. package/dist/esm/helpers-v5.d.ts.map +1 -1
  26. package/dist/esm/helpers-v5.js +46 -33
  27. package/dist/esm/helpers.d.ts +17 -19
  28. package/dist/esm/helpers.d.ts.map +1 -1
  29. package/dist/esm/helpers.js +90 -87
  30. package/dist/esm/observables.d.ts +7 -7
  31. package/dist/esm/observables.d.ts.map +1 -1
  32. package/dist/esm/observables.js +21 -25
  33. package/dist/esm/tsconfig.esm.tsbuildinfo +1 -1
  34. package/dist/esm/types.d.ts +96 -19
  35. package/dist/esm/types.d.ts.map +1 -1
  36. package/dist/esm/use-yspreadsheet-v2.d.ts +11 -10
  37. package/dist/esm/use-yspreadsheet-v2.d.ts.map +1 -1
  38. package/dist/esm/use-yspreadsheet-v2.js +76 -88
  39. package/dist/esm/use-yspreadsheet.d.ts +6 -6
  40. package/dist/esm/use-yspreadsheet.d.ts.map +1 -1
  41. package/dist/esm/use-yspreadsheet.js +17 -43
  42. package/dist/esm/yjs-runtime.js +5 -5
  43. package/dist/esm/ynodes.d.ts +61 -0
  44. package/dist/esm/ynodes.d.ts.map +1 -0
  45. package/dist/esm/ynodes.js +146 -0
  46. package/package.json +9 -8
@@ -0,0 +1,61 @@
1
+ import type { YEvent, YjsRuntime, YNode, YTransaction } from "./types";
2
+ /** Inserts `items` at `index`; nothing at all for no items (as Yjs 13's `Y.Array#insert`). */
3
+ export declare const listInsert: (node: YNode, index: number, items: readonly unknown[]) => void;
4
+ /** Deletes `length` items from `index`; nothing at all for a length of 0. */
5
+ export declare const listDelete: (node: YNode, index: number, length: number) => void;
6
+ /** Calls `callback` with each entry of a map node (its attributes), in insertion order. */
7
+ export declare const forEachEntry: (node: YNode, callback: (value: any, key: string) => void) => void;
8
+ /** Whether a map node holds any entry (without counting them all). */
9
+ export declare const hasEntries: (node: YNode) => boolean;
10
+ /**
11
+ * A stored value as Yjs 13's `toJSON` rendered it: a map node as an object of
12
+ * its entries, an array node as an array of its items (nested nodes rendered
13
+ * the same way), told apart by the host's `isMap` / `isArray` (their Yjs 13
14
+ * type reference). Anything else is returned as it is; a node of another kind
15
+ * (a text, XML) as its own `toJSON()`.
16
+ */
17
+ export declare const nodeJson: (value: unknown, runtime: YjsRuntime) => unknown;
18
+ /** A map node (or a root read as a map) as Yjs 13's `Y.Map#toJSON`: its entries in insertion order. */
19
+ export declare const mapJson: (node: YNode, runtime: YjsRuntime) => Record<string, any>;
20
+ /** An array node (or a root read as an array) as Yjs 13's `Y.Array#toJSON`. */
21
+ export declare const arrayJson: (node: YNode, runtime: YjsRuntime) => any[];
22
+ /** A changed descendant of an observed node, with its path from that node. */
23
+ export type YDeepEvent = {
24
+ event: YEvent;
25
+ path: Array<string | number>;
26
+ };
27
+ /**
28
+ * What Yjs 13's `observeDeep` delivered for `node` in `transaction`: an event
29
+ * per changed type at or below `node` that is still in the document, each with
30
+ * its path from `node`, top level first. `@y/y` calls a deep observer once per
31
+ * transaction and keeps the per-type events on the transaction, including the
32
+ * types the transaction deleted (Yjs 13 left those out: their paths name
33
+ * positions the deleted types no longer hold).
34
+ */
35
+ export declare const liveDeepEvents: (node: YNode, transaction: YTransaction, runtime: YjsRuntime) => YDeepEvent[];
36
+ /** One operation of a change to a node's children, as Yjs 13's `event.changes.delta` reported it. */
37
+ export type YjsDeltaOp = {
38
+ insert?: any[] | string;
39
+ delete?: number;
40
+ retain?: number;
41
+ };
42
+ /**
43
+ * The change `event` made to its target's children in Yjs 13's delta form:
44
+ * runs of kept (`retain`), removed (`delete`) and inserted (`insert`, the
45
+ * values) children. A child whose own content changed is kept, as Yjs 13
46
+ * counted it. Empty when only attributes changed. Read inside the observer.
47
+ */
48
+ export declare const childDelta: (event: YEvent) => YjsDeltaOp[];
49
+ /** The values `event` inserted into its target's children, in order. Read inside the observer. */
50
+ export declare const insertedValues: (event: YEvent) => unknown[];
51
+ /**
52
+ * The keys `event` changed on its target with the action Yjs 13 reported for
53
+ * them (`event.changes.keys`), read off the event's delta: a key it set is an
54
+ * `"update"` (an add too: neither the delta nor the package tells them apart),
55
+ * a key it removed a `"delete"`, and a key it set and removed again is left
56
+ * out, as Yjs 13 left it out. Read inside the observer.
57
+ */
58
+ export declare const changedKeys: (event: YEvent) => Map<string, {
59
+ action: "add" | "update" | "delete";
60
+ }>;
61
+ //# sourceMappingURL=ynodes.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ynodes.d.ts","sourceRoot":"","sources":["../../ynodes.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAA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C,EAAE,MAAM,CAAC;IAChB,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB,CAAC;AAkBF;;;;;GAKG;AACH,eAAO,MAAM,UAAU,GAAI,OAAO,MAAM,KAAG,UAAU,EAoBpD,CAAC;AAEF,kGAAkG;AAClG,eAAO,MAAM,cAAc,GAAI,OAAO,MAAM,KAAG,OAAO,EAMrD,CAAC;AAEF;;;;;;GAMG;AACH,eAAO,MAAM,WAAW,GACtB,OAAO,MAAM,KACZ,GAAG,CAAC,MAAM,EAAE;IAAE,MAAM,EAAE,KAAK,GAAG,QAAQ,GAAG,QAAQ,CAAA;CAAE,CAOrD,CAAC"}
@@ -0,0 +1,146 @@
1
+ // Reads and writes over `@y/y` 14 nodes shared by the helpers and the hooks.
2
+ // Every function reads integrated nodes only: `@y/y` keeps a node's content to
3
+ // itself until the node is inserted into a document.
4
+ /** Inserts `items` at `index`; nothing at all for no items (as Yjs 13's `Y.Array#insert`). */
5
+ export const listInsert = (node, index, items) => {
6
+ if (items.length > 0)
7
+ node.insert(index, [...items]);
8
+ };
9
+ /** Deletes `length` items from `index`; nothing at all for a length of 0. */
10
+ export const listDelete = (node, index, length) => {
11
+ if (length > 0)
12
+ node.delete(index, length);
13
+ };
14
+ /** Calls `callback` with each entry of a map node (its attributes), in insertion order. */
15
+ export const forEachEntry = (node, callback) => {
16
+ node.forEachAttr(callback);
17
+ };
18
+ /** Whether a map node holds any entry (without counting them all). */
19
+ export const hasEntries = (node) => !node.attrKeys().next().done;
20
+ /** Whether `value` is a `@y/y` node of a kind the host does not map (neither a map nor an array). */
21
+ const isOtherNode = (value) => typeof value === "object" &&
22
+ value !== null &&
23
+ typeof value.observe === "function" &&
24
+ typeof value.toJSON === "function";
25
+ /**
26
+ * A stored value as Yjs 13's `toJSON` rendered it: a map node as an object of
27
+ * its entries, an array node as an array of its items (nested nodes rendered
28
+ * the same way), told apart by the host's `isMap` / `isArray` (their Yjs 13
29
+ * type reference). Anything else is returned as it is; a node of another kind
30
+ * (a text, XML) as its own `toJSON()`.
31
+ */
32
+ export const nodeJson = (value, runtime) => {
33
+ if (runtime.isMap(value))
34
+ return mapJson(value, runtime);
35
+ if (runtime.isArray(value))
36
+ return arrayJson(value, runtime);
37
+ if (isOtherNode(value))
38
+ return value.toJSON();
39
+ return value;
40
+ };
41
+ /** A map node (or a root read as a map) as Yjs 13's `Y.Map#toJSON`: its entries in insertion order. */
42
+ export const mapJson = (node, runtime) => {
43
+ const out = {};
44
+ node.forEachAttr((value, key) => {
45
+ out[String(key)] = nodeJson(value, runtime);
46
+ });
47
+ return out;
48
+ };
49
+ /** An array node (or a root read as an array) as Yjs 13's `Y.Array#toJSON`. */
50
+ export const arrayJson = (node, runtime) => node.toArray().map((value) => nodeJson(value, runtime));
51
+ /** The node `path` leads to from `node` (attribute keys and child indexes), or undefined. */
52
+ const resolvePath = (node, path) => {
53
+ let current = node;
54
+ for (const segment of path) {
55
+ if (!isOtherNode(current))
56
+ return undefined;
57
+ current =
58
+ typeof segment === "number"
59
+ ? current.get(segment)
60
+ : current.getAttr(segment);
61
+ }
62
+ return current;
63
+ };
64
+ /**
65
+ * What Yjs 13's `observeDeep` delivered for `node` in `transaction`: an event
66
+ * per changed type at or below `node` that is still in the document, each with
67
+ * its path from `node`, top level first. `@y/y` calls a deep observer once per
68
+ * transaction and keeps the per-type events on the transaction, including the
69
+ * types the transaction deleted (Yjs 13 left those out: their paths name
70
+ * positions the deleted types no longer hold).
71
+ */
72
+ export const liveDeepEvents = (node, transaction, runtime) => {
73
+ const out = [];
74
+ for (const event of transaction.changedParentTypes.get(node) ?? []) {
75
+ let path;
76
+ try {
77
+ path = runtime.getPathTo(node, event.target);
78
+ }
79
+ catch {
80
+ continue;
81
+ }
82
+ if (resolvePath(node, path) !== event.target)
83
+ continue;
84
+ out.push({ event, path });
85
+ }
86
+ return out.sort((a, b) => a.path.length - b.path.length);
87
+ };
88
+ const childOps = (event) => event.delta?.children ?? [];
89
+ /**
90
+ * The change `event` made to its target's children in Yjs 13's delta form:
91
+ * runs of kept (`retain`), removed (`delete`) and inserted (`insert`, the
92
+ * values) children. A child whose own content changed is kept, as Yjs 13
93
+ * counted it. Empty when only attributes changed. Read inside the observer.
94
+ */
95
+ export const childDelta = (event) => {
96
+ const out = [];
97
+ const retain = (count) => {
98
+ const last = out[out.length - 1];
99
+ if (last && last.retain !== undefined)
100
+ last.retain += count;
101
+ else
102
+ out.push({ retain: count });
103
+ };
104
+ for (const op of childOps(event)) {
105
+ if (Array.isArray(op.insert) || typeof op.insert === "string") {
106
+ out.push({ insert: op.insert });
107
+ }
108
+ else if (typeof op.delete === "number") {
109
+ out.push({ delete: op.delete });
110
+ }
111
+ else if (typeof op.retain === "number") {
112
+ retain(op.retain);
113
+ }
114
+ else {
115
+ // A child whose content changed (`modify`) is one kept child.
116
+ retain(1);
117
+ }
118
+ }
119
+ return out;
120
+ };
121
+ /** The values `event` inserted into its target's children, in order. Read inside the observer. */
122
+ export const insertedValues = (event) => {
123
+ const out = [];
124
+ for (const op of childOps(event)) {
125
+ if (Array.isArray(op.insert))
126
+ out.push(...op.insert);
127
+ }
128
+ return out;
129
+ };
130
+ /**
131
+ * The keys `event` changed on its target with the action Yjs 13 reported for
132
+ * them (`event.changes.keys`), read off the event's delta: a key it set is an
133
+ * `"update"` (an add too: neither the delta nor the package tells them apart),
134
+ * a key it removed a `"delete"`, and a key it set and removed again is left
135
+ * out, as Yjs 13 left it out. Read inside the observer.
136
+ */
137
+ export const changedKeys = (event) => {
138
+ const out = new Map();
139
+ for (const op of event.delta?.attrs ?? []) {
140
+ if (op.type === "insert")
141
+ out.set(String(op.key), { action: "update" });
142
+ else if (op.type === "delete")
143
+ out.set(String(op.key), { action: "delete" });
144
+ }
145
+ return out;
146
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rowsncolumns/y-spreadsheet",
3
- "version": "16.1.0",
3
+ "version": "17.0.0",
4
4
  "main": "./dist/cjs/index.js",
5
5
  "module": "./dist/esm/index.js",
6
6
  "exports": {
@@ -35,13 +35,14 @@
35
35
  "devDependencies": {
36
36
  "@hocuspocus/provider": "^3.1.1",
37
37
  "@rowsncolumns/common-types": ">=5.3.1",
38
- "@rowsncolumns/fast-formula-parser": ">=6.2.41",
39
- "@rowsncolumns/grid": ">=13.2.35",
40
- "@rowsncolumns/spreadsheet": ">=10.4.1",
41
- "@rowsncolumns/spreadsheet-state": ">=29.1.4",
38
+ "@rowsncolumns/fast-formula-parser": ">=6.2.46",
39
+ "@rowsncolumns/grid": ">=13.4.1",
40
+ "@rowsncolumns/spreadsheet": ">=10.8.2",
41
+ "@rowsncolumns/spreadsheet-state": ">=29.4.4",
42
42
  "@rowsncolumns/ui": ">=16.0.3",
43
- "@rowsncolumns/utils": ">=9.5.1",
43
+ "@rowsncolumns/utils": ">=9.7.2",
44
44
  "@types/lodash": "^4.17.17",
45
+ "@y/y": "14.0.0-rc.29",
45
46
  "react": "^19.1.0",
46
47
  "react-dom": "^19.1.0",
47
48
  "y-websocket": "^3.0.0",
@@ -56,10 +57,10 @@
56
57
  "@rowsncolumns/utils": ">=9.3.0",
57
58
  "react": ">=18.0.0",
58
59
  "react-dom": ">=18.0.0",
59
- "yjs": ">=13.0.0"
60
+ "@y/y": ">=14.0.0-rc.29"
60
61
  },
61
62
  "peerDependenciesMeta": {
62
- "yjs": {
63
+ "@y/y": {
63
64
  "optional": true
64
65
  }
65
66
  },