@atlaskit/editor-plugin-text-formatting 1.15.7 → 1.16.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 +8 -0
- package/dist/cjs/input-method-utils.js +15 -0
- package/dist/cjs/plugin.js +39 -8
- package/dist/cjs/ui/FloatingToolbarComponent.js +71 -0
- package/dist/cjs/ui/PrimaryToolbarComponent.js +3 -1
- package/dist/cjs/ui/Toolbar/bold-button.js +61 -0
- package/dist/cjs/ui/Toolbar/dropdown-menu.js +24 -2
- package/dist/cjs/ui/Toolbar/hooks/clear-formatting-icon.js +5 -4
- package/dist/cjs/ui/Toolbar/hooks/formatting-icons.js +28 -23
- package/dist/cjs/ui/Toolbar/index.js +13 -6
- package/dist/cjs/ui/Toolbar/types.js +6 -1
- package/dist/es2019/input-method-utils.js +7 -0
- package/dist/es2019/plugin.js +39 -8
- package/dist/es2019/ui/FloatingToolbarComponent.js +64 -0
- package/dist/es2019/ui/PrimaryToolbarComponent.js +3 -1
- package/dist/es2019/ui/Toolbar/bold-button.js +54 -0
- package/dist/es2019/ui/Toolbar/dropdown-menu.js +24 -2
- package/dist/es2019/ui/Toolbar/hooks/clear-formatting-icon.js +4 -3
- package/dist/es2019/ui/Toolbar/hooks/formatting-icons.js +28 -23
- package/dist/es2019/ui/Toolbar/index.js +13 -6
- package/dist/es2019/ui/Toolbar/types.js +5 -0
- package/dist/esm/input-method-utils.js +8 -0
- package/dist/esm/plugin.js +39 -8
- package/dist/esm/ui/FloatingToolbarComponent.js +63 -0
- package/dist/esm/ui/PrimaryToolbarComponent.js +3 -1
- package/dist/esm/ui/Toolbar/bold-button.js +53 -0
- package/dist/esm/ui/Toolbar/dropdown-menu.js +24 -2
- package/dist/esm/ui/Toolbar/hooks/clear-formatting-icon.js +5 -4
- package/dist/esm/ui/Toolbar/hooks/formatting-icons.js +29 -24
- package/dist/esm/ui/Toolbar/index.js +13 -6
- package/dist/esm/ui/Toolbar/types.js +5 -0
- package/dist/types/commands/clear-formatting.d.ts +2 -2
- package/dist/types/input-method-utils.d.ts +6 -0
- package/dist/types/ui/FloatingToolbarComponent.d.ts +17 -0
- package/dist/types/ui/Toolbar/bold-button.d.ts +17 -0
- package/dist/types/ui/Toolbar/dropdown-menu.d.ts +4 -2
- package/dist/types/ui/Toolbar/hooks/clear-formatting-icon.d.ts +3 -2
- package/dist/types/ui/Toolbar/hooks/formatting-icons.d.ts +3 -2
- package/dist/types/ui/Toolbar/index.d.ts +2 -0
- package/dist/types/ui/Toolbar/types.d.ts +4 -0
- package/dist/types-ts4.5/commands/clear-formatting.d.ts +2 -2
- package/dist/types-ts4.5/input-method-utils.d.ts +6 -0
- package/dist/types-ts4.5/ui/FloatingToolbarComponent.d.ts +17 -0
- package/dist/types-ts4.5/ui/Toolbar/bold-button.d.ts +17 -0
- package/dist/types-ts4.5/ui/Toolbar/dropdown-menu.d.ts +4 -2
- package/dist/types-ts4.5/ui/Toolbar/hooks/clear-formatting-icon.d.ts +3 -2
- package/dist/types-ts4.5/ui/Toolbar/hooks/formatting-icons.d.ts +3 -2
- package/dist/types-ts4.5/ui/Toolbar/index.d.ts +2 -0
- package/dist/types-ts4.5/ui/Toolbar/types.d.ts +4 -0
- package/package.json +6 -5
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @jsxRuntime classic
|
|
3
|
+
* @jsx jsx
|
|
4
|
+
*/
|
|
5
|
+
import { useMemo } from 'react';
|
|
6
|
+
|
|
7
|
+
// eslint-disable-next-line @atlaskit/ui-styling-standard/use-compiled -- Ignored via go/DSP-18766
|
|
8
|
+
import { jsx } from '@emotion/react';
|
|
9
|
+
import { injectIntl } from 'react-intl-next';
|
|
10
|
+
import { useSharedPluginState } from '@atlaskit/editor-common/hooks';
|
|
11
|
+
import { ToolbarSize } from '@atlaskit/editor-common/types';
|
|
12
|
+
import { FormattingTextDropdownMenu } from './Toolbar/dropdown-menu';
|
|
13
|
+
import { useClearIcon } from './Toolbar/hooks/clear-formatting-icon';
|
|
14
|
+
import { useFormattingIcons } from './Toolbar/hooks/formatting-icons';
|
|
15
|
+
import { ToolbarType } from './Toolbar/types';
|
|
16
|
+
const FloatingToolbarSettings = {
|
|
17
|
+
disabled: false,
|
|
18
|
+
isReducedSpacing: true,
|
|
19
|
+
shouldUseResponsiveToolbar: false,
|
|
20
|
+
toolbarSize: ToolbarSize.XXXS,
|
|
21
|
+
hasMoreButton: false,
|
|
22
|
+
moreButtonLabel: '',
|
|
23
|
+
toolbarType: ToolbarType.FLOATING
|
|
24
|
+
};
|
|
25
|
+
const FloatingToolbarTextFormat = ({
|
|
26
|
+
api,
|
|
27
|
+
editorAnalyticsAPI,
|
|
28
|
+
editorView,
|
|
29
|
+
intl
|
|
30
|
+
}) => {
|
|
31
|
+
const {
|
|
32
|
+
textFormattingState
|
|
33
|
+
} = useSharedPluginState(api, ['textFormatting']);
|
|
34
|
+
const defaultIcons = useFormattingIcons({
|
|
35
|
+
schema: editorView.state.schema,
|
|
36
|
+
intl,
|
|
37
|
+
isToolbarDisabled: FloatingToolbarSettings.disabled,
|
|
38
|
+
editorAnalyticsAPI,
|
|
39
|
+
textFormattingState,
|
|
40
|
+
toolbarType: FloatingToolbarSettings.toolbarType
|
|
41
|
+
});
|
|
42
|
+
const clearIcon = useClearIcon({
|
|
43
|
+
textFormattingState,
|
|
44
|
+
intl,
|
|
45
|
+
editorAnalyticsAPI,
|
|
46
|
+
toolbarType: FloatingToolbarSettings.toolbarType
|
|
47
|
+
});
|
|
48
|
+
const items = useMemo(() => {
|
|
49
|
+
if (!clearIcon) {
|
|
50
|
+
return defaultIcons;
|
|
51
|
+
}
|
|
52
|
+
return [...defaultIcons, clearIcon];
|
|
53
|
+
}, [clearIcon, defaultIcons]);
|
|
54
|
+
return jsx(FormattingTextDropdownMenu, {
|
|
55
|
+
editorView: editorView,
|
|
56
|
+
items: items,
|
|
57
|
+
isReducedSpacing: FloatingToolbarSettings.isReducedSpacing,
|
|
58
|
+
moreButtonLabel: FloatingToolbarSettings.moreButtonLabel,
|
|
59
|
+
hasFormattingActive: FloatingToolbarSettings.hasMoreButton,
|
|
60
|
+
hasMoreButton: FloatingToolbarSettings.hasMoreButton,
|
|
61
|
+
intl: intl
|
|
62
|
+
});
|
|
63
|
+
};
|
|
64
|
+
export const FloatingToolbarTextFormalWithIntl = injectIntl(FloatingToolbarTextFormat);
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
import { useSharedPluginState } from '@atlaskit/editor-common/hooks';
|
|
3
3
|
import Toolbar from './Toolbar';
|
|
4
|
+
import { ToolbarType } from './Toolbar/types';
|
|
4
5
|
export function PrimaryToolbarComponent({
|
|
5
6
|
api,
|
|
6
7
|
popupsMountPoint,
|
|
@@ -25,6 +26,7 @@ export function PrimaryToolbarComponent({
|
|
|
25
26
|
isToolbarDisabled: disabled,
|
|
26
27
|
shouldUseResponsiveToolbar: shouldUseResponsiveToolbar,
|
|
27
28
|
editorAnalyticsAPI: api === null || api === void 0 ? void 0 : (_api$analytics = api.analytics) === null || _api$analytics === void 0 ? void 0 : _api$analytics.actions,
|
|
28
|
-
api: api
|
|
29
|
+
api: api,
|
|
30
|
+
toolbarType: ToolbarType.PRIMARY
|
|
29
31
|
});
|
|
30
32
|
}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @jsxRuntime classic
|
|
3
|
+
* @jsx jsx
|
|
4
|
+
*/
|
|
5
|
+
import React from 'react';
|
|
6
|
+
|
|
7
|
+
// eslint-disable-next-line @atlaskit/ui-styling-standard/use-compiled -- Ignored via go/DSP-18766
|
|
8
|
+
import { jsx } from '@emotion/react';
|
|
9
|
+
import { expandIconContainerStyle, triggerWrapperStyles, triggerWrapperStylesWithPadding } from '@atlaskit/editor-common/styles';
|
|
10
|
+
import { ToolbarButton } from '@atlaskit/editor-common/ui-menu';
|
|
11
|
+
import BoldIcon from '@atlaskit/icon/core/migration/text-bold--editor-bold';
|
|
12
|
+
import ChevronDownIcon from '@atlaskit/icon/utility/migration/chevron-down';
|
|
13
|
+
import { fg } from '@atlaskit/platform-feature-flags';
|
|
14
|
+
export const BoldToolbarButton = ({
|
|
15
|
+
label,
|
|
16
|
+
isReducedSpacing,
|
|
17
|
+
isDisabled,
|
|
18
|
+
isSelected,
|
|
19
|
+
'aria-expanded': ariaExpanded,
|
|
20
|
+
onClick,
|
|
21
|
+
onKeyDown
|
|
22
|
+
}) => {
|
|
23
|
+
return jsx(ToolbarButton, {
|
|
24
|
+
testId: 'ak-editor-selection-toolbar-format-text-button',
|
|
25
|
+
spacing: isReducedSpacing ? 'none' : 'default',
|
|
26
|
+
disabled: isDisabled,
|
|
27
|
+
selected: isSelected,
|
|
28
|
+
"aria-label": label,
|
|
29
|
+
"aria-expanded": ariaExpanded,
|
|
30
|
+
"aria-haspopup": true,
|
|
31
|
+
title: label,
|
|
32
|
+
onClick: onClick,
|
|
33
|
+
onKeyDown: onKeyDown,
|
|
34
|
+
iconBefore: jsx("div", {
|
|
35
|
+
css:
|
|
36
|
+
// eslint-disable-next-line @atlaskit/platform/ensure-feature-flag-registration
|
|
37
|
+
fg('platform-visual-refresh-icons') ?
|
|
38
|
+
// eslint-disable-next-line @atlaskit/design-system/consistent-css-prop-usage, @atlaskit/ui-styling-standard/no-imported-style-values
|
|
39
|
+
triggerWrapperStylesWithPadding :
|
|
40
|
+
// eslint-disable-next-line @atlaskit/design-system/consistent-css-prop-usage, @atlaskit/ui-styling-standard/no-imported-style-values
|
|
41
|
+
triggerWrapperStyles
|
|
42
|
+
}, jsx(BoldIcon, {
|
|
43
|
+
color: "currentColor",
|
|
44
|
+
spacing: "spacious",
|
|
45
|
+
label: ""
|
|
46
|
+
}), jsx("span", {
|
|
47
|
+
css: expandIconContainerStyle
|
|
48
|
+
}, jsx(ChevronDownIcon, {
|
|
49
|
+
label: "",
|
|
50
|
+
color: "currentColor",
|
|
51
|
+
LEGACY_margin: "0 0 0 -8px"
|
|
52
|
+
})))
|
|
53
|
+
});
|
|
54
|
+
};
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import React, { useCallback, useMemo, useState } from 'react';
|
|
2
|
+
import { toolbarMessages } from '@atlaskit/editor-common/messages';
|
|
2
3
|
import { DropdownMenuWithKeyboardNavigation as DropdownMenu } from '@atlaskit/editor-common/ui-menu';
|
|
3
4
|
import { akEditorMenuZIndex } from '@atlaskit/editor-shared-styles';
|
|
5
|
+
import { BoldToolbarButton } from './bold-button';
|
|
4
6
|
import { useMenuState } from './hooks/menu-state';
|
|
5
7
|
import { MoreButton } from './more-button';
|
|
6
8
|
export const FormattingTextDropdownMenu = /*#__PURE__*/React.memo(({
|
|
@@ -11,7 +13,9 @@ export const FormattingTextDropdownMenu = /*#__PURE__*/React.memo(({
|
|
|
11
13
|
hasFormattingActive,
|
|
12
14
|
popupsBoundariesElement,
|
|
13
15
|
popupsMountPoint,
|
|
14
|
-
popupsScrollableElement
|
|
16
|
+
popupsScrollableElement,
|
|
17
|
+
hasMoreButton,
|
|
18
|
+
intl
|
|
15
19
|
}) => {
|
|
16
20
|
const [isMenuOpen, toggleMenu, closeMenu] = useMenuState();
|
|
17
21
|
const [isOpenedByKeyboard, setIsOpenedByKeyboard] = useState(false);
|
|
@@ -47,7 +51,7 @@ export const FormattingTextDropdownMenu = /*#__PURE__*/React.memo(({
|
|
|
47
51
|
}
|
|
48
52
|
return isOpenedByKeyboard;
|
|
49
53
|
}
|
|
50
|
-
}, /*#__PURE__*/React.createElement(MoreButton, {
|
|
54
|
+
}, hasMoreButton ? /*#__PURE__*/React.createElement(MoreButton, {
|
|
51
55
|
isSelected: isMenuOpen || hasFormattingActive,
|
|
52
56
|
label: moreButtonLabel,
|
|
53
57
|
isReducedSpacing: isReducedSpacing,
|
|
@@ -64,5 +68,23 @@ export const FormattingTextDropdownMenu = /*#__PURE__*/React.memo(({
|
|
|
64
68
|
}
|
|
65
69
|
},
|
|
66
70
|
"aria-expanded": isMenuOpen
|
|
71
|
+
}) : /*#__PURE__*/React.createElement(BoldToolbarButton, {
|
|
72
|
+
isReducedSpacing: isReducedSpacing,
|
|
73
|
+
isDisabled: false,
|
|
74
|
+
isSelected: isMenuOpen,
|
|
75
|
+
label: intl.formatMessage(toolbarMessages.textFormat),
|
|
76
|
+
"aria-expanded": isMenuOpen,
|
|
77
|
+
"aria-haspopup": true,
|
|
78
|
+
onClick: () => {
|
|
79
|
+
toggleMenu();
|
|
80
|
+
setIsOpenedByKeyboard(false);
|
|
81
|
+
},
|
|
82
|
+
onKeyDown: event => {
|
|
83
|
+
if (event.key === 'Enter' || event.key === ' ') {
|
|
84
|
+
event.preventDefault();
|
|
85
|
+
toggleMenu();
|
|
86
|
+
setIsOpenedByKeyboard(true);
|
|
87
|
+
}
|
|
88
|
+
}
|
|
67
89
|
}));
|
|
68
90
|
});
|
|
@@ -6,20 +6,21 @@ import { useCallback, useMemo } from 'react';
|
|
|
6
6
|
|
|
7
7
|
// eslint-disable-next-line @atlaskit/ui-styling-standard/use-compiled -- Ignored via go/DSP-18766
|
|
8
8
|
import { jsx } from '@emotion/react';
|
|
9
|
-
import { INPUT_METHOD } from '@atlaskit/editor-common/analytics';
|
|
10
9
|
import { clearFormatting as clearFormattingKeymap, tooltip } from '@atlaskit/editor-common/keymaps';
|
|
11
10
|
import { toolbarMessages } from '@atlaskit/editor-common/messages';
|
|
12
11
|
import { shortcutStyle } from '@atlaskit/editor-shared-styles/shortcut';
|
|
13
12
|
import { clearFormattingWithAnalytics } from '../../../commands/clear-formatting';
|
|
13
|
+
import { getInputMethod } from '../../../input-method-utils';
|
|
14
14
|
export const useClearIcon = ({
|
|
15
15
|
intl,
|
|
16
16
|
textFormattingState,
|
|
17
|
-
editorAnalyticsAPI
|
|
17
|
+
editorAnalyticsAPI,
|
|
18
|
+
toolbarType
|
|
18
19
|
}) => {
|
|
19
20
|
const isPluginAvailable = Boolean(textFormattingState);
|
|
20
21
|
const formattingIsPresent = Boolean(textFormattingState === null || textFormattingState === void 0 ? void 0 : textFormattingState.formattingIsPresent);
|
|
21
22
|
const clearFormattingLabel = intl.formatMessage(toolbarMessages.clearFormatting);
|
|
22
|
-
const clearFormattingToolbar = useCallback((state, dispatch) => clearFormattingWithAnalytics(
|
|
23
|
+
const clearFormattingToolbar = useCallback((state, dispatch) => clearFormattingWithAnalytics(getInputMethod(toolbarType), editorAnalyticsAPI)(state, dispatch), [editorAnalyticsAPI, toolbarType]);
|
|
23
24
|
return useMemo(() => {
|
|
24
25
|
if (!isPluginAvailable) {
|
|
25
26
|
return null;
|
|
@@ -6,7 +6,7 @@ import React, { useMemo } from 'react';
|
|
|
6
6
|
|
|
7
7
|
// eslint-disable-next-line @atlaskit/ui-styling-standard/use-compiled -- Ignored via go/DSP-18766
|
|
8
8
|
import { jsx } from '@emotion/react';
|
|
9
|
-
import {
|
|
9
|
+
import { TOOLBAR_ACTION_SUBJECT_ID } from '@atlaskit/editor-common/analytics';
|
|
10
10
|
import { getAriaKeyshortcuts, toggleBold, toggleCode, toggleItalic, toggleStrikethrough, toggleSubscript, toggleSuperscript, toggleUnderline, tooltip, ToolTipContent } from '@atlaskit/editor-common/keymaps';
|
|
11
11
|
import { toolbarMessages } from '@atlaskit/editor-common/messages';
|
|
12
12
|
import { editorCommandToPMCommand } from '@atlaskit/editor-common/preset';
|
|
@@ -14,12 +14,13 @@ import { shortcutStyle } from '@atlaskit/editor-shared-styles/shortcut';
|
|
|
14
14
|
import BoldIcon from '@atlaskit/icon/core/migration/text-bold--editor-bold';
|
|
15
15
|
import ItalicIcon from '@atlaskit/icon/core/migration/text-italic--editor-italic';
|
|
16
16
|
import { toggleCodeWithAnalytics, toggleEmWithAnalytics, toggleStrikeWithAnalytics, toggleStrongWithAnalytics, toggleSubscriptWithAnalytics, toggleSuperscriptWithAnalytics, toggleUnderlineWithAnalytics } from '../../../commands';
|
|
17
|
+
import { getInputMethod } from '../../../input-method-utils';
|
|
17
18
|
import { IconTypes } from '../types';
|
|
18
|
-
const
|
|
19
|
-
const IconButtons = editorAnalyticsAPI => ({
|
|
19
|
+
const withInputMethod = (toolbarType, func) => editorCommandToPMCommand(func(getInputMethod(toolbarType)));
|
|
20
|
+
const IconButtons = (editorAnalyticsAPI, toolbarType) => ({
|
|
20
21
|
strong: {
|
|
21
22
|
buttonId: TOOLBAR_ACTION_SUBJECT_ID.TEXT_FORMATTING_STRONG,
|
|
22
|
-
command:
|
|
23
|
+
command: withInputMethod(toolbarType, toggleStrongWithAnalytics(editorAnalyticsAPI)),
|
|
23
24
|
message: toolbarMessages.bold,
|
|
24
25
|
tooltipKeymap: toggleBold,
|
|
25
26
|
component: () => jsx(BoldIcon, {
|
|
@@ -30,7 +31,7 @@ const IconButtons = editorAnalyticsAPI => ({
|
|
|
30
31
|
},
|
|
31
32
|
em: {
|
|
32
33
|
buttonId: TOOLBAR_ACTION_SUBJECT_ID.TEXT_FORMATTING_ITALIC,
|
|
33
|
-
command:
|
|
34
|
+
command: withInputMethod(toolbarType, toggleEmWithAnalytics(editorAnalyticsAPI)),
|
|
34
35
|
message: toolbarMessages.italic,
|
|
35
36
|
tooltipKeymap: toggleItalic,
|
|
36
37
|
component: () => jsx(ItalicIcon, {
|
|
@@ -40,27 +41,27 @@ const IconButtons = editorAnalyticsAPI => ({
|
|
|
40
41
|
})
|
|
41
42
|
},
|
|
42
43
|
underline: {
|
|
43
|
-
command:
|
|
44
|
+
command: withInputMethod(toolbarType, toggleUnderlineWithAnalytics(editorAnalyticsAPI)),
|
|
44
45
|
message: toolbarMessages.underline,
|
|
45
46
|
tooltipKeymap: toggleUnderline
|
|
46
47
|
},
|
|
47
48
|
strike: {
|
|
48
|
-
command:
|
|
49
|
+
command: withInputMethod(toolbarType, toggleStrikeWithAnalytics(editorAnalyticsAPI)),
|
|
49
50
|
message: toolbarMessages.strike,
|
|
50
51
|
tooltipKeymap: toggleStrikethrough
|
|
51
52
|
},
|
|
52
53
|
code: {
|
|
53
|
-
command:
|
|
54
|
+
command: withInputMethod(toolbarType, toggleCodeWithAnalytics(editorAnalyticsAPI)),
|
|
54
55
|
message: toolbarMessages.code,
|
|
55
56
|
tooltipKeymap: toggleCode
|
|
56
57
|
},
|
|
57
58
|
subscript: {
|
|
58
|
-
command:
|
|
59
|
+
command: withInputMethod(toolbarType, toggleSubscriptWithAnalytics(editorAnalyticsAPI)),
|
|
59
60
|
message: toolbarMessages.subscript,
|
|
60
61
|
tooltipKeymap: toggleSubscript
|
|
61
62
|
},
|
|
62
63
|
superscript: {
|
|
63
|
-
command:
|
|
64
|
+
command: withInputMethod(toolbarType, toggleSuperscriptWithAnalytics(editorAnalyticsAPI)),
|
|
64
65
|
message: toolbarMessages.superscript,
|
|
65
66
|
tooltipKeymap: toggleSuperscript
|
|
66
67
|
}
|
|
@@ -70,9 +71,10 @@ const getIcon = ({
|
|
|
70
71
|
isDisabled,
|
|
71
72
|
isActive,
|
|
72
73
|
intl,
|
|
73
|
-
editorAnalyticsAPI
|
|
74
|
+
editorAnalyticsAPI,
|
|
75
|
+
toolbarType
|
|
74
76
|
}) => {
|
|
75
|
-
const icon = IconButtons(editorAnalyticsAPI)[iconType];
|
|
77
|
+
const icon = IconButtons(editorAnalyticsAPI, toolbarType)[iconType];
|
|
76
78
|
const content = intl.formatMessage(icon.message);
|
|
77
79
|
const {
|
|
78
80
|
tooltipKeymap
|
|
@@ -136,7 +138,7 @@ const buildMenuIconState = iconMark => ({
|
|
|
136
138
|
hasSchemaMark
|
|
137
139
|
};
|
|
138
140
|
};
|
|
139
|
-
const buildIcon = (iconMark, editorAnalyticsAPI) => {
|
|
141
|
+
const buildIcon = (iconMark, editorAnalyticsAPI, toolbarType) => {
|
|
140
142
|
const getState = buildMenuIconState(iconMark);
|
|
141
143
|
return ({
|
|
142
144
|
schema,
|
|
@@ -159,7 +161,8 @@ const buildIcon = (iconMark, editorAnalyticsAPI) => {
|
|
|
159
161
|
isDisabled: isToolbarDisabled || isDisabled,
|
|
160
162
|
isActive,
|
|
161
163
|
intl,
|
|
162
|
-
editorAnalyticsAPI
|
|
164
|
+
editorAnalyticsAPI,
|
|
165
|
+
toolbarType
|
|
163
166
|
}), [isToolbarDisabled, isDisabled, isActive, intl]);
|
|
164
167
|
const shouldRenderIcon = hasSchemaMark && !isHidden;
|
|
165
168
|
return useMemo(() => shouldRenderIcon ? iconComponent : null, [shouldRenderIcon, iconComponent]);
|
|
@@ -170,21 +173,23 @@ export const useFormattingIcons = ({
|
|
|
170
173
|
textFormattingState,
|
|
171
174
|
schema,
|
|
172
175
|
intl,
|
|
173
|
-
editorAnalyticsAPI
|
|
176
|
+
editorAnalyticsAPI,
|
|
177
|
+
toolbarType
|
|
174
178
|
}) => {
|
|
175
179
|
const props = {
|
|
176
180
|
schema,
|
|
177
181
|
textFormattingState,
|
|
178
182
|
intl,
|
|
179
|
-
isToolbarDisabled: Boolean(isToolbarDisabled)
|
|
183
|
+
isToolbarDisabled: Boolean(isToolbarDisabled),
|
|
184
|
+
toolbarType
|
|
180
185
|
};
|
|
181
|
-
const buildStrongIcon = buildIcon(IconTypes.strong, editorAnalyticsAPI);
|
|
182
|
-
const buildEmIcon = buildIcon(IconTypes.em, editorAnalyticsAPI);
|
|
183
|
-
const buildUnderlineIcon = buildIcon(IconTypes.underline, editorAnalyticsAPI);
|
|
184
|
-
const buildStrikeIcon = buildIcon(IconTypes.strike, editorAnalyticsAPI);
|
|
185
|
-
const buildCodeIcon = buildIcon(IconTypes.code, editorAnalyticsAPI);
|
|
186
|
-
const buildSubscriptIcon = buildIcon(IconTypes.subscript, editorAnalyticsAPI);
|
|
187
|
-
const buildSuperscriptIcon = buildIcon(IconTypes.superscript, editorAnalyticsAPI);
|
|
186
|
+
const buildStrongIcon = buildIcon(IconTypes.strong, editorAnalyticsAPI, toolbarType);
|
|
187
|
+
const buildEmIcon = buildIcon(IconTypes.em, editorAnalyticsAPI, toolbarType);
|
|
188
|
+
const buildUnderlineIcon = buildIcon(IconTypes.underline, editorAnalyticsAPI, toolbarType);
|
|
189
|
+
const buildStrikeIcon = buildIcon(IconTypes.strike, editorAnalyticsAPI, toolbarType);
|
|
190
|
+
const buildCodeIcon = buildIcon(IconTypes.code, editorAnalyticsAPI, toolbarType);
|
|
191
|
+
const buildSubscriptIcon = buildIcon(IconTypes.subscript, editorAnalyticsAPI, toolbarType);
|
|
192
|
+
const buildSuperscriptIcon = buildIcon(IconTypes.superscript, editorAnalyticsAPI, toolbarType);
|
|
188
193
|
const strongIcon = buildStrongIcon(props);
|
|
189
194
|
const emIcon = buildEmIcon(props);
|
|
190
195
|
const underlineIcon = buildUnderlineIcon(props);
|
|
@@ -30,7 +30,8 @@ const ToolbarFormatting = ({
|
|
|
30
30
|
intl,
|
|
31
31
|
editorAnalyticsAPI,
|
|
32
32
|
textFormattingState,
|
|
33
|
-
api
|
|
33
|
+
api,
|
|
34
|
+
toolbarType
|
|
34
35
|
}) => {
|
|
35
36
|
var _usePreviousState;
|
|
36
37
|
const [message, setMessage] = useState('');
|
|
@@ -39,12 +40,14 @@ const ToolbarFormatting = ({
|
|
|
39
40
|
intl,
|
|
40
41
|
isToolbarDisabled,
|
|
41
42
|
editorAnalyticsAPI,
|
|
42
|
-
textFormattingState
|
|
43
|
+
textFormattingState,
|
|
44
|
+
toolbarType
|
|
43
45
|
});
|
|
44
46
|
const clearIcon = useClearIcon({
|
|
45
47
|
textFormattingState,
|
|
46
48
|
intl,
|
|
47
|
-
editorAnalyticsAPI
|
|
49
|
+
editorAnalyticsAPI,
|
|
50
|
+
toolbarType
|
|
48
51
|
});
|
|
49
52
|
const menuIconTypeList = useResponsiveIconTypeMenu({
|
|
50
53
|
toolbarSize,
|
|
@@ -150,7 +153,9 @@ const ToolbarFormatting = ({
|
|
|
150
153
|
isReducedSpacing: isReducedSpacing,
|
|
151
154
|
moreButtonLabel: moreFormattingButtonLabel,
|
|
152
155
|
hasFormattingActive: hasFormattingActive,
|
|
153
|
-
|
|
156
|
+
hasMoreButton: true,
|
|
157
|
+
items: items,
|
|
158
|
+
intl: intl
|
|
154
159
|
}))), !(api !== null && api !== void 0 && api.primaryToolbar) && /* eslint-disable-next-line @atlaskit/design-system/consistent-css-prop-usage */
|
|
155
160
|
// eslint-disable-next-line @atlaskit/ui-styling-standard/no-imported-style-values, @atlaskit/design-system/consistent-css-prop-usage -- Ignored via go/DSP-18766
|
|
156
161
|
jsx("span", {
|
|
@@ -169,7 +174,8 @@ const Toolbar = ({
|
|
|
169
174
|
intl,
|
|
170
175
|
editorAnalyticsAPI,
|
|
171
176
|
textFormattingState,
|
|
172
|
-
api
|
|
177
|
+
api,
|
|
178
|
+
toolbarType
|
|
173
179
|
}) => {
|
|
174
180
|
return jsx(ToolbarFormatting, {
|
|
175
181
|
textFormattingState: textFormattingState,
|
|
@@ -182,7 +188,8 @@ const Toolbar = ({
|
|
|
182
188
|
shouldUseResponsiveToolbar: shouldUseResponsiveToolbar,
|
|
183
189
|
intl: intl,
|
|
184
190
|
editorAnalyticsAPI: editorAnalyticsAPI,
|
|
185
|
-
api: api
|
|
191
|
+
api: api,
|
|
192
|
+
toolbarType: toolbarType
|
|
186
193
|
});
|
|
187
194
|
};
|
|
188
195
|
export default injectIntl(Toolbar);
|
|
@@ -7,4 +7,9 @@ export let IconTypes = /*#__PURE__*/function (IconTypes) {
|
|
|
7
7
|
IconTypes["subscript"] = "subscript";
|
|
8
8
|
IconTypes["superscript"] = "superscript";
|
|
9
9
|
return IconTypes;
|
|
10
|
+
}({});
|
|
11
|
+
export let ToolbarType = /*#__PURE__*/function (ToolbarType) {
|
|
12
|
+
ToolbarType["PRIMARY"] = "primaryToolbar";
|
|
13
|
+
ToolbarType["FLOATING"] = "floatingToolbar";
|
|
14
|
+
return ToolbarType;
|
|
10
15
|
}({});
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import _defineProperty from "@babel/runtime/helpers/defineProperty";
|
|
2
|
+
var _toolbarTypeToInputMe;
|
|
3
|
+
import { INPUT_METHOD } from '@atlaskit/editor-common/analytics';
|
|
4
|
+
import { ToolbarType } from './ui/Toolbar/types';
|
|
5
|
+
export var toolbarTypeToInputMethod = (_toolbarTypeToInputMe = {}, _defineProperty(_toolbarTypeToInputMe, ToolbarType.PRIMARY, INPUT_METHOD.TOOLBAR), _defineProperty(_toolbarTypeToInputMe, ToolbarType.FLOATING, INPUT_METHOD.FLOATING_TB), _toolbarTypeToInputMe);
|
|
6
|
+
export var getInputMethod = function getInputMethod(toolbarType) {
|
|
7
|
+
return toolbarTypeToInputMethod[toolbarType];
|
|
8
|
+
};
|
package/dist/esm/plugin.js
CHANGED
|
@@ -3,6 +3,7 @@ function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbol
|
|
|
3
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
4
|
import React from 'react';
|
|
5
5
|
import { code, em, strike, strong, subsup, underline } from '@atlaskit/adf-schema';
|
|
6
|
+
import { editorExperiment } from '@atlaskit/tmp-editor-statsig/experiments';
|
|
6
7
|
import { toggleCodeWithAnalytics, toggleEmWithAnalytics, toggleStrikeWithAnalytics, toggleStrongWithAnalytics, toggleSubscriptWithAnalytics, toggleSuperscriptWithAnalytics, toggleUnderlineWithAnalytics } from './commands';
|
|
7
8
|
import { plugin as clearFormattingPlugin, pluginKey as clearFormattingPluginKey } from './pm-plugins/clear-formatting';
|
|
8
9
|
import clearFormattingKeymapPlugin from './pm-plugins/clear-formatting-keymap';
|
|
@@ -11,13 +12,14 @@ import textFormattingInputRulePlugin from './pm-plugins/input-rule';
|
|
|
11
12
|
import keymapPlugin from './pm-plugins/keymap';
|
|
12
13
|
import { plugin as pmPlugin, pluginKey as textFormattingPluginKey } from './pm-plugins/main';
|
|
13
14
|
import textFormattingSmartInputRulePlugin from './pm-plugins/smart-input-rule';
|
|
15
|
+
import { FloatingToolbarTextFormalWithIntl as FloatingToolbarComponent } from './ui/FloatingToolbarComponent';
|
|
14
16
|
import { PrimaryToolbarComponent } from './ui/PrimaryToolbarComponent';
|
|
15
17
|
/**
|
|
16
18
|
* Text formatting plugin to be added to an `EditorPresetBuilder` and used with `ComposableEditor`
|
|
17
19
|
* from `@atlaskit/editor-core`.
|
|
18
20
|
*/
|
|
19
21
|
export var textFormattingPlugin = function textFormattingPlugin(_ref) {
|
|
20
|
-
var _api$primaryToolbar, _api$
|
|
22
|
+
var _api$primaryToolbar, _api$analytics7, _api$analytics8, _api$analytics9, _api$analytics10, _api$analytics11, _api$analytics12, _api$analytics13;
|
|
21
23
|
var options = _ref.config,
|
|
22
24
|
api = _ref.api;
|
|
23
25
|
var primaryToolbarComponent = function primaryToolbarComponent(_ref2) {
|
|
@@ -121,15 +123,44 @@ export var textFormattingPlugin = function textFormattingPlugin(_ref) {
|
|
|
121
123
|
formattingIsPresent: (_clearFormattingPlugi = clearFormattingPluginKey.getState(editorState)) === null || _clearFormattingPlugi === void 0 ? void 0 : _clearFormattingPlugi.formattingIsPresent
|
|
122
124
|
});
|
|
123
125
|
},
|
|
126
|
+
pluginsOptions: {
|
|
127
|
+
selectionToolbar: function selectionToolbar() {
|
|
128
|
+
if (editorExperiment('contextual_formatting_toolbar', true, {
|
|
129
|
+
exposure: true
|
|
130
|
+
})) {
|
|
131
|
+
var toolbarCustom = {
|
|
132
|
+
type: 'custom',
|
|
133
|
+
render: function render(view) {
|
|
134
|
+
var _api$analytics6;
|
|
135
|
+
if (!view) {
|
|
136
|
+
return;
|
|
137
|
+
}
|
|
138
|
+
return /*#__PURE__*/React.createElement(FloatingToolbarComponent, {
|
|
139
|
+
api: api,
|
|
140
|
+
editorView: view,
|
|
141
|
+
editorAnalyticsAPI: api === null || api === void 0 || (_api$analytics6 = api.analytics) === null || _api$analytics6 === void 0 ? void 0 : _api$analytics6.actions
|
|
142
|
+
});
|
|
143
|
+
},
|
|
144
|
+
fallback: []
|
|
145
|
+
};
|
|
146
|
+
return {
|
|
147
|
+
isToolbarAbove: true,
|
|
148
|
+
items: [toolbarCustom]
|
|
149
|
+
};
|
|
150
|
+
} else {
|
|
151
|
+
return undefined;
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
},
|
|
124
155
|
primaryToolbarComponent: !(api !== null && api !== void 0 && api.primaryToolbar) ? primaryToolbarComponent : undefined,
|
|
125
156
|
commands: {
|
|
126
|
-
toggleSuperscript: toggleSuperscriptWithAnalytics(api === null || api === void 0 || (_api$
|
|
127
|
-
toggleSubscript: toggleSubscriptWithAnalytics(api === null || api === void 0 || (_api$
|
|
128
|
-
toggleStrike: toggleStrikeWithAnalytics(api === null || api === void 0 || (_api$
|
|
129
|
-
toggleCode: toggleCodeWithAnalytics(api === null || api === void 0 || (_api$
|
|
130
|
-
toggleUnderline: toggleUnderlineWithAnalytics(api === null || api === void 0 || (_api$
|
|
131
|
-
toggleEm: toggleEmWithAnalytics(api === null || api === void 0 || (_api$
|
|
132
|
-
toggleStrong: toggleStrongWithAnalytics(api === null || api === void 0 || (_api$
|
|
157
|
+
toggleSuperscript: toggleSuperscriptWithAnalytics(api === null || api === void 0 || (_api$analytics7 = api.analytics) === null || _api$analytics7 === void 0 ? void 0 : _api$analytics7.actions),
|
|
158
|
+
toggleSubscript: toggleSubscriptWithAnalytics(api === null || api === void 0 || (_api$analytics8 = api.analytics) === null || _api$analytics8 === void 0 ? void 0 : _api$analytics8.actions),
|
|
159
|
+
toggleStrike: toggleStrikeWithAnalytics(api === null || api === void 0 || (_api$analytics9 = api.analytics) === null || _api$analytics9 === void 0 ? void 0 : _api$analytics9.actions),
|
|
160
|
+
toggleCode: toggleCodeWithAnalytics(api === null || api === void 0 || (_api$analytics10 = api.analytics) === null || _api$analytics10 === void 0 ? void 0 : _api$analytics10.actions),
|
|
161
|
+
toggleUnderline: toggleUnderlineWithAnalytics(api === null || api === void 0 || (_api$analytics11 = api.analytics) === null || _api$analytics11 === void 0 ? void 0 : _api$analytics11.actions),
|
|
162
|
+
toggleEm: toggleEmWithAnalytics(api === null || api === void 0 || (_api$analytics12 = api.analytics) === null || _api$analytics12 === void 0 ? void 0 : _api$analytics12.actions),
|
|
163
|
+
toggleStrong: toggleStrongWithAnalytics(api === null || api === void 0 || (_api$analytics13 = api.analytics) === null || _api$analytics13 === void 0 ? void 0 : _api$analytics13.actions)
|
|
133
164
|
}
|
|
134
165
|
};
|
|
135
166
|
};
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import _toConsumableArray from "@babel/runtime/helpers/toConsumableArray";
|
|
2
|
+
/**
|
|
3
|
+
* @jsxRuntime classic
|
|
4
|
+
* @jsx jsx
|
|
5
|
+
*/
|
|
6
|
+
import { useMemo } from 'react';
|
|
7
|
+
|
|
8
|
+
// eslint-disable-next-line @atlaskit/ui-styling-standard/use-compiled -- Ignored via go/DSP-18766
|
|
9
|
+
import { jsx } from '@emotion/react';
|
|
10
|
+
import { injectIntl } from 'react-intl-next';
|
|
11
|
+
import { useSharedPluginState } from '@atlaskit/editor-common/hooks';
|
|
12
|
+
import { ToolbarSize } from '@atlaskit/editor-common/types';
|
|
13
|
+
import { FormattingTextDropdownMenu } from './Toolbar/dropdown-menu';
|
|
14
|
+
import { useClearIcon } from './Toolbar/hooks/clear-formatting-icon';
|
|
15
|
+
import { useFormattingIcons } from './Toolbar/hooks/formatting-icons';
|
|
16
|
+
import { ToolbarType } from './Toolbar/types';
|
|
17
|
+
var FloatingToolbarSettings = {
|
|
18
|
+
disabled: false,
|
|
19
|
+
isReducedSpacing: true,
|
|
20
|
+
shouldUseResponsiveToolbar: false,
|
|
21
|
+
toolbarSize: ToolbarSize.XXXS,
|
|
22
|
+
hasMoreButton: false,
|
|
23
|
+
moreButtonLabel: '',
|
|
24
|
+
toolbarType: ToolbarType.FLOATING
|
|
25
|
+
};
|
|
26
|
+
var FloatingToolbarTextFormat = function FloatingToolbarTextFormat(_ref) {
|
|
27
|
+
var api = _ref.api,
|
|
28
|
+
editorAnalyticsAPI = _ref.editorAnalyticsAPI,
|
|
29
|
+
editorView = _ref.editorView,
|
|
30
|
+
intl = _ref.intl;
|
|
31
|
+
var _useSharedPluginState = useSharedPluginState(api, ['textFormatting']),
|
|
32
|
+
textFormattingState = _useSharedPluginState.textFormattingState;
|
|
33
|
+
var defaultIcons = useFormattingIcons({
|
|
34
|
+
schema: editorView.state.schema,
|
|
35
|
+
intl: intl,
|
|
36
|
+
isToolbarDisabled: FloatingToolbarSettings.disabled,
|
|
37
|
+
editorAnalyticsAPI: editorAnalyticsAPI,
|
|
38
|
+
textFormattingState: textFormattingState,
|
|
39
|
+
toolbarType: FloatingToolbarSettings.toolbarType
|
|
40
|
+
});
|
|
41
|
+
var clearIcon = useClearIcon({
|
|
42
|
+
textFormattingState: textFormattingState,
|
|
43
|
+
intl: intl,
|
|
44
|
+
editorAnalyticsAPI: editorAnalyticsAPI,
|
|
45
|
+
toolbarType: FloatingToolbarSettings.toolbarType
|
|
46
|
+
});
|
|
47
|
+
var items = useMemo(function () {
|
|
48
|
+
if (!clearIcon) {
|
|
49
|
+
return defaultIcons;
|
|
50
|
+
}
|
|
51
|
+
return [].concat(_toConsumableArray(defaultIcons), [clearIcon]);
|
|
52
|
+
}, [clearIcon, defaultIcons]);
|
|
53
|
+
return jsx(FormattingTextDropdownMenu, {
|
|
54
|
+
editorView: editorView,
|
|
55
|
+
items: items,
|
|
56
|
+
isReducedSpacing: FloatingToolbarSettings.isReducedSpacing,
|
|
57
|
+
moreButtonLabel: FloatingToolbarSettings.moreButtonLabel,
|
|
58
|
+
hasFormattingActive: FloatingToolbarSettings.hasMoreButton,
|
|
59
|
+
hasMoreButton: FloatingToolbarSettings.hasMoreButton,
|
|
60
|
+
intl: intl
|
|
61
|
+
});
|
|
62
|
+
};
|
|
63
|
+
export var FloatingToolbarTextFormalWithIntl = injectIntl(FloatingToolbarTextFormat);
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
import { useSharedPluginState } from '@atlaskit/editor-common/hooks';
|
|
3
3
|
import Toolbar from './Toolbar';
|
|
4
|
+
import { ToolbarType } from './Toolbar/types';
|
|
4
5
|
export function PrimaryToolbarComponent(_ref) {
|
|
5
6
|
var _api$analytics;
|
|
6
7
|
var api = _ref.api,
|
|
@@ -23,6 +24,7 @@ export function PrimaryToolbarComponent(_ref) {
|
|
|
23
24
|
isToolbarDisabled: disabled,
|
|
24
25
|
shouldUseResponsiveToolbar: shouldUseResponsiveToolbar,
|
|
25
26
|
editorAnalyticsAPI: api === null || api === void 0 || (_api$analytics = api.analytics) === null || _api$analytics === void 0 ? void 0 : _api$analytics.actions,
|
|
26
|
-
api: api
|
|
27
|
+
api: api,
|
|
28
|
+
toolbarType: ToolbarType.PRIMARY
|
|
27
29
|
});
|
|
28
30
|
}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @jsxRuntime classic
|
|
3
|
+
* @jsx jsx
|
|
4
|
+
*/
|
|
5
|
+
import React from 'react';
|
|
6
|
+
|
|
7
|
+
// eslint-disable-next-line @atlaskit/ui-styling-standard/use-compiled -- Ignored via go/DSP-18766
|
|
8
|
+
import { jsx } from '@emotion/react';
|
|
9
|
+
import { expandIconContainerStyle, triggerWrapperStyles, triggerWrapperStylesWithPadding } from '@atlaskit/editor-common/styles';
|
|
10
|
+
import { ToolbarButton } from '@atlaskit/editor-common/ui-menu';
|
|
11
|
+
import BoldIcon from '@atlaskit/icon/core/migration/text-bold--editor-bold';
|
|
12
|
+
import ChevronDownIcon from '@atlaskit/icon/utility/migration/chevron-down';
|
|
13
|
+
import { fg } from '@atlaskit/platform-feature-flags';
|
|
14
|
+
export var BoldToolbarButton = function BoldToolbarButton(_ref) {
|
|
15
|
+
var label = _ref.label,
|
|
16
|
+
isReducedSpacing = _ref.isReducedSpacing,
|
|
17
|
+
isDisabled = _ref.isDisabled,
|
|
18
|
+
isSelected = _ref.isSelected,
|
|
19
|
+
ariaExpanded = _ref['aria-expanded'],
|
|
20
|
+
onClick = _ref.onClick,
|
|
21
|
+
onKeyDown = _ref.onKeyDown;
|
|
22
|
+
return jsx(ToolbarButton, {
|
|
23
|
+
testId: 'ak-editor-selection-toolbar-format-text-button',
|
|
24
|
+
spacing: isReducedSpacing ? 'none' : 'default',
|
|
25
|
+
disabled: isDisabled,
|
|
26
|
+
selected: isSelected,
|
|
27
|
+
"aria-label": label,
|
|
28
|
+
"aria-expanded": ariaExpanded,
|
|
29
|
+
"aria-haspopup": true,
|
|
30
|
+
title: label,
|
|
31
|
+
onClick: onClick,
|
|
32
|
+
onKeyDown: onKeyDown,
|
|
33
|
+
iconBefore: jsx("div", {
|
|
34
|
+
css:
|
|
35
|
+
// eslint-disable-next-line @atlaskit/platform/ensure-feature-flag-registration
|
|
36
|
+
fg('platform-visual-refresh-icons') ?
|
|
37
|
+
// eslint-disable-next-line @atlaskit/design-system/consistent-css-prop-usage, @atlaskit/ui-styling-standard/no-imported-style-values
|
|
38
|
+
triggerWrapperStylesWithPadding :
|
|
39
|
+
// eslint-disable-next-line @atlaskit/design-system/consistent-css-prop-usage, @atlaskit/ui-styling-standard/no-imported-style-values
|
|
40
|
+
triggerWrapperStyles
|
|
41
|
+
}, jsx(BoldIcon, {
|
|
42
|
+
color: "currentColor",
|
|
43
|
+
spacing: "spacious",
|
|
44
|
+
label: ""
|
|
45
|
+
}), jsx("span", {
|
|
46
|
+
css: expandIconContainerStyle
|
|
47
|
+
}, jsx(ChevronDownIcon, {
|
|
48
|
+
label: "",
|
|
49
|
+
color: "currentColor",
|
|
50
|
+
LEGACY_margin: "0 0 0 -8px"
|
|
51
|
+
})))
|
|
52
|
+
});
|
|
53
|
+
};
|