@dxos/plugin-sheet 0.6.12-main.ed7cda7 → 0.6.12-staging.e11e696

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 (158) hide show
  1. package/dist/lib/browser/{SheetContainer-V4GCCZTX.mjs → SheetContainer-LG77O4RM.mjs} +14 -13
  2. package/dist/lib/browser/SheetContainer-LG77O4RM.mjs.map +7 -0
  3. package/dist/lib/browser/{chunk-U2JHW3L6.mjs → chunk-CHQAW4F4.mjs} +206 -53
  4. package/dist/lib/browser/chunk-CHQAW4F4.mjs.map +7 -0
  5. package/dist/lib/browser/{chunk-6ZMQVB4Z.mjs → chunk-GSV5QNLD.mjs} +220 -177
  6. package/dist/lib/browser/chunk-GSV5QNLD.mjs.map +7 -0
  7. package/dist/lib/browser/{chunk-T3NJFTD4.mjs → chunk-WZMOZKQZ.mjs} +2 -2
  8. package/dist/lib/browser/{chunk-T3NJFTD4.mjs.map → chunk-WZMOZKQZ.mjs.map} +3 -3
  9. package/dist/lib/browser/graph-M4IQ76QX.mjs +33 -0
  10. package/dist/lib/browser/index.mjs +45 -21
  11. package/dist/lib/browser/index.mjs.map +4 -4
  12. package/dist/lib/browser/meta.json +1 -1
  13. package/dist/lib/browser/types.mjs +1 -1
  14. package/dist/lib/node/{SheetContainer-3ZY7MPWJ.cjs → SheetContainer-OZ7DHH4L.cjs} +21 -20
  15. package/dist/lib/node/SheetContainer-OZ7DHH4L.cjs.map +7 -0
  16. package/dist/lib/node/{chunk-OTTD7FBK.cjs → chunk-5FTFZL5W.cjs} +224 -70
  17. package/dist/lib/node/chunk-5FTFZL5W.cjs.map +7 -0
  18. package/dist/lib/node/{chunk-DD6FIXWC.cjs → chunk-5XPK2V4A.cjs} +222 -175
  19. package/dist/lib/node/chunk-5XPK2V4A.cjs.map +7 -0
  20. package/dist/lib/node/{chunk-Q3HBHPRL.cjs → chunk-AOP42UAA.cjs} +5 -5
  21. package/dist/lib/node/{chunk-Q3HBHPRL.cjs.map → chunk-AOP42UAA.cjs.map} +3 -3
  22. package/dist/lib/node/graph-Q3N2X26H.cjs +55 -0
  23. package/dist/lib/node/graph-Q3N2X26H.cjs.map +7 -0
  24. package/dist/lib/node/index.cjs +51 -30
  25. package/dist/lib/node/index.cjs.map +4 -4
  26. package/dist/lib/node/meta.json +1 -1
  27. package/dist/lib/node/types.cjs +8 -8
  28. package/dist/lib/node/types.cjs.map +1 -1
  29. package/dist/lib/node-esm/{SheetContainer-PXSJX6XK.mjs → SheetContainer-4XS2G25Z.mjs} +14 -13
  30. package/dist/lib/node-esm/SheetContainer-4XS2G25Z.mjs.map +7 -0
  31. package/dist/lib/node-esm/{chunk-D6KU5MI7.mjs → chunk-5WPZCXNS.mjs} +220 -177
  32. package/dist/lib/node-esm/chunk-5WPZCXNS.mjs.map +7 -0
  33. package/dist/lib/node-esm/{chunk-7HVSOTGA.mjs → chunk-KK3XL37M.mjs} +206 -53
  34. package/dist/lib/node-esm/chunk-KK3XL37M.mjs.map +7 -0
  35. package/dist/lib/node-esm/{chunk-BMNA27EX.mjs → chunk-RR2AO4SM.mjs} +2 -2
  36. package/dist/lib/node-esm/{chunk-BMNA27EX.mjs.map → chunk-RR2AO4SM.mjs.map} +3 -3
  37. package/dist/lib/node-esm/graph-SMPUMOV2.mjs +34 -0
  38. package/dist/lib/node-esm/index.mjs +45 -21
  39. package/dist/lib/node-esm/index.mjs.map +4 -4
  40. package/dist/lib/node-esm/meta.json +1 -1
  41. package/dist/lib/node-esm/types.mjs +1 -1
  42. package/dist/types/src/SheetPlugin.d.ts.map +1 -1
  43. package/dist/types/src/components/CellEditor/CellEditor.stories.d.ts.map +1 -1
  44. package/dist/types/src/components/CellEditor/extension.d.ts.map +1 -1
  45. package/dist/types/src/components/GridSheet/GridSheet.d.ts +3 -3
  46. package/dist/types/src/components/GridSheet/GridSheet.d.ts.map +1 -1
  47. package/dist/types/src/components/GridSheet/GridSheet.stories.d.ts +1 -1
  48. package/dist/types/src/components/GridSheet/GridSheet.stories.d.ts.map +1 -1
  49. package/dist/types/src/components/Sheet/Sheet.d.ts.map +1 -1
  50. package/dist/types/src/components/Sheet/Sheet.stories.d.ts.map +1 -1
  51. package/dist/types/src/components/Sheet/sheet-context.d.ts +3 -3
  52. package/dist/types/src/components/Sheet/sheet-context.d.ts.map +1 -1
  53. package/dist/types/src/components/SheetContainer.d.ts +1 -1
  54. package/dist/types/src/components/SheetContainer.d.ts.map +1 -1
  55. package/dist/types/src/components/index.d.ts +1 -1
  56. package/dist/types/src/components/index.d.ts.map +1 -1
  57. package/dist/types/src/defs/types.d.ts.map +1 -1
  58. package/dist/types/src/defs/util.d.ts +1 -1
  59. package/dist/types/src/defs/util.d.ts.map +1 -1
  60. package/dist/types/src/extensions/compute.d.ts +3 -2
  61. package/dist/types/src/extensions/compute.d.ts.map +1 -1
  62. package/dist/types/src/extensions/compute.stories.d.ts.map +1 -1
  63. package/dist/types/src/graph/compute-graph-registry.d.ts +34 -0
  64. package/dist/types/src/graph/compute-graph-registry.d.ts.map +1 -0
  65. package/dist/types/src/graph/compute-graph.d.ts +17 -34
  66. package/dist/types/src/graph/compute-graph.d.ts.map +1 -1
  67. package/dist/types/src/graph/compute-graph.stories.d.ts.map +1 -1
  68. package/dist/types/src/graph/compute-graph.test.d.ts +2 -0
  69. package/dist/types/src/graph/compute-graph.test.d.ts.map +1 -0
  70. package/dist/types/src/graph/compute-node.d.ts +9 -2
  71. package/dist/types/src/graph/compute-node.d.ts.map +1 -1
  72. package/dist/types/src/graph/{async-function.d.ts → functions/async-function.d.ts} +13 -4
  73. package/dist/types/src/graph/functions/async-function.d.ts.map +1 -0
  74. package/dist/types/src/graph/functions/edge-function.d.ts +21 -0
  75. package/dist/types/src/graph/functions/edge-function.d.ts.map +1 -0
  76. package/dist/types/src/graph/functions/function-defs.d.ts.map +1 -0
  77. package/dist/types/src/graph/functions/index.d.ts +4 -0
  78. package/dist/types/src/graph/functions/index.d.ts.map +1 -0
  79. package/dist/types/src/graph/index.d.ts +2 -1
  80. package/dist/types/src/graph/index.d.ts.map +1 -1
  81. package/dist/types/src/graph/testing/index.d.ts +3 -0
  82. package/dist/types/src/graph/testing/index.d.ts.map +1 -0
  83. package/dist/types/src/graph/testing/test-builder.d.ts +15 -0
  84. package/dist/types/src/graph/testing/test-builder.d.ts.map +1 -0
  85. package/dist/types/src/graph/testing/test-plugin.d.ts +36 -0
  86. package/dist/types/src/graph/testing/test-plugin.d.ts.map +1 -0
  87. package/dist/types/src/hooks/useComputeGraph.d.ts.map +1 -1
  88. package/dist/types/src/hooks/useSheetModel.d.ts +2 -2
  89. package/dist/types/src/hooks/useSheetModel.d.ts.map +1 -1
  90. package/dist/types/src/model/sheet-model.d.ts +3 -3
  91. package/dist/types/src/model/sheet-model.d.ts.map +1 -1
  92. package/dist/types/src/model/sheet-model.test.d.ts +2 -0
  93. package/dist/types/src/model/sheet-model.test.d.ts.map +1 -0
  94. package/dist/types/src/testing/testing.d.ts +4 -5
  95. package/dist/types/src/testing/testing.d.ts.map +1 -1
  96. package/dist/types/src/types.d.ts +4 -3
  97. package/dist/types/src/types.d.ts.map +1 -1
  98. package/package.json +40 -39
  99. package/src/SheetPlugin.tsx +19 -15
  100. package/src/components/CellEditor/CellEditor.stories.tsx +2 -3
  101. package/src/components/CellEditor/extension.test.ts +0 -1
  102. package/src/components/CellEditor/extension.ts +4 -3
  103. package/src/components/GridSheet/GridSheet.stories.tsx +5 -4
  104. package/src/components/GridSheet/GridSheet.tsx +4 -4
  105. package/src/components/Sheet/Sheet.stories.tsx +21 -20
  106. package/src/components/Sheet/Sheet.tsx +30 -14
  107. package/src/components/Sheet/sheet-context.tsx +4 -4
  108. package/src/components/SheetContainer.tsx +13 -15
  109. package/src/defs/types.ts +1 -0
  110. package/src/defs/util.ts +19 -3
  111. package/src/extensions/compute.stories.tsx +20 -20
  112. package/src/extensions/compute.ts +91 -42
  113. package/src/graph/compute-graph-registry.ts +90 -0
  114. package/src/graph/compute-graph.stories.tsx +4 -3
  115. package/src/graph/compute-graph.test.ts +87 -0
  116. package/src/graph/compute-graph.ts +73 -121
  117. package/src/graph/compute-node.ts +17 -5
  118. package/src/graph/{async-function.ts → functions/async-function.ts} +23 -15
  119. package/src/graph/{edge-function.ts → functions/edge-function.ts} +14 -13
  120. package/src/graph/functions/index.ts +7 -0
  121. package/src/graph/hyperformula.test.ts +1 -2
  122. package/src/graph/index.ts +2 -1
  123. package/src/graph/testing/index.ts +6 -0
  124. package/src/graph/testing/test-builder.ts +54 -0
  125. package/src/graph/{custom-function.ts → testing/test-plugin.ts} +43 -9
  126. package/src/hooks/hooks.stories.tsx +3 -3
  127. package/src/hooks/useComputeGraph.ts +9 -1
  128. package/src/hooks/useSheetModel.ts +4 -7
  129. package/src/model/sheet-model.test.ts +59 -0
  130. package/src/model/sheet-model.ts +47 -30
  131. package/src/testing/testing.tsx +17 -15
  132. package/src/types.ts +3 -3
  133. package/dist/lib/browser/SheetContainer-V4GCCZTX.mjs.map +0 -7
  134. package/dist/lib/browser/chunk-6ZMQVB4Z.mjs.map +0 -7
  135. package/dist/lib/browser/chunk-U2JHW3L6.mjs.map +0 -7
  136. package/dist/lib/browser/graph-T27BOBOV.mjs +0 -21
  137. package/dist/lib/node/SheetContainer-3ZY7MPWJ.cjs.map +0 -7
  138. package/dist/lib/node/chunk-DD6FIXWC.cjs.map +0 -7
  139. package/dist/lib/node/chunk-OTTD7FBK.cjs.map +0 -7
  140. package/dist/lib/node/graph-SPKGX7W4.cjs +0 -43
  141. package/dist/lib/node/graph-SPKGX7W4.cjs.map +0 -7
  142. package/dist/lib/node-esm/SheetContainer-PXSJX6XK.mjs.map +0 -7
  143. package/dist/lib/node-esm/chunk-7HVSOTGA.mjs.map +0 -7
  144. package/dist/lib/node-esm/chunk-D6KU5MI7.mjs.map +0 -7
  145. package/dist/lib/node-esm/graph-U67IO4UC.mjs +0 -22
  146. package/dist/types/src/graph/async-function.d.ts.map +0 -1
  147. package/dist/types/src/graph/compute-graph.browser.test.d.ts +0 -2
  148. package/dist/types/src/graph/compute-graph.browser.test.d.ts.map +0 -1
  149. package/dist/types/src/graph/custom-function.d.ts +0 -21
  150. package/dist/types/src/graph/custom-function.d.ts.map +0 -1
  151. package/dist/types/src/graph/edge-function.d.ts +0 -20
  152. package/dist/types/src/graph/edge-function.d.ts.map +0 -1
  153. package/dist/types/src/graph/function-defs.d.ts.map +0 -1
  154. package/src/graph/compute-graph.browser.test.ts +0 -104
  155. /package/dist/lib/browser/{graph-T27BOBOV.mjs.map → graph-M4IQ76QX.mjs.map} +0 -0
  156. /package/dist/lib/node-esm/{graph-U67IO4UC.mjs.map → graph-SMPUMOV2.mjs.map} +0 -0
  157. /package/dist/types/src/graph/{function-defs.d.ts → functions/function-defs.d.ts} +0 -0
  158. /package/src/graph/{function-defs.ts → functions/function-defs.ts} +0 -0
