payload-richtext-tiptap 0.0.69 → 0.0.71
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/src/fields/TiptapEditor/extensions/AudioBlock/AudioBlock.d.ts.map +1 -1
- package/dist/src/fields/TiptapEditor/extensions/AudioBlock/AudioBlock.js +1 -0
- package/dist/src/fields/TiptapEditor/extensions/AudioBlock/AudioBlock.js.map +1 -1
- package/dist/src/fields/TiptapEditor/extensions/AudioBlock/components/AudioBlockMenu.js.map +1 -1
- package/dist/src/fields/TiptapEditor/extensions/Document/Document.d.ts.map +1 -1
- package/dist/src/fields/TiptapEditor/extensions/Document/Document.js +2 -2
- package/dist/src/fields/TiptapEditor/extensions/Document/Document.js.map +1 -1
- package/dist/src/fields/TiptapEditor/extensions/FontSize/FontSize.js.map +1 -1
- package/dist/src/fields/TiptapEditor/extensions/Heading/Heading.js.map +1 -1
- package/dist/src/fields/TiptapEditor/extensions/ImageBlock/ImageBlock.d.ts.map +1 -1
- package/dist/src/fields/TiptapEditor/extensions/ImageBlock/ImageBlock.js +1 -0
- package/dist/src/fields/TiptapEditor/extensions/ImageBlock/ImageBlock.js.map +1 -1
- package/dist/src/fields/TiptapEditor/extensions/ImageBlock/components/ImageBlockMenu.js.map +1 -1
- package/dist/src/fields/TiptapEditor/extensions/InsideLinks/InsideLink.client.js.map +1 -1
- package/dist/src/fields/TiptapEditor/extensions/InsideLinks/InsideLinksComponent.d.ts.map +1 -1
- package/dist/src/fields/TiptapEditor/extensions/InsideLinks/InsideLinksComponent.js +1 -0
- package/dist/src/fields/TiptapEditor/extensions/InsideLinks/InsideLinksComponent.js.map +1 -1
- package/dist/src/fields/TiptapEditor/extensions/MultiColumn/Columns.js +3 -3
- package/dist/src/fields/TiptapEditor/extensions/MultiColumn/Columns.js.map +1 -1
- package/dist/src/fields/TiptapEditor/extensions/MultiColumn/menus/ColumnsMenu.js.map +1 -1
- package/dist/src/fields/TiptapEditor/extensions/SlashCommand/MenuList.js.map +1 -1
- package/dist/src/fields/TiptapEditor/extensions/VideoBlock/VideoBlock.d.ts.map +1 -1
- package/dist/src/fields/TiptapEditor/extensions/VideoBlock/VideoBlock.js +1 -0
- package/dist/src/fields/TiptapEditor/extensions/VideoBlock/VideoBlock.js.map +1 -1
- package/dist/src/fields/TiptapEditor/extensions/VideoBlock/components/VideoBlockMenu.js.map +1 -1
- package/dist/src/fields/TiptapEditor/extensions/extension-kit.d.ts +1 -1
- package/dist/src/fields/TiptapEditor/features/BlockEditor/BlockEditor.d.ts +1 -2
- package/dist/src/fields/TiptapEditor/features/BlockEditor/BlockEditor.d.ts.map +1 -1
- package/dist/src/fields/TiptapEditor/features/BlockEditor/BlockEditor.js +54 -71
- package/dist/src/fields/TiptapEditor/features/BlockEditor/BlockEditor.js.map +1 -1
- package/dist/src/fields/TiptapEditor/features/menus/TextMenu/components/FontFamilyPicker.js.map +1 -1
- package/dist/src/fields/TiptapEditor/features/menus/TextMenu/components/FontSizePicker.js.map +1 -1
- package/dist/src/fields/TiptapEditor/features/panels/AICommandPanel/AICommandPanel.js.map +1 -1
- package/dist/src/fields/TiptapEditor/hooks/useBlockEditor.js.map +1 -1
- package/dist/src/fields/TiptapEditor/lib/extract.d.ts +3 -1
- package/dist/src/fields/TiptapEditor/lib/extract.d.ts.map +1 -1
- package/dist/src/fields/TiptapEditor/lib/extract.js +12 -0
- package/dist/src/fields/TiptapEditor/lib/extract.js.map +1 -1
- package/dist/src/fields/TiptapEditor/lib/utils/cssVar.js.map +1 -1
- package/dist/src/fields/TiptapEditor/lib/utils/isCustomNodeSelected.d.ts.map +1 -1
- package/dist/src/fields/TiptapEditor/lib/utils/isCustomNodeSelected.js +2 -7
- package/dist/src/fields/TiptapEditor/lib/utils/isCustomNodeSelected.js.map +1 -1
- package/dist/src/index.d.ts +1 -1
- package/dist/src/index.d.ts.map +1 -1
- package/dist/src/index.js +1 -1
- package/dist/src/index.js.map +1 -1
- package/dist/src/styles.css +2 -87
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +2 -2
- package/dist/src/fields/TiptapEditor/extensions/TableOfContentsNode/TableOfContentsNode.d.ts +0 -10
- package/dist/src/fields/TiptapEditor/extensions/TableOfContentsNode/TableOfContentsNode.d.ts.map +0 -1
- package/dist/src/fields/TiptapEditor/extensions/TableOfContentsNode/TableOfContentsNode.js +0 -55
- package/dist/src/fields/TiptapEditor/extensions/TableOfContentsNode/TableOfContentsNode.js.map +0 -1
- package/dist/src/fields/TiptapEditor/extensions/TableOfContentsNode/index.d.ts +0 -2
- package/dist/src/fields/TiptapEditor/extensions/TableOfContentsNode/index.d.ts.map +0 -1
- package/dist/src/fields/TiptapEditor/extensions/TableOfContentsNode/index.js +0 -3
- package/dist/src/fields/TiptapEditor/extensions/TableOfContentsNode/index.js.map +0 -1
- package/dist/src/fields/TiptapEditor/features/Sidebar/Sidebar.d.ts +0 -8
- package/dist/src/fields/TiptapEditor/features/Sidebar/Sidebar.d.ts.map +0 -1
- package/dist/src/fields/TiptapEditor/features/Sidebar/Sidebar.js +0 -32
- package/dist/src/fields/TiptapEditor/features/Sidebar/Sidebar.js.map +0 -1
- package/dist/src/fields/TiptapEditor/features/Sidebar/index.d.ts +0 -2
- package/dist/src/fields/TiptapEditor/features/Sidebar/index.d.ts.map +0 -1
- package/dist/src/fields/TiptapEditor/features/Sidebar/index.js +0 -3
- package/dist/src/fields/TiptapEditor/features/Sidebar/index.js.map +0 -1
- package/dist/src/fields/TiptapEditor/features/TableOfContents/TableOfContents.d.ts +0 -8
- package/dist/src/fields/TiptapEditor/features/TableOfContents/TableOfContents.d.ts.map +0 -1
- package/dist/src/fields/TiptapEditor/features/TableOfContents/TableOfContents.js +0 -57
- package/dist/src/fields/TiptapEditor/features/TableOfContents/TableOfContents.js.map +0 -1
- package/dist/src/fields/TiptapEditor/features/TableOfContents/index.d.ts +0 -2
- package/dist/src/fields/TiptapEditor/features/TableOfContents/index.d.ts.map +0 -1
- package/dist/src/fields/TiptapEditor/features/TableOfContents/index.js +0 -3
- package/dist/src/fields/TiptapEditor/features/TableOfContents/index.js.map +0 -1
|
@@ -1,18 +1,16 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
|
|
3
3
|
import { EditorContent } from "@tiptap/react";
|
|
4
|
-
import
|
|
4
|
+
import { useMemo, useRef } from "react";
|
|
5
5
|
import { EditorContext } from "../../context/EditorContext.js";
|
|
6
6
|
import { IframeMenu } from "../../extensions/Iframe/menus/index.js";
|
|
7
7
|
import ImageBlockMenu from "../../extensions/ImageBlock/components/ImageBlockMenu.js";
|
|
8
8
|
import { InsideLinksMenu } from "../../extensions/InsideLinks/menus/index.js";
|
|
9
9
|
import { ColumnsMenu } from "../../extensions/MultiColumn/menus/ColumnsMenu.js";
|
|
10
10
|
import { SocialMediaMenu } from "../../extensions/SocialMedia/menus/index.js";
|
|
11
|
-
import { TableColumnMenu, TableRowMenu } from "../../extensions/Table/menus/index.js";
|
|
12
11
|
import VideoBlockMenu from "../../extensions/VideoBlock/components/VideoBlockMenu.js";
|
|
13
12
|
import { useBlockEditor } from "../../hooks/useBlockEditor.js";
|
|
14
13
|
import { isRTL } from "../../lib/utils/isRtl.js";
|
|
15
|
-
import { Sidebar } from "../Sidebar/Sidebar.js";
|
|
16
14
|
import { ContentItemMenu } from "../menus/ContentItemMenu/ContentItemMenu.js";
|
|
17
15
|
import { TextMenu } from "../menus/TextMenu/TextMenu.js";
|
|
18
16
|
import { LinkMenu } from "../menus/index.js";
|
|
@@ -33,77 +31,62 @@ export const BlockEditor = ({ handleChange, content, openAssetHQHandler, additio
|
|
|
33
31
|
}, []);
|
|
34
32
|
return editor && /*#__PURE__*/ _jsx(EditorContext.Provider, {
|
|
35
33
|
value: providerValue,
|
|
36
|
-
children: /*#__PURE__*/
|
|
34
|
+
children: /*#__PURE__*/ _jsx("div", {
|
|
37
35
|
className: "flex h-full overflow-visible",
|
|
38
36
|
ref: menuContainerRef,
|
|
39
37
|
dir: dir ?? (isRTL(editor.getText()) ? "rtl" : "ltr"),
|
|
40
|
-
children:
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
appendTo: menuContainerRef
|
|
93
|
-
}),
|
|
94
|
-
/*#__PURE__*/ _jsx(ImageBlockMenu, {
|
|
95
|
-
editor: editor,
|
|
96
|
-
appendTo: menuContainerRef
|
|
97
|
-
}),
|
|
98
|
-
/*#__PURE__*/ _jsx(VideoBlockMenu, {
|
|
99
|
-
editor: editor,
|
|
100
|
-
appendTo: menuContainerRef
|
|
101
|
-
})
|
|
102
|
-
]
|
|
103
|
-
})
|
|
104
|
-
]
|
|
105
|
-
})
|
|
106
|
-
]
|
|
38
|
+
children: /*#__PURE__*/ _jsxs("div", {
|
|
39
|
+
className: "relative flex flex-col flex-1 h-full justify-center items-center ",
|
|
40
|
+
children: [
|
|
41
|
+
/*#__PURE__*/ _jsx(EditorContent, {
|
|
42
|
+
editor: editor,
|
|
43
|
+
ref: editorRef,
|
|
44
|
+
className: "flex-1 overflow-y-visible w-full h-full outline-none outline-offset-0",
|
|
45
|
+
style: {
|
|
46
|
+
outline: "none"
|
|
47
|
+
}
|
|
48
|
+
}),
|
|
49
|
+
isEditable && /*#__PURE__*/ _jsxs(_Fragment, {
|
|
50
|
+
children: [
|
|
51
|
+
/*#__PURE__*/ _jsx(ContentItemMenu, {
|
|
52
|
+
editor: editor
|
|
53
|
+
}),
|
|
54
|
+
/*#__PURE__*/ _jsx(LinkMenu, {
|
|
55
|
+
editor: editor,
|
|
56
|
+
appendTo: menuContainerRef
|
|
57
|
+
}),
|
|
58
|
+
/*#__PURE__*/ _jsx(TextMenu, {
|
|
59
|
+
editor: editor,
|
|
60
|
+
dir: dir ?? (isRTL(editor.getText()) ? "rtl" : "ltr")
|
|
61
|
+
}),
|
|
62
|
+
/*#__PURE__*/ _jsx(IframeMenu, {
|
|
63
|
+
editor: editor,
|
|
64
|
+
appendTo: menuContainerRef
|
|
65
|
+
}),
|
|
66
|
+
/*#__PURE__*/ _jsx(SocialMediaMenu, {
|
|
67
|
+
editor: editor,
|
|
68
|
+
appendTo: menuContainerRef
|
|
69
|
+
}),
|
|
70
|
+
/*#__PURE__*/ _jsx(InsideLinksMenu, {
|
|
71
|
+
editor: editor,
|
|
72
|
+
appendTo: menuContainerRef
|
|
73
|
+
}),
|
|
74
|
+
/*#__PURE__*/ _jsx(ColumnsMenu, {
|
|
75
|
+
editor: editor,
|
|
76
|
+
appendTo: menuContainerRef
|
|
77
|
+
}),
|
|
78
|
+
/*#__PURE__*/ _jsx(ImageBlockMenu, {
|
|
79
|
+
editor: editor,
|
|
80
|
+
appendTo: menuContainerRef
|
|
81
|
+
}),
|
|
82
|
+
/*#__PURE__*/ _jsx(VideoBlockMenu, {
|
|
83
|
+
editor: editor,
|
|
84
|
+
appendTo: menuContainerRef
|
|
85
|
+
})
|
|
86
|
+
]
|
|
87
|
+
})
|
|
88
|
+
]
|
|
89
|
+
})
|
|
107
90
|
})
|
|
108
91
|
});
|
|
109
92
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../../../src/fields/TiptapEditor/features/BlockEditor/BlockEditor.tsx"],"sourcesContent":["\"use client\";\nimport { EditorContent } from \"@tiptap/react\";\nimport
|
|
1
|
+
{"version":3,"sources":["../../../../../../src/fields/TiptapEditor/features/BlockEditor/BlockEditor.tsx"],"sourcesContent":["\"use client\";\nimport { EditorContent } from \"@tiptap/react\";\nimport { useMemo, useRef } from \"react\";\n\nimport { EditorContext } from \"../../context/EditorContext.js\";\nimport { IframeMenu } from \"../../extensions/Iframe/menus/index.js\";\nimport ImageBlockMenu from \"../../extensions/ImageBlock/components/ImageBlockMenu.js\";\nimport { InsideLinksMenu } from \"../../extensions/InsideLinks/menus/index.js\";\nimport { ColumnsMenu } from \"../../extensions/MultiColumn/menus/ColumnsMenu.js\";\nimport { SocialMediaMenu } from \"../../extensions/SocialMedia/menus/index.js\";\n\nimport VideoBlockMenu from \"../../extensions/VideoBlock/components/VideoBlockMenu.js\";\nimport { useBlockEditor } from \"../../hooks/useBlockEditor.js\";\nimport { isRTL } from \"../../lib/utils/isRtl.js\";\nimport { openAssetHQType } from \"../../types.js\";\nimport { ContentItemMenu } from \"../menus/ContentItemMenu/ContentItemMenu.js\";\nimport { TextMenu } from \"../menus/TextMenu/TextMenu.js\";\nimport { LinkMenu } from \"../menus/index.js\";\nimport { TiptapProps } from \"./types.js\";\nexport const BlockEditor = ({\n handleChange,\n content,\n openAssetHQHandler,\n additionalContext,\n isEditable = true,\n autoFocus = true,\n dir,\n}: TiptapProps & {\n openAssetHQHandler?: openAssetHQType;\n additionalContext?: Record<string, any>;\n autoFocus?: boolean;\n isEditable?: boolean;\n dir?: \"ltr\" | \"rtl\" | \"auto\";\n}) => {\n const menuContainerRef = useRef(null);\n const editorRef = useRef<HTMLDivElement>(null);\n\n const { editor, users, characterCount, leftSidebar } = useBlockEditor({\n content: content,\n handleChange: handleChange,\n openAssetHQHandler: openAssetHQHandler,\n additionalContext: additionalContext,\n autoFocus,\n isEditable,\n });\n\n const displayedUsers = users.slice(0, 3);\n const providerValue = useMemo(() => {\n return {};\n }, []);\n\n return (\n editor && (\n <EditorContext.Provider value={providerValue}>\n <div\n className=\"flex h-full overflow-visible\"\n ref={menuContainerRef}\n dir={dir ?? (isRTL(editor.getText()) ? \"rtl\" : \"ltr\")}\n >\n <div className=\"relative flex flex-col flex-1 h-full justify-center items-center \">\n <EditorContent\n editor={editor}\n ref={editorRef}\n className=\"flex-1 overflow-y-visible w-full h-full outline-none outline-offset-0\"\n style={{\n outline: \"none\",\n }}\n />\n {isEditable && (\n <>\n <ContentItemMenu editor={editor} />\n <LinkMenu editor={editor} appendTo={menuContainerRef} />\n <TextMenu\n editor={editor}\n dir={dir ?? (isRTL(editor.getText()) ? \"rtl\" : \"ltr\")}\n />\n <IframeMenu editor={editor} appendTo={menuContainerRef} />\n <SocialMediaMenu editor={editor} appendTo={menuContainerRef} />\n <InsideLinksMenu editor={editor} appendTo={menuContainerRef} />\n <ColumnsMenu editor={editor} appendTo={menuContainerRef} />\n <ImageBlockMenu editor={editor} appendTo={menuContainerRef} />\n <VideoBlockMenu editor={editor} appendTo={menuContainerRef} />\n </>\n )}\n </div>\n </div>\n </EditorContext.Provider>\n )\n );\n};\n\nexport default BlockEditor;\n"],"names":["EditorContent","useMemo","useRef","EditorContext","IframeMenu","ImageBlockMenu","InsideLinksMenu","ColumnsMenu","SocialMediaMenu","VideoBlockMenu","useBlockEditor","isRTL","ContentItemMenu","TextMenu","LinkMenu","BlockEditor","handleChange","content","openAssetHQHandler","additionalContext","isEditable","autoFocus","dir","menuContainerRef","editorRef","editor","users","characterCount","leftSidebar","displayedUsers","slice","providerValue","Provider","value","div","className","ref","getText","style","outline","appendTo"],"mappings":"AAAA;;AACA,SAASA,aAAa,QAAQ,gBAAgB;AAC9C,SAASC,OAAO,EAAEC,MAAM,QAAQ,QAAQ;AAExC,SAASC,aAAa,QAAQ,iCAAiC;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CAAQe,UAAUjB;;0CACpC,KAACV;gCACCY,QAAQA;gCACRH,KAAKA,OAAQX,CAAAA,MAAMc,OAAOY,OAAO,MAAM,QAAQ,KAAI;;0CAErD,KAACjC;gCAAWqB,QAAQA;gCAAQe,UAAUjB;;0CACtC,KAACf;gCAAgBiB,QAAQA;gCAAQe,UAAUjB;;0CAC3C,KAACjB;gCAAgBmB,QAAQA;gCAAQe,UAAUjB;;0CAC3C,KAAChB;gCAAYkB,QAAQA;gCAAQe,UAAUjB;;0CACvC,KAAClB;gCAAeoB,QAAQA;gCAAQe,UAAUjB;;0CAC1C,KAACd;gCAAegB,QAAQA;gCAAQe,UAAUjB;;;;;;;;AAQ1D,EAAE;AAEF,eAAeR,YAAY"}
|
package/dist/src/fields/TiptapEditor/features/menus/TextMenu/components/FontFamilyPicker.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../../../../../src/fields/TiptapEditor/features/menus/TextMenu/components/FontFamilyPicker.tsx"],"sourcesContent":["import * as Dropdown from \"@radix-ui/react-dropdown-menu\";\nimport { ChevronDown } from \"lucide-react\";\nimport { useCallback } from \"react\";\nimport {\n DropdownButton,\n DropdownCategoryTitle,\n} from \"../../../ui/Dropdown/Dropdown.js\";\nimport { Icon } from \"../../../ui/Icon.js\";\nimport { Surface } from \"../../../ui/Surface.js\";\nimport { Toolbar } from \"../../../ui/Toolbar.js\";\n\nconst FONT_FAMILY_GROUPS = [\n {\n label: \"Sans Serif\",\n options: [\n { label: \"Inter\", value: \"\" },\n { label: \"Arial\", value: \"Arial\" },\n { label: \"Helvetica\", value: \"Helvetica\" },\n ],\n },\n {\n label: \"Serif\",\n options: [\n { label: \"Times New Roman\", value: \"Times\" },\n { label: \"Garamond\", value: \"Garamond\" },\n { label: \"Georgia\", value: \"Georgia\" },\n ],\n },\n {\n label: \"Monospace\",\n options: [\n { label: \"Courier\", value: \"Courier\" },\n { label: \"Courier New\", value: \"Courier New\" },\n ],\n },\n];\n\nconst FONT_FAMILIES = FONT_FAMILY_GROUPS.flatMap((group) => [\n group.options,\n]).flat();\n\nexport type FontFamilyPickerProps = {\n onChange: (value: string) => void; // eslint-disable-line no-unused-vars\n value: string;\n};\n\nexport const FontFamilyPicker = ({\n onChange,\n value,\n}: FontFamilyPickerProps) => {\n const currentValue = FONT_FAMILIES.find((size) => size.value === value);\n const currentFontLabel = currentValue?.label.split(\" \")[0] || \"Inter\";\n\n const selectFont = useCallback(\n (font: string) => () => onChange(font),\n [onChange]\n );\n\n return (\n <Dropdown.Root>\n <Dropdown.Trigger asChild>\n <Toolbar.Button type=\"button\" active={!!currentValue?.value}>\n {currentFontLabel}\n <Icon icon={ChevronDown} className=\"w-2 h-2\" />\n </Toolbar.Button>\n </Dropdown.Trigger>\n <Dropdown.Content asChild>\n <Surface className=\"flex flex-col gap-1 px-2 py-4\">\n {FONT_FAMILY_GROUPS.map((group) => (\n <div\n className=\"mt-2.5 first:mt-0 gap-0.5 flex flex-col\"\n key={group.label}\n >\n <DropdownCategoryTitle>{group.label}</DropdownCategoryTitle>\n {group.options.map((font) => (\n <DropdownButton\n isActive={value === font.value}\n onClick={selectFont(font.value)}\n key={`${font.label}_${font.value}`}\n >\n <span style={{ fontFamily: font.value }}>{font.label}</span>\n </DropdownButton>\n ))}\n </div>\n ))}\n </Surface>\n </Dropdown.Content>\n </Dropdown.Root>\n );\n};\n"],"names":["Dropdown","ChevronDown","useCallback","DropdownButton","DropdownCategoryTitle","Icon","Surface","Toolbar","FONT_FAMILY_GROUPS","label","options","value","FONT_FAMILIES","flatMap","group","flat","FontFamilyPicker","onChange","currentValue","find","size","currentFontLabel","split","selectFont","font","Root","Trigger","asChild","Button","type","active","icon","className","Content","map","div","isActive","onClick","span","style","fontFamily"],"mappings":";AAAA,YAAYA,cAAc,gCAAgC;AAC1D,SAASC,WAAW,QAAQ,eAAe;AAC3C,SAASC,WAAW,QAAQ,QAAQ;AACpC,SACEC,cAAc,EACdC,qBAAqB,QAChB,mCAA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AA,KAACrB;oBAAQ0B,WAAU;8BAChBxB,mBAAmB0B,GAAG,CAAC,CAACpB,sBACvB,MAACqB;4BACCH,WAAU;;8CAGV,KAAC5B;8CAAuBU,MAAML,KAAK;;gCAClCK,MAAMJ,OAAO,CAACwB,GAAG,CAAC,CAACV,qBAClB,KAACrB;wCACCiC,UAAUzB,UAAUa,KAAKb,KAAK;wCAC9B0B,SAASd,WAAWC,KAAKb,KAAK;kDAG9B,cAAA,KAAC2B;4CAAKC,OAAO;gDAAEC,YAAYhB,KAAKb,KAAK;4CAAC;sDAAIa,KAAKf,KAAK;;uCAF/C,
|
|
1
|
+
{"version":3,"sources":["../../../../../../../../src/fields/TiptapEditor/features/menus/TextMenu/components/FontFamilyPicker.tsx"],"sourcesContent":["import * as Dropdown from \"@radix-ui/react-dropdown-menu\";\nimport { ChevronDown } from \"lucide-react\";\nimport { useCallback } from \"react\";\nimport {\n DropdownButton,\n DropdownCategoryTitle,\n} from \"../../../ui/Dropdown/Dropdown.js\";\nimport { Icon } from \"../../../ui/Icon.js\";\nimport { Surface } from \"../../../ui/Surface.js\";\nimport { Toolbar } from \"../../../ui/Toolbar.js\";\n\nconst FONT_FAMILY_GROUPS = [\n {\n label: \"Sans Serif\",\n options: [\n { label: \"Inter\", value: \"\" },\n { label: \"Arial\", value: \"Arial\" },\n { label: \"Helvetica\", value: \"Helvetica\" },\n ],\n },\n {\n label: \"Serif\",\n options: [\n { label: \"Times New Roman\", value: \"Times\" },\n { label: \"Garamond\", value: \"Garamond\" },\n { label: \"Georgia\", value: \"Georgia\" },\n ],\n },\n {\n label: \"Monospace\",\n options: [\n { label: \"Courier\", value: \"Courier\" },\n { label: \"Courier New\", value: \"Courier New\" },\n ],\n },\n];\n\nconst FONT_FAMILIES = FONT_FAMILY_GROUPS.flatMap((group) => [\n group.options,\n]).flat();\n\nexport type FontFamilyPickerProps = {\n onChange: (value: string) => void; // eslint-disable-line no-unused-vars\n value: string;\n};\n\nexport const FontFamilyPicker = ({\n onChange,\n value,\n}: FontFamilyPickerProps) => {\n const currentValue = FONT_FAMILIES.find((size) => size.value === value);\n const currentFontLabel = currentValue?.label.split(\" \")[0] || \"Inter\";\n\n const selectFont = useCallback(\n (font: string) => () => onChange(font),\n [onChange]\n );\n\n return (\n <Dropdown.Root>\n <Dropdown.Trigger asChild>\n <Toolbar.Button type=\"button\" active={!!currentValue?.value}>\n {currentFontLabel}\n <Icon icon={ChevronDown} className=\"w-2 h-2\" />\n </Toolbar.Button>\n </Dropdown.Trigger>\n <Dropdown.Content asChild>\n <Surface className=\"flex flex-col gap-1 px-2 py-4\">\n {FONT_FAMILY_GROUPS.map((group) => (\n <div\n className=\"mt-2.5 first:mt-0 gap-0.5 flex flex-col\"\n key={group.label}\n >\n <DropdownCategoryTitle>{group.label}</DropdownCategoryTitle>\n {group.options.map((font) => (\n <DropdownButton\n isActive={value === font.value}\n onClick={selectFont(font.value)}\n key={`${font.label}_${font.value}`}\n >\n <span style={{ fontFamily: font.value }}>{font.label}</span>\n </DropdownButton>\n ))}\n </div>\n ))}\n </Surface>\n </Dropdown.Content>\n </Dropdown.Root>\n );\n};\n"],"names":["Dropdown","ChevronDown","useCallback","DropdownButton","DropdownCategoryTitle","Icon","Surface","Toolbar","FONT_FAMILY_GROUPS","label","options","value","FONT_FAMILIES","flatMap","group","flat","FontFamilyPicker","onChange","currentValue","find","size","currentFontLabel","split","selectFont","font","Root","Trigger","asChild","Button","type","active","icon","className","Content","map","div","isActive","onClick","span","style","fontFamily"],"mappings":";AAAA,YAAYA,cAAc,gCAAgC;AAC1D,SAASC,WAAW,QAAQ,eAAe;AAC3C,SAASC,WAAW,QAAQ,QAAQ;AACpC,SACEC,cAAc,EACdC,qBAAqB,QAChB,mCAAmC;AAC1C,SAASC,IAAI,QAAQ,sBAAsB;AAC3C,SAASC,OAAO,QAAQ,yBAAyB;AACjD,SAASC,OAAO,QAAQ,yBAAyB;AAEjD,MAAMC,qBAAqB;IACzB;QACEC,OAAO;QACPC,SAAS;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ACwB,GAAG,CAAC,CAACV,qBAClB,KAACrB;wCACCiC,UAAUzB,UAAUa,KAAKb,KAAK;wCAC9B0B,SAASd,WAAWC,KAAKb,KAAK;kDAG9B,cAAA,KAAC2B;4CAAKC,OAAO;gDAAEC,YAAYhB,KAAKb,KAAK;4CAAC;sDAAIa,KAAKf,KAAK;;uCAF/C,GAAGe,KAAKf,KAAK,CAAC,CAAC,EAAEe,KAAKb,KAAK,EAAE;;2BAPjCG,MAAML,KAAK;;;;;AAkB9B,EAAE"}
|
package/dist/src/fields/TiptapEditor/features/menus/TextMenu/components/FontSizePicker.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../../../../../src/fields/TiptapEditor/features/menus/TextMenu/components/FontSizePicker.tsx"],"sourcesContent":["import * as Dropdown from \"@radix-ui/react-dropdown-menu\";\nimport { ChevronDown } from \"lucide-react\";\nimport { useCallback } from \"react\";\nimport { DropdownButton } from \"../../../ui/Dropdown/Dropdown.js\";\nimport { Icon } from \"../../../ui/Icon.js\";\nimport { Surface } from \"../../../ui/Surface.js\";\nimport { Toolbar } from \"../../../ui/Toolbar.js\";\n\nconst FONT_SIZES = [\n { label: \"Smaller\", value: \"12px\" },\n { label: \"Small\", value: \"14px\" },\n { label: \"Medium\", value: \"\" },\n { label: \"Large\", value: \"18px\" },\n { label: \"Extra Large\", value: \"24px\" },\n];\n\nexport type FontSizePickerProps = {\n onChange: (value: string) => void; // eslint-disable-line no-unused-vars\n value: string;\n};\n\nexport const FontSizePicker = ({ onChange, value }: FontSizePickerProps) => {\n const currentValue = FONT_SIZES.find((size) => size.value === value);\n const currentSizeLabel = currentValue?.label.split(\" \")[0] || \"Medium\";\n\n const selectSize = useCallback(\n (size: string) => () => onChange(size),\n [onChange]\n );\n\n return (\n <Dropdown.Root>\n <Dropdown.Trigger asChild>\n <Toolbar.Button type=\"button\" active={!!currentValue?.value}>\n {currentSizeLabel}\n <Icon icon={ChevronDown} className=\"w-2 h-2\" />\n </Toolbar.Button>\n </Dropdown.Trigger>\n <Dropdown.Content asChild>\n <Surface className=\"flex flex-col gap-1 px-2 py-4\">\n {FONT_SIZES.map((size) => (\n <DropdownButton\n isActive={value === size.value}\n onClick={selectSize(size.value)}\n key={`${size.label}_${size.value}`}\n >\n <span style={{ fontSize: size.value }}>{size.label}</span>\n </DropdownButton>\n ))}\n </Surface>\n </Dropdown.Content>\n </Dropdown.Root>\n );\n};\n"],"names":["Dropdown","ChevronDown","useCallback","DropdownButton","Icon","Surface","Toolbar","FONT_SIZES","label","value","FontSizePicker","onChange","currentValue","find","size","currentSizeLabel","split","selectSize","Root","Trigger","asChild","Button","type","active","icon","className","Content","map","isActive","onClick","span","style","fontSize"],"mappings":";AAAA,YAAYA,cAAc,gCAAgC;AAC1D,SAASC,WAAW,QAAQ,eAAe;AAC3C,SAASC,WAAW,QAAQ,QAAQ;AACpC,SAASC,cAAc,QAAQ,mCAAmC;AAClE,SAASC,IAAI,QAAQ,sBAAsB;AAC3C,SAASC,OAAO,QAAQ,yBAAyB;AACjD,SAASC,OAAO,QAAQ,yBAAyB;AAEjD,MAAMC,aAAa;IACjB;QAAEC,OAAO;QAAWC,OAAO;IAAO;IAClC;QAAED,OAAO;QAASC,OAAO;IAAO;IAChC;QAAED,OAAO;QAAUC,OAAO;IAAG;IAC7B;QAAED,OAAO;QAASC,OAAO;IAAO;IAChC;QAAED,OAAO;QAAeC,OAAO;IAAO;CACvC;AAOD,OAAO,MAAMC,iBAAiB,CAAC,EAAEC,QAAQ,EAAEF,KAAK,EAAuB;IACrE,MAAMG,eAAeL,WAAWM,IAAI,CAAC,CAACC,OAASA,KAAKL,KAAK,KAAKA;IAC9D,MAAMM,mBAAmBH,cAAcJ,MAAMQ,MAAM,IAAI,CAAC,EAAE,IAAI;IAE9D,MAAMC,aAAaf,YACjB,CAACY,OAAiB,IAAMH,SAASG,OACjC;QAACH;KAAS;IAGZ,qBACE,MAACX,SAASkB,IAAI;;0BACZ,KAAClB,SAASmB,OAAO;gBAACC,OAAO;0BACvB,cAAA,MAACd,QAAQe,MAAM;oBAACC,MAAK;oBAASC,QAAQ,CAAC,CAACX,cAAcH;;wBACnDM;sCACD,KAACX;4BAAKoB,MAAMvB;4BAAawB,WAAU;;;;;0BAGvC,KAACzB,SAAS0B,OAAO;gBAACN,OAAO;0BACvB,cAAA,KAACf;oBAAQoB,WAAU;8BAChBlB,WAAWoB,GAAG,CAAC,CAACb,qBACf,KAACX;4BACCyB,UAAUnB,UAAUK,KAAKL,KAAK;4BAC9BoB,SAASZ,WAAWH,KAAKL,KAAK;sCAG9B,cAAA,KAACqB;gCAAKC,OAAO;oCAAEC,UAAUlB,KAAKL,KAAK;gCAAC;0CAAIK,KAAKN,KAAK;;2BAF7C,
|
|
1
|
+
{"version":3,"sources":["../../../../../../../../src/fields/TiptapEditor/features/menus/TextMenu/components/FontSizePicker.tsx"],"sourcesContent":["import * as Dropdown from \"@radix-ui/react-dropdown-menu\";\nimport { ChevronDown } from \"lucide-react\";\nimport { useCallback } from \"react\";\nimport { DropdownButton } from \"../../../ui/Dropdown/Dropdown.js\";\nimport { Icon } from \"../../../ui/Icon.js\";\nimport { Surface } from \"../../../ui/Surface.js\";\nimport { Toolbar } from \"../../../ui/Toolbar.js\";\n\nconst FONT_SIZES = [\n { label: \"Smaller\", value: \"12px\" },\n { label: \"Small\", value: \"14px\" },\n { label: \"Medium\", value: \"\" },\n { label: \"Large\", value: \"18px\" },\n { label: \"Extra Large\", value: \"24px\" },\n];\n\nexport type FontSizePickerProps = {\n onChange: (value: string) => void; // eslint-disable-line no-unused-vars\n value: string;\n};\n\nexport const FontSizePicker = ({ onChange, value }: FontSizePickerProps) => {\n const currentValue = FONT_SIZES.find((size) => size.value === value);\n const currentSizeLabel = currentValue?.label.split(\" \")[0] || \"Medium\";\n\n const selectSize = useCallback(\n (size: string) => () => onChange(size),\n [onChange]\n );\n\n return (\n <Dropdown.Root>\n <Dropdown.Trigger asChild>\n <Toolbar.Button type=\"button\" active={!!currentValue?.value}>\n {currentSizeLabel}\n <Icon icon={ChevronDown} className=\"w-2 h-2\" />\n </Toolbar.Button>\n </Dropdown.Trigger>\n <Dropdown.Content asChild>\n <Surface className=\"flex flex-col gap-1 px-2 py-4\">\n {FONT_SIZES.map((size) => (\n <DropdownButton\n isActive={value === size.value}\n onClick={selectSize(size.value)}\n key={`${size.label}_${size.value}`}\n >\n <span style={{ fontSize: size.value }}>{size.label}</span>\n </DropdownButton>\n ))}\n </Surface>\n </Dropdown.Content>\n </Dropdown.Root>\n );\n};\n"],"names":["Dropdown","ChevronDown","useCallback","DropdownButton","Icon","Surface","Toolbar","FONT_SIZES","label","value","FontSizePicker","onChange","currentValue","find","size","currentSizeLabel","split","selectSize","Root","Trigger","asChild","Button","type","active","icon","className","Content","map","isActive","onClick","span","style","fontSize"],"mappings":";AAAA,YAAYA,cAAc,gCAAgC;AAC1D,SAASC,WAAW,QAAQ,eAAe;AAC3C,SAASC,WAAW,QAAQ,QAAQ;AACpC,SAASC,cAAc,QAAQ,mCAAmC;AAClE,SAASC,IAAI,QAAQ,sBAAsB;AAC3C,SAASC,OAAO,QAAQ,yBAAyB;AACjD,SAASC,OAAO,QAAQ,yBAAyB;AAEjD,MAAMC,aAAa;IACjB;QAAEC,OAAO;QAAWC,OAAO;IAAO;IAClC;QAAED,OAAO;QAASC,OAAO;IAAO;IAChC;QAAED,OAAO;QAAUC,OAAO;IAAG;IAC7B;QAAED,OAAO;QAASC,OAAO;IAAO;IAChC;QAAED,OAAO;QAAeC,OAAO;IAAO;CACvC;AAOD,OAAO,MAAMC,iBAAiB,CAAC,EAAEC,QAAQ,EAAEF,KAAK,EAAuB;IACrE,MAAMG,eAAeL,WAAWM,IAAI,CAAC,CAACC,OAASA,KAAKL,KAAK,KAAKA;IAC9D,MAAMM,mBAAmBH,cAAcJ,MAAMQ,MAAM,IAAI,CAAC,EAAE,IAAI;IAE9D,MAAMC,aAAaf,YACjB,CAACY,OAAiB,IAAMH,SAASG,OACjC;QAACH;KAAS;IAGZ,qBACE,MAACX,SAASkB,IAAI;;0BACZ,KAAClB,SAASmB,OAAO;gBAACC,OAAO;0BACvB,cAAA,MAACd,QAAQe,MAAM;oBAACC,MAAK;oBAASC,QAAQ,CAAC,CAACX,cAAcH;;wBACnDM;sCACD,KAACX;4BAAKoB,MAAMvB;4BAAawB,WAAU;;;;;0BAGvC,KAACzB,SAAS0B,OAAO;gBAACN,OAAO;0BACvB,cAAA,KAACf;oBAAQoB,WAAU;8BAChBlB,WAAWoB,GAAG,CAAC,CAACb,qBACf,KAACX;4BACCyB,UAAUnB,UAAUK,KAAKL,KAAK;4BAC9BoB,SAASZ,WAAWH,KAAKL,KAAK;sCAG9B,cAAA,KAACqB;gCAAKC,OAAO;oCAAEC,UAAUlB,KAAKL,KAAK;gCAAC;0CAAIK,KAAKN,KAAK;;2BAF7C,GAAGM,KAAKN,KAAK,CAAC,CAAC,EAAEM,KAAKL,KAAK,EAAE;;;;;AAShD,EAAE"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../../../../src/fields/TiptapEditor/features/panels/AICommandPanel/AICommandPanel.tsx"],"sourcesContent":["\"use client\";\n\nimport { useCompletion } from \"ai/react\";\nimport { ArrowUpCircle, Sparkles } from \"lucide-react\";\nimport React, {\n forwardRef,\n useCallback,\n useEffect,\n useImperativeHandle,\n useRef,\n useState,\n} from \"react\";\nimport Markdown from \"react-markdown\";\nimport TextareaAutosize from \"react-textarea-autosize\";\n\nimport { useLocale } from \"@payloadcms/ui/providers/Locale\";\nimport { Editor } from \"@tiptap/react\";\n\nimport {\n Command,\n Group,\n} from \"src/fields/TiptapEditor/extensions/AICommand/types.js\";\nimport { getPrevText } from \"../../../lib/utils/index.js\";\nimport { isRTL } from \"../../../lib/utils/isRtl.js\";\nimport CrazySpinner from \"../../ui/crazy-spinner.js\";\nimport { DropdownButton } from \"../../ui/Dropdown/Dropdown.js\";\nimport { Icon } from \"../../ui/Icon.js\";\nimport { ScrollArea } from \"../../ui/scroll-area.js\";\nimport { Surface } from \"../../ui/Surface.js\";\nimport { Toolbar } from \"../../ui/Toolbar.js\";\nimport AISelectorCommands from \"../../menus/TextMenu/components/ai-selector-commands.js\";\n\nexport type AICommandPanelProps = {\n editor: Editor;\n userPrompt?: string;\n onOpenChange: (value: boolean) => void;\n items: Group[];\n};\n\nexport const AICommandPanel = forwardRef(\n (\n {\n editor,\n onOpenChange,\n userPrompt,\n items,\n ...restProps\n }: AICommandPanelProps,\n ref\n ) => {\n const [inputValue, setInputValue] = useState(userPrompt ?? \"\");\n const { code } = useLocale();\n const { view } = editor;\n const scrollContainer = useRef<HTMLDivElement>(null);\n const activeItem = useRef<HTMLButtonElement>(null);\n const [selectedGroupIndex, setSelectedGroupIndex] = useState(0);\n const [selectedCommandIndex, setSelectedCommandIndex] = useState(0);\n\n const editorNode = view.dom as HTMLElement;\n const boundigClient = editorNode.getBoundingClientRect();\n const inputRef = useRef<HTMLTextAreaElement>(null);\n\n // const { status, messages, input, submitMessage, handleInputChange } = useAssistant({\n // // id: \"novel\",\n // api: \"/api/assistant\",\n // onResponse: (response) => {\n // if (response.status === 429) {\n // toast.error(\"You have reached your request limit for the day.\");\n // return;\n // }\n // },\n // onError: (e) => {\n // toast.error(e.message);\n // },\n // });\n\n const { completion, complete, isLoading } = useCompletion({\n // id: \"novel\",\n api: \"/api/generate\",\n onResponse: (response) => {\n if (response.status === 429) {\n console.log(\"You have reached your request limit for the day.\");\n\n return;\n }\n },\n\n onError: (e) => {\n console.log(\"ERROR\", e.message);\n },\n });\n\n const hasCompletion = completion.length > 0;\n const handleClick = useCallback(() => {\n if (completion) {\n return complete(completion, {\n body: { option: \"zap\", command: inputValue, language: code ?? \"en\" },\n }).then(() => setInputValue(\"\"));\n }\n const text = getPrevText(editor, { chars: 5000 });\n\n complete(text, {\n body: {\n option: \"zap\",\n command:\n (editor.storage.aiCommand.title\n ? \"Context Title:\" + editor.storage.aiCommand.title + \";\\n\"\n : \"\") +\n (editor.storage.aiCommand.language\n ? \"Context language:\" + editor.storage.aiCommand.language + \";\\n\"\n : \"\") +\n inputValue,\n language: editor.storage.aiCommand.language ?? code ?? \"en\",\n },\n }).then(() => setInputValue(\"\"));\n }, [code, inputValue]);\n\n useEffect(() => {\n if (userPrompt) setInputValue(userPrompt);\n }, [userPrompt]);\n useEffect(() => {\n editor.storage.aiCommand.completion = completion;\n // if (!isLoading && completion) {\n // const selection = editor.state.selection;\n // editor\n // .chain()\n // .focus()\n // .insertContentAt(selection.to - 1, completion)\n // .insertContentAt(selection.to, \" \")\n // .run();\n\n // }\n }, [completion, isLoading]);\n\n // Anytime the groups change, i.e. the user types to narrow it down, we want to\n // reset the current selection to the first menu item\n useEffect(() => {\n setSelectedGroupIndex(0);\n setSelectedCommandIndex(0);\n }, [items]);\n\n const selectItem = useCallback(\n (groupIndex: number, commandIndex: number) => {\n const command = items[groupIndex].commands[commandIndex];\n\n setInputValue(command.action(editor));\n // props.command(command);\n },\n [items, editor]\n );\n\n useImperativeHandle(ref, () => ({\n onKeyDown: ({ event }: { event: React.KeyboardEvent }) => {\n if (event.key === \"ArrowDown\") {\n if (!items.length) {\n return false;\n }\n\n const commands = items[selectedGroupIndex].commands;\n\n let newCommandIndex = selectedCommandIndex + 1;\n let newGroupIndex = selectedGroupIndex;\n\n if (commands.length - 1 < newCommandIndex) {\n newCommandIndex = 0;\n newGroupIndex = selectedGroupIndex + 1;\n }\n\n if (items.length - 1 < newGroupIndex) {\n newGroupIndex = 0;\n }\n\n setSelectedCommandIndex(newCommandIndex);\n setSelectedGroupIndex(newGroupIndex);\n\n return true;\n }\n\n if (event.key === \"ArrowUp\") {\n if (!items.length) {\n return false;\n }\n\n let newCommandIndex = selectedCommandIndex - 1;\n let newGroupIndex = selectedGroupIndex;\n\n if (newCommandIndex < 0) {\n newGroupIndex = selectedGroupIndex - 1;\n newCommandIndex = items[newGroupIndex]?.commands.length - 1 || 0;\n }\n\n if (newGroupIndex < 0) {\n newGroupIndex = items.length - 1;\n newCommandIndex = items[newGroupIndex].commands.length - 1;\n }\n\n setSelectedCommandIndex(newCommandIndex);\n setSelectedGroupIndex(newGroupIndex);\n\n return true;\n }\n\n if (event.key === \"Enter\") {\n if (\n !items.length ||\n selectedGroupIndex === -1 ||\n selectedCommandIndex === -1\n ) {\n return false;\n }\n\n selectItem(selectedGroupIndex, selectedCommandIndex);\n\n return true;\n }\n\n return false;\n },\n }));\n\n useEffect(() => {\n if (activeItem.current && scrollContainer.current) {\n const offsetTop = activeItem.current.offsetTop;\n const offsetHeight = activeItem.current.offsetHeight;\n\n scrollContainer.current.scrollTop = offsetTop - offsetHeight;\n }\n }, [selectedCommandIndex, selectedGroupIndex]);\n\n const createCommandClickHandler = useCallback(\n (groupIndex: number, commandIndex: number) => {\n return () => {\n selectItem(groupIndex, commandIndex);\n };\n },\n [selectItem]\n );\n\n return (\n <>\n <Surface\n className={`p-2 min-w-[20rem] flex flex-col gap-2 w-full ${\n hasCompletion ? \"-mt-72\" : \"\"\n }`}\n style={{\n width: boundigClient?.width,\n }}\n >\n <>\n {hasCompletion && (\n <div className=\"flex w-full\">\n <ScrollArea\n className=\"h-72 prose p-2 px-4 prose-sm w-full max-w-none\"\n dir={isRTL(completion) ? \"rtl\" : \"ltr\"}\n >\n <Markdown className=\"w-full\">{completion}</Markdown>\n </ScrollArea>\n </div>\n )}\n\n {isLoading && (\n <div\n className=\"flex h-12 w-full items-center px-4 text-sm font-medium text-muted-foreground text-blue-500\"\n style={{\n width: boundigClient?.width,\n }}\n >\n <Sparkles className=\"mr-2 h-4 w-4 shrink-0 \" />\n AI is thinking\n <div className=\"ml-2 mt-1\">\n <CrazySpinner />\n </div>\n </div>\n )}\n\n {!isLoading && (\n <>\n <div className=\"flex justify-between items-center \">\n {/* <CommandInput\n value={inputValue}\n onValueChange={setInputValue}\n autoFocus\n placeholder={\n hasCompletion ? 'Tell AI what to do next' : 'Ask AI to edit or generate...'\n }\n // onFocus={() => addAIHighlight(editor)}\n onKeyDown={(e) => {\n if (e.key === 'Enter') handleClick()\n }}\n /> */}\n <Sparkles className=\"mr-2 h-4 w-4 shrink-0 text-blue-500 \" />\n <TextareaAutosize\n ref={inputRef}\n style={{ resize: \"none\" }}\n className=\"w-full p-2 text-black bg-white rounded dark:bg-black dark:text-white focus:outline-none outline-none border-0 \"\n value={inputValue}\n onChange={(e) => {\n editor.storage.aiCommand.userPrompt = e.target.value;\n\n setInputValue(e.target.value);\n }}\n placeholder={\n hasCompletion\n ? \"Tell AI what to do next\"\n : \"Ask AI to edit or generate...\"\n }\n autoFocus\n // onFocus={() => {\n // addAIHighlight(editor)}}\n\n onKeyDown={(e) => {\n if (e.key === \"Enter\") handleClick();\n }}\n />\n <Toolbar.Button\n // size=\"icon\"\n\n // className=\"absolute right-2 top-1/2 h-6 w-6 -translate-y-1/2 rounded-full bg-zinc-100 hover:bg-zinc-150\"\n onClick={handleClick}\n >\n <ArrowUpCircle />\n </Toolbar.Button>\n </div>\n </>\n )}\n </>\n </Surface>\n {!isLoading && (\n <Surface\n ref={scrollContainer}\n className=\"text-black max-h-[min(80vh,24rem)] overflow-auto flex-wrap mb-8 p-2\"\n >\n <div className=\"grid grid-cols-1 gap-0.5\">\n {hasCompletion ? (\n <AISelectorCommands\n editor={editor}\n messages={completion}\n onSelect={(value, options) => {\n complete(value, { body: options });\n }}\n />\n ) : (\n items.map((group, groupIndex: number) => (\n <React.Fragment key={`${group.title}-wrapper`}>\n <div\n className=\"text-neutral-500 text-[0.65rem] col-[1/-1] mx-2 mt-4 font-semibold tracking-wider select-none uppercase first:mt-0.5\"\n key={`${group.title}`}\n >\n {group.title}\n </div>\n {group.commands.map(\n (command: Command, commandIndex: number) => (\n <DropdownButton\n key={`${command.label}`}\n isActive={\n selectedGroupIndex === groupIndex &&\n selectedCommandIndex === commandIndex\n }\n onClick={createCommandClickHandler(\n groupIndex,\n commandIndex\n )}\n >\n <Icon icon={command.icon} className=\"mr-1\" />\n {command.label}\n </DropdownButton>\n )\n )}\n </React.Fragment>\n ))\n )}\n </div>\n </Surface>\n )}\n </>\n );\n }\n);\n"],"names":["useCompletion","ArrowUpCircle","Sparkles","React","forwardRef","useCallback","useEffect","useImperativeHandle","useRef","useState","Markdown","TextareaAutosize","useLocale","getPrevText","isRTL","CrazySpinner","DropdownButton","Icon","ScrollArea","Surface","Toolbar","AISelectorCommands","AICommandPanel","editor","onOpenChange","userPrompt","items","restProps","ref","inputValue","setInputValue","code","view","scrollContainer","activeItem","selectedGroupIndex","setSelectedGroupIndex","selectedCommandIndex","setSelectedCommandIndex","editorNode","dom","boundigClient","getBoundingClientRect","inputRef","completion","complete","isLoading","api","onResponse","response","status","console","log","onError","e","message","hasCompletion","length","handleClick","body","option","command","language","then","text","chars","storage","aiCommand","title","selectItem","groupIndex","commandIndex","commands","action","onKeyDown","event","key","newCommandIndex","newGroupIndex","current","offsetTop","offsetHeight","scrollTop","createCommandClickHandler","className","style","width","div","dir","resize","value","onChange","target","placeholder","autoFocus","Button","onClick","messages","onSelect","options","map","group","Fragment","isActive","icon","label"],"mappings":"AAAA;;AAEA,SAASA,aAAa,QAAQ,WAAW;AACzC,SAASC,aAAa,EAAEC,QAAQ,QAAQ,eAAe;AACvD,OAAOC,SACLC,UAAU,EACVC,WAAW,EACXC,SAAS,EACTC,mBAAmB,EACnBC,MAAM,EACNC,QAAQ,QACH,QAAQ;AACf,OAAOC,cAAc,iBAAiB;AACtC,OAAOC,sBAAsB,0BAA0B;AAEvD,SAASC,SAAS,QAAQ,kCAAkC;AAO5D,SAASC,WAAW,QAAQ,8BAA8B;AAC1D,SAASC,KAAK,QAAQ,8BAA8B;AACpD,OAAOC,kBAAkB,4BAA4B;AACrD,SAASC,cAAc,QAAQ,gCAAgC;AAC/D,SAASC,IAAI,QAAQ,mBAAmB;AACxC,SAASC,UAAU,QAAQ,0BAA0B;AACrD,SAASC,OAAO,QAAQ,sBAAsB;AAC9C,SAASC,OAAO,QAAQ,sBAAsB;AAC9C,OAAOC,wBAAwB,0DA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G,KAAK,SAASlB;wCACzB;;kDAEF,KAACtC,QAAQ2E,MAAM;wCACb,cAAc;wCAEd,4GAA4G;wCAC5GC,SAAStC;kDAET,cAAA,KAACzD;;;;;;;;YAOZ,CAAC6C,2BACA,KAAC3B;gBACCS,KAAKK;gBACLmD,WAAU;0BAEV,cAAA,KAACG;oBAAIH,WAAU;8BACZ5B,8BACC,KAACnC;wBACCE,QAAQA;wBACR0E,UAAUrD;wBACVsD,UAAU,CAACR,OAAOS;4BAChBtD,SAAS6C,OAAO;gCAAE/B,MAAMwC;4BAAQ;wBAClC;yBAGFzE,MAAM0E,GAAG,CAAC,CAACC,OAAO/B,2BAChB,MAACnE,MAAMmG,QAAQ;;8CACb,KAACf;oCACCH,WAAU;8CAGTiB,MAAMjC,KAAK;mCAFP,CAAC,EAAEiC,MAAMjC,KAAK,CAAC,CAAC;gCAItBiC,MAAM7B,QAAQ,CAAC4B,GAAG,CACjB,CAACvC,SAAkBU,6BACjB,MAACvD;wCAECuF,UACEpE,uBAAuBmC,cACvBjC,yBAAyBkC;wCAE3ByB,SAASb,0BACPb,YACAC;;0DAGF,KAACtD;gDAAKuF,MAAM3C,QAAQ2C,IAAI;gDAAEpB,WAAU;;4CACnCvB,QAAQ4C,KAAK;;uCAXT,CAAC,EAAE5C,QAAQ4C,KAAK,CAAC,CAAC;;2BAVV,CAAC,EAAEJ,MAAMjC,KAAK,CAAC,QAAQ,CAAC;;;;;AAiC7D,GACA"}
|
|
1
|
+
{"version":3,"sources":["../../../../../../../src/fields/TiptapEditor/features/panels/AICommandPanel/AICommandPanel.tsx"],"sourcesContent":["\"use client\";\n\nimport { useCompletion } from \"ai/react\";\nimport { ArrowUpCircle, Sparkles } from \"lucide-react\";\nimport React, {\n forwardRef,\n useCallback,\n useEffect,\n useImperativeHandle,\n useRef,\n useState,\n} from \"react\";\nimport Markdown from \"react-markdown\";\nimport TextareaAutosize from \"react-textarea-autosize\";\n\nimport { useLocale } from \"@payloadcms/ui/providers/Locale\";\nimport { Editor } from \"@tiptap/react\";\n\nimport {\n Command,\n Group,\n} from \"src/fields/TiptapEditor/extensions/AICommand/types.js\";\nimport { getPrevText } from \"../../../lib/utils/index.js\";\nimport { isRTL } from \"../../../lib/utils/isRtl.js\";\nimport CrazySpinner from \"../../ui/crazy-spinner.js\";\nimport { DropdownButton } from \"../../ui/Dropdown/Dropdown.js\";\nimport { Icon } from \"../../ui/Icon.js\";\nimport { ScrollArea } from \"../../ui/scroll-area.js\";\nimport { Surface } from \"../../ui/Surface.js\";\nimport { Toolbar } from \"../../ui/Toolbar.js\";\nimport AISelectorCommands from \"../../menus/TextMenu/components/ai-selector-commands.js\";\n\nexport type AICommandPanelProps = {\n editor: Editor;\n userPrompt?: string;\n onOpenChange: (value: boolean) => void;\n items: Group[];\n};\n\nexport const AICommandPanel = forwardRef(\n (\n {\n editor,\n onOpenChange,\n userPrompt,\n items,\n ...restProps\n }: AICommandPanelProps,\n ref\n ) => {\n const [inputValue, setInputValue] = useState(userPrompt ?? \"\");\n const { code } = useLocale();\n const { view } = editor;\n const scrollContainer = useRef<HTMLDivElement>(null);\n const activeItem = useRef<HTMLButtonElement>(null);\n const [selectedGroupIndex, setSelectedGroupIndex] = useState(0);\n const [selectedCommandIndex, setSelectedCommandIndex] = useState(0);\n\n const editorNode = view.dom as HTMLElement;\n const boundigClient = editorNode.getBoundingClientRect();\n const inputRef = useRef<HTMLTextAreaElement>(null);\n\n // const { status, messages, input, submitMessage, handleInputChange } = useAssistant({\n // // id: \"novel\",\n // api: \"/api/assistant\",\n // onResponse: (response) => {\n // if (response.status === 429) {\n // toast.error(\"You have reached your request limit for the day.\");\n // return;\n // }\n // },\n // onError: (e) => {\n // toast.error(e.message);\n // },\n // });\n\n const { completion, complete, isLoading } = useCompletion({\n // id: \"novel\",\n api: \"/api/generate\",\n onResponse: (response) => {\n if (response.status === 429) {\n console.log(\"You have reached your request limit for the day.\");\n\n return;\n }\n },\n\n onError: (e) => {\n console.log(\"ERROR\", e.message);\n },\n });\n\n const hasCompletion = completion.length > 0;\n const handleClick = useCallback(() => {\n if (completion) {\n return complete(completion, {\n body: { option: \"zap\", command: inputValue, language: code ?? \"en\" },\n }).then(() => setInputValue(\"\"));\n }\n const text = getPrevText(editor, { chars: 5000 });\n\n complete(text, {\n body: {\n option: \"zap\",\n command:\n (editor.storage.aiCommand.title\n ? \"Context Title:\" + editor.storage.aiCommand.title + \";\\n\"\n : \"\") +\n (editor.storage.aiCommand.language\n ? \"Context language:\" + editor.storage.aiCommand.language + \";\\n\"\n : \"\") +\n inputValue,\n language: editor.storage.aiCommand.language ?? code ?? \"en\",\n },\n }).then(() => setInputValue(\"\"));\n }, [code, inputValue]);\n\n useEffect(() => {\n if (userPrompt) setInputValue(userPrompt);\n }, [userPrompt]);\n useEffect(() => {\n editor.storage.aiCommand.completion = completion;\n // if (!isLoading && completion) {\n // const selection = editor.state.selection;\n // editor\n // .chain()\n // .focus()\n // .insertContentAt(selection.to - 1, completion)\n // .insertContentAt(selection.to, \" \")\n // .run();\n\n // }\n }, [completion, isLoading]);\n\n // Anytime the groups change, i.e. the user types to narrow it down, we want to\n // reset the current selection to the first menu item\n useEffect(() => {\n setSelectedGroupIndex(0);\n setSelectedCommandIndex(0);\n }, [items]);\n\n const selectItem = useCallback(\n (groupIndex: number, commandIndex: number) => {\n const command = items[groupIndex].commands[commandIndex];\n\n setInputValue(command.action(editor));\n // props.command(command);\n },\n [items, editor]\n );\n\n useImperativeHandle(ref, () => ({\n onKeyDown: ({ event }: { event: React.KeyboardEvent }) => {\n if (event.key === \"ArrowDown\") {\n if (!items.length) {\n return false;\n }\n\n const commands = items[selectedGroupIndex].commands;\n\n let newCommandIndex = selectedCommandIndex + 1;\n let newGroupIndex = selectedGroupIndex;\n\n if (commands.length - 1 < newCommandIndex) {\n newCommandIndex = 0;\n newGroupIndex = selectedGroupIndex + 1;\n }\n\n if (items.length - 1 < newGroupIndex) {\n newGroupIndex = 0;\n }\n\n setSelectedCommandIndex(newCommandIndex);\n setSelectedGroupIndex(newGroupIndex);\n\n return true;\n }\n\n if (event.key === \"ArrowUp\") {\n if (!items.length) {\n return false;\n }\n\n let newCommandIndex = selectedCommandIndex - 1;\n let newGroupIndex = selectedGroupIndex;\n\n if (newCommandIndex < 0) {\n newGroupIndex = selectedGroupIndex - 1;\n newCommandIndex = items[newGroupIndex]?.commands.length - 1 || 0;\n }\n\n if (newGroupIndex < 0) {\n newGroupIndex = items.length - 1;\n newCommandIndex = items[newGroupIndex].commands.length - 1;\n }\n\n setSelectedCommandIndex(newCommandIndex);\n setSelectedGroupIndex(newGroupIndex);\n\n return true;\n }\n\n if (event.key === \"Enter\") {\n if (\n !items.length ||\n selectedGroupIndex === -1 ||\n selectedCommandIndex === -1\n ) {\n return false;\n }\n\n selectItem(selectedGroupIndex, selectedCommandIndex);\n\n return true;\n }\n\n return false;\n },\n }));\n\n useEffect(() => {\n if (activeItem.current && scrollContainer.current) {\n const offsetTop = activeItem.current.offsetTop;\n const offsetHeight = activeItem.current.offsetHeight;\n\n scrollContainer.current.scrollTop = offsetTop - offsetHeight;\n }\n }, [selectedCommandIndex, selectedGroupIndex]);\n\n const createCommandClickHandler = useCallback(\n (groupIndex: number, commandIndex: number) => {\n return () => {\n selectItem(groupIndex, commandIndex);\n };\n },\n [selectItem]\n );\n\n return (\n <>\n <Surface\n className={`p-2 min-w-[20rem] flex flex-col gap-2 w-full ${\n hasCompletion ? \"-mt-72\" : \"\"\n }`}\n style={{\n width: boundigClient?.width,\n }}\n >\n <>\n {hasCompletion && (\n <div className=\"flex w-full\">\n <ScrollArea\n className=\"h-72 prose p-2 px-4 prose-sm w-full max-w-none\"\n dir={isRTL(completion) ? \"rtl\" : \"ltr\"}\n >\n <Markdown className=\"w-full\">{completion}</Markdown>\n </ScrollArea>\n </div>\n )}\n\n {isLoading && (\n <div\n className=\"flex h-12 w-full items-center px-4 text-sm font-medium text-muted-foreground text-blue-500\"\n style={{\n width: boundigClient?.width,\n }}\n >\n <Sparkles className=\"mr-2 h-4 w-4 shrink-0 \" />\n AI is thinking\n <div className=\"ml-2 mt-1\">\n <CrazySpinner />\n </div>\n </div>\n )}\n\n {!isLoading && (\n <>\n <div className=\"flex justify-between items-center \">\n {/* <CommandInput\n value={inputValue}\n onValueChange={setInputValue}\n autoFocus\n placeholder={\n hasCompletion ? 'Tell AI what to do next' : 'Ask AI to edit or generate...'\n }\n // onFocus={() => addAIHighlight(editor)}\n onKeyDown={(e) => {\n if (e.key === 'Enter') handleClick()\n }}\n /> */}\n <Sparkles className=\"mr-2 h-4 w-4 shrink-0 text-blue-500 \" />\n <TextareaAutosize\n ref={inputRef}\n style={{ resize: \"none\" }}\n className=\"w-full p-2 text-black bg-white rounded dark:bg-black dark:text-white focus:outline-none outline-none border-0 \"\n value={inputValue}\n onChange={(e) => {\n editor.storage.aiCommand.userPrompt = e.target.value;\n\n setInputValue(e.target.value);\n }}\n placeholder={\n hasCompletion\n ? \"Tell AI what to do next\"\n : \"Ask AI to edit or generate...\"\n }\n autoFocus\n // onFocus={() => {\n // addAIHighlight(editor)}}\n\n onKeyDown={(e) => {\n if (e.key === \"Enter\") handleClick();\n }}\n />\n <Toolbar.Button\n // size=\"icon\"\n\n // className=\"absolute right-2 top-1/2 h-6 w-6 -translate-y-1/2 rounded-full bg-zinc-100 hover:bg-zinc-150\"\n onClick={handleClick}\n >\n <ArrowUpCircle />\n </Toolbar.Button>\n </div>\n </>\n )}\n </>\n </Surface>\n {!isLoading && (\n <Surface\n ref={scrollContainer}\n className=\"text-black max-h-[min(80vh,24rem)] overflow-auto flex-wrap mb-8 p-2\"\n >\n <div className=\"grid grid-cols-1 gap-0.5\">\n {hasCompletion ? (\n <AISelectorCommands\n editor={editor}\n messages={completion}\n onSelect={(value, options) => {\n complete(value, { body: options });\n }}\n />\n ) : (\n items.map((group, groupIndex: number) => (\n <React.Fragment key={`${group.title}-wrapper`}>\n <div\n className=\"text-neutral-500 text-[0.65rem] col-[1/-1] mx-2 mt-4 font-semibold tracking-wider select-none uppercase first:mt-0.5\"\n key={`${group.title}`}\n >\n {group.title}\n </div>\n {group.commands.map(\n (command: Command, commandIndex: number) => (\n <DropdownButton\n key={`${command.label}`}\n isActive={\n selectedGroupIndex === groupIndex &&\n selectedCommandIndex === commandIndex\n }\n onClick={createCommandClickHandler(\n groupIndex,\n commandIndex\n )}\n >\n <Icon icon={command.icon} className=\"mr-1\" />\n {command.label}\n </DropdownButton>\n )\n )}\n </React.Fragment>\n ))\n )}\n </div>\n </Surface>\n )}\n </>\n );\n }\n);\n"],"names":["useCompletion","ArrowUpCircle","Sparkles","React","forwardRef","useCallback","useEffect","useImperativeHandle","useRef","useState","Markdown","TextareaAutosize","useLocale","getPrevText","isRTL","CrazySpinner","DropdownButton","Icon","ScrollArea","Surface","Toolbar","AISelectorCommands","AICommandPanel","editor","onOpenChange","userPrompt","items","restProps","ref","inputValue","setInputValue","code","view","scrollContainer","activeItem","selectedGroupIndex","setSelectedGroupIndex","selectedCommandIndex","setSelectedCommandIndex","editorNode","dom","boundigClient","getBoundingClientRect","inputRef","completion","complete","isLoading","api","onResponse","response","status","console","log","onError","e","message","hasCompletion","length","handleClick","body","option","command","language","then","text","chars","storage","aiCommand","title","selectItem","groupIndex","commandIndex","commands","action","onKeyDown","event","key","newCommandIndex","newGroupIndex","current","offsetTop","offsetHeight","scrollTop","createCommandClickHandler","className","style","width","div","dir","resize","value","onChange","target","placeholder","autoFocus","Button","onClick","messages","onSelect","options","map","group","Fragment","isActive","icon","label"],"mappings":"AAAA;;AAEA,SAASA,aAAa,QAAQ,WAAW;AACzC,SAASC,aAAa,EAAEC,QAAQ,QAAQ,eAAe;AACvD,OAAOC,SACLC,UAAU,EACVC,WAAW,EACXC,SAAS,EACTC,mBAAmB,EACnBC,MAAM,EACNC,QAAQ,QACH,QAAQ;AACf,OAAOC,cAAc,iBAAiB;AACtC,OAAOC,sBAAsB,0BAA0B;AAEvD,SAASC,SAAS,QAAQ,kCAAkC;AAO5D,SAASC,WAAW,QAAQ,8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":["\"use client\";\nimport { useEffect, useMemo } from \"react\";\n\nimport { Editor, useEditor } from \"@tiptap/react\";\n\nimport ExtensionKit from \"../extensions/extension-kit.js\";\nimport { EditorUser } from \"../features/BlockEditor/types.js\";\nimport { useSidebar } from \"./useSidebar.js\";\n\nimport { useTranslation } from \"@payloadcms/ui/providers/Translation\";\nimport TurndownService from \"turndown\";\nimport { gfm } from \"turndown-plugin-gfm\";\nimport { AssetReturnType, openAssetHQType } from \"../types.js\";\ndeclare global {\n interface Window {\n editor: Editor | null;\n }\n}\n\nconst dummyAssetHqHandler = (\n listener: (asset: AssetReturnType) => void,\n file?: File\n) => {};\n\nexport const useBlockEditor = ({\n content,\n handleChange,\n openAssetHQHandler,\n additionalContext,\n autoFocus,\n isEditable,\n}: {\n content: { html: string; json: any };\n handleChange?: (data: any) => void;\n openAssetHQHandler?: openAssetHQType;\n additionalContext?: Record<string, any>;\n autoFocus: boolean;\n isEditable?: boolean;\n}) => {\n const leftSidebar = useSidebar();\n\n const turndownService = new TurndownService({});\n // Use the gfm plugin\n turndownService.use(gfm);\n turndownService.addRule(\"twitter\", {\n filter: \"div\",\n replacement: function (content) {\n return \"\\n\\n\" + content + \"\\n\\n\";\n },\n });\n const { t, i18n } = useTranslation();\n\n const editor = useEditor(\n {\n content: content?.json ?? content ?? {},\n immediatelyRender: false,\n autofocus: autoFocus ?? true,\n editable: isEditable ?? true,\n onCreate: ({ editor }) => {\n // provider?.on('synced', () => {\n // if (editor.isEmpty) {\n // editor.commands.setContent(initialContent)\n // }\n // })\n },\n extensions: [\n ...ExtensionKit({\n openAssetHQHandler: openAssetHQHandler ?? dummyAssetHqHandler,\n // provider,\n }),\n // Collaboration.configure({\n // document: ydoc,\n // }),\n // CollaborationCursor.configure({\n // provider,\n // user: {\n // name: randomElement(userNames),\n // color: randomElement(userColors),\n // },\n // }),\n ],\n editorProps: {\n attributes: {\n languages: i18n.language,\n autocomplete: \"off\",\n autocorrect: \"off\",\n autocapitalize: \"off\",\n class: \"min-h-full\",\n },\n },\n onUpdate: ({ editor }) => {\n handleChange(editor?.getJSON() ?? {});\n },\n },\n []\n );\n\n useEffect(() => {\n if (editor?.storage?.aiCommand) {\n editor.storage.aiCommand.title = additionalContext?.title ?? \"\";\n editor.storage.aiCommand.language = additionalContext?.language ?? \"\";\n }\n }, [editor, additionalContext]);\n\n const users = useMemo(() => {\n if (!editor?.storage?.collaborationCursor?.users) {\n return [];\n }\n\n return editor?.storage?.collaborationCursor?.users.map(\n (user: EditorUser) => {\n const names = user.name?.split(\" \");\n const firstName = names?.[0];\n const lastName = names?.[names.length - 1];\n const initials = `${firstName?.[0] || \"?\"}${lastName?.[0] || \"?\"}`;\n\n return { ...user, initials: initials.length ? initials : \"?\" };\n }\n );\n }, [editor?.storage.collaborationCursor?.users]);\n\n const characterCount = editor?.storage.characterCount || {\n characters: () => 0,\n words: () => 0,\n };\n\n // useEffect(() => {\n // provider?.on('status', (event: { status: WebSocketStatus }) => {\n // setCollabState(event.status)\n // })\n // }, [provider])\n\n if (typeof window != \"undefined\") window.editor = editor;\n\n return { editor, users, characterCount, leftSidebar };\n};\n"],"names":["useEffect","useMemo","useEditor","ExtensionKit","useSidebar","useTranslation","TurndownService","gfm","dummyAssetHqHandler","listener","file","useBlockEditor","content","handleChange","openAssetHQHandler","additionalContext","autoFocus","isEditable","leftSidebar","turndownService","use","addRule","filter","replacement","t","i18n","editor","json","immediatelyRender","autofocus","editable","onCreate","extensions","editorProps","attributes","languages","language","autocomplete","autocorrect","autocapitalize","class","onUpdate","getJSON","storage","aiCommand","title","users","collaborationCursor","map","user","names","name","split","firstName","lastName","length","initials","characterCount","characters","words","window"],"mappings":"AAAA;AACA,SAASA,SAAS,EAAEC,OAAO,QAAQ,QAAQ;AAE3C,SAAiBC,SAAS,QAAQ,gBAAgB;AAElD,OAAOC,kBAAkB,iCAAiC;AAE1D,SAASC,UAAU,QAAQ,kBAAkB;AAE7C,SAASC,cAAc,QAAQ,uCAAuC;AACtE,OAAOC,qB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AE9B,MAAM+B,QAAQ7C,QAAQ;QACpB,IAAI,CAACyB,QAAQiB,SAASI,qBAAqBD,OAAO;YAChD,OAAO,EAAE;QACX;QAEA,OAAOpB,QAAQiB,SAASI,qBAAqBD,MAAME,IACjD,CAACC;YACC,MAAMC,QAAQD,KAAKE,IAAI,EAAEC,MAAM;YAC/B,MAAMC,YAAYH,OAAO,CAAC,EAAE;YAC5B,MAAMI,WAAWJ,OAAO,CAACA,MAAMK,MAAM,GAAG,EAAE;YAC1C,MAAMC,WAAW,
|
|
1
|
+
{"version":3,"sources":["../../../../../src/fields/TiptapEditor/hooks/useBlockEditor.ts"],"sourcesContent":["\"use client\";\nimport { useEffect, useMemo } from \"react\";\n\nimport { Editor, useEditor } from \"@tiptap/react\";\n\nimport ExtensionKit from \"../extensions/extension-kit.js\";\nimport { EditorUser } from \"../features/BlockEditor/types.js\";\nimport { useSidebar } from \"./useSidebar.js\";\n\nimport { useTranslation } from \"@payloadcms/ui/providers/Translation\";\nimport TurndownService from \"turndown\";\nimport { gfm } from \"turndown-plugin-gfm\";\nimport { AssetReturnType, openAssetHQType } from \"../types.js\";\ndeclare global {\n interface Window {\n editor: Editor | null;\n }\n}\n\nconst dummyAssetHqHandler = (\n listener: (asset: AssetReturnType) => void,\n file?: File\n) => {};\n\nexport const useBlockEditor = ({\n content,\n handleChange,\n openAssetHQHandler,\n additionalContext,\n autoFocus,\n isEditable,\n}: {\n content: { html: string; json: any };\n handleChange?: (data: any) => void;\n openAssetHQHandler?: openAssetHQType;\n additionalContext?: Record<string, any>;\n autoFocus: boolean;\n isEditable?: boolean;\n}) => {\n const leftSidebar = useSidebar();\n\n const turndownService = new TurndownService({});\n // Use the gfm plugin\n turndownService.use(gfm);\n turndownService.addRule(\"twitter\", {\n filter: \"div\",\n replacement: function (content) {\n return \"\\n\\n\" + content + \"\\n\\n\";\n },\n });\n const { t, i18n } = useTranslation();\n\n const editor = useEditor(\n {\n content: content?.json ?? content ?? {},\n immediatelyRender: false,\n autofocus: autoFocus ?? true,\n editable: isEditable ?? true,\n onCreate: ({ editor }) => {\n // provider?.on('synced', () => {\n // if (editor.isEmpty) {\n // editor.commands.setContent(initialContent)\n // }\n // })\n },\n extensions: [\n ...ExtensionKit({\n openAssetHQHandler: openAssetHQHandler ?? dummyAssetHqHandler,\n // provider,\n }),\n // Collaboration.configure({\n // document: ydoc,\n // }),\n // CollaborationCursor.configure({\n // provider,\n // user: {\n // name: randomElement(userNames),\n // color: randomElement(userColors),\n // },\n // }),\n ],\n editorProps: {\n attributes: {\n languages: i18n.language,\n autocomplete: \"off\",\n autocorrect: \"off\",\n autocapitalize: \"off\",\n class: \"min-h-full\",\n },\n },\n onUpdate: ({ editor }) => {\n handleChange(editor?.getJSON() ?? {});\n },\n },\n []\n );\n\n useEffect(() => {\n if (editor?.storage?.aiCommand) {\n editor.storage.aiCommand.title = additionalContext?.title ?? \"\";\n editor.storage.aiCommand.language = additionalContext?.language ?? \"\";\n }\n }, [editor, additionalContext]);\n\n const users = useMemo(() => {\n if (!editor?.storage?.collaborationCursor?.users) {\n return [];\n }\n\n return editor?.storage?.collaborationCursor?.users.map(\n (user: EditorUser) => {\n const names = user.name?.split(\" \");\n const firstName = names?.[0];\n const lastName = names?.[names.length - 1];\n const initials = `${firstName?.[0] || \"?\"}${lastName?.[0] || \"?\"}`;\n\n return { ...user, initials: initials.length ? initials : \"?\" };\n }\n );\n }, [editor?.storage.collaborationCursor?.users]);\n\n const characterCount = editor?.storage.characterCount || {\n characters: () => 0,\n words: () => 0,\n };\n\n // useEffect(() => {\n // provider?.on('status', (event: { status: WebSocketStatus }) => {\n // setCollabState(event.status)\n // })\n // }, [provider])\n\n if (typeof window != \"undefined\") window.editor = editor;\n\n return { editor, users, characterCount, leftSidebar };\n};\n"],"names":["useEffect","useMemo","useEditor","ExtensionKit","useSidebar","useTranslation","TurndownService","gfm","dummyAssetHqHandler","listener","file","useBlockEditor","content","handleChange","openAssetHQHandler","additionalContext","autoFocus","isEditable","leftSidebar","turndownService","use","addRule","filter","replacement","t","i18n","editor","json","immediatelyRender","autofocus","editable","onCreate","extensions","editorProps","attributes","languages","language","autocomplete","autocorrect","autocapitalize","class","onUpdate","getJSON","storage","aiCommand","title","users","collaborationCursor","map","user","names","name","split","firstName","lastName","length","initials","characterCount","characters","words","window"],"mappings":"AAAA;AACA,SAASA,SAAS,EAAEC,OAAO,QAAQ,QAAQ;AAE3C,SAAiBC,SAAS,QAAQ,gBAAgB;AAElD,OAAOC,kBAAkB,iCAAiC;AAE1D,SAASC,UAAU,QAAQ,kBAAkB;AAE7C,SAASC,cAAc,QAAQ,uCAAuC;AACtE,OAAOC,qBAAqB,WAAW;AACvC,SAASC,GAAG,QAAQ,sBAAsB;AAQ1C,MAAMC,sBAAsB,CAC1BC,UACAC,QACI;AAEN,OAAO,MAAMC,iBAAiB,CAAC,EAC7BC,OAAO,EACPC,YAAY,EACZC,kBAAkB,EAClBC,iBAAiB,EACjBC,SAAS,EACTC,UAAU,EAQX;IACC,MAAMC,cAAcd;IAEpB,MAAMe,kBAAkB,IAAIb,gBAAgB,CAAC;IAC7C,qBAAqB;IACrBa,gBAAgBC,GAAG,CAACb;IACpBY,gBAAgBE,OAAO,CAAC,WAAW;QACjCC,QAAQ;QACRC,aAAa,SAAUX,OAAO;YAC5B,OAAO,SAASA,UAAU;QAC5B;IACF;IACA,MAAM,EAAEY,CAAC,EAAEC,IAAI,EAAE,GAAGpB;IAEpB,MAAMqB,SAASxB,UACb;QACEU,SAASA,SAASe,QAAQf,WAAW,CAAC;QACtCgB,mBAAmB;QACnBC,WAAWb,aAAa;QACxBc,UAAUb,cAAc;QACxBc,UAAU,CAAC,EAAEL,MAAM,EAAE;QACnB,iCAAiC;QACjC,0BAA0B;QAC1B,iDAAiD;QACjD,MAAM;QACN,KAAK;QACP;QACAM,YAAY;eACP7B,aAAa;gBACdW,oBAAoBA,sBAAsBN;YAE5C;SAWD;QACDyB,aAAa;YACXC,YAAY;gBACVC,WAAWV,KAAKW,QA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+1,6 @@
|
|
|
1
|
-
|
|
1
|
+
import { JSONContent } from "@tiptap/core";
|
|
2
|
+
export declare const extractTiptapJson: (markdownValue: string) => JSONContent;
|
|
2
3
|
export declare const extractTiptapJsonFromHTML: (htmlinput: string) => Record<string, any>;
|
|
3
4
|
export declare const extractMarkdown: (json: any) => any;
|
|
5
|
+
export declare const getHtml: (json: JSONContent) => string;
|
|
4
6
|
//# sourceMappingURL=extract.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"extract.d.ts","sourceRoot":"","sources":["../../../../../src/fields/TiptapEditor/lib/extract.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"extract.d.ts","sourceRoot":"","sources":["../../../../../src/fields/TiptapEditor/lib/extract.ts"],"names":[],"mappings":"AAAA,OAAO,EAAwB,WAAW,EAAE,MAAM,cAAc,CAAC;AAGjE,eAAO,MAAM,iBAAiB,kBAAmB,MAAM,gBAWtD,CAAC;AAEF,eAAO,MAAM,yBAAyB,cAAe,MAAM,wBAO1D,CAAC;AAEF,eAAO,MAAM,eAAe,SAAU,GAAG,QAWxC,CAAC;AAEF,eAAO,MAAM,OAAO,SAAU,WAAW,WAWxC,CAAC"}
|
|
@@ -30,5 +30,17 @@ export const extractMarkdown = (json)=>{
|
|
|
30
30
|
});
|
|
31
31
|
return editor.storage.markdown.getMarkdown();
|
|
32
32
|
};
|
|
33
|
+
export const getHtml = (json)=>{
|
|
34
|
+
const editor = new Editor({
|
|
35
|
+
content: json,
|
|
36
|
+
extensions: [
|
|
37
|
+
...ExtensionKit({
|
|
38
|
+
// provider,
|
|
39
|
+
openAssetHQHandler: ()=>{}
|
|
40
|
+
})
|
|
41
|
+
]
|
|
42
|
+
});
|
|
43
|
+
return editor?.getHTML();
|
|
44
|
+
};
|
|
33
45
|
|
|
34
46
|
//# sourceMappingURL=extract.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../../src/fields/TiptapEditor/lib/extract.ts"],"sourcesContent":["import { Editor, generateJSON } from \"@tiptap/core\";\nimport ExtensionKit from \"../extensions/extension-kit.js\";\n\nexport const extractTiptapJson = (markdownValue: string) => {\n const editor = new Editor({\n content: markdownValue,\n extensions: [\n ...ExtensionKit({\n openAssetHQHandler: () => {},\n // provider,\n }),\n ],\n });\n return editor.getJSON();\n};\n\nexport const extractTiptapJsonFromHTML = (htmlinput: string) => {\n return generateJSON(htmlinput, [\n ...ExtensionKit({\n openAssetHQHandler: () => {},\n // provider,\n }),\n ]);\n};\n\nexport const extractMarkdown = (json: any) => {\n const editor = new Editor({\n content: json,\n extensions: [\n ...ExtensionKit({\n // provider,\n openAssetHQHandler: () => {},\n }),\n ],\n });\n return editor.storage.markdown.getMarkdown();\n};\n"],"names":["Editor","generateJSON","ExtensionKit","extractTiptapJson","markdownValue","editor","content","extensions","openAssetHQHandler","getJSON","extractTiptapJsonFromHTML","htmlinput","extractMarkdown","json","storage","markdown","getMarkdown"],"mappings":"AAAA,SAASA,MAAM,EAAEC,YAAY,
|
|
1
|
+
{"version":3,"sources":["../../../../../src/fields/TiptapEditor/lib/extract.ts"],"sourcesContent":["import { Editor, generateJSON, JSONContent } from \"@tiptap/core\";\nimport ExtensionKit from \"../extensions/extension-kit.js\";\n\nexport const extractTiptapJson = (markdownValue: string) => {\n const editor = new Editor({\n content: markdownValue,\n extensions: [\n ...ExtensionKit({\n openAssetHQHandler: () => {},\n // provider,\n }),\n ],\n });\n return editor.getJSON();\n};\n\nexport const extractTiptapJsonFromHTML = (htmlinput: string) => {\n return generateJSON(htmlinput, [\n ...ExtensionKit({\n openAssetHQHandler: () => {},\n // provider,\n }),\n ]);\n};\n\nexport const extractMarkdown = (json: any) => {\n const editor = new Editor({\n content: json,\n extensions: [\n ...ExtensionKit({\n // provider,\n openAssetHQHandler: () => {},\n }),\n ],\n });\n return editor.storage.markdown.getMarkdown();\n};\n\nexport const getHtml = (json: JSONContent) => {\n const editor = new Editor({\n content: json,\n extensions: [\n ...ExtensionKit({\n // provider,\n openAssetHQHandler: () => {},\n }),\n ],\n });\n return editor?.getHTML();\n};\n"],"names":["Editor","generateJSON","ExtensionKit","extractTiptapJson","markdownValue","editor","content","extensions","openAssetHQHandler","getJSON","extractTiptapJsonFromHTML","htmlinput","extractMarkdown","json","storage","markdown","getMarkdown","getHtml","getHTML"],"mappings":"AAAA,SAASA,MAAM,EAAEC,YAAY,QAAqB,eAAe;AACjE,OAAOC,kBAAkB,iCAAiC;AAE1D,OAAO,MAAMC,oBAAoB,CAACC;IAChC,MAAMC,SAAS,IAAIL,OAAO;QACxBM,SAASF;QACTG,YAAY;eACPL,aAAa;gBACdM,oBAAoB,KAAO;YAE7B;SACD;IACH;IACA,OAAOH,OAAOI,OAAO;AACvB,EAAE;AAEF,OAAO,MAAMC,4BAA4B,CAACC;IACxC,OAAOV,aAAaU,WAAW;WAC1BT,aAAa;YACdM,oBAAoB,KAAO;QAE7B;KACD;AACH,EAAE;AAEF,OAAO,MAAMI,kBAAkB,CAACC;IAC9B,MAAMR,SAAS,IAAIL,OAAO;QACxBM,SAASO;QACTN,YAAY;eACPL,aAAa;gBACd,YAAY;gBACZM,oBAAoB,KAAO;YAC7B;SACD;IACH;IACA,OAAOH,OAAOS,OAAO,CAACC,QAAQ,CAACC,WAAW;AAC5C,EAAE;AAEF,OAAO,MAAMC,UAAU,CAACJ;IACtB,MAAMR,SAAS,IAAIL,OAAO;QACxBM,SAASO;QACTN,YAAY;eACPL,aAAa;gBACd,YAAY;gBACZM,oBAAoB,KAAO;YAC7B;SACD;IACH;IACA,OAAOH,QAAQa;AACjB,EAAE"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../../../src/fields/TiptapEditor/lib/utils/cssVar.ts"],"sourcesContent":["export const cssVar = (name: string, value?: string) => {\n let currentName = name\n if (name.substring(0, 2) !== '--') {\n currentName = `--${currentName}`\n }\n\n if (value) {\n document.documentElement.style.setProperty(currentName, value)\n }\n\n return getComputedStyle(document.body).getPropertyValue(currentName)\n}\n\nexport default cssVar\n"],"names":["cssVar","name","value","currentName","substring","document","documentElement","style","setProperty","getComputedStyle","body","getPropertyValue"],"mappings":"AAAA,OAAO,MAAMA,SAAS,CAACC,MAAcC;IACnC,IAAIC,cAAcF;IAClB,IAAIA,KAAKG,SAAS,CAAC,GAAG,OAAO,MAAM;QACjCD,cAAc,CAAC,EAAE,EAAEA,
|
|
1
|
+
{"version":3,"sources":["../../../../../../src/fields/TiptapEditor/lib/utils/cssVar.ts"],"sourcesContent":["export const cssVar = (name: string, value?: string) => {\n let currentName = name\n if (name.substring(0, 2) !== '--') {\n currentName = `--${currentName}`\n }\n\n if (value) {\n document.documentElement.style.setProperty(currentName, value)\n }\n\n return getComputedStyle(document.body).getPropertyValue(currentName)\n}\n\nexport default cssVar\n"],"names":["cssVar","name","value","currentName","substring","document","documentElement","style","setProperty","getComputedStyle","body","getPropertyValue"],"mappings":"AAAA,OAAO,MAAMA,SAAS,CAACC,MAAcC;IACnC,IAAIC,cAAcF;IAClB,IAAIA,KAAKG,SAAS,CAAC,GAAG,OAAO,MAAM;QACjCD,cAAc,CAAC,EAAE,EAAEA,aAAa;IAClC;IAEA,IAAID,OAAO;QACTG,SAASC,eAAe,CAACC,KAAK,CAACC,WAAW,CAACL,aAAaD;IAC1D;IAEA,OAAOO,iBAAiBJ,SAASK,IAAI,EAAEC,gBAAgB,CAACR;AAC1D,EAAC;AAED,eAAeH,OAAM"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"isCustomNodeSelected.d.ts","sourceRoot":"","sources":["../../../../../../src/fields/TiptapEditor/lib/utils/isCustomNodeSelected.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,eAAe,CAAC;
|
|
1
|
+
{"version":3,"file":"isCustomNodeSelected.d.ts","sourceRoot":"","sources":["../../../../../../src/fields/TiptapEditor/lib/utils/isCustomNodeSelected.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,eAAe,CAAC;AAUvC,eAAO,MAAM,mBAAmB,SAAU,WAAW,YAqBpD,CAAC;AAEF,eAAO,MAAM,oBAAoB,WAAY,MAAM,QAAQ,WAAW,YAcrE,CAAC;AAEF,eAAe,oBAAoB,CAAC"}
|
|
@@ -1,6 +1,4 @@
|
|
|
1
|
-
import { Figcaption, HorizontalRule, ImageBlock, ImageUpload, Link
|
|
2
|
-
import { TableOfContentsNode } from "../../extensions/TableOfContentsNode/index.js";
|
|
3
|
-
import { Iframe } from "../../extensions/Iframe/iframe.js";
|
|
1
|
+
import { Figcaption, HorizontalRule, ImageBlock, ImageUpload, Link } from "../../extensions/index.js";
|
|
4
2
|
export const isTableGripSelected = (node)=>{
|
|
5
3
|
let container = node;
|
|
6
4
|
while(container && ![
|
|
@@ -21,12 +19,9 @@ export const isCustomNodeSelected = (editor, node)=>{
|
|
|
21
19
|
HorizontalRule.name,
|
|
22
20
|
ImageBlock.name,
|
|
23
21
|
ImageUpload.name,
|
|
24
|
-
CodeBlock.name,
|
|
25
22
|
ImageBlock.name,
|
|
26
23
|
Link.name,
|
|
27
|
-
Figcaption.name
|
|
28
|
-
TableOfContentsNode.name,
|
|
29
|
-
Iframe.name
|
|
24
|
+
Figcaption.name
|
|
30
25
|
];
|
|
31
26
|
return customNodes.some((type)=>editor.isActive(type)) || isTableGripSelected(node);
|
|
32
27
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../../../src/fields/TiptapEditor/lib/utils/isCustomNodeSelected.ts"],"sourcesContent":["import { Editor } from \"@tiptap/react\";\n\nimport {\n Figcaption,\n HorizontalRule,\n ImageBlock,\n ImageUpload,\n Link,\n
|
|
1
|
+
{"version":3,"sources":["../../../../../../src/fields/TiptapEditor/lib/utils/isCustomNodeSelected.ts"],"sourcesContent":["import { Editor } from \"@tiptap/react\";\n\nimport {\n Figcaption,\n HorizontalRule,\n ImageBlock,\n ImageUpload,\n Link,\n} from \"../../extensions/index.js\";\n\nexport const isTableGripSelected = (node: HTMLElement) => {\n let container = node;\n\n while (container && ![\"TD\", \"TH\"].includes(container.tagName)) {\n container = container.parentElement!;\n }\n\n const gripColumn =\n container &&\n container.querySelector &&\n container.querySelector(\"a.grip-column.selected\");\n const gripRow =\n container &&\n container.querySelector &&\n container.querySelector(\"a.grip-row.selected\");\n\n if (gripColumn || gripRow) {\n return true;\n }\n\n return false;\n};\n\nexport const isCustomNodeSelected = (editor: Editor, node: HTMLElement) => {\n const customNodes = [\n HorizontalRule.name,\n ImageBlock.name,\n ImageUpload.name,\n ImageBlock.name,\n Link.name,\n Figcaption.name,\n ];\n\n return (\n customNodes.some((type) => editor.isActive(type)) ||\n isTableGripSelected(node)\n );\n};\n\nexport default isCustomNodeSelected;\n"],"names":["Figcaption","HorizontalRule","ImageBlock","ImageUpload","Link","isTableGripSelected","node","container","includes","tagName","parentElement","gripColumn","querySelector","gripRow","isCustomNodeSelected","editor","customNodes","name","some","type","isActive"],"mappings":"AAEA,SACEA,UAAU,EACVC,cAAc,EACdC,UAAU,EACVC,WAAW,EACXC,IAAI,QACC,4BAA4B;AAEnC,OAAO,MAAMC,sBAAsB,CAACC;IAClC,IAAIC,YAAYD;IAEhB,MAAOC,aAAa,CAAC;QAAC;QAAM;KAAK,CAACC,QAAQ,CAACD,UAAUE,OAAO,EAAG;QAC7DF,YAAYA,UAAUG,aAAa;IACrC;IAEA,MAAMC,aACJJ,aACAA,UAAUK,aAAa,IACvBL,UAAUK,aAAa,CAAC;IAC1B,MAAMC,UACJN,aACAA,UAAUK,aAAa,IACvBL,UAAUK,aAAa,CAAC;IAE1B,IAAID,cAAcE,SAAS;QACzB,OAAO;IACT;IAEA,OAAO;AACT,EAAE;AAEF,OAAO,MAAMC,uBAAuB,CAACC,QAAgBT;IACnD,MAAMU,cAAc;QAClBf,eAAegB,IAAI;QACnBf,WAAWe,IAAI;QACfd,YAAYc,IAAI;QAChBf,WAAWe,IAAI;QACfb,KAAKa,IAAI;QACTjB,WAAWiB,IAAI;KAChB;IAED,OACED,YAAYE,IAAI,CAAC,CAACC,OAASJ,OAAOK,QAAQ,CAACD,UAC3Cd,oBAAoBC;AAExB,EAAE;AAEF,eAAeQ,qBAAqB"}
|
package/dist/src/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
export { TipTapEditor } from "./fields/TiptapEditor/index.js";
|
|
2
2
|
export { EditorComponent } from "./fields/TiptapEditor/Components.js";
|
|
3
3
|
export { BlockEditor } from "./fields/TiptapEditor/features/BlockEditor/BlockEditor.js";
|
|
4
|
-
export { extractMarkdown, extractTiptapJson, extractTiptapJsonFromHTML, } from "./fields/TiptapEditor/lib/extract.js";
|
|
4
|
+
export { extractMarkdown, extractTiptapJson, extractTiptapJsonFromHTML, getHtml, } from "./fields/TiptapEditor/lib/extract.js";
|
|
5
5
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/src/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,gCAAgC,CAAC;AAC9D,OAAO,EAAE,eAAe,EAAE,MAAM,qCAAqC,CAAC;AACtE,OAAO,EAAE,WAAW,EAAE,MAAM,2DAA2D,CAAC;AACxF,OAAO,EACL,eAAe,EACf,iBAAiB,EACjB,yBAAyB,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,gCAAgC,CAAC;AAC9D,OAAO,EAAE,eAAe,EAAE,MAAM,qCAAqC,CAAC;AACtE,OAAO,EAAE,WAAW,EAAE,MAAM,2DAA2D,CAAC;AACxF,OAAO,EACL,eAAe,EACf,iBAAiB,EACjB,yBAAyB,EACzB,OAAO,GACR,MAAM,sCAAsC,CAAC"}
|
package/dist/src/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
export { TipTapEditor } from "./fields/TiptapEditor/index.js";
|
|
2
2
|
export { EditorComponent } from "./fields/TiptapEditor/Components.js";
|
|
3
3
|
export { BlockEditor } from "./fields/TiptapEditor/features/BlockEditor/BlockEditor.js";
|
|
4
|
-
export { extractMarkdown, extractTiptapJson, extractTiptapJsonFromHTML } from "./fields/TiptapEditor/lib/extract.js";
|
|
4
|
+
export { extractMarkdown, extractTiptapJson, extractTiptapJsonFromHTML, getHtml } from "./fields/TiptapEditor/lib/extract.js";
|
|
5
5
|
|
|
6
6
|
//# sourceMappingURL=index.js.map
|
package/dist/src/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/index.ts"],"sourcesContent":["export { TipTapEditor } from \"./fields/TiptapEditor/index.js\";\nexport { EditorComponent } from \"./fields/TiptapEditor/Components.js\";\nexport { BlockEditor } from \"./fields/TiptapEditor/features/BlockEditor/BlockEditor.js\";\nexport {\n extractMarkdown,\n extractTiptapJson,\n extractTiptapJsonFromHTML,\n} from \"./fields/TiptapEditor/lib/extract.js\";\n"],"names":["TipTapEditor","EditorComponent","BlockEditor","extractMarkdown","extractTiptapJson","extractTiptapJsonFromHTML"],"mappings":"AAAA,SAASA,YAAY,QAAQ,iCAAiC;AAC9D,SAASC,eAAe,QAAQ,sCAAsC;AACtE,SAASC,WAAW,QAAQ,4DAA4D;AACxF,SACEC,eAAe,EACfC,iBAAiB,EACjBC,yBAAyB,
|
|
1
|
+
{"version":3,"sources":["../../src/index.ts"],"sourcesContent":["export { TipTapEditor } from \"./fields/TiptapEditor/index.js\";\nexport { EditorComponent } from \"./fields/TiptapEditor/Components.js\";\nexport { BlockEditor } from \"./fields/TiptapEditor/features/BlockEditor/BlockEditor.js\";\nexport {\n extractMarkdown,\n extractTiptapJson,\n extractTiptapJsonFromHTML,\n getHtml,\n} from \"./fields/TiptapEditor/lib/extract.js\";\n"],"names":["TipTapEditor","EditorComponent","BlockEditor","extractMarkdown","extractTiptapJson","extractTiptapJsonFromHTML","getHtml"],"mappings":"AAAA,SAASA,YAAY,QAAQ,iCAAiC;AAC9D,SAASC,eAAe,QAAQ,sCAAsC;AACtE,SAASC,WAAW,QAAQ,4DAA4D;AACxF,SACEC,eAAe,EACfC,iBAAiB,EACjBC,yBAAyB,EACzBC,OAAO,QACF,uCAAuC"}
|