@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,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
|
-
|
|
2395
|
-
|
|
2396
|
-
|
|
2397
|
-
|
|
2398
|
-
|
|
2399
|
-
|
|
2400
|
-
if (
|
|
2401
|
-
|
|
2402
|
-
|
|
2403
|
-
|
|
2404
|
-
|
|
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
|
-
|
|
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
|
-
|
|
2436
|
-
|
|
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();
|