@atlaskit/editor-plugin-code-block-advanced 1.0.2 → 1.1.0
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/CHANGELOG.md +21 -0
- package/afm-cc/tsconfig.json +6 -0
- package/afm-jira/tsconfig.json +6 -0
- package/afm-post-office/tsconfig.json +6 -0
- package/dist/cjs/nodeviews/codeBlockAdvanced.js +29 -26
- package/dist/cjs/nodeviews/codemirrorSync/syncCMWithPM.js +0 -1
- package/dist/cjs/nodeviews/extensions/keymap/index.js +23 -3
- package/dist/cjs/nodeviews/extensions/manageSelectionMarker.js +28 -0
- package/dist/cjs/nodeviews/extensions/prosemirrorDecorations.js +134 -0
- package/dist/cjs/ui/theme.js +20 -2
- package/dist/es2019/nodeviews/codeBlockAdvanced.js +27 -27
- package/dist/es2019/nodeviews/codemirrorSync/syncCMWithPM.js +0 -1
- package/dist/es2019/nodeviews/extensions/keymap/index.js +23 -3
- package/dist/es2019/nodeviews/extensions/manageSelectionMarker.js +22 -0
- package/dist/es2019/nodeviews/extensions/prosemirrorDecorations.js +99 -0
- package/dist/es2019/ui/theme.js +62 -2
- package/dist/esm/nodeviews/codeBlockAdvanced.js +30 -27
- package/dist/esm/nodeviews/codemirrorSync/syncCMWithPM.js +0 -1
- package/dist/esm/nodeviews/extensions/keymap/index.js +23 -3
- package/dist/esm/nodeviews/extensions/manageSelectionMarker.js +22 -0
- package/dist/esm/nodeviews/extensions/prosemirrorDecorations.js +127 -0
- package/dist/esm/ui/theme.js +20 -2
- package/dist/types/codeBlockAdvancedPluginType.d.ts +9 -1
- package/dist/types/nodeviews/codeBlockAdvanced.d.ts +10 -5
- package/dist/types/nodeviews/extensions/keymap/index.d.ts +2 -1
- package/dist/types/nodeviews/extensions/manageSelectionMarker.d.ts +10 -0
- package/dist/types/nodeviews/extensions/prosemirrorDecorations.d.ts +20 -0
- package/dist/types-ts4.5/codeBlockAdvancedPluginType.d.ts +5 -1
- package/dist/types-ts4.5/nodeviews/codeBlockAdvanced.d.ts +10 -5
- package/dist/types-ts4.5/nodeviews/extensions/keymap/index.d.ts +2 -1
- package/dist/types-ts4.5/nodeviews/extensions/manageSelectionMarker.d.ts +10 -0
- package/dist/types-ts4.5/nodeviews/extensions/prosemirrorDecorations.d.ts +20 -0
- package/package.json +10 -8
- package/src/codeBlockAdvancedPluginType.ts +9 -1
- package/src/nodeviews/codeBlockAdvanced.ts +31 -30
- package/src/nodeviews/codemirrorSync/syncCMWithPM.ts +0 -1
- package/src/nodeviews/extensions/keymap/index.ts +31 -1
- package/src/nodeviews/extensions/manageSelectionMarker.ts +28 -0
- package/src/nodeviews/extensions/prosemirrorDecorations.ts +148 -0
- package/src/ui/theme.ts +64 -0
- package/tsconfig.app.json +6 -0
- package/dist/cjs/nodeviews/extensions/bidiCharWarning.js +0 -83
- package/dist/cjs/nodeviews/extensions/copyButtonDecorations.js +0 -22
- package/dist/es2019/nodeviews/extensions/bidiCharWarning.js +0 -53
- package/dist/es2019/nodeviews/extensions/copyButtonDecorations.js +0 -16
- package/dist/esm/nodeviews/extensions/bidiCharWarning.js +0 -77
- package/dist/esm/nodeviews/extensions/copyButtonDecorations.js +0 -16
- package/dist/types/nodeviews/extensions/bidiCharWarning.d.ts +0 -8
- package/dist/types/nodeviews/extensions/copyButtonDecorations.d.ts +0 -1
- package/dist/types-ts4.5/nodeviews/extensions/bidiCharWarning.d.ts +0 -8
- package/dist/types-ts4.5/nodeviews/extensions/copyButtonDecorations.d.ts +0 -1
- package/src/nodeviews/extensions/bidiCharWarning.ts +0 -72
- package/src/nodeviews/extensions/copyButtonDecorations.ts +0 -15
|
@@ -2,9 +2,17 @@ import type { Extension } from '@codemirror/state';
|
|
|
2
2
|
import type { NextEditorPlugin, OptionalPlugin } from '@atlaskit/editor-common/types';
|
|
3
3
|
import type { CodeBlockPlugin } from '@atlaskit/editor-plugin-code-block';
|
|
4
4
|
import type { EditorDisabledPlugin } from '@atlaskit/editor-plugin-editor-disabled';
|
|
5
|
+
import type { FindReplacePlugin } from '@atlaskit/editor-plugin-find-replace';
|
|
5
6
|
import type { SelectionPlugin } from '@atlaskit/editor-plugin-selection';
|
|
7
|
+
import type { SelectionMarkerPlugin } from '@atlaskit/editor-plugin-selection-marker';
|
|
6
8
|
export type CodeBlockAdvancedPlugin = NextEditorPlugin<'codeBlockAdvanced', {
|
|
7
|
-
dependencies: [
|
|
9
|
+
dependencies: [
|
|
10
|
+
CodeBlockPlugin,
|
|
11
|
+
SelectionPlugin,
|
|
12
|
+
OptionalPlugin<EditorDisabledPlugin>,
|
|
13
|
+
OptionalPlugin<SelectionMarkerPlugin>,
|
|
14
|
+
OptionalPlugin<FindReplacePlugin>
|
|
15
|
+
];
|
|
8
16
|
pluginConfiguration: {
|
|
9
17
|
extensions?: Extension[];
|
|
10
18
|
} | undefined;
|
|
@@ -2,7 +2,7 @@ import { Extension } from '@codemirror/state';
|
|
|
2
2
|
import { ViewUpdate } from '@codemirror/view';
|
|
3
3
|
import type { getPosHandler, getPosHandlerNode, ExtractInjectionAPI } from '@atlaskit/editor-common/types';
|
|
4
4
|
import { Node as PMNode } from '@atlaskit/editor-prosemirror/model';
|
|
5
|
-
import type { EditorView, NodeView } from '@atlaskit/editor-prosemirror/view';
|
|
5
|
+
import type { Decoration, DecorationSource, EditorView, NodeView } from '@atlaskit/editor-prosemirror/view';
|
|
6
6
|
import type { CodeBlockAdvancedPlugin } from '../codeBlockAdvancedPluginType';
|
|
7
7
|
interface ConfigProps {
|
|
8
8
|
api: ExtractInjectionAPI<CodeBlockAdvancedPlugin> | undefined;
|
|
@@ -15,15 +15,15 @@ declare class CodeBlockAdvancedNodeView implements NodeView {
|
|
|
15
15
|
private lineWrappingCompartment;
|
|
16
16
|
private languageCompartment;
|
|
17
17
|
private readOnlyCompartment;
|
|
18
|
-
private
|
|
18
|
+
private pmDecorationsCompartment;
|
|
19
19
|
private node;
|
|
20
20
|
private getPos;
|
|
21
21
|
private cm;
|
|
22
22
|
private selectionAPI;
|
|
23
23
|
private maybeTryingToReachNodeSelection;
|
|
24
24
|
private cleanupDisabledState;
|
|
25
|
-
private cleanupCopyButtonDecoration;
|
|
26
25
|
private languageLoader;
|
|
26
|
+
private pmFacet;
|
|
27
27
|
constructor(node: PMNode, view: EditorView, getPos: getPosHandlerNode, config: ConfigProps);
|
|
28
28
|
destroy(): void;
|
|
29
29
|
forwardUpdate(update: ViewUpdate): void;
|
|
@@ -31,10 +31,15 @@ declare class CodeBlockAdvancedNodeView implements NodeView {
|
|
|
31
31
|
private updateReadonlyState;
|
|
32
32
|
private updateLanguage;
|
|
33
33
|
private selectCodeBlockNode;
|
|
34
|
-
private addCopyButtonDecoration;
|
|
35
34
|
private wordWrappingEnabled;
|
|
36
35
|
private updateWordWrap;
|
|
37
|
-
update(node: PMNode): boolean;
|
|
36
|
+
update(node: PMNode, _: readonly Decoration[], innerDecorations: DecorationSource): boolean;
|
|
37
|
+
/**
|
|
38
|
+
* Updates a facet which stores information on the prosemirror decorations
|
|
39
|
+
*
|
|
40
|
+
* This then gets translated to codemirror decorations in `prosemirrorDecorationPlugin`
|
|
41
|
+
*/
|
|
42
|
+
private updateProseMirrorDecorations;
|
|
38
43
|
stopEvent(e: Event): boolean;
|
|
39
44
|
}
|
|
40
45
|
export declare const getCodeBlockAdvancedNodeView: (props: ConfigProps) => (node: PMNode, view: EditorView, getPos: getPosHandler) => CodeBlockAdvancedNodeView;
|
|
@@ -9,6 +9,7 @@ interface KeymapProps {
|
|
|
9
9
|
getPos: getPosHandlerNode;
|
|
10
10
|
selectCodeBlockNode: (relativeSelectionPos: RelativeSelectionPos | undefined) => void;
|
|
11
11
|
onMaybeNodeSelection: () => void;
|
|
12
|
+
customFindReplace: boolean;
|
|
12
13
|
}
|
|
13
|
-
export declare const keymapExtension: ({ view, getNode, getPos, selectCodeBlockNode, onMaybeNodeSelection, }: KeymapProps) => Extension;
|
|
14
|
+
export declare const keymapExtension: ({ view, getNode, getPos, selectCodeBlockNode, onMaybeNodeSelection, customFindReplace, }: KeymapProps) => Extension;
|
|
14
15
|
export {};
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { Extension } from '@codemirror/state';
|
|
2
|
+
import { type ExtractInjectionAPI } from '@atlaskit/editor-common/types';
|
|
3
|
+
import { CodeBlockAdvancedPlugin } from '../../codeBlockAdvancedPluginType';
|
|
4
|
+
/**
|
|
5
|
+
* Hides selection marker decoration when focused on codemirror editor and re-enables on blur
|
|
6
|
+
*
|
|
7
|
+
* @param api
|
|
8
|
+
* @returns CodeMirror Extension
|
|
9
|
+
*/
|
|
10
|
+
export declare const manageSelectionMarker: (api: ExtractInjectionAPI<CodeBlockAdvancedPlugin> | undefined) => Extension;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { Facet } from '@codemirror/state';
|
|
2
|
+
import { ViewPlugin, EditorView as CodeMirror, DecorationSet, ViewUpdate } from '@codemirror/view';
|
|
3
|
+
import type { EditorView, DecorationSource } from '@atlaskit/editor-prosemirror/view';
|
|
4
|
+
/**
|
|
5
|
+
* Creates CodeMirror versions of the decorations provided by ProseMirror.
|
|
6
|
+
*
|
|
7
|
+
* Inline ProseMirror decorations -> Mark CodeMirror decorations
|
|
8
|
+
* Widget ProseMirror decorations -> Widget CodeMirror decorations
|
|
9
|
+
*
|
|
10
|
+
* This way any decorations applied in ProseMirror land should automatically be supported
|
|
11
|
+
* by the CodeMirror editor
|
|
12
|
+
*
|
|
13
|
+
* @param updateDecorationsEffect Facet for the prosemirror decorations
|
|
14
|
+
* @returns CodeMirror extension
|
|
15
|
+
*/
|
|
16
|
+
export declare const prosemirrorDecorationPlugin: (updateDecorationsEffect: Facet<DecorationSource>, editorView: EditorView, getPos: () => number | undefined) => ViewPlugin<{
|
|
17
|
+
decorations: DecorationSet;
|
|
18
|
+
updateDecorations(view: CodeMirror): DecorationSet;
|
|
19
|
+
update(update: ViewUpdate): void;
|
|
20
|
+
}>;
|
|
@@ -2,12 +2,16 @@ import type { Extension } from '@codemirror/state';
|
|
|
2
2
|
import type { NextEditorPlugin, OptionalPlugin } from '@atlaskit/editor-common/types';
|
|
3
3
|
import type { CodeBlockPlugin } from '@atlaskit/editor-plugin-code-block';
|
|
4
4
|
import type { EditorDisabledPlugin } from '@atlaskit/editor-plugin-editor-disabled';
|
|
5
|
+
import type { FindReplacePlugin } from '@atlaskit/editor-plugin-find-replace';
|
|
5
6
|
import type { SelectionPlugin } from '@atlaskit/editor-plugin-selection';
|
|
7
|
+
import type { SelectionMarkerPlugin } from '@atlaskit/editor-plugin-selection-marker';
|
|
6
8
|
export type CodeBlockAdvancedPlugin = NextEditorPlugin<'codeBlockAdvanced', {
|
|
7
9
|
dependencies: [
|
|
8
10
|
CodeBlockPlugin,
|
|
9
11
|
SelectionPlugin,
|
|
10
|
-
OptionalPlugin<EditorDisabledPlugin
|
|
12
|
+
OptionalPlugin<EditorDisabledPlugin>,
|
|
13
|
+
OptionalPlugin<SelectionMarkerPlugin>,
|
|
14
|
+
OptionalPlugin<FindReplacePlugin>
|
|
11
15
|
];
|
|
12
16
|
pluginConfiguration: {
|
|
13
17
|
extensions?: Extension[];
|
|
@@ -2,7 +2,7 @@ import { Extension } from '@codemirror/state';
|
|
|
2
2
|
import { ViewUpdate } from '@codemirror/view';
|
|
3
3
|
import type { getPosHandler, getPosHandlerNode, ExtractInjectionAPI } from '@atlaskit/editor-common/types';
|
|
4
4
|
import { Node as PMNode } from '@atlaskit/editor-prosemirror/model';
|
|
5
|
-
import type { EditorView, NodeView } from '@atlaskit/editor-prosemirror/view';
|
|
5
|
+
import type { Decoration, DecorationSource, EditorView, NodeView } from '@atlaskit/editor-prosemirror/view';
|
|
6
6
|
import type { CodeBlockAdvancedPlugin } from '../codeBlockAdvancedPluginType';
|
|
7
7
|
interface ConfigProps {
|
|
8
8
|
api: ExtractInjectionAPI<CodeBlockAdvancedPlugin> | undefined;
|
|
@@ -15,15 +15,15 @@ declare class CodeBlockAdvancedNodeView implements NodeView {
|
|
|
15
15
|
private lineWrappingCompartment;
|
|
16
16
|
private languageCompartment;
|
|
17
17
|
private readOnlyCompartment;
|
|
18
|
-
private
|
|
18
|
+
private pmDecorationsCompartment;
|
|
19
19
|
private node;
|
|
20
20
|
private getPos;
|
|
21
21
|
private cm;
|
|
22
22
|
private selectionAPI;
|
|
23
23
|
private maybeTryingToReachNodeSelection;
|
|
24
24
|
private cleanupDisabledState;
|
|
25
|
-
private cleanupCopyButtonDecoration;
|
|
26
25
|
private languageLoader;
|
|
26
|
+
private pmFacet;
|
|
27
27
|
constructor(node: PMNode, view: EditorView, getPos: getPosHandlerNode, config: ConfigProps);
|
|
28
28
|
destroy(): void;
|
|
29
29
|
forwardUpdate(update: ViewUpdate): void;
|
|
@@ -31,10 +31,15 @@ declare class CodeBlockAdvancedNodeView implements NodeView {
|
|
|
31
31
|
private updateReadonlyState;
|
|
32
32
|
private updateLanguage;
|
|
33
33
|
private selectCodeBlockNode;
|
|
34
|
-
private addCopyButtonDecoration;
|
|
35
34
|
private wordWrappingEnabled;
|
|
36
35
|
private updateWordWrap;
|
|
37
|
-
update(node: PMNode): boolean;
|
|
36
|
+
update(node: PMNode, _: readonly Decoration[], innerDecorations: DecorationSource): boolean;
|
|
37
|
+
/**
|
|
38
|
+
* Updates a facet which stores information on the prosemirror decorations
|
|
39
|
+
*
|
|
40
|
+
* This then gets translated to codemirror decorations in `prosemirrorDecorationPlugin`
|
|
41
|
+
*/
|
|
42
|
+
private updateProseMirrorDecorations;
|
|
38
43
|
stopEvent(e: Event): boolean;
|
|
39
44
|
}
|
|
40
45
|
export declare const getCodeBlockAdvancedNodeView: (props: ConfigProps) => (node: PMNode, view: EditorView, getPos: getPosHandler) => CodeBlockAdvancedNodeView;
|
|
@@ -9,6 +9,7 @@ interface KeymapProps {
|
|
|
9
9
|
getPos: getPosHandlerNode;
|
|
10
10
|
selectCodeBlockNode: (relativeSelectionPos: RelativeSelectionPos | undefined) => void;
|
|
11
11
|
onMaybeNodeSelection: () => void;
|
|
12
|
+
customFindReplace: boolean;
|
|
12
13
|
}
|
|
13
|
-
export declare const keymapExtension: ({ view, getNode, getPos, selectCodeBlockNode, onMaybeNodeSelection, }: KeymapProps) => Extension;
|
|
14
|
+
export declare const keymapExtension: ({ view, getNode, getPos, selectCodeBlockNode, onMaybeNodeSelection, customFindReplace, }: KeymapProps) => Extension;
|
|
14
15
|
export {};
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { Extension } from '@codemirror/state';
|
|
2
|
+
import { type ExtractInjectionAPI } from '@atlaskit/editor-common/types';
|
|
3
|
+
import { CodeBlockAdvancedPlugin } from '../../codeBlockAdvancedPluginType';
|
|
4
|
+
/**
|
|
5
|
+
* Hides selection marker decoration when focused on codemirror editor and re-enables on blur
|
|
6
|
+
*
|
|
7
|
+
* @param api
|
|
8
|
+
* @returns CodeMirror Extension
|
|
9
|
+
*/
|
|
10
|
+
export declare const manageSelectionMarker: (api: ExtractInjectionAPI<CodeBlockAdvancedPlugin> | undefined) => Extension;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { Facet } from '@codemirror/state';
|
|
2
|
+
import { ViewPlugin, EditorView as CodeMirror, DecorationSet, ViewUpdate } from '@codemirror/view';
|
|
3
|
+
import type { EditorView, DecorationSource } from '@atlaskit/editor-prosemirror/view';
|
|
4
|
+
/**
|
|
5
|
+
* Creates CodeMirror versions of the decorations provided by ProseMirror.
|
|
6
|
+
*
|
|
7
|
+
* Inline ProseMirror decorations -> Mark CodeMirror decorations
|
|
8
|
+
* Widget ProseMirror decorations -> Widget CodeMirror decorations
|
|
9
|
+
*
|
|
10
|
+
* This way any decorations applied in ProseMirror land should automatically be supported
|
|
11
|
+
* by the CodeMirror editor
|
|
12
|
+
*
|
|
13
|
+
* @param updateDecorationsEffect Facet for the prosemirror decorations
|
|
14
|
+
* @returns CodeMirror extension
|
|
15
|
+
*/
|
|
16
|
+
export declare const prosemirrorDecorationPlugin: (updateDecorationsEffect: Facet<DecorationSource>, editorView: EditorView, getPos: () => number | undefined) => ViewPlugin<{
|
|
17
|
+
decorations: DecorationSet;
|
|
18
|
+
updateDecorations(view: CodeMirror): DecorationSet;
|
|
19
|
+
update(update: ViewUpdate): void;
|
|
20
|
+
}>;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@atlaskit/editor-plugin-code-block-advanced",
|
|
3
|
-
"version": "1.0
|
|
3
|
+
"version": "1.1.0",
|
|
4
4
|
"description": "CodeBlockAdvanced plugin for @atlaskit/editor-core",
|
|
5
5
|
"author": "Atlassian Pty Ltd",
|
|
6
6
|
"license": "Apache-2.0",
|
|
@@ -33,12 +33,14 @@
|
|
|
33
33
|
},
|
|
34
34
|
"dependencies": {
|
|
35
35
|
"@atlaskit/adf-schema": "^46.1.0",
|
|
36
|
-
"@atlaskit/editor-common": "^99.
|
|
37
|
-
"@atlaskit/editor-plugin-code-block": "^3.
|
|
38
|
-
"@atlaskit/editor-plugin-editor-disabled": "^1.
|
|
39
|
-
"@atlaskit/editor-plugin-
|
|
40
|
-
"@atlaskit/editor-
|
|
41
|
-
"@atlaskit/
|
|
36
|
+
"@atlaskit/editor-common": "^99.10.0",
|
|
37
|
+
"@atlaskit/editor-plugin-code-block": "^3.7.0",
|
|
38
|
+
"@atlaskit/editor-plugin-editor-disabled": "^1.5.0",
|
|
39
|
+
"@atlaskit/editor-plugin-find-replace": "^1.9.0",
|
|
40
|
+
"@atlaskit/editor-plugin-selection": "^1.7.0",
|
|
41
|
+
"@atlaskit/editor-plugin-selection-marker": "^1.8.0",
|
|
42
|
+
"@atlaskit/editor-prosemirror": "7.0.0",
|
|
43
|
+
"@atlaskit/tokens": "^3.3.0",
|
|
42
44
|
"@babel/runtime": "^7.0.0",
|
|
43
45
|
"@codemirror/autocomplete": "6.18.4",
|
|
44
46
|
"@codemirror/commands": "6.7.1",
|
|
@@ -54,7 +56,7 @@
|
|
|
54
56
|
"react": "^16.8.0 || ^17.0.0 || ~18.2.0"
|
|
55
57
|
},
|
|
56
58
|
"devDependencies": {
|
|
57
|
-
"@atlaskit/code": "^15.
|
|
59
|
+
"@atlaskit/code": "^15.7.0",
|
|
58
60
|
"typescript": "~5.4.2"
|
|
59
61
|
},
|
|
60
62
|
"techstack": {
|
|
@@ -3,12 +3,20 @@ import type { Extension } from '@codemirror/state';
|
|
|
3
3
|
import type { NextEditorPlugin, OptionalPlugin } from '@atlaskit/editor-common/types';
|
|
4
4
|
import type { CodeBlockPlugin } from '@atlaskit/editor-plugin-code-block';
|
|
5
5
|
import type { EditorDisabledPlugin } from '@atlaskit/editor-plugin-editor-disabled';
|
|
6
|
+
import type { FindReplacePlugin } from '@atlaskit/editor-plugin-find-replace';
|
|
6
7
|
import type { SelectionPlugin } from '@atlaskit/editor-plugin-selection';
|
|
8
|
+
import type { SelectionMarkerPlugin } from '@atlaskit/editor-plugin-selection-marker';
|
|
7
9
|
|
|
8
10
|
export type CodeBlockAdvancedPlugin = NextEditorPlugin<
|
|
9
11
|
'codeBlockAdvanced',
|
|
10
12
|
{
|
|
11
|
-
dependencies: [
|
|
13
|
+
dependencies: [
|
|
14
|
+
CodeBlockPlugin,
|
|
15
|
+
SelectionPlugin,
|
|
16
|
+
OptionalPlugin<EditorDisabledPlugin>,
|
|
17
|
+
OptionalPlugin<SelectionMarkerPlugin>,
|
|
18
|
+
OptionalPlugin<FindReplacePlugin>,
|
|
19
|
+
];
|
|
12
20
|
pluginConfiguration:
|
|
13
21
|
| {
|
|
14
22
|
extensions?: Extension[];
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { closeBrackets } from '@codemirror/autocomplete';
|
|
2
2
|
import { syntaxHighlighting, bracketMatching } from '@codemirror/language';
|
|
3
|
-
import { Compartment, Extension, EditorSelection } from '@codemirror/state';
|
|
3
|
+
import { Compartment, Extension, EditorSelection, Facet } from '@codemirror/state';
|
|
4
4
|
import { EditorView as CodeMirror, lineNumbers, ViewUpdate, gutters } from '@codemirror/view';
|
|
5
5
|
|
|
6
6
|
import { isCodeBlockWordWrapEnabled } from '@atlaskit/editor-common/code-block';
|
|
@@ -13,7 +13,12 @@ import type {
|
|
|
13
13
|
import { EditorSelectionAPI } from '@atlaskit/editor-plugin-selection';
|
|
14
14
|
import { Node as PMNode } from '@atlaskit/editor-prosemirror/model';
|
|
15
15
|
import { NodeSelection } from '@atlaskit/editor-prosemirror/state';
|
|
16
|
-
import type {
|
|
16
|
+
import type {
|
|
17
|
+
Decoration,
|
|
18
|
+
DecorationSource,
|
|
19
|
+
EditorView,
|
|
20
|
+
NodeView,
|
|
21
|
+
} from '@atlaskit/editor-prosemirror/view';
|
|
17
22
|
|
|
18
23
|
import type { CodeBlockAdvancedPlugin } from '../codeBlockAdvancedPluginType';
|
|
19
24
|
import { highlightStyle } from '../ui/syntaxHighlightingTheme';
|
|
@@ -21,9 +26,9 @@ import { cmTheme } from '../ui/theme';
|
|
|
21
26
|
|
|
22
27
|
import { syncCMWithPM } from './codemirrorSync/syncCMWithPM';
|
|
23
28
|
import { updateCMSelection } from './codemirrorSync/updateCMSelection';
|
|
24
|
-
import { bidiCharWarningExtension } from './extensions/bidiCharWarning';
|
|
25
|
-
import { copyButtonDecorations } from './extensions/copyButtonDecorations';
|
|
26
29
|
import { keymapExtension } from './extensions/keymap';
|
|
30
|
+
import { manageSelectionMarker } from './extensions/manageSelectionMarker';
|
|
31
|
+
import { prosemirrorDecorationPlugin } from './extensions/prosemirrorDecorations';
|
|
27
32
|
import { LanguageLoader } from './languages/loader';
|
|
28
33
|
|
|
29
34
|
interface ConfigProps {
|
|
@@ -39,17 +44,16 @@ class CodeBlockAdvancedNodeView implements NodeView {
|
|
|
39
44
|
private lineWrappingCompartment = new Compartment();
|
|
40
45
|
private languageCompartment = new Compartment();
|
|
41
46
|
private readOnlyCompartment = new Compartment();
|
|
42
|
-
private
|
|
47
|
+
private pmDecorationsCompartment = new Compartment();
|
|
43
48
|
private node: PMNode;
|
|
44
49
|
private getPos: getPosHandlerNode;
|
|
45
50
|
private cm: CodeMirror;
|
|
46
51
|
private selectionAPI: EditorSelectionAPI | undefined;
|
|
47
52
|
private maybeTryingToReachNodeSelection = false;
|
|
48
53
|
private cleanupDisabledState: (() => void) | undefined;
|
|
49
|
-
private cleanupCopyButtonDecoration: (() => void) | undefined;
|
|
50
54
|
private languageLoader: LanguageLoader;
|
|
55
|
+
private pmFacet = Facet.define<DecorationSource>();
|
|
51
56
|
|
|
52
|
-
// eslint-disable-next-line @typescript-eslint/max-params
|
|
53
57
|
constructor(node: PMNode, view: EditorView, getPos: getPosHandlerNode, config: ConfigProps) {
|
|
54
58
|
this.node = node;
|
|
55
59
|
this.view = view;
|
|
@@ -60,13 +64,6 @@ class CodeBlockAdvancedNodeView implements NodeView {
|
|
|
60
64
|
this.cleanupDisabledState = config.api?.editorDisabled?.sharedState.onChange(() => {
|
|
61
65
|
this.updateReadonlyState();
|
|
62
66
|
});
|
|
63
|
-
this.cleanupCopyButtonDecoration = config.api?.codeBlock?.sharedState.onChange(
|
|
64
|
-
({ nextSharedState, prevSharedState }) => {
|
|
65
|
-
if (nextSharedState?.copyButtonHoverNode !== prevSharedState?.copyButtonHoverNode) {
|
|
66
|
-
this.addCopyButtonDecoration(nextSharedState?.copyButtonHoverNode);
|
|
67
|
-
}
|
|
68
|
-
},
|
|
69
|
-
);
|
|
70
67
|
this.languageLoader = new LanguageLoader((lang) => {
|
|
71
68
|
this.updating = true;
|
|
72
69
|
this.cm.dispatch({
|
|
@@ -81,13 +78,14 @@ class CodeBlockAdvancedNodeView implements NodeView {
|
|
|
81
78
|
...config.extensions,
|
|
82
79
|
this.lineWrappingCompartment.of([]),
|
|
83
80
|
this.languageCompartment.of([]),
|
|
84
|
-
this.
|
|
81
|
+
this.pmDecorationsCompartment.of([]),
|
|
85
82
|
keymapExtension({
|
|
86
83
|
view,
|
|
87
84
|
getPos,
|
|
88
85
|
getNode,
|
|
89
86
|
selectCodeBlockNode: this.selectCodeBlockNode.bind(this),
|
|
90
87
|
onMaybeNodeSelection,
|
|
88
|
+
customFindReplace: Boolean(config.api?.findReplace),
|
|
91
89
|
}),
|
|
92
90
|
cmTheme,
|
|
93
91
|
syntaxHighlighting(highlightStyle),
|
|
@@ -100,7 +98,8 @@ class CodeBlockAdvancedNodeView implements NodeView {
|
|
|
100
98
|
this.readOnlyCompartment.of(CodeMirror.editable.of(this.view.editable)),
|
|
101
99
|
closeBrackets(),
|
|
102
100
|
CodeMirror.editorAttributes.of({ class: 'code-block' }),
|
|
103
|
-
|
|
101
|
+
manageSelectionMarker(config.api),
|
|
102
|
+
prosemirrorDecorationPlugin(this.pmFacet, view, getPos),
|
|
104
103
|
],
|
|
105
104
|
});
|
|
106
105
|
|
|
@@ -115,7 +114,6 @@ class CodeBlockAdvancedNodeView implements NodeView {
|
|
|
115
114
|
|
|
116
115
|
destroy() {
|
|
117
116
|
this.cleanupDisabledState?.();
|
|
118
|
-
this.cleanupCopyButtonDecoration?.();
|
|
119
117
|
}
|
|
120
118
|
|
|
121
119
|
forwardUpdate(update: ViewUpdate) {
|
|
@@ -162,18 +160,6 @@ class CodeBlockAdvancedNodeView implements NodeView {
|
|
|
162
160
|
}
|
|
163
161
|
}
|
|
164
162
|
|
|
165
|
-
private addCopyButtonDecoration(node: PMNode | undefined) {
|
|
166
|
-
this.updating = true;
|
|
167
|
-
this.cm.dispatch({
|
|
168
|
-
effects: [
|
|
169
|
-
this.copyDecoCompartment.reconfigure(
|
|
170
|
-
node && node === this.node ? copyButtonDecorations : [],
|
|
171
|
-
),
|
|
172
|
-
],
|
|
173
|
-
});
|
|
174
|
-
this.updating = false;
|
|
175
|
-
}
|
|
176
|
-
|
|
177
163
|
private wordWrappingEnabled = false;
|
|
178
164
|
|
|
179
165
|
private updateWordWrap(node: PMNode) {
|
|
@@ -191,7 +177,7 @@ class CodeBlockAdvancedNodeView implements NodeView {
|
|
|
191
177
|
}
|
|
192
178
|
}
|
|
193
179
|
|
|
194
|
-
update(node: PMNode) {
|
|
180
|
+
update(node: PMNode, _: readonly Decoration[], innerDecorations: DecorationSource) {
|
|
195
181
|
this.maybeTryingToReachNodeSelection = false;
|
|
196
182
|
|
|
197
183
|
if (node.type !== this.node.type) {
|
|
@@ -210,9 +196,24 @@ class CodeBlockAdvancedNodeView implements NodeView {
|
|
|
210
196
|
this.cm.dispatch(tr);
|
|
211
197
|
this.updating = false;
|
|
212
198
|
});
|
|
199
|
+
this.updateProseMirrorDecorations(innerDecorations);
|
|
213
200
|
return true;
|
|
214
201
|
}
|
|
215
202
|
|
|
203
|
+
/**
|
|
204
|
+
* Updates a facet which stores information on the prosemirror decorations
|
|
205
|
+
*
|
|
206
|
+
* This then gets translated to codemirror decorations in `prosemirrorDecorationPlugin`
|
|
207
|
+
*/
|
|
208
|
+
private updateProseMirrorDecorations(decorationSource: DecorationSource) {
|
|
209
|
+
this.updating = true;
|
|
210
|
+
const computedFacet = this.pmFacet.compute([], () => decorationSource);
|
|
211
|
+
this.cm.dispatch({
|
|
212
|
+
effects: this.pmDecorationsCompartment.reconfigure(computedFacet),
|
|
213
|
+
});
|
|
214
|
+
this.updating = false;
|
|
215
|
+
}
|
|
216
|
+
|
|
216
217
|
stopEvent(e: Event) {
|
|
217
218
|
if (e instanceof MouseEvent && e.type === 'mousedown') {
|
|
218
219
|
// !Warning: Side effect!
|
|
@@ -25,7 +25,6 @@ export const syncCMWithPM = ({ view, update, offset }: Props): void => {
|
|
|
25
25
|
const pmSel = view.state.selection;
|
|
26
26
|
if (update.docChanged || pmSel.from !== selFrom || pmSel.to !== selTo) {
|
|
27
27
|
const tr = view.state.tr;
|
|
28
|
-
// eslint-disable-next-line @typescript-eslint/max-params
|
|
29
28
|
update.changes.iterChanges((fromA, toA, fromB, toB, text) => {
|
|
30
29
|
if (text.length) {
|
|
31
30
|
tr.replaceWith(offset + fromA, offset + toA, view.state.schema.text(text.toString()));
|
|
@@ -2,6 +2,7 @@ import { defaultKeymap, indentWithTab } from '@codemirror/commands';
|
|
|
2
2
|
import { Extension } from '@codemirror/state';
|
|
3
3
|
import { KeyBinding, keymap as cmKeymap } from '@codemirror/view';
|
|
4
4
|
|
|
5
|
+
import { browser } from '@atlaskit/editor-common/browser';
|
|
5
6
|
import { RelativeSelectionPos } from '@atlaskit/editor-common/selection';
|
|
6
7
|
import type { getPosHandlerNode } from '@atlaskit/editor-common/types';
|
|
7
8
|
import { exitCode } from '@atlaskit/editor-prosemirror/commands';
|
|
@@ -18,6 +19,7 @@ interface KeymapProps {
|
|
|
18
19
|
getPos: getPosHandlerNode;
|
|
19
20
|
selectCodeBlockNode: (relativeSelectionPos: RelativeSelectionPos | undefined) => void;
|
|
20
21
|
onMaybeNodeSelection: () => void;
|
|
22
|
+
customFindReplace: boolean;
|
|
21
23
|
}
|
|
22
24
|
|
|
23
25
|
export const keymapExtension = ({
|
|
@@ -26,9 +28,17 @@ export const keymapExtension = ({
|
|
|
26
28
|
getPos,
|
|
27
29
|
selectCodeBlockNode,
|
|
28
30
|
onMaybeNodeSelection,
|
|
31
|
+
customFindReplace,
|
|
29
32
|
}: KeymapProps): Extension => {
|
|
30
33
|
return cmKeymap.of(
|
|
31
|
-
codeBlockKeymap({
|
|
34
|
+
codeBlockKeymap({
|
|
35
|
+
view,
|
|
36
|
+
getNode,
|
|
37
|
+
getPos,
|
|
38
|
+
selectCodeBlockNode,
|
|
39
|
+
onMaybeNodeSelection,
|
|
40
|
+
customFindReplace,
|
|
41
|
+
}),
|
|
32
42
|
);
|
|
33
43
|
};
|
|
34
44
|
|
|
@@ -38,6 +48,7 @@ const codeBlockKeymap = ({
|
|
|
38
48
|
getPos,
|
|
39
49
|
selectCodeBlockNode,
|
|
40
50
|
onMaybeNodeSelection,
|
|
51
|
+
customFindReplace,
|
|
41
52
|
}: KeymapProps): readonly KeyBinding[] => {
|
|
42
53
|
return [
|
|
43
54
|
{
|
|
@@ -96,6 +107,25 @@ const codeBlockKeymap = ({
|
|
|
96
107
|
onMaybeNodeSelection,
|
|
97
108
|
}),
|
|
98
109
|
},
|
|
110
|
+
{
|
|
111
|
+
key: 'Ctrl-f',
|
|
112
|
+
mac: 'Cmd-f',
|
|
113
|
+
run: () => {
|
|
114
|
+
// Pass synthetic event to prosemirror
|
|
115
|
+
if (customFindReplace) {
|
|
116
|
+
view.dispatchEvent(
|
|
117
|
+
new KeyboardEvent('keydown', {
|
|
118
|
+
key: 'f',
|
|
119
|
+
code: 'KeyF',
|
|
120
|
+
metaKey: browser.mac ? true : false,
|
|
121
|
+
ctrlKey: browser.mac ? false : true,
|
|
122
|
+
}),
|
|
123
|
+
);
|
|
124
|
+
return true;
|
|
125
|
+
}
|
|
126
|
+
return false;
|
|
127
|
+
},
|
|
128
|
+
},
|
|
99
129
|
{
|
|
100
130
|
key: 'Ctrl-Enter',
|
|
101
131
|
run: () => {
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { Extension } from '@codemirror/state';
|
|
2
|
+
import { EditorView as CodeMirror } from '@codemirror/view';
|
|
3
|
+
|
|
4
|
+
import { type ExtractInjectionAPI } from '@atlaskit/editor-common/types';
|
|
5
|
+
|
|
6
|
+
import { CodeBlockAdvancedPlugin } from '../../codeBlockAdvancedPluginType';
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Hides selection marker decoration when focused on codemirror editor and re-enables on blur
|
|
10
|
+
*
|
|
11
|
+
* @param api
|
|
12
|
+
* @returns CodeMirror Extension
|
|
13
|
+
*/
|
|
14
|
+
export const manageSelectionMarker = (
|
|
15
|
+
api: ExtractInjectionAPI<CodeBlockAdvancedPlugin> | undefined,
|
|
16
|
+
): Extension => {
|
|
17
|
+
let decoHide: (() => void) | undefined;
|
|
18
|
+
return CodeMirror.focusChangeEffect.of((_state, focusing) => {
|
|
19
|
+
if (focusing) {
|
|
20
|
+
api?.selectionMarker?.actions.queueHideDecoration((hideDecoration) => {
|
|
21
|
+
decoHide = hideDecoration;
|
|
22
|
+
});
|
|
23
|
+
} else {
|
|
24
|
+
decoHide?.();
|
|
25
|
+
}
|
|
26
|
+
return null;
|
|
27
|
+
});
|
|
28
|
+
};
|