@jvs-milkdown/crepe 1.2.16 → 1.2.17
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/feature/block-edit/index.js +35 -16
- package/lib/cjs/feature/block-edit/index.js.map +1 -1
- package/lib/cjs/feature/toolbar/index.js +47 -16
- package/lib/cjs/feature/toolbar/index.js.map +1 -1
- package/lib/cjs/index.js +210 -39
- package/lib/cjs/index.js.map +1 -1
- package/lib/esm/feature/block-edit/index.js +36 -17
- package/lib/esm/feature/block-edit/index.js.map +1 -1
- package/lib/esm/feature/toolbar/index.js +48 -17
- package/lib/esm/feature/toolbar/index.js.map +1 -1
- package/lib/esm/index.js +211 -40
- package/lib/esm/index.js.map +1 -1
- package/lib/tsconfig.tsbuildinfo +1 -1
- package/lib/types/feature/block-edit/menu/component.d.ts.map +1 -1
- package/lib/types/feature/fixed-toolbar/outline-panel.d.ts.map +1 -1
- package/lib/types/feature/toolbar/component.d.ts.map +1 -1
- package/package.json +4 -4
- package/src/feature/block-edit/menu/component.tsx +41 -17
- package/src/feature/fixed-toolbar/outline-panel.tsx +219 -32
- package/src/feature/toolbar/component.tsx +19 -0
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { commandsCtx, editorViewCtx, editorCtx, EditorStatus, editorViewOptionsCtx } from '@jvs-milkdown/kit/core';
|
|
1
|
+
import { commandsCtx, editorViewCtx, schemaCtx, editorCtx, EditorStatus, editorViewOptionsCtx } from '@jvs-milkdown/kit/core';
|
|
2
2
|
import { tooltipFactory, TooltipProvider } from '@jvs-milkdown/kit/plugin/tooltip';
|
|
3
3
|
import { NodeSelection, TextSelection, Plugin, PluginKey, AllSelection } from '@jvs-milkdown/kit/prose/state';
|
|
4
4
|
import { defineComponent, ref, computed, watch, watchEffect, onUnmounted, h, Fragment, onMounted, shallowRef, createApp } from 'vue';
|
|
@@ -2571,27 +2571,39 @@ defineComponent({
|
|
|
2571
2571
|
let activeTextColor = null;
|
|
2572
2572
|
let activeBgColor = null;
|
|
2573
2573
|
if (node && node.nodeSize > 2) {
|
|
2574
|
-
|
|
2575
|
-
|
|
2576
|
-
|
|
2577
|
-
|
|
2578
|
-
|
|
2579
|
-
|
|
2580
|
-
if (
|
|
2581
|
-
|
|
2582
|
-
|
|
2583
|
-
|
|
2584
|
-
|
|
2574
|
+
const schema = ctx.get(schemaCtx);
|
|
2575
|
+
const tcHasMark = schema.marks[textColorSchema.id];
|
|
2576
|
+
const bcHasMark = schema.marks[bgColorSchema.id];
|
|
2577
|
+
if (tcHasMark || bcHasMark) {
|
|
2578
|
+
node.descendants((childNode) => {
|
|
2579
|
+
if (childNode.isText) {
|
|
2580
|
+
if (tcHasMark && !activeTextColor) {
|
|
2581
|
+
const tcType = textColorSchema.type(ctx);
|
|
2582
|
+
const tcMark = childNode.marks.find(
|
|
2583
|
+
(m) => m.type === tcType
|
|
2584
|
+
);
|
|
2585
|
+
if (tcMark) activeTextColor = tcMark.attrs.color;
|
|
2586
|
+
}
|
|
2587
|
+
if (bcHasMark && !activeBgColor) {
|
|
2588
|
+
const bcType = bgColorSchema.type(ctx);
|
|
2589
|
+
const bcMark = childNode.marks.find(
|
|
2590
|
+
(m) => m.type === bcType
|
|
2591
|
+
);
|
|
2592
|
+
if (bcMark) activeBgColor = bcMark.attrs.color;
|
|
2593
|
+
}
|
|
2585
2594
|
}
|
|
2586
|
-
|
|
2587
|
-
|
|
2588
|
-
}
|
|
2595
|
+
return false;
|
|
2596
|
+
});
|
|
2597
|
+
}
|
|
2589
2598
|
}
|
|
2590
2599
|
const setBlockColor = (colorValue, isBg) => {
|
|
2591
2600
|
if (pos === null || pos === void 0) return;
|
|
2592
2601
|
const { tr } = view.state;
|
|
2593
2602
|
const targetNode = tr.doc.nodeAt(pos);
|
|
2594
2603
|
if (!targetNode) return;
|
|
2604
|
+
const schema = ctx.get(schemaCtx);
|
|
2605
|
+
const hasMark = isBg ? schema.marks[bgColorSchema.id] : schema.marks[textColorSchema.id];
|
|
2606
|
+
if (!hasMark) return;
|
|
2595
2607
|
const markType = isBg ? bgColorSchema.type(ctx) : textColorSchema.type(ctx);
|
|
2596
2608
|
const start = pos + 1;
|
|
2597
2609
|
const end = pos + targetNode.nodeSize - 1;
|
|
@@ -2610,10 +2622,17 @@ defineComponent({
|
|
|
2610
2622
|
const { tr } = view.state;
|
|
2611
2623
|
const targetNode = tr.doc.nodeAt(pos);
|
|
2612
2624
|
if (!targetNode) return;
|
|
2625
|
+
const schema = ctx.get(schemaCtx);
|
|
2626
|
+
const tcHasMark = schema.marks[textColorSchema.id];
|
|
2627
|
+
const bcHasMark = schema.marks[bgColorSchema.id];
|
|
2613
2628
|
const start = pos + 1;
|
|
2614
2629
|
const end = pos + targetNode.nodeSize - 1;
|
|
2615
|
-
|
|
2616
|
-
|
|
2630
|
+
if (tcHasMark) {
|
|
2631
|
+
tr.removeMark(start, end, textColorSchema.type(ctx));
|
|
2632
|
+
}
|
|
2633
|
+
if (bcHasMark) {
|
|
2634
|
+
tr.removeMark(start, end, bgColorSchema.type(ctx));
|
|
2635
|
+
}
|
|
2617
2636
|
view.dispatch(tr);
|
|
2618
2637
|
showColorMenu.value = false;
|
|
2619
2638
|
hide();
|
|
@@ -4893,6 +4912,10 @@ const Toolbar = defineComponent({
|
|
|
4893
4912
|
return { textColor: null, bgColor: null };
|
|
4894
4913
|
const view = ctx.get(editorViewCtx);
|
|
4895
4914
|
const { state } = view;
|
|
4915
|
+
const schema = ctx.get(schemaCtx);
|
|
4916
|
+
const tcHasMark = schema.marks[textColorSchema.id];
|
|
4917
|
+
const bcHasMark = schema.marks[bgColorSchema.id];
|
|
4918
|
+
if (!tcHasMark || !bcHasMark) return { textColor: null, bgColor: null };
|
|
4896
4919
|
const tcType = textColorSchema.type(ctx);
|
|
4897
4920
|
const bcType = bgColorSchema.type(ctx);
|
|
4898
4921
|
const { $cursor, ranges } = state.selection;
|
|
@@ -4937,6 +4960,10 @@ const Toolbar = defineComponent({
|
|
|
4937
4960
|
const { state, dispatch } = view;
|
|
4938
4961
|
const { tr } = state;
|
|
4939
4962
|
const { from, to, empty } = state.selection;
|
|
4963
|
+
const schema = ctx.get(schemaCtx);
|
|
4964
|
+
const tcHasMark = schema.marks[textColorSchema.id];
|
|
4965
|
+
const bcHasMark = schema.marks[bgColorSchema.id];
|
|
4966
|
+
if (!tcHasMark || !bcHasMark) return;
|
|
4940
4967
|
const textColorType = textColorSchema.type(ctx);
|
|
4941
4968
|
const bgColorType = bgColorSchema.type(ctx);
|
|
4942
4969
|
if (empty) {
|
|
@@ -4958,6 +4985,10 @@ const Toolbar = defineComponent({
|
|
|
4958
4985
|
return { fontFamily: null, fontSize: null };
|
|
4959
4986
|
const view = ctx.get(editorViewCtx);
|
|
4960
4987
|
const { state } = view;
|
|
4988
|
+
const schema = ctx.get(schemaCtx);
|
|
4989
|
+
const ffHasMark = schema.marks[fontFamilySchema.id];
|
|
4990
|
+
const fsHasMark = schema.marks[fontSizeSchema.id];
|
|
4991
|
+
if (!ffHasMark || !fsHasMark) return { fontFamily: null, fontSize: null };
|
|
4961
4992
|
const ffType = fontFamilySchema.type(ctx);
|
|
4962
4993
|
const fsType = fontSizeSchema.type(ctx);
|
|
4963
4994
|
const { $cursor, ranges } = state.selection;
|