@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,153 @@
|
|
|
1
|
+
import { defineMessages } from 'react-intl-next';
|
|
2
|
+
export var messages = defineMessages({
|
|
3
|
+
normal: {
|
|
4
|
+
id: 'fabric.editor.normal',
|
|
5
|
+
defaultMessage: 'Normal text',
|
|
6
|
+
description: 'This is the default text style'
|
|
7
|
+
},
|
|
8
|
+
heading1: {
|
|
9
|
+
id: 'fabric.editor.heading1',
|
|
10
|
+
defaultMessage: 'Heading 1',
|
|
11
|
+
description: 'Used for the title of a section of your document, headings run from 1 (largest size) to 6 (smallest size)'
|
|
12
|
+
},
|
|
13
|
+
heading1Description: {
|
|
14
|
+
id: 'fabric.editor.heading1Description',
|
|
15
|
+
defaultMessage: 'Use this for a top level heading',
|
|
16
|
+
description: 'Description of the main heading, heading 1'
|
|
17
|
+
},
|
|
18
|
+
heading2: {
|
|
19
|
+
id: 'fabric.editor.heading2',
|
|
20
|
+
defaultMessage: 'Heading 2',
|
|
21
|
+
description: 'Used for the title of a section of your document, headings run from 1 (largest size) to 6 (smallest size)'
|
|
22
|
+
},
|
|
23
|
+
heading2Description: {
|
|
24
|
+
id: 'fabric.editor.heading2Description',
|
|
25
|
+
defaultMessage: 'Use this for key sections',
|
|
26
|
+
description: 'Description of a subtitle heading or secondary heading'
|
|
27
|
+
},
|
|
28
|
+
heading3: {
|
|
29
|
+
id: 'fabric.editor.heading3',
|
|
30
|
+
defaultMessage: 'Heading 3',
|
|
31
|
+
description: 'Used for the title of a section of your document, headings run from 1 (largest size) to 6 (smallest size)'
|
|
32
|
+
},
|
|
33
|
+
heading3Description: {
|
|
34
|
+
id: 'fabric.editor.heading3Description',
|
|
35
|
+
defaultMessage: 'Use this for sub sections and group headings',
|
|
36
|
+
description: ''
|
|
37
|
+
},
|
|
38
|
+
heading4: {
|
|
39
|
+
id: 'fabric.editor.heading4',
|
|
40
|
+
defaultMessage: 'Heading 4',
|
|
41
|
+
description: 'Used for the title of a section of your document, headings run from 1 (largest size) to 6 (smallest size)'
|
|
42
|
+
},
|
|
43
|
+
heading4Description: {
|
|
44
|
+
id: 'fabric.editor.heading4Description',
|
|
45
|
+
defaultMessage: 'Use this for deep headings',
|
|
46
|
+
description: ''
|
|
47
|
+
},
|
|
48
|
+
heading5: {
|
|
49
|
+
id: 'fabric.editor.heading5',
|
|
50
|
+
defaultMessage: 'Heading 5',
|
|
51
|
+
description: 'Used for the title of a section of your document, headings run from 1 (largest size) to 6 (smallest size)'
|
|
52
|
+
},
|
|
53
|
+
heading5Description: {
|
|
54
|
+
id: 'fabric.editor.heading5Description',
|
|
55
|
+
defaultMessage: 'Use this for grouping list items',
|
|
56
|
+
description: ''
|
|
57
|
+
},
|
|
58
|
+
heading6: {
|
|
59
|
+
id: 'fabric.editor.heading6',
|
|
60
|
+
defaultMessage: 'Heading 6',
|
|
61
|
+
description: 'Used for the title of a section of your document, headings run from 1 (largest size) to 6 (smallest size)'
|
|
62
|
+
},
|
|
63
|
+
heading6Description: {
|
|
64
|
+
id: 'fabric.editor.heading6Description',
|
|
65
|
+
defaultMessage: 'Use this for low level headings',
|
|
66
|
+
description: ''
|
|
67
|
+
},
|
|
68
|
+
blockquote: {
|
|
69
|
+
id: 'fabric.editor.blockquote2',
|
|
70
|
+
defaultMessage: 'Quote',
|
|
71
|
+
description: 'Quote some text'
|
|
72
|
+
},
|
|
73
|
+
blockquoteDescription: {
|
|
74
|
+
id: 'fabric.editor.blockquote.description',
|
|
75
|
+
defaultMessage: 'Insert a quote or citation',
|
|
76
|
+
description: 'Quote some text'
|
|
77
|
+
},
|
|
78
|
+
codeblock: {
|
|
79
|
+
id: 'fabric.editor.codeblock',
|
|
80
|
+
defaultMessage: 'Code snippet',
|
|
81
|
+
description: 'Insert a snippet/segment of code (code block)'
|
|
82
|
+
},
|
|
83
|
+
codeblockDescription: {
|
|
84
|
+
id: 'fabric.editor.codeblock.description',
|
|
85
|
+
defaultMessage: 'Display code with syntax highlighting',
|
|
86
|
+
description: 'Insert a snippet/segment of code (code block)'
|
|
87
|
+
},
|
|
88
|
+
infoPanel: {
|
|
89
|
+
id: 'fabric.editor.infoPanel',
|
|
90
|
+
defaultMessage: 'Info panel',
|
|
91
|
+
description: 'Visually distinguishes your text by adding a background colour (blue, purple, yellow, green, red)'
|
|
92
|
+
},
|
|
93
|
+
infoPanelDescription: {
|
|
94
|
+
id: 'fabric.editor.infoPanel.description',
|
|
95
|
+
defaultMessage: 'Highlight information in a colored panel',
|
|
96
|
+
description: 'Visually distinguishes your text by adding a background colour (blue, purple, yellow, green, red)'
|
|
97
|
+
},
|
|
98
|
+
notePanel: {
|
|
99
|
+
id: 'fabric.editor.notePanel',
|
|
100
|
+
defaultMessage: 'Note panel',
|
|
101
|
+
description: 'Visually distinguishes your text by adding a note panel'
|
|
102
|
+
},
|
|
103
|
+
notePanelDescription: {
|
|
104
|
+
id: 'fabric.editor.notePanel.description',
|
|
105
|
+
defaultMessage: 'Add a note in a colored panel',
|
|
106
|
+
description: 'Visually distinguishes your text by adding a note panel'
|
|
107
|
+
},
|
|
108
|
+
successPanel: {
|
|
109
|
+
id: 'fabric.editor.successPanel',
|
|
110
|
+
defaultMessage: 'Success panel',
|
|
111
|
+
description: 'Visually distinguishes your text by adding a success panel'
|
|
112
|
+
},
|
|
113
|
+
successPanelDescription: {
|
|
114
|
+
id: 'fabric.editor.successPanel.description',
|
|
115
|
+
defaultMessage: 'Add tips in a colored panel',
|
|
116
|
+
description: 'Visually distinguishes your text by adding a success panel'
|
|
117
|
+
},
|
|
118
|
+
warningPanel: {
|
|
119
|
+
id: 'fabric.editor.warningPanel',
|
|
120
|
+
defaultMessage: 'Warning panel',
|
|
121
|
+
description: 'Visually distinguishes your text by adding a warning panel'
|
|
122
|
+
},
|
|
123
|
+
warningPanelDescription: {
|
|
124
|
+
id: 'fabric.editor.warningPanel.description',
|
|
125
|
+
defaultMessage: 'Add a note of caution in a colored panel',
|
|
126
|
+
description: 'Visually distinguishes your text by adding a warning panel'
|
|
127
|
+
},
|
|
128
|
+
errorPanel: {
|
|
129
|
+
id: 'fabric.editor.errorPanel',
|
|
130
|
+
defaultMessage: 'Error panel',
|
|
131
|
+
description: 'Visually distinguishes your text by adding a error panel'
|
|
132
|
+
},
|
|
133
|
+
errorPanelDescription: {
|
|
134
|
+
id: 'fabric.editor.errorPanel.description',
|
|
135
|
+
defaultMessage: 'Call out errors in a colored panel',
|
|
136
|
+
description: 'Visually distinguishes your text by adding a error panel'
|
|
137
|
+
},
|
|
138
|
+
customPanel: {
|
|
139
|
+
id: 'fabric.editor.customPanel',
|
|
140
|
+
defaultMessage: 'Custom panel',
|
|
141
|
+
description: 'Visually distinguishes your panel by adding a emoji icon and background color'
|
|
142
|
+
},
|
|
143
|
+
customPanelDescription: {
|
|
144
|
+
id: 'fabric.editor.customPanel.description',
|
|
145
|
+
defaultMessage: 'Add a note with an emoji and colored background',
|
|
146
|
+
description: 'Visually distinguishes your panel by adding a emoji icon and background color '
|
|
147
|
+
},
|
|
148
|
+
other: {
|
|
149
|
+
id: 'fabric.editor.other',
|
|
150
|
+
defaultMessage: 'Others...',
|
|
151
|
+
description: 'Other text formatting'
|
|
152
|
+
}
|
|
153
|
+
});
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
import _toConsumableArray from "@babel/runtime/helpers/toConsumableArray";
|
|
2
|
+
import { ACTION, ACTION_SUBJECT, ACTION_SUBJECT_ID, EVENT_TYPE, INPUT_METHOD } from '@atlaskit/editor-common/analytics';
|
|
3
|
+
import { insertBlock } from '@atlaskit/editor-common/commands';
|
|
4
|
+
import { inputRuleWithAnalytics } from '@atlaskit/editor-common/utils';
|
|
5
|
+
import { createPlugin, createRule, leafNodeReplacementCharacter } from '@atlaskit/prosemirror-input-rules';
|
|
6
|
+
import { createJoinNodesRule, createWrappingTextBlockRule } from '../utils';
|
|
7
|
+
var MAX_HEADING_LEVEL = 6;
|
|
8
|
+
function getHeadingLevel(match) {
|
|
9
|
+
return {
|
|
10
|
+
level: match[1].length
|
|
11
|
+
};
|
|
12
|
+
}
|
|
13
|
+
function headingRule(nodeType, maxLevel) {
|
|
14
|
+
return createWrappingTextBlockRule({
|
|
15
|
+
match: new RegExp('^(#{1,' + maxLevel + '})\\s$'),
|
|
16
|
+
nodeType: nodeType,
|
|
17
|
+
getAttrs: getHeadingLevel
|
|
18
|
+
});
|
|
19
|
+
}
|
|
20
|
+
function blockQuoteRule(nodeType) {
|
|
21
|
+
return createJoinNodesRule(/^\s*>\s$/, nodeType);
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* Get heading rules
|
|
26
|
+
*
|
|
27
|
+
* @param {Schema} schema
|
|
28
|
+
* @returns {InputRuleWithHandler[]}
|
|
29
|
+
*/
|
|
30
|
+
function getHeadingRules(editorAnalyticsAPI, schema) {
|
|
31
|
+
// '# ' for h1, '## ' for h2 and etc
|
|
32
|
+
var hashRule = headingRule(schema.nodes.heading, MAX_HEADING_LEVEL);
|
|
33
|
+
var leftNodeReplacementHashRule = createRule(new RegExp("".concat(leafNodeReplacementCharacter, "(#{1,6})\\s$")), function (state, match, start, end) {
|
|
34
|
+
var level = match[1].length;
|
|
35
|
+
return insertBlock(state, schema.nodes.heading, start, end, {
|
|
36
|
+
level: level
|
|
37
|
+
});
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
// New analytics handler
|
|
41
|
+
var ruleWithHeadingAnalytics = inputRuleWithAnalytics(function (_state, matchResult) {
|
|
42
|
+
return {
|
|
43
|
+
action: ACTION.FORMATTED,
|
|
44
|
+
actionSubject: ACTION_SUBJECT.TEXT,
|
|
45
|
+
eventType: EVENT_TYPE.TRACK,
|
|
46
|
+
actionSubjectId: ACTION_SUBJECT_ID.FORMAT_HEADING,
|
|
47
|
+
attributes: {
|
|
48
|
+
inputMethod: INPUT_METHOD.FORMATTING,
|
|
49
|
+
newHeadingLevel: getHeadingLevel(matchResult).level
|
|
50
|
+
}
|
|
51
|
+
};
|
|
52
|
+
}, editorAnalyticsAPI);
|
|
53
|
+
return [ruleWithHeadingAnalytics(hashRule), ruleWithHeadingAnalytics(leftNodeReplacementHashRule)];
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
* Get all block quote input rules
|
|
58
|
+
*
|
|
59
|
+
* @param {Schema} schema
|
|
60
|
+
* @returns {InputRuleWithHandler[]}
|
|
61
|
+
*/
|
|
62
|
+
function getBlockQuoteRules(editorAnalyticsAPI, schema) {
|
|
63
|
+
// '> ' for blockquote
|
|
64
|
+
var greatherThanRule = blockQuoteRule(schema.nodes.blockquote);
|
|
65
|
+
var leftNodeReplacementGreatherRule = createRule(new RegExp("".concat(leafNodeReplacementCharacter, "\\s*>\\s$")), function (state, _match, start, end) {
|
|
66
|
+
return insertBlock(state, schema.nodes.blockquote, start, end);
|
|
67
|
+
});
|
|
68
|
+
|
|
69
|
+
// Analytics V3 handler
|
|
70
|
+
var ruleWithBlockQuoteAnalytics = inputRuleWithAnalytics({
|
|
71
|
+
action: ACTION.FORMATTED,
|
|
72
|
+
actionSubject: ACTION_SUBJECT.TEXT,
|
|
73
|
+
eventType: EVENT_TYPE.TRACK,
|
|
74
|
+
actionSubjectId: ACTION_SUBJECT_ID.FORMAT_BLOCK_QUOTE,
|
|
75
|
+
attributes: {
|
|
76
|
+
inputMethod: INPUT_METHOD.FORMATTING
|
|
77
|
+
}
|
|
78
|
+
}, editorAnalyticsAPI);
|
|
79
|
+
return [ruleWithBlockQuoteAnalytics(greatherThanRule), ruleWithBlockQuoteAnalytics(leftNodeReplacementGreatherRule)];
|
|
80
|
+
}
|
|
81
|
+
function inputRulePlugin(editorAnalyticsAPI, schema, featureFlags) {
|
|
82
|
+
var rules = [];
|
|
83
|
+
if (schema.nodes.heading) {
|
|
84
|
+
rules.push.apply(rules, _toConsumableArray(getHeadingRules(editorAnalyticsAPI, schema)));
|
|
85
|
+
}
|
|
86
|
+
if (schema.nodes.blockquote) {
|
|
87
|
+
rules.push.apply(rules, _toConsumableArray(getBlockQuoteRules(editorAnalyticsAPI, schema)));
|
|
88
|
+
}
|
|
89
|
+
if (rules.length !== 0) {
|
|
90
|
+
return createPlugin('block-type', rules, {
|
|
91
|
+
isBlockNodeRule: true
|
|
92
|
+
});
|
|
93
|
+
}
|
|
94
|
+
return;
|
|
95
|
+
}
|
|
96
|
+
export default inputRulePlugin;
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { INPUT_METHOD } from '@atlaskit/editor-common/analytics';
|
|
2
|
+
import { backspace, bindKeymapWithCommand, deleteKey, findKeyMapForBrowser, findShortcutByKeymap, forwardDelete, insertNewLine, keymap, moveDown, moveUp, redo as redoKeymap, toggleBlockQuote, undo as undoKeymap } from '@atlaskit/editor-common/keymaps';
|
|
3
|
+
import { createNewParagraphAbove, createNewParagraphBelow, deleteEmptyParagraphAndMoveBlockUp, insertNewLineWithAnalytics } from '@atlaskit/editor-common/utils';
|
|
4
|
+
import { chainCommands } from '@atlaskit/editor-prosemirror/commands';
|
|
5
|
+
import { redo, undo } from '@atlaskit/editor-prosemirror/history';
|
|
6
|
+
import * as blockTypes from '../block-types';
|
|
7
|
+
import { cleanUpAtTheStartOfDocument, deleteAndMoveCursor, deleteBlockContent, insertBlockQuoteWithAnalytics } from '../commands';
|
|
8
|
+
import { isNodeAWrappingBlockNode } from '../utils';
|
|
9
|
+
var backspaceCommand = chainCommands(cleanUpAtTheStartOfDocument, deleteBlockContent(isNodeAWrappingBlockNode), deleteAndMoveCursor);
|
|
10
|
+
var del = chainCommands(deleteEmptyParagraphAndMoveBlockUp(isNodeAWrappingBlockNode), deleteBlockContent(isNodeAWrappingBlockNode), deleteAndMoveCursor);
|
|
11
|
+
export default function keymapPlugin(editorAnalyticsApi, schema, _featureFlags) {
|
|
12
|
+
var list = {};
|
|
13
|
+
bindKeymapWithCommand(insertNewLine.common, insertNewLineWithAnalytics(editorAnalyticsApi), list);
|
|
14
|
+
bindKeymapWithCommand(moveUp.common, createNewParagraphAbove, list);
|
|
15
|
+
bindKeymapWithCommand(moveDown.common, createNewParagraphBelow, list);
|
|
16
|
+
bindKeymapWithCommand(findKeyMapForBrowser(redoKeymap), redo, list);
|
|
17
|
+
bindKeymapWithCommand(undoKeymap.common, undo, list);
|
|
18
|
+
bindKeymapWithCommand(backspace.common, backspaceCommand, list);
|
|
19
|
+
bindKeymapWithCommand(deleteKey.common, del, list);
|
|
20
|
+
bindKeymapWithCommand(forwardDelete.mac, del, list);
|
|
21
|
+
if (schema.nodes[blockTypes.BLOCK_QUOTE.nodeName]) {
|
|
22
|
+
bindKeymapWithCommand(findShortcutByKeymap(toggleBlockQuote), insertBlockQuoteWithAnalytics(INPUT_METHOD.KEYBOARD, editorAnalyticsApi), list);
|
|
23
|
+
}
|
|
24
|
+
return keymap(list);
|
|
25
|
+
}
|
|
@@ -0,0 +1,142 @@
|
|
|
1
|
+
import _defineProperty from "@babel/runtime/helpers/defineProperty";
|
|
2
|
+
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
|
3
|
+
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
|
|
4
|
+
import { INPUT_METHOD } from '@atlaskit/editor-common/analytics';
|
|
5
|
+
import { SafePlugin } from '@atlaskit/editor-common/safe-plugin';
|
|
6
|
+
import { browser } from '@atlaskit/editor-common/utils';
|
|
7
|
+
import { PluginKey } from '@atlaskit/editor-prosemirror/state';
|
|
8
|
+
import { BLOCK_QUOTE, CODE_BLOCK, HEADING_1, HEADING_2, HEADING_3, HEADING_4, HEADING_5, HEADING_6, HEADINGS_BY_LEVEL, NORMAL_TEXT, OTHER, PANEL, TEXT_BLOCK_TYPES, WRAPPER_BLOCK_TYPES } from '../block-types';
|
|
9
|
+
import { setHeadingWithAnalytics, setNormalTextWithAnalytics } from '../commands';
|
|
10
|
+
import { HEADING_KEYS } from '../consts';
|
|
11
|
+
import { areBlockTypesDisabled } from '../utils';
|
|
12
|
+
var blockTypeForNode = function blockTypeForNode(node, schema) {
|
|
13
|
+
if (node.type === schema.nodes.heading) {
|
|
14
|
+
var maybeNode = HEADINGS_BY_LEVEL[node.attrs['level']];
|
|
15
|
+
if (maybeNode) {
|
|
16
|
+
return maybeNode;
|
|
17
|
+
}
|
|
18
|
+
} else if (node.type === schema.nodes.paragraph) {
|
|
19
|
+
return NORMAL_TEXT;
|
|
20
|
+
}
|
|
21
|
+
return OTHER;
|
|
22
|
+
};
|
|
23
|
+
var isBlockTypeSchemaSupported = function isBlockTypeSchemaSupported(blockType, state) {
|
|
24
|
+
switch (blockType) {
|
|
25
|
+
case NORMAL_TEXT:
|
|
26
|
+
return !!state.schema.nodes.paragraph;
|
|
27
|
+
case HEADING_1:
|
|
28
|
+
case HEADING_2:
|
|
29
|
+
case HEADING_3:
|
|
30
|
+
case HEADING_4:
|
|
31
|
+
case HEADING_5:
|
|
32
|
+
case HEADING_6:
|
|
33
|
+
return !!state.schema.nodes.heading;
|
|
34
|
+
case BLOCK_QUOTE:
|
|
35
|
+
return !!state.schema.nodes.blockquote;
|
|
36
|
+
case CODE_BLOCK:
|
|
37
|
+
return !!state.schema.nodes.codeBlock;
|
|
38
|
+
case PANEL:
|
|
39
|
+
return !!state.schema.nodes.panel;
|
|
40
|
+
}
|
|
41
|
+
return;
|
|
42
|
+
};
|
|
43
|
+
var detectBlockType = function detectBlockType(availableBlockTypes, state) {
|
|
44
|
+
// Before a document is loaded, there is no selection.
|
|
45
|
+
if (!state.selection) {
|
|
46
|
+
return NORMAL_TEXT;
|
|
47
|
+
}
|
|
48
|
+
var blockType;
|
|
49
|
+
var _state$selection = state.selection,
|
|
50
|
+
$from = _state$selection.$from,
|
|
51
|
+
$to = _state$selection.$to;
|
|
52
|
+
state.doc.nodesBetween($from.pos, $to.pos, function (node) {
|
|
53
|
+
var nodeBlockType = availableBlockTypes.filter(function (blockType) {
|
|
54
|
+
return blockType === blockTypeForNode(node, state.schema);
|
|
55
|
+
});
|
|
56
|
+
if (nodeBlockType.length > 0) {
|
|
57
|
+
if (!blockType) {
|
|
58
|
+
blockType = nodeBlockType[0];
|
|
59
|
+
} else if (blockType !== OTHER && blockType !== nodeBlockType[0]) {
|
|
60
|
+
blockType = OTHER;
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
});
|
|
64
|
+
return blockType || OTHER;
|
|
65
|
+
};
|
|
66
|
+
var autoformatHeading = function autoformatHeading(headingLevel, view, editorAnalyticsApi) {
|
|
67
|
+
if (headingLevel === 0) {
|
|
68
|
+
setNormalTextWithAnalytics(INPUT_METHOD.FORMATTING, editorAnalyticsApi)(view.state, view.dispatch);
|
|
69
|
+
} else {
|
|
70
|
+
setHeadingWithAnalytics(headingLevel, INPUT_METHOD.FORMATTING, editorAnalyticsApi)(view.state, view.dispatch);
|
|
71
|
+
}
|
|
72
|
+
return true;
|
|
73
|
+
};
|
|
74
|
+
export var pluginKey = new PluginKey('blockTypePlugin');
|
|
75
|
+
export var createPlugin = function createPlugin(editorAnalyticsApi, dispatch, lastNodeMustBeParagraph) {
|
|
76
|
+
var altKeyLocation = 0;
|
|
77
|
+
return new SafePlugin({
|
|
78
|
+
appendTransaction: function appendTransaction(_transactions, _oldState, newState) {
|
|
79
|
+
if (lastNodeMustBeParagraph) {
|
|
80
|
+
var pos = newState.doc.resolve(newState.doc.content.size - 1);
|
|
81
|
+
var lastNode = pos.node(1);
|
|
82
|
+
var paragraph = newState.schema.nodes.paragraph;
|
|
83
|
+
if (lastNode && lastNode.isBlock && lastNode.type !== paragraph) {
|
|
84
|
+
return newState.tr.insert(newState.doc.content.size, newState.schema.nodes.paragraph.create()).setMeta('addToHistory', false);
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
},
|
|
88
|
+
state: {
|
|
89
|
+
init: function init(_config, state) {
|
|
90
|
+
var availableBlockTypes = TEXT_BLOCK_TYPES.filter(function (blockType) {
|
|
91
|
+
return isBlockTypeSchemaSupported(blockType, state);
|
|
92
|
+
});
|
|
93
|
+
var availableWrapperBlockTypes = WRAPPER_BLOCK_TYPES.filter(function (blockType) {
|
|
94
|
+
return isBlockTypeSchemaSupported(blockType, state);
|
|
95
|
+
});
|
|
96
|
+
return {
|
|
97
|
+
currentBlockType: detectBlockType(availableBlockTypes, state),
|
|
98
|
+
blockTypesDisabled: areBlockTypesDisabled(state),
|
|
99
|
+
availableBlockTypes: availableBlockTypes,
|
|
100
|
+
availableWrapperBlockTypes: availableWrapperBlockTypes
|
|
101
|
+
};
|
|
102
|
+
},
|
|
103
|
+
apply: function apply(_tr, oldPluginState, _oldState, newState) {
|
|
104
|
+
var newPluginState = _objectSpread(_objectSpread({}, oldPluginState), {}, {
|
|
105
|
+
currentBlockType: detectBlockType(oldPluginState.availableBlockTypes, newState),
|
|
106
|
+
blockTypesDisabled: areBlockTypesDisabled(newState)
|
|
107
|
+
});
|
|
108
|
+
if (newPluginState.currentBlockType !== oldPluginState.currentBlockType || newPluginState.blockTypesDisabled !== oldPluginState.blockTypesDisabled) {
|
|
109
|
+
dispatch(pluginKey, newPluginState);
|
|
110
|
+
}
|
|
111
|
+
return newPluginState;
|
|
112
|
+
}
|
|
113
|
+
},
|
|
114
|
+
key: pluginKey,
|
|
115
|
+
props: {
|
|
116
|
+
/**
|
|
117
|
+
* As we only want the left alt key to work for headings shortcuts on Windows
|
|
118
|
+
* we can't use prosemirror-keymap and need to handle these shortcuts specially
|
|
119
|
+
* Shortcut on Mac: Cmd-Opt-{heading level}
|
|
120
|
+
* Shortcut on Windows: Ctrl-LeftAlt-{heading level}
|
|
121
|
+
*/
|
|
122
|
+
handleKeyDown: function handleKeyDown(view, event) {
|
|
123
|
+
var headingLevel = HEADING_KEYS.indexOf(event.keyCode);
|
|
124
|
+
if (headingLevel > -1 && event.altKey) {
|
|
125
|
+
if (browser.mac && event.metaKey) {
|
|
126
|
+
return autoformatHeading(headingLevel, view, editorAnalyticsApi);
|
|
127
|
+
} else if (!browser.mac && event.ctrlKey && altKeyLocation !== event.DOM_KEY_LOCATION_RIGHT) {
|
|
128
|
+
return autoformatHeading(headingLevel, view, editorAnalyticsApi);
|
|
129
|
+
}
|
|
130
|
+
} else if (event.key === 'Alt') {
|
|
131
|
+
// event.location is for the current key only; when a user hits Ctrl-Alt-1 the
|
|
132
|
+
// location refers to the location of the '1' key
|
|
133
|
+
// We store the location of the Alt key when it is hit to check against later
|
|
134
|
+
altKeyLocation = event.location;
|
|
135
|
+
} else if (!event.altKey) {
|
|
136
|
+
altKeyLocation = 0;
|
|
137
|
+
}
|
|
138
|
+
return false;
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
});
|
|
142
|
+
};
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import _taggedTemplateLiteral from "@babel/runtime/helpers/taggedTemplateLiteral";
|
|
2
|
+
var _templateObject;
|
|
3
|
+
import { css } from '@emotion/react';
|
|
4
|
+
import { blockquoteSharedStyles, headingsSharedStyles } from '@atlaskit/editor-common/styles';
|
|
5
|
+
export var blocktypeStyles = function blocktypeStyles(props) {
|
|
6
|
+
return css(_templateObject || (_templateObject = _taggedTemplateLiteral(["\n .ProseMirror {\n ", ";\n ", ";\n }\n"])), blockquoteSharedStyles, headingsSharedStyles(props));
|
|
7
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
/** @jsx jsx */
|
|
2
|
+
import React from 'react';
|
|
3
|
+
import { jsx } from '@emotion/react';
|
|
4
|
+
import { defineMessages, FormattedMessage } from 'react-intl-next';
|
|
5
|
+
import { wrapperStyle } from '@atlaskit/editor-common/styles';
|
|
6
|
+
import { ToolbarButton } from '@atlaskit/editor-common/ui-menu';
|
|
7
|
+
import ExpandIcon from '@atlaskit/icon/glyph/chevron-down';
|
|
8
|
+
import TextStyleIcon from '@atlaskit/icon/glyph/editor/text-style';
|
|
9
|
+
import { NORMAL_TEXT } from '../../block-types';
|
|
10
|
+
import { buttonContentReducedSpacingStyle, buttonContentStyle, expandIconWrapperStyle, wrapperSmallStyle } from './styled';
|
|
11
|
+
export var messages = defineMessages({
|
|
12
|
+
textStyles: {
|
|
13
|
+
id: 'fabric.editor.textStyles',
|
|
14
|
+
defaultMessage: 'Text styles',
|
|
15
|
+
description: 'Menu provides access to various heading styles or normal text'
|
|
16
|
+
}
|
|
17
|
+
});
|
|
18
|
+
export var BlockTypeButton = function BlockTypeButton(props) {
|
|
19
|
+
var labelTextStyles = props.formatMessage(messages.textStyles);
|
|
20
|
+
return jsx(ToolbarButton, {
|
|
21
|
+
spacing: props.isReducedSpacing ? 'none' : 'default',
|
|
22
|
+
selected: props.selected,
|
|
23
|
+
className: "block-type-btn",
|
|
24
|
+
disabled: props.disabled,
|
|
25
|
+
onClick: props.onClick,
|
|
26
|
+
onKeyDown: props.onKeyDown,
|
|
27
|
+
title: labelTextStyles,
|
|
28
|
+
"aria-label": labelTextStyles,
|
|
29
|
+
"aria-haspopup": true,
|
|
30
|
+
"aria-expanded": props['aria-expanded'],
|
|
31
|
+
iconAfter: jsx("span", {
|
|
32
|
+
// eslint-disable-next-line @atlaskit/design-system/consistent-css-prop-usage
|
|
33
|
+
css: [wrapperStyle, props.isSmall && wrapperSmallStyle],
|
|
34
|
+
"data-testid": "toolbar-block-type-text-styles-icon"
|
|
35
|
+
}, props.isSmall && jsx(TextStyleIcon, {
|
|
36
|
+
label: labelTextStyles
|
|
37
|
+
}), jsx("span", {
|
|
38
|
+
// eslint-disable-next-line @atlaskit/design-system/consistent-css-prop-usage
|
|
39
|
+
css: expandIconWrapperStyle
|
|
40
|
+
}, jsx(ExpandIcon, {
|
|
41
|
+
label: ""
|
|
42
|
+
})))
|
|
43
|
+
}, !props.isSmall && jsx("span", {
|
|
44
|
+
css: [
|
|
45
|
+
// eslint-disable-next-line @atlaskit/design-system/consistent-css-prop-usage
|
|
46
|
+
buttonContentStyle,
|
|
47
|
+
// eslint-disable-next-line @atlaskit/design-system/consistent-css-prop-usage
|
|
48
|
+
props.isReducedSpacing && buttonContentReducedSpacingStyle]
|
|
49
|
+
}, jsx(FormattedMessage, props.title || NORMAL_TEXT.title)));
|
|
50
|
+
};
|