@milkdown/preset-commonmark 7.6.3 → 7.7.0

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