@atlaskit/editor-plugin-text-formatting 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.eslintrc.js +7 -0
- package/CHANGELOG.md +1 -0
- package/LICENSE.md +13 -0
- package/README.md +9 -0
- package/dist/cjs/actions.js +188 -0
- package/dist/cjs/commands/clear-formatting.js +111 -0
- package/dist/cjs/commands/text-formatting.js +143 -0
- package/dist/cjs/commands/transform-to-code.js +68 -0
- package/dist/cjs/index.js +12 -0
- package/dist/cjs/plugin.js +133 -0
- package/dist/cjs/pm-plugins/clear-formatting-keymap.js +21 -0
- package/dist/cjs/pm-plugins/clear-formatting.js +36 -0
- package/dist/cjs/pm-plugins/cursor.js +55 -0
- package/dist/cjs/pm-plugins/input-rule.js +274 -0
- package/dist/cjs/pm-plugins/keymap.js +52 -0
- package/dist/cjs/pm-plugins/main.js +113 -0
- package/dist/cjs/pm-plugins/plugin-key.js +9 -0
- package/dist/cjs/pm-plugins/smart-input-rule.js +176 -0
- package/dist/cjs/ui/Toolbar/constants.js +19 -0
- package/dist/cjs/ui/Toolbar/dropdown-menu.js +86 -0
- package/dist/cjs/ui/Toolbar/hooks/clear-formatting-icon.js +55 -0
- package/dist/cjs/ui/Toolbar/hooks/formatting-icons.js +227 -0
- package/dist/cjs/ui/Toolbar/hooks/menu-state.js +23 -0
- package/dist/cjs/ui/Toolbar/hooks/responsive-toolbar-buttons.js +60 -0
- package/dist/cjs/ui/Toolbar/index.js +183 -0
- package/dist/cjs/ui/Toolbar/more-button.js +42 -0
- package/dist/cjs/ui/Toolbar/single-toolbar-buttons.js +49 -0
- package/dist/cjs/ui/Toolbar/types.js +17 -0
- package/dist/cjs/utils/cell-selection.js +12 -0
- package/dist/cjs/utils.js +86 -0
- package/dist/cjs/version.json +5 -0
- package/dist/es2019/actions.js +161 -0
- package/dist/es2019/commands/clear-formatting.js +105 -0
- package/dist/es2019/commands/text-formatting.js +144 -0
- package/dist/es2019/commands/transform-to-code.js +71 -0
- package/dist/es2019/index.js +1 -0
- package/dist/es2019/plugin.js +124 -0
- package/dist/es2019/pm-plugins/clear-formatting-keymap.js +10 -0
- package/dist/es2019/pm-plugins/clear-formatting.js +26 -0
- package/dist/es2019/pm-plugins/cursor.js +52 -0
- package/dist/es2019/pm-plugins/input-rule.js +242 -0
- package/dist/es2019/pm-plugins/keymap.js +43 -0
- package/dist/es2019/pm-plugins/main.js +110 -0
- package/dist/es2019/pm-plugins/plugin-key.js +2 -0
- package/dist/es2019/pm-plugins/smart-input-rule.js +155 -0
- package/dist/es2019/ui/Toolbar/constants.js +20 -0
- package/dist/es2019/ui/Toolbar/dropdown-menu.js +66 -0
- package/dist/es2019/ui/Toolbar/hooks/clear-formatting-icon.js +44 -0
- package/dist/es2019/ui/Toolbar/hooks/formatting-icons.js +212 -0
- package/dist/es2019/ui/Toolbar/hooks/menu-state.js +11 -0
- package/dist/es2019/ui/Toolbar/hooks/responsive-toolbar-buttons.js +48 -0
- package/dist/es2019/ui/Toolbar/index.js +168 -0
- package/dist/es2019/ui/Toolbar/more-button.js +34 -0
- package/dist/es2019/ui/Toolbar/single-toolbar-buttons.js +39 -0
- package/dist/es2019/ui/Toolbar/types.js +10 -0
- package/dist/es2019/utils/cell-selection.js +5 -0
- package/dist/es2019/utils.js +74 -0
- package/dist/es2019/version.json +5 -0
- package/dist/esm/actions.js +168 -0
- package/dist/esm/commands/clear-formatting.js +101 -0
- package/dist/esm/commands/text-formatting.js +134 -0
- package/dist/esm/commands/transform-to-code.js +61 -0
- package/dist/esm/index.js +1 -0
- package/dist/esm/plugin.js +125 -0
- package/dist/esm/pm-plugins/clear-formatting-keymap.js +10 -0
- package/dist/esm/pm-plugins/clear-formatting.js +28 -0
- package/dist/esm/pm-plugins/cursor.js +48 -0
- package/dist/esm/pm-plugins/input-rule.js +257 -0
- package/dist/esm/pm-plugins/keymap.js +43 -0
- package/dist/esm/pm-plugins/main.js +99 -0
- package/dist/esm/pm-plugins/plugin-key.js +2 -0
- package/dist/esm/pm-plugins/smart-input-rule.js +169 -0
- package/dist/esm/ui/Toolbar/constants.js +8 -0
- package/dist/esm/ui/Toolbar/dropdown-menu.js +75 -0
- package/dist/esm/ui/Toolbar/hooks/clear-formatting-icon.js +47 -0
- package/dist/esm/ui/Toolbar/hooks/formatting-icons.js +215 -0
- package/dist/esm/ui/Toolbar/hooks/menu-state.js +15 -0
- package/dist/esm/ui/Toolbar/hooks/responsive-toolbar-buttons.js +50 -0
- package/dist/esm/ui/Toolbar/index.js +174 -0
- package/dist/esm/ui/Toolbar/more-button.js +33 -0
- package/dist/esm/ui/Toolbar/single-toolbar-buttons.js +38 -0
- package/dist/esm/ui/Toolbar/types.js +10 -0
- package/dist/esm/utils/cell-selection.js +5 -0
- package/dist/esm/utils.js +75 -0
- package/dist/esm/version.json +5 -0
- package/dist/types/actions.d.ts +22 -0
- package/dist/types/commands/clear-formatting.d.ts +6 -0
- package/dist/types/commands/text-formatting.d.ts +5 -0
- package/dist/types/commands/transform-to-code.d.ts +2 -0
- package/dist/types/index.d.ts +3 -0
- package/dist/types/plugin.d.ts +17 -0
- package/dist/types/pm-plugins/clear-formatting-keymap.d.ts +4 -0
- package/dist/types/pm-plugins/clear-formatting.d.ts +8 -0
- package/dist/types/pm-plugins/cursor.d.ts +3 -0
- package/dist/types/pm-plugins/input-rule.d.ts +23 -0
- package/dist/types/pm-plugins/keymap.d.ts +4 -0
- package/dist/types/pm-plugins/main.d.ts +7 -0
- package/dist/types/pm-plugins/plugin-key.d.ts +3 -0
- package/dist/types/pm-plugins/smart-input-rule.d.ts +3 -0
- package/dist/types/ui/Toolbar/constants.d.ts +6 -0
- package/dist/types/ui/Toolbar/dropdown-menu.d.ts +15 -0
- package/dist/types/ui/Toolbar/hooks/clear-formatting-icon.d.ts +7 -0
- package/dist/types/ui/Toolbar/hooks/formatting-icons.d.ts +14 -0
- package/dist/types/ui/Toolbar/hooks/menu-state.d.ts +1 -0
- package/dist/types/ui/Toolbar/hooks/responsive-toolbar-buttons.d.ts +20 -0
- package/dist/types/ui/Toolbar/index.d.ts +25 -0
- package/dist/types/ui/Toolbar/more-button.d.ts +14 -0
- package/dist/types/ui/Toolbar/single-toolbar-buttons.d.ts +10 -0
- package/dist/types/ui/Toolbar/types.d.ts +32 -0
- package/dist/types/utils/cell-selection.d.ts +3 -0
- package/dist/types/utils.d.ts +11 -0
- package/dist/types-ts4.5/actions.d.ts +22 -0
- package/dist/types-ts4.5/commands/clear-formatting.d.ts +6 -0
- package/dist/types-ts4.5/commands/text-formatting.d.ts +5 -0
- package/dist/types-ts4.5/commands/transform-to-code.d.ts +2 -0
- package/dist/types-ts4.5/index.d.ts +3 -0
- package/dist/types-ts4.5/plugin.d.ts +19 -0
- package/dist/types-ts4.5/pm-plugins/clear-formatting-keymap.d.ts +4 -0
- package/dist/types-ts4.5/pm-plugins/clear-formatting.d.ts +8 -0
- package/dist/types-ts4.5/pm-plugins/cursor.d.ts +3 -0
- package/dist/types-ts4.5/pm-plugins/input-rule.d.ts +23 -0
- package/dist/types-ts4.5/pm-plugins/keymap.d.ts +4 -0
- package/dist/types-ts4.5/pm-plugins/main.d.ts +7 -0
- package/dist/types-ts4.5/pm-plugins/plugin-key.d.ts +3 -0
- package/dist/types-ts4.5/pm-plugins/smart-input-rule.d.ts +3 -0
- package/dist/types-ts4.5/ui/Toolbar/constants.d.ts +6 -0
- package/dist/types-ts4.5/ui/Toolbar/dropdown-menu.d.ts +15 -0
- package/dist/types-ts4.5/ui/Toolbar/hooks/clear-formatting-icon.d.ts +7 -0
- package/dist/types-ts4.5/ui/Toolbar/hooks/formatting-icons.d.ts +14 -0
- package/dist/types-ts4.5/ui/Toolbar/hooks/menu-state.d.ts +5 -0
- package/dist/types-ts4.5/ui/Toolbar/hooks/responsive-toolbar-buttons.d.ts +20 -0
- package/dist/types-ts4.5/ui/Toolbar/index.d.ts +25 -0
- package/dist/types-ts4.5/ui/Toolbar/more-button.d.ts +14 -0
- package/dist/types-ts4.5/ui/Toolbar/single-toolbar-buttons.d.ts +10 -0
- package/dist/types-ts4.5/ui/Toolbar/types.d.ts +32 -0
- package/dist/types-ts4.5/utils/cell-selection.d.ts +3 -0
- package/dist/types-ts4.5/utils.d.ts +11 -0
- package/package.json +93 -0
- package/report.api.md +66 -0
- package/tmp/api-report-tmp.d.ts +39 -0
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { INPUT_METHOD } from '@atlaskit/editor-common/analytics';
|
|
2
|
+
import * as keymaps from '@atlaskit/editor-common/keymaps';
|
|
3
|
+
import { keymap } from '@atlaskit/editor-prosemirror/keymap';
|
|
4
|
+
import { toggleCodeWithAnalytics, toggleEmWithAnalytics, toggleStrikeWithAnalytics, toggleStrongWithAnalytics, toggleSubscriptWithAnalytics, toggleSuperscriptWithAnalytics, toggleUnderlineWithAnalytics } from '../actions';
|
|
5
|
+
export default function keymapPlugin(schema, editorAnalyticsAPI) {
|
|
6
|
+
var list = {};
|
|
7
|
+
if (schema.marks.strong) {
|
|
8
|
+
keymaps.bindKeymapWithCommand(keymaps.toggleBold.common, toggleStrongWithAnalytics(editorAnalyticsAPI)({
|
|
9
|
+
inputMethod: INPUT_METHOD.SHORTCUT
|
|
10
|
+
}), list);
|
|
11
|
+
}
|
|
12
|
+
if (schema.marks.em) {
|
|
13
|
+
keymaps.bindKeymapWithCommand(keymaps.toggleItalic.common, toggleEmWithAnalytics(editorAnalyticsAPI)({
|
|
14
|
+
inputMethod: INPUT_METHOD.SHORTCUT
|
|
15
|
+
}), list);
|
|
16
|
+
}
|
|
17
|
+
if (schema.marks.code) {
|
|
18
|
+
keymaps.bindKeymapWithCommand(keymaps.toggleCode.common, toggleCodeWithAnalytics(editorAnalyticsAPI)({
|
|
19
|
+
inputMethod: INPUT_METHOD.SHORTCUT
|
|
20
|
+
}), list);
|
|
21
|
+
}
|
|
22
|
+
if (schema.marks.strike) {
|
|
23
|
+
keymaps.bindKeymapWithCommand(keymaps.toggleStrikethrough.common, toggleStrikeWithAnalytics(editorAnalyticsAPI)({
|
|
24
|
+
inputMethod: INPUT_METHOD.SHORTCUT
|
|
25
|
+
}), list);
|
|
26
|
+
}
|
|
27
|
+
if (schema.marks.subsup) {
|
|
28
|
+
keymaps.bindKeymapWithCommand(keymaps.toggleSubscript.common, toggleSubscriptWithAnalytics(editorAnalyticsAPI)({
|
|
29
|
+
inputMethod: INPUT_METHOD.SHORTCUT
|
|
30
|
+
}), list);
|
|
31
|
+
}
|
|
32
|
+
if (schema.marks.subsup) {
|
|
33
|
+
keymaps.bindKeymapWithCommand(keymaps.toggleSuperscript.common, toggleSuperscriptWithAnalytics(editorAnalyticsAPI)({
|
|
34
|
+
inputMethod: INPUT_METHOD.SHORTCUT
|
|
35
|
+
}), list);
|
|
36
|
+
}
|
|
37
|
+
if (schema.marks.underline) {
|
|
38
|
+
keymaps.bindKeymapWithCommand(keymaps.toggleUnderline.common, toggleUnderlineWithAnalytics(editorAnalyticsAPI)({
|
|
39
|
+
inputMethod: INPUT_METHOD.SHORTCUT
|
|
40
|
+
}), list);
|
|
41
|
+
}
|
|
42
|
+
return keymap(list);
|
|
43
|
+
}
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
// TODO: Ideally this should use the custom toggleMark function from @atlaskit/editor-common so we also disable the options when selecting inline nodes but it disables the marks when the selection is empty at this point in time which is undesirable
|
|
2
|
+
// import { toggleMark } from '@atlaskit/editor-common/mark';
|
|
3
|
+
|
|
4
|
+
import { moveLeft as keymapMoveLeft, moveRight as keymapMoveRight } from '@atlaskit/editor-common/keymaps';
|
|
5
|
+
import { anyMarkActive } from '@atlaskit/editor-common/mark';
|
|
6
|
+
import { SafePlugin } from '@atlaskit/editor-common/safe-plugin';
|
|
7
|
+
import { shallowEqual } from '@atlaskit/editor-common/utils';
|
|
8
|
+
import { toggleMark } from '@atlaskit/editor-prosemirror/commands';
|
|
9
|
+
import { createInlineCodeFromTextInputWithAnalytics } from '../commands/text-formatting';
|
|
10
|
+
import * as commands from '../commands/text-formatting';
|
|
11
|
+
import { pluginKey } from './plugin-key';
|
|
12
|
+
export { pluginKey };
|
|
13
|
+
var getTextFormattingState = function getTextFormattingState(editorState, editorAnalyticsAPI) {
|
|
14
|
+
var _editorState$schema$m = editorState.schema.marks,
|
|
15
|
+
em = _editorState$schema$m.em,
|
|
16
|
+
code = _editorState$schema$m.code,
|
|
17
|
+
strike = _editorState$schema$m.strike,
|
|
18
|
+
strong = _editorState$schema$m.strong,
|
|
19
|
+
subsup = _editorState$schema$m.subsup,
|
|
20
|
+
underline = _editorState$schema$m.underline;
|
|
21
|
+
var state = {};
|
|
22
|
+
if (code) {
|
|
23
|
+
state.codeActive = anyMarkActive(editorState, code.create());
|
|
24
|
+
state.codeDisabled = !toggleMark(code)(editorState);
|
|
25
|
+
}
|
|
26
|
+
if (em) {
|
|
27
|
+
state.emActive = anyMarkActive(editorState, em);
|
|
28
|
+
state.emDisabled = state.codeActive ? true : !toggleMark(em)(editorState);
|
|
29
|
+
}
|
|
30
|
+
if (strike) {
|
|
31
|
+
state.strikeActive = anyMarkActive(editorState, strike);
|
|
32
|
+
state.strikeDisabled = state.codeActive ? true : !toggleMark(strike)(editorState);
|
|
33
|
+
}
|
|
34
|
+
if (strong) {
|
|
35
|
+
state.strongActive = anyMarkActive(editorState, strong);
|
|
36
|
+
state.strongDisabled = state.codeActive ? true : !toggleMark(strong)(editorState);
|
|
37
|
+
}
|
|
38
|
+
if (subsup) {
|
|
39
|
+
var subMark = subsup.create({
|
|
40
|
+
type: 'sub'
|
|
41
|
+
});
|
|
42
|
+
var supMark = subsup.create({
|
|
43
|
+
type: 'sup'
|
|
44
|
+
});
|
|
45
|
+
state.subscriptActive = anyMarkActive(editorState, subMark);
|
|
46
|
+
state.subscriptDisabled = state.codeActive ? true : !toggleMark(subsup, {
|
|
47
|
+
type: 'sub'
|
|
48
|
+
})(editorState);
|
|
49
|
+
state.superscriptActive = anyMarkActive(editorState, supMark);
|
|
50
|
+
state.superscriptDisabled = state.codeActive ? true : !toggleMark(subsup, {
|
|
51
|
+
type: 'sup'
|
|
52
|
+
})(editorState);
|
|
53
|
+
}
|
|
54
|
+
if (underline) {
|
|
55
|
+
state.underlineActive = anyMarkActive(editorState, underline);
|
|
56
|
+
state.underlineDisabled = state.codeActive ? true : !toggleMark(underline)(editorState);
|
|
57
|
+
}
|
|
58
|
+
return state;
|
|
59
|
+
};
|
|
60
|
+
export var plugin = function plugin(dispatch, editorAnalyticsAPI) {
|
|
61
|
+
return new SafePlugin({
|
|
62
|
+
state: {
|
|
63
|
+
init: function init(_config, state) {
|
|
64
|
+
return getTextFormattingState(state, editorAnalyticsAPI);
|
|
65
|
+
},
|
|
66
|
+
apply: function apply(_tr, pluginState, _oldState, newState) {
|
|
67
|
+
var state = getTextFormattingState(newState, editorAnalyticsAPI);
|
|
68
|
+
if (!shallowEqual(pluginState, state)) {
|
|
69
|
+
dispatch(pluginKey, state);
|
|
70
|
+
return state;
|
|
71
|
+
}
|
|
72
|
+
return pluginState;
|
|
73
|
+
}
|
|
74
|
+
},
|
|
75
|
+
key: pluginKey,
|
|
76
|
+
props: {
|
|
77
|
+
handleKeyDown: function handleKeyDown(view, event) {
|
|
78
|
+
var state = view.state,
|
|
79
|
+
dispatch = view.dispatch;
|
|
80
|
+
if (event.key === keymapMoveRight.common && !event.metaKey) {
|
|
81
|
+
return commands.moveRight()(state, dispatch);
|
|
82
|
+
} else if (event.key === keymapMoveLeft.common && !event.metaKey) {
|
|
83
|
+
return commands.moveLeft()(state, dispatch);
|
|
84
|
+
}
|
|
85
|
+
return false;
|
|
86
|
+
},
|
|
87
|
+
handleTextInput: function handleTextInput(view, from, to, text) {
|
|
88
|
+
var state = view.state,
|
|
89
|
+
dispatch = view.dispatch;
|
|
90
|
+
var schema = state.schema,
|
|
91
|
+
parentNodeType = state.selection.$from.parent.type;
|
|
92
|
+
if (parentNodeType.allowsMarkType(schema.marks.code)) {
|
|
93
|
+
return createInlineCodeFromTextInputWithAnalytics(editorAnalyticsAPI)(from, to, text)(state, dispatch);
|
|
94
|
+
}
|
|
95
|
+
return false;
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
});
|
|
99
|
+
};
|
|
@@ -0,0 +1,169 @@
|
|
|
1
|
+
import _toConsumableArray from "@babel/runtime/helpers/toConsumableArray";
|
|
2
|
+
import _defineProperty from "@babel/runtime/helpers/defineProperty";
|
|
3
|
+
import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
|
|
4
|
+
import { ACTION, ACTION_SUBJECT, ACTION_SUBJECT_ID, EVENT_TYPE, PUNC, SYMBOL } from '@atlaskit/editor-common/analytics';
|
|
5
|
+
import { inputRuleWithAnalytics } from '@atlaskit/editor-common/utils';
|
|
6
|
+
import { Selection } from '@atlaskit/editor-prosemirror/state';
|
|
7
|
+
import { createPlugin, createRule } from '@atlaskit/prosemirror-input-rules';
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Creates an InputRuleHandler that will match on a regular expression of the
|
|
11
|
+
* form `(prefix, content, suffix?)`, and replace it with some given text,
|
|
12
|
+
* maintaining prefix and suffix around the replacement.
|
|
13
|
+
*
|
|
14
|
+
* @param text text to replace with
|
|
15
|
+
*/
|
|
16
|
+
function replaceTextUsingCaptureGroup(text) {
|
|
17
|
+
return function (state, match, start, end) {
|
|
18
|
+
var _match = _slicedToArray(match, 4),
|
|
19
|
+
prefix = _match[1],
|
|
20
|
+
suffix = _match[3];
|
|
21
|
+
var replacement = text + (suffix || '');
|
|
22
|
+
var tr = state.tr,
|
|
23
|
+
$to = state.selection.$to;
|
|
24
|
+
var startPos = start + (prefix || '').length;
|
|
25
|
+
var safePos = Math.min(
|
|
26
|
+
// I know it is almost impossible to have a negative value at this point.
|
|
27
|
+
// But, this is JS #trustnoone
|
|
28
|
+
Math.max(startPos, 0), end);
|
|
29
|
+
tr.replaceWith(safePos, end, state.schema.text(replacement, $to.marks()));
|
|
30
|
+
tr.setSelection(Selection.near(tr.doc.resolve(tr.selection.to)));
|
|
31
|
+
return tr;
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
function createReplacementRule(to, from) {
|
|
35
|
+
return createRule(from, replaceTextUsingCaptureGroup(to));
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* Create replacement rules fiven a replacement map
|
|
40
|
+
* @param replMap - Replacement map
|
|
41
|
+
* @param trackingEventName - Analytics V2 tracking event name
|
|
42
|
+
* @param replacementRuleWithAnalytics - Analytics GAS V3 middleware for replacement and rules.
|
|
43
|
+
*/
|
|
44
|
+
function createReplacementRules(replMap, replacementRuleWithAnalytics) {
|
|
45
|
+
return Object.keys(replMap).map(function (replacement) {
|
|
46
|
+
var regex = replMap[replacement];
|
|
47
|
+
var rule = createReplacementRule(replacement, regex);
|
|
48
|
+
if (replacementRuleWithAnalytics) {
|
|
49
|
+
return replacementRuleWithAnalytics(replacement)(rule);
|
|
50
|
+
}
|
|
51
|
+
return rule;
|
|
52
|
+
});
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
// We don't agressively upgrade single quotes to smart quotes because
|
|
56
|
+
// they may clash with an emoji. Only do that when we have a matching
|
|
57
|
+
// single quote, or a contraction.
|
|
58
|
+
function createSingleQuotesRules() {
|
|
59
|
+
return [
|
|
60
|
+
// wrapped text
|
|
61
|
+
createRule(/(\s|^)'(\S+.*\S+)'$/, function (state, match, start, end) {
|
|
62
|
+
var OPEN_SMART_QUOTE_CHAR = '‘';
|
|
63
|
+
var CLOSED_SMART_QUOTE_CHAR = '’';
|
|
64
|
+
var _match2 = _slicedToArray(match, 3),
|
|
65
|
+
spacing = _match2[1],
|
|
66
|
+
innerContent = _match2[2];
|
|
67
|
+
// Edge case where match begins with some spacing. We need to add
|
|
68
|
+
// it back to the document
|
|
69
|
+
var openQuoteReplacement = spacing + OPEN_SMART_QUOTE_CHAR;
|
|
70
|
+
// End is not always where the closed quote is, edge case exists
|
|
71
|
+
// when there is spacing after the closed quote. We need to
|
|
72
|
+
// determine position of closed quote from the start position.
|
|
73
|
+
var positionOfClosedQuote = start + openQuoteReplacement.length + innerContent.length;
|
|
74
|
+
return state.tr.insertText(CLOSED_SMART_QUOTE_CHAR, positionOfClosedQuote, end).insertText(openQuoteReplacement, start, start + openQuoteReplacement.length);
|
|
75
|
+
}),
|
|
76
|
+
// apostrophe
|
|
77
|
+
createReplacementRule('’', /(\w+)(')(\w+)$/)];
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
/**
|
|
81
|
+
* Get replacement rules related to product
|
|
82
|
+
*/
|
|
83
|
+
function getProductRules(editorAnalyticsAPI) {
|
|
84
|
+
var productRuleWithAnalytics = function productRuleWithAnalytics(product) {
|
|
85
|
+
return inputRuleWithAnalytics(function (_, match) {
|
|
86
|
+
return {
|
|
87
|
+
action: ACTION.SUBSTITUTED,
|
|
88
|
+
actionSubject: ACTION_SUBJECT.TEXT,
|
|
89
|
+
actionSubjectId: ACTION_SUBJECT_ID.PRODUCT_NAME,
|
|
90
|
+
eventType: EVENT_TYPE.TRACK,
|
|
91
|
+
attributes: {
|
|
92
|
+
product: product,
|
|
93
|
+
originalSpelling: match[2]
|
|
94
|
+
}
|
|
95
|
+
};
|
|
96
|
+
}, editorAnalyticsAPI);
|
|
97
|
+
};
|
|
98
|
+
return createReplacementRules({
|
|
99
|
+
Atlassian: /(\s+|^)(atlassian)(\s)$/,
|
|
100
|
+
Jira: /(\s+|^)(jira|JIRA)(\s)$/,
|
|
101
|
+
Bitbucket: /(\s+|^)(bitbucket|BitBucket)(\s)$/,
|
|
102
|
+
Hipchat: /(\s+|^)(hipchat|HipChat)(\s)$/,
|
|
103
|
+
Trello: /(\s+|^)(trello)(\s)$/
|
|
104
|
+
}, productRuleWithAnalytics);
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
/**
|
|
108
|
+
* Get replacement rules related to symbol
|
|
109
|
+
*/
|
|
110
|
+
function getSymbolRules(editorAnalyticsAPI) {
|
|
111
|
+
var symbolToString = {
|
|
112
|
+
'→': SYMBOL.ARROW_RIGHT,
|
|
113
|
+
'←': SYMBOL.ARROW_LEFT,
|
|
114
|
+
'↔︎': SYMBOL.ARROW_DOUBLE
|
|
115
|
+
};
|
|
116
|
+
var symbolRuleWithAnalytics = function symbolRuleWithAnalytics(symbol) {
|
|
117
|
+
return inputRuleWithAnalytics({
|
|
118
|
+
action: ACTION.SUBSTITUTED,
|
|
119
|
+
actionSubject: ACTION_SUBJECT.TEXT,
|
|
120
|
+
actionSubjectId: ACTION_SUBJECT_ID.SYMBOL,
|
|
121
|
+
eventType: EVENT_TYPE.TRACK,
|
|
122
|
+
attributes: {
|
|
123
|
+
symbol: symbolToString[symbol]
|
|
124
|
+
}
|
|
125
|
+
}, editorAnalyticsAPI);
|
|
126
|
+
};
|
|
127
|
+
return createReplacementRules({
|
|
128
|
+
'→': /(\s+|^)(--?>)(\s)$/,
|
|
129
|
+
'←': /(\s+|^)(<--?)(\s)$/,
|
|
130
|
+
'↔︎': /(\s+|^)(<->?)(\s)$/
|
|
131
|
+
}, symbolRuleWithAnalytics);
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
/**
|
|
135
|
+
* Get replacement rules related to punctuation
|
|
136
|
+
*/
|
|
137
|
+
function getPunctuationRules(editorAnalyticsAPI) {
|
|
138
|
+
var punctuationToString = _defineProperty({
|
|
139
|
+
'–': PUNC.DASH,
|
|
140
|
+
'…': PUNC.ELLIPSIS,
|
|
141
|
+
'”': PUNC.QUOTE_DOUBLE
|
|
142
|
+
}, PUNC.QUOTE_SINGLE, PUNC.QUOTE_SINGLE);
|
|
143
|
+
var punctuationRuleWithAnalytics = function punctuationRuleWithAnalytics(punctuation) {
|
|
144
|
+
return inputRuleWithAnalytics({
|
|
145
|
+
action: ACTION.SUBSTITUTED,
|
|
146
|
+
actionSubject: ACTION_SUBJECT.TEXT,
|
|
147
|
+
actionSubjectId: ACTION_SUBJECT_ID.PUNC,
|
|
148
|
+
eventType: EVENT_TYPE.TRACK,
|
|
149
|
+
attributes: {
|
|
150
|
+
punctuation: punctuationToString[punctuation]
|
|
151
|
+
}
|
|
152
|
+
}, editorAnalyticsAPI);
|
|
153
|
+
};
|
|
154
|
+
var dashEllipsisRules = createReplacementRules({
|
|
155
|
+
'–': /(\s+|^)(--)(\s)$/,
|
|
156
|
+
'…': /()(\.\.\.)$/
|
|
157
|
+
}, punctuationRuleWithAnalytics);
|
|
158
|
+
var doubleQuoteRules = createReplacementRules({
|
|
159
|
+
'“': /((?:^|[\s\{\[\(\<'"\u2018\u201C]))(")$/,
|
|
160
|
+
'”': /"$/
|
|
161
|
+
}, punctuationRuleWithAnalytics);
|
|
162
|
+
var singleQuoteRules = createSingleQuotesRules();
|
|
163
|
+
return [].concat(_toConsumableArray(dashEllipsisRules), _toConsumableArray(doubleQuoteRules), _toConsumableArray(singleQuoteRules.map(function (rule) {
|
|
164
|
+
return punctuationRuleWithAnalytics(PUNC.QUOTE_SINGLE)(rule);
|
|
165
|
+
})));
|
|
166
|
+
}
|
|
167
|
+
export default (function (editorAnalyticsAPI) {
|
|
168
|
+
return createPlugin('text-formatting:smart-input', [].concat(_toConsumableArray(getProductRules(editorAnalyticsAPI)), _toConsumableArray(getSymbolRules(editorAnalyticsAPI)), _toConsumableArray(getPunctuationRules(editorAnalyticsAPI))));
|
|
169
|
+
});
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import _defineProperty from "@babel/runtime/helpers/defineProperty";
|
|
2
|
+
var _ResponsiveCustomButt, _ResponsiveCustomMenu;
|
|
3
|
+
import { ToolbarSize } from '@atlaskit/editor-common/types';
|
|
4
|
+
import { IconTypes } from './types';
|
|
5
|
+
export var DefaultButtonsToolbar = [IconTypes.strong, IconTypes.em];
|
|
6
|
+
export var DefaultButtonsMenu = [IconTypes.underline, IconTypes.strike, IconTypes.code, IconTypes.subscript, IconTypes.superscript];
|
|
7
|
+
export var ResponsiveCustomButtonToolbar = (_ResponsiveCustomButt = {}, _defineProperty(_ResponsiveCustomButt, ToolbarSize.XXL, DefaultButtonsToolbar), _defineProperty(_ResponsiveCustomButt, ToolbarSize.XL, DefaultButtonsToolbar), _defineProperty(_ResponsiveCustomButt, ToolbarSize.L, DefaultButtonsToolbar), _defineProperty(_ResponsiveCustomButt, ToolbarSize.M, []), _defineProperty(_ResponsiveCustomButt, ToolbarSize.S, []), _defineProperty(_ResponsiveCustomButt, ToolbarSize.XXXS, []), _ResponsiveCustomButt);
|
|
8
|
+
export var ResponsiveCustomMenu = (_ResponsiveCustomMenu = {}, _defineProperty(_ResponsiveCustomMenu, ToolbarSize.XXL, DefaultButtonsMenu), _defineProperty(_ResponsiveCustomMenu, ToolbarSize.XL, DefaultButtonsMenu), _defineProperty(_ResponsiveCustomMenu, ToolbarSize.L, DefaultButtonsMenu), _defineProperty(_ResponsiveCustomMenu, ToolbarSize.M, [IconTypes.strong, IconTypes.em].concat(DefaultButtonsMenu)), _defineProperty(_ResponsiveCustomMenu, ToolbarSize.S, [IconTypes.strong, IconTypes.em].concat(DefaultButtonsMenu)), _defineProperty(_ResponsiveCustomMenu, ToolbarSize.XXXS, [IconTypes.strong, IconTypes.em].concat(DefaultButtonsMenu)), _ResponsiveCustomMenu);
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
|
|
2
|
+
import React, { useCallback, useMemo, useState } from 'react';
|
|
3
|
+
import { DropdownMenuWithKeyboardNavigation as DropdownMenu } from '@atlaskit/editor-common/ui-menu';
|
|
4
|
+
import { akEditorMenuZIndex } from '@atlaskit/editor-shared-styles';
|
|
5
|
+
import { useMenuState } from './hooks/menu-state';
|
|
6
|
+
import { MoreButton } from './more-button';
|
|
7
|
+
export var FormattingTextDropdownMenu = /*#__PURE__*/React.memo(function (_ref) {
|
|
8
|
+
var editorView = _ref.editorView,
|
|
9
|
+
moreButtonLabel = _ref.moreButtonLabel,
|
|
10
|
+
isReducedSpacing = _ref.isReducedSpacing,
|
|
11
|
+
items = _ref.items,
|
|
12
|
+
hasFormattingActive = _ref.hasFormattingActive,
|
|
13
|
+
popupsBoundariesElement = _ref.popupsBoundariesElement,
|
|
14
|
+
popupsMountPoint = _ref.popupsMountPoint,
|
|
15
|
+
popupsScrollableElement = _ref.popupsScrollableElement;
|
|
16
|
+
var _useMenuState = useMenuState(),
|
|
17
|
+
_useMenuState2 = _slicedToArray(_useMenuState, 3),
|
|
18
|
+
isMenuOpen = _useMenuState2[0],
|
|
19
|
+
toggleMenu = _useMenuState2[1],
|
|
20
|
+
closeMenu = _useMenuState2[2];
|
|
21
|
+
var _useState = useState(false),
|
|
22
|
+
_useState2 = _slicedToArray(_useState, 2),
|
|
23
|
+
isOpenedByKeyboard = _useState2[0],
|
|
24
|
+
setIsOpenedByKeyboard = _useState2[1];
|
|
25
|
+
var group = useMemo(function () {
|
|
26
|
+
return [{
|
|
27
|
+
items: items
|
|
28
|
+
}];
|
|
29
|
+
}, [items]);
|
|
30
|
+
var onItemActivated = useCallback(function (_ref2) {
|
|
31
|
+
var item = _ref2.item,
|
|
32
|
+
_ref2$shouldCloseMenu = _ref2.shouldCloseMenu,
|
|
33
|
+
shouldCloseMenu = _ref2$shouldCloseMenu === void 0 ? true : _ref2$shouldCloseMenu;
|
|
34
|
+
item.command(editorView.state, editorView.dispatch);
|
|
35
|
+
if (shouldCloseMenu) {
|
|
36
|
+
closeMenu();
|
|
37
|
+
}
|
|
38
|
+
}, [editorView.state, editorView.dispatch, closeMenu]);
|
|
39
|
+
return /*#__PURE__*/React.createElement(DropdownMenu, {
|
|
40
|
+
mountTo: popupsMountPoint,
|
|
41
|
+
onOpenChange: closeMenu,
|
|
42
|
+
boundariesElement: popupsBoundariesElement,
|
|
43
|
+
scrollableElement: popupsScrollableElement,
|
|
44
|
+
onItemActivated: onItemActivated,
|
|
45
|
+
isOpen: isMenuOpen,
|
|
46
|
+
items: group,
|
|
47
|
+
zIndex: akEditorMenuZIndex,
|
|
48
|
+
fitHeight: 188,
|
|
49
|
+
fitWidth: 136,
|
|
50
|
+
shouldUseDefaultRole: true,
|
|
51
|
+
shouldFocusFirstItem: function shouldFocusFirstItem() {
|
|
52
|
+
if (isOpenedByKeyboard) {
|
|
53
|
+
setIsOpenedByKeyboard(false);
|
|
54
|
+
}
|
|
55
|
+
return isOpenedByKeyboard;
|
|
56
|
+
}
|
|
57
|
+
}, /*#__PURE__*/React.createElement(MoreButton, {
|
|
58
|
+
isSelected: isMenuOpen || hasFormattingActive,
|
|
59
|
+
label: moreButtonLabel,
|
|
60
|
+
isReducedSpacing: isReducedSpacing,
|
|
61
|
+
isDisabled: false,
|
|
62
|
+
onClick: function onClick() {
|
|
63
|
+
toggleMenu();
|
|
64
|
+
setIsOpenedByKeyboard(false);
|
|
65
|
+
},
|
|
66
|
+
onKeyDown: function onKeyDown(event) {
|
|
67
|
+
if (event.key === 'Enter' || event.key === ' ') {
|
|
68
|
+
event.preventDefault();
|
|
69
|
+
toggleMenu();
|
|
70
|
+
setIsOpenedByKeyboard(true);
|
|
71
|
+
}
|
|
72
|
+
},
|
|
73
|
+
"aria-expanded": isMenuOpen
|
|
74
|
+
}));
|
|
75
|
+
});
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
/** @jsx jsx */
|
|
2
|
+
import { useCallback, useMemo } from 'react';
|
|
3
|
+
import { jsx } from '@emotion/react';
|
|
4
|
+
import { INPUT_METHOD } from '@atlaskit/editor-common/analytics';
|
|
5
|
+
import { clearFormatting as clearFormattingKeymap, tooltip } from '@atlaskit/editor-common/keymaps';
|
|
6
|
+
import { toolbarMessages } from '@atlaskit/editor-common/messages';
|
|
7
|
+
import { shortcutStyle } from '@atlaskit/editor-shared-styles/shortcut';
|
|
8
|
+
import { clearFormattingWithAnalytics } from '../../../commands/clear-formatting';
|
|
9
|
+
import { pluginKey as clearFormattingPluginKey } from '../../../pm-plugins/clear-formatting';
|
|
10
|
+
var useClearFormattingPluginState = function useClearFormattingPluginState(editorState) {
|
|
11
|
+
return useMemo(function () {
|
|
12
|
+
return clearFormattingPluginKey.getState(editorState);
|
|
13
|
+
}, [editorState]);
|
|
14
|
+
};
|
|
15
|
+
export var useClearIcon = function useClearIcon(_ref) {
|
|
16
|
+
var intl = _ref.intl,
|
|
17
|
+
editorState = _ref.editorState,
|
|
18
|
+
editorAnalyticsAPI = _ref.editorAnalyticsAPI;
|
|
19
|
+
var pluginState = useClearFormattingPluginState(editorState);
|
|
20
|
+
var isPluginAvailable = Boolean(pluginState);
|
|
21
|
+
var formattingIsPresent = Boolean(pluginState === null || pluginState === void 0 ? void 0 : pluginState.formattingIsPresent);
|
|
22
|
+
var clearFormattingLabel = intl.formatMessage(toolbarMessages.clearFormatting);
|
|
23
|
+
var clearFormattingToolbar = useCallback(function (state, dispatch) {
|
|
24
|
+
return clearFormattingWithAnalytics(INPUT_METHOD.TOOLBAR, editorAnalyticsAPI)(state, dispatch);
|
|
25
|
+
}, [editorAnalyticsAPI]);
|
|
26
|
+
return useMemo(function () {
|
|
27
|
+
if (!isPluginAvailable) {
|
|
28
|
+
return null;
|
|
29
|
+
}
|
|
30
|
+
return {
|
|
31
|
+
key: 'clearFormatting',
|
|
32
|
+
command: clearFormattingToolbar,
|
|
33
|
+
content: clearFormattingLabel,
|
|
34
|
+
elemAfter:
|
|
35
|
+
// eslint-disable-next-line @atlaskit/design-system/consistent-css-prop-usage
|
|
36
|
+
jsx("div", {
|
|
37
|
+
css: shortcutStyle
|
|
38
|
+
}, tooltip(clearFormattingKeymap)),
|
|
39
|
+
value: {
|
|
40
|
+
name: 'clearFormatting'
|
|
41
|
+
},
|
|
42
|
+
isActive: false,
|
|
43
|
+
isDisabled: !formattingIsPresent,
|
|
44
|
+
'aria-label': clearFormattingKeymap ? tooltip(clearFormattingKeymap, String(clearFormattingLabel)) : String(clearFormattingLabel)
|
|
45
|
+
};
|
|
46
|
+
}, [isPluginAvailable, clearFormattingToolbar, clearFormattingLabel, formattingIsPresent]);
|
|
47
|
+
};
|
|
@@ -0,0 +1,215 @@
|
|
|
1
|
+
import _defineProperty from "@babel/runtime/helpers/defineProperty";
|
|
2
|
+
var _IconsMarkSchema;
|
|
3
|
+
/** @jsx jsx */
|
|
4
|
+
import React, { useMemo } from 'react';
|
|
5
|
+
import { jsx } from '@emotion/react';
|
|
6
|
+
import { INPUT_METHOD, TOOLBAR_ACTION_SUBJECT_ID } from '@atlaskit/editor-common/analytics';
|
|
7
|
+
import { getAriaKeyshortcuts, toggleBold, toggleCode, toggleItalic, toggleStrikethrough, toggleSubscript, toggleSuperscript, toggleUnderline, tooltip, ToolTipContent } from '@atlaskit/editor-common/keymaps';
|
|
8
|
+
import { toolbarMessages } from '@atlaskit/editor-common/messages';
|
|
9
|
+
import { shortcutStyle } from '@atlaskit/editor-shared-styles/shortcut';
|
|
10
|
+
import BoldIcon from '@atlaskit/icon/glyph/editor/bold';
|
|
11
|
+
import ItalicIcon from '@atlaskit/icon/glyph/editor/italic';
|
|
12
|
+
import { toggleCodeWithAnalytics, toggleEmWithAnalytics, toggleStrikeWithAnalytics, toggleStrongWithAnalytics, toggleSubscriptWithAnalytics, toggleSuperscriptWithAnalytics, toggleUnderlineWithAnalytics } from '../../../actions';
|
|
13
|
+
import { pluginKey as textFormattingPluginKey } from '../../../pm-plugins/plugin-key';
|
|
14
|
+
import { IconTypes } from '../types';
|
|
15
|
+
var withToolbarInputMethod = function withToolbarInputMethod(func) {
|
|
16
|
+
return func({
|
|
17
|
+
inputMethod: INPUT_METHOD.TOOLBAR
|
|
18
|
+
});
|
|
19
|
+
};
|
|
20
|
+
var IconButtons = function IconButtons(editorAnalyticsAPI) {
|
|
21
|
+
return {
|
|
22
|
+
strong: {
|
|
23
|
+
buttonId: TOOLBAR_ACTION_SUBJECT_ID.TEXT_FORMATTING_STRONG,
|
|
24
|
+
command: withToolbarInputMethod(toggleStrongWithAnalytics(editorAnalyticsAPI)),
|
|
25
|
+
message: toolbarMessages.bold,
|
|
26
|
+
tooltipKeymap: toggleBold,
|
|
27
|
+
component: function component() {
|
|
28
|
+
return jsx(BoldIcon, {
|
|
29
|
+
label: ""
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
},
|
|
33
|
+
em: {
|
|
34
|
+
buttonId: TOOLBAR_ACTION_SUBJECT_ID.TEXT_FORMATTING_ITALIC,
|
|
35
|
+
command: withToolbarInputMethod(toggleEmWithAnalytics(editorAnalyticsAPI)),
|
|
36
|
+
message: toolbarMessages.italic,
|
|
37
|
+
tooltipKeymap: toggleItalic,
|
|
38
|
+
component: function component() {
|
|
39
|
+
return jsx(ItalicIcon, {
|
|
40
|
+
label: ""
|
|
41
|
+
});
|
|
42
|
+
}
|
|
43
|
+
},
|
|
44
|
+
underline: {
|
|
45
|
+
command: withToolbarInputMethod(toggleUnderlineWithAnalytics(editorAnalyticsAPI)),
|
|
46
|
+
message: toolbarMessages.underline,
|
|
47
|
+
tooltipKeymap: toggleUnderline
|
|
48
|
+
},
|
|
49
|
+
strike: {
|
|
50
|
+
command: withToolbarInputMethod(toggleStrikeWithAnalytics(editorAnalyticsAPI)),
|
|
51
|
+
message: toolbarMessages.strike,
|
|
52
|
+
tooltipKeymap: toggleStrikethrough
|
|
53
|
+
},
|
|
54
|
+
code: {
|
|
55
|
+
command: withToolbarInputMethod(toggleCodeWithAnalytics(editorAnalyticsAPI)),
|
|
56
|
+
message: toolbarMessages.code,
|
|
57
|
+
tooltipKeymap: toggleCode
|
|
58
|
+
},
|
|
59
|
+
subscript: {
|
|
60
|
+
command: withToolbarInputMethod(toggleSubscriptWithAnalytics(editorAnalyticsAPI)),
|
|
61
|
+
message: toolbarMessages.subscript,
|
|
62
|
+
tooltipKeymap: toggleSubscript
|
|
63
|
+
},
|
|
64
|
+
superscript: {
|
|
65
|
+
command: withToolbarInputMethod(toggleSuperscriptWithAnalytics(editorAnalyticsAPI)),
|
|
66
|
+
message: toolbarMessages.superscript,
|
|
67
|
+
tooltipKeymap: toggleSuperscript
|
|
68
|
+
}
|
|
69
|
+
};
|
|
70
|
+
};
|
|
71
|
+
var getIcon = function getIcon(_ref) {
|
|
72
|
+
var iconType = _ref.iconType,
|
|
73
|
+
isDisabled = _ref.isDisabled,
|
|
74
|
+
isActive = _ref.isActive,
|
|
75
|
+
intl = _ref.intl,
|
|
76
|
+
editorAnalyticsAPI = _ref.editorAnalyticsAPI;
|
|
77
|
+
var icon = IconButtons(editorAnalyticsAPI)[iconType];
|
|
78
|
+
var content = intl.formatMessage(icon.message);
|
|
79
|
+
var tooltipKeymap = icon.tooltipKeymap;
|
|
80
|
+
return {
|
|
81
|
+
content: content,
|
|
82
|
+
buttonId: icon.buttonId,
|
|
83
|
+
iconMark: iconType,
|
|
84
|
+
key: iconType,
|
|
85
|
+
command: icon.command,
|
|
86
|
+
iconElement: icon.component ? icon.component() : undefined,
|
|
87
|
+
tooltipElement: tooltipKeymap ? jsx(ToolTipContent, {
|
|
88
|
+
description: content,
|
|
89
|
+
keymap: tooltipKeymap
|
|
90
|
+
}) : undefined,
|
|
91
|
+
elemAfter: tooltipKeymap ?
|
|
92
|
+
// eslint-disable-next-line @atlaskit/design-system/consistent-css-prop-usage
|
|
93
|
+
jsx("div", {
|
|
94
|
+
css: shortcutStyle
|
|
95
|
+
}, tooltip(tooltipKeymap)) : undefined,
|
|
96
|
+
value: {
|
|
97
|
+
name: iconType
|
|
98
|
+
},
|
|
99
|
+
isActive: isActive,
|
|
100
|
+
isDisabled: isDisabled,
|
|
101
|
+
'aria-label': tooltipKeymap ? tooltip(tooltipKeymap, String(content)) : String(content),
|
|
102
|
+
'aria-keyshortcuts': getAriaKeyshortcuts(tooltipKeymap)
|
|
103
|
+
};
|
|
104
|
+
};
|
|
105
|
+
var IconsMarkSchema = (_IconsMarkSchema = {}, _defineProperty(_IconsMarkSchema, IconTypes.strong, 'strong'), _defineProperty(_IconsMarkSchema, IconTypes.em, 'em'), _defineProperty(_IconsMarkSchema, IconTypes.strike, 'strike'), _defineProperty(_IconsMarkSchema, IconTypes.code, 'code'), _defineProperty(_IconsMarkSchema, IconTypes.underline, 'underline'), _defineProperty(_IconsMarkSchema, IconTypes.superscript, 'subsup'), _defineProperty(_IconsMarkSchema, IconTypes.subscript, 'subsup'), _IconsMarkSchema);
|
|
106
|
+
var buildMenuIconState = function buildMenuIconState(iconMark) {
|
|
107
|
+
return function (_ref2) {
|
|
108
|
+
var schema = _ref2.schema,
|
|
109
|
+
textFormattingPluginState = _ref2.textFormattingPluginState;
|
|
110
|
+
var hasPluginState = Boolean(Object.keys(textFormattingPluginState || {}).length);
|
|
111
|
+
var markSchema = IconsMarkSchema[iconMark];
|
|
112
|
+
var hasSchemaMark = Boolean(schema.marks[markSchema]);
|
|
113
|
+
if (!hasPluginState) {
|
|
114
|
+
return {
|
|
115
|
+
isActive: false,
|
|
116
|
+
isDisabled: true,
|
|
117
|
+
isHidden: false,
|
|
118
|
+
hasSchemaMark: hasSchemaMark
|
|
119
|
+
};
|
|
120
|
+
}
|
|
121
|
+
var isActive = textFormattingPluginState["".concat(iconMark, "Active")];
|
|
122
|
+
var isDisabled = textFormattingPluginState["".concat(iconMark, "Disabled")];
|
|
123
|
+
var isHidden = textFormattingPluginState["".concat(iconMark, "Hidden")];
|
|
124
|
+
return {
|
|
125
|
+
isActive: Boolean(isActive),
|
|
126
|
+
isDisabled: Boolean(isDisabled),
|
|
127
|
+
isHidden: Boolean(isHidden),
|
|
128
|
+
hasSchemaMark: hasSchemaMark
|
|
129
|
+
};
|
|
130
|
+
};
|
|
131
|
+
};
|
|
132
|
+
var buildIcon = function buildIcon(iconMark, editorAnalyticsAPI) {
|
|
133
|
+
var getState = buildMenuIconState(iconMark);
|
|
134
|
+
return function (_ref3) {
|
|
135
|
+
var schema = _ref3.schema,
|
|
136
|
+
textFormattingPluginState = _ref3.textFormattingPluginState,
|
|
137
|
+
intl = _ref3.intl,
|
|
138
|
+
isToolbarDisabled = _ref3.isToolbarDisabled;
|
|
139
|
+
var iconState = getState({
|
|
140
|
+
schema: schema,
|
|
141
|
+
textFormattingPluginState: textFormattingPluginState
|
|
142
|
+
});
|
|
143
|
+
var isActive = iconState.isActive,
|
|
144
|
+
isDisabled = iconState.isDisabled,
|
|
145
|
+
isHidden = iconState.isHidden,
|
|
146
|
+
hasSchemaMark = iconState.hasSchemaMark;
|
|
147
|
+
var iconComponent = useMemo(function () {
|
|
148
|
+
return getIcon({
|
|
149
|
+
iconType: IconTypes[iconMark],
|
|
150
|
+
isDisabled: isToolbarDisabled || isDisabled,
|
|
151
|
+
isActive: isActive,
|
|
152
|
+
intl: intl,
|
|
153
|
+
editorAnalyticsAPI: editorAnalyticsAPI
|
|
154
|
+
});
|
|
155
|
+
}, [isToolbarDisabled, isDisabled, isActive, intl]);
|
|
156
|
+
var shouldRenderIcon = hasSchemaMark && !isHidden;
|
|
157
|
+
return useMemo(function () {
|
|
158
|
+
return shouldRenderIcon ? iconComponent : null;
|
|
159
|
+
}, [shouldRenderIcon, iconComponent]);
|
|
160
|
+
};
|
|
161
|
+
};
|
|
162
|
+
var useTextFormattingPluginState = function useTextFormattingPluginState(editorState) {
|
|
163
|
+
return useMemo(function () {
|
|
164
|
+
var pluginState = textFormattingPluginKey.getState(editorState);
|
|
165
|
+
|
|
166
|
+
// TODO: ED-13910 for reasons that goes beyond my knowledge. This is the only way to make the current unit tests happy. Even thought this was wrong before
|
|
167
|
+
return pluginState;
|
|
168
|
+
}, [editorState]);
|
|
169
|
+
};
|
|
170
|
+
export var useFormattingIcons = function useFormattingIcons(_ref4) {
|
|
171
|
+
var isToolbarDisabled = _ref4.isToolbarDisabled,
|
|
172
|
+
editorState = _ref4.editorState,
|
|
173
|
+
intl = _ref4.intl,
|
|
174
|
+
editorAnalyticsAPI = _ref4.editorAnalyticsAPI;
|
|
175
|
+
var textFormattingPluginState = useTextFormattingPluginState(editorState);
|
|
176
|
+
var schema = editorState.schema;
|
|
177
|
+
var props = {
|
|
178
|
+
schema: schema,
|
|
179
|
+
textFormattingPluginState: textFormattingPluginState,
|
|
180
|
+
intl: intl,
|
|
181
|
+
isToolbarDisabled: Boolean(isToolbarDisabled)
|
|
182
|
+
};
|
|
183
|
+
var buildStrongIcon = buildIcon(IconTypes.strong, editorAnalyticsAPI);
|
|
184
|
+
var buildEmIcon = buildIcon(IconTypes.em, editorAnalyticsAPI);
|
|
185
|
+
var buildUnderlineIcon = buildIcon(IconTypes.underline, editorAnalyticsAPI);
|
|
186
|
+
var buildStrikeIcon = buildIcon(IconTypes.strike, editorAnalyticsAPI);
|
|
187
|
+
var buildCodeIcon = buildIcon(IconTypes.code, editorAnalyticsAPI);
|
|
188
|
+
var buildSubscriptIcon = buildIcon(IconTypes.subscript, editorAnalyticsAPI);
|
|
189
|
+
var buildSuperscriptIcon = buildIcon(IconTypes.superscript, editorAnalyticsAPI);
|
|
190
|
+
var strongIcon = buildStrongIcon(props);
|
|
191
|
+
var emIcon = buildEmIcon(props);
|
|
192
|
+
var underlineIcon = buildUnderlineIcon(props);
|
|
193
|
+
var strikeIcon = buildStrikeIcon(props);
|
|
194
|
+
var codeIcon = buildCodeIcon(props);
|
|
195
|
+
var subscriptIcon = buildSubscriptIcon(props);
|
|
196
|
+
var superscriptIcon = buildSuperscriptIcon(props);
|
|
197
|
+
var result = useMemo(function () {
|
|
198
|
+
return [strongIcon, emIcon, underlineIcon, strikeIcon, codeIcon, subscriptIcon, superscriptIcon];
|
|
199
|
+
}, [strongIcon, emIcon, underlineIcon, strikeIcon, codeIcon, subscriptIcon, superscriptIcon]);
|
|
200
|
+
return result;
|
|
201
|
+
};
|
|
202
|
+
export var useHasFormattingActived = function useHasFormattingActived(_ref5) {
|
|
203
|
+
var editorState = _ref5.editorState,
|
|
204
|
+
iconTypeList = _ref5.iconTypeList;
|
|
205
|
+
var textFormattingPluginState = useTextFormattingPluginState(editorState);
|
|
206
|
+
var hasActiveFormatting = useMemo(function () {
|
|
207
|
+
if (!textFormattingPluginState) {
|
|
208
|
+
return false;
|
|
209
|
+
}
|
|
210
|
+
return iconTypeList.some(function (iconType) {
|
|
211
|
+
return textFormattingPluginState["".concat(iconType, "Active")];
|
|
212
|
+
});
|
|
213
|
+
}, [textFormattingPluginState, iconTypeList]);
|
|
214
|
+
return hasActiveFormatting;
|
|
215
|
+
};
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
|
|
2
|
+
import { useCallback, useState } from 'react';
|
|
3
|
+
export var useMenuState = function useMenuState() {
|
|
4
|
+
var _useState = useState(false),
|
|
5
|
+
_useState2 = _slicedToArray(_useState, 2),
|
|
6
|
+
isMenuOpen = _useState2[0],
|
|
7
|
+
setIsMenuOpened = _useState2[1];
|
|
8
|
+
var toggleMenu = useCallback(function () {
|
|
9
|
+
setIsMenuOpened(!isMenuOpen);
|
|
10
|
+
}, [isMenuOpen]);
|
|
11
|
+
var closeMenu = useCallback(function () {
|
|
12
|
+
setIsMenuOpened(false);
|
|
13
|
+
}, []);
|
|
14
|
+
return [isMenuOpen, toggleMenu, closeMenu];
|
|
15
|
+
};
|