@atlaskit/editor-plugin-text-formatting 2.2.4 → 2.2.6

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.
Files changed (30) hide show
  1. package/CHANGELOG.md +19 -0
  2. package/dist/cjs/pm-plugins/keymap.js +52 -1
  3. package/dist/cjs/pm-plugins/main.js +3 -1
  4. package/dist/cjs/textFormattingPlugin.js +4 -2
  5. package/dist/cjs/ui/FloatingToolbarComponent.js +90 -8
  6. package/dist/cjs/ui/PrimaryToolbarComponent.js +80 -2
  7. package/dist/cjs/ui/Toolbar/hooks/clear-formatting-icon.js +4 -3
  8. package/dist/cjs/ui/Toolbar/hooks/formatting-icons.js +2 -2
  9. package/dist/cjs/ui/Toolbar/index.js +7 -4
  10. package/dist/es2019/pm-plugins/keymap.js +52 -1
  11. package/dist/es2019/pm-plugins/main.js +3 -1
  12. package/dist/es2019/textFormattingPlugin.js +4 -2
  13. package/dist/es2019/ui/FloatingToolbarComponent.js +88 -5
  14. package/dist/es2019/ui/PrimaryToolbarComponent.js +82 -4
  15. package/dist/es2019/ui/Toolbar/hooks/clear-formatting-icon.js +4 -3
  16. package/dist/es2019/ui/Toolbar/hooks/formatting-icons.js +2 -2
  17. package/dist/es2019/ui/Toolbar/index.js +7 -2
  18. package/dist/esm/pm-plugins/keymap.js +52 -1
  19. package/dist/esm/pm-plugins/main.js +3 -1
  20. package/dist/esm/textFormattingPlugin.js +4 -2
  21. package/dist/esm/ui/FloatingToolbarComponent.js +88 -5
  22. package/dist/esm/ui/PrimaryToolbarComponent.js +81 -3
  23. package/dist/esm/ui/Toolbar/hooks/clear-formatting-icon.js +4 -3
  24. package/dist/esm/ui/Toolbar/hooks/formatting-icons.js +2 -2
  25. package/dist/esm/ui/Toolbar/index.js +7 -2
  26. package/dist/types/ui/Toolbar/hooks/clear-formatting-icon.d.ts +3 -3
  27. package/dist/types/ui/Toolbar/index.d.ts +1 -1
  28. package/dist/types-ts4.5/ui/Toolbar/hooks/clear-formatting-icon.d.ts +3 -3
  29. package/dist/types-ts4.5/ui/Toolbar/index.d.ts +1 -1
  30. package/package.json +5 -5
@@ -7,8 +7,9 @@ import React, { useMemo } from 'react';
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
9
  import { injectIntl } from 'react-intl-next';
10
- import { useSharedPluginState } from '@atlaskit/editor-common/hooks';
10
+ import { useSharedPluginState, sharedPluginStateHookMigratorFactory } from '@atlaskit/editor-common/hooks';
11
11
  import { ToolbarSize } from '@atlaskit/editor-common/types';
12
+ import { useSharedPluginStateSelector } from '@atlaskit/editor-common/use-shared-plugin-state-selector';
12
13
  import { TextSelection } from '@atlaskit/editor-prosemirror/state';
13
14
  import { fg } from '@atlaskit/platform-feature-flags';
14
15
  import { editorExperiment } from '@atlaskit/tmp-editor-statsig/experiments';
@@ -29,21 +30,102 @@ const FloatingToolbarSettings = {
29
30
  moreButtonLabel: '',
30
31
  toolbarType: ToolbarType.FLOATING
31
32
  };
