@ctzhian/tiptap 1.13.9 → 2.0.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.
Files changed (47) hide show
  1. package/dist/Editor/demo.js +1 -1
  2. package/dist/Editor/index.js +17 -0
  3. package/dist/component/CustomBubbleMenu/index.js +1 -1
  4. package/dist/component/CustomDragHandle/index.js +3 -59
  5. package/dist/component/Icons/delete-back-2-line-icon.d.ts +6 -0
  6. package/dist/component/Icons/delete-back-2-line-icon.js +13 -0
  7. package/dist/component/Menu/index.js +5 -1
  8. package/dist/contants/enums.d.ts +9 -0
  9. package/dist/contants/enums.js +61 -1
  10. package/dist/extension/component/TableCellHandleMenu/index.d.ts +9 -0
  11. package/dist/extension/component/TableCellHandleMenu/index.js +443 -0
  12. package/dist/extension/component/TableExtendButton/TableExtendButton.css +30 -0
  13. package/dist/extension/component/TableExtendButton/index.d.ts +23 -0
  14. package/dist/extension/component/TableExtendButton/index.js +201 -0
  15. package/dist/extension/component/TableExtendButton/use-table-extend-row-column.d.ts +15 -0
  16. package/dist/extension/component/TableExtendButton/use-table-extend-row-column.js +87 -0
  17. package/dist/extension/component/TableHandle/TableHandleMenu.css +36 -0
  18. package/dist/extension/component/TableHandle/TableHandleMenu.d.ts +17 -0
  19. package/dist/extension/component/TableHandle/TableHandleMenu.js +685 -0
  20. package/dist/extension/component/TableHandle/index.d.ts +28 -0
  21. package/dist/extension/component/TableHandle/index.js +93 -0
  22. package/dist/extension/component/TableHandle/use-table-handle-positioning.d.ts +40 -0
  23. package/dist/extension/component/TableHandle/use-table-handle-positioning.js +193 -0
  24. package/dist/extension/component/TableHandle/use-table-handle-state.d.ts +22 -0
  25. package/dist/extension/component/TableHandle/use-table-handle-state.js +45 -0
  26. package/dist/extension/component/TableSelectionOverlay/index.d.ts +16 -0
  27. package/dist/extension/component/TableSelectionOverlay/index.js +460 -0
  28. package/dist/extension/component/UploadProgress/index.d.ts +1 -1
  29. package/dist/extension/node/FileHandler.d.ts +1 -1
  30. package/dist/extension/node/Table.js +226 -43
  31. package/dist/extension/node/TableHandler/create-image.d.ts +9 -0
  32. package/dist/extension/node/TableHandler/create-image.js +235 -0
  33. package/dist/extension/node/TableHandler/index.d.ts +15 -0
  34. package/dist/extension/node/TableHandler/index.js +33 -0
  35. package/dist/extension/node/TableHandler/plugin.d.ts +49 -0
  36. package/dist/extension/node/TableHandler/plugin.js +1030 -0
  37. package/dist/index.css +29 -10
  38. package/dist/type/index.d.ts +2 -0
  39. package/dist/util/table-utils.d.ts +161 -0
  40. package/dist/util/table-utils.js +605 -0
  41. package/package.json +2 -1
  42. package/dist/extension/component/Table/ContextMenu.d.ts +0 -11
  43. package/dist/extension/component/Table/ContextMenu.js +0 -186
  44. package/dist/extension/component/Table/TableContextMenuPlugin.d.ts +0 -9
  45. package/dist/extension/component/Table/TableContextMenuPlugin.js +0 -336
  46. package/dist/extension/component/Table/index.d.ts +0 -2
  47. package/dist/extension/component/Table/index.js +0 -2
package/dist/index.css CHANGED
@@ -418,7 +418,6 @@
418
418
  word-break: break-all;
419
419
  }
420
420
 
421
- /* 表格单元格基础样式 */
422
421
  .tiptap.ProseMirror table td,
423
422
  .tiptap.ProseMirror table th {
424
423
  border: none;
@@ -441,12 +440,12 @@
441
440
  margin-bottom: 0;
442
441
  }
443
442
 
444
- /* 表格表头样式 */
445
443
  .tiptap.ProseMirror table th {
446
444
  font-weight: 600;
447
445
  text-transform: uppercase;
448
446
  letter-spacing: 0.5px;
449
447
  text-align: left;
448
+ background-color: var(--mui-palette-background-paper3);
450
449
  }
451
450
 
452
451
  .tiptap.ProseMirror[contenteditable="true"] table .selectedCell * {
@@ -454,9 +453,8 @@
454
453
  user-select: none;
455
454
  }
456
455
 
457
- /* 表格选择状态 */
458
456
  .tiptap.ProseMirror[contenteditable="true"] table .selectedCell:after {
459
- background-color: color-mix(in srgb, var(--mui-palette-primary-main) 12%, transparent);
457
+ background-color: color-mix(in srgb, var(--mui-palette-primary-main) 5%, transparent);
460
458
  content: '';
461
459
  left: 0;
462
460
  right: 0;
@@ -467,7 +465,6 @@
467
465
  z-index: 2;
468
466
  }
