@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.
- 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 +40 -34
- 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
|
@@ -2,72 +2,58 @@
|
|
|
2
2
|
"use client";
|
|
3
3
|
import {
|
|
4
4
|
BasicEditor
|
|
5
|
-
} from "../../chunk-
|
|
5
|
+
} from "../../chunk-WPRDVMPN.mjs";
|
|
6
6
|
import "../../chunk-MNTOOEHA.mjs";
|
|
7
|
-
import "../../chunk-
|
|
8
|
-
import "../../chunk-
|
|
7
|
+
import "../../chunk-QF3YHPWM.mjs";
|
|
8
|
+
import "../../chunk-B2DHYFSH.mjs";
|
|
9
9
|
import "../../chunk-HLLA2HRV.mjs";
|
|
10
10
|
import "../../chunk-XLSZK3WJ.mjs";
|
|
11
11
|
import "../../chunk-CNVACBGT.mjs";
|
|
12
|
-
import "../../chunk-
|
|
13
|
-
import "../../chunk-
|
|
12
|
+
import "../../chunk-JNL4KY45.mjs";
|
|
13
|
+
import "../../chunk-OZWCQMRA.mjs";
|
|
14
|
+
import "../../chunk-VX3HSJ76.mjs";
|
|
14
15
|
import "../../chunk-4ALV4UA5.mjs";
|
|
15
|
-
import "../../chunk-
|
|
16
|
-
import "../../chunk-
|
|
16
|
+
import "../../chunk-GYIYX2JH.mjs";
|
|
17
|
+
import "../../chunk-IQERE7KP.mjs";
|
|
17
18
|
import "../../chunk-Y2KSWMG5.mjs";
|
|
18
|
-
import "../../chunk-
|
|
19
|
-
import "../../chunk-
|
|
20
|
-
import "../../chunk-
|
|
21
|
-
import "../../chunk-
|
|
22
|
-
import "../../chunk-
|
|
23
|
-
import "../../chunk-
|
|
24
|
-
import "../../chunk-
|
|
19
|
+
import "../../chunk-2SI7MRAE.mjs";
|
|
20
|
+
import "../../chunk-ZVTJ6XD7.mjs";
|
|
21
|
+
import "../../chunk-YJAHZXLG.mjs";
|
|
22
|
+
import "../../chunk-V6TAZMQN.mjs";
|
|
23
|
+
import "../../chunk-LVNUU67N.mjs";
|
|
24
|
+
import "../../chunk-WHJ4B43N.mjs";
|
|
25
|
+
import "../../chunk-LHXRE26G.mjs";
|
|
26
|
+
import "../../chunk-Q7DFJ5NI.mjs";
|
|
27
|
+
import "../../chunk-IOB3REX6.mjs";
|
|
28
|
+
import "../../chunk-LNVWG34E.mjs";
|
|
25
29
|
import "../../chunk-TLM5ALHZ.mjs";
|
|
26
|
-
import "../../chunk-
|
|
27
|
-
import "../../chunk-
|
|
28
|
-
import "../../chunk-
|
|
30
|
+
import "../../chunk-XL5FS7LN.mjs";
|
|
31
|
+
import "../../chunk-2Z2QVW67.mjs";
|
|
32
|
+
import "../../chunk-B7WJOQ3X.mjs";
|
|
33
|
+
import "../../chunk-UJ4BNZ63.mjs";
|
|
34
|
+
import "../../chunk-EHY2NAW7.mjs";
|
|
29
35
|
import "../../chunk-33QD5PYJ.mjs";
|
|
30
|
-
import "../../chunk-LVNUU67N.mjs";
|
|
31
|
-
import "../../chunk-JHMEXFB3.mjs";
|
|
32
|
-
import "../../chunk-R2RRQUU5.mjs";
|
|
33
36
|
import "../../chunk-F73FCUD5.mjs";
|
|
37
|
+
import "../../chunk-W2FLOOJ6.mjs";
|
|
38
|
+
import "../../chunk-ZZ4OU46C.mjs";
|
|
34
39
|
import "../../chunk-ATRHILCH.mjs";
|
|
35
|
-
import "../../chunk-
|
|
36
|
-
import "../../chunk-
|
|
37
|
-
import "../../chunk-2Z2QVW67.mjs";
|
|
38
|
-
import "../../chunk-RQPJU4UB.mjs";
|
|
39
|
-
import "../../chunk-KI3YOPAA.mjs";
|
|
40
|
-
import "../../chunk-WCBSINO5.mjs";
|
|
41
|
-
import "../../chunk-I7WKP3OM.mjs";
|
|
40
|
+
import "../../chunk-OEVR5N7X.mjs";
|
|
41
|
+
import "../../chunk-BEV5U2DK.mjs";
|
|
42
42
|
import "../../chunk-BXJYNSWQ.mjs";
|
|
43
|
-
import "../../chunk-
|
|
44
|
-
import "../../chunk-
|
|
45
|
-
import "../../chunk-
|
|
46
|
-
import "../../chunk-KR42JAVB.mjs";
|
|
43
|
+
import "../../chunk-TZQQ6C2Q.mjs";
|
|
44
|
+
import "../../chunk-REJEJXOZ.mjs";
|
|
45
|
+
import "../../chunk-NUCXXNTA.mjs";
|
|
47
46
|
import "../../chunk-7LHOYNVF.mjs";
|
|
48
47
|
import "../../chunk-CUT6PA4X.mjs";
|
|
49
48
|
import "../../chunk-U5XAL46P.mjs";
|
|
50
|
-
import "../../chunk-
|
|
51
|
-
import "../../chunk-
|
|
52
|
-
import "../../chunk-LXZ53XU7.mjs";
|
|
53
|
-
import "../../chunk-7HC7D256.mjs";
|
|
54
|
-
import "../../chunk-574UV65T.mjs";
|
|
55
|
-
import "../../chunk-AC22DSDA.mjs";
|
|
56
|
-
import "../../chunk-LKOQAQPZ.mjs";
|
|
57
|
-
import "../../chunk-TVFWG7IC.mjs";
|
|
58
|
-
import "../../chunk-T6P7CS4F.mjs";
|
|
59
|
-
import "../../chunk-HYDS6H67.mjs";
|
|
60
|
-
import "../../chunk-KRLE4MMD.mjs";
|
|
61
|
-
import "../../chunk-4IIGLBTD.mjs";
|
|
62
|
-
import "../../chunk-EN3J5AMF.mjs";
|
|
63
|
-
import "../../chunk-C6M3CDOK.mjs";
|
|
49
|
+
import "../../chunk-H6LC4LDQ.mjs";
|
|
50
|
+
import "../../chunk-KR42JAVB.mjs";
|
|
64
51
|
import "../../chunk-R2GM4A3T.mjs";
|
|
65
52
|
import "../../chunk-DT7ML2P4.mjs";
|
|
66
53
|
import "../../chunk-KK4K43WM.mjs";
|
|
67
54
|
import "../../chunk-TDFS3DCZ.mjs";
|
|
68
55
|
import "../../chunk-42HKGCOO.mjs";
|
|
69
56
|
import "../../chunk-P55PLOHR.mjs";
|
|
70
|
-
import "../../chunk-WKV76XOR.mjs";
|
|
71
57
|
export {
|
|
72
58
|
BasicEditor
|
|
73
59
|
};
|
|
@@ -67,70 +67,15 @@ function useTiptapEditor(providedEditor) {
|
|
|
67
67
|
}
|
|
68
68
|
|
|
69
69
|
// src/ui/blockquote-button/use-blockquote.ts
|
|
70
|
+
var import_editor_utils = require("@kopexa/editor-utils");
|
|
70
71
|
var import_icons = require("@kopexa/icons");
|
|
71
|
-
var import_state2 = require("@tiptap/pm/state");
|
|
72
|
-
var React = __toESM(require("react"));
|
|
73
|
-
|
|
74
|
-
// src/utils/index.ts
|
|
75
72
|
var import_state = require("@tiptap/pm/state");
|
|
76
|
-
var
|
|
77
|
-
var isNodeInSchema = (nodeName, editor) => {
|
|
78
|
-
if (!(editor == null ? void 0 : editor.schema)) return false;
|
|
79
|
-
return editor.schema.spec.nodes.get(nodeName) !== void 0;
|
|
80
|
-
};
|
|
81
|
-
function findNodePosition(props) {
|
|
82
|
-
var _a;
|
|
83
|
-
const { editor, node, nodePos } = props;
|
|
84
|
-
if (!editor || !((_a = editor.state) == null ? void 0 : _a.doc)) return null;
|
|
85
|
-
const hasValidNode = node !== void 0 && node !== null;
|
|
86
|
-
const hasValidPos = nodePos !== void 0 && nodePos !== null;
|
|
87
|
-
if (!hasValidNode && !hasValidPos) {
|
|
88
|
-
return null;
|
|
89
|
-
}
|
|
90
|
-
if (hasValidPos) {
|
|
91
|
-
try {
|
|
92
|
-
const nodeAtPos = editor.state.doc.nodeAt(nodePos);
|
|
93
|
-
if (nodeAtPos) {
|
|
94
|
-
return { pos: nodePos, node: nodeAtPos };
|
|
95
|
-
}
|
|
96
|
-
} catch (error) {
|
|
97
|
-
console.error("Error checking node at position:", error);
|
|
98
|
-
return null;
|
|
99
|
-
}
|
|
100
|
-
}
|
|
101
|
-
let foundPos = -1;
|
|
102
|
-
let foundNode = null;
|
|
103
|
-
editor.state.doc.descendants((currentNode, pos) => {
|
|
104
|
-
if (currentNode === node) {
|
|
105
|
-
foundPos = pos;
|
|
106
|
-
foundNode = currentNode;
|
|
107
|
-
return false;
|
|
108
|
-
}
|
|
109
|
-
return true;
|
|
110
|
-
});
|
|
111
|
-
return foundPos !== -1 && foundNode !== null ? { pos: foundPos, node: foundNode } : null;
|
|
112
|
-
}
|
|
113
|
-
function isNodeTypeSelected(editor, types = []) {
|
|
114
|
-
if (!editor || !editor.state.selection) return false;
|
|
115
|
-
const { state } = editor;
|
|
116
|
-
const { selection } = state;
|
|
117
|
-
if (selection.empty) return false;
|
|
118
|
-
if (selection instanceof import_state.NodeSelection) {
|
|
119
|
-
const node = selection.node;
|
|
120
|
-
return node ? types.includes(node.type.name) : false;
|
|
121
|
-
}
|
|
122
|
-
return false;
|
|
123
|
-
}
|
|
124
|
-
function isValidPosition(pos) {
|
|
125
|
-
return typeof pos === "number" && pos >= 0;
|
|
126
|
-
}
|
|
127
|
-
|
|
128
|
-
// src/ui/blockquote-button/use-blockquote.ts
|
|
73
|
+
var React = __toESM(require("react"));
|
|
129
74
|
var BLOCKQUOTE_SHORTCUT_KEY = "mod+shift+b";
|
|
130
75
|
function canToggleBlockquote(editor, turnInto = true) {
|
|
131
76
|
var _a;
|
|
132
77
|
if (!editor || !editor.isEditable) return false;
|
|
133
|
-
if (!isNodeInSchema("blockquote", editor) || isNodeTypeSelected(editor, ["image"]))
|
|
78
|
+
if (!(0, import_editor_utils.isNodeInSchema)("blockquote", editor) || (0, import_editor_utils.isNodeTypeSelected)(editor, ["image"]))
|
|
134
79
|
return false;
|
|
135
80
|
if (!turnInto) {
|
|
136
81
|
return editor.can().toggleWrap("blockquote");
|
|
@@ -139,12 +84,12 @@ function canToggleBlockquote(editor, turnInto = true) {
|
|
|
139
84
|
const view = editor.view;
|
|
140
85
|
const state = view.state;
|
|
141
86
|
const selection = state.selection;
|
|
142
|
-
if (selection.empty || selection instanceof
|
|
143
|
-
const pos = (_a = findNodePosition({
|
|
87
|
+
if (selection.empty || selection instanceof import_state.TextSelection) {
|
|
88
|
+
const pos = (_a = (0, import_editor_utils.findNodePosition)({
|
|
144
89
|
editor,
|
|
145
90
|
node: state.selection.$anchor.node(1)
|
|
146
91
|
})) == null ? void 0 : _a.pos;
|
|
147
|
-
if (!isValidPosition(pos)) return false;
|
|
92
|
+
if (!(0, import_editor_utils.isValidPosition)(pos)) return false;
|
|
148
93
|
}
|
|
149
94
|
return true;
|
|
150
95
|
} catch {
|
|
@@ -159,19 +104,19 @@ function toggleBlockquote(editor) {
|
|
|
159
104
|
const view = editor.view;
|
|
160
105
|
let state = view.state;
|
|
161
106
|
let tr = state.tr;
|
|
162
|
-
if (state.selection.empty || state.selection instanceof
|
|
163
|
-
const pos = (_a = findNodePosition({
|
|
107
|
+
if (state.selection.empty || state.selection instanceof import_state.TextSelection) {
|
|
108
|
+
const pos = (_a = (0, import_editor_utils.findNodePosition)({
|
|
164
109
|
editor,
|
|
165
110
|
node: state.selection.$anchor.node(1)
|
|
166
111
|
})) == null ? void 0 : _a.pos;
|
|
167
|
-
if (!isValidPosition(pos)) return false;
|
|
168
|
-
tr = tr.setSelection(
|
|
112
|
+
if (!(0, import_editor_utils.isValidPosition)(pos)) return false;
|
|
113
|
+
tr = tr.setSelection(import_state.NodeSelection.create(state.doc, pos));
|
|
169
114
|
view.dispatch(tr);
|
|
170
115
|
state = view.state;
|
|
171
116
|
}
|
|
172
117
|
const selection = state.selection;
|
|
173
118
|
let chain = editor.chain().focus();
|
|
174
|
-
if (selection instanceof
|
|
119
|
+
if (selection instanceof import_state.NodeSelection) {
|
|
175
120
|
const firstChild = (_b = selection.node.firstChild) == null ? void 0 : _b.firstChild;
|
|
176
121
|
const lastChild = (_c = selection.node.lastChild) == null ? void 0 : _c.lastChild;
|
|
177
122
|
const from = firstChild ? selection.from + firstChild.nodeSize : selection.from + 1;
|
|
@@ -189,7 +134,7 @@ function toggleBlockquote(editor) {
|
|
|
189
134
|
function shouldShowButton(props) {
|
|
190
135
|
const { editor, hideWhenUnavailable } = props;
|
|
191
136
|
if (!editor || !editor.isEditable) return false;
|
|
192
|
-
if (!isNodeInSchema("blockquote", editor)) return false;
|
|
137
|
+
if (!(0, import_editor_utils.isNodeInSchema)("blockquote", editor)) return false;
|
|
193
138
|
if (hideWhenUnavailable && !editor.isActive("code")) {
|
|
194
139
|
return canToggleBlockquote(editor);
|
|
195
140
|
}
|
|
@@ -1,11 +1,9 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
import {
|
|
3
3
|
BlockquoteButton
|
|
4
|
-
} from "../../chunk-
|
|
5
|
-
import "../../chunk-
|
|
6
|
-
import "../../chunk-C6M3CDOK.mjs";
|
|
4
|
+
} from "../../chunk-W2FLOOJ6.mjs";
|
|
5
|
+
import "../../chunk-ZZ4OU46C.mjs";
|
|
7
6
|
import "../../chunk-P55PLOHR.mjs";
|
|
8
|
-
import "../../chunk-WKV76XOR.mjs";
|
|
9
7
|
export {
|
|
10
8
|
BlockquoteButton
|
|
11
9
|
};
|
|
@@ -74,70 +74,15 @@ function useTiptapEditor(providedEditor) {
|
|
|
74
74
|
}
|
|
75
75
|
|
|
76
76
|
// src/ui/blockquote-button/use-blockquote.ts
|
|
77
|
+
var import_editor_utils = require("@kopexa/editor-utils");
|
|
77
78
|
var import_icons = require("@kopexa/icons");
|
|
78
|
-
var import_state2 = require("@tiptap/pm/state");
|
|
79
|
-
var React = __toESM(require("react"));
|
|
80
|
-
|
|
81
|
-
// src/utils/index.ts
|
|
82
79
|
var import_state = require("@tiptap/pm/state");
|
|
83
|
-
var
|
|
84
|
-
var isNodeInSchema = (nodeName, editor) => {
|
|
85
|
-
if (!(editor == null ? void 0 : editor.schema)) return false;
|
|
86
|
-
return editor.schema.spec.nodes.get(nodeName) !== void 0;
|
|
87
|
-
};
|
|
88
|
-
function findNodePosition(props) {
|
|
89
|
-
var _a;
|
|
90
|
-
const { editor, node, nodePos } = props;
|
|
91
|
-
if (!editor || !((_a = editor.state) == null ? void 0 : _a.doc)) return null;
|
|
92
|
-
const hasValidNode = node !== void 0 && node !== null;
|
|
93
|
-
const hasValidPos = nodePos !== void 0 && nodePos !== null;
|
|
94
|
-
if (!hasValidNode && !hasValidPos) {
|
|
95
|
-
return null;
|
|
96
|
-
}
|
|
97
|
-
if (hasValidPos) {
|
|
98
|
-
try {
|
|
99
|
-
const nodeAtPos = editor.state.doc.nodeAt(nodePos);
|
|
100
|
-
if (nodeAtPos) {
|
|
101
|
-
return { pos: nodePos, node: nodeAtPos };
|
|
102
|
-
}
|
|
103
|
-
} catch (error) {
|
|
104
|
-
console.error("Error checking node at position:", error);
|
|
105
|
-
return null;
|
|
106
|
-
}
|
|
107
|
-
}
|
|
108
|
-
let foundPos = -1;
|
|
109
|
-
let foundNode = null;
|
|
110
|
-
editor.state.doc.descendants((currentNode, pos) => {
|
|
111
|
-
if (currentNode === node) {
|
|
112
|
-
foundPos = pos;
|
|
113
|
-
foundNode = currentNode;
|
|
114
|
-
return false;
|
|
115
|
-
}
|
|
116
|
-
return true;
|
|
117
|
-
});
|
|
118
|
-
return foundPos !== -1 && foundNode !== null ? { pos: foundPos, node: foundNode } : null;
|
|
119
|
-
}
|
|
120
|
-
function isNodeTypeSelected(editor, types = []) {
|
|
121
|
-
if (!editor || !editor.state.selection) return false;
|
|
122
|
-
const { state } = editor;
|
|
123
|
-
const { selection } = state;
|
|
124
|
-
if (selection.empty) return false;
|
|
125
|
-
if (selection instanceof import_state.NodeSelection) {
|
|
126
|
-
const node = selection.node;
|
|
127
|
-
return node ? types.includes(node.type.name) : false;
|
|
128
|
-
}
|
|
129
|
-
return false;
|
|
130
|
-
}
|
|
131
|
-
function isValidPosition(pos) {
|
|
132
|
-
return typeof pos === "number" && pos >= 0;
|
|
133
|
-
}
|
|
134
|
-
|
|
135
|
-
// src/ui/blockquote-button/use-blockquote.ts
|
|
80
|
+
var React = __toESM(require("react"));
|
|
136
81
|
var BLOCKQUOTE_SHORTCUT_KEY = "mod+shift+b";
|
|
137
82
|
function canToggleBlockquote(editor, turnInto = true) {
|
|
138
83
|
var _a;
|
|
139
84
|
if (!editor || !editor.isEditable) return false;
|
|
140
|
-
if (!isNodeInSchema("blockquote", editor) || isNodeTypeSelected(editor, ["image"]))
|
|
85
|
+
if (!(0, import_editor_utils.isNodeInSchema)("blockquote", editor) || (0, import_editor_utils.isNodeTypeSelected)(editor, ["image"]))
|
|
141
86
|
return false;
|
|
142
87
|
if (!turnInto) {
|
|
143
88
|
return editor.can().toggleWrap("blockquote");
|
|
@@ -146,12 +91,12 @@ function canToggleBlockquote(editor, turnInto = true) {
|
|
|
146
91
|
const view = editor.view;
|
|
147
92
|
const state = view.state;
|
|
148
93
|
const selection = state.selection;
|
|
149
|
-
if (selection.empty || selection instanceof
|
|
150
|
-
const pos = (_a = findNodePosition({
|
|
94
|
+
if (selection.empty || selection instanceof import_state.TextSelection) {
|
|
95
|
+
const pos = (_a = (0, import_editor_utils.findNodePosition)({
|
|
151
96
|
editor,
|
|
152
97
|
node: state.selection.$anchor.node(1)
|
|
153
98
|
})) == null ? void 0 : _a.pos;
|
|
154
|
-
if (!isValidPosition(pos)) return false;
|
|
99
|
+
if (!(0, import_editor_utils.isValidPosition)(pos)) return false;
|
|
155
100
|
}
|
|
156
101
|
return true;
|
|
157
102
|
} catch {
|
|
@@ -166,19 +111,19 @@ function toggleBlockquote(editor) {
|
|
|
166
111
|
const view = editor.view;
|
|
167
112
|
let state = view.state;
|
|
168
113
|
let tr = state.tr;
|
|
169
|
-
if (state.selection.empty || state.selection instanceof
|
|
170
|
-
const pos = (_a = findNodePosition({
|
|
114
|
+
if (state.selection.empty || state.selection instanceof import_state.TextSelection) {
|
|
115
|
+
const pos = (_a = (0, import_editor_utils.findNodePosition)({
|
|
171
116
|
editor,
|
|
172
117
|
node: state.selection.$anchor.node(1)
|
|
173
118
|
})) == null ? void 0 : _a.pos;
|
|
174
|
-
if (!isValidPosition(pos)) return false;
|
|
175
|
-
tr = tr.setSelection(
|
|
119
|
+
if (!(0, import_editor_utils.isValidPosition)(pos)) return false;
|
|
120
|
+
tr = tr.setSelection(import_state.NodeSelection.create(state.doc, pos));
|
|
176
121
|
view.dispatch(tr);
|
|
177
122
|
state = view.state;
|
|
178
123
|
}
|
|
179
124
|
const selection = state.selection;
|
|
180
125
|
let chain = editor.chain().focus();
|
|
181
|
-
if (selection instanceof
|
|
126
|
+
if (selection instanceof import_state.NodeSelection) {
|
|
182
127
|
const firstChild = (_b = selection.node.firstChild) == null ? void 0 : _b.firstChild;
|
|
183
128
|
const lastChild = (_c = selection.node.lastChild) == null ? void 0 : _c.lastChild;
|
|
184
129
|
const from = firstChild ? selection.from + firstChild.nodeSize : selection.from + 1;
|
|
@@ -196,7 +141,7 @@ function toggleBlockquote(editor) {
|
|
|
196
141
|
function shouldShowButton(props) {
|
|
197
142
|
const { editor, hideWhenUnavailable } = props;
|
|
198
143
|
if (!editor || !editor.isEditable) return false;
|
|
199
|
-
if (!isNodeInSchema("blockquote", editor)) return false;
|
|
144
|
+
if (!(0, import_editor_utils.isNodeInSchema)("blockquote", editor)) return false;
|
|
200
145
|
if (hideWhenUnavailable && !editor.isActive("code")) {
|
|
201
146
|
return canToggleBlockquote(editor);
|
|
202
147
|
}
|
|
@@ -2,17 +2,15 @@
|
|
|
2
2
|
import "../../chunk-F73FCUD5.mjs";
|
|
3
3
|
import {
|
|
4
4
|
BlockquoteButton
|
|
5
|
-
} from "../../chunk-
|
|
5
|
+
} from "../../chunk-W2FLOOJ6.mjs";
|
|
6
6
|
import {
|
|
7
7
|
BLOCKQUOTE_SHORTCUT_KEY,
|
|
8
8
|
canToggleBlockquote,
|
|
9
9
|
shouldShowButton,
|
|
10
10
|
toggleBlockquote,
|
|
11
11
|
useBlockquote
|
|
12
|
-
} from "../../chunk-
|
|
13
|
-
import "../../chunk-C6M3CDOK.mjs";
|
|
12
|
+
} from "../../chunk-ZZ4OU46C.mjs";
|
|
14
13
|
import "../../chunk-P55PLOHR.mjs";
|
|
15
|
-
import "../../chunk-WKV76XOR.mjs";
|
|
16
14
|
export {
|
|
17
15
|
BLOCKQUOTE_SHORTCUT_KEY,
|
|
18
16
|
BlockquoteButton,
|
|
@@ -39,8 +39,9 @@ __export(use_blockquote_exports, {
|
|
|
39
39
|
useBlockquote: () => useBlockquote
|
|
40
40
|
});
|
|
41
41
|
module.exports = __toCommonJS(use_blockquote_exports);
|
|
42
|
+
var import_editor_utils = require("@kopexa/editor-utils");
|
|
42
43
|
var import_icons = require("@kopexa/icons");
|
|
43
|
-
var
|
|
44
|
+
var import_state = require("@tiptap/pm/state");
|
|
44
45
|
var React = __toESM(require("react"));
|
|
45
46
|
|
|
46
47
|
// src/hooks/use-tiptap-editor.ts
|
|
@@ -72,66 +73,12 @@ function useTiptapEditor(providedEditor) {
|
|
|
72
73
|
return editorState || { editor: null };
|
|
73
74
|
}
|
|
74
75
|
|
|
75
|
-
// src/utils/index.ts
|
|
76
|
-
var import_state = require("@tiptap/pm/state");
|
|
77
|
-
var MAX_FILE_SIZE = 5 * 1024 * 1024;
|
|
78
|
-
var isNodeInSchema = (nodeName, editor) => {
|
|
79
|
-
if (!(editor == null ? void 0 : editor.schema)) return false;
|
|
80
|
-
return editor.schema.spec.nodes.get(nodeName) !== void 0;
|
|
81
|
-
};
|
|
82
|
-
function findNodePosition(props) {
|
|
83
|
-
var _a;
|
|
84
|
-
const { editor, node, nodePos } = props;
|
|
85
|
-
if (!editor || !((_a = editor.state) == null ? void 0 : _a.doc)) return null;
|
|
86
|
-
const hasValidNode = node !== void 0 && node !== null;
|
|
87
|
-
const hasValidPos = nodePos !== void 0 && nodePos !== null;
|
|
88
|
-
if (!hasValidNode && !hasValidPos) {
|
|
89
|
-
return null;
|
|
90
|
-
}
|
|
91
|
-
if (hasValidPos) {
|
|
92
|
-
try {
|
|
93
|
-
const nodeAtPos = editor.state.doc.nodeAt(nodePos);
|
|
94
|
-
if (nodeAtPos) {
|
|
95
|
-
return { pos: nodePos, node: nodeAtPos };
|
|
96
|
-
}
|
|
97
|
-
} catch (error) {
|
|
98
|
-
console.error("Error checking node at position:", error);
|
|
99
|
-
return null;
|
|
100
|
-
}
|
|
101
|
-
}
|
|
102
|
-
let foundPos = -1;
|
|
103
|
-
let foundNode = null;
|
|
104
|
-
editor.state.doc.descendants((currentNode, pos) => {
|
|
105
|
-
if (currentNode === node) {
|
|
106
|
-
foundPos = pos;
|
|
107
|
-
foundNode = currentNode;
|
|
108
|
-
return false;
|
|
109
|
-
}
|
|
110
|
-
return true;
|
|
111
|
-
});
|
|
112
|
-
return foundPos !== -1 && foundNode !== null ? { pos: foundPos, node: foundNode } : null;
|
|
113
|
-
}
|
|
114
|
-
function isNodeTypeSelected(editor, types = []) {
|
|
115
|
-
if (!editor || !editor.state.selection) return false;
|
|
116
|
-
const { state } = editor;
|
|
117
|
-
const { selection } = state;
|
|
118
|
-
if (selection.empty) return false;
|
|
119
|
-
if (selection instanceof import_state.NodeSelection) {
|
|
120
|
-
const node = selection.node;
|
|
121
|
-
return node ? types.includes(node.type.name) : false;
|
|
122
|
-
}
|
|
123
|
-
return false;
|
|
124
|
-
}
|
|
125
|
-
function isValidPosition(pos) {
|
|
126
|
-
return typeof pos === "number" && pos >= 0;
|
|
127
|
-
}
|
|
128
|
-
|
|
129
76
|
// src/ui/blockquote-button/use-blockquote.ts
|
|
130
77
|
var BLOCKQUOTE_SHORTCUT_KEY = "mod+shift+b";
|
|
131
78
|
function canToggleBlockquote(editor, turnInto = true) {
|
|
132
79
|
var _a;
|
|
133
80
|
if (!editor || !editor.isEditable) return false;
|
|
134
|
-
if (!isNodeInSchema("blockquote", editor) || isNodeTypeSelected(editor, ["image"]))
|
|
81
|
+
if (!(0, import_editor_utils.isNodeInSchema)("blockquote", editor) || (0, import_editor_utils.isNodeTypeSelected)(editor, ["image"]))
|
|
135
82
|
return false;
|
|
136
83
|
if (!turnInto) {
|
|
137
84
|
return editor.can().toggleWrap("blockquote");
|
|
@@ -140,12 +87,12 @@ function canToggleBlockquote(editor, turnInto = true) {
|
|
|
140
87
|
const view = editor.view;
|
|
141
88
|
const state = view.state;
|
|
142
89
|
const selection = state.selection;
|
|
143
|
-
if (selection.empty || selection instanceof
|
|
144
|
-
const pos = (_a = findNodePosition({
|
|
90
|
+
if (selection.empty || selection instanceof import_state.TextSelection) {
|
|
91
|
+
const pos = (_a = (0, import_editor_utils.findNodePosition)({
|
|
145
92
|
editor,
|
|
146
93
|
node: state.selection.$anchor.node(1)
|
|
147
94
|
})) == null ? void 0 : _a.pos;
|
|
148
|
-
if (!isValidPosition(pos)) return false;
|
|
95
|
+
if (!(0, import_editor_utils.isValidPosition)(pos)) return false;
|
|
149
96
|
}
|
|
150
97
|
return true;
|
|
151
98
|
} catch {
|
|
@@ -160,19 +107,19 @@ function toggleBlockquote(editor) {
|
|
|
160
107
|
const view = editor.view;
|
|
161
108
|
let state = view.state;
|
|
162
109
|
let tr = state.tr;
|
|
163
|
-
if (state.selection.empty || state.selection instanceof
|
|
164
|
-
const pos = (_a = findNodePosition({
|
|
110
|
+
if (state.selection.empty || state.selection instanceof import_state.TextSelection) {
|
|
111
|
+
const pos = (_a = (0, import_editor_utils.findNodePosition)({
|
|
165
112
|
editor,
|
|
166
113
|
node: state.selection.$anchor.node(1)
|
|
167
114
|
})) == null ? void 0 : _a.pos;
|
|
168
|
-
if (!isValidPosition(pos)) return false;
|
|
169
|
-
tr = tr.setSelection(
|
|
115
|
+
if (!(0, import_editor_utils.isValidPosition)(pos)) return false;
|
|
116
|
+
tr = tr.setSelection(import_state.NodeSelection.create(state.doc, pos));
|
|
170
117
|
view.dispatch(tr);
|
|
171
118
|
state = view.state;
|
|
172
119
|
}
|
|
173
120
|
const selection = state.selection;
|
|
174
121
|
let chain = editor.chain().focus();
|
|
175
|
-
if (selection instanceof
|
|
122
|
+
if (selection instanceof import_state.NodeSelection) {
|
|
176
123
|
const firstChild = (_b = selection.node.firstChild) == null ? void 0 : _b.firstChild;
|
|
177
124
|
const lastChild = (_c = selection.node.lastChild) == null ? void 0 : _c.lastChild;
|
|
178
125
|
const from = firstChild ? selection.from + firstChild.nodeSize : selection.from + 1;
|
|
@@ -190,7 +137,7 @@ function toggleBlockquote(editor) {
|
|
|
190
137
|
function shouldShowButton(props) {
|
|
191
138
|
const { editor, hideWhenUnavailable } = props;
|
|
192
139
|
if (!editor || !editor.isEditable) return false;
|
|
193
|
-
if (!isNodeInSchema("blockquote", editor)) return false;
|
|
140
|
+
if (!(0, import_editor_utils.isNodeInSchema)("blockquote", editor)) return false;
|
|
194
141
|
if (hideWhenUnavailable && !editor.isActive("code")) {
|
|
195
142
|
return canToggleBlockquote(editor);
|
|
196
143
|
}
|
|
@@ -6,10 +6,8 @@ import {
|
|
|
6
6
|
shouldShowButton,
|
|
7
7
|
toggleBlockquote,
|
|
8
8
|
useBlockquote
|
|
9
|
-
} from "../../chunk-
|
|
10
|
-
import "../../chunk-C6M3CDOK.mjs";
|
|
9
|
+
} from "../../chunk-ZZ4OU46C.mjs";
|
|
11
10
|
import "../../chunk-P55PLOHR.mjs";
|
|
12
|
-
import "../../chunk-WKV76XOR.mjs";
|
|
13
11
|
export {
|
|
14
12
|
BLOCKQUOTE_SHORTCUT_KEY,
|
|
15
13
|
canToggleBlockquote,
|
|
@@ -68,70 +68,15 @@ function useTiptapEditor(providedEditor) {
|
|
|
68
68
|
}
|
|
69
69
|
|
|
70
70
|
// src/ui/codeblock-button/use-code-block.ts
|
|
71
|
+
var import_editor_utils = require("@kopexa/editor-utils");
|
|
71
72
|
var import_icons = require("@kopexa/icons");
|
|
72
|
-
var import_state2 = require("@tiptap/pm/state");
|
|
73
|
-
var React = __toESM(require("react"));
|
|
74
|
-
|
|
75
|
-
// src/utils/index.ts
|
|
76
73
|
var import_state = require("@tiptap/pm/state");
|
|
77
|
-
var
|
|
78
|
-
var isNodeInSchema = (nodeName, editor) => {
|
|
79
|
-
if (!(editor == null ? void 0 : editor.schema)) return false;
|
|
80
|
-
return editor.schema.spec.nodes.get(nodeName) !== void 0;
|
|
81
|
-
};
|
|
82
|
-
function findNodePosition(props) {
|
|
83
|
-
var _a;
|
|
84
|
-
const { editor, node, nodePos } = props;
|
|
85
|
-
if (!editor || !((_a = editor.state) == null ? void 0 : _a.doc)) return null;
|
|
86
|
-
const hasValidNode = node !== void 0 && node !== null;
|
|
87
|
-
const hasValidPos = nodePos !== void 0 && nodePos !== null;
|
|
88
|
-
if (!hasValidNode && !hasValidPos) {
|
|
89
|
-
return null;
|
|
90
|
-
}
|
|
91
|
-
if (hasValidPos) {
|
|
92
|
-
try {
|
|
93
|
-
const nodeAtPos = editor.state.doc.nodeAt(nodePos);
|
|
94
|
-
if (nodeAtPos) {
|
|
95
|
-
return { pos: nodePos, node: nodeAtPos };
|
|
96
|
-
}
|
|
97
|
-
} catch (error) {
|
|
98
|
-
console.error("Error checking node at position:", error);
|
|
99
|
-
return null;
|
|
100
|
-
}
|
|
101
|
-
}
|
|
102
|
-
let foundPos = -1;
|
|
103
|
-
let foundNode = null;
|
|
104
|
-
editor.state.doc.descendants((currentNode, pos) => {
|
|
105
|
-
if (currentNode === node) {
|
|
106
|
-
foundPos = pos;
|
|
107
|
-
foundNode = currentNode;
|
|
108
|
-
return false;
|
|
109
|
-
}
|
|
110
|
-
return true;
|
|
111
|
-
});
|
|
112
|
-
return foundPos !== -1 && foundNode !== null ? { pos: foundPos, node: foundNode } : null;
|
|
113
|
-
}
|
|
114
|
-
function isNodeTypeSelected(editor, types = []) {
|
|
115
|
-
if (!editor || !editor.state.selection) return false;
|
|
116
|
-
const { state } = editor;
|
|
117
|
-
const { selection } = state;
|
|
118
|
-
if (selection.empty) return false;
|
|
119
|
-
if (selection instanceof import_state.NodeSelection) {
|
|
120
|
-
const node = selection.node;
|
|
121
|
-
return node ? types.includes(node.type.name) : false;
|
|
122
|
-
}
|
|
123
|
-
return false;
|
|
124
|
-
}
|
|
125
|
-
function isValidPosition(pos) {
|
|
126
|
-
return typeof pos === "number" && pos >= 0;
|
|
127
|
-
}
|
|
128
|
-
|
|
129
|
-
// src/ui/codeblock-button/use-code-block.ts
|
|
74
|
+
var React = __toESM(require("react"));
|
|
130
75
|
var CODE_BLOCK_SHORTCUT_KEY = "mod+alt+c";
|
|
131
76
|
function canToggle(editor, turnInto = true) {
|
|
132
77
|
var _a;
|
|
133
78
|
if (!editor || !editor.isEditable) return false;
|
|
134
|
-
if (!isNodeInSchema("codeBlock", editor) || isNodeTypeSelected(editor, ["image"]))
|
|
79
|
+
if (!(0, import_editor_utils.isNodeInSchema)("codeBlock", editor) || (0, import_editor_utils.isNodeTypeSelected)(editor, ["image"]))
|
|
135
80
|
return false;
|
|
136
81
|
if (!turnInto) {
|
|
137
82
|
return editor.can().toggleNode("codeBlock", "paragraph");
|
|
@@ -140,12 +85,12 @@ function canToggle(editor, turnInto = true) {
|
|
|
140
85
|
const view = editor.view;
|
|
141
86
|
const state = view.state;
|
|
142
87
|
const selection = state.selection;
|
|
143
|
-
if (selection.empty || selection instanceof
|
|
144
|
-
const pos = (_a = findNodePosition({
|
|
88
|
+
if (selection.empty || selection instanceof import_state.TextSelection) {
|
|
89
|
+
const pos = (_a = (0, import_editor_utils.findNodePosition)({
|
|
145
90
|
editor,
|
|
146
91
|
node: state.selection.$anchor.node(1)
|
|
147
92
|
})) == null ? void 0 : _a.pos;
|
|
148
|
-
if (!isValidPosition(pos)) return false;
|
|
93
|
+
if (!(0, import_editor_utils.isValidPosition)(pos)) return false;
|
|
149
94
|
}
|
|
150
95
|
return true;
|
|
151
96
|
} catch {
|
|
@@ -160,19 +105,19 @@ function toggleCodeBlock(editor) {
|
|
|
160
105
|
const view = editor.view;
|
|
161
106
|
let state = view.state;
|
|
162
107
|
let tr = state.tr;
|
|
163
|
-
if (state.selection.empty || state.selection instanceof
|
|
164
|
-
const pos = (_a = findNodePosition({
|
|
108
|
+
if (state.selection.empty || state.selection instanceof import_state.TextSelection) {
|
|
109
|
+
const pos = (_a = (0, import_editor_utils.findNodePosition)({
|
|
165
110
|
editor,
|
|
166
111
|
node: state.selection.$anchor.node(1)
|
|
167
112
|
})) == null ? void 0 : _a.pos;
|
|
168
|
-
if (!isValidPosition(pos)) return false;
|
|
169
|
-
tr = tr.setSelection(
|
|
113
|
+
if (!(0, import_editor_utils.isValidPosition)(pos)) return false;
|
|
114
|
+
tr = tr.setSelection(import_state.NodeSelection.create(state.doc, pos));
|
|
170
115
|
view.dispatch(tr);
|
|
171
116
|
state = view.state;
|
|
172
117
|
}
|
|
173
118
|
const selection = state.selection;
|
|
174
119
|
let chain = editor.chain().focus();
|
|
175
|
-
if (selection instanceof
|
|
120
|
+
if (selection instanceof import_state.NodeSelection) {
|
|
176
121
|
const firstChild = (_b = selection.node.firstChild) == null ? void 0 : _b.firstChild;
|
|
177
122
|
const lastChild = (_c = selection.node.lastChild) == null ? void 0 : _c.lastChild;
|
|
178
123
|
const from = firstChild ? selection.from + firstChild.nodeSize : selection.from + 1;
|
|
@@ -190,7 +135,7 @@ function toggleCodeBlock(editor) {
|
|
|
190
135
|
function shouldShowButton(props) {
|
|
191
136
|
const { editor, hideWhenUnavailable } = props;
|
|
192
137
|
if (!editor || !editor.isEditable) return false;
|
|
193
|
-
if (!isNodeInSchema("codeBlock", editor)) return false;
|
|
138
|
+
if (!(0, import_editor_utils.isNodeInSchema)("codeBlock", editor)) return false;
|
|
194
139
|
if (hideWhenUnavailable && !editor.isActive("code")) {
|
|
195
140
|
return canToggle(editor);
|
|
196
141
|
}
|
|
@@ -249,15 +194,7 @@ var CodeBlockButton = ({
|
|
|
249
194
|
...buttonProps
|
|
250
195
|
}) => {
|
|
251
196
|
const { editor } = useTiptapEditor(providedEditor);
|
|
252
|
-
const {
|
|
253
|
-
isVisible,
|
|
254
|
-
canToggle: canToggle2,
|
|
255
|
-
isActive,
|
|
256
|
-
handleToggle,
|
|
257
|
-
label,
|
|
258
|
-
shortcutKeys,
|
|
259
|
-
Icon
|
|
260
|
-
} = useCodeBlock({
|
|
197
|
+
const { isVisible, canToggle: canToggle2, isActive, handleToggle, label, shortcutKeys } = useCodeBlock({
|
|
261
198
|
editor,
|
|
262
199
|
hideWhenUnavailable,
|
|
263
200
|
onToggled
|