@dxos/plugin-sheet 0.6.12-main.78ddbdf → 0.6.12-main.89e9959

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 (160) 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/util.d.ts +9 -0
  49. package/dist/types/src/components/GridSheet/util.d.ts.map +1 -1
  50. package/dist/types/src/components/Sheet/Sheet.d.ts.map +1 -1
  51. package/dist/types/src/components/Sheet/Sheet.stories.d.ts.map +1 -1
  52. package/dist/types/src/components/Sheet/sheet-context.d.ts +3 -3
  53. package/dist/types/src/components/Sheet/sheet-context.d.ts.map +1 -1
  54. package/dist/types/src/components/SheetContainer.d.ts +1 -1
  55. package/dist/types/src/components/SheetContainer.d.ts.map +1 -1
  56. package/dist/types/src/components/index.d.ts +1 -1
  57. package/dist/types/src/components/index.d.ts.map +1 -1
  58. package/dist/types/src/defs/types.d.ts.map +1 -1
  59. package/dist/types/src/defs/util.d.ts +1 -1
  60. package/dist/types/src/defs/util.d.ts.map +1 -1
  61. package/dist/types/src/extensions/compute.d.ts +3 -2
  62. package/dist/types/src/extensions/compute.d.ts.map +1 -1
  63. package/dist/types/src/extensions/compute.stories.d.ts.map +1 -1
  64. package/dist/types/src/graph/compute-graph-registry.d.ts +34 -0
  65. package/dist/types/src/graph/compute-graph-registry.d.ts.map +1 -0
  66. package/dist/types/src/graph/compute-graph.d.ts +17 -34
  67. package/dist/types/src/graph/compute-graph.d.ts.map +1 -1
  68. package/dist/types/src/graph/compute-graph.stories.d.ts.map +1 -1
  69. package/dist/types/src/graph/compute-graph.test.d.ts +2 -0
  70. package/dist/types/src/graph/compute-graph.test.d.ts.map +1 -0
  71. package/dist/types/src/graph/compute-node.d.ts +9 -2
  72. package/dist/types/src/graph/compute-node.d.ts.map +1 -1
  73. package/dist/types/src/graph/{async-function.d.ts → functions/async-function.d.ts} +13 -4
  74. package/dist/types/src/graph/functions/async-function.d.ts.map +1 -0
  75. package/dist/types/src/graph/functions/edge-function.d.ts +21 -0
  76. package/dist/types/src/graph/functions/edge-function.d.ts.map +1 -0
  77. package/dist/types/src/graph/functions/function-defs.d.ts.map +1 -0
  78. package/dist/types/src/graph/functions/index.d.ts +4 -0
  79. package/dist/types/src/graph/functions/index.d.ts.map +1 -0
  80. package/dist/types/src/graph/index.d.ts +2 -1
  81. package/dist/types/src/graph/index.d.ts.map +1 -1
  82. package/dist/types/src/graph/testing/index.d.ts +3 -0
  83. package/dist/types/src/graph/testing/index.d.ts.map +1 -0
  84. package/dist/types/src/graph/testing/test-builder.d.ts +15 -0
  85. package/dist/types/src/graph/testing/test-builder.d.ts.map +1 -0
  86. package/dist/types/src/graph/testing/test-plugin.d.ts +36 -0
  87. package/dist/types/src/graph/testing/test-plugin.d.ts.map +1 -0
  88. package/dist/types/src/hooks/useComputeGraph.d.ts.map +1 -1
  89. package/dist/types/src/hooks/useSheetModel.d.ts +2 -2
  90. package/dist/types/src/hooks/useSheetModel.d.ts.map +1 -1
  91. package/dist/types/src/model/sheet-model.d.ts +3 -3
  92. package/dist/types/src/model/sheet-model.d.ts.map +1 -1
  93. package/dist/types/src/model/sheet-model.test.d.ts +2 -0
  94. package/dist/types/src/model/sheet-model.test.d.ts.map +1 -0
  95. package/dist/types/src/testing/testing.d.ts +4 -5
  96. package/dist/types/src/testing/testing.d.ts.map +1 -1
  97. package/dist/types/src/types.d.ts +4 -3
  98. package/dist/types/src/types.d.ts.map +1 -1
  99. package/package.json +40 -39
  100. package/src/SheetPlugin.tsx +19 -15
  101. package/src/components/CellEditor/CellEditor.stories.tsx +2 -3
  102. package/src/components/CellEditor/extension.test.ts +0 -1
  103. package/src/components/CellEditor/extension.ts +4 -3
  104. package/src/components/GridSheet/GridSheet.stories.tsx +3 -3
  105. package/src/components/GridSheet/GridSheet.tsx +26 -8
  106. package/src/components/GridSheet/util.ts +61 -21
  107. package/src/components/Sheet/Sheet.stories.tsx +21 -20
  108. package/src/components/Sheet/Sheet.tsx +30 -14
  109. package/src/components/Sheet/sheet-context.tsx +4 -4
  110. package/src/components/SheetContainer.tsx +13 -15
  111. package/src/defs/types.ts +1 -0
  112. package/src/defs/util.ts +19 -3
  113. package/src/extensions/compute.stories.tsx +20 -20
  114. package/src/extensions/compute.ts +91 -42
  115. package/src/graph/compute-graph-registry.ts +90 -0
  116. package/src/graph/compute-graph.stories.tsx +4 -3
  117. package/src/graph/compute-graph.test.ts +87 -0
  118. package/src/graph/compute-graph.ts +73 -121
  119. package/src/graph/compute-node.ts +17 -5
  120. package/src/graph/{async-function.ts → functions/async-function.ts} +23 -15
  121. package/src/graph/{edge-function.ts → functions/edge-function.ts} +14 -13
  122. package/src/graph/functions/index.ts +7 -0
  123. package/src/graph/hyperformula.test.ts +1 -2
  124. package/src/graph/index.ts +2 -1
  125. package/src/graph/testing/index.ts +6 -0
  126. package/src/graph/testing/test-builder.ts +54 -0
  127. package/src/graph/{custom-function.ts → testing/test-plugin.ts} +43 -9
  128. package/src/hooks/hooks.stories.tsx +3 -3
  129. package/src/hooks/useComputeGraph.ts +9 -1
  130. package/src/hooks/useSheetModel.ts +4 -7
  131. package/src/model/sheet-model.test.ts +59 -0
  132. package/src/model/sheet-model.ts +47 -30
  133. package/src/testing/testing.tsx +17 -15
  134. package/src/types.ts +3 -3
  135. package/dist/lib/browser/SheetContainer-V4GCCZTX.mjs.map +0 -7
  136. package/dist/lib/browser/chunk-6ZMQVB4Z.mjs.map +0 -7
  137. package/dist/lib/browser/chunk-U2JHW3L6.mjs.map +0 -7
  138. package/dist/lib/browser/graph-T27BOBOV.mjs +0 -21
  139. package/dist/lib/node/SheetContainer-3ZY7MPWJ.cjs.map +0 -7
  140. package/dist/lib/node/chunk-DD6FIXWC.cjs.map +0 -7
  141. package/dist/lib/node/chunk-OTTD7FBK.cjs.map +0 -7
  142. package/dist/lib/node/graph-SPKGX7W4.cjs +0 -43
  143. package/dist/lib/node/graph-SPKGX7W4.cjs.map +0 -7
  144. package/dist/lib/node-esm/SheetContainer-PXSJX6XK.mjs.map +0 -7
  145. package/dist/lib/node-esm/chunk-7HVSOTGA.mjs.map +0 -7
  146. package/dist/lib/node-esm/chunk-D6KU5MI7.mjs.map +0 -7
  147. package/dist/lib/node-esm/graph-U67IO4UC.mjs +0 -22
  148. package/dist/types/src/graph/async-function.d.ts.map +0 -1
  149. package/dist/types/src/graph/compute-graph.browser.test.d.ts +0 -2
  150. package/dist/types/src/graph/compute-graph.browser.test.d.ts.map +0 -1
  151. package/dist/types/src/graph/custom-function.d.ts +0 -21
  152. package/dist/types/src/graph/custom-function.d.ts.map +0 -1
  153. package/dist/types/src/graph/edge-function.d.ts +0 -20
  154. package/dist/types/src/graph/edge-function.d.ts.map +0 -1
  155. package/dist/types/src/graph/function-defs.d.ts.map +0 -1
  156. package/src/graph/compute-graph.browser.test.ts +0 -104
  157. /package/dist/lib/browser/{graph-T27BOBOV.mjs.map → graph-M4IQ76QX.mjs.map} +0 -0
  158. /package/dist/lib/node-esm/{graph-U67IO4UC.mjs.map → graph-SMPUMOV2.mjs.map} +0 -0
  159. /package/dist/types/src/graph/{function-defs.d.ts → functions/function-defs.d.ts} +0 -0
  160. /package/src/graph/{function-defs.ts → functions/function-defs.ts} +0 -0
