@limetech/lime-elements 37.54.0 → 37.54.1
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/CHANGELOG.md +9 -0
- package/dist/cjs/limel-prosemirror-adapter.cjs.entry.js +27 -2
- package/dist/cjs/limel-prosemirror-adapter.cjs.entry.js.map +1 -1
- package/dist/collection/components/text-editor/prosemirror-adapter/menu/types.js +10 -0
- package/dist/collection/components/text-editor/prosemirror-adapter/menu/types.js.map +1 -1
- package/dist/collection/components/text-editor/prosemirror-adapter/plugins/link-plugin.js +18 -3
- package/dist/collection/components/text-editor/prosemirror-adapter/plugins/link-plugin.js.map +1 -1
- package/dist/esm/limel-prosemirror-adapter.entry.js +27 -2
- package/dist/esm/limel-prosemirror-adapter.entry.js.map +1 -1
- package/dist/lime-elements/lime-elements.esm.js +1 -1
- package/dist/lime-elements/{p-58d0b6b0.entry.js → p-ed214c35.entry.js} +2 -2
- package/dist/lime-elements/p-ed214c35.entry.js.map +1 -0
- package/package.json +1 -1
- package/dist/lime-elements/p-58d0b6b0.entry.js.map +0 -1
|
@@ -33,4 +33,14 @@ export const LevelMapping = {
|
|
|
33
33
|
two: 2,
|
|
34
34
|
three: 3,
|
|
35
35
|
};
|
|
36
|
+
/**
|
|
37
|
+
* The `MouseButtons` type is used to represent the different mouse buttons.
|
|
38
|
+
* The values correspond to the button codes used in the `MouseEvent` interface.
|
|
39
|
+
* @beta
|
|
40
|
+
*/
|
|
41
|
+
export const MouseButtons = {
|
|
42
|
+
Left: 0,
|
|
43
|
+
Middle: 1,
|
|
44
|
+
Right: 2,
|
|
45
|
+
};
|
|
36
46
|
//# sourceMappingURL=types.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../../../../src/components/text-editor/prosemirror-adapter/menu/types.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,MAAM,CAAC,MAAM,eAAe,GAAG;EAC3B,IAAI,EAAE,QAAQ;EACd,MAAM,EAAE,IAAI;EACZ,UAAU,EAAE,YAAY;EACxB,YAAY,EAAE,cAAc;EAC5B,YAAY,EAAE,cAAc;EAC5B,YAAY,EAAE,cAAc;EAC5B,IAAI,EAAE,MAAM;EACZ,WAAW,EAAE,cAAc;EAC3B,UAAU,EAAE,aAAa;EACzB,aAAa,EAAE,eAAe;EAC9B,IAAI,EAAE,MAAM;EACZ,SAAS,EAAE,YAAY;CAC1B,CAAC;AAKF,MAAM,CAAC,MAAM,oBAAoB,GAAsB,MAAM,CAAC,MAAM,CAChE,eAAe,CACG,CAAC;AAEvB;;;;;;;GAOG;AACH,MAAM,CAAC,MAAM,YAAY,GAAG;EACxB,OAAO,EAAE,SAAS;EAClB,GAAG,EAAE,CAAC;EACN,GAAG,EAAE,CAAC;EACN,KAAK,EAAE,CAAC;CACX,CAAC","sourcesContent":["/**\n * The `EditorMenuType` type is used to specify the type of menu items that can be added to the editor toolbar.\n * Each one represents a different type to be used for creating the prosemirror commands relevant to the button.\n * The values correspond to the types that can be used with the `prosemirror-commands` library.\n * @beta\n */\n\nexport const EditorMenuTypes = {\n Bold: 'strong',\n Italic: 'em',\n Blockquote: 'blockquote',\n HeaderLevel1: 'headerlevel1',\n HeaderLevel2: 'headerlevel2',\n HeaderLevel3: 'headerlevel3',\n Link: 'link',\n OrderedList: 'ordered_list',\n BulletList: 'bullet_list',\n Strikethrough: 'strikethrough',\n Code: 'code',\n CodeBlock: 'code_block',\n};\n\nexport type EditorMenuTypes =\n (typeof EditorMenuTypes)[keyof typeof EditorMenuTypes];\n\nexport const editorMenuTypesArray: EditorMenuTypes[] = Object.values(\n EditorMenuTypes,\n) as EditorMenuTypes[];\n\n/**\n * `LevelMapping` is used to map string identifiers to numerical header levels.\n * It provides a way to represent different levels of headings in ProseMirror commands.\n *\n * The `Heading` identifier is not a valid level and is used to identify the node type.\n * The numerical values are used for creating ProseMirror commands to set the level of a heading node in the editor.\n * @beta\n */\nexport const LevelMapping = {\n Heading: 'heading',\n one: 1,\n two: 2,\n three: 3,\n};\n\nexport type LevelMapping = (typeof LevelMapping)[keyof typeof LevelMapping];\n\nexport type ProseMirrorAdapterElementWithFocus =\n HTMLLimelProsemirrorAdapterElement & {\n setFocus: () => void;\n };\n\n/**\n * The `EditorTextLink` type is used to represent a link in the editor.\n * @beta\n * @private\n */\nexport type EditorTextLink = {\n text?: string;\n href: string;\n};\n"]}
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../../../../src/components/text-editor/prosemirror-adapter/menu/types.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,MAAM,CAAC,MAAM,eAAe,GAAG;EAC3B,IAAI,EAAE,QAAQ;EACd,MAAM,EAAE,IAAI;EACZ,UAAU,EAAE,YAAY;EACxB,YAAY,EAAE,cAAc;EAC5B,YAAY,EAAE,cAAc;EAC5B,YAAY,EAAE,cAAc;EAC5B,IAAI,EAAE,MAAM;EACZ,WAAW,EAAE,cAAc;EAC3B,UAAU,EAAE,aAAa;EACzB,aAAa,EAAE,eAAe;EAC9B,IAAI,EAAE,MAAM;EACZ,SAAS,EAAE,YAAY;CAC1B,CAAC;AAKF,MAAM,CAAC,MAAM,oBAAoB,GAAsB,MAAM,CAAC,MAAM,CAChE,eAAe,CACG,CAAC;AAEvB;;;;;;;GAOG;AACH,MAAM,CAAC,MAAM,YAAY,GAAG;EACxB,OAAO,EAAE,SAAS;EAClB,GAAG,EAAE,CAAC;EACN,GAAG,EAAE,CAAC;EACN,KAAK,EAAE,CAAC;CACX,CAAC;AAmBF;;;;GAIG;AACH,MAAM,CAAC,MAAM,YAAY,GAAG;EACxB,IAAI,EAAE,CAAC;EACP,MAAM,EAAE,CAAC;EACT,KAAK,EAAE,CAAC;CACX,CAAC","sourcesContent":["/**\n * The `EditorMenuType` type is used to specify the type of menu items that can be added to the editor toolbar.\n * Each one represents a different type to be used for creating the prosemirror commands relevant to the button.\n * The values correspond to the types that can be used with the `prosemirror-commands` library.\n * @beta\n */\n\nexport const EditorMenuTypes = {\n Bold: 'strong',\n Italic: 'em',\n Blockquote: 'blockquote',\n HeaderLevel1: 'headerlevel1',\n HeaderLevel2: 'headerlevel2',\n HeaderLevel3: 'headerlevel3',\n Link: 'link',\n OrderedList: 'ordered_list',\n BulletList: 'bullet_list',\n Strikethrough: 'strikethrough',\n Code: 'code',\n CodeBlock: 'code_block',\n};\n\nexport type EditorMenuTypes =\n (typeof EditorMenuTypes)[keyof typeof EditorMenuTypes];\n\nexport const editorMenuTypesArray: EditorMenuTypes[] = Object.values(\n EditorMenuTypes,\n) as EditorMenuTypes[];\n\n/**\n * `LevelMapping` is used to map string identifiers to numerical header levels.\n * It provides a way to represent different levels of headings in ProseMirror commands.\n *\n * The `Heading` identifier is not a valid level and is used to identify the node type.\n * The numerical values are used for creating ProseMirror commands to set the level of a heading node in the editor.\n * @beta\n */\nexport const LevelMapping = {\n Heading: 'heading',\n one: 1,\n two: 2,\n three: 3,\n};\n\nexport type LevelMapping = (typeof LevelMapping)[keyof typeof LevelMapping];\n\nexport type ProseMirrorAdapterElementWithFocus =\n HTMLLimelProsemirrorAdapterElement & {\n setFocus: () => void;\n };\n\n/**\n * The `EditorTextLink` type is used to represent a link in the editor.\n * @beta\n * @private\n */\nexport type EditorTextLink = {\n text?: string;\n href: string;\n};\n\n/**\n * The `MouseButtons` type is used to represent the different mouse buttons.\n * The values correspond to the button codes used in the `MouseEvent` interface.\n * @beta\n */\nexport const MouseButtons = {\n Left: 0,\n Middle: 1,\n Right: 2,\n};\n\nexport type MouseButtons = (typeof MouseButtons)[keyof typeof MouseButtons];\n"]}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { Plugin, PluginKey, TextSelection } from 'prosemirror-state';
|
|
2
2
|
import { schema } from 'prosemirror-schema-basic';
|
|
3
3
|
import { isExternalLink, isValidUrl } from '../menu/menu-commands';
|
|
4
|
-
import { EditorMenuTypes } from '../menu/types';
|
|
4
|
+
import { EditorMenuTypes, MouseButtons } from '../menu/types';
|
|
5
5
|
export const linkPluginKey = new PluginKey('linkPlugin');
|
|
6
6
|
const updateLink = (view, updateLinkCallback) => {
|
|
7
7
|
const { from, to } = view.state.selection;
|
|
@@ -103,7 +103,7 @@ const openLinkMenu = (view, href, text) => {
|
|
|
103
103
|
let lastClickTime = 0;
|
|
104
104
|
const DOUBLE_CLICK_DELAY = 200;
|
|
105
105
|
let clickTimeout;
|
|
106
|
-
const
|
|
106
|
+
const processClickEvent = (view, event) => {
|
|
107
107
|
const now = Date.now();
|
|
108
108
|
if (now - lastClickTime < DOUBLE_CLICK_DELAY) {
|
|
109
109
|
clearTimeout(clickTimeout);
|
|
@@ -162,7 +162,22 @@ export const createLinkPlugin = (updateLinkCallback) => {
|
|
|
162
162
|
event.button === 0) {
|
|
163
163
|
return processModClickEvent(view, event);
|
|
164
164
|
}
|
|
165
|
-
|
|
165
|
+
if (event.button !== MouseButtons.Right) {
|
|
166
|
+
// We want to ignore right-clicks
|
|
167
|
+
return processClickEvent(view, event);
|
|
168
|
+
}
|
|
169
|
+
return true;
|
|
170
|
+
},
|
|
171
|
+
click: (_view, event) => {
|
|
172
|
+
if (!(event.target instanceof HTMLElement)) {
|
|
173
|
+
return;
|
|
174
|
+
}
|
|
175
|
+
// Prevent unhandled navigation and bubbling for link clicks
|
|
176
|
+
const link = event.target.closest('a');
|
|
177
|
+
if (link) {
|
|
178
|
+
event.preventDefault();
|
|
179
|
+
event.stopPropagation();
|
|
180
|
+
}
|
|
166
181
|
},
|
|
167
182
|
},
|
|
168
183
|
},
|
package/dist/collection/components/text-editor/prosemirror-adapter/plugins/link-plugin.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"link-plugin.js","sourceRoot":"","sources":["../../../../../src/components/text-editor/prosemirror-adapter/plugins/link-plugin.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,SAAS,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAC;AAErE,OAAO,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E;KACvB,UAAU,CAAC,YAAY,EAAE,IAAI,EAAE,EAAE,CAAC;KAClC,OAAO,CAAC,IAAI,EAAE,IAAI,GAAG,YAAY,CAAC,MAAM,EAAE,QAAQ,CAAC,CAAC;EAEzD,QAAQ,CAAC,WAAW,CAAC,CAAC;AAC1B,CAAC,CAAC;AAEF,MAAM,CAAC,MAAM,gBAAgB,GAAG,CAAC,kBAAuC,EAAE,EAAE;EACxE,OAAO,IAAI,MAAM,CAAC;IACd,GAAG,EAAE,aAAa;IAClB,KAAK,EAAE;MACH,WAAW,EAAE,CAAC,IAAI,EAAE,KAAK,EAAE,EAAE;QACzB,OAAO,iBAAiB,CAAC,IAAI,EAAE,KAAK,CAAC,CAAC;MAC1C,CAAC;MACD,eAAe,EAAE;QACb,SAAS,EAAE,CAAC,IAAI,EAAE,KAAK,EAAE,EAAE;UACvB,IACI,CAAC,KAAK,CAAC,OAAO,IAAI,KAAK,CAAC,OAAO,CAAC;YAChC,KAAK,CAAC,MAAM,KAAK,CAAC,EACpB;YACE,OAAO,oBAAoB,CAAC,IAAI,EAAE,KAAK,CAAC,CAAC;WAC5C;UAED,OAAO,uBAAuB,CAAC,IAAI,EAAE,KAAK,CAAC,CAAC;QAChD,CAAC;OACJ;KACJ;IACD,IAAI,EAAE,GAAG,EAAE,CAAC,CAAC;MACT,MAAM,EAAE,CAAC,IAAI,EAAE,EAAE;QACb,UAAU,CAAC,IAAI,EAAE,kBAAkB,CAAC,CAAC;MACzC,CAAC;KACJ,CAAC;GACL,CAAC,CAAC;AACP,CAAC,CAAC","sourcesContent":["import { Plugin, PluginKey, TextSelection } from 'prosemirror-state';\nimport { EditorView } from 'prosemirror-view';\nimport { schema } from 'prosemirror-schema-basic';\nimport { Mark } from 'prosemirror-model';\nimport { isExternalLink, isValidUrl } from '../menu/menu-commands';\nimport { EditorMenuTypes } from '../menu/types';\n\nexport const linkPluginKey = new PluginKey('linkPlugin');\n\nexport type UpdateLinkCallback = (text: string, href: string) => void;\n\nexport interface EditorLinkMenuEventDetail {\n href: string;\n text: string;\n}\n\nconst updateLink = (\n view: EditorView,\n updateLinkCallback?: UpdateLinkCallback,\n) => {\n const { from, to } = view.state.selection;\n\n let text = '';\n let href = '';\n view.state.doc.nodesBetween(from, to, (node, pos) => {\n if (node.type.name !== 'text') {\n return;\n }\n\n const fromInNode = Math.max(0, from - pos);\n const toInNode = Math.min(node.text.length, to - pos);\n\n text += node.text.slice(fromInNode, toInNode);\n\n node.marks.forEach((mark: Mark) => {\n if (mark.type.name === 'link') {\n href = mark.attrs.href;\n }\n });\n });\n\n if (updateLinkCallback) {\n updateLinkCallback(text, href);\n }\n};\n\n/**\n * Finds the start position of the link node ensuring the href matches the original link's href.\n * @param doc - The ProseMirror document.\n * @param pos - The position to start searching from.\n * @param href - The href attribute of the original link mark.\n * @returns The start position of the link node.\n */\nconst findStart = (doc, pos, href) => {\n while (pos > 0) {\n const node = doc.nodeAt(pos - 1);\n if (\n !node?.isText ||\n !node.marks.some(\n (mark: Mark) =>\n mark.type.name === EditorMenuTypes.Link &&\n mark.attrs.href === href,\n )\n ) {\n break;\n }\n\n pos--;\n }\n\n return pos;\n};\n\n/**\n * Finds the end position of the link node ensuring the href matches the original link's href.\n * @param doc - The ProseMirror document.\n * @param pos - The position to start searching from.\n * @param href - The href attribute of the original link mark.\n * @returns The end position of the link node.\n */\nconst findEnd = (doc, pos, href) => {\n while (pos < doc.content.size) {\n const node = doc.nodeAt(pos);\n if (\n !node?.isText ||\n !node.marks.some(\n (mark) =>\n mark.type.name === EditorMenuTypes.Link &&\n mark.attrs.href === href,\n )\n ) {\n break;\n }\n\n pos++;\n }\n\n return pos;\n};\n\n/**\n * Gets the link data at the specified position.\n * @param view - The ProseMirror editor view.\n * @param event - The mouse event.\n * @returns An object containing the link data or null if no link is found.\n */\nconst getLinkDataAtPosition = (view: EditorView, event: MouseEvent) => {\n const pos = view.posAtCoords({ left: event.clientX, top: event.clientY });\n const node = view.state.doc.nodeAt(pos.pos);\n if (!node) {\n return null;\n }\n\n const linkMark = node.marks.find(\n (mark) => mark.type.name === EditorMenuTypes.Link,\n );\n if (!linkMark) {\n return null;\n }\n\n const href = linkMark.attrs.href;\n const from = findStart(view.state.doc, pos.pos, href);\n const to = findEnd(view.state.doc, pos.pos, href);\n const text = view.state.doc.textBetween(from, to, ' ');\n\n return { href: href, text: text, from: from, to: to };\n};\n\nconst processModClickEvent = (view: EditorView, event: MouseEvent): boolean => {\n const { href } = getLinkDataAtPosition(view, event);\n if (href) {\n window.open(href, '_blank');\n\n return true;\n }\n\n return false;\n};\n\nconst openLinkMenu = (view: EditorView, href: string, text: string) => {\n const event = new CustomEvent<EditorLinkMenuEventDetail>(\n 'open-editor-link-menu',\n {\n detail: { href: href, text: text },\n bubbles: true,\n composed: true,\n },\n );\n view.dom.dispatchEvent(event);\n};\n\nlet lastClickTime = 0;\nconst DOUBLE_CLICK_DELAY = 200;\nlet clickTimeout;\n\nconst processDoubleClickEvent = (\n view: EditorView,\n event: MouseEvent,\n): boolean => {\n const now = Date.now();\n\n if (now - lastClickTime < DOUBLE_CLICK_DELAY) {\n clearTimeout(clickTimeout);\n lastClickTime = now; // Reset lastClickTime to prevent single-click action\n\n return false;\n }\n\n lastClickTime = now;\n\n clickTimeout = setTimeout(() => {\n const linkData = getLinkDataAtPosition(view, event);\n if (linkData) {\n const { href, text, from, to } = linkData;\n const transaction = view.state.tr.setSelection(\n TextSelection.create(view.state.doc, from, to),\n );\n view.dispatch(transaction);\n openLinkMenu(view, href, text);\n }\n }, DOUBLE_CLICK_DELAY);\n\n return true;\n};\n\nconst processPasteEvent = (\n view: EditorView,\n event: ClipboardEvent,\n): boolean => {\n const clipboardData = event.clipboardData;\n if (!clipboardData) {\n return false;\n }\n\n const text = clipboardData.getData('text/plain');\n\n // Process as a link if the text is a valid URL\n if (isValidUrl(text)) {\n pasteAsLink(view, text);\n\n return true;\n }\n\n return false;\n};\n\nconst pasteAsLink = (view: EditorView, href: string) => {\n const { state, dispatch } = view;\n const { from, to } = state.selection;\n const linkMark = schema.marks.link.create({\n href: href,\n title: href,\n target: isExternalLink(href) ? '_blank' : null,\n });\n const selectedText = state.doc.textBetween(from, to, ' ') || href;\n const transaction = state.tr\n .insertText(selectedText, from, to)\n .addMark(from, from + selectedText.length, linkMark);\n\n dispatch(transaction);\n};\n\nexport const createLinkPlugin = (updateLinkCallback?: UpdateLinkCallback) => {\n return new Plugin({\n key: linkPluginKey,\n props: {\n handlePaste: (view, event) => {\n return processPasteEvent(view, event);\n },\n handleDOMEvents: {\n mousedown: (view, event) => {\n if (\n (event.metaKey || event.ctrlKey) &&\n event.button === 0\n ) {\n return processModClickEvent(view, event);\n }\n\n return processDoubleClickEvent(view, event);\n },\n },\n },\n view: () => ({\n update: (view) => {\n updateLink(view, updateLinkCallback);\n },\n }),\n });\n};\n"]}
|
|
1
|
+
{"version":3,"file":"link-plugin.js","sourceRoot":"","sources":["../../../../../src/components/text-editor/prosemirror-adapter/plugins/link-plugin.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,SAAS,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAC;AAErE,OAAO,EAAE,MAAM,EAAE,MAAM,0BAA0B,CAAC;AAElD,OAAO,EAAE,cAAc,EAAE,UAAU,EAAE,MAAM,uBAAuB,CAAC;AACnE,OAAO,EAAE,eAAe,EAAE,YAAY,EAAE,MAAM,eAAe,CAAC;AAE9D,MAAM,CAAC,MAAM,aAAa,GAAG,IAAI,SAAS,CAAC,YAAY,CAAC,CAAC;AASzD,MAAM,UAAU,GAAG,CACf,IAAgB,EAChB,kBAAuC,EACzC,EAAE;EACA,MAAM,EAAE,IAAI,EAAE,EAAE,EAAE,GAAG,IAAI,CAAC,KAAK,CAAC,SAAS,CAAC;EAE1C,IAAI,IAAI,GAAG,EAAE,CAAC;EACd,IAAI,IAAI,GAAG,EAAE,CAAC;EACd,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,YAAY,CAAC,IAAI,EAAE,EAAE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,KAAK,EAAE,EAAE;UACvB,IACI,CAAC,KAAK,CAAC,OAAO,IAAI,KAAK,CAAC,OAAO,CAAC;YAChC,KAAK,CAAC,MAAM,KAAK,CAAC,EACpB;YACE,OAAO,oBAAoB,CAAC,IAAI,EAAE,KAAK,CAAC,CAAC;WAC5C;UAED,IAAI,KAAK,CAAC,MAAM,KAAK,YAAY,CAAC,KAAK,EAAE;YACrC,iCAAiC;YACjC,OAAO,iBAAiB,CAAC,IAAI,EAAE,KAAK,CAAC,CAAC;WACzC;UAED,OAAO,IAAI,CAAC;QAChB,CAAC;QACD,KAAK,EAAE,CAAC,KAAK,EAAE,KAAK,EAAE,EAAE;UACpB,IAAI,CAAC,CAAC,KAAK,CAAC,MAAM,YAAY,WAAW,CAAC,EAAE;YACxC,OAAO;WACV;UAED,4DAA4D;UAC5D,MAAM,IAAI,GAAG,KAAK,CAAC,MAAM,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC;UACvC,IAAI,IAAI,EAAE;YACN,KAAK,CAAC,cAAc,EAAE,CAAC;YACvB,KAAK,CAAC,eAAe,EAAE,CAAC;WAC3B;QACL,CAAC;OACJ;KACJ;IACD,IAAI,EAAE,GAAG,EAAE,CAAC,CAAC;MACT,MAAM,EAAE,CAAC,IAAI,EAAE,EAAE;QACb,UAAU,CAAC,IAAI,EAAE,kBAAkB,CAAC,CAAC;MACzC,CAAC;KACJ,CAAC;GACL,CAAC,CAAC;AACP,CAAC,CAAC","sourcesContent":["import { Plugin, PluginKey, TextSelection } from 'prosemirror-state';\nimport { EditorView } from 'prosemirror-view';\nimport { schema } from 'prosemirror-schema-basic';\nimport { Mark } from 'prosemirror-model';\nimport { isExternalLink, isValidUrl } from '../menu/menu-commands';\nimport { EditorMenuTypes, MouseButtons } from '../menu/types';\n\nexport const linkPluginKey = new PluginKey('linkPlugin');\n\nexport type UpdateLinkCallback = (text: string, href: string) => void;\n\nexport interface EditorLinkMenuEventDetail {\n href: string;\n text: string;\n}\n\nconst updateLink = (\n view: EditorView,\n updateLinkCallback?: UpdateLinkCallback,\n) => {\n const { from, to } = view.state.selection;\n\n let text = '';\n let href = '';\n view.state.doc.nodesBetween(from, to, (node, pos) => {\n if (node.type.name !== 'text') {\n return;\n }\n\n const fromInNode = Math.max(0, from - pos);\n const toInNode = Math.min(node.text.length, to - pos);\n\n text += node.text.slice(fromInNode, toInNode);\n\n node.marks.forEach((mark: Mark) => {\n if (mark.type.name === 'link') {\n href = mark.attrs.href;\n }\n });\n });\n\n if (updateLinkCallback) {\n updateLinkCallback(text, href);\n }\n};\n\n/**\n * Finds the start position of the link node ensuring the href matches the original link's href.\n * @param doc - The ProseMirror document.\n * @param pos - The position to start searching from.\n * @param href - The href attribute of the original link mark.\n * @returns The start position of the link node.\n */\nconst findStart = (doc, pos, href) => {\n while (pos > 0) {\n const node = doc.nodeAt(pos - 1);\n if (\n !node?.isText ||\n !node.marks.some(\n (mark: Mark) =>\n mark.type.name === EditorMenuTypes.Link &&\n mark.attrs.href === href,\n )\n ) {\n break;\n }\n\n pos--;\n }\n\n return pos;\n};\n\n/**\n * Finds the end position of the link node ensuring the href matches the original link's href.\n * @param doc - The ProseMirror document.\n * @param pos - The position to start searching from.\n * @param href - The href attribute of the original link mark.\n * @returns The end position of the link node.\n */\nconst findEnd = (doc, pos, href) => {\n while (pos < doc.content.size) {\n const node = doc.nodeAt(pos);\n if (\n !node?.isText ||\n !node.marks.some(\n (mark) =>\n mark.type.name === EditorMenuTypes.Link &&\n mark.attrs.href === href,\n )\n ) {\n break;\n }\n\n pos++;\n }\n\n return pos;\n};\n\n/**\n * Gets the link data at the specified position.\n * @param view - The ProseMirror editor view.\n * @param event - The mouse event.\n * @returns An object containing the link data or null if no link is found.\n */\nconst getLinkDataAtPosition = (view: EditorView, event: MouseEvent) => {\n const pos = view.posAtCoords({ left: event.clientX, top: event.clientY });\n const node = view.state.doc.nodeAt(pos.pos);\n if (!node) {\n return null;\n }\n\n const linkMark = node.marks.find(\n (mark) => mark.type.name === EditorMenuTypes.Link,\n );\n if (!linkMark) {\n return null;\n }\n\n const href = linkMark.attrs.href;\n const from = findStart(view.state.doc, pos.pos, href);\n const to = findEnd(view.state.doc, pos.pos, href);\n const text = view.state.doc.textBetween(from, to, ' ');\n\n return { href: href, text: text, from: from, to: to };\n};\n\nconst processModClickEvent = (view: EditorView, event: MouseEvent): boolean => {\n const { href } = getLinkDataAtPosition(view, event);\n if (href) {\n window.open(href, '_blank');\n\n return true;\n }\n\n return false;\n};\n\nconst openLinkMenu = (view: EditorView, href: string, text: string) => {\n const event = new CustomEvent<EditorLinkMenuEventDetail>(\n 'open-editor-link-menu',\n {\n detail: { href: href, text: text },\n bubbles: true,\n composed: true,\n },\n );\n view.dom.dispatchEvent(event);\n};\n\nlet lastClickTime = 0;\nconst DOUBLE_CLICK_DELAY = 200;\nlet clickTimeout;\n\nconst processClickEvent = (view: EditorView, event: MouseEvent): boolean => {\n const now = Date.now();\n\n if (now - lastClickTime < DOUBLE_CLICK_DELAY) {\n clearTimeout(clickTimeout);\n lastClickTime = now; // Reset lastClickTime to prevent single-click action\n\n return false;\n }\n\n lastClickTime = now;\n\n clickTimeout = setTimeout(() => {\n const linkData = getLinkDataAtPosition(view, event);\n if (linkData) {\n const { href, text, from, to } = linkData;\n const transaction = view.state.tr.setSelection(\n TextSelection.create(view.state.doc, from, to),\n );\n view.dispatch(transaction);\n openLinkMenu(view, href, text);\n }\n }, DOUBLE_CLICK_DELAY);\n\n return true;\n};\n\nconst processPasteEvent = (\n view: EditorView,\n event: ClipboardEvent,\n): boolean => {\n const clipboardData = event.clipboardData;\n if (!clipboardData) {\n return false;\n }\n\n const text = clipboardData.getData('text/plain');\n\n // Process as a link if the text is a valid URL\n if (isValidUrl(text)) {\n pasteAsLink(view, text);\n\n return true;\n }\n\n return false;\n};\n\nconst pasteAsLink = (view: EditorView, href: string) => {\n const { state, dispatch } = view;\n const { from, to } = state.selection;\n const linkMark = schema.marks.link.create({\n href: href,\n title: href,\n target: isExternalLink(href) ? '_blank' : null,\n });\n const selectedText = state.doc.textBetween(from, to, ' ') || href;\n const transaction = state.tr\n .insertText(selectedText, from, to)\n .addMark(from, from + selectedText.length, linkMark);\n\n dispatch(transaction);\n};\n\nexport const createLinkPlugin = (updateLinkCallback?: UpdateLinkCallback) => {\n return new Plugin({\n key: linkPluginKey,\n props: {\n handlePaste: (view, event) => {\n return processPasteEvent(view, event);\n },\n handleDOMEvents: {\n mousedown: (view, event) => {\n if (\n (event.metaKey || event.ctrlKey) &&\n event.button === 0\n ) {\n return processModClickEvent(view, event);\n }\n\n if (event.button !== MouseButtons.Right) {\n // We want to ignore right-clicks\n return processClickEvent(view, event);\n }\n\n return true;\n },\n click: (_view, event) => {\n if (!(event.target instanceof HTMLElement)) {\n return;\n }\n\n // Prevent unhandled navigation and bubbling for link clicks\n const link = event.target.closest('a');\n if (link) {\n event.preventDefault();\n event.stopPropagation();\n }\n },\n },\n },\n view: () => ({\n update: (view) => {\n updateLink(view, updateLinkCallback);\n },\n }),\n });\n};\n"]}
|
|
@@ -16559,6 +16559,16 @@ const LevelMapping = {
|
|
|
16559
16559
|
two: 2,
|
|
16560
16560
|
three: 3,
|
|
16561
16561
|
};
|
|
16562
|
+
/**
|
|
16563
|
+
* The `MouseButtons` type is used to represent the different mouse buttons.
|
|
16564
|
+
* The values correspond to the button codes used in the `MouseEvent` interface.
|
|
16565
|
+
* @beta
|
|
16566
|
+
*/
|
|
16567
|
+
const MouseButtons = {
|
|
16568
|
+
Left: 0,
|
|
16569
|
+
Middle: 1,
|
|
16570
|
+
Right: 2,
|
|
16571
|
+
};
|
|
16562
16572
|
|
|
16563
16573
|
const setActiveMethodForMark = (command, markType) => {
|
|
16564
16574
|
command.active = (state) => {
|
|
@@ -25738,7 +25748,7 @@ const openLinkMenu = (view, href, text) => {
|
|
|
25738
25748
|
let lastClickTime = 0;
|
|
25739
25749
|
const DOUBLE_CLICK_DELAY = 200;
|
|
25740
25750
|
let clickTimeout;
|
|
25741
|
-
const
|
|
25751
|
+
const processClickEvent = (view, event) => {
|
|
25742
25752
|
const now = Date.now();
|
|
25743
25753
|
if (now - lastClickTime < DOUBLE_CLICK_DELAY) {
|
|
25744
25754
|
clearTimeout(clickTimeout);
|
|
@@ -25797,7 +25807,22 @@ const createLinkPlugin = (updateLinkCallback) => {
|
|
|
25797
25807
|
event.button === 0) {
|
|
25798
25808
|
return processModClickEvent(view, event);
|
|
25799
25809
|
}
|
|
25800
|
-
|
|
25810
|
+
if (event.button !== MouseButtons.Right) {
|
|
25811
|
+
// We want to ignore right-clicks
|
|
25812
|
+
return processClickEvent(view, event);
|
|
25813
|
+
}
|
|
25814
|
+
return true;
|
|
25815
|
+
},
|
|
25816
|
+
click: (_view, event) => {
|
|
25817
|
+
if (!(event.target instanceof HTMLElement)) {
|
|
25818
|
+
return;
|
|
25819
|
+
}
|
|
25820
|
+
// Prevent unhandled navigation and bubbling for link clicks
|
|
25821
|
+
const link = event.target.closest('a');
|
|
25822
|
+
if (link) {
|
|
25823
|
+
event.preventDefault();
|
|
25824
|
+
event.stopPropagation();
|
|
25825
|
+
}
|
|
25801
25826
|
},
|
|
25802
25827
|
},
|
|
25803
25828
|
},
|