@krainovsd/markdown-editor 0.3.1 → 0.3.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.
@@ -4,7 +4,7 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
4
4
 
5
5
  const langMarkdown = require('@codemirror/lang-markdown');
6
6
  require('@codemirror/state');
7
- const index = require('./index-nRNnOuav.js');
7
+ const index = require('./index-BgxbH3r2.js');
8
8
  require('@codemirror/view');
9
9
  require('@codemirror/commands');
10
10
  require('@codemirror/language');
@@ -49,4 +49,4 @@ const initMarkdown = ({ languages, imageSrcGetter }) => {
49
49
  };
50
50
 
51
51
  exports.initMarkdown = initMarkdown;
52
- //# sourceMappingURL=index-DXevyHeZ.js.map
52
+ //# sourceMappingURL=index-DU8JMAfc.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index-DXevyHeZ.js","sources":["../../src/extensions/markdown/mention/mention-parser.ts","../../src/extensions/markdown/markdown-parser.ts","../../src/extensions/markdown/init-markdown.ts"],"sourcesContent":["import type { MarkdownConfig } from \"@lezer/markdown\";\nimport { CODE_OF_SPACE, CODE_OF_START_MENTION, NAME_OF_MENTION } 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, next, pos) {\n if (next != CODE_OF_START_MENTION) return -1;\n let end: number = pos + 1;\n for (let i = pos + 1; i < cx.end; i++) {\n const next = cx.char(i);\n if (next === CODE_OF_SPACE) break;\n end++;\n }\n\n return cx.addElement(cx.elt(NAME_OF_MENTION, pos, end));\n },\n },\n ],\n};\n","import type { MarkdownExtension } from \"@lezer/markdown\";\nimport { mentionParser } from \"./mention\";\n\nexport const markdownParserPlugin: MarkdownExtension = [mentionParser];\n","import { markdown, markdownLanguage } from \"@codemirror/lang-markdown\";\nimport { type Extension } from \"@codemirror/state\";\nimport { markdownDecorationPlugin } from \"./markdown-decoration\";\nimport { markdownParserPlugin } from \"./markdown-parser\";\nimport { markdownState } from \"./markdown-state\";\nimport type { InitMarkdownOptions } from \"./markdown-types\";\n\nexport const initMarkdown = ({ languages, imageSrcGetter }: InitMarkdownOptions): Extension => {\n return [\n markdownState,\n markdown({\n base: markdownLanguage,\n codeLanguages: languages,\n addKeymap: true,\n extensions: [markdownParserPlugin],\n }),\n markdownDecorationPlugin({ imageSrcGetter }),\n ];\n};\n"],"names":["NAME_OF_MENTION","CODE_OF_START_MENTION","CODE_OF_SPACE","markdownState","markdown","markdownLanguage","markdownDecorationPlugin"],"mappings":";;;;;;;;;;;;;;AAGO,MAAM,aAAa,GAAmB;AAC3C,IAAA,WAAW,EAAE,CAAC,EAAE,IAAI,EAAEA,qBAAe,EAAE,CAAC;AACxC,IAAA,WAAW,EAAE;AACX,QAAA;AACE,YAAA,IAAI,EAAEA,qBAAe;AACrB,YAAA,KAAK,CAAC,EAAE,EAAE,IAAI,EAAE,GAAG,EAAA;gBACjB,IAAI,IAAI,IAAIC,2BAAqB;oBAAE,OAAO,CAAC,CAAC;AAC5C,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,IAAI,GAAG,EAAE,CAAC,IAAI,CAAC,CAAC,CAAC;oBACvB,IAAI,IAAI,KAAKC,mBAAa;wBAAE;AAC5B,oBAAA,GAAG,EAAE;;AAGP,gBAAA,OAAO,EAAE,CAAC,UAAU,CAAC,EAAE,CAAC,GAAG,CAACF,qBAAe,EAAE,GAAG,EAAE,GAAG,CAAC,CAAC;aACxD;AACF,SAAA;AACF,KAAA;CACF;;AClBM,MAAM,oBAAoB,GAAsB,CAAC,aAAa,CAAC;;ACIzD,MAAA,YAAY,GAAG,CAAC,EAAE,SAAS,EAAE,cAAc,EAAuB,KAAe;IAC5F,OAAO;QACLG,mBAAa;AACb,QAAAC,qBAAQ,CAAC;AACP,YAAA,IAAI,EAAEC,6BAAgB;AACtB,YAAA,aAAa,EAAE,SAAS;AACxB,YAAA,SAAS,EAAE,IAAI;YACf,UAAU,EAAE,CAAC,oBAAoB,CAAC;SACnC,CAAC;AACF,QAAAC,8BAAwB,CAAC,EAAE,cAAc,EAAE,CAAC;KAC7C;AACH;;;;"}
1
+ {"version":3,"file":"index-DU8JMAfc.js","sources":["../../src/extensions/markdown/mention/mention-parser.ts","../../src/extensions/markdown/markdown-parser.ts","../../src/extensions/markdown/init-markdown.ts"],"sourcesContent":["import type { MarkdownConfig } from \"@lezer/markdown\";\nimport { CODE_OF_SPACE, CODE_OF_START_MENTION, NAME_OF_MENTION } 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, next, pos) {\n if (next != CODE_OF_START_MENTION) return -1;\n let end: number = pos + 1;\n for (let i = pos + 1; i < cx.end; i++) {\n const next = cx.char(i);\n if (next === CODE_OF_SPACE) break;\n end++;\n }\n\n return cx.addElement(cx.elt(NAME_OF_MENTION, pos, end));\n },\n },\n ],\n};\n","import type { MarkdownExtension } from \"@lezer/markdown\";\nimport { mentionParser } from \"./mention\";\n\nexport const markdownParserPlugin: MarkdownExtension = [mentionParser];\n","import { markdown, markdownLanguage } from \"@codemirror/lang-markdown\";\nimport { type Extension } from \"@codemirror/state\";\nimport { markdownDecorationPlugin } from \"./markdown-decoration\";\nimport { markdownParserPlugin } from \"./markdown-parser\";\nimport { markdownState } from \"./markdown-state\";\nimport type { InitMarkdownOptions } from \"./markdown-types\";\n\nexport const initMarkdown = ({ languages, imageSrcGetter }: InitMarkdownOptions): Extension => {\n return [\n markdownState,\n markdown({\n base: markdownLanguage,\n codeLanguages: languages,\n addKeymap: true,\n extensions: [markdownParserPlugin],\n }),\n markdownDecorationPlugin({ imageSrcGetter }),\n ];\n};\n"],"names":["NAME_OF_MENTION","CODE_OF_START_MENTION","CODE_OF_SPACE","markdownState","markdown","markdownLanguage","markdownDecorationPlugin"],"mappings":";;;;;;;;;;;;;;AAGO,MAAM,aAAa,GAAmB;AAC3C,IAAA,WAAW,EAAE,CAAC,EAAE,IAAI,EAAEA,qBAAe,EAAE,CAAC;AACxC,IAAA,WAAW,EAAE;AACX,QAAA;AACE,YAAA,IAAI,EAAEA,qBAAe;AACrB,YAAA,KAAK,CAAC,EAAE,EAAE,IAAI,EAAE,GAAG,EAAA;gBACjB,IAAI,IAAI,IAAIC,2BAAqB;oBAAE,OAAO,CAAC,CAAC;AAC5C,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,IAAI,GAAG,EAAE,CAAC,IAAI,CAAC,CAAC,CAAC;oBACvB,IAAI,IAAI,KAAKC,mBAAa;wBAAE;AAC5B,oBAAA,GAAG,EAAE;;AAGP,gBAAA,OAAO,EAAE,CAAC,UAAU,CAAC,EAAE,CAAC,GAAG,CAACF,qBAAe,EAAE,GAAG,EAAE,GAAG,CAAC,CAAC;aACxD;AACF,SAAA;AACF,KAAA;CACF;;AClBM,MAAM,oBAAoB,GAAsB,CAAC,aAAa,CAAC;;ACIzD,MAAA,YAAY,GAAG,CAAC,EAAE,SAAS,EAAE,cAAc,EAAuB,KAAe;IAC5F,OAAO;QACLG,mBAAa;AACb,QAAAC,qBAAQ,CAAC;AACP,YAAA,IAAI,EAAEC,6BAAgB;AACtB,YAAA,aAAa,EAAE,SAAS;AACxB,YAAA,SAAS,EAAE,IAAI;YACf,UAAU,EAAE,CAAC,oBAAoB,CAAC;SACnC,CAAC;AACF,QAAAC,8BAAwB,CAAC,EAAE,cAAc,EAAE,CAAC;KAC7C;AACH;;;;"}
package/lib/cjs/index.js CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
4
4
 
