@notum-cz/strapi-plugin-tiptap-editor 1.0.1

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.
Files changed (104) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +160 -0
  3. package/dist/_chunks/AccentCursive-CpAPpH9C.mjs +3383 -0
  4. package/dist/_chunks/AccentCursive-CpAPpH9C.mjs.map +1 -0
  5. package/dist/_chunks/AccentCursive-D6sTlhub.js +3384 -0
  6. package/dist/_chunks/AccentCursive-D6sTlhub.js.map +1 -0
  7. package/dist/_chunks/FormattedHeadingInput-DycgfIze.mjs +101 -0
  8. package/dist/_chunks/FormattedHeadingInput-DycgfIze.mjs.map +1 -0
  9. package/dist/_chunks/FormattedHeadingInput-FFjiRSEJ.js +101 -0
  10. package/dist/_chunks/FormattedHeadingInput-FFjiRSEJ.js.map +1 -0
  11. package/dist/_chunks/RichTextInput-BZQ2iVqa.mjs +4481 -0
  12. package/dist/_chunks/RichTextInput-BZQ2iVqa.mjs.map +1 -0
  13. package/dist/_chunks/RichTextInput-BbbQxPc-.js +4414 -0
  14. package/dist/_chunks/RichTextInput-BbbQxPc-.js.map +1 -0
  15. package/dist/_chunks/RichTextInput-BjLR2pi0.js +4416 -0
  16. package/dist/_chunks/RichTextInput-BjLR2pi0.js.map +1 -0
  17. package/dist/_chunks/RichTextInput-BlxoJMa2.js +4488 -0
  18. package/dist/_chunks/RichTextInput-BlxoJMa2.js.map +1 -0
  19. package/dist/_chunks/RichTextInput-Bm3X8fR2.mjs +4400 -0
  20. package/dist/_chunks/RichTextInput-Bm3X8fR2.mjs.map +1 -0
  21. package/dist/_chunks/RichTextInput-Bms-gSvK.js +4407 -0
  22. package/dist/_chunks/RichTextInput-Bms-gSvK.js.map +1 -0
  23. package/dist/_chunks/RichTextInput-BtNjPJRN.mjs +4400 -0
  24. package/dist/_chunks/RichTextInput-BtNjPJRN.mjs.map +1 -0
  25. package/dist/_chunks/RichTextInput-Bw3tcXfp.js +4407 -0
  26. package/dist/_chunks/RichTextInput-Bw3tcXfp.js.map +1 -0
  27. package/dist/_chunks/RichTextInput-CsgNpoxq.mjs +4409 -0
  28. package/dist/_chunks/RichTextInput-CsgNpoxq.mjs.map +1 -0
  29. package/dist/_chunks/RichTextInput-CwTvEMda.js +4407 -0
  30. package/dist/_chunks/RichTextInput-CwTvEMda.js.map +1 -0
  31. package/dist/_chunks/RichTextInput-DG-36krM.js +1181 -0
  32. package/dist/_chunks/RichTextInput-DG-36krM.js.map +1 -0
  33. package/dist/_chunks/RichTextInput-DLac-zNQ.mjs +4400 -0
  34. package/dist/_chunks/RichTextInput-DLac-zNQ.mjs.map +1 -0
  35. package/dist/_chunks/RichTextInput-DSXttrvi.js +4407 -0
  36. package/dist/_chunks/RichTextInput-DSXttrvi.js.map +1 -0
  37. package/dist/_chunks/RichTextInput-DeJ6Exto.mjs +4400 -0
  38. package/dist/_chunks/RichTextInput-DeJ6Exto.mjs.map +1 -0
  39. package/dist/_chunks/RichTextInput-DgT88AkO.mjs +1175 -0
  40. package/dist/_chunks/RichTextInput-DgT88AkO.mjs.map +1 -0
  41. package/dist/_chunks/RichTextInput-DlMaDJQF.mjs +4400 -0
  42. package/dist/_chunks/RichTextInput-DlMaDJQF.mjs.map +1 -0
  43. package/dist/_chunks/RichTextInput-DtaYdjCs.mjs +4400 -0
  44. package/dist/_chunks/RichTextInput-DtaYdjCs.mjs.map +1 -0
  45. package/dist/_chunks/RichTextInput-YTKXo5oq.js +4407 -0
  46. package/dist/_chunks/RichTextInput-YTKXo5oq.js.map +1 -0
  47. package/dist/_chunks/RichTextInput-tmg-oMJk.mjs +4407 -0
  48. package/dist/_chunks/RichTextInput-tmg-oMJk.mjs.map +1 -0
  49. package/dist/_chunks/RichTextInput-umhMsI5o.js +4407 -0
  50. package/dist/_chunks/RichTextInput-umhMsI5o.js.map +1 -0
  51. package/dist/_chunks/en-B4KWt_jN.js +5 -0
  52. package/dist/_chunks/en-B4KWt_jN.js.map +1 -0
  53. package/dist/_chunks/en-Byx4XI2L.mjs +5 -0
  54. package/dist/_chunks/en-Byx4XI2L.mjs.map +1 -0
  55. package/dist/admin/index.js +71 -0
  56. package/dist/admin/index.js.map +1 -0
  57. package/dist/admin/index.mjs +72 -0
  58. package/dist/admin/index.mjs.map +1 -0
  59. package/dist/admin/src/components/BaseTiptapInput.d.ts +12 -0
  60. package/dist/admin/src/components/FormattedHeadingInput.d.ts +4 -0
  61. package/dist/admin/src/components/Initializer.d.ts +5 -0
  62. package/dist/admin/src/components/LinkDialog.d.ts +14 -0
  63. package/dist/admin/src/components/RichTextInput.d.ts +4 -0
  64. package/dist/admin/src/components/Spacer.d.ts +3 -0
  65. package/dist/admin/src/components/TableSizeDialog.d.ts +10 -0
  66. package/dist/admin/src/components/TiptapInput.d.ts +7 -0
  67. package/dist/admin/src/components/TiptapInputStyles.d.ts +2 -0
  68. package/dist/admin/src/components/ToolbarButton.d.ts +11 -0
  69. package/dist/admin/src/extensions/AccentCursive.d.ts +18 -0
  70. package/dist/admin/src/extensions/Heading.d.ts +8 -0
  71. package/dist/admin/src/extensions/Link.d.ts +7 -0
  72. package/dist/admin/src/extensions/Script.d.ts +7 -0
  73. package/dist/admin/src/extensions/StarterKit.d.ts +13 -0
  74. package/dist/admin/src/extensions/Table.d.ts +11 -0
  75. package/dist/admin/src/extensions/TextAlign.d.ts +9 -0
  76. package/dist/admin/src/fields/formattedHeadingField.d.ts +20 -0
  77. package/dist/admin/src/fields/richTextField.d.ts +20 -0
  78. package/dist/admin/src/icons/TextAlignCenter.d.ts +2 -0
  79. package/dist/admin/src/icons/TextAlignJustify.d.ts +2 -0
  80. package/dist/admin/src/icons/TextAlignLeft.d.ts +2 -0
  81. package/dist/admin/src/icons/TextAlignRight.d.ts +2 -0
  82. package/dist/admin/src/index.d.ts +10 -0
  83. package/dist/admin/src/pluginId.d.ts +1 -0
  84. package/dist/admin/src/utils/getTranslation.d.ts +2 -0
  85. package/dist/admin/src/utils/tiptapUtils.d.ts +18 -0
  86. package/dist/server/index.js +44 -0
  87. package/dist/server/index.js.map +1 -0
  88. package/dist/server/index.mjs +45 -0
  89. package/dist/server/index.mjs.map +1 -0
  90. package/dist/server/src/bootstrap.d.ts +5 -0
  91. package/dist/server/src/config/index.d.ts +5 -0
  92. package/dist/server/src/content-types/index.d.ts +2 -0
  93. package/dist/server/src/controllers/index.d.ts +2 -0
  94. package/dist/server/src/destroy.d.ts +5 -0
  95. package/dist/server/src/fields/richTextField.d.ts +2 -0
  96. package/dist/server/src/index.d.ts +25 -0
  97. package/dist/server/src/middlewares/index.d.ts +2 -0
  98. package/dist/server/src/policies/index.d.ts +2 -0
  99. package/dist/server/src/register.d.ts +5 -0
  100. package/dist/server/src/routes/index.d.ts +2 -0
  101. package/dist/server/src/services/index.d.ts +2 -0
  102. package/dist/shared/fields.d.ts +1 -0
  103. package/dist/shared/pluginId.d.ts +1 -0
  104. package/package.json +80 -0
