1 | "use strict";
|
2 |
|
3 | var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
4 | var _typeof = require("@babel/runtime/helpers/typeof");
|
5 | Object.defineProperty(exports, "__esModule", {
|
6 | value: true
|
7 | });
|
8 | exports.insertBlockPlugin = void 0;
|
9 | var _react = _interopRequireWildcard(require("react"));
|
10 | var _analytics = require("@atlaskit/editor-common/analytics");
|
11 | var _hooks = require("@atlaskit/editor-common/hooks");
|
12 | var _providerFactory = require("@atlaskit/editor-common/provider-factory");
|
13 | var _types = require("@atlaskit/editor-common/types");
|
14 | var _consts = require("@atlaskit/editor-plugin-block-type/consts");
|
15 | var _ToolbarInsertBlock = _interopRequireDefault(require("./ui/ToolbarInsertBlock"));
|
16 | function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(e) { return e ? t : r; })(e); }
|
17 | function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != _typeof(e) && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && Object.prototype.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
|
18 | var toolbarSizeToButtons = function toolbarSizeToButtons(toolbarSize) {
|
19 | switch (toolbarSize) {
|
20 | case _types.ToolbarSize.XXL:
|
21 | case _types.ToolbarSize.XL:
|
22 | case _types.ToolbarSize.L:
|
23 | case _types.ToolbarSize.M:
|
24 | return 7;
|
25 | case _types.ToolbarSize.S:
|
26 | return 2;
|
27 | default:
|
28 | return 0;
|
29 | }
|
30 | };
|
31 |
|
32 |
|
33 |
|
34 |
|
35 | function handleInsertBlockType(insertCodeBlock, insertPanel, insertBlockQuote) {
|
36 | return function (name) {
|
37 | if (name === _consts.CODE_BLOCK.name && insertCodeBlock) {
|
38 | return insertCodeBlock(_analytics.INPUT_METHOD.TOOLBAR);
|
39 | }
|
40 | if (name === _consts.PANEL.name && insertPanel) {
|
41 | return insertPanel(_analytics.INPUT_METHOD.TOOLBAR);
|
42 | }
|
43 | if (name === _consts.BLOCK_QUOTE.name && insertBlockQuote) {
|
44 | return insertBlockQuote(_analytics.INPUT_METHOD.TOOLBAR);
|
45 | }
|
46 | return function () {
|
47 | return false;
|
48 | };
|
49 | };
|
50 | }
|
51 | var insertBlockPlugin = exports.insertBlockPlugin = function insertBlockPlugin(_ref) {
|
52 | var _ref$config = _ref.config,
|
53 | options = _ref$config === void 0 ? {} : _ref$config,
|
54 | api = _ref.api;
|
55 | var toggleDropdownMenuOptionsRef = {
|
56 | current: null
|
57 | };
|
58 | var registerToggleDropdownMenuOptions = function registerToggleDropdownMenuOptions(cb) {
|
59 | toggleDropdownMenuOptionsRef.current = cb;
|
60 | return function () {
|
61 | toggleDropdownMenuOptionsRef.current = null;
|
62 | };
|
63 | };
|
64 | return {
|
65 | name: 'insertBlock',
|
66 | actions: {
|
67 | toggleAdditionalMenu: function toggleAdditionalMenu() {
|
68 | var toggle = toggleDropdownMenuOptionsRef.current;
|
69 | if (!toggle) {
|
70 | return;
|
71 | }
|
72 | toggle();
|
73 | }
|
74 | },
|
75 | usePluginHook: function usePluginHook() {
|
76 | (0, _react.useLayoutEffect)(function () {
|
77 | return function () {
|
78 | toggleDropdownMenuOptionsRef.current = null;
|
79 | };
|
80 | }, []);
|
81 | },
|
82 | primaryToolbarComponent: function primaryToolbarComponent(_ref2) {
|
83 | var editorView = _ref2.editorView,
|
84 | editorActions = _ref2.editorActions,
|
85 | dispatchAnalyticsEvent = _ref2.dispatchAnalyticsEvent,
|
86 | providerFactory = _ref2.providerFactory,
|
87 | popupsMountPoint = _ref2.popupsMountPoint,
|
88 | popupsBoundariesElement = _ref2.popupsBoundariesElement,
|
89 | popupsScrollableElement = _ref2.popupsScrollableElement,
|
90 | toolbarSize = _ref2.toolbarSize,
|
91 | disabled = _ref2.disabled,
|
92 | isToolbarReducedSpacing = _ref2.isToolbarReducedSpacing,
|
93 | isLastItem = _ref2.isLastItem;
|
94 | var renderNode = function renderNode(providers) {
|
95 | return _react.default.createElement(ToolbarInsertBlockWithInjectionApi, {
|
96 | pluginInjectionApi: api,
|
97 | editorView: editorView,
|
98 | editorActions: editorActions,
|
99 | dispatchAnalyticsEvent: dispatchAnalyticsEvent,
|
100 | providerFactory: providerFactory,
|
101 | popupsMountPoint: popupsMountPoint,
|
102 | popupsBoundariesElement: popupsBoundariesElement,
|
103 | popupsScrollableElement: popupsScrollableElement,
|
104 | toolbarSize: toolbarSize,
|
105 | disabled: disabled,
|
106 | isToolbarReducedSpacing: isToolbarReducedSpacing,
|
107 | isLastItem: isLastItem,
|
108 | providers: providers,
|
109 | options: options,
|
110 | registerToggleDropdownMenuOptions: registerToggleDropdownMenuOptions
|
111 | });
|
112 | };
|
113 | return _react.default.createElement(_providerFactory.WithProviders, {
|
114 | providerFactory: providerFactory,
|
115 | providers: ['emojiProvider'],
|
116 | renderNode: renderNode
|
117 | });
|
118 | }
|
119 | };
|
120 | };
|
121 | function ToolbarInsertBlockWithInjectionApi(_ref3) {
|
122 | var _ref4, _ref5, _pluginInjectionApi$i, _pluginInjectionApi$c, _pluginInjectionApi$p, _pluginInjectionApi$b, _pluginInjectionApi$e;
|
123 | var editorView = _ref3.editorView,
|
124 | editorActions = _ref3.editorActions,
|
125 | dispatchAnalyticsEvent = _ref3.dispatchAnalyticsEvent,
|
126 | popupsMountPoint = _ref3.popupsMountPoint,
|
127 | popupsBoundariesElement = _ref3.popupsBoundariesElement,
|
128 | popupsScrollableElement = _ref3.popupsScrollableElement,
|
129 | toolbarSize = _ref3.toolbarSize,
|
130 | disabled = _ref3.disabled,
|
131 | isToolbarReducedSpacing = _ref3.isToolbarReducedSpacing,
|
132 | isLastItem = _ref3.isLastItem,
|
133 | providers = _ref3.providers,
|
134 | pluginInjectionApi = _ref3.pluginInjectionApi,
|
135 | options = _ref3.options,
|
136 | registerToggleDropdownMenuOptions = _ref3.registerToggleDropdownMenuOptions;
|
137 | var buttons = toolbarSizeToButtons(toolbarSize);
|
138 | var _useSharedPluginState = (0, _hooks.useSharedPluginState)(pluginInjectionApi, ['hyperlink', 'date', 'imageUpload', 'mention', 'emoji', 'blockType', 'media', 'typeAhead', 'placeholderText']),
|
139 | dateState = _useSharedPluginState.dateState,
|
140 | hyperlinkState = _useSharedPluginState.hyperlinkState,
|
141 | imageUploadState = _useSharedPluginState.imageUploadState,
|
142 | mentionState = _useSharedPluginState.mentionState,
|
143 | emojiState = _useSharedPluginState.emojiState,
|
144 | blockTypeState = _useSharedPluginState.blockTypeState,
|
145 | mediaState = _useSharedPluginState.mediaState,
|
146 | typeAheadState = _useSharedPluginState.typeAheadState,
|
147 | placeholderTextState = _useSharedPluginState.placeholderTextState;
|
148 | return _react.default.createElement(_ToolbarInsertBlock.default, {
|
149 | pluginInjectionApi: pluginInjectionApi,
|
150 | buttons: buttons,
|
151 | isReducedSpacing: isToolbarReducedSpacing,
|
152 | isDisabled: disabled,
|
153 | isTypeAheadAllowed: Boolean(typeAheadState === null || typeAheadState === void 0 ? void 0 : typeAheadState.isAllowed),
|
154 | editorView: editorView,
|
155 | tableSupported: !!editorView.state.schema.nodes.table,
|
156 | tableSelectorSupported: options.tableSelectorSupported && !!editorView.state.schema.nodes.table,
|
157 | actionSupported: !!editorView.state.schema.nodes.taskItem,
|
158 | mentionsSupported: !!(mentionState && mentionState.mentionProvider),
|
159 | mentionsDisabled: !!(mentionState && !mentionState.canInsertMention),
|
160 | decisionSupported: !!editorView.state.schema.nodes.decisionItem,
|
161 | dateEnabled: !!dateState,
|
162 | placeholderTextEnabled: placeholderTextState && placeholderTextState.allowInserting,
|
163 | layoutSectionEnabled: Boolean(pluginInjectionApi === null || pluginInjectionApi === void 0 ? void 0 : pluginInjectionApi.layout),
|
164 | expandEnabled: !!options.allowExpand,
|
165 | mediaUploadsEnabled: (_ref4 = mediaState && mediaState.allowsUploads) !== null && _ref4 !== void 0 ? _ref4 : undefined,
|
166 | onShowMediaPicker: (_ref5 = mediaState && mediaState.showMediaPicker) !== null && _ref5 !== void 0 ? _ref5 : undefined,
|
167 | mediaSupported: !!mediaState,
|
168 | imageUploadSupported: !!(pluginInjectionApi !== null && pluginInjectionApi !== void 0 && pluginInjectionApi.imageUpload),
|
169 | imageUploadEnabled: imageUploadState === null || imageUploadState === void 0 ? void 0 : imageUploadState.enabled,
|
170 | handleImageUpload: pluginInjectionApi === null || pluginInjectionApi === void 0 || (_pluginInjectionApi$i = pluginInjectionApi.imageUpload) === null || _pluginInjectionApi$i === void 0 ? void 0 : _pluginInjectionApi$i.actions.startUpload,
|
171 | availableWrapperBlockTypes: blockTypeState && blockTypeState.availableWrapperBlockTypes,
|
172 | linkSupported: !!hyperlinkState,
|
173 | linkDisabled: !hyperlinkState || !hyperlinkState.canInsertLink || !!hyperlinkState.activeLinkMark,
|
174 | emojiDisabled: !emojiState || !providers.emojiProvider,
|
175 | emojiProvider: providers.emojiProvider,
|
176 | nativeStatusSupported: options.nativeStatusSupported,
|
177 | horizontalRuleEnabled: options.horizontalRuleEnabled,
|
178 | 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),
|
179 | onInsertMacroFromMacroBrowser: pluginInjectionApi === null || pluginInjectionApi === void 0 || (_pluginInjectionApi$e = pluginInjectionApi.extension) === null || _pluginInjectionApi$e === void 0 ? void 0 : _pluginInjectionApi$e.actions.insertMacroFromMacroBrowser,
|
180 | popupsMountPoint: popupsMountPoint,
|
181 | popupsBoundariesElement: popupsBoundariesElement,
|
182 | popupsScrollableElement: popupsScrollableElement,
|
183 | insertMenuItems: options.insertMenuItems,
|
184 | editorActions: editorActions,
|
185 | dispatchAnalyticsEvent: dispatchAnalyticsEvent,
|
186 | replacePlusMenuWithElementBrowser: options.replacePlusMenuWithElementBrowser,
|
187 | showElementBrowserLink: options.showElementBrowserLink,
|
188 | showSeparator: !isLastItem && toolbarSize <= _types.ToolbarSize.S,
|
189 | registerToggleDropdownMenuOptions: registerToggleDropdownMenuOptions
|
190 | });
|
191 | } |
\ | No newline at end of file |