5
- const index = require('./index-nRNnOuav.js');
5
+ const index = require('./index-BgxbH3r2.js');
6
6
  require('@codemirror/commands');
7
7
  require('@codemirror/view');
8
8
  require('@codemirror/language');
@@ -5,18 +5,17 @@ import { markdownState } from '../markdown-state.js';
5
5
  import { NAME_OF_IMAGE, CODE_OF_START_IMAGE_TEXT, CODE_OF_START_IMAGE_URL, CODE_OF_END_IMAGE_TEXT, CODE_OF_END_IMAGE_URL } from './image-constants.js';
6
6
  import { ImageWidget } from './image-widget.js';
7
7
 
8
- function getImageDecorations({ decorations, node, view }) {
8
+ function getImageDecorations({ decorations, node, view, settings }) {
9
9
  if (node.name !== NAME_OF_IMAGE) {
10
10
  return;
11
11
  }
12
12
  const { text, url } = parseInfo(view, node);
13
- const imageSrcGetter = view.state.field(markdownState).imageSrcGetter;
14
13
  const uniqueId = view.state.field(markdownState).uniqueId;
15
14
  const line = view.lineBlockAt(node.from);
16
15
  const fullLine = line.from === node.from && line.to === node.to;
17
16
  decorations.push(getWidgetDecorationOptions({
18
17
  range: [node.to],
19
- widget: new ImageWidget(text, url, node.from, node.to, uniqueId, fullLine, imageSrcGetter, view),
18
+ widget: new ImageWidget(text, url, node.from, node.to, uniqueId, fullLine, settings.imageSrcGetter, view),
20
19
  }));
21
20
  }
22
21
  function getImageSelectionDecorations({ decorations, node, view, forceActive, }) {
@@ -1 +1 @@
1
- {"version":3,"file":"image-decoration.js","sources":["../../../../../src/extensions/markdown/image/image-decoration.ts"],"sourcesContent":["import { type EditorView } from \"@codemirror/view\";\nimport type { SyntaxNodeRef } from \"@lezer/common\";\nimport { utils } from \"@/lib\";\nimport { markdownState } from \"../markdown-state\";\nimport type {\n DecorationPlugin,\n GetDecorationOptions,\n GetSelectionDecorationOptions,\n} from \"../markdown-types\";\nimport {\n CODE_OF_END_IMAGE_TEXT,\n CODE_OF_END_IMAGE_URL,\n CODE_OF_START_IMAGE_TEXT,\n CODE_OF_START_IMAGE_URL,\n NAME_OF_IMAGE,\n} from \"./image-constants\";\nimport { ImageWidget } from \"./image-widget\";\n\nfunction getImageDecorations({ decorations, node, view }: GetDecorationOptions) {\n if (node.name !== NAME_OF_IMAGE) {\n return;\n }\n\n const { text, url } = parseInfo(view, node);\n const imageSrcGetter = view.state.field(markdownState).imageSrcGetter;\n const uniqueId = view.state.field(markdownState).uniqueId;\n const line = view.lineBlockAt(node.from);\n const fullLine = line.from === node.from && line.to === node.to;\n\n decorations.push(\n utils.getWidgetDecorationOptions({\n range: [node.to],\n widget: new ImageWidget(\n text,\n url,\n node.from,\n node.to,\n uniqueId,\n fullLine,\n imageSrcGetter,\n view,\n ),\n }),\n );\n}\n\nfunction getImageSelectionDecorations({\n decorations,\n node,\n view,\n forceActive,\n}: GetSelectionDecorationOptions) {\n if (node.name !== NAME_OF_IMAGE) {\n return;\n }\n\n const { text, url } = parseInfo(view, node);\n const openedImage = view.state.field(markdownState).openedImage;\n const uniqueId = view.state.field(markdownState).uniqueId;\n const key = `${url}:${text}:${uniqueId}:${node.from}:${node.to}`;\n const isOpened = openedImage && openedImage === 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(utils.getHideDecoration({ range: [node.from, node.to] }));\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\nfunction parseInfo(view: EditorView, node: SyntaxNodeRef) {\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_IMAGE_TEXT)\n textCoordinates.from = pos + 1;\n else if (\n urlCoordinates.from === -1 &&\n textCoordinates.to !== -1 &&\n code === CODE_OF_START_IMAGE_URL\n )\n urlCoordinates.from = pos + 1;\n else if (\n textCoordinates.from !== -1 &&\n textCoordinates.to === -1 &&\n code === CODE_OF_END_IMAGE_TEXT\n )\n textCoordinates.to = pos;\n else if (\n urlCoordinates.from !== -1 &&\n urlCoordinates.to === -1 &&\n code === CODE_OF_END_IMAGE_URL\n )\n urlCoordinates.to = pos;\n }\n\n const text = content.substring(textCoordinates.from, textCoordinates.to);\n const url = content.substring(urlCoordinates.from, urlCoordinates.to);\n\n return { text, url };\n}\n\nexport const imageDecorationPlugin: DecorationPlugin = {\n selectionDecorations: [getImageSelectionDecorations],\n decorations: [getImageDecorations],\n};\n"],"names":["utils.getWidgetDecorationOptions","utils.getMarkDecoration","utils.isInRange","utils.getHideDecoration"],"mappings":";;;;;;;AAkBA,SAAS,mBAAmB,CAAC,EAAE,WAAW,EAAE,IAAI,EAAE,IAAI,EAAwB,EAAA;AAC5E,IAAA,IAAI,IAAI,CAAC,IAAI,KAAK,aAAa,EAAE;QAC/B;;AAGF,IAAA,MAAM,EAAE,IAAI,EAAE,GAAG,EAAE,GAAG,SAAS,CAAC,IAAI,EAAE,IAAI,CAAC;AAC3C,IAAA,MAAM,cAAc,GAAG,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,aAAa,CAAC,CAAC,cAAc;AACrE,IAAA,MAAM,QAAQ,GAAG,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,aAAa,CAAC,CAAC,QAAQ;IACzD,MAAM,IAAI,GAAG,IAAI,CAAC,WAAW,CAAC,IAAI,CAAC,IAAI,CAAC;AACxC,IAAA,MAAM,QAAQ,GAAG,IAAI,CAAC,IAAI,KAAK,IAAI,CAAC,IAAI,IAAI,IAAI,CAAC,EAAE,KAAK,IAAI,CAAC,EAAE;AAE/D,IA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AAC;AAC1B,YAAA,eAAe,CAAC,EAAE,KAAK,CAAC,CAAC;AACzB,YAAA,IAAI,KAAK,uBAAuB;AAEhC,YAAA,cAAc,CAAC,IAAI,GAAG,GAAG,GAAG,CAAC;AAC1B,aAAA,IACH,eAAe,CAAC,IAAI,KAAK,CAAC,CAAC;AAC3B,YAAA,eAAe,CAAC,EAAE,KAAK,CAAC,CAAC;AACzB,YAAA,IAAI,KAAK,sBAAsB;AAE/B,YAAA,eAAe,CAAC,EAAE,GAAG,GAAG;AACrB,aAAA,IACH,cAAc,CAAC,IAAI,KAAK,CAAC,CAAC;AAC1B,YAAA,cAAc,CAAC,EAAE,KAAK,CAAC,CAAC;AACxB,YAAA,IAAI,KAAK,qBAAqB;AAE9B,YAAA,cAAc,CAAC,EAAE,GAAG,GAAG;;AAG3B,IAAA,MAAM,IAAI,GAAG,OAAO,CAAC,SAAS,CAAC,eAAe,CAAC,IAAI,EAAE,eAAe,CAAC,EAAE,CAAC;AACxE,IAAA,MAAM,GAAG,GAAG,OAAO,CAAC,SAAS,CAAC,cAAc,CAAC,IAAI,EAAE,cAAc,CAAC,EAAE,CAAC;AAErE,IAAA,OAAO,EAAE,IAAI,EAAE,GAAG,EAAE;AACtB;AAEa,MAAA,qBAAqB,GAAqB;IACrD,oBAAoB,EAAE,CAAC,4BAA4B,CAAC;IACpD,WAAW,EAAE,CAAC,mBAAmB,CAAC;;;;;"}
1
+ {"version":3,"file":"image-decoration.js","sources":["../../../../../src/extensions/markdown/image/image-decoration.ts"],"sourcesContent":["import { type EditorView } from \"@codemirror/view\";\nimport type { SyntaxNodeRef } from \"@lezer/common\";\nimport { utils } from \"@/lib\";\nimport { markdownState } from \"../markdown-state\";\nimport type {\n DecorationPlugin,\n GetDecorationOptions,\n GetSelectionDecorationOptions,\n} from \"../markdown-types\";\nimport {\n CODE_OF_END_IMAGE_TEXT,\n CODE_OF_END_IMAGE_URL,\n CODE_OF_START_IMAGE_TEXT,\n CODE_OF_START_IMAGE_URL,\n NAME_OF_IMAGE,\n} from \"./image-constants\";\nimport { ImageWidget } from \"./image-widget\";\n\nfunction getImageDecorations({ decorations, node, view, settings }: GetDecorationOptions) {\n if (node.name !== NAME_OF_IMAGE) {\n return;\n }\n\n const { text, url } = parseInfo(view, node);\n const uniqueId = view.state.field(markdownState).uniqueId;\n const line = view.lineBlockAt(node.from);\n const fullLine = line.from === node.from && line.to === node.to;\n\n decorations.push(\n utils.getWidgetDecorationOptions({\n range: [node.to],\n widget: new ImageWidget(\n text,\n url,\n node.from,\n node.to,\n uniqueId,\n fullLine,\n settings.imageSrcGetter,\n view,\n ),\n }),\n );\n}\n\nfunction getImageSelectionDecorations({\n decorations,\n node,\n view,\n forceActive,\n}: GetSelectionDecorationOptions) {\n if (node.name !== NAME_OF_IMAGE) {\n return;\n }\n\n const { text, url } = parseInfo(view, node);\n const openedImage = view.state.field(markdownState).openedImage;\n const uniqueId = view.state.field(markdownState).uniqueId;\n const key = `${url}:${text}:${uniqueId}:${node.from}:${node.to}`;\n const isOpened = openedImage && openedImage === 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(utils.getHideDecoration({ range: [node.from, node.to] }));\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\nfunction parseInfo(view: EditorView, node: SyntaxNodeRef) {\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_IMAGE_TEXT)\n textCoordinates.from = pos + 1;\n else if (\n urlCoordinates.from === -1 &&\n textCoordinates.to !== -1 &&\n code === CODE_OF_START_IMAGE_URL\n )\n urlCoordinates.from = pos + 1;\n else if (\n textCoordinates.from !== -1 &&\n textCoordinates.to === -1 &&\n code === CODE_OF_END_IMAGE_TEXT\n )\n textCoordinates.to = pos;\n else if (\n urlCoordinates.from !== -1 &&\n urlCoordinates.to === -1 &&\n code === CODE_OF_END_IMAGE_URL\n )\n urlCoordinates.to = pos;\n }\n\n const text = content.substring(textCoordinates.from, textCoordinates.to);\n const url = content.substring(urlCoordinates.from, urlCoordinates.to);\n\n return { text, url };\n}\n\nexport const imageDecorationPlugin: DecorationPlugin = {\n selectionDecorations: [getImageSelectionDecorations],\n decorations: [getImageDecorations],\n};\n"],"names":["utils.getWidgetDecorationOptions","utils.getMarkDecoration","utils.isInRange","utils.getHideDecoration"],"mappings":";;;;;;;AAkBA,SAAS,mBAAmB,CAAC,EAAE,WAAW,EAAE,IAAI,EAAE,IAAI,EAAE,QAAQ,EAAwB,EAAA;AACtF,IAAA,IAAI,IAAI,CAAC,IAAI,KAAK,aAAa,EAAE;QAC/B;;AAGF,IAAA,MAAM,EAAE,IAAI,EAAE,GAAG,EAAE,GAAG,SAAS,CAAC,IAAI,EAAE,IAAI,CAAC;AAC3C,IAAA,MAAM,QAAQ,GAAG,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,aAAa,CAAC,CAAC,QAAQ;IACzD,MAAM,IAAI,GAAG,IAAI,CAAC,WAAW,CAAC,IAAI,CAAC,IAAI,CAAC;AACxC,IAAA,MAAM,QAAQ,GAAG,IAAI,CAAC,IAAI,KAAK,IAAI,CAAC,IAAI,IAAI,IAAI,CAAC,EAAE,KAAK,IAAI,CAAC,EAAE;AAE/D,IAAA,WAAW,CAAC,IAAI,CACdA,0BAAgC,CAAC;AAC/B,QAAA,KAAK,EAAE,CAAC,IAAI,CAAC,EAAE,CAAC;QAChB,MAAM,EAAE,IAAI,WAAW,CACrB,IAAI,EACJ,GAAG,EACH,IAAI,CAAC,IAAI,EACT,I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CAAC,IAAI,KAAK,CAAC,CAAC;AAC3B,YAAA,eAAe,CAAC,EAAE,KAAK,CAAC,CAAC;AACzB,YAAA,IAAI,KAAK,sBAAsB;AAE/B,YAAA,eAAe,CAAC,EAAE,GAAG,GAAG;AACrB,aAAA,IACH,cAAc,CAAC,IAAI,KAAK,CAAC,CAAC;AAC1B,YAAA,cAAc,CAAC,EAAE,KAAK,CAAC,CAAC;AACxB,YAAA,IAAI,KAAK,qBAAqB;AAE9B,YAAA,cAAc,CAAC,EAAE,GAAG,GAAG;;AAG3B,IAAA,MAAM,IAAI,GAAG,OAAO,CAAC,SAAS,CAAC,eAAe,CAAC,IAAI,EAAE,eAAe,CAAC,EAAE,CAAC;AACxE,IAAA,MAAM,GAAG,GAAG,OAAO,CAAC,SAAS,CAAC,cAAc,CAAC,IAAI,EAAE,cAAc,CAAC,EAAE,CAAC;AAErE,IAAA,OAAO,EAAE,IAAI,EAAE,GAAG,EAAE;AACtB;AAEa,MAAA,qBAAqB,GAAqB;IACrD,oBAAoB,EAAE,CAAC,4BAA4B,CAAC;IACpD,WAAW,EAAE,CAAC,mBAAmB,CAAC;;;;;"}
@@ -4,6 +4,9 @@ import { openedImageEffect } from '../markdown-state.js';
4
4
  import styles from '../styles.module.scss.js';
5
5
 
6
6
  const IMAGE_NODES = {};
7
+ const INTERVAL_DELAY = 10000;
8
+ const EXISTING_WIDGETS = new Set();
9
+ let interval = null;
7
10
  class ImageWidget extends WidgetType {
8
11
  text;
9
12
  link;
@@ -36,6 +39,7 @@ class ImageWidget extends WidgetType {
36
39
  if (!image)
37
40
  return false;
38
41
  delete IMAGE_NODES[this.key];
42
+ EXISTING_WIDGETS.delete(this.key);
39
43
  if (image.src !== widget.src)
40
44
  image.src = widget.src;
41
45
  if (image.alt !== widget.text)
@@ -46,12 +50,14 @@ class ImageWidget extends WidgetType {
46
50
  this.to = widget.to;
47
51
  this.registerListeners(image);
48
52
  IMAGE_NODES[this.key] = image;
53
+ EXISTING_WIDGETS.add(this.key);
49
54
  return true;
50
55
  }
51
56
  updateDOM() {
52
57
  return true;
53
58
  }
54
59
  toDOM() {
60
+ EXISTING_WIDGETS.add(this.key);
55
61
  let container = IMAGE_NODES[this.key];
56
62
  let image = container?.image;
57
63
  if (image && container) {
@@ -76,11 +82,12 @@ class ImageWidget extends WidgetType {
76
82
  }
77
83
  this.registerListeners(container);
78
84
  IMAGE_NODES[this.key] = container;
85
+ if (!interval)
86
+ interval = setInterval(garbageCollectorInterval, INTERVAL_DELAY);
79
87
  return container;
80
88
  }
81
- destroy(dom) {
82
- delete IMAGE_NODES[this.key];
83
- dom.destroy?.();
89
+ destroy() {
90
+ EXISTING_WIDGETS.delete(this.key);
84
91
  }
85
92
  registerListeners(image) {
86
93
  image.clearListeners?.();
@@ -95,6 +102,19 @@ class ImageWidget extends WidgetType {
95
102
  };
96
103
  }
97
104
  }
105
+ /** for disable cache */
106
+ function garbageCollectorInterval() {
107
+ for (const [key, node] of Object.entries(IMAGE_NODES)) {
108
+ if (EXISTING_WIDGETS.has(key) || !node)
109
+ continue;
110
+ delete IMAGE_NODES[key];
111
+ node.destroy?.();
112
+ }
113
+ if (Object.keys(IMAGE_NODES).length === 0 && interval) {
114
+ clearInterval(interval);
115
+ interval = null;
116
+ }
117
+ }
98
118
  /** recursively find the link text node in line */
99
119
  function getTextNode(text, link, key, line) {
100
120
  if (!line)
@@ -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> = {};\n\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\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\n return true;\n }\n\n updateDOM(): boolean {\n return true;\n }\n\n toDOM(): HTMLElement {\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 return container;\n }\n\n destroy(dom: ImageContainerElement): void {\n delete IMAGE_NODES[this.key];\n dom.destroy?.();\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/** 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;AAQnE,MAAO,WAAY,SAAQ,UAAU,CAAA;AAE/B,IAAA,IAAA;AACA,IAAA,IAAA;AACA,IAAA,IAAA;AACA,IAAA,EAAA;AACA,IAAA,QAAA;AACA,IAAA,QAAA;AACA,IAAA,cAAA;AACA,IAAA,IAAA;AARV,IAAA,WAAA,CACU,IAAY,EACZ,IAAY,EACZ,IAAY,EACZ,EAAU,EACV,QAAgB,EAChB,QAAiB,EACjB,cAAqD,EACrD,IAAgB,EAAA;AAExB,QAAA,KAAK,EAAE;QATC,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,IAAQ,CAAA,QAAA,GAAR,QAAQ;QACR,IAAc,CAAA,cAAA,GAAd,cAAc;QACd,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,IAAI,GAAG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,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":["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;AAOpC,MAAO,WAAY,SAAQ,UAAU,CAAA;AAE/B,IAAA,IAAA;AACA,IAAA,IAAA;AACA,IAAA,IAAA;AACA,IAAA,EAAA;AACA,IAAA,QAAA;AACA,IAAA,QAAA;AACA,IAAA,cAAA;AACA,IAAA,IAAA;AARV,IAAA,WAAA,CACU,IAAY,EACZ,IAAY,EACZ,IAAY,EACZ,EAAU,EACV,QAAgB,EAChB,QAAiB,EACjB,cAAqD,EACrD,IAAgB,EAAA;AAExB,QAAA,KAAK,EAAE;QATC,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,IAAQ,CAAA,QAAA,GAAR,QAAQ;QACR,IAAc,CAAA,cAAA,GAAd,cAAc;QACd,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,CAA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12,12 +12,12 @@ function getItalicDecorations({ decorations, node }) {
12
12
  range: [node.from, node.to],
13
13
  }));
14
14
  }
15
- function getItalicSelectionDecorations({ decorations, node, view, forceActive, }) {
15
+ function getItalicSelectionDecorations({ decorations, node, view, forceActive, settings, }) {
16
16
  if (node.name !== NAME_OF_ITALIC) {
17
17
  return;
18
18
  }
19
- if (checkIsSeveralEmphasis({ decorations, node, view, forceActive })) {
20
- return void splitEmphasis({ decorations, node, view, forceActive });
19
+ if (checkIsSeveralEmphasis({ decorations, node, view, forceActive, settings })) {
20
+ return void splitEmphasis({ decorations, node, view, forceActive, settings });
21
21
  }
22
22
  let step = 1;
23
23
  const startText = view.state.doc.sliceString(node.from, node.from + 3);
@@ -46,7 +46,7 @@ function checkIsSeveralEmphasis({ node, view }) {
46
46
  return true;
47
47
  return false;
48
48
  }
49
- function splitEmphasis({ decorations, node, view, forceActive }) {
49
+ function splitEmphasis({ decorations, node, view, forceActive, settings, }) {
50
50
  const text = view.state.doc.sliceString(node.from, node.to);
51
51
  let marks = 0;
52
52
  let pos = 0;
@@ -60,12 +60,14 @@ function splitEmphasis({ decorations, node, view, forceActive }) {
60
60
  view,
61
61
  node: { ...node, name: node.name, from: node.from, to: node.from + pos },
62
62
  forceActive,
63
+ settings,
63
64
  });
64
65
  getItalicSelectionDecorations({
65
66
  decorations,
66
67
  view,
67
68
  node: { ...node, name: node.name, from: node.from + pos, to: node.to },
68
69
  forceActive,
70
+ settings,
69
71
  });
70
72
  }
71
73
  const italicDecorationPlugin = {
@@ -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}: GetSelectionDecorationOptions) {\n if (node.name !== NAME_OF_ITALIC) {\n return;\n }\n\n if (checkIsSeveralEmphasis({ decorations, node, view, forceActive })) {\n return void splitEmphasis({ decorations, node, view, forceActive });\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({ decorations, node, view, forceActive }: 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 });\n getItalicSelectionDecorations({\n decorations,\n view,\n node: { ...node, name: node.name, from: node.from + pos, to: node.to },\n forceActive,\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,GACmB,EAAA;AAC9B,IAAA,IAAI,IAAI,CAAC,IAAI,KAAK,cAAc,EAAE;QAChC;;AAGF,IAAA,IAAI,sBAAsB,CAAC,EAAE,WAAW,EAAE,IAAI,EAAE,IAAI,EAAE,WAAW,EAAE,CAAC,EAAE;AACpE,QAAA,OAAO,KAAK,aAAa,CAAC,EAAE,WAAW,EAAE,IAAI,EAAE,IAAI,EAAE,WAAW,EAAE,CAAC;;IAGrE,IAAI,IAAI,GAAG,CAAC;IACZ,MAAM,SAAS,GAAG,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,WAAW,CAAC,IAAI,CAAC,IAAI,EAAE,IAAI,CAAC,IAAI,GAAG,CAAC,CAAC;IACtE,IACE,oBAAoB,CAAC,GAAG,CAAC,SAAS,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC;QACjD,oBAAoB,CAAC,GAAG,CAAC,SAAS,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC;QACjD,oBAAoB,CAAC,GAAG,CAAC,SAAS,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC;QAEjD,IAAI,GAAG,CAA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IAC3D,IAAI,KAAK,GAAG,CAAC;IACb,IAAI,GAAG,GAAG,CAAC;IAEX,OAAO,GAAG,IAAI,IAAI,CAAC,MAAM,IAAI,KAAK,GAAG,CAAC,EAAE;QACtC,IAAI,oBAAoB,CAAC,GAAG,CAAC,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC,CAAC;AAAE,YAAA,KAAK,EAAE;AAC3D,QAAA,GAAG,EAAE;;AAGP,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,EAAE,EAAE,EAAE,IAAI,CAAC,IAAI,GAAG,GAAG,EAAE;QACxE,WAAW;AACZ,KAAA,CAAC;AACF,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;AACZ,KAAA,CAAC;AACJ;AAEa,MAAA,sBAAsB,GAAqB;IACtD,WAAW,EAAE,CAAC,oBAAoB,CAAC;IACnC,oBAAoB,EAAE,CAAC,6BAA6B,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,EACJ,WAAW,EACX,QAAQ,GACsB,EAAA;AAC9B,IAAA,IAAI,IAAI,CAAC,IAAI,KAAK,cAAc,EAAE;QAChC;;AAGF,IAAA,IAAI,sBAAsB,CAAC,EAAE,WAAW,EAAE,IAAI,EAAE,IAAI,EAAE,WAAW,EAAE,QAAQ,EAAE,CAAC,EAAE;AAC9E,QAAA,OAAO,KAAK,aAAa,CAAC,EAAE,WAAW,EAAE,IAAI,EAAE,IAAI,EAAE,WAAW,EAAE,QAAQ,EAAE,CAAC;;IAG/E,IAAI,IAAI,GAAG,CAAC;IACZ,MAAM,SAAS,GAAG,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,WAAW,CAAC,IAAI,CAAC,IAAI,EAAE,IAAI,CAAC,IAAI,GAAG,CAAC,CAAC;IACtE,IACE,oBAAoB,CAAC,GAAG,CAAC,SAAS,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC;QACjD,oBAAoB,CAAC,GAAG,CAAC,SAAS,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC;QACjD,oBAAoB,CAAC,GAAG,CAAC,SAAS,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC;QAEjD,IAAI,GAAG,CAAC;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,CAAC;IAC3D,IAAI,KAAK,GAAG,CAAC;IACb,IAAI,GAAG,GAAG,CAAC;IAEX,OAAO,GAAG,IAAI,IAAI,CAAC,MAAM,IAAI,KAAK,GAAG,CAAC,EAAE;QACtC,IAAI,oBAAoB,CAAC,GAAG,CAAC,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC,CAAC;AAAE,YAAA,KAAK,EAAE;AAC3D,QAAA,GAAG,EAAE;;AAGP,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,EAAE,EAAE,EAAE,IAAI,CAAC,IAAI,GAAG,GAAG,EAAE;QACxE,WAAW;QACX,QAAQ;AACT,KAAA,CAAC;AACF,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;;;;;"}
@@ -5,7 +5,7 @@ import { NAME_OF_LINK, CODE_OF_START_LINK_TEXT, CODE_OF_START_LINK_URL, CODE_OF_
5
5
  import { getLinkLabelSelectionDecoration } from './link-label-decoration.js';
6
6
  import { LinkWidget } from './link-widget.js';
7
7
 
8
- function getLinkSelectionDecorations({ decorations, node, view, forceActive, }) {
8
+ function getLinkSelectionDecorations({ decorations, node, view, forceActive, settings, }) {
9
9
  if (node.name !== NAME_OF_LINK) {
10
10
  return;
11
11
  }
@@ -32,7 +32,7 @@ function getLinkSelectionDecorations({ decorations, node, view, forceActive, })
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, settings });
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}: 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 });\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,GACmB,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,CAAC,CAAC,EAAE,EAAE,EAAE,CAAC,CAAC,EAAE;AAC5C,IAAA,MAAM,cAAc,GAAG,EAAE,IAAI,EAAE,CAA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AAA,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;;;;;"}
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,CAAC,CAAC,EAAE,EAAE,EAAE,CAAC,CAAC,EAAE;AAC5C,IAAA,MAAM,cAAc,GAAG,EAAE,IAAI,EAAE,CAAC,CAA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;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;;;;;"}
@@ -12,7 +12,6 @@ import { italicDecorationPlugin } from './italic/italic-decoration.js';
12
12
  import { linkDecorationPlugin } from './link/link-decoration.js';
13
13
  import { autoLinkDecorationPlugin } from './link/auto-link-decoration.js';
14
14
  import { listDecorationPlugin } from './list/list-decoration.js';
15
- import { imageSrcGetterEffect } from './markdown-state.js';
16
15
  import { mentionDecorationPlugin } from './mention/mention-decoration.js';
17
16
  import { strikeThroughDecorationPlugin } from './strike-through/strike-through-decoration.js';
18
17
  import { todoDecorationPlugin } from './todo/todo-decoration.js';
@@ -57,7 +56,7 @@ const SKIP_MARKS = new Set([
57
56
  "HeaderMark",
58
57
  "TaskMarker",
59
58
  ]);
60
- function createDecorationsGetter() {
59
+ function createDecorationsGetter(settings) {
61
60
  let markdownDecorationsCache = [];
62
61
  let markdownSelectionDecorationsCache = [];
63
62
  function getDecorations(view, isChanged, mouseReleased) {
@@ -78,7 +77,7 @@ function createDecorationsGetter() {
78
77
  return;
79
78
  /** Decoration by change content */
80
79
  if (processDecorations)
81
- decorationFunctions.forEach((f) => f({ decorations, node, view }));
80
+ decorationFunctions.forEach((f) => f({ decorations, node, view, settings }));
82
81
  /** Decoration by selection content */
83
82
  if (processSelectionDecorations)
84
83
  selectionDecorationFunctions.forEach((f) => f({
@@ -86,6 +85,7 @@ function createDecorationsGetter() {
86
85
  node,
87
86
  view,
88
87
  forceActive: isReadonly,
88
+ settings,
89
89
  }));
90
90
  },
91
91
  });
@@ -100,7 +100,7 @@ function createDecorationsGetter() {
100
100
  }
101
101
  return getDecorations;
102
102
  }
103
- const markdownDecorationPlugin = (stateConfig) => {
103
+ const markdownDecorationPlugin = (settings) => {
104
104
  return ViewPlugin.fromClass(class DecorationMarkdown {
105
105
  decorations;
106
106
  mouseReleased = true;
@@ -108,17 +108,12 @@ const markdownDecorationPlugin = (stateConfig) => {
108
108
  view;
109
109
  decorationGetter;
110
110
  constructor(view) {
111
- this.decorationGetter = createDecorationsGetter();
111
+ this.decorationGetter = createDecorationsGetter(settings);
112
112
  this.decorations = this.decorationGetter(view, true, this.mouseReleased);
113
113
  this.dom = view.dom;
114
114
  this.view = view;
115
115
  document.addEventListener("mousedown", this.onMouseDown.bind(this));
116
116
  document.addEventListener("mouseup", this.onMouseUp.bind(this));
117
- saveDispatch(() => {
118
- this.view.dispatch(this.view.state.update({
119
- effects: [imageSrcGetterEffect.of(stateConfig.imageSrcGetter)],
120
- }));
121
- });
122
117
  }
123
118
  update(update) {
124
119
  const isDocumentChanged = update.docChanged ||
@@ -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 { imageSrcGetterEffect } from \"./markdown-state\";\nimport type {\n DecorationPlugin,\n GetDecorationFunction,\n GetSelectionDecorationFunction,\n MarkdownStateConfig,\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() {\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((f) => f({ decorations, node, view }));\n\n /** Decoration by selection content */\n if (processSelectionDecorations)\n selectionDecorationFunctions.forEach((f) =>\n f({\n decorations: selectionDecorations,\n node,\n view,\n forceActive: isReadonly,\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 = (stateConfig: MarkdownStateConfig) => {\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();\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 saveDispatch(() => {\n this.view.dispatch(\n this.view.state.update({\n effects: [imageSrcGetterEffect.of(stateConfig.imageSrcGetter)],\n }),\n );\n });\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":";;;;;;;;;;;;;;;;;;;AA8BA,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,MAAM,MAAM,IAAI,iBAAiB,EAAE;IACtC,IAAI,MAAM,CAAC,WAAW;QAAE,mBAAmB,GAAG,mBAAmB,CAAC,MAAM,CAAC,MAAM,CAAC,WAAW,CAAC;IAC5F,IAAI,MAAM,CAAC,oBAAoB;QAC7B,4BAA4B,GAAG,4BAA4B,CAAC,MAAM,CAAC,MAAM,CAAC,oBAAoB,CAAC;AACnG;AAEA,MAAM,UAAU,GAAG,IAAI,GAAG,CAAC;IACzB,UAAU;IACV,WAAW;IACX,cAAc;IACd,YAAY;IACZ,mBAAmB;IACnB,YAAY;IACZ,aAAa;IACb,UAAU;IACV,UAAU;IACV,KAAK;IACL,UAAU;IACV,UAAU;IACV,UAAU;IACV,YAAY;IACZ,YAAY;AACb,CAAA,CAAC;AAEF,SAAS,uBAAuB,GAAA;IAC9B,IAAI,wBAAwB,GAAwB,EAAE;IACtD,IAAI,iCAAiC,GAAwB,EAAE;AAE/D,IAAA,SAAS,cAAc,CAAC,IAAgB,EAAE,SAAkB,EAAE,aAAsB,EAAA;QAClF,MAAM,kBAAkB,GAAG,SAAS;AACpC,QAAA,MAAM,2BAA2B,GAAG,S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AAC,WAAW,GAAG,IAAI,CAAC,gBAAgB,CACtC,MAAM,CAAC,IAAI,EACX,iBAAiB,EACjB,IAAI,CAAC,aAAa,CACnB;;QAGH,OAAO,GAAA;AACL,YAAA,QAAQ,CAAC,mBAAmB,CAAC,WAAW,EAAE,IAAI,CAAC,WAAW,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;AACtE,YAAA,QAAQ,CAAC,mBAAmB,CAAC,SAAS,EAAE,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;;QAGpE,WAAW,GAAA;AACT,YAAA,IAAI,CAAC,aAAa,GAAG,KAAK;;QAG5B,SAAS,GAAA;AACP,YAAA,IAAI,CAAC,aAAa,GAAG,IAAI;AACzB,YAAA,IAAI,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC,SAAS,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,IAAI,KAAK,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC,SAAS,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,EAAE,EAAE;gBACvF,YAAY,CAAC,MAAK;AAChB,oBAAA,IAAI,CAAC,IAAI,CAAC,QAAQ,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
+ {"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((f) => f({ decorations, node, view, settings }));\n\n /** Decoration by selection content */\n if (processSelectionDecorations)\n selectionDecorationFunctions.forEach((f) =>\n f({\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,MAAM,MAAM,IAAI,iBAAiB,EAAE;IACtC,IAAI,MAAM,CAAC,WAAW;QAAE,mBAAmB,GAAG,mBAAmB,CAAC,MAAM,CAAC,MAAM,CAAC,WAAW,CAAC;IAC5F,IAAI,MAAM,CAAC,oBAAoB;QAC7B,4BAA4B,GAAG,4BAA4B,CAAC,MAAM,CAAC,MAAM,CAAC,oBAAoB,CAAC;AACnG;AAEA,MAAM,UAAU,GAAG,IAAI,GAAG,CAAC;IACzB,UAAU;IACV,WAAW;IACX,cAAc;IACd,YAAY;IACZ,mBAAmB;IACnB,YAAY;IACZ,aAAa;IACb,UAAU;IACV,UAAU;IACV,KAAK;IACL,UAAU;IACV,UAAU;IACV,UAAU;IACV,YAAY;IACZ,YAAY;AACb,CAAA,CAAC;AAEF,SAAS,uBAAuB,CAAC,QAAoC,E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WAAW,GAAG,IAAI,CAAC,gBAAgB,CACtC,MAAM,CAAC,IAAI,EACX,iBAAiB,EACjB,IAAI,CAAC,aAAa,CACnB;;QAGH,OAAO,GAAA;AACL,YAAA,QAAQ,CAAC,mBAAmB,CAAC,WAAW,EAAE,IAAI,CAAC,WAAW,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;AACtE,YAAA,QAAQ,CAAC,mBAAmB,CAAC,SAAS,EAAE,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;;QAGpE,WAAW,GAAA;AACT,YAAA,IAAI,CAAC,aAAa,GAAG,KAAK;;QAG5B,SAAS,GAAA;AACP,YAAA,IAAI,CAAC,aAAa,GAAG,IAAI;AACzB,YAAA,IAAI,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC,SAAS,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,IAAI,KAAK,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC,SAAS,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,EAAE,EAAE;gBACvF,YAAY,CAAC,MAAK;AAChB,oBAAA,IAAI,CAAC,IAAI,CAAC,QAAQ,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;;;;"}
@@ -4,12 +4,10 @@ import { randomString } from '../../lib/utils/random-string.js';
4
4
 
5
5
  const openedImageEffect = StateEffect.define();
6
6
  const openedLinkEffect = StateEffect.define();
7
- const imageSrcGetterEffect = StateEffect.define();
8
7
  const markdownState = StateField.define({
9
8
  create() {
10
9
  return {
11
10
  openedImage: undefined,
12
- imageSrcGetter: undefined,
13
11
  openedLink: undefined,
14
12
  uniqueId: randomString(10),
15
13
  };
@@ -19,8 +17,6 @@ const markdownState = StateField.define({
19
17
  for (const effect of transaction.effects) {
20
18
  if (effect.is(openedImageEffect))
21
19
  newValue.openedImage = effect.value;
22
- if (effect.is(imageSrcGetterEffect))
23
- newValue.imageSrcGetter = effect.value;
24
20
  if (effect.is(openedLinkEffect))
25
21
  newValue.openedLink = effect.value;
26
22
  }
@@ -28,5 +24,5 @@ const markdownState = StateField.define({
28
24
  },
29
25
  });
30
26
 
31
- export { imageSrcGetterEffect, markdownState, openedImageEffect, openedLinkEffect };
27
+ export { markdownState, openedImageEffect, openedLinkEffect };
32
28
  //# sourceMappingURL=markdown-state.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"markdown-state.js","sources":["../../../../src/extensions/markdown/markdown-state.ts"],"sourcesContent":["import { StateEffect, StateField } from \"@codemirror/state\";\nimport { randomString } from \"@/lib/utils\";\nimport type { MarkdownState } from \"./markdown-types\";\n\nexport const openedImageEffect = StateEffect.define<string | undefined>();\nexport const openedLinkEffect = StateEffect.define<string | undefined>();\nexport const imageSrcGetterEffect = StateEffect.define<((src: string) => string) | undefined>();\n\nexport const markdownState = StateField.define<MarkdownState>({\n create() {\n return {\n openedImage: undefined,\n imageSrcGetter: undefined,\n openedLink: undefined,\n uniqueId: randomString(10),\n };\n },\n\n update(value, transaction) {\n const newValue = { ...value };\n\n for (const effect of transaction.effects) {\n if (effect.is(openedImageEffect)) newValue.openedImage = effect.value;\n if (effect.is(imageSrcGetterEffect)) newValue.imageSrcGetter = effect.value;\n if (effect.is(openedLinkEffect)) newValue.openedLink = effect.value;\n }\n\n return newValue;\n },\n});\n"],"names":[],"mappings":";;;;MAIa,iBAAiB,GAAG,WAAW,CAAC,MAAM;MACtC,gBAAgB,GAAG,WAAW,CAAC,MAAM;MACrC,oBAAoB,GAAG,WAAW,CAAC,MAAM;AAEzC,MAAA,aAAa,GAAG,UAAU,CAAC,MAAM,CAAgB;IAC5D,MAAM,GAAA;QACJ,OAAO;AACL,YAAA,WAAW,EAAE,SAAS;AACtB,YAAA,cAAc,EAAE,SAAS;AACzB,YAAA,UAAU,EAAE,SAAS;AACrB,YAAA,QAAQ,EAAE,YAAY,CAAC,EAAE,CAAC;SAC3B;KACF;IAED,MAAM,CAAC,KAAK,EAAE,WAAW,EAAA;AACvB,QAAA,MAAM,QAAQ,GAAG,EAAE,GAAG,KAAK,EAAE;AAE7B,QAAA,KAAK,MAAM,MAAM,IAAI,WAAW,CAAC,OAAO,EAAE;AACxC,YAAA,IAAI,MAAM,CAAC,EAAE,CAAC,iBAAiB,CAAC;AAAE,gBAAA,QAAQ,CAAC,WAAW,GAAG,MAAM,CAAC,KAAK;AACrE,YAAA,IAAI,MAAM,CAAC,EAAE,CAAC,oBAAoB,CAAC;AAAE,gBAAA,QAAQ,CAAC,cAAc,GAAG,MAAM,CAAC,KAAK;AAC3E,YAAA,IAAI,MAAM,CAAC,EAAE,CAAC,gBAAgB,CAAC;AAAE,gBAAA,QAAQ,CAAC,UAAU,GAAG,MAAM,CAAC,KAAK;;AAGrE,QAAA,OAAO,QAAQ;KAChB;AACF,CAAA;;;;"}
1
+ {"version":3,"file":"markdown-state.js","sources":["../../../../src/extensions/markdown/markdown-state.ts"],"sourcesContent":["import { StateEffect, StateField } from \"@codemirror/state\";\nimport { randomString } from \"@/lib/utils\";\nimport type { MarkdownState } from \"./markdown-types\";\n\nexport const openedImageEffect = StateEffect.define<string | undefined>();\nexport const openedLinkEffect = StateEffect.define<string | undefined>();\n\nexport const markdownState = StateField.define<MarkdownState>({\n create() {\n return {\n openedImage: undefined,\n openedLink: undefined,\n uniqueId: randomString(10),\n };\n },\n\n update(value, transaction) {\n const newValue = { ...value };\n\n for (const effect of transaction.effects) {\n if (effect.is(openedImageEffect)) newValue.openedImage = effect.value;\n if (effect.is(openedLinkEffect)) newValue.openedLink = effect.value;\n }\n\n return newValue;\n },\n});\n"],"names":[],"mappings":";;;;MAIa,iBAAiB,GAAG,WAAW,CAAC,MAAM;MACtC,gBAAgB,GAAG,WAAW,CAAC,MAAM;AAErC,MAAA,aAAa,GAAG,UAAU,CAAC,MAAM,CAAgB;IAC5D,MAAM,GAAA;QACJ,OAAO;AACL,YAAA,WAAW,EAAE,SAAS;AACtB,YAAA,UAAU,EAAE,SAAS;AACrB,YAAA,QAAQ,EAAE,YAAY,CAAC,EAAE,CAAC;SAC3B;KACF;IAED,MAAM,CAAC,KAAK,EAAE,WAAW,EAAA;AACvB,QAAA,MAAM,QAAQ,GAAG,EAAE,GAAG,KAAK,EAAE;AAE7B,QAAA,KAAK,MAAM,MAAM,IAAI,WAAW,CAAC,OAAO,EAAE;AACxC,YAAA,IAAI,MAAM,CAAC,EAAE,CAAC,iBAAiB,CAAC;AAAE,gBAAA,QAAQ,CAAC,WAAW,GAAG,MAAM,CAAC,KAAK;AACrE,YAAA,IAAI,MAAM,CAAC,EAAE,CAAC,gBAAgB,CAAC;AAAE,gBAAA,QAAQ,CAAC,UAAU,GAAG,MAAM,CAAC,KAAK;;AAGrE,QAAA,OAAO,QAAQ;KAChB;AACF,CAAA;;;;"}
package/lib/index.d.ts CHANGED
@@ -81,12 +81,14 @@ type GetDecorationOptions = {
81
81
  node: SyntaxNodeRef;
82
82
  decorations: Range<Decoration>[];
83
83
  view: EditorView;
84
+ settings: MarkdownDecorationSettings;
84
85
  };
85
86
  type GetSelectionDecorationOptions = {
86
87
  node: SyntaxNodeRef;
87
88
  decorations: Range<Decoration>[];
88
89
  view: EditorView;
89
90
  forceActive: boolean;
91
+ settings: MarkdownDecorationSettings;
90
92
  };
91
93
  type GetDecorationFunction = (options: GetDecorationOptions) => void;
92
94
  type GetSelectionDecorationFunction = (options: GetSelectionDecorationOptions) => void;
@@ -94,6 +96,9 @@ type DecorationPlugin = {
94
96
  decorations?: GetDecorationFunction[];
95
97
  selectionDecorations?: GetSelectionDecorationFunction[];
96
98
  };
99
+ type MarkdownDecorationSettings = {
100
+ imageSrcGetter?: (src: string) => string;
101
+ };
97
102
 
98
103
  type InitSettingsOptions = {
99
104
  readonly?: boolean;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@krainovsd/markdown-editor",
3
- "version": "0.3.1",
3
+ "version": "0.3.2",
4
4
  "description": "Krainov markdown-editor",
5
5
  "type": "module",
6
6
  "author": "KrainovSD <denislosev48@gmail.com>",