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