@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.
- package/.eslintrc.js +14 -0
- package/CHANGELOG.md +1 -0
- package/LICENSE.md +13 -0
- package/README.md +32 -0
- package/consts/package.json +15 -0
- package/dist/cjs/consts.js +66 -0
- package/dist/cjs/index.js +12 -0
- package/dist/cjs/messages.js +19 -0
- package/dist/cjs/plugin/block-types.js +106 -0
- package/dist/cjs/plugin/commands/block-type.js +183 -0
- package/dist/cjs/plugin/commands/delete-and-move-cursor.js +56 -0
- package/dist/cjs/plugin/commands/delete-block-content.js +45 -0
- package/dist/cjs/plugin/commands/index.js +69 -0
- package/dist/cjs/plugin/consts.js +15 -0
- package/dist/cjs/plugin/index.js +217 -0
- package/dist/cjs/plugin/messages.js +160 -0
- package/dist/cjs/plugin/pm-plugins/input-rule.js +104 -0
- package/dist/cjs/plugin/pm-plugins/keymap.js +34 -0
- package/dist/cjs/plugin/pm-plugins/main.js +151 -0
- package/dist/cjs/plugin/styles.js +15 -0
- package/dist/cjs/plugin/types.js +5 -0
- package/dist/cjs/plugin/ui/ToolbarBlockType/blocktype-button.js +60 -0
- package/dist/cjs/plugin/ui/ToolbarBlockType/index.js +208 -0
- package/dist/cjs/plugin/ui/ToolbarBlockType/styled.js +34 -0
- package/dist/cjs/plugin/ui/ToolbarBlockType/toolbar-messages.js +15 -0
- package/dist/cjs/plugin/utils.js +87 -0
- package/dist/cjs/styles.js +12 -0
- package/dist/es2019/consts.js +1 -0
- package/dist/es2019/index.js +1 -0
- package/dist/es2019/messages.js +2 -0
- package/dist/es2019/plugin/block-types.js +84 -0
- package/dist/es2019/plugin/commands/block-type.js +170 -0
- package/dist/es2019/plugin/commands/delete-and-move-cursor.js +55 -0
- package/dist/es2019/plugin/commands/delete-block-content.js +42 -0
- package/dist/es2019/plugin/commands/index.js +8 -0
- package/dist/es2019/plugin/consts.js +8 -0
- package/dist/es2019/plugin/index.js +204 -0
- package/dist/es2019/plugin/messages.js +153 -0
- package/dist/es2019/plugin/pm-plugins/input-rule.js +93 -0
- package/dist/es2019/plugin/pm-plugins/keymap.js +25 -0
- package/dist/es2019/plugin/pm-plugins/main.js +137 -0
- package/dist/es2019/plugin/styles.js +8 -0
- package/dist/es2019/plugin/types.js +1 -0
- package/dist/es2019/plugin/ui/ToolbarBlockType/blocktype-button.js +50 -0
- package/dist/es2019/plugin/ui/ToolbarBlockType/index.js +185 -0
- package/dist/es2019/plugin/ui/ToolbarBlockType/styled.js +49 -0
- package/dist/es2019/plugin/ui/ToolbarBlockType/toolbar-messages.js +8 -0
- package/dist/es2019/plugin/utils.js +76 -0
- package/dist/es2019/styles.js +1 -0
- package/dist/esm/consts.js +1 -0
- package/dist/esm/index.js +1 -0
- package/dist/esm/messages.js +2 -0
- package/dist/esm/plugin/block-types.js +84 -0
- package/dist/esm/plugin/commands/block-type.js +169 -0
- package/dist/esm/plugin/commands/delete-and-move-cursor.js +50 -0
- package/dist/esm/plugin/commands/delete-block-content.js +39 -0
- package/dist/esm/plugin/commands/index.js +8 -0
- package/dist/esm/plugin/consts.js +8 -0
- package/dist/esm/plugin/index.js +205 -0
- package/dist/esm/plugin/messages.js +153 -0
- package/dist/esm/plugin/pm-plugins/input-rule.js +96 -0
- package/dist/esm/plugin/pm-plugins/keymap.js +25 -0
- package/dist/esm/plugin/pm-plugins/main.js +142 -0
- package/dist/esm/plugin/styles.js +7 -0
- package/dist/esm/plugin/types.js +1 -0
- package/dist/esm/plugin/ui/ToolbarBlockType/blocktype-button.js +50 -0
- package/dist/esm/plugin/ui/ToolbarBlockType/index.js +201 -0
- package/dist/esm/plugin/ui/ToolbarBlockType/styled.js +20 -0
- package/dist/esm/plugin/ui/ToolbarBlockType/toolbar-messages.js +8 -0
- package/dist/esm/plugin/utils.js +77 -0
- package/dist/esm/styles.js +1 -0
- package/dist/types/consts.d.ts +1 -0
- package/dist/types/index.d.ts +6 -0
- package/dist/types/messages.d.ts +2 -0
- package/dist/types/plugin/block-types.d.ts +19 -0
- package/dist/types/plugin/commands/block-type.d.ts +18 -0
- package/dist/types/plugin/commands/delete-and-move-cursor.d.ts +12 -0
- package/dist/types/plugin/commands/delete-block-content.d.ts +10 -0
- package/dist/types/plugin/commands/index.d.ts +9 -0
- package/dist/types/plugin/consts.d.ts +1 -0
- package/dist/types/plugin/index.d.ts +18 -0
- package/dist/types/plugin/messages.d.ts +152 -0
- package/dist/types/plugin/pm-plugins/input-rule.d.ts +6 -0
- package/dist/types/plugin/pm-plugins/keymap.d.ts +5 -0
- package/dist/types/plugin/pm-plugins/main.d.ts +17 -0
- package/dist/types/plugin/styles.d.ts +2 -0
- package/dist/types/plugin/types.d.ts +22 -0
- package/dist/types/plugin/ui/ToolbarBlockType/blocktype-button.d.ts +22 -0
- package/dist/types/plugin/ui/ToolbarBlockType/index.d.ts +29 -0
- package/dist/types/plugin/ui/ToolbarBlockType/styled.d.ts +8 -0
- package/dist/types/plugin/ui/ToolbarBlockType/toolbar-messages.d.ts +7 -0
- package/dist/types/plugin/utils.d.ts +16 -0
- package/dist/types/styles.d.ts +1 -0
- package/dist/types-ts4.5/consts.d.ts +1 -0
- package/dist/types-ts4.5/index.d.ts +6 -0
- package/dist/types-ts4.5/messages.d.ts +2 -0
- package/dist/types-ts4.5/plugin/block-types.d.ts +19 -0
- package/dist/types-ts4.5/plugin/commands/block-type.d.ts +18 -0
- package/dist/types-ts4.5/plugin/commands/delete-and-move-cursor.d.ts +12 -0
- package/dist/types-ts4.5/plugin/commands/delete-block-content.d.ts +10 -0
- package/dist/types-ts4.5/plugin/commands/index.d.ts +9 -0
- package/dist/types-ts4.5/plugin/consts.d.ts +1 -0
- package/dist/types-ts4.5/plugin/index.d.ts +20 -0
- package/dist/types-ts4.5/plugin/messages.d.ts +152 -0
- package/dist/types-ts4.5/plugin/pm-plugins/input-rule.d.ts +6 -0
- package/dist/types-ts4.5/plugin/pm-plugins/keymap.d.ts +5 -0
- package/dist/types-ts4.5/plugin/pm-plugins/main.d.ts +17 -0
- package/dist/types-ts4.5/plugin/styles.d.ts +2 -0
- package/dist/types-ts4.5/plugin/types.d.ts +22 -0
- package/dist/types-ts4.5/plugin/ui/ToolbarBlockType/blocktype-button.d.ts +22 -0
- package/dist/types-ts4.5/plugin/ui/ToolbarBlockType/index.d.ts +29 -0
- package/dist/types-ts4.5/plugin/ui/ToolbarBlockType/styled.d.ts +8 -0
- package/dist/types-ts4.5/plugin/ui/ToolbarBlockType/toolbar-messages.d.ts +7 -0
- package/dist/types-ts4.5/plugin/utils.d.ts +16 -0
- package/dist/types-ts4.5/styles.d.ts +1 -0
- package/messages/package.json +15 -0
- package/package.json +105 -0
- package/report.api.md +108 -0
- package/styles/package.json +15 -0
- package/tmp/api-report-tmp.d.ts +75 -0
|
@@ -0,0 +1,217 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
+
Object.defineProperty(exports, "__esModule", {
|
|
5
|
+
value: true
|
|
6
|
+
});
|
|
7
|
+
exports.blockTypePlugin = void 0;
|
|
8
|
+
Object.defineProperty(exports, "pluginKey", {
|
|
9
|
+
enumerable: true,
|
|
10
|
+
get: function get() {
|
|
11
|
+
return _main.pluginKey;
|
|
12
|
+
}
|
|
13
|
+
});
|
|
14
|
+
var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray"));
|
|
15
|
+
var _react = _interopRequireDefault(require("react"));
|
|
16
|
+
var _adfSchema = require("@atlaskit/adf-schema");
|
|
17
|
+
var _analytics = require("@atlaskit/editor-common/analytics");
|
|
18
|
+
var _keymaps = require("@atlaskit/editor-common/keymaps");
|
|
19
|
+
var _quickInsert = require("@atlaskit/editor-common/quick-insert");
|
|
20
|
+
var _types = require("@atlaskit/editor-common/types");
|
|
21
|
+
var _withPluginState = require("@atlaskit/editor-common/with-plugin-state");
|
|
22
|
+
var _commands = require("./commands");
|
|
23
|
+
var _blockType = require("./commands/block-type");
|
|
24
|
+
var _messages = require("./messages");
|
|
25
|
+
var _inputRule = _interopRequireDefault(require("./pm-plugins/input-rule"));
|
|
26
|
+
var _keymap = _interopRequireDefault(require("./pm-plugins/keymap"));
|
|
27
|
+
var _main = require("./pm-plugins/main");
|
|
28
|
+
var _ToolbarBlockType = _interopRequireDefault(require("./ui/ToolbarBlockType"));
|
|
29
|
+
var headingPluginOptions = function headingPluginOptions(_ref, isAllowed, editorAnalyticsApi) {
|
|
30
|
+
var formatMessage = _ref.formatMessage;
|
|
31
|
+
if (!isAllowed) {
|
|
32
|
+
return [];
|
|
33
|
+
}
|
|
34
|
+
return Array.from({
|
|
35
|
+
length: 6
|
|
36
|
+
}, function (_v, idx) {
|
|
37
|
+
var level = idx + 1;
|
|
38
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
39
|
+
var descriptionDescriptor = _messages.messages["heading".concat(level, "Description")];
|
|
40
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
41
|
+
var keyshortcut = (0, _keymaps.tooltip)(_keymaps.keymap["toggleHeading".concat(level)]);
|
|
42
|
+
var id = "heading".concat(level);
|
|
43
|
+
return {
|
|
44
|
+
id: id,
|
|
45
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
46
|
+
title: formatMessage(_messages.messages[id]),
|
|
47
|
+
description: formatMessage(descriptionDescriptor),
|
|
48
|
+
priority: 1300,
|
|
49
|
+
keywords: ["h".concat(level)],
|
|
50
|
+
keyshortcut: keyshortcut,
|
|
51
|
+
icon: function icon() {
|
|
52
|
+
return /*#__PURE__*/_react.default.createElement(_quickInsert.IconHeading, {
|
|
53
|
+
level: level
|
|
54
|
+
});
|
|
55
|
+
},
|
|
56
|
+
action: function action(insert, state) {
|
|
57
|
+
var tr = insert(state.schema.nodes.heading.createChecked({
|
|
58
|
+
level: level
|
|
59
|
+
}));
|
|
60
|
+
editorAnalyticsApi === null || editorAnalyticsApi === void 0 ? void 0 : editorAnalyticsApi.attachAnalyticsEvent({
|
|
61
|
+
action: _analytics.ACTION.FORMATTED,
|
|
62
|
+
actionSubject: _analytics.ACTION_SUBJECT.TEXT,
|
|
63
|
+
eventType: _analytics.EVENT_TYPE.TRACK,
|
|
64
|
+
actionSubjectId: _analytics.ACTION_SUBJECT_ID.FORMAT_HEADING,
|
|
65
|
+
attributes: {
|
|
66
|
+
inputMethod: _analytics.INPUT_METHOD.QUICK_INSERT,
|
|
67
|
+
newHeadingLevel: level
|
|
68
|
+
}
|
|
69
|
+
})(tr);
|
|
70
|
+
return tr;
|
|
71
|
+
}
|
|
72
|
+
};
|
|
73
|
+
});
|
|
74
|
+
};
|
|
75
|
+
var blockquotePluginOptions = function blockquotePluginOptions(_ref2, isAllowed, editorAnalyticsApi) {
|
|
76
|
+
var formatMessage = _ref2.formatMessage;
|
|
77
|
+
if (!isAllowed) {
|
|
78
|
+
return [];
|
|
79
|
+
}
|
|
80
|
+
return [{
|
|
81
|
+
id: 'blockquote',
|
|
82
|
+
title: formatMessage(_messages.messages.blockquote),
|
|
83
|
+
description: formatMessage(_messages.messages.blockquoteDescription),
|
|
84
|
+
priority: 1300,
|
|
85
|
+
keyshortcut: (0, _keymaps.tooltip)(_keymaps.toggleBlockQuote),
|
|
86
|
+
icon: function icon() {
|
|
87
|
+
return /*#__PURE__*/_react.default.createElement(_quickInsert.IconQuote, null);
|
|
88
|
+
},
|
|
89
|
+
action: function action(insert, state) {
|
|
90
|
+
var tr = insert(state.schema.nodes.blockquote.createChecked({}, state.schema.nodes.paragraph.createChecked()));
|
|
91
|
+
editorAnalyticsApi === null || editorAnalyticsApi === void 0 ? void 0 : editorAnalyticsApi.attachAnalyticsEvent({
|
|
92
|
+
action: _analytics.ACTION.FORMATTED,
|
|
93
|
+
actionSubject: _analytics.ACTION_SUBJECT.TEXT,
|
|
94
|
+
eventType: _analytics.EVENT_TYPE.TRACK,
|
|
95
|
+
actionSubjectId: _analytics.ACTION_SUBJECT_ID.FORMAT_BLOCK_QUOTE,
|
|
96
|
+
attributes: {
|
|
97
|
+
inputMethod: _analytics.INPUT_METHOD.QUICK_INSERT
|
|
98
|
+
}
|
|
99
|
+
})(tr);
|
|
100
|
+
return tr;
|
|
101
|
+
}
|
|
102
|
+
}];
|
|
103
|
+
};
|
|
104
|
+
var blockTypePlugin = function blockTypePlugin(_ref3) {
|
|
105
|
+
var options = _ref3.config,
|
|
106
|
+
api = _ref3.api;
|
|
107
|
+
return {
|
|
108
|
+
name: 'blockType',
|
|
109
|
+
nodes: function nodes() {
|
|
110
|
+
var nodes = [{
|
|
111
|
+
name: 'heading',
|
|
112
|
+
node: _adfSchema.heading
|
|
113
|
+
}, {
|
|
114
|
+
name: 'blockquote',
|
|
115
|
+
node: _adfSchema.blockquote
|
|
116
|
+
}, {
|
|
117
|
+
name: 'hardBreak',
|
|
118
|
+
node: _adfSchema.hardBreak
|
|
119
|
+
}];
|
|
120
|
+
if (options && options.allowBlockType) {
|
|
121
|
+
var exclude = options.allowBlockType.exclude ? options.allowBlockType.exclude : [];
|
|
122
|
+
return nodes.filter(function (node) {
|
|
123
|
+
return exclude.indexOf(node.name) === -1;
|
|
124
|
+
});
|
|
125
|
+
}
|
|
126
|
+
return nodes;
|
|
127
|
+
},
|
|
128
|
+
pmPlugins: function pmPlugins() {
|
|
129
|
+
return [{
|
|
130
|
+
name: 'blockType',
|
|
131
|
+
plugin: function plugin(_ref4) {
|
|
132
|
+
var _api$analytics;
|
|
133
|
+
var dispatch = _ref4.dispatch;
|
|
134
|
+
return (0, _main.createPlugin)(api === null || api === void 0 ? void 0 : (_api$analytics = api.analytics) === null || _api$analytics === void 0 ? void 0 : _api$analytics.actions, dispatch, options && options.lastNodeMustBeParagraph);
|
|
135
|
+
}
|
|
136
|
+
}, {
|
|
137
|
+
name: 'blockTypeInputRule',
|
|
138
|
+
plugin: function plugin(_ref5) {
|
|
139
|
+
var _api$analytics2;
|
|
140
|
+
var schema = _ref5.schema,
|
|
141
|
+
featureFlags = _ref5.featureFlags;
|
|
142
|
+
return (0, _inputRule.default)(api === null || api === void 0 ? void 0 : (_api$analytics2 = api.analytics) === null || _api$analytics2 === void 0 ? void 0 : _api$analytics2.actions, schema, featureFlags);
|
|
143
|
+
}
|
|
144
|
+
},
|
|
145
|
+
// Needs to be lower priority than editor-tables.tableEditing
|
|
146
|
+
// plugin as it is currently swallowing right/down arrow events inside tables
|
|
147
|
+
{
|
|
148
|
+
name: 'blockTypeKeyMap',
|
|
149
|
+
plugin: function plugin(_ref6) {
|
|
150
|
+
var _api$analytics3;
|
|
151
|
+
var schema = _ref6.schema,
|
|
152
|
+
featureFlags = _ref6.featureFlags;
|
|
153
|
+
return (0, _keymap.default)(api === null || api === void 0 ? void 0 : (_api$analytics3 = api.analytics) === null || _api$analytics3 === void 0 ? void 0 : _api$analytics3.actions, schema, featureFlags);
|
|
154
|
+
}
|
|
155
|
+
}];
|
|
156
|
+
},
|
|
157
|
+
actions: {
|
|
158
|
+
insertBlockQuote: function insertBlockQuote(inputMethod) {
|
|
159
|
+
var _api$analytics4;
|
|
160
|
+
return (0, _blockType.insertBlockQuoteWithAnalytics)(inputMethod, api === null || api === void 0 ? void 0 : (_api$analytics4 = api.analytics) === null || _api$analytics4 === void 0 ? void 0 : _api$analytics4.actions);
|
|
161
|
+
},
|
|
162
|
+
setBlockType: function setBlockType(name, inputMethod) {
|
|
163
|
+
var _api$analytics5;
|
|
164
|
+
return (0, _commands.setBlockTypeWithAnalytics)(name, inputMethod, api === null || api === void 0 ? void 0 : (_api$analytics5 = api.analytics) === null || _api$analytics5 === void 0 ? void 0 : _api$analytics5.actions);
|
|
165
|
+
}
|
|
166
|
+
},
|
|
167
|
+
getSharedState: function getSharedState(editorState) {
|
|
168
|
+
if (!editorState) {
|
|
169
|
+
return;
|
|
170
|
+
}
|
|
171
|
+
return _main.pluginKey.getState(editorState);
|
|
172
|
+
},
|
|
173
|
+
primaryToolbarComponent: function primaryToolbarComponent(_ref7) {
|
|
174
|
+
var editorView = _ref7.editorView,
|
|
175
|
+
popupsMountPoint = _ref7.popupsMountPoint,
|
|
176
|
+
popupsBoundariesElement = _ref7.popupsBoundariesElement,
|
|
177
|
+
popupsScrollableElement = _ref7.popupsScrollableElement,
|
|
178
|
+
toolbarSize = _ref7.toolbarSize,
|
|
179
|
+
disabled = _ref7.disabled,
|
|
180
|
+
isToolbarReducedSpacing = _ref7.isToolbarReducedSpacing,
|
|
181
|
+
eventDispatcher = _ref7.eventDispatcher;
|
|
182
|
+
var isSmall = options && options.isUndoRedoButtonsEnabled ? toolbarSize < _types.ToolbarSize.XXL : toolbarSize < _types.ToolbarSize.XL;
|
|
183
|
+
var boundSetBlockType = function boundSetBlockType(name) {
|
|
184
|
+
var _api$analytics6;
|
|
185
|
+
return (0, _commands.setBlockTypeWithAnalytics)(name, _analytics.INPUT_METHOD.TOOLBAR, api === null || api === void 0 ? void 0 : (_api$analytics6 = api.analytics) === null || _api$analytics6 === void 0 ? void 0 : _api$analytics6.actions)(editorView.state, editorView.dispatch);
|
|
186
|
+
};
|
|
187
|
+
return /*#__PURE__*/_react.default.createElement(_withPluginState.WithPluginState, {
|
|
188
|
+
editorView: editorView,
|
|
189
|
+
eventDispatcher: eventDispatcher,
|
|
190
|
+
plugins: {
|
|
191
|
+
pluginState: _main.pluginKey
|
|
192
|
+
},
|
|
193
|
+
render: function render(_ref8) {
|
|
194
|
+
var pluginState = _ref8.pluginState;
|
|
195
|
+
return /*#__PURE__*/_react.default.createElement(_ToolbarBlockType.default, {
|
|
196
|
+
isSmall: isSmall,
|
|
197
|
+
isDisabled: disabled,
|
|
198
|
+
isReducedSpacing: isToolbarReducedSpacing,
|
|
199
|
+
setBlockType: boundSetBlockType,
|
|
200
|
+
pluginState: pluginState,
|
|
201
|
+
popupsMountPoint: popupsMountPoint,
|
|
202
|
+
popupsBoundariesElement: popupsBoundariesElement,
|
|
203
|
+
popupsScrollableElement: popupsScrollableElement
|
|
204
|
+
});
|
|
205
|
+
}
|
|
206
|
+
});
|
|
207
|
+
},
|
|
208
|
+
pluginsOptions: {
|
|
209
|
+
quickInsert: function quickInsert(intl) {
|
|
210
|
+
var _api$analytics7, _api$analytics8;
|
|
211
|
+
var exclude = options && options.allowBlockType && options.allowBlockType.exclude ? options.allowBlockType.exclude : [];
|
|
212
|
+
return [].concat((0, _toConsumableArray2.default)(blockquotePluginOptions(intl, exclude.indexOf('blockquote') === -1, api === null || api === void 0 ? void 0 : (_api$analytics7 = api.analytics) === null || _api$analytics7 === void 0 ? void 0 : _api$analytics7.actions)), (0, _toConsumableArray2.default)(headingPluginOptions(intl, exclude.indexOf('heading') === -1, api === null || api === void 0 ? void 0 : (_api$analytics8 = api.analytics) === null || _api$analytics8 === void 0 ? void 0 : _api$analytics8.actions)));
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
};
|
|
216
|
+
};
|
|
217
|
+
exports.blockTypePlugin = blockTypePlugin;
|
|
@@ -0,0 +1,160 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.messages = void 0;
|
|
7
|
+
var _reactIntlNext = require("react-intl-next");
|
|
8
|
+
var messages = (0, _reactIntlNext.defineMessages)({
|
|
9
|
+
normal: {
|
|
10
|
+
id: 'fabric.editor.normal',
|
|
11
|
+
defaultMessage: 'Normal text',
|
|
12
|
+
description: 'This is the default text style'
|
|
13
|
+
},
|
|
14
|
+
heading1: {
|
|
15
|
+
id: 'fabric.editor.heading1',
|
|
16
|
+
defaultMessage: 'Heading 1',
|
|
17
|
+
description: 'Used for the title of a section of your document, headings run from 1 (largest size) to 6 (smallest size)'
|
|
18
|
+
},
|
|
19
|
+
heading1Description: {
|
|
20
|
+
id: 'fabric.editor.heading1Description',
|
|
21
|
+
defaultMessage: 'Use this for a top level heading',
|
|
22
|
+
description: 'Description of the main heading, heading 1'
|
|
23
|
+
},
|
|
24
|
+
heading2: {
|
|
25
|
+
id: 'fabric.editor.heading2',
|
|
26
|
+
defaultMessage: 'Heading 2',
|
|
27
|
+
description: 'Used for the title of a section of your document, headings run from 1 (largest size) to 6 (smallest size)'
|
|
28
|
+
},
|
|
29
|
+
heading2Description: {
|
|
30
|
+
id: 'fabric.editor.heading2Description',
|
|
31
|
+
defaultMessage: 'Use this for key sections',
|
|
32
|
+
description: 'Description of a subtitle heading or secondary heading'
|
|
33
|
+
},
|
|
34
|
+
heading3: {
|
|
35
|
+
id: 'fabric.editor.heading3',
|
|
36
|
+
defaultMessage: 'Heading 3',
|
|
37
|
+
description: 'Used for the title of a section of your document, headings run from 1 (largest size) to 6 (smallest size)'
|
|
38
|
+
},
|
|
39
|
+
heading3Description: {
|
|
40
|
+
id: 'fabric.editor.heading3Description',
|
|
41
|
+
defaultMessage: 'Use this for sub sections and group headings',
|
|
42
|
+
description: ''
|
|
43
|
+
},
|
|
44
|
+
heading4: {
|
|
45
|
+
id: 'fabric.editor.heading4',
|
|
46
|
+
defaultMessage: 'Heading 4',
|
|
47
|
+
description: 'Used for the title of a section of your document, headings run from 1 (largest size) to 6 (smallest size)'
|
|
48
|
+
},
|
|
49
|
+
heading4Description: {
|
|
50
|
+
id: 'fabric.editor.heading4Description',
|
|
51
|
+
defaultMessage: 'Use this for deep headings',
|
|
52
|
+
description: ''
|
|
53
|
+
},
|
|
54
|
+
heading5: {
|
|
55
|
+
id: 'fabric.editor.heading5',
|
|
56
|
+
defaultMessage: 'Heading 5',
|
|
57
|
+
description: 'Used for the title of a section of your document, headings run from 1 (largest size) to 6 (smallest size)'
|
|
58
|
+
},
|
|
59
|
+
heading5Description: {
|
|
60
|
+
id: 'fabric.editor.heading5Description',
|
|
61
|
+
defaultMessage: 'Use this for grouping list items',
|
|
62
|
+
description: ''
|
|
63
|
+
},
|
|
64
|
+
heading6: {
|
|
65
|
+
id: 'fabric.editor.heading6',
|
|
66
|
+
defaultMessage: 'Heading 6',
|
|
67
|
+
description: 'Used for the title of a section of your document, headings run from 1 (largest size) to 6 (smallest size)'
|
|
68
|
+
},
|
|
69
|
+
heading6Description: {
|
|
70
|
+
id: 'fabric.editor.heading6Description',
|
|
71
|
+
defaultMessage: 'Use this for low level headings',
|
|
72
|
+
description: ''
|
|
73
|
+
},
|
|
74
|
+
blockquote: {
|
|
75
|
+
id: 'fabric.editor.blockquote2',
|
|
76
|
+
defaultMessage: 'Quote',
|
|
77
|
+
description: 'Quote some text'
|
|
78
|
+
},
|
|
79
|
+
blockquoteDescription: {
|
|
80
|
+
id: 'fabric.editor.blockquote.description',
|
|
81
|
+
defaultMessage: 'Insert a quote or citation',
|
|
82
|
+
description: 'Quote some text'
|
|
83
|
+
},
|
|
84
|
+
codeblock: {
|
|
85
|
+
id: 'fabric.editor.codeblock',
|
|
86
|
+
defaultMessage: 'Code snippet',
|
|
87
|
+
description: 'Insert a snippet/segment of code (code block)'
|
|
88
|
+
},
|
|
89
|
+
codeblockDescription: {
|
|
90
|
+
id: 'fabric.editor.codeblock.description',
|
|
91
|
+
defaultMessage: 'Display code with syntax highlighting',
|
|
92
|
+
description: 'Insert a snippet/segment of code (code block)'
|
|
93
|
+
},
|
|
94
|
+
infoPanel: {
|
|
95
|
+
id: 'fabric.editor.infoPanel',
|
|
96
|
+
defaultMessage: 'Info panel',
|
|
97
|
+
description: 'Visually distinguishes your text by adding a background colour (blue, purple, yellow, green, red)'
|
|
98
|
+
},
|
|
99
|
+
infoPanelDescription: {
|
|
100
|
+
id: 'fabric.editor.infoPanel.description',
|
|
101
|
+
defaultMessage: 'Highlight information in a colored panel',
|
|
102
|
+
description: 'Visually distinguishes your text by adding a background colour (blue, purple, yellow, green, red)'
|
|
103
|
+
},
|
|
104
|
+
notePanel: {
|
|
105
|
+
id: 'fabric.editor.notePanel',
|
|
106
|
+
defaultMessage: 'Note panel',
|
|
107
|
+
description: 'Visually distinguishes your text by adding a note panel'
|
|
108
|
+
},
|
|
109
|
+
notePanelDescription: {
|
|
110
|
+
id: 'fabric.editor.notePanel.description',
|
|
111
|
+
defaultMessage: 'Add a note in a colored panel',
|
|
112
|
+
description: 'Visually distinguishes your text by adding a note panel'
|
|
113
|
+
},
|
|
114
|
+
successPanel: {
|
|
115
|
+
id: 'fabric.editor.successPanel',
|
|
116
|
+
defaultMessage: 'Success panel',
|
|
117
|
+
description: 'Visually distinguishes your text by adding a success panel'
|
|
118
|
+
},
|
|
119
|
+
successPanelDescription: {
|
|
120
|
+
id: 'fabric.editor.successPanel.description',
|
|
121
|
+
defaultMessage: 'Add tips in a colored panel',
|
|
122
|
+
description: 'Visually distinguishes your text by adding a success panel'
|
|
123
|
+
},
|
|
124
|
+
warningPanel: {
|
|
125
|
+
id: 'fabric.editor.warningPanel',
|
|
126
|
+
defaultMessage: 'Warning panel',
|
|
127
|
+
description: 'Visually distinguishes your text by adding a warning panel'
|
|
128
|
+
},
|
|
129
|
+
warningPanelDescription: {
|
|
130
|
+
id: 'fabric.editor.warningPanel.description',
|
|
131
|
+
defaultMessage: 'Add a note of caution in a colored panel',
|
|
132
|
+
description: 'Visually distinguishes your text by adding a warning panel'
|
|
133
|
+
},
|
|
134
|
+
errorPanel: {
|
|
135
|
+
id: 'fabric.editor.errorPanel',
|
|
136
|
+
defaultMessage: 'Error panel',
|
|
137
|
+
description: 'Visually distinguishes your text by adding a error panel'
|
|
138
|
+
},
|
|
139
|
+
errorPanelDescription: {
|
|
140
|
+
id: 'fabric.editor.errorPanel.description',
|
|
141
|
+
defaultMessage: 'Call out errors in a colored panel',
|
|
142
|
+
description: 'Visually distinguishes your text by adding a error panel'
|
|
143
|
+
},
|
|
144
|
+
customPanel: {
|
|
145
|
+
id: 'fabric.editor.customPanel',
|
|
146
|
+
defaultMessage: 'Custom panel',
|
|
147
|
+
description: 'Visually distinguishes your panel by adding a emoji icon and background color'
|
|
148
|
+
},
|
|
149
|
+
customPanelDescription: {
|
|
150
|
+
id: 'fabric.editor.customPanel.description',
|
|
151
|
+
defaultMessage: 'Add a note with an emoji and colored background',
|
|
152
|
+
description: 'Visually distinguishes your panel by adding a emoji icon and background color '
|
|
153
|
+
},
|
|
154
|
+
other: {
|
|
155
|
+
id: 'fabric.editor.other',
|
|
156
|
+
defaultMessage: 'Others...',
|
|
157
|
+
description: 'Other text formatting'
|
|
158
|
+
}
|
|
159
|
+
});
|
|
160
|
+
exports.messages = messages;
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
+
Object.defineProperty(exports, "__esModule", {
|
|
5
|
+
value: true
|
|
6
|
+
});
|
|
7
|
+
exports.default = void 0;
|
|
8
|
+
var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray"));
|
|
9
|
+
var _analytics = require("@atlaskit/editor-common/analytics");
|
|
10
|
+
var _commands = require("@atlaskit/editor-common/commands");
|
|
11
|
+
var _utils = require("@atlaskit/editor-common/utils");
|
|
12
|
+
var _prosemirrorInputRules = require("@atlaskit/prosemirror-input-rules");
|
|
13
|
+
var _utils2 = require("../utils");
|
|
14
|
+
var MAX_HEADING_LEVEL = 6;
|
|
15
|
+
function getHeadingLevel(match) {
|
|
16
|
+
return {
|
|
17
|
+
level: match[1].length
|
|
18
|
+
};
|
|
19
|
+
}
|
|
20
|
+
function headingRule(nodeType, maxLevel) {
|
|
21
|
+
return (0, _utils2.createWrappingTextBlockRule)({
|
|
22
|
+
match: new RegExp('^(#{1,' + maxLevel + '})\\s$'),
|
|
23
|
+
nodeType: nodeType,
|
|
24
|
+
getAttrs: getHeadingLevel
|
|
25
|
+
});
|
|
26
|
+
}
|
|
27
|
+
function blockQuoteRule(nodeType) {
|
|
28
|
+
return (0, _utils2.createJoinNodesRule)(/^\s*>\s$/, nodeType);
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* Get heading rules
|
|
33
|
+
*
|
|
34
|
+
* @param {Schema} schema
|
|
35
|
+
* @returns {InputRuleWithHandler[]}
|
|
36
|
+
*/
|
|
37
|
+
function getHeadingRules(editorAnalyticsAPI, schema) {
|
|
38
|
+
// '# ' for h1, '## ' for h2 and etc
|
|
39
|
+
var hashRule = headingRule(schema.nodes.heading, MAX_HEADING_LEVEL);
|
|
40
|
+
var leftNodeReplacementHashRule = (0, _prosemirrorInputRules.createRule)(new RegExp("".concat(_prosemirrorInputRules.leafNodeReplacementCharacter, "(#{1,6})\\s$")), function (state, match, start, end) {
|
|
41
|
+
var level = match[1].length;
|
|
42
|
+
return (0, _commands.insertBlock)(state, schema.nodes.heading, start, end, {
|
|
43
|
+
level: level
|
|
44
|
+
});
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
// New analytics handler
|
|
48
|
+
var ruleWithHeadingAnalytics = (0, _utils.inputRuleWithAnalytics)(function (_state, matchResult) {
|
|
49
|
+
return {
|
|
50
|
+
action: _analytics.ACTION.FORMATTED,
|
|
51
|
+
actionSubject: _analytics.ACTION_SUBJECT.TEXT,
|
|
52
|
+
eventType: _analytics.EVENT_TYPE.TRACK,
|
|
53
|
+
actionSubjectId: _analytics.ACTION_SUBJECT_ID.FORMAT_HEADING,
|
|
54
|
+
attributes: {
|
|
55
|
+
inputMethod: _analytics.INPUT_METHOD.FORMATTING,
|
|
56
|
+
newHeadingLevel: getHeadingLevel(matchResult).level
|
|
57
|
+
}
|
|
58
|
+
};
|
|
59
|
+
}, editorAnalyticsAPI);
|
|
60
|
+
return [ruleWithHeadingAnalytics(hashRule), ruleWithHeadingAnalytics(leftNodeReplacementHashRule)];
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
/**
|
|
64
|
+
* Get all block quote input rules
|
|
65
|
+
*
|
|
66
|
+
* @param {Schema} schema
|
|
67
|
+
* @returns {InputRuleWithHandler[]}
|
|
68
|
+
*/
|
|
69
|
+
function getBlockQuoteRules(editorAnalyticsAPI, schema) {
|
|
70
|
+
// '> ' for blockquote
|
|
71
|
+
var greatherThanRule = blockQuoteRule(schema.nodes.blockquote);
|
|
72
|
+
var leftNodeReplacementGreatherRule = (0, _prosemirrorInputRules.createRule)(new RegExp("".concat(_prosemirrorInputRules.leafNodeReplacementCharacter, "\\s*>\\s$")), function (state, _match, start, end) {
|
|
73
|
+
return (0, _commands.insertBlock)(state, schema.nodes.blockquote, start, end);
|
|
74
|
+
});
|
|
75
|
+
|
|
76
|
+
// Analytics V3 handler
|
|
77
|
+
var ruleWithBlockQuoteAnalytics = (0, _utils.inputRuleWithAnalytics)({
|
|
78
|
+
action: _analytics.ACTION.FORMATTED,
|
|
79
|
+
actionSubject: _analytics.ACTION_SUBJECT.TEXT,
|
|
80
|
+
eventType: _analytics.EVENT_TYPE.TRACK,
|
|
81
|
+
actionSubjectId: _analytics.ACTION_SUBJECT_ID.FORMAT_BLOCK_QUOTE,
|
|
82
|
+
attributes: {
|
|
83
|
+
inputMethod: _analytics.INPUT_METHOD.FORMATTING
|
|
84
|
+
}
|
|
85
|
+
}, editorAnalyticsAPI);
|
|
86
|
+
return [ruleWithBlockQuoteAnalytics(greatherThanRule), ruleWithBlockQuoteAnalytics(leftNodeReplacementGreatherRule)];
|
|
87
|
+
}
|
|
88
|
+
function inputRulePlugin(editorAnalyticsAPI, schema, featureFlags) {
|
|
89
|
+
var rules = [];
|
|
90
|
+
if (schema.nodes.heading) {
|
|
91
|
+
rules.push.apply(rules, (0, _toConsumableArray2.default)(getHeadingRules(editorAnalyticsAPI, schema)));
|
|
92
|
+
}
|
|
93
|
+
if (schema.nodes.blockquote) {
|
|
94
|
+
rules.push.apply(rules, (0, _toConsumableArray2.default)(getBlockQuoteRules(editorAnalyticsAPI, schema)));
|
|
95
|
+
}
|
|
96
|
+
if (rules.length !== 0) {
|
|
97
|
+
return (0, _prosemirrorInputRules.createPlugin)('block-type', rules, {
|
|
98
|
+
isBlockNodeRule: true
|
|
99
|
+
});
|
|
100
|
+
}
|
|
101
|
+
return;
|
|
102
|
+
}
|
|
103
|
+
var _default = inputRulePlugin;
|
|
104
|
+
exports.default = _default;
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _typeof = require("@babel/runtime/helpers/typeof");
|
|
4
|
+
Object.defineProperty(exports, "__esModule", {
|
|
5
|
+
value: true
|
|
6
|
+
});
|
|
7
|
+
exports.default = keymapPlugin;
|
|
8
|
+
var _analytics = require("@atlaskit/editor-common/analytics");
|
|
9
|
+
var _keymaps = require("@atlaskit/editor-common/keymaps");
|
|
10
|
+
var _utils = require("@atlaskit/editor-common/utils");
|
|
11
|
+
var _commands = require("@atlaskit/editor-prosemirror/commands");
|
|
12
|
+
var _history = require("@atlaskit/editor-prosemirror/history");
|
|
13
|
+
var blockTypes = _interopRequireWildcard(require("../block-types"));
|
|
14
|
+
var _commands2 = require("../commands");
|
|
15
|
+
var _utils2 = require("../utils");
|
|
16
|
+
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
|
|
17
|
+
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || _typeof(obj) !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
|
18
|
+
var backspaceCommand = (0, _commands.chainCommands)(_commands2.cleanUpAtTheStartOfDocument, (0, _commands2.deleteBlockContent)(_utils2.isNodeAWrappingBlockNode), _commands2.deleteAndMoveCursor);
|
|
19
|
+
var del = (0, _commands.chainCommands)((0, _utils.deleteEmptyParagraphAndMoveBlockUp)(_utils2.isNodeAWrappingBlockNode), (0, _commands2.deleteBlockContent)(_utils2.isNodeAWrappingBlockNode), _commands2.deleteAndMoveCursor);
|
|
20
|
+
function keymapPlugin(editorAnalyticsApi, schema, _featureFlags) {
|
|
21
|
+
var list = {};
|
|
22
|
+
(0, _keymaps.bindKeymapWithCommand)(_keymaps.insertNewLine.common, (0, _utils.insertNewLineWithAnalytics)(editorAnalyticsApi), list);
|
|
23
|
+
(0, _keymaps.bindKeymapWithCommand)(_keymaps.moveUp.common, _utils.createNewParagraphAbove, list);
|
|
24
|
+
(0, _keymaps.bindKeymapWithCommand)(_keymaps.moveDown.common, _utils.createNewParagraphBelow, list);
|
|
25
|
+
(0, _keymaps.bindKeymapWithCommand)((0, _keymaps.findKeyMapForBrowser)(_keymaps.redo), _history.redo, list);
|
|
26
|
+
(0, _keymaps.bindKeymapWithCommand)(_keymaps.undo.common, _history.undo, list);
|
|
27
|
+
(0, _keymaps.bindKeymapWithCommand)(_keymaps.backspace.common, backspaceCommand, list);
|
|
28
|
+
(0, _keymaps.bindKeymapWithCommand)(_keymaps.deleteKey.common, del, list);
|
|
29
|
+
(0, _keymaps.bindKeymapWithCommand)(_keymaps.forwardDelete.mac, del, list);
|
|
30
|
+
if (schema.nodes[blockTypes.BLOCK_QUOTE.nodeName]) {
|
|
31
|
+
(0, _keymaps.bindKeymapWithCommand)((0, _keymaps.findShortcutByKeymap)(_keymaps.toggleBlockQuote), (0, _commands2.insertBlockQuoteWithAnalytics)(_analytics.INPUT_METHOD.KEYBOARD, editorAnalyticsApi), list);
|
|
32
|
+
}
|
|
33
|
+
return (0, _keymaps.keymap)(list);
|
|
34
|
+
}
|
|
@@ -0,0 +1,151 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
+
Object.defineProperty(exports, "__esModule", {
|
|
5
|
+
value: true
|
|
6
|
+
});
|
|
7
|
+
exports.pluginKey = exports.createPlugin = void 0;
|
|
8
|
+
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
9
|
+
var _analytics = require("@atlaskit/editor-common/analytics");
|
|
10
|
+
var _safePlugin = require("@atlaskit/editor-common/safe-plugin");
|
|
11
|
+
var _utils = require("@atlaskit/editor-common/utils");
|
|
12
|
+
var _state = require("@atlaskit/editor-prosemirror/state");
|
|
13
|
+
var _blockTypes = require("../block-types");
|
|
14
|
+
var _commands = require("../commands");
|
|
15
|
+
var _consts = require("../consts");
|
|
16
|
+
var _utils2 = require("../utils");
|
|
17
|
+
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; }
|
|
18
|
+
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { (0, _defineProperty2.default)(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
|
|
19
|
+
var blockTypeForNode = function blockTypeForNode(node, schema) {
|
|
20
|
+
if (node.type === schema.nodes.heading) {
|
|
21
|
+
var maybeNode = _blockTypes.HEADINGS_BY_LEVEL[node.attrs['level']];
|
|
22
|
+
if (maybeNode) {
|
|
23
|
+
return maybeNode;
|
|
24
|
+
}
|
|
25
|
+
} else if (node.type === schema.nodes.paragraph) {
|
|
26
|
+
return _blockTypes.NORMAL_TEXT;
|
|
27
|
+
}
|
|
28
|
+
return _blockTypes.OTHER;
|
|
29
|
+
};
|
|
30
|
+
var isBlockTypeSchemaSupported = function isBlockTypeSchemaSupported(blockType, state) {
|
|
31
|
+
switch (blockType) {
|
|
32
|
+
case _blockTypes.NORMAL_TEXT:
|
|
33
|
+
return !!state.schema.nodes.paragraph;
|
|
34
|
+
case _blockTypes.HEADING_1:
|
|
35
|
+
case _blockTypes.HEADING_2:
|
|
36
|
+
case _blockTypes.HEADING_3:
|
|
37
|
+
case _blockTypes.HEADING_4:
|
|
38
|
+
case _blockTypes.HEADING_5:
|
|
39
|
+
case _blockTypes.HEADING_6:
|
|
40
|
+
return !!state.schema.nodes.heading;
|
|
41
|
+
case _blockTypes.BLOCK_QUOTE:
|
|
42
|
+
return !!state.schema.nodes.blockquote;
|
|
43
|
+
case _blockTypes.CODE_BLOCK:
|
|
44
|
+
return !!state.schema.nodes.codeBlock;
|
|
45
|
+
case _blockTypes.PANEL:
|
|
46
|
+
return !!state.schema.nodes.panel;
|
|
47
|
+
}
|
|
48
|
+
return;
|
|
49
|
+
};
|
|
50
|
+
var detectBlockType = function detectBlockType(availableBlockTypes, state) {
|
|
51
|
+
// Before a document is loaded, there is no selection.
|
|
52
|
+
if (!state.selection) {
|
|
53
|
+
return _blockTypes.NORMAL_TEXT;
|
|
54
|
+
}
|
|
55
|
+
var blockType;
|
|
56
|
+
var _state$selection = state.selection,
|
|
57
|
+
$from = _state$selection.$from,
|
|
58
|
+
$to = _state$selection.$to;
|
|
59
|
+
state.doc.nodesBetween($from.pos, $to.pos, function (node) {
|
|
60
|
+
var nodeBlockType = availableBlockTypes.filter(function (blockType) {
|
|
61
|
+
return blockType === blockTypeForNode(node, state.schema);
|
|
62
|
+
});
|
|
63
|
+
if (nodeBlockType.length > 0) {
|
|
64
|
+
if (!blockType) {
|
|
65
|
+
blockType = nodeBlockType[0];
|
|
66
|
+
} else if (blockType !== _blockTypes.OTHER && blockType !== nodeBlockType[0]) {
|
|
67
|
+
blockType = _blockTypes.OTHER;
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
});
|
|
71
|
+
return blockType || _blockTypes.OTHER;
|
|
72
|
+
};
|
|
73
|
+
var autoformatHeading = function autoformatHeading(headingLevel, view, editorAnalyticsApi) {
|
|
74
|
+
if (headingLevel === 0) {
|
|
75
|
+
(0, _commands.setNormalTextWithAnalytics)(_analytics.INPUT_METHOD.FORMATTING, editorAnalyticsApi)(view.state, view.dispatch);
|
|
76
|
+
} else {
|
|
77
|
+
(0, _commands.setHeadingWithAnalytics)(headingLevel, _analytics.INPUT_METHOD.FORMATTING, editorAnalyticsApi)(view.state, view.dispatch);
|
|
78
|
+
}
|
|
79
|
+
return true;
|
|
80
|
+
};
|
|
81
|
+
var pluginKey = new _state.PluginKey('blockTypePlugin');
|
|
82
|
+
exports.pluginKey = pluginKey;
|
|
83
|
+
var createPlugin = function createPlugin(editorAnalyticsApi, dispatch, lastNodeMustBeParagraph) {
|
|
84
|
+
var altKeyLocation = 0;
|
|
85
|
+
return new _safePlugin.SafePlugin({
|
|
86
|
+
appendTransaction: function appendTransaction(_transactions, _oldState, newState) {
|
|
87
|
+
if (lastNodeMustBeParagraph) {
|
|
88
|
+
var pos = newState.doc.resolve(newState.doc.content.size - 1);
|
|
89
|
+
var lastNode = pos.node(1);
|
|
90
|
+
var paragraph = newState.schema.nodes.paragraph;
|
|
91
|
+
if (lastNode && lastNode.isBlock && lastNode.type !== paragraph) {
|
|
92
|
+
return newState.tr.insert(newState.doc.content.size, newState.schema.nodes.paragraph.create()).setMeta('addToHistory', false);
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
},
|
|
96
|
+
state: {
|
|
97
|
+
init: function init(_config, state) {
|
|
98
|
+
var availableBlockTypes = _blockTypes.TEXT_BLOCK_TYPES.filter(function (blockType) {
|
|
99
|
+
return isBlockTypeSchemaSupported(blockType, state);
|
|
100
|
+
});
|
|
101
|
+
var availableWrapperBlockTypes = _blockTypes.WRAPPER_BLOCK_TYPES.filter(function (blockType) {
|
|
102
|
+
return isBlockTypeSchemaSupported(blockType, state);
|
|
103
|
+
});
|
|
104
|
+
return {
|
|
105
|
+
currentBlockType: detectBlockType(availableBlockTypes, state),
|
|
106
|
+
blockTypesDisabled: (0, _utils2.areBlockTypesDisabled)(state),
|
|
107
|
+
availableBlockTypes: availableBlockTypes,
|
|
108
|
+
availableWrapperBlockTypes: availableWrapperBlockTypes
|
|
109
|
+
};
|
|
110
|
+
},
|
|
111
|
+
apply: function apply(_tr, oldPluginState, _oldState, newState) {
|
|
112
|
+
var newPluginState = _objectSpread(_objectSpread({}, oldPluginState), {}, {
|
|
113
|
+
currentBlockType: detectBlockType(oldPluginState.availableBlockTypes, newState),
|
|
114
|
+
blockTypesDisabled: (0, _utils2.areBlockTypesDisabled)(newState)
|
|
115
|
+
});
|
|
116
|
+
if (newPluginState.currentBlockType !== oldPluginState.currentBlockType || newPluginState.blockTypesDisabled !== oldPluginState.blockTypesDisabled) {
|
|
117
|
+
dispatch(pluginKey, newPluginState);
|
|
118
|
+
}
|
|
119
|
+
return newPluginState;
|
|
120
|
+
}
|
|
121
|
+
},
|
|
122
|
+
key: pluginKey,
|
|
123
|
+
props: {
|
|
124
|
+
/**
|
|
125
|
+
* As we only want the left alt key to work for headings shortcuts on Windows
|
|
126
|
+
* we can't use prosemirror-keymap and need to handle these shortcuts specially
|
|
127
|
+
* Shortcut on Mac: Cmd-Opt-{heading level}
|
|
128
|
+
* Shortcut on Windows: Ctrl-LeftAlt-{heading level}
|
|
129
|
+
*/
|
|
130
|
+
handleKeyDown: function handleKeyDown(view, event) {
|
|
131
|
+
var headingLevel = _consts.HEADING_KEYS.indexOf(event.keyCode);
|
|
132
|
+
if (headingLevel > -1 && event.altKey) {
|
|
133
|
+
if (_utils.browser.mac && event.metaKey) {
|
|
134
|
+
return autoformatHeading(headingLevel, view, editorAnalyticsApi);
|
|
135
|
+
} else if (!_utils.browser.mac && event.ctrlKey && altKeyLocation !== event.DOM_KEY_LOCATION_RIGHT) {
|
|
136
|
+
return autoformatHeading(headingLevel, view, editorAnalyticsApi);
|
|
137
|
+
}
|
|
138
|
+
} else if (event.key === 'Alt') {
|
|
139
|
+
// event.location is for the current key only; when a user hits Ctrl-Alt-1 the
|
|
140
|
+
// location refers to the location of the '1' key
|
|
141
|
+
// We store the location of the Alt key when it is hit to check against later
|
|
142
|
+
altKeyLocation = event.location;
|
|
143
|
+
} else if (!event.altKey) {
|
|
144
|
+
altKeyLocation = 0;
|
|
145
|
+
}
|
|
146
|
+
return false;
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
});
|
|
150
|
+
};
|
|
151
|
+
exports.createPlugin = createPlugin;
|