@jvs-milkdown/crepe 1.2.13 → 1.2.15
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/builder.js +41 -2
- package/lib/cjs/builder.js.map +1 -1
- package/lib/cjs/feature/block-edit/index.js +9 -2
- package/lib/cjs/feature/block-edit/index.js.map +1 -1
- package/lib/cjs/feature/code-mirror/index.js +9 -2
- package/lib/cjs/feature/code-mirror/index.js.map +1 -1
- package/lib/cjs/feature/cursor/index.js +9 -2
- package/lib/cjs/feature/cursor/index.js.map +1 -1
- package/lib/cjs/feature/image-block/index.js +9 -2
- package/lib/cjs/feature/image-block/index.js.map +1 -1
- package/lib/cjs/feature/inline-diff/index.js +1298 -0
- package/lib/cjs/feature/inline-diff/index.js.map +1 -0
- package/lib/cjs/feature/latex/index.js +9 -2
- package/lib/cjs/feature/latex/index.js.map +1 -1
- package/lib/cjs/feature/link-tooltip/index.js +9 -2
- package/lib/cjs/feature/link-tooltip/index.js.map +1 -1
- package/lib/cjs/feature/list-item/index.js +9 -2
- package/lib/cjs/feature/list-item/index.js.map +1 -1
- package/lib/cjs/feature/placeholder/index.js +9 -2
- package/lib/cjs/feature/placeholder/index.js.map +1 -1
- package/lib/cjs/feature/table/index.js +9 -2
- package/lib/cjs/feature/table/index.js.map +1 -1
- package/lib/cjs/feature/toolbar/index.js +14 -6
- package/lib/cjs/feature/toolbar/index.js.map +1 -1
- package/lib/cjs/index.js +1280 -260
- package/lib/cjs/index.js.map +1 -1
- package/lib/esm/builder.js +41 -2
- package/lib/esm/builder.js.map +1 -1
- package/lib/esm/feature/block-edit/index.js +9 -2
- package/lib/esm/feature/block-edit/index.js.map +1 -1
- package/lib/esm/feature/code-mirror/index.js +9 -2
- package/lib/esm/feature/code-mirror/index.js.map +1 -1
- package/lib/esm/feature/cursor/index.js +9 -2
- package/lib/esm/feature/cursor/index.js.map +1 -1
- package/lib/esm/feature/image-block/index.js +9 -2
- package/lib/esm/feature/image-block/index.js.map +1 -1
- package/lib/esm/feature/inline-diff/index.js +1274 -0
- package/lib/esm/feature/inline-diff/index.js.map +1 -0
- package/lib/esm/feature/latex/index.js +9 -2
- package/lib/esm/feature/latex/index.js.map +1 -1
- package/lib/esm/feature/link-tooltip/index.js +9 -2
- package/lib/esm/feature/link-tooltip/index.js.map +1 -1
- package/lib/esm/feature/list-item/index.js +9 -2
- package/lib/esm/feature/list-item/index.js.map +1 -1
- package/lib/esm/feature/placeholder/index.js +9 -2
- package/lib/esm/feature/placeholder/index.js.map +1 -1
- package/lib/esm/feature/table/index.js +9 -2
- package/lib/esm/feature/table/index.js.map +1 -1
- package/lib/esm/feature/toolbar/index.js +14 -6
- package/lib/esm/feature/toolbar/index.js.map +1 -1
- package/lib/esm/index.js +1262 -261
- package/lib/esm/index.js.map +1 -1
- package/lib/theme/common/diff-block.css +41 -0
- package/lib/theme/common/inline-diff.css +142 -0
- package/lib/theme/common/list-item.css +113 -0
- package/lib/theme/common/style.css +2 -0
- package/lib/tsconfig.tsbuildinfo +1 -1
- package/lib/types/core/builder.d.ts +2 -0
- package/lib/types/core/builder.d.ts.map +1 -1
- package/lib/types/core/locale.d.ts +4 -0
- package/lib/types/core/locale.d.ts.map +1 -1
- package/lib/types/feature/diff-block/index.d.ts +10 -0
- package/lib/types/feature/diff-block/index.d.ts.map +1 -0
- package/lib/types/feature/fixed-toolbar/index.d.ts.map +1 -1
- package/lib/types/feature/fixed-toolbar/outline-panel.d.ts.map +1 -1
- package/lib/types/feature/index.d.ts +7 -1
- package/lib/types/feature/index.d.ts.map +1 -1
- package/lib/types/feature/inline-diff/change-panel.d.ts +4 -0
- package/lib/types/feature/inline-diff/change-panel.d.ts.map +1 -0
- package/lib/types/feature/inline-diff/config.d.ts +12 -0
- package/lib/types/feature/inline-diff/config.d.ts.map +1 -0
- package/lib/types/feature/inline-diff/diff-engine.d.ts +20 -0
- package/lib/types/feature/inline-diff/diff-engine.d.ts.map +1 -0
- package/lib/types/feature/inline-diff/diff-view.d.ts +2 -0
- package/lib/types/feature/inline-diff/diff-view.d.ts.map +1 -0
- package/lib/types/feature/inline-diff/doc-builder.d.ts +21 -0
- package/lib/types/feature/inline-diff/doc-builder.d.ts.map +1 -0
- package/lib/types/feature/inline-diff/index.d.ts +9 -0
- package/lib/types/feature/inline-diff/index.d.ts.map +1 -0
- package/lib/types/feature/loader.d.ts.map +1 -1
- package/lib/types/feature/toolbar/component.d.ts.map +1 -1
- package/package.json +15 -4
- package/src/core/builder.ts +19 -0
- package/src/core/locale.ts +7 -0
- package/src/feature/diff-block/index.ts +48 -0
- package/src/feature/fixed-toolbar/index.ts +62 -23
- package/src/feature/fixed-toolbar/outline-panel.tsx +5 -3
- package/src/feature/index.ts +12 -0
- package/src/feature/inline-diff/change-panel.ts +280 -0
- package/src/feature/inline-diff/config.ts +28 -0
- package/src/feature/inline-diff/diff-engine.ts +181 -0
- package/src/feature/inline-diff/diff-view.ts +2 -0
- package/src/feature/inline-diff/doc-builder.ts +139 -0
- package/src/feature/inline-diff/index.ts +514 -0
- package/src/feature/loader.ts +8 -0
- package/src/feature/toolbar/component.tsx +3 -2
- package/src/theme/common/diff-block.css +43 -0
- package/src/theme/common/inline-diff.css +148 -0
- package/src/theme/common/list-item.css +122 -0
- package/src/theme/common/style.css +2 -0
|
@@ -23,6 +23,8 @@ export declare class CrepeBuilder {
|
|
|
23
23
|
get readonly(): boolean;
|
|
24
24
|
setReadonly: (value: boolean) => this;
|
|
25
25
|
getMarkdown: () => string;
|
|
26
|
+
showDiff: (oldMarkdown: string, newMarkdown: string) => this;
|
|
27
|
+
hideDiff: () => this;
|
|
26
28
|
on: (fn: (api: ListenerManager) => void) => this;
|
|
27
29
|
}
|
|
28
30
|
//# sourceMappingURL=builder.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"builder.d.ts","sourceRoot":"","sources":["../../../src/core/builder.ts"],"names":[],"mappings":"AACA,OAAO,EACL,KAAK,YAAY,EAEjB,MAAM,EAKP,MAAM,wBAAwB,CAAA;AAI/B,OAAO,EAGL,KAAK,eAAe,EACrB,MAAM,mCAAmC,CAAA;AAO1C,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,YAAY,CAAA;AACpD,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAA;AAEtD,OAAO,EAAE,YAAY,EAAE,MAAM,YAAY,CAAA;
|
|
1
|
+
{"version":3,"file":"builder.d.ts","sourceRoot":"","sources":["../../../src/core/builder.ts"],"names":[],"mappings":"AACA,OAAO,EACL,KAAK,YAAY,EAEjB,MAAM,EAKP,MAAM,wBAAwB,CAAA;AAI/B,OAAO,EAGL,KAAK,eAAe,EACrB,MAAM,mCAAmC,CAAA;AAO1C,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,YAAY,CAAA;AACpD,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAA;AAEtD,OAAO,EAAE,YAAY,EAAE,MAAM,YAAY,CAAA;AAGzC,OAAO,EAAc,KAAK,iBAAiB,EAAE,MAAM,UAAU,CAAA;AAU7D,MAAM,WAAW,kBAAkB;IAIjC,IAAI,CAAC,EAAE,IAAI,GAAG,MAAM,GAAG,IAAI,CAAA;IAG3B,YAAY,CAAC,EAAE,YAAY,CAAA;IAG3B,MAAM,CAAC,EAAE,MAAM,CAAA;IAGf,YAAY,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,iBAAiB,CAAC,CAAC,CAAA;CAC1D;AAID,qBAAa,YAAY;;gBAYX,EACV,IAAI,EACJ,YAAiB,EACjB,MAAgB,EAChB,YAAY,GACb,GAAE,kBAAuB;IA0H1B,UAAU,EAAE;QACV,CAAC,CAAC,SAAS,YAAY,EACrB,OAAO,EAAE,aAAa,CAAC,kBAAkB,CAAC,CAAC,CAAC,CAAC,EAC7C,MAAM,CAAC,EAAE,kBAAkB,CAAC,CAAC,CAAC,GAC7B,YAAY,CAAA;QACf,CAAC,CAAC,EAAE,OAAO,EAAE,aAAa,CAAC,CAAC,CAAC,EAAE,MAAM,CAAC,EAAE,CAAC,GAAG,YAAY,CAAA;KACzD,CAGA;IAGD,MAAM,wBAEL;IAGD,OAAO,wBAEN;IAGD,IAAI,MAAM,IAAI,MAAM,CAEnB;IAGD,IAAI,QAAQ,YAEX;IAGD,WAAW,GAAI,OAAO,OAAO,UAW5B;IAGD,WAAW,eAEV;IAGD,QAAQ,GAAI,aAAa,MAAM,EAAE,aAAa,MAAM,UAMnD;IAGD,QAAQ,aAMP;IAGD,EAAE,GAAI,IAAI,CAAC,GAAG,EAAE,eAAe,KAAK,IAAI,UAavC;CACF"}
|
|
@@ -140,6 +140,8 @@ export declare const zhCN: {
|
|
|
140
140
|
'shortcuts.history': string;
|
|
141
141
|
'shortcuts.undo': string;
|
|
142
142
|
'shortcuts.redo': string;
|
|
143
|
+
'inlineDiff.accept': string;
|
|
144
|
+
'inlineDiff.reject': string;
|
|
143
145
|
};
|
|
144
146
|
export declare const enUS: typeof zhCN;
|
|
145
147
|
export type CrepeTranslations = typeof zhCN;
|
|
@@ -284,6 +286,8 @@ export declare const translationsCtx: import("@jvs-milkdown/ctx").SliceType<Reco
|
|
|
284
286
|
'shortcuts.history': string;
|
|
285
287
|
'shortcuts.undo': string;
|
|
286
288
|
'shortcuts.redo': string;
|
|
289
|
+
'inlineDiff.accept': string;
|
|
290
|
+
'inlineDiff.reject': string;
|
|
287
291
|
}>>, string>;
|
|
288
292
|
export declare const localeCtx: import("@jvs-milkdown/ctx").SliceType<string, "localeCtx">;
|
|
289
293
|
export declare function i18n(ctx: Ctx, key: keyof CrepeTranslations): string;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"locale.d.ts","sourceRoot":"","sources":["../../../src/core/locale.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,uBAAuB,CAAA;AAIhD,eAAO,MAAM,IAAI
|
|
1
|
+
{"version":3,"file":"locale.d.ts","sourceRoot":"","sources":["../../../src/core/locale.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,uBAAuB,CAAA;AAIhD,eAAO,MAAM,IAAI;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CA+KhB,CAAA;AAED,eAAO,MAAM,IAAI,EAAE,OAAO,IA+JzB,CAAA;AAED,MAAM,MAAM,iBAAiB,GAAG,OAAO,IAAI,CAAA;AAE3C,eAAO,MAAM,eAAe;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;YAQ3B,CAAA;AAED,eAAO,MAAM,SAAS,4DAAoC,CAAA;AAE1D,wBAAgB,IAAI,CAAC,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,MAAM,iBAAiB,GAAG,MAAM,CASnE"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { Extension } from '@codemirror/state';
|
|
2
|
+
import { type DiffBlockConfig } from '@jvs-milkdown/kit/component/diff-block';
|
|
3
|
+
import type { DefineFeature } from '../shared';
|
|
4
|
+
interface DiffBlockConfigCustom extends Omit<DiffBlockConfig, 'theme'> {
|
|
5
|
+
theme: Extension;
|
|
6
|
+
}
|
|
7
|
+
export type DiffBlockFeatureConfig = Partial<DiffBlockConfigCustom>;
|
|
8
|
+
export declare const diffBlockFeature: DefineFeature<DiffBlockFeatureConfig>;
|
|
9
|
+
export {};
|
|
10
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/feature/diff-block/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,mBAAmB,CAAA;AAGlD,OAAO,EAGL,KAAK,eAAe,EACrB,MAAM,wCAAwC,CAAA;AAG/C,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,WAAW,CAAA;AAK9C,UAAU,qBAAsB,SAAQ,IAAI,CAAC,eAAe,EAAE,OAAO,CAAC;IACpE,KAAK,EAAE,SAAS,CAAA;CACjB;AAED,MAAM,MAAM,sBAAsB,GAAG,OAAO,CAAC,qBAAqB,CAAC,CAAA;AAEnE,eAAO,MAAM,gBAAgB,EAAE,aAAa,CAAC,sBAAsB,CA0BlE,CAAA"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/feature/fixed-toolbar/index.ts"],"names":[],"mappings":"AAIA,OAAO,EAAU,SAAS,EAAiB,MAAM,+BAA+B,CAAA;AAchF,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,aAAa,CAAA;AAC/C,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,WAAW,CAAA;AAC9C,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAA;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/feature/fixed-toolbar/index.ts"],"names":[],"mappings":"AAIA,OAAO,EAAU,SAAS,EAAiB,MAAM,+BAA+B,CAAA;AAchF,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,aAAa,CAAA;AAC/C,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,WAAW,CAAA;AAC9C,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAA;AAYpD,MAAM,WAAW,kBAAkB;IACjC,QAAQ,CAAC,EAAE,MAAM,CAAA;IACjB,QAAQ,CAAC,EAAE,MAAM,CAAA;IACjB,UAAU,CAAC,EAAE,MAAM,CAAA;IACnB,QAAQ,CAAC,EAAE,MAAM,CAAA;IACjB,iBAAiB,CAAC,EAAE,MAAM,CAAA;IAC1B,SAAS,CAAC,EAAE,MAAM,CAAA;IAClB,MAAM,CAAC,EAAE,MAAM,CAAA;IACf,MAAM,CAAC,EAAE,MAAM,CAAA;IACf,MAAM,CAAC,EAAE,MAAM,CAAA;IACf,YAAY,CAAC,EAAE,CAAC,OAAO,EAAE,YAAY,CAAC,WAAW,CAAC,KAAK,IAAI,CAAA;IAC3D,eAAe,CAAC,EAAE,MAAM,GAAG,OAAO,CAAA;IAClC,aAAa,CAAC,EAAE,CAAC,IAAI,EAAE,IAAI,KAAK,OAAO,CAAC,MAAM,CAAC,CAAA;IAC/C,kBAAkB,CAAC,EAAE,MAAM,EAAE,CAAA;CAC9B;AAED,MAAM,MAAM,yBAAyB,GAAG,OAAO,CAAC,kBAAkB,CAAC,CAAA;AAEnE,eAAO,MAAM,kBAAkB,0FAG9B,CAAA;AAED,eAAO,MAAM,eAAe,gBAA0C,CAAA;AAiStE,eAAO,MAAM,kBAAkB,sCAK7B,CAAA;AAEF,eAAO,MAAM,YAAY,EAAE,aAAa,CAAC,yBAAyB,CA6BjE,CAAA"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"outline-panel.d.ts","sourceRoot":"","sources":["../../../../src/feature/fixed-toolbar/outline-panel.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,uBAAuB,CAAA;AAgBhD,eAAO,MAAM,YAAY;;cAEE,MAAM,GAAG;;;;;cAAT,MAAM,GAAG;;;+
|
|
1
|
+
{"version":3,"file":"outline-panel.d.ts","sourceRoot":"","sources":["../../../../src/feature/fixed-toolbar/outline-panel.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,uBAAuB,CAAA;AAgBhD,eAAO,MAAM,YAAY;;cAEE,MAAM,GAAG;;;;;cAAT,MAAM,GAAG;;;+GA+clC,CAAA"}
|
|
@@ -2,8 +2,10 @@ import type { AttachmentFeatureConfig } from './attachment/config';
|
|
|
2
2
|
import type { BlockEditFeatureConfig } from './block-edit';
|
|
3
3
|
import type { CodeMirrorFeatureConfig } from './code-mirror';
|
|
4
4
|
import type { CursorFeatureConfig } from './cursor';
|
|
5
|
+
import type { DiffBlockFeatureConfig } from './diff-block';
|
|
5
6
|
import type { FixedToolbarFeatureConfig } from './fixed-toolbar';
|
|
6
7
|
import type { ImageBlockFeatureConfig } from './image-block';
|
|
8
|
+
import type { InlineDiffFeatureConfig } from './inline-diff';
|
|
7
9
|
import type { LatexFeatureConfig } from './latex';
|
|
8
10
|
import type { LinkTooltipFeatureConfig } from './link-tooltip';
|
|
9
11
|
import type { ListItemFeatureConfig } from './list-item';
|
|
@@ -22,7 +24,9 @@ export declare enum CrepeFeature {
|
|
|
22
24
|
Placeholder = "placeholder",
|
|
23
25
|
Table = "table",
|
|
24
26
|
Latex = "latex",
|
|
25
|
-
Attachment = "attachment"
|
|
27
|
+
Attachment = "attachment",
|
|
28
|
+
InlineDiff = "inline-diff",
|
|
29
|
+
DiffBlock = "diff-block"
|
|
26
30
|
}
|
|
27
31
|
export interface CrepeFeatureConfig {
|
|
28
32
|
[CrepeFeature.Cursor]?: CursorFeatureConfig;
|
|
@@ -37,6 +41,8 @@ export interface CrepeFeatureConfig {
|
|
|
37
41
|
[CrepeFeature.Table]?: TableFeatureConfig;
|
|
38
42
|
[CrepeFeature.Latex]?: LatexFeatureConfig;
|
|
39
43
|
[CrepeFeature.Attachment]?: AttachmentFeatureConfig;
|
|
44
|
+
[CrepeFeature.InlineDiff]?: InlineDiffFeatureConfig;
|
|
45
|
+
[CrepeFeature.DiffBlock]?: DiffBlockFeatureConfig;
|
|
40
46
|
}
|
|
41
47
|
export declare const defaultFeatures: Record<CrepeFeature, boolean>;
|
|
42
48
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/feature/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,qBAAqB,CAAA;AAClE,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,cAAc,CAAA;AAC1D,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,eAAe,CAAA;AAC5D,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,UAAU,CAAA;AACnD,OAAO,KAAK,EAAE,yBAAyB,EAAE,MAAM,iBAAiB,CAAA;AAChE,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,eAAe,CAAA;AAC5D,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,SAAS,CAAA;AACjD,OAAO,KAAK,EAAE,wBAAwB,EAAE,MAAM,gBAAgB,CAAA;AAC9D,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,aAAa,CAAA;AACxD,OAAO,KAAK,EAAE,wBAAwB,EAAE,MAAM,eAAe,CAAA;AAC7D,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,SAAS,CAAA;AACjD,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,WAAW,CAAA;AAKrD,oBAAY,YAAY;IAEtB,UAAU,gBAAgB;IAG1B,QAAQ,cAAc;IAGtB,WAAW,iBAAiB;IAG5B,MAAM,WAAW;IAGjB,UAAU,gBAAgB;IAG1B,SAAS,eAAe;IAGxB,OAAO,YAAY;IAGnB,YAAY,kBAAkB;IAG9B,WAAW,gBAAgB;IAG3B,KAAK,UAAU;IAGf,KAAK,UAAU;IAGf,UAAU,eAAe;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/feature/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,qBAAqB,CAAA;AAClE,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,cAAc,CAAA;AAC1D,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,eAAe,CAAA;AAC5D,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,UAAU,CAAA;AACnD,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,cAAc,CAAA;AAC1D,OAAO,KAAK,EAAE,yBAAyB,EAAE,MAAM,iBAAiB,CAAA;AAChE,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,eAAe,CAAA;AAC5D,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,eAAe,CAAA;AAC5D,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,SAAS,CAAA;AACjD,OAAO,KAAK,EAAE,wBAAwB,EAAE,MAAM,gBAAgB,CAAA;AAC9D,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,aAAa,CAAA;AACxD,OAAO,KAAK,EAAE,wBAAwB,EAAE,MAAM,eAAe,CAAA;AAC7D,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,SAAS,CAAA;AACjD,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,WAAW,CAAA;AAKrD,oBAAY,YAAY;IAEtB,UAAU,gBAAgB;IAG1B,QAAQ,cAAc;IAGtB,WAAW,iBAAiB;IAG5B,MAAM,WAAW;IAGjB,UAAU,gBAAgB;IAG1B,SAAS,eAAe;IAGxB,OAAO,YAAY;IAGnB,YAAY,kBAAkB;IAG9B,WAAW,gBAAgB;IAG3B,KAAK,UAAU;IAGf,KAAK,UAAU;IAGf,UAAU,eAAe;IAGzB,UAAU,gBAAgB;IAG1B,SAAS,eAAe;CACzB;AAED,MAAM,WAAW,kBAAkB;IACjC,CAAC,YAAY,CAAC,MAAM,CAAC,CAAC,EAAE,mBAAmB,CAAA;IAC3C,CAAC,YAAY,CAAC,QAAQ,CAAC,CAAC,EAAE,qBAAqB,CAAA;IAC/C,CAAC,YAAY,CAAC,WAAW,CAAC,CAAC,EAAE,wBAAwB,CAAA;IACrD,CAAC,YAAY,CAAC,UAAU,CAAC,CAAC,EAAE,uBAAuB,CAAA;IACnD,CAAC,YAAY,CAAC,SAAS,CAAC,CAAC,EAAE,sBAAsB,CAAA;IACjD,CAAC,YAAY,CAAC,WAAW,CAAC,CAAC,EAAE,wBAAwB,CAAA;IACrD,CAAC,YAAY,CAAC,OAAO,CAAC,CAAC,EAAE,oBAAoB,CAAA;IAC7C,CAAC,YAAY,CAAC,YAAY,CAAC,CAAC,EAAE,yBAAyB,CAAA;IACvD,CAAC,YAAY,CAAC,UAAU,CAAC,CAAC,EAAE,uBAAuB,CAAA;IACnD,CAAC,YAAY,CAAC,KAAK,CAAC,CAAC,EAAE,kBAAkB,CAAA;IACzC,CAAC,YAAY,CAAC,KAAK,CAAC,CAAC,EAAE,kBAAkB,CAAA;IACzC,CAAC,YAAY,CAAC,UAAU,CAAC,CAAC,EAAE,uBAAuB,CAAA;IACnD,CAAC,YAAY,CAAC,UAAU,CAAC,CAAC,EAAE,uBAAuB,CAAA;IACnD,CAAC,YAAY,CAAC,SAAS,CAAC,CAAC,EAAE,sBAAsB,CAAA;CAClD;AAED,eAAO,MAAM,eAAe,EAAE,MAAM,CAAC,YAAY,EAAE,OAAO,CAezD,CAAA"}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { type App as VueApp } from 'vue';
|
|
2
|
+
import type { ChangeInfo } from './doc-builder';
|
|
3
|
+
export declare function mountChangePanel(container: HTMLElement, changes: ChangeInfo[], onNavigate: (from: number) => void, onClose?: () => void): VueApp;
|
|
4
|
+
//# sourceMappingURL=change-panel.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"change-panel.d.ts","sourceRoot":"","sources":["../../../../src/feature/inline-diff/change-panel.ts"],"names":[],"mappings":"AAAA,OAAO,EAA+B,KAAK,GAAG,IAAI,MAAM,EAAE,MAAM,KAAK,CAAA;AAErE,OAAO,KAAK,EAAE,UAAU,EAAc,MAAM,eAAe,CAAA;AAa3D,wBAAgB,gBAAgB,CAC9B,SAAS,EAAE,WAAW,EACtB,OAAO,EAAE,UAAU,EAAE,EACrB,UAAU,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,IAAI,EAClC,OAAO,CAAC,EAAE,MAAM,IAAI,GACnB,MAAM,CAmQR"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export interface InlineDiffConfig {
|
|
2
|
+
addedClass: string;
|
|
3
|
+
deletedClass: string;
|
|
4
|
+
}
|
|
5
|
+
export interface InlineDiffApi {
|
|
6
|
+
showDiff: (oldMarkdown: string, newMarkdown?: string) => void;
|
|
7
|
+
hideDiff: () => void;
|
|
8
|
+
isShowing: () => boolean;
|
|
9
|
+
}
|
|
10
|
+
export declare const inlineDiffConfig: import("@jvs-milkdown/utils").$Ctx<InlineDiffConfig, "inlineDiffConfigCtx">;
|
|
11
|
+
export declare const inlineDiffApiCtx: import("@jvs-milkdown/utils").$Ctx<InlineDiffApi, "inlineDiffApiCtx">;
|
|
12
|
+
//# sourceMappingURL=config.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../../../../src/feature/inline-diff/config.ts"],"names":[],"mappings":"AAEA,MAAM,WAAW,gBAAgB;IAC/B,UAAU,EAAE,MAAM,CAAA;IAClB,YAAY,EAAE,MAAM,CAAA;CACrB;AAED,MAAM,WAAW,aAAa;IAC5B,QAAQ,EAAE,CAAC,WAAW,EAAE,MAAM,EAAE,WAAW,CAAC,EAAE,MAAM,KAAK,IAAI,CAAA;IAC7D,QAAQ,EAAE,MAAM,IAAI,CAAA;IACpB,SAAS,EAAE,MAAM,OAAO,CAAA;CACzB;AAED,eAAO,MAAM,gBAAgB,6EAM5B,CAAA;AAQD,eAAO,MAAM,gBAAgB,uEAAoC,CAAA"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import type { Node as PMNode } from '@jvs-milkdown/kit/prose/model';
|
|
2
|
+
export type DiffType = 'unchanged' | 'added' | 'removed';
|
|
3
|
+
export interface CharPart {
|
|
4
|
+
type: 'equal' | 'insert' | 'delete';
|
|
5
|
+
value: string;
|
|
6
|
+
}
|
|
7
|
+
export interface BlockDiff {
|
|
8
|
+
type: DiffType;
|
|
9
|
+
oldNode?: PMNode;
|
|
10
|
+
newNode?: PMNode;
|
|
11
|
+
parts?: CharPart[];
|
|
12
|
+
}
|
|
13
|
+
export type ChunkStatus = 'pending' | 'accepted' | 'rejected';
|
|
14
|
+
export interface DiffChunk {
|
|
15
|
+
id: string;
|
|
16
|
+
diffs: BlockDiff[];
|
|
17
|
+
status: ChunkStatus;
|
|
18
|
+
}
|
|
19
|
+
export declare function computeDiff(oldBlocks: PMNode[], newBlocks: PMNode[]): DiffChunk[];
|
|
20
|
+
//# sourceMappingURL=diff-engine.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"diff-engine.d.ts","sourceRoot":"","sources":["../../../../src/feature/inline-diff/diff-engine.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,IAAI,IAAI,MAAM,EAAE,MAAM,+BAA+B,CAAA;AAInE,MAAM,MAAM,QAAQ,GAAG,WAAW,GAAG,OAAO,GAAG,SAAS,CAAA;AAExD,MAAM,WAAW,QAAQ;IACvB,IAAI,EAAE,OAAO,GAAG,QAAQ,GAAG,QAAQ,CAAA;IACnC,KAAK,EAAE,MAAM,CAAA;CACd;AAED,MAAM,WAAW,SAAS;IACxB,IAAI,EAAE,QAAQ,CAAA;IACd,OAAO,CAAC,EAAE,MAAM,CAAA;IAChB,OAAO,CAAC,EAAE,MAAM,CAAA;IAChB,KAAK,CAAC,EAAE,QAAQ,EAAE,CAAA;CACnB;AAED,MAAM,MAAM,WAAW,GAAG,SAAS,GAAG,UAAU,GAAG,UAAU,CAAA;AAE7D,MAAM,WAAW,SAAS;IACxB,EAAE,EAAE,MAAM,CAAA;IACV,KAAK,EAAE,SAAS,EAAE,CAAA;IAClB,MAAM,EAAE,WAAW,CAAA;CACpB;AAyCD,wBAAgB,WAAW,CACzB,SAAS,EAAE,MAAM,EAAE,EACnB,SAAS,EAAE,MAAM,EAAE,GAClB,SAAS,EAAE,CAgHb"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"diff-view.d.ts","sourceRoot":"","sources":["../../../../src/feature/inline-diff/diff-view.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,CAAA"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import type { Schema, Node as PMNode } from '@jvs-milkdown/kit/prose/model';
|
|
2
|
+
import type { DiffChunk } from './diff-engine';
|
|
3
|
+
export type ChangeType = 'added' | 'removed';
|
|
4
|
+
export interface ContentRange {
|
|
5
|
+
from: number;
|
|
6
|
+
to: number;
|
|
7
|
+
}
|
|
8
|
+
export interface ChangeInfo {
|
|
9
|
+
type: ChangeType;
|
|
10
|
+
from: number;
|
|
11
|
+
oldText: string;
|
|
12
|
+
newText: string;
|
|
13
|
+
blockRange: ContentRange;
|
|
14
|
+
inlineRanges: ContentRange[];
|
|
15
|
+
chunkId: string;
|
|
16
|
+
}
|
|
17
|
+
export declare function buildNewDoc(chunks: DiffChunk[], schema: Schema): {
|
|
18
|
+
doc: PMNode;
|
|
19
|
+
changes: ChangeInfo[];
|
|
20
|
+
};
|
|
21
|
+
//# sourceMappingURL=doc-builder.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"doc-builder.d.ts","sourceRoot":"","sources":["../../../../src/feature/inline-diff/doc-builder.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,IAAI,IAAI,MAAM,EAAE,MAAM,+BAA+B,CAAA;AAE3E,OAAO,KAAK,EAAE,SAAS,EAAY,MAAM,eAAe,CAAA;AAExD,MAAM,MAAM,UAAU,GAAG,OAAO,GAAG,SAAS,CAAA;AAE5C,MAAM,WAAW,YAAY;IAC3B,IAAI,EAAE,MAAM,CAAA;IACZ,EAAE,EAAE,MAAM,CAAA;CACX;AAED,MAAM,WAAW,UAAU;IACzB,IAAI,EAAE,UAAU,CAAA;IAChB,IAAI,EAAE,MAAM,CAAA;IACZ,OAAO,EAAE,MAAM,CAAA;IACf,OAAO,EAAE,MAAM,CAAA;IACf,UAAU,EAAE,YAAY,CAAA;IACxB,YAAY,EAAE,YAAY,EAAE,CAAA;IAC5B,OAAO,EAAE,MAAM,CAAA;CAChB;AAWD,wBAAgB,WAAW,CACzB,MAAM,EAAE,SAAS,EAAE,EACnB,MAAM,EAAE,MAAM,GACb;IAAE,GAAG,EAAE,MAAM,CAAC;IAAC,OAAO,EAAE,UAAU,EAAE,CAAA;CAAE,CAyGxC"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { PluginKey } from '@jvs-milkdown/kit/prose/state';
|
|
2
|
+
import type { DefineFeature } from '../shared';
|
|
3
|
+
import { inlineDiffApiCtx, type InlineDiffConfig, type InlineDiffApi } from './config';
|
|
4
|
+
export type InlineDiffFeatureConfig = Partial<InlineDiffConfig>;
|
|
5
|
+
export { inlineDiffApiCtx, type InlineDiffApi };
|
|
6
|
+
export declare const inlineDiffKey: PluginKey<any>;
|
|
7
|
+
export declare const inlineDiffPlugin: import("@jvs-milkdown/utils").$Prose;
|
|
8
|
+
export declare const inlineDiff: DefineFeature<InlineDiffFeatureConfig>;
|
|
9
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/feature/inline-diff/index.ts"],"names":[],"mappings":"AAMA,OAAO,EAAU,SAAS,EAAE,MAAM,+BAA+B,CAAA;AAIjE,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,WAAW,CAAA;AAM9C,OAAO,EAEL,gBAAgB,EAChB,KAAK,gBAAgB,EACrB,KAAK,aAAa,EACnB,MAAM,UAAU,CAAA;AAIjB,MAAM,MAAM,uBAAuB,GAAG,OAAO,CAAC,gBAAgB,CAAC,CAAA;AAE/D,OAAO,EAAE,gBAAgB,EAAE,KAAK,aAAa,EAAE,CAAA;AAE/C,eAAO,MAAM,aAAa,gBAAqC,CAAA;AAyc/D,eAAO,MAAM,gBAAgB,sCAQ3B,CAAA;AAEF,eAAO,MAAM,UAAU,EAAE,aAAa,CAAC,uBAAuB,CAiB7D,CAAA"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"loader.d.ts","sourceRoot":"","sources":["../../../src/feature/loader.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,wBAAwB,CAAA;
|
|
1
|
+
{"version":3,"file":"loader.d.ts","sourceRoot":"","sources":["../../../src/feature/loader.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,wBAAwB,CAAA;AASpD,OAAO,EAAE,YAAY,EAAE,MAAM,SAAS,CAAA;AAStC,wBAAgB,WAAW,CACzB,OAAO,EAAE,YAAY,EACrB,MAAM,EAAE,MAAM,EACd,MAAM,CAAC,EAAE,KAAK,QA8Cf"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"component.d.ts","sourceRoot":"","sources":["../../../../src/feature/toolbar/component.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,uBAAuB,CAAA;AAehD,OAAO,EACL,KAAK,SAAS,EAGf,MAAM,+BAA+B,CAAA;AAUtC,OAAO,EAEL,KAAK,GAAG,EACR,KAAK,UAAU,EAQhB,MAAM,KAAK,CAAA;AAEZ,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,GAAG,CAAA;AAmG7C,KAAK,YAAY,GAAG;IAClB,GAAG,EAAE,GAAG,CAAA;IACR,IAAI,EAAE,MAAM,IAAI,CAAA;IAChB,IAAI,EAAE,GAAG,CAAC,OAAO,CAAC,CAAA;IAClB,SAAS,EAAE,UAAU,CAAC,SAAS,CAAC,CAAA;IAChC,MAAM,CAAC,EAAE,oBAAoB,CAAA;IAC7B,OAAO,CAAC,EAAE,OAAO,CAAA;CAClB,CAAA;AAeD,eAAO,MAAM,OAAO,
|
|
1
|
+
{"version":3,"file":"component.d.ts","sourceRoot":"","sources":["../../../../src/feature/toolbar/component.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,uBAAuB,CAAA;AAehD,OAAO,EACL,KAAK,SAAS,EAGf,MAAM,+BAA+B,CAAA;AAUtC,OAAO,EAEL,KAAK,GAAG,EACR,KAAK,UAAU,EAQhB,MAAM,KAAK,CAAA;AAEZ,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,GAAG,CAAA;AAmG7C,KAAK,YAAY,GAAG;IAClB,GAAG,EAAE,GAAG,CAAA;IACR,IAAI,EAAE,MAAM,IAAI,CAAA;IAChB,IAAI,EAAE,GAAG,CAAC,OAAO,CAAC,CAAA;IAClB,SAAS,EAAE,UAAU,CAAC,SAAS,CAAC,CAAA;IAChC,MAAM,CAAC,EAAE,oBAAoB,CAAA;IAC7B,OAAO,CAAC,EAAE,OAAO,CAAA;CAClB,CAAA;AAeD,eAAO,MAAM,OAAO,0WAy9ElB,CAAA"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@jvs-milkdown/crepe",
|
|
3
|
-
"version": "1.2.
|
|
3
|
+
"version": "1.2.15",
|
|
4
4
|
"keywords": [
|
|
5
5
|
"crepe",
|
|
6
6
|
"editor",
|
|
@@ -81,6 +81,16 @@
|
|
|
81
81
|
"require": "./lib/cjs/feature/toolbar/index.js",
|
|
82
82
|
"types": "./lib/types/feature/toolbar/index.d.ts"
|
|
83
83
|
},
|
|
84
|
+
"./feature/inline-diff": {
|
|
85
|
+
"import": "./lib/esm/feature/inline-diff/index.js",
|
|
86
|
+
"require": "./lib/cjs/feature/inline-diff/index.js",
|
|
87
|
+
"types": "./lib/types/feature/inline-diff/index.d.ts"
|
|
88
|
+
},
|
|
89
|
+
"./feature/diff-block": {
|
|
90
|
+
"import": "./lib/esm/feature/diff-block/index.js",
|
|
91
|
+
"require": "./lib/cjs/feature/diff-block/index.js",
|
|
92
|
+
"types": "./lib/types/feature/diff-block/index.d.ts"
|
|
93
|
+
},
|
|
84
94
|
"./theme/common/*": "./lib/theme/common/*",
|
|
85
95
|
"./theme/classic.css": "./lib/theme/crepe/style.css",
|
|
86
96
|
"./theme/classic-dark.css": "./lib/theme/crepe-dark/style.css",
|
|
@@ -97,12 +107,13 @@
|
|
|
97
107
|
"@codemirror/theme-one-dark": "^6.1.2",
|
|
98
108
|
"@codemirror/view": "^6.26.0",
|
|
99
109
|
"@floating-ui/dom": "^1.7.6",
|
|
100
|
-
"@jvs-milkdown/kit": "^1.2.
|
|
101
|
-
"@jvs-milkdown/prose": "^1.2.
|
|
102
|
-
"@jvs-milkdown/utils": "^1.2.
|
|
110
|
+
"@jvs-milkdown/kit": "^1.2.15",
|
|
111
|
+
"@jvs-milkdown/prose": "^1.2.15",
|
|
112
|
+
"@jvs-milkdown/utils": "^1.2.15",
|
|
103
113
|
"@types/lodash-es": "^4.17.12",
|
|
104
114
|
"clsx": "^2.0.0",
|
|
105
115
|
"codemirror": "^6.0.1",
|
|
116
|
+
"diff": "^9.0.0",
|
|
106
117
|
"katex": "^0.16.0",
|
|
107
118
|
"lodash-es": "^4.17.21",
|
|
108
119
|
"prosemirror-virtual-cursor": "^0.4.2",
|
package/src/core/builder.ts
CHANGED
|
@@ -27,6 +27,7 @@ import type { DefineFeature } from '../feature/shared'
|
|
|
27
27
|
|
|
28
28
|
import { CrepeFeature } from '../feature'
|
|
29
29
|
import { attachmentConfig } from '../feature/attachment/config'
|
|
30
|
+
import { inlineDiffApiCtx } from '../feature/inline-diff/config'
|
|
30
31
|
import { zhCN, enUS, type CrepeTranslations } from './locale'
|
|
31
32
|
import {
|
|
32
33
|
CrepeCtx,
|
|
@@ -244,6 +245,24 @@ export class CrepeBuilder {
|
|
|
244
245
|
return this.#editor.action(getMarkdown())
|
|
245
246
|
}
|
|
246
247
|
|
|
248
|
+
/// Show inline diff between two markdown versions.
|
|
249
|
+
showDiff = (oldMarkdown: string, newMarkdown: string) => {
|
|
250
|
+
this.#editor.action((ctx) => {
|
|
251
|
+
const api = ctx.get(inlineDiffApiCtx.key)
|
|
252
|
+
api.showDiff(oldMarkdown, newMarkdown)
|
|
253
|
+
})
|
|
254
|
+
return this
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
/// Hide inline diff and return to editing mode.
|
|
258
|
+
hideDiff = () => {
|
|
259
|
+
this.#editor.action((ctx) => {
|
|
260
|
+
const api = ctx.get(inlineDiffApiCtx.key)
|
|
261
|
+
api.hideDiff()
|
|
262
|
+
})
|
|
263
|
+
return this
|
|
264
|
+
}
|
|
265
|
+
|
|
247
266
|
/// Register event listeners.
|
|
248
267
|
on = (fn: (api: ListenerManager) => void) => {
|
|
249
268
|
if (this.#editor.status !== EditorStatus.Created) {
|
package/src/core/locale.ts
CHANGED
|
@@ -173,6 +173,10 @@ export const zhCN = {
|
|
|
173
173
|
'shortcuts.history': '历史记录',
|
|
174
174
|
'shortcuts.undo': '撤销',
|
|
175
175
|
'shortcuts.redo': '重做',
|
|
176
|
+
|
|
177
|
+
// inline-diff
|
|
178
|
+
'inlineDiff.accept': '接受',
|
|
179
|
+
'inlineDiff.reject': '拒绝',
|
|
176
180
|
}
|
|
177
181
|
|
|
178
182
|
export const enUS: typeof zhCN = {
|
|
@@ -331,6 +335,9 @@ export const enUS: typeof zhCN = {
|
|
|
331
335
|
'shortcuts.history': 'History',
|
|
332
336
|
'shortcuts.undo': 'Undo',
|
|
333
337
|
'shortcuts.redo': 'Redo',
|
|
338
|
+
|
|
339
|
+
'inlineDiff.accept': 'Accept',
|
|
340
|
+
'inlineDiff.reject': 'Reject',
|
|
334
341
|
}
|
|
335
342
|
|
|
336
343
|
export type CrepeTranslations = typeof zhCN
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import type { Extension } from '@codemirror/state'
|
|
2
|
+
|
|
3
|
+
import { oneDark } from '@codemirror/theme-one-dark'
|
|
4
|
+
import {
|
|
5
|
+
diffBlock,
|
|
6
|
+
diffBlockConfig,
|
|
7
|
+
type DiffBlockConfig,
|
|
8
|
+
} from '@jvs-milkdown/kit/component/diff-block'
|
|
9
|
+
import { basicSetup } from 'codemirror'
|
|
10
|
+
|
|
11
|
+
import type { DefineFeature } from '../shared'
|
|
12
|
+
|
|
13
|
+
import { crepeFeatureConfig } from '../../core/slice'
|
|
14
|
+
import { CrepeFeature } from '../index'
|
|
15
|
+
|
|
16
|
+
interface DiffBlockConfigCustom extends Omit<DiffBlockConfig, 'theme'> {
|
|
17
|
+
theme: Extension
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export type DiffBlockFeatureConfig = Partial<DiffBlockConfigCustom>
|
|
21
|
+
|
|
22
|
+
export const diffBlockFeature: DefineFeature<DiffBlockFeatureConfig> = (
|
|
23
|
+
editor,
|
|
24
|
+
config = {}
|
|
25
|
+
) => {
|
|
26
|
+
editor
|
|
27
|
+
.config(crepeFeatureConfig(CrepeFeature.DiffBlock))
|
|
28
|
+
.config((ctx) => {
|
|
29
|
+
const { languages = [], theme } = config
|
|
30
|
+
const extensions = [basicSetup]
|
|
31
|
+
if (theme) {
|
|
32
|
+
extensions.push(theme)
|
|
33
|
+
} else {
|
|
34
|
+
extensions.push(oneDark)
|
|
35
|
+
}
|
|
36
|
+
if (config.extensions) {
|
|
37
|
+
extensions.push(...config.extensions)
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
ctx.update(diffBlockConfig.key, (defaultConfig) => ({
|
|
41
|
+
...defaultConfig,
|
|
42
|
+
extensions,
|
|
43
|
+
languages: languages.length > 0 ? languages : defaultConfig.languages,
|
|
44
|
+
renderLanguage: config.renderLanguage || defaultConfig.renderLanguage,
|
|
45
|
+
}))
|
|
46
|
+
})
|
|
47
|
+
.use(diffBlock)
|
|
48
|
+
}
|
|
@@ -22,6 +22,8 @@ import type { ToolbarItem } from '../toolbar/config'
|
|
|
22
22
|
|
|
23
23
|
import { crepeFeatureConfig } from '../../core/slice'
|
|
24
24
|
import { CrepeFeature } from '../index'
|
|
25
|
+
import { highlightMark } from '../toolbar/highlight-mark'
|
|
26
|
+
import { underline } from '../toolbar/underline'
|
|
25
27
|
import { FixedToolbarComponent } from './component'
|
|
26
28
|
import { buildDefaultFixedToolbar } from './config'
|
|
27
29
|
import { DocumentHeader } from './document-header'
|
|
@@ -68,6 +70,7 @@ class FixedToolbarView implements PluginView {
|
|
|
68
70
|
#scrollContainers: Element[] = []
|
|
69
71
|
#onDblClick: ((event: MouseEvent) => void) | undefined
|
|
70
72
|
#view: EditorView
|
|
73
|
+
#editorContainer?: HTMLElement
|
|
71
74
|
|
|
72
75
|
constructor(ctx: Ctx, view: EditorView) {
|
|
73
76
|
this.#view = view
|
|
@@ -91,16 +94,25 @@ class FixedToolbarView implements PluginView {
|
|
|
91
94
|
if (root) {
|
|
92
95
|
root.style.position = 'relative'
|
|
93
96
|
// Use internal styles for transition for smooth resizing
|
|
94
|
-
root.style.transition =
|
|
95
|
-
'padding 0.1s ease-out, background-color 0.2s ease-out'
|
|
97
|
+
root.style.transition = 'background-color 0.2s ease-out'
|
|
96
98
|
|
|
97
99
|
root.prepend(this.#content)
|
|
98
100
|
|
|
101
|
+
const editorContainer = document.createElement('div')
|
|
102
|
+
editorContainer.className = 'milkdown-editor-container'
|
|
103
|
+
editorContainer.style.transition = 'padding 0.1s ease-out'
|
|
104
|
+
editorContainer.style.display = 'flex'
|
|
105
|
+
editorContainer.style.flexDirection = 'column'
|
|
106
|
+
editorContainer.style.flexGrow = '1'
|
|
107
|
+
root.insertBefore(editorContainer, view.dom)
|
|
108
|
+
editorContainer.appendChild(view.dom)
|
|
109
|
+
this.#editorContainer = editorContainer
|
|
110
|
+
|
|
99
111
|
const headerContent = document.createElement('div')
|
|
100
112
|
this.#headerApp = createApp(DocumentHeader, { ctx, config })
|
|
101
113
|
this.#headerApp.mount(headerContent)
|
|
102
114
|
this.#headerContent = headerContent
|
|
103
|
-
|
|
115
|
+
editorContainer.insertBefore(headerContent, view.dom)
|
|
104
116
|
|
|
105
117
|
const outlineContent = document.createElement('div')
|
|
106
118
|
outlineContent.style.position = 'fixed'
|
|
@@ -189,7 +201,29 @@ class FixedToolbarView implements PluginView {
|
|
|
189
201
|
outlineContent.style.right = 'auto'
|
|
190
202
|
} else {
|
|
191
203
|
outlineContent.style.left = 'auto'
|
|
192
|
-
|
|
204
|
+
let baseOffset = window.innerWidth - rootRect.right
|
|
205
|
+
let rightOffset = baseOffset
|
|
206
|
+
let hasVScroll = false
|
|
207
|
+
if (document.documentElement.scrollHeight > window.innerHeight) {
|
|
208
|
+
hasVScroll = true
|
|
209
|
+
}
|
|
210
|
+
let parent: HTMLElement | null = root
|
|
211
|
+
while (parent && parent !== document.body) {
|
|
212
|
+
const { overflowY } = getComputedStyle(parent)
|
|
213
|
+
if (overflowY === 'auto' || overflowY === 'scroll') {
|
|
214
|
+
if (parent.scrollHeight > parent.clientHeight) {
|
|
215
|
+
hasVScroll = true
|
|
216
|
+
break
|
|
217
|
+
}
|
|
218
|
+
}
|
|
219
|
+
parent = parent.parentElement
|
|
220
|
+
}
|
|
221
|
+
if (hasVScroll) {
|
|
222
|
+
rightOffset = Math.max(rightOffset, 32)
|
|
223
|
+
} else {
|
|
224
|
+
rightOffset = Math.max(rightOffset, 0)
|
|
225
|
+
}
|
|
226
|
+
outlineContent.style.right = `${rightOffset}px`
|
|
193
227
|
}
|
|
194
228
|
}
|
|
195
229
|
}
|
|
@@ -231,26 +265,26 @@ class FixedToolbarView implements PluginView {
|
|
|
231
265
|
root.style.backgroundColor = ''
|
|
232
266
|
}
|
|
233
267
|
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
268
|
+
// Reset root and toolbar styles to default/full-width
|
|
269
|
+
root.style.paddingLeft = '0'
|
|
270
|
+
root.style.paddingRight = '0'
|
|
271
|
+
this.#content.style.width = '100%'
|
|
272
|
+
this.#content.style.marginLeft = '0'
|
|
273
|
+
this.#content.style.marginRight = '0'
|
|
274
|
+
|
|
275
|
+
if (this.#editorContainer) {
|
|
276
|
+
if (viewState.outlineVisible) {
|
|
277
|
+
if (viewState.outlinePosition === 'left') {
|
|
278
|
+
this.#editorContainer.style.paddingLeft = `${viewState.outlineWidth}px`
|
|
279
|
+
this.#editorContainer.style.paddingRight = '0'
|
|
280
|
+
} else {
|
|
281
|
+
this.#editorContainer.style.paddingLeft = '0'
|
|
282
|
+
this.#editorContainer.style.paddingRight = `${viewState.outlineWidth}px`
|
|
283
|
+
}
|
|
241
284
|
} else {
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
this.#content.style.width = `calc(100% + ${viewState.outlineWidth}px)`
|
|
245
|
-
this.#content.style.marginLeft = '0'
|
|
246
|
-
this.#content.style.marginRight = `-${viewState.outlineWidth}px`
|
|
285
|
+
this.#editorContainer.style.paddingLeft = '0'
|
|
286
|
+
this.#editorContainer.style.paddingRight = '0'
|
|
247
287
|
}
|
|
248
|
-
} else {
|
|
249
|
-
root.style.paddingLeft = '0'
|
|
250
|
-
root.style.paddingRight = '0'
|
|
251
|
-
this.#content.style.width = '100%'
|
|
252
|
-
this.#content.style.marginLeft = '0'
|
|
253
|
-
this.#content.style.marginRight = '0'
|
|
254
288
|
}
|
|
255
289
|
|
|
256
290
|
const maxWidth = (editorWidthMap as any)[viewState.editorWidth]
|
|
@@ -269,8 +303,11 @@ class FixedToolbarView implements PluginView {
|
|
|
269
303
|
}
|
|
270
304
|
|
|
271
305
|
// Compute geometry after styles and DOM (cover) are updated
|
|
272
|
-
nextTick(() => {
|
|
306
|
+
void nextTick(() => {
|
|
273
307
|
this.#updateOutlineGeometry?.()
|
|
308
|
+
setTimeout(() => {
|
|
309
|
+
this.#updateOutlineGeometry?.()
|
|
310
|
+
}, 100)
|
|
274
311
|
})
|
|
275
312
|
},
|
|
276
313
|
{ immediate: true }
|
|
@@ -338,5 +375,7 @@ export const fixedToolbar: DefineFeature<FixedToolbarFeatureConfig> = (
|
|
|
338
375
|
})
|
|
339
376
|
.use(viewMenuStateCtx)
|
|
340
377
|
.use(fixedToolbarConfig)
|
|
378
|
+
.use(underline as any)
|
|
379
|
+
.use(highlightMark as any)
|
|
341
380
|
.use(fixedToolbarPlugin)
|
|
342
381
|
}
|
|
@@ -263,7 +263,8 @@ export const OutlinePanel = defineComponent({
|
|
|
263
263
|
width: `${state.outlineWidth}px`,
|
|
264
264
|
minWidth: '200px',
|
|
265
265
|
maxWidth: '400px',
|
|
266
|
-
backgroundColor:
|
|
266
|
+
backgroundColor:
|
|
267
|
+
state.documentBackground || 'var(--crepe-color-background)',
|
|
267
268
|
borderRight: isLeft
|
|
268
269
|
? '1px solid var(--crepe-color-outline-variant, color-mix(in srgb, var(--crepe-color-outline), transparent 80%))'
|
|
269
270
|
: 'none',
|
|
@@ -283,11 +284,12 @@ export const OutlinePanel = defineComponent({
|
|
|
283
284
|
{/* Header */}
|
|
284
285
|
<div
|
|
285
286
|
style={{
|
|
286
|
-
padding: '
|
|
287
|
+
padding: '12px 16px',
|
|
287
288
|
fontWeight: 'bold',
|
|
288
289
|
fontSize: '14px',
|
|
289
290
|
color: 'var(--crepe-color-on-surface)',
|
|
290
|
-
borderBottom:
|
|
291
|
+
borderBottom:
|
|
292
|
+
'1px solid var(--crepe-color-outline-variant, color-mix(in srgb, var(--crepe-color-outline, #ddd), transparent 80%))',
|
|
291
293
|
display: 'flex',
|
|
292
294
|
justifyContent: 'space-between',
|
|
293
295
|
alignItems: 'center',
|
package/src/feature/index.ts
CHANGED
|
@@ -2,8 +2,10 @@ import type { AttachmentFeatureConfig } from './attachment/config'
|
|
|
2
2
|
import type { BlockEditFeatureConfig } from './block-edit'
|
|
3
3
|
import type { CodeMirrorFeatureConfig } from './code-mirror'
|
|
4
4
|
import type { CursorFeatureConfig } from './cursor'
|
|
5
|
+
import type { DiffBlockFeatureConfig } from './diff-block'
|
|
5
6
|
import type { FixedToolbarFeatureConfig } from './fixed-toolbar'
|
|
6
7
|
import type { ImageBlockFeatureConfig } from './image-block'
|
|
8
|
+
import type { InlineDiffFeatureConfig } from './inline-diff'
|
|
7
9
|
import type { LatexFeatureConfig } from './latex'
|
|
8
10
|
import type { LinkTooltipFeatureConfig } from './link-tooltip'
|
|
9
11
|
import type { ListItemFeatureConfig } from './list-item'
|
|
@@ -50,6 +52,12 @@ export enum CrepeFeature {
|
|
|
50
52
|
|
|
51
53
|
/// File attachment uploads
|
|
52
54
|
Attachment = 'attachment',
|
|
55
|
+
|
|
56
|
+
/// Inline diff comparison between two document versions, similar to Word track changes.
|
|
57
|
+
InlineDiff = 'inline-diff',
|
|
58
|
+
|
|
59
|
+
/// Diff comparison block for showing code differences
|
|
60
|
+
DiffBlock = 'diff-block',
|
|
53
61
|
}
|
|
54
62
|
|
|
55
63
|
export interface CrepeFeatureConfig {
|
|
@@ -65,6 +73,8 @@ export interface CrepeFeatureConfig {
|
|
|
65
73
|
[CrepeFeature.Table]?: TableFeatureConfig
|
|
66
74
|
[CrepeFeature.Latex]?: LatexFeatureConfig
|
|
67
75
|
[CrepeFeature.Attachment]?: AttachmentFeatureConfig
|
|
76
|
+
[CrepeFeature.InlineDiff]?: InlineDiffFeatureConfig
|
|
77
|
+
[CrepeFeature.DiffBlock]?: DiffBlockFeatureConfig
|
|
68
78
|
}
|
|
69
79
|
|
|
70
80
|
export const defaultFeatures: Record<CrepeFeature, boolean> = {
|
|
@@ -80,4 +90,6 @@ export const defaultFeatures: Record<CrepeFeature, boolean> = {
|
|
|
80
90
|
[CrepeFeature.Table]: true,
|
|
81
91
|
[CrepeFeature.Latex]: true,
|
|
82
92
|
[CrepeFeature.Attachment]: true,
|
|
93
|
+
[CrepeFeature.InlineDiff]: false,
|
|
94
|
+
[CrepeFeature.DiffBlock]: true,
|
|
83
95
|
}
|