@a3s-lab/office 0.1.0 → 0.2.2

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 (69) hide show
  1. package/README.md +101 -24
  2. package/dist/0~2582.js +485 -0
  3. package/dist/0~4595.js +14 -7
  4. package/dist/0~4750.js +939 -0
  5. package/dist/{0~work-document-paragraph-formatting.js → 0~5861.js} +174 -3
  6. package/dist/0~7048.js +8 -6
  7. package/dist/0~9512.js +7 -4
  8. package/dist/0~document-editor.js +3147 -531
  9. package/dist/0~markdown-editor.js +26 -1
  10. package/dist/0~presentation-editor.js +68 -12
  11. package/dist/0~spreadsheet-editor.js +37 -17
  12. package/dist/0~work-document-extensions.js +588 -13
  13. package/dist/0~work-document-model-codec.js +1 -1
  14. package/dist/0~work-docx-bibliography.js +1 -1
  15. package/dist/0~work-docx-export.js +116 -55
  16. package/dist/0~work-docx-import.js +766 -107
  17. package/dist/0~work-office-diagnostics.js +2 -2
  18. package/dist/{4704.js → 2881.js} +162 -71
  19. package/dist/4104.js +2 -62
  20. package/dist/internal/features/work/editors/document-comment-window.d.ts +37 -0
  21. package/dist/internal/features/work/editors/document-navigation-panel.d.ts +3 -1
  22. package/dist/internal/features/work/editors/document-navigation-window.d.ts +64 -0
  23. package/dist/internal/features/work/editors/document-outline-navigation.d.ts +11 -0
  24. package/dist/internal/features/work/editors/document-page-navigation.d.ts +11 -1
  25. package/dist/internal/features/work/editors/document-page-thumbnail.d.ts +31 -0
  26. package/dist/internal/features/work/editors/document-picture-properties-dialog-model.d.ts +28 -0
  27. package/dist/internal/features/work/editors/document-picture-properties-dialog.d.ts +4 -0
  28. package/dist/internal/features/work/editors/document-search-navigation.d.ts +12 -0
  29. package/dist/internal/features/work/editors/document-table-margins-popover.d.ts +4 -0
  30. package/dist/internal/features/work/editors/document-table-properties-dialog-model.d.ts +51 -0
  31. package/dist/internal/features/work/editors/document-table-properties-dialog-sections.d.ts +19 -0
  32. package/dist/internal/features/work/editors/document-table-properties-dialog.d.ts +8 -0
  33. package/dist/internal/features/work/editors/office-task-pane.d.ts +1 -1
  34. package/dist/internal/features/work/editors/presentation-chart-panel.d.ts +2 -1
  35. package/dist/internal/features/work/editors/presentation-comments-panel.d.ts +2 -1
  36. package/dist/internal/features/work/editors/spreadsheet-workbook-panel.d.ts +2 -1
  37. package/dist/internal/features/work/editors/use-document-pagination.d.ts +6 -0
  38. package/dist/internal/features/work/editors/use-presentation-review-commands.d.ts +1 -1
  39. package/dist/internal/features/work/work-document-image-layout.d.ts +11 -0
  40. package/dist/internal/features/work/work-document-page-capture.d.ts +15 -0
  41. package/dist/internal/features/work/work-document-paragraph-formatting.d.ts +4 -0
  42. package/dist/internal/features/work/work-document-section.d.ts +3 -1
  43. package/dist/internal/features/work/work-document-table-borders.d.ts +20 -0
  44. package/dist/internal/features/work/work-document-table-cell-formatting.d.ts +8 -5
  45. package/dist/internal/features/work/work-document-table-geometry.d.ts +41 -0
  46. package/dist/internal/features/work/work-document-table-property-changes.d.ts +25 -0
  47. package/dist/internal/features/work/work-document-table-sizing.d.ts +15 -2
  48. package/dist/internal/features/work/work-document-word-line-metrics.d.ts +11 -0
  49. package/dist/internal/features/work/work-docx-document-layout.d.ts +2 -0
  50. package/dist/internal/features/work/work-docx-paragraph-alignment-import.d.ts +2 -1
  51. package/dist/internal/features/work/work-docx-paragraph-direction-import.d.ts +2 -1
  52. package/dist/internal/features/work/work-docx-paragraph-indent-import.d.ts +2 -1
  53. package/dist/internal/features/work/work-docx-paragraph-pagination-import.d.ts +2 -1
  54. package/dist/internal/features/work/work-docx-paragraph-spacing-import.d.ts +3 -2
  55. package/dist/internal/features/work/work-docx-paragraph-styles.d.ts +2 -2
  56. package/dist/internal/features/work/work-docx-run-formatting-import.d.ts +8 -1
  57. package/dist/internal/features/work/work-docx-tab-stop-import.d.ts +2 -1
  58. package/dist/internal/features/work/work-docx-table-cell-export.d.ts +1 -1
  59. package/dist/internal/features/work/work-docx-table-cell-import.d.ts +14 -4
  60. package/dist/internal/features/work/work-docx-table-sizing-export.d.ts +1 -1
  61. package/dist/internal/features/work/work-docx-table-sizing-import.d.ts +4 -3
  62. package/dist/internal/features/work/work-docx-table-styles.d.ts +22 -0
  63. package/dist/internal/features/work/work-types.d.ts +6 -0
  64. package/dist/office-kernel.wasm +0 -0
  65. package/dist/styles.css +1288 -233
  66. package/docs/{browser-editor-architecture.md → latest/en/browser-editor-architecture.md} +144 -35
  67. package/package.json +9 -5
  68. package/dist/0~6552.js +0 -787
  69. package/dist/0~8155.js +0 -299
