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