@dxos/plugin-sheet 0.6.12-main.15a606f → 0.6.12-main.78ddbdf

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.
@@ -1 +1 @@
1
- {"version":3,"file":"GridSheet.stories.d.ts","sourceRoot":"","sources":["../../../../../src/components/GridSheet/GridSheet.stories.tsx"],"names":[],"mappings":"AAIA,OAAO,KAAK,MAAM,OAAO,CAAC;;;;;;AAU1B,wBASE;AAEF,eAAO,MAAM,KAAK,gCASjB,CAAC"}
1
+ {"version":3,"file":"GridSheet.stories.d.ts","sourceRoot":"","sources":["../../../../../src/components/GridSheet/GridSheet.stories.tsx"],"names":[],"mappings":"AAIA,OAAO,KAAK,MAAM,OAAO,CAAC;;;;;;AAW1B,wBASE;AAEF,eAAO,MAAM,KAAK,gCASjB,CAAC"}
@@ -1,6 +1,7 @@
1
- import { type GridEditing, type GridContentProps } from '@dxos/react-ui-grid';
1
+ import { type MutableRefObject } from 'react';
2
+ import { type GridEditing, type GridContentProps, type DxGridElement } from '@dxos/react-ui-grid';
2
3
  import { type CellAddress } from '../../defs';
3
4
  import { type SheetModel, type FormattingModel } from '../../model';
4
5
  export declare const dxGridCellIndexToSheetCellAddress: (gridEditing: GridEditing) => CellAddress | null;
5
- export declare const useSheetModelDxGridProps: (model: SheetModel, formatting: FormattingModel) => Pick<GridContentProps, "cells" | "columns" | "rows">;
6
+ export declare const useSheetModelDxGridProps: (dxGridRef: MutableRefObject<DxGridElement | null>, model: SheetModel, formatting: FormattingModel) => Pick<GridContentProps, "columns" | "rows">;
6
7
  //# sourceMappingURL=util.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"util.d.ts","sourceRoot":"","sources":["../../../../../src/components/GridSheet/util.ts"],"names":[],"mappings":"AAOA,OAAO,EAAE,KAAK,WAAW,EAAE,KAAK,gBAAgB,EAAE,MAAM,qBAAqB,CAAC;AAG9E,OAAO,EAAoB,KAAK,WAAW,EAAE,MAAM,YAAY,CAAC;AAChE,OAAO,EAAE,KAAK,UAAU,EAAE,KAAK,eAAe,EAAE,MAAM,aAAa,CAAC;AAEpE,eAAO,MAAM,iCAAiC,gBAAiB,WAAW,KAAG,WAAW,GAAG,IAS1F,CAAC;AA+BF,eAAO,MAAM,wBAAwB,UAC5B,UAAU,cACL,eAAe,KAC1B,IAAI,CAAC,gBAAgB,EAAE,OAAO,GAAG,SAAS,GAAG,MAAM,CAgCrD,CAAC"}