package/dist/0~2582.js ADDED
@@ -0,0 +1,485 @@
1
+ import { Extension } from "@tiptap/core";
2
+ import { TableCell, TableHeader, TableRow } from "@tiptap/extension-table";
3
+ import { NodeSelection } from "@tiptap/pm/state";
4
+ import { CellSelection } from "@tiptap/pm/tables";
5
+ import { renderDocumentTableBorders, setSelectedDocumentTableBorders, normalizeTableColor, uniformDocumentTableBorder, documentTableBordersFromElement, normalizeDocumentTableBorderWidth, normalizeDocumentTableBorderStyle, documentTableBordersFromAttributes, normalizeDocumentTableCellMarginOverrides, renderDocumentTableCellMarginOverrides, documentTableCellMarginOverridesFromElement, uniformDocumentTableBorders } from "./0~4750.js";
6
+ const DOCUMENT_TABLE_STYLE_OPTIONS = [
7
+ {
8
+ id: 'grid',
9
+ label: '网格',
10
+ headerColor: '#f1f4f9',
11
+ bodyColor: '#ffffff',
12
+ alternateColor: '#ffffff',
13
+ borderColor: '#cfd5df',
14
+ borderStyle: 'solid',
15
+ borderWidth: 1
16
+ },
17
+ {
18
+ id: 'blueStripe',
19
+ label: '蓝色条纹',
20
+ headerColor: '#d9eaf7',
21
+ bodyColor: '#ffffff',
22
+ alternateColor: '#f7fbff',
23
+ borderColor: '#9fbad0',
24
+ borderStyle: 'solid',
25
+ borderWidth: 1
26
+ },
27
+ {
28
+ id: 'greenStripe',
29
+ label: '绿色条纹',
30
+ headerColor: '#ddeee7',
31
+ bodyColor: '#ffffff',
32
+ alternateColor: '#f4faf7',
33
+ borderColor: '#abc8be',
34
+ borderStyle: 'solid',
35
+ borderWidth: 1
36
+ },
37
+ {
38
+ id: 'grayStripe',
39
+ label: '灰色条纹',
40
+ headerColor: '#e7e9ed',
41
+ bodyColor: '#ffffff',
42
+ alternateColor: '#f6f7f9',
43
+ borderColor: '#b9c0ca',
44
+ borderStyle: 'solid',
45
+ borderWidth: 1
46
+ },
47
+ {
48
+ id: 'clean',
49
+ label: '简洁',
50
+ headerColor: '#f1f4f9',
51
+ bodyColor: '#ffffff',
52
+ alternateColor: '#ffffff',
53
+ borderColor: '#cfd5df',
54
+ borderStyle: 'none',
55
+ borderWidth: 0
56
+ }
57
+ ];
58
+ const DEFAULT_DOCUMENT_TABLE_CELL_FORMAT = {
59
+ backgroundColor: '#ffffff',
60
+ verticalAlign: 'top',
61
+ borderColor: '#cfd5df',
62
+ borderStyle: 'solid',
63
+ borderWidth: 1,
64
+ borders: uniformDocumentTableBorders({
65
+ color: '#cfd5df',
66
+ style: 'solid',
67
+ width: 1
68
+ }),
69
+ margins: null
70
+ };
71
+ const DEFAULT_DOCUMENT_TABLE_HEADER_FORMAT = {
72
+ ...DEFAULT_DOCUMENT_TABLE_CELL_FORMAT,
73
+ backgroundColor: '#f1f4f9'
74
+ };
75
+ const DocumentTableCell = TableCell.extend({
76
+ addAttributes () {
77
+ return {
78
+ ...this.parent?.(),
79
+ ...documentTableCellAttributes(DEFAULT_DOCUMENT_TABLE_CELL_FORMAT)
80
+ };
81
+ }
82
+ });
83
+ const DocumentTableHeader = TableHeader.extend({
84
+ addAttributes () {
85
+ return {
86
+ ...this.parent?.(),
87
+ ...documentTableCellAttributes(DEFAULT_DOCUMENT_TABLE_HEADER_FORMAT)
88
+ };
89
+ }
90
+ });
91
+ const DocumentTableFormatting = Extension.create({
92
+ name: 'documentTableFormatting',
93
+ addCommands () {
94
+ return {
95
+ setDocumentTableCellFormat: (format)=>(props)=>setSelectedCellFormat(props, format),
96
+ setDocumentTableHorizontalAlignment: (alignment)=>(props)=>setSelectedCellAlignment(props, alignment),
97
+ applyDocumentTableStyle: (style)=>(props)=>applyTableStyle(props, style),
98
+ setDocumentTableBorders: (target, border)=>(props)=>setSelectedDocumentTableBorders(props, target, border)
99
+ };
100
+ }
101
+ });
102
+ function documentTableCellFormat(state) {
103
+ const position = selectedTableCellPositions(state.selection)[0];
104
+ const node = void 0 === position ? null : state.doc.nodeAt(position);
105
+ return node && isTableCell(node) ? formatFromAttributes(node.attrs) : null;
106
+ }
107
+ function documentTableHorizontalAlignment(state) {
108
+ const position = selectedTableCellPositions(state.selection)[0];
109
+ const cell = void 0 === position ? null : state.doc.nodeAt(position);
110
+ let alignment = 'left';
111
+ cell?.descendants((node)=>{
112
+ if ('paragraph' !== node.type.name && 'heading' !== node.type.name) return true;
113
+ if ('center' === node.attrs.textAlign || 'right' === node.attrs.textAlign) alignment = node.attrs.textAlign;
114
+ return false;
115
+ });
116
+ return alignment;
117
+ }
118
+ function activeDocumentTableStyle(state) {
119
+ const context = selectedTable(state.selection);
120
+ if (!context) return null;
121
+ for (const style of DOCUMENT_TABLE_STYLE_OPTIONS){
122
+ let matches = true;
123
+ context.node.forEach((row, _rowOffset, rowIndex)=>{
124
+ row.forEach((cell)=>{
125
+ const expected = tableStyleCellFormat(style, cell, rowIndex);
126
+ const actual = formatFromAttributes(cell.attrs);
127
+ const expectedBorder = {
128
+ color: style.borderColor,
129
+ style: style.borderStyle,
130
+ width: style.borderWidth
131
+ };
132
+ const actualBorder = uniformDocumentTableBorder(actual.borders);
133
+ if (expected.backgroundColor !== actual.backgroundColor || !actualBorder || actualBorder.color !== expectedBorder.color || actualBorder.style !== expectedBorder.style || actualBorder.width !== expectedBorder.width) matches = false;
134
+ });
135
+ });
136
+ if (matches) return style.id;
137
+ }
138
+ return null;
139
+ }
140
+ function documentTableCellAttributes(defaults) {
141
+ return {
142
+ backgroundColor: {
143
+ default: defaults.backgroundColor,
144
+ parseHTML: (element)=>normalizeTableColor(element.dataset.officeCellFill || element.style.backgroundColor) ?? defaults.backgroundColor,
145
+ renderHTML: (attributes)=>{
146
+ const color = normalizeTableColor(String(attributes.backgroundColor ?? '')) ?? defaults.backgroundColor;
147
+ return {
148
+ 'data-office-cell-fill': color,
149
+ style: `background-color: ${color}`
150
+ };
151
+ }
152
+ },
153
+ verticalAlign: {
154
+ default: defaults.verticalAlign,
155
+ parseHTML: (element)=>normalizeDocumentTableVerticalAlign(element.dataset.officeCellVerticalAlign || element.style.verticalAlign) ?? defaults.verticalAlign,
156
+ renderHTML: (attributes)=>{
157
+ const alignment = normalizeDocumentTableVerticalAlign(String(attributes.verticalAlign ?? '')) ?? defaults.verticalAlign;
158
+ return {
159
+ 'data-office-cell-vertical-align': alignment,
160
+ style: `vertical-align: ${alignment}`
161
+ };
162
+ }
163
+ },
164
+ borderColor: {
165
+ default: defaults.borderColor,
166
+ parseHTML: (element)=>normalizeTableColor(element.dataset.officeCellBorderColor || element.style.borderColor) ?? defaults.borderColor,
167
+ renderHTML: ()=>({})
168
+ },
169
+ borderStyle: {
170
+ default: defaults.borderStyle,
171
+ parseHTML: (element)=>normalizeDocumentTableBorderStyle(element.dataset.officeCellBorderStyle || element.style.borderStyle) ?? defaults.borderStyle,
172
+ renderHTML: ()=>({})
173
+ },
174
+ borderWidth: {
175
+ default: defaults.borderWidth,
176
+ parseHTML: (element)=>normalizeDocumentTableBorderWidth(element.dataset.officeCellBorderWidth || element.style.borderWidth) ?? defaults.borderWidth,
177
+ renderHTML: ()=>({})
178
+ },
179
+ borders: {
180
+ default: defaults.borders,
181
+ parseHTML: (element)=>documentTableBordersFromElement(element, {
182
+ color: defaults.borderColor,
183
+ style: defaults.borderStyle,
184
+ width: defaults.borderWidth
185
+ }),
186
+ renderHTML: (attributes)=>renderDocumentTableBorders(formatFromAttributes(attributes, defaults).borders)
187
+ },
188
+ margins: {
189
+ default: defaults.margins,
190
+ parseHTML: (element)=>documentTableCellMarginOverridesFromElement(element),
191
+ renderHTML: (attributes)=>renderDocumentTableCellMarginOverrides(attributes.margins)
192
+ }
193
+ };
194
+ }
195
+ function setSelectedCellFormat({ dispatch, state }, patch) {
196
+ const normalized = normalizeFormatPatch(patch);
197
+ if (!normalized) return false;
198
+ const positions = selectedTableCellPositions(state.selection);
199
+ if (!positions.length) return false;
200
+ const transaction = state.tr;
201
+ for (const position of positions){
202
+ const cell = transaction.doc.nodeAt(position);
203
+ if (!cell || !isTableCell(cell)) continue;
204
+ const current = formatFromAttributes(cell.attrs);
205
+ const changesBorder = void 0 !== normalized.borderColor || void 0 !== normalized.borderStyle || void 0 !== normalized.borderWidth;
206
+ const nextBorder = {
207
+ color: normalized.borderColor ?? current.borderColor,
208
+ style: normalized.borderStyle ?? current.borderStyle,
209
+ width: normalized.borderWidth ?? current.borderWidth
210
+ };
211
+ if ('none' === nextBorder.style) nextBorder.width = 0;
212
+ transaction.setNodeMarkup(position, void 0, {
213
+ ...cell.attrs,
214
+ ...normalized,
215
+ ...changesBorder ? {
216
+ borderColor: nextBorder.color,
217
+ borderStyle: nextBorder.style,
218
+ borderWidth: nextBorder.width,
219
+ borders: uniformDocumentTableBorders(nextBorder)
220
+ } : {}
221
+ });
222
+ }
223
+ if (dispatch && transaction.docChanged) dispatch(transaction.scrollIntoView());
224
+ return true;
225
+ }
226
+ function setSelectedCellAlignment({ dispatch, state }, alignment) {
227
+ if ('left' !== alignment && 'center' !== alignment && 'right' !== alignment) return false;
228
+ const positions = selectedTableCellPositions(state.selection);
229
+ if (!positions.length) return false;
230
+ const transaction = state.tr;
231
+ for (const position of positions){
232
+ const cell = transaction.doc.nodeAt(position);
233
+ if (cell && isTableCell(cell)) cell.descendants((node, offset)=>{
234
+ if ('paragraph' !== node.type.name && 'heading' !== node.type.name) return true;
235
+ transaction.setNodeMarkup(position + 1 + offset, void 0, {
236
+ ...node.attrs,
237
+ textAlign: alignment
238
+ });
239
+ return false;
240
+ });
241
+ }
242
+ if (dispatch && transaction.docChanged) dispatch(transaction.scrollIntoView());
243
+ return true;
244
+ }
245
+ function applyTableStyle({ dispatch, state }, styleId) {
246
+ const style = DOCUMENT_TABLE_STYLE_OPTIONS.find((candidate)=>candidate.id === styleId);
247
+ const context = selectedTable(state.selection);
248
+ if (!style || !context) return false;
249
+ const transaction = state.tr;
250
+ context.node.forEach((row, rowOffset, rowIndex)=>{
251
+ row.forEach((cell, cellOffset)=>{
252
+ const position = context.position + 2 + rowOffset + cellOffset;
253
+ const format = tableStyleCellFormat(style, cell, rowIndex);
254
+ const border = {
255
+ color: style.borderColor,
256
+ style: style.borderStyle,
257
+ width: style.borderWidth
258
+ };
259
+ transaction.setNodeMarkup(position, void 0, {
260
+ ...cell.attrs,
261
+ ...format,
262
+ borders: uniformDocumentTableBorders(border)
263
+ });
264
+ });
265
+ });
266
+ if (dispatch && transaction.docChanged) dispatch(transaction.scrollIntoView());
267
+ return true;
268
+ }
269
+ function selectedTableCellPositions(selection) {
270
+ if (selection instanceof CellSelection) {
271
+ const positions = [];
272
+ selection.forEachCell((_node, position)=>positions.push(position));
273
+ return positions;
274
+ }
275
+ if (selection instanceof NodeSelection && 'table' === selection.node.type.spec.tableRole) {
276
+ const positions = [];
277
+ selection.node.forEach((row, rowOffset)=>{
278
+ row.forEach((_cell, cellOffset)=>{
279
+ positions.push(selection.from + 2 + rowOffset + cellOffset);
280
+ });
281
+ });
282
+ return positions;
283
+ }
284
+ const position = ancestorPosition(selection.$from, isTableCell);
285
+ return null === position ? [] : [
286
+ position
287
+ ];
288
+ }
289
+ function selectedTable(selection) {
290
+ if (selection instanceof NodeSelection && 'table' === selection.node.type.spec.tableRole) return {
291
+ node: selection.node,
292
+ position: selection.from
293
+ };
294
+ for(let depth = selection.$from.depth; depth > 0; depth -= 1){
295
+ const node = selection.$from.node(depth);
296
+ if ('table' === node.type.spec.tableRole) return {
297
+ node,
298
+ position: selection.$from.before(depth)
299
+ };
300
+ }
301
+ return null;
302
+ }
303
+ function ancestorPosition(position, predicate) {
304
+ for(let depth = position.depth; depth > 0; depth -= 1)if (predicate(position.node(depth))) return position.before(depth);
305
+ return null;
306
+ }
307
+ function isTableCell(node) {
308
+ return 'cell' === node.type.spec.tableRole || 'header_cell' === node.type.spec.tableRole;
309
+ }
310
+ function tableStyleCellFormat(style, cell, rowIndex) {
311
+ return {
312
+ backgroundColor: 'header_cell' === cell.type.spec.tableRole ? style.headerColor : rowIndex % 2 === 1 ? style.alternateColor : style.bodyColor,
313
+ borderColor: style.borderColor,
314
+ borderStyle: style.borderStyle,
315
+ borderWidth: style.borderWidth
316
+ };
317
+ }
318
+ function normalizeFormatPatch(patch) {
319
+ const normalized = {};
320
+ if (void 0 !== patch.backgroundColor) {
321
+ const color = normalizeTableColor(patch.backgroundColor);
322
+ if (!color) return null;
323
+ normalized.backgroundColor = color;
324
+ }
325
+ if (void 0 !== patch.verticalAlign) {
326
+ const alignment = normalizeDocumentTableVerticalAlign(patch.verticalAlign);
327
+ if (!alignment) return null;
328
+ normalized.verticalAlign = alignment;
329
+ }
330
+ if (void 0 !== patch.borderColor) {
331
+ const color = normalizeTableColor(patch.borderColor);
332
+ if (!color) return null;
333
+ normalized.borderColor = color;
334
+ }
335
+ if (void 0 !== patch.borderStyle) {
336
+ const style = normalizeDocumentTableBorderStyle(patch.borderStyle);
337
+ if (!style) return null;
338
+ normalized.borderStyle = style;
339
+ }
340
+ if (void 0 !== patch.borderWidth) {
341
+ const width = normalizeDocumentTableBorderWidth(patch.borderWidth);
342
+ if (null === width) return null;
343
+ normalized.borderWidth = width;
344
+ }
345
+ if (void 0 !== patch.margins) if (null === patch.margins) normalized.margins = null;
346
+ else {
347
+ const margins = normalizeDocumentTableCellMarginOverrides(patch.margins);
348
+ if (!margins) return null;
349
+ normalized.margins = margins;
350
+ }
351
+ return normalized;
352
+ }
353
+ function formatFromAttributes(attributes, defaults = DEFAULT_DOCUMENT_TABLE_CELL_FORMAT) {
354
+ const fallbackBorder = {
355
+ color: normalizeTableColor(String(attributes.borderColor ?? '')) ?? defaults.borderColor,
356
+ style: normalizeDocumentTableBorderStyle(String(attributes.borderStyle ?? '')) ?? defaults.borderStyle,
357
+ width: normalizeDocumentTableBorderWidth(attributes.borderWidth) ?? defaults.borderWidth
358
+ };
359
+ if ('none' === fallbackBorder.style) fallbackBorder.width = 0;
360
+ const borders = documentTableBordersFromAttributes(attributes, fallbackBorder);
361
+ const representative = uniformDocumentTableBorder(borders) ?? borders.top;
362
+ return {
363
+ backgroundColor: normalizeTableColor(String(attributes.backgroundColor ?? '')) ?? defaults.backgroundColor,
364
+ verticalAlign: normalizeDocumentTableVerticalAlign(String(attributes.verticalAlign ?? '')) ?? defaults.verticalAlign,
365
+ borderColor: representative.color,
366
+ borderStyle: representative.style,
367
+ borderWidth: representative.width,
368
+ borders,
369
+ margins: normalizeDocumentTableCellMarginOverrides(attributes.margins)
370
+ };
371
+ }
372
+ function normalizeDocumentTableVerticalAlign(value) {
373
+ if ('top' === value || 'middle' === value || 'bottom' === value) return value;
374
+ if ('center' === value) return 'middle';
375
+ return null;
376
+ }
377
+ const DocumentTableRow = TableRow.extend({
378
+ addAttributes () {
379
+ return {
380
+ ...this.parent?.() ?? {},
381
+ cantSplit: booleanRowAttribute('cantSplit', 'officeCantSplit', 'data-office-cant-split'),
382
+ repeatHeader: booleanRowAttribute('repeatHeader', 'officeRepeatHeader', 'data-office-repeat-header'),
383
+ rowHeight: {
384
+ default: null,
385
+ parseHTML: (element)=>normalizeDocumentTableRowHeight(element.dataset.officeRowHeight || element.style.height),
386
+ renderHTML: (attributes)=>{
387
+ const height = normalizeDocumentTableRowHeight(attributes.rowHeight);
388
+ return null === height ? {} : {
389
+ 'data-office-row-height': String(height),
390
+ style: `height: ${height}px`
391
+ };
392
+ }
393
+ },
394
+ rowHeightRule: {
395
+ default: null,
396
+ parseHTML: (element)=>normalizeDocumentTableRowHeightRule(element.dataset.officeRowHeightRule),
397
+ renderHTML: (attributes)=>{
398
+ const rule = normalizeDocumentTableRowHeightRule(attributes.rowHeightRule);
399
+ return null === rule ? {} : {
400
+ 'data-office-row-height-rule': rule
401
+ };
402
+ }
403
+ }
404
+ };
405
+ },
406
+ addCommands () {
407
+ return {
408
+ ...this.parent?.() ?? {},
409
+ setDocumentTableRowOptions: (options, commandOptions = {})=>({ chain, editor })=>{
410
+ if (!editor.isActive('table')) return false;
411
+ let commandChain = chain();
412
+ if (false !== commandOptions.restoreFocus) commandChain = commandChain.focus();
413
+ return commandChain.updateAttributes('tableRow', {
414
+ cantSplit: Boolean(options.cantSplit),
415
+ repeatHeader: Boolean(options.repeatHeader)
416
+ }).run();
417
+ }
418
+ };
419
+ }
420
+ });
421
+ function documentTableRowOptions(editor) {
422
+ const attributes = editor.getAttributes('tableRow');
423
+ return {
424
+ cantSplit: directBoolean(attributes.cantSplit) ?? false,
425
+ repeatHeader: directBoolean(attributes.repeatHeader) ?? editor.isActive('tableHeader')
426
+ };
427
+ }
428
+ function canSetDocumentTableRowRepeatHeader(editor) {
429
+ const resolved = editor.state.selection.$from;
430
+ for(let depth = resolved.depth; depth > 0; depth -= 1){
431
+ if ('tableRow' !== resolved.node(depth).type.name) continue;
432
+ const tableDepth = depth - 1;
433
+ const table = resolved.node(tableDepth);
434
+ if ('table' !== table.type.name) break;
435
+ let leadingHeaderCount = 0;
436
+ for(let index = 0; index < table.childCount; index += 1){
437
+ if (!documentTableRowRepeats(table.child(index))) break;
438
+ leadingHeaderCount += 1;
439
+ }
440
+ return resolved.index(tableDepth) <= leadingHeaderCount;
441
+ }
442
+ return false;
443
+ }
444
+ function documentTableRowRepeats(node) {
445
+ const explicit = directBoolean(node.attrs.repeatHeader);
446
+ if (null !== explicit) return explicit;
447
+ if (0 === node.childCount) return false;
448
+ for(let index = 0; index < node.childCount; index += 1)if ('tableHeader' !== node.child(index).type.name) return false;
449
+ return true;
450
+ }
451
+ function documentTableRowCantSplit(node) {
452
+ return directBoolean(node.attrs.cantSplit) ?? false;
453
+ }
454
+ function documentTableRowHeight(attributes) {
455
+ const height = normalizeDocumentTableRowHeight(attributes.rowHeight);
456
+ return {
457
+ height,
458
+ rule: null === height ? null : normalizeDocumentTableRowHeightRule(attributes.rowHeightRule) ?? 'atLeast'
459
+ };
460
+ }
461
+ function normalizeDocumentTableRowHeight(value) {
462
+ const height = Number.parseFloat(String(value ?? '').replace(/px$/i, ''));
463
+ return Number.isFinite(height) && height > 0 ? Math.round(100 * height) / 100 : null;
464
+ }
465
+ function normalizeDocumentTableRowHeightRule(value) {
466
+ return 'exact' === value || 'atLeast' === value ? value : null;
467
+ }
468
+ function booleanRowAttribute(modelKey, datasetKey, htmlName) {
469
+ return {
470
+ default: null,
471
+ parseHTML: (element)=>directBoolean(element.dataset[datasetKey]),
472
+ renderHTML: (attributes)=>{
473
+ const value = directBoolean(attributes[modelKey]);
474
+ return null === value ? {} : {
475
+ [htmlName]: String(value)
476
+ };
477
+ }
478
+ };
479
+ }
480
+ function directBoolean(value) {
481
+ if (true === value || 'true' === value || '1' === value) return true;
482
+ if (false === value || 'false' === value || '0' === value) return false;
483
+ return null;
484
+ }
485
+ export { DEFAULT_DOCUMENT_TABLE_CELL_FORMAT, DOCUMENT_TABLE_STYLE_OPTIONS, DocumentTableCell, DocumentTableFormatting, DocumentTableHeader, DocumentTableRow, activeDocumentTableStyle, canSetDocumentTableRowRepeatHeader, documentTableCellFormat, documentTableHorizontalAlignment, documentTableRowCantSplit, documentTableRowHeight, documentTableRowOptions, documentTableRowRepeats, normalizeDocumentTableRowHeightRule, normalizeDocumentTableVerticalAlign };
package/dist/0~4595.js CHANGED
@@ -706,6 +706,7 @@ function WorkOfficeRibbon({ ariaLabel, tabs, defaultTab, activeTab, onTabChange,
706
706
  const selectedLabel = tabs.find((tab)=>tab.id === selectedTab)?.label ?? tabs[0]?.label ?? '';
707
707
  const selectedPanel = panels[selectedTab];
708
708
  const hasSelectedPanel = null != selectedPanel;
709
+ const hasRibbonOverflow = ribbonOverflow.backward || ribbonOverflow.forward;
709
710
  const updateRibbonOverflow = useCallback(()=>{
710
711
  const toolbar = toolbarRef.current;
711
712
  if (!toolbar) return;
@@ -909,10 +910,11 @@ function WorkOfficeRibbon({ ariaLabel, tabs, defaultTab, activeTab, onTabChange,
909
910
  "aria-labelledby": `${reactId}-tab-${selectedTab}`,
910
911
  children: hasSelectedPanel && /*#__PURE__*/ jsxs(jsx_runtime_Fragment, {
911
912
  children: [
912
- ribbonOverflow.backward && /*#__PURE__*/ jsx("button", {
913
+ hasRibbonOverflow && /*#__PURE__*/ jsx("button", {
913
914
  type: "button",
914
915
  className: "work-office-ribbon-scroll previous",
915
916
  "aria-label": `向左查看更多${selectedLabel}工具`,
917
+ disabled: !ribbonOverflow.backward,
916
918
  onClick: ()=>scrollRibbon(-1),
917
919
  children: /*#__PURE__*/ jsx(ChevronLeft, {
918
920
  size: 15
@@ -921,16 +923,17 @@ function WorkOfficeRibbon({ ariaLabel, tabs, defaultTab, activeTab, onTabChange,
921
923
  /*#__PURE__*/ jsx("div", {
922
924
  ref: toolbarRef,
923
925
  className: `work-office-toolbar ${toolbarClassName}`.trim(),
924
- "data-has-overflow": ribbonOverflow.backward || ribbonOverflow.forward ? 'true' : void 0,
926
+ "data-has-overflow": hasRibbonOverflow ? 'true' : void 0,
925
927
  role: "toolbar",
926
928
  "aria-label": `${selectedLabel}工具栏`,
927
929
  onScroll: updateRibbonOverflow,
928
930
  children: selectedPanel
929
931
  }),
930
- ribbonOverflow.forward && /*#__PURE__*/ jsx("button", {
932
+ hasRibbonOverflow && /*#__PURE__*/ jsx("button", {
931
933
  type: "button",
932
934
  className: "work-office-ribbon-scroll next",
933
935
  "aria-label": `向右查看更多${selectedLabel}工具`,
936
+ disabled: !ribbonOverflow.forward,
934
937
  onClick: ()=>scrollRibbon(1),
935
938
  children: /*#__PURE__*/ jsx(ChevronRight, {
936
939
  size: 15
@@ -944,12 +947,16 @@ function WorkOfficeRibbon({ ariaLabel, tabs, defaultTab, activeTab, onTabChange,
944
947
  }
945
948
  function ribbonItemGeometry(toolbar) {
946
949
  return Array.from(toolbar.children).flatMap((element)=>element instanceof HTMLElement ? [
947
- {
948
- left: element.offsetLeft,
949
- right: element.offsetLeft + element.offsetWidth
950
- }
950
+ ribbonItemBounds(toolbar, element)
951
951
  ] : []);
952
952
  }
953
+ function ribbonItemBounds(toolbar, element) {
954
+ const left = element.offsetParent === toolbar ? element.offsetLeft : element.offsetLeft - toolbar.offsetLeft;
955
+ return {
956
+ left,
957
+ right: left + element.offsetWidth
958
+ };
959
+ }
953
960
  function scrollSelectedRibbonTabIntoView(tabList, selectedTab) {
954
961
  const selected = Array.from(tabList.children).find((element)=>element instanceof HTMLElement && element.dataset.tabId === selectedTab);
955
962
  if (!selected || tabList.clientWidth <= 0) return;