@atlaskit/editor-plugin-toolbar-lists-indentation 0.1.1 → 0.2.0
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/index.js +8 -1
- package/dist/cjs/plugin.js +90 -0
- package/dist/cjs/pm-plugins/indentation-buttons.js +56 -0
- package/dist/cjs/types.js +5 -0
- package/dist/cjs/ui/Toolbar.js +134 -0
- package/dist/cjs/ui/ToolbarDropdown.js +179 -0
- package/dist/cjs/ui/index.js +63 -0
- package/dist/cjs/ui/onItemActivated.js +53 -0
- package/dist/es2019/index.js +1 -1
- package/dist/es2019/plugin.js +85 -0
- package/dist/es2019/pm-plugins/indentation-buttons.js +53 -0
- package/dist/es2019/types.js +1 -0
- package/dist/es2019/ui/Toolbar.js +125 -0
- package/dist/es2019/ui/ToolbarDropdown.js +168 -0
- package/dist/es2019/ui/index.js +58 -0
- package/dist/es2019/ui/onItemActivated.js +46 -0
- package/dist/esm/index.js +1 -1
- package/dist/esm/plugin.js +82 -0
- package/dist/esm/pm-plugins/indentation-buttons.js +50 -0
- package/dist/esm/types.js +1 -0
- package/dist/esm/ui/Toolbar.js +126 -0
- package/dist/esm/ui/ToolbarDropdown.js +171 -0
- package/dist/esm/ui/index.js +56 -0
- package/dist/esm/ui/onItemActivated.js +47 -0
- package/dist/types/index.d.ts +2 -1
- package/dist/types/plugin.d.ts +31 -0
- package/dist/types/pm-plugins/indentation-buttons.d.ts +19 -0
- package/dist/types/types.d.ts +20 -0
- package/dist/types/ui/Toolbar.d.ts +3 -0
- package/dist/types/ui/ToolbarDropdown.d.ts +8 -0
- package/dist/types/ui/index.d.ts +26 -0
- package/dist/types/ui/onItemActivated.d.ts +9 -0
- package/dist/types-ts4.5/index.d.ts +2 -1
- package/dist/types-ts4.5/plugin.d.ts +31 -0
- package/dist/types-ts4.5/pm-plugins/indentation-buttons.d.ts +19 -0
- package/dist/types-ts4.5/types.d.ts +20 -0
- package/dist/types-ts4.5/ui/Toolbar.d.ts +3 -0
- package/dist/types-ts4.5/ui/ToolbarDropdown.d.ts +8 -0
- package/dist/types-ts4.5/ui/index.d.ts +26 -0
- package/dist/types-ts4.5/ui/onItemActivated.d.ts +9 -0
- package/package.json +19 -6
- package/report.api.md +36 -1
- package/tmp/api-report-tmp.d.ts +31 -0
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,11 @@
|
|
|
1
1
|
# @atlaskit/editor-plugin-toolbar-lists-indentation
|
|
2
2
|
|
|
3
|
+
## 0.2.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- [#43661](https://bitbucket.org/atlassian/atlassian-frontend/pull-requests/43661) [`ebf781502ed`](https://bitbucket.org/atlassian/atlassian-frontend/commits/ebf781502ed) - Extract toolbar-lists-indentation plugin code from editor-core and move into @atlaskit/editor-plugin-toolbar-lists-indentation.
|
|
8
|
+
|
|
3
9
|
## 0.1.1
|
|
4
10
|
|
|
5
11
|
### Patch Changes
|
package/dist/cjs/index.js
CHANGED
|
@@ -2,4 +2,11 @@
|
|
|
2
2
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
|
-
});
|
|
5
|
+
});
|
|
6
|
+
Object.defineProperty(exports, "toolbarListsIndentationPlugin", {
|
|
7
|
+
enumerable: true,
|
|
8
|
+
get: function get() {
|
|
9
|
+
return _plugin.toolbarListsIndentationPlugin;
|
|
10
|
+
}
|
|
11
|
+
});
|
|
12
|
+
var _plugin = require("./plugin");
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
+
Object.defineProperty(exports, "__esModule", {
|
|
5
|
+
value: true
|
|
6
|
+
});
|
|
7
|
+
exports.PrimaryToolbarComponent = PrimaryToolbarComponent;
|
|
8
|
+
exports.toolbarListsIndentationPlugin = void 0;
|
|
9
|
+
var _react = _interopRequireDefault(require("react"));
|
|
10
|
+
var _hooks = require("@atlaskit/editor-common/hooks");
|
|
11
|
+
var _types = require("@atlaskit/editor-common/types");
|
|
12
|
+
var _indentationButtons = require("./pm-plugins/indentation-buttons");
|
|
13
|
+
var _ui = _interopRequireDefault(require("./ui"));
|
|
14
|
+
var toolbarListsIndentationPlugin = exports.toolbarListsIndentationPlugin = function toolbarListsIndentationPlugin(_ref) {
|
|
15
|
+
var _api$featureFlags;
|
|
16
|
+
var config = _ref.config,
|
|
17
|
+
api = _ref.api;
|
|
18
|
+
var _ref2 = config !== null && config !== void 0 ? config : {},
|
|
19
|
+
_ref2$showIndentation = _ref2.showIndentationButtons,
|
|
20
|
+
showIndentationButtons = _ref2$showIndentation === void 0 ? false : _ref2$showIndentation,
|
|
21
|
+
_ref2$allowHeadingAnd = _ref2.allowHeadingAndParagraphIndentation,
|
|
22
|
+
allowHeadingAndParagraphIndentation = _ref2$allowHeadingAnd === void 0 ? false : _ref2$allowHeadingAnd;
|
|
23
|
+
var featureFlags = (api === null || api === void 0 || (_api$featureFlags = api.featureFlags) === null || _api$featureFlags === void 0 ? void 0 : _api$featureFlags.sharedState.currentState()) || {};
|
|
24
|
+
return {
|
|
25
|
+
name: 'toolbarListsIndentation',
|
|
26
|
+
primaryToolbarComponent: function primaryToolbarComponent(_ref3) {
|
|
27
|
+
var editorView = _ref3.editorView,
|
|
28
|
+
popupsMountPoint = _ref3.popupsMountPoint,
|
|
29
|
+
popupsBoundariesElement = _ref3.popupsBoundariesElement,
|
|
30
|
+
popupsScrollableElement = _ref3.popupsScrollableElement,
|
|
31
|
+
toolbarSize = _ref3.toolbarSize,
|
|
32
|
+
disabled = _ref3.disabled,
|
|
33
|
+
isToolbarReducedSpacing = _ref3.isToolbarReducedSpacing;
|
|
34
|
+
var isSmall = toolbarSize < _types.ToolbarSize.L;
|
|
35
|
+
return /*#__PURE__*/_react.default.createElement(PrimaryToolbarComponent, {
|
|
36
|
+
featureFlags: featureFlags,
|
|
37
|
+
popupsMountPoint: popupsMountPoint,
|
|
38
|
+
popupsBoundariesElement: popupsBoundariesElement,
|
|
39
|
+
popupsScrollableElement: popupsScrollableElement,
|
|
40
|
+
isSmall: isSmall,
|
|
41
|
+
isToolbarReducedSpacing: isToolbarReducedSpacing,
|
|
42
|
+
disabled: disabled,
|
|
43
|
+
editorView: editorView,
|
|
44
|
+
showIndentationButtons: showIndentationButtons,
|
|
45
|
+
pluginInjectionApi: api,
|
|
46
|
+
allowHeadingAndParagraphIndentation: allowHeadingAndParagraphIndentation
|
|
47
|
+
});
|
|
48
|
+
}
|
|
49
|
+
};
|
|
50
|
+
};
|
|
51
|
+
function PrimaryToolbarComponent(_ref4) {
|
|
52
|
+
var featureFlags = _ref4.featureFlags,
|
|
53
|
+
popupsMountPoint = _ref4.popupsMountPoint,
|
|
54
|
+
popupsBoundariesElement = _ref4.popupsBoundariesElement,
|
|
55
|
+
popupsScrollableElement = _ref4.popupsScrollableElement,
|
|
56
|
+
isSmall = _ref4.isSmall,
|
|
57
|
+
isToolbarReducedSpacing = _ref4.isToolbarReducedSpacing,
|
|
58
|
+
disabled = _ref4.disabled,
|
|
59
|
+
editorView = _ref4.editorView,
|
|
60
|
+
showIndentationButtons = _ref4.showIndentationButtons,
|
|
61
|
+
pluginInjectionApi = _ref4.pluginInjectionApi,
|
|
62
|
+
allowHeadingAndParagraphIndentation = _ref4.allowHeadingAndParagraphIndentation;
|
|
63
|
+
var _useSharedPluginState = (0, _hooks.useSharedPluginState)(pluginInjectionApi, ['list', 'indentation', 'taskDecision']),
|
|
64
|
+
listState = _useSharedPluginState.listState,
|
|
65
|
+
indentationState = _useSharedPluginState.indentationState,
|
|
66
|
+
taskDecisionState = _useSharedPluginState.taskDecisionState;
|
|
67
|
+
var toolbarListsIndentationState = (0, _indentationButtons.getIndentationButtonsState)(editorView.state, allowHeadingAndParagraphIndentation, taskDecisionState, indentationState, pluginInjectionApi === null || pluginInjectionApi === void 0 ? void 0 : pluginInjectionApi.list.actions.isInsideListItem);
|
|
68
|
+
if (!listState) {
|
|
69
|
+
return null;
|
|
70
|
+
}
|
|
71
|
+
return /*#__PURE__*/_react.default.createElement(_ui.default, {
|
|
72
|
+
featureFlags: featureFlags,
|
|
73
|
+
isSmall: isSmall,
|
|
74
|
+
isReducedSpacing: isToolbarReducedSpacing,
|
|
75
|
+
disabled: disabled,
|
|
76
|
+
editorView: editorView,
|
|
77
|
+
popupsMountPoint: popupsMountPoint,
|
|
78
|
+
popupsBoundariesElement: popupsBoundariesElement,
|
|
79
|
+
popupsScrollableElement: popupsScrollableElement,
|
|
80
|
+
bulletListActive: listState.bulletListActive,
|
|
81
|
+
bulletListDisabled: listState.bulletListDisabled,
|
|
82
|
+
orderedListActive: listState.orderedListActive,
|
|
83
|
+
orderedListDisabled: listState.orderedListDisabled,
|
|
84
|
+
showIndentationButtons: !!showIndentationButtons,
|
|
85
|
+
indentDisabled: toolbarListsIndentationState.indentDisabled,
|
|
86
|
+
outdentDisabled: toolbarListsIndentationState.outdentDisabled,
|
|
87
|
+
indentationStateNode: toolbarListsIndentationState === null || toolbarListsIndentationState === void 0 ? void 0 : toolbarListsIndentationState.node,
|
|
88
|
+
pluginInjectionApi: pluginInjectionApi
|
|
89
|
+
});
|
|
90
|
+
}
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.getIndentationButtonsState = getIndentationButtonsState;
|
|
7
|
+
var _indentation = require("@atlaskit/editor-common/indentation");
|
|
8
|
+
var _lists = require("@atlaskit/editor-common/lists");
|
|
9
|
+
var _utils = require("@atlaskit/editor-prosemirror/utils");
|
|
10
|
+
function getIndentationButtonsState(editorState, allowHeadingAndParagraphIndentation, taskDecisionState, indentationState, isInsideListItem) {
|
|
11
|
+
var _indentationState$isI;
|
|
12
|
+
var state = {
|
|
13
|
+
indentDisabled: true,
|
|
14
|
+
outdentDisabled: true,
|
|
15
|
+
node: null
|
|
16
|
+
};
|
|
17
|
+
var selection = editorState.selection;
|
|
18
|
+
|
|
19
|
+
// Handle bullet and numbered lists seperately as they do
|
|
20
|
+
// not use the indentation mark.
|
|
21
|
+
// Check for lists before paragraphs and headings in case
|
|
22
|
+
// the selection is in a list nested in a layout column.
|
|
23
|
+
if (isInsideListItem !== null && isInsideListItem !== void 0 && isInsideListItem(editorState.tr)) {
|
|
24
|
+
var _getListItemAttribute = (0, _lists.getListItemAttributes)(selection.$head),
|
|
25
|
+
indentLevel = _getListItemAttribute.indentLevel,
|
|
26
|
+
itemIndex = _getListItemAttribute.itemIndex;
|
|
27
|
+
return {
|
|
28
|
+
// List indent levels are zero indexed so we need to subtract 1
|
|
29
|
+
indentDisabled: itemIndex === 0 || indentLevel >= _indentation.MAX_INDENTATION_LEVEL - 1,
|
|
30
|
+
outdentDisabled: false,
|
|
31
|
+
node: 'list'
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
// Handle tasks seperately as they do not use the indentation mark
|
|
36
|
+
// and have different behaviour for outdent compared to lists
|
|
37
|
+
if (taskDecisionState !== null && taskDecisionState !== void 0 && taskDecisionState.isInsideTask) {
|
|
38
|
+
return {
|
|
39
|
+
indentDisabled: taskDecisionState.indentDisabled,
|
|
40
|
+
outdentDisabled: taskDecisionState.outdentDisabled,
|
|
41
|
+
node: 'taskList'
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
var isTopLevelParagraphOrHeading = selection.$from.depth === 1;
|
|
45
|
+
var isInLayoutNode = (0, _utils.hasParentNodeOfType)(editorState.schema.nodes.layoutColumn)(selection) &&
|
|
46
|
+
// depth of non-nested paragraphs and headings in layouts will always be 3
|
|
47
|
+
selection.$from.depth === 3;
|
|
48
|
+
if (allowHeadingAndParagraphIndentation && ((_indentationState$isI = indentationState === null || indentationState === void 0 ? void 0 : indentationState.isIndentationAllowed) !== null && _indentationState$isI !== void 0 ? _indentationState$isI : false) && (isTopLevelParagraphOrHeading || isInLayoutNode) && indentationState) {
|
|
49
|
+
return {
|
|
50
|
+
indentDisabled: indentationState.indentDisabled,
|
|
51
|
+
outdentDisabled: indentationState.outdentDisabled,
|
|
52
|
+
node: 'paragraph_heading'
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
return state;
|
|
56
|
+
}
|
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
+
Object.defineProperty(exports, "__esModule", {
|
|
5
|
+
value: true
|
|
6
|
+
});
|
|
7
|
+
exports.Toolbar = Toolbar;
|
|
8
|
+
var _react = require("react");
|
|
9
|
+
var _react2 = require("@emotion/react");
|
|
10
|
+
var _reactIntlNext = require("react-intl-next");
|
|
11
|
+
var _keymaps = require("@atlaskit/editor-common/keymaps");
|
|
12
|
+
var _messages = require("@atlaskit/editor-common/messages");
|
|
13
|
+
var _styles = require("@atlaskit/editor-common/styles");
|
|
14
|
+
var _uiMenu = require("@atlaskit/editor-common/ui-menu");
|
|
15
|
+
var _bulletList = _interopRequireDefault(require("@atlaskit/icon/glyph/editor/bullet-list"));
|
|
16
|
+
var _indent = _interopRequireDefault(require("@atlaskit/icon/glyph/editor/indent"));
|
|
17
|
+
var _numberList = _interopRequireDefault(require("@atlaskit/icon/glyph/editor/number-list"));
|
|
18
|
+
var _outdent = _interopRequireDefault(require("@atlaskit/icon/glyph/editor/outdent"));
|
|
19
|
+
/** @jsx jsx */
|
|
20
|
+
|
|
21
|
+
function Toolbar(props) {
|
|
22
|
+
var _useIntl = (0, _reactIntlNext.useIntl)(),
|
|
23
|
+
formatMessage = _useIntl.formatMessage;
|
|
24
|
+
var indentButtonRef = (0, _react.useRef)(null);
|
|
25
|
+
var outdentButtonRef = (0, _react.useRef)(null);
|
|
26
|
+
var disabled = props.disabled,
|
|
27
|
+
isReducedSpacing = props.isReducedSpacing,
|
|
28
|
+
bulletListActive = props.bulletListActive,
|
|
29
|
+
bulletListDisabled = props.bulletListDisabled,
|
|
30
|
+
orderedListActive = props.orderedListActive,
|
|
31
|
+
orderedListDisabled = props.orderedListDisabled,
|
|
32
|
+
showIndentationButtons = props.showIndentationButtons,
|
|
33
|
+
indentDisabled = props.indentDisabled,
|
|
34
|
+
outdentDisabled = props.outdentDisabled,
|
|
35
|
+
onItemActivated = props.onItemActivated;
|
|
36
|
+
var labelUnorderedList = formatMessage(_messages.listMessages.unorderedList);
|
|
37
|
+
var labelOrderedList = formatMessage(_messages.listMessages.orderedList);
|
|
38
|
+
var indentMessage = formatMessage(_messages.indentationMessages.indent);
|
|
39
|
+
var outdentMessage = formatMessage(_messages.indentationMessages.outdent);
|
|
40
|
+
var isIndentButtonFocused = document.activeElement === indentButtonRef.current;
|
|
41
|
+
var isOutdentButtonFocused = document.activeElement === outdentButtonRef.current;
|
|
42
|
+
var handleOnItemActivated = function handleOnItemActivated(buttonName) {
|
|
43
|
+
return function (event) {
|
|
44
|
+
return onItemActivated({
|
|
45
|
+
editorView: props.editorView,
|
|
46
|
+
buttonName: buttonName
|
|
47
|
+
});
|
|
48
|
+
};
|
|
49
|
+
};
|
|
50
|
+
(0, _react.useEffect)(function () {
|
|
51
|
+
if (isIndentButtonFocused && indentDisabled && outdentButtonRef.current) {
|
|
52
|
+
outdentButtonRef.current.focus();
|
|
53
|
+
}
|
|
54
|
+
}, [indentButtonRef, indentDisabled, isIndentButtonFocused]);
|
|
55
|
+
(0, _react.useEffect)(function () {
|
|
56
|
+
if (isOutdentButtonFocused && outdentDisabled && indentButtonRef.current) {
|
|
57
|
+
indentButtonRef.current.focus();
|
|
58
|
+
}
|
|
59
|
+
}, [outdentButtonRef, outdentDisabled, isOutdentButtonFocused]);
|
|
60
|
+
return (
|
|
61
|
+
// eslint-disable-next-line @atlaskit/design-system/consistent-css-prop-usage
|
|
62
|
+
(0, _react2.jsx)("span", {
|
|
63
|
+
css: _styles.buttonGroupStyle
|
|
64
|
+
}, (0, _react2.jsx)(_uiMenu.ToolbarButton, {
|
|
65
|
+
buttonId: _uiMenu.TOOLBAR_BUTTON.BULLET_LIST,
|
|
66
|
+
testId: labelUnorderedList,
|
|
67
|
+
spacing: isReducedSpacing ? 'none' : 'default',
|
|
68
|
+
onClick: handleOnItemActivated('bullet_list'),
|
|
69
|
+
selected: bulletListActive,
|
|
70
|
+
"aria-pressed": bulletListActive,
|
|
71
|
+
"aria-label": (0, _keymaps.tooltip)(_keymaps.toggleBulletList, labelUnorderedList),
|
|
72
|
+
"aria-keyshortcuts": (0, _keymaps.getAriaKeyshortcuts)(_keymaps.toggleBulletList),
|
|
73
|
+
disabled: bulletListDisabled || disabled,
|
|
74
|
+
title: (0, _react2.jsx)(_keymaps.ToolTipContent, {
|
|
75
|
+
description: labelUnorderedList,
|
|
76
|
+
keymap: _keymaps.toggleBulletList
|
|
77
|
+
}),
|
|
78
|
+
iconBefore: (0, _react2.jsx)(_bulletList.default, {
|
|
79
|
+
label: ""
|
|
80
|
+
})
|
|
81
|
+
}), (0, _react2.jsx)(_uiMenu.ToolbarButton, {
|
|
82
|
+
buttonId: _uiMenu.TOOLBAR_BUTTON.ORDERED_LIST,
|
|
83
|
+
testId: labelOrderedList,
|
|
84
|
+
spacing: isReducedSpacing ? 'none' : 'default',
|
|
85
|
+
onClick: handleOnItemActivated('ordered_list'),
|
|
86
|
+
selected: orderedListActive,
|
|
87
|
+
"aria-pressed": orderedListActive,
|
|
88
|
+
"aria-label": (0, _keymaps.tooltip)(_keymaps.toggleOrderedList, labelOrderedList),
|
|
89
|
+
"aria-keyshortcuts": (0, _keymaps.getAriaKeyshortcuts)(_keymaps.toggleOrderedList),
|
|
90
|
+
disabled: orderedListDisabled || disabled,
|
|
91
|
+
title: (0, _react2.jsx)(_keymaps.ToolTipContent, {
|
|
92
|
+
description: labelOrderedList,
|
|
93
|
+
keymap: _keymaps.toggleOrderedList
|
|
94
|
+
}),
|
|
95
|
+
iconBefore: (0, _react2.jsx)(_numberList.default, {
|
|
96
|
+
label: ""
|
|
97
|
+
})
|
|
98
|
+
}), showIndentationButtons && (0, _react2.jsx)(_uiMenu.ToolbarButton, {
|
|
99
|
+
buttonId: _uiMenu.TOOLBAR_BUTTON.OUTDENT,
|
|
100
|
+
testId: _uiMenu.TOOLBAR_BUTTON.OUTDENT,
|
|
101
|
+
ref: outdentButtonRef,
|
|
102
|
+
spacing: isReducedSpacing ? 'none' : 'default',
|
|
103
|
+
onClick: handleOnItemActivated('outdent'),
|
|
104
|
+
iconBefore: (0, _react2.jsx)(_outdent.default, {
|
|
105
|
+
label: ""
|
|
106
|
+
}),
|
|
107
|
+
disabled: outdentDisabled || disabled,
|
|
108
|
+
"aria-label": (0, _keymaps.tooltip)(_keymaps.outdent, outdentMessage),
|
|
109
|
+
"aria-keyshortcuts": (0, _keymaps.getAriaKeyshortcuts)(_keymaps.outdent),
|
|
110
|
+
title: (0, _react2.jsx)(_keymaps.ToolTipContent, {
|
|
111
|
+
description: outdentMessage,
|
|
112
|
+
keymap: _keymaps.outdent
|
|
113
|
+
})
|
|
114
|
+
}), showIndentationButtons && (0, _react2.jsx)(_uiMenu.ToolbarButton, {
|
|
115
|
+
buttonId: _uiMenu.TOOLBAR_BUTTON.INDENT,
|
|
116
|
+
testId: _uiMenu.TOOLBAR_BUTTON.INDENT,
|
|
117
|
+
ref: indentButtonRef,
|
|
118
|
+
spacing: isReducedSpacing ? 'none' : 'default',
|
|
119
|
+
onClick: handleOnItemActivated('indent'),
|
|
120
|
+
iconBefore: (0, _react2.jsx)(_indent.default, {
|
|
121
|
+
label: ""
|
|
122
|
+
}),
|
|
123
|
+
disabled: indentDisabled || disabled,
|
|
124
|
+
"aria-label": (0, _keymaps.tooltip)(_keymaps.indent, indentMessage),
|
|
125
|
+
"aria-keyshortcuts": (0, _keymaps.getAriaKeyshortcuts)(_keymaps.indent),
|
|
126
|
+
title: (0, _react2.jsx)(_keymaps.ToolTipContent, {
|
|
127
|
+
description: indentMessage,
|
|
128
|
+
keymap: _keymaps.indent
|
|
129
|
+
})
|
|
130
|
+
}), (0, _react2.jsx)("span", {
|
|
131
|
+
css: _styles.separatorStyles
|
|
132
|
+
}))
|
|
133
|
+
);
|
|
134
|
+
}
|
|
@@ -0,0 +1,179 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
+
Object.defineProperty(exports, "__esModule", {
|
|
5
|
+
value: true
|
|
6
|
+
});
|
|
7
|
+
exports.ToolbarDropdown = ToolbarDropdown;
|
|
8
|
+
var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
|
|
9
|
+
var _react = _interopRequireDefault(require("react"));
|
|
10
|
+
var _react2 = require("@emotion/react");
|
|
11
|
+
var _reactIntlNext = require("react-intl-next");
|
|
12
|
+
var _keymaps = require("@atlaskit/editor-common/keymaps");
|
|
13
|
+
var _messages = require("@atlaskit/editor-common/messages");
|
|
14
|
+
var _styles = require("@atlaskit/editor-common/styles");
|
|
15
|
+
var _uiMenu = require("@atlaskit/editor-common/ui-menu");
|
|
16
|
+
var _shortcut = require("@atlaskit/editor-shared-styles/shortcut");
|
|
17
|
+
var _chevronDown = _interopRequireDefault(require("@atlaskit/icon/glyph/chevron-down"));
|
|
18
|
+
var _bulletList = _interopRequireDefault(require("@atlaskit/icon/glyph/editor/bullet-list"));
|
|
19
|
+
/** @jsx jsx */
|
|
20
|
+
|
|
21
|
+
function ToolbarDropdown(props) {
|
|
22
|
+
var _useIntl = (0, _reactIntlNext.useIntl)(),
|
|
23
|
+
formatMessage = _useIntl.formatMessage;
|
|
24
|
+
var disabled = props.disabled,
|
|
25
|
+
isReducedSpacing = props.isReducedSpacing,
|
|
26
|
+
bulletListActive = props.bulletListActive,
|
|
27
|
+
orderedListActive = props.orderedListActive,
|
|
28
|
+
popupsMountPoint = props.popupsMountPoint,
|
|
29
|
+
popupsBoundariesElement = props.popupsBoundariesElement,
|
|
30
|
+
popupsScrollableElement = props.popupsScrollableElement,
|
|
31
|
+
onItemActivated = props.onItemActivated;
|
|
32
|
+
var _React$useState = _react.default.useState(false),
|
|
33
|
+
_React$useState2 = (0, _slicedToArray2.default)(_React$useState, 2),
|
|
34
|
+
isDropdownOpen = _React$useState2[0],
|
|
35
|
+
setIsDropdownOpen = _React$useState2[1];
|
|
36
|
+
var _React$useState3 = _react.default.useState(false),
|
|
37
|
+
_React$useState4 = (0, _slicedToArray2.default)(_React$useState3, 2),
|
|
38
|
+
isOpenedByKeyboard = _React$useState4[0],
|
|
39
|
+
setOpenedByKeyboard = _React$useState4[1];
|
|
40
|
+
var labelLists = formatMessage(_messages.listMessages.lists);
|
|
41
|
+
var onOpenChange = function onOpenChange(attrs) {
|
|
42
|
+
setIsDropdownOpen(attrs.isDropdownOpen);
|
|
43
|
+
};
|
|
44
|
+
var handleTriggerClick = function handleTriggerClick() {
|
|
45
|
+
onOpenChange({
|
|
46
|
+
isDropdownOpen: !isDropdownOpen
|
|
47
|
+
});
|
|
48
|
+
};
|
|
49
|
+
var handleOnKeyDown = function handleOnKeyDown(event) {
|
|
50
|
+
if (event.key === 'Enter' || event.key === ' ') {
|
|
51
|
+
event.preventDefault();
|
|
52
|
+
setIsDropdownOpen(!isDropdownOpen);
|
|
53
|
+
setOpenedByKeyboard(true);
|
|
54
|
+
}
|
|
55
|
+
};
|
|
56
|
+
var items = useItems(props);
|
|
57
|
+
var handleOnItemActivated = function handleOnItemActivated(_ref) {
|
|
58
|
+
var item = _ref.item,
|
|
59
|
+
_ref$shouldCloseMenu = _ref.shouldCloseMenu,
|
|
60
|
+
shouldCloseMenu = _ref$shouldCloseMenu === void 0 ? true : _ref$shouldCloseMenu;
|
|
61
|
+
setIsDropdownOpen(!shouldCloseMenu);
|
|
62
|
+
return onItemActivated({
|
|
63
|
+
editorView: props.editorView,
|
|
64
|
+
buttonName: item.value.name
|
|
65
|
+
});
|
|
66
|
+
};
|
|
67
|
+
return (
|
|
68
|
+
// eslint-disable-next-line @atlaskit/design-system/consistent-css-prop-usage
|
|
69
|
+
(0, _react2.jsx)("span", {
|
|
70
|
+
css: _styles.wrapperStyle
|
|
71
|
+
}, (0, _react2.jsx)(_uiMenu.DropdownMenuWithKeyboardNavigation, {
|
|
72
|
+
items: items,
|
|
73
|
+
onItemActivated: handleOnItemActivated,
|
|
74
|
+
mountTo: popupsMountPoint,
|
|
75
|
+
boundariesElement: popupsBoundariesElement,
|
|
76
|
+
scrollableElement: popupsScrollableElement,
|
|
77
|
+
isOpen: isDropdownOpen,
|
|
78
|
+
onOpenChange: onOpenChange,
|
|
79
|
+
fitHeight: 188,
|
|
80
|
+
fitWidth: 175,
|
|
81
|
+
shouldUseDefaultRole: true,
|
|
82
|
+
shouldFocusFirstItem: function shouldFocusFirstItem() {
|
|
83
|
+
if (isOpenedByKeyboard) {
|
|
84
|
+
setOpenedByKeyboard(false);
|
|
85
|
+
}
|
|
86
|
+
return isOpenedByKeyboard;
|
|
87
|
+
}
|
|
88
|
+
}, (0, _react2.jsx)(_uiMenu.ToolbarButton, {
|
|
89
|
+
spacing: isReducedSpacing ? 'none' : 'default',
|
|
90
|
+
selected: bulletListActive || orderedListActive,
|
|
91
|
+
"aria-expanded": isDropdownOpen,
|
|
92
|
+
"aria-haspopup": true,
|
|
93
|
+
"aria-label": labelLists,
|
|
94
|
+
disabled: disabled,
|
|
95
|
+
onClick: handleTriggerClick,
|
|
96
|
+
onKeyDown: handleOnKeyDown,
|
|
97
|
+
title: labelLists,
|
|
98
|
+
iconBefore:
|
|
99
|
+
// eslint-disable-next-line @atlaskit/design-system/consistent-css-prop-usage
|
|
100
|
+
(0, _react2.jsx)("span", {
|
|
101
|
+
css: _styles.wrapperStyle
|
|
102
|
+
}, (0, _react2.jsx)(_bulletList.default, {
|
|
103
|
+
label: labelLists
|
|
104
|
+
}), (0, _react2.jsx)("span", {
|
|
105
|
+
css: _styles.expandIconWrapperStyle
|
|
106
|
+
}, (0, _react2.jsx)(_chevronDown.default, {
|
|
107
|
+
label: ""
|
|
108
|
+
})))
|
|
109
|
+
})), (0, _react2.jsx)("span", {
|
|
110
|
+
css: _styles.separatorStyles
|
|
111
|
+
}))
|
|
112
|
+
);
|
|
113
|
+
}
|
|
114
|
+
function useItems(props) {
|
|
115
|
+
var _useIntl2 = (0, _reactIntlNext.useIntl)(),
|
|
116
|
+
formatMessage = _useIntl2.formatMessage;
|
|
117
|
+
var labelUnorderedList = formatMessage(_messages.listMessages.unorderedList);
|
|
118
|
+
var labelOrderedList = formatMessage(_messages.listMessages.orderedList);
|
|
119
|
+
var items = [{
|
|
120
|
+
key: 'unorderedList',
|
|
121
|
+
content: labelUnorderedList,
|
|
122
|
+
value: {
|
|
123
|
+
name: 'bullet_list'
|
|
124
|
+
},
|
|
125
|
+
isDisabled: props.bulletListDisabled,
|
|
126
|
+
isActive: Boolean(props.bulletListActive),
|
|
127
|
+
elemAfter:
|
|
128
|
+
// eslint-disable-next-line @atlaskit/design-system/consistent-css-prop-usage
|
|
129
|
+
(0, _react2.jsx)("div", {
|
|
130
|
+
css: _shortcut.shortcutStyle
|
|
131
|
+
}, (0, _keymaps.tooltip)(_keymaps.toggleBulletList))
|
|
132
|
+
}, {
|
|
133
|
+
key: 'orderedList',
|
|
134
|
+
content: labelOrderedList,
|
|
135
|
+
value: {
|
|
136
|
+
name: 'ordered_list'
|
|
137
|
+
},
|
|
138
|
+
isDisabled: props.orderedListDisabled,
|
|
139
|
+
isActive: Boolean(props.orderedListActive),
|
|
140
|
+
elemAfter:
|
|
141
|
+
// eslint-disable-next-line @atlaskit/design-system/consistent-css-prop-usage
|
|
142
|
+
(0, _react2.jsx)("div", {
|
|
143
|
+
css: _shortcut.shortcutStyle
|
|
144
|
+
}, (0, _keymaps.tooltip)(_keymaps.toggleOrderedList))
|
|
145
|
+
}];
|
|
146
|
+
if (props.showIndentationButtons) {
|
|
147
|
+
var labelIndent = formatMessage(_messages.indentationMessages.indent);
|
|
148
|
+
var labelOutdent = formatMessage(_messages.indentationMessages.outdent);
|
|
149
|
+
items.push({
|
|
150
|
+
key: 'outdent',
|
|
151
|
+
content: labelOutdent,
|
|
152
|
+
value: {
|
|
153
|
+
name: 'outdent'
|
|
154
|
+
},
|
|
155
|
+
isDisabled: props.outdentDisabled,
|
|
156
|
+
isActive: false,
|
|
157
|
+
elemAfter:
|
|
158
|
+
// eslint-disable-next-line @atlaskit/design-system/consistent-css-prop-usage
|
|
159
|
+
(0, _react2.jsx)("div", {
|
|
160
|
+
css: _shortcut.shortcutStyle
|
|
161
|
+
}, (0, _keymaps.tooltip)(_keymaps.outdent))
|
|
162
|
+
}, {
|
|
163
|
+
key: 'indent',
|
|
164
|
+
content: labelIndent,
|
|
165
|
+
value: {
|
|
166
|
+
name: 'indent'
|
|
167
|
+
},
|
|
168
|
+
isDisabled: props.indentDisabled,
|
|
169
|
+
isActive: false,
|
|
170
|
+
// eslint-disable-next-line @atlaskit/design-system/consistent-css-prop-usage
|
|
171
|
+
elemAfter: (0, _react2.jsx)("div", {
|
|
172
|
+
css: _shortcut.shortcutStyle
|
|
173
|
+
}, (0, _keymaps.tooltip)(_keymaps.indent))
|
|
174
|
+
});
|
|
175
|
+
}
|
|
176
|
+
return [{
|
|
177
|
+
items: items
|
|
178
|
+
}];
|
|
179
|
+
}
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = ToolbarListsIndentation;
|
|
7
|
+
var _react = require("@emotion/react");
|
|
8
|
+
var _onItemActivated = require("./onItemActivated");
|
|
9
|
+
var _Toolbar = require("./Toolbar");
|
|
10
|
+
var _ToolbarDropdown = require("./ToolbarDropdown");
|
|
11
|
+
/** @jsx jsx */
|
|
12
|
+
|
|
13
|
+
function ToolbarListsIndentation(props) {
|
|
14
|
+
var disabled = props.disabled,
|
|
15
|
+
isSmall = props.isSmall,
|
|
16
|
+
isReducedSpacing = props.isReducedSpacing,
|
|
17
|
+
bulletListActive = props.bulletListActive,
|
|
18
|
+
bulletListDisabled = props.bulletListDisabled,
|
|
19
|
+
orderedListActive = props.orderedListActive,
|
|
20
|
+
orderedListDisabled = props.orderedListDisabled,
|
|
21
|
+
showIndentationButtons = props.showIndentationButtons,
|
|
22
|
+
popupsMountPoint = props.popupsMountPoint,
|
|
23
|
+
popupsBoundariesElement = props.popupsBoundariesElement,
|
|
24
|
+
popupsScrollableElement = props.popupsScrollableElement,
|
|
25
|
+
indentDisabled = props.indentDisabled,
|
|
26
|
+
outdentDisabled = props.outdentDisabled,
|
|
27
|
+
indentationStateNode = props.indentationStateNode,
|
|
28
|
+
featureFlags = props.featureFlags,
|
|
29
|
+
pluginInjectionApi = props.pluginInjectionApi;
|
|
30
|
+
if (isSmall) {
|
|
31
|
+
return (0, _react.jsx)(_ToolbarDropdown.ToolbarDropdown, {
|
|
32
|
+
editorView: props.editorView,
|
|
33
|
+
isReducedSpacing: isReducedSpacing,
|
|
34
|
+
popupsMountPoint: popupsMountPoint,
|
|
35
|
+
popupsBoundariesElement: popupsBoundariesElement,
|
|
36
|
+
popupsScrollableElement: popupsScrollableElement,
|
|
37
|
+
bulletListActive: bulletListActive,
|
|
38
|
+
bulletListDisabled: bulletListDisabled,
|
|
39
|
+
showIndentationButtons: showIndentationButtons,
|
|
40
|
+
orderedListActive: orderedListActive,
|
|
41
|
+
orderedListDisabled: orderedListDisabled,
|
|
42
|
+
indentDisabled: indentDisabled,
|
|
43
|
+
outdentDisabled: outdentDisabled,
|
|
44
|
+
disabled: disabled,
|
|
45
|
+
onItemActivated: (0, _onItemActivated.onItemActivated)(pluginInjectionApi, indentationStateNode),
|
|
46
|
+
featureFlags: featureFlags
|
|
47
|
+
});
|
|
48
|
+
}
|
|
49
|
+
return (0, _react.jsx)(_Toolbar.Toolbar, {
|
|
50
|
+
editorView: props.editorView,
|
|
51
|
+
isReducedSpacing: isReducedSpacing,
|
|
52
|
+
bulletListActive: bulletListActive,
|
|
53
|
+
bulletListDisabled: bulletListDisabled,
|
|
54
|
+
showIndentationButtons: showIndentationButtons,
|
|
55
|
+
orderedListActive: orderedListActive,
|
|
56
|
+
orderedListDisabled: orderedListDisabled,
|
|
57
|
+
indentDisabled: indentDisabled,
|
|
58
|
+
outdentDisabled: outdentDisabled,
|
|
59
|
+
disabled: disabled,
|
|
60
|
+
onItemActivated: (0, _onItemActivated.onItemActivated)(pluginInjectionApi, indentationStateNode),
|
|
61
|
+
featureFlags: featureFlags
|
|
62
|
+
});
|
|
63
|
+
}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.onItemActivated = void 0;
|
|
7
|
+
var _analytics = require("@atlaskit/editor-common/analytics");
|
|
8
|
+
var onItemActivated = exports.onItemActivated = function onItemActivated(pluginInjectionApi, indentationStateNode) {
|
|
9
|
+
return function (_ref) {
|
|
10
|
+
var buttonName = _ref.buttonName,
|
|
11
|
+
editorView = _ref.editorView;
|
|
12
|
+
switch (buttonName) {
|
|
13
|
+
case 'bullet_list':
|
|
14
|
+
pluginInjectionApi === null || pluginInjectionApi === void 0 || pluginInjectionApi.core.actions.execute(pluginInjectionApi === null || pluginInjectionApi === void 0 ? void 0 : pluginInjectionApi.list.commands.toggleBulletList(_analytics.INPUT_METHOD.TOOLBAR));
|
|
15
|
+
break;
|
|
16
|
+
case 'ordered_list':
|
|
17
|
+
pluginInjectionApi === null || pluginInjectionApi === void 0 || pluginInjectionApi.core.actions.execute(pluginInjectionApi === null || pluginInjectionApi === void 0 ? void 0 : pluginInjectionApi.list.commands.toggleOrderedList(_analytics.INPUT_METHOD.TOOLBAR));
|
|
18
|
+
break;
|
|
19
|
+
case 'indent':
|
|
20
|
+
{
|
|
21
|
+
var node = indentationStateNode;
|
|
22
|
+
if (node === 'paragraph_heading') {
|
|
23
|
+
var _pluginInjectionApi$i;
|
|
24
|
+
pluginInjectionApi === null || pluginInjectionApi === void 0 || (_pluginInjectionApi$i = pluginInjectionApi.indentation) === null || _pluginInjectionApi$i === void 0 || _pluginInjectionApi$i.actions.indentParagraphOrHeading(_analytics.INPUT_METHOD.TOOLBAR)(editorView.state, editorView.dispatch);
|
|
25
|
+
}
|
|
26
|
+
if (node === 'list') {
|
|
27
|
+
pluginInjectionApi === null || pluginInjectionApi === void 0 || pluginInjectionApi.core.actions.execute(pluginInjectionApi === null || pluginInjectionApi === void 0 ? void 0 : pluginInjectionApi.list.commands.indentList(_analytics.INPUT_METHOD.TOOLBAR));
|
|
28
|
+
}
|
|
29
|
+
if (node === 'taskList') {
|
|
30
|
+
var _pluginInjectionApi$t;
|
|
31
|
+
pluginInjectionApi === null || pluginInjectionApi === void 0 || (_pluginInjectionApi$t = pluginInjectionApi.taskDecision) === null || _pluginInjectionApi$t === void 0 || _pluginInjectionApi$t.actions.indentTaskList(_analytics.INPUT_METHOD.TOOLBAR)(editorView.state, editorView.dispatch);
|
|
32
|
+
}
|
|
33
|
+
break;
|
|
34
|
+
}
|
|
35
|
+
case 'outdent':
|
|
36
|
+
{
|
|
37
|
+
var _node = indentationStateNode;
|
|
38
|
+
if (_node === 'paragraph_heading') {
|
|
39
|
+
var _pluginInjectionApi$i2;
|
|
40
|
+
pluginInjectionApi === null || pluginInjectionApi === void 0 || (_pluginInjectionApi$i2 = pluginInjectionApi.indentation) === null || _pluginInjectionApi$i2 === void 0 || _pluginInjectionApi$i2.actions.outdentParagraphOrHeading(_analytics.INPUT_METHOD.TOOLBAR)(editorView.state, editorView.dispatch);
|
|
41
|
+
}
|
|
42
|
+
if (_node === 'list') {
|
|
43
|
+
pluginInjectionApi === null || pluginInjectionApi === void 0 || pluginInjectionApi.core.actions.execute(pluginInjectionApi === null || pluginInjectionApi === void 0 ? void 0 : pluginInjectionApi.list.commands.outdentList(_analytics.INPUT_METHOD.TOOLBAR));
|
|
44
|
+
}
|
|
45
|
+
if (_node === 'taskList') {
|
|
46
|
+
var _pluginInjectionApi$t2;
|
|
47
|
+
pluginInjectionApi === null || pluginInjectionApi === void 0 || (_pluginInjectionApi$t2 = pluginInjectionApi.taskDecision) === null || _pluginInjectionApi$t2 === void 0 || _pluginInjectionApi$t2.actions.outdentTaskList(_analytics.INPUT_METHOD.TOOLBAR)(editorView.state, editorView.dispatch);
|
|
48
|
+
}
|
|
49
|
+
break;
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
};
|
|
53
|
+
};
|
package/dist/es2019/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export {};
|
|
1
|
+
export { toolbarListsIndentationPlugin } from './plugin';
|