@atlaskit/editor-plugin-code-block 3.3.10 → 3.3.12
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 +18 -0
- package/dist/cjs/nodeviews/code-block.js +2 -2
- package/dist/cjs/plugin.js +6 -0
- package/dist/cjs/pm-plugins/codeBlockAutoFullStopTransformPlugin.js +65 -0
- package/dist/cjs/pm-plugins/main.js +10 -10
- package/dist/cjs/refresh-browser-selection.js +2 -2
- package/dist/es2019/nodeviews/code-block.js +1 -1
- package/dist/es2019/plugin.js +4 -0
- package/dist/es2019/pm-plugins/codeBlockAutoFullStopTransformPlugin.js +65 -0
- package/dist/es2019/pm-plugins/main.js +1 -1
- package/dist/es2019/refresh-browser-selection.js +1 -1
- package/dist/esm/nodeviews/code-block.js +1 -1
- package/dist/esm/plugin.js +6 -0
- package/dist/esm/pm-plugins/codeBlockAutoFullStopTransformPlugin.js +58 -0
- package/dist/esm/pm-plugins/main.js +1 -1
- package/dist/esm/refresh-browser-selection.js +1 -1
- package/dist/types/pm-plugins/codeBlockAutoFullStopTransformPlugin.d.ts +4 -0
- package/dist/types-ts4.5/pm-plugins/codeBlockAutoFullStopTransformPlugin.d.ts +4 -0
- package/package.json +5 -2
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,23 @@
|
|
|
1
1
|
# @atlaskit/editor-plugin-code-block
|
|
2
2
|
|
|
3
|
+
## 3.3.12
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- [#136348](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/pull-requests/136348)
|
|
8
|
+
[`fb4fb56f1da7c`](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/commits/fb4fb56f1da7c) -
|
|
9
|
+
Use optimised entry-points on editor-common for browser.
|
|
10
|
+
- Updated dependencies
|
|
11
|
+
|
|
12
|
+
## 3.3.11
|
|
13
|
+
|
|
14
|
+
### Patch Changes
|
|
15
|
+
|
|
16
|
+
- [#136266](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/pull-requests/136266)
|
|
17
|
+
[`cb41a82ab6813`](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/commits/cb41a82ab6813) -
|
|
18
|
+
ED-24752 Add new plugin to code block that strips auto inserted fullstops from mac on code blocks
|
|
19
|
+
- Updated dependencies
|
|
20
|
+
|
|
3
21
|
## 3.3.10
|
|
4
22
|
|
|
5
23
|
### Patch Changes
|
|
@@ -9,8 +9,8 @@ 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 _browser = require("@atlaskit/editor-common/browser");
|
|
12
13
|
var _codeBlock = require("@atlaskit/editor-common/code-block");
|
|
13
|
-
var _utils = require("@atlaskit/editor-common/utils");
|
|
14
14
|
var _model = require("@atlaskit/editor-prosemirror/model");
|
|
15
15
|
var _platformFeatureFlags = require("@atlaskit/platform-feature-flags");
|
|
16
16
|
var _actions = require("../actions");
|
|
@@ -178,7 +178,7 @@ var CodeBlockView = exports.CodeBlockView = /*#__PURE__*/function () {
|
|
|
178
178
|
} else {
|
|
179
179
|
this.ensureLineNumbers();
|
|
180
180
|
}
|
|
181
|
-
if (
|
|
181
|
+
if (_browser.browser.android) {
|
|
182
182
|
this.coalesceDOMElements();
|
|
183
183
|
(0, _actions.resetShouldIgnoreFollowingMutations)(this.view.state, this.view.dispatch);
|
|
184
184
|
}
|
package/dist/cjs/plugin.js
CHANGED
|
@@ -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
|
+
}
|
|
@@ -6,10 +6,10 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
6
6
|
});
|
|
7
7
|
exports.createPlugin = void 0;
|
|
8
8
|
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
9
|
+
var _browser = require("@atlaskit/editor-common/browser");
|
|
9
10
|
var _messages = require("@atlaskit/editor-common/messages");
|
|
10
11
|
var _safePlugin = require("@atlaskit/editor-common/safe-plugin");
|
|
11
12
|
var _selection = require("@atlaskit/editor-common/selection");
|
|
12
|
-
var _utils = require("@atlaskit/editor-common/utils");
|
|
13
13
|
var _state = require("@atlaskit/editor-prosemirror/state");
|
|
14
14
|
var _view = require("@atlaskit/editor-prosemirror/view");
|
|
15
15
|
var _platformFeatureFlags = require("@atlaskit/platform-feature-flags");
|
|
@@ -17,7 +17,7 @@ var _actions = require("../actions");
|
|
|
17
17
|
var _codeBlock = require("../nodeviews/code-block");
|
|
18
18
|
var _pluginKey = require("../plugin-key");
|
|
19
19
|
var _classNames = require("../ui/class-names");
|
|
20
|
-
var
|
|
20
|
+
var _utils = require("../utils");
|
|
21
21
|
var _actions2 = require("./actions");
|
|
22
22
|
var _decorators = require("./decorators");
|
|
23
23
|
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
|
@@ -38,12 +38,12 @@ var createPlugin = exports.createPlugin = function createPlugin(_ref) {
|
|
|
38
38
|
var keyEvent = event;
|
|
39
39
|
var eventInputType = keyEvent.inputType;
|
|
40
40
|
var eventText = keyEvent.data;
|
|
41
|
-
if (
|
|
41
|
+
if (_browser.browser.ios && event.composed &&
|
|
42
42
|
// insertParagraph will be the input type when the enter key is pressed.
|
|
43
|
-
eventInputType === 'insertParagraph' && (0,
|
|
43
|
+
eventInputType === 'insertParagraph' && (0, _utils.findCodeBlock)(view.state, view.state.selection)) {
|
|
44
44
|
event.preventDefault();
|
|
45
45
|
return true;
|
|
46
|
-
} else if (
|
|
46
|
+
} else if (_browser.browser.android && event.composed && eventInputType === 'insertCompositionText' && eventText[(eventText === null || eventText === void 0 ? void 0 : eventText.length) - 1] === '\n' && (0, _utils.findCodeBlock)(view.state, view.state.selection)) {
|
|
47
47
|
var resultingText = event.target.outerText + '\n';
|
|
48
48
|
if (resultingText.endsWith(eventText)) {
|
|
49
49
|
// End of paragraph
|
|
@@ -63,7 +63,7 @@ var createPlugin = exports.createPlugin = function createPlugin(_ref) {
|
|
|
63
63
|
}
|
|
64
64
|
return true;
|
|
65
65
|
}
|
|
66
|
-
if (
|
|
66
|
+
if (_browser.browser.android) {
|
|
67
67
|
(0, _actions.resetShouldIgnoreFollowingMutations)(view.state, view.dispatch);
|
|
68
68
|
}
|
|
69
69
|
return false;
|
|
@@ -72,7 +72,7 @@ var createPlugin = exports.createPlugin = function createPlugin(_ref) {
|
|
|
72
72
|
return new _safePlugin.SafePlugin({
|
|
73
73
|
state: {
|
|
74
74
|
init: function init(_, state) {
|
|
75
|
-
var node = (0,
|
|
75
|
+
var node = (0, _utils.findCodeBlock)(state, state.selection);
|
|
76
76
|
var initialDecorations = (0, _platformFeatureFlags.fg)('editor_support_code_block_wrapping') ? (0, _decorators.generateInitialDecorations)(state) : [];
|
|
77
77
|
return {
|
|
78
78
|
pos: node ? node.pos : null,
|
|
@@ -85,13 +85,13 @@ var createPlugin = exports.createPlugin = function createPlugin(_ref) {
|
|
|
85
85
|
apply: function apply(tr, pluginState, _oldState, newState) {
|
|
86
86
|
var meta = tr.getMeta(_pluginKey.pluginKey);
|
|
87
87
|
if ((meta === null || meta === void 0 ? void 0 : meta.type) === _actions2.ACTIONS.SET_IS_WRAPPED && (0, _platformFeatureFlags.fg)('editor_support_code_block_wrapping')) {
|
|
88
|
-
var node = (0,
|
|
88
|
+
var node = (0, _utils.findCodeBlock)(newState, tr.selection);
|
|
89
89
|
return _objectSpread(_objectSpread({}, pluginState), {}, {
|
|
90
90
|
decorations: (0, _decorators.updateDecorationSetWithWordWrappedDecorator)(pluginState.decorations, tr, node)
|
|
91
91
|
});
|
|
92
92
|
}
|
|
93
93
|
if (tr.docChanged) {
|
|
94
|
-
var _node = (0,
|
|
94
|
+
var _node = (0, _utils.findCodeBlock)(newState, tr.selection);
|
|
95
95
|
|
|
96
96
|
// Updates mapping position of all existing decorations to new positions
|
|
97
97
|
// specifically used for updating word wrap node decorators (does not cover drag & drop, validateWordWrappedDecorators does).
|
|
@@ -107,7 +107,7 @@ var createPlugin = exports.createPlugin = function createPlugin(_ref) {
|
|
|
107
107
|
return newPluginState;
|
|
108
108
|
}
|
|
109
109
|
if (tr.selectionSet) {
|
|
110
|
-
var _node2 = (0,
|
|
110
|
+
var _node2 = (0, _utils.findCodeBlock)(newState, tr.selection);
|
|
111
111
|
var _newPluginState = _objectSpread(_objectSpread({}, pluginState), {}, {
|
|
112
112
|
pos: _node2 ? _node2.pos : null,
|
|
113
113
|
isNodeSelected: tr.selection instanceof _state.NodeSelection
|
|
@@ -4,7 +4,7 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.refreshBrowserSelection = exports.default = void 0;
|
|
7
|
-
var
|
|
7
|
+
var _browser = require("@atlaskit/editor-common/browser");
|
|
8
8
|
var _pluginKey = require("./plugin-key");
|
|
9
9
|
// Workaround for a firefox issue where dom selection is off sync
|
|
10
10
|
// https://product-fabric.atlassian.net/browse/ED-12442
|
|
@@ -20,7 +20,7 @@ var refreshBrowserSelection = exports.refreshBrowserSelection = function refresh
|
|
|
20
20
|
};
|
|
21
21
|
var refreshBrowserSelectionOnChange = function refreshBrowserSelectionOnChange(transaction, editorState) {
|
|
22
22
|
var _pluginKey$getState;
|
|
23
|
-
if (
|
|
23
|
+
if (_browser.browser.gecko && transaction.docChanged &&
|
|
24
24
|
// codeblockState.pos should be set if current selection is in a codeblock.
|
|
25
25
|
typeof ((_pluginKey$getState = _pluginKey.pluginKey.getState(editorState)) === null || _pluginKey$getState === void 0 ? void 0 : _pluginKey$getState.pos) === 'number') {
|
|
26
26
|
refreshBrowserSelection();
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import _defineProperty from "@babel/runtime/helpers/defineProperty";
|
|
2
2
|
import rafSchedule from 'raf-schd';
|
|
3
|
+
import { browser } from '@atlaskit/editor-common/browser';
|
|
3
4
|
import { codeBlockWrappedStates, defaultWordWrapState, transferCodeBlockWrappedValue } from '@atlaskit/editor-common/code-block';
|
|
4
|
-
import { browser } from '@atlaskit/editor-common/utils';
|
|
5
5
|
import { DOMSerializer } from '@atlaskit/editor-prosemirror/model';
|
|
6
6
|
import { fg } from '@atlaskit/platform-feature-flags';
|
|
7
7
|
import { resetShouldIgnoreFollowingMutations } from '../actions';
|
package/dist/es2019/plugin.js
CHANGED
|
@@ -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
|
+
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
+
import { browser } from '@atlaskit/editor-common/browser';
|
|
1
2
|
import { blockTypeMessages } from '@atlaskit/editor-common/messages';
|
|
2
3
|
import { SafePlugin } from '@atlaskit/editor-common/safe-plugin';
|
|
3
4
|
import { createSelectionClickHandler } from '@atlaskit/editor-common/selection';
|
|
4
|
-
import { browser } from '@atlaskit/editor-common/utils';
|
|
5
5
|
import { NodeSelection } from '@atlaskit/editor-prosemirror/state';
|
|
6
6
|
import { DecorationSet } from '@atlaskit/editor-prosemirror/view';
|
|
7
7
|
import { fg } from '@atlaskit/platform-feature-flags';
|
|
@@ -2,8 +2,8 @@ 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 { browser } from '@atlaskit/editor-common/browser';
|
|
5
6
|
import { codeBlockWrappedStates, defaultWordWrapState, transferCodeBlockWrappedValue } from '@atlaskit/editor-common/code-block';
|
|
6
|
-
import { browser } from '@atlaskit/editor-common/utils';
|
|
7
7
|
import { DOMSerializer } from '@atlaskit/editor-prosemirror/model';
|
|
8
8
|
import { fg } from '@atlaskit/platform-feature-flags';
|
|
9
9
|
import { resetShouldIgnoreFollowingMutations } from '../actions';
|
package/dist/esm/plugin.js
CHANGED
|
@@ -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
|
+
}
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import _defineProperty from "@babel/runtime/helpers/defineProperty";
|
|
2
2
|
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
|
3
3
|
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
|
|
4
|
+
import { browser } from '@atlaskit/editor-common/browser';
|
|
4
5
|
import { blockTypeMessages } from '@atlaskit/editor-common/messages';
|
|
5
6
|
import { SafePlugin } from '@atlaskit/editor-common/safe-plugin';
|
|
6
7
|
import { createSelectionClickHandler } from '@atlaskit/editor-common/selection';
|
|
7
|
-
import { browser } from '@atlaskit/editor-common/utils';
|
|
8
8
|
import { NodeSelection } from '@atlaskit/editor-prosemirror/state';
|
|
9
9
|
import { DecorationSet } from '@atlaskit/editor-prosemirror/view';
|
|
10
10
|
import { fg } from '@atlaskit/platform-feature-flags';
|
|
@@ -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.
|
|
3
|
+
"version": "3.3.12",
|
|
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.
|
|
36
|
+
"@atlaskit/editor-common": "^88.8.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
|
}
|