@atlaskit/editor-plugin-code-block 3.5.15 → 3.6.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 CHANGED
@@ -1,5 +1,31 @@
1
1
  # @atlaskit/editor-plugin-code-block
2
2
 
3
+ ## 3.6.0
4
+
5
+ ### Minor Changes
6
+
7
+ - [#103918](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/pull-requests/103918)
8
+ [`29844093c6ab4`](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/commits/29844093c6ab4) -
9
+ Expose new shared state for code block plugin which indicates the current node that the copy text
10
+ button is hovered for. Display highlight decorations for the copy text button in the advanced code
11
+ block plugin.
12
+
13
+ ### Patch Changes
14
+
15
+ - Updated dependencies
16
+
17
+ ## 3.5.16
18
+
19
+ ### Patch Changes
20
+
21
+ - [#100411](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/pull-requests/100411)
22
+ [`14499ab145534`](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/commits/14499ab145534) -
23
+ [ux] Introduces advanced code block as per:
24
+ https://hello.atlassian.net/wiki/spaces/EDITOR/pages/4632293323/Editor+RFC+063+Advanced+code+blocks.
25
+ This can be added to an existing editor preset to enrich the code block experience with syntax
26
+ highlighting and can be extended for other features via CodeMirror extensions (ie. autocompletion,
27
+ code folding etc.).
28
+
3
29
  ## 3.5.15
4
30
 
5
31
  ### Patch Changes
@@ -36,6 +36,14 @@ var codeBlockPlugin = function codeBlockPlugin(_ref) {
36
36
  node: _adfSchema.codeBlock
37
37
  }];
38
38
  },