469
467
 
470
- /* 表格列调整手柄 */
471
468
  .tiptap.ProseMirror[contenteditable="true"] table .column-resize-handle {
472
469
  border-right: 2px dotted var(--mui-palette-primary-main);
473
470
  bottom: -2px;
@@ -481,18 +478,43 @@
481
478
  transition: all 0.2s ease-in-out;
482
479
  }
483
480
 
481
+ .tiptap-table-dropcursor {
482
+ position: absolute !important;
483
+ z-index: 20;
484
+ pointer-events: none;
485
+ background-color: var(--mui-palette-primary-main, #1976d2);
486
+ }
487
+
484
488
  .tiptap.ProseMirror.resize-cursor {
485
489
  cursor: col-resize;
486
490
  }
487
491
 
488
- /* 表格包装器样式 */
489
492
  .tiptap.ProseMirror .tableWrapper {
490
493
  width: 100%;
491
494
  overflow-x: auto;
495
+ overflow-y: hidden;
496
+ position: relative;
492
497
  margin: 20px 0;
493
498
  }
494
499
 
495
- /* 表格滚动条样式 */
500
+ .tiptap.ProseMirror[contenteditable="true"] .tableWrapper {
501
+ padding-top: 16px;
502
+ padding-left: 16px;
503
+ padding-bottom: 16px;
504
+ padding-right: 16px;
505
+ }
506
+
507
+ .tiptap.ProseMirror .table-controls {
508
+ position: relative;
509
+ overflow: visible;
510
+ pointer-events: none;
511
+ z-index: 10;
512
+ }
513
+
514
+ .tiptap.ProseMirror .table-controls>* {
515
+ pointer-events: auto;
516
+ }
517
+
496
518
  .tiptap.ProseMirror .tableWrapper::-webkit-scrollbar {
497
519
  height: 5px;
498
520
  cursor: pointer;
@@ -510,7 +532,6 @@
510
532
  cursor: pointer;
511
533
  }
512
534
 
513
- /* youtube */
514
535
  .tiptap.ProseMirror div[data-youtube-video] {
515
536
  cursor: move;
516
537
  padding-right: 1.5rem;
@@ -551,7 +572,6 @@
551
572
  line-height: 24px;
552
573
  }
553
574
 
554
- /* AI 续写建议样式 */
555
575
  .tiptap.ProseMirror .ai-writing-suggestion {
556
576
  color: color-mix(in srgb, var(--mui-palette-text-primary) 15%, transparent);
557
577
  pointer-events: none;
@@ -559,7 +579,6 @@
559
579
  white-space: pre-wrap;
560
580
  }
561
581
 
562
- /* placeholder */
563
582
  .tiptap.ProseMirror .cq-details[data-placeholder]::before,
564
583
  .tiptap.ProseMirror table *[data-placeholder]::before,
565
584
  .tiptap.ProseMirror li p[data-placeholder]::before {
@@ -37,6 +37,8 @@ export interface MenuProps {
37
37
  transformOrigin?: PopoverOrigin;
38
38
  };
39
39
  zIndex?: number;
40
+ onOpen?: () => void;
41
+ onClose?: () => void;
40
42
  }
41
43
  export type ToolbarItemType = {
42
44
  id: string;
@@ -0,0 +1,161 @@
1
+ import type { Node } from '@tiptap/pm/model';
2
+ import { type EditorState, type Transaction } from '@tiptap/pm/state';
3
+ import type { FindNodeResult } from '@tiptap/pm/tables';
4
+ import { TableMap } from '@tiptap/pm/tables';
5
+ import type { Editor } from '@tiptap/react';
6
+ export declare const RESIZE_MIN_WIDTH = 35;
7
+ export declare const EMPTY_CELL_WIDTH = 120;
8
+ export declare const EMPTY_CELL_HEIGHT = 40;
9
+ export type Orientation = 'row' | 'column';
10
+ export interface CellInfo extends FindNodeResult {
11
+ row: number;
12
+ column: number;
13
+ }
14
+ export type CellCoordinates = {
15
+ row: number;
16
+ col: number;
17
+ };
18
+ export type SelectionReturnMode = 'state' | 'transaction' | 'dispatch';
19
+ export type BaseSelectionOptions = {
20
+ mode?: SelectionReturnMode;
21
+ };
22
+ export type DispatchSelectionOptions = {
23
+ mode: 'dispatch';
24
+ dispatch: (tr: Transaction) => void;
25
+ };
26
+ export type TransactionSelectionOptions = {
27
+ mode: 'transaction';
28
+ };
29
+ export type StateSelectionOptions = {
30
+ mode?: 'state';
31
+ };
32
+ export type TableInfo = {
33
+ map: TableMap;
34
+ } & FindNodeResult;
35
+ export declare function isHTMLElement(n: unknown): n is HTMLElement;
36
+ export type DomCellAroundResult = {
37
+ type: 'cell';
38
+ domNode: HTMLElement;
39
+ tbodyNode: HTMLTableSectionElement | null;
40
+ } | {
41
+ type: 'wrapper';
42
+ domNode: HTMLElement;
43
+ tbodyNode: HTMLTableSectionElement | null;
44
+ };
45
+ export declare function safeClosest<T extends Element>(start: Element | null, selector: string): T | null;
46
+ /**
47
+ * Walk up from an element until we find a TD/TH or the table wrapper.
48
+ * Returns the found element plus its tbody (if present).
49
+ */
50
+ export declare function domCellAround(target: Element): DomCellAroundResult | undefined;
51
+ /**
52
+ * Clamps a value between min and max bounds
53
+ */
54
+ export declare function clamp(value: number, min: number, max: number): number;
55
+ /**
56
+ * Checks if a cell is merged (has colspan or rowspan > 1)
57
+ */
58
+ export declare function isCellMerged(node: Node | null): boolean;
59
+ /**
60
+ * Get information about the table at the current selection or a specific position.
61
+ */
62
+ export declare function getTable(editor: Editor | null, tablePos?: number): {
63
+ map: TableMap;
64
+ node: Node;
65
+ pos: number;
66
+ start: number;
67
+ depth: number;
68
+ } | null;
69
+ /**
70
+ * Checks if the current text selection is inside a table cell.
71
+ */
72
+ export declare function isSelectionInCell(state: EditorState): boolean;
73
+ /**
74
+ * Runs a function while preserving the editor's selection.
75
+ */
76
+ export declare function runPreservingCursor(editor: Editor, fn: () => void): boolean;
77
+ /**
78
+ * Determines whether a table cell is effectively empty.
79
+ */
80
+ export declare function isCellEmpty(cellNode: Node): boolean;
81
+ /**
82
+ * Counts how many consecutive empty rows exist at the bottom of a given table.
83
+ */
84
+ export declare function countEmptyRowsFromEnd(editor: Editor, tablePos: number): number;
85
+ /**
86
+ * Counts how many consecutive empty columns exist at the right edge of a given table.
87
+ */
88
+ export declare function countEmptyColumnsFromEnd(editor: Editor, tablePos: number): number;
89
+ /**
90
+ * Rounds a number with a symmetric "dead-zone" around integer boundaries.
91
+ */
92
+ export declare function marginRound(num: number, margin?: number): number;
93
+ /**
94
+ * Selects table cells by their (row, col) coordinates.
95
+ */
96
+ export declare function selectCellsByCoords(editor: Editor | null, tablePos: number, coords: {
97
+ row: number;
98
+ col: number;
99
+ }[], options?: BaseSelectionOptions | DispatchSelectionOptions): EditorState | Transaction | void;
100
+ /**
101
+ * Select the cell at (row, col) using `cellAround` to respect merged cells.
102
+ */
103
+ export declare function selectCellAt({ editor, row, col, tablePos, dispatch, }: {
104
+ editor: Editor | null;
105
+ row: number;
106
+ col: number;
107
+ tablePos?: number;
108
+ dispatch?: (tr: Transaction) => void;
109
+ }): boolean;
110
+ /**
111
+ * Selects a boundary cell of the table based on orientation.
112
+ */
113
+ export declare function selectLastCell(editor: Editor, tableNode: Node, tablePos: number, orientation: Orientation): boolean;
114
+ /**
115
+ * Get all (row, col) coordinates for a given row or column index.
116
+ */
117
+ export declare function getIndexCoordinates({ editor, index, orientation, tablePos, }: {
118
+ editor: Editor | null;
119
+ index: number;
120
+ orientation?: Orientation;
121
+ tablePos?: number;
122
+ }): {
123
+ row: number;
124
+ col: number;
125
+ }[] | null;
126
+ /**
127
+ * Given a DOM cell element, find its (row, col) indices within the table.
128
+ */
129
+ export declare function getCellIndicesFromDOM(cell: HTMLTableCellElement, tableNode: Node | null, editor: Editor): {
130
+ rowIndex: number;
131
+ colIndex: number;
132
+ } | null;
133
+ /**
134
+ * Given a DOM element inside a table, find the corresponding table node and its position.
135
+ */
136
+ export declare function getTableFromDOM(tableElement: HTMLElement, editor: Editor): {
137
+ node: Node;
138
+ pos: number;
139
+ } | null;
140
+ /**
141
+ * Checks if a node is a table node
142
+ */
143
+ export declare function isTableNode(node: Node | null | undefined): node is Node;
144
+ /**
145
+ * Get all cells (and unique merged cells) from a specific row.
146
+ */
147
+ export declare function getRowCells(editor: Editor | null, rowIndex?: number, tablePos?: number): {
148
+ cells: CellInfo[];
149
+ mergedCells: CellInfo[];
150
+ };
151
+ /**
152
+ * Collect cells (and unique merged cells) from the current table.
153
+ */
154
+ export declare function getColumnCells(editor: Editor | null, columnIndex?: number, tablePos?: number): {
155
+ cells: CellInfo[];
156
+ mergedCells: CellInfo[];
157
+ };
158
+ /**
159
+ * Compare two DOMRects for equality (within a small tolerance)
160
+ */
161
+ export declare function rectEq(rect1: DOMRect | null, rect2: DOMRect | null): boolean;