@atlaskit/editor-core 189.1.10 → 189.1.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.
Files changed (75) hide show
  1. package/CHANGELOG.md +13 -0
  2. package/dist/cjs/plugins/index.js +0 -7
  3. package/dist/cjs/plugins/insert-block/index.js +3 -8
  4. package/dist/cjs/presets/universal.js +2 -1
  5. package/dist/cjs/ui/ContentStyles/index.js +8 -8
  6. package/dist/cjs/{plugins/layout/styles.js → ui/ContentStyles/layout.js} +1 -0
  7. package/dist/cjs/version-wrapper.js +1 -1
  8. package/dist/es2019/plugins/index.js +0 -1
  9. package/dist/es2019/plugins/insert-block/index.js +3 -8
  10. package/dist/es2019/presets/universal.js +2 -1
  11. package/dist/es2019/ui/ContentStyles/index.js +1 -1
  12. package/dist/es2019/{plugins/layout/styles.js → ui/ContentStyles/layout.js} +1 -0
  13. package/dist/es2019/version-wrapper.js +1 -1
  14. package/dist/esm/plugins/index.js +0 -1
  15. package/dist/esm/plugins/insert-block/index.js +3 -8
  16. package/dist/esm/presets/universal.js +2 -1
  17. package/dist/esm/ui/ContentStyles/index.js +1 -1
  18. package/dist/esm/{plugins/layout/styles.js → ui/ContentStyles/layout.js} +1 -0
  19. package/dist/esm/version-wrapper.js +1 -1
  20. package/dist/types/plugins/index.d.ts +0 -1
  21. package/dist/types/plugins/insert-block/types.d.ts +1 -1
  22. package/dist/types/types/editor-props.d.ts +1 -1
  23. package/dist/types/{plugins/layout/styles.d.ts → ui/ContentStyles/layout.d.ts} +1 -1
  24. package/dist/types-ts4.5/plugins/index.d.ts +0 -1
  25. package/dist/types-ts4.5/plugins/insert-block/types.d.ts +1 -1
  26. package/dist/types-ts4.5/types/editor-props.d.ts +1 -1
  27. package/dist/types-ts4.5/{plugins/layout/styles.d.ts → ui/ContentStyles/layout.d.ts} +1 -1
  28. package/package.json +2 -1
  29. package/report.api.md +1 -10
  30. package/tmp/api-report-tmp.d.ts +1 -10
  31. package/dist/cjs/plugins/layout/actions.js +0 -346
  32. package/dist/cjs/plugins/layout/index.js +0 -92
  33. package/dist/cjs/plugins/layout/pm-plugins/main.js +0 -148
  34. package/dist/cjs/plugins/layout/pm-plugins/plugin-key.js +0 -8
  35. package/dist/cjs/plugins/layout/pm-plugins/types.js +0 -5
  36. package/dist/cjs/plugins/layout/toolbar-messages.js +0 -39
  37. package/dist/cjs/plugins/layout/toolbar.js +0 -116
  38. package/dist/cjs/plugins/layout/types.js +0 -5
  39. package/dist/cjs/plugins/layout/utils.js +0 -30
  40. package/dist/es2019/plugins/layout/actions.js +0 -329
  41. package/dist/es2019/plugins/layout/index.js +0 -76
  42. package/dist/es2019/plugins/layout/pm-plugins/main.js +0 -142
  43. package/dist/es2019/plugins/layout/pm-plugins/plugin-key.js +0 -2
  44. package/dist/es2019/plugins/layout/pm-plugins/types.js +0 -1
  45. package/dist/es2019/plugins/layout/toolbar-messages.js +0 -33
  46. package/dist/es2019/plugins/layout/toolbar.js +0 -101
  47. package/dist/es2019/plugins/layout/types.js +0 -1
  48. package/dist/es2019/plugins/layout/utils.js +0 -1
  49. package/dist/esm/plugins/layout/actions.js +0 -337
  50. package/dist/esm/plugins/layout/index.js +0 -80
  51. package/dist/esm/plugins/layout/pm-plugins/main.js +0 -141
  52. package/dist/esm/plugins/layout/pm-plugins/plugin-key.js +0 -2
  53. package/dist/esm/plugins/layout/pm-plugins/types.js +0 -1
  54. package/dist/esm/plugins/layout/toolbar-messages.js +0 -33
  55. package/dist/esm/plugins/layout/toolbar.js +0 -109
  56. package/dist/esm/plugins/layout/types.js +0 -1
  57. package/dist/esm/plugins/layout/utils.js +0 -1
  58. package/dist/types/plugins/layout/actions.d.ts +0 -23
  59. package/dist/types/plugins/layout/index.d.ts +0 -16
  60. package/dist/types/plugins/layout/pm-plugins/main.d.ts +0 -6
  61. package/dist/types/plugins/layout/pm-plugins/plugin-key.d.ts +0 -3
  62. package/dist/types/plugins/layout/pm-plugins/types.d.ts +0 -14
  63. package/dist/types/plugins/layout/toolbar-messages.d.ts +0 -32
  64. package/dist/types/plugins/layout/toolbar.d.ts +0 -6
  65. package/dist/types/plugins/layout/types.d.ts +0 -13
  66. package/dist/types/plugins/layout/utils.d.ts +0 -1
  67. package/dist/types-ts4.5/plugins/layout/actions.d.ts +0 -23
  68. package/dist/types-ts4.5/plugins/layout/index.d.ts +0 -19
  69. package/dist/types-ts4.5/plugins/layout/pm-plugins/main.d.ts +0 -6
  70. package/dist/types-ts4.5/plugins/layout/pm-plugins/plugin-key.d.ts +0 -3
  71. package/dist/types-ts4.5/plugins/layout/pm-plugins/types.d.ts +0 -14
  72. package/dist/types-ts4.5/plugins/layout/toolbar-messages.d.ts +0 -32
  73. package/dist/types-ts4.5/plugins/layout/toolbar.d.ts +0 -6
  74. package/dist/types-ts4.5/plugins/layout/types.d.ts +0 -13
  75. package/dist/types-ts4.5/plugins/layout/utils.d.ts +0 -1
