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