@atlaskit/editor-plugin-code-block 3.3.10 → 3.3.11

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,14 @@
1
1
  # @atlaskit/editor-plugin-code-block
2
2
 
3
+ ## 3.3.11
4
+
5
+ ### Patch Changes
6
+
7
+ - [#136266](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/pull-requests/136266)
8
+ [`cb41a82ab6813`](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/commits/cb41a82ab6813) -
9
+ ED-24752 Add new plugin to code block that strips auto inserted fullstops from mac on code blocks
10
+ - Updated dependencies
11
+
3
12
  ## 3.3.10
4
13
 
5
14
  ### Patch Changes
@@ -12,6 +12,7 @@ var _analytics = require("@atlaskit/editor-common/analytics");
12
12
  var _messages = require("@atlaskit/editor-common/messages");
13
13
  var _quickInsert = require("@atlaskit/editor-common/quick-insert");
14
14
  var _actions = require("./actions");
15
+ var _codeBlockAutoFullStopTransformPlugin = require("./pm-plugins/codeBlockAutoFullStopTransformPlugin");
15
16
  var _codeBlockCopySelectionPlugin = require("./pm-plugins/codeBlockCopySelectionPlugin");
16
17
  var _ideUx = _interopRequireDefault(require("./pm-plugins/ide-ux"));
17
18
  var _inputRule = require("./pm-plugins/input-rule");
@@ -65,6 +66,11 @@ var codeBlockPlugin = function codeBlockPlugin(_ref) {
65
66
  plugin: function plugin() {
66
67
  return (0, _codeBlockCopySelectionPlugin.codeBlockCopySelectionPlugin)();
67
68
  }
69
+ }, {
70
+ name: 'codeBlockAutoFullStopTransform',
71
+ plugin: function plugin() {
72
+ return (0, _codeBlockAutoFullStopTransformPlugin.codeBlockAutoFullStopTransformPlugin)();
73
+ }
68
74
  }];
69
75
  },
70
76
  // Workaround for a firefox issue where dom selection is off sync
@@ -0,0 +1,65 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.codeBlockAutoFullStopTransformPlugin = codeBlockAutoFullStopTransformPlugin;
7
+ exports.codeBlockAutoFullStopTransformPluginKey = void 0;
8
+ var _safePlugin = require("@atlaskit/editor-common/safe-plugin");
9
+ var _utils = require("@atlaskit/editor-common/utils");
10
+ var _state = require("@atlaskit/editor-prosemirror/state");
11
+ var _platformFeatureFlags = require("@atlaskit/platform-feature-flags");
12
+ var _utils2 = require("../utils");
13
+ var codeBlockAutoFullStopTransformPluginKey = exports.codeBlockAutoFullStopTransformPluginKey = new _state.PluginKey('codeBlockAutoFullStopTransformPluginKey');
14
+ function codeBlockAutoFullStopTransformPlugin() {
15
+ return new _safePlugin.SafePlugin({
16
+ key: codeBlockAutoFullStopTransformPluginKey,
17
+ appendTransaction: function appendTransaction(_transactions, oldState, newState) {
18
+ if (!(0, _platformFeatureFlags.fg)('editor_support_code_block_wrapping') || !(0, _platformFeatureFlags.fg)('code_block_auto_insertion_bug_fix')) {
19
+ return undefined;
20
+ }
21
+
22
+ // We need to compare the old and new state to isloate auto insertion of fullstop on mac
23
+ var trNew = newState.tr;
24
+ var trOld = oldState.tr;
25
+ var fromOld = trOld.selection.from;
26
+ var _trNew$selection = trNew.selection,
27
+ fromNew = _trNew$selection.from,
28
+ toNew = _trNew$selection.to;
29
+ var isCodeBlock = !!(0, _utils2.findCodeBlock)(oldState, trOld.selection) && !!(0, _utils2.findCodeBlock)(newState, trNew.selection);
30
+
31
+ /**
32
+ * Mac will auto insert a fullstop when the user double taps the space key after some content.
33
+ * Line number decorators are assumed content so on new lines the fullstop is inserted.
34
+ *
35
+ * - When a fulltop is auto inserted the new states selection is the same, the old state selection is one position less
36
+ * - The text returned for the old state returns as a space with the selection from - 1
37
+ * - The text returned for the new state returns as a fullstop with the selection from - 2 to from -1
38
+ *
39
+ * This is enough conditional logic to isoloate the auto insertion of the fullstop on mac
40
+ *
41
+ * There are some solutions to this problem in codemirror which can be read further here
42
+ * https://discuss.codemirror.net/t/dot-being-added-when-pressing-space-repeatedly/3899
43
+ */
44
+
45
+ // both selections must be of code block early exit
46
+ if (_utils.browser.mac && fromNew === toNew && fromNew === fromOld + 1 && isCodeBlock) {
47
+ // detect when '.' is inserted when the previous state was a space ' '
48
+ try {
49
+ var textBetweenBefore = trOld.doc.textBetween(fromOld - 1, fromOld); // ' '
50
+ var textBetweenAfter = trNew.doc.textBetween(fromNew - 2, fromNew - 1); // '.'
51
+ if (textBetweenBefore === ' ' && textBetweenAfter === '.') {
52
+ trNew.delete(fromNew - 2, fromNew); // remove the fullstop
53
+ trNew.insertText(' ', fromNew - 2); // insert double space
54
+
55
+ return trNew;
56
+ }
57
+ } catch (error) {
58
+ // if for some reason textBetween fails, just return the new transaction as is by defaut.
59
+ return undefined;
60
+ }
61
+ }
62
+ return undefined;
63
+ }
64
+ });
65
+ }
@@ -4,6 +4,7 @@ import { ACTION, ACTION_SUBJECT, ACTION_SUBJECT_ID, EVENT_TYPE, INPUT_METHOD } f
4
4
  import { blockTypeMessages } from '@atlaskit/editor-common/messages';
