@kopexa/tiptap 1.0.0 → 13.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 +40 -34
  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,1034 +0,0 @@
1
- "use client";
2
- "use strict";
3
- var __defProp = Object.defineProperty;
4
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
- var __getOwnPropNames = Object.getOwnPropertyNames;
6
- var __hasOwnProp = Object.prototype.hasOwnProperty;
7
- var __defNormalProp = (obj, key2, value) => key2 in obj ? __defProp(obj, key2, { enumerable: true, configurable: true, writable: true, value }) : obj[key2] = value;
8
- var __export = (target, all) => {
9
- for (var name in all)
10
- __defProp(target, name, { get: all[name], enumerable: true });
11
- };
12
- var __copyProps = (to, from, except, desc) => {
13
- if (from && typeof from === "object" || typeof from === "function") {
14
- for (let key2 of __getOwnPropNames(from))
15
- if (!__hasOwnProp.call(to, key2) && key2 !== except)
16
- __defProp(to, key2, { get: () => from[key2], enumerable: !(desc = __getOwnPropDesc(from, key2)) || desc.enumerable });
17
- }
18
- return to;
19
- };
20
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
21
- var __publicField = (obj, key2, value) => __defNormalProp(obj, typeof key2 !== "symbol" ? key2 + "" : key2, value);
22
-
23
- // src/extensions/table/kit.ts
24
- var kit_exports = {};
25
- __export(kit_exports, {
26
- TableKit: () => TableKit
27
- });
28
- module.exports = __toCommonJS(kit_exports);
29
- var import_react = require("@tiptap/react");
30
-
31
- // src/extensions/table/table/table.ts
32
- var import_extension_table = require("@tiptap/extension-table");
33
- var import_tables2 = require("@tiptap/pm/tables");
34
-
35
- // src/extensions/table/table/table-controls.ts
36
- var import_core = require("@tiptap/core");
37
- var import_state = require("@tiptap/pm/state");
38
- var import_view = require("@tiptap/pm/view");
39
- var key = new import_state.PluginKey("tableControls");
40
- function tableControls() {
41
- return new import_state.Plugin({
42
- key,
43
- state: {
44
- init() {
45
- return new TableControlsState();
46
- },
47
- apply(tr, prev) {
48
- return prev.apply(tr);
49
- }
50
- },
51
- props: {
52
- handleDOMEvents: {
53
- mousemove: (view, event) => {
54
- var _a;
55
- const pluginState = key.getState(view.state);
56
- if (!event.target.closest(".table-wrapper") && pluginState.values.hoveredTable) {
57
- return view.dispatch(
58
- view.state.tr.setMeta(key, {
59
- setHoveredTable: null,
60
- setHoveredCell: null
61
- })
62
- );
63
- }
64
- const pos = view.posAtCoords({
65
- left: event.clientX,
66
- top: event.clientY
67
- });
68
- if (!pos || pos.pos < 0 || pos.pos > view.state.doc.content.size)
69
- return;
70
- const table = (0, import_core.findParentNode)((node) => node.type.name === "table")(
71
- import_state.TextSelection.create(view.state.doc, pos.pos)
72
- );
73
- const cell = (0, import_core.findParentNode)(
74
- (node) => node.type.name === "tableCell" || node.type.name === "tableHeader"
75
- )(import_state.TextSelection.create(view.state.doc, pos.pos));
76
- if (!table || !cell) return;
77
- if (((_a = pluginState.values.hoveredCell) == null ? void 0 : _a.pos) !== cell.pos) {
78
- return view.dispatch(
79
- view.state.tr.setMeta(key, {
80
- setHoveredTable: table,
81
- setHoveredCell: cell
82
- })
83
- );
84
- }
85
- }
86
- },
87
- decorations: (state) => {
88
- const pluginState = key.getState(state);
89
- if (!pluginState) {
90
- return null;
91
- }
92
- const { hoveredTable, hoveredCell } = pluginState.values;
93
- const docSize = state.doc.content.size;
94
- if (hoveredTable && hoveredCell && hoveredTable.pos < docSize && hoveredCell.pos < docSize) {
95
- const decorations = [
96
- import_view.Decoration.node(
97
- hoveredTable.pos,
98
- hoveredTable.pos + hoveredTable.node.nodeSize,
99
- {},
100
- {
101
- hoveredTable,
102
- hoveredCell
103
- }
104
- )
105
- ];
106
- return import_view.DecorationSet.create(state.doc, decorations);
107
- }
108
- return null;
109
- }
110
- }
111
- });
112
- }
113
- var TableControlsState = class {
114
- constructor(props = {}) {
115
- __publicField(this, "values");
116
- this.values = {
117
- hoveredTable: null,
118
- hoveredCell: null,
119
- ...props
120
- };
121
- }
122
- apply(tr) {
123
- const actions = tr.getMeta(key);
124
- if ((actions == null ? void 0 : actions.setHoveredTable) !== void 0) {
125
- this.values.hoveredTable = actions.setHoveredTable;
126
- }
127
- if ((actions == null ? void 0 : actions.setHoveredCell) !== void 0) {
128
- this.values.hoveredCell = actions.setHoveredCell;
129
- }
130
- return this;
131
- }
132
- };
133
-
134
- // src/extensions/table/table/table-view.tsx
135
- var import_dom = require("@floating-ui/dom");
136
- var import_tables = require("@tiptap/pm/tables");
137
- var import_jsx_dom_cjs = require("jsx-dom-cjs");
138
-
139
- // src/extensions/table/table/icons.ts
140
- var icons = {
141
- colorPicker: `<svg xmlns="http://www.w3.org/2000/svg" length="24" viewBox="0 0 24 24" style="transform: ;msFilter:;"><path fill="rgb(var(--color-text-300))" d="M20 14c-.092.064-2 2.083-2 3.5 0 1.494.949 2.448 2 2.5.906.044 2-.891 2-2.5 0-1.5-1.908-3.436-2-3.5zM9.586 20c.378.378.88.586 1.414.586s1.036-.208 1.414-.586l7-7-.707-.707L11 4.586 8.707 2.293 7.293 3.707 9.586 6 4 11.586c-.378.378-.586.88-.586 1.414s.208 1.036.586 1.414L9.586 20zM11 7.414 16.586 13H5.414L11 7.414z"></path></svg>`,
142
- deleteColumn: `<svg xmlns="http://www.w3.org/2000/svg" width="12" height="12" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-trash-2"><path d="M3 6h18"/><path d="M19 6v14c0 1-1 2-2 2H7c-1 0-2-1-2-2V6"/><path d="M8 6V4c0-1 1-2 2-2h4c1 0 2 1 2 2v2"/><line x1="10" x2="10" y1="11" y2="17"/><line x1="14" x2="14" y1="11" y2="17"/></svg>`,
143
- deleteRow: `<svg xmlns="http://www.w3.org/2000/svg" width="12" height="12" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-trash-2"><path d="M3 6h18"/><path d="M19 6v14c0 1-1 2-2 2H7c-1 0-2-1-2-2V6"/><path d="M8 6V4c0-1 1-2 2-2h4c1 0 2 1 2 2v2"/><line x1="10" x2="10" y1="11" y2="17"/><line x1="14" x2="14" y1="11" y2="17"/></svg>`,
144
- insertLeftTableIcon: `<svg
145
- xmlns="http://www.w3.org/2000/svg"
146
- length={12}
147
- viewBox="0 -960 960 960"
148
- >
149
- <path
150
- d="M224.617-140.001q-30.307 0-51.307-21-21-21-21-51.308v-535.382q0-30.308 21-51.308t51.307-21H360q30.307 0 51.307 21 21 21 21 51.308v535.382q0 30.308-21 51.308t-51.307 21H224.617Zm375.383 0q-30.307 0-51.307-21-21-21-21-51.308v-535.382q0-30.308 21-51.308t51.307-21h135.383q30.307 0 51.307 21 21 21 21 51.308v535.382q0 30.308-21 51.308t-51.307 21H600Zm147.691-607.69q0-4.616-3.846-8.463-3.846-3.846-8.462-3.846H600q-4.616 0-8.462 3.846-3.847 3.847-3.847 8.463v535.382q0 4.616 3.847 8.463Q595.384-200 600-200h135.383q4.616 0 8.462-3.846 3.846-3.847 3.846-8.463v-535.382ZM587.691-200h160-160Z"
151
- fill="rgb(var(--color-text-300))"
152
- />
153
- </svg>
154
- `,
155
- insertRightTableIcon: `<svg
156
- xmlns="http://www.w3.org/2000/svg"
157
- length={12}
158
- viewBox="0 -960 960 960"
159
- >
160
- <path
161
- d="M600-140.001q-30.307 0-51.307-21-21-21-21-51.308v-535.382q0-30.308 21-51.308t51.307-21h135.383q30.307 0 51.307 21 21 21 21 51.308v535.382q0 30.308-21 51.308t-51.307 21H600Zm-375.383 0q-30.307 0-51.307-21-21-21-21-51.308v-535.382q0-30.308 21-51.308t51.307-21H360q30.307 0 51.307 21 21 21 21 51.308v535.382q0 30.308-21 51.308t-51.307 21H224.617Zm-12.308-607.69v535.382q0 4.616 3.846 8.463 3.846 3.846 8.462 3.846H360q4.616 0 8.462-3.846 3.847-3.847 3.847-8.463v-535.382q0-4.616-3.847-8.463Q364.616-760 360-760H224.617q-4.616 0-8.462 3.846-3.846 3.847-3.846 8.463Zm160 547.691h-160 160Z"
162
- fill="rgb(var(--color-text-300))"
163
- />
164
- </svg>
165
- `,
166
- insertTopTableIcon: `<svg
167
- xmlns="http://www.w3.org/2000/svg"
168
- length={24}
169
- viewBox="0 -960 960 960"
170
- >
171
- <path
172
- d="M212.309-527.693q-30.308 0-51.308-21t-21-51.307v-135.383q0-30.307 21-51.307 21-21 51.308-21h535.382q30.308 0 51.308 21t21 51.307V-600q0 30.307-21 51.307-21 21-51.308 21H212.309Zm0 375.383q-30.308 0-51.308-21t-21-51.307V-360q0-30.307 21-51.307 21-21 51.308-21h535.382q30.308 0 51.308 21t21 51.307v135.383q0 30.307-21 51.307-21 21-51.308 21H212.309Zm0-59.999h535.382q4.616 0 8.463-3.846 3.846-3.846 3.846-8.462V-360q0-4.616-3.846-8.462-3.847-3.847-8.463-3.847H212.309q-4.616 0-8.463 3.847Q200-364.616 200-360v135.383q0 4.616 3.846 8.462 3.847 3.846 8.463 3.846Zm-12.309-160v160-160Z"
173
- fill="rgb(var(--color-text-300))"
174
- />
175
- </svg>
176
- `,
177
- toggleColumnHeader: `<svg xmlns="http://www.w3.org/2000/svg" width="12" height="12" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-toggle-right"><rect width="20" height="12" x="2" y="6" rx="6" ry="6"/><circle cx="16" cy="12" r="2"/></svg>`,
178
- toggleRowHeader: `<svg xmlns="http://www.w3.org/2000/svg" width="12" height="12" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-toggle-right"><rect width="20" height="12" x="2" y="6" rx="6" ry="6"/><circle cx="16" cy="12" r="2"/></svg>`,
179
- insertBottomTableIcon: `<svg
180
- xmlns="http://www.w3.org/2000/svg"
181
- length={24}
182
- viewBox="0 -960 960 960"
183
- >
184
- <path
185
- d="M212.309-152.31q-30.308 0-51.308-21t-21-51.307V-360q0-30.307 21-51.307 21-21 51.308-21h535.382q30.308 0 51.308 21t21 51.307v135.383q0 30.307-21 51.307-21 21-51.308 21H212.309Zm0-375.383q-30.308 0-51.308-21t-21-51.307v-135.383q0-30.307 21-51.307 21-21 51.308-21h535.382q30.308 0 51.308 21t21 51.307V-600q0 30.307-21 51.307-21 21-51.308 21H212.309Zm535.382-219.998H212.309q-4.616 0-8.463 3.846-3.846 3.846-3.846 8.462V-600q0 4.616 3.846 8.462 3.847 3.847 8.463 3.847h535.382q4.616 0 8.463-3.847Q760-595.384 760-600v-135.383q0-4.616-3.846-8.462-3.847-3.846-8.463-3.846ZM200-587.691v-160 160Z"
186
- fill="rgb(var(--color-text-300))"
187
- />
188
- </svg>
189
- `
190
- };
191
-
192
- // src/extensions/table/table/table-view.tsx
193
- var Popover = class {
194
- constructor(content, opts) {
195
- __publicField(this, "reference");
196
- __publicField(this, "floating");
197
- __publicField(this, "cleanupAutoUpdate", null);
198
- __publicField(this, "onDocClick", (e) => {
199
- if (!this.floating.contains(e.target) && !this.reference.contains(e.target)) {
200
- this.hide();
201
- }
202
- });
203
- __publicField(this, "onEsc", (e) => {
204
- if (e.key === "Escape") this.hide();
205
- });
206
- __publicField(this, "_placement");
207
- __publicField(this, "_offsetPx");
208
- // biome-ignore lint/correctness/noUnusedPrivateClassMembers: backwards. will be used later
209
- __publicField(this, "_interactive");
210
- var _a, _b, _c, _d;
211
- this.reference = opts.reference;
212
- this.floating = document.createElement("div");
213
- this.floating.setAttribute("role", "dialog");
214
- this.floating.setAttribute("aria-modal", "false");
215
- this.floating.style.position = "fixed";
216
- this.floating.style.zIndex = "9999";
217
- this.floating.style.display = "none";
218
- this.floating.className = "rounded-md border bg-background px-2 py-2.5 text-xs shadow-sm min-w-[12rem] whitespace-nowrap";
219
- this.floating.appendChild(content);
220
- const host = (_a = opts.container) != null ? _a : document.body;
221
- host.appendChild(this.floating);
222
- this._placement = (_b = opts.placement) != null ? _b : "right";
223
- this._offsetPx = (_c = opts.offsetPx) != null ? _c : 6;
224
- this._interactive = (_d = opts.interactive) != null ? _d : true;
225
- }
226
- async _updatePosition() {
227
- const { x, y } = await (0, import_dom.computePosition)(this.reference, this.floating, {
228
- placement: this._placement,
229
- middleware: [(0, import_dom.offset)(this._offsetPx), (0, import_dom.flip)(), (0, import_dom.shift)({ padding: 8 })]
230
- });
231
- Object.assign(this.floating.style, { left: `${x}px`, top: `${y}px` });
232
- }
233
- show() {
234
- if (this.floating.style.display !== "none") return;
235
- this.floating.style.display = "block";
236
- this.cleanupAutoUpdate = (0, import_dom.autoUpdate)(
237
- this.reference,
238
- this.floating,
239
- () => this._updatePosition()
240
- );
241
- document.addEventListener("keydown", this.onEsc, { passive: true });
242
- document.addEventListener("mousedown", this.onDocClick, { capture: true });
243
- requestAnimationFrame(() => this._updatePosition());
244
- }
245
- hide() {
246
- var _a;
247
- if (this.floating.style.display === "none") return;
248
- this.floating.style.display = "none";
249
- (_a = this.cleanupAutoUpdate) == null ? void 0 : _a.call(this);
250
- this.cleanupAutoUpdate = null;
251
- document.removeEventListener("keydown", this.onEsc);
252
- document.removeEventListener("mousedown", this.onDocClick, {
253
- capture: true
254
- });
255
- }
256
- toggle() {
257
- if (this.floating.style.display === "none") this.show();
258
- else this.hide();
259
- }
260
- destroy() {
261
- this.hide();
262
- this.floating.remove();
263
- }
264
- get el() {
265
- return this.floating;
266
- }
267
- };
268
- function setCellsBackgroundColor(editor, color) {
269
- return editor.chain().focus().updateAttributes("tableCell", {
270
- background: color.backgroundColor,
271
- textColor: color.textColor
272
- }).run();
273
- }
274
- function setTableRowBackgroundColor(editor, color) {
275
- const { state, dispatch } = editor.view;
276
- const { selection } = state;
277
- if (!(selection instanceof import_tables.CellSelection)) return false;
278
- const hoveredCell = selection.$headCell || selection.$anchorCell;
279
- let rowDepth = hoveredCell.depth;
280
- while (rowDepth > 0 && hoveredCell.node(rowDepth).type.name !== "tableRow") {
281
- rowDepth--;
282
- }
283
- if (hoveredCell.node(rowDepth).type.name !== "tableRow") return false;
284
- const rowStartPos = hoveredCell.start(rowDepth);
285
- const tr = state.tr.setNodeMarkup(rowStartPos - 1, null, {
286
- ...hoveredCell.node(rowDepth).attrs,
287
- background: color.backgroundColor,
288
- textColor: color.textColor
289
- });
290
- dispatch(tr);
291
- return true;
292
- }
293
- var columnsToolboxItems = [
294
- {
295
- label: "Toggle column header",
296
- icon: icons.toggleColumnHeader,
297
- action: ({ editor }) => editor.chain().focus().toggleHeaderColumn().run()
298
- },
299
- {
300
- label: "Add column before",
301
- icon: icons.insertLeftTableIcon,
302
- action: ({ editor }) => editor.chain().focus().addColumnBefore().run()
303
- },
304
- {
305
- label: "Add column after",
306
- icon: icons.insertRightTableIcon,
307
- action: ({ editor }) => editor.chain().focus().addColumnAfter().run()
308
- },
309
- { label: "Pick color", icon: "", action: () => {
310
- } },
311
- {
312
- label: "Delete column",
313
- icon: icons.deleteColumn,
314
- action: ({ editor }) => editor.chain().focus().deleteColumn().run()
315
- }
316
- ];
317
- var rowsToolboxItems = [
318
- {
319
- label: "Toggle row header",
320
- icon: icons.toggleRowHeader,
321
- action: ({ editor }) => editor.chain().focus().toggleHeaderRow().run()
322
- },
323
- {
324
- label: "Add row above",
325
- icon: icons.insertTopTableIcon,
326
- action: ({ editor }) => editor.chain().focus().addRowBefore().run()
327
- },
328
- {
329
- label: "Add row below",
330
- icon: icons.insertBottomTableIcon,
331
- action: ({ editor }) => editor.chain().focus().addRowAfter().run()
332
- },
333
- { label: "Pick color", icon: "", action: () => {
334
- } },
335
- {
336
- label: "Delete row",
337
- icon: icons.deleteRow,
338
- action: ({ editor }) => editor.chain().focus().deleteRow().run()
339
- }
340
- ];
341
- function buildToolboxContent({
342
- items,
343
- onClickItem,
344
- onSelectColor,
345
- colors
346
- }) {
347
- return (0, import_jsx_dom_cjs.h)(
348
- "div",
349
- { className: "space-y-2" },
350
- items.map((item) => {
351
- if (item.label === "Pick color") {
352
- return (0, import_jsx_dom_cjs.h)("div", { className: "flex flex-col" }, [
353
- (0, import_jsx_dom_cjs.h)("hr", { className: "!my-2 border" }),
354
- (0, import_jsx_dom_cjs.h)("div", { className: "text-foreground text-sm" }, item.label),
355
- (0, import_jsx_dom_cjs.h)(
356
- "div",
357
- { className: "grid grid-cols-6 gap-x-1 gap-y-2.5 mt-2" },
358
- Object.entries(colors).map(
359
- ([_, colorValue]) => {
360
- var _a;
361
- return (0, import_jsx_dom_cjs.h)("button", {
362
- // @ts-expect-error JSX
363
- type: "button",
364
- className: "grid place-items-center size-6 rounded outline-none ring-offset-2 focus-visible:ring",
365
- style: `background-color:${colorValue.backgroundColor};color:${colorValue.textColor || "inherit"};`,
366
- innerHTML: (_a = colorValue.icon) != null ? _a : `<span class="text-md" style="color:${colorValue.textColor || "inherit"}">A</span>`,
367
- onClick: (e) => {
368
- e.stopPropagation();
369
- onSelectColor(colorValue);
370
- }
371
- });
372
- }
373
- )
374
- ),
375
- (0, import_jsx_dom_cjs.h)("hr", { className: "!my-2 border" })
376
- ]);
377
- }
378
- return (0, import_jsx_dom_cjs.h)(
379
- "button",
380
- {
381
- // @ts-expect-error JSX
382
- type: "button",
383
- className: "w-full flex items-center gap-2 px-1 py-1.5 bg-background hover:bg-muted text-sm text-foreground rounded",
384
- onClick: (e) => {
385
- e.stopPropagation();
386
- onClickItem(item);
387
- }
388
- },
389
- [
390
- (0, import_jsx_dom_cjs.h)("span", { className: "h-3 w-3 shrink-0", innerHTML: item.icon }),
391
- (0, import_jsx_dom_cjs.h)("div", { className: "label" }, item.label)
392
- ]
393
- );
394
- })
395
- );
396
- }
397
- function createToolbox({
398
- triggerButton,
399
- items,
400
- onSelectColor,
401
- onClickItem,
402
- colors,
403
- appendTo
404
- }) {
405
- if (!triggerButton) {
406
- return null;
407
- }
408
- const content = buildToolboxContent({
409
- items,
410
- onClickItem,
411
- onSelectColor,
412
- colors
413
- });
414
- const pop = new Popover(content, {
415
- reference: triggerButton,
416
- container: appendTo != null ? appendTo : void 0,
417
- placement: "right",
418
- offsetPx: 6,
419
- interactive: true
420
- });
421
- const onTrigger = (e) => {
422
- e.stopPropagation();
423
- pop.toggle();
424
- };
425
- triggerButton.addEventListener("click", onTrigger);
426
- return {
427
- show: () => pop.show(),
428
- hide: () => pop.hide(),
429
- destroy: () => {
430
- pop.destroy();
431
- triggerButton.removeEventListener("click", onTrigger);
432
- }
433
- };
434
- }
435
- var TableView = class {
436
- constructor(node, cellMinWidth, decorations, editor, getPos) {
437
- __publicField(this, "node");
438
- __publicField(this, "cellMinWidth");
439
- __publicField(this, "decorations");
440
- __publicField(this, "editor");
441
- __publicField(this, "getPos");
442
- __publicField(this, "hoveredCell", null);
443
- __publicField(this, "map");
444
- __publicField(this, "root");
445
- __publicField(this, "table");
446
- __publicField(this, "colgroup");
447
- __publicField(this, "tbody");
448
- __publicField(this, "rowsControl");
449
- __publicField(this, "columnsControl");
450
- __publicField(this, "columnsToolbox");
451
- __publicField(this, "rowsToolbox");
452
- __publicField(this, "controls");
453
- var _a, _b, _c, _d;
454
- this.node = node;
455
- this.cellMinWidth = cellMinWidth;
456
- this.decorations = decorations.slice();
457
- this.editor = editor;
458
- this.getPos = getPos;
459
- this.hoveredCell = null;
460
- this.map = import_tables.TableMap.get(node);
461
- if (editor.isEditable) {
462
- this.rowsControl = (0, import_jsx_dom_cjs.h)(
463
- "div",
464
- { className: "rows-control" },
465
- (0, import_jsx_dom_cjs.h)("button", {
466
- // @ts-expect-error JSX
467
- type: "button",
468
- className: "rows-control-div",
469
- onClick: () => this.selectRow(),
470
- "aria-label": "Row actions"
471
- })
472
- );
473
- this.columnsControl = (0, import_jsx_dom_cjs.h)(
474
- "div",
475
- { className: "columns-control" },
476
- (0, import_jsx_dom_cjs.h)("button", {
477
- // @ts-expect-error JSX
478
- type: "button",
479
- className: "columns-control-div",
480
- onClick: () => this.selectColumn(),
481
- "aria-label": "Column actions"
482
- })
483
- );
484
- this.controls = (0, import_jsx_dom_cjs.h)(
485
- "div",
486
- { className: "table-controls", contentEditable: "false" },
487
- this.rowsControl,
488
- this.columnsControl
489
- );
490
- const palette = {
491
- Blue: { backgroundColor: "#D9E4FF", textColor: "#171717" },
492
- Orange: { backgroundColor: "#FFEDD5", textColor: "#171717" },
493
- Grey: { backgroundColor: "#F1F1F1", textColor: "#171717" },
494
- Yellow: { backgroundColor: "#FEF3C7", textColor: "#171717" },
495
- Green: { backgroundColor: "#DCFCE7", textColor: "#171717" },
496
- Red: { backgroundColor: "#FFDDDD", textColor: "#171717" },
497
- Pink: { backgroundColor: "#FFE8FA", textColor: "#171717" },
498
- Purple: { backgroundColor: "#E8DAFB", textColor: "#171717" },
499
- None: {
500
- backgroundColor: "transparent",
501
- textColor: "inherit",
502
- 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>`
503
- }
504
- };
505
- this.columnsToolbox = createToolbox({
506
- triggerButton: (_a = this.columnsControl) == null ? void 0 : _a.querySelector(
507
- ".columns-control-div"
508
- ),
509
- items: columnsToolboxItems,
510
- colors: palette,
511
- appendTo: (_b = this.controls) != null ? _b : null,
512
- onSelectColor: (color) => setCellsBackgroundColor(this.editor, color),
513
- onClickItem: (item) => {
514
- var _a2, _b2;
515
- item.action({
516
- editor: this.editor,
517
- triggerButton: (_a2 = this.columnsControl) == null ? void 0 : _a2.firstElementChild,
518
- controlsContainer: this.controls
519
- });
520
- (_b2 = this.columnsToolbox) == null ? void 0 : _b2.hide();
521
- }
522
- });
523
- this.rowsToolbox = createToolbox({
524
- triggerButton: (_c = this.rowsControl) == null ? void 0 : _c.querySelector(
525
- ".rows-control-div"
526
- ),
527
- items: rowsToolboxItems,
528
- colors: palette,
529
- appendTo: (_d = this.controls) != null ? _d : null,
530
- onSelectColor: (color) => setTableRowBackgroundColor(editor, color),
531
- onClickItem: (item) => {
532
- var _a2, _b2;
533
- item.action({
534
- editor: this.editor,
535
- triggerButton: (_a2 = this.rowsControl) == null ? void 0 : _a2.firstElementChild,
536
- controlsContainer: this.controls
537
- });
538
- (_b2 = this.rowsToolbox) == null ? void 0 : _b2.hide();
539
- }
540
- });
541
- }
542
- this.colgroup = (0, import_jsx_dom_cjs.h)(
543
- "colgroup",
544
- null,
545
- Array.from({ length: this.map.width }, () => 1).map(() => (0, import_jsx_dom_cjs.h)("col"))
546
- );
547
- this.tbody = (0, import_jsx_dom_cjs.h)("tbody");
548
- this.table = (0, import_jsx_dom_cjs.h)(
549
- "table",
550
- null,
551
- this.colgroup,
552
- this.tbody
553
- );
554
- this.root = (0, import_jsx_dom_cjs.h)(
555
- "div",
556
- {
557
- className: "table-wrapper horizontal-scrollbar scrollbar-md controls--disabled"
558
- },
559
- this.controls,
560
- this.table
561
- );
562
- this.render();
563
- }
564
- get dom() {
565
- return this.root;
566
- }
567
- get contentDOM() {
568
- return this.tbody;
569
- }
570
- update(node, decorations) {
571
- if (node.type !== this.node.type) return false;
572
- this.node = node;
573
- this.decorations = [...decorations];
574
- this.map = import_tables.TableMap.get(this.node);
575
- if (this.editor.isEditable) this.updateControls();
576
- this.render();
577
- return true;
578
- }
579
- render() {
580
- if (this.colgroup.children.length !== this.map.width) {
581
- const cols = Array.from({ length: this.map.width }, () => 1).map(
582
- () => (0, import_jsx_dom_cjs.h)("col")
583
- );
584
- this.colgroup.replaceChildren(...cols);
585
- }
586
- (0, import_tables.updateColumnsOnResize)(
587
- this.node,
588
- this.colgroup,
589
- this.table,
590
- this.cellMinWidth
591
- );
592
- }
593
- ignoreMutation() {
594
- return true;
595
- }
596
- updateControls() {
597
- var _a;
598
- const { hoveredTable: table, hoveredCell: cell } = Object.values(
599
- this.decorations
600
- ).reduce(
601
- (acc, curr) => {
602
- if (curr.spec.hoveredCell !== void 0)
603
- acc.hoveredCell = curr.spec.hoveredCell;
604
- if (curr.spec.hoveredTable !== void 0)
605
- acc.hoveredTable = curr.spec.hoveredTable;
606
- return acc;
607
- },
608
- {}
609
- );
610
- if (table === void 0 || cell === void 0) {
611
- this.root.classList.add("controls--disabled");
612
- return;
613
- }
614
- this.root.classList.remove("controls--disabled");
615
- this.hoveredCell = cell;
616
- const cellDom = this.editor.view.nodeDOM(cell.pos);
617
- if (!this.table || !cellDom) return;
618
- const tableRect = this.table.getBoundingClientRect();
619
- const cellRect = cellDom.getBoundingClientRect();
620
- if (this.columnsControl) {
621
- this.columnsControl.style.left = `${cellRect.left - tableRect.left - (((_a = this.table.parentElement) == null ? void 0 : _a.scrollLeft) || 0)}px`;
622
- this.columnsControl.style.width = `${cellRect.width}px`;
623
- }
624
- if (this.rowsControl) {
625
- this.rowsControl.style.top = `${cellRect.top - tableRect.top}px`;
626
- this.rowsControl.style.height = `${cellRect.height}px`;
627
- }
628
- }
629
- selectColumn() {
630
- if (!this.hoveredCell) return;
631
- const colIndex = this.map.colCount(
632
- this.hoveredCell.pos - (this.getPos() + 1)
633
- );
634
- const anchorCellPos = this.hoveredCell.pos;
635
- const headCellPos = this.map.map[colIndex + this.map.width * (this.map.height - 1)] + (this.getPos() + 1);
636
- const cellSelection = import_tables.CellSelection.create(
637
- this.editor.view.state.doc,
638
- anchorCellPos,
639
- headCellPos
640
- );
641
- this.editor.view.dispatch(this.editor.state.tr.setSelection(cellSelection));
642
- }
643
- selectRow() {
644
- if (!this.hoveredCell) return;
645
- const anchorCellPos = this.hoveredCell.pos;
646
- const anchorCellIndex = this.map.map.indexOf(
647
- anchorCellPos - (this.getPos() + 1)
648
- );
649
- const headCellPos = this.map.map[anchorCellIndex + (this.map.width - 1)] + (this.getPos() + 1);
650
- const cellSelection = import_tables.CellSelection.create(
651
- this.editor.state.doc,
652
- anchorCellPos,
653
- headCellPos
654
- );
655
- this.editor.view.dispatch(
656
- this.editor.view.state.tr.setSelection(cellSelection)
657
- );
658
- }
659
- };
660
-
661
- // src/utils/index.ts
662
- var import_state2 = require("@tiptap/pm/state");
663
- var MAX_FILE_SIZE = 5 * 1024 * 1024;
664
- function findParentNodeOfType(selection, typeName) {
665
- let depth = selection.$anchor.depth;
666
- while (depth > 0) {
667
- const node = selection.$anchor.node(depth);
668
- if (node.type.name === typeName) {
669
- return { node, pos: selection.$anchor.start(depth) - 1 };
670
- }
671
- depth--;
672
- }
673
- return null;
674
- }
675
-
676
- // src/extensions/table/table/utilities/insert-line-above-table-action.ts
677
- var insertLineAboveTableAction = ({
678
- editor
679
- }) => {
680
- if (!editor.isActive("table")) return false;
681
- try {
682
- const { selection } = editor.state;
683
- const tableNode = findParentNodeOfType(selection, "table");
684
- if (!tableNode) return false;
685
- const tablePos = tableNode.pos;
686
- const firstRow = tableNode.node.child(0);
687
- const selectionPath = selection.$anchor.path;
688
- const selectionInFirstRow = selectionPath.includes(firstRow);
689
- if (!selectionInFirstRow) return false;
690
- if (tablePos === 0) {
691
- editor.chain().insertContentAt(tablePos, { type: "paragraph" }).run();
692
- editor.chain().setTextSelection(tablePos + 1).run();
693
- } else {
694
- const prevNodePos = tablePos - 1;
695
- if (prevNodePos <= 0) return false;
696
- const prevNode = editor.state.doc.nodeAt(prevNodePos - 1);
697
- if (prevNode && prevNode.type.name === "paragraph") {
698
- const endOfParagraphPos = tablePos - prevNode.nodeSize;
699
- editor.chain().setTextSelection(endOfParagraphPos).run();
700
- } else {
701
- return false;
702
- }
703
- }
704
- return true;
705
- } catch (e) {
706
- console.error("failed to insert line above table", e);
707
- return false;
708
- }
709
- };
710
-
711
- // src/extensions/table/table/utilities/insert-line-below-table-action.ts
712
- var insertLineBelowTableAction = ({
713
- editor
714
- }) => {
715
- if (!editor.isActive("table")) return false;
716
- try {
717
- const { selection } = editor.state;
718
- const tableNode = findParentNodeOfType(selection, "table");
719
- if (!tableNode) return false;
720
- const tablePos = tableNode.pos;
721
- const table = tableNode.node;
722
- const rowCount = table.childCount;
723
- const lastRow = table.child(rowCount - 1);
724
- const selectionPath = selection.$anchor.path;
725
- const selectionInLastRow = selectionPath.includes(lastRow);
726
- if (!selectionInLastRow) return false;
727
- const nextNodePos = tablePos + table.nodeSize;
728
- const nextNode = editor.state.doc.nodeAt(nextNodePos);
729
- if (nextNode && nextNode.type.name === "paragraph") {
730
- const endOfParagraphPos = nextNodePos + nextNode.nodeSize - 1;
731
- editor.chain().setTextSelection(endOfParagraphPos).run();
732
- } else if (!nextNode) {
733
- editor.chain().insertContentAt(nextNodePos, { type: "paragraph" }).run();
734
- editor.chain().setTextSelection(nextNodePos + 1).run();
735
- } else {
736
- return false;
737
- }
738
- return true;
739
- } catch (e) {
740
- console.error("failed to insert line above table", e);
741
- return false;
742
- }
743
- };
744
-
745
- // src/extensions/table/table/table.ts
746
- var Table = import_extension_table.Table.extend({
747
- addOptions() {
748
- var _a;
749
- return {
750
- ...(_a = this.parent) == null ? void 0 : _a.call(this),
751
- HTMLAttributes: {},
752
- resizable: true,
753
- handleWidth: 5,
754
- cellMinWidth: 100,
755
- lastColumnResizable: true,
756
- allowTableNodeSelection: true
757
- };
758
- },
759
- addKeyboardShortcuts() {
760
- var _a;
761
- return {
762
- ...(_a = this.parent) == null ? void 0 : _a.call(this),
763
- Tab: () => {
764
- if (this.editor.isActive("table")) {
765
- if (this.editor.isActive("listItem") || this.editor.isActive("taskItem")) {
766
- return false;
767
- }
768
- if (this.editor.commands.goToNextCell()) {
769
- return true;
770
- }
771
- if (!this.editor.can().addRowAfter()) {
772
- return false;
773
- }
774
- return this.editor.chain().addRowAfter().goToNextCell().run();
775
- }
776
- return false;
777
- },
778
- ArrowDown: insertLineBelowTableAction,
779
- ArrowUp: insertLineAboveTableAction
780
- };
781
- },
782
- addNodeView() {
783
- return ({ editor, getPos, node, decorations }) => {
784
- const { cellMinWidth } = this.options;
785
- return new TableView(
786
- node,
787
- cellMinWidth,
788
- // biome-ignore lint/suspicious/noExplicitAny: prosemirror
789
- decorations,
790
- editor,
791
- getPos
792
- );
793
- };
794
- },
795
- addProseMirrorPlugins() {
796
- const isResizable = this.options.resizable && this.editor.isEditable;
797
- const plugins = [
798
- (0, import_tables2.tableEditing)({
799
- allowTableNodeSelection: this.options.allowTableNodeSelection
800
- }),
801
- tableControls()
802
- ];
803
- if (isResizable) {
804
- plugins.unshift(
805
- (0, import_tables2.columnResizing)({
806
- handleWidth: this.options.handleWidth,
807
- cellMinWidth: this.options.cellMinWidth,
808
- // View: TableView,
809
- lastColumnResizable: this.options.lastColumnResizable
810
- })
811
- );
812
- }
813
- return plugins;
814
- }
815
- });
816
-
817
- // src/extensions/table/table-cell.ts
818
- var import_core2 = require("@tiptap/core");
819
- var TableCell = import_core2.Node.create({
820
- name: "tableCell",
821
- content: "block+",
822
- // DONT allow table in table.
823
- tableRole: "cell",
824
- isolating: true,
825
- addOptions() {
826
- return {
827
- HTMLAttributes: {}
828
- };
829
- },
830
- parseHTML() {
831
- return [{ tag: "td" }];
832
- },
833
- renderHTML({ node, HTMLAttributes }) {
834
- return [
835
- "td",
836
- (0, import_core2.mergeAttributes)(this.options.HTMLAttributes, HTMLAttributes, {
837
- style: `background-color: ${node.attrs.background}; color: ${node.attrs.textColor}`
838
- }),
839
- 0
840
- ];
841
- },
842
- addAttributes() {
843
- return {
844
- colspan: {
845
- default: 1,
846
- parseHTML: (element) => {
847
- const colspan = element.getAttribute("colspan");
848
- const value = colspan ? Number.parseInt(colspan, 10) : 1;
849
- return value;
850
- }
851
- },
852
- rowspan: {
853
- default: 1,
854
- parseHTML: (element) => {
855
- const rowspan = element.getAttribute("rowspan");
856
- const value = rowspan ? Number.parseInt(rowspan, 10) : 1;
857
- return value;
858
- }
859
- },
860
- colwidth: {
861
- default: null,
862
- parseHTML: (element) => {
863
- const colwidth = element.getAttribute("colwidth");
864
- const value = colwidth ? [Number.parseInt(colwidth, 10)] : null;
865
- return value;
866
- }
867
- },
868
- background: {
869
- default: null
870
- },
871
- textColor: {
872
- default: null
873
- },
874
- style: {
875
- default: null
876
- }
877
- };
878
- }
879
- // addProseMirrorPlugins() {
880
- // return [
881
- // new Plugin({
882
- // props: {
883
- // decorations: (state) => {
884
- // const { isEditable } = this.editor;
885
- // if (!isEditable) {
886
- // return DecorationSet.empty;
887
- // }
888
- // const { doc, selection } = state;
889
- // const decorations: Decoration[] = [];
890
- // const cells = getCellsInColumn(0)(selection);
891
- // if (cells) {
892
- // cells.forEach(({ pos }: { pos: number }, index: number) => {
893
- // decorations.push(
894
- // Decoration.widget(pos + 1, () => {
895
- // const rowSelected = isRowSelected(index)(selection);
896
- // let className = "grip-row";
897
- // if (rowSelected) {
898
- // className += " selected";
899
- // }
900
- // if (index === 0) {
901
- // className += " first";
902
- // }
903
- // if (index === cells.length - 1) {
904
- // className += " last";
905
- // }
906
- // const grip = document.createElement("a");
907
- // grip.className = className;
908
- // grip.addEventListener("mousedown", (event) => {
909
- // event.preventDefault();
910
- // event.stopImmediatePropagation();
911
- // this.editor.view.dispatch(
912
- // selectRow(index)(this.editor.state.tr),
913
- // );
914
- // });
915
- // return grip;
916
- // }),
917
- // );
918
- // });
919
- // }
920
- // return DecorationSet.create(doc, decorations);
921
- // },
922
- // },
923
- // }),
924
- // ];
925
- // },
926
- });
927
-
928
- // src/extensions/table/table-header.ts
929
- var import_extension_table2 = require("@tiptap/extension-table");
930
- var TableHeader = import_extension_table2.TableHeader.extend({
931
- addAttributes() {
932
- return {
933
- colspan: {
934
- default: 1
935
- },
936
- rowspan: {
937
- default: 1
938
- },
939
- colwidth: {
940
- default: null,
941
- parseHTML: (element) => {
942
- const colwidth = element.getAttribute("colwidth");
943
- const value = colwidth ? [Number.parseInt(colwidth, 10)] : null;
944
- return value;
945
- }
946
- },
947
- background: {
948
- default: "none"
949
- },
950
- style: {
951
- default: null
952
- }
953
- };
954
- }
955
- // addProseMirrorPlugins() {
956
- // return [
957
- // new Plugin({
958
- // props: {
959
- // decorations: (state) => {
960
- // const { isEditable } = this.editor;
961
- // if (!isEditable) {
962
- // return DecorationSet.empty;
963
- // }
964
- // const { doc, selection } = state;
965
- // const decorations: Decoration[] = [];
966
- // const cells = getCellsInRow(0)(selection);
967
- // if (cells) {
968
- // cells.forEach(({ pos }, index) => {
969
- // decorations.push(
970
- // Decoration.widget(pos + 1, () => {
971
- // const colSelected = isColumnSelected(index)(selection);
972
- // let className = "grip-column";
973
- // if (colSelected) {
974
- // className += " selected";
975
- // }
976
- // if (index === 0) {
977
- // className += " first";
978
- // }
979
- // if (index === cells.length - 1) {
980
- // className += " last";
981
- // }
982
- // const grip = document.createElement("a");
983
- // grip.className = className;
984
- // grip.addEventListener("mousedown", (event) => {
985
- // event.preventDefault();
986
- // event.stopImmediatePropagation();
987
- // this.editor.view.dispatch(
988
- // selectColumn(index)(this.editor.state.tr),
989
- // );
990
- // });
991
- // return grip;
992
- // }),
993
- // );
994
- // });
995
- // }
996
- // return DecorationSet.create(doc, decorations);
997
- // },
998
- // },
999
- // }),
1000
- // ];
1001
- // },
1002
- });
1003
-
1004
- // src/extensions/table/table-row.ts
1005
- var import_extension_table3 = require("@tiptap/extension-table");
1006
- var TableRow = import_extension_table3.TableRow.extend({
1007
- allowGapCursor: false,
1008
- content: "(tableCell | tableHeader)*"
1009
- });
1010
-
1011
- // src/extensions/table/kit.ts
1012
- var TableKit = import_react.Extension.create({
1013
- name: "tableKit",
1014
- addExtensions() {
1015
- const extensions = [];
1016
- if (this.options.table !== false) {
1017
- extensions.push(Table.configure(this.options.table));
1018
- }
1019
- if (this.options.tableCell !== false) {
1020
- extensions.push(TableCell.configure(this.options.tableCell));
1021
- }
1022
- if (this.options.tableHeader !== false) {
1023
- extensions.push(TableHeader.configure(this.options.tableHeader));
1024
- }
1025
- if (this.options.tableRow !== false) {
1026
- extensions.push(TableRow.configure(this.options.tableRow));
1027
- }
1028
- return extensions;
1029
- }
1030
- });
1031
- // Annotate the CommonJS export names for ESM import in node:
1032
- 0 && (module.exports = {
1033
- TableKit
1034
- });