@milkdown/crepe 7.19.1 → 7.20.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (100) hide show
  1. package/lib/cjs/builder.js +43 -1
  2. package/lib/cjs/builder.js.map +1 -1
  3. package/lib/cjs/feature/block-edit/index.js +8 -2
  4. package/lib/cjs/feature/block-edit/index.js.map +1 -1
  5. package/lib/cjs/feature/code-mirror/index.js +1 -0
  6. package/lib/cjs/feature/code-mirror/index.js.map +1 -1
  7. package/lib/cjs/feature/cursor/index.js +1 -0
  8. package/lib/cjs/feature/cursor/index.js.map +1 -1
  9. package/lib/cjs/feature/image-block/index.js +4 -1
  10. package/lib/cjs/feature/image-block/index.js.map +1 -1
  11. package/lib/cjs/feature/latex/index.js +5 -0
  12. package/lib/cjs/feature/latex/index.js.map +1 -1
  13. package/lib/cjs/feature/link-tooltip/index.js +1 -0
  14. package/lib/cjs/feature/link-tooltip/index.js.map +1 -1
  15. package/lib/cjs/feature/list-item/index.js +1 -0
  16. package/lib/cjs/feature/list-item/index.js.map +1 -1
  17. package/lib/cjs/feature/placeholder/index.js +1 -0
  18. package/lib/cjs/feature/placeholder/index.js.map +1 -1
  19. package/lib/cjs/feature/table/index.js +1 -0
  20. package/lib/cjs/feature/table/index.js.map +1 -1
  21. package/lib/cjs/feature/toolbar/index.js +9 -2
  22. package/lib/cjs/feature/toolbar/index.js.map +1 -1
  23. package/lib/cjs/feature/top-bar/index.js +790 -0
  24. package/lib/cjs/feature/top-bar/index.js.map +1 -0
  25. package/lib/cjs/index.js +630 -142
  26. package/lib/cjs/index.js.map +1 -1
  27. package/lib/esm/builder.js +43 -1
  28. package/lib/esm/builder.js.map +1 -1
  29. package/lib/esm/feature/block-edit/index.js +8 -2
  30. package/lib/esm/feature/block-edit/index.js.map +1 -1
  31. package/lib/esm/feature/code-mirror/index.js +1 -0
  32. package/lib/esm/feature/code-mirror/index.js.map +1 -1
  33. package/lib/esm/feature/cursor/index.js +1 -0
  34. package/lib/esm/feature/cursor/index.js.map +1 -1
  35. package/lib/esm/feature/image-block/index.js +4 -1
  36. package/lib/esm/feature/image-block/index.js.map +1 -1
  37. package/lib/esm/feature/latex/index.js +5 -0
  38. package/lib/esm/feature/latex/index.js.map +1 -1
  39. package/lib/esm/feature/link-tooltip/index.js +1 -0
  40. package/lib/esm/feature/link-tooltip/index.js.map +1 -1
  41. package/lib/esm/feature/list-item/index.js +1 -0
  42. package/lib/esm/feature/list-item/index.js.map +1 -1
  43. package/lib/esm/feature/placeholder/index.js +1 -0
  44. package/lib/esm/feature/placeholder/index.js.map +1 -1
  45. package/lib/esm/feature/table/index.js +1 -0
  46. package/lib/esm/feature/table/index.js.map +1 -1
  47. package/lib/esm/feature/toolbar/index.js +9 -2
  48. package/lib/esm/feature/toolbar/index.js.map +1 -1
  49. package/lib/esm/feature/top-bar/index.js +788 -0
  50. package/lib/esm/feature/top-bar/index.js.map +1 -0
  51. package/lib/esm/index.js +631 -143
  52. package/lib/esm/index.js.map +1 -1
  53. package/lib/theme/common/style.css +1 -0
  54. package/lib/theme/common/top-bar.css +152 -0
  55. package/lib/tsconfig.tsbuildinfo +1 -1
  56. package/lib/types/core/builder.d.ts +2 -1
  57. package/lib/types/core/builder.d.ts.map +1 -1
  58. package/lib/types/feature/block-edit/handle/component.d.ts.map +1 -1
  59. package/lib/types/feature/block-edit/menu/component.d.ts.map +1 -1
  60. package/lib/types/feature/image-block/index.d.ts +2 -0
  61. package/lib/types/feature/image-block/index.d.ts.map +1 -1
  62. package/lib/types/feature/index.d.ts +4 -1
  63. package/lib/types/feature/index.d.ts.map +1 -1
  64. package/lib/types/feature/latex/inline-tooltip/component.d.ts.map +1 -1
  65. package/lib/types/feature/loader.d.ts.map +1 -1
  66. package/lib/types/feature/toolbar/component.d.ts.map +1 -1
  67. package/lib/types/feature/toolbar/config.d.ts +1 -1
  68. package/lib/types/feature/top-bar/component.d.ts +11 -0
  69. package/lib/types/feature/top-bar/component.d.ts.map +1 -0
  70. package/lib/types/feature/top-bar/config.d.ts +34 -0
  71. package/lib/types/feature/top-bar/config.d.ts.map +1 -0
  72. package/lib/types/feature/top-bar/index.d.ts +26 -0
  73. package/lib/types/feature/top-bar/index.d.ts.map +1 -0
  74. package/lib/types/icons/code-block.d.ts +2 -0
  75. package/lib/types/icons/code-block.d.ts.map +1 -0
  76. package/lib/types/icons/index.d.ts +1 -0
  77. package/lib/types/icons/index.d.ts.map +1 -1
  78. package/lib/types/utils/group-builder.d.ts +1 -1
  79. package/lib/types/utils/group-builder.d.ts.map +1 -1
  80. package/lib/types/utils/keep-alive.d.ts +2 -0
  81. package/lib/types/utils/keep-alive.d.ts.map +1 -0
  82. package/package.json +18 -13
  83. package/src/core/builder.ts +39 -2
  84. package/src/feature/block-edit/handle/component.tsx +3 -2
  85. package/src/feature/block-edit/menu/component.tsx +3 -2
  86. package/src/feature/block-edit/menu/config.ts +1 -1
  87. package/src/feature/image-block/index.ts +4 -0
  88. package/src/feature/index.ts +6 -0
  89. package/src/feature/latex/inline-tooltip/component.tsx +4 -2
  90. package/src/feature/loader.ts +4 -0
  91. package/src/feature/toolbar/component.tsx +7 -5
  92. package/src/feature/top-bar/component.tsx +198 -0
  93. package/src/feature/top-bar/config.ts +367 -0
  94. package/src/feature/top-bar/index.ts +113 -0
  95. package/src/icons/code-block.ts +12 -0
  96. package/src/icons/index.ts +1 -0
  97. package/src/theme/common/style.css +1 -0
  98. package/src/theme/common/top-bar.css +156 -0
  99. package/src/utils/group-builder.ts +1 -1
  100. package/src/utils/keep-alive.ts +3 -0
package/lib/cjs/index.js CHANGED
@@ -40,6 +40,7 @@ var history$1 = require('@milkdown/kit/plugin/history');
40
40
  var indent = require('@milkdown/kit/plugin/indent');
41
41
  var listener = require('@milkdown/kit/plugin/listener');
42
42
  var trailing = require('@milkdown/kit/plugin/trailing');
43
+ var upload = require('@milkdown/kit/plugin/upload');
43
44
 