@@ -2,13 +2,13 @@ import { createRequire } from 'node:module';const require = createRequire(import
2
2
  import {
3
3
  SheetType,
4
4
  ValueTypeEnum
5
- } from "./chunk-BMNA27EX.mjs";
5
+ } from "./chunk-RR2AO4SM.mjs";
6
6
  import {
7
7
  SHEET_PLUGIN
8
8
  } from "./chunk-IU2L277A.mjs";
9
9
  import {
10
10
  createSheetName
11
- } from "./chunk-D6KU5MI7.mjs";
11
+ } from "./chunk-5WPZCXNS.mjs";
12
12
 
13
13
  // packages/plugins/plugin-sheet/src/components/Sheet/Sheet.tsx
14
14
  import { DndContext, DragOverlay, KeyboardSensor, MouseSensor, TouchSensor, useDraggable, useDroppable, useSensor, useSensors } from "@dnd-kit/core";
@@ -22,7 +22,7 @@ import { useResizeDetector } from "react-resize-detector";
22
22
  import { debounce as debounce2 } from "@dxos/async";
23
23
  import { fullyQualifiedId as fullyQualifiedId2, createDocAccessor } from "@dxos/client/echo";
24
24
  import { log as log2 } from "@dxos/log";
25
- import { createAttendableAttributes, useHasAttention } from "@dxos/react-ui-attention";
25
+ import { ATTENABLE_ATTRIBUTE, useAttendableAttributes, useAttention, useAttentionPath } from "@dxos/react-ui-attention";
26
26
  import { mx as mx2 } from "@dxos/react-ui-theme";
