@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.
Files changed (140) hide show
  1. package/.eslintrc.js +7 -0
  2. package/CHANGELOG.md +1 -0
  3. package/LICENSE.md +13 -0
  4. package/README.md +9 -0
  5. package/dist/cjs/actions.js +188 -0
  6. package/dist/cjs/commands/clear-formatting.js +111 -0
  7. package/dist/cjs/commands/text-formatting.js +143 -0
  8. package/dist/cjs/commands/transform-to-code.js +68 -0
  9. package/dist/cjs/index.js +12 -0
  10. package/dist/cjs/plugin.js +133 -0
  11. package/dist/cjs/pm-plugins/clear-formatting-keymap.js +21 -0
  12. package/dist/cjs/pm-plugins/clear-formatting.js +36 -0
  13. package/dist/cjs/pm-plugins/cursor.js +55 -0
  14. package/dist/cjs/pm-plugins/input-rule.js +274 -0
  15. package/dist/cjs/pm-plugins/keymap.js +52 -0
  16. package/dist/cjs/pm-plugins/main.js +113 -0
  17. package/dist/cjs/pm-plugins/plugin-key.js +9 -0
  18. package/dist/cjs/pm-plugins/smart-input-rule.js +176 -0
  19. package/dist/cjs/ui/Toolbar/constants.js +19 -0
  20. package/dist/cjs/ui/Toolbar/dropdown-menu.js +86 -0
  21. package/dist/cjs/ui/Toolbar/hooks/clear-formatting-icon.js +55 -0
  22. package/dist/cjs/ui/Toolbar/hooks/formatting-icons.js +227 -0
  23. package/dist/cjs/ui/Toolbar/hooks/menu-state.js +23 -0
  24. package/dist/cjs/ui/Toolbar/hooks/responsive-toolbar-buttons.js +60 -0
  25. package/dist/cjs/ui/Toolbar/index.js +183 -0
  26. package/dist/cjs/ui/Toolbar/more-button.js +42 -0
  27. package/dist/cjs/ui/Toolbar/single-toolbar-buttons.js +49 -0
  28. package/dist/cjs/ui/Toolbar/types.js +17 -0
  29. package/dist/cjs/utils/cell-selection.js +12 -0
  30. package/dist/cjs/utils.js +86 -0
  31. package/dist/cjs/version.json +5 -0
  32. package/dist/es2019/actions.js +161 -0
  33. package/dist/es2019/commands/clear-formatting.js +105 -0
  34. package/dist/es2019/commands/text-formatting.js +144 -0
  35. package/dist/es2019/commands/transform-to-code.js +71 -0
  36. package/dist/es2019/index.js +1 -0
  37. package/dist/es2019/plugin.js +124 -0
  38. package/dist/es2019/pm-plugins/clear-formatting-keymap.js +10 -0
  39. package/dist/es2019/pm-plugins/clear-formatting.js +26 -0
  40. package/dist/es2019/pm-plugins/cursor.js +52 -0
  41. package/dist/es2019/pm-plugins/input-rule.js +242 -0
  42. package/dist/es2019/pm-plugins/keymap.js +43 -0
  43. package/dist/es2019/pm-plugins/main.js +110 -0
  44. package/dist/es2019/pm-plugins/plugin-key.js +2 -0
  45. package/dist/es2019/pm-plugins/smart-input-rule.js +155 -0
  46. package/dist/es2019/ui/Toolbar/constants.js +20 -0
  47. package/dist/es2019/ui/Toolbar/dropdown-menu.js +66 -0
  48. package/dist/es2019/ui/Toolbar/hooks/clear-formatting-icon.js +44 -0
  49. package/dist/es2019/ui/Toolbar/hooks/formatting-icons.js +212 -0
  50. package/dist/es2019/ui/Toolbar/hooks/menu-state.js +11 -0
  51. package/dist/es2019/ui/Toolbar/hooks/responsive-toolbar-buttons.js +48 -0
  52. package/dist/es2019/ui/Toolbar/index.js +168 -0
  53. package/dist/es2019/ui/Toolbar/more-button.js +34 -0
  54. package/dist/es2019/ui/Toolbar/single-toolbar-buttons.js +39 -0
  55. package/dist/es2019/ui/Toolbar/types.js +10 -0
  56. package/dist/es2019/utils/cell-selection.js +5 -0
  57. package/dist/es2019/utils.js +74 -0
  58. package/dist/es2019/version.json +5 -0
  59. package/dist/esm/actions.js +168 -0
  60. package/dist/esm/commands/clear-formatting.js +101 -0
  61. package/dist/esm/commands/text-formatting.js +134 -0
  62. package/dist/esm/commands/transform-to-code.js +61 -0
  63. package/dist/esm/index.js +1 -0
  64. package/dist/esm/plugin.js +125 -0
  65. package/dist/esm/pm-plugins/clear-formatting-keymap.js +10 -0
  66. package/dist/esm/pm-plugins/clear-formatting.js +28 -0
  67. package/dist/esm/pm-plugins/cursor.js +48 -0
  68. package/dist/esm/pm-plugins/input-rule.js +257 -0
  69. package/dist/esm/pm-plugins/keymap.js +43 -0
  70. package/dist/esm/pm-plugins/main.js +99 -0
  71. package/dist/esm/pm-plugins/plugin-key.js +2 -0
  72. package/dist/esm/pm-plugins/smart-input-rule.js +169 -0
  73. package/dist/esm/ui/Toolbar/constants.js +8 -0
  74. package/dist/esm/ui/Toolbar/dropdown-menu.js +75 -0
  75. package/dist/esm/ui/Toolbar/hooks/clear-formatting-icon.js +47 -0
  76. package/dist/esm/ui/Toolbar/hooks/formatting-icons.js +215 -0
  77. package/dist/esm/ui/Toolbar/hooks/menu-state.js +15 -0
  78. package/dist/esm/ui/Toolbar/hooks/responsive-toolbar-buttons.js +50 -0
  79. package/dist/esm/ui/Toolbar/index.js +174 -0
  80. package/dist/esm/ui/Toolbar/more-button.js +33 -0
  81. package/dist/esm/ui/Toolbar/single-toolbar-buttons.js +38 -0
  82. package/dist/esm/ui/Toolbar/types.js +10 -0
  83. package/dist/esm/utils/cell-selection.js +5 -0
  84. package/dist/esm/utils.js +75 -0
  85. package/dist/esm/version.json +5 -0
  86. package/dist/types/actions.d.ts +22 -0
  87. package/dist/types/commands/clear-formatting.d.ts +6 -0
  88. package/dist/types/commands/text-formatting.d.ts +5 -0
  89. package/dist/types/commands/transform-to-code.d.ts +2 -0
  90. package/dist/types/index.d.ts +3 -0
  91. package/dist/types/plugin.d.ts +17 -0
  92. package/dist/types/pm-plugins/clear-formatting-keymap.d.ts +4 -0
  93. package/dist/types/pm-plugins/clear-formatting.d.ts +8 -0
  94. package/dist/types/pm-plugins/cursor.d.ts +3 -0
  95. package/dist/types/pm-plugins/input-rule.d.ts +23 -0
  96. package/dist/types/pm-plugins/keymap.d.ts +4 -0
  97. package/dist/types/pm-plugins/main.d.ts +7 -0
  98. package/dist/types/pm-plugins/plugin-key.d.ts +3 -0
  99. package/dist/types/pm-plugins/smart-input-rule.d.ts +3 -0
  100. package/dist/types/ui/Toolbar/constants.d.ts +6 -0
  101. package/dist/types/ui/Toolbar/dropdown-menu.d.ts +15 -0
  102. package/dist/types/ui/Toolbar/hooks/clear-formatting-icon.d.ts +7 -0
  103. package/dist/types/ui/Toolbar/hooks/formatting-icons.d.ts +14 -0
  104. package/dist/types/ui/Toolbar/hooks/menu-state.d.ts +1 -0
  105. package/dist/types/ui/Toolbar/hooks/responsive-toolbar-buttons.d.ts +20 -0
  106. package/dist/types/ui/Toolbar/index.d.ts +25 -0
  107. package/dist/types/ui/Toolbar/more-button.d.ts +14 -0
  108. package/dist/types/ui/Toolbar/single-toolbar-buttons.d.ts +10 -0
  109. package/dist/types/ui/Toolbar/types.d.ts +32 -0
  110. package/dist/types/utils/cell-selection.d.ts +3 -0
  111. package/dist/types/utils.d.ts +11 -0
  112. package/dist/types-ts4.5/actions.d.ts +22 -0
  113. package/dist/types-ts4.5/commands/clear-formatting.d.ts +6 -0
  114. package/dist/types-ts4.5/commands/text-formatting.d.ts +5 -0
  115. package/dist/types-ts4.5/commands/transform-to-code.d.ts +2 -0
  116. package/dist/types-ts4.5/index.d.ts +3 -0
  117. package/dist/types-ts4.5/plugin.d.ts +19 -0
  118. package/dist/types-ts4.5/pm-plugins/clear-formatting-keymap.d.ts +4 -0
  119. package/dist/types-ts4.5/pm-plugins/clear-formatting.d.ts +8 -0
  120. package/dist/types-ts4.5/pm-plugins/cursor.d.ts +3 -0
  121. package/dist/types-ts4.5/pm-plugins/input-rule.d.ts +23 -0
  122. package/dist/types-ts4.5/pm-plugins/keymap.d.ts +4 -0
  123. package/dist/types-ts4.5/pm-plugins/main.d.ts +7 -0
  124. package/dist/types-ts4.5/pm-plugins/plugin-key.d.ts +3 -0
  125. package/dist/types-ts4.5/pm-plugins/smart-input-rule.d.ts +3 -0
  126. package/dist/types-ts4.5/ui/Toolbar/constants.d.ts +6 -0
  127. package/dist/types-ts4.5/ui/Toolbar/dropdown-menu.d.ts +15 -0
  128. package/dist/types-ts4.5/ui/Toolbar/hooks/clear-formatting-icon.d.ts +7 -0
  129. package/dist/types-ts4.5/ui/Toolbar/hooks/formatting-icons.d.ts +14 -0
  130. package/dist/types-ts4.5/ui/Toolbar/hooks/menu-state.d.ts +5 -0
  131. package/dist/types-ts4.5/ui/Toolbar/hooks/responsive-toolbar-buttons.d.ts +20 -0
  132. package/dist/types-ts4.5/ui/Toolbar/index.d.ts +25 -0
  133. package/dist/types-ts4.5/ui/Toolbar/more-button.d.ts +14 -0
  134. package/dist/types-ts4.5/ui/Toolbar/single-toolbar-buttons.d.ts +10 -0
  135. package/dist/types-ts4.5/ui/Toolbar/types.d.ts +32 -0
  136. package/dist/types-ts4.5/utils/cell-selection.d.ts +3 -0
  137. package/dist/types-ts4.5/utils.d.ts +11 -0
  138. package/package.json +93 -0
  139. package/report.api.md +66 -0
  140. package/tmp/api-report-tmp.d.ts +39 -0
