Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@milkdown/transformer

Package Overview
Dependencies
Maintainers
1
Versions
64
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@milkdown/transformer - npm Package Compare versions

Comparing version 6.2.0 to 6.3.0

572

lib/index.es.js

@@ -1,312 +0,176 @@

var __defProp = Object.defineProperty;
var __defProps = Object.defineProperties;
var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __propIsEnum = Object.prototype.propertyIsEnumerable;
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
var __spreadValues = (a, b) => {
for (var prop in b || (b = {}))
if (__hasOwnProp.call(b, prop))
__defNormalProp(a, prop, b[prop]);
if (__getOwnPropSymbols)
for (var prop of __getOwnPropSymbols(b)) {
if (__propIsEnum.call(b, prop))
__defNormalProp(a, prop, b[prop]);
}
return a;
var J = (e, t, s) => {
if (!t.has(e))
throw TypeError("Cannot " + s);
};
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
var __objRest = (source, exclude) => {
var target = {};
for (var prop in source)
if (__hasOwnProp.call(source, prop) && exclude.indexOf(prop) < 0)
target[prop] = source[prop];
if (source != null && __getOwnPropSymbols)
for (var prop of __getOwnPropSymbols(source)) {
if (exclude.indexOf(prop) < 0 && __propIsEnum.call(source, prop))
target[prop] = source[prop];
}
return target;
};
var __accessCheck = (obj, member, msg) => {
if (!member.has(obj))
throw TypeError("Cannot " + msg);
};
var __privateAdd = (obj, member, value) => {
if (member.has(obj))
var h = (e, t, s) => {
if (t.has(e))
throw TypeError("Cannot add the same private member more than once");
member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
t instanceof WeakSet ? t.add(e) : t.set(e, s);
};
var __privateMethod = (obj, member, method) => {
__accessCheck(obj, member, "access private method");
return method;
};
var _matchTarget, matchTarget_fn, _runNode, runNode_fn, _matchTarget2, matchTarget_fn2, _runProseNode, runProseNode_fn, _runProseMark, runProseMark_fn, _runNode2, runNode_fn2;
import { stackOverFlow, createNodeInParserFail, parserMatchError, serializerMatchError } from "@milkdown/exception";
import { Mark } from "@milkdown/prose/model";
var a = (e, t, s) => (J(e, t, "access private method"), s);
import { stackOverFlow as v, createNodeInParserFail as x, parserMatchError as A, serializerMatchError as U } from "@milkdown/exception";
import { Mark as $ } from "@milkdown/prose/model";
export * from "remark";
const getStackUtil = () => {
const size2 = (ctx) => ctx.elements.length;
const top2 = (ctx) => ctx.elements[size2(ctx) - 1];
const push2 = (ctx) => (node) => {
var _a;
(_a = top2(ctx)) == null ? void 0 : _a.push(node);
};
const open2 = (ctx) => (node) => {
ctx.elements.push(node);
};
const close2 = (ctx) => {
const el = ctx.elements.pop();
if (!el)
throw stackOverFlow();
return el;
};
const w = () => {
const e = (o) => o.elements.length, t = (o) => o.elements[e(o) - 1];
return {
size: size2,
top: top2,
push: push2,
open: open2,
close: close2
size: e,
top: t,
push: (o) => (c) => {
var i;
(i = t(o)) == null || i.push(c);
},
open: (o) => (c) => {
o.elements.push(c);
},
close: (o) => {
const c = o.elements.pop();
if (!c)
throw v();
return c;
}
};
};
const pushElement$1 = (element, node, ...rest) => {
element.content.push(node, ...rest);
};
const popElement$1 = (element) => element.content.pop();
const createElement$1 = (type, content, attrs) => {
const element = {
type,
content,
attrs,
push: (...args) => pushElement$1(element, ...args),
pop: () => popElement$1(element)
}, q = (e, t, ...s) => {
e.content.push(t, ...s);
}, B = (e) => e.content.pop(), C = (e, t, s) => {
const n = {
type: e,
content: t,
attrs: s,
push: (...r) => q(n, ...r),
pop: () => B(n)
};
return element;
};
const { size: size$1, push: push$1, top, open: open$1, close: close$1 } = getStackUtil();
const hasText = (node) => node.isText;
const maybeMerge = (schema, a, b) => {
if (hasText(a) && hasText(b) && Mark.sameSet(a.marks, b.marks)) {
return schema.text(a.text + b.text, a.marks);
}
return;
};
const openNode$1 = (ctx) => (nodeType, attrs) => open$1(ctx)(createElement$1(nodeType, [], attrs));
const addNode$1 = (ctx) => (nodeType, attrs, content) => {
const node = nodeType.createAndFill(attrs, content, ctx.marks);
if (!node)
throw createNodeInParserFail(nodeType, attrs, content);
push$1(ctx)(node);
return node;
};
const closeNode$1 = (ctx) => () => {
ctx.marks = Mark.none;
const element = close$1(ctx);
return addNode$1(ctx)(element.type, element.attrs, element.content);
};
const openMark$1 = (ctx) => (markType, attrs) => {
const mark = markType.create(attrs);
ctx.marks = mark.addToSet(ctx.marks);
};
const closeMark$1 = (ctx) => (markType) => {
ctx.marks = markType.removeFromSet(ctx.marks);
};
const addText = (ctx) => (text) => {
const topElement = top(ctx);
if (!topElement)
throw stackOverFlow();
const prevNode = topElement.pop();
const currNode = ctx.schema.text(text, ctx.marks);
if (!prevNode) {
topElement.push(currNode);
return n;
}, { size: G, push: H, top: K, open: L, close: Q } = w(), g = (e) => e.isText, V = (e, t, s) => {
if (g(t) && g(s) && $.sameSet(t.marks, s.marks))
return e.text(t.text + s.text, t.marks);
}, W = (e) => (t, s) => L(e)(C(t, [], s)), E = (e) => (t, s, n) => {
const r = t.createAndFill(s, n, e.marks);
if (!r)
throw x(t, s, n);
return H(e)(r), r;
}, T = (e) => () => {
e.marks = $.none;
const t = Q(e);
return E(e)(t.type, t.attrs, t.content);
}, X = (e) => (t, s) => {
const n = t.create(s);
e.marks = n.addToSet(e.marks);
}, Y = (e) => (t) => {
e.marks = t.removeFromSet(e.marks);
}, Z = (e) => (t) => {
const s = K(e);
if (!s)
throw v();
const n = s.pop(), r = e.schema.text(t, e.marks);
if (!n) {
s.push(r);
return;
}
const merged = maybeMerge(ctx.schema, prevNode, currNode);
if (merged) {
topElement.push(merged);
const o = V(e.schema, n, r);
if (o) {
s.push(o);
return;
}
topElement.push(prevNode, currNode);
};
const build$1 = (ctx) => () => {
let doc = void 0;
do {
doc = closeNode$1(ctx)();
} while (size$1(ctx));
return doc;
};
const createStack$1 = (schema) => {
const ctx = {
s.push(n, r);
}, _ = (e) => () => {
let t;
do
t = T(e)();
while (G(e));
return t;
}, tt = (e) => {
const t = {
marks: [],
elements: [],
schema
schema: e
};
return {
build: build$1(ctx),
openMark: openMark$1(ctx),
closeMark: closeMark$1(ctx),
addText: addText(ctx),
openNode: openNode$1(ctx),
addNode: addNode$1(ctx),
closeNode: closeNode$1(ctx)
build: _(t),
openMark: X(t),
closeMark: Y(t),
addText: Z(t),
openNode: W(t),
addNode: E(t),
closeNode: T(t)
};
};
class State$1 {
constructor(stack, schema, specMap) {
__privateAdd(this, _matchTarget);
__privateAdd(this, _runNode);
this.stack = stack;
this.schema = schema;
this.specMap = specMap;
this.run = (remark, markdown) => {
const tree = remark.runSync(remark.parse(markdown));
this.next(tree);
return this;
};
this.next = (nodes = []) => {
[nodes].flat().forEach((node) => __privateMethod(this, _runNode, runNode_fn).call(this, node));
return this;
};
this.toDoc = () => this.stack.build();
this.injectRoot = (node, nodeType, attrs) => {
this.stack.openNode(nodeType, attrs);
this.next(node.children);
return this;
};
this.addText = (text = "") => {
this.stack.addText(text);
return this;
};
this.addNode = (...args) => {
this.stack.addNode(...args);
return this;
};
this.openNode = (...args) => {
this.stack.openNode(...args);
return this;
};
this.closeNode = (...args) => {
this.stack.closeNode(...args);
return this;
};
this.openMark = (...args) => {
this.stack.openMark(...args);
return this;
};
this.closeMark = (...args) => {
this.stack.closeMark(...args);
return this;
};
var d, b, l, P;
class et {
constructor(t, s, n) {
h(this, d);
h(this, l);
this.stack = t, this.schema = s, this.specMap = n, this.run = (r, o) => {
const c = r.runSync(r.parse(o));
return this.next(c), this;
}, this.next = (r = []) => ([r].flat().forEach((o) => a(this, l, P).call(this, o)), this), this.toDoc = () => this.stack.build(), this.injectRoot = (r, o, c) => (this.stack.openNode(o, c), this.next(r.children), this), this.addText = (r = "") => (this.stack.addText(r), this), this.addNode = (...r) => (this.stack.addNode(...r), this), this.openNode = (...r) => (this.stack.openNode(...r), this), this.closeNode = (...r) => (this.stack.closeNode(...r), this), this.openMark = (...r) => (this.stack.openMark(...r), this), this.closeMark = (...r) => (this.stack.closeMark(...r), this);
}
}
_matchTarget = new WeakSet();
matchTarget_fn = function(node) {
const result = Object.values(this.specMap).find((x) => x.match(node));
if (!result)
throw parserMatchError(node);
return result;
d = new WeakSet(), b = function(t) {
const s = Object.values(this.specMap).find((n) => n.match(t));
if (!s)
throw A(t);
return s;
}, l = new WeakSet(), P = function(t) {
const { key: s, runner: n, is: r } = a(this, d, b).call(this, t), o = this.schema[r === "node" ? "nodes" : "marks"][s];
n(this, t, o);
};
_runNode = new WeakSet();
runNode_fn = function(node) {
const { key, runner, is } = __privateMethod(this, _matchTarget, matchTarget_fn).call(this, node);
const proseType = this.schema[is === "node" ? "nodes" : "marks"][key];
runner(this, node, proseType);
};
const createParser = (schema, specMap, remark) => (text) => {
const state = new State$1(createStack$1(schema), schema, specMap);
state.run(remark, text);
return state.toDoc();
};
const pushElement = (element, node, ...rest) => {
if (!element.children) {
element.children = [];
}
element.children.push(node, ...rest);
};
const popElement = (element) => {
var _a;
return (_a = element.children) == null ? void 0 : _a.pop();
};
const createElement = (type, children, value, props = {}) => {
const element = {
type,
children,
props,
value,
push: (...args) => pushElement(element, ...args),
pop: () => popElement(element)
const Mt = (e, t, s) => (n) => {
const r = new et(tt(e), e, t);
return r.run(s, n), r.toDoc();
}, st = (e, t, ...s) => {
e.children || (e.children = []), e.children.push(t, ...s);
}, rt = (e) => {
var t;
return (t = e.children) == null ? void 0 : t.pop();
}, z = (e, t, s, n = {}) => {
const r = {
type: e,
children: t,
props: n,
value: s,
push: (...o) => st(r, ...o),
pop: () => rt(r)
};
return element;
};
const { size, push, open, close } = getStackUtil();
const maybeMergeChildren = (element) => {
const { children } = element;
if (!children)
return element;
element.children = children.reduce((nextChildren, child, index) => {
if (index === 0) {
return [child];
}
const last = nextChildren[nextChildren.length - 1];
if (last && child["isMark"] && child.type === last.type) {
const _a = child, { children: currChildren } = _a, currRest = __objRest(_a, ["children"]);
const _b = last, { children: prevChildren } = _b, prevRest = __objRest(_b, ["children"]);
if (currChildren && prevChildren && JSON.stringify(currRest) === JSON.stringify(prevRest)) {
const next = __spreadProps(__spreadValues({}, prevRest), {
children: [...prevChildren, ...currChildren]
});
return nextChildren.slice(0, -1).concat(maybeMergeChildren(next));
return r;
}, { size: nt, push: ot, open: ct, close: it } = w(), O = (e) => {
const { children: t } = e;
return t && (e.children = t.reduce((s, n, r) => {
if (r === 0)
return [n];
const o = s[s.length - 1];
if (o && n.isMark && n.type === o.type) {
const { children: c, ...i } = n, { children: y, ...S } = o;
if (c && y && JSON.stringify(i) === JSON.stringify(S)) {
const D = {
...S,
children: [...y, ...c]
};
return s.slice(0, -1).concat(O(D));
}
}
return nextChildren.concat(child);
}, []);
return element;
};
const createMarkdownNode = (element) => {
const node = __spreadProps(__spreadValues({}, element.props), {
type: element.type
});
if (element.children) {
node.children = element.children;
}
if (element.value) {
node["value"] = element.value;
}
return node;
};
const openNode = (ctx) => (type, value, props) => open(ctx)(createElement(type, [], value, props));
const addNode = (ctx) => (type, children, value, props) => {
const element = createElement(type, children, value, props);
const node = maybeMergeChildren(createMarkdownNode(element));
push(ctx)(node);
return node;
};
const closeNode = (ctx) => () => {
const element = close(ctx);
return addNode(ctx)(element.type, element.children, element.value, element.props);
};
const openMark = (ctx) => (mark, type, value, props) => {
const isIn = mark.isInSet(ctx.marks);
if (isIn) {
return;
}
ctx.marks = mark.addToSet(ctx.marks);
openNode(ctx)(type, value, __spreadProps(__spreadValues({}, props), { isMark: true }));
};
const closeMark = (ctx) => (mark) => {
if (!mark.isInSet(ctx.marks))
return null;
ctx.marks = mark.type.removeFromSet(ctx.marks);
return closeNode(ctx)();
};
const build = (ctx) => () => {
let doc = null;
do {
doc = closeNode(ctx)();
} while (size(ctx));
return doc;
};
const createStack = () => {
const ctx = {
return s.concat(n);
}, [])), e;
}, at = (e) => {
const t = {
...e.props,
type: e.type
};
return e.children && (t.children = e.children), e.value && (t.value = e.value), t;
}, F = (e) => (t, s, n) => ct(e)(z(t, [], s, n)), I = (e) => (t, s, n, r) => {
const o = z(t, s, n, r), c = O(at(o));
return ot(e)(c), c;
}, M = (e) => () => {
const t = it(e);
return I(e)(t.type, t.children, t.value, t.props);
}, ht = (e) => (t, s, n, r) => {
t.isInSet(e.marks) || (e.marks = t.addToSet(e.marks), F(e)(s, n, { ...r, isMark: !0 }));
}, ut = (e) => (t) => t.isInSet(e.marks) ? (e.marks = t.type.removeFromSet(e.marks), M(e)()) : null, pt = (e) => () => {
let t = null;
do
t = M(e)();
while (nt(e));
return t;
}, dt = () => {
const e = {
marks: [],

@@ -316,95 +180,55 @@ elements: []

return {
build: build(ctx),
openMark: openMark(ctx),
closeMark: closeMark(ctx),
openNode: openNode(ctx),
addNode: addNode(ctx),
closeNode: closeNode(ctx)
build: pt(e),
openMark: ht(e),
closeMark: ut(e),
openNode: F(e),
addNode: I(e),
closeNode: M(e)
};
};
const isFragment = (x) => Object.prototype.hasOwnProperty.call(x, "size");
class State {
constructor(stack, schema, specMap) {
__privateAdd(this, _matchTarget2);
__privateAdd(this, _runProseNode);
__privateAdd(this, _runProseMark);
__privateAdd(this, _runNode2);
this.stack = stack;
this.schema = schema;
this.specMap = specMap;
this.toString = (remark) => remark.stringify(this.stack.build());
this.next = (nodes) => {
if (isFragment(nodes)) {
nodes.forEach((node) => {
__privateMethod(this, _runNode2, runNode_fn2).call(this, node);
});
return this;
}
__privateMethod(this, _runNode2, runNode_fn2).call(this, nodes);
return this;
};
this.addNode = (...args) => {
this.stack.addNode(...args);
return this;
};
this.openNode = (...args) => {
this.stack.openNode(...args);
return this;
};
this.closeNode = (...args) => {
this.stack.closeNode(...args);
return this;
};
this.withMark = (...args) => {
this.stack.openMark(...args);
return this;
};
}, lt = (e) => Object.prototype.hasOwnProperty.call(e, "size");
var u, N, k, j, m, R, p, f;
class kt {
constructor(t, s, n) {
h(this, u);
h(this, k);
h(this, m);
h(this, p);
this.stack = t, this.schema = s, this.specMap = n, this.toString = (r) => r.stringify(this.stack.build()), this.next = (r) => lt(r) ? (r.forEach((o) => {
a(this, p, f).call(this, o);
}), this) : (a(this, p, f).call(this, r), this), this.addNode = (...r) => (this.stack.addNode(...r), this), this.openNode = (...r) => (this.stack.openNode(...r), this), this.closeNode = (...r) => (this.stack.closeNode(...r), this), this.withMark = (...r) => (this.stack.openMark(...r), this);
}
run(tree) {
this.next(tree);
return this;
run(t) {
return this.next(t), this;
}
}
_matchTarget2 = new WeakSet();
matchTarget_fn2 = function(node) {
const result = Object.entries(this.specMap).map(([key, spec]) => __spreadValues({
key
}, spec)).find((x) => x.match(node));
if (!result)
throw serializerMatchError(node.type);
return result;
u = new WeakSet(), N = function(t) {
const s = Object.entries(this.specMap).map(([n, r]) => ({
key: n,
...r
})).find((n) => n.match(t));
if (!s)
throw U(t.type);
return s;
}, k = new WeakSet(), j = function(t) {
const { runner: s } = a(this, u, N).call(this, t);
s(this, t);
}, m = new WeakSet(), R = function(t, s) {
const { runner: n } = a(this, u, N).call(this, t);
return n(this, t, s);
}, p = new WeakSet(), f = function(t) {
const { marks: s } = t, n = (c) => {
var i;
return (i = c.type.spec.priority) != null ? i : 50;
};
[...s].sort((c, i) => n(c) - n(i)).every((c) => !a(this, m, R).call(this, c, t)) && a(this, k, j).call(this, t), s.forEach((c) => this.stack.closeMark(c));
};
_runProseNode = new WeakSet();
runProseNode_fn = function(node) {
const { runner } = __privateMethod(this, _matchTarget2, matchTarget_fn2).call(this, node);
runner(this, node);
const yt = (e, t, s) => (n) => {
const r = new kt(dt(), e, t);
return r.run(n), r.toString(s);
};
_runProseMark = new WeakSet();
runProseMark_fn = function(mark, node) {
const { runner } = __privateMethod(this, _matchTarget2, matchTarget_fn2).call(this, mark);
return runner(this, mark, node);
export {
Mt as createParser,
yt as createSerializer,
w as getStackUtil
};
_runNode2 = new WeakSet();
runNode_fn2 = function(node) {
const { marks } = node;
const getPriority = (x) => {
var _a;
return (_a = x.type.spec["priority"]) != null ? _a : 50;
};
const tmp = [...marks].sort((a, b) => getPriority(a) - getPriority(b));
const unPreventNext = tmp.every((mark) => !__privateMethod(this, _runProseMark, runProseMark_fn).call(this, mark, node));
if (unPreventNext) {
__privateMethod(this, _runProseNode, runProseNode_fn).call(this, node);
}
marks.forEach((mark) => this.stack.closeMark(mark));
};
const createSerializer = (schema, specMap, remark) => (content) => {
const state = new State(createStack(), schema, specMap);
state.run(content);
return state.toString(remark);
};
if (globalThis.process && !globalThis.process.env) {
globalThis.process.env = {};
}
export { createParser, createSerializer, getStackUtil };
//# sourceMappingURL=index.es.js.map

@@ -10,3 +10,3 @@ import { Node, NodeType } from '@milkdown/prose/model';

};
export declare const createElement: (type: NodeType, content: Node[], attrs?: Attrs | undefined) => StackElement;
export declare const createElement: (type: NodeType, content: Node[], attrs?: Attrs) => StackElement;
//# sourceMappingURL=stack-element.d.ts.map

@@ -5,7 +5,7 @@ import { MarkType, Node, NodeType, Schema } from '@milkdown/prose/model';

build: () => Node;
openMark: (markType: MarkType, attrs?: Attrs | undefined) => void;
openMark: (markType: MarkType, attrs?: Attrs) => void;
closeMark: (markType: MarkType) => void;
addText: (text: string) => void;
openNode: (nodeType: NodeType, attrs?: Attrs | undefined) => void;
addNode: (nodeType: NodeType, attrs?: Attrs | undefined, content?: Node[] | undefined) => Node;
openNode: (nodeType: NodeType, attrs?: Attrs) => void;
addNode: (nodeType: NodeType, attrs?: Attrs, content?: Node[]) => Node;
closeNode: () => Node;

@@ -12,0 +12,0 @@ };

@@ -45,3 +45,3 @@ import type { MarkType, Node, NodeType, Schema } from '@milkdown/prose/model';

*/
injectRoot: (node: MarkdownNode, nodeType: NodeType, attrs?: Attrs | undefined) => this;
injectRoot: (node: MarkdownNode, nodeType: NodeType, attrs?: Attrs) => this;
/**

@@ -48,0 +48,0 @@ * Add a text type prosemirror node.

@@ -11,3 +11,3 @@ import type { MarkdownNode } from '..';

};
export declare const createElement: (type: string, children?: MarkdownNode[] | undefined, value?: string | undefined, props?: JSONRecord) => StackElement;
export declare const createElement: (type: string, children?: MarkdownNode[], value?: string, props?: JSONRecord) => StackElement;
//# sourceMappingURL=stack-element.d.ts.map
{
"name": "@milkdown/transformer",
"version": "6.2.0",
"version": "6.3.0",
"type": "module",

@@ -20,3 +20,3 @@ "main": "./lib/index.es.js",

"devDependencies": {
"@milkdown/prose": "6.2.0"
"@milkdown/prose": "6.3.0"
},

@@ -27,7 +27,7 @@ "peerDependencies": {

"dependencies": {
"@milkdown/exception": "6.2.0",
"@milkdown/exception": "6.3.0",
"@types/mdast": "^3.0.10",
"@types/unist": "^2.0.6",
"remark": "^14.0.1",
"tslib": "^2.3.1",
"tslib": "^2.4.0",
"unified": "^10.1.0"

@@ -34,0 +34,0 @@ },

/* Copyright 2021, Milkdown by Mirone. */
/**
* This hack is meant to fix https://github.com/lukeed/kleur/pull/54
* kleur is a dependency of remark.
*/
if (globalThis.process && !globalThis.process.env) {
globalThis.process.env = {};
}
export * from './parser';

@@ -12,0 +4,0 @@ export * from './serializer';

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

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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc