@dou-ui/editor 0.1.0-alpha.1 → 0.1.0-alpha.11
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/code/code-editor-block.js.map +1 -1
- package/dist/code/code-editor-block.vue_vue_type_script_setup_true_lang.js +1 -0
- package/dist/code/code-editor-block.vue_vue_type_script_setup_true_lang.js.map +1 -1
- package/dist/collaboration/binding.js +344 -42
- package/dist/collaboration/binding.js.map +1 -1
- package/dist/collaboration/index.js +30 -10
- package/dist/collaboration/index.js.map +1 -1
- package/dist/components/block-handle.js.map +1 -1
- package/dist/components/block-handle.vue_vue_type_script_setup_true_lang.js +1 -1
- package/dist/components/block-handle.vue_vue_type_script_setup_true_lang.js.map +1 -1
- package/dist/components/bubble-toolbar.js.map +1 -1
- package/dist/components/bubble-toolbar.vue_vue_type_script_setup_true_lang.js +2 -1
- package/dist/components/bubble-toolbar.vue_vue_type_script_setup_true_lang.js.map +1 -1
- package/dist/components/comment-card.js.map +1 -1
- package/dist/components/comment-card.vue_vue_type_script_setup_true_lang.js +2 -1
- package/dist/components/comment-card.vue_vue_type_script_setup_true_lang.js.map +1 -1
- package/dist/core/convert.js +3 -3
- package/dist/core/convert.js.map +1 -1
- package/dist/core/editor.js +2 -1
- package/dist/core/editor.js.map +1 -1
- package/dist/core/plugins.js +108 -5
- package/dist/core/plugins.js.map +1 -1
- package/dist/core/prepare.js +12 -5
- package/dist/core/prepare.js.map +1 -1
- package/dist/dom.js +6 -1
- package/dist/dom.js.map +1 -1
- package/dist/extensions/align/align-menu.js.map +1 -1
- package/dist/extensions/align/align-menu.vue_vue_type_script_setup_true_lang.js +4 -6
- package/dist/extensions/align/align-menu.vue_vue_type_script_setup_true_lang.js.map +1 -1
- package/dist/extensions/callout/html.js +5 -4
- package/dist/extensions/callout/html.js.map +1 -1
- package/dist/extensions/colors/color-menu.js.map +1 -1
- package/dist/extensions/colors/color-menu.vue_vue_type_script_setup_true_lang.js +6 -8
- package/dist/extensions/colors/color-menu.vue_vue_type_script_setup_true_lang.js.map +1 -1
- package/dist/extensions/list-html.js +1 -1
- package/dist/extensions/list-html.js.map +1 -1
- package/dist/index.js.map +1 -1
- package/dist/markdown/index.js +2 -2
- package/dist/markdown/index.js.map +1 -1
- package/dist/style.css +1 -1
- package/dist/style.js +0 -1
- package/dist/types/collaboration/binding.d.ts +8 -0
- package/dist/types/collaboration/index.d.ts +36 -4
- package/dist/types/core/convert.d.ts +10 -2
- package/dist/types/core/plugins.d.ts +9 -0
- package/dist/types/core/prepare.d.ts +16 -2
- package/dist/types/dom.d.ts +2 -0
- package/dist/types/index.d.ts +2 -1
- package/dist/types/markdown/index.d.ts +8 -1
- package/package.json +5 -5
package/dist/core/prepare.js
CHANGED
|
@@ -31,7 +31,7 @@ function splitContainer(element) {
|
|
|
31
31
|
const nodes = Array.from(element.childNodes);
|
|
32
32
|
while (nodes.length && isBlank(nodes[0])) nodes.shift();
|
|
33
33
|
const first = nodes[0];
|
|
34
|
-
if (first
|
|
34
|
+
if (first?.nodeType === 1 && first.tagName === "P") return {
|
|
35
35
|
content: Array.from(first.childNodes),
|
|
36
36
|
children: nodes.slice(1)
|
|
37
37
|
};
|
|
@@ -68,14 +68,21 @@ var BLOCK_TAGS = /* @__PURE__ */ new Set([
|
|
|
68
68
|
"UL"
|
|
69
69
|
]);
|
|
70
70
|
var isBlank = (node) => node.nodeType === 3 && !node.textContent?.trim();
|
|
71
|
-
var isBlockElement = (node) => node
|
|
71
|
+
var isBlockElement = (node) => node.nodeType === 1 && BLOCK_TAGS.has(node.tagName);
|
|
72
72
|
/** Run every extension's `prepareHTML` over the markup. */
|
|
73
73
|
function prepareElement(root, kit) {
|
|
74
74
|
for (const extension of kit.extensions) extension.prepareHTML?.(root);
|
|
75
75
|
}
|
|
76
|
-
/**
|
|
77
|
-
|
|
78
|
-
|
|
76
|
+
/**
|
|
77
|
+
* Read HTML as blocks, with the block types, inline nodes and marks of `kit`.
|
|
78
|
+
* Uses the global `DOMParser` unless given `domParser`; `name` is the
|
|
79
|
+
* function the error message tells to pass one to.
|
|
80
|
+
*/
|
|
81
|
+
function parseHTML(html, kit, domParser, name = "htmlToBlocks(html, extensions, { domParser })") {
|
|
82
|
+
const parser = domParser ?? (typeof DOMParser === "undefined" ? null : new DOMParser());
|
|
83
|
+
if (!parser) throw new Error(`[@dou-ui/editor] reading HTML needs a DOMParser, and there is none here: pass one from a DOM library such as happy-dom or linkedom, as ${name}`);
|
|
84
|
+
const whole = /^\s*<(!doctype|html)/i.test(html) ? html : `<!doctype html><html><head></head><body>${html}</body></html>`;
|
|
85
|
+
const doc = parser.parseFromString(whole, "text/html");
|
|
79
86
|
prepareElement(doc.body, kit);
|
|
80
87
|
const blocks = docToBlocks(DOMParser$1.fromSchema(kit.schema).parse(doc.body));
|
|
81
88
|
const fill = (list) => list.map((block) => ({
|
package/dist/core/prepare.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"prepare.js","names":["PMDOMParser"],"sources":["../../src/core/prepare.ts"],"sourcesContent":["import { DOMParser as PMDOMParser } from 'prosemirror-model'\nimport { Plugin, PluginKey } from 'prosemirror-state'\nimport type { ResolvedEditorExtensions } from './extension'\nimport { createId, docToBlocks, type Block } from './model'\n\n/**\n * The editor's own markup for a block: a content element of `type` holding\n * `content`, followed by a group holding `children`. Extensions use it in\n * `prepareHTML` to turn containers such as `<details>` into blocks.\n */\nexport function blockElement(\n doc: Document,\n type: string,\n content: Node[],\n children: Node[] = [],\n data: Record<string, string> = {},\n): HTMLElement {\n const block = doc.createElement('div')\n block.dataset.blockId = ''\n const element = doc.createElement('div')\n element.dataset.contentType = type\n Object.assign(element.dataset, data)\n element.append(...content)\n block.append(element)\n if (children.some((node) => node.nodeType === 1 || node.textContent?.trim())) {\n const group = doc.createElement('div')\n group.className = 'dou-editor__group'\n group.append(...children)\n block.append(group)\n }\n return block\n}\n\n/**\n * Split a container's children into its own text (the first paragraph, or\n * the inline nodes before the first block element) and the blocks after it.\n */\nexport function splitContainer(element: Element): { content: Node[]; children: Node[] } {\n const nodes = Array.from(element.childNodes)\n while (nodes.length && isBlank(nodes[0]!)) nodes.shift()\n const first = nodes[0]\n if (first
|
|
1
|
+
{"version":3,"file":"prepare.js","names":["PMDOMParser"],"sources":["../../src/core/prepare.ts"],"sourcesContent":["import { DOMParser as PMDOMParser } from 'prosemirror-model'\nimport { Plugin, PluginKey } from 'prosemirror-state'\nimport type { ResolvedEditorExtensions } from './extension'\nimport { createId, docToBlocks, type Block } from './model'\n\n/**\n * The editor's own markup for a block: a content element of `type` holding\n * `content`, followed by a group holding `children`. Extensions use it in\n * `prepareHTML` to turn containers such as `<details>` into blocks.\n */\nexport function blockElement(\n doc: Document,\n type: string,\n content: Node[],\n children: Node[] = [],\n data: Record<string, string> = {},\n): HTMLElement {\n const block = doc.createElement('div')\n block.dataset.blockId = ''\n const element = doc.createElement('div')\n element.dataset.contentType = type\n Object.assign(element.dataset, data)\n element.append(...content)\n block.append(element)\n if (children.some((node) => node.nodeType === 1 || node.textContent?.trim())) {\n const group = doc.createElement('div')\n group.className = 'dou-editor__group'\n group.append(...children)\n block.append(group)\n }\n return block\n}\n\n/**\n * Split a container's children into its own text (the first paragraph, or\n * the inline nodes before the first block element) and the blocks after it.\n */\nexport function splitContainer(element: Element): { content: Node[]; children: Node[] } {\n const nodes = Array.from(element.childNodes)\n while (nodes.length && isBlank(nodes[0]!)) nodes.shift()\n const first = nodes[0]\n if (first?.nodeType === 1 && (first as Element).tagName === 'P')\n return { content: Array.from(first.childNodes), children: nodes.slice(1) }\n const content: Node[] = []\n while (nodes.length && !isBlockElement(nodes[0]!)) content.push(nodes.shift()!)\n return { content, children: nodes }\n}\n\nconst BLOCK_TAGS = new Set([\n 'ADDRESS',\n 'ARTICLE',\n 'ASIDE',\n 'BLOCKQUOTE',\n 'DETAILS',\n 'DIV',\n 'DL',\n 'FIGURE',\n 'FOOTER',\n 'H1',\n 'H2',\n 'H3',\n 'H4',\n 'H5',\n 'H6',\n 'HEADER',\n 'HR',\n 'OL',\n 'P',\n 'PRE',\n 'SECTION',\n 'TABLE',\n 'UL',\n])\n\nconst isBlank = (node: Node) => node.nodeType === 3 && !node.textContent?.trim()\n\nconst isBlockElement = (node: Node) =>\n node.nodeType === 1 && BLOCK_TAGS.has((node as Element).tagName)\n\n/** Run every extension's `prepareHTML` over the markup. */\nexport function prepareElement(root: HTMLElement, kit: ResolvedEditorExtensions) {\n for (const extension of kit.extensions) extension.prepareHTML?.(root)\n}\n\n/**\n * Something that reads HTML like the browser's `DOMParser`, e.g. one from a\n * DOM library such as happy-dom or linkedom. Only `parseFromString` is used,\n * and only the `body` of what it returns.\n */\nexport interface DOMParserLike {\n parseFromString(html: string, type: 'text/html'): { body: unknown }\n}\n\n/**\n * Read HTML as blocks, with the block types, inline nodes and marks of `kit`.\n * Uses the global `DOMParser` unless given `domParser`; `name` is the\n * function the error message tells to pass one to.\n */\nexport function parseHTML(\n html: string,\n kit: ResolvedEditorExtensions,\n domParser?: DOMParserLike,\n name = 'htmlToBlocks(html, extensions, { domParser })',\n): Block[] {\n const parser = domParser ?? (typeof DOMParser === 'undefined' ? null : new DOMParser())\n if (!parser)\n throw new Error(\n `[@dou-ui/editor] reading HTML needs a DOMParser, and there is none here: pass one from a DOM library such as happy-dom or linkedom, as ${name}`,\n )\n // a whole document: some libraries leave the body empty for a bare fragment\n const whole = /^\\s*<(!doctype|html)/i.test(html)\n ? html\n : `<!doctype html><html><head></head><body>${html}</body></html>`\n const doc = parser.parseFromString(whole, 'text/html') as unknown as Document\n prepareElement(doc.body, kit)\n const blocks = docToBlocks(PMDOMParser.fromSchema(kit.schema).parse(doc.body as unknown as Node))\n // read blocks are shared and read-only: copy the ones without an id\n const fill = (list: Block[]): Block[] =>\n list.map((block) => ({ ...block, id: block.id || createId(), children: fill(block.children) }))\n return fill(blocks)\n}\n\n/** Pasted HTML goes through the extensions' `prepareHTML` too. */\nexport function preparePastePlugin(kit: ResolvedEditorExtensions): Plugin {\n return new Plugin({\n key: new PluginKey('dou-editor-paste'),\n props: {\n transformPastedHTML(html) {\n if (!kit.extensions.some((extension) => extension.prepareHTML)) return html\n const doc = new DOMParser().parseFromString(html, 'text/html')\n prepareElement(doc.body, kit)\n return doc.body.innerHTML\n },\n },\n })\n}\n"],"mappings":";;;;;;;;;AAUA,SAAgB,aACd,KACA,MACA,SACA,WAAmB,CAAC,GACpB,OAA+B,CAAC,GACnB;CACb,MAAM,QAAQ,IAAI,cAAc,KAAK;CACrC,MAAM,QAAQ,UAAU;CACxB,MAAM,UAAU,IAAI,cAAc,KAAK;CACvC,QAAQ,QAAQ,cAAc;CAC9B,OAAO,OAAO,QAAQ,SAAS,IAAI;CACnC,QAAQ,OAAO,GAAG,OAAO;CACzB,MAAM,OAAO,OAAO;CACpB,IAAI,SAAS,MAAM,SAAS,KAAK,aAAa,KAAK,KAAK,aAAa,KAAK,CAAC,GAAG;EAC5E,MAAM,QAAQ,IAAI,cAAc,KAAK;EACrC,MAAM,YAAY;EAClB,MAAM,OAAO,GAAG,QAAQ;EACxB,MAAM,OAAO,KAAK;CACpB;CACA,OAAO;AACT;;;;;AAMA,SAAgB,eAAe,SAAyD;CACtF,MAAM,QAAQ,MAAM,KAAK,QAAQ,UAAU;CAC3C,OAAO,MAAM,UAAU,QAAQ,MAAM,EAAG,GAAG,MAAM,MAAM;CACvD,MAAM,QAAQ,MAAM;CACpB,IAAI,OAAO,aAAa,KAAM,MAAkB,YAAY,KAC1D,OAAO;EAAE,SAAS,MAAM,KAAK,MAAM,UAAU;EAAG,UAAU,MAAM,MAAM,CAAC;CAAE;CAC3E,MAAM,UAAkB,CAAC;CACzB,OAAO,MAAM,UAAU,CAAC,eAAe,MAAM,EAAG,GAAG,QAAQ,KAAK,MAAM,MAAM,CAAE;CAC9E,OAAO;EAAE;EAAS,UAAU;CAAM;AACpC;AAEA,IAAM,6BAAa,IAAI,IAAI;CACzB;CACA;CACA;CACA;CACA;CACA;CACA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
@@ -43,6 +43,11 @@ function firstLine(content) {
|
|
|
43
43
|
height
|
|
44
44
|
};
|
|
45
45
|
}
|
|
46
|
-
|
|
46
|
+
/** The right edge of the editor's text column: the surface less its padding (a reading width). */
|
|
47
|
+
function columnRight(surface) {
|
|
48
|
+
const padding = Number.parseFloat(getComputedStyle(surface).paddingRight) || 0;
|
|
49
|
+
return surface.getBoundingClientRect().right - padding;
|
|
50
|
+
}
|
|
51
|
+
export { blockElementOf, columnRight, contentAt, firstLine, scrollParent };
|
|
47
52
|
|
|
48
53
|
//# sourceMappingURL=dom.js.map
|
package/dist/dom.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"dom.js","names":[],"sources":["../src/dom.ts"],"sourcesContent":["import type { EditorView } from 'prosemirror-view'\n\n/**\n * The content element (paragraph, heading, …) at height `y` in viewport\n * coordinates: the last one whose top is above it. Contents follow each\n * other from top to bottom in document order, nested ones included, so\n * a binary search does.\n */\nexport function contentAt(view: EditorView, y: number): HTMLElement | null {\n const list = view.dom.querySelectorAll<HTMLElement>('.dou-editor__content')\n let low = 0\n let high = list.length - 1\n let found = -1\n while (low <= high) {\n const middle = (low + high) >> 1\n if (list[middle]!.getBoundingClientRect().top <= y) {\n found = middle\n low = middle + 1\n } else high = middle - 1\n }\n return list[Math.max(found, 0)] ?? null\n}\n\n/** The block element around a content element. */\nexport function blockElementOf(content: HTMLElement): HTMLElement | null {\n return content.closest<HTMLElement>('.dou-editor__block')\n}\n\n/** The nearest ancestor that scrolls vertically, or `null` for the page. */\nexport function scrollParent(element: HTMLElement): HTMLElement | null {\n for (let node = element.parentElement; node; node = node.parentElement) {\n const { overflowY } = getComputedStyle(node)\n if ((overflowY === 'auto' || overflowY === 'scroll') && node.scrollHeight > node.clientHeight)\n return node\n }\n return null\n}\n\n/** Where the first line of a content element sits: its top and height. */\nexport function firstLine(content: HTMLElement): { top: number; height: number } {\n const rect = content.getBoundingClientRect()\n const style = getComputedStyle(content)\n const lineHeight = Number.parseFloat(style.lineHeight)\n const padding = Number.parseFloat(style.paddingTop) || 0\n const height = Number.isFinite(lineHeight) ? Math.min(lineHeight, rect.height) : rect.height\n return { top: rect.top + (height < rect.height ? padding : 0), height }\n}\n"],"mappings":";;;;;;;AAQA,SAAgB,UAAU,MAAkB,GAA+B;CACzE,MAAM,OAAO,KAAK,IAAI,iBAA8B,sBAAsB;CAC1E,IAAI,MAAM;CACV,IAAI,OAAO,KAAK,SAAS;CACzB,IAAI,QAAQ;CACZ,OAAO,OAAO,MAAM;EAClB,MAAM,SAAU,MAAM,QAAS;EAC/B,IAAI,KAAK,OAAO,CAAE,sBAAsB,CAAC,CAAC,OAAO,GAAG;GAClD,QAAQ;GACR,MAAM,SAAS;EACjB,OAAO,OAAO,SAAS;CACzB;CACA,OAAO,KAAK,KAAK,IAAI,OAAO,CAAC,MAAM;AACrC;;AAGA,SAAgB,eAAe,SAA0C;CACvE,OAAO,QAAQ,QAAqB,oBAAoB;AAC1D;;AAGA,SAAgB,aAAa,SAA0C;CACrE,KAAK,IAAI,OAAO,QAAQ,eAAe,MAAM,OAAO,KAAK,eAAe;EACtE,MAAM,EAAE,cAAc,iBAAiB,IAAI;EAC3C,KAAK,cAAc,UAAU,cAAc,aAAa,KAAK,eAAe,KAAK,cAC/E,OAAO;CACX;CACA,OAAO;AACT;;AAGA,SAAgB,UAAU,SAAuD;CAC/E,MAAM,OAAO,QAAQ,sBAAsB;CAC3C,MAAM,QAAQ,iBAAiB,OAAO;CACtC,MAAM,aAAa,OAAO,WAAW,MAAM,UAAU;CACrD,MAAM,UAAU,OAAO,WAAW,MAAM,UAAU,KAAK;CACvD,MAAM,SAAS,OAAO,SAAS,UAAU,IAAI,KAAK,IAAI,YAAY,KAAK,MAAM,IAAI,KAAK;CACtF,OAAO;EAAE,KAAK,KAAK,OAAO,SAAS,KAAK,SAAS,UAAU;EAAI;CAAO;AACxE"}
|
|
1
|
+
{"version":3,"file":"dom.js","names":[],"sources":["../src/dom.ts"],"sourcesContent":["import type { EditorView } from 'prosemirror-view'\n\n/**\n * The content element (paragraph, heading, …) at height `y` in viewport\n * coordinates: the last one whose top is above it. Contents follow each\n * other from top to bottom in document order, nested ones included, so\n * a binary search does.\n */\nexport function contentAt(view: EditorView, y: number): HTMLElement | null {\n const list = view.dom.querySelectorAll<HTMLElement>('.dou-editor__content')\n let low = 0\n let high = list.length - 1\n let found = -1\n while (low <= high) {\n const middle = (low + high) >> 1\n if (list[middle]!.getBoundingClientRect().top <= y) {\n found = middle\n low = middle + 1\n } else high = middle - 1\n }\n return list[Math.max(found, 0)] ?? null\n}\n\n/** The block element around a content element. */\nexport function blockElementOf(content: HTMLElement): HTMLElement | null {\n return content.closest<HTMLElement>('.dou-editor__block')\n}\n\n/** The nearest ancestor that scrolls vertically, or `null` for the page. */\nexport function scrollParent(element: HTMLElement): HTMLElement | null {\n for (let node = element.parentElement; node; node = node.parentElement) {\n const { overflowY } = getComputedStyle(node)\n if ((overflowY === 'auto' || overflowY === 'scroll') && node.scrollHeight > node.clientHeight)\n return node\n }\n return null\n}\n\n/** Where the first line of a content element sits: its top and height. */\nexport function firstLine(content: HTMLElement): { top: number; height: number } {\n const rect = content.getBoundingClientRect()\n const style = getComputedStyle(content)\n const lineHeight = Number.parseFloat(style.lineHeight)\n const padding = Number.parseFloat(style.paddingTop) || 0\n const height = Number.isFinite(lineHeight) ? Math.min(lineHeight, rect.height) : rect.height\n return { top: rect.top + (height < rect.height ? padding : 0), height }\n}\n\n/** The right edge of the editor's text column: the surface less its padding (a reading width). */\nexport function columnRight(surface: HTMLElement): number {\n const padding = Number.parseFloat(getComputedStyle(surface).paddingRight) || 0\n return surface.getBoundingClientRect().right - padding\n}\n"],"mappings":";;;;;;;AAQA,SAAgB,UAAU,MAAkB,GAA+B;CACzE,MAAM,OAAO,KAAK,IAAI,iBAA8B,sBAAsB;CAC1E,IAAI,MAAM;CACV,IAAI,OAAO,KAAK,SAAS;CACzB,IAAI,QAAQ;CACZ,OAAO,OAAO,MAAM;EAClB,MAAM,SAAU,MAAM,QAAS;EAC/B,IAAI,KAAK,OAAO,CAAE,sBAAsB,CAAC,CAAC,OAAO,GAAG;GAClD,QAAQ;GACR,MAAM,SAAS;EACjB,OAAO,OAAO,SAAS;CACzB;CACA,OAAO,KAAK,KAAK,IAAI,OAAO,CAAC,MAAM;AACrC;;AAGA,SAAgB,eAAe,SAA0C;CACvE,OAAO,QAAQ,QAAqB,oBAAoB;AAC1D;;AAGA,SAAgB,aAAa,SAA0C;CACrE,KAAK,IAAI,OAAO,QAAQ,eAAe,MAAM,OAAO,KAAK,eAAe;EACtE,MAAM,EAAE,cAAc,iBAAiB,IAAI;EAC3C,KAAK,cAAc,UAAU,cAAc,aAAa,KAAK,eAAe,KAAK,cAC/E,OAAO;CACX;CACA,OAAO;AACT;;AAGA,SAAgB,UAAU,SAAuD;CAC/E,MAAM,OAAO,QAAQ,sBAAsB;CAC3C,MAAM,QAAQ,iBAAiB,OAAO;CACtC,MAAM,aAAa,OAAO,WAAW,MAAM,UAAU;CACrD,MAAM,UAAU,OAAO,WAAW,MAAM,UAAU,KAAK;CACvD,MAAM,SAAS,OAAO,SAAS,UAAU,IAAI,KAAK,IAAI,YAAY,KAAK,MAAM,IAAI,KAAK;CACtF,OAAO;EAAE,KAAK,KAAK,OAAO,SAAS,KAAK,SAAS,UAAU;EAAI;CAAO;AACxE;;AAGA,SAAgB,YAAY,SAA8B;CACxD,MAAM,UAAU,OAAO,WAAW,iBAAiB,OAAO,CAAC,CAAC,YAAY,KAAK;CAC7E,OAAO,QAAQ,sBAAsB,CAAC,CAAC,QAAQ;AACjD"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"align-menu.js","names":["_sfc_main"],"sources":["../../../src/extensions/align/align-menu.vue"],"sourcesContent":["<script setup lang=\"ts\">\nimport { TextAlignCenterIcon, TextAlignLeftIcon, TextAlignRightIcon } from '@dou-ui/icons'\nimport { DouButton, DouDropdown, DouDropdownItem, DouDropdownRadioGroup, DouTooltip } from 'dou-ui'\nimport { computed } from 'vue'\nimport type { BlockAlign } from '../../core/align'\nimport { useEditor, useToolbarMenu } from '../../editor'\nimport { currentAlign, setAlign } from './commands'\n\nconst { view, state, messages } = useEditor()\n\nconst icons = { left: TextAlignLeftIcon, center: TextAlignCenterIcon, right: TextAlignRightIcon }\nconst shortcuts = { left: 'mod+shift+l', center: 'mod+shift+e', right: 'mod+shift+r' }\nconst aligns = ['left', 'center', 'right'] as const\n\nconst align = computed(() => (state.value ? currentAlign(state.value) : undefined))\n\nfunction choose(value: unknown) {\n const current = view.value\n if (!current) return\n // left is the reading direction: store nothing\n const next = value === 'left' ? null : (value as BlockAlign)\n setAlign(next)(current.state, current.dispatch)\n current.focus()\n}\n\nconst open = useToolbarMenu()\n</script>\n\n<template>\n <DouTooltip
|
|
1
|
+
{"version":3,"file":"align-menu.js","names":["_sfc_main"],"sources":["../../../src/extensions/align/align-menu.vue"],"sourcesContent":["<script setup lang=\"ts\">\nimport { TextAlignCenterIcon, TextAlignLeftIcon, TextAlignRightIcon } from '@dou-ui/icons'\nimport { DouButton, DouDropdown, DouDropdownItem, DouDropdownRadioGroup, DouTooltip } from 'dou-ui'\nimport { computed } from 'vue'\nimport type { BlockAlign } from '../../core/align'\nimport { useEditor, useToolbarMenu } from '../../editor'\nimport { currentAlign, setAlign } from './commands'\n\nconst { view, state, messages } = useEditor()\n\nconst icons = { left: TextAlignLeftIcon, center: TextAlignCenterIcon, right: TextAlignRightIcon }\nconst shortcuts = { left: 'mod+shift+l', center: 'mod+shift+e', right: 'mod+shift+r' }\nconst aligns = ['left', 'center', 'right'] as const\n\nconst align = computed(() => (state.value ? currentAlign(state.value) : undefined))\n\nfunction choose(value: unknown) {\n const current = view.value\n if (!current) return\n // left is the reading direction: store nothing\n const next = value === 'left' ? null : (value as BlockAlign)\n setAlign(next)(current.state, current.dispatch)\n current.focus()\n}\n\nconst open = useToolbarMenu()\n</script>\n\n<template>\n <DouTooltip v-if=\"align !== undefined\" :content=\"messages.align.label\" placement=\"bottom\">\n <DouDropdown v-model:open=\"open\" placement=\"bottom-start\" class=\"dou-editor-menu\">\n <DouButton size=\"sm\" variant=\"ghost\" :aria-label=\"messages.align.label\">\n <component :is=\"icons[align === 'mixed' || !align ? 'left' : align]\" />\n </DouButton>\n <template #menu>\n <DouDropdownRadioGroup\n :model-value=\"align === 'mixed' ? undefined : (align ?? 'left')\"\n @update:model-value=\"choose\"\n >\n <DouDropdownItem\n v-for=\"name in aligns\"\n :key=\"name\"\n :value=\"name\"\n :shortcut=\"shortcuts[name]\"\n >\n <template #prefix><component :is=\"icons[name]\" /></template>\n {{ messages.align[name] }}\n </DouDropdownItem>\n </DouDropdownRadioGroup>\n </template>\n </DouDropdown>\n </DouTooltip>\n</template>\n"],"mappings":""}
|
|
@@ -1,10 +1,9 @@
|
|
|
1
1
|
import { useEditor, useToolbarMenu } from "../../editor.js";
|
|
2
2
|
import { currentAlign, setAlign } from "./commands.js";
|
|
3
3
|
import { DouButton, DouDropdown, DouDropdownItem, DouDropdownRadioGroup, DouTooltip } from "dou-ui";
|
|
4
|
-
import { Fragment, computed, createBlock, createCommentVNode, createElementBlock,
|
|
4
|
+
import { Fragment, computed, createBlock, createCommentVNode, createElementBlock, createTextVNode, createVNode, defineComponent, isRef, openBlock, renderList, resolveDynamicComponent, toDisplayString, unref, withCtx } from "vue";
|
|
5
5
|
import { TextAlignCenterIcon, TextAlignLeftIcon, TextAlignRightIcon } from "@dou-ui/icons";
|
|
6
6
|
// src/extensions/align/align-menu.vue?vue&type=script&setup=true&lang.ts
|
|
7
|
-
var _hoisted_1 = { class: "dou-editor-bubble__trigger" };
|
|
8
7
|
var align_menu_vue_vue_type_script_setup_true_lang_default = /*@__PURE__*/ defineComponent({
|
|
9
8
|
__name: "align-menu",
|
|
10
9
|
setup(__props) {
|
|
@@ -36,10 +35,9 @@ var align_menu_vue_vue_type_script_setup_true_lang_default = /*@__PURE__*/ defin
|
|
|
36
35
|
return align.value !== void 0 ? (openBlock(), createBlock(unref(DouTooltip), {
|
|
37
36
|
key: 0,
|
|
38
37
|
content: unref(messages).align.label,
|
|
39
|
-
disabled: unref(open),
|
|
40
38
|
placement: "bottom"
|
|
41
39
|
}, {
|
|
42
|
-
default: withCtx(() => [
|
|
40
|
+
default: withCtx(() => [createVNode(unref(DouDropdown), {
|
|
43
41
|
open: unref(open),
|
|
44
42
|
"onUpdate:open": _cache[0] || (_cache[0] = ($event) => isRef(open) ? open.value = $event : null),
|
|
45
43
|
placement: "bottom-start",
|
|
@@ -71,9 +69,9 @@ var align_menu_vue_vue_type_script_setup_true_lang_default = /*@__PURE__*/ defin
|
|
|
71
69
|
_: 1
|
|
72
70
|
}, 8, ["aria-label"])]),
|
|
73
71
|
_: 1
|
|
74
|
-
}, 8, ["open"])])
|
|
72
|
+
}, 8, ["open"])]),
|
|
75
73
|
_: 1
|
|
76
|
-
}, 8, ["content"
|
|
74
|
+
}, 8, ["content"])) : createCommentVNode("", true);
|
|
77
75
|
};
|
|
78
76
|
}
|
|
79
77
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"align-menu.vue_vue_type_script_setup_true_lang.js","names":["_openBlock","_createBlock","_unref","_withCtx","
|
|
1
|
+
{"version":3,"file":"align-menu.vue_vue_type_script_setup_true_lang.js","names":["_openBlock","_createBlock","_unref","_withCtx","_createVNode","_isRef","_createElementBlock","_Fragment","_renderList","_resolveDynamicComponent","_createTextVNode","_toDisplayString","_createCommentVNode"],"sources":["../../../src/extensions/align/align-menu.vue"],"sourcesContent":["<script setup lang=\"ts\">\nimport { TextAlignCenterIcon, TextAlignLeftIcon, TextAlignRightIcon } from '@dou-ui/icons'\nimport { DouButton, DouDropdown, DouDropdownItem, DouDropdownRadioGroup, DouTooltip } from 'dou-ui'\nimport { computed } from 'vue'\nimport type { BlockAlign } from '../../core/align'\nimport { useEditor, useToolbarMenu } from '../../editor'\nimport { currentAlign, setAlign } from './commands'\n\nconst { view, state, messages } = useEditor()\n\nconst icons = { left: TextAlignLeftIcon, center: TextAlignCenterIcon, right: TextAlignRightIcon }\nconst shortcuts = { left: 'mod+shift+l', center: 'mod+shift+e', right: 'mod+shift+r' }\nconst aligns = ['left', 'center', 'right'] as const\n\nconst align = computed(() => (state.value ? currentAlign(state.value) : undefined))\n\nfunction choose(value: unknown) {\n const current = view.value\n if (!current) return\n // left is the reading direction: store nothing\n const next = value === 'left' ? null : (value as BlockAlign)\n setAlign(next)(current.state, current.dispatch)\n current.focus()\n}\n\nconst open = useToolbarMenu()\n</script>\n\n<template>\n <DouTooltip v-if=\"align !== undefined\" :content=\"messages.align.label\" placement=\"bottom\">\n <DouDropdown v-model:open=\"open\" placement=\"bottom-start\" class=\"dou-editor-menu\">\n <DouButton size=\"sm\" variant=\"ghost\" :aria-label=\"messages.align.label\">\n <component :is=\"icons[align === 'mixed' || !align ? 'left' : align]\" />\n </DouButton>\n <template #menu>\n <DouDropdownRadioGroup\n :model-value=\"align === 'mixed' ? undefined : (align ?? 'left')\"\n @update:model-value=\"choose\"\n >\n <DouDropdownItem\n v-for=\"name in aligns\"\n :key=\"name\"\n :value=\"name\"\n :shortcut=\"shortcuts[name]\"\n >\n <template #prefix><component :is=\"icons[name]\" /></template>\n {{ messages.align[name] }}\n </DouDropdownItem>\n </DouDropdownRadioGroup>\n </template>\n </DouDropdown>\n </DouTooltip>\n</template>\n"],"mappings":";;;;;;;;;EAQA,MAAM,EAAE,MAAM,OAAO,aAAa,UAAU;EAE5C,MAAM,QAAQ;GAAE,MAAM;GAAmB,QAAQ;GAAqB,OAAO;EAAmB;EAChG,MAAM,YAAY;GAAE,MAAM;GAAe,QAAQ;GAAe,OAAO;EAAc;EACrF,MAAM,SAAS;GAAC;GAAQ;GAAU;EAAO;EAEzC,MAAM,QAAQ,eAAgB,MAAM,QAAQ,aAAa,MAAM,KAAK,IAAI,KAAA,CAAU;EAElF,SAAS,OAAO,OAAgB;GAC9B,MAAM,UAAU,KAAK;GACrB,IAAI,CAA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{
|
|
|
28
28
|
/** Take the `[!TIP]` off the start of a quote's text; returns the tone, or null without one. */
|
|
29
29
|
function takeMarker(content) {
|
|
30
30
|
const first = content.find((node) => node.textContent?.trim());
|
|
31
|
-
if (
|
|
32
|
-
const
|
|
31
|
+
if (first?.nodeType !== 3) return null;
|
|
32
|
+
const text = first;
|
|
33
|
+
const match = MARKER.exec(text.data);
|
|
33
34
|
if (!match) return null;
|
|
34
|
-
|
|
35
|
+
text.data = text.data.slice(match[0].length);
|
|
35
36
|
const next = content[content.indexOf(first) + 1];
|
|
36
|
-
if (!
|
|
37
|
+
if (!text.data.trim() && next?.nodeType === 1 && next.tagName === "BR") next.remove();
|
|
37
38
|
return ALERTS[match[1].toUpperCase()];
|
|
38
39
|
}
|
|
39
40
|
/** `<aside data-callout>` from `blocksToHTML`, and quotes that start with `[!TIP]` as Markdown writes them. */
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"html.js","names":[],"sources":["../../../src/extensions/callout/html.ts"],"sourcesContent":["import { indentLines, type BlockOutput } from '../../core/output'\nimport { blockElement, splitContainer } from '../../core/prepare'\nimport { calloutTones } from './tones'\n\n/** The alert labels of GitHub's Markdown, and the tone each one reads as. */\nconst ALERTS: Record<string, string> = {\n NOTE: 'info',\n IMPORTANT: 'info',\n TIP: 'tip',\n WARNING: 'warning',\n CAUTION: 'danger',\n}\nconst LABELS: Record<string, string> = {\n info: 'NOTE',\n tip: 'TIP',\n warning: 'WARNING',\n danger: 'CAUTION',\n}\nconst MARKER = /^\\s*\\[!(NOTE|IMPORTANT|TIP|WARNING|CAUTION)\\][ \\t]*\\n?/i\n\nconst toneOf = (tone: unknown) => (String(tone) in calloutTones ? String(tone) : 'info')\n\nexport const calloutOutput: BlockOutput = {\n html: (block, { content, children }) =>\n `<aside data-callout=\"${toneOf(block.props.tone)}\"><p>${content}</p>${children}</aside>`,\n // GitHub's alert syntax: a quote that starts with `[!TIP]`\n markdown: (block, { content, children }) => {\n const head = [`[!${LABELS[toneOf(block.props.tone)]}]`, content].filter(Boolean).join('\\n')\n return indentLines(children ? `${head}\\n\\n${children}` : head, '> ', '> ')\n },\n}\n\n/** Take the `[!TIP]` off the start of a quote's text; returns the tone, or null without one. */\nfunction takeMarker(content: Node[]): string | null {\n const first = content.find((node) => node.textContent?.trim())\n if (
|
|
1
|
+
{"version":3,"file":"html.js","names":[],"sources":["../../../src/extensions/callout/html.ts"],"sourcesContent":["import { indentLines, type BlockOutput } from '../../core/output'\nimport { blockElement, splitContainer } from '../../core/prepare'\nimport { calloutTones } from './tones'\n\n/** The alert labels of GitHub's Markdown, and the tone each one reads as. */\nconst ALERTS: Record<string, string> = {\n NOTE: 'info',\n IMPORTANT: 'info',\n TIP: 'tip',\n WARNING: 'warning',\n CAUTION: 'danger',\n}\nconst LABELS: Record<string, string> = {\n info: 'NOTE',\n tip: 'TIP',\n warning: 'WARNING',\n danger: 'CAUTION',\n}\nconst MARKER = /^\\s*\\[!(NOTE|IMPORTANT|TIP|WARNING|CAUTION)\\][ \\t]*\\n?/i\n\nconst toneOf = (tone: unknown) => (String(tone) in calloutTones ? String(tone) : 'info')\n\nexport const calloutOutput: BlockOutput = {\n html: (block, { content, children }) =>\n `<aside data-callout=\"${toneOf(block.props.tone)}\"><p>${content}</p>${children}</aside>`,\n // GitHub's alert syntax: a quote that starts with `[!TIP]`\n markdown: (block, { content, children }) => {\n const head = [`[!${LABELS[toneOf(block.props.tone)]}]`, content].filter(Boolean).join('\\n')\n return indentLines(children ? `${head}\\n\\n${children}` : head, '> ', '> ')\n },\n}\n\n/** Take the `[!TIP]` off the start of a quote's text; returns the tone, or null without one. */\nfunction takeMarker(content: Node[]): string | null {\n const first = content.find((node) => node.textContent?.trim())\n // by node type, not `instanceof`: the DOM may come from a library, without globals\n if (first?.nodeType !== 3) return null\n const text = first as Text\n const match = MARKER.exec(text.data)\n if (!match) return null\n text.data = text.data.slice(match[0].length)\n // the text after the marker starts on the next line\n const index = content.indexOf(first)\n const next = content[index + 1]\n if (!text.data.trim() && next?.nodeType === 1 && (next as Element).tagName === 'BR')\n (next as Element).remove()\n return ALERTS[match[1]!.toUpperCase()]!\n}\n\n/** `<aside data-callout>` from `blocksToHTML`, and quotes that start with `[!TIP]` as Markdown writes them. */\nexport function prepareCallouts(root: HTMLElement) {\n for (const element of Array.from(root.querySelectorAll('aside[data-callout]'))) {\n const { content, children } = splitContainer(element)\n const tone = toneOf((element as HTMLElement).dataset.callout)\n element.replaceWith(blockElement(element.ownerDocument, 'callout', content, children, { tone }))\n }\n for (const element of Array.from(root.querySelectorAll('blockquote'))) {\n const { content, children } = splitContainer(element)\n const tone = takeMarker(content)\n if (tone)\n element.replaceWith(\n blockElement(element.ownerDocument, 'callout', content, children, { tone }),\n )\n }\n // a quote another extension already turned into a block\n for (const element of Array.from(\n root.querySelectorAll<HTMLElement>('div[data-content-type=\"quote\"]'),\n )) {\n const tone = takeMarker(Array.from(element.childNodes))\n if (tone) {\n element.dataset.contentType = 'callout'\n element.dataset.tone = tone\n }\n }\n}\n"],"mappings":";;;;;AAKA,IAAM,SAAiC;CACrC,MAAM;CACN,WAAW;CACX,KAAK;CACL,SAAS;CACT,SAAS;AACX;AACA,IAAM,SAAiC;CACrC,MAAM;CACN,KAAK;CACL,SAAS;CACT,QAAQ;AACV;AACA,IAAM,SAAS;AAEf,IAAM,UAAU,SAAmB,OAAO,IAAI,KAAK,eAAe,OAAO,IAAI,IAAI;AAEjF,IAAa,gBAA6B;CACxC,OAAO,OAAO,EAAE,SAAS,eACvB,wBAAwB,OAAO,MAAM,MAAM,IAAI,EAAE,OAAO,QAAQ,MAAM,SAAS;CAEjF,WAAW,OAAO,EAAE,SAAS,eAAe;EAC1C,MAAM,OAAO,CAAC,KAAK,OAAO,OAAO,MAAM,MAAM,IAAI,GAAG,IAAI,OAAO,CAAC,CAAC,OAAO,OAAO,CAAC,CAAC,KAAK,IAAI;EAC1F,OAAO,YAAY,WAAW,GAAG,KAAK,MAAM,aAAa,MAAM,MAAM,I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+1 @@
|
|
|
1
|
-
{"version":3,"file":"color-menu.js","names":["_sfc_main"],"sources":["../../../src/extensions/colors/color-menu.vue"],"sourcesContent":["<script setup lang=\"ts\">\nimport { CheckIcon } from '@dou-ui/icons'\nimport { DouButton, DouDropdown, DouDropdownItem, DouDropdownSub, DouTooltip } from 'dou-ui'\nimport { computed } from 'vue'\nimport { useEditor, useToolbarMenu } from '../../editor'\nimport { setHighlight, setTextColor, textColors, type TextColor } from './palette'\n\nconst { view, state, messages } = useEditor()\n\n/** The color the whole selection has, `null` for none, `'mixed'` for several. */\nfunction current(name: string): string | null {\n const now = state.value\n const type = now?.schema.marks[name]\n if (!now || !type) return null\n const { from, to } = now.selection\n let value: string | null | undefined\n now.doc.nodesBetween(from, to, (node) => {\n if (!node.isText || value === 'mixed') return\n const found = (type.isInSet(node.marks)?.attrs.value as string | undefined) ?? null\n value = value === undefined || value === found ? found : 'mixed'\n })\n return value ?? null\n}\n\n/** The swatch shows one color; several show as the default. */\nconst shown = (value: string | null) => (value && value !== 'mixed' ? value : undefined)\n\nconst color = computed(() => current('textColor'))\nconst highlight = computed(() => current('highlight'))\n\nfunction apply(kind: 'text' | 'background', value: TextColor | null) {\n const target = view.value\n if (!target) return\n ;(kind === 'text' ? setTextColor : setHighlight)(value)(target.state, target.dispatch)\n target.focus()\n}\n\nconst open = useToolbarMenu()\n</script>\n\n<template>\n <DouTooltip :content=\"messages.colors.label\"
|
|
1
|
+
{"version":3,"file":"color-menu.js","names":["_sfc_main"],"sources":["../../../src/extensions/colors/color-menu.vue"],"sourcesContent":["<script setup lang=\"ts\">\nimport { CheckIcon } from '@dou-ui/icons'\nimport { DouButton, DouDropdown, DouDropdownItem, DouDropdownSub, DouTooltip } from 'dou-ui'\nimport { computed } from 'vue'\nimport { useEditor, useToolbarMenu } from '../../editor'\nimport { setHighlight, setTextColor, textColors, type TextColor } from './palette'\n\nconst { view, state, messages } = useEditor()\n\n/** The color the whole selection has, `null` for none, `'mixed'` for several. */\nfunction current(name: string): string | null {\n const now = state.value\n const type = now?.schema.marks[name]\n if (!now || !type) return null\n const { from, to } = now.selection\n let value: string | null | undefined\n now.doc.nodesBetween(from, to, (node) => {\n if (!node.isText || value === 'mixed') return\n const found = (type.isInSet(node.marks)?.attrs.value as string | undefined) ?? null\n value = value === undefined || value === found ? found : 'mixed'\n })\n return value ?? null\n}\n\n/** The swatch shows one color; several show as the default. */\nconst shown = (value: string | null) => (value && value !== 'mixed' ? value : undefined)\n\nconst color = computed(() => current('textColor'))\nconst highlight = computed(() => current('highlight'))\n\nfunction apply(kind: 'text' | 'background', value: TextColor | null) {\n const target = view.value\n if (!target) return\n ;(kind === 'text' ? setTextColor : setHighlight)(value)(target.state, target.dispatch)\n target.focus()\n}\n\nconst open = useToolbarMenu()\n</script>\n\n<template>\n <DouTooltip :content=\"messages.colors.label\" placement=\"bottom\">\n <DouDropdown v-model:open=\"open\" placement=\"bottom-start\" class=\"dou-editor-menu\">\n <DouButton\n size=\"sm\"\n variant=\"ghost\"\n class=\"dou-editor-colors__button\"\n :aria-label=\"messages.colors.label\"\n >\n <template #leading>\n <span\n class=\"dou-editor-colors__swatch\"\n :data-color=\"shown(color)\"\n :data-highlight=\"shown(highlight)\"\n aria-hidden=\"true\"\n ><span class=\"dou-editor-colors__letter\">A</span></span\n >\n </template>\n </DouButton>\n <template #menu>\n <DouDropdownSub\n v-for=\"kind in ['text', 'background'] as const\"\n :key=\"kind\"\n :title=\"kind === 'text' ? messages.colors.text : messages.colors.background\"\n >\n <DouDropdownItem @click=\"apply(kind, null)\">\n <template #prefix>\n <span class=\"dou-editor-colors__swatch\" aria-hidden=\"true\"\n ><span class=\"dou-editor-colors__letter\">A</span></span\n >\n </template>\n {{ messages.colors.none }}\n <template v-if=\"!(kind === 'text' ? color : highlight)\" #suffix><CheckIcon /></template>\n </DouDropdownItem>\n <DouDropdownItem v-for=\"name in textColors\" :key=\"name\" @click=\"apply(kind, name)\">\n <template #prefix>\n <span\n class=\"dou-editor-colors__swatch\"\n :data-color=\"kind === 'text' ? name : undefined\"\n :data-highlight=\"kind === 'background' ? name : undefined\"\n aria-hidden=\"true\"\n ><span class=\"dou-editor-colors__letter\">A</span></span\n >\n </template>\n {{ messages.colors.names[name] }}\n <template v-if=\"(kind === 'text' ? color : highlight) === name\" #suffix>\n <CheckIcon />\n </template>\n </DouDropdownItem>\n </DouDropdownSub>\n </template>\n </DouDropdown>\n </DouTooltip>\n</template>\n"],"mappings":""}
|
|
@@ -5,9 +5,8 @@ import { DouButton, DouDropdown, DouDropdownItem, DouDropdownSub, DouTooltip } f
|
|
|
5
5
|
import { Fragment, computed, createBlock, createElementBlock, createElementVNode, createSlots, createTextVNode, createVNode, defineComponent, isRef, openBlock, renderList, toDisplayString, unref, withCtx } from "vue";
|
|
6
6
|
import { CheckIcon } from "@dou-ui/icons";
|
|
7
7
|
// src/extensions/colors/color-menu.vue?vue&type=script&setup=true&lang.ts
|
|
8
|
-
var _hoisted_1 =
|
|
8
|
+
var _hoisted_1 = ["data-color", "data-highlight"];
|
|
9
9
|
var _hoisted_2 = ["data-color", "data-highlight"];
|
|
10
|
-
var _hoisted_3 = ["data-color", "data-highlight"];
|
|
11
10
|
var color_menu_vue_vue_type_script_setup_true_lang_default = /*@__PURE__*/ defineComponent({
|
|
12
11
|
__name: "color-menu",
|
|
13
12
|
setup(__props) {
|
|
@@ -40,10 +39,9 @@ var color_menu_vue_vue_type_script_setup_true_lang_default = /*@__PURE__*/ defin
|
|
|
40
39
|
return (_ctx, _cache) => {
|
|
41
40
|
return openBlock(), createBlock(unref(DouTooltip), {
|
|
42
41
|
content: unref(messages).colors.label,
|
|
43
|
-
disabled: unref(open),
|
|
44
42
|
placement: "bottom"
|
|
45
43
|
}, {
|
|
46
|
-
default: withCtx(() => [
|
|
44
|
+
default: withCtx(() => [createVNode(unref(DouDropdown), {
|
|
47
45
|
open: unref(open),
|
|
48
46
|
"onUpdate:open": _cache[0] || (_cache[0] = ($event) => isRef(open) ? open.value = $event : null),
|
|
49
47
|
placement: "bottom-start",
|
|
@@ -75,7 +73,7 @@ var color_menu_vue_vue_type_script_setup_true_lang_default = /*@__PURE__*/ defin
|
|
|
75
73
|
"data-color": kind === "text" ? name : void 0,
|
|
76
74
|
"data-highlight": kind === "background" ? name : void 0,
|
|
77
75
|
"aria-hidden": "true"
|
|
78
|
-
}, [..._cache[3] || (_cache[3] = [createElementVNode("span", { class: "dou-editor-colors__letter" }, "A", -1)])], 8,
|
|
76
|
+
}, [..._cache[3] || (_cache[3] = [createElementVNode("span", { class: "dou-editor-colors__letter" }, "A", -1)])], 8, _hoisted_2)]),
|
|
79
77
|
default: withCtx(() => [createTextVNode(" " + toDisplayString(unref(messages).colors.names[name]) + " ", 1)]),
|
|
80
78
|
_: 2
|
|
81
79
|
}, [(kind === "text" ? color.value : highlight.value) === name ? {
|
|
@@ -98,13 +96,13 @@ var color_menu_vue_vue_type_script_setup_true_lang_default = /*@__PURE__*/ defin
|
|
|
98
96
|
"data-color": shown(color.value),
|
|
99
97
|
"data-highlight": shown(highlight.value),
|
|
100
98
|
"aria-hidden": "true"
|
|
101
|
-
}, [..._cache[1] || (_cache[1] = [createElementVNode("span", { class: "dou-editor-colors__letter" }, "A", -1)])], 8,
|
|
99
|
+
}, [..._cache[1] || (_cache[1] = [createElementVNode("span", { class: "dou-editor-colors__letter" }, "A", -1)])], 8, _hoisted_1)]),
|
|
102
100
|
_: 1
|
|
103
101
|
}, 8, ["aria-label"])]),
|
|
104
102
|
_: 1
|
|
105
|
-
}, 8, ["open"])])
|
|
103
|
+
}, 8, ["open"])]),
|
|
106
104
|
_: 1
|
|
107
|
-
}, 8, ["content"
|
|
105
|
+
}, 8, ["content"]);
|
|
108
106
|
};
|
|
109
107
|
}
|
|
110
108
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"color-menu.vue_vue_type_script_setup_true_lang.js","names":["_openBlock","_createBlock","_unref","_withCtx","
|
|
1
|
+
{"version":3,"file":"color-menu.vue_vue_type_script_setup_true_lang.js","names":["_openBlock","_createBlock","_unref","_withCtx","_createVNode","_isRef","_createElementBlock","_Fragment","_renderList","_createSlots","_createElementVNode","_createTextVNode","_toDisplayString"],"sources":["../../../src/extensions/colors/color-menu.vue"],"sourcesContent":["<script setup lang=\"ts\">\nimport { CheckIcon } from '@dou-ui/icons'\nimport { DouButton, DouDropdown, DouDropdownItem, DouDropdownSub, DouTooltip } from 'dou-ui'\nimport { computed } from 'vue'\nimport { useEditor, useToolbarMenu } from '../../editor'\nimport { setHighlight, setTextColor, textColors, type TextColor } from './palette'\n\nconst { view, state, messages } = useEditor()\n\n/** The color the whole selection has, `null` for none, `'mixed'` for several. */\nfunction current(name: string): string | null {\n const now = state.value\n const type = now?.schema.marks[name]\n if (!now || !type) return null\n const { from, to } = now.selection\n let value: string | null | undefined\n now.doc.nodesBetween(from, to, (node) => {\n if (!node.isText || value === 'mixed') return\n const found = (type.isInSet(node.marks)?.attrs.value as string | undefined) ?? null\n value = value === undefined || value === found ? found : 'mixed'\n })\n return value ?? null\n}\n\n/** The swatch shows one color; several show as the default. */\nconst shown = (value: string | null) => (value && value !== 'mixed' ? value : undefined)\n\nconst color = computed(() => current('textColor'))\nconst highlight = computed(() => current('highlight'))\n\nfunction apply(kind: 'text' | 'background', value: TextColor | null) {\n const target = view.value\n if (!target) return\n ;(kind === 'text' ? setTextColor : setHighlight)(value)(target.state, target.dispatch)\n target.focus()\n}\n\nconst open = useToolbarMenu()\n</script>\n\n<template>\n <DouTooltip :content=\"messages.colors.label\" placement=\"bottom\">\n <DouDropdown v-model:open=\"open\" placement=\"bottom-start\" class=\"dou-editor-menu\">\n <DouButton\n size=\"sm\"\n variant=\"ghost\"\n class=\"dou-editor-colors__button\"\n :aria-label=\"messages.colors.label\"\n >\n <template #leading>\n <span\n class=\"dou-editor-colors__swatch\"\n :data-color=\"shown(color)\"\n :data-highlight=\"shown(highlight)\"\n aria-hidden=\"true\"\n ><span class=\"dou-editor-colors__letter\">A</span></span\n >\n </template>\n </DouButton>\n <template #menu>\n <DouDropdownSub\n v-for=\"kind in ['text', 'background'] as const\"\n :key=\"kind\"\n :title=\"kind === 'text' ? messages.colors.text : messages.colors.background\"\n >\n <DouDropdownItem @click=\"apply(kind, null)\">\n <template #prefix>\n <span class=\"dou-editor-colors__swatch\" aria-hidden=\"true\"\n ><span class=\"dou-editor-colors__letter\">A</span></span\n >\n </template>\n {{ messages.colors.none }}\n <template v-if=\"!(kind === 'text' ? color : highlight)\" #suffix><CheckIcon /></template>\n </DouDropdownItem>\n <DouDropdownItem v-for=\"name in textColors\" :key=\"name\" @click=\"apply(kind, name)\">\n <template #prefix>\n <span\n class=\"dou-editor-colors__swatch\"\n :data-color=\"kind === 'text' ? name : undefined\"\n :data-highlight=\"kind === 'background' ? name : undefined\"\n aria-hidden=\"true\"\n ><span class=\"dou-editor-colors__letter\">A</span></span\n >\n </template>\n {{ messages.colors.names[name] }}\n <template v-if=\"(kind === 'text' ? color : highlight) === name\" #suffix>\n <CheckIcon />\n </template>\n </DouDropdownItem>\n </DouDropdownSub>\n </template>\n </DouDropdown>\n </DouTooltip>\n</template>\n"],"mappings":";;;;;;;;;;;;EAOA,MAAM,EAAE,MAAM,OAAO,aAAa,UAAU;;EAG5C,SAAS,QAAQ,MAA6B;GAC5C,MAAM,MAAM,MAAM;GAClB,MAAM,OAAO,KAAK,OAAO,MAAM;GAC/B,IAAI,CAAC,OAAO,CAAC,MAAM,OAAO;GAC1B,MAAM,EAAE,MAAM,OAAO,IAAI;GACzB,IAAI;GACJ,IAAI,IAAI,aAAa,MAAM,KAAK,SAAS;IACvC,IAAI,CAAC,KAAK,UAAU,UAAU,SAAS;IACvC,MAAM,QAAS,KAAK,QAAQ,KAAK,KAAK,CAAC,EAAE,MAAM,SAAgC;IAC/E,QAAQ,UAAU,KAAA,KAAa,UAAU,QAAQ,QAAQ;GAC3D,CAAC;GACD,OAAO,SAAS;EAClB;;EAGA,MAAM,SAAS,UAA0B,SAAS,UAAU,UAAU,Q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EAAA,SAAI,SAAc,MAAA,QAAQ,UAAA,S;QAAa,MAAA;QAAO,IAAAC,cAAa,CAAbC,YAAaF,MAAA,SAAA,CAAA,C;;O,mCAE/EF,UAAA,IAAA,GAAAM,mBAckBC,UAAA,MAAAC,WAdcN,MAAA,UAAA,IAAR,SAAI;QAA5B,OAAAF,UAAA,GAAAC,YAckBC,MAAA,eAAA,GAAA;SAd2B,KAAK;SAAO,UAAK,WAAE,MAAM,MAAM,IAAI;;SACnE,QAAMC,cAOd,CANDO,mBAMC,QAAA;UALC,OAAM;UACL,cAAY,SAAI,SAAc,OAAO,KAAA;UACrC,kBAAgB,SAAI,eAAoB,OAAO,KAAA;UAChD,eAAY;S,kCACXA,mBAAgD,QAAA,EAA1C,OAAM,4BAA2B,GAAC,KAAC,EAAA,C;SAEnC,SAAAP,cACX,CADWQ,gBAAA,MACXC,gBAAGV,MAAA,QAAA,CAAQ,CAAC,OAAO,MAAM,KAAI,IAAI,KACjC,CAAA,C;;Q,KAAiB,SAAI,SAAc,MAAA,QAAQ,UAAA,WAAe,O;SAAO,MAAA;SAC/D,IAAAC,cAAa,CAAbC,YAAaF,MAAA,SAAA,CAAA,C;;;;;;;KA3CrB,SAAAC,cAeY,CAfZC,YAeYF,MAAA,SAAA,GAAA;MAdV,MAAK;MACL,SAAQ;MACR,OAAM;MACL,cAAYA,MAAA,QAAA,CAAQ,CAAC,OAAO;;MAElB,SAAOC,cAOf,CANDO,mBAMC,QAAA;OALC,OAAM;OACL,cAAY,MAAM,MAAA,KAAK;OACvB,kBAAgB,MAAM,UAAA,KAAS;OAChC,eAAY;M,kCACXA,mBAAgD,QAAA,EAA1C,OAAM,4BAA2B,GAAC,KAAC,EAAA,C"}
|
|
@@ -42,7 +42,7 @@ function convertList(list) {
|
|
|
42
42
|
return blocks;
|
|
43
43
|
}
|
|
44
44
|
function firstText(item) {
|
|
45
|
-
const walker = item.ownerDocument.createTreeWalker(item,
|
|
45
|
+
const walker = item.ownerDocument.createTreeWalker(item, 4);
|
|
46
46
|
for (let node = walker.nextNode(); node; node = walker.nextNode()) if (node.textContent?.trim()) return node;
|
|
47
47
|
return null;
|
|
48
48
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"list-html.js","names":[],"sources":["../../src/extensions/list-html.ts"],"sourcesContent":["import { indentLines, type BlockOutputContext } from '../core/output'\nimport { blockElement, splitContainer } from '../core/prepare'\n\nconst TASK = /^\\s*\\[( |x|X)\\]\\s/\n\n/**\n * Lists from other apps nest a list inside an item (`<li>text<ul>…</ul></li>`),\n * but a list item here is a block of text with child blocks. Rewrite them\n * into blocks before parsing, so nesting survives. Task lists\n * (`<li><input type=\"checkbox\">`, or `[ ]` / `[x]` before the text as\n * Markdown writes them) become to-do items.\n */\nexport function prepareLists(root: HTMLElement) {\n const outer = Array.from(root.querySelectorAll('ul, ol')).filter(\n (list) => !list.parentElement?.closest('ul, ol'),\n )\n for (const list of outer) list.replaceWith(...convertList(list))\n}\n\nfunction convertList(list: Element): HTMLElement[] {\n const doc = list.ownerDocument\n const numbered = list.tagName === 'OL'\n const blocks: HTMLElement[] = []\n for (const item of Array.from(list.children)) {\n if (item.tagName !== 'LI') continue\n let type = numbered ? 'numberedItem' : 'bulletItem'\n const data: Record<string, string> = {}\n const checkbox = item.querySelector(\n ':scope > input[type=\"checkbox\"], :scope > p > input[type=\"checkbox\"]',\n )\n if (checkbox) {\n type = 'checkItem'\n data.checked = String(\n (checkbox as HTMLInputElement).checked || checkbox.hasAttribute('checked'),\n )\n checkbox.remove()\n } else {\n const text = firstText(item)\n const match = text && TASK.exec(text.data)\n if (text && match) {\n type = 'checkItem'\n data.checked = String(match[1] !== ' ')\n text.data = text.data.slice(match[0].length)\n }\n }\n // the first paragraph is the item's text; what follows becomes its children\n for (const nested of Array.from(item.children))\n if (nested.tagName === 'UL' || nested.tagName === 'OL')\n nested.replaceWith(...convertList(nested))\n const { content, children } = splitContainer(item)\n blocks.push(blockElement(doc, type, content, children, data))\n }\n return blocks\n}\n\nfunction firstText(item: Element): Text | null {\n const walker = item.ownerDocument.createTreeWalker(item,
|
|
1
|
+
{"version":3,"file":"list-html.js","names":[],"sources":["../../src/extensions/list-html.ts"],"sourcesContent":["import { indentLines, type BlockOutputContext } from '../core/output'\nimport { blockElement, splitContainer } from '../core/prepare'\n\nconst TASK = /^\\s*\\[( |x|X)\\]\\s/\n\n/**\n * Lists from other apps nest a list inside an item (`<li>text<ul>…</ul></li>`),\n * but a list item here is a block of text with child blocks. Rewrite them\n * into blocks before parsing, so nesting survives. Task lists\n * (`<li><input type=\"checkbox\">`, or `[ ]` / `[x]` before the text as\n * Markdown writes them) become to-do items.\n */\nexport function prepareLists(root: HTMLElement) {\n const outer = Array.from(root.querySelectorAll('ul, ol')).filter(\n (list) => !list.parentElement?.closest('ul, ol'),\n )\n for (const list of outer) list.replaceWith(...convertList(list))\n}\n\nfunction convertList(list: Element): HTMLElement[] {\n const doc = list.ownerDocument\n const numbered = list.tagName === 'OL'\n const blocks: HTMLElement[] = []\n for (const item of Array.from(list.children)) {\n if (item.tagName !== 'LI') continue\n let type = numbered ? 'numberedItem' : 'bulletItem'\n const data: Record<string, string> = {}\n const checkbox = item.querySelector(\n ':scope > input[type=\"checkbox\"], :scope > p > input[type=\"checkbox\"]',\n )\n if (checkbox) {\n type = 'checkItem'\n data.checked = String(\n (checkbox as HTMLInputElement).checked || checkbox.hasAttribute('checked'),\n )\n checkbox.remove()\n } else {\n const text = firstText(item)\n const match = text && TASK.exec(text.data)\n if (text && match) {\n type = 'checkItem'\n data.checked = String(match[1] !== ' ')\n text.data = text.data.slice(match[0].length)\n }\n }\n // the first paragraph is the item's text; what follows becomes its children\n for (const nested of Array.from(item.children))\n if (nested.tagName === 'UL' || nested.tagName === 'OL')\n nested.replaceWith(...convertList(nested))\n const { content, children } = splitContainer(item)\n blocks.push(blockElement(doc, type, content, children, data))\n }\n return blocks\n}\n\nfunction firstText(item: Element): Text | null {\n // NodeFilter.SHOW_TEXT, as a number: the DOM may come from a library, without globals\n const walker = item.ownerDocument.createTreeWalker(item, 4)\n for (let node = walker.nextNode(); node; node = walker.nextNode()) {\n if (node.textContent?.trim()) return node as Text\n }\n return null\n}\n\n/** A list item in Markdown: the marker, the text, and the children indented under it. */\nexport function listItemMarkdown(marker: string, { content, children }: BlockOutputContext) {\n // a checkbox marker indents its children like the bullet in front of it\n const width = marker.startsWith('- [') ? 2 : marker.length\n const item = indentLines(content, marker, ' '.repeat(width))\n if (!children) return item\n // a nested list follows right after; other blocks need a blank line, or they join the text\n const gap = /^([-*+]|\\d+[.)])( |$)/.test(children) ? '\\n' : '\\n\\n'\n return `${item}${gap}${indentLines(children, ' '.repeat(width))}`\n}\n"],"mappings":";;;AAGA,IAAM,OAAO;;;;;;;;AASb,SAAgB,aAAa,MAAmB;CAC9C,MAAM,QAAQ,MAAM,KAAK,KAAK,iBAAiB,QAAQ,CAAC,CAAC,CAAC,QACvD,SAAS,CAAC,KAAK,eAAe,QAAQ,QAAQ,CACjD;CACA,KAAK,MAAM,QAAQ,OAAO,KAAK,YAAY,GAAG,YAAY,IAAI,CAAC;AACjE;AAEA,SAAS,YAAY,MAA8B;CACjD,MAAM,MAAM,KAAK;CACjB,MAAM,WAAW,KAAK,YAAY;CAClC,MAAM,SAAwB,CAAC;CAC/B,KAAK,MAAM,QAAQ,MAAM,KAAK,KAAK,QAAQ,GAAG;EAC5C,IAAI,KAAK,YAAY,MAAM;EAC3B,IAAI,OAAO,WAAW,iBAAiB;EACvC,MAAM,OAA+B,CAAC;EACtC,MAAM,WAAW,KAAK,cACpB,0EACF;EACA,IAAI,UAAU;GACZ,OAAO;GACP,KAAK,UAAU,OACZ,SAA8B,WAAW,SAAS,aAAa,SAAS,CAC3E;GACA,SAAS,OAAO;EAClB,OAAO;GACL,MAAM,OAAO,UAAU,IAAI;GAC3B,MAAM,QAAQ,QAAQ,KAAK,KAAK,KAAK,IAAI;GACzC,IAAI,QAAQ,OAAO;IACjB,OAAO;IACP,KAAK,UAAU,OAAO,MAAM,OAAO,GAAG;IACtC,KAAK,OAAO,KAAK,KAAK,MAAM,MAAM,EAAE,CAAC,MAAM;GAC7C;EACF;EAEA,KAAK,MAAM,UAAU,MAAM,KAAK,KAAK,QAAQ,GAC3C,IAAI,OAAO,YAAY,QAAQ,OAAO,YAAY,MAChD,OAAO,YAAY,GAAG,YAAY,MAAM,CAAC;EAC7C,MAAM,EAAE,SAAS,aAAa,eAAe,IAAI;EACjD,OAAO,KAAK,aAAa,KAAK,MAAM,SAAS,UAAU,IAAI,CAAC;CAC9D;CACA,OAAO;AACT;AAEA,SAAS,UAAU,MAA4B;CAE7C,MAAM,SAAS,KAAK,cAAc,iBAAiB,MAAM,CAAC;CAC1D,KAAK,IAAI,OAAO,OAAO,SAAS,GAAG,MAAM,OAAO,OAAO,SAAS,GAC9D,IAAI,KAAK,aAAa,KAAK,GAAG,OAAO;CAEvC,OAAO;AACT;;AAGA,SAAgB,iBAAiB,QAAgB,EAAE,SAAS,YAAgC;CAE1F,MAAM,QAAQ,OAAO,WAAW,KAAK,IAAI,IAAI,OAAO;CACpD,MAAM,OAAO,YAAY,SAAS,QAAQ,IAAI,OAAO,KAAK,CAAC;CAC3D,IAAI,CAAC,UAAU,OAAO;CAGtB,OAAO,GAAG,OADE,wBAAwB,KAAK,QAAQ,IAAI,OAAO,SACrC,YAAY,UAAU,IAAI,OAAO,KAAK,CAAC;AAChE"}
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":["Editor"],"sources":["../src/index.ts"],"sourcesContent":["import { withInstall } from 'dou-ui'\nimport Editor from './editor.vue'\nimport type { EditorContent } from './define-block'\n\nexport const DouEditor = withInstall(Editor)\nexport default DouEditor\n\nexport { useEditor, useToolbarMenu } from './editor'\nexport type {\n EditorComments,\n EditorContext,\n EditorEmits,\n EditorExpose,\n EditorLinkOpenEvent,\n EditorProps,\n EditorOrigin,\n EditorSelection,\n EditorTransactionResult,\n} from './editor'\nexport { EditorTransaction } from './core/transaction'\nexport type {\n BlockEdge,\n BlockPatch,\n BlockPlacement,\n EditorTransactionMeta,\n} from './core/transaction'\nexport type { BlockChanges } from './core/changes'\nexport type { CommentAnchor, CommentRange } from './core/comments'\nexport { editorLocales, useEditorMessages } from './locale'\nexport type { EditorMessages, EditorMessagesOverride } from './locale'\nexport { filterOptions } from './catalog'\nexport { defineEditorExtension, labelOf } from './core/extension'\nexport type {\n BlockOption,\n CommentsProvider,\n EditorExtension,\n EditorExtensionContext,\n FormatOption,\n HistoryProvider,\n Label,\n MountComponent,\n ResolvedEditorExtensions,\n} from './core/extension'\nexport {\n align,\n callout,\n codeBlock,\n colors,\n divider,\n formatting,\n heading,\n link,\n lists,\n paragraph,\n quote,\n editorKit,\n table,\n toggle,\n} from './extensions/editor-kit'\nexport type { CalloutTone } from './extensions/callout'\nexport { setHighlight, setTextColor, textColors } from './extensions/colors'\nexport type { TextColor } from './extensions/colors'\nexport { currentAlign, setAlign } from './extensions/align'\nexport { alignable } from './core/align'\nexport type { BlockAlign } from './core/align'\nexport { attachment, formatFileSize, isSafeFileSrc } from './extensions/attachment'\nexport type { AttachmentOptions } from './extensions/attachment'\nexport { embed, resolveEmbed } from './extensions/embed'\nexport type { EmbedOptions, EmbedResolver, EmbedTarget } from './extensions/embed'\nexport {\n alignColumns,\n clearCells,\n deleteColumns,\n deleteRows,\n insertColumn,\n insertRow,\n mergeCells,\n moveLines,\n moveLinesTo,\n splitMergedCell,\n toggleHeader,\n} from './extensions/table'\nexport type { TableAlign, TableColumn } from './extensions/table'\nexport type { EditorKitOptions } from './extensions/editor-kit'\nexport { componentMounter, defineBlock, EditorContent, vueNodeView } from './define-block'\nexport { historyCommands } from './core/editor'\nexport { defaultLanguages } from './extensions/code-block'\nexport type { CodeBlockOptions, CodeHighlighter, CodeLanguage } from './extensions/code-block'\nexport { image, isSafeImageSrc, readAsDataUrl } from './extensions/image'\nexport { mention } from './extensions/mention'\nexport type { MentionItem, MentionOptions } from './extensions/mention'\nexport type { FileUploader, ImageOptions } from './extensions/image'\nexport type { BlockViewProps, DefineBlockOptions } from './define-block'\nexport { atomInputRule, blockInputRule, markInputRule } from './core/input-rules'\nexport type {\n Block,\n BlockProps,\n BreakContent,\n EditorDocument,\n InlineContent,\n InlineNodeContent,\n PartialBlock,\n PartialTableCell,\n PartialTableRow,\n RowsSpec,\n TableCell,\n TableRow,\n TextContent,\n} from './core/model'\nexport { blocksToDoc, createId, docToBlocks } from './core/model'\nexport { diffBlocks, diffText, inlineText } from './core/diff'\nexport type { BlockVersionChange, BlocksDiff, TextPart } from './core/diff'\nexport { searchDoc } from './core/search'\nexport type { EditorMatch, EditorSearchQuery } from './core/search'\nexport { checkDocument, emptyDocument, migrateDocument } from './document'\nexport type { CheckDocumentOptions, DocumentProblem } from './document'\nexport type { BuiltinContentType, ContentType, MarkType } from './core/schema'\nexport { contentDOM, createSchema, isSafeHref, textBlock } from './core/schema'\nexport {\n duplicateBlocks,\n insertBlockAfter,\n liftBlocks,\n swapBlocks,\n moveRangeTo,\n setBlockType,\n sinkBlocks,\n} from './core/commands'\nexport { clearBlockSelection, getBlockSelection, selectBlocks } from './core/block-selection'\nexport { isRemote } from './core/plugins'\nexport { blocksToHTML, htmlToBlocks } from './core/convert'\nexport type { EditorExtensionList } from './core/convert'\nexport { escapeHTML, escapeMarkdown, indentLines } from './core/output'\nexport type {\n BlockOutput,\n BlockOutputContext,\n EditorExtensionOutput,\n InlineOutput,\n MarkdownBlockContext,\n MarkOutput,\n} from './core/output'\nexport { blockElement, splitContainer } from './core/prepare'\n\ndeclare module 'vue' {\n export interface GlobalComponents {\n DouEditor: typeof DouEditor\n DouEditorContent: typeof EditorContent\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAIA,IAAa,YAAY,YAAYA,cAAM"}
|
|
1
|
+
{"version":3,"file":"index.js","names":["Editor"],"sources":["../src/index.ts"],"sourcesContent":["import { withInstall } from 'dou-ui'\nimport Editor from './editor.vue'\nimport type { EditorContent } from './define-block'\n\nexport const DouEditor = withInstall(Editor)\nexport default DouEditor\n\nexport { useEditor, useToolbarMenu } from './editor'\nexport type {\n EditorComments,\n EditorContext,\n EditorEmits,\n EditorExpose,\n EditorLinkOpenEvent,\n EditorProps,\n EditorOrigin,\n EditorSelection,\n EditorTransactionResult,\n} from './editor'\nexport { EditorTransaction } from './core/transaction'\nexport type {\n BlockEdge,\n BlockPatch,\n BlockPlacement,\n EditorTransactionMeta,\n} from './core/transaction'\nexport type { BlockChanges } from './core/changes'\nexport type { CommentAnchor, CommentRange } from './core/comments'\nexport { editorLocales, useEditorMessages } from './locale'\nexport type { EditorMessages, EditorMessagesOverride } from './locale'\nexport { filterOptions } from './catalog'\nexport { defineEditorExtension, labelOf } from './core/extension'\nexport type {\n BlockOption,\n CommentsProvider,\n EditorExtension,\n EditorExtensionContext,\n FormatOption,\n HistoryProvider,\n Label,\n MountComponent,\n ResolvedEditorExtensions,\n} from './core/extension'\nexport {\n align,\n callout,\n codeBlock,\n colors,\n divider,\n formatting,\n heading,\n link,\n lists,\n paragraph,\n quote,\n editorKit,\n table,\n toggle,\n} from './extensions/editor-kit'\nexport type { CalloutTone } from './extensions/callout'\nexport { setHighlight, setTextColor, textColors } from './extensions/colors'\nexport type { TextColor } from './extensions/colors'\nexport { currentAlign, setAlign } from './extensions/align'\nexport { alignable } from './core/align'\nexport type { BlockAlign } from './core/align'\nexport { attachment, formatFileSize, isSafeFileSrc } from './extensions/attachment'\nexport type { AttachmentOptions } from './extensions/attachment'\nexport { embed, resolveEmbed } from './extensions/embed'\nexport type { EmbedOptions, EmbedResolver, EmbedTarget } from './extensions/embed'\nexport {\n alignColumns,\n clearCells,\n deleteColumns,\n deleteRows,\n insertColumn,\n insertRow,\n mergeCells,\n moveLines,\n moveLinesTo,\n splitMergedCell,\n toggleHeader,\n} from './extensions/table'\nexport type { TableAlign, TableColumn } from './extensions/table'\nexport type { EditorKitOptions } from './extensions/editor-kit'\nexport { componentMounter, defineBlock, EditorContent, vueNodeView } from './define-block'\nexport { historyCommands } from './core/editor'\nexport { defaultLanguages } from './extensions/code-block'\nexport type { CodeBlockOptions, CodeHighlighter, CodeLanguage } from './extensions/code-block'\nexport { image, isSafeImageSrc, readAsDataUrl } from './extensions/image'\nexport { mention } from './extensions/mention'\nexport type { MentionItem, MentionOptions } from './extensions/mention'\nexport type { FileUploader, ImageOptions } from './extensions/image'\nexport type { BlockViewProps, DefineBlockOptions } from './define-block'\nexport { atomInputRule, blockInputRule, markInputRule } from './core/input-rules'\nexport type {\n Block,\n BlockProps,\n BreakContent,\n EditorDocument,\n InlineContent,\n InlineNodeContent,\n PartialBlock,\n PartialTableCell,\n PartialTableRow,\n RowsSpec,\n TableCell,\n TableRow,\n TextContent,\n} from './core/model'\nexport { blocksToDoc, createId, docToBlocks } from './core/model'\nexport { diffBlocks, diffText, inlineText } from './core/diff'\nexport type { BlockVersionChange, BlocksDiff, TextPart } from './core/diff'\nexport { searchDoc } from './core/search'\nexport type { EditorMatch, EditorSearchQuery } from './core/search'\nexport { checkDocument, emptyDocument, migrateDocument } from './document'\nexport type { CheckDocumentOptions, DocumentProblem } from './document'\nexport type { BuiltinContentType, ContentType, MarkType } from './core/schema'\nexport { contentDOM, createSchema, isSafeHref, textBlock } from './core/schema'\nexport {\n duplicateBlocks,\n insertBlockAfter,\n liftBlocks,\n swapBlocks,\n moveRangeTo,\n setBlockType,\n sinkBlocks,\n} from './core/commands'\nexport { clearBlockSelection, getBlockSelection, selectBlocks } from './core/block-selection'\nexport { isRemote } from './core/plugins'\nexport { blocksToHTML, htmlToBlocks, type HTMLToBlocksOptions } from './core/convert'\nexport type { DOMParserLike } from './core/prepare'\nexport type { EditorExtensionList } from './core/convert'\nexport { escapeHTML, escapeMarkdown, indentLines } from './core/output'\nexport type {\n BlockOutput,\n BlockOutputContext,\n EditorExtensionOutput,\n InlineOutput,\n MarkdownBlockContext,\n MarkOutput,\n} from './core/output'\nexport { blockElement, splitContainer } from './core/prepare'\n\ndeclare module 'vue' {\n export interface GlobalComponents {\n DouEditor: typeof DouEditor\n DouEditorContent: typeof EditorContent\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAIA,IAAa,YAAY,YAAYA,cAAM"}
|
package/dist/markdown/index.js
CHANGED
|
@@ -15,9 +15,9 @@ function render(markdown) {
|
|
|
15
15
|
function blocksToMarkdown(blocks, extensions) {
|
|
16
16
|
return writeMarkdown(blocks, kitOf(extensions));
|
|
17
17
|
}
|
|
18
|
-
/** Read Markdown as blocks. Needs `DOMParser
|
|
18
|
+
/** Read Markdown as blocks. Needs a `DOMParser`: the browser's, or `options.domParser`. */
|
|
19
19
|
function markdownToBlocks(markdown, extensions, options = {}) {
|
|
20
|
-
return parseHTML((options.render ?? render)(markdown), kitOf(extensions));
|
|
20
|
+
return parseHTML((options.render ?? render)(markdown), kitOf(extensions), options.domParser, "markdownToBlocks(markdown, extensions, { domParser })");
|
|
21
21
|
}
|
|
22
22
|
export { blocksToMarkdown, markdownToBlocks };
|
|
23
23
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":[],"sources":["../../src/markdown/index.ts"],"sourcesContent":["import MarkdownIt from 'markdown-it'\nimport { kitOf, type EditorExtensionList } from '../core/convert'\nimport type { Block, PartialBlock } from '../core/model'\nimport { writeMarkdown } from '../core/output'\nimport { parseHTML } from '../core/prepare'\n\nexport interface MarkdownToBlocksOptions {\n /**\n * Turns Markdown into HTML. Defaults to markdown-it with HTML allowed\n * (the HTML is read like pasted HTML, so only what the extensions know\n * is kept); pass your own to add syntax.\n */\n render?: (markdown: string) => string\n}\n\nlet parser: MarkdownIt | undefined\n\nfunction render(markdown: string) {\n parser ??= new MarkdownIt({ html: true, linkify: true })\n return parser.render(markdown)\n}\n\n/** Write blocks as Markdown (CommonMark with GitHub's extensions). Works without a browser. */\nexport function blocksToMarkdown(blocks: PartialBlock[], extensions: EditorExtensionList): string {\n return writeMarkdown(blocks, kitOf(extensions))\n}\n\n/** Read Markdown as blocks. Needs `DOMParser
|
|
1
|
+
{"version":3,"file":"index.js","names":[],"sources":["../../src/markdown/index.ts"],"sourcesContent":["import MarkdownIt from 'markdown-it'\nimport { kitOf, type EditorExtensionList } from '../core/convert'\nimport type { Block, PartialBlock } from '../core/model'\nimport { writeMarkdown } from '../core/output'\nimport { parseHTML, type DOMParserLike } from '../core/prepare'\n\nexport type { DOMParserLike }\n\nexport interface MarkdownToBlocksOptions {\n /**\n * Turns Markdown into HTML. Defaults to markdown-it with HTML allowed\n * (the HTML is read like pasted HTML, so only what the extensions know\n * is kept); pass your own to add syntax.\n */\n render?: (markdown: string) => string\n /**\n * Reads the HTML. Defaults to the global `DOMParser`; where there is none\n * (Node, Bun), pass one from a DOM library such as happy-dom or linkedom.\n */\n domParser?: DOMParserLike\n}\n\nlet parser: MarkdownIt | undefined\n\nfunction render(markdown: string) {\n parser ??= new MarkdownIt({ html: true, linkify: true })\n return parser.render(markdown)\n}\n\n/** Write blocks as Markdown (CommonMark with GitHub's extensions). Works without a browser. */\nexport function blocksToMarkdown(blocks: PartialBlock[], extensions: EditorExtensionList): string {\n return writeMarkdown(blocks, kitOf(extensions))\n}\n\n/** Read Markdown as blocks. Needs a `DOMParser`: the browser's, or `options.domParser`. */\nexport function markdownToBlocks(\n markdown: string,\n extensions: EditorExtensionList,\n options: MarkdownToBlocksOptions = {},\n): Block[] {\n return parseHTML(\n (options.render ?? render)(markdown),\n kitOf(extensions),\n options.domParser,\n 'markdownToBlocks(markdown, extensions, { domParser })',\n )\n}\n"],"mappings":";;;;;AAsBA,IAAI;AAEJ,SAAS,OAAO,UAAkB;CAChC,WAAW,IAAI,WAAW;EAAE,MAAM;EAAM,SAAS;CAAK,CAAC;CACvD,OAAO,OAAO,OAAO,QAAQ;AAC/B;;AAGA,SAAgB,iBAAiB,QAAwB,YAAyC;CAChG,OAAO,cAAc,QAAQ,MAAM,UAAU,CAAC;AAChD;;AAGA,SAAgB,iBACd,UACA,YACA,UAAmC,CAAC,GAC3B;CACT,OAAO,WACJ,QAAQ,UAAU,OAAA,CAAQ,QAAQ,GACnC,MAAM,UAAU,GAChB,QAAQ,WACR,uDACF;AACF"}
|