@atlaskit/editor-plugin-layout 1.12.7 → 1.12.9

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 (65) hide show
  1. package/CHANGELOG.md +18 -0
  2. package/dist/cjs/index.js +2 -2
  3. package/dist/cjs/{plugin.js → layoutPlugin.js} +7 -7
  4. package/dist/cjs/layoutPluginType.js +12 -0
  5. package/dist/cjs/{actions.js → pm-plugins/actions.js} +23 -45
  6. package/dist/cjs/pm-plugins/main.js +2 -2
  7. package/dist/cjs/pm-plugins/resizing.js +2 -2
  8. package/dist/cjs/ui/global-styles.js +29 -14
  9. package/dist/cjs/{toolbar.js → ui/toolbar.js} +9 -9
  10. package/dist/es2019/index.js +1 -1
  11. package/dist/es2019/{plugin.js → layoutPlugin.js} +7 -7
  12. package/dist/es2019/layoutPluginType.js +2 -0
  13. package/dist/es2019/{actions.js → pm-plugins/actions.js} +23 -46
  14. package/dist/es2019/pm-plugins/main.js +2 -2
  15. package/dist/es2019/pm-plugins/resizing.js +1 -1
  16. package/dist/es2019/ui/global-styles.js +20 -6
  17. package/dist/es2019/{toolbar.js → ui/toolbar.js} +9 -9
  18. package/dist/esm/index.js +1 -1
  19. package/dist/esm/{plugin.js → layoutPlugin.js} +7 -7
  20. package/dist/esm/layoutPluginType.js +2 -0
  21. package/dist/esm/{actions.js → pm-plugins/actions.js} +23 -45
  22. package/dist/esm/pm-plugins/main.js +2 -2
  23. package/dist/esm/pm-plugins/resizing.js +1 -1
  24. package/dist/esm/ui/global-styles.js +27 -12
  25. package/dist/esm/{toolbar.js → ui/toolbar.js} +9 -9
  26. package/dist/types/index.d.ts +2 -2
  27. package/dist/types/layoutPlugin.d.ts +4 -0
  28. package/dist/types/{plugin.d.ts → layoutPluginType.d.ts} +1 -2
  29. package/dist/types/{node-views → nodeviews}/index.d.ts +1 -1
  30. package/dist/types/{actions.d.ts → pm-plugins/actions.d.ts} +6 -7
  31. package/dist/types/pm-plugins/resizing.d.ts +1 -1
  32. package/dist/types/ui/global-styles.d.ts +0 -4
  33. package/dist/types/{toolbar.d.ts → ui/toolbar.d.ts} +1 -1
  34. package/dist/types-ts4.5/index.d.ts +2 -2
  35. package/dist/types-ts4.5/layoutPlugin.d.ts +4 -0
  36. package/dist/types-ts4.5/{plugin.d.ts → layoutPluginType.d.ts} +1 -2
  37. package/dist/types-ts4.5/{node-views → nodeviews}/index.d.ts +1 -1
  38. package/dist/types-ts4.5/{actions.d.ts → pm-plugins/actions.d.ts} +6 -7
  39. package/dist/types-ts4.5/pm-plugins/resizing.d.ts +1 -1
  40. package/dist/types-ts4.5/ui/global-styles.d.ts +0 -4
  41. package/dist/types-ts4.5/{toolbar.d.ts → ui/toolbar.d.ts} +1 -1
  42. package/package.json +8 -5
  43. /package/dist/cjs/{node-views → nodeviews}/index.js +0 -0
  44. /package/dist/cjs/{consts.js → pm-plugins/consts.js} +0 -0
  45. /package/dist/cjs/{utils → pm-plugins/utils}/index.js +0 -0
  46. /package/dist/cjs/{utils → pm-plugins/utils}/preRelease.js +0 -0
  47. /package/dist/cjs/{types.js → types/index.js} +0 -0
  48. /package/dist/es2019/{node-views → nodeviews}/index.js +0 -0
  49. /package/dist/es2019/{consts.js → pm-plugins/consts.js} +0 -0
  50. /package/dist/es2019/{utils → pm-plugins/utils}/index.js +0 -0
  51. /package/dist/es2019/{utils → pm-plugins/utils}/preRelease.js +0 -0
  52. /package/dist/es2019/{types.js → types/index.js} +0 -0
  53. /package/dist/esm/{node-views → nodeviews}/index.js +0 -0
  54. /package/dist/esm/{consts.js → pm-plugins/consts.js} +0 -0
  55. /package/dist/esm/{utils → pm-plugins/utils}/index.js +0 -0
  56. /package/dist/esm/{utils → pm-plugins/utils}/preRelease.js +0 -0
  57. /package/dist/esm/{types.js → types/index.js} +0 -0
  58. /package/dist/types/{consts.d.ts → pm-plugins/consts.d.ts} +0 -0
  59. /package/dist/types/{utils → pm-plugins/utils}/index.d.ts +0 -0
  60. /package/dist/types/{utils → pm-plugins/utils}/preRelease.d.ts +0 -0
  61. /package/dist/types/{types.d.ts → types/index.d.ts} +0 -0
  62. /package/dist/types-ts4.5/{consts.d.ts → pm-plugins/consts.d.ts} +0 -0
  63. /package/dist/types-ts4.5/{utils → pm-plugins/utils}/index.d.ts +0 -0
  64. /package/dist/types-ts4.5/{utils → pm-plugins/utils}/preRelease.d.ts +0 -0
  65. /package/dist/types-ts4.5/{types.d.ts → types/index.d.ts} +0 -0
@@ -1,13 +1,12 @@
1
1
  import { ACTION, ACTION_SUBJECT, ACTION_SUBJECT_ID, EVENT_TYPE, LAYOUT_TYPE } from '@atlaskit/editor-common/analytics';
2
2
  import { withAnalytics } from '@atlaskit/editor-common/editor-analytics';
3
- import { layoutMessages as messages } from '@atlaskit/editor-common/messages';
4
3
  import { flatmap, getStepRange, isEmptyDocument, mapChildren } from '@atlaskit/editor-common/utils';
