@atlaskit/editor-plugin-code-block 3.2.2 → 3.2.3

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,16 @@
1
1
  # @atlaskit/editor-plugin-code-block
2
2
 
3
+ ## 3.2.3
4
+
5
+ ### Patch Changes
6
+
7
+ - [#125133](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/pull-requests/125133)
8
+ [`d804e5dd3216b`](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/commits/d804e5dd3216b) -
9
+ ED-24226 - Add state to manage the toggle word wrap state of code blocks. New WeakMap added in
10
+ editor-common/src/code-block, as word wrap state is shared throughout the editor. Covers regular
11
+ changes to code block by the user via the node view update function. Covers breakout of code block
12
+ node. Does not cover drag&drop & cut&paste edge cases.
13
+
3
14
  ## 3.2.2
4
15
 
5
16
  ### Patch Changes
@@ -7,17 +7,20 @@ exports.copyContentToClipboard = exports.changeLanguage = void 0;
7
7
  exports.createInsertCodeBlockTransaction = createInsertCodeBlockTransaction;
8
8
  exports.ignoreFollowingMutations = void 0;
9
9
  exports.insertCodeBlockWithAnalytics = insertCodeBlockWithAnalytics;
10
- exports.wrapCodeBlock = exports.resetShouldIgnoreFollowingMutations = exports.resetCopiedState = exports.removeCodeBlock = void 0;
10
+ exports.toggleWordWrapStateForCodeBlockNode = exports.resetShouldIgnoreFollowingMutations = exports.resetCopiedState = exports.removeCodeBlock = void 0;
11
11
  var _analytics = require("@atlaskit/editor-common/analytics");
12
12
  var _clipboard = require("@atlaskit/editor-common/clipboard");
13
+ var _codeBlock = require("@atlaskit/editor-common/code-block");
13
14
  var _editorAnalytics = require("@atlaskit/editor-common/editor-analytics");
14
15
  var _insert = require("@atlaskit/editor-common/insert");
15
16
  var _state = require("@atlaskit/editor-prosemirror/state");
16
17
  var _utils = require("@atlaskit/editor-prosemirror/utils");
18
+ var _platformFeatureFlags = require("@atlaskit/platform-feature-flags");
17
19
  var _pluginKey = require("./plugin-key");
18
20
  var _actions = require("./pm-plugins/actions");
19
21
  var _codeBlockCopySelectionPlugin = require("./pm-plugins/codeBlockCopySelectionPlugin");
20
22
  var _transformToCodeBlock = require("./transform-to-code-block");
23
+ var _utils2 = require("./utils");
21
24
  var removeCodeBlock = exports.removeCodeBlock = function removeCodeBlock(state, dispatch) {
22
25
  var nodes = state.schema.nodes,
23
26
  tr = state.tr;
@@ -32,11 +35,6 @@ var removeCodeBlock = exports.removeCodeBlock = function removeCodeBlock(state,
32
35
  }
33
36
  return true;
34
37
  };
35
-
36
- // we will be hooking the button up in this follow up card ED-24222
37
- var wrapCodeBlock = exports.wrapCodeBlock = function wrapCodeBlock(state, dispatch) {
38
- return false;
39
- };
40
38
  var changeLanguage = exports.changeLanguage = function changeLanguage(editorAnalyticsAPI) {
41
39
  return function (language) {
42
40
  return function (state, dispatch) {
@@ -203,4 +201,25 @@ function insertCodeBlockWithAnalytics(inputMethod, analyticsAPI) {
203
201
  }
204
202
  return true;
205
203
  });
206
- }
204
+ }
205
+
206
+ /**
207
+ * Add the given node to the codeBlockWrappedStates WeakMap with the toggle boolean value.
208
+ */
209
+ var toggleWordWrapStateForCodeBlockNode = exports.toggleWordWrapStateForCodeBlockNode = function toggleWordWrapStateForCodeBlockNode(state) {
210
+ var _findCodeBlock;
211
+ if (!(0, _platformFeatureFlags.fg)('editor_support_code_block_wrapping')) {
212
+ return false;
213
+ }
214
+ var codeBlockNode = (_findCodeBlock = (0, _utils2.findCodeBlock)(state)) === null || _findCodeBlock === void 0 ? void 0 : _findCodeBlock.node;
215
+ if (!_codeBlock.codeBlockWrappedStates || !codeBlockNode) {
216
+ return false;
217
+ }
218
+ var currentValue = (0, _codeBlock.isCodeBlockWordWrapEnabled)(codeBlockNode);
219
+ _codeBlock.codeBlockWrappedStates.set(codeBlockNode, !currentValue);
220
+
221
+ // TODO: Remove in ED-24222. Leaving here for demo purposes.
222
+ // eslint-disable-next-line no-console
223
+ console.log("Code Block Word Wrap: Updating codeBlockWrappedStates with: ".concat(_codeBlock.codeBlockWrappedStates.get(codeBlockNode)));
224
+ return true;
225
+ };
@@ -9,6 +9,7 @@ var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/cl
9
9
  var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));
