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