@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
package/CHANGELOG.md CHANGED
@@ -1,5 +1,24 @@
1
1
  # @atlaskit/editor-plugin-text-formatting
2
2
 
3
+ ## 2.2.6
4
+
5
+ ### Patch Changes
6
+
7
+ - [#154988](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/pull-requests/154988)
8
+ [`76019734ff982`](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/commits/76019734ff982) -
9
+ [ED-27560] Adds `isInitialised` state variable to text-formatting plugin and migrates it to
10
+ useSharedPluginStateSelector
11
+ - Updated dependencies
12
+
13
+ ## 2.2.5
14
+
15
+ ### Patch Changes
16
+
17
+ - [#152656](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/pull-requests/152656)
18
+ [`cd915ad2cc130`](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/commits/cd915ad2cc130) -
19
+ Disallow keyboard formatting when selection contains text with code mark
20
+ - Updated dependencies
21
+
3
22
  ## 2.2.4
4
23
 
5
24
  ### Patch Changes
@@ -8,7 +8,10 @@ var _analytics = require("@atlaskit/editor-common/analytics");
8
8
  var _keymaps = require("@atlaskit/editor-common/keymaps");
9
9
  var _safePlugin = require("@atlaskit/editor-common/safe-plugin");
10
10
  var _keymap = require("@atlaskit/editor-prosemirror/keymap");
11
+ var _platformFeatureFlags = require("@atlaskit/platform-feature-flags");
12
+ var _experiments = require("@atlaskit/tmp-editor-statsig/experiments");
11
13
  var _commands = require("./commands");
14
+ var _pluginKey = require("./plugin-key");
12
15
  function keymapPlugin(schema, editorAnalyticsAPI) {
13
16
  var list = {};
14
17
  if (schema.marks.strong) {
@@ -53,11 +56,59 @@ function keymapPlugin(schema, editorAnalyticsAPI) {
53
56
  // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
54
57
  _keymaps.toggleUnderline.common, (0, _commands.toggleUnderlineWithAnalytics)(editorAnalyticsAPI)(_analytics.INPUT_METHOD.SHORTCUT), list);
55
58
  }
59
+ var getEnabledKeylist = function getEnabledKeylist(view) {
60
+ var textFormattingState = _pluginKey.pluginKey.getState(view.state);
61
+ var list = {};
62
+ if (schema.marks.strong && !(textFormattingState !== null && textFormattingState !== void 0 && textFormattingState.strongDisabled)) {
63
+ (0, _keymaps.bindKeymapWithEditorCommand)(
64
+ // Ignored via go/ees005
65
+ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
66
+ _keymaps.toggleBold.common, (0, _commands.toggleStrongWithAnalytics)(editorAnalyticsAPI)(_analytics.INPUT_METHOD.SHORTCUT), list);
67
+ }
68
+ if (schema.marks.em && !(textFormattingState !== null && textFormattingState !== void 0 && textFormattingState.emDisabled)) {
69
+ (0, _keymaps.bindKeymapWithEditorCommand)(
70
+ // Ignored via go/ees005
71
+ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
72
+ _keymaps.toggleItalic.common, (0, _commands.toggleEmWithAnalytics)(editorAnalyticsAPI)(_analytics.INPUT_METHOD.SHORTCUT), list);
73
+ }
74
+ if (schema.marks.code && !(textFormattingState !== null && textFormattingState !== void 0 && textFormattingState.codeDisabled)) {
75
+ (0, _keymaps.bindKeymapWithEditorCommand)(
76
+ // Ignored via go/ees005
77
+ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
78
+ _keymaps.toggleCode.common, (0, _commands.toggleCodeWithAnalytics)(editorAnalyticsAPI)(_analytics.INPUT_METHOD.SHORTCUT), list);
79
+ }
80
+ if (schema.marks.strike && !(textFormattingState !== null && textFormattingState !== void 0 && textFormattingState.strikeDisabled)) {
81
+ (0, _keymaps.bindKeymapWithEditorCommand)(
82
+ // Ignored via go/ees005
83
+ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
84
+ _keymaps.toggleStrikethrough.common, (0, _commands.toggleStrikeWithAnalytics)(editorAnalyticsAPI)(_analytics.INPUT_METHOD.SHORTCUT), list);
85
+ }
86
+ if (schema.marks.subsup && !(textFormattingState !== null && textFormattingState !== void 0 && textFormattingState.subscriptDisabled)) {
87
+ (0, _keymaps.bindKeymapWithEditorCommand)(
88
+ // Ignored via go/ees005
89
+ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
90
+ _keymaps.toggleSubscript.common, (0, _commands.toggleSubscriptWithAnalytics)(editorAnalyticsAPI)(_analytics.INPUT_METHOD.SHORTCUT), list);
91
+ }
92
+ if (schema.marks.subsup && !(textFormattingState !== null && textFormattingState !== void 0 && textFormattingState.superscriptDisabled)) {
93
+ (0, _keymaps.bindKeymapWithEditorCommand)(
94
+ // Ignored via go/ees005
95
+ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
96
+ _keymaps.toggleSuperscript.common, (0, _commands.toggleSuperscriptWithAnalytics)(editorAnalyticsAPI)(_analytics.INPUT_METHOD.SHORTCUT), list);
97
+ }
98
+ if (schema.marks.underline && !(textFormattingState !== null && textFormattingState !== void 0 && textFormattingState.underlineDisabled)) {
99
+ (0, _keymaps.bindKeymapWithEditorCommand)(
100
+ // Ignored via go/ees005
101
+ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
102
+ _keymaps.toggleUnderline.common, (0, _commands.toggleUnderlineWithAnalytics)(editorAnalyticsAPI)(_analytics.INPUT_METHOD.SHORTCUT), list);
103
+ }
104
+ return list;
105
+ };
56
106
  return new _safePlugin.SafePlugin({
57
107
  props: {
58
108
  handleKeyDown: function handleKeyDown(view, event) {
59
109
  var keyboardEvent = (0, _keymaps.isCapsLockOnAndModifyKeyboardEvent)(event);
60
- return (0, _keymap.keydownHandler)(list)(view, keyboardEvent);
110
+ var keymapList = (0, _experiments.editorExperiment)('platform_editor_controls', 'variant1') && (0, _platformFeatureFlags.fg)('platform_editor_controls_patch_8') ? getEnabledKeylist(view) : list;
111
+ return (0, _keymap.keydownHandler)(keymapList)(view, keyboardEvent);
61
112
  }
62
113
  }
63
114
  });
@@ -48,7 +48,9 @@ var getTextFormattingState = function getTextFormattingState(editorState, editor
48
48
  strong = _editorState$schema$m.strong,
49
49
  subsup = _editorState$schema$m.subsup,
50
50
  underline = _editorState$schema$m.underline;
51
- var state = {};
51
+ var state = {
52
+ isInitialised: true
53
+ };
52
54
  if (code) {
53
55
  state.codeActive = (0, _mark.anyMarkActive)(editorState, code.create());
54
56
  state.codeDisabled = !checkNodeSelection(code, editorState);
@@ -127,8 +127,10 @@ var textFormattingPlugin = exports.textFormattingPlugin = function textFormattin
127
127
  if (!editorState) {
128
128
  return undefined;
129
129
  }
130
- return _objectSpread(_objectSpread({}, _pluginKey.pluginKey.getState(editorState)), {}, {
131
- formattingIsPresent: (_clearFormattingPlugi = _clearFormatting.pluginKey.getState(editorState)) === null || _clearFormattingPlugi === void 0 ? void 0 : _clearFormattingPlugi.formattingIsPresent
130
+ var textFormattingState = _pluginKey.pluginKey.getState(editorState);
131
+ return _objectSpread(_objectSpread({}, textFormattingState), {}, {
132
+ formattingIsPresent: (_clearFormattingPlugi = _clearFormatting.pluginKey.getState(editorState)) === null || _clearFormattingPlugi === void 0 ? void 0 : _clearFormattingPlugi.formattingIsPresent,
133
+ isInitialised: !!(textFormattingState !== null && textFormattingState !== void 0 && textFormattingState.isInitialised)
132
134
  });
133
135
  },
134
136
  pluginsOptions: {
@@ -1,15 +1,18 @@
1
1
  "use strict";
2
2
 
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
3
4
  var _typeof = require("@babel/runtime/helpers/typeof");
4
5
  Object.defineProperty(exports, "__esModule", {
5
6
  value: true
6
7
  });
7
8
  exports.FloatingToolbarTextFormalWithIntl = void 0;
9
+ var _objectWithoutProperties2 = _interopRequireDefault(require("@babel/runtime/helpers/objectWithoutProperties"));
8
10
  var _react = _interopRequireWildcard(require("react"));
9
11
  var _react2 = require("@emotion/react");
10
12
  var _reactIntlNext = require("react-intl-next");
11
13
  var _hooks = require("@atlaskit/editor-common/hooks");
12
14
  var _types = require("@atlaskit/editor-common/types");
15
+ var _useSharedPluginStateSelector = require("@atlaskit/editor-common/use-shared-plugin-state-selector");
13
16
  var _state = require("@atlaskit/editor-prosemirror/state");
14
17
  var _platformFeatureFlags = require("@atlaskit/platform-feature-flags");
15
18
  var _experiments = require("@atlaskit/tmp-editor-statsig/experiments");
@@ -21,15 +24,14 @@ var _formattingIcons = require("./Toolbar/hooks/formatting-icons");
21
24
  var _useIconList2 = require("./Toolbar/hooks/use-icon-list");
22
25
  var _singleToolbarButtons = require("./Toolbar/single-toolbar-buttons");
23
26
  var _types2 = require("./Toolbar/types");
24
- 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); }
25
- 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 && {}.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; }
27
+ var _excluded = ["formattingIsPresent"];
26
28
  /**
27
29
  * @jsxRuntime classic
28
30
  * @jsx jsx
29
31
  */
30
-
31
32
  // eslint-disable-next-line @atlaskit/ui-styling-standard/use-compiled -- Ignored via go/DSP-18766
32
-
33
+ 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); }
34
+ 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 && {}.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; }
33
35
  var FloatingToolbarSettings = {
34
36
  disabled: false,
35
37
  isReducedSpacing: true,
@@ -39,19 +41,98 @@ var FloatingToolbarSettings = {
39
41
  moreButtonLabel: '',
40
42
  toolbarType: _types2.ToolbarType.FLOATING
41
43
  };
44
+ var useSharedState = (0, _hooks.sharedPluginStateHookMigratorFactory)(function (api) {
45
+ var isInitialised = (0, _useSharedPluginStateSelector.useSharedPluginStateSelector)(api, 'textFormatting.isInitialised');
46
+ var formattingIsPresent = (0, _useSharedPluginStateSelector.useSharedPluginStateSelector)(api, 'textFormatting.formattingIsPresent');
47
+ var emActive = (0, _useSharedPluginStateSelector.useSharedPluginStateSelector)(api, 'textFormatting.emActive');
48
+ var emDisabled = (0, _useSharedPluginStateSelector.useSharedPluginStateSelector)(api, 'textFormatting.emDisabled');
49
+ var emHidden = (0, _useSharedPluginStateSelector.useSharedPluginStateSelector)(api, 'textFormatting.emHidden');
50
+ var codeActive = (0, _useSharedPluginStateSelector.useSharedPluginStateSelector)(api, 'textFormatting.codeActive');
51
+ var codeDisabled = (0, _useSharedPluginStateSelector.useSharedPluginStateSelector)(api, 'textFormatting.codeDisabled');
52
+ var codeHidden = (0, _useSharedPluginStateSelector.useSharedPluginStateSelector)(api, 'textFormatting.codeHidden');
53
+ var underlineActive = (0, _useSharedPluginStateSelector.useSharedPluginStateSelector)(api, 'textFormatting.underlineActive');
54
+ var underlineDisabled = (0, _useSharedPluginStateSelector.useSharedPluginStateSelector)(api, 'textFormatting.underlineDisabled');
55
+ var underlineHidden = (0, _useSharedPluginStateSelector.useSharedPluginStateSelector)(api, 'textFormatting.underlineHidden');
56
+ var strikeActive = (0, _useSharedPluginStateSelector.useSharedPluginStateSelector)(api, 'textFormatting.strikeActive');
57
+ var strikeDisabled = (0, _useSharedPluginStateSelector.useSharedPluginStateSelector)(api, 'textFormatting.strikeDisabled');
58
+ var strikeHidden = (0, _useSharedPluginStateSelector.useSharedPluginStateSelector)(api, 'textFormatting.strikeHidden');
59
+ var strongActive = (0, _useSharedPluginStateSelector.useSharedPluginStateSelector)(api, 'textFormatting.strongActive');
60
+ var strongDisabled = (0, _useSharedPluginStateSelector.useSharedPluginStateSelector)(api, 'textFormatting.strongDisabled');
61
+ var strongHidden = (0, _useSharedPluginStateSelector.useSharedPluginStateSelector)(api, 'textFormatting.strongHidden');
62
+ var superscriptActive = (0, _useSharedPluginStateSelector.useSharedPluginStateSelector)(api, 'textFormatting.superscriptActive');
63
+ var superscriptDisabled = (0, _useSharedPluginStateSelector.useSharedPluginStateSelector)(api, 'textFormatting.superscriptDisabled');
64
+ var superscriptHidden = (0, _useSharedPluginStateSelector.useSharedPluginStateSelector)(api, 'textFormatting.superscriptHidden');
65
+ var subscriptActive = (0, _useSharedPluginStateSelector.useSharedPluginStateSelector)(api, 'textFormatting.subscriptActive');
66
+ var subscriptDisabled = (0, _useSharedPluginStateSelector.useSharedPluginStateSelector)(api, 'textFormatting.subscriptDisabled');
67
+ var subscriptHidden = (0, _useSharedPluginStateSelector.useSharedPluginStateSelector)(api, 'textFormatting.subscriptHidden');
68
+ return {
69
+ isInitialised: Boolean(isInitialised),
70
+ formattingIsPresent: formattingIsPresent,
71
+ emActive: emActive,
72
+ emDisabled: emDisabled,
73
+ emHidden: emHidden,
74
+ codeActive: codeActive,
75
+ codeDisabled: codeDisabled,
76
+ codeHidden: codeHidden,
77
+ underlineActive: underlineActive,
78
+ underlineDisabled: underlineDisabled,
79
+ underlineHidden: underlineHidden,
80
+ strikeActive: strikeActive,
81
+ strikeDisabled: strikeDisabled,
82
+ strikeHidden: strikeHidden,
83
+ strongActive: strongActive,
84
+ strongDisabled: strongDisabled,
85
+ strongHidden: strongHidden,
86
+ superscriptActive: superscriptActive,
87
+ superscriptDisabled: superscriptDisabled,
88
+ superscriptHidden: superscriptHidden,
89
+ subscriptActive: subscriptActive,
90
+ subscriptDisabled: subscriptDisabled,
91
+ subscriptHidden: subscriptHidden
92
+ };
93
+ }, function (api) {
94
+ var _useSharedPluginState = (0, _hooks.useSharedPluginState)(api, ['textFormatting']),
95
+ textFormattingState = _useSharedPluginState.textFormattingState;
96
+ return {
97
+ isInitialised: Boolean(textFormattingState === null || textFormattingState === void 0 ? void 0 : textFormattingState.isInitialised),
98
+ formattingIsPresent: textFormattingState === null || textFormattingState === void 0 ? void 0 : textFormattingState.formattingIsPresent,
99
+ emActive: textFormattingState === null || textFormattingState === void 0 ? void 0 : textFormattingState.emActive,
100
+ emDisabled: textFormattingState === null || textFormattingState === void 0 ? void 0 : textFormattingState.emDisabled,
101
+ emHidden: textFormattingState === null || textFormattingState === void 0 ? void 0 : textFormattingState.emHidden,
102
+ codeActive: textFormattingState === null || textFormattingState === void 0 ? void 0 : textFormattingState.codeActive,
103
+ codeDisabled: textFormattingState === null || textFormattingState === void 0 ? void 0 : textFormattingState.codeDisabled,
104
+ codeHidden: textFormattingState === null || textFormattingState === void 0 ? void 0 : textFormattingState.codeHidden,
105
+ underlineActive: textFormattingState === null || textFormattingState === void 0 ? void 0 : textFormattingState.underlineActive,
106
+ underlineDisabled: textFormattingState === null || textFormattingState === void 0 ? void 0 : textFormattingState.underlineDisabled,
107
+ underlineHidden: textFormattingState === null || textFormattingState === void 0 ? void 0 : textFormattingState.underlineHidden,
108
+ strikeActive: textFormattingState === null || textFormattingState === void 0 ? void 0 : textFormattingState.strikeActive,
109
+ strikeDisabled: textFormattingState === null || textFormattingState === void 0 ? void 0 : textFormattingState.strikeDisabled,
110
+ strikeHidden: textFormattingState === null || textFormattingState === void 0 ? void 0 : textFormattingState.strikeHidden,
111
+ strongActive: textFormattingState === null || textFormattingState === void 0 ? void 0 : textFormattingState.strongActive,
112
+ strongDisabled: textFormattingState === null || textFormattingState === void 0 ? void 0 : textFormattingState.strongDisabled,
113
+ strongHidden: textFormattingState === null || textFormattingState === void 0 ? void 0 : textFormattingState.strongHidden,
114
+ superscriptActive: textFormattingState === null || textFormattingState === void 0 ? void 0 : textFormattingState.superscriptActive,
115
+ superscriptDisabled: textFormattingState === null || textFormattingState === void 0 ? void 0 : textFormattingState.superscriptDisabled,
116
+ superscriptHidden: textFormattingState === null || textFormattingState === void 0 ? void 0 : textFormattingState.superscriptHidden,
117
+ subscriptActive: textFormattingState === null || textFormattingState === void 0 ? void 0 : textFormattingState.subscriptActive,
118
+ subscriptDisabled: textFormattingState === null || textFormattingState === void 0 ? void 0 : textFormattingState.subscriptDisabled,
119
+ subscriptHidden: textFormattingState === null || textFormattingState === void 0 ? void 0 : textFormattingState.subscriptHidden
120
+ };
121
+ });
42
122
  var FloatingToolbarTextFormat = function FloatingToolbarTextFormat(_ref) {
43
123
  var api = _ref.api,
44
124
  editorAnalyticsAPI = _ref.editorAnalyticsAPI,
45
125
  editorView = _ref.editorView,
46
126
  intl = _ref.intl;
47
- var _useSharedPluginState = (0, _hooks.useSharedPluginState)(api, ['textFormatting']),
48
- textFormattingState = _useSharedPluginState.textFormattingState;
127
+ var textFormattingState = useSharedState(api);
128
+ var formattingIsPresent = textFormattingState.formattingIsPresent,
129
+ formattingIconState = (0, _objectWithoutProperties2.default)(textFormattingState, _excluded);
49
130
  var defaultIcons = (0, _formattingIcons.useFormattingIcons)({
50
131
  schema: editorView.state.schema,
51
132
  intl: intl,
52
133
  isToolbarDisabled: FloatingToolbarSettings.disabled,
53
134
  editorAnalyticsAPI: editorAnalyticsAPI,
54
- textFormattingState: textFormattingState,
135
+ textFormattingState: formattingIconState,
55
136
  toolbarType: FloatingToolbarSettings.toolbarType
56
137
  });
57
138
  var hasMultiplePartsWithFormattingSelected;
@@ -72,7 +153,8 @@ var FloatingToolbarTextFormat = function FloatingToolbarTextFormat(_ref) {
72
153
  dropdownItems = _useIconList.dropdownItems,
73
154
  singleItems = _useIconList.singleItems;
74
155
  var clearIcon = (0, _clearFormattingIcon.useClearIcon)({
75
- textFormattingState: textFormattingState,
156
+ formattingPluginInitialised: textFormattingState.isInitialised,
157
+ formattingIsPresent: formattingIsPresent,
76
158
  intl: intl,
77
159
  editorAnalyticsAPI: editorAnalyticsAPI,
78
160
  toolbarType: FloatingToolbarSettings.toolbarType
@@ -7,8 +7,87 @@ Object.defineProperty(exports, "__esModule", {
7
7
  exports.PrimaryToolbarComponent = PrimaryToolbarComponent;
8
8
  var _react = _interopRequireDefault(require("react"));
9
9
  var _hooks = require("@atlaskit/editor-common/hooks");
10
+ var _useSharedPluginStateSelector = require("@atlaskit/editor-common/use-shared-plugin-state-selector");
10
11
  var _Toolbar = _interopRequireDefault(require("./Toolbar"));
11
12
  var _types = require("./Toolbar/types");
13
+ var useSharedState = (0, _hooks.sharedPluginStateHookMigratorFactory)(function (api) {
14
+ var isInitialised = (0, _useSharedPluginStateSelector.useSharedPluginStateSelector)(api, 'textFormatting.isInitialised');
15
+ var formattingIsPresent = (0, _useSharedPluginStateSelector.useSharedPluginStateSelector)(api, 'textFormatting.formattingIsPresent');
16
+ var emActive = (0, _useSharedPluginStateSelector.useSharedPluginStateSelector)(api, 'textFormatting.emActive');
17
+ var emDisabled = (0, _useSharedPluginStateSelector.useSharedPluginStateSelector)(api, 'textFormatting.emDisabled');
18
+ var emHidden = (0, _useSharedPluginStateSelector.useSharedPluginStateSelector)(api, 'textFormatting.emHidden');
19
+ var codeActive = (0, _useSharedPluginStateSelector.useSharedPluginStateSelector)(api, 'textFormatting.codeActive');
20
+ var codeDisabled = (0, _useSharedPluginStateSelector.useSharedPluginStateSelector)(api, 'textFormatting.codeDisabled');
21
+ var codeHidden = (0, _useSharedPluginStateSelector.useSharedPluginStateSelector)(api, 'textFormatting.codeHidden');
22
+ var underlineActive = (0, _useSharedPluginStateSelector.useSharedPluginStateSelector)(api, 'textFormatting.underlineActive');
23
+ var underlineDisabled = (0, _useSharedPluginStateSelector.useSharedPluginStateSelector)(api, 'textFormatting.underlineDisabled');
24
+ var underlineHidden = (0, _useSharedPluginStateSelector.useSharedPluginStateSelector)(api, 'textFormatting.underlineHidden');
25
+ var strikeActive = (0, _useSharedPluginStateSelector.useSharedPluginStateSelector)(api, 'textFormatting.strikeActive');
26
+ var strikeDisabled = (0, _useSharedPluginStateSelector.useSharedPluginStateSelector)(api, 'textFormatting.strikeDisabled');
27
+ var strikeHidden = (0, _useSharedPluginStateSelector.useSharedPluginStateSelector)(api, 'textFormatting.strikeHidden');
28
+ var strongActive = (0, _useSharedPluginStateSelector.useSharedPluginStateSelector)(api, 'textFormatting.strongActive');
29
+ var strongDisabled = (0, _useSharedPluginStateSelector.useSharedPluginStateSelector)(api, 'textFormatting.strongDisabled');
30
+ var strongHidden = (0, _useSharedPluginStateSelector.useSharedPluginStateSelector)(api, 'textFormatting.strongHidden');
31
+ var superscriptActive = (0, _useSharedPluginStateSelector.useSharedPluginStateSelector)(api, 'textFormatting.superscriptActive');
32
+ var superscriptDisabled = (0, _useSharedPluginStateSelector.useSharedPluginStateSelector)(api, 'textFormatting.superscriptDisabled');
33
+ var superscriptHidden = (0, _useSharedPluginStateSelector.useSharedPluginStateSelector)(api, 'textFormatting.superscriptHidden');
34
+ var subscriptActive = (0, _useSharedPluginStateSelector.useSharedPluginStateSelector)(api, 'textFormatting.subscriptActive');
35
+ var subscriptDisabled = (0, _useSharedPluginStateSelector.useSharedPluginStateSelector)(api, 'textFormatting.subscriptDisabled');
36
+ var subscriptHidden = (0, _useSharedPluginStateSelector.useSharedPluginStateSelector)(api, 'textFormatting.subscriptHidden');
37
+ return {
38
+ isInitialised: Boolean(isInitialised),
39
+ formattingIsPresent: formattingIsPresent,
40
+ emActive: emActive,
41
+ emDisabled: emDisabled,
42
+ emHidden: emHidden,
43
+ codeActive: codeActive,
44
+ codeDisabled: codeDisabled,
45
+ codeHidden: codeHidden,
46
+ underlineActive: underlineActive,
47
+ underlineDisabled: underlineDisabled,
48
+ underlineHidden: underlineHidden,
49
+ strikeActive: strikeActive,
50
+ strikeDisabled: strikeDisabled,
51
+ strikeHidden: strikeHidden,
52
+ strongActive: strongActive,
53
+ strongDisabled: strongDisabled,
54
+ strongHidden: strongHidden,
55
+ superscriptActive: superscriptActive,
56
+ superscriptDisabled: superscriptDisabled,
57
+ superscriptHidden: superscriptHidden,
58
+ subscriptActive: subscriptActive,
59
+ subscriptDisabled: subscriptDisabled,
60
+ subscriptHidden: subscriptHidden
61
+ };
62
+ }, function (api) {
63
+ var _useSharedPluginState = (0, _hooks.useSharedPluginState)(api, ['textFormatting']),
64
+ textFormattingState = _useSharedPluginState.textFormattingState;
65
+ return {
66
+ isInitialised: Boolean(textFormattingState === null || textFormattingState === void 0 ? void 0 : textFormattingState.isInitialised),
67
+ formattingIsPresent: textFormattingState === null || textFormattingState === void 0 ? void 0 : textFormattingState.formattingIsPresent,
68
+ emActive: textFormattingState === null || textFormattingState === void 0 ? void 0 : textFormattingState.emActive,
69
+ emDisabled: textFormattingState === null || textFormattingState === void 0 ? void 0 : textFormattingState.emDisabled,
70
+ emHidden: textFormattingState === null || textFormattingState === void 0 ? void 0 : textFormattingState.emHidden,
71
+ codeActive: textFormattingState === null || textFormattingState === void 0 ? void 0 : textFormattingState.codeActive,
72
+ codeDisabled: textFormattingState === null || textFormattingState === void 0 ? void 0 : textFormattingState.codeDisabled,
73
+ codeHidden: textFormattingState === null || textFormattingState === void 0 ? void 0 : textFormattingState.codeHidden,
74
+ underlineActive: textFormattingState === null || textFormattingState === void 0 ? void 0 : textFormattingState.underlineActive,
75
+ underlineDisabled: textFormattingState === null || textFormattingState === void 0 ? void 0 : textFormattingState.underlineDisabled,
76
+ underlineHidden: textFormattingState === null || textFormattingState === void 0 ? void 0 : textFormattingState.underlineHidden,
77
+ strikeActive: textFormattingState === null || textFormattingState === void 0 ? void 0 : textFormattingState.strikeActive,
78
+ strikeDisabled: textFormattingState === null || textFormattingState === void 0 ? void 0 : textFormattingState.strikeDisabled,
79
+ strikeHidden: textFormattingState === null || textFormattingState === void 0 ? void 0 : textFormattingState.strikeHidden,
80
+ strongActive: textFormattingState === null || textFormattingState === void 0 ? void 0 : textFormattingState.strongActive,
81
+ strongDisabled: textFormattingState === null || textFormattingState === void 0 ? void 0 : textFormattingState.strongDisabled,
82
+ strongHidden: textFormattingState === null || textFormattingState === void 0 ? void 0 : textFormattingState.strongHidden,
83
+ superscriptActive: textFormattingState === null || textFormattingState === void 0 ? void 0 : textFormattingState.superscriptActive,
84
+ superscriptDisabled: textFormattingState === null || textFormattingState === void 0 ? void 0 : textFormattingState.superscriptDisabled,
85
+ superscriptHidden: textFormattingState === null || textFormattingState === void 0 ? void 0 : textFormattingState.superscriptHidden,
86
+ subscriptActive: textFormattingState === null || textFormattingState === void 0 ? void 0 : textFormattingState.subscriptActive,
87
+ subscriptDisabled: textFormattingState === null || textFormattingState === void 0 ? void 0 : textFormattingState.subscriptDisabled,
88
+ subscriptHidden: textFormattingState === null || textFormattingState === void 0 ? void 0 : textFormattingState.subscriptHidden
89
+ };
90
+ });
12
91
  function PrimaryToolbarComponent(_ref) {
13
92
  var _api$analytics;
14
93
  var api = _ref.api,
@@ -19,8 +98,7 @@ function PrimaryToolbarComponent(_ref) {
19
98
  disabled = _ref.disabled,
20
99
  isReducedSpacing = _ref.isReducedSpacing,
21
100
  shouldUseResponsiveToolbar = _ref.shouldUseResponsiveToolbar;
22
- var _useSharedPluginState = (0, _hooks.useSharedPluginState)(api, ['textFormatting']),
23
- textFormattingState = _useSharedPluginState.textFormattingState;
101
+ var textFormattingState = useSharedState(api);
24
102
  return /*#__PURE__*/_react.default.createElement(_Toolbar.default, {
25
103
  textFormattingState: textFormattingState,
26
104
  popupsMountPoint: popupsMountPoint,
@@ -23,11 +23,12 @@ var _inputMethodUtils = require("../input-method-utils");
23
23
 
24
24
  var useClearIcon = exports.useClearIcon = function useClearIcon(_ref) {
25
25
  var intl = _ref.intl,
26
- textFormattingState = _ref.textFormattingState,
26
+ formattingPluginInitialised = _ref.formattingPluginInitialised,
27
+ formattingPresent = _ref.formattingIsPresent,
27
28
  editorAnalyticsAPI = _ref.editorAnalyticsAPI,
28
29
  toolbarType = _ref.toolbarType;
29
- var isPluginAvailable = Boolean(textFormattingState);
30
- var formattingIsPresent = Boolean(textFormattingState === null || textFormattingState === void 0 ? void 0 : textFormattingState.formattingIsPresent);
30
+ var isPluginAvailable = Boolean(formattingPluginInitialised);
31
+ var formattingIsPresent = Boolean(formattingPresent);
31
32
  var clearFormattingLabel = intl.formatMessage(_messages.toolbarMessages.clearFormatting);
32
33
  var clearFormattingToolbar = (0, _react.useCallback)(function (state, dispatch) {
33
34
  return (0, _clearFormatting.clearFormattingWithAnalytics)((0, _inputMethodUtils.getInputMethod)(toolbarType), editorAnalyticsAPI)(state, dispatch);
@@ -176,7 +176,7 @@ var buildMenuIconState = function buildMenuIconState(iconMark) {
176
176
  return function (_ref2) {
177
177
  var schema = _ref2.schema,
178
178
  textFormattingState = _ref2.textFormattingState;
179
- var hasPluginState = Boolean(Object.keys(textFormattingState || {}).length);
179
+ var hasPluginState = Boolean(textFormattingState === null || textFormattingState === void 0 ? void 0 : textFormattingState.isInitialised);
180
180
  var markSchema = IconsMarkSchema[iconMark];
181
181
  var hasSchemaMark = Boolean(schema.marks[markSchema]);
182
182
  if (!hasPluginState) {
@@ -266,7 +266,7 @@ var useHasFormattingActived = exports.useHasFormattingActived = function useHasF
266
266
  var iconTypeList = _ref5.iconTypeList,
267
267
  textFormattingState = _ref5.textFormattingState;
268
268
  var hasActiveFormatting = (0, _react.useMemo)(function () {
269
- if (!textFormattingState) {
269
+ if (!(textFormattingState !== null && textFormattingState !== void 0 && textFormattingState.isInitialised)) {
270
270
  return false;
271
271
  }
272
272
  return iconTypeList.some(function (iconType) {
@@ -6,6 +6,7 @@ Object.defineProperty(exports, "__esModule", {
6
6
  });
7
7
  exports.default = void 0;
8
8
  var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray"));
9
+ var _objectWithoutProperties2 = _interopRequireDefault(require("@babel/runtime/helpers/objectWithoutProperties"));
9
10
  var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
10
11
  var _react = require("react");
11
12
  var _react2 = require("@emotion/react");
@@ -23,13 +24,12 @@ var _formattingIcons = require("./hooks/formatting-icons");
23
24
  var _responsiveToolbarButtons = require("./hooks/responsive-toolbar-buttons");
24
25
  var _moreButton = require("./more-button");
25
26
  var _singleToolbarButtons = require("./single-toolbar-buttons");
27
+ var _excluded = ["formattingIsPresent"];
26
28
  /**
27
29
  * @jsxRuntime classic
28
30
  * @jsx jsx
29
31
  */
30
-
31
32
  // eslint-disable-next-line @atlaskit/ui-styling-standard/use-compiled -- Ignored via go/DSP-18766
32
-
33
33
  var ToolbarFormatting = function ToolbarFormatting(_ref) {
34
34
  var _usePreviousState;
35
35
  var shouldUseResponsiveToolbar = _ref.shouldUseResponsiveToolbar,
@@ -49,16 +49,19 @@ var ToolbarFormatting = function ToolbarFormatting(_ref) {
49
49
  _useState2 = (0, _slicedToArray2.default)(_useState, 2),
50
50
  message = _useState2[0],
51
51
  setMessage = _useState2[1];
52
+ var formattingIsPresent = textFormattingState.formattingIsPresent,
53
+ formattingIconState = (0, _objectWithoutProperties2.default)(textFormattingState, _excluded);
52
54
  var defaultIcons = (0, _formattingIcons.useFormattingIcons)({
53
55
  schema: editorView.state.schema,
54
56
  intl: intl,
55
57
  isToolbarDisabled: isToolbarDisabled,
56
58
  editorAnalyticsAPI: editorAnalyticsAPI,
57
- textFormattingState: textFormattingState,
59
+ textFormattingState: formattingIconState,
58
60
  toolbarType: toolbarType
59
61
  });
60
62
  var clearIcon = (0, _clearFormattingIcon.useClearIcon)({
61
- textFormattingState: textFormattingState,
63
+ formattingPluginInitialised: textFormattingState.isInitialised,
64
+ formattingIsPresent: formattingIsPresent,
62
65
  intl: intl,
63
66
  editorAnalyticsAPI: editorAnalyticsAPI,
64
67
  toolbarType: 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
  const 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
+ const getEnabledKeylist = view => {
54
+ const textFormattingState = pluginKey.getState(view.state);
55
+ const 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(view, event) {
53
103
  const keyboardEvent = isCapsLockOnAndModifyKeyboardEvent(event);
54
- return keydownHandler(list)(view, keyboardEvent);
104
+ const 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
  });
@@ -39,7 +39,9 @@ const getTextFormattingState = (editorState, editorAnalyticsAPI) => {
39
39
  subsup,
40
40
  underline
41
41
  } = editorState.schema.marks;
42
- const state = {};
42
+ const state = {
43
+ isInitialised: true
44
+ };
43
45
  if (code) {
44
46
  state.codeActive = anyMarkActive(editorState, code.create());
45
47
  state.codeDisabled = !checkNodeSelection(code, editorState);
@@ -120,9 +120,11 @@ export const textFormattingPlugin = ({
120
120
  if (!editorState) {
121
121
  return undefined;
122
122
  }
123
+ const textFormattingState = textFormattingPluginKey.getState(editorState);
123
124
  return {
124
- ...textFormattingPluginKey.getState(editorState),
125
- formattingIsPresent: (_clearFormattingPlugi = clearFormattingPluginKey.getState(editorState)) === null || _clearFormattingPlugi === void 0 ? void 0 : _clearFormattingPlugi.formattingIsPresent
125
+ ...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: {