notra-editor 0.8.0 → 0.8.2
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/components/blockquote-button/blockquote-button.cjs +5 -3
- package/dist/components/blockquote-button/blockquote-button.cjs.map +1 -1
- package/dist/components/blockquote-button/blockquote-button.mjs +5 -3
- package/dist/components/blockquote-button/blockquote-button.mjs.map +1 -1
- package/dist/components/code-block-button/code-block-button.cjs +5 -3
- package/dist/components/code-block-button/code-block-button.cjs.map +1 -1
- package/dist/components/code-block-button/code-block-button.mjs +5 -3
- package/dist/components/code-block-button/code-block-button.mjs.map +1 -1
- package/dist/components/code-block-view/code-block-shell.cjs +4 -2
- package/dist/components/code-block-view/code-block-shell.cjs.map +1 -1
- package/dist/components/code-block-view/code-block-shell.mjs +3 -2
- package/dist/components/code-block-view/code-block-shell.mjs.map +1 -1
- package/dist/components/code-block-view/code-block-view.cjs +6 -4
- package/dist/components/code-block-view/code-block-view.cjs.map +1 -1
- package/dist/components/code-block-view/code-block-view.mjs +6 -4
- package/dist/components/code-block-view/code-block-view.mjs.map +1 -1
- package/dist/components/code-block-view/language-select.cjs +9 -7
- package/dist/components/code-block-view/language-select.cjs.map +1 -1
- package/dist/components/code-block-view/language-select.mjs +9 -7
- package/dist/components/code-block-view/language-select.mjs.map +1 -1
- package/dist/components/copy-button.cjs +6 -4
- package/dist/components/copy-button.cjs.map +1 -1
- package/dist/components/copy-button.mjs +6 -4
- package/dist/components/copy-button.mjs.map +1 -1
- package/dist/components/heading-dropdown-menu/heading-dropdown-menu.cjs +8 -6
- package/dist/components/heading-dropdown-menu/heading-dropdown-menu.cjs.map +1 -1
- package/dist/components/heading-dropdown-menu/heading-dropdown-menu.mjs +8 -6
- package/dist/components/heading-dropdown-menu/heading-dropdown-menu.mjs.map +1 -1
- package/dist/components/heading-dropdown-menu/heading-menu-item.cjs +6 -4
- package/dist/components/heading-dropdown-menu/heading-menu-item.cjs.map +1 -1
- package/dist/components/heading-dropdown-menu/heading-menu-item.mjs +5 -4
- package/dist/components/heading-dropdown-menu/heading-menu-item.mjs.map +1 -1
- package/dist/components/heading-dropdown-menu/use-heading.cjs +4 -2
- package/dist/components/heading-dropdown-menu/use-heading.cjs.map +1 -1
- package/dist/components/heading-dropdown-menu/use-heading.mjs +3 -2
- package/dist/components/heading-dropdown-menu/use-heading.mjs.map +1 -1
- package/dist/components/image-popover/image-input-form.cjs +127 -0
- package/dist/components/image-popover/image-input-form.cjs.map +1 -0
- package/dist/components/image-popover/image-input-form.d.cts +16 -0
- package/dist/components/image-popover/image-input-form.d.ts +16 -0
- package/dist/components/image-popover/image-input-form.mjs +103 -0
- package/dist/components/image-popover/image-input-form.mjs.map +1 -0
- package/dist/components/image-popover/image-popover.cjs +35 -92
- package/dist/components/image-popover/image-popover.cjs.map +1 -1
- package/dist/components/image-popover/image-popover.mjs +36 -93
- package/dist/components/image-popover/image-popover.mjs.map +1 -1
- package/dist/components/image-popover/use-image-popover.cjs +2 -0
- package/dist/components/image-popover/use-image-popover.cjs.map +1 -1
- package/dist/components/image-popover/use-image-popover.mjs +1 -0
- package/dist/components/image-popover/use-image-popover.mjs.map +1 -1
- package/dist/components/link-popover/link-popover.cjs +10 -8
- package/dist/components/link-popover/link-popover.cjs.map +1 -1
- package/dist/components/link-popover/link-popover.mjs +10 -8
- package/dist/components/link-popover/link-popover.mjs.map +1 -1
- package/dist/components/link-popover/use-link-popover.cjs +2 -0
- package/dist/components/link-popover/use-link-popover.cjs.map +1 -1
- package/dist/components/link-popover/use-link-popover.mjs +1 -0
- package/dist/components/link-popover/use-link-popover.mjs.map +1 -1
- package/dist/components/list-dropdown-menu/list-dropdown-menu.cjs +8 -6
- package/dist/components/list-dropdown-menu/list-dropdown-menu.cjs.map +1 -1
- package/dist/components/list-dropdown-menu/list-dropdown-menu.mjs +8 -6
- package/dist/components/list-dropdown-menu/list-dropdown-menu.mjs.map +1 -1
- package/dist/components/list-dropdown-menu/list-menu-item.cjs +6 -4
- package/dist/components/list-dropdown-menu/list-menu-item.cjs.map +1 -1
- package/dist/components/list-dropdown-menu/list-menu-item.mjs +5 -4
- package/dist/components/list-dropdown-menu/list-menu-item.mjs.map +1 -1
- package/dist/components/list-dropdown-menu/use-list.cjs +5 -3
- package/dist/components/list-dropdown-menu/use-list.cjs.map +1 -1
- package/dist/components/list-dropdown-menu/use-list.mjs +4 -3
- package/dist/components/list-dropdown-menu/use-list.mjs.map +1 -1
- package/dist/components/mark-button/mark-button.cjs +6 -4
- package/dist/components/mark-button/mark-button.cjs.map +1 -1
- package/dist/components/mark-button/mark-button.mjs +6 -4
- package/dist/components/mark-button/mark-button.mjs.map +1 -1
- package/dist/components/mark-button/use-mark.cjs +4 -2
- package/dist/components/mark-button/use-mark.cjs.map +1 -1
- package/dist/components/mark-button/use-mark.mjs +3 -2
- package/dist/components/mark-button/use-mark.mjs.map +1 -1
- package/dist/components/slash-dropdown-menu/slash-dropdown-menu.cjs +151 -0
- package/dist/components/slash-dropdown-menu/slash-dropdown-menu.cjs.map +1 -0
- package/dist/components/slash-dropdown-menu/slash-dropdown-menu.d.cts +9 -0
- package/dist/components/slash-dropdown-menu/slash-dropdown-menu.d.ts +9 -0
- package/dist/components/slash-dropdown-menu/slash-dropdown-menu.mjs +127 -0
- package/dist/components/slash-dropdown-menu/slash-dropdown-menu.mjs.map +1 -0
- package/dist/components/slash-dropdown-menu/slash-image-popover.cjs +80 -0
- package/dist/components/slash-dropdown-menu/slash-image-popover.cjs.map +1 -0
- package/dist/components/slash-dropdown-menu/slash-image-popover.d.cts +11 -0
- package/dist/components/slash-dropdown-menu/slash-image-popover.d.ts +11 -0
- package/dist/components/slash-dropdown-menu/slash-image-popover.mjs +56 -0
- package/dist/components/slash-dropdown-menu/slash-image-popover.mjs.map +1 -0
- package/dist/components/slash-dropdown-menu/use-slash-items.cjs +138 -0
- package/dist/components/slash-dropdown-menu/use-slash-items.cjs.map +1 -0
- package/dist/components/slash-dropdown-menu/use-slash-items.d.cts +11 -0
- package/dist/components/slash-dropdown-menu/use-slash-items.d.ts +11 -0
- package/dist/components/slash-dropdown-menu/use-slash-items.mjs +125 -0
- package/dist/components/slash-dropdown-menu/use-slash-items.mjs.map +1 -0
- package/dist/components/suggestion-menu/filter-suggestion-items.cjs +57 -0
- package/dist/components/suggestion-menu/filter-suggestion-items.cjs.map +1 -0
- package/dist/components/suggestion-menu/filter-suggestion-items.d.cts +6 -0
- package/dist/components/suggestion-menu/filter-suggestion-items.d.ts +6 -0
- package/dist/components/suggestion-menu/filter-suggestion-items.mjs +32 -0
- package/dist/components/suggestion-menu/filter-suggestion-items.mjs.map +1 -0
- package/dist/components/suggestion-menu/suggestion-menu-types.cjs +19 -0
- package/dist/components/suggestion-menu/suggestion-menu-types.cjs.map +1 -0
- package/dist/components/suggestion-menu/suggestion-menu-types.d.cts +22 -0
- package/dist/components/suggestion-menu/suggestion-menu-types.d.ts +22 -0
- package/dist/components/suggestion-menu/suggestion-menu-types.mjs +1 -0
- package/dist/components/suggestion-menu/suggestion-menu-types.mjs.map +1 -0
- package/dist/components/suggestion-menu/suggestion-menu.cjs +205 -0
- package/dist/components/suggestion-menu/suggestion-menu.cjs.map +1 -0
- package/dist/components/suggestion-menu/suggestion-menu.d.cts +27 -0
- package/dist/components/suggestion-menu/suggestion-menu.d.ts +27 -0
- package/dist/components/suggestion-menu/suggestion-menu.mjs +181 -0
- package/dist/components/suggestion-menu/suggestion-menu.mjs.map +1 -0
- package/dist/components/toolbar/toolbar.cjs +4 -2
- package/dist/components/toolbar/toolbar.cjs.map +1 -1
- package/dist/components/toolbar/toolbar.mjs +3 -2
- package/dist/components/toolbar/toolbar.mjs.map +1 -1
- package/dist/components/ui/button.cjs +5 -3
- package/dist/components/ui/button.cjs.map +1 -1
- package/dist/components/ui/button.mjs +4 -3
- package/dist/components/ui/button.mjs.map +1 -1
- package/dist/components/ui/command.cjs +6 -5
- package/dist/components/ui/command.cjs.map +1 -1
- package/dist/components/ui/command.mjs +5 -5
- package/dist/components/ui/command.mjs.map +1 -1
- package/dist/components/ui/dialog.cjs +5 -4
- package/dist/components/ui/dialog.cjs.map +1 -1
- package/dist/components/ui/dialog.mjs +4 -4
- package/dist/components/ui/dialog.mjs.map +1 -1
- package/dist/components/ui/dropdown-menu.cjs +4 -3
- package/dist/components/ui/dropdown-menu.cjs.map +1 -1
- package/dist/components/ui/dropdown-menu.mjs +3 -3
- package/dist/components/ui/dropdown-menu.mjs.map +1 -1
- package/dist/components/ui/input-group.cjs +9 -7
- package/dist/components/ui/input-group.cjs.map +1 -1
- package/dist/components/ui/input-group.d.cts +1 -1
- package/dist/components/ui/input-group.d.ts +1 -1
- package/dist/components/ui/input-group.mjs +9 -7
- package/dist/components/ui/input-group.mjs.map +1 -1
- package/dist/components/ui/input.cjs +3 -1
- package/dist/components/ui/input.cjs.map +1 -1
- package/dist/components/ui/input.mjs +2 -1
- package/dist/components/ui/input.mjs.map +1 -1
- package/dist/components/ui/popover.cjs +4 -3
- package/dist/components/ui/popover.cjs.map +1 -1
- package/dist/components/ui/popover.mjs +3 -3
- package/dist/components/ui/popover.mjs.map +1 -1
- package/dist/components/ui/separator.cjs +4 -3
- package/dist/components/ui/separator.cjs.map +1 -1
- package/dist/components/ui/separator.mjs +3 -3
- package/dist/components/ui/separator.mjs.map +1 -1
- package/dist/components/ui/spacer.cjs +2 -0
- package/dist/components/ui/spacer.cjs.map +1 -1
- package/dist/components/ui/spacer.mjs +1 -0
- package/dist/components/ui/spacer.mjs.map +1 -1
- package/dist/components/ui/textarea.cjs +3 -1
- package/dist/components/ui/textarea.cjs.map +1 -1
- package/dist/components/ui/textarea.mjs +2 -1
- package/dist/components/ui/textarea.mjs.map +1 -1
- package/dist/components/undo-redo-button/undo-redo-button.cjs +6 -4
- package/dist/components/undo-redo-button/undo-redo-button.cjs.map +1 -1
- package/dist/components/undo-redo-button/undo-redo-button.mjs +6 -4
- package/dist/components/undo-redo-button/undo-redo-button.mjs.map +1 -1
- package/dist/components/undo-redo-button/use-undo-redo.cjs +4 -2
- package/dist/components/undo-redo-button/use-undo-redo.cjs.map +1 -1
- package/dist/components/undo-redo-button/use-undo-redo.mjs +3 -2
- package/dist/components/undo-redo-button/use-undo-redo.mjs.map +1 -1
- package/dist/extensions/code-block.cjs +8 -6
- package/dist/extensions/code-block.cjs.map +1 -1
- package/dist/extensions/code-block.mjs +7 -6
- package/dist/extensions/code-block.mjs.map +1 -1
- package/dist/extensions/editor.cjs +5 -3
- package/dist/extensions/editor.cjs.map +1 -1
- package/dist/extensions/editor.mjs +4 -3
- package/dist/extensions/editor.mjs.map +1 -1
- package/dist/extensions/index.cjs +4 -2
- package/dist/extensions/index.cjs.map +1 -1
- package/dist/extensions/index.mjs +3 -2
- package/dist/extensions/index.mjs.map +1 -1
- package/dist/extensions/shared.cjs +5 -3
- package/dist/extensions/shared.cjs.map +1 -1
- package/dist/extensions/shared.mjs +4 -3
- package/dist/extensions/shared.mjs.map +1 -1
- package/dist/hooks/use-copy-to-clipboard.cjs +3 -2
- package/dist/hooks/use-copy-to-clipboard.cjs.map +1 -1
- package/dist/hooks/use-copy-to-clipboard.mjs +2 -2
- package/dist/hooks/use-copy-to-clipboard.mjs.map +1 -1
- package/dist/hooks/use-floating-element.cjs +55 -0
- package/dist/hooks/use-floating-element.cjs.map +1 -0
- package/dist/hooks/use-floating-element.d.cts +21 -0
- package/dist/hooks/use-floating-element.d.ts +21 -0
- package/dist/hooks/use-floating-element.mjs +35 -0
- package/dist/hooks/use-floating-element.mjs.map +1 -0
- package/dist/hooks/use-markdown-editor.cjs +6 -1
- package/dist/hooks/use-markdown-editor.cjs.map +1 -1
- package/dist/hooks/use-markdown-editor.d.cts +1 -1
- package/dist/hooks/use-markdown-editor.d.ts +1 -1
- package/dist/hooks/use-markdown-editor.mjs +5 -1
- package/dist/hooks/use-markdown-editor.mjs.map +1 -1
- package/dist/index.cjs +18 -16
- package/dist/index.cjs.map +1 -1
- package/dist/index.mjs +17 -16
- package/dist/index.mjs.map +1 -1
- package/dist/lib/highlight-code-to-html.cjs +2 -0
- package/dist/lib/highlight-code-to-html.cjs.map +1 -1
- package/dist/lib/highlight-code-to-html.mjs +1 -0
- package/dist/lib/highlight-code-to-html.mjs.map +1 -1
- package/dist/lib/languages.cjs +4 -2
- package/dist/lib/languages.cjs.map +1 -1
- package/dist/lib/languages.mjs +3 -2
- package/dist/lib/languages.mjs.map +1 -1
- package/dist/lib/utils.cjs +2 -0
- package/dist/lib/utils.cjs.map +1 -1
- package/dist/lib/utils.mjs +1 -0
- package/dist/lib/utils.mjs.map +1 -1
- package/dist/notra-editor.cjs +17 -13
- package/dist/notra-editor.cjs.map +1 -1
- package/dist/notra-editor.mjs +17 -13
- package/dist/notra-editor.mjs.map +1 -1
- package/dist/notra-reader.cjs +9 -7
- package/dist/notra-reader.cjs.map +1 -1
- package/dist/notra-reader.mjs +8 -7
- package/dist/notra-reader.mjs.map +1 -1
- package/dist/styles/globals.css +6 -0
- package/dist/themes/default/editor.css +50 -0
- package/dist/utils/markdown-to-json.cjs +5 -3
- package/dist/utils/markdown-to-json.cjs.map +1 -1
- package/dist/utils/markdown-to-json.mjs +4 -3
- package/dist/utils/markdown-to-json.mjs.map +1 -1
- package/package.json +4 -1
|
@@ -1,48 +1,42 @@
|
|
|
1
1
|
"use client";
|
|
2
|
-
|
|
3
|
-
|
|
2
|
+
|
|
3
|
+
// src/components/image-popover/image-popover.tsx
|
|
4
|
+
import { ImageIcon } from "lucide-react";
|
|
4
5
|
import { forwardRef, useCallback, useEffect, useState } from "react";
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
8
|
-
import { Popover, PopoverContent, PopoverTrigger } from "../ui/popover";
|
|
9
|
-
import {
|
|
10
|
-
|
|
6
|
+
import { ImageInputForm } from "./image-input-form.mjs";
|
|
7
|
+
import { useImagePopover } from "./use-image-popover.mjs";
|
|
8
|
+
import { Button } from "../ui/button.mjs";
|
|
9
|
+
import { Popover, PopoverContent, PopoverTrigger } from "../ui/popover.mjs";
|
|
10
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
11
|
+
var ImagePopover = forwardRef(
|
|
11
12
|
({ editor, ...buttonProps }, ref) => {
|
|
12
13
|
const [isOpen, setIsOpen] = useState(false);
|
|
13
|
-
const {
|
|
14
|
-
url,
|
|
15
|
-
setUrl,
|
|
16
|
-
alt,
|
|
17
|
-
setAlt,
|
|
18
|
-
isActive,
|
|
19
|
-
canSet,
|
|
20
|
-
setImage,
|
|
21
|
-
removeImage,
|
|
22
|
-
wasSelectionMove
|
|
23
|
-
} = useImagePopover({ editor });
|
|
14
|
+
const { url, alt, isActive, canSet, removeImage, wasSelectionMove } = useImagePopover({ editor });
|
|
24
15
|
useEffect(() => {
|
|
25
16
|
if (isActive && wasSelectionMove) {
|
|
26
17
|
setIsOpen(true);
|
|
27
18
|
}
|
|
28
19
|
}, [isActive, wasSelectionMove]);
|
|
29
|
-
const
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
}, [removeImage]);
|
|
37
|
-
const handleKeyDown = useCallback(
|
|
38
|
-
(event) => {
|
|
39
|
-
if (event.key === "Enter") {
|
|
40
|
-
event.preventDefault();
|
|
41
|
-
handleSetImage();
|
|
20
|
+
const handleSubmit = useCallback(
|
|
21
|
+
(values) => {
|
|
22
|
+
if (!editor) return;
|
|
23
|
+
if (!values.url) {
|
|
24
|
+
if (isActive) removeImage();
|
|
25
|
+
setIsOpen(false);
|
|
26
|
+
return;
|
|
42
27
|
}
|
|
28
|
+
editor.chain().focus().setImage({
|
|
29
|
+
src: values.url,
|
|
30
|
+
alt: values.alt || void 0
|
|
31
|
+
}).run();
|
|
32
|
+
setIsOpen(false);
|
|
43
33
|
},
|
|
44
|
-
[
|
|
34
|
+
[editor, isActive, removeImage]
|
|
45
35
|
);
|
|
36
|
+
const handleRemove = useCallback(() => {
|
|
37
|
+
removeImage();
|
|
38
|
+
setIsOpen(false);
|
|
39
|
+
}, [removeImage]);
|
|
46
40
|
return /* @__PURE__ */ jsxs(Popover, { open: isOpen, onOpenChange: setIsOpen, children: [
|
|
47
41
|
/* @__PURE__ */ jsx(PopoverTrigger, { asChild: true, children: /* @__PURE__ */ jsx(
|
|
48
42
|
Button,
|
|
@@ -65,68 +59,17 @@ const ImagePopover = forwardRef(
|
|
|
65
59
|
)
|
|
66
60
|
}
|
|
67
61
|
) }),
|
|
68
|
-
/* @__PURE__ */
|
|
69
|
-
|
|
62
|
+
/* @__PURE__ */ jsx(PopoverContent, { align: "start", className: "nt:w-auto nt:p-0", children: /* @__PURE__ */ jsx(
|
|
63
|
+
ImageInputForm,
|
|
70
64
|
{
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
autoFocus: true,
|
|
78
|
-
className: "nt:h-7 nt:border-none nt:shadow-none nt:focus-visible:ring-0",
|
|
79
|
-
placeholder: "Paste image URL...",
|
|
80
|
-
type: "url",
|
|
81
|
-
value: url,
|
|
82
|
-
onChange: (e) => setUrl(e.target.value),
|
|
83
|
-
onKeyDown: handleKeyDown
|
|
84
|
-
}
|
|
85
|
-
),
|
|
86
|
-
/* @__PURE__ */ jsx(
|
|
87
|
-
Input,
|
|
88
|
-
{
|
|
89
|
-
className: "nt:h-7 nt:border-none nt:shadow-none nt:focus-visible:ring-0",
|
|
90
|
-
placeholder: "Alt text (optional)",
|
|
91
|
-
type: "text",
|
|
92
|
-
value: alt,
|
|
93
|
-
onChange: (e) => setAlt(e.target.value),
|
|
94
|
-
onKeyDown: handleKeyDown
|
|
95
|
-
}
|
|
96
|
-
),
|
|
97
|
-
/* @__PURE__ */ jsxs("div", { className: "nt:flex nt:items-center nt:justify-end nt:gap-1", children: [
|
|
98
|
-
/* @__PURE__ */ jsx(
|
|
99
|
-
Button,
|
|
100
|
-
{
|
|
101
|
-
"aria-label": "Apply image",
|
|
102
|
-
disabled: !url && !isActive,
|
|
103
|
-
size: "icon-sm",
|
|
104
|
-
tabIndex: -1,
|
|
105
|
-
type: "button",
|
|
106
|
-
variant: "ghost",
|
|
107
|
-
onClick: handleSetImage,
|
|
108
|
-
children: /* @__PURE__ */ jsx(CornerDownLeft, {})
|
|
109
|
-
}
|
|
110
|
-
),
|
|
111
|
-
isActive && /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
112
|
-
/* @__PURE__ */ jsx(Separator, { className: "nt:h-5", orientation: "vertical" }),
|
|
113
|
-
/* @__PURE__ */ jsx(
|
|
114
|
-
Button,
|
|
115
|
-
{
|
|
116
|
-
"aria-label": "Remove image",
|
|
117
|
-
size: "icon-sm",
|
|
118
|
-
tabIndex: -1,
|
|
119
|
-
type: "button",
|
|
120
|
-
variant: "ghost",
|
|
121
|
-
onClick: handleRemoveImage,
|
|
122
|
-
children: /* @__PURE__ */ jsx(Trash2, {})
|
|
123
|
-
}
|
|
124
|
-
)
|
|
125
|
-
] })
|
|
126
|
-
] })
|
|
127
|
-
]
|
|
65
|
+
initialAlt: alt,
|
|
66
|
+
initialUrl: url,
|
|
67
|
+
showRemove: isActive,
|
|
68
|
+
onCancel: () => setIsOpen(false),
|
|
69
|
+
onRemove: handleRemove,
|
|
70
|
+
onSubmit: handleSubmit
|
|
128
71
|
}
|
|
129
|
-
)
|
|
72
|
+
) })
|
|
130
73
|
] });
|
|
131
74
|
}
|
|
132
75
|
);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/components/image-popover/image-popover.tsx"],"sourcesContent":["'use client';\n\nimport {
|
|
1
|
+
{"version":3,"sources":["../../../src/components/image-popover/image-popover.tsx"],"sourcesContent":["'use client';\n\nimport { ImageIcon } from 'lucide-react';\nimport { forwardRef, useCallback, useEffect, useState } from 'react';\n\nimport { ImageInputForm } from './image-input-form.js';\nimport { useImagePopover } from './use-image-popover.js';\nimport { Button } from '../ui/button.js';\nimport { Popover, PopoverContent, PopoverTrigger } from '../ui/popover.js';\n\nimport type { Editor } from '@tiptap/core';\n\nexport interface ImagePopoverProps extends Omit<\n\tReact.ButtonHTMLAttributes<HTMLButtonElement>,\n\t'type'\n> {\n\teditor: Editor | null;\n}\n\nexport const ImagePopover = forwardRef<HTMLButtonElement, ImagePopoverProps>(\n\t({ editor, ...buttonProps }, ref) => {\n\t\tconst [isOpen, setIsOpen] = useState(false);\n\n\t\tconst { url, alt, isActive, canSet, removeImage, wasSelectionMove } =\n\t\t\tuseImagePopover({ editor });\n\n\t\tuseEffect(() => {\n\t\t\tif (isActive && wasSelectionMove) {\n\t\t\t\tsetIsOpen(true);\n\t\t\t}\n\t\t}, [isActive, wasSelectionMove]);\n\n\t\t// Bypass useImagePopover.setImage — it reads url/alt from hook state,\n\t\t// which lags behind the form values when called synchronously after the\n\t\t// hook's setUrl/setAlt setters. Submit values directly to the editor.\n\t\tconst handleSubmit = useCallback(\n\t\t\t(values: { url: string; alt: string }) => {\n\t\t\t\tif (!editor) return;\n\n\t\t\t\tif (!values.url) {\n\t\t\t\t\tif (isActive) removeImage();\n\n\t\t\t\t\tsetIsOpen(false);\n\n\t\t\t\t\treturn;\n\t\t\t\t}\n\n\t\t\t\teditor\n\t\t\t\t\t.chain()\n\t\t\t\t\t.focus()\n\t\t\t\t\t.setImage({\n\t\t\t\t\t\tsrc: values.url,\n\t\t\t\t\t\talt: values.alt || undefined\n\t\t\t\t\t})\n\t\t\t\t\t.run();\n\t\t\t\tsetIsOpen(false);\n\t\t\t},\n\t\t\t[editor, isActive, removeImage]\n\t\t);\n\n\t\tconst handleRemove = useCallback(() => {\n\t\t\tremoveImage();\n\t\t\tsetIsOpen(false);\n\t\t}, [removeImage]);\n\n\t\treturn (\n\t\t\t<Popover open={isOpen} onOpenChange={setIsOpen}>\n\t\t\t\t<PopoverTrigger asChild>\n\t\t\t\t\t<Button\n\t\t\t\t\t\tref={ref}\n\t\t\t\t\t\taria-label=\"Image\"\n\t\t\t\t\t\taria-pressed={isActive}\n\t\t\t\t\t\tdata-active-state={isActive ? 'on' : 'off'}\n\t\t\t\t\t\tdisabled={!canSet}\n\t\t\t\t\t\tsize=\"icon\"\n\t\t\t\t\t\ttabIndex={-1}\n\t\t\t\t\t\ttype=\"button\"\n\t\t\t\t\t\tvariant=\"ghost\"\n\t\t\t\t\t\t{...buttonProps}\n\t\t\t\t\t>\n\t\t\t\t\t\t<ImageIcon\n\t\t\t\t\t\t\tclassName={\n\t\t\t\t\t\t\t\tisActive ? 'nt:text-[var(--tt-brand-color-500)]' : undefined\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t/>\n\t\t\t\t\t</Button>\n\t\t\t\t</PopoverTrigger>\n\t\t\t\t<PopoverContent align=\"start\" className=\"nt:w-auto nt:p-0\">\n\t\t\t\t\t<ImageInputForm\n\t\t\t\t\t\tinitialAlt={alt}\n\t\t\t\t\t\tinitialUrl={url}\n\t\t\t\t\t\tshowRemove={isActive}\n\t\t\t\t\t\tonCancel={() => setIsOpen(false)}\n\t\t\t\t\t\tonRemove={handleRemove}\n\t\t\t\t\t\tonSubmit={handleSubmit}\n\t\t\t\t\t/>\n\t\t\t\t</PopoverContent>\n\t\t\t</Popover>\n\t\t);\n\t}\n);\n\nImagePopover.displayName = 'ImagePopover';\n"],"mappings":";;;AAEA,SAAS,iBAAiB;AAC1B,SAAS,YAAY,aAAa,WAAW,gBAAgB;AAE7D,SAAS,sBAAsB;AAC/B,SAAS,uBAAuB;AAChC,SAAS,cAAc;AACvB,SAAS,SAAS,gBAAgB,sBAAsB;AA0DrD,SAcG,KAdH;AA/CI,IAAM,eAAe;AAAA,EAC3B,CAAC,EAAE,QAAQ,GAAG,YAAY,GAAG,QAAQ;AACpC,UAAM,CAAC,QAAQ,SAAS,IAAI,SAAS,KAAK;AAE1C,UAAM,EAAE,KAAK,KAAK,UAAU,QAAQ,aAAa,iBAAiB,IACjE,gBAAgB,EAAE,OAAO,CAAC;AAE3B,cAAU,MAAM;AACf,UAAI,YAAY,kBAAkB;AACjC,kBAAU,IAAI;AAAA,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to;
|
|
17
17
|
};
|
|
18
18
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// src/components/image-popover/use-image-popover.ts
|
|
19
21
|
var use_image_popover_exports = {};
|
|
20
22
|
__export(use_image_popover_exports, {
|
|
21
23
|
useImagePopover: () => useImagePopover
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/components/image-popover/use-image-popover.ts"],"sourcesContent":["import { useCallback, useEffect, useState } from 'react';\n\nimport type { Editor } from '@tiptap/core';\nimport type {} from '@tiptap/extension-image';\nimport type { Transaction } from '@tiptap/pm/state';\n\nexport interface UseImagePopoverConfig {\n\teditor: Editor | null;\n}\n\nexport function useImagePopover({ editor }: UseImagePopoverConfig) {\n\tconst [url, setUrl] = useState('');\n\tconst [alt, setAlt] = useState('');\n\tconst [isActive, setIsActive] = useState(false);\n\tconst [canSet, setCanSet] = useState(false);\n\tconst [wasSelectionMove, setWasSelectionMove] = useState(false);\n\n\tuseEffect(() => {\n\t\tif (!editor) return;\n\n\t\tconst handleUpdate = ({\n\t\t\ttransaction\n\t\t}: { transaction?: Transaction } = {}) => {\n\t\t\tconst active = editor.isActive('image');\n\n\t\t\tsetIsActive(active);\n\t\t\tsetCanSet(editor.isEditable);\n\n\t\t\tif (transaction) {\n\t\t\t\tsetWasSelectionMove(!transaction.docChanged);\n\t\t\t}\n\n\t\t\tif (active) {\n\t\t\t\tconst attrs = editor.getAttributes('image');\n\n\t\t\t\tsetUrl(attrs.src ?? '');\n\t\t\t\tsetAlt(attrs.alt ?? '');\n\t\t\t}\n\t\t};\n\n\t\thandleUpdate();\n\n\t\teditor.on('selectionUpdate', handleUpdate);\n\t\teditor.on('transaction', handleUpdate);\n\n\t\treturn () => {\n\t\t\teditor.off('selectionUpdate', handleUpdate);\n\t\t\teditor.off('transaction', handleUpdate);\n\t\t};\n\t}, [editor]);\n\n\tconst removeImage = useCallback(() => {\n\t\tif (!editor) return;\n\n\t\teditor.chain().focus().deleteSelection().run();\n\t\tsetUrl('');\n\t\tsetAlt('');\n\t}, [editor]);\n\n\tconst setImage = useCallback(() => {\n\t\tif (!editor) return;\n\n\t\tif (!url) {\n\t\t\tif (isActive) {\n\t\t\t\tremoveImage();\n\t\t\t}\n\n\t\t\treturn;\n\t\t}\n\n\t\teditor\n\t\t\t.chain()\n\t\t\t.focus()\n\t\t\t.setImage({ src: url, alt: alt || undefined })\n\t\t\t.run();\n\t}, [editor, url, alt, isActive, removeImage]);\n\n\treturn {\n\t\turl,\n\t\tsetUrl,\n\t\talt,\n\t\tsetAlt,\n\t\tisActive,\n\t\tcanSet,\n\t\tsetImage,\n\t\tremoveImage,\n\t\twasSelectionMove\n\t};\n}\n"],"mappings":"
|
|
1
|
+
{"version":3,"sources":["../../../src/components/image-popover/use-image-popover.ts"],"sourcesContent":["import { useCallback, useEffect, useState } from 'react';\n\nimport type { Editor } from '@tiptap/core';\nimport type {} from '@tiptap/extension-image';\nimport type { Transaction } from '@tiptap/pm/state';\n\nexport interface UseImagePopoverConfig {\n\teditor: Editor | null;\n}\n\nexport function useImagePopover({ editor }: UseImagePopoverConfig) {\n\tconst [url, setUrl] = useState('');\n\tconst [alt, setAlt] = useState('');\n\tconst [isActive, setIsActive] = useState(false);\n\tconst [canSet, setCanSet] = useState(false);\n\tconst [wasSelectionMove, setWasSelectionMove] = useState(false);\n\n\tuseEffect(() => {\n\t\tif (!editor) return;\n\n\t\tconst handleUpdate = ({\n\t\t\ttransaction\n\t\t}: { transaction?: Transaction } = {}) => {\n\t\t\tconst active = editor.isActive('image');\n\n\t\t\tsetIsActive(active);\n\t\t\tsetCanSet(editor.isEditable);\n\n\t\t\tif (transaction) {\n\t\t\t\tsetWasSelectionMove(!transaction.docChanged);\n\t\t\t}\n\n\t\t\tif (active) {\n\t\t\t\tconst attrs = editor.getAttributes('image');\n\n\t\t\t\tsetUrl(attrs.src ?? '');\n\t\t\t\tsetAlt(attrs.alt ?? '');\n\t\t\t}\n\t\t};\n\n\t\thandleUpdate();\n\n\t\teditor.on('selectionUpdate', handleUpdate);\n\t\teditor.on('transaction', handleUpdate);\n\n\t\treturn () => {\n\t\t\teditor.off('selectionUpdate', handleUpdate);\n\t\t\teditor.off('transaction', handleUpdate);\n\t\t};\n\t}, [editor]);\n\n\tconst removeImage = useCallback(() => {\n\t\tif (!editor) return;\n\n\t\teditor.chain().focus().deleteSelection().run();\n\t\tsetUrl('');\n\t\tsetAlt('');\n\t}, [editor]);\n\n\tconst setImage = useCallback(() => {\n\t\tif (!editor) return;\n\n\t\tif (!url) {\n\t\t\tif (isActive) {\n\t\t\t\tremoveImage();\n\t\t\t}\n\n\t\t\treturn;\n\t\t}\n\n\t\teditor\n\t\t\t.chain()\n\t\t\t.focus()\n\t\t\t.setImage({ src: url, alt: alt || undefined })\n\t\t\t.run();\n\t}, [editor, url, alt, isActive, removeImage]);\n\n\treturn {\n\t\turl,\n\t\tsetUrl,\n\t\talt,\n\t\tsetAlt,\n\t\tisActive,\n\t\tcanSet,\n\t\tsetImage,\n\t\tremoveImage,\n\t\twasSelectionMove\n\t};\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,mBAAiD;AAU1C,SAAS,gBAAgB,EAAE,OAAO,GAA0B;AAClE,QAAM,CAAC,KAAK,MAAM,QAAI,uBAAS,EAAE;AACjC,QAAM,CAAC,KAAK,MAAM,QAAI,uBAAS,EAAE;AACjC,QAAM,CAAC,UAAU,WAAW,QAAI,uBAAS,KAAK;AAC9C,QAAM,CAAC,QAAQ,SAAS,QAAI,uBAAS,KAAK;AAC1C,QAAM,CAAC,kBAAkB,mBAAmB,QAAI,uBAAS,KAAK;AAE9D,8BAAU,MAAM;AACf,QAAI,CAAC,OAAQ;AAEb,UAAM,eAAe,CAAC;AAAA,MACrB;AAAA,IACD,IAAmC,CAAC,MAAM;AACzC,YAAM,SAAS,OAAO,SAAS,OAAO;AAEtC,kBAAY,MAAM;AAClB,gBAAU,OAAO,UAAU;AAE3B,UAAI,aAAa;AAChB,4BAAoB,CAAC,YAAY,UAAU;AAAA,MAC5C;AAEA,UAAI,QAAQ;AACX,cAAM,QAAQ,OAAO,cAAc,OAAO;AAE1C,eAAO,MAAM,OAAO,EAAE;AACtB,eAAO,MAAM,OAAO,EAAE;AAAA,MACvB;AAAA,IACD;AAEA,iBAAa;AAEb,WAAO,GAAG,mBAAmB,YAAY;AACzC,WAAO,GAAG,eAAe,YAAY;AAErC,WAAO,MAAM;AACZ,aAAO,IAAI,mBAAmB,YAAY;AAC1C,aAAO,IAAI,eAAe,YAAY;AAAA,IACvC;AAAA,EACD,GAAG,CAAC,MAAM,CAAC;AAEX,QAAM,kBAAc,0BAAY,MAAM;AACrC,QAAI,CAAC,OAAQ;AAEb,WAAO,MAAM,EAAE,MAAM,EAAE,gBAAgB,EAAE,IAAI;AAC7C,WAAO,EAAE;AACT,WAAO,EAAE;AAAA,EACV,GAAG,CAAC,MAAM,CAAC;AAEX,QAAM,eAAW,0BAAY,MAAM;AAClC,QAAI,CAAC,OAAQ;AAEb,QAAI,CAAC,KAAK;AACT,UAAI,UAAU;AACb,oBAAY;AAAA,MACb;AAEA;AAAA,IACD;AAEA,WACE,MAAM,EACN,MAAM,EACN,SAAS,EAAE,KAAK,KAAK,KAAK,OAAO,OAAU,CAAC,EAC5C,IAAI;AAAA,EACP,GAAG,CAAC,QAAQ,KAAK,KAAK,UAAU,WAAW,CAAC;AAE5C,SAAO;AAAA,IACN;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EACD;AACD;","names":[]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/components/image-popover/use-image-popover.ts"],"sourcesContent":["import { useCallback, useEffect, useState } from 'react';\n\nimport type { Editor } from '@tiptap/core';\nimport type {} from '@tiptap/extension-image';\nimport type { Transaction } from '@tiptap/pm/state';\n\nexport interface UseImagePopoverConfig {\n\teditor: Editor | null;\n}\n\nexport function useImagePopover({ editor }: UseImagePopoverConfig) {\n\tconst [url, setUrl] = useState('');\n\tconst [alt, setAlt] = useState('');\n\tconst [isActive, setIsActive] = useState(false);\n\tconst [canSet, setCanSet] = useState(false);\n\tconst [wasSelectionMove, setWasSelectionMove] = useState(false);\n\n\tuseEffect(() => {\n\t\tif (!editor) return;\n\n\t\tconst handleUpdate = ({\n\t\t\ttransaction\n\t\t}: { transaction?: Transaction } = {}) => {\n\t\t\tconst active = editor.isActive('image');\n\n\t\t\tsetIsActive(active);\n\t\t\tsetCanSet(editor.isEditable);\n\n\t\t\tif (transaction) {\n\t\t\t\tsetWasSelectionMove(!transaction.docChanged);\n\t\t\t}\n\n\t\t\tif (active) {\n\t\t\t\tconst attrs = editor.getAttributes('image');\n\n\t\t\t\tsetUrl(attrs.src ?? '');\n\t\t\t\tsetAlt(attrs.alt ?? '');\n\t\t\t}\n\t\t};\n\n\t\thandleUpdate();\n\n\t\teditor.on('selectionUpdate', handleUpdate);\n\t\teditor.on('transaction', handleUpdate);\n\n\t\treturn () => {\n\t\t\teditor.off('selectionUpdate', handleUpdate);\n\t\t\teditor.off('transaction', handleUpdate);\n\t\t};\n\t}, [editor]);\n\n\tconst removeImage = useCallback(() => {\n\t\tif (!editor) return;\n\n\t\teditor.chain().focus().deleteSelection().run();\n\t\tsetUrl('');\n\t\tsetAlt('');\n\t}, [editor]);\n\n\tconst setImage = useCallback(() => {\n\t\tif (!editor) return;\n\n\t\tif (!url) {\n\t\t\tif (isActive) {\n\t\t\t\tremoveImage();\n\t\t\t}\n\n\t\t\treturn;\n\t\t}\n\n\t\teditor\n\t\t\t.chain()\n\t\t\t.focus()\n\t\t\t.setImage({ src: url, alt: alt || undefined })\n\t\t\t.run();\n\t}, [editor, url, alt, isActive, removeImage]);\n\n\treturn {\n\t\turl,\n\t\tsetUrl,\n\t\talt,\n\t\tsetAlt,\n\t\tisActive,\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AAQ;AAEb,QAAI,CAAC,KAAK;AACT,UAAI,UAAU;AACb,oBAAY;AAAA,MACb;AAEA;AAAA,IACD;AAEA,WACE,MAAM,EACN,MAAM,EACN,SAAS,EAAE,KAAK,KAAK,KAAK,OAAO,OAAU,CAAC,EAC5C,IAAI;AAAA,EACP,GAAG,CAAC,QAAQ,KAAK,KAAK,UAAU,WAAW,CAAC;AAE5C,SAAO;AAAA,IACN;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EACD;AACD;","names":[]}
|
|
1
|
+
{"version":3,"sources":["../../../src/components/image-popover/use-image-popover.ts"],"sourcesContent":["import { useCallback, useEffect, useState } from 'react';\n\nimport type { Editor } from '@tiptap/core';\nimport type {} from '@tiptap/extension-image';\nimport type { Transaction } from '@tiptap/pm/state';\n\nexport interface UseImagePopoverConfig {\n\teditor: Editor | null;\n}\n\nexport function useImagePopover({ editor }: UseImagePopoverConfig) {\n\tconst [url, setUrl] = useState('');\n\tconst [alt, setAlt] = useState('');\n\tconst [isActive, setIsActive] = useState(false);\n\tconst [canSet, setCanSet] = useState(false);\n\tconst [wasSelectionMove, setWasSelectionMove] = useState(false);\n\n\tuseEffect(() => {\n\t\tif (!editor) return;\n\n\t\tconst handleUpdate = ({\n\t\t\ttransaction\n\t\t}: { transaction?: Transaction } = {}) => {\n\t\t\tconst active = editor.isActive('image');\n\n\t\t\tsetIsActive(active);\n\t\t\tsetCanSet(editor.isEditable);\n\n\t\t\tif (transaction) {\n\t\t\t\tsetWasSelectionMove(!transaction.docChanged);\n\t\t\t}\n\n\t\t\tif (active) {\n\t\t\t\tconst attrs = editor.getAttributes('image');\n\n\t\t\t\tsetUrl(attrs.src ?? '');\n\t\t\t\tsetAlt(attrs.alt ?? '');\n\t\t\t}\n\t\t};\n\n\t\thandleUpdate();\n\n\t\teditor.on('selectionUpdate', handleUpdate);\n\t\teditor.on('transaction', handleUpdate);\n\n\t\treturn () => {\n\t\t\teditor.off('selectionUpdate', handleUpdate);\n\t\t\teditor.off('transaction', handleUpdate);\n\t\t};\n\t}, [editor]);\n\n\tconst removeImage = useCallback(() => {\n\t\tif (!editor) return;\n\n\t\teditor.chain().focus().deleteSelection().run();\n\t\tsetUrl('');\n\t\tsetAlt('');\n\t}, [editor]);\n\n\tconst setImage = useCallback(() => {\n\t\tif (!editor) return;\n\n\t\tif (!url) {\n\t\t\tif (isActive) {\n\t\t\t\tremoveImage();\n\t\t\t}\n\n\t\t\treturn;\n\t\t}\n\n\t\teditor\n\t\t\t.chain()\n\t\t\t.focus()\n\t\t\t.setImage({ src: url, alt: alt || undefined })\n\t\t\t.run();\n\t}, [editor, url, alt, isActive, removeImage]);\n\n\treturn {\n\t\turl,\n\t\tsetUrl,\n\t\talt,\n\t\tsetAlt,\n\t\tisActive,\n\t\tcanSet,\n\t\tsetImage,\n\t\tremoveImage,\n\t\twasSelectionMove\n\t};\n}\n"],"mappings":";AAAA,SAAS,aAAa,WAAW,gBAAgB;AAU1C,SAAS,gBAAgB,EAAE,OAAO,GAA0B;AAClE,QAAM,CAAC,KAAK,MAAM,IAAI,SAAS,EAAE;AACjC,QAAM,CAAC,KAAK,MAAM,IAAI,SAAS,EAAE;AACjC,QAAM,CAAC,UAAU,WAAW,IAAI,SAAS,KAAK;AAC9C,QAAM,CAAC,QAAQ,SAAS,IAAI,SAAS,KAAK;AAC1C,QAAM,CAAC,kBAAkB,mBAAmB,IAAI,SAAS,KAAK;AAE9D,YAAU,MAAM;AACf,QAAI,CAAC,OAAQ;AAEb,UAAM,eAAe,CAAC;AAAA,MACrB;AAAA,IACD,IAAmC,CAAC,MAAM;AACzC,YAAM,SAAS,OAAO,SAAS,OAAO;AAEtC,kBAAY,MAAM;AAClB,gBAAU,OAAO,UAAU;AAE3B,UAAI,aAAa;AAChB,4BAAoB,CAAC,YAAY,UAAU;AAAA,MAC5C;AAEA,UAAI,QAAQ;AACX,cAAM,QAAQ,OAAO,cAAc,OAAO;AAE1C,eAAO,MAAM,OAAO,EAAE;AACtB,eAAO,MAAM,OAAO,EAAE;AAAA,MACvB;AAAA,IACD;AAEA,iBAAa;AAEb,WAAO,GAAG,mBAAmB,YAAY;AACzC,WAAO,GAAG,eAAe,YAAY;AAErC,WAAO,MAAM;AACZ,aAAO,IAAI,mBAAmB,YAAY;AAC1C,aAAO,IAAI,eAAe,YAAY;AAAA,IACvC;AAAA,EACD,GAAG,CAAC,MAAM,CAAC;AAEX,QAAM,cAAc,YAAY,MAAM;AACrC,QAAI,CAAC,OAAQ;AAEb,WAAO,MAAM,EAAE,MAAM,EAAE,gBAAgB,EAAE,IAAI;AAC7C,WAAO,EAAE;AACT,WAAO,EAAE;AAAA,EACV,GAAG,CAAC,MAAM,CAAC;AAEX,QAAM,WAAW,YAAY,MAAM;AAClC,QAAI,CAAC,OAAQ;AAEb,QAAI,CAAC,KAAK;AACT,UAAI,UAAU;AACb,oBAAY;AAAA,MACb;AAEA;AAAA,IACD;AAEA,WACE,MAAM,EACN,MAAM,EACN,SAAS,EAAE,KAAK,KAAK,KAAK,OAAO,OAAU,CAAC,EAC5C,IAAI;AAAA,EACP,GAAG,CAAC,QAAQ,KAAK,KAAK,UAAU,WAAW,CAAC;AAE5C,SAAO;AAAA,IACN;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EACD;AACD;","names":[]}
|
|
@@ -17,20 +17,22 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
17
17
|
return to;
|
|
18
18
|
};
|
|
19
19
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
20
|
+
|
|
21
|
+
// src/components/link-popover/link-popover.tsx
|
|
20
22
|
var link_popover_exports = {};
|
|
21
23
|
__export(link_popover_exports, {
|
|
22
24
|
LinkPopover: () => LinkPopover
|
|
23
25
|
});
|
|
24
26
|
module.exports = __toCommonJS(link_popover_exports);
|
|
25
|
-
var import_jsx_runtime = require("react/jsx-runtime");
|
|
26
27
|
var import_lucide_react = require("lucide-react");
|
|
27
28
|
var import_react = require("react");
|
|
28
|
-
var import_use_link_popover = require("./use-link-popover");
|
|
29
|
-
var import_button = require("../ui/button");
|
|
30
|
-
var import_input = require("../ui/input");
|
|
31
|
-
var import_popover = require("../ui/popover");
|
|
32
|
-
var import_separator = require("../ui/separator");
|
|
33
|
-
|
|
29
|
+
var import_use_link_popover = require("./use-link-popover.cjs");
|
|
30
|
+
var import_button = require("../ui/button.cjs");
|
|
31
|
+
var import_input = require("../ui/input.cjs");
|
|
32
|
+
var import_popover = require("../ui/popover.cjs");
|
|
33
|
+
var import_separator = require("../ui/separator.cjs");
|
|
34
|
+
var import_jsx_runtime = require("react/jsx-runtime");
|
|
35
|
+
var LinkPopover = (0, import_react.forwardRef)(
|
|
34
36
|
({ editor, ...buttonProps }, ref) => {
|
|
35
37
|
const [isOpen, setIsOpen] = (0, import_react.useState)(false);
|
|
36
38
|
const {
|
|
@@ -91,7 +93,7 @@ const LinkPopover = (0, import_react.forwardRef)(
|
|
|
91
93
|
import_popover.PopoverContent,
|
|
92
94
|
{
|
|
93
95
|
align: "start",
|
|
94
|
-
className: "nt:flex nt:w-auto nt:items-center nt:gap-1 nt:p-1",
|
|
96
|
+
className: "nt:flex nt:w-auto nt:flex-row nt:items-center nt:gap-1 nt:p-1",
|
|
95
97
|
children: [
|
|
96
98
|
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
97
99
|
import_input.Input,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/components/link-popover/link-popover.tsx"],"sourcesContent":["'use client';\n\nimport {\n\tCornerDownLeft,\n\tExternalLink,\n\tLink as LinkIcon,\n\tTrash2\n} from 'lucide-react';\nimport { forwardRef, useCallback, useEffect, useState } from 'react';\n\nimport { useLinkPopover } from './use-link-popover';\nimport { Button } from '../ui/button';\nimport { Input } from '../ui/input';\nimport { Popover, PopoverContent, PopoverTrigger } from '../ui/popover';\nimport { Separator } from '../ui/separator';\n\nimport type { Editor } from '@tiptap/core';\n\nexport interface LinkPopoverProps extends Omit<\n\tReact.ButtonHTMLAttributes<HTMLButtonElement>,\n\t'type'\n> {\n\teditor: Editor | null;\n}\n\nexport const LinkPopover = forwardRef<HTMLButtonElement, LinkPopoverProps>(\n\t({ editor, ...buttonProps }, ref) => {\n\t\tconst [isOpen, setIsOpen] = useState(false);\n\n\t\tconst {\n\t\t\turl,\n\t\t\tsetUrl,\n\t\t\tisActive,\n\t\t\tcanSet,\n\t\t\tsetLink,\n\t\t\tremoveLink,\n\t\t\topenLink,\n\t\t\twasSelectionMove\n\t\t} = useLinkPopover({ editor });\n\n\t\t// Auto-open popover when cursor moves onto an existing link (selection-only transaction)\n\t\tuseEffect(() => {\n\t\t\tif (isActive && wasSelectionMove) {\n\t\t\t\tsetIsOpen(true);\n\t\t\t}\n\t\t}, [isActive, wasSelectionMove]);\n\n\t\tconst handleSetLink = useCallback(() => {\n\t\t\tsetLink();\n\t\t\tsetIsOpen(false);\n\t\t}, [setLink]);\n\n\t\tconst handleRemoveLink = useCallback(() => {\n\t\t\tremoveLink();\n\t\t\tsetIsOpen(false);\n\t\t}, [removeLink]);\n\n\t\tconst handleKeyDown = useCallback(\n\t\t\t(event: React.KeyboardEvent<HTMLInputElement>) => {\n\t\t\t\tif (event.key === 'Enter') {\n\t\t\t\t\tevent.preventDefault();\n\t\t\t\t\thandleSetLink();\n\t\t\t\t}\n\t\t\t},\n\t\t\t[handleSetLink]\n\t\t);\n\n\t\treturn (\n\t\t\t<Popover open={isOpen} onOpenChange={setIsOpen}>\n\t\t\t\t<PopoverTrigger asChild>\n\t\t\t\t\t<Button\n\t\t\t\t\t\tref={ref}\n\t\t\t\t\t\taria-label=\"Link\"\n\t\t\t\t\t\taria-pressed={isActive}\n\t\t\t\t\t\tdata-active-state={isActive ? 'on' : 'off'}\n\t\t\t\t\t\tdisabled={!canSet}\n\t\t\t\t\t\tsize=\"icon\"\n\t\t\t\t\t\ttabIndex={-1}\n\t\t\t\t\t\ttype=\"button\"\n\t\t\t\t\t\tvariant=\"ghost\"\n\t\t\t\t\t\t{...buttonProps}\n\t\t\t\t\t>\n\t\t\t\t\t\t<LinkIcon\n\t\t\t\t\t\t\tclassName={\n\t\t\t\t\t\t\t\tisActive ? 'nt:text-[var(--tt-brand-color-500)]' : undefined\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t/>\n\t\t\t\t\t</Button>\n\t\t\t\t</PopoverTrigger>\n\t\t\t\t<PopoverContent\n\t\t\t\t\talign=\"start\"\n\t\t\t\t\tclassName=\"nt:flex nt:w-auto nt:items-center nt:gap-1 nt:p-1\"\n\t\t\t\t>\n\t\t\t\t\t<Input\n\t\t\t\t\t\tautoFocus\n\t\t\t\t\t\tclassName=\"nt:h-7 nt:min-w-48 nt:border-none nt:shadow-none nt:focus-visible:ring-0\"\n\t\t\t\t\t\tplaceholder=\"Paste a link...\"\n\t\t\t\t\t\ttype=\"url\"\n\t\t\t\t\t\tvalue={url}\n\t\t\t\t\t\tonChange={(e) => setUrl(e.target.value)}\n\t\t\t\t\t\tonKeyDown={handleKeyDown}\n\t\t\t\t\t/>\n\t\t\t\t\t<Button\n\t\t\t\t\t\taria-label=\"Apply link\"\n\t\t\t\t\t\tdisabled={!url && !isActive}\n\t\t\t\t\t\tsize=\"icon-sm\"\n\t\t\t\t\t\ttabIndex={-1}\n\t\t\t\t\t\ttype=\"button\"\n\t\t\t\t\t\tvariant=\"ghost\"\n\t\t\t\t\t\tonClick={handleSetLink}\n\t\t\t\t\t>\n\t\t\t\t\t\t<CornerDownLeft />\n\t\t\t\t\t</Button>\n\t\t\t\t\t<Separator className=\"nt:h-5\" orientation=\"vertical\" />\n\t\t\t\t\t<Button\n\t\t\t\t\t\taria-label=\"Open link in new window\"\n\t\t\t\t\t\tsize=\"icon-sm\"\n\t\t\t\t\t\ttabIndex={-1}\n\t\t\t\t\t\ttype=\"button\"\n\t\t\t\t\t\tvariant=\"ghost\"\n\t\t\t\t\t\tonClick={openLink}\n\t\t\t\t\t>\n\t\t\t\t\t\t<ExternalLink />\n\t\t\t\t\t</Button>\n\t\t\t\t\t<Button\n\t\t\t\t\t\taria-label=\"Remove link\"\n\t\t\t\t\t\tsize=\"icon-sm\"\n\t\t\t\t\t\ttabIndex={-1}\n\t\t\t\t\t\ttype=\"button\"\n\t\t\t\t\t\tvariant=\"ghost\"\n\t\t\t\t\t\tonClick={handleRemoveLink}\n\t\t\t\t\t>\n\t\t\t\t\t\t<Trash2 />\n\t\t\t\t\t</Button>\n\t\t\t\t</PopoverContent>\n\t\t\t</Popover>\n\t\t);\n\t}\n);\n\nLinkPopover.displayName = 'LinkPopover';\n"],"mappings":"
|
|
1
|
+
{"version":3,"sources":["../../../src/components/link-popover/link-popover.tsx"],"sourcesContent":["'use client';\n\nimport {\n\tCornerDownLeft,\n\tExternalLink,\n\tLink as LinkIcon,\n\tTrash2\n} from 'lucide-react';\nimport { forwardRef, useCallback, useEffect, useState } from 'react';\n\nimport { useLinkPopover } from './use-link-popover.js';\nimport { Button } from '../ui/button.js';\nimport { Input } from '../ui/input.js';\nimport { Popover, PopoverContent, PopoverTrigger } from '../ui/popover.js';\nimport { Separator } from '../ui/separator.js';\n\nimport type { Editor } from '@tiptap/core';\n\nexport interface LinkPopoverProps extends Omit<\n\tReact.ButtonHTMLAttributes<HTMLButtonElement>,\n\t'type'\n> {\n\teditor: Editor | null;\n}\n\nexport const LinkPopover = forwardRef<HTMLButtonElement, LinkPopoverProps>(\n\t({ editor, ...buttonProps }, ref) => {\n\t\tconst [isOpen, setIsOpen] = useState(false);\n\n\t\tconst {\n\t\t\turl,\n\t\t\tsetUrl,\n\t\t\tisActive,\n\t\t\tcanSet,\n\t\t\tsetLink,\n\t\t\tremoveLink,\n\t\t\topenLink,\n\t\t\twasSelectionMove\n\t\t} = useLinkPopover({ editor });\n\n\t\t// Auto-open popover when cursor moves onto an existing link (selection-only transaction)\n\t\tuseEffect(() => {\n\t\t\tif (isActive && wasSelectionMove) {\n\t\t\t\tsetIsOpen(true);\n\t\t\t}\n\t\t}, [isActive, wasSelectionMove]);\n\n\t\tconst handleSetLink = useCallback(() => {\n\t\t\tsetLink();\n\t\t\tsetIsOpen(false);\n\t\t}, [setLink]);\n\n\t\tconst handleRemoveLink = useCallback(() => {\n\t\t\tremoveLink();\n\t\t\tsetIsOpen(false);\n\t\t}, [removeLink]);\n\n\t\tconst handleKeyDown = useCallback(\n\t\t\t(event: React.KeyboardEvent<HTMLInputElement>) => {\n\t\t\t\tif (event.key === 'Enter') {\n\t\t\t\t\tevent.preventDefault();\n\t\t\t\t\thandleSetLink();\n\t\t\t\t}\n\t\t\t},\n\t\t\t[handleSetLink]\n\t\t);\n\n\t\treturn (\n\t\t\t<Popover open={isOpen} onOpenChange={setIsOpen}>\n\t\t\t\t<PopoverTrigger asChild>\n\t\t\t\t\t<Button\n\t\t\t\t\t\tref={ref}\n\t\t\t\t\t\taria-label=\"Link\"\n\t\t\t\t\t\taria-pressed={isActive}\n\t\t\t\t\t\tdata-active-state={isActive ? 'on' : 'off'}\n\t\t\t\t\t\tdisabled={!canSet}\n\t\t\t\t\t\tsize=\"icon\"\n\t\t\t\t\t\ttabIndex={-1}\n\t\t\t\t\t\ttype=\"button\"\n\t\t\t\t\t\tvariant=\"ghost\"\n\t\t\t\t\t\t{...buttonProps}\n\t\t\t\t\t>\n\t\t\t\t\t\t<LinkIcon\n\t\t\t\t\t\t\tclassName={\n\t\t\t\t\t\t\t\tisActive ? 'nt:text-[var(--tt-brand-color-500)]' : undefined\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t/>\n\t\t\t\t\t</Button>\n\t\t\t\t</PopoverTrigger>\n\t\t\t\t<PopoverContent\n\t\t\t\t\talign=\"start\"\n\t\t\t\t\tclassName=\"nt:flex nt:w-auto nt:flex-row nt:items-center nt:gap-1 nt:p-1\"\n\t\t\t\t>\n\t\t\t\t\t<Input\n\t\t\t\t\t\tautoFocus\n\t\t\t\t\t\tclassName=\"nt:h-7 nt:min-w-48 nt:border-none nt:shadow-none nt:focus-visible:ring-0\"\n\t\t\t\t\t\tplaceholder=\"Paste a link...\"\n\t\t\t\t\t\ttype=\"url\"\n\t\t\t\t\t\tvalue={url}\n\t\t\t\t\t\tonChange={(e) => setUrl(e.target.value)}\n\t\t\t\t\t\tonKeyDown={handleKeyDown}\n\t\t\t\t\t/>\n\t\t\t\t\t<Button\n\t\t\t\t\t\taria-label=\"Apply link\"\n\t\t\t\t\t\tdisabled={!url && !isActive}\n\t\t\t\t\t\tsize=\"icon-sm\"\n\t\t\t\t\t\ttabIndex={-1}\n\t\t\t\t\t\ttype=\"button\"\n\t\t\t\t\t\tvariant=\"ghost\"\n\t\t\t\t\t\tonClick={handleSetLink}\n\t\t\t\t\t>\n\t\t\t\t\t\t<CornerDownLeft />\n\t\t\t\t\t</Button>\n\t\t\t\t\t<Separator className=\"nt:h-5\" orientation=\"vertical\" />\n\t\t\t\t\t<Button\n\t\t\t\t\t\taria-label=\"Open link in new window\"\n\t\t\t\t\t\tsize=\"icon-sm\"\n\t\t\t\t\t\ttabIndex={-1}\n\t\t\t\t\t\ttype=\"button\"\n\t\t\t\t\t\tvariant=\"ghost\"\n\t\t\t\t\t\tonClick={openLink}\n\t\t\t\t\t>\n\t\t\t\t\t\t<ExternalLink />\n\t\t\t\t\t</Button>\n\t\t\t\t\t<Button\n\t\t\t\t\t\taria-label=\"Remove link\"\n\t\t\t\t\t\tsize=\"icon-sm\"\n\t\t\t\t\t\ttabIndex={-1}\n\t\t\t\t\t\ttype=\"button\"\n\t\t\t\t\t\tvariant=\"ghost\"\n\t\t\t\t\t\tonClick={handleRemoveLink}\n\t\t\t\t\t>\n\t\t\t\t\t\t<Trash2 />\n\t\t\t\t\t</Button>\n\t\t\t\t</PopoverContent>\n\t\t\t</Popover>\n\t\t);\n\t}\n);\n\nLinkPopover.displayName = 'LinkPopover';\n"],"mappings":";;;;;;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ft,
|
|
5
6
|
ExternalLink,
|
|
@@ -7,12 +8,13 @@ import {
|
|
|
7
8
|
Trash2
|
|
8
9
|
} from "lucide-react";
|
|
9
10
|
import { forwardRef, useCallback, useEffect, useState } from "react";
|
|
10
|
-
import { useLinkPopover } from "./use-link-popover";
|
|
11
|
-
import { Button } from "../ui/button";
|
|
12
|
-
import { Input } from "../ui/input";
|
|
13
|
-
import { Popover, PopoverContent, PopoverTrigger } from "../ui/popover";
|
|
14
|
-
import { Separator } from "../ui/separator";
|
|
15
|
-
|
|
11
|
+
import { useLinkPopover } from "./use-link-popover.mjs";
|
|
12
|
+
import { Button } from "../ui/button.mjs";
|
|
13
|
+
import { Input } from "../ui/input.mjs";
|
|
14
|
+
import { Popover, PopoverContent, PopoverTrigger } from "../ui/popover.mjs";
|
|
15
|
+
import { Separator } from "../ui/separator.mjs";
|
|
16
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
17
|
+
var LinkPopover = forwardRef(
|
|
16
18
|
({ editor, ...buttonProps }, ref) => {
|
|
17
19
|
const [isOpen, setIsOpen] = useState(false);
|
|
18
20
|
const {
|
|
@@ -73,7 +75,7 @@ const LinkPopover = forwardRef(
|
|
|
73
75
|
PopoverContent,
|
|
74
76
|
{
|
|
75
77
|
align: "start",
|
|
76
|
-
className: "nt:flex nt:w-auto nt:items-center nt:gap-1 nt:p-1",
|
|
78
|
+
className: "nt:flex nt:w-auto nt:flex-row nt:items-center nt:gap-1 nt:p-1",
|
|
77
79
|
children: [
|
|
78
80
|
/* @__PURE__ */ jsx(
|
|
79
81
|
Input,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/components/link-popover/link-popover.tsx"],"sourcesContent":["'use client';\n\nimport {\n\tCornerDownLeft,\n\tExternalLink,\n\tLink as LinkIcon,\n\tTrash2\n} from 'lucide-react';\nimport { forwardRef, useCallback, useEffect, useState } from 'react';\n\nimport { useLinkPopover } from './use-link-popover';\nimport { Button } from '../ui/button';\nimport { Input } from '../ui/input';\nimport { Popover, PopoverContent, PopoverTrigger } from '../ui/popover';\nimport { Separator } from '../ui/separator';\n\nimport type { Editor } from '@tiptap/core';\n\nexport interface LinkPopoverProps extends Omit<\n\tReact.ButtonHTMLAttributes<HTMLButtonElement>,\n\t'type'\n> {\n\teditor: Editor | null;\n}\n\nexport const LinkPopover = forwardRef<HTMLButtonElement, LinkPopoverProps>(\n\t({ editor, ...buttonProps }, ref) => {\n\t\tconst [isOpen, setIsOpen] = useState(false);\n\n\t\tconst {\n\t\t\turl,\n\t\t\tsetUrl,\n\t\t\tisActive,\n\t\t\tcanSet,\n\t\t\tsetLink,\n\t\t\tremoveLink,\n\t\t\topenLink,\n\t\t\twasSelectionMove\n\t\t} = useLinkPopover({ editor });\n\n\t\t// Auto-open popover when cursor moves onto an existing link (selection-only transaction)\n\t\tuseEffect(() => {\n\t\t\tif (isActive && wasSelectionMove) {\n\t\t\t\tsetIsOpen(true);\n\t\t\t}\n\t\t}, [isActive, wasSelectionMove]);\n\n\t\tconst handleSetLink = useCallback(() => {\n\t\t\tsetLink();\n\t\t\tsetIsOpen(false);\n\t\t}, [setLink]);\n\n\t\tconst handleRemoveLink = useCallback(() => {\n\t\t\tremoveLink();\n\t\t\tsetIsOpen(false);\n\t\t}, [removeLink]);\n\n\t\tconst handleKeyDown = useCallback(\n\t\t\t(event: React.KeyboardEvent<HTMLInputElement>) => {\n\t\t\t\tif (event.key === 'Enter') {\n\t\t\t\t\tevent.preventDefault();\n\t\t\t\t\thandleSetLink();\n\t\t\t\t}\n\t\t\t},\n\t\t\t[handleSetLink]\n\t\t);\n\n\t\treturn (\n\t\t\t<Popover open={isOpen} onOpenChange={setIsOpen}>\n\t\t\t\t<PopoverTrigger asChild>\n\t\t\t\t\t<Button\n\t\t\t\t\t\tref={ref}\n\t\t\t\t\t\taria-label=\"Link\"\n\t\t\t\t\t\taria-pressed={isActive}\n\t\t\t\t\t\tdata-active-state={isActive ? 'on' : 'off'}\n\t\t\t\t\t\tdisabled={!canSet}\n\t\t\t\t\t\tsize=\"icon\"\n\t\t\t\t\t\ttabIndex={-1}\n\t\t\t\t\t\ttype=\"button\"\n\t\t\t\t\t\tvariant=\"ghost\"\n\t\t\t\t\t\t{...buttonProps}\n\t\t\t\t\t>\n\t\t\t\t\t\t<LinkIcon\n\t\t\t\t\t\t\tclassName={\n\t\t\t\t\t\t\t\tisActive ? 'nt:text-[var(--tt-brand-color-500)]' : undefined\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t/>\n\t\t\t\t\t</Button>\n\t\t\t\t</PopoverTrigger>\n\t\t\t\t<PopoverContent\n\t\t\t\t\talign=\"start\"\n\t\t\t\t\tclassName=\"nt:flex nt:w-auto nt:items-center nt:gap-1 nt:p-1\"\n\t\t\t\t>\n\t\t\t\t\t<Input\n\t\t\t\t\t\tautoFocus\n\t\t\t\t\t\tclassName=\"nt:h-7 nt:min-w-48 nt:border-none nt:shadow-none nt:focus-visible:ring-0\"\n\t\t\t\t\t\tplaceholder=\"Paste a link...\"\n\t\t\t\t\t\ttype=\"url\"\n\t\t\t\t\t\tvalue={url}\n\t\t\t\t\t\tonChange={(e) => setUrl(e.target.value)}\n\t\t\t\t\t\tonKeyDown={handleKeyDown}\n\t\t\t\t\t/>\n\t\t\t\t\t<Button\n\t\t\t\t\t\taria-label=\"Apply link\"\n\t\t\t\t\t\tdisabled={!url && !isActive}\n\t\t\t\t\t\tsize=\"icon-sm\"\n\t\t\t\t\t\ttabIndex={-1}\n\t\t\t\t\t\ttype=\"button\"\n\t\t\t\t\t\tvariant=\"ghost\"\n\t\t\t\t\t\tonClick={handleSetLink}\n\t\t\t\t\t>\n\t\t\t\t\t\t<CornerDownLeft />\n\t\t\t\t\t</Button>\n\t\t\t\t\t<Separator className=\"nt:h-5\" orientation=\"vertical\" />\n\t\t\t\t\t<Button\n\t\t\t\t\t\taria-label=\"Open link in new window\"\n\t\t\t\t\t\tsize=\"icon-sm\"\n\t\t\t\t\t\ttabIndex={-1}\n\t\t\t\t\t\ttype=\"button\"\n\t\t\t\t\t\tvariant=\"ghost\"\n\t\t\t\t\t\tonClick={openLink}\n\t\t\t\t\t>\n\t\t\t\t\t\t<ExternalLink />\n\t\t\t\t\t</Button>\n\t\t\t\t\t<Button\n\t\t\t\t\t\taria-label=\"Remove link\"\n\t\t\t\t\t\tsize=\"icon-sm\"\n\t\t\t\t\t\ttabIndex={-1}\n\t\t\t\t\t\ttype=\"button\"\n\t\t\t\t\t\tvariant=\"ghost\"\n\t\t\t\t\t\tonClick={handleRemoveLink}\n\t\t\t\t\t>\n\t\t\t\t\t\t<Trash2 />\n\t\t\t\t\t</Button>\n\t\t\t\t</PopoverContent>\n\t\t\t</Popover>\n\t\t);\n\t}\n);\n\nLinkPopover.displayName = 'LinkPopover';\n"],"mappings":";
|
|
1
|
+
{"version":3,"sources":["../../../src/components/link-popover/link-popover.tsx"],"sourcesContent":["'use client';\n\nimport {\n\tCornerDownLeft,\n\tExternalLink,\n\tLink as LinkIcon,\n\tTrash2\n} from 'lucide-react';\nimport { forwardRef, useCallback, useEffect, useState } from 'react';\n\nimport { useLinkPopover } from './use-link-popover.js';\nimport { Button } from '../ui/button.js';\nimport { Input } from '../ui/input.js';\nimport { Popover, PopoverContent, PopoverTrigger } from '../ui/popover.js';\nimport { Separator } from '../ui/separator.js';\n\nimport type { Editor } from '@tiptap/core';\n\nexport interface LinkPopoverProps extends Omit<\n\tReact.ButtonHTMLAttributes<HTMLButtonElement>,\n\t'type'\n> {\n\teditor: Editor | null;\n}\n\nexport const LinkPopover = forwardRef<HTMLButtonElement, LinkPopoverProps>(\n\t({ editor, ...buttonProps }, ref) => {\n\t\tconst [isOpen, setIsOpen] = useState(false);\n\n\t\tconst {\n\t\t\turl,\n\t\t\tsetUrl,\n\t\t\tisActive,\n\t\t\tcanSet,\n\t\t\tsetLink,\n\t\t\tremoveLink,\n\t\t\topenLink,\n\t\t\twasSelectionMove\n\t\t} = useLinkPopover({ editor });\n\n\t\t// Auto-open popover when cursor moves onto an existing link (selection-only transaction)\n\t\tuseEffect(() => {\n\t\t\tif (isActive && wasSelectionMove) {\n\t\t\t\tsetIsOpen(true);\n\t\t\t}\n\t\t}, [isActive, wasSelectionMove]);\n\n\t\tconst handleSetLink = useCallback(() => {\n\t\t\tsetLink();\n\t\t\tsetIsOpen(false);\n\t\t}, [setLink]);\n\n\t\tconst handleRemoveLink = useCallback(() => {\n\t\t\tremoveLink();\n\t\t\tsetIsOpen(false);\n\t\t}, [removeLink]);\n\n\t\tconst handleKeyDown = useCallback(\n\t\t\t(event: React.KeyboardEvent<HTMLInputElement>) => {\n\t\t\t\tif (event.key === 'Enter') {\n\t\t\t\t\tevent.preventDefault();\n\t\t\t\t\thandleSetLink();\n\t\t\t\t}\n\t\t\t},\n\t\t\t[handleSetLink]\n\t\t);\n\n\t\treturn (\n\t\t\t<Popover open={isOpen} onOpenChange={setIsOpen}>\n\t\t\t\t<PopoverTrigger asChild>\n\t\t\t\t\t<Button\n\t\t\t\t\t\tref={ref}\n\t\t\t\t\t\taria-label=\"Link\"\n\t\t\t\t\t\taria-pressed={isActive}\n\t\t\t\t\t\tdata-active-state={isActive ? 'on' : 'off'}\n\t\t\t\t\t\tdisabled={!canSet}\n\t\t\t\t\t\tsize=\"icon\"\n\t\t\t\t\t\ttabIndex={-1}\n\t\t\t\t\t\ttype=\"button\"\n\t\t\t\t\t\tvariant=\"ghost\"\n\t\t\t\t\t\t{...buttonProps}\n\t\t\t\t\t>\n\t\t\t\t\t\t<LinkIcon\n\t\t\t\t\t\t\tclassName={\n\t\t\t\t\t\t\t\tisActive ? 'nt:text-[var(--tt-brand-color-500)]' : undefined\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t/>\n\t\t\t\t\t</Button>\n\t\t\t\t</PopoverTrigger>\n\t\t\t\t<PopoverContent\n\t\t\t\t\talign=\"start\"\n\t\t\t\t\tclassName=\"nt:flex nt:w-auto nt:flex-row nt:items-center nt:gap-1 nt:p-1\"\n\t\t\t\t>\n\t\t\t\t\t<Input\n\t\t\t\t\t\tautoFocus\n\t\t\t\t\t\tclassName=\"nt:h-7 nt:min-w-48 nt:border-none nt:shadow-none nt:focus-visible:ring-0\"\n\t\t\t\t\t\tplaceholder=\"Paste a link...\"\n\t\t\t\t\t\ttype=\"url\"\n\t\t\t\t\t\tvalue={url}\n\t\t\t\t\t\tonChange={(e) => setUrl(e.target.value)}\n\t\t\t\t\t\tonKeyDown={handleKeyDown}\n\t\t\t\t\t/>\n\t\t\t\t\t<Button\n\t\t\t\t\t\taria-label=\"Apply link\"\n\t\t\t\t\t\tdisabled={!url && !isActive}\n\t\t\t\t\t\tsize=\"icon-sm\"\n\t\t\t\t\t\ttabIndex={-1}\n\t\t\t\t\t\ttype=\"button\"\n\t\t\t\t\t\tvariant=\"ghost\"\n\t\t\t\t\t\tonClick={handleSetLink}\n\t\t\t\t\t>\n\t\t\t\t\t\t<CornerDownLeft />\n\t\t\t\t\t</Button>\n\t\t\t\t\t<Separator className=\"nt:h-5\" orientation=\"vertical\" />\n\t\t\t\t\t<Button\n\t\t\t\t\t\taria-label=\"Open link in new window\"\n\t\t\t\t\t\tsize=\"icon-sm\"\n\t\t\t\t\t\ttabIndex={-1}\n\t\t\t\t\t\ttype=\"button\"\n\t\t\t\t\t\tvariant=\"ghost\"\n\t\t\t\t\t\tonClick={openLink}\n\t\t\t\t\t>\n\t\t\t\t\t\t<ExternalLink />\n\t\t\t\t\t</Button>\n\t\t\t\t\t<Button\n\t\t\t\t\t\taria-label=\"Remove link\"\n\t\t\t\t\t\tsize=\"icon-sm\"\n\t\t\t\t\t\ttabIndex={-1}\n\t\t\t\t\t\ttype=\"button\"\n\t\t\t\t\t\tvariant=\"ghost\"\n\t\t\t\t\t\tonClick={handleRemoveLink}\n\t\t\t\t\t>\n\t\t\t\t\t\t<Trash2 />\n\t\t\t\t\t</Button>\n\t\t\t\t</PopoverContent>\n\t\t\t</Popover>\n\t\t);\n\t}\n);\n\nLinkPopover.displayName = 'LinkPopover';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|
};
|
|
18
18
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// src/components/link-popover/use-link-popover.ts
|
|
19
21
|
var use_link_popover_exports = {};
|
|
20
22
|
__export(use_link_popover_exports, {
|
|
21
23
|
useLinkPopover: () => useLinkPopover
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/components/link-popover/use-link-popover.ts"],"sourcesContent":["import { useCallback, useEffect, useState } from 'react';\n\nimport type { Editor } from '@tiptap/core';\nimport type { Transaction } from '@tiptap/pm/state';\n\nexport interface UseLinkPopoverConfig {\n\teditor: Editor | null;\n}\n\nexport function useLinkPopover({ editor }: UseLinkPopoverConfig) {\n\tconst [url, setUrl] = useState('');\n\tconst [isActive, setIsActive] = useState(false);\n\tconst [canSet, setCanSet] = useState(false);\n\tconst [wasSelectionMove, setWasSelectionMove] = useState(false);\n\n\tuseEffect(() => {\n\t\tif (!editor) return;\n\n\t\tconst handleUpdate = ({\n\t\t\ttransaction\n\t\t}: { transaction?: Transaction } = {}) => {\n\t\t\tconst active = editor.isActive('link');\n\n\t\t\tsetIsActive(active);\n\t\t\tsetCanSet(editor.isEditable);\n\n\t\t\tif (transaction) {\n\t\t\t\tsetWasSelectionMove(!transaction.docChanged);\n\t\t\t}\n\n\t\t\tif (active) {\n\t\t\t\tsetUrl(editor.getAttributes('link').href ?? '');\n\t\t\t}\n\t\t};\n\n\t\thandleUpdate();\n\n\t\teditor.on('selectionUpdate', handleUpdate);\n\t\teditor.on('transaction', handleUpdate);\n\n\t\treturn () => {\n\t\t\teditor.off('selectionUpdate', handleUpdate);\n\t\t\teditor.off('transaction', handleUpdate);\n\t\t};\n\t}, [editor]);\n\n\tconst setLink = useCallback(() => {\n\t\tif (!editor) return;\n\n\t\tif (!url) {\n\t\t\teditor.chain().focus().extendMarkRange('link').unsetLink().run();\n\n\t\t\treturn;\n\t\t}\n\n\t\teditor.chain().focus().extendMarkRange('link').setLink({ href: url }).run();\n\t}, [editor, url]);\n\n\tconst removeLink = useCallback(() => {\n\t\tif (!editor) return;\n\n\t\teditor.chain().focus().extendMarkRange('link').unsetLink().run();\n\t\tsetUrl('');\n\t}, [editor]);\n\n\tconst openLink = useCallback(() => {\n\t\tif (!url) return;\n\n\t\tconst sanitized = /^https?:\\/\\//i.test(url) ? url : `https://${url}`;\n\n\t\twindow.open(sanitized, '_blank', 'noopener,noreferrer');\n\t}, [url]);\n\n\treturn {\n\t\turl,\n\t\tsetUrl,\n\t\tisActive,\n\t\tcanSet,\n\t\tsetLink,\n\t\tremoveLink,\n\t\topenLink,\n\t\twasSelectionMove\n\t};\n}\n"],"mappings":"
|
|
1
|
+
{"version":3,"sources":["../../../src/components/link-popover/use-link-popover.ts"],"sourcesContent":["import { useCallback, useEffect, useState } from 'react';\n\nimport type { Editor } from '@tiptap/core';\nimport type { Transaction } from '@tiptap/pm/state';\n\nexport interface UseLinkPopoverConfig {\n\teditor: Editor | null;\n}\n\nexport function useLinkPopover({ editor }: UseLinkPopoverConfig) {\n\tconst [url, setUrl] = useState('');\n\tconst [isActive, setIsActive] = useState(false);\n\tconst [canSet, setCanSet] = useState(false);\n\tconst [wasSelectionMove, setWasSelectionMove] = useState(false);\n\n\tuseEffect(() => {\n\t\tif (!editor) return;\n\n\t\tconst handleUpdate = ({\n\t\t\ttransaction\n\t\t}: { transaction?: Transaction } = {}) => {\n\t\t\tconst active = editor.isActive('link');\n\n\t\t\tsetIsActive(active);\n\t\t\tsetCanSet(editor.isEditable);\n\n\t\t\tif (transaction) {\n\t\t\t\tsetWasSelectionMove(!transaction.docChanged);\n\t\t\t}\n\n\t\t\tif (active) {\n\t\t\t\tsetUrl(editor.getAttributes('link').href ?? '');\n\t\t\t}\n\t\t};\n\n\t\thandleUpdate();\n\n\t\teditor.on('selectionUpdate', handleUpdate);\n\t\teditor.on('transaction', handleUpdate);\n\n\t\treturn () => {\n\t\t\teditor.off('selectionUpdate', handleUpdate);\n\t\t\teditor.off('transaction', handleUpdate);\n\t\t};\n\t}, [editor]);\n\n\tconst setLink = useCallback(() => {\n\t\tif (!editor) return;\n\n\t\tif (!url) {\n\t\t\teditor.chain().focus().extendMarkRange('link').unsetLink().run();\n\n\t\t\treturn;\n\t\t}\n\n\t\teditor.chain().focus().extendMarkRange('link').setLink({ href: url }).run();\n\t}, [editor, url]);\n\n\tconst removeLink = useCallback(() => {\n\t\tif (!editor) return;\n\n\t\teditor.chain().focus().extendMarkRange('link').unsetLink().run();\n\t\tsetUrl('');\n\t}, [editor]);\n\n\tconst openLink = useCallback(() => {\n\t\tif (!url) return;\n\n\t\tconst sanitized = /^https?:\\/\\//i.test(url) ? url : `https://${url}`;\n\n\t\twindow.open(sanitized, '_blank', 'noopener,noreferrer');\n\t}, [url]);\n\n\treturn {\n\t\turl,\n\t\tsetUrl,\n\t\tisActive,\n\t\tcanSet,\n\t\tsetLink,\n\t\tremoveLink,\n\t\topenLink,\n\t\twasSelectionMove\n\t};\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,mBAAiD;AAS1C,SAAS,eAAe,EAAE,OAAO,GAAyB;AAChE,QAAM,CAAC,KAAK,MAAM,QAAI,uBAAS,EAAE;AACjC,QAAM,CAAC,UAAU,WAAW,QAAI,uBAAS,KAAK;AAC9C,QAAM,CAAC,QAAQ,SAAS,QAAI,uBAAS,KAAK;AAC1C,QAAM,CAAC,kBAAkB,mBAAmB,QAAI,uBAAS,KAAK;AAE9D,8BAAU,MAAM;AACf,QAAI,CAAC,OAAQ;AAEb,UAAM,eAAe,CAAC;AAAA,MACrB;AAAA,IACD,IAAmC,CAAC,MAAM;AACzC,YAAM,SAAS,OAAO,SAAS,MAAM;AAErC,kBAAY,MAAM;AAClB,gBAAU,OAAO,UAAU;AAE3B,UAAI,aAAa;AAChB,4BAAoB,CAAC,YAAY,UAAU;AAAA,MAC5C;AAEA,UAAI,QAAQ;AACX,eAAO,OAAO,cAAc,MAAM,EAAE,QAAQ,EAAE;AAAA,MAC/C;AAAA,IACD;AAEA,iBAAa;AAEb,WAAO,GAAG,mBAAmB,YAAY;AACzC,WAAO,GAAG,eAAe,YAAY;AAErC,WAAO,MAAM;AACZ,aAAO,IAAI,mBAAmB,YAAY;AAC1C,aAAO,IAAI,eAAe,YAAY;AAAA,IACvC;AAAA,EACD,GAAG,CAAC,MAAM,CAAC;AAEX,QAAM,cAAU,0BAAY,MAAM;AACjC,QAAI,CAAC,OAAQ;AAEb,QAAI,CAAC,KAAK;AACT,aAAO,MAAM,EAAE,MAAM,EAAE,gBAAgB,MAAM,EAAE,UAAU,EAAE,IAAI;AAE/D;AAAA,IACD;AAEA,WAAO,MAAM,EAAE,MAAM,EAAE,gBAAgB,MAAM,EAAE,QAAQ,EAAE,MAAM,IAAI,CAAC,EAAE,IAAI;AAAA,EAC3E,GAAG,CAAC,QAAQ,GAAG,CAAC;AAEhB,QAAM,iBAAa,0BAAY,MAAM;AACpC,QAAI,CAAC,OAAQ;AAEb,WAAO,MAAM,EAAE,MAAM,EAAE,gBAAgB,MAAM,EAAE,UAAU,EAAE,IAAI;AAC/D,WAAO,EAAE;AAAA,EACV,GAAG,CAAC,MAAM,CAAC;AAEX,QAAM,eAAW,0BAAY,MAAM;AAClC,QAAI,CAAC,IAAK;AAEV,UAAM,YAAY,gBAAgB,KAAK,GAAG,IAAI,MAAM,WAAW,GAAG;AAElE,WAAO,KAAK,WAAW,UAAU,qBAAqB;AAAA,EACvD,GAAG,CAAC,GAAG,CAAC;AAER,SAAO;AAAA,IACN;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EACD;AACD;","names":[]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/components/link-popover/use-link-popover.ts"],"sourcesContent":["import { useCallback, useEffect, useState } from 'react';\n\nimport type { Editor } from '@tiptap/core';\nimport type { Transaction } from '@tiptap/pm/state';\n\nexport interface UseLinkPopoverConfig {\n\teditor: Editor | null;\n}\n\nexport function useLinkPopover({ editor }: UseLinkPopoverConfig) {\n\tconst [url, setUrl] = useState('');\n\tconst [isActive, setIsActive] = useState(false);\n\tconst [canSet, setCanSet] = useState(false);\n\tconst [wasSelectionMove, setWasSelectionMove] = useState(false);\n\n\tuseEffect(() => {\n\t\tif (!editor) return;\n\n\t\tconst handleUpdate = ({\n\t\t\ttransaction\n\t\t}: { transaction?: Transaction } = {}) => {\n\t\t\tconst active = editor.isActive('link');\n\n\t\t\tsetIsActive(active);\n\t\t\tsetCanSet(editor.isEditable);\n\n\t\t\tif (transaction) {\n\t\t\t\tsetWasSelectionMove(!transaction.docChanged);\n\t\t\t}\n\n\t\t\tif (active) {\n\t\t\t\tsetUrl(editor.getAttributes('link').href ?? '');\n\t\t\t}\n\t\t};\n\n\t\thandleUpdate();\n\n\t\teditor.on('selectionUpdate', handleUpdate);\n\t\teditor.on('transaction', handleUpdate);\n\n\t\treturn () => {\n\t\t\teditor.off('selectionUpdate', handleUpdate);\n\t\t\teditor.off('transaction', handleUpdate);\n\t\t};\n\t}, [editor]);\n\n\tconst setLink = useCallback(() => {\n\t\tif (!editor) return;\n\n\t\tif (!url) {\n\t\t\teditor.chain().focus().extendMarkRange('link').unsetLink().run();\n\n\t\t\treturn;\n\t\t}\n\n\t\teditor.chain().focus().extendMarkRange('link').setLink({ href: url }).run();\n\t}, [editor, url]);\n\n\tconst removeLink = useCallback(() => {\n\t\tif (!editor) return;\n\n\t\teditor.chain().focus().extendMarkRange('link').unsetLink().run();\n\t\tsetUrl('');\n\t}, [editor]);\n\n\tconst openLink = useCallback(() => {\n\t\tif (!url) return;\n\n\t\tconst sanitized = /^https?:\\/\\//i.test(url) ? url : `https://${url}`;\n\n\t\twindow.open(sanitized, '_blank', 'noopener,noreferrer');\n\t}, [url]);\n\n\treturn {\n\t\turl,\n\t\tsetUrl,\n\t\tisActive,\n\t\tcanSet,\n\t\tset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AAM;AACpC,QAAI,CAAC,OAAQ;AAEb,WAAO,MAAM,EAAE,MAAM,EAAE,gBAAgB,MAAM,EAAE,UAAU,EAAE,IAAI;AAC/D,WAAO,EAAE;AAAA,EACV,GAAG,CAAC,MAAM,CAAC;AAEX,QAAM,WAAW,YAAY,MAAM;AAClC,QAAI,CAAC,IAAK;AAEV,UAAM,YAAY,gBAAgB,KAAK,GAAG,IAAI,MAAM,WAAW,GAAG;AAElE,WAAO,KAAK,WAAW,UAAU,qBAAqB;AAAA,EACvD,GAAG,CAAC,GAAG,CAAC;AAER,SAAO;AAAA,IACN;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EACD;AACD;","names":[]}
|
|
1
|
+
{"version":3,"sources":["../../../src/components/link-popover/use-link-popover.ts"],"sourcesContent":["import { useCallback, useEffect, useState } from 'react';\n\nimport type { Editor } from '@tiptap/core';\nimport type { Transaction } from '@tiptap/pm/state';\n\nexport interface UseLinkPopoverConfig {\n\teditor: Editor | null;\n}\n\nexport function useLinkPopover({ editor }: UseLinkPopoverConfig) {\n\tconst [url, setUrl] = useState('');\n\tconst [isActive, setIsActive] = useState(false);\n\tconst [canSet, setCanSet] = useState(false);\n\tconst [wasSelectionMove, setWasSelectionMove] = useState(false);\n\n\tuseEffect(() => {\n\t\tif (!editor) return;\n\n\t\tconst handleUpdate = ({\n\t\t\ttransaction\n\t\t}: { transaction?: Transaction } = {}) => {\n\t\t\tconst active = editor.isActive('link');\n\n\t\t\tsetIsActive(active);\n\t\t\tsetCanSet(editor.isEditable);\n\n\t\t\tif (transaction) {\n\t\t\t\tsetWasSelectionMove(!transaction.docChanged);\n\t\t\t}\n\n\t\t\tif (active) {\n\t\t\t\tsetUrl(editor.getAttributes('link').href ?? '');\n\t\t\t}\n\t\t};\n\n\t\thandleUpdate();\n\n\t\teditor.on('selectionUpdate', handleUpdate);\n\t\teditor.on('transaction', handleUpdate);\n\n\t\treturn () => {\n\t\t\teditor.off('selectionUpdate', handleUpdate);\n\t\t\teditor.off('transaction', handleUpdate);\n\t\t};\n\t}, [editor]);\n\n\tconst setLink = useCallback(() => {\n\t\tif (!editor) return;\n\n\t\tif (!url) {\n\t\t\teditor.chain().focus().extendMarkRange('link').unsetLink().run();\n\n\t\t\treturn;\n\t\t}\n\n\t\teditor.chain().focus().extendMarkRange('link').setLink({ href: url }).run();\n\t}, [editor, url]);\n\n\tconst removeLink = useCallback(() => {\n\t\tif (!editor) return;\n\n\t\teditor.chain().focus().extendMarkRange('link').unsetLink().run();\n\t\tsetUrl('');\n\t}, [editor]);\n\n\tconst openLink = useCallback(() => {\n\t\tif (!url) return;\n\n\t\tconst sanitized = /^https?:\\/\\//i.test(url) ? url : `https://${url}`;\n\n\t\twindow.open(sanitized, '_blank', 'noopener,noreferrer');\n\t}, [url]);\n\n\treturn {\n\t\turl,\n\t\tsetUrl,\n\t\tisActive,\n\t\tcanSet,\n\t\tsetLink,\n\t\tremoveLink,\n\t\topenLink,\n\t\twasSelectionMove\n\t};\n}\n"],"mappings":";AAAA,SAAS,aAAa,WAAW,gBAAgB;AAS1C,SAAS,eAAe,EAAE,OAAO,GAAyB;AAChE,QAAM,CAAC,KAAK,MAAM,IAAI,SAAS,EAAE;AACjC,QAAM,CAAC,UAAU,WAAW,IAAI,SAAS,KAAK;AAC9C,QAAM,CAAC,QAAQ,SAAS,IAAI,SAAS,KAAK;AAC1C,QAAM,CAAC,kBAAkB,mBAAmB,IAAI,SAAS,KAAK;AAE9D,YAAU,MAAM;AACf,QAAI,CAAC,OAAQ;AAEb,UAAM,eAAe,CAAC;AAAA,MACrB;AAAA,IACD,IAAmC,CAAC,MAAM;AACzC,YAAM,SAAS,OAAO,SAAS,MAAM;AAErC,kBAAY,MAAM;AAClB,gBAAU,OAAO,UAAU;AAE3B,UAAI,aAAa;AAChB,4BAAoB,CAAC,YAAY,UAAU;AAAA,MAC5C;AAEA,UAAI,QAAQ;AACX,eAAO,OAAO,cAAc,MAAM,EAAE,QAAQ,EAAE;AAAA,MAC/C;AAAA,IACD;AAEA,iBAAa;AAEb,WAAO,GAAG,mBAAmB,YAAY;AACzC,WAAO,GAAG,eAAe,YAAY;AAErC,WAAO,MAAM;AACZ,aAAO,IAAI,mBAAmB,YAAY;AAC1C,aAAO,IAAI,eAAe,YAAY;AAAA,IACvC;AAAA,EACD,GAAG,CAAC,MAAM,CAAC;AAEX,QAAM,UAAU,YAAY,MAAM;AACjC,QAAI,CAAC,OAAQ;AAEb,QAAI,CAAC,KAAK;AACT,aAAO,MAAM,EAAE,MAAM,EAAE,gBAAgB,MAAM,EAAE,UAAU,EAAE,IAAI;AAE/D;AAAA,IACD;AAEA,WAAO,MAAM,EAAE,MAAM,EAAE,gBAAgB,MAAM,EAAE,QAAQ,EAAE,MAAM,IAAI,CAAC,EAAE,IAAI;AAAA,EAC3E,GAAG,CAAC,QAAQ,GAAG,CAAC;AAEhB,QAAM,aAAa,YAAY,MAAM;AACpC,QAAI,CAAC,OAAQ;AAEb,WAAO,MAAM,EAAE,MAAM,EAAE,gBAAgB,MAAM,EAAE,UAAU,EAAE,IAAI;AAC/D,WAAO,EAAE;AAAA,EACV,GAAG,CAAC,MAAM,CAAC;AAEX,QAAM,WAAW,YAAY,MAAM;AAClC,QAAI,CAAC,IAAK;AAEV,UAAM,YAAY,gBAAgB,KAAK,GAAG,IAAI,MAAM,WAAW,GAAG;AAElE,WAAO,KAAK,WAAW,UAAU,qBAAqB;AAAA,EACvD,GAAG,CAAC,GAAG,CAAC;AAER,SAAO;AAAA,IACN;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EACD;AACD;","names":[]}
|
|
@@ -17,19 +17,21 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
17
17
|
return to;
|
|
18
18
|
};
|
|
19
19
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
20
|
+
|
|
21
|
+
// src/components/list-dropdown-menu/list-dropdown-menu.tsx
|
|
20
22
|
var list_dropdown_menu_exports = {};
|
|
21
23
|
__export(list_dropdown_menu_exports, {
|
|
22
24
|
ListDropdownMenu: () => ListDropdownMenu
|
|
23
25
|
});
|
|
24
26
|
module.exports = __toCommonJS(list_dropdown_menu_exports);
|
|
25
|
-
var import_jsx_runtime = require("react/jsx-runtime");
|
|
26
27
|
var import_lucide_react = require("lucide-react");
|
|
27
28
|
var import_react = require("react");
|
|
28
|
-
var import_list_menu_item = require("./list-menu-item");
|
|
29
|
-
var import_use_list = require("./use-list");
|
|
30
|
-
var import_button = require("../ui/button");
|
|
31
|
-
var import_dropdown_menu = require("../ui/dropdown-menu");
|
|
32
|
-
|
|
29
|
+
var import_list_menu_item = require("./list-menu-item.cjs");
|
|
30
|
+
var import_use_list = require("./use-list.cjs");
|
|
31
|
+
var import_button = require("../ui/button.cjs");
|
|
32
|
+
var import_dropdown_menu = require("../ui/dropdown-menu.cjs");
|
|
33
|
+
var import_jsx_runtime = require("react/jsx-runtime");
|
|
34
|
+
var ListDropdownMenu = (0, import_react.forwardRef)(
|
|
33
35
|
({
|
|
34
36
|
editor,
|
|
35
37
|
types = ["bulletList", "orderedList", "taskList"],
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/components/list-dropdown-menu/list-dropdown-menu.tsx"],"sourcesContent":["'use client';\n\nimport { ChevronDown } from 'lucide-react';\nimport { forwardRef } from 'react';\n\nimport { ListMenuItem } from './list-menu-item';\nimport {\n\tgetListTriggerIcon,\n\tuseActiveListType,\n\ttype ListType\n} from './use-list';\nimport { Button } from '../ui/button';\nimport {\n\tDropdownMenu,\n\tDropdownMenuTrigger,\n\tDropdownMenuContent,\n\tDropdownMenuGroup\n} from '../ui/dropdown-menu';\n\nimport type { Editor } from '@tiptap/core';\nimport type { ComponentProps } from 'react';\n\nexport interface ListDropdownMenuProps extends Omit<\n\tComponentProps<typeof Button>,\n\t'type'\n> {\n\teditor: Editor | null;\n\ttypes?: ListType[];\n}\n\nexport const ListDropdownMenu = forwardRef<\n\tHTMLButtonElement,\n\tListDropdownMenuProps\n>(\n\t(\n\t\t{\n\t\t\teditor,\n\t\t\ttypes = ['bulletList', 'orderedList', 'taskList'],\n\t\t\t...buttonProps\n\t\t},\n\t\tref\n\t) => {\n\t\tconst activeType = useActiveListType(editor, types);\n\t\tconst TriggerIcon = getListTriggerIcon(activeType);\n\n\t\treturn (\n\t\t\t<DropdownMenu>\n\t\t\t\t<DropdownMenuTrigger asChild>\n\t\t\t\t\t<Button\n\t\t\t\t\t\tref={ref}\n\t\t\t\t\t\taria-label=\"List\"\n\t\t\t\t\t\tclassName=\"nt:gap-1 nt:px-2\"\n\t\t\t\t\t\tdata-active-state={activeType !== null ? 'on' : 'off'}\n\t\t\t\t\t\tsize=\"default\"\n\t\t\t\t\t\ttabIndex={-1}\n\t\t\t\t\t\ttype=\"button\"\n\t\t\t\t\t\tvariant=\"ghost\"\n\t\t\t\t\t\t{...buttonProps}\n\t\t\t\t\t>\n\t\t\t\t\t\t<TriggerIcon\n\t\t\t\t\t\t\tclassName={\n\t\t\t\t\t\t\t\tactiveType !== null\n\t\t\t\t\t\t\t\t\t? 'nt:text-[var(--tt-brand-color-500)]'\n\t\t\t\t\t\t\t\t\t: undefined\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t/>\n\t\t\t\t\t\t<ChevronDown className=\"nt:size-3\" />\n\t\t\t\t\t</Button>\n\t\t\t\t</DropdownMenuTrigger>\n\t\t\t\t<DropdownMenuContent align=\"start\">\n\t\t\t\t\t<DropdownMenuGroup>\n\t\t\t\t\t\t{types.map((type) => (\n\t\t\t\t\t\t\t<ListMenuItem key={type} editor={editor} listType={type} />\n\t\t\t\t\t\t))}\n\t\t\t\t\t</DropdownMenuGroup>\n\t\t\t\t</DropdownMenuContent>\n\t\t\t</DropdownMenu>\n\t\t);\n\t}\n);\n\nListDropdownMenu.displayName = 'ListDropdownMenu';\n"],"mappings":"
|
|
1
|
+
{"version":3,"sources":["../../../src/components/list-dropdown-menu/list-dropdown-menu.tsx"],"sourcesContent":["'use client';\n\nimport { ChevronDown } from 'lucide-react';\nimport { forwardRef } from 'react';\n\nimport { ListMenuItem } from './list-menu-item.js';\nimport {\n\tgetListTriggerIcon,\n\tuseActiveListType,\n\ttype ListType\n} from './use-list.js';\nimport { Button } from '../ui/button.js';\nimport {\n\tDropdownMenu,\n\tDropdownMenuTrigger,\n\tDropdownMenuContent,\n\tDropdownMenuGroup\n} from '../ui/dropdown-menu.js';\n\nimport type { Editor } from '@tiptap/core';\nimport type { ComponentProps } from 'react';\n\nexport interface ListDropdownMenuProps extends Omit<\n\tComponentProps<typeof Button>,\n\t'type'\n> {\n\teditor: Editor | null;\n\ttypes?: ListType[];\n}\n\nexport const ListDropdownMenu = forwardRef<\n\tHTMLButtonElement,\n\tListDropdownMenuProps\n>(\n\t(\n\t\t{\n\t\t\teditor,\n\t\t\ttypes = ['bulletList', 'orderedList', 'taskList'],\n\t\t\t...buttonProps\n\t\t},\n\t\tref\n\t) => {\n\t\tconst activeType = useActiveListType(editor, types);\n\t\tconst TriggerIcon = getListTriggerIcon(activeType);\n\n\t\treturn (\n\t\t\t<DropdownMenu>\n\t\t\t\t<DropdownMenuTrigger asChild>\n\t\t\t\t\t<Button\n\t\t\t\t\t\tref={ref}\n\t\t\t\t\t\taria-label=\"List\"\n\t\t\t\t\t\tclassName=\"nt:gap-1 nt:px-2\"\n\t\t\t\t\t\tdata-active-state={activeType !== null ? 'on' : 'off'}\n\t\t\t\t\t\tsize=\"default\"\n\t\t\t\t\t\ttabIndex={-1}\n\t\t\t\t\t\ttype=\"button\"\n\t\t\t\t\t\tvariant=\"ghost\"\n\t\t\t\t\t\t{...buttonProps}\n\t\t\t\t\t>\n\t\t\t\t\t\t<TriggerIcon\n\t\t\t\t\t\t\tclassName={\n\t\t\t\t\t\t\t\tactiveType !== null\n\t\t\t\t\t\t\t\t\t? 'nt:text-[var(--tt-brand-color-500)]'\n\t\t\t\t\t\t\t\t\t: undefined\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t/>\n\t\t\t\t\t\t<ChevronDown className=\"nt:size-3\" />\n\t\t\t\t\t</Button>\n\t\t\t\t</DropdownMenuTrigger>\n\t\t\t\t<DropdownMenuContent align=\"start\">\n\t\t\t\t\t<DropdownMenuGroup>\n\t\t\t\t\t\t{types.map((type) => (\n\t\t\t\t\t\t\t<ListMenuItem key={type} editor={editor} listType={type} />\n\t\t\t\t\t\t))}\n\t\t\t\t\t</DropdownMenuGroup>\n\t\t\t\t</DropdownMenuContent>\n\t\t\t</DropdownMenu>\n\t\t);\n\t}\n);\n\nListDropdownMenu.displayName = 'ListDropdownMenu';\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAEA,0BAA4B;AAC5B,mBAA2B;AAE3B,4BAA6B;AAC7B,sBAIO;AACP,oBAAuB;AACvB,2BAKO;AA+BF;AAlBE,IAAM,uBAAmB;AAAA,EAI/B,CACC;AAAA,IACC;AAAA,IACA,QAAQ,CAAC,cAAc,eAAe,UAAU;AAAA,IAChD,GAAG;AAAA,EACJ,GACA,QACI;AACJ,UAAM,iBAAa,mCAAkB,QAAQ,KAAK;AAClD,UAAM,kBAAc,oCAAmB,UAAU;AAEjD,WACC,6CAAC,qCACA;AAAA,kDAAC,4CAAoB,SAAO,MAC3B;AAAA,QAAC;AAAA;AAAA,UACA;AAAA,UACA,cAAW;AAAA,UACX,WAAU;AAAA,UACV,qBAAmB,eAAe,OAAO,OAAO;AAAA,UAChD,MAAK;AAAA,UACL,UAAU;AAAA,UACV,MAAK;AAAA,UACL,SAAQ;AAAA,UACP,GAAG;AAAA,UAEJ;AAAA;AAAA,cAAC;AAAA;AAAA,gBACA,WACC,eAAe,OACZ,wCACA;AAAA;AAAA,YAEL;AAAA,YACA,4CAAC,mCAAY,WAAU,aAAY;AAAA;AAAA;AAAA,MACpC,GACD;AAAA,MACA,4CAAC,4CAAoB,OAAM,SAC1B,sDAAC,0CACC,gBAAM,IAAI,CAAC,SACX,4CAAC,sCAAwB,QAAgB,UAAU,QAAhC,IAAsC,CACzD,GACF,GACD;AAAA,OACD;AAAA,EAEF;AACD;AAEA,iBAAiB,cAAc;","names":[]}
|
|
@@ -1,20 +1,22 @@
|
|
|
1
1
|
"use client";
|
|
2
|
-
|
|
2
|
+
|
|
3
|
+
// src/components/list-dropdown-menu/list-dropdown-menu.tsx
|
|
3
4
|
import { ChevronDown } from "lucide-react";
|
|
4
5
|
import { forwardRef } from "react";
|
|
5
|
-
import { ListMenuItem } from "./list-menu-item";
|
|
6
|
+
import { ListMenuItem } from "./list-menu-item.mjs";
|
|
6
7
|
import {
|
|
7
8
|
getListTriggerIcon,
|
|
8
9
|
useActiveListType
|
|
9
|
-
} from "./use-list";
|
|
10
|
-
import { Button } from "../ui/button";
|
|
10
|
+
} from "./use-list.mjs";
|
|
11
|
+
import { Button } from "../ui/button.mjs";
|
|
11
12
|
import {
|
|
12
13
|
DropdownMenu,
|
|
13
14
|
DropdownMenuTrigger,
|
|
14
15
|
DropdownMenuContent,
|
|
15
16
|
DropdownMenuGroup
|
|
16
|
-
} from "../ui/dropdown-menu";
|
|
17
|
-
|
|
17
|
+
} from "../ui/dropdown-menu.mjs";
|
|
18
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
19
|
+
var ListDropdownMenu = forwardRef(
|
|
18
20
|
({
|
|
19
21
|
editor,
|
|
20
22
|
types = ["bulletList", "orderedList", "taskList"],
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/components/list-dropdown-menu/list-dropdown-menu.tsx"],"sourcesContent":["'use client';\n\nimport { ChevronDown } from 'lucide-react';\nimport { forwardRef } from 'react';\n\nimport { ListMenuItem } from './list-menu-item';\nimport {\n\tgetListTriggerIcon,\n\tuseActiveListType,\n\ttype ListType\n} from './use-list';\nimport { Button } from '../ui/button';\nimport {\n\tDropdownMenu,\n\tDropdownMenuTrigger,\n\tDropdownMenuContent,\n\tDropdownMenuGroup\n} from '../ui/dropdown-menu';\n\nimport type { Editor } from '@tiptap/core';\nimport type { ComponentProps } from 'react';\n\nexport interface ListDropdownMenuProps extends Omit<\n\tComponentProps<typeof Button>,\n\t'type'\n> {\n\teditor: Editor | null;\n\ttypes?: ListType[];\n}\n\nexport const ListDropdownMenu = forwardRef<\n\tHTMLButtonElement,\n\tListDropdownMenuProps\n>(\n\t(\n\t\t{\n\t\t\teditor,\n\t\t\ttypes = ['bulletList', 'orderedList', 'taskList'],\n\t\t\t...buttonProps\n\t\t},\n\t\tref\n\t) => {\n\t\tconst activeType = useActiveListType(editor, types);\n\t\tconst TriggerIcon = getListTriggerIcon(activeType);\n\n\t\treturn (\n\t\t\t<DropdownMenu>\n\t\t\t\t<DropdownMenuTrigger asChild>\n\t\t\t\t\t<Button\n\t\t\t\t\t\tref={ref}\n\t\t\t\t\t\taria-label=\"List\"\n\t\t\t\t\t\tclassName=\"nt:gap-1 nt:px-2\"\n\t\t\t\t\t\tdata-active-state={activeType !== null ? 'on' : 'off'}\n\t\t\t\t\t\tsize=\"default\"\n\t\t\t\t\t\ttabIndex={-1}\n\t\t\t\t\t\ttype=\"button\"\n\t\t\t\t\t\tvariant=\"ghost\"\n\t\t\t\t\t\t{...buttonProps}\n\t\t\t\t\t>\n\t\t\t\t\t\t<TriggerIcon\n\t\t\t\t\t\t\tclassName={\n\t\t\t\t\t\t\t\tactiveType !== null\n\t\t\t\t\t\t\t\t\t? 'nt:text-[var(--tt-brand-color-500)]'\n\t\t\t\t\t\t\t\t\t: undefined\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t/>\n\t\t\t\t\t\t<ChevronDown className=\"nt:size-3\" />\n\t\t\t\t\t</Button>\n\t\t\t\t</DropdownMenuTrigger>\n\t\t\t\t<DropdownMenuContent align=\"start\">\n\t\t\t\t\t<DropdownMenuGroup>\n\t\t\t\t\t\t{types.map((type) => (\n\t\t\t\t\t\t\t<ListMenuItem key={type} editor={editor} listType={type} />\n\t\t\t\t\t\t))}\n\t\t\t\t\t</DropdownMenuGroup>\n\t\t\t\t</DropdownMenuContent>\n\t\t\t</DropdownMenu>\n\t\t);\n\t}\n);\n\nListDropdownMenu.displayName = 'ListDropdownMenu';\n"],"mappings":"
|
|
1
|
+
{"version":3,"sources":["../../../src/components/list-dropdown-menu/list-dropdown-menu.tsx"],"sourcesContent":["'use client';\n\nimport { ChevronDown } from 'lucide-react';\nimport { forwardRef } from 'react';\n\nimport { ListMenuItem } from './list-menu-item.js';\nimport {\n\tgetListTriggerIcon,\n\tuseActiveListType,\n\ttype ListType\n} from './use-list.js';\nimport { Button } from '../ui/button.js';\nimport {\n\tDropdownMenu,\n\tDropdownMenuTrigger,\n\tDropdownMenuContent,\n\tDropdownMenuGroup\n} from '../ui/dropdown-menu.js';\n\nimport type { Editor } from '@tiptap/core';\nimport type { ComponentProps } from 'react';\n\nexport interface ListDropdownMenuProps extends Omit<\n\tComponentProps<typeof Button>,\n\t'type'\n> {\n\teditor: Editor | null;\n\ttypes?: ListType[];\n}\n\nexport const ListDropdownMenu = forwardRef<\n\tHTMLButtonElement,\n\tListDropdownMenuProps\n>(\n\t(\n\t\t{\n\t\t\teditor,\n\t\t\ttypes = ['bulletList', 'orderedList', 'taskList'],\n\t\t\t...buttonProps\n\t\t},\n\t\tref\n\t) => {\n\t\tconst activeType = useActiveListType(editor, types);\n\t\tconst TriggerIcon = getListTriggerIcon(activeType);\n\n\t\treturn (\n\t\t\t<DropdownMenu>\n\t\t\t\t<DropdownMenuTrigger asChild>\n\t\t\t\t\t<Button\n\t\t\t\t\t\tref={ref}\n\t\t\t\t\t\taria-label=\"List\"\n\t\t\t\t\t\tclassName=\"nt:gap-1 nt:px-2\"\n\t\t\t\t\t\tdata-active-state={activeType !== null ? 'on' : 'off'}\n\t\t\t\t\t\tsize=\"default\"\n\t\t\t\t\t\ttabIndex={-1}\n\t\t\t\t\t\ttype=\"button\"\n\t\t\t\t\t\tvariant=\"ghost\"\n\t\t\t\t\t\t{...buttonProps}\n\t\t\t\t\t>\n\t\t\t\t\t\t<TriggerIcon\n\t\t\t\t\t\t\tclassName={\n\t\t\t\t\t\t\t\tactiveType !== null\n\t\t\t\t\t\t\t\t\t? 'nt:text-[var(--tt-brand-color-500)]'\n\t\t\t\t\t\t\t\t\t: undefined\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t/>\n\t\t\t\t\t\t<ChevronDown className=\"nt:size-3\" />\n\t\t\t\t\t</Button>\n\t\t\t\t</DropdownMenuTrigger>\n\t\t\t\t<DropdownMenuContent align=\"start\">\n\t\t\t\t\t<DropdownMenuGroup>\n\t\t\t\t\t\t{types.map((type) => (\n\t\t\t\t\t\t\t<ListMenuItem key={type} editor={editor} listType={type} />\n\t\t\t\t\t\t))}\n\t\t\t\t\t</DropdownMenuGroup>\n\t\t\t\t</DropdownMenuContent>\n\t\t\t</DropdownMenu>\n\t\t);\n\t}\n);\n\nListDropdownMenu.displayName = 'ListDropdownMenu';\n"],"mappings":";;;AAEA,SAAS,mBAAmB;AAC5B,SAAS,kBAAkB;AAE3B,SAAS,oBAAoB;AAC7B;AAAA,EACC;AAAA,EACA;AAAA,OAEM;AACP,SAAS,cAAc;AACvB;AAAA,EACC;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACM;AA+BF,SAWC,KAXD;AAlBE,IAAM,mBAAmB;AAAA,EAI/B,CACC;AAAA,IACC;AAAA,IACA,QAAQ,CAAC,cAAc,eAAe,UAAU;AAAA,IAChD,GAAG;AAAA,EACJ,GACA,QACI;AACJ,UAAM,aAAa,kBAAkB,QAAQ,KAAK;AAClD,UAAM,cAAc,mBAAmB,UAAU;AAEjD,WACC,qBAAC,gBACA;AAAA,0BAAC,uBAAoB,SAAO,MAC3B;AAAA,QAAC;AAAA;AAAA,UACA;AAAA,UACA,cAAW;AAAA,UACX,WAAU;AAAA,UACV,qBAAmB,eAAe,OAAO,OAAO;AAAA,UAChD,MAAK;AAAA,UACL,UAAU;AAAA,UACV,MAAK;AAAA,UACL,SAAQ;AAAA,UACP,GAAG;AAAA,UAEJ;AAAA;AAAA,cAAC;AAAA;AAAA,gBACA,WACC,eAAe,OACZ,wCACA;AAAA;AAAA,YAEL;AAAA,YACA,oBAAC,eAAY,WAAU,aAAY;AAAA;AAAA;AAAA,MACpC,GACD;AAAA,MACA,oBAAC,uBAAoB,OAAM,SAC1B,8BAAC,qBACC,gBAAM,IAAI,CAAC,SACX,oBAAC,gBAAwB,QAAgB,UAAU,QAAhC,IAAsC,CACzD,GACF,GACD;AAAA,OACD;AAAA,EAEF;AACD;AAEA,iBAAiB,cAAc;","names":[]}
|
|
@@ -16,16 +16,18 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
16
16
|
return to;
|
|
17
17
|
};
|
|
18
18
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// src/components/list-dropdown-menu/list-menu-item.tsx
|
|
19
21
|
var list_menu_item_exports = {};
|
|
20
22
|
__export(list_menu_item_exports, {
|
|
21
23
|
ListMenuItem: () => ListMenuItem
|
|
22
24
|
});
|
|
23
25
|
module.exports = __toCommonJS(list_menu_item_exports);
|
|
24
|
-
var import_jsx_runtime = require("react/jsx-runtime");
|
|
25
26
|
var import_react = require("react");
|
|
26
|
-
var import_use_list = require("./use-list");
|
|
27
|
-
var import_dropdown_menu = require("../ui/dropdown-menu");
|
|
28
|
-
|
|
27
|
+
var import_use_list = require("./use-list.cjs");
|
|
28
|
+
var import_dropdown_menu = require("../ui/dropdown-menu.cjs");
|
|
29
|
+
var import_jsx_runtime = require("react/jsx-runtime");
|
|
30
|
+
var ListMenuItem = (0, import_react.forwardRef)(
|
|
29
31
|
({ editor, listType }, ref) => {
|
|
30
32
|
const { isActive, canToggle, handleToggle, label, Icon } = (0, import_use_list.useList)({
|
|
31
33
|
editor,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/components/list-dropdown-menu/list-menu-item.tsx"],"sourcesContent":["import { forwardRef } from 'react';\n\nimport { useList, type ListType } from './use-list';\nimport { DropdownMenuItem } from '../ui/dropdown-menu';\n\nimport type { Editor } from '@tiptap/core';\n\nexport interface ListMenuItemProps {\n\teditor: Editor | null;\n\tlistType: ListType;\n}\n\nexport const ListMenuItem = forwardRef<HTMLDivElement, ListMenuItemProps>(\n\t({ editor, listType }, ref) => {\n\t\tconst { isActive, canToggle, handleToggle, label, Icon } = useList({\n\t\t\teditor,\n\t\t\ttype: listType\n\t\t});\n\n\t\treturn (\n\t\t\t<DropdownMenuItem\n\t\t\t\tref={ref}\n\t\t\t\taria-label={label}\n\t\t\t\tclassName=\"nt:data-[active-state=on]:bg-accent nt:data-[active-state=on]:text-[var(--tt-brand-color-500)]\"\n\t\t\t\tdata-active-state={isActive ? 'on' : 'off'}\n\t\t\t\tdisabled={!canToggle}\n\t\t\t\tonSelect={handleToggle}\n\t\t\t>\n\t\t\t\t<Icon />\n\t\t\t\t<span>{label}</span>\n\t\t\t</DropdownMenuItem>\n\t\t);\n\t}\n);\n\nListMenuItem.displayName = 'ListMenuItem';\n"],"mappings":"
|
|
1
|
+
{"version":3,"sources":["../../../src/components/list-dropdown-menu/list-menu-item.tsx"],"sourcesContent":["import { forwardRef } from 'react';\n\nimport { useList, type ListType } from './use-list.js';\nimport { DropdownMenuItem } from '../ui/dropdown-menu.js';\n\nimport type { Editor } from '@tiptap/core';\n\nexport interface ListMenuItemProps {\n\teditor: Editor | null;\n\tlistType: ListType;\n}\n\nexport const ListMenuItem = forwardRef<HTMLDivElement, ListMenuItemProps>(\n\t({ editor, listType }, ref) => {\n\t\tconst { isActive, canToggle, handleToggle, label, Icon } = useList({\n\t\t\teditor,\n\t\t\ttype: listType\n\t\t});\n\n\t\treturn (\n\t\t\t<DropdownMenuItem\n\t\t\t\tref={ref}\n\t\t\t\taria-label={label}\n\t\t\t\tclassName=\"nt:data-[active-state=on]:bg-accent nt:data-[active-state=on]:text-[var(--tt-brand-color-500)]\"\n\t\t\t\tdata-active-state={isActive ? 'on' : 'off'}\n\t\t\t\tdisabled={!canToggle}\n\t\t\t\tonSelect={handleToggle}\n\t\t\t>\n\t\t\t\t<Icon />\n\t\t\t\t<span>{label}</span>\n\t\t\t</DropdownMenuItem>\n\t\t);\n\t}\n);\n\nListMenuItem.displayName = 'ListMenuItem';\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,mBAA2B;AAE3B,sBAAuC;AACvC,2BAAiC;AAiB9B;AARI,IAAM,mBAAe;AAAA,EAC3B,CAAC,EAAE,QAAQ,SAAS,GAAG,QAAQ;AAC9B,UAAM,EAAE,UAAU,WAAW,cAAc,OAAO,KAAK,QAAI,yBAAQ;AAAA,MAClE;AAAA,MACA,MAAM;AAAA,IACP,CAAC;AAED,WACC;AAAA,MAAC;AAAA;AAAA,QACA;AAAA,QACA,cAAY;AAAA,QACZ,WAAU;AAAA,QACV,qBAAmB,WAAW,OAAO;AAAA,QACrC,UAAU,CAAC;AAAA,QACX,UAAU;AAAA,QAEV;AAAA,sDAAC,QAAK;AAAA,UACN,4CAAC,UAAM,iBAAM;AAAA;AAAA;AAAA,IACd;AAAA,EAEF;AACD;AAEA,aAAa,cAAc;","names":[]}
|
|
@@ -1,8 +1,9 @@
|
|
|
1
|
-
|
|
1
|
+
// src/components/list-dropdown-menu/list-menu-item.tsx
|
|
2
2
|
import { forwardRef } from "react";
|
|
3
|
-
import { useList } from "./use-list";
|
|
4
|
-
import { DropdownMenuItem } from "../ui/dropdown-menu";
|
|
5
|
-
|
|
3
|
+
import { useList } from "./use-list.mjs";
|
|
4
|
+
import { DropdownMenuItem } from "../ui/dropdown-menu.mjs";
|
|
5
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
6
|
+
var ListMenuItem = forwardRef(
|
|
6
7
|
({ editor, listType }, ref) => {
|
|
7
8
|
const { isActive, canToggle, handleToggle, label, Icon } = useList({
|
|
8
9
|
editor,
|