@@ -0,0 +1,50 @@
1
+ import _toConsumableArray from "@babel/runtime/helpers/toConsumableArray";
2
+ import { useMemo } from 'react';
3
+ import { DefaultButtonsMenu, DefaultButtonsToolbar, ResponsiveCustomButtonToolbar, ResponsiveCustomMenu } from '../constants';
4
+ export var useResponsiveIconTypeButtons = function useResponsiveIconTypeButtons(_ref) {
5
+ var toolbarSize = _ref.toolbarSize,
6
+ responsivenessEnabled = _ref.responsivenessEnabled;
7
+ var iconTypeList = useMemo(function () {
8
+ return ResponsiveCustomButtonToolbar[toolbarSize];
9
+ }, [toolbarSize]);
10
+ return responsivenessEnabled ? iconTypeList : DefaultButtonsToolbar;
11
+ };
12
+ export var useResponsiveIconTypeMenu = function useResponsiveIconTypeMenu(_ref2) {
13
+ var toolbarSize = _ref2.toolbarSize,
14
+ responsivenessEnabled = _ref2.responsivenessEnabled;
15
+ var iconTypeList = useMemo(function () {
16
+ return ResponsiveCustomMenu[toolbarSize];
17
+ }, [toolbarSize]);
18
+ return responsivenessEnabled ? iconTypeList : DefaultButtonsMenu;
19
+ };
20
+ export var useResponsiveToolbarButtons = function useResponsiveToolbarButtons(_ref3) {
21
+ var icons = _ref3.icons,
22
+ toolbarSize = _ref3.toolbarSize,
23
+ responsivenessEnabled = _ref3.responsivenessEnabled;
24
+ var iconTypeList = useResponsiveIconTypeButtons({
25
+ toolbarSize: toolbarSize,
26
+ responsivenessEnabled: responsivenessEnabled
27
+ });
28
+ var iconsPosition = useMemo(function () {
29
+ return icons.reduce(function (acc, icon) {
30
+ if (!icon || !icon.iconMark) {
31
+ return acc;
32
+ }
33
+ var isIconSingleButton = iconTypeList.includes(icon.iconMark);
34
+ if (isIconSingleButton) {
35
+ return {
36
+ dropdownItems: acc.dropdownItems,
37
+ singleItems: [].concat(_toConsumableArray(acc.singleItems), [icon])
38
+ };
39
+ }
40
+ return {
41
+ dropdownItems: [].concat(_toConsumableArray(acc.dropdownItems), [icon]),
42
+ singleItems: acc.singleItems
43
+ };
44
+ }, {
45
+ dropdownItems: [],
46
+ singleItems: []
47
+ });
48
+ }, [icons, iconTypeList]);
49
+ return iconsPosition;
50
+ };
@@ -0,0 +1,174 @@
1
+ import _toConsumableArray from "@babel/runtime/helpers/toConsumableArray";
2
+ import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
3
+ /** @jsx jsx */
4
+ import { useEffect, useMemo, useState } from 'react';
5
+ import { jsx } from '@emotion/react';
6
+ import { injectIntl } from 'react-intl-next';
7
+ import { usePreviousState } from '@atlaskit/editor-common/hooks';
8
+ import { toolbarMessages } from '@atlaskit/editor-common/messages';
9
+ import { buttonGroupStyle, separatorStyles, wrapperStyle } from '@atlaskit/editor-common/styles';
10
+ import { Announcer } from '@atlaskit/editor-common/ui';
11
+ import { compareItemsArrays, isArrayContainsContent } from '../../utils';
12
+ import { FormattingTextDropdownMenu } from './dropdown-menu';
13
+ import { useClearIcon } from './hooks/clear-formatting-icon';
14
+ import { useFormattingIcons, useHasFormattingActived } from './hooks/formatting-icons';
15
+ import { useResponsiveIconTypeMenu, useResponsiveToolbarButtons } from './hooks/responsive-toolbar-buttons';
16
+ import { MoreButton } from './more-button';
17
+ import { SingleToolbarButtons } from './single-toolbar-buttons';
18
+ var ToolbarFormatting = function ToolbarFormatting(_ref) {
19
+ var _usePreviousState;
20
+ var shouldUseResponsiveToolbar = _ref.shouldUseResponsiveToolbar,
21
+ popupsMountPoint = _ref.popupsMountPoint,
22
+ popupsBoundariesElement = _ref.popupsBoundariesElement,
23
+ popupsScrollableElement = _ref.popupsScrollableElement,
24
+ editorView = _ref.editorView,
25
+ toolbarSize = _ref.toolbarSize,
26
+ isReducedSpacing = _ref.isReducedSpacing,
27
+ isToolbarDisabled = _ref.isToolbarDisabled,
28
+ intl = _ref.intl,
29
+ editorAnalyticsAPI = _ref.editorAnalyticsAPI;
30
+ var editorState = useMemo(function () {
31
+ return editorView.state;
32
+ }, [editorView.state]);
33
+ var _useState = useState(''),
34
+ _useState2 = _slicedToArray(_useState, 2),
35
+ message = _useState2[0],
36
+ setMessage = _useState2[1];
37
+ var defaultIcons = useFormattingIcons({
38
+ editorState: editorState,
39
+ intl: intl,
40
+ isToolbarDisabled: isToolbarDisabled,
41
+ editorAnalyticsAPI: editorAnalyticsAPI
42
+ });
43
+ var clearIcon = useClearIcon({
44
+ editorState: editorState,
45
+ intl: intl,
46
+ editorAnalyticsAPI: editorAnalyticsAPI
47
+ });
48
+ var menuIconTypeList = useResponsiveIconTypeMenu({
49
+ toolbarSize: toolbarSize,
50
+ responsivenessEnabled: shouldUseResponsiveToolbar
51
+ });
52
+ var hasFormattingActive = useHasFormattingActived({
53
+ editorState: editorView.state,
54
+ iconTypeList: menuIconTypeList
55
+ });
56
+ var _useResponsiveToolbar = useResponsiveToolbarButtons({
57
+ icons: defaultIcons,
58
+ toolbarSize: toolbarSize,
59
+ responsivenessEnabled: shouldUseResponsiveToolbar
60
+ }),
61
+ dropdownItems = _useResponsiveToolbar.dropdownItems,
62
+ singleItems = _useResponsiveToolbar.singleItems;
63
+ var clearFormattingStatus = intl.formatMessage(toolbarMessages.textFormattingOff);
64
+ var superscriptOffSubscriptOnStatus = intl.formatMessage(toolbarMessages.superscriptOffSubscriptOn);
65
+ var subscriptOffSuperscriptOnStatus = intl.formatMessage(toolbarMessages.subscriptOffSuperscriptOn);
66
+ var activeItems = [].concat(_toConsumableArray(dropdownItems), _toConsumableArray(singleItems)).filter(function (item) {
67
+ return item.isActive;
68
+ });
69
+ var prevActiveItems = (_usePreviousState = usePreviousState(activeItems)) !== null && _usePreviousState !== void 0 ? _usePreviousState : [];
70
+ var fromSuperscriptToSubscript = isArrayContainsContent(activeItems, 'Subscript') && isArrayContainsContent(prevActiveItems, 'Superscript');
71
+ var fromSubscriptToSuperscript = isArrayContainsContent(activeItems, 'Superscript') && isArrayContainsContent(prevActiveItems, 'Subscript');
72
+ var comparedItems;
73
+ var screenReaderMessage = '';
74
+ if (prevActiveItems && activeItems.length > prevActiveItems.length) {
75
+ comparedItems = compareItemsArrays(activeItems, prevActiveItems);
76
+ screenReaderMessage = intl.formatMessage(toolbarMessages.on, {
77
+ formattingType: comparedItems[0].content
78
+ });
79
+ } else {
80
+ comparedItems = compareItemsArrays(prevActiveItems, activeItems);
81
+ if (comparedItems && comparedItems.length) {
82
+ var _activeItems$;
83
+ screenReaderMessage = intl.formatMessage(toolbarMessages.off, {
84
+ formattingType: comparedItems[0].content
85
+ });
86
+ if (((_activeItems$ = activeItems[0]) === null || _activeItems$ === void 0 ? void 0 : _activeItems$.content) === 'Code') {
87
+ screenReaderMessage = intl.formatMessage(toolbarMessages.codeOn, {
88
+ textFormattingOff: (prevActiveItems === null || prevActiveItems === void 0 ? void 0 : prevActiveItems.length) > 1 ? clearFormattingStatus : screenReaderMessage
89
+ });
90
+ }
91
+ if (fromSuperscriptToSubscript) {
92
+ screenReaderMessage = superscriptOffSubscriptOnStatus;
93
+ }
94
+ if (fromSubscriptToSuperscript) {
95
+ screenReaderMessage = subscriptOffSuperscriptOnStatus;
96
+ }
97
+ }
98
+ }
99
+
100
+ // handle 'Clear formatting' status for screen readers
101
+ if (!(activeItems !== null && activeItems !== void 0 && activeItems.length) && (prevActiveItems === null || prevActiveItems === void 0 ? void 0 : prevActiveItems.length) > 1) {
102
+ screenReaderMessage = clearFormattingStatus;
103
+ }
104
+ var items = useMemo(function () {
105
+ if (!clearIcon) {
106
+ return dropdownItems;
107
+ }
108
+ return [].concat(_toConsumableArray(dropdownItems), [clearIcon]);
109
+ }, [clearIcon, dropdownItems]);
110
+ var moreFormattingButtonLabel = intl.formatMessage(toolbarMessages.moreFormatting);
111
+ useEffect(function () {
112
+ if (screenReaderMessage) {
113
+ setMessage(screenReaderMessage);
114
+ }
115
+ }, [screenReaderMessage]);
116
+ return (
117
+ // eslint-disable-next-line @atlaskit/design-system/consistent-css-prop-usage
118
+ jsx("span", {
119
+ css: buttonGroupStyle
120
+ }, message && jsx(Announcer, {
121
+ ariaLive: "assertive",
122
+ text: message,
123
+ ariaRelevant: "additions",
124
+ delay: 250
125
+ }), jsx(SingleToolbarButtons, {
126
+ items: singleItems,
127
+ editorView: editorView,
128
+ isReducedSpacing: isReducedSpacing
129
+ }), jsx("span", {
130
+ css: wrapperStyle
131
+ }, isToolbarDisabled ? jsx("div", null, jsx(MoreButton, {
132
+ label: moreFormattingButtonLabel,
133
+ isReducedSpacing: isReducedSpacing,
134
+ isDisabled: true,
135
+ isSelected: false,
136
+ "aria-expanded": undefined,
137
+ "aria-pressed": undefined
138
+ })) : jsx(FormattingTextDropdownMenu, {
139
+ popupsMountPoint: popupsMountPoint,
140
+ popupsBoundariesElement: popupsBoundariesElement,
141
+ popupsScrollableElement: popupsScrollableElement,
142
+ editorView: editorView,
143
+ isReducedSpacing: isReducedSpacing,
144
+ moreButtonLabel: moreFormattingButtonLabel,
145
+ hasFormattingActive: hasFormattingActive,
146
+ items: items
147
+ }), jsx("span", {
148
+ css: separatorStyles
149
+ })))
150
+ );
151
+ };
152
+ var Toolbar = function Toolbar(_ref2) {
153
+ var popupsMountPoint = _ref2.popupsMountPoint,
154
+ popupsScrollableElement = _ref2.popupsScrollableElement,
155
+ toolbarSize = _ref2.toolbarSize,
156
+ isReducedSpacing = _ref2.isReducedSpacing,
157
+ editorView = _ref2.editorView,
158
+ isToolbarDisabled = _ref2.isToolbarDisabled,
159
+ shouldUseResponsiveToolbar = _ref2.shouldUseResponsiveToolbar,
160
+ intl = _ref2.intl,
161
+ editorAnalyticsAPI = _ref2.editorAnalyticsAPI;
162
+ return jsx(ToolbarFormatting, {
163
+ popupsMountPoint: popupsMountPoint,
164
+ popupsScrollableElement: popupsScrollableElement,
165
+ toolbarSize: toolbarSize,
166
+ isReducedSpacing: isReducedSpacing,
167
+ editorView: editorView,
168
+ isToolbarDisabled: isToolbarDisabled,
169
+ shouldUseResponsiveToolbar: shouldUseResponsiveToolbar,
170
+ intl: intl,
171
+ editorAnalyticsAPI: editorAnalyticsAPI
172
+ });
173
+ };
174
+ export default injectIntl(Toolbar);
@@ -0,0 +1,33 @@
1
+ /** @jsx jsx */
2
+ import React from 'react';
3
+ import { jsx } from '@emotion/react';
4
+ import { triggerWrapperStyles } from '@atlaskit/editor-common/styles';
5
+ import { ToolbarButton } from '@atlaskit/editor-common/ui-menu';
6
+ import MoreIcon from '@atlaskit/icon/glyph/editor/more';
7
+ export var MoreButton = /*#__PURE__*/React.memo(function (_ref) {
8
+ var label = _ref.label,
9
+ ariaExpanded = _ref['aria-expanded'],
10
+ isReducedSpacing = _ref.isReducedSpacing,
11
+ isSelected = _ref.isSelected,
12
+ isDisabled = _ref.isDisabled,
13
+ onClick = _ref.onClick,
14
+ onKeyDown = _ref.onKeyDown;
15
+ return jsx(ToolbarButton, {
16
+ disabled: isDisabled,
17
+ selected: isSelected,
18
+ onClick: onClick,
19
+ onKeyDown: onKeyDown,
20
+ spacing: isReducedSpacing ? 'none' : 'default',
21
+ title: label,
22
+ iconBefore:
23
+ // eslint-disable-next-line @atlaskit/design-system/consistent-css-prop-usage
24
+ jsx("div", {
25
+ css: triggerWrapperStyles
26
+ }, jsx(MoreIcon, {
27
+ label: ""
28
+ })),
29
+ "aria-expanded": ariaExpanded,
30
+ "aria-label": label,
31
+ "aria-haspopup": true
32
+ });
33
+ });
@@ -0,0 +1,38 @@
1
+ /** @jsx jsx */
2
+ import React, { useCallback } from 'react';
3
+ import { jsx } from '@emotion/react';
4
+ import { buttonGroupStyle } from '@atlaskit/editor-common/styles';
5
+ import { ToolbarButton } from '@atlaskit/editor-common/ui-menu';
6
+ export var SingleToolbarButtons = /*#__PURE__*/React.memo(function (_ref) {
7
+ var items = _ref.items,
8
+ isReducedSpacing = _ref.isReducedSpacing,
9
+ editorView = _ref.editorView;
10
+ var onClick = useCallback(function (command) {
11
+ return function () {
12
+ command(editorView.state, editorView.dispatch);
13
+ return false;
14
+ };
15
+ }, [editorView.state, editorView.dispatch]);
16
+ return (
17
+ // eslint-disable-next-line @atlaskit/design-system/consistent-css-prop-usage
18
+ jsx("span", {
19
+ css: buttonGroupStyle
20
+ }, items.map(function (item) {
21
+ var _item$ariaLabel;
22
+ return jsx(ToolbarButton, {
23
+ key: item.key,
24
+ testId: "editor-toolbar__".concat(String(item.content)),
25
+ buttonId: item.buttonId,
26
+ spacing: isReducedSpacing ? 'none' : 'default',
27
+ onClick: onClick(item.command),
28
+ selected: item.isActive,
29
+ disabled: item.isDisabled,
30
+ title: item.tooltipElement,
31
+ iconBefore: item.iconElement,
32
+ "aria-pressed": item.isActive,
33
+ "aria-label": (_item$ariaLabel = item['aria-label']) !== null && _item$ariaLabel !== void 0 ? _item$ariaLabel : String(item.content),
34
+ "aria-keyshortcuts": item['aria-keyshortcuts']
35
+ });
36
+ }))
37
+ );
38
+ });
@@ -0,0 +1,10 @@
1
+ export var IconTypes = /*#__PURE__*/function (IconTypes) {
2
+ IconTypes["strong"] = "strong";
3
+ IconTypes["em"] = "em";
4
+ IconTypes["underline"] = "underline";
5
+ IconTypes["strike"] = "strike";
6
+ IconTypes["code"] = "code";
7
+ IconTypes["subscript"] = "subscript";
8
+ IconTypes["superscript"] = "superscript";
9
+ return IconTypes;
10
+ }({});
@@ -0,0 +1,5 @@
1
+ export var cellSelectionNodesBetween = function cellSelectionNodesBetween(selection, doc, f, startPos) {
2
+ selection.forEachCell(function (cell, cellPos) {
3
+ doc.nodesBetween(cellPos, cellPos + cell.nodeSize, f, startPos);
4
+ });
5
+ };
@@ -0,0 +1,75 @@
1
+ import { anyMarkActive } from '@atlaskit/editor-common/mark';
2
+ import { FORMATTING_MARK_TYPES, FORMATTING_NODE_TYPES } from './commands/clear-formatting';
3
+ export var hasCode = function hasCode(state, pos) {
4
+ var code = state.schema.marks.code;
5
+ var node = pos >= 0 && state.doc.nodeAt(pos);
6
+ if (node) {
7
+ return !!node.marks.filter(function (mark) {
8
+ return mark.type === code;
9
+ }).length;
10
+ }
11
+ return false;
12
+ };
13
+
14
+ /**
15
+ * Determine if a mark (with specific attribute values) exists anywhere in the selection.
16
+ */
17
+ export var markActive = function markActive(state, mark) {
18
+ var _state$selection = state.selection,
19
+ from = _state$selection.from,
20
+ to = _state$selection.to,
21
+ empty = _state$selection.empty;
22
+ // When the selection is empty, only the active marks apply.
23
+ if (empty) {
24
+ return !!mark.isInSet(state.tr.storedMarks || state.selection.$from.marks());
25
+ }
26
+ // For a non-collapsed selection, the marks on the nodes matter.
27
+ var found = false;
28
+ state.doc.nodesBetween(from, to, function (node) {
29
+ found = found || mark.isInSet(node.marks);
30
+ });
31
+ return found;
32
+ };
33
+ var blockStylingIsPresent = function blockStylingIsPresent(state) {
34
+ var _state$selection2 = state.selection,
35
+ from = _state$selection2.from,
36
+ to = _state$selection2.to;
37
+ var isBlockStyling = false;
38
+ state.doc.nodesBetween(from, to, function (node) {
39
+ if (FORMATTING_NODE_TYPES.indexOf(node.type.name) !== -1) {
40
+ isBlockStyling = true;
41
+ return false;
42
+ }
43
+ return true;
44
+ });
45
+ return isBlockStyling;
46
+ };
47
+ var marksArePresent = function marksArePresent(state) {
48
+ var activeMarkTypes = FORMATTING_MARK_TYPES.filter(function (mark) {
49
+ if (!!state.schema.marks[mark]) {
50
+ var _state$selection3 = state.selection,
51
+ $from = _state$selection3.$from,
52
+ empty = _state$selection3.empty;
53
+ var marks = state.schema.marks;
54
+ if (empty) {
55
+ return !!marks[mark].isInSet(state.storedMarks || $from.marks());
56
+ }
57
+ return anyMarkActive(state, marks[mark]);
58
+ }
59
+ return false;
60
+ });
61
+ return activeMarkTypes.length > 0;
62
+ };
63
+ export var checkFormattingIsPresent = function checkFormattingIsPresent(state) {
64
+ return marksArePresent(state) || blockStylingIsPresent(state);
65
+ };
66
+ export var compareItemsArrays = function compareItemsArrays(items, prevItems) {
67
+ return items && items.filter(function (item) {
68
+ return !prevItems.includes(item);
69
+ });
70
+ };
71
+ export var isArrayContainsContent = function isArrayContainsContent(items, content) {
72
+ return items.filter(function (item) {
73
+ return item.content === content;
74
+ }).length > 0;
75
+ };
@@ -0,0 +1,5 @@
1
+ {
2
+ "name": "@atlaskit/editor-plugin-text-formatting",
3
+ "version": "0.1.0",
4
+ "sideEffects": false
5
+ }
@@ -0,0 +1,22 @@
1
+ import type { EditorAnalyticsAPI } from '@atlaskit/editor-common/analytics';
2
+ import type { Command, InputMethodBasic } from '@atlaskit/editor-common/types';
3
+ type ToggleMarkCommand = () => Command;
4
+ export type ToggleMarkWithAnalyticsCommand = (analyticsMetadata: {
5
+ inputMethod: InputMethodBasic;
6
+ }) => Command;
7
+ type ToggleMarkWithAnalyticsFactory = (editorAnalyticsAPI: EditorAnalyticsAPI | undefined) => ToggleMarkWithAnalyticsCommand;
8
+ export declare const toggleEm: ToggleMarkCommand;
9
+ export declare const toggleEmWithAnalytics: ToggleMarkWithAnalyticsFactory;
10
+ export declare const toggleStrike: ToggleMarkCommand;
11
+ export declare const toggleStrikeWithAnalytics: ToggleMarkWithAnalyticsFactory;
12
+ export declare const toggleStrong: ToggleMarkCommand;
13
+ export declare const toggleStrongWithAnalytics: ToggleMarkWithAnalyticsFactory;
14
+ export declare const toggleUnderline: ToggleMarkCommand;
15
+ export declare const toggleUnderlineWithAnalytics: ToggleMarkWithAnalyticsFactory;
16
+ export declare const toggleSuperscript: ToggleMarkCommand;
17
+ export declare const toggleSuperscriptWithAnalytics: ToggleMarkWithAnalyticsFactory;
18
+ export declare const toggleSubscript: ToggleMarkCommand;
19
+ export declare const toggleSubscriptWithAnalytics: ToggleMarkWithAnalyticsFactory;
20
+ export declare const toggleCode: ToggleMarkCommand;
21
+ export declare const toggleCodeWithAnalytics: ToggleMarkWithAnalyticsFactory;
22
+ export {};
@@ -0,0 +1,6 @@
1
+ import type { EditorAnalyticsAPI, INPUT_METHOD } from '@atlaskit/editor-common/analytics';
2
+ import type { Command } from '@atlaskit/editor-common/types';
3
+ export declare const FORMATTING_NODE_TYPES: string[];
4
+ export declare const FORMATTING_MARK_TYPES: string[];
5
+ export declare function clearFormattingWithAnalytics(inputMethod: INPUT_METHOD.TOOLBAR | INPUT_METHOD.SHORTCUT, editorAnalyticsAPI: EditorAnalyticsAPI | undefined): Command;
6
+ export declare function clearFormatting(inputMethod?: INPUT_METHOD.TOOLBAR | INPUT_METHOD.SHORTCUT, editorAnalyticsAPI?: EditorAnalyticsAPI | undefined): Command;
@@ -0,0 +1,5 @@
1
+ import type { EditorAnalyticsAPI } from '@atlaskit/editor-common/analytics';
2
+ import type { Command } from '@atlaskit/editor-common/types';
3
+ export declare const moveRight: () => Command;
4
+ export declare const moveLeft: () => Command;
5
+ export declare const createInlineCodeFromTextInputWithAnalytics: (editorAnalyticsAPI: EditorAnalyticsAPI | undefined) => (from: number, to: number, text: string) => Command;
@@ -0,0 +1,2 @@
1
+ import type { Transaction } from '@atlaskit/editor-prosemirror/state';
2
+ export declare const transformSmartCharsMentionsAndEmojis: (from: number, to: number, tr: Transaction) => void;
@@ -0,0 +1,3 @@
1
+ export { textFormattingPlugin } from './plugin';
2
+ export type { TextFormattingPlugin } from './plugin';
3
+ export type { ToggleMarkWithAnalyticsCommand } from './actions';
@@ -0,0 +1,17 @@
1
+ import type { NextEditorPlugin, OptionalPlugin, TextFormattingOptions } from '@atlaskit/editor-common/types';
2
+ import type { analyticsPlugin } from '@atlaskit/editor-plugin-analytics';
3
+ import type { ToggleMarkWithAnalyticsCommand } from './actions';
4
+ export type TextFormattingPlugin = NextEditorPlugin<'textFormatting', {
5
+ pluginConfiguration: TextFormattingOptions | undefined;
6
+ dependencies: [OptionalPlugin<typeof analyticsPlugin>];
7
+ actions: {
8
+ toggleSuperscript: ToggleMarkWithAnalyticsCommand;
9
+ toggleSubscript: ToggleMarkWithAnalyticsCommand;
10
+ toggleStrike: ToggleMarkWithAnalyticsCommand;
11
+ toggleCode: ToggleMarkWithAnalyticsCommand;
12
+ toggleUnderline: ToggleMarkWithAnalyticsCommand;
13
+ toggleEm: ToggleMarkWithAnalyticsCommand;
14
+ toggleStrong: ToggleMarkWithAnalyticsCommand;
15
+ };
16
+ }>;
17
+ export declare const textFormattingPlugin: TextFormattingPlugin;
@@ -0,0 +1,4 @@
1
+ import type { EditorAnalyticsAPI } from '@atlaskit/editor-common/analytics';
2
+ import type { SafePlugin } from '@atlaskit/editor-common/safe-plugin';
3
+ export declare function keymapPlugin(editorAnalyticsAPI: EditorAnalyticsAPI | undefined): SafePlugin;
4
+ export default keymapPlugin;
@@ -0,0 +1,8 @@
1
+ import type { Dispatch } from '@atlaskit/editor-common/event-dispatcher';
2
+ import { SafePlugin } from '@atlaskit/editor-common/safe-plugin';
3
+ import { PluginKey } from '@atlaskit/editor-prosemirror/state';
4
+ export interface ClearFormattingState {
5
+ formattingIsPresent?: boolean;
6
+ }
7
+ export declare const pluginKey: PluginKey<ClearFormattingState>;
8
+ export declare const plugin: (dispatch: Dispatch) => SafePlugin<ClearFormattingState>;
@@ -0,0 +1,3 @@
1
+ import { SafePlugin } from '@atlaskit/editor-common/safe-plugin';
2
+ declare const _default: SafePlugin<any>;
3
+ export default _default;
@@ -0,0 +1,23 @@
1
+ import type { EditorAnalyticsAPI } from '@atlaskit/editor-common/analytics';
2
+ import type { SafePlugin } from '@atlaskit/editor-common/safe-plugin';
3
+ import type { Schema } from '@atlaskit/editor-prosemirror/model';
4
+ declare enum ValidAutoformatChars {
5
+ STRONG = "__",
6
+ STRIKE = "~~",
7
+ STRONG_MARKDOWN = "**",
8
+ ITALIC_MARKDOWN = "*",
9
+ ITALIC = "_",
10
+ CODE = "`"
11
+ }
12
+ export declare const ValidCombinations: Record<ValidAutoformatChars, string[]>;
13
+ declare class ReverseRegexExp extends RegExp {
14
+ exec(str: string): RegExpExecArray | null;
15
+ }
16
+ export declare const strongRegex1: ReverseRegexExp;
17
+ export declare const strongRegex2: ReverseRegexExp;
18
+ export declare const italicRegex1: ReverseRegexExp;
19
+ export declare const italicRegex2: ReverseRegexExp;
20
+ export declare const strikeRegex: ReverseRegexExp;
21
+ export declare const codeRegex: ReverseRegexExp;
22
+ export declare function inputRulePlugin(schema: Schema, editorAnalyticsAPI: EditorAnalyticsAPI | undefined): SafePlugin | undefined;
23
+ export default inputRulePlugin;
@@ -0,0 +1,4 @@
1
+ import type { EditorAnalyticsAPI } from '@atlaskit/editor-common/analytics';
2
+ import type { SafePlugin } from '@atlaskit/editor-common/safe-plugin';
3
+ import type { Schema } from '@atlaskit/editor-prosemirror/model';
4
+ export default function keymapPlugin(schema: Schema, editorAnalyticsAPI: EditorAnalyticsAPI | undefined): SafePlugin;
@@ -0,0 +1,7 @@
1
+ import type { EditorAnalyticsAPI } from '@atlaskit/editor-common/analytics';
2
+ import type { Dispatch } from '@atlaskit/editor-common/event-dispatcher';
3
+ import { SafePlugin } from '@atlaskit/editor-common/safe-plugin';
4
+ import type { TextFormattingState } from '@atlaskit/editor-common/types';
5
+ import { pluginKey } from './plugin-key';
6
+ export { pluginKey };
7
+ export declare const plugin: (dispatch: Dispatch, editorAnalyticsAPI: EditorAnalyticsAPI | undefined) => SafePlugin<TextFormattingState>;
@@ -0,0 +1,3 @@
1
+ import type { TextFormattingState } from '@atlaskit/editor-common/types';
2
+ import { PluginKey } from '@atlaskit/editor-prosemirror/state';
3
+ export declare const pluginKey: PluginKey<TextFormattingState>;
@@ -0,0 +1,3 @@
1
+ import type { EditorAnalyticsAPI } from '@atlaskit/editor-common/analytics';
2
+ declare const _default: (editorAnalyticsAPI: EditorAnalyticsAPI | undefined) => import("@atlaskit/editor-common/safe-plugin").SafePlugin<any>;
3
+ export default _default;
@@ -0,0 +1,6 @@
1
+ import { ToolbarSize } from '@atlaskit/editor-common/types';
2
+ import { IconTypes } from './types';
3
+ export declare const DefaultButtonsToolbar: IconTypes[];
4
+ export declare const DefaultButtonsMenu: IconTypes[];
5
+ export declare const ResponsiveCustomButtonToolbar: Record<ToolbarSize, IconTypes[]>;
6
+ export declare const ResponsiveCustomMenu: Record<ToolbarSize, IconTypes[]>;
@@ -0,0 +1,15 @@
1
+ import React from 'react';
2
+ import type { EditorView } from '@atlaskit/editor-prosemirror/view';
3
+ import type { MenuIconItem } from './types';
4
+ type DropdownMenuProps = {
5
+ editorView: EditorView;
6
+ isReducedSpacing: boolean;
7
+ items: Array<MenuIconItem>;
8
+ moreButtonLabel: string;
9
+ hasFormattingActive: boolean;
10
+ popupsBoundariesElement?: HTMLElement;
11
+ popupsMountPoint?: HTMLElement;
12
+ popupsScrollableElement?: HTMLElement;
13
+ };
14
+ export declare const FormattingTextDropdownMenu: React.MemoExoticComponent<({ editorView, moreButtonLabel, isReducedSpacing, items, hasFormattingActive, popupsBoundariesElement, popupsMountPoint, popupsScrollableElement, }: DropdownMenuProps) => JSX.Element>;
15
+ export {};
@@ -0,0 +1,7 @@
1
+ import type { EditorAnalyticsAPI } from '@atlaskit/editor-common/analytics';
2
+ import type { IconHookProps, MenuIconItem } from '../types';
3
+ interface ClearIconHookProps extends IconHookProps {
4
+ editorAnalyticsAPI: EditorAnalyticsAPI | undefined;
5
+ }
6
+ export declare const useClearIcon: ({ intl, editorState, editorAnalyticsAPI, }: ClearIconHookProps) => MenuIconItem | null;
7
+ export {};
@@ -0,0 +1,14 @@
1
+ import type { EditorAnalyticsAPI } from '@atlaskit/editor-common/analytics';
2
+ import type { EditorState } from '@atlaskit/editor-prosemirror/state';
3
+ import type { IconHookProps, MenuIconItem } from '../types';
4
+ import { IconTypes } from '../types';
5
+ interface FormattingIconHookProps extends IconHookProps {
6
+ editorAnalyticsAPI: EditorAnalyticsAPI | undefined;
7
+ }
8
+ export declare const useFormattingIcons: ({ isToolbarDisabled, editorState, intl, editorAnalyticsAPI, }: FormattingIconHookProps) => Array<MenuIconItem | null>;
9
+ type Props = {
10
+ editorState: EditorState;
11
+ iconTypeList: IconTypes[];
12
+ };
13
+ export declare const useHasFormattingActived: ({ editorState, iconTypeList, }: Props) => boolean;
14
+ export {};
@@ -0,0 +1 @@
1
+ export declare const useMenuState: () => readonly [boolean, () => void, () => void];
@@ -0,0 +1,20 @@
1
+ import type { ToolbarSize } from '@atlaskit/editor-common/types';
2
+ import type { MenuIconItem } from '../types';
3
+ export declare const useResponsiveIconTypeButtons: ({ toolbarSize, responsivenessEnabled, }: {
4
+ toolbarSize: ToolbarSize;
5
+ responsivenessEnabled: boolean;
6
+ }) => import("../types").IconTypes[];
7
+ export declare const useResponsiveIconTypeMenu: ({ toolbarSize, responsivenessEnabled, }: {
8
+ toolbarSize: ToolbarSize;
9
+ responsivenessEnabled: boolean;
10
+ }) => import("../types").IconTypes[];
11
+ type IconsPositions = {
12
+ dropdownItems: Array<MenuIconItem>;
13
+ singleItems: Array<MenuIconItem>;
14
+ };
15
+ export declare const useResponsiveToolbarButtons: ({ icons, toolbarSize, responsivenessEnabled, }: {
16
+ responsivenessEnabled: boolean;
17
+ toolbarSize: ToolbarSize;
18
+ icons: Array<MenuIconItem | null>;
19
+ }) => IconsPositions;
20
+ export {};
@@ -0,0 +1,25 @@
1
+ /// <reference types="react" />
2
+ import type { WrappedComponentProps } from 'react-intl-next';
3
+ import type { EditorAnalyticsAPI } from '@atlaskit/editor-common/analytics';
4
+ import type { ToolbarSize } from '@atlaskit/editor-common/types';
5
+ import type { EditorState } from '@atlaskit/editor-prosemirror/state';
6
+ import type { EditorView } from '@atlaskit/editor-prosemirror/view';
7
+ export type ToolbarFormattingProps = {
8
+ editorView: EditorView;
9
+ isToolbarDisabled: boolean;
10
+ toolbarSize: ToolbarSize;
11
+ isReducedSpacing: boolean;
12
+ shouldUseResponsiveToolbar: boolean;
13
+ popupsMountPoint?: HTMLElement;
14
+ popupsBoundariesElement?: HTMLElement;
15
+ popupsScrollableElement?: HTMLElement;
16
+ editorAnalyticsAPI?: EditorAnalyticsAPI;
17
+ };
18
+ declare const _default: import("react").FC<import("react-intl-next").WithIntlProps<ToolbarFormattingProps & WrappedComponentProps<"intl"> & {
19
+ editorState: EditorState;
20
+ }>> & {
21
+ WrappedComponent: import("react").ComponentType<ToolbarFormattingProps & WrappedComponentProps<"intl"> & {
22
+ editorState: EditorState;
23
+ }>;
24
+ };
25
+ export default _default;
@@ -0,0 +1,14 @@
1
+ /** @jsx jsx */
2
+ import React from 'react';
3
+ import { jsx } from '@emotion/react';
4
+ type MoreButtonProps = {
5
+ label: string;
6
+ isReducedSpacing: boolean;
7
+ isSelected: boolean;
8
+ isDisabled: boolean;
9
+ 'aria-expanded': React.AriaAttributes['aria-expanded'];
10
+ onClick?: (event: React.MouseEvent<HTMLElement>) => void;
11
+ onKeyDown?: (event: React.KeyboardEvent) => void;
12
+ };
13
+ export declare const MoreButton: React.MemoExoticComponent<({ label, "aria-expanded": ariaExpanded, isReducedSpacing, isSelected, isDisabled, onClick, onKeyDown, }: MoreButtonProps) => jsx.JSX.Element>;
14
+ export {};