@atlaskit/editor-plugin-text-formatting 0.1.1 → 0.2.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/CHANGELOG.md +10 -0
- package/dist/cjs/commands.js +271 -0
- package/dist/cjs/plugin.js +9 -9
- package/dist/cjs/pm-plugins/keymap.js +9 -26
- package/dist/cjs/ui/Toolbar/hooks/formatting-icons.js +10 -11
- package/dist/cjs/version.json +1 -1
- package/dist/es2019/commands.js +251 -0
- package/dist/es2019/plugin.js +2 -2
- package/dist/es2019/pm-plugins/keymap.js +9 -23
- package/dist/es2019/ui/Toolbar/hooks/formatting-icons.js +3 -4
- package/dist/es2019/version.json +1 -1
- package/dist/esm/commands.js +251 -0
- package/dist/esm/plugin.js +2 -2
- package/dist/esm/pm-plugins/keymap.js +9 -23
- package/dist/esm/ui/Toolbar/hooks/formatting-icons.js +3 -4
- package/dist/esm/version.json +1 -1
- package/dist/types/commands.d.ts +19 -0
- package/dist/types/index.d.ts +1 -1
- package/dist/types/plugin.d.ts +9 -9
- package/dist/types-ts4.5/commands.d.ts +19 -0
- package/dist/types-ts4.5/index.d.ts +1 -1
- package/dist/types-ts4.5/plugin.d.ts +9 -9
- package/package.json +2 -2
- package/report.api.md +12 -12
- package/tmp/api-report-tmp.d.ts +10 -12
- package/dist/cjs/actions.js +0 -188
- package/dist/es2019/actions.js +0 -161
- package/dist/esm/actions.js +0 -168
- package/dist/types/actions.d.ts +0 -22
- package/dist/types-ts4.5/actions.d.ts +0 -22
|
@@ -0,0 +1,251 @@
|
|
|
1
|
+
import { ACTION, ACTION_SUBJECT, ACTION_SUBJECT_ID, EVENT_TYPE } from '@atlaskit/editor-common/analytics';
|
|
2
|
+
import { toggleMark } from '@atlaskit/editor-common/mark';
|
|
3
|
+
export const toggleEm = ({
|
|
4
|
+
tr
|
|
5
|
+
}) => {
|
|
6
|
+
const {
|
|
7
|
+
em
|
|
8
|
+
} = tr.doc.type.schema.marks;
|
|
9
|
+
if (!em) {
|
|
10
|
+
// No transaction to apply
|
|
11
|
+
return null;
|
|
12
|
+
}
|
|
13
|
+
return toggleMark(em)({
|
|
14
|
+
tr
|
|
15
|
+
});
|
|
16
|
+
};
|
|
17
|
+
export const toggleEmWithAnalytics = editorAnalyticsApi => inputMethod => ({
|
|
18
|
+
tr
|
|
19
|
+
}) => {
|
|
20
|
+
const newTr = toggleEm({
|
|
21
|
+
tr
|
|
22
|
+
});
|
|
23
|
+
if (!newTr) {
|
|
24
|
+
// No transaction to apply
|
|
25
|
+
return null;
|
|
26
|
+
}
|
|
27
|
+
editorAnalyticsApi === null || editorAnalyticsApi === void 0 ? void 0 : editorAnalyticsApi.attachAnalyticsEvent({
|
|
28
|
+
action: ACTION.FORMATTED,
|
|
29
|
+
actionSubject: ACTION_SUBJECT.TEXT,
|
|
30
|
+
eventType: EVENT_TYPE.TRACK,
|
|
31
|
+
actionSubjectId: ACTION_SUBJECT_ID.FORMAT_ITALIC,
|
|
32
|
+
attributes: {
|
|
33
|
+
inputMethod
|
|
34
|
+
}
|
|
35
|
+
})(newTr);
|
|
36
|
+
return newTr;
|
|
37
|
+
};
|
|
38
|
+
export const toggleStrike = ({
|
|
39
|
+
tr
|
|
40
|
+
}) => {
|
|
41
|
+
const {
|
|
42
|
+
strike
|
|
43
|
+
} = tr.doc.type.schema.marks;
|
|
44
|
+
if (!strike) {
|
|
45
|
+
// No transaction to apply
|
|
46
|
+
return null;
|
|
47
|
+
}
|
|
48
|
+
return toggleMark(strike)({
|
|
49
|
+
tr
|
|
50
|
+
});
|
|
51
|
+
};
|
|
52
|
+
export const toggleStrikeWithAnalytics = editorAnalyticsApi => inputMethod => ({
|
|
53
|
+
tr
|
|
54
|
+
}) => {
|
|
55
|
+
const newTr = toggleStrike({
|
|
56
|
+
tr
|
|
57
|
+
});
|
|
58
|
+
if (!newTr) {
|
|
59
|
+
// No transaction to apply
|
|
60
|
+
return null;
|
|
61
|
+
}
|
|
62
|
+
editorAnalyticsApi === null || editorAnalyticsApi === void 0 ? void 0 : editorAnalyticsApi.attachAnalyticsEvent({
|
|
63
|
+
action: ACTION.FORMATTED,
|
|
64
|
+
actionSubject: ACTION_SUBJECT.TEXT,
|
|
65
|
+
eventType: EVENT_TYPE.TRACK,
|
|
66
|
+
actionSubjectId: ACTION_SUBJECT_ID.FORMAT_STRIKE,
|
|
67
|
+
attributes: {
|
|
68
|
+
inputMethod
|
|
69
|
+
}
|
|
70
|
+
})(newTr);
|
|
71
|
+
return newTr;
|
|
72
|
+
};
|
|
73
|
+
export const toggleStrong = ({
|
|
74
|
+
tr
|
|
75
|
+
}) => {
|
|
76
|
+
const {
|
|
77
|
+
strong
|
|
78
|
+
} = tr.doc.type.schema.marks;
|
|
79
|
+
if (!strong) {
|
|
80
|
+
// No transaction to apply
|
|
81
|
+
return null;
|
|
82
|
+
}
|
|
83
|
+
return toggleMark(strong)({
|
|
84
|
+
tr
|
|
85
|
+
});
|
|
86
|
+
};
|
|
87
|
+
export const toggleStrongWithAnalytics = editorAnalyticsApi => inputMethod => ({
|
|
88
|
+
tr
|
|
89
|
+
}) => {
|
|
90
|
+
const newTr = toggleStrong({
|
|
91
|
+
tr
|
|
92
|
+
});
|
|
93
|
+
if (!newTr) {
|
|
94
|
+
// No transaction to apply
|
|
95
|
+
return null;
|
|
96
|
+
}
|
|
97
|
+
editorAnalyticsApi === null || editorAnalyticsApi === void 0 ? void 0 : editorAnalyticsApi.attachAnalyticsEvent({
|
|
98
|
+
action: ACTION.FORMATTED,
|
|
99
|
+
actionSubject: ACTION_SUBJECT.TEXT,
|
|
100
|
+
eventType: EVENT_TYPE.TRACK,
|
|
101
|
+
actionSubjectId: ACTION_SUBJECT_ID.FORMAT_STRONG,
|
|
102
|
+
attributes: {
|
|
103
|
+
inputMethod
|
|
104
|
+
}
|
|
105
|
+
})(newTr);
|
|
106
|
+
return newTr;
|
|
107
|
+
};
|
|
108
|
+
export const toggleUnderline = ({
|
|
109
|
+
tr
|
|
110
|
+
}) => {
|
|
111
|
+
const {
|
|
112
|
+
underline
|
|
113
|
+
} = tr.doc.type.schema.marks;
|
|
114
|
+
if (!underline) {
|
|
115
|
+
// No transaction to apply
|
|
116
|
+
return null;
|
|
117
|
+
}
|
|
118
|
+
return toggleMark(underline)({
|
|
119
|
+
tr
|
|
120
|
+
});
|
|
121
|
+
};
|
|
122
|
+
export const toggleUnderlineWithAnalytics = editorAnalyticsApi => inputMethod => ({
|
|
123
|
+
tr
|
|
124
|
+
}) => {
|
|
125
|
+
const newTr = toggleUnderline({
|
|
126
|
+
tr
|
|
127
|
+
});
|
|
128
|
+
if (!newTr) {
|
|
129
|
+
// No transaction to apply
|
|
130
|
+
return null;
|
|
131
|
+
}
|
|
132
|
+
editorAnalyticsApi === null || editorAnalyticsApi === void 0 ? void 0 : editorAnalyticsApi.attachAnalyticsEvent({
|
|
133
|
+
action: ACTION.FORMATTED,
|
|
134
|
+
actionSubject: ACTION_SUBJECT.TEXT,
|
|
135
|
+
eventType: EVENT_TYPE.TRACK,
|
|
136
|
+
actionSubjectId: ACTION_SUBJECT_ID.FORMAT_UNDERLINE,
|
|
137
|
+
attributes: {
|
|
138
|
+
inputMethod
|
|
139
|
+
}
|
|
140
|
+
})(newTr);
|
|
141
|
+
return newTr;
|
|
142
|
+
};
|
|
143
|
+
export const toggleSuperscript = ({
|
|
144
|
+
tr
|
|
145
|
+
}) => {
|
|
146
|
+
const {
|
|
147
|
+
subsup
|
|
148
|
+
} = tr.doc.type.schema.marks;
|
|
149
|
+
if (!subsup) {
|
|
150
|
+
// No transaction to apply
|
|
151
|
+
return null;
|
|
152
|
+
}
|
|
153
|
+
return toggleMark(subsup, {
|
|
154
|
+
type: 'sup'
|
|
155
|
+
})({
|
|
156
|
+
tr
|
|
157
|
+
});
|
|
158
|
+
};
|
|
159
|
+
export const toggleSuperscriptWithAnalytics = editorAnalyticsApi => inputMethod => ({
|
|
160
|
+
tr
|
|
161
|
+
}) => {
|
|
162
|
+
const newTr = toggleSuperscript({
|
|
163
|
+
tr
|
|
164
|
+
});
|
|
165
|
+
if (!newTr) {
|
|
166
|
+
// No transaction to apply
|
|
167
|
+
return null;
|
|
168
|
+
}
|
|
169
|
+
editorAnalyticsApi === null || editorAnalyticsApi === void 0 ? void 0 : editorAnalyticsApi.attachAnalyticsEvent({
|
|
170
|
+
action: ACTION.FORMATTED,
|
|
171
|
+
actionSubject: ACTION_SUBJECT.TEXT,
|
|
172
|
+
eventType: EVENT_TYPE.TRACK,
|
|
173
|
+
actionSubjectId: ACTION_SUBJECT_ID.FORMAT_SUPER,
|
|
174
|
+
attributes: {
|
|
175
|
+
inputMethod
|
|
176
|
+
}
|
|
177
|
+
})(newTr);
|
|
178
|
+
return newTr;
|
|
179
|
+
};
|
|
180
|
+
export const toggleSubscript = ({
|
|
181
|
+
tr
|
|
182
|
+
}) => {
|
|
183
|
+
const {
|
|
184
|
+
subsup
|
|
185
|
+
} = tr.doc.type.schema.marks;
|
|
186
|
+
if (!subsup) {
|
|
187
|
+
// No transaction to apply
|
|
188
|
+
return null;
|
|
189
|
+
}
|
|
190
|
+
return toggleMark(subsup, {
|
|
191
|
+
type: 'sub'
|
|
192
|
+
})({
|
|
193
|
+
tr
|
|
194
|
+
});
|
|
195
|
+
};
|
|
196
|
+
export const toggleSubscriptWithAnalytics = editorAnalyticsApi => inputMethod => ({
|
|
197
|
+
tr
|
|
198
|
+
}) => {
|
|
199
|
+
const newTr = toggleSubscript({
|
|
200
|
+
tr
|
|
201
|
+
});
|
|
202
|
+
if (!newTr) {
|
|
203
|
+
// No transaction to apply
|
|
204
|
+
return null;
|
|
205
|
+
}
|
|
206
|
+
editorAnalyticsApi === null || editorAnalyticsApi === void 0 ? void 0 : editorAnalyticsApi.attachAnalyticsEvent({
|
|
207
|
+
action: ACTION.FORMATTED,
|
|
208
|
+
actionSubject: ACTION_SUBJECT.TEXT,
|
|
209
|
+
eventType: EVENT_TYPE.TRACK,
|
|
210
|
+
actionSubjectId: ACTION_SUBJECT_ID.FORMAT_SUB,
|
|
211
|
+
attributes: {
|
|
212
|
+
inputMethod
|
|
213
|
+
}
|
|
214
|
+
})(newTr);
|
|
215
|
+
return newTr;
|
|
216
|
+
};
|
|
217
|
+
export const toggleCode = ({
|
|
218
|
+
tr
|
|
219
|
+
}) => {
|
|
220
|
+
const {
|
|
221
|
+
code
|
|
222
|
+
} = tr.doc.type.schema.marks;
|
|
223
|
+
if (!code) {
|
|
224
|
+
// No transaction to apply
|
|
225
|
+
return null;
|
|
226
|
+
}
|
|
227
|
+
return toggleMark(code)({
|
|
228
|
+
tr
|
|
229
|
+
});
|
|
230
|
+
};
|
|
231
|
+
export const toggleCodeWithAnalytics = editorAnalyticsApi => inputMethod => ({
|
|
232
|
+
tr
|
|
233
|
+
}) => {
|
|
234
|
+
const newTr = toggleCode({
|
|
235
|
+
tr
|
|
236
|
+
});
|
|
237
|
+
if (!newTr) {
|
|
238
|
+
// No transaction to apply
|
|
239
|
+
return null;
|
|
240
|
+
}
|
|
241
|
+
editorAnalyticsApi === null || editorAnalyticsApi === void 0 ? void 0 : editorAnalyticsApi.attachAnalyticsEvent({
|
|
242
|
+
action: ACTION.FORMATTED,
|
|
243
|
+
actionSubject: ACTION_SUBJECT.TEXT,
|
|
244
|
+
eventType: EVENT_TYPE.TRACK,
|
|
245
|
+
actionSubjectId: ACTION_SUBJECT_ID.FORMAT_CODE,
|
|
246
|
+
attributes: {
|
|
247
|
+
inputMethod
|
|
248
|
+
}
|
|
249
|
+
})(newTr);
|
|
250
|
+
return newTr;
|
|
251
|
+
};
|
package/dist/es2019/plugin.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
import { code, em, strike, strong, subsup, underline } from '@atlaskit/adf-schema';
|
|
3
3
|
import { WithPluginState } from '@atlaskit/editor-common/with-plugin-state';
|
|
4
|
-
import { toggleCodeWithAnalytics, toggleEmWithAnalytics, toggleStrikeWithAnalytics, toggleStrongWithAnalytics, toggleSubscriptWithAnalytics, toggleSuperscriptWithAnalytics, toggleUnderlineWithAnalytics } from './
|
|
4
|
+
import { toggleCodeWithAnalytics, toggleEmWithAnalytics, toggleStrikeWithAnalytics, toggleStrongWithAnalytics, toggleSubscriptWithAnalytics, toggleSuperscriptWithAnalytics, toggleUnderlineWithAnalytics } from './commands';
|
|
5
5
|
import { plugin as clearFormattingPlugin, pluginKey as clearFormattingPluginKey } from './pm-plugins/clear-formatting';
|
|
6
6
|
import clearFormattingKeymapPlugin from './pm-plugins/clear-formatting-keymap';
|
|
7
7
|
import textFormattingCursorPlugin from './pm-plugins/cursor';
|
|
@@ -111,7 +111,7 @@ export const textFormattingPlugin = (options = {}, api) => {
|
|
|
111
111
|
}
|
|
112
112
|
});
|
|
113
113
|
},
|
|
114
|
-
|
|
114
|
+
commands: {
|
|
115
115
|
toggleSuperscript: toggleSuperscriptWithAnalytics(api === null || api === void 0 ? void 0 : (_api$dependencies$ana7 = api.dependencies.analytics) === null || _api$dependencies$ana7 === void 0 ? void 0 : _api$dependencies$ana7.actions),
|
|
116
116
|
toggleSubscript: toggleSubscriptWithAnalytics(api === null || api === void 0 ? void 0 : (_api$dependencies$ana8 = api.dependencies.analytics) === null || _api$dependencies$ana8 === void 0 ? void 0 : _api$dependencies$ana8.actions),
|
|
117
117
|
toggleStrike: toggleStrikeWithAnalytics(api === null || api === void 0 ? void 0 : (_api$dependencies$ana9 = api.dependencies.analytics) === null || _api$dependencies$ana9 === void 0 ? void 0 : _api$dependencies$ana9.actions),
|
|
@@ -1,43 +1,29 @@
|
|
|
1
1
|
import { INPUT_METHOD } from '@atlaskit/editor-common/analytics';
|
|
2
|
-
import
|
|
2
|
+
import { bindKeymapWithPluginCommand, toggleBold, toggleCode, toggleItalic, toggleStrikethrough, toggleSubscript, toggleSuperscript, toggleUnderline } from '@atlaskit/editor-common/keymaps';
|
|
3
3
|
import { keymap } from '@atlaskit/editor-prosemirror/keymap';
|
|
4
|
-
import { toggleCodeWithAnalytics, toggleEmWithAnalytics, toggleStrikeWithAnalytics, toggleStrongWithAnalytics, toggleSubscriptWithAnalytics, toggleSuperscriptWithAnalytics, toggleUnderlineWithAnalytics } from '../
|
|
4
|
+
import { toggleCodeWithAnalytics, toggleEmWithAnalytics, toggleStrikeWithAnalytics, toggleStrongWithAnalytics, toggleSubscriptWithAnalytics, toggleSuperscriptWithAnalytics, toggleUnderlineWithAnalytics } from '../commands';
|
|
5
5
|
export default function keymapPlugin(schema, editorAnalyticsAPI) {
|
|
6
6
|
const list = {};
|
|
7
7
|
if (schema.marks.strong) {
|
|
8
|
-
|
|
9
|
-
inputMethod: INPUT_METHOD.SHORTCUT
|
|
10
|
-
}), list);
|
|
8
|
+
bindKeymapWithPluginCommand(toggleBold.common, toggleStrongWithAnalytics(editorAnalyticsAPI)(INPUT_METHOD.SHORTCUT), list);
|
|
11
9
|
}
|
|
12
10
|
if (schema.marks.em) {
|
|
13
|
-
|
|
14
|
-
inputMethod: INPUT_METHOD.SHORTCUT
|
|
15
|
-
}), list);
|
|
11
|
+
bindKeymapWithPluginCommand(toggleItalic.common, toggleEmWithAnalytics(editorAnalyticsAPI)(INPUT_METHOD.SHORTCUT), list);
|
|
16
12
|
}
|
|
17
13
|
if (schema.marks.code) {
|
|
18
|
-
|
|
19
|
-
inputMethod: INPUT_METHOD.SHORTCUT
|
|
20
|
-
}), list);
|
|
14
|
+
bindKeymapWithPluginCommand(toggleCode.common, toggleCodeWithAnalytics(editorAnalyticsAPI)(INPUT_METHOD.SHORTCUT), list);
|
|
21
15
|
}
|
|
22
16
|
if (schema.marks.strike) {
|
|
23
|
-
|
|
24
|
-
inputMethod: INPUT_METHOD.SHORTCUT
|
|
25
|
-
}), list);
|
|
17
|
+
bindKeymapWithPluginCommand(toggleStrikethrough.common, toggleStrikeWithAnalytics(editorAnalyticsAPI)(INPUT_METHOD.SHORTCUT), list);
|
|
26
18
|
}
|
|
27
19
|
if (schema.marks.subsup) {
|
|
28
|
-
|
|
29
|
-
inputMethod: INPUT_METHOD.SHORTCUT
|
|
30
|
-
}), list);
|
|
20
|
+
bindKeymapWithPluginCommand(toggleSubscript.common, toggleSubscriptWithAnalytics(editorAnalyticsAPI)(INPUT_METHOD.SHORTCUT), list);
|
|
31
21
|
}
|
|
32
22
|
if (schema.marks.subsup) {
|
|
33
|
-
|
|
34
|
-
inputMethod: INPUT_METHOD.SHORTCUT
|
|
35
|
-
}), list);
|
|
23
|
+
bindKeymapWithPluginCommand(toggleSuperscript.common, toggleSuperscriptWithAnalytics(editorAnalyticsAPI)(INPUT_METHOD.SHORTCUT), list);
|
|
36
24
|
}
|
|
37
25
|
if (schema.marks.underline) {
|
|
38
|
-
|
|
39
|
-
inputMethod: INPUT_METHOD.SHORTCUT
|
|
40
|
-
}), list);
|
|
26
|
+
bindKeymapWithPluginCommand(toggleUnderline.common, toggleUnderlineWithAnalytics(editorAnalyticsAPI)(INPUT_METHOD.SHORTCUT), list);
|
|
41
27
|
}
|
|
42
28
|
return keymap(list);
|
|
43
29
|
}
|
|
@@ -4,15 +4,14 @@ import { jsx } from '@emotion/react';
|
|
|
4
4
|
import { INPUT_METHOD, TOOLBAR_ACTION_SUBJECT_ID } from '@atlaskit/editor-common/analytics';
|
|
5
5
|
import { getAriaKeyshortcuts, toggleBold, toggleCode, toggleItalic, toggleStrikethrough, toggleSubscript, toggleSuperscript, toggleUnderline, tooltip, ToolTipContent } from '@atlaskit/editor-common/keymaps';
|
|
6
6
|
import { toolbarMessages } from '@atlaskit/editor-common/messages';
|
|
7
|
+
import { pluginCommandToPMCommand } from '@atlaskit/editor-common/preset';
|
|
7
8
|
import { shortcutStyle } from '@atlaskit/editor-shared-styles/shortcut';
|
|
8
9
|
import BoldIcon from '@atlaskit/icon/glyph/editor/bold';
|
|
9
10
|
import ItalicIcon from '@atlaskit/icon/glyph/editor/italic';
|
|
10
|
-
import { toggleCodeWithAnalytics, toggleEmWithAnalytics, toggleStrikeWithAnalytics, toggleStrongWithAnalytics, toggleSubscriptWithAnalytics, toggleSuperscriptWithAnalytics, toggleUnderlineWithAnalytics } from '../../../
|
|
11
|
+
import { toggleCodeWithAnalytics, toggleEmWithAnalytics, toggleStrikeWithAnalytics, toggleStrongWithAnalytics, toggleSubscriptWithAnalytics, toggleSuperscriptWithAnalytics, toggleUnderlineWithAnalytics } from '../../../commands';
|
|
11
12
|
import { pluginKey as textFormattingPluginKey } from '../../../pm-plugins/plugin-key';
|
|
12
13
|
import { IconTypes } from '../types';
|
|
13
|
-
const withToolbarInputMethod = func => func(
|
|
14
|
-
inputMethod: INPUT_METHOD.TOOLBAR
|
|
15
|
-
});
|
|
14
|
+
const withToolbarInputMethod = func => pluginCommandToPMCommand(func(INPUT_METHOD.TOOLBAR));
|
|
16
15
|
const IconButtons = editorAnalyticsAPI => ({
|
|
17
16
|
strong: {
|
|
18
17
|
buttonId: TOOLBAR_ACTION_SUBJECT_ID.TEXT_FORMATTING_STRONG,
|
package/dist/es2019/version.json
CHANGED
|
@@ -0,0 +1,251 @@
|
|
|
1
|
+
import { ACTION, ACTION_SUBJECT, ACTION_SUBJECT_ID, EVENT_TYPE } from '@atlaskit/editor-common/analytics';
|
|
2
|
+
import { toggleMark } from '@atlaskit/editor-common/mark';
|
|
3
|
+
export var toggleEm = function toggleEm(_ref) {
|
|
4
|
+
var tr = _ref.tr;
|
|
5
|
+
var em = tr.doc.type.schema.marks.em;
|
|
6
|
+
if (!em) {
|
|
7
|
+
// No transaction to apply
|
|
8
|
+
return null;
|
|
9
|
+
}
|
|
10
|
+
return toggleMark(em)({
|
|
11
|
+
tr: tr
|
|
12
|
+
});
|
|
13
|
+
};
|
|
14
|
+
export var toggleEmWithAnalytics = function toggleEmWithAnalytics(editorAnalyticsApi) {
|
|
15
|
+
return function (inputMethod) {
|
|
16
|
+
return function (_ref2) {
|
|
17
|
+
var tr = _ref2.tr;
|
|
18
|
+
var newTr = toggleEm({
|
|
19
|
+
tr: tr
|
|
20
|
+
});
|
|
21
|
+
if (!newTr) {
|
|
22
|
+
// No transaction to apply
|
|
23
|
+
return null;
|
|
24
|
+
}
|
|
25
|
+
editorAnalyticsApi === null || editorAnalyticsApi === void 0 ? void 0 : editorAnalyticsApi.attachAnalyticsEvent({
|
|
26
|
+
action: ACTION.FORMATTED,
|
|
27
|
+
actionSubject: ACTION_SUBJECT.TEXT,
|
|
28
|
+
eventType: EVENT_TYPE.TRACK,
|
|
29
|
+
actionSubjectId: ACTION_SUBJECT_ID.FORMAT_ITALIC,
|
|
30
|
+
attributes: {
|
|
31
|
+
inputMethod: inputMethod
|
|
32
|
+
}
|
|
33
|
+
})(newTr);
|
|
34
|
+
return newTr;
|
|
35
|
+
};
|
|
36
|
+
};
|
|
37
|
+
};
|
|
38
|
+
export var toggleStrike = function toggleStrike(_ref3) {
|
|
39
|
+
var tr = _ref3.tr;
|
|
40
|
+
var strike = tr.doc.type.schema.marks.strike;
|
|
41
|
+
if (!strike) {
|
|
42
|
+
// No transaction to apply
|
|
43
|
+
return null;
|
|
44
|
+
}
|
|
45
|
+
return toggleMark(strike)({
|
|
46
|
+
tr: tr
|
|
47
|
+
});
|
|
48
|
+
};
|
|
49
|
+
export var toggleStrikeWithAnalytics = function toggleStrikeWithAnalytics(editorAnalyticsApi) {
|
|
50
|
+
return function (inputMethod) {
|
|
51
|
+
return function (_ref4) {
|
|
52
|
+
var tr = _ref4.tr;
|
|
53
|
+
var newTr = toggleStrike({
|
|
54
|
+
tr: tr
|
|
55
|
+
});
|
|
56
|
+
if (!newTr) {
|
|
57
|
+
// No transaction to apply
|
|
58
|
+
return null;
|
|
59
|
+
}
|
|
60
|
+
editorAnalyticsApi === null || editorAnalyticsApi === void 0 ? void 0 : editorAnalyticsApi.attachAnalyticsEvent({
|
|
61
|
+
action: ACTION.FORMATTED,
|
|
62
|
+
actionSubject: ACTION_SUBJECT.TEXT,
|
|
63
|
+
eventType: EVENT_TYPE.TRACK,
|
|
64
|
+
actionSubjectId: ACTION_SUBJECT_ID.FORMAT_STRIKE,
|
|
65
|
+
attributes: {
|
|
66
|
+
inputMethod: inputMethod
|
|
67
|
+
}
|
|
68
|
+
})(newTr);
|
|
69
|
+
return newTr;
|
|
70
|
+
};
|
|
71
|
+
};
|
|
72
|
+
};
|
|
73
|
+
export var toggleStrong = function toggleStrong(_ref5) {
|
|
74
|
+
var tr = _ref5.tr;
|
|
75
|
+
var strong = tr.doc.type.schema.marks.strong;
|
|
76
|
+
if (!strong) {
|
|
77
|
+
// No transaction to apply
|
|
78
|
+
return null;
|
|
79
|
+
}
|
|
80
|
+
return toggleMark(strong)({
|
|
81
|
+
tr: tr
|
|
82
|
+
});
|
|
83
|
+
};
|
|
84
|
+
export var toggleStrongWithAnalytics = function toggleStrongWithAnalytics(editorAnalyticsApi) {
|
|
85
|
+
return function (inputMethod) {
|
|
86
|
+
return function (_ref6) {
|
|
87
|
+
var tr = _ref6.tr;
|
|
88
|
+
var newTr = toggleStrong({
|
|
89
|
+
tr: tr
|
|
90
|
+
});
|
|
91
|
+
if (!newTr) {
|
|
92
|
+
// No transaction to apply
|
|
93
|
+
return null;
|
|
94
|
+
}
|
|
95
|
+
editorAnalyticsApi === null || editorAnalyticsApi === void 0 ? void 0 : editorAnalyticsApi.attachAnalyticsEvent({
|
|
96
|
+
action: ACTION.FORMATTED,
|
|
97
|
+
actionSubject: ACTION_SUBJECT.TEXT,
|
|
98
|
+
eventType: EVENT_TYPE.TRACK,
|
|
99
|
+
actionSubjectId: ACTION_SUBJECT_ID.FORMAT_STRONG,
|
|
100
|
+
attributes: {
|
|
101
|
+
inputMethod: inputMethod
|
|
102
|
+
}
|
|
103
|
+
})(newTr);
|
|
104
|
+
return newTr;
|
|
105
|
+
};
|
|
106
|
+
};
|
|
107
|
+
};
|
|
108
|
+
export var toggleUnderline = function toggleUnderline(_ref7) {
|
|
109
|
+
var tr = _ref7.tr;
|
|
110
|
+
var underline = tr.doc.type.schema.marks.underline;
|
|
111
|
+
if (!underline) {
|
|
112
|
+
// No transaction to apply
|
|
113
|
+
return null;
|
|
114
|
+
}
|
|
115
|
+
return toggleMark(underline)({
|
|
116
|
+
tr: tr
|
|
117
|
+
});
|
|
118
|
+
};
|
|
119
|
+
export var toggleUnderlineWithAnalytics = function toggleUnderlineWithAnalytics(editorAnalyticsApi) {
|
|
120
|
+
return function (inputMethod) {
|
|
121
|
+
return function (_ref8) {
|
|
122
|
+
var tr = _ref8.tr;
|
|
123
|
+
var newTr = toggleUnderline({
|
|
124
|
+
tr: tr
|
|
125
|
+
});
|
|
126
|
+
if (!newTr) {
|
|
127
|
+
// No transaction to apply
|
|
128
|
+
return null;
|
|
129
|
+
}
|
|
130
|
+
editorAnalyticsApi === null || editorAnalyticsApi === void 0 ? void 0 : editorAnalyticsApi.attachAnalyticsEvent({
|
|
131
|
+
action: ACTION.FORMATTED,
|
|
132
|
+
actionSubject: ACTION_SUBJECT.TEXT,
|
|
133
|
+
eventType: EVENT_TYPE.TRACK,
|
|
134
|
+
actionSubjectId: ACTION_SUBJECT_ID.FORMAT_UNDERLINE,
|
|
135
|
+
attributes: {
|
|
136
|
+
inputMethod: inputMethod
|
|
137
|
+
}
|
|
138
|
+
})(newTr);
|
|
139
|
+
return newTr;
|
|
140
|
+
};
|
|
141
|
+
};
|
|
142
|
+
};
|
|
143
|
+
export var toggleSuperscript = function toggleSuperscript(_ref9) {
|
|
144
|
+
var tr = _ref9.tr;
|
|
145
|
+
var subsup = tr.doc.type.schema.marks.subsup;
|
|
146
|
+
if (!subsup) {
|
|
147
|
+
// No transaction to apply
|
|
148
|
+
return null;
|
|
149
|
+
}
|
|
150
|
+
return toggleMark(subsup, {
|
|
151
|
+
type: 'sup'
|
|
152
|
+
})({
|
|
153
|
+
tr: tr
|
|
154
|
+
});
|
|
155
|
+
};
|
|
156
|
+
export var toggleSuperscriptWithAnalytics = function toggleSuperscriptWithAnalytics(editorAnalyticsApi) {
|
|
157
|
+
return function (inputMethod) {
|
|
158
|
+
return function (_ref10) {
|
|
159
|
+
var tr = _ref10.tr;
|
|
160
|
+
var newTr = toggleSuperscript({
|
|
161
|
+
tr: tr
|
|
162
|
+
});
|
|
163
|
+
if (!newTr) {
|
|
164
|
+
// No transaction to apply
|
|
165
|
+
return null;
|
|
166
|
+
}
|
|
167
|
+
editorAnalyticsApi === null || editorAnalyticsApi === void 0 ? void 0 : editorAnalyticsApi.attachAnalyticsEvent({
|
|
168
|
+
action: ACTION.FORMATTED,
|
|
169
|
+
actionSubject: ACTION_SUBJECT.TEXT,
|
|
170
|
+
eventType: EVENT_TYPE.TRACK,
|
|
171
|
+
actionSubjectId: ACTION_SUBJECT_ID.FORMAT_SUPER,
|
|
172
|
+
attributes: {
|
|
173
|
+
inputMethod: inputMethod
|
|
174
|
+
}
|
|
175
|
+
})(newTr);
|
|
176
|
+
return newTr;
|
|
177
|
+
};
|
|
178
|
+
};
|
|
179
|
+
};
|
|
180
|
+
export var toggleSubscript = function toggleSubscript(_ref11) {
|
|
181
|
+
var tr = _ref11.tr;
|
|
182
|
+
var subsup = tr.doc.type.schema.marks.subsup;
|
|
183
|
+
if (!subsup) {
|
|
184
|
+
// No transaction to apply
|
|
185
|
+
return null;
|
|
186
|
+
}
|
|
187
|
+
return toggleMark(subsup, {
|
|
188
|
+
type: 'sub'
|
|
189
|
+
})({
|
|
190
|
+
tr: tr
|
|
191
|
+
});
|
|
192
|
+
};
|
|
193
|
+
export var toggleSubscriptWithAnalytics = function toggleSubscriptWithAnalytics(editorAnalyticsApi) {
|
|
194
|
+
return function (inputMethod) {
|
|
195
|
+
return function (_ref12) {
|
|
196
|
+
var tr = _ref12.tr;
|
|
197
|
+
var newTr = toggleSubscript({
|
|
198
|
+
tr: tr
|
|
199
|
+
});
|
|
200
|
+
if (!newTr) {
|
|
201
|
+
// No transaction to apply
|
|
202
|
+
return null;
|
|
203
|
+
}
|
|
204
|
+
editorAnalyticsApi === null || editorAnalyticsApi === void 0 ? void 0 : editorAnalyticsApi.attachAnalyticsEvent({
|
|
205
|
+
action: ACTION.FORMATTED,
|
|
206
|
+
actionSubject: ACTION_SUBJECT.TEXT,
|
|
207
|
+
eventType: EVENT_TYPE.TRACK,
|
|
208
|
+
actionSubjectId: ACTION_SUBJECT_ID.FORMAT_SUB,
|
|
209
|
+
attributes: {
|
|
210
|
+
inputMethod: inputMethod
|
|
211
|
+
}
|
|
212
|
+
})(newTr);
|
|
213
|
+
return newTr;
|
|
214
|
+
};
|
|
215
|
+
};
|
|
216
|
+
};
|
|
217
|
+
export var toggleCode = function toggleCode(_ref13) {
|
|
218
|
+
var tr = _ref13.tr;
|
|
219
|
+
var code = tr.doc.type.schema.marks.code;
|
|
220
|
+
if (!code) {
|
|
221
|
+
// No transaction to apply
|
|
222
|
+
return null;
|
|
223
|
+
}
|
|
224
|
+
return toggleMark(code)({
|
|
225
|
+
tr: tr
|
|
226
|
+
});
|
|
227
|
+
};
|
|
228
|
+
export var toggleCodeWithAnalytics = function toggleCodeWithAnalytics(editorAnalyticsApi) {
|
|
229
|
+
return function (inputMethod) {
|
|
230
|
+
return function (_ref14) {
|
|
231
|
+
var tr = _ref14.tr;
|
|
232
|
+
var newTr = toggleCode({
|
|
233
|
+
tr: tr
|
|
234
|
+
});
|
|
235
|
+
if (!newTr) {
|
|
236
|
+
// No transaction to apply
|
|
237
|
+
return null;
|
|
238
|
+
}
|
|
239
|
+
editorAnalyticsApi === null || editorAnalyticsApi === void 0 ? void 0 : editorAnalyticsApi.attachAnalyticsEvent({
|
|
240
|
+
action: ACTION.FORMATTED,
|
|
241
|
+
actionSubject: ACTION_SUBJECT.TEXT,
|
|
242
|
+
eventType: EVENT_TYPE.TRACK,
|
|
243
|
+
actionSubjectId: ACTION_SUBJECT_ID.FORMAT_CODE,
|
|
244
|
+
attributes: {
|
|
245
|
+
inputMethod: inputMethod
|
|
246
|
+
}
|
|
247
|
+
})(newTr);
|
|
248
|
+
return newTr;
|
|
249
|
+
};
|
|
250
|
+
};
|
|
251
|
+
};
|
package/dist/esm/plugin.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
import { code, em, strike, strong, subsup, underline } from '@atlaskit/adf-schema';
|
|
3
3
|
import { WithPluginState } from '@atlaskit/editor-common/with-plugin-state';
|
|
4
|
-
import { toggleCodeWithAnalytics, toggleEmWithAnalytics, toggleStrikeWithAnalytics, toggleStrongWithAnalytics, toggleSubscriptWithAnalytics, toggleSuperscriptWithAnalytics, toggleUnderlineWithAnalytics } from './
|
|
4
|
+
import { toggleCodeWithAnalytics, toggleEmWithAnalytics, toggleStrikeWithAnalytics, toggleStrongWithAnalytics, toggleSubscriptWithAnalytics, toggleSuperscriptWithAnalytics, toggleUnderlineWithAnalytics } from './commands';
|
|
5
5
|
import { plugin as clearFormattingPlugin, pluginKey as clearFormattingPluginKey } from './pm-plugins/clear-formatting';
|
|
6
6
|
import clearFormattingKeymapPlugin from './pm-plugins/clear-formatting-keymap';
|
|
7
7
|
import textFormattingCursorPlugin from './pm-plugins/cursor';
|
|
@@ -112,7 +112,7 @@ export var textFormattingPlugin = function textFormattingPlugin() {
|
|
|
112
112
|
}
|
|
113
113
|
});
|
|
114
114
|
},
|
|
115
|
-
|
|
115
|
+
commands: {
|
|
116
116
|
toggleSuperscript: toggleSuperscriptWithAnalytics(api === null || api === void 0 ? void 0 : (_api$dependencies$ana7 = api.dependencies.analytics) === null || _api$dependencies$ana7 === void 0 ? void 0 : _api$dependencies$ana7.actions),
|
|
117
117
|
toggleSubscript: toggleSubscriptWithAnalytics(api === null || api === void 0 ? void 0 : (_api$dependencies$ana8 = api.dependencies.analytics) === null || _api$dependencies$ana8 === void 0 ? void 0 : _api$dependencies$ana8.actions),
|
|
118
118
|
toggleStrike: toggleStrikeWithAnalytics(api === null || api === void 0 ? void 0 : (_api$dependencies$ana9 = api.dependencies.analytics) === null || _api$dependencies$ana9 === void 0 ? void 0 : _api$dependencies$ana9.actions),
|
|
@@ -1,43 +1,29 @@
|
|
|
1
1
|
import { INPUT_METHOD } from '@atlaskit/editor-common/analytics';
|
|
2
|
-
import
|
|
2
|
+
import { bindKeymapWithPluginCommand, toggleBold, toggleCode, toggleItalic, toggleStrikethrough, toggleSubscript, toggleSuperscript, toggleUnderline } from '@atlaskit/editor-common/keymaps';
|
|
3
3
|
import { keymap } from '@atlaskit/editor-prosemirror/keymap';
|
|
4
|
-
import { toggleCodeWithAnalytics, toggleEmWithAnalytics, toggleStrikeWithAnalytics, toggleStrongWithAnalytics, toggleSubscriptWithAnalytics, toggleSuperscriptWithAnalytics, toggleUnderlineWithAnalytics } from '../
|
|
4
|
+
import { toggleCodeWithAnalytics, toggleEmWithAnalytics, toggleStrikeWithAnalytics, toggleStrongWithAnalytics, toggleSubscriptWithAnalytics, toggleSuperscriptWithAnalytics, toggleUnderlineWithAnalytics } from '../commands';
|
|
5
5
|
export default function keymapPlugin(schema, editorAnalyticsAPI) {
|
|
6
6
|
var list = {};
|
|
7
7
|
if (schema.marks.strong) {
|
|
8
|
-
|
|
9
|
-
inputMethod: INPUT_METHOD.SHORTCUT
|
|
10
|
-
}), list);
|
|
8
|
+
bindKeymapWithPluginCommand(toggleBold.common, toggleStrongWithAnalytics(editorAnalyticsAPI)(INPUT_METHOD.SHORTCUT), list);
|
|
11
9
|
}
|
|
12
10
|
if (schema.marks.em) {
|
|
13
|
-
|
|
14
|
-
inputMethod: INPUT_METHOD.SHORTCUT
|
|
15
|
-
}), list);
|
|
11
|
+
bindKeymapWithPluginCommand(toggleItalic.common, toggleEmWithAnalytics(editorAnalyticsAPI)(INPUT_METHOD.SHORTCUT), list);
|
|
16
12
|
}
|
|
17
13
|
if (schema.marks.code) {
|
|
18
|
-
|
|
19
|
-
inputMethod: INPUT_METHOD.SHORTCUT
|
|
20
|
-
}), list);
|
|
14
|
+
bindKeymapWithPluginCommand(toggleCode.common, toggleCodeWithAnalytics(editorAnalyticsAPI)(INPUT_METHOD.SHORTCUT), list);
|
|
21
15
|
}
|
|
22
16
|
if (schema.marks.strike) {
|
|
23
|
-
|
|
24
|
-
inputMethod: INPUT_METHOD.SHORTCUT
|
|
25
|
-
}), list);
|
|
17
|
+
bindKeymapWithPluginCommand(toggleStrikethrough.common, toggleStrikeWithAnalytics(editorAnalyticsAPI)(INPUT_METHOD.SHORTCUT), list);
|
|
26
18
|
}
|
|
27
19
|
if (schema.marks.subsup) {
|
|
28
|
-
|
|
29
|
-
inputMethod: INPUT_METHOD.SHORTCUT
|
|
30
|
-
}), list);
|
|
20
|
+
bindKeymapWithPluginCommand(toggleSubscript.common, toggleSubscriptWithAnalytics(editorAnalyticsAPI)(INPUT_METHOD.SHORTCUT), list);
|
|
31
21
|
}
|
|
32
22
|
if (schema.marks.subsup) {
|
|
33
|
-
|
|
34
|
-
inputMethod: INPUT_METHOD.SHORTCUT
|
|
35
|
-
}), list);
|
|
23
|
+
bindKeymapWithPluginCommand(toggleSuperscript.common, toggleSuperscriptWithAnalytics(editorAnalyticsAPI)(INPUT_METHOD.SHORTCUT), list);
|
|
36
24
|
}
|
|
37
25
|
if (schema.marks.underline) {
|
|
38
|
-
|
|
39
|
-
inputMethod: INPUT_METHOD.SHORTCUT
|
|
40
|
-
}), list);
|
|
26
|
+
bindKeymapWithPluginCommand(toggleUnderline.common, toggleUnderlineWithAnalytics(editorAnalyticsAPI)(INPUT_METHOD.SHORTCUT), list);
|
|
41
27
|
}
|
|
42
28
|
return keymap(list);
|
|
43
29
|
}
|