@jvs-milkdown/crepe 1.2.15 → 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.
@@ -1,6 +1,6 @@
1
1
  import { blockConfig, block, BlockProvider } from '@jvs-milkdown/kit/plugin/block';
2
2
  import { createSlice } from '@jvs-milkdown/kit/ctx';
3
- import { commandsCtx, editorViewCtx } from '@jvs-milkdown/kit/core';
3
+ import { commandsCtx, editorViewCtx, schemaCtx } from '@jvs-milkdown/kit/core';
4
4
  import { findNodeInSelection, findParent } from '@jvs-milkdown/kit/prose';
5
5
  import { NodeSelection, TextSelection } from '@jvs-milkdown/kit/prose/state';
6
6
  import { defineComponent, ref, computed, watch, watchEffect, onUnmounted, h, createApp, Fragment, reactive } from 'vue';
@@ -2391,27 +2391,39 @@ const Menu = defineComponent({
2391
2391
  let activeTextColor = null;
2392
2392
  let activeBgColor = null;
2393
2393
  if (node && node.nodeSize > 2) {
2394
- node.descendants((childNode) => {
2395
- if (childNode.isText) {
2396
- const tcType = textColorSchema.type(ctx);
2397
- const bcType = bgColorSchema.type(ctx);
2398
- if (!activeTextColor) {
2399
- const tcMark = childNode.marks.find((m) => m.type === tcType);
2400
- if (tcMark) activeTextColor = tcMark.attrs.color;
2401
- }
2402
- if (!activeBgColor) {
2403
- const bcMark = childNode.marks.find((m) => m.type === bcType);
2404
- if (bcMark) activeBgColor = bcMark.attrs.color;
2394
+ const schema = ctx.get(schemaCtx);
2395
+ const tcHasMark = schema.marks[textColorSchema.id];
2396
+ const bcHasMark = schema.marks[bgColorSchema.id];
2397
+ if (tcHasMark || bcHasMark) {
2398
+ node.descendants((childNode) => {
2399
+ if (childNode.isText) {
2400
+ if (tcHasMark && !activeTextColor) {
2401
+ const tcType = textColorSchema.type(ctx);
2402
+ const tcMark = childNode.marks.find(
2403
+ (m) => m.type === tcType
2404
+ );
2405
+ if (tcMark) activeTextColor = tcMark.attrs.color;
2406
+ }
2407
+ if (bcHasMark && !activeBgColor) {
2408
+ const bcType = bgColorSchema.type(ctx);
2409
+ const bcMark = childNode.marks.find(
2410
+ (m) => m.type === bcType
2411
+ );
2412
+ if (bcMark) activeBgColor = bcMark.attrs.color;
2413
+ }
2405
2414
  }
2406
- }
2407
- return false;
2408
- });
2415
+ return false;
2416
+ });
2417
+ }
2409
2418
  }
2410
2419
  const setBlockColor = (colorValue, isBg) => {
2411
2420
  if (pos === null || pos === void 0) return;
2412
2421
  const { tr } = view.state;
2413
2422
  const targetNode = tr.doc.nodeAt(pos);
2414
2423
  if (!targetNode) return;
2424
+ const schema = ctx.get(schemaCtx);
2425
+ const hasMark = isBg ? schema.marks[bgColorSchema.id] : schema.marks[textColorSchema.id];
2426
+ if (!hasMark) return;
2415
2427
  const markType = isBg ? bgColorSchema.type(ctx) : textColorSchema.type(ctx);
2416
2428
  const start = pos + 1;
2417
2429
  const end = pos + targetNode.nodeSize - 1;
@@ -2430,10 +2442,17 @@ const Menu = defineComponent({
2430
2442
  const { tr } = view.state;
2431
2443
  const targetNode = tr.doc.nodeAt(pos);
2432
2444
  if (!targetNode) return;
2445
+ const schema = ctx.get(schemaCtx);
2446
+ const tcHasMark = schema.marks[textColorSchema.id];
2447
+ const bcHasMark = schema.marks[bgColorSchema.id];
2433
2448
  const start = pos + 1;
2434
2449
  const end = pos + targetNode.nodeSize - 1;
2435
- tr.removeMark(start, end, textColorSchema.type(ctx));
2436
- tr.removeMark(start, end, bgColorSchema.type(ctx));
2450
+ if (tcHasMark) {
2451
+ tr.removeMark(start, end, textColorSchema.type(ctx));
2452
+ }
2453
+ if (bcHasMark) {
2454
+ tr.removeMark(start, end, bgColorSchema.type(ctx));
2455
+ }
2437
2456
  view.dispatch(tr);
2438
2457
  showColorMenu.value = false;
2439
2458
  hide();