@milkdown/plugin-diagram
Advanced tools
Comparing version 7.2.4 to 7.3.0
@@ -7,31 +7,31 @@ import { expectDomTypeError as f } from "@milkdown/exception"; | ||
import { visit as M } from "unist-util-visit"; | ||
import { customAlphabet as $ } from "nanoid"; | ||
const w = (e) => ({ | ||
import { customAlphabet as R } from "nanoid"; | ||
const $ = (t) => ({ | ||
type: "diagram", | ||
value: e | ||
}), R = (e) => M(e, "code", (t, i, a) => { | ||
const { lang: r, value: s } = t; | ||
value: t | ||
}), w = (t) => M(t, "code", (e, i, a) => { | ||
const { lang: r, value: s } = e; | ||
if (r !== "mermaid") | ||
return t; | ||
const m = w(s); | ||
return a && i != null && a.children.splice(i, 1, m), t; | ||
return e; | ||
const m = $(s); | ||
return a && i != null && a.children.splice(i, 1, m), e; | ||
}), I = () => { | ||
function e(t) { | ||
R(t); | ||
function t(e) { | ||
w(e); | ||
} | ||
return e; | ||
}, T = $("abcdefg", 8), c = (e) => { | ||
var t; | ||
return ((t = e == null ? void 0 : e.attrs) == null ? void 0 : t.identity) || T(); | ||
}, n = (e, t) => (Object.assign(e, { | ||
return t; | ||
}, T = R("abcdefg", 8), c = (t) => { | ||
var e; | ||
return ((e = t == null ? void 0 : t.attrs) == null ? void 0 : e.identity) || T(); | ||
}, n = (t, e) => (Object.assign(t, { | ||
meta: { | ||
package: "@milkdown/plugin-diagram", | ||
...t | ||
...e | ||
} | ||
}), e), l = k({ startOnLoad: !1 }, "mermaidConfig"); | ||
}), t), l = k({ startOnLoad: !1 }, "mermaidConfig"); | ||
n(l, { | ||
displayName: "Ctx<mermaidConfig>" | ||
}); | ||
const o = "diagram", d = h(o, (e) => (D.initialize({ | ||
...e.get(l.key) | ||
const o = "diagram", d = h(o, (t) => (D.initialize({ | ||
...t.get(l.key) | ||
}), { | ||
@@ -56,8 +56,8 @@ content: "text*", | ||
preserveWhitespace: "full", | ||
getAttrs: (t) => { | ||
if (!(t instanceof HTMLElement)) | ||
throw f(t); | ||
getAttrs: (e) => { | ||
if (!(e instanceof HTMLElement)) | ||
throw f(e); | ||
return { | ||
value: t.dataset.value, | ||
identity: t.dataset.id | ||
value: e.dataset.value, | ||
identity: e.dataset.id | ||
}; | ||
@@ -67,17 +67,17 @@ } | ||
], | ||
toDOM: (t) => { | ||
const i = c(t), a = t.attrs.value, r = document.createElement("div"); | ||
toDOM: (e) => { | ||
const i = c(e), a = e.attrs.value, r = document.createElement("div"); | ||
return r.dataset.type = o, r.dataset.id = i, r.dataset.value = a, r.textContent = a, r; | ||
}, | ||
parseMarkdown: { | ||
match: ({ type: t }) => t === o, | ||
runner: (t, i, a) => { | ||
match: ({ type: e }) => e === o, | ||
runner: (e, i, a) => { | ||
const r = i.value; | ||
t.addNode(a, { value: r, identity: c() }); | ||
e.addNode(a, { value: r, identity: c() }); | ||
} | ||
}, | ||
toMarkdown: { | ||
match: (t) => t.type.name === o, | ||
runner: (t, i) => { | ||
t.addNode("code", void 0, i.attrs.value || "", { lang: "mermaid" }); | ||
match: (e) => e.type.name === o, | ||
runner: (e, i) => { | ||
e.addNode("code", void 0, i.attrs.value || "", { lang: "mermaid" }); | ||
} | ||
@@ -92,18 +92,21 @@ } | ||
}); | ||
const u = C((e) => new v(/^```mermaid$/, (t, i, a, r) => { | ||
const s = d.type(e), m = t.doc.resolve(a); | ||
return m.node(-1).canReplaceWith(m.index(-1), m.indexAfter(-1), s) ? t.tr.delete(a, r).setBlockType(a, a, s, { identity: c() }) : null; | ||
const p = C((t) => new v(/^```mermaid$/, (e, i, a, r) => { | ||
const s = d.type(t), m = e.doc.resolve(a); | ||
return m.node(-1).canReplaceWith(m.index(-1), m.indexAfter(-1), s) ? e.tr.delete(a, r).setBlockType(a, a, s, { identity: c() }) : null; | ||
})); | ||
n(u, { | ||
n(p, { | ||
displayName: "InputRule<insertDiagramInputRules>" | ||
}); | ||
const p = N(() => I); | ||
n(p, { | ||
const u = N("remarkMermaid", () => I); | ||
n(u.plugin, { | ||
displayName: "Remark<diagram>" | ||
}); | ||
const g = x("InsertDiagramCommand", (e) => () => y(d.type(e), { identity: c() })); | ||
n(u.options, { | ||
displayName: "RemarkConfig<diagram>" | ||
}); | ||
const g = x("InsertDiagramCommand", (t) => () => y(d.type(t), { identity: c() })); | ||
n(g, { | ||
displayName: "Command<insertDiagramCommand>" | ||
}); | ||
const W = [p, l, d, g, u].flat(); | ||
const W = [u, l, d, g, p].flat(); | ||
export { | ||
@@ -113,6 +116,6 @@ W as diagram, | ||
g as insertDiagramCommand, | ||
u as insertDiagramInputRules, | ||
p as insertDiagramInputRules, | ||
l as mermaidConfigCtx, | ||
p as remarkDiagramPlugin | ||
u as remarkDiagramPlugin | ||
}; | ||
//# sourceMappingURL=index.es.js.map |
@@ -7,31 +7,31 @@ import { expectDomTypeError as f } from "@milkdown/exception"; | ||
import { visit as M } from "unist-util-visit"; | ||
import { customAlphabet as $ } from "nanoid"; | ||
const w = (e) => ({ | ||
import { customAlphabet as R } from "nanoid"; | ||
const $ = (t) => ({ | ||
type: "diagram", | ||
value: e | ||
}), R = (e) => M(e, "code", (t, i, a) => { | ||
const { lang: r, value: s } = t; | ||
value: t | ||
}), w = (t) => M(t, "code", (e, i, a) => { | ||
const { lang: r, value: s } = e; | ||
if (r !== "mermaid") | ||
return t; | ||
const m = w(s); | ||
return a && i != null && a.children.splice(i, 1, m), t; | ||
return e; | ||
const m = $(s); | ||
return a && i != null && a.children.splice(i, 1, m), e; | ||
}), I = () => { | ||
function e(t) { | ||
R(t); | ||
function t(e) { | ||
w(e); | ||
} | ||
return e; | ||
}, T = $("abcdefg", 8), c = (e) => { | ||
var t; | ||
return ((t = e == null ? void 0 : e.attrs) == null ? void 0 : t.identity) || T(); | ||
}, n = (e, t) => (Object.assign(e, { | ||
return t; | ||
}, T = R("abcdefg", 8), c = (t) => { | ||
var e; | ||
return ((e = t == null ? void 0 : t.attrs) == null ? void 0 : e.identity) || T(); | ||
}, n = (t, e) => (Object.assign(t, { | ||
meta: { | ||
package: "@milkdown/plugin-diagram", | ||
...t | ||
...e | ||
} | ||
}), e), l = k({ startOnLoad: !1 }, "mermaidConfig"); | ||
}), t), l = k({ startOnLoad: !1 }, "mermaidConfig"); | ||
n(l, { | ||
displayName: "Ctx<mermaidConfig>" | ||
}); | ||
const o = "diagram", d = h(o, (e) => (D.initialize({ | ||
...e.get(l.key) | ||
const o = "diagram", d = h(o, (t) => (D.initialize({ | ||
...t.get(l.key) | ||
}), { | ||
@@ -56,8 +56,8 @@ content: "text*", | ||
preserveWhitespace: "full", | ||
getAttrs: (t) => { | ||
if (!(t instanceof HTMLElement)) | ||
throw f(t); | ||
getAttrs: (e) => { | ||
if (!(e instanceof HTMLElement)) | ||
throw f(e); | ||
return { | ||
value: t.dataset.value, | ||
identity: t.dataset.id | ||
value: e.dataset.value, | ||
identity: e.dataset.id | ||
}; | ||
@@ -67,17 +67,17 @@ } | ||
], | ||
toDOM: (t) => { | ||
const i = c(t), a = t.attrs.value, r = document.createElement("div"); | ||
toDOM: (e) => { | ||
const i = c(e), a = e.attrs.value, r = document.createElement("div"); | ||
return r.dataset.type = o, r.dataset.id = i, r.dataset.value = a, r.textContent = a, r; | ||
}, | ||
parseMarkdown: { | ||
match: ({ type: t }) => t === o, | ||
runner: (t, i, a) => { | ||
match: ({ type: e }) => e === o, | ||
runner: (e, i, a) => { | ||
const r = i.value; | ||
t.addNode(a, { value: r, identity: c() }); | ||
e.addNode(a, { value: r, identity: c() }); | ||
} | ||
}, | ||
toMarkdown: { | ||
match: (t) => t.type.name === o, | ||
runner: (t, i) => { | ||
t.addNode("code", void 0, i.attrs.value || "", { lang: "mermaid" }); | ||
match: (e) => e.type.name === o, | ||
runner: (e, i) => { | ||
e.addNode("code", void 0, i.attrs.value || "", { lang: "mermaid" }); | ||
} | ||
@@ -92,18 +92,21 @@ } | ||
}); | ||
const u = C((e) => new v(/^```mermaid$/, (t, i, a, r) => { | ||
const s = d.type(e), m = t.doc.resolve(a); | ||
return m.node(-1).canReplaceWith(m.index(-1), m.indexAfter(-1), s) ? t.tr.delete(a, r).setBlockType(a, a, s, { identity: c() }) : null; | ||
const p = C((t) => new v(/^```mermaid$/, (e, i, a, r) => { | ||
const s = d.type(t), m = e.doc.resolve(a); | ||
return m.node(-1).canReplaceWith(m.index(-1), m.indexAfter(-1), s) ? e.tr.delete(a, r).setBlockType(a, a, s, { identity: c() }) : null; | ||
})); | ||
n(u, { | ||
n(p, { | ||
displayName: "InputRule<insertDiagramInputRules>" | ||
}); | ||
const p = N(() => I); | ||
n(p, { | ||
const u = N("remarkMermaid", () => I); | ||
n(u.plugin, { | ||
displayName: "Remark<diagram>" | ||
}); | ||
const g = x("InsertDiagramCommand", (e) => () => y(d.type(e), { identity: c() })); | ||
n(u.options, { | ||
displayName: "RemarkConfig<diagram>" | ||
}); | ||
const g = x("InsertDiagramCommand", (t) => () => y(d.type(t), { identity: c() })); | ||
n(g, { | ||
displayName: "Command<insertDiagramCommand>" | ||
}); | ||
const W = [p, l, d, g, u].flat(); | ||
const W = [u, l, d, g, p].flat(); | ||
export { | ||
@@ -113,6 +116,6 @@ W as diagram, | ||
g as insertDiagramCommand, | ||
u as insertDiagramInputRules, | ||
p as insertDiagramInputRules, | ||
l as mermaidConfigCtx, | ||
p as remarkDiagramPlugin | ||
u as remarkDiagramPlugin | ||
}; | ||
//# sourceMappingURL=index.es.js.map |
@@ -5,4 +5,4 @@ import type { MermaidConfig } from 'mermaid'; | ||
export declare const insertDiagramInputRules: import("@milkdown/utils").$InputRule; | ||
export declare const remarkDiagramPlugin: import("@milkdown/utils").$Remark; | ||
export declare const remarkDiagramPlugin: import("@milkdown/utils").$Remark<"remarkMermaid", unknown>; | ||
export declare const insertDiagramCommand: import("@milkdown/utils").$Command<unknown>; | ||
//# sourceMappingURL=node.d.ts.map |
@@ -1,3 +0,3 @@ | ||
import type { Node } from 'unist'; | ||
import type { Node } from '@milkdown/transformer'; | ||
export declare const remarkMermaid: () => (tree: Node) => void; | ||
//# sourceMappingURL=remark-mermaid.d.ts.map |
{ | ||
"name": "@milkdown/plugin-diagram", | ||
"type": "module", | ||
"version": "7.2.4", | ||
"version": "7.3.0", | ||
"license": "MIT", | ||
@@ -27,3 +27,4 @@ "repository": { | ||
"@milkdown/ctx": "^7.2.0", | ||
"@milkdown/prose": "^7.2.0" | ||
"@milkdown/prose": "^7.2.0", | ||
"@milkdown/transformer": "^7.2.0" | ||
}, | ||
@@ -35,12 +36,12 @@ "dependencies": { | ||
"tslib": "^2.5.0", | ||
"unist-util-visit": "^4.0.0", | ||
"@milkdown/exception": "7.2.4", | ||
"@milkdown/utils": "7.2.4" | ||
"unist-util-visit": "^5.0.0", | ||
"@milkdown/exception": "7.3.0", | ||
"@milkdown/utils": "7.3.0" | ||
}, | ||
"devDependencies": { | ||
"@types/d3": "^7.4.0", | ||
"@types/unist": "^2.0.6", | ||
"@milkdown/core": "7.2.4", | ||
"@milkdown/ctx": "7.2.4", | ||
"@milkdown/prose": "7.2.4" | ||
"@milkdown/core": "7.3.0", | ||
"@milkdown/ctx": "7.3.0", | ||
"@milkdown/prose": "7.3.0", | ||
"@milkdown/transformer": "7.3.0" | ||
}, | ||
@@ -47,0 +48,0 @@ "nx": { |
@@ -115,8 +115,12 @@ /* Copyright 2021, Milkdown by Mirone. */ | ||
/// A remark plugin that will parse mermaid code block. | ||
export const remarkDiagramPlugin = $remark(() => remarkMermaid) | ||
export const remarkDiagramPlugin = $remark('remarkMermaid', () => remarkMermaid) | ||
withMeta(remarkDiagramPlugin, { | ||
withMeta(remarkDiagramPlugin.plugin, { | ||
displayName: 'Remark<diagram>', | ||
}) | ||
withMeta(remarkDiagramPlugin.options, { | ||
displayName: 'RemarkConfig<diagram>', | ||
}) | ||
/// A command that will insert a diagram node. | ||
@@ -123,0 +127,0 @@ export const insertDiagramCommand = $command('InsertDiagramCommand', ctx => () => setBlockType(diagramSchema.type(ctx), { identity: getId() })) |
/* Copyright 2021, Milkdown by Mirone. */ | ||
import type { Node, Parent } from 'unist' | ||
import type { Node } from '@milkdown/transformer' | ||
import { visit } from 'unist-util-visit' | ||
@@ -12,3 +12,3 @@ | ||
const visitCodeBlock = (ast: Node) => | ||
visit(ast, 'code', (node, index, parent: Parent) => { | ||
visit(ast, 'code', (node, index, parent: Node & { children: Node[] }) => { | ||
const { lang, value } = node | ||
@@ -15,0 +15,0 @@ |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
26699
411
11
+ Added@milkdown/exception@7.3.0(transitive)
+ Added@milkdown/utils@7.3.0(transitive)
- Removed@milkdown/exception@7.2.4(transitive)
- Removed@milkdown/utils@7.2.4(transitive)
- Removedunist-util-is@5.2.1(transitive)
- Removedunist-util-visit@4.1.2(transitive)
- Removedunist-util-visit-parents@5.1.3(transitive)
Updated@milkdown/exception@7.3.0
Updated@milkdown/utils@7.3.0
Updatedunist-util-visit@^5.0.0