39
+ getSharedState: function getSharedState(state) {
40
+ if (!state) {
41
+ return undefined;
42
+ }
43
+ return {
44
+ copyButtonHoverNode: _codeBlockCopySelectionPlugin.copySelectionPluginKey.getState(state).codeBlockNode
45
+ };
46
+ },
39
47
  pmPlugins: function pmPlugins() {
40
48
  return [{
41
49
  name: 'codeBlock',
@@ -23,12 +23,14 @@ function getSelectionDecorationStartAndEnd(_ref) {
23
23
  });
24
24
  if (!codeBlockNode) {
25
25
  return {
26
- decorationStartAndEnd: undefined
26
+ decorationStartAndEnd: undefined,
27
+ codeBlockNode: undefined
27
28
  };
28
29
  }
29
30
  var decorationStartAndEnd = [codeBlockNode.start, codeBlockNode.start + codeBlockNode.node.nodeSize];
30
31
  return {
31
- decorationStartAndEnd: decorationStartAndEnd
32
+ decorationStartAndEnd: decorationStartAndEnd,
33
+ codeBlockNode: codeBlockNode.node
32
34
  };
33
35
  }
34
36
  function codeBlockCopySelectionPlugin() {
@@ -105,7 +105,11 @@ var createPlugin = exports.createPlugin = function createPlugin(_ref) {
105
105
  var codeBlockNodes = (0, _platformFeatureFlags.fg)('editor_code_wrapping_perf_improvement_ed-25141') ? (0, _utils.getAllChangedCodeBlocksInTransaction)(tr) : (0, _utils.getAllCodeBlockNodesInDoc)(newState);
106
106
  if (codeBlockNodes) {
107
107
  (0, _codeBlock.updateCodeBlockWrappedStateNodeKeys)(codeBlockNodes, _oldState);
108
- updatedDecorationSet = (0, _decorators.updateCodeBlockDecorations)(tr, codeBlockNodes, updatedDecorationSet);
108
+ // Disabled when using advanced code block for performance reasons
109
+ // @ts-expect-error Code block advanced cannot depend on code block
110
+ if ((api === null || api === void 0 ? void 0 : api.codeBlockAdvanced) === undefined) {
111
+ updatedDecorationSet = (0, _decorators.updateCodeBlockDecorations)(tr, codeBlockNodes, updatedDecorationSet);
112
+ }
109
113
  }
110
114
  var newPluginState = _objectSpread(_objectSpread({}, pluginState), {}, {
111
115
  pos: _node ? _node.pos : null,
@@ -6,7 +6,7 @@ import { IconCode } from '@atlaskit/editor-common/quick-insert';
6
6
  import { fg } from '@atlaskit/platform-feature-flags';
7
7
  import { createInsertCodeBlockTransaction, insertCodeBlockWithAnalytics } from './editor-commands';
8
8
  import { codeBlockAutoFullStopTransformPlugin } from './pm-plugins/codeBlockAutoFullStopTransformPlugin';
9
- import { codeBlockCopySelectionPlugin } from './pm-plugins/codeBlockCopySelectionPlugin';
9
+ import { codeBlockCopySelectionPlugin, copySelectionPluginKey } from './pm-plugins/codeBlockCopySelectionPlugin';
10
10
  import ideUX from './pm-plugins/ide-ux';
11
11
  import { createCodeBlockInputRule } from './pm-plugins/input-rule';
12
12
  import keymap from './pm-plugins/keymaps';
@@ -27,6 +27,14 @@ const codeBlockPlugin = ({
27
27
  node: codeBlock
28
28
  }];
29
29
  },
30
+ getSharedState(state) {
31
+ if (!state) {
32
+ return undefined;
33
+ }
34
+ return {
35
+ copyButtonHoverNode: copySelectionPluginKey.getState(state).codeBlockNode
36
+ };
37
+ },
30
38
  pmPlugins() {
31
39
  return [{
32
40
  name: 'codeBlock',
@@ -13,12 +13,14 @@ function getSelectionDecorationStartAndEnd({
13
13
  });
14
14
  if (!codeBlockNode) {
15
15
  return {
16
- decorationStartAndEnd: undefined
16
+ decorationStartAndEnd: undefined,
17
+ codeBlockNode: undefined
17
18
  };
18
19
  }
19
20
  const decorationStartAndEnd = [codeBlockNode.start, codeBlockNode.start + codeBlockNode.node.nodeSize];
20
21
  return {
21
- decorationStartAndEnd
22
+ decorationStartAndEnd,
23
+ codeBlockNode: codeBlockNode.node
22
24
  };
23
25
  }
24
26
  export function codeBlockCopySelectionPlugin() {
@@ -95,7 +95,11 @@ export const createPlugin = ({
95
95
  const codeBlockNodes = fg('editor_code_wrapping_perf_improvement_ed-25141') ? getAllChangedCodeBlocksInTransaction(tr) : getAllCodeBlockNodesInDoc(newState);
96
96
  if (codeBlockNodes) {
97
97
  updateCodeBlockWrappedStateNodeKeys(codeBlockNodes, _oldState);
98
- updatedDecorationSet = updateCodeBlockDecorations(tr, codeBlockNodes, updatedDecorationSet);
98
+ // Disabled when using advanced code block for performance reasons
99
+ // @ts-expect-error Code block advanced cannot depend on code block
100
+ if ((api === null || api === void 0 ? void 0 : api.codeBlockAdvanced) === undefined) {
101
+ updatedDecorationSet = updateCodeBlockDecorations(tr, codeBlockNodes, updatedDecorationSet);
102
+ }
99
103
  }
100
104
  const newPluginState = {
101
105
  ...pluginState,
@@ -9,7 +9,7 @@ import { IconCode } from '@atlaskit/editor-common/quick-insert';
9
9
  import { fg } from '@atlaskit/platform-feature-flags';
10
10
  import { createInsertCodeBlockTransaction, insertCodeBlockWithAnalytics } from './editor-commands';
11
11
  import { codeBlockAutoFullStopTransformPlugin } from './pm-plugins/codeBlockAutoFullStopTransformPlugin';
12
- import { codeBlockCopySelectionPlugin } from './pm-plugins/codeBlockCopySelectionPlugin';
12
+ import { codeBlockCopySelectionPlugin, copySelectionPluginKey } from './pm-plugins/codeBlockCopySelectionPlugin';
13
13
  import ideUX from './pm-plugins/ide-ux';
14
14
  import { createCodeBlockInputRule } from './pm-plugins/input-rule';
15
15
  import keymap from './pm-plugins/keymaps';
@@ -29,6 +29,14 @@ var codeBlockPlugin = function codeBlockPlugin(_ref) {
29
29
  node: codeBlock
30
30
  }];
31
31
  },
32
+ getSharedState: function getSharedState(state) {
33
+ if (!state) {
34
+ return undefined;
35
+ }
36
+ return {
37
+ copyButtonHoverNode: copySelectionPluginKey.getState(state).codeBlockNode
38
+ };
39
+ },
32
40
  pmPlugins: function pmPlugins() {
33
41
  return [{
34
42
  name: 'codeBlock',
@@ -13,12 +13,14 @@ function getSelectionDecorationStartAndEnd(_ref) {
13
13
  });
14
14
  if (!codeBlockNode) {
15
15
  return {
16
- decorationStartAndEnd: undefined
16
+ decorationStartAndEnd: undefined,
17
+ codeBlockNode: undefined
17
18
  };
18
19
  }
19
20
  var decorationStartAndEnd = [codeBlockNode.start, codeBlockNode.start + codeBlockNode.node.nodeSize];
20
21
  return {
21
- decorationStartAndEnd: decorationStartAndEnd
22
+ decorationStartAndEnd: decorationStartAndEnd,
23
+ codeBlockNode: codeBlockNode.node
22
24
  };
23
25
  }
24
26
  export function codeBlockCopySelectionPlugin() {
@@ -100,7 +100,11 @@ export var createPlugin = function createPlugin(_ref) {
100
100
  var codeBlockNodes = fg('editor_code_wrapping_perf_improvement_ed-25141') ? getAllChangedCodeBlocksInTransaction(tr) : getAllCodeBlockNodesInDoc(newState);
101
101
  if (codeBlockNodes) {
102
102
  updateCodeBlockWrappedStateNodeKeys(codeBlockNodes, _oldState);
103
- updatedDecorationSet = updateCodeBlockDecorations(tr, codeBlockNodes, updatedDecorationSet);
103
+ // Disabled when using advanced code block for performance reasons
104
+ // @ts-expect-error Code block advanced cannot depend on code block
105
+ if ((api === null || api === void 0 ? void 0 : api.codeBlockAdvanced) === undefined) {
106
+ updatedDecorationSet = updateCodeBlockDecorations(tr, codeBlockNodes, updatedDecorationSet);
107
+ }
104
108
  }
105
109
  var newPluginState = _objectSpread(_objectSpread({}, pluginState), {}, {
106
110
  pos: _node ? _node.pos : null,
@@ -5,17 +5,23 @@ import type { CompositionPlugin } from '@atlaskit/editor-plugin-composition';
5
5
  import type { DecorationsPlugin } from '@atlaskit/editor-plugin-decorations';
6
6
  import type { EditorDisabledPlugin } from '@atlaskit/editor-plugin-editor-disabled';
7
7
  import type { FeatureFlagsPlugin } from '@atlaskit/editor-plugin-feature-flags';
8
+ import type { Node as PMNode } from '@atlaskit/editor-prosemirror/model';
8
9
  import type { CodeBlockOptions } from './types';
10
+ type CodeBlockDependencies = [
11
+ DecorationsPlugin,
12
+ CompositionPlugin,
13
+ OptionalPlugin<AnalyticsPlugin>,
14
+ OptionalPlugin<EditorDisabledPlugin>,
15
+ OptionalPlugin<FeatureFlagsPlugin>
16
+ ];
9
17
  export type CodeBlockPlugin = NextEditorPlugin<'codeBlock', {
10
18
  pluginConfiguration: CodeBlockOptions | undefined;
11
- dependencies: [
12
- DecorationsPlugin,
13
- CompositionPlugin,
14
- OptionalPlugin<AnalyticsPlugin>,
15
- OptionalPlugin<EditorDisabledPlugin>,
16
- OptionalPlugin<FeatureFlagsPlugin>
17
- ];
19
+ dependencies: CodeBlockDependencies;
20
+ sharedState: {
21
+ copyButtonHoverNode: PMNode;
22
+ } | undefined;
18
23
  actions: {
19
24
  insertCodeBlock: (inputMethod: INPUT_METHOD) => Command;
20
25
  };
21
26
  }>;
27
+ export {};
@@ -1,9 +1,11 @@
1
1
  import { SafePlugin } from '@atlaskit/editor-common/safe-plugin';
2
+ import type { Node as PMNode } from '@atlaskit/editor-prosemirror/model';
2
3
  import { PluginKey } from '@atlaskit/editor-prosemirror/state';
3
4
  import type { EditorState, Transaction } from '@atlaskit/editor-prosemirror/state';
4
5
  export declare const copySelectionPluginKey: PluginKey<any>;
5
6
  type CodeBlockCopySelectionPluginState = {
6
7
  decorationStartAndEnd?: [start: number, end: number];
8
+ codeBlockNode?: PMNode;
7
9
  };
8
10
  export declare function codeBlockCopySelectionPlugin(): SafePlugin<CodeBlockCopySelectionPluginState>;
9
11
  export declare function provideVisualFeedbackForCopyButton(state: EditorState, dispatch?: (tr: Transaction) => void): boolean;
@@ -1,6 +1,7 @@
1
1
  import type { IntlShape } from 'react-intl-next';
2
2
  import { SafePlugin } from '@atlaskit/editor-common/safe-plugin';
3
3
  import type { ExtractInjectionAPI } from '@atlaskit/editor-common/types';
4
+ import type { Node as PMNode } from '@atlaskit/editor-prosemirror/model';
4
5
  import { DecorationSet } from '@atlaskit/editor-prosemirror/view';
5
6
  import type { CodeBlockPlugin } from '../index';
6
7
  import { type CodeBlockState } from './main-state';
@@ -36,6 +37,9 @@ export declare const createPlugin: ({ useLongPressSelection, getIntl, allowCompo
36
37
  pluginConfiguration: import("@atlaskit/editor-common/types").FeatureFlags;
37
38
  sharedState: import("@atlaskit/editor-common/types").FeatureFlags;
38
39
  }, import("@atlaskit/editor-common/types").FeatureFlags>>];
40
+ sharedState: {
41
+ copyButtonHoverNode: PMNode;
42
+ } | undefined;
39
43
  actions: {
40
44
  insertCodeBlock: (inputMethod: import("@atlaskit/editor-common/analytics").INPUT_METHOD) => import("@atlaskit/editor-common/types").Command;
41
45
  };
@@ -5,17 +5,23 @@ import type { CompositionPlugin } from '@atlaskit/editor-plugin-composition';
5
5
  import type { DecorationsPlugin } from '@atlaskit/editor-plugin-decorations';
6
6
  import type { EditorDisabledPlugin } from '@atlaskit/editor-plugin-editor-disabled';
7
7
  import type { FeatureFlagsPlugin } from '@atlaskit/editor-plugin-feature-flags';
8
+ import type { Node as PMNode } from '@atlaskit/editor-prosemirror/model';
8
9
  import type { CodeBlockOptions } from './types';
10
+ type CodeBlockDependencies = [
11
+ DecorationsPlugin,
12
+ CompositionPlugin,
13
+ OptionalPlugin<AnalyticsPlugin>,
14
+ OptionalPlugin<EditorDisabledPlugin>,
15
+ OptionalPlugin<FeatureFlagsPlugin>
16
+ ];
9
17
  export type CodeBlockPlugin = NextEditorPlugin<'codeBlock', {
10
18
  pluginConfiguration: CodeBlockOptions | undefined;
11
- dependencies: [
12
- DecorationsPlugin,
13
- CompositionPlugin,
14
- OptionalPlugin<AnalyticsPlugin>,
15
- OptionalPlugin<EditorDisabledPlugin>,
16
- OptionalPlugin<FeatureFlagsPlugin>
17
- ];
19
+ dependencies: CodeBlockDependencies;
20
+ sharedState: {
21
+ copyButtonHoverNode: PMNode;
22
+ } | undefined;
18
23
  actions: {
19
24
  insertCodeBlock: (inputMethod: INPUT_METHOD) => Command;
20
25
  };
21
26
  }>;
27
+ export {};
@@ -1,4 +1,5 @@
1
1
  import { SafePlugin } from '@atlaskit/editor-common/safe-plugin';
2
+ import type { Node as PMNode } from '@atlaskit/editor-prosemirror/model';
2
3
  import { PluginKey } from '@atlaskit/editor-prosemirror/state';
3
4
  import type { EditorState, Transaction } from '@atlaskit/editor-prosemirror/state';
4
5
  export declare const copySelectionPluginKey: PluginKey<any>;
@@ -7,6 +8,7 @@ type CodeBlockCopySelectionPluginState = {
7
8
  start: number,
8
9
  end: number
9
10
  ];
11
+ codeBlockNode?: PMNode;
10
12
  };
11
13
  export declare function codeBlockCopySelectionPlugin(): SafePlugin<CodeBlockCopySelectionPluginState>;
12
14
  export declare function provideVisualFeedbackForCopyButton(state: EditorState, dispatch?: (tr: Transaction) => void): boolean;
@@ -1,6 +1,7 @@
1
1
  import type { IntlShape } from 'react-intl-next';
2
2
  import { SafePlugin } from '@atlaskit/editor-common/safe-plugin';
3
3
  import type { ExtractInjectionAPI } from '@atlaskit/editor-common/types';
4
+ import type { Node as PMNode } from '@atlaskit/editor-prosemirror/model';
4
5
  import { DecorationSet } from '@atlaskit/editor-prosemirror/view';
5
6
  import type { CodeBlockPlugin } from '../index';
6
7
  import { type CodeBlockState } from './main-state';
@@ -44,6 +45,9 @@ export declare const createPlugin: ({ useLongPressSelection, getIntl, allowCompo
44
45
  sharedState: import("@atlaskit/editor-common/types").FeatureFlags;
45
46
  }, import("@atlaskit/editor-common/types").FeatureFlags>>
46
47
  ];
48
+ sharedState: {
49
+ copyButtonHoverNode: PMNode;
50
+ } | undefined;
47
51
  actions: {
48
52
  insertCodeBlock: (inputMethod: import("@atlaskit/editor-common/analytics").INPUT_METHOD) => import("@atlaskit/editor-common/types").Command;
49
53
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atlaskit/editor-plugin-code-block",
3
- "version": "3.5.15",
3
+ "version": "3.6.0",
4
4
  "description": "Code block plugin for @atlaskit/editor-core",
5
5
  "author": "Atlassian Pty Ltd",
6
6
  "license": "Apache-2.0",
@@ -33,13 +33,13 @@
33
33
  "dependencies": {
34
34
  "@atlaskit/adf-schema": "^46.1.0",
35
35
  "@atlaskit/code": "^15.6.0",
36
- "@atlaskit/editor-common": "^99.0.0",
37
- "@atlaskit/editor-plugin-analytics": "^1.10.0",
36
+ "@atlaskit/editor-common": "^99.5.0",
37
+ "@atlaskit/editor-plugin-analytics": "^1.11.0",
38
38
  "@atlaskit/editor-plugin-composition": "^1.2.0",
39
39
  "@atlaskit/editor-plugin-decorations": "^1.3.0",
40
40
  "@atlaskit/editor-plugin-editor-disabled": "^1.3.0",
41
41
  "@atlaskit/editor-prosemirror": "6.2.1",
42
- "@atlaskit/icon": "^23.3.0",
42
+ "@atlaskit/icon": "^23.4.0",
43
43
  "@atlaskit/platform-feature-flags": "^0.3.0",
44
44
  "@atlaskit/prosemirror-input-rules": "^3.2.0",
45
45
  "@babel/runtime": "^7.0.0"