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