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 +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,SAAS,kBAAkB;AAE3B,SAAS,eAA8B;AACvC,SAAS,wBAAwB;AAiB9B,SAQC,KARD;AARI,IAAM,eAAe;AAAA,EAC3B,CAAC,EAAE,QAAQ,SAAS,GAAG,QAAQ;AAC9B,UAAM,EAAE,UAAU,WAAW,cAAc,OAAO,KAAK,IAAI,QAAQ;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,8BAAC,QAAK;AAAA,UACN,oBAAC,UAAM,iBAAM;AAAA;AAAA;AAAA,IACd;AAAA,EAEF;AACD;AAEA,aAAa,cAAc;","names":[]}
|
|
@@ -16,6 +16,8 @@ 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/use-list.ts
|
|
19
21
|
var use_list_exports = {};
|
|
20
22
|
__export(use_list_exports, {
|
|
21
23
|
getListTriggerIcon: () => getListTriggerIcon,
|
|
@@ -25,17 +27,17 @@ __export(use_list_exports, {
|
|
|
25
27
|
module.exports = __toCommonJS(use_list_exports);
|
|
26
28
|
var import_lucide_react = require("lucide-react");
|
|
27
29
|
var import_react = require("react");
|
|
28
|
-
|
|
30
|
+
var listIcons = {
|
|
29
31
|
bulletList: import_lucide_react.List,
|
|
30
32
|
orderedList: import_lucide_react.ListOrdered,
|
|
31
33
|
taskList: import_lucide_react.ListTodo
|
|
32
34
|
};
|
|
33
|
-
|
|
35
|
+
var listLabels = {
|
|
34
36
|
bulletList: "Bullet List",
|
|
35
37
|
orderedList: "Ordered List",
|
|
36
38
|
taskList: "Task List"
|
|
37
39
|
};
|
|
38
|
-
|
|
40
|
+
var listItemTypes = {
|
|
39
41
|
bulletList: "listItem",
|
|
40
42
|
orderedList: "listItem",
|
|
41
43
|
taskList: "taskItem"
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/components/list-dropdown-menu/use-list.ts"],"sourcesContent":["import { List, ListOrdered, ListTodo } from 'lucide-react';\nimport { useCallback, useEffect, useState } from 'react';\n\nimport type { Editor } from '@tiptap/core';\nimport type { LucideIcon } from 'lucide-react';\n\nexport type ListType = 'bulletList' | 'orderedList' | 'taskList';\n\ntype IconComponent = LucideIcon;\n\nconst listIcons: Record<ListType, IconComponent> = {\n\tbulletList: List,\n\torderedList: ListOrdered,\n\ttaskList: ListTodo\n};\n\nconst listLabels: Record<ListType, string> = {\n\tbulletList: 'Bullet List',\n\torderedList: 'Ordered List',\n\ttaskList: 'Task List'\n};\n\nconst listItemTypes: Record<ListType, string> = {\n\tbulletList: 'listItem',\n\torderedList: 'listItem',\n\ttaskList: 'taskItem'\n};\n\nfunction canToggleList(editor: Editor | null): boolean {\n\tif (!editor || !editor.isEditable) return false;\n\n\treturn (\n\t\teditor.can().toggleList('bulletList', 'listItem') ||\n\t\teditor.can().clearNodes()\n\t);\n}\n\nexport function useList({\n\teditor,\n\ttype\n}: {\n\teditor: Editor | null;\n\ttype: ListType;\n}) {\n\tconst [isActive, setIsActive] = useState(false);\n\tconst [canToggle, setCanToggle] = useState(false);\n\n\tuseEffect(() => {\n\t\tif (!editor) return;\n\n\t\tconst handleUpdate = () => {\n\t\t\tsetIsActive(editor.isActive(type));\n\t\t\tsetCanToggle(canToggleList(editor));\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, type]);\n\n\tconst handleToggle = useCallback(() => {\n\t\tif (!editor || !editor.isEditable) return false;\n\n\t\tconst itemType = listItemTypes[type];\n\n\t\tif (editor.isActive(type)) {\n\t\t\t// Currently this list type → convert back to paragraph\n\t\t\treturn editor.chain().focus().clearNodes().run();\n\t\t}\n\n\t\t// clearNodes first to convert any block type to paragraph,\n\t\t// then toggle list\n\t\treturn editor.chain().focus().clearNodes().toggleList(type, itemType).run();\n\t}, [editor, type]);\n\n\treturn {\n\t\tisActive,\n\t\tcanToggle,\n\t\thandleToggle,\n\t\tlabel: listLabels[type],\n\t\tIcon: listIcons[type]\n\t};\n}\n\nexport function useActiveListType(\n\teditor: Editor | null,\n\ttypes: ListType[]\n): ListType | null {\n\tconst [activeType, setActiveType] = useState<ListType | null>(null);\n\n\tuseEffect(() => {\n\t\tif (!editor) return;\n\n\t\tconst handleUpdate = () => {\n\t\t\tconst found = types.find((type) => editor.isActive(type));\n\n\t\t\tsetActiveType(found ?? null);\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, types]);\n\n\treturn activeType;\n}\n\nexport function getListTriggerIcon(activeType: ListType | null): IconComponent {\n\tif (activeType === null) return List;\n\n\treturn listIcons[activeType];\n}\n"],"mappings":"
|
|
1
|
+
{"version":3,"sources":["../../../src/components/list-dropdown-menu/use-list.ts"],"sourcesContent":["import { List, ListOrdered, ListTodo } from 'lucide-react';\nimport { useCallback, useEffect, useState } from 'react';\n\nimport type { Editor } from '@tiptap/core';\nimport type { LucideIcon } from 'lucide-react';\n\nexport type ListType = 'bulletList' | 'orderedList' | 'taskList';\n\ntype IconComponent = LucideIcon;\n\nconst listIcons: Record<ListType, IconComponent> = {\n\tbulletList: List,\n\torderedList: ListOrdered,\n\ttaskList: ListTodo\n};\n\nconst listLabels: Record<ListType, string> = {\n\tbulletList: 'Bullet List',\n\torderedList: 'Ordered List',\n\ttaskList: 'Task List'\n};\n\nconst listItemTypes: Record<ListType, string> = {\n\tbulletList: 'listItem',\n\torderedList: 'listItem',\n\ttaskList: 'taskItem'\n};\n\nfunction canToggleList(editor: Editor | null): boolean {\n\tif (!editor || !editor.isEditable) return false;\n\n\treturn (\n\t\teditor.can().toggleList('bulletList', 'listItem') ||\n\t\teditor.can().clearNodes()\n\t);\n}\n\nexport function useList({\n\teditor,\n\ttype\n}: {\n\teditor: Editor | null;\n\ttype: ListType;\n}) {\n\tconst [isActive, setIsActive] = useState(false);\n\tconst [canToggle, setCanToggle] = useState(false);\n\n\tuseEffect(() => {\n\t\tif (!editor) return;\n\n\t\tconst handleUpdate = () => {\n\t\t\tsetIsActive(editor.isActive(type));\n\t\t\tsetCanToggle(canToggleList(editor));\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, type]);\n\n\tconst handleToggle = useCallback(() => {\n\t\tif (!editor || !editor.isEditable) return false;\n\n\t\tconst itemType = listItemTypes[type];\n\n\t\tif (editor.isActive(type)) {\n\t\t\t// Currently this list type → convert back to paragraph\n\t\t\treturn editor.chain().focus().clearNodes().run();\n\t\t}\n\n\t\t// clearNodes first to convert any block type to paragraph,\n\t\t// then toggle list\n\t\treturn editor.chain().focus().clearNodes().toggleList(type, itemType).run();\n\t}, [editor, type]);\n\n\treturn {\n\t\tisActive,\n\t\tcanToggle,\n\t\thandleToggle,\n\t\tlabel: listLabels[type],\n\t\tIcon: listIcons[type]\n\t};\n}\n\nexport function useActiveListType(\n\teditor: Editor | null,\n\ttypes: ListType[]\n): ListType | null {\n\tconst [activeType, setActiveType] = useState<ListType | null>(null);\n\n\tuseEffect(() => {\n\t\tif (!editor) return;\n\n\t\tconst handleUpdate = () => {\n\t\t\tconst found = types.find((type) => editor.isActive(type));\n\n\t\t\tsetActiveType(found ?? null);\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, types]);\n\n\treturn activeType;\n}\n\nexport function getListTriggerIcon(activeType: ListType | null): IconComponent {\n\tif (activeType === null) return List;\n\n\treturn listIcons[activeType];\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,0BAA4C;AAC5C,mBAAiD;AASjD,IAAM,YAA6C;AAAA,EAClD,YAAY;AAAA,EACZ,aAAa;AAAA,EACb,UAAU;AACX;AAEA,IAAM,aAAuC;AAAA,EAC5C,YAAY;AAAA,EACZ,aAAa;AAAA,EACb,UAAU;AACX;AAEA,IAAM,gBAA0C;AAAA,EAC/C,YAAY;AAAA,EACZ,aAAa;AAAA,EACb,UAAU;AACX;AAEA,SAAS,cAAc,QAAgC;AACtD,MAAI,CAAC,UAAU,CAAC,OAAO,WAAY,QAAO;AAE1C,SACC,OAAO,IAAI,EAAE,WAAW,cAAc,UAAU,KAChD,OAAO,IAAI,EAAE,WAAW;AAE1B;AAEO,SAAS,QAAQ;AAAA,EACvB;AAAA,EACA;AACD,GAGG;AACF,QAAM,CAAC,UAAU,WAAW,QAAI,uBAAS,KAAK;AAC9C,QAAM,CAAC,WAAW,YAAY,QAAI,uBAAS,KAAK;AAEhD,8BAAU,MAAM;AACf,QAAI,CAAC,OAAQ;AAEb,UAAM,eAAe,MAAM;AAC1B,kBAAY,OAAO,SAAS,IAAI,CAAC;AACjC,mBAAa,cAAc,MAAM,CAAC;AAAA,IACnC;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,QAAQ,IAAI,CAAC;AAEjB,QAAM,mBAAe,0BAAY,MAAM;AACtC,QAAI,CAAC,UAAU,CAAC,OAAO,WAAY,QAAO;AAE1C,UAAM,WAAW,cAAc,IAAI;AAEnC,QAAI,OAAO,SAAS,IAAI,GAAG;AAE1B,aAAO,OAAO,MAAM,EAAE,MAAM,EAAE,WAAW,EAAE,IAAI;AAAA,IAChD;AAIA,WAAO,OAAO,MAAM,EAAE,MAAM,EAAE,WAAW,EAAE,WAAW,MAAM,QAAQ,EAAE,IAAI;AAAA,EAC3E,GAAG,CAAC,QAAQ,IAAI,CAAC;AAEjB,SAAO;AAAA,IACN;AAAA,IACA;AAAA,IACA;AAAA,IACA,OAAO,WAAW,IAAI;AAAA,IACtB,MAAM,UAAU,IAAI;AAAA,EACrB;AACD;AAEO,SAAS,kBACf,QACA,OACkB;AAClB,QAAM,CAAC,YAAY,aAAa,QAAI,uBAA0B,IAAI;AAElE,8BAAU,MAAM;AACf,QAAI,CAAC,OAAQ;AAEb,UAAM,eAAe,MAAM;AAC1B,YAAM,QAAQ,MAAM,KAAK,CAAC,SAAS,OAAO,SAAS,IAAI,CAAC;AAExD,oBAAc,SAAS,IAAI;AAAA,IAC5B;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,QAAQ,KAAK,CAAC;AAElB,SAAO;AACR;AAEO,SAAS,mBAAmB,YAA4C;AAC9E,MAAI,eAAe,KAAM,QAAO;AAEhC,SAAO,UAAU,UAAU;AAC5B;","names":[]}
|
|
@@ -1,16 +1,17 @@
|
|
|
1
|
+
// src/components/list-dropdown-menu/use-list.ts
|
|
1
2
|
import { List, ListOrdered, ListTodo } from "lucide-react";
|
|
2
3
|
import { useCallback, useEffect, useState } from "react";
|
|
3
|
-
|
|
4
|
+
var listIcons = {
|
|
4
5
|
bulletList: List,
|
|
5
6
|
orderedList: ListOrdered,
|
|
6
7
|
taskList: ListTodo
|
|
7
8
|
};
|
|
8
|
-
|
|
9
|
+
var listLabels = {
|
|
9
10
|
bulletList: "Bullet List",
|
|
10
11
|
orderedList: "Ordered List",
|
|
11
12
|
taskList: "Task List"
|
|
12
13
|
};
|
|
13
|
-
|
|
14
|
+
var listItemTypes = {
|
|
14
15
|
bulletList: "listItem",
|
|
15
16
|
orderedList: "listItem",
|
|
16
17
|
taskList: "taskItem"
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/components/list-dropdown-menu/use-list.ts"],"sourcesContent":["import { List, ListOrdered, ListTodo } from 'lucide-react';\nimport { useCallback, useEffect, useState } from 'react';\n\nimport type { Editor } from '@tiptap/core';\nimport type { LucideIcon } from 'lucide-react';\n\nexport type ListType = 'bulletList' | 'orderedList' | 'taskList';\n\ntype IconComponent = LucideIcon;\n\nconst listIcons: Record<ListType, IconComponent> = {\n\tbulletList: List,\n\torderedList: ListOrdered,\n\ttaskList: ListTodo\n};\n\nconst listLabels: Record<ListType, string> = {\n\tbulletList: 'Bullet List',\n\torderedList: 'Ordered List',\n\ttaskList: 'Task List'\n};\n\nconst listItemTypes: Record<ListType, string> = {\n\tbulletList: 'listItem',\n\torderedList: 'listItem',\n\ttaskList: 'taskItem'\n};\n\nfunction canToggleList(editor: Editor | null): boolean {\n\tif (!editor || !editor.isEditable) return false;\n\n\treturn (\n\t\teditor.can().toggleList('bulletList', 'listItem') ||\n\t\teditor.can().clearNodes()\n\t);\n}\n\nexport function useList({\n\teditor,\n\ttype\n}: {\n\teditor: Editor | null;\n\ttype: ListType;\n}) {\n\tconst [isActive, setIsActive] = useState(false);\n\tconst [canToggle, setCanToggle] = useState(false);\n\n\tuseEffect(() => {\n\t\tif (!editor) return;\n\n\t\tconst handleUpdate = () => {\n\t\t\tsetIsActive(editor.isActive(type));\n\t\t\tsetCanToggle(canToggleList(editor));\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, type]);\n\n\tconst handleToggle = useCallback(() => {\n\t\tif (!editor || !editor.isEditable) return false;\n\n\t\tconst itemType = listItemTypes[type];\n\n\t\tif (editor.isActive(type)) {\n\t\t\t// Currently this list type → convert back to paragraph\n\t\t\treturn editor.chain().focus().clearNodes().run();\n\t\t}\n\n\t\t// clearNodes first to convert any block type to paragraph,\n\t\t// then toggle list\n\t\treturn editor.chain().focus().clearNodes().toggleList(type, itemType).run();\n\t}, [editor, type]);\n\n\treturn {\n\t\tisActive,\n\t\tcanToggle,\n\t\thandleToggle,\n\t\tlabel: listLabels[type],\n\t\tIcon: listIcons[type]\n\t};\n}\n\nexport function useActiveListType(\n\teditor: Editor | null,\n\ttypes: ListType[]\n): ListType | null {\n\tconst [activeType, setActiveType] = useState<ListType | null>(null);\n\n\tuseEffect(() => {\n\t\tif (!editor) return;\n\n\t\tconst handleUpdate = () => {\n\t\t\tconst found = types.find((type) => editor.isActive(type));\n\n\t\t\tsetActiveType(found ?? null);\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, types]);\n\n\treturn activeType;\n}\n\nexport function getListTriggerIcon(activeType: ListType | null): IconComponent {\n\tif (activeType === null) return List;\n\n\treturn listIcons[activeType];\n}\n"],"mappings":"AAAA,SAAS,MAAM,aAAa,gBAAgB;AAC5C,SAAS,aAAa,WAAW,gBAAgB;AASjD,
|
|
1
|
+
{"version":3,"sources":["../../../src/components/list-dropdown-menu/use-list.ts"],"sourcesContent":["import { List, ListOrdered, ListTodo } from 'lucide-react';\nimport { useCallback, useEffect, useState } from 'react';\n\nimport type { Editor } from '@tiptap/core';\nimport type { LucideIcon } from 'lucide-react';\n\nexport type ListType = 'bulletList' | 'orderedList' | 'taskList';\n\ntype IconComponent = LucideIcon;\n\nconst listIcons: Record<ListType, IconComponent> = {\n\tbulletList: List,\n\torderedList: ListOrdered,\n\ttaskList: ListTodo\n};\n\nconst listLabels: Record<ListType, string> = {\n\tbulletList: 'Bullet List',\n\torderedList: 'Ordered List',\n\ttaskList: 'Task List'\n};\n\nconst listItemTypes: Record<ListType, string> = {\n\tbulletList: 'listItem',\n\torderedList: 'listItem',\n\ttaskList: 'taskItem'\n};\n\nfunction canToggleList(editor: Editor | null): boolean {\n\tif (!editor || !editor.isEditable) return false;\n\n\treturn (\n\t\teditor.can().toggleList('bulletList', 'listItem') ||\n\t\teditor.can().clearNodes()\n\t);\n}\n\nexport function useList({\n\teditor,\n\ttype\n}: {\n\teditor: Editor | null;\n\ttype: ListType;\n}) {\n\tconst [isActive, setIsActive] = useState(false);\n\tconst [canToggle, setCanToggle] = useState(false);\n\n\tuseEffect(() => {\n\t\tif (!editor) return;\n\n\t\tconst handleUpdate = () => {\n\t\t\tsetIsActive(editor.isActive(type));\n\t\t\tsetCanToggle(canToggleList(editor));\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, type]);\n\n\tconst handleToggle = useCallback(() => {\n\t\tif (!editor || !editor.isEditable) return false;\n\n\t\tconst itemType = listItemTypes[type];\n\n\t\tif (editor.isActive(type)) {\n\t\t\t// Currently this list type → convert back to paragraph\n\t\t\treturn editor.chain().focus().clearNodes().run();\n\t\t}\n\n\t\t// clearNodes first to convert any block type to paragraph,\n\t\t// then toggle list\n\t\treturn editor.chain().focus().clearNodes().toggleList(type, itemType).run();\n\t}, [editor, type]);\n\n\treturn {\n\t\tisActive,\n\t\tcanToggle,\n\t\thandleToggle,\n\t\tlabel: listLabels[type],\n\t\tIcon: listIcons[type]\n\t};\n}\n\nexport function useActiveListType(\n\teditor: Editor | null,\n\ttypes: ListType[]\n): ListType | null {\n\tconst [activeType, setActiveType] = useState<ListType | null>(null);\n\n\tuseEffect(() => {\n\t\tif (!editor) return;\n\n\t\tconst handleUpdate = () => {\n\t\t\tconst found = types.find((type) => editor.isActive(type));\n\n\t\t\tsetActiveType(found ?? null);\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, types]);\n\n\treturn activeType;\n}\n\nexport function getListTriggerIcon(activeType: ListType | null): IconComponent {\n\tif (activeType === null) return List;\n\n\treturn listIcons[activeType];\n}\n"],"mappings":";AAAA,SAAS,MAAM,aAAa,gBAAgB;AAC5C,SAAS,aAAa,WAAW,gBAAgB;AASjD,IAAM,YAA6C;AAAA,EAClD,YAAY;AAAA,EACZ,aAAa;AAAA,EACb,UAAU;AACX;AAEA,IAAM,aAAuC;AAAA,EAC5C,YAAY;AAAA,EACZ,aAAa;AAAA,EACb,UAAU;AACX;AAEA,IAAM,gBAA0C;AAAA,EAC/C,YAAY;AAAA,EACZ,aAAa;AAAA,EACb,UAAU;AACX;AAEA,SAAS,cAAc,QAAgC;AACtD,MAAI,CAAC,UAAU,CAAC,OAAO,WAAY,QAAO;AAE1C,SACC,OAAO,IAAI,EAAE,WAAW,cAAc,UAAU,KAChD,OAAO,IAAI,EAAE,WAAW;AAE1B;AAEO,SAAS,QAAQ;AAAA,EACvB;AAAA,EACA;AACD,GAGG;AACF,QAAM,CAAC,UAAU,WAAW,IAAI,SAAS,KAAK;AAC9C,QAAM,CAAC,WAAW,YAAY,IAAI,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AAO,IAAI,eAAe,YAAY;AAAA,IACvC;AAAA,EACD,GAAG,CAAC,QAAQ,KAAK,CAAC;AAElB,SAAO;AACR;AAEO,SAAS,mBAAmB,YAA4C;AAC9E,MAAI,eAAe,KAAM,QAAO;AAEhC,SAAO,UAAU,UAAU;AAC5B;","names":[]}
|
|
@@ -17,16 +17,18 @@ 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/mark-button/mark-button.tsx
|
|
20
22
|
var mark_button_exports = {};
|
|
21
23
|
__export(mark_button_exports, {
|
|
22
24
|
MarkButton: () => MarkButton
|
|
23
25
|
});
|
|
24
26
|
module.exports = __toCommonJS(mark_button_exports);
|
|
25
|
-
var import_jsx_runtime = require("react/jsx-runtime");
|
|
26
27
|
var import_react = require("react");
|
|
27
|
-
var import_use_mark = require("./use-mark");
|
|
28
|
-
var import_button = require("../ui/button");
|
|
29
|
-
|
|
28
|
+
var import_use_mark = require("./use-mark.cjs");
|
|
29
|
+
var import_button = require("../ui/button.cjs");
|
|
30
|
+
var import_jsx_runtime = require("react/jsx-runtime");
|
|
31
|
+
var MarkButton = (0, import_react.forwardRef)(
|
|
30
32
|
({ editor, type, onClick, ...buttonProps }, ref) => {
|
|
31
33
|
const { isActive, canToggle, handleToggle, label, Icon } = (0, import_use_mark.useMark)({
|
|
32
34
|
editor,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/components/mark-button/mark-button.tsx"],"sourcesContent":["'use client';\n\nimport { forwardRef, useCallback } from 'react';\n\nimport { useMark } from './use-mark';\nimport { Button } from '../ui/button';\n\nimport type { MarkType } from './use-mark';\nimport type { Editor } from '@tiptap/core';\n\nexport interface MarkButtonProps extends Omit<\n\tReact.ButtonHTMLAttributes<HTMLButtonElement>,\n\t'type'\n> {\n\teditor: Editor | null;\n\ttype: MarkType;\n}\n\nexport const MarkButton = forwardRef<HTMLButtonElement, MarkButtonProps>(\n\t({ editor, type, onClick, ...buttonProps }, ref) => {\n\t\tconst { isActive, canToggle, handleToggle, label, Icon } = useMark({\n\t\t\teditor,\n\t\t\ttype\n\t\t});\n\n\t\tconst handleClick = useCallback(\n\t\t\t(event: React.MouseEvent<HTMLButtonElement>) => {\n\t\t\t\tonClick?.(event);\n\n\t\t\t\tif (event.defaultPrevented) return;\n\n\t\t\t\thandleToggle();\n\t\t\t},\n\t\t\t[handleToggle, onClick]\n\t\t);\n\n\t\treturn (\n\t\t\t<Button\n\t\t\t\tref={ref}\n\t\t\t\taria-label={label}\n\t\t\t\taria-pressed={isActive}\n\t\t\t\tdata-active-state={isActive ? 'on' : 'off'}\n\t\t\t\tdisabled={!canToggle}\n\t\t\t\tsize=\"icon\"\n\t\t\t\ttabIndex={-1}\n\t\t\t\ttype=\"button\"\n\t\t\t\tvariant=\"ghost\"\n\t\t\t\tonClick={handleClick}\n\t\t\t\t{...buttonProps}\n\t\t\t>\n\t\t\t\t<Icon\n\t\t\t\t\tclassName={\n\t\t\t\t\t\tisActive ? 'nt:text-[var(--tt-brand-color-500)]' : undefined\n\t\t\t\t\t}\n\t\t\t\t/>\n\t\t\t</Button>\n\t\t);\n\t}\n);\n\nMarkButton.displayName = 'MarkButton';\n"],"mappings":"
|
|
1
|
+
{"version":3,"sources":["../../../src/components/mark-button/mark-button.tsx"],"sourcesContent":["'use client';\n\nimport { forwardRef, useCallback } from 'react';\n\nimport { useMark } from './use-mark.js';\nimport { Button } from '../ui/button.js';\n\nimport type { MarkType } from './use-mark.js';\nimport type { Editor } from '@tiptap/core';\n\nexport interface MarkButtonProps extends Omit<\n\tReact.ButtonHTMLAttributes<HTMLButtonElement>,\n\t'type'\n> {\n\teditor: Editor | null;\n\ttype: MarkType;\n}\n\nexport const MarkButton = forwardRef<HTMLButtonElement, MarkButtonProps>(\n\t({ editor, type, onClick, ...buttonProps }, ref) => {\n\t\tconst { isActive, canToggle, handleToggle, label, Icon } = useMark({\n\t\t\teditor,\n\t\t\ttype\n\t\t});\n\n\t\tconst handleClick = useCallback(\n\t\t\t(event: React.MouseEvent<HTMLButtonElement>) => {\n\t\t\t\tonClick?.(event);\n\n\t\t\t\tif (event.defaultPrevented) return;\n\n\t\t\t\thandleToggle();\n\t\t\t},\n\t\t\t[handleToggle, onClick]\n\t\t);\n\n\t\treturn (\n\t\t\t<Button\n\t\t\t\tref={ref}\n\t\t\t\taria-label={label}\n\t\t\t\taria-pressed={isActive}\n\t\t\t\tdata-active-state={isActive ? 'on' : 'off'}\n\t\t\t\tdisabled={!canToggle}\n\t\t\t\tsize=\"icon\"\n\t\t\t\ttabIndex={-1}\n\t\t\t\ttype=\"button\"\n\t\t\t\tvariant=\"ghost\"\n\t\t\t\tonClick={handleClick}\n\t\t\t\t{...buttonProps}\n\t\t\t>\n\t\t\t\t<Icon\n\t\t\t\t\tclassName={\n\t\t\t\t\t\tisActive ? 'nt:text-[var(--tt-brand-color-500)]' : undefined\n\t\t\t\t\t}\n\t\t\t\t/>\n\t\t\t</Button>\n\t\t);\n\t}\n);\n\nMarkButton.displayName = 'MarkButton';\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAEA,mBAAwC;AAExC,sBAAwB;AACxB,oBAAuB;AA6CnB;AAhCG,IAAM,iBAAa;AAAA,EACzB,CAAC,EAAE,QAAQ,MAAM,SAAS,GAAG,YAAY,GAAG,QAAQ;AACnD,UAAM,EAAE,UAAU,WAAW,cAAc,OAAO,KAAK,QAAI,yBAAQ;AAAA,MAClE;AAAA,MACA;AAAA,IACD,CAAC;AAED,UAAM,kBAAc;AAAA,MACnB,CAAC,UAA+C;AAC/C,kBAAU,KAAK;AAEf,YAAI,MAAM,iBAAkB;AAE5B,qBAAa;AAAA,MACd;AAAA,MACA,CAAC,cAAc,OAAO;AAAA,IACvB;AAEA,WACC;AAAA,MAAC;AAAA;AAAA,QACA;AAAA,QACA,cAAY;AAAA,QACZ,gBAAc;AAAA,QACd,qBAAmB,WAAW,OAAO;AAAA,QACrC,UAAU,CAAC;AAAA,QACX,MAAK;AAAA,QACL,UAAU;AAAA,QACV,MAAK;AAAA,QACL,SAAQ;AAAA,QACR,SAAS;AAAA,QACR,GAAG;AAAA,QAEJ;AAAA,UAAC;AAAA;AAAA,YACA,WACC,WAAW,wCAAwC;AAAA;AAAA,QAErD;AAAA;AAAA,IACD;AAAA,EAEF;AACD;AAEA,WAAW,cAAc;","names":[]}
|
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
"use client";
|
|
2
|
-
|
|
2
|
+
|
|
3
|
+
// src/components/mark-button/mark-button.tsx
|
|
3
4
|
import { forwardRef, useCallback } from "react";
|
|
4
|
-
import { useMark } from "./use-mark";
|
|
5
|
-
import { Button } from "../ui/button";
|
|
6
|
-
|
|
5
|
+
import { useMark } from "./use-mark.mjs";
|
|
6
|
+
import { Button } from "../ui/button.mjs";
|
|
7
|
+
import { jsx } from "react/jsx-runtime";
|
|
8
|
+
var MarkButton = forwardRef(
|
|
7
9
|
({ editor, type, onClick, ...buttonProps }, ref) => {
|
|
8
10
|
const { isActive, canToggle, handleToggle, label, Icon } = useMark({
|
|
9
11
|
editor,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/components/mark-button/mark-button.tsx"],"sourcesContent":["'use client';\n\nimport { forwardRef, useCallback } from 'react';\n\nimport { useMark } from './use-mark';\nimport { Button } from '../ui/button';\n\nimport type { MarkType } from './use-mark';\nimport type { Editor } from '@tiptap/core';\n\nexport interface MarkButtonProps extends Omit<\n\tReact.ButtonHTMLAttributes<HTMLButtonElement>,\n\t'type'\n> {\n\teditor: Editor | null;\n\ttype: MarkType;\n}\n\nexport const MarkButton = forwardRef<HTMLButtonElement, MarkButtonProps>(\n\t({ editor, type, onClick, ...buttonProps }, ref) => {\n\t\tconst { isActive, canToggle, handleToggle, label, Icon } = useMark({\n\t\t\teditor,\n\t\t\ttype\n\t\t});\n\n\t\tconst handleClick = useCallback(\n\t\t\t(event: React.MouseEvent<HTMLButtonElement>) => {\n\t\t\t\tonClick?.(event);\n\n\t\t\t\tif (event.defaultPrevented) return;\n\n\t\t\t\thandleToggle();\n\t\t\t},\n\t\t\t[handleToggle, onClick]\n\t\t);\n\n\t\treturn (\n\t\t\t<Button\n\t\t\t\tref={ref}\n\t\t\t\taria-label={label}\n\t\t\t\taria-pressed={isActive}\n\t\t\t\tdata-active-state={isActive ? 'on' : 'off'}\n\t\t\t\tdisabled={!canToggle}\n\t\t\t\tsize=\"icon\"\n\t\t\t\ttabIndex={-1}\n\t\t\t\ttype=\"button\"\n\t\t\t\tvariant=\"ghost\"\n\t\t\t\tonClick={handleClick}\n\t\t\t\t{...buttonProps}\n\t\t\t>\n\t\t\t\t<Icon\n\t\t\t\t\tclassName={\n\t\t\t\t\t\tisActive ? 'nt:text-[var(--tt-brand-color-500)]' : undefined\n\t\t\t\t\t}\n\t\t\t\t/>\n\t\t\t</Button>\n\t\t);\n\t}\n);\n\nMarkButton.displayName = 'MarkButton';\n"],"mappings":"
|
|
1
|
+
{"version":3,"sources":["../../../src/components/mark-button/mark-button.tsx"],"sourcesContent":["'use client';\n\nimport { forwardRef, useCallback } from 'react';\n\nimport { useMark } from './use-mark.js';\nimport { Button } from '../ui/button.js';\n\nimport type { MarkType } from './use-mark.js';\nimport type { Editor } from '@tiptap/core';\n\nexport interface MarkButtonProps extends Omit<\n\tReact.ButtonHTMLAttributes<HTMLButtonElement>,\n\t'type'\n> {\n\teditor: Editor | null;\n\ttype: MarkType;\n}\n\nexport const MarkButton = forwardRef<HTMLButtonElement, MarkButtonProps>(\n\t({ editor, type, onClick, ...buttonProps }, ref) => {\n\t\tconst { isActive, canToggle, handleToggle, label, Icon } = useMark({\n\t\t\teditor,\n\t\t\ttype\n\t\t});\n\n\t\tconst handleClick = useCallback(\n\t\t\t(event: React.MouseEvent<HTMLButtonElement>) => {\n\t\t\t\tonClick?.(event);\n\n\t\t\t\tif (event.defaultPrevented) return;\n\n\t\t\t\thandleToggle();\n\t\t\t},\n\t\t\t[handleToggle, onClick]\n\t\t);\n\n\t\treturn (\n\t\t\t<Button\n\t\t\t\tref={ref}\n\t\t\t\taria-label={label}\n\t\t\t\taria-pressed={isActive}\n\t\t\t\tdata-active-state={isActive ? 'on' : 'off'}\n\t\t\t\tdisabled={!canToggle}\n\t\t\t\tsize=\"icon\"\n\t\t\t\ttabIndex={-1}\n\t\t\t\ttype=\"button\"\n\t\t\t\tvariant=\"ghost\"\n\t\t\t\tonClick={handleClick}\n\t\t\t\t{...buttonProps}\n\t\t\t>\n\t\t\t\t<Icon\n\t\t\t\t\tclassName={\n\t\t\t\t\t\tisActive ? 'nt:text-[var(--tt-brand-color-500)]' : undefined\n\t\t\t\t\t}\n\t\t\t\t/>\n\t\t\t</Button>\n\t\t);\n\t}\n);\n\nMarkButton.displayName = 'MarkButton';\n"],"mappings":";;;AAEA,SAAS,YAAY,mBAAmB;AAExC,SAAS,eAAe;AACxB,SAAS,cAAc;AA6CnB;AAhCG,IAAM,aAAa;AAAA,EACzB,CAAC,EAAE,QAAQ,MAAM,SAAS,GAAG,YAAY,GAAG,QAAQ;AACnD,UAAM,EAAE,UAAU,WAAW,cAAc,OAAO,KAAK,IAAI,QAAQ;AAAA,MAClE;AAAA,MACA;AAAA,IACD,CAAC;AAED,UAAM,cAAc;AAAA,MACnB,CAAC,UAA+C;AAC/C,kBAAU,KAAK;AAEf,YAAI,MAAM,iBAAkB;AAE5B,qBAAa;AAAA,MACd;AAAA,MACA,CAAC,cAAc,OAAO;AAAA,IACvB;AAEA,WACC;AAAA,MAAC;AAAA;AAAA,QACA;AAAA,QACA,cAAY;AAAA,QACZ,gBAAc;AAAA,QACd,qBAAmB,WAAW,OAAO;AAAA,QACrC,UAAU,CAAC;AAAA,QACX,MAAK;AAAA,QACL,UAAU;AAAA,QACV,MAAK;AAAA,QACL,SAAQ;AAAA,QACR,SAAS;AAAA,QACR,GAAG;AAAA,QAEJ;AAAA,UAAC;AAAA;AAAA,YACA,WACC,WAAW,wCAAwC;AAAA;AAAA,QAErD;AAAA;AAAA,IACD;AAAA,EAEF;AACD;AAEA,WAAW,cAAc;","names":[]}
|
|
@@ -16,6 +16,8 @@ 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/mark-button/use-mark.ts
|
|
19
21
|
var use_mark_exports = {};
|
|
20
22
|
__export(use_mark_exports, {
|
|
21
23
|
useMark: () => useMark
|
|
@@ -23,13 +25,13 @@ __export(use_mark_exports, {
|
|
|
23
25
|
module.exports = __toCommonJS(use_mark_exports);
|
|
24
26
|
var import_lucide_react = require("lucide-react");
|
|
25
27
|
var import_react = require("react");
|
|
26
|
-
|
|
28
|
+
var markLabels = {
|
|
27
29
|
bold: "Bold",
|
|
28
30
|
italic: "Italic",
|
|
29
31
|
strike: "Strikethrough",
|
|
30
32
|
code: "Code"
|
|
31
33
|
};
|
|
32
|
-
|
|
34
|
+
var markIcons = {
|
|
33
35
|
bold: import_lucide_react.Bold,
|
|
34
36
|
italic: import_lucide_react.Italic,
|
|
35
37
|
strike: import_lucide_react.Strikethrough,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/components/mark-button/use-mark.ts"],"sourcesContent":["import { Bold, Code, Italic, Strikethrough } from 'lucide-react';\nimport { useCallback, useEffect, useState } from 'react';\n\nimport type { Editor } from '@tiptap/core';\nimport type { LucideIcon } from 'lucide-react';\n\nexport type MarkType = 'bold' | 'italic' | 'strike' | 'code';\n\nexport interface UseMarkConfig {\n\teditor: Editor | null;\n\ttype: MarkType;\n}\n\nconst markLabels: Record<MarkType, string> = {\n\tbold: 'Bold',\n\titalic: 'Italic',\n\tstrike: 'Strikethrough',\n\tcode: 'Code'\n};\n\nconst markIcons: Record<MarkType, LucideIcon> = {\n\tbold: Bold,\n\titalic: Italic,\n\tstrike: Strikethrough,\n\tcode: Code\n};\n\nexport function useMark({ editor, type }: UseMarkConfig) {\n\tconst [isActive, setIsActive] = useState(false);\n\tconst [canToggle, setCanToggle] = useState(false);\n\n\tuseEffect(() => {\n\t\tif (!editor) return;\n\n\t\tconst handleUpdate = () => {\n\t\t\tsetIsActive(editor.isActive(type));\n\t\t\tsetCanToggle(editor.isEditable && editor.can().toggleMark(type));\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, type]);\n\n\tconst handleToggle = useCallback(() => {\n\t\tif (!editor || !editor.isEditable) return false;\n\n\t\treturn editor.chain().focus().toggleMark(type).run();\n\t}, [editor, type]);\n\n\treturn {\n\t\tisActive,\n\t\tcanToggle,\n\t\thandleToggle,\n\t\tlabel: markLabels[type],\n\t\tIcon: markIcons[type]\n\t};\n}\n"],"mappings":"
|
|
1
|
+
{"version":3,"sources":["../../../src/components/mark-button/use-mark.ts"],"sourcesContent":["import { Bold, Code, Italic, Strikethrough } from 'lucide-react';\nimport { useCallback, useEffect, useState } from 'react';\n\nimport type { Editor } from '@tiptap/core';\nimport type { LucideIcon } from 'lucide-react';\n\nexport type MarkType = 'bold' | 'italic' | 'strike' | 'code';\n\nexport interface UseMarkConfig {\n\teditor: Editor | null;\n\ttype: MarkType;\n}\n\nconst markLabels: Record<MarkType, string> = {\n\tbold: 'Bold',\n\titalic: 'Italic',\n\tstrike: 'Strikethrough',\n\tcode: 'Code'\n};\n\nconst markIcons: Record<MarkType, LucideIcon> = {\n\tbold: Bold,\n\titalic: Italic,\n\tstrike: Strikethrough,\n\tcode: Code\n};\n\nexport function useMark({ editor, type }: UseMarkConfig) {\n\tconst [isActive, setIsActive] = useState(false);\n\tconst [canToggle, setCanToggle] = useState(false);\n\n\tuseEffect(() => {\n\t\tif (!editor) return;\n\n\t\tconst handleUpdate = () => {\n\t\t\tsetIsActive(editor.isActive(type));\n\t\t\tsetCanToggle(editor.isEditable && editor.can().toggleMark(type));\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, type]);\n\n\tconst handleToggle = useCallback(() => {\n\t\tif (!editor || !editor.isEditable) return false;\n\n\t\treturn editor.chain().focus().toggleMark(type).run();\n\t}, [editor, type]);\n\n\treturn {\n\t\tisActive,\n\t\tcanToggle,\n\t\thandleToggle,\n\t\tlabel: markLabels[type],\n\t\tIcon: markIcons[type]\n\t};\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,0BAAkD;AAClD,mBAAiD;AAYjD,IAAM,aAAuC;AAAA,EAC5C,MAAM;AAAA,EACN,QAAQ;AAAA,EACR,QAAQ;AAAA,EACR,MAAM;AACP;AAEA,IAAM,YAA0C;AAAA,EAC/C,MAAM;AAAA,EACN,QAAQ;AAAA,EACR,QAAQ;AAAA,EACR,MAAM;AACP;AAEO,SAAS,QAAQ,EAAE,QAAQ,KAAK,GAAkB;AACxD,QAAM,CAAC,UAAU,WAAW,QAAI,uBAAS,KAAK;AAC9C,QAAM,CAAC,WAAW,YAAY,QAAI,uBAAS,KAAK;AAEhD,8BAAU,MAAM;AACf,QAAI,CAAC,OAAQ;AAEb,UAAM,eAAe,MAAM;AAC1B,kBAAY,OAAO,SAAS,IAAI,CAAC;AACjC,mBAAa,OAAO,cAAc,OAAO,IAAI,EAAE,WAAW,IAAI,CAAC;AAAA,IAChE;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,QAAQ,IAAI,CAAC;AAEjB,QAAM,mBAAe,0BAAY,MAAM;AACtC,QAAI,CAAC,UAAU,CAAC,OAAO,WAAY,QAAO;AAE1C,WAAO,OAAO,MAAM,EAAE,MAAM,EAAE,WAAW,IAAI,EAAE,IAAI;AAAA,EACpD,GAAG,CAAC,QAAQ,IAAI,CAAC;AAEjB,SAAO;AAAA,IACN;AAAA,IACA;AAAA,IACA;AAAA,IACA,OAAO,WAAW,IAAI;AAAA,IACtB,MAAM,UAAU,IAAI;AAAA,EACrB;AACD;","names":[]}
|
|
@@ -1,12 +1,13 @@
|
|
|
1
|
+
// src/components/mark-button/use-mark.ts
|
|
1
2
|
import { Bold, Code, Italic, Strikethrough } from "lucide-react";
|
|
2
3
|
import { useCallback, useEffect, useState } from "react";
|
|
3
|
-
|
|
4
|
+
var markLabels = {
|
|
4
5
|
bold: "Bold",
|
|
5
6
|
italic: "Italic",
|
|
6
7
|
strike: "Strikethrough",
|
|
7
8
|
code: "Code"
|
|
8
9
|
};
|
|
9
|
-
|
|
10
|
+
var markIcons = {
|
|
10
11
|
bold: Bold,
|
|
11
12
|
italic: Italic,
|
|
12
13
|
strike: Strikethrough,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/components/mark-button/use-mark.ts"],"sourcesContent":["import { Bold, Code, Italic, Strikethrough } from 'lucide-react';\nimport { useCallback, useEffect, useState } from 'react';\n\nimport type { Editor } from '@tiptap/core';\nimport type { LucideIcon } from 'lucide-react';\n\nexport type MarkType = 'bold' | 'italic' | 'strike' | 'code';\n\nexport interface UseMarkConfig {\n\teditor: Editor | null;\n\ttype: MarkType;\n}\n\nconst markLabels: Record<MarkType, string> = {\n\tbold: 'Bold',\n\titalic: 'Italic',\n\tstrike: 'Strikethrough',\n\tcode: 'Code'\n};\n\nconst markIcons: Record<MarkType, LucideIcon> = {\n\tbold: Bold,\n\titalic: Italic,\n\tstrike: Strikethrough,\n\tcode: Code\n};\n\nexport function useMark({ editor, type }: UseMarkConfig) {\n\tconst [isActive, setIsActive] = useState(false);\n\tconst [canToggle, setCanToggle] = useState(false);\n\n\tuseEffect(() => {\n\t\tif (!editor) return;\n\n\t\tconst handleUpdate = () => {\n\t\t\tsetIsActive(editor.isActive(type));\n\t\t\tsetCanToggle(editor.isEditable && editor.can().toggleMark(type));\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, type]);\n\n\tconst handleToggle = useCallback(() => {\n\t\tif (!editor || !editor.isEditable) return false;\n\n\t\treturn editor.chain().focus().toggleMark(type).run();\n\t}, [editor, type]);\n\n\treturn {\n\t\tisActive,\n\t\tcanToggle,\n\t\thandleToggle,\n\t\tlabel: markLabels[type],\n\t\tIcon: markIcons[type]\n\t};\n}\n"],"mappings":"AAAA,SAAS,MAAM,MAAM,QAAQ,qBAAqB;AAClD,SAAS,aAAa,WAAW,gBAAgB;AAYjD,
|
|
1
|
+
{"version":3,"sources":["../../../src/components/mark-button/use-mark.ts"],"sourcesContent":["import { Bold, Code, Italic, Strikethrough } from 'lucide-react';\nimport { useCallback, useEffect, useState } from 'react';\n\nimport type { Editor } from '@tiptap/core';\nimport type { LucideIcon } from 'lucide-react';\n\nexport type MarkType = 'bold' | 'italic' | 'strike' | 'code';\n\nexport interface UseMarkConfig {\n\teditor: Editor | null;\n\ttype: MarkType;\n}\n\nconst markLabels: Record<MarkType, string> = {\n\tbold: 'Bold',\n\titalic: 'Italic',\n\tstrike: 'Strikethrough',\n\tcode: 'Code'\n};\n\nconst markIcons: Record<MarkType, LucideIcon> = {\n\tbold: Bold,\n\titalic: Italic,\n\tstrike: Strikethrough,\n\tcode: Code\n};\n\nexport function useMark({ editor, type }: UseMarkConfig) {\n\tconst [isActive, setIsActive] = useState(false);\n\tconst [canToggle, setCanToggle] = useState(false);\n\n\tuseEffect(() => {\n\t\tif (!editor) return;\n\n\t\tconst handleUpdate = () => {\n\t\t\tsetIsActive(editor.isActive(type));\n\t\t\tsetCanToggle(editor.isEditable && editor.can().toggleMark(type));\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, type]);\n\n\tconst handleToggle = useCallback(() => {\n\t\tif (!editor || !editor.isEditable) return false;\n\n\t\treturn editor.chain().focus().toggleMark(type).run();\n\t}, [editor, type]);\n\n\treturn {\n\t\tisActive,\n\t\tcanToggle,\n\t\thandleToggle,\n\t\tlabel: markLabels[type],\n\t\tIcon: markIcons[type]\n\t};\n}\n"],"mappings":";AAAA,SAAS,MAAM,MAAM,QAAQ,qBAAqB;AAClD,SAAS,aAAa,WAAW,gBAAgB;AAYjD,IAAM,aAAuC;AAAA,EAC5C,MAAM;AAAA,EACN,QAAQ;AAAA,EACR,QAAQ;AAAA,EACR,MAAM;AACP;AAEA,IAAM,YAA0C;AAAA,EAC/C,MAAM;AAAA,EACN,QAAQ;AAAA,EACR,QAAQ;AAAA,EACR,MAAM;AACP;AAEO,SAAS,QAAQ,EAAE,QAAQ,KAAK,GAAkB;AACxD,QAAM,CAAC,UAAU,WAAW,IAAI,SAAS,KAAK;AAC9C,QAAM,CAAC,WAAW,YAAY,IAAI,SAAS,KAAK;AAEhD,YAAU,MAAM;AACf,QAAI,CAAC,OAAQ;AAEb,UAAM,eAAe,MAAM;AAC1B,kBAAY,OAAO,SAAS,IAAI,CAAC;AACjC,mBAAa,OAAO,cAAc,OAAO,IAAI,EAAE,WAAW,IAAI,CAAC;AAAA,IAChE;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,QAAQ,IAAI,CAAC;AAEjB,QAAM,eAAe,YAAY,MAAM;AACtC,QAAI,CAAC,UAAU,CAAC,OAAO,WAAY,QAAO;AAE1C,WAAO,OAAO,MAAM,EAAE,MAAM,EAAE,WAAW,IAAI,EAAE,IAAI;AAAA,EACpD,GAAG,CAAC,QAAQ,IAAI,CAAC;AAEjB,SAAO;AAAA,IACN;AAAA,IACA;AAAA,IACA;AAAA,IACA,OAAO,WAAW,IAAI;AAAA,IACtB,MAAM,UAAU,IAAI;AAAA,EACrB;AACD;","names":[]}
|
|
@@ -0,0 +1,151 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
"use client";
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
+
var __export = (target, all) => {
|
|
8
|
+
for (var name in all)
|
|
9
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
10
|
+
};
|
|
11
|
+
var __copyProps = (to, from, except, desc) => {
|
|
12
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
13
|
+
for (let key of __getOwnPropNames(from))
|
|
14
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
15
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
16
|
+
}
|
|
17
|
+
return to;
|
|
18
|
+
};
|
|
19
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
20
|
+
|
|
21
|
+
// src/components/slash-dropdown-menu/slash-dropdown-menu.tsx
|
|
22
|
+
var slash_dropdown_menu_exports = {};
|
|
23
|
+
__export(slash_dropdown_menu_exports, {
|
|
24
|
+
SlashDropdownMenu: () => SlashDropdownMenu
|
|
25
|
+
});
|
|
26
|
+
module.exports = __toCommonJS(slash_dropdown_menu_exports);
|
|
27
|
+
var import_react = require("react");
|
|
28
|
+
var import_slash_image_popover = require("./slash-image-popover.cjs");
|
|
29
|
+
var import_use_slash_items = require("./use-slash-items.cjs");
|
|
30
|
+
var import_filter_suggestion_items = require("../suggestion-menu/filter-suggestion-items.cjs");
|
|
31
|
+
var import_suggestion_menu = require("../suggestion-menu/suggestion-menu.cjs");
|
|
32
|
+
var import_button = require("../ui/button.cjs");
|
|
33
|
+
var import_separator = require("../ui/separator.cjs");
|
|
34
|
+
var import_jsx_runtime = require("react/jsx-runtime");
|
|
35
|
+
function SlashDropdownMenu({ editor }) {
|
|
36
|
+
const [imageAnchor, setImageAnchor] = (0, import_react.useState)(null);
|
|
37
|
+
const handleImageRequest = (0, import_react.useCallback)(() => {
|
|
38
|
+
if (!editor) return;
|
|
39
|
+
const { from } = editor.state.selection;
|
|
40
|
+
const rect = editor.view.coordsAtPos(from);
|
|
41
|
+
const domRect = new DOMRect(
|
|
42
|
+
rect.left,
|
|
43
|
+
rect.top,
|
|
44
|
+
rect.right - rect.left,
|
|
45
|
+
rect.bottom - rect.top
|
|
46
|
+
);
|
|
47
|
+
setImageAnchor(domRect);
|
|
48
|
+
}, [editor]);
|
|
49
|
+
const getItems = (0, import_use_slash_items.useSlashItems)({ onImageRequest: handleImageRequest });
|
|
50
|
+
const itemsCallback = (0, import_react.useCallback)(
|
|
51
|
+
({ query, editor: editor2 }) => (0, import_filter_suggestion_items.filterSuggestionItems)(getItems(editor2), query),
|
|
52
|
+
[getItems]
|
|
53
|
+
);
|
|
54
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_jsx_runtime.Fragment, { children: [
|
|
55
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
56
|
+
import_suggestion_menu.SuggestionMenu,
|
|
57
|
+
{
|
|
58
|
+
char: "/",
|
|
59
|
+
decorationClass: "notra-slash-decoration",
|
|
60
|
+
decorationContent: "Filter...",
|
|
61
|
+
editor,
|
|
62
|
+
items: itemsCallback,
|
|
63
|
+
pluginKey: "slashDropdownMenu",
|
|
64
|
+
selector: "notra-slash-dropdown-menu",
|
|
65
|
+
children: ({ items, selectedIndex, onSelect }) => /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
66
|
+
GroupedItemList,
|
|
67
|
+
{
|
|
68
|
+
items,
|
|
69
|
+
selectedIndex,
|
|
70
|
+
onSelect
|
|
71
|
+
}
|
|
72
|
+
)
|
|
73
|
+
}
|
|
74
|
+
),
|
|
75
|
+
imageAnchor && editor && /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
76
|
+
import_slash_image_popover.SlashImagePopover,
|
|
77
|
+
{
|
|
78
|
+
anchorRect: imageAnchor,
|
|
79
|
+
editor,
|
|
80
|
+
onClose: () => setImageAnchor(null)
|
|
81
|
+
}
|
|
82
|
+
)
|
|
83
|
+
] });
|
|
84
|
+
}
|
|
85
|
+
function GroupedItemList({
|
|
86
|
+
items,
|
|
87
|
+
selectedIndex,
|
|
88
|
+
onSelect
|
|
89
|
+
}) {
|
|
90
|
+
const groups = (0, import_react.useMemo)(() => {
|
|
91
|
+
const result = [];
|
|
92
|
+
items.forEach((item, index) => {
|
|
93
|
+
const label = item.group ?? "";
|
|
94
|
+
const last = result[result.length - 1];
|
|
95
|
+
if (last && last.label === label) {
|
|
96
|
+
last.items.push(item);
|
|
97
|
+
last.offsets.push(index);
|
|
98
|
+
} else {
|
|
99
|
+
result.push({ label, items: [item], offsets: [index] });
|
|
100
|
+
}
|
|
101
|
+
});
|
|
102
|
+
return result;
|
|
103
|
+
}, [items]);
|
|
104
|
+
if (items.length === 0) return null;
|
|
105
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { className: "notra-slash-card", children: groups.map((group, groupIndex) => /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { children: [
|
|
106
|
+
groupIndex > 0 && /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_separator.Separator, { className: "nt:my-1", orientation: "horizontal" }),
|
|
107
|
+
group.label && /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { className: "notra-slash-group-label", children: group.label }),
|
|
108
|
+
group.items.map((item, itemIndex) => {
|
|
109
|
+
const absoluteIndex = group.offsets[itemIndex];
|
|
110
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
111
|
+
SlashItemButton,
|
|
112
|
+
{
|
|
113
|
+
isSelected: absoluteIndex === selectedIndex,
|
|
114
|
+
item,
|
|
115
|
+
onSelect: () => onSelect(item)
|
|
116
|
+
},
|
|
117
|
+
`${item.title}-${absoluteIndex}`
|
|
118
|
+
);
|
|
119
|
+
})
|
|
120
|
+
] }, `${group.label}-${groupIndex}`)) });
|
|
121
|
+
}
|
|
122
|
+
function SlashItemButton({ item, isSelected, onSelect }) {
|
|
123
|
+
const ref = (0, import_react.useRef)(null);
|
|
124
|
+
(0, import_react.useEffect)(() => {
|
|
125
|
+
if (!isSelected || !ref.current) return;
|
|
126
|
+
ref.current.scrollIntoView({ block: "nearest" });
|
|
127
|
+
}, [isSelected]);
|
|
128
|
+
const Badge = item.badge;
|
|
129
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(
|
|
130
|
+
import_button.Button,
|
|
131
|
+
{
|
|
132
|
+
ref,
|
|
133
|
+
className: "nt:w-full nt:justify-start nt:gap-2",
|
|
134
|
+
"data-active-state": isSelected ? "on" : "off",
|
|
135
|
+
size: "default",
|
|
136
|
+
tabIndex: -1,
|
|
137
|
+
type: "button",
|
|
138
|
+
variant: "ghost",
|
|
139
|
+
onClick: onSelect,
|
|
140
|
+
children: [
|
|
141
|
+
Badge && /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Badge, { className: "nt:size-4" }),
|
|
142
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { className: "nt:flex-1 nt:text-left", children: item.title })
|
|
143
|
+
]
|
|
144
|
+
}
|
|
145
|
+
);
|
|
146
|
+
}
|
|
147
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
148
|
+
0 && (module.exports = {
|
|
149
|
+
SlashDropdownMenu
|
|
150
|
+
});
|
|
151
|
+
//# sourceMappingURL=slash-dropdown-menu.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/components/slash-dropdown-menu/slash-dropdown-menu.tsx"],"sourcesContent":["'use client';\n\nimport { useCallback, useEffect, useMemo, useRef, useState } from 'react';\n\nimport { SlashImagePopover } from './slash-image-popover.js';\nimport { useSlashItems } from './use-slash-items.js';\nimport { filterSuggestionItems } from '../suggestion-menu/filter-suggestion-items.js';\nimport { SuggestionMenu } from '../suggestion-menu/suggestion-menu.js';\nimport { Button } from '../ui/button.js';\nimport { Separator } from '../ui/separator.js';\n\nimport type { SuggestionItem } from '../suggestion-menu/suggestion-menu-types.js';\nimport type { Editor } from '@tiptap/core';\n\nexport interface SlashDropdownMenuProps {\n\teditor: Editor | null;\n}\n\nexport function SlashDropdownMenu({ editor }: SlashDropdownMenuProps) {\n\tconst [imageAnchor, setImageAnchor] = useState<DOMRect | null>(null);\n\n\tconst handleImageRequest = useCallback(() => {\n\t\tif (!editor) return;\n\n\t\tconst { from } = editor.state.selection;\n\t\tconst rect = editor.view.coordsAtPos(from);\n\t\tconst domRect = new DOMRect(\n\t\t\trect.left,\n\t\t\trect.top,\n\t\t\trect.right - rect.left,\n\t\t\trect.bottom - rect.top\n\t\t);\n\n\t\tsetImageAnchor(domRect);\n\t}, [editor]);\n\n\tconst getItems = useSlashItems({ onImageRequest: handleImageRequest });\n\n\tconst itemsCallback = useCallback(\n\t\t({ query, editor }: { query: string; editor: Editor }) =>\n\t\t\tfilterSuggestionItems(getItems(editor), query),\n\t\t[getItems]\n\t);\n\n\treturn (\n\t\t<>\n\t\t\t<SuggestionMenu\n\t\t\t\tchar=\"/\"\n\t\t\t\tdecorationClass=\"notra-slash-decoration\"\n\t\t\t\tdecorationContent=\"Filter...\"\n\t\t\t\teditor={editor}\n\t\t\t\titems={itemsCallback}\n\t\t\t\tpluginKey=\"slashDropdownMenu\"\n\t\t\t\tselector=\"notra-slash-dropdown-menu\"\n\t\t\t>\n\t\t\t\t{({ items, selectedIndex, onSelect }) => (\n\t\t\t\t\t<GroupedItemList\n\t\t\t\t\t\titems={items}\n\t\t\t\t\t\tselectedIndex={selectedIndex}\n\t\t\t\t\t\tonSelect={onSelect}\n\t\t\t\t\t/>\n\t\t\t\t)}\n\t\t\t</SuggestionMenu>\n\t\t\t{imageAnchor && editor && (\n\t\t\t\t<SlashImagePopover\n\t\t\t\t\tanchorRect={imageAnchor}\n\t\t\t\t\teditor={editor}\n\t\t\t\t\tonClose={() => setImageAnchor(null)}\n\t\t\t\t/>\n\t\t\t)}\n\t\t</>\n\t);\n}\n\ninterface GroupedItemListProps {\n\titems: SuggestionItem[];\n\tselectedIndex: number;\n\tonSelect: (item: SuggestionItem) => void;\n}\n\nfunction GroupedItemList({\n\titems,\n\tselectedIndex,\n\tonSelect\n}: GroupedItemListProps) {\n\tconst groups = useMemo(() => {\n\t\tconst result: {\n\t\t\tlabel: string;\n\t\t\titems: SuggestionItem[];\n\t\t\toffsets: number[];\n\t\t}[] = [];\n\n\t\titems.forEach((item, index) => {\n\t\t\tconst label = item.group ?? '';\n\t\t\tconst last = result[result.length - 1];\n\n\t\t\tif (last && last.label === label) {\n\t\t\t\tlast.items.push(item);\n\t\t\t\tlast.offsets.push(index);\n\t\t\t} else {\n\t\t\t\tresult.push({ label, items: [item], offsets: [index] });\n\t\t\t}\n\t\t});\n\n\t\treturn result;\n\t}, [items]);\n\n\tif (items.length === 0) return null;\n\n\treturn (\n\t\t<div className=\"notra-slash-card\">\n\t\t\t{groups.map((group, groupIndex) => (\n\t\t\t\t<div key={`${group.label}-${groupIndex}`}>\n\t\t\t\t\t{groupIndex > 0 && (\n\t\t\t\t\t\t<Separator className=\"nt:my-1\" orientation=\"horizontal\" />\n\t\t\t\t\t)}\n\t\t\t\t\t{group.label && (\n\t\t\t\t\t\t<div className=\"notra-slash-group-label\">{group.label}</div>\n\t\t\t\t\t)}\n\t\t\t\t\t{group.items.map((item, itemIndex) => {\n\t\t\t\t\t\tconst absoluteIndex = group.offsets[itemIndex];\n\n\t\t\t\t\t\treturn (\n\t\t\t\t\t\t\t<SlashItemButton\n\t\t\t\t\t\t\t\tkey={`${item.title}-${absoluteIndex}`}\n\t\t\t\t\t\t\t\tisSelected={absoluteIndex === selectedIndex}\n\t\t\t\t\t\t\t\titem={item}\n\t\t\t\t\t\t\t\tonSelect={() => onSelect(item)}\n\t\t\t\t\t\t\t/>\n\t\t\t\t\t\t);\n\t\t\t\t\t})}\n\t\t\t\t</div>\n\t\t\t))}\n\t\t</div>\n\t);\n}\n\ninterface SlashItemButtonProps {\n\titem: SuggestionItem;\n\tisSelected: boolean;\n\tonSelect: () => void;\n}\n\nfunction SlashItemButton({ item, isSelected, onSelect }: SlashItemButtonProps) {\n\tconst ref = useRef<HTMLButtonElement>(null);\n\n\tuseEffect(() => {\n\t\tif (!isSelected || !ref.current) return;\n\n\t\tref.current.scrollIntoView({ block: 'nearest' });\n\t}, [isSelected]);\n\n\tconst Badge = item.badge;\n\n\treturn (\n\t\t<Button\n\t\t\tref={ref}\n\t\t\tclassName=\"nt:w-full nt:justify-start nt:gap-2\"\n\t\t\tdata-active-state={isSelected ? 'on' : 'off'}\n\t\t\tsize=\"default\"\n\t\t\ttabIndex={-1}\n\t\t\ttype=\"button\"\n\t\t\tvariant=\"ghost\"\n\t\t\tonClick={onSelect}\n\t\t>\n\t\t\t{Badge && <Badge className=\"nt:size-4\" />}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B,IAAI;AAE1C,8BAAU,MAAM;AACf,QAAI,CAAC,cAAc,CAAC,IAAI,QAAS;AAEjC,QAAI,QAAQ,eAAe,EAAE,OAAO,UAAU,CAAC;AAAA,EAChD,GAAG,CAAC,UAAU,CAAC;AAEf,QAAM,QAAQ,KAAK;AAEnB,SACC;AAAA,IAAC;AAAA;AAAA,MACA;AAAA,MACA,WAAU;AAAA,MACV,qBAAmB,aAAa,OAAO;AAAA,MACvC,MAAK;AAAA,MACL,UAAU;AAAA,MACV,MAAK;AAAA,MACL,SAAQ;AAAA,MACR,SAAS;AAAA,MAER;AAAA,iBAAS,4CAAC,SAAM,WAAU,aAAY;AAAA,QACvC,4CAAC,UAAK,WAAU,0BAA0B,eAAK,OAAM;AAAA;AAAA;AAAA,EACtD;AAEF;","names":["editor"]}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
2
|
+
import { Editor } from '@tiptap/core';
|
|
3
|
+
|
|
4
|
+
interface SlashDropdownMenuProps {
|
|
5
|
+
editor: Editor | null;
|
|
6
|
+
}
|
|
7
|
+
declare function SlashDropdownMenu({ editor }: SlashDropdownMenuProps): react_jsx_runtime.JSX.Element;
|
|
8
|
+
|
|
9
|
+
export { SlashDropdownMenu, type SlashDropdownMenuProps };
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
2
|
+
import { Editor } from '@tiptap/core';
|
|
3
|
+
|
|
4
|
+
interface SlashDropdownMenuProps {
|
|
5
|
+
editor: Editor | null;
|
|
6
|
+
}
|
|
7
|
+
declare function SlashDropdownMenu({ editor }: SlashDropdownMenuProps): react_jsx_runtime.JSX.Element;
|
|
8
|
+
|
|
9
|
+
export { SlashDropdownMenu, type SlashDropdownMenuProps };
|
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
|
|
3
|
+
// src/components/slash-dropdown-menu/slash-dropdown-menu.tsx
|
|
4
|
+
import { useCallback, useEffect, useMemo, useRef, useState } from "react";
|
|
5
|
+
import { SlashImagePopover } from "./slash-image-popover.mjs";
|
|
6
|
+
import { useSlashItems } from "./use-slash-items.mjs";
|
|
7
|
+
import { filterSuggestionItems } from "../suggestion-menu/filter-suggestion-items.mjs";
|
|
8
|
+
import { SuggestionMenu } from "../suggestion-menu/suggestion-menu.mjs";
|
|
9
|
+
import { Button } from "../ui/button.mjs";
|
|
10
|
+
import { Separator } from "../ui/separator.mjs";
|
|
11
|
+
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
12
|
+
function SlashDropdownMenu({ editor }) {
|
|
13
|
+
const [imageAnchor, setImageAnchor] = useState(null);
|
|
14
|
+
const handleImageRequest = useCallback(() => {
|
|
15
|
+
if (!editor) return;
|
|
16
|
+
const { from } = editor.state.selection;
|
|
17
|
+
const rect = editor.view.coordsAtPos(from);
|
|
18
|
+
const domRect = new DOMRect(
|
|
19
|
+
rect.left,
|
|
20
|
+
rect.top,
|
|
21
|
+
rect.right - rect.left,
|
|
22
|
+
rect.bottom - rect.top
|
|
23
|
+
);
|
|
24
|
+
setImageAnchor(domRect);
|
|
25
|
+
}, [editor]);
|
|
26
|
+
const getItems = useSlashItems({ onImageRequest: handleImageRequest });
|
|
27
|
+
const itemsCallback = useCallback(
|
|
28
|
+
({ query, editor: editor2 }) => filterSuggestionItems(getItems(editor2), query),
|
|
29
|
+
[getItems]
|
|
30
|
+
);
|
|
31
|
+
return /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
32
|
+
/* @__PURE__ */ jsx(
|
|
33
|
+
SuggestionMenu,
|
|
34
|
+
{
|
|
35
|
+
char: "/",
|
|
36
|
+
decorationClass: "notra-slash-decoration",
|
|
37
|
+
decorationContent: "Filter...",
|
|
38
|
+
editor,
|
|
39
|
+
items: itemsCallback,
|
|
40
|
+
pluginKey: "slashDropdownMenu",
|
|
41
|
+
selector: "notra-slash-dropdown-menu",
|
|
42
|
+
children: ({ items, selectedIndex, onSelect }) => /* @__PURE__ */ jsx(
|
|
43
|
+
GroupedItemList,
|
|
44
|
+
{
|
|
45
|
+
items,
|
|
46
|
+
selectedIndex,
|
|
47
|
+
onSelect
|
|
48
|
+
}
|
|
49
|
+
)
|
|
50
|
+
}
|
|
51
|
+
),
|
|
52
|
+
imageAnchor && editor && /* @__PURE__ */ jsx(
|
|
53
|
+
SlashImagePopover,
|
|
54
|
+
{
|
|
55
|
+
anchorRect: imageAnchor,
|
|
56
|
+
editor,
|
|
57
|
+
onClose: () => setImageAnchor(null)
|
|
58
|
+
}
|
|
59
|
+
)
|
|
60
|
+
] });
|
|
61
|
+
}
|
|
62
|
+
function GroupedItemList({
|
|
63
|
+
items,
|
|
64
|
+
selectedIndex,
|
|
65
|
+
onSelect
|
|
66
|
+
}) {
|
|
67
|
+
const groups = useMemo(() => {
|
|
68
|
+
const result = [];
|
|
69
|
+
items.forEach((item, index) => {
|
|
70
|
+
const label = item.group ?? "";
|
|
71
|
+
const last = result[result.length - 1];
|
|
72
|
+
if (last && last.label === label) {
|
|
73
|
+
last.items.push(item);
|
|
74
|
+
last.offsets.push(index);
|
|
75
|
+
} else {
|
|
76
|
+
result.push({ label, items: [item], offsets: [index] });
|
|
77
|
+
}
|
|
78
|
+
});
|
|
79
|
+
return result;
|
|
80
|
+
}, [items]);
|
|
81
|
+
if (items.length === 0) return null;
|
|
82
|
+
return /* @__PURE__ */ jsx("div", { className: "notra-slash-card", children: groups.map((group, groupIndex) => /* @__PURE__ */ jsxs("div", { children: [
|
|
83
|
+
groupIndex > 0 && /* @__PURE__ */ jsx(Separator, { className: "nt:my-1", orientation: "horizontal" }),
|
|
84
|
+
group.label && /* @__PURE__ */ jsx("div", { className: "notra-slash-group-label", children: group.label }),
|
|
85
|
+
group.items.map((item, itemIndex) => {
|
|
86
|
+
const absoluteIndex = group.offsets[itemIndex];
|
|
87
|
+
return /* @__PURE__ */ jsx(
|
|
88
|
+
SlashItemButton,
|
|
89
|
+
{
|
|
90
|
+
isSelected: absoluteIndex === selectedIndex,
|
|
91
|
+
item,
|
|
92
|
+
onSelect: () => onSelect(item)
|
|
93
|
+
},
|
|
94
|
+
`${item.title}-${absoluteIndex}`
|
|
95
|
+
);
|
|
96
|
+
})
|
|
97
|
+
] }, `${group.label}-${groupIndex}`)) });
|
|
98
|
+
}
|
|
99
|
+
function SlashItemButton({ item, isSelected, onSelect }) {
|
|
100
|
+
const ref = useRef(null);
|
|
101
|
+
useEffect(() => {
|
|
102
|
+
if (!isSelected || !ref.current) return;
|
|
103
|
+
ref.current.scrollIntoView({ block: "nearest" });
|
|
104
|
+
}, [isSelected]);
|
|
105
|
+
const Badge = item.badge;
|
|
106
|
+
return /* @__PURE__ */ jsxs(
|
|
107
|
+
Button,
|
|
108
|
+
{
|
|
109
|
+
ref,
|
|
110
|
+
className: "nt:w-full nt:justify-start nt:gap-2",
|
|
111
|
+
"data-active-state": isSelected ? "on" : "off",
|
|
112
|
+
size: "default",
|
|
113
|
+
tabIndex: -1,
|
|
114
|
+
type: "button",
|
|
115
|
+
variant: "ghost",
|
|
116
|
+
onClick: onSelect,
|
|
117
|
+
children: [
|
|
118
|
+
Badge && /* @__PURE__ */ jsx(Badge, { className: "nt:size-4" }),
|
|
119
|
+
/* @__PURE__ */ jsx("span", { className: "nt:flex-1 nt:text-left", children: item.title })
|
|
120
|
+
]
|
|
121
|
+
}
|
|
122
|
+
);
|
|
123
|
+
}
|
|
124
|
+
export {
|
|
125
|
+
SlashDropdownMenu
|
|
126
|
+
};
|
|
127
|
+
//# sourceMappingURL=slash-dropdown-menu.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/components/slash-dropdown-menu/slash-dropdown-menu.tsx"],"sourcesContent":["'use client';\n\nimport { useCallback, useEffect, useMemo, useRef, useState } from 'react';\n\nimport { SlashImagePopover } from './slash-image-popover.js';\nimport { useSlashItems } from './use-slash-items.js';\nimport { filterSuggestionItems } from '../suggestion-menu/filter-suggestion-items.js';\nimport { SuggestionMenu } from '../suggestion-menu/suggestion-menu.js';\nimport { Button } from '../ui/button.js';\nimport { Separator } from '../ui/separator.js';\n\nimport type { SuggestionItem } from '../suggestion-menu/suggestion-menu-types.js';\nimport type { Editor } from '@tiptap/core';\n\nexport interface SlashDropdownMenuProps {\n\teditor: Editor | null;\n}\n\nexport function SlashDropdownMenu({ editor }: SlashDropdownMenuProps) {\n\tconst [imageAnchor, setImageAnchor] = useState<DOMRect | null>(null);\n\n\tconst handleImageRequest = useCallback(() => {\n\t\tif (!editor) return;\n\n\t\tconst { from } = editor.state.selection;\n\t\tconst rect = editor.view.coordsAtPos(from);\n\t\tconst domRect = new DOMRect(\n\t\t\trect.left,\n\t\t\trect.top,\n\t\t\trect.right - rect.left,\n\t\t\trect.bottom - rect.top\n\t\t);\n\n\t\tsetImageAnchor(domRect);\n\t}, [editor]);\n\n\tconst getItems = useSlashItems({ onImageRequest: handleImageRequest });\n\n\tconst itemsCallback = useCallback(\n\t\t({ query, editor }: { query: string; editor: Editor }) =>\n\t\t\tfilterSuggestionItems(getItems(editor), query),\n\t\t[getItems]\n\t);\n\n\treturn (\n\t\t<>\n\t\t\t<SuggestionMenu\n\t\t\t\tchar=\"/\"\n\t\t\t\tdecorationClass=\"notra-slash-decoration\"\n\t\t\t\tdecorationContent=\"Filter...\"\n\t\t\t\teditor={editor}\n\t\t\t\titems={itemsCallback}\n\t\t\t\tpluginKey=\"slashDropdownMenu\"\n\t\t\t\tselector=\"notra-slash-dropdown-menu\"\n\t\t\t>\n\t\t\t\t{({ items, selectedIndex, onSelect }) => (\n\t\t\t\t\t<GroupedItemList\n\t\t\t\t\t\titems={items}\n\t\t\t\t\t\tselectedIndex={selectedIndex}\n\t\t\t\t\t\tonSelect={onSelect}\n\t\t\t\t\t/>\n\t\t\t\t)}\n\t\t\t</SuggestionMenu>\n\t\t\t{imageAnchor && editor && (\n\t\t\t\t<SlashImagePopover\n\t\t\t\t\tanchorRect={imageAnchor}\n\t\t\t\t\teditor={editor}\n\t\t\t\t\tonClose={() => setImageAnchor(null)}\n\t\t\t\t/>\n\t\t\t)}\n\t\t</>\n\t);\n}\n\ninterface GroupedItemListProps {\n\titems: SuggestionItem[];\n\tselectedIndex: number;\n\tonSelect: (item: SuggestionItem) => void;\n}\n\nfunction GroupedItemList({\n\titems,\n\tselectedIndex,\n\tonSelect\n}: GroupedItemListProps) {\n\tconst groups = useMemo(() => {\n\t\tconst result: {\n\t\t\tlabel: string;\n\t\t\titems: SuggestionItem[];\n\t\t\toffsets: number[];\n\t\t}[] = [];\n\n\t\titems.forEach((item, index) => {\n\t\t\tconst label = item.group ?? '';\n\t\t\tconst last = result[result.length - 1];\n\n\t\t\tif (last && last.label === label) {\n\t\t\t\tlast.items.push(item);\n\t\t\t\tlast.offsets.push(index);\n\t\t\t} else {\n\t\t\t\tresult.push({ label, items: [item], offsets: [index] });\n\t\t\t}\n\t\t});\n\n\t\treturn result;\n\t}, [items]);\n\n\tif (items.length === 0) return null;\n\n\treturn (\n\t\t<div className=\"notra-slash-card\">\n\t\t\t{groups.map((group, groupIndex) => (\n\t\t\t\t<div key={`${group.label}-${groupIndex}`}>\n\t\t\t\t\t{groupIndex > 0 && (\n\t\t\t\t\t\t<Separator className=\"nt:my-1\" orientation=\"horizontal\" />\n\t\t\t\t\t)}\n\t\t\t\t\t{group.label && (\n\t\t\t\t\t\t<div className=\"notra-slash-group-label\">{group.label}</div>\n\t\t\t\t\t)}\n\t\t\t\t\t{group.items.map((item, itemIndex) => {\n\t\t\t\t\t\tconst absoluteIndex = group.offsets[itemIndex];\n\n\t\t\t\t\t\treturn (\n\t\t\t\t\t\t\t<SlashItemButton\n\t\t\t\t\t\t\t\tkey={`${item.title}-${absoluteIndex}`}\n\t\t\t\t\t\t\t\tisSelected={absoluteIndex === selectedIndex}\n\t\t\t\t\t\t\t\titem={item}\n\t\t\t\t\t\t\t\tonSelect={() => onSelect(item)}\n\t\t\t\t\t\t\t/>\n\t\t\t\t\t\t);\n\t\t\t\t\t})}\n\t\t\t\t</div>\n\t\t\t))}\n\t\t</div>\n\t);\n}\n\ninterface SlashItemButtonProps {\n\titem: SuggestionItem;\n\tisSelected: boolean;\n\tonSelect: () => void;\n}\n\nfunction SlashItemButton({ item, isSelected, onSelect }: SlashItemButtonProps) {\n\tconst ref = useRef<HTMLButtonElement>(null);\n\n\tuseEffect(() => {\n\t\tif (!isSelected || !ref.current) return;\n\n\t\tref.current.scrollIntoView({ block: 'nearest' });\n\t}, [isSelected]);\n\n\tconst Badge = item.badge;\n\n\treturn (\n\t\t<Button\n\t\t\tref={ref}\n\t\t\tclassName=\"nt:w-full nt:justify-start nt:gap-2\"\n\t\t\tdata-active-state={isSelected ? 'on' : 'off'}\n\t\t\tsize=\"default\"\n\t\t\ttabIndex={-1}\n\t\t\ttype=\"button\"\n\t\t\tvariant=\"ghost\"\n\t\t\tonClick={onSelect}\n\t\t>\n\t\t\t{Badge && <Badge className=\"nt:size-4\" />}\n\t\t\t<span className=\"nt:flex-1 nt:text-left\">{item.title}</span>\n\t\t</Button>\n\t);\n}\n"],"mappings":";;;AAEA,SAAS,aAAa,WAAW,SAAS,QAAQ,gBAAgB;AAElE,SAAS,yBAAyB;AAClC,SAAS,qBAAqB;AAC9B,SAAS,6BAA6B;AACtC,SAAS,sBAAsB;AAC/B,SAAS,cAAc;AACvB,SAAS,iBAAiB;AAoCxB,mBAWG,KAXH;AA3BK,SAAS,kBAAkB,EAAE,OAAO,GAA2B;AACrE,QAAM,CAAC,aAAa,cAAc,IAAI,SAAyB,IAAI;AAEnE,QAAM,qBAAqB,YAAY,MAAM;AAC5C,QAAI,CAAC,OAAQ;AAEb,UAAM,EAAE,KAAK,IAAI,OAAO,MAAM;AAC9B,UAAM,OAAO,OAAO,KAAK,YAAY,IAAI;AACzC,UAAM,UAAU,IAAI;AAAA,MACnB,KAAK;AAAA,MACL,KAAK;AAAA,MACL,KAAK,QAAQ,KAAK;AAAA,MAClB,KAAK,SAAS,KAAK;AAA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