@atlaskit/editor-plugin-insert-block 0.1.1 → 0.2.1
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/.eslintrc.js +26 -0
- package/CHANGELOG.md +12 -0
- package/dist/cjs/index.js +8 -1
- package/dist/cjs/plugin.js +164 -0
- package/dist/cjs/types.js +5 -0
- package/dist/cjs/ui/ElementBrowser/InsertMenu.js +169 -0
- package/dist/cjs/ui/ElementBrowser/types.js +5 -0
- package/dist/cjs/ui/ToolbarInsertBlock/block-insert-element-browser.js +42 -0
- package/dist/cjs/ui/ToolbarInsertBlock/block-insert-menu-legacy.js +42 -0
- package/dist/cjs/ui/ToolbarInsertBlock/block-insert-menu.js +66 -0
- package/dist/cjs/ui/ToolbarInsertBlock/create-items.js +217 -0
- package/dist/cjs/ui/ToolbarInsertBlock/dropdown-button.js +52 -0
- package/dist/cjs/ui/ToolbarInsertBlock/index.js +570 -0
- package/dist/cjs/ui/ToolbarInsertBlock/item.js +252 -0
- package/dist/cjs/ui/ToolbarInsertBlock/messages.js +12 -0
- package/dist/cjs/ui/ToolbarInsertBlock/shallow-equals.js +20 -0
- package/dist/cjs/ui/ToolbarInsertBlock/sort-items.js +30 -0
- package/dist/cjs/ui/ToolbarInsertBlock/styles.js +11 -0
- package/dist/cjs/ui/ToolbarInsertBlock/types.js +5 -0
- package/dist/es2019/index.js +1 -1
- package/dist/es2019/plugin.js +158 -0
- package/dist/es2019/types.js +1 -0
- package/dist/es2019/ui/ElementBrowser/InsertMenu.js +156 -0
- package/dist/es2019/ui/ElementBrowser/types.js +1 -0
- package/dist/es2019/ui/ToolbarInsertBlock/block-insert-element-browser.js +35 -0
- package/dist/es2019/ui/ToolbarInsertBlock/block-insert-menu-legacy.js +35 -0
- package/dist/es2019/ui/ToolbarInsertBlock/block-insert-menu.js +59 -0
- package/dist/es2019/ui/ToolbarInsertBlock/create-items.js +198 -0
- package/dist/es2019/ui/ToolbarInsertBlock/dropdown-button.js +39 -0
- package/dist/es2019/ui/ToolbarInsertBlock/index.js +562 -0
- package/dist/es2019/ui/ToolbarInsertBlock/item.js +202 -0
- package/dist/es2019/ui/ToolbarInsertBlock/messages.js +1 -0
- package/dist/es2019/ui/ToolbarInsertBlock/shallow-equals.js +8 -0
- package/dist/es2019/ui/ToolbarInsertBlock/sort-items.js +22 -0
- package/dist/es2019/ui/ToolbarInsertBlock/styles.js +16 -0
- package/dist/es2019/ui/ToolbarInsertBlock/types.js +1 -0
- package/dist/esm/index.js +1 -1
- package/dist/esm/plugin.js +157 -0
- package/dist/esm/types.js +1 -0
- package/dist/esm/ui/ElementBrowser/InsertMenu.js +163 -0
- package/dist/esm/ui/ElementBrowser/types.js +1 -0
- package/dist/esm/ui/ToolbarInsertBlock/block-insert-element-browser.js +35 -0
- package/dist/esm/ui/ToolbarInsertBlock/block-insert-menu-legacy.js +35 -0
- package/dist/esm/ui/ToolbarInsertBlock/block-insert-menu.js +59 -0
- package/dist/esm/ui/ToolbarInsertBlock/create-items.js +210 -0
- package/dist/esm/ui/ToolbarInsertBlock/dropdown-button.js +44 -0
- package/dist/esm/ui/ToolbarInsertBlock/index.js +564 -0
- package/dist/esm/ui/ToolbarInsertBlock/item.js +244 -0
- package/dist/esm/ui/ToolbarInsertBlock/messages.js +1 -0
- package/dist/esm/ui/ToolbarInsertBlock/shallow-equals.js +13 -0
- package/dist/esm/ui/ToolbarInsertBlock/sort-items.js +24 -0
- package/dist/esm/ui/ToolbarInsertBlock/styles.js +4 -0
- package/dist/esm/ui/ToolbarInsertBlock/types.js +1 -0
- package/dist/types/index.d.ts +2 -1
- package/dist/types/plugin.d.ts +16 -0
- package/dist/types/types.d.ts +45 -0
- package/dist/types/ui/ElementBrowser/InsertMenu.d.ts +4 -0
- package/dist/types/ui/ElementBrowser/types.d.ts +22 -0
- package/dist/types/ui/ToolbarInsertBlock/block-insert-element-browser.d.ts +28 -0
- package/dist/types/ui/ToolbarInsertBlock/block-insert-menu-legacy.d.ts +21 -0
- package/dist/types/ui/ToolbarInsertBlock/block-insert-menu.d.ts +33 -0
- package/dist/types/ui/ToolbarInsertBlock/create-items.d.ts +39 -0
- package/dist/types/ui/ToolbarInsertBlock/dropdown-button.d.ts +16 -0
- package/dist/types/ui/ToolbarInsertBlock/index.d.ts +46 -0
- package/dist/types/ui/ToolbarInsertBlock/item.d.ts +35 -0
- package/dist/types/ui/ToolbarInsertBlock/messages.d.ts +1 -0
- package/dist/types/ui/ToolbarInsertBlock/shallow-equals.d.ts +1 -0
- package/dist/types/ui/ToolbarInsertBlock/sort-items.d.ts +2 -0
- package/dist/types/ui/ToolbarInsertBlock/styles.d.ts +1 -0
- package/dist/types/ui/ToolbarInsertBlock/types.d.ts +59 -0
- package/dist/types-ts4.5/index.d.ts +2 -1
- package/dist/types-ts4.5/plugin.d.ts +16 -0
- package/dist/types-ts4.5/types.d.ts +45 -0
- package/dist/types-ts4.5/ui/ElementBrowser/InsertMenu.d.ts +4 -0
- package/dist/types-ts4.5/ui/ElementBrowser/types.d.ts +22 -0
- package/dist/types-ts4.5/ui/ToolbarInsertBlock/block-insert-element-browser.d.ts +28 -0
- package/dist/types-ts4.5/ui/ToolbarInsertBlock/block-insert-menu-legacy.d.ts +21 -0
- package/dist/types-ts4.5/ui/ToolbarInsertBlock/block-insert-menu.d.ts +33 -0
- package/dist/types-ts4.5/ui/ToolbarInsertBlock/create-items.d.ts +42 -0
- package/dist/types-ts4.5/ui/ToolbarInsertBlock/dropdown-button.d.ts +16 -0
- package/dist/types-ts4.5/ui/ToolbarInsertBlock/index.d.ts +46 -0
- package/dist/types-ts4.5/ui/ToolbarInsertBlock/item.d.ts +35 -0
- package/dist/types-ts4.5/ui/ToolbarInsertBlock/messages.d.ts +1 -0
- package/dist/types-ts4.5/ui/ToolbarInsertBlock/shallow-equals.d.ts +1 -0
- package/dist/types-ts4.5/ui/ToolbarInsertBlock/sort-items.d.ts +2 -0
- package/dist/types-ts4.5/ui/ToolbarInsertBlock/styles.d.ts +1 -0
- package/dist/types-ts4.5/ui/ToolbarInsertBlock/types.d.ts +59 -0
- package/package.json +37 -9
- package/report.api.md +82 -1
- package/tmp/api-report-tmp.d.ts +0 -9
package/.eslintrc.js
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
module.exports = {
|
|
2
|
+
rules: {
|
|
3
|
+
'@typescript-eslint/no-duplicate-imports': 'error',
|
|
4
|
+
'@typescript-eslint/no-explicit-any': 'error',
|
|
5
|
+
'@typescript-eslint/ban-types': [
|
|
6
|
+
'error',
|
|
7
|
+
{
|
|
8
|
+
types: {
|
|
9
|
+
'React.FC':
|
|
10
|
+
'Please use types directly on props instead, and explicitly define children if required',
|
|
11
|
+
'React.FunctionalComponent':
|
|
12
|
+
'Please use types directly on props instead, and explicitly define children if required',
|
|
13
|
+
},
|
|
14
|
+
extendDefaults: false,
|
|
15
|
+
},
|
|
16
|
+
],
|
|
17
|
+
},
|
|
18
|
+
overrides: [
|
|
19
|
+
{
|
|
20
|
+
files: ['**/__tests__/**/*.{js,ts,tsx}', '**/examples/**/*.{js,ts,tsx}'],
|
|
21
|
+
rules: {
|
|
22
|
+
'@typescript-eslint/no-explicit-any': 'off',
|
|
23
|
+
},
|
|
24
|
+
},
|
|
25
|
+
],
|
|
26
|
+
};
|
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,17 @@
|
|
|
1
1
|
# @atlaskit/editor-plugin-insert-block
|
|
2
2
|
|
|
3
|
+
## 0.2.1
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- Updated dependencies
|
|
8
|
+
|
|
9
|
+
## 0.2.0
|
|
10
|
+
|
|
11
|
+
### Minor Changes
|
|
12
|
+
|
|
13
|
+
- [#43507](https://bitbucket.org/atlassian/atlassian-frontend/pull-requests/43507) [`a9695768de6`](https://bitbucket.org/atlassian/atlassian-frontend/commits/a9695768de6) - Extracted insert block plugin code from editor-core to @atlaskit/editor-plugin-insert-block
|
|
14
|
+
|
|
3
15
|
## 0.1.1
|
|
4
16
|
|
|
5
17
|
### 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, "insertBlockPlugin", {
|
|
7
|
+
enumerable: true,
|
|
8
|
+
get: function get() {
|
|
9
|
+
return _plugin.insertBlockPlugin;
|
|
10
|
+
}
|
|
11
|
+
});
|
|
12
|
+
var _plugin = require("./plugin");
|
|
@@ -0,0 +1,164 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
+
Object.defineProperty(exports, "__esModule", {
|
|
5
|
+
value: true
|
|
6
|
+
});
|
|
7
|
+
exports.insertBlockPlugin = void 0;
|
|
8
|
+
var _react = _interopRequireDefault(require("react"));
|
|
9
|
+
var _analytics = require("@atlaskit/editor-common/analytics");
|
|
10
|
+
var _hooks = require("@atlaskit/editor-common/hooks");
|
|
11
|
+
var _providerFactory = require("@atlaskit/editor-common/provider-factory");
|
|
12
|
+
var _types = require("@atlaskit/editor-common/types");
|
|
13
|
+
var _consts = require("@atlaskit/editor-plugin-block-type/consts");
|
|
14
|
+
var _ToolbarInsertBlock = _interopRequireDefault(require("./ui/ToolbarInsertBlock"));
|
|
15
|
+
var toolbarSizeToButtons = function toolbarSizeToButtons(toolbarSize) {
|
|
16
|
+
switch (toolbarSize) {
|
|
17
|
+
case _types.ToolbarSize.XXL:
|
|
18
|
+
case _types.ToolbarSize.XL:
|
|
19
|
+
case _types.ToolbarSize.L:
|
|
20
|
+
case _types.ToolbarSize.M:
|
|
21
|
+
return 7;
|
|
22
|
+
case _types.ToolbarSize.S:
|
|
23
|
+
return 2;
|
|
24
|
+
default:
|
|
25
|
+
return 0;
|
|
26
|
+
}
|
|
27
|
+
};
|
|
28
|
+
/**
|
|
29
|
+
* Wrapper over insertBlockTypeWithAnalytics to autobind toolbar input method
|
|
30
|
+
* @param name Block name
|
|
31
|
+
*/
|
|
32
|
+
function handleInsertBlockType(insertCodeBlock, insertPanel, insertBlockQuote) {
|
|
33
|
+
return function (name) {
|
|
34
|
+
if (name === _consts.CODE_BLOCK.name && insertCodeBlock) {
|
|
35
|
+
return insertCodeBlock(_analytics.INPUT_METHOD.TOOLBAR);
|
|
36
|
+
}
|
|
37
|
+
if (name === _consts.PANEL.name && insertPanel) {
|
|
38
|
+
return insertPanel(_analytics.INPUT_METHOD.TOOLBAR);
|
|
39
|
+
}
|
|
40
|
+
if (name === _consts.BLOCK_QUOTE.name && insertBlockQuote) {
|
|
41
|
+
return insertBlockQuote(_analytics.INPUT_METHOD.TOOLBAR);
|
|
42
|
+
}
|
|
43
|
+
return function () {
|
|
44
|
+
return false;
|
|
45
|
+
};
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
var insertBlockPlugin = exports.insertBlockPlugin = function insertBlockPlugin(_ref) {
|
|
49
|
+
var _api$featureFlags;
|
|
50
|
+
var _ref$config = _ref.config,
|
|
51
|
+
options = _ref$config === void 0 ? {} : _ref$config,
|
|
52
|
+
api = _ref.api;
|
|
53
|
+
var featureFlags = (api === null || api === void 0 || (_api$featureFlags = api.featureFlags) === null || _api$featureFlags === void 0 ? void 0 : _api$featureFlags.sharedState.currentState()) || {};
|
|
54
|
+
return {
|
|
55
|
+
name: 'insertBlock',
|
|
56
|
+
primaryToolbarComponent: function primaryToolbarComponent(_ref2) {
|
|
57
|
+
var editorView = _ref2.editorView,
|
|
58
|
+
editorActions = _ref2.editorActions,
|
|
59
|
+
dispatchAnalyticsEvent = _ref2.dispatchAnalyticsEvent,
|
|
60
|
+
providerFactory = _ref2.providerFactory,
|
|
61
|
+
popupsMountPoint = _ref2.popupsMountPoint,
|
|
62
|
+
popupsBoundariesElement = _ref2.popupsBoundariesElement,
|
|
63
|
+
popupsScrollableElement = _ref2.popupsScrollableElement,
|
|
64
|
+
toolbarSize = _ref2.toolbarSize,
|
|
65
|
+
disabled = _ref2.disabled,
|
|
66
|
+
isToolbarReducedSpacing = _ref2.isToolbarReducedSpacing,
|
|
67
|
+
isLastItem = _ref2.isLastItem;
|
|
68
|
+
var renderNode = function renderNode(providers) {
|
|
69
|
+
return /*#__PURE__*/_react.default.createElement(ToolbarInsertBlockWithInjectionApi, {
|
|
70
|
+
pluginInjectionApi: api,
|
|
71
|
+
editorView: editorView,
|
|
72
|
+
editorActions: editorActions,
|
|
73
|
+
dispatchAnalyticsEvent: dispatchAnalyticsEvent,
|
|
74
|
+
providerFactory: providerFactory,
|
|
75
|
+
popupsMountPoint: popupsMountPoint,
|
|
76
|
+
popupsBoundariesElement: popupsBoundariesElement,
|
|
77
|
+
popupsScrollableElement: popupsScrollableElement,
|
|
78
|
+
toolbarSize: toolbarSize,
|
|
79
|
+
disabled: disabled,
|
|
80
|
+
isToolbarReducedSpacing: isToolbarReducedSpacing,
|
|
81
|
+
isLastItem: isLastItem,
|
|
82
|
+
featureFlags: featureFlags,
|
|
83
|
+
providers: providers,
|
|
84
|
+
options: options
|
|
85
|
+
});
|
|
86
|
+
};
|
|
87
|
+
return /*#__PURE__*/_react.default.createElement(_providerFactory.WithProviders, {
|
|
88
|
+
providerFactory: providerFactory,
|
|
89
|
+
providers: ['emojiProvider'],
|
|
90
|
+
renderNode: renderNode
|
|
91
|
+
});
|
|
92
|
+
}
|
|
93
|
+
};
|
|
94
|
+
};
|
|
95
|
+
function ToolbarInsertBlockWithInjectionApi(_ref3) {
|
|
96
|
+
var _ref4, _ref5, _pluginInjectionApi$i, _pluginInjectionApi$c, _pluginInjectionApi$p, _pluginInjectionApi$b, _pluginInjectionApi$e;
|
|
97
|
+
var editorView = _ref3.editorView,
|
|
98
|
+
editorActions = _ref3.editorActions,
|
|
99
|
+
dispatchAnalyticsEvent = _ref3.dispatchAnalyticsEvent,
|
|
100
|
+
popupsMountPoint = _ref3.popupsMountPoint,
|
|
101
|
+
popupsBoundariesElement = _ref3.popupsBoundariesElement,
|
|
102
|
+
popupsScrollableElement = _ref3.popupsScrollableElement,
|
|
103
|
+
toolbarSize = _ref3.toolbarSize,
|
|
104
|
+
disabled = _ref3.disabled,
|
|
105
|
+
isToolbarReducedSpacing = _ref3.isToolbarReducedSpacing,
|
|
106
|
+
isLastItem = _ref3.isLastItem,
|
|
107
|
+
providers = _ref3.providers,
|
|
108
|
+
pluginInjectionApi = _ref3.pluginInjectionApi,
|
|
109
|
+
options = _ref3.options,
|
|
110
|
+
featureFlags = _ref3.featureFlags;
|
|
111
|
+
var buttons = toolbarSizeToButtons(toolbarSize);
|
|
112
|
+
var _useSharedPluginState = (0, _hooks.useSharedPluginState)(pluginInjectionApi, ['hyperlink', 'date', 'imageUpload', 'mention', 'emoji', 'blockType', 'media', 'typeAhead', 'placeholderText']),
|
|
113
|
+
dateState = _useSharedPluginState.dateState,
|
|
114
|
+
hyperlinkState = _useSharedPluginState.hyperlinkState,
|
|
115
|
+
imageUploadState = _useSharedPluginState.imageUploadState,
|
|
116
|
+
mentionState = _useSharedPluginState.mentionState,
|
|
117
|
+
emojiState = _useSharedPluginState.emojiState,
|
|
118
|
+
blockTypeState = _useSharedPluginState.blockTypeState,
|
|
119
|
+
mediaState = _useSharedPluginState.mediaState,
|
|
120
|
+
typeAheadState = _useSharedPluginState.typeAheadState,
|
|
121
|
+
placeholderTextState = _useSharedPluginState.placeholderTextState;
|
|
122
|
+
return /*#__PURE__*/_react.default.createElement(_ToolbarInsertBlock.default, {
|
|
123
|
+
pluginInjectionApi: pluginInjectionApi,
|
|
124
|
+
buttons: buttons,
|
|
125
|
+
isReducedSpacing: isToolbarReducedSpacing,
|
|
126
|
+
isDisabled: disabled,
|
|
127
|
+
isTypeAheadAllowed: Boolean(typeAheadState === null || typeAheadState === void 0 ? void 0 : typeAheadState.isAllowed),
|
|
128
|
+
editorView: editorView,
|
|
129
|
+
tableSupported: !!editorView.state.schema.nodes.table,
|
|
130
|
+
actionSupported: !!editorView.state.schema.nodes.taskItem,
|
|
131
|
+
mentionsSupported: !!(mentionState && mentionState.mentionProvider),
|
|
132
|
+
mentionsDisabled: !!(mentionState && !mentionState.canInsertMention),
|
|
133
|
+
decisionSupported: !!editorView.state.schema.nodes.decisionItem,
|
|
134
|
+
dateEnabled: !!dateState,
|
|
135
|
+
placeholderTextEnabled: placeholderTextState && placeholderTextState.allowInserting,
|
|
136
|
+
layoutSectionEnabled: Boolean(pluginInjectionApi === null || pluginInjectionApi === void 0 ? void 0 : pluginInjectionApi.layout),
|
|
137
|
+
expandEnabled: !!options.allowExpand,
|
|
138
|
+
mediaUploadsEnabled: (_ref4 = mediaState && mediaState.allowsUploads) !== null && _ref4 !== void 0 ? _ref4 : undefined,
|
|
139
|
+
onShowMediaPicker: (_ref5 = mediaState && mediaState.showMediaPicker) !== null && _ref5 !== void 0 ? _ref5 : undefined,
|
|
140
|
+
mediaSupported: !!mediaState,
|
|
141
|
+
imageUploadSupported: !!(pluginInjectionApi !== null && pluginInjectionApi !== void 0 && pluginInjectionApi.imageUpload),
|
|
142
|
+
imageUploadEnabled: imageUploadState === null || imageUploadState === void 0 ? void 0 : imageUploadState.enabled,
|
|
143
|
+
handleImageUpload: pluginInjectionApi === null || pluginInjectionApi === void 0 || (_pluginInjectionApi$i = pluginInjectionApi.imageUpload) === null || _pluginInjectionApi$i === void 0 ? void 0 : _pluginInjectionApi$i.actions.startUpload,
|
|
144
|
+
availableWrapperBlockTypes: blockTypeState && blockTypeState.availableWrapperBlockTypes,
|
|
145
|
+
linkSupported: !!hyperlinkState,
|
|
146
|
+
linkDisabled: !hyperlinkState || !hyperlinkState.canInsertLink || !!hyperlinkState.activeLinkMark,
|
|
147
|
+
emojiDisabled: !emojiState || !emojiState.emojiProvider,
|
|
148
|
+
emojiProvider: providers.emojiProvider,
|
|
149
|
+
nativeStatusSupported: options.nativeStatusSupported,
|
|
150
|
+
horizontalRuleEnabled: options.horizontalRuleEnabled,
|
|
151
|
+
onInsertBlockType: handleInsertBlockType(pluginInjectionApi === null || pluginInjectionApi === void 0 || (_pluginInjectionApi$c = pluginInjectionApi.codeBlock) === null || _pluginInjectionApi$c === void 0 ? void 0 : _pluginInjectionApi$c.actions.insertCodeBlock, pluginInjectionApi === null || pluginInjectionApi === void 0 || (_pluginInjectionApi$p = pluginInjectionApi.panel) === null || _pluginInjectionApi$p === void 0 ? void 0 : _pluginInjectionApi$p.actions.insertPanel, pluginInjectionApi === null || pluginInjectionApi === void 0 || (_pluginInjectionApi$b = pluginInjectionApi.blockType) === null || _pluginInjectionApi$b === void 0 ? void 0 : _pluginInjectionApi$b.actions.insertBlockQuote),
|
|
152
|
+
onInsertMacroFromMacroBrowser: pluginInjectionApi === null || pluginInjectionApi === void 0 || (_pluginInjectionApi$e = pluginInjectionApi.extension) === null || _pluginInjectionApi$e === void 0 ? void 0 : _pluginInjectionApi$e.actions.insertMacroFromMacroBrowser,
|
|
153
|
+
popupsMountPoint: popupsMountPoint,
|
|
154
|
+
popupsBoundariesElement: popupsBoundariesElement,
|
|
155
|
+
popupsScrollableElement: popupsScrollableElement,
|
|
156
|
+
insertMenuItems: options.insertMenuItems,
|
|
157
|
+
editorActions: editorActions,
|
|
158
|
+
dispatchAnalyticsEvent: dispatchAnalyticsEvent,
|
|
159
|
+
replacePlusMenuWithElementBrowser: options.replacePlusMenuWithElementBrowser,
|
|
160
|
+
showElementBrowserLink: options.showElementBrowserLink,
|
|
161
|
+
showSeparator: !isLastItem && toolbarSize <= _types.ToolbarSize.S,
|
|
162
|
+
featureFlags: featureFlags
|
|
163
|
+
});
|
|
164
|
+
}
|
|
@@ -0,0 +1,169 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
+
Object.defineProperty(exports, "__esModule", {
|
|
5
|
+
value: true
|
|
6
|
+
});
|
|
7
|
+
exports.default = void 0;
|
|
8
|
+
var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
|
|
9
|
+
var _objectWithoutProperties2 = _interopRequireDefault(require("@babel/runtime/helpers/objectWithoutProperties"));
|
|
10
|
+
var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
|
|
11
|
+
var _react = require("react");
|
|
12
|
+
var _react2 = require("@emotion/react");
|
|
13
|
+
var _elementBrowser = require("@atlaskit/editor-common/element-browser");
|
|
14
|
+
var _quickInsert = require("@atlaskit/editor-common/quick-insert");
|
|
15
|
+
var _uiReact = require("@atlaskit/editor-common/ui-react");
|
|
16
|
+
var _theme = require("@atlaskit/theme");
|
|
17
|
+
var _colors = require("@atlaskit/theme/colors");
|
|
18
|
+
var _excluded = ["children"];
|
|
19
|
+
/** @jsx jsx */
|
|
20
|
+
// AFP-2532 TODO: Fix automatic suppressions below
|
|
21
|
+
// eslint-disable-next-line @atlassian/tangerine/import/entry-points
|
|
22
|
+
var InsertMenu = function InsertMenu(_ref) {
|
|
23
|
+
var _pluginInjectionApi$q6, _pluginInjectionApi$q7;
|
|
24
|
+
var editorView = _ref.editorView,
|
|
25
|
+
dropdownItems = _ref.dropdownItems,
|
|
26
|
+
showElementBrowserLink = _ref.showElementBrowserLink,
|
|
27
|
+
onInsert = _ref.onInsert,
|
|
28
|
+
toggleVisiblity = _ref.toggleVisiblity,
|
|
29
|
+
pluginInjectionApi = _ref.pluginInjectionApi;
|
|
30
|
+
var _useState = (0, _react.useState)(0),
|
|
31
|
+
_useState2 = (0, _slicedToArray2.default)(_useState, 2),
|
|
32
|
+
itemCount = _useState2[0],
|
|
33
|
+
setItemCount = _useState2[1];
|
|
34
|
+
var transform = (0, _react.useCallback)(function (item) {
|
|
35
|
+
return {
|
|
36
|
+
title: item.content,
|
|
37
|
+
description: item.tooltipDescription,
|
|
38
|
+
keyshortcut: item.shortcut,
|
|
39
|
+
icon: function icon() {
|
|
40
|
+
return getSvgIconForItem({
|
|
41
|
+
name: item.value.name
|
|
42
|
+
}) || item.elemBefore;
|
|
43
|
+
},
|
|
44
|
+
/**
|
|
45
|
+
* @note This transformed items action is only used when a quick insert item has been
|
|
46
|
+
* called from the quick insert menu and a search has not been performed.
|
|
47
|
+
*/
|
|
48
|
+
action: function action() {
|
|
49
|
+
return onInsert({
|
|
50
|
+
item: item
|
|
51
|
+
});
|
|
52
|
+
},
|
|
53
|
+
// "insertInsertMenuItem" expects these 2 properties.
|
|
54
|
+
onClick: item.onClick,
|
|
55
|
+
value: item.value
|
|
56
|
+
};
|
|
57
|
+
}, [onInsert]);
|
|
58
|
+
var quickInsertDropdownItems = dropdownItems.map(transform);
|
|
59
|
+
var viewMoreItem = showElementBrowserLink ? quickInsertDropdownItems.pop() : undefined;
|
|
60
|
+
var onInsertItem = (0, _react.useCallback)(function (item) {
|
|
61
|
+
var _pluginInjectionApi$q;
|
|
62
|
+
toggleVisiblity();
|
|
63
|
+
if (!editorView.hasFocus()) {
|
|
64
|
+
editorView.focus();
|
|
65
|
+
}
|
|
66
|
+
pluginInjectionApi === null || pluginInjectionApi === void 0 || (_pluginInjectionApi$q = pluginInjectionApi.quickInsert) === null || _pluginInjectionApi$q === void 0 || _pluginInjectionApi$q.actions.insertItem(item)(editorView.state, editorView.dispatch);
|
|
67
|
+
}, [editorView, toggleVisiblity, pluginInjectionApi]);
|
|
68
|
+
var getItems = (0, _react.useCallback)(function (query, category) {
|
|
69
|
+
var result;
|
|
70
|
+
/**
|
|
71
|
+
* @warning The results if there is a query are not the same as the results if there is no query.
|
|
72
|
+
* For example: If you have a typed panel and then select the panel item then it will call a different action
|
|
73
|
+
* than is specified on the editor plugins quick insert
|
|
74
|
+
* @see above transform function for more details.
|
|
75
|
+
*/
|
|
76
|
+
if (query) {
|
|
77
|
+
var _pluginInjectionApi$q2, _pluginInjectionApi$q3;
|
|
78
|
+
result = (_pluginInjectionApi$q2 = pluginInjectionApi === null || pluginInjectionApi === void 0 || (_pluginInjectionApi$q3 = pluginInjectionApi.quickInsert) === null || _pluginInjectionApi$q3 === void 0 ? void 0 : _pluginInjectionApi$q3.actions.getSuggestions({
|
|
79
|
+
query: query,
|
|
80
|
+
category: category
|
|
81
|
+
})) !== null && _pluginInjectionApi$q2 !== void 0 ? _pluginInjectionApi$q2 : [];
|
|
82
|
+
} else {
|
|
83
|
+
var _pluginInjectionApi$q4, _pluginInjectionApi$q5;
|
|
84
|
+
var featuredQuickInsertSuggestions = (_pluginInjectionApi$q4 = pluginInjectionApi === null || pluginInjectionApi === void 0 || (_pluginInjectionApi$q5 = pluginInjectionApi.quickInsert) === null || _pluginInjectionApi$q5 === void 0 ? void 0 : _pluginInjectionApi$q5.actions.getSuggestions({
|
|
85
|
+
category: category,
|
|
86
|
+
featuredItems: true
|
|
87
|
+
})) !== null && _pluginInjectionApi$q4 !== void 0 ? _pluginInjectionApi$q4 : [];
|
|
88
|
+
result = quickInsertDropdownItems.concat(featuredQuickInsertSuggestions);
|
|
89
|
+
}
|
|
90
|
+
setItemCount(result.length);
|
|
91
|
+
return result;
|
|
92
|
+
}, [pluginInjectionApi === null || pluginInjectionApi === void 0 || (_pluginInjectionApi$q6 = pluginInjectionApi.quickInsert) === null || _pluginInjectionApi$q6 === void 0 ? void 0 : _pluginInjectionApi$q6.actions, quickInsertDropdownItems]);
|
|
93
|
+
var emptyStateHandler = pluginInjectionApi === null || pluginInjectionApi === void 0 || (_pluginInjectionApi$q7 = pluginInjectionApi.quickInsert) === null || _pluginInjectionApi$q7 === void 0 || (_pluginInjectionApi$q7 = _pluginInjectionApi$q7.sharedState.currentState()) === null || _pluginInjectionApi$q7 === void 0 ? void 0 : _pluginInjectionApi$q7.emptyStateHandler;
|
|
94
|
+
return (
|
|
95
|
+
// eslint-disable-next-line @atlaskit/design-system/consistent-css-prop-usage
|
|
96
|
+
(0, _react2.jsx)("div", {
|
|
97
|
+
css: insertMenuWrapper(itemCount)
|
|
98
|
+
}, (0, _react2.jsx)(ElementBrowserWrapper, {
|
|
99
|
+
handleClickOutside: toggleVisiblity,
|
|
100
|
+
handleEscapeKeydown: toggleVisiblity,
|
|
101
|
+
closeOnTab: true
|
|
102
|
+
}, (0, _react2.jsx)(_elementBrowser.ElementBrowser, {
|
|
103
|
+
mode: "inline",
|
|
104
|
+
getItems: getItems,
|
|
105
|
+
emptyStateHandler: emptyStateHandler,
|
|
106
|
+
onInsertItem: onInsertItem,
|
|
107
|
+
showSearch: true,
|
|
108
|
+
showCategories: false
|
|
109
|
+
// On page resize we want the InlineElementBrowser to show updated tools/overflow items
|
|
110
|
+
,
|
|
111
|
+
key: quickInsertDropdownItems.length,
|
|
112
|
+
viewMoreItem: viewMoreItem
|
|
113
|
+
})))
|
|
114
|
+
);
|
|
115
|
+
};
|
|
116
|
+
var getSvgIconForItem = function getSvgIconForItem(_ref2) {
|
|
117
|
+
var name = _ref2.name;
|
|
118
|
+
var Icon = {
|
|
119
|
+
codeblock: _quickInsert.IconCode,
|
|
120
|
+
panel: _quickInsert.IconPanel,
|
|
121
|
+
blockquote: _quickInsert.IconQuote,
|
|
122
|
+
decision: _quickInsert.IconDecision,
|
|
123
|
+
horizontalrule: _quickInsert.IconDivider,
|
|
124
|
+
expand: _quickInsert.IconExpand,
|
|
125
|
+
date: _quickInsert.IconDate,
|
|
126
|
+
status: _quickInsert.IconStatus
|
|
127
|
+
}[name];
|
|
128
|
+
return Icon ? (0, _react2.jsx)(Icon, {
|
|
129
|
+
label: ""
|
|
130
|
+
}) : undefined;
|
|
131
|
+
};
|
|
132
|
+
var getInsertMenuHeight = function getInsertMenuHeight(_ref3) {
|
|
133
|
+
var itemCount = _ref3.itemCount;
|
|
134
|
+
// Figure based on visuals to exclude the searchbar, padding/margin, and the ViewMore item.
|
|
135
|
+
var EXTRA_SPACE_EXCLUDING_ELEMENTLIST = 112;
|
|
136
|
+
if (itemCount > 0 && itemCount < 6) {
|
|
137
|
+
return itemCount * _elementBrowser.ELEMENT_ITEM_HEIGHT + EXTRA_SPACE_EXCLUDING_ELEMENTLIST;
|
|
138
|
+
}
|
|
139
|
+
return 560; // For showing 6 Elements.
|
|
140
|
+
};
|
|
141
|
+
|
|
142
|
+
var insertMenuWrapper = function insertMenuWrapper(itemCount) {
|
|
143
|
+
return (0, _react2.css)({
|
|
144
|
+
display: 'flex',
|
|
145
|
+
flexDirection: 'column',
|
|
146
|
+
width: '320px',
|
|
147
|
+
height: "".concat(getInsertMenuHeight({
|
|
148
|
+
itemCount: itemCount
|
|
149
|
+
}), "px"),
|
|
150
|
+
backgroundColor: "".concat("var(--ds-surface-overlay, ".concat(_colors.N0, ")")),
|
|
151
|
+
borderRadius: "".concat((0, _theme.borderRadius)(), "px"),
|
|
152
|
+
boxShadow: "".concat("var(--ds-shadow-overlay, ".concat("0 0 0 1px ".concat(_colors.N30A, ",\n 0 2px 1px ").concat(_colors.N30A, ",\n 0 0 20px -6px ").concat(_colors.N60A), ")"))
|
|
153
|
+
});
|
|
154
|
+
};
|
|
155
|
+
var flexWrapperStyles = (0, _react2.css)({
|
|
156
|
+
display: 'flex',
|
|
157
|
+
flex: 1,
|
|
158
|
+
boxSizing: 'border-box',
|
|
159
|
+
overflow: 'hidden'
|
|
160
|
+
});
|
|
161
|
+
var FlexWrapper = function FlexWrapper(props) {
|
|
162
|
+
var children = props.children,
|
|
163
|
+
divProps = (0, _objectWithoutProperties2.default)(props, _excluded);
|
|
164
|
+
return (0, _react2.jsx)("div", (0, _extends2.default)({
|
|
165
|
+
css: flexWrapperStyles
|
|
166
|
+
}, divProps), children);
|
|
167
|
+
};
|
|
168
|
+
var ElementBrowserWrapper = (0, _uiReact.withReactEditorViewOuterListeners)(FlexWrapper);
|
|
169
|
+
var _default = exports.default = InsertMenu;
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
+
Object.defineProperty(exports, "__esModule", {
|
|
5
|
+
value: true
|
|
6
|
+
});
|
|
7
|
+
exports.BlockInsertElementBrowser = void 0;
|
|
8
|
+
var _react = _interopRequireDefault(require("react"));
|
|
9
|
+
var _ui = require("@atlaskit/editor-common/ui");
|
|
10
|
+
var _InsertMenu = _interopRequireDefault(require("../ElementBrowser/InsertMenu"));
|
|
11
|
+
var _dropdownButton = require("./dropdown-button");
|
|
12
|
+
var BlockInsertElementBrowser = exports.BlockInsertElementBrowser = function BlockInsertElementBrowser(props) {
|
|
13
|
+
return /*#__PURE__*/_react.default.createElement(_react.default.Fragment, null, props.open && /*#__PURE__*/_react.default.createElement(_ui.Popup, {
|
|
14
|
+
target: props.plusButtonRef,
|
|
15
|
+
fitHeight: 500,
|
|
16
|
+
fitWidth: 350,
|
|
17
|
+
offset: [0, 3],
|
|
18
|
+
mountTo: props.popupsMountPoint,
|
|
19
|
+
boundariesElement: props.popupsBoundariesElement,
|
|
20
|
+
scrollableElement: props.popupsScrollableElement,
|
|
21
|
+
preventOverflow: true,
|
|
22
|
+
alignX: "right"
|
|
23
|
+
}, /*#__PURE__*/_react.default.createElement(_InsertMenu.default, {
|
|
24
|
+
editorView: props.editorView,
|
|
25
|
+
dropdownItems: props.items,
|
|
26
|
+
onInsert: props.onInsert,
|
|
27
|
+
toggleVisiblity: props.togglePlusMenuVisibility,
|
|
28
|
+
showElementBrowserLink: props.showElementBrowserLink,
|
|
29
|
+
pluginInjectionApi: props.pluginInjectionApi
|
|
30
|
+
})), /*#__PURE__*/_react.default.createElement(_dropdownButton.DropDownButton, {
|
|
31
|
+
"aria-expanded": props.open,
|
|
32
|
+
"aria-haspopup": true,
|
|
33
|
+
handleRef: props.onRef,
|
|
34
|
+
selected: props.open,
|
|
35
|
+
disabled: props.disabled,
|
|
36
|
+
onClick: props.onClick,
|
|
37
|
+
onKeyDown: props.onKeyDown,
|
|
38
|
+
spacing: props.spacing,
|
|
39
|
+
label: props.label,
|
|
40
|
+
"aria-keyshortcuts": "/"
|
|
41
|
+
}));
|
|
42
|
+
};
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
+
Object.defineProperty(exports, "__esModule", {
|
|
5
|
+
value: true
|
|
6
|
+
});
|
|
7
|
+
exports.BlockInsertMenuLegacy = void 0;
|
|
8
|
+
var _react = _interopRequireDefault(require("react"));
|
|
9
|
+
var _uiMenu = require("@atlaskit/editor-common/ui-menu");
|
|
10
|
+
var _editorSharedStyles = require("@atlaskit/editor-shared-styles");
|
|
11
|
+
var _dropdownButton = require("./dropdown-button");
|
|
12
|
+
var BlockInsertMenuLegacy = exports.BlockInsertMenuLegacy = function BlockInsertMenuLegacy(props) {
|
|
13
|
+
var items = props.items;
|
|
14
|
+
var dropdownItems = _react.default.useMemo(function () {
|
|
15
|
+
return [{
|
|
16
|
+
items: items
|
|
17
|
+
}];
|
|
18
|
+
}, [items]);
|
|
19
|
+
return /*#__PURE__*/_react.default.createElement(_uiMenu.DropdownMenuWithKeyboardNavigation, {
|
|
20
|
+
items: dropdownItems,
|
|
21
|
+
onItemActivated: props.onItemActivated,
|
|
22
|
+
onOpenChange: props.onOpenChange,
|
|
23
|
+
mountTo: props.popupsMountPoint,
|
|
24
|
+
boundariesElement: props.popupsBoundariesElement,
|
|
25
|
+
scrollableElement: props.popupsScrollableElement,
|
|
26
|
+
isOpen: props.open,
|
|
27
|
+
fitHeight: 188,
|
|
28
|
+
fitWidth: 175,
|
|
29
|
+
zIndex: _editorSharedStyles.akEditorMenuZIndex
|
|
30
|
+
}, /*#__PURE__*/_react.default.createElement(_dropdownButton.DropDownButton, {
|
|
31
|
+
"aria-expanded": props.open,
|
|
32
|
+
"aria-haspopup": true,
|
|
33
|
+
handleRef: props.onRef,
|
|
34
|
+
selected: props.open,
|
|
35
|
+
disabled: props.disabled,
|
|
36
|
+
onClick: props.onClick,
|
|
37
|
+
onKeyDown: props.onKeyDown,
|
|
38
|
+
spacing: props.spacing,
|
|
39
|
+
label: props.label,
|
|
40
|
+
"aria-keyshortcuts": "/"
|
|
41
|
+
}));
|
|
42
|
+
};
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
+
Object.defineProperty(exports, "__esModule", {
|
|
5
|
+
value: true
|
|
6
|
+
});
|
|
7
|
+
exports.BlockInsertMenu = void 0;
|
|
8
|
+
var _react = _interopRequireDefault(require("react"));
|
|
9
|
+
var _blockInsertElementBrowser = require("./block-insert-element-browser");
|
|
10
|
+
var _blockInsertMenuLegacy = require("./block-insert-menu-legacy");
|
|
11
|
+
var _dropdownButton = require("./dropdown-button");
|
|
12
|
+
var BlockInsertMenu = exports.BlockInsertMenu = function BlockInsertMenu(props) {
|
|
13
|
+
if (props.items.length === 0) {
|
|
14
|
+
return null;
|
|
15
|
+
}
|
|
16
|
+
if (props.disabled) {
|
|
17
|
+
return /*#__PURE__*/_react.default.createElement("div", null, /*#__PURE__*/_react.default.createElement(_dropdownButton.DropDownButton, {
|
|
18
|
+
"aria-expanded": props.open,
|
|
19
|
+
"aria-haspopup": true,
|
|
20
|
+
handleRef: props.onRef,
|
|
21
|
+
selected: props.open,
|
|
22
|
+
disabled: props.disabled,
|
|
23
|
+
onClick: props.onClick,
|
|
24
|
+
onKeyDown: props.onKeyDown,
|
|
25
|
+
spacing: props.spacing,
|
|
26
|
+
label: props.label,
|
|
27
|
+
"aria-keyshortcuts": "/"
|
|
28
|
+
}));
|
|
29
|
+
}
|
|
30
|
+
if (props.replacePlusMenuWithElementBrowser) {
|
|
31
|
+
return /*#__PURE__*/_react.default.createElement(_blockInsertElementBrowser.BlockInsertElementBrowser, {
|
|
32
|
+
disabled: props.disabled,
|
|
33
|
+
editorView: props.editorView,
|
|
34
|
+
items: props.items,
|
|
35
|
+
label: props.label,
|
|
36
|
+
onClick: props.onClick,
|
|
37
|
+
onKeyDown: props.onKeyDown,
|
|
38
|
+
onInsert: props.onInsert,
|
|
39
|
+
onRef: props.onPlusButtonRef,
|
|
40
|
+
open: props.open,
|
|
41
|
+
plusButtonRef: props.plusButtonRef,
|
|
42
|
+
popupsBoundariesElement: props.popupsBoundariesElement,
|
|
43
|
+
popupsMountPoint: props.popupsMountPoint,
|
|
44
|
+
popupsScrollableElement: props.popupsScrollableElement,
|
|
45
|
+
spacing: props.spacing,
|
|
46
|
+
togglePlusMenuVisibility: props.togglePlusMenuVisibility,
|
|
47
|
+
showElementBrowserLink: props.showElementBrowserLink,
|
|
48
|
+
pluginInjectionApi: props.pluginInjectionApi
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
return /*#__PURE__*/_react.default.createElement(_blockInsertMenuLegacy.BlockInsertMenuLegacy, {
|
|
52
|
+
disabled: props.disabled,
|
|
53
|
+
items: props.items,
|
|
54
|
+
label: props.label,
|
|
55
|
+
onClick: props.onClick,
|
|
56
|
+
onKeyDown: props.onKeyDown,
|
|
57
|
+
onItemActivated: props.onItemActivated,
|
|
58
|
+
onOpenChange: props.onOpenChange,
|
|
59
|
+
onRef: props.onRef,
|
|
60
|
+
open: props.open,
|
|
61
|
+
popupsBoundariesElement: props.popupsBoundariesElement,
|
|
62
|
+
popupsMountPoint: props.popupsMountPoint,
|
|
63
|
+
popupsScrollableElement: props.popupsScrollableElement,
|
|
64
|
+
spacing: props.spacing
|
|
65
|
+
});
|
|
66
|
+
};
|