5
4
  import { Fragment, Slice } from '@atlaskit/editor-prosemirror/model';
6
5
  import { NodeSelection, TextSelection } from '@atlaskit/editor-prosemirror/state';
7
6
  import { safeInsert } from '@atlaskit/editor-prosemirror/utils';
8
7
  import { editorExperiment } from '@atlaskit/tmp-editor-statsig/experiments';
9
8
  import { EVEN_DISTRIBUTED_COL_WIDTHS } from './consts';
10
- import { pluginKey } from './pm-plugins/plugin-key';
9
+ import { pluginKey } from './plugin-key';
11
10
  import { isPreRelease2 } from './utils/preRelease';
12
11
  export const ONE_COL_LAYOUTS = ['single'];
13
12
  export const TWO_COL_LAYOUTS = ['two_equal', 'two_left_sidebar', 'two_right_sidebar'];
@@ -119,47 +118,30 @@ export const getSelectedLayout = (maybeLayoutSection, current) => {
119
118
  }
120
119
  return current;
121
120
  };
122
- const createPlaceholderNode = (schema, formatMessage) => {
123
- if (!formatMessage) {
124
- return undefined;
125
- }
126
- const {
127
- paragraph,
128
- placeholder
129
- } = schema.nodes;
130
- //create a paragraph node with content of placeholder node
131
- const placeholderNode = placeholder.createChecked({
132
- text: formatMessage(messages.layoutPlaceholder)
133
- });
134
- return paragraph.createAndFill(undefined, placeholderNode);
135
- };
136
- export const createMultiColumnLayoutSection = (state, numberOfColumns, formatMessage) => {
121
+ export const createMultiColumnLayoutSection = (state, numberOfColumns = 2) => {
137
122
  const {
138
123
  layoutSection,
139
124
  layoutColumn
140
125
  } = state.schema.nodes;
141
- const placeholder = createPlaceholderNode(state.schema, formatMessage);
142
- const layoutColumnNode = layoutColumn.createAndFill({
143
- width: EVEN_DISTRIBUTED_COL_WIDTHS[numberOfColumns]
144
- }, placeholder);
145
126
  const columns = Fragment.fromArray(Array.from({
146
127
  length: numberOfColumns
147
- }, () => layoutColumnNode));
128
+ }, () => layoutColumn.createAndFill({
129
+ width: EVEN_DISTRIBUTED_COL_WIDTHS[numberOfColumns]
130
+ })));
148
131
  return layoutSection.createAndFill(undefined, columns);
149
132
  };
150
- export const createDefaultLayoutSection = (state, formatMessage) => {
133
+ export const createDefaultLayoutSection = state => {
151
134
  const {
152
135
  layoutSection,
153
136
  layoutColumn
154
137
  } = state.schema.nodes;
155
- const placeholder = isPreRelease2() ? createPlaceholderNode(state.schema, formatMessage) : undefined;
156
138
 
157
139
  // create a 50-50 layout by default
158
140
  const columns = Fragment.fromArray([layoutColumn.createAndFill({
159
141
  width: 50
160
- }, placeholder), layoutColumn.createAndFill({
142
+ }), layoutColumn.createAndFill({
161
143
  width: 50
162
- }, placeholder)]);
144
+ })]);
163
145
  return layoutSection.createAndFill(undefined, columns);
164
146
  };
165
147
  export const insertLayoutColumns = (state, dispatch) => {
@@ -168,7 +150,7 @@ export const insertLayoutColumns = (state, dispatch) => {
168
150
  }
169
151
  return true;
170
152
  };