5
5
  import { IconCode } from '@atlaskit/editor-common/quick-insert';
6
6
  import { createInsertCodeBlockTransaction, insertCodeBlockWithAnalytics } from './actions';
7
+ import { codeBlockAutoFullStopTransformPlugin } from './pm-plugins/codeBlockAutoFullStopTransformPlugin';
7
8
  import { codeBlockCopySelectionPlugin } from './pm-plugins/codeBlockCopySelectionPlugin';
8
9
  import ideUX from './pm-plugins/ide-ux';
9
10
  import { createCodeBlockInputRule } from './pm-plugins/input-rule';
@@ -51,6 +52,9 @@ const codeBlockPlugin = ({
51
52
  }, {
52
53
  name: 'codeBlockCopySelection',
53
54
  plugin: () => codeBlockCopySelectionPlugin()
55
+ }, {
56
+ name: 'codeBlockAutoFullStopTransform',
57
+ plugin: () => codeBlockAutoFullStopTransformPlugin()
54
58
  }];
55
59
  },
56
60
  // Workaround for a firefox issue where dom selection is off sync
@@ -0,0 +1,65 @@
1
+ import { SafePlugin } from '@atlaskit/editor-common/safe-plugin';
2
+ import { browser } from '@atlaskit/editor-common/utils';
3
+ import { PluginKey } from '@atlaskit/editor-prosemirror/state';
4
+ import { fg } from '@atlaskit/platform-feature-flags';
5
+ import { findCodeBlock } from '../utils';
6
+ export const codeBlockAutoFullStopTransformPluginKey = new PluginKey('codeBlockAutoFullStopTransformPluginKey');
7
+ export function codeBlockAutoFullStopTransformPlugin() {
8
+ return new SafePlugin({
9
+ key: codeBlockAutoFullStopTransformPluginKey,
10
+ appendTransaction(_transactions, oldState, newState) {
11
+ if (!fg('editor_support_code_block_wrapping') || !fg('code_block_auto_insertion_bug_fix')) {
12
+ return undefined;
13
+ }
14
+
15
+ // We need to compare the old and new state to isloate auto insertion of fullstop on mac
16
+ const {
17
+ tr: trNew
18
+ } = newState;
19
+ const {
20
+ tr: trOld
21
+ } = oldState;
22
+ const {
23
+ from: fromOld
24
+ } = trOld.selection;
25
+ const {
26
+ from: fromNew,
27
+ to: toNew
28
+ } = trNew.selection;
29
+ const isCodeBlock = !!findCodeBlock(oldState, trOld.selection) && !!findCodeBlock(newState, trNew.selection);
30
+
31
+ /**
32
+ * Mac will auto insert a fullstop when the user double taps the space key after some content.
33
+ * Line number decorators are assumed content so on new lines the fullstop is inserted.
34
+ *
35
+ * - When a fulltop is auto inserted the new states selection is the same, the old state selection is one position less
36
+ * - The text returned for the old state returns as a space with the selection from - 1
37
+ * - The text returned for the new state returns as a fullstop with the selection from - 2 to from -1
38
+ *
39
+ * This is enough conditional logic to isoloate the auto insertion of the fullstop on mac
40
+ *
41
+ * There are some solutions to this problem in codemirror which can be read further here
42
+ * https://discuss.codemirror.net/t/dot-being-added-when-pressing-space-repeatedly/3899
43
+ */
44
+
45
+ // both selections must be of code block early exit
46
+ if (browser.mac && fromNew === toNew && fromNew === fromOld + 1 && isCodeBlock) {
47
+ // detect when '.' is inserted when the previous state was a space ' '
48
+ try {
49
+ const textBetweenBefore = trOld.doc.textBetween(fromOld - 1, fromOld); // ' '
50
+ const textBetweenAfter = trNew.doc.textBetween(fromNew - 2, fromNew - 1); // '.'
51
+ if (textBetweenBefore === ' ' && textBetweenAfter === '.') {
52
+ trNew.delete(fromNew - 2, fromNew); // remove the fullstop
53
+ trNew.insertText(' ', fromNew - 2); // insert double space
54
+
55
+ return trNew;
56
+ }
57
+ } catch (error) {
58
+ // if for some reason textBetween fails, just return the new transaction as is by defaut.
59
+ return undefined;
60
+ }
61
+ }
62
+ return undefined;
63
+ }
64
+ });
65
+ }
@@ -7,6 +7,7 @@ import { ACTION, ACTION_SUBJECT, ACTION_SUBJECT_ID, EVENT_TYPE, INPUT_METHOD } f
7
7
  import { blockTypeMessages } from '@atlaskit/editor-common/messages';
