@atlaskit/editor-plugin-block-type 1.0.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 (120) hide show
  1. package/.eslintrc.js +14 -0
  2. package/CHANGELOG.md +1 -0
  3. package/LICENSE.md +13 -0
  4. package/README.md +32 -0
  5. package/consts/package.json +15 -0
  6. package/dist/cjs/consts.js +66 -0
  7. package/dist/cjs/index.js +12 -0
  8. package/dist/cjs/messages.js +19 -0
  9. package/dist/cjs/plugin/block-types.js +106 -0
  10. package/dist/cjs/plugin/commands/block-type.js +183 -0
  11. package/dist/cjs/plugin/commands/delete-and-move-cursor.js +56 -0
  12. package/dist/cjs/plugin/commands/delete-block-content.js +45 -0
  13. package/dist/cjs/plugin/commands/index.js +69 -0
  14. package/dist/cjs/plugin/consts.js +15 -0
  15. package/dist/cjs/plugin/index.js +217 -0
  16. package/dist/cjs/plugin/messages.js +160 -0
  17. package/dist/cjs/plugin/pm-plugins/input-rule.js +104 -0
  18. package/dist/cjs/plugin/pm-plugins/keymap.js +34 -0
  19. package/dist/cjs/plugin/pm-plugins/main.js +151 -0
  20. package/dist/cjs/plugin/styles.js +15 -0
  21. package/dist/cjs/plugin/types.js +5 -0
  22. package/dist/cjs/plugin/ui/ToolbarBlockType/blocktype-button.js +60 -0
  23. package/dist/cjs/plugin/ui/ToolbarBlockType/index.js +208 -0
  24. package/dist/cjs/plugin/ui/ToolbarBlockType/styled.js +34 -0
  25. package/dist/cjs/plugin/ui/ToolbarBlockType/toolbar-messages.js +15 -0
  26. package/dist/cjs/plugin/utils.js +87 -0
  27. package/dist/cjs/styles.js +12 -0
  28. package/dist/es2019/consts.js +1 -0
  29. package/dist/es2019/index.js +1 -0
  30. package/dist/es2019/messages.js +2 -0
  31. package/dist/es2019/plugin/block-types.js +84 -0
  32. package/dist/es2019/plugin/commands/block-type.js +170 -0
  33. package/dist/es2019/plugin/commands/delete-and-move-cursor.js +55 -0
  34. package/dist/es2019/plugin/commands/delete-block-content.js +42 -0
  35. package/dist/es2019/plugin/commands/index.js +8 -0
  36. package/dist/es2019/plugin/consts.js +8 -0
  37. package/dist/es2019/plugin/index.js +204 -0
  38. package/dist/es2019/plugin/messages.js +153 -0
  39. package/dist/es2019/plugin/pm-plugins/input-rule.js +93 -0
  40. package/dist/es2019/plugin/pm-plugins/keymap.js +25 -0
  41. package/dist/es2019/plugin/pm-plugins/main.js +137 -0
  42. package/dist/es2019/plugin/styles.js +8 -0
  43. package/dist/es2019/plugin/types.js +1 -0
  44. package/dist/es2019/plugin/ui/ToolbarBlockType/blocktype-button.js +50 -0
  45. package/dist/es2019/plugin/ui/ToolbarBlockType/index.js +185 -0
  46. package/dist/es2019/plugin/ui/ToolbarBlockType/styled.js +49 -0
  47. package/dist/es2019/plugin/ui/ToolbarBlockType/toolbar-messages.js +8 -0
  48. package/dist/es2019/plugin/utils.js +76 -0
  49. package/dist/es2019/styles.js +1 -0
  50. package/dist/esm/consts.js +1 -0
  51. package/dist/esm/index.js +1 -0
  52. package/dist/esm/messages.js +2 -0
  53. package/dist/esm/plugin/block-types.js +84 -0
  54. package/dist/esm/plugin/commands/block-type.js +169 -0
  55. package/dist/esm/plugin/commands/delete-and-move-cursor.js +50 -0
  56. package/dist/esm/plugin/commands/delete-block-content.js +39 -0
  57. package/dist/esm/plugin/commands/index.js +8 -0
  58. package/dist/esm/plugin/consts.js +8 -0
  59. package/dist/esm/plugin/index.js +205 -0
  60. package/dist/esm/plugin/messages.js +153 -0
  61. package/dist/esm/plugin/pm-plugins/input-rule.js +96 -0
  62. package/dist/esm/plugin/pm-plugins/keymap.js +25 -0
  63. package/dist/esm/plugin/pm-plugins/main.js +142 -0
  64. package/dist/esm/plugin/styles.js +7 -0
  65. package/dist/esm/plugin/types.js +1 -0
  66. package/dist/esm/plugin/ui/ToolbarBlockType/blocktype-button.js +50 -0
  67. package/dist/esm/plugin/ui/ToolbarBlockType/index.js +201 -0
  68. package/dist/esm/plugin/ui/ToolbarBlockType/styled.js +20 -0
  69. package/dist/esm/plugin/ui/ToolbarBlockType/toolbar-messages.js +8 -0
  70. package/dist/esm/plugin/utils.js +77 -0
  71. package/dist/esm/styles.js +1 -0
  72. package/dist/types/consts.d.ts +1 -0
  73. package/dist/types/index.d.ts +6 -0
  74. package/dist/types/messages.d.ts +2 -0
  75. package/dist/types/plugin/block-types.d.ts +19 -0
  76. package/dist/types/plugin/commands/block-type.d.ts +18 -0
  77. package/dist/types/plugin/commands/delete-and-move-cursor.d.ts +12 -0
  78. package/dist/types/plugin/commands/delete-block-content.d.ts +10 -0
  79. package/dist/types/plugin/commands/index.d.ts +9 -0
  80. package/dist/types/plugin/consts.d.ts +1 -0
  81. package/dist/types/plugin/index.d.ts +18 -0
  82. package/dist/types/plugin/messages.d.ts +152 -0
  83. package/dist/types/plugin/pm-plugins/input-rule.d.ts +6 -0
  84. package/dist/types/plugin/pm-plugins/keymap.d.ts +5 -0
  85. package/dist/types/plugin/pm-plugins/main.d.ts +17 -0
  86. package/dist/types/plugin/styles.d.ts +2 -0
  87. package/dist/types/plugin/types.d.ts +22 -0
  88. package/dist/types/plugin/ui/ToolbarBlockType/blocktype-button.d.ts +22 -0
  89. package/dist/types/plugin/ui/ToolbarBlockType/index.d.ts +29 -0
  90. package/dist/types/plugin/ui/ToolbarBlockType/styled.d.ts +8 -0
  91. package/dist/types/plugin/ui/ToolbarBlockType/toolbar-messages.d.ts +7 -0
  92. package/dist/types/plugin/utils.d.ts +16 -0
  93. package/dist/types/styles.d.ts +1 -0
  94. package/dist/types-ts4.5/consts.d.ts +1 -0
  95. package/dist/types-ts4.5/index.d.ts +6 -0
  96. package/dist/types-ts4.5/messages.d.ts +2 -0
  97. package/dist/types-ts4.5/plugin/block-types.d.ts +19 -0
  98. package/dist/types-ts4.5/plugin/commands/block-type.d.ts +18 -0
  99. package/dist/types-ts4.5/plugin/commands/delete-and-move-cursor.d.ts +12 -0
  100. package/dist/types-ts4.5/plugin/commands/delete-block-content.d.ts +10 -0
  101. package/dist/types-ts4.5/plugin/commands/index.d.ts +9 -0
  102. package/dist/types-ts4.5/plugin/consts.d.ts +1 -0
  103. package/dist/types-ts4.5/plugin/index.d.ts +20 -0
  104. package/dist/types-ts4.5/plugin/messages.d.ts +152 -0
  105. package/dist/types-ts4.5/plugin/pm-plugins/input-rule.d.ts +6 -0
  106. package/dist/types-ts4.5/plugin/pm-plugins/keymap.d.ts +5 -0
  107. package/dist/types-ts4.5/plugin/pm-plugins/main.d.ts +17 -0
  108. package/dist/types-ts4.5/plugin/styles.d.ts +2 -0
  109. package/dist/types-ts4.5/plugin/types.d.ts +22 -0
  110. package/dist/types-ts4.5/plugin/ui/ToolbarBlockType/blocktype-button.d.ts +22 -0
  111. package/dist/types-ts4.5/plugin/ui/ToolbarBlockType/index.d.ts +29 -0
  112. package/dist/types-ts4.5/plugin/ui/ToolbarBlockType/styled.d.ts +8 -0
  113. package/dist/types-ts4.5/plugin/ui/ToolbarBlockType/toolbar-messages.d.ts +7 -0
  114. package/dist/types-ts4.5/plugin/utils.d.ts +16 -0
  115. package/dist/types-ts4.5/styles.d.ts +1 -0
  116. package/messages/package.json +15 -0
  117. package/package.json +105 -0
  118. package/report.api.md +108 -0
  119. package/styles/package.json +15 -0
  120. package/tmp/api-report-tmp.d.ts +75 -0