171
- export const insertLayoutColumnsWithAnalytics = editorAnalyticsAPI => (inputMethod, formatMessage) => withAnalytics(editorAnalyticsAPI, {
153
+ export const insertLayoutColumnsWithAnalytics = editorAnalyticsAPI => inputMethod => withAnalytics(editorAnalyticsAPI, {
172
154
  action: ACTION.INSERTED,
173
155
  actionSubject: ACTION_SUBJECT.DOCUMENT,
174
156
  actionSubjectId: ACTION_SUBJECT_ID.LAYOUT,
@@ -178,7 +160,7 @@ export const insertLayoutColumnsWithAnalytics = editorAnalyticsAPI => (inputMeth
178
160
  eventType: EVENT_TYPE.TRACK
179
161
  })((state, dispatch) => {
180
162
  if (dispatch) {
181
- dispatch(safeInsert(createDefaultLayoutSection(state, formatMessage))(state.tr));
163
+ dispatch(safeInsert(createDefaultLayoutSection(state))(state.tr));
182
164
  }
183
165
  return true;
184
166
  });
@@ -186,26 +168,21 @@ export const insertLayoutColumnsWithAnalytics = editorAnalyticsAPI => (inputMeth
186
168
  /**
187
169
  * Add a column to the right of existing layout
188
170
  */
189
- function addColumn(schema, pos, formatMessage) {
171
+ function addColumn(schema, pos) {
190
172
  if (!isPreRelease2()) {
191
173
  return tr => {
192
174
  tr.replaceWith(tr.mapping.map(pos), tr.mapping.map(pos), schema.nodes.layoutColumn.createAndFill());
193
175
  };
194
176
  }
195
- const placeholder = createPlaceholderNode(schema, formatMessage);
196
177
  return tr => {
197
- tr.replaceWith(tr.mapping.map(pos), tr.mapping.map(pos), schema.nodes.layoutColumn.createAndFill(undefined, placeholder));
178
+ tr.replaceWith(tr.mapping.map(pos), tr.mapping.map(pos), schema.nodes.layoutColumn.createAndFill(undefined));
198
179
  };
199
180
  }
200
- const containPlaceholderOnly = (node, schema) => {
201
- var _node$firstChild, _node$firstChild2, _node$firstChild2$fir;
202
- return node.childCount === 1 && ((_node$firstChild = node.firstChild) === null || _node$firstChild === void 0 ? void 0 : _node$firstChild.childCount) === 1 && ((_node$firstChild2 = node.firstChild) === null || _node$firstChild2 === void 0 ? void 0 : (_node$firstChild2$fir = _node$firstChild2.firstChild) === null || _node$firstChild2$fir === void 0 ? void 0 : _node$firstChild2$fir.type) === schema.nodes.placeholder;
203
- };
204
181
  function removeLastColumnInLayout(column, columnPos, insideRightEdgePos) {
205
182
  return tr => {
206
183
  // check if the column only contains a paragraph with a placeholder text
207
184
  // if so, remove the whole column, otherwise just remove the paragraph
208
- if (isEmptyDocument(column) || containPlaceholderOnly(column, tr.doc.type.schema)) {
185
+ if (isEmptyDocument(column)) {
209
186
  tr.replaceRange(tr.mapping.map(columnPos - 1), tr.mapping.map(insideRightEdgePos), Slice.empty);
210
187
  } else {
211
188
  tr.replaceRange(tr.mapping.map(columnPos - 1), tr.mapping.map(columnPos + 1), Slice.empty);
@@ -228,10 +205,10 @@ const fromThreeColstoOne = (node, tr, insideRightEdgePos) => {
228
205
  const secondColumn = node.content.child(1);
229
206
  fromTwoColsToOne(secondColumn, insideRightEdgePos - thirdColumn.nodeSize - secondColumn.nodeSize, insideRightEdgePos)(tr);
230
207
  };
231
- const increaseColumns = (schema, pos, newColumnsNumber = 1, formatMessage) => {
208
+ const increaseColumns = (schema, pos, newColumnsNumber = 1) => {
232
209
  return tr => {
233
210
  for (let i = 0; i < newColumnsNumber; i++) {
234
- addColumn(schema, pos, formatMessage)(tr);
211
+ addColumn(schema, pos)(tr);
235
212
  }
236
213
  };
237
214
  };
@@ -254,7 +231,7 @@ const decreaseColumns = (node, insideRightEdgePos, columnsNumberToRemove = 1) =>
254
231
  * Switching from 3 -> 2 moves all the content of the third col inside the second before
255
232
  * removing it
256
233
  */
257
- function forceColumnStructure(state, node, pos, presetLayout, formatMessage) {
234
+ function forceColumnStructure(state, node, pos, presetLayout) {
258
235
  const tr = state.tr;
259
236
  const insideRightEdgeOfLayoutSection = pos + node.nodeSize - 1;
260
237
  const numCols = node.childCount;
@@ -267,7 +244,7 @@ function forceColumnStructure(state, node, pos, presetLayout, formatMessage) {
267
244
 
268
245
  // 2 columns -> 3 columns
269
246
  } else if (THREE_COL_LAYOUTS.indexOf(presetLayout) >= 0 && numCols === 2) {
270
- fromTwoColsToThree(state.schema, insideRightEdgeOfLayoutSection, formatMessage)(tr);
247
+ fromTwoColsToThree(state.schema, insideRightEdgeOfLayoutSection)(tr);
271
248
 
272
249
  // 2 columns -> 1 column
273
250
  } else if (ONE_COL_LAYOUTS.indexOf(presetLayout) >= 0 && numCols === 2) {
@@ -288,13 +265,13 @@ function forceColumnStructure(state, node, pos, presetLayout, formatMessage) {
288
265
  }
289
266
  return tr;
290
267
  }
291
- function forceColumnStructureNew(state, node, pos, presetLayout, formatMessage) {
268
+ function forceColumnStructureNew(state, node, pos, presetLayout) {
292
269
  const tr = state.tr;
293
270
  const insideRightEdgeOfLayoutSection = pos + node.nodeSize - 1;
294
271
  const numCols = node.childCount;
295
272
  const columnChange = getWidthsForPreset(presetLayout).length - numCols;
296
273
  if (columnChange > 0) {
297
- increaseColumns(state.schema, insideRightEdgeOfLayoutSection, columnChange, formatMessage)(tr);
274
+ increaseColumns(state.schema, insideRightEdgeOfLayoutSection, columnChange)(tr);
298
275
  } else if (columnChange < 0) {
299
276
  decreaseColumns(node, insideRightEdgeOfLayoutSection, -columnChange)(tr);
300
277
  }
@@ -323,9 +300,9 @@ function forceColumnWidths(state, tr, pos, presetLayout) {
323
300
  }
324
301
  return tr.replaceWith(pos + 1, pos + node.nodeSize - 1, columnWidth(node, state.schema, getWidthsForPreset(presetLayout)));
325
302
  }
326
- export function forceSectionToPresetLayout(state, node, pos, presetLayout, formatMessage) {
303
+ export function forceSectionToPresetLayout(state, node, pos, presetLayout) {
327
304
  const forceColumnStructureFn = isPreRelease2() ? forceColumnStructureNew : forceColumnStructure;
328
- let tr = forceColumnStructureFn(state, node, pos, presetLayout, formatMessage);
305
+ let tr = forceColumnStructureFn(state, node, pos, presetLayout);
329
306
 
330
307
  // save the selection here, since forcing column widths causes a change over the
331
308
  // entire layoutSection, which remaps selection to the end. not remapping here
@@ -335,7 +312,7 @@ export function forceSectionToPresetLayout(state, node, pos, presetLayout, forma
335
312
  const selectionPos$ = tr.doc.resolve(selection.$from.pos);
336
313
  return tr.setSelection(state.selection instanceof NodeSelection ? new NodeSelection(selectionPos$) : new TextSelection(selectionPos$));
337
314
  }
338
- export const setPresetLayout = editorAnalyticsAPI => (layout, formatMessage) => (state, dispatch) => {
315
+ export const setPresetLayout = editorAnalyticsAPI => layout => (state, dispatch) => {
339
316
  const {
340
317
  pos,
341
318
  selectedLayout
@@ -347,7 +324,7 @@ export const setPresetLayout = editorAnalyticsAPI => (layout, formatMessage) =>
347
324
  if (!node) {
348
325
  return false;
349
326
  }
350
- let tr = forceSectionToPresetLayout(state, node, pos, layout, formatMessage);
327
+ let tr = forceSectionToPresetLayout(state, node, pos, layout);
351
328
  if (tr) {
352
329
  editorAnalyticsAPI === null || editorAnalyticsAPI === void 0 ? void 0 : editorAnalyticsAPI.attachAnalyticsEvent({
353
330
  action: ACTION.CHANGED_LAYOUT,
@@ -5,9 +5,9 @@ import { keydownHandler } from '@atlaskit/editor-prosemirror/keymap';
5
5
  import { Selection, TextSelection } from '@atlaskit/editor-prosemirror/state';
6
6
  import { findParentNodeOfType } from '@atlaskit/editor-prosemirror/utils';
7
7
  import { Decoration, DecorationSet } from '@atlaskit/editor-prosemirror/view';
8
- import { fixColumnSizes, fixColumnStructure, getSelectedLayout } from '../actions';
9
- import { getMaybeLayoutSection } from '../utils';
8
+ import { fixColumnSizes, fixColumnStructure, getSelectedLayout } from './actions';
10
9
  import { pluginKey } from './plugin-key';
10
+ import { getMaybeLayoutSection } from './utils';
11
11
  export const DEFAULT_LAYOUT = 'two_equal';
12
12
  const isWholeSelectionInsideLayoutColumn = state => {
13
13
  // Since findParentNodeOfType doesn't check if selection.to shares the parent, we do this check ourselves
@@ -1,6 +1,6 @@
1
1
  import { SafePlugin } from '@atlaskit/editor-common/safe-plugin';
2
2
  import { PluginKey } from '@atlaskit/editor-prosemirror/state';
3
- import { LayoutSectionView } from '../node-views';
3
+ import { LayoutSectionView } from '../nodeviews';
4
4
  export const pluginKey = new PluginKey('layoutResizingPlugin');
5
5
  export default ((options, pluginInjectionApi, portalProviderAPI, eventDispatcher) => new SafePlugin({
6
6
  key: pluginKey,
@@ -2,21 +2,35 @@
2
2
  * @jsxRuntime classic
3
3
  * @jsx jsx
4
4
  */
5
- // eslint-disable-next-line @atlaskit/ui-styling-standard/no-global-styles, @atlaskit/ui-styling-standard/use-compiled -- Ignored via go/DSP-18766
5
+ import { useMemo } from 'react';
6
+
7
+ // eslint-disable-next-line @atlaskit/ui-styling-standard/no-global-styles, @atlaskit/ui-styling-standard/use-compiled
6
8
  import { css, Global, jsx } from '@emotion/react';
7
- const globalStyles = css({
9
+ import { useIntl } from 'react-intl-next';
10
+ import { layoutMessages as messages } from '@atlaskit/editor-common/messages';
11
+ const getPlaceholderStyle = message => css({
12
+ // when paragraph is the only child, and it only has a trailingBreak.
8
13
  // eslint-disable-next-line @atlaskit/ui-styling-standard/no-nested-selectors, @atlaskit/ui-styling-standard/no-unsafe-selectors -- Ignored via go/DSP-18766
9
- '.ProseMirror [data-layout-column] span.pm-placeholder__text[data-placeholder]': {
14
+ '.ProseMirror [data-layout-column] > [data-layout-content] > p:only-child:has(.ProseMirror-trailingBreak:only-child)': {
10
15
  // eslint-disable-next-line @atlaskit/ui-styling-standard/no-important-styles -- Ignored via go/DSP-18766
11
- '&::after': {
16
+ '&::before': {
17
+ // eslint-disable-next-line @atlaskit/ui-styling-standard/no-unsafe-values
18
+ content: `"${message}"`,
19
+ position: 'absolute',
12
20
  color: "var(--ds-text-disabled, #A5ADBA)",
13
21
  font: "var(--ds-font-body, normal 400 14px/20px ui-sans-serif, -apple-system, BlinkMacSystemFont, \"Segoe UI\", Ubuntu, system-ui, \"Helvetica Neue\", sans-serif)",
14
- fontStyle: 'italic'
22
+ marginTop: "var(--ds-space-050, 4px)"
15
23
  }
16
24
  }
17
25
  });
18
26
  export const GlobalStylesWrapper = () => {
27
+ const {
28
+ formatMessage
29
+ } = useIntl();
30
+ const placeholderStyle = useMemo(() => {
31
+ return getPlaceholderStyle(formatMessage(messages.layoutPlaceholder));
32
+ }, [formatMessage]);
19
33
  return jsx(Global, {
20
- styles: globalStyles
34
+ styles: placeholderStyle
21
35
  });
22
36
  };
@@ -15,10 +15,10 @@ import LayoutTwoLeftSidebarIcon from '@atlaskit/icon/glyph/editor/layout-two-lef
15
15
  import LayoutTwoRightSidebarIcon from '@atlaskit/icon/glyph/editor/layout-two-right-sidebar';
16
16
  import RemoveIcon from '@atlaskit/icon/glyph/editor/remove';
17
17
  import { fg } from '@atlaskit/platform-feature-flags';
18
- import { deleteActiveLayoutNode, getPresetLayout, setPresetLayout } from './actions';
19
- import { LayoutThreeWithLeftSidebarsIcon } from './ui/icons/LayoutThreeWithLeftSidebars';
20
- import { LayoutThreeWithRightSidebarsIcon } from './ui/icons/LayoutThreeWithRightSidebars';
21
- import { isPreRelease2 } from './utils/preRelease';
18
+ import { deleteActiveLayoutNode, getPresetLayout, setPresetLayout } from '../pm-plugins/actions';
19
+ import { isPreRelease2 } from '../pm-plugins/utils/preRelease';
20
+ import { LayoutThreeWithLeftSidebarsIcon } from './icons/LayoutThreeWithLeftSidebars';
21
+ import { LayoutThreeWithRightSidebarsIcon } from './icons/LayoutThreeWithRightSidebars';
22
22
  const LAYOUT_TYPES = [{
23
23
  id: 'editor.layout.twoEquals',
24
24
  type: 'two_equal',
@@ -111,7 +111,7 @@ const buildLayoutButton = (intl, item, currentLayout, editorAnalyticsAPI) => ({
111
111
  iconFallback: item.iconFallback,
112
112
  testId: item.title.id ? `${item.title.id}` : undefined,
113
113
  title: intl.formatMessage(item.title),
114
- onClick: setPresetLayout(editorAnalyticsAPI)(item.type, intl.formatMessage),
114
+ onClick: setPresetLayout(editorAnalyticsAPI)(item.type),
115
115
  selected: !!currentLayout && currentLayout === item.type,
116
116
  tabIndex: null
117
117
  });
@@ -137,7 +137,7 @@ const getAdvancedLayoutItems = ({
137
137
  }),
138
138
  //'2-columns',
139
139
  icon: iconPlaceholder,
140
- onClick: setPresetLayout(editorAnalyticsAPI)('two_equal', intl.formatMessage),
140
+ onClick: setPresetLayout(editorAnalyticsAPI)('two_equal'),
141
141
  selected: numberOfColumns === 2
142
142
  }, {
143
143
  title: intl.formatMessage(layoutMessages.columnOption, {
@@ -145,7 +145,7 @@ const getAdvancedLayoutItems = ({
145
145
  }),
146
146
  //'3-columns'
147
147
  icon: iconPlaceholder,
148
- onClick: setPresetLayout(editorAnalyticsAPI)('three_equal', intl.formatMessage),
148
+ onClick: setPresetLayout(editorAnalyticsAPI)('three_equal'),
149
149
  selected: numberOfColumns === 3
150
150
  }, {
151
151
  title: intl.formatMessage(layoutMessages.columnOption, {
@@ -153,7 +153,7 @@ const getAdvancedLayoutItems = ({
153
153
  }),
154
154
  //'4-columns'
155
155
  icon: iconPlaceholder,
156
- onClick: setPresetLayout(editorAnalyticsAPI)('four_equal', intl.formatMessage),
156
+ onClick: setPresetLayout(editorAnalyticsAPI)('four_equal'),
157
157
  selected: numberOfColumns === 4
158
158
  }, {
159
159
  title: intl.formatMessage(layoutMessages.columnOption, {
@@ -161,7 +161,7 @@ const getAdvancedLayoutItems = ({
161
161
  }),
162
162
  //'5-columns'
163
163
  icon: iconPlaceholder,
164
- onClick: setPresetLayout(editorAnalyticsAPI)('five_equal', intl.formatMessage),
164
+ onClick: setPresetLayout(editorAnalyticsAPI)('five_equal'),
165
165
  selected: numberOfColumns === 5
166
166
  }];
167
167
  return [{
package/dist/esm/index.js CHANGED
@@ -1 +1 @@
1
- export { layoutPlugin } from './plugin';
1
+ export { layoutPlugin } from './layoutPlugin';
@@ -5,13 +5,13 @@ import { ACTION, ACTION_SUBJECT, ACTION_SUBJECT_ID, EVENT_TYPE, INPUT_METHOD } f
5
5
  import { layoutMessages, toolbarInsertBlockMessages as messages } from '@atlaskit/editor-common/messages';
6
6
  import { IconFiveColumnLayout, IconFourColumnLayout, IconLayout, IconThreeColumnLayout, IconTwoColumnLayout } from '@atlaskit/editor-common/quick-insert';
7
7
  import { fg } from '@atlaskit/platform-feature-flags';
8
- import { createDefaultLayoutSection, createMultiColumnLayoutSection, insertLayoutColumnsWithAnalytics } from './actions';
8
+ import { createDefaultLayoutSection, createMultiColumnLayoutSection, insertLayoutColumnsWithAnalytics } from './pm-plugins/actions';
9
9
  import { default as createLayoutPlugin } from './pm-plugins/main';
10
10
  import { pluginKey } from './pm-plugins/plugin-key';
11
11
  import { default as createLayoutResizingPlugin } from './pm-plugins/resizing';
12
- import { buildToolbar } from './toolbar';
12
+ import { isPreRelease2 } from './pm-plugins/utils/preRelease';
13
13
  import { GlobalStylesWrapper } from './ui/global-styles';
14
- import { isPreRelease2 } from './utils/preRelease';
14
+ import { buildToolbar } from './ui/toolbar';
15
15
  export { pluginKey };
16
16
  export var layoutPlugin = function layoutPlugin(_ref) {
17
17
  var _api$analytics;
@@ -75,7 +75,7 @@ export var layoutPlugin = function layoutPlugin(_ref) {
75
75
  return /*#__PURE__*/React.createElement(IconTwoColumnLayout, null);
76
76
  },
77
77
  action: function action(insert, state) {
78
- var tr = insert(createMultiColumnLayoutSection(state, 2, formatMessage));
78
+ var tr = insert(createMultiColumnLayoutSection(state, 2));
79
79
  return tr;
80
80
  }
81
81
  }, {
@@ -88,7 +88,7 @@ export var layoutPlugin = function layoutPlugin(_ref) {
88
88
  return /*#__PURE__*/React.createElement(IconThreeColumnLayout, null);
89
89
  },
90
90
  action: function action(insert, state) {
91
- var tr = insert(createMultiColumnLayoutSection(state, 3, formatMessage));
91
+ var tr = insert(createMultiColumnLayoutSection(state, 3));
92
92
  return tr;
93
93
  }
94
94
  }, {
@@ -101,7 +101,7 @@ export var layoutPlugin = function layoutPlugin(_ref) {
101
101
  return /*#__PURE__*/React.createElement(IconFourColumnLayout, null);
102
102
  },
103
103
  action: function action(insert, state) {
104
- var tr = insert(createMultiColumnLayoutSection(state, 4, formatMessage));
104
+ var tr = insert(createMultiColumnLayoutSection(state, 4));
105
105
  return tr;
106
106
  }
107
107
  }, {
@@ -114,7 +114,7 @@ export var layoutPlugin = function layoutPlugin(_ref) {
114
114
  return /*#__PURE__*/React.createElement(IconFiveColumnLayout, null);
115
115
  },
116
116
  action: function action(insert, state) {
117
- var tr = insert(createMultiColumnLayoutSection(state, 5, formatMessage));
117
+ var tr = insert(createMultiColumnLayoutSection(state, 5));
118
118
  return tr;
119
119
  }
120
120
  }] : [{
@@ -0,0 +1,2 @@
1
+ import { pluginKey } from './pm-plugins/plugin-key';
2
+ export { pluginKey };
@@ -3,14 +3,13 @@ function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbol
3
3
  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) { _defineProperty(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; }
4
4
  import { ACTION, ACTION_SUBJECT, ACTION_SUBJECT_ID, EVENT_TYPE, LAYOUT_TYPE } from '@atlaskit/editor-common/analytics';
5
5
  import { withAnalytics } from '@atlaskit/editor-common/editor-analytics';
6
- import { layoutMessages as messages } from '@atlaskit/editor-common/messages';
7
6
  import { flatmap, getStepRange, isEmptyDocument, mapChildren } from '@atlaskit/editor-common/utils';
8
7
  import { Fragment, Slice } from '@atlaskit/editor-prosemirror/model';
9
8
  import { NodeSelection, TextSelection } from '@atlaskit/editor-prosemirror/state';
10
9
  import { safeInsert } from '@atlaskit/editor-prosemirror/utils';
11
10
  import { editorExperiment } from '@atlaskit/tmp-editor-statsig/experiments';
12
11
  import { EVEN_DISTRIBUTED_COL_WIDTHS } from './consts';
13
- import { pluginKey } from './pm-plugins/plugin-key';
12
+ import { pluginKey } from './plugin-key';
14
13
  import { isPreRelease2 } from './utils/preRelease';
15
14
  export var ONE_COL_LAYOUTS = ['single'];
16
15
  export var TWO_COL_LAYOUTS = ['two_equal', 'two_left_sidebar', 'two_right_sidebar'];
@@ -126,46 +125,31 @@ export var getSelectedLayout = function getSelectedLayout(maybeLayoutSection, cu
126
125
  }
127
126
  return current;
128
127
  };
129
- var createPlaceholderNode = function createPlaceholderNode(schema, formatMessage) {
130
- if (!formatMessage) {
131
- return undefined;
132
- }
133
- var _schema$nodes = schema.nodes,
134
- paragraph = _schema$nodes.paragraph,
135
- placeholder = _schema$nodes.placeholder;
136
- //create a paragraph node with content of placeholder node
137
- var placeholderNode = placeholder.createChecked({
138
- text: formatMessage(messages.layoutPlaceholder)
139
- });
140
- return paragraph.createAndFill(undefined, placeholderNode);
141
- };
142
- export var createMultiColumnLayoutSection = function createMultiColumnLayoutSection(state, numberOfColumns, formatMessage) {
128
+ export var createMultiColumnLayoutSection = function createMultiColumnLayoutSection(state) {
129
+ var numberOfColumns = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 2;
143
130
  var _state$schema$nodes = state.schema.nodes,
144
131
  layoutSection = _state$schema$nodes.layoutSection,
145
132
  layoutColumn = _state$schema$nodes.layoutColumn;
146
- var placeholder = createPlaceholderNode(state.schema, formatMessage);
147
- var layoutColumnNode = layoutColumn.createAndFill({
148
- width: EVEN_DISTRIBUTED_COL_WIDTHS[numberOfColumns]
149
- }, placeholder);
150
133
  var columns = Fragment.fromArray(Array.from({
151
134
  length: numberOfColumns
152
135
  }, function () {
153
- return layoutColumnNode;
136
+ return layoutColumn.createAndFill({
137
+ width: EVEN_DISTRIBUTED_COL_WIDTHS[numberOfColumns]
138
+ });
154
139
  }));
155
140
  return layoutSection.createAndFill(undefined, columns);
156
141
  };
157
- export var createDefaultLayoutSection = function createDefaultLayoutSection(state, formatMessage) {
142
+ export var createDefaultLayoutSection = function createDefaultLayoutSection(state) {
158
143
  var _state$schema$nodes2 = state.schema.nodes,
159
144
  layoutSection = _state$schema$nodes2.layoutSection,
160
145
  layoutColumn = _state$schema$nodes2.layoutColumn;
161
- var placeholder = isPreRelease2() ? createPlaceholderNode(state.schema, formatMessage) : undefined;
162
146
 
163
147
  // create a 50-50 layout by default
164
148
  var columns = Fragment.fromArray([layoutColumn.createAndFill({
165
149
  width: 50
166
- }, placeholder), layoutColumn.createAndFill({
150
+ }), layoutColumn.createAndFill({
167
151
  width: 50
168
- }, placeholder)]);
152
+ })]);
169
153
  return layoutSection.createAndFill(undefined, columns);
170
154
  };
171
155
  export var insertLayoutColumns = function insertLayoutColumns(state, dispatch) {
@@ -175,7 +159,7 @@ export var insertLayoutColumns = function insertLayoutColumns(state, dispatch) {
175
159
  return true;
176
160
  };
177
161
  export var insertLayoutColumnsWithAnalytics = function insertLayoutColumnsWithAnalytics(editorAnalyticsAPI) {
178
- return function (inputMethod, formatMessage) {
162
+ return function (inputMethod) {
179
163
  return withAnalytics(editorAnalyticsAPI, {
180
164
  action: ACTION.INSERTED,
181
165
  actionSubject: ACTION_SUBJECT.DOCUMENT,
@@ -186,7 +170,7 @@ export var insertLayoutColumnsWithAnalytics = function insertLayoutColumnsWithAn
186
170
  eventType: EVENT_TYPE.TRACK
187
171
  })(function (state, dispatch) {
188
172
  if (dispatch) {
189
- dispatch(safeInsert(createDefaultLayoutSection(state, formatMessage))(state.tr));
173
+ dispatch(safeInsert(createDefaultLayoutSection(state))(state.tr));
190
174
  }
191
175
  return true;
192
176
  });
@@ -196,26 +180,21 @@ export var insertLayoutColumnsWithAnalytics = function insertLayoutColumnsWithAn
196
180
  /**
197
181
  * Add a column to the right of existing layout
198
182
  */
199
- function addColumn(schema, pos, formatMessage) {
183
+ function addColumn(schema, pos) {
200
184
  if (!isPreRelease2()) {
201
185
  return function (tr) {
202
186
  tr.replaceWith(tr.mapping.map(pos), tr.mapping.map(pos), schema.nodes.layoutColumn.createAndFill());
203
187
  };
204
188
  }
205
- var placeholder = createPlaceholderNode(schema, formatMessage);
206
189
  return function (tr) {
207
- tr.replaceWith(tr.mapping.map(pos), tr.mapping.map(pos), schema.nodes.layoutColumn.createAndFill(undefined, placeholder));
190
+ tr.replaceWith(tr.mapping.map(pos), tr.mapping.map(pos), schema.nodes.layoutColumn.createAndFill(undefined));
208
191
  };
209
192
  }
210
- var containPlaceholderOnly = function containPlaceholderOnly(node, schema) {
211
- var _node$firstChild, _node$firstChild2;
212
- return node.childCount === 1 && ((_node$firstChild = node.firstChild) === null || _node$firstChild === void 0 ? void 0 : _node$firstChild.childCount) === 1 && ((_node$firstChild2 = node.firstChild) === null || _node$firstChild2 === void 0 || (_node$firstChild2 = _node$firstChild2.firstChild) === null || _node$firstChild2 === void 0 ? void 0 : _node$firstChild2.type) === schema.nodes.placeholder;
213
- };
214
193
  function removeLastColumnInLayout(column, columnPos, insideRightEdgePos) {
215
194
  return function (tr) {
216
195
  // check if the column only contains a paragraph with a placeholder text
217
196
  // if so, remove the whole column, otherwise just remove the paragraph
218
- if (isEmptyDocument(column) || containPlaceholderOnly(column, tr.doc.type.schema)) {
197
+ if (isEmptyDocument(column)) {
219
198
  tr.replaceRange(tr.mapping.map(columnPos - 1), tr.mapping.map(insideRightEdgePos), Slice.empty);
220
199
  } else {
221
200
  tr.replaceRange(tr.mapping.map(columnPos - 1), tr.mapping.map(columnPos + 1), Slice.empty);
@@ -240,10 +219,9 @@ var fromThreeColstoOne = function fromThreeColstoOne(node, tr, insideRightEdgePo
240
219
  };
241
220
  var increaseColumns = function increaseColumns(schema, pos) {
242
221
  var newColumnsNumber = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 1;
243
- var formatMessage = arguments.length > 3 ? arguments[3] : undefined;
244
222
  return function (tr) {
245
223
  for (var i = 0; i < newColumnsNumber; i++) {
246
- addColumn(schema, pos, formatMessage)(tr);
224
+ addColumn(schema, pos)(tr);
247
225
  }
248
226
  };
249
227
  };
@@ -267,7 +245,7 @@ var decreaseColumns = function decreaseColumns(node, insideRightEdgePos) {
267
245
  * Switching from 3 -> 2 moves all the content of the third col inside the second before
268
246
  * removing it
269
247
  */
270
- function forceColumnStructure(state, node, pos, presetLayout, formatMessage) {
248
+ function forceColumnStructure(state, node, pos, presetLayout) {
271
249
  var tr = state.tr;
272
250
  var insideRightEdgeOfLayoutSection = pos + node.nodeSize - 1;
273
251
  var numCols = node.childCount;
@@ -280,7 +258,7 @@ function forceColumnStructure(state, node, pos, presetLayout, formatMessage) {
280
258
 
281
259
  // 2 columns -> 3 columns
282
260
  } else if (THREE_COL_LAYOUTS.indexOf(presetLayout) >= 0 && numCols === 2) {
283
- fromTwoColsToThree(state.schema, insideRightEdgeOfLayoutSection, formatMessage)(tr);
261
+ fromTwoColsToThree(state.schema, insideRightEdgeOfLayoutSection)(tr);
284
262
 
285
263
  // 2 columns -> 1 column
286
264
  } else if (ONE_COL_LAYOUTS.indexOf(presetLayout) >= 0 && numCols === 2) {
@@ -301,13 +279,13 @@ function forceColumnStructure(state, node, pos, presetLayout, formatMessage) {
301
279
  }
302
280
  return tr;
303
281
  }
304
- function forceColumnStructureNew(state, node, pos, presetLayout, formatMessage) {
282
+ function forceColumnStructureNew(state, node, pos, presetLayout) {
305
283
  var tr = state.tr;
306
284
  var insideRightEdgeOfLayoutSection = pos + node.nodeSize - 1;
307
285
  var numCols = node.childCount;
308
286
  var columnChange = getWidthsForPreset(presetLayout).length - numCols;
309
287
  if (columnChange > 0) {
310
- increaseColumns(state.schema, insideRightEdgeOfLayoutSection, columnChange, formatMessage)(tr);
288
+ increaseColumns(state.schema, insideRightEdgeOfLayoutSection, columnChange)(tr);
311
289
  } else if (columnChange < 0) {
312
290
  decreaseColumns(node, insideRightEdgeOfLayoutSection, -columnChange)(tr);
313
291
  }
@@ -335,9 +313,9 @@ function forceColumnWidths(state, tr, pos, presetLayout) {
335
313
  }
336
314
  return tr.replaceWith(pos + 1, pos + node.nodeSize - 1, columnWidth(node, state.schema, getWidthsForPreset(presetLayout)));
337
315
  }
338
- export function forceSectionToPresetLayout(state, node, pos, presetLayout, formatMessage) {
316
+ export function forceSectionToPresetLayout(state, node, pos, presetLayout) {
339
317
  var forceColumnStructureFn = isPreRelease2() ? forceColumnStructureNew : forceColumnStructure;
340
- var tr = forceColumnStructureFn(state, node, pos, presetLayout, formatMessage);
318
+ var tr = forceColumnStructureFn(state, node, pos, presetLayout);
341
319
 
342
320
  // save the selection here, since forcing column widths causes a change over the
343
321
  // entire layoutSection, which remaps selection to the end. not remapping here
@@ -348,7 +326,7 @@ export function forceSectionToPresetLayout(state, node, pos, presetLayout, forma
348
326
  return tr.setSelection(state.selection instanceof NodeSelection ? new NodeSelection(selectionPos$) : new TextSelection(selectionPos$));
349
327
  }
350
328
  export var setPresetLayout = function setPresetLayout(editorAnalyticsAPI) {
351
- return function (layout, formatMessage) {
329
+ return function (layout) {
352
330
  return function (state, dispatch) {
353
331
  var _ref = pluginKey.getState(state),
354
332
  pos = _ref.pos,
@@ -360,7 +338,7 @@ export var setPresetLayout = function setPresetLayout(editorAnalyticsAPI) {
360
338
  if (!node) {
361
339
  return false;
362
340
  }
363
- var tr = forceSectionToPresetLayout(state, node, pos, layout, formatMessage);
341
+ var tr = forceSectionToPresetLayout(state, node, pos, layout);
364
342
  if (tr) {
365
343
  editorAnalyticsAPI === null || editorAnalyticsAPI === void 0 || editorAnalyticsAPI.attachAnalyticsEvent({
366
344
  action: ACTION.CHANGED_LAYOUT,
@@ -8,9 +8,9 @@ import { keydownHandler } from '@atlaskit/editor-prosemirror/keymap';
8
8
  import { Selection, TextSelection } from '@atlaskit/editor-prosemirror/state';
9
9
  import { findParentNodeOfType } from '@atlaskit/editor-prosemirror/utils';
10
10
  import { Decoration, DecorationSet } from '@atlaskit/editor-prosemirror/view';
11
- import { fixColumnSizes, fixColumnStructure, getSelectedLayout } from '../actions';
12
- import { getMaybeLayoutSection } from '../utils';
11
+ import { fixColumnSizes, fixColumnStructure, getSelectedLayout } from './actions';
13
12
  import { pluginKey } from './plugin-key';
13
+ import { getMaybeLayoutSection } from './utils';
14
14
  export var DEFAULT_LAYOUT = 'two_equal';
15
15
  var isWholeSelectionInsideLayoutColumn = function isWholeSelectionInsideLayoutColumn(state) {
16
16
  // Since findParentNodeOfType doesn't check if selection.to shares the parent, we do this check ourselves
@@ -1,6 +1,6 @@
1
1
  import { SafePlugin } from '@atlaskit/editor-common/safe-plugin';
2
2
  import { PluginKey } from '@atlaskit/editor-prosemirror/state';
3
- import { LayoutSectionView } from '../node-views';
3
+ import { LayoutSectionView } from '../nodeviews';
4
4
  export var pluginKey = new PluginKey('layoutResizingPlugin');
5
5
  export default (function (options, pluginInjectionApi, portalProviderAPI, eventDispatcher) {
6
6
  return new SafePlugin({
@@ -2,21 +2,36 @@
2
2
  * @jsxRuntime classic
3
3
  * @jsx jsx
4
4
  */
5
- // eslint-disable-next-line @atlaskit/ui-styling-standard/no-global-styles, @atlaskit/ui-styling-standard/use-compiled -- Ignored via go/DSP-18766
5
+ import { useMemo } from 'react';
6
+
7
+ // eslint-disable-next-line @atlaskit/ui-styling-standard/no-global-styles, @atlaskit/ui-styling-standard/use-compiled
6
8
  import { css, Global, jsx } from '@emotion/react';
7
- var globalStyles = css({
8
- // eslint-disable-next-line @atlaskit/ui-styling-standard/no-nested-selectors, @atlaskit/ui-styling-standard/no-unsafe-selectors -- Ignored via go/DSP-18766
9
- '.ProseMirror [data-layout-column] span.pm-placeholder__text[data-placeholder]': {
10
- // eslint-disable-next-line @atlaskit/ui-styling-standard/no-important-styles -- Ignored via go/DSP-18766
11
- '&::after': {
12
- color: "var(--ds-text-disabled, #A5ADBA)",
13
- font: "var(--ds-font-body, normal 400 14px/20px ui-sans-serif, -apple-system, BlinkMacSystemFont, \"Segoe UI\", Ubuntu, system-ui, \"Helvetica Neue\", sans-serif)",
14
- fontStyle: 'italic'
9
+ import { useIntl } from 'react-intl-next';
10
+ import { layoutMessages as messages } from '@atlaskit/editor-common/messages';
11
+ var getPlaceholderStyle = function getPlaceholderStyle(message) {
12
+ return css({
13
+ // when paragraph is the only child, and it only has a trailingBreak.
14
+ // eslint-disable-next-line @atlaskit/ui-styling-standard/no-nested-selectors, @atlaskit/ui-styling-standard/no-unsafe-selectors -- Ignored via go/DSP-18766
15
+ '.ProseMirror [data-layout-column] > [data-layout-content] > p:only-child:has(.ProseMirror-trailingBreak:only-child)': {
16
+ // eslint-disable-next-line @atlaskit/ui-styling-standard/no-important-styles -- Ignored via go/DSP-18766
17
+ '&::before': {
18
+ // eslint-disable-next-line @atlaskit/ui-styling-standard/no-unsafe-values
19
+ content: "\"".concat(message, "\""),
20
+ position: 'absolute',
21
+ color: "var(--ds-text-disabled, #A5ADBA)",
22
+ font: "var(--ds-font-body, normal 400 14px/20px ui-sans-serif, -apple-system, BlinkMacSystemFont, \"Segoe UI\", Ubuntu, system-ui, \"Helvetica Neue\", sans-serif)",
23
+ marginTop: "var(--ds-space-050, 4px)"
24
+ }
15
25
  }
16
- }
17
- });
26
+ });
27
+ };
18
28
  export var GlobalStylesWrapper = function GlobalStylesWrapper() {
29
+ var _useIntl = useIntl(),
30
+ formatMessage = _useIntl.formatMessage;
31
+ var placeholderStyle = useMemo(function () {
32
+ return getPlaceholderStyle(formatMessage(messages.layoutPlaceholder));
33
+ }, [formatMessage]);
19
34
  return jsx(Global, {
20
- styles: globalStyles
35
+ styles: placeholderStyle
21
36
  });
22
37
  };