@krainovsd/markdown-editor 0.3.2 → 0.4.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/cjs/{index-BgxbH3r2.js → index-Df0WnJ4c.js} +470 -54
- package/lib/cjs/index-Df0WnJ4c.js.map +1 -0
- package/lib/cjs/{index-DU8JMAfc.js → index-Ne5xJkxS.js} +10 -6
- package/lib/cjs/index-Ne5xJkxS.js.map +1 -0
- package/lib/cjs/index.js +2 -1
- package/lib/cjs/index.js.map +1 -1
- package/lib/esm/extensions/auto-completes/custom/tag-auto-complete.js +33 -0
- package/lib/esm/extensions/auto-completes/custom/tag-auto-complete.js.map +1 -0
- package/lib/esm/extensions/auto-completes/init-auto-complete.js +27 -0
- package/lib/esm/extensions/auto-completes/init-auto-complete.js.map +1 -0
- package/lib/esm/extensions/init-extensions.js +5 -3
- package/lib/esm/extensions/init-extensions.js.map +1 -1
- package/lib/esm/extensions/keymaps/custom/bold-key-map.js +56 -0
- package/lib/esm/extensions/keymaps/custom/bold-key-map.js.map +1 -0
- package/lib/esm/extensions/keymaps/custom/italic-key-map.js +57 -0
- package/lib/esm/extensions/keymaps/custom/italic-key-map.js.map +1 -0
- package/lib/esm/extensions/keymaps/custom/link-key-map.js +28 -0
- package/lib/esm/extensions/keymaps/custom/link-key-map.js.map +1 -0
- package/lib/esm/extensions/keymaps/init-key-map.js +7 -10
- package/lib/esm/extensions/keymaps/init-key-map.js.map +1 -1
- package/lib/esm/extensions/listeners/get-change-event.js +3 -3
- package/lib/esm/extensions/listeners/get-change-event.js.map +1 -1
- package/lib/esm/extensions/listeners/get-focus-event.js +3 -3
- package/lib/esm/extensions/listeners/get-focus-event.js.map +1 -1
- package/lib/esm/extensions/markdown/blockquote/blockquote-constants.js +1 -1
- package/lib/esm/extensions/markdown/blockquote/blockquote-constants.js.map +1 -1
- package/lib/esm/extensions/markdown/blockquote/blockquote-decoration.js +1 -1
- package/lib/esm/extensions/markdown/blockquote/blockquote-decoration.js.map +1 -1
- package/lib/esm/extensions/markdown/bold/bold-constants.js +1 -1
- package/lib/esm/extensions/markdown/bold/bold-constants.js.map +1 -1
- package/lib/esm/extensions/markdown/bold/bold-decoration.js +1 -1
- package/lib/esm/extensions/markdown/code/code-constants.js +3 -1
- package/lib/esm/extensions/markdown/code/code-constants.js.map +1 -1
- package/lib/esm/extensions/markdown/code/code-decoration.js +34 -3
- package/lib/esm/extensions/markdown/code/code-decoration.js.map +1 -1
- package/lib/esm/extensions/markdown/header/header-decoration.js +1 -1
- package/lib/esm/extensions/markdown/image/image-decoration.js.map +1 -1
- package/lib/esm/extensions/markdown/image/image-widget.js +26 -2
- package/lib/esm/extensions/markdown/image/image-widget.js.map +1 -1
- package/lib/esm/extensions/markdown/italic/italic-decoration.js +2 -2
- package/lib/esm/extensions/markdown/italic/italic-decoration.js.map +1 -1
- package/lib/esm/extensions/markdown/link/link-decoration.js +1 -1
- package/lib/esm/extensions/markdown/link/link-decoration.js.map +1 -1
- package/lib/esm/extensions/markdown/link/link-widget.js +28 -2
- package/lib/esm/extensions/markdown/link/link-widget.js.map +1 -1
- package/lib/esm/extensions/markdown/list/list-decoration.js +1 -1
- package/lib/esm/extensions/markdown/list/list-decoration.js.map +1 -1
- package/lib/esm/extensions/markdown/markdown-decoration.js +2 -2
- package/lib/esm/extensions/markdown/markdown-decoration.js.map +1 -1
- package/lib/esm/extensions/markdown/mention/mention-constants.js +4 -3
- package/lib/esm/extensions/markdown/mention/mention-constants.js.map +1 -1
- package/lib/esm/extensions/markdown/mention/mention-decoration.js +1 -1
- package/lib/esm/extensions/markdown/mention/mention-parser.js +8 -5
- package/lib/esm/extensions/markdown/mention/mention-parser.js.map +1 -1
- package/lib/esm/extensions/markdown/strike-through/strike-through-decoration.js +1 -1
- package/lib/esm/extensions/markdown/styles.module.scss.js +2 -2
- package/lib/esm/extensions/markdown/todo/todo-decoration.js +1 -1
- package/lib/esm/extensions/markdown/todo/todo-decoration.js.map +1 -1
- package/lib/esm/extensions/settings/init-settings.js +2 -2
- package/lib/esm/extensions/settings/init-settings.js.map +1 -1
- package/lib/esm/extensions/theme/theme-constants.js +2 -0
- package/lib/esm/extensions/theme/theme-constants.js.map +1 -1
- package/lib/esm/extensions/theme/themes/get-dark-theme.js +5 -2
- package/lib/esm/extensions/theme/themes/get-dark-theme.js.map +1 -1
- package/lib/esm/extensions/theme/themes/get-highlight-template.js +4 -1
- package/lib/esm/extensions/theme/themes/get-highlight-template.js.map +1 -1
- package/lib/esm/extensions/theme/themes/get-light-theme.js +5 -2
- package/lib/esm/extensions/theme/themes/get-light-theme.js.map +1 -1
- package/lib/esm/extensions/theme/themes/get-theme-template.js +7 -0
- package/lib/esm/extensions/theme/themes/get-theme-template.js.map +1 -1
- package/lib/esm/index.js +1 -0
- package/lib/esm/index.js.map +1 -1
- package/lib/esm/lib/utils/overlap-mark.js +151 -0
- package/lib/esm/lib/utils/overlap-mark.js.map +1 -0
- package/lib/esm/module/Editor/Editor.js +3 -6
- package/lib/esm/module/Editor/Editor.js.map +1 -1
- package/lib/esm/module/Editor/lib/init-editor-provider.js +2 -3
- package/lib/esm/module/Editor/lib/init-editor-provider.js.map +1 -1
- package/lib/esm/module/Editor/lib/init-editor.js +1 -1
- package/lib/esm/module/Editor/lib/init-editor.js.map +1 -1
- package/lib/esm/node_modules/.pnpm/style-inject@0.3.0/node_modules/style-inject/dist/style-inject.es.js.map +1 -1
- package/lib/index.d.ts +11 -2
- package/package.json +19 -29
- package/lib/cjs/index-BgxbH3r2.js.map +0 -1
- package/lib/cjs/index-DU8JMAfc.js.map +0 -1
|
@@ -2,7 +2,9 @@ import { WidgetType } from '@codemirror/view';
|
|
|
2
2
|
import { saveDispatch } from '../../../lib/utils/save-dispatch.js';
|
|
3
3
|
import { openedImageEffect } from '../markdown-state.js';
|
|
4
4
|
import styles from '../styles.module.scss.js';
|
|
5
|
+
import { CODE_OF_START_IMAGE_URL } from './image-constants.js';
|
|
5
6
|
|
|
7
|
+
/* eslint-disable max-params */
|
|
6
8
|
const IMAGE_NODES = {};
|
|
7
9
|
const INTERVAL_DELAY = 10000;
|
|
8
10
|
const EXISTING_WIDGETS = new Set();
|
|
@@ -49,7 +51,7 @@ class ImageWidget extends WidgetType {
|
|
|
49
51
|
this.from = widget.from;
|
|
50
52
|
this.to = widget.to;
|
|
51
53
|
this.registerListeners(image);
|
|
52
|
-
IMAGE_NODES[this.key] =
|
|
54
|
+
IMAGE_NODES[this.key] = container;
|
|
53
55
|
EXISTING_WIDGETS.add(this.key);
|
|
54
56
|
return true;
|
|
55
57
|
}
|
|
@@ -155,8 +157,30 @@ function isCorrectNode(text, link, node) {
|
|
|
155
157
|
textContent.includes(text));
|
|
156
158
|
}
|
|
157
159
|
function selectLink({ link, node, selection, start }) {
|
|
158
|
-
const startPosition = start ??
|
|
160
|
+
const startPosition = start ?? node.textContent?.indexOf?.(link) ?? 0;
|
|
159
161
|
const endPosition = startPosition + link.length;
|
|
162
|
+
if (startPosition === 0 && endPosition === 0) {
|
|
163
|
+
const content = node.textContent;
|
|
164
|
+
if (!content)
|
|
165
|
+
return;
|
|
166
|
+
let startPosition = 0;
|
|
167
|
+
let pos = 0;
|
|
168
|
+
while (pos < content.length) {
|
|
169
|
+
if (content.codePointAt(pos) !== CODE_OF_START_IMAGE_URL) {
|
|
170
|
+
pos++;
|
|
171
|
+
}
|
|
172
|
+
else {
|
|
173
|
+
startPosition = pos + 1;
|
|
174
|
+
break;
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
const range = document.createRange();
|
|
178
|
+
range.setStart(node, startPosition);
|
|
179
|
+
range.collapse(true);
|
|
180
|
+
selection.removeAllRanges();
|
|
181
|
+
selection.addRange(range);
|
|
182
|
+
return;
|
|
183
|
+
}
|
|
160
184
|
const range = document.createRange();
|
|
161
185
|
range.setStart(node, startPosition);
|
|
162
186
|
range.setEnd(node, endPosition);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"image-widget.js","sources":["../../../../../src/extensions/markdown/image/image-widget.ts"],"sourcesContent":["import { type EditorView, WidgetType } from \"@codemirror/view\";\nimport { saveDispatch } from \"@/lib/utils\";\nimport { openedImageEffect } from \"../markdown-state\";\nimport styles from \"../styles.module.scss\";\n\nconst IMAGE_NODES: Record<string, ImageContainerElement | undefined> = {};\nconst INTERVAL_DELAY = 10000;\nconst EXISTING_WIDGETS: Set<string> = new Set();\nlet interval: NodeJS.Timeout | null = null;\ninterface ImageContainerElement extends HTMLSpanElement {\n clearListeners?: () => void;\n destroy?: () => void;\n image?: HTMLImageElement;\n}\n\nexport class ImageWidget extends WidgetType {\n constructor(\n private text: string,\n private link: string,\n private from: number,\n private to: number,\n private uniqueId: string,\n private fullLine: boolean,\n private imageSrcGetter: ((src: string) => string) | undefined,\n private view: EditorView,\n ) {\n super();\n }\n\n get key() {\n return `${this.link}:${this.text}:${this.uniqueId}:${this.from}:${this.to}`;\n }\n\n get src() {\n return this.imageSrcGetter ? this.imageSrcGetter(this.link) : this.link;\n }\n\n eq(widget: ImageWidget): boolean {\n const container = IMAGE_NODES[this.key];\n const image = container?.image;\n\n if (!image) return false;\n\n delete IMAGE_NODES[this.key];\n EXISTING_WIDGETS.delete(this.key);\n\n if (image.src !== widget.src) image.src = widget.src;\n if (image.alt !== widget.text) image.alt = widget.text;\n\n this.link = widget.link;\n this.text = widget.text;\n this.from = widget.from;\n this.to = widget.to;\n\n this.registerListeners(image);\n IMAGE_NODES[this.key] = image;\n EXISTING_WIDGETS.add(this.key);\n\n return true;\n }\n\n updateDOM(): boolean {\n return true;\n }\n\n toDOM(): HTMLElement {\n EXISTING_WIDGETS.add(this.key);\n let container = IMAGE_NODES[this.key];\n let image = container?.image;\n\n if (image && container) {\n if (image.src !== this.src) {\n image.src = this.src;\n }\n if (image.alt !== this.text) image.alt = this.text;\n\n return container;\n }\n\n image = document.createElement(\"img\");\n image.classList.add(styles.image);\n image.alt = this.text;\n image.src = this.src;\n image.style.maxWidth = \"100%\";\n\n container = document.createElement(\"span\") as ImageContainerElement;\n container.appendChild(image);\n container.image = image;\n if (this.fullLine) {\n container.style.width = \"100%\";\n container.style.display = \"inline-block\";\n }\n\n this.registerListeners(container);\n IMAGE_NODES[this.key] = container;\n\n if (!interval) interval = setInterval(garbageCollectorInterval, INTERVAL_DELAY);\n\n return container;\n }\n\n destroy(): void {\n EXISTING_WIDGETS.delete(this.key);\n }\n\n registerListeners(image: ImageContainerElement) {\n image.clearListeners?.();\n const abortController = new AbortController();\n image.addEventListener(\n \"mousedown\",\n (event) => handleClick(this.view, this.text, this.link, this.key, event),\n { signal: abortController.signal },\n );\n image.clearListeners = () => {\n abortController.abort();\n };\n image.destroy = () => {\n image.clearListeners?.();\n image.remove();\n };\n }\n}\n\n/** for disable cache */\nfunction garbageCollectorInterval() {\n for (const [key, node] of Object.entries(IMAGE_NODES)) {\n if (EXISTING_WIDGETS.has(key) || !node) continue;\n delete IMAGE_NODES[key];\n node.destroy?.();\n }\n\n if (Object.keys(IMAGE_NODES).length === 0 && interval) {\n clearInterval(interval);\n interval = null;\n }\n}\n\n/** recursively find the link text node in line */\nfunction getTextNode(\n text: string,\n link: string,\n key: string,\n line: ChildNode | Node | null | undefined,\n): ChildNode | null {\n if (!line) return null;\n const textNodeContainer = getTextNodeContainer(text, link, key, line);\n if (!textNodeContainer) return null;\n\n for (const node of Array.from(textNodeContainer.childNodes)) {\n if (isCorrectNode(text, link, node)) {\n return node;\n }\n }\n\n return null;\n}\n\nfunction getTextNodeContainer(\n text: string,\n link: string,\n key: string,\n line: ChildNode | Node | null | undefined,\n): HTMLElement | null {\n if (!line) return null;\n\n for (const node of Array.from(line.childNodes)) {\n if (node instanceof HTMLElement && node.getAttribute(\"data-id\") === key) {\n return node;\n }\n\n if (node.nodeType !== 3) {\n const inner = getTextNodeContainer(text, link, key, node);\n if (inner) return inner;\n }\n }\n\n return null;\n}\n\nfunction isCorrectNode(\n text: string,\n link: string,\n node: ChildNode | Node | null | undefined,\n): node is ChildNode | Node {\n if (!node) return false;\n\n const textContent = node?.textContent;\n\n return Boolean(\n node &&\n textContent &&\n node.nodeType === 3 &&\n textContent.includes(link) &&\n textContent.includes(text),\n );\n}\n\ntype SelectLinkOptions = {\n node: ChildNode | Node;\n selection: Selection;\n start?: number;\n link: string;\n};\nfunction selectLink({ link, node, selection, start }: SelectLinkOptions) {\n const startPosition = start ?? (node.textContent?.indexOf?.(link) || 0);\n const endPosition = startPosition + link.length;\n\n const range = document.createRange();\n range.setStart(node, startPosition);\n range.setEnd(node, endPosition);\n selection.removeAllRanges();\n selection.addRange(range);\n}\n\nfunction handleClick(\n view: EditorView | undefined,\n text: string,\n link: string,\n key: string,\n event: MouseEvent,\n) {\n const selection = window.getSelection();\n\n if (event.shiftKey || event.ctrlKey || event.altKey || event.metaKey) {\n return;\n }\n\n event.stopPropagation();\n event.preventDefault();\n const target = event.target as HTMLImageElement;\n const parent = target.parentNode;\n let line: HTMLElement | null = parent as HTMLElement | null;\n\n /** recursively find line that contains link */\n while (line && !line.classList.contains(\"cm-line\")) {\n line = line.parentNode as HTMLElement | null;\n }\n\n const editor = Array.from(document.querySelectorAll(\".cm-editor\")).find((element) =>\n element.contains(target),\n );\n\n if (!selection || !editor || !parent) return;\n\n const textNode = getTextNode(text, link, key, line);\n\n if (textNode) {\n return void selectLink({ selection, link, node: textNode });\n }\n\n saveDispatch(() => {\n if (!view) return;\n view.dispatch(view.state.update({ effects: openedImageEffect.of(key) }));\n\n const textNode = getTextNode(text, link, key, line);\n if (textNode) {\n selectLink({ selection, link, node: textNode });\n }\n\n requestAnimationFrame(() => {\n saveDispatch(() => {\n if (view) view.dispatch(view.state.update({ effects: openedImageEffect.of(undefined) }));\n });\n });\n });\n\n return false;\n}\n"],"names":[],"mappings":";;;;;AAKA,MAAM,WAAW,GAAsD,EAAE;AACzE,MAAM,cAAc,GAAG,KAAK;AAC5B,MAAM,gBAAgB,GAAgB,IAAI,GAAG,EAAE;AAC/C,IAAI,QAAQ,GAA0B,IAAI;A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,EAAE,IAAI,EAAE,QAAQ,EAAE,CAAC;;IAG7D,YAAY,CAAC,MAAK;AAChB,QAAA,IAAI,CAAC,IAAI;YAAE;QACX,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,EAAE,OAAO,EAAE,iBAAiB,CAAC,EAAE,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC;AAExE,QAAA,MAAM,QAAQ,GAAG,WAAW,CAAC,IAAI,EAAE,IAAI,EAAE,GAAG,EAAE,IAAI,CAAC;QACnD,IAAI,QAAQ,EAAE;YACZ,UAAU,CAAC,EAAE,SAAS,EAAE,IAAI,EAAE,IAAI,EAAE,QAAQ,EAAE,CAAC;;QAGjD,qBAAqB,CAAC,MAAK;YACzB,YAAY,CAAC,MAAK;AAChB,gBAAA,IAAI,IAAI;oBAAE,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,EAAE,OAAO,EAAE,iBAAiB,CAAC,EAAE,CAAC,SAAS,CAAC,EAAE,CAAC,CAAC;AAC1F,aAAC,CAAC;AACJ,SAAC,CAAC;AACJ,KAAC,CAAC;AAEF,IAAA,OAAO,KAAK;AACd;;;;"}
|
|
1
|
+
{"version":3,"file":"image-widget.js","sources":["../../../../../src/extensions/markdown/image/image-widget.ts"],"sourcesContent":["/* eslint-disable max-params */\nimport { type EditorView, WidgetType } from \"@codemirror/view\";\nimport { saveDispatch } from \"@/lib/utils\";\nimport { openedImageEffect } from \"../markdown-state\";\nimport styles from \"../styles.module.scss\";\nimport { CODE_OF_START_IMAGE_URL } from \"./image-constants\";\n\nconst IMAGE_NODES: Record<string, ImageContainerElement | undefined> = {};\nconst INTERVAL_DELAY = 10000;\nconst EXISTING_WIDGETS = new Set<string>();\nlet interval: NodeJS.Timeout | null = null;\ninterface ImageContainerElement extends HTMLSpanElement {\n clearListeners?: () => void;\n destroy?: () => void;\n image?: HTMLImageElement;\n}\n\nexport class ImageWidget extends WidgetType {\n constructor(\n private text: string,\n private link: string,\n private from: number,\n private to: number,\n private uniqueId: string,\n private fullLine: boolean,\n private imageSrcGetter: ((src: string) => string) | undefined,\n private view: EditorView,\n ) {\n super();\n }\n\n get key() {\n return `${this.link}:${this.text}:${this.uniqueId}:${this.from}:${this.to}`;\n }\n\n get src() {\n return this.imageSrcGetter ? this.imageSrcGetter(this.link) : this.link;\n }\n\n eq(widget: ImageWidget): boolean {\n const container = IMAGE_NODES[this.key];\n const image = container?.image;\n\n if (!image) return false;\n\n delete IMAGE_NODES[this.key];\n EXISTING_WIDGETS.delete(this.key);\n\n if (image.src !== widget.src) image.src = widget.src;\n if (image.alt !== widget.text) image.alt = widget.text;\n\n this.link = widget.link;\n this.text = widget.text;\n this.from = widget.from;\n this.to = widget.to;\n\n this.registerListeners(image);\n IMAGE_NODES[this.key] = container;\n EXISTING_WIDGETS.add(this.key);\n\n return true;\n }\n\n updateDOM(): boolean {\n return true;\n }\n\n toDOM(): HTMLElement {\n EXISTING_WIDGETS.add(this.key);\n let container = IMAGE_NODES[this.key];\n let image = container?.image;\n\n if (image && container) {\n if (image.src !== this.src) {\n image.src = this.src;\n }\n if (image.alt !== this.text) image.alt = this.text;\n\n return container;\n }\n\n image = document.createElement(\"img\");\n image.classList.add(styles.image);\n image.alt = this.text;\n image.src = this.src;\n image.style.maxWidth = \"100%\";\n\n container = document.createElement(\"span\") as ImageContainerElement;\n container.appendChild(image);\n container.image = image;\n if (this.fullLine) {\n container.style.width = \"100%\";\n container.style.display = \"inline-block\";\n }\n\n this.registerListeners(container);\n IMAGE_NODES[this.key] = container;\n\n if (!interval) interval = setInterval(garbageCollectorInterval, INTERVAL_DELAY);\n\n return container;\n }\n\n destroy(): void {\n EXISTING_WIDGETS.delete(this.key);\n }\n\n registerListeners(image: ImageContainerElement) {\n image.clearListeners?.();\n const abortController = new AbortController();\n image.addEventListener(\n \"mousedown\",\n (event) => handleClick(this.view, this.text, this.link, this.key, event),\n { signal: abortController.signal },\n );\n image.clearListeners = () => {\n abortController.abort();\n };\n image.destroy = () => {\n image.clearListeners?.();\n image.remove();\n };\n }\n}\n\n/** for disable cache */\nfunction garbageCollectorInterval() {\n for (const [key, node] of Object.entries(IMAGE_NODES)) {\n if (EXISTING_WIDGETS.has(key) || !node) continue;\n delete IMAGE_NODES[key];\n node.destroy?.();\n }\n\n if (Object.keys(IMAGE_NODES).length === 0 && interval) {\n clearInterval(interval);\n interval = null;\n }\n}\n\n/** recursively find the link text node in line */\nfunction getTextNode(\n text: string,\n link: string,\n key: string,\n line: ChildNode | Node | null | undefined,\n): ChildNode | null {\n if (!line) return null;\n const textNodeContainer = getTextNodeContainer(text, link, key, line);\n if (!textNodeContainer) return null;\n\n for (const node of Array.from(textNodeContainer.childNodes)) {\n if (isCorrectNode(text, link, node)) {\n return node;\n }\n }\n\n return null;\n}\n\nfunction getTextNodeContainer(\n text: string,\n link: string,\n key: string,\n line: ChildNode | Node | null | undefined,\n): HTMLElement | null {\n if (!line) return null;\n\n for (const node of Array.from(line.childNodes)) {\n if (node instanceof HTMLElement && node.getAttribute(\"data-id\") === key) {\n return node;\n }\n\n if (node.nodeType !== 3) {\n const inner = getTextNodeContainer(text, link, key, node);\n if (inner) return inner;\n }\n }\n\n return null;\n}\n\nfunction isCorrectNode(\n text: string,\n link: string,\n node: ChildNode | Node | null | undefined,\n): node is ChildNode | Node {\n if (!node) return false;\n\n const textContent = node?.textContent;\n\n return Boolean(\n node &&\n textContent &&\n node.nodeType === 3 &&\n textContent.includes(link) &&\n textContent.includes(text),\n );\n}\n\ntype SelectLinkOptions = {\n node: ChildNode | Node;\n selection: Selection;\n start?: number;\n link: string;\n};\nfunction selectLink({ link, node, selection, start }: SelectLinkOptions) {\n const startPosition = start ?? node.textContent?.indexOf?.(link) ?? 0;\n const endPosition = startPosition + link.length;\n\n if (startPosition === 0 && endPosition === 0) {\n const content = node.textContent;\n if (!content) return;\n let startPosition = 0;\n let pos = 0;\n\n while (pos < content.length) {\n if (content.codePointAt(pos) !== CODE_OF_START_IMAGE_URL) {\n pos++;\n } else {\n startPosition = pos + 1;\n break;\n }\n }\n\n const range = document.createRange();\n range.setStart(node, startPosition);\n range.collapse(true);\n selection.removeAllRanges();\n selection.addRange(range);\n\n return;\n }\n\n const range = document.createRange();\n range.setStart(node, startPosition);\n range.setEnd(node, endPosition);\n selection.removeAllRanges();\n selection.addRange(range);\n}\n\nfunction handleClick(\n view: EditorView | undefined,\n text: string,\n link: string,\n key: string,\n event: MouseEvent,\n) {\n const selection = window.getSelection();\n\n if (event.shiftKey || event.ctrlKey || event.altKey || event.metaKey) {\n return;\n }\n\n event.stopPropagation();\n event.preventDefault();\n const target = event.target as HTMLImageElement;\n const parent = target.parentNode;\n let line: HTMLElement | null = parent as HTMLElement | null;\n\n /** recursively find line that contains link */\n while (line && !line.classList.contains(\"cm-line\")) {\n line = line.parentNode as HTMLElement | null;\n }\n\n const editor = Array.from(document.querySelectorAll(\".cm-editor\")).find((element) =>\n element.contains(target),\n );\n\n if (!selection || !editor || !parent) return;\n\n const textNode = getTextNode(text, link, key, line);\n\n if (textNode) {\n return void selectLink({ selection, link, node: textNode });\n }\n\n saveDispatch(() => {\n if (!view) return;\n view.dispatch(view.state.update({ effects: openedImageEffect.of(key) }));\n\n const textNode = getTextNode(text, link, key, line);\n if (textNode) {\n selectLink({ selection, link, node: textNode });\n }\n\n requestAnimationFrame(() => {\n saveDispatch(() => {\n if (view) view.dispatch(view.state.update({ effects: openedImageEffect.of(undefined) }));\n });\n });\n });\n\n return false;\n}\n"],"names":[],"mappings":";;;;;;AAAA;AAOA,MAAM,WAAW,GAAsD,EAAE;AACzE,MAAM,cAAc,GAAG,KAAK;AAC5B,MAAM,gBAAgB,GAAG,IAAI,GAAG,EAAU;AAC1C,IAAI,QAAQ,GAA0B,IAAI;AAOpC,MAAO,WAAY,SAAQ,UAAU,CAAA;AAE/B,IAAA,IAAA;AACA,IAAA,IAAA;AACA,IAAA,IAAA;AACA,IAAA,EAAA;AACA,IAAA,QAA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AAC;AACJ,KAAC,CAAC;AAEF,IAAA,OAAO,KAAK;AACd;;;;"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { getHideDecoration, getMarkDecoration } from '../../../lib/utils/get-decoration.js';
|
|
2
2
|
import { isInRange } from '../../../lib/utils/is-in-range.js';
|
|
3
3
|
import styles from '../styles.module.scss.js';
|
|
4
4
|
import { NAME_OF_ITALIC, LIST_OF_ITALIC_MARKS } from './italic-constants.js';
|
|
@@ -16,7 +16,7 @@ function getItalicSelectionDecorations({ decorations, node, view, forceActive, s
|
|
|
16
16
|
if (node.name !== NAME_OF_ITALIC) {
|
|
17
17
|
return;
|
|
18
18
|
}
|
|
19
|
-
if (checkIsSeveralEmphasis({
|
|
19
|
+
if (checkIsSeveralEmphasis({ node, view})) {
|
|
20
20
|
return void splitEmphasis({ decorations, node, view, forceActive, settings });
|
|
21
21
|
}
|
|
22
22
|
let step = 1;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"italic-decoration.js","sources":["../../../../../src/extensions/markdown/italic/italic-decoration.ts"],"sourcesContent":["import { utils } from \"@/lib\";\nimport type {\n DecorationPlugin,\n GetDecorationOptions,\n GetSelectionDecorationOptions,\n} from \"../markdown-types\";\nimport styles from \"../styles.module.scss\";\nimport { LIST_OF_ITALIC_MARKS, NAME_OF_ITALIC } from \"./italic-constants\";\n\nfunction getItalicDecorations({ decorations, node }: GetDecorationOptions) {\n if (node.name !== NAME_OF_ITALIC) {\n return;\n }\n\n decorations.push(\n utils.getMarkDecoration({\n style: styles.italic,\n range: [node.from, node.to],\n }),\n );\n}\n\nfunction getItalicSelectionDecorations({\n decorations,\n node,\n view,\n forceActive,\n settings,\n}: GetSelectionDecorationOptions) {\n if (node.name !== NAME_OF_ITALIC) {\n return;\n }\n\n if (checkIsSeveralEmphasis({ decorations, node, view, forceActive, settings })) {\n return void splitEmphasis({ decorations, node, view, forceActive, settings });\n }\n\n let step = 1;\n const startText = view.state.doc.sliceString(node.from, node.from + 3);\n if (\n LIST_OF_ITALIC_MARKS.has(startText.charCodeAt(0)) &&\n LIST_OF_ITALIC_MARKS.has(startText.charCodeAt(1)) &&\n LIST_OF_ITALIC_MARKS.has(startText.charCodeAt(2))\n )\n step = 3;\n\n if (\n forceActive ||\n !view.hasFocus ||\n !utils.isInRange(view.state.selection.ranges, [node.from, node.to])\n ) {\n decorations.push(utils.getHideDecoration({ range: [node.from, node.from + step] }));\n decorations.push(utils.getHideDecoration({ range: [node.to - step, node.to] }));\n }\n}\n\n/** Fixed wide italic + italic */\nfunction checkIsSeveralEmphasis({ node, view }: GetSelectionDecorationOptions) {\n let marks = 0;\n let pos = 0;\n\n const text = view.state.doc.sliceString(node.from, node.to);\n\n while (pos <= text.length) {\n if (LIST_OF_ITALIC_MARKS.has(text.charCodeAt(pos))) marks++;\n pos++;\n }\n\n if (marks === 8) return true;\n\n return false;\n}\n\nfunction splitEmphasis({\n decorations,\n node,\n view,\n forceActive,\n settings,\n}: GetSelectionDecorationOptions) {\n const text = view.state.doc.sliceString(node.from, node.to);\n let marks = 0;\n let pos = 0;\n\n while (pos <= text.length && marks < 6) {\n if (LIST_OF_ITALIC_MARKS.has(text.charCodeAt(pos))) marks++;\n pos++;\n }\n\n getItalicSelectionDecorations({\n decorations,\n view,\n node: { ...node, name: node.name, from: node.from, to: node.from + pos },\n forceActive,\n settings,\n });\n getItalicSelectionDecorations({\n decorations,\n view,\n node: { ...node, name: node.name, from: node.from + pos, to: node.to },\n forceActive,\n settings,\n });\n}\n\nexport const italicDecorationPlugin: DecorationPlugin = {\n decorations: [getItalicDecorations],\n selectionDecorations: [getItalicSelectionDecorations],\n};\n"],"names":["utils.getMarkDecoration","utils.isInRange","utils.getHideDecoration"],"mappings":";;;;;AASA,SAAS,oBAAoB,CAAC,EAAE,WAAW,EAAE,IAAI,EAAwB,EAAA;AACvE,IAAA,IAAI,IAAI,CAAC,IAAI,KAAK,cAAc,EAAE;QAChC;;AAGF,IAAA,WAAW,CAAC,IAAI,CACdA,iBAAuB,CAAC;QACtB,KAAK,EAAE,MAAM,CAAC,MAAM;QACpB,KAAK,EAAE,CAAC,IAAI,CAAC,IAAI,EAAE,IAAI,CAAC,EAAE,CAAC;AAC5B,KAAA,CAAC,CACH;AACH;AAEA,SAAS,6BAA6B,CAAC,EACrC,WAAW,EACX,IAAI,EACJ,IAAI,EACJ,WAAW,EACX,QAAQ,GACsB,EAAA;AAC9B,IAAA,IAAI,IAAI,CAAC,IAAI,KAAK,cAAc,EAAE;QAChC;;AAGF,IAAA,IAAI,sBAAsB,CAAC,
|
|
1
|
+
{"version":3,"file":"italic-decoration.js","sources":["../../../../../src/extensions/markdown/italic/italic-decoration.ts"],"sourcesContent":["import { utils } from \"@/lib\";\nimport type {\n DecorationPlugin,\n GetDecorationOptions,\n GetSelectionDecorationOptions,\n} from \"../markdown-types\";\nimport styles from \"../styles.module.scss\";\nimport { LIST_OF_ITALIC_MARKS, NAME_OF_ITALIC } from \"./italic-constants\";\n\nfunction getItalicDecorations({ decorations, node }: GetDecorationOptions) {\n if (node.name !== NAME_OF_ITALIC) {\n return;\n }\n\n decorations.push(\n utils.getMarkDecoration({\n style: styles.italic,\n range: [node.from, node.to],\n }),\n );\n}\n\nfunction getItalicSelectionDecorations({\n decorations,\n node,\n view,\n forceActive,\n settings,\n}: GetSelectionDecorationOptions) {\n if (node.name !== NAME_OF_ITALIC) {\n return;\n }\n\n if (checkIsSeveralEmphasis({ decorations, node, view, forceActive, settings })) {\n return void splitEmphasis({ decorations, node, view, forceActive, settings });\n }\n\n let step = 1;\n const startText = view.state.doc.sliceString(node.from, node.from + 3);\n if (\n LIST_OF_ITALIC_MARKS.has(startText.charCodeAt(0)) &&\n LIST_OF_ITALIC_MARKS.has(startText.charCodeAt(1)) &&\n LIST_OF_ITALIC_MARKS.has(startText.charCodeAt(2))\n )\n step = 3;\n\n if (\n forceActive ||\n !view.hasFocus ||\n !utils.isInRange(view.state.selection.ranges, [node.from, node.to])\n ) {\n decorations.push(utils.getHideDecoration({ range: [node.from, node.from + step] }));\n decorations.push(utils.getHideDecoration({ range: [node.to - step, node.to] }));\n }\n}\n\n/** Fixed wide italic + italic */\nfunction checkIsSeveralEmphasis({ node, view }: GetSelectionDecorationOptions) {\n let marks = 0;\n let pos = 0;\n\n const text = view.state.doc.sliceString(node.from, node.to);\n\n while (pos <= text.length) {\n if (LIST_OF_ITALIC_MARKS.has(text.charCodeAt(pos))) marks++;\n pos++;\n }\n\n if (marks === 8) return true;\n\n return false;\n}\n\nfunction splitEmphasis({\n decorations,\n node,\n view,\n forceActive,\n settings,\n}: GetSelectionDecorationOptions) {\n const text = view.state.doc.sliceString(node.from, node.to);\n let marks = 0;\n let pos = 0;\n\n while (pos <= text.length && marks < 6) {\n if (LIST_OF_ITALIC_MARKS.has(text.charCodeAt(pos))) marks++;\n pos++;\n }\n\n getItalicSelectionDecorations({\n decorations,\n view,\n node: { ...node, name: node.name, from: node.from, to: node.from + pos },\n forceActive,\n settings,\n });\n getItalicSelectionDecorations({\n decorations,\n view,\n node: { ...node, name: node.name, from: node.from + pos, to: node.to },\n forceActive,\n settings,\n });\n}\n\nexport const italicDecorationPlugin: DecorationPlugin = {\n decorations: [getItalicDecorations],\n selectionDecorations: [getItalicSelectionDecorations],\n};\n"],"names":["utils.getMarkDecoration","utils.isInRange","utils.getHideDecoration"],"mappings":";;;;;AASA,SAAS,oBAAoB,CAAC,EAAE,WAAW,EAAE,IAAI,EAAwB,EAAA;AACvE,IAAA,IAAI,IAAI,CAAC,IAAI,KAAK,cAAc,EAAE;QAChC;;AAGF,IAAA,WAAW,CAAC,IAAI,CACdA,iBAAuB,CAAC;QACtB,KAAK,EAAE,MAAM,CAAC,MAAM;QACpB,KAAK,EAAE,CAAC,IAAI,CAAC,IAAI,EAAE,IAAI,CAAC,EAAE,CAAC;AAC5B,KAAA,CAAC,CACH;AACH;AAEA,SAAS,6BAA6B,CAAC,EACrC,WAAW,EACX,IAAI,EACJ,IAAI,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,IAAA,6BAA6B,CAAC;QAC5B,WAAW;QACX,IAAI;QACJ,IAAI,EAAE,EAAE,GAAG,IAAI,EAAE,IAAI,EAAE,IAAI,CAAC,IAAI,EAAE,IAAI,EAAE,IAAI,CAAC,IAAI,GAAG,GAAG,EAAE,EAAE,EAAE,IAAI,CAAC,EAAE,EAAE;QACtE,WAAW;QACX,QAAQ;AACT,KAAA,CAAC;AACJ;AAEa,MAAA,sBAAsB,GAAqB;IACtD,WAAW,EAAE,CAAC,oBAAoB,CAAC;IACnC,oBAAoB,EAAE,CAAC,6BAA6B,CAAC;;;;;"}
|
|
@@ -32,7 +32,7 @@ function getLinkSelectionDecorations({ decorations, node, view, forceActive, set
|
|
|
32
32
|
urlCoordinates.to = pos;
|
|
33
33
|
}
|
|
34
34
|
if (urlCoordinates.from === -1 || urlCoordinates.to === -1)
|
|
35
|
-
return void getLinkLabelSelectionDecoration({ decorations, forceActive, node, view
|
|
35
|
+
return void getLinkLabelSelectionDecoration({ decorations, forceActive, node, view});
|
|
36
36
|
const text = content.substring(textCoordinates.from, textCoordinates.to);
|
|
37
37
|
const url = content.substring(urlCoordinates.from, urlCoordinates.to);
|
|
38
38
|
const openedLink = view.state.field(markdownState).openedLink;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"link-decoration.js","sources":["../../../../../src/extensions/markdown/link/link-decoration.ts"],"sourcesContent":["import { utils } from \"@/lib\";\nimport { markdownState } from \"../markdown-state\";\nimport type { DecorationPlugin, GetSelectionDecorationOptions } from \"../markdown-types\";\nimport {\n CODE_OF_END_LINK_TEXT,\n CODE_OF_END_LINK_URL,\n CODE_OF_START_LINK_TEXT,\n CODE_OF_START_LINK_URL,\n NAME_OF_LINK,\n} from \"./link-constants\";\nimport { getLinkLabelSelectionDecoration } from \"./link-label-decoration\";\nimport { LinkWidget } from \"./link-widget\";\n\nfunction getLinkSelectionDecorations({\n decorations,\n node,\n view,\n forceActive,\n settings,\n}: GetSelectionDecorationOptions) {\n if (node.name !== NAME_OF_LINK) {\n return;\n }\n\n const content = view.state.doc.sliceString(node.from, node.to);\n const textCoordinates = { from: -1, to: -1 };\n const urlCoordinates = { from: -1, to: -1 };\n let pos = -1;\n\n while (pos < content.length) {\n pos++;\n const code = content.charCodeAt(pos);\n\n if (textCoordinates.from === -1 && code === CODE_OF_START_LINK_TEXT)\n textCoordinates.from = pos + 1;\n else if (\n urlCoordinates.from === -1 &&\n textCoordinates.to !== -1 &&\n code === CODE_OF_START_LINK_URL\n )\n urlCoordinates.from = pos + 1;\n else if (\n textCoordinates.from !== -1 &&\n textCoordinates.to === -1 &&\n code === CODE_OF_END_LINK_TEXT\n )\n textCoordinates.to = pos;\n else if (\n urlCoordinates.from !== -1 &&\n urlCoordinates.to === -1 &&\n code === CODE_OF_END_LINK_URL\n )\n urlCoordinates.to = pos;\n }\n\n if (urlCoordinates.from === -1 || urlCoordinates.to === -1)\n return void getLinkLabelSelectionDecoration({ decorations, forceActive, node, view, settings });\n\n const text = content.substring(textCoordinates.from, textCoordinates.to);\n const url = content.substring(urlCoordinates.from, urlCoordinates.to);\n\n const openedLink = view.state.field(markdownState).openedLink;\n const uniqueId = view.state.field(markdownState).uniqueId;\n const key = `${url}:${text}:${uniqueId}:${node.from}:${node.to}`;\n const isOpened = openedLink && openedLink === key;\n\n if (isOpened) {\n return void decorations.push(\n utils.getMarkDecoration({\n range: [node.from, node.to],\n attributes: {\n \"data-id\": key,\n },\n }),\n );\n }\n\n if (\n forceActive ||\n !view.hasFocus ||\n !utils.isInRange(view.state.selection.ranges, [node.from, node.to])\n ) {\n decorations.push(\n utils.getReplaceDecoration({\n range: [node.from, node.to],\n widget: new LinkWidget(text, url, node.from, node.to, uniqueId, view),\n }),\n );\n } else {\n decorations.push(\n utils.getMarkDecoration({\n range: [node.from, node.to],\n attributes: {\n \"data-id\": key,\n },\n }),\n );\n }\n}\n\nexport const linkDecorationPlugin: DecorationPlugin = {\n selectionDecorations: [getLinkSelectionDecorations],\n};\n"],"names":["utils.getMarkDecoration","utils.isInRange","utils.getReplaceDecoration"],"mappings":";;;;;;;AAaA,SAAS,2BAA2B,CAAC,EACnC,WAAW,EACX,IAAI,EACJ,IAAI,EACJ,WAAW,EACX,QAAQ,GACsB,EAAA;AAC9B,IAAA,IAAI,IAAI,CAAC,IAAI,KAAK,YAAY,EAAE;QAC9B;;AAGF,IAAA,MAAM,OAAO,GAAG,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,WAAW,CAAC,IAAI,CAAC,IAAI,EAAE,IAAI,CAAC,EAAE,CAAC;AAC9D,IAAA,MAAM,eAAe,GAAG,EAAE,IAAI,EAAE,
|
|
1
|
+
{"version":3,"file":"link-decoration.js","sources":["../../../../../src/extensions/markdown/link/link-decoration.ts"],"sourcesContent":["import { utils } from \"@/lib\";\nimport { markdownState } from \"../markdown-state\";\nimport type { DecorationPlugin, GetSelectionDecorationOptions } from \"../markdown-types\";\nimport {\n CODE_OF_END_LINK_TEXT,\n CODE_OF_END_LINK_URL,\n CODE_OF_START_LINK_TEXT,\n CODE_OF_START_LINK_URL,\n NAME_OF_LINK,\n} from \"./link-constants\";\nimport { getLinkLabelSelectionDecoration } from \"./link-label-decoration\";\nimport { LinkWidget } from \"./link-widget\";\n\nfunction getLinkSelectionDecorations({\n decorations,\n node,\n view,\n forceActive,\n settings,\n}: GetSelectionDecorationOptions) {\n if (node.name !== NAME_OF_LINK) {\n return;\n }\n\n const content = view.state.doc.sliceString(node.from, node.to);\n const textCoordinates = { from: -1, to: -1 };\n const urlCoordinates = { from: -1, to: -1 };\n let pos = -1;\n\n while (pos < content.length) {\n pos++;\n const code = content.charCodeAt(pos);\n\n if (textCoordinates.from === -1 && code === CODE_OF_START_LINK_TEXT)\n textCoordinates.from = pos + 1;\n else if (\n urlCoordinates.from === -1 &&\n textCoordinates.to !== -1 &&\n code === CODE_OF_START_LINK_URL\n )\n urlCoordinates.from = pos + 1;\n else if (\n textCoordinates.from !== -1 &&\n textCoordinates.to === -1 &&\n code === CODE_OF_END_LINK_TEXT\n )\n textCoordinates.to = pos;\n else if (\n urlCoordinates.from !== -1 &&\n urlCoordinates.to === -1 &&\n code === CODE_OF_END_LINK_URL\n )\n urlCoordinates.to = pos;\n }\n\n if (urlCoordinates.from === -1 || urlCoordinates.to === -1)\n return void getLinkLabelSelectionDecoration({ decorations, forceActive, node, view, settings });\n\n const text = content.substring(textCoordinates.from, textCoordinates.to);\n const url = content.substring(urlCoordinates.from, urlCoordinates.to);\n\n const openedLink = view.state.field(markdownState).openedLink;\n const uniqueId = view.state.field(markdownState).uniqueId;\n const key = `${url}:${text}:${uniqueId}:${node.from}:${node.to}`;\n const isOpened = openedLink && openedLink === key;\n\n if (isOpened) {\n return void decorations.push(\n utils.getMarkDecoration({\n range: [node.from, node.to],\n attributes: {\n \"data-id\": key,\n },\n }),\n );\n }\n\n if (\n forceActive ||\n !view.hasFocus ||\n !utils.isInRange(view.state.selection.ranges, [node.from, node.to])\n ) {\n decorations.push(\n utils.getReplaceDecoration({\n range: [node.from, node.to],\n widget: new LinkWidget(text, url, node.from, node.to, uniqueId, view),\n }),\n );\n } else {\n decorations.push(\n utils.getMarkDecoration({\n range: [node.from, node.to],\n attributes: {\n \"data-id\": key,\n },\n }),\n );\n }\n}\n\nexport const linkDecorationPlugin: DecorationPlugin = {\n selectionDecorations: [getLinkSelectionDecorations],\n};\n"],"names":["utils.getMarkDecoration","utils.isInRange","utils.getReplaceDecoration"],"mappings":";;;;;;;AAaA,SAAS,2BAA2B,CAAC,EACnC,WAAW,EACX,IAAI,EACJ,IAAI,EACJ,WAAW,EACX,QAAQ,GACsB,EAAA;AAC9B,IAAA,IAAI,IAAI,CAAC,IAAI,KAAK,YAAY,EAAE;QAC9B;;AAGF,IAAA,MAAM,OAAO,GAAG,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,WAAW,CAAC,IAAI,CAAC,IAAI,EAAE,IAAI,CAAC,EAAE,CAAC;AAC9D,IAAA,MAAM,eAAe,GAAG,EAAE,IAAI,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CAAC,CACH;;SACI;AACL,QAAA,WAAW,CAAC,IAAI,CACdF,iBAAuB,CAAC;YACtB,KAAK,EAAE,CAAC,IAAI,CAAC,IAAI,EAAE,IAAI,CAAC,EAAE,CAAC;AAC3B,YAAA,UAAU,EAAE;AACV,gBAAA,SAAS,EAAE,GAAG;AACf,aAAA;AACF,SAAA,CAAC,CACH;;AAEL;AAEa,MAAA,oBAAoB,GAAqB;IACpD,oBAAoB,EAAE,CAAC,2BAA2B,CAAC;;;;;"}
|
|
@@ -6,7 +6,9 @@ import { CLASSES } from '../../theme/theme-constants.js';
|
|
|
6
6
|
import { saveDispatch } from '../../../lib/utils/save-dispatch.js';
|
|
7
7
|
import { openedLinkEffect } from '../markdown-state.js';
|
|
8
8
|
import styles from '../styles.module.scss.js';
|
|
9
|
+
import { CODE_OF_START_LINK_URL } from './link-constants.js';
|
|
9
10
|
|
|
11
|
+
/* eslint-disable max-params */
|
|
10
12
|
const LINK_NODES = {};
|
|
11
13
|
class LinkWidget extends WidgetType {
|
|
12
14
|
text;
|
|
@@ -63,7 +65,9 @@ class LinkWidget extends WidgetType {
|
|
|
63
65
|
anchor.clearListeners?.();
|
|
64
66
|
const abortController = new AbortController();
|
|
65
67
|
anchor.addEventListener("mousedown", (event) => handleClick(this.view, this.text, this.link, this.key, event), { signal: abortController.signal });
|
|
66
|
-
anchor.addEventListener("click", (
|
|
68
|
+
anchor.addEventListener("click", (event) => event.preventDefault(), {
|
|
69
|
+
signal: abortController.signal,
|
|
70
|
+
});
|
|
67
71
|
anchor.clearListeners = () => {
|
|
68
72
|
abortController.abort();
|
|
69
73
|
};
|
|
@@ -113,8 +117,30 @@ function isCorrectNode(text, link, node) {
|
|
|
113
117
|
textContent.includes(text));
|
|
114
118
|
}
|
|
115
119
|
function selectLink({ link, node, selection, start }) {
|
|
116
|
-
const startPosition = start ??
|
|
120
|
+
const startPosition = start ?? node.textContent?.indexOf?.(link) ?? 0;
|
|
117
121
|
const endPosition = startPosition + link.length;
|
|
122
|
+
if (startPosition === 0 && endPosition === 0) {
|
|
123
|
+
const content = node.textContent;
|
|
124
|
+
if (!content)
|
|
125
|
+
return;
|
|
126
|
+
let startPosition = 0;
|
|
127
|
+
let pos = 0;
|
|
128
|
+
while (pos < content.length) {
|
|
129
|
+
if (content.codePointAt(pos) !== CODE_OF_START_LINK_URL) {
|
|
130
|
+
pos++;
|
|
131
|
+
}
|
|
132
|
+
else {
|
|
133
|
+
startPosition = pos + 1;
|
|
134
|
+
break;
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
const range = document.createRange();
|
|
138
|
+
range.setStart(node, startPosition);
|
|
139
|
+
range.collapse(true);
|
|
140
|
+
selection.removeAllRanges();
|
|
141
|
+
selection.addRange(range);
|
|
142
|
+
return;
|
|
143
|
+
}
|
|
118
144
|
const range = document.createRange();
|
|
119
145
|
range.setStart(node, startPosition);
|
|
120
146
|
range.setEnd(node, endPosition);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"link-widget.js","sources":["../../../../../src/extensions/markdown/link/link-widget.ts"],"sourcesContent":["import { type EditorView, WidgetType } from \"@codemirror/view\";\nimport { CLASSES } from \"@/extensions/theme\";\nimport { saveDispatch } from \"@/lib/utils\";\nimport { openedLinkEffect } from \"../markdown-state\";\nimport styles from \"../styles.module.scss\";\n\nconst LINK_NODES: Record<string, AnchorElement | undefined> = {};\n\ninterface AnchorElement extends HTMLAnchorElement {\n clearListeners?: () => void;\n destroy?: () => void;\n}\nexport class LinkWidget extends WidgetType {\n constructor(\n private text: string,\n private link: string,\n private from: number,\n private to: number,\n private uniqueId: string,\n private view: EditorView,\n ) {\n super();\n }\n\n get key() {\n return `${this.link}:${this.text}:${this.uniqueId}:${this.from}:${this.to}`;\n }\n\n eq(widget: LinkWidget): boolean {\n const anchor = LINK_NODES[this.key];\n if (!anchor) return false;\n delete LINK_NODES[this.key];\n\n if (anchor.href !== widget.link) anchor.href = widget.link;\n if (anchor.textContent !== widget.text) anchor.textContent = widget.text;\n\n this.link = widget.link;\n this.text = widget.text;\n this.from = widget.from;\n this.to = widget.to;\n\n this.registerListeners(anchor);\n LINK_NODES[this.key] = anchor;\n\n return true;\n }\n\n toDOM(): HTMLElement {\n const anchor = document.createElement(\"a\") as AnchorElement;\n anchor.classList.add(styles.link);\n anchor.classList.add(CLASSES.link);\n\n anchor.target = \"_blank\";\n anchor.textContent = this.text;\n anchor.href = this.link;\n\n this.registerListeners(anchor);\n\n LINK_NODES[this.key] = anchor;\n\n return anchor;\n }\n\n destroy(dom: AnchorElement): void {\n delete LINK_NODES[this.key];\n dom.destroy?.();\n }\n\n registerListeners(anchor: AnchorElement) {\n anchor.clearListeners?.();\n const abortController = new AbortController();\n anchor.addEventListener(\n \"mousedown\",\n (event) => handleClick(this.view, this.text, this.link, this.key, event),\n { signal: abortController.signal },\n );\n anchor.addEventListener(\"click\", (e) => e.preventDefault(), { signal: abortController.signal });\n anchor.clearListeners = () => {\n abortController.abort();\n };\n anchor.destroy = () => {\n anchor.clearListeners?.();\n anchor.remove();\n };\n }\n}\n\n/** recursively find the link text node in line */\nfunction getTextNode(\n text: string,\n link: string,\n key: string,\n line: ChildNode | Node | null | undefined,\n): ChildNode | null {\n if (!line) return null;\n const textNodeContainer = getTextNodeContainer(text, link, key, line);\n if (!textNodeContainer) return null;\n\n for (const node of Array.from(textNodeContainer.childNodes)) {\n if (isCorrectNode(text, link, node)) {\n return node;\n }\n }\n\n return null;\n}\n\nfunction getTextNodeContainer(\n text: string,\n link: string,\n key: string,\n line: ChildNode | Node | null | undefined,\n): HTMLElement | null {\n if (!line) return null;\n\n for (const node of Array.from(line.childNodes)) {\n if (node instanceof HTMLElement && node.getAttribute(\"data-id\") === key) {\n return node;\n }\n\n if (node.nodeType !== 3) {\n const inner = getTextNodeContainer(text, link, key, node);\n if (inner) return inner;\n }\n }\n\n return null;\n}\n\nfunction isCorrectNode(\n text: string,\n link: string,\n node: ChildNode | Node | null | undefined,\n): node is ChildNode | Node {\n if (!node) return false;\n\n const textContent = node?.textContent;\n\n return Boolean(\n node &&\n textContent &&\n node.nodeType === 3 &&\n textContent.includes(link) &&\n textContent.includes(text),\n );\n}\n\ntype SelectLinkOptions = {\n node: ChildNode | Node;\n selection: Selection;\n start?: number;\n link: string;\n};\nfunction selectLink({ link, node, selection, start }: SelectLinkOptions) {\n const startPosition = start ?? (node.textContent?.indexOf?.(link) || 0);\n const endPosition = startPosition + link.length;\n\n const range = document.createRange();\n range.setStart(node, startPosition);\n range.setEnd(node, endPosition);\n selection.removeAllRanges();\n selection.addRange(range);\n}\n\nfunction handleClick(view: EditorView, text: string, link: string, key: string, event: MouseEvent) {\n /** open the link if has special key or the view is readonly */\n const contentEditable = view.contentDOM.getAttribute(\"contenteditable\");\n const forceActive = !contentEditable || contentEditable === \"false\";\n\n if (event.shiftKey || event.ctrlKey || event.altKey || event.metaKey || forceActive) {\n if (event.type === \"mousedown\") {\n const target = event.target as HTMLAnchorElement;\n window.open(target.href, \"_blank\");\n }\n\n return;\n }\n\n event.stopPropagation();\n event.preventDefault();\n const target = event.target as HTMLImageElement;\n const parent = target.parentNode;\n let line: HTMLElement | null = parent as HTMLElement | null;\n\n /** recursively find line that contains link */\n while (line && !line.classList.contains(\"cm-line\")) {\n line = line.parentNode as HTMLElement | null;\n }\n\n const editor = Array.from(document.querySelectorAll(\".cm-editor\")).find((element) =>\n element.contains(target),\n );\n const selection = window.getSelection();\n\n if (!selection || !editor || !parent) return;\n\n const textNode = getTextNode(text, link, key, line);\n\n if (textNode) {\n return void selectLink({ selection, link, node: textNode });\n }\n\n saveDispatch(() => {\n if (!view) return;\n\n view.dispatch(view.state.update({ effects: openedLinkEffect.of(key) }));\n\n const textNode = getTextNode(text, link, key, line);\n if (textNode) {\n selectLink({ selection, link, node: textNode });\n }\n\n requestAnimationFrame(() => {\n saveDispatch(() => {\n if (view) view.dispatch(view.state.update({ effects: openedLinkEffect.of(undefined) }));\n });\n });\n });\n\n return false;\n}\n"],"names":[],"mappings":";;;;;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EAAE,IAAI,EAAE,IAAI,EAAE,QAAQ,EAAE,CAAC;;IAG7D,YAAY,CAAC,MAAK;AAChB,QAAA,IAAI,CAAC,IAAI;YAAE;QAEX,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,EAAE,OAAO,EAAE,gBAAgB,CAAC,EAAE,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC;AAEvE,QAAA,MAAM,QAAQ,GAAG,WAAW,CAAC,IAAI,EAAE,IAAI,EAAE,GAAG,EAAE,IAAI,CAAC;QACnD,IAAI,QAAQ,EAAE;YACZ,UAAU,CAAC,EAAE,SAAS,EAAE,IAAI,EAAE,IAAI,EAAE,QAAQ,EAAE,CAAC;;QAGjD,qBAAqB,CAAC,MAAK;YACzB,YAAY,CAAC,MAAK;AAChB,gBAAA,IAAI,IAAI;oBAAE,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,EAAE,OAAO,EAAE,gBAAgB,CAAC,EAAE,CAAC,SAAS,CAAC,EAAE,CAAC,CAAC;AACzF,aAAC,CAAC;AACJ,SAAC,CAAC;AACJ,KAAC,CAAC;AAEF,IAAA,OAAO,KAAK;AACd;;;;"}
|
|
1
|
+
{"version":3,"file":"link-widget.js","sources":["../../../../../src/extensions/markdown/link/link-widget.ts"],"sourcesContent":["/* eslint-disable max-params */\nimport { type EditorView, WidgetType } from \"@codemirror/view\";\nimport { CLASSES } from \"@/extensions/theme\";\nimport { saveDispatch } from \"@/lib/utils\";\nimport { openedLinkEffect } from \"../markdown-state\";\nimport styles from \"../styles.module.scss\";\nimport { CODE_OF_START_LINK_URL } from \"./link-constants\";\n\nconst LINK_NODES: Record<string, AnchorElement | undefined> = {};\n\ninterface AnchorElement extends HTMLAnchorElement {\n clearListeners?: () => void;\n destroy?: () => void;\n}\nexport class LinkWidget extends WidgetType {\n constructor(\n private text: string,\n private link: string,\n private from: number,\n private to: number,\n private uniqueId: string,\n private view: EditorView,\n ) {\n super();\n }\n\n get key() {\n return `${this.link}:${this.text}:${this.uniqueId}:${this.from}:${this.to}`;\n }\n\n eq(widget: LinkWidget): boolean {\n const anchor = LINK_NODES[this.key];\n if (!anchor) return false;\n delete LINK_NODES[this.key];\n\n if (anchor.href !== widget.link) anchor.href = widget.link;\n if (anchor.textContent !== widget.text) anchor.textContent = widget.text;\n\n this.link = widget.link;\n this.text = widget.text;\n this.from = widget.from;\n this.to = widget.to;\n\n this.registerListeners(anchor);\n LINK_NODES[this.key] = anchor;\n\n return true;\n }\n\n toDOM(): HTMLElement {\n const anchor = document.createElement(\"a\") as AnchorElement;\n anchor.classList.add(styles.link);\n anchor.classList.add(CLASSES.link);\n\n anchor.target = \"_blank\";\n anchor.textContent = this.text;\n anchor.href = this.link;\n\n this.registerListeners(anchor);\n\n LINK_NODES[this.key] = anchor;\n\n return anchor;\n }\n\n destroy(dom: AnchorElement): void {\n delete LINK_NODES[this.key];\n dom.destroy?.();\n }\n\n registerListeners(anchor: AnchorElement) {\n anchor.clearListeners?.();\n const abortController = new AbortController();\n anchor.addEventListener(\n \"mousedown\",\n (event) => handleClick(this.view, this.text, this.link, this.key, event),\n { signal: abortController.signal },\n );\n anchor.addEventListener(\"click\", (event) => event.preventDefault(), {\n signal: abortController.signal,\n });\n anchor.clearListeners = () => {\n abortController.abort();\n };\n anchor.destroy = () => {\n anchor.clearListeners?.();\n anchor.remove();\n };\n }\n}\n\n/** recursively find the link text node in line */\nfunction getTextNode(\n text: string,\n link: string,\n key: string,\n line: ChildNode | Node | null | undefined,\n): ChildNode | null {\n if (!line) return null;\n const textNodeContainer = getTextNodeContainer(text, link, key, line);\n if (!textNodeContainer) return null;\n\n for (const node of Array.from(textNodeContainer.childNodes)) {\n if (isCorrectNode(text, link, node)) {\n return node;\n }\n }\n\n return null;\n}\n\nfunction getTextNodeContainer(\n text: string,\n link: string,\n key: string,\n line: ChildNode | Node | null | undefined,\n): HTMLElement | null {\n if (!line) return null;\n\n for (const node of Array.from(line.childNodes)) {\n if (node instanceof HTMLElement && node.getAttribute(\"data-id\") === key) {\n return node;\n }\n\n if (node.nodeType !== 3) {\n const inner = getTextNodeContainer(text, link, key, node);\n if (inner) return inner;\n }\n }\n\n return null;\n}\n\nfunction isCorrectNode(\n text: string,\n link: string,\n node: ChildNode | Node | null | undefined,\n): node is ChildNode | Node {\n if (!node) return false;\n\n const textContent = node?.textContent;\n\n return Boolean(\n node &&\n textContent &&\n node.nodeType === 3 &&\n textContent.includes(link) &&\n textContent.includes(text),\n );\n}\n\ntype SelectLinkOptions = {\n node: ChildNode | Node;\n selection: Selection;\n start?: number;\n link: string;\n};\nfunction selectLink({ link, node, selection, start }: SelectLinkOptions) {\n const startPosition = start ?? node.textContent?.indexOf?.(link) ?? 0;\n const endPosition = startPosition + link.length;\n\n if (startPosition === 0 && endPosition === 0) {\n const content = node.textContent;\n if (!content) return;\n let startPosition = 0;\n let pos = 0;\n\n while (pos < content.length) {\n if (content.codePointAt(pos) !== CODE_OF_START_LINK_URL) {\n pos++;\n } else {\n startPosition = pos + 1;\n break;\n }\n }\n\n const range = document.createRange();\n range.setStart(node, startPosition);\n range.collapse(true);\n selection.removeAllRanges();\n selection.addRange(range);\n\n return;\n }\n\n const range = document.createRange();\n range.setStart(node, startPosition);\n range.setEnd(node, endPosition);\n selection.removeAllRanges();\n selection.addRange(range);\n}\n\nfunction handleClick(view: EditorView, text: string, link: string, key: string, event: MouseEvent) {\n /** open the link if has special key or the view is readonly */\n const contentEditable = view.contentDOM.getAttribute(\"contenteditable\");\n const forceActive = !contentEditable || contentEditable === \"false\";\n\n if (event.shiftKey || event.ctrlKey || event.altKey || event.metaKey || forceActive) {\n if (event.type === \"mousedown\") {\n const target = event.target as HTMLAnchorElement;\n window.open(target.href, \"_blank\");\n }\n\n return;\n }\n\n event.stopPropagation();\n event.preventDefault();\n const target = event.target as HTMLImageElement;\n const parent = target.parentNode;\n let line: HTMLElement | null = parent as HTMLElement | null;\n\n /** recursively find line that contains link */\n while (line && !line.classList.contains(\"cm-line\")) {\n line = line.parentNode as HTMLElement | null;\n }\n\n const editor = Array.from(document.querySelectorAll(\".cm-editor\")).find((element) =>\n element.contains(target),\n );\n const selection = window.getSelection();\n\n if (!selection || !editor || !parent) return;\n\n const textNode = getTextNode(text, link, key, line);\n\n if (textNode) {\n return void selectLink({ selection, link, node: textNode });\n }\n\n saveDispatch(() => {\n if (!view) return;\n\n view.dispatch(view.state.update({ effects: openedLinkEffect.of(key) }));\n\n const textNode = getTextNode(text, link, key, line);\n if (textNode) {\n selectLink({ selection, link, node: textNode });\n }\n\n requestAnimationFrame(() => {\n saveDispatch(() => {\n if (view) view.dispatch(view.state.update({ effects: openedLinkEffect.of(undefined) }));\n });\n });\n });\n\n return false;\n}\n"],"names":[],"mappings":";;;;;;;;;;AAAA;AAQA,MAAM,UAAU,GAA8C,EAAE;AAM1D,MAAO,UAAW,SAAQ,UAAU,CAAA;AAE9B,IAAA,IAAA;AACA,IAAA,IAAA;AACA,IAAA,IAAA;AACA,IAAA,EAAA;AACA,IAAA,QAAA;AACA,IAAA,IAAA;IANV,WACU,CAAA,IAAY,EACZ,IAAY,EACZ,IAAY,EACZ,EAAU,EACV,QAAgB,EAChB,IAAgB,EAAA;AAExB,QAAA,KAAK,EAAE;QAPC,IAAI,CAAA,IAAA,GAAJ,IAAI;QACJ,IAAI,CAAA,IAAA,GAAJ,IAAI;QACJ,IAAI,CAAA,IAAA,GAAJ,IAAI;QACJ,IAAE,CAAA,EAAA,GAAF,EAAE;QACF,IAAQ,CAAA,QAAA,GAAR,QAAQ;QACR,IAAI,CAAA,IAAA,GAAJ,IAAI;;AAKd,IAAA,IAAI,GAAG,GAAA;QACL,OAAO,CAAA,EAAG,IAAI,CAAC,IAAI,IAAI,IAAI,CAAC,IAAI,CAAI,CAAA,EAAA,IAAI,CAAC,QAAQ,CAAA,CAAA,EAAI,IAAI,CAAC,IAAI,IAAI,IAAI,CAAC,EAAE,CAAA,CAAE;;AAG7E,IAAA,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AAY,CAAC,MAAK;AAChB,QAAA,IAAI,CAAC,IAAI;YAAE;QAEX,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,EAAE,OAAO,EAAE,gBAAgB,CAAC,EAAE,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC;AAEvE,QAAA,MAAM,QAAQ,GAAG,WAAW,CAAC,IAAI,EAAE,IAAI,EAAE,GAAG,EAAE,IAAI,CAAC;QACnD,IAAI,QAAQ,EAAE;YACZ,UAAU,CAAC,EAAE,SAAS,EAAE,IAAI,EAAE,IAAI,EAAE,QAAQ,EAAE,CAAC;;QAGjD,qBAAqB,CAAC,MAAK;YACzB,YAAY,CAAC,MAAK;AAChB,gBAAA,IAAI,IAAI;oBAAE,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,EAAE,OAAO,EAAE,gBAAgB,CAAC,EAAE,CAAC,SAAS,CAAC,EAAE,CAAC,CAAC;AACzF,aAAC,CAAC;AACJ,SAAC,CAAC;AACJ,KAAC,CAAC;AAEF,IAAA,OAAO,KAAK;AACd;;;;"}
|
|
@@ -8,7 +8,7 @@ function getListSelectionDecorations({ decorations, node, view, forceActive, })
|
|
|
8
8
|
return;
|
|
9
9
|
}
|
|
10
10
|
const content = view.state.doc.sliceString(node.from, node.to);
|
|
11
|
-
const lastCodePoint = content.codePointAt(content.length - 1)
|
|
11
|
+
const lastCodePoint = content.codePointAt(content.length - 1) ?? 0;
|
|
12
12
|
if (!LIST_OF_LIST_MARKS.has(lastCodePoint) && CODE_OF_ORDERED_LIST_MARK !== lastCodePoint) {
|
|
13
13
|
return;
|
|
14
14
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"list-decoration.js","sources":["../../../../../src/extensions/markdown/list/list-decoration.ts"],"sourcesContent":["import { utils } from \"@/lib\";\nimport type { DecorationPlugin, GetSelectionDecorationOptions } from \"../markdown-types\";\nimport {\n CODE_OF_ORDERED_LIST_MARK,\n LIST_OF_LIST_MARKS,\n NAME_OF_LIST,\n NAME_OF_TODO,\n} from \"./list-constants\";\nimport { ListPointWidget } from \"./list-widget\";\n\nfunction getListSelectionDecorations({\n decorations,\n node,\n view,\n forceActive,\n}: GetSelectionDecorationOptions) {\n if (node.name !== NAME_OF_LIST) {\n return;\n }\n\n const content = view.state.doc.sliceString(node.from, node.to);\n const lastCodePoint = content.codePointAt(content.length - 1)
|
|
1
|
+
{"version":3,"file":"list-decoration.js","sources":["../../../../../src/extensions/markdown/list/list-decoration.ts"],"sourcesContent":["import { utils } from \"@/lib\";\nimport type { DecorationPlugin, GetSelectionDecorationOptions } from \"../markdown-types\";\nimport {\n CODE_OF_ORDERED_LIST_MARK,\n LIST_OF_LIST_MARKS,\n NAME_OF_LIST,\n NAME_OF_TODO,\n} from \"./list-constants\";\nimport { ListPointWidget } from \"./list-widget\";\n\nfunction getListSelectionDecorations({\n decorations,\n node,\n view,\n forceActive,\n}: GetSelectionDecorationOptions) {\n if (node.name !== NAME_OF_LIST) {\n return;\n }\n\n const content = view.state.doc.sliceString(node.from, node.to);\n const lastCodePoint = content.codePointAt(content.length - 1) ?? 0;\n if (!LIST_OF_LIST_MARKS.has(lastCodePoint) && CODE_OF_ORDERED_LIST_MARK !== lastCodePoint) {\n return;\n }\n\n const nextSibling = node.node.nextSibling;\n if (nextSibling && nextSibling.name === NAME_OF_TODO) {\n if (\n forceActive ||\n !view.hasFocus ||\n !utils.isInRange(view.state.selection.ranges, [node.from, nextSibling.from + 3])\n ) {\n decorations.push(utils.getHideDecoration({ range: [node.from, nextSibling.from] }));\n }\n\n return;\n }\n\n if (\n forceActive ||\n !view.hasFocus ||\n !utils.isInRange(view.state.selection.ranges, [node.from, node.to])\n ) {\n decorations.push(\n utils.getReplaceDecoration({\n range: [node.from, node.to],\n widget: new ListPointWidget(content, lastCodePoint),\n }),\n );\n }\n}\n\nexport const listDecorationPlugin: DecorationPlugin = {\n selectionDecorations: [getListSelectionDec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I,CACdE,oBAA0B,CAAC;YACzB,KAAK,EAAE,CAAC,IAAI,CAAC,IAAI,EAAE,IAAI,CAAC,EAAE,CAAC;AAC3B,YAAA,MAAM,EAAE,IAAI,eAAe,CAAC,OAAO,EAAE,aAAa,CAAC;AACpD,SAAA,CAAC,CACH;;AAEL;AAEa,MAAA,oBAAoB,GAAqB;IACpD,oBAAoB,EAAE,CAAC,2BAA2B,CAAC;;;;;"}
|
|
@@ -77,10 +77,10 @@ function createDecorationsGetter(settings) {
|
|
|
77
77
|
return;
|
|
78
78
|
/** Decoration by change content */
|
|
79
79
|
if (processDecorations)
|
|
80
|
-
decorationFunctions.forEach((
|
|
80
|
+
decorationFunctions.forEach((funk) => funk({ decorations, node, view, settings }));
|
|
81
81
|
/** Decoration by selection content */
|
|
82
82
|
if (processSelectionDecorations)
|
|
83
|
-
selectionDecorationFunctions.forEach((
|
|
83
|
+
selectionDecorationFunctions.forEach((funk) => funk({
|
|
84
84
|
decorations: selectionDecorations,
|
|
85
85
|
node,
|
|
86
86
|
view,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"markdown-decoration.js","sources":["../../../../src/extensions/markdown/markdown-decoration.ts"],"sourcesContent":["import { syntaxTree } from \"@codemirror/language\";\nimport { type Range } from \"@codemirror/state\";\nimport {\n Decoration,\n type DecorationSet,\n type EditorView,\n ViewPlugin,\n type ViewUpdate,\n} from \"@codemirror/view\";\nimport { saveDispatch } from \"@/lib/utils\";\nimport { blockquoteDecorationPlugin } from \"./blockquote\";\nimport { boldDecorationPlugin } from \"./bold\";\nimport { codeDecorationPlugin } from \"./code\";\nimport { headerDecorationPlugin } from \"./header\";\nimport { horizontalDecorationPlugin } from \"./horizontal\";\nimport { imageDecorationPlugin } from \"./image/image-decoration\";\nimport { italicDecorationPlugin } from \"./italic\";\nimport { autoLinkDecorationPlugin, linkDecorationPlugin } from \"./link\";\nimport { listDecorationPlugin } from \"./list\";\nimport type {\n DecorationPlugin,\n GetDecorationFunction,\n GetSelectionDecorationFunction,\n MarkdownDecorationSettings,\n} from \"./markdown-types\";\nimport { mentionDecorationPlugin } from \"./mention/mention-decoration\";\nimport { strikeThroughDecorationPlugin } from \"./strike-through\";\nimport { todoDecorationPlugin } from \"./todo\";\n\nconst decorationPlugins: DecorationPlugin[] = [\n blockquoteDecorationPlugin,\n boldDecorationPlugin,\n codeDecorationPlugin,\n headerDecorationPlugin,\n horizontalDecorationPlugin,\n imageDecorationPlugin,\n italicDecorationPlugin,\n linkDecorationPlugin,\n listDecorationPlugin,\n autoLinkDecorationPlugin,\n mentionDecorationPlugin,\n strikeThroughDecorationPlugin,\n todoDecorationPlugin,\n];\n\nlet decorationFunctions: GetDecorationFunction[] = [];\nlet selectionDecorationFunctions: GetSelectionDecorationFunction[] = [];\n\nfor (const plugin of decorationPlugins) {\n if (plugin.decorations) decorationFunctions = decorationFunctions.concat(plugin.decorations);\n if (plugin.selectionDecorations)\n selectionDecorationFunctions = selectionDecorationFunctions.concat(plugin.selectionDecorations);\n}\n\nconst SKIP_MARKS = new Set([\n \"Document\",\n \"Paragraph\",\n \"EmphasisMark\",\n \"Blockquote\",\n \"StrikethroughMark\",\n \"BulletList\",\n \"OrderedList\",\n \"ListItem\",\n \"LinkMark\",\n \"URL\",\n \"CodeMark\",\n \"CodeInfo\",\n \"CodeText\",\n \"HeaderMark\",\n \"TaskMarker\",\n]);\n\nfunction createDecorationsGetter(settings: MarkdownDecorationSettings) {\n let markdownDecorationsCache: Range<Decoration>[] = [];\n let markdownSelectionDecorationsCache: Range<Decoration>[] = [];\n\n function getDecorations(view: EditorView, isChanged: boolean, mouseReleased: boolean) {\n const processDecorations = isChanged;\n const processSelectionDecorations = isChanged || mouseReleased;\n const decorations: Range<Decoration>[] = processDecorations ? [] : markdownDecorationsCache;\n const selectionDecorations: Range<Decoration>[] = processSelectionDecorations\n ? []\n : markdownSelectionDecorationsCache;\n\n const contentEditable = view.contentDOM.getAttribute(\"contenteditable\");\n const isReadonly = !contentEditable || contentEditable === \"false\";\n\n for (const { from: fromVisible, to: toVisible } of view.visibleRanges) {\n syntaxTree(view.state).iterate({\n from: fromVisible,\n to: toVisible,\n enter: (node) => {\n if (SKIP_MARKS.has(node.name)) return;\n /** Decoration by change content */\n if (processDecorations)\n decorationFunctions.forEach((
|
|
1
|
+
{"version":3,"file":"markdown-decoration.js","sources":["../../../../src/extensions/markdown/markdown-decoration.ts"],"sourcesContent":["import { syntaxTree } from \"@codemirror/language\";\nimport { type Range } from \"@codemirror/state\";\nimport {\n Decoration,\n type DecorationSet,\n type EditorView,\n ViewPlugin,\n type ViewUpdate,\n} from \"@codemirror/view\";\nimport { saveDispatch } from \"@/lib/utils\";\nimport { blockquoteDecorationPlugin } from \"./blockquote\";\nimport { boldDecorationPlugin } from \"./bold\";\nimport { codeDecorationPlugin } from \"./code\";\nimport { headerDecorationPlugin } from \"./header\";\nimport { horizontalDecorationPlugin } from \"./horizontal\";\nimport { imageDecorationPlugin } from \"./image/image-decoration\";\nimport { italicDecorationPlugin } from \"./italic\";\nimport { autoLinkDecorationPlugin, linkDecorationPlugin } from \"./link\";\nimport { listDecorationPlugin } from \"./list\";\nimport type {\n DecorationPlugin,\n GetDecorationFunction,\n GetSelectionDecorationFunction,\n MarkdownDecorationSettings,\n} from \"./markdown-types\";\nimport { mentionDecorationPlugin } from \"./mention/mention-decoration\";\nimport { strikeThroughDecorationPlugin } from \"./strike-through\";\nimport { todoDecorationPlugin } from \"./todo\";\n\nconst decorationPlugins: DecorationPlugin[] = [\n blockquoteDecorationPlugin,\n boldDecorationPlugin,\n codeDecorationPlugin,\n headerDecorationPlugin,\n horizontalDecorationPlugin,\n imageDecorationPlugin,\n italicDecorationPlugin,\n linkDecorationPlugin,\n listDecorationPlugin,\n autoLinkDecorationPlugin,\n mentionDecorationPlugin,\n strikeThroughDecorationPlugin,\n todoDecorationPlugin,\n];\n\nlet decorationFunctions: GetDecorationFunction[] = [];\nlet selectionDecorationFunctions: GetSelectionDecorationFunction[] = [];\n\nfor (const plugin of decorationPlugins) {\n if (plugin.decorations) decorationFunctions = decorationFunctions.concat(plugin.decorations);\n if (plugin.selectionDecorations)\n selectionDecorationFunctions = selectionDecorationFunctions.concat(plugin.selectionDecorations);\n}\n\nconst SKIP_MARKS = new Set([\n \"Document\",\n \"Paragraph\",\n \"EmphasisMark\",\n \"Blockquote\",\n \"StrikethroughMark\",\n \"BulletList\",\n \"OrderedList\",\n \"ListItem\",\n \"LinkMark\",\n \"URL\",\n \"CodeMark\",\n \"CodeInfo\",\n \"CodeText\",\n \"HeaderMark\",\n \"TaskMarker\",\n]);\n\nfunction createDecorationsGetter(settings: MarkdownDecorationSettings) {\n let markdownDecorationsCache: Range<Decoration>[] = [];\n let markdownSelectionDecorationsCache: Range<Decoration>[] = [];\n\n function getDecorations(view: EditorView, isChanged: boolean, mouseReleased: boolean) {\n const processDecorations = isChanged;\n const processSelectionDecorations = isChanged || mouseReleased;\n const decorations: Range<Decoration>[] = processDecorations ? [] : markdownDecorationsCache;\n const selectionDecorations: Range<Decoration>[] = processSelectionDecorations\n ? []\n : markdownSelectionDecorationsCache;\n\n const contentEditable = view.contentDOM.getAttribute(\"contenteditable\");\n const isReadonly = !contentEditable || contentEditable === \"false\";\n\n for (const { from: fromVisible, to: toVisible } of view.visibleRanges) {\n syntaxTree(view.state).iterate({\n from: fromVisible,\n to: toVisible,\n enter: (node) => {\n if (SKIP_MARKS.has(node.name)) return;\n /** Decoration by change content */\n if (processDecorations)\n decorationFunctions.forEach((funk) => funk({ decorations, node, view, settings }));\n\n /** Decoration by selection content */\n if (processSelectionDecorations)\n selectionDecorationFunctions.forEach((funk) =>\n funk({\n decorations: selectionDecorations,\n node,\n view,\n forceActive: isReadonly,\n settings,\n }),\n );\n },\n });\n }\n\n if (processDecorations) {\n markdownDecorationsCache = decorations;\n }\n if (processSelectionDecorations) {\n markdownSelectionDecorationsCache = selectionDecorations;\n }\n\n return Decoration.set([...decorations, ...selectionDecorations], true);\n }\n\n return getDecorations;\n}\n\nexport const markdownDecorationPlugin = (settings: MarkdownDecorationSettings) => {\n return ViewPlugin.fromClass(\n class DecorationMarkdown {\n decorations: DecorationSet;\n\n mouseReleased: boolean = true;\n\n dom: HTMLElement;\n\n view: EditorView;\n\n decorationGetter: (\n view: EditorView,\n isChanged: boolean,\n mouseReleased: boolean,\n ) => DecorationSet;\n\n constructor(view: EditorView) {\n this.decorationGetter = createDecorationsGetter(settings);\n this.decorations = this.decorationGetter(view, true, this.mouseReleased);\n this.dom = view.dom;\n this.view = view;\n document.addEventListener(\"mousedown\", this.onMouseDown.bind(this));\n document.addEventListener(\"mouseup\", this.onMouseUp.bind(this));\n }\n\n update(update: ViewUpdate) {\n const isDocumentChanged =\n update.docChanged ||\n update.viewportChanged ||\n syntaxTree(update.startState) != syntaxTree(update.state);\n this.decorations = this.decorationGetter(\n update.view,\n isDocumentChanged,\n this.mouseReleased,\n );\n }\n\n destroy() {\n document.removeEventListener(\"mousedown\", this.onMouseDown.bind(this));\n document.removeEventListener(\"mouseup\", this.onMouseUp.bind(this));\n }\n\n onMouseDown(this: DecorationMarkdown) {\n this.mouseReleased = false;\n }\n\n onMouseUp(this: DecorationMarkdown) {\n this.mouseReleased = true;\n if (this.view.state.selection.ranges[0].from !== this.view.state.selection.ranges[0].to) {\n saveDispatch(() => {\n this.view.dispatch(this.view.state.update({}));\n });\n }\n }\n },\n {\n decorations: (plugin) => plugin.decorations,\n },\n );\n};\n"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;AA6BA,MAAM,iBAAiB,GAAuB;IAC5C,0BAA0B;IAC1B,oBAAoB;IACpB,oBAAoB;IACpB,sBAAsB;IACtB,0BAA0B;IAC1B,qBAAqB;IACrB,sBAAsB;IACtB,oBAAoB;IACpB,oBAAoB;IACpB,wBAAwB;IACxB,uBAAuB;IACvB,6BAA6B;IAC7B,oBAAoB;CACrB;AAED,IAAI,mBAAmB,GAA4B,EAAE;AACrD,IAAI,4BAA4B,GAAqC,EAAE;AAEvE,KAAK,M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CAAC,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,EAAE,CAAC,CAAC;AAChD,iBAAC,CAAC;;;KAGP,EACD;QACE,WAAW,EAAE,CAAC,MAAM,KAAK,MAAM,CAAC,WAAW;AAC5C,KAAA,CACF;AACH;;;;"}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
const CODE_OF_START_MENTION =
|
|
2
|
-
const CODE_OF_SPACE =
|
|
1
|
+
const CODE_OF_START_MENTION = "@".codePointAt(0); // @
|
|
2
|
+
const CODE_OF_SPACE = " ".codePointAt(0);
|
|
3
|
+
const CODE_OF_LINE_BREAK = "\n".codePointAt(0);
|
|
3
4
|
const NAME_OF_MENTION = "Mention";
|
|
4
5
|
|
|
5
|
-
export { CODE_OF_SPACE, CODE_OF_START_MENTION, NAME_OF_MENTION };
|
|
6
|
+
export { CODE_OF_LINE_BREAK, CODE_OF_SPACE, CODE_OF_START_MENTION, NAME_OF_MENTION };
|
|
6
7
|
//# sourceMappingURL=mention-constants.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"mention-constants.js","sources":["../../../../../src/extensions/markdown/mention/mention-constants.ts"],"sourcesContent":["export const CODE_OF_START_MENTION =
|
|
1
|
+
{"version":3,"file":"mention-constants.js","sources":["../../../../../src/extensions/markdown/mention/mention-constants.ts"],"sourcesContent":["export const CODE_OF_START_MENTION = \"@\".codePointAt(0); // @\nexport const CODE_OF_SPACE = \" \".codePointAt(0);\nexport const CODE_OF_LINE_BREAK = \"\\n\".codePointAt(0);\nexport const NAME_OF_MENTION = \"Mention\";\n"],"names":[],"mappings":"AAAO,MAAM,qBAAqB,GAAG,GAAG,CAAC,WAAW,CAAC,CAAC,EAAE;AAC3C,MAAA,aAAa,GAAG,GAAG,CAAC,WAAW,CAAC,CAAC;AACjC,MAAA,kBAAkB,GAAG,IAAI,CAAC,WAAW,CAAC,CAAC;AAC7C,MAAM,eAAe,GAAG;;;;"}
|
|
@@ -4,7 +4,7 @@ import '../../compartments/index.js';
|
|
|
4
4
|
import '@codemirror/language';
|
|
5
5
|
import '@lezer/highlight';
|
|
6
6
|
import { CLASSES } from '../../theme/theme-constants.js';
|
|
7
|
-
import {
|
|
7
|
+
import { getHideDecoration, getMarkDecoration } from '../../../lib/utils/get-decoration.js';
|
|
8
8
|
import { isInRange } from '../../../lib/utils/is-in-range.js';
|
|
9
9
|
import styles from '../styles.module.scss.js';
|
|
10
10
|
import { NAME_OF_MENTION } from './mention-constants.js';
|
|
@@ -1,17 +1,20 @@
|
|
|
1
|
-
import { NAME_OF_MENTION, CODE_OF_START_MENTION, CODE_OF_SPACE } from './mention-constants.js';
|
|
1
|
+
import { NAME_OF_MENTION, CODE_OF_START_MENTION, CODE_OF_SPACE, CODE_OF_LINE_BREAK } from './mention-constants.js';
|
|
2
2
|
|
|
3
3
|
const mentionParser = {
|
|
4
4
|
defineNodes: [{ name: NAME_OF_MENTION }],
|
|
5
5
|
parseInline: [
|
|
6
6
|
{
|
|
7
7
|
name: NAME_OF_MENTION,
|
|
8
|
-
parse(cx,
|
|
9
|
-
if (
|
|
8
|
+
parse(cx, code, pos) {
|
|
9
|
+
if (code != CODE_OF_START_MENTION)
|
|
10
|
+
return -1;
|
|
11
|
+
const nextCode = cx.char(pos + 1);
|
|
12
|
+
if (nextCode === -1 || nextCode === CODE_OF_SPACE || nextCode === CODE_OF_LINE_BREAK)
|
|
10
13
|
return -1;
|
|
11
14
|
let end = pos + 1;
|
|
12
15
|
for (let i = pos + 1; i < cx.end; i++) {
|
|
13
|
-
const
|
|
14
|
-
if (
|
|
16
|
+
const nextCode = cx.char(i);
|
|
17
|
+
if (nextCode === -1 || nextCode === CODE_OF_SPACE || nextCode === CODE_OF_LINE_BREAK)
|
|
15
18
|
break;
|
|
16
19
|
end++;
|
|
17
20
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"mention-parser.js","sources":["../../../../../src/extensions/markdown/mention/mention-parser.ts"],"sourcesContent":["import type { MarkdownConfig } from \"@lezer/markdown\";\nimport {
|
|
1
|
+
{"version":3,"file":"mention-parser.js","sources":["../../../../../src/extensions/markdown/mention/mention-parser.ts"],"sourcesContent":["import type { MarkdownConfig } from \"@lezer/markdown\";\nimport {\n CODE_OF_LINE_BREAK,\n CODE_OF_SPACE,\n CODE_OF_START_MENTION,\n NAME_OF_MENTION,\n} from \"./mention-constants\";\n\nexport const mentionParser: MarkdownConfig = {\n defineNodes: [{ name: NAME_OF_MENTION }],\n parseInline: [\n {\n name: NAME_OF_MENTION,\n parse(cx, code, pos) {\n if (code != CODE_OF_START_MENTION) return -1;\n const nextCode = cx.char(pos + 1);\n if (nextCode === -1 || nextCode === CODE_OF_SPACE || nextCode === CODE_OF_LINE_BREAK)\n return -1;\n\n let end: number = pos + 1;\n for (let i = pos + 1; i < cx.end; i++) {\n const nextCode = cx.char(i);\n if (nextCode === -1 || nextCode === CODE_OF_SPACE || nextCode === CODE_OF_LINE_BREAK)\n break;\n end++;\n }\n\n return cx.addElement(cx.elt(NAME_OF_MENTION, pos, end));\n },\n },\n ],\n};\n"],"names":[],"mappings":";;AAQa,MAAA,aAAa,GAAmB;AAC3C,IAAA,WAAW,EAAE,CAAC,EAAE,IAAI,EAAE,eAAe,EAAE,CAAC;AACxC,IAAA,WAAW,EAAE;AACX,QAAA;AACE,YAAA,IAAI,EAAE,eAAe;AACrB,YAAA,KAAK,CAAC,EAAE,EAAE,IAAI,EAAE,GAAG,EAAA;gBACjB,IAAI,IAAI,IAAI,qBAAqB;oBAAE,OAAO,EAAE;gBAC5C,MAAM,QAAQ,GAAG,EAAE,CAAC,IAAI,CAAC,GAAG,GAAG,CAAC,CAAC;gBACjC,IAAI,QAAQ,KAAK,EAAE,IAAI,QAAQ,KAAK,aAAa,IAAI,QAAQ,KAAK,kBAAkB;oBAClF,OAAO,EAAE;AAEX,gBAAA,IAAI,GAAG,GAAW,GAAG,GAAG,CAAC;AACzB,gBAAA,KAAK,IAAI,CAAC,GAAG,GAAG,GAAG,CAAC,EAAE,CAAC,GAAG,EAAE,CAAC,GAAG,EAAE,CAAC,EAAE,EAAE;oBACrC,MAAM,QAAQ,GAAG,EAAE,CAAC,IAAI,CAAC,CAAC,CAAC;oBAC3B,IAAI,QAAQ,KAAK,EAAE,IAAI,QAAQ,KAAK,aAAa,IAAI,QAAQ,KAAK,kBAAkB;wBAClF;AACF,oBAAA,GAAG,EAAE;;AAGP,gBAAA,OAAO,EAAE,CAAC,UAAU,CAAC,EAAE,CAAC,GAAG,CAAC,eAAe,EAAE,GAAG,EAAE,GAAG,CAAC,CAAC;aACxD;AACF,SAAA;AACF,KAAA;;;;;"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { getHideDecoration, getMarkDecoration } from '../../../lib/utils/get-decoration.js';
|
|
2
2
|
import { isInRange } from '../../../lib/utils/is-in-range.js';
|
|
3
3
|
import styles from '../styles.module.scss.js';
|
|
4
4
|
import { NAME_OF_STRIKE_THROUGH } from './strike-through-constants.js';
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import styleInject from '../../node_modules/.pnpm/style-inject@0.3.0/node_modules/style-inject/dist/style-inject.es.js';
|
|
2
2
|
|
|
3
|
-
var css_248z = "._header_XFwV5{font-weight:700}._header_XFwV5._level_1_-KPph{font-size:
|
|
4
|
-
const styles = {"header":"_header_XFwV5","level_1":"_level_1_-KPph","level_2":"_level_2_ecHlB","level_3":"_level_3_SYcVr","level_4":"_level_4_V3o5m","level_5":"_level_5_I7eVk","level_6":"_level_6_A3lbK","bold":"_bold_I8DT-","italic":"_italic_72qBe","blockquote":"_blockquote_Xq6O4","blockquote__inner":"_blockquote__inner_mjT0h","blockquote__inner-deep":"_blockquote__inner-deep_s6tNj","strike-through":"_strike-through_U64jP","list":"_list_MHIjT","common":"_common_0GdDi","link":"_link_7U9wl","link__label":"_link__label_dHGGf","image":"_image_KmBM8","code__line":"_code__line_m3IiO","
|
|
3
|
+
var css_248z = "._header_XFwV5{font-weight:700}._header_XFwV5._level_1_-KPph{font-size:2em}._header_XFwV5._level_2_ecHlB{font-size:1.8em}._header_XFwV5._level_3_SYcVr{font-size:1.6em}._header_XFwV5._level_4_V3o5m{font-size:1.4em}._header_XFwV5._level_5_I7eVk{font-size:1.3em}._header_XFwV5._level_6_A3lbK{font-size:1.2em}._bold_I8DT-{font-weight:700}._italic_72qBe{font-style:italic}._blockquote_Xq6O4{border-left:3px solid;margin-left:5px}._blockquote__inner_mjT0h{margin-left:1px;padding-left:5px;position:relative}._blockquote__inner_mjT0h:before{border-left:3px solid;content:\"\";height:140%;left:0;position:absolute;top:-3px}._blockquote__inner-deep_s6tNj{margin-left:5px}._strike-through_U64jP{text-decoration:line-through}._list_MHIjT._common_0GdDi{position:relative;visibility:hidden}._list_MHIjT._common_0GdDi:after{border-radius:100%;content:\"\";height:5px;left:0;position:absolute;top:50%;transform:translateY(-50%);visibility:visible;width:5px}._link_7U9wl{text-decoration:none;text-decoration:underline}._link__label_dHGGf{font-size:12px;position:relative;top:-4px}._image_KmBM8{display:inline-flex}._code__line_m3IiO{padding:5px;position:relative}._code__button_WwYE-{background-color:transparent;border:none;border-radius:4px;box-shadow:none;cursor:pointer;min-width:30px;outline:none;padding:4px 10px;position:absolute;right:5px;top:5px;transition:all .3s ease;z-index:1}._code__button_WwYE-._pending_fgHgD:before{animation:_loading-btn--fade-in_8z5an .33s ease,_loading-btn--rotation_QaopN .66s linear 0s infinite;border:2px solid hsla(0,0%,100%,.33);border-radius:50%;border-top-color:#000;content:\"\";display:inline-block;height:10.5px;left:50%;position:absolute;top:50%;width:10.5px}._code__button_WwYE-._success_kUPnO:after{animation:_loading-btn--fade-in_8z5an .6s ease;border-color:currentcolor;border-style:solid;border-width:0 0 1px 1px;content:\"\";display:inline-block;height:7px;left:50%;position:absolute;top:50%;transform:translate(-50%,-75%) rotate(-45deg);width:11px}._code__button_WwYE-._fail_cOpap:after,._code__button_WwYE-._fail_cOpap:before{content:\" \";height:13px;left:50%;position:absolute;top:50%;width:1px}._code__button_WwYE-._fail_cOpap:before{transform:translate(-50%,-50%) rotate(45deg)}._code__button_WwYE-._fail_cOpap:after{transform:translate(-50%,-50%) rotate(-45deg)}@keyframes _loading-btn--fade-in_8z5an{0%{opacity:0}to{opacity:1}}@keyframes _loading-btn--rotation_QaopN{0%{transform:translate(-50%,-50%) rotate(0deg)}to{transform:translate(-50%,-50%) rotate(1turn)}}._code__span_iSCmj{opacity:1;transition:opacity .3s ease}._code__span_iSCmj._hide_uqpax{opacity:0}._code__block_JehA4{padding:1px 5px}._code__block_line_U7lcQ{border-left:1px solid;margin-left:5px}._horizontal_J1jU-{border-bottom:1px solid;margin:0 5px;position:relative;width:calc(100% - 10px)}._todo_m6MIP{align-items:flex-end;display:inline-flex;height:100%;padding-left:3px;padding-right:3px}._todo_m6MIP>input{margin:0}._todo__checked_kemjy{text-decoration:line-through}._mention_cpzik{font-weight:700}";
|
|
4
|
+
const styles = {"header":"_header_XFwV5","level_1":"_level_1_-KPph","level_2":"_level_2_ecHlB","level_3":"_level_3_SYcVr","level_4":"_level_4_V3o5m","level_5":"_level_5_I7eVk","level_6":"_level_6_A3lbK","bold":"_bold_I8DT-","italic":"_italic_72qBe","blockquote":"_blockquote_Xq6O4","blockquote__inner":"_blockquote__inner_mjT0h","blockquote__inner-deep":"_blockquote__inner-deep_s6tNj","strike-through":"_strike-through_U64jP","list":"_list_MHIjT","common":"_common_0GdDi","link":"_link_7U9wl","link__label":"_link__label_dHGGf","image":"_image_KmBM8","code__line":"_code__line_m3IiO","code__button":"_code__button_WwYE-","pending":"_pending_fgHgD","loading-btn--fade-in":"_loading-btn--fade-in_8z5an","loading-btn--rotation":"_loading-btn--rotation_QaopN","success":"_success_kUPnO","fail":"_fail_cOpap","code__span":"_code__span_iSCmj","hide":"_hide_uqpax","code__block":"_code__block_JehA4","code__block_line":"_code__block_line_U7lcQ","horizontal":"_horizontal_J1jU-","todo":"_todo_m6MIP","todo__checked":"_todo__checked_kemjy","mention":"_mention_cpzik"};
|
|
5
5
|
styleInject(css_248z);
|
|
6
6
|
|
|
7
7
|
export { styles as default };
|
|
@@ -10,7 +10,7 @@ function getTodoSelectionDecoration({ decorations, node, view, forceActive, }) {
|
|
|
10
10
|
const prevSibling = node.node.prevSibling;
|
|
11
11
|
if (!prevSibling || prevSibling.name !== NAME_OF_LIST_MARK)
|
|
12
12
|
return;
|
|
13
|
-
const isChecked = LIST_OF_TODO_MARKS.has(view.state.doc.sliceString(node.from + 1, node.from + 2).codePointAt(0)
|
|
13
|
+
const isChecked = LIST_OF_TODO_MARKS.has(view.state.doc.sliceString(node.from + 1, node.from + 2).codePointAt(0) ?? 0);
|
|
14
14
|
if (forceActive ||
|
|
15
15
|
!view.hasFocus ||
|
|
16
16
|
!isInRange(view.state.selection.ranges, [prevSibling.from, node.from + 3])) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"todo-decoration.js","sources":["../../../../../src/extensions/markdown/todo/todo-decoration.ts"],"sourcesContent":["import { utils } from \"@/lib\";\nimport type { DecorationPlugin, GetSelectionDecorationOptions } from \"../markdown-types\";\nimport styles from \"../styles.module.scss\";\nimport { LIST_OF_TODO_MARKS, NAME_OF_LIST_MARK, NAME_OF_TODO } from \"./todo-constants\";\nimport { TodoWidget } from \"./todo-widget\";\n\nfunction getTodoSelectionDecoration({\n decorations,\n node,\n view,\n forceActive,\n}: GetSelectionDecorationOptions) {\n if (node.name !== NAME_OF_TODO) return;\n\n const prevSibling = node.node.prevSibling;\n if (!prevSibling || prevSibling.name !== NAME_OF_LIST_MARK) return;\n\n const isChecked = LIST_OF_TODO_MARKS.has(\n view.state.doc.sliceString(node.from + 1, node.from + 2).codePointAt(0)
|
|
1
|
+
{"version":3,"file":"todo-decoration.js","sources":["../../../../../src/extensions/markdown/todo/todo-decoration.ts"],"sourcesContent":["import { utils } from \"@/lib\";\nimport type { DecorationPlugin, GetSelectionDecorationOptions } from \"../markdown-types\";\nimport styles from \"../styles.module.scss\";\nimport { LIST_OF_TODO_MARKS, NAME_OF_LIST_MARK, NAME_OF_TODO } from \"./todo-constants\";\nimport { TodoWidget } from \"./todo-widget\";\n\nfunction getTodoSelectionDecoration({\n decorations,\n node,\n view,\n forceActive,\n}: GetSelectionDecorationOptions) {\n if (node.name !== NAME_OF_TODO) return;\n\n const prevSibling = node.node.prevSibling;\n if (!prevSibling || prevSibling.name !== NAME_OF_LIST_MARK) return;\n\n const isChecked = LIST_OF_TODO_MARKS.has(\n view.state.doc.sliceString(node.from + 1, node.from + 2).codePointAt(0) ?? 0,\n );\n\n if (\n forceActive ||\n !view.hasFocus ||\n !utils.isInRange(view.state.selection.ranges, [prevSibling.from, node.from + 3])\n ) {\n decorations.push(\n utils.getReplaceDecoration({\n range: [node.from, node.from + 3],\n widget: new TodoWidget(isChecked, node.from + 1),\n }),\n );\n }\n\n if (isChecked) {\n const line = view.lineBlockAt(node.from);\n\n if (\n forceActive ||\n !view.hasFocus ||\n !utils.isInRange(view.state.selection.ranges, [line.from, line.to])\n )\n decorations.push(\n utils.getMarkDecoration({ style: styles.todo__checked, range: [node.from + 4, node.to] }),\n );\n }\n}\n\nexport const todoDecorationPlugin: DecorationPlugin = {\n selectionDecorations: [getTodoSelectionDecoration],\n};\n"],"names":["utils.isInRange","utils.getReplaceDecoration","utils.getMarkDecoration"],"mappings":";;;;;;AAMA,SAAS,0BAA0B,CAAC,EAClC,WAAW,EACX,IAAI,EACJ,IAAI,EACJ,WAAW,GACmB,EAAA;AAC9B,IAAA,IAAI,IAAI,CAAC,IAAI,KAAK,YAAY;QAAE;AAEhC,IAAA,MAAM,WAAW,GAAG,IAAI,CAAC,IAAI,CAAC,WAAW;AACzC,IAAA,IAAI,CAAC,WAAW,IAAI,WAAW,CAAC,IAAI,KAAK,iBAAiB;QAAE;AAE5D,IAAA,MAAM,SAAS,GAAG,kBAAkB,CAAC,GAAG,CACtC,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,WAAW,CAAC,IAAI,CAAC,IAAI,GAAG,CAAC,EAAE,IAAI,CAAC,IAAI,GAAG,CAAC,CAAC,CAAC,WAAW,CAAC,CAAC,CAAC,IAAI,CAAC,CAC7E;AAED,IAAA,IACE,WAAW;QACX,CAAC,IAAI,CAAC,QAAQ;QACd,CAACA,SAAe,CAAC,IAAI,CAAC,KAAK,CAAC,SAAS,CAAC,MAAM,EAAE,CAAC,WAAW,CAAC,IAAI,EAAE,IAAI,CAAC,IAAI,GAAG,CAAC,CAAC,CAAC,EAChF;AACA,QAAA,WAAW,CAAC,IAAI,CACdC,oBAA0B,CAAC;YACzB,KAAK,EAAE,CAAC,IAAI,CAAC,IAAI,EAAE,IAAI,CAAC,IAAI,GAAG,CAAC,CAAC;YACjC,MAAM,EAAE,IAAI,UAAU,CAAC,SAAS,EAAE,IAAI,CAAC,IAAI,GAAG,CAAC,CAAC;AACjD,SAAA,CAAC,CACH;;IAGH,IAAI,SAAS,EAAE;QACb,MAAM,IAAI,GAAG,IAAI,CAAC,WAAW,CAAC,IAAI,CAAC,IAAI,CAAC;AAExC,QAAA,IACE,WAAW;YACX,CAAC,IAAI,CAAC,QAAQ;YACd,CAACD,SAAe,CAAC,IAAI,CAAC,KAAK,CAAC,SAAS,CAAC,MAAM,EAAE,CAAC,IAAI,CAAC,IAAI,EAAE,IAAI,CAAC,EAAE,CAAC,CAAC;AAEnE,YAAA,WAAW,CAAC,IAAI,CACdE,iBAAuB,CAAC,EAAE,KAAK,EAAE,MAAM,CAAC,aAAa,EAAE,KAAK,EAAE,CAAC,IAAI,CAAC,IAAI,GAAG,CAAC,EAAE,IAAI,CAAC,EAAE,CAAC,EAAE,CAAC,CAC1F;;AAEP;AAEa,MAAA,oBAAoB,GAAqB;IACpD,oBAAoB,EAAE,CAAC,0BAA0B,CAAC;;;;;"}
|
|
@@ -3,7 +3,7 @@ import '@codemirror/state';
|
|
|
3
3
|
import { drawSelection, EditorView } from '@codemirror/view';
|
|
4
4
|
import { ReadonlyCompartment, VimModeCompartment } from '../compartments/index.js';
|
|
5
5
|
|
|
6
|
-
async function
|
|
6
|
+
async function initSettings({ readonly, vimMode, }) {
|
|
7
7
|
let vimExtension = [];
|
|
8
8
|
if (vimMode) {
|
|
9
9
|
const { vim } = await import('@replit/codemirror-vim');
|
|
@@ -16,5 +16,5 @@ async function InitSettings({ readonly, vimMode, }) {
|
|
|
16
16
|
];
|
|
17
17
|
}
|
|
18
18
|
|
|
19
|
-
export {
|
|
19
|
+
export { initSettings };
|
|
20
20
|
//# sourceMappingURL=init-settings.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"init-settings.js","sources":["../../../../src/extensions/settings/init-settings.ts"],"sourcesContent":["import { history } from \"@codemirror/commands\";\nimport { type Extension } from \"@codemirror/state\";\nimport { EditorView, drawSelection } from \"@codemirror/view\";\nimport { ReadonlyCompartment, VimModeCompartment } from \"../compartments\";\n\nexport type InitSettingsOptions = {\n readonly?: boolean;\n vimMode?: boolean;\n};\n\nexport async function
|
|
1
|
+
{"version":3,"file":"init-settings.js","sources":["../../../../src/extensions/settings/init-settings.ts"],"sourcesContent":["import { history } from \"@codemirror/commands\";\nimport { type Extension } from \"@codemirror/state\";\nimport { EditorView, drawSelection } from \"@codemirror/view\";\nimport { ReadonlyCompartment, VimModeCompartment } from \"../compartments\";\n\nexport type InitSettingsOptions = {\n readonly?: boolean;\n vimMode?: boolean;\n};\n\nexport async function initSettings({\n readonly,\n vimMode,\n}: InitSettingsOptions): Promise<Extension[]> {\n let vimExtension: Extension = [];\n if (vimMode) {\n const { vim } = await import(\"@replit/codemirror-vim\");\n vimExtension = [vim({ status: true }), drawSelection()];\n }\n\n return [\n ReadonlyCompartment.of(EditorView.editable.of(!readonly)),\n VimModeCompartment.of(vimExtension),\n history(),\n ];\n}\n"],"names":[],"mappings":";;;;;AAUO,eAAe,YAAY,CAAC,EACjC,QAAQ,EACR,OAAO,GACa,EAAA;IACpB,IAAI,YAAY,GAAc,EAAE;IAChC,IAAI,OAAO,EAAE;QACX,MAAM,EAAE,GAAG,EAAE,GAAG,MAAM,OAAO,wBAAwB,CAAC;AACtD,QAAA,YAAY,GAAG,CAAC,GAAG,CAAC,EAAE,MAAM,EAAE,IAAI,EAAE,CAAC,EAAE,aAAa,EAAE,CAAC;;IAGzD,OAAO;AACL,QAAA,mBAAmB,CAAC,EAAE,CAAC,UAAU,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC,QAAQ,CAAC,CAAC;AACzD,QAAA,kBAAkB,CAAC,EAAE,CAAC,YAAY,CAAC;AACnC,QAAA,OAAO,EAAE;KACV;AACH;;;;"}
|