@dxos/plugin-sheet 0.6.13-main.548ca8d → 0.6.13-main.ed424a1
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/{SheetContainer-NDNIS44E.mjs → SheetContainer-RVRACGCZ.mjs} +107 -82
- package/dist/lib/browser/SheetContainer-RVRACGCZ.mjs.map +7 -0
- package/dist/lib/browser/{chunk-GKI67SEF.mjs → chunk-BWN5DZWZ.mjs} +16 -11
- package/dist/lib/browser/chunk-BWN5DZWZ.mjs.map +7 -0
- package/dist/lib/browser/{chunk-AQSGDA4X.mjs → chunk-HOG37RYS.mjs} +92 -178
- package/dist/lib/browser/chunk-HOG37RYS.mjs.map +7 -0
- package/dist/lib/browser/index.mjs +2 -2
- package/dist/lib/browser/meta.json +1 -1
- package/dist/lib/browser/types.mjs +3 -3
- package/dist/lib/node/{SheetContainer-YSQGJD7K.cjs → SheetContainer-J7XROAMN.cjs} +113 -89
- package/dist/lib/node/SheetContainer-J7XROAMN.cjs.map +7 -0
- package/dist/lib/node/{chunk-6F43RV45.cjs → chunk-AXQZA2YS.cjs} +103 -186
- package/dist/lib/node/chunk-AXQZA2YS.cjs.map +7 -0
- package/dist/lib/node/{chunk-ER3PM7GD.cjs → chunk-NZARD7UP.cjs} +20 -15
- package/dist/lib/node/chunk-NZARD7UP.cjs.map +7 -0
- package/dist/lib/node/index.cjs +18 -18
- package/dist/lib/node/meta.json +1 -1
- package/dist/lib/node/types.cjs +7 -7
- package/dist/lib/node/types.cjs.map +1 -1
- package/dist/lib/node-esm/{SheetContainer-M7WRMZDU.mjs → SheetContainer-YWQVKHQB.mjs} +107 -82
- package/dist/lib/node-esm/SheetContainer-YWQVKHQB.mjs.map +7 -0
- package/dist/lib/node-esm/{chunk-ELTFPX5B.mjs → chunk-BPXXIAOQ.mjs} +92 -178
- package/dist/lib/node-esm/chunk-BPXXIAOQ.mjs.map +7 -0
- package/dist/lib/node-esm/{chunk-ZVLLQ2PJ.mjs → chunk-WFDTY3IC.mjs} +16 -11
- package/dist/lib/node-esm/chunk-WFDTY3IC.mjs.map +7 -0
- package/dist/lib/node-esm/index.mjs +2 -2
- package/dist/lib/node-esm/meta.json +1 -1
- package/dist/lib/node-esm/types.mjs +3 -3
- package/dist/types/src/components/GridSheet/GridSheet.d.ts.map +1 -1
- package/dist/types/src/components/GridSheet/util.d.ts +2 -2
- package/dist/types/src/components/GridSheet/util.d.ts.map +1 -1
- package/dist/types/src/components/SheetContainer/SheetContainer.d.ts.map +1 -1
- package/dist/types/src/components/SheetContainer/SheetContainer.stories.d.ts.map +1 -1
- package/dist/types/src/components/SheetContext/SheetContext.d.ts +1 -2
- package/dist/types/src/components/SheetContext/SheetContext.d.ts.map +1 -1
- package/dist/types/src/components/Toolbar/Toolbar.d.ts +11 -17
- package/dist/types/src/components/Toolbar/Toolbar.d.ts.map +1 -1
- package/dist/types/src/components/Toolbar/Toolbar.stories.d.ts +1 -2
- package/dist/types/src/components/Toolbar/Toolbar.stories.d.ts.map +1 -1
- package/dist/types/src/components/index.d.ts.map +1 -1
- package/dist/types/src/defs/index.d.ts +1 -0
- package/dist/types/src/defs/index.d.ts.map +1 -1
- package/dist/types/src/defs/sheet-range-types.d.ts +13 -0
- package/dist/types/src/defs/sheet-range-types.d.ts.map +1 -0
- package/dist/types/src/hooks/index.d.ts +0 -1
- package/dist/types/src/hooks/index.d.ts.map +1 -1
- package/dist/types/src/model/index.d.ts +0 -1
- package/dist/types/src/model/index.d.ts.map +1 -1
- package/dist/types/src/types.d.ts +39 -20
- package/dist/types/src/types.d.ts.map +1 -1
- package/package.json +35 -34
- package/src/components/GridSheet/GridSheet.stories.tsx +2 -2
- package/src/components/GridSheet/GridSheet.tsx +5 -3
- package/src/components/GridSheet/util.ts +24 -10
- package/src/components/SheetContainer/SheetContainer.stories.tsx +2 -2
- package/src/components/SheetContainer/SheetContainer.tsx +3 -28
- package/src/components/SheetContext/SheetContext.tsx +5 -9
- package/src/components/Toolbar/Toolbar.tsx +116 -68
- package/src/defs/index.ts +1 -0
- package/src/defs/sheet-range-types.ts +46 -0
- package/src/defs/util.ts +1 -1
- package/src/hooks/index.ts +0 -1
- package/src/model/index.ts +0 -1
- package/src/types.ts +5 -11
- package/dist/lib/browser/SheetContainer-NDNIS44E.mjs.map +0 -7
- package/dist/lib/browser/chunk-AQSGDA4X.mjs.map +0 -7
- package/dist/lib/browser/chunk-GKI67SEF.mjs.map +0 -7
- package/dist/lib/node/SheetContainer-YSQGJD7K.cjs.map +0 -7
- package/dist/lib/node/chunk-6F43RV45.cjs.map +0 -7
- package/dist/lib/node/chunk-ER3PM7GD.cjs.map +0 -7
- package/dist/lib/node-esm/SheetContainer-M7WRMZDU.mjs.map +0 -7
- package/dist/lib/node-esm/chunk-ELTFPX5B.mjs.map +0 -7
- package/dist/lib/node-esm/chunk-ZVLLQ2PJ.mjs.map +0 -7
- package/dist/types/src/hooks/useFormattingModel.d.ts +0 -3
- package/dist/types/src/hooks/useFormattingModel.d.ts.map +0 -1
- package/dist/types/src/model/formatting-model.d.ts +0 -19
- package/dist/types/src/model/formatting-model.d.ts.map +0 -1
- package/src/hooks/useFormattingModel.ts +0 -11
- package/src/model/formatting-model.ts +0 -116
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../src/components/SheetContainer/SheetContainer.tsx", "../../../src/components/FunctionEditor/FunctionEditor.tsx", "../../../src/components/Toolbar/Toolbar.tsx", "../../../src/components/SheetContainer/index.ts"],
|
|
4
|
+
"sourcesContent": ["//\n// Copyright 2023 DXOS.org\n//\n\nimport React from 'react';\n\nimport { FunctionEditor } from '../FunctionEditor';\nimport { GridSheet } from '../GridSheet';\nimport { SheetProvider, type SheetProviderProps } from '../SheetContext';\nimport { Toolbar } from '../Toolbar';\n\nexport const SheetContainer = ({ graph, sheet, role }: SheetProviderProps & { role?: string }) => {\n return (\n <SheetProvider sheet={sheet} graph={graph}>\n <Toolbar.Root role={role}>\n <Toolbar.Styles />\n <Toolbar.Alignment />\n <Toolbar.Separator />\n <Toolbar.Actions />\n </Toolbar.Root>\n <div role='none' className='border-bs border-separator grid cols-1 rows-[1fr_min-content] min-bs-0'>\n <GridSheet />\n <FunctionEditor />\n </div>\n </SheetProvider>\n );\n};\n", "//\n// Copyright 2024 DXOS.org\n//\n\nimport React from 'react';\n\nimport { Icon } from '@dxos/react-ui';\nimport { mx } from '@dxos/react-ui-theme';\n\nimport { addressToA1Notation, rangeToA1Notation } from '../../defs';\nimport { useSheetContext } from '../SheetContext';\n\nexport const FunctionEditor = () => {\n const { model, cursor, range } = useSheetContext();\n\n let value;\n let isFormula = false;\n if (cursor) {\n value = model.getCellValue(cursor);\n if (typeof value === 'string' && value.charAt(0) === '=') {\n value = model.graph.mapFunctionBindingFromId(model.mapFormulaIndicesToRefs(value));\n isFormula = true;\n } else if (value != null) {\n value = String(value);\n }\n }\n\n return (\n <div\n className={mx(\n 'flex shrink-0 justify-between items-center px-4 py-1 text-sm border-bs !border-separator attention-surface',\n )}\n >\n <div className='flex gap-4 items-center'>\n <div className='flex w-16 items-center font-mono'>\n {(range && rangeToA1Notation(range)) || (cursor && addressToA1Notation(cursor))}\n </div>\n <div className='flex gap-2 items-center'>\n <Icon icon='ph--function--regular' classNames={['text-greenText', isFormula ? 'visible' : 'invisible']} />\n <span className='font-mono'>{value}</span>\n </div>\n </div>\n </div>\n );\n};\n", "//\n// Copyright 2024 DXOS.org\n//\n\nimport { createContext } from '@radix-ui/react-context';\nimport React, { type PropsWithChildren, useCallback, useMemo } from 'react';\n\nimport { useIntentDispatcher } from '@dxos/app-framework';\nimport {\n Icon,\n Toolbar as NaturalToolbar,\n useTranslation,\n Tooltip,\n type ToolbarToggleGroupItemProps as NaturalToolbarToggleGroupItemProps,\n type ToolbarButtonProps as NaturalToolbarButtonProps,\n type ToolbarToggleProps as NaturalToolbarToggleProps,\n type ThemedClassName,\n} from '@dxos/react-ui';\nimport { useAttention } from '@dxos/react-ui-attention';\nimport { nonNullable } from '@dxos/util';\n\nimport {\n addressToIndex,\n type AlignKey,\n type AlignValue,\n type CommentKey,\n type CommentValue,\n inRange,\n type StyleKey,\n type StyleValue,\n} from '../../defs';\nimport { SHEET_PLUGIN } from '../../meta';\nimport { type SheetType } from '../../types';\nimport { useSheetContext } from '../SheetContext';\n\n//\n// Buttons\n//\n\nconst buttonStyles = 'min-bs-0 p-2';\nconst tooltipProps = { side: 'bottom' as const, classNames: 'z-10' };\n\nconst ToolbarSeparator = () => <div role='separator' className='grow' />;\n\n//\n// ToolbarItem\n//\n\ntype ToolbarItemProps =\n | (NaturalToolbarButtonProps & { itemType: 'button'; icon: string })\n | (NaturalToolbarToggleGroupItemProps & { itemType: 'toggleGroupItem'; icon: string })\n | (NaturalToolbarToggleProps & { itemType: 'toggle'; icon: string });\n\nexport const ToolbarItem = ({ itemType, icon, children, ...props }: ToolbarItemProps) => {\n const Invoker =\n itemType === 'toggleGroupItem'\n ? NaturalToolbar.ToggleGroupItem\n : itemType === 'toggle'\n ? NaturalToolbar.Toggle\n : NaturalToolbar.Button;\n return (\n <Tooltip.Root>\n <Tooltip.Trigger asChild>\n {/* TODO(thure): type the props spread better. */}\n <Invoker variant='ghost' {...(props as any)} classNames={buttonStyles}>\n <Icon icon={icon} size={5} />\n <span className='sr-only'>{children}</span>\n </Invoker>\n </Tooltip.Trigger>\n <Tooltip.Portal>\n <Tooltip.Content {...tooltipProps}>\n {children}\n <Tooltip.Arrow />\n </Tooltip.Content>\n </Tooltip.Portal>\n </Tooltip.Root>\n );\n};\n\n//\n// Root\n//\n\ntype AlignAction = { key: AlignKey; value: AlignValue };\ntype CommentAction = { key: CommentKey; value: CommentValue; cellContent?: string };\ntype StyleAction = { key: StyleKey; value: StyleValue };\n\nexport type ToolbarAction = StyleAction | AlignAction | CommentAction;\n\nexport type ToolbarActionType = ToolbarAction['key'];\n\nexport type ToolbarActionHandler = (action: ToolbarAction) => void;\n\nexport type ToolbarProps = ThemedClassName<\n PropsWithChildren<{\n role?: string;\n }>\n>;\n\nconst [ToolbarContextProvider, useToolbarContext] = createContext<{ onAction: (action: ToolbarAction) => void }>(\n 'Toolbar',\n);\n\n// TODO(Zan): Factor out, copied this from MarkdownPlugin.\nconst sectionToolbarLayout =\n 'bs-[--rail-action] bg-[--sticky-bg] sticky block-start-0 __-block-start-px transition-opacity';\n\ntype Range = SheetType['ranges'][number];\n\nconst ToolbarRoot = ({ children, role, classNames }: ToolbarProps) => {\n const { id, model, range, cursor } = useSheetContext();\n const { hasAttention } = useAttention(id);\n const dispatch = useIntentDispatcher();\n\n // TODO(Zan): Centralise the toolbar action handler. Current implementation in stories.\n const handleAction = useCallback(\n (action: ToolbarAction) => {\n switch (action.key) {\n case 'align':\n if (cursor) {\n const index = model.sheet.ranges?.findIndex(\n (range) => range.key === action.key && inRange(range.range, cursor),\n );\n const nextRange = range ? { from: range.from, to: range.to ?? range.from } : { from: cursor, to: cursor };\n const nextRangeEntity = {\n range: nextRange as Range['range'],\n key: action.key,\n value: action.value,\n };\n if (index < 0) {\n model.sheet.ranges?.push(nextRangeEntity);\n } else {\n model.sheet.ranges?.splice(index, 1, nextRangeEntity);\n }\n }\n break;\n case 'style':\n if (action.value === 'unset') {\n const index = model.sheet.ranges?.findIndex((range) => range.key === action.key);\n if (index >= 0) {\n model.sheet.ranges?.splice(index, 1);\n }\n } else if (range || cursor) {\n const nextRange = range ? { from: range.from, to: range.to ?? range.from } : { from: cursor, to: cursor };\n model.sheet.ranges?.push({\n range: nextRange as Range['range'],\n key: action.key,\n value: action.value,\n });\n }\n break;\n case 'comment': {\n // TODO(Zan): We shouldn't hardcode the action ID.\n void dispatch({\n action: 'dxos.org/plugin/thread/action/create',\n data: {\n cursor: action.value,\n name: action.cellContent,\n subject: model.sheet,\n },\n });\n }\n }\n },\n [model.sheet, range, cursor, dispatch],\n );\n\n return (\n <ToolbarContextProvider onAction={handleAction}>\n <NaturalToolbar.Root\n classNames={[\n ...(role === 'section'\n ? ['z-[2] group-focus-within/section:visible', !hasAttention && 'invisible', sectionToolbarLayout]\n : ['attention-surface']),\n classNames,\n ]}\n >\n {children}\n </NaturalToolbar.Root>\n </ToolbarContextProvider>\n );\n};\n\n// TODO(burdon): Generalize.\n// TODO(burdon): Detect and display current state.\ntype ButtonProps<T> = {\n value: T;\n icon: string;\n disabled?: (state: Range) => boolean;\n};\n\n//\n// Alignment\n//\n\nconst alignmentOptions: ButtonProps<AlignValue>[] = [\n { value: 'start', icon: 'ph--text-align-left--regular' },\n { value: 'center', icon: 'ph--text-align-center--regular' },\n { value: 'end', icon: 'ph--text-align-right--regular' },\n];\n\nconst Alignment = () => {\n const { cursor, model } = useSheetContext();\n const { onAction } = useToolbarContext('Alignment');\n const { t } = useTranslation(SHEET_PLUGIN);\n\n const value = useMemo(\n () =>\n cursor\n ? model.sheet.ranges?.find(({ range, key }) => key === 'alignment' && inRange(range, cursor))?.value\n : undefined,\n [cursor, model.sheet.ranges],\n );\n\n return (\n <NaturalToolbar.ToggleGroup\n type='single'\n value={value}\n onValueChange={(value: AlignValue) => onAction?.({ key: 'align', value })}\n >\n {alignmentOptions.map(({ value, icon }) => (\n <ToolbarItem itemType='toggleGroupItem' key={value} value={value} icon={icon}>\n {t(`toolbar ${value} label`)}\n </ToolbarItem>\n ))}\n </NaturalToolbar.ToggleGroup>\n );\n};\n\nconst styleOptions: ButtonProps<StyleValue>[] = [{ value: 'highlight', icon: 'ph--highlighter--regular' }];\n\nconst Styles = () => {\n const { cursor, model } = useSheetContext();\n const { onAction } = useToolbarContext('Styles');\n const { t } = useTranslation(SHEET_PLUGIN);\n\n const activeValues = useMemo(\n () =>\n cursor\n ? model.sheet.ranges\n ?.filter(({ range, key }) => key === 'style' && inRange(range, cursor))\n .reduce((acc, { value }) => {\n acc.add(value);\n return acc;\n }, new Set())\n : undefined,\n [cursor, model.sheet.ranges],\n );\n\n return (\n <>\n {styleOptions.map(({ value, icon }) => (\n <ToolbarItem\n itemType='toggle'\n key={value}\n pressed={activeValues?.has(value)}\n onPressedChange={(nextPressed: boolean) => onAction?.({ key: 'style', value: nextPressed ? value : 'unset' })}\n icon={icon}\n >\n {t(`toolbar ${value} label`)}\n </ToolbarItem>\n ))}\n </>\n );\n};\n\n//\n// Actions\n//\n\nconst Actions = () => {\n const { onAction } = useToolbarContext('Actions');\n const { cursor, range, model } = useSheetContext();\n const { t } = useTranslation(SHEET_PLUGIN);\n\n const overlapsCommentAnchor = (model.sheet.threads ?? [])\n .filter(nonNullable)\n .filter((thread) => thread.status !== 'resolved')\n .some((thread) => {\n if (!cursor) {\n return false;\n }\n return addressToIndex(model.sheet, cursor) === thread.anchor;\n });\n\n const hasCursor = !!cursor;\n const cursorOnly = hasCursor && !range && !overlapsCommentAnchor;\n\n const tooltipLabelKey = !hasCursor\n ? 'no cursor label'\n : overlapsCommentAnchor\n ? 'selection overlaps existing comment label'\n : range\n ? 'comment ranges not supported label'\n : 'comment label';\n\n return (\n <ToolbarItem\n itemType='button'\n value='comment'\n icon='ph--chat-text--regular'\n data-testid='editor.toolbar.comment'\n onClick={() => {\n if (!cursor) {\n return;\n }\n return onAction?.({\n key: 'comment',\n value: addressToIndex(model.sheet, cursor),\n cellContent: model.getCellText(cursor),\n });\n }}\n disabled={!cursorOnly || overlapsCommentAnchor}\n >\n {t(tooltipLabelKey)}\n </ToolbarItem>\n );\n};\n\nexport const Toolbar = {\n Root: ToolbarRoot,\n Separator: ToolbarSeparator,\n Alignment,\n Styles,\n Actions,\n};\n\nexport { useToolbarContext };\n", "//\n// Copyright 2024 DXOS.org\n//\n\nimport { SheetContainer } from './SheetContainer';\n\nexport default SheetContainer;\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;AAIA,OAAOA,YAAW;;;ACAlB,OAAOC,WAAW;AAElB,SAASC,YAAY;AACrB,SAASC,UAAU;AAKZ,IAAMC,iBAAiB,MAAA;AAC5B,QAAM,EAAEC,OAAOC,QAAQC,MAAK,IAAKC,gB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,MAAAA;MACjC,CAAA;IACF;IACAkE,UAAU,CAACL,cAAcT;KAExBvB,EAAEiC,eAAAA,CAAAA;AAGT;AAEO,IAAMK,UAAU;EACrBrF,MAAMc;EACNwE,WAAWtG;EACX8D;EACAY;EACAW;AACF;;;AF1TO,IAAMkB,iBAAiB,CAAC,EAAEC,OAAOC,OAAOC,KAAI,MAA0C;AAC3F,SACE,gBAAAC,OAAA,cAACC,eAAAA;IAAcH;IAAcD;KAC3B,gBAAAG,OAAA,cAACE,QAAQC,MAAI;IAACJ;KACZ,gBAAAC,OAAA,cAACE,QAAQE,QAAM,IAAA,GACf,gBAAAJ,OAAA,cAACE,QAAQG,WAAS,IAAA,GAClB,gBAAAL,OAAA,cAACE,QAAQI,WAAS,IAAA,GAClB,gBAAAN,OAAA,cAACE,QAAQK,SAAO,IAAA,CAAA,GAElB,gBAAAP,OAAA,cAACQ,OAAAA;IAAIT,MAAK;IAAOU,WAAU;KACzB,gBAAAT,OAAA,cAACU,WAAAA,IAAAA,GACD,gBAAAV,OAAA,cAACW,gBAAAA,IAAAA,CAAAA,CAAAA;AAIT;;;AGpBA,IAAA,yBAAeC;",
|
|
6
|
+
"names": ["React", "React", "Icon", "mx", "FunctionEditor", "model", "cursor", "range", "useSheetContext", "value", "isFormula", "getCellValue", "charAt", "graph", "mapFunctionBindingFromId", "mapFormulaIndicesToRefs", "String", "div", "className", "mx", "rangeToA1Notation", "addressToA1Notation", "Icon", "icon", "classNames", "span", "createContext", "React", "useCallback", "useMemo", "useIntentDispatcher", "Icon", "Toolbar", "NaturalToolbar", "useTranslation", "Tooltip", "useAttention", "nonNullable", "buttonStyles", "tooltipProps", "side", "classNames", "ToolbarSeparator", "React", "div", "role", "className", "ToolbarItem", "itemType", "icon", "children", "props", "Invoker", "NaturalToolbar", "ToggleGroupItem", "Toggle", "Button", "Tooltip", "Root", "Trigger", "asChild", "variant", "Icon", "size", "span", "Portal", "Content", "Arrow", "ToolbarContextProvider", "useToolbarContext", "createContext", "sectionToolbarLayout", "ToolbarRoot", "id", "model", "range", "cursor", "useSheetContext", "hasAttention", "useAttention", "dispatch", "useIntentDispatcher", "handleAction", "useCallback", "action", "key", "index", "sheet", "ranges", "findIndex", "inRange", "nextRange", "from", "to", "nextRangeEntity", "value", "push", "splice", "data", "name", "cellContent", "subject", "onAction", "alignmentOptions", "Alignment", "t", "useTranslation", "SHEET_PLUGIN", "useMemo", "find", "undefined", "ToggleGroup", "type", "onValueChange", "map", "styleOptions", "Styles", "activeValues", "filter", "reduce", "acc", "add", "Set", "pressed", "has", "onPressedChange", "nextPressed", "Actions", "overlapsCommentAnchor", "threads", "nonNullable", "thread", "status", "some", "addressToIndex", "anchor", "hasCursor", "cursorOnly", "tooltipLabelKey", "data-testid", "onClick", "getCellText", "disabled", "Toolbar", "Separator", "SheetContainer", "graph", "sheet", "role", "React", "SheetProvider", "Toolbar", "Root", "Styles", "Alignment", "Separator", "Actions", "div", "className", "GridSheet", "FunctionEditor", "SheetContainer"]
|
|
7
|
+
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { createRequire } from 'node:module';const require = createRequire(import.meta.url);
|
|
2
2
|
import {
|
|
3
3
|
SheetType
|
|
4
|
-
} from "./chunk-
|
|
4
|
+
} from "./chunk-WFDTY3IC.mjs";
|
|
5
5
|
import {
|
|
6
6
|
SHEET_PLUGIN
|
|
7
7
|
} from "./chunk-VCYJWE3O.mjs";
|
|
@@ -134,7 +134,7 @@ var createSheet = ({ name, cells, ...size } = {}) => {
|
|
|
134
134
|
columns: [],
|
|
135
135
|
rowMeta: {},
|
|
136
136
|
columnMeta: {},
|
|
137
|
-
|
|
137
|
+
ranges: []
|
|
138
138
|
});
|
|
139
139
|
initialize(sheet, size);
|
|
140
140
|
if (cells) {
|
|
@@ -157,13 +157,6 @@ var addressFromIndex = (sheet, idx) => {
|
|
|
157
157
|
row: sheet.rows.indexOf(row)
|
|
158
158
|
};
|
|
159
159
|
};
|
|
160
|
-
var rangeFromIndex = (sheet, idx) => {
|
|
161
|
-
const [from, to] = idx.split(":").map((index) => addressFromIndex(sheet, index));
|
|
162
|
-
return {
|
|
163
|
-
from,
|
|
164
|
-
to
|
|
165
|
-
};
|
|
166
|
-
};
|
|
167
160
|
var closest = (cursor, cells) => {
|
|
168
161
|
let closestCell2;
|
|
169
162
|
let closestDistance = Number.MAX_SAFE_INTEGER;
|
|
@@ -186,6 +179,34 @@ var compareIndexPositions = (sheet, indexA, indexB) => {
|
|
|
186
179
|
}
|
|
187
180
|
};
|
|
188
181
|
|
|
182
|
+
// packages/plugins/plugin-sheet/src/defs/sheet-range-types.ts
|
|
183
|
+
var cellClassNameForRange = ({ key, value }) => {
|
|
184
|
+
switch (key) {
|
|
185
|
+
case "align":
|
|
186
|
+
switch (value) {
|
|
187
|
+
case "start":
|
|
188
|
+
return "text-start";
|
|
189
|
+
case "center":
|
|
190
|
+
return "text-center";
|
|
191
|
+
case "end":
|
|
192
|
+
return "text-end";
|
|
193
|
+
default:
|
|
194
|
+
return void 0;
|
|
195
|
+
}
|
|
196
|
+
case "comment":
|
|
197
|
+
return "bg-gridComment";
|
|
198
|
+
case "style":
|
|
199
|
+
switch (value) {
|
|
200
|
+
case "highlight":
|
|
201
|
+
return "bg-gridHighlight";
|
|
202
|
+
default:
|
|
203
|
+
return void 0;
|
|
204
|
+
}
|
|
205
|
+
default:
|
|
206
|
+
return void 0;
|
|
207
|
+
}
|
|
208
|
+
};
|
|
209
|
+
|
|
189
210
|
// packages/plugins/plugin-sheet/src/extensions/compute.ts
|
|
190
211
|
import { syntaxTree } from "@codemirror/language";
|
|
191
212
|
import { RangeSetBuilder, StateEffect, StateField } from "@codemirror/state";
|
|
@@ -411,13 +432,14 @@ import { useAsyncState } from "@dxos/react-hooks";
|
|
|
411
432
|
import React4 from "react";
|
|
412
433
|
|
|
413
434
|
// packages/plugins/plugin-sheet/src/components/GridSheet/GridSheet.tsx
|
|
414
|
-
import React3, { useCallback as useCallback2, useMemo as
|
|
435
|
+
import React3, { useCallback as useCallback2, useMemo as useMemo3, useRef } from "react";
|
|
415
436
|
import { useAttention } from "@dxos/react-ui-attention";
|
|
416
437
|
import { Grid as Grid2, editorKeys, GridCellEditor, closestCell } from "@dxos/react-ui-grid";
|
|
417
438
|
|
|
418
439
|
// packages/plugins/plugin-sheet/src/components/GridSheet/util.ts
|
|
419
440
|
import { useEffect, useLayoutEffect, useState } from "react";
|
|
420
441
|
import { createDocAccessor } from "@dxos/react-client/echo";
|
|
442
|
+
import { parseValue, cellClassesForFieldType } from "@dxos/react-ui-data";
|
|
421
443
|
import { colToA1Notation, rowToA1Notation } from "@dxos/react-ui-grid";
|
|
422
444
|
import { mx as mx2 } from "@dxos/react-ui-theme";
|
|
423
445
|
var dxGridCellIndexToSheetCellAddress = (index) => {
|
|
@@ -453,7 +475,26 @@ var createDxGridRows = (model) => {
|
|
|
453
475
|
grid: {}
|
|
454
476
|
});
|
|
455
477
|
};
|
|
456
|
-
var
|
|
478
|
+
var projectCellProps = (model, col, row) => {
|
|
479
|
+
const address = {
|
|
480
|
+
col,
|
|
481
|
+
row
|
|
482
|
+
};
|
|
483
|
+
const rawValue = model.getValue(address);
|
|
484
|
+
if (rawValue === void 0 || rawValue === null) {
|
|
485
|
+
return {
|
|
486
|
+
value: ""
|
|
487
|
+
};
|
|
488
|
+
}
|
|
489
|
+
const ranges = model.sheet.ranges?.filter(({ range }) => inRange(range, address));
|
|
490
|
+
const type = model.getValueType(address);
|
|
491
|
+
const classNames = ranges?.map(cellClassNameForRange).reverse();
|
|
492
|
+
return {
|
|
493
|
+
value: parseValue(type, rawValue),
|
|
494
|
+
className: mx2(cellClassesForFieldType(type), classNames)
|
|
495
|
+
};
|
|
496
|
+
};
|
|
497
|
+
var gridCellGetter = (model) => {
|
|
457
498
|
const cachedGridCells = {};
|
|
458
499
|
return (nextBounds) => {
|
|
459
500
|
[
|
|
@@ -464,16 +505,10 @@ var gridCellGetter = (model, formatting) => {
|
|
|
464
505
|
].forEach((_2, r0) => {
|
|
465
506
|
const col = nextBounds.start.col + c0;
|
|
466
507
|
const row = nextBounds.start.row + r0;
|
|
467
|
-
const cell =
|
|
468
|
-
col,
|
|
469
|
-
row
|
|
470
|
-
});
|
|
508
|
+
const cell = projectCellProps(model, col, row);
|
|
471
509
|
if (cell.value) {
|
|
472
510
|
cachedGridCells;
|
|
473
|
-
cachedGridCells[`${col},${row}`] =
|
|
474
|
-
value: cell.value,
|
|
475
|
-
className: mx2(cell.classNames)
|
|
476
|
-
};
|
|
511
|
+
cachedGridCells[`${col},${row}`] = cell;
|
|
477
512
|
}
|
|
478
513
|
});
|
|
479
514
|
});
|
|
@@ -489,8 +524,8 @@ var colLabelCell = (col) => ({
|
|
|
489
524
|
value: colToA1Notation(col),
|
|
490
525
|
resizeHandle: "col"
|
|
491
526
|
});
|
|
492
|
-
var cellGetter = (model
|
|
493
|
-
const getGridCells = gridCellGetter(model
|
|
527
|
+
var cellGetter = (model) => {
|
|
528
|
+
const getGridCells = gridCellGetter(model);
|
|
494
529
|
return (nextBounds, plane) => {
|
|
495
530
|
switch (plane) {
|
|
496
531
|
case "grid":
|
|
@@ -516,7 +551,7 @@ var cellGetter = (model, formatting) => {
|
|
|
516
551
|
}
|
|
517
552
|
};
|
|
518
553
|
};
|
|
519
|
-
var useSheetModelDxGridProps = (dxGridRef, model
|
|
554
|
+
var useSheetModelDxGridProps = (dxGridRef, model) => {
|
|
520
555
|
const [columns, setColumns] = useState(createDxGridColumns(model));
|
|
521
556
|
const [rows, setRows] = useState(createDxGridColumns(model));
|
|
522
557
|
useLayoutEffect(() => {
|
|
@@ -524,7 +559,7 @@ var useSheetModelDxGridProps = (dxGridRef, model, formatting) => {
|
|
|
524
559
|
"cells"
|
|
525
560
|
]);
|
|
526
561
|
if (dxGridRef.current) {
|
|
527
|
-
dxGridRef.current.getCells = cellGetter(model
|
|
562
|
+
dxGridRef.current.getCells = cellGetter(model);
|
|
528
563
|
}
|
|
529
564
|
const handleCellsUpdate = () => {
|
|
530
565
|
dxGridRef.current?.requestUpdate("initialCells");
|
|
@@ -532,8 +567,7 @@ var useSheetModelDxGridProps = (dxGridRef, model, formatting) => {
|
|
|
532
567
|
cellsAccessor.handle.addListener("change", handleCellsUpdate);
|
|
533
568
|
return () => cellsAccessor.handle.removeListener("change", handleCellsUpdate);
|
|
534
569
|
}, [
|
|
535
|
-
model
|
|
536
|
-
formatting
|
|
570
|
+
model
|
|
537
571
|
]);
|
|
538
572
|
useEffect(() => {
|
|
539
573
|
const columnMetaAccessor = createDocAccessor(model.sheet, [
|
|
@@ -563,8 +597,8 @@ var useSheetModelDxGridProps = (dxGridRef, model, formatting) => {
|
|
|
563
597
|
};
|
|
564
598
|
};
|
|
565
599
|
|
|
566
|
-
// packages/plugins/plugin-sheet/src/hooks/
|
|
567
|
-
import {
|
|
600
|
+
// packages/plugins/plugin-sheet/src/hooks/useSheetModel.ts
|
|
601
|
+
import { useEffect as useEffect2, useState as useState2 } from "react";
|
|
568
602
|
|
|
569
603
|
// packages/plugins/plugin-sheet/src/model/decorations.ts
|
|
570
604
|
import { create as create2 } from "@dxos/echo-schema";
|
|
@@ -605,118 +639,6 @@ var createDecorations = () => {
|
|
|
605
639
|
};
|
|
606
640
|
};
|
|
607
641
|
|
|
608
|
-
// packages/plugins/plugin-sheet/src/model/formatting-model.ts
|
|
609
|
-
import { FieldValueType } from "@dxos/schema";
|
|
610
|
-
var FormattingModel = class {
|
|
611
|
-
constructor(_model) {
|
|
612
|
-
this._model = _model;
|
|
613
|
-
}
|
|
614
|
-
/**
|
|
615
|
-
* Get formatted string value and className for cell.
|
|
616
|
-
*/
|
|
617
|
-
getFormatting(cell) {
|
|
618
|
-
const value = this._model.getValue(cell);
|
|
619
|
-
if (value === void 0 || value === null) {
|
|
620
|
-
return {};
|
|
621
|
-
}
|
|
622
|
-
const locales = void 0;
|
|
623
|
-
const idx = addressToIndex(this._model.sheet, cell);
|
|
624
|
-
let formatting = this._model.sheet.formatting.find?.(({ range }) => range === idx);
|
|
625
|
-
const classNames = [
|
|
626
|
-
...formatting?.classNames ?? []
|
|
627
|
-
];
|
|
628
|
-
for (const [idx2, _formatting] of Object.entries(this._model.sheet.formatting)) {
|
|
629
|
-
const range = rangeFromIndex(this._model.sheet, idx2);
|
|
630
|
-
if (inRange(range, cell)) {
|
|
631
|
-
if (_formatting.classNames) {
|
|
632
|
-
classNames.push(..._formatting.classNames);
|
|
633
|
-
}
|
|
634
|
-
if (_formatting.type) {
|
|
635
|
-
formatting = _formatting;
|
|
636
|
-
}
|
|
637
|
-
}
|
|
638
|
-
}
|
|
639
|
-
const defaultNumber = "justify-end font-mono";
|
|
640
|
-
const type = formatting?.type ?? this._model.getValueType(cell);
|
|
641
|
-
switch (type) {
|
|
642
|
-
case FieldValueType.Boolean: {
|
|
643
|
-
return {
|
|
644
|
-
value: value.toLocaleString().toUpperCase(),
|
|
645
|
-
classNames: [
|
|
646
|
-
...classNames,
|
|
647
|
-
value ? "!text-greenText" : "!text-orangeText"
|
|
648
|
-
]
|
|
649
|
-
};
|
|
650
|
-
}
|
|
651
|
-
//
|
|
652
|
-
// Numbers.
|
|
653
|
-
//
|
|
654
|
-
case FieldValueType.Number: {
|
|
655
|
-
return {
|
|
656
|
-
value: value.toLocaleString(locales),
|
|
657
|
-
classNames: [
|
|
658
|
-
...classNames,
|
|
659
|
-
defaultNumber
|
|
660
|
-
]
|
|
661
|
-
};
|
|
662
|
-
}
|
|
663
|
-
case FieldValueType.Percent: {
|
|
664
|
-
return {
|
|
665
|
-
value: value * 100 + "%",
|
|
666
|
-
classNames: [
|
|
667
|
-
...classNames,
|
|
668
|
-
defaultNumber
|
|
669
|
-
]
|
|
670
|
-
};
|
|
671
|
-
}
|
|
672
|
-
case FieldValueType.Currency: {
|
|
673
|
-
return {
|
|
674
|
-
value: value.toLocaleString(locales, {
|
|
675
|
-
style: "currency",
|
|
676
|
-
currency: "USD",
|
|
677
|
-
minimumFractionDigits: 2,
|
|
678
|
-
maximumFractionDigits: 2
|
|
679
|
-
}),
|
|
680
|
-
classNames: [
|
|
681
|
-
...classNames,
|
|
682
|
-
defaultNumber
|
|
683
|
-
]
|
|
684
|
-
};
|
|
685
|
-
}
|
|
686
|
-
//
|
|
687
|
-
// Dates.
|
|
688
|
-
//
|
|
689
|
-
case FieldValueType.DateTime: {
|
|
690
|
-
const date = this._model.toLocalDate(value);
|
|
691
|
-
return {
|
|
692
|
-
value: date.toLocaleString(locales),
|
|
693
|
-
classNames
|
|
694
|
-
};
|
|
695
|
-
}
|
|
696
|
-
case FieldValueType.Date: {
|
|
697
|
-
const date = this._model.toLocalDate(value);
|
|
698
|
-
return {
|
|
699
|
-
value: date.toLocaleDateString(locales),
|
|
700
|
-
classNames
|
|
701
|
-
};
|
|
702
|
-
}
|
|
703
|
-
case FieldValueType.Time: {
|
|
704
|
-
const date = this._model.toLocalDate(value);
|
|
705
|
-
return {
|
|
706
|
-
value: date.toLocaleTimeString(locales),
|
|
707
|
-
classNames
|
|
708
|
-
};
|
|
709
|
-
}
|
|
710
|
-
default: {
|
|
711
|
-
return {
|
|
712
|
-
value: String(value),
|
|
713
|
-
classNames
|
|
714
|
-
};
|
|
715
|
-
}
|
|
716
|
-
}
|
|
717
|
-
}
|
|
718
|
-
};
|
|
719
|
-
|
|
720
642
|
// packages/plugins/plugin-sheet/src/model/sheet-model.ts
|
|
721
643
|
import { Event } from "@dxos/async";
|
|
722
644
|
import { Resource } from "@dxos/context";
|
|
@@ -724,17 +646,17 @@ import { getTypename } from "@dxos/echo-schema";
|
|
|
724
646
|
import { invariant as invariant3 } from "@dxos/invariant";
|
|
725
647
|
import { PublicKey } from "@dxos/keys";
|
|
726
648
|
import { log } from "@dxos/log";
|
|
727
|
-
import { FieldValueType
|
|
649
|
+
import { FieldValueType } from "@dxos/schema";
|
|
728
650
|
import { DetailedCellError, ExportedCellChange } from "#hyperformula";
|
|
729
651
|
var __dxlog_file2 = "/home/runner/work/dxos/dxos/packages/plugins/plugin-sheet/src/model/sheet-model.ts";
|
|
730
652
|
var typeMap = {
|
|
731
|
-
BOOLEAN:
|
|
732
|
-
NUMBER_RAW:
|
|
733
|
-
NUMBER_PERCENT:
|
|
734
|
-
NUMBER_CURRENCY:
|
|
735
|
-
NUMBER_DATETIME:
|
|
736
|
-
NUMBER_DATE:
|
|
737
|
-
NUMBER_TIME:
|
|
653
|
+
BOOLEAN: FieldValueType.Boolean,
|
|
654
|
+
NUMBER_RAW: FieldValueType.Number,
|
|
655
|
+
NUMBER_PERCENT: FieldValueType.Percent,
|
|
656
|
+
NUMBER_CURRENCY: FieldValueType.Currency,
|
|
657
|
+
NUMBER_DATETIME: FieldValueType.DateTime,
|
|
658
|
+
NUMBER_DATE: FieldValueType.Date,
|
|
659
|
+
NUMBER_TIME: FieldValueType.Time
|
|
738
660
|
};
|
|
739
661
|
var getTopLeft = (range) => {
|
|
740
662
|
const to = range.to ?? range.from;
|
|
@@ -1205,15 +1127,7 @@ var SheetModel = class extends Resource {
|
|
|
1205
1127
|
}
|
|
1206
1128
|
};
|
|
1207
1129
|
|
|
1208
|
-
// packages/plugins/plugin-sheet/src/hooks/useFormattingModel.ts
|
|
1209
|
-
var useFormattingModel = (model) => {
|
|
1210
|
-
return useMemo(() => model && new FormattingModel(model), [
|
|
1211
|
-
model
|
|
1212
|
-
]);
|
|
1213
|
-
};
|
|
1214
|
-
|
|
1215
1130
|
// packages/plugins/plugin-sheet/src/hooks/useSheetModel.ts
|
|
1216
|
-
import { useEffect as useEffect2, useState as useState2 } from "react";
|
|
1217
1131
|
var useSheetModel = (graph, sheet, { readonly } = {}) => {
|
|
1218
1132
|
const [model, setModel] = useState2();
|
|
1219
1133
|
useEffect2(() => {
|
|
@@ -1242,7 +1156,7 @@ var useSheetModel = (graph, sheet, { readonly } = {}) => {
|
|
|
1242
1156
|
|
|
1243
1157
|
// packages/plugins/plugin-sheet/src/hooks/threads.ts
|
|
1244
1158
|
import { effect } from "@preact/signals-core";
|
|
1245
|
-
import { useCallback, useEffect as useEffect3, useMemo
|
|
1159
|
+
import { useCallback, useEffect as useEffect3, useMemo } from "react";
|
|
1246
1160
|
import { LayoutAction, useIntentDispatcher, useIntentResolver } from "@dxos/app-framework";
|
|
1247
1161
|
import { debounce as debounce2 } from "@dxos/async";
|
|
1248
1162
|
import { fullyQualifiedId } from "@dxos/react-client/echo";
|
|
@@ -1267,11 +1181,11 @@ var useUpdateFocusedCellOnThreadSelection = (model, grid) => {
|
|
|
1267
1181
|
};
|
|
1268
1182
|
var useSelectThreadOnCellFocus = (model, cursor) => {
|
|
1269
1183
|
const dispatch = useIntentDispatcher();
|
|
1270
|
-
const activeThreads =
|
|
1184
|
+
const activeThreads = useMemo(() => model.sheet.threads?.filter((thread) => !!thread && thread.status === "active") ?? [], [
|
|
1271
1185
|
// TODO(thure): Surely we can find a better dependency for this…
|
|
1272
1186
|
JSON.stringify(model.sheet.threads)
|
|
1273
1187
|
]);
|
|
1274
|
-
const activeThreadAddresses =
|
|
1188
|
+
const activeThreadAddresses = useMemo(() => activeThreads.map((thread) => thread.anchor).filter((anchor) => anchor !== void 0).map((anchor) => addressFromIndex(model.sheet, anchor)), [
|
|
1275
1189
|
activeThreads,
|
|
1276
1190
|
model.sheet
|
|
1277
1191
|
]);
|
|
@@ -1299,7 +1213,7 @@ var useSelectThreadOnCellFocus = (model, cursor) => {
|
|
|
1299
1213
|
activeThreadAddresses,
|
|
1300
1214
|
model.sheet
|
|
1301
1215
|
]);
|
|
1302
|
-
const debounced =
|
|
1216
|
+
const debounced = useMemo(() => {
|
|
1303
1217
|
return debounce2((cellCoords) => requestAnimationFrame(() => selectClosestThread(cellCoords)), 50);
|
|
1304
1218
|
}, [
|
|
1305
1219
|
selectClosestThread
|
|
@@ -1324,10 +1238,10 @@ var createThreadDecoration = (cellIndex, threadId, sheetId) => {
|
|
|
1324
1238
|
};
|
|
1325
1239
|
};
|
|
1326
1240
|
var useThreadDecorations = (model, decorations) => {
|
|
1327
|
-
const sheet =
|
|
1241
|
+
const sheet = useMemo(() => model.sheet, [
|
|
1328
1242
|
model.sheet
|
|
1329
1243
|
]);
|
|
1330
|
-
const sheetId =
|
|
1244
|
+
const sheetId = useMemo(() => fullyQualifiedId(sheet), [
|
|
1331
1245
|
sheet
|
|
1332
1246
|
]);
|
|
1333
1247
|
useEffect3(() => {
|
|
@@ -1361,7 +1275,7 @@ var useThreadDecorations = (model, decorations) => {
|
|
|
1361
1275
|
};
|
|
1362
1276
|
|
|
1363
1277
|
// packages/plugins/plugin-sheet/src/components/SheetContext/SheetContext.tsx
|
|
1364
|
-
import React2, { createContext as createContext2, useContext, useMemo as
|
|
1278
|
+
import React2, { createContext as createContext2, useContext, useMemo as useMemo2, useState as useState3 } from "react";
|
|
1365
1279
|
import { invariant as invariant4 } from "@dxos/invariant";
|
|
1366
1280
|
import { fullyQualifiedId as fullyQualifiedId2 } from "@dxos/react-client/echo";
|
|
1367
1281
|
import { Grid, useGridContext } from "@dxos/react-ui-grid";
|
|
@@ -1371,7 +1285,7 @@ var useSheetContext = () => {
|
|
|
1371
1285
|
const context = useContext(SheetContext);
|
|
1372
1286
|
invariant4(context, void 0, {
|
|
1373
1287
|
F: __dxlog_file3,
|
|
1374
|
-
L:
|
|
1288
|
+
L: 45,
|
|
1375
1289
|
S: void 0,
|
|
1376
1290
|
A: [
|
|
1377
1291
|
"context",
|
|
@@ -1380,9 +1294,9 @@ var useSheetContext = () => {
|
|
|
1380
1294
|
});
|
|
1381
1295
|
return context;
|
|
1382
1296
|
};
|
|
1383
|
-
var SheetProviderImpl = ({ model,
|
|
1297
|
+
var SheetProviderImpl = ({ model, onInfo, children, __gridScope }) => {
|
|
1384
1298
|
const { id, editing, setEditing } = useGridContext("SheetProvider", __gridScope);
|
|
1385
|
-
const decorations =
|
|
1299
|
+
const decorations = useMemo2(() => createDecorations(), []);
|
|
1386
1300
|
const [cursor, setCursor] = useState3();
|
|
1387
1301
|
const [range, setRange] = useState3();
|
|
1388
1302
|
useSelectThreadOnCellFocus(model, cursor);
|
|
@@ -1391,7 +1305,6 @@ var SheetProviderImpl = ({ model, formatting, onInfo, children, __gridScope }) =
|
|
|
1391
1305
|
value: {
|
|
1392
1306
|
id,
|
|
1393
1307
|
model,
|
|
1394
|
-
formatting,
|
|
1395
1308
|
editing,
|
|
1396
1309
|
setEditing,
|
|
1397
1310
|
cursor,
|
|
@@ -1408,12 +1321,10 @@ var SheetProvider = ({ children, graph, sheet, readonly, onInfo }) => {
|
|
|
1408
1321
|
const model = useSheetModel(graph, sheet, {
|
|
1409
1322
|
readonly
|
|
1410
1323
|
});
|
|
1411
|
-
|
|
1412
|
-
return !model || !formatting ? null : /* @__PURE__ */ React2.createElement(Grid.Root, {
|
|
1324
|
+
return !model ? null : /* @__PURE__ */ React2.createElement(Grid.Root, {
|
|
1413
1325
|
id: fullyQualifiedId2(sheet)
|
|
1414
1326
|
}, /* @__PURE__ */ React2.createElement(SheetProviderImpl, {
|
|
1415
1327
|
model,
|
|
1416
|
-
formatting,
|
|
1417
1328
|
onInfo
|
|
1418
1329
|
}, children));
|
|
1419
1330
|
};
|
|
@@ -1454,17 +1365,19 @@ var sheetColDefault = {
|
|
|
1454
1365
|
}
|
|
1455
1366
|
};
|
|
1456
1367
|
var GridSheet = () => {
|
|
1457
|
-
const { id, model,
|
|
1368
|
+
const { id, model, editing, setEditing, setCursor, setRange } = useSheetContext();
|
|
1458
1369
|
const dxGrid = useRef(null);
|
|
1459
1370
|
const rangeNotifier = useRef();
|
|
1460
1371
|
const { hasAttention } = useAttention(id);
|
|
1461
1372
|
const handleFocus = useCallback2((event) => {
|
|
1462
1373
|
if (!editing) {
|
|
1463
1374
|
const cell = closestCell(event.target);
|
|
1464
|
-
|
|
1465
|
-
|
|
1466
|
-
|
|
1467
|
-
|
|
1375
|
+
if (cell && cell.plane === "grid") {
|
|
1376
|
+
setCursor({
|
|
1377
|
+
col: cell.col,
|
|
1378
|
+
row: cell.row
|
|
1379
|
+
});
|
|
1380
|
+
}
|
|
1468
1381
|
}
|
|
1469
1382
|
}, [
|
|
1470
1383
|
editing
|
|
@@ -1534,8 +1447,8 @@ var GridSheet = () => {
|
|
|
1534
1447
|
}, [
|
|
1535
1448
|
hasAttention
|
|
1536
1449
|
]);
|
|
1537
|
-
const { columns, rows } = useSheetModelDxGridProps(dxGrid, model
|
|
1538
|
-
const extension =
|
|
1450
|
+
const { columns, rows } = useSheetModelDxGridProps(dxGrid, model);
|
|
1451
|
+
const extension = useMemo3(() => [
|
|
1539
1452
|
editorKeys({
|
|
1540
1453
|
onClose: handleClose,
|
|
1541
1454
|
...editing?.initialContent && {
|
|
@@ -1580,7 +1493,7 @@ var GridSheet = () => {
|
|
|
1580
1493
|
};
|
|
1581
1494
|
|
|
1582
1495
|
// packages/plugins/plugin-sheet/src/components/index.ts
|
|
1583
|
-
var SheetContainer = React4.lazy(() => import("./SheetContainer-
|
|
1496
|
+
var SheetContainer = React4.lazy(() => import("./SheetContainer-YWQVKHQB.mjs"));
|
|
1584
1497
|
|
|
1585
1498
|
// packages/plugins/plugin-sheet/src/hooks/useComputeGraph.ts
|
|
1586
1499
|
var useComputeGraph = (space) => {
|
|
@@ -1602,6 +1515,7 @@ export {
|
|
|
1602
1515
|
ComputeGraphContextProvider,
|
|
1603
1516
|
addressToA1Notation,
|
|
1604
1517
|
rangeToA1Notation,
|
|
1518
|
+
inRange,
|
|
1605
1519
|
createSheet,
|
|
1606
1520
|
addressToIndex,
|
|
1607
1521
|
compareIndexPositions,
|
|
@@ -1612,4 +1526,4 @@ export {
|
|
|
1612
1526
|
GridSheet,
|
|
1613
1527
|
SheetContainer
|
|
1614
1528
|
};
|
|
1615
|
-
//# sourceMappingURL=chunk-
|
|
1529
|
+
//# sourceMappingURL=chunk-BPXXIAOQ.mjs.map
|