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

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (96) hide show
  1. package/dist/lib/browser/{SheetContainer-LG77O4RM.mjs → SheetContainer-XBTEYQ6T.mjs} +4 -4
  2. package/dist/lib/browser/{chunk-QILRZNE5.mjs → chunk-D3QTX46O.mjs} +4 -5
  3. package/dist/lib/browser/chunk-D3QTX46O.mjs.map +7 -0
  4. package/dist/lib/browser/{chunk-CHQAW4F4.mjs → chunk-NA6NLHDE.mjs} +117 -260
  5. package/dist/lib/browser/chunk-NA6NLHDE.mjs.map +7 -0
  6. package/dist/lib/browser/{chunk-WZMOZKQZ.mjs → chunk-NZBWHQSR.mjs} +21 -25
  7. package/dist/lib/browser/chunk-NZBWHQSR.mjs.map +7 -0
  8. package/dist/lib/browser/index.mjs +8 -17
  9. package/dist/lib/browser/index.mjs.map +4 -4
  10. package/dist/lib/browser/meta.json +1 -1
  11. package/dist/lib/browser/meta.mjs +1 -1
  12. package/dist/lib/browser/types.mjs +4 -8
  13. package/dist/lib/node/{SheetContainer-OZ7DHH4L.cjs → SheetContainer-HSRYKV52.cjs} +16 -16
  14. package/dist/lib/node/{chunk-BNARJ5GM.cjs → chunk-QIFIGEKV.cjs} +6 -7
  15. package/dist/lib/node/chunk-QIFIGEKV.cjs.map +7 -0
  16. package/dist/lib/node/{chunk-5FTFZL5W.cjs → chunk-UXH6GKEU.cjs} +61 -202
  17. package/dist/lib/node/chunk-UXH6GKEU.cjs.map +7 -0
  18. package/dist/lib/node/{chunk-AOP42UAA.cjs → chunk-XYGN3RTG.cjs} +27 -33
  19. package/dist/lib/node/chunk-XYGN3RTG.cjs.map +7 -0
  20. package/dist/lib/node/index.cjs +29 -37
  21. package/dist/lib/node/index.cjs.map +4 -4
  22. package/dist/lib/node/meta.cjs +3 -3
  23. package/dist/lib/node/meta.cjs.map +1 -1
  24. package/dist/lib/node/meta.json +1 -1
  25. package/dist/lib/node/types.cjs +8 -12
  26. package/dist/lib/node/types.cjs.map +2 -2
  27. package/dist/lib/node-esm/{SheetContainer-4XS2G25Z.mjs → SheetContainer-Q4PHM7ZE.mjs} +4 -4
  28. package/dist/lib/node-esm/{chunk-RR2AO4SM.mjs → chunk-GH33JLIW.mjs} +21 -25
  29. package/dist/lib/node-esm/chunk-GH33JLIW.mjs.map +7 -0
  30. package/dist/lib/node-esm/{chunk-KK3XL37M.mjs → chunk-J2KAVUQA.mjs} +117 -260
  31. package/dist/lib/node-esm/chunk-J2KAVUQA.mjs.map +7 -0
  32. package/dist/lib/node-esm/{chunk-IU2L277A.mjs → chunk-VCYJWE3O.mjs} +4 -5
  33. package/dist/lib/node-esm/chunk-VCYJWE3O.mjs.map +7 -0
  34. package/dist/lib/node-esm/index.mjs +8 -17
  35. package/dist/lib/node-esm/index.mjs.map +4 -4
  36. package/dist/lib/node-esm/meta.json +1 -1
  37. package/dist/lib/node-esm/meta.mjs +1 -1
  38. package/dist/lib/node-esm/types.mjs +4 -8
  39. package/dist/types/src/components/GridSheet/GridSheet.d.ts.map +1 -1
  40. package/dist/types/src/components/{CellEditor/CellEditor.stories.d.ts → GridSheet/SheetCellEditor.stories.d.ts} +2 -2
  41. package/dist/types/src/components/GridSheet/SheetCellEditor.stories.d.ts.map +1 -0
  42. package/dist/types/src/components/GridSheet/util.d.ts +2 -2
  43. package/dist/types/src/components/GridSheet/util.d.ts.map +1 -1
  44. package/dist/types/src/components/Sheet/Sheet.d.ts.map +1 -1
  45. package/dist/types/src/components/Sheet/Sheet.stories.d.ts.map +1 -1
  46. package/dist/types/src/extensions/editor/extension.d.ts.map +1 -0
  47. package/dist/types/src/extensions/editor/extension.test.d.ts.map +1 -0
  48. package/dist/types/src/extensions/editor/index.d.ts +2 -0
  49. package/dist/types/src/extensions/editor/index.d.ts.map +1 -0
  50. package/dist/types/src/extensions/index.d.ts +1 -0
  51. package/dist/types/src/extensions/index.d.ts.map +1 -1
  52. package/dist/types/src/meta.d.ts +3 -6
  53. package/dist/types/src/meta.d.ts.map +1 -1
  54. package/dist/types/src/model/formatting-model.d.ts +3 -0
  55. package/dist/types/src/model/formatting-model.d.ts.map +1 -1
  56. package/dist/types/src/model/sheet-model.d.ts +3 -2
  57. package/dist/types/src/model/sheet-model.d.ts.map +1 -1
  58. package/dist/types/src/types.d.ts +4 -20
  59. package/dist/types/src/types.d.ts.map +1 -1
  60. package/package.json +36 -34
  61. package/src/components/GridSheet/GridSheet.tsx +14 -32
  62. package/src/components/{CellEditor/CellEditor.stories.tsx → GridSheet/SheetCellEditor.stories.tsx} +2 -2
  63. package/src/components/GridSheet/util.ts +2 -6
  64. package/src/components/Sheet/Sheet.stories.tsx +4 -3
  65. package/src/components/Sheet/Sheet.tsx +2 -8
  66. package/src/{components/CellEditor → extensions/editor}/index.ts +0 -1
  67. package/src/extensions/index.ts +1 -0
  68. package/src/{meta.tsx → meta.ts} +3 -3
  69. package/src/model/formatting-model.ts +11 -8
  70. package/src/model/sheet-model.test.ts +1 -3
  71. package/src/model/sheet-model.ts +13 -11
  72. package/src/types.ts +8 -35
  73. package/dist/lib/browser/chunk-CHQAW4F4.mjs.map +0 -7
  74. package/dist/lib/browser/chunk-QILRZNE5.mjs.map +0 -7
  75. package/dist/lib/browser/chunk-WZMOZKQZ.mjs.map +0 -7
  76. package/dist/lib/node/chunk-5FTFZL5W.cjs.map +0 -7
  77. package/dist/lib/node/chunk-AOP42UAA.cjs.map +0 -7
  78. package/dist/lib/node/chunk-BNARJ5GM.cjs.map +0 -7
  79. package/dist/lib/node-esm/chunk-IU2L277A.mjs.map +0 -7
  80. package/dist/lib/node-esm/chunk-KK3XL37M.mjs.map +0 -7
  81. package/dist/lib/node-esm/chunk-RR2AO4SM.mjs.map +0 -7
  82. package/dist/types/src/components/CellEditor/CellEditor.d.ts +0 -34
  83. package/dist/types/src/components/CellEditor/CellEditor.d.ts.map +0 -1
  84. package/dist/types/src/components/CellEditor/CellEditor.stories.d.ts.map +0 -1
  85. package/dist/types/src/components/CellEditor/extension.d.ts.map +0 -1
  86. package/dist/types/src/components/CellEditor/extension.test.d.ts.map +0 -1
  87. package/dist/types/src/components/CellEditor/index.d.ts +0 -3
  88. package/dist/types/src/components/CellEditor/index.d.ts.map +0 -1
  89. package/src/components/CellEditor/CellEditor.tsx +0 -163
  90. /package/dist/lib/browser/{SheetContainer-LG77O4RM.mjs.map → SheetContainer-XBTEYQ6T.mjs.map} +0 -0
  91. /package/dist/lib/node/{SheetContainer-OZ7DHH4L.cjs.map → SheetContainer-HSRYKV52.cjs.map} +0 -0
  92. /package/dist/lib/node-esm/{SheetContainer-4XS2G25Z.mjs.map → SheetContainer-Q4PHM7ZE.mjs.map} +0 -0
  93. /package/dist/types/src/{components/CellEditor → extensions/editor}/extension.d.ts +0 -0
  94. /package/dist/types/src/{components/CellEditor → extensions/editor}/extension.test.d.ts +0 -0
  95. /package/src/{components/CellEditor → extensions/editor}/extension.test.ts +0 -0
  96. /package/src/{components/CellEditor → extensions/editor}/extension.ts +0 -0
