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