@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.
@@ -2393,27 +2393,39 @@ const Menu = vue.defineComponent({
2393
2393
  let activeTextColor = null;
2394
2394
  let activeBgColor = null;
2395
2395
  if (node && node.nodeSize > 2) {
2396
- node.descendants((childNode) => {
2397
- if (childNode.isText) {
2398
- const tcType = textColorSchema.type(ctx);
2399
- const bcType = bgColorSchema.type(ctx);
2400
- if (!activeTextColor) {
2401
- const tcMark = childNode.marks.find((m) => m.type === tcType);
2402
- if (tcMark) activeTextColor = tcMark.attrs.color;
2403
- }
2404
- if (!activeBgColor) {
2405
- const bcMark = childNode.marks.find((m) => m.type === bcType);
2406
- if (bcMark) activeBgColor = bcMark.attrs.color;
2396
+ const schema = ctx.get(core.schemaCtx);
2397
+ const tcHasMark = schema.marks[textColorSchema.id];
2398
+ const bcHasMark = schema.marks[bgColorSchema.id];
2399
+ if (tcHasMark || bcHasMark) {
2400
+ node.descendants((childNode) => {
2401
+ if (childNode.isText) {
2402
+ if (tcHasMark && !activeTextColor) {
2403
+ const tcType = textColorSchema.type(ctx);
2404
+ const tcMark = childNode.marks.find(
2405
+ (m) => m.type === tcType
2406
+ );
2407
+ if (tcMark) activeTextColor = tcMark.attrs.color;
2408
+ }
2409
+ if (bcHasMark && !activeBgColor) {
2410
+ const bcType = bgColorSchema.type(ctx);
2411
+ const bcMark = childNode.marks.find(
2412
+ (m) => m.type === bcType
2413
+ );
2414
+ if (bcMark) activeBgColor = bcMark.attrs.color;
2415
+ }
2407
2416
  }
2408
- }
2409
- return false;
2410
- });
2417
+ return false;
2418
+ });
2419
+ }
2411
2420
  }
2412
2421
  const setBlockColor = (colorValue, isBg) => {
2413
2422
  if (pos === null || pos === void 0) return;
2414
2423
  const { tr } = view.state;
2415
2424
  const targetNode = tr.doc.nodeAt(pos);
2416
2425
  if (!targetNode) return;
2426
+ const schema = ctx.get(core.schemaCtx);
2427
+ const hasMark = isBg ? schema.marks[bgColorSchema.id] : schema.marks[textColorSchema.id];
2428
+ if (!hasMark) return;
2417
2429
  const markType = isBg ? bgColorSchema.type(ctx) : textColorSchema.type(ctx);
2418
2430
  const start = pos + 1;
2419
2431
  const end = pos + targetNode.nodeSize - 1;
@@ -2432,10 +2444,17 @@ const Menu = vue.defineComponent({
2432
2444
  const { tr } = view.state;
2433
2445
  const targetNode = tr.doc.nodeAt(pos);
2434
2446
  if (!targetNode) return;
2447
+ const schema = ctx.get(core.schemaCtx);
2448
+ const tcHasMark = schema.marks[textColorSchema.id];
2449
+ const bcHasMark = schema.marks[bgColorSchema.id];
2435
2450
  const start = pos + 1;
2436
2451
  const end = pos + targetNode.nodeSize - 1;
2437
- tr.removeMark(start, end, textColorSchema.type(ctx));
2438
- tr.removeMark(start, end, bgColorSchema.type(ctx));
2452
+ if (tcHasMark) {
2453
+ tr.removeMark(start, end, textColorSchema.type(ctx));
2454
+ }
2455
+ if (bcHasMark) {
2456
+ tr.removeMark(start, end, bgColorSchema.type(ctx));
2457
+ }
2439
2458
  view.dispatch(tr);
2440
2459
  showColorMenu.value = false;
2441
2460
  hide();