@@ -1,163 +0,0 @@
1
- //
2
- // Copyright 2024 DXOS.org
3
- //
4
-
5
- import { type Extension } from '@codemirror/state';
6
- import { EditorView, keymap } from '@codemirror/view';
7
- import React, { type DOMAttributes, type KeyboardEvent } from 'react';
8
-
9
- import { useThemeContext } from '@dxos/react-ui';
10
- import {
11
- type UseTextEditorProps,
12
- createBasicExtensions,
13
- createThemeExtensions,
14
- preventNewline,
15
- useTextEditor,
16
- } from '@dxos/react-ui-editor';
17
- import { type GridEditBox } from '@dxos/react-ui-grid';
18
-
19
- type EditorKeyEvent = Pick<KeyboardEvent<HTMLInputElement>, 'key'> & { shift?: boolean };
20
-
21
- export type EditorKeysProps = {
22
- onClose: (value: string | undefined, event: EditorKeyEvent) => void;
23
- onNav?: (value: string | undefined, event: EditorKeyEvent) => void;
24
- };
25
-
26
- export const editorKeys = ({ onNav, onClose }: EditorKeysProps): Extension => {
27
- return keymap.of([
28
- {
29
- key: 'ArrowUp',
30
- run: (editor) => {
31
- const value = editor.state.doc.toString();
32
- onNav?.(value, { key: 'ArrowUp' });
33
- return !!onNav;
34
- },
35
- },
36
- {
37
- key: 'ArrowDown',
38
- run: (editor) => {
39
- const value = editor.state.doc.toString();
40
- onNav?.(value, { key: 'ArrowDown' });
41
- return !!onNav;
42
- },
43
- },
44
- {
45
- key: 'ArrowLeft',
46
- run: (editor) => {
47
- const value = editor.state.doc.toString();
48
- onNav?.(value, { key: 'ArrowLeft' });
49
- return !!onNav;
50
- },
51
- },
52
- {
53
- key: 'ArrowRight',
54
- run: (editor) => {
55
- const value = editor.state.doc.toString();
56
- onNav?.(value, { key: 'ArrowRight' });
57
- return !!onNav;
58
- },
59
- },
60
- {
61
- key: 'Enter',
62
- run: (editor) => {
63
- onClose(editor.state.doc.toString(), { key: 'Enter' });
64
- return true;
65
- },
66
- shift: (editor) => {
67
- onClose(editor.state.doc.toString(), { key: 'Enter', shift: true });
68
- return true;
69
- },
70
- },
71
- {
72
- key: 'Tab',
73
- run: (editor) => {
74
- onClose(editor.state.doc.toString(), { key: 'Tab' });
75
- return true;
76
- },
77
- shift: (editor) => {
78
- onClose(editor.state.doc.toString(), { key: 'Tab', shift: true });
79
- return true;
80
- },
81
- },
82
- {
83
- key: 'Escape',
84
- run: () => {
85
- onClose(undefined, { key: 'Escape' });
86
- return true;
87
- },
88
- },
89
- ]);
90
- };
91
-
92
- export type CellEditorProps = {
93
- value?: string;
94
- extension?: Extension;
95
- variant?: keyof typeof editorVariants;
96
- box?: GridEditBox;
97
- gridId?: string;
98
- } & Pick<UseTextEditorProps, 'autoFocus'> &
99
- Pick<DOMAttributes<HTMLInputElement>, 'onBlur' | 'onKeyDown'>;
100
-
101
- const editorVariants = {
102
- // TODO(thure): remove when legacy is no longer used.
103
- legacy: {
104
- root: 'flex w-full',
105
- editor: 'flex w-full [&>.cm-scroller]:scrollbar-none',
106
- content: '!px-2 !py-1',
107
- },
108
- grid: {
109
- root: 'absolute z-[1]',
110
- editor: '[&>.cm-scroller]:scrollbar-none tabular-nums',
111
- content: '!border !border-transparent !p-0.5',
112
- },
113
- };
114
-
115
- export const CellEditor = ({
116
- value,
117
- extension,
118
- autoFocus,
119
- onBlur,
120
- variant = 'legacy',
121
- box,
122
- gridId,
123
- }: CellEditorProps) => {
124
- const { themeMode } = useThemeContext();
125
- const { parentRef } = useTextEditor(() => {
126
- return {
127
- autoFocus,
128
- initialValue: value,
129
- selection: { anchor: value?.length ?? 0 },
130
- extensions: [
131
- extension ?? [],
132
- preventNewline,
133
- EditorView.focusChangeEffect.of((_, focusing) => {
134
- if (!focusing) {
135
- onBlur?.({ type: 'blur' } as any);
136
- }
137
- return null;
138
- }),
139
- createBasicExtensions({ lineWrapping: false }),
140
- createThemeExtensions({
141
- themeMode,
142
- slots: {
143
- editor: {
144
- className: editorVariants[variant].editor,
145
- },
146
- content: {
147
- className: editorVariants[variant].content,
148
- },
149
- },
150
- }),
151
- ],
152
- };
153
- }, [extension, autoFocus, value, variant, onBlur]);
154
-
155
- return (
156
- <div
157
- ref={parentRef}
158
- className={editorVariants[variant].root}
159
- style={box}
160
- {...(gridId && { 'data-grid': gridId })}
161
- />
162
- );
163
- };