@atlaskit/editor-plugin-expand 1.3.1 → 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 +6 -0
- 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/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/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 +1 -1
- /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,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
|
@@ -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
|
+
};
|