27
27
 
28
28
  // packages/plugins/plugin-sheet/src/components/Sheet/grid.ts
@@ -57,7 +57,7 @@ var addressFromA1Notation = (ref) => {
57
57
  const match = ref.match(/([A-Z]+)(\d+)/);
58
58
  invariant(match, `Invalid notation: ${ref}`, {
59
59
  F: __dxlog_file,
60
- L: 39,
60
+ L: 40,
61
61
  S: void 0,
62
62
  A: [
63
63
  "match",
@@ -132,9 +132,9 @@ var initialize = (sheet, { rows = DEFAULT_ROWS, columns = DEFAULT_COLUMNS } = {}
132
132
  insertIndices(sheet.columns, 0, columns, MAX_COLUMNS);
133
133
  }
134
134
  };
135
- var createSheet = ({ title, ...size } = {}) => {
135
+ var createSheet = ({ name, cells, ...size } = {}) => {
136
136
  const sheet = create(SheetType, {
137
- title,
137
+ name,
138
138
  cells: {},
139
139
  rows: [],
140
140
  columns: [],
@@ -143,6 +143,14 @@ var createSheet = ({ title, ...size } = {}) => {
143
143
  formatting: {}
144
144
  });
145
145
  initialize(sheet, size);
146
+ if (cells) {
147
+ Object.entries(cells).forEach(([key, { value }]) => {
148
+ const idx = addressToIndex(sheet, addressFromA1Notation(key));
149
+ sheet.cells[idx] = {
150
+ value
151
+ };
152
+ });
153
+ }
146
154
  return sheet;
147
155
  };
148
156
  var addressToIndex = (sheet, cell) => {
@@ -537,15 +545,22 @@ var ComputeGraphContextProvider = ({ registry, children }) => {
537
545
  };
538
546
 
539
547
  // packages/plugins/plugin-sheet/src/components/index.ts
540
- var SheetContainer = React2.lazy(() => import("./SheetContainer-PXSJX6XK.mjs"));
548
+ var SheetContainer = React2.lazy(() => import("./SheetContainer-4XS2G25Z.mjs"));
541
549
 
542
550
  // packages/plugins/plugin-sheet/src/hooks/useComputeGraph.ts
543
551
  var useComputeGraph = (space) => {
544
552
  const { registry } = useContext(ComputeGraphContext) ?? raise(new Error("Missing ComputeGraphContext"));
545
- return useAsyncState(async () => space && registry.getOrCreateGraph(space), [
553
+ const [graph] = useAsyncState(async () => {
554
+ if (space) {
555
+ const graph2 = registry.getOrCreateGraph(space);
556
+ await graph2.open();
557
+ return graph2;
558
+ }
559
+ }, [
546
560
  space,
547
561
  registry
548
562
  ]);
563
+ return graph;
549
564
  };
550
565
 
551
566
  // packages/plugins/plugin-sheet/src/hooks/useFormattingModel.ts
@@ -665,6 +680,7 @@ var FormattingModel = class {
665
680
  // packages/plugins/plugin-sheet/src/model/sheet-model.ts
666
681
  import { Event } from "@dxos/async";
667
682
  import { Resource } from "@dxos/context";
683
+ import { getTypename } from "@dxos/echo-schema";
668
684
  import { invariant as invariant2 } from "@dxos/invariant";
669
685
  import { PublicKey } from "@dxos/keys";
670
686
  import { log } from "@dxos/log";
@@ -703,8 +719,6 @@ var SheetModel = class extends Resource {
703
719
  this._options = _options;
704
720
  this.id = `model-${PublicKey.random().truncate()}`;
705
721
  this.update = new Event();
706
- this._node = this._graph.getOrCreateNode(createSheetName(this._sheet.id));
707
- this.reset();
708
722
  }
709
723
  get graph() {
710
724
  return this._graph;
@@ -729,14 +743,19 @@ var SheetModel = class extends Resource {
729
743
  id: this.id
730
744
  }, {
731
745
  F: __dxlog_file2,
732
- L: 105,
746
+ L: 104,
733
747
  S: this,
734
748
  C: (f, a) => f(...a)
735
749
  });
736
750
  initialize(this._sheet);
737
- this.reset();
738
- const unsubscribe = this._graph.update.on(() => this.update.emit());
751
+ this._node = this._graph.getOrCreateNode(createSheetName({
752
+ type: getTypename(this._sheet),
753
+ id: this._sheet.id
754
+ }));
755
+ await this._node.open();
756
+ const unsubscribe = this._node.update.on((event) => this.update.emit(event));
739
757
  this._ctx.onDispose(unsubscribe);
758
+ this.reset();
740
759
  }
741
760
  /**
742
761
  * Update engine.
@@ -744,13 +763,31 @@ var SheetModel = class extends Resource {
744
763
  * @deprecated
745
764
  */
746
765
  reset() {
747
- this._node.hf.clearSheet(this._node.sheetId);
766
+ invariant2(this._node, void 0, {
767
+ F: __dxlog_file2,
768
+ L: 124,
769
+ S: this,
770
+ A: [
771
+ "this._node",
772
+ ""
773
+ ]
774
+ });
775
+ this._node.graph.hf.clearSheet(this._node.sheetId);
748
776
  Object.entries(this._sheet.cells).forEach(([key, { value }]) => {
777
+ invariant2(this._node, void 0, {
778
+ F: __dxlog_file2,
779
+ L: 127,
780
+ S: this,
781
+ A: [
782
+ "this._node",
783
+ ""
784
+ ]
785
+ });
749
786
  const { col, row } = addressFromIndex(this._sheet, key);
750
787
  if (typeof value === "string" && value.charAt(0) === "=") {
751
788
  value = this._graph.mapFormulaToNative(this._graph.mapFunctionBindingFromId(this.mapFormulaIndicesToRefs(value)));
752
789
  }
753
- this._node.hf.setCellContents({
790
+ this._node.graph.hf.setCellContents({
754
791
  sheet: this._node.sheetId,
755
792
  row,
756
793
  col
@@ -765,7 +802,7 @@ var SheetModel = class extends Resource {
765
802
  */
766
803
  // TODO(burdon): Remove.
767
804
  recalculate() {
768
- this._node.hf.rebuildAndRecalculate();
805
+ this._node?.graph.hf.rebuildAndRecalculate();
769
806
  }
770
807
  insertRows(i, n = 1) {
771
808
  insertIndices(this._sheet.rows, i, n, MAX_ROWS);
@@ -783,27 +820,63 @@ var SheetModel = class extends Resource {
783
820
  * Clear range of values.
784
821
  */
785
822
  clear(range) {
823
+ invariant2(this._node, void 0, {
824
+ F: __dxlog_file2,
825
+ L: 169,
826
+ S: this,
827
+ A: [
828
+ "this._node",
829
+ ""
830
+ ]
831
+ });
786
832
  const topLeft = getTopLeft(range);
787
833
  const values = this._iterRange(range, () => null);
788
- this._node.hf.setCellContents(toSimpleCellAddress(this._node.sheetId, topLeft), values);
834
+ this._node.graph.hf.setCellContents(toSimpleCellAddress(this._node.sheetId, topLeft), values);
789
835
  this._iterRange(range, (cell) => {
790
836
  const idx = addressToIndex(this._sheet, cell);
791
837
  delete this._sheet.cells[idx];
792
838
  });
793
839
  }
794
840
  cut(range) {
795
- this._node.hf.cut(toModelRange(this._node.sheetId, range));
841
+ invariant2(this._node, void 0, {
842
+ F: __dxlog_file2,
843
+ L: 180,
844
+ S: this,
845
+ A: [
846
+ "this._node",
847
+ ""
848
+ ]
849
+ });
850
+ this._node.graph.hf.cut(toModelRange(this._node.sheetId, range));
796
851
  this._iterRange(range, (cell) => {
797
852
  const idx = addressToIndex(this._sheet, cell);
798
853
  delete this._sheet.cells[idx];
799
854
  });
800
855
  }
801
856
  copy(range) {
802
- this._node.hf.copy(toModelRange(this._node.sheetId, range));
857
+ invariant2(this._node, void 0, {
858
+ F: __dxlog_file2,
859
+ L: 189,
860
+ S: this,
861
+ A: [
862
+ "this._node",
863
+ ""
864
+ ]
865
+ });
866
+ this._node.graph.hf.copy(toModelRange(this._node.sheetId, range));
803
867
  }
804
868
  paste(cell) {
805
- if (!this._node.hf.isClipboardEmpty()) {
806
- const changes = this._node.hf.paste(toSimpleCellAddress(this._node.sheetId, cell));
869
+ invariant2(this._node, void 0, {
870
+ F: __dxlog_file2,
871
+ L: 194,
872
+ S: this,
873
+ A: [
874
+ "this._node",
875
+ ""
876
+ ]
877
+ });
878
+ if (!this._node.graph.hf.isClipboardEmpty()) {
879
+ const changes = this._node.graph.hf.paste(toSimpleCellAddress(this._node.sheetId, cell));
807
880
  for (const change of changes) {
808
881
  if (change instanceof ExportedCellChange) {
809
882
  const { address, newValue } = change;
@@ -820,15 +893,31 @@ var SheetModel = class extends Resource {
820
893
  }
821
894
  // TODO(burdon): Display undo/redo state.
822
895
  undo() {
823
- if (this._node.hf.isThereSomethingToUndo()) {
824
- this._node.hf.undo();
825
- this.update.emit();
896
+ invariant2(this._node, void 0, {
897
+ F: __dxlog_file2,
898
+ L: 209,
899
+ S: this,
900
+ A: [
901
+ "this._node",
902
+ ""
903
+ ]
904
+ });
905
+ if (this._node.graph.hf.isThereSomethingToUndo()) {
906
+ this._node.graph.hf.undo();
826
907
  }
827
908
  }
828
909
  redo() {
829
- if (this._node.hf.isThereSomethingToRedo()) {
830
- this._node.hf.redo();
831
- this.update.emit();
910
+ invariant2(this._node, void 0, {
911
+ F: __dxlog_file2,
912
+ L: 217,
913
+ S: this,
914
+ A: [
915
+ "this._node",
916
+ ""
917
+ ]
918
+ });
919
+ if (this._node.graph.hf.isThereSomethingToRedo()) {
920
+ this._node.graph.hf.redo();
832
921
  }
833
922
  }
834
923
  /**
@@ -862,7 +951,16 @@ var SheetModel = class extends Resource {
862
951
  * Gets the regular or computed value from the engine.
863
952
  */
864
953
  getValue(cell) {
865
- const value = this._node.hf.getCellValue(toSimpleCellAddress(this._node.sheetId, cell));
954
+ invariant2(this._node, void 0, {
955
+ F: __dxlog_file2,
956
+ L: 260,
957
+ S: this,
958
+ A: [
959
+ "this._node",
960
+ ""
961
+ ]
962
+ });
963
+ const value = this._node.graph.hf.getCellValue(toSimpleCellAddress(this._node.sheetId, cell));
866
964
  if (value instanceof DetailedCellError) {
867
965
  return value.toString();
868
966
  }
@@ -872,14 +970,32 @@ var SheetModel = class extends Resource {
872
970
  * Get value type.
873
971
  */
874
972
  getValueType(cell) {
973
+ invariant2(this._node, void 0, {
974
+ F: __dxlog_file2,
975
+ L: 273,
976
+ S: this,
977
+ A: [
978
+ "this._node",
979
+ ""
980
+ ]
981
+ });
875
982
  const addr = toSimpleCellAddress(this._node.sheetId, cell);
876
- const type = this._node.hf.getCellValueDetailedType(addr);
983
+ const type = this._node.graph.hf.getCellValueDetailedType(addr);
877
984
  return typeMap[type];
878
985
  }
879
986
  /**
880
987
  * Sets the value, updating the sheet and engine.
881
988
  */
882
989
  setValue(cell, value) {
990
+ invariant2(this._node, void 0, {
991
+ F: __dxlog_file2,
992
+ L: 283,
993
+ S: this,
994
+ A: [
995
+ "this._node",
996
+ ""
997
+ ]
998
+ });
883
999
  if (this._options.readonly) {
884
1000
  throw new ReadonlyException();
885
1001
  }
@@ -895,7 +1011,7 @@ var SheetModel = class extends Resource {
895
1011
  if (refresh) {
896
1012
  this.reset();
897
1013
  }
898
- this._node.hf.setCellContents({
1014
+ this._node.graph.hf.setCellContents({
899
1015
  sheet: this._node.sheetId,
900
1016
  row: cell.row,
901
1017
  col: cell.col
@@ -970,7 +1086,7 @@ var SheetModel = class extends Resource {
970
1086
  mapFormulaRefsToIndices(formula) {
971
1087
  invariant2(formula.charAt(0) === "=", void 0, {
972
1088
  F: __dxlog_file2,
973
- L: 358,
1089
+ L: 372,
974
1090
  S: this,
975
1091
  A: [
976
1092
  "formula.charAt(0) === '='",
@@ -987,7 +1103,7 @@ var SheetModel = class extends Resource {
987
1103
  mapFormulaIndicesToRefs(formula) {
988
1104
  invariant2(formula.charAt(0) === "=", void 0, {
989
1105
  F: __dxlog_file2,
990
- L: 368,
1106
+ L: 382,
991
1107
  S: this,
992
1108
  A: [
993
1109
  "formula.charAt(0) === '='",
@@ -1011,13 +1127,40 @@ var SheetModel = class extends Resource {
1011
1127
  return new Date(year, month - 1, day, hours, minutes, seconds);
1012
1128
  }
1013
1129
  toDateTime(num) {
1014
- return this._node.hf.numberToDateTime(num);
1130
+ invariant2(this._node, void 0, {
1131
+ F: __dxlog_file2,
1132
+ L: 403,
1133
+ S: this,
1134
+ A: [
1135
+ "this._node",
1136
+ ""
1137
+ ]
1138
+ });
1139
+ return this._node.graph.hf.numberToDateTime(num);
1015
1140
  }
1016
1141
  toDate(num) {
1017
- return this._node.hf.numberToDate(num);
1142
+ invariant2(this._node, void 0, {
1143
+ F: __dxlog_file2,
1144
+ L: 408,
1145
+ S: this,
1146
+ A: [
1147
+ "this._node",
1148
+ ""
1149
+ ]
1150
+ });
1151
+ return this._node.graph.hf.numberToDate(num);
1018
1152
  }
1019
1153
  toTime(num) {
1020
- return this._node.hf.numberToTime(num);
1154
+ invariant2(this._node, void 0, {
1155
+ F: __dxlog_file2,
1156
+ L: 413,
1157
+ S: this,
1158
+ A: [
1159
+ "this._node",
1160
+ ""
1161
+ ]
1162
+ });
1163
+ return this._node.graph.hf.numberToTime(num);
1021
1164
  }
1022
1165
  };
1023
1166
 
@@ -1030,11 +1173,10 @@ var useFormattingModel = (model) => {
1030
1173
 
1031
1174
  // packages/plugins/plugin-sheet/src/hooks/useSheetModel.ts
1032
1175
  import { useEffect as useEffect2, useState as useState3 } from "react";
1033
- var useSheetModel = (space, sheet, { readonly } = {}) => {
1034
- const graph = useComputeGraph(space);
1176
+ var useSheetModel = (graph, sheet, { readonly } = {}) => {
1035
1177
  const [model, setModel] = useState3();
1036
1178
  useEffect2(() => {
1037
- if (!space || !graph || !sheet) {
1179
+ if (!graph || !sheet) {
1038
1180
  return;
1039
1181
  }
1040
1182
  let model2;
@@ -1050,9 +1192,8 @@ var useSheetModel = (space, sheet, { readonly } = {}) => {
1050
1192
  void model2?.close();
1051
1193
  };
1052
1194
  }, [
1053
- space,
1054
- sheet,
1055
1195
  graph,
1196
+ sheet,
1056
1197
  readonly
1057
1198
  ]);
1058
1199
  return model;
@@ -1074,8 +1215,8 @@ var useSheetContext = () => {
1074
1215
  });
1075
1216
  return context;
1076
1217
  };
1077
- var SheetContextProvider = ({ children, sheet, space, readonly, onInfo }) => {
1078
- const model = useSheetModel(space, sheet, {
1218
+ var SheetContextProvider = ({ children, graph, sheet, readonly, onInfo }) => {
1219
+ const model = useSheetModel(graph, sheet, {
1079
1220
  readonly
1080
1221
  });
1081
1222
  const formatting = useFormattingModel(model);
@@ -1457,10 +1598,10 @@ var CellEditor = ({ value, extension, autoFocus, onBlur, variant = "legacy", box
1457
1598
  // packages/plugins/plugin-sheet/src/components/CellEditor/extension.ts
1458
1599
  import { acceptCompletion, autocompletion, completionStatus, startCompletion } from "@codemirror/autocomplete";
1459
1600
  import { HighlightStyle, syntaxHighlighting } from "@codemirror/language";
1460
- import { Facet } from "@codemirror/state";
1461
1601
  import { ViewPlugin, keymap as keymap2 } from "@codemirror/view";
1462
1602
  import { tags } from "@lezer/highlight";
1463
1603
  import { spreadsheet } from "codemirror-lang-spreadsheet";
1604
+ import { singleValueFacet } from "@dxos/react-ui-editor/state";
1464
1605
  import { mx } from "@dxos/react-ui-theme";
1465
1606
  var highlightStyles = HighlightStyle.define([
1466
1607
  // Function.
@@ -1492,7 +1633,7 @@ var highlightStyles = HighlightStyle.define([
1492
1633
  class: "text-unAccent"
1493
1634
  }
1494
1635
  ]);
1495
- var languageFacet = Facet.define();
1636
+ var languageFacet = singleValueFacet();
1496
1637
  var sheetExtension = ({ functions = [] }) => {
1497
1638
  const { extension, language } = spreadsheet({
1498
1639
  idiom: "en-US",
@@ -1609,7 +1750,7 @@ var rangeExtension = (onInit) => {
1609
1750
  update(view2) {
1610
1751
  const { anchor } = view2.state.selection.ranges[0];
1611
1752
  activeRange = void 0;
1612
- const [language] = view2.state.facet(languageFacet);
1753
+ const language = view2.state.facet(languageFacet);
1613
1754
  const { topNode } = language.parser.parse(view2.state.doc.toString());
1614
1755
  visitTree(topNode, ({ type, from, to }) => {
1615
1756
  if (from <= anchor && to >= anchor) {
@@ -2173,7 +2314,7 @@ var SheetGrid = /* @__PURE__ */ forwardRef(({ size, rows, columns, rowSizes, col
2173
2314
  id: model.id
2174
2315
  }, {
2175
2316
  F: __dxlog_file4,
2176
- L: 737,
2317
+ L: 738,
2177
2318
  S: void 0,
2178
2319
  C: (f, a) => f(...a)
2179
2320
  });
@@ -2291,8 +2432,7 @@ var SheetGrid = /* @__PURE__ */ forwardRef(({ size, rows, columns, rowSizes, col
2291
2432
  columnSizes
2292
2433
  });
2293
2434
  const id = fullyQualifiedId2(model.sheet);
2294
- const attendableAttrs = createAttendableAttributes(id);
2295
- const hasAttention = useHasAttention(id);
2435
+ const { hasAttention } = useAttention(id);
2296
2436
  return /* @__PURE__ */ React6.createElement("div", {
2297
2437
  ref: containerRef,
2298
2438
  role: "grid",
@@ -2379,13 +2519,25 @@ var SheetGrid = /* @__PURE__ */ forwardRef(({ size, rows, columns, rowSizes, col
2379
2519
  }
2380
2520
  });
2381
2521
  });
2382
- }))), /* @__PURE__ */ createPortal(/* @__PURE__ */ React6.createElement("input", {
2522
+ }))), /* @__PURE__ */ createPortal(/* @__PURE__ */ React6.createElement(SheetInput, {
2383
2523
  ref: inputRef,
2384
- autoFocus: true,
2524
+ id,
2525
+ onKeyDown: handleKeyDown
2526
+ }), document.body));
2527
+ });
2528
+ var SheetInput = /* @__PURE__ */ forwardRef(({ id, onKeyDown }, forwardedRef) => {
2529
+ const path = useAttentionPath();
2530
+ const attendableAttrs = useAttendableAttributes(id);
2531
+ return path.toReversed().reduce((acc, part) => {
2532
+ return /* @__PURE__ */ React6.createElement("div", {
2533
+ [ATTENABLE_ATTRIBUTE]: part
2534
+ }, acc);
2535
+ }, /* @__PURE__ */ React6.createElement("input", {
2536
+ ref: forwardedRef,
2385
2537
  className: "absolute w-[1px] h-[1px] bg-transparent outline-none border-none caret-transparent",
2386
- onKeyDown: handleKeyDown,
2538
+ onKeyDown,
2387
2539
  ...attendableAttrs
2388
- }), document.body));
2540
+ }));
2389
2541
  });
2390
2542
  var SelectionOverlay = ({ root }) => {
2391
2543
  const { range } = useSheetContext();
@@ -2546,8 +2698,9 @@ export {
2546
2698
  createSheet,
2547
2699
  addressToIndex,
2548
2700
  compareIndexPositions,
2701
+ useComputeGraph,
2549
2702
  useSheetContext,
2550
2703
  Sheet,
2551
2704
  SheetContainer
2552
2705
  };
2553
- //# sourceMappingURL=chunk-7HVSOTGA.mjs.map
2706
+ //# sourceMappingURL=chunk-KK3XL37M.mjs.map