payload-richtext-tiptap 0.0.142 → 0.0.144
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/README.md +27 -1
- package/dist/src/fields/TiptapEditor/extensions/AICommand/AICommand.d.ts.map +1 -1
- package/dist/src/fields/TiptapEditor/extensions/AICommand/AICommand.js +48 -38
- package/dist/src/fields/TiptapEditor/extensions/AICommand/AICommand.js.map +1 -1
- package/dist/src/fields/TiptapEditor/extensions/LinkPreview/LinkPreview.d.ts +3 -3
- package/dist/src/fields/TiptapEditor/extensions/LinkPreview/LinkPreview.d.ts.map +1 -1
- package/dist/src/fields/TiptapEditor/extensions/LinkPreview/LinkPreview.js +47 -41
- package/dist/src/fields/TiptapEditor/extensions/LinkPreview/LinkPreview.js.map +1 -1
- package/dist/src/fields/TiptapEditor/extensions/extension-kit.d.ts +1 -1
- package/dist/src/fields/TiptapEditor/extensions/extension-kit.d.ts.map +1 -1
- package/dist/src/fields/TiptapEditor/extensions/serverside/ServersideTiptapBody.d.ts +4 -2
- package/dist/src/fields/TiptapEditor/extensions/serverside/ServersideTiptapBody.d.ts.map +1 -1
- package/dist/src/fields/TiptapEditor/extensions/serverside/ServersideTiptapBody.js +53 -14
- package/dist/src/fields/TiptapEditor/extensions/serverside/ServersideTiptapBody.js.map +1 -1
- package/dist/src/fields/TiptapEditor/features/panels/AICommandPanel/AICommandPanel.js +4 -4
- package/dist/src/fields/TiptapEditor/features/panels/AICommandPanel/AICommandPanel.js.map +1 -1
- package/dist/src/fields/TiptapEditor/features/panels/AIEditorPanel/AIEditorPanel.d.ts.map +1 -1
- package/dist/src/fields/TiptapEditor/features/panels/AIEditorPanel/AIEditorPanel.js +4 -6
- package/dist/src/fields/TiptapEditor/features/panels/AIEditorPanel/AIEditorPanel.js.map +1 -1
- package/dist/src/fields/TiptapEditor/lib/tiptapSchema.d.ts +62 -62
- package/dist/src/mobile.css +1 -1
- package/dist/src/styles.css +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +4 -3
package/README.md
CHANGED
|
@@ -2,6 +2,32 @@
|
|
|
2
2
|
|
|
3
3
|
This package provides a simple way to use tiptap editor in react and payloadcms
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
## Setup
|
|
6
|
+
|
|
7
|
+
### Tiptap Pro Authentication
|
|
8
|
+
|
|
9
|
+
This package uses Tiptap Pro features that require authentication to access private repositories. To set this up:
|
|
10
|
+
|
|
11
|
+
1. Copy the `.npmrc.template` file to create your own `.npmrc` file:
|
|
12
|
+
|
|
13
|
+
```bash
|
|
14
|
+
cp .npmrc.template .npmrc
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
2. Set up the `TIPTAP_AUTH_TOKEN` environment variable with your Tiptap authentication token:
|
|
18
|
+
|
|
19
|
+
**For local development:**
|
|
20
|
+
Add to your shell profile (e.g., `~/.zshrc` or `~/.bash_profile`):
|
|
21
|
+
|
|
22
|
+
```bash
|
|
23
|
+
export TIPTAP_AUTH_TOKEN=your-actual-token
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
Then restart your terminal or run `source ~/.zshrc` (or equivalent for your shell).
|
|
27
|
+
|
|
28
|
+
**For CI/CD environments:**
|
|
29
|
+
Add the token as a secret environment variable in your CI platform settings.
|
|
30
|
+
|
|
31
|
+
3. The `.npmrc` file is excluded from git to prevent committing sensitive credentials.
|
|
6
32
|
|
|
7
33
|
**NOTE:** This package is a WIP and is not currently extensible.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"AICommand.d.ts","sourceRoot":"","sources":["../../../../../../src/fields/TiptapEditor/extensions/AICommand/AICommand.ts"],"names":[],"mappings":"AACA,OAAO,EAAU,SAAS,EAAE,MAAM,cAAc,CAAA;AAchD,eAAO,MAAM,SAAS,
|
|
1
|
+
{"version":3,"file":"AICommand.d.ts","sourceRoot":"","sources":["../../../../../../src/fields/TiptapEditor/extensions/AICommand/AICommand.ts"],"names":[],"mappings":"AACA,OAAO,EAAU,SAAS,EAAE,MAAM,cAAc,CAAA;AAchD,eAAO,MAAM,SAAS,qBAwSpB,CAAA;AAEF,eAAe,SAAS,CAAA"}
|
|
@@ -12,36 +12,7 @@ let popupSelection;
|
|
|
12
12
|
export const AICommand = Extension.create({
|
|
13
13
|
name: extensionName,
|
|
14
14
|
priority: 200,
|
|
15
|
-
onCreate () {
|
|
16
|
-
const t = tippy;
|
|
17
|
-
popup = t('body', {
|
|
18
|
-
interactive: true,
|
|
19
|
-
trigger: 'manual',
|
|
20
|
-
placement: 'bottom-start',
|
|
21
|
-
theme: 'slash-command',
|
|
22
|
-
// maxWidth: "16rem",
|
|
23
|
-
offset: [
|
|
24
|
-
0,
|
|
25
|
-
-16
|
|
26
|
-
],
|
|
27
|
-
popperOptions: {
|
|
28
|
-
strategy: 'fixed',
|
|
29
|
-
modifiers: [
|
|
30
|
-
{
|
|
31
|
-
name: 'flip',
|
|
32
|
-
enabled: false
|
|
33
|
-
}
|
|
34
|
-
]
|
|
35
|
-
},
|
|
36
|
-
onHidden: (instance)=>{
|
|
37
|
-
const selection = this.editor.state.selection;
|
|
38
|
-
this.editor?.chain()?.focus()?.insertContentAt({
|
|
39
|
-
from: popupSelection.from - 1,
|
|
40
|
-
to: popupSelection.to
|
|
41
|
-
}, ' ')?.insertContentAt(selection.to, this?.editor?.storage?.aiCommand?.completion?.content ?? [])?.run();
|
|
42
|
-
}
|
|
43
|
-
});
|
|
44
|
-
},
|
|
15
|
+
onCreate () {},
|
|
45
16
|
addProseMirrorPlugins () {
|
|
46
17
|
return [
|
|
47
18
|
Suggestion({
|
|
@@ -111,6 +82,46 @@ export const AICommand = Extension.create({
|
|
|
111
82
|
let scrollHandler = null;
|
|
112
83
|
return {
|
|
113
84
|
onStart: (props)=>{
|
|
85
|
+
const editor = props.editor;
|
|
86
|
+
const t = tippy;
|
|
87
|
+
popup = t('body', {
|
|
88
|
+
interactive: true,
|
|
89
|
+
trigger: 'manual',
|
|
90
|
+
placement: 'bottom-start',
|
|
91
|
+
theme: 'slash-command',
|
|
92
|
+
// maxWidth: "16rem",
|
|
93
|
+
offset: [
|
|
94
|
+
0,
|
|
95
|
+
-16
|
|
96
|
+
],
|
|
97
|
+
popperOptions: {
|
|
98
|
+
strategy: 'fixed',
|
|
99
|
+
modifiers: [
|
|
100
|
+
{
|
|
101
|
+
name: 'flip',
|
|
102
|
+
enabled: false
|
|
103
|
+
}
|
|
104
|
+
]
|
|
105
|
+
},
|
|
106
|
+
editor: editor,
|
|
107
|
+
onHide (instance) {
|
|
108
|
+
try {
|
|
109
|
+
const editorRef = instance.props.editor;
|
|
110
|
+
const completion = editorRef?.storage?.aiCommand?.completion ?? [];
|
|
111
|
+
const selection = editorRef?.state?.selection;
|
|
112
|
+
if (!completion || completion === '') {
|
|
113
|
+
return;
|
|
114
|
+
}
|
|
115
|
+
editorRef?.chain().focus().insertContentAt({
|
|
116
|
+
from: popupSelection.from - 1,
|
|
117
|
+
to: popupSelection.to
|
|
118
|
+
}, ' ').insertContentAt(popupSelection.to, completion).run();
|
|
119
|
+
props.editor.storage.aiCommand.completion = '';
|
|
120
|
+
} catch (e) {
|
|
121
|
+
console.log('Error', e);
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
});
|
|
114
125
|
component = new ReactRenderer(AIMenuList, {
|
|
115
126
|
props,
|
|
116
127
|
editor: props.editor
|
|
@@ -145,7 +156,7 @@ export const AICommand = Extension.create({
|
|
|
145
156
|
popup?.[0].setProps({
|
|
146
157
|
getReferenceClientRect,
|
|
147
158
|
appendTo: ()=>document.body,
|
|
148
|
-
content: component
|
|
159
|
+
content: component?.element
|
|
149
160
|
});
|
|
150
161
|
const selection = this?.editor?.state?.selection;
|
|
151
162
|
popupSelection = {
|
|
@@ -154,8 +165,8 @@ export const AICommand = Extension.create({
|
|
|
154
165
|
};
|
|
155
166
|
popup?.[0].show();
|
|
156
167
|
},
|
|
157
|
-
onUpdate (props)
|
|
158
|
-
component
|
|
168
|
+
onUpdate: (props)=>{
|
|
169
|
+
component?.updateProps(props);
|
|
159
170
|
const { view } = props.editor;
|
|
160
171
|
const editorNode = view.dom;
|
|
161
172
|
const getReferenceClientRect = ()=>{
|
|
@@ -188,7 +199,7 @@ export const AICommand = Extension.create({
|
|
|
188
199
|
getReferenceClientRect
|
|
189
200
|
});
|
|
190
201
|
},
|
|
191
|
-
onKeyDown (props)
|
|
202
|
+
onKeyDown: (props)=>{
|
|
192
203
|
if (props.event.key === 'Escape') {
|
|
193
204
|
popup?.[0].hide();
|
|
194
205
|
return true;
|
|
@@ -196,10 +207,9 @@ export const AICommand = Extension.create({
|
|
|
196
207
|
if (!popup?.[0].state.isShown) {
|
|
197
208
|
popup?.[0].show();
|
|
198
209
|
}
|
|
199
|
-
return component
|
|
210
|
+
return component?.ref?.onKeyDown(props);
|
|
200
211
|
},
|
|
201
|
-
onExit (props)
|
|
202
|
-
popup?.[0].hide();
|
|
212
|
+
onExit: (props)=>{
|
|
203
213
|
if (scrollHandler) {
|
|
204
214
|
const { view } = props.editor;
|
|
205
215
|
view.dom.parentElement?.removeEventListener('scroll', scrollHandler);
|
|
@@ -207,7 +217,7 @@ export const AICommand = Extension.create({
|
|
|
207
217
|
props.editor.storage.aiCommand.active = false;
|
|
208
218
|
props.editor.storage.aiCommand.userPrompt = '';
|
|
209
219
|
props.editor.storage.aiCommand.completion = '';
|
|
210
|
-
component
|
|
220
|
+
component?.destroy();
|
|
211
221
|
}
|
|
212
222
|
};
|
|
213
223
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../../../src/fields/TiptapEditor/extensions/AICommand/AICommand.ts"],"sourcesContent":["'use client'\r\nimport { Editor, Extension } from '@tiptap/core'\r\nimport { PluginKey } from '@tiptap/pm/state'\r\nimport { ReactRenderer } from '@tiptap/react'\r\nimport Suggestion, { SuggestionKeyDownProps, SuggestionProps } from '@tiptap/suggestion'\r\nimport tippy from 'tippy.js'\r\n\r\nimport AIMenuList from './AIMenuList.js'\r\n// import { AICommandPanel } from \"../../features/panels/AICommandPanel/AICommandPanel.js\";\r\n\r\nconst extensionName = 'aiCommand'\r\n\r\nlet popup: any\r\nlet popupSelection: { from: number; to: number }\r\n\r\nexport const AICommand = Extension.create({\r\n name: extensionName,\r\n\r\n priority: 200,\r\n\r\n onCreate() {\r\n const t = tippy as any\r\n popup = t('body', {\r\n interactive: true,\r\n trigger: 'manual',\r\n placement: 'bottom-start',\r\n theme: 'slash-command',\r\n // maxWidth: \"16rem\",\r\n offset: [0, -16],\r\n popperOptions: {\r\n strategy: 'fixed',\r\n modifiers: [\r\n {\r\n name: 'flip',\r\n enabled: false,\r\n },\r\n ],\r\n },\r\n onHidden: (instance) => {\r\n const selection = this.editor.state.selection\r\n\r\n this.editor\r\n ?.chain()\r\n ?.focus()\r\n ?.insertContentAt({ from: popupSelection.from - 1, to: popupSelection.to }, ' ')\r\n ?.insertContentAt(\r\n selection.to,\r\n this?.editor?.storage?.aiCommand?.completion?.content ?? [],\r\n )\r\n ?.run()\r\n },\r\n })\r\n },\r\n\r\n addProseMirrorPlugins() {\r\n return [\r\n Suggestion({\r\n editor: this.editor,\r\n char: ' ',\r\n allowSpaces: false,\r\n startOfLine: true,\r\n pluginKey: new PluginKey(extensionName),\r\n allow: ({ state, range }) => {\r\n const $from = state.doc.resolve(range.from)\r\n const isRootDepth = $from.depth === 1\r\n const isParagraph = $from.parent.type.name === 'paragraph'\r\n const isStartOfNode = $from.parent.textContent?.charAt(0) === ' '\r\n const textLength = $from.parent.textContent?.length\r\n\r\n // TODO\r\n const isInColumn = this.editor.isActive('column')\r\n\r\n const afterContent = $from.parent.textContent?.substring(\r\n $from.parent.textContent?.indexOf(' '),\r\n )\r\n const isValidAfterContent = !afterContent?.endsWith(' ')\r\n return (\r\n ((isRootDepth && isParagraph && isStartOfNode) ||\r\n (isInColumn && isParagraph && isStartOfNode)) &&\r\n isValidAfterContent &&\r\n textLength === 1\r\n )\r\n },\r\n command: ({ editor, props }: { editor: Editor; props: any }) => {\r\n // const { view, state } = editor;\r\n // const { $head, $from } = view.state.selection;\r\n\r\n // const end = $from.pos;\r\n // const from = $head?.nodeBefore\r\n // ? end -\r\n // ($head.nodeBefore.text?.substring(\r\n // $head.nodeBefore.text?.indexOf(\" \")\r\n // ).length ?? 0)\r\n // : $from.start();\r\n\r\n // const tr = state.tr.deleteRange(from, end);\r\n // view.dispatch(tr);\r\n\r\n props.action(editor)\r\n // view.focus();\r\n },\r\n items: async ({ query }: { query: string }) => {\r\n const GROUPS = (await import('./groups.js')).default\r\n const withFilteredCommands = GROUPS.map((group) => ({\r\n ...group,\r\n commands: group.commands\r\n .filter((item) => {\r\n const labelNormalized = item.label.toLowerCase().trim()\r\n const queryNormalized = query.toLowerCase().trim()\r\n\r\n if (item.aliases) {\r\n const aliases = item.aliases.map((alias) => alias.toLowerCase().trim())\r\n\r\n return (\r\n labelNormalized.includes(queryNormalized) || aliases.includes(queryNormalized)\r\n )\r\n }\r\n\r\n return labelNormalized.includes(queryNormalized)\r\n })\r\n .filter((command) =>\r\n command.shouldBeHidden ? !command.shouldBeHidden(this.editor) : true,\r\n ),\r\n }))\r\n\r\n const withoutEmptyGroups = withFilteredCommands.filter((group) => {\r\n if (group.commands.length > 0) {\r\n return true\r\n }\r\n\r\n return false\r\n })\r\n\r\n const withEnabledSettings = withoutEmptyGroups.map((group) => ({\r\n ...group,\r\n commands: group.commands.map((command) => ({\r\n ...command,\r\n isEnabled: true,\r\n })),\r\n }))\r\n\r\n return withEnabledSettings\r\n },\r\n render: () => {\r\n let component: any\r\n\r\n let scrollHandler: (() => void) | null = null\r\n\r\n return {\r\n onStart: (props: SuggestionProps) => {\r\n component = new ReactRenderer(AIMenuList, {\r\n props,\r\n editor: props.editor,\r\n })\r\n props.editor.storage.aiCommand.active = true\r\n const { view } = props.editor\r\n\r\n const editorNode = view.dom as HTMLElement\r\n\r\n const getReferenceClientRect = () => {\r\n if (!props.clientRect) {\r\n return props.editor.storage[extensionName].rect\r\n }\r\n\r\n const rect = props.clientRect()\r\n\r\n if (!rect) {\r\n return props.editor.storage[extensionName].rect\r\n }\r\n\r\n let yPos = rect.y\r\n\r\n if (rect.top + component.element.offsetHeight + 40 > window.innerHeight) {\r\n const diff = rect.top + component.element.offsetHeight - window.innerHeight + 40\r\n yPos = rect.y - diff\r\n }\r\n\r\n // Account for when the editor is bound inside a container that doesn't go all the way to the edge of the screen\r\n const editorXOffset = editorNode.getBoundingClientRect().x\r\n const boundigClient = editorNode.getBoundingClientRect()\r\n\r\n return new DOMRect(rect.x, yPos, boundigClient.width, rect.height)\r\n }\r\n\r\n scrollHandler = () => {\r\n popup?.[0].setProps({\r\n getReferenceClientRect,\r\n })\r\n }\r\n\r\n view.dom.parentElement?.addEventListener('scroll', scrollHandler)\r\n\r\n popup?.[0].setProps({\r\n getReferenceClientRect,\r\n appendTo: () => document.body,\r\n content: component.element,\r\n })\r\n\r\n const selection = this?.editor?.state?.selection\r\n popupSelection = { from: selection?.from, to: selection?.to }\r\n\r\n popup?.[0].show()\r\n },\r\n\r\n onUpdate(props: SuggestionProps) {\r\n component.updateProps(props)\r\n\r\n const { view } = props.editor\r\n\r\n const editorNode = view.dom as HTMLElement\r\n\r\n const getReferenceClientRect = () => {\r\n if (!props.clientRect) {\r\n return props.editor.storage[extensionName].rect\r\n }\r\n\r\n const rect = props.clientRect()\r\n\r\n if (!rect) {\r\n return props.editor.storage[extensionName].rect\r\n }\r\n\r\n // Account for when the editor is bound inside a container that doesn't go all the way to the edge of the screen\r\n return new DOMRect(rect.x, rect.y, rect.width, rect.height)\r\n }\r\n\r\n let scrollHandler = () => {\r\n popup?.[0].setProps({\r\n getReferenceClientRect,\r\n })\r\n }\r\n\r\n view.dom.parentElement?.addEventListener('scroll', scrollHandler)\r\n\r\n // eslint-disable-next-line no-param-reassign\r\n props.editor.storage[extensionName].rect = props.clientRect\r\n ? getReferenceClientRect()\r\n : {\r\n width: 0,\r\n height: 0,\r\n left: 0,\r\n top: 0,\r\n right: 0,\r\n bottom: 0,\r\n }\r\n popup?.[0].setProps({\r\n getReferenceClientRect,\r\n })\r\n },\r\n\r\n onKeyDown(props: SuggestionKeyDownProps) {\r\n if (props.event.key === 'Escape') {\r\n popup?.[0].hide()\r\n\r\n return true\r\n }\r\n\r\n if (!popup?.[0].state.isShown) {\r\n popup?.[0].show()\r\n }\r\n\r\n return component.ref?.onKeyDown(props)\r\n },\r\n\r\n onExit(props) {\r\n popup?.[0].hide()\r\n if (scrollHandler) {\r\n const { view } = props.editor\r\n view.dom.parentElement?.removeEventListener('scroll', scrollHandler)\r\n }\r\n\r\n props.editor.storage.aiCommand.active = false\r\n props.editor.storage.aiCommand.userPrompt = ''\r\n props.editor.storage.aiCommand.completion = ''\r\n\r\n component.destroy()\r\n },\r\n }\r\n },\r\n }),\r\n ]\r\n },\r\n\r\n addStorage() {\r\n return {\r\n rect: {\r\n width: 0,\r\n height: 0,\r\n left: 0,\r\n top: 0,\r\n right: 0,\r\n bottom: 0,\r\n },\r\n userPrompt: '',\r\n completion: '',\r\n title: '',\r\n active: false,\r\n }\r\n },\r\n})\r\n\r\nexport default AICommand\r\n"],"names":["Extension","PluginKey","ReactRenderer","Suggestion","tippy","AIMenuList","extensionName","popup","popupSelection","AICommand","create","name","priority","onCreate","t","interactive","trigger","placement","theme","offset","popperOptions","strategy","modifiers","enabled","onHidden","instance","selection","editor","state","chain","focus","insertContentAt","from","to","storage","aiCommand","completion","content","run","addProseMirrorPlugins","char","allowSpaces","startOfLine","pluginKey","allow","range","$from","doc","resolve","isRootDepth","depth","isParagraph","parent","type","isStartOfNode","textContent","charAt","textLength","length","isInColumn","isActive","afterContent","substring","indexOf","isValidAfterContent","endsWith","command","props","action","items","query","GROUPS","default","withFilteredCommands","map","group","commands","filter","item","labelNormalized","label","toLowerCase","trim","queryNormalized","aliases","alias","includes","shouldBeHidden","withoutEmptyGroups","withEnabledSettings","isEnabled","render","component","scrollHandler","onStart","active","view","editorNode","dom","getReferenceClientRect","clientRect","rect","yPos","y","top","element","offsetHeight","window","innerHeight","diff","editorXOffset","getBoundingClientRect","x","boundigClient","DOMRect","width","height","setProps","parentElement","addEventListener","appendTo","document","body","show","onUpdate","updateProps","left","right","bottom","onKeyDown","event","key","hide","isShown","ref","onExit","removeEventListener","userPrompt","destroy","addStorage","title"],"mappings":"AAAA;AACA,SAAiBA,SAAS,QAAQ,eAAc;AAChD,SAASC,SAAS,QAAQ,mBAAkB;AAC5C,SAASC,aAAa,QAAQ,gBAAe;AAC7C,OAAOC,gBAA6D,qBAAoB;AACxF,OAAOC,WAAW,WAAU;AAE5B,OAAOC,gBAAgB,kBAAiB;AACxC,2FAA2F;AAE3F,MAAMC,gBAAgB;AAEtB,IAAIC;AACJ,IAAIC;AAEJ,OAAO,MAAMC,YAAYT,UAAUU,MAAM,CAAC;IACxCC,MAAML;IAENM,UAAU;IAEVC;QACE,MAAMC,IAAIV;QACVG,QAAQO,EAAE,QAAQ;YAChBC,aAAa;YACbC,SAAS;YACTC,WAAW;YACXC,OAAO;YACP,qBAAqB;YACrBC,QAAQ;gBAAC;gBAAG,CAAC;aAAG;YAChBC,eAAe;gBACbC,UAAU;gBACVC,WAAW;oBACT;wBACEX,MAAM;wBACNY,SAAS;oBACX;iBACD;YACH;YACAC,UAAU,CAACC;gBACT,MAAMC,YAAY,IAAI,CAACC,MAAM,CAACC,KAAK,CAACF,SAAS;gBAE7C,IAAI,CAACC,MAAM,EACPE,SACAC,SACAC,gBAAgB;oBAAEC,MAAMxB,eAAewB,IAAI,GAAG;oBAAGC,IAAIzB,eAAeyB,EAAE;gBAAC,GAAG,MAC1EF,gBACAL,UAAUO,EAAE,EACZ,IAAI,EAAEN,QAAQO,SAASC,WAAWC,YAAYC,WAAW,EAAE,GAE3DC;YACN;QACF;IACF;IAEAC;QACE,OAAO;YACLpC,WAAW;gBACTwB,QAAQ,IAAI,CAACA,MAAM;gBACnBa,MAAM;gBACNC,aAAa;gBACbC,aAAa;gBACbC,WAAW,IAAI1C,UAAUK;gBACz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,IAAIvC,eAAe;gCACjB,MAAM,EAAEG,IAAI,EAAE,GAAG7B,MAAMxC,MAAM;gCAC7BqE,KAAKE,GAAG,CAACoB,aAAa,EAAEkB,oBAAoB,UAAU3C;4BACxD;4BAEA1B,MAAMxC,MAAM,CAACO,OAAO,CAACC,SAAS,CAAC4D,MAAM,GAAG;4BACxC5B,MAAMxC,MAAM,CAACO,OAAO,CAACC,SAAS,CAACsG,UAAU,GAAG;4BAC5CtE,MAAMxC,MAAM,CAACO,OAAO,CAACC,SAAS,CAACC,UAAU,GAAG;4BAE5CwD,UAAU8C,OAAO;wBACnB;oBACF;gBACF;YACF;SACD;IACH;IAEAC;QACE,OAAO;YACLtC,MAAM;gBACJc,OAAO;gBACPC,QAAQ;gBACRU,MAAM;gBACNtB,KAAK;gBACLuB,OAAO;gBACPC,QAAQ;YACV;YACAS,YAAY;YACZrG,YAAY;YACZwG,OAAO;YACP7C,QAAQ;QACV;IACF;AACF,GAAE;AAEF,eAAetF,UAAS"}
|
|
1
|
+
{"version":3,"sources":["../../../../../../src/fields/TiptapEditor/extensions/AICommand/AICommand.ts"],"sourcesContent":["'use client'\r\nimport { Editor, Extension } from '@tiptap/core'\r\nimport { PluginKey } from '@tiptap/pm/state'\r\nimport { ReactRenderer } from '@tiptap/react'\r\nimport Suggestion, { SuggestionKeyDownProps, SuggestionProps } from '@tiptap/suggestion'\r\nimport tippy from 'tippy.js'\r\n\r\nimport AIMenuList from './AIMenuList.js'\r\n// import { AICommandPanel } from \"../../features/panels/AICommandPanel/AICommandPanel.js\";\r\n\r\nconst extensionName = 'aiCommand'\r\n\r\nlet popup: any\r\nlet popupSelection: { from: number; to: number }\r\n\r\nexport const AICommand = Extension.create({\r\n name: extensionName,\r\n\r\n priority: 200,\r\n\r\n onCreate() {},\r\n\r\n addProseMirrorPlugins() {\r\n return [\r\n Suggestion({\r\n editor: this.editor,\r\n char: ' ',\r\n allowSpaces: false,\r\n startOfLine: true,\r\n pluginKey: new PluginKey(extensionName),\r\n allow: ({ state, range }) => {\r\n const $from = state.doc.resolve(range.from)\r\n const isRootDepth = $from.depth === 1\r\n const isParagraph = $from.parent.type.name === 'paragraph'\r\n const isStartOfNode = $from.parent.textContent?.charAt(0) === ' '\r\n const textLength = $from.parent.textContent?.length\r\n\r\n // TODO\r\n const isInColumn = this.editor.isActive('column')\r\n\r\n const afterContent = $from.parent.textContent?.substring(\r\n $from.parent.textContent?.indexOf(' '),\r\n )\r\n const isValidAfterContent = !afterContent?.endsWith(' ')\r\n return (\r\n ((isRootDepth && isParagraph && isStartOfNode) ||\r\n (isInColumn && isParagraph && isStartOfNode)) &&\r\n isValidAfterContent &&\r\n textLength === 1\r\n )\r\n },\r\n command: ({ editor, props }: { editor: Editor; props: any }) => {\r\n // const { view, state } = editor;\r\n // const { $head, $from } = view.state.selection;\r\n\r\n // const end = $from.pos;\r\n // const from = $head?.nodeBefore\r\n // ? end -\r\n // ($head.nodeBefore.text?.substring(\r\n // $head.nodeBefore.text?.indexOf(\" \")\r\n // ).length ?? 0)\r\n // : $from.start();\r\n\r\n // const tr = state.tr.deleteRange(from, end);\r\n // view.dispatch(tr);\r\n\r\n props.action(editor)\r\n // view.focus();\r\n },\r\n items: async ({ query }: { query: string }) => {\r\n const GROUPS = (await import('./groups.js')).default\r\n const withFilteredCommands = GROUPS.map((group) => ({\r\n ...group,\r\n commands: group.commands\r\n .filter((item) => {\r\n const labelNormalized = item.label.toLowerCase().trim()\r\n const queryNormalized = query.toLowerCase().trim()\r\n\r\n if (item.aliases) {\r\n const aliases = item.aliases.map((alias) => alias.toLowerCase().trim())\r\n\r\n return (\r\n labelNormalized.includes(queryNormalized) || aliases.includes(queryNormalized)\r\n )\r\n }\r\n\r\n return labelNormalized.includes(queryNormalized)\r\n })\r\n .filter((command) =>\r\n command.shouldBeHidden ? !command.shouldBeHidden(this.editor) : true,\r\n ),\r\n }))\r\n\r\n const withoutEmptyGroups = withFilteredCommands.filter((group) => {\r\n if (group.commands.length > 0) {\r\n return true\r\n }\r\n\r\n return false\r\n })\r\n\r\n const withEnabledSettings = withoutEmptyGroups.map((group) => ({\r\n ...group,\r\n commands: group.commands.map((command) => ({\r\n ...command,\r\n isEnabled: true,\r\n })),\r\n }))\r\n\r\n return withEnabledSettings\r\n },\r\n render: () => {\r\n let component: any\r\n\r\n let scrollHandler: (() => void) | null = null\r\n\r\n return {\r\n onStart: (props: SuggestionProps) => {\r\n const editor = props.editor\r\n\r\n const t = tippy as any\r\n popup = t('body', {\r\n interactive: true,\r\n trigger: 'manual',\r\n placement: 'bottom-start',\r\n theme: 'slash-command',\r\n // maxWidth: \"16rem\",\r\n offset: [0, -16],\r\n popperOptions: {\r\n strategy: 'fixed',\r\n modifiers: [\r\n {\r\n name: 'flip',\r\n enabled: false,\r\n },\r\n ],\r\n },\r\n editor: editor,\r\n onHide(instance) {\r\n try {\r\n const editorRef = instance.props.editor\r\n const completion = editorRef?.storage?.aiCommand?.completion ?? []\r\n const selection = editorRef?.state?.selection\r\n\r\n if (!completion || completion === '') {\r\n return\r\n }\r\n editorRef\r\n ?.chain()\r\n .focus()\r\n .insertContentAt(\r\n { from: popupSelection.from - 1, to: popupSelection.to },\r\n ' ',\r\n )\r\n .insertContentAt(popupSelection.to, completion)\r\n .run()\r\n\r\n props.editor.storage.aiCommand.completion = ''\r\n } catch (e) {\r\n console.log('Error', e)\r\n }\r\n },\r\n })\r\n component = new ReactRenderer(AIMenuList, {\r\n props,\r\n editor: props.editor,\r\n })\r\n props.editor.storage.aiCommand.active = true\r\n const { view } = props.editor\r\n\r\n const editorNode = view.dom as HTMLElement\r\n\r\n const getReferenceClientRect = () => {\r\n if (!props.clientRect) {\r\n return props.editor.storage[extensionName].rect\r\n }\r\n\r\n const rect = props.clientRect()\r\n\r\n if (!rect) {\r\n return props.editor.storage[extensionName].rect\r\n }\r\n\r\n let yPos = rect.y\r\n\r\n if (rect.top + component.element.offsetHeight + 40 > window.innerHeight) {\r\n const diff = rect.top + component.element.offsetHeight - window.innerHeight + 40\r\n yPos = rect.y - diff\r\n }\r\n\r\n // Account for when the editor is bound inside a container that doesn't go all the way to the edge of the screen\r\n const editorXOffset = editorNode.getBoundingClientRect().x\r\n const boundigClient = editorNode.getBoundingClientRect()\r\n\r\n return new DOMRect(rect.x, yPos, boundigClient.width, rect.height)\r\n }\r\n\r\n scrollHandler = () => {\r\n popup?.[0].setProps({\r\n getReferenceClientRect,\r\n })\r\n }\r\n\r\n view.dom.parentElement?.addEventListener('scroll', scrollHandler)\r\n\r\n popup?.[0].setProps({\r\n getReferenceClientRect,\r\n appendTo: () => document.body,\r\n content: component?.element,\r\n })\r\n\r\n const selection = this?.editor?.state?.selection\r\n popupSelection = { from: selection?.from, to: selection?.to }\r\n\r\n popup?.[0].show()\r\n },\r\n\r\n onUpdate: (props: SuggestionProps) => {\r\n component?.updateProps(props)\r\n\r\n const { view } = props.editor\r\n\r\n const editorNode = view.dom as HTMLElement\r\n\r\n const getReferenceClientRect = () => {\r\n if (!props.clientRect) {\r\n return props.editor.storage[extensionName].rect\r\n }\r\n\r\n const rect = props.clientRect()\r\n\r\n if (!rect) {\r\n return props.editor.storage[extensionName].rect\r\n }\r\n\r\n // Account for when the editor is bound inside a container that doesn't go all the way to the edge of the screen\r\n return new DOMRect(rect.x, rect.y, rect.width, rect.height)\r\n }\r\n\r\n let scrollHandler = () => {\r\n popup?.[0].setProps({\r\n getReferenceClientRect,\r\n })\r\n }\r\n\r\n view.dom.parentElement?.addEventListener('scroll', scrollHandler)\r\n\r\n // eslint-disable-next-line no-param-reassign\r\n props.editor.storage[extensionName].rect = props.clientRect\r\n ? getReferenceClientRect()\r\n : {\r\n width: 0,\r\n height: 0,\r\n left: 0,\r\n top: 0,\r\n right: 0,\r\n bottom: 0,\r\n }\r\n popup?.[0].setProps({\r\n getReferenceClientRect,\r\n })\r\n },\r\n\r\n onKeyDown: (props: SuggestionKeyDownProps) => {\r\n if (props.event.key === 'Escape') {\r\n popup?.[0].hide()\r\n\r\n return true\r\n }\r\n\r\n if (!popup?.[0].state.isShown) {\r\n popup?.[0].show()\r\n }\r\n\r\n return component?.ref?.onKeyDown(props)\r\n },\r\n\r\n onExit: (props) => {\r\n if (scrollHandler) {\r\n const { view } = props.editor\r\n view.dom.parentElement?.removeEventListener('scroll', scrollHandler)\r\n }\r\n\r\n props.editor.storage.aiCommand.active = false\r\n props.editor.storage.aiCommand.userPrompt = ''\r\n props.editor.storage.aiCommand.completion = ''\r\n\r\n component?.destroy()\r\n },\r\n }\r\n },\r\n }),\r\n ]\r\n },\r\n\r\n addStorage() {\r\n return {\r\n rect: {\r\n width: 0,\r\n height: 0,\r\n left: 0,\r\n top: 0,\r\n right: 0,\r\n bottom: 0,\r\n },\r\n userPrompt: '',\r\n completion: '',\r\n title: '',\r\n active: false,\r\n }\r\n },\r\n})\r\n\r\nexport default AICommand\r\n"],"names":["Extension","PluginKey","ReactRenderer","Suggestion","tippy","AIMenuList","extensionName","popup","popupSelection","AICommand","create","name","priority","onCreate","addProseMirrorPlugins","editor","char","allowSpaces","startOfLine","pluginKey","allow","state","range","$from","doc","resolve","from","isRootDepth","depth","isParagraph","parent","type","isStartOfNode","textContent","charAt","textLength","length","isInColumn","isActive","afterContent","substring","indexOf","isValidAfterContent","endsWith","command","props","action","items","query","GROUPS","default","withFilteredCommands","map","group","commands","filter","item","labelNormalized","label","toLowerCase","trim","queryNormalized","aliases","alias","includes","shouldBeHidden","withoutEmptyGroups","withEnabledSettings","isEnabled","render","component","scrollHandler","onStart","t","interactive","trigger","placement","theme","offset","popperOptions","strategy","modifiers","enabled","onHide","instance","editorRef","completion","storage","aiCommand","selection","chain","focus","insertContentAt","to","run","e","console","log","active","view","editorNode","dom","getReferenceClientRect","clientRect","rect","yPos","y","top","element","offsetHeight","window","innerHeight","diff","editorXOffset","getBoundingClientRect","x","boundigClient","DOMRect","width","height","setProps","parentElement","addEventListener","appendTo","document","body","content","show","onUpdate","updateProps","left","right","bottom","onKeyDown","event","key","hide","isShown","ref","onExit","removeEventListener","userP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AWoE,KAAKL,UAAUxF;wBACnC;wBAEA8F,QAAQ,CAAC9F;4BACP,IAAI0B,eAAe;gCACjB,MAAM,EAAE4B,IAAI,EAAE,GAAGtD,MAAM9B,MAAM;gCAC7BoF,KAAKE,GAAG,CAACoB,aAAa,EAAEmB,oBAAoB,UAAUrE;4BACxD;4BAEA1B,MAAM9B,MAAM,CAACwE,OAAO,CAACC,SAAS,CAACU,MAAM,GAAG;4BACxCrD,MAAM9B,MAAM,CAACwE,OAAO,CAACC,SAAS,CAACqD,UAAU,GAAG;4BAC5ChG,MAAM9B,MAAM,CAACwE,OAAO,CAACC,SAAS,CAACF,UAAU,GAAG;4BAE5ChB,WAAWwE;wBACb;oBACF;gBACF;YACF;SACD;IACH;IAEAC;QACE,OAAO;YACLvC,MAAM;gBACJc,OAAO;gBACPC,QAAQ;gBACRW,MAAM;gBACNvB,KAAK;gBACLwB,OAAO;gBACPC,QAAQ;YACV;YACAS,YAAY;YACZvD,YAAY;YACZ0D,OAAO;YACP9C,QAAQ;QACV;IACF;AACF,GAAE;AAEF,eAAezF,UAAS"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { Node } from
|
|
2
|
-
import { SiteMetaData } from
|
|
3
|
-
declare module
|
|
1
|
+
import { Node } from '@tiptap/core';
|
|
2
|
+
import { SiteMetaData } from '../../features/BlockEditor/types.jsx';
|
|
3
|
+
declare module '@tiptap/core' {
|
|
4
4
|
interface Commands<ReturnType> {
|
|
5
5
|
linkPreview: {
|
|
6
6
|
setLinkPreview: (src?: string, metadata?: SiteMetaData) => ReturnType;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"LinkPreview.d.ts","sourceRoot":"","sources":["../../../../../../src/fields/TiptapEditor/extensions/LinkPreview/LinkPreview.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAmB,MAAM,cAAc,CAAC;AACrD,OAAO,EAAE,YAAY,EAAE,MAAM,sCAAsC,CAAC;
|
|
1
|
+
{"version":3,"file":"LinkPreview.d.ts","sourceRoot":"","sources":["../../../../../../src/fields/TiptapEditor/extensions/LinkPreview/LinkPreview.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAmB,MAAM,cAAc,CAAC;AACrD,OAAO,EAAE,YAAY,EAAE,MAAM,sCAAsC,CAAC;AAGpE,OAAO,QAAQ,cAAc,CAAC;IAC5B,UAAU,QAAQ,CAAC,UAAU;QAC3B,WAAW,EAAE;YACX,cAAc,EAAE,CAAC,GAAG,CAAC,EAAE,MAAM,EAAE,QAAQ,CAAC,EAAE,YAAY,KAAK,UAAU,CAAC;SACvE,CAAC;KACH;CACF;AAED,eAAO,MAAM,WAAW,gBAoGtB,CAAC"}
|
|
@@ -1,71 +1,77 @@
|
|
|
1
|
-
import { Node, mergeAttributes } from
|
|
1
|
+
import { Node, mergeAttributes } from '@tiptap/core';
|
|
2
|
+
import i18next from 'i18next';
|
|
2
3
|
export const LinkPreview = Node.create({
|
|
3
|
-
name:
|
|
4
|
-
group:
|
|
4
|
+
name: 'linkPreview',
|
|
5
|
+
group: 'block',
|
|
5
6
|
atom: true,
|
|
6
7
|
addAttributes () {
|
|
7
8
|
return {
|
|
8
9
|
href: {
|
|
9
|
-
default:
|
|
10
|
+
default: ''
|
|
10
11
|
},
|
|
11
12
|
title: {
|
|
12
|
-
default:
|
|
13
|
+
default: ''
|
|
13
14
|
},
|
|
14
15
|
description: {
|
|
15
|
-
default:
|
|
16
|
+
default: ''
|
|
16
17
|
},
|
|
17
18
|
image: {
|
|
18
|
-
default:
|
|
19
|
+
default: ''
|
|
19
20
|
}
|
|
20
21
|
};
|
|
21
22
|
},
|
|
22
23
|
parseHTML () {
|
|
23
24
|
return [
|
|
24
25
|
{
|
|
25
|
-
tag:
|
|
26
|
+
tag: 'a[data-link-preview]'
|
|
26
27
|
}
|
|
27
28
|
];
|
|
28
29
|
},
|
|
29
30
|
renderHTML ({ node }) {
|
|
30
31
|
return [
|
|
31
|
-
|
|
32
|
+
'a',
|
|
32
33
|
mergeAttributes({
|
|
33
|
-
|
|
34
|
-
|
|
34
|
+
'data-link-preview': '',
|
|
35
|
+
href: node.attrs.href,
|
|
36
|
+
target: '_blank',
|
|
37
|
+
rel: 'noopener noreferrer',
|
|
38
|
+
dir: i18next.dir(),
|
|
39
|
+
class: 'relative flex w-full px-4 py-3 flex-col items-start gap-6 rounded bg-[#F1F1F1] border-l-0 transition-all duration-200 ease-in-out box-border mb-4 hover:bg-[#F9F9F9] hover:shadow-[0_4px_6px_-1px_rgba(0,0,0,0.1),0_-4px_6px_-1px_rgba(0,0,0,0.06),4px_0_6px_-1px_rgba(0,0,0,0.06)] focus:bg-[#F9F9F9] focus:shadow-[0_4px_6px_-1px_rgba(0,0,0,0.1),0_-4px_6px_-1px_rgba(0,0,0,0.06),4px_0_6px_-1px_rgba(0,0,0,0.06)] before:content-[""] before:absolute before:left-0 before:top-0 before:bottom-0 before:w-[3px] before:rounded-l-md before:bg-[#01ABD9]'
|
|
35
40
|
}),
|
|
36
|
-
node.attrs.image ? [
|
|
37
|
-
"img",
|
|
38
|
-
{
|
|
39
|
-
src: node.attrs.image,
|
|
40
|
-
width: "120px",
|
|
41
|
-
height: "120px"
|
|
42
|
-
}
|
|
43
|
-
] : "",
|
|
44
41
|
[
|
|
45
|
-
|
|
46
|
-
{
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
42
|
+
'div',
|
|
43
|
+
{
|
|
44
|
+
class: 'flex items-start w-full gap-3'
|
|
45
|
+
},
|
|
46
|
+
node.attrs.image ? [
|
|
47
|
+
'img',
|
|
48
|
+
{
|
|
49
|
+
class: 'flex justify-center items-center rounded flex-shrink-0 !w-20 !h-20 md:!w-[84px] md:!h-[84px]',
|
|
50
|
+
src: node.attrs.image
|
|
51
|
+
}
|
|
52
|
+
] : '',
|
|
52
53
|
[
|
|
53
|
-
|
|
54
|
+
'div',
|
|
54
55
|
{
|
|
55
|
-
|
|
56
|
+
class: 'flex flex-col items-start'
|
|
56
57
|
},
|
|
57
|
-
|
|
58
|
+
[
|
|
59
|
+
'span',
|
|
60
|
+
{
|
|
61
|
+
class: 'overflow-hidden text-[#1F2121] text-ellipsis font-[var(--font-notosans),Arial,sans-serif] text-xs md:text-base font-medium leading-[15px] uppercase mb-1',
|
|
62
|
+
'data-link-preview-related': '',
|
|
63
|
+
'data-testid': 'link-preview-related'
|
|
64
|
+
},
|
|
65
|
+
i18next.t('related', 'RELATED')
|
|
66
|
+
],
|
|
67
|
+
[
|
|
68
|
+
'strong',
|
|
69
|
+
{
|
|
70
|
+
class: 'text-[#1F2121] font-[var(--font-playfair),Georgia,serif] text-base sm:text-lg md:text-xl font-extrabold leading-[31px] underline decoration-solid line-clamp-2 overflow-hidden text-ellipsis max-h-[62px]'
|
|
71
|
+
},
|
|
72
|
+
node.attrs.title
|
|
73
|
+
]
|
|
58
74
|
]
|
|
59
|
-
],
|
|
60
|
-
[
|
|
61
|
-
"a",
|
|
62
|
-
{
|
|
63
|
-
href: node.attrs.href,
|
|
64
|
-
target: "_blank",
|
|
65
|
-
rel: "noopener noreferrer",
|
|
66
|
-
style: "position: absolute; top: 5px; right: 5px; text-decoration: none; font-size: 14px; color: #555; cursor: pointer;"
|
|
67
|
-
},
|
|
68
|
-
"🔗"
|
|
69
75
|
]
|
|
70
76
|
];
|
|
71
77
|
},
|
|
@@ -73,12 +79,12 @@ export const LinkPreview = Node.create({
|
|
|
73
79
|
return {
|
|
74
80
|
setLinkPreview: (src, metadata)=>({ commands, state })=>{
|
|
75
81
|
return commands.insertContent({
|
|
76
|
-
type:
|
|
82
|
+
type: 'linkPreview',
|
|
77
83
|
attrs: {
|
|
78
84
|
href: src,
|
|
79
85
|
title: metadata?.title,
|
|
80
86
|
description: metadata?.description,
|
|
81
|
-
image: metadata?.images?.[0] ||
|
|
87
|
+
image: metadata?.images?.[0] || '/png/placeholder.png'
|
|
82
88
|
}
|
|
83
89
|
});
|
|
84
90
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../../../src/fields/TiptapEditor/extensions/LinkPreview/LinkPreview.tsx"],"sourcesContent":["import { Node, mergeAttributes } from
|
|
1
|
+
{"version":3,"sources":["../../../../../../src/fields/TiptapEditor/extensions/LinkPreview/LinkPreview.tsx"],"sourcesContent":["import { Node, mergeAttributes } from '@tiptap/core';\r\nimport { SiteMetaData } from '../../features/BlockEditor/types.jsx';\r\nimport i18next from 'i18next';\r\n\r\ndeclare module '@tiptap/core' {\r\n interface Commands<ReturnType> {\r\n linkPreview: {\r\n setLinkPreview: (src?: string, metadata?: SiteMetaData) => ReturnType;\r\n };\r\n }\r\n}\r\n\r\nexport const LinkPreview = Node.create({\r\n name: 'linkPreview',\r\n group: 'block',\r\n atom: true,\r\n\r\n addAttributes() {\r\n return {\r\n href: {\r\n default: ''\r\n },\r\n title: { default: '' },\r\n description: {\r\n default: ''\r\n },\r\n image: {\r\n default: ''\r\n }\r\n };\r\n },\r\n\r\n parseHTML() {\r\n return [\r\n {\r\n tag: 'a[data-link-preview]'\r\n }\r\n ];\r\n },\r\n\r\n renderHTML({ node }) {\r\n return [\r\n 'a',\r\n mergeAttributes({\r\n 'data-link-preview': '',\r\n href: node.attrs.href,\r\n target: '_blank',\r\n rel: 'noopener noreferrer',\r\n dir: i18next.dir(),\r\n class:\r\n 'relative flex w-full px-4 py-3 flex-col items-start gap-6 rounded bg-[#F1F1F1] border-l-0 transition-all duration-200 ease-in-out box-border mb-4 hover:bg-[#F9F9F9] hover:shadow-[0_4px_6px_-1px_rgba(0,0,0,0.1),0_-4px_6px_-1px_rgba(0,0,0,0.06),4px_0_6px_-1px_rgba(0,0,0,0.06)] focus:bg-[#F9F9F9] focus:shadow-[0_4px_6px_-1px_rgba(0,0,0,0.1),0_-4px_6px_-1px_rgba(0,0,0,0.06),4px_0_6px_-1px_rgba(0,0,0,0.06)] before:content-[\"\"] before:absolute before:left-0 before:top-0 before:bottom-0 before:w-[3px] before:rounded-l-md before:bg-[#01ABD9]'\r\n }),\r\n [\r\n 'div',\r\n {\r\n class: 'flex items-start w-full gap-3'\r\n },\r\n node.attrs.image\r\n ? [\r\n 'img',\r\n {\r\n class:\r\n 'flex justify-center items-center rounded flex-shrink-0 !w-20 !h-20 md:!w-[84px] md:!h-[84px]',\r\n src: node.attrs.image\r\n }\r\n ]\r\n : '',\r\n [\r\n 'div',\r\n {\r\n class: 'flex flex-col items-start'\r\n },\r\n [\r\n 'span',\r\n {\r\n class:\r\n 'overflow-hidden text-[#1F2121] text-ellipsis font-[var(--font-notosans),Arial,sans-serif] text-xs md:text-base font-medium leading-[15px] uppercase mb-1',\r\n 'data-link-preview-related': '',\r\n 'data-testid': 'link-preview-related'\r\n },\r\n i18next.t('related', 'RELATED')\r\n ],\r\n [\r\n 'strong',\r\n {\r\n class:\r\n 'text-[#1F2121] font-[var(--font-playfair),Georgia,serif] text-base sm:text-lg md:text-xl font-extrabold leading-[31px] underline decoration-solid line-clamp-2 overflow-hidden text-ellipsis max-h-[62px]'\r\n },\r\n node.attrs.title\r\n ]\r\n ]\r\n ]\r\n ];\r\n },\r\n\r\n addCommands() {\r\n return {\r\n setLinkPreview:\r\n (src, metadata) =>\r\n ({ commands, state }) => {\r\n return commands.insertContent({\r\n type: 'linkPreview',\r\n attrs: {\r\n href: src,\r\n title: metadata?.title,\r\n description: metadata?.description,\r\n image: metadata?.images?.[0] || '/png/placeholder.png'\r\n }\r\n });\r\n }\r\n };\r\n }\r\n});\r\n"],"names":["Node","mergeAttributes","i18next","LinkPreview","create","name","group","atom","addAttributes","href","default","title","description","image","parseHTML","tag","renderHTML","node","attrs","target","rel","dir","class","src","t","addCommands","setLinkPreview","metadata","commands","state","insertContent","type","images"],"mappings":"AAAA,SAASA,IAAI,EAAEC,eAAe,QAAQ,eAAe;AAErD,OAAOC,aAAa,UAAU;AAU9B,OAAO,MAAMC,cAAcH,KAAKI,MAAM,CAAC;IACrCC,MAAM;IACNC,OAAO;IACPC,MAAM;IAENC;QACE,OAAO;YACLC,MAAM;gBACJC,SAAS;YACX;YACAC,OAAO;gBAAED,SAAS;YAAG;YACrBE,aAAa;gBACXF,SAAS;YACX;YACAG,OAAO;gBACLH,SAAS;YACX;QACF;IACF;IAEAI;QACE,OAAO;YACL;gBACEC,KAAK;YACP;SACD;IACH;IAEAC,YAAW,EAAEC,IAAI,EAAE;QACjB,OAAO;YACL;YACAhB,gBAAgB;gBACd,qBAAqB;gBACrBQ,MAAMQ,KAAKC,KAAK,CAACT,IAAI;gBACrBU,QAAQ;gBACRC,KAAK;gBACLC,KAAKnB,QAAQmB,GAAG;gBAChBC,OACE;YACJ;YACA;gBACE;gBACA;oBACEA,OAAO;gBACT;gBACAL,KAAKC,KAAK,CAACL,KAAK,GACZ;oBACE;oBACA;wBACES,OACE;wBACFC,KAAKN,KAAKC,KAAK,CAACL,KAAK;oBACvB;iBACD,GACD;gBACJ;oBACE;oBACA;wBACES,OAAO;oBACT;oBACA;wBACE;wBACA;4BACEA,OACE;4BACF,6BAA6B;4BAC7B,eAAe;wBACjB;wBACApB,QAAQsB,CAAC,CAAC,WAAW;qBACtB;oBACD;wBACE;wBACA;4BACEF,OACE;wBACJ;wBACAL,KAAKC,KAAK,CAACP,KAAK;qBACjB;iBACF;aACF;SACF;IACH;IAEAc;QACE,OAAO;YACLC,gBACE,CAACH,KAAKI,WACN,CAAC,EAAEC,QAAQ,EAAEC,KAAK,EAAE;oBAClB,OAAOD,SAASE,aAAa,CAAC;wBAC5BC,MAAM;wBACNb,OAAO;4BACLT,MAAMc;4BACNZ,OAAOgB,UAAUhB;4BACjBC,aAAae,UAAUf;4BACvBC,OAAOc,UAAUK,QAAQ,CAAC,EAAE,IAAI;wBAClC;oBACF;gBACF;QACJ;IACF;AACF,GAAG"}
|
|
@@ -3,6 +3,6 @@ interface ExtensionKitProps {
|
|
|
3
3
|
openAssetHQHandler: openAssetHQType;
|
|
4
4
|
dir?: "ltr" | "rtl";
|
|
5
5
|
}
|
|
6
|
-
export declare const ExtensionKit: ({ dir, openAssetHQHandler, }: ExtensionKitProps) => (import("@tiptap/core").
|
|
6
|
+
export declare const ExtensionKit: ({ dir, openAssetHQHandler, }: ExtensionKitProps) => (import("@tiptap/core").Node<any, any> | import("@tiptap/core").Extension<any, any> | import("@tiptap/core").Mark<import("@tiptap/extension-superscript").SuperscriptExtensionOptions, any>)[];
|
|
7
7
|
export default ExtensionKit;
|
|
8
8
|
//# sourceMappingURL=extension-kit.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"extension-kit.d.ts","sourceRoot":"","sources":["../../../../../src/fields/TiptapEditor/extensions/extension-kit.ts"],"names":[],"mappings":"AAiDA,OAAO,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AAI9C,UAAU,iBAAiB;IACzB,kBAAkB,EAAE,eAAe,CAAC;IACpC,GAAG,CAAC,EAAE,KAAK,GAAG,KAAK,CAAC;CACrB;AAED,eAAO,MAAM,YAAY,iCAGtB,iBAAiB
|
|
1
|
+
{"version":3,"file":"extension-kit.d.ts","sourceRoot":"","sources":["../../../../../src/fields/TiptapEditor/extensions/extension-kit.ts"],"names":[],"mappings":"AAiDA,OAAO,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AAI9C,UAAU,iBAAiB;IACzB,kBAAkB,EAAE,eAAe,CAAC;IACpC,GAAG,CAAC,EAAE,KAAK,GAAG,KAAK,CAAC;CACrB;AAED,eAAO,MAAM,YAAY,iCAGtB,iBAAiB,mMA6HnB,CAAC;AAEF,eAAe,YAAY,CAAC"}
|
|
@@ -1,7 +1,9 @@
|
|
|
1
|
-
import React from
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { AdditionalContextType } from '../../features/BlockEditor/types.js';
|
|
2
3
|
type Props = {
|
|
3
4
|
body: any;
|
|
5
|
+
additionalContext?: AdditionalContextType;
|
|
4
6
|
};
|
|
5
|
-
export declare const ServersideTiptapBody: ({ body }: Props) => React.JSX.Element;
|
|
7
|
+
export declare const ServersideTiptapBody: ({ body, additionalContext }: Props) => React.JSX.Element;
|
|
6
8
|
export {};
|
|
7
9
|
//# sourceMappingURL=ServersideTiptapBody.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ServersideTiptapBody.d.ts","sourceRoot":"","sources":["../../../../../../src/fields/TiptapEditor/extensions/serverside/ServersideTiptapBody.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAC;AA0E1B,KAAK,KAAK,GAAG;IACX,IAAI,EAAE,GAAG,CAAC;
|
|
1
|
+
{"version":3,"file":"ServersideTiptapBody.d.ts","sourceRoot":"","sources":["../../../../../../src/fields/TiptapEditor/extensions/serverside/ServersideTiptapBody.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAC;AA0E1B,OAAO,EAAE,qBAAqB,EAAE,MAAM,qCAAqC,CAAC;AAI5E,KAAK,KAAK,GAAG;IACX,IAAI,EAAE,GAAG,CAAC;IACV,iBAAiB,CAAC,EAAE,qBAAqB,CAAC;CAC3C,CAAC;AAsCF,eAAO,MAAM,oBAAoB,gCAAiC,KAAK,sBAyFtE,CAAC"}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { jsx as _jsx, Fragment as _Fragment } from "react/jsx-runtime";
|
|
2
|
-
import React from
|
|
3
|
-
import { generateHTML } from
|
|
2
|
+
import React from 'react';
|
|
3
|
+
import { generateHTML } from '@tiptap/html';
|
|
4
|
+
import i18n from 'i18next';
|
|
4
5
|
// import { Text } from "@tiptap/extension-text";
|
|
5
6
|
import { StarterKit, Highlight, // CharacterCount,
|
|
6
7
|
Underline, Placeholder, // Emoji,
|
|
@@ -30,22 +31,60 @@ Link, // ImageUpload,
|
|
|
30
31
|
// Instagram,
|
|
31
32
|
// Columns,
|
|
32
33
|
Paragraph, // InsideLinks,
|
|
33
|
-
TableCell, TableHeader, TableRow, Column, LinkPreview } from
|
|
34
|
-
import { TwitterBlockServerside } from
|
|
35
|
-
import { YouTubeServerside } from
|
|
36
|
-
import { InstagramServerside } from
|
|
37
|
-
import { ImageBlockServerside } from
|
|
38
|
-
import { TiktokServerside } from
|
|
39
|
-
import { LinkedinServerside } from
|
|
40
|
-
import { FacebookServerside } from
|
|
41
|
-
import { VideoBlockServerside } from
|
|
42
|
-
import { InsideLinkServerside } from
|
|
43
|
-
import { IFrameServerside } from
|
|
44
|
-
|
|
34
|
+
TableCell, TableHeader, TableRow, Column, LinkPreview } from '../index.js';
|
|
35
|
+
import { TwitterBlockServerside } from './TwitterBlockServerside.js';
|
|
36
|
+
import { YouTubeServerside } from './YouTubeServerside.js';
|
|
37
|
+
import { InstagramServerside } from './InstagramServerside.js';
|
|
38
|
+
import { ImageBlockServerside } from './ImageBlockServerside.js';
|
|
39
|
+
import { TiktokServerside } from './TiktokServerside.js';
|
|
40
|
+
import { LinkedinServerside } from './LinkedinServerside.js';
|
|
41
|
+
import { FacebookServerside } from './FacebookServerside.js';
|
|
42
|
+
import { VideoBlockServerside } from './VideoBlockServerside.js';
|
|
43
|
+
import { InsideLinkServerside } from './InsideLinkServerside.js';
|
|
44
|
+
import { IFrameServerside } from './IFrameServerside.js';
|
|
45
|
+
const DEFAULT_LANG = 'en';
|
|
46
|
+
// Initialize i18n based on additionalContext
|
|
47
|
+
const initializeI18n = (additionalContext)=>{
|
|
48
|
+
if (!additionalContext) {
|
|
49
|
+
i18n.init({
|
|
50
|
+
fallbackLng: DEFAULT_LANG,
|
|
51
|
+
lng: DEFAULT_LANG,
|
|
52
|
+
returnEmptyString: true,
|
|
53
|
+
resources: {}
|
|
54
|
+
});
|
|
55
|
+
return;
|
|
56
|
+
}
|
|
57
|
+
if (additionalContext.language && additionalContext.translations) {
|
|
58
|
+
i18n.init({
|
|
59
|
+
fallbackLng: additionalContext.language,
|
|
60
|
+
lng: additionalContext.language,
|
|
61
|
+
returnEmptyString: true,
|
|
62
|
+
resources: {
|
|
63
|
+
[additionalContext.language]: {
|
|
64
|
+
translation: additionalContext.translations
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
});
|
|
68
|
+
return;
|
|
69
|
+
}
|
|
70
|
+
if (additionalContext.language) {
|
|
71
|
+
i18n.init({
|
|
72
|
+
fallbackLng: additionalContext?.language,
|
|
73
|
+
lng: additionalContext?.language,
|
|
74
|
+
returnEmptyString: true,
|
|
75
|
+
resources: {}
|
|
76
|
+
});
|
|
77
|
+
}
|
|
78
|
+
};
|
|
79
|
+
export const ServersideTiptapBody = ({ body, additionalContext })=>{
|
|
45
80
|
if (!body) return null;
|
|
81
|
+
// Initialize i18n synchronously
|
|
82
|
+
initializeI18n(additionalContext);
|
|
83
|
+
const textDirection = i18n.dir();
|
|
46
84
|
return /*#__PURE__*/ _jsx(_Fragment, {
|
|
47
85
|
children: /*#__PURE__*/ _jsx("div", {
|
|
48
86
|
className: "tiptap ProseMirror min-h-full",
|
|
87
|
+
dir: textDirection,
|
|
49
88
|
dangerouslySetInnerHTML: {
|
|
50
89
|
__html: generateHTML(body, [
|
|
51
90
|
// Text,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../../../src/fields/TiptapEditor/extensions/serverside/ServersideTiptapBody.tsx"],"sourcesContent":["import React from
|
|
1
|
+
{"version":3,"sources":["../../../../../../src/fields/TiptapEditor/extensions/serverside/ServersideTiptapBody.tsx"],"sourcesContent":["import React from 'react';\r\nimport { generateHTML } from '@tiptap/html';\r\nimport i18n from 'i18next';\r\n// import { Text } from \"@tiptap/extension-text\";\r\nimport {\r\n StarterKit,\r\n Highlight,\r\n // CharacterCount,\r\n Underline,\r\n Placeholder,\r\n // Emoji,\r\n TextAlign,\r\n TextStyle,\r\n FontFamily,\r\n Typography,\r\n // Color,\r\n // Dropcursor,\r\n // CollaborationCursor,\r\n Subscript,\r\n // TableOfContents,\r\n Superscript,\r\n CodeBlock,\r\n // BulletList,\r\n // OrderedList,\r\n // Collaboration,\r\n // TaskItem,\r\n // TaskList,\r\n // FileHandler,\r\n // Selection,\r\n // Focus,\r\n Table,\r\n HorizontalRule,\r\n Heading,\r\n Document,\r\n // TrailingNode,\r\n // FontSize,\r\n // Figure,\r\n // Figcaption,\r\n BlockquoteFigure,\r\n // Quote,\r\n // QuoteCaption,\r\n Link,\r\n // ImageUpload,\r\n // ImageBlock,\r\n // VideoBlock,\r\n // AudioBlock,\r\n // Youtube,\r\n // Instagram,\r\n // Columns,\r\n Paragraph,\r\n // InsideLinks,\r\n TableCell,\r\n TableHeader,\r\n TableRow,\r\n Column,\r\n LinkPreview\r\n // Twitter,\r\n // Linkedin,\r\n // Tiktok,\r\n // Facebook,\r\n // Instagram,\r\n // Youtube,\r\n} from '../index.js';\r\n\r\nimport { TwitterBlockServerside } from './TwitterBlockServerside.js';\r\nimport { YouTubeServerside } from './YouTubeServerside.js';\r\nimport { InstagramServerside } from './InstagramServerside.js';\r\nimport { ImageBlockServerside } from './ImageBlockServerside.js';\r\nimport { TiktokServerside } from './TiktokServerside.js';\r\nimport { LinkedinServerside } from './LinkedinServerside.js';\r\nimport { FacebookServerside } from './FacebookServerside.js';\r\nimport { VideoBlockServerside } from './VideoBlockServerside.js';\r\nimport { InsideLinkServerside } from './InsideLinkServerside.js';\r\nimport { IFrameServerside } from './IFrameServerside.js';\r\nimport { AdditionalContextType } from '../../features/BlockEditor/types.js';\r\n\r\nconst DEFAULT_LANG = 'en';\r\n\r\ntype Props = {\r\n body: any;\r\n additionalContext?: AdditionalContextType;\r\n};\r\n\r\n// Initialize i18n based on additionalContext\r\nconst initializeI18n = (additionalContext?: AdditionalContextType) => {\r\n if (!additionalContext) {\r\n i18n.init({\r\n fallbackLng: DEFAULT_LANG,\r\n lng: DEFAULT_LANG,\r\n returnEmptyString: true,\r\n resources: {}\r\n });\r\n return;\r\n }\r\n\r\n if (additionalContext.language && additionalContext.translations) {\r\n i18n.init({\r\n fallbackLng: additionalContext.language,\r\n lng: additionalContext.language,\r\n returnEmptyString: true,\r\n resources: {\r\n [additionalContext.language]: {\r\n translation: additionalContext.translations\r\n }\r\n }\r\n });\r\n return;\r\n }\r\n\r\n if (additionalContext.language) {\r\n i18n.init({\r\n fallbackLng: additionalContext?.language,\r\n lng: additionalContext?.language,\r\n returnEmptyString: true,\r\n resources: {}\r\n });\r\n }\r\n};\r\n\r\nexport const ServersideTiptapBody = ({ body, additionalContext }: Props) => {\r\n if (!body) return null;\r\n\r\n // Initialize i18n synchronously\r\n initializeI18n(additionalContext);\r\n\r\n const textDirection = i18n.dir();\r\n\r\n return (\r\n <>\r\n <div\r\n className='tiptap ProseMirror min-h-full'\r\n dir={textDirection}\r\n dangerouslySetInnerHTML={{\r\n __html: generateHTML(body, [\r\n // Text,\r\n StarterKit.configure({\r\n paragraph: false,\r\n document: false,\r\n dropcursor: false,\r\n heading: false,\r\n horizontalRule: false,\r\n blockquote: false,\r\n history: false,\r\n codeBlock: false\r\n }),\r\n Highlight,\r\n // CharacterCount,\r\n Underline,\r\n Placeholder,\r\n // Emoji,\r\n TextAlign,\r\n TextStyle,\r\n FontFamily,\r\n Typography,\r\n // Color,\r\n // Dropcursor,\r\n // CollaborationCursor,\r\n // Subscript,\r\n // TableOfContents,\r\n // Superscript,\r\n CodeBlock,\r\n // BulletList,\r\n // OrderedList,\r\n // Collaboration,\r\n // TaskItem,\r\n // TaskList,\r\n // FileHandler,\r\n // Selection,\r\n // Focus,\r\n Table,\r\n HorizontalRule,\r\n Heading,\r\n Document,\r\n // TrailingNode,\r\n // SlashCommand,\r\n // FontSize,\r\n // Figure,\r\n // Figcaption,\r\n BlockquoteFigure,\r\n // Quote,\r\n // QuoteCaption,\r\n ImageBlockServerside,\r\n VideoBlockServerside,\r\n // AudioBlock,\r\n // Columns,\r\n TwitterBlockServerside,\r\n InstagramServerside,\r\n YouTubeServerside,\r\n Paragraph,\r\n Superscript,\r\n Subscript,\r\n Link,\r\n TiktokServerside,\r\n LinkedinServerside,\r\n FacebookServerside,\r\n InsideLinkServerside,\r\n IFrameServerside,\r\n // InsideLinks,\r\n TableCell,\r\n TableHeader,\r\n TableRow,\r\n Column,\r\n LinkPreview\r\n ])\r\n }}\r\n />\r\n </>\r\n );\r\n};\r\n"],"names":["React","generateHTML","i18n","StarterKit","Highlight","Underline","Placeholder","TextAlign","TextStyle","FontFamily","Typography","Subscript","Superscript","CodeBlock","Table","HorizontalRule","Heading","Document","BlockquoteFigure","Link","Paragraph","TableCell","TableHeader","TableRow","Column","LinkPreview","TwitterBlockServerside","YouTubeServerside","InstagramServerside","ImageBlockServerside","TiktokServerside","LinkedinServerside","FacebookServerside","VideoBlockServerside","InsideLinkServerside","IFrameServerside","DEFAULT_LANG","initializeI18n","additionalContext","init","fallbackLng","lng","returnEmptyString","resources","language","translations","translation","ServersideTiptapBody","body","textDirection","dir","div","className","dangerouslySetInnerHTML","__html","configure","paragraph","document","dropcursor","heading","horizontalRule","blockquote","history","codeBlock"],"mappings":";AAAA,OAAOA,WAAW,QAAQ;AAC1B,SAASC,YAAY,QAAQ,eAAe;AAC5C,OAAOC,UAAU,UAAU;AAC3B,iDAAiD;AACjD,SACEC,UAAU,EACVC,SAAS,EAETC,AADA,kBAAkB;AAClBA,SAAS,EACTC,WAAW,EAEXC,AADA,SAAS;AACTA,SAAS,EACTC,SAAS,EACTC,UAAU,EACVC,UAAU,EAIVC,AAHA,SAAS;AACT,cAAc;AACd,uBAAuB;AACvBA,SAAS,EAETC,AADA,mBAAmB;AACnBA,WAAW,EACXC,SAAS,EASTC,AARA,cAAc;AACd,eAAe;AACf,iBAAiB;AACjB,YAAY;AACZ,YAAY;AACZ,eAAe;AACf,aAAa;AACb,SAAS;AACTA,KAAK,EACLC,cAAc,EACdC,OAAO,EACPC,QAAQ,EAKRC,AAJA,gBAAgB;AAChB,YAAY;AACZ,UAAU;AACV,cAAc;AACdA,gBAAgB,EAGhBC,AAFA,SAAS;AACT,gBAAgB;AAChBA,IAAI,EAQJC,AAPA,eAAe;AACf,gBAAgB;AAChB,gBAAgB;AAChB,cAAc;AACd,WAAW;AACX,aAA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