@xlsx-editor.dev/react 0.0.0-placeholder.0 → 0.1.0-beta.0
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/LICENSE +201 -0
- package/README.md +219 -2
- package/THIRD_PARTY_NOTICES.md +6 -0
- package/dist/index.d.ts +576 -0
- package/dist/index.js +2597 -0
- package/docs/editing-cells.md +180 -0
- package/docs/formatting-and-structure.md +85 -0
- package/docs/layout-and-props.md +141 -0
- package/docs/sheets-clipboard-and-sizes.md +94 -0
- package/docs/toolbar-and-keyboard.md +449 -0
- package/docs/view-mode-and-protection.md +35 -0
- package/package.json +56 -6
- package/src/styles/editor.css +3 -0
- package/src/styles/editor.css.d.ts +2 -0
|
@@ -0,0 +1,449 @@
|
|
|
1
|
+
# Toolbar and keyboard
|
|
2
|
+
|
|
3
|
+
This guide describes the toolbar of `@xlsx-editor.dev/react` and the keyboard of the editor. For setup and the component props, see the [package README](../README.md).
|
|
4
|
+
|
|
5
|
+
## Toolbar
|
|
6
|
+
|
|
7
|
+
`XlsxEditor` shows a toolbar over the grid. To get the workbook when the user selects **Save** in the toolbar, pass `onSave`. It receives the workbook as bytes of the kind that was opened: `snapshot().workbookKind` is `workbook` or `template`, so you can choose the file extension. With `onSave`, Control or Command and S in the editor also saves, also when you hide the save control. Without `onSave`, the save control is disabled, and the browser keeps the shortcut:
|
|
8
|
+
|
|
9
|
+
<!-- sample: guide-on-save -->
|
|
10
|
+
|
|
11
|
+
```tsx
|
|
12
|
+
<XlsxEditor
|
|
13
|
+
document={bytes}
|
|
14
|
+
onSave={(edited, saved) => {
|
|
15
|
+
if (saved.stillOpen) upload(edited);
|
|
16
|
+
}}
|
|
17
|
+
style={{ height: 600 }}
|
|
18
|
+
/>
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
The bytes arrive after the press, because the save runs in short tasks. A press during a running save of the same revision joins that save, so `onSave` runs once. `saved.stillOpen` is `false` when another open, `close()`, or `destroy()` ended the workbook during the save. `saved.revision` is the revision that the bytes hold, so an edit made during the save stays unsaved. When saves of different revisions overlap, `onSave` never receives older bytes after newer bytes.
|
|
22
|
+
|
|
23
|
+
A browser opens a file dialog only soon after a user action. The bytes of a large workbook can arrive after that time, and `showSaveFilePicker` then rejects with a `SecurityError`. If this happens, keep the bytes and ask the user to select a control of your own, and open the dialog from that press.
|
|
24
|
+
|
|
25
|
+
In your own layout, place `XlsxEditor.Toolbar` inside `XlsxEditor.Viewport`. It takes these props:
|
|
26
|
+
|
|
27
|
+
| Prop | Type | Default | What it does |
|
|
28
|
+
| --- | --- | --- | --- |
|
|
29
|
+
| `onSave` | `(bytes: Uint8Array<ArrayBuffer>, saved: SavedWorkbook) => void` | none | Receives the workbook bytes of the save control, and of Control or Command and S in the editor, also with the save control hidden. Without it, the save control is disabled, and the browser keeps the shortcut. A refused save calls nothing. Check `saved.stillOpen` before you store the bytes: it is `false` when the workbook on screen is no longer the one that was saved. |
|
|
30
|
+
| `onSaveStart` | `(saving: Promise<SavedWorkbook \| null>) => void` | none | Called once when a press of the save control, or of Control or Command and S in the editor, starts a delivery to `onSave`. It gets the promise of the result, so you can show that the save runs. A press that joins the running save of an earlier press and a refused save do not call it. A press that joins a save from `saveInTasks` calls it, because that save has no delivery yet. The promise resolves to `null` when the save is refused later. |
|
|
31
|
+
| `opening` | `boolean` | `false` | Tells the toolbar that your page opens another workbook while the editor still shows the old one, for example during a download or a file read before `load`. While it is `true`, the save control is disabled with the reason that a workbook is loading, and Control or Command and S in the editor starts no save work. After such a press, and only then, the snapshot holds the refusal `loading`, with `command: 'save'`. A press reads the value of the latest render. When the prop changes to `false`, the toolbar forgets that refusal and keeps any other refusal. |
|
|
32
|
+
| `overflow` | `boolean` | `true` | Keeps the toolbar on one row and moves the groups that do not fit into the **More** panel. `false` wraps the controls onto more rows. It has no effect with `preset={false}`. |
|
|
33
|
+
| `hidden` | `ChromeSlotId[]` | `[]` | The slots to leave out. A group whose slots are all hidden is left out. It has no effect with `preset={false}`. |
|
|
34
|
+
| `preset` | `boolean` | `true` | `false` renders only the children, in their order, with no measure and no **More** panel. |
|
|
35
|
+
| `children` | `ReactNode` | none | Parts that change the toolbar. See [Toolbar parts](#toolbar-parts). |
|
|
36
|
+
| `className` | `string` | none | Added after the `xlsx-toolbar` class. |
|
|
37
|
+
|
|
38
|
+
To leave out the history group and the save control:
|
|
39
|
+
|
|
40
|
+
<!-- sample: guide-hidden-slots -->
|
|
41
|
+
|
|
42
|
+
```tsx
|
|
43
|
+
<XlsxEditor.Toolbar hidden={['history.undo', 'history.redo', 'file.save']} />
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
The toolbar shows the groups of `CHROME_GROUPS` in this order. Each slot id is the group id and the control id:
|
|
47
|
+
|
|
48
|
+
| Group | Slot ids |
|
|
49
|
+
| --- | --- |
|
|
50
|
+
| History | `history.undo`, `history.redo` |
|
|
51
|
+
| Font | `font.family`, `font.size`, `font.bold`, `font.italic`, `font.underline`, `font.color` |
|
|
52
|
+
| Fill | `fill.color` |
|
|
53
|
+
| Borders | `borders.outline`, `borders.all`, `borders.none` |
|
|
54
|
+
| Alignment | `alignment.left`, `alignment.center`, `alignment.right`, `alignment.top`, `alignment.middle`, `alignment.bottom`, `alignment.wrap` |
|
|
55
|
+
| Number format | `number.format`, `number.custom`, `number.increaseDecimals`, `number.decreaseDecimals` |
|
|
56
|
+
| Insert and delete (one menu) | `cells.insertRows`, `cells.insertColumns`, `cells.deleteRows`, `cells.deleteColumns` |
|
|
57
|
+
| Clear (one menu) | `clear.contents`, `clear.formats`, `clear.all` |
|
|
58
|
+
| File | `file.save` |
|
|
59
|
+
|
|
60
|
+
A control with the `dialog` shape in `CHROME_GROUPS`, such as `number.custom`, opens a dialog. Its `execute` needs the value that the dialog produces, so render it as a dialog opener, not as a plain button.
|
|
61
|
+
|
|
62
|
+
The font size list also takes a typed size from 1 to 409 points. A number format that is not in the list shows as `Custom:` and its format code.
|
|
63
|
+
|
|
64
|
+
The number format list has these entries: General, Number, Currency, Accounting, Percentage, Scientific, Fraction, Short date, Long date, Time, and Text. An entry with a built-in id of ECMA-376 Part 1, 18.8.30, writes that id. If the workbook gives the id another code, the entry writes the code of the id in the number locale instead. Currency (`"$"#,##0.00`) and Accounting take the currency symbol from `numberLocale.currencySymbol`. The symbol goes before the number in every number locale. Long date writes `dddd, mmmm d, yyyy` in every number locale, with English day and month names.
|
|
65
|
+
|
|
66
|
+
A code that differs from an entry only in its decimal places shows the entry's name, such as Percentage for `0.0%`. The list marks that entry as current, not as picked. A pick of the current entry writes the code of that entry: Percentage on a `0.000%` cell writes `0.00%`. On one cell or one merged range that already shows the picked entry, a pick writes nothing and adds no undo step.
|
|
67
|
+
|
|
68
|
+
The Number entry has no thousands separator, so the list shows built-in ids 3 (`#,##0`) and 4 (`#,##0.00`) as Custom. An entry shows only its name, with no title, so a screen reader does not read its code. The accessible name and the title of the closed list give the name and the decimal places, such as "Percentage, 1 decimal place", but never the code of an entry.
|
|
69
|
+
|
|
70
|
+
To build your own list, call `numberFormatListView(value, t, snapshot.numberLocale)` of `@xlsx-editor.dev/core/editor`, which `@xlsx-editor.dev/react` also exports. Pass the `value` of `useEditorCommand('number.format')`. The result holds the translated `entries`, the `text` of the closed list, the `name` for its accessible name and title, and the `current` entry. The toolbar list shows itself from the same function.
|
|
71
|
+
|
|
72
|
+
### Decimal places
|
|
73
|
+
|
|
74
|
+
`number.increaseDecimals` and `number.decreaseDecimals` add or remove one decimal place in each number section of the code. The other parts of the code stay the same: sections, colors, conditions, literals, the text section, and the exponent. A decrease removes the decimal point with the last place, so `0.` steps up to `0.0` and back to `0`. These rules apply to the code:
|
|
75
|
+
|
|
76
|
+
- In the zero section of a code with three or more sections, a run of `?` can follow a quoted literal or a dash. Such a run, as `"-"??` in the Accounting code, pads the literal. A step adds or removes one `?` there, and no decimal point.
|
|
77
|
+
- With a literal other than a dash, or with no fill, a decrease to no places removes the last `?` of that padding. An increase does not add it back. This is the known approximation `decimal-padding`.
|
|
78
|
+
- A run of `?` before a quoted literal, as `??" kg"`, steps as a number.
|
|
79
|
+
- A literal or a second point can split the places, as in `0.00" "0`. A step can then move a place to the other side of the literal. This is the known approximation `decimal-split-places`.
|
|
80
|
+
- A step does not change a date or time, text, a fraction, or a General section with a color, a condition, a literal, or other sections.
|
|
81
|
+
- A cell keeps its format when the step would make a comma scale the number. It also keeps it when the step would add or remove a group separator. So `0.00,0` does not step down.
|
|
82
|
+
- A cell with a control character in its code keeps its format, and so does a cell whose new code would be longer than 255 characters. The other selected cells step.
|
|
83
|
+
- An increase stops at 30 places in a section.
|
|
84
|
+
|
|
85
|
+
On General, a step writes one place more or one place less than the grid shows for the number in the cell. A narrow column shows fewer places, such as `3.141593` for 3.14159265358. If the grid shows the number in exponent form, such as `1E+20`, the step writes a scientific code, such as `0.0E+00`. With no text measurer, or when the cell shows only `#`, the step reads the General text at full width. Such a cell can still show only `#` after the step, until the column is wide enough. On one empty General cell, an increase writes `0.0`, and creates the cell when it has no `x:c` element.
|
|
86
|
+
|
|
87
|
+
On a selection, each selected cell steps from its own number format, in one undo step. These rules apply:
|
|
88
|
+
|
|
89
|
+
- A cell whose code cannot change keeps its format, so a selection of a date and a number changes only the number.
|
|
90
|
+
- A cell that holds text, a boolean, or an error does not step. If no selected cell holds a number, both controls are disabled.
|
|
91
|
+
- A date cell (`t="d"`) steps from the serial number that the grid shows for it. A `t="d"` value that the editor cannot read shows as text, so it does not step.
|
|
92
|
+
- Among more cells, an empty cell keeps its format, and so does an empty position. One empty cell steps from its own code.
|
|
93
|
+
- A merged range steps as its top-left cell.
|
|
94
|
+
- Every General number of a column takes the step of the first General number of that column. So the column lines up. The first is the active cell in its own column, and else the first in row order. A General number in exponent form steps alone.
|
|
95
|
+
|
|
96
|
+
The step reads only the cells that exist, at most 16,384 inside the selection. On a whole column, a cell that you create later takes the column format, which the step does not change. The number format list has no such limit. Like the other format commands, it is refused only when it would create more than 16,384 new cells.
|
|
97
|
+
|
|
98
|
+
After a step or a number format change, the live region says the new text of the active cell. On a selection of more than one cell, it first says that the decimal places or the number format changed. A number format change that also commits typed text is the exception: the live region then says only the new text of the active cell. If the text stays the same, or changes only in its spaces, the live region says only that the decimal places or the number format changed.
|
|
99
|
+
|
|
100
|
+
If no selected cell can step, the control is disabled, and the command is refused with `decimals-unchanged`. Past 16,384 cells that exist, it is refused with `decimals-too-large`. The refusal holds the disabled reason of the control in `reason`. For `decimals-unchanged`, `refusalText` shows that reason. For `decimals-too-large`, it shows the cell limit.
|
|
101
|
+
|
|
102
|
+
The reason names the problem of the active cell when it holds a number, and else the problem of the first selected cell with a number. It speaks of the cell when `selectionSingle` is `true`, and else of a selected cell.
|
|
103
|
+
|
|
104
|
+
While a cell edit holds changed text, both controls are disabled with `editPending`, and the command is refused with `edit-pending`. This differs from Bold and the number format list, which commit the typed text first. The difference is deliberate. A step reads the stored format of each cell. The commit of typed text can change that format, such as `12%` on a General cell. So you commit or cancel the edit, and then see what the step changes.
|
|
105
|
+
|
|
106
|
+
To step from your own control, call `useEditorCommand('number.increaseDecimals').execute()`. A host with no React calls `runToolbarCommand(editor, 'number.increaseDecimals')` of `@xlsx-editor.dev/core/editor`. The step has no method on the editor instance. It is a toolbar command, as indent is in DOCX Editor's command map, and the command keeps its state and its refusals in one place.
|
|
107
|
+
|
|
108
|
+
#### Decimal step state in your own chrome
|
|
109
|
+
|
|
110
|
+
To show why a decimal step is disabled, render the control from `useEditorCommand('number.increaseDecimals')`. Use `isEnabled` for the disabled state, and show `disabledReason`, which is already translated. A host with no React reads `toolbarCommandState(snapshot, 'number.increaseDecimals').disabledReason` of `@xlsx-editor.dev/core/editor`, and translates it with `disabledReasonText(reason, t)`.
|
|
111
|
+
|
|
112
|
+
To get the code that a list entry writes, call `numberFormatChoiceCode(value, locale)`. To get the list value of `activeFormat.numberFormat`, call `numberFormatValue(format, snapshot.numberLocale)`. A value that is no entry starts with `CUSTOM_NUMBER_FORMAT_PREFIX`.
|
|
113
|
+
|
|
114
|
+
### Number format dialog
|
|
115
|
+
|
|
116
|
+
The last item of the number format list, **More number formats…**, opens the number format dialog of the `number.custom` slot. If you pass `hidden={['number.format']}`, the slot shows as its own button. In the dialog, type a format code (ECMA-376 Part 1, 18.8.31), or pick one of the custom codes of the workbook. The preview shows the active cell's value through the code, as the grid would show it. If the active cell is empty, the preview shows a sample number. If the editor cannot apply the code, the dialog shows the reason, marks the field invalid, and **Apply** changes nothing.
|
|
117
|
+
|
|
118
|
+
**Apply** sets the number format of the selection in one undo step. On one cell, an **Apply** of the code that the dialog opened with changes nothing, so the cell keeps its format. A new code gets a custom number format from id 164, and a code that the workbook already holds uses its id. A code equal to a built-in code is written as the built-in id, so the cell shows the number locale's code for that id, as the preview does.
|
|
119
|
+
|
|
120
|
+
To apply a code from your own control, pass it to `useEditorCommand('number.custom').execute(code)`. To show why a code cannot be applied before you call `execute`, call `numberFormatCodeProblem(code)`. To build your own number format dialog, use the functions that the toolbar dialog uses. `@xlsx-editor.dev/react` exports each of them:
|
|
121
|
+
|
|
122
|
+
1. In the event handler that opens the dialog, call `numberFormatDialogStart(editor)`, and keep the result as `start`. It commits an open cell edit, so do not call it during render. Keep that object itself: for a copy, `numberFormatDialogApplyStep` returns `closed`. It gives the code to show first in `start.initial`. If it returns `null`, the slot is disabled or the commit is refused: do not open the dialog.
|
|
123
|
+
|
|
124
|
+
Render your opener from `useEditorCommand('number.custom')`, disabled when `isEnabled` is `false` and with `disabledReason` as its reason. Then a `null` start means a refused commit: show `refusalText(snapshot.refusal, t, snapshot.numberLocale)`, or keep `XlsxEditor.StatusMessage` in the layout.
|
|
125
|
+
|
|
126
|
+
1. To list the custom codes of the workbook, call `workbookNumberFormatCodes(editor)` once for each change of the editor state, such as in a `useMemo` keyed on `useEditorSnapshot()`, not for each key. It lists at most `MAX_LISTED_NUMBER_FORMATS` codes. The codes come from the file: show them as text only.
|
|
127
|
+
1. As the user types, call `previewNumberFormat(editor, code)`. If `ok` is `false`, show its `problem`; it has no `text`. Otherwise show `text`. If `stale` is `true`, the value is a formula result that an edit can have changed: show it with `t('grid.staleResult', { text })`.
|
|
128
|
+
|
|
129
|
+
If the active cell is empty, the preview formats `NUMBER_FORMAT_SAMPLE` and sets `sample`. If the code has a color, `color` holds it as `RRGGBB` from the engine's palette. A rich text cell shows its stored text for every code.
|
|
130
|
+
|
|
131
|
+
1. Open the dialog as a native `dialog` element with `showModal()`, as the sample does. The browser moves focus into it, keeps Tab in it, sends `cancel` on Escape, and returns focus to the opener when it closes. Give the element `aria-modal="true"`: then Control or Command and S in it does not save the workbook. If you build the dialog from another element, focus its first control, keep Tab in it with `trapTabWithin(dialog, event)` on `keydown`, and close it on Escape.
|
|
132
|
+
1. While the dialog is open, close it when `numberFormatDialogCurrent(editor, start)` is `false`: another workbook loaded, the selection moved, the number locale changed, or the slot is disabled. Read it with `useEditorState`: the selector reads the editor, and `useEditorState` calls it again on each change of the editor state.
|
|
133
|
+
1. On **Apply**, call `numberFormatDialogApplyStep(editor, start, code)`, and act on its `kind`. For `closed` and `unchanged`, close the dialog. For `apply`, run `execute(code)`, and close the dialog when it returns `true`. If it returns `false`, the editor refused the edit: show `refusalText(snapshot.refusal, t, snapshot.numberLocale)`, or keep `XlsxEditor.StatusMessage` in the layout. For `problem`, keep the dialog open.
|
|
134
|
+
|
|
135
|
+
To show a problem, translate its key with its parameters. Each key is in `NUMBER_FORMAT_CODE_PROBLEM_KEYS` and in the catalog of `@xlsx-editor.dev/i18n`.
|
|
136
|
+
|
|
137
|
+
The following sample is a minimal dialog component with the close check and the **Apply** step. It leaves out the preview and the list of steps 2 and 3. `start` comes from step 1, and the opener passes `close`, a function from `useCallback`:
|
|
138
|
+
|
|
139
|
+
<!-- sample: guide-number-format-dialog -->
|
|
140
|
+
|
|
141
|
+
```tsx
|
|
142
|
+
import { useCallback, useEffect, useLayoutEffect, useRef, useState } from 'react';
|
|
143
|
+
import {
|
|
144
|
+
numberFormatDialogApplyStep,
|
|
145
|
+
numberFormatDialogCurrent,
|
|
146
|
+
refusalText,
|
|
147
|
+
useEditorCommand,
|
|
148
|
+
useEditorState,
|
|
149
|
+
useTranslation,
|
|
150
|
+
useXlsxEditor,
|
|
151
|
+
type NumberFormatDialogStart,
|
|
152
|
+
} from '@xlsx-editor.dev/react';
|
|
153
|
+
|
|
154
|
+
function NumberFormatHostDialog({
|
|
155
|
+
start,
|
|
156
|
+
close,
|
|
157
|
+
}: {
|
|
158
|
+
start: NumberFormatDialogStart;
|
|
159
|
+
close: () => void;
|
|
160
|
+
}) {
|
|
161
|
+
const editor = useXlsxEditor()!;
|
|
162
|
+
const { t } = useTranslation();
|
|
163
|
+
const command = useEditorCommand('number.custom');
|
|
164
|
+
const [code, setCode] = useState(start.initial);
|
|
165
|
+
const [error, setError] = useState<string | null>(null);
|
|
166
|
+
const ref = useRef<HTMLDialogElement>(null);
|
|
167
|
+
// The browser focuses the field, keeps Tab in the dialog, and returns focus on close.
|
|
168
|
+
useLayoutEffect(() => {
|
|
169
|
+
const dialog = ref.current!;
|
|
170
|
+
dialog.showModal();
|
|
171
|
+
return () => dialog.close();
|
|
172
|
+
}, []);
|
|
173
|
+
const current = useEditorState(
|
|
174
|
+
useCallback(() => numberFormatDialogCurrent(editor, start), [editor, start])
|
|
175
|
+
);
|
|
176
|
+
useEffect(() => {
|
|
177
|
+
if (!current) close();
|
|
178
|
+
}, [current, close]);
|
|
179
|
+
function apply() {
|
|
180
|
+
const step = numberFormatDialogApplyStep(editor, start, code);
|
|
181
|
+
if (step.kind === 'problem') {
|
|
182
|
+
setError(t(step.problem.key, step.problem.params));
|
|
183
|
+
} else if (step.kind !== 'apply' || command.execute(code)) {
|
|
184
|
+
close();
|
|
185
|
+
} else {
|
|
186
|
+
// The editor refused the edit: show its reason.
|
|
187
|
+
const snapshot = editor.snapshot();
|
|
188
|
+
setError(
|
|
189
|
+
snapshot.refusal
|
|
190
|
+
? refusalText(snapshot.refusal, t, snapshot.numberLocale)
|
|
191
|
+
: t('dialogs.numberFormat.notApplied')
|
|
192
|
+
);
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
return (
|
|
196
|
+
<dialog
|
|
197
|
+
ref={ref}
|
|
198
|
+
aria-modal="true"
|
|
199
|
+
aria-label={t('dialogs.numberFormat.title')}
|
|
200
|
+
onCancel={(e) => {
|
|
201
|
+
e.preventDefault();
|
|
202
|
+
close();
|
|
203
|
+
}}
|
|
204
|
+
>
|
|
205
|
+
<input
|
|
206
|
+
aria-label={t('dialogs.numberFormat.code')}
|
|
207
|
+
value={code}
|
|
208
|
+
onChange={(e) => setCode(e.currentTarget.value)}
|
|
209
|
+
/>
|
|
210
|
+
{error ? <p role="alert">{error}</p> : null}
|
|
211
|
+
<button type="button" onClick={apply}>
|
|
212
|
+
{t('common.apply')}
|
|
213
|
+
</button>
|
|
214
|
+
</dialog>
|
|
215
|
+
);
|
|
216
|
+
}
|
|
217
|
+
```
|
|
218
|
+
|
|
219
|
+
The `value` of `number.custom` is `General` for a built-in id that has no code in the editor's number locale. If you send that value back through `execute`, the cells change to the `General` format: on a range, the dialog's **Apply** of that unchanged value does the same. A built-in id whose locale code is the value keeps its id.
|
|
220
|
+
|
|
221
|
+
### Control state
|
|
222
|
+
|
|
223
|
+
The toolbar has no state of its own. Each control reads its state from `toolbarCommandState()` of `@xlsx-editor.dev/core/editor`, so the toolbar and your own controls show the same answer. The sheet tabs read the state of the add button and the sheet menu rows from `sheetCommandState()` of the same entry, which `@xlsx-editor.dev/react` also exports. A disabled control shows its label and the engine's reason as its tooltip (`toolbar.disabledTitle`), and the reason as its accessible description. The reasons are keys of the `disabledReason` section of the catalog in `@xlsx-editor.dev/i18n`:
|
|
224
|
+
|
|
225
|
+
- `editorNotReady`: no workbook is open yet.
|
|
226
|
+
- `loading`: a workbook is loading. The save control also takes this reason while the `opening` prop is `true`.
|
|
227
|
+
- `nothingToUndo` and `nothingToRedo`: the history has no step in that direction.
|
|
228
|
+
- `editPending`: the open cell edit has changed text. Its commit would clear the redo steps, and a decimal step would read a format that the commit can change.
|
|
229
|
+
- `rangeTooLarge`: a format command, or a merge and center, would create more than one whole row of new cells.
|
|
230
|
+
- `clearTooLarge`: a clear of formats would create more than one whole row of new cells.
|
|
231
|
+
- `structureBlocked`, `structureBlockedUnnamed`, `structureUnavailable`, and `wholeSheet`: the sheet or the selection refuses an insert or a delete.
|
|
232
|
+
- `noSave`: the toolbar has no `onSave`.
|
|
233
|
+
- `viewMode`: the editor is in view mode.
|
|
234
|
+
- `composing`: an input method composes in the open cell editor, and every control waits for it to finish.
|
|
235
|
+
- `formatLocked`: the sheet is protected, and its protection does not allow formatting cells, so the format and clear-format commands are disabled.
|
|
236
|
+
- `stylesUnread`: the styles part stays as bytes past a read limit, so the format commands and merge and center are disabled. On a sheet that is not protected, Clear formats and Clear all stay enabled, because they give the default format.
|
|
237
|
+
- `stylesUnreadProtected`: the styles part stays as bytes, and the sheet is protected. The protection of each cell is in that part, so Clear formats and Clear all are disabled.
|
|
238
|
+
- `structureLocked`: the sheet is protected, and its protection does not allow the insert or the delete of rows or columns that the command makes.
|
|
239
|
+
- `workbookLocked`: the workbook protection does not allow a sheet add, rename, delete, or move, so `sheetCommandState()` disables them.
|
|
240
|
+
- `mergeLocked`: the sheet is protected, so `mergeCommandState()` disables merge and unmerge.
|
|
241
|
+
- `mergeOneCell`: one cell is selected, so there is nothing to merge.
|
|
242
|
+
- `mergeOverlap`: the selection overlaps a merged range, so a merge waits for an unmerge.
|
|
243
|
+
- `noMergedRange`: the selection has no merged range to unmerge.
|
|
244
|
+
- `lastSheet`: the sheet is the last visible sheet, so `sheetCommandState()` disables Delete.
|
|
245
|
+
- `notWorksheet`: the sheet is not a worksheet, such as a chartsheet or a macro sheet, or its part is missing. `sheetCommandState()` disables Rename, Delete, and both moves of it, and its tab shows the reason.
|
|
246
|
+
- `sheetEditBlocked`: content in the workbook can refer to any sheet. That is a chart, a pivot table, or a sheet that is not a worksheet. It is also a workbook or package relationship outside the allowlist, such as data connections. `sheetCommandState()` then disables Rename and Delete of every sheet, and each worksheet tab shows the reason. The snapshot holds the refusal in `sheetEditRefusal`.
|
|
247
|
+
- `locked`: the sheet is protected, and a locked cell in the selection holds content, so Clear contents and Clear all would change it.
|
|
248
|
+
- The keys that start with `decimals`: no selected cell can take a decimal step. The key names the cause, such as `decimalsDate`. The engine picks the key for the selection, so you show `disabledReason` and never map a cause to a key.
|
|
249
|
+
- `cellAlternateContent`: a cell of the selection holds a value and also holds data in a form that the editor cannot update (`selectionContentBlocked`), so Clear contents and Clear all are disabled.
|
|
250
|
+
- `cellAlternateContentClearAll`: the reason of `cellAlternateContent` for Clear all while Clear formats is enabled. It also points to Clear formats.
|
|
251
|
+
- `formulaRange`: a clear of the selection would change a formula range that the editor cannot rewrite or remove (`selectionFormulaRangeBlocked`), so Clear contents and Clear all are disabled. The clear command gives `shared-formula` for the same selection. A clear that would move the formula of a shared child out of the grid is refused only when it runs, so the field is null for it.
|
|
252
|
+
- `formulaRangeClearAll`: the reason of `formulaRange` for Clear all while Clear formats is enabled. It also points to Clear formats.
|
|
253
|
+
- `formulaCell` and `formulaCellClearAll`: the reasons of `formulaRange` and `formulaRangeClearAll` when one cell's formula blocks the clear of a shared formula master. They name the master to leave out (`selectionFormulaRangeMasterCell`) and the cell whose formula blocks it (`selectionFormulaRangeCauseCell`).
|
|
254
|
+
- `formulaUnreadable` and `formulaUnreadableClearAll`: the reasons of `formulaCell` and `formulaCellClearAll` when the formula of the master cannot be read (`selectionFormulaRangeCauseUnreadable` is `true`).
|
|
255
|
+
- `notWired`: the slot id is not in the registry.
|
|
256
|
+
|
|
257
|
+
An enabled control can also have a `hint` object, whose `key` is a key of the `hint` section of the catalog. The toolbar shows the hint after the label in the tooltip, and as the accessible description. The key `hint.conditionalFormat` means that a true conditional formatting rule shows a different state of this control at the active cell. The control still reads and sets the cell format.
|
|
258
|
+
|
|
259
|
+
The key `hint.decimalsLargeSelection` is on a decimal step when the selection is too large to format. Then the other format controls are disabled with `rangeTooLarge`, and the step still changes the selected cells that hold numbers. When a layout of the grid runs out of its conditional formatting check budget, the notice shows, and no control has this hint until another sheet or workbook shows.
|
|
260
|
+
|
|
261
|
+
If a cell edit holds changed text, undo is available and cancels the edit, as `undo()` on the editor instance does. Redo is not available while the edit holds changed text, with the reason `editPending`, and `redo()` refuses it with `edit-pending`.
|
|
262
|
+
|
|
263
|
+
### Toolbar parts
|
|
264
|
+
|
|
265
|
+
If you build your own layout with `XlsxEditor.Toolbar`, the toolbar takes two kinds of part as its children. `XlsxEditor` renders its own toolbar and does not take parts.
|
|
266
|
+
|
|
267
|
+
- `XlsxEditor.Toolbar.Slot` with a `slotId` replaces that slot with its children, where the slot stands. With `hidden`, it removes the slot and its children, as the `hidden` list does.
|
|
268
|
+
- `XlsxEditor.Toolbar.Group` with a new `id` adds a host group. The bar measures it with its own groups, and moves it into the **More** panel when it does not fit. In the panel, the group shows as a section with its heading: `label`, else the translated `labelKey`, else the `id`. A host group follows every built-in group, or the group that `after` names. A group with a built-in `id`, such as `file`, shows its children after its own controls. With `hidden`, it removes the group and its children.
|
|
269
|
+
|
|
270
|
+
Pass the parts as direct children of the toolbar or of a Fragment. The toolbar does not read a part that a component of your own renders. In the preset bar, such a part shows in the block of other children, so a `Toolbar.Group` there never moves into the **More** panel.
|
|
271
|
+
|
|
272
|
+
The last part for a slot or a group wins. If a slot is in the `hidden` list, the list wins over a `Toolbar.Slot` with children. In a menu group, such as Clear, the replaced slot's content shows after the menu, and the menu keeps the other slots.
|
|
273
|
+
|
|
274
|
+
The bar moves groups into the **More** panel from the end of the bar. A host group with no `after` follows every built-in group, so it moves first. In the panel, the content of a `Toolbar.Slot` and of a `Toolbar.Group` shows in the section of its group.
|
|
275
|
+
|
|
276
|
+
Other children, such as a status text, show in one block after the groups and the **More** button. The block always stays in the bar, and the bar measures the groups in the room that is left.
|
|
277
|
+
|
|
278
|
+
The parts take these props:
|
|
279
|
+
|
|
280
|
+
| Part | Prop | Type | What it does |
|
|
281
|
+
| --- | --- | --- | --- |
|
|
282
|
+
| `Toolbar.Slot` | `slotId` | `ChromeSlotId` | The slot that the part names. Required. |
|
|
283
|
+
| `Toolbar.Slot` | `hidden` | `boolean` | Removes the slot where it stands. |
|
|
284
|
+
| `Toolbar.Slot` | `children` | `ReactNode` | Content that takes the place of the slot. Without children, the part renders the built-in control of the slot. |
|
|
285
|
+
| `Toolbar.Group` | `id` | `string` | A built-in group id, such as `file`, or a new id for a host group. Required. |
|
|
286
|
+
| `Toolbar.Group` | `label` | `string` | The heading of a host group in the **More** panel, and its accessible name. |
|
|
287
|
+
| `Toolbar.Group` | `labelKey` | `string` | A catalog key for the heading, translated with the toolbar's locale. `label` wins over it. |
|
|
288
|
+
| `Toolbar.Group` | `after` | `string` | The id of the group that a host group follows. |
|
|
289
|
+
| `Toolbar.Group` | `hidden` | `boolean` | Removes the group from the bar and from the **More** panel. |
|
|
290
|
+
| `Toolbar.Group` | `className` | `string` | A class after `xlsx-toolbar-group`. The group draws its separator line as `::before`, so the `gap`, `padding`, `border`, and `background` of the class also apply around the line. The built-in line rule has the weight of one class. A `::before` rule of your class overrides the line when it comes after the editor stylesheet. To remove the line, set `content: none`. |
|
|
291
|
+
| `Toolbar.Group` | `children` | `ReactNode` | The controls of the group. A host group with no children is left out. |
|
|
292
|
+
|
|
293
|
+
The following sample replaces the save control, removes the underline control, and adds a host group after the history group:
|
|
294
|
+
|
|
295
|
+
<!-- sample: guide-toolbar-parts -->
|
|
296
|
+
|
|
297
|
+
```tsx
|
|
298
|
+
<XlsxEditor.Toolbar>
|
|
299
|
+
<XlsxEditor.Toolbar.Slot slotId="file.save">
|
|
300
|
+
<SaveToDriveButton />
|
|
301
|
+
</XlsxEditor.Toolbar.Slot>
|
|
302
|
+
<XlsxEditor.Toolbar.Slot slotId="font.underline" hidden />
|
|
303
|
+
<XlsxEditor.Toolbar.Group id="share" label="Share" after="history">
|
|
304
|
+
<ShareButton />
|
|
305
|
+
</XlsxEditor.Toolbar.Group>
|
|
306
|
+
</XlsxEditor.Toolbar>
|
|
307
|
+
```
|
|
308
|
+
|
|
309
|
+
With `preset={false}`, the toolbar renders only its children. There, a `Toolbar.Slot` with no children renders the built-in control of its slot, and a `Toolbar.Group` renders its children as one group. The parts render in the order that you give, so `after` has no effect:
|
|
310
|
+
|
|
311
|
+
<!-- sample: guide-toolbar-own -->
|
|
312
|
+
|
|
313
|
+
```tsx
|
|
314
|
+
<XlsxEditor.Toolbar preset={false}>
|
|
315
|
+
<XlsxEditor.Toolbar.Group id="text" label="Text">
|
|
316
|
+
<XlsxEditor.Toolbar.Slot slotId="font.bold" />
|
|
317
|
+
<XlsxEditor.Toolbar.Slot slotId="font.italic" />
|
|
318
|
+
</XlsxEditor.Toolbar.Group>
|
|
319
|
+
<XlsxEditor.Toolbar.Slot slotId="history.undo" />
|
|
320
|
+
</XlsxEditor.Toolbar>
|
|
321
|
+
```
|
|
322
|
+
|
|
323
|
+
The arrow keys move between the controls of this bar too, as in the preset bar.
|
|
324
|
+
|
|
325
|
+
A `Toolbar.Slot` with no children in a host group places a second copy of a built-in control. To move the control into the host group, also hide its slot with a `Toolbar.Slot` with `hidden`, or with the `hidden` list.
|
|
326
|
+
|
|
327
|
+
In a development build, the toolbar prints a warning once for each part that cannot do what it says. A build is a development build when `import.meta.env.DEV` is `true`, or, where that flag is absent, when `process.env.NODE_ENV` is not `production`. A bundle that sets neither prints no warning. Each warning starts with `[xlsx-editor]`. The toolbar warns about these parts:
|
|
328
|
+
|
|
329
|
+
- A `Toolbar.Slot` whose `slotId` is not a slot of `CHROME_GROUPS`. In the preset bar, its children show in the block of other children.
|
|
330
|
+
- A `Toolbar.Slot` with children whose slot the `hidden` list names.
|
|
331
|
+
- A `Toolbar.Slot` with children whose group is hidden.
|
|
332
|
+
- A `label`, `labelKey`, or `after` on a built-in group.
|
|
333
|
+
- An `after` that names no group, that names its own group, or that leads into a cycle of anchors.
|
|
334
|
+
- An `after` that names a group that stands last because its own anchors name no group.
|
|
335
|
+
|
|
336
|
+
### Controls of your own
|
|
337
|
+
|
|
338
|
+
To place controls of your own anywhere in the layout, call `useEditorCommand(slot)` inside `XlsxEditor.Root`. It returns the same state that the toolbar shows:
|
|
339
|
+
|
|
340
|
+
| Field | Type | What it holds |
|
|
341
|
+
| --- | --- | --- |
|
|
342
|
+
| `execute` | `(value?: string) => boolean` | Runs the command. Pass the picked value of a value slot, such as `'14'` for `font.size`. Returns `true` when the command ran and `false` when the editor refused it. |
|
|
343
|
+
| `isActive` | `boolean` | The command is applied at the active cell, such as bold on a bold cell. |
|
|
344
|
+
| `isEnabled` | `boolean` | The editor runs the command now. |
|
|
345
|
+
| `disabledReason` | `string \| null` | The engine's reason when the command is disabled, translated. |
|
|
346
|
+
| `hint` | `string \| null` | The engine's hint for an enabled command, translated, such as the text of `hint.conditionalFormat`. Null on a disabled command. |
|
|
347
|
+
| `value` | `string \| null` | What a value slot shows, such as the font name, the size in points, or the format code of the active cell for `number.custom`. |
|
|
348
|
+
|
|
349
|
+
The component re-renders only when the state of its slot changes, and the result keeps its identity while its fields are equal:
|
|
350
|
+
|
|
351
|
+
<!-- sample: guide-bold-button -->
|
|
352
|
+
|
|
353
|
+
```tsx
|
|
354
|
+
import { useEditorCommand } from '@xlsx-editor.dev/react';
|
|
355
|
+
|
|
356
|
+
function BoldButton() {
|
|
357
|
+
const bold = useEditorCommand('font.bold');
|
|
358
|
+
return (
|
|
359
|
+
<button
|
|
360
|
+
type="button"
|
|
361
|
+
aria-pressed={bold.isActive}
|
|
362
|
+
aria-disabled={!bold.isEnabled}
|
|
363
|
+
title={bold.disabledReason ?? 'Bold'}
|
|
364
|
+
onMouseDown={(e) => e.preventDefault()}
|
|
365
|
+
onClick={() => bold.execute()}
|
|
366
|
+
>
|
|
367
|
+
Bold
|
|
368
|
+
</button>
|
|
369
|
+
);
|
|
370
|
+
}
|
|
371
|
+
```
|
|
372
|
+
|
|
373
|
+
Inside a toolbar, `file.save` hands the bytes to the toolbar's `onSave`, also in a control of your own that is a toolbar part's content, such as the content of a `Toolbar.Slot`. Outside a toolbar, `file.save` is disabled: call `save()` or `saveInTasks()` on the ref instead.
|
|
374
|
+
|
|
375
|
+
### Toolbar keyboard
|
|
376
|
+
|
|
377
|
+
| Keys | Action |
|
|
378
|
+
| --- | --- |
|
|
379
|
+
| Tab | Move to the next control of the toolbar. Each control is a stop, disabled controls too. |
|
|
380
|
+
| Left arrow, Right arrow, Home, End | Move between the controls of the toolbar, your own controls too. The keys stop at the first and the last control. A key that your control handles and cancels does not move the focus. |
|
|
381
|
+
| Enter, Space, or Down arrow on a list, palette, or menu button | Open it, with the keyboard on the selected item or the first item |
|
|
382
|
+
| Down arrow on an open list | Move the keyboard into it |
|
|
383
|
+
| Up arrow, Down arrow, Home, End | Move between the items of an open list or menu. In a palette, Left arrow and Right arrow move too. |
|
|
384
|
+
| Enter or Space on an item | Apply the item, and return the keyboard to the grid |
|
|
385
|
+
| Escape | Close the list, and return the keyboard to its button |
|
|
386
|
+
|
|
387
|
+
A disabled control keeps the keyboard: pressing it does nothing. A control of your own that cannot take the focus, such as a hidden input or a disabled control, is not a stop. If a control of your own moves the focus on when it gets the focus, for example to a field of its own or to a popup, the focus stays where the control moved it.
|
|
388
|
+
|
|
389
|
+
A field of your own in the toolbar keeps the keys that it needs:
|
|
390
|
+
|
|
391
|
+
- A text field keeps Home and End. It keeps Left arrow and Right arrow until the caret is at that end of the text, or while text is selected.
|
|
392
|
+
- A field whose caret the page cannot read, such as an email or a number field, keeps all four keys.
|
|
393
|
+
- A text area and an editable element keep all four keys.
|
|
394
|
+
- A `<select>` element keeps Home and End.
|
|
395
|
+
- A radio button keeps Left arrow and Right arrow, and a range input (`<input type="range">`) keeps all four keys, because they change the value.
|
|
396
|
+
- A control in an element of your own with the role `dialog` or `menu` keeps all four keys. Move the focus in it yourself. A toolbar inside such an element of your own keeps its keys.
|
|
397
|
+
|
|
398
|
+
To leave a field that keeps a key, press Tab.
|
|
399
|
+
|
|
400
|
+
## Keyboard
|
|
401
|
+
|
|
402
|
+
| Keys | Action |
|
|
403
|
+
| --- | --- |
|
|
404
|
+
| Arrow keys | Move the active cell |
|
|
405
|
+
| Shift and an arrow key | Extend the selection. A selection of whole rows or columns stays whole rows or columns. |
|
|
406
|
+
| Shift and Space | Select the whole rows of the selection |
|
|
407
|
+
| Control or Command and Space | Select the whole columns of the selection |
|
|
408
|
+
| Control or Command and an arrow key | Go to the edge of the data |
|
|
409
|
+
| Tab, Enter, and Shift with them | Move right, down, left, or up |
|
|
410
|
+
| Tab, Enter, and Shift with them, in a selection of more than one cell (a merged cell is one cell) | Move the active cell inside the selection, wrap at its edges, and keep the selection |
|
|
411
|
+
| Shift+Tab in column A, or Tab in the last column | Move the focus out of the grid, to the previous or next control |
|
|
412
|
+
| Escape, then Tab or Shift+Tab | Move the focus out of the grid from any cell, to the next or previous control. If Escape ends a pending copy or cut or cancels a cell edit, press Escape again. Any other key except a modifier key alone, a press anywhere on the page, or a focus change cancels the exit |
|
|
413
|
+
| Page Up, Page Down | Move by one window of rows |
|
|
414
|
+
| Home | Go to column A of the row |
|
|
415
|
+
| Control or Command and Home | Go to cell A1 |
|
|
416
|
+
| Control or Command and End | Go to the last row and column that hold content |
|
|
417
|
+
| Alt and Page Up or Page Down | Show the previous or next sheet |
|
|
418
|
+
| Control or Command and A | Select the whole sheet |
|
|
419
|
+
| Control or Command and `+`, `-`, or `0`, when no whole row or column is selected | Zoom in, zoom out, or reset the zoom |
|
|
420
|
+
| Control or Command and `+` (or Shift and `=`), on whole rows or columns | Insert rows or columns |
|
|
421
|
+
| Control or Command and `-`, on whole rows or columns | Delete the selected rows or columns. Zoom out stays available when no whole row or column is selected. |
|
|
422
|
+
| A character | Start an edit with that character |
|
|
423
|
+
| F2, or a double-click on a cell | Edit the active cell |
|
|
424
|
+
| Backspace | Start an edit with empty text |
|
|
425
|
+
| Enter, Tab, and Shift with them | Commit the edit and move |
|
|
426
|
+
| Escape | Cancel the edit |
|
|
427
|
+
| Control or Command and S | Save, as the save control of the toolbar does, when the toolbar has `onSave`, also with the save control hidden. Only a key in the editor counts, and the editor takes the key from the browser. A refused save shows "The workbook was not saved" with the reason |
|
|
428
|
+
| Control or Command and Z, Control or Command and Shift and Z, or Control and Y, in the cell editor | Undo or redo the typing in the cell editor, as the browser's own text input binds the keys. The keys never cancel the edit and never change the workbook history |
|
|
429
|
+
| Alt and Enter, in the cell editor | Add a line break. Where the browser has no `insertText` command, the line break has no undo step in the cell editor |
|
|
430
|
+
| Delete | Clear the values of the selection |
|
|
431
|
+
| Control or Command and B, I, or U | Toggle bold, italic, or underline |
|
|
432
|
+
| Control or Command and C, X, or V | Copy, cut, or paste the selection |
|
|
433
|
+
| Left arrow, Right arrow, Home, End, on a sheet tab | Show the previous, next, first, or last sheet, and move the focus to its tab |
|
|
434
|
+
| F2 on a sheet tab | Rename the sheet |
|
|
435
|
+
| Shift+F10 or the Menu key on a sheet tab | Open the sheet actions |
|
|
436
|
+
| Control or Command and Z, Control or Command and Shift and Z, or Control or Command and Y, on a sheet tab or on **Add a sheet** | Undo or redo |
|
|
437
|
+
| Control or Command and Z | Undo, with no cell edit open. With an empty history, the editor shows "There is nothing to undo." once |
|
|
438
|
+
| Control or Command and Shift and Z, or Control or Command and Y | Redo, with no cell edit open. With nothing to redo, the editor shows "There is nothing to redo." once |
|
|
439
|
+
| Enter, Tab, and Shift with them, in the formula bar | Commit the edit and move, as in the cell editor. With no open edit, move the active cell |
|
|
440
|
+
| Alt and Enter, in the formula bar | Add a line break |
|
|
441
|
+
| Escape, in the formula bar | Cancel the edit, and return the keyboard to the grid |
|
|
442
|
+
| Enter, in the name box | Select the typed reference, and return the keyboard to the grid |
|
|
443
|
+
| Escape, in the name box | Drop the typed reference, and return the keyboard to the grid |
|
|
444
|
+
| Control or Command and Z, Control or Command and Shift and Z, or Control or Command and Y, in the formula bar or the name box | Undo or redo, with no cell edit open and no typed reference. Otherwise the keys undo or redo the typing in the field |
|
|
445
|
+
| F6, Shift+F6 | Move the keyboard to the next or previous region: the toolbar, the formula bar, the grid, and the footer with the sheet tabs and the zoom control. In the formula bar, an open cell edit commits first. The formula bar region starts at the name box |
|
|
446
|
+
|
|
447
|
+
A press on a cell selects it, and a drag selects the cells that it covers. With Shift, a press or a drag extends the selection from its anchor to the pressed cell, and a press on a row or column heading extends it to whole rows or columns. The active cell stays when the new selection holds it; otherwise the anchor becomes the active cell.
|
|
448
|
+
|
|
449
|
+
On a touch screen, a drag pans the sheet and a tap selects the cell under it. A two-finger pinch does not zoom the grid; use the zoom control. On a trackpad, a pinch zooms as Control and the mouse wheel do. The grid shows a focus ring while it has the keyboard; without the keyboard, the active cell keeps a muted border. The ring color is the `--doc-focus-ring` token, shared with DOCX Editor; its contrast against the chrome is below 3:1, and a change to it is made for the editor family as a whole.
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
# View mode and protection
|
|
2
|
+
|
|
3
|
+
This guide describes view mode, sheet protection, and workbook protection. For setup, see the [package README](../README.md).
|
|
4
|
+
|
|
5
|
+
## View mode
|
|
6
|
+
|
|
7
|
+
To show a workbook without letting the user change it, pass `mode="view"`. The default is `"edit"`. A change of `mode` applies without a reload:
|
|
8
|
+
|
|
9
|
+
<!-- sample: guide-view-mode -->
|
|
10
|
+
|
|
11
|
+
```tsx
|
|
12
|
+
<XlsxEditor document={bytes} mode={canEdit ? 'edit' : 'view'} style={{ height: 600 }} />
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
In view mode, the editor refuses every edit with the reason `view-mode`. Typing, F2, Backspace, Delete, and a double-click open no cell editor. The editing commands of the editor instance return the refusal, and the toolbar disables its edit controls with the reason `viewMode`. The sheet tabs disable the add button and the edit rows of the sheet menu with the same reason, and start no rename. A heading edge starts no resize. Cut and paste are refused with `view-mode`.
|
|
16
|
+
|
|
17
|
+
You can still select cells, copy, switch sheets, zoom, and save. If a cell edit is open when the mode changes to `"view"`, the editor commits it first. If the editor cannot store that edit, it stays in edit mode with the cell editor open and shows the reason. `setMode()` on the editor instance returns `false` in that case.
|
|
18
|
+
|
|
19
|
+
The `mode` prop applies when it changes. A call to `setMode()` on the editor instance stays until the next change of the prop. If the prop change to `"view"` cannot apply, it waits: the status strip shows that view mode waits, and the switch applies when the user commits or cancels the edit. A call to `setMode()` during the wait ends the wait. To show the wait in a layout of your own, read `useViewModeWaits()`, which returns `true` while the switch waits. On the editor instance, call `setMode()`, and read the mode in `snapshot().mode`.
|
|
20
|
+
|
|
21
|
+
## Sheet protection
|
|
22
|
+
|
|
23
|
+
On a protected sheet (`x:sheetProtection` with `sheet` set to true, ECMA-376 Part 1, 18.3.1.85), the editor refuses some edits with the reason `locked`. It refuses a value edit on a locked cell. It refuses a format edit unless the protection allows formatting cells (`formatCells` set to false). A paste that gives a cell another cell format is a format edit. A plain-text paste of a typed form, such as `12%`, is not refused for its format: it stores the number and keeps the cell format. A new cell format that changes the protection of a cell is refused with the rule `cell`, also when the protection allows formatting cells.
|
|
24
|
+
|
|
25
|
+
It refuses a column width unless the protection allows formatting columns (`formatColumns`), and a row height unless it allows formatting rows (`formatRows`). A heading edge whose size the protection does not allow shows no resize edge. It refuses an insert or a delete of rows or columns unless the protection allows it (`insertRows`, `deleteRows`, `insertColumns`, and `deleteColumns`). Each of these attributes is true by default, and true locks the action (`CT_SheetProtection`).
|
|
26
|
+
|
|
27
|
+
A cell is locked unless its cell format unlocks it with `x:protection/@locked` set to false (ECMA-376 Part 1, 18.8.33). A cell format with no protection of its own takes the protection of its cell style. A cell that does not exist takes the format of its row or column. When the protection allows deleting rows or columns, a deletion also deletes locked cells.
|
|
28
|
+
|
|
29
|
+
It refuses a merge or an unmerge of cells with the rule `merge`, whatever the protection allows. A cut is refused when its paste could not clear the source. That is a locked cell that holds content, or a sheet that does not allow formatting cells. The refusal has the command `cut`. A clear of formats keeps whether each cell is locked or hidden. The editor has no paste of values only, so a cut on a sheet that does not allow formatting cells is always refused (`editing.lockedRefused.cutFormats`).
|
|
30
|
+
|
|
31
|
+
Typing on a locked cell opens no cell editor, and the status strip shows that the sheet is protected. The snapshot holds what the protection allows in `protection`, a `SheetProtection`. Its fields are true when an action is allowed: `allowFormatCells`, `allowFormatColumns`, `allowFormatRows`, `allowInsertRows`, `allowDeleteRows`, `allowInsertColumns`, and `allowDeleteColumns`. `activeCellLocked` is true when the active cell is locked. `selectionContentLocked` is true when clearing the selection would change a locked cell that holds content, so Clear contents and Clear all are disabled. The editor does not enforce `protectedRanges`.
|
|
32
|
+
|
|
33
|
+
## Workbook protection
|
|
34
|
+
|
|
35
|
+
When the workbook protection (`x:workbookProtection`, ECMA-376 Part 1, 18.2.29) sets `lockStructure` to true, the editor refuses a sheet add, rename, delete, or move with `locked` and the rule `workbook`. The sheet tabs then disable those actions with the reason `workbookLocked`. The snapshot holds the workbook protection in `workbookProtection`, a `WorkbookProtection` whose `allowStructure` is false then. The `lockStructure` attribute is false by default. The editor never reads or checks the password, and it keeps the protection as the file holds it.
|
package/package.json
CHANGED
|
@@ -1,14 +1,64 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@xlsx-editor.dev/react",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"description": "
|
|
3
|
+
"version": "0.1.0-beta.0",
|
|
4
|
+
"description": "React adapter for XLSX Editor: a provider, hooks, and chrome parts over the @xlsx-editor.dev/core workbook editor.",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"sideEffects": [
|
|
7
|
+
"*.css"
|
|
8
|
+
],
|
|
9
|
+
"exports": {
|
|
10
|
+
".": {
|
|
11
|
+
"types": "./dist/index.d.ts",
|
|
12
|
+
"import": "./dist/index.js"
|
|
13
|
+
},
|
|
14
|
+
"./styles.css": {
|
|
15
|
+
"types": "./src/styles/editor.css.d.ts",
|
|
16
|
+
"default": "./src/styles/editor.css"
|
|
17
|
+
},
|
|
18
|
+
"./package.json": "./package.json"
|
|
19
|
+
},
|
|
20
|
+
"files": [
|
|
21
|
+
"dist",
|
|
22
|
+
"docs",
|
|
23
|
+
"src/styles",
|
|
24
|
+
"README.md",
|
|
25
|
+
"LICENSE",
|
|
26
|
+
"THIRD_PARTY_NOTICES.md",
|
|
27
|
+
"!dist/metafile-*.json"
|
|
28
|
+
],
|
|
29
|
+
"scripts": {
|
|
30
|
+
"build": "node ../../scripts/check-built-siblings.mjs && tsup",
|
|
31
|
+
"typecheck": "bun check",
|
|
32
|
+
"api:extract": "node ../../scripts/api-extractor.mjs --package @xlsx-editor.dev/react --local",
|
|
33
|
+
"api:check": "node ../../scripts/api-extractor.mjs --package @xlsx-editor.dev/react"
|
|
34
|
+
},
|
|
35
|
+
"dependencies": {
|
|
36
|
+
"@xlsx-editor.dev/i18n": "^0.1.0-beta.0"
|
|
37
|
+
},
|
|
38
|
+
"peerDependencies": {
|
|
39
|
+
"@xlsx-editor.dev/core": "~0.1.0-beta.0",
|
|
40
|
+
"react": "^18.0.0 || ^19.0.0",
|
|
41
|
+
"react-dom": "^18.0.0 || ^19.0.0"
|
|
42
|
+
},
|
|
43
|
+
"devDependencies": {
|
|
44
|
+
"@xlsx-editor.dev/core": "workspace:*",
|
|
45
|
+
"typescript7": "npm:typescript@^7.0.2"
|
|
46
|
+
},
|
|
5
47
|
"license": "Apache-2.0",
|
|
48
|
+
"keywords": [
|
|
49
|
+
"xlsx",
|
|
50
|
+
"editor",
|
|
51
|
+
"spreadsheet",
|
|
52
|
+
"workbook",
|
|
53
|
+
"react"
|
|
54
|
+
],
|
|
55
|
+
"homepage": "https://xlsx-editor.dev/",
|
|
6
56
|
"repository": {
|
|
7
57
|
"type": "git",
|
|
8
|
-
"url": "
|
|
58
|
+
"url": "https://github.com/eigenpal/xlsx-editor.git",
|
|
9
59
|
"directory": "packages/react"
|
|
10
60
|
},
|
|
11
|
-
"
|
|
12
|
-
|
|
13
|
-
|
|
61
|
+
"publishConfig": {
|
|
62
|
+
"access": "public"
|
|
63
|
+
}
|
|
14
64
|
}
|