@@ -1,116 +0,0 @@
1
- "use strict";
2
-
3
- var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
- Object.defineProperty(exports, "__esModule", {
5
- value: true
6
- });
7
- exports.layoutToolbarTitle = exports.buildToolbar = void 0;
8
- var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray"));
9
- var _utils = require("@atlaskit/editor-prosemirror/utils");
10
- var _layoutSingle = _interopRequireDefault(require("@atlaskit/icon/glyph/editor/layout-single"));
11
- var _layoutTwoEqual = _interopRequireDefault(require("@atlaskit/icon/glyph/editor/layout-two-equal"));
12
- var _layoutThreeEqual = _interopRequireDefault(require("@atlaskit/icon/glyph/editor/layout-three-equal"));
13
- var _layoutTwoLeftSidebar = _interopRequireDefault(require("@atlaskit/icon/glyph/editor/layout-two-left-sidebar"));
14
- var _layoutTwoRightSidebar = _interopRequireDefault(require("@atlaskit/icon/glyph/editor/layout-two-right-sidebar"));
15
- var _layoutThreeWithSidebars = _interopRequireDefault(require("@atlaskit/icon/glyph/editor/layout-three-with-sidebars"));
16
- var _remove = _interopRequireDefault(require("@atlaskit/icon/glyph/editor/remove"));
17
- var _toolbarMessages = require("./toolbar-messages");
18
- var _messages = _interopRequireDefault(require("../../messages"));
19
- var _actions = require("./actions");
20
- var LAYOUT_TYPES = [{
21
- id: 'editor.layout.twoEquals',
22
- type: 'two_equal',
23
- title: _toolbarMessages.toolbarMessages.twoColumns,
24
- icon: _layoutTwoEqual.default
25
- }, {
26
- id: 'editor.layout.threeEquals',
27
- type: 'three_equal',
28
- title: _toolbarMessages.toolbarMessages.threeColumns,
29
- icon: _layoutThreeEqual.default
30
- }];
31
- var LAYOUT_TYPES_WITH_SINGLE_COL = [{
32
- id: 'editor.layout.singeLayout',
33
- type: 'single',
34
- title: _toolbarMessages.toolbarMessages.singleColumn,
35
- icon: _layoutSingle.default
36
- }].concat(LAYOUT_TYPES);
37
- var SIDEBAR_LAYOUT_TYPES = [{
38
- id: 'editor.layout.twoRightSidebar',
39
- type: 'two_right_sidebar',
40
- title: _toolbarMessages.toolbarMessages.rightSidebar,
41
- icon: _layoutTwoRightSidebar.default
42
- }, {
43
- id: 'editor.layout.twoLeftSidebar',
44
- type: 'two_left_sidebar',
45
- title: _toolbarMessages.toolbarMessages.leftSidebar,
46
- icon: _layoutTwoLeftSidebar.default
47
- }, {
48
- id: 'editor.layout.threeWithSidebars',
49
- type: 'three_with_sidebars',
50
- title: _toolbarMessages.toolbarMessages.threeColumnsWithSidebars,
51
- icon: _layoutThreeWithSidebars.default
52
- }];
53
- var buildLayoutButton = function buildLayoutButton(intl, item, currentLayout, editorAnalyticsAPI) {
54
- return {
55
- id: item.id,
56
- type: 'button',
57
- icon: item.icon,
58
- testId: item.title.id,
59
- title: intl.formatMessage(item.title),
60
- onClick: (0, _actions.setPresetLayout)(editorAnalyticsAPI)(item.type),
61
- selected: !!currentLayout && currentLayout === item.type,
62
- tabIndex: null
63
- };
64
- };
65
- var layoutToolbarTitle = exports.layoutToolbarTitle = 'Layout floating controls';
66
- var buildToolbar = exports.buildToolbar = function buildToolbar(state, intl, pos, _allowBreakout, addSidebarLayouts, allowSingleColumnLayout, api) {
67
- var _api$decorations$acti, _api$decorations, _api$analytics;
68
- var _ref = (_api$decorations$acti = api === null || api === void 0 || (_api$decorations = api.decorations) === null || _api$decorations === void 0 ? void 0 : _api$decorations.actions) !== null && _api$decorations$acti !== void 0 ? _api$decorations$acti : {},
69
- hoverDecoration = _ref.hoverDecoration;
70
- var editorAnalyticsAPI = api === null || api === void 0 || (_api$analytics = api.analytics) === null || _api$analytics === void 0 ? void 0 : _api$analytics.actions;
71
- var node = state.doc.nodeAt(pos);
72
- if (node) {
73
- var currentLayout = (0, _actions.getPresetLayout)(node);
74
- var separator = {
75
- type: 'separator'
76
- };
77
- var nodeType = state.schema.nodes.layoutSection;
78
- var deleteButton = {
79
- id: 'editor.layout.delete',
80
- type: 'button',
81
- appearance: 'danger',
82
- focusEditoronEnter: true,
83
- icon: _remove.default,
84
- testId: _messages.default.remove.id,
85
- title: intl.formatMessage(_messages.default.remove),
86
- onClick: (0, _actions.deleteActiveLayoutNode)(editorAnalyticsAPI),
87
- onMouseEnter: hoverDecoration === null || hoverDecoration === void 0 ? void 0 : hoverDecoration(nodeType, true),
88
- onMouseLeave: hoverDecoration === null || hoverDecoration === void 0 ? void 0 : hoverDecoration(nodeType, false),
89
- onFocus: hoverDecoration === null || hoverDecoration === void 0 ? void 0 : hoverDecoration(nodeType, true),
90
- onBlur: hoverDecoration === null || hoverDecoration === void 0 ? void 0 : hoverDecoration(nodeType, false),
91
- tabIndex: null
92
- };
93
- var layoutTypes = allowSingleColumnLayout ? LAYOUT_TYPES_WITH_SINGLE_COL : LAYOUT_TYPES;
94
- return {
95
- title: layoutToolbarTitle,
96
- getDomRef: function getDomRef(view) {
97
- return (0, _utils.findDomRefAtPos)(pos, view.domAtPos.bind(view));
98
- },
99
- nodeType: nodeType,
100
- items: [].concat((0, _toConsumableArray2.default)(layoutTypes.map(function (i) {
101
- return buildLayoutButton(intl, i, currentLayout, editorAnalyticsAPI);
102
- })), (0, _toConsumableArray2.default)(addSidebarLayouts ? SIDEBAR_LAYOUT_TYPES.map(function (i) {
103
- return buildLayoutButton(intl, i, currentLayout, editorAnalyticsAPI);
104
- }) : []), [{
105
- type: 'copy-button',
106
- items: [separator, {
107
- state: state,
108
- formatMessage: intl.formatMessage,
109
- nodeType: nodeType
110
- }]
111
- }, separator, deleteButton]),
112
- scrollable: true
113
- };
114
- }
115
- return;
116
- };
@@ -1,5 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
@@ -1,30 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- Object.defineProperty(exports, "removeLayoutFromFirstChild", {
7
- enumerable: true,
8
- get: function get() {
9
- return _transforms.removeLayoutFromFirstChild;
10
- }
11
- });
12
- Object.defineProperty(exports, "removeLayoutFromLastChild", {
13
- enumerable: true,
14
- get: function get() {
15
- return _transforms.removeLayoutFromLastChild;
16
- }
17
- });
18
- Object.defineProperty(exports, "transformSliceToRemoveOpenLayoutNodes", {
19
- enumerable: true,
20
- get: function get() {
21
- return _transforms.transformSliceToRemoveOpenLayoutNodes;
22
- }
23
- });
24
- Object.defineProperty(exports, "unwrapContentFromLayout", {
25
- enumerable: true,
26
- get: function get() {
27
- return _transforms.unwrapContentFromLayout;
28
- }
29
- });
30
- var _transforms = require("@atlaskit/editor-common/transforms");
@@ -1,329 +0,0 @@
1
- import { safeInsert } from '@atlaskit/editor-prosemirror/utils';
2
- import { Fragment, Slice } from '@atlaskit/editor-prosemirror/model';
3
- import { TextSelection, NodeSelection } from '@atlaskit/editor-prosemirror/state';
4
- import { flatmap, mapChildren } from '../../utils/slice';
5
- import { getStepRange, isEmptyDocument } from '@atlaskit/editor-common/utils';
6
- import { ACTION, ACTION_SUBJECT, ACTION_SUBJECT_ID, EVENT_TYPE, LAYOUT_TYPE } from '@atlaskit/editor-common/analytics';
7
- import { withAnalytics } from '@atlaskit/editor-common/editor-analytics';
8
- import { pluginKey } from './pm-plugins/plugin-key';
9
- export const ONE_COL_LAYOUTS = ['single'];
10
- export const TWO_COL_LAYOUTS = ['two_equal', 'two_left_sidebar', 'two_right_sidebar'];
11
- export const THREE_COL_LAYOUTS = ['three_equal', 'three_with_sidebars'];
12
- const getWidthsForPreset = presetLayout => {
13
- switch (presetLayout) {
14
- case 'single':
15
- return [100];
16
- case 'two_equal':
17
- return [50, 50];
18
- case 'three_equal':
19
- return [33.33, 33.33, 33.33];
20
- case 'two_left_sidebar':
21
- return [33.33, 66.66];
22
- case 'two_right_sidebar':
23
- return [66.66, 33.33];
24
- case 'three_with_sidebars':
25
- return [25, 50, 25];
26
- }
27
- };
28
-
29
- /**
30
- * Finds layout preset based on the width attrs of all the layoutColumn nodes
31
- * inside the layoutSection node
32
- */
33
- export const getPresetLayout = section => {
34
- const widths = mapChildren(section, column => column.attrs.width).join(',');
35
- switch (widths) {
36
- case '100':
37
- return 'single';
38
- case '33.33,33.33,33.33':
39
- return 'three_equal';
40
- case '25,50,25':
41
- return 'three_with_sidebars';
42
- case '50,50':
43
- return 'two_equal';
44
- case '33.33,66.66':
45
- return 'two_left_sidebar';
46
- case '66.66,33.33':
47
- return 'two_right_sidebar';
48
- }
49
- return;
50
- };
51
- export const getSelectedLayout = (maybeLayoutSection, current) => {
52
- if (maybeLayoutSection && getPresetLayout(maybeLayoutSection)) {
53
- return getPresetLayout(maybeLayoutSection) || current;
54
- }
55
- return current;
56
- };
57
- export const createDefaultLayoutSection = state => {
58
- const {
59
- layoutSection,
60
- layoutColumn
61
- } = state.schema.nodes;
62
-
63
- // create a 50-50 layout by default
64
- const columns = Fragment.fromArray([layoutColumn.createAndFill({
65
- width: 50
66
- }), layoutColumn.createAndFill({
67
- width: 50
68
- })]);
69
- return layoutSection.createAndFill(undefined, columns);
70
- };
71
- export const insertLayoutColumns = (state, dispatch) => {
72
- if (dispatch) {
73
- dispatch(safeInsert(createDefaultLayoutSection(state))(state.tr));
74
- }
75
- return true;
76
- };
77
- export const insertLayoutColumnsWithAnalytics = editorAnalyticsAPI => inputMethod => withAnalytics(editorAnalyticsAPI, {
78
- action: ACTION.INSERTED,
79
- actionSubject: ACTION_SUBJECT.DOCUMENT,
80
- actionSubjectId: ACTION_SUBJECT_ID.LAYOUT,
81
- attributes: {
82
- inputMethod
83
- },
84
- eventType: EVENT_TYPE.TRACK
85
- })(insertLayoutColumns);
86
-
87
- /**
88
- * Add a column to the right of existing layout
89
- */
90
- function addColumn(schema, pos) {
91
- return tr => {
92
- tr.replaceWith(tr.mapping.map(pos), tr.mapping.map(pos), schema.nodes.layoutColumn.createAndFill());
93
- };
94
- }
95
- function removeLastColumnInLayout(column, columnPos, insideRightEdgePos) {
96
- return tr => {
97
- if (isEmptyDocument(column)) {
98
- tr.replaceRange(tr.mapping.map(columnPos - 1), tr.mapping.map(insideRightEdgePos), Slice.empty);
99
- } else {
100
- tr.replaceRange(tr.mapping.map(columnPos - 1), tr.mapping.map(columnPos + 1), Slice.empty);
101
- }
102
- };
103
- }
104
- const fromTwoColsToThree = addColumn;
105
- const fromOneColToTwo = addColumn;
106
- const fromTwoColsToOne = removeLastColumnInLayout;
107
- const fromThreeColsToTwo = removeLastColumnInLayout;
108
- const fromOneColToThree = (schema, pos) => {
109
- return tr => {
110
- addColumn(schema, pos)(tr);
111
- addColumn(schema, pos)(tr);
112
- };
113
- };
114
- const fromThreeColstoOne = (node, tr, insideRightEdgePos) => {
115
- const thirdColumn = node.content.child(2);
116
- fromThreeColsToTwo(thirdColumn, insideRightEdgePos - thirdColumn.nodeSize, insideRightEdgePos)(tr);
117
- const secondColumn = node.content.child(1);
118
- fromTwoColsToOne(secondColumn, insideRightEdgePos - thirdColumn.nodeSize - secondColumn.nodeSize, insideRightEdgePos)(tr);
119
- };
120
-
121
- /**
122
- * Handles switching from 2 -> 3 cols, or 3 -> 2 cols
123
- * Switching from 2 -> 3 just adds a new one at the end
124
- * Switching from 3 -> 2 moves all the content of the third col inside the second before
125
- * removing it
126
- */
127
- function forceColumnStructure(state, node, pos, presetLayout) {
128
- const tr = state.tr;
129
- const insideRightEdgeOfLayoutSection = pos + node.nodeSize - 1;
130
- const numCols = node.childCount;
131
-
132
- // 3 columns -> 2 columns
133
- if (TWO_COL_LAYOUTS.indexOf(presetLayout) >= 0 && numCols === 3) {
134
- const thirdColumn = node.content.child(2);
135
- const columnPos = insideRightEdgeOfLayoutSection - thirdColumn.nodeSize;
136
- fromThreeColsToTwo(thirdColumn, columnPos, insideRightEdgeOfLayoutSection)(tr);
137
-
138
- // 2 columns -> 3 columns
139
- } else if (THREE_COL_LAYOUTS.indexOf(presetLayout) >= 0 && numCols === 2) {
140
- fromTwoColsToThree(state.schema, insideRightEdgeOfLayoutSection)(tr);
141
-
142
- // 2 columns -> 1 column
143
- } else if (ONE_COL_LAYOUTS.indexOf(presetLayout) >= 0 && numCols === 2) {
144
- const secondColumn = node.content.child(1);
145
- const columnPos = insideRightEdgeOfLayoutSection - secondColumn.nodeSize;
146
- fromTwoColsToOne(secondColumn, columnPos, insideRightEdgeOfLayoutSection)(tr);
147
-
148
- // 3 columns -> 1 column
149
- } else if (ONE_COL_LAYOUTS.indexOf(presetLayout) >= 0 && numCols === 3) {
150
- fromThreeColstoOne(node, tr, insideRightEdgeOfLayoutSection);
151
-
152
- // 1 column -> 2 columns
153
- } else if (TWO_COL_LAYOUTS.indexOf(presetLayout) >= 0 && numCols === 1) {
154
- fromOneColToTwo(state.schema, insideRightEdgeOfLayoutSection)(tr);
155
- // 1 column -> 3 columns
156
- } else if (THREE_COL_LAYOUTS.indexOf(presetLayout) >= 0 && numCols === 1) {
157
- fromOneColToThree(state.schema, insideRightEdgeOfLayoutSection)(tr);
158
- }
159
- return tr;
160
- }
161
- function columnWidth(node, schema, widths) {
162
- const {
163
- layoutColumn
164
- } = schema.nodes;
165
- const truncatedWidths = widths.map(w => Number(w.toFixed(2)));
166
- return flatmap(node.content, (column, idx) => {
167
- if (column.type === layoutColumn) {
168
- return layoutColumn.create({
169
- ...column.attrs,
170
- width: truncatedWidths[idx]
171
- }, column.content, column.marks);
172
- } else {
173
- return column;
174
- }
175
- });
176
- }
177
- function forceColumnWidths(state, tr, pos, presetLayout) {
178
- const node = tr.doc.nodeAt(pos);
179
- if (!node) {
180
- return tr;
181
- }
182
- return tr.replaceWith(pos + 1, pos + node.nodeSize - 1, columnWidth(node, state.schema, getWidthsForPreset(presetLayout)));
183
- }
184
- export function forceSectionToPresetLayout(state, node, pos, presetLayout) {
185
- let tr = forceColumnStructure(state, node, pos, presetLayout);
186
-
187
- // save the selection here, since forcing column widths causes a change over the
188
- // entire layoutSection, which remaps selection to the end. not remapping here
189
- // is safe because the structure is no longer changing.
190
- const selection = tr.selection;
191
- tr = forceColumnWidths(state, tr, pos, presetLayout);
192
- const selectionPos$ = tr.doc.resolve(selection.$from.pos);
193
- return tr.setSelection(state.selection instanceof NodeSelection ? new NodeSelection(selectionPos$) : new TextSelection(selectionPos$));
194
- }
195
- export const setPresetLayout = editorAnalyticsAPI => layout => (state, dispatch) => {
196
- const {
197
- pos,
198
- selectedLayout
199
- } = pluginKey.getState(state);
200
- if (selectedLayout === layout || pos === null) {
201
- return false;
202
- }
203
- const node = state.doc.nodeAt(pos);
204
- if (!node) {
205
- return false;
206
- }
207
- let tr = forceSectionToPresetLayout(state, node, pos, layout);
208
- if (tr) {
209
- editorAnalyticsAPI === null || editorAnalyticsAPI === void 0 ? void 0 : editorAnalyticsAPI.attachAnalyticsEvent({
210
- action: ACTION.CHANGED_LAYOUT,
211
- actionSubject: ACTION_SUBJECT.LAYOUT,
212
- attributes: {
213
- previousLayout: formatLayoutName(selectedLayout),
214
- newLayout: formatLayoutName(layout)
215
- },
216
- eventType: EVENT_TYPE.TRACK
217
- })(tr);
218
- tr.setMeta('scrollIntoView', false);
219
- if (dispatch) {
220
- dispatch(tr);
221
- }
222
- return true;
223
- }
224
- return false;
225
- };
226
- function layoutNeedChanges(node) {
227
- return !getPresetLayout(node);
228
- }
229
- function getLayoutChange(node, pos, schema) {
230
- if (node.type === schema.nodes.layoutSection) {
231
- if (!layoutNeedChanges(node)) {
232
- return;
233
- }
234
- const presetLayout = node.childCount === 2 ? 'two_equal' : node.childCount === 3 ? 'three_equal' : 'single';
235
- const fixedColumns = columnWidth(node, schema, getWidthsForPreset(presetLayout));
236
- return {
237
- from: pos + 1,
238
- to: pos + node.nodeSize - 1,
239
- slice: new Slice(fixedColumns, 0, 0)
240
- };
241
- }
242
- }
243
- export const fixColumnSizes = (changedTr, state) => {
244
- const {
245
- layoutSection
246
- } = state.schema.nodes;
247
- let change;
248
- const range = getStepRange(changedTr);
249
- if (!range) {
250
- return undefined;
251
- }
252
- changedTr.doc.nodesBetween(range.from, range.to, (node, pos) => {
253
- if (node.type !== layoutSection) {
254
- return true; // Check all internal nodes expect for layout section
255
- }
256
- // Node is a section
257
- if (layoutNeedChanges(node)) {
258
- change = getLayoutChange(node, pos, state.schema);
259
- }
260
- return false; // We dont go deep, We dont accept nested layouts
261
- });
262
-
263
- // Hack to prevent: https://product-fabric.atlassian.net/browse/ED-7523
264
- // By default prosemirror try to recreate the node with the default attributes
265
- // The default attribute is invalid adf though. when this happen the node after
266
- // current position is a layout section
267
- const $pos = changedTr.doc.resolve(range.to);
268
- if ($pos.depth > 0) {
269
- // 'range.to' position could resolve to doc, in this ResolvedPos.after will throws
270
- const pos = $pos.after();
271
- const node = changedTr.doc.nodeAt(pos);
272
- if (node && node.type === layoutSection && layoutNeedChanges(node)) {
273
- change = getLayoutChange(node, pos, state.schema);
274
- }
275
- }
276
- return change;
277
- };
278
- export const fixColumnStructure = state => {
279
- const {
280
- pos,
281
- selectedLayout
282
- } = pluginKey.getState(state);
283
- if (pos !== null && selectedLayout) {
284
- const node = state.doc.nodeAt(pos);
285
- if (node && node.childCount !== getWidthsForPreset(selectedLayout).length) {
286
- return forceSectionToPresetLayout(state, node, pos, selectedLayout);
287
- }
288
- }
289
- return;
290
- };
291
- export const deleteActiveLayoutNode = editorAnalyticsAPI => (state, dispatch) => {
292
- const {
293
- pos,
294
- selectedLayout
295
- } = pluginKey.getState(state);
296
- if (pos !== null) {
297
- const node = state.doc.nodeAt(pos);
298
- if (dispatch) {
299
- let tr = state.tr.delete(pos, pos + node.nodeSize);
300
- editorAnalyticsAPI === null || editorAnalyticsAPI === void 0 ? void 0 : editorAnalyticsAPI.attachAnalyticsEvent({
301
- action: ACTION.DELETED,
302
- actionSubject: ACTION_SUBJECT.LAYOUT,
303
- attributes: {
304
- layout: formatLayoutName(selectedLayout)
305
- },
306
- eventType: EVENT_TYPE.TRACK
307
- })(tr);
308
- dispatch(tr);
309
- }
310
- return true;
311
- }
312
- return false;
313
- };
314
- const formatLayoutName = layout => {
315
- switch (layout) {
316
- case 'single':
317
- return LAYOUT_TYPE.SINGLE_COL;
318
- case 'two_equal':
319
- return LAYOUT_TYPE.TWO_COLS_EQUAL;
320
- case 'three_equal':
321
- return LAYOUT_TYPE.THREE_COLS_EQUAL;
322
- case 'two_left_sidebar':
323
- return LAYOUT_TYPE.LEFT_SIDEBAR;
324
- case 'two_right_sidebar':
325
- return LAYOUT_TYPE.RIGHT_SIDEBAR;
326
- case 'three_with_sidebars':
327
- return LAYOUT_TYPE.THREE_WITH_SIDEBARS;
328
- }
329
- };
@@ -1,76 +0,0 @@
1
- import React from 'react';
2
- import { layoutColumn, layoutSection } from '@atlaskit/adf-schema';
3
- import { default as createLayoutPlugin } from './pm-plugins/main';
4
- import { buildToolbar } from './toolbar';
5
- import { createDefaultLayoutSection, insertLayoutColumnsWithAnalytics } from './actions';
6
- import { IconLayout } from '@atlaskit/editor-common/quick-insert';
7
- import { ACTION, ACTION_SUBJECT, ACTION_SUBJECT_ID, EVENT_TYPE, INPUT_METHOD } from '@atlaskit/editor-common/analytics';
8
- import { messages } from '../insert-block/ui/ToolbarInsertBlock/messages';
9
- import { pluginKey } from './pm-plugins/plugin-key';
10
- export { pluginKey };
11
- const layoutPlugin = ({
12
- config: options = {},
13
- api
14
- }) => {
15
- var _api$analytics;
16
- return {
17
- name: 'layout',
18
- nodes() {
19
- return [{
20
- name: 'layoutSection',
21
- node: layoutSection
22
- }, {
23
- name: 'layoutColumn',
24
- node: layoutColumn
25
- }];
26
- },
27
- pmPlugins() {
28
- return [{
29
- name: 'layout',
30
- plugin: () => createLayoutPlugin(options)
31
- }];
32
- },
33
- actions: {
34
- insertLayoutColumns: insertLayoutColumnsWithAnalytics(api === null || api === void 0 ? void 0 : (_api$analytics = api.analytics) === null || _api$analytics === void 0 ? void 0 : _api$analytics.actions)
35
- },
36
- pluginsOptions: {
37
- floatingToolbar(state, intl) {
38
- const {
39
- pos,
40
- allowBreakout,
41
- addSidebarLayouts,
42
- allowSingleColumnLayout
43
- } = pluginKey.getState(state);
44
- if (pos !== null) {
45
- return buildToolbar(state, intl, pos, allowBreakout, addSidebarLayouts, allowSingleColumnLayout, api);
46
- }
47
- return undefined;
48
- },
49
- quickInsert: ({
50
- formatMessage
51
- }) => [{
52
- id: 'layout',
53
- title: formatMessage(messages.columns),
54
- description: formatMessage(messages.columnsDescription),
55
- keywords: ['column', 'section'],
56
- priority: 1100,
57
- icon: () => /*#__PURE__*/React.createElement(IconLayout, null),
58
- action(insert, state) {
59
- var _api$analytics2, _api$analytics2$actio;
60
- const tr = insert(createDefaultLayoutSection(state));
61
- api === null || api === void 0 ? void 0 : (_api$analytics2 = api.analytics) === null || _api$analytics2 === void 0 ? void 0 : (_api$analytics2$actio = _api$analytics2.actions) === null || _api$analytics2$actio === void 0 ? void 0 : _api$analytics2$actio.attachAnalyticsEvent({
62
- action: ACTION.INSERTED,
63
- actionSubject: ACTION_SUBJECT.DOCUMENT,
64
- actionSubjectId: ACTION_SUBJECT_ID.LAYOUT,
65
- attributes: {
66
- inputMethod: INPUT_METHOD.QUICK_INSERT
67
- },
68
- eventType: EVENT_TYPE.TRACK
69
- })(tr);
70
- return tr;
71
- }
72
- }]
73
- }
74
- };
75
- };
76
- export default layoutPlugin;