@atlaskit/editor-plugin-breakout 2.5.3 → 2.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 +9 -0
- package/dist/cjs/editor-commands/set-breakout-width.js +6 -0
- package/dist/cjs/pm-plugins/handle-key-down.js +71 -0
- package/dist/cjs/pm-plugins/resizing-plugin.js +3 -1
- package/dist/es2019/editor-commands/set-breakout-width.js +6 -0
- package/dist/es2019/pm-plugins/handle-key-down.js +66 -0
- package/dist/es2019/pm-plugins/resizing-plugin.js +3 -1
- package/dist/esm/editor-commands/set-breakout-width.js +6 -0
- package/dist/esm/pm-plugins/handle-key-down.js +65 -0
- package/dist/esm/pm-plugins/resizing-plugin.js +3 -1
- package/dist/types/pm-plugins/handle-key-down.d.ts +2 -0
- package/dist/types-ts4.5/pm-plugins/handle-key-down.d.ts +2 -0
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,14 @@
|
|
|
1
1
|
# @atlaskit/editor-plugin-breakout
|
|
2
2
|
|
|
3
|
+
## 2.6.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- [#166502](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/pull-requests/166502)
|
|
8
|
+
[`ea1ed63fc9615`](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/commits/ea1ed63fc9615) -
|
|
9
|
+
ED-28032 add keyboard shortcuts for new resizing experience behind
|
|
10
|
+
platform_editor_breakout_resizing
|
|
11
|
+
|
|
3
12
|
## 2.5.3
|
|
4
13
|
|
|
5
14
|
### Patch Changes
|
|
@@ -5,6 +5,7 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
});
|
|
6
6
|
exports.setBreakoutWidth = setBreakoutWidth;
|
|
7
7
|
var _codeBlock = require("@atlaskit/editor-common/code-block");
|
|
8
|
+
var _state = require("@atlaskit/editor-prosemirror/state");
|
|
8
9
|
var _platformFeatureFlags = require("@atlaskit/platform-feature-flags");
|
|
9
10
|
var _singlePlayerExpand = require("../pm-plugins/utils/single-player-expand");
|
|
10
11
|
function setBreakoutWidth(width, mode, pos, isLivePage) {
|
|
@@ -34,6 +35,11 @@ function setBreakoutWidth(width, mode, pos, isLivePage) {
|
|
|
34
35
|
if ((0, _platformFeatureFlags.fg)('platform_editor_breakout_resizing_hello_release')) {
|
|
35
36
|
tr.setMeta('scrollIntoView', false);
|
|
36
37
|
}
|
|
38
|
+
|
|
39
|
+
// keep current selection, necessary to not remove NodeSelection for keyboard resizing
|
|
40
|
+
if (state.selection instanceof _state.NodeSelection && state.selection.node.eq(node) && (0, _platformFeatureFlags.fg)('platform_editor_breakout_resizing_hello_release')) {
|
|
41
|
+
tr.setSelection(_state.NodeSelection.create(tr.doc, pos));
|
|
42
|
+
}
|
|
37
43
|
if (dispatch) {
|
|
38
44
|
dispatch(tr);
|
|
39
45
|
}
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.handleKeyDown = void 0;
|
|
7
|
+
var _browser = require("@atlaskit/editor-common/browser");
|
|
8
|
+
var _state = require("@atlaskit/editor-prosemirror/state");
|
|
9
|
+
var _editorSharedStyles = require("@atlaskit/editor-shared-styles");
|
|
10
|
+
var _platformFeatureFlags = require("@atlaskit/platform-feature-flags");
|
|
11
|
+
var _setBreakoutWidth = require("../editor-commands/set-breakout-width");
|
|
12
|
+
var KEYBOARD_RESIZE_STEP = 10;
|
|
13
|
+
var getAncestorResizableNode = function getAncestorResizableNode(view, breakoutResizableNodes) {
|
|
14
|
+
var selection = view.state.selection;
|
|
15
|
+
if (selection instanceof _state.NodeSelection) {
|
|
16
|
+
var selectedNode = selection.node;
|
|
17
|
+
if (breakoutResizableNodes.has(selectedNode.type)) {
|
|
18
|
+
return {
|
|
19
|
+
node: selectedNode,
|
|
20
|
+
pos: selection.$from.pos
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
} else if (selection instanceof _state.TextSelection) {
|
|
24
|
+
var node = null;
|
|
25
|
+
var nodePos = null;
|
|
26
|
+
|
|
27
|
+
// only top level nodes are resizable
|
|
28
|
+
var resolvedPos = view.state.doc.resolve(selection.$from.pos);
|
|
29
|
+
var currentNode = resolvedPos.node(1);
|
|
30
|
+
if (breakoutResizableNodes.has(currentNode.type)) {
|
|
31
|
+
node = currentNode;
|
|
32
|
+
nodePos = resolvedPos.before(1);
|
|
33
|
+
return {
|
|
34
|
+
node: node,
|
|
35
|
+
pos: nodePos
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
return null;
|
|
40
|
+
};
|
|
41
|
+
var handleKeyDown = exports.handleKeyDown = function handleKeyDown(view, event) {
|
|
42
|
+
if ((0, _platformFeatureFlags.fg)('platform_editor_breakout_resizing_hello_release')) {
|
|
43
|
+
var metaKey = _browser.browser.mac ? event.metaKey : event.ctrlKey;
|
|
44
|
+
var isBracketKey = event.code === 'BracketRight' || event.code === 'BracketLeft';
|
|
45
|
+
if (metaKey && event.altKey && isBracketKey) {
|
|
46
|
+
var _view$state$schema$no = view.state.schema.nodes,
|
|
47
|
+
expand = _view$state$schema$no.expand,
|
|
48
|
+
codeBlock = _view$state$schema$no.codeBlock,
|
|
49
|
+
layoutSection = _view$state$schema$no.layoutSection;
|
|
50
|
+
var breakoutResizableNodes = new Set([expand, codeBlock, layoutSection]);
|
|
51
|
+
var result = getAncestorResizableNode(view, breakoutResizableNodes);
|
|
52
|
+
if (result) {
|
|
53
|
+
var node = result.node,
|
|
54
|
+
pos = result.pos;
|
|
55
|
+
var breakoutMark = node === null || node === void 0 ? void 0 : node.marks.find(function (mark) {
|
|
56
|
+
return mark.type.name === 'breakout';
|
|
57
|
+
});
|
|
58
|
+
if (breakoutMark) {
|
|
59
|
+
var step = event.code === 'BracketRight' ? KEYBOARD_RESIZE_STEP : -KEYBOARD_RESIZE_STEP;
|
|
60
|
+
var newWidth = breakoutMark.attrs.width + step;
|
|
61
|
+
if (newWidth < _editorSharedStyles.akEditorFullWidthLayoutWidth && newWidth > _editorSharedStyles.akEditorDefaultLayoutWidth) {
|
|
62
|
+
(0, _setBreakoutWidth.setBreakoutWidth)(breakoutMark.attrs.width + step, breakoutMark.attrs.mode, pos)(view.state, view.dispatch);
|
|
63
|
+
view.focus();
|
|
64
|
+
}
|
|
65
|
+
return true;
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
return false;
|
|
70
|
+
}
|
|
71
|
+
};
|
|
@@ -9,6 +9,7 @@ var _utils = require("@atlaskit/editor-common/utils");
|
|
|
9
9
|
var _document = require("@atlaskit/editor-common/utils/document");
|
|
10
10
|
var _state = require("@atlaskit/editor-prosemirror/state");
|
|
11
11
|
var _editorSharedStyles = require("@atlaskit/editor-shared-styles");
|
|
12
|
+
var _handleKeyDown = require("./handle-key-down");
|
|
12
13
|
var _resizingMarkView = require("./resizing-mark-view");
|
|
13
14
|
var addBreakoutToResizableNode = function addBreakoutToResizableNode(_ref) {
|
|
14
15
|
var node = _ref.node,
|
|
@@ -56,7 +57,8 @@ var createResizingPlugin = exports.createResizingPlugin = function createResizin
|
|
|
56
57
|
breakout: function breakout(mark, view) {
|
|
57
58
|
return new _resizingMarkView.ResizingMarkView(mark, view, api);
|
|
58
59
|
}
|
|
59
|
-
}
|
|
60
|
+
},
|
|
61
|
+
handleKeyDown: _handleKeyDown.handleKeyDown
|
|
60
62
|
},
|
|
61
63
|
appendTransaction: function appendTransaction(transactions, oldState, newState) {
|
|
62
64
|
var newTr = newState.tr;
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { transferCodeBlockWrappedValue } from '@atlaskit/editor-common/code-block';
|
|
2
|
+
import { NodeSelection } from '@atlaskit/editor-prosemirror/state';
|
|
2
3
|
import { fg } from '@atlaskit/platform-feature-flags';
|
|
3
4
|
import { updateExpandedStateNew } from '../pm-plugins/utils/single-player-expand';
|
|
4
5
|
export function setBreakoutWidth(width, mode, pos, isLivePage) {
|
|
@@ -28,6 +29,11 @@ export function setBreakoutWidth(width, mode, pos, isLivePage) {
|
|
|
28
29
|
if (fg('platform_editor_breakout_resizing_hello_release')) {
|
|
29
30
|
tr.setMeta('scrollIntoView', false);
|
|
30
31
|
}
|
|
32
|
+
|
|
33
|
+
// keep current selection, necessary to not remove NodeSelection for keyboard resizing
|
|
34
|
+
if (state.selection instanceof NodeSelection && state.selection.node.eq(node) && fg('platform_editor_breakout_resizing_hello_release')) {
|
|
35
|
+
tr.setSelection(NodeSelection.create(tr.doc, pos));
|
|
36
|
+
}
|
|
31
37
|
if (dispatch) {
|
|
32
38
|
dispatch(tr);
|
|
33
39
|
}
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import { browser } from '@atlaskit/editor-common/browser';
|
|
2
|
+
import { NodeSelection, TextSelection } from '@atlaskit/editor-prosemirror/state';
|
|
3
|
+
import { akEditorDefaultLayoutWidth, akEditorFullWidthLayoutWidth } from '@atlaskit/editor-shared-styles';
|
|
4
|
+
import { fg } from '@atlaskit/platform-feature-flags';
|
|
5
|
+
import { setBreakoutWidth } from '../editor-commands/set-breakout-width';
|
|
6
|
+
const KEYBOARD_RESIZE_STEP = 10;
|
|
7
|
+
const getAncestorResizableNode = (view, breakoutResizableNodes) => {
|
|
8
|
+
const selection = view.state.selection;
|
|
9
|
+
if (selection instanceof NodeSelection) {
|
|
10
|
+
const selectedNode = selection.node;
|
|
11
|
+
if (breakoutResizableNodes.has(selectedNode.type)) {
|
|
12
|
+
return {
|
|
13
|
+
node: selectedNode,
|
|
14
|
+
pos: selection.$from.pos
|
|
15
|
+
};
|
|
16
|
+
}
|
|
17
|
+
} else if (selection instanceof TextSelection) {
|
|
18
|
+
let node = null;
|
|
19
|
+
let nodePos = null;
|
|
20
|
+
|
|
21
|
+
// only top level nodes are resizable
|
|
22
|
+
const resolvedPos = view.state.doc.resolve(selection.$from.pos);
|
|
23
|
+
const currentNode = resolvedPos.node(1);
|
|
24
|
+
if (breakoutResizableNodes.has(currentNode.type)) {
|
|
25
|
+
node = currentNode;
|
|
26
|
+
nodePos = resolvedPos.before(1);
|
|
27
|
+
return {
|
|
28
|
+
node: node,
|
|
29
|
+
pos: nodePos
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
return null;
|
|
34
|
+
};
|
|
35
|
+
export const handleKeyDown = (view, event) => {
|
|
36
|
+
if (fg('platform_editor_breakout_resizing_hello_release')) {
|
|
37
|
+
const metaKey = browser.mac ? event.metaKey : event.ctrlKey;
|
|
38
|
+
const isBracketKey = event.code === 'BracketRight' || event.code === 'BracketLeft';
|
|
39
|
+
if (metaKey && event.altKey && isBracketKey) {
|
|
40
|
+
const {
|
|
41
|
+
expand,
|
|
42
|
+
codeBlock,
|
|
43
|
+
layoutSection
|
|
44
|
+
} = view.state.schema.nodes;
|
|
45
|
+
const breakoutResizableNodes = new Set([expand, codeBlock, layoutSection]);
|
|
46
|
+
const result = getAncestorResizableNode(view, breakoutResizableNodes);
|
|
47
|
+
if (result) {
|
|
48
|
+
const {
|
|
49
|
+
node,
|
|
50
|
+
pos
|
|
51
|
+
} = result;
|
|
52
|
+
const breakoutMark = node === null || node === void 0 ? void 0 : node.marks.find(mark => mark.type.name === 'breakout');
|
|
53
|
+
if (breakoutMark) {
|
|
54
|
+
const step = event.code === 'BracketRight' ? KEYBOARD_RESIZE_STEP : -KEYBOARD_RESIZE_STEP;
|
|
55
|
+
const newWidth = breakoutMark.attrs.width + step;
|
|
56
|
+
if (newWidth < akEditorFullWidthLayoutWidth && newWidth > akEditorDefaultLayoutWidth) {
|
|
57
|
+
setBreakoutWidth(breakoutMark.attrs.width + step, breakoutMark.attrs.mode, pos)(view.state, view.dispatch);
|
|
58
|
+
view.focus();
|
|
59
|
+
}
|
|
60
|
+
return true;
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
return false;
|
|
65
|
+
}
|
|
66
|
+
};
|
|
@@ -3,6 +3,7 @@ import { stepAddsOneOf } from '@atlaskit/editor-common/utils';
|
|
|
3
3
|
import { getChangedNodes, isReplaceDocOperation } from '@atlaskit/editor-common/utils/document';
|
|
4
4
|
import { PluginKey } from '@atlaskit/editor-prosemirror/state';
|
|
5
5
|
import { akEditorDefaultLayoutWidth, akEditorFullWidthLayoutWidth, akEditorCalculatedWideLayoutWidth } from '@atlaskit/editor-shared-styles';
|
|
6
|
+
import { handleKeyDown } from './handle-key-down';
|
|
6
7
|
import { ResizingMarkView } from './resizing-mark-view';
|
|
7
8
|
const addBreakoutToResizableNode = ({
|
|
8
9
|
node,
|
|
@@ -51,7 +52,8 @@ export const createResizingPlugin = (api, options) => {
|
|
|
51
52
|
breakout: (mark, view) => {
|
|
52
53
|
return new ResizingMarkView(mark, view, api);
|
|
53
54
|
}
|
|
54
|
-
}
|
|
55
|
+
},
|
|
56
|
+
handleKeyDown
|
|
55
57
|
},
|
|
56
58
|
appendTransaction(transactions, oldState, newState) {
|
|
57
59
|
let newTr = newState.tr;
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { transferCodeBlockWrappedValue } from '@atlaskit/editor-common/code-block';
|
|
2
|
+
import { NodeSelection } from '@atlaskit/editor-prosemirror/state';
|
|
2
3
|
import { fg } from '@atlaskit/platform-feature-flags';
|
|
3
4
|
import { updateExpandedStateNew } from '../pm-plugins/utils/single-player-expand';
|
|
4
5
|
export function setBreakoutWidth(width, mode, pos, isLivePage) {
|
|
@@ -28,6 +29,11 @@ export function setBreakoutWidth(width, mode, pos, isLivePage) {
|
|
|
28
29
|
if (fg('platform_editor_breakout_resizing_hello_release')) {
|
|
29
30
|
tr.setMeta('scrollIntoView', false);
|
|
30
31
|
}
|
|
32
|
+
|
|
33
|
+
// keep current selection, necessary to not remove NodeSelection for keyboard resizing
|
|
34
|
+
if (state.selection instanceof NodeSelection && state.selection.node.eq(node) && fg('platform_editor_breakout_resizing_hello_release')) {
|
|
35
|
+
tr.setSelection(NodeSelection.create(tr.doc, pos));
|
|
36
|
+
}
|
|
31
37
|
if (dispatch) {
|
|
32
38
|
dispatch(tr);
|
|
33
39
|
}
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import { browser } from '@atlaskit/editor-common/browser';
|
|
2
|
+
import { NodeSelection, TextSelection } from '@atlaskit/editor-prosemirror/state';
|
|
3
|
+
import { akEditorDefaultLayoutWidth, akEditorFullWidthLayoutWidth } from '@atlaskit/editor-shared-styles';
|
|
4
|
+
import { fg } from '@atlaskit/platform-feature-flags';
|
|
5
|
+
import { setBreakoutWidth } from '../editor-commands/set-breakout-width';
|
|
6
|
+
var KEYBOARD_RESIZE_STEP = 10;
|
|
7
|
+
var getAncestorResizableNode = function getAncestorResizableNode(view, breakoutResizableNodes) {
|
|
8
|
+
var selection = view.state.selection;
|
|
9
|
+
if (selection instanceof NodeSelection) {
|
|
10
|
+
var selectedNode = selection.node;
|
|
11
|
+
if (breakoutResizableNodes.has(selectedNode.type)) {
|
|
12
|
+
return {
|
|
13
|
+
node: selectedNode,
|
|
14
|
+
pos: selection.$from.pos
|
|
15
|
+
};
|
|
16
|
+
}
|
|
17
|
+
} else if (selection instanceof TextSelection) {
|
|
18
|
+
var node = null;
|
|
19
|
+
var nodePos = null;
|
|
20
|
+
|
|
21
|
+
// only top level nodes are resizable
|
|
22
|
+
var resolvedPos = view.state.doc.resolve(selection.$from.pos);
|
|
23
|
+
var currentNode = resolvedPos.node(1);
|
|
24
|
+
if (breakoutResizableNodes.has(currentNode.type)) {
|
|
25
|
+
node = currentNode;
|
|
26
|
+
nodePos = resolvedPos.before(1);
|
|
27
|
+
return {
|
|
28
|
+
node: node,
|
|
29
|
+
pos: nodePos
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
return null;
|
|
34
|
+
};
|
|
35
|
+
export var handleKeyDown = function handleKeyDown(view, event) {
|
|
36
|
+
if (fg('platform_editor_breakout_resizing_hello_release')) {
|
|
37
|
+
var metaKey = browser.mac ? event.metaKey : event.ctrlKey;
|
|
38
|
+
var isBracketKey = event.code === 'BracketRight' || event.code === 'BracketLeft';
|
|
39
|
+
if (metaKey && event.altKey && isBracketKey) {
|
|
40
|
+
var _view$state$schema$no = view.state.schema.nodes,
|
|
41
|
+
expand = _view$state$schema$no.expand,
|
|
42
|
+
codeBlock = _view$state$schema$no.codeBlock,
|
|
43
|
+
layoutSection = _view$state$schema$no.layoutSection;
|
|
44
|
+
var breakoutResizableNodes = new Set([expand, codeBlock, layoutSection]);
|
|
45
|
+
var result = getAncestorResizableNode(view, breakoutResizableNodes);
|
|
46
|
+
if (result) {
|
|
47
|
+
var node = result.node,
|
|
48
|
+
pos = result.pos;
|
|
49
|
+
var breakoutMark = node === null || node === void 0 ? void 0 : node.marks.find(function (mark) {
|
|
50
|
+
return mark.type.name === 'breakout';
|
|
51
|
+
});
|
|
52
|
+
if (breakoutMark) {
|
|
53
|
+
var step = event.code === 'BracketRight' ? KEYBOARD_RESIZE_STEP : -KEYBOARD_RESIZE_STEP;
|
|
54
|
+
var newWidth = breakoutMark.attrs.width + step;
|
|
55
|
+
if (newWidth < akEditorFullWidthLayoutWidth && newWidth > akEditorDefaultLayoutWidth) {
|
|
56
|
+
setBreakoutWidth(breakoutMark.attrs.width + step, breakoutMark.attrs.mode, pos)(view.state, view.dispatch);
|
|
57
|
+
view.focus();
|
|
58
|
+
}
|
|
59
|
+
return true;
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
return false;
|
|
64
|
+
}
|
|
65
|
+
};
|
|
@@ -3,6 +3,7 @@ import { stepAddsOneOf } from '@atlaskit/editor-common/utils';
|
|
|
3
3
|
import { getChangedNodes, isReplaceDocOperation } from '@atlaskit/editor-common/utils/document';
|
|
4
4
|
import { PluginKey } from '@atlaskit/editor-prosemirror/state';
|
|
5
5
|
import { akEditorDefaultLayoutWidth, akEditorFullWidthLayoutWidth, akEditorCalculatedWideLayoutWidth } from '@atlaskit/editor-shared-styles';
|
|
6
|
+
import { handleKeyDown } from './handle-key-down';
|
|
6
7
|
import { ResizingMarkView } from './resizing-mark-view';
|
|
7
8
|
var addBreakoutToResizableNode = function addBreakoutToResizableNode(_ref) {
|
|
8
9
|
var node = _ref.node,
|
|
@@ -50,7 +51,8 @@ export var createResizingPlugin = function createResizingPlugin(api, options) {
|
|
|
50
51
|
breakout: function breakout(mark, view) {
|
|
51
52
|
return new ResizingMarkView(mark, view, api);
|
|
52
53
|
}
|
|
53
|
-
}
|
|
54
|
+
},
|
|
55
|
+
handleKeyDown: handleKeyDown
|
|
54
56
|
},
|
|
55
57
|
appendTransaction: function appendTransaction(transactions, oldState, newState) {
|
|
56
58
|
var newTr = newState.tr;
|