@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.
- package/CHANGELOG.md +18 -0
- package/dist/cjs/index.js +2 -2
- package/dist/cjs/{plugin.js → layoutPlugin.js} +7 -7
- package/dist/cjs/layoutPluginType.js +12 -0
- package/dist/cjs/{actions.js → pm-plugins/actions.js} +23 -45
- package/dist/cjs/pm-plugins/main.js +2 -2
- package/dist/cjs/pm-plugins/resizing.js +2 -2
- package/dist/cjs/ui/global-styles.js +29 -14
- package/dist/cjs/{toolbar.js → ui/toolbar.js} +9 -9
- package/dist/es2019/index.js +1 -1
- package/dist/es2019/{plugin.js → layoutPlugin.js} +7 -7
- package/dist/es2019/layoutPluginType.js +2 -0
- package/dist/es2019/{actions.js → pm-plugins/actions.js} +23 -46
- package/dist/es2019/pm-plugins/main.js +2 -2
- package/dist/es2019/pm-plugins/resizing.js +1 -1
- package/dist/es2019/ui/global-styles.js +20 -6
- package/dist/es2019/{toolbar.js → ui/toolbar.js} +9 -9
- package/dist/esm/index.js +1 -1
- package/dist/esm/{plugin.js → layoutPlugin.js} +7 -7
- package/dist/esm/layoutPluginType.js +2 -0
- package/dist/esm/{actions.js → pm-plugins/actions.js} +23 -45
- package/dist/esm/pm-plugins/main.js +2 -2
- package/dist/esm/pm-plugins/resizing.js +1 -1
- package/dist/esm/ui/global-styles.js +27 -12
- package/dist/esm/{toolbar.js → ui/toolbar.js} +9 -9
- package/dist/types/index.d.ts +2 -2
- package/dist/types/layoutPlugin.d.ts +4 -0
- package/dist/types/{plugin.d.ts → layoutPluginType.d.ts} +1 -2
- package/dist/types/{node-views → nodeviews}/index.d.ts +1 -1
- package/dist/types/{actions.d.ts → pm-plugins/actions.d.ts} +6 -7
- package/dist/types/pm-plugins/resizing.d.ts +1 -1
- package/dist/types/ui/global-styles.d.ts +0 -4
- package/dist/types/{toolbar.d.ts → ui/toolbar.d.ts} +1 -1
- package/dist/types-ts4.5/index.d.ts +2 -2
- package/dist/types-ts4.5/layoutPlugin.d.ts +4 -0
- package/dist/types-ts4.5/{plugin.d.ts → layoutPluginType.d.ts} +1 -2
- package/dist/types-ts4.5/{node-views → nodeviews}/index.d.ts +1 -1
- package/dist/types-ts4.5/{actions.d.ts → pm-plugins/actions.d.ts} +6 -7
- package/dist/types-ts4.5/pm-plugins/resizing.d.ts +1 -1
- package/dist/types-ts4.5/ui/global-styles.d.ts +0 -4
- package/dist/types-ts4.5/{toolbar.d.ts → ui/toolbar.d.ts} +1 -1
- package/package.json +8 -5
- /package/dist/cjs/{node-views → nodeviews}/index.js +0 -0
- /package/dist/cjs/{consts.js → pm-plugins/consts.js} +0 -0
- /package/dist/cjs/{utils → pm-plugins/utils}/index.js +0 -0
- /package/dist/cjs/{utils → pm-plugins/utils}/preRelease.js +0 -0
- /package/dist/cjs/{types.js → types/index.js} +0 -0
- /package/dist/es2019/{node-views → nodeviews}/index.js +0 -0
- /package/dist/es2019/{consts.js → pm-plugins/consts.js} +0 -0
- /package/dist/es2019/{utils → pm-plugins/utils}/index.js +0 -0
- /package/dist/es2019/{utils → pm-plugins/utils}/preRelease.js +0 -0
- /package/dist/es2019/{types.js → types/index.js} +0 -0
- /package/dist/esm/{node-views → nodeviews}/index.js +0 -0
- /package/dist/esm/{consts.js → pm-plugins/consts.js} +0 -0
- /package/dist/esm/{utils → pm-plugins/utils}/index.js +0 -0
- /package/dist/esm/{utils → pm-plugins/utils}/preRelease.js +0 -0
- /package/dist/esm/{types.js → types/index.js} +0 -0
- /package/dist/types/{consts.d.ts → pm-plugins/consts.d.ts} +0 -0
- /package/dist/types/{utils → pm-plugins/utils}/index.d.ts +0 -0
- /package/dist/types/{utils → pm-plugins/utils}/preRelease.d.ts +0 -0
- /package/dist/types/{types.d.ts → types/index.d.ts} +0 -0
- /package/dist/types-ts4.5/{consts.d.ts → pm-plugins/consts.d.ts} +0 -0
- /package/dist/types-ts4.5/{utils → pm-plugins/utils}/index.d.ts +0 -0
- /package/dist/types-ts4.5/{utils → pm-plugins/utils}/preRelease.d.ts +0 -0
- /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 './
|
|
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
|
|
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
|
-
}, () =>
|
|
128
|
+
}, () => layoutColumn.createAndFill({
|
|
129
|
+
width: EVEN_DISTRIBUTED_COL_WIDTHS[numberOfColumns]
|
|
130
|
+
})));
|
|
148
131
|
return layoutSection.createAndFill(undefined, columns);
|
|
149
132
|
};
|
|
150
|
-
export const createDefaultLayoutSection =
|
|
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
|
-
}
|
|
142
|
+
}), layoutColumn.createAndFill({
|
|
161
143
|
width: 50
|
|
162
|
-
}
|
|
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 =>
|
|
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
|
|
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
|
|
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
|
|
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)
|
|
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
|
|
208
|
+
const increaseColumns = (schema, pos, newColumnsNumber = 1) => {
|
|
232
209
|
return tr => {
|
|
233
210
|
for (let i = 0; i < newColumnsNumber; i++) {
|
|
234
|
-
addColumn(schema, pos
|
|
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
|
|
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
|
|
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
|
|
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
|
|
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
|
|
303
|
+
export function forceSectionToPresetLayout(state, node, pos, presetLayout) {
|
|
327
304
|
const forceColumnStructureFn = isPreRelease2() ? forceColumnStructureNew : forceColumnStructure;
|
|
328
|
-
let tr = forceColumnStructureFn(state, node, pos, presetLayout
|
|
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 =>
|
|
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
|
|
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 '
|
|
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 '../
|
|
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
|
-
|
|
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
|
-
|
|
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]
|
|
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
|
-
'&::
|
|
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
|
-
|
|
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:
|
|
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 '
|
|
19
|
-
import {
|
|
20
|
-
import {
|
|
21
|
-
import {
|
|
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
|
|
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'
|
|
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'
|
|
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'
|
|
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'
|
|
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 './
|
|
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 {
|
|
12
|
+
import { isPreRelease2 } from './pm-plugins/utils/preRelease';
|
|
13
13
|
import { GlobalStylesWrapper } from './ui/global-styles';
|
|
14
|
-
import {
|
|
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
|
|
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
|
|
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
|
|
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
|
|
117
|
+
var tr = insert(createMultiColumnLayoutSection(state, 5));
|
|
118
118
|
return tr;
|
|
119
119
|
}
|
|
120
120
|
}] : [{
|
|
@@ -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 './
|
|
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
|
|
130
|
-
|
|
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
|
|
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
|
|
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
|
-
}
|
|
150
|
+
}), layoutColumn.createAndFill({
|
|
167
151
|
width: 50
|
|
168
|
-
}
|
|
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
|
|
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
|
|
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
|
|
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
|
|
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)
|
|
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
|
|
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
|
|
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
|
|
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
|
|
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
|
|
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
|
|
316
|
+
export function forceSectionToPresetLayout(state, node, pos, presetLayout) {
|
|
339
317
|
var forceColumnStructureFn = isPreRelease2() ? forceColumnStructureNew : forceColumnStructure;
|
|
340
|
-
var tr = forceColumnStructureFn(state, node, pos, presetLayout
|
|
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
|
|
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
|
|
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 '
|
|
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 '../
|
|
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
|
-
|
|
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
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
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:
|
|
35
|
+
styles: placeholderStyle
|
|
21
36
|
});
|
|
22
37
|
};
|