@milkdown/preset-commonmark 7.6.2 → 7.6.4

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/index.es.js CHANGED
@@ -1,266 +1,297 @@
1
- import { $markAttr as U, $markSchema as G, $command as c, $inputRule as h, $useKeymap as f, $node as Qe, $nodeAttr as N, $nodeSchema as I, $ctx as Xe, $remark as v, $prose as _ } from "@milkdown/utils";
2
- import { remarkStringifyOptionsCtx as Ye, commandsCtx as g, editorViewCtx as At } from "@milkdown/core";
3
- import { toggleMark as J, setBlockType as D, wrapIn as Q } from "@milkdown/prose/commands";
4
- import { Fragment as wt } from "@milkdown/prose/model";
5
- import { expectDomTypeError as A } from "@milkdown/exception";
6
- import { textblockTypeInputRule as Ze, wrappingInputRule as X, InputRule as et } from "@milkdown/prose/inputrules";
7
- import Ht from "@sindresorhus/slugify";
8
- import { TextSelection as Y, Selection as tt, PluginKey as E, Plugin as P } from "@milkdown/prose/state";
9
- import { markRule as j, findSelectedNodeOfType as Bt } from "@milkdown/prose";
10
- import { sinkListItem as Rt, liftListItem as rt, splitListItem as Ot } from "@milkdown/prose/schema-list";
11
- import { ReplaceStep as Tt, AddMarkStep as Kt } from "@milkdown/prose/transform";
12
- import { Decoration as ze, DecorationSet as Je } from "@milkdown/prose/view";
13
- import { visit as Z } from "unist-util-visit";
14
- import Dt from "remark-inline-links";
15
- function at(t, e) {
16
- var o;
17
- if (!(e.childCount >= 1 && ((o = e.lastChild) == null ? void 0 : o.type.name) === "hardbreak")) {
18
- t.next(e.content);
1
+ import { $markAttr, $markSchema, $inputRule, $command, $useKeymap, $node, $nodeAttr, $nodeSchema, $ctx, $remark, $prose } from "@milkdown/utils";
2
+ import { remarkStringifyOptionsCtx, commandsCtx, editorViewCtx } from "@milkdown/core";
3
+ import { toggleMark, setBlockType, wrapIn } from "@milkdown/prose/commands";
4
+ import { Fragment } from "@milkdown/prose/model";
5
+ import { expectDomTypeError } from "@milkdown/exception";
6
+ import { textblockTypeInputRule, wrappingInputRule, InputRule } from "@milkdown/prose/inputrules";
7
+ import { TextSelection, Selection, PluginKey, Plugin } from "@milkdown/prose/state";
8
+ import { markRule, findSelectedNodeOfType } from "@milkdown/prose";
9
+ import { sinkListItem, splitListItem, liftListItem } from "@milkdown/prose/schema-list";
10
+ import { ReplaceStep, AddMarkStep } from "@milkdown/prose/transform";
11
+ import { Decoration, DecorationSet } from "@milkdown/prose/view";
12
+ import { visit } from "unist-util-visit";
13
+ import remarkInlineLinks from "remark-inline-links";
14
+ function serializeText(state, node) {
15
+ var _a;
16
+ const lastIsHardBreak = node.childCount >= 1 && ((_a = node.lastChild) == null ? void 0 : _a.type.name) === "hardbreak";
17
+ if (!lastIsHardBreak) {
18
+ state.next(node.content);
19
19
  return;
20
20
  }
21
- const a = [];
22
- e.content.forEach((s, l, i) => {
23
- i !== e.childCount - 1 && a.push(s);
24
- }), t.next(wt.fromArray(a));
21
+ const contentArr = [];
22
+ node.content.forEach((n, _, i) => {
23
+ if (i === node.childCount - 1) return;
24
+ contentArr.push(n);
25
+ });
26
+ state.next(Fragment.fromArray(contentArr));
25
27
  }
26
- function n(t, e) {
27
- return Object.assign(t, {
28
+ function withMeta(plugin, meta) {
29
+ Object.assign(plugin, {
28
30
  meta: {
29
31
  package: "@milkdown/preset-commonmark",
30
- ...e
32
+ ...meta
31
33
  }
32
- }), t;
34
+ });
35
+ return plugin;
33
36
  }
34
- const ee = U("emphasis");
35
- n(ee, {
37
+ const emphasisAttr = $markAttr("emphasis");
38
+ withMeta(emphasisAttr, {
36
39
  displayName: "Attr<emphasis>",
37
40
  group: "Emphasis"
38
41
  });
39
- const R = G("emphasis", (t) => ({
42
+ const emphasisSchema = $markSchema("emphasis", (ctx) => ({
40
43
  attrs: {
41
44
  marker: {
42
- default: t.get(Ye).emphasis || "*"
45
+ default: ctx.get(remarkStringifyOptionsCtx).emphasis || "*"
43
46
  }
44
47
  },
45
48
  parseDOM: [
46
49
  { tag: "i" },
47
50
  { tag: "em" },
48
- { style: "font-style", getAttrs: (e) => e === "italic" }
51
+ { style: "font-style", getAttrs: (value) => value === "italic" }
49
52
  ],
50
- toDOM: (e) => ["em", t.get(ee.key)(e)],
53
+ toDOM: (mark) => ["em", ctx.get(emphasisAttr.key)(mark)],
51
54
  parseMarkdown: {
52
- match: (e) => e.type === "emphasis",
53
- runner: (e, r, a) => {
54
- e.openMark(a, { marker: r.marker }), e.next(r.children), e.closeMark(a);
55
+ match: (node) => node.type === "emphasis",
56
+ runner: (state, node, markType) => {
57
+ state.openMark(markType, { marker: node.marker });
58
+ state.next(node.children);
59
+ state.closeMark(markType);
55
60
  }
56
61
  },
57
62
  toMarkdown: {
58
- match: (e) => e.type.name === "emphasis",
59
- runner: (e, r) => {
60
- e.withMark(r, "emphasis", void 0, {
61
- marker: r.attrs.marker
63
+ match: (mark) => mark.type.name === "emphasis",
64
+ runner: (state, mark) => {
65
+ state.withMark(mark, "emphasis", void 0, {
66
+ marker: mark.attrs.marker
62
67
  });
63
68
  }
64
69
  }
65
70
  }));
66
- n(R.mark, {
71
+ withMeta(emphasisSchema.mark, {
67
72
  displayName: "MarkSchema<emphasis>",
68
73
  group: "Emphasis"
69
74
  });
70
- n(R.ctx, {
75
+ withMeta(emphasisSchema.ctx, {
71
76
  displayName: "MarkSchemaCtx<emphasis>",
72
77
  group: "Emphasis"
73
78
  });
74
- const te = c("ToggleEmphasis", (t) => () => J(R.type(t)));
75
- n(te, {
79
+ const toggleEmphasisCommand = $command("ToggleEmphasis", (ctx) => () => {
80
+ return toggleMark(emphasisSchema.type(ctx));
81
+ });
82
+ withMeta(toggleEmphasisCommand, {
76
83
  displayName: "Command<toggleEmphasisCommand>",
77
84
  group: "Emphasis"
78
85
  });
79
- const nt = h((t) => j(/(?:^|[^*])\*([^*]+)\*$/, R.type(t), {
80
- getAttr: () => ({
81
- marker: "*"
82
- }),
83
- updateCaptured: ({ fullMatch: e, start: r }) => e.startsWith("*") ? {} : { fullMatch: e.slice(1), start: r + 1 }
84
- }));
85
- n(nt, {
86
+ const emphasisStarInputRule = $inputRule((ctx) => {
87
+ return markRule(/(?:^|[^*])\*([^*]+)\*$/, emphasisSchema.type(ctx), {
88
+ getAttr: () => ({
89
+ marker: "*"
90
+ }),
91
+ updateCaptured: ({ fullMatch, start }) => !fullMatch.startsWith("*") ? { fullMatch: fullMatch.slice(1), start: start + 1 } : {}
92
+ });
93
+ });
94
+ withMeta(emphasisStarInputRule, {
86
95
  displayName: "InputRule<emphasis>|Star",
87
96
  group: "Emphasis"
88
97
  });
89
- const ot = h((t) => j(/(?:^|[^_])_([^_]+)_$/, R.type(t), {
90
- getAttr: () => ({
91
- marker: "_"
92
- }),
93
- updateCaptured: ({ fullMatch: e, start: r }) => e.startsWith("_") ? {} : { fullMatch: e.slice(1), start: r + 1 }
94
- }));
95
- n(ot, {
98
+ const emphasisUnderscoreInputRule = $inputRule((ctx) => {
99
+ return markRule(/(?:^|[^_])_([^_]+)_$/, emphasisSchema.type(ctx), {
100
+ getAttr: () => ({
101
+ marker: "_"
102
+ }),
103
+ updateCaptured: ({ fullMatch, start }) => !fullMatch.startsWith("_") ? { fullMatch: fullMatch.slice(1), start: start + 1 } : {}
104
+ });
105
+ });
106
+ withMeta(emphasisUnderscoreInputRule, {
96
107
  displayName: "InputRule<emphasis>|Underscore",
97
108
  group: "Emphasis"
98
109
  });
99
- const re = f("emphasisKeymap", {
110
+ const emphasisKeymap = $useKeymap("emphasisKeymap", {
100
111
  ToggleEmphasis: {
101
112
  shortcuts: "Mod-i",
102
- command: (t) => {
103
- const e = t.get(g);
104
- return () => e.call(te.key);
113
+ command: (ctx) => {
114
+ const commands2 = ctx.get(commandsCtx);
115
+ return () => commands2.call(toggleEmphasisCommand.key);
105
116
  }
106
117
  }
107
118
  });
108
- n(re.ctx, {
119
+ withMeta(emphasisKeymap.ctx, {
109
120
  displayName: "KeymapCtx<emphasis>",
110
121
  group: "Emphasis"
111
122
  });
112
- n(re.shortcuts, {
123
+ withMeta(emphasisKeymap.shortcuts, {
113
124
  displayName: "Keymap<emphasis>",
114
125
  group: "Emphasis"
115
126
  });
116
- const ae = U("strong");
117
- n(ae, {
127
+ const strongAttr = $markAttr("strong");
128
+ withMeta(strongAttr, {
118
129
  displayName: "Attr<strong>",
119
130
  group: "Strong"
120
131
  });
121
- const $ = G("strong", (t) => ({
132
+ const strongSchema = $markSchema("strong", (ctx) => ({
122
133
  attrs: {
123
134
  marker: {
124
- default: t.get(Ye).strong || "*"
135
+ default: ctx.get(remarkStringifyOptionsCtx).strong || "*"
125
136
  }
126
137
  },
127
138
  parseDOM: [
128
139
  { tag: "b" },
129
140
  { tag: "strong" },
130
- { style: "font-style", getAttrs: (e) => e === "bold" }
141
+ { style: "font-style", getAttrs: (value) => value === "bold" }
131
142
  ],
132
- toDOM: (e) => ["strong", t.get(ae.key)(e)],
143
+ toDOM: (mark) => ["strong", ctx.get(strongAttr.key)(mark)],
133
144
  parseMarkdown: {
134
- match: (e) => e.type === "strong",
135
- runner: (e, r, a) => {
136
- e.openMark(a, { marker: r.marker }), e.next(r.children), e.closeMark(a);
145
+ match: (node) => node.type === "strong",
146
+ runner: (state, node, markType) => {
147
+ state.openMark(markType, { marker: node.marker });
148
+ state.next(node.children);
149
+ state.closeMark(markType);
137
150
  }
138
151
  },
139
152
  toMarkdown: {
140
- match: (e) => e.type.name === "strong",
141
- runner: (e, r) => {
142
- e.withMark(r, "strong", void 0, {
143
- marker: r.attrs.marker
153
+ match: (mark) => mark.type.name === "strong",
154
+ runner: (state, mark) => {
155
+ state.withMark(mark, "strong", void 0, {
156
+ marker: mark.attrs.marker
144
157
  });
145
158
  }
146
159
  }
147
160
  }));
148
- n($.mark, {
161
+ withMeta(strongSchema.mark, {
149
162
  displayName: "MarkSchema<strong>",
150
163
  group: "Strong"
151
164
  });
152
- n($.ctx, {
165
+ withMeta(strongSchema.ctx, {
153
166
  displayName: "MarkSchemaCtx<strong>",
154
167
  group: "Strong"
155
168
  });
156
- const ne = c("ToggleStrong", (t) => () => J($.type(t)));
157
- n(ne, {
169
+ const toggleStrongCommand = $command("ToggleStrong", (ctx) => () => {
170
+ return toggleMark(strongSchema.type(ctx));
171
+ });
172
+ withMeta(toggleStrongCommand, {
158
173
  displayName: "Command<toggleStrongCommand>",
159
174
  group: "Strong"
160
175
  });
161
- const st = h((t) => j(/(?:\*\*|__)([^*_]+)(?:\*\*|__)$/, $.type(t), {
162
- getAttr: (e) => ({
163
- marker: e[0].startsWith("*") ? "*" : "_"
164
- })
165
- }));
166
- n(st, {
176
+ const strongInputRule = $inputRule((ctx) => {
177
+ return markRule(/(?:\*\*|__)([^*_]+)(?:\*\*|__)$/, strongSchema.type(ctx), {
178
+ getAttr: (match) => {
179
+ return {
180
+ marker: match[0].startsWith("*") ? "*" : "_"
181
+ };
182
+ }
183
+ });
184
+ });
185
+ withMeta(strongInputRule, {
167
186
  displayName: "InputRule<strong>",
168
187
  group: "Strong"
169
188
  });
170
- const oe = f("strongKeymap", {
189
+ const strongKeymap = $useKeymap("strongKeymap", {
171
190
  ToggleBold: {
172
191
  shortcuts: ["Mod-b"],
173
- command: (t) => {
174
- const e = t.get(g);
175
- return () => e.call(ne.key);
192
+ command: (ctx) => {
193
+ const commands2 = ctx.get(commandsCtx);
194
+ return () => commands2.call(toggleStrongCommand.key);
176
195
  }
177
196
  }
178
197
  });
179
- n(oe.ctx, {
198
+ withMeta(strongKeymap.ctx, {
180
199
  displayName: "KeymapCtx<strong>",
181
200
  group: "Strong"
182
201
  });
183
- n(oe.shortcuts, {
202
+ withMeta(strongKeymap.shortcuts, {
184
203
  displayName: "Keymap<strong>",
185
204
  group: "Strong"
186
205
  });
187
- const se = U("inlineCode");
188
- n(se, {
206
+ const inlineCodeAttr = $markAttr("inlineCode");
207
+ withMeta(inlineCodeAttr, {
189
208
  displayName: "Attr<inlineCode>",
190
209
  group: "InlineCode"
191
210
  });
192
- const x = G("inlineCode", (t) => ({
211
+ const inlineCodeSchema = $markSchema("inlineCode", (ctx) => ({
193
212
  priority: 100,
194
- code: !0,
195
- inclusive: !1,
213
+ code: true,
214
+ inclusive: false,
196
215
  parseDOM: [{ tag: "code" }],
197
- toDOM: (e) => ["code", t.get(se.key)(e)],
216
+ toDOM: (mark) => ["code", ctx.get(inlineCodeAttr.key)(mark)],
198
217
  parseMarkdown: {
199
- match: (e) => e.type === "inlineCode",
200
- runner: (e, r, a) => {
201
- e.openMark(a), e.addText(r.value), e.closeMark(a);
218
+ match: (node) => node.type === "inlineCode",
219
+ runner: (state, node, markType) => {
220
+ state.openMark(markType);
221
+ state.addText(node.value);
222
+ state.closeMark(markType);
202
223
  }
203
224
  },
204
225
  toMarkdown: {
205
- match: (e) => e.type.name === "inlineCode",
206
- runner: (e, r, a) => {
207
- e.withMark(r, "inlineCode", a.text || "");
226
+ match: (mark) => mark.type.name === "inlineCode",
227
+ runner: (state, mark, node) => {
228
+ state.withMark(mark, "inlineCode", node.text || "");
208
229
  }
209
230
  }
210
231
  }));
211
- n(x.mark, {
232
+ withMeta(inlineCodeSchema.mark, {
212
233
  displayName: "MarkSchema<inlineCode>",
213
234
  group: "InlineCode"
214
235
  });
215
- n(x.ctx, {
236
+ withMeta(inlineCodeSchema.ctx, {
216
237
  displayName: "MarkSchemaCtx<inlineCode>",
217
238
  group: "InlineCode"
218
239
  });
219
- const le = c(
240
+ const toggleInlineCodeCommand = $command(
220
241
  "ToggleInlineCode",
221
- (t) => () => (e, r) => {
222
- const { selection: a, tr: o } = e;
223
- if (a.empty) return !1;
224
- const { from: s, to: l } = a;
225
- return e.doc.rangeHasMark(s, l, x.type(t)) ? (r == null || r(o.removeMark(s, l, x.type(t))), !0) : (Object.keys(e.schema.marks).filter(
226
- (m) => m !== x.type.name
227
- ).map((m) => e.schema.marks[m]).forEach((m) => {
228
- o.removeMark(s, l, m);
229
- }), r == null || r(o.addMark(s, l, x.type(t).create())), !0);
242
+ (ctx) => () => (state, dispatch) => {
243
+ const { selection, tr } = state;
244
+ if (selection.empty) return false;
245
+ const { from, to } = selection;
246
+ const has = state.doc.rangeHasMark(from, to, inlineCodeSchema.type(ctx));
247
+ if (has) {
248
+ dispatch == null ? void 0 : dispatch(tr.removeMark(from, to, inlineCodeSchema.type(ctx)));
249
+ return true;
250
+ }
251
+ const restMarksName = Object.keys(state.schema.marks).filter(
252
+ (x) => x !== inlineCodeSchema.type.name
253
+ );
254
+ restMarksName.map((name) => state.schema.marks[name]).forEach((t) => {
255
+ tr.removeMark(from, to, t);
256
+ });
257
+ dispatch == null ? void 0 : dispatch(tr.addMark(from, to, inlineCodeSchema.type(ctx).create()));
258
+ return true;
230
259
  }
231
260
  );
232
- n(le, {
261
+ withMeta(toggleInlineCodeCommand, {
233
262
  displayName: "Command<toggleInlineCodeCommand>",
234
263
  group: "InlineCode"
235
264
  });
236
- const lt = h((t) => j(/(?:`)([^`]+)(?:`)$/, x.type(t)));
237
- n(lt, {
265
+ const inlineCodeInputRule = $inputRule((ctx) => {
266
+ return markRule(/(?:`)([^`]+)(?:`)$/, inlineCodeSchema.type(ctx));
267
+ });
268
+ withMeta(inlineCodeInputRule, {
238
269
  displayName: "InputRule<inlineCodeInputRule>",
239
270
  group: "InlineCode"
240
271
  });
241
- const ie = f("inlineCodeKeymap", {
272
+ const inlineCodeKeymap = $useKeymap("inlineCodeKeymap", {
242
273
  ToggleInlineCode: {
243
274
  shortcuts: "Mod-e",
244
- command: (t) => {
245
- const e = t.get(g);
246
- return () => e.call(le.key);
275
+ command: (ctx) => {
276
+ const commands2 = ctx.get(commandsCtx);
277
+ return () => commands2.call(toggleInlineCodeCommand.key);
247
278
  }
248
279
  }
249
280
  });
250
- n(ie.ctx, {
281
+ withMeta(inlineCodeKeymap.ctx, {
251
282
  displayName: "KeymapCtx<inlineCode>",
252
283
  group: "InlineCode"
253
284
  });
254
- n(ie.shortcuts, {
285
+ withMeta(inlineCodeKeymap.shortcuts, {
255
286
  displayName: "Keymap<inlineCode>",
256
287
  group: "InlineCode"
257
288
  });
258
- const de = U("link");
259
- n(de, {
289
+ const linkAttr = $markAttr("link");
290
+ withMeta(linkAttr, {
260
291
  displayName: "Attr<link>",
261
292
  group: "Link"
262
293
  });
263
- const B = G("link", (t) => ({
294
+ const linkSchema = $markSchema("link", (ctx) => ({
264
295
  attrs: {
265
296
  href: {},
266
297
  title: { default: null }
@@ -268,165 +299,186 @@ const B = G("link", (t) => ({
268
299
  parseDOM: [
269
300
  {
270
301
  tag: "a[href]",
271
- getAttrs: (e) => {
272
- if (!(e instanceof HTMLElement)) throw A(e);
302
+ getAttrs: (dom) => {
303
+ if (!(dom instanceof HTMLElement)) throw expectDomTypeError(dom);
273
304
  return {
274
- href: e.getAttribute("href"),
275
- title: e.getAttribute("title")
305
+ href: dom.getAttribute("href"),
306
+ title: dom.getAttribute("title")
276
307
  };
277
308
  }
278
309
  }
279
310
  ],
280
- toDOM: (e) => ["a", { ...t.get(de.key)(e), ...e.attrs }],
311
+ toDOM: (mark) => ["a", { ...ctx.get(linkAttr.key)(mark), ...mark.attrs }],
281
312
  parseMarkdown: {
282
- match: (e) => e.type === "link",
283
- runner: (e, r, a) => {
284
- const o = r.url, s = r.title;
285
- e.openMark(a, { href: o, title: s }), e.next(r.children), e.closeMark(a);
313
+ match: (node) => node.type === "link",
314
+ runner: (state, node, markType) => {
315
+ const url = node.url;
316
+ const title = node.title;
317
+ state.openMark(markType, { href: url, title });
318
+ state.next(node.children);
319
+ state.closeMark(markType);
286
320
  }
287
321
  },
288
322
  toMarkdown: {
289
- match: (e) => e.type.name === "link",
290
- runner: (e, r) => {
291
- e.withMark(r, "link", void 0, {
292
- title: r.attrs.title,
293
- url: r.attrs.href
323
+ match: (mark) => mark.type.name === "link",
324
+ runner: (state, mark) => {
325
+ state.withMark(mark, "link", void 0, {
326
+ title: mark.attrs.title,
327
+ url: mark.attrs.href
294
328
  });
295
329
  }
296
330
  }
297
331
  }));
298
- n(B.mark, {
332
+ withMeta(linkSchema.mark, {
299
333
  displayName: "MarkSchema<link>",
300
334
  group: "Link"
301
335
  });
302
- const it = c(
336
+ const toggleLinkCommand = $command(
303
337
  "ToggleLink",
304
- (t) => (e = {}) => J(B.type(t), e)
338
+ (ctx) => (payload = {}) => toggleMark(linkSchema.type(ctx), payload)
305
339
  );
306
- n(it, {
340
+ withMeta(toggleLinkCommand, {
307
341
  displayName: "Command<toggleLinkCommand>",
308
342
  group: "Link"
309
343
  });
310
- const dt = c(
344
+ const updateLinkCommand = $command(
311
345
  "UpdateLink",
312
- (t) => (e = {}) => (r, a) => {
313
- if (!a) return !1;
314
- let o, s = -1;
315
- const { selection: l } = r, { from: i, to: d } = l;
316
- if (r.doc.nodesBetween(i, i === d ? d + 1 : d, (y, b) => {
317
- if (B.type(t).isInSet(y.marks))
318
- return o = y, s = b, !1;
319
- }), !o) return !1;
320
- const m = o.marks.find(({ type: y }) => y === B.type(t));
321
- if (!m) return !1;
322
- const u = s, p = s + o.nodeSize, { tr: k } = r, C = B.type(t).create({ ...m.attrs, ...e });
323
- return C ? (a(
324
- k.removeMark(u, p, m).addMark(u, p, C).setSelection(new Y(k.selection.$anchor)).scrollIntoView()
325
- ), !0) : !1;
346
+ (ctx) => (payload = {}) => (state, dispatch) => {
347
+ if (!dispatch) return false;
348
+ let node;
349
+ let pos = -1;
350
+ const { selection } = state;
351
+ const { from, to } = selection;
352
+ state.doc.nodesBetween(from, from === to ? to + 1 : to, (n, p) => {
353
+ if (linkSchema.type(ctx).isInSet(n.marks)) {
354
+ node = n;
355
+ pos = p;
356
+ return false;
357
+ }
358
+ return void 0;
359
+ });
360
+ if (!node) return false;
361
+ const mark = node.marks.find(({ type }) => type === linkSchema.type(ctx));
362
+ if (!mark) return false;
363
+ const start = pos;
364
+ const end = pos + node.nodeSize;
365
+ const { tr } = state;
366
+ const linkMark = linkSchema.type(ctx).create({ ...mark.attrs, ...payload });
367
+ if (!linkMark) return false;
368
+ dispatch(
369
+ tr.removeMark(start, end, mark).addMark(start, end, linkMark).setSelection(new TextSelection(tr.selection.$anchor)).scrollIntoView()
370
+ );
371
+ return true;
326
372
  }
327
373
  );
328
- n(dt, {
374
+ withMeta(updateLinkCommand, {
329
375
  displayName: "Command<updateLinkCommand>",
330
376
  group: "Link"
331
377
  });
332
- const mt = Qe("doc", () => ({
378
+ const docSchema = $node("doc", () => ({
333
379
  content: "block+",
334
380
  parseMarkdown: {
335
- match: ({ type: t }) => t === "root",
336
- runner: (t, e, r) => {
337
- t.injectRoot(e, r);
381
+ match: ({ type }) => type === "root",
382
+ runner: (state, node, type) => {
383
+ state.injectRoot(node, type);
338
384
  }
339
385
  },
340
386
  toMarkdown: {
341
- match: (t) => t.type.name === "doc",
342
- runner: (t, e) => {
343
- t.openNode("root"), t.next(e.content);
387
+ match: (node) => node.type.name === "doc",
388
+ runner: (state, node) => {
389
+ state.openNode("root");
390
+ state.next(node.content);
344
391
  }
345
392
  }
346
393
  }));
347
- n(mt, {
394
+ withMeta(docSchema, {
348
395
  displayName: "NodeSchema<doc>",
349
396
  group: "Doc"
350
397
  });
351
- const me = N("paragraph");
352
- n(me, {
398
+ const paragraphAttr = $nodeAttr("paragraph");
399
+ withMeta(paragraphAttr, {
353
400
  displayName: "Attr<paragraph>",
354
401
  group: "Paragraph"
355
402
  });
356
- const w = I("paragraph", (t) => ({
403
+ const paragraphSchema = $nodeSchema("paragraph", (ctx) => ({
357
404
  content: "inline*",
358
405
  group: "block",
359
406
  parseDOM: [{ tag: "p" }],
360
- toDOM: (e) => ["p", t.get(me.key)(e), 0],
407
+ toDOM: (node) => ["p", ctx.get(paragraphAttr.key)(node), 0],
361
408
  parseMarkdown: {
362
- match: (e) => e.type === "paragraph",
363
- runner: (e, r, a) => {
364
- e.openNode(a), r.children ? e.next(r.children) : e.addText(r.value || ""), e.closeNode();
409
+ match: (node) => node.type === "paragraph",
410
+ runner: (state, node, type) => {
411
+ state.openNode(type);
412
+ if (node.children) state.next(node.children);
413
+ else state.addText(node.value || "");
414
+ state.closeNode();
365
415
  }
366
416
  },
367
417
  toMarkdown: {
368
- match: (e) => e.type.name === "paragraph",
369
- runner: (e, r) => {
370
- e.openNode("paragraph"), at(e, r), e.closeNode();
418
+ match: (node) => node.type.name === "paragraph",
419
+ runner: (state, node) => {
420
+ state.openNode("paragraph");
421
+ serializeText(state, node);
422
+ state.closeNode();
371
423
  }
372
424
  }
373
425
  }));
374
- n(w.node, {
426
+ withMeta(paragraphSchema.node, {
375
427
  displayName: "NodeSchema<paragraph>",
376
428
  group: "Paragraph"
377
429
  });
378
- n(w.ctx, {
430
+ withMeta(paragraphSchema.ctx, {
379
431
  displayName: "NodeSchemaCtx<paragraph>",
380
432
  group: "Paragraph"
381
433
  });
382
- const ue = c(
434
+ const turnIntoTextCommand = $command(
383
435
  "TurnIntoText",
384
- (t) => () => D(w.type(t))
436
+ (ctx) => () => setBlockType(paragraphSchema.type(ctx))
385
437
  );
386
- n(ue, {
438
+ withMeta(turnIntoTextCommand, {
387
439
  displayName: "Command<turnIntoTextCommand>",
388
440
  group: "Paragraph"
389
441
  });
390
- const pe = f("paragraphKeymap", {
442
+ const paragraphKeymap = $useKeymap("paragraphKeymap", {
391
443
  TurnIntoText: {
392
444
  shortcuts: "Mod-Alt-0",
393
- command: (t) => {
394
- const e = t.get(g);
395
- return () => e.call(ue.key);
445
+ command: (ctx) => {
446
+ const commands2 = ctx.get(commandsCtx);
447
+ return () => commands2.call(turnIntoTextCommand.key);
396
448
  }
397
449
  }
398
450
  });
399
- n(pe.ctx, {
451
+ withMeta(paragraphKeymap.ctx, {
400
452
  displayName: "KeymapCtx<paragraph>",
401
453
  group: "Paragraph"
402
454
  });
403
- n(pe.shortcuts, {
455
+ withMeta(paragraphKeymap.shortcuts, {
404
456
  displayName: "Keymap<paragraph>",
405
457
  group: "Paragraph"
406
458
  });
407
- const vt = Array(6).fill(0).map((t, e) => e + 1);
408
- function _t(t) {
409
- return Ht(t.textContent);
459
+ const headingIndex = Array(6).fill(0).map((_, i) => i + 1);
460
+ function defaultHeadingIdGenerator(node) {
461
+ return node.textContent.toLowerCase().trim().replace(/[^\w\s-]/g, "").replace(/\s+/g, "-");
410
462
  }
411
- const z = Xe(
412
- _t,
463
+ const headingIdGenerator = $ctx(
464
+ defaultHeadingIdGenerator,
413
465
  "headingIdGenerator"
414
466
  );
415
- n(z, {
467
+ withMeta(headingIdGenerator, {
416
468
  displayName: "Ctx<HeadingIdGenerator>",
417
469
  group: "Heading"
418
470
  });
419
- const ce = N("heading");
420
- n(ce, {
471
+ const headingAttr = $nodeAttr("heading");
472
+ withMeta(headingAttr, {
421
473
  displayName: "Attr<heading>",
422
474
  group: "Heading"
423
475
  });
424
- const H = I("heading", (t) => {
425
- const e = t.get(z.key);
476
+ const headingSchema = $nodeSchema("heading", (ctx) => {
477
+ const getId = ctx.get(headingIdGenerator.key);
426
478
  return {
427
479
  content: "inline*",
428
480
  group: "block",
429
- defining: !0,
481
+ defining: true,
430
482
  attrs: {
431
483
  id: {
432
484
  default: ""
@@ -435,682 +487,749 @@ const H = I("heading", (t) => {
435
487
  default: 1
436
488
  }
437
489
  },
438
- parseDOM: vt.map((r) => ({
439
- tag: `h${r}`,
440
- getAttrs: (a) => {
441
- if (!(a instanceof HTMLElement)) throw A(a);
442
- return { level: r, id: a.id };
490
+ parseDOM: headingIndex.map((x) => ({
491
+ tag: `h${x}`,
492
+ getAttrs: (node) => {
493
+ if (!(node instanceof HTMLElement)) throw expectDomTypeError(node);
494
+ return { level: x, id: node.id };
443
495
  }
444
496
  })),
445
- toDOM: (r) => [
446
- `h${r.attrs.level}`,
447
- {
448
- ...t.get(ce.key)(r),
449
- id: r.attrs.id || e(r)
450
- },
451
- 0
452
- ],
497
+ toDOM: (node) => {
498
+ return [
499
+ `h${node.attrs.level}`,
500
+ {
501
+ ...ctx.get(headingAttr.key)(node),
502
+ id: node.attrs.id || getId(node)
503
+ },
504
+ 0
505
+ ];
506
+ },
453
507
  parseMarkdown: {
454
- match: ({ type: r }) => r === "heading",
455
- runner: (r, a, o) => {
456
- const s = a.depth;
457
- r.openNode(o, { level: s }), r.next(a.children), r.closeNode();
508
+ match: ({ type }) => type === "heading",
509
+ runner: (state, node, type) => {
510
+ const depth = node.depth;
511
+ state.openNode(type, { level: depth });
512
+ state.next(node.children);
513
+ state.closeNode();
458
514
  }
459
515
  },
460
516
  toMarkdown: {
461
- match: (r) => r.type.name === "heading",
462
- runner: (r, a) => {
463
- r.openNode("heading", void 0, { depth: a.attrs.level }), at(r, a), r.closeNode();
517
+ match: (node) => node.type.name === "heading",
518
+ runner: (state, node) => {
519
+ state.openNode("heading", void 0, { depth: node.attrs.level });
520
+ serializeText(state, node);
521
+ state.closeNode();
464
522
  }
465
523
  }
466
524
  };
467
525
  });
468
- n(H.node, {
526
+ withMeta(headingSchema.node, {
469
527
  displayName: "NodeSchema<heading>",
470
528
  group: "Heading"
471
529
  });
472
- n(H.ctx, {
530
+ withMeta(headingSchema.ctx, {
473
531
  displayName: "NodeSchemaCtx<heading>",
474
532
  group: "Heading"
475
533
  });
476
- const ut = h((t) => Ze(
477
- /^(?<hashes>#+)\s$/,
478
- H.type(t),
479
- (e) => {
480
- var l, i;
481
- const r = ((i = (l = e.groups) == null ? void 0 : l.hashes) == null ? void 0 : i.length) || 0, a = t.get(At), { $from: o } = a.state.selection, s = o.node();
482
- if (s.type.name === "heading") {
483
- let d = Number(s.attrs.level) + Number(r);
484
- return d > 6 && (d = 6), { level: d };
485
- }
486
- return { level: r };
487
- }
488
- ));
489
- n(ut, {
534
+ const wrapInHeadingInputRule = $inputRule((ctx) => {
535
+ return textblockTypeInputRule(
536
+ /^(?<hashes>#+)\s$/,
537
+ headingSchema.type(ctx),
538
+ (match) => {
539
+ var _a, _b;
540
+ const x = ((_b = (_a = match.groups) == null ? void 0 : _a.hashes) == null ? void 0 : _b.length) || 0;
541
+ const view = ctx.get(editorViewCtx);
542
+ const { $from } = view.state.selection;
543
+ const node = $from.node();
544
+ if (node.type.name === "heading") {
545
+ let level = Number(node.attrs.level) + Number(x);
546
+ if (level > 6) level = 6;
547
+ return { level };
548
+ }
549
+ return { level: x };
550
+ }
551
+ );
552
+ });
553
+ withMeta(wrapInHeadingInputRule, {
490
554
  displayName: "InputRule<wrapInHeadingInputRule>",
491
555
  group: "Heading"
492
556
  });
493
- const L = c("WrapInHeading", (t) => (e) => (e ?? (e = 1), e < 1 ? D(w.type(t)) : D(H.type(t), { level: e })));
494
- n(L, {
557
+ const wrapInHeadingCommand = $command("WrapInHeading", (ctx) => {
558
+ return (level) => {
559
+ level ?? (level = 1);
560
+ if (level < 1) return setBlockType(paragraphSchema.type(ctx));
561
+ return setBlockType(headingSchema.type(ctx), { level });
562
+ };
563
+ });
564
+ withMeta(wrapInHeadingCommand, {
495
565
  displayName: "Command<wrapInHeadingCommand>",
496
566
  group: "Heading"
497
567
  });
498
- const ge = c(
568
+ const downgradeHeadingCommand = $command(
499
569
  "DowngradeHeading",
500
- (t) => () => (e, r, a) => {
501
- const { $from: o } = e.selection, s = o.node();
502
- if (s.type !== H.type(t) || !e.selection.empty || o.parentOffset !== 0)
503
- return !1;
504
- const l = s.attrs.level - 1;
505
- return l ? (r == null || r(
506
- e.tr.setNodeMarkup(e.selection.$from.before(), void 0, {
507
- ...s.attrs,
508
- level: l
570
+ (ctx) => () => (state, dispatch, view) => {
571
+ const { $from } = state.selection;
572
+ const node = $from.node();
573
+ if (node.type !== headingSchema.type(ctx) || !state.selection.empty || $from.parentOffset !== 0)
574
+ return false;
575
+ const level = node.attrs.level - 1;
576
+ if (!level)
577
+ return setBlockType(paragraphSchema.type(ctx))(state, dispatch, view);
578
+ dispatch == null ? void 0 : dispatch(
579
+ state.tr.setNodeMarkup(state.selection.$from.before(), void 0, {
580
+ ...node.attrs,
581
+ level
509
582
  })
510
- ), !0) : D(w.type(t))(e, r, a);
583
+ );
584
+ return true;
511
585
  }
512
586
  );
513
- n(ge, {
587
+ withMeta(downgradeHeadingCommand, {
514
588
  displayName: "Command<downgradeHeadingCommand>",
515
589
  group: "Heading"
516
590
  });
517
- const ke = f("headingKeymap", {
591
+ const headingKeymap = $useKeymap("headingKeymap", {
518
592
  TurnIntoH1: {
519
593
  shortcuts: "Mod-Alt-1",
520
- command: (t) => {
521
- const e = t.get(g);
522
- return () => e.call(L.key, 1);
594
+ command: (ctx) => {
595
+ const commands2 = ctx.get(commandsCtx);
596
+ return () => commands2.call(wrapInHeadingCommand.key, 1);
523
597
  }
524
598
  },
525
599
  TurnIntoH2: {
526
600
  shortcuts: "Mod-Alt-2",
527
- command: (t) => {
528
- const e = t.get(g);
529
- return () => e.call(L.key, 2);
601
+ command: (ctx) => {
602
+ const commands2 = ctx.get(commandsCtx);
603
+ return () => commands2.call(wrapInHeadingCommand.key, 2);
530
604
  }
531
605
  },
532
606
  TurnIntoH3: {
533
607
  shortcuts: "Mod-Alt-3",
534
- command: (t) => {
535
- const e = t.get(g);
536
- return () => e.call(L.key, 3);
608
+ command: (ctx) => {
609
+ const commands2 = ctx.get(commandsCtx);
610
+ return () => commands2.call(wrapInHeadingCommand.key, 3);
537
611
  }
538
612
  },
539
613
  TurnIntoH4: {
540
614
  shortcuts: "Mod-Alt-4",
541
- command: (t) => {
542
- const e = t.get(g);
543
- return () => e.call(L.key, 4);
615
+ command: (ctx) => {
616
+ const commands2 = ctx.get(commandsCtx);
617
+ return () => commands2.call(wrapInHeadingCommand.key, 4);
544
618
  }
545
619
  },
546
620
  TurnIntoH5: {
547
621
  shortcuts: "Mod-Alt-5",
548
- command: (t) => {
549
- const e = t.get(g);
550
- return () => e.call(L.key, 5);
622
+ command: (ctx) => {
623
+ const commands2 = ctx.get(commandsCtx);
624
+ return () => commands2.call(wrapInHeadingCommand.key, 5);
551
625
  }
552
626
  },
553
627
  TurnIntoH6: {
554
628
  shortcuts: "Mod-Alt-6",
555
- command: (t) => {
556
- const e = t.get(g);
557
- return () => e.call(L.key, 6);
629
+ command: (ctx) => {
630
+ const commands2 = ctx.get(commandsCtx);
631
+ return () => commands2.call(wrapInHeadingCommand.key, 6);
558
632
  }
559
633
  },
560
634
  DowngradeHeading: {
561
635
  shortcuts: ["Delete", "Backspace"],
562
- command: (t) => {
563
- const e = t.get(g);
564
- return () => e.call(ge.key);
636
+ command: (ctx) => {
637
+ const commands2 = ctx.get(commandsCtx);
638
+ return () => commands2.call(downgradeHeadingCommand.key);
565
639
  }
566
640
  }
567
641
  });
568
- n(ke.ctx, {
642
+ withMeta(headingKeymap.ctx, {
569
643
  displayName: "KeymapCtx<heading>",
570
644
  group: "Heading"
571
645
  });
572
- n(ke.shortcuts, {
646
+ withMeta(headingKeymap.shortcuts, {
573
647
  displayName: "Keymap<heading>",
574
648
  group: "Heading"
575
649
  });
576
- const ye = N("blockquote");
577
- n(ye, {
650
+ const blockquoteAttr = $nodeAttr("blockquote");
651
+ withMeta(blockquoteAttr, {
578
652
  displayName: "Attr<blockquote>",
579
653
  group: "Blockquote"
580
654
  });
581
- const q = I(
655
+ const blockquoteSchema = $nodeSchema(
582
656
  "blockquote",
583
- (t) => ({
657
+ (ctx) => ({
584
658
  content: "block+",
585
659
  group: "block",
586
- defining: !0,
660
+ defining: true,
587
661
  parseDOM: [{ tag: "blockquote" }],
588
- toDOM: (e) => ["blockquote", t.get(ye.key)(e), 0],
662
+ toDOM: (node) => ["blockquote", ctx.get(blockquoteAttr.key)(node), 0],
589
663
  parseMarkdown: {
590
- match: ({ type: e }) => e === "blockquote",
591
- runner: (e, r, a) => {
592
- e.openNode(a).next(r.children).closeNode();
664
+ match: ({ type }) => type === "blockquote",
665
+ runner: (state, node, type) => {
666
+ state.openNode(type).next(node.children).closeNode();
593
667
  }
594
668
  },
595
669
  toMarkdown: {
596
- match: (e) => e.type.name === "blockquote",
597
- runner: (e, r) => {
598
- e.openNode("blockquote").next(r.content).closeNode();
670
+ match: (node) => node.type.name === "blockquote",
671
+ runner: (state, node) => {
672
+ state.openNode("blockquote").next(node.content).closeNode();
599
673
  }
600
674
  }
601
675
  })
602
676
  );
603
- n(q.node, {
677
+ withMeta(blockquoteSchema.node, {
604
678
  displayName: "NodeSchema<blockquote>",
605
679
  group: "Blockquote"
606
680
  });
607
- n(q.ctx, {
681
+ withMeta(blockquoteSchema.ctx, {
608
682
  displayName: "NodeSchemaCtx<blockquote>",
609
683
  group: "Blockquote"
610
684
  });
611
- const pt = h(
612
- (t) => X(/^\s*>\s$/, q.type(t))
685
+ const wrapInBlockquoteInputRule = $inputRule(
686
+ (ctx) => wrappingInputRule(/^\s*>\s$/, blockquoteSchema.type(ctx))
613
687
  );
614
- n(pt, {
688
+ withMeta(wrapInBlockquoteInputRule, {
615
689
  displayName: "InputRule<wrapInBlockquoteInputRule>",
616
690
  group: "Blockquote"
617
691
  });
618
- const he = c(
692
+ const wrapInBlockquoteCommand = $command(
619
693
  "WrapInBlockquote",
620
- (t) => () => Q(q.type(t))
694
+ (ctx) => () => wrapIn(blockquoteSchema.type(ctx))
621
695
  );
622
- n(he, {
696
+ withMeta(wrapInBlockquoteCommand, {
623
697
  displayName: "Command<wrapInBlockquoteCommand>",
624
698
  group: "Blockquote"
625
699
  });
626
- const fe = f("blockquoteKeymap", {
700
+ const blockquoteKeymap = $useKeymap("blockquoteKeymap", {
627
701
  WrapInBlockquote: {
628
702
  shortcuts: "Mod-Shift-b",
629
- command: (t) => {
630
- const e = t.get(g);
631
- return () => e.call(he.key);
703
+ command: (ctx) => {
704
+ const commands2 = ctx.get(commandsCtx);
705
+ return () => commands2.call(wrapInBlockquoteCommand.key);
632
706
  }
633
707
  }
634
708
  });
635
- n(fe.ctx, {
709
+ withMeta(blockquoteKeymap.ctx, {
636
710
  displayName: "KeymapCtx<blockquote>",
637
711
  group: "Blockquote"
638
712
  });
639
- n(fe.shortcuts, {
713
+ withMeta(blockquoteKeymap.shortcuts, {
640
714
  displayName: "Keymap<blockquote>",
641
715
  group: "Blockquote"
642
716
  });
643
- const Ne = N("codeBlock", () => ({
717
+ const codeBlockAttr = $nodeAttr("codeBlock", () => ({
644
718
  pre: {},
645
719
  code: {}
646
720
  }));
647
- n(Ne, {
721
+ withMeta(codeBlockAttr, {
648
722
  displayName: "Attr<codeBlock>",
649
723
  group: "CodeBlock"
650
724
  });
651
- const W = I("code_block", (t) => ({
652
- content: "text*",
653
- group: "block",
654
- marks: "",
655
- defining: !0,
656
- code: !0,
657
- attrs: {
658
- language: {
659
- default: ""
660
- }
661
- },
662
- parseDOM: [
663
- {
664
- tag: "pre",
665
- preserveWhitespace: "full",
666
- getAttrs: (e) => {
667
- if (!(e instanceof HTMLElement)) throw A(e);
668
- return { language: e.dataset.language };
725
+ const codeBlockSchema = $nodeSchema("code_block", (ctx) => {
726
+ return {
727
+ content: "text*",
728
+ group: "block",
729
+ marks: "",
730
+ defining: true,
731
+ code: true,
732
+ attrs: {
733
+ language: {
734
+ default: ""
669
735
  }
670
- }
671
- ],
672
- toDOM: (e) => {
673
- const r = t.get(Ne.key)(e);
674
- return [
675
- "pre",
736
+ },
737
+ parseDOM: [
676
738
  {
677
- ...r.pre,
678
- "data-language": e.attrs.language
679
- },
680
- ["code", r.code, 0]
681
- ];
682
- },
683
- parseMarkdown: {
684
- match: ({ type: e }) => e === "code",
685
- runner: (e, r, a) => {
686
- const o = r.lang, s = r.value;
687
- e.openNode(a, { language: o }), s && e.addText(s), e.closeNode();
688
- }
689
- },
690
- toMarkdown: {
691
- match: (e) => e.type.name === "code_block",
692
- runner: (e, r) => {
693
- var a;
694
- e.addNode("code", void 0, ((a = r.content.firstChild) == null ? void 0 : a.text) || "", {
695
- lang: r.attrs.language
696
- });
739
+ tag: "pre",
740
+ preserveWhitespace: "full",
741
+ getAttrs: (dom) => {
742
+ if (!(dom instanceof HTMLElement)) throw expectDomTypeError(dom);
743
+ return { language: dom.dataset.language };
744
+ }
745
+ }
746
+ ],
747
+ toDOM: (node) => {
748
+ const attr = ctx.get(codeBlockAttr.key)(node);
749
+ return [
750
+ "pre",
751
+ {
752
+ ...attr.pre,
753
+ "data-language": node.attrs.language
754
+ },
755
+ ["code", attr.code, 0]
756
+ ];
757
+ },
758
+ parseMarkdown: {
759
+ match: ({ type }) => type === "code",
760
+ runner: (state, node, type) => {
761
+ const language = node.lang;
762
+ const value = node.value;
763
+ state.openNode(type, { language });
764
+ if (value) state.addText(value);
765
+ state.closeNode();
766
+ }
767
+ },
768
+ toMarkdown: {
769
+ match: (node) => node.type.name === "code_block",
770
+ runner: (state, node) => {
771
+ var _a;
772
+ state.addNode("code", void 0, ((_a = node.content.firstChild) == null ? void 0 : _a.text) || "", {
773
+ lang: node.attrs.language
774
+ });
775
+ }
697
776
  }
698
- }
699
- }));
700
- n(W.node, {
777
+ };
778
+ });
779
+ withMeta(codeBlockSchema.node, {
701
780
  displayName: "NodeSchema<codeBlock>",
702
781
  group: "CodeBlock"
703
782
  });
704
- n(W.ctx, {
783
+ withMeta(codeBlockSchema.ctx, {
705
784
  displayName: "NodeSchemaCtx<codeBlock>",
706
785
  group: "CodeBlock"
707
786
  });
708
- const ct = h(
709
- (t) => Ze(
787
+ const createCodeBlockInputRule = $inputRule(
788
+ (ctx) => textblockTypeInputRule(
710
789
  /^```(?<language>[a-z]*)?[\s\n]$/,
711
- W.type(t),
712
- (e) => {
713
- var r;
790
+ codeBlockSchema.type(ctx),
791
+ (match) => {
792
+ var _a;
714
793
  return {
715
- language: ((r = e.groups) == null ? void 0 : r.language) ?? ""
794
+ language: ((_a = match.groups) == null ? void 0 : _a.language) ?? ""
716
795
  };
717
796
  }
718
797
  )
719
798
  );
720
- n(ct, {
799
+ withMeta(createCodeBlockInputRule, {
721
800
  displayName: "InputRule<createCodeBlockInputRule>",
722
801
  group: "CodeBlock"
723
802
  });
724
- const Ie = c(
803
+ const createCodeBlockCommand = $command(
725
804
  "CreateCodeBlock",
726
- (t) => (e = "") => D(W.type(t), { language: e })
805
+ (ctx) => (language = "") => setBlockType(codeBlockSchema.type(ctx), { language })
727
806
  );
728
- n(Ie, {
807
+ withMeta(createCodeBlockCommand, {
729
808
  displayName: "Command<createCodeBlockCommand>",
730
809
  group: "CodeBlock"
731
810
  });
732
- const Et = c(
811
+ const updateCodeBlockLanguageCommand = $command(
733
812
  "UpdateCodeBlockLanguage",
734
- () => ({ pos: t, language: e } = {
813
+ () => ({ pos, language } = {
735
814
  pos: -1,
736
815
  language: ""
737
- }) => (r, a) => t >= 0 ? (a == null || a(r.tr.setNodeAttribute(t, "language", e)), !0) : !1
816
+ }) => (state, dispatch) => {
817
+ if (pos >= 0) {
818
+ dispatch == null ? void 0 : dispatch(state.tr.setNodeAttribute(pos, "language", language));
819
+ return true;
820
+ }
821
+ return false;
822
+ }
738
823
  );
739
- n(Et, {
824
+ withMeta(updateCodeBlockLanguageCommand, {
740
825
  displayName: "Command<updateCodeBlockLanguageCommand>",
741
826
  group: "CodeBlock"
742
827
  });
743
- const Ce = f("codeBlockKeymap", {
828
+ const codeBlockKeymap = $useKeymap("codeBlockKeymap", {
744
829
  CreateCodeBlock: {
745
830
  shortcuts: "Mod-Alt-c",
746
- command: (t) => {
747
- const e = t.get(g);
748
- return () => e.call(Ie.key);
831
+ command: (ctx) => {
832
+ const commands2 = ctx.get(commandsCtx);
833
+ return () => commands2.call(createCodeBlockCommand.key);
749
834
  }
750
835
  }
751
836
  });
752
- n(Ce.ctx, {
837
+ withMeta(codeBlockKeymap.ctx, {
753
838
  displayName: "KeymapCtx<codeBlock>",
754
839
  group: "CodeBlock"
755
840
  });
756
- n(Ce.shortcuts, {
841
+ withMeta(codeBlockKeymap.shortcuts, {
757
842
  displayName: "Keymap<codeBlock>",
758
843
  group: "CodeBlock"
759
844
  });
760
- const Me = N("image");
761
- n(Me, {
845
+ const imageAttr = $nodeAttr("image");
846
+ withMeta(imageAttr, {
762
847
  displayName: "Attr<image>",
763
848
  group: "Image"
764
849
  });
765
- const O = I("image", (t) => ({
766
- inline: !0,
767
- group: "inline",
768
- selectable: !0,
769
- draggable: !0,
770
- marks: "",
771
- atom: !0,
772
- defining: !0,
773
- isolating: !0,
774
- attrs: {
775
- src: { default: "" },
776
- alt: { default: "" },
777
- title: { default: "" }
778
- },
779
- parseDOM: [
780
- {
781
- tag: "img[src]",
782
- getAttrs: (e) => {
783
- if (!(e instanceof HTMLElement)) throw A(e);
784
- return {
785
- src: e.getAttribute("src") || "",
786
- alt: e.getAttribute("alt") || "",
787
- title: e.getAttribute("title") || e.getAttribute("alt") || ""
788
- };
850
+ const imageSchema = $nodeSchema("image", (ctx) => {
851
+ return {
852
+ inline: true,
853
+ group: "inline",
854
+ selectable: true,
855
+ draggable: true,
856
+ marks: "",
857
+ atom: true,
858
+ defining: true,
859
+ isolating: true,
860
+ attrs: {
861
+ src: { default: "" },
862
+ alt: { default: "" },
863
+ title: { default: "" }
864
+ },
865
+ parseDOM: [
866
+ {
867
+ tag: "img[src]",
868
+ getAttrs: (dom) => {
869
+ if (!(dom instanceof HTMLElement)) throw expectDomTypeError(dom);
870
+ return {
871
+ src: dom.getAttribute("src") || "",
872
+ alt: dom.getAttribute("alt") || "",
873
+ title: dom.getAttribute("title") || dom.getAttribute("alt") || ""
874
+ };
875
+ }
876
+ }
877
+ ],
878
+ toDOM: (node) => {
879
+ return ["img", { ...ctx.get(imageAttr.key)(node), ...node.attrs }];
880
+ },
881
+ parseMarkdown: {
882
+ match: ({ type }) => type === "image",
883
+ runner: (state, node, type) => {
884
+ const url = node.url;
885
+ const alt = node.alt;
886
+ const title = node.title;
887
+ state.addNode(type, {
888
+ src: url,
889
+ alt,
890
+ title
891
+ });
892
+ }
893
+ },
894
+ toMarkdown: {
895
+ match: (node) => node.type.name === "image",
896
+ runner: (state, node) => {
897
+ state.addNode("image", void 0, void 0, {
898
+ title: node.attrs.title,
899
+ url: node.attrs.src,
900
+ alt: node.attrs.alt
901
+ });
789
902
  }
790
903
  }
791
- ],
792
- toDOM: (e) => ["img", { ...t.get(Me.key)(e), ...e.attrs }],
793
- parseMarkdown: {
794
- match: ({ type: e }) => e === "image",
795
- runner: (e, r, a) => {
796
- const o = r.url, s = r.alt, l = r.title;
797
- e.addNode(a, {
798
- src: o,
799
- alt: s,
800
- title: l
801
- });
802
- }
803
- },
804
- toMarkdown: {
805
- match: (e) => e.type.name === "image",
806
- runner: (e, r) => {
807
- e.addNode("image", void 0, void 0, {
808
- title: r.attrs.title,
809
- url: r.attrs.src,
810
- alt: r.attrs.alt
811
- });
812
- }
813
- }
814
- }));
815
- n(O.node, {
904
+ };
905
+ });
906
+ withMeta(imageSchema.node, {
816
907
  displayName: "NodeSchema<image>",
817
908
  group: "Image"
818
909
  });
819
- n(O.ctx, {
910
+ withMeta(imageSchema.ctx, {
820
911
  displayName: "NodeSchemaCtx<image>",
821
912
  group: "Image"
822
913
  });
823
- const gt = c(
914
+ const insertImageCommand = $command(
824
915
  "InsertImage",
825
- (t) => (e = {}) => (r, a) => {
826
- if (!a) return !0;
827
- const { src: o = "", alt: s = "", title: l = "" } = e, i = O.type(t).create({ src: o, alt: s, title: l });
828
- return i && a(r.tr.replaceSelectionWith(i).scrollIntoView()), !0;
916
+ (ctx) => (payload = {}) => (state, dispatch) => {
917
+ if (!dispatch) return true;
918
+ const { src = "", alt = "", title = "" } = payload;
919
+ const node = imageSchema.type(ctx).create({ src, alt, title });
920
+ if (!node) return true;
921
+ dispatch(state.tr.replaceSelectionWith(node).scrollIntoView());
922
+ return true;
829
923
  }
830
924
  );
831
- n(gt, {
925
+ withMeta(insertImageCommand, {
832
926
  displayName: "Command<insertImageCommand>",
833
927
  group: "Image"
834
928
  });
835
- const kt = c(
929
+ const updateImageCommand = $command(
836
930
  "UpdateImage",
837
- (t) => (e = {}) => (r, a) => {
838
- const o = Bt(
839
- r.selection,
840
- O.type(t)
931
+ (ctx) => (payload = {}) => (state, dispatch) => {
932
+ const nodeWithPos = findSelectedNodeOfType(
933
+ state.selection,
934
+ imageSchema.type(ctx)
935
+ );
936
+ if (!nodeWithPos) return false;
937
+ const { node, pos } = nodeWithPos;
938
+ const newAttrs = { ...node.attrs };
939
+ const { src, alt, title } = payload;
940
+ if (src !== void 0) newAttrs.src = src;
941
+ if (alt !== void 0) newAttrs.alt = alt;
942
+ if (title !== void 0) newAttrs.title = title;
943
+ dispatch == null ? void 0 : dispatch(
944
+ state.tr.setNodeMarkup(pos, void 0, newAttrs).scrollIntoView()
841
945
  );
842
- if (!o) return !1;
843
- const { node: s, pos: l } = o, i = { ...s.attrs }, { src: d, alt: m, title: u } = e;
844
- return d !== void 0 && (i.src = d), m !== void 0 && (i.alt = m), u !== void 0 && (i.title = u), a == null || a(
845
- r.tr.setNodeMarkup(l, void 0, i).scrollIntoView()
846
- ), !0;
946
+ return true;
847
947
  }
848
948
  );
849
- n(kt, {
949
+ withMeta(updateImageCommand, {
850
950
  displayName: "Command<updateImageCommand>",
851
951
  group: "Image"
852
952
  });
853
- const Pt = h(
854
- (t) => new et(
953
+ const insertImageInputRule = $inputRule(
954
+ (ctx) => new InputRule(
855
955
  /!\[(?<alt>.*?)]\((?<filename>.*?)\s*(?="|\))"?(?<title>[^"]+)?"?\)/,
856
- (e, r, a, o) => {
857
- const [s, l, i = "", d] = r;
858
- return s ? e.tr.replaceWith(
859
- a,
860
- o,
861
- O.type(t).create({ src: i, alt: l, title: d })
862
- ) : null;
956
+ (state, match, start, end) => {
957
+ const [matched, alt, src = "", title] = match;
958
+ if (matched)
959
+ return state.tr.replaceWith(
960
+ start,
961
+ end,
962
+ imageSchema.type(ctx).create({ src, alt, title })
963
+ );
964
+ return null;
863
965
  }
864
966
  )
865
967
  );
866
- n(Pt, {
968
+ withMeta(insertImageInputRule, {
867
969
  displayName: "InputRule<insertImageInputRule>",
868
970
  group: "Image"
869
971
  });
870
- const V = N("hardbreak", (t) => ({
871
- "data-type": "hardbreak",
872
- "data-is-inline": t.attrs.isInline
873
- }));
874
- n(V, {
972
+ const hardbreakAttr = $nodeAttr("hardbreak", (node) => {
973
+ return {
974
+ "data-type": "hardbreak",
975
+ "data-is-inline": node.attrs.isInline
976
+ };
977
+ });
978
+ withMeta(hardbreakAttr, {
875
979
  displayName: "Attr<hardbreak>",
876
980
  group: "Hardbreak"
877
981
  });
878
- const S = I("hardbreak", (t) => ({
879
- inline: !0,
982
+ const hardbreakSchema = $nodeSchema("hardbreak", (ctx) => ({
983
+ inline: true,
880
984
  group: "inline",
881
985
  attrs: {
882
986
  isInline: {
883
- default: !1
987
+ default: false
884
988
  }
885
989
  },
886
- selectable: !1,
990
+ selectable: false,
887
991
  parseDOM: [
888
992
  { tag: "br" },
889
993
  {
890
994
  tag: 'span[data-type="hardbreak"]',
891
- getAttrs: () => ({ isInline: !0 })
995
+ getAttrs: () => ({ isInline: true })
892
996
  }
893
997
  ],
894
- toDOM: (e) => e.attrs.isInline ? ["span", t.get(V.key)(e), " "] : ["br", t.get(V.key)(e)],
998
+ toDOM: (node) => node.attrs.isInline ? ["span", ctx.get(hardbreakAttr.key)(node), " "] : ["br", ctx.get(hardbreakAttr.key)(node)],
895
999
  parseMarkdown: {
896
- match: ({ type: e }) => e === "break",
897
- runner: (e, r, a) => {
898
- var o;
899
- e.addNode(a, {
900
- isInline: !!((o = r.data) != null && o.isInline)
1000
+ match: ({ type }) => type === "break",
1001
+ runner: (state, node, type) => {
1002
+ var _a;
1003
+ state.addNode(type, {
1004
+ isInline: Boolean(
1005
+ (_a = node.data) == null ? void 0 : _a.isInline
1006
+ )
901
1007
  });
902
1008
  }
903
1009
  },
904
- leafText: () => `
905
- `,
1010
+ leafText: () => "\n",
906
1011
  toMarkdown: {
907
- match: (e) => e.type.name === "hardbreak",
908
- runner: (e, r) => {
909
- r.attrs.isInline ? e.addNode("text", void 0, `
910
- `) : e.addNode("break");
1012
+ match: (node) => node.type.name === "hardbreak",
1013
+ runner: (state, node) => {
1014
+ if (node.attrs.isInline) state.addNode("text", void 0, "\n");
1015
+ else state.addNode("break");
911
1016
  }
912
1017
  }
913
1018
  }));
914
- n(S.node, {
1019
+ withMeta(hardbreakSchema.node, {
915
1020
  displayName: "NodeSchema<hardbreak>",
916
1021
  group: "Hardbreak"
917
1022
  });
918
- n(S.ctx, {
1023
+ withMeta(hardbreakSchema.ctx, {
919
1024
  displayName: "NodeSchemaCtx<hardbreak>",
920
1025
  group: "Hardbreak"
921
1026
  });
922
- const be = c(
1027
+ const insertHardbreakCommand = $command(
923
1028
  "InsertHardbreak",
924
- (t) => () => (e, r) => {
925
- var s;
926
- const { selection: a, tr: o } = e;
927
- if (!(a instanceof Y)) return !1;
928
- if (a.empty) {
929
- const l = a.$from.node();
930
- if (l.childCount > 0 && ((s = l.lastChild) == null ? void 0 : s.type.name) === "hardbreak")
931
- return r == null || r(
932
- o.replaceRangeWith(
933
- a.to - 1,
934
- a.to,
935
- e.schema.node("paragraph")
936
- ).setSelection(tt.near(o.doc.resolve(a.to))).scrollIntoView()
937
- ), !0;
938
- }
939
- return r == null || r(
940
- o.setMeta("hardbreak", !0).replaceSelectionWith(S.type(t).create()).scrollIntoView()
941
- ), !0;
1029
+ (ctx) => () => (state, dispatch) => {
1030
+ var _a;
1031
+ const { selection, tr } = state;
1032
+ if (!(selection instanceof TextSelection)) return false;
1033
+ if (selection.empty) {
1034
+ const node = selection.$from.node();
1035
+ if (node.childCount > 0 && ((_a = node.lastChild) == null ? void 0 : _a.type.name) === "hardbreak") {
1036
+ dispatch == null ? void 0 : dispatch(
1037
+ tr.replaceRangeWith(
1038
+ selection.to - 1,
1039
+ selection.to,
1040
+ state.schema.node("paragraph")
1041
+ ).setSelection(Selection.near(tr.doc.resolve(selection.to))).scrollIntoView()
1042
+ );
1043
+ return true;
1044
+ }
1045
+ }
1046
+ dispatch == null ? void 0 : dispatch(
1047
+ tr.setMeta("hardbreak", true).replaceSelectionWith(hardbreakSchema.type(ctx).create()).scrollIntoView()
1048
+ );
1049
+ return true;
942
1050
  }
943
1051
  );
944
- n(be, {
1052
+ withMeta(insertHardbreakCommand, {
945
1053
  displayName: "Command<insertHardbreakCommand>",
946
1054
  group: "Hardbreak"
947
1055
  });
948
- const Le = f("hardbreakKeymap", {
1056
+ const hardbreakKeymap = $useKeymap("hardbreakKeymap", {
949
1057
  InsertHardbreak: {
950
1058
  shortcuts: "Shift-Enter",
951
- command: (t) => {
952
- const e = t.get(g);
953
- return () => e.call(be.key);
1059
+ command: (ctx) => {
1060
+ const commands2 = ctx.get(commandsCtx);
1061
+ return () => commands2.call(insertHardbreakCommand.key);
954
1062
  }
955
1063
  }
956
1064
  });
957
- n(Le.ctx, {
1065
+ withMeta(hardbreakKeymap.ctx, {
958
1066
  displayName: "KeymapCtx<hardbreak>",
959
1067
  group: "Hardbreak"
960
1068
  });
961
- n(Le.shortcuts, {
1069
+ withMeta(hardbreakKeymap.shortcuts, {
962
1070
  displayName: "Keymap<hardbreak>",
963
1071
  group: "Hardbreak"
964
1072
  });
965
- const xe = N("hr");
966
- n(xe, {
1073
+ const hrAttr = $nodeAttr("hr");
1074
+ withMeta(hrAttr, {
967
1075
  displayName: "Attr<hr>",
968
1076
  group: "Hr"
969
1077
  });
970
- const F = I("hr", (t) => ({
1078
+ const hrSchema = $nodeSchema("hr", (ctx) => ({
971
1079
  group: "block",
972
1080
  parseDOM: [{ tag: "hr" }],
973
- toDOM: (e) => ["hr", t.get(xe.key)(e)],
1081
+ toDOM: (node) => ["hr", ctx.get(hrAttr.key)(node)],
974
1082
  parseMarkdown: {
975
- match: ({ type: e }) => e === "thematicBreak",
976
- runner: (e, r, a) => {
977
- e.addNode(a);
1083
+ match: ({ type }) => type === "thematicBreak",
1084
+ runner: (state, _, type) => {
1085
+ state.addNode(type);
978
1086
  }
979
1087
  },
980
1088
  toMarkdown: {
981
- match: (e) => e.type.name === "hr",
982
- runner: (e) => {
983
- e.addNode("thematicBreak");
1089
+ match: (node) => node.type.name === "hr",
1090
+ runner: (state) => {
1091
+ state.addNode("thematicBreak");
984
1092
  }
985
1093
  }
986
1094
  }));
987
- n(F.node, {
1095
+ withMeta(hrSchema.node, {
988
1096
  displayName: "NodeSchema<hr>",
989
1097
  group: "Hr"
990
1098
  });
991
- n(F.ctx, {
1099
+ withMeta(hrSchema.ctx, {
992
1100
  displayName: "NodeSchemaCtx<hr>",
993
1101
  group: "Hr"
994
1102
  });
995
- const yt = h(
996
- (t) => new et(/^(?:---|___\s|\*\*\*\s)$/, (e, r, a, o) => {
997
- const { tr: s } = e;
998
- return r[0] && s.replaceWith(a - 1, o, F.type(t).create()), s;
1103
+ const insertHrInputRule = $inputRule(
1104
+ (ctx) => new InputRule(/^(?:---|___\s|\*\*\*\s)$/, (state, match, start, end) => {
1105
+ const { tr } = state;
1106
+ if (match[0]) tr.replaceWith(start - 1, end, hrSchema.type(ctx).create());
1107
+ return tr;
999
1108
  })
1000
1109
  );
1001
- n(yt, {
1110
+ withMeta(insertHrInputRule, {
1002
1111
  displayName: "InputRule<insertHrInputRule>",
1003
1112
  group: "Hr"
1004
1113
  });
1005
- const ht = c(
1114
+ const insertHrCommand = $command(
1006
1115
  "InsertHr",
1007
- (t) => () => (e, r) => {
1008
- if (!r) return !0;
1009
- const a = w.node.type(t).create(), { tr: o, selection: s } = e, { from: l } = s, i = F.type(t).create();
1010
- if (!i) return !0;
1011
- const d = o.replaceSelectionWith(i).insert(l, a), m = tt.findFrom(d.doc.resolve(l), 1, !0);
1012
- return m && r(d.setSelection(m).scrollIntoView()), !0;
1116
+ (ctx) => () => (state, dispatch) => {
1117
+ if (!dispatch) return true;
1118
+ const paragraph = paragraphSchema.node.type(ctx).create();
1119
+ const { tr, selection } = state;
1120
+ const { from } = selection;
1121
+ const node = hrSchema.type(ctx).create();
1122
+ if (!node) return true;
1123
+ const _tr = tr.replaceSelectionWith(node).insert(from, paragraph);
1124
+ const sel = Selection.findFrom(_tr.doc.resolve(from), 1, true);
1125
+ if (!sel) return true;
1126
+ dispatch(_tr.setSelection(sel).scrollIntoView());
1127
+ return true;
1013
1128
  }
1014
1129
  );
1015
- n(ht, {
1130
+ withMeta(insertHrCommand, {
1016
1131
  displayName: "Command<insertHrCommand>",
1017
1132
  group: "Hr"
1018
1133
  });
1019
- const Se = N("bulletList");
1020
- n(Se, {
1134
+ const bulletListAttr = $nodeAttr("bulletList");
1135
+ withMeta(bulletListAttr, {
1021
1136
  displayName: "Attr<bulletList>",
1022
1137
  group: "BulletList"
1023
1138
  });
1024
- const T = I("bullet_list", (t) => ({
1025
- content: "listItem+",
1026
- group: "block",
1027
- attrs: {
1028
- spread: {
1029
- default: !1
1030
- }
1031
- },
1032
- parseDOM: [
1033
- {
1034
- tag: "ul",
1035
- getAttrs: (e) => {
1036
- if (!(e instanceof HTMLElement)) throw A(e);
1037
- return {
1038
- spread: e.dataset.spread
1039
- };
1139
+ const bulletListSchema = $nodeSchema("bullet_list", (ctx) => {
1140
+ return {
1141
+ content: "listItem+",
1142
+ group: "block",
1143
+ attrs: {
1144
+ spread: {
1145
+ default: false
1040
1146
  }
1041
- }
1042
- ],
1043
- toDOM: (e) => [
1044
- "ul",
1045
- {
1046
- ...t.get(Se.key)(e),
1047
- "data-spread": e.attrs.spread
1048
1147
  },
1049
- 0
1050
- ],
1051
- parseMarkdown: {
1052
- match: ({ type: e, ordered: r }) => e === "list" && !r,
1053
- runner: (e, r, a) => {
1054
- const o = r.spread != null ? `${r.spread}` : "false";
1055
- e.openNode(a, { spread: o }).next(r.children).closeNode();
1056
- }
1057
- },
1058
- toMarkdown: {
1059
- match: (e) => e.type.name === "bullet_list",
1060
- runner: (e, r) => {
1061
- e.openNode("list", void 0, {
1062
- ordered: !1,
1063
- spread: r.attrs.spread === "true"
1064
- }).next(r.content).closeNode();
1148
+ parseDOM: [
1149
+ {
1150
+ tag: "ul",
1151
+ getAttrs: (dom) => {
1152
+ if (!(dom instanceof HTMLElement)) throw expectDomTypeError(dom);
1153
+ return {
1154
+ spread: dom.dataset.spread
1155
+ };
1156
+ }
1157
+ }
1158
+ ],
1159
+ toDOM: (node) => {
1160
+ return [
1161
+ "ul",
1162
+ {
1163
+ ...ctx.get(bulletListAttr.key)(node),
1164
+ "data-spread": node.attrs.spread
1165
+ },
1166
+ 0
1167
+ ];
1168
+ },
1169
+ parseMarkdown: {
1170
+ match: ({ type, ordered }) => type === "list" && !ordered,
1171
+ runner: (state, node, type) => {
1172
+ const spread = node.spread != null ? `${node.spread}` : "false";
1173
+ state.openNode(type, { spread }).next(node.children).closeNode();
1174
+ }
1175
+ },
1176
+ toMarkdown: {
1177
+ match: (node) => node.type.name === "bullet_list",
1178
+ runner: (state, node) => {
1179
+ state.openNode("list", void 0, {
1180
+ ordered: false,
1181
+ spread: node.attrs.spread === "true"
1182
+ }).next(node.content).closeNode();
1183
+ }
1065
1184
  }
1066
- }
1067
- }));
1068
- n(T.node, {
1185
+ };
1186
+ });
1187
+ withMeta(bulletListSchema.node, {
1069
1188
  displayName: "NodeSchema<bulletList>",
1070
1189
  group: "BulletList"
1071
1190
  });
1072
- n(T.ctx, {
1191
+ withMeta(bulletListSchema.ctx, {
1073
1192
  displayName: "NodeSchemaCtx<bulletList>",
1074
1193
  group: "BulletList"
1075
1194
  });
1076
- const ft = h(
1077
- (t) => X(/^\s*([-+*])\s$/, T.type(t))
1195
+ const wrapInBulletListInputRule = $inputRule(
1196
+ (ctx) => wrappingInputRule(/^\s*([-+*])\s$/, bulletListSchema.type(ctx))
1078
1197
  );
1079
- n(ft, {
1198
+ withMeta(wrapInBulletListInputRule, {
1080
1199
  displayName: "InputRule<wrapInBulletListInputRule>",
1081
1200
  group: "BulletList"
1082
1201
  });
1083
- const Ae = c(
1202
+ const wrapInBulletListCommand = $command(
1084
1203
  "WrapInBulletList",
1085
- (t) => () => Q(T.type(t))
1204
+ (ctx) => () => wrapIn(bulletListSchema.type(ctx))
1086
1205
  );
1087
- n(Ae, {
1206
+ withMeta(wrapInBulletListCommand, {
1088
1207
  displayName: "Command<wrapInBulletListCommand>",
1089
1208
  group: "BulletList"
1090
1209
  });
1091
- const we = f("bulletListKeymap", {
1210
+ const bulletListKeymap = $useKeymap("bulletListKeymap", {
1092
1211
  WrapInBulletList: {
1093
1212
  shortcuts: "Mod-Alt-8",
1094
- command: (t) => {
1095
- const e = t.get(g);
1096
- return () => e.call(Ae.key);
1213
+ command: (ctx) => {
1214
+ const commands2 = ctx.get(commandsCtx);
1215
+ return () => commands2.call(wrapInBulletListCommand.key);
1097
1216
  }
1098
1217
  }
1099
1218
  });
1100
- n(we.ctx, {
1219
+ withMeta(bulletListKeymap.ctx, {
1101
1220
  displayName: "KeymapCtx<bulletListKeymap>",
1102
1221
  group: "BulletList"
1103
1222
  });
1104
- n(we.shortcuts, {
1223
+ withMeta(bulletListKeymap.shortcuts, {
1105
1224
  displayName: "Keymap<bulletListKeymap>",
1106
1225
  group: "BulletList"
1107
1226
  });
1108
- const He = N("orderedList");
1109
- n(He, {
1227
+ const orderedListAttr = $nodeAttr("orderedList");
1228
+ withMeta(orderedListAttr, {
1110
1229
  displayName: "Attr<orderedList>",
1111
1230
  group: "OrderedList"
1112
1231
  });
1113
- const K = I("ordered_list", (t) => ({
1232
+ const orderedListSchema = $nodeSchema("ordered_list", (ctx) => ({
1114
1233
  content: "listItem+",
1115
1234
  group: "block",
1116
1235
  attrs: {
@@ -1118,101 +1237,103 @@ const K = I("ordered_list", (t) => ({
1118
1237
  default: 1
1119
1238
  },
1120
1239
  spread: {
1121
- default: !1
1240
+ default: false
1122
1241
  }
1123
1242
  },
1124
1243
  parseDOM: [
1125
1244
  {
1126
1245
  tag: "ol",
1127
- getAttrs: (e) => {
1128
- if (!(e instanceof HTMLElement)) throw A(e);
1246
+ getAttrs: (dom) => {
1247
+ if (!(dom instanceof HTMLElement)) throw expectDomTypeError(dom);
1129
1248
  return {
1130
- spread: e.dataset.spread,
1131
- order: e.hasAttribute("start") ? Number(e.getAttribute("start")) : 1
1249
+ spread: dom.dataset.spread,
1250
+ order: dom.hasAttribute("start") ? Number(dom.getAttribute("start")) : 1
1132
1251
  };
1133
1252
  }
1134
1253
  }
1135
1254
  ],
1136
- toDOM: (e) => [
1255
+ toDOM: (node) => [
1137
1256
  "ol",
1138
1257
  {
1139
- ...t.get(He.key)(e),
1140
- ...e.attrs.order === 1 ? {} : e.attrs.order,
1141
- "data-spread": e.attrs.spread
1258
+ ...ctx.get(orderedListAttr.key)(node),
1259
+ ...node.attrs.order === 1 ? {} : node.attrs.order,
1260
+ "data-spread": node.attrs.spread
1142
1261
  },
1143
1262
  0
1144
1263
  ],
1145
1264
  parseMarkdown: {
1146
- match: ({ type: e, ordered: r }) => e === "list" && !!r,
1147
- runner: (e, r, a) => {
1148
- const o = r.spread != null ? `${r.spread}` : "true";
1149
- e.openNode(a, { spread: o }).next(r.children).closeNode();
1265
+ match: ({ type, ordered }) => type === "list" && !!ordered,
1266
+ runner: (state, node, type) => {
1267
+ const spread = node.spread != null ? `${node.spread}` : "true";
1268
+ state.openNode(type, { spread }).next(node.children).closeNode();
1150
1269
  }
1151
1270
  },
1152
1271
  toMarkdown: {
1153
- match: (e) => e.type.name === "ordered_list",
1154
- runner: (e, r) => {
1155
- e.openNode("list", void 0, {
1156
- ordered: !0,
1272
+ match: (node) => node.type.name === "ordered_list",
1273
+ runner: (state, node) => {
1274
+ state.openNode("list", void 0, {
1275
+ ordered: true,
1157
1276
  start: 1,
1158
- spread: r.attrs.spread === "true"
1159
- }), e.next(r.content), e.closeNode();
1277
+ spread: node.attrs.spread === "true"
1278
+ });
1279
+ state.next(node.content);
1280
+ state.closeNode();
1160
1281
  }
1161
1282
  }
1162
1283
  }));
1163
- n(K.node, {
1284
+ withMeta(orderedListSchema.node, {
1164
1285
  displayName: "NodeSchema<orderedList>",
1165
1286
  group: "OrderedList"
1166
1287
  });
1167
- n(K.ctx, {
1288
+ withMeta(orderedListSchema.ctx, {
1168
1289
  displayName: "NodeSchemaCtx<orderedList>",
1169
1290
  group: "OrderedList"
1170
1291
  });
1171
- const Nt = h(
1172
- (t) => X(
1292
+ const wrapInOrderedListInputRule = $inputRule(
1293
+ (ctx) => wrappingInputRule(
1173
1294
  /^\s*(\d+)\.\s$/,
1174
- K.type(t),
1175
- (e) => ({ order: Number(e[1]) }),
1176
- (e, r) => r.childCount + r.attrs.order === Number(e[1])
1295
+ orderedListSchema.type(ctx),
1296
+ (match) => ({ order: Number(match[1]) }),
1297
+ (match, node) => node.childCount + node.attrs.order === Number(match[1])
1177
1298
  )
1178
1299
  );
1179
- n(Nt, {
1300
+ withMeta(wrapInOrderedListInputRule, {
1180
1301
  displayName: "InputRule<wrapInOrderedListInputRule>",
1181
1302
  group: "OrderedList"
1182
1303
  });
1183
- const Be = c(
1304
+ const wrapInOrderedListCommand = $command(
1184
1305
  "WrapInOrderedList",
1185
- (t) => () => Q(K.type(t))
1306
+ (ctx) => () => wrapIn(orderedListSchema.type(ctx))
1186
1307
  );
1187
- n(Be, {
1308
+ withMeta(wrapInOrderedListCommand, {
1188
1309
  displayName: "Command<wrapInOrderedListCommand>",
1189
1310
  group: "OrderedList"
1190
1311
  });
1191
- const Re = f("orderedListKeymap", {
1312
+ const orderedListKeymap = $useKeymap("orderedListKeymap", {
1192
1313
  WrapInOrderedList: {
1193
1314
  shortcuts: "Mod-Alt-7",
1194
- command: (t) => {
1195
- const e = t.get(g);
1196
- return () => e.call(Be.key);
1315
+ command: (ctx) => {
1316
+ const commands2 = ctx.get(commandsCtx);
1317
+ return () => commands2.call(wrapInOrderedListCommand.key);
1197
1318
  }
1198
1319
  }
1199
1320
  });
1200
- n(Re.ctx, {
1321
+ withMeta(orderedListKeymap.ctx, {
1201
1322
  displayName: "KeymapCtx<orderedList>",
1202
1323
  group: "OrderedList"
1203
1324
  });
1204
- n(Re.shortcuts, {
1325
+ withMeta(orderedListKeymap.shortcuts, {
1205
1326
  displayName: "Keymap<orderedList>",
1206
1327
  group: "OrderedList"
1207
1328
  });
1208
- const Oe = N("listItem");
1209
- n(Oe, {
1329
+ const listItemAttr = $nodeAttr("listItem");
1330
+ withMeta(listItemAttr, {
1210
1331
  displayName: "Attr<listItem>",
1211
1332
  group: "ListItem"
1212
1333
  });
1213
- const M = I("list_item", (t) => ({
1334
+ const listItemSchema = $nodeSchema("list_item", (ctx) => ({
1214
1335
  group: "listItem",
1215
- content: "(paragraph|blockquote) block*",
1336
+ content: "paragraph block*",
1216
1337
  attrs: {
1217
1338
  label: {
1218
1339
  default: "•"
@@ -1224,707 +1345,833 @@ const M = I("list_item", (t) => ({
1224
1345
  default: "true"
1225
1346
  }
1226
1347
  },
1227
- defining: !0,
1348
+ defining: true,
1228
1349
  parseDOM: [
1229
1350
  {
1230
1351
  tag: "li",
1231
- getAttrs: (e) => {
1232
- if (!(e instanceof HTMLElement)) throw A(e);
1352
+ getAttrs: (dom) => {
1353
+ if (!(dom instanceof HTMLElement)) throw expectDomTypeError(dom);
1233
1354
  return {
1234
- label: e.dataset.label,
1235
- listType: e.dataset.listType,
1236
- spread: e.dataset.spread
1355
+ label: dom.dataset.label,
1356
+ listType: dom.dataset.listType,
1357
+ spread: dom.dataset.spread
1237
1358
  };
1238
1359
  }
1239
1360
  }
1240
1361
  ],
1241
- toDOM: (e) => [
1362
+ toDOM: (node) => [
1242
1363
  "li",
1243
1364
  {
1244
- ...t.get(Oe.key)(e),
1245
- "data-label": e.attrs.label,
1246
- "data-list-type": e.attrs.listType,
1247
- "data-spread": e.attrs.spread
1365
+ ...ctx.get(listItemAttr.key)(node),
1366
+ "data-label": node.attrs.label,
1367
+ "data-list-type": node.attrs.listType,
1368
+ "data-spread": node.attrs.spread
1248
1369
  },
1249
1370
  0
1250
1371
  ],
1251
1372
  parseMarkdown: {
1252
- match: ({ type: e }) => e === "listItem",
1253
- runner: (e, r, a) => {
1254
- const o = r.label != null ? `${r.label}.` : "•", s = r.label != null ? "ordered" : "bullet", l = r.spread != null ? `${r.spread}` : "true";
1255
- e.openNode(a, { label: o, listType: s, spread: l }), e.next(r.children), e.closeNode();
1373
+ match: ({ type }) => type === "listItem",
1374
+ runner: (state, node, type) => {
1375
+ const label = node.label != null ? `${node.label}.` : "•";
1376
+ const listType = node.label != null ? "ordered" : "bullet";
1377
+ const spread = node.spread != null ? `${node.spread}` : "true";
1378
+ state.openNode(type, { label, listType, spread });
1379
+ state.next(node.children);
1380
+ state.closeNode();
1256
1381
  }
1257
1382
  },
1258
1383
  toMarkdown: {
1259
- match: (e) => e.type.name === "list_item",
1260
- runner: (e, r) => {
1261
- e.openNode("listItem", void 0, {
1262
- spread: r.attrs.spread === "true"
1263
- }), e.next(r.content), e.closeNode();
1384
+ match: (node) => node.type.name === "list_item",
1385
+ runner: (state, node) => {
1386
+ state.openNode("listItem", void 0, {
1387
+ spread: node.attrs.spread === "true"
1388
+ });
1389
+ state.next(node.content);
1390
+ state.closeNode();
1264
1391
  }
1265
1392
  }
1266
1393
  }));
1267
- n(M.node, {
1394
+ withMeta(listItemSchema.node, {
1268
1395
  displayName: "NodeSchema<listItem>",
1269
1396
  group: "ListItem"
1270
1397
  });
1271
- n(M.ctx, {
1398
+ withMeta(listItemSchema.ctx, {
1272
1399
  displayName: "NodeSchemaCtx<listItem>",
1273
1400
  group: "ListItem"
1274
1401
  });
1275
- const Te = c(
1402
+ const sinkListItemCommand = $command(
1276
1403
  "SinkListItem",
1277
- (t) => () => Rt(M.type(t))
1404
+ (ctx) => () => sinkListItem(listItemSchema.type(ctx))
1278
1405
  );
1279
- n(Te, {
1406
+ withMeta(sinkListItemCommand, {
1280
1407
  displayName: "Command<sinkListItemCommand>",
1281
1408
  group: "ListItem"
1282
1409
  });
1283
- const Ke = c(
1410
+ const liftListItemCommand = $command(
1284
1411
  "LiftListItem",
1285
- (t) => () => rt(M.type(t))
1412
+ (ctx) => () => liftListItem(listItemSchema.type(ctx))
1286
1413
  );
1287
- n(Ke, {
1414
+ withMeta(liftListItemCommand, {
1288
1415
  displayName: "Command<liftListItemCommand>",
1289
1416
  group: "ListItem"
1290
1417
  });
1291
- const De = c(
1418
+ const splitListItemCommand = $command(
1292
1419
  "SplitListItem",
1293
- (t) => () => Ot(M.type(t))
1420
+ (ctx) => () => splitListItem(listItemSchema.type(ctx))
1294
1421
  );
1295
- n(De, {
1422
+ withMeta(splitListItemCommand, {
1296
1423
  displayName: "Command<splitListItemCommand>",
1297
1424
  group: "ListItem"
1298
1425
  });
1299
- function $t(t) {
1300
- return (e, r, a) => {
1301
- const { selection: o } = e;
1302
- if (!(o instanceof Y)) return !1;
1303
- const { empty: s, $from: l } = o;
1304
- if (!s || l.parentOffset !== 0) return !1;
1305
- const i = l.node(-1);
1306
- return i.type !== M.type(t) || i.firstChild !== l.node() || l.node(-2).childCount > 1 ? !1 : rt(M.type(t))(e, r, a);
1426
+ function liftFirstListItem(ctx) {
1427
+ return (state, dispatch, view) => {
1428
+ const { selection } = state;
1429
+ if (!(selection instanceof TextSelection)) return false;
1430
+ const { empty, $from } = selection;
1431
+ if (!empty || $from.parentOffset !== 0) return false;
1432
+ const parentItem = $from.node(-1);
1433
+ if (parentItem.type !== listItemSchema.type(ctx) || parentItem.firstChild !== $from.node())
1434
+ return false;
1435
+ const list = $from.node(-2);
1436
+ if (list.childCount > 1) return false;
1437
+ return liftListItem(listItemSchema.type(ctx))(state, dispatch, view);
1307
1438
  };
1308
1439
  }
1309
- const ve = c(
1440
+ const liftFirstListItemCommand = $command(
1310
1441
  "LiftFirstListItem",
1311
- (t) => () => $t(t)
1442
+ (ctx) => () => liftFirstListItem(ctx)
1312
1443
  );
1313
- n(ve, {
1444
+ withMeta(liftFirstListItemCommand, {
1314
1445
  displayName: "Command<liftFirstListItemCommand>",
1315
1446
  group: "ListItem"
1316
1447
  });
1317
- const _e = f("listItemKeymap", {
1448
+ const listItemKeymap = $useKeymap("listItemKeymap", {
1318
1449
  NextListItem: {
1319
1450
  shortcuts: "Enter",
1320
- command: (t) => {
1321
- const e = t.get(g);
1322
- return () => e.call(De.key);
1451
+ command: (ctx) => {
1452
+ const commands2 = ctx.get(commandsCtx);
1453
+ return () => commands2.call(splitListItemCommand.key);
1323
1454
  }
1324
1455
  },
1325
1456
  SinkListItem: {
1326
1457
  shortcuts: ["Tab", "Mod-]"],
1327
- command: (t) => {
1328
- const e = t.get(g);
1329
- return () => e.call(Te.key);
1458
+ command: (ctx) => {
1459
+ const commands2 = ctx.get(commandsCtx);
1460
+ return () => commands2.call(sinkListItemCommand.key);
1330
1461
  }
1331
1462
  },
1332
1463
  LiftListItem: {
1333
1464
  shortcuts: ["Shift-Tab", "Mod-["],
1334
- command: (t) => {
1335
- const e = t.get(g);
1336
- return () => e.call(Ke.key);
1465
+ command: (ctx) => {
1466
+ const commands2 = ctx.get(commandsCtx);
1467
+ return () => commands2.call(liftListItemCommand.key);
1337
1468
  }
1338
1469
  },
1339
1470
  LiftFirstListItem: {
1340
1471
  shortcuts: ["Backspace", "Delete"],
1341
- command: (t) => {
1342
- const e = t.get(g);
1343
- return () => e.call(ve.key);
1472
+ command: (ctx) => {
1473
+ const commands2 = ctx.get(commandsCtx);
1474
+ return () => commands2.call(liftFirstListItemCommand.key);
1344
1475
  }
1345
1476
  }
1346
1477
  });
1347
- n(_e.ctx, {
1478
+ withMeta(listItemKeymap.ctx, {
1348
1479
  displayName: "KeymapCtx<listItem>",
1349
1480
  group: "ListItem"
1350
1481
  });
1351
- n(_e.shortcuts, {
1482
+ withMeta(listItemKeymap.shortcuts, {
1352
1483
  displayName: "Keymap<listItem>",
1353
1484
  group: "ListItem"
1354
1485
  });
1355
- const It = Qe("text", () => ({
1486
+ const textSchema = $node("text", () => ({
1356
1487
  group: "inline",
1357
1488
  parseMarkdown: {
1358
- match: ({ type: t }) => t === "text",
1359
- runner: (t, e) => {
1360
- t.addText(e.value);
1489
+ match: ({ type }) => type === "text",
1490
+ runner: (state, node) => {
1491
+ state.addText(node.value);
1361
1492
  }
1362
1493
  },
1363
1494
  toMarkdown: {
1364
- match: (t) => t.type.name === "text",
1365
- runner: (t, e) => {
1366
- t.addNode("text", void 0, e.text);
1495
+ match: (node) => node.type.name === "text",
1496
+ runner: (state, node) => {
1497
+ state.addNode("text", void 0, node.text);
1367
1498
  }
1368
1499
  }
1369
1500
  }));
1370
- n(It, {
1501
+ withMeta(textSchema, {
1371
1502
  displayName: "NodeSchema<text>",
1372
1503
  group: "Text"
1373
1504
  });
1374
- const Ee = N("html");
1375
- n(Ee, {
1505
+ const htmlAttr = $nodeAttr("html");
1506
+ withMeta(htmlAttr, {
1376
1507
  displayName: "Attr<html>",
1377
1508
  group: "Html"
1378
1509
  });
1379
- const Pe = I("html", (t) => ({
1380
- atom: !0,
1381
- group: "inline",
1382
- inline: !0,
1383
- attrs: {
1384
- value: {
1385
- default: ""
1386
- }
1387
- },
1388
- toDOM: (e) => {
1389
- const r = document.createElement("span"), a = {
1390
- ...t.get(Ee.key)(e),
1391
- "data-value": e.attrs.value,
1392
- "data-type": "html"
1393
- };
1394
- return r.textContent = e.attrs.value, ["span", a, e.attrs.value];
1395
- },
1396
- parseDOM: [
1397
- {
1398
- tag: 'span[data-type="html"]',
1399
- getAttrs: (e) => ({
1400
- value: e.dataset.value ?? ""
1401
- })
1402
- }
1403
- ],
1404
- parseMarkdown: {
1405
- match: ({ type: e }) => e === "html",
1406
- runner: (e, r, a) => {
1407
- e.addNode(a, { value: r.value });
1408
- }
1409
- },
1410
- toMarkdown: {
1411
- match: (e) => e.type.name === "html",
1412
- runner: (e, r) => {
1413
- e.addNode("html", void 0, r.attrs.value);
1510
+ const htmlSchema = $nodeSchema("html", (ctx) => {
1511
+ return {
1512
+ atom: true,
1513
+ group: "inline",
1514
+ inline: true,
1515
+ attrs: {
1516
+ value: {
1517
+ default: ""
1518
+ }
1519
+ },
1520
+ toDOM: (node) => {
1521
+ const span = document.createElement("span");
1522
+ const attr = {
1523
+ ...ctx.get(htmlAttr.key)(node),
1524
+ "data-value": node.attrs.value,
1525
+ "data-type": "html"
1526
+ };
1527
+ span.textContent = node.attrs.value;
1528
+ return ["span", attr, node.attrs.value];
1529
+ },
1530
+ parseDOM: [
1531
+ {
1532
+ tag: 'span[data-type="html"]',
1533
+ getAttrs: (dom) => {
1534
+ return {
1535
+ value: dom.dataset.value ?? ""
1536
+ };
1537
+ }
1538
+ }
1539
+ ],
1540
+ parseMarkdown: {
1541
+ match: ({ type }) => Boolean(type === "html"),
1542
+ runner: (state, node, type) => {
1543
+ state.addNode(type, { value: node.value });
1544
+ }
1545
+ },
1546
+ toMarkdown: {
1547
+ match: (node) => node.type.name === "html",
1548
+ runner: (state, node) => {
1549
+ state.addNode("html", void 0, node.attrs.value);
1550
+ }
1414
1551
  }
1415
- }
1416
- }));
1417
- n(Pe.node, {
1552
+ };
1553
+ });
1554
+ withMeta(htmlSchema.node, {
1418
1555
  displayName: "NodeSchema<html>",
1419
1556
  group: "Html"
1420
1557
  });
1421
- n(Pe.ctx, {
1558
+ withMeta(htmlSchema.ctx, {
1422
1559
  displayName: "NodeSchemaCtx<html>",
1423
1560
  group: "Html"
1424
1561
  });
1425
- const qt = [
1426
- mt,
1427
- me,
1428
- w,
1429
- z,
1430
- ce,
1431
- H,
1432
- V,
1433
- S,
1434
- ye,
1435
- q,
1436
- Ne,
1437
- W,
1438
- xe,
1439
- F,
1440
- Me,
1441
- O,
1442
- Se,
1443
- T,
1444
- He,
1445
- K,
1446
- Oe,
1447
- M,
1448
- ee,
1449
- R,
1450
- ae,
1451
- $,
1452
- se,
1453
- x,
1454
- de,
1455
- B,
1456
- Ee,
1457
- Pe,
1458
- It
1459
- ].flat(), Wt = [
1460
- pt,
1461
- ft,
1462
- Nt,
1463
- ct,
1464
- yt,
1465
- ut
1466
- ].flat(), Ft = [
1467
- nt,
1468
- ot,
1469
- lt,
1470
- st
1471
- ], Vt = [
1472
- ue,
1473
- he,
1474
- L,
1475
- ge,
1476
- Ie,
1477
- be,
1478
- ht,
1479
- gt,
1480
- kt,
1481
- Be,
1482
- Ae,
1483
- Te,
1484
- De,
1485
- Ke,
1486
- ve,
1487
- te,
1488
- le,
1489
- ne,
1490
- it,
1491
- dt
1492
- ], Ut = [
1493
- fe,
1494
- Ce,
1495
- Le,
1496
- ke,
1497
- _e,
1498
- Re,
1499
- we,
1500
- pe,
1501
- re,
1502
- ie,
1503
- oe
1504
- ].flat(), $e = v(
1562
+ const schema = [
1563
+ docSchema,
1564
+ paragraphAttr,
1565
+ paragraphSchema,
1566
+ headingIdGenerator,
1567
+ headingAttr,
1568
+ headingSchema,
1569
+ hardbreakAttr,
1570
+ hardbreakSchema,
1571
+ blockquoteAttr,
1572
+ blockquoteSchema,
1573
+ codeBlockAttr,
1574
+ codeBlockSchema,
1575
+ hrAttr,
1576
+ hrSchema,
1577
+ imageAttr,
1578
+ imageSchema,
1579
+ bulletListAttr,
1580
+ bulletListSchema,
1581
+ orderedListAttr,
1582
+ orderedListSchema,
1583
+ listItemAttr,
1584
+ listItemSchema,
1585
+ emphasisAttr,
1586
+ emphasisSchema,
1587
+ strongAttr,
1588
+ strongSchema,
1589
+ inlineCodeAttr,
1590
+ inlineCodeSchema,
1591
+ linkAttr,
1592
+ linkSchema,
1593
+ htmlAttr,
1594
+ htmlSchema,
1595
+ textSchema
1596
+ ].flat();
1597
+ const inputRules = [
1598
+ wrapInBlockquoteInputRule,
1599
+ wrapInBulletListInputRule,
1600
+ wrapInOrderedListInputRule,
1601
+ createCodeBlockInputRule,
1602
+ insertHrInputRule,
1603
+ wrapInHeadingInputRule
1604
+ ].flat();
1605
+ const markInputRules = [
1606
+ emphasisStarInputRule,
1607
+ emphasisUnderscoreInputRule,
1608
+ inlineCodeInputRule,
1609
+ strongInputRule
1610
+ ];
1611
+ const commands = [
1612
+ turnIntoTextCommand,
1613
+ wrapInBlockquoteCommand,
1614
+ wrapInHeadingCommand,
1615
+ downgradeHeadingCommand,
1616
+ createCodeBlockCommand,
1617
+ insertHardbreakCommand,
1618
+ insertHrCommand,
1619
+ insertImageCommand,
1620
+ updateImageCommand,
1621
+ wrapInOrderedListCommand,
1622
+ wrapInBulletListCommand,
1623
+ sinkListItemCommand,
1624
+ splitListItemCommand,
1625
+ liftListItemCommand,
1626
+ liftFirstListItemCommand,
1627
+ toggleEmphasisCommand,
1628
+ toggleInlineCodeCommand,
1629
+ toggleStrongCommand,
1630
+ toggleLinkCommand,
1631
+ updateLinkCommand
1632
+ ];
1633
+ const keymap = [
1634
+ blockquoteKeymap,
1635
+ codeBlockKeymap,
1636
+ hardbreakKeymap,
1637
+ headingKeymap,
1638
+ listItemKeymap,
1639
+ orderedListKeymap,
1640
+ bulletListKeymap,
1641
+ paragraphKeymap,
1642
+ emphasisKeymap,
1643
+ inlineCodeKeymap,
1644
+ strongKeymap
1645
+ ].flat();
1646
+ const remarkAddOrderInListPlugin = $remark(
1505
1647
  "remarkAddOrderInList",
1506
- () => () => (t) => {
1507
- Z(t, "list", (e) => {
1508
- if (e.ordered) {
1509
- const r = e.start ?? 1;
1510
- e.children.forEach((a, o) => {
1511
- a.label = o + r;
1648
+ () => () => (tree) => {
1649
+ visit(tree, "list", (node) => {
1650
+ if (node.ordered) {
1651
+ const start = node.start ?? 1;
1652
+ node.children.forEach((child, index) => {
1653
+ child.label = index + start;
1512
1654
  });
1513
1655
  }
1514
1656
  });
1515
1657
  }
1516
1658
  );
1517
- n($e.plugin, {
1659
+ withMeta(remarkAddOrderInListPlugin.plugin, {
1518
1660
  displayName: "Remark<remarkAddOrderInListPlugin>",
1519
1661
  group: "Remark"
1520
1662
  });
1521
- n($e.options, {
1663
+ withMeta(remarkAddOrderInListPlugin.options, {
1522
1664
  displayName: "RemarkConfig<remarkAddOrderInListPlugin>",
1523
1665
  group: "Remark"
1524
1666
  });
1525
- const qe = v(
1667
+ const remarkLineBreak = $remark(
1526
1668
  "remarkLineBreak",
1527
- () => () => (t) => {
1528
- const e = /[\t ]*(?:\r?\n|\r)/g;
1529
- Z(
1530
- t,
1669
+ () => () => (tree) => {
1670
+ const find = /[\t ]*(?:\r?\n|\r)/g;
1671
+ visit(
1672
+ tree,
1531
1673
  "text",
1532
- (r, a, o) => {
1533
- if (!r.value || typeof r.value != "string") return;
1534
- const s = [];
1535
- let l = 0;
1536
- e.lastIndex = 0;
1537
- let i = e.exec(r.value);
1538
- for (; i; ) {
1539
- const m = i.index;
1540
- l !== m && s.push({
1541
- type: "text",
1542
- value: r.value.slice(l, m)
1543
- }), s.push({ type: "break", data: { isInline: !0 } }), l = m + i[0].length, i = e.exec(r.value);
1674
+ (node, index, parent) => {
1675
+ if (!node.value || typeof node.value !== "string") return;
1676
+ const result = [];
1677
+ let start = 0;
1678
+ find.lastIndex = 0;
1679
+ let match = find.exec(node.value);
1680
+ while (match) {
1681
+ const position = match.index;
1682
+ if (start !== position)
1683
+ result.push({
1684
+ type: "text",
1685
+ value: node.value.slice(start, position)
1686
+ });
1687
+ result.push({ type: "break", data: { isInline: true } });
1688
+ start = position + match[0].length;
1689
+ match = find.exec(node.value);
1544
1690
  }
1545
- if (s.length > 0 && o && typeof a == "number")
1546
- return l < r.value.length && s.push({ type: "text", value: r.value.slice(l) }), o.children.splice(a, 1, ...s), a + s.length;
1691
+ const hasResultAndIndex = result.length > 0 && parent && typeof index === "number";
1692
+ if (!hasResultAndIndex) return;
1693
+ if (start < node.value.length)
1694
+ result.push({ type: "text", value: node.value.slice(start) });
1695
+ parent.children.splice(index, 1, ...result);
1696
+ return index + result.length;
1547
1697
  }
1548
1698
  );
1549
1699
  }
1550
1700
  );
1551
- n(qe.plugin, {
1701
+ withMeta(remarkLineBreak.plugin, {
1552
1702
  displayName: "Remark<remarkLineBreak>",
1553
1703
  group: "Remark"
1554
1704
  });
1555
- n(qe.options, {
1705
+ withMeta(remarkLineBreak.options, {
1556
1706
  displayName: "RemarkConfig<remarkLineBreak>",
1557
1707
  group: "Remark"
1558
1708
  });
1559
- const We = v(
1709
+ const remarkInlineLinkPlugin = $remark(
1560
1710
  "remarkInlineLink",
1561
- () => Dt
1711
+ () => remarkInlineLinks
1562
1712
  );
1563
- n(We.plugin, {
1713
+ withMeta(remarkInlineLinkPlugin.plugin, {
1564
1714
  displayName: "Remark<remarkInlineLinkPlugin>",
1565
1715
  group: "Remark"
1566
1716
  });
1567
- n(We.options, {
1717
+ withMeta(remarkInlineLinkPlugin.options, {
1568
1718
  displayName: "RemarkConfig<remarkInlineLinkPlugin>",
1569
1719
  group: "Remark"
1570
1720
  });
1571
- const Gt = (t) => !!t.children, jt = (t) => t.type === "html";
1572
- function zt(t, e) {
1573
- return r(t, 0, null)[0];
1574
- function r(a, o, s) {
1575
- if (Gt(a)) {
1576
- const l = [];
1577
- for (let i = 0, d = a.children.length; i < d; i++) {
1578
- const m = a.children[i];
1579
- if (m) {
1580
- const u = r(m, i, a);
1581
- if (u)
1582
- for (let p = 0, k = u.length; p < k; p++) {
1583
- const C = u[p];
1584
- C && l.push(C);
1721
+ const isParent = (node) => !!node.children;
1722
+ const isHTML = (node) => node.type === "html";
1723
+ function flatMapWithDepth(ast, fn) {
1724
+ return transform(ast, 0, null)[0];
1725
+ function transform(node, index, parent) {
1726
+ if (isParent(node)) {
1727
+ const out = [];
1728
+ for (let i = 0, n = node.children.length; i < n; i++) {
1729
+ const nthChild = node.children[i];
1730
+ if (nthChild) {
1731
+ const xs = transform(nthChild, i, node);
1732
+ if (xs) {
1733
+ for (let j = 0, m = xs.length; j < m; j++) {
1734
+ const item = xs[j];
1735
+ if (item) out.push(item);
1585
1736
  }
1737
+ }
1586
1738
  }
1587
1739
  }
1588
- a.children = l;
1740
+ node.children = out;
1589
1741
  }
1590
- return e(a, o, s);
1742
+ return fn(node, index, parent);
1591
1743
  }
1592
1744
  }
1593
- const Fe = v(
1745
+ const remarkHtmlTransformer = $remark(
1594
1746
  "remarkHTMLTransformer",
1595
- () => () => (t) => {
1596
- zt(t, (e, r, a) => jt(e) ? ((a == null ? void 0 : a.type) === "root" && (e.children = [{ ...e }], delete e.value, e.type = "paragraph"), [e]) : [e]);
1747
+ () => () => (tree) => {
1748
+ flatMapWithDepth(tree, (node, _index, parent) => {
1749
+ if (!isHTML(node)) return [node];
1750
+ if ((parent == null ? void 0 : parent.type) === "root") {
1751
+ node.children = [{ ...node }];
1752
+ delete node.value;
1753
+ node.type = "paragraph";
1754
+ }
1755
+ return [node];
1756
+ });
1597
1757
  }
1598
1758
  );
1599
- n(Fe.plugin, {
1759
+ withMeta(remarkHtmlTransformer.plugin, {
1600
1760
  displayName: "Remark<remarkHtmlTransformer>",
1601
1761
  group: "Remark"
1602
1762
  });
1603
- n(Fe.options, {
1763
+ withMeta(remarkHtmlTransformer.options, {
1604
1764
  displayName: "RemarkConfig<remarkHtmlTransformer>",
1605
1765
  group: "Remark"
1606
1766
  });
1607
- const Ve = v(
1767
+ const remarkMarker = $remark(
1608
1768
  "remarkMarker",
1609
- () => () => (t, e) => {
1610
- const r = (a) => e.value.charAt(a.position.start.offset);
1611
- Z(
1612
- t,
1613
- (a) => ["strong", "emphasis"].includes(a.type),
1614
- (a) => {
1615
- a.marker = r(a);
1769
+ () => () => (tree, file) => {
1770
+ const getMarker = (node) => {
1771
+ return file.value.charAt(node.position.start.offset);
1772
+ };
1773
+ visit(
1774
+ tree,
1775
+ (node) => ["strong", "emphasis"].includes(node.type),
1776
+ (node) => {
1777
+ node.marker = getMarker(node);
1616
1778
  }
1617
1779
  );
1618
1780
  }
1619
1781
  );
1620
- n(Ve.plugin, {
1782
+ withMeta(remarkMarker.plugin, {
1621
1783
  displayName: "Remark<remarkMarker>",
1622
1784
  group: "Remark"
1623
1785
  });
1624
- n(Ve.options, {
1786
+ withMeta(remarkMarker.options, {
1625
1787
  displayName: "RemarkConfig<remarkMarker>",
1626
1788
  group: "Remark"
1627
1789
  });
1628
- const Ct = _(() => {
1629
- let t = !1;
1630
- const e = new E(
1790
+ const inlineNodesCursorPlugin = $prose(() => {
1791
+ let lock = false;
1792
+ const inlineNodesCursorPluginKey = new PluginKey(
1631
1793
  "MILKDOWN_INLINE_NODES_CURSOR"
1632
- ), r = new P({
1633
- key: e,
1794
+ );
1795
+ const inlineNodesCursorPlugin2 = new Plugin({
1796
+ key: inlineNodesCursorPluginKey,
1634
1797
  state: {
1635
1798
  init() {
1636
- return !1;
1799
+ return false;
1637
1800
  },
1638
- apply(a) {
1639
- if (!a.selection.empty) return !1;
1640
- const o = a.selection.$from, s = o.nodeBefore, l = o.nodeAfter;
1641
- return !!(s && l && s.isInline && !s.isText && l.isInline && !l.isText);
1801
+ apply(tr) {
1802
+ if (!tr.selection.empty) return false;
1803
+ const pos = tr.selection.$from;
1804
+ const left = pos.nodeBefore;
1805
+ const right = pos.nodeAfter;
1806
+ if (left && right && left.isInline && !left.isText && right.isInline && !right.isText)
1807
+ return true;
1808
+ return false;
1642
1809
  }
1643
1810
  },
1644
1811
  props: {
1645
1812
  handleDOMEvents: {
1646
- compositionend: (a, o) => t ? (t = !1, requestAnimationFrame(() => {
1647
- if (r.getState(a.state)) {
1648
- const l = a.state.selection.from;
1649
- o.preventDefault(), a.dispatch(a.state.tr.insertText(o.data || "", l));
1813
+ compositionend: (view, e) => {
1814
+ if (lock) {
1815
+ lock = false;
1816
+ requestAnimationFrame(() => {
1817
+ const active = inlineNodesCursorPlugin2.getState(view.state);
1818
+ if (active) {
1819
+ const from = view.state.selection.from;
1820
+ e.preventDefault();
1821
+ view.dispatch(view.state.tr.insertText(e.data || "", from));
1822
+ }
1823
+ });
1824
+ return true;
1650
1825
  }
1651
- }), !0) : !1,
1652
- compositionstart: (a) => (r.getState(a.state) && (t = !0), !1),
1653
- beforeinput: (a, o) => {
1654
- if (r.getState(a.state) && o instanceof InputEvent && o.data && !t) {
1655
- const l = a.state.selection.from;
1656
- return o.preventDefault(), a.dispatch(a.state.tr.insertText(o.data || "", l)), !0;
1826
+ return false;
1827
+ },
1828
+ compositionstart: (view) => {
1829
+ const active = inlineNodesCursorPlugin2.getState(view.state);
1830
+ if (active) lock = true;
1831
+ return false;
1832
+ },
1833
+ beforeinput: (view, e) => {
1834
+ const active = inlineNodesCursorPlugin2.getState(view.state);
1835
+ if (active && e instanceof InputEvent && e.data && !lock) {
1836
+ const from = view.state.selection.from;
1837
+ e.preventDefault();
1838
+ view.dispatch(view.state.tr.insertText(e.data || "", from));
1839
+ return true;
1657
1840
  }
1658
- return !1;
1841
+ return false;
1659
1842
  }
1660
1843
  },
1661
- decorations(a) {
1662
- if (r.getState(a)) {
1663
- const l = a.selection.$from.pos, i = document.createElement("span"), d = ze.widget(l, i, {
1844
+ decorations(state) {
1845
+ const active = inlineNodesCursorPlugin2.getState(state);
1846
+ if (active) {
1847
+ const pos = state.selection.$from;
1848
+ const position = pos.pos;
1849
+ const left = document.createElement("span");
1850
+ const leftDec = Decoration.widget(position, left, {
1664
1851
  side: -1
1665
- }), m = document.createElement("span"), u = ze.widget(l, m);
1666
- return setTimeout(() => {
1667
- i.contentEditable = "true", m.contentEditable = "true";
1668
- }), Je.create(a.doc, [d, u]);
1852
+ });
1853
+ const right = document.createElement("span");
1854
+ const rightDec = Decoration.widget(position, right);
1855
+ setTimeout(() => {
1856
+ left.contentEditable = "true";
1857
+ right.contentEditable = "true";
1858
+ });
1859
+ return DecorationSet.create(state.doc, [leftDec, rightDec]);
1669
1860
  }
1670
- return Je.empty;
1861
+ return DecorationSet.empty;
1671
1862
  }
1672
1863
  }
1673
1864
  });
1674
- return r;
1865
+ return inlineNodesCursorPlugin2;
1675
1866
  });
1676
- n(Ct, {
1867
+ withMeta(inlineNodesCursorPlugin, {
1677
1868
  displayName: "Prose<inlineNodesCursorPlugin>",
1678
1869
  group: "Prose"
1679
1870
  });
1680
- const Mt = _((t) => new P({
1681
- key: new E("MILKDOWN_HARDBREAK_MARKS"),
1682
- appendTransaction: (e, r, a) => {
1683
- if (!e.length) return;
1684
- const [o] = e;
1685
- if (!o) return;
1686
- const [s] = o.steps;
1687
- if (o.getMeta("hardbreak")) {
1688
- if (!(s instanceof Tt)) return;
1689
- const { from: d } = s;
1690
- return a.tr.setNodeMarkup(
1691
- d,
1692
- S.type(t),
1693
- void 0,
1694
- []
1695
- );
1696
- }
1697
- if (s instanceof Kt) {
1698
- let d = a.tr;
1699
- const { from: m, to: u } = s;
1700
- return a.doc.nodesBetween(m, u, (p, k) => {
1701
- p.type === S.type(t) && (d = d.setNodeMarkup(
1702
- k,
1703
- S.type(t),
1871
+ const hardbreakClearMarkPlugin = $prose((ctx) => {
1872
+ return new Plugin({
1873
+ key: new PluginKey("MILKDOWN_HARDBREAK_MARKS"),
1874
+ appendTransaction: (trs, _oldState, newState) => {
1875
+ if (!trs.length) return;
1876
+ const [tr] = trs;
1877
+ if (!tr) return;
1878
+ const [step] = tr.steps;
1879
+ const isInsertHr = tr.getMeta("hardbreak");
1880
+ if (isInsertHr) {
1881
+ if (!(step instanceof ReplaceStep)) return;
1882
+ const { from } = step;
1883
+ return newState.tr.setNodeMarkup(
1884
+ from,
1885
+ hardbreakSchema.type(ctx),
1704
1886
  void 0,
1705
1887
  []
1706
- ));
1707
- }), d;
1888
+ );
1889
+ }
1890
+ const isAddMarkStep = step instanceof AddMarkStep;
1891
+ if (isAddMarkStep) {
1892
+ let _tr = newState.tr;
1893
+ const { from, to } = step;
1894
+ newState.doc.nodesBetween(from, to, (node, pos) => {
1895
+ if (node.type === hardbreakSchema.type(ctx))
1896
+ _tr = _tr.setNodeMarkup(
1897
+ pos,
1898
+ hardbreakSchema.type(ctx),
1899
+ void 0,
1900
+ []
1901
+ );
1902
+ });
1903
+ return _tr;
1904
+ }
1905
+ return void 0;
1708
1906
  }
1709
- }
1710
- }));
1711
- n(Mt, {
1907
+ });
1908
+ });
1909
+ withMeta(hardbreakClearMarkPlugin, {
1712
1910
  displayName: "Prose<hardbreakClearMarkPlugin>",
1713
1911
  group: "Prose"
1714
1912
  });
1715
- const Ue = Xe(
1913
+ const hardbreakFilterNodes = $ctx(
1716
1914
  ["table", "code_block"],
1717
1915
  "hardbreakFilterNodes"
1718
1916
  );
1719
- n(Ue, {
1917
+ withMeta(hardbreakFilterNodes, {
1720
1918
  displayName: "Ctx<hardbreakFilterNodes>",
1721
1919
  group: "Prose"
1722
1920
  });
1723
- const bt = _((t) => {
1724
- const e = t.get(Ue.key);
1725
- return new P({
1726
- key: new E("MILKDOWN_HARDBREAK_FILTER"),
1727
- filterTransaction: (r, a) => {
1728
- const o = r.getMeta("hardbreak"), [s] = r.steps;
1729
- if (o && s) {
1730
- const { from: l } = s, i = a.doc.resolve(l);
1731
- let d = i.depth, m = !0;
1732
- for (; d > 0; )
1733
- e.includes(i.node(d).type.name) && (m = !1), d--;
1734
- return m;
1921
+ const hardbreakFilterPlugin = $prose((ctx) => {
1922
+ const notIn = ctx.get(hardbreakFilterNodes.key);
1923
+ return new Plugin({
1924
+ key: new PluginKey("MILKDOWN_HARDBREAK_FILTER"),
1925
+ filterTransaction: (tr, state) => {
1926
+ const isInsertHr = tr.getMeta("hardbreak");
1927
+ const [step] = tr.steps;
1928
+ if (isInsertHr && step) {
1929
+ const { from } = step;
1930
+ const $from = state.doc.resolve(from);
1931
+ let curDepth = $from.depth;
1932
+ let canApply = true;
1933
+ while (curDepth > 0) {
1934
+ if (notIn.includes($from.node(curDepth).type.name)) canApply = false;
1935
+ curDepth--;
1936
+ }
1937
+ return canApply;
1735
1938
  }
1736
- return !0;
1939
+ return true;
1737
1940
  }
1738
1941
  });
1739
1942
  });
1740
- n(bt, {
1943
+ withMeta(hardbreakFilterPlugin, {
1741
1944
  displayName: "Prose<hardbreakFilterPlugin>",
1742
1945
  group: "Prose"
1743
1946
  });
1744
- const Lt = _((t) => {
1745
- const e = new E("MILKDOWN_HEADING_ID"), r = (a) => {
1746
- if (a.composing) return;
1747
- const o = t.get(z.key), s = a.state.tr.setMeta("addToHistory", !1);
1748
- let l = !1;
1749
- const i = {};
1750
- a.state.doc.descendants((d, m) => {
1751
- if (d.type === H.type(t)) {
1752
- if (d.textContent.trim().length === 0) return;
1753
- const u = d.attrs;
1754
- let p = o(d);
1755
- i[p] ? (i[p] += 1, p += `-#${i[p]}`) : i[p] = 1, u.id !== p && (l = !0, s.setMeta(e, !0).setNodeMarkup(m, void 0, {
1756
- ...u,
1757
- id: p
1758
- }));
1947
+ const syncHeadingIdPlugin = $prose((ctx) => {
1948
+ const headingIdPluginKey = new PluginKey("MILKDOWN_HEADING_ID");
1949
+ const updateId = (view) => {
1950
+ if (view.composing) return;
1951
+ const getId = ctx.get(headingIdGenerator.key);
1952
+ const tr = view.state.tr.setMeta("addToHistory", false);
1953
+ let found = false;
1954
+ const idMap = {};
1955
+ view.state.doc.descendants((node, pos) => {
1956
+ if (node.type === headingSchema.type(ctx)) {
1957
+ if (node.textContent.trim().length === 0) return;
1958
+ const attrs = node.attrs;
1959
+ let id = getId(node);
1960
+ if (idMap[id]) {
1961
+ idMap[id] += 1;
1962
+ id += `-#${idMap[id]}`;
1963
+ } else {
1964
+ idMap[id] = 1;
1965
+ }
1966
+ if (attrs.id !== id) {
1967
+ found = true;
1968
+ tr.setMeta(headingIdPluginKey, true).setNodeMarkup(pos, void 0, {
1969
+ ...attrs,
1970
+ id
1971
+ });
1972
+ }
1759
1973
  }
1760
- }), l && a.dispatch(s);
1974
+ });
1975
+ if (found) view.dispatch(tr);
1761
1976
  };
1762
- return new P({
1763
- key: e,
1764
- view: (a) => (r(a), {
1765
- update: (o, s) => {
1766
- o.state.doc.eq(s.doc) || r(o);
1767
- }
1768
- })
1977
+ return new Plugin({
1978
+ key: headingIdPluginKey,
1979
+ view: (view) => {
1980
+ updateId(view);
1981
+ return {
1982
+ update: (view2, prevState) => {
1983
+ if (view2.state.doc.eq(prevState.doc)) return;
1984
+ updateId(view2);
1985
+ }
1986
+ };
1987
+ }
1769
1988
  });
1770
1989
  });
1771
- n(Lt, {
1990
+ withMeta(syncHeadingIdPlugin, {
1772
1991
  displayName: "Prose<syncHeadingIdPlugin>",
1773
1992
  group: "Prose"
1774
1993
  });
1775
- const xt = _((t) => {
1776
- const e = (r) => {
1777
- if (r.composing || !r.editable) return;
1778
- const a = K.type(t), o = T.type(t), s = M.type(t), l = r.state, i = (u, p) => {
1779
- let k = !1;
1780
- const C = `${p + 1}.`;
1781
- return u.label !== C && (u.label = C, k = !0), k;
1994
+ const syncListOrderPlugin = $prose((ctx) => {
1995
+ const syncOrderLabel = (view) => {
1996
+ if (view.composing || !view.editable) return;
1997
+ const orderedListType = orderedListSchema.type(ctx);
1998
+ const bulletListType = bulletListSchema.type(ctx);
1999
+ const listItemType = listItemSchema.type(ctx);
2000
+ const state = view.state;
2001
+ const handleNodeItem = (attrs, index) => {
2002
+ let changed = false;
2003
+ const expectedLabel = `${index + 1}.`;
2004
+ if (attrs.label !== expectedLabel) {
2005
+ attrs.label = expectedLabel;
2006
+ changed = true;
2007
+ }
2008
+ return changed;
1782
2009
  };
1783
- let d = l.tr, m = !1;
1784
- l.doc.descendants((u, p, k, C) => {
1785
- if (u.type === o) {
1786
- const y = u.maybeChild(0);
1787
- (y == null ? void 0 : y.type) === s && y.attrs.listType === "ordered" && (m = !0, d.setNodeMarkup(p, a, { spread: "true" }), u.descendants((b, Ge, Qt, St) => {
1788
- if (b.type === s) {
1789
- const je = { ...b.attrs };
1790
- i(je, St) && (d = d.setNodeMarkup(Ge, void 0, je));
1791
- }
1792
- return !1;
1793
- }));
1794
- } else if (u.type === s && (k == null ? void 0 : k.type) === a) {
1795
- const y = { ...u.attrs };
1796
- let b = !1;
1797
- y.listType !== "ordered" && (y.listType = "ordered", b = !0), (k == null ? void 0 : k.maybeChild(0)) && (b = i(y, C)), b && (d = d.setNodeMarkup(p, void 0, y), m = !0);
2010
+ let tr = state.tr;
2011
+ let needDispatch = false;
2012
+ state.doc.descendants((node, pos, parent, index) => {
2013
+ if (node.type === bulletListType) {
2014
+ const base = node.maybeChild(0);
2015
+ if ((base == null ? void 0 : base.type) === listItemType && base.attrs.listType === "ordered") {
2016
+ needDispatch = true;
2017
+ tr.setNodeMarkup(pos, orderedListType, { spread: "true" });
2018
+ node.descendants((child, pos2, _parent, index2) => {
2019
+ if (child.type === listItemType) {
2020
+ const attrs = { ...child.attrs };
2021
+ const changed = handleNodeItem(attrs, index2);
2022
+ if (changed) tr = tr.setNodeMarkup(pos2, void 0, attrs);
2023
+ }
2024
+ return false;
2025
+ });
2026
+ }
2027
+ } else if (node.type === listItemType && (parent == null ? void 0 : parent.type) === orderedListType) {
2028
+ const attrs = { ...node.attrs };
2029
+ let changed = false;
2030
+ if (attrs.listType !== "ordered") {
2031
+ attrs.listType = "ordered";
2032
+ changed = true;
2033
+ }
2034
+ const base = parent == null ? void 0 : parent.maybeChild(0);
2035
+ if (base) changed = handleNodeItem(attrs, index);
2036
+ if (changed) {
2037
+ tr = tr.setNodeMarkup(pos, void 0, attrs);
2038
+ needDispatch = true;
2039
+ }
1798
2040
  }
1799
- }), m && r.dispatch(d.setMeta("addToHistory", !1));
2041
+ });
2042
+ if (needDispatch) view.dispatch(tr.setMeta("addToHistory", false));
1800
2043
  };
1801
- return new P({
1802
- key: new E("MILKDOWN_KEEP_LIST_ORDER"),
1803
- view: (r) => (e(r), {
1804
- update: (a) => {
1805
- e(a);
1806
- }
1807
- })
2044
+ return new Plugin({
2045
+ key: new PluginKey("MILKDOWN_KEEP_LIST_ORDER"),
2046
+ view: (view) => {
2047
+ syncOrderLabel(view);
2048
+ return {
2049
+ update: (view2) => {
2050
+ syncOrderLabel(view2);
2051
+ }
2052
+ };
2053
+ }
1808
2054
  });
1809
2055
  });
1810
- n(xt, {
2056
+ withMeta(syncListOrderPlugin, {
1811
2057
  displayName: "Prose<syncListOrderPlugin>",
1812
2058
  group: "Prose"
1813
2059
  });
1814
- const Jt = [
1815
- Mt,
1816
- Ue,
1817
- bt,
1818
- Ct,
1819
- $e,
1820
- We,
1821
- qe,
1822
- Fe,
1823
- Ve,
1824
- Lt,
1825
- xt
1826
- ].flat(), pr = [
1827
- qt,
1828
- Wt,
1829
- Ft,
1830
- Vt,
1831
- Ut,
1832
- Jt
2060
+ const plugins = [
2061
+ hardbreakClearMarkPlugin,
2062
+ hardbreakFilterNodes,
2063
+ hardbreakFilterPlugin,
2064
+ inlineNodesCursorPlugin,
2065
+ remarkAddOrderInListPlugin,
2066
+ remarkInlineLinkPlugin,
2067
+ remarkLineBreak,
2068
+ remarkHtmlTransformer,
2069
+ remarkMarker,
2070
+ syncHeadingIdPlugin,
2071
+ syncListOrderPlugin
2072
+ ].flat();
2073
+ const commonmark = [
2074
+ schema,
2075
+ inputRules,
2076
+ markInputRules,
2077
+ commands,
2078
+ keymap,
2079
+ plugins
1833
2080
  ].flat();
1834
2081
  export {
1835
- ye as blockquoteAttr,
1836
- fe as blockquoteKeymap,
1837
- q as blockquoteSchema,
1838
- Se as bulletListAttr,
1839
- we as bulletListKeymap,
1840
- T as bulletListSchema,
1841
- Ne as codeBlockAttr,
1842
- Ce as codeBlockKeymap,
1843
- W as codeBlockSchema,
1844
- Vt as commands,
1845
- pr as commonmark,
1846
- Ie as createCodeBlockCommand,
1847
- ct as createCodeBlockInputRule,
1848
- mt as docSchema,
1849
- ge as downgradeHeadingCommand,
1850
- ee as emphasisAttr,
1851
- re as emphasisKeymap,
1852
- R as emphasisSchema,
1853
- nt as emphasisStarInputRule,
1854
- ot as emphasisUnderscoreInputRule,
1855
- V as hardbreakAttr,
1856
- Mt as hardbreakClearMarkPlugin,
1857
- Ue as hardbreakFilterNodes,
1858
- bt as hardbreakFilterPlugin,
1859
- Le as hardbreakKeymap,
1860
- S as hardbreakSchema,
1861
- ce as headingAttr,
1862
- z as headingIdGenerator,
1863
- ke as headingKeymap,
1864
- H as headingSchema,
1865
- xe as hrAttr,
1866
- F as hrSchema,
1867
- Ee as htmlAttr,
1868
- Pe as htmlSchema,
1869
- Me as imageAttr,
1870
- O as imageSchema,
1871
- se as inlineCodeAttr,
1872
- lt as inlineCodeInputRule,
1873
- ie as inlineCodeKeymap,
1874
- x as inlineCodeSchema,
1875
- Ct as inlineNodesCursorPlugin,
1876
- Wt as inputRules,
1877
- be as insertHardbreakCommand,
1878
- ht as insertHrCommand,
1879
- yt as insertHrInputRule,
1880
- gt as insertImageCommand,
1881
- Pt as insertImageInputRule,
1882
- Ut as keymap,
1883
- ve as liftFirstListItemCommand,
1884
- Ke as liftListItemCommand,
1885
- de as linkAttr,
1886
- B as linkSchema,
1887
- Oe as listItemAttr,
1888
- _e as listItemKeymap,
1889
- M as listItemSchema,
1890
- Ft as markInputRules,
1891
- He as orderedListAttr,
1892
- Re as orderedListKeymap,
1893
- K as orderedListSchema,
1894
- me as paragraphAttr,
1895
- pe as paragraphKeymap,
1896
- w as paragraphSchema,
1897
- Jt as plugins,
1898
- $e as remarkAddOrderInListPlugin,
1899
- Fe as remarkHtmlTransformer,
1900
- We as remarkInlineLinkPlugin,
1901
- qe as remarkLineBreak,
1902
- Ve as remarkMarker,
1903
- qt as schema,
1904
- Te as sinkListItemCommand,
1905
- De as splitListItemCommand,
1906
- ae as strongAttr,
1907
- st as strongInputRule,
1908
- oe as strongKeymap,
1909
- $ as strongSchema,
1910
- Lt as syncHeadingIdPlugin,
1911
- xt as syncListOrderPlugin,
1912
- It as textSchema,
1913
- te as toggleEmphasisCommand,
1914
- le as toggleInlineCodeCommand,
1915
- it as toggleLinkCommand,
1916
- ne as toggleStrongCommand,
1917
- ue as turnIntoTextCommand,
1918
- Et as updateCodeBlockLanguageCommand,
1919
- kt as updateImageCommand,
1920
- dt as updateLinkCommand,
1921
- he as wrapInBlockquoteCommand,
1922
- pt as wrapInBlockquoteInputRule,
1923
- Ae as wrapInBulletListCommand,
1924
- ft as wrapInBulletListInputRule,
1925
- L as wrapInHeadingCommand,
1926
- ut as wrapInHeadingInputRule,
1927
- Be as wrapInOrderedListCommand,
1928
- Nt as wrapInOrderedListInputRule
2082
+ blockquoteAttr,
2083
+ blockquoteKeymap,
2084
+ blockquoteSchema,
2085
+ bulletListAttr,
2086
+ bulletListKeymap,
2087
+ bulletListSchema,
2088
+ codeBlockAttr,
2089
+ codeBlockKeymap,
2090
+ codeBlockSchema,
2091
+ commands,
2092
+ commonmark,
2093
+ createCodeBlockCommand,
2094
+ createCodeBlockInputRule,
2095
+ docSchema,
2096
+ downgradeHeadingCommand,
2097
+ emphasisAttr,
2098
+ emphasisKeymap,
2099
+ emphasisSchema,
2100
+ emphasisStarInputRule,
2101
+ emphasisUnderscoreInputRule,
2102
+ hardbreakAttr,
2103
+ hardbreakClearMarkPlugin,
2104
+ hardbreakFilterNodes,
2105
+ hardbreakFilterPlugin,
2106
+ hardbreakKeymap,
2107
+ hardbreakSchema,
2108
+ headingAttr,
2109
+ headingIdGenerator,
2110
+ headingKeymap,
2111
+ headingSchema,
2112
+ hrAttr,
2113
+ hrSchema,
2114
+ htmlAttr,
2115
+ htmlSchema,
2116
+ imageAttr,
2117
+ imageSchema,
2118
+ inlineCodeAttr,
2119
+ inlineCodeInputRule,
2120
+ inlineCodeKeymap,
2121
+ inlineCodeSchema,
2122
+ inlineNodesCursorPlugin,
2123
+ inputRules,
2124
+ insertHardbreakCommand,
2125
+ insertHrCommand,
2126
+ insertHrInputRule,
2127
+ insertImageCommand,
2128
+ insertImageInputRule,
2129
+ keymap,
2130
+ liftFirstListItemCommand,
2131
+ liftListItemCommand,
2132
+ linkAttr,
2133
+ linkSchema,
2134
+ listItemAttr,
2135
+ listItemKeymap,
2136
+ listItemSchema,
2137
+ markInputRules,
2138
+ orderedListAttr,
2139
+ orderedListKeymap,
2140
+ orderedListSchema,
2141
+ paragraphAttr,
2142
+ paragraphKeymap,
2143
+ paragraphSchema,
2144
+ plugins,
2145
+ remarkAddOrderInListPlugin,
2146
+ remarkHtmlTransformer,
2147
+ remarkInlineLinkPlugin,
2148
+ remarkLineBreak,
2149
+ remarkMarker,
2150
+ schema,
2151
+ sinkListItemCommand,
2152
+ splitListItemCommand,
2153
+ strongAttr,
2154
+ strongInputRule,
2155
+ strongKeymap,
2156
+ strongSchema,
2157
+ syncHeadingIdPlugin,
2158
+ syncListOrderPlugin,
2159
+ textSchema,
2160
+ toggleEmphasisCommand,
2161
+ toggleInlineCodeCommand,
2162
+ toggleLinkCommand,
2163
+ toggleStrongCommand,
2164
+ turnIntoTextCommand,
2165
+ updateCodeBlockLanguageCommand,
2166
+ updateImageCommand,
2167
+ updateLinkCommand,
2168
+ wrapInBlockquoteCommand,
2169
+ wrapInBlockquoteInputRule,
2170
+ wrapInBulletListCommand,
2171
+ wrapInBulletListInputRule,
2172
+ wrapInHeadingCommand,
2173
+ wrapInHeadingInputRule,
2174
+ wrapInOrderedListCommand,
2175
+ wrapInOrderedListInputRule
1929
2176
  };
1930
2177
  //# sourceMappingURL=index.es.js.map