@@ -0,0 +1,201 @@
1
+ import _classCallCheck from "@babel/runtime/helpers/classCallCheck";
2
+ import _createClass from "@babel/runtime/helpers/createClass";
3
+ import _assertThisInitialized from "@babel/runtime/helpers/assertThisInitialized";
4
+ import _inherits from "@babel/runtime/helpers/inherits";
5
+ import _possibleConstructorReturn from "@babel/runtime/helpers/possibleConstructorReturn";
6
+ import _getPrototypeOf from "@babel/runtime/helpers/getPrototypeOf";
7
+ import _defineProperty from "@babel/runtime/helpers/defineProperty";
8
+ 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; }
9
+ 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; }
10
+ function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
11
+ function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
12
+ /** @jsx jsx */
13
+ import React from 'react';
14
+ import { jsx } from '@emotion/react';
15
+ import { injectIntl } from 'react-intl-next';
16
+ import { findKeymapByDescription, getAriaKeyshortcuts, tooltip } from '@atlaskit/editor-common/keymaps';
17
+ import { separatorStyles, wrapperStyle } from '@atlaskit/editor-common/styles';
18
+ import { DropdownMenuWithKeyboardNavigation as DropdownMenu } from '@atlaskit/editor-common/ui-menu';
19
+ import { akEditorMenuZIndex } from '@atlaskit/editor-shared-styles';
20
+ import { BlockTypeButton } from './blocktype-button';
21
+ import { blockTypeMenuItemStyle, keyboardShortcut, keyboardShortcutSelect } from './styled';
22
+ // eslint-disable-next-line @repo/internal/react/no-class-components
23
+ var ToolbarBlockType = /*#__PURE__*/function (_React$PureComponent) {
24
+ _inherits(ToolbarBlockType, _React$PureComponent);
25
+ var _super = _createSuper(ToolbarBlockType);
26
+ function ToolbarBlockType() {
27
+ var _this;
28
+ _classCallCheck(this, ToolbarBlockType);
29
+ for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
30
+ args[_key] = arguments[_key];
31
+ }
32
+ _this = _super.call.apply(_super, [this].concat(args));
33
+ _defineProperty(_assertThisInitialized(_this), "state", {
34
+ active: false,
35
+ isOpenedByKeyboard: false
36
+ });
37
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
38
+ _defineProperty(_assertThisInitialized(_this), "onOpenChange", function (attrs) {
39
+ _this.setState(_objectSpread(_objectSpread({}, _this.state), {}, {
40
+ active: attrs.isOpen,
41
+ isOpenedByKeyboard: attrs.isOpenedByKeyboard
42
+ }));
43
+ });
44
+ _defineProperty(_assertThisInitialized(_this), "handleTriggerClick", function () {
45
+ _this.onOpenChange({
46
+ isOpen: !_this.state.active,
47
+ isOpenedByKeyboard: false
48
+ });
49
+ });
50
+ _defineProperty(_assertThisInitialized(_this), "handleTriggerByKeyboard", function (event) {
51
+ if (event.key === 'Enter' || event.key === ' ') {
52
+ event.preventDefault();
53
+ _this.onOpenChange({
54
+ isOpen: !_this.state.active,
55
+ isOpenedByKeyboard: true
56
+ });
57
+ }
58
+ });
59
+ _defineProperty(_assertThisInitialized(_this), "createItems", function () {
60
+ var formatMessage = _this.props.intl.formatMessage;
61
+ var _this$props$pluginSta = _this.props.pluginState,
62
+ currentBlockType = _this$props$pluginSta.currentBlockType,
63
+ availableBlockTypes = _this$props$pluginSta.availableBlockTypes;
64
+ var items = availableBlockTypes.map(function (blockType, index) {
65
+ var isActive = currentBlockType === blockType;
66
+ var tagName = blockType.tagName || 'p';
67
+ var Tag = tagName;
68
+ var keyMap = findKeymapByDescription(blockType.title.defaultMessage);
69
+ return {
70
+ content:
71
+ // eslint-disable-next-line @atlaskit/design-system/consistent-css-prop-usage
72
+ jsx("div", {
73
+ css: blockTypeMenuItemStyle(tagName, isActive)
74
+ }, jsx(Tag, null, formatMessage(blockType.title))),
75
+ value: blockType,
76
+ label: formatMessage(blockType.title),
77
+ 'aria-label': tooltip(keyMap, formatMessage(blockType.title)),
78
+ keyShortcuts: getAriaKeyshortcuts(keyMap),
79
+ key: "".concat(blockType.name, "-").concat(index),
80
+ elemAfter:
81
+ // eslint-disable-next-line @atlaskit/design-system/consistent-css-prop-usage
82
+ jsx("div", {
83
+ css: [keyboardShortcut, isActive && keyboardShortcutSelect]
84
+ }, tooltip(keyMap)),
85
+ isActive: isActive
86
+ };
87
+ });
88
+ return [{
89
+ items: items
90
+ }];
91
+ });
92
+ _defineProperty(_assertThisInitialized(_this), "handleSelectBlockType", function (_ref) {
93
+ var item = _ref.item,
94
+ _ref$shouldCloseMenu = _ref.shouldCloseMenu,
95
+ shouldCloseMenu = _ref$shouldCloseMenu === void 0 ? true : _ref$shouldCloseMenu;
96
+ var blockType = item.value;
97
+ _this.props.setBlockType(blockType.name);
98
+ if (shouldCloseMenu) {
99
+ _this.setState(_objectSpread(_objectSpread({}, _this.state), {}, {
100
+ active: false
101
+ }));
102
+ }
103
+ });
104
+ return _this;
105
+ }
106
+ _createClass(ToolbarBlockType, [{
107
+ key: "render",
108
+ value: function render() {
109
+ var _this2 = this;
110
+ var _this$state = this.state,
111
+ active = _this$state.active,
112
+ isOpenedByKeyboard = _this$state.isOpenedByKeyboard;
113
+ var _this$props = this.props,
114
+ popupsMountPoint = _this$props.popupsMountPoint,
115
+ popupsBoundariesElement = _this$props.popupsBoundariesElement,
116
+ popupsScrollableElement = _this$props.popupsScrollableElement,
117
+ isSmall = _this$props.isSmall,
118
+ isReducedSpacing = _this$props.isReducedSpacing,
119
+ _this$props$pluginSta2 = _this$props.pluginState,
120
+ currentBlockType = _this$props$pluginSta2.currentBlockType,
121
+ blockTypesDisabled = _this$props$pluginSta2.blockTypesDisabled,
122
+ availableBlockTypes = _this$props$pluginSta2.availableBlockTypes,
123
+ formatMessage = _this$props.intl.formatMessage;
124
+ var isHeadingDisabled = !availableBlockTypes.some(function (blockType) {
125
+ return blockType.nodeName === 'heading';
126
+ });
127
+ if (isHeadingDisabled) {
128
+ return null;
129
+ }
130
+ var blockTypeTitles = availableBlockTypes.filter(function (blockType) {
131
+ return blockType.name === currentBlockType.name;
132
+ }).map(function (blockType) {
133
+ return blockType.title;
134
+ });
135
+ if (!this.props.isDisabled && !blockTypesDisabled) {
136
+ var items = this.createItems();
137
+ return (
138
+ // eslint-disable-next-line @atlaskit/design-system/consistent-css-prop-usage
139
+ jsx("span", {
140
+ css: wrapperStyle
141
+ }, jsx(DropdownMenu, {
142
+ items: items,
143
+ onOpenChange: this.onOpenChange,
144
+ onItemActivated: this.handleSelectBlockType,
145
+ isOpen: active,
146
+ mountTo: popupsMountPoint,
147
+ boundariesElement: popupsBoundariesElement,
148
+ scrollableElement: popupsScrollableElement,
149
+ zIndex: akEditorMenuZIndex,
150
+ fitHeight: 360,
151
+ fitWidth: 106,
152
+ shouldUseDefaultRole: true,
153
+ shouldFocusFirstItem: function shouldFocusFirstItem() {
154
+ if (isOpenedByKeyboard) {
155
+ // eslint-disable-next-line @repo/internal/react/no-set-state-inside-render
156
+ _this2.setState(_objectSpread(_objectSpread({}, _this2.state), {}, {
157
+ isOpenedByKeyboard: false
158
+ }));
159
+ }
160
+ return isOpenedByKeyboard;
161
+ }
162
+ }, jsx(BlockTypeButton, {
163
+ isSmall: isSmall,
164
+ isReducedSpacing: isReducedSpacing,
165
+ selected: active,
166
+ disabled: false,
167
+ title: blockTypeTitles[0],
168
+ onClick: this.handleTriggerClick,
169
+ onKeyDown: this.handleTriggerByKeyboard,
170
+ formatMessage: formatMessage,
171
+ "aria-expanded": active
172
+ })), jsx("span", {
173
+ // eslint-disable-next-line @atlaskit/design-system/consistent-css-prop-usage
174
+ css: separatorStyles
175
+ }))
176
+ );
177
+ }
178
+ return (
179
+ // eslint-disable-next-line @atlaskit/design-system/consistent-css-prop-usage
180
+ jsx("span", {
181
+ css: wrapperStyle
182
+ }, jsx(BlockTypeButton, {
183
+ isSmall: isSmall,
184
+ isReducedSpacing: isReducedSpacing,
185
+ selected: active,
186
+ disabled: true,
187
+ title: blockTypeTitles[0],
188
+ onClick: this.handleTriggerClick,
189
+ onKeyDown: this.handleTriggerByKeyboard,
190
+ formatMessage: formatMessage,
191
+ "aria-expanded": active
192
+ }), jsx("span", {
193
+ // eslint-disable-next-line @atlaskit/design-system/consistent-css-prop-usage
194
+ css: separatorStyles
195
+ }))
196
+ );
197
+ }
198
+ }]);
199
+ return ToolbarBlockType;
200
+ }(React.PureComponent);
201
+ export default injectIntl(ToolbarBlockType);
@@ -0,0 +1,20 @@
1
+ import _taggedTemplateLiteral from "@babel/runtime/helpers/taggedTemplateLiteral";
2
+ var _templateObject, _templateObject2, _templateObject3, _templateObject4, _templateObject5, _templateObject6, _templateObject7;
3
+ /** @jsx jsx */
4
+ import { css } from '@emotion/react';
5
+ import { headingsSharedStyles } from '@atlaskit/editor-common/styles';
6
+ import { shortcutStyle } from '@atlaskit/editor-shared-styles/shortcut';
7
+ import { N400 } from '@atlaskit/theme/colors';
8
+ export var blockTypeMenuItemStyle = function blockTypeMenuItemStyle(tagName, selected) {
9
+ // TEMP FIX: See https://product-fabric.atlassian.net/browse/ED-13878
10
+ var selectedStyle = selected ? "".concat(tagName, " { color: ", "var(--ds-text, white)", " !important; }") : '';
11
+ return function (themeProps) {
12
+ return css(_templateObject || (_templateObject = _taggedTemplateLiteral(["\n ", ";\n > {\n h1,\n h2,\n h3,\n h4,\n h5,\n h6 {\n margin-top: 0;\n }\n }\n ", ";\n "])), headingsSharedStyles(themeProps), selectedStyle);
13
+ };
14
+ };
15
+ export var keyboardShortcut = css(_templateObject2 || (_templateObject2 = _taggedTemplateLiteral(["\n ", "\n margin-left: ", ";\n"])), shortcutStyle, "var(--ds-space-200, 16px)");
16
+ export var keyboardShortcutSelect = css(_templateObject3 || (_templateObject3 = _taggedTemplateLiteral(["\n color: ", ";\n"])), "var(--ds-icon, ".concat(N400, ")"));
17
+ export var buttonContentStyle = css(_templateObject4 || (_templateObject4 = _taggedTemplateLiteral(["\n display: flex;\n min-width: 80px;\n align-items: center;\n overflow: hidden;\n justify-content: center;\n flex-direction: column;\n padding: ", ";\n"])), "var(--ds-space-075, 6px)");
18
+ export var buttonContentReducedSpacingStyle = css(_templateObject5 || (_templateObject5 = _taggedTemplateLiteral(["\n padding: ", ";\n"])), "var(--ds-space-100, 8px)");
19
+ export var wrapperSmallStyle = css(_templateObject6 || (_templateObject6 = _taggedTemplateLiteral(["\n margin-left: ", ";\n min-width: 40px;\n"])), "var(--ds-space-050, 4px)");
20
+ export var expandIconWrapperStyle = css(_templateObject7 || (_templateObject7 = _taggedTemplateLiteral(["\n margin-left: -8px;\n"])));
@@ -0,0 +1,8 @@
1
+ import { defineMessages } from 'react-intl-next';
2
+ export var toolbarMessages = defineMessages({
3
+ textStyles: {
4
+ id: 'fabric.editor.textStyles',
5
+ defaultMessage: 'Text styles',
6
+ description: 'Menu provides access to various heading styles or normal text'
7
+ }
8
+ });
@@ -0,0 +1,77 @@
1
+ import { createWrappingJoinRule } from '@atlaskit/editor-common/utils';
2
+ import { createRule } from '@atlaskit/prosemirror-input-rules';
3
+ import { WRAPPER_BLOCK_TYPES } from './block-types';
4
+ export var isNodeAWrappingBlockNode = function isNodeAWrappingBlockNode(node) {
5
+ if (!node) {
6
+ return false;
7
+ }
8
+ return WRAPPER_BLOCK_TYPES.some(function (blockNode) {
9
+ return blockNode.name === node.type.name;
10
+ });
11
+ };
12
+ export var createJoinNodesRule = function createJoinNodesRule(match, nodeType) {
13
+ return createWrappingJoinRule({
14
+ nodeType: nodeType,
15
+ match: match,
16
+ getAttrs: {},
17
+ joinPredicate: function joinPredicate(_, node) {
18
+ return node.type === nodeType;
19
+ }
20
+ });
21
+ };
22
+ export var createWrappingTextBlockRule = function createWrappingTextBlockRule(_ref) {
23
+ var match = _ref.match,
24
+ nodeType = _ref.nodeType,
25
+ getAttrs = _ref.getAttrs;
26
+ var handler = function handler(state, match, start, end) {
27
+ var fixedStart = Math.max(start, 1);
28
+ var $start = state.doc.resolve(fixedStart);
29
+ var attrs = getAttrs instanceof Function ? getAttrs(match) : getAttrs;
30
+ var nodeBefore = $start.node(-1);
31
+ if (nodeBefore && !nodeBefore.canReplaceWith($start.index(-1), $start.indexAfter(-1), nodeType)) {
32
+ return null;
33
+ }
34
+ return state.tr.delete(fixedStart, end).setBlockType(fixedStart, fixedStart, nodeType, attrs);
35
+ };
36
+ return createRule(match, handler);
37
+ };
38
+
39
+ /**
40
+ * Function will create a list of wrapper blocks present in a selection.
41
+ */
42
+ function getSelectedWrapperNodes(state) {
43
+ var nodes = [];
44
+ if (state.selection) {
45
+ var _state$selection = state.selection,
46
+ $from = _state$selection.$from,
47
+ $to = _state$selection.$to;
48
+ var _state$schema$nodes = state.schema.nodes,
49
+ blockquote = _state$schema$nodes.blockquote,
50
+ panel = _state$schema$nodes.panel,
51
+ orderedList = _state$schema$nodes.orderedList,
52
+ bulletList = _state$schema$nodes.bulletList,
53
+ listItem = _state$schema$nodes.listItem,
54
+ codeBlock = _state$schema$nodes.codeBlock,
55
+ decisionItem = _state$schema$nodes.decisionItem,
56
+ decisionList = _state$schema$nodes.decisionList,
57
+ taskItem = _state$schema$nodes.taskItem,
58
+ taskList = _state$schema$nodes.taskList;
59
+ state.doc.nodesBetween($from.pos, $to.pos, function (node) {
60
+ if (node.isBlock && [blockquote, panel, orderedList, bulletList, listItem, codeBlock, decisionItem, decisionList, taskItem, taskList].indexOf(node.type) >= 0) {
61
+ nodes.push(node.type);
62
+ }
63
+ });
64
+ }
65
+ return nodes;
66
+ }
67
+
68
+ /**
69
+ * Function will check if changing block types: Paragraph, Heading is enabled.
70
+ */
71
+ export function areBlockTypesDisabled(state) {
72
+ var nodesTypes = getSelectedWrapperNodes(state);
73
+ var panel = state.schema.nodes.panel;
74
+ return nodesTypes.filter(function (type) {
75
+ return type !== panel;
76
+ }).length > 0;
77
+ }
@@ -0,0 +1 @@
1
+ export { blocktypeStyles } from './plugin/styles';
@@ -0,0 +1 @@
1
+ export { BLOCK_QUOTE, CODE_BLOCK, HEADING_1, HEADING_2, HEADING_3, HEADING_4, HEADING_5, HEADING_6, NORMAL_TEXT, PANEL, } from './plugin/block-types';
@@ -0,0 +1,6 @@
1
+ export { blockTypePlugin } from './plugin';
2
+ export type { BlockTypePlugin } from './plugin';
3
+ export type { BlockTypePluginOptions, BlockType } from './plugin/types';
4
+ export type { BlockTypeState } from './plugin/pm-plugins/main';
5
+ export type { InputMethod } from './plugin/commands';
6
+ export type { DropdownItem } from './plugin/ui/ToolbarBlockType';
@@ -0,0 +1,2 @@
1
+ export { messages } from './plugin/messages';
2
+ export { toolbarMessages } from './plugin/ui/ToolbarBlockType/toolbar-messages';
@@ -0,0 +1,19 @@
1
+ import type { BlockType } from './types';
2
+ export declare const NORMAL_TEXT: BlockType;
3
+ export declare const HEADING_1: BlockType;
4
+ export declare const HEADING_2: BlockType;
5
+ export declare const HEADING_3: BlockType;
6
+ export declare const HEADING_4: BlockType;
7
+ export declare const HEADING_5: BlockType;
8
+ export declare const HEADING_6: BlockType;
9
+ export declare const BLOCK_QUOTE: BlockType;
10
+ export declare const CODE_BLOCK: BlockType;
11
+ export declare const PANEL: BlockType;
12
+ export declare const OTHER: BlockType;
13
+ export declare const TEXT_BLOCK_TYPES: BlockType[];
14
+ export declare const WRAPPER_BLOCK_TYPES: BlockType[];
15
+ export declare const ALL_BLOCK_TYPES: BlockType[];
16
+ export declare const HEADINGS_BY_LEVEL: Record<number, BlockType>;
17
+ export declare const HEADINGS_BY_NAME: {
18
+ [blockType: string]: BlockType;
19
+ };
@@ -0,0 +1,18 @@
1
+ import type { EditorAnalyticsAPI, INPUT_METHOD } from '@atlaskit/editor-common/analytics';
2
+ import type { Command, HeadingLevelsAndNormalText } from '@atlaskit/editor-common/types';
3
+ export type InputMethod = INPUT_METHOD.TOOLBAR | INPUT_METHOD.INSERT_MENU | INPUT_METHOD.SHORTCUT | INPUT_METHOD.FORMATTING | INPUT_METHOD.KEYBOARD;
4
+ export declare function setBlockType(name: string): Command;
5
+ export declare function setBlockTypeWithAnalytics(name: string, inputMethod: InputMethod, editorAnalyticsApi: EditorAnalyticsAPI | undefined): Command;
6
+ export declare function setNormalText(): Command;
7
+ export declare function setNormalTextWithAnalytics(inputMethod: InputMethod, editorAnalyticsApi: EditorAnalyticsAPI | undefined): Command;
8
+ export declare const setHeadingWithAnalytics: (newHeadingLevel: HeadingLevelsAndNormalText, inputMethod: InputMethod, editorAnalyticsApi: EditorAnalyticsAPI | undefined) => Command;
9
+ /**
10
+ *
11
+ * @param name - block type name
12
+ * @param inputMethod - input method
13
+ * @param editorAnalyticsApi - analytics api, undefined if not available either because it failed to load or wasn't added
14
+ * otherwise Editor becomes very sad and crashes
15
+ * @returns - command that inserts block type
16
+ */
17
+ export declare const insertBlockQuoteWithAnalytics: (inputMethod: InputMethod, editorAnalyticsApi: EditorAnalyticsAPI | undefined) => Command;
18
+ export declare const cleanUpAtTheStartOfDocument: Command;
@@ -0,0 +1,12 @@
1
+ import type { Command } from '@atlaskit/editor-common/types';
2
+ /**
3
+ * Fixes cursor position after delete for list/task in panel and table
4
+ *
5
+ * ED-13873 fixes a bug where after deleting a list the cursor would move
6
+ * to the cell to the right. Uses setSelection to position the cursor as expected after deleting.
7
+ *
8
+ * @param state EditorState
9
+ * @param dispatch CommandDispatch
10
+ * @returns boolean
11
+ */
12
+ export declare const deleteAndMoveCursor: Command;
@@ -0,0 +1,10 @@
1
+ import type { Command } from '@atlaskit/editor-common/types';
2
+ import type { Node as PMNode } from '@atlaskit/editor-prosemirror/model';
3
+ /**
4
+ * Prevent removing the block when deleting block content
5
+ *
6
+ * @param state EditorState
7
+ * @param dispatch CommandDispatch
8
+ * @returns boolean
9
+ */
10
+ export declare function deleteBlockContent(isNodeAWrappingBlockNode: (node?: PMNode | null) => boolean): Command;
@@ -0,0 +1,9 @@
1
+ export { cleanUpAtTheStartOfDocument, insertBlockQuoteWithAnalytics, setBlockType, setBlockTypeWithAnalytics, setHeadingWithAnalytics, setNormalText, setNormalTextWithAnalytics, } from './block-type';
2
+ export type { InputMethod } from './block-type';
3
+ export { deleteAndMoveCursor } from './delete-and-move-cursor';
4
+ export { deleteBlockContent } from './delete-block-content';
5
+ /**
6
+ * @private
7
+ * @deprecated use import from @atlaskit/editor-common/commands
8
+ */
9
+ export { setHeading } from '@atlaskit/editor-common/commands';
@@ -0,0 +1 @@
1
+ export declare const HEADING_KEYS: number[];
@@ -0,0 +1,18 @@
1
+ import type { Command, NextEditorPlugin, OptionalPlugin } from '@atlaskit/editor-common/types';
2
+ import type { analyticsPlugin } from '@atlaskit/editor-plugin-analytics';
3
+ import type { InputMethod } from './commands/block-type';
4
+ import type { BlockTypeState } from './pm-plugins/main';
5
+ import type { BlockTypePluginOptions } from './types';
6
+ export type BlockTypePlugin = NextEditorPlugin<'blockType', {
7
+ pluginConfiguration: BlockTypePluginOptions | undefined;
8
+ dependencies: [OptionalPlugin<typeof analyticsPlugin>];
9
+ sharedState: BlockTypeState | undefined;
10
+ actions: {
11
+ insertBlockQuote: (inputMethod: InputMethod) => Command;
12
+ setBlockType: (name: string, inputMethod: InputMethod) => Command;
13
+ };
14
+ }>;
15
+ declare const blockTypePlugin: BlockTypePlugin;
16
+ export { blockTypePlugin };
17
+ export { pluginKey } from './pm-plugins/main';
18
+ export type { BlockTypeState } from './pm-plugins/main';
@@ -0,0 +1,152 @@
1
+ export declare const messages: {
2
+ normal: {
3
+ id: string;
4
+ defaultMessage: string;
5
+ description: string;
6
+ };
7
+ heading1: {
8
+ id: string;
9
+ defaultMessage: string;
10
+ description: string;
11
+ };
12
+ heading1Description: {
13
+ id: string;
14
+ defaultMessage: string;
15
+ description: string;
16
+ };
17
+ heading2: {
18
+ id: string;
19
+ defaultMessage: string;
20
+ description: string;
21
+ };
22
+ heading2Description: {
23
+ id: string;
24
+ defaultMessage: string;
25
+ description: string;
26
+ };
27
+ heading3: {
28
+ id: string;
29
+ defaultMessage: string;
30
+ description: string;
31
+ };
32
+ heading3Description: {
33
+ id: string;
34
+ defaultMessage: string;
35
+ description: string;
36
+ };
37
+ heading4: {
38
+ id: string;
39
+ defaultMessage: string;
40
+ description: string;
41
+ };
42
+ heading4Description: {
43
+ id: string;
44
+ defaultMessage: string;
45
+ description: string;
46
+ };
47
+ heading5: {
48
+ id: string;
49
+ defaultMessage: string;
50
+ description: string;
51
+ };
52
+ heading5Description: {
53
+ id: string;
54
+ defaultMessage: string;
55
+ description: string;
56
+ };
57
+ heading6: {
58
+ id: string;
59
+ defaultMessage: string;
60
+ description: string;
61
+ };
62
+ heading6Description: {
63
+ id: string;
64
+ defaultMessage: string;
65
+ description: string;
66
+ };
67
+ blockquote: {
68
+ id: string;
69
+ defaultMessage: string;
70
+ description: string;
71
+ };
72
+ blockquoteDescription: {
73
+ id: string;
74
+ defaultMessage: string;
75
+ description: string;
76
+ };
77
+ codeblock: {
78
+ id: string;
79
+ defaultMessage: string;
80
+ description: string;
81
+ };
82
+ codeblockDescription: {
83
+ id: string;
84
+ defaultMessage: string;
85
+ description: string;
86
+ };
87
+ infoPanel: {
88
+ id: string;
89
+ defaultMessage: string;
90
+ description: string;
91
+ };
92
+ infoPanelDescription: {
93
+ id: string;
94
+ defaultMessage: string;
95
+ description: string;
96
+ };
97
+ notePanel: {
98
+ id: string;
99
+ defaultMessage: string;
100
+ description: string;
101
+ };
102
+ notePanelDescription: {
103
+ id: string;
104
+ defaultMessage: string;
105
+ description: string;
106
+ };
107
+ successPanel: {
108
+ id: string;
109
+ defaultMessage: string;
110
+ description: string;
111
+ };
112
+ successPanelDescription: {
113
+ id: string;
114
+ defaultMessage: string;
115
+ description: string;
116
+ };
117
+ warningPanel: {
118
+ id: string;
119
+ defaultMessage: string;
120
+ description: string;
121
+ };
122
+ warningPanelDescription: {
123
+ id: string;
124
+ defaultMessage: string;
125
+ description: string;
126
+ };
127
+ errorPanel: {
128
+ id: string;
129
+ defaultMessage: string;
130
+ description: string;
131
+ };
132
+ errorPanelDescription: {
133
+ id: string;
134
+ defaultMessage: string;
135
+ description: string;
136
+ };
137
+ customPanel: {
138
+ id: string;
139
+ defaultMessage: string;
140
+ description: string;
141
+ };
142
+ customPanelDescription: {
143
+ id: string;
144
+ defaultMessage: string;
145
+ description: string;
146
+ };
147
+ other: {
148
+ id: string;
149
+ defaultMessage: string;
150
+ description: string;
151
+ };
152
+ };
@@ -0,0 +1,6 @@
1
+ import type { EditorAnalyticsAPI } from '@atlaskit/editor-common/analytics';
2
+ import type { SafePlugin } from '@atlaskit/editor-common/safe-plugin';
3
+ import type { FeatureFlags } from '@atlaskit/editor-common/types';
4
+ import type { Schema } from '@atlaskit/editor-prosemirror/model';
5
+ declare function inputRulePlugin(editorAnalyticsAPI: EditorAnalyticsAPI | undefined, schema: Schema, featureFlags: FeatureFlags): SafePlugin | undefined;
6
+ export default inputRulePlugin;
@@ -0,0 +1,5 @@
1
+ import type { EditorAnalyticsAPI } from '@atlaskit/editor-common/analytics';
2
+ import type { SafePlugin } from '@atlaskit/editor-common/safe-plugin';
3
+ import type { FeatureFlags } from '@atlaskit/editor-common/types';
4
+ import type { Schema } from '@atlaskit/editor-prosemirror/model';
5
+ export default function keymapPlugin(editorAnalyticsApi: EditorAnalyticsAPI | undefined, schema: Schema, _featureFlags: FeatureFlags): SafePlugin;
@@ -0,0 +1,17 @@
1
+ import type { EditorAnalyticsAPI } from '@atlaskit/editor-common/analytics';
2
+ import { SafePlugin } from '@atlaskit/editor-common/safe-plugin';
3
+ import { PluginKey } from '@atlaskit/editor-prosemirror/state';
4
+ import type { BlockType } from '../types';
5
+ export type BlockTypeState = {
6
+ currentBlockType: BlockType;
7
+ blockTypesDisabled: boolean;
8
+ availableBlockTypes: BlockType[];
9
+ availableWrapperBlockTypes: BlockType[];
10
+ };
11
+ export declare const pluginKey: PluginKey<BlockTypeState>;
12
+ export declare const createPlugin: (editorAnalyticsApi: EditorAnalyticsAPI | undefined, dispatch: (eventName: string | PluginKey, data: any) => void, lastNodeMustBeParagraph?: boolean) => SafePlugin<{
13
+ currentBlockType: BlockType;
14
+ blockTypesDisabled: boolean;
15
+ availableBlockTypes: BlockType[];
16
+ availableWrapperBlockTypes: BlockType[];
17
+ }>;
@@ -0,0 +1,2 @@
1
+ import type { ThemeProps } from '@atlaskit/theme/types';
2
+ export declare const blocktypeStyles: (props: ThemeProps) => import("@emotion/react").SerializedStyles;
@@ -0,0 +1,22 @@
1
+ import type { MessageDescriptor } from 'react-intl-next';
2
+ import type { AllowedBlockTypes, HeadingLevelsAndNormalText } from '@atlaskit/editor-common/types';
3
+ import type { NodeSpec } from '@atlaskit/editor-prosemirror/model';
4
+ export type BlockTypeName = 'normal' | 'heading1' | 'heading2' | 'heading3' | 'heading4' | 'heading5' | 'heading6' | 'blockquote' | 'codeblock' | 'panel' | 'notePanel' | 'successPanel' | 'warningPanel' | 'errorPanel' | 'other';
5
+ export interface BlockType {
6
+ name: string;
7
+ title: MessageDescriptor;
8
+ nodeName: string;
9
+ tagName?: string;
10
+ level?: HeadingLevelsAndNormalText;
11
+ }
12
+ export interface BlockTypeNode {
13
+ name: AllowedBlockTypes;
14
+ node: NodeSpec;
15
+ }
16
+ export interface BlockTypePluginOptions {
17
+ lastNodeMustBeParagraph?: boolean;
18
+ allowBlockType?: {
19
+ exclude?: Array<AllowedBlockTypes>;
20
+ };
21
+ isUndoRedoButtonsEnabled?: boolean;
22
+ }
@@ -0,0 +1,22 @@
1
+ /** @jsx jsx */
2
+ import React from 'react';
3
+ import type { MessageDescriptor, WrappedComponentProps } from 'react-intl-next';
4
+ export interface BlockTypeButtonProps {
5
+ isSmall?: boolean;
6
+ isReducedSpacing?: boolean;
7
+ 'aria-expanded': React.AriaAttributes['aria-expanded'];
8
+ selected: boolean;
9
+ disabled: boolean;
10
+ title: MessageDescriptor;
11
+ onClick(e: React.MouseEvent): void;
12
+ onKeyDown(e: React.KeyboardEvent): void;
13
+ formatMessage: WrappedComponentProps['intl']['formatMessage'];
14
+ }
15
+ export declare const messages: {
16
+ textStyles: {
17
+ id: string;
18
+ defaultMessage: string;
19
+ description: string;
20
+ };
21
+ };
22
+ export declare const BlockTypeButton: React.StatelessComponent<BlockTypeButtonProps>;