@kopexa/tiptap 1.0.0 → 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 (213) hide show
  1. package/dist/{chunk-AASYBJDX.mjs → chunk-2SI7MRAE.mjs} +1 -1
  2. package/dist/{chunk-6W7J7PHZ.mjs → chunk-B2DHYFSH.mjs} +6 -7
  3. package/dist/{chunk-RQPJU4UB.mjs → chunk-B7WJOQ3X.mjs} +1 -1
  4. package/dist/{chunk-ACWAVTTK.mjs → chunk-BEV5U2DK.mjs} +6 -6
  5. package/dist/{chunk-TGQP45HH.mjs → chunk-EHY2NAW7.mjs} +1 -3
  6. package/dist/{chunk-O5P45H3I.mjs → chunk-GYIYX2JH.mjs} +1 -1
  7. package/dist/{chunk-QCULSZRZ.mjs → chunk-IOB3REX6.mjs} +1 -3
  8. package/dist/{chunk-ILPDDC4W.mjs → chunk-IQERE7KP.mjs} +1 -4
  9. package/dist/{chunk-6SS62RYU.mjs → chunk-JNL4KY45.mjs} +1 -3
  10. package/dist/{chunk-R2RRQUU5.mjs → chunk-LHXRE26G.mjs} +2 -2
  11. package/dist/{chunk-F2HHFSM4.mjs → chunk-LNVWG34E.mjs} +1 -4
  12. package/dist/chunk-NUCXXNTA.mjs +131 -0
  13. package/dist/{chunk-GLQRF7PR.mjs → chunk-OEVR5N7X.mjs} +2 -10
  14. package/dist/{chunk-YYHNT322.mjs → chunk-OZWCQMRA.mjs} +27 -19
  15. package/dist/{chunk-OX2A52WL.mjs → chunk-Q7DFJ5NI.mjs} +2 -4
  16. package/dist/{chunk-ODBSAQ5V.mjs → chunk-QF3YHPWM.mjs} +2 -4
  17. package/dist/{chunk-R5AMMJTQ.mjs → chunk-REJEJXOZ.mjs} +3 -3
  18. package/dist/chunk-TZQQ6C2Q.mjs +101 -0
  19. package/dist/{chunk-KI3YOPAA.mjs → chunk-UJ4BNZ63.mjs} +1 -4
  20. package/dist/{chunk-4LAWYE7B.mjs → chunk-V6TAZMQN.mjs} +2 -4
  21. package/dist/{chunk-QP2LCU5N.mjs → chunk-VX3HSJ76.mjs} +2 -2
  22. package/dist/{chunk-WCBSINO5.mjs → chunk-W2FLOOJ6.mjs} +1 -1
  23. package/dist/{chunk-JHMEXFB3.mjs → chunk-WHJ4B43N.mjs} +1 -1
  24. package/dist/{chunk-YD56B5SG.mjs → chunk-WPRDVMPN.mjs} +19 -18
  25. package/dist/{chunk-44V2Y6IU.mjs → chunk-XL5FS7LN.mjs} +3 -3
  26. package/dist/{chunk-ZSYXHD7D.mjs → chunk-YJAHZXLG.mjs} +1 -4
  27. package/dist/{chunk-T7LL5ZSR.mjs → chunk-ZVTJ6XD7.mjs} +1 -3
  28. package/dist/{chunk-I7WKP3OM.mjs → chunk-ZZ4OU46C.mjs} +6 -6
  29. package/dist/context/editor-context.d.mts +4 -4
  30. package/dist/context/editor-context.d.ts +4 -4
  31. package/dist/context/editor-context.js +5 -5
  32. package/dist/context/editor-context.mjs +5 -6
  33. package/dist/extensions/link/index.mjs +0 -1
  34. package/dist/extensions/selection/index.mjs +0 -1
  35. package/dist/extensions/trailing-node/index.mjs +0 -1
  36. package/dist/extensions/ui-state/index.mjs +0 -1
  37. package/dist/hooks/use-create-editor.d.mts +16 -5
  38. package/dist/hooks/use-create-editor.d.ts +16 -5
  39. package/dist/hooks/use-create-editor.js +84 -1062
  40. package/dist/hooks/use-create-editor.mjs +5 -18
  41. package/dist/hooks/use-cursor-visibility.mjs +0 -1
  42. package/dist/hooks/use-floating-element.mjs +0 -1
  43. package/dist/hooks/use-floating-toolbar-visibility.mjs +0 -1
  44. package/dist/hooks/use-menu-navigation.mjs +0 -1
  45. package/dist/hooks/use-tiptap-editor.mjs +0 -1
  46. package/dist/hooks/use-ui-editor-state.mjs +0 -1
  47. package/dist/hooks/use-window-size.mjs +0 -1
  48. package/dist/index.d.mts +6 -5
  49. package/dist/index.d.ts +6 -5
  50. package/dist/index.js +483 -1584
  51. package/dist/index.mjs +39 -60
  52. package/dist/presets/basic/editor-header.js +112 -167
  53. package/dist/presets/basic/editor-header.mjs +25 -25
  54. package/dist/presets/basic/index.d.mts +6 -3
  55. package/dist/presets/basic/index.d.ts +6 -3
  56. package/dist/presets/basic/index.js +386 -1468
  57. package/dist/presets/basic/index.mjs +32 -46
  58. package/dist/ui/blockquote-button/blockquote-button.js +12 -67
  59. package/dist/ui/blockquote-button/blockquote-button.mjs +2 -4
  60. package/dist/ui/blockquote-button/index.js +12 -67
  61. package/dist/ui/blockquote-button/index.mjs +2 -4
  62. package/dist/ui/blockquote-button/use-blockquote.js +12 -65
  63. package/dist/ui/blockquote-button/use-blockquote.mjs +1 -3
  64. package/dist/ui/codeblock-button/code-block-button.js +13 -76
  65. package/dist/ui/codeblock-button/code-block-button.mjs +2 -4
  66. package/dist/ui/codeblock-button/index.js +13 -76
  67. package/dist/ui/codeblock-button/index.mjs +2 -4
  68. package/dist/ui/codeblock-button/use-code-block.js +12 -65
  69. package/dist/ui/codeblock-button/use-code-block.mjs +1 -3
  70. package/dist/ui/color-highlight-button/color-highlight-button.js +3 -23
  71. package/dist/ui/color-highlight-button/color-highlight-button.mjs +2 -4
  72. package/dist/ui/color-highlight-button/index.js +3 -23
  73. package/dist/ui/color-highlight-button/index.mjs +2 -4
  74. package/dist/ui/color-highlight-button/use-color-highlight.js +3 -21
  75. package/dist/ui/color-highlight-button/use-color-highlight.mjs +1 -3
  76. package/dist/ui/color-highlight-popover/color-highlight-popover.js +4 -24
  77. package/dist/ui/color-highlight-popover/color-highlight-popover.mjs +3 -5
  78. package/dist/ui/color-highlight-popover/index.js +4 -24
  79. package/dist/ui/color-highlight-popover/index.mjs +3 -5
  80. package/dist/ui/copy-anchor-link-button/use-scroll-to-hash.js +2 -18
  81. package/dist/ui/copy-anchor-link-button/use-scroll-to-hash.mjs +1 -3
  82. package/dist/ui/heading-button/index.js +2 -9
  83. package/dist/ui/heading-button/index.mjs +1 -3
  84. package/dist/ui/heading-button/utils.mjs +0 -1
  85. package/dist/ui/heading-dropdown-menu/index.js +4 -10
  86. package/dist/ui/heading-dropdown-menu/index.mjs +2 -4
  87. package/dist/ui/link-popover/index.js +2 -6
  88. package/dist/ui/link-popover/index.mjs +3 -4
  89. package/dist/ui/link-popover/link-popover.js +2 -6
  90. package/dist/ui/link-popover/link-popover.mjs +3 -4
  91. package/dist/ui/link-popover/use-link-popover.js +2 -6
  92. package/dist/ui/link-popover/use-link-popover.mjs +2 -3
  93. package/dist/ui/list-button/index.js +2 -9
  94. package/dist/ui/list-button/index.mjs +1 -3
  95. package/dist/ui/list-dropdown-menu/index.js +4 -10
  96. package/dist/ui/list-dropdown-menu/index.mjs +2 -4
  97. package/dist/ui/mark-button/index.js +3 -21
  98. package/dist/ui/mark-button/index.mjs +1 -3
  99. package/dist/ui/reset-all-formatting-button/index.mjs +0 -1
  100. package/dist/ui/reset-all-formatting-button/reset-all-formatting-button.mjs +0 -1
  101. package/dist/ui/reset-all-formatting-button/use-reset-all-formatting.mjs +0 -1
  102. package/dist/ui/slash-dropdown-menu/index.js +27 -129
  103. package/dist/ui/slash-dropdown-menu/index.mjs +3 -5
  104. package/dist/ui/slash-dropdown-menu/slash-dropdown-menu.js +27 -129
  105. package/dist/ui/slash-dropdown-menu/slash-dropdown-menu.mjs +3 -5
  106. package/dist/ui/slash-dropdown-menu/use-slash-dropdown-menu.js +23 -116
  107. package/dist/ui/slash-dropdown-menu/use-slash-dropdown-menu.mjs +2 -4
  108. package/dist/ui/suggestion-menu/index.mjs +0 -1
  109. package/dist/ui/suggestion-menu/suggestion-menu-utils.mjs +0 -1
  110. package/dist/ui/suggestion-menu/suggestion-menu.mjs +0 -1
  111. package/dist/ui/table-button/index.js +4 -24
  112. package/dist/ui/table-button/index.mjs +2 -4
  113. package/dist/ui/table-button/use-table.js +3 -21
  114. package/dist/ui/table-button/use-table.mjs +1 -3
  115. package/dist/ui/text-align-button/index.js +3 -32
  116. package/dist/ui/text-align-button/index.mjs +2 -4
  117. package/dist/ui/text-align-button/text-align-button.js +3 -32
  118. package/dist/ui/text-align-button/text-align-button.mjs +2 -4
  119. package/dist/ui/text-align-button/use-text-align.js +3 -30
  120. package/dist/ui/text-align-button/use-text-align.mjs +1 -3
  121. package/dist/ui/undo-redo-button/index.js +2 -18
  122. package/dist/ui/undo-redo-button/index.mjs +2 -4
  123. package/dist/ui/undo-redo-button/undo-redo-button.js +2 -18
  124. package/dist/ui/undo-redo-button/undo-redo-button.mjs +2 -4
  125. package/dist/ui/undo-redo-button/use-undo-redo.js +2 -16
  126. package/dist/ui/undo-redo-button/use-undo-redo.mjs +1 -3
  127. package/dist/utils/index.d.mts +1 -101
  128. package/dist/utils/index.d.ts +1 -101
  129. package/dist/utils/index.js +0 -166
  130. package/dist/utils/index.mjs +1 -28
  131. package/dist/utils/safe-parse.mjs +0 -1
  132. package/package.json +36 -30
  133. package/dist/chunk-4HTILXJM.mjs +0 -104
  134. package/dist/chunk-4IIGLBTD.mjs +0 -81
  135. package/dist/chunk-574UV65T.mjs +0 -111
  136. package/dist/chunk-7HC7D256.mjs +0 -91
  137. package/dist/chunk-AC22DSDA.mjs +0 -540
  138. package/dist/chunk-AGOMESFC.mjs +0 -1
  139. package/dist/chunk-BXPGSCTT.mjs +0 -39
  140. package/dist/chunk-C6M3CDOK.mjs +0 -254
  141. package/dist/chunk-EN3J5AMF.mjs +0 -12
  142. package/dist/chunk-HYDS6H67.mjs +0 -58
  143. package/dist/chunk-KRLE4MMD.mjs +0 -116
  144. package/dist/chunk-LKOQAQPZ.mjs +0 -13
  145. package/dist/chunk-LXZ53XU7.mjs +0 -1
  146. package/dist/chunk-T6P7CS4F.mjs +0 -42
  147. package/dist/chunk-TVFWG7IC.mjs +0 -43
  148. package/dist/chunk-VULWMVYS.mjs +0 -11
  149. package/dist/chunk-WKV76XOR.mjs +0 -8
  150. package/dist/extensions/table/index.d.mts +0 -8
  151. package/dist/extensions/table/index.d.ts +0 -8
  152. package/dist/extensions/table/index.js +0 -1044
  153. package/dist/extensions/table/index.mjs +0 -33
  154. package/dist/extensions/table/kit.d.mts +0 -30
  155. package/dist/extensions/table/kit.d.ts +0 -30
  156. package/dist/extensions/table/kit.js +0 -1034
  157. package/dist/extensions/table/kit.mjs +0 -20
  158. package/dist/extensions/table/table/icons.d.mts +0 -13
  159. package/dist/extensions/table/table/icons.d.ts +0 -13
  160. package/dist/extensions/table/table/icons.js +0 -81
  161. package/dist/extensions/table/table/icons.mjs +0 -8
  162. package/dist/extensions/table/table/index.d.mts +0 -3
  163. package/dist/extensions/table/table/index.d.ts +0 -3
  164. package/dist/extensions/table/table/index.js +0 -818
  165. package/dist/extensions/table/table/index.mjs +0 -16
  166. package/dist/extensions/table/table/table-controls.d.mts +0 -10
  167. package/dist/extensions/table/table/table-controls.d.ts +0 -10
  168. package/dist/extensions/table/table/table-controls.js +0 -129
  169. package/dist/extensions/table/table/table-controls.mjs +0 -8
  170. package/dist/extensions/table/table/table-view.d.mts +0 -43
  171. package/dist/extensions/table/table/table-view.d.ts +0 -43
  172. package/dist/extensions/table/table/table-view.js +0 -610
  173. package/dist/extensions/table/table/table-view.mjs +0 -12
  174. package/dist/extensions/table/table/table.d.mts +0 -17
  175. package/dist/extensions/table/table/table.d.ts +0 -17
  176. package/dist/extensions/table/table/table.js +0 -816
  177. package/dist/extensions/table/table/table.mjs +0 -15
  178. package/dist/extensions/table/table/utilities/col-style.d.mts +0 -3
  179. package/dist/extensions/table/table/utilities/col-style.d.ts +0 -3
  180. package/dist/extensions/table/table/utilities/col-style.js +0 -36
  181. package/dist/extensions/table/table/utilities/col-style.mjs +0 -8
  182. package/dist/extensions/table/table/utilities/delete-table-when-all-cells-selected.d.mts +0 -5
  183. package/dist/extensions/table/table/utilities/delete-table-when-all-cells-selected.d.ts +0 -5
  184. package/dist/extensions/table/table/utilities/delete-table-when-all-cells-selected.js +0 -66
  185. package/dist/extensions/table/table/utilities/delete-table-when-all-cells-selected.mjs +0 -40
  186. package/dist/extensions/table/table/utilities/get-table-node-types.d.mts +0 -7
  187. package/dist/extensions/table/table/utilities/get-table-node-types.d.ts +0 -7
  188. package/dist/extensions/table/table/utilities/get-table-node-types.js +0 -44
  189. package/dist/extensions/table/table/utilities/get-table-node-types.mjs +0 -21
  190. package/dist/extensions/table/table/utilities/insert-line-above-table-action.d.mts +0 -5
  191. package/dist/extensions/table/table/utilities/insert-line-above-table-action.d.ts +0 -5
  192. package/dist/extensions/table/table/utilities/insert-line-above-table-action.js +0 -80
  193. package/dist/extensions/table/table/utilities/insert-line-above-table-action.mjs +0 -9
  194. package/dist/extensions/table/table/utilities/insert-line-below-table-action.d.mts +0 -5
  195. package/dist/extensions/table/table/utilities/insert-line-below-table-action.d.ts +0 -5
  196. package/dist/extensions/table/table/utilities/insert-line-below-table-action.js +0 -79
  197. package/dist/extensions/table/table/utilities/insert-line-below-table-action.mjs +0 -9
  198. package/dist/extensions/table/table/utilities/is-cell-selection.d.mts +0 -5
  199. package/dist/extensions/table/table/utilities/is-cell-selection.d.ts +0 -5
  200. package/dist/extensions/table/table/utilities/is-cell-selection.js +0 -34
  201. package/dist/extensions/table/table/utilities/is-cell-selection.mjs +0 -8
  202. package/dist/extensions/table/table-cell.d.mts +0 -8
  203. package/dist/extensions/table/table-cell.d.ts +0 -8
  204. package/dist/extensions/table/table-cell.js +0 -139
  205. package/dist/extensions/table/table-cell.mjs +0 -8
  206. package/dist/extensions/table/table-header.d.mts +0 -6
  207. package/dist/extensions/table/table-header.d.ts +0 -6
  208. package/dist/extensions/table/table-header.js +0 -104
  209. package/dist/extensions/table/table-header.mjs +0 -8
  210. package/dist/extensions/table/table-row.d.mts +0 -6
  211. package/dist/extensions/table/table-row.d.ts +0 -6
  212. package/dist/extensions/table/table-row.js +0 -35
  213. package/dist/extensions/table/table-row.mjs +0 -8
