@dxos/plugin-sheet 0.8.4-main.bc674ce → 0.8.4-main.c351d160a8
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.
- package/dist/lib/browser/RangeList-YI6FSF3S.mjs +48 -0
- package/dist/lib/browser/RangeList-YI6FSF3S.mjs.map +7 -0
- package/dist/lib/browser/{chunk-S27QJYTN.mjs → SheetContainer-O577SWMS.mjs} +578 -243
- package/dist/lib/browser/SheetContainer-O577SWMS.mjs.map +7 -0
- package/dist/lib/browser/{anchor-sort-LLO7PZKF.mjs → anchor-sort-NV6MQFUH.mjs} +5 -4
- package/dist/lib/browser/anchor-sort-NV6MQFUH.mjs.map +7 -0
- package/dist/lib/browser/{chunk-KE3AKN5W.mjs → chunk-GHS75KWH.mjs} +15 -32
- package/dist/lib/browser/chunk-GHS75KWH.mjs.map +7 -0
- package/dist/lib/browser/{chunk-IFLWVS2V.mjs → chunk-NNWF7EKC.mjs} +10 -10
- package/dist/lib/browser/{chunk-IFLWVS2V.mjs.map → chunk-NNWF7EKC.mjs.map} +2 -2
- package/dist/lib/browser/{compute-graph-registry-RC5L7RE4.mjs → compute-graph-registry-HVVALVIE.mjs} +2 -2
- package/dist/lib/browser/index.mjs +24 -27
- package/dist/lib/browser/index.mjs.map +3 -3
- package/dist/lib/browser/{markdown-D2T2DOVX.mjs → markdown-I2REDYX5.mjs} +3 -3
- package/dist/lib/browser/meta.json +1 -1
- package/dist/lib/browser/{operation-resolver-YDOW72CN.mjs → operation-resolver-VGBMFSYG.mjs} +5 -19
- package/dist/lib/browser/operation-resolver-VGBMFSYG.mjs.map +7 -0
- package/dist/lib/browser/react-surface-NSPYPZYP.mjs +52 -0
- package/dist/lib/browser/react-surface-NSPYPZYP.mjs.map +7 -0
- package/dist/lib/browser/types/index.mjs +1 -1
- package/dist/lib/node-esm/RangeList-7EG3K4KG.mjs +49 -0
- package/dist/lib/node-esm/RangeList-7EG3K4KG.mjs.map +7 -0
- package/dist/lib/node-esm/{chunk-Y4V6HVHO.mjs → SheetContainer-ICPEZUMD.mjs} +578 -243
- package/dist/lib/node-esm/SheetContainer-ICPEZUMD.mjs.map +7 -0
- package/dist/lib/node-esm/{anchor-sort-OX5I2YOW.mjs → anchor-sort-7XYLH2AM.mjs} +5 -4
- package/dist/lib/node-esm/anchor-sort-7XYLH2AM.mjs.map +7 -0
- package/dist/lib/node-esm/{chunk-PPOYR7DK.mjs → chunk-M52YLLWU.mjs} +10 -10
- package/dist/lib/node-esm/{chunk-PPOYR7DK.mjs.map → chunk-M52YLLWU.mjs.map} +2 -2
- package/dist/lib/node-esm/{chunk-6J5L47IB.mjs → chunk-VGXC77GH.mjs} +15 -32
- package/dist/lib/node-esm/chunk-VGXC77GH.mjs.map +7 -0
- package/dist/lib/node-esm/{compute-graph-registry-ZGXVLVGD.mjs → compute-graph-registry-IDU2KKQU.mjs} +2 -2
- package/dist/lib/node-esm/index.mjs +24 -27
- package/dist/lib/node-esm/index.mjs.map +3 -3
- package/dist/lib/node-esm/{markdown-PTV72DLO.mjs → markdown-6KBH3MBO.mjs} +3 -3
- package/dist/lib/node-esm/meta.json +1 -1
- package/dist/lib/node-esm/{operation-resolver-Q63VQBVA.mjs → operation-resolver-E7FIHPCO.mjs} +5 -19
- package/dist/lib/node-esm/operation-resolver-E7FIHPCO.mjs.map +7 -0
- package/dist/lib/node-esm/{react-surface-SWRZSZVR.mjs → react-surface-LCMQBROP.mjs} +22 -21
- package/dist/lib/node-esm/react-surface-LCMQBROP.mjs.map +7 -0
- package/dist/lib/node-esm/types/index.mjs +1 -1
- package/dist/types/src/SheetPlugin.d.ts.map +1 -1
- package/dist/types/src/capabilities/anchor-sort/anchor-sort.d.ts +3 -2
- package/dist/types/src/capabilities/anchor-sort/anchor-sort.d.ts.map +1 -1
- package/dist/types/src/capabilities/anchor-sort/index.d.ts +1 -1
- package/dist/types/src/capabilities/anchor-sort/index.d.ts.map +1 -1
- package/dist/types/src/capabilities/compute-graph-registry/compute-graph-registry.d.ts +1 -1
- package/dist/types/src/capabilities/markdown/markdown.d.ts +1 -1
- package/dist/types/src/capabilities/operation-resolver/index.d.ts +1 -1
- package/dist/types/src/capabilities/operation-resolver/index.d.ts.map +1 -1
- package/dist/types/src/capabilities/operation-resolver/operation-resolver.d.ts +2 -2
- package/dist/types/src/capabilities/operation-resolver/operation-resolver.d.ts.map +1 -1
- package/dist/types/src/capabilities/react-surface/index.d.ts +1 -1
- package/dist/types/src/capabilities/react-surface/index.d.ts.map +1 -1
- package/dist/types/src/capabilities/react-surface/react-surface.d.ts +2 -2
- package/dist/types/src/capabilities/react-surface/react-surface.d.ts.map +1 -1
- package/dist/types/src/components/Sheet/Sheet.d.ts +15 -0
- package/dist/types/src/components/Sheet/Sheet.d.ts.map +1 -0
- package/dist/types/src/components/Sheet/index.d.ts +2 -0
- package/dist/types/src/components/Sheet/index.d.ts.map +1 -0
- package/dist/types/src/components/SheetContent/SheetCellEditor.stories.d.ts.map +1 -0
- package/dist/types/src/components/SheetContent/SheetContent.d.ts +7 -0
- package/dist/types/src/components/SheetContent/SheetContent.d.ts.map +1 -0
- package/dist/types/src/components/{GridSheet/GridSheet.stories.d.ts → SheetContent/SheetContent.stories.d.ts} +5 -2
- package/dist/types/src/components/SheetContent/SheetContent.stories.d.ts.map +1 -0
- package/dist/types/src/components/SheetContent/index.d.ts +2 -0
- package/dist/types/src/components/SheetContent/index.d.ts.map +1 -0
- package/dist/types/src/components/SheetContent/util.d.ts.map +1 -0
- package/dist/types/src/components/{SheetContext/SheetContext.d.ts → SheetRoot/SheetRoot.d.ts} +6 -4
- package/dist/types/src/components/SheetRoot/SheetRoot.d.ts.map +1 -0
- package/dist/types/src/components/SheetRoot/index.d.ts +2 -0
- package/dist/types/src/components/SheetRoot/index.d.ts.map +1 -0
- package/dist/types/src/components/SheetStatusbar/SheetStatusbar.d.ts +7 -0
- package/dist/types/src/components/SheetStatusbar/SheetStatusbar.d.ts.map +1 -0
- package/dist/types/src/components/SheetStatusbar/index.d.ts +2 -0
- package/dist/types/src/components/SheetStatusbar/index.d.ts.map +1 -0
- package/dist/types/src/components/SheetToolbar/SheetToolbar.d.ts +6 -3
- package/dist/types/src/components/SheetToolbar/SheetToolbar.d.ts.map +1 -1
- package/dist/types/src/components/SheetToolbar/SheetToolbar.stories.d.ts +2 -0
- package/dist/types/src/components/SheetToolbar/SheetToolbar.stories.d.ts.map +1 -1
- package/dist/types/src/components/index.d.ts +1 -4
- package/dist/types/src/components/index.d.ts.map +1 -1
- package/dist/types/src/{components → containers}/RangeList/RangeList.d.ts.map +1 -1
- package/dist/types/src/containers/RangeList/index.d.ts +3 -0
- package/dist/types/src/containers/RangeList/index.d.ts.map +1 -0
- package/dist/types/src/containers/SheetContainer/SheetContainer.d.ts +12 -0
- package/dist/types/src/containers/SheetContainer/SheetContainer.d.ts.map +1 -0
- package/dist/types/src/{components → containers}/SheetContainer/SheetContainer.stories.d.ts +2 -2
- package/dist/types/src/containers/SheetContainer/SheetContainer.stories.d.ts.map +1 -0
- package/dist/types/src/{components → containers}/SheetContainer/index.d.ts.map +1 -1
- package/dist/types/src/containers/index.d.ts +4 -0
- package/dist/types/src/containers/index.d.ts.map +1 -0
- package/dist/types/src/extensions/compute.stories.d.ts.map +1 -1
- package/dist/types/src/integrations/thread-ranges.d.ts.map +1 -1
- package/dist/types/src/model/sheet-model.d.ts.map +1 -1
- package/dist/types/src/testing/testing.d.ts +1 -1
- package/dist/types/src/translations.d.ts +1 -0
- package/dist/types/src/translations.d.ts.map +1 -1
- package/dist/types/src/types/Sheet.d.ts +1 -1
- package/dist/types/src/types/Sheet.d.ts.map +1 -1
- package/dist/types/src/types/types.d.ts +3 -24
- package/dist/types/src/types/types.d.ts.map +1 -1
- package/dist/types/tsconfig.tsbuildinfo +1 -1
- package/package.json +62 -62
- package/src/SheetPlugin.tsx +15 -24
- package/src/capabilities/anchor-sort/anchor-sort.ts +3 -2
- package/src/capabilities/operation-resolver/operation-resolver.ts +4 -15
- package/src/capabilities/react-surface/react-surface.tsx +19 -13
- package/src/components/ComputeGraph/compute-graph.stories.tsx +2 -2
- package/src/components/Sheet/Sheet.tsx +20 -0
- package/src/components/Sheet/index.ts +5 -0
- package/src/components/{GridSheet → SheetContent}/SheetCellEditor.stories.tsx +5 -5
- package/src/components/{GridSheet/GridSheet.stories.tsx → SheetContent/SheetContent.stories.tsx} +12 -11
- package/src/components/{GridSheet/GridSheet.tsx → SheetContent/SheetContent.tsx} +14 -11
- package/src/components/{RangeList → SheetContent}/index.ts +1 -1
- package/src/components/{GridSheet → SheetContent}/util.ts +3 -3
- package/src/components/{SheetContext/SheetContext.tsx → SheetRoot/SheetRoot.tsx} +44 -36
- package/src/components/{GridSheet → SheetRoot}/index.ts +1 -1
- package/src/components/{FunctionEditor/FunctionEditor.tsx → SheetStatusbar/SheetStatusbar.tsx} +19 -8
- package/src/components/{FunctionEditor → SheetStatusbar}/index.ts +1 -1
- package/src/components/SheetToolbar/SheetToolbar.stories.tsx +4 -4
- package/src/components/SheetToolbar/SheetToolbar.tsx +11 -10
- package/src/components/SheetToolbar/align.ts +9 -9
- package/src/components/SheetToolbar/style.ts +7 -7
- package/src/components/index.ts +1 -7
- package/src/{components → containers}/RangeList/RangeList.tsx +10 -8
- package/src/containers/RangeList/index.ts +7 -0
- package/src/{components → containers}/SheetContainer/SheetContainer.stories.tsx +28 -33
- package/src/containers/SheetContainer/SheetContainer.tsx +57 -0
- package/src/{components → containers}/SheetContainer/index.ts +1 -1
- package/src/containers/index.ts +8 -0
- package/src/extensions/compute.stories.tsx +12 -11
- package/src/extensions/editor/sheet-extension.ts +10 -10
- package/src/integrations/thread-ranges.ts +6 -9
- package/src/meta.ts +1 -1
- package/src/model/sheet-model.ts +36 -34
- package/src/playwright/playwright.config.ts +1 -1
- package/src/playwright/sheet.spec.ts +1 -1
- package/src/translations.ts +1 -0
- package/src/types/Sheet.ts +8 -2
- package/src/types/capabilities.ts +1 -1
- package/src/types/sheet-range-types.ts +3 -3
- package/src/types/types.ts +4 -20
- package/dist/lib/browser/SheetContainer-J72HS2FI.mjs +0 -397
- package/dist/lib/browser/SheetContainer-J72HS2FI.mjs.map +0 -7
- package/dist/lib/browser/anchor-sort-LLO7PZKF.mjs.map +0 -7
- package/dist/lib/browser/chunk-KE3AKN5W.mjs.map +0 -7
- package/dist/lib/browser/chunk-S27QJYTN.mjs.map +0 -7
- package/dist/lib/browser/operation-resolver-YDOW72CN.mjs.map +0 -7
- package/dist/lib/browser/react-surface-JIYVFH42.mjs +0 -51
- package/dist/lib/browser/react-surface-JIYVFH42.mjs.map +0 -7
- package/dist/lib/node-esm/SheetContainer-OGSSDOZU.mjs +0 -398
- package/dist/lib/node-esm/SheetContainer-OGSSDOZU.mjs.map +0 -7
- package/dist/lib/node-esm/anchor-sort-OX5I2YOW.mjs.map +0 -7
- package/dist/lib/node-esm/chunk-6J5L47IB.mjs.map +0 -7
- package/dist/lib/node-esm/chunk-Y4V6HVHO.mjs.map +0 -7
- package/dist/lib/node-esm/operation-resolver-Q63VQBVA.mjs.map +0 -7
- package/dist/lib/node-esm/react-surface-SWRZSZVR.mjs.map +0 -7
- package/dist/types/src/components/FunctionEditor/FunctionEditor.d.ts +0 -3
- package/dist/types/src/components/FunctionEditor/FunctionEditor.d.ts.map +0 -1
- package/dist/types/src/components/FunctionEditor/index.d.ts +0 -2
- package/dist/types/src/components/FunctionEditor/index.d.ts.map +0 -1
- package/dist/types/src/components/GridSheet/GridSheet.d.ts +0 -3
- package/dist/types/src/components/GridSheet/GridSheet.d.ts.map +0 -1
- package/dist/types/src/components/GridSheet/GridSheet.stories.d.ts.map +0 -1
- package/dist/types/src/components/GridSheet/SheetCellEditor.stories.d.ts.map +0 -1
- package/dist/types/src/components/GridSheet/index.d.ts +0 -2
- package/dist/types/src/components/GridSheet/index.d.ts.map +0 -1
- package/dist/types/src/components/GridSheet/util.d.ts.map +0 -1
- package/dist/types/src/components/RangeList/index.d.ts +0 -2
- package/dist/types/src/components/RangeList/index.d.ts.map +0 -1
- package/dist/types/src/components/SheetContainer/SheetContainer.d.ts +0 -10
- package/dist/types/src/components/SheetContainer/SheetContainer.d.ts.map +0 -1
- package/dist/types/src/components/SheetContainer/SheetContainer.stories.d.ts.map +0 -1
- package/dist/types/src/components/SheetContext/SheetContext.d.ts.map +0 -1
- package/dist/types/src/components/SheetContext/index.d.ts +0 -2
- package/dist/types/src/components/SheetContext/index.d.ts.map +0 -1
- package/src/components/SheetContainer/SheetContainer.tsx +0 -48
- package/src/components/SheetContext/index.ts +0 -5
- /package/dist/lib/browser/{compute-graph-registry-RC5L7RE4.mjs.map → compute-graph-registry-HVVALVIE.mjs.map} +0 -0
- /package/dist/lib/browser/{markdown-D2T2DOVX.mjs.map → markdown-I2REDYX5.mjs.map} +0 -0
- /package/dist/lib/node-esm/{compute-graph-registry-ZGXVLVGD.mjs.map → compute-graph-registry-IDU2KKQU.mjs.map} +0 -0
- /package/dist/lib/node-esm/{markdown-PTV72DLO.mjs.map → markdown-6KBH3MBO.mjs.map} +0 -0
- /package/dist/types/src/components/{GridSheet → SheetContent}/SheetCellEditor.stories.d.ts +0 -0
- /package/dist/types/src/components/{GridSheet → SheetContent}/util.d.ts +0 -0
- /package/dist/types/src/{components → containers}/RangeList/RangeList.d.ts +0 -0
- /package/dist/types/src/{components → containers}/SheetContainer/index.d.ts +0 -0
|
@@ -2,7 +2,7 @@ import { createRequire } from 'node:module';const require = createRequire(import
|
|
|
2
2
|
import {
|
|
3
3
|
rangeExtension,
|
|
4
4
|
sheetExtension
|
|
5
|
-
} from "./chunk-
|
|
5
|
+
} from "./chunk-M52YLLWU.mjs";
|
|
6
6
|
import {
|
|
7
7
|
DEFAULT_COLS,
|
|
8
8
|
DEFAULT_ROWS,
|
|
@@ -10,17 +10,22 @@ import {
|
|
|
10
10
|
MAX_ROWS,
|
|
11
11
|
ReadonlyException,
|
|
12
12
|
SheetOperation,
|
|
13
|
-
Sheet_exports,
|
|
14
13
|
addressFromIndex,
|
|
15
14
|
addressToIndex,
|
|
15
|
+
alignKey,
|
|
16
16
|
cellClassNameForRange,
|
|
17
17
|
initialize,
|
|
18
18
|
insertIndices,
|
|
19
19
|
mapFormulaIndicesToRefs,
|
|
20
20
|
mapFormulaRefsToIndices,
|
|
21
21
|
meta,
|
|
22
|
-
rangeFromIndex
|
|
23
|
-
|
|
22
|
+
rangeFromIndex,
|
|
23
|
+
rangeToIndex
|
|
24
|
+
} from "./chunk-VGXC77GH.mjs";
|
|
25
|
+
|
|
26
|
+
// src/containers/SheetContainer/SheetContainer.tsx
|
|
27
|
+
import React6 from "react";
|
|
28
|
+
import { Panel } from "@dxos/react-ui";
|
|
24
29
|
|
|
25
30
|
// src/components/ComputeGraph/ComputeGraphContextProvider.tsx
|
|
26
31
|
import React, { createContext, useContext } from "react";
|
|
@@ -49,72 +54,27 @@ var useComputeGraph = (space) => {
|
|
|
49
54
|
return graph;
|
|
50
55
|
};
|
|
51
56
|
|
|
52
|
-
// src/components/
|
|
53
|
-
import
|
|
54
|
-
import
|
|
57
|
+
// src/components/SheetContent/SheetContent.tsx
|
|
58
|
+
import React3, { forwardRef, useCallback as useCallback3, useMemo as useMemo2, useRef, useState as useState4 } from "react";
|
|
59
|
+
import { useOperationInvoker as useOperationInvoker2 } from "@dxos/app-framework/ui";
|
|
55
60
|
import { rangeToA1Notation } from "@dxos/compute";
|
|
56
|
-
import { Obj } from "@dxos/echo";
|
|
57
|
-
import { Callout, useTranslation } from "@dxos/react-ui";
|
|
58
|
-
import { List } from "@dxos/react-ui-list";
|
|
59
|
-
import { ghostHover } from "@dxos/ui-theme";
|
|
60
|
-
var RangeList = ({ sheet }) => {
|
|
61
|
-
const { t } = useTranslation(meta.id);
|
|
62
|
-
const handleSelectRange = (range) => {
|
|
63
|
-
};
|
|
64
|
-
const handleDeleteRange = useCallback((range) => {
|
|
65
|
-
const index = sheet.ranges.findIndex((sheetRange) => sheetRange === range);
|
|
66
|
-
Obj.change(sheet, (s) => {
|
|
67
|
-
s.ranges.splice(index, 1);
|
|
68
|
-
});
|
|
69
|
-
}, [
|
|
70
|
-
sheet
|
|
71
|
-
]);
|
|
72
|
-
return /* @__PURE__ */ React2.createElement(React2.Fragment, null, /* @__PURE__ */ React2.createElement("h2", {
|
|
73
|
-
className: "mbs-cardSpacingBlock mbe-labelSpacingBlock text-sm font-semibold"
|
|
74
|
-
}, t("range list heading")), sheet.ranges.length < 1 ? /* @__PURE__ */ React2.createElement(Callout.Root, null, /* @__PURE__ */ React2.createElement(Callout.Title, null, t("no ranges message"))) : /* @__PURE__ */ React2.createElement(List.Root, {
|
|
75
|
-
items: sheet.ranges,
|
|
76
|
-
isItem: Schema.is(Sheet_exports.Range)
|
|
77
|
-
}, ({ items: ranges }) => ranges.map((range, i) => /* @__PURE__ */ React2.createElement(List.Item, {
|
|
78
|
-
key: i,
|
|
79
|
-
item: range,
|
|
80
|
-
classNames: [
|
|
81
|
-
"p-2",
|
|
82
|
-
ghostHover
|
|
83
|
-
]
|
|
84
|
-
}, /* @__PURE__ */ React2.createElement(List.ItemDragHandle, null), /* @__PURE__ */ React2.createElement(List.ItemTitle, {
|
|
85
|
-
onClick: () => handleSelectRange(range)
|
|
86
|
-
}, t("range title", {
|
|
87
|
-
position: rangeToA1Notation(rangeFromIndex(sheet, range.range)),
|
|
88
|
-
key: t(`range key ${range.key} label`),
|
|
89
|
-
value: t(`range value ${range.value} label`)
|
|
90
|
-
})), /* @__PURE__ */ React2.createElement(List.ItemDeleteButton, {
|
|
91
|
-
onClick: () => handleDeleteRange(range)
|
|
92
|
-
})))));
|
|
93
|
-
};
|
|
94
|
-
|
|
95
|
-
// src/components/index.ts
|
|
96
|
-
import { lazy } from "react";
|
|
97
|
-
|
|
98
|
-
// src/components/GridSheet/GridSheet.tsx
|
|
99
|
-
import React4, { useCallback as useCallback4, useMemo as useMemo2, useRef, useState as useState4 } from "react";
|
|
100
|
-
import { useOperationInvoker as useOperationInvoker2 } from "@dxos/app-framework/react";
|
|
101
|
-
import { rangeToA1Notation as rangeToA1Notation2 } from "@dxos/compute";
|
|
102
|
-
import { Obj as Obj5 } from "@dxos/echo";
|
|
61
|
+
import { Obj as Obj3 } from "@dxos/echo";
|
|
103
62
|
import { defaultColSize, defaultRowSize } from "@dxos/lit-grid";
|
|
104
|
-
import { DropdownMenu, Icon, useTranslation
|
|
63
|
+
import { DropdownMenu, Icon, useTranslation } from "@dxos/react-ui";
|
|
105
64
|
import { useAttention } from "@dxos/react-ui-attention";
|
|
106
65
|
import { Grid as Grid2, GridCellEditor, closestCell, editorKeys, parseCellIndex } from "@dxos/react-ui-grid";
|
|
66
|
+
import { composableProps } from "@dxos/ui-theme";
|
|
107
67
|
|
|
108
68
|
// src/integrations/thread-ranges.ts
|
|
109
69
|
import * as Effect from "effect/Effect";
|
|
110
|
-
import { useCallback
|
|
111
|
-
import {
|
|
112
|
-
import {
|
|
70
|
+
import { useCallback, useEffect, useMemo } from "react";
|
|
71
|
+
import { useOperationInvoker, useOperationResolver } from "@dxos/app-framework/ui";
|
|
72
|
+
import { COMPANION_PREFIX, LayoutOperation } from "@dxos/app-toolkit";
|
|
113
73
|
import { debounce } from "@dxos/async";
|
|
114
74
|
import { inRange } from "@dxos/compute";
|
|
115
|
-
import { Obj
|
|
75
|
+
import { Obj, Relation } from "@dxos/echo";
|
|
116
76
|
import { OperationResolver } from "@dxos/operation";
|
|
117
|
-
import {
|
|
77
|
+
import { DeckOperation } from "@dxos/plugin-deck/types";
|
|
118
78
|
import { ThreadOperation } from "@dxos/plugin-thread/types";
|
|
119
79
|
import { Filter, Query, useQuery } from "@dxos/react-client/echo";
|
|
120
80
|
import { AnchoredTo, Thread } from "@dxos/types";
|
|
@@ -137,10 +97,9 @@ var parseThreadAnchorAsCellRange = (cursor) => {
|
|
|
137
97
|
}
|
|
138
98
|
};
|
|
139
99
|
var useUpdateFocusedCellOnThreadSelection = (grid) => {
|
|
140
|
-
const { model, setActiveRefs } = useSheetContext();
|
|
141
|
-
const sheetId = Obj2.getDXN(model.sheet).toString();
|
|
100
|
+
const { attendableId: sheetId, model, setActiveRefs } = useSheetContext();
|
|
142
101
|
const scrollIntoViewHandler = useMemo(() => OperationResolver.make({
|
|
143
|
-
operation:
|
|
102
|
+
operation: LayoutOperation.ScrollIntoView,
|
|
144
103
|
position: "hoist",
|
|
145
104
|
filter: (input) => input.subject === sheetId && !!input.cursor,
|
|
146
105
|
handler: (input) => Effect.sync(() => {
|
|
@@ -164,15 +123,15 @@ var useUpdateFocusedCellOnThreadSelection = (grid) => {
|
|
|
164
123
|
var useSelectThreadOnCellFocus = () => {
|
|
165
124
|
const { model, cursor } = useSheetContext();
|
|
166
125
|
const { invokePromise } = useOperationInvoker();
|
|
167
|
-
const db =
|
|
126
|
+
const db = Obj.getDatabase(model.sheet);
|
|
168
127
|
const anchors = useQuery(db, Query.select(Filter.id(model.sheet.id)).targetOf(AnchoredTo.AnchoredTo));
|
|
169
|
-
const selectClosestThread =
|
|
128
|
+
const selectClosestThread = useCallback((cellAddress) => {
|
|
170
129
|
if (!cellAddress) {
|
|
171
130
|
return;
|
|
172
131
|
}
|
|
173
132
|
const closestThread = anchors.find((anchor) => {
|
|
174
133
|
const source = Relation.getSource(anchor);
|
|
175
|
-
if (anchor.anchor &&
|
|
134
|
+
if (anchor.anchor && Obj.instanceOf(Thread.Thread, source)) {
|
|
176
135
|
const range = parseThreadAnchorAsCellRange(anchor.anchor);
|
|
177
136
|
return range ? inRange(range, cellAddress) : false;
|
|
178
137
|
} else {
|
|
@@ -180,14 +139,12 @@ var useSelectThreadOnCellFocus = () => {
|
|
|
180
139
|
}
|
|
181
140
|
});
|
|
182
141
|
if (closestThread) {
|
|
183
|
-
const primary = Obj2.getDXN(model.sheet).toString();
|
|
184
142
|
void (async () => {
|
|
185
143
|
await invokePromise(ThreadOperation.Select, {
|
|
186
144
|
current: Relation.getDXN(closestThread).toString()
|
|
187
145
|
});
|
|
188
146
|
await invokePromise(DeckOperation.ChangeCompanion, {
|
|
189
|
-
|
|
190
|
-
companion: `${primary}${ATTENDABLE_PATH_SEPARATOR}comments`
|
|
147
|
+
companion: `${COMPANION_PREFIX}comments`
|
|
191
148
|
});
|
|
192
149
|
})();
|
|
193
150
|
}
|
|
@@ -211,17 +168,16 @@ var useSelectThreadOnCellFocus = () => {
|
|
|
211
168
|
]);
|
|
212
169
|
};
|
|
213
170
|
|
|
214
|
-
// src/components/
|
|
215
|
-
import
|
|
216
|
-
import {
|
|
217
|
-
import { invariant as invariant2 } from "@dxos/invariant";
|
|
171
|
+
// src/components/SheetRoot/SheetRoot.tsx
|
|
172
|
+
import React2, { createContext as createContext2, useCallback as useCallback2, useContext as useContext2, useState as useState2 } from "react";
|
|
173
|
+
import { raise as raise2 } from "@dxos/debug";
|
|
218
174
|
import { Grid, useGridContext } from "@dxos/react-ui-grid";
|
|
219
175
|
|
|
220
176
|
// src/model/sheet-model.ts
|
|
221
177
|
import { Event } from "@dxos/async";
|
|
222
178
|
import { DetailedCellError, ExportedCellChange, addressFromA1Notation, addressToA1Notation, createSheetName, isFormula } from "@dxos/compute";
|
|
223
179
|
import { Resource } from "@dxos/context";
|
|
224
|
-
import { Obj as
|
|
180
|
+
import { Obj as Obj2 } from "@dxos/echo";
|
|
225
181
|
import { Format, TypeEnum } from "@dxos/echo/internal";
|
|
226
182
|
import { invariant } from "@dxos/invariant";
|
|
227
183
|
import { PublicKey } from "@dxos/keys";
|
|
@@ -309,8 +265,8 @@ var SheetModel = class extends Resource {
|
|
|
309
265
|
S: this,
|
|
310
266
|
C: (f, a) => f(...a)
|
|
311
267
|
});
|
|
312
|
-
|
|
313
|
-
initialize(
|
|
268
|
+
Obj2.change(this._sheet, (obj) => {
|
|
269
|
+
initialize(obj);
|
|
314
270
|
});
|
|
315
271
|
this._graph.update.on((event) => {
|
|
316
272
|
if (event.type === "functionsUpdated") {
|
|
@@ -318,7 +274,7 @@ var SheetModel = class extends Resource {
|
|
|
318
274
|
}
|
|
319
275
|
});
|
|
320
276
|
this._node = this._graph.getOrCreateNode(createSheetName({
|
|
321
|
-
type:
|
|
277
|
+
type: Obj2.getTypename(this._sheet),
|
|
322
278
|
id: this._sheet.id
|
|
323
279
|
}));
|
|
324
280
|
await this._node.open();
|
|
@@ -380,16 +336,16 @@ var SheetModel = class extends Resource {
|
|
|
380
336
|
}
|
|
381
337
|
insertRows(i, n = 1) {
|
|
382
338
|
let idx = [];
|
|
383
|
-
|
|
384
|
-
idx = insertIndices(
|
|
339
|
+
Obj2.change(this._sheet, (obj) => {
|
|
340
|
+
idx = insertIndices(obj.rows, i, n, MAX_ROWS);
|
|
385
341
|
});
|
|
386
342
|
this.reset();
|
|
387
343
|
return idx;
|
|
388
344
|
}
|
|
389
345
|
insertColumns(i, n = 1) {
|
|
390
346
|
let idx = [];
|
|
391
|
-
|
|
392
|
-
idx = insertIndices(
|
|
347
|
+
Obj2.change(this._sheet, (obj) => {
|
|
348
|
+
idx = insertIndices(obj.columns, i, n, MAX_COLS);
|
|
393
349
|
});
|
|
394
350
|
this.reset();
|
|
395
351
|
return idx;
|
|
@@ -402,9 +358,9 @@ var SheetModel = class extends Resource {
|
|
|
402
358
|
const values = this.getCellValues(range).flat();
|
|
403
359
|
const index = this._sheet.rows.indexOf(rowIndex);
|
|
404
360
|
this.clear(range);
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
delete
|
|
361
|
+
Obj2.change(this._sheet, (obj) => {
|
|
362
|
+
obj.rows.splice(index, 1);
|
|
363
|
+
delete obj.rowMeta[rowIndex];
|
|
408
364
|
});
|
|
409
365
|
this.reset();
|
|
410
366
|
return {
|
|
@@ -423,9 +379,9 @@ var SheetModel = class extends Resource {
|
|
|
423
379
|
const values = this.getCellValues(range).flat();
|
|
424
380
|
const index = this._sheet.columns.indexOf(colIndex);
|
|
425
381
|
this.clear(range);
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
delete
|
|
382
|
+
Obj2.change(this._sheet, (obj) => {
|
|
383
|
+
obj.columns.splice(index, 1);
|
|
384
|
+
delete obj.columnMeta[colIndex];
|
|
429
385
|
});
|
|
430
386
|
this.reset();
|
|
431
387
|
return {
|
|
@@ -437,33 +393,33 @@ var SheetModel = class extends Resource {
|
|
|
437
393
|
};
|
|
438
394
|
}
|
|
439
395
|
restoreRow({ index, axisIndex, axisMeta, values }) {
|
|
440
|
-
|
|
441
|
-
|
|
396
|
+
Obj2.change(this._sheet, (obj) => {
|
|
397
|
+
obj.rows.splice(index, 0, axisIndex);
|
|
442
398
|
values.forEach((value, col) => {
|
|
443
399
|
if (value) {
|
|
444
|
-
|
|
400
|
+
obj.cells[`${obj.columns[col]}@${axisIndex}`] = {
|
|
445
401
|
value
|
|
446
402
|
};
|
|
447
403
|
}
|
|
448
404
|
});
|
|
449
405
|
if (axisMeta) {
|
|
450
|
-
|
|
406
|
+
obj.rowMeta[axisIndex] = axisMeta;
|
|
451
407
|
}
|
|
452
408
|
});
|
|
453
409
|
this.reset();
|
|
454
410
|
}
|
|
455
411
|
restoreColumn({ index, axisIndex, axisMeta, values }) {
|
|
456
|
-
|
|
457
|
-
|
|
412
|
+
Obj2.change(this._sheet, (obj) => {
|
|
413
|
+
obj.columns.splice(index, 0, axisIndex);
|
|
458
414
|
values.forEach((value, row) => {
|
|
459
415
|
if (value) {
|
|
460
|
-
|
|
416
|
+
obj.cells[`${axisIndex}@${obj.rows[row]}`] = {
|
|
461
417
|
value
|
|
462
418
|
};
|
|
463
419
|
}
|
|
464
420
|
});
|
|
465
421
|
if (axisMeta) {
|
|
466
|
-
|
|
422
|
+
obj.columnMeta[axisIndex] = axisMeta;
|
|
467
423
|
}
|
|
468
424
|
});
|
|
469
425
|
this.reset();
|
|
@@ -478,7 +434,7 @@ var SheetModel = class extends Resource {
|
|
|
478
434
|
clear(range) {
|
|
479
435
|
invariant(this._node, void 0, {
|
|
480
436
|
F: __dxlog_file,
|
|
481
|
-
L:
|
|
437
|
+
L: 276,
|
|
482
438
|
S: this,
|
|
483
439
|
A: [
|
|
484
440
|
"this._node",
|
|
@@ -488,17 +444,17 @@ var SheetModel = class extends Resource {
|
|
|
488
444
|
const topLeft = getTopLeft(range);
|
|
489
445
|
const values = this._iterRange(range, () => null);
|
|
490
446
|
this._node.graph.hf.setCellContents(toSimpleCellAddress(this._node.sheetId, topLeft), values);
|
|
491
|
-
|
|
447
|
+
Obj2.change(this._sheet, (obj) => {
|
|
492
448
|
this._iterRange(range, (cell) => {
|
|
493
449
|
const idx = addressToIndex(this._sheet, cell);
|
|
494
|
-
delete
|
|
450
|
+
delete obj.cells[idx];
|
|
495
451
|
});
|
|
496
452
|
});
|
|
497
453
|
}
|
|
498
454
|
cut(range) {
|
|
499
455
|
invariant(this._node, void 0, {
|
|
500
456
|
F: __dxlog_file,
|
|
501
|
-
L:
|
|
457
|
+
L: 289,
|
|
502
458
|
S: this,
|
|
503
459
|
A: [
|
|
504
460
|
"this._node",
|
|
@@ -506,17 +462,17 @@ var SheetModel = class extends Resource {
|
|
|
506
462
|
]
|
|
507
463
|
});
|
|
508
464
|
this._node.graph.hf.cut(toModelRange(this._node.sheetId, range));
|
|
509
|
-
|
|
465
|
+
Obj2.change(this._sheet, (obj) => {
|
|
510
466
|
this._iterRange(range, (cell) => {
|
|
511
467
|
const idx = addressToIndex(this._sheet, cell);
|
|
512
|
-
delete
|
|
468
|
+
delete obj.cells[idx];
|
|
513
469
|
});
|
|
514
470
|
});
|
|
515
471
|
}
|
|
516
472
|
copy(range) {
|
|
517
473
|
invariant(this._node, void 0, {
|
|
518
474
|
F: __dxlog_file,
|
|
519
|
-
L:
|
|
475
|
+
L: 300,
|
|
520
476
|
S: this,
|
|
521
477
|
A: [
|
|
522
478
|
"this._node",
|
|
@@ -528,7 +484,7 @@ var SheetModel = class extends Resource {
|
|
|
528
484
|
paste(cell) {
|
|
529
485
|
invariant(this._node, void 0, {
|
|
530
486
|
F: __dxlog_file,
|
|
531
|
-
L:
|
|
487
|
+
L: 305,
|
|
532
488
|
S: this,
|
|
533
489
|
A: [
|
|
534
490
|
"this._node",
|
|
@@ -537,7 +493,7 @@ var SheetModel = class extends Resource {
|
|
|
537
493
|
});
|
|
538
494
|
if (!this._node.graph.hf.isClipboardEmpty()) {
|
|
539
495
|
const changes = this._node.graph.hf.paste(toSimpleCellAddress(this._node.sheetId, cell));
|
|
540
|
-
|
|
496
|
+
Obj2.change(this._sheet, (obj) => {
|
|
541
497
|
for (const change of changes) {
|
|
542
498
|
if (change instanceof ExportedCellChange) {
|
|
543
499
|
const { address, newValue } = change;
|
|
@@ -545,7 +501,7 @@ var SheetModel = class extends Resource {
|
|
|
545
501
|
row: address.row,
|
|
546
502
|
col: address.col
|
|
547
503
|
});
|
|
548
|
-
|
|
504
|
+
obj.cells[idx] = {
|
|
549
505
|
value: newValue
|
|
550
506
|
};
|
|
551
507
|
}
|
|
@@ -557,7 +513,7 @@ var SheetModel = class extends Resource {
|
|
|
557
513
|
undo() {
|
|
558
514
|
invariant(this._node, void 0, {
|
|
559
515
|
F: __dxlog_file,
|
|
560
|
-
L:
|
|
516
|
+
L: 322,
|
|
561
517
|
S: this,
|
|
562
518
|
A: [
|
|
563
519
|
"this._node",
|
|
@@ -571,7 +527,7 @@ var SheetModel = class extends Resource {
|
|
|
571
527
|
redo() {
|
|
572
528
|
invariant(this._node, void 0, {
|
|
573
529
|
F: __dxlog_file,
|
|
574
|
-
L:
|
|
530
|
+
L: 330,
|
|
575
531
|
S: this,
|
|
576
532
|
A: [
|
|
577
533
|
"this._node",
|
|
@@ -615,7 +571,7 @@ var SheetModel = class extends Resource {
|
|
|
615
571
|
getValue(cell) {
|
|
616
572
|
invariant(this._node, void 0, {
|
|
617
573
|
F: __dxlog_file,
|
|
618
|
-
L:
|
|
574
|
+
L: 373,
|
|
619
575
|
S: this,
|
|
620
576
|
A: [
|
|
621
577
|
"this._node",
|
|
@@ -630,7 +586,7 @@ var SheetModel = class extends Resource {
|
|
|
630
586
|
error: value
|
|
631
587
|
}, {
|
|
632
588
|
F: __dxlog_file,
|
|
633
|
-
L:
|
|
589
|
+
L: 378,
|
|
634
590
|
S: this,
|
|
635
591
|
C: (f, a) => f(...a)
|
|
636
592
|
});
|
|
@@ -644,7 +600,7 @@ var SheetModel = class extends Resource {
|
|
|
644
600
|
getValueDescription(cell) {
|
|
645
601
|
invariant(this._node, void 0, {
|
|
646
602
|
F: __dxlog_file,
|
|
647
|
-
L:
|
|
603
|
+
L: 389,
|
|
648
604
|
S: this,
|
|
649
605
|
A: [
|
|
650
606
|
"this._node",
|
|
@@ -661,7 +617,7 @@ var SheetModel = class extends Resource {
|
|
|
661
617
|
setValue(cell, value) {
|
|
662
618
|
invariant(this._node, void 0, {
|
|
663
619
|
F: __dxlog_file,
|
|
664
|
-
L:
|
|
620
|
+
L: 399,
|
|
665
621
|
S: this,
|
|
666
622
|
A: [
|
|
667
623
|
"this._node",
|
|
@@ -673,14 +629,14 @@ var SheetModel = class extends Resource {
|
|
|
673
629
|
}
|
|
674
630
|
let refresh = false;
|
|
675
631
|
if (cell.row >= this._sheet.rows.length) {
|
|
676
|
-
|
|
677
|
-
insertIndices(
|
|
632
|
+
Obj2.change(this._sheet, (obj) => {
|
|
633
|
+
insertIndices(obj.rows, cell.row, 1, MAX_ROWS);
|
|
678
634
|
});
|
|
679
635
|
refresh = true;
|
|
680
636
|
}
|
|
681
637
|
if (cell.col >= this._sheet.columns.length) {
|
|
682
|
-
|
|
683
|
-
insertIndices(
|
|
638
|
+
Obj2.change(this._sheet, (obj) => {
|
|
639
|
+
insertIndices(obj.columns, cell.col, 1, MAX_COLS);
|
|
684
640
|
});
|
|
685
641
|
refresh = true;
|
|
686
642
|
}
|
|
@@ -698,15 +654,15 @@ var SheetModel = class extends Resource {
|
|
|
698
654
|
]);
|
|
699
655
|
const idx = addressToIndex(this._sheet, cell);
|
|
700
656
|
if (value === void 0 || value === null) {
|
|
701
|
-
|
|
702
|
-
delete
|
|
657
|
+
Obj2.change(this._sheet, (obj) => {
|
|
658
|
+
delete obj.cells[idx];
|
|
703
659
|
});
|
|
704
660
|
} else {
|
|
705
661
|
if (isFormula(value)) {
|
|
706
662
|
value = this._graph.mapFunctionBindingToId(mapFormulaRefsToIndices(this._sheet, value));
|
|
707
663
|
}
|
|
708
|
-
|
|
709
|
-
|
|
664
|
+
Obj2.change(this._sheet, (obj) => {
|
|
665
|
+
obj.cells[idx] = {
|
|
710
666
|
value
|
|
711
667
|
};
|
|
712
668
|
});
|
|
@@ -763,7 +719,7 @@ var SheetModel = class extends Resource {
|
|
|
763
719
|
mapFormulaIndicesToRefs(formula) {
|
|
764
720
|
invariant(isFormula(formula), void 0, {
|
|
765
721
|
F: __dxlog_file,
|
|
766
|
-
L:
|
|
722
|
+
L: 492,
|
|
767
723
|
S: this,
|
|
768
724
|
A: [
|
|
769
725
|
"isFormula(formula)",
|
|
@@ -789,7 +745,7 @@ var SheetModel = class extends Resource {
|
|
|
789
745
|
toDateTime(num) {
|
|
790
746
|
invariant(this._node, void 0, {
|
|
791
747
|
F: __dxlog_file,
|
|
792
|
-
L:
|
|
748
|
+
L: 513,
|
|
793
749
|
S: this,
|
|
794
750
|
A: [
|
|
795
751
|
"this._node",
|
|
@@ -801,7 +757,7 @@ var SheetModel = class extends Resource {
|
|
|
801
757
|
toDate(num) {
|
|
802
758
|
invariant(this._node, void 0, {
|
|
803
759
|
F: __dxlog_file,
|
|
804
|
-
L:
|
|
760
|
+
L: 518,
|
|
805
761
|
S: this,
|
|
806
762
|
A: [
|
|
807
763
|
"this._node",
|
|
@@ -813,7 +769,7 @@ var SheetModel = class extends Resource {
|
|
|
813
769
|
toTime(num) {
|
|
814
770
|
invariant(this._node, void 0, {
|
|
815
771
|
F: __dxlog_file,
|
|
816
|
-
L:
|
|
772
|
+
L: 523,
|
|
817
773
|
S: this,
|
|
818
774
|
A: [
|
|
819
775
|
"this._node",
|
|
@@ -852,29 +808,34 @@ var useSheetModel = (graph, sheet, { readonly } = {}) => {
|
|
|
852
808
|
return model;
|
|
853
809
|
};
|
|
854
810
|
|
|
855
|
-
// src/components/
|
|
856
|
-
var __dxlog_file2 = "/__w/dxos/dxos/packages/plugins/plugin-sheet/src/components/SheetContext/SheetContext.tsx";
|
|
811
|
+
// src/components/SheetRoot/SheetRoot.tsx
|
|
857
812
|
var SheetContext = /* @__PURE__ */ createContext2(void 0);
|
|
858
813
|
var useSheetContext = () => {
|
|
859
|
-
|
|
860
|
-
|
|
861
|
-
|
|
862
|
-
|
|
863
|
-
|
|
864
|
-
A: [
|
|
865
|
-
"context",
|
|
866
|
-
""
|
|
867
|
-
]
|
|
814
|
+
return useContext2(SheetContext) ?? raise2(new Error("Missing SheetContext"));
|
|
815
|
+
};
|
|
816
|
+
var SheetRoot = ({ children, graph, sheet, attendableId, readonly, ignoreAttention, onInfo }) => {
|
|
817
|
+
const model = useSheetModel(graph, sheet, {
|
|
818
|
+
readonly
|
|
868
819
|
});
|
|
869
|
-
|
|
820
|
+
if (!model) {
|
|
821
|
+
return null;
|
|
822
|
+
}
|
|
823
|
+
return /* @__PURE__ */ React2.createElement(Grid.Root, {
|
|
824
|
+
id: attendableId
|
|
825
|
+
}, /* @__PURE__ */ React2.createElement(SheetProviderImpl, {
|
|
826
|
+
model,
|
|
827
|
+
attendableId,
|
|
828
|
+
onInfo,
|
|
829
|
+
ignoreAttention
|
|
830
|
+
}, children));
|
|
870
831
|
};
|
|
871
|
-
var SheetProviderImpl = ({ __gridScope, children, ignoreAttention, model, onInfo }) => {
|
|
832
|
+
var SheetProviderImpl = ({ __gridScope, children, attendableId, ignoreAttention, model, onInfo }) => {
|
|
872
833
|
const { id, editing, setEditing } = useGridContext("SheetProvider", __gridScope);
|
|
873
834
|
const [cursor, setCursorInternal] = useState2();
|
|
874
835
|
const [range, setRangeInternal] = useState2();
|
|
875
836
|
const [cursorFallbackRange, setCursorFallbackRange] = useState2();
|
|
876
837
|
const [activeRefs, setActiveRefs] = useState2("");
|
|
877
|
-
const setCursor =
|
|
838
|
+
const setCursor = useCallback2((nextCursor) => {
|
|
878
839
|
setCursorInternal(nextCursor);
|
|
879
840
|
setCursorFallbackRange(range?.to ? range : nextCursor ? {
|
|
880
841
|
from: nextCursor,
|
|
@@ -883,7 +844,7 @@ var SheetProviderImpl = ({ __gridScope, children, ignoreAttention, model, onInfo
|
|
|
883
844
|
}, [
|
|
884
845
|
range
|
|
885
846
|
]);
|
|
886
|
-
const setRange =
|
|
847
|
+
const setRange = useCallback2((nextRange) => {
|
|
887
848
|
setRangeInternal(nextRange);
|
|
888
849
|
setCursorFallbackRange(nextRange?.to ? nextRange : cursor ? {
|
|
889
850
|
from: cursor,
|
|
@@ -892,9 +853,10 @@ var SheetProviderImpl = ({ __gridScope, children, ignoreAttention, model, onInfo
|
|
|
892
853
|
}, [
|
|
893
854
|
cursor
|
|
894
855
|
]);
|
|
895
|
-
return /* @__PURE__ */
|
|
856
|
+
return /* @__PURE__ */ React2.createElement(SheetContext.Provider, {
|
|
896
857
|
value: {
|
|
897
858
|
id,
|
|
859
|
+
attendableId,
|
|
898
860
|
model,
|
|
899
861
|
editing,
|
|
900
862
|
setEditing,
|
|
@@ -905,26 +867,14 @@ var SheetProviderImpl = ({ __gridScope, children, ignoreAttention, model, onInfo
|
|
|
905
867
|
cursorFallbackRange,
|
|
906
868
|
activeRefs,
|
|
907
869
|
setActiveRefs,
|
|
870
|
+
ignoreAttention,
|
|
908
871
|
// TODO(burdon): Change to event.
|
|
909
|
-
onInfo
|
|
910
|
-
ignoreAttention
|
|
872
|
+
onInfo
|
|
911
873
|
}
|
|
912
874
|
}, children);
|
|
913
875
|
};
|
|
914
|
-
var SheetProvider = ({ children, graph, sheet, readonly, ignoreAttention, onInfo }) => {
|
|
915
|
-
const model = useSheetModel(graph, sheet, {
|
|
916
|
-
readonly
|
|
917
|
-
});
|
|
918
|
-
return !model ? null : /* @__PURE__ */ React3.createElement(Grid.Root, {
|
|
919
|
-
id: Obj4.getDXN(sheet).toString()
|
|
920
|
-
}, /* @__PURE__ */ React3.createElement(SheetProviderImpl, {
|
|
921
|
-
model,
|
|
922
|
-
onInfo,
|
|
923
|
-
ignoreAttention
|
|
924
|
-
}, children));
|
|
925
|
-
};
|
|
926
876
|
|
|
927
|
-
// src/components/
|
|
877
|
+
// src/components/SheetContent/util.ts
|
|
928
878
|
import { useEffect as useEffect3, useState as useState3 } from "react";
|
|
929
879
|
import { inRange as inRange2 } from "@dxos/compute";
|
|
930
880
|
import { createDocAccessor } from "@dxos/echo-db";
|
|
@@ -1001,12 +951,12 @@ var gridCellGetter = (model) => {
|
|
|
1001
951
|
};
|
|
1002
952
|
var rowLabelCell = (row) => ({
|
|
1003
953
|
value: rowToA1Notation(row),
|
|
1004
|
-
className: "!bg-
|
|
954
|
+
className: "!bg-toolbar-surface text-subdued text-end pe-1",
|
|
1005
955
|
resizeHandle: "row"
|
|
1006
956
|
});
|
|
1007
957
|
var colLabelCell = (col) => ({
|
|
1008
958
|
value: colToA1Notation(col),
|
|
1009
|
-
className: "!bg-
|
|
959
|
+
className: "!bg-toolbar-surface text-subdued",
|
|
1010
960
|
resizeHandle: "col"
|
|
1011
961
|
});
|
|
1012
962
|
var cellGetter = (model) => {
|
|
@@ -1018,7 +968,7 @@ var cellGetter = (model) => {
|
|
|
1018
968
|
case "fixedStartStart": {
|
|
1019
969
|
return {
|
|
1020
970
|
"0,0": {
|
|
1021
|
-
className: "!bg-
|
|
971
|
+
className: "!bg-toolbar-surface"
|
|
1022
972
|
}
|
|
1023
973
|
};
|
|
1024
974
|
}
|
|
@@ -1095,7 +1045,7 @@ var useSheetModelDxGridProps = (dxGrid, model) => {
|
|
|
1095
1045
|
};
|
|
1096
1046
|
};
|
|
1097
1047
|
|
|
1098
|
-
// src/components/
|
|
1048
|
+
// src/components/SheetContent/SheetContent.tsx
|
|
1099
1049
|
var inertPosition = {
|
|
1100
1050
|
plane: "grid",
|
|
1101
1051
|
col: 0,
|
|
@@ -1142,15 +1092,15 @@ var sheetRowDefault = {
|
|
|
1142
1092
|
resizeable: true
|
|
1143
1093
|
}
|
|
1144
1094
|
};
|
|
1145
|
-
var
|
|
1146
|
-
const { t } =
|
|
1095
|
+
var SheetContent = /* @__PURE__ */ forwardRef((props, forwardedRef) => {
|
|
1096
|
+
const { t } = useTranslation(meta.id);
|
|
1147
1097
|
const { id, model, editing, setCursor, setRange, cursor, cursorFallbackRange, activeRefs, ignoreAttention } = useSheetContext();
|
|
1148
1098
|
const [dxGrid, setDxGrid] = useState4(null);
|
|
1149
1099
|
const [extraplanarFocus, setExtraplanarFocus] = useState4(null);
|
|
1150
1100
|
const { invokePromise } = useOperationInvoker2();
|
|
1151
1101
|
const rangeController = useRef(null);
|
|
1152
1102
|
const { hasAttention } = useAttention(id);
|
|
1153
|
-
const handleFocus =
|
|
1103
|
+
const handleFocus = useCallback3((event) => {
|
|
1154
1104
|
if (!editing) {
|
|
1155
1105
|
const cell = closestCell(event.target);
|
|
1156
1106
|
if (cell) {
|
|
@@ -1170,7 +1120,7 @@ var GridSheet = () => {
|
|
|
1170
1120
|
}, [
|
|
1171
1121
|
editing
|
|
1172
1122
|
]);
|
|
1173
|
-
const handleClose =
|
|
1123
|
+
const handleClose = useCallback3((_value, event) => {
|
|
1174
1124
|
if (event) {
|
|
1175
1125
|
const { key, shift } = event;
|
|
1176
1126
|
const axis = [
|
|
@@ -1193,7 +1143,7 @@ var GridSheet = () => {
|
|
|
1193
1143
|
editing,
|
|
1194
1144
|
dxGrid
|
|
1195
1145
|
]);
|
|
1196
|
-
const handleBlur =
|
|
1146
|
+
const handleBlur = useCallback3((value) => {
|
|
1197
1147
|
if (value !== void 0) {
|
|
1198
1148
|
model.setValue(parseCellIndex(editing.index), value);
|
|
1199
1149
|
}
|
|
@@ -1201,8 +1151,8 @@ var GridSheet = () => {
|
|
|
1201
1151
|
model,
|
|
1202
1152
|
editing
|
|
1203
1153
|
]);
|
|
1204
|
-
const handleAxisResize =
|
|
1205
|
-
|
|
1154
|
+
const handleAxisResize = useCallback3(({ axis, size, index: numericIndex }) => {
|
|
1155
|
+
Obj3.change(model.sheet, (sheet) => {
|
|
1206
1156
|
if (axis === "row") {
|
|
1207
1157
|
const rowId = sheet.rows[parseInt(numericIndex)];
|
|
1208
1158
|
sheet.rowMeta[rowId] ??= {};
|
|
@@ -1216,7 +1166,7 @@ var GridSheet = () => {
|
|
|
1216
1166
|
}, [
|
|
1217
1167
|
model
|
|
1218
1168
|
]);
|
|
1219
|
-
const handleSelect =
|
|
1169
|
+
const handleSelect = useCallback3(({ minCol, maxCol, minRow, maxRow }) => {
|
|
1220
1170
|
const range = {
|
|
1221
1171
|
from: {
|
|
1222
1172
|
col: minCol,
|
|
@@ -1230,14 +1180,14 @@ var GridSheet = () => {
|
|
|
1230
1180
|
};
|
|
1231
1181
|
}
|
|
1232
1182
|
if (editing) {
|
|
1233
|
-
rangeController.current?.setRange(
|
|
1183
|
+
rangeController.current?.setRange(rangeToA1Notation(range));
|
|
1234
1184
|
} else {
|
|
1235
1185
|
setRange(range.to ? range : void 0);
|
|
1236
1186
|
}
|
|
1237
1187
|
}, [
|
|
1238
1188
|
editing
|
|
1239
1189
|
]);
|
|
1240
|
-
const handleWheel =
|
|
1190
|
+
const handleWheel = useCallback3((event) => {
|
|
1241
1191
|
if (!ignoreAttention && !hasAttention) {
|
|
1242
1192
|
event.stopPropagation();
|
|
1243
1193
|
}
|
|
@@ -1245,7 +1195,7 @@ var GridSheet = () => {
|
|
|
1245
1195
|
hasAttention,
|
|
1246
1196
|
ignoreAttention
|
|
1247
1197
|
]);
|
|
1248
|
-
const selectEntireAxis =
|
|
1198
|
+
const selectEntireAxis = useCallback3((pos) => {
|
|
1249
1199
|
switch (pos.plane) {
|
|
1250
1200
|
case "frozenRowsStart":
|
|
1251
1201
|
return dxGrid?.setSelection({
|
|
@@ -1278,7 +1228,7 @@ var GridSheet = () => {
|
|
|
1278
1228
|
dxGrid,
|
|
1279
1229
|
model.sheet
|
|
1280
1230
|
]);
|
|
1281
|
-
const handleClick =
|
|
1231
|
+
const handleClick = useCallback3((event) => {
|
|
1282
1232
|
const cell = closestCell(event.target);
|
|
1283
1233
|
if (cell) {
|
|
1284
1234
|
selectEntireAxis(cell);
|
|
@@ -1286,7 +1236,7 @@ var GridSheet = () => {
|
|
|
1286
1236
|
}, [
|
|
1287
1237
|
selectEntireAxis
|
|
1288
1238
|
]);
|
|
1289
|
-
const handleKeyDown =
|
|
1239
|
+
const handleKeyDown = useCallback3((event) => {
|
|
1290
1240
|
switch (event.key) {
|
|
1291
1241
|
case "Backspace":
|
|
1292
1242
|
case "Delete":
|
|
@@ -1336,7 +1286,7 @@ var GridSheet = () => {
|
|
|
1336
1286
|
const contextMenuAnchorRef = useRef(null);
|
|
1337
1287
|
const [contextMenuOpen, setContextMenuOpen] = useState4(null);
|
|
1338
1288
|
const contextMenuAxis = contextMenuOpen?.plane.startsWith("frozenRows") ? "col" : "row";
|
|
1339
|
-
const handleContextMenu =
|
|
1289
|
+
const handleContextMenu = useCallback3((event) => {
|
|
1340
1290
|
const cell = closestCell(event.target);
|
|
1341
1291
|
if (cell && cell.plane.startsWith("frozen")) {
|
|
1342
1292
|
event.preventDefault();
|
|
@@ -1344,7 +1294,7 @@ var GridSheet = () => {
|
|
|
1344
1294
|
setContextMenuOpen(cell);
|
|
1345
1295
|
}
|
|
1346
1296
|
}, []);
|
|
1347
|
-
const handleAxisMenuAction =
|
|
1297
|
+
const handleAxisMenuAction = useCallback3((operation) => {
|
|
1348
1298
|
switch (operation) {
|
|
1349
1299
|
case "insert-before":
|
|
1350
1300
|
case "insert-after":
|
|
@@ -1390,85 +1340,470 @@ var GridSheet = () => {
|
|
|
1390
1340
|
handleClose,
|
|
1391
1341
|
editing
|
|
1392
1342
|
]);
|
|
1393
|
-
const getCellContent =
|
|
1343
|
+
const getCellContent = useCallback3((index) => {
|
|
1394
1344
|
return model.getCellText(parseCellIndex(index));
|
|
1395
1345
|
}, [
|
|
1396
1346
|
model
|
|
1397
1347
|
]);
|
|
1398
1348
|
useUpdateFocusedCellOnThreadSelection(dxGrid);
|
|
1399
1349
|
useSelectThreadOnCellFocus();
|
|
1400
|
-
return (
|
|
1401
|
-
|
|
1402
|
-
|
|
1350
|
+
return /* @__PURE__ */ React3.createElement("div", {
|
|
1351
|
+
ref: forwardedRef,
|
|
1352
|
+
...composableProps(props, {
|
|
1403
1353
|
role: "none",
|
|
1404
|
-
className: "relative min-
|
|
1405
|
-
}
|
|
1406
|
-
|
|
1407
|
-
|
|
1408
|
-
|
|
1409
|
-
|
|
1410
|
-
|
|
1411
|
-
|
|
1412
|
-
|
|
1413
|
-
|
|
1414
|
-
|
|
1415
|
-
|
|
1416
|
-
|
|
1417
|
-
|
|
1418
|
-
|
|
1419
|
-
|
|
1420
|
-
|
|
1421
|
-
|
|
1422
|
-
|
|
1423
|
-
|
|
1424
|
-
|
|
1425
|
-
|
|
1426
|
-
|
|
1427
|
-
|
|
1428
|
-
|
|
1429
|
-
|
|
1430
|
-
|
|
1431
|
-
|
|
1432
|
-
|
|
1433
|
-
|
|
1434
|
-
|
|
1435
|
-
|
|
1436
|
-
|
|
1437
|
-
|
|
1438
|
-
|
|
1439
|
-
|
|
1440
|
-
|
|
1441
|
-
|
|
1442
|
-
|
|
1443
|
-
|
|
1444
|
-
|
|
1445
|
-
|
|
1446
|
-
|
|
1447
|
-
|
|
1448
|
-
|
|
1449
|
-
|
|
1450
|
-
|
|
1451
|
-
|
|
1452
|
-
|
|
1453
|
-
|
|
1454
|
-
|
|
1455
|
-
|
|
1456
|
-
|
|
1457
|
-
|
|
1458
|
-
|
|
1459
|
-
|
|
1354
|
+
className: "relative min-h-0"
|
|
1355
|
+
})
|
|
1356
|
+
}, /* @__PURE__ */ React3.createElement(GridCellEditor, {
|
|
1357
|
+
getCellContent,
|
|
1358
|
+
extensions,
|
|
1359
|
+
onBlur: handleBlur
|
|
1360
|
+
}), /* @__PURE__ */ React3.createElement(Grid2.Content, {
|
|
1361
|
+
className: "[--dx-grid-base:var(--base-surface)] [&_.dx-grid]:absolute [&_.dx-grid]:inset-0",
|
|
1362
|
+
initialCells,
|
|
1363
|
+
limitColumns: DEFAULT_COLS,
|
|
1364
|
+
limitRows: DEFAULT_ROWS,
|
|
1365
|
+
columns,
|
|
1366
|
+
rows,
|
|
1367
|
+
columnDefault: sheetColDefault,
|
|
1368
|
+
rowDefault: sheetRowDefault,
|
|
1369
|
+
activeRefs,
|
|
1370
|
+
frozen,
|
|
1371
|
+
overscroll: "trap",
|
|
1372
|
+
onAxisResize: handleAxisResize,
|
|
1373
|
+
onSelect: handleSelect,
|
|
1374
|
+
onFocus: handleFocus,
|
|
1375
|
+
onWheelCapture: handleWheel,
|
|
1376
|
+
onKeyDown: handleKeyDown,
|
|
1377
|
+
onContextMenu: handleContextMenu,
|
|
1378
|
+
onClick: handleClick,
|
|
1379
|
+
ref: setDxGrid
|
|
1380
|
+
}), /* @__PURE__ */ React3.createElement(DropdownMenu.Root, {
|
|
1381
|
+
modal: false,
|
|
1382
|
+
open: !!contextMenuOpen,
|
|
1383
|
+
onOpenChange: (nextOpen) => setContextMenuOpen(nextOpen ? inertPosition : null)
|
|
1384
|
+
}, /* @__PURE__ */ React3.createElement(DropdownMenu.VirtualTrigger, {
|
|
1385
|
+
virtualRef: contextMenuAnchorRef
|
|
1386
|
+
}), /* @__PURE__ */ React3.createElement(DropdownMenu.Content, {
|
|
1387
|
+
side: contextMenuAxis === "col" ? "bottom" : "right",
|
|
1388
|
+
sideOffset: 4,
|
|
1389
|
+
collisionPadding: 8
|
|
1390
|
+
}, /* @__PURE__ */ React3.createElement(DropdownMenu.Viewport, null, /* @__PURE__ */ React3.createElement(DropdownMenu.Item, {
|
|
1391
|
+
onClick: () => handleAxisMenuAction("insert-before"),
|
|
1392
|
+
"data-testid": `grid.${contextMenuAxis}.insert-before`
|
|
1393
|
+
}, /* @__PURE__ */ React3.createElement(Icon, {
|
|
1394
|
+
size: 5,
|
|
1395
|
+
icon: contextMenuAxis === "col" ? "ph--columns-plus-left--regular" : "ph--rows-plus-top--regular"
|
|
1396
|
+
}), /* @__PURE__ */ React3.createElement("span", null, t(`add ${contextMenuAxis} before label`))), /* @__PURE__ */ React3.createElement(DropdownMenu.Item, {
|
|
1397
|
+
onClick: () => handleAxisMenuAction("insert-after"),
|
|
1398
|
+
"data-testid": `grid.${contextMenuAxis}.insert-after`
|
|
1399
|
+
}, /* @__PURE__ */ React3.createElement(Icon, {
|
|
1400
|
+
size: 5,
|
|
1401
|
+
icon: contextMenuAxis === "col" ? "ph--columns-plus-right--regular" : "ph--rows-plus-bottom--regular"
|
|
1402
|
+
}), /* @__PURE__ */ React3.createElement("span", null, t(`add ${contextMenuAxis} after label`))), /* @__PURE__ */ React3.createElement(DropdownMenu.Item, {
|
|
1403
|
+
onClick: () => handleAxisMenuAction("drop"),
|
|
1404
|
+
"data-testid": `grid.${contextMenuAxis}.drop`
|
|
1405
|
+
}, /* @__PURE__ */ React3.createElement(Icon, {
|
|
1406
|
+
size: 5,
|
|
1407
|
+
icon: "ph--backspace--regular"
|
|
1408
|
+
}), /* @__PURE__ */ React3.createElement("span", null, t(`delete ${contextMenuAxis} label`)))), /* @__PURE__ */ React3.createElement(DropdownMenu.Arrow, null))));
|
|
1409
|
+
});
|
|
1410
|
+
|
|
1411
|
+
// src/components/SheetStatusbar/SheetStatusbar.tsx
|
|
1412
|
+
import React4, { forwardRef as forwardRef2 } from "react";
|
|
1413
|
+
import { addressToA1Notation as addressToA1Notation2, isFormula as isFormula2, rangeToA1Notation as rangeToA1Notation2 } from "@dxos/compute";
|
|
1414
|
+
import { Icon as Icon2 } from "@dxos/react-ui";
|
|
1415
|
+
import { composableProps as composableProps2, mx as mx2 } from "@dxos/ui-theme";
|
|
1416
|
+
var SheetStatusbar = /* @__PURE__ */ forwardRef2((props, forwardedRef) => {
|
|
1417
|
+
const { className, ...rest } = composableProps2(props);
|
|
1418
|
+
const { model, cursor, range } = useSheetContext();
|
|
1419
|
+
let value;
|
|
1420
|
+
let formula = false;
|
|
1421
|
+
if (cursor) {
|
|
1422
|
+
value = model.getCellValue(cursor);
|
|
1423
|
+
if (isFormula2(value)) {
|
|
1424
|
+
value = model.graph.mapFunctionBindingFromId(mapFormulaIndicesToRefs(model.sheet, value));
|
|
1425
|
+
formula = true;
|
|
1426
|
+
} else if (value != null) {
|
|
1427
|
+
value = String(value);
|
|
1428
|
+
}
|
|
1429
|
+
}
|
|
1430
|
+
return /* @__PURE__ */ React4.createElement("div", {
|
|
1431
|
+
ref: forwardedRef,
|
|
1432
|
+
...rest,
|
|
1433
|
+
className: mx2("flex shrink-0 justify-between items-center px-4 py-1 text-sm bg-toolbar-surface border-y !border-subdued-separator", className)
|
|
1434
|
+
}, /* @__PURE__ */ React4.createElement("div", {
|
|
1435
|
+
className: "flex gap-4 items-center"
|
|
1436
|
+
}, /* @__PURE__ */ React4.createElement("div", {
|
|
1437
|
+
className: "flex w-16 items-center font-mono"
|
|
1438
|
+
}, range && rangeToA1Notation2(range) || cursor && addressToA1Notation2(cursor)), /* @__PURE__ */ React4.createElement("div", {
|
|
1439
|
+
className: "flex gap-2 items-center"
|
|
1440
|
+
}, /* @__PURE__ */ React4.createElement(Icon2, {
|
|
1441
|
+
icon: "ph--function--regular",
|
|
1442
|
+
classNames: [
|
|
1443
|
+
"text-green-text",
|
|
1444
|
+
formula ? "visible" : "invisible"
|
|
1445
|
+
]
|
|
1446
|
+
}), /* @__PURE__ */ React4.createElement("span", {
|
|
1447
|
+
className: "font-mono"
|
|
1448
|
+
}, value))));
|
|
1449
|
+
});
|
|
1450
|
+
|
|
1451
|
+
// src/components/SheetToolbar/SheetToolbar.tsx
|
|
1452
|
+
import { Atom as Atom2, RegistryContext as RegistryContext4 } from "@effect-atom/atom-react";
|
|
1453
|
+
import React5, { useContext as useContext6, useMemo as useMemo4 } from "react";
|
|
1454
|
+
import { useAppGraph } from "@dxos/app-toolkit/ui";
|
|
1455
|
+
import { Menu, createGapSeparator, useMenuActions } from "@dxos/react-ui-menu";
|
|
1456
|
+
|
|
1457
|
+
// src/components/SheetToolbar/align.ts
|
|
1458
|
+
import { RegistryContext } from "@effect-atom/atom-react";
|
|
1459
|
+
import { useContext as useContext3, useEffect as useEffect4 } from "react";
|
|
1460
|
+
import { inRange as inRange3 } from "@dxos/compute";
|
|
1461
|
+
import { Obj as Obj4 } from "@dxos/echo";
|
|
1462
|
+
import { createMenuAction, createMenuItemGroup } from "@dxos/react-ui-menu";
|
|
1463
|
+
var aligns = {
|
|
1464
|
+
start: "ph--text-align-left--regular",
|
|
1465
|
+
center: "ph--text-align-center--regular",
|
|
1466
|
+
end: "ph--text-align-right--regular"
|
|
1467
|
+
};
|
|
1468
|
+
var useAlignState = (stateAtom) => {
|
|
1469
|
+
const registry = useContext3(RegistryContext);
|
|
1470
|
+
const { cursor, model } = useSheetContext();
|
|
1471
|
+
useEffect4(() => {
|
|
1472
|
+
const alignValue = cursor ? model.sheet.ranges?.findLast(({ range, key }) => key === alignKey && inRange3(rangeFromIndex(model.sheet, range), cursor))?.value : void 0;
|
|
1473
|
+
const prev = registry.get(stateAtom);
|
|
1474
|
+
registry.set(stateAtom, {
|
|
1475
|
+
...prev,
|
|
1476
|
+
[alignKey]: alignValue
|
|
1477
|
+
});
|
|
1478
|
+
}, [
|
|
1479
|
+
cursor,
|
|
1480
|
+
model.sheet,
|
|
1481
|
+
registry,
|
|
1482
|
+
stateAtom
|
|
1483
|
+
]);
|
|
1484
|
+
};
|
|
1485
|
+
var createAlignGroupAction = (value) => createMenuItemGroup("align", {
|
|
1486
|
+
label: [
|
|
1487
|
+
"align label",
|
|
1488
|
+
{
|
|
1489
|
+
ns: meta.id
|
|
1490
|
+
}
|
|
1491
|
+
],
|
|
1492
|
+
variant: "toggleGroup",
|
|
1493
|
+
selectCardinality: "single",
|
|
1494
|
+
value: `${alignKey}--${value}`
|
|
1495
|
+
});
|
|
1496
|
+
var createAlignActions = ({ model, state, stateAtom, registry, cursorFallbackRange }) => Object.entries(aligns).map(([alignValue, icon]) => {
|
|
1497
|
+
return createMenuAction(`${alignKey}--${alignValue}`, () => {
|
|
1498
|
+
if (!cursorFallbackRange) {
|
|
1499
|
+
return;
|
|
1500
|
+
}
|
|
1501
|
+
const index = model.sheet.ranges?.findIndex((range) => range.key === alignKey && inRange3(rangeFromIndex(model.sheet, range.range), cursorFallbackRange.from)) ?? -1;
|
|
1502
|
+
const nextRangeEntity = {
|
|
1503
|
+
range: rangeToIndex(model.sheet, cursorFallbackRange),
|
|
1504
|
+
key: alignKey,
|
|
1505
|
+
value: alignValue
|
|
1506
|
+
};
|
|
1507
|
+
const currentState = registry.get(stateAtom);
|
|
1508
|
+
if (index < 0) {
|
|
1509
|
+
Obj4.change(model.sheet, (obj) => {
|
|
1510
|
+
obj.ranges?.push(nextRangeEntity);
|
|
1511
|
+
});
|
|
1512
|
+
registry.set(stateAtom, {
|
|
1513
|
+
...currentState,
|
|
1514
|
+
[alignKey]: nextRangeEntity.value
|
|
1515
|
+
});
|
|
1516
|
+
} else if (model.sheet.ranges[index].value === nextRangeEntity.value) {
|
|
1517
|
+
Obj4.change(model.sheet, (obj) => {
|
|
1518
|
+
obj.ranges?.splice(index, 1);
|
|
1519
|
+
});
|
|
1520
|
+
registry.set(stateAtom, {
|
|
1521
|
+
...currentState,
|
|
1522
|
+
[alignKey]: void 0
|
|
1523
|
+
});
|
|
1524
|
+
} else {
|
|
1525
|
+
Obj4.change(model.sheet, (obj) => {
|
|
1526
|
+
obj.ranges?.splice(index, 1, nextRangeEntity);
|
|
1527
|
+
});
|
|
1528
|
+
registry.set(stateAtom, {
|
|
1529
|
+
...currentState,
|
|
1530
|
+
[alignKey]: nextRangeEntity.value
|
|
1531
|
+
});
|
|
1532
|
+
}
|
|
1533
|
+
}, {
|
|
1534
|
+
key: alignKey,
|
|
1535
|
+
value: alignValue,
|
|
1536
|
+
checked: state[alignKey] === alignValue,
|
|
1537
|
+
label: [
|
|
1538
|
+
`range value ${alignValue} label`,
|
|
1539
|
+
{
|
|
1540
|
+
ns: meta.id
|
|
1541
|
+
}
|
|
1542
|
+
],
|
|
1543
|
+
icon,
|
|
1544
|
+
testId: `grid.toolbar.${alignKey}.${alignValue}`
|
|
1545
|
+
});
|
|
1546
|
+
});
|
|
1547
|
+
var createAlign = (context) => {
|
|
1548
|
+
const alignGroup = createAlignGroupAction(context.state[alignKey]);
|
|
1549
|
+
const alignActions = createAlignActions(context);
|
|
1550
|
+
return {
|
|
1551
|
+
nodes: [
|
|
1552
|
+
alignGroup,
|
|
1553
|
+
...alignActions
|
|
1554
|
+
],
|
|
1555
|
+
edges: [
|
|
1556
|
+
{
|
|
1557
|
+
source: "root",
|
|
1558
|
+
target: "align",
|
|
1559
|
+
relation: "child"
|
|
1560
|
+
},
|
|
1561
|
+
...alignActions.map(({ id }) => ({
|
|
1562
|
+
source: alignGroup.id,
|
|
1563
|
+
target: id,
|
|
1564
|
+
relation: "child"
|
|
1565
|
+
}))
|
|
1566
|
+
]
|
|
1567
|
+
};
|
|
1568
|
+
};
|
|
1569
|
+
|
|
1570
|
+
// src/components/SheetToolbar/style.ts
|
|
1571
|
+
import { RegistryContext as RegistryContext2 } from "@effect-atom/atom-react";
|
|
1572
|
+
import { useContext as useContext4, useEffect as useEffect5 } from "react";
|
|
1573
|
+
import { inRange as inRange4 } from "@dxos/compute";
|
|
1574
|
+
import { Obj as Obj5 } from "@dxos/echo";
|
|
1575
|
+
import { createMenuAction as createMenuAction2, createMenuItemGroup as createMenuItemGroup2 } from "@dxos/react-ui-menu";
|
|
1576
|
+
var styles = {
|
|
1577
|
+
highlight: "ph--highlighter--regular",
|
|
1578
|
+
softwrap: "ph--paragraph--regular"
|
|
1579
|
+
};
|
|
1580
|
+
var useStyleState = (stateAtom) => {
|
|
1581
|
+
const registry = useContext4(RegistryContext2);
|
|
1582
|
+
const { cursorFallbackRange, model } = useSheetContext();
|
|
1583
|
+
useEffect5(() => {
|
|
1584
|
+
let highlight = false;
|
|
1585
|
+
let softwrap = false;
|
|
1586
|
+
if (cursorFallbackRange && model.sheet.ranges) {
|
|
1587
|
+
model.sheet.ranges.filter(({ range, key }) => key === "style" && inRange4(rangeFromIndex(model.sheet, range), cursorFallbackRange.from)).forEach(({ value }) => {
|
|
1588
|
+
if (value === "highlight") {
|
|
1589
|
+
highlight = true;
|
|
1590
|
+
}
|
|
1591
|
+
if (value === "softwrap") {
|
|
1592
|
+
softwrap = true;
|
|
1593
|
+
}
|
|
1594
|
+
});
|
|
1595
|
+
}
|
|
1596
|
+
const prev = registry.get(stateAtom);
|
|
1597
|
+
registry.set(stateAtom, {
|
|
1598
|
+
...prev,
|
|
1599
|
+
highlight,
|
|
1600
|
+
softwrap
|
|
1601
|
+
});
|
|
1602
|
+
}, [
|
|
1603
|
+
cursorFallbackRange,
|
|
1604
|
+
model.sheet,
|
|
1605
|
+
registry,
|
|
1606
|
+
stateAtom
|
|
1607
|
+
]);
|
|
1608
|
+
};
|
|
1609
|
+
var createStyleGroup = (state) => {
|
|
1610
|
+
return createMenuItemGroup2("style", {
|
|
1611
|
+
variant: "toggleGroup",
|
|
1612
|
+
selectCardinality: "multiple",
|
|
1613
|
+
value: Object.keys(styles).filter((key) => !!state[key]).map((styleValue) => `style--${styleValue}`)
|
|
1614
|
+
});
|
|
1615
|
+
};
|
|
1616
|
+
var createStyleActions = ({ model, state, stateAtom, registry, cursorFallbackRange }) => Object.entries(styles).map(([styleValue, icon]) => {
|
|
1617
|
+
return createMenuAction2(`style--${styleValue}`, () => {
|
|
1618
|
+
if (!cursorFallbackRange) {
|
|
1619
|
+
return;
|
|
1620
|
+
}
|
|
1621
|
+
const index = model.sheet.ranges?.findIndex((range) => range.key === "style" && inRange4(rangeFromIndex(model.sheet, range.range), cursorFallbackRange.from)) ?? -1;
|
|
1622
|
+
const nextRangeEntity = {
|
|
1623
|
+
range: rangeToIndex(model.sheet, cursorFallbackRange),
|
|
1624
|
+
key: "style",
|
|
1625
|
+
value: styleValue
|
|
1626
|
+
};
|
|
1627
|
+
const currentState = registry.get(stateAtom);
|
|
1628
|
+
if (model.sheet.ranges.filter(({ range, key: rangeKey }) => rangeKey === "style" && inRange4(rangeFromIndex(model.sheet, range), cursorFallbackRange.from)).some(({ value: rangeValue }) => rangeValue === styleValue)) {
|
|
1629
|
+
if (index >= 0) {
|
|
1630
|
+
Obj5.change(model.sheet, (obj) => {
|
|
1631
|
+
obj.ranges?.splice(index, 1);
|
|
1632
|
+
});
|
|
1633
|
+
}
|
|
1634
|
+
registry.set(stateAtom, {
|
|
1635
|
+
...currentState,
|
|
1636
|
+
[nextRangeEntity.value]: false
|
|
1637
|
+
});
|
|
1638
|
+
} else {
|
|
1639
|
+
Obj5.change(model.sheet, (obj) => {
|
|
1640
|
+
obj.ranges?.push(nextRangeEntity);
|
|
1641
|
+
});
|
|
1642
|
+
registry.set(stateAtom, {
|
|
1643
|
+
...currentState,
|
|
1644
|
+
[nextRangeEntity.value]: true
|
|
1645
|
+
});
|
|
1646
|
+
}
|
|
1647
|
+
}, {
|
|
1648
|
+
key: "style",
|
|
1649
|
+
value: styleValue,
|
|
1650
|
+
icon,
|
|
1651
|
+
label: [
|
|
1652
|
+
`range value ${styleValue} label`,
|
|
1653
|
+
{
|
|
1654
|
+
ns: meta.id
|
|
1655
|
+
}
|
|
1656
|
+
],
|
|
1657
|
+
checked: !!state[styleValue]
|
|
1658
|
+
});
|
|
1659
|
+
});
|
|
1660
|
+
var createStyle = (context) => {
|
|
1661
|
+
const styleGroupAction = createStyleGroup(context.state);
|
|
1662
|
+
const styleActions = createStyleActions(context);
|
|
1663
|
+
return {
|
|
1664
|
+
nodes: [
|
|
1665
|
+
styleGroupAction,
|
|
1666
|
+
...styleActions
|
|
1667
|
+
],
|
|
1668
|
+
edges: [
|
|
1669
|
+
{
|
|
1670
|
+
source: "root",
|
|
1671
|
+
target: "style",
|
|
1672
|
+
relation: "child"
|
|
1673
|
+
},
|
|
1674
|
+
...styleActions.map(({ id }) => ({
|
|
1675
|
+
source: styleGroupAction.id,
|
|
1676
|
+
target: id,
|
|
1677
|
+
relation: "child"
|
|
1678
|
+
}))
|
|
1679
|
+
]
|
|
1680
|
+
};
|
|
1681
|
+
};
|
|
1682
|
+
|
|
1683
|
+
// src/components/SheetToolbar/useToolbarState.ts
|
|
1684
|
+
import { Atom, RegistryContext as RegistryContext3, useAtomValue } from "@effect-atom/atom-react";
|
|
1685
|
+
import { useContext as useContext5, useMemo as useMemo3 } from "react";
|
|
1686
|
+
var useToolbarState = (initialState = {}) => {
|
|
1687
|
+
return useMemo3(() => Atom.make(initialState).pipe(Atom.keepAlive), []);
|
|
1688
|
+
};
|
|
1689
|
+
|
|
1690
|
+
// src/components/SheetToolbar/SheetToolbar.tsx
|
|
1691
|
+
var createToolbarActions = ({ model, stateAtom, registry, cursorFallbackRange, customActions }) => {
|
|
1692
|
+
return Atom2.make((get) => {
|
|
1693
|
+
const state = get(stateAtom);
|
|
1694
|
+
const context = {
|
|
1695
|
+
model,
|
|
1696
|
+
state,
|
|
1697
|
+
stateAtom,
|
|
1698
|
+
registry,
|
|
1699
|
+
cursorFallbackRange
|
|
1700
|
+
};
|
|
1701
|
+
const align = createAlign(context);
|
|
1702
|
+
const style = createStyle(context);
|
|
1703
|
+
const gap = createGapSeparator();
|
|
1704
|
+
const graph = {
|
|
1705
|
+
nodes: [
|
|
1706
|
+
...align.nodes,
|
|
1707
|
+
...style.nodes,
|
|
1708
|
+
...gap.nodes
|
|
1709
|
+
],
|
|
1710
|
+
edges: [
|
|
1711
|
+
...align.edges,
|
|
1712
|
+
...style.edges,
|
|
1713
|
+
...gap.edges
|
|
1714
|
+
]
|
|
1715
|
+
};
|
|
1716
|
+
if (customActions) {
|
|
1717
|
+
const custom = get(customActions);
|
|
1718
|
+
graph.nodes.push(...custom.nodes);
|
|
1719
|
+
graph.edges.push(...custom.edges);
|
|
1720
|
+
}
|
|
1721
|
+
return graph;
|
|
1722
|
+
});
|
|
1723
|
+
};
|
|
1724
|
+
var SheetToolbar = ({ id, ...props }) => {
|
|
1725
|
+
const { model, cursorFallbackRange } = useSheetContext();
|
|
1726
|
+
const stateAtom = useToolbarState({});
|
|
1727
|
+
const registry = useContext6(RegistryContext4);
|
|
1728
|
+
useAlignState(stateAtom);
|
|
1729
|
+
useStyleState(stateAtom);
|
|
1730
|
+
const { graph } = useAppGraph();
|
|
1731
|
+
const customActions = useMemo4(() => {
|
|
1732
|
+
return Atom2.make((get) => {
|
|
1733
|
+
const actions = get(graph.actions(id));
|
|
1734
|
+
const nodes = actions.filter((action) => action.properties.disposition === "toolbar");
|
|
1735
|
+
return {
|
|
1736
|
+
nodes,
|
|
1737
|
+
edges: nodes.map((node) => ({
|
|
1738
|
+
source: "root",
|
|
1739
|
+
target: node.id,
|
|
1740
|
+
relation: "child"
|
|
1741
|
+
}))
|
|
1742
|
+
};
|
|
1743
|
+
});
|
|
1744
|
+
}, [
|
|
1745
|
+
graph,
|
|
1746
|
+
id
|
|
1747
|
+
]);
|
|
1748
|
+
const actionsCreator = useMemo4(() => createToolbarActions({
|
|
1749
|
+
model,
|
|
1750
|
+
stateAtom,
|
|
1751
|
+
registry,
|
|
1752
|
+
cursorFallbackRange,
|
|
1753
|
+
customActions
|
|
1754
|
+
}), [
|
|
1755
|
+
model,
|
|
1756
|
+
stateAtom,
|
|
1757
|
+
registry,
|
|
1758
|
+
cursorFallbackRange,
|
|
1759
|
+
customActions
|
|
1760
|
+
]);
|
|
1761
|
+
const menu = useMenuActions(actionsCreator);
|
|
1762
|
+
return /* @__PURE__ */ React5.createElement(Menu.Root, {
|
|
1763
|
+
...props,
|
|
1764
|
+
...menu,
|
|
1765
|
+
attendableId: id
|
|
1766
|
+
}, /* @__PURE__ */ React5.createElement(Menu.Toolbar, null));
|
|
1460
1767
|
};
|
|
1461
1768
|
|
|
1462
|
-
// src/components/
|
|
1463
|
-
var
|
|
1769
|
+
// src/components/Sheet/Sheet.tsx
|
|
1770
|
+
var Sheet = {
|
|
1771
|
+
Root: SheetRoot,
|
|
1772
|
+
Toolbar: SheetToolbar,
|
|
1773
|
+
Content: SheetContent,
|
|
1774
|
+
Statusbar: SheetStatusbar
|
|
1775
|
+
};
|
|
1776
|
+
|
|
1777
|
+
// src/containers/SheetContainer/SheetContainer.tsx
|
|
1778
|
+
var SheetContainer = ({ registry, ...props }) => /* @__PURE__ */ React6.createElement(ComputeGraphContextProvider, {
|
|
1779
|
+
registry
|
|
1780
|
+
}, /* @__PURE__ */ React6.createElement(SheetContainerInner, props));
|
|
1781
|
+
var SheetContainerInner = ({ role, subject: sheet, attendableId, space, ignoreAttention }) => {
|
|
1782
|
+
const graph = useComputeGraph(space);
|
|
1783
|
+
if (!graph) {
|
|
1784
|
+
return null;
|
|
1785
|
+
}
|
|
1786
|
+
return /* @__PURE__ */ React6.createElement(Sheet.Root, {
|
|
1787
|
+
graph,
|
|
1788
|
+
sheet,
|
|
1789
|
+
attendableId,
|
|
1790
|
+
ignoreAttention
|
|
1791
|
+
}, /* @__PURE__ */ React6.createElement(Panel.Root, {
|
|
1792
|
+
classNames: role === "section" && "aspect-aquare"
|
|
1793
|
+
}, /* @__PURE__ */ React6.createElement(Panel.Toolbar, {
|
|
1794
|
+
asChild: true
|
|
1795
|
+
}, /* @__PURE__ */ React6.createElement(Sheet.Toolbar, {
|
|
1796
|
+
id: attendableId
|
|
1797
|
+
})), /* @__PURE__ */ React6.createElement(Panel.Content, {
|
|
1798
|
+
asChild: true
|
|
1799
|
+
}, /* @__PURE__ */ React6.createElement(Sheet.Content, null)), /* @__PURE__ */ React6.createElement(Panel.Statusbar, {
|
|
1800
|
+
asChild: true
|
|
1801
|
+
}, /* @__PURE__ */ React6.createElement(Sheet.Statusbar, null))));
|
|
1802
|
+
};
|
|
1464
1803
|
|
|
1804
|
+
// src/containers/SheetContainer/index.ts
|
|
1805
|
+
var SheetContainer_default = SheetContainer;
|
|
1465
1806
|
export {
|
|
1466
|
-
|
|
1467
|
-
useComputeGraph,
|
|
1468
|
-
useSheetContext,
|
|
1469
|
-
SheetProvider,
|
|
1470
|
-
GridSheet,
|
|
1471
|
-
RangeList,
|
|
1472
|
-
SheetContainer
|
|
1807
|
+
SheetContainer_default as default
|
|
1473
1808
|
};
|
|
1474
|
-
//# sourceMappingURL=
|
|
1809
|
+
//# sourceMappingURL=SheetContainer-ICPEZUMD.mjs.map
|