@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,346 +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.fixColumnStructure = exports.fixColumnSizes = exports.deleteActiveLayoutNode = exports.createDefaultLayoutSection = exports.TWO_COL_LAYOUTS = exports.THREE_COL_LAYOUTS = exports.ONE_COL_LAYOUTS = void 0;
8
- exports.forceSectionToPresetLayout = forceSectionToPresetLayout;
9
- exports.setPresetLayout = exports.insertLayoutColumnsWithAnalytics = exports.insertLayoutColumns = exports.getSelectedLayout = exports.getPresetLayout = void 0;
10
- var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
11
- var _utils = require("@atlaskit/editor-prosemirror/utils");
12
- var _model = require("@atlaskit/editor-prosemirror/model");
13
- var _state = require("@atlaskit/editor-prosemirror/state");
14
- var _slice = require("../../utils/slice");
15
- var _utils2 = require("@atlaskit/editor-common/utils");
16
- var _analytics = require("@atlaskit/editor-common/analytics");
17
- var _editorAnalytics = require("@atlaskit/editor-common/editor-analytics");
18
- var _pluginKey = require("./pm-plugins/plugin-key");
19
- function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
20
- function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { (0, _defineProperty2.default)(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
21
- var ONE_COL_LAYOUTS = exports.ONE_COL_LAYOUTS = ['single'];
22
- var TWO_COL_LAYOUTS = exports.TWO_COL_LAYOUTS = ['two_equal', 'two_left_sidebar', 'two_right_sidebar'];
23
- var THREE_COL_LAYOUTS = exports.THREE_COL_LAYOUTS = ['three_equal', 'three_with_sidebars'];
24
- var getWidthsForPreset = function getWidthsForPreset(presetLayout) {
25
- switch (presetLayout) {
26
- case 'single':
27
- return [100];
28
- case 'two_equal':
29
- return [50, 50];
30
- case 'three_equal':
31
- return [33.33, 33.33, 33.33];
32
- case 'two_left_sidebar':
33
- return [33.33, 66.66];
34
- case 'two_right_sidebar':
35
- return [66.66, 33.33];
36
- case 'three_with_sidebars':
37
- return [25, 50, 25];
38
- }
39
- };
40
-
41
- /**
42
- * Finds layout preset based on the width attrs of all the layoutColumn nodes
43
- * inside the layoutSection node
44
- */
45
- var getPresetLayout = exports.getPresetLayout = function getPresetLayout(section) {
46
- var widths = (0, _slice.mapChildren)(section, function (column) {
47
- return column.attrs.width;
48
- }).join(',');
49
- switch (widths) {
50
- case '100':
51
- return 'single';
52
- case '33.33,33.33,33.33':
53
- return 'three_equal';
54
- case '25,50,25':
55
- return 'three_with_sidebars';
56
- case '50,50':
57
- return 'two_equal';
58
- case '33.33,66.66':
59
- return 'two_left_sidebar';
60
- case '66.66,33.33':
61
- return 'two_right_sidebar';
62
- }
63
- return;
64
- };
65
- var getSelectedLayout = exports.getSelectedLayout = function getSelectedLayout(maybeLayoutSection, current) {
66
- if (maybeLayoutSection && getPresetLayout(maybeLayoutSection)) {
67
- return getPresetLayout(maybeLayoutSection) || current;
68
- }
69
- return current;
70
- };
71
- var createDefaultLayoutSection = exports.createDefaultLayoutSection = function createDefaultLayoutSection(state) {
72
- var _state$schema$nodes = state.schema.nodes,
73
- layoutSection = _state$schema$nodes.layoutSection,
74
- layoutColumn = _state$schema$nodes.layoutColumn;
75
-
76
- // create a 50-50 layout by default
77
- var columns = _model.Fragment.fromArray([layoutColumn.createAndFill({
78
- width: 50
79
- }), layoutColumn.createAndFill({
80
- width: 50
81
- })]);
82
- return layoutSection.createAndFill(undefined, columns);
83
- };
84
- var insertLayoutColumns = exports.insertLayoutColumns = function insertLayoutColumns(state, dispatch) {
85
- if (dispatch) {
86
- dispatch((0, _utils.safeInsert)(createDefaultLayoutSection(state))(state.tr));
87
- }
88
- return true;
89
- };
90
- var insertLayoutColumnsWithAnalytics = exports.insertLayoutColumnsWithAnalytics = function insertLayoutColumnsWithAnalytics(editorAnalyticsAPI) {
91
- return function (inputMethod) {
92
- return (0, _editorAnalytics.withAnalytics)(editorAnalyticsAPI, {
93
- action: _analytics.ACTION.INSERTED,
94
- actionSubject: _analytics.ACTION_SUBJECT.DOCUMENT,
95
- actionSubjectId: _analytics.ACTION_SUBJECT_ID.LAYOUT,
96
- attributes: {
97
- inputMethod: inputMethod
98
- },
99
- eventType: _analytics.EVENT_TYPE.TRACK
100
- })(insertLayoutColumns);
101
- };
102
- };
103
-
104
- /**
105
- * Add a column to the right of existing layout
106
- */
107
- function addColumn(schema, pos) {
108
- return function (tr) {
109
- tr.replaceWith(tr.mapping.map(pos), tr.mapping.map(pos), schema.nodes.layoutColumn.createAndFill());
110
- };
111
- }
112
- function removeLastColumnInLayout(column, columnPos, insideRightEdgePos) {
113
- return function (tr) {
114
- if ((0, _utils2.isEmptyDocument)(column)) {
115
- tr.replaceRange(tr.mapping.map(columnPos - 1), tr.mapping.map(insideRightEdgePos), _model.Slice.empty);
116
- } else {
117
- tr.replaceRange(tr.mapping.map(columnPos - 1), tr.mapping.map(columnPos + 1), _model.Slice.empty);
118
- }
119
- };
120
- }
121
- var fromTwoColsToThree = addColumn;
122
- var fromOneColToTwo = addColumn;
123
- var fromTwoColsToOne = removeLastColumnInLayout;
124
- var fromThreeColsToTwo = removeLastColumnInLayout;
125
- var fromOneColToThree = function fromOneColToThree(schema, pos) {
126
- return function (tr) {
127
- addColumn(schema, pos)(tr);
128
- addColumn(schema, pos)(tr);
129
- };
130
- };
131
- var fromThreeColstoOne = function fromThreeColstoOne(node, tr, insideRightEdgePos) {
132
- var thirdColumn = node.content.child(2);
133
- fromThreeColsToTwo(thirdColumn, insideRightEdgePos - thirdColumn.nodeSize, insideRightEdgePos)(tr);
134
- var secondColumn = node.content.child(1);
135
- fromTwoColsToOne(secondColumn, insideRightEdgePos - thirdColumn.nodeSize - secondColumn.nodeSize, insideRightEdgePos)(tr);
136
- };
137
-
138
- /**
139
- * Handles switching from 2 -> 3 cols, or 3 -> 2 cols
140
- * Switching from 2 -> 3 just adds a new one at the end
141
- * Switching from 3 -> 2 moves all the content of the third col inside the second before
142
- * removing it
143
- */
144
- function forceColumnStructure(state, node, pos, presetLayout) {
145
- var tr = state.tr;
146
- var insideRightEdgeOfLayoutSection = pos + node.nodeSize - 1;
147
- var numCols = node.childCount;
148
-
149
- // 3 columns -> 2 columns
150
- if (TWO_COL_LAYOUTS.indexOf(presetLayout) >= 0 && numCols === 3) {
151
- var thirdColumn = node.content.child(2);
152
- var columnPos = insideRightEdgeOfLayoutSection - thirdColumn.nodeSize;
153
- fromThreeColsToTwo(thirdColumn, columnPos, insideRightEdgeOfLayoutSection)(tr);
154
-
155
- // 2 columns -> 3 columns
156
- } else if (THREE_COL_LAYOUTS.indexOf(presetLayout) >= 0 && numCols === 2) {
157
- fromTwoColsToThree(state.schema, insideRightEdgeOfLayoutSection)(tr);
158
-
159
- // 2 columns -> 1 column
160
- } else if (ONE_COL_LAYOUTS.indexOf(presetLayout) >= 0 && numCols === 2) {
161
- var secondColumn = node.content.child(1);
162
- var _columnPos = insideRightEdgeOfLayoutSection - secondColumn.nodeSize;
163
- fromTwoColsToOne(secondColumn, _columnPos, insideRightEdgeOfLayoutSection)(tr);
164
-
165
- // 3 columns -> 1 column
166
- } else if (ONE_COL_LAYOUTS.indexOf(presetLayout) >= 0 && numCols === 3) {
167
- fromThreeColstoOne(node, tr, insideRightEdgeOfLayoutSection);
168
-
169
- // 1 column -> 2 columns
170
- } else if (TWO_COL_LAYOUTS.indexOf(presetLayout) >= 0 && numCols === 1) {
171
- fromOneColToTwo(state.schema, insideRightEdgeOfLayoutSection)(tr);
172
- // 1 column -> 3 columns
173
- } else if (THREE_COL_LAYOUTS.indexOf(presetLayout) >= 0 && numCols === 1) {
174
- fromOneColToThree(state.schema, insideRightEdgeOfLayoutSection)(tr);
175
- }
176
- return tr;
177
- }
178
- function columnWidth(node, schema, widths) {
179
- var layoutColumn = schema.nodes.layoutColumn;
180
- var truncatedWidths = widths.map(function (w) {
181
- return Number(w.toFixed(2));
182
- });
183
- return (0, _slice.flatmap)(node.content, function (column, idx) {
184
- if (column.type === layoutColumn) {
185
- return layoutColumn.create(_objectSpread(_objectSpread({}, column.attrs), {}, {
186
- width: truncatedWidths[idx]
187
- }), column.content, column.marks);
188
- } else {
189
- return column;
190
- }
191
- });
192
- }
193
- function forceColumnWidths(state, tr, pos, presetLayout) {
194
- var node = tr.doc.nodeAt(pos);
195
- if (!node) {
196
- return tr;
197
- }
198
- return tr.replaceWith(pos + 1, pos + node.nodeSize - 1, columnWidth(node, state.schema, getWidthsForPreset(presetLayout)));
199
- }
200
- function forceSectionToPresetLayout(state, node, pos, presetLayout) {
201
- var tr = forceColumnStructure(state, node, pos, presetLayout);
202
-
203
- // save the selection here, since forcing column widths causes a change over the
204
- // entire layoutSection, which remaps selection to the end. not remapping here
205
- // is safe because the structure is no longer changing.
206
- var selection = tr.selection;
207
- tr = forceColumnWidths(state, tr, pos, presetLayout);
208
- var selectionPos$ = tr.doc.resolve(selection.$from.pos);
209
- return tr.setSelection(state.selection instanceof _state.NodeSelection ? new _state.NodeSelection(selectionPos$) : new _state.TextSelection(selectionPos$));
210
- }
211
- var setPresetLayout = exports.setPresetLayout = function setPresetLayout(editorAnalyticsAPI) {
212
- return function (layout) {
213
- return function (state, dispatch) {
214
- var _ref = _pluginKey.pluginKey.getState(state),
215
- pos = _ref.pos,
216
- selectedLayout = _ref.selectedLayout;
217
- if (selectedLayout === layout || pos === null) {
218
- return false;
219
- }
220
- var node = state.doc.nodeAt(pos);
221
- if (!node) {
222
- return false;
223
- }
224
- var tr = forceSectionToPresetLayout(state, node, pos, layout);
225
- if (tr) {
226
- editorAnalyticsAPI === null || editorAnalyticsAPI === void 0 || editorAnalyticsAPI.attachAnalyticsEvent({
227
- action: _analytics.ACTION.CHANGED_LAYOUT,
228
- actionSubject: _analytics.ACTION_SUBJECT.LAYOUT,
229
- attributes: {
230
- previousLayout: formatLayoutName(selectedLayout),
231
- newLayout: formatLayoutName(layout)
232
- },
233
- eventType: _analytics.EVENT_TYPE.TRACK
234
- })(tr);
235
- tr.setMeta('scrollIntoView', false);
236
- if (dispatch) {
237
- dispatch(tr);
238
- }
239
- return true;
240
- }
241
- return false;
242
- };
243
- };
244
- };
245
- function layoutNeedChanges(node) {
246
- return !getPresetLayout(node);
247
- }
248
- function getLayoutChange(node, pos, schema) {
249
- if (node.type === schema.nodes.layoutSection) {
250
- if (!layoutNeedChanges(node)) {
251
- return;
252
- }
253
- var presetLayout = node.childCount === 2 ? 'two_equal' : node.childCount === 3 ? 'three_equal' : 'single';
254
- var fixedColumns = columnWidth(node, schema, getWidthsForPreset(presetLayout));
255
- return {
256
- from: pos + 1,
257
- to: pos + node.nodeSize - 1,
258
- slice: new _model.Slice(fixedColumns, 0, 0)
259
- };
260
- }
261
- }
262
- var fixColumnSizes = exports.fixColumnSizes = function fixColumnSizes(changedTr, state) {
263
- var layoutSection = state.schema.nodes.layoutSection;
264
- var change;
265
- var range = (0, _utils2.getStepRange)(changedTr);
266
- if (!range) {
267
- return undefined;
268
- }
269
- changedTr.doc.nodesBetween(range.from, range.to, function (node, pos) {
270
- if (node.type !== layoutSection) {
271
- return true; // Check all internal nodes expect for layout section
272
- }
273
- // Node is a section
274
- if (layoutNeedChanges(node)) {
275
- change = getLayoutChange(node, pos, state.schema);
276
- }
277
- return false; // We dont go deep, We dont accept nested layouts
278
- });
279
-
280
- // Hack to prevent: https://product-fabric.atlassian.net/browse/ED-7523
281
- // By default prosemirror try to recreate the node with the default attributes
282
- // The default attribute is invalid adf though. when this happen the node after
283
- // current position is a layout section
284
- var $pos = changedTr.doc.resolve(range.to);
285
- if ($pos.depth > 0) {
286
- // 'range.to' position could resolve to doc, in this ResolvedPos.after will throws
287
- var pos = $pos.after();
288
- var node = changedTr.doc.nodeAt(pos);
289
- if (node && node.type === layoutSection && layoutNeedChanges(node)) {
290
- change = getLayoutChange(node, pos, state.schema);
291
- }
292
- }
293
- return change;
294
- };
295
- var fixColumnStructure = exports.fixColumnStructure = function fixColumnStructure(state) {
296
- var _ref2 = _pluginKey.pluginKey.getState(state),
297
- pos = _ref2.pos,
298
- selectedLayout = _ref2.selectedLayout;
299
- if (pos !== null && selectedLayout) {
300
- var node = state.doc.nodeAt(pos);
301
- if (node && node.childCount !== getWidthsForPreset(selectedLayout).length) {
302
- return forceSectionToPresetLayout(state, node, pos, selectedLayout);
303
- }
304
- }
305
- return;
306
- };
307
- var deleteActiveLayoutNode = exports.deleteActiveLayoutNode = function deleteActiveLayoutNode(editorAnalyticsAPI) {
308
- return function (state, dispatch) {
309
- var _ref3 = _pluginKey.pluginKey.getState(state),
310
- pos = _ref3.pos,
311
- selectedLayout = _ref3.selectedLayout;
312
- if (pos !== null) {
313
- var node = state.doc.nodeAt(pos);
314
- if (dispatch) {
315
- var tr = state.tr.delete(pos, pos + node.nodeSize);
316
- editorAnalyticsAPI === null || editorAnalyticsAPI === void 0 || editorAnalyticsAPI.attachAnalyticsEvent({
317
- action: _analytics.ACTION.DELETED,
318
- actionSubject: _analytics.ACTION_SUBJECT.LAYOUT,
319
- attributes: {
320
- layout: formatLayoutName(selectedLayout)
321
- },
322
- eventType: _analytics.EVENT_TYPE.TRACK
323
- })(tr);
324
- dispatch(tr);
325
- }
326
- return true;
327
- }
328
- return false;
329
- };
330
- };
331
- var formatLayoutName = function formatLayoutName(layout) {
332
- switch (layout) {
333
- case 'single':
334
- return _analytics.LAYOUT_TYPE.SINGLE_COL;
335
- case 'two_equal':
336
- return _analytics.LAYOUT_TYPE.TWO_COLS_EQUAL;
337
- case 'three_equal':
338
- return _analytics.LAYOUT_TYPE.THREE_COLS_EQUAL;
339
- case 'two_left_sidebar':
340
- return _analytics.LAYOUT_TYPE.LEFT_SIDEBAR;
341
- case 'two_right_sidebar':
342
- return _analytics.LAYOUT_TYPE.RIGHT_SIDEBAR;
343
- case 'three_with_sidebars':
344
- return _analytics.LAYOUT_TYPE.THREE_WITH_SIDEBARS;
345
- }
346
- };
@@ -1,92 +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.default = void 0;
8
- Object.defineProperty(exports, "pluginKey", {
9
- enumerable: true,
10
- get: function get() {
11
- return _pluginKey.pluginKey;
12
- }
13
- });
14
- var _react = _interopRequireDefault(require("react"));
15
- var _adfSchema = require("@atlaskit/adf-schema");
16
- var _main = _interopRequireDefault(require("./pm-plugins/main"));
17
- var _toolbar = require("./toolbar");
18
- var _actions = require("./actions");
19
- var _quickInsert = require("@atlaskit/editor-common/quick-insert");
20
- var _analytics = require("@atlaskit/editor-common/analytics");
21
- var _messages = require("../insert-block/ui/ToolbarInsertBlock/messages");
22
- var _pluginKey = require("./pm-plugins/plugin-key");
23
- var layoutPlugin = function layoutPlugin(_ref) {
24
- var _api$analytics;
25
- var _ref$config = _ref.config,
26
- options = _ref$config === void 0 ? {} : _ref$config,
27
- api = _ref.api;
28
- return {
29
- name: 'layout',
30
- nodes: function nodes() {
31
- return [{
32
- name: 'layoutSection',
33
- node: _adfSchema.layoutSection
34
- }, {
35
- name: 'layoutColumn',
36
- node: _adfSchema.layoutColumn
37
- }];
38
- },
39
- pmPlugins: function pmPlugins() {
40
- return [{
41
- name: 'layout',
42
- plugin: function plugin() {
43
- return (0, _main.default)(options);
44
- }
45
- }];
46
- },
47
- actions: {
48
- insertLayoutColumns: (0, _actions.insertLayoutColumnsWithAnalytics)(api === null || api === void 0 || (_api$analytics = api.analytics) === null || _api$analytics === void 0 ? void 0 : _api$analytics.actions)
49
- },
50
- pluginsOptions: {
51
- floatingToolbar: function floatingToolbar(state, intl) {
52
- var _ref2 = _pluginKey.pluginKey.getState(state),
53
- pos = _ref2.pos,
54
- allowBreakout = _ref2.allowBreakout,
55
- addSidebarLayouts = _ref2.addSidebarLayouts,
56
- allowSingleColumnLayout = _ref2.allowSingleColumnLayout;
57
- if (pos !== null) {
58
- return (0, _toolbar.buildToolbar)(state, intl, pos, allowBreakout, addSidebarLayouts, allowSingleColumnLayout, api);
59
- }
60
- return undefined;
61
- },
62
- quickInsert: function quickInsert(_ref3) {
63
- var formatMessage = _ref3.formatMessage;
64
- return [{
65
- id: 'layout',
66
- title: formatMessage(_messages.messages.columns),
67
- description: formatMessage(_messages.messages.columnsDescription),
68
- keywords: ['column', 'section'],
69
- priority: 1100,
70
- icon: function icon() {
71
- return /*#__PURE__*/_react.default.createElement(_quickInsert.IconLayout, null);
72
- },
73
- action: function action(insert, state) {
74
- var _api$analytics2;
75
- var tr = insert((0, _actions.createDefaultLayoutSection)(state));
76
- api === null || api === void 0 || (_api$analytics2 = api.analytics) === null || _api$analytics2 === void 0 || (_api$analytics2 = _api$analytics2.actions) === null || _api$analytics2 === void 0 || _api$analytics2.attachAnalyticsEvent({
77
- action: _analytics.ACTION.INSERTED,
78
- actionSubject: _analytics.ACTION_SUBJECT.DOCUMENT,
79
- actionSubjectId: _analytics.ACTION_SUBJECT_ID.LAYOUT,
80
- attributes: {
81
- inputMethod: _analytics.INPUT_METHOD.QUICK_INSERT
82
- },
83
- eventType: _analytics.EVENT_TYPE.TRACK
84
- })(tr);
85
- return tr;
86
- }
87
- }];
88
- }
89
- }
90
- };
91
- };
92
- var _default = exports.default = layoutPlugin;
@@ -1,148 +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.default = exports.DEFAULT_LAYOUT = void 0;
8
- var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
9
- var _safePlugin = require("@atlaskit/editor-common/safe-plugin");
10
- var _state = require("@atlaskit/editor-prosemirror/state");
11
- var _view = require("@atlaskit/editor-prosemirror/view");
12
- var _keymap = require("@atlaskit/editor-prosemirror/keymap");
13
- var _utils = require("@atlaskit/editor-prosemirror/utils");
14
- var _utils2 = require("@atlaskit/editor-common/utils");
15
- var _selection = require("@atlaskit/editor-common/selection");
16
- var _actions = require("../actions");
17
- var _pluginKey = require("./plugin-key");
18
- function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
19
- function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { (0, _defineProperty2.default)(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
20
- var DEFAULT_LAYOUT = exports.DEFAULT_LAYOUT = 'two_equal';
21
- var isWholeSelectionInsideLayoutColumn = function isWholeSelectionInsideLayoutColumn(state) {
22
- // Since findParentNodeOfType doesn't check if selection.to shares the parent, we do this check ourselves
23
- var fromParent = (0, _utils.findParentNodeOfType)(state.schema.nodes.layoutColumn)(state.selection);
24
- if (fromParent) {
25
- var isToPosInsideSameLayoutColumn = state.selection.from < fromParent.pos + fromParent.node.nodeSize;
26
- return isToPosInsideSameLayoutColumn;
27
- }
28
- return false;
29
- };
30
- var moveCursorToNextColumn = function moveCursorToNextColumn(state, dispatch) {
31
- var selection = state.selection;
32
- var _state$schema$nodes = state.schema.nodes,
33
- layoutColumn = _state$schema$nodes.layoutColumn,
34
- layoutSection = _state$schema$nodes.layoutSection;
35
- var section = (0, _utils.findParentNodeOfType)(layoutSection)(selection);
36
- var column = (0, _utils.findParentNodeOfType)(layoutColumn)(selection);
37
- if (column.node !== section.node.lastChild) {
38
- var $nextColumn = state.doc.resolve(column.pos + column.node.nodeSize);
39
- var shiftedSelection = _state.TextSelection.findFrom($nextColumn, 1);
40
- if (dispatch) {
41
- dispatch(state.tr.setSelection(shiftedSelection));
42
- }
43
- }
44
- return true;
45
- };
46
-
47
- // TODO: Look at memoize-one-ing this fn
48
- var getNodeDecoration = function getNodeDecoration(pos, node) {
49
- return [_view.Decoration.node(pos, pos + node.nodeSize, {
50
- class: 'selected'
51
- })];
52
- };
53
- var getInitialPluginState = function getInitialPluginState(options, state) {
54
- var maybeLayoutSection = (0, _utils.findParentNodeOfType)(state.schema.nodes.layoutSection)(state.selection);
55
- var allowBreakout = options.allowBreakout || false;
56
- var addSidebarLayouts = options.UNSAFE_addSidebarLayouts || false;
57
- var allowSingleColumnLayout = options.UNSAFE_allowSingleColumnLayout || false;
58
- var pos = maybeLayoutSection ? maybeLayoutSection.pos : null;
59
- var selectedLayout = (0, _actions.getSelectedLayout)(maybeLayoutSection && maybeLayoutSection.node, DEFAULT_LAYOUT);
60
- return {
61
- pos: pos,
62
- allowBreakout: allowBreakout,
63
- addSidebarLayouts: addSidebarLayouts,
64
- selectedLayout: selectedLayout,
65
- allowSingleColumnLayout: allowSingleColumnLayout
66
- };
67
- };
68
- var _default = exports.default = function _default(options) {
69
- return new _safePlugin.SafePlugin({
70
- key: _pluginKey.pluginKey,
71
- state: {
72
- init: function init(_, state) {
73
- return getInitialPluginState(options, state);
74
- },
75
- apply: function apply(tr, pluginState, _oldState, newState) {
76
- if (tr.docChanged || tr.selectionSet) {
77
- var layoutSection = newState.schema.nodes.layoutSection,
78
- selection = newState.selection;
79
- var maybeLayoutSection = (0, _utils.findParentNodeOfType)(layoutSection)(selection) || (0, _utils.findSelectedNodeOfType)([layoutSection])(selection);
80
- var newPluginState = _objectSpread(_objectSpread({}, pluginState), {}, {
81
- pos: maybeLayoutSection ? maybeLayoutSection.pos : null,
82
- selectedLayout: (0, _actions.getSelectedLayout)(maybeLayoutSection && maybeLayoutSection.node, pluginState.selectedLayout)
83
- });
84
- return newPluginState;
85
- }
86
- return pluginState;
87
- }
88
- },
89
- props: {
90
- decorations: function decorations(state) {
91
- var layoutState = _pluginKey.pluginKey.getState(state);
92
- if (layoutState.pos !== null) {
93
- return _view.DecorationSet.create(state.doc, getNodeDecoration(layoutState.pos, state.doc.nodeAt(layoutState.pos)));
94
- }
95
- return undefined;
96
- },
97
- handleKeyDown: (0, _keymap.keydownHandler)({
98
- Tab: (0, _utils2.filterCommand)(isWholeSelectionInsideLayoutColumn, moveCursorToNextColumn)
99
- }),
100
- handleClickOn: (0, _selection.createSelectionClickHandler)(['layoutColumn'], function (target) {
101
- return target.hasAttribute('data-layout-section') || target.hasAttribute('data-layout-column');
102
- }, {
103
- useLongPressSelection: options.useLongPressSelection || false,
104
- getNodeSelectionPos: function getNodeSelectionPos(state, nodePos) {
105
- return state.doc.resolve(nodePos).before();
106
- }
107
- })
108
- },
109
- appendTransaction: function appendTransaction(transactions, _oldState, newState) {
110
- var changes = [];
111
- transactions.forEach(function (prevTr) {
112
- // remap change segments across the transaction set
113
- changes.forEach(function (change) {
114
- return {
115
- from: prevTr.mapping.map(change.from),
116
- to: prevTr.mapping.map(change.to),
117
- slice: change.slice
118
- };
119
- });
120
-
121
- // don't consider transactions that don't mutate
122
- if (!prevTr.docChanged) {
123
- return;
124
- }
125
- var change = (0, _actions.fixColumnSizes)(prevTr, newState);
126
- if (change) {
127
- changes.push(change);
128
- }
129
- });
130
- if (changes.length) {
131
- var tr = newState.tr;
132
- var selection = newState.selection.toJSON();
133
- changes.forEach(function (change) {
134
- tr.replaceRange(change.from, change.to, change.slice);
135
- });
136
-
137
- // selecting and deleting across columns in 3 col layouts can remove
138
- // a layoutColumn so we fix the structure here
139
- tr = (0, _actions.fixColumnStructure)(newState) || tr;
140
- if (tr.docChanged) {
141
- tr.setSelection(_state.Selection.fromJSON(tr.doc, selection));
142
- return tr;
143
- }
144
- }
145
- return;
146
- }
147
- });
148
- };
@@ -1,8 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.pluginKey = void 0;
7
- var _state = require("@atlaskit/editor-prosemirror/state");
8
- var pluginKey = exports.pluginKey = new _state.PluginKey('layout');
@@ -1,5 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
@@ -1,39 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.toolbarMessages = void 0;
7
- var _reactIntlNext = require("react-intl-next");
8
- var toolbarMessages = exports.toolbarMessages = (0, _reactIntlNext.defineMessages)({
9
- singleColumn: {
10
- id: 'fabric.editor.single',
11
- defaultMessage: 'Single column',
12
- description: 'Layout with one single column'
13
- },
14
- twoColumns: {
15
- id: 'fabric.editor.twoColumns',
16
- defaultMessage: 'Two columns',
17
- description: 'Layout with two columns of equal width'
18
- },
19
- threeColumns: {
20
- id: 'fabric.editor.threeColumns',
21
- defaultMessage: 'Three columns',
22
- description: 'Layout with three columns of equal width'
23
- },
24
- rightSidebar: {
25
- id: 'fabric.editor.rightSidebar',
26
- defaultMessage: 'Right sidebar',
27
- description: 'Layout with two columns, left column is 2/3 and right is 1/3 of page'
28
- },
29
- leftSidebar: {
30
- id: 'fabric.editor.leftSidebar',
31
- defaultMessage: 'Left sidebar',
32
- description: 'Layout with two columns, left column is 1/3 and right is 2/3 of page'
33
- },
34
- threeColumnsWithSidebars: {
35
- id: 'fabric.editor.threeColumnsWithSidebars',
36
- defaultMessage: 'Three columns with sidebars',
37
- description: 'Layout with 3 columns laid out as 25% - 50% - 25%'
38
- }
39
- });