@@ -1,540 +0,0 @@
1
- "use client";
2
- import {
3
- getColStyleDeclaration
4
- } from "./chunk-LKOQAQPZ.mjs";
5
- import {
6
- icons
7
- } from "./chunk-HYDS6H67.mjs";
8
- import {
9
- __publicField
10
- } from "./chunk-WKV76XOR.mjs";
11
-
12
- // src/extensions/table/table/table-view.tsx
13
- import {
14
- autoUpdate,
15
- computePosition,
16
- flip,
17
- offset,
18
- shift
19
- } from "@floating-ui/dom";
20
- import {
21
- CellSelection,
22
- TableMap,
23
- updateColumnsOnResize
24
- } from "@tiptap/pm/tables";
25
- import { h } from "jsx-dom-cjs";
26
- var Popover = class {
27
- constructor(content, opts) {
28
- __publicField(this, "reference");
29
- __publicField(this, "floating");
30
- __publicField(this, "cleanupAutoUpdate", null);
31
- __publicField(this, "onDocClick", (e) => {
32
- if (!this.floating.contains(e.target) && !this.reference.contains(e.target)) {
33
- this.hide();
34
- }
35
- });
36
- __publicField(this, "onEsc", (e) => {
37
- if (e.key === "Escape") this.hide();
38
- });
39
- __publicField(this, "_placement");
40
- __publicField(this, "_offsetPx");
41
- // biome-ignore lint/correctness/noUnusedPrivateClassMembers: backwards. will be used later
42
- __publicField(this, "_interactive");
43
- var _a, _b, _c, _d;
44
- this.reference = opts.reference;
45
- this.floating = document.createElement("div");
46
- this.floating.setAttribute("role", "dialog");
47
- this.floating.setAttribute("aria-modal", "false");
48
- this.floating.style.position = "fixed";
49
- this.floating.style.zIndex = "9999";
50
- this.floating.style.display = "none";
51
- this.floating.className = "rounded-md border bg-background px-2 py-2.5 text-xs shadow-sm min-w-[12rem] whitespace-nowrap";
52
- this.floating.appendChild(content);
53
- const host = (_a = opts.container) != null ? _a : document.body;
54
- host.appendChild(this.floating);
55
- this._placement = (_b = opts.placement) != null ? _b : "right";
56
- this._offsetPx = (_c = opts.offsetPx) != null ? _c : 6;
57
- this._interactive = (_d = opts.interactive) != null ? _d : true;
58
- }
59
- async _updatePosition() {
60
- const { x, y } = await computePosition(this.reference, this.floating, {
61
- placement: this._placement,
62
- middleware: [offset(this._offsetPx), flip(), shift({ padding: 8 })]
63
- });
64
- Object.assign(this.floating.style, { left: `${x}px`, top: `${y}px` });
65
- }
66
- show() {
67
- if (this.floating.style.display !== "none") return;
68
- this.floating.style.display = "block";
69
- this.cleanupAutoUpdate = autoUpdate(
70
- this.reference,
71
- this.floating,
72
- () => this._updatePosition()
73
- );
74
- document.addEventListener("keydown", this.onEsc, { passive: true });
75
- document.addEventListener("mousedown", this.onDocClick, { capture: true });
76
- requestAnimationFrame(() => this._updatePosition());
77
- }
78
- hide() {
79
- var _a;
80
- if (this.floating.style.display === "none") return;
81
- this.floating.style.display = "none";
82
- (_a = this.cleanupAutoUpdate) == null ? void 0 : _a.call(this);
83
- this.cleanupAutoUpdate = null;
84
- document.removeEventListener("keydown", this.onEsc);
85
- document.removeEventListener("mousedown", this.onDocClick, {
86
- capture: true
87
- });
88
- }
89
- toggle() {
90
- if (this.floating.style.display === "none") this.show();
91
- else this.hide();
92
- }
93
- destroy() {
94
- this.hide();
95
- this.floating.remove();
96
- }
97
- get el() {
98
- return this.floating;
99
- }
100
- };
101
- function updateColumns(node, colgroup, table, cellMinWidth, overrideCol, overrideValue) {
102
- var _a;
103
- let totalWidth = 0;
104
- let fixedWidth = true;
105
- let nextDOM = colgroup.firstChild;
106
- const row = node.firstChild;
107
- if (row !== null) {
108
- for (let i = 0, col = 0; i < row.childCount; i += 1) {
109
- const { colspan, colwidth } = row.child(i).attrs;
110
- for (let j = 0; j < colspan; j += 1, col += 1) {
111
- const hasWidth = overrideCol === col ? overrideValue : colwidth == null ? void 0 : colwidth[j];
112
- const cssWidth = hasWidth ? `${hasWidth}px` : "";
113
- totalWidth += hasWidth || cellMinWidth;
114
- if (!hasWidth) fixedWidth = false;
115
- if (!nextDOM) {
116
- const colElement = document.createElement("col");
117
- const [key, val] = getColStyleDeclaration(cellMinWidth, hasWidth);
118
- colElement.style.setProperty(key, val);
119
- colgroup.appendChild(colElement);
120
- } else {
121
- const colEl = nextDOM;
122
- if (colEl.style.width !== cssWidth) {
123
- const [key, val] = getColStyleDeclaration(cellMinWidth, hasWidth);
124
- colEl.style.setProperty(key, val);
125
- }
126
- nextDOM = nextDOM.nextSibling;
127
- }
128
- }
129
- }
130
- }
131
- while (nextDOM) {
132
- const after = nextDOM.nextSibling;
133
- (_a = nextDOM.parentNode) == null ? void 0 : _a.removeChild(nextDOM);
134
- nextDOM = after;
135
- }
136
- if (fixedWidth) {
137
- table.style.width = `${totalWidth}px`;
138
- table.style.minWidth = "";
139
- } else {
140
- table.style.width = "";
141
- table.style.minWidth = `${totalWidth}px`;
142
- }
143
- }
144
- function setCellsBackgroundColor(editor, color) {
145
- return editor.chain().focus().updateAttributes("tableCell", {
146
- background: color.backgroundColor,
147
- textColor: color.textColor
148
- }).run();
149
- }
150
- function setTableRowBackgroundColor(editor, color) {
151
- const { state, dispatch } = editor.view;
152
- const { selection } = state;
153
- if (!(selection instanceof CellSelection)) return false;
154
- const hoveredCell = selection.$headCell || selection.$anchorCell;
155
- let rowDepth = hoveredCell.depth;
156
- while (rowDepth > 0 && hoveredCell.node(rowDepth).type.name !== "tableRow") {
157
- rowDepth--;
158
- }
159
- if (hoveredCell.node(rowDepth).type.name !== "tableRow") return false;
160
- const rowStartPos = hoveredCell.start(rowDepth);
161
- const tr = state.tr.setNodeMarkup(rowStartPos - 1, null, {
162
- ...hoveredCell.node(rowDepth).attrs,
163
- background: color.backgroundColor,
164
- textColor: color.textColor
165
- });
166
- dispatch(tr);
167
- return true;
168
- }
169
- var columnsToolboxItems = [
170
- {
171
- label: "Toggle column header",
172
- icon: icons.toggleColumnHeader,
173
- action: ({ editor }) => editor.chain().focus().toggleHeaderColumn().run()
174
- },
175
- {
176
- label: "Add column before",
177
- icon: icons.insertLeftTableIcon,
178
- action: ({ editor }) => editor.chain().focus().addColumnBefore().run()
179
- },
180
- {
181
- label: "Add column after",
182
- icon: icons.insertRightTableIcon,
183
- action: ({ editor }) => editor.chain().focus().addColumnAfter().run()
184
- },
185
- { label: "Pick color", icon: "", action: () => {
186
- } },
187
- {
188
- label: "Delete column",
189
- icon: icons.deleteColumn,
190
- action: ({ editor }) => editor.chain().focus().deleteColumn().run()
191
- }
192
- ];
193
- var rowsToolboxItems = [
194
- {
195
- label: "Toggle row header",
196
- icon: icons.toggleRowHeader,
197
- action: ({ editor }) => editor.chain().focus().toggleHeaderRow().run()
198
- },
199
- {
200
- label: "Add row above",
201
- icon: icons.insertTopTableIcon,
202
- action: ({ editor }) => editor.chain().focus().addRowBefore().run()
203
- },
204
- {
205
- label: "Add row below",
206
- icon: icons.insertBottomTableIcon,
207
- action: ({ editor }) => editor.chain().focus().addRowAfter().run()
208
- },
209
- { label: "Pick color", icon: "", action: () => {
210
- } },
211
- {
212
- label: "Delete row",
213
- icon: icons.deleteRow,
214
- action: ({ editor }) => editor.chain().focus().deleteRow().run()
215
- }
216
- ];
217
- function buildToolboxContent({
218
- items,
219
- onClickItem,
220
- onSelectColor,
221
- colors
222
- }) {
223
- return h(
224
- "div",
225
- { className: "space-y-2" },
226
- items.map((item) => {
227
- if (item.label === "Pick color") {
228
- return h("div", { className: "flex flex-col" }, [
229
- h("hr", { className: "!my-2 border" }),
230
- h("div", { className: "text-foreground text-sm" }, item.label),
231
- h(
232
- "div",
233
- { className: "grid grid-cols-6 gap-x-1 gap-y-2.5 mt-2" },
234
- Object.entries(colors).map(
235
- ([_, colorValue]) => {
236
- var _a;
237
- return h("button", {
238
- // @ts-expect-error JSX
239
- type: "button",
240
- className: "grid place-items-center size-6 rounded outline-none ring-offset-2 focus-visible:ring",
241
- style: `background-color:${colorValue.backgroundColor};color:${colorValue.textColor || "inherit"};`,
242
- innerHTML: (_a = colorValue.icon) != null ? _a : `<span class="text-md" style="color:${colorValue.textColor || "inherit"}">A</span>`,
243
- onClick: (e) => {
244
- e.stopPropagation();
245
- onSelectColor(colorValue);
246
- }
247
- });
248
- }
249
- )
250
- ),
251
- h("hr", { className: "!my-2 border" })
252
- ]);
253
- }
254
- return h(
255
- "button",
256
- {
257
- // @ts-expect-error JSX
258
- type: "button",
259
- className: "w-full flex items-center gap-2 px-1 py-1.5 bg-background hover:bg-muted text-sm text-foreground rounded",
260
- onClick: (e) => {
261
- e.stopPropagation();
262
- onClickItem(item);
263
- }
264
- },
265
- [
266
- h("span", { className: "h-3 w-3 shrink-0", innerHTML: item.icon }),
267
- h("div", { className: "label" }, item.label)
268
- ]
269
- );
270
- })
271
- );
272
- }
273
- function createToolbox({
274
- triggerButton,
275
- items,
276
- onSelectColor,
277
- onClickItem,
278
- colors,
279
- appendTo
280
- }) {
281
- if (!triggerButton) {
282
- return null;
283
- }
284
- const content = buildToolboxContent({
285
- items,
286
- onClickItem,
287
- onSelectColor,
288
- colors
289
- });
290
- const pop = new Popover(content, {
291
- reference: triggerButton,
292
- container: appendTo != null ? appendTo : void 0,
293
- placement: "right",
294
- offsetPx: 6,
295
- interactive: true
296
- });
297
- const onTrigger = (e) => {
298
- e.stopPropagation();
299
- pop.toggle();
300
- };
301
- triggerButton.addEventListener("click", onTrigger);
302
- return {
303
- show: () => pop.show(),
304
- hide: () => pop.hide(),
305
- destroy: () => {
306
- pop.destroy();
307
- triggerButton.removeEventListener("click", onTrigger);
308
- }
309
- };
310
- }
311
- var TableView = class {
312
- constructor(node, cellMinWidth, decorations, editor, getPos) {
313
- __publicField(this, "node");
314
- __publicField(this, "cellMinWidth");
315
- __publicField(this, "decorations");
316
- __publicField(this, "editor");
317
- __publicField(this, "getPos");
318
- __publicField(this, "hoveredCell", null);
319
- __publicField(this, "map");
320
- __publicField(this, "root");
321
- __publicField(this, "table");
322
- __publicField(this, "colgroup");
323
- __publicField(this, "tbody");
324
- __publicField(this, "rowsControl");
325
- __publicField(this, "columnsControl");
326
- __publicField(this, "columnsToolbox");
327
- __publicField(this, "rowsToolbox");
328
- __publicField(this, "controls");
329
- var _a, _b, _c, _d;
330
- this.node = node;
331
- this.cellMinWidth = cellMinWidth;
332
- this.decorations = decorations.slice();
333
- this.editor = editor;
334
- this.getPos = getPos;
335
- this.hoveredCell = null;
336
- this.map = TableMap.get(node);
337
- if (editor.isEditable) {
338
- this.rowsControl = h(
339
- "div",
340
- { className: "rows-control" },
341
- h("button", {
342
- // @ts-expect-error JSX
343
- type: "button",
344
- className: "rows-control-div",
345
- onClick: () => this.selectRow(),
346
- "aria-label": "Row actions"
347
- })
348
- );
349
- this.columnsControl = h(
350
- "div",
351
- { className: "columns-control" },
352
- h("button", {
353
- // @ts-expect-error JSX
354
- type: "button",
355
- className: "columns-control-div",
356
- onClick: () => this.selectColumn(),
357
- "aria-label": "Column actions"
358
- })
359
- );
360
- this.controls = h(
361
- "div",
362
- { className: "table-controls", contentEditable: "false" },
363
- this.rowsControl,
364
- this.columnsControl
365
- );
366
- const palette = {
367
- Blue: { backgroundColor: "#D9E4FF", textColor: "#171717" },
368
- Orange: { backgroundColor: "#FFEDD5", textColor: "#171717" },
369
- Grey: { backgroundColor: "#F1F1F1", textColor: "#171717" },
370
- Yellow: { backgroundColor: "#FEF3C7", textColor: "#171717" },
371
- Green: { backgroundColor: "#DCFCE7", textColor: "#171717" },
372
- Red: { backgroundColor: "#FFDDDD", textColor: "#171717" },
373
- Pink: { backgroundColor: "#FFE8FA", textColor: "#171717" },
374
- Purple: { backgroundColor: "#E8DAFB", textColor: "#171717" },
375
- None: {
376
- backgroundColor: "transparent",
377
- textColor: "inherit",
378
- icon: `<svg xmlns="http://www.w3.org/2000/svg" width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="gray" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-ban"><circle cx="12" cy="12" r="10"/><path d="m4.9 4.9 14.2 14.2"/></svg>`
379
- }
380
- };
381
- this.columnsToolbox = createToolbox({
382
- triggerButton: (_a = this.columnsControl) == null ? void 0 : _a.querySelector(
383
- ".columns-control-div"
384
- ),
385
- items: columnsToolboxItems,
386
- colors: palette,
387
- appendTo: (_b = this.controls) != null ? _b : null,
388
- onSelectColor: (color) => setCellsBackgroundColor(this.editor, color),
389
- onClickItem: (item) => {
390
- var _a2, _b2;
391
- item.action({
392
- editor: this.editor,
393
- triggerButton: (_a2 = this.columnsControl) == null ? void 0 : _a2.firstElementChild,
394
- controlsContainer: this.controls
395
- });
396
- (_b2 = this.columnsToolbox) == null ? void 0 : _b2.hide();
397
- }
398
- });
399
- this.rowsToolbox = createToolbox({
400
- triggerButton: (_c = this.rowsControl) == null ? void 0 : _c.querySelector(
401
- ".rows-control-div"
402
- ),
403
- items: rowsToolboxItems,
404
- colors: palette,
405
- appendTo: (_d = this.controls) != null ? _d : null,
406
- onSelectColor: (color) => setTableRowBackgroundColor(editor, color),
407
- onClickItem: (item) => {
408
- var _a2, _b2;
409
- item.action({
410
- editor: this.editor,
411
- triggerButton: (_a2 = this.rowsControl) == null ? void 0 : _a2.firstElementChild,
412
- controlsContainer: this.controls
413
- });
414
- (_b2 = this.rowsToolbox) == null ? void 0 : _b2.hide();
415
- }
416
- });
417
- }
418
- this.colgroup = h(
419
- "colgroup",
420
- null,
421
- Array.from({ length: this.map.width }, () => 1).map(() => h("col"))
422
- );
423
- this.tbody = h("tbody");
424
- this.table = h(
425
- "table",
426
- null,
427
- this.colgroup,
428
- this.tbody
429
- );
430
- this.root = h(
431
- "div",
432
- {
433
- className: "table-wrapper horizontal-scrollbar scrollbar-md controls--disabled"
434
- },
435
- this.controls,
436
- this.table
437
- );
438
- this.render();
439
- }
440
- get dom() {
441
- return this.root;
442
- }
443
- get contentDOM() {
444
- return this.tbody;
445
- }
446
- update(node, decorations) {
447
- if (node.type !== this.node.type) return false;
448
- this.node = node;
449
- this.decorations = [...decorations];
450
- this.map = TableMap.get(this.node);
451
- if (this.editor.isEditable) this.updateControls();
452
- this.render();
453
- return true;
454
- }
455
- render() {
456
- if (this.colgroup.children.length !== this.map.width) {
457
- const cols = Array.from({ length: this.map.width }, () => 1).map(
458
- () => h("col")
459
- );
460
- this.colgroup.replaceChildren(...cols);
461
- }
462
- updateColumnsOnResize(
463
- this.node,
464
- this.colgroup,
465
- this.table,
466
- this.cellMinWidth
467
- );
468
- }
469
- ignoreMutation() {
470
- return true;
471
- }
472
- updateControls() {
473
- var _a;
474
- const { hoveredTable: table, hoveredCell: cell } = Object.values(
475
- this.decorations
476
- ).reduce(
477
- (acc, curr) => {
478
- if (curr.spec.hoveredCell !== void 0)
479
- acc.hoveredCell = curr.spec.hoveredCell;
480
- if (curr.spec.hoveredTable !== void 0)
481
- acc.hoveredTable = curr.spec.hoveredTable;
482
- return acc;
483
- },
484
- {}
485
- );
486
- if (table === void 0 || cell === void 0) {
487
- this.root.classList.add("controls--disabled");
488
- return;
489
- }
490
- this.root.classList.remove("controls--disabled");
491
- this.hoveredCell = cell;
492
- const cellDom = this.editor.view.nodeDOM(cell.pos);
493
- if (!this.table || !cellDom) return;
494
- const tableRect = this.table.getBoundingClientRect();
495
- const cellRect = cellDom.getBoundingClientRect();
496
- if (this.columnsControl) {
497
- this.columnsControl.style.left = `${cellRect.left - tableRect.left - (((_a = this.table.parentElement) == null ? void 0 : _a.scrollLeft) || 0)}px`;
498
- this.columnsControl.style.width = `${cellRect.width}px`;
499
- }
500
- if (this.rowsControl) {
501
- this.rowsControl.style.top = `${cellRect.top - tableRect.top}px`;
502
- this.rowsControl.style.height = `${cellRect.height}px`;
503
- }
504
- }
505
- selectColumn() {
506
- if (!this.hoveredCell) return;
507
- const colIndex = this.map.colCount(
508
- this.hoveredCell.pos - (this.getPos() + 1)
509
- );
510
- const anchorCellPos = this.hoveredCell.pos;
511
- const headCellPos = this.map.map[colIndex + this.map.width * (this.map.height - 1)] + (this.getPos() + 1);
512
- const cellSelection = CellSelection.create(
513
- this.editor.view.state.doc,
514
- anchorCellPos,
515
- headCellPos
516
- );
517
- this.editor.view.dispatch(this.editor.state.tr.setSelection(cellSelection));
518
- }
519
- selectRow() {
520
- if (!this.hoveredCell) return;
521
- const anchorCellPos = this.hoveredCell.pos;
522
- const anchorCellIndex = this.map.map.indexOf(
523
- anchorCellPos - (this.getPos() + 1)
524
- );
525
- const headCellPos = this.map.map[anchorCellIndex + (this.map.width - 1)] + (this.getPos() + 1);
526
- const cellSelection = CellSelection.create(
527
- this.editor.state.doc,
528
- anchorCellPos,
529
- headCellPos
530
- );
531
- this.editor.view.dispatch(
532
- this.editor.view.state.tr.setSelection(cellSelection)
533
- );
534
- }
535
- };
536
-
537
- export {
538
- updateColumns,
539
- TableView
540
- };
@@ -1 +0,0 @@
1
- "use client";
@@ -1,39 +0,0 @@
1
- "use client";
2
- import {
3
- Table
4
- } from "./chunk-7HC7D256.mjs";
5
- import {
6
- TableCell
7
- } from "./chunk-KRLE4MMD.mjs";
8
- import {
9
- TableHeader
10
- } from "./chunk-4IIGLBTD.mjs";
11
- import {
12
- TableRow
13
- } from "./chunk-EN3J5AMF.mjs";
14
-
15
- // src/extensions/table/kit.ts
16
- import { Extension } from "@tiptap/react";
17
- var TableKit = Extension.create({
18
- name: "tableKit",
19
- addExtensions() {
20
- const extensions = [];
21
- if (this.options.table !== false) {
22
- extensions.push(Table.configure(this.options.table));
23
- }
24
- if (this.options.tableCell !== false) {
25
- extensions.push(TableCell.configure(this.options.tableCell));
26
- }
27
- if (this.options.tableHeader !== false) {
28
- extensions.push(TableHeader.configure(this.options.tableHeader));
29
- }
30
- if (this.options.tableRow !== false) {
31
- extensions.push(TableRow.configure(this.options.tableRow));
32
- }
33
- return extensions;
34
- }
35
- });
36
-
37
- export {
38
- TableKit
39
- };