@atlaskit/editor-plugin-code-block 3.3.4 → 3.3.6

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,20 @@
1
1
  # @atlaskit/editor-plugin-code-block
2
2
 
3
+ ## 3.3.6
4
+
5
+ ### Patch Changes
6
+
7
+ - Updated dependencies
8
+
9
+ ## 3.3.5
10
+
11
+ ### Patch Changes
12
+
13
+ - [#130377](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/pull-requests/130377)
14
+ [`3dad41b881f45`](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/commits/3dad41b881f45) -
15
+ [ux] ED-24613 add support for decorator mapping on new transactions and live view button enable
16
+ - Updated dependencies
17
+
3
18
  ## 3.3.4
4
19
 
5
20
  ### Patch Changes
@@ -70,20 +70,18 @@ var createPlugin = exports.createPlugin = function createPlugin(_ref) {
70
70
  }
71
71
  return decorationSetFromState;
72
72
  };
73
- var createLineDecoratorPluginState = function createLineDecoratorPluginState(pluginState, tr, state) {
74
- var decorationSetFromState = pluginState.decorations;
73
+ var updateLineDecorationSet = function updateLineDecorationSet(tr, state, decorationSet) {
75
74
  // remove all the line number children from the decorations set. 'undefined, undefined' is used to find() the whole doc.
76
- var children = decorationSetFromState.find(undefined, undefined, function (spec) {
75
+ var children = decorationSet.find(undefined, undefined, function (spec) {
77
76
  return spec.type === _decorators.DECORATION_WIDGET_TYPE;
78
77
  });
79
- decorationSetFromState = decorationSetFromState.remove(children);
78
+ decorationSet = decorationSet.remove(children);
80
79
 
81
80
  // regenerate all the line number for the documents code blocks
82
81
  var lineDecorators = createLineNumberDecoratorsFromDecendants(state);
83
82
 
84
83
  // add the newly generated line numbers to the decorations set
85
- decorationSetFromState = decorationSetFromState.add(tr.doc, (0, _toConsumableArray2.default)(lineDecorators));
86
- return decorationSetFromState;
84
+ return decorationSet.add(tr.doc, (0, _toConsumableArray2.default)(lineDecorators));
87
85
  };
88
86
 
89
87
  // ME-1599: Composition on mobile was causing the DOM observer to mutate the code block
@@ -147,10 +145,17 @@ var createPlugin = exports.createPlugin = function createPlugin(_ref) {
147
145
  }
148
146
  if (tr.docChanged) {
149
147
  var _node = (0, _utils2.findCodeBlock)(newState, tr.selection);
148
+
149
+ // Updates mapping position of all existing decorations to new positions
150
+ // specifically used for updating word wrap node decorators
151
+ var updatedDecorationSet = pluginState.decorations.map(tr.mapping, tr.doc);
152
+
153
+ // Wipe and regenerate all line numbers in the document
154
+ updatedDecorationSet = updateLineDecorationSet(tr, newState, updatedDecorationSet);
150
155
  var newPluginState = _objectSpread(_objectSpread({}, pluginState), {}, {
151
156
  pos: _node ? _node.pos : null,
152
157
  isNodeSelected: tr.selection instanceof _state.NodeSelection,
153
- decorations: (0, _platformFeatureFlags.fg)('editor_support_code_block_wrapping') ? createLineDecoratorPluginState(pluginState, tr, newState) : _view.DecorationSet.empty
158
+ decorations: (0, _platformFeatureFlags.fg)('editor_support_code_block_wrapping') ? updatedDecorationSet : _view.DecorationSet.empty
154
159
  });
155
160
  return newPluginState;
156
161
  }
@@ -106,6 +106,7 @@ var getToolbarConfig = exports.getToolbarConfig = function getToolbarConfig() {
106
106
  var codeBlockWrapButton = {
107
107
  id: 'editor.codeBlock.wrap',
108
108
  type: 'button',
109
+ supportsViewMode: true,
109
110
  icon: _WrapIcon.WrapIcon,
110
111
  onClick: (0, _actions.toggleWordWrapStateForCodeBlockNode)(editorAnalyticsAPI),
111
112
  // Hooking up here for demo purposes. To be revisited with ED-24222.
@@ -58,18 +58,16 @@ export const createPlugin = ({
58
58
  }
59
59
  return decorationSetFromState;
60
60
  };
61
- const createLineDecoratorPluginState = (pluginState, tr, state) => {
62
- let decorationSetFromState = pluginState.decorations;
61
+ const updateLineDecorationSet = (tr, state, decorationSet) => {
63
62
  // remove all the line number children from the decorations set. 'undefined, undefined' is used to find() the whole doc.
64
- const children = decorationSetFromState.find(undefined, undefined, spec => spec.type === DECORATION_WIDGET_TYPE);
65
- decorationSetFromState = decorationSetFromState.remove(children);
63
+ const children = decorationSet.find(undefined, undefined, spec => spec.type === DECORATION_WIDGET_TYPE);
64
+ decorationSet = decorationSet.remove(children);
66
65
 
67
66
  // regenerate all the line number for the documents code blocks
68
67
  const lineDecorators = createLineNumberDecoratorsFromDecendants(state);
69
68
 
70
69
  // add the newly generated line numbers to the decorations set
71
- decorationSetFromState = decorationSetFromState.add(tr.doc, [...lineDecorators]);
72
- return decorationSetFromState;
70
+ return decorationSet.add(tr.doc, [...lineDecorators]);
73
71
  };
74
72
 
75
73
  // ME-1599: Composition on mobile was causing the DOM observer to mutate the code block
@@ -132,11 +130,18 @@ export const createPlugin = ({
132
130
  }
133
131
  if (tr.docChanged) {
134
132
  const node = findCodeBlock(newState, tr.selection);
133
+
134
+ // Updates mapping position of all existing decorations to new positions
135
+ // specifically used for updating word wrap node decorators
136
+ let updatedDecorationSet = pluginState.decorations.map(tr.mapping, tr.doc);
137
+
138
+ // Wipe and regenerate all line numbers in the document
139
+ updatedDecorationSet = updateLineDecorationSet(tr, newState, updatedDecorationSet);
135
140
  const newPluginState = {
136
141
  ...pluginState,
137
142
  pos: node ? node.pos : null,
138
143
  isNodeSelected: tr.selection instanceof NodeSelection,
139
- decorations: fg('editor_support_code_block_wrapping') ? createLineDecoratorPluginState(pluginState, tr, newState) : DecorationSet.empty
144
+ decorations: fg('editor_support_code_block_wrapping') ? updatedDecorationSet : DecorationSet.empty
140
145
  };
141
146
  return newPluginState;
142
147
  }
@@ -87,6 +87,7 @@ export const getToolbarConfig = (allowCopyToClipboard = false, api) => (state, {
87
87
  const codeBlockWrapButton = {
88
88
  id: 'editor.codeBlock.wrap',
89
89
  type: 'button',
90
+ supportsViewMode: true,
90
91
  icon: WrapIcon,
91
92
  onClick: toggleWordWrapStateForCodeBlockNode(editorAnalyticsAPI),
92
93
  // Hooking up here for demo purposes. To be revisited with ED-24222.
@@ -63,20 +63,18 @@ export var createPlugin = function createPlugin(_ref) {
63
63
  }
64
64
  return decorationSetFromState;
65
65
  };
66
- var createLineDecoratorPluginState = function createLineDecoratorPluginState(pluginState, tr, state) {
67
- var decorationSetFromState = pluginState.decorations;
66
+ var updateLineDecorationSet = function updateLineDecorationSet(tr, state, decorationSet) {
68
67
  // remove all the line number children from the decorations set. 'undefined, undefined' is used to find() the whole doc.
69
- var children = decorationSetFromState.find(undefined, undefined, function (spec) {
68
+ var children = decorationSet.find(undefined, undefined, function (spec) {
70
69
  return spec.type === DECORATION_WIDGET_TYPE;
71
70
  });
72
- decorationSetFromState = decorationSetFromState.remove(children);
71
+ decorationSet = decorationSet.remove(children);
73
72
 
74
73
  // regenerate all the line number for the documents code blocks
75
74
  var lineDecorators = createLineNumberDecoratorsFromDecendants(state);
76
75
 
77
76
  // add the newly generated line numbers to the decorations set
78
- decorationSetFromState = decorationSetFromState.add(tr.doc, _toConsumableArray(lineDecorators));
79
- return decorationSetFromState;
77
+ return decorationSet.add(tr.doc, _toConsumableArray(lineDecorators));
80
78
  };
81
79
 
82
80
  // ME-1599: Composition on mobile was causing the DOM observer to mutate the code block
@@ -140,10 +138,17 @@ export var createPlugin = function createPlugin(_ref) {
140
138
  }
141
139
  if (tr.docChanged) {
142
140
  var _node = findCodeBlock(newState, tr.selection);
141
+
142
+ // Updates mapping position of all existing decorations to new positions
143
+ // specifically used for updating word wrap node decorators
144
+ var updatedDecorationSet = pluginState.decorations.map(tr.mapping, tr.doc);
145
+
146
+ // Wipe and regenerate all line numbers in the document
147
+ updatedDecorationSet = updateLineDecorationSet(tr, newState, updatedDecorationSet);
143
148
  var newPluginState = _objectSpread(_objectSpread({}, pluginState), {}, {
144
149
  pos: _node ? _node.pos : null,
145
150
  isNodeSelected: tr.selection instanceof NodeSelection,
146
- decorations: fg('editor_support_code_block_wrapping') ? createLineDecoratorPluginState(pluginState, tr, newState) : DecorationSet.empty
151
+ decorations: fg('editor_support_code_block_wrapping') ? updatedDecorationSet : DecorationSet.empty
147
152
  });
148
153
  return newPluginState;
149
154
  }
@@ -96,6 +96,7 @@ export var getToolbarConfig = function getToolbarConfig() {
96
96
  var codeBlockWrapButton = {
97
97
  id: 'editor.codeBlock.wrap',
98
98
  type: 'button',
99
+ supportsViewMode: true,
99
100
  icon: WrapIcon,
100
101
  onClick: toggleWordWrapStateForCodeBlockNode(editorAnalyticsAPI),
101
102
  // Hooking up here for demo purposes. To be revisited with ED-24222.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atlaskit/editor-plugin-code-block",
3
- "version": "3.3.4",
3
+ "version": "3.3.6",
4
4
  "description": "Code block plugin for @atlaskit/editor-core",
5
5
  "author": "Atlassian Pty Ltd",
6
6
  "license": "Apache-2.0",
@@ -35,13 +35,13 @@
35
35
  "dependencies": {
36
36
  "@atlaskit/adf-schema": "^40.8.1",
37
37
  "@atlaskit/code": "^15.5.0",
38
- "@atlaskit/editor-common": "^87.10.0",
39
- "@atlaskit/editor-plugin-analytics": "^1.7.0",
38
+ "@atlaskit/editor-common": "^88.0.0",
39
+ "@atlaskit/editor-plugin-analytics": "^1.8.0",
40
40
  "@atlaskit/editor-plugin-composition": "^1.2.0",
41
- "@atlaskit/editor-plugin-decorations": "^1.2.0",
42
- "@atlaskit/editor-plugin-editor-disabled": "^1.2.0",
41
+ "@atlaskit/editor-plugin-decorations": "^1.3.0",
42
+ "@atlaskit/editor-plugin-editor-disabled": "^1.3.0",
43
43
  "@atlaskit/editor-prosemirror": "5.0.1",
44
- "@atlaskit/icon": "^22.13.0",
44
+ "@atlaskit/icon": "^22.14.0",
45
45
  "@atlaskit/platform-feature-flags": "^0.3.0",
46
46
  "@atlaskit/prosemirror-input-rules": "^3.2.0",
47
47
  "@babel/runtime": "^7.0.0",