@@ -0,0 +1,3383 @@
1
+ import { jsxs, jsx } from "react/jsx-runtime";
2
+ import { Field, Box, Flex, Tooltip, Button } from "@strapi/design-system";
3
+ import { EditorContent, useEditor, useEditorState } from "@tiptap/react";
4
+ import styled from "styled-components";
5
+ import { forwardRef } from "react";
6
+ import { RemoveMarkStep, Transform, liftTarget, joinPoint, canSplit, ReplaceStep, ReplaceAroundStep, canJoin } from "@tiptap/pm/transform";
7
+ import { createParagraphNear as createParagraphNear$1, deleteSelection as deleteSelection$1, exitCode as exitCode$1, joinUp as joinUp$1, joinDown as joinDown$1, joinBackward as joinBackward$1, joinForward as joinForward$1, joinTextblockBackward as joinTextblockBackward$1, joinTextblockForward as joinTextblockForward$1, lift as lift$1, liftEmptyBlock as liftEmptyBlock$1, newlineInCode as newlineInCode$1, selectNodeBackward as selectNodeBackward$1, selectNodeForward as selectNodeForward$1, selectParentNode as selectParentNode$1, selectTextblockEnd as selectTextblockEnd$1, selectTextblockStart as selectTextblockStart$1, setBlockType, wrapIn as wrapIn$1 } from "@tiptap/pm/commands";
8
+ import { Plugin, PluginKey, Selection, NodeSelection, TextSelection, AllSelection } from "@tiptap/pm/state";
9
+ import { Fragment, Slice, Node, Schema, DOMParser } from "@tiptap/pm/model";
10
+ import { liftListItem as liftListItem$1, sinkListItem as sinkListItem$1, wrapInList as wrapInList$1 } from "@tiptap/pm/schema-list";
11
+ import "@tiptap/pm/view";
12
+ import "@tiptap/pm/keymap";
13
+ import { useField } from "@strapi/strapi/admin";
14
+ import { Italic } from "@strapi/icons";
15
+ const TiptapInputStyles = styled.div`
16
+ .editor-toolbar {
17
+ margin-bottom: 0.25rem;
18
+ padding-bottom: 0.25rem;
19
+ }
20
+
21
+ .ProseMirror {
22
+ font-size: 1.4rem; /* Increase editor font size to match Strapi default */
23
+ outline: none;
24
+ max-height: 60vh;
25
+ overflow-y: auto;
26
+ padding: 1rem;
27
+ }
28
+
29
+ /* Remove unnecessary margin at the top of the editor */
30
+ .ProseMirror *:first-child {
31
+ margin-top: 0;
32
+ }
33
+
34
+ /* --- Basic text styles --- */
35
+
36
+ .ProseMirror p {
37
+ margin: 0 0 12px;
38
+ }
39
+
40
+ .ProseMirror p:last-child {
41
+ margin-bottom: 0;
42
+ }
43
+
44
+ .ProseMirror h1,
45
+ .ProseMirror h2,
46
+ .ProseMirror h3,
47
+ .ProseMirror h4 {
48
+ font-weight: 600;
49
+ line-height: 1.25;
50
+ margin: 1em 0 0.5em;
51
+ }
52
+
53
+ .ProseMirror h1 {
54
+ font-size: 4rem;
55
+ }
56
+
57
+ .ProseMirror h2 {
58
+ font-size: 3.2rem;
59
+ }
60
+
61
+ .ProseMirror h3 {
62
+ font-size: 2.5rem;
63
+ }
64
+
65
+ .ProseMirror h4 {
66
+ font-size: 2rem;
67
+ }
68
+
69
+ .ProseMirror ul,
70
+ .ProseMirror ol {
71
+ margin: 0.75em 0 1em;
72
+ padding-left: 1.5rem;
73
+ }
74
+
75
+ .ProseMirror ul {
76
+ list-style: disc;
77
+ }
78
+
79
+ .ProseMirror ol {
80
+ list-style: decimal;
81
+ }
82
+
83
+ .ProseMirror li {
84
+ margin: 0.25em 0;
85
+ }
86
+
87
+ .ProseMirror blockquote {
88
+ border-left: 3px solid #222;
89
+ margin: 1em 0;
90
+ padding: 0.25em 1rem;
91
+ font-style: italic;
92
+ background: #fafafa;
93
+ }
94
+
95
+ .ProseMirror code {
96
+ background: #f3f3f3;
97
+ padding: 2px 4px;
98
+ border-radius: 4px;
99
+ font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, 'Liberation Mono', monospace;
100
+ font-size: 0.9em;
101
+ }
102
+
103
+ .ProseMirror a {
104
+ color: #0c75af;
105
+ text-decoration: underline;
106
+ }
107
+
108
+ .ProseMirror strong {
109
+ font-weight: 600;
110
+ }
111
+
112
+ .ProseMirror em {
113
+ font-style: italic;
114
+ }
115
+
116
+ .ProseMirror u {
117
+ text-decoration: underline;
118
+ }
119
+
120
+ .ProseMirror s {
121
+ text-decoration: line-through;
122
+ }
123
+
124
+ // Source: https://tiptap.dev/docs/editor/extensions/nodes/table?gad_source=1&gad_campaignid=22014820935&gclid=Cj0KCQjwjL3HBhCgARIsAPUg7a5ZcPOMy7tBMIDShF9LCrr6JRpVHDI9vlgYCfoVjzM573ROeYQwcdMaArJMEALw_wcB
125
+
126
+ .ProseMirror {
127
+ table {
128
+ border-collapse: collapse;
129
+ margin: 0;
130
+ overflow: hidden;
131
+ table-layout: fixed;
132
+ width: 100%;
133
+
134
+ td,
135
+ th {
136
+ border: 1px solid #ddd;
137
+ box-sizing: border-box;
138
+ min-width: 1em;
139
+ padding: 6px 8px;
140
+ position: relative;
141
+ vertical-align: top;
142
+
143
+ > * {
144
+ margin-bottom: 0;
145
+ }
146
+ }
147
+
148
+ /* It is not possible to distinguish header vs body cells when rendering
149
+ content in React. So we render all as td and the user should use bold text
150
+ in cells. */
151
+ th {
152
+ background-color: inherit;
153
+ font-weight: normal;
154
+ text-align: left;
155
+ }
156
+
157
+ .selectedCell:after {
158
+ background: rgba(0, 37, 159, 0.32);
159
+ content: '';
160
+ left: 0;
161
+ right: 0;
162
+ top: 0;
163
+ bottom: 0;
164
+ pointer-events: none;
165
+ position: absolute;
166
+ z-index: 2;
167
+ }
168
+
169
+ .column-resize-handle {
170
+ background-color: purple;
171
+ bottom: -2px;
172
+ pointer-events: none;
173
+ position: absolute;
174
+ right: -2px;
175
+ top: 0;
176
+ width: 4px;
177
+ }
178
+ }
179
+
180
+ .tableWrapper {
181
+ margin: 1.5rem 0;
182
+ overflow-x: auto;
183
+ }
184
+
185
+ &.resize-cursor {
186
+ cursor: ew-resize;
187
+ cursor: col-resize;
188
+ }
189
+ }
190
+
191
+ /* --- Accent Cursive --- */
192
+ /* How the accented text looks like in editor */
193
+
194
+ .accent-cursive {
195
+ color: var(--color-accent-dark, #ae8f5b);
196
+ font-style: italic;
197
+ font-weight: bold;
198
+ }
199
+
200
+ /* --- Only Cursive --- */
201
+ /* How the only cursive text looks like in editor */
202
+
203
+ .only-cursive {
204
+ font-style: italic;
205
+ font-weight: bold;
206
+ }
207
+ `;
208
+ const BaseTiptapInput = forwardRef(
209
+ ({ hint, disabled = false, labelAction, label, name, required = false, editor, field, children }, forwardedRef) => {
210
+ const borderColor = field.error ? "danger600" : "neutral200";
211
+ const background = disabled ? "neutral200" : "neutral100";
212
+ return /* @__PURE__ */ jsxs(Field.Root, { name, id: name, hint, error: field.error, required, children: [
213
+ /* @__PURE__ */ jsx(Field.Label, { action: labelAction, children: label }),
214
+ /* @__PURE__ */ jsx(TiptapInputStyles, { children: /* @__PURE__ */ jsxs(
215
+ Box,
216
+ {
217
+ className: `tiptap-editor-wrapper ${field.error ? "has-error" : ""} ${disabled ? "is-disabled" : ""}`,
218
+ hasRadius: true,
219
+ borderColor,
220
+ background,
221
+ paddingTop: 1,
222
+ paddingBottom: 0,
223
+ paddingLeft: 0,
224
+ paddingRight: 0,
225
+ children: [
226
+ /* @__PURE__ */ jsx(Box, { className: "editor-toolbar", paddingLeft: 2, paddingRight: 2, paddingBottom: 2, children: /* @__PURE__ */ jsx(Flex, { gap: 1, wrap: "wrap", children }) }),
227
+ /* @__PURE__ */ jsx(
228
+ Box,
229
+ {
230
+ className: "editor-content",
231
+ background: "neutral0",
232
+ paddingTop: 2,
233
+ paddingBottom: 2,
234
+ paddingLeft: 2,
235
+ paddingRight: 2,
236
+ children: /* @__PURE__ */ jsx(EditorContent, { editor, disabled, ref: forwardedRef })
237
+ }
238
+ )
239
+ ]
240
+ }
241
+ ) }),
242
+ /* @__PURE__ */ jsx(Field.Hint, {}),
243
+ /* @__PURE__ */ jsx(Field.Error, {})
244
+ ] });
245
+ }
246
+ );
247
+ var __defProp = Object.defineProperty;
248
+ var __export = (target, all) => {
249
+ for (var name in all)
250
+ __defProp(target, name, { get: all[name], enumerable: true });
251
+ };
252
+ function createChainableState(config) {
253
+ const { state, transaction } = config;
254
+ let { selection } = transaction;
255
+ let { doc } = transaction;
256
+ let { storedMarks } = transaction;
257
+ return {
258
+ ...state,
259
+ apply: state.apply.bind(state),
260
+ applyTransaction: state.applyTransaction.bind(state),
261
+ plugins: state.plugins,
262
+ schema: state.schema,
263
+ reconfigure: state.reconfigure.bind(state),
264
+ toJSON: state.toJSON.bind(state),
265
+ get storedMarks() {
266
+ return storedMarks;
267
+ },
268
+ get selection() {
269
+ return selection;
270
+ },
271
+ get doc() {
272
+ return doc;
273
+ },
274
+ get tr() {
275
+ selection = transaction.selection;
276
+ doc = transaction.doc;
277
+ storedMarks = transaction.storedMarks;
278
+ return transaction;
279
+ }
280
+ };
281
+ }
282
+ var CommandManager = class {
283
+ constructor(props) {
284
+ this.editor = props.editor;
285
+ this.rawCommands = this.editor.extensionManager.commands;
286
+ this.customState = props.state;
287
+ }
288
+ get hasCustomState() {
289
+ return !!this.customState;
290
+ }
291
+ get state() {
292
+ return this.customState || this.editor.state;
293
+ }
294
+ get commands() {
295
+ const { rawCommands, editor, state } = this;
296
+ const { view } = editor;
297
+ const { tr } = state;
298
+ const props = this.buildProps(tr);
299
+ return Object.fromEntries(
300
+ Object.entries(rawCommands).map(([name, command2]) => {
301
+ const method = (...args) => {
302
+ const callback = command2(...args)(props);
303
+ if (!tr.getMeta("preventDispatch") && !this.hasCustomState) {
304
+ view.dispatch(tr);
305
+ }
306
+ return callback;
307
+ };
308
+ return [name, method];
309
+ })
310
+ );
311
+ }
312
+ get chain() {
313
+ return () => this.createChain();
314
+ }
315
+ get can() {
316
+ return () => this.createCan();
317
+ }
318
+ createChain(startTr, shouldDispatch = true) {
319
+ const { rawCommands, editor, state } = this;
320
+ const { view } = editor;
321
+ const callbacks = [];
322
+ const hasStartTransaction = !!startTr;
323
+ const tr = startTr || state.tr;
324
+ const run3 = () => {
325
+ if (!hasStartTransaction && shouldDispatch && !tr.getMeta("preventDispatch") && !this.hasCustomState) {
326
+ view.dispatch(tr);
327
+ }
328
+ return callbacks.every((callback) => callback === true);
329
+ };
330
+ const chain = {
331
+ ...Object.fromEntries(
332
+ Object.entries(rawCommands).map(([name, command2]) => {
333
+ const chainedCommand = (...args) => {
334
+ const props = this.buildProps(tr, shouldDispatch);
335
+ const callback = command2(...args)(props);
336
+ callbacks.push(callback);
337
+ return chain;
338
+ };
339
+ return [name, chainedCommand];
340
+ })
341
+ ),
342
+ run: run3
343
+ };
344
+ return chain;
345
+ }
346
+ createCan(startTr) {
347
+ const { rawCommands, state } = this;
348
+ const dispatch = false;
349
+ const tr = startTr || state.tr;
350
+ const props = this.buildProps(tr, dispatch);
351
+ const formattedCommands = Object.fromEntries(
352
+ Object.entries(rawCommands).map(([name, command2]) => {
353
+ return [name, (...args) => command2(...args)({ ...props, dispatch: void 0 })];
354
+ })
355
+ );
356
+ return {
357
+ ...formattedCommands,
358
+ chain: () => this.createChain(tr, dispatch)
359
+ };
360
+ }
361
+ buildProps(tr, shouldDispatch = true) {
362
+ const { rawCommands, editor, state } = this;
363
+ const { view } = editor;
364
+ const props = {
365
+ tr,
366
+ editor,
367
+ view,
368
+ state: createChainableState({
369
+ state,
370
+ transaction: tr
371
+ }),
372
+ dispatch: shouldDispatch ? () => void 0 : void 0,
373
+ chain: () => this.createChain(tr, shouldDispatch),
374
+ can: () => this.createCan(tr),
375
+ get commands() {
376
+ return Object.fromEntries(
377
+ Object.entries(rawCommands).map(([name, command2]) => {
378
+ return [name, (...args) => command2(...args)(props)];
379
+ })
380
+ );
381
+ }
382
+ };
383
+ return props;
384
+ }
385
+ };
386
+ var commands_exports = {};
387
+ __export(commands_exports, {
388
+ blur: () => blur,
389
+ clearContent: () => clearContent,
390
+ clearNodes: () => clearNodes,
391
+ command: () => command,
392
+ createParagraphNear: () => createParagraphNear,
393
+ cut: () => cut,
394
+ deleteCurrentNode: () => deleteCurrentNode,
395
+ deleteNode: () => deleteNode,
396
+ deleteRange: () => deleteRange,
397
+ deleteSelection: () => deleteSelection,
398
+ enter: () => enter,
399
+ exitCode: () => exitCode,
400
+ extendMarkRange: () => extendMarkRange,
401
+ first: () => first,
402
+ focus: () => focus,
403
+ forEach: () => forEach,
404
+ insertContent: () => insertContent,
405
+ insertContentAt: () => insertContentAt,
406
+ joinBackward: () => joinBackward,
407
+ joinDown: () => joinDown,
408
+ joinForward: () => joinForward,
409
+ joinItemBackward: () => joinItemBackward,
410
+ joinItemForward: () => joinItemForward,
411
+ joinTextblockBackward: () => joinTextblockBackward,
412
+ joinTextblockForward: () => joinTextblockForward,
413
+ joinUp: () => joinUp,
414
+ keyboardShortcut: () => keyboardShortcut,
415
+ lift: () => lift,
416
+ liftEmptyBlock: () => liftEmptyBlock,
417
+ liftListItem: () => liftListItem,
418
+ newlineInCode: () => newlineInCode,
419
+ resetAttributes: () => resetAttributes,
420
+ scrollIntoView: () => scrollIntoView,
421
+ selectAll: () => selectAll,
422
+ selectNodeBackward: () => selectNodeBackward,
423
+ selectNodeForward: () => selectNodeForward,
424
+ selectParentNode: () => selectParentNode,
425
+ selectTextblockEnd: () => selectTextblockEnd,
426
+ selectTextblockStart: () => selectTextblockStart,
427
+ setContent: () => setContent,
428
+ setMark: () => setMark,
429
+ setMeta: () => setMeta,
430
+ setNode: () => setNode,
431
+ setNodeSelection: () => setNodeSelection,
432
+ setTextDirection: () => setTextDirection,
433
+ setTextSelection: () => setTextSelection,
434
+ sinkListItem: () => sinkListItem,
435
+ splitBlock: () => splitBlock,
436
+ splitListItem: () => splitListItem,
437
+ toggleList: () => toggleList,
438
+ toggleMark: () => toggleMark,
439
+ toggleNode: () => toggleNode,
440
+ toggleWrap: () => toggleWrap,
441
+ undoInputRule: () => undoInputRule,
442
+ unsetAllMarks: () => unsetAllMarks,
443
+ unsetMark: () => unsetMark,
444
+ unsetTextDirection: () => unsetTextDirection,
445
+ updateAttributes: () => updateAttributes,
446
+ wrapIn: () => wrapIn,
447
+ wrapInList: () => wrapInList
448
+ });
449
+ var blur = () => ({ editor, view }) => {
450
+ requestAnimationFrame(() => {
451
+ var _a;
452
+ if (!editor.isDestroyed) {
453
+ view.dom.blur();
454
+ (_a = window == null ? void 0 : window.getSelection()) == null ? void 0 : _a.removeAllRanges();
455
+ }
456
+ });
457
+ return true;
458
+ };
459
+ var clearContent = (emitUpdate = true) => ({ commands }) => {
460
+ return commands.setContent("", { emitUpdate });
461
+ };
462
+ var clearNodes = () => ({ state, tr, dispatch }) => {
463
+ const { selection } = tr;
464
+ const { ranges } = selection;
465
+ if (!dispatch) {
466
+ return true;
467
+ }
468
+ ranges.forEach(({ $from, $to }) => {
469
+ state.doc.nodesBetween($from.pos, $to.pos, (node, pos) => {
470
+ if (node.type.isText) {
471
+ return;
472
+ }
473
+ const { doc, mapping } = tr;
474
+ const $mappedFrom = doc.resolve(mapping.map(pos));
475
+ const $mappedTo = doc.resolve(mapping.map(pos + node.nodeSize));
476
+ const nodeRange = $mappedFrom.blockRange($mappedTo);
477
+ if (!nodeRange) {
478
+ return;
479
+ }
480
+ const targetLiftDepth = liftTarget(nodeRange);
481
+ if (node.type.isTextblock) {
482
+ const { defaultType } = $mappedFrom.parent.contentMatchAt($mappedFrom.index());
483
+ tr.setNodeMarkup(nodeRange.start, defaultType);
484
+ }
485
+ if (targetLiftDepth || targetLiftDepth === 0) {
486
+ tr.lift(nodeRange, targetLiftDepth);
487
+ }
488
+ });
489
+ });
490
+ return true;
491
+ };
492
+ var command = (fn) => (props) => {
493
+ return fn(props);
494
+ };
495
+ var createParagraphNear = () => ({ state, dispatch }) => {
496
+ return createParagraphNear$1(state, dispatch);
497
+ };
498
+ var cut = (originRange, targetPos) => ({ editor, tr }) => {
499
+ const { state } = editor;
500
+ const contentSlice = state.doc.slice(originRange.from, originRange.to);
501
+ tr.deleteRange(originRange.from, originRange.to);
502
+ const newPos = tr.mapping.map(targetPos);
503
+ tr.insert(newPos, contentSlice.content);
504
+ tr.setSelection(new TextSelection(tr.doc.resolve(Math.max(newPos - 1, 0))));
505
+ return true;
506
+ };
507
+ var deleteCurrentNode = () => ({ tr, dispatch }) => {
508
+ const { selection } = tr;
509
+ const currentNode = selection.$anchor.node();
510
+ if (currentNode.content.size > 0) {
511
+ return false;
512
+ }
513
+ const $pos = tr.selection.$anchor;
514
+ for (let depth = $pos.depth; depth > 0; depth -= 1) {
515
+ const node = $pos.node(depth);
516
+ if (node.type === currentNode.type) {
517
+ if (dispatch) {
518
+ const from = $pos.before(depth);
519
+ const to = $pos.after(depth);
520
+ tr.delete(from, to).scrollIntoView();
521
+ }
522
+ return true;
523
+ }
524
+ }
525
+ return false;
526
+ };
527
+ function getNodeType(nameOrType, schema) {
528
+ if (typeof nameOrType === "string") {
529
+ if (!schema.nodes[nameOrType]) {
530
+ throw Error(`There is no node type named '${nameOrType}'. Maybe you forgot to add the extension?`);
531
+ }
532
+ return schema.nodes[nameOrType];
533
+ }
534
+ return nameOrType;
535
+ }
536
+ var deleteNode = (typeOrName) => ({ tr, state, dispatch }) => {
537
+ const type = getNodeType(typeOrName, state.schema);
538
+ const $pos = tr.selection.$anchor;
539
+ for (let depth = $pos.depth; depth > 0; depth -= 1) {
540
+ const node = $pos.node(depth);
541
+ if (node.type === type) {
542
+ if (dispatch) {
543
+ const from = $pos.before(depth);
544
+ const to = $pos.after(depth);
545
+ tr.delete(from, to).scrollIntoView();
546
+ }
547
+ return true;
548
+ }
549
+ }
550
+ return false;
551
+ };
552
+ var deleteRange = (range) => ({ tr, dispatch }) => {
553
+ const { from, to } = range;
554
+ if (dispatch) {
555
+ tr.delete(from, to);
556
+ }
557
+ return true;
558
+ };
559
+ var deleteSelection = () => ({ state, dispatch }) => {
560
+ return deleteSelection$1(state, dispatch);
561
+ };
562
+ var enter = () => ({ commands }) => {
563
+ return commands.keyboardShortcut("Enter");
564
+ };
565
+ var exitCode = () => ({ state, dispatch }) => {
566
+ return exitCode$1(state, dispatch);
567
+ };
568
+ function isRegExp(value) {
569
+ return Object.prototype.toString.call(value) === "[object RegExp]";
570
+ }
571
+ function objectIncludes(object1, object2, options = { strict: true }) {
572
+ const keys = Object.keys(object2);
573
+ if (!keys.length) {
574
+ return true;
575
+ }
576
+ return keys.every((key) => {
577
+ if (options.strict) {
578
+ return object2[key] === object1[key];
579
+ }
580
+ if (isRegExp(object2[key])) {
581
+ return object2[key].test(object1[key]);
582
+ }
583
+ return object2[key] === object1[key];
584
+ });
585
+ }
586
+ function findMarkInSet(marks, type, attributes = {}) {
587
+ return marks.find((item) => {
588
+ return item.type === type && objectIncludes(
589
+ // Only check equality for the attributes that are provided
590
+ Object.fromEntries(Object.keys(attributes).map((k) => [k, item.attrs[k]])),
591
+ attributes
592
+ );
593
+ });
594
+ }
595
+ function isMarkInSet(marks, type, attributes = {}) {
596
+ return !!findMarkInSet(marks, type, attributes);
597
+ }
598
+ function getMarkRange($pos, type, attributes) {
599
+ var _a;
600
+ if (!$pos || !type) {
601
+ return;
602
+ }
603
+ let start = $pos.parent.childAfter($pos.parentOffset);
604
+ if (!start.node || !start.node.marks.some((mark2) => mark2.type === type)) {
605
+ start = $pos.parent.childBefore($pos.parentOffset);
606
+ }
607
+ if (!start.node || !start.node.marks.some((mark2) => mark2.type === type)) {
608
+ return;
609
+ }
610
+ attributes = attributes || ((_a = start.node.marks[0]) == null ? void 0 : _a.attrs);
611
+ const mark = findMarkInSet([...start.node.marks], type, attributes);
612
+ if (!mark) {
613
+ return;
614
+ }
615
+ let startIndex = start.index;
616
+ let startPos = $pos.start() + start.offset;
617
+ let endIndex = startIndex + 1;
618
+ let endPos = startPos + start.node.nodeSize;
619
+ while (startIndex > 0 && isMarkInSet([...$pos.parent.child(startIndex - 1).marks], type, attributes)) {
620
+ startIndex -= 1;
621
+ startPos -= $pos.parent.child(startIndex).nodeSize;
622
+ }
623
+ while (endIndex < $pos.parent.childCount && isMarkInSet([...$pos.parent.child(endIndex).marks], type, attributes)) {
624
+ endPos += $pos.parent.child(endIndex).nodeSize;
625
+ endIndex += 1;
626
+ }
627
+ return {
628
+ from: startPos,
629
+ to: endPos
630
+ };
631
+ }
632
+ function getMarkType(nameOrType, schema) {
633
+ if (typeof nameOrType === "string") {
634
+ if (!schema.marks[nameOrType]) {
635
+ throw Error(`There is no mark type named '${nameOrType}'. Maybe you forgot to add the extension?`);
636
+ }
637
+ return schema.marks[nameOrType];
638
+ }
639
+ return nameOrType;
640
+ }
641
+ var extendMarkRange = (typeOrName, attributes = {}) => ({ tr, state, dispatch }) => {
642
+ const type = getMarkType(typeOrName, state.schema);
643
+ const { doc, selection } = tr;
644
+ const { $from, from, to } = selection;
645
+ if (dispatch) {
646
+ const range = getMarkRange($from, type, attributes);
647
+ if (range && range.from <= from && range.to >= to) {
648
+ const newSelection = TextSelection.create(doc, range.from, range.to);
649
+ tr.setSelection(newSelection);
650
+ }
651
+ }
652
+ return true;
653
+ };
654
+ var first = (commands) => (props) => {
655
+ const items = typeof commands === "function" ? commands(props) : commands;
656
+ for (let i = 0; i < items.length; i += 1) {
657
+ if (items[i](props)) {
658
+ return true;
659
+ }
660
+ }
661
+ return false;
662
+ };
663
+ function isTextSelection(value) {
664
+ return value instanceof TextSelection;
665
+ }
666
+ function minMax(value = 0, min = 0, max = 0) {
667
+ return Math.min(Math.max(value, min), max);
668
+ }
669
+ function resolveFocusPosition(doc, position = null) {
670
+ if (!position) {
671
+ return null;
672
+ }
673
+ const selectionAtStart = Selection.atStart(doc);
674
+ const selectionAtEnd = Selection.atEnd(doc);
675
+ if (position === "start" || position === true) {
676
+ return selectionAtStart;
677
+ }
678
+ if (position === "end") {
679
+ return selectionAtEnd;
680
+ }
681
+ const minPos = selectionAtStart.from;
682
+ const maxPos = selectionAtEnd.to;
683
+ if (position === "all") {
684
+ return TextSelection.create(doc, minMax(0, minPos, maxPos), minMax(doc.content.size, minPos, maxPos));
685
+ }
686
+ return TextSelection.create(doc, minMax(position, minPos, maxPos), minMax(position, minPos, maxPos));
687
+ }
688
+ function isAndroid() {
689
+ return navigator.platform === "Android" || /android/i.test(navigator.userAgent);
690
+ }
691
+ function isiOS() {
692
+ return ["iPad Simulator", "iPhone Simulator", "iPod Simulator", "iPad", "iPhone", "iPod"].includes(navigator.platform) || // iPad on iOS 13 detection
693
+ navigator.userAgent.includes("Mac") && "ontouchend" in document;
694
+ }
695
+ function isSafari() {
696
+ return typeof navigator !== "undefined" ? /^((?!chrome|android).)*safari/i.test(navigator.userAgent) : false;
697
+ }
698
+ var focus = (position = null, options = {}) => ({ editor, view, tr, dispatch }) => {
699
+ options = {
700
+ scrollIntoView: true,
701
+ ...options
702
+ };
703
+ const delayedFocus = () => {
704
+ if (isiOS() || isAndroid()) {
705
+ view.dom.focus();
706
+ }
707
+ if (isSafari() && !isiOS() && !isAndroid()) {
708
+ view.dom.focus({ preventScroll: true });
709
+ }
710
+ requestAnimationFrame(() => {
711
+ if (!editor.isDestroyed) {
712
+ view.focus();
713
+ if (options == null ? void 0 : options.scrollIntoView) {
714
+ editor.commands.scrollIntoView();
715
+ }
716
+ }
717
+ });
718
+ };
719
+ try {
720
+ if (view.hasFocus() && position === null || position === false) {
721
+ return true;
722
+ }
723
+ } catch {
724
+ return false;
725
+ }
726
+ if (dispatch && position === null && !isTextSelection(editor.state.selection)) {
727
+ delayedFocus();
728
+ return true;
729
+ }
730
+ const selection = resolveFocusPosition(tr.doc, position) || editor.state.selection;
731
+ const isSameSelection = editor.state.selection.eq(selection);
732
+ if (dispatch) {
733
+ if (!isSameSelection) {
734
+ tr.setSelection(selection);
735
+ }
736
+ if (isSameSelection && tr.storedMarks) {
737
+ tr.setStoredMarks(tr.storedMarks);
738
+ }
739
+ delayedFocus();
740
+ }
741
+ return true;
742
+ };
743
+ var forEach = (items, fn) => (props) => {
744
+ return items.every((item, index) => fn(item, { ...props, index }));
745
+ };
746
+ var insertContent = (value, options) => ({ tr, commands }) => {
747
+ return commands.insertContentAt({ from: tr.selection.from, to: tr.selection.to }, value, options);
748
+ };
749
+ var removeWhitespaces = (node) => {
750
+ const children = node.childNodes;
751
+ for (let i = children.length - 1; i >= 0; i -= 1) {
752
+ const child = children[i];
753
+ if (child.nodeType === 3 && child.nodeValue && /^(\n\s\s|\n)$/.test(child.nodeValue)) {
754
+ node.removeChild(child);
755
+ } else if (child.nodeType === 1) {
756
+ removeWhitespaces(child);
757
+ }
758
+ }
759
+ return node;
760
+ };
761
+ function elementFromString(value) {
762
+ if (typeof window === "undefined") {
763
+ throw new Error("[tiptap error]: there is no window object available, so this function cannot be used");
764
+ }
765
+ const wrappedValue = `<body>${value}</body>`;
766
+ const html = new window.DOMParser().parseFromString(wrappedValue, "text/html").body;
767
+ return removeWhitespaces(html);
768
+ }
769
+ function createNodeFromContent(content, schema, options) {
770
+ if (content instanceof Node || content instanceof Fragment) {
771
+ return content;
772
+ }
773
+ options = {
774
+ slice: true,
775
+ parseOptions: {},
776
+ ...options
777
+ };
778
+ const isJSONContent = typeof content === "object" && content !== null;
779
+ const isTextContent = typeof content === "string";
780
+ if (isJSONContent) {
781
+ try {
782
+ const isArrayContent = Array.isArray(content) && content.length > 0;
783
+ if (isArrayContent) {
784
+ return Fragment.fromArray(content.map((item) => schema.nodeFromJSON(item)));
785
+ }
786
+ const node = schema.nodeFromJSON(content);
787
+ if (options.errorOnInvalidContent) {
788
+ node.check();
789
+ }
790
+ return node;
791
+ } catch (error) {
792
+ if (options.errorOnInvalidContent) {
793
+ throw new Error("[tiptap error]: Invalid JSON content", { cause: error });
794
+ }
795
+ console.warn("[tiptap warn]: Invalid content.", "Passed value:", content, "Error:", error);
796
+ return createNodeFromContent("", schema, options);
797
+ }
798
+ }
799
+ if (isTextContent) {
800
+ if (options.errorOnInvalidContent) {
801
+ let hasInvalidContent = false;
802
+ let invalidContent = "";
803
+ const contentCheckSchema = new Schema({
804
+ topNode: schema.spec.topNode,
805
+ marks: schema.spec.marks,
806
+ // Prosemirror's schemas are executed such that: the last to execute, matches last
807
+ // This means that we can add a catch-all node at the end of the schema to catch any content that we don't know how to handle
808
+ nodes: schema.spec.nodes.append({
809
+ __tiptap__private__unknown__catch__all__node: {
810
+ content: "inline*",
811
+ group: "block",
812
+ parseDOM: [
813
+ {
814
+ tag: "*",
815
+ getAttrs: (e) => {
816
+ hasInvalidContent = true;
817
+ invalidContent = typeof e === "string" ? e : e.outerHTML;
818
+ return null;
819
+ }
820
+ }
821
+ ]
822
+ }
823
+ })
824
+ });
825
+ if (options.slice) {
826
+ DOMParser.fromSchema(contentCheckSchema).parseSlice(elementFromString(content), options.parseOptions);
827
+ } else {
828
+ DOMParser.fromSchema(contentCheckSchema).parse(elementFromString(content), options.parseOptions);
829
+ }
830
+ if (options.errorOnInvalidContent && hasInvalidContent) {
831
+ throw new Error("[tiptap error]: Invalid HTML content", {
832
+ cause: new Error(`Invalid element found: ${invalidContent}`)
833
+ });
834
+ }
835
+ }
836
+ const parser = DOMParser.fromSchema(schema);
837
+ if (options.slice) {
838
+ return parser.parseSlice(elementFromString(content), options.parseOptions).content;
839
+ }
840
+ return parser.parse(elementFromString(content), options.parseOptions);
841
+ }
842
+ return createNodeFromContent("", schema, options);
843
+ }
844
+ function selectionToInsertionEnd(tr, startLen, bias) {
845
+ const last = tr.steps.length - 1;
846
+ if (last < startLen) {
847
+ return;
848
+ }
849
+ const step = tr.steps[last];
850
+ if (!(step instanceof ReplaceStep || step instanceof ReplaceAroundStep)) {
851
+ return;
852
+ }
853
+ const map = tr.mapping.maps[last];
854
+ let end = 0;
855
+ map.forEach((_from, _to, _newFrom, newTo) => {
856
+ if (end === 0) {
857
+ end = newTo;
858
+ }
859
+ });
860
+ tr.setSelection(Selection.near(tr.doc.resolve(end), bias));
861
+ }
862
+ var isFragment = (nodeOrFragment) => {
863
+ return !("type" in nodeOrFragment);
864
+ };
865
+ var insertContentAt = (position, value, options) => ({ tr, dispatch, editor }) => {
866
+ var _a;
867
+ if (dispatch) {
868
+ options = {
869
+ parseOptions: editor.options.parseOptions,
870
+ updateSelection: true,
871
+ applyInputRules: false,
872
+ applyPasteRules: false,
873
+ ...options
874
+ };
875
+ let content;
876
+ const emitContentError = (error) => {
877
+ editor.emit("contentError", {
878
+ editor,
879
+ error,
880
+ disableCollaboration: () => {
881
+ if ("collaboration" in editor.storage && typeof editor.storage.collaboration === "object" && editor.storage.collaboration) {
882
+ editor.storage.collaboration.isDisabled = true;
883
+ }
884
+ }
885
+ });
886
+ };
887
+ const parseOptions = {
888
+ preserveWhitespace: "full",
889
+ ...options.parseOptions
890
+ };
891
+ if (!options.errorOnInvalidContent && !editor.options.enableContentCheck && editor.options.emitContentError) {
892
+ try {
893
+ createNodeFromContent(value, editor.schema, {
894
+ parseOptions,
895
+ errorOnInvalidContent: true
896
+ });
897
+ } catch (e) {
898
+ emitContentError(e);
899
+ }
900
+ }
901
+ try {
902
+ content = createNodeFromContent(value, editor.schema, {
903
+ parseOptions,
904
+ errorOnInvalidContent: (_a = options.errorOnInvalidContent) != null ? _a : editor.options.enableContentCheck
905
+ });
906
+ } catch (e) {
907
+ emitContentError(e);
908
+ return false;
909
+ }
910
+ let { from, to } = typeof position === "number" ? { from: position, to: position } : { from: position.from, to: position.to };
911
+ let isOnlyTextContent = true;
912
+ let isOnlyBlockContent = true;
913
+ const nodes = isFragment(content) ? content : [content];
914
+ nodes.forEach((node) => {
915
+ node.check();
916
+ isOnlyTextContent = isOnlyTextContent ? node.isText && node.marks.length === 0 : false;
917
+ isOnlyBlockContent = isOnlyBlockContent ? node.isBlock : false;
918
+ });
919
+ if (from === to && isOnlyBlockContent) {
920
+ const { parent } = tr.doc.resolve(from);
921
+ const isEmptyTextBlock = parent.isTextblock && !parent.type.spec.code && !parent.childCount;
922
+ if (isEmptyTextBlock) {
923
+ from -= 1;
924
+ to += 1;
925
+ }
926
+ }
927
+ let newContent;
928
+ if (isOnlyTextContent) {
929
+ if (Array.isArray(value)) {
930
+ newContent = value.map((v) => v.text || "").join("");
931
+ } else if (value instanceof Fragment) {
932
+ let text = "";
933
+ value.forEach((node) => {
934
+ if (node.text) {
935
+ text += node.text;
936
+ }
937
+ });
938
+ newContent = text;
939
+ } else if (typeof value === "object" && !!value && !!value.text) {
940
+ newContent = value.text;
941
+ } else {
942
+ newContent = value;
943
+ }
944
+ tr.insertText(newContent, from, to);
945
+ } else {
946
+ newContent = content;
947
+ const $from = tr.doc.resolve(from);
948
+ const $fromNode = $from.node();
949
+ const fromSelectionAtStart = $from.parentOffset === 0;
950
+ const isTextSelection2 = $fromNode.isText || $fromNode.isTextblock;
951
+ const hasContent = $fromNode.content.size > 0;
952
+ if (fromSelectionAtStart && isTextSelection2 && hasContent) {
953
+ from = Math.max(0, from - 1);
954
+ }
955
+ tr.replaceWith(from, to, newContent);
956
+ }
957
+ if (options.updateSelection) {
958
+ selectionToInsertionEnd(tr, tr.steps.length - 1, -1);
959
+ }
960
+ if (options.applyInputRules) {
961
+ tr.setMeta("applyInputRules", { from, text: newContent });
962
+ }
963
+ if (options.applyPasteRules) {
964
+ tr.setMeta("applyPasteRules", { from, text: newContent });
965
+ }
966
+ }
967
+ return true;
968
+ };
969
+ var joinUp = () => ({ state, dispatch }) => {
970
+ return joinUp$1(state, dispatch);
971
+ };
972
+ var joinDown = () => ({ state, dispatch }) => {
973
+ return joinDown$1(state, dispatch);
974
+ };
975
+ var joinBackward = () => ({ state, dispatch }) => {
976
+ return joinBackward$1(state, dispatch);
977
+ };
978
+ var joinForward = () => ({ state, dispatch }) => {
979
+ return joinForward$1(state, dispatch);
980
+ };
981
+ var joinItemBackward = () => ({ state, dispatch, tr }) => {
982
+ try {
983
+ const point = joinPoint(state.doc, state.selection.$from.pos, -1);
984
+ if (point === null || point === void 0) {
985
+ return false;
986
+ }
987
+ tr.join(point, 2);
988
+ if (dispatch) {
989
+ dispatch(tr);
990
+ }
991
+ return true;
992
+ } catch {
993
+ return false;
994
+ }
995
+ };
996
+ var joinItemForward = () => ({ state, dispatch, tr }) => {
997
+ try {
998
+ const point = joinPoint(state.doc, state.selection.$from.pos, 1);
999
+ if (point === null || point === void 0) {
1000
+ return false;
1001
+ }
1002
+ tr.join(point, 2);
1003
+ if (dispatch) {
1004
+ dispatch(tr);
1005
+ }
1006
+ return true;
1007
+ } catch {
1008
+ return false;
1009
+ }
1010
+ };
1011
+ var joinTextblockBackward = () => ({ state, dispatch }) => {
1012
+ return joinTextblockBackward$1(state, dispatch);
1013
+ };
1014
+ var joinTextblockForward = () => ({ state, dispatch }) => {
1015
+ return joinTextblockForward$1(state, dispatch);
1016
+ };
1017
+ function isMacOS() {
1018
+ return typeof navigator !== "undefined" ? /Mac/.test(navigator.platform) : false;
1019
+ }
1020
+ function normalizeKeyName(name) {
1021
+ const parts = name.split(/-(?!$)/);
1022
+ let result = parts[parts.length - 1];
1023
+ if (result === "Space") {
1024
+ result = " ";
1025
+ }
1026
+ let alt;
1027
+ let ctrl;
1028
+ let shift;
1029
+ let meta;
1030
+ for (let i = 0; i < parts.length - 1; i += 1) {
1031
+ const mod = parts[i];
1032
+ if (/^(cmd|meta|m)$/i.test(mod)) {
1033
+ meta = true;
1034
+ } else if (/^a(lt)?$/i.test(mod)) {
1035
+ alt = true;
1036
+ } else if (/^(c|ctrl|control)$/i.test(mod)) {
1037
+ ctrl = true;
1038
+ } else if (/^s(hift)?$/i.test(mod)) {
1039
+ shift = true;
1040
+ } else if (/^mod$/i.test(mod)) {
1041
+ if (isiOS() || isMacOS()) {
1042
+ meta = true;
1043
+ } else {
1044
+ ctrl = true;
1045
+ }
1046
+ } else {
1047
+ throw new Error(`Unrecognized modifier name: ${mod}`);
1048
+ }
1049
+ }
1050
+ if (alt) {
1051
+ result = `Alt-${result}`;
1052
+ }
1053
+ if (ctrl) {
1054
+ result = `Ctrl-${result}`;
1055
+ }
1056
+ if (meta) {
1057
+ result = `Meta-${result}`;
1058
+ }
1059
+ if (shift) {
1060
+ result = `Shift-${result}`;
1061
+ }
1062
+ return result;
1063
+ }
1064
+ var keyboardShortcut = (name) => ({ editor, view, tr, dispatch }) => {
1065
+ const keys = normalizeKeyName(name).split(/-(?!$)/);
1066
+ const key = keys.find((item) => !["Alt", "Ctrl", "Meta", "Shift"].includes(item));
1067
+ const event = new KeyboardEvent("keydown", {
1068
+ key: key === "Space" ? " " : key,
1069
+ altKey: keys.includes("Alt"),
1070
+ ctrlKey: keys.includes("Ctrl"),
1071
+ metaKey: keys.includes("Meta"),
1072
+ shiftKey: keys.includes("Shift"),
1073
+ bubbles: true,
1074
+ cancelable: true
1075
+ });
1076
+ const capturedTransaction = editor.captureTransaction(() => {
1077
+ view.someProp("handleKeyDown", (f) => f(view, event));
1078
+ });
1079
+ capturedTransaction == null ? void 0 : capturedTransaction.steps.forEach((step) => {
1080
+ const newStep = step.map(tr.mapping);
1081
+ if (newStep && dispatch) {
1082
+ tr.maybeStep(newStep);
1083
+ }
1084
+ });
1085
+ return true;
1086
+ };
1087
+ function isNodeActive(state, typeOrName, attributes = {}) {
1088
+ const { from, to, empty } = state.selection;
1089
+ const type = typeOrName ? getNodeType(typeOrName, state.schema) : null;
1090
+ const nodeRanges = [];
1091
+ state.doc.nodesBetween(from, to, (node, pos) => {
1092
+ if (node.isText) {
1093
+ return;
1094
+ }
1095
+ const relativeFrom = Math.max(from, pos);
1096
+ const relativeTo = Math.min(to, pos + node.nodeSize);
1097
+ nodeRanges.push({
1098
+ node,
1099
+ from: relativeFrom,
1100
+ to: relativeTo
1101
+ });
1102
+ });
1103
+ const selectionRange = to - from;
1104
+ const matchedNodeRanges = nodeRanges.filter((nodeRange) => {
1105
+ if (!type) {
1106
+ return true;
1107
+ }
1108
+ return type.name === nodeRange.node.type.name;
1109
+ }).filter((nodeRange) => objectIncludes(nodeRange.node.attrs, attributes, { strict: false }));
1110
+ if (empty) {
1111
+ return !!matchedNodeRanges.length;
1112
+ }
1113
+ const range = matchedNodeRanges.reduce((sum, nodeRange) => sum + nodeRange.to - nodeRange.from, 0);
1114
+ return range >= selectionRange;
1115
+ }
1116
+ var lift = (typeOrName, attributes = {}) => ({ state, dispatch }) => {
1117
+ const type = getNodeType(typeOrName, state.schema);
1118
+ const isActive2 = isNodeActive(state, type, attributes);
1119
+ if (!isActive2) {
1120
+ return false;
1121
+ }
1122
+ return lift$1(state, dispatch);
1123
+ };
1124
+ var liftEmptyBlock = () => ({ state, dispatch }) => {
1125
+ return liftEmptyBlock$1(state, dispatch);
1126
+ };
1127
+ var liftListItem = (typeOrName) => ({ state, dispatch }) => {
1128
+ const type = getNodeType(typeOrName, state.schema);
1129
+ return liftListItem$1(type)(state, dispatch);
1130
+ };
1131
+ var newlineInCode = () => ({ state, dispatch }) => {
1132
+ return newlineInCode$1(state, dispatch);
1133
+ };
1134
+ function getSchemaTypeNameByName(name, schema) {
1135
+ if (schema.nodes[name]) {
1136
+ return "node";
1137
+ }
1138
+ if (schema.marks[name]) {
1139
+ return "mark";
1140
+ }
1141
+ return null;
1142
+ }
1143
+ function deleteProps(obj, propOrProps) {
1144
+ const props = typeof propOrProps === "string" ? [propOrProps] : propOrProps;
1145
+ return Object.keys(obj).reduce((newObj, prop) => {
1146
+ if (!props.includes(prop)) {
1147
+ newObj[prop] = obj[prop];
1148
+ }
1149
+ return newObj;
1150
+ }, {});
1151
+ }
1152
+ var resetAttributes = (typeOrName, attributes) => ({ tr, state, dispatch }) => {
1153
+ let nodeType = null;
1154
+ let markType = null;
1155
+ const schemaType = getSchemaTypeNameByName(
1156
+ typeof typeOrName === "string" ? typeOrName : typeOrName.name,
1157
+ state.schema
1158
+ );
1159
+ if (!schemaType) {
1160
+ return false;
1161
+ }
1162
+ if (schemaType === "node") {
1163
+ nodeType = getNodeType(typeOrName, state.schema);
1164
+ }
1165
+ if (schemaType === "mark") {
1166
+ markType = getMarkType(typeOrName, state.schema);
1167
+ }
1168
+ let canReset = false;
1169
+ tr.selection.ranges.forEach((range) => {
1170
+ state.doc.nodesBetween(range.$from.pos, range.$to.pos, (node, pos) => {
1171
+ if (nodeType && nodeType === node.type) {
1172
+ canReset = true;
1173
+ if (dispatch) {
1174
+ tr.setNodeMarkup(pos, void 0, deleteProps(node.attrs, attributes));
1175
+ }
1176
+ }
1177
+ if (markType && node.marks.length) {
1178
+ node.marks.forEach((mark) => {
1179
+ if (markType === mark.type) {
1180
+ canReset = true;
1181
+ if (dispatch) {
1182
+ tr.addMark(pos, pos + node.nodeSize, markType.create(deleteProps(mark.attrs, attributes)));
1183
+ }
1184
+ }
1185
+ });
1186
+ }
1187
+ });
1188
+ });
1189
+ return canReset;
1190
+ };
1191
+ var scrollIntoView = () => ({ tr, dispatch }) => {
1192
+ if (dispatch) {
1193
+ tr.scrollIntoView();
1194
+ }
1195
+ return true;
1196
+ };
1197
+ var selectAll = () => ({ tr, dispatch }) => {
1198
+ if (dispatch) {
1199
+ const selection = new AllSelection(tr.doc);
1200
+ tr.setSelection(selection);
1201
+ }
1202
+ return true;
1203
+ };
1204
+ var selectNodeBackward = () => ({ state, dispatch }) => {
1205
+ return selectNodeBackward$1(state, dispatch);
1206
+ };
1207
+ var selectNodeForward = () => ({ state, dispatch }) => {
1208
+ return selectNodeForward$1(state, dispatch);
1209
+ };
1210
+ var selectParentNode = () => ({ state, dispatch }) => {
1211
+ return selectParentNode$1(state, dispatch);
1212
+ };
1213
+ var selectTextblockEnd = () => ({ state, dispatch }) => {
1214
+ return selectTextblockEnd$1(state, dispatch);
1215
+ };
1216
+ var selectTextblockStart = () => ({ state, dispatch }) => {
1217
+ return selectTextblockStart$1(state, dispatch);
1218
+ };
1219
+ function createDocument(content, schema, parseOptions = {}, options = {}) {
1220
+ return createNodeFromContent(content, schema, {
1221
+ slice: false,
1222
+ parseOptions,
1223
+ errorOnInvalidContent: options.errorOnInvalidContent
1224
+ });
1225
+ }
1226
+ var setContent = (content, { errorOnInvalidContent, emitUpdate = true, parseOptions = {} } = {}) => ({ editor, tr, dispatch, commands }) => {
1227
+ const { doc } = tr;
1228
+ if (parseOptions.preserveWhitespace !== "full") {
1229
+ const document2 = createDocument(content, editor.schema, parseOptions, {
1230
+ errorOnInvalidContent: errorOnInvalidContent != null ? errorOnInvalidContent : editor.options.enableContentCheck
1231
+ });
1232
+ if (dispatch) {
1233
+ tr.replaceWith(0, doc.content.size, document2).setMeta("preventUpdate", !emitUpdate);
1234
+ }
1235
+ return true;
1236
+ }
1237
+ if (dispatch) {
1238
+ tr.setMeta("preventUpdate", !emitUpdate);
1239
+ }
1240
+ return commands.insertContentAt({ from: 0, to: doc.content.size }, content, {
1241
+ parseOptions,
1242
+ errorOnInvalidContent: errorOnInvalidContent != null ? errorOnInvalidContent : editor.options.enableContentCheck
1243
+ });
1244
+ };
1245
+ function getMarkAttributes(state, typeOrName) {
1246
+ const type = getMarkType(typeOrName, state.schema);
1247
+ const { from, to, empty } = state.selection;
1248
+ const marks = [];
1249
+ if (empty) {
1250
+ if (state.storedMarks) {
1251
+ marks.push(...state.storedMarks);
1252
+ }
1253
+ marks.push(...state.selection.$head.marks());
1254
+ } else {
1255
+ state.doc.nodesBetween(from, to, (node) => {
1256
+ marks.push(...node.marks);
1257
+ });
1258
+ }
1259
+ const mark = marks.find((markItem) => markItem.type.name === type.name);
1260
+ if (!mark) {
1261
+ return {};
1262
+ }
1263
+ return { ...mark.attrs };
1264
+ }
1265
+ function combineTransactionSteps(oldDoc, transactions) {
1266
+ const transform = new Transform(oldDoc);
1267
+ transactions.forEach((transaction) => {
1268
+ transaction.steps.forEach((step) => {
1269
+ transform.step(step);
1270
+ });
1271
+ });
1272
+ return transform;
1273
+ }
1274
+ function defaultBlockAt(match) {
1275
+ for (let i = 0; i < match.edgeCount; i += 1) {
1276
+ const { type } = match.edge(i);
1277
+ if (type.isTextblock && !type.hasRequiredAttrs()) {
1278
+ return type;
1279
+ }
1280
+ }
1281
+ return null;
1282
+ }
1283
+ function findParentNodeClosestToPos($pos, predicate) {
1284
+ for (let i = $pos.depth; i > 0; i -= 1) {
1285
+ const node = $pos.node(i);
1286
+ if (predicate(node)) {
1287
+ return {
1288
+ pos: i > 0 ? $pos.before(i) : 0,
1289
+ start: $pos.start(i),
1290
+ depth: i,
1291
+ node
1292
+ };
1293
+ }
1294
+ }
1295
+ }
1296
+ function findParentNode(predicate) {
1297
+ return (selection) => findParentNodeClosestToPos(selection.$from, predicate);
1298
+ }
1299
+ function getExtensionField(extension, field, context) {
1300
+ if (extension.config[field] === void 0 && extension.parent) {
1301
+ return getExtensionField(extension.parent, field, context);
1302
+ }
1303
+ if (typeof extension.config[field] === "function") {
1304
+ const value = extension.config[field].bind({
1305
+ ...context,
1306
+ parent: extension.parent ? getExtensionField(extension.parent, field, context) : null
1307
+ });
1308
+ return value;
1309
+ }
1310
+ return extension.config[field];
1311
+ }
1312
+ function isFunction(value) {
1313
+ return typeof value === "function";
1314
+ }
1315
+ function callOrReturn(value, context = void 0, ...props) {
1316
+ if (isFunction(value)) {
1317
+ if (context) {
1318
+ return value.bind(context)(...props);
1319
+ }
1320
+ return value(...props);
1321
+ }
1322
+ return value;
1323
+ }
1324
+ function splitExtensions(extensions) {
1325
+ const baseExtensions = extensions.filter((extension) => extension.type === "extension");
1326
+ const nodeExtensions = extensions.filter((extension) => extension.type === "node");
1327
+ const markExtensions = extensions.filter((extension) => extension.type === "mark");
1328
+ return {
1329
+ baseExtensions,
1330
+ nodeExtensions,
1331
+ markExtensions
1332
+ };
1333
+ }
1334
+ function mergeAttributes(...objects) {
1335
+ return objects.filter((item) => !!item).reduce((items, item) => {
1336
+ const mergedAttributes = { ...items };
1337
+ Object.entries(item).forEach(([key, value]) => {
1338
+ const exists = mergedAttributes[key];
1339
+ if (!exists) {
1340
+ mergedAttributes[key] = value;
1341
+ return;
1342
+ }
1343
+ if (key === "class") {
1344
+ const valueClasses = value ? String(value).split(" ") : [];
1345
+ const existingClasses = mergedAttributes[key] ? mergedAttributes[key].split(" ") : [];
1346
+ const insertClasses = valueClasses.filter((valueClass) => !existingClasses.includes(valueClass));
1347
+ mergedAttributes[key] = [...existingClasses, ...insertClasses].join(" ");
1348
+ } else if (key === "style") {
1349
+ const newStyles = value ? value.split(";").map((style2) => style2.trim()).filter(Boolean) : [];
1350
+ const existingStyles = mergedAttributes[key] ? mergedAttributes[key].split(";").map((style2) => style2.trim()).filter(Boolean) : [];
1351
+ const styleMap = /* @__PURE__ */ new Map();
1352
+ existingStyles.forEach((style2) => {
1353
+ const [property, val] = style2.split(":").map((part) => part.trim());
1354
+ styleMap.set(property, val);
1355
+ });
1356
+ newStyles.forEach((style2) => {
1357
+ const [property, val] = style2.split(":").map((part) => part.trim());
1358
+ styleMap.set(property, val);
1359
+ });
1360
+ mergedAttributes[key] = Array.from(styleMap.entries()).map(([property, val]) => `${property}: ${val}`).join("; ");
1361
+ } else {
1362
+ mergedAttributes[key] = value;
1363
+ }
1364
+ });
1365
+ return mergedAttributes;
1366
+ }, {});
1367
+ }
1368
+ function getTextBetween(startNode, range, options) {
1369
+ const { from, to } = range;
1370
+ const { blockSeparator = "\n\n", textSerializers = {} } = options || {};
1371
+ let text = "";
1372
+ startNode.nodesBetween(from, to, (node, pos, parent, index) => {
1373
+ var _a;
1374
+ if (node.isBlock && pos > from) {
1375
+ text += blockSeparator;
1376
+ }
1377
+ const textSerializer = textSerializers == null ? void 0 : textSerializers[node.type.name];
1378
+ if (textSerializer) {
1379
+ if (parent) {
1380
+ text += textSerializer({
1381
+ node,
1382
+ pos,
1383
+ parent,
1384
+ index,
1385
+ range
1386
+ });
1387
+ }
1388
+ return false;
1389
+ }
1390
+ if (node.isText) {
1391
+ text += (_a = node == null ? void 0 : node.text) == null ? void 0 : _a.slice(Math.max(from, pos) - pos, to - pos);
1392
+ }
1393
+ });
1394
+ return text;
1395
+ }
1396
+ function getTextSerializersFromSchema(schema) {
1397
+ return Object.fromEntries(
1398
+ Object.entries(schema.nodes).filter(([, node]) => node.spec.toText).map(([name, node]) => [name, node.spec.toText])
1399
+ );
1400
+ }
1401
+ function removeDuplicates(array, by = JSON.stringify) {
1402
+ const seen = {};
1403
+ return array.filter((item) => {
1404
+ const key = by(item);
1405
+ return Object.prototype.hasOwnProperty.call(seen, key) ? false : seen[key] = true;
1406
+ });
1407
+ }
1408
+ function simplifyChangedRanges(changes) {
1409
+ const uniqueChanges = removeDuplicates(changes);
1410
+ return uniqueChanges.length === 1 ? uniqueChanges : uniqueChanges.filter((change, index) => {
1411
+ const rest = uniqueChanges.filter((_, i) => i !== index);
1412
+ return !rest.some((otherChange) => {
1413
+ return change.oldRange.from >= otherChange.oldRange.from && change.oldRange.to <= otherChange.oldRange.to && change.newRange.from >= otherChange.newRange.from && change.newRange.to <= otherChange.newRange.to;
1414
+ });
1415
+ });
1416
+ }
1417
+ function getChangedRanges(transform) {
1418
+ const { mapping, steps } = transform;
1419
+ const changes = [];
1420
+ mapping.maps.forEach((stepMap, index) => {
1421
+ const ranges = [];
1422
+ if (!stepMap.ranges.length) {
1423
+ const { from, to } = steps[index];
1424
+ if (from === void 0 || to === void 0) {
1425
+ return;
1426
+ }
1427
+ ranges.push({ from, to });
1428
+ } else {
1429
+ stepMap.forEach((from, to) => {
1430
+ ranges.push({ from, to });
1431
+ });
1432
+ }
1433
+ ranges.forEach(({ from, to }) => {
1434
+ const newStart = mapping.slice(index).map(from, -1);
1435
+ const newEnd = mapping.slice(index).map(to);
1436
+ const oldStart = mapping.invert().map(newStart, -1);
1437
+ const oldEnd = mapping.invert().map(newEnd);
1438
+ changes.push({
1439
+ oldRange: {
1440
+ from: oldStart,
1441
+ to: oldEnd
1442
+ },
1443
+ newRange: {
1444
+ from: newStart,
1445
+ to: newEnd
1446
+ }
1447
+ });
1448
+ });
1449
+ });
1450
+ return simplifyChangedRanges(changes);
1451
+ }
1452
+ function getSplittedAttributes(extensionAttributes, typeName, attributes) {
1453
+ return Object.fromEntries(
1454
+ Object.entries(attributes).filter(([name]) => {
1455
+ const extensionAttribute = extensionAttributes.find((item) => {
1456
+ return item.type === typeName && item.name === name;
1457
+ });
1458
+ if (!extensionAttribute) {
1459
+ return false;
1460
+ }
1461
+ return extensionAttribute.attribute.keepOnSplit;
1462
+ })
1463
+ );
1464
+ }
1465
+ function isMarkActive(state, typeOrName, attributes = {}) {
1466
+ const { empty, ranges } = state.selection;
1467
+ const type = typeOrName ? getMarkType(typeOrName, state.schema) : null;
1468
+ if (empty) {
1469
+ return !!(state.storedMarks || state.selection.$from.marks()).filter((mark) => {
1470
+ if (!type) {
1471
+ return true;
1472
+ }
1473
+ return type.name === mark.type.name;
1474
+ }).find((mark) => objectIncludes(mark.attrs, attributes, { strict: false }));
1475
+ }
1476
+ let selectionRange = 0;
1477
+ const markRanges = [];
1478
+ ranges.forEach(({ $from, $to }) => {
1479
+ const from = $from.pos;
1480
+ const to = $to.pos;
1481
+ state.doc.nodesBetween(from, to, (node, pos) => {
1482
+ if (!node.isText && !node.marks.length) {
1483
+ return;
1484
+ }
1485
+ const relativeFrom = Math.max(from, pos);
1486
+ const relativeTo = Math.min(to, pos + node.nodeSize);
1487
+ const range2 = relativeTo - relativeFrom;
1488
+ selectionRange += range2;
1489
+ markRanges.push(
1490
+ ...node.marks.map((mark) => ({
1491
+ mark,
1492
+ from: relativeFrom,
1493
+ to: relativeTo
1494
+ }))
1495
+ );
1496
+ });
1497
+ });
1498
+ if (selectionRange === 0) {
1499
+ return false;
1500
+ }
1501
+ const matchedRange = markRanges.filter((markRange) => {
1502
+ if (!type) {
1503
+ return true;
1504
+ }
1505
+ return type.name === markRange.mark.type.name;
1506
+ }).filter((markRange) => objectIncludes(markRange.mark.attrs, attributes, { strict: false })).reduce((sum, markRange) => sum + markRange.to - markRange.from, 0);
1507
+ const excludedRange = markRanges.filter((markRange) => {
1508
+ if (!type) {
1509
+ return true;
1510
+ }
1511
+ return markRange.mark.type !== type && markRange.mark.type.excludes(type);
1512
+ }).reduce((sum, markRange) => sum + markRange.to - markRange.from, 0);
1513
+ const range = matchedRange > 0 ? matchedRange + excludedRange : matchedRange;
1514
+ return range >= selectionRange;
1515
+ }
1516
+ function isList(name, extensions) {
1517
+ const { nodeExtensions } = splitExtensions(extensions);
1518
+ const extension = nodeExtensions.find((item) => item.name === name);
1519
+ if (!extension) {
1520
+ return false;
1521
+ }
1522
+ const context = {
1523
+ name: extension.name,
1524
+ options: extension.options,
1525
+ storage: extension.storage
1526
+ };
1527
+ const group = callOrReturn(getExtensionField(extension, "group", context));
1528
+ if (typeof group !== "string") {
1529
+ return false;
1530
+ }
1531
+ return group.split(" ").includes("list");
1532
+ }
1533
+ function isNodeEmpty(node, {
1534
+ checkChildren = true,
1535
+ ignoreWhitespace = false
1536
+ } = {}) {
1537
+ var _a;
1538
+ if (ignoreWhitespace) {
1539
+ if (node.type.name === "hardBreak") {
1540
+ return true;
1541
+ }
1542
+ if (node.isText) {
1543
+ return /^\s*$/m.test((_a = node.text) != null ? _a : "");
1544
+ }
1545
+ }
1546
+ if (node.isText) {
1547
+ return !node.text;
1548
+ }
1549
+ if (node.isAtom || node.isLeaf) {
1550
+ return false;
1551
+ }
1552
+ if (node.content.childCount === 0) {
1553
+ return true;
1554
+ }
1555
+ if (checkChildren) {
1556
+ let isContentEmpty = true;
1557
+ node.content.forEach((childNode) => {
1558
+ if (isContentEmpty === false) {
1559
+ return;
1560
+ }
1561
+ if (!isNodeEmpty(childNode, { ignoreWhitespace, checkChildren })) {
1562
+ isContentEmpty = false;
1563
+ }
1564
+ });
1565
+ return isContentEmpty;
1566
+ }
1567
+ return false;
1568
+ }
1569
+ function isNodeSelection(value) {
1570
+ return value instanceof NodeSelection;
1571
+ }
1572
+ function canSetMark(state, tr, newMarkType) {
1573
+ var _a;
1574
+ const { selection } = tr;
1575
+ let cursor = null;
1576
+ if (isTextSelection(selection)) {
1577
+ cursor = selection.$cursor;
1578
+ }
1579
+ if (cursor) {
1580
+ const currentMarks = (_a = state.storedMarks) != null ? _a : cursor.marks();
1581
+ const parentAllowsMarkType = cursor.parent.type.allowsMarkType(newMarkType);
1582
+ return parentAllowsMarkType && (!!newMarkType.isInSet(currentMarks) || !currentMarks.some((mark) => mark.type.excludes(newMarkType)));
1583
+ }
1584
+ const { ranges } = selection;
1585
+ return ranges.some(({ $from, $to }) => {
1586
+ let someNodeSupportsMark = $from.depth === 0 ? state.doc.inlineContent && state.doc.type.allowsMarkType(newMarkType) : false;
1587
+ state.doc.nodesBetween($from.pos, $to.pos, (node, _pos, parent) => {
1588
+ if (someNodeSupportsMark) {
1589
+ return false;
1590
+ }
1591
+ if (node.isInline) {
1592
+ const parentAllowsMarkType = !parent || parent.type.allowsMarkType(newMarkType);
1593
+ const currentMarksAllowMarkType = !!newMarkType.isInSet(node.marks) || !node.marks.some((otherMark) => otherMark.type.excludes(newMarkType));
1594
+ someNodeSupportsMark = parentAllowsMarkType && currentMarksAllowMarkType;
1595
+ }
1596
+ return !someNodeSupportsMark;
1597
+ });
1598
+ return someNodeSupportsMark;
1599
+ });
1600
+ }
1601
+ var setMark = (typeOrName, attributes = {}) => ({ tr, state, dispatch }) => {
1602
+ const { selection } = tr;
1603
+ const { empty, ranges } = selection;
1604
+ const type = getMarkType(typeOrName, state.schema);
1605
+ if (dispatch) {
1606
+ if (empty) {
1607
+ const oldAttributes = getMarkAttributes(state, type);
1608
+ tr.addStoredMark(
1609
+ type.create({
1610
+ ...oldAttributes,
1611
+ ...attributes
1612
+ })
1613
+ );
1614
+ } else {
1615
+ ranges.forEach((range) => {
1616
+ const from = range.$from.pos;
1617
+ const to = range.$to.pos;
1618
+ state.doc.nodesBetween(from, to, (node, pos) => {
1619
+ const trimmedFrom = Math.max(pos, from);
1620
+ const trimmedTo = Math.min(pos + node.nodeSize, to);
1621
+ const someHasMark = node.marks.find((mark) => mark.type === type);
1622
+ if (someHasMark) {
1623
+ node.marks.forEach((mark) => {
1624
+ if (type === mark.type) {
1625
+ tr.addMark(
1626
+ trimmedFrom,
1627
+ trimmedTo,
1628
+ type.create({
1629
+ ...mark.attrs,
1630
+ ...attributes
1631
+ })
1632
+ );
1633
+ }
1634
+ });
1635
+ } else {
1636
+ tr.addMark(trimmedFrom, trimmedTo, type.create(attributes));
1637
+ }
1638
+ });
1639
+ });
1640
+ }
1641
+ }
1642
+ return canSetMark(state, tr, type);
1643
+ };
1644
+ var setMeta = (key, value) => ({ tr }) => {
1645
+ tr.setMeta(key, value);
1646
+ return true;
1647
+ };
1648
+ var setNode = (typeOrName, attributes = {}) => ({ state, dispatch, chain }) => {
1649
+ const type = getNodeType(typeOrName, state.schema);
1650
+ let attributesToCopy;
1651
+ if (state.selection.$anchor.sameParent(state.selection.$head)) {
1652
+ attributesToCopy = state.selection.$anchor.parent.attrs;
1653
+ }
1654
+ if (!type.isTextblock) {
1655
+ console.warn('[tiptap warn]: Currently "setNode()" only supports text block nodes.');
1656
+ return false;
1657
+ }
1658
+ return chain().command(({ commands }) => {
1659
+ const canSetBlock = setBlockType(type, { ...attributesToCopy, ...attributes })(state);
1660
+ if (canSetBlock) {
1661
+ return true;
1662
+ }
1663
+ return commands.clearNodes();
1664
+ }).command(({ state: updatedState }) => {
1665
+ return setBlockType(type, { ...attributesToCopy, ...attributes })(updatedState, dispatch);
1666
+ }).run();
1667
+ };
1668
+ var setNodeSelection = (position) => ({ tr, dispatch }) => {
1669
+ if (dispatch) {
1670
+ const { doc } = tr;
1671
+ const from = minMax(position, 0, doc.content.size);
1672
+ const selection = NodeSelection.create(doc, from);
1673
+ tr.setSelection(selection);
1674
+ }
1675
+ return true;
1676
+ };
1677
+ var setTextDirection = (direction, position) => ({ tr, state, dispatch }) => {
1678
+ const { selection } = state;
1679
+ let from;
1680
+ let to;
1681
+ if (typeof position === "number") {
1682
+ from = position;
1683
+ to = position;
1684
+ } else if (position && "from" in position && "to" in position) {
1685
+ from = position.from;
1686
+ to = position.to;
1687
+ } else {
1688
+ from = selection.from;
1689
+ to = selection.to;
1690
+ }
1691
+ if (dispatch) {
1692
+ tr.doc.nodesBetween(from, to, (node, pos) => {
1693
+ if (node.isText) {
1694
+ return;
1695
+ }
1696
+ tr.setNodeMarkup(pos, void 0, {
1697
+ ...node.attrs,
1698
+ dir: direction
1699
+ });
1700
+ });
1701
+ }
1702
+ return true;
1703
+ };
1704
+ var setTextSelection = (position) => ({ tr, dispatch }) => {
1705
+ if (dispatch) {
1706
+ const { doc } = tr;
1707
+ const { from, to } = typeof position === "number" ? { from: position, to: position } : position;
1708
+ const minPos = TextSelection.atStart(doc).from;
1709
+ const maxPos = TextSelection.atEnd(doc).to;
1710
+ const resolvedFrom = minMax(from, minPos, maxPos);
1711
+ const resolvedEnd = minMax(to, minPos, maxPos);
1712
+ const selection = TextSelection.create(doc, resolvedFrom, resolvedEnd);
1713
+ tr.setSelection(selection);
1714
+ }
1715
+ return true;
1716
+ };
1717
+ var sinkListItem = (typeOrName) => ({ state, dispatch }) => {
1718
+ const type = getNodeType(typeOrName, state.schema);
1719
+ return sinkListItem$1(type)(state, dispatch);
1720
+ };
1721
+ function ensureMarks(state, splittableMarks) {
1722
+ const marks = state.storedMarks || state.selection.$to.parentOffset && state.selection.$from.marks();
1723
+ if (marks) {
1724
+ const filteredMarks = marks.filter((mark) => splittableMarks == null ? void 0 : splittableMarks.includes(mark.type.name));
1725
+ state.tr.ensureMarks(filteredMarks);
1726
+ }
1727
+ }
1728
+ var splitBlock = ({ keepMarks = true } = {}) => ({ tr, state, dispatch, editor }) => {
1729
+ const { selection, doc } = tr;
1730
+ const { $from, $to } = selection;
1731
+ const extensionAttributes = editor.extensionManager.attributes;
1732
+ const newAttributes = getSplittedAttributes(extensionAttributes, $from.node().type.name, $from.node().attrs);
1733
+ if (selection instanceof NodeSelection && selection.node.isBlock) {
1734
+ if (!$from.parentOffset || !canSplit(doc, $from.pos)) {
1735
+ return false;
1736
+ }
1737
+ if (dispatch) {
1738
+ if (keepMarks) {
1739
+ ensureMarks(state, editor.extensionManager.splittableMarks);
1740
+ }
1741
+ tr.split($from.pos).scrollIntoView();
1742
+ }
1743
+ return true;
1744
+ }
1745
+ if (!$from.parent.isBlock) {
1746
+ return false;
1747
+ }
1748
+ const atEnd = $to.parentOffset === $to.parent.content.size;
1749
+ const deflt = $from.depth === 0 ? void 0 : defaultBlockAt($from.node(-1).contentMatchAt($from.indexAfter(-1)));
1750
+ let types = atEnd && deflt ? [
1751
+ {
1752
+ type: deflt,
1753
+ attrs: newAttributes
1754
+ }
1755
+ ] : void 0;
1756
+ let can = canSplit(tr.doc, tr.mapping.map($from.pos), 1, types);
1757
+ if (!types && !can && canSplit(tr.doc, tr.mapping.map($from.pos), 1, deflt ? [{ type: deflt }] : void 0)) {
1758
+ can = true;
1759
+ types = deflt ? [
1760
+ {
1761
+ type: deflt,
1762
+ attrs: newAttributes
1763
+ }
1764
+ ] : void 0;
1765
+ }
1766
+ if (dispatch) {
1767
+ if (can) {
1768
+ if (selection instanceof TextSelection) {
1769
+ tr.deleteSelection();
1770
+ }
1771
+ tr.split(tr.mapping.map($from.pos), 1, types);
1772
+ if (deflt && !atEnd && !$from.parentOffset && $from.parent.type !== deflt) {
1773
+ const first2 = tr.mapping.map($from.before());
1774
+ const $first = tr.doc.resolve(first2);
1775
+ if ($from.node(-1).canReplaceWith($first.index(), $first.index() + 1, deflt)) {
1776
+ tr.setNodeMarkup(tr.mapping.map($from.before()), deflt);
1777
+ }
1778
+ }
1779
+ }
1780
+ if (keepMarks) {
1781
+ ensureMarks(state, editor.extensionManager.splittableMarks);
1782
+ }
1783
+ tr.scrollIntoView();
1784
+ }
1785
+ return can;
1786
+ };
1787
+ var splitListItem = (typeOrName, overrideAttrs = {}) => ({ tr, state, dispatch, editor }) => {
1788
+ var _a;
1789
+ const type = getNodeType(typeOrName, state.schema);
1790
+ const { $from, $to } = state.selection;
1791
+ const node = state.selection.node;
1792
+ if (node && node.isBlock || $from.depth < 2 || !$from.sameParent($to)) {
1793
+ return false;
1794
+ }
1795
+ const grandParent = $from.node(-1);
1796
+ if (grandParent.type !== type) {
1797
+ return false;
1798
+ }
1799
+ const extensionAttributes = editor.extensionManager.attributes;
1800
+ if ($from.parent.content.size === 0 && $from.node(-1).childCount === $from.indexAfter(-1)) {
1801
+ if ($from.depth === 2 || $from.node(-3).type !== type || $from.index(-2) !== $from.node(-2).childCount - 1) {
1802
+ return false;
1803
+ }
1804
+ if (dispatch) {
1805
+ let wrap = Fragment.empty;
1806
+ const depthBefore = $from.index(-1) ? 1 : $from.index(-2) ? 2 : 3;
1807
+ for (let d = $from.depth - depthBefore; d >= $from.depth - 3; d -= 1) {
1808
+ wrap = Fragment.from($from.node(d).copy(wrap));
1809
+ }
1810
+ const depthAfter = (
1811
+ // eslint-disable-next-line no-nested-ternary
1812
+ $from.indexAfter(-1) < $from.node(-2).childCount ? 1 : $from.indexAfter(-2) < $from.node(-3).childCount ? 2 : 3
1813
+ );
1814
+ const newNextTypeAttributes2 = {
1815
+ ...getSplittedAttributes(extensionAttributes, $from.node().type.name, $from.node().attrs),
1816
+ ...overrideAttrs
1817
+ };
1818
+ const nextType2 = ((_a = type.contentMatch.defaultType) == null ? void 0 : _a.createAndFill(newNextTypeAttributes2)) || void 0;
1819
+ wrap = wrap.append(Fragment.from(type.createAndFill(null, nextType2) || void 0));
1820
+ const start = $from.before($from.depth - (depthBefore - 1));
1821
+ tr.replace(start, $from.after(-depthAfter), new Slice(wrap, 4 - depthBefore, 0));
1822
+ let sel = -1;
1823
+ tr.doc.nodesBetween(start, tr.doc.content.size, (n, pos) => {
1824
+ if (sel > -1) {
1825
+ return false;
1826
+ }
1827
+ if (n.isTextblock && n.content.size === 0) {
1828
+ sel = pos + 1;
1829
+ }
1830
+ });
1831
+ if (sel > -1) {
1832
+ tr.setSelection(TextSelection.near(tr.doc.resolve(sel)));
1833
+ }
1834
+ tr.scrollIntoView();
1835
+ }
1836
+ return true;
1837
+ }
1838
+ const nextType = $to.pos === $from.end() ? grandParent.contentMatchAt(0).defaultType : null;
1839
+ const newTypeAttributes = {
1840
+ ...getSplittedAttributes(extensionAttributes, grandParent.type.name, grandParent.attrs),
1841
+ ...overrideAttrs
1842
+ };
1843
+ const newNextTypeAttributes = {
1844
+ ...getSplittedAttributes(extensionAttributes, $from.node().type.name, $from.node().attrs),
1845
+ ...overrideAttrs
1846
+ };
1847
+ tr.delete($from.pos, $to.pos);
1848
+ const types = nextType ? [
1849
+ { type, attrs: newTypeAttributes },
1850
+ { type: nextType, attrs: newNextTypeAttributes }
1851
+ ] : [{ type, attrs: newTypeAttributes }];
1852
+ if (!canSplit(tr.doc, $from.pos, 2)) {
1853
+ return false;
1854
+ }
1855
+ if (dispatch) {
1856
+ const { selection, storedMarks } = state;
1857
+ const { splittableMarks } = editor.extensionManager;
1858
+ const marks = storedMarks || selection.$to.parentOffset && selection.$from.marks();
1859
+ tr.split($from.pos, 2, types).scrollIntoView();
1860
+ if (!marks || !dispatch) {
1861
+ return true;
1862
+ }
1863
+ const filteredMarks = marks.filter((mark) => splittableMarks.includes(mark.type.name));
1864
+ tr.ensureMarks(filteredMarks);
1865
+ }
1866
+ return true;
1867
+ };
1868
+ var joinListBackwards = (tr, listType) => {
1869
+ const list = findParentNode((node) => node.type === listType)(tr.selection);
1870
+ if (!list) {
1871
+ return true;
1872
+ }
1873
+ const before = tr.doc.resolve(Math.max(0, list.pos - 1)).before(list.depth);
1874
+ if (before === void 0) {
1875
+ return true;
1876
+ }
1877
+ const nodeBefore = tr.doc.nodeAt(before);
1878
+ const canJoinBackwards = list.node.type === (nodeBefore == null ? void 0 : nodeBefore.type) && canJoin(tr.doc, list.pos);
1879
+ if (!canJoinBackwards) {
1880
+ return true;
1881
+ }
1882
+ tr.join(list.pos);
1883
+ return true;
1884
+ };
1885
+ var joinListForwards = (tr, listType) => {
1886
+ const list = findParentNode((node) => node.type === listType)(tr.selection);
1887
+ if (!list) {
1888
+ return true;
1889
+ }
1890
+ const after = tr.doc.resolve(list.start).after(list.depth);
1891
+ if (after === void 0) {
1892
+ return true;
1893
+ }
1894
+ const nodeAfter = tr.doc.nodeAt(after);
1895
+ const canJoinForwards = list.node.type === (nodeAfter == null ? void 0 : nodeAfter.type) && canJoin(tr.doc, after);
1896
+ if (!canJoinForwards) {
1897
+ return true;
1898
+ }
1899
+ tr.join(after);
1900
+ return true;
1901
+ };
1902
+ var toggleList = (listTypeOrName, itemTypeOrName, keepMarks, attributes = {}) => ({ editor, tr, state, dispatch, chain, commands, can }) => {
1903
+ const { extensions, splittableMarks } = editor.extensionManager;
1904
+ const listType = getNodeType(listTypeOrName, state.schema);
1905
+ const itemType = getNodeType(itemTypeOrName, state.schema);
1906
+ const { selection, storedMarks } = state;
1907
+ const { $from, $to } = selection;
1908
+ const range = $from.blockRange($to);
1909
+ const marks = storedMarks || selection.$to.parentOffset && selection.$from.marks();
1910
+ if (!range) {
1911
+ return false;
1912
+ }
1913
+ const parentList = findParentNode((node) => isList(node.type.name, extensions))(selection);
1914
+ if (range.depth >= 1 && parentList && range.depth - parentList.depth <= 1) {
1915
+ if (parentList.node.type === listType) {
1916
+ return commands.liftListItem(itemType);
1917
+ }
1918
+ if (isList(parentList.node.type.name, extensions) && listType.validContent(parentList.node.content) && dispatch) {
1919
+ return chain().command(() => {
1920
+ tr.setNodeMarkup(parentList.pos, listType);
1921
+ return true;
1922
+ }).command(() => joinListBackwards(tr, listType)).command(() => joinListForwards(tr, listType)).run();
1923
+ }
1924
+ }
1925
+ if (!keepMarks || !marks || !dispatch) {
1926
+ return chain().command(() => {
1927
+ const canWrapInList = can().wrapInList(listType, attributes);
1928
+ if (canWrapInList) {
1929
+ return true;
1930
+ }
1931
+ return commands.clearNodes();
1932
+ }).wrapInList(listType, attributes).command(() => joinListBackwards(tr, listType)).command(() => joinListForwards(tr, listType)).run();
1933
+ }
1934
+ return chain().command(() => {
1935
+ const canWrapInList = can().wrapInList(listType, attributes);
1936
+ const filteredMarks = marks.filter((mark) => splittableMarks.includes(mark.type.name));
1937
+ tr.ensureMarks(filteredMarks);
1938
+ if (canWrapInList) {
1939
+ return true;
1940
+ }
1941
+ return commands.clearNodes();
1942
+ }).wrapInList(listType, attributes).command(() => joinListBackwards(tr, listType)).command(() => joinListForwards(tr, listType)).run();
1943
+ };
1944
+ var toggleMark = (typeOrName, attributes = {}, options = {}) => ({ state, commands }) => {
1945
+ const { extendEmptyMarkRange = false } = options;
1946
+ const type = getMarkType(typeOrName, state.schema);
1947
+ const isActive2 = isMarkActive(state, type, attributes);
1948
+ if (isActive2) {
1949
+ return commands.unsetMark(type, { extendEmptyMarkRange });
1950
+ }
1951
+ return commands.setMark(type, attributes);
1952
+ };
1953
+ var toggleNode = (typeOrName, toggleTypeOrName, attributes = {}) => ({ state, commands }) => {
1954
+ const type = getNodeType(typeOrName, state.schema);
1955
+ const toggleType = getNodeType(toggleTypeOrName, state.schema);
1956
+ const isActive2 = isNodeActive(state, type, attributes);
1957
+ let attributesToCopy;
1958
+ if (state.selection.$anchor.sameParent(state.selection.$head)) {
1959
+ attributesToCopy = state.selection.$anchor.parent.attrs;
1960
+ }
1961
+ if (isActive2) {
1962
+ return commands.setNode(toggleType, attributesToCopy);
1963
+ }
1964
+ return commands.setNode(type, { ...attributesToCopy, ...attributes });
1965
+ };
1966
+ var toggleWrap = (typeOrName, attributes = {}) => ({ state, commands }) => {
1967
+ const type = getNodeType(typeOrName, state.schema);
1968
+ const isActive2 = isNodeActive(state, type, attributes);
1969
+ if (isActive2) {
1970
+ return commands.lift(type);
1971
+ }
1972
+ return commands.wrapIn(type, attributes);
1973
+ };
1974
+ var undoInputRule = () => ({ state, dispatch }) => {
1975
+ const plugins = state.plugins;
1976
+ for (let i = 0; i < plugins.length; i += 1) {
1977
+ const plugin = plugins[i];
1978
+ let undoable;
1979
+ if (plugin.spec.isInputRules && (undoable = plugin.getState(state))) {
1980
+ if (dispatch) {
1981
+ const tr = state.tr;
1982
+ const toUndo = undoable.transform;
1983
+ for (let j = toUndo.steps.length - 1; j >= 0; j -= 1) {
1984
+ tr.step(toUndo.steps[j].invert(toUndo.docs[j]));
1985
+ }
1986
+ if (undoable.text) {
1987
+ const marks = tr.doc.resolve(undoable.from).marks();
1988
+ tr.replaceWith(undoable.from, undoable.to, state.schema.text(undoable.text, marks));
1989
+ } else {
1990
+ tr.delete(undoable.from, undoable.to);
1991
+ }
1992
+ }
1993
+ return true;
1994
+ }
1995
+ }
1996
+ return false;
1997
+ };
1998
+ var unsetAllMarks = () => ({ tr, dispatch }) => {
1999
+ const { selection } = tr;
2000
+ const { empty, ranges } = selection;
2001
+ if (empty) {
2002
+ return true;
2003
+ }
2004
+ if (dispatch) {
2005
+ ranges.forEach((range) => {
2006
+ tr.removeMark(range.$from.pos, range.$to.pos);
2007
+ });
2008
+ }
2009
+ return true;
2010
+ };
2011
+ var unsetMark = (typeOrName, options = {}) => ({ tr, state, dispatch }) => {
2012
+ var _a;
2013
+ const { extendEmptyMarkRange = false } = options;
2014
+ const { selection } = tr;
2015
+ const type = getMarkType(typeOrName, state.schema);
2016
+ const { $from, empty, ranges } = selection;
2017
+ if (!dispatch) {
2018
+ return true;
2019
+ }
2020
+ if (empty && extendEmptyMarkRange) {
2021
+ let { from, to } = selection;
2022
+ const attrs = (_a = $from.marks().find((mark) => mark.type === type)) == null ? void 0 : _a.attrs;
2023
+ const range = getMarkRange($from, type, attrs);
2024
+ if (range) {
2025
+ from = range.from;
2026
+ to = range.to;
2027
+ }
2028
+ tr.removeMark(from, to, type);
2029
+ } else {
2030
+ ranges.forEach((range) => {
2031
+ tr.removeMark(range.$from.pos, range.$to.pos, type);
2032
+ });
2033
+ }
2034
+ tr.removeStoredMark(type);
2035
+ return true;
2036
+ };
2037
+ var unsetTextDirection = (position) => ({ tr, state, dispatch }) => {
2038
+ const { selection } = state;
2039
+ let from;
2040
+ let to;
2041
+ if (typeof position === "number") {
2042
+ from = position;
2043
+ to = position;
2044
+ } else if (position && "from" in position && "to" in position) {
2045
+ from = position.from;
2046
+ to = position.to;
2047
+ } else {
2048
+ from = selection.from;
2049
+ to = selection.to;
2050
+ }
2051
+ if (dispatch) {
2052
+ tr.doc.nodesBetween(from, to, (node, pos) => {
2053
+ if (node.isText) {
2054
+ return;
2055
+ }
2056
+ const newAttrs = { ...node.attrs };
2057
+ delete newAttrs.dir;
2058
+ tr.setNodeMarkup(pos, void 0, newAttrs);
2059
+ });
2060
+ }
2061
+ return true;
2062
+ };
2063
+ var updateAttributes = (typeOrName, attributes = {}) => ({ tr, state, dispatch }) => {
2064
+ let nodeType = null;
2065
+ let markType = null;
2066
+ const schemaType = getSchemaTypeNameByName(
2067
+ typeof typeOrName === "string" ? typeOrName : typeOrName.name,
2068
+ state.schema
2069
+ );
2070
+ if (!schemaType) {
2071
+ return false;
2072
+ }
2073
+ if (schemaType === "node") {
2074
+ nodeType = getNodeType(typeOrName, state.schema);
2075
+ }
2076
+ if (schemaType === "mark") {
2077
+ markType = getMarkType(typeOrName, state.schema);
2078
+ }
2079
+ let canUpdate = false;
2080
+ tr.selection.ranges.forEach((range) => {
2081
+ const from = range.$from.pos;
2082
+ const to = range.$to.pos;
2083
+ let lastPos;
2084
+ let lastNode;
2085
+ let trimmedFrom;
2086
+ let trimmedTo;
2087
+ if (tr.selection.empty) {
2088
+ state.doc.nodesBetween(from, to, (node, pos) => {
2089
+ if (nodeType && nodeType === node.type) {
2090
+ canUpdate = true;
2091
+ trimmedFrom = Math.max(pos, from);
2092
+ trimmedTo = Math.min(pos + node.nodeSize, to);
2093
+ lastPos = pos;
2094
+ lastNode = node;
2095
+ }
2096
+ });
2097
+ } else {
2098
+ state.doc.nodesBetween(from, to, (node, pos) => {
2099
+ if (pos < from && nodeType && nodeType === node.type) {
2100
+ canUpdate = true;
2101
+ trimmedFrom = Math.max(pos, from);
2102
+ trimmedTo = Math.min(pos + node.nodeSize, to);
2103
+ lastPos = pos;
2104
+ lastNode = node;
2105
+ }
2106
+ if (pos >= from && pos <= to) {
2107
+ if (nodeType && nodeType === node.type) {
2108
+ canUpdate = true;
2109
+ if (dispatch) {
2110
+ tr.setNodeMarkup(pos, void 0, {
2111
+ ...node.attrs,
2112
+ ...attributes
2113
+ });
2114
+ }
2115
+ }
2116
+ if (markType && node.marks.length) {
2117
+ node.marks.forEach((mark) => {
2118
+ if (markType === mark.type) {
2119
+ canUpdate = true;
2120
+ if (dispatch) {
2121
+ const trimmedFrom2 = Math.max(pos, from);
2122
+ const trimmedTo2 = Math.min(pos + node.nodeSize, to);
2123
+ tr.addMark(
2124
+ trimmedFrom2,
2125
+ trimmedTo2,
2126
+ markType.create({
2127
+ ...mark.attrs,
2128
+ ...attributes
2129
+ })
2130
+ );
2131
+ }
2132
+ }
2133
+ });
2134
+ }
2135
+ }
2136
+ });
2137
+ }
2138
+ if (lastNode) {
2139
+ if (lastPos !== void 0 && dispatch) {
2140
+ tr.setNodeMarkup(lastPos, void 0, {
2141
+ ...lastNode.attrs,
2142
+ ...attributes
2143
+ });
2144
+ }
2145
+ if (markType && lastNode.marks.length) {
2146
+ lastNode.marks.forEach((mark) => {
2147
+ if (markType === mark.type && dispatch) {
2148
+ tr.addMark(
2149
+ trimmedFrom,
2150
+ trimmedTo,
2151
+ markType.create({
2152
+ ...mark.attrs,
2153
+ ...attributes
2154
+ })
2155
+ );
2156
+ }
2157
+ });
2158
+ }
2159
+ }
2160
+ });
2161
+ return canUpdate;
2162
+ };
2163
+ var wrapIn = (typeOrName, attributes = {}) => ({ state, dispatch }) => {
2164
+ const type = getNodeType(typeOrName, state.schema);
2165
+ return wrapIn$1(type, attributes)(state, dispatch);
2166
+ };
2167
+ var wrapInList = (typeOrName, attributes = {}) => ({ state, dispatch }) => {
2168
+ const type = getNodeType(typeOrName, state.schema);
2169
+ return wrapInList$1(type, attributes)(state, dispatch);
2170
+ };
2171
+ var InputRule = class {
2172
+ constructor(config) {
2173
+ var _a;
2174
+ this.find = config.find;
2175
+ this.handler = config.handler;
2176
+ this.undoable = (_a = config.undoable) != null ? _a : true;
2177
+ }
2178
+ };
2179
+ function getType(value) {
2180
+ return Object.prototype.toString.call(value).slice(8, -1);
2181
+ }
2182
+ function isPlainObject(value) {
2183
+ if (getType(value) !== "Object") {
2184
+ return false;
2185
+ }
2186
+ return value.constructor === Object && Object.getPrototypeOf(value) === Object.prototype;
2187
+ }
2188
+ function mergeDeep(target, source) {
2189
+ const output = { ...target };
2190
+ if (isPlainObject(target) && isPlainObject(source)) {
2191
+ Object.keys(source).forEach((key) => {
2192
+ if (isPlainObject(source[key]) && isPlainObject(target[key])) {
2193
+ output[key] = mergeDeep(target[key], source[key]);
2194
+ } else {
2195
+ output[key] = source[key];
2196
+ }
2197
+ });
2198
+ }
2199
+ return output;
2200
+ }
2201
+ var Extendable = class {
2202
+ constructor(config = {}) {
2203
+ this.type = "extendable";
2204
+ this.parent = null;
2205
+ this.child = null;
2206
+ this.name = "";
2207
+ this.config = {
2208
+ name: this.name
2209
+ };
2210
+ this.config = {
2211
+ ...this.config,
2212
+ ...config
2213
+ };
2214
+ this.name = this.config.name;
2215
+ }
2216
+ get options() {
2217
+ return {
2218
+ ...callOrReturn(
2219
+ getExtensionField(this, "addOptions", {
2220
+ name: this.name
2221
+ })
2222
+ ) || {}
2223
+ };
2224
+ }
2225
+ get storage() {
2226
+ return {
2227
+ ...callOrReturn(
2228
+ getExtensionField(this, "addStorage", {
2229
+ name: this.name,
2230
+ options: this.options
2231
+ })
2232
+ ) || {}
2233
+ };
2234
+ }
2235
+ configure(options = {}) {
2236
+ const extension = this.extend({
2237
+ ...this.config,
2238
+ addOptions: () => {
2239
+ return mergeDeep(this.options, options);
2240
+ }
2241
+ });
2242
+ extension.name = this.name;
2243
+ extension.parent = this.parent;
2244
+ return extension;
2245
+ }
2246
+ extend(extendedConfig = {}) {
2247
+ const extension = new this.constructor({ ...this.config, ...extendedConfig });
2248
+ extension.parent = this;
2249
+ this.child = extension;
2250
+ extension.name = "name" in extendedConfig ? extendedConfig.name : extension.parent.name;
2251
+ return extension;
2252
+ }
2253
+ };
2254
+ var Mark = class _Mark extends Extendable {
2255
+ constructor() {
2256
+ super(...arguments);
2257
+ this.type = "mark";
2258
+ }
2259
+ /**
2260
+ * Create a new Mark instance
2261
+ * @param config - Mark configuration object or a function that returns a configuration object
2262
+ */
2263
+ static create(config = {}) {
2264
+ const resolvedConfig = typeof config === "function" ? config() : config;
2265
+ return new _Mark(resolvedConfig);
2266
+ }
2267
+ static handleExit({ editor, mark }) {
2268
+ const { tr } = editor.state;
2269
+ const currentPos = editor.state.selection.$from;
2270
+ const isAtEnd = currentPos.pos === currentPos.end();
2271
+ if (isAtEnd) {
2272
+ const currentMarks = currentPos.marks();
2273
+ const isInMark = !!currentMarks.find((m) => (m == null ? void 0 : m.type.name) === mark.name);
2274
+ if (!isInMark) {
2275
+ return false;
2276
+ }
2277
+ const removeMark = currentMarks.find((m) => (m == null ? void 0 : m.type.name) === mark.name);
2278
+ if (removeMark) {
2279
+ tr.removeStoredMark(removeMark);
2280
+ }
2281
+ tr.insertText(" ", currentPos.pos);
2282
+ editor.view.dispatch(tr);
2283
+ return true;
2284
+ }
2285
+ return false;
2286
+ }
2287
+ configure(options) {
2288
+ return super.configure(options);
2289
+ }
2290
+ extend(extendedConfig) {
2291
+ const resolvedConfig = typeof extendedConfig === "function" ? extendedConfig() : extendedConfig;
2292
+ return super.extend(resolvedConfig);
2293
+ }
2294
+ };
2295
+ var extensions_exports = {};
2296
+ __export(extensions_exports, {
2297
+ ClipboardTextSerializer: () => ClipboardTextSerializer,
2298
+ Commands: () => Commands,
2299
+ Delete: () => Delete,
2300
+ Drop: () => Drop,
2301
+ Editable: () => Editable,
2302
+ FocusEvents: () => FocusEvents,
2303
+ Keymap: () => Keymap,
2304
+ Paste: () => Paste,
2305
+ Tabindex: () => Tabindex,
2306
+ TextDirection: () => TextDirection,
2307
+ focusEventsPluginKey: () => focusEventsPluginKey
2308
+ });
2309
+ var Extension = class _Extension extends Extendable {
2310
+ constructor() {
2311
+ super(...arguments);
2312
+ this.type = "extension";
2313
+ }
2314
+ /**
2315
+ * Create a new Extension instance
2316
+ * @param config - Extension configuration object or a function that returns a configuration object
2317
+ */
2318
+ static create(config = {}) {
2319
+ const resolvedConfig = typeof config === "function" ? config() : config;
2320
+ return new _Extension(resolvedConfig);
2321
+ }
2322
+ configure(options) {
2323
+ return super.configure(options);
2324
+ }
2325
+ extend(extendedConfig) {
2326
+ const resolvedConfig = typeof extendedConfig === "function" ? extendedConfig() : extendedConfig;
2327
+ return super.extend(resolvedConfig);
2328
+ }
2329
+ };
2330
+ var ClipboardTextSerializer = Extension.create({
2331
+ name: "clipboardTextSerializer",
2332
+ addOptions() {
2333
+ return {
2334
+ blockSeparator: void 0
2335
+ };
2336
+ },
2337
+ addProseMirrorPlugins() {
2338
+ return [
2339
+ new Plugin({
2340
+ key: new PluginKey("clipboardTextSerializer"),
2341
+ props: {
2342
+ clipboardTextSerializer: () => {
2343
+ const { editor } = this;
2344
+ const { state, schema } = editor;
2345
+ const { doc, selection } = state;
2346
+ const { ranges } = selection;
2347
+ const from = Math.min(...ranges.map((range2) => range2.$from.pos));
2348
+ const to = Math.max(...ranges.map((range2) => range2.$to.pos));
2349
+ const textSerializers = getTextSerializersFromSchema(schema);
2350
+ const range = { from, to };
2351
+ return getTextBetween(doc, range, {
2352
+ ...this.options.blockSeparator !== void 0 ? { blockSeparator: this.options.blockSeparator } : {},
2353
+ textSerializers
2354
+ });
2355
+ }
2356
+ }
2357
+ })
2358
+ ];
2359
+ }
2360
+ });
2361
+ var Commands = Extension.create({
2362
+ name: "commands",
2363
+ addCommands() {
2364
+ return {
2365
+ ...commands_exports
2366
+ };
2367
+ }
2368
+ });
2369
+ var Delete = Extension.create({
2370
+ name: "delete",
2371
+ onUpdate({ transaction, appendedTransactions }) {
2372
+ var _a, _b, _c;
2373
+ const callback = () => {
2374
+ var _a2, _b2, _c2, _d;
2375
+ if ((_d = (_c2 = (_b2 = (_a2 = this.editor.options.coreExtensionOptions) == null ? void 0 : _a2.delete) == null ? void 0 : _b2.filterTransaction) == null ? void 0 : _c2.call(_b2, transaction)) != null ? _d : transaction.getMeta("y-sync$")) {
2376
+ return;
2377
+ }
2378
+ const nextTransaction = combineTransactionSteps(transaction.before, [transaction, ...appendedTransactions]);
2379
+ const changes = getChangedRanges(nextTransaction);
2380
+ changes.forEach((change) => {
2381
+ if (nextTransaction.mapping.mapResult(change.oldRange.from).deletedAfter && nextTransaction.mapping.mapResult(change.oldRange.to).deletedBefore) {
2382
+ nextTransaction.before.nodesBetween(change.oldRange.from, change.oldRange.to, (node, from) => {
2383
+ const to = from + node.nodeSize - 2;
2384
+ const isFullyWithinRange = change.oldRange.from <= from && to <= change.oldRange.to;
2385
+ this.editor.emit("delete", {
2386
+ type: "node",
2387
+ node,
2388
+ from,
2389
+ to,
2390
+ newFrom: nextTransaction.mapping.map(from),
2391
+ newTo: nextTransaction.mapping.map(to),
2392
+ deletedRange: change.oldRange,
2393
+ newRange: change.newRange,
2394
+ partial: !isFullyWithinRange,
2395
+ editor: this.editor,
2396
+ transaction,
2397
+ combinedTransform: nextTransaction
2398
+ });
2399
+ });
2400
+ }
2401
+ });
2402
+ const mapping = nextTransaction.mapping;
2403
+ nextTransaction.steps.forEach((step, index) => {
2404
+ var _a3, _b3;
2405
+ if (step instanceof RemoveMarkStep) {
2406
+ const newStart = mapping.slice(index).map(step.from, -1);
2407
+ const newEnd = mapping.slice(index).map(step.to);
2408
+ const oldStart = mapping.invert().map(newStart, -1);
2409
+ const oldEnd = mapping.invert().map(newEnd);
2410
+ const foundBeforeMark = (_a3 = nextTransaction.doc.nodeAt(newStart - 1)) == null ? void 0 : _a3.marks.some((mark) => mark.eq(step.mark));
2411
+ const foundAfterMark = (_b3 = nextTransaction.doc.nodeAt(newEnd)) == null ? void 0 : _b3.marks.some((mark) => mark.eq(step.mark));
2412
+ this.editor.emit("delete", {
2413
+ type: "mark",
2414
+ mark: step.mark,
2415
+ from: step.from,
2416
+ to: step.to,
2417
+ deletedRange: {
2418
+ from: oldStart,
2419
+ to: oldEnd
2420
+ },
2421
+ newRange: {
2422
+ from: newStart,
2423
+ to: newEnd
2424
+ },
2425
+ partial: Boolean(foundAfterMark || foundBeforeMark),
2426
+ editor: this.editor,
2427
+ transaction,
2428
+ combinedTransform: nextTransaction
2429
+ });
2430
+ }
2431
+ });
2432
+ };
2433
+ if ((_c = (_b = (_a = this.editor.options.coreExtensionOptions) == null ? void 0 : _a.delete) == null ? void 0 : _b.async) != null ? _c : true) {
2434
+ setTimeout(callback, 0);
2435
+ } else {
2436
+ callback();
2437
+ }
2438
+ }
2439
+ });
2440
+ var Drop = Extension.create({
2441
+ name: "drop",
2442
+ addProseMirrorPlugins() {
2443
+ return [
2444
+ new Plugin({
2445
+ key: new PluginKey("tiptapDrop"),
2446
+ props: {
2447
+ handleDrop: (_, e, slice, moved) => {
2448
+ this.editor.emit("drop", {
2449
+ editor: this.editor,
2450
+ event: e,
2451
+ slice,
2452
+ moved
2453
+ });
2454
+ }
2455
+ }
2456
+ })
2457
+ ];
2458
+ }
2459
+ });
2460
+ var Editable = Extension.create({
2461
+ name: "editable",
2462
+ addProseMirrorPlugins() {
2463
+ return [
2464
+ new Plugin({
2465
+ key: new PluginKey("editable"),
2466
+ props: {
2467
+ editable: () => this.editor.options.editable
2468
+ }
2469
+ })
2470
+ ];
2471
+ }
2472
+ });
2473
+ var focusEventsPluginKey = new PluginKey("focusEvents");
2474
+ var FocusEvents = Extension.create({
2475
+ name: "focusEvents",
2476
+ addProseMirrorPlugins() {
2477
+ const { editor } = this;
2478
+ return [
2479
+ new Plugin({
2480
+ key: focusEventsPluginKey,
2481
+ props: {
2482
+ handleDOMEvents: {
2483
+ focus: (view, event) => {
2484
+ editor.isFocused = true;
2485
+ const transaction = editor.state.tr.setMeta("focus", { event }).setMeta("addToHistory", false);
2486
+ view.dispatch(transaction);
2487
+ return false;
2488
+ },
2489
+ blur: (view, event) => {
2490
+ editor.isFocused = false;
2491
+ const transaction = editor.state.tr.setMeta("blur", { event }).setMeta("addToHistory", false);
2492
+ view.dispatch(transaction);
2493
+ return false;
2494
+ }
2495
+ }
2496
+ }
2497
+ })
2498
+ ];
2499
+ }
2500
+ });
2501
+ var Keymap = Extension.create({
2502
+ name: "keymap",
2503
+ addKeyboardShortcuts() {
2504
+ const handleBackspace = () => this.editor.commands.first(({ commands }) => [
2505
+ () => commands.undoInputRule(),
2506
+ // maybe convert first text block node to default node
2507
+ () => commands.command(({ tr }) => {
2508
+ const { selection, doc } = tr;
2509
+ const { empty, $anchor } = selection;
2510
+ const { pos, parent } = $anchor;
2511
+ const $parentPos = $anchor.parent.isTextblock && pos > 0 ? tr.doc.resolve(pos - 1) : $anchor;
2512
+ const parentIsIsolating = $parentPos.parent.type.spec.isolating;
2513
+ const parentPos = $anchor.pos - $anchor.parentOffset;
2514
+ const isAtStart = parentIsIsolating && $parentPos.parent.childCount === 1 ? parentPos === $anchor.pos : Selection.atStart(doc).from === pos;
2515
+ if (!empty || !parent.type.isTextblock || parent.textContent.length || !isAtStart || isAtStart && $anchor.parent.type.name === "paragraph") {
2516
+ return false;
2517
+ }
2518
+ return commands.clearNodes();
2519
+ }),
2520
+ () => commands.deleteSelection(),
2521
+ () => commands.joinBackward(),
2522
+ () => commands.selectNodeBackward()
2523
+ ]);
2524
+ const handleDelete = () => this.editor.commands.first(({ commands }) => [
2525
+ () => commands.deleteSelection(),
2526
+ () => commands.deleteCurrentNode(),
2527
+ () => commands.joinForward(),
2528
+ () => commands.selectNodeForward()
2529
+ ]);
2530
+ const handleEnter = () => this.editor.commands.first(({ commands }) => [
2531
+ () => commands.newlineInCode(),
2532
+ () => commands.createParagraphNear(),
2533
+ () => commands.liftEmptyBlock(),
2534
+ () => commands.splitBlock()
2535
+ ]);
2536
+ const baseKeymap = {
2537
+ Enter: handleEnter,
2538
+ "Mod-Enter": () => this.editor.commands.exitCode(),
2539
+ Backspace: handleBackspace,
2540
+ "Mod-Backspace": handleBackspace,
2541
+ "Shift-Backspace": handleBackspace,
2542
+ Delete: handleDelete,
2543
+ "Mod-Delete": handleDelete,
2544
+ "Mod-a": () => this.editor.commands.selectAll()
2545
+ };
2546
+ const pcKeymap = {
2547
+ ...baseKeymap
2548
+ };
2549
+ const macKeymap = {
2550
+ ...baseKeymap,
2551
+ "Ctrl-h": handleBackspace,
2552
+ "Alt-Backspace": handleBackspace,
2553
+ "Ctrl-d": handleDelete,
2554
+ "Ctrl-Alt-Backspace": handleDelete,
2555
+ "Alt-Delete": handleDelete,
2556
+ "Alt-d": handleDelete,
2557
+ "Ctrl-a": () => this.editor.commands.selectTextblockStart(),
2558
+ "Ctrl-e": () => this.editor.commands.selectTextblockEnd()
2559
+ };
2560
+ if (isiOS() || isMacOS()) {
2561
+ return macKeymap;
2562
+ }
2563
+ return pcKeymap;
2564
+ },
2565
+ addProseMirrorPlugins() {
2566
+ return [
2567
+ // With this plugin we check if the whole document was selected and deleted.
2568
+ // In this case we will additionally call `clearNodes()` to convert e.g. a heading
2569
+ // to a paragraph if necessary.
2570
+ // This is an alternative to ProseMirror's `AllSelection`, which doesn’t work well
2571
+ // with many other commands.
2572
+ new Plugin({
2573
+ key: new PluginKey("clearDocument"),
2574
+ appendTransaction: (transactions, oldState, newState) => {
2575
+ if (transactions.some((tr2) => tr2.getMeta("composition"))) {
2576
+ return;
2577
+ }
2578
+ const docChanges = transactions.some((transaction) => transaction.docChanged) && !oldState.doc.eq(newState.doc);
2579
+ const ignoreTr = transactions.some((transaction) => transaction.getMeta("preventClearDocument"));
2580
+ if (!docChanges || ignoreTr) {
2581
+ return;
2582
+ }
2583
+ const { empty, from, to } = oldState.selection;
2584
+ const allFrom = Selection.atStart(oldState.doc).from;
2585
+ const allEnd = Selection.atEnd(oldState.doc).to;
2586
+ const allWasSelected = from === allFrom && to === allEnd;
2587
+ if (empty || !allWasSelected) {
2588
+ return;
2589
+ }
2590
+ const isEmpty = isNodeEmpty(newState.doc);
2591
+ if (!isEmpty) {
2592
+ return;
2593
+ }
2594
+ const tr = newState.tr;
2595
+ const state = createChainableState({
2596
+ state: newState,
2597
+ transaction: tr
2598
+ });
2599
+ const { commands } = new CommandManager({
2600
+ editor: this.editor,
2601
+ state
2602
+ });
2603
+ commands.clearNodes();
2604
+ if (!tr.steps.length) {
2605
+ return;
2606
+ }
2607
+ return tr;
2608
+ }
2609
+ })
2610
+ ];
2611
+ }
2612
+ });
2613
+ var Paste = Extension.create({
2614
+ name: "paste",
2615
+ addProseMirrorPlugins() {
2616
+ return [
2617
+ new Plugin({
2618
+ key: new PluginKey("tiptapPaste"),
2619
+ props: {
2620
+ handlePaste: (_view, e, slice) => {
2621
+ this.editor.emit("paste", {
2622
+ editor: this.editor,
2623
+ event: e,
2624
+ slice
2625
+ });
2626
+ }
2627
+ }
2628
+ })
2629
+ ];
2630
+ }
2631
+ });
2632
+ var Tabindex = Extension.create({
2633
+ name: "tabindex",
2634
+ addProseMirrorPlugins() {
2635
+ return [
2636
+ new Plugin({
2637
+ key: new PluginKey("tabindex"),
2638
+ props: {
2639
+ attributes: () => this.editor.isEditable ? { tabindex: "0" } : {}
2640
+ }
2641
+ })
2642
+ ];
2643
+ }
2644
+ });
2645
+ var TextDirection = Extension.create({
2646
+ name: "textDirection",
2647
+ addOptions() {
2648
+ return {
2649
+ direction: void 0
2650
+ };
2651
+ },
2652
+ addGlobalAttributes() {
2653
+ if (!this.options.direction) {
2654
+ return [];
2655
+ }
2656
+ const { nodeExtensions } = splitExtensions(this.extensions);
2657
+ return [
2658
+ {
2659
+ types: nodeExtensions.filter((extension) => extension.name !== "text").map((extension) => extension.name),
2660
+ attributes: {
2661
+ dir: {
2662
+ default: this.options.direction,
2663
+ parseHTML: (element) => {
2664
+ const dir = element.getAttribute("dir");
2665
+ if (dir && (dir === "ltr" || dir === "rtl" || dir === "auto")) {
2666
+ return dir;
2667
+ }
2668
+ return this.options.direction;
2669
+ },
2670
+ renderHTML: (attributes) => {
2671
+ if (!attributes.dir) {
2672
+ return {};
2673
+ }
2674
+ return {
2675
+ dir: attributes.dir
2676
+ };
2677
+ }
2678
+ }
2679
+ }
2680
+ }
2681
+ ];
2682
+ },
2683
+ addProseMirrorPlugins() {
2684
+ return [
2685
+ new Plugin({
2686
+ key: new PluginKey("textDirection"),
2687
+ props: {
2688
+ attributes: () => {
2689
+ const direction = this.options.direction;
2690
+ if (!direction) {
2691
+ return {};
2692
+ }
2693
+ return {
2694
+ dir: direction
2695
+ };
2696
+ }
2697
+ }
2698
+ })
2699
+ ];
2700
+ }
2701
+ });
2702
+ function textblockTypeInputRule(config) {
2703
+ return new InputRule({
2704
+ find: config.find,
2705
+ handler: ({ state, range, match }) => {
2706
+ const $start = state.doc.resolve(range.from);
2707
+ const attributes = callOrReturn(config.getAttributes, void 0, match) || {};
2708
+ if (!$start.node(-1).canReplaceWith($start.index(-1), $start.indexAfter(-1), config.type)) {
2709
+ return null;
2710
+ }
2711
+ state.tr.delete(range.from, range.to).setBlockType(range.from, range.from, config.type, attributes);
2712
+ },
2713
+ undoable: config.undoable
2714
+ });
2715
+ }
2716
+ var markdown_exports = {};
2717
+ __export(markdown_exports, {
2718
+ createAtomBlockMarkdownSpec: () => createAtomBlockMarkdownSpec,
2719
+ createBlockMarkdownSpec: () => createBlockMarkdownSpec,
2720
+ createInlineMarkdownSpec: () => createInlineMarkdownSpec,
2721
+ parseAttributes: () => parseAttributes,
2722
+ parseIndentedBlocks: () => parseIndentedBlocks,
2723
+ renderNestedMarkdownContent: () => renderNestedMarkdownContent,
2724
+ serializeAttributes: () => serializeAttributes
2725
+ });
2726
+ function parseAttributes(attrString) {
2727
+ if (!(attrString == null ? void 0 : attrString.trim())) {
2728
+ return {};
2729
+ }
2730
+ const attributes = {};
2731
+ const quotedStrings = [];
2732
+ const tempString = attrString.replace(/["']([^"']*)["']/g, (match) => {
2733
+ quotedStrings.push(match);
2734
+ return `__QUOTED_${quotedStrings.length - 1}__`;
2735
+ });
2736
+ const classMatches = tempString.match(/(?:^|\s)\.([a-zA-Z][\w-]*)/g);
2737
+ if (classMatches) {
2738
+ const classes = classMatches.map((match) => match.trim().slice(1));
2739
+ attributes.class = classes.join(" ");
2740
+ }
2741
+ const idMatch = tempString.match(/(?:^|\s)#([a-zA-Z][\w-]*)/);
2742
+ if (idMatch) {
2743
+ attributes.id = idMatch[1];
2744
+ }
2745
+ const kvRegex = /([a-zA-Z][\w-]*)\s*=\s*(__QUOTED_\d+__)/g;
2746
+ const kvMatches = Array.from(tempString.matchAll(kvRegex));
2747
+ kvMatches.forEach(([, key, quotedRef]) => {
2748
+ var _a;
2749
+ const quotedIndex = parseInt(((_a = quotedRef.match(/__QUOTED_(\d+)__/)) == null ? void 0 : _a[1]) || "0", 10);
2750
+ const quotedValue = quotedStrings[quotedIndex];
2751
+ if (quotedValue) {
2752
+ attributes[key] = quotedValue.slice(1, -1);
2753
+ }
2754
+ });
2755
+ const cleanString = tempString.replace(/(?:^|\s)\.([a-zA-Z][\w-]*)/g, "").replace(/(?:^|\s)#([a-zA-Z][\w-]*)/g, "").replace(/([a-zA-Z][\w-]*)\s*=\s*__QUOTED_\d+__/g, "").trim();
2756
+ if (cleanString) {
2757
+ const booleanAttrs = cleanString.split(/\s+/).filter(Boolean);
2758
+ booleanAttrs.forEach((attr) => {
2759
+ if (attr.match(/^[a-zA-Z][\w-]*$/)) {
2760
+ attributes[attr] = true;
2761
+ }
2762
+ });
2763
+ }
2764
+ return attributes;
2765
+ }
2766
+ function serializeAttributes(attributes) {
2767
+ if (!attributes || Object.keys(attributes).length === 0) {
2768
+ return "";
2769
+ }
2770
+ const parts = [];
2771
+ if (attributes.class) {
2772
+ const classes = String(attributes.class).split(/\s+/).filter(Boolean);
2773
+ classes.forEach((cls) => parts.push(`.${cls}`));
2774
+ }
2775
+ if (attributes.id) {
2776
+ parts.push(`#${attributes.id}`);
2777
+ }
2778
+ Object.entries(attributes).forEach(([key, value]) => {
2779
+ if (key === "class" || key === "id") {
2780
+ return;
2781
+ }
2782
+ if (value === true) {
2783
+ parts.push(key);
2784
+ } else if (value !== false && value != null) {
2785
+ parts.push(`${key}="${String(value)}"`);
2786
+ }
2787
+ });
2788
+ return parts.join(" ");
2789
+ }
2790
+ function createAtomBlockMarkdownSpec(options) {
2791
+ const {
2792
+ nodeName,
2793
+ name: markdownName,
2794
+ parseAttributes: parseAttributes2 = parseAttributes,
2795
+ serializeAttributes: serializeAttributes2 = serializeAttributes,
2796
+ defaultAttributes = {},
2797
+ requiredAttributes = [],
2798
+ allowedAttributes
2799
+ } = options;
2800
+ const blockName = markdownName || nodeName;
2801
+ const filterAttributes = (attrs) => {
2802
+ if (!allowedAttributes) {
2803
+ return attrs;
2804
+ }
2805
+ const filtered = {};
2806
+ allowedAttributes.forEach((key) => {
2807
+ if (key in attrs) {
2808
+ filtered[key] = attrs[key];
2809
+ }
2810
+ });
2811
+ return filtered;
2812
+ };
2813
+ return {
2814
+ parseMarkdown: (token, h2) => {
2815
+ const attrs = { ...defaultAttributes, ...token.attributes };
2816
+ return h2.createNode(nodeName, attrs, []);
2817
+ },
2818
+ markdownTokenizer: {
2819
+ name: nodeName,
2820
+ level: "block",
2821
+ start(src) {
2822
+ var _a;
2823
+ const regex = new RegExp(`^:::${blockName}(?:\\s|$)`, "m");
2824
+ const index = (_a = src.match(regex)) == null ? void 0 : _a.index;
2825
+ return index !== void 0 ? index : -1;
2826
+ },
2827
+ tokenize(src, _tokens, _lexer) {
2828
+ const regex = new RegExp(`^:::${blockName}(?:\\s+\\{([^}]*)\\})?\\s*:::(?:\\n|$)`);
2829
+ const match = src.match(regex);
2830
+ if (!match) {
2831
+ return void 0;
2832
+ }
2833
+ const attrString = match[1] || "";
2834
+ const attributes = parseAttributes2(attrString);
2835
+ const missingRequired = requiredAttributes.find((required) => !(required in attributes));
2836
+ if (missingRequired) {
2837
+ return void 0;
2838
+ }
2839
+ return {
2840
+ type: nodeName,
2841
+ raw: match[0],
2842
+ attributes
2843
+ };
2844
+ }
2845
+ },
2846
+ renderMarkdown: (node) => {
2847
+ const filteredAttrs = filterAttributes(node.attrs || {});
2848
+ const attrs = serializeAttributes2(filteredAttrs);
2849
+ const attrString = attrs ? ` {${attrs}}` : "";
2850
+ return `:::${blockName}${attrString} :::`;
2851
+ }
2852
+ };
2853
+ }
2854
+ function createBlockMarkdownSpec(options) {
2855
+ const {
2856
+ nodeName,
2857
+ name: markdownName,
2858
+ getContent,
2859
+ parseAttributes: parseAttributes2 = parseAttributes,
2860
+ serializeAttributes: serializeAttributes2 = serializeAttributes,
2861
+ defaultAttributes = {},
2862
+ content = "block",
2863
+ allowedAttributes
2864
+ } = options;
2865
+ const blockName = markdownName || nodeName;
2866
+ const filterAttributes = (attrs) => {
2867
+ if (!allowedAttributes) {
2868
+ return attrs;
2869
+ }
2870
+ const filtered = {};
2871
+ allowedAttributes.forEach((key) => {
2872
+ if (key in attrs) {
2873
+ filtered[key] = attrs[key];
2874
+ }
2875
+ });
2876
+ return filtered;
2877
+ };
2878
+ return {
2879
+ parseMarkdown: (token, h2) => {
2880
+ let nodeContent;
2881
+ if (getContent) {
2882
+ const contentResult = getContent(token);
2883
+ nodeContent = typeof contentResult === "string" ? [{ type: "text", text: contentResult }] : contentResult;
2884
+ } else if (content === "block") {
2885
+ nodeContent = h2.parseChildren(token.tokens || []);
2886
+ } else {
2887
+ nodeContent = h2.parseInline(token.tokens || []);
2888
+ }
2889
+ const attrs = { ...defaultAttributes, ...token.attributes };
2890
+ return h2.createNode(nodeName, attrs, nodeContent);
2891
+ },
2892
+ markdownTokenizer: {
2893
+ name: nodeName,
2894
+ level: "block",
2895
+ start(src) {
2896
+ var _a;
2897
+ const regex = new RegExp(`^:::${blockName}`, "m");
2898
+ const index = (_a = src.match(regex)) == null ? void 0 : _a.index;
2899
+ return index !== void 0 ? index : -1;
2900
+ },
2901
+ tokenize(src, _tokens, lexer) {
2902
+ var _a;
2903
+ const openingRegex = new RegExp(`^:::${blockName}(?:\\s+\\{([^}]*)\\})?\\s*\\n`);
2904
+ const openingMatch = src.match(openingRegex);
2905
+ if (!openingMatch) {
2906
+ return void 0;
2907
+ }
2908
+ const [openingTag, attrString = ""] = openingMatch;
2909
+ const attributes = parseAttributes2(attrString);
2910
+ let level = 1;
2911
+ const position = openingTag.length;
2912
+ let matchedContent = "";
2913
+ const blockPattern = /^:::([\w-]*)(\s.*)?/gm;
2914
+ const remaining = src.slice(position);
2915
+ blockPattern.lastIndex = 0;
2916
+ for (; ; ) {
2917
+ const match = blockPattern.exec(remaining);
2918
+ if (match === null) {
2919
+ break;
2920
+ }
2921
+ const matchPos = match.index;
2922
+ const blockType = match[1];
2923
+ if ((_a = match[2]) == null ? void 0 : _a.endsWith(":::")) {
2924
+ continue;
2925
+ }
2926
+ if (blockType) {
2927
+ level += 1;
2928
+ } else {
2929
+ level -= 1;
2930
+ if (level === 0) {
2931
+ const rawContent = remaining.slice(0, matchPos);
2932
+ matchedContent = rawContent.trim();
2933
+ const fullMatch = src.slice(0, position + matchPos + match[0].length);
2934
+ let contentTokens = [];
2935
+ if (matchedContent) {
2936
+ if (content === "block") {
2937
+ contentTokens = lexer.blockTokens(rawContent);
2938
+ contentTokens.forEach((token) => {
2939
+ if (token.text && (!token.tokens || token.tokens.length === 0)) {
2940
+ token.tokens = lexer.inlineTokens(token.text);
2941
+ }
2942
+ });
2943
+ while (contentTokens.length > 0) {
2944
+ const lastToken = contentTokens[contentTokens.length - 1];
2945
+ if (lastToken.type === "paragraph" && (!lastToken.text || lastToken.text.trim() === "")) {
2946
+ contentTokens.pop();
2947
+ } else {
2948
+ break;
2949
+ }
2950
+ }
2951
+ } else {
2952
+ contentTokens = lexer.inlineTokens(matchedContent);
2953
+ }
2954
+ }
2955
+ return {
2956
+ type: nodeName,
2957
+ raw: fullMatch,
2958
+ attributes,
2959
+ content: matchedContent,
2960
+ tokens: contentTokens
2961
+ };
2962
+ }
2963
+ }
2964
+ }
2965
+ return void 0;
2966
+ }
2967
+ },
2968
+ renderMarkdown: (node, h2) => {
2969
+ const filteredAttrs = filterAttributes(node.attrs || {});
2970
+ const attrs = serializeAttributes2(filteredAttrs);
2971
+ const attrString = attrs ? ` {${attrs}}` : "";
2972
+ const renderedContent = h2.renderChildren(node.content || [], "\n\n");
2973
+ return `:::${blockName}${attrString}
2974
+
2975
+ ${renderedContent}
2976
+
2977
+ :::`;
2978
+ }
2979
+ };
2980
+ }
2981
+ function parseShortcodeAttributes(attrString) {
2982
+ if (!attrString.trim()) {
2983
+ return {};
2984
+ }
2985
+ const attributes = {};
2986
+ const regex = /(\w+)=(?:"([^"]*)"|'([^']*)')/g;
2987
+ let match = regex.exec(attrString);
2988
+ while (match !== null) {
2989
+ const [, key, doubleQuoted, singleQuoted] = match;
2990
+ attributes[key] = doubleQuoted || singleQuoted;
2991
+ match = regex.exec(attrString);
2992
+ }
2993
+ return attributes;
2994
+ }
2995
+ function serializeShortcodeAttributes(attrs) {
2996
+ return Object.entries(attrs).filter(([, value]) => value !== void 0 && value !== null).map(([key, value]) => `${key}="${value}"`).join(" ");
2997
+ }
2998
+ function createInlineMarkdownSpec(options) {
2999
+ const {
3000
+ nodeName,
3001
+ name: shortcodeName,
3002
+ getContent,
3003
+ parseAttributes: parseAttributes2 = parseShortcodeAttributes,
3004
+ serializeAttributes: serializeAttributes2 = serializeShortcodeAttributes,
3005
+ defaultAttributes = {},
3006
+ selfClosing = false,
3007
+ allowedAttributes
3008
+ } = options;
3009
+ const shortcode = shortcodeName || nodeName;
3010
+ const filterAttributes = (attrs) => {
3011
+ if (!allowedAttributes) {
3012
+ return attrs;
3013
+ }
3014
+ const filtered = {};
3015
+ allowedAttributes.forEach((attr) => {
3016
+ const attrName = typeof attr === "string" ? attr : attr.name;
3017
+ const skipIfDefault = typeof attr === "string" ? void 0 : attr.skipIfDefault;
3018
+ if (attrName in attrs) {
3019
+ const value = attrs[attrName];
3020
+ if (skipIfDefault !== void 0 && value === skipIfDefault) {
3021
+ return;
3022
+ }
3023
+ filtered[attrName] = value;
3024
+ }
3025
+ });
3026
+ return filtered;
3027
+ };
3028
+ const escapedShortcode = shortcode.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
3029
+ return {
3030
+ parseMarkdown: (token, h2) => {
3031
+ const attrs = { ...defaultAttributes, ...token.attributes };
3032
+ if (selfClosing) {
3033
+ return h2.createNode(nodeName, attrs);
3034
+ }
3035
+ const content = getContent ? getContent(token) : token.content || "";
3036
+ if (content) {
3037
+ return h2.createNode(nodeName, attrs, [h2.createTextNode(content)]);
3038
+ }
3039
+ return h2.createNode(nodeName, attrs, []);
3040
+ },
3041
+ markdownTokenizer: {
3042
+ name: nodeName,
3043
+ level: "inline",
3044
+ start(src) {
3045
+ const startPattern = selfClosing ? new RegExp(`\\[${escapedShortcode}\\s*[^\\]]*\\]`) : new RegExp(`\\[${escapedShortcode}\\s*[^\\]]*\\][\\s\\S]*?\\[\\/${escapedShortcode}\\]`);
3046
+ const match = src.match(startPattern);
3047
+ const index = match == null ? void 0 : match.index;
3048
+ return index !== void 0 ? index : -1;
3049
+ },
3050
+ tokenize(src, _tokens, _lexer) {
3051
+ const tokenPattern = selfClosing ? new RegExp(`^\\[${escapedShortcode}\\s*([^\\]]*)\\]`) : new RegExp(`^\\[${escapedShortcode}\\s*([^\\]]*)\\]([\\s\\S]*?)\\[\\/${escapedShortcode}\\]`);
3052
+ const match = src.match(tokenPattern);
3053
+ if (!match) {
3054
+ return void 0;
3055
+ }
3056
+ let content = "";
3057
+ let attrString = "";
3058
+ if (selfClosing) {
3059
+ const [, attrs] = match;
3060
+ attrString = attrs;
3061
+ } else {
3062
+ const [, attrs, contentMatch] = match;
3063
+ attrString = attrs;
3064
+ content = contentMatch || "";
3065
+ }
3066
+ const attributes = parseAttributes2(attrString.trim());
3067
+ return {
3068
+ type: nodeName,
3069
+ raw: match[0],
3070
+ content: content.trim(),
3071
+ attributes
3072
+ };
3073
+ }
3074
+ },
3075
+ renderMarkdown: (node) => {
3076
+ let content = "";
3077
+ if (getContent) {
3078
+ content = getContent(node);
3079
+ } else if (node.content && node.content.length > 0) {
3080
+ content = node.content.filter((child) => child.type === "text").map((child) => child.text).join("");
3081
+ }
3082
+ const filteredAttrs = filterAttributes(node.attrs || {});
3083
+ const attrs = serializeAttributes2(filteredAttrs);
3084
+ const attrString = attrs ? ` ${attrs}` : "";
3085
+ if (selfClosing) {
3086
+ return `[${shortcode}${attrString}]`;
3087
+ }
3088
+ return `[${shortcode}${attrString}]${content}[/${shortcode}]`;
3089
+ }
3090
+ };
3091
+ }
3092
+ function parseIndentedBlocks(src, config, lexer) {
3093
+ var _a, _b, _c, _d;
3094
+ const lines = src.split("\n");
3095
+ const items = [];
3096
+ let totalRaw = "";
3097
+ let i = 0;
3098
+ const baseIndentSize = config.baseIndentSize || 2;
3099
+ while (i < lines.length) {
3100
+ const currentLine = lines[i];
3101
+ const itemMatch = currentLine.match(config.itemPattern);
3102
+ if (!itemMatch) {
3103
+ if (items.length > 0) {
3104
+ break;
3105
+ } else if (currentLine.trim() === "") {
3106
+ i += 1;
3107
+ totalRaw = `${totalRaw}${currentLine}
3108
+ `;
3109
+ continue;
3110
+ } else {
3111
+ return void 0;
3112
+ }
3113
+ }
3114
+ const itemData = config.extractItemData(itemMatch);
3115
+ const { indentLevel, mainContent } = itemData;
3116
+ totalRaw = `${totalRaw}${currentLine}
3117
+ `;
3118
+ const itemContent = [mainContent];
3119
+ i += 1;
3120
+ while (i < lines.length) {
3121
+ const nextLine = lines[i];
3122
+ if (nextLine.trim() === "") {
3123
+ const nextNonEmptyIndex = lines.slice(i + 1).findIndex((l) => l.trim() !== "");
3124
+ if (nextNonEmptyIndex === -1) {
3125
+ break;
3126
+ }
3127
+ const nextNonEmpty = lines[i + 1 + nextNonEmptyIndex];
3128
+ const nextIndent2 = ((_b = (_a = nextNonEmpty.match(/^(\s*)/)) == null ? void 0 : _a[1]) == null ? void 0 : _b.length) || 0;
3129
+ if (nextIndent2 > indentLevel) {
3130
+ itemContent.push(nextLine);
3131
+ totalRaw = `${totalRaw}${nextLine}
3132
+ `;
3133
+ i += 1;
3134
+ continue;
3135
+ } else {
3136
+ break;
3137
+ }
3138
+ }
3139
+ const nextIndent = ((_d = (_c = nextLine.match(/^(\s*)/)) == null ? void 0 : _c[1]) == null ? void 0 : _d.length) || 0;
3140
+ if (nextIndent > indentLevel) {
3141
+ itemContent.push(nextLine);
3142
+ totalRaw = `${totalRaw}${nextLine}
3143
+ `;
3144
+ i += 1;
3145
+ } else {
3146
+ break;
3147
+ }
3148
+ }
3149
+ let nestedTokens;
3150
+ const nestedContent = itemContent.slice(1);
3151
+ if (nestedContent.length > 0) {
3152
+ const dedentedNested = nestedContent.map((nestedLine) => nestedLine.slice(indentLevel + baseIndentSize)).join("\n");
3153
+ if (dedentedNested.trim()) {
3154
+ if (config.customNestedParser) {
3155
+ nestedTokens = config.customNestedParser(dedentedNested);
3156
+ } else {
3157
+ nestedTokens = lexer.blockTokens(dedentedNested);
3158
+ }
3159
+ }
3160
+ }
3161
+ const token = config.createToken(itemData, nestedTokens);
3162
+ items.push(token);
3163
+ }
3164
+ if (items.length === 0) {
3165
+ return void 0;
3166
+ }
3167
+ return {
3168
+ items,
3169
+ raw: totalRaw
3170
+ };
3171
+ }
3172
+ function renderNestedMarkdownContent(node, h2, prefixOrGenerator, ctx) {
3173
+ if (!node || !Array.isArray(node.content)) {
3174
+ return "";
3175
+ }
3176
+ const prefix = typeof prefixOrGenerator === "function" ? prefixOrGenerator(ctx) : prefixOrGenerator;
3177
+ const [content, ...children] = node.content;
3178
+ const mainContent = h2.renderChildren([content]);
3179
+ const output = [`${prefix}${mainContent}`];
3180
+ if (children && children.length > 0) {
3181
+ children.forEach((child) => {
3182
+ const childContent = h2.renderChildren([child]);
3183
+ if (childContent) {
3184
+ const indentedChild = childContent.split("\n").map((line) => line ? h2.indent(line) : "").join("\n");
3185
+ output.push(indentedChild);
3186
+ }
3187
+ });
3188
+ }
3189
+ return output.join("\n");
3190
+ }
3191
+ var Node3 = class _Node extends Extendable {
3192
+ constructor() {
3193
+ super(...arguments);
3194
+ this.type = "node";
3195
+ }
3196
+ /**
3197
+ * Create a new Node instance
3198
+ * @param config - Node configuration object or a function that returns a configuration object
3199
+ */
3200
+ static create(config = {}) {
3201
+ const resolvedConfig = typeof config === "function" ? config() : config;
3202
+ return new _Node(resolvedConfig);
3203
+ }
3204
+ configure(options) {
3205
+ return super.configure(options);
3206
+ }
3207
+ extend(extendedConfig) {
3208
+ const resolvedConfig = typeof extendedConfig === "function" ? extendedConfig() : extendedConfig;
3209
+ return super.extend(resolvedConfig);
3210
+ }
3211
+ };
3212
+ function tiptapContent(text) {
3213
+ return {
3214
+ type: "doc",
3215
+ content: [
3216
+ {
3217
+ type: "paragraph",
3218
+ content: [
3219
+ {
3220
+ type: "text",
3221
+ text
3222
+ }
3223
+ ]
3224
+ }
3225
+ ]
3226
+ };
3227
+ }
3228
+ function parseJSONContent(value, defaultValue) {
3229
+ if (!value) {
3230
+ return tiptapContent(defaultValue);
3231
+ }
3232
+ try {
3233
+ return typeof value === "string" ? JSON.parse(value) : value;
3234
+ } catch (e) {
3235
+ console.error("Failed to parse JSON content:", e);
3236
+ return tiptapContent(`
3237
+ This component's content is malformed. Please change it or remove this component.
3238
+ Original content: ${JSON.stringify(value)}
3239
+ `);
3240
+ }
3241
+ }
3242
+ function useTiptapEditor(name, defaultValue = "", extensions = []) {
3243
+ const field = useField(name);
3244
+ const editor = useEditor({
3245
+ extensions,
3246
+ content: parseJSONContent(field.value, defaultValue),
3247
+ onUpdate: ({ editor: editor2 }) => {
3248
+ const json = editor2.getJSON();
3249
+ field.onChange(name, JSON.stringify(json));
3250
+ }
3251
+ });
3252
+ return { editor, field };
3253
+ }
3254
+ function toolbarButton(key, {
3255
+ onClick,
3256
+ icon,
3257
+ active,
3258
+ disabled,
3259
+ tooltip,
3260
+ marginLeft,
3261
+ hidden
3262
+ }) {
3263
+ return /* @__PURE__ */ jsx(Tooltip, { description: tooltip, children: /* @__PURE__ */ jsx(
3264
+ Button,
3265
+ {
3266
+ onClick,
3267
+ variant: "tertiary",
3268
+ size: "S",
3269
+ paddingLeft: 2,
3270
+ paddingRight: 2,
3271
+ marginLeft: marginLeft ?? 1,
3272
+ disabled,
3273
+ style: {
3274
+ color: active ? "black" : void 0,
3275
+ backgroundColor: active ? "#d9d8ff" : void 0,
3276
+ display: hidden ? "none" : void 0
3277
+ },
3278
+ children: icon
3279
+ }
3280
+ ) }, key);
3281
+ }
3282
+ function spacer(width) {
3283
+ return /* @__PURE__ */ jsx("div", { style: { width: width + "px" } });
3284
+ }
3285
+ const AccentCursiveMark = Mark.create({
3286
+ name: "accentCursive",
3287
+ addAttributes() {
3288
+ return {
3289
+ class: {
3290
+ default: "accent-cursive"
3291
+ }
3292
+ };
3293
+ },
3294
+ parseHTML() {
3295
+ return [
3296
+ {
3297
+ tag: "span.accent-cursive"
3298
+ }
3299
+ ];
3300
+ },
3301
+ renderHTML({ HTMLAttributes }) {
3302
+ return ["span", { ...HTMLAttributes, class: "accent-cursive" }, 0];
3303
+ }
3304
+ });
3305
+ const OnlyCursiveMark = Mark.create({
3306
+ name: "onlyCursive",
3307
+ addAttributes() {
3308
+ return {
3309
+ class: {
3310
+ default: "only-cursive"
3311
+ }
3312
+ };
3313
+ },
3314
+ parseHTML() {
3315
+ return [
3316
+ {
3317
+ tag: "span.only-cursive"
3318
+ }
3319
+ ];
3320
+ },
3321
+ renderHTML({ HTMLAttributes }) {
3322
+ return ["span", { ...HTMLAttributes, class: "only-cursive" }, 0];
3323
+ }
3324
+ });
3325
+ function useCursiveMark(editor, markName, props = { disabled: false }) {
3326
+ const editorState = useEditorState({
3327
+ editor,
3328
+ selector: (ctx) => {
3329
+ return {
3330
+ isActive: ctx.editor.isActive(markName) ?? false,
3331
+ canToggle: ctx.editor.can().chain().toggleMark(markName).run() ?? false
3332
+ };
3333
+ }
3334
+ });
3335
+ const toggleMark2 = () => {
3336
+ editor?.chain().focus().toggleMark(markName).run();
3337
+ };
3338
+ const getButtonConfig = () => {
3339
+ const configs = {
3340
+ accentCursive: {
3341
+ color: "var(--color-accent-dark, #ae8f5b)",
3342
+ tooltip: "Accent Cursive"
3343
+ },
3344
+ onlyCursive: {
3345
+ color: "var(--color-primary-default)",
3346
+ tooltip: "Only Cursive"
3347
+ }
3348
+ };
3349
+ return configs[markName];
3350
+ };
3351
+ const config = getButtonConfig();
3352
+ return {
3353
+ button: toolbarButton(markName, {
3354
+ onClick: toggleMark2,
3355
+ icon: /* @__PURE__ */ jsx(Italic, { style: { color: config.color } }),
3356
+ active: editorState.isActive,
3357
+ disabled: props.disabled || !editor || !editorState.canToggle,
3358
+ tooltip: config.tooltip
3359
+ })
3360
+ };
3361
+ }
3362
+ function useAccentCursive(editor, props) {
3363
+ return useCursiveMark(editor, "accentCursive", props);
3364
+ }
3365
+ export {
3366
+ AccentCursiveMark as A,
3367
+ BaseTiptapInput as B,
3368
+ Extension as E,
3369
+ Node3 as N,
3370
+ OnlyCursiveMark as O,
3371
+ useCursiveMark as a,
3372
+ textblockTypeInputRule as b,
3373
+ callOrReturn as c,
3374
+ isNodeSelection as d,
3375
+ useAccentCursive as e,
3376
+ getExtensionField as g,
3377
+ isNodeEmpty as i,
3378
+ mergeAttributes as m,
3379
+ spacer as s,
3380
+ toolbarButton as t,
3381
+ useTiptapEditor as u
3382
+ };
3383
+ //# sourceMappingURL=AccentCursive-CpAPpH9C.mjs.map