1
+ {"version":3,"file":"util.d.ts","sourceRoot":"","sources":["../../../../../src/components/GridSheet/util.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,KAAK,gBAAgB,EAAwC,MAAM,OAAO,CAAC;AAGpF,OAAO,EACL,KAAK,WAAW,EAChB,KAAK,gBAAgB,EACrB,KAAK,aAAa,EAInB,MAAM,qBAAqB,CAAC;AAG7B,OAAO,EAAE,KAAK,WAAW,EAAE,MAAM,YAAY,CAAC;AAC9C,OAAO,EAAE,KAAK,UAAU,EAAE,KAAK,eAAe,EAAE,MAAM,aAAa,CAAC;AAEpE,eAAO,MAAM,iCAAiC,gBAAiB,WAAW,KAAG,WAAW,GAAG,IAS1F,CAAC;AAwCF,eAAO,MAAM,wBAAwB,cACxB,gBAAgB,CAAC,aAAa,GAAG,IAAI,CAAC,SAC1C,UAAU,cACL,eAAe,KAC1B,IAAI,CAAC,gBAAgB,EAAE,SAAS,GAAG,MAAM,CAkC3C,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dxos/plugin-sheet",
3
- "version": "0.6.12-main.15a606f",
3
+ "version": "0.6.12-main.78ddbdf",
4
4
  "description": "Braneframe sketch plugin",
5
5
  "homepage": "https://dxos.org",
6
6
  "bugs": "https://github.com/dxos/dxos/issues",
@@ -78,29 +78,29 @@
78
78
  "re-resizable": "^6.9.17",
79
79
  "react-markdown": "^8.0.5",
80
80
  "react-resize-detector": "^11.0.1",
81
- "@dxos/app-framework": "0.6.12-main.15a606f",
82
- "@dxos/async": "0.6.12-main.15a606f",
83
- "@dxos/client": "0.6.12-main.15a606f",
84
- "@dxos/crypto": "0.6.12-main.15a606f",
85
- "@dxos/context": "0.6.12-main.15a606f",
86
- "@dxos/debug": "0.6.12-main.15a606f",
87
- "@dxos/echo-schema": "0.6.12-main.15a606f",
88
- "@dxos/invariant": "0.6.12-main.15a606f",
89
- "@dxos/keys": "0.6.12-main.15a606f",
90
- "@dxos/plugin-attention": "0.6.12-main.15a606f",
91
- "@dxos/log": "0.6.12-main.15a606f",
92
- "@dxos/plugin-client": "0.6.12-main.15a606f",
93
- "@dxos/plugin-graph": "0.6.12-main.15a606f",
94
- "@dxos/plugin-markdown": "0.6.12-main.15a606f",
95
- "@dxos/plugin-script": "0.6.12-main.15a606f",
96
- "@dxos/plugin-space": "0.6.12-main.15a606f",
97
- "@dxos/react-client": "0.6.12-main.15a606f",
98
- "@dxos/plugin-stack": "0.6.12-main.15a606f",
99
- "@dxos/react-hooks": "0.6.12-main.15a606f",
100
- "@dxos/react-ui-attention": "0.6.12-main.15a606f",
101
- "@dxos/react-ui-editor": "0.6.12-main.15a606f",
102
- "@dxos/react-ui-grid": "0.6.12-main.15a606f",
103
- "@dxos/util": "0.6.12-main.15a606f"
81
+ "@dxos/app-framework": "0.6.12-main.78ddbdf",
82
+ "@dxos/client": "0.6.12-main.78ddbdf",
83
+ "@dxos/async": "0.6.12-main.78ddbdf",
84
+ "@dxos/context": "0.6.12-main.78ddbdf",
85
+ "@dxos/crypto": "0.6.12-main.78ddbdf",
86
+ "@dxos/debug": "0.6.12-main.78ddbdf",
87
+ "@dxos/echo-schema": "0.6.12-main.78ddbdf",
88
+ "@dxos/invariant": "0.6.12-main.78ddbdf",
89
+ "@dxos/log": "0.6.12-main.78ddbdf",
90
+ "@dxos/plugin-attention": "0.6.12-main.78ddbdf",
91
+ "@dxos/keys": "0.6.12-main.78ddbdf",
92
+ "@dxos/plugin-graph": "0.6.12-main.78ddbdf",
93
+ "@dxos/plugin-client": "0.6.12-main.78ddbdf",
94
+ "@dxos/plugin-markdown": "0.6.12-main.78ddbdf",
95
+ "@dxos/plugin-script": "0.6.12-main.78ddbdf",
96
+ "@dxos/plugin-space": "0.6.12-main.78ddbdf",
97
+ "@dxos/plugin-stack": "0.6.12-main.78ddbdf",
98
+ "@dxos/react-client": "0.6.12-main.78ddbdf",
99
+ "@dxos/react-hooks": "0.6.12-main.78ddbdf",
100
+ "@dxos/react-ui-attention": "0.6.12-main.78ddbdf",
101
+ "@dxos/react-ui-editor": "0.6.12-main.78ddbdf",
102
+ "@dxos/react-ui-grid": "0.6.12-main.78ddbdf",
103
+ "@dxos/util": "0.6.12-main.78ddbdf"
104
104
  },
105
105
  "devDependencies": {
106
106
  "@lezer/generator": "^1.7.1",
@@ -113,20 +113,20 @@
113
113
  "react": "~18.2.0",
114
114
  "react-dom": "~18.2.0",
115
115
  "vite": "5.4.7",
116
- "@dxos/echo-generator": "0.6.12-main.15a606f",
117
- "@dxos/random": "0.6.12-main.15a606f",
118
- "@dxos/react-ui": "0.6.12-main.15a606f",
119
- "@dxos/react-ui-syntax-highlighter": "0.6.12-main.15a606f",
120
- "@dxos/react-ui-types": "0.6.12-main.15a606f",
121
- "@dxos/react-ui-theme": "0.6.12-main.15a606f",
122
- "@dxos/storybook-utils": "0.6.12-main.15a606f"
116
+ "@dxos/echo-generator": "0.6.12-main.78ddbdf",
117
+ "@dxos/react-ui": "0.6.12-main.78ddbdf",
118
+ "@dxos/random": "0.6.12-main.78ddbdf",
119
+ "@dxos/react-ui-syntax-highlighter": "0.6.12-main.78ddbdf",
120
+ "@dxos/react-ui-types": "0.6.12-main.78ddbdf",
121
+ "@dxos/storybook-utils": "0.6.12-main.78ddbdf",
122
+ "@dxos/react-ui-theme": "0.6.12-main.78ddbdf"
123
123
  },
124
124
  "optionalDependencies": {
125
125
  "@phosphor-icons/react": "^2.1.5",
126
126
  "react": "~18.2.0",
127
127
  "react-dom": "~18.2.0",
128
- "@dxos/react-ui": "0.6.12-main.15a606f",
129
- "@dxos/react-ui-theme": "0.6.12-main.15a606f"
128
+ "@dxos/react-ui-theme": "0.6.12-main.78ddbdf",
129
+ "@dxos/react-ui": "0.6.12-main.78ddbdf"
130
130
  },
131
131
  "publishConfig": {
132
132
  "access": "public"
@@ -11,12 +11,13 @@ import { withTheme, withLayout } from '@dxos/storybook-utils';
11
11
  import { GridSheet } from './GridSheet';
12
12
  import { useComputeGraph } from '../../hooks';
13
13
  import { useTestSheet, withGraphDecorator } from '../../testing';
14
+ import { SheetType } from '../../types';
14
15
 
15
16
  export default {
16
17
  title: 'plugin-sheet/GridSheet',
17
18
  component: GridSheet,
18
19
  decorators: [
19
- withClientProvider({ createSpace: true }),
20
+ withClientProvider({ types: [SheetType], createSpace: true }),
20
21
  withGraphDecorator,
21
22
  withTheme,
22
23
  withLayout({ fullscreen: true, tooltips: true }),
@@ -108,7 +108,7 @@ const GridSheetImpl = ({
108
108
  [editing],
109
109
  );
110
110
 
111
- const { cells, columns, rows } = useSheetModelDxGridProps(model, formatting);
111
+ const { columns, rows } = useSheetModelDxGridProps(dxGrid, model, formatting);
112
112
 
113
113
  const extension = useMemo(
114
114
  () => [
@@ -123,7 +123,7 @@ const GridSheetImpl = ({
123
123
  <>
124
124
  <GridSheetCellEditor model={model} extension={extension} />
125
125
  <Grid.Content
126
- cells={cells}
126
+ initialCells={{}}
127
127
  columns={columns}
128
128
  rows={rows}
129
129
  onAxisResize={handleAxisResize}
@@ -2,13 +2,20 @@
2
2
  // Copyright 2024 DXOS.org
3
3
  //
4
4
 
5
- import { useEffect, useState } from 'react';
5
+ import { type MutableRefObject, useEffect, useLayoutEffect, useState } from 'react';
6
6
 
7
7
  import { createDocAccessor } from '@dxos/react-client/echo';
8
- import { type GridEditing, type GridContentProps } from '@dxos/react-ui-grid';
8
+ import {
9
+ type GridEditing,
10
+ type GridContentProps,
11
+ type DxGridElement,
12
+ type DxGridCells,
13
+ type DxGridAxisMeta,
14
+ type DxGridRange,
15
+ } from '@dxos/react-ui-grid';
9
16
  import { mx } from '@dxos/react-ui-theme';
10
17
 
11
- import { addressFromIndex, type CellAddress } from '../../defs';
18
+ import { type CellAddress } from '../../defs';
12
19
  import { type SheetModel, type FormattingModel } from '../../model';
13
20
 
14
21
  export const dxGridCellIndexToSheetCellAddress = (gridEditing: GridEditing): CellAddress | null => {
@@ -22,19 +29,8 @@ export const dxGridCellIndexToSheetCellAddress = (gridEditing: GridEditing): Cel
22
29
  };
23
30
  };
24
31
 
25
- const createDxGridCells = (model: SheetModel, formatting: FormattingModel) => {
26
- return Object.keys(model.sheet.cells).reduce((acc: NonNullable<GridContentProps['cells']>, sheetCellIndex) => {
27
- const address = addressFromIndex(model.sheet, sheetCellIndex);
28
- const cell = formatting.getFormatting(address);
29
- if (cell.value) {
30
- acc[`${address.col},${address.row}`] = { value: cell.value, className: mx(cell.classNames) };
31
- }
32
- return acc;
33
- }, {});
34
- };
35
-
36
- const createDxGridColumns = (model: SheetModel): GridContentProps['columns'] => {
37
- return model.sheet.columns.reduce((acc: NonNullable<GridContentProps['columns']>, columnId, numericIndex) => {
32
+ const createDxGridColumns = (model: SheetModel): DxGridAxisMeta => {
33
+ return model.sheet.columns.reduce((acc: DxGridAxisMeta, columnId, numericIndex) => {
38
34
  if (model.sheet.columnMeta[columnId] && model.sheet.columnMeta[columnId].size) {
39
35
  acc[numericIndex] = { size: model.sheet.columnMeta[columnId].size, resizeable: true };
40
36
  }
@@ -42,8 +38,8 @@ const createDxGridColumns = (model: SheetModel): GridContentProps['columns'] =>
42
38
  }, {});
43
39
  };
44
40
 
45
- const createDxGridRows = (model: SheetModel): GridContentProps['rows'] => {
46
- return model.sheet.rows.reduce((acc: NonNullable<GridContentProps['rows']>, rowId, numericIndex) => {
41
+ const createDxGridRows = (model: SheetModel): DxGridAxisMeta => {
42
+ return model.sheet.rows.reduce((acc: DxGridAxisMeta, rowId, numericIndex) => {
47
43
  if (model.sheet.rowMeta[rowId] && model.sheet.rowMeta[rowId].size) {
48
44
  acc[numericIndex] = { size: model.sheet.rowMeta[rowId].size, resizeable: true };
49
45
  }
@@ -51,18 +47,41 @@ const createDxGridRows = (model: SheetModel): GridContentProps['rows'] => {
51
47
  }, {});
52
48
  };
53
49
 
50
+ const cellGetter = (model: SheetModel, formatting: FormattingModel) => {
51
+ // TODO(thure): Actually use the cache.
52
+ let _cachedBounds: DxGridRange | null = null;
53
+ const cachedCells: DxGridCells = {};
54
+ return (nextBounds: DxGridRange): DxGridCells => {
55
+ [...Array(nextBounds.end.col - nextBounds.start.col)].forEach((_, c0) => {
56
+ return [...Array(nextBounds.end.row - nextBounds.start.row)].forEach((_, r0) => {
57
+ const col = nextBounds.start.col + c0;
58
+ const row = nextBounds.start.row + r0;
59
+ const cell = formatting.getFormatting({ col, row });
60
+ if (cell.value) {
61
+ cachedCells[`${col},${row}`] = { value: cell.value, className: mx(cell.classNames) };
62
+ }
63
+ });
64
+ });
65
+ _cachedBounds = nextBounds;
66
+ return cachedCells;
67
+ };
68
+ };
69
+
54
70
  export const useSheetModelDxGridProps = (
71
+ dxGridRef: MutableRefObject<DxGridElement | null>,
55
72
  model: SheetModel,
56
73
  formatting: FormattingModel,
57
- ): Pick<GridContentProps, 'cells' | 'columns' | 'rows'> => {
58
- const [dxGridCells, setDxGridCells] = useState<GridContentProps['cells']>(createDxGridCells(model, formatting));
59
- const [dxGridColumns, setDxGridColumns] = useState<GridContentProps['columns']>(createDxGridColumns(model));
60
- const [dxGridRows, setDxGridRows] = useState<GridContentProps['rows']>(createDxGridColumns(model));
74
+ ): Pick<GridContentProps, 'columns' | 'rows'> => {
75
+ const [columns, setColumns] = useState<DxGridAxisMeta>(createDxGridColumns(model));
76
+ const [rows, setRows] = useState<DxGridAxisMeta>(createDxGridColumns(model));
61
77
 
62
- useEffect(() => {
78
+ useLayoutEffect(() => {
63
79
  const cellsAccessor = createDocAccessor(model.sheet, ['cells']);
80
+ if (dxGridRef.current) {
81
+ dxGridRef.current.getCells = cellGetter(model, formatting);
82
+ }
64
83
  const handleCellsUpdate = () => {
65
- setDxGridCells(createDxGridCells(model, formatting));
84
+ dxGridRef.current?.requestUpdate('initialCells');
66
85
  };
67
86
  cellsAccessor.handle.addListener('change', handleCellsUpdate);
68
87
  return () => cellsAccessor.handle.removeListener('change', handleCellsUpdate);
@@ -72,10 +91,10 @@ export const useSheetModelDxGridProps = (
72
91
  const columnMetaAccessor = createDocAccessor(model.sheet, ['columnMeta']);
73
92
  const rowMetaAccessor = createDocAccessor(model.sheet, ['rowMeta']);
74
93
  const handleColumnMetaUpdate = () => {
75
- setDxGridColumns(createDxGridColumns(model));
94
+ setColumns(createDxGridColumns(model));
76
95
  };
77
96
  const handleRowMetaUpdate = () => {
78
- setDxGridRows(createDxGridRows(model));
97
+ setRows(createDxGridRows(model));
79
98
  };
80
99
  columnMetaAccessor.handle.addListener('change', handleColumnMetaUpdate);
81
100
  rowMetaAccessor.handle.addListener('change', handleRowMetaUpdate);
@@ -85,5 +104,5 @@ export const useSheetModelDxGridProps = (
85
104
  };
86
105
  }, [model]);
87
106
 
88
- return { cells: dxGridCells, columns: dxGridColumns, rows: dxGridRows };
107
+ return { columns, rows };
89
108
  };