33
+ const useSharedState = sharedPluginStateHookMigratorFactory(api => {
34
+ const isInitialised = useSharedPluginStateSelector(api, 'textFormatting.isInitialised');
35
+ const formattingIsPresent = useSharedPluginStateSelector(api, 'textFormatting.formattingIsPresent');
36
+ const emActive = useSharedPluginStateSelector(api, 'textFormatting.emActive');
37
+ const emDisabled = useSharedPluginStateSelector(api, 'textFormatting.emDisabled');
38
+ const emHidden = useSharedPluginStateSelector(api, 'textFormatting.emHidden');
39
+ const codeActive = useSharedPluginStateSelector(api, 'textFormatting.codeActive');
40
+ const codeDisabled = useSharedPluginStateSelector(api, 'textFormatting.codeDisabled');
41
+ const codeHidden = useSharedPluginStateSelector(api, 'textFormatting.codeHidden');
42
+ const underlineActive = useSharedPluginStateSelector(api, 'textFormatting.underlineActive');
43
+ const underlineDisabled = useSharedPluginStateSelector(api, 'textFormatting.underlineDisabled');
44
+ const underlineHidden = useSharedPluginStateSelector(api, 'textFormatting.underlineHidden');
45
+ const strikeActive = useSharedPluginStateSelector(api, 'textFormatting.strikeActive');
46
+ const strikeDisabled = useSharedPluginStateSelector(api, 'textFormatting.strikeDisabled');
47
+ const strikeHidden = useSharedPluginStateSelector(api, 'textFormatting.strikeHidden');
48
+ const strongActive = useSharedPluginStateSelector(api, 'textFormatting.strongActive');
49
+ const strongDisabled = useSharedPluginStateSelector(api, 'textFormatting.strongDisabled');
50
+ const strongHidden = useSharedPluginStateSelector(api, 'textFormatting.strongHidden');
51
+ const superscriptActive = useSharedPluginStateSelector(api, 'textFormatting.superscriptActive');
52
+ const superscriptDisabled = useSharedPluginStateSelector(api, 'textFormatting.superscriptDisabled');
53
+ const superscriptHidden = useSharedPluginStateSelector(api, 'textFormatting.superscriptHidden');
54
+ const subscriptActive = useSharedPluginStateSelector(api, 'textFormatting.subscriptActive');
55
+ const subscriptDisabled = useSharedPluginStateSelector(api, 'textFormatting.subscriptDisabled');
56
+ const subscriptHidden = useSharedPluginStateSelector(api, 'textFormatting.subscriptHidden');
57
+ return {
58
+ isInitialised: Boolean(isInitialised),
59
+ formattingIsPresent,
60
+ emActive,
61
+ emDisabled,
62
+ emHidden,
63
+ codeActive,
64
+ codeDisabled,
65
+ codeHidden,
66
+ underlineActive,
67
+ underlineDisabled,
68
+ underlineHidden,
69
+ strikeActive,
70
+ strikeDisabled,
71
+ strikeHidden,
72
+ strongActive,
73
+ strongDisabled,
74
+ strongHidden,
75
+ superscriptActive,
76
+ superscriptDisabled,
77
+ superscriptHidden,
78
+ subscriptActive,
79
+ subscriptDisabled,
80
+ subscriptHidden
81
+ };
82
+ }, api => {
83
+ const {
84
+ textFormattingState
85
+ } = useSharedPluginState(api, ['textFormatting']);
86
+ return {
87
+ isInitialised: Boolean(textFormattingState === null || textFormattingState === void 0 ? void 0 : textFormattingState.isInitialised),
88
+ formattingIsPresent: textFormattingState === null || textFormattingState === void 0 ? void 0 : textFormattingState.formattingIsPresent,
89
+ emActive: textFormattingState === null || textFormattingState === void 0 ? void 0 : textFormattingState.emActive,
90
+ emDisabled: textFormattingState === null || textFormattingState === void 0 ? void 0 : textFormattingState.emDisabled,
91
+ emHidden: textFormattingState === null || textFormattingState === void 0 ? void 0 : textFormattingState.emHidden,
92
+ codeActive: textFormattingState === null || textFormattingState === void 0 ? void 0 : textFormattingState.codeActive,
93
+ codeDisabled: textFormattingState === null || textFormattingState === void 0 ? void 0 : textFormattingState.codeDisabled,
94
+ codeHidden: textFormattingState === null || textFormattingState === void 0 ? void 0 : textFormattingState.codeHidden,
95
+ underlineActive: textFormattingState === null || textFormattingState === void 0 ? void 0 : textFormattingState.underlineActive,
96
+ underlineDisabled: textFormattingState === null || textFormattingState === void 0 ? void 0 : textFormattingState.underlineDisabled,
97
+ underlineHidden: textFormattingState === null || textFormattingState === void 0 ? void 0 : textFormattingState.underlineHidden,
98
+ strikeActive: textFormattingState === null || textFormattingState === void 0 ? void 0 : textFormattingState.strikeActive,
99
+ strikeDisabled: textFormattingState === null || textFormattingState === void 0 ? void 0 : textFormattingState.strikeDisabled,
100
+ strikeHidden: textFormattingState === null || textFormattingState === void 0 ? void 0 : textFormattingState.strikeHidden,
101
+ strongActive: textFormattingState === null || textFormattingState === void 0 ? void 0 : textFormattingState.strongActive,
102
+ strongDisabled: textFormattingState === null || textFormattingState === void 0 ? void 0 : textFormattingState.strongDisabled,
103
+ strongHidden: textFormattingState === null || textFormattingState === void 0 ? void 0 : textFormattingState.strongHidden,
104
+ superscriptActive: textFormattingState === null || textFormattingState === void 0 ? void 0 : textFormattingState.superscriptActive,
105
+ superscriptDisabled: textFormattingState === null || textFormattingState === void 0 ? void 0 : textFormattingState.superscriptDisabled,
106
+ superscriptHidden: textFormattingState === null || textFormattingState === void 0 ? void 0 : textFormattingState.superscriptHidden,
107
+ subscriptActive: textFormattingState === null || textFormattingState === void 0 ? void 0 : textFormattingState.subscriptActive,
108
+ subscriptDisabled: textFormattingState === null || textFormattingState === void 0 ? void 0 : textFormattingState.subscriptDisabled,
109
+ subscriptHidden: textFormattingState === null || textFormattingState === void 0 ? void 0 : textFormattingState.subscriptHidden
110
+ };
111
+ });
32
112
  const FloatingToolbarTextFormat = ({
33
113
  api,
34
114
  editorAnalyticsAPI,
35
115
  editorView,
36
116
  intl
37
117
  }) => {
118
+ const textFormattingState = useSharedState(api);
38
119
  const {
39
- textFormattingState
40
- } = useSharedPluginState(api, ['textFormatting']);
120
+ formattingIsPresent,
121
+ ...formattingIconState
122
+ } = textFormattingState;
41
123
  const defaultIcons = useFormattingIcons({
42
124
  schema: editorView.state.schema,
43
125
  intl,
44
126
  isToolbarDisabled: FloatingToolbarSettings.disabled,
45
127
  editorAnalyticsAPI,
46
- textFormattingState,
128
+ textFormattingState: formattingIconState,
47
129
  toolbarType: FloatingToolbarSettings.toolbarType
48
130
  });
49
131
  let hasMultiplePartsWithFormattingSelected;
@@ -69,7 +151,8 @@ const FloatingToolbarTextFormat = ({
69
151
  shouldUnselect: hasMultiplePartsWithFormattingSelected
70
152
  });
