@atlaskit/editor-plugin-expand 1.3.0 → 1.3.2
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 +12 -0
- package/dist/cjs/legacyExpand/nodeviews/index.js +18 -5
- package/dist/cjs/singlePlayerExpand/commands.js +134 -0
- package/dist/cjs/singlePlayerExpand/node-views/index.js +381 -0
- package/dist/cjs/singlePlayerExpand/plugin.js +72 -9
- package/dist/cjs/singlePlayerExpand/pm-plugins/keymap.js +121 -0
- package/dist/cjs/singlePlayerExpand/pm-plugins/main.js +68 -0
- package/dist/cjs/singlePlayerExpand/toolbar.js +59 -0
- package/dist/cjs/singlePlayerExpand/ui/ExpandButton.js +87 -0
- package/dist/cjs/singlePlayerExpand/ui/NodeView.js +59 -0
- package/dist/cjs/singlePlayerExpand/utils.js +35 -0
- package/dist/es2019/index.js +0 -2
- package/dist/es2019/legacyExpand/nodeviews/index.js +18 -5
- package/dist/es2019/legacyExpand/pm-plugins/keymap.js +1 -2
- package/dist/es2019/singlePlayerExpand/commands.js +118 -0
- package/dist/es2019/singlePlayerExpand/node-views/index.js +370 -0
- package/dist/es2019/singlePlayerExpand/plugin.js +69 -10
- package/dist/es2019/singlePlayerExpand/pm-plugins/keymap.js +137 -0
- package/dist/es2019/singlePlayerExpand/pm-plugins/main.js +53 -0
- package/dist/es2019/singlePlayerExpand/toolbar.js +51 -0
- package/dist/es2019/singlePlayerExpand/ui/ExpandButton.js +77 -0
- package/dist/es2019/singlePlayerExpand/ui/NodeView.js +52 -0
- package/dist/es2019/singlePlayerExpand/utils.js +5 -0
- package/dist/esm/index.js +0 -2
- package/dist/esm/legacyExpand/nodeviews/index.js +18 -5
- package/dist/esm/legacyExpand/pm-plugins/keymap.js +1 -2
- package/dist/esm/singlePlayerExpand/commands.js +128 -0
- package/dist/esm/singlePlayerExpand/node-views/index.js +373 -0
- package/dist/esm/singlePlayerExpand/plugin.js +71 -10
- package/dist/esm/singlePlayerExpand/pm-plugins/keymap.js +115 -0
- package/dist/esm/singlePlayerExpand/pm-plugins/main.js +60 -0
- package/dist/esm/singlePlayerExpand/toolbar.js +52 -0
- package/dist/esm/singlePlayerExpand/ui/ExpandButton.js +77 -0
- package/dist/esm/singlePlayerExpand/ui/NodeView.js +53 -0
- package/dist/esm/singlePlayerExpand/utils.js +5 -0
- package/dist/types/index.d.ts +1 -1
- package/dist/types/legacyExpand/nodeviews/index.d.ts +1 -1
- package/dist/types/legacyExpand/plugin.d.ts +1 -1
- package/dist/types/legacyExpand/pm-plugins/keymap.d.ts +1 -1
- package/dist/types/legacyExpand/pm-plugins/main.d.ts +2 -2
- package/dist/types/legacyExpand/pm-plugins/plugin-factory.d.ts +1 -1
- package/dist/types/legacyExpand/reducer.d.ts +1 -1
- package/dist/types/legacyExpand/toolbar.d.ts +1 -1
- package/dist/types/plugin.d.ts +1 -1
- package/dist/types/singlePlayerExpand/commands.d.ts +15 -0
- package/dist/types/singlePlayerExpand/node-views/index.d.ts +51 -0
- package/dist/types/singlePlayerExpand/plugin.d.ts +1 -1
- package/dist/types/singlePlayerExpand/pm-plugins/keymap.d.ts +6 -0
- package/dist/types/singlePlayerExpand/pm-plugins/main.d.ts +9 -0
- package/dist/types/singlePlayerExpand/toolbar.d.ts +3 -0
- package/dist/types/singlePlayerExpand/ui/ExpandButton.d.ts +13 -0
- package/dist/types/singlePlayerExpand/ui/NodeView.d.ts +5 -0
- package/dist/types/singlePlayerExpand/utils.d.ts +3 -0
- package/dist/{types-ts4.5/legacyExpand → types}/types.d.ts +1 -1
- package/dist/types-ts4.5/index.d.ts +1 -1
- package/dist/types-ts4.5/legacyExpand/nodeviews/index.d.ts +1 -1
- package/dist/types-ts4.5/legacyExpand/plugin.d.ts +1 -1
- package/dist/types-ts4.5/legacyExpand/pm-plugins/keymap.d.ts +1 -1
- package/dist/types-ts4.5/legacyExpand/pm-plugins/main.d.ts +2 -2
- package/dist/types-ts4.5/legacyExpand/pm-plugins/plugin-factory.d.ts +1 -1
- package/dist/types-ts4.5/legacyExpand/reducer.d.ts +1 -1
- package/dist/types-ts4.5/legacyExpand/toolbar.d.ts +1 -1
- package/dist/types-ts4.5/plugin.d.ts +1 -1
- package/dist/types-ts4.5/singlePlayerExpand/commands.d.ts +15 -0
- package/dist/types-ts4.5/singlePlayerExpand/node-views/index.d.ts +51 -0
- package/dist/types-ts4.5/singlePlayerExpand/plugin.d.ts +1 -1
- package/dist/types-ts4.5/singlePlayerExpand/pm-plugins/keymap.d.ts +6 -0
- package/dist/types-ts4.5/singlePlayerExpand/pm-plugins/main.d.ts +9 -0
- package/dist/types-ts4.5/singlePlayerExpand/toolbar.d.ts +3 -0
- package/dist/types-ts4.5/singlePlayerExpand/ui/ExpandButton.d.ts +13 -0
- package/dist/types-ts4.5/singlePlayerExpand/ui/NodeView.d.ts +5 -0
- package/dist/types-ts4.5/singlePlayerExpand/utils.d.ts +3 -0
- package/dist/{types/legacyExpand → types-ts4.5}/types.d.ts +1 -1
- package/package.json +5 -5
- /package/dist/cjs/{legacyExpand/types.js → types.js} +0 -0
- /package/dist/es2019/{legacyExpand/types.js → types.js} +0 -0
- /package/dist/esm/{legacyExpand/types.js → types.js} +0 -0
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
import { backspace, bindKeymapWithCommand, moveDown, moveUp } from '@atlaskit/editor-common/keymaps';
|
|
2
|
+
import { GapCursorSelection, Side } from '@atlaskit/editor-common/selection';
|
|
3
|
+
import { findExpand } from '@atlaskit/editor-common/transforms';
|
|
4
|
+
import { isEmptyNode, isPositionNearTableRow } from '@atlaskit/editor-common/utils';
|
|
5
|
+
import { keymap } from '@atlaskit/editor-prosemirror/keymap';
|
|
6
|
+
import { Selection } from '@atlaskit/editor-prosemirror/state';
|
|
7
|
+
import { deleteExpand, focusTitle } from '../commands';
|
|
8
|
+
const isExpandNode = node => {
|
|
9
|
+
return (node === null || node === void 0 ? void 0 : node.type.name) === 'expand' || (node === null || node === void 0 ? void 0 : node.type.name) === 'nestedExpand';
|
|
10
|
+
};
|
|
11
|
+
export function expandKeymap(api, options) {
|
|
12
|
+
const list = {};
|
|
13
|
+
bindKeymapWithCommand(moveUp.common, (state, dispatch, editorView) => {
|
|
14
|
+
if (!editorView) {
|
|
15
|
+
return false;
|
|
16
|
+
}
|
|
17
|
+
const {
|
|
18
|
+
selection,
|
|
19
|
+
schema
|
|
20
|
+
} = state;
|
|
21
|
+
const {
|
|
22
|
+
nodeBefore
|
|
23
|
+
} = selection.$from;
|
|
24
|
+
if (selection instanceof GapCursorSelection && selection.side === Side.RIGHT && nodeBefore && (nodeBefore.type === schema.nodes.expand || nodeBefore.type === schema.nodes.nestedExpand)
|
|
25
|
+
// TO-DO: add back in expanded logic
|
|
26
|
+
) {
|
|
27
|
+
const {
|
|
28
|
+
$from
|
|
29
|
+
} = selection;
|
|
30
|
+
return focusTitle(Math.max($from.pos - 1, 0))(state, dispatch, editorView);
|
|
31
|
+
}
|
|
32
|
+
const {
|
|
33
|
+
$from
|
|
34
|
+
} = state.selection;
|
|
35
|
+
if (editorView.endOfTextblock('up')) {
|
|
36
|
+
const expand = findExpand(state);
|
|
37
|
+
|
|
38
|
+
// Moving UP in a table should move the cursor to the row above
|
|
39
|
+
// however when an expand is in a table cell to the left of the
|
|
40
|
+
// current table cell, arrow UP moves the cursor to the left
|
|
41
|
+
// see ED-15425
|
|
42
|
+
if (isPositionNearTableRow($from, schema, 'before') && !expand) {
|
|
43
|
+
return false;
|
|
44
|
+
}
|
|
45
|
+
const prevCursorPos = Math.max($from.pos - $from.parentOffset - 1, 0);
|
|
46
|
+
// move cursor from expand's content to its title
|
|
47
|
+
if (expand && expand.start === prevCursorPos) {
|
|
48
|
+
return focusTitle(expand.start)(state, dispatch, editorView);
|
|
49
|
+
}
|
|
50
|
+
const sel = Selection.findFrom(state.doc.resolve(prevCursorPos), -1);
|
|
51
|
+
const expandBefore = findExpand(state, sel);
|
|
52
|
+
if (sel && expandBefore) {
|
|
53
|
+
// moving cursor from outside of an expand to the title when it is collapsed
|
|
54
|
+
|
|
55
|
+
// TO-DO: Bring back expanded logic
|
|
56
|
+
return focusTitle(expandBefore.start)(state, dispatch, editorView);
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
return false;
|
|
60
|
+
}, list);
|
|
61
|
+
bindKeymapWithCommand(moveDown.common, (state, dispatch, editorView) => {
|
|
62
|
+
if (!editorView) {
|
|
63
|
+
return false;
|
|
64
|
+
}
|
|
65
|
+
const {
|
|
66
|
+
expand,
|
|
67
|
+
nestedExpand
|
|
68
|
+
} = state.schema.nodes;
|
|
69
|
+
const {
|
|
70
|
+
selection
|
|
71
|
+
} = state;
|
|
72
|
+
const {
|
|
73
|
+
nodeAfter
|
|
74
|
+
} = selection.$from;
|
|
75
|
+
if (selection instanceof GapCursorSelection && selection.side === Side.LEFT && nodeAfter && (nodeAfter.type === expand || nodeAfter.type === nestedExpand)
|
|
76
|
+
// TO-DO: Bring back expanded logic
|
|
77
|
+
) {
|
|
78
|
+
const {
|
|
79
|
+
$from
|
|
80
|
+
} = selection;
|
|
81
|
+
return focusTitle($from.pos + 1)(state, dispatch, editorView);
|
|
82
|
+
}
|
|
83
|
+
if (editorView.endOfTextblock('down')) {
|
|
84
|
+
const {
|
|
85
|
+
$from
|
|
86
|
+
} = state.selection;
|
|
87
|
+
if ($from.depth === 0) {
|
|
88
|
+
return false;
|
|
89
|
+
}
|
|
90
|
+
const $after = state.doc.resolve($from.after());
|
|
91
|
+
if ($after.nodeAfter && ($after.nodeAfter.type === expand || $after.nodeAfter.type === nestedExpand)) {
|
|
92
|
+
return focusTitle($after.pos + 1)(state, dispatch, editorView);
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
return false;
|
|
96
|
+
}, list);
|
|
97
|
+
bindKeymapWithCommand(backspace.common, (state, dispatch, editorView) => {
|
|
98
|
+
const {
|
|
99
|
+
selection
|
|
100
|
+
} = state;
|
|
101
|
+
const {
|
|
102
|
+
$from
|
|
103
|
+
} = selection;
|
|
104
|
+
if (!editorView || !selection.empty) {
|
|
105
|
+
return false;
|
|
106
|
+
}
|
|
107
|
+
const {
|
|
108
|
+
expand,
|
|
109
|
+
nestedExpand
|
|
110
|
+
} = state.schema.nodes;
|
|
111
|
+
const expandNode = findExpand(state);
|
|
112
|
+
if (!expandNode) {
|
|
113
|
+
// @see ED-7977
|
|
114
|
+
const sel = Selection.findFrom(state.doc.resolve(Math.max(selection.$from.pos - 1, 0)), -1);
|
|
115
|
+
const expandBefore = findExpand(state, sel);
|
|
116
|
+
if (expandBefore && (expandBefore.node.type === expand || expandBefore.node.type === nestedExpand)
|
|
117
|
+
// TO-DO: Bring back expanded logic
|
|
118
|
+
) {
|
|
119
|
+
return focusTitle(expandBefore.start)(state, dispatch, editorView);
|
|
120
|
+
}
|
|
121
|
+
return false;
|
|
122
|
+
}
|
|
123
|
+
const parentNode = state.doc.nodeAt($from.before(Math.max($from.depth - 1, 1)));
|
|
124
|
+
// ED-10012 catch cases where the expand has another node nested within it and
|
|
125
|
+
// the backspace should be applied only to the inner node instead of the expand
|
|
126
|
+
if (parentNode && !isExpandNode(parentNode)) {
|
|
127
|
+
return false;
|
|
128
|
+
}
|
|
129
|
+
const textSel = Selection.findFrom(state.doc.resolve(expandNode.pos), 1, true);
|
|
130
|
+
if (textSel && selection.$from.pos === textSel.$from.pos && isEmptyNode(state.schema)(expandNode.node) && dispatch) {
|
|
131
|
+
var _api$analytics;
|
|
132
|
+
return deleteExpand(api === null || api === void 0 ? void 0 : (_api$analytics = api.analytics) === null || _api$analytics === void 0 ? void 0 : _api$analytics.actions)(state, dispatch);
|
|
133
|
+
}
|
|
134
|
+
return false;
|
|
135
|
+
}, list);
|
|
136
|
+
return keymap(list);
|
|
137
|
+
}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import { SafePlugin } from '@atlaskit/editor-common/safe-plugin';
|
|
2
|
+
import { createSelectionClickHandler } from '@atlaskit/editor-common/selection';
|
|
3
|
+
import { expandClassNames } from '@atlaskit/editor-common/styles';
|
|
4
|
+
import { PluginKey } from '@atlaskit/editor-prosemirror/state';
|
|
5
|
+
import ExpandNodeView from '../node-views';
|
|
6
|
+
export const pluginKey = new PluginKey('expandPlugin');
|
|
7
|
+
export function containsClass(element, className) {
|
|
8
|
+
var _element$classList;
|
|
9
|
+
return Boolean(element === null || element === void 0 ? void 0 : (_element$classList = element.classList) === null || _element$classList === void 0 ? void 0 : _element$classList.contains(className));
|
|
10
|
+
}
|
|
11
|
+
export const createPlugin = (dispatch, getIntl, appearance = 'full-page', useLongPressSelection = false, api, allowInteractiveExpand = true, __livePage = false) => {
|
|
12
|
+
const isMobile = appearance === 'mobile';
|
|
13
|
+
return new SafePlugin({
|
|
14
|
+
key: pluginKey,
|
|
15
|
+
props: {
|
|
16
|
+
nodeViews: {
|
|
17
|
+
expand: ExpandNodeView({
|
|
18
|
+
getIntl,
|
|
19
|
+
isMobile,
|
|
20
|
+
api,
|
|
21
|
+
allowInteractiveExpand,
|
|
22
|
+
__livePage
|
|
23
|
+
}),
|
|
24
|
+
nestedExpand: ExpandNodeView({
|
|
25
|
+
getIntl,
|
|
26
|
+
isMobile,
|
|
27
|
+
api,
|
|
28
|
+
allowInteractiveExpand,
|
|
29
|
+
__livePage
|
|
30
|
+
})
|
|
31
|
+
},
|
|
32
|
+
handleKeyDown(_view, event) {
|
|
33
|
+
return containsClass(event.target, expandClassNames.titleContainer);
|
|
34
|
+
},
|
|
35
|
+
handleKeyPress(_view, event) {
|
|
36
|
+
return containsClass(event.target, expandClassNames.titleContainer);
|
|
37
|
+
},
|
|
38
|
+
handleScrollToSelection() {
|
|
39
|
+
return containsClass(document.activeElement, expandClassNames.titleInput);
|
|
40
|
+
},
|
|
41
|
+
handleClickOn: createSelectionClickHandler(['expand', 'nestedExpand'], target => target.classList.contains(expandClassNames.prefix), {
|
|
42
|
+
useLongPressSelection
|
|
43
|
+
})
|
|
44
|
+
},
|
|
45
|
+
// @see ED-8027 to follow up on this work-around
|
|
46
|
+
filterTransaction(tr) {
|
|
47
|
+
if (containsClass(document.activeElement, expandClassNames.titleInput) && tr.selectionSet && (!tr.steps.length || tr.isGeneric)) {
|
|
48
|
+
return false;
|
|
49
|
+
}
|
|
50
|
+
return true;
|
|
51
|
+
}
|
|
52
|
+
});
|
|
53
|
+
};
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import commonMessages from '@atlaskit/editor-common/messages';
|
|
2
|
+
import { findDomRefAtPos } from '@atlaskit/editor-prosemirror/utils';
|
|
3
|
+
import RemoveIcon from '@atlaskit/icon/glyph/editor/remove';
|
|
4
|
+
import { deleteExpand } from './commands';
|
|
5
|
+
import { findParentExpandNode } from './utils';
|
|
6
|
+
export const getToolbarConfig = api => (state, {
|
|
7
|
+
formatMessage
|
|
8
|
+
}) => {
|
|
9
|
+
var _api$decorations$acti, _api$decorations, _api$analytics;
|
|
10
|
+
const {
|
|
11
|
+
hoverDecoration
|
|
12
|
+
} = (_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 : {};
|
|
13
|
+
const editorAnalyticsAPI = api === null || api === void 0 ? void 0 : (_api$analytics = api.analytics) === null || _api$analytics === void 0 ? void 0 : _api$analytics.actions;
|
|
14
|
+
const selectedExpandNode = findParentExpandNode(state);
|
|
15
|
+
if (selectedExpandNode) {
|
|
16
|
+
const {
|
|
17
|
+
nestedExpand,
|
|
18
|
+
expand
|
|
19
|
+
} = state.schema.nodes;
|
|
20
|
+
return {
|
|
21
|
+
title: 'Expand toolbar',
|
|
22
|
+
getDomRef: view => findDomRefAtPos(selectedExpandNode.pos, view.domAtPos.bind(view)),
|
|
23
|
+
nodeType: [nestedExpand, expand],
|
|
24
|
+
offset: [0, 6],
|
|
25
|
+
items: [{
|
|
26
|
+
type: 'copy-button',
|
|
27
|
+
items: [{
|
|
28
|
+
state,
|
|
29
|
+
formatMessage,
|
|
30
|
+
nodeType: [nestedExpand, expand]
|
|
31
|
+
}, {
|
|
32
|
+
type: 'separator'
|
|
33
|
+
}]
|
|
34
|
+
}, {
|
|
35
|
+
id: 'editor.expand.delete',
|
|
36
|
+
type: 'button',
|
|
37
|
+
appearance: 'danger',
|
|
38
|
+
focusEditoronEnter: true,
|
|
39
|
+
icon: RemoveIcon,
|
|
40
|
+
onClick: deleteExpand(editorAnalyticsAPI),
|
|
41
|
+
onMouseEnter: hoverDecoration === null || hoverDecoration === void 0 ? void 0 : hoverDecoration([nestedExpand, expand], true),
|
|
42
|
+
onMouseLeave: hoverDecoration === null || hoverDecoration === void 0 ? void 0 : hoverDecoration([nestedExpand, expand], false),
|
|
43
|
+
onFocus: hoverDecoration === null || hoverDecoration === void 0 ? void 0 : hoverDecoration([nestedExpand, expand], true),
|
|
44
|
+
onBlur: hoverDecoration === null || hoverDecoration === void 0 ? void 0 : hoverDecoration([nestedExpand, expand], false),
|
|
45
|
+
title: formatMessage(commonMessages.remove),
|
|
46
|
+
tabIndex: null
|
|
47
|
+
}]
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
return;
|
|
51
|
+
};
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
import _extends from "@babel/runtime/helpers/extends";
|
|
2
|
+
/** @jsx jsx */
|
|
3
|
+
import React, { useCallback } from 'react';
|
|
4
|
+
import { jsx } from '@emotion/react';
|
|
5
|
+
import Button from '@atlaskit/button/custom-theme-button';
|
|
6
|
+
import { expandClassNames } from '@atlaskit/editor-common/styles';
|
|
7
|
+
import { expandLayoutWrapperStyle, ExpandLayoutWrapperWithRef, expandMessages } from '@atlaskit/editor-common/ui';
|
|
8
|
+
import { akEditorSwoopCubicBezier } from '@atlaskit/editor-shared-styles';
|
|
9
|
+
import ChevronRightIcon from '@atlaskit/icon/glyph/chevron-right';
|
|
10
|
+
import Tooltip from '@atlaskit/tooltip';
|
|
11
|
+
function withTooltip(Component) {
|
|
12
|
+
return function WithTooltip(props) {
|
|
13
|
+
return jsx(Tooltip, {
|
|
14
|
+
content: props.label,
|
|
15
|
+
position: "top",
|
|
16
|
+
tag: ExpandLayoutWrapperWithRef
|
|
17
|
+
}, jsx(Component, props));
|
|
18
|
+
};
|
|
19
|
+
}
|
|
20
|
+
export const ExpandButtonInner = props => {
|
|
21
|
+
const useTheme = useCallback((currentTheme, themeProps) => {
|
|
22
|
+
const {
|
|
23
|
+
buttonStyles,
|
|
24
|
+
...rest
|
|
25
|
+
} = currentTheme(themeProps);
|
|
26
|
+
return {
|
|
27
|
+
buttonStyles: {
|
|
28
|
+
...buttonStyles,
|
|
29
|
+
height: '100%',
|
|
30
|
+
'& svg': {
|
|
31
|
+
transform: props.expanded ? 'transform: rotate(90deg);' : 'transform: rotate(0deg);',
|
|
32
|
+
transition: `transform 0.2s ${akEditorSwoopCubicBezier};`
|
|
33
|
+
}
|
|
34
|
+
},
|
|
35
|
+
...rest
|
|
36
|
+
};
|
|
37
|
+
}, [props]);
|
|
38
|
+
return jsx(Button, {
|
|
39
|
+
appearance: "subtle",
|
|
40
|
+
className: expandClassNames.iconContainer,
|
|
41
|
+
iconBefore: jsx(ChevronRightIcon, {
|
|
42
|
+
label: ''
|
|
43
|
+
}),
|
|
44
|
+
shouldFitContainer: true,
|
|
45
|
+
theme: useTheme,
|
|
46
|
+
"aria-expanded": props.expanded,
|
|
47
|
+
isDisabled: !props.allowInteractiveExpand
|
|
48
|
+
});
|
|
49
|
+
};
|
|
50
|
+
const ButtonWithTooltip = withTooltip(ExpandButtonInner);
|
|
51
|
+
const ButtonWithoutTooltip = ExpandButtonInner;
|
|
52
|
+
export const ExpandButton = props => {
|
|
53
|
+
const {
|
|
54
|
+
expanded,
|
|
55
|
+
intl
|
|
56
|
+
} = props;
|
|
57
|
+
const message = expanded ? expandMessages.collapseNode : expandMessages.expandNode;
|
|
58
|
+
const label = intl && intl.formatMessage(message) || message.defaultMessage;
|
|
59
|
+
// check to ensure device supports any-hover
|
|
60
|
+
const supportsAnyHover = !!window.matchMedia ? window.matchMedia('(any-hover: hover)').matches !== window.matchMedia('(any-hover: none)').matches : false;
|
|
61
|
+
const hoverEventCheck = supportsAnyHover ? window.matchMedia('(any-hover: hover)').matches : true;
|
|
62
|
+
|
|
63
|
+
// hoverEventCheck is to disable tooltips for mobile to prevent incorrect hover state causing issues on iOS
|
|
64
|
+
if (props.allowInteractiveExpand && hoverEventCheck) {
|
|
65
|
+
return jsx(ButtonWithTooltip, _extends({
|
|
66
|
+
label: label
|
|
67
|
+
}, props));
|
|
68
|
+
}
|
|
69
|
+
return (
|
|
70
|
+
// eslint-disable-next-line @atlaskit/design-system/consistent-css-prop-usage
|
|
71
|
+
jsx("div", {
|
|
72
|
+
css: expandLayoutWrapperStyle
|
|
73
|
+
}, jsx(ButtonWithoutTooltip, _extends({
|
|
74
|
+
label: label
|
|
75
|
+
}, props)))
|
|
76
|
+
);
|
|
77
|
+
};
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import ReactDOM from 'react-dom';
|
|
3
|
+
import { expandClassNames } from '@atlaskit/editor-common/styles';
|
|
4
|
+
import { expandMessages } from '@atlaskit/editor-common/ui';
|
|
5
|
+
import { ExpandButton } from '../ui/ExpandButton';
|
|
6
|
+
|
|
7
|
+
// TODO: https://product-fabric.atlassian.net/browse/ED-22841
|
|
8
|
+
export const buildExpandClassName = type => {
|
|
9
|
+
return `${expandClassNames.prefix} ${expandClassNames.type(type)}
|
|
10
|
+
${expandClassNames.expanded}`;
|
|
11
|
+
};
|
|
12
|
+
export const toDOM = (node, __livePage, intl) => ['div', {
|
|
13
|
+
// prettier-ignore
|
|
14
|
+
'class': buildExpandClassName(node.type.name),
|
|
15
|
+
'data-node-type': node.type.name,
|
|
16
|
+
'data-title': node.attrs.title
|
|
17
|
+
}, ['div', {
|
|
18
|
+
// prettier-ignore
|
|
19
|
+
'class': expandClassNames.titleContainer,
|
|
20
|
+
contenteditable: 'false',
|
|
21
|
+
// Element gains access to focus events.
|
|
22
|
+
// This is needed to prevent PM gaining access
|
|
23
|
+
// on interacting with our controls.
|
|
24
|
+
tabindex: '-1'
|
|
25
|
+
},
|
|
26
|
+
// prettier-ignore
|
|
27
|
+
['div', {
|
|
28
|
+
'class': expandClassNames.icon
|
|
29
|
+
}], ['div', {
|
|
30
|
+
// prettier-ignore
|
|
31
|
+
'class': expandClassNames.inputContainer
|
|
32
|
+
}, ['input', {
|
|
33
|
+
// prettier-ignore
|
|
34
|
+
'class': expandClassNames.titleInput,
|
|
35
|
+
value: node.attrs.title,
|
|
36
|
+
placeholder: intl && intl.formatMessage(expandMessages.expandPlaceholderText) || expandMessages.expandPlaceholderText.defaultMessage,
|
|
37
|
+
type: 'text'
|
|
38
|
+
}]]],
|
|
39
|
+
// prettier-ignore
|
|
40
|
+
['div', {
|
|
41
|
+
'class': expandClassNames.content
|
|
42
|
+
}, 0]];
|
|
43
|
+
export const renderIcon = (icon, allowInteractiveExpand, intl, node) => {
|
|
44
|
+
if (!icon) {
|
|
45
|
+
return;
|
|
46
|
+
}
|
|
47
|
+
ReactDOM.render( /*#__PURE__*/React.createElement(ExpandButton, {
|
|
48
|
+
intl: intl,
|
|
49
|
+
allowInteractiveExpand: allowInteractiveExpand,
|
|
50
|
+
expanded: true // TO-DO https://product-fabric.atlassian.net/browse/ED-22841
|
|
51
|
+
}), icon);
|
|
52
|
+
};
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { findParentNodeOfType } from '@atlaskit/editor-prosemirror/utils';
|
|
2
|
+
export { findExpand, transformSliceToRemoveOpenExpand, transformSliceToRemoveOpenNestedExpand, transformSliceNestedExpandToExpand } from '@atlaskit/editor-common/transforms';
|
|
3
|
+
export const findParentExpandNode = state => {
|
|
4
|
+
return findParentNodeOfType(state.schema.nodes.expand)(state.selection) || findParentNodeOfType(state.schema.nodes.nestedExpand)(state.selection);
|
|
5
|
+
};
|
package/dist/esm/index.js
CHANGED
|
@@ -16,7 +16,7 @@ import { ExpandIconButton } from '../ui/ExpandIconButton';
|
|
|
16
16
|
function buildExpandClassName(type, expanded) {
|
|
17
17
|
return "".concat(expandClassNames.prefix, " ").concat(expandClassNames.type(type), " ").concat(expanded ? expandClassNames.expanded : '');
|
|
18
18
|
}
|
|
19
|
-
var toDOM = function toDOM(node, __livePage, intl) {
|
|
19
|
+
var toDOM = function toDOM(node, __livePage, intl, editable) {
|
|
20
20
|
return ['div', {
|
|
21
21
|
// prettier-ignore
|
|
22
22
|
'class': buildExpandClassName(node.type.name, getBooleanFF('platform.editor.live-pages-expand-divergence') && __livePage ? !node.attrs.__expanded : node.attrs.__expanded),
|
|
@@ -42,11 +42,13 @@ var toDOM = function toDOM(node, __livePage, intl) {
|
|
|
42
42
|
'class': expandClassNames.titleInput,
|
|
43
43
|
value: node.attrs.title,
|
|
44
44
|
placeholder: intl && intl.formatMessage(expandMessages.expandPlaceholderText) || expandMessages.expandPlaceholderText.defaultMessage,
|
|
45
|
-
type: 'text'
|
|
45
|
+
type: 'text',
|
|
46
|
+
readonly: !editable ? 'true' : undefined
|
|
46
47
|
}]]],
|
|
47
48
|
// prettier-ignore
|
|
48
49
|
['div', {
|
|
49
|
-
'class': expandClassNames.content
|
|
50
|
+
'class': expandClassNames.content,
|
|
51
|
+
contenteditable: editable
|
|
50
52
|
}, 0]];
|
|
51
53
|
};
|
|
52
54
|
export var ExpandNodeView = /*#__PURE__*/function () {
|
|
@@ -353,7 +355,7 @@ export var ExpandNodeView = /*#__PURE__*/function () {
|
|
|
353
355
|
this.selectNearNode = selectNearNode;
|
|
354
356
|
this.__livePage = __livePage;
|
|
355
357
|
this.intl = getIntl();
|
|
356
|
-
var _DOMSerializer$render = DOMSerializer.renderSpec(document, toDOM(node, this.__livePage, this.intl)),
|
|
358
|
+
var _DOMSerializer$render = DOMSerializer.renderSpec(document, toDOM(node, this.__livePage, this.intl, view.editable)),
|
|
357
359
|
dom = _DOMSerializer$render.dom,
|
|
358
360
|
contentDOM = _DOMSerializer$render.contentDOM;
|
|
359
361
|
this.allowInteractiveExpand = allowInteractiveExpand;
|
|
@@ -442,7 +444,18 @@ export var ExpandNodeView = /*#__PURE__*/function () {
|
|
|
442
444
|
}
|
|
443
445
|
if (this.content) {
|
|
444
446
|
// Disallow interaction/selection inside when collapsed.
|
|
445
|
-
this.content.setAttribute('contenteditable', getBooleanFF('platform.editor.live-pages-expand-divergence') && this.__livePage ? !node.attrs.__expanded : node.attrs.__expanded);
|
|
447
|
+
this.content.setAttribute('contenteditable', this.view.editable && (getBooleanFF('platform.editor.live-pages-expand-divergence') && this.__livePage ? !node.attrs.__expanded : node.attrs.__expanded));
|
|
448
|
+
}
|
|
449
|
+
} else {
|
|
450
|
+
if (this.content) {
|
|
451
|
+
this.content.setAttribute('contenteditable', this.view.editable ? 'true' : 'false');
|
|
452
|
+
}
|
|
453
|
+
}
|
|
454
|
+
if (this.input) {
|
|
455
|
+
if (!this.view.editable) {
|
|
456
|
+
this.input.setAttribute('readonly', 'true');
|
|
457
|
+
} else {
|
|
458
|
+
this.input.removeAttribute('readonly');
|
|
446
459
|
}
|
|
447
460
|
}
|
|
448
461
|
|
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
import { backspace, bindKeymapWithCommand, moveDown, moveLeft, moveRight, moveUp, tab } from '@atlaskit/editor-common/keymaps';
|
|
2
2
|
import { GapCursorSelection, RelativeSelectionPos, Side } from '@atlaskit/editor-common/selection';
|
|
3
3
|
import { expandClassNames } from '@atlaskit/editor-common/styles';
|
|
4
|
-
import { isPositionNearTableRow } from '@atlaskit/editor-common/utils';
|
|
5
|
-
import { isEmptyNode } from '@atlaskit/editor-common/utils';
|
|
4
|
+
import { isEmptyNode, isPositionNearTableRow } from '@atlaskit/editor-common/utils';
|
|
6
5
|
import { keymap } from '@atlaskit/editor-prosemirror/keymap';
|
|
7
6
|
import { NodeSelection, Selection, TextSelection } from '@atlaskit/editor-prosemirror/state';
|
|
8
7
|
import { getBooleanFF } from '@atlaskit/platform-feature-flags';
|
|
@@ -0,0 +1,128 @@
|
|
|
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 { SetAttrsStep } from '@atlaskit/adf-schema/steps';
|
|
5
|
+
import { ACTION, ACTION_SUBJECT, ACTION_SUBJECT_ID, EVENT_TYPE, INPUT_METHOD } from '@atlaskit/editor-common/analytics';
|
|
6
|
+
import { findExpand } from '@atlaskit/editor-common/transforms';
|
|
7
|
+
import { createWrapSelectionTransaction } from '@atlaskit/editor-common/utils';
|
|
8
|
+
import { Selection } from '@atlaskit/editor-prosemirror/state';
|
|
9
|
+
import { safeInsert } from '@atlaskit/editor-prosemirror/utils';
|
|
10
|
+
import { findTable } from '@atlaskit/editor-tables/utils';
|
|
11
|
+
|
|
12
|
+
// Creates either an expand or a nestedExpand node based on the current selection
|
|
13
|
+
export var createExpandNode = function createExpandNode(state) {
|
|
14
|
+
var _state$schema$nodes = state.schema.nodes,
|
|
15
|
+
expand = _state$schema$nodes.expand,
|
|
16
|
+
nestedExpand = _state$schema$nodes.nestedExpand;
|
|
17
|
+
var expandType = findTable(state.selection) ? nestedExpand : expand;
|
|
18
|
+
return expandType.createAndFill({});
|
|
19
|
+
};
|
|
20
|
+
export var insertExpand = function insertExpand(editorAnalyticsAPI) {
|
|
21
|
+
return function (state, dispatch) {
|
|
22
|
+
var expandNode = createExpandNode(state);
|
|
23
|
+
if (!expandNode) {
|
|
24
|
+
return false;
|
|
25
|
+
}
|
|
26
|
+
var tr = state.selection.empty ? safeInsert(expandNode)(state.tr).scrollIntoView() : createWrapSelectionTransaction({
|
|
27
|
+
state: state,
|
|
28
|
+
type: expandNode.type
|
|
29
|
+
});
|
|
30
|
+
var payload = {
|
|
31
|
+
action: ACTION.INSERTED,
|
|
32
|
+
actionSubject: ACTION_SUBJECT.DOCUMENT,
|
|
33
|
+
actionSubjectId: (expandNode === null || expandNode === void 0 ? void 0 : expandNode.type) === state.schema.nodes.expand ? ACTION_SUBJECT_ID.EXPAND : ACTION_SUBJECT_ID.NESTED_EXPAND,
|
|
34
|
+
attributes: {
|
|
35
|
+
inputMethod: INPUT_METHOD.INSERT_MENU
|
|
36
|
+
},
|
|
37
|
+
eventType: EVENT_TYPE.TRACK
|
|
38
|
+
};
|
|
39
|
+
if (dispatch && expandNode) {
|
|
40
|
+
editorAnalyticsAPI === null || editorAnalyticsAPI === void 0 || editorAnalyticsAPI.attachAnalyticsEvent(payload)(tr);
|
|
41
|
+
dispatch(tr);
|
|
42
|
+
}
|
|
43
|
+
return true;
|
|
44
|
+
};
|
|
45
|
+
};
|
|
46
|
+
export var deleteExpand = function deleteExpand(editorAnalyticsAPI) {
|
|
47
|
+
return function (state, dispatch) {
|
|
48
|
+
var expandNode = findExpand(state);
|
|
49
|
+
if (!expandNode) {
|
|
50
|
+
return false;
|
|
51
|
+
}
|
|
52
|
+
return deleteExpandAtPos(editorAnalyticsAPI)(expandNode.pos, expandNode.node)(state, dispatch);
|
|
53
|
+
};
|
|
54
|
+
};
|
|
55
|
+
export var deleteExpandAtPos = function deleteExpandAtPos(editorAnalyticsAPI) {
|
|
56
|
+
return function (expandNodePos, expandNode) {
|
|
57
|
+
return function (state, dispatch) {
|
|
58
|
+
if (!expandNode || isNaN(expandNodePos)) {
|
|
59
|
+
return false;
|
|
60
|
+
}
|
|
61
|
+
var payload = {
|
|
62
|
+
action: ACTION.DELETED,
|
|
63
|
+
actionSubject: expandNode.type === state.schema.nodes.expand ? ACTION_SUBJECT.EXPAND : ACTION_SUBJECT.NESTED_EXPAND,
|
|
64
|
+
attributes: {
|
|
65
|
+
inputMethod: INPUT_METHOD.TOOLBAR
|
|
66
|
+
},
|
|
67
|
+
eventType: EVENT_TYPE.TRACK
|
|
68
|
+
};
|
|
69
|
+
if (expandNode && dispatch) {
|
|
70
|
+
var tr = state.tr;
|
|
71
|
+
tr.delete(expandNodePos, expandNodePos + expandNode.nodeSize);
|
|
72
|
+
editorAnalyticsAPI === null || editorAnalyticsAPI === void 0 || editorAnalyticsAPI.attachAnalyticsEvent(payload)(tr);
|
|
73
|
+
dispatch(tr);
|
|
74
|
+
}
|
|
75
|
+
return true;
|
|
76
|
+
};
|
|
77
|
+
};
|
|
78
|
+
};
|
|
79
|
+
|
|
80
|
+
// Used to clear any node or cell selection when expand title is focused
|
|
81
|
+
export var setSelectionInsideExpand = function setSelectionInsideExpand(expandPos) {
|
|
82
|
+
return function (state, dispatch, editorView) {
|
|
83
|
+
if (editorView) {
|
|
84
|
+
if (!editorView.hasFocus()) {
|
|
85
|
+
editorView.focus();
|
|
86
|
+
}
|
|
87
|
+
var sel = Selection.findFrom(editorView.state.doc.resolve(expandPos), 1, true);
|
|
88
|
+
if (sel && dispatch) {
|
|
89
|
+
dispatch(editorView.state.tr.setSelection(sel));
|
|
90
|
+
}
|
|
91
|
+
return true;
|
|
92
|
+
}
|
|
93
|
+
return false;
|
|
94
|
+
};
|
|
95
|
+
};
|
|
96
|
+
export var updateExpandTitle = function updateExpandTitle(_ref) {
|
|
97
|
+
var title = _ref.title,
|
|
98
|
+
nodeType = _ref.nodeType,
|
|
99
|
+
pos = _ref.pos;
|
|
100
|
+
return function (state, dispatch) {
|
|
101
|
+
var node = state.doc.nodeAt(pos);
|
|
102
|
+
if (node && node.type === nodeType && dispatch) {
|
|
103
|
+
var tr = state.tr;
|
|
104
|
+
tr.step(new SetAttrsStep(pos, _objectSpread(_objectSpread({}, node.attrs), {}, {
|
|
105
|
+
title: title
|
|
106
|
+
})));
|
|
107
|
+
dispatch(tr);
|
|
108
|
+
}
|
|
109
|
+
return true;
|
|
110
|
+
};
|
|
111
|
+
};
|
|
112
|
+
export var focusTitle = function focusTitle(pos) {
|
|
113
|
+
return function (state, dispatch, editorView) {
|
|
114
|
+
if (editorView) {
|
|
115
|
+
var dom = editorView.domAtPos(pos);
|
|
116
|
+
var expandWrapper = dom.node.parentElement;
|
|
117
|
+
if (expandWrapper) {
|
|
118
|
+
setSelectionInsideExpand(pos)(state, dispatch, editorView);
|
|
119
|
+
var input = expandWrapper.querySelector('input');
|
|
120
|
+
if (input) {
|
|
121
|
+
input.focus();
|
|
122
|
+
return true;
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
return false;
|
|
127
|
+
};
|
|
128
|
+
};
|