10
10
  var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
11
11
  var _rafSchd = _interopRequireDefault(require("raf-schd"));
12
+ var _codeBlock = require("@atlaskit/editor-common/code-block");
12
13
  var _utils = require("@atlaskit/editor-common/utils");
13
14
  var _model = require("@atlaskit/editor-prosemirror/model");
14
15
  var _platformFeatureFlags = require("@atlaskit/platform-feature-flags");
@@ -142,6 +143,9 @@ var CodeBlockView = exports.CodeBlockView = /*#__PURE__*/function () {
142
143
  return false;
143
144
  }
144
145
  if (node !== this.node) {
146
+ if ((0, _platformFeatureFlags.fg)('editor_support_code_block_wrapping')) {
147
+ (0, _codeBlock.transferCodeBlockWrappedValue)(this.node, node);
148
+ }
145
149
  if (node.attrs.language !== this.node.attrs.language) {
146
150
  this.contentDOM.setAttribute('data-language', node.attrs.language || '');
147
151
  }
@@ -105,7 +105,8 @@ var getToolbarConfig = exports.getToolbarConfig = function getToolbarConfig() {
105
105
  id: 'editor.codeBlock.wrap',
106
106
  type: 'button',
107
107
  icon: _WrapIcon.WrapIcon,
108
- onClick: _actions.wrapCodeBlock,
108
+ onClick: _actions.toggleWordWrapStateForCodeBlockNode,
109
+ // Hooking up here for demo purposes. To be revisited with ED-24222.
109
110
  title: formatMessage(_messages.codeBlockButtonMessages.wrapCode),
110
111
  tabIndex: null
111
112
  };
@@ -1,13 +1,16 @@
1
1
  import { ACTION, ACTION_SUBJECT, ACTION_SUBJECT_ID, EVENT_TYPE } from '@atlaskit/editor-common/analytics';
2
2
  import { copyToClipboard } from '@atlaskit/editor-common/clipboard';
3
+ import { codeBlockWrappedStates, isCodeBlockWordWrapEnabled } from '@atlaskit/editor-common/code-block';
3
4
  import { withAnalytics } from '@atlaskit/editor-common/editor-analytics';
4
5
  import { shouldSplitSelectedNodeOnNodeInsertion } from '@atlaskit/editor-common/insert';
5
6
  import { NodeSelection } from '@atlaskit/editor-prosemirror/state';
6
7
  import { findParentNodeOfType, findSelectedNodeOfType, isNodeSelection, removeParentNodeOfType, removeSelectedNode, safeInsert } from '@atlaskit/editor-prosemirror/utils';
8
+ import { fg } from '@atlaskit/platform-feature-flags';
7
9
  import { pluginKey } from './plugin-key';
8
10
  import { ACTIONS } from './pm-plugins/actions';
9
11
  import { copySelectionPluginKey } from './pm-plugins/codeBlockCopySelectionPlugin';
10
12
  import { transformToCodeBlockAction } from './transform-to-code-block';
13
+ import { findCodeBlock } from './utils';
11
14
  export const removeCodeBlock = (state, dispatch) => {
12
15
  const {
13
16
  schema: {
@@ -26,11 +29,6 @@ export const removeCodeBlock = (state, dispatch) => {
26
29
  }
27
30
  return true;
28
31
  };
29
-
30
- // we will be hooking the button up in this follow up card ED-24222
31
- export const wrapCodeBlock = (state, dispatch) => {
32
- return false;
33
- };
34
32
  export const changeLanguage = editorAnalyticsAPI => language => (state, dispatch) => {
35
33
  var _pluginKey$getState;
36
34
  const {
@@ -213,4 +211,25 @@ export function insertCodeBlockWithAnalytics(inputMethod, analyticsAPI) {
213
211
  }
214
212
  return true;
215
213
  });
216
- }
214
+ }
215
+
216
+ /**
217
+ * Add the given node to the codeBlockWrappedStates WeakMap with the toggle boolean value.
218
+ */
219
+ export const toggleWordWrapStateForCodeBlockNode = state => {
220
+ var _findCodeBlock;
221
+ if (!fg('editor_support_code_block_wrapping')) {
222
+ return false;
223
+ }
224
+ const codeBlockNode = (_findCodeBlock = findCodeBlock(state)) === null || _findCodeBlock === void 0 ? void 0 : _findCodeBlock.node;
225
+ if (!codeBlockWrappedStates || !codeBlockNode) {
226
+ return false;
227
+ }
228
+ const currentValue = isCodeBlockWordWrapEnabled(codeBlockNode);
229
+ codeBlockWrappedStates.set(codeBlockNode, !currentValue);
230
+
231
+ // TODO: Remove in ED-24222. Leaving here for demo purposes.
232
+ // eslint-disable-next-line no-console
233
+ console.log(`Code Block Word Wrap: Updating codeBlockWrappedStates with: ${codeBlockWrappedStates.get(codeBlockNode)}`);
234
+ return true;
235
+ };
@@ -1,5 +1,6 @@
1
1
  import _defineProperty from "@babel/runtime/helpers/defineProperty";
2
2
  import rafSchedule from 'raf-schd';
3
+ import { transferCodeBlockWrappedValue } from '@atlaskit/editor-common/code-block';
3
4
  import { browser } from '@atlaskit/editor-common/utils';
4
5
  import { DOMSerializer } from '@atlaskit/editor-prosemirror/model';
5
6
  import { fg } from '@atlaskit/platform-feature-flags';
@@ -119,6 +120,9 @@ export class CodeBlockView {
119
120
  return false;
120
121
  }
121
122
  if (node !== this.node) {
123
+ if (fg('editor_support_code_block_wrapping')) {
124
+ transferCodeBlockWrappedValue(this.node, node);
125
+ }
122
126
  if (node.attrs.language !== this.node.attrs.language) {
123
127
  this.contentDOM.setAttribute('data-language', node.attrs.language || '');
124
128
  }
@@ -3,7 +3,7 @@ import { findDomRefAtPos } from '@atlaskit/editor-prosemirror/utils';
3
3
  import CopyIcon from '@atlaskit/icon/glyph/copy';
4
4
  import RemoveIcon from '@atlaskit/icon/glyph/editor/remove';
5
5
  import { fg } from '@atlaskit/platform-feature-flags';
6
- import { changeLanguage, copyContentToClipboard, removeCodeBlock, resetCopiedState, wrapCodeBlock } from './actions';
6
+ import { changeLanguage, copyContentToClipboard, removeCodeBlock, resetCopiedState, toggleWordWrapStateForCodeBlockNode } from './actions';
7
7
  import { createLanguageList, DEFAULT_LANGUAGES, getLanguageIdentifier } from './language-list';
8
8
  import { pluginKey } from './plugin-key';
9
9
  import { provideVisualFeedbackForCopyButton, removeVisualFeedbackForCopyButton } from './pm-plugins/codeBlockCopySelectionPlugin';
@@ -86,7 +86,8 @@ export const getToolbarConfig = (allowCopyToClipboard = false, api) => (state, {
86
86
  id: 'editor.codeBlock.wrap',
87
87
  type: 'button',
88
88
  icon: WrapIcon,
89
- onClick: wrapCodeBlock,
89
+ onClick: toggleWordWrapStateForCodeBlockNode,
90
+ // Hooking up here for demo purposes. To be revisited with ED-24222.
90
91
  title: formatMessage(codeBlockButtonMessages.wrapCode),
91
92
  tabIndex: null
92
93
  };
@@ -1,13 +1,16 @@
1
1
  import { ACTION, ACTION_SUBJECT, ACTION_SUBJECT_ID, EVENT_TYPE } from '@atlaskit/editor-common/analytics';
2
2
  import { copyToClipboard } from '@atlaskit/editor-common/clipboard';
3
+ import { codeBlockWrappedStates, isCodeBlockWordWrapEnabled } from '@atlaskit/editor-common/code-block';
3
4
  import { withAnalytics } from '@atlaskit/editor-common/editor-analytics';
4
5
  import { shouldSplitSelectedNodeOnNodeInsertion } from '@atlaskit/editor-common/insert';
5
6
  import { NodeSelection } from '@atlaskit/editor-prosemirror/state';
6
7
  import { findParentNodeOfType, findSelectedNodeOfType, isNodeSelection, removeParentNodeOfType, removeSelectedNode, safeInsert } from '@atlaskit/editor-prosemirror/utils';
8
+ import { fg } from '@atlaskit/platform-feature-flags';
7
9
  import { pluginKey } from './plugin-key';
8
10
  import { ACTIONS } from './pm-plugins/actions';
9
11
  import { copySelectionPluginKey } from './pm-plugins/codeBlockCopySelectionPlugin';
10
12
  import { transformToCodeBlockAction } from './transform-to-code-block';
13
+ import { findCodeBlock } from './utils';
11
14
  export var removeCodeBlock = function removeCodeBlock(state, dispatch) {
12
15
  var nodes = state.schema.nodes,
13
16
  tr = state.tr;
@@ -22,11 +25,6 @@ export var removeCodeBlock = function removeCodeBlock(state, dispatch) {
22
25
  }
23
26
  return true;
24
27
  };
25
-
26
- // we will be hooking the button up in this follow up card ED-24222
27
- export var wrapCodeBlock = function wrapCodeBlock(state, dispatch) {
28
- return false;
29
- };
30
28
  export var changeLanguage = function changeLanguage(editorAnalyticsAPI) {
31
29
  return function (language) {
32
30
  return function (state, dispatch) {
@@ -193,4 +191,25 @@ export function insertCodeBlockWithAnalytics(inputMethod, analyticsAPI) {
193
191
  }
194
192
  return true;
195
193
  });
196
- }
194
+ }
195
+
196
+ /**
197
+ * Add the given node to the codeBlockWrappedStates WeakMap with the toggle boolean value.
198
+ */
199
+ export var toggleWordWrapStateForCodeBlockNode = function toggleWordWrapStateForCodeBlockNode(state) {
200
+ var _findCodeBlock;
201
+ if (!fg('editor_support_code_block_wrapping')) {
202
+ return false;
203
+ }
204
+ var codeBlockNode = (_findCodeBlock = findCodeBlock(state)) === null || _findCodeBlock === void 0 ? void 0 : _findCodeBlock.node;
205
+ if (!codeBlockWrappedStates || !codeBlockNode) {
206
+ return false;
207
+ }
208
+ var currentValue = isCodeBlockWordWrapEnabled(codeBlockNode);
209
+ codeBlockWrappedStates.set(codeBlockNode, !currentValue);
210
+
211
+ // TODO: Remove in ED-24222. Leaving here for demo purposes.
212
+ // eslint-disable-next-line no-console
213
+ console.log("Code Block Word Wrap: Updating codeBlockWrappedStates with: ".concat(codeBlockWrappedStates.get(codeBlockNode)));
214
+ return true;
215
+ };
@@ -2,6 +2,7 @@ import _classCallCheck from "@babel/runtime/helpers/classCallCheck";
2
2
  import _createClass from "@babel/runtime/helpers/createClass";
3
3
  import _defineProperty from "@babel/runtime/helpers/defineProperty";
4
4
  import rafSchedule from 'raf-schd';
5
+ import { transferCodeBlockWrappedValue } from '@atlaskit/editor-common/code-block';
5
6
  import { browser } from '@atlaskit/editor-common/utils';
6
7
  import { DOMSerializer } from '@atlaskit/editor-prosemirror/model';
7
8
  import { fg } from '@atlaskit/platform-feature-flags';
@@ -135,6 +136,9 @@ export var CodeBlockView = /*#__PURE__*/function () {
135
136
  return false;
136
137
  }
137
138
  if (node !== this.node) {
139
+ if (fg('editor_support_code_block_wrapping')) {
140
+ transferCodeBlockWrappedValue(this.node, node);
141
+ }
138
142
  if (node.attrs.language !== this.node.attrs.language) {
139
143
  this.contentDOM.setAttribute('data-language', node.attrs.language || '');
140
144
  }
@@ -3,7 +3,7 @@ import { findDomRefAtPos } from '@atlaskit/editor-prosemirror/utils';
3
3
  import CopyIcon from '@atlaskit/icon/glyph/copy';
4
4
  import RemoveIcon from '@atlaskit/icon/glyph/editor/remove';
5
5
  import { fg } from '@atlaskit/platform-feature-flags';
6
- import { changeLanguage, copyContentToClipboard, removeCodeBlock, resetCopiedState, wrapCodeBlock } from './actions';
6
+ import { changeLanguage, copyContentToClipboard, removeCodeBlock, resetCopiedState, toggleWordWrapStateForCodeBlockNode } from './actions';
7
7
  import { createLanguageList, DEFAULT_LANGUAGES, getLanguageIdentifier } from './language-list';
8
8
  import { pluginKey } from './plugin-key';
9
9
  import { provideVisualFeedbackForCopyButton, removeVisualFeedbackForCopyButton } from './pm-plugins/codeBlockCopySelectionPlugin';
@@ -95,7 +95,8 @@ export var getToolbarConfig = function getToolbarConfig() {
95
95
  id: 'editor.codeBlock.wrap',
96
96
  type: 'button',
97
97
  icon: WrapIcon,
98
- onClick: wrapCodeBlock,
98
+ onClick: toggleWordWrapStateForCodeBlockNode,
99
+ // Hooking up here for demo purposes. To be revisited with ED-24222.
99
100
  title: formatMessage(codeBlockButtonMessages.wrapCode),
100
101
  tabIndex: null
101
102
  };
@@ -2,7 +2,6 @@ import type { EditorAnalyticsAPI, INPUT_METHOD } from '@atlaskit/editor-common/a
2
2
  import type { Command } from '@atlaskit/editor-common/types';
3
3
  import type { EditorState } from '@atlaskit/editor-prosemirror/state';
4
4
  export declare const removeCodeBlock: Command;
5
- export declare const wrapCodeBlock: Command;
6
5
  export declare const changeLanguage: (editorAnalyticsAPI: EditorAnalyticsAPI | undefined) => (language: string) => Command;
7
6
  export declare const copyContentToClipboard: Command;
8
7
  export declare const resetCopiedState: Command;
@@ -17,3 +16,7 @@ export declare function createInsertCodeBlockTransaction({ state }: {
17
16
  state: EditorState;
18
17
  }): import("prosemirror-state").Transaction;
19
18
  export declare function insertCodeBlockWithAnalytics(inputMethod: INPUT_METHOD, analyticsAPI?: EditorAnalyticsAPI): Command;
19
+ /**
20
+ * Add the given node to the codeBlockWrappedStates WeakMap with the toggle boolean value.
21
+ */
22
+ export declare const toggleWordWrapStateForCodeBlockNode: Command;
@@ -2,7 +2,7 @@ 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
4
  import type { CodeBlockPlugin } from '../index';
5
- import type { CodeBlockState } from './main-state';
5
+ import { type CodeBlockState } from './main-state';
6
6
  export declare const createPlugin: ({ useLongPressSelection, getIntl, allowCompositionInputOverride, api, isWrapped, }: {
7
7
  useLongPressSelection?: boolean | undefined;
8
8
  getIntl: () => IntlShape;
@@ -2,7 +2,6 @@ import type { EditorAnalyticsAPI, INPUT_METHOD } from '@atlaskit/editor-common/a
2
2
  import type { Command } from '@atlaskit/editor-common/types';
3
3
  import type { EditorState } from '@atlaskit/editor-prosemirror/state';
4
4
  export declare const removeCodeBlock: Command;
5
- export declare const wrapCodeBlock: Command;
6
5
  export declare const changeLanguage: (editorAnalyticsAPI: EditorAnalyticsAPI | undefined) => (language: string) => Command;
7
6
  export declare const copyContentToClipboard: Command;
8
7
  export declare const resetCopiedState: Command;
@@ -17,3 +16,7 @@ export declare function createInsertCodeBlockTransaction({ state }: {
17
16
  state: EditorState;
18
17
  }): import("prosemirror-state").Transaction;
19
18
  export declare function insertCodeBlockWithAnalytics(inputMethod: INPUT_METHOD, analyticsAPI?: EditorAnalyticsAPI): Command;
19
+ /**
20
+ * Add the given node to the codeBlockWrappedStates WeakMap with the toggle boolean value.
21
+ */
22
+ export declare const toggleWordWrapStateForCodeBlockNode: Command;
@@ -2,7 +2,7 @@ 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
4
  import type { CodeBlockPlugin } from '../index';
5
- import type { CodeBlockState } from './main-state';
5
+ import { type CodeBlockState } from './main-state';
6
6
  export declare const createPlugin: ({ useLongPressSelection, getIntl, allowCompositionInputOverride, api, isWrapped, }: {
7
7
  useLongPressSelection?: boolean | undefined;
8
8
  getIntl: () => IntlShape;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atlaskit/editor-plugin-code-block",
3
- "version": "3.2.2",
3
+ "version": "3.2.3",
4
4
  "description": "Code block plugin for @atlaskit/editor-core",
5
5
  "author": "Atlassian Pty Ltd",
6
6
  "license": "Apache-2.0",