@atlaskit/editor-plugin-breakout 2.2.6 → 2.3.1
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 +26 -0
- package/dist/cjs/breakoutPlugin.js +1 -1
- package/dist/cjs/editor-commands/set-breakout-width.js +3 -2
- package/dist/cjs/pm-plugins/resizer-callbacks.js +2 -2
- package/dist/cjs/pm-plugins/resizing-plugin.js +95 -1
- package/dist/es2019/breakoutPlugin.js +1 -1
- package/dist/es2019/editor-commands/set-breakout-width.js +3 -2
- package/dist/es2019/pm-plugins/resizer-callbacks.js +6 -6
- package/dist/es2019/pm-plugins/resizing-plugin.js +98 -1
- package/dist/esm/breakoutPlugin.js +1 -1
- package/dist/esm/editor-commands/set-breakout-width.js +3 -2
- package/dist/esm/pm-plugins/resizer-callbacks.js +6 -6
- package/dist/esm/pm-plugins/resizing-plugin.js +95 -1
- package/dist/types/editor-commands/set-breakout-width.d.ts +2 -2
- package/dist/types/pm-plugins/resizer-callbacks.d.ts +5 -5
- package/dist/types/pm-plugins/resizing-plugin.d.ts +2 -1
- package/dist/types-ts4.5/editor-commands/set-breakout-width.d.ts +2 -2
- package/dist/types-ts4.5/pm-plugins/resizer-callbacks.d.ts +5 -5
- package/dist/types-ts4.5/pm-plugins/resizing-plugin.d.ts +2 -1
- package/package.json +6 -6
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,31 @@
|
|
|
1
1
|
# @atlaskit/editor-plugin-breakout
|
|
2
2
|
|
|
3
|
+
## 2.3.1
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- [#160619](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/pull-requests/160619)
|
|
8
|
+
[`6e034b31d6c9c`](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/commits/6e034b31d6c9c) -
|
|
9
|
+
ED-28096 fix nested nodes getting breakout mark
|
|
10
|
+
- Updated dependencies
|
|
11
|
+
|
|
12
|
+
## 2.3.0
|
|
13
|
+
|
|
14
|
+
### Minor Changes
|
|
15
|
+
|
|
16
|
+
- [#158239](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/pull-requests/158239)
|
|
17
|
+
[`c2caa0af876e0`](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/commits/c2caa0af876e0) -
|
|
18
|
+
[ux] ED-28028 add breakout mark to expands, codeblocks and layouts for new resizing experience
|
|
19
|
+
behind the platform_editor_breakout_resizing experiment
|
|
20
|
+
|
|
21
|
+
### Patch Changes
|
|
22
|
+
|
|
23
|
+
- [#159213](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/pull-requests/159213)
|
|
24
|
+
[`75e3b93e94f8c`](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/commits/75e3b93e94f8c) -
|
|
25
|
+
[ED-28069] this change is retaining the breakout mode when setting the breakout width when using
|
|
26
|
+
the new resizing experience behind the platform_editor_breakout_resizing experiment.
|
|
27
|
+
- Updated dependencies
|
|
28
|
+
|
|
3
29
|
## 2.2.6
|
|
4
30
|
|
|
5
31
|
### Patch Changes
|
|
@@ -178,7 +178,7 @@ var breakoutPlugin = exports.breakoutPlugin = function breakoutPlugin(_ref3) {
|
|
|
178
178
|
return [{
|
|
179
179
|
name: 'breakout-resizing',
|
|
180
180
|
plugin: function plugin() {
|
|
181
|
-
return (0, _resizingPlugin.createResizingPlugin)(api);
|
|
181
|
+
return (0, _resizingPlugin.createResizingPlugin)(api, options);
|
|
182
182
|
}
|
|
183
183
|
}];
|
|
184
184
|
}
|
|
@@ -5,14 +5,15 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
});
|
|
6
6
|
exports.setBreakoutWidth = setBreakoutWidth;
|
|
7
7
|
// TODO: ED-28029 - add fixes for expands and codeblocks
|
|
8
|
-
function setBreakoutWidth(width, pos, isLivePage) {
|
|
8
|
+
function setBreakoutWidth(width, mode, pos, isLivePage) {
|
|
9
9
|
return function (state, dispatch) {
|
|
10
10
|
var node = state.doc.nodeAt(pos);
|
|
11
11
|
if (!node) {
|
|
12
12
|
return false;
|
|
13
13
|
}
|
|
14
14
|
var tr = state.tr.setNodeMarkup(pos, node.type, node.attrs, [state.schema.marks.breakout.create({
|
|
15
|
-
width: width
|
|
15
|
+
width: width,
|
|
16
|
+
mode: mode
|
|
16
17
|
})]);
|
|
17
18
|
if (dispatch) {
|
|
18
19
|
dispatch(tr);
|
|
@@ -26,7 +26,6 @@ function getProposedWidth(_ref) {
|
|
|
26
26
|
var containerWidth = ((api === null || api === void 0 || (_api$width$sharedStat = api.width.sharedState) === null || _api$width$sharedStat === void 0 || (_api$width$sharedStat = _api$width$sharedStat.currentState()) === null || _api$width$sharedStat === void 0 ? void 0 : _api$width$sharedStat.width) || 0) - 2 * (0, _editorSharedStyles.akEditorGutterPaddingDynamic)() - _editorSharedStyles.akEditorGutterPadding;
|
|
27
27
|
return Math.min(Math.max(WIDTHS.MIN, Math.min(proposedWidth, containerWidth)), WIDTHS.MAX);
|
|
28
28
|
}
|
|
29
|
-
;
|
|
30
29
|
function createResizerCallbacks(_ref2) {
|
|
31
30
|
var dom = _ref2.dom,
|
|
32
31
|
contentDOM = _ref2.contentDOM,
|
|
@@ -61,13 +60,14 @@ function createResizerCallbacks(_ref2) {
|
|
|
61
60
|
if (pos === undefined) {
|
|
62
61
|
return;
|
|
63
62
|
}
|
|
63
|
+
var mode = mark.attrs.mode;
|
|
64
64
|
var initialWidth = mark.attrs.width;
|
|
65
65
|
var newWidth = getProposedWidth({
|
|
66
66
|
initialWidth: initialWidth,
|
|
67
67
|
location: location,
|
|
68
68
|
api: api
|
|
69
69
|
});
|
|
70
|
-
(0, _setBreakoutWidth.setBreakoutWidth)(newWidth, pos)(view.state, view.dispatch);
|
|
70
|
+
(0, _setBreakoutWidth.setBreakoutWidth)(newWidth, mode, pos)(view.state, view.dispatch);
|
|
71
71
|
contentDOM.style.removeProperty(_resizingMarkView.LOCAL_RESIZE_PROPERTY);
|
|
72
72
|
view.dispatch(view.state.tr.setMeta('is-resizer-resizing', false).setMeta('scrollIntoView', false));
|
|
73
73
|
api === null || api === void 0 || api.core.actions.execute((_api$userIntent2 = api.userIntent) === null || _api$userIntent2 === void 0 ? void 0 : _api$userIntent2.commands.setCurrentUserIntent('default'));
|
|
@@ -5,10 +5,50 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
});
|
|
6
6
|
exports.resizingPluginKey = exports.createResizingPlugin = void 0;
|
|
7
7
|
var _safePlugin = require("@atlaskit/editor-common/safe-plugin");
|
|
8
|
+
var _utils = require("@atlaskit/editor-common/utils");
|
|
9
|
+
var _document = require("@atlaskit/editor-common/utils/document");
|
|
8
10
|
var _state = require("@atlaskit/editor-prosemirror/state");
|
|
11
|
+
var _editorSharedStyles = require("@atlaskit/editor-shared-styles");
|
|
9
12
|
var _resizingMarkView = require("./resizing-mark-view");
|
|
13
|
+
var addBreakoutToResizableNode = function addBreakoutToResizableNode(_ref) {
|
|
14
|
+
var node = _ref.node,
|
|
15
|
+
pos = _ref.pos,
|
|
16
|
+
newState = _ref.newState,
|
|
17
|
+
newTr = _ref.newTr,
|
|
18
|
+
breakoutResizableNodes = _ref.breakoutResizableNodes,
|
|
19
|
+
isFullWidthEnabled = _ref.isFullWidthEnabled;
|
|
20
|
+
var updatedDocChanged = false;
|
|
21
|
+
var updatedTr = newTr;
|
|
22
|
+
var $pos = newState.doc.resolve(pos);
|
|
23
|
+
var isTopLevelNode = ($pos === null || $pos === void 0 ? void 0 : $pos.depth) === 0;
|
|
24
|
+
if (breakoutResizableNodes.has(node.type) && isTopLevelNode) {
|
|
25
|
+
var breakout = newState.schema.marks.breakout;
|
|
26
|
+
var breakoutMark = node.marks.find(function (mark) {
|
|
27
|
+
return mark.type === breakout;
|
|
28
|
+
});
|
|
29
|
+
if (!breakoutMark) {
|
|
30
|
+
var width = isFullWidthEnabled ? _editorSharedStyles.akEditorFullWidthLayoutWidth : _editorSharedStyles.akEditorDefaultLayoutWidth;
|
|
31
|
+
updatedTr = newTr.setNodeMarkup(pos, node.type, node.attrs, [breakout.create({
|
|
32
|
+
width: width
|
|
33
|
+
})]);
|
|
34
|
+
updatedDocChanged = true;
|
|
35
|
+
} else if ((breakoutMark === null || breakoutMark === void 0 ? void 0 : breakoutMark.attrs.width) === null || (breakoutMark === null || breakoutMark === void 0 ? void 0 : breakoutMark.attrs.width) === undefined) {
|
|
36
|
+
var mode = breakoutMark.attrs.mode;
|
|
37
|
+
var newWidth = mode === 'wide' ? _editorSharedStyles.akEditorCalculatedWideLayoutWidth : _editorSharedStyles.akEditorFullWidthLayoutWidth;
|
|
38
|
+
updatedTr = newTr.setNodeMarkup(pos, node.type, node.attrs, [breakout.create({
|
|
39
|
+
width: newWidth,
|
|
40
|
+
mode: mode
|
|
41
|
+
})]);
|
|
42
|
+
updatedDocChanged = true;
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
return {
|
|
46
|
+
updatedTr: updatedTr,
|
|
47
|
+
updatedDocChanged: updatedDocChanged
|
|
48
|
+
};
|
|
49
|
+
};
|
|
10
50
|
var resizingPluginKey = exports.resizingPluginKey = new _state.PluginKey('breakout-resizing');
|
|
11
|
-
var createResizingPlugin = exports.createResizingPlugin = function createResizingPlugin(api) {
|
|
51
|
+
var createResizingPlugin = exports.createResizingPlugin = function createResizingPlugin(api, options) {
|
|
12
52
|
return new _safePlugin.SafePlugin({
|
|
13
53
|
key: resizingPluginKey,
|
|
14
54
|
props: {
|
|
@@ -17,6 +57,60 @@ var createResizingPlugin = exports.createResizingPlugin = function createResizin
|
|
|
17
57
|
return new _resizingMarkView.ResizingMarkView(mark, view, api);
|
|
18
58
|
}
|
|
19
59
|
}
|
|
60
|
+
},
|
|
61
|
+
appendTransaction: function appendTransaction(transactions, oldState, newState) {
|
|
62
|
+
var newTr = newState.tr;
|
|
63
|
+
var hasDocChanged = false;
|
|
64
|
+
var _newState$schema$node = newState.schema.nodes,
|
|
65
|
+
expand = _newState$schema$node.expand,
|
|
66
|
+
codeBlock = _newState$schema$node.codeBlock,
|
|
67
|
+
layoutSection = _newState$schema$node.layoutSection;
|
|
68
|
+
var breakoutResizableNodes = new Set([expand, codeBlock, layoutSection]);
|
|
69
|
+
var isFullWidthEnabled = !((options === null || options === void 0 ? void 0 : options.allowBreakoutButton) === true);
|
|
70
|
+
if ((0, _document.isReplaceDocOperation)(transactions, oldState)) {
|
|
71
|
+
newState.doc.forEach(function (node, pos) {
|
|
72
|
+
var _addBreakoutToResizab = addBreakoutToResizableNode({
|
|
73
|
+
node: node,
|
|
74
|
+
pos: pos,
|
|
75
|
+
newState: newState,
|
|
76
|
+
newTr: newTr,
|
|
77
|
+
breakoutResizableNodes: breakoutResizableNodes,
|
|
78
|
+
isFullWidthEnabled: isFullWidthEnabled
|
|
79
|
+
}),
|
|
80
|
+
updatedTr = _addBreakoutToResizab.updatedTr,
|
|
81
|
+
updatedDocChanged = _addBreakoutToResizab.updatedDocChanged;
|
|
82
|
+
newTr = updatedTr;
|
|
83
|
+
hasDocChanged = hasDocChanged || updatedDocChanged;
|
|
84
|
+
});
|
|
85
|
+
} else {
|
|
86
|
+
transactions.forEach(function (tr) {
|
|
87
|
+
var isAddingResizableNodes = tr.steps.some(function (step) {
|
|
88
|
+
return (0, _utils.stepAddsOneOf)(step, breakoutResizableNodes);
|
|
89
|
+
});
|
|
90
|
+
if (isAddingResizableNodes) {
|
|
91
|
+
var changedNodes = (0, _document.getChangedNodes)(tr);
|
|
92
|
+
changedNodes.forEach(function (_ref2) {
|
|
93
|
+
var node = _ref2.node,
|
|
94
|
+
pos = _ref2.pos;
|
|
95
|
+
var _addBreakoutToResizab2 = addBreakoutToResizableNode({
|
|
96
|
+
node: node,
|
|
97
|
+
pos: pos,
|
|
98
|
+
newState: newState,
|
|
99
|
+
newTr: newTr,
|
|
100
|
+
breakoutResizableNodes: breakoutResizableNodes,
|
|
101
|
+
isFullWidthEnabled: isFullWidthEnabled
|
|
102
|
+
}),
|
|
103
|
+
updatedTr = _addBreakoutToResizab2.updatedTr,
|
|
104
|
+
updatedDocChanged = _addBreakoutToResizab2.updatedDocChanged;
|
|
105
|
+
newTr = updatedTr;
|
|
106
|
+
hasDocChanged = hasDocChanged || updatedDocChanged;
|
|
107
|
+
});
|
|
108
|
+
}
|
|
109
|
+
});
|
|
110
|
+
}
|
|
111
|
+
if (hasDocChanged) {
|
|
112
|
+
return newTr;
|
|
113
|
+
}
|
|
20
114
|
}
|
|
21
115
|
});
|
|
22
116
|
};
|
|
@@ -171,7 +171,7 @@ export const breakoutPlugin = ({
|
|
|
171
171
|
if (editorExperiment('platform_editor_breakout_resizing', true)) {
|
|
172
172
|
return [{
|
|
173
173
|
name: 'breakout-resizing',
|
|
174
|
-
plugin: () => createResizingPlugin(api)
|
|
174
|
+
plugin: () => createResizingPlugin(api, options)
|
|
175
175
|
}];
|
|
176
176
|
}
|
|
177
177
|
return [{
|
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
// TODO: ED-28029 - add fixes for expands and codeblocks
|
|
2
|
-
export function setBreakoutWidth(width, pos, isLivePage) {
|
|
2
|
+
export function setBreakoutWidth(width, mode, pos, isLivePage) {
|
|
3
3
|
return (state, dispatch) => {
|
|
4
4
|
const node = state.doc.nodeAt(pos);
|
|
5
5
|
if (!node) {
|
|
6
6
|
return false;
|
|
7
7
|
}
|
|
8
8
|
const tr = state.tr.setNodeMarkup(pos, node.type, node.attrs, [state.schema.marks.breakout.create({
|
|
9
|
-
width
|
|
9
|
+
width,
|
|
10
|
+
mode
|
|
10
11
|
})]);
|
|
11
12
|
if (dispatch) {
|
|
12
13
|
dispatch(tr);
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { akEditorGutterPaddingDynamic, akEditorGutterPadding } from
|
|
2
|
-
import { preventUnhandled } from
|
|
3
|
-
import { setBreakoutWidth } from
|
|
4
|
-
import { LOCAL_RESIZE_PROPERTY } from
|
|
1
|
+
import { akEditorGutterPaddingDynamic, akEditorGutterPadding } from '@atlaskit/editor-shared-styles';
|
|
2
|
+
import { preventUnhandled } from '@atlaskit/pragmatic-drag-and-drop/prevent-unhandled';
|
|
3
|
+
import { setBreakoutWidth } from '../editor-commands/set-breakout-width';
|
|
4
|
+
import { LOCAL_RESIZE_PROPERTY } from './resizing-mark-view';
|
|
5
5
|
const RESIZE_RATIO = 2;
|
|
6
6
|
const WIDTHS = {
|
|
7
7
|
MIN: 760,
|
|
@@ -21,7 +21,6 @@ function getProposedWidth({
|
|
|
21
21
|
const containerWidth = ((api === null || api === void 0 ? void 0 : (_api$width$sharedStat = api.width.sharedState) === null || _api$width$sharedStat === void 0 ? void 0 : (_api$width$sharedStat2 = _api$width$sharedStat.currentState()) === null || _api$width$sharedStat2 === void 0 ? void 0 : _api$width$sharedStat2.width) || 0) - 2 * akEditorGutterPaddingDynamic() - akEditorGutterPadding;
|
|
22
22
|
return Math.min(Math.max(WIDTHS.MIN, Math.min(proposedWidth, containerWidth)), WIDTHS.MAX);
|
|
23
23
|
}
|
|
24
|
-
;
|
|
25
24
|
export function createResizerCallbacks({
|
|
26
25
|
dom,
|
|
27
26
|
contentDOM,
|
|
@@ -59,13 +58,14 @@ export function createResizerCallbacks({
|
|
|
59
58
|
if (pos === undefined) {
|
|
60
59
|
return;
|
|
61
60
|
}
|
|
61
|
+
const mode = mark.attrs.mode;
|
|
62
62
|
const initialWidth = mark.attrs.width;
|
|
63
63
|
const newWidth = getProposedWidth({
|
|
64
64
|
initialWidth,
|
|
65
65
|
location,
|
|
66
66
|
api
|
|
67
67
|
});
|
|
68
|
-
setBreakoutWidth(newWidth, pos)(view.state, view.dispatch);
|
|
68
|
+
setBreakoutWidth(newWidth, mode, pos)(view.state, view.dispatch);
|
|
69
69
|
contentDOM.style.removeProperty(LOCAL_RESIZE_PROPERTY);
|
|
70
70
|
view.dispatch(view.state.tr.setMeta('is-resizer-resizing', false).setMeta('scrollIntoView', false));
|
|
71
71
|
api === null || api === void 0 ? void 0 : api.core.actions.execute((_api$userIntent2 = api.userIntent) === null || _api$userIntent2 === void 0 ? void 0 : _api$userIntent2.commands.setCurrentUserIntent('default'));
|
|
@@ -1,8 +1,49 @@
|
|
|
1
1
|
import { SafePlugin } from '@atlaskit/editor-common/safe-plugin';
|
|
2
|
+
import { stepAddsOneOf } from '@atlaskit/editor-common/utils';
|
|
3
|
+
import { getChangedNodes, isReplaceDocOperation } from '@atlaskit/editor-common/utils/document';
|
|
2
4
|
import { PluginKey } from '@atlaskit/editor-prosemirror/state';
|
|
5
|
+
import { akEditorDefaultLayoutWidth, akEditorFullWidthLayoutWidth, akEditorCalculatedWideLayoutWidth } from '@atlaskit/editor-shared-styles';
|
|
3
6
|
import { ResizingMarkView } from './resizing-mark-view';
|
|
7
|
+
const addBreakoutToResizableNode = ({
|
|
8
|
+
node,
|
|
9
|
+
pos,
|
|
10
|
+
newState,
|
|
11
|
+
newTr,
|
|
12
|
+
breakoutResizableNodes,
|
|
13
|
+
isFullWidthEnabled
|
|
14
|
+
}) => {
|
|
15
|
+
let updatedDocChanged = false;
|
|
16
|
+
let updatedTr = newTr;
|
|
17
|
+
const $pos = newState.doc.resolve(pos);
|
|
18
|
+
const isTopLevelNode = ($pos === null || $pos === void 0 ? void 0 : $pos.depth) === 0;
|
|
19
|
+
if (breakoutResizableNodes.has(node.type) && isTopLevelNode) {
|
|
20
|
+
const {
|
|
21
|
+
breakout
|
|
22
|
+
} = newState.schema.marks;
|
|
23
|
+
const breakoutMark = node.marks.find(mark => mark.type === breakout);
|
|
24
|
+
if (!breakoutMark) {
|
|
25
|
+
const width = isFullWidthEnabled ? akEditorFullWidthLayoutWidth : akEditorDefaultLayoutWidth;
|
|
26
|
+
updatedTr = newTr.setNodeMarkup(pos, node.type, node.attrs, [breakout.create({
|
|
27
|
+
width: width
|
|
28
|
+
})]);
|
|
29
|
+
updatedDocChanged = true;
|
|
30
|
+
} else if ((breakoutMark === null || breakoutMark === void 0 ? void 0 : breakoutMark.attrs.width) === null || (breakoutMark === null || breakoutMark === void 0 ? void 0 : breakoutMark.attrs.width) === undefined) {
|
|
31
|
+
const mode = breakoutMark.attrs.mode;
|
|
32
|
+
const newWidth = mode === 'wide' ? akEditorCalculatedWideLayoutWidth : akEditorFullWidthLayoutWidth;
|
|
33
|
+
updatedTr = newTr.setNodeMarkup(pos, node.type, node.attrs, [breakout.create({
|
|
34
|
+
width: newWidth,
|
|
35
|
+
mode: mode
|
|
36
|
+
})]);
|
|
37
|
+
updatedDocChanged = true;
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
return {
|
|
41
|
+
updatedTr,
|
|
42
|
+
updatedDocChanged
|
|
43
|
+
};
|
|
44
|
+
};
|
|
4
45
|
export const resizingPluginKey = new PluginKey('breakout-resizing');
|
|
5
|
-
export const createResizingPlugin = api => {
|
|
46
|
+
export const createResizingPlugin = (api, options) => {
|
|
6
47
|
return new SafePlugin({
|
|
7
48
|
key: resizingPluginKey,
|
|
8
49
|
props: {
|
|
@@ -11,6 +52,62 @@ export const createResizingPlugin = api => {
|
|
|
11
52
|
return new ResizingMarkView(mark, view, api);
|
|
12
53
|
}
|
|
13
54
|
}
|
|
55
|
+
},
|
|
56
|
+
appendTransaction(transactions, oldState, newState) {
|
|
57
|
+
let newTr = newState.tr;
|
|
58
|
+
let hasDocChanged = false;
|
|
59
|
+
const {
|
|
60
|
+
expand,
|
|
61
|
+
codeBlock,
|
|
62
|
+
layoutSection
|
|
63
|
+
} = newState.schema.nodes;
|
|
64
|
+
const breakoutResizableNodes = new Set([expand, codeBlock, layoutSection]);
|
|
65
|
+
const isFullWidthEnabled = !((options === null || options === void 0 ? void 0 : options.allowBreakoutButton) === true);
|
|
66
|
+
if (isReplaceDocOperation(transactions, oldState)) {
|
|
67
|
+
newState.doc.forEach((node, pos) => {
|
|
68
|
+
const {
|
|
69
|
+
updatedTr,
|
|
70
|
+
updatedDocChanged
|
|
71
|
+
} = addBreakoutToResizableNode({
|
|
72
|
+
node,
|
|
73
|
+
pos,
|
|
74
|
+
newState,
|
|
75
|
+
newTr,
|
|
76
|
+
breakoutResizableNodes,
|
|
77
|
+
isFullWidthEnabled
|
|
78
|
+
});
|
|
79
|
+
newTr = updatedTr;
|
|
80
|
+
hasDocChanged = hasDocChanged || updatedDocChanged;
|
|
81
|
+
});
|
|
82
|
+
} else {
|
|
83
|
+
transactions.forEach(tr => {
|
|
84
|
+
const isAddingResizableNodes = tr.steps.some(step => stepAddsOneOf(step, breakoutResizableNodes));
|
|
85
|
+
if (isAddingResizableNodes) {
|
|
86
|
+
const changedNodes = getChangedNodes(tr);
|
|
87
|
+
changedNodes.forEach(({
|
|
88
|
+
node,
|
|
89
|
+
pos
|
|
90
|
+
}) => {
|
|
91
|
+
const {
|
|
92
|
+
updatedTr,
|
|
93
|
+
updatedDocChanged
|
|
94
|
+
} = addBreakoutToResizableNode({
|
|
95
|
+
node,
|
|
96
|
+
pos,
|
|
97
|
+
newState,
|
|
98
|
+
newTr,
|
|
99
|
+
breakoutResizableNodes,
|
|
100
|
+
isFullWidthEnabled
|
|
101
|
+
});
|
|
102
|
+
newTr = updatedTr;
|
|
103
|
+
hasDocChanged = hasDocChanged || updatedDocChanged;
|
|
104
|
+
});
|
|
105
|
+
}
|
|
106
|
+
});
|
|
107
|
+
}
|
|
108
|
+
if (hasDocChanged) {
|
|
109
|
+
return newTr;
|
|
110
|
+
}
|
|
14
111
|
}
|
|
15
112
|
});
|
|
16
113
|
};
|
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
// TODO: ED-28029 - add fixes for expands and codeblocks
|
|
2
|
-
export function setBreakoutWidth(width, pos, isLivePage) {
|
|
2
|
+
export function setBreakoutWidth(width, mode, pos, isLivePage) {
|
|
3
3
|
return function (state, dispatch) {
|
|
4
4
|
var node = state.doc.nodeAt(pos);
|
|
5
5
|
if (!node) {
|
|
6
6
|
return false;
|
|
7
7
|
}
|
|
8
8
|
var tr = state.tr.setNodeMarkup(pos, node.type, node.attrs, [state.schema.marks.breakout.create({
|
|
9
|
-
width: width
|
|
9
|
+
width: width,
|
|
10
|
+
mode: mode
|
|
10
11
|
})]);
|
|
11
12
|
if (dispatch) {
|
|
12
13
|
dispatch(tr);
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { akEditorGutterPaddingDynamic, akEditorGutterPadding } from
|
|
2
|
-
import { preventUnhandled } from
|
|
3
|
-
import { setBreakoutWidth } from
|
|
4
|
-
import { LOCAL_RESIZE_PROPERTY } from
|
|
1
|
+
import { akEditorGutterPaddingDynamic, akEditorGutterPadding } from '@atlaskit/editor-shared-styles';
|
|
2
|
+
import { preventUnhandled } from '@atlaskit/pragmatic-drag-and-drop/prevent-unhandled';
|
|
3
|
+
import { setBreakoutWidth } from '../editor-commands/set-breakout-width';
|
|
4
|
+
import { LOCAL_RESIZE_PROPERTY } from './resizing-mark-view';
|
|
5
5
|
var RESIZE_RATIO = 2;
|
|
6
6
|
var WIDTHS = {
|
|
7
7
|
MIN: 760,
|
|
@@ -20,7 +20,6 @@ function getProposedWidth(_ref) {
|
|
|
20
20
|
var containerWidth = ((api === null || api === void 0 || (_api$width$sharedStat = api.width.sharedState) === null || _api$width$sharedStat === void 0 || (_api$width$sharedStat = _api$width$sharedStat.currentState()) === null || _api$width$sharedStat === void 0 ? void 0 : _api$width$sharedStat.width) || 0) - 2 * akEditorGutterPaddingDynamic() - akEditorGutterPadding;
|
|
21
21
|
return Math.min(Math.max(WIDTHS.MIN, Math.min(proposedWidth, containerWidth)), WIDTHS.MAX);
|
|
22
22
|
}
|
|
23
|
-
;
|
|
24
23
|
export function createResizerCallbacks(_ref2) {
|
|
25
24
|
var dom = _ref2.dom,
|
|
26
25
|
contentDOM = _ref2.contentDOM,
|
|
@@ -55,13 +54,14 @@ export function createResizerCallbacks(_ref2) {
|
|
|
55
54
|
if (pos === undefined) {
|
|
56
55
|
return;
|
|
57
56
|
}
|
|
57
|
+
var mode = mark.attrs.mode;
|
|
58
58
|
var initialWidth = mark.attrs.width;
|
|
59
59
|
var newWidth = getProposedWidth({
|
|
60
60
|
initialWidth: initialWidth,
|
|
61
61
|
location: location,
|
|
62
62
|
api: api
|
|
63
63
|
});
|
|
64
|
-
setBreakoutWidth(newWidth, pos)(view.state, view.dispatch);
|
|
64
|
+
setBreakoutWidth(newWidth, mode, pos)(view.state, view.dispatch);
|
|
65
65
|
contentDOM.style.removeProperty(LOCAL_RESIZE_PROPERTY);
|
|
66
66
|
view.dispatch(view.state.tr.setMeta('is-resizer-resizing', false).setMeta('scrollIntoView', false));
|
|
67
67
|
api === null || api === void 0 || api.core.actions.execute((_api$userIntent2 = api.userIntent) === null || _api$userIntent2 === void 0 ? void 0 : _api$userIntent2.commands.setCurrentUserIntent('default'));
|
|
@@ -1,8 +1,48 @@
|
|
|
1
1
|
import { SafePlugin } from '@atlaskit/editor-common/safe-plugin';
|
|
2
|
+
import { stepAddsOneOf } from '@atlaskit/editor-common/utils';
|
|
3
|
+
import { getChangedNodes, isReplaceDocOperation } from '@atlaskit/editor-common/utils/document';
|
|
2
4
|
import { PluginKey } from '@atlaskit/editor-prosemirror/state';
|
|
5
|
+
import { akEditorDefaultLayoutWidth, akEditorFullWidthLayoutWidth, akEditorCalculatedWideLayoutWidth } from '@atlaskit/editor-shared-styles';
|
|
3
6
|
import { ResizingMarkView } from './resizing-mark-view';
|
|
7
|
+
var addBreakoutToResizableNode = function addBreakoutToResizableNode(_ref) {
|
|
8
|
+
var node = _ref.node,
|
|
9
|
+
pos = _ref.pos,
|
|
10
|
+
newState = _ref.newState,
|
|
11
|
+
newTr = _ref.newTr,
|
|
12
|
+
breakoutResizableNodes = _ref.breakoutResizableNodes,
|
|
13
|
+
isFullWidthEnabled = _ref.isFullWidthEnabled;
|
|
14
|
+
var updatedDocChanged = false;
|
|
15
|
+
var updatedTr = newTr;
|
|
16
|
+
var $pos = newState.doc.resolve(pos);
|
|
17
|
+
var isTopLevelNode = ($pos === null || $pos === void 0 ? void 0 : $pos.depth) === 0;
|
|
18
|
+
if (breakoutResizableNodes.has(node.type) && isTopLevelNode) {
|
|
19
|
+
var breakout = newState.schema.marks.breakout;
|
|
20
|
+
var breakoutMark = node.marks.find(function (mark) {
|
|
21
|
+
return mark.type === breakout;
|
|
22
|
+
});
|
|
23
|
+
if (!breakoutMark) {
|
|
24
|
+
var width = isFullWidthEnabled ? akEditorFullWidthLayoutWidth : akEditorDefaultLayoutWidth;
|
|
25
|
+
updatedTr = newTr.setNodeMarkup(pos, node.type, node.attrs, [breakout.create({
|
|
26
|
+
width: width
|
|
27
|
+
})]);
|
|
28
|
+
updatedDocChanged = true;
|
|
29
|
+
} else if ((breakoutMark === null || breakoutMark === void 0 ? void 0 : breakoutMark.attrs.width) === null || (breakoutMark === null || breakoutMark === void 0 ? void 0 : breakoutMark.attrs.width) === undefined) {
|
|
30
|
+
var mode = breakoutMark.attrs.mode;
|
|
31
|
+
var newWidth = mode === 'wide' ? akEditorCalculatedWideLayoutWidth : akEditorFullWidthLayoutWidth;
|
|
32
|
+
updatedTr = newTr.setNodeMarkup(pos, node.type, node.attrs, [breakout.create({
|
|
33
|
+
width: newWidth,
|
|
34
|
+
mode: mode
|
|
35
|
+
})]);
|
|
36
|
+
updatedDocChanged = true;
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
return {
|
|
40
|
+
updatedTr: updatedTr,
|
|
41
|
+
updatedDocChanged: updatedDocChanged
|
|
42
|
+
};
|
|
43
|
+
};
|
|
4
44
|
export var resizingPluginKey = new PluginKey('breakout-resizing');
|
|
5
|
-
export var createResizingPlugin = function createResizingPlugin(api) {
|
|
45
|
+
export var createResizingPlugin = function createResizingPlugin(api, options) {
|
|
6
46
|
return new SafePlugin({
|
|
7
47
|
key: resizingPluginKey,
|
|
8
48
|
props: {
|
|
@@ -11,6 +51,60 @@ export var createResizingPlugin = function createResizingPlugin(api) {
|
|
|
11
51
|
return new ResizingMarkView(mark, view, api);
|
|
12
52
|
}
|
|
13
53
|
}
|
|
54
|
+
},
|
|
55
|
+
appendTransaction: function appendTransaction(transactions, oldState, newState) {
|
|
56
|
+
var newTr = newState.tr;
|
|
57
|
+
var hasDocChanged = false;
|
|
58
|
+
var _newState$schema$node = newState.schema.nodes,
|
|
59
|
+
expand = _newState$schema$node.expand,
|
|
60
|
+
codeBlock = _newState$schema$node.codeBlock,
|
|
61
|
+
layoutSection = _newState$schema$node.layoutSection;
|
|
62
|
+
var breakoutResizableNodes = new Set([expand, codeBlock, layoutSection]);
|
|
63
|
+
var isFullWidthEnabled = !((options === null || options === void 0 ? void 0 : options.allowBreakoutButton) === true);
|
|
64
|
+
if (isReplaceDocOperation(transactions, oldState)) {
|
|
65
|
+
newState.doc.forEach(function (node, pos) {
|
|
66
|
+
var _addBreakoutToResizab = addBreakoutToResizableNode({
|
|
67
|
+
node: node,
|
|
68
|
+
pos: pos,
|
|
69
|
+
newState: newState,
|
|
70
|
+
newTr: newTr,
|
|
71
|
+
breakoutResizableNodes: breakoutResizableNodes,
|
|
72
|
+
isFullWidthEnabled: isFullWidthEnabled
|
|
73
|
+
}),
|
|
74
|
+
updatedTr = _addBreakoutToResizab.updatedTr,
|
|
75
|
+
updatedDocChanged = _addBreakoutToResizab.updatedDocChanged;
|
|
76
|
+
newTr = updatedTr;
|
|
77
|
+
hasDocChanged = hasDocChanged || updatedDocChanged;
|
|
78
|
+
});
|
|
79
|
+
} else {
|
|
80
|
+
transactions.forEach(function (tr) {
|
|
81
|
+
var isAddingResizableNodes = tr.steps.some(function (step) {
|
|
82
|
+
return stepAddsOneOf(step, breakoutResizableNodes);
|
|
83
|
+
});
|
|
84
|
+
if (isAddingResizableNodes) {
|
|
85
|
+
var changedNodes = getChangedNodes(tr);
|
|
86
|
+
changedNodes.forEach(function (_ref2) {
|
|
87
|
+
var node = _ref2.node,
|
|
88
|
+
pos = _ref2.pos;
|
|
89
|
+
var _addBreakoutToResizab2 = addBreakoutToResizableNode({
|
|
90
|
+
node: node,
|
|
91
|
+
pos: pos,
|
|
92
|
+
newState: newState,
|
|
93
|
+
newTr: newTr,
|
|
94
|
+
breakoutResizableNodes: breakoutResizableNodes,
|
|
95
|
+
isFullWidthEnabled: isFullWidthEnabled
|
|
96
|
+
}),
|
|
97
|
+
updatedTr = _addBreakoutToResizab2.updatedTr,
|
|
98
|
+
updatedDocChanged = _addBreakoutToResizab2.updatedDocChanged;
|
|
99
|
+
newTr = updatedTr;
|
|
100
|
+
hasDocChanged = hasDocChanged || updatedDocChanged;
|
|
101
|
+
});
|
|
102
|
+
}
|
|
103
|
+
});
|
|
104
|
+
}
|
|
105
|
+
if (hasDocChanged) {
|
|
106
|
+
return newTr;
|
|
107
|
+
}
|
|
14
108
|
}
|
|
15
109
|
});
|
|
16
110
|
};
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import type { Command } from '@atlaskit/editor-common/types';
|
|
2
|
-
export declare function setBreakoutWidth(width: number, pos: number, isLivePage?: boolean): Command;
|
|
1
|
+
import type { BreakoutMode, Command } from '@atlaskit/editor-common/types';
|
|
2
|
+
export declare function setBreakoutWidth(width: number, mode: BreakoutMode, pos: number, isLivePage?: boolean): Command;
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import { ExtractInjectionAPI } from
|
|
1
|
+
import { ExtractInjectionAPI } from '@atlaskit/editor-common/types';
|
|
2
2
|
import { Mark } from '@atlaskit/editor-prosemirror/model';
|
|
3
|
-
import { EditorView } from
|
|
4
|
-
import { BaseEventPayload, ElementDragType } from
|
|
5
|
-
import { BreakoutPlugin } from
|
|
6
|
-
export declare function createResizerCallbacks({ dom, contentDOM, view, mark, api }: {
|
|
3
|
+
import { EditorView } from '@atlaskit/editor-prosemirror/view';
|
|
4
|
+
import { BaseEventPayload, ElementDragType } from '@atlaskit/pragmatic-drag-and-drop/types';
|
|
5
|
+
import { BreakoutPlugin } from '../breakoutPluginType';
|
|
6
|
+
export declare function createResizerCallbacks({ dom, contentDOM, view, mark, api, }: {
|
|
7
7
|
dom: HTMLElement;
|
|
8
8
|
contentDOM: HTMLElement;
|
|
9
9
|
view: EditorView;
|
|
@@ -2,5 +2,6 @@ import { SafePlugin } from '@atlaskit/editor-common/safe-plugin';
|
|
|
2
2
|
import { ExtractInjectionAPI } from '@atlaskit/editor-common/types';
|
|
3
3
|
import { PluginKey } from '@atlaskit/editor-prosemirror/state';
|
|
4
4
|
import { BreakoutPlugin } from '../breakoutPluginType';
|
|
5
|
+
import type { BreakoutPluginOptions } from '../breakoutPluginType';
|
|
5
6
|
export declare const resizingPluginKey: PluginKey<any>;
|
|
6
|
-
export declare const createResizingPlugin: (api: ExtractInjectionAPI<BreakoutPlugin> | undefined) => SafePlugin<any>;
|
|
7
|
+
export declare const createResizingPlugin: (api: ExtractInjectionAPI<BreakoutPlugin> | undefined, options?: BreakoutPluginOptions) => SafePlugin<any>;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import type { Command } from '@atlaskit/editor-common/types';
|
|
2
|
-
export declare function setBreakoutWidth(width: number, pos: number, isLivePage?: boolean): Command;
|
|
1
|
+
import type { BreakoutMode, Command } from '@atlaskit/editor-common/types';
|
|
2
|
+
export declare function setBreakoutWidth(width: number, mode: BreakoutMode, pos: number, isLivePage?: boolean): Command;
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import { ExtractInjectionAPI } from
|
|
1
|
+
import { ExtractInjectionAPI } from '@atlaskit/editor-common/types';
|
|
2
2
|
import { Mark } from '@atlaskit/editor-prosemirror/model';
|
|
3
|
-
import { EditorView } from
|
|
4
|
-
import { BaseEventPayload, ElementDragType } from
|
|
5
|
-
import { BreakoutPlugin } from
|
|
6
|
-
export declare function createResizerCallbacks({ dom, contentDOM, view, mark, api }: {
|
|
3
|
+
import { EditorView } from '@atlaskit/editor-prosemirror/view';
|
|
4
|
+
import { BaseEventPayload, ElementDragType } from '@atlaskit/pragmatic-drag-and-drop/types';
|
|
5
|
+
import { BreakoutPlugin } from '../breakoutPluginType';
|
|
6
|
+
export declare function createResizerCallbacks({ dom, contentDOM, view, mark, api, }: {
|
|
7
7
|
dom: HTMLElement;
|
|
8
8
|
contentDOM: HTMLElement;
|
|
9
9
|
view: EditorView;
|
|
@@ -2,5 +2,6 @@ import { SafePlugin } from '@atlaskit/editor-common/safe-plugin';
|
|
|
2
2
|
import { ExtractInjectionAPI } from '@atlaskit/editor-common/types';
|
|
3
3
|
import { PluginKey } from '@atlaskit/editor-prosemirror/state';
|
|
4
4
|
import { BreakoutPlugin } from '../breakoutPluginType';
|
|
5
|
+
import type { BreakoutPluginOptions } from '../breakoutPluginType';
|
|
5
6
|
export declare const resizingPluginKey: PluginKey<any>;
|
|
6
|
-
export declare const createResizingPlugin: (api: ExtractInjectionAPI<BreakoutPlugin> | undefined) => SafePlugin<any>;
|
|
7
|
+
export declare const createResizingPlugin: (api: ExtractInjectionAPI<BreakoutPlugin> | undefined, options?: BreakoutPluginOptions) => SafePlugin<any>;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@atlaskit/editor-plugin-breakout",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.3.1",
|
|
4
4
|
"description": "Breakout plugin for @atlaskit/editor-core",
|
|
5
5
|
"author": "Atlassian Pty Ltd",
|
|
6
6
|
"license": "Apache-2.0",
|
|
@@ -34,19 +34,19 @@
|
|
|
34
34
|
},
|
|
35
35
|
"dependencies": {
|
|
36
36
|
"@atlaskit/adf-schema": "^47.6.0",
|
|
37
|
-
"@atlaskit/editor-common": "^105.
|
|
38
|
-
"@atlaskit/editor-plugin-block-controls": "^3.
|
|
37
|
+
"@atlaskit/editor-common": "^105.10.0",
|
|
38
|
+
"@atlaskit/editor-plugin-block-controls": "^3.15.0",
|
|
39
39
|
"@atlaskit/editor-plugin-editor-disabled": "^2.0.0",
|
|
40
|
-
"@atlaskit/editor-plugin-editor-viewmode": "^
|
|
40
|
+
"@atlaskit/editor-plugin-editor-viewmode": "^4.0.0",
|
|
41
41
|
"@atlaskit/editor-plugin-user-intent": "^0.1.0",
|
|
42
42
|
"@atlaskit/editor-plugin-width": "^3.0.0",
|
|
43
43
|
"@atlaskit/editor-prosemirror": "7.0.0",
|
|
44
44
|
"@atlaskit/editor-shared-styles": "^3.4.0",
|
|
45
|
-
"@atlaskit/icon": "^26.
|
|
45
|
+
"@atlaskit/icon": "^26.3.0",
|
|
46
46
|
"@atlaskit/platform-feature-flags": "^1.1.0",
|
|
47
47
|
"@atlaskit/pragmatic-drag-and-drop": "^1.7.0",
|
|
48
48
|
"@atlaskit/theme": "^18.0.0",
|
|
49
|
-
"@atlaskit/tmp-editor-statsig": "^
|
|
49
|
+
"@atlaskit/tmp-editor-statsig": "^5.0.0",
|
|
50
50
|
"@atlaskit/tokens": "^4.9.0",
|
|
51
51
|
"@babel/runtime": "^7.0.0",
|
|
52
52
|
"@emotion/react": "^11.7.1"
|