44
45
  var CrepeFeature = /* @__PURE__ */ ((CrepeFeature2) => {
45
46
  CrepeFeature2["CodeMirror"] = "code-mirror";
@@ -52,6 +53,7 @@ var CrepeFeature = /* @__PURE__ */ ((CrepeFeature2) => {
52
53
  CrepeFeature2["Placeholder"] = "placeholder";
53
54
  CrepeFeature2["Table"] = "table";
54
55
  CrepeFeature2["Latex"] = "latex";
56
+ CrepeFeature2["TopBar"] = "top-bar";
55
57
  return CrepeFeature2;
56
58
  })(CrepeFeature || {});
57
59
  const defaultFeatures = {
@@ -64,7 +66,8 @@ const defaultFeatures = {
64
66
  ["toolbar" /* Toolbar */]: true,
65
67
  ["code-mirror" /* CodeMirror */]: true,
66
68
  ["table" /* Table */]: true,
67
- ["latex" /* Latex */]: true
69
+ ["latex" /* Latex */]: true,
70
+ ["top-bar" /* TopBar */]: false
68
71
  };
69
72
 
70
73
  const alignCenterIcon = `
@@ -268,6 +271,19 @@ const codeIcon = `
268
271
  </svg>
269
272
  `;
270
273
 
274
+ const codeBlockIcon = `
275
+ <svg
276
+ xmlns="http://www.w3.org/2000/svg"
277
+ width="24"
278
+ height="24"
279
+ viewBox="0 0 24 24"
280
+ >
281
+ <path
282
+ d="M3 3h18a1 1 0 0 1 1 1v16a1 1 0 0 1-1 1H3a1 1 0 0 1-1-1V4a1 1 0 0 1 1-1zm1 2v14h16V5H4zm8 10h6v2h-6v-2zm-3.333-3L5.838 9.172l1.415-1.415L11.495 12l-4.242 4.243-1.415-1.415L8.667 12z"
283
+ />
284
+ </svg>
285
+ `;
286
+
271
287
  const confirmIcon = `
272
288
  <svg
273
289
  xmlns="http://www.w3.org/2000/svg"
@@ -770,22 +786,22 @@ function isInList(selection) {
770
786
  return (type == null ? void 0 : type.name) === "list_item";
771
787
  }
772
788
 
773
- var __typeError$5 = (msg) => {
789
+ var __typeError$6 = (msg) => {
774
790
  throw TypeError(msg);
775
791
  };
776
- var __accessCheck$5 = (obj, member, msg) => member.has(obj) || __typeError$5("Cannot " + msg);
777
- var __privateGet$5 = (obj, member, getter) => (__accessCheck$5(obj, member, "read from private field"), getter ? getter.call(obj) : member.get(obj));
778
- var __privateAdd$5 = (obj, member, value) => member.has(obj) ? __typeError$5("Cannot add the same private member more than once") : member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
779
- var __privateSet$5 = (obj, member, value, setter) => (__accessCheck$5(obj, member, "write to private field"), member.set(obj, value), value);
792
+ var __accessCheck$6 = (obj, member, msg) => member.has(obj) || __typeError$6("Cannot " + msg);
793
+ var __privateGet$6 = (obj, member, getter) => (__accessCheck$6(obj, member, "read from private field"), getter ? getter.call(obj) : member.get(obj));
794
+ var __privateAdd$6 = (obj, member, value) => member.has(obj) ? __typeError$6("Cannot add the same private member more than once") : member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
795
+ var __privateSet$6 = (obj, member, value, setter) => (__accessCheck$6(obj, member, "write to private field"), member.set(obj, value), value);
780
796
  var _groups, _getGroupInstance;
781
797
  class GroupBuilder {
782
798
  constructor() {
783
- __privateAdd$5(this, _groups, []);
799
+ __privateAdd$6(this, _groups, []);
784
800
  this.clear = () => {
785
- __privateSet$5(this, _groups, []);
801
+ __privateSet$6(this, _groups, []);
786
802
  return this;
787
803
  };
788
- __privateAdd$5(this, _getGroupInstance, (group) => {
804
+ __privateAdd$6(this, _getGroupInstance, (group) => {
789
805
  const groupInstance = {
790
806
  group,
791
807
  addItem: (key, item) => {
@@ -807,23 +823,26 @@ class GroupBuilder {
807
823
  label,
808
824
  items
809
825
  };
810
- __privateGet$5(this, _groups).push(group);
811
- return __privateGet$5(this, _getGroupInstance).call(this, group);
826
+ __privateGet$6(this, _groups).push(group);
827
+ return __privateGet$6(this, _getGroupInstance).call(this, group);
812
828
  };
813
829
  this.getGroup = (key) => {
814
- const group = __privateGet$5(this, _groups).find((group2) => group2.key === key);
830
+ const group = __privateGet$6(this, _groups).find((group2) => group2.key === key);
815
831
  if (!group) throw new Error(`Group with key ${key} not found`);
816
- return __privateGet$5(this, _getGroupInstance).call(this, group);
832
+ return __privateGet$6(this, _getGroupInstance).call(this, group);
817
833
  };
818
834
  this.build = () => {
819
- return __privateGet$5(this, _groups);
835
+ return __privateGet$6(this, _groups);
820
836
  };
821
837
  }
822
838
  }
823
839
  _groups = new WeakMap();
824
840
  _getGroupInstance = new WeakMap();
825
841
 
826
- function getGroups$1(filter, config, ctx) {
842
+ function keepAlive(..._args) {
843
+ }
844
+
845
+ function getGroups$2(filter, config, ctx) {
827
846
  var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y, _z, _A, _B, _C, _D, _E, _F, _G, _H, _I, _J, _K, _L, _M, _N, _O, _P, _Q, _R, _S, _T, _U, _V, _W, _X, _Y, _Z, __, _$, _aa, _ba, _ca, _da, _ea, _fa, _ga, _ha, _ia, _ja, _ka, _la, _ma, _na, _oa, _pa, _qa, _ra, _sa, _ta, _ua, _va, _wa, _xa, _ya, _za, _Aa, _Ba, _Ca, _Da, _Ea, _Fa, _Ga, _Ha, _Ia, _Ja, _Ka, _La, _Ma, _Na, _Oa, _Pa, _Qa, _Ra, _Sa, _Ta, _Ua, _Va, _Wa, _Xa, _Ya, _Za, __a, _$a, _ab, _bb, _cb, _db, _eb, _fb, _gb, _hb, _ib, _jb, _kb;
828
847
  const flags = ctx && useCrepeFeatures(ctx).get();
829
848
  const isLatexEnabled = flags == null ? void 0 : flags.includes(CrepeFeature.Latex);
@@ -1090,7 +1109,7 @@ function getGroups$1(filter, config, ctx) {
1090
1109
  commands.call(commonmark.clearTextInCurrentBlockCommand.key);
1091
1110
  commands.call(commonmark.addBlockTypeCommand.key, {
1092
1111
  nodeType: codeBlock,
1093
- attrs: { language: "LaTex" }
1112
+ attrs: { language: "LaTeX" }
1094
1113
  });
1095
1114
  }
1096
1115
  });
@@ -1126,6 +1145,7 @@ function getGroups$1(filter, config, ctx) {
1126
1145
  };
1127
1146
  }
1128
1147
 
1148
+ keepAlive(vue.h);
1129
1149
  const Menu = vue.defineComponent({
1130
1150
  props: {
1131
1151
  ctx: {
@@ -1151,7 +1171,7 @@ const Menu = vue.defineComponent({
1151
1171
  },
1152
1172
  setup({ ctx, show, filter, hide, config }) {
1153
1173
  const host = vue.ref();
1154
- const groupInfo = vue.computed(() => getGroups$1(filter.value, config, ctx));
1174
+ const groupInfo = vue.computed(() => getGroups$2(filter.value, config, ctx));
1155
1175
  const hoverIndex = vue.ref(0);
1156
1176
  const prevMousePosition = vue.ref({ x: -999, y: -999 });
1157
1177
  const onPointerMove = (e) => {
@@ -1180,7 +1200,7 @@ const Menu = vue.defineComponent({
1180
1200
  };
1181
1201
  const runByIndex = (index) => {
1182
1202
  const item = groupInfo.value.groups.flatMap((group) => group.items).at(index);
1183
- if (item && ctx) item.onRun(ctx);
1203
+ if ((item == null ? void 0 : item.onRun) && ctx) item.onRun(ctx);
1184
1204
  hide();
1185
1205
  };
1186
1206
  const onKeydown = (e) => {
@@ -1284,14 +1304,14 @@ const Menu = vue.defineComponent({
1284
1304
  }
1285
1305
  });
1286
1306
 
1287
- var __typeError$4 = (msg) => {
1307
+ var __typeError$5 = (msg) => {
1288
1308
  throw TypeError(msg);
1289
1309
  };
1290
- var __accessCheck$4 = (obj, member, msg) => member.has(obj) || __typeError$4("Cannot " + msg);
1291
- var __privateGet$4 = (obj, member, getter) => (__accessCheck$4(obj, member, "read from private field"), getter ? getter.call(obj) : member.get(obj));
1292
- var __privateAdd$4 = (obj, member, value) => member.has(obj) ? __typeError$4("Cannot add the same private member more than once") : member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
1293
- var __privateSet$4 = (obj, member, value, setter) => (__accessCheck$4(obj, member, "write to private field"), member.set(obj, value), value);
1294
- var _content$3, _app$3, _filter, _slashProvider, _programmaticallyPos;
1310
+ var __accessCheck$5 = (obj, member, msg) => member.has(obj) || __typeError$5("Cannot " + msg);
1311
+ var __privateGet$5 = (obj, member, getter) => (__accessCheck$5(obj, member, "read from private field"), getter ? getter.call(obj) : member.get(obj));
1312
+ var __privateAdd$5 = (obj, member, value) => member.has(obj) ? __typeError$5("Cannot add the same private member more than once") : member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
1313
+ var __privateSet$5 = (obj, member, value, setter) => (__accessCheck$5(obj, member, "write to private field"), member.set(obj, value), value);
1314
+ var _content$3, _app$4, _filter, _slashProvider, _programmaticallyPos;
1295
1315
  const menu = slash.slashFactory("CREPE_MENU");
1296
1316
  const menuAPI = utils.$ctx(
1297
1317
  {
@@ -1309,33 +1329,33 @@ function configureMenu(ctx, config) {
1309
1329
  }
1310
1330
  class MenuView {
1311
1331
  constructor(ctx, view, config) {
1312
- __privateAdd$4(this, _content$3);
1313
- __privateAdd$4(this, _app$3);
1314
- __privateAdd$4(this, _filter);
1315
- __privateAdd$4(this, _slashProvider);
1316
- __privateAdd$4(this, _programmaticallyPos, null);
1332
+ __privateAdd$5(this, _content$3);
1333
+ __privateAdd$5(this, _app$4);
1334
+ __privateAdd$5(this, _filter);
1335
+ __privateAdd$5(this, _slashProvider);
1336
+ __privateAdd$5(this, _programmaticallyPos, null);
1317
1337
  this.update = (view) => {
1318
- __privateGet$4(this, _slashProvider).update(view);
1338
+ __privateGet$5(this, _slashProvider).update(view);
1319
1339
  };
1320
1340
  this.show = (pos) => {
1321
- __privateSet$4(this, _programmaticallyPos, pos);
1322
- __privateGet$4(this, _filter).value = "";
1323
- __privateGet$4(this, _slashProvider).show();
1341
+ __privateSet$5(this, _programmaticallyPos, pos);
1342
+ __privateGet$5(this, _filter).value = "";
1343
+ __privateGet$5(this, _slashProvider).show();
1324
1344
  };
1325
1345
  this.hide = () => {
1326
- __privateSet$4(this, _programmaticallyPos, null);
1327
- __privateGet$4(this, _slashProvider).hide();
1346
+ __privateSet$5(this, _programmaticallyPos, null);
1347
+ __privateGet$5(this, _slashProvider).hide();
1328
1348
  };
1329
1349
  this.destroy = () => {
1330
- __privateGet$4(this, _slashProvider).destroy();
1331
- __privateGet$4(this, _app$3).unmount();
1332
- __privateGet$4(this, _content$3).remove();
1350
+ __privateGet$5(this, _slashProvider).destroy();
1351
+ __privateGet$5(this, _app$4).unmount();
1352
+ __privateGet$5(this, _content$3).remove();
1333
1353
  };
1334
1354
  const content = document.createElement("div");
1335
1355
  content.classList.add("milkdown-slash-menu");
1336
1356
  const show = vue.ref(false);
1337
1357
  const filter = vue.ref("");
1338
- __privateSet$4(this, _filter, filter);
1358
+ __privateSet$5(this, _filter, filter);
1339
1359
  const hide = this.hide;
1340
1360
  const app = vue.createApp(Menu, {
1341
1361
  ctx,
@@ -1344,12 +1364,12 @@ class MenuView {
1344
1364
  filter,
1345
1365
  hide
1346
1366
  });
1347
- __privateSet$4(this, _app$3, app);
1367
+ __privateSet$5(this, _app$4, app);
1348
1368
  app.mount(content);
1349
- __privateSet$4(this, _content$3, content);
1369
+ __privateSet$5(this, _content$3, content);
1350
1370
  const self = this;
1351
- __privateSet$4(this, _slashProvider, new slash.SlashProvider({
1352
- content: __privateGet$4(this, _content$3),
1371
+ __privateSet$5(this, _slashProvider, new slash.SlashProvider({
1372
+ content: __privateGet$5(this, _content$3),
1353
1373
  debounce: 20,
1354
1374
  shouldShow(view2) {
1355
1375
  if (isInCodeBlock(view2.state.selection) || isInList(view2.state.selection))
@@ -1362,13 +1382,13 @@ class MenuView {
1362
1382
  if (!isSelectionAtEndOfNode(view2.state.selection)) {
1363
1383
  return false;
1364
1384
  }
1365
- const pos = __privateGet$4(self, _programmaticallyPos);
1385
+ const pos = __privateGet$5(self, _programmaticallyPos);
1366
1386
  filter.value = currentText.startsWith("/") ? currentText.slice(1) : currentText;
1367
1387
  if (typeof pos === "number") {
1368
1388
  const maxSize = view2.state.doc.nodeSize - 2;
1369
1389
  const validPos = Math.min(pos, maxSize);
1370
1390
  if (view2.state.doc.resolve(validPos).node() !== view2.state.doc.resolve(view2.state.selection.from).node()) {
1371
- __privateSet$4(self, _programmaticallyPos, null);
1391
+ __privateSet$5(self, _programmaticallyPos, null);
1372
1392
  return false;
1373
1393
  }
1374
1394
  return true;
@@ -1378,10 +1398,10 @@ class MenuView {
1378
1398
  },
1379
1399
  offset: 10
1380
1400
  }));
1381
- __privateGet$4(this, _slashProvider).onShow = () => {
1401
+ __privateGet$5(this, _slashProvider).onShow = () => {
1382
1402
  show.value = true;
1383
1403
  };
1384
- __privateGet$4(this, _slashProvider).onHide = () => {
1404
+ __privateGet$5(this, _slashProvider).onHide = () => {
1385
1405
  show.value = false;
1386
1406
  };
1387
1407
  this.update(view);
@@ -1392,7 +1412,7 @@ class MenuView {
1392
1412
  }
1393
1413
  }
1394
1414
  _content$3 = new WeakMap();
1395
- _app$3 = new WeakMap();
1415
+ _app$4 = new WeakMap();
1396
1416
  _filter = new WeakMap();
1397
1417
  _slashProvider = new WeakMap();
1398
1418
  _programmaticallyPos = new WeakMap();
@@ -1404,6 +1424,7 @@ function isSelectionAtEndOfNode(selection) {
1404
1424
  return offset === parent.content.size;
1405
1425
  }
1406
1426
 
1427
+ keepAlive(vue.h, vue.Fragment);
1407
1428
  const BlockHandle = vue.defineComponent({
1408
1429
  props: {
1409
1430
  onAdd: {
@@ -1447,45 +1468,45 @@ const BlockHandle = vue.defineComponent({
1447
1468
  }
1448
1469
  });
1449
1470
 
1450
- var __typeError$3 = (msg) => {
1471
+ var __typeError$4 = (msg) => {
1451
1472
  throw TypeError(msg);
1452
1473
  };
1453
- var __accessCheck$3 = (obj, member, msg) => member.has(obj) || __typeError$3("Cannot " + msg);
1454
- var __privateGet$3 = (obj, member, getter) => (__accessCheck$3(obj, member, "read from private field"), getter ? getter.call(obj) : member.get(obj));
1455
- var __privateAdd$3 = (obj, member, value) => member.has(obj) ? __typeError$3("Cannot add the same private member more than once") : member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
1456
- var __privateSet$3 = (obj, member, value, setter) => (__accessCheck$3(obj, member, "write to private field"), member.set(obj, value), value);
1457
- var _content$2, _provider$1, _app$2, _ctx;
1474
+ var __accessCheck$4 = (obj, member, msg) => member.has(obj) || __typeError$4("Cannot " + msg);
1475
+ var __privateGet$4 = (obj, member, getter) => (__accessCheck$4(obj, member, "read from private field"), getter ? getter.call(obj) : member.get(obj));
1476
+ var __privateAdd$4 = (obj, member, value) => member.has(obj) ? __typeError$4("Cannot add the same private member more than once") : member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
1477
+ var __privateSet$4 = (obj, member, value, setter) => (__accessCheck$4(obj, member, "write to private field"), member.set(obj, value), value);
1478
+ var _content$2, _provider$1, _app$3, _ctx;
1458
1479
  class BlockHandleView {
1459
1480
  constructor(ctx, config) {
1460
- __privateAdd$3(this, _content$2);
1461
- __privateAdd$3(this, _provider$1);
1462
- __privateAdd$3(this, _app$2);
1463
- __privateAdd$3(this, _ctx);
1481
+ __privateAdd$4(this, _content$2);
1482
+ __privateAdd$4(this, _provider$1);
1483
+ __privateAdd$4(this, _app$3);
1484
+ __privateAdd$4(this, _ctx);
1464
1485
  this.update = () => {
1465
- __privateGet$3(this, _provider$1).update();
1486
+ __privateGet$4(this, _provider$1).update();
1466
1487
  };
1467
1488
  this.destroy = () => {
1468
- __privateGet$3(this, _provider$1).destroy();
1469
- __privateGet$3(this, _content$2).remove();
1470
- __privateGet$3(this, _app$2).unmount();
1489
+ __privateGet$4(this, _provider$1).destroy();
1490
+ __privateGet$4(this, _content$2).remove();
1491
+ __privateGet$4(this, _app$3).unmount();
1471
1492
  };
1472
1493
  this.onAdd = () => {
1473
- const ctx = __privateGet$3(this, _ctx);
1494
+ const ctx = __privateGet$4(this, _ctx);
1474
1495
  const view = ctx.get(core.editorViewCtx);
1475
1496
  if (!view.hasFocus()) view.focus();
1476
1497
  const { state: state$1, dispatch } = view;
1477
- const active = __privateGet$3(this, _provider$1).active;
1498
+ const active = __privateGet$4(this, _provider$1).active;
1478
1499
  if (!active) return;
1479
1500
  const $pos = active.$pos;
1480
1501
  const pos = $pos.pos + active.node.nodeSize;
1481
1502
  let tr = state$1.tr.insert(pos, commonmark.paragraphSchema.type(ctx).create());
1482
1503
  tr = tr.setSelection(state.TextSelection.near(tr.doc.resolve(pos)));
1483
1504
  dispatch(tr.scrollIntoView());
1484
- __privateGet$3(this, _provider$1).hide();
1505
+ __privateGet$4(this, _provider$1).hide();
1485
1506
  ctx.get(menuAPI.key).show(tr.selection.from);
1486
1507
  };
1487
1508
  var _a, _b, _c;
1488
- __privateSet$3(this, _ctx, ctx);
1509
+ __privateSet$4(this, _ctx, ctx);
1489
1510
  const content = document.createElement("div");
1490
1511
  content.classList.add("milkdown-block-handle");
1491
1512
  const app = vue.createApp(BlockHandle, {
@@ -1494,10 +1515,10 @@ class BlockHandleView {
1494
1515
  handleIcon: (_b = config == null ? void 0 : config.handleDragIcon) != null ? _b : menuIcon
1495
1516
  });
1496
1517
  app.mount(content);
1497
- __privateSet$3(this, _app$2, app);
1498
- __privateSet$3(this, _content$2, content);
1518
+ __privateSet$4(this, _app$3, app);
1519
+ __privateSet$4(this, _content$2, content);
1499
1520
  const blockProviderOptions = (_c = config == null ? void 0 : config.blockHandle) != null ? _c : {};
1500
- __privateSet$3(this, _provider$1, new block.BlockProvider({
1521
+ __privateSet$4(this, _provider$1, new block.BlockProvider({
1501
1522
  ctx,
1502
1523
  content,
1503
1524
  getOffset: () => 16,
@@ -1524,7 +1545,7 @@ class BlockHandleView {
1524
1545
  }
1525
1546
  _content$2 = new WeakMap();
1526
1547
  _provider$1 = new WeakMap();
1527
- _app$2 = new WeakMap();
1548
+ _app$3 = new WeakMap();
1528
1549
  _ctx = new WeakMap();
1529
1550
  function configureBlockHandle(ctx, config) {
1530
1551
  ctx.set(block.blockConfig.key, {
@@ -1630,7 +1651,9 @@ const imageBlock = (editor, config) => {
1630
1651
  uploadPlaceholderText: (_f = config == null ? void 0 : config.blockUploadPlaceholderText) != null ? _f : "or paste link",
1631
1652
  onUpload: (_h = (_g = config == null ? void 0 : config.blockOnUpload) != null ? _g : config == null ? void 0 : config.onUpload) != null ? _h : value.onUpload,
1632
1653
  proxyDomURL: config == null ? void 0 : config.proxyDomURL,
1633
- onImageLoadError: (_i = config == null ? void 0 : config.onImageLoadError) != null ? _i : value.onImageLoadError
1654
+ onImageLoadError: (_i = config == null ? void 0 : config.onImageLoadError) != null ? _i : value.onImageLoadError,
1655
+ maxWidth: config == null ? void 0 : config.maxWidth,
1656
+ maxHeight: config == null ? void 0 : config.maxHeight
1634
1657
  };
1635
1658
  });
1636
1659
  }).use(imageBlock$1.imageBlockComponent).use(imageInline.imageInlineComponent);
@@ -1747,6 +1770,7 @@ const toggleLatexCommand = utils.$command("ToggleLatex", (ctx) => {
1747
1770
 
1748
1771
  const inlineLatexTooltip = tooltip.tooltipFactory("INLINE_LATEX");
1749
1772
 
1773
+ keepAlive(vue.h);
1750
1774
  const LatexTooltip = vue.defineComponent({
1751
1775
  props: {
1752
1776
  config: {
@@ -1782,31 +1806,31 @@ const LatexTooltip = vue.defineComponent({
1782
1806
  }
1783
1807
  });
1784
1808
 
1785
- var __typeError$2 = (msg) => {
1809
+ var __typeError$3 = (msg) => {
1786
1810
  throw TypeError(msg);
1787
1811
  };
1788
- var __accessCheck$2 = (obj, member, msg) => member.has(obj) || __typeError$2("Cannot " + msg);
1789
- var __privateGet$2 = (obj, member, getter) => (__accessCheck$2(obj, member, "read from private field"), getter ? getter.call(obj) : member.get(obj));
1790
- var __privateAdd$2 = (obj, member, value) => member.has(obj) ? __typeError$2("Cannot add the same private member more than once") : member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
1791
- var __privateSet$2 = (obj, member, value, setter) => (__accessCheck$2(obj, member, "write to private field"), member.set(obj, value), value);
1792
- var _content$1, _provider, _dom, _innerView, _updateValue, _app$1, _onHide, _shouldShow;
1812
+ var __accessCheck$3 = (obj, member, msg) => member.has(obj) || __typeError$3("Cannot " + msg);
1813
+ var __privateGet$3 = (obj, member, getter) => (__accessCheck$3(obj, member, "read from private field"), getter ? getter.call(obj) : member.get(obj));
1814
+ var __privateAdd$3 = (obj, member, value) => member.has(obj) ? __typeError$3("Cannot add the same private member more than once") : member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
1815
+ var __privateSet$3 = (obj, member, value, setter) => (__accessCheck$3(obj, member, "write to private field"), member.set(obj, value), value);
1816
+ var _content$1, _provider, _dom, _innerView, _updateValue, _app$2, _onHide, _shouldShow;
1793
1817
  class LatexInlineTooltip {
1794
1818
  constructor(ctx, view, config) {
1795
1819
  this.ctx = ctx;
1796
- __privateAdd$2(this, _content$1);
1797
- __privateAdd$2(this, _provider);
1798
- __privateAdd$2(this, _dom);
1799
- __privateAdd$2(this, _innerView, vue.shallowRef(null));
1800
- __privateAdd$2(this, _updateValue, vue.shallowRef(() => {
1820
+ __privateAdd$3(this, _content$1);
1821
+ __privateAdd$3(this, _provider);
1822
+ __privateAdd$3(this, _dom);
1823
+ __privateAdd$3(this, _innerView, vue.shallowRef(null));
1824
+ __privateAdd$3(this, _updateValue, vue.shallowRef(() => {
1801
1825
  }));
1802
- __privateAdd$2(this, _app$1);
1803
- __privateAdd$2(this, _onHide, () => {
1804
- if (__privateGet$2(this, _innerView).value) {
1805
- __privateGet$2(this, _innerView).value.destroy();
1806
- __privateGet$2(this, _innerView).value = null;
1826
+ __privateAdd$3(this, _app$2);
1827
+ __privateAdd$3(this, _onHide, () => {
1828
+ if (__privateGet$3(this, _innerView).value) {
1829
+ __privateGet$3(this, _innerView).value.destroy();
1830
+ __privateGet$3(this, _innerView).value = null;
1807
1831
  }
1808
1832
  });
1809
- __privateAdd$2(this, _shouldShow, (view) => {
1833
+ __privateAdd$3(this, _shouldShow, (view) => {
1810
1834
  const shouldShow = () => {
1811
1835
  const { selection, schema } = view.state;
1812
1836
  if (selection.empty) return false;
@@ -1818,7 +1842,7 @@ class LatexInlineTooltip {
1818
1842
  null,
1819
1843
  schema.text(node.attrs.value)
1820
1844
  );
1821
- const innerView = new view$1.EditorView(__privateGet$2(this, _dom), {
1845
+ const innerView = new view$1.EditorView(__privateGet$3(this, _dom), {
1822
1846
  state: state.EditorState.create({
1823
1847
  doc: paragraph,
1824
1848
  schema: new model.Schema({
@@ -1845,15 +1869,15 @@ class LatexInlineTooltip {
1845
1869
  "Mod-Z": history.redo,
1846
1870
  "Mod-y": history.redo,
1847
1871
  Enter: () => {
1848
- __privateGet$2(this, _updateValue).value();
1872
+ __privateGet$3(this, _updateValue).value();
1849
1873
  return true;
1850
1874
  }
1851
1875
  })
1852
1876
  ]
1853
1877
  })
1854
1878
  });
1855
- __privateGet$2(this, _innerView).value = innerView;
1856
- __privateGet$2(this, _updateValue).value = () => {
1879
+ __privateGet$3(this, _innerView).value = innerView;
1880
+ __privateGet$3(this, _updateValue).value = () => {
1857
1881
  const { tr } = view.state;
1858
1882
  tr.setNodeAttribute(textFrom, "value", innerView.state.doc.textContent);
1859
1883
  view.dispatch(tr);
@@ -1864,37 +1888,37 @@ class LatexInlineTooltip {
1864
1888
  return true;
1865
1889
  };
1866
1890
  const show = shouldShow();
1867
- if (!show) __privateGet$2(this, _onHide).call(this);
1891
+ if (!show) __privateGet$3(this, _onHide).call(this);
1868
1892
  return show;
1869
1893
  });
1870
1894
  this.update = (view, prevState) => {
1871
- __privateGet$2(this, _provider).update(view, prevState);
1895
+ __privateGet$3(this, _provider).update(view, prevState);
1872
1896
  };
1873
1897
  this.destroy = () => {
1874
- __privateGet$2(this, _app$1).unmount();
1875
- __privateGet$2(this, _provider).destroy();
1876
- __privateGet$2(this, _content$1).remove();
1898
+ __privateGet$3(this, _app$2).unmount();
1899
+ __privateGet$3(this, _provider).destroy();
1900
+ __privateGet$3(this, _content$1).remove();
1877
1901
  };
1878
1902
  const content = document.createElement("div");
1879
1903
  content.className = "milkdown-latex-inline-edit";
1880
- __privateSet$2(this, _content$1, content);
1881
- __privateSet$2(this, _app$1, vue.createApp(LatexTooltip, {
1904
+ __privateSet$3(this, _content$1, content);
1905
+ __privateSet$3(this, _app$2, vue.createApp(LatexTooltip, {
1882
1906
  config,
1883
- innerView: __privateGet$2(this, _innerView),
1884
- updateValue: __privateGet$2(this, _updateValue)
1907
+ innerView: __privateGet$3(this, _innerView),
1908
+ updateValue: __privateGet$3(this, _updateValue)
1885
1909
  }));
1886
- __privateGet$2(this, _app$1).mount(content);
1887
- __privateSet$2(this, _provider, new tooltip.TooltipProvider({
1910
+ __privateGet$3(this, _app$2).mount(content);
1911
+ __privateSet$3(this, _provider, new tooltip.TooltipProvider({
1888
1912
  debounce: 0,
1889
- content: __privateGet$2(this, _content$1),
1890
- shouldShow: __privateGet$2(this, _shouldShow),
1913
+ content: __privateGet$3(this, _content$1),
1914
+ shouldShow: __privateGet$3(this, _shouldShow),
1891
1915
  offset: 10,
1892
1916
  floatingUIOptions: {
1893
1917
  placement: "bottom"
1894
1918
  }
1895
1919
  }));
1896
- __privateGet$2(this, _provider).update(view);
1897
- __privateSet$2(this, _dom, document.createElement("div"));
1920
+ __privateGet$3(this, _provider).update(view);
1921
+ __privateSet$3(this, _dom, document.createElement("div"));
1898
1922
  }
1899
1923
  }
1900
1924
  _content$1 = new WeakMap();
@@ -1902,7 +1926,7 @@ _provider = new WeakMap();
1902
1926
  _dom = new WeakMap();
1903
1927
  _innerView = new WeakMap();
1904
1928
  _updateValue = new WeakMap();
1905
- _app$1 = new WeakMap();
1929
+ _app$2 = new WeakMap();
1906
1930
  _onHide = new WeakMap();
1907
1931
  _shouldShow = new WeakMap();
1908
1932
 
@@ -2107,7 +2131,7 @@ const table = (editor, config) => {
2107
2131
  }).use(tableBlock.tableBlock);
2108
2132
  };
2109
2133
 
2110
- function getGroups(config, ctx) {
2134
+ function getGroups$1(config, ctx) {
2111
2135
  var _a, _b, _c, _d, _e, _f, _g;
2112
2136
  const groupBuilder = new GroupBuilder();
2113
2137
  groupBuilder.addGroup("formatting", "Formatting").addItem("bold", {
@@ -2195,6 +2219,7 @@ function getGroups(config, ctx) {
2195
2219
  return groupBuilder.build();
2196
2220
  }
2197
2221
 
2222
+ keepAlive(vue.h, vue.Fragment);
2198
2223
  const Toolbar = vue.defineComponent({
2199
2224
  props: {
2200
2225
  ctx: {
@@ -2222,15 +2247,17 @@ const Toolbar = vue.defineComponent({
2222
2247
  const { ctx, config } = props;
2223
2248
  const onClick = (fn) => (e) => {
2224
2249
  e.preventDefault();
2225
- ctx && fn(ctx);
2250
+ if (ctx) {
2251
+ fn == null ? void 0 : fn(ctx);
2252
+ }
2226
2253
  };
2227
2254
  function checkActive(checker) {
2228
- props.selection.value;
2255
+ keepAlive(props.selection.value);
2229
2256
  const status = ctx.get(core.editorCtx).status;
2230
2257
  if (status !== core.EditorStatus.Created) return false;
2231
2258
  return checker(ctx);
2232
2259
  }
2233
- const groupInfo = vue.computed(() => getGroups(config, ctx));
2260
+ const groupInfo = vue.computed(() => getGroups$1(config, ctx));
2234
2261
  return () => {
2235
2262
  return /* @__PURE__ */ vue.h(vue.Fragment, null, groupInfo.value.map((group) => {
2236
2263
  return group.items.map((item) => {
@@ -2259,49 +2286,49 @@ const Toolbar = vue.defineComponent({
2259
2286
  }
2260
2287
  });
2261
2288
 
2262
- var __typeError$1 = (msg) => {
2289
+ var __typeError$2 = (msg) => {
2263
2290
  throw TypeError(msg);
2264
2291
  };
2265
- var __accessCheck$1 = (obj, member, msg) => member.has(obj) || __typeError$1("Cannot " + msg);
2266
- var __privateGet$1 = (obj, member, getter) => (__accessCheck$1(obj, member, "read from private field"), getter ? getter.call(obj) : member.get(obj));
2267
- var __privateAdd$1 = (obj, member, value) => member.has(obj) ? __typeError$1("Cannot add the same private member more than once") : member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
2268
- var __privateSet$1 = (obj, member, value, setter) => (__accessCheck$1(obj, member, "write to private field"), member.set(obj, value), value);
2269
- var _tooltipProvider, _content, _app, _selection, _show;
2292
+ var __accessCheck$2 = (obj, member, msg) => member.has(obj) || __typeError$2("Cannot " + msg);
2293
+ var __privateGet$2 = (obj, member, getter) => (__accessCheck$2(obj, member, "read from private field"), getter ? getter.call(obj) : member.get(obj));
2294
+ var __privateAdd$2 = (obj, member, value) => member.has(obj) ? __typeError$2("Cannot add the same private member more than once") : member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
2295
+ var __privateSet$2 = (obj, member, value, setter) => (__accessCheck$2(obj, member, "write to private field"), member.set(obj, value), value);
2296
+ var _tooltipProvider, _content, _app$1, _selection, _show;
2270
2297
  const toolbarTooltip = tooltip.tooltipFactory("CREPE_TOOLBAR");
2271
2298
  class ToolbarView {
2272
2299
  constructor(ctx, view, config) {
2273
- __privateAdd$1(this, _tooltipProvider);
2274
- __privateAdd$1(this, _content);
2275
- __privateAdd$1(this, _app);
2276
- __privateAdd$1(this, _selection);
2277
- __privateAdd$1(this, _show, vue.ref(false));
2300
+ __privateAdd$2(this, _tooltipProvider);
2301
+ __privateAdd$2(this, _content);
2302
+ __privateAdd$2(this, _app$1);
2303
+ __privateAdd$2(this, _selection);
2304
+ __privateAdd$2(this, _show, vue.ref(false));
2278
2305
  this.update = (view, prevState) => {
2279
- __privateGet$1(this, _tooltipProvider).update(view, prevState);
2280
- __privateGet$1(this, _selection).value = view.state.selection;
2306
+ __privateGet$2(this, _tooltipProvider).update(view, prevState);
2307
+ __privateGet$2(this, _selection).value = view.state.selection;
2281
2308
  };
2282
2309
  this.destroy = () => {
2283
- __privateGet$1(this, _tooltipProvider).destroy();
2284
- __privateGet$1(this, _app).unmount();
2285
- __privateGet$1(this, _content).remove();
2310
+ __privateGet$2(this, _tooltipProvider).destroy();
2311
+ __privateGet$2(this, _app$1).unmount();
2312
+ __privateGet$2(this, _content).remove();
2286
2313
  };
2287
2314
  this.hide = () => {
2288
- __privateGet$1(this, _tooltipProvider).hide();
2315
+ __privateGet$2(this, _tooltipProvider).hide();
2289
2316
  };
2290
2317
  const content = document.createElement("div");
2291
2318
  content.className = "milkdown-toolbar";
2292
- __privateSet$1(this, _selection, vue.shallowRef(view.state.selection));
2319
+ __privateSet$2(this, _selection, vue.shallowRef(view.state.selection));
2293
2320
  const app = vue.createApp(Toolbar, {
2294
2321
  ctx,
2295
2322
  hide: this.hide,
2296
2323
  config,
2297
- selection: __privateGet$1(this, _selection),
2298
- show: __privateGet$1(this, _show)
2324
+ selection: __privateGet$2(this, _selection),
2325
+ show: __privateGet$2(this, _show)
2299
2326
  });
2300
2327
  app.mount(content);
2301
- __privateSet$1(this, _content, content);
2302
- __privateSet$1(this, _app, app);
2303
- __privateSet$1(this, _tooltipProvider, new tooltip.TooltipProvider({
2304
- content: __privateGet$1(this, _content),
2328
+ __privateSet$2(this, _content, content);
2329
+ __privateSet$2(this, _app$1, app);
2330
+ __privateSet$2(this, _tooltipProvider, new tooltip.TooltipProvider({
2331
+ content: __privateGet$2(this, _content),
2305
2332
  debounce: 20,
2306
2333
  offset: 10,
2307
2334
  shouldShow(view2) {
@@ -2318,18 +2345,18 @@ class ToolbarView {
2318
2345
  return true;
2319
2346
  }
2320
2347
  }));
2321
- __privateGet$1(this, _tooltipProvider).onShow = () => {
2322
- __privateGet$1(this, _show).value = true;
2348
+ __privateGet$2(this, _tooltipProvider).onShow = () => {
2349
+ __privateGet$2(this, _show).value = true;
2323
2350
  };
2324
- __privateGet$1(this, _tooltipProvider).onHide = () => {
2325
- __privateGet$1(this, _show).value = false;
2351
+ __privateGet$2(this, _tooltipProvider).onHide = () => {
2352
+ __privateGet$2(this, _show).value = false;
2326
2353
  };
2327
2354
  this.update(view);
2328
2355
  }
2329
2356
  }
2330
2357
  _tooltipProvider = new WeakMap();
2331
2358
  _content = new WeakMap();
2332
- _app = new WeakMap();
2359
+ _app$1 = new WeakMap();
2333
2360
  _selection = new WeakMap();
2334
2361
  _show = new WeakMap();
2335
2362
  const toolbar = (editor, config) => {
@@ -2340,6 +2367,442 @@ const toolbar = (editor, config) => {
2340
2367
  }).use(toolbarTooltip);
2341
2368
  };
2342
2369
 
2370
+ const defaultHeadingOptions = [
2371
+ { label: "Paragraph", level: null },
2372
+ { label: "Heading 1", level: 1 },
2373
+ { label: "Heading 2", level: 2 },
2374
+ { label: "Heading 3", level: 3 },
2375
+ { label: "Heading 4", level: 4 },
2376
+ { label: "Heading 5", level: 5 },
2377
+ { label: "Heading 6", level: 6 }
2378
+ ];
2379
+ function getCurrentHeading(ctx, options) {
2380
+ var _a, _b;
2381
+ const headingOptions = options != null ? options : defaultHeadingOptions;
2382
+ const view = ctx.get(core.editorViewCtx);
2383
+ const { $from } = view.state.selection;
2384
+ const node = $from.parent;
2385
+ const paragraphOption = (_a = headingOptions.find((o) => o.level === null)) != null ? _a : headingOptions[0];
2386
+ if (node.type === commonmark.headingSchema.type(ctx)) {
2387
+ const level = node.attrs.level;
2388
+ return (_b = headingOptions.find((o) => o.level === level)) != null ? _b : paragraphOption;
2389
+ }
2390
+ return paragraphOption;
2391
+ }
2392
+ function setHeading(ctx, level) {
2393
+ const commands = ctx.get(core.commandsCtx);
2394
+ if (level === null || level === void 0) {
2395
+ const paragraph = commonmark.paragraphSchema.type(ctx);
2396
+ commands.call(commonmark.setBlockTypeCommand.key, { nodeType: paragraph });
2397
+ } else {
2398
+ const heading = commonmark.headingSchema.type(ctx);
2399
+ commands.call(commonmark.setBlockTypeCommand.key, {
2400
+ nodeType: heading,
2401
+ attrs: { level }
2402
+ });
2403
+ }
2404
+ }
2405
+ function isMarkActive(ctx, markType) {
2406
+ const commands = ctx.get(core.commandsCtx);
2407
+ const selected = commands.call(commonmark.isMarkSelectedCommand.key, markType);
2408
+ if (selected) return true;
2409
+ const view = ctx.get(core.editorViewCtx);
2410
+ const { state: state$1 } = view;
2411
+ if (state$1.storedMarks) {
2412
+ return state$1.storedMarks.some((m) => m.type === markType);
2413
+ }
2414
+ if (state$1.selection instanceof state.TextSelection) {
2415
+ const { $cursor } = state$1.selection;
2416
+ if ($cursor) {
2417
+ return $cursor.marks().some((m) => m.type === markType);
2418
+ }
2419
+ }
2420
+ return false;
2421
+ }
2422
+ function buildHeadingSelector(headingOptions, chevronIcon) {
2423
+ const options = headingOptions != null ? headingOptions : defaultHeadingOptions;
2424
+ return {
2425
+ icon: "",
2426
+ active: () => false,
2427
+ selector: {
2428
+ chevronIcon: chevronIcon != null ? chevronIcon : chevronDownIcon,
2429
+ activeLabel: (ctx) => getCurrentHeading(ctx, options).label,
2430
+ options: options.map((opt) => ({
2431
+ label: opt.label,
2432
+ onSelect: (ctx) => setHeading(ctx, opt.level)
2433
+ }))
2434
+ }
2435
+ };
2436
+ }
2437
+ function getGroups(config, ctx) {
2438
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o;
2439
+ const flags = ctx && useCrepeFeatures(ctx).get();
2440
+ const isLatexEnabled = flags == null ? void 0 : flags.includes(CrepeFeature.Latex);
2441
+ const isImageBlockEnabled = flags == null ? void 0 : flags.includes(CrepeFeature.ImageBlock);
2442
+ const isTableEnabled = flags == null ? void 0 : flags.includes(CrepeFeature.Table);
2443
+ const groupBuilder = new GroupBuilder();
2444
+ groupBuilder.addGroup("heading", "Heading").addItem("heading-selector", {
2445
+ ...buildHeadingSelector(config == null ? void 0 : config.headingOptions, config == null ? void 0 : config.chevronDownIcon)
2446
+ });
2447
+ groupBuilder.addGroup("formatting", "Formatting").addItem("bold", {
2448
+ icon: (_a = config == null ? void 0 : config.boldIcon) != null ? _a : boldIcon,
2449
+ active: (ctx2) => isMarkActive(ctx2, commonmark.strongSchema.type(ctx2)),
2450
+ onRun: (ctx2) => {
2451
+ const commands = ctx2.get(core.commandsCtx);
2452
+ commands.call(commonmark.toggleStrongCommand.key);
2453
+ }
2454
+ }).addItem("italic", {
2455
+ icon: (_b = config == null ? void 0 : config.italicIcon) != null ? _b : italicIcon,
2456
+ active: (ctx2) => isMarkActive(ctx2, commonmark.emphasisSchema.type(ctx2)),
2457
+ onRun: (ctx2) => {
2458
+ const commands = ctx2.get(core.commandsCtx);
2459
+ commands.call(commonmark.toggleEmphasisCommand.key);
2460
+ }
2461
+ }).addItem("strikethrough", {
2462
+ icon: (_c = config == null ? void 0 : config.strikethroughIcon) != null ? _c : strikethroughIcon,
2463
+ active: (ctx2) => isMarkActive(ctx2, gfm.strikethroughSchema.type(ctx2)),
2464
+ onRun: (ctx2) => {
2465
+ const commands = ctx2.get(core.commandsCtx);
2466
+ commands.call(gfm.toggleStrikethroughCommand.key);
2467
+ }
2468
+ }).addItem("code", {
2469
+ icon: (_d = config == null ? void 0 : config.codeIcon) != null ? _d : codeIcon,
2470
+ active: (ctx2) => isMarkActive(ctx2, commonmark.inlineCodeSchema.type(ctx2)),
2471
+ onRun: (ctx2) => {
2472
+ const view = ctx2.get(core.editorViewCtx);
2473
+ const { state } = view;
2474
+ if (state.selection.empty) {
2475
+ const markType = commonmark.inlineCodeSchema.type(ctx2);
2476
+ const has = isMarkActive(ctx2, markType);
2477
+ if (has) {
2478
+ view.dispatch(state.tr.removeStoredMark(markType));
2479
+ } else {
2480
+ view.dispatch(state.tr.addStoredMark(markType.create()));
2481
+ }
2482
+ } else {
2483
+ const commands = ctx2.get(core.commandsCtx);
2484
+ commands.call(commonmark.toggleInlineCodeCommand.key);
2485
+ }
2486
+ }
2487
+ });
2488
+ groupBuilder.addGroup("list", "List").addItem("bullet-list", {
2489
+ icon: (_e = config == null ? void 0 : config.bulletListIcon) != null ? _e : bulletListIcon,
2490
+ active: () => false,
2491
+ onRun: (ctx2) => {
2492
+ const commands = ctx2.get(core.commandsCtx);
2493
+ const bulletList = commonmark.bulletListSchema.type(ctx2);
2494
+ commands.call(commonmark.wrapInBlockTypeCommand.key, { nodeType: bulletList });
2495
+ }
2496
+ }).addItem("ordered-list", {
2497
+ icon: (_f = config == null ? void 0 : config.orderedListIcon) != null ? _f : orderedListIcon,
2498
+ active: () => false,
2499
+ onRun: (ctx2) => {
2500
+ const commands = ctx2.get(core.commandsCtx);
2501
+ const orderedList = commonmark.orderedListSchema.type(ctx2);
2502
+ commands.call(commonmark.wrapInBlockTypeCommand.key, { nodeType: orderedList });
2503
+ }
2504
+ }).addItem("task-list", {
2505
+ icon: (_g = config == null ? void 0 : config.taskListIcon) != null ? _g : todoListIcon,
2506
+ active: () => false,
2507
+ onRun: (ctx2) => {
2508
+ const commands = ctx2.get(core.commandsCtx);
2509
+ const listItem = commonmark.listItemSchema.type(ctx2);
2510
+ commands.call(commonmark.wrapInBlockTypeCommand.key, {
2511
+ nodeType: listItem,
2512
+ attrs: { checked: false }
2513
+ });
2514
+ }
2515
+ });
2516
+ const insertGroup = groupBuilder.addGroup("insert", "Insert");
2517
+ insertGroup.addItem("link", {
2518
+ icon: (_h = config == null ? void 0 : config.linkIcon) != null ? _h : linkIcon,
2519
+ active: (ctx2) => isMarkActive(ctx2, commonmark.linkSchema.type(ctx2)),
2520
+ onRun: (ctx2) => {
2521
+ const view = ctx2.get(core.editorViewCtx);
2522
+ const { state } = view;
2523
+ const markType = commonmark.linkSchema.type(ctx2);
2524
+ if (state.selection.empty && isMarkActive(ctx2, markType)) {
2525
+ view.dispatch(state.tr.removeStoredMark(markType));
2526
+ return;
2527
+ }
2528
+ const commands = ctx2.get(core.commandsCtx);
2529
+ commands.call(linkTooltip$1.toggleLinkCommand.key);
2530
+ }
2531
+ });
2532
+ if (isImageBlockEnabled) {
2533
+ insertGroup.addItem("image", {
2534
+ icon: (_i = config == null ? void 0 : config.imageIcon) != null ? _i : imageIcon,
2535
+ active: () => false,
2536
+ onRun: (ctx2) => {
2537
+ const commands = ctx2.get(core.commandsCtx);
2538
+ const imageBlock = imageBlock$1.imageBlockSchema.type(ctx2);
2539
+ commands.call(commonmark.addBlockTypeCommand.key, { nodeType: imageBlock });
2540
+ }
2541
+ });
2542
+ }
2543
+ if (isTableEnabled) {
2544
+ insertGroup.addItem("table", {
2545
+ icon: (_j = config == null ? void 0 : config.tableIcon) != null ? _j : tableIcon,
2546
+ active: () => false,
2547
+ onRun: (ctx2) => {
2548
+ const commands = ctx2.get(core.commandsCtx);
2549
+ const view = ctx2.get(core.editorViewCtx);
2550
+ const { from } = view.state.selection;
2551
+ commands.call(commonmark.addBlockTypeCommand.key, {
2552
+ nodeType: gfm.createTable(ctx2, 3, 3)
2553
+ });
2554
+ commands.call(commonmark.selectTextNearPosCommand.key, { pos: from });
2555
+ }
2556
+ });
2557
+ }
2558
+ const blockGroup = groupBuilder.addGroup("block", "Block");
2559
+ blockGroup.addItem("code-block", {
2560
+ icon: (_k = config == null ? void 0 : config.codeBlockIcon) != null ? _k : codeBlockIcon,
2561
+ active: () => false,
2562
+ onRun: (ctx2) => {
2563
+ const commands = ctx2.get(core.commandsCtx);
2564
+ const codeBlock = commonmark.codeBlockSchema.type(ctx2);
2565
+ commands.call(commonmark.setBlockTypeCommand.key, { nodeType: codeBlock });
2566
+ }
2567
+ });
2568
+ if (isLatexEnabled) {
2569
+ blockGroup.addItem("math", {
2570
+ icon: (_l = config == null ? void 0 : config.mathIcon) != null ? _l : functionsIcon,
2571
+ active: () => false,
2572
+ onRun: (ctx2) => {
2573
+ const commands = ctx2.get(core.commandsCtx);
2574
+ const codeBlock = commonmark.codeBlockSchema.type(ctx2);
2575
+ commands.call(commonmark.addBlockTypeCommand.key, {
2576
+ nodeType: codeBlock,
2577
+ attrs: { language: "LaTeX" }
2578
+ });
2579
+ }
2580
+ });
2581
+ }
2582
+ groupBuilder.addGroup("more", "More").addItem("quote", {
2583
+ icon: (_m = config == null ? void 0 : config.quoteIcon) != null ? _m : quoteIcon,
2584
+ active: () => false,
2585
+ onRun: (ctx2) => {
2586
+ const commands = ctx2.get(core.commandsCtx);
2587
+ const blockquote = commonmark.blockquoteSchema.type(ctx2);
2588
+ commands.call(commonmark.wrapInBlockTypeCommand.key, { nodeType: blockquote });
2589
+ }
2590
+ }).addItem("hr", {
2591
+ icon: (_n = config == null ? void 0 : config.hrIcon) != null ? _n : dividerIcon,
2592
+ active: () => false,
2593
+ onRun: (ctx2) => {
2594
+ const commands = ctx2.get(core.commandsCtx);
2595
+ const hr = commonmark.hrSchema.type(ctx2);
2596
+ commands.call(commonmark.addBlockTypeCommand.key, { nodeType: hr });
2597
+ }
2598
+ });
2599
+ (_o = config == null ? void 0 : config.buildTopBar) == null ? void 0 : _o.call(config, groupBuilder);
2600
+ return groupBuilder.build();
2601
+ }
2602
+
2603
+ keepAlive(vue.h, vue.Fragment);
2604
+ const TopBar = vue.defineComponent({
2605
+ props: {
2606
+ ctx: {
2607
+ type: Object,
2608
+ required: true
2609
+ },
2610
+ version: {
2611
+ type: Object,
2612
+ required: true
2613
+ },
2614
+ config: {
2615
+ type: Object,
2616
+ required: false
2617
+ }
2618
+ },
2619
+ setup(props) {
2620
+ const { ctx, config } = props;
2621
+ const openSelectorKey = vue.ref(null);
2622
+ const onClick = (fn) => (e) => {
2623
+ e.preventDefault();
2624
+ if (ctx) {
2625
+ fn(ctx);
2626
+ }
2627
+ };
2628
+ function isReady() {
2629
+ const status = ctx.get(core.editorCtx).status;
2630
+ return status === core.EditorStatus.Created;
2631
+ }
2632
+ function subscribeState() {
2633
+ keepAlive(props.version.value);
2634
+ }
2635
+ function checkActive(checker) {
2636
+ subscribeState();
2637
+ if (!isReady()) return false;
2638
+ return checker(ctx);
2639
+ }
2640
+ function getSelectorLabel(selector) {
2641
+ var _a, _b;
2642
+ subscribeState();
2643
+ if (!isReady()) return (_b = (_a = selector.options[0]) == null ? void 0 : _a.label) != null ? _b : "";
2644
+ return selector.activeLabel(ctx);
2645
+ }
2646
+ function onToggleSelector(key, e) {
2647
+ e.preventDefault();
2648
+ e.stopPropagation();
2649
+ openSelectorKey.value = openSelectorKey.value === key ? null : key;
2650
+ }
2651
+ const clickOutsideHandler = (e) => {
2652
+ const target = e.target;
2653
+ if (target.closest(".top-bar-heading-selector")) return;
2654
+ openSelectorKey.value = null;
2655
+ };
2656
+ vue.onMounted(() => {
2657
+ window.addEventListener("pointerdown", clickOutsideHandler);
2658
+ });
2659
+ vue.onUnmounted(() => {
2660
+ window.removeEventListener("pointerdown", clickOutsideHandler);
2661
+ });
2662
+ const groupInfo = vue.computed(() => getGroups(config, ctx));
2663
+ function renderSelector(itemKey, selector) {
2664
+ const isOpen = openSelectorKey.value === itemKey;
2665
+ const activeLabel = getSelectorLabel(selector);
2666
+ return /* @__PURE__ */ vue.h("div", { key: itemKey, class: "top-bar-heading-selector" }, /* @__PURE__ */ vue.h(
2667
+ "button",
2668
+ {
2669
+ type: "button",
2670
+ class: "top-bar-heading-button",
2671
+ onPointerdown: (e) => onToggleSelector(itemKey, e)
2672
+ },
2673
+ /* @__PURE__ */ vue.h("span", { class: "top-bar-heading-label" }, activeLabel),
2674
+ selector.chevronIcon && /* @__PURE__ */ vue.h("span", { class: "top-bar-chevron" }, /* @__PURE__ */ vue.h(component.Icon, { icon: selector.chevronIcon }))
2675
+ ), isOpen && /* @__PURE__ */ vue.h("div", { class: "top-bar-heading-dropdown" }, selector.options.map((option, index) => /* @__PURE__ */ vue.h(
2676
+ "button",
2677
+ {
2678
+ key: `${itemKey}-${index}`,
2679
+ type: "button",
2680
+ class: clsx(
2681
+ "top-bar-heading-option",
2682
+ activeLabel === option.label && "active"
2683
+ ),
2684
+ onPointerdown: (e) => {
2685
+ e.preventDefault();
2686
+ e.stopPropagation();
2687
+ openSelectorKey.value = null;
2688
+ option.onSelect(ctx);
2689
+ }
2690
+ },
2691
+ option.label
2692
+ ))));
2693
+ }
2694
+ function renderButton(item) {
2695
+ return /* @__PURE__ */ vue.h(
2696
+ "button",
2697
+ {
2698
+ key: item.key,
2699
+ type: "button",
2700
+ class: clsx("top-bar-item", checkActive(item.active) && "active"),
2701
+ onPointerdown: onClick(item.onRun)
2702
+ },
2703
+ /* @__PURE__ */ vue.h(component.Icon, { icon: item.icon })
2704
+ );
2705
+ }
2706
+ return () => {
2707
+ const view = isReady() ? ctx.get(core.editorViewCtx) : null;
2708
+ const isReadonly = view ? !view.editable : false;
2709
+ if (isReadonly) return null;
2710
+ return /* @__PURE__ */ vue.h("div", { class: "top-bar-inner" }, groupInfo.value.map((group) => {
2711
+ return group.items.map((item) => {
2712
+ if (item.selector) {
2713
+ return renderSelector(item.key, item.selector);
2714
+ }
2715
+ if (!item.onRun) return null;
2716
+ return renderButton(
2717
+ item
2718
+ );
2719
+ });
2720
+ }).reduce((acc, curr, index) => {
2721
+ var _a, _b;
2722
+ if (index === 0) {
2723
+ acc.push(...curr);
2724
+ } else {
2725
+ const groupKey = (_b = (_a = groupInfo.value[index]) == null ? void 0 : _a.key) != null ? _b : index;
2726
+ acc.push(
2727
+ /* @__PURE__ */ vue.h("div", { key: `divider-${groupKey}`, class: "top-bar-divider" }),
2728
+ ...curr
2729
+ );
2730
+ }
2731
+ return acc;
2732
+ }, []));
2733
+ };
2734
+ }
2735
+ });
2736
+
2737
+ var __typeError$1 = (msg) => {
2738
+ throw TypeError(msg);
2739
+ };
2740
+ var __accessCheck$1 = (obj, member, msg) => member.has(obj) || __typeError$1("Cannot " + msg);
2741
+ var __privateGet$1 = (obj, member, getter) => (__accessCheck$1(obj, member, "read from private field"), getter ? getter.call(obj) : member.get(obj));
2742
+ var __privateAdd$1 = (obj, member, value) => member.has(obj) ? __typeError$1("Cannot add the same private member more than once") : member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
2743
+ var __privateSet$1 = (obj, member, value, setter) => (__accessCheck$1(obj, member, "write to private field"), member.set(obj, value), value);
2744
+ var _container, _app, _version;
2745
+ const topBarPluginKey = new state.PluginKey("CREPE_TOP_BAR");
2746
+ class TopBarView {
2747
+ constructor(ctx, view, config) {
2748
+ __privateAdd$1(this, _container);
2749
+ __privateAdd$1(this, _app);
2750
+ __privateAdd$1(this, _version);
2751
+ this.update = (view, _prevState) => {
2752
+ __privateGet$1(this, _container).style.display = view.editable ? "" : "none";
2753
+ __privateGet$1(this, _version).value++;
2754
+ };
2755
+ this.destroy = () => {
2756
+ __privateGet$1(this, _app).unmount();
2757
+ __privateGet$1(this, _container).remove();
2758
+ };
2759
+ __privateSet$1(this, _version, vue.ref(0));
2760
+ const container = document.createElement("div");
2761
+ container.className = "milkdown-top-bar";
2762
+ const app = vue.createApp(TopBar, {
2763
+ ctx,
2764
+ config,
2765
+ version: __privateGet$1(this, _version)
2766
+ });
2767
+ app.mount(container);
2768
+ __privateSet$1(this, _container, container);
2769
+ __privateSet$1(this, _app, app);
2770
+ const editorRoot = view.dom.parentElement;
2771
+ if (editorRoot) {
2772
+ editorRoot.insertBefore(container, editorRoot.firstChild);
2773
+ }
2774
+ this.update(view);
2775
+ }
2776
+ }
2777
+ _container = new WeakMap();
2778
+ _app = new WeakMap();
2779
+ _version = new WeakMap();
2780
+ const topBarSlice = utils.$ctx(
2781
+ {
2782
+ view: () => ({
2783
+ update: () => {
2784
+ },
2785
+ destroy: () => {
2786
+ }
2787
+ })
2788
+ },
2789
+ "topBarConfig"
2790
+ );
2791
+ const topBarPlugin = utils.$prose((ctx) => {
2792
+ const config = ctx.get(topBarSlice.key);
2793
+ return new state.Plugin({
2794
+ key: topBarPluginKey,
2795
+ view: config.view
2796
+ });
2797
+ });
2798
+ const topBar = (editor, config) => {
2799
+ editor.config(crepeFeatureConfig(CrepeFeature.TopBar)).config((ctx) => {
2800
+ ctx.set(topBarSlice.key, {
2801
+ view: (view) => new TopBarView(ctx, view, config)
2802
+ });
2803
+ }).use(topBarSlice).use(topBarPlugin);
2804
+ };
2805
+
2343
2806
  function loadFeature(feature, editor, config) {
2344
2807
  switch (feature) {
2345
2808
  case CrepeFeature.CodeMirror: {
@@ -2372,6 +2835,9 @@ function loadFeature(feature, editor, config) {
2372
2835
  case CrepeFeature.Latex: {
2373
2836
  return latex(editor, config);
2374
2837
  }
2838
+ case CrepeFeature.TopBar: {
2839
+ return topBar(editor, config);
2840
+ }
2375
2841
  }
2376
2842
  }
2377
2843
 
@@ -2453,7 +2919,29 @@ class CrepeBuilder {
2453
2919
  ...value,
2454
2920
  size: 4
2455
2921
  }));
2456
- }).use(commonmark.commonmark).use(listener.listener).use(history$1.history).use(indent.indent).use(trailing.trailing).use(clipboard.clipboard).use(gfm.gfm));
2922
+ ctx.update(upload.uploadConfig.key, (prev) => ({
2923
+ ...prev,
2924
+ uploader: async (files, schema, ctx2) => {
2925
+ const features = useCrepeFeatures(ctx2).get();
2926
+ const hasImageBlock = features.includes(CrepeFeature.ImageBlock);
2927
+ const nodeType = hasImageBlock ? schema.nodes["image-block"] : schema.nodes["image"];
2928
+ if (!nodeType) return [];
2929
+ const onUpload = hasImageBlock ? ctx2.get(imageBlock$1.imageBlockConfig.key).onUpload : void 0;
2930
+ const images = [];
2931
+ for (let i = 0; i < files.length; i++) {
2932
+ const file = files.item(i);
2933
+ if (file && file.type.includes("image")) images.push(file);
2934
+ }
2935
+ const nodes = await Promise.all(
2936
+ images.map(async (file) => {
2937
+ const src = onUpload ? await onUpload(file) : URL.createObjectURL(file);
2938
+ return nodeType.createAndFill({ src });
2939
+ })
2940
+ );
2941
+ return nodes;
2942
+ }
2943
+ }));
2944
+ }).use(commonmark.commonmark).use(listener.listener).use(history$1.history).use(indent.indent).use(trailing.trailing).use(clipboard.clipboard).use(upload.upload).use(gfm.gfm));
2457
2945
  }
2458
2946
  /// Get the milkdown editor instance.
2459
2947
  get editor() {