@milkdown/plugin-emoji 7.1.0 → 7.1.2-next.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/__internal__/parse.d.ts.map +1 -0
- package/lib/__internal__/remark-twemoji.d.ts.map +1 -0
- package/lib/__internal__/with-meta.d.ts +3 -0
- package/lib/__internal__/with-meta.d.ts.map +1 -0
- package/lib/index.d.ts.map +1 -1
- package/lib/index.es.js +97 -65
- package/lib/index.es.js.map +1 -1
- package/package.json +12 -12
- package/src/__internal__/with-meta.ts +16 -0
- package/src/index.ts +28 -2
- package/lib/parse.d.ts.map +0 -1
- package/lib/remark-twemoji.d.ts.map +0 -1
- /package/lib/{parse.d.ts → __internal__/parse.d.ts} +0 -0
- /package/lib/{remark-twemoji.d.ts → __internal__/remark-twemoji.d.ts} +0 -0
- /package/src/{parse.ts → __internal__/parse.ts} +0 -0
- /package/src/{remark-twemoji.ts → __internal__/remark-twemoji.ts} +0 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"parse.d.ts","sourceRoot":"","sources":["../../src/__internal__/parse.ts"],"names":[],"mappings":"AAKA,eAAO,MAAM,KAAK,UAAW,MAAM,mBAAmB,cAAc,KAAG,MAC6E,CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"remark-twemoji.d.ts","sourceRoot":"","sources":["../../src/__internal__/remark-twemoji.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,uBAAuB,CAAA;AAqCzD,eAAO,MAAM,aAAa,EAAE,CAAC,cAAc,CAAC,EAAE,cAAc,KAAK,YA8BhE,CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"with-meta.d.ts","sourceRoot":"","sources":["../../src/__internal__/with-meta.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,IAAI,EAAE,cAAc,EAAE,MAAM,eAAe,CAAA;AAEzD,eAAO,MAAM,QAAQ,8CAEb,QAAQ,IAAI,CAAC,GAAG,KAAK,IAAI,EAAE,aAAa,CAAC,MAUhD,CAAA"}
|
package/lib/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,eAAe,CAAA;AAOnD,OAAO,KAAK,OAAO,MAAM,SAAS,CAAA;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,eAAe,CAAA;AAOnD,OAAO,KAAK,OAAO,MAAM,SAAS,CAAA;AAMlC,KAAK,cAAc,GAAG,OAAO,CAAC,UAAU,CAAC,OAAO,OAAO,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,EAAE,QAAQ,GAAG,SAAS,CAAC,CAAA;AAGxF,MAAM,WAAW,WAAW;IAC1B,cAAc,CAAC,EAAE,cAAc,CAAA;CAChC;AAGD,eAAO,MAAM,WAAW,4DAAsD,CAAA;AAM9E,eAAO,MAAM,SAAS,qCAGnB,CAAA;AAMH,eAAO,MAAM,WAAW,gDA+CrB,CAAA;AAWH,eAAO,MAAM,oBAAoB,sCAc9B,CAAA;AAOH,eAAO,MAAM,iBAAiB,mCAA6C,CAAA;AAO3E,eAAO,MAAM,mBAAmB,mCAAyE,CAAA;AAOzG,eAAO,MAAM,KAAK,EAAE,cAAc,EAO1B,CAAA"}
|
package/lib/index.es.js
CHANGED
|
@@ -1,51 +1,64 @@
|
|
|
1
|
-
import { expectDomTypeError as
|
|
2
|
-
import { InputRule as
|
|
3
|
-
import { $ctx as
|
|
4
|
-
import
|
|
5
|
-
import
|
|
6
|
-
import
|
|
7
|
-
import
|
|
8
|
-
const
|
|
9
|
-
function
|
|
10
|
-
return
|
|
11
|
-
function
|
|
12
|
-
if (
|
|
13
|
-
const
|
|
14
|
-
for (let
|
|
15
|
-
const l = t.children[
|
|
1
|
+
import { expectDomTypeError as N } from "@milkdown/exception";
|
|
2
|
+
import { InputRule as v } from "@milkdown/prose/inputrules";
|
|
3
|
+
import { $ctx as R, $nodeAttr as T, $nodeSchema as C, $inputRule as A, $remark as y } from "@milkdown/utils";
|
|
4
|
+
import I from "node-emoji";
|
|
5
|
+
import L from "remark-emoji";
|
|
6
|
+
import O from "twemoji";
|
|
7
|
+
import P from "emoji-regex";
|
|
8
|
+
const $ = (n) => ({ title: n }), w = (n, e) => O.parse(n, { attributes: $, base: "https://cdn.jsdelivr.net/gh/twitter/twemoji/assets/", ...e }), g = P(), b = (n) => !!n.children, H = (n) => !!n.value;
|
|
9
|
+
function S(n, e) {
|
|
10
|
+
return m(n, 0, null)[0];
|
|
11
|
+
function m(t, i, r) {
|
|
12
|
+
if (b(t)) {
|
|
13
|
+
const s = [];
|
|
14
|
+
for (let o = 0, c = t.children.length; o < c; o++) {
|
|
15
|
+
const l = t.children[o];
|
|
16
16
|
if (l) {
|
|
17
|
-
const
|
|
18
|
-
if (
|
|
19
|
-
for (let
|
|
20
|
-
const
|
|
21
|
-
|
|
17
|
+
const j = m(l, o, t);
|
|
18
|
+
if (j)
|
|
19
|
+
for (let f = 0, M = j.length; f < M; f++) {
|
|
20
|
+
const d = j[f];
|
|
21
|
+
d && s.push(d);
|
|
22
22
|
}
|
|
23
23
|
}
|
|
24
24
|
}
|
|
25
|
-
t.children =
|
|
25
|
+
t.children = s;
|
|
26
26
|
}
|
|
27
|
-
return e(t,
|
|
27
|
+
return e(t, i, r);
|
|
28
28
|
}
|
|
29
29
|
}
|
|
30
|
-
const
|
|
31
|
-
function e(
|
|
32
|
-
|
|
33
|
-
if (!
|
|
30
|
+
const D = (n) => () => {
|
|
31
|
+
function e(m) {
|
|
32
|
+
S(m, (t) => {
|
|
33
|
+
if (!H(t))
|
|
34
34
|
return [t];
|
|
35
|
-
const
|
|
36
|
-
let
|
|
37
|
-
for (;
|
|
38
|
-
const { index: c } =
|
|
39
|
-
l && (c > 0 &&
|
|
35
|
+
const i = t.value, r = [];
|
|
36
|
+
let s, o = i;
|
|
37
|
+
for (; s = g.exec(o); ) {
|
|
38
|
+
const { index: c } = s, l = s[0];
|
|
39
|
+
l && (c > 0 && r.push({ ...t, value: o.slice(0, c) }), r.push({ ...t, value: w(l, n), type: "emoji" }), o = o.slice(c + l.length)), g.lastIndex = 0;
|
|
40
40
|
}
|
|
41
|
-
return
|
|
41
|
+
return o.length && r.push({ ...t, value: o }), r;
|
|
42
42
|
});
|
|
43
43
|
}
|
|
44
44
|
return e;
|
|
45
|
-
},
|
|
45
|
+
}, a = (n, e) => (Object.assign(n, {
|
|
46
|
+
meta: {
|
|
47
|
+
package: "@milkdown/plugin-emoji",
|
|
48
|
+
...e
|
|
49
|
+
}
|
|
50
|
+
}), n), u = R({}, "emojiConfig");
|
|
51
|
+
a(u, {
|
|
52
|
+
displayName: "Ctx<emojiConfig>"
|
|
53
|
+
});
|
|
54
|
+
const h = T("emoji", () => ({
|
|
46
55
|
span: {},
|
|
47
56
|
img: {}
|
|
48
|
-
}))
|
|
57
|
+
}));
|
|
58
|
+
a(h, {
|
|
59
|
+
displayName: "Attr<emoji>"
|
|
60
|
+
});
|
|
61
|
+
const p = C("emoji", (n) => ({
|
|
49
62
|
group: "inline",
|
|
50
63
|
inline: !0,
|
|
51
64
|
attrs: {
|
|
@@ -58,57 +71,76 @@ const I = (n) => () => {
|
|
|
58
71
|
tag: 'span[data-type="emoji"]',
|
|
59
72
|
getAttrs: (e) => {
|
|
60
73
|
if (!(e instanceof HTMLElement))
|
|
61
|
-
throw
|
|
74
|
+
throw N(e);
|
|
62
75
|
return { html: e.innerHTML };
|
|
63
76
|
}
|
|
64
77
|
}
|
|
65
78
|
],
|
|
66
79
|
toDOM: (e) => {
|
|
67
|
-
var
|
|
68
|
-
const
|
|
80
|
+
var r;
|
|
81
|
+
const m = n.get(h.key)(e), t = document.createElement("span");
|
|
69
82
|
t.innerHTML = e.attrs.html;
|
|
70
|
-
const
|
|
71
|
-
return t.remove(),
|
|
83
|
+
const i = (r = t.firstElementChild) == null ? void 0 : r.cloneNode();
|
|
84
|
+
return t.remove(), i && i instanceof HTMLElement && Object.entries(m.img).forEach(([s, o]) => i.setAttribute(s, o)), ["span", { ...m.container, "data-type": "emoji" }, i];
|
|
72
85
|
},
|
|
73
86
|
parseMarkdown: {
|
|
74
87
|
match: ({ type: e }) => e === "emoji",
|
|
75
|
-
runner: (e,
|
|
76
|
-
e.addNode(t, { html:
|
|
88
|
+
runner: (e, m, t) => {
|
|
89
|
+
e.addNode(t, { html: m.value });
|
|
77
90
|
}
|
|
78
91
|
},
|
|
79
92
|
toMarkdown: {
|
|
80
93
|
match: (e) => e.type.name === "emoji",
|
|
81
|
-
runner: (e,
|
|
94
|
+
runner: (e, m) => {
|
|
82
95
|
const t = document.createElement("span");
|
|
83
|
-
t.innerHTML =
|
|
84
|
-
const
|
|
85
|
-
t.remove(), e.addNode("text", void 0,
|
|
96
|
+
t.innerHTML = m.attrs.html;
|
|
97
|
+
const i = t.querySelector("img"), r = (i == null ? void 0 : i.title) || (i == null ? void 0 : i.alt);
|
|
98
|
+
t.remove(), e.addNode("text", void 0, r);
|
|
86
99
|
}
|
|
87
100
|
}
|
|
88
|
-
}))
|
|
89
|
-
|
|
90
|
-
|
|
101
|
+
}));
|
|
102
|
+
a(p.node, {
|
|
103
|
+
displayName: "NodeSchema<emoji>"
|
|
104
|
+
});
|
|
105
|
+
a(p.ctx, {
|
|
106
|
+
displayName: "NodeSchemaCtx<emoji>"
|
|
107
|
+
});
|
|
108
|
+
const k = A((n) => new v(/(:([^:\s]+):)$/, (e, m, t, i) => {
|
|
109
|
+
const r = m[0];
|
|
110
|
+
if (!r)
|
|
91
111
|
return null;
|
|
92
|
-
const
|
|
93
|
-
if (!
|
|
112
|
+
const s = I.get(r);
|
|
113
|
+
if (!s || r.includes(s))
|
|
94
114
|
return null;
|
|
95
|
-
const
|
|
96
|
-
return e.tr.setMeta("emoji", !0).replaceRangeWith(t,
|
|
97
|
-
}))
|
|
98
|
-
|
|
115
|
+
const o = w(s, n.get(u.key).twemojiOptions);
|
|
116
|
+
return e.tr.setMeta("emoji", !0).replaceRangeWith(t, i, p.type().create({ html: o })).scrollIntoView();
|
|
117
|
+
}));
|
|
118
|
+
a(k, {
|
|
119
|
+
displayName: "InputRule<insertEmojiInputRule>"
|
|
120
|
+
});
|
|
121
|
+
const x = y(() => L);
|
|
122
|
+
a(x, {
|
|
123
|
+
displayName: "Remark<remarkEmojiPlugin>"
|
|
124
|
+
});
|
|
125
|
+
const E = y((n) => D(n.get(u.key).twemojiOptions));
|
|
126
|
+
a(E, {
|
|
127
|
+
displayName: "Remark<remarkTwemojiPlugin>"
|
|
128
|
+
});
|
|
129
|
+
const J = [
|
|
130
|
+
h,
|
|
131
|
+
u,
|
|
132
|
+
x,
|
|
133
|
+
E,
|
|
99
134
|
p,
|
|
100
|
-
|
|
101
|
-
N,
|
|
102
|
-
w,
|
|
103
|
-
P
|
|
135
|
+
k
|
|
104
136
|
].flat();
|
|
105
137
|
export {
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
138
|
+
J as emoji,
|
|
139
|
+
h as emojiAttr,
|
|
140
|
+
u as emojiConfig,
|
|
141
|
+
p as emojiSchema,
|
|
142
|
+
k as insertEmojiInputRule,
|
|
143
|
+
x as remarkEmojiPlugin,
|
|
144
|
+
E as remarkTwemojiPlugin
|
|
113
145
|
};
|
|
114
146
|
//# sourceMappingURL=index.es.js.map
|
package/lib/index.es.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.es.js","sources":["../src/parse.ts","../src/remark-twemoji.ts","../src/index.ts"],"sourcesContent":["/* Copyright 2021, Milkdown by Mirone. */\nimport twemoji from 'twemoji'\n\nconst setAttr = (text: string) => ({ title: text })\n\nexport const parse = (emoji: string, twemojiOptions?: TwemojiOptions): string =>\n twemoji.parse(emoji, { attributes: setAttr, base: 'https://cdn.jsdelivr.net/gh/twitter/twemoji/assets/', ...twemojiOptions }) as unknown as string\n","/* Copyright 2021, Milkdown by Mirone. */\nimport type { RemarkPlugin } from '@milkdown/transformer'\nimport emojiRegex from 'emoji-regex'\nimport type { Literal, Node, Parent } from 'unist'\n\nimport { parse } from './parse'\n\nconst regex = emojiRegex()\n\nconst isParent = (node: Node): node is Parent => !!(node as Parent).children\nconst isLiteral = (node: Node): node is Literal => !!(node as Literal).value\n\nfunction flatMap(ast: Node, fn: (node: Node, index: number, parent: Node | null) => Node[]) {\n return transform(ast, 0, null)[0]\n\n function transform(node: Node, index: number, parent: Node | null) {\n if (isParent(node)) {\n const out = []\n for (let i = 0, n = node.children.length; i < n; i++) {\n const nthChild = node.children[i]\n if (nthChild) {\n const xs = transform(nthChild, i, node)\n if (xs) {\n for (let j = 0, m = xs.length; j < m; j++) {\n const item = xs[j]\n if (item)\n out.push(item)\n }\n }\n }\n }\n node.children = out\n }\n\n return fn(node, index, parent)\n }\n}\n\nexport const twemojiPlugin: (twemojiOptions?: TwemojiOptions) => RemarkPlugin = twemojiOptions => () => {\n function transformer(tree: Node) {\n flatMap(tree, (node) => {\n if (!isLiteral(node))\n return [node]\n\n const value = node.value as string\n const output: Literal<string>[] = []\n let match\n let str = value\n // eslint-disable-next-line no-cond-assign\n while ((match = regex.exec(str))) {\n const { index } = match\n const emoji = match[0]\n if (emoji) {\n if (index > 0)\n output.push({ ...node, value: str.slice(0, index) })\n\n output.push({ ...node, value: parse(emoji, twemojiOptions), type: 'emoji' })\n str = str.slice(index + emoji.length)\n }\n regex.lastIndex = 0\n }\n if (str.length)\n output.push({ ...node, value: str })\n\n return output\n })\n }\n return transformer\n}\n","/* Copyright 2021, Milkdown by Mirone. */\nimport type { MilkdownPlugin } from '@milkdown/ctx'\nimport type { RemarkPlugin } from '@milkdown/transformer'\nimport { expectDomTypeError } from '@milkdown/exception'\nimport { InputRule } from '@milkdown/prose/inputrules'\nimport { $ctx, $inputRule, $nodeAttr, $nodeSchema, $remark } from '@milkdown/utils'\nimport nodeEmoji from 'node-emoji'\nimport remarkEmoji from 'remark-emoji'\nimport type Twemoji from 'twemoji'\n\nimport { parse } from './parse'\nimport { twemojiPlugin } from './remark-twemoji'\n\ntype TwemojiOptions = Exclude<Parameters<typeof Twemoji.parse>[1], Function | undefined>\n\n/// @internal\nexport interface EmojiConfig {\n twemojiOptions?: TwemojiOptions\n}\n\n/// A slice that contains [options for twemoji](https://github.com/twitter/twemoji#object-as-parameter).\nexport const emojiConfig = $ctx<EmojiConfig, 'emojiConfig'>({}, 'emojiConfig')\n\n/// HTML attributes for emoji node.\nexport const emojiAttr = $nodeAttr('emoji', () => ({\n span: {},\n img: {},\n}))\n\n/// Schema for emoji node.\nexport const emojiSchema = $nodeSchema('emoji', ctx => ({\n group: 'inline',\n inline: true,\n attrs: {\n html: {\n default: '',\n },\n },\n parseDOM: [\n {\n tag: 'span[data-type=\"emoji\"]',\n getAttrs: (dom) => {\n if (!(dom instanceof HTMLElement))\n throw expectDomTypeError(dom)\n\n return { html: dom.innerHTML }\n },\n },\n ],\n toDOM: (node) => {\n const attrs = ctx.get(emojiAttr.key)(node)\n const tmp = document.createElement('span')\n tmp.innerHTML = node.attrs.html\n const dom = tmp.firstElementChild?.cloneNode()\n tmp.remove()\n if (dom && dom instanceof HTMLElement)\n Object.entries<string>(attrs.img).forEach(([key, value]) => dom.setAttribute(key, value))\n\n return ['span', { ...attrs.container, 'data-type': 'emoji' }, dom]\n },\n parseMarkdown: {\n match: ({ type }) => type === 'emoji',\n runner: (state, node, type) => {\n state.addNode(type, { html: node.value as string })\n },\n },\n toMarkdown: {\n match: node => node.type.name === 'emoji',\n runner: (state, node) => {\n const span = document.createElement('span')\n span.innerHTML = node.attrs.html\n const img = span.querySelector('img')\n const title = img?.title || img?.alt\n span.remove()\n state.addNode('text', undefined, title)\n },\n },\n}))\n\n/// Input rule for inserting emoji.\n/// For example, `:smile:` will be replaced with `😄`.\nexport const insertEmojiInputRule = $inputRule(ctx => new InputRule(/(:([^:\\s]+):)$/, (state, match, start, end) => {\n const content = match[0]\n if (!content)\n return null\n const got = nodeEmoji.get(content)\n if (!got || content.includes(got))\n return null\n\n const html = parse(got, ctx.get(emojiConfig.key).twemojiOptions)\n\n return state.tr\n .setMeta('emoji', true)\n .replaceRangeWith(start, end, emojiSchema.type().create({ html }))\n .scrollIntoView()\n}))\n\n/// This plugin wraps [remark-emoji](https://github.com/rhysd/remark-emoji).\nexport const remarkEmojiPlugin = $remark(() => remarkEmoji as RemarkPlugin)\n\n/// This plugin is used for transforming emoji to twemoji.\nexport const remarkTwemojiPlugin = $remark(ctx => twemojiPlugin(ctx.get(emojiConfig.key).twemojiOptions))\n\n/// All plugins exported by this package.\nexport const emoji: MilkdownPlugin[] = [\n emojiAttr,\n emojiConfig,\n remarkEmojiPlugin,\n remarkTwemojiPlugin,\n emojiSchema,\n insertEmojiInputRule,\n].flat()\n"],"names":["setAttr","text","parse","emoji","twemojiOptions","twemoji","regex","emojiRegex","isParent","node","isLiteral","flatMap","ast","fn","transform","index","parent","out","n","nthChild","xs","j","m","item","twemojiPlugin","transformer","tree","value","output","match","str","emojiConfig","$ctx","emojiAttr","$nodeAttr","emojiSchema","$nodeSchema","ctx","dom","expectDomTypeError","attrs","tmp","_a","key","type","state","span","img","title","insertEmojiInputRule","$inputRule","InputRule","start","end","content","got","nodeEmoji","html","remarkEmojiPlugin","$remark","remarkEmoji","remarkTwemojiPlugin"],"mappings":";;;;;;;AAGA,MAAMA,IAAU,CAACC,OAAkB,EAAE,OAAOA,EAAK,IAEpCC,IAAQ,CAACC,GAAeC,MACnCC,EAAQ,MAAMF,GAAO,EAAE,YAAYH,GAAS,MAAM,uDAAuD,GAAGI,GAAgB,GCCxHE,IAAQC,EAAW,GAEnBC,IAAW,CAACC,MAA+B,CAAC,CAAEA,EAAgB,UA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","sources":["../src/__internal__/parse.ts","../src/__internal__/remark-twemoji.ts","../src/__internal__/with-meta.ts","../src/index.ts"],"sourcesContent":["/* Copyright 2021, Milkdown by Mirone. */\nimport twemoji from 'twemoji'\n\nconst setAttr = (text: string) => ({ title: text })\n\nexport const parse = (emoji: string, twemojiOptions?: TwemojiOptions): string =>\n twemoji.parse(emoji, { attributes: setAttr, base: 'https://cdn.jsdelivr.net/gh/twitter/twemoji/assets/', ...twemojiOptions }) as unknown as string\n","/* Copyright 2021, Milkdown by Mirone. */\nimport type { RemarkPlugin } from '@milkdown/transformer'\nimport emojiRegex from 'emoji-regex'\nimport type { Literal, Node, Parent } from 'unist'\n\nimport { parse } from './parse'\n\nconst regex = emojiRegex()\n\nconst isParent = (node: Node): node is Parent => !!(node as Parent).children\nconst isLiteral = (node: Node): node is Literal => !!(node as Literal).value\n\nfunction flatMap(ast: Node, fn: (node: Node, index: number, parent: Node | null) => Node[]) {\n return transform(ast, 0, null)[0]\n\n function transform(node: Node, index: number, parent: Node | null) {\n if (isParent(node)) {\n const out = []\n for (let i = 0, n = node.children.length; i < n; i++) {\n const nthChild = node.children[i]\n if (nthChild) {\n const xs = transform(nthChild, i, node)\n if (xs) {\n for (let j = 0, m = xs.length; j < m; j++) {\n const item = xs[j]\n if (item)\n out.push(item)\n }\n }\n }\n }\n node.children = out\n }\n\n return fn(node, index, parent)\n }\n}\n\nexport const twemojiPlugin: (twemojiOptions?: TwemojiOptions) => RemarkPlugin = twemojiOptions => () => {\n function transformer(tree: Node) {\n flatMap(tree, (node) => {\n if (!isLiteral(node))\n return [node]\n\n const value = node.value as string\n const output: Literal<string>[] = []\n let match\n let str = value\n // eslint-disable-next-line no-cond-assign\n while ((match = regex.exec(str))) {\n const { index } = match\n const emoji = match[0]\n if (emoji) {\n if (index > 0)\n output.push({ ...node, value: str.slice(0, index) })\n\n output.push({ ...node, value: parse(emoji, twemojiOptions), type: 'emoji' })\n str = str.slice(index + emoji.length)\n }\n regex.lastIndex = 0\n }\n if (str.length)\n output.push({ ...node, value: str })\n\n return output\n })\n }\n return transformer\n}\n","/* Copyright 2021, Milkdown by Mirone. */\nimport type { Meta, MilkdownPlugin } from '@milkdown/ctx'\n\nexport const withMeta = <T extends MilkdownPlugin>(\n plugin: T,\n meta: Partial<Meta> & Pick<Meta, 'displayName'>,\n): T => {\n Object.assign(plugin, {\n meta: {\n package: '@milkdown/plugin-emoji',\n ...meta,\n },\n })\n\n return plugin\n}\n","/* Copyright 2021, Milkdown by Mirone. */\nimport type { MilkdownPlugin } from '@milkdown/ctx'\nimport type { RemarkPlugin } from '@milkdown/transformer'\nimport { expectDomTypeError } from '@milkdown/exception'\nimport { InputRule } from '@milkdown/prose/inputrules'\nimport { $ctx, $inputRule, $nodeAttr, $nodeSchema, $remark } from '@milkdown/utils'\nimport nodeEmoji from 'node-emoji'\nimport remarkEmoji from 'remark-emoji'\nimport type Twemoji from 'twemoji'\n\nimport { parse } from './__internal__/parse'\nimport { twemojiPlugin } from './__internal__/remark-twemoji'\nimport { withMeta } from './__internal__/with-meta'\n\ntype TwemojiOptions = Exclude<Parameters<typeof Twemoji.parse>[1], Function | undefined>\n\n/// @internal\nexport interface EmojiConfig {\n twemojiOptions?: TwemojiOptions\n}\n\n/// A slice that contains [options for twemoji](https://github.com/twitter/twemoji#object-as-parameter).\nexport const emojiConfig = $ctx<EmojiConfig, 'emojiConfig'>({}, 'emojiConfig')\nwithMeta(emojiConfig, {\n displayName: 'Ctx<emojiConfig>',\n})\n\n/// HTML attributes for emoji node.\nexport const emojiAttr = $nodeAttr('emoji', () => ({\n span: {},\n img: {},\n}))\nwithMeta(emojiAttr, {\n displayName: 'Attr<emoji>',\n})\n\n/// Schema for emoji node.\nexport const emojiSchema = $nodeSchema('emoji', ctx => ({\n group: 'inline',\n inline: true,\n attrs: {\n html: {\n default: '',\n },\n },\n parseDOM: [\n {\n tag: 'span[data-type=\"emoji\"]',\n getAttrs: (dom) => {\n if (!(dom instanceof HTMLElement))\n throw expectDomTypeError(dom)\n\n return { html: dom.innerHTML }\n },\n },\n ],\n toDOM: (node) => {\n const attrs = ctx.get(emojiAttr.key)(node)\n const tmp = document.createElement('span')\n tmp.innerHTML = node.attrs.html\n const dom = tmp.firstElementChild?.cloneNode()\n tmp.remove()\n if (dom && dom instanceof HTMLElement)\n Object.entries<string>(attrs.img).forEach(([key, value]) => dom.setAttribute(key, value))\n\n return ['span', { ...attrs.container, 'data-type': 'emoji' }, dom]\n },\n parseMarkdown: {\n match: ({ type }) => type === 'emoji',\n runner: (state, node, type) => {\n state.addNode(type, { html: node.value as string })\n },\n },\n toMarkdown: {\n match: node => node.type.name === 'emoji',\n runner: (state, node) => {\n const span = document.createElement('span')\n span.innerHTML = node.attrs.html\n const img = span.querySelector('img')\n const title = img?.title || img?.alt\n span.remove()\n state.addNode('text', undefined, title)\n },\n },\n}))\n\nwithMeta(emojiSchema.node, {\n displayName: 'NodeSchema<emoji>',\n})\nwithMeta(emojiSchema.ctx, {\n displayName: 'NodeSchemaCtx<emoji>',\n})\n\n/// Input rule for inserting emoji.\n/// For example, `:smile:` will be replaced with `😄`.\nexport const insertEmojiInputRule = $inputRule(ctx => new InputRule(/(:([^:\\s]+):)$/, (state, match, start, end) => {\n const content = match[0]\n if (!content)\n return null\n const got = nodeEmoji.get(content)\n if (!got || content.includes(got))\n return null\n\n const html = parse(got, ctx.get(emojiConfig.key).twemojiOptions)\n\n return state.tr\n .setMeta('emoji', true)\n .replaceRangeWith(start, end, emojiSchema.type().create({ html }))\n .scrollIntoView()\n}))\n\nwithMeta(insertEmojiInputRule, {\n displayName: 'InputRule<insertEmojiInputRule>',\n})\n\n/// This plugin wraps [remark-emoji](https://github.com/rhysd/remark-emoji).\nexport const remarkEmojiPlugin = $remark(() => remarkEmoji as RemarkPlugin)\n\nwithMeta(remarkEmojiPlugin, {\n displayName: 'Remark<remarkEmojiPlugin>',\n})\n\n/// This plugin is used for transforming emoji to twemoji.\nexport const remarkTwemojiPlugin = $remark(ctx => twemojiPlugin(ctx.get(emojiConfig.key).twemojiOptions))\n\nwithMeta(remarkTwemojiPlugin, {\n displayName: 'Remark<remarkTwemojiPlugin>',\n})\n\n/// All plugins exported by this package.\nexport const emoji: MilkdownPlugin[] = [\n emojiAttr,\n emojiConfig,\n remarkEmojiPlugin,\n remarkTwemojiPlugin,\n emojiSchema,\n insertEmojiInputRule,\n].flat()\n"],"names":["setAttr","text","parse","emoji","twemojiOptions","twemoji","regex","emojiRegex","isParent","node","isLiteral","flatMap","ast","fn","transform","index","parent","out","i","n","nthChild","xs","j","m","item","twemojiPlugin","transformer","tree","value","output","match","str","withMeta","plugin","meta","emojiConfig","$ctx","emojiAttr","$nodeAttr","emojiSchema","$nodeSchema","ctx","dom","expectDomTypeError","attrs","tmp","_a","key","type","state","span","img","title","insertEmojiInputRule","$inputRule","InputRule","start","end","content","got","nodeEmoji","html","remarkEmojiPlugin","$remark","remarkEmoji","remarkTwemojiPlugin"],"mappings":";;;;;;;AAGA,MAAMA,IAAU,CAACC,OAAkB,EAAE,OAAOA,EAAK,IAEpCC,IAAQ,CAACC,GAAeC,MACnCC,EAAQ,MAAMF,GAAO,EAAE,YAAYH,GAAS,MAAM,uDAAuD,GAAGI,GAAgB,GCCxHE,IAAQC,EAAW,GAEnBC,IAAW,CAACC,MAA+B,CAAC,CAAEA,EAAgB,UAC9DC,IAAY,CAACD,MAAgC,CAAC,CAAEA,EAAiB;AAEvE,SAASE,EAAQC,GAAWC,GAAgE;AAC1F,SAAOC,EAAUF,GAAK,GAAG,IAAI,EAAE;AAEtB,WAAAE,EAAUL,GAAYM,GAAeC,GAAqB;AAC7D,QAAAR,EAASC,CAAI,GAAG;AAClB,YAAMQ,IAAM,CAAA;AACH,eAAAC,IAAI,GAAGC,IAAIV,EAAK,SAAS,QAAQS,IAAIC,GAAGD,KAAK;AAC9C,cAAAE,IAAWX,EAAK,SAASS;AAC/B,YAAIE,GAAU;AACZ,gBAAMC,IAAKP,EAAUM,GAAUF,GAAGT,CAAI;A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AAM9D,IAA0B;AAAA,EACrCkC;AAAA,EACAF;AAAA,EACA2B;AAAA,EACAG;AAAA,EACA1B;AAAA,EACAc;AACF,EAAE,KAAK;"}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@milkdown/plugin-emoji",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "7.1.0",
|
|
4
|
+
"version": "7.1.2-next.0",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": {
|
|
7
7
|
"type": "git",
|
|
@@ -20,28 +20,28 @@
|
|
|
20
20
|
"src"
|
|
21
21
|
],
|
|
22
22
|
"peerDependencies": {
|
|
23
|
-
"@milkdown/core": "^7.
|
|
24
|
-
"@milkdown/ctx": "^7.
|
|
25
|
-
"@milkdown/prose": "^7.
|
|
26
|
-
"@milkdown/transformer": "^7.
|
|
23
|
+
"@milkdown/core": "^7.1.2-next.0",
|
|
24
|
+
"@milkdown/ctx": "^7.1.2-next.0",
|
|
25
|
+
"@milkdown/prose": "^7.1.2-next.0",
|
|
26
|
+
"@milkdown/transformer": "^7.1.2-next.0"
|
|
27
27
|
},
|
|
28
28
|
"dependencies": {
|
|
29
29
|
"@types/node-emoji": "^1.8.1",
|
|
30
30
|
"emoji-regex": "^10.0.0",
|
|
31
31
|
"node-emoji": "^1.10.0",
|
|
32
32
|
"remark-emoji": "^3.0.1",
|
|
33
|
-
"tslib": "^2.
|
|
33
|
+
"tslib": "^2.5.0",
|
|
34
34
|
"twemoji": "^14.0.1",
|
|
35
35
|
"unist-util-visit": "^4.0.0",
|
|
36
|
-
"@milkdown/exception": "7.1.0",
|
|
37
|
-
"@milkdown/utils": "7.1.0"
|
|
36
|
+
"@milkdown/exception": "7.1.2-next.0",
|
|
37
|
+
"@milkdown/utils": "7.1.2-next.0"
|
|
38
38
|
},
|
|
39
39
|
"devDependencies": {
|
|
40
40
|
"@types/unist": "^2.0.6",
|
|
41
|
-
"@milkdown/core": "7.1.0",
|
|
42
|
-
"@milkdown/ctx": "7.1.0",
|
|
43
|
-
"@milkdown/prose": "7.1.0",
|
|
44
|
-
"@milkdown/transformer": "7.1.0"
|
|
41
|
+
"@milkdown/core": "7.1.2-next.0",
|
|
42
|
+
"@milkdown/ctx": "7.1.2-next.0",
|
|
43
|
+
"@milkdown/prose": "7.1.2-next.0",
|
|
44
|
+
"@milkdown/transformer": "7.1.2-next.0"
|
|
45
45
|
},
|
|
46
46
|
"nx": {
|
|
47
47
|
"targets": {
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/* Copyright 2021, Milkdown by Mirone. */
|
|
2
|
+
import type { Meta, MilkdownPlugin } from '@milkdown/ctx'
|
|
3
|
+
|
|
4
|
+
export const withMeta = <T extends MilkdownPlugin>(
|
|
5
|
+
plugin: T,
|
|
6
|
+
meta: Partial<Meta> & Pick<Meta, 'displayName'>,
|
|
7
|
+
): T => {
|
|
8
|
+
Object.assign(plugin, {
|
|
9
|
+
meta: {
|
|
10
|
+
package: '@milkdown/plugin-emoji',
|
|
11
|
+
...meta,
|
|
12
|
+
},
|
|
13
|
+
})
|
|
14
|
+
|
|
15
|
+
return plugin
|
|
16
|
+
}
|
package/src/index.ts
CHANGED
|
@@ -8,8 +8,9 @@ import nodeEmoji from 'node-emoji'
|
|
|
8
8
|
import remarkEmoji from 'remark-emoji'
|
|
9
9
|
import type Twemoji from 'twemoji'
|
|
10
10
|
|
|
11
|
-
import { parse } from './parse'
|
|
12
|
-
import { twemojiPlugin } from './remark-twemoji'
|
|
11
|
+
import { parse } from './__internal__/parse'
|
|
12
|
+
import { twemojiPlugin } from './__internal__/remark-twemoji'
|
|
13
|
+
import { withMeta } from './__internal__/with-meta'
|
|
13
14
|
|
|
14
15
|
type TwemojiOptions = Exclude<Parameters<typeof Twemoji.parse>[1], Function | undefined>
|
|
15
16
|
|
|
@@ -20,12 +21,18 @@ export interface EmojiConfig {
|
|
|
20
21
|
|
|
21
22
|
/// A slice that contains [options for twemoji](https://github.com/twitter/twemoji#object-as-parameter).
|
|
22
23
|
export const emojiConfig = $ctx<EmojiConfig, 'emojiConfig'>({}, 'emojiConfig')
|
|
24
|
+
withMeta(emojiConfig, {
|
|
25
|
+
displayName: 'Ctx<emojiConfig>',
|
|
26
|
+
})
|
|
23
27
|
|
|
24
28
|
/// HTML attributes for emoji node.
|
|
25
29
|
export const emojiAttr = $nodeAttr('emoji', () => ({
|
|
26
30
|
span: {},
|
|
27
31
|
img: {},
|
|
28
32
|
}))
|
|
33
|
+
withMeta(emojiAttr, {
|
|
34
|
+
displayName: 'Attr<emoji>',
|
|
35
|
+
})
|
|
29
36
|
|
|
30
37
|
/// Schema for emoji node.
|
|
31
38
|
export const emojiSchema = $nodeSchema('emoji', ctx => ({
|
|
@@ -77,6 +84,13 @@ export const emojiSchema = $nodeSchema('emoji', ctx => ({
|
|
|
77
84
|
},
|
|
78
85
|
}))
|
|
79
86
|
|
|
87
|
+
withMeta(emojiSchema.node, {
|
|
88
|
+
displayName: 'NodeSchema<emoji>',
|
|
89
|
+
})
|
|
90
|
+
withMeta(emojiSchema.ctx, {
|
|
91
|
+
displayName: 'NodeSchemaCtx<emoji>',
|
|
92
|
+
})
|
|
93
|
+
|
|
80
94
|
/// Input rule for inserting emoji.
|
|
81
95
|
/// For example, `:smile:` will be replaced with `😄`.
|
|
82
96
|
export const insertEmojiInputRule = $inputRule(ctx => new InputRule(/(:([^:\s]+):)$/, (state, match, start, end) => {
|
|
@@ -95,12 +109,24 @@ export const insertEmojiInputRule = $inputRule(ctx => new InputRule(/(:([^:\s]+)
|
|
|
95
109
|
.scrollIntoView()
|
|
96
110
|
}))
|
|
97
111
|
|
|
112
|
+
withMeta(insertEmojiInputRule, {
|
|
113
|
+
displayName: 'InputRule<insertEmojiInputRule>',
|
|
114
|
+
})
|
|
115
|
+
|
|
98
116
|
/// This plugin wraps [remark-emoji](https://github.com/rhysd/remark-emoji).
|
|
99
117
|
export const remarkEmojiPlugin = $remark(() => remarkEmoji as RemarkPlugin)
|
|
100
118
|
|
|
119
|
+
withMeta(remarkEmojiPlugin, {
|
|
120
|
+
displayName: 'Remark<remarkEmojiPlugin>',
|
|
121
|
+
})
|
|
122
|
+
|
|
101
123
|
/// This plugin is used for transforming emoji to twemoji.
|
|
102
124
|
export const remarkTwemojiPlugin = $remark(ctx => twemojiPlugin(ctx.get(emojiConfig.key).twemojiOptions))
|
|
103
125
|
|
|
126
|
+
withMeta(remarkTwemojiPlugin, {
|
|
127
|
+
displayName: 'Remark<remarkTwemojiPlugin>',
|
|
128
|
+
})
|
|
129
|
+
|
|
104
130
|
/// All plugins exported by this package.
|
|
105
131
|
export const emoji: MilkdownPlugin[] = [
|
|
106
132
|
emojiAttr,
|
package/lib/parse.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"parse.d.ts","sourceRoot":"","sources":["../src/parse.ts"],"names":[],"mappings":"AAKA,eAAO,MAAM,KAAK,UAAW,MAAM,mBAAmB,cAAc,KAAG,MAC6E,CAAA"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"remark-twemoji.d.ts","sourceRoot":"","sources":["../src/remark-twemoji.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,uBAAuB,CAAA;AAqCzD,eAAO,MAAM,aAAa,EAAE,CAAC,cAAc,CAAC,EAAE,cAAc,KAAK,YA8BhE,CAAA"}
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|