@atlaskit/editor-plugin-text-formatting 22.0.2 → 22.0.4
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
CHANGED
|
@@ -1,5 +1,19 @@
|
|
|
1
1
|
# @atlaskit/editor-plugin-text-formatting
|
|
2
2
|
|
|
3
|
+
## 22.0.4
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- Updated dependencies
|
|
8
|
+
|
|
9
|
+
## 22.0.3
|
|
10
|
+
|
|
11
|
+
### Patch Changes
|
|
12
|
+
|
|
13
|
+
- [`85394203c5e0a`](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/commits/85394203c5e0a) -
|
|
14
|
+
Cleanup `platform_editor_markdown_compatible_toolbar`.
|
|
15
|
+
- Updated dependencies
|
|
16
|
+
|
|
3
17
|
## 22.0.2
|
|
4
18
|
|
|
5
19
|
### Patch Changes
|
|
@@ -7,46 +7,14 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
7
7
|
exports.useComponentInfo = exports.formatOptions = void 0;
|
|
8
8
|
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
9
9
|
var _reactIntl = require("react-intl");
|
|
10
|
-
var _analytics = require("@atlaskit/editor-common/analytics");
|
|
11
10
|
var _hooks = require("@atlaskit/editor-common/hooks");
|
|
12
11
|
var _keymaps = require("@atlaskit/editor-common/keymaps");
|
|
13
12
|
var _messages = require("@atlaskit/editor-common/messages");
|
|
14
13
|
var _toolbar = require("@atlaskit/editor-common/toolbar");
|
|
15
14
|
var _editorToolbar = require("@atlaskit/editor-toolbar");
|
|
16
|
-
var _fg = require("@atlaskit/platform-feature-flags/fg");
|
|
17
|
-
var _expValEqualsNoExposure = require("@atlaskit/tmp-editor-statsig/exp-val-equals-no-exposure");
|
|
18
15
|
var _toggleMark = require("../../../editor-commands/toggle-mark");
|
|
19
16
|
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
|
20
17
|
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) { (0, _defineProperty2.default)(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; } // oxlint-disable-next-line import/no-duplicates
|
|
21
|
-
/**
|
|
22
|
-
* Local copy of `@atlassian/editor-plugin-markdown-mode/source-view-utils`'s
|
|
23
|
-
* `SourceViewInlineFormat` union. Kept here so this `@atlaskit/`-published
|
|
24
|
-
* package doesn't depend on the `@atlassian/`-namespaced source-view-utils
|
|
25
|
-
* subpath for type resolution. Must stay in sync with the source-of-truth
|
|
26
|
-
* declaration in markdown-mode.
|
|
27
|
-
*/
|
|
28
|
-
|
|
29
|
-
/**
|
|
30
|
-
* Maps the text-formatting plugin's `FormatOptions` keys to their
|
|
31
|
-
* `SourceViewInlineFormat` equivalents for the CM6 source view.
|
|
32
|
-
* Only formats that have a markdown syntax equivalent are included —
|
|
33
|
-
* underline, subscript, and superscript have no GFM equivalent and
|
|
34
|
-
* are left as undefined (they remain PM-only).
|
|
35
|
-
*/
|
|
36
|
-
var FORMAT_OPTION_TO_SOURCE_VIEW = {
|
|
37
|
-
strong: 'bold',
|
|
38
|
-
em: 'italic',
|
|
39
|
-
code: 'inlineCode',
|
|
40
|
-
strike: 'strikethrough'
|
|
41
|
-
};
|
|
42
|
-
var SOURCE_VIEW_ANALYTICS_ACTION_SUBJECT_ID = {
|
|
43
|
-
bold: _analytics.ACTION_SUBJECT_ID.FORMAT_STRONG,
|
|
44
|
-
italic: _analytics.ACTION_SUBJECT_ID.FORMAT_ITALIC,
|
|
45
|
-
inlineCode: _analytics.ACTION_SUBJECT_ID.FORMAT_CODE,
|
|
46
|
-
strikethrough: _analytics.ACTION_SUBJECT_ID.FORMAT_STRIKE
|
|
47
|
-
};
|
|
48
|
-
var TEXT_FORMATTING_PLUGIN_STATE_KEYS = ['textFormatting'];
|
|
49
|
-
var TEXT_FORMATTING_MARKDOWN_PLUGIN_STATE_KEYS = ['textFormatting', 'markdownMode'];
|
|
50
18
|
var FormatMarkSchema = {
|
|
51
19
|
strong: 'strong',
|
|
52
20
|
em: 'em',
|
|
@@ -64,25 +32,19 @@ var useComponentInfo = exports.useComponentInfo = function useComponentInfo(_ref
|
|
|
64
32
|
shortcut = _ref.shortcut,
|
|
65
33
|
toggleMarkWithAnalyticsCallback = _ref.toggleMarkWithAnalyticsCallback,
|
|
66
34
|
parents = _ref.parents;
|
|
67
|
-
var
|
|
68
|
-
|
|
69
|
-
var _useSharedPluginState = (0, _hooks.useSharedPluginStateWithSelector)(api, pluginStateKeys, function (states) {
|
|
70
|
-
var _states$textFormattin, _states$textFormattin2, _states$textFormattin3, _states$textFormattin4, _states$markdownModeS, _states$markdownModeS2;
|
|
35
|
+
var _useSharedPluginState = (0, _hooks.useSharedPluginStateWithSelector)(api, ['textFormatting'], function (states) {
|
|
36
|
+
var _states$textFormattin, _states$textFormattin2, _states$textFormattin3, _states$textFormattin4;
|
|
71
37
|
return {
|
|
72
38
|
isActive: (_states$textFormattin = states.textFormattingState) === null || _states$textFormattin === void 0 ? void 0 : _states$textFormattin["".concat(optionType, "Active")],
|
|
73
39
|
isDisabled: (_states$textFormattin2 = states.textFormattingState) === null || _states$textFormattin2 === void 0 ? void 0 : _states$textFormattin2["".concat(optionType, "Disabled")],
|
|
74
40
|
isHidden: (_states$textFormattin3 = states.textFormattingState) === null || _states$textFormattin3 === void 0 ? void 0 : _states$textFormattin3["".concat(optionType, "Hidden")],
|
|
75
|
-
isPluginInitialised: (_states$textFormattin4 = states.textFormattingState) === null || _states$textFormattin4 === void 0 ? void 0 : _states$textFormattin4.isInitialised
|
|
76
|
-
markdownModeView: isMarkdownBridgeEnabled ? (_states$markdownModeS = states.markdownModeState) === null || _states$markdownModeS === void 0 ? void 0 : _states$markdownModeS.view : undefined,
|
|
77
|
-
sourceFormatState: isMarkdownBridgeEnabled ? (_states$markdownModeS2 = states.markdownModeState) === null || _states$markdownModeS2 === void 0 ? void 0 : _states$markdownModeS2.sourceInlineFormatState : null
|
|
41
|
+
isPluginInitialised: (_states$textFormattin4 = states.textFormattingState) === null || _states$textFormattin4 === void 0 ? void 0 : _states$textFormattin4.isInitialised
|
|
78
42
|
};
|
|
79
43
|
}),
|
|
80
44
|
isActive = _useSharedPluginState.isActive,
|
|
81
45
|
isDisabled = _useSharedPluginState.isDisabled,
|
|
82
46
|
isHidden = _useSharedPluginState.isHidden,
|
|
83
|
-
isPluginInitialised = _useSharedPluginState.isPluginInitialised
|
|
84
|
-
markdownModeView = _useSharedPluginState.markdownModeView,
|
|
85
|
-
sourceFormatState = _useSharedPluginState.sourceFormatState;
|
|
47
|
+
isPluginInitialised = _useSharedPluginState.isPluginInitialised;
|
|
86
48
|
var hasMarkSchema = api === null || api === void 0 || (_api$core = api.core) === null || _api$core === void 0 || (_api$core = _api$core.sharedState.currentState()) === null || _api$core === void 0 || (_api$core = _api$core.schema) === null || _api$core === void 0 ? void 0 : _api$core.marks[FormatMarkSchema[optionType]];
|
|
87
49
|
var formatOptionState;
|
|
88
50
|
if (!isPluginInitialised) {
|
|
@@ -103,89 +65,9 @@ var useComponentInfo = exports.useComponentInfo = function useComponentInfo(_ref
|
|
|
103
65
|
var formatTitle = formatMessage(title);
|
|
104
66
|
var shortcutContent = (0, _keymaps.tooltip)(shortcut);
|
|
105
67
|
var ariaLabel = (0, _keymaps.tooltip)(shortcut, formatTitle);
|
|
106
|
-
|
|
107
|
-
// The SourceViewInlineFormat key for this format option, if it has one.
|
|
108
|
-
// undefined for underline, subscript, superscript (no GFM equivalent).
|
|
109
|
-
var sourceViewFormat = FORMAT_OPTION_TO_SOURCE_VIEW[optionType];
|
|
110
|
-
|
|
111
|
-
// The CM6 source view is authoritative when the user has switched to it.
|
|
112
|
-
// We rely on `markdownModeState.view === 'syntax'` (synchronous, set on
|
|
113
|
-
// `setView`) rather than the presence of `sourceFormatState` — the latter
|
|
114
|
-
// is `null` until the CM6 update listener fires for the first time, so
|
|
115
|
-
// using it as the sentinel would let the first toolbar click after entering
|
|
116
|
-
// source view fall through to the PM path and mutate the hidden PM doc.
|
|
117
|
-
var isInSourceView = markdownModeView === 'syntax';
|
|
118
|
-
if (isInSourceView && !sourceViewFormat) {
|
|
119
|
-
// Underline, subscript, superscript have no GFM equivalent. Disable
|
|
120
|
-
// them immediately on entering source view — independent of whether
|
|
121
|
-
// the CM6 update listener has fired yet — so the buttons don't briefly
|
|
122
|
-
// appear active/enabled during that race window.
|
|
123
|
-
formatOptionState = {
|
|
124
|
-
isActive: false,
|
|
125
|
-
isDisabled: true,
|
|
126
|
-
isHidden: false
|
|
127
|
-
};
|
|
128
|
-
} else if (isInSourceView && sourceFormatState && sourceViewFormat) {
|
|
129
|
-
// Map each SourceViewInlineFormat to its isActive field on the snapshot.
|
|
130
|
-
var activeByFormat = {
|
|
131
|
-
bold: sourceFormatState.boldActive,
|
|
132
|
-
italic: sourceFormatState.italicActive,
|
|
133
|
-
inlineCode: sourceFormatState.codeActive,
|
|
134
|
-
strikethrough: sourceFormatState.strikeActive
|
|
135
|
-
};
|
|
136
|
-
formatOptionState = {
|
|
137
|
-
isActive: activeByFormat[sourceViewFormat],
|
|
138
|
-
isDisabled: !sourceFormatState.inlineFormattingAvailable,
|
|
139
|
-
isHidden: false
|
|
140
|
-
};
|
|
141
|
-
} else if (isInSourceView) {
|
|
142
|
-
// Race window: the user has switched to source view but the CM6 update
|
|
143
|
-
// listener hasn't pushed its first format state snapshot yet
|
|
144
|
-
// (`sourceFormatState` is still `null`). Without this branch the
|
|
145
|
-
// button would render stale PM-cursor state (e.g. "Bold active" based
|
|
146
|
-
// on where the PM selection was) until CM6 catches up. Render a
|
|
147
|
-
// neutral, non-disabled state instead.
|
|
148
|
-
formatOptionState = {
|
|
149
|
-
isActive: false,
|
|
150
|
-
isDisabled: false,
|
|
151
|
-
isHidden: false
|
|
152
|
-
};
|
|
153
|
-
}
|
|
154
68
|
var onClick = function onClick() {
|
|
155
|
-
var _api$
|
|
156
|
-
|
|
157
|
-
if (isInSourceView) {
|
|
158
|
-
if (sourceViewFormat) {
|
|
159
|
-
var _api$analytics;
|
|
160
|
-
api === null || api === void 0 || (_api$analytics = api.analytics) === null || _api$analytics === void 0 || _api$analytics.actions.fireAnalyticsEvent({
|
|
161
|
-
action: _analytics.ACTION.FORMATTED,
|
|
162
|
-
actionSubject: _analytics.ACTION_SUBJECT.TEXT,
|
|
163
|
-
eventType: _analytics.EVENT_TYPE.TRACK,
|
|
164
|
-
actionSubjectId: SOURCE_VIEW_ANALYTICS_ACTION_SUBJECT_ID[sourceViewFormat],
|
|
165
|
-
attributes: {
|
|
166
|
-
inputMethod: (0, _toolbar.getInputMethodFromParentKeys)(parents)
|
|
167
|
-
}
|
|
168
|
-
});
|
|
169
|
-
switch (sourceViewFormat) {
|
|
170
|
-
case 'bold':
|
|
171
|
-
api === null || api === void 0 || (_api$markdownMode = api.markdownMode) === null || _api$markdownMode === void 0 || _api$markdownMode.actions.toggleSourceBold();
|
|
172
|
-
break;
|
|
173
|
-
case 'italic':
|
|
174
|
-
api === null || api === void 0 || (_api$markdownMode2 = api.markdownMode) === null || _api$markdownMode2 === void 0 || _api$markdownMode2.actions.toggleSourceItalic();
|
|
175
|
-
break;
|
|
176
|
-
case 'inlineCode':
|
|
177
|
-
api === null || api === void 0 || (_api$markdownMode3 = api.markdownMode) === null || _api$markdownMode3 === void 0 || _api$markdownMode3.actions.toggleSourceInlineCode();
|
|
178
|
-
break;
|
|
179
|
-
case 'strikethrough':
|
|
180
|
-
api === null || api === void 0 || (_api$markdownMode4 = api.markdownMode) === null || _api$markdownMode4 === void 0 || _api$markdownMode4.actions.toggleSourceStrike();
|
|
181
|
-
break;
|
|
182
|
-
}
|
|
183
|
-
}
|
|
184
|
-
return;
|
|
185
|
-
}
|
|
186
|
-
|
|
187
|
-
// Default PM path.
|
|
188
|
-
api === null || api === void 0 || api.core.actions.execute(toggleMarkWithAnalyticsCallback(api === null || api === void 0 || (_api$analytics2 = api.analytics) === null || _api$analytics2 === void 0 ? void 0 : _api$analytics2.actions)((0, _toolbar.getInputMethodFromParentKeys)(parents)));
|
|
69
|
+
var _api$analytics;
|
|
70
|
+
api === null || api === void 0 || api.core.actions.execute(toggleMarkWithAnalyticsCallback(api === null || api === void 0 || (_api$analytics = api.analytics) === null || _api$analytics === void 0 ? void 0 : _api$analytics.actions)((0, _toolbar.getInputMethodFromParentKeys)(parents)));
|
|
189
71
|
};
|
|
190
72
|
return _objectSpread(_objectSpread({}, formatOptionState), {}, {
|
|
191
73
|
formatTitle: formatTitle,
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { useIntl } from 'react-intl';
|
|
2
|
-
import { ACTION, ACTION_SUBJECT, ACTION_SUBJECT_ID, EVENT_TYPE } from '@atlaskit/editor-common/analytics';
|
|
3
2
|
import { useSharedPluginStateWithSelector } from '@atlaskit/editor-common/hooks';
|
|
4
3
|
import { toggleBold, toggleCode, toggleItalic, toggleStrikethrough, toggleSubscript, toggleSuperscript, toggleUnderline, tooltip } from '@atlaskit/editor-common/keymaps';
|
|
5
4
|
import { toolbarMessages } from '@atlaskit/editor-common/messages';
|
|
@@ -7,39 +6,7 @@ import { BOLD_MENU_ITEM, CODE_MENU_ITEM, ITALIC_MENU_ITEM, STRIKE_MENU_ITEM, SUB
|
|
|
7
6
|
// oxlint-disable-next-line import/no-duplicates
|
|
8
7
|
|
|
9
8
|
import { BoldIcon, ItalicIcon, UnderlineIcon, CodeIcon, StrikeThroughIcon, SubscriptIcon, SuperscriptIcon } from '@atlaskit/editor-toolbar';
|
|
10
|
-
import { fg } from '@atlaskit/platform-feature-flags/fg';
|
|
11
|
-
import { expValEqualsNoExposure } from '@atlaskit/tmp-editor-statsig/exp-val-equals-no-exposure';
|
|
12
9
|
import { toggleStrongWithAnalytics, toggleEmWithAnalytics, toggleUnderlineWithAnalytics, toggleCodeWithAnalytics, toggleStrikeWithAnalytics, toggleSubscriptWithAnalytics, toggleSuperscriptWithAnalytics } from '../../../editor-commands/toggle-mark';
|
|
13
|
-
|
|
14
|
-
/**
|
|
15
|
-
* Local copy of `@atlassian/editor-plugin-markdown-mode/source-view-utils`'s
|
|
16
|
-
* `SourceViewInlineFormat` union. Kept here so this `@atlaskit/`-published
|
|
17
|
-
* package doesn't depend on the `@atlassian/`-namespaced source-view-utils
|
|
18
|
-
* subpath for type resolution. Must stay in sync with the source-of-truth
|
|
19
|
-
* declaration in markdown-mode.
|
|
20
|
-
*/
|
|
21
|
-
|
|
22
|
-
/**
|
|
23
|
-
* Maps the text-formatting plugin's `FormatOptions` keys to their
|
|
24
|
-
* `SourceViewInlineFormat` equivalents for the CM6 source view.
|
|
25
|
-
* Only formats that have a markdown syntax equivalent are included —
|
|
26
|
-
* underline, subscript, and superscript have no GFM equivalent and
|
|
27
|
-
* are left as undefined (they remain PM-only).
|
|
28
|
-
*/
|
|
29
|
-
const FORMAT_OPTION_TO_SOURCE_VIEW = {
|
|
30
|
-
strong: 'bold',
|
|
31
|
-
em: 'italic',
|
|
32
|
-
code: 'inlineCode',
|
|
33
|
-
strike: 'strikethrough'
|
|
34
|
-
};
|
|
35
|
-
const SOURCE_VIEW_ANALYTICS_ACTION_SUBJECT_ID = {
|
|
36
|
-
bold: ACTION_SUBJECT_ID.FORMAT_STRONG,
|
|
37
|
-
italic: ACTION_SUBJECT_ID.FORMAT_ITALIC,
|
|
38
|
-
inlineCode: ACTION_SUBJECT_ID.FORMAT_CODE,
|
|
39
|
-
strikethrough: ACTION_SUBJECT_ID.FORMAT_STRIKE
|
|
40
|
-
};
|
|
41
|
-
const TEXT_FORMATTING_PLUGIN_STATE_KEYS = ['textFormatting'];
|
|
42
|
-
const TEXT_FORMATTING_MARKDOWN_PLUGIN_STATE_KEYS = ['textFormatting', 'markdownMode'];
|
|
43
10
|
const FormatMarkSchema = {
|
|
44
11
|
strong: 'strong',
|
|
45
12
|
em: 'em',
|
|
@@ -58,24 +25,18 @@ export const useComponentInfo = ({
|
|
|
58
25
|
parents
|
|
59
26
|
}) => {
|
|
60
27
|
var _api$core, _api$core$sharedState, _api$core$sharedState2;
|
|
61
|
-
const isMarkdownBridgeEnabled = expValEqualsNoExposure('cc-markdown-mode', 'isEnabled', true) && fg('platform_editor_markdown_compatible_toolbar');
|
|
62
|
-
const pluginStateKeys = isMarkdownBridgeEnabled ? TEXT_FORMATTING_MARKDOWN_PLUGIN_STATE_KEYS : TEXT_FORMATTING_PLUGIN_STATE_KEYS;
|
|
63
28
|
const {
|
|
64
29
|
isActive,
|
|
65
30
|
isDisabled,
|
|
66
31
|
isHidden,
|
|
67
|
-
isPluginInitialised
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
} = useSharedPluginStateWithSelector(api, pluginStateKeys, states => {
|
|
71
|
-
var _states$textFormattin, _states$textFormattin2, _states$textFormattin3, _states$textFormattin4, _states$markdownModeS, _states$markdownModeS2;
|
|
32
|
+
isPluginInitialised
|
|
33
|
+
} = useSharedPluginStateWithSelector(api, ['textFormatting'], states => {
|
|
34
|
+
var _states$textFormattin, _states$textFormattin2, _states$textFormattin3, _states$textFormattin4;
|
|
72
35
|
return {
|
|
73
36
|
isActive: (_states$textFormattin = states.textFormattingState) === null || _states$textFormattin === void 0 ? void 0 : _states$textFormattin[`${optionType}Active`],
|
|
74
37
|
isDisabled: (_states$textFormattin2 = states.textFormattingState) === null || _states$textFormattin2 === void 0 ? void 0 : _states$textFormattin2[`${optionType}Disabled`],
|
|
75
38
|
isHidden: (_states$textFormattin3 = states.textFormattingState) === null || _states$textFormattin3 === void 0 ? void 0 : _states$textFormattin3[`${optionType}Hidden`],
|
|
76
|
-
isPluginInitialised: (_states$textFormattin4 = states.textFormattingState) === null || _states$textFormattin4 === void 0 ? void 0 : _states$textFormattin4.isInitialised
|
|
77
|
-
markdownModeView: isMarkdownBridgeEnabled ? (_states$markdownModeS = states.markdownModeState) === null || _states$markdownModeS === void 0 ? void 0 : _states$markdownModeS.view : undefined,
|
|
78
|
-
sourceFormatState: isMarkdownBridgeEnabled ? (_states$markdownModeS2 = states.markdownModeState) === null || _states$markdownModeS2 === void 0 ? void 0 : _states$markdownModeS2.sourceInlineFormatState : null
|
|
39
|
+
isPluginInitialised: (_states$textFormattin4 = states.textFormattingState) === null || _states$textFormattin4 === void 0 ? void 0 : _states$textFormattin4.isInitialised
|
|
79
40
|
};
|
|
80
41
|
});
|
|
81
42
|
const hasMarkSchema = api === null || api === void 0 ? void 0 : (_api$core = api.core) === null || _api$core === void 0 ? void 0 : (_api$core$sharedState = _api$core.sharedState.currentState()) === null || _api$core$sharedState === void 0 ? void 0 : (_api$core$sharedState2 = _api$core$sharedState.schema) === null || _api$core$sharedState2 === void 0 ? void 0 : _api$core$sharedState2.marks[FormatMarkSchema[optionType]];
|
|
@@ -99,89 +60,9 @@ export const useComponentInfo = ({
|
|
|
99
60
|
const formatTitle = formatMessage(title);
|
|
100
61
|
const shortcutContent = tooltip(shortcut);
|
|
101
62
|
const ariaLabel = tooltip(shortcut, formatTitle);
|
|
102
|
-
|
|
103
|
-
// The SourceViewInlineFormat key for this format option, if it has one.
|
|
104
|
-
// undefined for underline, subscript, superscript (no GFM equivalent).
|
|
105
|
-
const sourceViewFormat = FORMAT_OPTION_TO_SOURCE_VIEW[optionType];
|
|
106
|
-
|
|
107
|
-
// The CM6 source view is authoritative when the user has switched to it.
|
|
108
|
-
// We rely on `markdownModeState.view === 'syntax'` (synchronous, set on
|
|
109
|
-
// `setView`) rather than the presence of `sourceFormatState` — the latter
|
|
110
|
-
// is `null` until the CM6 update listener fires for the first time, so
|
|
111
|
-
// using it as the sentinel would let the first toolbar click after entering
|
|
112
|
-
// source view fall through to the PM path and mutate the hidden PM doc.
|
|
113
|
-
const isInSourceView = markdownModeView === 'syntax';
|
|
114
|
-
if (isInSourceView && !sourceViewFormat) {
|
|
115
|
-
// Underline, subscript, superscript have no GFM equivalent. Disable
|
|
116
|
-
// them immediately on entering source view — independent of whether
|
|
117
|
-
// the CM6 update listener has fired yet — so the buttons don't briefly
|
|
118
|
-
// appear active/enabled during that race window.
|
|
119
|
-
formatOptionState = {
|
|
120
|
-
isActive: false,
|
|
121
|
-
isDisabled: true,
|
|
122
|
-
isHidden: false
|
|
123
|
-
};
|
|
124
|
-
} else if (isInSourceView && sourceFormatState && sourceViewFormat) {
|
|
125
|
-
// Map each SourceViewInlineFormat to its isActive field on the snapshot.
|
|
126
|
-
const activeByFormat = {
|
|
127
|
-
bold: sourceFormatState.boldActive,
|
|
128
|
-
italic: sourceFormatState.italicActive,
|
|
129
|
-
inlineCode: sourceFormatState.codeActive,
|
|
130
|
-
strikethrough: sourceFormatState.strikeActive
|
|
131
|
-
};
|
|
132
|
-
formatOptionState = {
|
|
133
|
-
isActive: activeByFormat[sourceViewFormat],
|
|
134
|
-
isDisabled: !sourceFormatState.inlineFormattingAvailable,
|
|
135
|
-
isHidden: false
|
|
136
|
-
};
|
|
137
|
-
} else if (isInSourceView) {
|
|
138
|
-
// Race window: the user has switched to source view but the CM6 update
|
|
139
|
-
// listener hasn't pushed its first format state snapshot yet
|
|
140
|
-
// (`sourceFormatState` is still `null`). Without this branch the
|
|
141
|
-
// button would render stale PM-cursor state (e.g. "Bold active" based
|
|
142
|
-
// on where the PM selection was) until CM6 catches up. Render a
|
|
143
|
-
// neutral, non-disabled state instead.
|
|
144
|
-
formatOptionState = {
|
|
145
|
-
isActive: false,
|
|
146
|
-
isDisabled: false,
|
|
147
|
-
isHidden: false
|
|
148
|
-
};
|
|
149
|
-
}
|
|
150
63
|
const onClick = () => {
|
|
151
|
-
var _api$
|
|
152
|
-
|
|
153
|
-
if (isInSourceView) {
|
|
154
|
-
if (sourceViewFormat) {
|
|
155
|
-
var _api$analytics;
|
|
156
|
-
api === null || api === void 0 ? void 0 : (_api$analytics = api.analytics) === null || _api$analytics === void 0 ? void 0 : _api$analytics.actions.fireAnalyticsEvent({
|
|
157
|
-
action: ACTION.FORMATTED,
|
|
158
|
-
actionSubject: ACTION_SUBJECT.TEXT,
|
|
159
|
-
eventType: EVENT_TYPE.TRACK,
|
|
160
|
-
actionSubjectId: SOURCE_VIEW_ANALYTICS_ACTION_SUBJECT_ID[sourceViewFormat],
|
|
161
|
-
attributes: {
|
|
162
|
-
inputMethod: getInputMethodFromParentKeys(parents)
|
|
163
|
-
}
|
|
164
|
-
});
|
|
165
|
-
switch (sourceViewFormat) {
|
|
166
|
-
case 'bold':
|
|
167
|
-
api === null || api === void 0 ? void 0 : (_api$markdownMode = api.markdownMode) === null || _api$markdownMode === void 0 ? void 0 : _api$markdownMode.actions.toggleSourceBold();
|
|
168
|
-
break;
|
|
169
|
-
case 'italic':
|
|
170
|
-
api === null || api === void 0 ? void 0 : (_api$markdownMode2 = api.markdownMode) === null || _api$markdownMode2 === void 0 ? void 0 : _api$markdownMode2.actions.toggleSourceItalic();
|
|
171
|
-
break;
|
|
172
|
-
case 'inlineCode':
|
|
173
|
-
api === null || api === void 0 ? void 0 : (_api$markdownMode3 = api.markdownMode) === null || _api$markdownMode3 === void 0 ? void 0 : _api$markdownMode3.actions.toggleSourceInlineCode();
|
|
174
|
-
break;
|
|
175
|
-
case 'strikethrough':
|
|
176
|
-
api === null || api === void 0 ? void 0 : (_api$markdownMode4 = api.markdownMode) === null || _api$markdownMode4 === void 0 ? void 0 : _api$markdownMode4.actions.toggleSourceStrike();
|
|
177
|
-
break;
|
|
178
|
-
}
|
|
179
|
-
}
|
|
180
|
-
return;
|
|
181
|
-
}
|
|
182
|
-
|
|
183
|
-
// Default PM path.
|
|
184
|
-
api === null || api === void 0 ? void 0 : api.core.actions.execute(toggleMarkWithAnalyticsCallback(api === null || api === void 0 ? void 0 : (_api$analytics2 = api.analytics) === null || _api$analytics2 === void 0 ? void 0 : _api$analytics2.actions)(getInputMethodFromParentKeys(parents)));
|
|
64
|
+
var _api$analytics;
|
|
65
|
+
api === null || api === void 0 ? void 0 : api.core.actions.execute(toggleMarkWithAnalyticsCallback(api === null || api === void 0 ? void 0 : (_api$analytics = api.analytics) === null || _api$analytics === void 0 ? void 0 : _api$analytics.actions)(getInputMethodFromParentKeys(parents)));
|
|
185
66
|
};
|
|
186
67
|
return {
|
|
187
68
|
...formatOptionState,
|
|
@@ -2,7 +2,6 @@ import _defineProperty from "@babel/runtime/helpers/defineProperty";
|
|
|
2
2
|
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
|
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 { useIntl } from 'react-intl';
|
|
5
|
-
import { ACTION, ACTION_SUBJECT, ACTION_SUBJECT_ID, EVENT_TYPE } from '@atlaskit/editor-common/analytics';
|
|
6
5
|
import { useSharedPluginStateWithSelector } from '@atlaskit/editor-common/hooks';
|
|
7
6
|
import { toggleBold, toggleCode, toggleItalic, toggleStrikethrough, toggleSubscript, toggleSuperscript, toggleUnderline, tooltip } from '@atlaskit/editor-common/keymaps';
|
|
8
7
|
import { toolbarMessages } from '@atlaskit/editor-common/messages';
|
|
@@ -10,39 +9,7 @@ import { BOLD_MENU_ITEM, CODE_MENU_ITEM, ITALIC_MENU_ITEM, STRIKE_MENU_ITEM, SUB
|
|
|
10
9
|
// oxlint-disable-next-line import/no-duplicates
|
|
11
10
|
|
|
12
11
|
import { BoldIcon, ItalicIcon, UnderlineIcon, CodeIcon, StrikeThroughIcon, SubscriptIcon, SuperscriptIcon } from '@atlaskit/editor-toolbar';
|
|
13
|
-
import { fg } from '@atlaskit/platform-feature-flags/fg';
|
|
14
|
-
import { expValEqualsNoExposure } from '@atlaskit/tmp-editor-statsig/exp-val-equals-no-exposure';
|
|
15
12
|
import { toggleStrongWithAnalytics, toggleEmWithAnalytics, toggleUnderlineWithAnalytics, toggleCodeWithAnalytics, toggleStrikeWithAnalytics, toggleSubscriptWithAnalytics, toggleSuperscriptWithAnalytics } from '../../../editor-commands/toggle-mark';
|
|
16
|
-
|
|
17
|
-
/**
|
|
18
|
-
* Local copy of `@atlassian/editor-plugin-markdown-mode/source-view-utils`'s
|
|
19
|
-
* `SourceViewInlineFormat` union. Kept here so this `@atlaskit/`-published
|
|
20
|
-
* package doesn't depend on the `@atlassian/`-namespaced source-view-utils
|
|
21
|
-
* subpath for type resolution. Must stay in sync with the source-of-truth
|
|
22
|
-
* declaration in markdown-mode.
|
|
23
|
-
*/
|
|
24
|
-
|
|
25
|
-
/**
|
|
26
|
-
* Maps the text-formatting plugin's `FormatOptions` keys to their
|
|
27
|
-
* `SourceViewInlineFormat` equivalents for the CM6 source view.
|
|
28
|
-
* Only formats that have a markdown syntax equivalent are included —
|
|
29
|
-
* underline, subscript, and superscript have no GFM equivalent and
|
|
30
|
-
* are left as undefined (they remain PM-only).
|
|
31
|
-
*/
|
|
32
|
-
var FORMAT_OPTION_TO_SOURCE_VIEW = {
|
|
33
|
-
strong: 'bold',
|
|
34
|
-
em: 'italic',
|
|
35
|
-
code: 'inlineCode',
|
|
36
|
-
strike: 'strikethrough'
|
|
37
|
-
};
|
|
38
|
-
var SOURCE_VIEW_ANALYTICS_ACTION_SUBJECT_ID = {
|
|
39
|
-
bold: ACTION_SUBJECT_ID.FORMAT_STRONG,
|
|
40
|
-
italic: ACTION_SUBJECT_ID.FORMAT_ITALIC,
|
|
41
|
-
inlineCode: ACTION_SUBJECT_ID.FORMAT_CODE,
|
|
42
|
-
strikethrough: ACTION_SUBJECT_ID.FORMAT_STRIKE
|
|
43
|
-
};
|
|
44
|
-
var TEXT_FORMATTING_PLUGIN_STATE_KEYS = ['textFormatting'];
|
|
45
|
-
var TEXT_FORMATTING_MARKDOWN_PLUGIN_STATE_KEYS = ['textFormatting', 'markdownMode'];
|
|
46
13
|
var FormatMarkSchema = {
|
|
47
14
|
strong: 'strong',
|
|
48
15
|
em: 'em',
|
|
@@ -60,25 +27,19 @@ export var useComponentInfo = function useComponentInfo(_ref) {
|
|
|
60
27
|
shortcut = _ref.shortcut,
|
|
61
28
|
toggleMarkWithAnalyticsCallback = _ref.toggleMarkWithAnalyticsCallback,
|
|
62
29
|
parents = _ref.parents;
|
|
63
|
-
var
|
|
64
|
-
|
|
65
|
-
var _useSharedPluginState = useSharedPluginStateWithSelector(api, pluginStateKeys, function (states) {
|
|
66
|
-
var _states$textFormattin, _states$textFormattin2, _states$textFormattin3, _states$textFormattin4, _states$markdownModeS, _states$markdownModeS2;
|
|
30
|
+
var _useSharedPluginState = useSharedPluginStateWithSelector(api, ['textFormatting'], function (states) {
|
|
31
|
+
var _states$textFormattin, _states$textFormattin2, _states$textFormattin3, _states$textFormattin4;
|
|
67
32
|
return {
|
|
68
33
|
isActive: (_states$textFormattin = states.textFormattingState) === null || _states$textFormattin === void 0 ? void 0 : _states$textFormattin["".concat(optionType, "Active")],
|
|
69
34
|
isDisabled: (_states$textFormattin2 = states.textFormattingState) === null || _states$textFormattin2 === void 0 ? void 0 : _states$textFormattin2["".concat(optionType, "Disabled")],
|
|
70
35
|
isHidden: (_states$textFormattin3 = states.textFormattingState) === null || _states$textFormattin3 === void 0 ? void 0 : _states$textFormattin3["".concat(optionType, "Hidden")],
|
|
71
|
-
isPluginInitialised: (_states$textFormattin4 = states.textFormattingState) === null || _states$textFormattin4 === void 0 ? void 0 : _states$textFormattin4.isInitialised
|
|
72
|
-
markdownModeView: isMarkdownBridgeEnabled ? (_states$markdownModeS = states.markdownModeState) === null || _states$markdownModeS === void 0 ? void 0 : _states$markdownModeS.view : undefined,
|
|
73
|
-
sourceFormatState: isMarkdownBridgeEnabled ? (_states$markdownModeS2 = states.markdownModeState) === null || _states$markdownModeS2 === void 0 ? void 0 : _states$markdownModeS2.sourceInlineFormatState : null
|
|
36
|
+
isPluginInitialised: (_states$textFormattin4 = states.textFormattingState) === null || _states$textFormattin4 === void 0 ? void 0 : _states$textFormattin4.isInitialised
|
|
74
37
|
};
|
|
75
38
|
}),
|
|
76
39
|
isActive = _useSharedPluginState.isActive,
|
|
77
40
|
isDisabled = _useSharedPluginState.isDisabled,
|
|
78
41
|
isHidden = _useSharedPluginState.isHidden,
|
|
79
|
-
isPluginInitialised = _useSharedPluginState.isPluginInitialised
|
|
80
|
-
markdownModeView = _useSharedPluginState.markdownModeView,
|
|
81
|
-
sourceFormatState = _useSharedPluginState.sourceFormatState;
|
|
42
|
+
isPluginInitialised = _useSharedPluginState.isPluginInitialised;
|
|
82
43
|
var hasMarkSchema = api === null || api === void 0 || (_api$core = api.core) === null || _api$core === void 0 || (_api$core = _api$core.sharedState.currentState()) === null || _api$core === void 0 || (_api$core = _api$core.schema) === null || _api$core === void 0 ? void 0 : _api$core.marks[FormatMarkSchema[optionType]];
|
|
83
44
|
var formatOptionState;
|
|
84
45
|
if (!isPluginInitialised) {
|
|
@@ -99,89 +60,9 @@ export var useComponentInfo = function useComponentInfo(_ref) {
|
|
|
99
60
|
var formatTitle = formatMessage(title);
|
|
100
61
|
var shortcutContent = tooltip(shortcut);
|
|
101
62
|
var ariaLabel = tooltip(shortcut, formatTitle);
|
|
102
|
-
|
|
103
|
-
// The SourceViewInlineFormat key for this format option, if it has one.
|
|
104
|
-
// undefined for underline, subscript, superscript (no GFM equivalent).
|
|
105
|
-
var sourceViewFormat = FORMAT_OPTION_TO_SOURCE_VIEW[optionType];
|
|
106
|
-
|
|
107
|
-
// The CM6 source view is authoritative when the user has switched to it.
|
|
108
|
-
// We rely on `markdownModeState.view === 'syntax'` (synchronous, set on
|
|
109
|
-
// `setView`) rather than the presence of `sourceFormatState` — the latter
|
|
110
|
-
// is `null` until the CM6 update listener fires for the first time, so
|
|
111
|
-
// using it as the sentinel would let the first toolbar click after entering
|
|
112
|
-
// source view fall through to the PM path and mutate the hidden PM doc.
|
|
113
|
-
var isInSourceView = markdownModeView === 'syntax';
|
|
114
|
-
if (isInSourceView && !sourceViewFormat) {
|
|
115
|
-
// Underline, subscript, superscript have no GFM equivalent. Disable
|
|
116
|
-
// them immediately on entering source view — independent of whether
|
|
117
|
-
// the CM6 update listener has fired yet — so the buttons don't briefly
|
|
118
|
-
// appear active/enabled during that race window.
|
|
119
|
-
formatOptionState = {
|
|
120
|
-
isActive: false,
|
|
121
|
-
isDisabled: true,
|
|
122
|
-
isHidden: false
|
|
123
|
-
};
|
|
124
|
-
} else if (isInSourceView && sourceFormatState && sourceViewFormat) {
|
|
125
|
-
// Map each SourceViewInlineFormat to its isActive field on the snapshot.
|
|
126
|
-
var activeByFormat = {
|
|
127
|
-
bold: sourceFormatState.boldActive,
|
|
128
|
-
italic: sourceFormatState.italicActive,
|
|
129
|
-
inlineCode: sourceFormatState.codeActive,
|
|
130
|
-
strikethrough: sourceFormatState.strikeActive
|
|
131
|
-
};
|
|
132
|
-
formatOptionState = {
|
|
133
|
-
isActive: activeByFormat[sourceViewFormat],
|
|
134
|
-
isDisabled: !sourceFormatState.inlineFormattingAvailable,
|
|
135
|
-
isHidden: false
|
|
136
|
-
};
|
|
137
|
-
} else if (isInSourceView) {
|
|
138
|
-
// Race window: the user has switched to source view but the CM6 update
|
|
139
|
-
// listener hasn't pushed its first format state snapshot yet
|
|
140
|
-
// (`sourceFormatState` is still `null`). Without this branch the
|
|
141
|
-
// button would render stale PM-cursor state (e.g. "Bold active" based
|
|
142
|
-
// on where the PM selection was) until CM6 catches up. Render a
|
|
143
|
-
// neutral, non-disabled state instead.
|
|
144
|
-
formatOptionState = {
|
|
145
|
-
isActive: false,
|
|
146
|
-
isDisabled: false,
|
|
147
|
-
isHidden: false
|
|
148
|
-
};
|
|
149
|
-
}
|
|
150
63
|
var onClick = function onClick() {
|
|
151
|
-
var _api$
|
|
152
|
-
|
|
153
|
-
if (isInSourceView) {
|
|
154
|
-
if (sourceViewFormat) {
|
|
155
|
-
var _api$analytics;
|
|
156
|
-
api === null || api === void 0 || (_api$analytics = api.analytics) === null || _api$analytics === void 0 || _api$analytics.actions.fireAnalyticsEvent({
|
|
157
|
-
action: ACTION.FORMATTED,
|
|
158
|
-
actionSubject: ACTION_SUBJECT.TEXT,
|
|
159
|
-
eventType: EVENT_TYPE.TRACK,
|
|
160
|
-
actionSubjectId: SOURCE_VIEW_ANALYTICS_ACTION_SUBJECT_ID[sourceViewFormat],
|
|
161
|
-
attributes: {
|
|
162
|
-
inputMethod: getInputMethodFromParentKeys(parents)
|
|
163
|
-
}
|
|
164
|
-
});
|
|
165
|
-
switch (sourceViewFormat) {
|
|
166
|
-
case 'bold':
|
|
167
|
-
api === null || api === void 0 || (_api$markdownMode = api.markdownMode) === null || _api$markdownMode === void 0 || _api$markdownMode.actions.toggleSourceBold();
|
|
168
|
-
break;
|
|
169
|
-
case 'italic':
|
|
170
|
-
api === null || api === void 0 || (_api$markdownMode2 = api.markdownMode) === null || _api$markdownMode2 === void 0 || _api$markdownMode2.actions.toggleSourceItalic();
|
|
171
|
-
break;
|
|
172
|
-
case 'inlineCode':
|
|
173
|
-
api === null || api === void 0 || (_api$markdownMode3 = api.markdownMode) === null || _api$markdownMode3 === void 0 || _api$markdownMode3.actions.toggleSourceInlineCode();
|
|
174
|
-
break;
|
|
175
|
-
case 'strikethrough':
|
|
176
|
-
api === null || api === void 0 || (_api$markdownMode4 = api.markdownMode) === null || _api$markdownMode4 === void 0 || _api$markdownMode4.actions.toggleSourceStrike();
|
|
177
|
-
break;
|
|
178
|
-
}
|
|
179
|
-
}
|
|
180
|
-
return;
|
|
181
|
-
}
|
|
182
|
-
|
|
183
|
-
// Default PM path.
|
|
184
|
-
api === null || api === void 0 || api.core.actions.execute(toggleMarkWithAnalyticsCallback(api === null || api === void 0 || (_api$analytics2 = api.analytics) === null || _api$analytics2 === void 0 ? void 0 : _api$analytics2.actions)(getInputMethodFromParentKeys(parents)));
|
|
64
|
+
var _api$analytics;
|
|
65
|
+
api === null || api === void 0 || api.core.actions.execute(toggleMarkWithAnalyticsCallback(api === null || api === void 0 || (_api$analytics = api.analytics) === null || _api$analytics === void 0 ? void 0 : _api$analytics.actions)(getInputMethodFromParentKeys(parents)));
|
|
185
66
|
};
|
|
186
67
|
return _objectSpread(_objectSpread({}, formatOptionState), {}, {
|
|
187
68
|
formatTitle: formatTitle,
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { NextEditorPlugin, OptionalPlugin, TextFormattingOptions as CommonTextFormattingOptions, TextFormattingState
|
|
1
|
+
import type { NextEditorPlugin, OptionalPlugin, TextFormattingOptions as CommonTextFormattingOptions, TextFormattingState } from '@atlaskit/editor-common/types';
|
|
2
2
|
import type { AnalyticsPlugin } from '@atlaskit/editor-plugin-analytics';
|
|
3
3
|
import type { BasePlugin } from '@atlaskit/editor-plugin-base';
|
|
4
4
|
import type { PrimaryToolbarPlugin } from '@atlaskit/editor-plugin-primary-toolbar';
|
|
@@ -23,8 +23,7 @@ export type TextFormattingPlugin = NextEditorPlugin<'textFormatting', {
|
|
|
23
23
|
OptionalPlugin<BasePlugin>,
|
|
24
24
|
OptionalPlugin<SelectionToolbarPlugin>,
|
|
25
25
|
OptionalPlugin<UserPreferencesPlugin>,
|
|
26
|
-
OptionalPlugin<ToolbarPlugin
|
|
27
|
-
OptionalPlugin<_MarkdownModePluginStub>
|
|
26
|
+
OptionalPlugin<ToolbarPlugin>
|
|
28
27
|
];
|
|
29
28
|
pluginConfiguration: TextFormattingPluginOptions | undefined;
|
|
30
29
|
sharedState: TextFormattingState | undefined;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@atlaskit/editor-plugin-text-formatting",
|
|
3
|
-
"version": "22.0.
|
|
3
|
+
"version": "22.0.4",
|
|
4
4
|
"description": "Text-formatting plugin for @atlaskit/editor-core",
|
|
5
5
|
"author": "Atlassian Pty Ltd",
|
|
6
6
|
"license": "Apache-2.0",
|
|
@@ -38,13 +38,13 @@
|
|
|
38
38
|
"@atlaskit/icon": "^38.0.0",
|
|
39
39
|
"@atlaskit/platform-feature-flags": "^2.2.0",
|
|
40
40
|
"@atlaskit/prosemirror-input-rules": "^4.1.0",
|
|
41
|
-
"@atlaskit/tmp-editor-statsig": "^
|
|
41
|
+
"@atlaskit/tmp-editor-statsig": "^213.0.0",
|
|
42
42
|
"@atlaskit/tokens": "^20.1.0",
|
|
43
43
|
"@babel/runtime": "^7.0.0",
|
|
44
44
|
"@emotion/react": "^11.7.1"
|
|
45
45
|
},
|
|
46
46
|
"peerDependencies": {
|
|
47
|
-
"@atlaskit/editor-common": "^126.
|
|
47
|
+
"@atlaskit/editor-common": "^126.2.0",
|
|
48
48
|
"react": "^18.2.0 || ^19.2.0",
|
|
49
49
|
"react-intl": "^5.25.1 || ^6.0.0 || ^7.0.0"
|
|
50
50
|
},
|
|
@@ -59,9 +59,6 @@
|
|
|
59
59
|
},
|
|
60
60
|
"editor_inline_comments_on_inline_nodes": {
|
|
61
61
|
"type": "boolean"
|
|
62
|
-
},
|
|
63
|
-
"platform_editor_markdown_compatible_toolbar": {
|
|
64
|
-
"type": "boolean"
|
|
65
62
|
}
|
|
66
63
|
}
|
|
67
64
|
}
|