@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
|
@@ -2573,27 +2573,39 @@ vue.defineComponent({
|
|
|
2573
2573
|
let activeTextColor = null;
|
|
2574
2574
|
let activeBgColor = null;
|
|
2575
2575
|
if (node && node.nodeSize > 2) {
|
|
2576
|
-
|
|
2577
|
-
|
|
2578
|
-
|
|
2579
|
-
|
|
2580
|
-
|
|
2581
|
-
|
|
2582
|
-
if (
|
|
2583
|
-
|
|
2584
|
-
|
|
2585
|
-
|
|
2586
|
-
|
|
2576
|
+
const schema = ctx.get(core.schemaCtx);
|
|
2577
|
+
const tcHasMark = schema.marks[textColorSchema.id];
|
|
2578
|
+
const bcHasMark = schema.marks[bgColorSchema.id];
|
|
2579
|
+
if (tcHasMark || bcHasMark) {
|
|
2580
|
+
node.descendants((childNode) => {
|
|
2581
|
+
if (childNode.isText) {
|
|
2582
|
+
if (tcHasMark && !activeTextColor) {
|
|
2583
|
+
const tcType = textColorSchema.type(ctx);
|
|
2584
|
+
const tcMark = childNode.marks.find(
|
|
2585
|
+
(m) => m.type === tcType
|
|
2586
|
+
);
|
|
2587
|
+
if (tcMark) activeTextColor = tcMark.attrs.color;
|
|
2588
|
+
}
|
|
2589
|
+
if (bcHasMark && !activeBgColor) {
|
|
2590
|
+
const bcType = bgColorSchema.type(ctx);
|
|
2591
|
+
const bcMark = childNode.marks.find(
|
|
2592
|
+
(m) => m.type === bcType
|
|
2593
|
+
);
|
|
2594
|
+
if (bcMark) activeBgColor = bcMark.attrs.color;
|
|
2595
|
+
}
|
|
2587
2596
|
}
|
|
2588
|
-
|
|
2589
|
-
|
|
2590
|
-
}
|
|
2597
|
+
return false;
|
|
2598
|
+
});
|
|
2599
|
+
}
|
|
2591
2600
|
}
|
|
2592
2601
|
const setBlockColor = (colorValue, isBg) => {
|
|
2593
2602
|
if (pos === null || pos === void 0) return;
|
|
2594
2603
|
const { tr } = view.state;
|
|
2595
2604
|
const targetNode = tr.doc.nodeAt(pos);
|
|
2596
2605
|
if (!targetNode) return;
|
|
2606
|
+
const schema = ctx.get(core.schemaCtx);
|
|
2607
|
+
const hasMark = isBg ? schema.marks[bgColorSchema.id] : schema.marks[textColorSchema.id];
|
|
2608
|
+
if (!hasMark) return;
|
|
2597
2609
|
const markType = isBg ? bgColorSchema.type(ctx) : textColorSchema.type(ctx);
|
|
2598
2610
|
const start = pos + 1;
|
|
2599
2611
|
const end = pos + targetNode.nodeSize - 1;
|
|
@@ -2612,10 +2624,17 @@ vue.defineComponent({
|
|
|
2612
2624
|
const { tr } = view.state;
|
|
2613
2625
|
const targetNode = tr.doc.nodeAt(pos);
|
|
2614
2626
|
if (!targetNode) return;
|
|
2627
|
+
const schema = ctx.get(core.schemaCtx);
|
|
2628
|
+
const tcHasMark = schema.marks[textColorSchema.id];
|
|
2629
|
+
const bcHasMark = schema.marks[bgColorSchema.id];
|
|
2615
2630
|
const start = pos + 1;
|
|
2616
2631
|
const end = pos + targetNode.nodeSize - 1;
|
|
2617
|
-
|
|
2618
|
-
|
|
2632
|
+
if (tcHasMark) {
|
|
2633
|
+
tr.removeMark(start, end, textColorSchema.type(ctx));
|
|
2634
|
+
}
|
|
2635
|
+
if (bcHasMark) {
|
|
2636
|
+
tr.removeMark(start, end, bgColorSchema.type(ctx));
|
|
2637
|
+
}
|
|
2619
2638
|
view.dispatch(tr);
|
|
2620
2639
|
showColorMenu.value = false;
|
|
2621
2640
|
hide();
|
|
@@ -4895,6 +4914,10 @@ const Toolbar = vue.defineComponent({
|
|
|
4895
4914
|
return { textColor: null, bgColor: null };
|
|
4896
4915
|
const view = ctx.get(core.editorViewCtx);
|
|
4897
4916
|
const { state } = view;
|
|
4917
|
+
const schema = ctx.get(core.schemaCtx);
|
|
4918
|
+
const tcHasMark = schema.marks[textColorSchema.id];
|
|
4919
|
+
const bcHasMark = schema.marks[bgColorSchema.id];
|
|
4920
|
+
if (!tcHasMark || !bcHasMark) return { textColor: null, bgColor: null };
|
|
4898
4921
|
const tcType = textColorSchema.type(ctx);
|
|
4899
4922
|
const bcType = bgColorSchema.type(ctx);
|
|
4900
4923
|
const { $cursor, ranges } = state.selection;
|
|
@@ -4939,6 +4962,10 @@ const Toolbar = vue.defineComponent({
|
|
|
4939
4962
|
const { state, dispatch } = view;
|
|
4940
4963
|
const { tr } = state;
|
|
4941
4964
|
const { from, to, empty } = state.selection;
|
|
4965
|
+
const schema = ctx.get(core.schemaCtx);
|
|
4966
|
+
const tcHasMark = schema.marks[textColorSchema.id];
|
|
4967
|
+
const bcHasMark = schema.marks[bgColorSchema.id];
|
|
4968
|
+
if (!tcHasMark || !bcHasMark) return;
|
|
4942
4969
|
const textColorType = textColorSchema.type(ctx);
|
|
4943
4970
|
const bgColorType = bgColorSchema.type(ctx);
|
|
4944
4971
|
if (empty) {
|
|
@@ -4960,6 +4987,10 @@ const Toolbar = vue.defineComponent({
|
|
|
4960
4987
|
return { fontFamily: null, fontSize: null };
|
|
4961
4988
|
const view = ctx.get(core.editorViewCtx);
|
|
4962
4989
|
const { state } = view;
|
|
4990
|
+
const schema = ctx.get(core.schemaCtx);
|
|
4991
|
+
const ffHasMark = schema.marks[fontFamilySchema.id];
|
|
4992
|
+
const fsHasMark = schema.marks[fontSizeSchema.id];
|
|
4993
|
+
if (!ffHasMark || !fsHasMark) return { fontFamily: null, fontSize: null };
|
|
4963
4994
|
const ffType = fontFamilySchema.type(ctx);
|
|
4964
4995
|
const fsType = fontSizeSchema.type(ctx);
|
|
4965
4996
|
const { $cursor, ranges } = state.selection;
|