@open-document/core 0.6.0 → 0.8.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/dist/{build-BvIHtePO.js → build-CFL7nhz0.js} +1 -1
- package/dist/{check-BqEdVH7G.js → check-pEQh4jJE.js} +3 -3
- package/dist/cli/bin.js +6 -6
- package/dist/{config-B7vFf9qZ.js → config-4nz5NnxW.js} +593 -137
- package/dist/{context-BaUE_aqU.js → context-BH8C-dSW.js} +1 -1
- package/dist/{dev-DXG-Dg-y.js → dev-BCSUczXW.js} +1 -1
- package/dist/{export-CT1Axnjv.js → export-BQ-GvMsb.js} +3 -3
- package/dist/{import-C8ZC4R6T.js → import-Daat3L2J.js} +2 -2
- package/dist/index.d.ts +21 -3
- package/dist/index.js +40 -9
- package/dist/ops/index.d.ts +47 -3
- package/dist/ops/index.js +3 -3
- package/dist/{ops-ByclxTfk.js → ops-DQfckiyp.js} +2 -45
- package/dist/{preview-CdmWbaHy.js → preview-CwCrw-i3.js} +1 -1
- package/dist/vite/index.js +1 -1
- package/package.json +1 -1
- package/src/app/components/data-table.tsx +17 -2
- package/src/app/components/design-panel/design-panel.tsx +149 -274
- package/src/app/components/design-panel/design-provider.tsx +35 -15
- package/src/app/components/footnote.tsx +27 -10
- package/src/app/components/history-provider.tsx +125 -0
- package/src/app/components/inspector/inspector.tsx +1149 -208
- package/src/app/components/numbering.tsx +13 -1
- package/src/app/components/panel/edit-save-card.tsx +112 -0
- package/src/app/components/panel/fields.tsx +247 -0
- package/src/app/components/panel/panel-shell.tsx +71 -0
- package/src/app/components/panel/save-card.tsx +146 -0
- package/src/app/lib/footnotes.ts +6 -3
- package/src/app/lib/href.ts +14 -0
- package/src/app/lib/inspector/inline-edit.test.ts +244 -0
- package/src/app/lib/inspector/inline-edit.ts +770 -0
- package/src/app/lib/source-loc.ts +15 -0
- package/src/app/lib/view-mode.test.ts +46 -0
- package/src/app/lib/view-mode.ts +76 -0
- package/src/app/routes/doc.tsx +206 -48
- package/src/app/styles.css +41 -0
|
@@ -0,0 +1,244 @@
|
|
|
1
|
+
import { describe, expect, it } from 'vitest';
|
|
2
|
+
import {
|
|
3
|
+
cleanRun,
|
|
4
|
+
clearFormatting,
|
|
5
|
+
hasMark,
|
|
6
|
+
holdSpaces,
|
|
7
|
+
hrefOf,
|
|
8
|
+
isRunDirty,
|
|
9
|
+
linkAt,
|
|
10
|
+
mapSegmentText,
|
|
11
|
+
matchRanges,
|
|
12
|
+
mergeSegments,
|
|
13
|
+
setHref,
|
|
14
|
+
spliceSegments,
|
|
15
|
+
toggleMark,
|
|
16
|
+
} from './inline-edit.ts';
|
|
17
|
+
|
|
18
|
+
const text = (value: string) => ({ text: value, inline: true });
|
|
19
|
+
const mark = (value: string) => ({ text: value, inline: true });
|
|
20
|
+
const markup = (value: string) => ({ text: value, inline: false });
|
|
21
|
+
|
|
22
|
+
describe('matchRanges', () => {
|
|
23
|
+
it('pairs runs with text nodes, stepping over separators and markup', () => {
|
|
24
|
+
// `{agency} {kind}` renders three text nodes; the ideographic space is
|
|
25
|
+
// whitespace and never part of a run.
|
|
26
|
+
const parts = [
|
|
27
|
+
{ index: 0, value: '範例市政府' },
|
|
28
|
+
{ index: 1, value: '函' },
|
|
29
|
+
];
|
|
30
|
+
expect(matchRanges(parts, [text('範例市政府'), text(' '), text('函')])).toEqual([
|
|
31
|
+
[0, 0],
|
|
32
|
+
[2, 2],
|
|
33
|
+
]);
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
it('gathers text and bare marks into one run', () => {
|
|
37
|
+
const parts = [{ index: 0, value: 'Use real h1/h2 elements' }];
|
|
38
|
+
expect(
|
|
39
|
+
matchRanges(parts, [text('Use real '), mark('h1'), text('/'), mark('h2'), text(' elements')]),
|
|
40
|
+
).toEqual([[0, 4]]);
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
it('keeps runs apart at markup that is not a bare mark', () => {
|
|
44
|
+
const parts = [
|
|
45
|
+
{ index: 0, value: 'before' },
|
|
46
|
+
{ index: 1, value: 'after' },
|
|
47
|
+
];
|
|
48
|
+
expect(matchRanges(parts, [text('before '), markup('x'), text(' after')])).toEqual([
|
|
49
|
+
[0, 0],
|
|
50
|
+
[2, 2],
|
|
51
|
+
]);
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
it('steps over text the source cannot claim', () => {
|
|
55
|
+
// `{count} items`, where the count is computed: its text node is not a run.
|
|
56
|
+
const parts = [{ index: 0, value: 'items' }];
|
|
57
|
+
expect(matchRanges(parts, [text('3'), text(' items')])).toEqual([[1, 1]]);
|
|
58
|
+
});
|
|
59
|
+
|
|
60
|
+
it('matches across JSX line collapsing', () => {
|
|
61
|
+
const parts = [{ index: 0, value: 'Availability held\n above target.' }];
|
|
62
|
+
expect(matchRanges(parts, [text('Availability held above target.')])).toEqual([[0, 0]]);
|
|
63
|
+
});
|
|
64
|
+
|
|
65
|
+
it('refuses when the rendered text is not what the source says', () => {
|
|
66
|
+
expect(matchRanges([{ index: 0, value: 'Title' }], [text('TITLE')])).toBeNull();
|
|
67
|
+
});
|
|
68
|
+
|
|
69
|
+
it('keeps runs in document order', () => {
|
|
70
|
+
const parts = [
|
|
71
|
+
{ index: 0, value: 'b' },
|
|
72
|
+
{ index: 1, value: 'a' },
|
|
73
|
+
];
|
|
74
|
+
expect(matchRanges(parts, [text('a'), markup('-'), text('b')])).toBeNull();
|
|
75
|
+
});
|
|
76
|
+
});
|
|
77
|
+
|
|
78
|
+
describe('cleanRun', () => {
|
|
79
|
+
it('turns the browser’s non-breaking spaces back into spaces', () => {
|
|
80
|
+
expect(cleanRun('a b', 'a b')).toBe('a b');
|
|
81
|
+
});
|
|
82
|
+
|
|
83
|
+
it('trims edges a trimmed source run never had', () => {
|
|
84
|
+
expect(cleanRun('端點是 ', '對外端點為')).toBe('端點是');
|
|
85
|
+
});
|
|
86
|
+
|
|
87
|
+
it('keeps edge whitespace a run really holds', () => {
|
|
88
|
+
expect(cleanRun(' indented\n', ' code\n')).toBe(' indented\n');
|
|
89
|
+
});
|
|
90
|
+
});
|
|
91
|
+
|
|
92
|
+
describe('isRunDirty', () => {
|
|
93
|
+
it('ignores whitespace-only differences', () => {
|
|
94
|
+
expect(isRunDirty('Editable heading ', 'Editable heading')).toBe(false);
|
|
95
|
+
expect(isRunDirty('Edited heading', 'Editable heading')).toBe(true);
|
|
96
|
+
});
|
|
97
|
+
});
|
|
98
|
+
|
|
99
|
+
describe('holdSpaces', () => {
|
|
100
|
+
it('keeps a trailing space from collapsing while the next word is typed', () => {
|
|
101
|
+
expect(holdSpaces('Rewritten ')).toBe('Rewritten\u00a0');
|
|
102
|
+
expect(cleanRun(`${holdSpaces('Rewritten ')}heading`, 'Editable heading')).toBe(
|
|
103
|
+
'Rewritten heading',
|
|
104
|
+
);
|
|
105
|
+
});
|
|
106
|
+
|
|
107
|
+
it('holds runs of spaces and leading spaces, not single inner ones', () => {
|
|
108
|
+
expect(holdSpaces(' a b c')).toBe('\u00a0a \u00a0b c');
|
|
109
|
+
});
|
|
110
|
+
});
|
|
111
|
+
|
|
112
|
+
describe('segments', () => {
|
|
113
|
+
const plain = [{ text: 'Executive summary' }];
|
|
114
|
+
|
|
115
|
+
it('bolds a range and splits the run around it', () => {
|
|
116
|
+
expect(toggleMark(plain, 10, 17, 'bold')).toEqual([
|
|
117
|
+
{ text: 'Executive ' },
|
|
118
|
+
{ text: 'summary', bold: true },
|
|
119
|
+
]);
|
|
120
|
+
});
|
|
121
|
+
|
|
122
|
+
it('takes the mark off when the whole range already has it', () => {
|
|
123
|
+
const bolded = toggleMark(plain, 10, 17, 'bold');
|
|
124
|
+
expect(toggleMark(bolded, 10, 17, 'bold')).toEqual(plain);
|
|
125
|
+
});
|
|
126
|
+
|
|
127
|
+
it('adds the mark when only part of the range has it', () => {
|
|
128
|
+
const bolded = toggleMark(plain, 10, 17, 'bold');
|
|
129
|
+
expect(hasMark(bolded, 5, 17, 'bold')).toBe(false);
|
|
130
|
+
expect(toggleMark(bolded, 5, 17, 'bold')).toEqual([
|
|
131
|
+
{ text: 'Execu' },
|
|
132
|
+
{ text: 'tive summary', bold: true },
|
|
133
|
+
]);
|
|
134
|
+
});
|
|
135
|
+
|
|
136
|
+
it('keeps bold and italic independent', () => {
|
|
137
|
+
const both = toggleMark(toggleMark(plain, 0, 9, 'bold'), 5, 9, 'italic');
|
|
138
|
+
expect(both).toEqual([
|
|
139
|
+
{ text: 'Execu', bold: true },
|
|
140
|
+
{ text: 'tive', bold: true, italic: true },
|
|
141
|
+
{ text: ' summary' },
|
|
142
|
+
]);
|
|
143
|
+
});
|
|
144
|
+
|
|
145
|
+
it('continues the emphasis of the character before the caret', () => {
|
|
146
|
+
const bolded = toggleMark(plain, 10, 17, 'bold');
|
|
147
|
+
expect(spliceSegments(bolded, 17, 17, '!')).toEqual([
|
|
148
|
+
{ text: 'Executive ' },
|
|
149
|
+
{ text: 'summary!', bold: true },
|
|
150
|
+
]);
|
|
151
|
+
expect(spliceSegments(bolded, 10, 10, 'x')).toEqual([
|
|
152
|
+
{ text: 'Executive x' },
|
|
153
|
+
{ text: 'summary', bold: true },
|
|
154
|
+
]);
|
|
155
|
+
});
|
|
156
|
+
|
|
157
|
+
it('keeps the formatting of the words a selection replaces', () => {
|
|
158
|
+
const bolded = toggleMark(plain, 10, 17, 'bold');
|
|
159
|
+
expect(spliceSegments(bolded, 10, 17, 'digest')).toEqual([
|
|
160
|
+
{ text: 'Executive ' },
|
|
161
|
+
{ text: 'digest', bold: true },
|
|
162
|
+
]);
|
|
163
|
+
});
|
|
164
|
+
|
|
165
|
+
it('deletes across pieces and merges what is left', () => {
|
|
166
|
+
const bolded = toggleMark(plain, 10, 17, 'bold');
|
|
167
|
+
expect(spliceSegments(bolded, 9, 17, '')).toEqual([{ text: 'Executive' }]);
|
|
168
|
+
});
|
|
169
|
+
|
|
170
|
+
it('counts UTF-16 units, as DOM offsets do', () => {
|
|
171
|
+
// The emoji is two units; the selection's offsets for "ab" are 2–4.
|
|
172
|
+
expect(toggleMark([{ text: '😀ab' }], 2, 4, 'bold')).toEqual([
|
|
173
|
+
{ text: '😀' },
|
|
174
|
+
{ text: 'ab', bold: true },
|
|
175
|
+
]);
|
|
176
|
+
});
|
|
177
|
+
|
|
178
|
+
it('rewrites text across piece boundaries without moving them', () => {
|
|
179
|
+
const pieces = [{ text: 'a ' }, { text: ' b', bold: true }];
|
|
180
|
+
expect(mapSegmentText(pieces, holdSpaces)).toEqual([
|
|
181
|
+
{ text: 'a ' },
|
|
182
|
+
{ text: '\u00a0b', bold: true },
|
|
183
|
+
]);
|
|
184
|
+
});
|
|
185
|
+
|
|
186
|
+
it('drops empty pieces and joins equal neighbours', () => {
|
|
187
|
+
expect(mergeSegments([{ text: 'a' }, { text: '' }, { text: 'b' }])).toEqual([{ text: 'ab' }]);
|
|
188
|
+
});
|
|
189
|
+
});
|
|
190
|
+
|
|
191
|
+
describe('code, links and clearing', () => {
|
|
192
|
+
const plain = [{ text: 'See the guide now' }];
|
|
193
|
+
|
|
194
|
+
it('toggles code like any other mark', () => {
|
|
195
|
+
expect(toggleMark(plain, 8, 13, 'code')).toEqual([
|
|
196
|
+
{ text: 'See the ' },
|
|
197
|
+
{ text: 'guide', code: true },
|
|
198
|
+
{ text: ' now' },
|
|
199
|
+
]);
|
|
200
|
+
});
|
|
201
|
+
|
|
202
|
+
it('links a range, and finds the whole link from a caret inside it', () => {
|
|
203
|
+
const linked = setHref(plain, 4, 13, '/guide');
|
|
204
|
+
expect(linked).toEqual([
|
|
205
|
+
{ text: 'See ' },
|
|
206
|
+
{ text: 'the guide', href: '/guide' },
|
|
207
|
+
{ text: ' now' },
|
|
208
|
+
]);
|
|
209
|
+
expect(linkAt(linked, 6)).toEqual({ from: 4, to: 13, href: '/guide' });
|
|
210
|
+
expect(linkAt(linked, 13)).toEqual({ from: 4, to: 13, href: '/guide' });
|
|
211
|
+
expect(linkAt(linked, 2)).toBeNull();
|
|
212
|
+
expect(hrefOf(linked, 4, 13)).toBe('/guide');
|
|
213
|
+
expect(hrefOf(linked, 2, 13)).toBeNull();
|
|
214
|
+
});
|
|
215
|
+
|
|
216
|
+
it('unlinks with a null href', () => {
|
|
217
|
+
const linked = setHref(plain, 4, 13, '/guide');
|
|
218
|
+
expect(setHref(linked, 4, 13, null)).toEqual(plain);
|
|
219
|
+
});
|
|
220
|
+
|
|
221
|
+
it('does not extend a link when typing just past its end', () => {
|
|
222
|
+
const linked = setHref(plain, 4, 13, '/guide');
|
|
223
|
+
expect(spliceSegments(linked, 13, 13, 's')).toEqual([
|
|
224
|
+
{ text: 'See ' },
|
|
225
|
+
{ text: 'the guide', href: '/guide' },
|
|
226
|
+
{ text: 's now' },
|
|
227
|
+
]);
|
|
228
|
+
// Inside the link, typing stays in it.
|
|
229
|
+
expect(spliceSegments(linked, 8, 8, 'x')).toEqual([
|
|
230
|
+
{ text: 'See ' },
|
|
231
|
+
{ text: 'the xguide', href: '/guide' },
|
|
232
|
+
{ text: ' now' },
|
|
233
|
+
]);
|
|
234
|
+
});
|
|
235
|
+
|
|
236
|
+
it('clears every kind of formatting from the range only', () => {
|
|
237
|
+
const busy = toggleMark(setHref(toggleMark(plain, 0, 17, 'bold'), 4, 13, '/g'), 8, 13, 'code');
|
|
238
|
+
expect(clearFormatting(busy, 4, 13)).toEqual([
|
|
239
|
+
{ text: 'See ', bold: true },
|
|
240
|
+
{ text: 'the guide' },
|
|
241
|
+
{ text: ' now', bold: true },
|
|
242
|
+
]);
|
|
243
|
+
});
|
|
244
|
+
});
|