8
8
  import { IconCode } from '@atlaskit/editor-common/quick-insert';
9
9
  import { createInsertCodeBlockTransaction, insertCodeBlockWithAnalytics } from './actions';
10
+ import { codeBlockAutoFullStopTransformPlugin } from './pm-plugins/codeBlockAutoFullStopTransformPlugin';
10
11
  import { codeBlockCopySelectionPlugin } from './pm-plugins/codeBlockCopySelectionPlugin';
11
12
  import ideUX from './pm-plugins/ide-ux';
12
13
  import { createCodeBlockInputRule } from './pm-plugins/input-rule';
@@ -58,6 +59,11 @@ var codeBlockPlugin = function codeBlockPlugin(_ref) {
58
59
  plugin: function plugin() {
59
60
  return codeBlockCopySelectionPlugin();
60
61
  }
62
+ }, {
63
+ name: 'codeBlockAutoFullStopTransform',
64
+ plugin: function plugin() {
65
+ return codeBlockAutoFullStopTransformPlugin();
66
+ }
61
67
  }];
62
68
  },
63
69
  // Workaround for a firefox issue where dom selection is off sync
@@ -0,0 +1,58 @@
1
+ import { SafePlugin } from '@atlaskit/editor-common/safe-plugin';
2
+ import { browser } from '@atlaskit/editor-common/utils';
3
+ import { PluginKey } from '@atlaskit/editor-prosemirror/state';
4
+ import { fg } from '@atlaskit/platform-feature-flags';
5
+ import { findCodeBlock } from '../utils';
6
+ export var codeBlockAutoFullStopTransformPluginKey = new PluginKey('codeBlockAutoFullStopTransformPluginKey');
7
+ export function codeBlockAutoFullStopTransformPlugin() {
8
+ return new SafePlugin({
9
+ key: codeBlockAutoFullStopTransformPluginKey,
10
+ appendTransaction: function appendTransaction(_transactions, oldState, newState) {
11
+ if (!fg('editor_support_code_block_wrapping') || !fg('code_block_auto_insertion_bug_fix')) {
12
+ return undefined;
13
+ }
14
+
15
+ // We need to compare the old and new state to isloate auto insertion of fullstop on mac
16
+ var trNew = newState.tr;
17
+ var trOld = oldState.tr;
18
+ var fromOld = trOld.selection.from;
19
+ var _trNew$selection = trNew.selection,
20
+ fromNew = _trNew$selection.from,
21
+ toNew = _trNew$selection.to;
22
+ var isCodeBlock = !!findCodeBlock(oldState, trOld.selection) && !!findCodeBlock(newState, trNew.selection);
23
+
24
+ /**
25
+ * Mac will auto insert a fullstop when the user double taps the space key after some content.
26
+ * Line number decorators are assumed content so on new lines the fullstop is inserted.
27
+ *
28
+ * - When a fulltop is auto inserted the new states selection is the same, the old state selection is one position less
29
+ * - The text returned for the old state returns as a space with the selection from - 1
30
+ * - The text returned for the new state returns as a fullstop with the selection from - 2 to from -1
31
+ *
32
+ * This is enough conditional logic to isoloate the auto insertion of the fullstop on mac
33
+ *
34
+ * There are some solutions to this problem in codemirror which can be read further here
35
+ * https://discuss.codemirror.net/t/dot-being-added-when-pressing-space-repeatedly/3899
36
+ */
37
+
38
+ // both selections must be of code block early exit
39
+ if (browser.mac && fromNew === toNew && fromNew === fromOld + 1 && isCodeBlock) {
40
+ // detect when '.' is inserted when the previous state was a space ' '
41
+ try {
42
+ var textBetweenBefore = trOld.doc.textBetween(fromOld - 1, fromOld); // ' '
43
+ var textBetweenAfter = trNew.doc.textBetween(fromNew - 2, fromNew - 1); // '.'
44
+ if (textBetweenBefore === ' ' && textBetweenAfter === '.') {
45
+ trNew.delete(fromNew - 2, fromNew); // remove the fullstop
46
+ trNew.insertText(' ', fromNew - 2); // insert double space
47
+
48
+ return trNew;
49
+ }
50
+ } catch (error) {
51
+ // if for some reason textBetween fails, just return the new transaction as is by defaut.
52
+ return undefined;
53
+ }
54
+ }
55
+ return undefined;
56
+ }
57
+ });
58
+ }
@@ -0,0 +1,4 @@
1
+ import { SafePlugin } from '@atlaskit/editor-common/safe-plugin';
2
+ import { PluginKey } from '@atlaskit/editor-prosemirror/state';
3
+ export declare const codeBlockAutoFullStopTransformPluginKey: PluginKey<any>;
4
+ export declare function codeBlockAutoFullStopTransformPlugin(): SafePlugin<any>;
@@ -0,0 +1,4 @@
1
+ import { SafePlugin } from '@atlaskit/editor-common/safe-plugin';
2
+ import { PluginKey } from '@atlaskit/editor-prosemirror/state';
3
+ export declare const codeBlockAutoFullStopTransformPluginKey: PluginKey<any>;
4
+ export declare function codeBlockAutoFullStopTransformPlugin(): SafePlugin<any>;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atlaskit/editor-plugin-code-block",
3
- "version": "3.3.10",
3
+ "version": "3.3.11",
4
4
  "description": "Code block plugin for @atlaskit/editor-core",
5
5
  "author": "Atlassian Pty Ltd",
6
6
  "license": "Apache-2.0",
@@ -33,7 +33,7 @@
33
33
  "dependencies": {
34
34
  "@atlaskit/adf-schema": "^40.9.0",
35
35
  "@atlaskit/code": "^15.6.0",
36
- "@atlaskit/editor-common": "^88.5.0",
36
+ "@atlaskit/editor-common": "^88.7.0",
37
37
  "@atlaskit/editor-plugin-analytics": "^1.8.0",
38
38
  "@atlaskit/editor-plugin-composition": "^1.2.0",
39
39
  "@atlaskit/editor-plugin-decorations": "^1.3.0",
@@ -94,6 +94,9 @@
94
94
  "editor_support_code_block_wrapping": {
95
95
  "type": "boolean"
96
96
  },
97
+ "code_block_auto_insertion_bug_fix": {
98
+ "type": "boolean"
99
+ },
97
100
  "platform.editor.live-view.disable-editing-in-view-mode_fi1rx": {
98
101
  "type": "boolean"
99
102
  }