71
153
  const clearIcon = useClearIcon({
72
- textFormattingState,
154
+ formattingPluginInitialised: textFormattingState.isInitialised,
155
+ formattingIsPresent,
73
156
  intl,
74
157
  editorAnalyticsAPI,
75
158
  toolbarType: FloatingToolbarSettings.toolbarType
@@ -1,7 +1,87 @@
1
1
  import React from 'react';
2
- import { useSharedPluginState } from '@atlaskit/editor-common/hooks';
2
+ import { useSharedPluginState, sharedPluginStateHookMigratorFactory } from '@atlaskit/editor-common/hooks';
3
+ import { useSharedPluginStateSelector } from '@atlaskit/editor-common/use-shared-plugin-state-selector';
3
4
  import Toolbar from './Toolbar';
4
5
  import { ToolbarType } from './Toolbar/types';
6
+ const useSharedState = sharedPluginStateHookMigratorFactory(api => {
7
+ const isInitialised = useSharedPluginStateSelector(api, 'textFormatting.isInitialised');
8
+ const formattingIsPresent = useSharedPluginStateSelector(api, 'textFormatting.formattingIsPresent');
9
+ const emActive = useSharedPluginStateSelector(api, 'textFormatting.emActive');
10
+ const emDisabled = useSharedPluginStateSelector(api, 'textFormatting.emDisabled');
11
+ const emHidden = useSharedPluginStateSelector(api, 'textFormatting.emHidden');
12
+ const codeActive = useSharedPluginStateSelector(api, 'textFormatting.codeActive');
13
+ const codeDisabled = useSharedPluginStateSelector(api, 'textFormatting.codeDisabled');
14
+ const codeHidden = useSharedPluginStateSelector(api, 'textFormatting.codeHidden');
15
+ const underlineActive = useSharedPluginStateSelector(api, 'textFormatting.underlineActive');
16
+ const underlineDisabled = useSharedPluginStateSelector(api, 'textFormatting.underlineDisabled');
17
+ const underlineHidden = useSharedPluginStateSelector(api, 'textFormatting.underlineHidden');
18
+ const strikeActive = useSharedPluginStateSelector(api, 'textFormatting.strikeActive');
19
+ const strikeDisabled = useSharedPluginStateSelector(api, 'textFormatting.strikeDisabled');
20
+ const strikeHidden = useSharedPluginStateSelector(api, 'textFormatting.strikeHidden');
21
+ const strongActive = useSharedPluginStateSelector(api, 'textFormatting.strongActive');
22
+ const strongDisabled = useSharedPluginStateSelector(api, 'textFormatting.strongDisabled');
23
+ const strongHidden = useSharedPluginStateSelector(api, 'textFormatting.strongHidden');
24
+ const superscriptActive = useSharedPluginStateSelector(api, 'textFormatting.superscriptActive');
25
+ const superscriptDisabled = useSharedPluginStateSelector(api, 'textFormatting.superscriptDisabled');
26
+ const superscriptHidden = useSharedPluginStateSelector(api, 'textFormatting.superscriptHidden');
27
+ const subscriptActive = useSharedPluginStateSelector(api, 'textFormatting.subscriptActive');
28
+ const subscriptDisabled = useSharedPluginStateSelector(api, 'textFormatting.subscriptDisabled');
29
+ const subscriptHidden = useSharedPluginStateSelector(api, 'textFormatting.subscriptHidden');
30
+ return {
31
+ isInitialised: Boolean(isInitialised),
32
+ formattingIsPresent,
33
+ emActive,
34
+ emDisabled,
35
+ emHidden,
36
+ codeActive,
37
+ codeDisabled,
38
+ codeHidden,
39
+ underlineActive,
40
+ underlineDisabled,
41
+ underlineHidden,
42
+ strikeActive,
43
+ strikeDisabled,
44
+ strikeHidden,
45
+ strongActive,
46
+ strongDisabled,
47
+ strongHidden,
48
+ superscriptActive,
49
+ superscriptDisabled,
50
+ superscriptHidden,
51
+ subscriptActive,
52
+ subscriptDisabled,
53
+ subscriptHidden
54
+ };
55
+ }, api => {
56
+ const {
57
+ textFormattingState
58
+ } = useSharedPluginState(api, ['textFormatting']);
59
+ return {
60
+ isInitialised: Boolean(textFormattingState === null || textFormattingState === void 0 ? void 0 : textFormattingState.isInitialised),
61
+ formattingIsPresent: textFormattingState === null || textFormattingState === void 0 ? void 0 : textFormattingState.formattingIsPresent,
62
+ emActive: textFormattingState === null || textFormattingState === void 0 ? void 0 : textFormattingState.emActive,
63
+ emDisabled: textFormattingState === null || textFormattingState === void 0 ? void 0 : textFormattingState.emDisabled,
64
+ emHidden: textFormattingState === null || textFormattingState === void 0 ? void 0 : textFormattingState.emHidden,
65
+ codeActive: textFormattingState === null || textFormattingState === void 0 ? void 0 : textFormattingState.codeActive,
66
+ codeDisabled: textFormattingState === null || textFormattingState === void 0 ? void 0 : textFormattingState.codeDisabled,
67
+ codeHidden: textFormattingState === null || textFormattingState === void 0 ? void 0 : textFormattingState.codeHidden,
68
+ underlineActive: textFormattingState === null || textFormattingState === void 0 ? void 0 : textFormattingState.underlineActive,
69
+ underlineDisabled: textFormattingState === null || textFormattingState === void 0 ? void 0 : textFormattingState.underlineDisabled,
70
+ underlineHidden: textFormattingState === null || textFormattingState === void 0 ? void 0 : textFormattingState.underlineHidden,
71
+ strikeActive: textFormattingState === null || textFormattingState === void 0 ? void 0 : textFormattingState.strikeActive,
72
+ strikeDisabled: textFormattingState === null || textFormattingState === void 0 ? void 0 : textFormattingState.strikeDisabled,
73
+ strikeHidden: textFormattingState === null || textFormattingState === void 0 ? void 0 : textFormattingState.strikeHidden,
74
+ strongActive: textFormattingState === null || textFormattingState === void 0 ? void 0 : textFormattingState.strongActive,
75
+ strongDisabled: textFormattingState === null || textFormattingState === void 0 ? void 0 : textFormattingState.strongDisabled,
76
+ strongHidden: textFormattingState === null || textFormattingState === void 0 ? void 0 : textFormattingState.strongHidden,
77
+ superscriptActive: textFormattingState === null || textFormattingState === void 0 ? void 0 : textFormattingState.superscriptActive,
78
+ superscriptDisabled: textFormattingState === null || textFormattingState === void 0 ? void 0 : textFormattingState.superscriptDisabled,
79
+ superscriptHidden: textFormattingState === null || textFormattingState === void 0 ? void 0 : textFormattingState.superscriptHidden,
80
+ subscriptActive: textFormattingState === null || textFormattingState === void 0 ? void 0 : textFormattingState.subscriptActive,
81
+ subscriptDisabled: textFormattingState === null || textFormattingState === void 0 ? void 0 : textFormattingState.subscriptDisabled,
82
+ subscriptHidden: textFormattingState === null || textFormattingState === void 0 ? void 0 : textFormattingState.subscriptHidden
83
+ };
84
+ });
5
85
  export function PrimaryToolbarComponent({
6
86
  api,
7
87
  popupsMountPoint,
@@ -13,9 +93,7 @@ export function PrimaryToolbarComponent({
13
93
  shouldUseResponsiveToolbar
14
94
  }) {
15
95
  var _api$analytics;
16
- const {
17
- textFormattingState
18
- } = useSharedPluginState(api, ['textFormatting']);
96
+ const textFormattingState = useSharedState(api);
19
97
  return /*#__PURE__*/React.createElement(Toolbar, {
20
98
  textFormattingState: textFormattingState,
21
99
  popupsMountPoint: popupsMountPoint,
@@ -15,12 +15,13 @@ import { clearFormattingWithAnalytics } from '../../../editor-commands/clear-for
15
15
  import { getInputMethod } from '../input-method-utils';
16
16
  export const useClearIcon = ({
17
17
  intl,
18
- textFormattingState,
18
+ formattingPluginInitialised,
19
+ formattingIsPresent: formattingPresent,
19
20
  editorAnalyticsAPI,
20
21
  toolbarType
21
22
  }) => {
22
- const isPluginAvailable = Boolean(textFormattingState);
23
- const formattingIsPresent = Boolean(textFormattingState === null || textFormattingState === void 0 ? void 0 : textFormattingState.formattingIsPresent);
23
+ const isPluginAvailable = Boolean(formattingPluginInitialised);
24
+ const formattingIsPresent = Boolean(formattingPresent);
24
25
  const clearFormattingLabel = intl.formatMessage(toolbarMessages.clearFormatting);
25
26
  const clearFormattingToolbar = useCallback((state, dispatch) => clearFormattingWithAnalytics(getInputMethod(toolbarType), editorAnalyticsAPI)(state, dispatch), [editorAnalyticsAPI, toolbarType]);
26
27
  return useMemo(() => {
@@ -168,7 +168,7 @@ const buildMenuIconState = iconMark => ({
168
168
  schema,
169
169
  textFormattingState
170
170
  }) => {
171
- const hasPluginState = Boolean(Object.keys(textFormattingState || {}).length);
171
+ const hasPluginState = Boolean(textFormattingState === null || textFormattingState === void 0 ? void 0 : textFormattingState.isInitialised);
172
172
  const markSchema = IconsMarkSchema[iconMark];
173
173
  const hasSchemaMark = Boolean(schema.marks[markSchema]);
174
174
  if (!hasPluginState) {
@@ -256,7 +256,7 @@ export const useHasFormattingActived = ({
256
256
  textFormattingState
257
257
  }) => {
258
258
  const hasActiveFormatting = useMemo(() => {
259
- if (!textFormattingState) {
259
+ if (!(textFormattingState !== null && textFormattingState !== void 0 && textFormattingState.isInitialised)) {
260
260
  return false;
261
261
  }
262
262
  return iconTypeList.some(iconType => textFormattingState[`${iconType}Active`]);
@@ -37,16 +37,21 @@ const ToolbarFormatting = ({
37
37
  }) => {
38
38
  var _usePreviousState;
39
39
  const [message, setMessage] = useState('');
40
+ const {
41
+ formattingIsPresent,
42
+ ...formattingIconState
43
+ } = textFormattingState;
40
44
  const defaultIcons = useFormattingIcons({
41
45
  schema: editorView.state.schema,
42
46
  intl,
43
47
  isToolbarDisabled,
44
48
  editorAnalyticsAPI,
45
- textFormattingState,
49
+ textFormattingState: formattingIconState,
46
50
  toolbarType
47
51
  });
48
52
  const clearIcon = useClearIcon({
49
- textFormattingState,
53
+ formattingPluginInitialised: textFormattingState.isInitialised,
54
+ formattingIsPresent,
50
55
  intl,
51
56
  editorAnalyticsAPI,
52
57
  toolbarType
@@ -2,7 +2,10 @@ import { INPUT_METHOD } from '@atlaskit/editor-common/analytics';
2
2
  import { bindKeymapWithEditorCommand, isCapsLockOnAndModifyKeyboardEvent, toggleBold, toggleCode, toggleItalic, toggleStrikethrough, toggleSubscript, toggleSuperscript, toggleUnderline } from '@atlaskit/editor-common/keymaps';
3
3
  import { SafePlugin } from '@atlaskit/editor-common/safe-plugin';
4
4
  import { keydownHandler } from '@atlaskit/editor-prosemirror/keymap';
5
+ import { fg } from '@atlaskit/platform-feature-flags';
6
+ import { editorExperiment } from '@atlaskit/tmp-editor-statsig/experiments';
5
7
  import { toggleCodeWithAnalytics, toggleEmWithAnalytics, toggleStrikeWithAnalytics, toggleStrongWithAnalytics, toggleSubscriptWithAnalytics, toggleSuperscriptWithAnalytics, toggleUnderlineWithAnalytics } from './commands';
8
+ import { pluginKey } from './plugin-key';
6
9
  export default function keymapPlugin(schema, editorAnalyticsAPI) {
7
10
  var list = {};
8
11
  if (schema.marks.strong) {
@@ -47,11 +50,59 @@ export default function keymapPlugin(schema, editorAnalyticsAPI) {
47
50
  // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
48
51
  toggleUnderline.common, toggleUnderlineWithAnalytics(editorAnalyticsAPI)(INPUT_METHOD.SHORTCUT), list);
49
52
  }
53
+ var getEnabledKeylist = function getEnabledKeylist(view) {
54
+ var textFormattingState = pluginKey.getState(view.state);
55
+ var list = {};
56
+ if (schema.marks.strong && !(textFormattingState !== null && textFormattingState !== void 0 && textFormattingState.strongDisabled)) {
57
+ bindKeymapWithEditorCommand(
58
+ // Ignored via go/ees005
59
+ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
60
+ toggleBold.common, toggleStrongWithAnalytics(editorAnalyticsAPI)(INPUT_METHOD.SHORTCUT), list);
61
+ }
62
+ if (schema.marks.em && !(textFormattingState !== null && textFormattingState !== void 0 && textFormattingState.emDisabled)) {
63
+ bindKeymapWithEditorCommand(
64
+ // Ignored via go/ees005
65
+ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
66
+ toggleItalic.common, toggleEmWithAnalytics(editorAnalyticsAPI)(INPUT_METHOD.SHORTCUT), list);
67
+ }
68
+ if (schema.marks.code && !(textFormattingState !== null && textFormattingState !== void 0 && textFormattingState.codeDisabled)) {
69
+ bindKeymapWithEditorCommand(
70
+ // Ignored via go/ees005
71
+ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
72
+ toggleCode.common, toggleCodeWithAnalytics(editorAnalyticsAPI)(INPUT_METHOD.SHORTCUT), list);
73
+ }
74
+ if (schema.marks.strike && !(textFormattingState !== null && textFormattingState !== void 0 && textFormattingState.strikeDisabled)) {
75
+ bindKeymapWithEditorCommand(
76
+ // Ignored via go/ees005
77
+ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
78
+ toggleStrikethrough.common, toggleStrikeWithAnalytics(editorAnalyticsAPI)(INPUT_METHOD.SHORTCUT), list);
79
+ }
80
+ if (schema.marks.subsup && !(textFormattingState !== null && textFormattingState !== void 0 && textFormattingState.subscriptDisabled)) {
81
+ bindKeymapWithEditorCommand(
82
+ // Ignored via go/ees005
83
+ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
84
+ toggleSubscript.common, toggleSubscriptWithAnalytics(editorAnalyticsAPI)(INPUT_METHOD.SHORTCUT), list);
85
+ }
86
+ if (schema.marks.subsup && !(textFormattingState !== null && textFormattingState !== void 0 && textFormattingState.superscriptDisabled)) {
87
+ bindKeymapWithEditorCommand(
88
+ // Ignored via go/ees005
89
+ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
90
+ toggleSuperscript.common, toggleSuperscriptWithAnalytics(editorAnalyticsAPI)(INPUT_METHOD.SHORTCUT), list);
91
+ }
92
+ if (schema.marks.underline && !(textFormattingState !== null && textFormattingState !== void 0 && textFormattingState.underlineDisabled)) {
93
+ bindKeymapWithEditorCommand(
94
+ // Ignored via go/ees005
95
+ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
96
+ toggleUnderline.common, toggleUnderlineWithAnalytics(editorAnalyticsAPI)(INPUT_METHOD.SHORTCUT), list);
97
+ }
98
+ return list;
99
+ };
50
100
  return new SafePlugin({
51
101
  props: {
52
102
  handleKeyDown: function handleKeyDown(view, event) {
53
103
  var keyboardEvent = isCapsLockOnAndModifyKeyboardEvent(event);
54
- return keydownHandler(list)(view, keyboardEvent);
104
+ var keymapList = editorExperiment('platform_editor_controls', 'variant1') && fg('platform_editor_controls_patch_8') ? getEnabledKeylist(view) : list;
105
+ return keydownHandler(keymapList)(view, keyboardEvent);
55
106
  }
56
107
  }
57
108
  });
@@ -38,7 +38,9 @@ var getTextFormattingState = function getTextFormattingState(editorState, editor
38
38
  strong = _editorState$schema$m.strong,
39
39
  subsup = _editorState$schema$m.subsup,
40
40
  underline = _editorState$schema$m.underline;
41
- var state = {};
41
+ var state = {
42
+ isInitialised: true
43
+ };
42
44
  if (code) {
43
45
  state.codeActive = anyMarkActive(editorState, code.create());
44
46
  state.codeDisabled = !checkNodeSelection(code, editorState);
@@ -121,8 +121,10 @@ export var textFormattingPlugin = function textFormattingPlugin(_ref) {
121
121
  if (!editorState) {
122
122
  return undefined;
123
123
  }
124
- return _objectSpread(_objectSpread({}, textFormattingPluginKey.getState(editorState)), {}, {
125
- formattingIsPresent: (_clearFormattingPlugi = clearFormattingPluginKey.getState(editorState)) === null || _clearFormattingPlugi === void 0 ? void 0 : _clearFormattingPlugi.formattingIsPresent
124
+ var textFormattingState = textFormattingPluginKey.getState(editorState);
125
+ return _objectSpread(_objectSpread({}, textFormattingState), {}, {
126
+ formattingIsPresent: (_clearFormattingPlugi = clearFormattingPluginKey.getState(editorState)) === null || _clearFormattingPlugi === void 0 ? void 0 : _clearFormattingPlugi.formattingIsPresent,
127
+ isInitialised: !!(textFormattingState !== null && textFormattingState !== void 0 && textFormattingState.isInitialised)
126
128
  });
127
129
  },
128
130
  pluginsOptions: {
@@ -1,3 +1,5 @@
1
+ import _objectWithoutProperties from "@babel/runtime/helpers/objectWithoutProperties";
2
+ var _excluded = ["formattingIsPresent"];
1
3
  /**
2
4
  * @jsxRuntime classic
3
5
  * @jsx jsx
@@ -7,8 +9,9 @@ import React, { useMemo } from 'react';
7
9
  // eslint-disable-next-line @atlaskit/ui-styling-standard/use-compiled -- Ignored via go/DSP-18766
8
10
  import { jsx } from '@emotion/react';
9
11
  import { injectIntl } from 'react-intl-next';
10
- import { useSharedPluginState } from '@atlaskit/editor-common/hooks';
12
+ import { useSharedPluginState, sharedPluginStateHookMigratorFactory } from '@atlaskit/editor-common/hooks';
11
13
  import { ToolbarSize } from '@atlaskit/editor-common/types';
14
+ import { useSharedPluginStateSelector } from '@atlaskit/editor-common/use-shared-plugin-state-selector';
12
15
  import { TextSelection } from '@atlaskit/editor-prosemirror/state';
13
16
  import { fg } from '@atlaskit/platform-feature-flags';
14
17
  import { editorExperiment } from '@atlaskit/tmp-editor-statsig/experiments';
@@ -29,19 +32,98 @@ var FloatingToolbarSettings = {
29
32
  moreButtonLabel: '',
30
33
  toolbarType: ToolbarType.FLOATING
31
34
  };
35
+ var useSharedState = sharedPluginStateHookMigratorFactory(function (api) {
36
+ var isInitialised = useSharedPluginStateSelector(api, 'textFormatting.isInitialised');
37
+ var formattingIsPresent = useSharedPluginStateSelector(api, 'textFormatting.formattingIsPresent');
38
+ var emActive = useSharedPluginStateSelector(api, 'textFormatting.emActive');
39
+ var emDisabled = useSharedPluginStateSelector(api, 'textFormatting.emDisabled');
40
+ var emHidden = useSharedPluginStateSelector(api, 'textFormatting.emHidden');
41
+ var codeActive = useSharedPluginStateSelector(api, 'textFormatting.codeActive');
42
+ var codeDisabled = useSharedPluginStateSelector(api, 'textFormatting.codeDisabled');
43
+ var codeHidden = useSharedPluginStateSelector(api, 'textFormatting.codeHidden');
44
+ var underlineActive = useSharedPluginStateSelector(api, 'textFormatting.underlineActive');
45
+ var underlineDisabled = useSharedPluginStateSelector(api, 'textFormatting.underlineDisabled');
46
+ var underlineHidden = useSharedPluginStateSelector(api, 'textFormatting.underlineHidden');
47
+ var strikeActive = useSharedPluginStateSelector(api, 'textFormatting.strikeActive');
48
+ var strikeDisabled = useSharedPluginStateSelector(api, 'textFormatting.strikeDisabled');
49
+ var strikeHidden = useSharedPluginStateSelector(api, 'textFormatting.strikeHidden');
50
+ var strongActive = useSharedPluginStateSelector(api, 'textFormatting.strongActive');
51
+ var strongDisabled = useSharedPluginStateSelector(api, 'textFormatting.strongDisabled');
52
+ var strongHidden = useSharedPluginStateSelector(api, 'textFormatting.strongHidden');
53
+ var superscriptActive = useSharedPluginStateSelector(api, 'textFormatting.superscriptActive');
54
+ var superscriptDisabled = useSharedPluginStateSelector(api, 'textFormatting.superscriptDisabled');
55
+ var superscriptHidden = useSharedPluginStateSelector(api, 'textFormatting.superscriptHidden');
56
+ var subscriptActive = useSharedPluginStateSelector(api, 'textFormatting.subscriptActive');
57
+ var subscriptDisabled = useSharedPluginStateSelector(api, 'textFormatting.subscriptDisabled');
58
+ var subscriptHidden = useSharedPluginStateSelector(api, 'textFormatting.subscriptHidden');
59
+ return {
60
+ isInitialised: Boolean(isInitialised),
61
+ formattingIsPresent: formattingIsPresent,
62
+ emActive: emActive,
63
+ emDisabled: emDisabled,
64
+ emHidden: emHidden,
65
+ codeActive: codeActive,
66
+ codeDisabled: codeDisabled,
67
+ codeHidden: codeHidden,
68
+ underlineActive: underlineActive,
69
+ underlineDisabled: underlineDisabled,
70
+ underlineHidden: underlineHidden,
71
+ strikeActive: strikeActive,
72
+ strikeDisabled: strikeDisabled,
73
+ strikeHidden: strikeHidden,
74
+ strongActive: strongActive,
75
+ strongDisabled: strongDisabled,
76
+ strongHidden: strongHidden,
77
+ superscriptActive: superscriptActive,
78
+ superscriptDisabled: superscriptDisabled,
79
+ superscriptHidden: superscriptHidden,
80
+ subscriptActive: subscriptActive,
81
+ subscriptDisabled: subscriptDisabled,
82
+ subscriptHidden: subscriptHidden
83
+ };
84
+ }, function (api) {
85
+ var _useSharedPluginState = useSharedPluginState(api, ['textFormatting']),
86
+ textFormattingState = _useSharedPluginState.textFormattingState;
87
+ return {
88
+ isInitialised: Boolean(textFormattingState === null || textFormattingState === void 0 ? void 0 : textFormattingState.isInitialised),
89
+ formattingIsPresent: textFormattingState === null || textFormattingState === void 0 ? void 0 : textFormattingState.formattingIsPresent,
90
+ emActive: textFormattingState === null || textFormattingState === void 0 ? void 0 : textFormattingState.emActive,
91
+ emDisabled: textFormattingState === null || textFormattingState === void 0 ? void 0 : textFormattingState.emDisabled,
92
+ emHidden: textFormattingState === null || textFormattingState === void 0 ? void 0 : textFormattingState.emHidden,
93
+ codeActive: textFormattingState === null || textFormattingState === void 0 ? void 0 : textFormattingState.codeActive,
94
+ codeDisabled: textFormattingState === null || textFormattingState === void 0 ? void 0 : textFormattingState.codeDisabled,
95
+ codeHidden: textFormattingState === null || textFormattingState === void 0 ? void 0 : textFormattingState.codeHidden,
96
+ underlineActive: textFormattingState === null || textFormattingState === void 0 ? void 0 : textFormattingState.underlineActive,
97
+ underlineDisabled: textFormattingState === null || textFormattingState === void 0 ? void 0 : textFormattingState.underlineDisabled,
98
+ underlineHidden: textFormattingState === null || textFormattingState === void 0 ? void 0 : textFormattingState.underlineHidden,
99
+ strikeActive: textFormattingState === null || textFormattingState === void 0 ? void 0 : textFormattingState.strikeActive,
100
+ strikeDisabled: textFormattingState === null || textFormattingState === void 0 ? void 0 : textFormattingState.strikeDisabled,
101
+ strikeHidden: textFormattingState === null || textFormattingState === void 0 ? void 0 : textFormattingState.strikeHidden,
102
+ strongActive: textFormattingState === null || textFormattingState === void 0 ? void 0 : textFormattingState.strongActive,
103
+ strongDisabled: textFormattingState === null || textFormattingState === void 0 ? void 0 : textFormattingState.strongDisabled,
104
+ strongHidden: textFormattingState === null || textFormattingState === void 0 ? void 0 : textFormattingState.strongHidden,
105
+ superscriptActive: textFormattingState === null || textFormattingState === void 0 ? void 0 : textFormattingState.superscriptActive,
106
+ superscriptDisabled: textFormattingState === null || textFormattingState === void 0 ? void 0 : textFormattingState.superscriptDisabled,
107
+ superscriptHidden: textFormattingState === null || textFormattingState === void 0 ? void 0 : textFormattingState.superscriptHidden,
108
+ subscriptActive: textFormattingState === null || textFormattingState === void 0 ? void 0 : textFormattingState.subscriptActive,
109
+ subscriptDisabled: textFormattingState === null || textFormattingState === void 0 ? void 0 : textFormattingState.subscriptDisabled,
110
+ subscriptHidden: textFormattingState === null || textFormattingState === void 0 ? void 0 : textFormattingState.subscriptHidden
111
+ };
112
+ });
32
113
  var FloatingToolbarTextFormat = function FloatingToolbarTextFormat(_ref) {
33
114
  var api = _ref.api,
34
115
  editorAnalyticsAPI = _ref.editorAnalyticsAPI,
35
116
  editorView = _ref.editorView,
36
117
  intl = _ref.intl;
37
- var _useSharedPluginState = useSharedPluginState(api, ['textFormatting']),
38
- textFormattingState = _useSharedPluginState.textFormattingState;
118
+ var textFormattingState = useSharedState(api);
119
+ var formattingIsPresent = textFormattingState.formattingIsPresent,
120
+ formattingIconState = _objectWithoutProperties(textFormattingState, _excluded);
39
121
  var defaultIcons = useFormattingIcons({
40
122
  schema: editorView.state.schema,
41
123
  intl: intl,
42
124
  isToolbarDisabled: FloatingToolbarSettings.disabled,
43
125
  editorAnalyticsAPI: editorAnalyticsAPI,
44
- textFormattingState: textFormattingState,
126
+ textFormattingState: formattingIconState,
45
127
  toolbarType: FloatingToolbarSettings.toolbarType
46
128
  });
47
129
  var hasMultiplePartsWithFormattingSelected;
@@ -62,7 +144,8 @@ var FloatingToolbarTextFormat = function FloatingToolbarTextFormat(_ref) {
62
144
  dropdownItems = _useIconList.dropdownItems,
63
145
  singleItems = _useIconList.singleItems;
64
146
  var clearIcon = useClearIcon({
65
- textFormattingState: textFormattingState,
147
+ formattingPluginInitialised: textFormattingState.isInitialised,
148
+ formattingIsPresent: formattingIsPresent,
66
149
  intl: intl,
67
150
  editorAnalyticsAPI: editorAnalyticsAPI,
68
151
  toolbarType: FloatingToolbarSettings.toolbarType
@@ -1,7 +1,86 @@
1
1
  import React from 'react';
2
- import { useSharedPluginState } from '@atlaskit/editor-common/hooks';
2
+ import { useSharedPluginState, sharedPluginStateHookMigratorFactory } from '@atlaskit/editor-common/hooks';
3
+ import { useSharedPluginStateSelector } from '@atlaskit/editor-common/use-shared-plugin-state-selector';
3
4
  import Toolbar from './Toolbar';
4
5
  import { ToolbarType } from './Toolbar/types';
6
+ var useSharedState = sharedPluginStateHookMigratorFactory(function (api) {
7
+ var isInitialised = useSharedPluginStateSelector(api, 'textFormatting.isInitialised');
8
+ var formattingIsPresent = useSharedPluginStateSelector(api, 'textFormatting.formattingIsPresent');
9
+ var emActive = useSharedPluginStateSelector(api, 'textFormatting.emActive');
10
+ var emDisabled = useSharedPluginStateSelector(api, 'textFormatting.emDisabled');
11
+ var emHidden = useSharedPluginStateSelector(api, 'textFormatting.emHidden');
12
+ var codeActive = useSharedPluginStateSelector(api, 'textFormatting.codeActive');
13
+ var codeDisabled = useSharedPluginStateSelector(api, 'textFormatting.codeDisabled');
14
+ var codeHidden = useSharedPluginStateSelector(api, 'textFormatting.codeHidden');
15
+ var underlineActive = useSharedPluginStateSelector(api, 'textFormatting.underlineActive');
16
+ var underlineDisabled = useSharedPluginStateSelector(api, 'textFormatting.underlineDisabled');
17
+ var underlineHidden = useSharedPluginStateSelector(api, 'textFormatting.underlineHidden');
18
+ var strikeActive = useSharedPluginStateSelector(api, 'textFormatting.strikeActive');
19
+ var strikeDisabled = useSharedPluginStateSelector(api, 'textFormatting.strikeDisabled');
20
+ var strikeHidden = useSharedPluginStateSelector(api, 'textFormatting.strikeHidden');
21
+ var strongActive = useSharedPluginStateSelector(api, 'textFormatting.strongActive');
22
+ var strongDisabled = useSharedPluginStateSelector(api, 'textFormatting.strongDisabled');
23
+ var strongHidden = useSharedPluginStateSelector(api, 'textFormatting.strongHidden');
24
+ var superscriptActive = useSharedPluginStateSelector(api, 'textFormatting.superscriptActive');
25
+ var superscriptDisabled = useSharedPluginStateSelector(api, 'textFormatting.superscriptDisabled');
26
+ var superscriptHidden = useSharedPluginStateSelector(api, 'textFormatting.superscriptHidden');
27
+ var subscriptActive = useSharedPluginStateSelector(api, 'textFormatting.subscriptActive');
28
+ var subscriptDisabled = useSharedPluginStateSelector(api, 'textFormatting.subscriptDisabled');
29
+ var subscriptHidden = useSharedPluginStateSelector(api, 'textFormatting.subscriptHidden');
30
+ return {
31
+ isInitialised: Boolean(isInitialised),
32
+ formattingIsPresent: formattingIsPresent,
33
+ emActive: emActive,
34
+ emDisabled: emDisabled,
35
+ emHidden: emHidden,
36
+ codeActive: codeActive,
37
+ codeDisabled: codeDisabled,
38
+ codeHidden: codeHidden,
39
+ underlineActive: underlineActive,
40
+ underlineDisabled: underlineDisabled,
41
+ underlineHidden: underlineHidden,
42
+ strikeActive: strikeActive,
43
+ strikeDisabled: strikeDisabled,
44
+ strikeHidden: strikeHidden,
45
+ strongActive: strongActive,
46
+ strongDisabled: strongDisabled,
47
+ strongHidden: strongHidden,
48
+ superscriptActive: superscriptActive,
49
+ superscriptDisabled: superscriptDisabled,
50
+ superscriptHidden: superscriptHidden,
51
+ subscriptActive: subscriptActive,
52
+ subscriptDisabled: subscriptDisabled,
53
+ subscriptHidden: subscriptHidden
54
+ };
55
+ }, function (api) {
56
+ var _useSharedPluginState = useSharedPluginState(api, ['textFormatting']),
57
+ textFormattingState = _useSharedPluginState.textFormattingState;
58
+ return {
59
+ isInitialised: Boolean(textFormattingState === null || textFormattingState === void 0 ? void 0 : textFormattingState.isInitialised),
60
+ formattingIsPresent: textFormattingState === null || textFormattingState === void 0 ? void 0 : textFormattingState.formattingIsPresent,
61
+ emActive: textFormattingState === null || textFormattingState === void 0 ? void 0 : textFormattingState.emActive,
62
+ emDisabled: textFormattingState === null || textFormattingState === void 0 ? void 0 : textFormattingState.emDisabled,
63
+ emHidden: textFormattingState === null || textFormattingState === void 0 ? void 0 : textFormattingState.emHidden,
64
+ codeActive: textFormattingState === null || textFormattingState === void 0 ? void 0 : textFormattingState.codeActive,
65
+ codeDisabled: textFormattingState === null || textFormattingState === void 0 ? void 0 : textFormattingState.codeDisabled,
66
+ codeHidden: textFormattingState === null || textFormattingState === void 0 ? void 0 : textFormattingState.codeHidden,
67
+ underlineActive: textFormattingState === null || textFormattingState === void 0 ? void 0 : textFormattingState.underlineActive,
68
+ underlineDisabled: textFormattingState === null || textFormattingState === void 0 ? void 0 : textFormattingState.underlineDisabled,
69
+ underlineHidden: textFormattingState === null || textFormattingState === void 0 ? void 0 : textFormattingState.underlineHidden,
70
+ strikeActive: textFormattingState === null || textFormattingState === void 0 ? void 0 : textFormattingState.strikeActive,
71
+ strikeDisabled: textFormattingState === null || textFormattingState === void 0 ? void 0 : textFormattingState.strikeDisabled,
72
+ strikeHidden: textFormattingState === null || textFormattingState === void 0 ? void 0 : textFormattingState.strikeHidden,
73
+ strongActive: textFormattingState === null || textFormattingState === void 0 ? void 0 : textFormattingState.strongActive,
74
+ strongDisabled: textFormattingState === null || textFormattingState === void 0 ? void 0 : textFormattingState.strongDisabled,
75
+ strongHidden: textFormattingState === null || textFormattingState === void 0 ? void 0 : textFormattingState.strongHidden,
76
+ superscriptActive: textFormattingState === null || textFormattingState === void 0 ? void 0 : textFormattingState.superscriptActive,
77
+ superscriptDisabled: textFormattingState === null || textFormattingState === void 0 ? void 0 : textFormattingState.superscriptDisabled,
78
+ superscriptHidden: textFormattingState === null || textFormattingState === void 0 ? void 0 : textFormattingState.superscriptHidden,
79
+ subscriptActive: textFormattingState === null || textFormattingState === void 0 ? void 0 : textFormattingState.subscriptActive,
80
+ subscriptDisabled: textFormattingState === null || textFormattingState === void 0 ? void 0 : textFormattingState.subscriptDisabled,
81
+ subscriptHidden: textFormattingState === null || textFormattingState === void 0 ? void 0 : textFormattingState.subscriptHidden
82
+ };
83
+ });
5
84
  export function PrimaryToolbarComponent(_ref) {
6
85
  var _api$analytics;
7
86
  var api = _ref.api,
@@ -12,8 +91,7 @@ export function PrimaryToolbarComponent(_ref) {
12
91
  disabled = _ref.disabled,
13
92
  isReducedSpacing = _ref.isReducedSpacing,
14
93
  shouldUseResponsiveToolbar = _ref.shouldUseResponsiveToolbar;
15
- var _useSharedPluginState = useSharedPluginState(api, ['textFormatting']),
16
- textFormattingState = _useSharedPluginState.textFormattingState;
94
+ var textFormattingState = useSharedState(api);
17
95
  return /*#__PURE__*/React.createElement(Toolbar, {
18
96
  textFormattingState: textFormattingState,
19
97
  popupsMountPoint: popupsMountPoint,
@@ -15,11 +15,12 @@ import { clearFormattingWithAnalytics } from '../../../editor-commands/clear-for
15
15
  import { getInputMethod } from '../input-method-utils';
16
16
  export var useClearIcon = function useClearIcon(_ref) {
17
17
  var intl = _ref.intl,
18
- textFormattingState = _ref.textFormattingState,
18
+ formattingPluginInitialised = _ref.formattingPluginInitialised,
19
+ formattingPresent = _ref.formattingIsPresent,
19
20
  editorAnalyticsAPI = _ref.editorAnalyticsAPI,
20
21
  toolbarType = _ref.toolbarType;
21
- var isPluginAvailable = Boolean(textFormattingState);
22
- var formattingIsPresent = Boolean(textFormattingState === null || textFormattingState === void 0 ? void 0 : textFormattingState.formattingIsPresent);
22
+ var isPluginAvailable = Boolean(formattingPluginInitialised);
23
+ var formattingIsPresent = Boolean(formattingPresent);
23
24
  var clearFormattingLabel = intl.formatMessage(toolbarMessages.clearFormatting);
24
25
  var clearFormattingToolbar = useCallback(function (state, dispatch) {
25
26
  return clearFormattingWithAnalytics(getInputMethod(toolbarType), editorAnalyticsAPI)(state, dispatch);