@@ -26,20 +26,21 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
26
26
  mod
27
27
  ));
28
28
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
- var chunk_OTTD7FBK_exports = {};
30
- __export(chunk_OTTD7FBK_exports, {
29
+ var chunk_5FTFZL5W_exports = {};
30
+ __export(chunk_5FTFZL5W_exports, {
31
31
  ComputeGraphContextProvider: () => ComputeGraphContextProvider,
32
32
  Sheet: () => Sheet,
33
33
  SheetContainer: () => SheetContainer,
34
34
  addressToIndex: () => addressToIndex,
35
35
  compareIndexPositions: () => compareIndexPositions,
36
36
  createSheet: () => createSheet,
37
+ useComputeGraph: () => useComputeGraph,
37
38
  useSheetContext: () => useSheetContext
38
39
  });
39
- module.exports = __toCommonJS(chunk_OTTD7FBK_exports);
40
- var import_chunk_Q3HBHPRL = require("./chunk-Q3HBHPRL.cjs");
40
+ module.exports = __toCommonJS(chunk_5FTFZL5W_exports);
41
+ var import_chunk_AOP42UAA = require("./chunk-AOP42UAA.cjs");
41
42
  var import_chunk_BNARJ5GM = require("./chunk-BNARJ5GM.cjs");
42
- var import_chunk_DD6FIXWC = require("./chunk-DD6FIXWC.cjs");
43
+ var import_chunk_5XPK2V4A = require("./chunk-5XPK2V4A.cjs");
43
44
  var import_core = require("@dnd-kit/core");
44
45
  var import_modifiers = require("@dnd-kit/modifiers");
45
46
  var import_utilities = require("@dnd-kit/utilities");
@@ -69,6 +70,7 @@ var import_react8 = __toESM(require("react"));
69
70
  var import_react9 = require("react");
70
71
  var import_async2 = require("@dxos/async");
71
72
  var import_context = require("@dxos/context");
73
+ var import_echo_schema3 = require("@dxos/echo-schema");
72
74
  var import_invariant3 = require("@dxos/invariant");
73
75
  var import_keys = require("@dxos/keys");
74
76
  var import_log2 = require("@dxos/log");
@@ -86,10 +88,10 @@ var import_react_ui2 = require("@dxos/react-ui");
86
88
  var import_react_ui_editor = require("@dxos/react-ui-editor");
87
89
  var import_autocomplete = require("@codemirror/autocomplete");
88
90
  var import_language = require("@codemirror/language");
89
- var import_state = require("@codemirror/state");
90
91
  var import_view2 = require("@codemirror/view");
91
92
  var import_highlight = require("@lezer/highlight");
92
93
  var import_codemirror_lang_spreadsheet = require("codemirror-lang-spreadsheet");
94
+ var import_state = require("@dxos/react-ui-editor/state");
93
95
  var import_react_ui_theme2 = require("@dxos/react-ui-theme");
94
96
  var __dxlog_file = "/home/runner/work/dxos/dxos/packages/plugins/plugin-sheet/src/defs/types.ts";
95
97
  var DEFAULT_ROWS = 50;
@@ -118,7 +120,7 @@ var addressFromA1Notation = (ref) => {
118
120
  const match = ref.match(/([A-Z]+)(\d+)/);
119
121
  (0, import_invariant.invariant)(match, `Invalid notation: ${ref}`, {
120
122
  F: __dxlog_file,
121
- L: 39,
123
+ L: 40,
122
124
  S: void 0,
123
125
  A: [
124
126
  "match",
@@ -189,9 +191,9 @@ var initialize = (sheet, { rows = DEFAULT_ROWS, columns = DEFAULT_COLUMNS } = {}
189
191
  insertIndices(sheet.columns, 0, columns, MAX_COLUMNS);
190
192
  }
191
193
  };
192
- var createSheet = ({ title, ...size } = {}) => {
193
- const sheet = (0, import_echo_schema.create)(import_chunk_Q3HBHPRL.SheetType, {
194
- title,
194
+ var createSheet = ({ name, cells, ...size } = {}) => {
195
+ const sheet = (0, import_echo_schema.create)(import_chunk_AOP42UAA.SheetType, {
196
+ name,
195
197
  cells: {},
196
198
  rows: [],
197
199
  columns: [],
@@ -200,6 +202,14 @@ var createSheet = ({ title, ...size } = {}) => {
200
202
  formatting: {}
201
203
  });
202
204
  initialize(sheet, size);
205
+ if (cells) {
206
+ Object.entries(cells).forEach(([key, { value }]) => {
207
+ const idx = addressToIndex(sheet, addressFromA1Notation(key));
208
+ sheet.cells[idx] = {
209
+ value
210
+ };
211
+ });
212
+ }
203
213
  return sheet;
204
214
  };
205
215
  var addressToIndex = (sheet, cell) => {
@@ -569,13 +579,20 @@ var ComputeGraphContextProvider = ({ registry, children }) => {
569
579
  }
570
580
  }, children);
571
581
  };
572
- var SheetContainer = import_react7.default.lazy(() => import("./SheetContainer-3ZY7MPWJ.cjs"));
582
+ var SheetContainer = import_react7.default.lazy(() => import("./SheetContainer-OZ7DHH4L.cjs"));
573
583
  var useComputeGraph = (space) => {
574
584
  const { registry } = (0, import_react6.useContext)(ComputeGraphContext) ?? (0, import_debug.raise)(new Error("Missing ComputeGraphContext"));
575
- return (0, import_react_hooks.useAsyncState)(async () => space && registry.getOrCreateGraph(space), [
585
+ const [graph] = (0, import_react_hooks.useAsyncState)(async () => {
586
+ if (space) {
587
+ const graph2 = registry.getOrCreateGraph(space);
588
+ await graph2.open();
589
+ return graph2;
590
+ }
591
+ }, [
576
592
  space,
577
593
  registry
578
594
  ]);
595
+ return graph;
579
596
  };
580
597
  var FormattingModel = class {
581
598
  constructor(_model) {
@@ -609,7 +626,7 @@ var FormattingModel = class {
609
626
  const defaultNumber = "justify-end font-mono";
610
627
  const type = formatting?.type ?? this._model.getValueType(cell);
611
628
  switch (type) {
612
- case import_chunk_Q3HBHPRL.ValueTypeEnum.Boolean: {
629
+ case import_chunk_AOP42UAA.ValueTypeEnum.Boolean: {
613
630
  return {
614
631
  value: value.toLocaleString().toUpperCase(),
615
632
  classNames: [
@@ -621,7 +638,7 @@ var FormattingModel = class {
621
638
  //
622
639
  // Numbers.
623
640
  //
624
- case import_chunk_Q3HBHPRL.ValueTypeEnum.Number: {
641
+ case import_chunk_AOP42UAA.ValueTypeEnum.Number: {
625
642
  return {
626
643
  value: value.toLocaleString(locales),
627
644
  classNames: [
@@ -630,7 +647,7 @@ var FormattingModel = class {
630
647
  ]
631
648
  };
632
649
  }
633
- case import_chunk_Q3HBHPRL.ValueTypeEnum.Percent: {
650
+ case import_chunk_AOP42UAA.ValueTypeEnum.Percent: {
634
651
  return {
635
652
  value: value * 100 + "%",
636
653
  classNames: [
@@ -639,7 +656,7 @@ var FormattingModel = class {
639
656
  ]
640
657
  };
641
658
  }
642
- case import_chunk_Q3HBHPRL.ValueTypeEnum.Currency: {
659
+ case import_chunk_AOP42UAA.ValueTypeEnum.Currency: {
643
660
  return {
644
661
  value: value.toLocaleString(locales, {
645
662
  style: "currency",
@@ -656,21 +673,21 @@ var FormattingModel = class {
656
673
  //
657
674
  // Dates.
658
675
  //
659
- case import_chunk_Q3HBHPRL.ValueTypeEnum.DateTime: {
676
+ case import_chunk_AOP42UAA.ValueTypeEnum.DateTime: {
660
677
  const date = this._model.toLocalDate(value);
661
678
  return {
662
679
  value: date.toLocaleString(locales),
663
680
  classNames
664
681
  };
665
682
  }
666
- case import_chunk_Q3HBHPRL.ValueTypeEnum.Date: {
683
+ case import_chunk_AOP42UAA.ValueTypeEnum.Date: {
667
684
  const date = this._model.toLocalDate(value);
668
685
  return {
669
686
  value: date.toLocaleDateString(locales),
670
687
  classNames
671
688
  };
672
689
  }
673
- case import_chunk_Q3HBHPRL.ValueTypeEnum.Time: {
690
+ case import_chunk_AOP42UAA.ValueTypeEnum.Time: {
674
691
  const date = this._model.toLocalDate(value);
675
692
  return {
676
693
  value: date.toLocaleTimeString(locales),
@@ -688,13 +705,13 @@ var FormattingModel = class {
688
705
  };
689
706
  var __dxlog_file2 = "/home/runner/work/dxos/dxos/packages/plugins/plugin-sheet/src/model/sheet-model.ts";
690
707
  var typeMap = {
691
- BOOLEAN: import_chunk_Q3HBHPRL.ValueTypeEnum.Boolean,
692
- NUMBER_RAW: import_chunk_Q3HBHPRL.ValueTypeEnum.Number,
693
- NUMBER_PERCENT: import_chunk_Q3HBHPRL.ValueTypeEnum.Percent,
694
- NUMBER_CURRENCY: import_chunk_Q3HBHPRL.ValueTypeEnum.Currency,
695
- NUMBER_DATETIME: import_chunk_Q3HBHPRL.ValueTypeEnum.DateTime,
696
- NUMBER_DATE: import_chunk_Q3HBHPRL.ValueTypeEnum.Date,
697
- NUMBER_TIME: import_chunk_Q3HBHPRL.ValueTypeEnum.Time
708
+ BOOLEAN: import_chunk_AOP42UAA.ValueTypeEnum.Boolean,
709
+ NUMBER_RAW: import_chunk_AOP42UAA.ValueTypeEnum.Number,
710
+ NUMBER_PERCENT: import_chunk_AOP42UAA.ValueTypeEnum.Percent,
711
+ NUMBER_CURRENCY: import_chunk_AOP42UAA.ValueTypeEnum.Currency,
712
+ NUMBER_DATETIME: import_chunk_AOP42UAA.ValueTypeEnum.DateTime,
713
+ NUMBER_DATE: import_chunk_AOP42UAA.ValueTypeEnum.Date,
714
+ NUMBER_TIME: import_chunk_AOP42UAA.ValueTypeEnum.Time
698
715
  };
699
716
  var getTopLeft = (range) => {
700
717
  const to = range.to ?? range.from;
@@ -720,8 +737,6 @@ var SheetModel = class extends import_context.Resource {
720
737
  this._options = _options;
721
738
  this.id = `model-${import_keys.PublicKey.random().truncate()}`;
722
739
  this.update = new import_async2.Event();
723
- this._node = this._graph.getOrCreateNode((0, import_chunk_DD6FIXWC.createSheetName)(this._sheet.id));
724
- this.reset();
725
740
  }
726
741
  get graph() {
727
742
  return this._graph;
@@ -746,14 +761,19 @@ var SheetModel = class extends import_context.Resource {
746
761
  id: this.id
747
762
  }, {
748
763
  F: __dxlog_file2,
749
- L: 105,
764
+ L: 104,
750
765
  S: this,
751
766
  C: (f, a) => f(...a)
752
767
  });
753
768
  initialize(this._sheet);
754
- this.reset();
755
- const unsubscribe = this._graph.update.on(() => this.update.emit());
769
+ this._node = this._graph.getOrCreateNode((0, import_chunk_5XPK2V4A.createSheetName)({
770
+ type: (0, import_echo_schema3.getTypename)(this._sheet),
771
+ id: this._sheet.id
772
+ }));
773
+ await this._node.open();
774
+ const unsubscribe = this._node.update.on((event) => this.update.emit(event));
756
775
  this._ctx.onDispose(unsubscribe);
776
+ this.reset();
757
777
  }
758
778
  /**
759
779
  * Update engine.
@@ -761,13 +781,31 @@ var SheetModel = class extends import_context.Resource {
761
781
  * @deprecated
762
782
  */
763
783
  reset() {
764
- this._node.hf.clearSheet(this._node.sheetId);
784
+ (0, import_invariant3.invariant)(this._node, void 0, {
785
+ F: __dxlog_file2,
786
+ L: 124,
787
+ S: this,
788
+ A: [
789
+ "this._node",
790
+ ""
791
+ ]
792
+ });
793
+ this._node.graph.hf.clearSheet(this._node.sheetId);
765
794
  Object.entries(this._sheet.cells).forEach(([key, { value }]) => {
795
+ (0, import_invariant3.invariant)(this._node, void 0, {
796
+ F: __dxlog_file2,
797
+ L: 127,
798
+ S: this,
799
+ A: [
800
+ "this._node",
801
+ ""
802
+ ]
803
+ });
766
804
  const { col, row } = addressFromIndex(this._sheet, key);
767
805
  if (typeof value === "string" && value.charAt(0) === "=") {
768
806
  value = this._graph.mapFormulaToNative(this._graph.mapFunctionBindingFromId(this.mapFormulaIndicesToRefs(value)));
769
807
  }
770
- this._node.hf.setCellContents({
808
+ this._node.graph.hf.setCellContents({
771
809
  sheet: this._node.sheetId,
772
810
  row,
773
811
  col
@@ -782,7 +820,7 @@ var SheetModel = class extends import_context.Resource {
782
820
  */
783
821
  // TODO(burdon): Remove.
784
822
  recalculate() {
785
- this._node.hf.rebuildAndRecalculate();
823
+ this._node?.graph.hf.rebuildAndRecalculate();
786
824
  }
787
825
  insertRows(i, n = 1) {
788
826
  insertIndices(this._sheet.rows, i, n, MAX_ROWS);
@@ -800,27 +838,63 @@ var SheetModel = class extends import_context.Resource {
800
838
  * Clear range of values.
801
839
  */
802
840
  clear(range) {
841
+ (0, import_invariant3.invariant)(this._node, void 0, {
842
+ F: __dxlog_file2,
843
+ L: 169,
844
+ S: this,
845
+ A: [
846
+ "this._node",
847
+ ""
848
+ ]
849
+ });
803
850
  const topLeft = getTopLeft(range);
804
851
  const values = this._iterRange(range, () => null);
805
- this._node.hf.setCellContents(toSimpleCellAddress(this._node.sheetId, topLeft), values);
852
+ this._node.graph.hf.setCellContents(toSimpleCellAddress(this._node.sheetId, topLeft), values);
806
853
  this._iterRange(range, (cell) => {
807
854
  const idx = addressToIndex(this._sheet, cell);
808
855
  delete this._sheet.cells[idx];
809
856
  });
810
857
  }
811
858
  cut(range) {
812
- this._node.hf.cut(toModelRange(this._node.sheetId, range));
859
+ (0, import_invariant3.invariant)(this._node, void 0, {
860
+ F: __dxlog_file2,
861
+ L: 180,
862
+ S: this,
863
+ A: [
864
+ "this._node",
865
+ ""
866
+ ]
867
+ });
868
+ this._node.graph.hf.cut(toModelRange(this._node.sheetId, range));
813
869
  this._iterRange(range, (cell) => {
814
870
  const idx = addressToIndex(this._sheet, cell);
815
871
  delete this._sheet.cells[idx];
816
872
  });
817
873
  }
818
874
  copy(range) {
819
- this._node.hf.copy(toModelRange(this._node.sheetId, range));
875
+ (0, import_invariant3.invariant)(this._node, void 0, {
876
+ F: __dxlog_file2,
877
+ L: 189,
878
+ S: this,
879
+ A: [
880
+ "this._node",
881
+ ""
882
+ ]
883
+ });
884
+ this._node.graph.hf.copy(toModelRange(this._node.sheetId, range));
820
885
  }
821
886
  paste(cell) {
822
- if (!this._node.hf.isClipboardEmpty()) {
823
- const changes = this._node.hf.paste(toSimpleCellAddress(this._node.sheetId, cell));
887
+ (0, import_invariant3.invariant)(this._node, void 0, {
888
+ F: __dxlog_file2,
889
+ L: 194,
890
+ S: this,
891
+ A: [
892
+ "this._node",
893
+ ""
894
+ ]
895
+ });
896
+ if (!this._node.graph.hf.isClipboardEmpty()) {
897
+ const changes = this._node.graph.hf.paste(toSimpleCellAddress(this._node.sheetId, cell));
824
898
  for (const change of changes) {
825
899
  if (change instanceof import_hyperformula.ExportedCellChange) {
826
900
  const { address, newValue } = change;
@@ -837,15 +911,31 @@ var SheetModel = class extends import_context.Resource {
837
911
  }
838
912
  // TODO(burdon): Display undo/redo state.
839
913
  undo() {
840
- if (this._node.hf.isThereSomethingToUndo()) {
841
- this._node.hf.undo();
842
- this.update.emit();
914
+ (0, import_invariant3.invariant)(this._node, void 0, {
915
+ F: __dxlog_file2,
916
+ L: 209,
917
+ S: this,
918
+ A: [
919
+ "this._node",
920
+ ""
921
+ ]
922
+ });
923
+ if (this._node.graph.hf.isThereSomethingToUndo()) {
924
+ this._node.graph.hf.undo();
843
925
  }
844
926
  }
845
927
  redo() {
846
- if (this._node.hf.isThereSomethingToRedo()) {
847
- this._node.hf.redo();
848
- this.update.emit();
928
+ (0, import_invariant3.invariant)(this._node, void 0, {
929
+ F: __dxlog_file2,
930
+ L: 217,
931
+ S: this,
932
+ A: [
933
+ "this._node",
934
+ ""
935
+ ]
936
+ });
937
+ if (this._node.graph.hf.isThereSomethingToRedo()) {
938
+ this._node.graph.hf.redo();
849
939
  }
850
940
  }
851
941
  /**
@@ -879,7 +969,16 @@ var SheetModel = class extends import_context.Resource {
879
969
  * Gets the regular or computed value from the engine.
880
970
  */
881
971
  getValue(cell) {
882
- const value = this._node.hf.getCellValue(toSimpleCellAddress(this._node.sheetId, cell));
972
+ (0, import_invariant3.invariant)(this._node, void 0, {
973
+ F: __dxlog_file2,
974
+ L: 260,
975
+ S: this,
976
+ A: [
977
+ "this._node",
978
+ ""
979
+ ]
980
+ });
981
+ const value = this._node.graph.hf.getCellValue(toSimpleCellAddress(this._node.sheetId, cell));
883
982
  if (value instanceof import_hyperformula.DetailedCellError) {
884
983
  return value.toString();
885
984
  }
@@ -889,14 +988,32 @@ var SheetModel = class extends import_context.Resource {
889
988
  * Get value type.
890
989
  */
891
990
  getValueType(cell) {
991
+ (0, import_invariant3.invariant)(this._node, void 0, {
992
+ F: __dxlog_file2,
993
+ L: 273,
994
+ S: this,
995
+ A: [
996
+ "this._node",
997
+ ""
998
+ ]
999
+ });
892
1000
  const addr = toSimpleCellAddress(this._node.sheetId, cell);
893
- const type = this._node.hf.getCellValueDetailedType(addr);
1001
+ const type = this._node.graph.hf.getCellValueDetailedType(addr);
894
1002
  return typeMap[type];
895
1003
  }
896
1004
  /**
897
1005
  * Sets the value, updating the sheet and engine.
898
1006
  */
899
1007
  setValue(cell, value) {
1008
+ (0, import_invariant3.invariant)(this._node, void 0, {
1009
+ F: __dxlog_file2,
1010
+ L: 283,
1011
+ S: this,
1012
+ A: [
1013
+ "this._node",
1014
+ ""
1015
+ ]
1016
+ });
900
1017
  if (this._options.readonly) {
901
1018
  throw new ReadonlyException();
902
1019
  }
@@ -912,7 +1029,7 @@ var SheetModel = class extends import_context.Resource {
912
1029
  if (refresh) {
913
1030
  this.reset();
914
1031
  }
915
- this._node.hf.setCellContents({
1032
+ this._node.graph.hf.setCellContents({
916
1033
  sheet: this._node.sheetId,
917
1034
  row: cell.row,
918
1035
  col: cell.col
@@ -987,7 +1104,7 @@ var SheetModel = class extends import_context.Resource {
987
1104
  mapFormulaRefsToIndices(formula) {
988
1105
  (0, import_invariant3.invariant)(formula.charAt(0) === "=", void 0, {
989
1106
  F: __dxlog_file2,
990
- L: 358,
1107
+ L: 372,
991
1108
  S: this,
992
1109
  A: [
993
1110
  "formula.charAt(0) === '='",
@@ -1004,7 +1121,7 @@ var SheetModel = class extends import_context.Resource {
1004
1121
  mapFormulaIndicesToRefs(formula) {
1005
1122
  (0, import_invariant3.invariant)(formula.charAt(0) === "=", void 0, {
1006
1123
  F: __dxlog_file2,
1007
- L: 368,
1124
+ L: 382,
1008
1125
  S: this,
1009
1126
  A: [
1010
1127
  "formula.charAt(0) === '='",
@@ -1028,13 +1145,40 @@ var SheetModel = class extends import_context.Resource {
1028
1145
  return new Date(year, month - 1, day, hours, minutes, seconds);
1029
1146
  }
1030
1147
  toDateTime(num) {
1031
- return this._node.hf.numberToDateTime(num);
1148
+ (0, import_invariant3.invariant)(this._node, void 0, {
1149
+ F: __dxlog_file2,
1150
+ L: 403,
1151
+ S: this,
1152
+ A: [
1153
+ "this._node",
1154
+ ""
1155
+ ]
1156
+ });
1157
+ return this._node.graph.hf.numberToDateTime(num);
1032
1158
  }
1033
1159
  toDate(num) {
1034
- return this._node.hf.numberToDate(num);
1160
+ (0, import_invariant3.invariant)(this._node, void 0, {
1161
+ F: __dxlog_file2,
1162
+ L: 408,
1163
+ S: this,
1164
+ A: [
1165
+ "this._node",
1166
+ ""
1167
+ ]
1168
+ });
1169
+ return this._node.graph.hf.numberToDate(num);
1035
1170
  }
1036
1171
  toTime(num) {
1037
- return this._node.hf.numberToTime(num);
1172
+ (0, import_invariant3.invariant)(this._node, void 0, {
1173
+ F: __dxlog_file2,
1174
+ L: 413,
1175
+ S: this,
1176
+ A: [
1177
+ "this._node",
1178
+ ""
1179
+ ]
1180
+ });
1181
+ return this._node.graph.hf.numberToTime(num);
1038
1182
  }
1039
1183
  };
1040
1184
  var useFormattingModel = (model) => {
@@ -1042,11 +1186,10 @@ var useFormattingModel = (model) => {
1042
1186
  model
1043
1187
  ]);
1044
1188
  };
1045
- var useSheetModel = (space, sheet, { readonly } = {}) => {
1046
- const graph = useComputeGraph(space);
1189
+ var useSheetModel = (graph, sheet, { readonly } = {}) => {
1047
1190
  const [model, setModel] = (0, import_react10.useState)();
1048
1191
  (0, import_react10.useEffect)(() => {
1049
- if (!space || !graph || !sheet) {
1192
+ if (!graph || !sheet) {
1050
1193
  return;
1051
1194
  }
1052
1195
  let model2;
@@ -1062,9 +1205,8 @@ var useSheetModel = (space, sheet, { readonly } = {}) => {
1062
1205
  void model2?.close();
1063
1206
  };
1064
1207
  }, [
1065
- space,
1066
- sheet,
1067
1208
  graph,
1209
+ sheet,
1068
1210
  readonly
1069
1211
  ]);
1070
1212
  return model;
@@ -1084,8 +1226,8 @@ var useSheetContext = () => {
1084
1226
  });
1085
1227
  return context;
1086
1228
  };
1087
- var SheetContextProvider = ({ children, sheet, space, readonly, onInfo }) => {
1088
- const model = useSheetModel(space, sheet, {
1229
+ var SheetContextProvider = ({ children, graph, sheet, readonly, onInfo }) => {
1230
+ const model = useSheetModel(graph, sheet, {
1089
1231
  readonly
1090
1232
  });
1091
1233
  const formatting = useFormattingModel(model);
@@ -1477,7 +1619,7 @@ var highlightStyles = import_language.HighlightStyle.define([
1477
1619
  class: "text-unAccent"
1478
1620
  }
1479
1621
  ]);
1480
- var languageFacet = import_state.Facet.define();
1622
+ var languageFacet = (0, import_state.singleValueFacet)();
1481
1623
  var sheetExtension = ({ functions = [] }) => {
1482
1624
  const { extension, language } = (0, import_codemirror_lang_spreadsheet.spreadsheet)({
1483
1625
  idiom: "en-US",
@@ -1594,7 +1736,7 @@ var rangeExtension = (onInit) => {
1594
1736
  update(view2) {
1595
1737
  const { anchor } = view2.state.selection.ranges[0];
1596
1738
  activeRange = void 0;
1597
- const [language] = view2.state.facet(languageFacet);
1739
+ const language = view2.state.facet(languageFacet);
1598
1740
  const { topNode } = language.parser.parse(view2.state.doc.toString());
1599
1741
  visitTree(topNode, ({ type, from, to }) => {
1600
1742
  if (from <= anchor && to >= anchor) {
@@ -2156,7 +2298,7 @@ var SheetGrid = /* @__PURE__ */ (0, import_react2.forwardRef)(({ size, rows, col
2156
2298
  id: model.id
2157
2299
  }, {
2158
2300
  F: __dxlog_file4,
2159
- L: 737,
2301
+ L: 738,
2160
2302
  S: void 0,
2161
2303
  C: (f, a) => f(...a)
2162
2304
  });
@@ -2274,8 +2416,7 @@ var SheetGrid = /* @__PURE__ */ (0, import_react2.forwardRef)(({ size, rows, col
2274
2416
  columnSizes
2275
2417
  });
2276
2418
  const id = (0, import_echo.fullyQualifiedId)(model.sheet);
2277
- const attendableAttrs = (0, import_react_ui_attention.createAttendableAttributes)(id);
2278
- const hasAttention = (0, import_react_ui_attention.useHasAttention)(id);
2419
+ const { hasAttention } = (0, import_react_ui_attention.useAttention)(id);
2279
2420
  return /* @__PURE__ */ import_react2.default.createElement("div", {
2280
2421
  ref: containerRef,
2281
2422
  role: "grid",
@@ -2362,13 +2503,25 @@ var SheetGrid = /* @__PURE__ */ (0, import_react2.forwardRef)(({ size, rows, col
2362
2503
  }
2363
2504
  });
2364
2505
  });
2365
- }))), /* @__PURE__ */ (0, import_react_dom.createPortal)(/* @__PURE__ */ import_react2.default.createElement("input", {
2506
+ }))), /* @__PURE__ */ (0, import_react_dom.createPortal)(/* @__PURE__ */ import_react2.default.createElement(SheetInput, {
2366
2507
  ref: inputRef,
2367
- autoFocus: true,
2508
+ id,
2509
+ onKeyDown: handleKeyDown
2510
+ }), document.body));
2511
+ });
2512
+ var SheetInput = /* @__PURE__ */ (0, import_react2.forwardRef)(({ id, onKeyDown }, forwardedRef) => {
2513
+ const path = (0, import_react_ui_attention.useAttentionPath)();
2514
+ const attendableAttrs = (0, import_react_ui_attention.useAttendableAttributes)(id);
2515
+ return path.toReversed().reduce((acc, part) => {
2516
+ return /* @__PURE__ */ import_react2.default.createElement("div", {
2517
+ [import_react_ui_attention.ATTENABLE_ATTRIBUTE]: part
2518
+ }, acc);
2519
+ }, /* @__PURE__ */ import_react2.default.createElement("input", {
2520
+ ref: forwardedRef,
2368
2521
  className: "absolute w-[1px] h-[1px] bg-transparent outline-none border-none caret-transparent",
2369
- onKeyDown: handleKeyDown,
2522
+ onKeyDown,
2370
2523
  ...attendableAttrs
2371
- }), document.body));
2524
+ }));
2372
2525
  });
2373
2526
  var SelectionOverlay = ({ root }) => {
2374
2527
  const { range } = useSheetContext();
@@ -2531,6 +2684,7 @@ var Sheet = {
2531
2684
  addressToIndex,
2532
2685
  compareIndexPositions,
2533
2686
  createSheet,
2687
+ useComputeGraph,
2534
2688
  useSheetContext
2535
2689
  });
2536
- //# sourceMappingURL=chunk-OTTD7FBK.cjs.map
2690
+ //# sourceMappingURL=chunk-5FTFZL5W.cjs.map