@atlaskit/editor-plugin-layout 2.5.0 → 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 +17 -0
- package/dist/cjs/layoutPlugin.js +36 -1
- package/dist/cjs/pm-plugins/main.js +5 -7
- package/dist/cjs/pm-plugins/utils/index.js +0 -1
- package/dist/es2019/layoutPlugin.js +35 -0
- package/dist/es2019/pm-plugins/main.js +5 -7
- package/dist/es2019/pm-plugins/utils/index.js +0 -1
- package/dist/esm/layoutPlugin.js +36 -0
- package/dist/esm/pm-plugins/main.js +5 -7
- package/dist/esm/pm-plugins/utils/index.js +0 -1
- package/dist/types/layoutPlugin.d.ts +9 -0
- package/dist/types-ts4.5/layoutPlugin.d.ts +9 -0
- package/package.json +4 -4
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,22 @@
|
|
|
1
1
|
# @atlaskit/editor-plugin-layout
|
|
2
2
|
|
|
3
|
+
## 2.6.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- [#144082](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/pull-requests/144082)
|
|
8
|
+
[`583a67e0b8ee7`](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/commits/583a67e0b8ee7) -
|
|
9
|
+
ED-27146 improve layout insertion behaivour, now will select into the layout after insertion.
|
|
10
|
+
|
|
11
|
+
## 2.5.1
|
|
12
|
+
|
|
13
|
+
### Patch Changes
|
|
14
|
+
|
|
15
|
+
- [#142936](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/pull-requests/142936)
|
|
16
|
+
[`9d1e16eaadf95`](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/commits/9d1e16eaadf95) -
|
|
17
|
+
ED-26662: Delete layout column can create a single column layout
|
|
18
|
+
- Updated dependencies
|
|
19
|
+
|
|
3
20
|
## 2.5.0
|
|
4
21
|
|
|
5
22
|
### Minor Changes
|
package/dist/cjs/layoutPlugin.js
CHANGED
|
@@ -4,13 +4,15 @@ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefau
|
|
|
4
4
|
Object.defineProperty(exports, "__esModule", {
|
|
5
5
|
value: true
|
|
6
6
|
});
|
|
7
|
-
exports.layoutPlugin = void 0;
|
|
7
|
+
exports.selectIntoLayoutSection = exports.layoutPlugin = void 0;
|
|
8
8
|
var _react = _interopRequireDefault(require("react"));
|
|
9
9
|
var _adfSchema = require("@atlaskit/adf-schema");
|
|
10
10
|
var _schema = require("@atlaskit/adf-schema/schema");
|
|
11
11
|
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
|
+
var _state = require("@atlaskit/editor-prosemirror/state");
|
|
15
|
+
var _utils = require("@atlaskit/editor-prosemirror/utils");
|
|
14
16
|
var _experiments = require("@atlaskit/tmp-editor-statsig/experiments");
|
|
15
17
|
var _actions = require("./pm-plugins/actions");
|
|
16
18
|
var _main = _interopRequireDefault(require("./pm-plugins/main"));
|
|
@@ -18,6 +20,33 @@ var _pluginKey = require("./pm-plugins/plugin-key");
|
|
|
18
20
|
var _resizing = _interopRequireDefault(require("./pm-plugins/resizing"));
|
|
19
21
|
var _globalStyles = require("./ui/global-styles");
|
|
20
22
|
var _toolbar = require("./ui/toolbar");
|
|
23
|
+
/**
|
|
24
|
+
* This function is used to set the selection into
|
|
25
|
+
* the first paragraph of the first column of a layout section.
|
|
26
|
+
* This function is only intended to be used after inserting a new layout section.
|
|
27
|
+
* @param tr - transaction
|
|
28
|
+
* @returns - transaction with the selection set to the first paragraph of the first column
|
|
29
|
+
*/
|
|
30
|
+
var selectIntoLayoutSection = exports.selectIntoLayoutSection = function selectIntoLayoutSection(tr) {
|
|
31
|
+
var _nodeWithPos$node$fir;
|
|
32
|
+
if (!(0, _experiments.editorExperiment)('single_column_layouts', true)) {
|
|
33
|
+
return tr;
|
|
34
|
+
}
|
|
35
|
+
var _tr$doc$type$schema$n = tr.doc.type.schema.nodes,
|
|
36
|
+
layoutSection = _tr$doc$type$schema$n.layoutSection,
|
|
37
|
+
paragraph = _tr$doc$type$schema$n.paragraph;
|
|
38
|
+
var nodeWithPos = (0, _utils.findParentNode)(function (node) {
|
|
39
|
+
return node.type === layoutSection;
|
|
40
|
+
})(tr.selection);
|
|
41
|
+
if (!nodeWithPos || !nodeWithPos.node || nodeWithPos.node.type.name !== 'layoutSection' || ((_nodeWithPos$node$fir = nodeWithPos.node.firstChild) === null || _nodeWithPos$node$fir === void 0 || (_nodeWithPos$node$fir = _nodeWithPos$node$fir.firstChild) === null || _nodeWithPos$node$fir === void 0 ? void 0 : _nodeWithPos$node$fir.type) !== paragraph) {
|
|
42
|
+
return tr;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
// set text selection at the beginning of the layout section
|
|
46
|
+
// will set the selection to the first column
|
|
47
|
+
tr.setSelection(_state.TextSelection.create(tr.doc, nodeWithPos.pos));
|
|
48
|
+
return tr;
|
|
49
|
+
};
|
|
21
50
|
var layoutPlugin = exports.layoutPlugin = function layoutPlugin(_ref) {
|
|
22
51
|
var _api$analytics;
|
|
23
52
|
var _ref$config = _ref.config,
|
|
@@ -98,6 +127,7 @@ var layoutPlugin = exports.layoutPlugin = function layoutPlugin(_ref) {
|
|
|
98
127
|
action: function action(insert, state, _source) {
|
|
99
128
|
var tr = insert((0, _actions.createMultiColumnLayoutSection)(state, 1));
|
|
100
129
|
withInsertLayoutAnalytics(tr);
|
|
130
|
+
selectIntoLayoutSection(tr);
|
|
101
131
|
return tr;
|
|
102
132
|
}
|
|
103
133
|
}] : [];
|
|
@@ -117,6 +147,7 @@ var layoutPlugin = exports.layoutPlugin = function layoutPlugin(_ref) {
|
|
|
117
147
|
action: function action(insert, state) {
|
|
118
148
|
var tr = insert((0, _actions.createMultiColumnLayoutSection)(state, 3));
|
|
119
149
|
withInsertLayoutAnalytics(tr);
|
|
150
|
+
selectIntoLayoutSection(tr);
|
|
120
151
|
return tr;
|
|
121
152
|
}
|
|
122
153
|
}];
|
|
@@ -135,6 +166,7 @@ var layoutPlugin = exports.layoutPlugin = function layoutPlugin(_ref) {
|
|
|
135
166
|
action: function action(insert, state) {
|
|
136
167
|
var tr = insert((0, _actions.createMultiColumnLayoutSection)(state, 2));
|
|
137
168
|
withInsertLayoutAnalytics(tr);
|
|
169
|
+
selectIntoLayoutSection(tr);
|
|
138
170
|
return tr;
|
|
139
171
|
}
|
|
140
172
|
}, {
|
|
@@ -151,6 +183,7 @@ var layoutPlugin = exports.layoutPlugin = function layoutPlugin(_ref) {
|
|
|
151
183
|
action: function action(insert, state) {
|
|
152
184
|
var tr = insert((0, _actions.createMultiColumnLayoutSection)(state, 3));
|
|
153
185
|
withInsertLayoutAnalytics(tr);
|
|
186
|
+
selectIntoLayoutSection(tr);
|
|
154
187
|
return tr;
|
|
155
188
|
}
|
|
156
189
|
}, {
|
|
@@ -167,6 +200,7 @@ var layoutPlugin = exports.layoutPlugin = function layoutPlugin(_ref) {
|
|
|
167
200
|
action: function action(insert, state) {
|
|
168
201
|
var tr = insert((0, _actions.createMultiColumnLayoutSection)(state, 4));
|
|
169
202
|
withInsertLayoutAnalytics(tr);
|
|
203
|
+
selectIntoLayoutSection(tr);
|
|
170
204
|
return tr;
|
|
171
205
|
}
|
|
172
206
|
}, {
|
|
@@ -183,6 +217,7 @@ var layoutPlugin = exports.layoutPlugin = function layoutPlugin(_ref) {
|
|
|
183
217
|
action: function action(insert, state) {
|
|
184
218
|
var tr = insert((0, _actions.createMultiColumnLayoutSection)(state, 5));
|
|
185
219
|
withInsertLayoutAnalytics(tr);
|
|
220
|
+
selectIntoLayoutSection(tr);
|
|
186
221
|
return tr;
|
|
187
222
|
}
|
|
188
223
|
}]);
|
|
@@ -80,7 +80,7 @@ var getInitialPluginState = function getInitialPluginState(options, state) {
|
|
|
80
80
|
// see packages/editor/editor-plugin-layout-tests/src/__tests__/unit/delete.ts
|
|
81
81
|
var handleDeleteLayoutColumn = function handleDeleteLayoutColumn(state, dispatch) {
|
|
82
82
|
var sel = state.selection;
|
|
83
|
-
if (sel instanceof _state.NodeSelection && sel.node.type.name === 'layoutColumn' && sel.$from.parent.type.name === 'layoutSection' && sel.$from.parent.childCount === 2 && dispatch && (0, _experiments.editorExperiment)('advanced_layouts', true)) {
|
|
83
|
+
if (sel instanceof _state.NodeSelection && sel.node.type.name === 'layoutColumn' && sel.$from.parent.type.name === 'layoutSection' && sel.$from.parent.childCount === 2 && dispatch && (0, _experiments.editorExperiment)('advanced_layouts', true) && !(0, _experiments.editorExperiment)('single_column_layouts', true)) {
|
|
84
84
|
var _sel$$from$parent$las, _sel$$from$parent$fir;
|
|
85
85
|
var tr = state.tr;
|
|
86
86
|
var layoutContentFragment = sel.$from.parentOffset === 0 ? _model.Fragment.from((_sel$$from$parent$las = sel.$from.parent.lastChild) === null || _sel$$from$parent$las === void 0 ? void 0 : _sel$$from$parent$las.content) : _model.Fragment.from((_sel$$from$parent$fir = sel.$from.parent.firstChild) === null || _sel$$from$parent$fir === void 0 ? void 0 : _sel$$from$parent$fir.content);
|
|
@@ -172,12 +172,10 @@ var _default = exports.default = function _default(options) {
|
|
|
172
172
|
if ((0, _experiments.editorExperiment)('advanced_layouts', true) && changes.length === 1) {
|
|
173
173
|
var _change$slice$content, _change$slice$content2;
|
|
174
174
|
var change = changes[0];
|
|
175
|
-
//
|
|
176
|
-
//
|
|
177
|
-
//
|
|
178
|
-
|
|
179
|
-
// when a user deletes a layoutColumn
|
|
180
|
-
if (change.slice.content.childCount === 1 && ((_change$slice$content = change.slice.content.firstChild) === null || _change$slice$content === void 0 ? void 0 : _change$slice$content.type.name) === 'layoutColumn' && ((_change$slice$content2 = change.slice.content.firstChild) === null || _change$slice$content2 === void 0 ? void 0 : _change$slice$content2.attrs.width) === _consts.EVEN_DISTRIBUTED_COL_WIDTHS[1]) {
|
|
175
|
+
// When editorExperiment('single_column_layouts', true) is on
|
|
176
|
+
// delete can create a single column layout
|
|
177
|
+
// otherwise we replace the single column layout with its content
|
|
178
|
+
if (!(0, _experiments.editorExperiment)('single_column_layouts', true) && change.slice.content.childCount === 1 && ((_change$slice$content = change.slice.content.firstChild) === null || _change$slice$content === void 0 ? void 0 : _change$slice$content.type.name) === 'layoutColumn' && ((_change$slice$content2 = change.slice.content.firstChild) === null || _change$slice$content2 === void 0 ? void 0 : _change$slice$content2.attrs.width) === _consts.EVEN_DISTRIBUTED_COL_WIDTHS[1]) {
|
|
181
179
|
var tr = newState.tr;
|
|
182
180
|
var content = change.slice.content.firstChild.content;
|
|
183
181
|
tr.replaceWith(change.from - 1, change.to, content);
|
|
@@ -38,7 +38,6 @@ var selectIntoLayout = exports.selectIntoLayout = function selectIntoLayout(view
|
|
|
38
38
|
var $maybeLayoutSection = view.state.doc.resolve(posOfLayout);
|
|
39
39
|
if (((_$maybeLayoutSection$ = $maybeLayoutSection.nodeAfter) === null || _$maybeLayoutSection$ === void 0 ? void 0 : _$maybeLayoutSection$.type.name) === 'layoutSection') {
|
|
40
40
|
var _layoutSectionNode$fi;
|
|
41
|
-
// $maybeLayoutSection.posAtIndex(1, 1);
|
|
42
41
|
var layoutSectionNode = $maybeLayoutSection.nodeAfter;
|
|
43
42
|
|
|
44
43
|
// check if the childIndex is valid
|
|
@@ -4,6 +4,8 @@ import { layoutSectionWithSingleColumn } from '@atlaskit/adf-schema/schema';
|
|
|
4
4
|
import { ACTION, ACTION_SUBJECT, ACTION_SUBJECT_ID, EVENT_TYPE, INPUT_METHOD } from '@atlaskit/editor-common/analytics';
|
|
5
5
|
import { layoutMessages, toolbarInsertBlockMessages as messages } from '@atlaskit/editor-common/messages';
|
|
6
6
|
import { IconFiveColumnLayout, IconFourColumnLayout, IconLayout, IconOneColumnLayout, IconThreeColumnLayout, IconTwoColumnLayout } from '@atlaskit/editor-common/quick-insert';
|
|
7
|
+
import { TextSelection } from '@atlaskit/editor-prosemirror/state';
|
|
8
|
+
import { findParentNode } from '@atlaskit/editor-prosemirror/utils';
|
|
7
9
|
import { editorExperiment } from '@atlaskit/tmp-editor-statsig/experiments';
|
|
8
10
|
import { createDefaultLayoutSection, createMultiColumnLayoutSection, insertLayoutColumnsWithAnalytics } from './pm-plugins/actions';
|
|
9
11
|
import { default as createLayoutPlugin } from './pm-plugins/main';
|
|
@@ -11,6 +13,33 @@ import { pluginKey } from './pm-plugins/plugin-key';
|
|
|
11
13
|
import { default as createLayoutResizingPlugin } from './pm-plugins/resizing';
|
|
12
14
|
import { GlobalStylesWrapper } from './ui/global-styles';
|
|
13
15
|
import { buildToolbar } from './ui/toolbar';
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* This function is used to set the selection into
|
|
19
|
+
* the first paragraph of the first column of a layout section.
|
|
20
|
+
* This function is only intended to be used after inserting a new layout section.
|
|
21
|
+
* @param tr - transaction
|
|
22
|
+
* @returns - transaction with the selection set to the first paragraph of the first column
|
|
23
|
+
*/
|
|
24
|
+
export const selectIntoLayoutSection = tr => {
|
|
25
|
+
var _nodeWithPos$node$fir, _nodeWithPos$node$fir2;
|
|
26
|
+
if (!editorExperiment('single_column_layouts', true)) {
|
|
27
|
+
return tr;
|
|
28
|
+
}
|
|
29
|
+
const {
|
|
30
|
+
layoutSection,
|
|
31
|
+
paragraph
|
|
32
|
+
} = tr.doc.type.schema.nodes;
|
|
33
|
+
const nodeWithPos = findParentNode(node => node.type === layoutSection)(tr.selection);
|
|
34
|
+
if (!nodeWithPos || !nodeWithPos.node || nodeWithPos.node.type.name !== 'layoutSection' || ((_nodeWithPos$node$fir = nodeWithPos.node.firstChild) === null || _nodeWithPos$node$fir === void 0 ? void 0 : (_nodeWithPos$node$fir2 = _nodeWithPos$node$fir.firstChild) === null || _nodeWithPos$node$fir2 === void 0 ? void 0 : _nodeWithPos$node$fir2.type) !== paragraph) {
|
|
35
|
+
return tr;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
// set text selection at the beginning of the layout section
|
|
39
|
+
// will set the selection to the first column
|
|
40
|
+
tr.setSelection(TextSelection.create(tr.doc, nodeWithPos.pos));
|
|
41
|
+
return tr;
|
|
42
|
+
};
|
|
14
43
|
export const layoutPlugin = ({
|
|
15
44
|
config: options = {},
|
|
16
45
|
api
|
|
@@ -88,6 +117,7 @@ export const layoutPlugin = ({
|
|
|
88
117
|
action(insert, state, _source) {
|
|
89
118
|
const tr = insert(createMultiColumnLayoutSection(state, 1));
|
|
90
119
|
withInsertLayoutAnalytics(tr);
|
|
120
|
+
selectIntoLayoutSection(tr);
|
|
91
121
|
return tr;
|
|
92
122
|
}
|
|
93
123
|
}] : [];
|
|
@@ -105,6 +135,7 @@ export const layoutPlugin = ({
|
|
|
105
135
|
action(insert, state) {
|
|
106
136
|
const tr = insert(createMultiColumnLayoutSection(state, 3));
|
|
107
137
|
withInsertLayoutAnalytics(tr);
|
|
138
|
+
selectIntoLayoutSection(tr);
|
|
108
139
|
return tr;
|
|
109
140
|
}
|
|
110
141
|
}];
|
|
@@ -121,6 +152,7 @@ export const layoutPlugin = ({
|
|
|
121
152
|
action(insert, state) {
|
|
122
153
|
const tr = insert(createMultiColumnLayoutSection(state, 2));
|
|
123
154
|
withInsertLayoutAnalytics(tr);
|
|
155
|
+
selectIntoLayoutSection(tr);
|
|
124
156
|
return tr;
|
|
125
157
|
}
|
|
126
158
|
}, {
|
|
@@ -135,6 +167,7 @@ export const layoutPlugin = ({
|
|
|
135
167
|
action(insert, state) {
|
|
136
168
|
const tr = insert(createMultiColumnLayoutSection(state, 3));
|
|
137
169
|
withInsertLayoutAnalytics(tr);
|
|
170
|
+
selectIntoLayoutSection(tr);
|
|
138
171
|
return tr;
|
|
139
172
|
}
|
|
140
173
|
}, {
|
|
@@ -149,6 +182,7 @@ export const layoutPlugin = ({
|
|
|
149
182
|
action(insert, state) {
|
|
150
183
|
const tr = insert(createMultiColumnLayoutSection(state, 4));
|
|
151
184
|
withInsertLayoutAnalytics(tr);
|
|
185
|
+
selectIntoLayoutSection(tr);
|
|
152
186
|
return tr;
|
|
153
187
|
}
|
|
154
188
|
}, {
|
|
@@ -163,6 +197,7 @@ export const layoutPlugin = ({
|
|
|
163
197
|
action(insert, state) {
|
|
164
198
|
const tr = insert(createMultiColumnLayoutSection(state, 5));
|
|
165
199
|
withInsertLayoutAnalytics(tr);
|
|
200
|
+
selectIntoLayoutSection(tr);
|
|
166
201
|
return tr;
|
|
167
202
|
}
|
|
168
203
|
}];
|
|
@@ -75,7 +75,7 @@ const getInitialPluginState = (options, state) => {
|
|
|
75
75
|
// see packages/editor/editor-plugin-layout-tests/src/__tests__/unit/delete.ts
|
|
76
76
|
const handleDeleteLayoutColumn = (state, dispatch) => {
|
|
77
77
|
const sel = state.selection;
|
|
78
|
-
if (sel instanceof NodeSelection && sel.node.type.name === 'layoutColumn' && sel.$from.parent.type.name === 'layoutSection' && sel.$from.parent.childCount === 2 && dispatch && editorExperiment('advanced_layouts', true)) {
|
|
78
|
+
if (sel instanceof NodeSelection && sel.node.type.name === 'layoutColumn' && sel.$from.parent.type.name === 'layoutSection' && sel.$from.parent.childCount === 2 && dispatch && editorExperiment('advanced_layouts', true) && !editorExperiment('single_column_layouts', true)) {
|
|
79
79
|
var _sel$$from$parent$las, _sel$$from$parent$fir;
|
|
80
80
|
const tr = state.tr;
|
|
81
81
|
const layoutContentFragment = sel.$from.parentOffset === 0 ? Fragment.from((_sel$$from$parent$las = sel.$from.parent.lastChild) === null || _sel$$from$parent$las === void 0 ? void 0 : _sel$$from$parent$las.content) : Fragment.from((_sel$$from$parent$fir = sel.$from.parent.firstChild) === null || _sel$$from$parent$fir === void 0 ? void 0 : _sel$$from$parent$fir.content);
|
|
@@ -162,12 +162,10 @@ export default (options => new SafePlugin({
|
|
|
162
162
|
if (editorExperiment('advanced_layouts', true) && changes.length === 1) {
|
|
163
163
|
var _change$slice$content, _change$slice$content2;
|
|
164
164
|
const change = changes[0];
|
|
165
|
-
//
|
|
166
|
-
//
|
|
167
|
-
//
|
|
168
|
-
|
|
169
|
-
// when a user deletes a layoutColumn
|
|
170
|
-
if (change.slice.content.childCount === 1 && ((_change$slice$content = change.slice.content.firstChild) === null || _change$slice$content === void 0 ? void 0 : _change$slice$content.type.name) === 'layoutColumn' && ((_change$slice$content2 = change.slice.content.firstChild) === null || _change$slice$content2 === void 0 ? void 0 : _change$slice$content2.attrs.width) === EVEN_DISTRIBUTED_COL_WIDTHS[1]) {
|
|
165
|
+
// When editorExperiment('single_column_layouts', true) is on
|
|
166
|
+
// delete can create a single column layout
|
|
167
|
+
// otherwise we replace the single column layout with its content
|
|
168
|
+
if (!editorExperiment('single_column_layouts', true) && change.slice.content.childCount === 1 && ((_change$slice$content = change.slice.content.firstChild) === null || _change$slice$content === void 0 ? void 0 : _change$slice$content.type.name) === 'layoutColumn' && ((_change$slice$content2 = change.slice.content.firstChild) === null || _change$slice$content2 === void 0 ? void 0 : _change$slice$content2.attrs.width) === EVEN_DISTRIBUTED_COL_WIDTHS[1]) {
|
|
171
169
|
const tr = newState.tr;
|
|
172
170
|
const {
|
|
173
171
|
content
|
|
@@ -36,7 +36,6 @@ export const selectIntoLayout = (view, posOfLayout, childIndex = 0) => {
|
|
|
36
36
|
const $maybeLayoutSection = view.state.doc.resolve(posOfLayout);
|
|
37
37
|
if (((_$maybeLayoutSection$ = $maybeLayoutSection.nodeAfter) === null || _$maybeLayoutSection$ === void 0 ? void 0 : _$maybeLayoutSection$.type.name) === 'layoutSection') {
|
|
38
38
|
var _layoutSectionNode$fi;
|
|
39
|
-
// $maybeLayoutSection.posAtIndex(1, 1);
|
|
40
39
|
const layoutSectionNode = $maybeLayoutSection.nodeAfter;
|
|
41
40
|
|
|
42
41
|
// check if the childIndex is valid
|
package/dist/esm/layoutPlugin.js
CHANGED
|
@@ -4,6 +4,8 @@ import { layoutSectionWithSingleColumn } from '@atlaskit/adf-schema/schema';
|
|
|
4
4
|
import { ACTION, ACTION_SUBJECT, ACTION_SUBJECT_ID, EVENT_TYPE, INPUT_METHOD } from '@atlaskit/editor-common/analytics';
|
|
5
5
|
import { layoutMessages, toolbarInsertBlockMessages as messages } from '@atlaskit/editor-common/messages';
|
|
6
6
|
import { IconFiveColumnLayout, IconFourColumnLayout, IconLayout, IconOneColumnLayout, IconThreeColumnLayout, IconTwoColumnLayout } from '@atlaskit/editor-common/quick-insert';
|
|
7
|
+
import { TextSelection } from '@atlaskit/editor-prosemirror/state';
|
|
8
|
+
import { findParentNode } from '@atlaskit/editor-prosemirror/utils';
|
|
7
9
|
import { editorExperiment } from '@atlaskit/tmp-editor-statsig/experiments';
|
|
8
10
|
import { createDefaultLayoutSection, createMultiColumnLayoutSection, insertLayoutColumnsWithAnalytics } from './pm-plugins/actions';
|
|
9
11
|
import { default as createLayoutPlugin } from './pm-plugins/main';
|
|
@@ -11,6 +13,34 @@ import { pluginKey } from './pm-plugins/plugin-key';
|
|
|
11
13
|
import { default as createLayoutResizingPlugin } from './pm-plugins/resizing';
|
|
12
14
|
import { GlobalStylesWrapper } from './ui/global-styles';
|
|
13
15
|
import { buildToolbar } from './ui/toolbar';
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* This function is used to set the selection into
|
|
19
|
+
* the first paragraph of the first column of a layout section.
|
|
20
|
+
* This function is only intended to be used after inserting a new layout section.
|
|
21
|
+
* @param tr - transaction
|
|
22
|
+
* @returns - transaction with the selection set to the first paragraph of the first column
|
|
23
|
+
*/
|
|
24
|
+
export var selectIntoLayoutSection = function selectIntoLayoutSection(tr) {
|
|
25
|
+
var _nodeWithPos$node$fir;
|
|
26
|
+
if (!editorExperiment('single_column_layouts', true)) {
|
|
27
|
+
return tr;
|
|
28
|
+
}
|
|
29
|
+
var _tr$doc$type$schema$n = tr.doc.type.schema.nodes,
|
|
30
|
+
layoutSection = _tr$doc$type$schema$n.layoutSection,
|
|
31
|
+
paragraph = _tr$doc$type$schema$n.paragraph;
|
|
32
|
+
var nodeWithPos = findParentNode(function (node) {
|
|
33
|
+
return node.type === layoutSection;
|
|
34
|
+
})(tr.selection);
|
|
35
|
+
if (!nodeWithPos || !nodeWithPos.node || nodeWithPos.node.type.name !== 'layoutSection' || ((_nodeWithPos$node$fir = nodeWithPos.node.firstChild) === null || _nodeWithPos$node$fir === void 0 || (_nodeWithPos$node$fir = _nodeWithPos$node$fir.firstChild) === null || _nodeWithPos$node$fir === void 0 ? void 0 : _nodeWithPos$node$fir.type) !== paragraph) {
|
|
36
|
+
return tr;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
// set text selection at the beginning of the layout section
|
|
40
|
+
// will set the selection to the first column
|
|
41
|
+
tr.setSelection(TextSelection.create(tr.doc, nodeWithPos.pos));
|
|
42
|
+
return tr;
|
|
43
|
+
};
|
|
14
44
|
export var layoutPlugin = function layoutPlugin(_ref) {
|
|
15
45
|
var _api$analytics;
|
|
16
46
|
var _ref$config = _ref.config,
|
|
@@ -91,6 +121,7 @@ export var layoutPlugin = function layoutPlugin(_ref) {
|
|
|
91
121
|
action: function action(insert, state, _source) {
|
|
92
122
|
var tr = insert(createMultiColumnLayoutSection(state, 1));
|
|
93
123
|
withInsertLayoutAnalytics(tr);
|
|
124
|
+
selectIntoLayoutSection(tr);
|
|
94
125
|
return tr;
|
|
95
126
|
}
|
|
96
127
|
}] : [];
|
|
@@ -110,6 +141,7 @@ export var layoutPlugin = function layoutPlugin(_ref) {
|
|
|
110
141
|
action: function action(insert, state) {
|
|
111
142
|
var tr = insert(createMultiColumnLayoutSection(state, 3));
|
|
112
143
|
withInsertLayoutAnalytics(tr);
|
|
144
|
+
selectIntoLayoutSection(tr);
|
|
113
145
|
return tr;
|
|
114
146
|
}
|
|
115
147
|
}];
|
|
@@ -128,6 +160,7 @@ export var layoutPlugin = function layoutPlugin(_ref) {
|
|
|
128
160
|
action: function action(insert, state) {
|
|
129
161
|
var tr = insert(createMultiColumnLayoutSection(state, 2));
|
|
130
162
|
withInsertLayoutAnalytics(tr);
|
|
163
|
+
selectIntoLayoutSection(tr);
|
|
131
164
|
return tr;
|
|
132
165
|
}
|
|
133
166
|
}, {
|
|
@@ -144,6 +177,7 @@ export var layoutPlugin = function layoutPlugin(_ref) {
|
|
|
144
177
|
action: function action(insert, state) {
|
|
145
178
|
var tr = insert(createMultiColumnLayoutSection(state, 3));
|
|
146
179
|
withInsertLayoutAnalytics(tr);
|
|
180
|
+
selectIntoLayoutSection(tr);
|
|
147
181
|
return tr;
|
|
148
182
|
}
|
|
149
183
|
}, {
|
|
@@ -160,6 +194,7 @@ export var layoutPlugin = function layoutPlugin(_ref) {
|
|
|
160
194
|
action: function action(insert, state) {
|
|
161
195
|
var tr = insert(createMultiColumnLayoutSection(state, 4));
|
|
162
196
|
withInsertLayoutAnalytics(tr);
|
|
197
|
+
selectIntoLayoutSection(tr);
|
|
163
198
|
return tr;
|
|
164
199
|
}
|
|
165
200
|
}, {
|
|
@@ -176,6 +211,7 @@ export var layoutPlugin = function layoutPlugin(_ref) {
|
|
|
176
211
|
action: function action(insert, state) {
|
|
177
212
|
var tr = insert(createMultiColumnLayoutSection(state, 5));
|
|
178
213
|
withInsertLayoutAnalytics(tr);
|
|
214
|
+
selectIntoLayoutSection(tr);
|
|
179
215
|
return tr;
|
|
180
216
|
}
|
|
181
217
|
}]);
|
|
@@ -73,7 +73,7 @@ var getInitialPluginState = function getInitialPluginState(options, state) {
|
|
|
73
73
|
// see packages/editor/editor-plugin-layout-tests/src/__tests__/unit/delete.ts
|
|
74
74
|
var handleDeleteLayoutColumn = function handleDeleteLayoutColumn(state, dispatch) {
|
|
75
75
|
var sel = state.selection;
|
|
76
|
-
if (sel instanceof NodeSelection && sel.node.type.name === 'layoutColumn' && sel.$from.parent.type.name === 'layoutSection' && sel.$from.parent.childCount === 2 && dispatch && editorExperiment('advanced_layouts', true)) {
|
|
76
|
+
if (sel instanceof NodeSelection && sel.node.type.name === 'layoutColumn' && sel.$from.parent.type.name === 'layoutSection' && sel.$from.parent.childCount === 2 && dispatch && editorExperiment('advanced_layouts', true) && !editorExperiment('single_column_layouts', true)) {
|
|
77
77
|
var _sel$$from$parent$las, _sel$$from$parent$fir;
|
|
78
78
|
var tr = state.tr;
|
|
79
79
|
var layoutContentFragment = sel.$from.parentOffset === 0 ? Fragment.from((_sel$$from$parent$las = sel.$from.parent.lastChild) === null || _sel$$from$parent$las === void 0 ? void 0 : _sel$$from$parent$las.content) : Fragment.from((_sel$$from$parent$fir = sel.$from.parent.firstChild) === null || _sel$$from$parent$fir === void 0 ? void 0 : _sel$$from$parent$fir.content);
|
|
@@ -165,12 +165,10 @@ export default (function (options) {
|
|
|
165
165
|
if (editorExperiment('advanced_layouts', true) && changes.length === 1) {
|
|
166
166
|
var _change$slice$content, _change$slice$content2;
|
|
167
167
|
var change = changes[0];
|
|
168
|
-
//
|
|
169
|
-
//
|
|
170
|
-
//
|
|
171
|
-
|
|
172
|
-
// when a user deletes a layoutColumn
|
|
173
|
-
if (change.slice.content.childCount === 1 && ((_change$slice$content = change.slice.content.firstChild) === null || _change$slice$content === void 0 ? void 0 : _change$slice$content.type.name) === 'layoutColumn' && ((_change$slice$content2 = change.slice.content.firstChild) === null || _change$slice$content2 === void 0 ? void 0 : _change$slice$content2.attrs.width) === EVEN_DISTRIBUTED_COL_WIDTHS[1]) {
|
|
168
|
+
// When editorExperiment('single_column_layouts', true) is on
|
|
169
|
+
// delete can create a single column layout
|
|
170
|
+
// otherwise we replace the single column layout with its content
|
|
171
|
+
if (!editorExperiment('single_column_layouts', true) && change.slice.content.childCount === 1 && ((_change$slice$content = change.slice.content.firstChild) === null || _change$slice$content === void 0 ? void 0 : _change$slice$content.type.name) === 'layoutColumn' && ((_change$slice$content2 = change.slice.content.firstChild) === null || _change$slice$content2 === void 0 ? void 0 : _change$slice$content2.attrs.width) === EVEN_DISTRIBUTED_COL_WIDTHS[1]) {
|
|
174
172
|
var tr = newState.tr;
|
|
175
173
|
var content = change.slice.content.firstChild.content;
|
|
176
174
|
tr.replaceWith(change.from - 1, change.to, content);
|
|
@@ -32,7 +32,6 @@ export var selectIntoLayout = function selectIntoLayout(view, posOfLayout) {
|
|
|
32
32
|
var $maybeLayoutSection = view.state.doc.resolve(posOfLayout);
|
|
33
33
|
if (((_$maybeLayoutSection$ = $maybeLayoutSection.nodeAfter) === null || _$maybeLayoutSection$ === void 0 ? void 0 : _$maybeLayoutSection$.type.name) === 'layoutSection') {
|
|
34
34
|
var _layoutSectionNode$fi;
|
|
35
|
-
// $maybeLayoutSection.posAtIndex(1, 1);
|
|
36
35
|
var layoutSectionNode = $maybeLayoutSection.nodeAfter;
|
|
37
36
|
|
|
38
37
|
// check if the childIndex is valid
|
|
@@ -1,2 +1,11 @@
|
|
|
1
|
+
import { type Transaction } from '@atlaskit/editor-prosemirror/state';
|
|
1
2
|
import type { LayoutPlugin } from './layoutPluginType';
|
|
3
|
+
/**
|
|
4
|
+
* This function is used to set the selection into
|
|
5
|
+
* the first paragraph of the first column of a layout section.
|
|
6
|
+
* This function is only intended to be used after inserting a new layout section.
|
|
7
|
+
* @param tr - transaction
|
|
8
|
+
* @returns - transaction with the selection set to the first paragraph of the first column
|
|
9
|
+
*/
|
|
10
|
+
export declare const selectIntoLayoutSection: (tr: Transaction) => Transaction;
|
|
2
11
|
export declare const layoutPlugin: LayoutPlugin;
|
|
@@ -1,2 +1,11 @@
|
|
|
1
|
+
import { type Transaction } from '@atlaskit/editor-prosemirror/state';
|
|
1
2
|
import type { LayoutPlugin } from './layoutPluginType';
|
|
3
|
+
/**
|
|
4
|
+
* This function is used to set the selection into
|
|
5
|
+
* the first paragraph of the first column of a layout section.
|
|
6
|
+
* This function is only intended to be used after inserting a new layout section.
|
|
7
|
+
* @param tr - transaction
|
|
8
|
+
* @returns - transaction with the selection set to the first paragraph of the first column
|
|
9
|
+
*/
|
|
10
|
+
export declare const selectIntoLayoutSection: (tr: Transaction) => Transaction;
|
|
2
11
|
export declare const layoutPlugin: LayoutPlugin;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@atlaskit/editor-plugin-layout",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.6.0",
|
|
4
4
|
"description": "Layout plugin for @atlaskit/editor-core",
|
|
5
5
|
"author": "Atlassian Pty Ltd",
|
|
6
6
|
"license": "Apache-2.0",
|
|
@@ -34,7 +34,7 @@
|
|
|
34
34
|
},
|
|
35
35
|
"dependencies": {
|
|
36
36
|
"@atlaskit/adf-schema": "^47.6.0",
|
|
37
|
-
"@atlaskit/editor-common": "^103.
|
|
37
|
+
"@atlaskit/editor-common": "^103.12.0",
|
|
38
38
|
"@atlaskit/editor-plugin-analytics": "^2.2.0",
|
|
39
39
|
"@atlaskit/editor-plugin-decorations": "^2.0.0",
|
|
40
40
|
"@atlaskit/editor-plugin-editor-disabled": "^2.0.0",
|
|
@@ -45,8 +45,8 @@
|
|
|
45
45
|
"@atlaskit/editor-shared-styles": "^3.4.0",
|
|
46
46
|
"@atlaskit/icon": "^25.6.0",
|
|
47
47
|
"@atlaskit/platform-feature-flags": "^1.1.0",
|
|
48
|
-
"@atlaskit/tmp-editor-statsig": "^4.
|
|
49
|
-
"@atlaskit/tokens": "^4.
|
|
48
|
+
"@atlaskit/tmp-editor-statsig": "^4.12.0",
|
|
49
|
+
"@atlaskit/tokens": "^4.8.0",
|
|
50
50
|
"@babel/runtime": "^7.0.0",
|
|
51
51
|
"@emotion/react": "^11.7.1"
|
|
52
52
|
},
|