@atlaskit/editor-plugin-media 0.3.17 → 0.4.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 +11 -0
- package/dist/cjs/plugin.js +21 -19
- package/dist/cjs/pm-plugins/keymap.js +96 -1
- package/dist/cjs/pm-plugins/mediaResizeAnnouncerMess.js +34 -0
- package/dist/cjs/toolbar/commands.js +1 -1
- package/dist/cjs/toolbar/index.js +1 -1
- package/dist/es2019/plugin.js +5 -2
- package/dist/es2019/pm-plugins/keymap.js +87 -2
- package/dist/es2019/pm-plugins/mediaResizeAnnouncerMess.js +28 -0
- package/dist/es2019/toolbar/commands.js +1 -1
- package/dist/es2019/toolbar/index.js +1 -1
- package/dist/esm/plugin.js +21 -19
- package/dist/esm/pm-plugins/keymap.js +97 -2
- package/dist/esm/pm-plugins/mediaResizeAnnouncerMess.js +28 -0
- package/dist/esm/toolbar/commands.js +1 -1
- package/dist/esm/toolbar/index.js +1 -1
- package/dist/types/pm-plugins/keymap.d.ts +2 -1
- package/dist/types/pm-plugins/mediaResizeAnnouncerMess.d.ts +27 -0
- package/dist/types/pm-plugins/types.d.ts +1 -0
- package/dist/types/toolbar/commands.d.ts +2 -1
- package/dist/types-ts4.5/pm-plugins/keymap.d.ts +2 -1
- package/dist/types-ts4.5/pm-plugins/mediaResizeAnnouncerMess.d.ts +27 -0
- package/dist/types-ts4.5/pm-plugins/types.d.ts +1 -0
- package/dist/types-ts4.5/toolbar/commands.d.ts +2 -1
- package/package.json +3 -3
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,16 @@
|
|
|
1
1
|
# @atlaskit/editor-plugin-media
|
|
2
2
|
|
|
3
|
+
## 0.4.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- [#43108](https://bitbucket.org/atlassian/atlassian-frontend/pull-requests/43108) [`b779a47b799`](https://bitbucket.org/atlassian/atlassian-frontend/commits/b779a47b799) - ECA11Y-86: Added ability to resize media via keyboard and added announcer
|
|
8
|
+
|
|
9
|
+
### Patch Changes
|
|
10
|
+
|
|
11
|
+
- [#43379](https://bitbucket.org/atlassian/atlassian-frontend/pull-requests/43379) [`482c025520d`](https://bitbucket.org/atlassian/atlassian-frontend/commits/482c025520d) - ED-20763 Upgrade ADF schema version to 33.2.3 for MBE nodes.
|
|
12
|
+
- Updated dependencies
|
|
13
|
+
|
|
3
14
|
## 0.3.17
|
|
4
15
|
|
|
5
16
|
### Patch Changes
|
package/dist/cjs/plugin.js
CHANGED
|
@@ -58,6 +58,7 @@ var mediaPlugin = exports.mediaPlugin = function mediaPlugin(_ref2) {
|
|
|
58
58
|
options = _ref2$config === void 0 ? {} : _ref2$config,
|
|
59
59
|
api = _ref2.api;
|
|
60
60
|
var featureFlags = (api === null || api === void 0 || (_api$featureFlags = api.featureFlags) === null || _api$featureFlags === void 0 ? void 0 : _api$featureFlags.sharedState.currentState()) || {};
|
|
61
|
+
var apiWidth = api === null || api === void 0 ? void 0 : api.width;
|
|
61
62
|
return {
|
|
62
63
|
name: 'media',
|
|
63
64
|
getSharedState: function getSharedState(editorState) {
|
|
@@ -145,16 +146,17 @@ var mediaPlugin = exports.mediaPlugin = function mediaPlugin(_ref2) {
|
|
|
145
146
|
}
|
|
146
147
|
}, {
|
|
147
148
|
name: 'mediaKeymap',
|
|
148
|
-
plugin: function plugin() {
|
|
149
|
+
plugin: function plugin(_ref5) {
|
|
149
150
|
var _api$analytics2;
|
|
150
|
-
|
|
151
|
+
var getIntl = _ref5.getIntl;
|
|
152
|
+
return (0, _keymap2.default)(options, api === null || api === void 0 || (_api$analytics2 = api.analytics) === null || _api$analytics2 === void 0 ? void 0 : _api$analytics2.actions, api === null || api === void 0 ? void 0 : api.selection.actions, apiWidth, getIntl);
|
|
151
153
|
}
|
|
152
154
|
}];
|
|
153
155
|
if (options && options.allowMediaSingle) {
|
|
154
156
|
pmPlugins.push({
|
|
155
157
|
name: 'mediaSingleKeymap',
|
|
156
|
-
plugin: function plugin(
|
|
157
|
-
var schema =
|
|
158
|
+
plugin: function plugin(_ref6) {
|
|
159
|
+
var schema = _ref6.schema;
|
|
158
160
|
return (0, _keymapMediaSingle.default)(schema);
|
|
159
161
|
}
|
|
160
162
|
});
|
|
@@ -166,9 +168,9 @@ var mediaPlugin = exports.mediaPlugin = function mediaPlugin(_ref2) {
|
|
|
166
168
|
});
|
|
167
169
|
pmPlugins.push({
|
|
168
170
|
name: 'mediaAltTextKeymap',
|
|
169
|
-
plugin: function plugin(
|
|
171
|
+
plugin: function plugin(_ref7) {
|
|
170
172
|
var _api$analytics3;
|
|
171
|
-
var schema =
|
|
173
|
+
var schema = _ref7.schema;
|
|
172
174
|
return (0, _keymap.default)(schema, api === null || api === void 0 || (_api$analytics3 = api.analytics) === null || _api$analytics3 === void 0 ? void 0 : _api$analytics3.actions);
|
|
173
175
|
}
|
|
174
176
|
});
|
|
@@ -176,15 +178,15 @@ var mediaPlugin = exports.mediaPlugin = function mediaPlugin(_ref2) {
|
|
|
176
178
|
if (options && options.allowLinking) {
|
|
177
179
|
pmPlugins.push({
|
|
178
180
|
name: 'mediaLinking',
|
|
179
|
-
plugin: function plugin(
|
|
180
|
-
var dispatch =
|
|
181
|
+
plugin: function plugin(_ref8) {
|
|
182
|
+
var dispatch = _ref8.dispatch;
|
|
181
183
|
return (0, _linking.default)(dispatch);
|
|
182
184
|
}
|
|
183
185
|
});
|
|
184
186
|
pmPlugins.push({
|
|
185
187
|
name: 'mediaLinkingKeymap',
|
|
186
|
-
plugin: function plugin(
|
|
187
|
-
var schema =
|
|
188
|
+
plugin: function plugin(_ref9) {
|
|
189
|
+
var schema = _ref9.schema;
|
|
188
190
|
return (0, _keymap3.default)(schema);
|
|
189
191
|
}
|
|
190
192
|
});
|
|
@@ -220,19 +222,19 @@ var mediaPlugin = exports.mediaPlugin = function mediaPlugin(_ref2) {
|
|
|
220
222
|
});
|
|
221
223
|
return pmPlugins;
|
|
222
224
|
},
|
|
223
|
-
contentComponent: function contentComponent(
|
|
224
|
-
var editorView =
|
|
225
|
-
appearance =
|
|
225
|
+
contentComponent: function contentComponent(_ref10) {
|
|
226
|
+
var editorView = _ref10.editorView,
|
|
227
|
+
appearance = _ref10.appearance;
|
|
226
228
|
return /*#__PURE__*/_react.default.createElement(MediaPickerFunctionalComponent, {
|
|
227
229
|
editorDomElement: editorView.dom,
|
|
228
230
|
appearance: appearance,
|
|
229
231
|
api: api
|
|
230
232
|
});
|
|
231
233
|
},
|
|
232
|
-
secondaryToolbarComponent: function secondaryToolbarComponent(
|
|
233
|
-
var editorView =
|
|
234
|
-
eventDispatcher =
|
|
235
|
-
disabled =
|
|
234
|
+
secondaryToolbarComponent: function secondaryToolbarComponent(_ref11) {
|
|
235
|
+
var editorView = _ref11.editorView,
|
|
236
|
+
eventDispatcher = _ref11.eventDispatcher,
|
|
237
|
+
disabled = _ref11.disabled;
|
|
236
238
|
return /*#__PURE__*/_react.default.createElement(_ToolbarMedia.default, {
|
|
237
239
|
isDisabled: disabled,
|
|
238
240
|
isReducedSpacing: true,
|
|
@@ -240,8 +242,8 @@ var mediaPlugin = exports.mediaPlugin = function mediaPlugin(_ref2) {
|
|
|
240
242
|
});
|
|
241
243
|
},
|
|
242
244
|
pluginsOptions: {
|
|
243
|
-
quickInsert: function quickInsert(
|
|
244
|
-
var formatMessage =
|
|
245
|
+
quickInsert: function quickInsert(_ref12) {
|
|
246
|
+
var formatMessage = _ref12.formatMessage;
|
|
245
247
|
return [{
|
|
246
248
|
id: 'media',
|
|
247
249
|
title: formatMessage(_messages.toolbarInsertBlockMessages.mediaFiles),
|
|
@@ -6,12 +6,17 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
6
6
|
exports.default = void 0;
|
|
7
7
|
exports.keymapPlugin = keymapPlugin;
|
|
8
8
|
var _keymaps = require("@atlaskit/editor-common/keymaps");
|
|
9
|
+
var _mediaSingle = require("@atlaskit/editor-common/media-single");
|
|
9
10
|
var _selection = require("@atlaskit/editor-common/selection");
|
|
10
11
|
var _keymap = require("@atlaskit/editor-prosemirror/keymap");
|
|
11
12
|
var _state = require("@atlaskit/editor-prosemirror/state");
|
|
13
|
+
var _editorSharedStyles = require("@atlaskit/editor-shared-styles");
|
|
12
14
|
var _captions = require("../commands/captions");
|
|
13
15
|
var _pluginKey = require("../pm-plugins/plugin-key");
|
|
14
|
-
|
|
16
|
+
var _commands = require("../toolbar/commands");
|
|
17
|
+
var _utils = require("../toolbar/utils");
|
|
18
|
+
var _mediaResizeAnnouncerMess = require("./mediaResizeAnnouncerMess");
|
|
19
|
+
function keymapPlugin(options, editorAnalyticsAPI, editorSelectionAPI, widthPlugin, getIntl) {
|
|
15
20
|
var list = {};
|
|
16
21
|
(0, _keymaps.bindKeymapWithCommand)(_keymaps.undo.common, ignoreLinksInSteps, list);
|
|
17
22
|
(0, _keymaps.bindKeymapWithCommand)(_keymaps.enter.common, splitMediaGroup, list);
|
|
@@ -22,6 +27,10 @@ function keymapPlugin(options, editorAnalyticsAPI, editorSelectionAPI) {
|
|
|
22
27
|
(0, _keymaps.bindKeymapWithCommand)(_keymaps.moveRight.common, arrowRightFromMediaSingle(editorSelectionAPI), list);
|
|
23
28
|
}
|
|
24
29
|
(0, _keymaps.bindKeymapWithCommand)(_keymaps.insertNewLine.common, splitMediaGroup, list);
|
|
30
|
+
(0, _keymaps.bindKeymapWithCommand)(_keymaps.increaseMediaSize.common, handleMediaIncrease(editorAnalyticsAPI, widthPlugin, options, getIntl), list);
|
|
31
|
+
(0, _keymaps.bindKeymapWithCommand)(_keymaps.decreaseMediaSize.common, handleMediaDecrease(editorAnalyticsAPI, widthPlugin, options, getIntl), list);
|
|
32
|
+
(0, _keymaps.bindKeymapWithCommand)(_keymaps.quickIncreaseMediaSize.common, handleMediaQuickIncrease(editorAnalyticsAPI, widthPlugin, options, getIntl), list);
|
|
33
|
+
(0, _keymaps.bindKeymapWithCommand)(_keymaps.quickDecreaseMediaSize.common, handleMediaQuickDecrease(editorAnalyticsAPI, widthPlugin, options, getIntl), list);
|
|
25
34
|
return (0, _keymap.keymap)(list);
|
|
26
35
|
}
|
|
27
36
|
var ignoreLinksInSteps = function ignoreLinksInSteps(state) {
|
|
@@ -33,6 +42,92 @@ var splitMediaGroup = function splitMediaGroup(state) {
|
|
|
33
42
|
var mediaPluginState = _pluginKey.stateKey.getState(state);
|
|
34
43
|
return mediaPluginState.splitMediaGroup();
|
|
35
44
|
};
|
|
45
|
+
var createAnnouncer = function createAnnouncer(action, mediaWidth, changeAmount, validation, getIntl) {
|
|
46
|
+
var announcerContainer = document.getElementById('media-announcer') || document.createElement('div');
|
|
47
|
+
var intl = getIntl();
|
|
48
|
+
if (!announcerContainer.id) {
|
|
49
|
+
announcerContainer.id = 'media-announcer';
|
|
50
|
+
announcerContainer.setAttribute('role', 'status');
|
|
51
|
+
announcerContainer.setAttribute('aria-live', 'polite');
|
|
52
|
+
announcerContainer.setAttribute('aria-atomic', 'true');
|
|
53
|
+
var style = announcerContainer.style;
|
|
54
|
+
style.position = 'absolute';
|
|
55
|
+
style.width = '1px';
|
|
56
|
+
style.height = '1px';
|
|
57
|
+
style.marginTop = '-1px';
|
|
58
|
+
style.opacity = '0';
|
|
59
|
+
style.overflow = 'hidden';
|
|
60
|
+
document.body.appendChild(announcerContainer);
|
|
61
|
+
} else {
|
|
62
|
+
var newMediaWidth = mediaWidth + changeAmount;
|
|
63
|
+
if (validation === 'greater-than-max') {
|
|
64
|
+
announcerContainer.textContent = intl.formatMessage(_mediaResizeAnnouncerMess.mediaResizeAnnouncerMess.MediaWidthIsMax);
|
|
65
|
+
} else if (validation === 'less-than-min') {
|
|
66
|
+
announcerContainer.textContent = intl.formatMessage(_mediaResizeAnnouncerMess.mediaResizeAnnouncerMess.MediaWidthIsMin);
|
|
67
|
+
} else {
|
|
68
|
+
announcerContainer.textContent = intl.formatMessage(_mediaResizeAnnouncerMess.mediaResizeAnnouncerMess.DefaultMediaWidth, {
|
|
69
|
+
action: action,
|
|
70
|
+
newMediaWidth: newMediaWidth
|
|
71
|
+
});
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
};
|
|
75
|
+
var handleMediaSizeChange = function handleMediaSizeChange(editorAnalyticsAPI, widthPlugin, options, changeAmount, action, getIntl) {
|
|
76
|
+
return function (state, dispatch) {
|
|
77
|
+
var _selectedNode$node, _selectedNode$node2, _widthPlugin$sharedSt;
|
|
78
|
+
var selectedNode = (0, _utils.getSelectedMediaSingle)(state);
|
|
79
|
+
var layout = selectedNode === null || selectedNode === void 0 || (_selectedNode$node = selectedNode.node) === null || _selectedNode$node === void 0 || (_selectedNode$node = _selectedNode$node.attrs) === null || _selectedNode$node === void 0 ? void 0 : _selectedNode$node.layout;
|
|
80
|
+
var mediaWidth = selectedNode === null || selectedNode === void 0 || (_selectedNode$node2 = selectedNode.node) === null || _selectedNode$node2 === void 0 || (_selectedNode$node2 = _selectedNode$node2.attrs) === null || _selectedNode$node2 === void 0 ? void 0 : _selectedNode$node2.width;
|
|
81
|
+
var contentWidth =
|
|
82
|
+
// @ts-ignore readonly sharedState
|
|
83
|
+
(widthPlugin === null || widthPlugin === void 0 || (_widthPlugin$sharedSt = widthPlugin.sharedState.currentState()) === null || _widthPlugin$sharedSt === void 0 ? void 0 : _widthPlugin$sharedSt.lineLength) || _editorSharedStyles.akEditorDefaultLayoutWidth;
|
|
84
|
+
var minWidth = _mediaSingle.MEDIA_SINGLE_DEFAULT_MIN_PIXEL_WIDTH;
|
|
85
|
+
var maxWidth;
|
|
86
|
+
var validation = 'valid';
|
|
87
|
+
var newWidth = mediaWidth + changeAmount;
|
|
88
|
+
var intl = getIntl();
|
|
89
|
+
if (options !== null && options !== void 0 && options.fullWidthEnabled) {
|
|
90
|
+
var _widthPlugin$sharedSt2;
|
|
91
|
+
// @ts-ignore readonly sharedState
|
|
92
|
+
maxWidth = widthPlugin === null || widthPlugin === void 0 || (_widthPlugin$sharedSt2 = widthPlugin.sharedState.currentState()) === null || _widthPlugin$sharedSt2 === void 0 ? void 0 : _widthPlugin$sharedSt2.lineLength;
|
|
93
|
+
} else {
|
|
94
|
+
var _widthPlugin$sharedSt3;
|
|
95
|
+
maxWidth = (0, _mediaSingle.calcMediaSingleMaxWidth)( // @ts-ignore readonly sharedState
|
|
96
|
+
widthPlugin === null || widthPlugin === void 0 || (_widthPlugin$sharedSt3 = widthPlugin.sharedState.currentState()) === null || _widthPlugin$sharedSt3 === void 0 ? void 0 : _widthPlugin$sharedSt3.width);
|
|
97
|
+
}
|
|
98
|
+
if (newWidth > maxWidth) {
|
|
99
|
+
newWidth = maxWidth;
|
|
100
|
+
validation = 'greater-than-max';
|
|
101
|
+
} else if (newWidth < minWidth) {
|
|
102
|
+
newWidth = minWidth;
|
|
103
|
+
validation = 'less-than-min';
|
|
104
|
+
} else {
|
|
105
|
+
newWidth;
|
|
106
|
+
validation = 'valid';
|
|
107
|
+
}
|
|
108
|
+
if (action === 'increased') {
|
|
109
|
+
action = intl.formatMessage(_mediaResizeAnnouncerMess.mediaResizeAnnouncerMess.IncreasedAction);
|
|
110
|
+
} else if (action === 'decreased') {
|
|
111
|
+
action = intl.formatMessage(_mediaResizeAnnouncerMess.mediaResizeAnnouncerMess.DecreasedAction);
|
|
112
|
+
}
|
|
113
|
+
var newLayout = (0, _utils.calcNewLayout)(newWidth, layout, contentWidth, options === null || options === void 0 ? void 0 : options.fullWidthEnabled);
|
|
114
|
+
(0, _commands.updateMediaSingleWidth)(editorAnalyticsAPI)(newWidth, validation, 'keyboard', newLayout)(state, dispatch);
|
|
115
|
+
createAnnouncer(action, mediaWidth, changeAmount, validation, getIntl);
|
|
116
|
+
return true;
|
|
117
|
+
};
|
|
118
|
+
};
|
|
119
|
+
var handleMediaIncrease = function handleMediaIncrease(editorAnalyticsAPI, widthPlugin, options, getIntl) {
|
|
120
|
+
return handleMediaSizeChange(editorAnalyticsAPI, widthPlugin, options, 1, 'increased', getIntl);
|
|
121
|
+
};
|
|
122
|
+
var handleMediaDecrease = function handleMediaDecrease(editorAnalyticsAPI, widthPlugin, options, getIntl) {
|
|
123
|
+
return handleMediaSizeChange(editorAnalyticsAPI, widthPlugin, options, -1, 'decreased', getIntl);
|
|
124
|
+
};
|
|
125
|
+
var handleMediaQuickIncrease = function handleMediaQuickIncrease(editorAnalyticsAPI, widthPlugin, options, getIntl) {
|
|
126
|
+
return handleMediaSizeChange(editorAnalyticsAPI, widthPlugin, options, 10, 'increased', getIntl);
|
|
127
|
+
};
|
|
128
|
+
var handleMediaQuickDecrease = function handleMediaQuickDecrease(editorAnalyticsAPI, widthPlugin, options, getIntl) {
|
|
129
|
+
return handleMediaSizeChange(editorAnalyticsAPI, widthPlugin, options, -10, 'decreased', getIntl);
|
|
130
|
+
};
|
|
36
131
|
var insertAndSelectCaption = function insertAndSelectCaption(editorAnalyticsAPI) {
|
|
37
132
|
return function (state, dispatch) {
|
|
38
133
|
var selection = state.selection,
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.mediaResizeAnnouncerMess = void 0;
|
|
7
|
+
var _reactIntlNext = require("react-intl-next");
|
|
8
|
+
var mediaResizeAnnouncerMess = exports.mediaResizeAnnouncerMess = (0, _reactIntlNext.defineMessages)({
|
|
9
|
+
MediaWidthIsMax: {
|
|
10
|
+
id: 'fabric.editor.media.pixelEntry.MediaWidthIsMax',
|
|
11
|
+
defaultMessage: 'Media increased to the maximum size',
|
|
12
|
+
description: 'The media has the maximum allowed width'
|
|
13
|
+
},
|
|
14
|
+
MediaWidthIsMin: {
|
|
15
|
+
id: 'fabric.editor.media.MediaWidthIsMin',
|
|
16
|
+
defaultMessage: 'Media decreased to the minimum size',
|
|
17
|
+
description: 'The media has the minimum allowed width'
|
|
18
|
+
},
|
|
19
|
+
DefaultMediaWidth: {
|
|
20
|
+
id: 'fabric.editor.media.DefaultMediaWidth',
|
|
21
|
+
defaultMessage: 'Media width {action} to {newMediaWidth} pixels.',
|
|
22
|
+
description: 'Media width {action} to {newMediaWidth} pixels.'
|
|
23
|
+
},
|
|
24
|
+
IncreasedAction: {
|
|
25
|
+
id: 'fabric.editor.media.decreased',
|
|
26
|
+
defaultMessage: 'increased',
|
|
27
|
+
description: 'Increased action'
|
|
28
|
+
},
|
|
29
|
+
DecreasedAction: {
|
|
30
|
+
id: 'fabric.editor.media.decreased',
|
|
31
|
+
defaultMessage: 'decreased',
|
|
32
|
+
description: 'Decreased action'
|
|
33
|
+
}
|
|
34
|
+
});
|
|
@@ -203,7 +203,7 @@ var setBorderMark = exports.setBorderMark = function setBorderMark(editorAnalyti
|
|
|
203
203
|
};
|
|
204
204
|
};
|
|
205
205
|
var updateMediaSingleWidth = exports.updateMediaSingleWidth = function updateMediaSingleWidth(editorAnalyticsAPI) {
|
|
206
|
-
return function (width, validation, layout) {
|
|
206
|
+
return function (width, validation, input, layout) {
|
|
207
207
|
return function (state, dispatch) {
|
|
208
208
|
var selectedMediaSingleNode = (0, _utils2.getSelectedMediaSingle)(state);
|
|
209
209
|
if (!selectedMediaSingleNode) {
|
|
@@ -322,7 +322,7 @@ var generateMediaSingleFloatingToolbar = function generateMediaSingleFloatingToo
|
|
|
322
322
|
var width = _ref2.width,
|
|
323
323
|
validation = _ref2.validation;
|
|
324
324
|
var newLayout = (0, _utils2.calcNewLayout)(width, layout, contentWidth, options.fullWidthEnabled, isNested);
|
|
325
|
-
(0, _commands.updateMediaSingleWidth)(pluginInjectionApi === null || pluginInjectionApi === void 0 || (_pluginInjectionApi$a4 = pluginInjectionApi.analytics) === null || _pluginInjectionApi$a4 === void 0 ? void 0 : _pluginInjectionApi$a4.actions)(width, validation, newLayout)(state, dispatch);
|
|
325
|
+
(0, _commands.updateMediaSingleWidth)(pluginInjectionApi === null || pluginInjectionApi === void 0 || (_pluginInjectionApi$a4 = pluginInjectionApi.analytics) === null || _pluginInjectionApi$a4 === void 0 ? void 0 : _pluginInjectionApi$a4.actions)(width, validation, 'floatingToolBar', newLayout)(state, dispatch);
|
|
326
326
|
},
|
|
327
327
|
onMigrate: function onMigrate() {
|
|
328
328
|
var tr = state.tr.setNodeMarkup(selectedMediaSingleNode.pos, undefined, _objectSpread(_objectSpread({}, selectedMediaSingleNode.node.attrs), {}, {
|
package/dist/es2019/plugin.js
CHANGED
|
@@ -49,6 +49,7 @@ export const mediaPlugin = ({
|
|
|
49
49
|
}) => {
|
|
50
50
|
var _api$featureFlags;
|
|
51
51
|
const featureFlags = (api === null || api === void 0 ? void 0 : (_api$featureFlags = api.featureFlags) === null || _api$featureFlags === void 0 ? void 0 : _api$featureFlags.sharedState.currentState()) || {};
|
|
52
|
+
const apiWidth = api === null || api === void 0 ? void 0 : api.width;
|
|
52
53
|
return {
|
|
53
54
|
name: 'media',
|
|
54
55
|
getSharedState(editorState) {
|
|
@@ -136,9 +137,11 @@ export const mediaPlugin = ({
|
|
|
136
137
|
}
|
|
137
138
|
}, {
|
|
138
139
|
name: 'mediaKeymap',
|
|
139
|
-
plugin: (
|
|
140
|
+
plugin: ({
|
|
141
|
+
getIntl
|
|
142
|
+
}) => {
|
|
140
143
|
var _api$analytics2;
|
|
141
|
-
return keymapPlugin(options, api === null || api === void 0 ? void 0 : (_api$analytics2 = api.analytics) === null || _api$analytics2 === void 0 ? void 0 : _api$analytics2.actions, api === null || api === void 0 ? void 0 : api.selection.actions);
|
|
144
|
+
return keymapPlugin(options, api === null || api === void 0 ? void 0 : (_api$analytics2 = api.analytics) === null || _api$analytics2 === void 0 ? void 0 : _api$analytics2.actions, api === null || api === void 0 ? void 0 : api.selection.actions, apiWidth, getIntl);
|
|
142
145
|
}
|
|
143
146
|
}];
|
|
144
147
|
if (options && options.allowMediaSingle) {
|
|
@@ -1,10 +1,15 @@
|
|
|
1
|
-
import { bindKeymapWithCommand, enter, insertNewLine, moveDown, moveLeft, moveRight, tab, undo } from '@atlaskit/editor-common/keymaps';
|
|
1
|
+
import { bindKeymapWithCommand, decreaseMediaSize, enter, increaseMediaSize, insertNewLine, moveDown, moveLeft, moveRight, quickDecreaseMediaSize, quickIncreaseMediaSize, tab, undo } from '@atlaskit/editor-common/keymaps';
|
|
2
|
+
import { calcMediaSingleMaxWidth, MEDIA_SINGLE_DEFAULT_MIN_PIXEL_WIDTH } from '@atlaskit/editor-common/media-single';
|
|
2
3
|
import { GapCursorSelection, Side } from '@atlaskit/editor-common/selection';
|
|
3
4
|
import { keymap } from '@atlaskit/editor-prosemirror/keymap';
|
|
4
5
|
import { NodeSelection } from '@atlaskit/editor-prosemirror/state';
|
|
6
|
+
import { akEditorDefaultLayoutWidth } from '@atlaskit/editor-shared-styles';
|
|
5
7
|
import { insertAndSelectCaptionFromMediaSinglePos, selectCaptionFromMediaSinglePos } from '../commands/captions';
|
|
6
8
|
import { stateKey } from '../pm-plugins/plugin-key';
|
|
7
|
-
|
|
9
|
+
import { updateMediaSingleWidth } from '../toolbar/commands';
|
|
10
|
+
import { calcNewLayout, getSelectedMediaSingle } from '../toolbar/utils';
|
|
11
|
+
import { mediaResizeAnnouncerMess } from './mediaResizeAnnouncerMess';
|
|
12
|
+
export function keymapPlugin(options, editorAnalyticsAPI, editorSelectionAPI, widthPlugin, getIntl) {
|
|
8
13
|
const list = {};
|
|
9
14
|
bindKeymapWithCommand(undo.common, ignoreLinksInSteps, list);
|
|
10
15
|
bindKeymapWithCommand(enter.common, splitMediaGroup, list);
|
|
@@ -15,6 +20,10 @@ export function keymapPlugin(options, editorAnalyticsAPI, editorSelectionAPI) {
|
|
|
15
20
|
bindKeymapWithCommand(moveRight.common, arrowRightFromMediaSingle(editorSelectionAPI), list);
|
|
16
21
|
}
|
|
17
22
|
bindKeymapWithCommand(insertNewLine.common, splitMediaGroup, list);
|
|
23
|
+
bindKeymapWithCommand(increaseMediaSize.common, handleMediaIncrease(editorAnalyticsAPI, widthPlugin, options, getIntl), list);
|
|
24
|
+
bindKeymapWithCommand(decreaseMediaSize.common, handleMediaDecrease(editorAnalyticsAPI, widthPlugin, options, getIntl), list);
|
|
25
|
+
bindKeymapWithCommand(quickIncreaseMediaSize.common, handleMediaQuickIncrease(editorAnalyticsAPI, widthPlugin, options, getIntl), list);
|
|
26
|
+
bindKeymapWithCommand(quickDecreaseMediaSize.common, handleMediaQuickDecrease(editorAnalyticsAPI, widthPlugin, options, getIntl), list);
|
|
18
27
|
return keymap(list);
|
|
19
28
|
}
|
|
20
29
|
const ignoreLinksInSteps = state => {
|
|
@@ -26,6 +35,82 @@ const splitMediaGroup = state => {
|
|
|
26
35
|
const mediaPluginState = stateKey.getState(state);
|
|
27
36
|
return mediaPluginState.splitMediaGroup();
|
|
28
37
|
};
|
|
38
|
+
const createAnnouncer = (action, mediaWidth, changeAmount, validation, getIntl) => {
|
|
39
|
+
let announcerContainer = document.getElementById('media-announcer') || document.createElement('div');
|
|
40
|
+
const intl = getIntl();
|
|
41
|
+
if (!announcerContainer.id) {
|
|
42
|
+
announcerContainer.id = 'media-announcer';
|
|
43
|
+
announcerContainer.setAttribute('role', 'status');
|
|
44
|
+
announcerContainer.setAttribute('aria-live', 'polite');
|
|
45
|
+
announcerContainer.setAttribute('aria-atomic', 'true');
|
|
46
|
+
const style = announcerContainer.style;
|
|
47
|
+
style.position = 'absolute';
|
|
48
|
+
style.width = '1px';
|
|
49
|
+
style.height = '1px';
|
|
50
|
+
style.marginTop = '-1px';
|
|
51
|
+
style.opacity = '0';
|
|
52
|
+
style.overflow = 'hidden';
|
|
53
|
+
document.body.appendChild(announcerContainer);
|
|
54
|
+
} else {
|
|
55
|
+
const newMediaWidth = mediaWidth + changeAmount;
|
|
56
|
+
if (validation === 'greater-than-max') {
|
|
57
|
+
announcerContainer.textContent = intl.formatMessage(mediaResizeAnnouncerMess.MediaWidthIsMax);
|
|
58
|
+
} else if (validation === 'less-than-min') {
|
|
59
|
+
announcerContainer.textContent = intl.formatMessage(mediaResizeAnnouncerMess.MediaWidthIsMin);
|
|
60
|
+
} else {
|
|
61
|
+
announcerContainer.textContent = intl.formatMessage(mediaResizeAnnouncerMess.DefaultMediaWidth, {
|
|
62
|
+
action: action,
|
|
63
|
+
newMediaWidth: newMediaWidth
|
|
64
|
+
});
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
};
|
|
68
|
+
const handleMediaSizeChange = (editorAnalyticsAPI, widthPlugin, options, changeAmount, action, getIntl) => (state, dispatch) => {
|
|
69
|
+
var _selectedNode$node, _selectedNode$node$at, _selectedNode$node2, _selectedNode$node2$a, _widthPlugin$sharedSt;
|
|
70
|
+
const selectedNode = getSelectedMediaSingle(state);
|
|
71
|
+
const layout = selectedNode === null || selectedNode === void 0 ? void 0 : (_selectedNode$node = selectedNode.node) === null || _selectedNode$node === void 0 ? void 0 : (_selectedNode$node$at = _selectedNode$node.attrs) === null || _selectedNode$node$at === void 0 ? void 0 : _selectedNode$node$at.layout;
|
|
72
|
+
const mediaWidth = selectedNode === null || selectedNode === void 0 ? void 0 : (_selectedNode$node2 = selectedNode.node) === null || _selectedNode$node2 === void 0 ? void 0 : (_selectedNode$node2$a = _selectedNode$node2.attrs) === null || _selectedNode$node2$a === void 0 ? void 0 : _selectedNode$node2$a.width;
|
|
73
|
+
const contentWidth =
|
|
74
|
+
// @ts-ignore readonly sharedState
|
|
75
|
+
(widthPlugin === null || widthPlugin === void 0 ? void 0 : (_widthPlugin$sharedSt = widthPlugin.sharedState.currentState()) === null || _widthPlugin$sharedSt === void 0 ? void 0 : _widthPlugin$sharedSt.lineLength) || akEditorDefaultLayoutWidth;
|
|
76
|
+
const minWidth = MEDIA_SINGLE_DEFAULT_MIN_PIXEL_WIDTH;
|
|
77
|
+
let maxWidth;
|
|
78
|
+
let validation = 'valid';
|
|
79
|
+
let newWidth = mediaWidth + changeAmount;
|
|
80
|
+
const intl = getIntl();
|
|
81
|
+
if (options !== null && options !== void 0 && options.fullWidthEnabled) {
|
|
82
|
+
var _widthPlugin$sharedSt2;
|
|
83
|
+
// @ts-ignore readonly sharedState
|
|
84
|
+
maxWidth = widthPlugin === null || widthPlugin === void 0 ? void 0 : (_widthPlugin$sharedSt2 = widthPlugin.sharedState.currentState()) === null || _widthPlugin$sharedSt2 === void 0 ? void 0 : _widthPlugin$sharedSt2.lineLength;
|
|
85
|
+
} else {
|
|
86
|
+
var _widthPlugin$sharedSt3;
|
|
87
|
+
maxWidth = calcMediaSingleMaxWidth( // @ts-ignore readonly sharedState
|
|
88
|
+
widthPlugin === null || widthPlugin === void 0 ? void 0 : (_widthPlugin$sharedSt3 = widthPlugin.sharedState.currentState()) === null || _widthPlugin$sharedSt3 === void 0 ? void 0 : _widthPlugin$sharedSt3.width);
|
|
89
|
+
}
|
|
90
|
+
if (newWidth > maxWidth) {
|
|
91
|
+
newWidth = maxWidth;
|
|
92
|
+
validation = 'greater-than-max';
|
|
93
|
+
} else if (newWidth < minWidth) {
|
|
94
|
+
newWidth = minWidth;
|
|
95
|
+
validation = 'less-than-min';
|
|
96
|
+
} else {
|
|
97
|
+
newWidth;
|
|
98
|
+
validation = 'valid';
|
|
99
|
+
}
|
|
100
|
+
if (action === 'increased') {
|
|
101
|
+
action = intl.formatMessage(mediaResizeAnnouncerMess.IncreasedAction);
|
|
102
|
+
} else if (action === 'decreased') {
|
|
103
|
+
action = intl.formatMessage(mediaResizeAnnouncerMess.DecreasedAction);
|
|
104
|
+
}
|
|
105
|
+
const newLayout = calcNewLayout(newWidth, layout, contentWidth, options === null || options === void 0 ? void 0 : options.fullWidthEnabled);
|
|
106
|
+
updateMediaSingleWidth(editorAnalyticsAPI)(newWidth, validation, 'keyboard', newLayout)(state, dispatch);
|
|
107
|
+
createAnnouncer(action, mediaWidth, changeAmount, validation, getIntl);
|
|
108
|
+
return true;
|
|
109
|
+
};
|
|
110
|
+
const handleMediaIncrease = (editorAnalyticsAPI, widthPlugin, options, getIntl) => handleMediaSizeChange(editorAnalyticsAPI, widthPlugin, options, 1, 'increased', getIntl);
|
|
111
|
+
const handleMediaDecrease = (editorAnalyticsAPI, widthPlugin, options, getIntl) => handleMediaSizeChange(editorAnalyticsAPI, widthPlugin, options, -1, 'decreased', getIntl);
|
|
112
|
+
const handleMediaQuickIncrease = (editorAnalyticsAPI, widthPlugin, options, getIntl) => handleMediaSizeChange(editorAnalyticsAPI, widthPlugin, options, 10, 'increased', getIntl);
|
|
113
|
+
const handleMediaQuickDecrease = (editorAnalyticsAPI, widthPlugin, options, getIntl) => handleMediaSizeChange(editorAnalyticsAPI, widthPlugin, options, -10, 'decreased', getIntl);
|
|
29
114
|
const insertAndSelectCaption = editorAnalyticsAPI => (state, dispatch) => {
|
|
30
115
|
const {
|
|
31
116
|
selection,
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { defineMessages } from 'react-intl-next';
|
|
2
|
+
export const mediaResizeAnnouncerMess = defineMessages({
|
|
3
|
+
MediaWidthIsMax: {
|
|
4
|
+
id: 'fabric.editor.media.pixelEntry.MediaWidthIsMax',
|
|
5
|
+
defaultMessage: 'Media increased to the maximum size',
|
|
6
|
+
description: 'The media has the maximum allowed width'
|
|
7
|
+
},
|
|
8
|
+
MediaWidthIsMin: {
|
|
9
|
+
id: 'fabric.editor.media.MediaWidthIsMin',
|
|
10
|
+
defaultMessage: 'Media decreased to the minimum size',
|
|
11
|
+
description: 'The media has the minimum allowed width'
|
|
12
|
+
},
|
|
13
|
+
DefaultMediaWidth: {
|
|
14
|
+
id: 'fabric.editor.media.DefaultMediaWidth',
|
|
15
|
+
defaultMessage: 'Media width {action} to {newMediaWidth} pixels.',
|
|
16
|
+
description: 'Media width {action} to {newMediaWidth} pixels.'
|
|
17
|
+
},
|
|
18
|
+
IncreasedAction: {
|
|
19
|
+
id: 'fabric.editor.media.decreased',
|
|
20
|
+
defaultMessage: 'increased',
|
|
21
|
+
description: 'Increased action'
|
|
22
|
+
},
|
|
23
|
+
DecreasedAction: {
|
|
24
|
+
id: 'fabric.editor.media.decreased',
|
|
25
|
+
defaultMessage: 'decreased',
|
|
26
|
+
description: 'Decreased action'
|
|
27
|
+
}
|
|
28
|
+
});
|
|
@@ -181,7 +181,7 @@ export const setBorderMark = editorAnalyticsAPI => attrs => (state, dispatch) =>
|
|
|
181
181
|
}
|
|
182
182
|
return true;
|
|
183
183
|
};
|
|
184
|
-
export const updateMediaSingleWidth = editorAnalyticsAPI => (width, validation, layout) => (state, dispatch) => {
|
|
184
|
+
export const updateMediaSingleWidth = editorAnalyticsAPI => (width, validation, input, layout) => (state, dispatch) => {
|
|
185
185
|
const selectedMediaSingleNode = getSelectedMediaSingle(state);
|
|
186
186
|
if (!selectedMediaSingleNode) {
|
|
187
187
|
return false;
|
|
@@ -324,7 +324,7 @@ const generateMediaSingleFloatingToolbar = (state, intl, options, pluginState, m
|
|
|
324
324
|
}) => {
|
|
325
325
|
var _pluginInjectionApi$a4;
|
|
326
326
|
const newLayout = calcNewLayout(width, layout, contentWidth, options.fullWidthEnabled, isNested);
|
|
327
|
-
updateMediaSingleWidth(pluginInjectionApi === null || pluginInjectionApi === void 0 ? void 0 : (_pluginInjectionApi$a4 = pluginInjectionApi.analytics) === null || _pluginInjectionApi$a4 === void 0 ? void 0 : _pluginInjectionApi$a4.actions)(width, validation, newLayout)(state, dispatch);
|
|
327
|
+
updateMediaSingleWidth(pluginInjectionApi === null || pluginInjectionApi === void 0 ? void 0 : (_pluginInjectionApi$a4 = pluginInjectionApi.analytics) === null || _pluginInjectionApi$a4 === void 0 ? void 0 : _pluginInjectionApi$a4.actions)(width, validation, 'floatingToolBar', newLayout)(state, dispatch);
|
|
328
328
|
},
|
|
329
329
|
onMigrate: () => {
|
|
330
330
|
const tr = state.tr.setNodeMarkup(selectedMediaSingleNode.pos, undefined, {
|
package/dist/esm/plugin.js
CHANGED
|
@@ -47,6 +47,7 @@ export var mediaPlugin = function mediaPlugin(_ref2) {
|
|
|
47
47
|
options = _ref2$config === void 0 ? {} : _ref2$config,
|
|
48
48
|
api = _ref2.api;
|
|
49
49
|
var featureFlags = (api === null || api === void 0 || (_api$featureFlags = api.featureFlags) === null || _api$featureFlags === void 0 ? void 0 : _api$featureFlags.sharedState.currentState()) || {};
|
|
50
|
+
var apiWidth = api === null || api === void 0 ? void 0 : api.width;
|
|
50
51
|
return {
|
|
51
52
|
name: 'media',
|
|
52
53
|
getSharedState: function getSharedState(editorState) {
|
|
@@ -134,16 +135,17 @@ export var mediaPlugin = function mediaPlugin(_ref2) {
|
|
|
134
135
|
}
|
|
135
136
|
}, {
|
|
136
137
|
name: 'mediaKeymap',
|
|
137
|
-
plugin: function plugin() {
|
|
138
|
+
plugin: function plugin(_ref5) {
|
|
138
139
|
var _api$analytics2;
|
|
139
|
-
|
|
140
|
+
var getIntl = _ref5.getIntl;
|
|
141
|
+
return keymapPlugin(options, api === null || api === void 0 || (_api$analytics2 = api.analytics) === null || _api$analytics2 === void 0 ? void 0 : _api$analytics2.actions, api === null || api === void 0 ? void 0 : api.selection.actions, apiWidth, getIntl);
|
|
140
142
|
}
|
|
141
143
|
}];
|
|
142
144
|
if (options && options.allowMediaSingle) {
|
|
143
145
|
pmPlugins.push({
|
|
144
146
|
name: 'mediaSingleKeymap',
|
|
145
|
-
plugin: function plugin(
|
|
146
|
-
var schema =
|
|
147
|
+
plugin: function plugin(_ref6) {
|
|
148
|
+
var schema = _ref6.schema;
|
|
147
149
|
return keymapMediaSinglePlugin(schema);
|
|
148
150
|
}
|
|
149
151
|
});
|
|
@@ -155,9 +157,9 @@ export var mediaPlugin = function mediaPlugin(_ref2) {
|
|
|
155
157
|
});
|
|
156
158
|
pmPlugins.push({
|
|
157
159
|
name: 'mediaAltTextKeymap',
|
|
158
|
-
plugin: function plugin(
|
|
160
|
+
plugin: function plugin(_ref7) {
|
|
159
161
|
var _api$analytics3;
|
|
160
|
-
var schema =
|
|
162
|
+
var schema = _ref7.schema;
|
|
161
163
|
return keymapMediaAltTextPlugin(schema, api === null || api === void 0 || (_api$analytics3 = api.analytics) === null || _api$analytics3 === void 0 ? void 0 : _api$analytics3.actions);
|
|
162
164
|
}
|
|
163
165
|
});
|
|
@@ -165,15 +167,15 @@ export var mediaPlugin = function mediaPlugin(_ref2) {
|
|
|
165
167
|
if (options && options.allowLinking) {
|
|
166
168
|
pmPlugins.push({
|
|
167
169
|
name: 'mediaLinking',
|
|
168
|
-
plugin: function plugin(
|
|
169
|
-
var dispatch =
|
|
170
|
+
plugin: function plugin(_ref8) {
|
|
171
|
+
var dispatch = _ref8.dispatch;
|
|
170
172
|
return linkingPlugin(dispatch);
|
|
171
173
|
}
|
|
172
174
|
});
|
|
173
175
|
pmPlugins.push({
|
|
174
176
|
name: 'mediaLinkingKeymap',
|
|
175
|
-
plugin: function plugin(
|
|
176
|
-
var schema =
|
|
177
|
+
plugin: function plugin(_ref9) {
|
|
178
|
+
var schema = _ref9.schema;
|
|
177
179
|
return keymapLinkingPlugin(schema);
|
|
178
180
|
}
|
|
179
181
|
});
|
|
@@ -209,19 +211,19 @@ export var mediaPlugin = function mediaPlugin(_ref2) {
|
|
|
209
211
|
});
|
|
210
212
|
return pmPlugins;
|
|
211
213
|
},
|
|
212
|
-
contentComponent: function contentComponent(
|
|
213
|
-
var editorView =
|
|
214
|
-
appearance =
|
|
214
|
+
contentComponent: function contentComponent(_ref10) {
|
|
215
|
+
var editorView = _ref10.editorView,
|
|
216
|
+
appearance = _ref10.appearance;
|
|
215
217
|
return /*#__PURE__*/React.createElement(MediaPickerFunctionalComponent, {
|
|
216
218
|
editorDomElement: editorView.dom,
|
|
217
219
|
appearance: appearance,
|
|
218
220
|
api: api
|
|
219
221
|
});
|
|
220
222
|
},
|
|
221
|
-
secondaryToolbarComponent: function secondaryToolbarComponent(
|
|
222
|
-
var editorView =
|
|
223
|
-
eventDispatcher =
|
|
224
|
-
disabled =
|
|
223
|
+
secondaryToolbarComponent: function secondaryToolbarComponent(_ref11) {
|
|
224
|
+
var editorView = _ref11.editorView,
|
|
225
|
+
eventDispatcher = _ref11.eventDispatcher,
|
|
226
|
+
disabled = _ref11.disabled;
|
|
225
227
|
return /*#__PURE__*/React.createElement(ToolbarMedia, {
|
|
226
228
|
isDisabled: disabled,
|
|
227
229
|
isReducedSpacing: true,
|
|
@@ -229,8 +231,8 @@ export var mediaPlugin = function mediaPlugin(_ref2) {
|
|
|
229
231
|
});
|
|
230
232
|
},
|
|
231
233
|
pluginsOptions: {
|
|
232
|
-
quickInsert: function quickInsert(
|
|
233
|
-
var formatMessage =
|
|
234
|
+
quickInsert: function quickInsert(_ref12) {
|
|
235
|
+
var formatMessage = _ref12.formatMessage;
|
|
234
236
|
return [{
|
|
235
237
|
id: 'media',
|
|
236
238
|
title: formatMessage(messages.mediaFiles),
|
|
@@ -1,10 +1,15 @@
|
|
|
1
|
-
import { bindKeymapWithCommand, enter, insertNewLine, moveDown, moveLeft, moveRight, tab, undo } from '@atlaskit/editor-common/keymaps';
|
|
1
|
+
import { bindKeymapWithCommand, decreaseMediaSize, enter, increaseMediaSize, insertNewLine, moveDown, moveLeft, moveRight, quickDecreaseMediaSize, quickIncreaseMediaSize, tab, undo } from '@atlaskit/editor-common/keymaps';
|
|
2
|
+
import { calcMediaSingleMaxWidth, MEDIA_SINGLE_DEFAULT_MIN_PIXEL_WIDTH } from '@atlaskit/editor-common/media-single';
|
|
2
3
|
import { GapCursorSelection, Side } from '@atlaskit/editor-common/selection';
|
|
3
4
|
import { keymap } from '@atlaskit/editor-prosemirror/keymap';
|
|
4
5
|
import { NodeSelection } from '@atlaskit/editor-prosemirror/state';
|
|
6
|
+
import { akEditorDefaultLayoutWidth } from '@atlaskit/editor-shared-styles';
|
|
5
7
|
import { insertAndSelectCaptionFromMediaSinglePos, selectCaptionFromMediaSinglePos } from '../commands/captions';
|
|
6
8
|
import { stateKey } from '../pm-plugins/plugin-key';
|
|
7
|
-
|
|
9
|
+
import { updateMediaSingleWidth } from '../toolbar/commands';
|
|
10
|
+
import { calcNewLayout, getSelectedMediaSingle } from '../toolbar/utils';
|
|
11
|
+
import { mediaResizeAnnouncerMess } from './mediaResizeAnnouncerMess';
|
|
12
|
+
export function keymapPlugin(options, editorAnalyticsAPI, editorSelectionAPI, widthPlugin, getIntl) {
|
|
8
13
|
var list = {};
|
|
9
14
|
bindKeymapWithCommand(undo.common, ignoreLinksInSteps, list);
|
|
10
15
|
bindKeymapWithCommand(enter.common, splitMediaGroup, list);
|
|
@@ -15,6 +20,10 @@ export function keymapPlugin(options, editorAnalyticsAPI, editorSelectionAPI) {
|
|
|
15
20
|
bindKeymapWithCommand(moveRight.common, arrowRightFromMediaSingle(editorSelectionAPI), list);
|
|
16
21
|
}
|
|
17
22
|
bindKeymapWithCommand(insertNewLine.common, splitMediaGroup, list);
|
|
23
|
+
bindKeymapWithCommand(increaseMediaSize.common, handleMediaIncrease(editorAnalyticsAPI, widthPlugin, options, getIntl), list);
|
|
24
|
+
bindKeymapWithCommand(decreaseMediaSize.common, handleMediaDecrease(editorAnalyticsAPI, widthPlugin, options, getIntl), list);
|
|
25
|
+
bindKeymapWithCommand(quickIncreaseMediaSize.common, handleMediaQuickIncrease(editorAnalyticsAPI, widthPlugin, options, getIntl), list);
|
|
26
|
+
bindKeymapWithCommand(quickDecreaseMediaSize.common, handleMediaQuickDecrease(editorAnalyticsAPI, widthPlugin, options, getIntl), list);
|
|
18
27
|
return keymap(list);
|
|
19
28
|
}
|
|
20
29
|
var ignoreLinksInSteps = function ignoreLinksInSteps(state) {
|
|
@@ -26,6 +35,92 @@ var splitMediaGroup = function splitMediaGroup(state) {
|
|
|
26
35
|
var mediaPluginState = stateKey.getState(state);
|
|
27
36
|
return mediaPluginState.splitMediaGroup();
|
|
28
37
|
};
|
|
38
|
+
var createAnnouncer = function createAnnouncer(action, mediaWidth, changeAmount, validation, getIntl) {
|
|
39
|
+
var announcerContainer = document.getElementById('media-announcer') || document.createElement('div');
|
|
40
|
+
var intl = getIntl();
|
|
41
|
+
if (!announcerContainer.id) {
|
|
42
|
+
announcerContainer.id = 'media-announcer';
|
|
43
|
+
announcerContainer.setAttribute('role', 'status');
|
|
44
|
+
announcerContainer.setAttribute('aria-live', 'polite');
|
|
45
|
+
announcerContainer.setAttribute('aria-atomic', 'true');
|
|
46
|
+
var style = announcerContainer.style;
|
|
47
|
+
style.position = 'absolute';
|
|
48
|
+
style.width = '1px';
|
|
49
|
+
style.height = '1px';
|
|
50
|
+
style.marginTop = '-1px';
|
|
51
|
+
style.opacity = '0';
|
|
52
|
+
style.overflow = 'hidden';
|
|
53
|
+
document.body.appendChild(announcerContainer);
|
|
54
|
+
} else {
|
|
55
|
+
var newMediaWidth = mediaWidth + changeAmount;
|
|
56
|
+
if (validation === 'greater-than-max') {
|
|
57
|
+
announcerContainer.textContent = intl.formatMessage(mediaResizeAnnouncerMess.MediaWidthIsMax);
|
|
58
|
+
} else if (validation === 'less-than-min') {
|
|
59
|
+
announcerContainer.textContent = intl.formatMessage(mediaResizeAnnouncerMess.MediaWidthIsMin);
|
|
60
|
+
} else {
|
|
61
|
+
announcerContainer.textContent = intl.formatMessage(mediaResizeAnnouncerMess.DefaultMediaWidth, {
|
|
62
|
+
action: action,
|
|
63
|
+
newMediaWidth: newMediaWidth
|
|
64
|
+
});
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
};
|
|
68
|
+
var handleMediaSizeChange = function handleMediaSizeChange(editorAnalyticsAPI, widthPlugin, options, changeAmount, action, getIntl) {
|
|
69
|
+
return function (state, dispatch) {
|
|
70
|
+
var _selectedNode$node, _selectedNode$node2, _widthPlugin$sharedSt;
|
|
71
|
+
var selectedNode = getSelectedMediaSingle(state);
|
|
72
|
+
var layout = selectedNode === null || selectedNode === void 0 || (_selectedNode$node = selectedNode.node) === null || _selectedNode$node === void 0 || (_selectedNode$node = _selectedNode$node.attrs) === null || _selectedNode$node === void 0 ? void 0 : _selectedNode$node.layout;
|
|
73
|
+
var mediaWidth = selectedNode === null || selectedNode === void 0 || (_selectedNode$node2 = selectedNode.node) === null || _selectedNode$node2 === void 0 || (_selectedNode$node2 = _selectedNode$node2.attrs) === null || _selectedNode$node2 === void 0 ? void 0 : _selectedNode$node2.width;
|
|
74
|
+
var contentWidth =
|
|
75
|
+
// @ts-ignore readonly sharedState
|
|
76
|
+
(widthPlugin === null || widthPlugin === void 0 || (_widthPlugin$sharedSt = widthPlugin.sharedState.currentState()) === null || _widthPlugin$sharedSt === void 0 ? void 0 : _widthPlugin$sharedSt.lineLength) || akEditorDefaultLayoutWidth;
|
|
77
|
+
var minWidth = MEDIA_SINGLE_DEFAULT_MIN_PIXEL_WIDTH;
|
|
78
|
+
var maxWidth;
|
|
79
|
+
var validation = 'valid';
|
|
80
|
+
var newWidth = mediaWidth + changeAmount;
|
|
81
|
+
var intl = getIntl();
|
|
82
|
+
if (options !== null && options !== void 0 && options.fullWidthEnabled) {
|
|
83
|
+
var _widthPlugin$sharedSt2;
|
|
84
|
+
// @ts-ignore readonly sharedState
|
|
85
|
+
maxWidth = widthPlugin === null || widthPlugin === void 0 || (_widthPlugin$sharedSt2 = widthPlugin.sharedState.currentState()) === null || _widthPlugin$sharedSt2 === void 0 ? void 0 : _widthPlugin$sharedSt2.lineLength;
|
|
86
|
+
} else {
|
|
87
|
+
var _widthPlugin$sharedSt3;
|
|
88
|
+
maxWidth = calcMediaSingleMaxWidth( // @ts-ignore readonly sharedState
|
|
89
|
+
widthPlugin === null || widthPlugin === void 0 || (_widthPlugin$sharedSt3 = widthPlugin.sharedState.currentState()) === null || _widthPlugin$sharedSt3 === void 0 ? void 0 : _widthPlugin$sharedSt3.width);
|
|
90
|
+
}
|
|
91
|
+
if (newWidth > maxWidth) {
|
|
92
|
+
newWidth = maxWidth;
|
|
93
|
+
validation = 'greater-than-max';
|
|
94
|
+
} else if (newWidth < minWidth) {
|
|
95
|
+
newWidth = minWidth;
|
|
96
|
+
validation = 'less-than-min';
|
|
97
|
+
} else {
|
|
98
|
+
newWidth;
|
|
99
|
+
validation = 'valid';
|
|
100
|
+
}
|
|
101
|
+
if (action === 'increased') {
|
|
102
|
+
action = intl.formatMessage(mediaResizeAnnouncerMess.IncreasedAction);
|
|
103
|
+
} else if (action === 'decreased') {
|
|
104
|
+
action = intl.formatMessage(mediaResizeAnnouncerMess.DecreasedAction);
|
|
105
|
+
}
|
|
106
|
+
var newLayout = calcNewLayout(newWidth, layout, contentWidth, options === null || options === void 0 ? void 0 : options.fullWidthEnabled);
|
|
107
|
+
updateMediaSingleWidth(editorAnalyticsAPI)(newWidth, validation, 'keyboard', newLayout)(state, dispatch);
|
|
108
|
+
createAnnouncer(action, mediaWidth, changeAmount, validation, getIntl);
|
|
109
|
+
return true;
|
|
110
|
+
};
|
|
111
|
+
};
|
|
112
|
+
var handleMediaIncrease = function handleMediaIncrease(editorAnalyticsAPI, widthPlugin, options, getIntl) {
|
|
113
|
+
return handleMediaSizeChange(editorAnalyticsAPI, widthPlugin, options, 1, 'increased', getIntl);
|
|
114
|
+
};
|
|
115
|
+
var handleMediaDecrease = function handleMediaDecrease(editorAnalyticsAPI, widthPlugin, options, getIntl) {
|
|
116
|
+
return handleMediaSizeChange(editorAnalyticsAPI, widthPlugin, options, -1, 'decreased', getIntl);
|
|
117
|
+
};
|
|
118
|
+
var handleMediaQuickIncrease = function handleMediaQuickIncrease(editorAnalyticsAPI, widthPlugin, options, getIntl) {
|
|
119
|
+
return handleMediaSizeChange(editorAnalyticsAPI, widthPlugin, options, 10, 'increased', getIntl);
|
|
120
|
+
};
|
|
121
|
+
var handleMediaQuickDecrease = function handleMediaQuickDecrease(editorAnalyticsAPI, widthPlugin, options, getIntl) {
|
|
122
|
+
return handleMediaSizeChange(editorAnalyticsAPI, widthPlugin, options, -10, 'decreased', getIntl);
|
|
123
|
+
};
|
|
29
124
|
var insertAndSelectCaption = function insertAndSelectCaption(editorAnalyticsAPI) {
|
|
30
125
|
return function (state, dispatch) {
|
|
31
126
|
var selection = state.selection,
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { defineMessages } from 'react-intl-next';
|
|
2
|
+
export var mediaResizeAnnouncerMess = defineMessages({
|
|
3
|
+
MediaWidthIsMax: {
|
|
4
|
+
id: 'fabric.editor.media.pixelEntry.MediaWidthIsMax',
|
|
5
|
+
defaultMessage: 'Media increased to the maximum size',
|
|
6
|
+
description: 'The media has the maximum allowed width'
|
|
7
|
+
},
|
|
8
|
+
MediaWidthIsMin: {
|
|
9
|
+
id: 'fabric.editor.media.MediaWidthIsMin',
|
|
10
|
+
defaultMessage: 'Media decreased to the minimum size',
|
|
11
|
+
description: 'The media has the minimum allowed width'
|
|
12
|
+
},
|
|
13
|
+
DefaultMediaWidth: {
|
|
14
|
+
id: 'fabric.editor.media.DefaultMediaWidth',
|
|
15
|
+
defaultMessage: 'Media width {action} to {newMediaWidth} pixels.',
|
|
16
|
+
description: 'Media width {action} to {newMediaWidth} pixels.'
|
|
17
|
+
},
|
|
18
|
+
IncreasedAction: {
|
|
19
|
+
id: 'fabric.editor.media.decreased',
|
|
20
|
+
defaultMessage: 'increased',
|
|
21
|
+
description: 'Increased action'
|
|
22
|
+
},
|
|
23
|
+
DecreasedAction: {
|
|
24
|
+
id: 'fabric.editor.media.decreased',
|
|
25
|
+
defaultMessage: 'decreased',
|
|
26
|
+
description: 'Decreased action'
|
|
27
|
+
}
|
|
28
|
+
});
|
|
@@ -196,7 +196,7 @@ export var setBorderMark = function setBorderMark(editorAnalyticsAPI) {
|
|
|
196
196
|
};
|
|
197
197
|
};
|
|
198
198
|
export var updateMediaSingleWidth = function updateMediaSingleWidth(editorAnalyticsAPI) {
|
|
199
|
-
return function (width, validation, layout) {
|
|
199
|
+
return function (width, validation, input, layout) {
|
|
200
200
|
return function (state, dispatch) {
|
|
201
201
|
var selectedMediaSingleNode = getSelectedMediaSingle(state);
|
|
202
202
|
if (!selectedMediaSingleNode) {
|
|
@@ -312,7 +312,7 @@ var generateMediaSingleFloatingToolbar = function generateMediaSingleFloatingToo
|
|
|
312
312
|
var width = _ref2.width,
|
|
313
313
|
validation = _ref2.validation;
|
|
314
314
|
var newLayout = calcNewLayout(width, layout, contentWidth, options.fullWidthEnabled, isNested);
|
|
315
|
-
updateMediaSingleWidth(pluginInjectionApi === null || pluginInjectionApi === void 0 || (_pluginInjectionApi$a4 = pluginInjectionApi.analytics) === null || _pluginInjectionApi$a4 === void 0 ? void 0 : _pluginInjectionApi$a4.actions)(width, validation, newLayout)(state, dispatch);
|
|
315
|
+
updateMediaSingleWidth(pluginInjectionApi === null || pluginInjectionApi === void 0 || (_pluginInjectionApi$a4 = pluginInjectionApi.analytics) === null || _pluginInjectionApi$a4 === void 0 ? void 0 : _pluginInjectionApi$a4.actions)(width, validation, 'floatingToolBar', newLayout)(state, dispatch);
|
|
316
316
|
},
|
|
317
317
|
onMigrate: function onMigrate() {
|
|
318
318
|
var tr = state.tr.setNodeMarkup(selectedMediaSingleNode.pos, undefined, _objectSpread(_objectSpread({}, selectedMediaSingleNode.node.attrs), {}, {
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import type { EditorAnalyticsAPI } from '@atlaskit/editor-common/analytics';
|
|
2
2
|
import type { SafePlugin } from '@atlaskit/editor-common/safe-plugin';
|
|
3
3
|
import type { EditorSelectionAPI } from '@atlaskit/editor-plugin-selection';
|
|
4
|
+
import type { WidthPlugin } from '@atlaskit/editor-plugin-width';
|
|
4
5
|
import type { MediaOptions } from '../types';
|
|
5
|
-
export declare function keymapPlugin(options: MediaOptions | undefined, editorAnalyticsAPI: EditorAnalyticsAPI | undefined, editorSelectionAPI: EditorSelectionAPI | undefined): SafePlugin;
|
|
6
|
+
export declare function keymapPlugin(options: MediaOptions | undefined, editorAnalyticsAPI: EditorAnalyticsAPI | undefined, editorSelectionAPI: EditorSelectionAPI | undefined, widthPlugin: WidthPlugin | undefined, getIntl: any): SafePlugin;
|
|
6
7
|
export default keymapPlugin;
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
export declare const mediaResizeAnnouncerMess: {
|
|
2
|
+
MediaWidthIsMax: {
|
|
3
|
+
id: string;
|
|
4
|
+
defaultMessage: string;
|
|
5
|
+
description: string;
|
|
6
|
+
};
|
|
7
|
+
MediaWidthIsMin: {
|
|
8
|
+
id: string;
|
|
9
|
+
defaultMessage: string;
|
|
10
|
+
description: string;
|
|
11
|
+
};
|
|
12
|
+
DefaultMediaWidth: {
|
|
13
|
+
id: string;
|
|
14
|
+
defaultMessage: string;
|
|
15
|
+
description: string;
|
|
16
|
+
};
|
|
17
|
+
IncreasedAction: {
|
|
18
|
+
id: string;
|
|
19
|
+
defaultMessage: string;
|
|
20
|
+
description: string;
|
|
21
|
+
};
|
|
22
|
+
DecreasedAction: {
|
|
23
|
+
id: string;
|
|
24
|
+
defaultMessage: string;
|
|
25
|
+
description: string;
|
|
26
|
+
};
|
|
27
|
+
};
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import type { BorderMarkAttributes, RichMediaLayout } from '@atlaskit/adf-schema';
|
|
2
2
|
import type { EditorAnalyticsAPI } from '@atlaskit/editor-common/analytics';
|
|
3
3
|
import type { Command } from '@atlaskit/editor-common/types';
|
|
4
|
+
import type { EventInput } from '../pm-plugins/types';
|
|
4
5
|
import type { PixelEntryValidation } from '../ui/PixelEntry/types';
|
|
5
6
|
export declare const DEFAULT_BORDER_COLOR = "#091e4224";
|
|
6
7
|
export declare const DEFAULT_BORDER_SIZE = 2;
|
|
@@ -9,4 +10,4 @@ export declare const changeMediaCardToInline: (editorAnalyticsAPI: EditorAnalyti
|
|
|
9
10
|
export declare const removeInlineCard: Command;
|
|
10
11
|
export declare const toggleBorderMark: (editorAnalyticsAPI: EditorAnalyticsAPI | undefined) => Command;
|
|
11
12
|
export declare const setBorderMark: (editorAnalyticsAPI: EditorAnalyticsAPI | undefined) => (attrs: Partial<BorderMarkAttributes>) => Command;
|
|
12
|
-
export declare const updateMediaSingleWidth: (editorAnalyticsAPI: EditorAnalyticsAPI | undefined) => (width: number, validation: PixelEntryValidation, layout: RichMediaLayout) => Command;
|
|
13
|
+
export declare const updateMediaSingleWidth: (editorAnalyticsAPI: EditorAnalyticsAPI | undefined) => (width: number, validation: PixelEntryValidation, input: EventInput, layout: RichMediaLayout) => Command;
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import type { EditorAnalyticsAPI } from '@atlaskit/editor-common/analytics';
|
|
2
2
|
import type { SafePlugin } from '@atlaskit/editor-common/safe-plugin';
|
|
3
3
|
import type { EditorSelectionAPI } from '@atlaskit/editor-plugin-selection';
|
|
4
|
+
import type { WidthPlugin } from '@atlaskit/editor-plugin-width';
|
|
4
5
|
import type { MediaOptions } from '../types';
|
|
5
|
-
export declare function keymapPlugin(options: MediaOptions | undefined, editorAnalyticsAPI: EditorAnalyticsAPI | undefined, editorSelectionAPI: EditorSelectionAPI | undefined): SafePlugin;
|
|
6
|
+
export declare function keymapPlugin(options: MediaOptions | undefined, editorAnalyticsAPI: EditorAnalyticsAPI | undefined, editorSelectionAPI: EditorSelectionAPI | undefined, widthPlugin: WidthPlugin | undefined, getIntl: any): SafePlugin;
|
|
6
7
|
export default keymapPlugin;
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
export declare const mediaResizeAnnouncerMess: {
|
|
2
|
+
MediaWidthIsMax: {
|
|
3
|
+
id: string;
|
|
4
|
+
defaultMessage: string;
|
|
5
|
+
description: string;
|
|
6
|
+
};
|
|
7
|
+
MediaWidthIsMin: {
|
|
8
|
+
id: string;
|
|
9
|
+
defaultMessage: string;
|
|
10
|
+
description: string;
|
|
11
|
+
};
|
|
12
|
+
DefaultMediaWidth: {
|
|
13
|
+
id: string;
|
|
14
|
+
defaultMessage: string;
|
|
15
|
+
description: string;
|
|
16
|
+
};
|
|
17
|
+
IncreasedAction: {
|
|
18
|
+
id: string;
|
|
19
|
+
defaultMessage: string;
|
|
20
|
+
description: string;
|
|
21
|
+
};
|
|
22
|
+
DecreasedAction: {
|
|
23
|
+
id: string;
|
|
24
|
+
defaultMessage: string;
|
|
25
|
+
description: string;
|
|
26
|
+
};
|
|
27
|
+
};
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import type { BorderMarkAttributes, RichMediaLayout } from '@atlaskit/adf-schema';
|
|
2
2
|
import type { EditorAnalyticsAPI } from '@atlaskit/editor-common/analytics';
|
|
3
3
|
import type { Command } from '@atlaskit/editor-common/types';
|
|
4
|
+
import type { EventInput } from '../pm-plugins/types';
|
|
4
5
|
import type { PixelEntryValidation } from '../ui/PixelEntry/types';
|
|
5
6
|
export declare const DEFAULT_BORDER_COLOR = "#091e4224";
|
|
6
7
|
export declare const DEFAULT_BORDER_SIZE = 2;
|
|
@@ -9,4 +10,4 @@ export declare const changeMediaCardToInline: (editorAnalyticsAPI: EditorAnalyti
|
|
|
9
10
|
export declare const removeInlineCard: Command;
|
|
10
11
|
export declare const toggleBorderMark: (editorAnalyticsAPI: EditorAnalyticsAPI | undefined) => Command;
|
|
11
12
|
export declare const setBorderMark: (editorAnalyticsAPI: EditorAnalyticsAPI | undefined) => (attrs: Partial<BorderMarkAttributes>) => Command;
|
|
12
|
-
export declare const updateMediaSingleWidth: (editorAnalyticsAPI: EditorAnalyticsAPI | undefined) => (width: number, validation: PixelEntryValidation, layout: RichMediaLayout) => Command;
|
|
13
|
+
export declare const updateMediaSingleWidth: (editorAnalyticsAPI: EditorAnalyticsAPI | undefined) => (width: number, validation: PixelEntryValidation, input: EventInput, layout: RichMediaLayout) => Command;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@atlaskit/editor-plugin-media",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.4.0",
|
|
4
4
|
"description": "Media plugin for @atlaskit/editor-core",
|
|
5
5
|
"author": "Atlassian Pty Ltd",
|
|
6
6
|
"license": "Apache-2.0",
|
|
@@ -32,11 +32,11 @@
|
|
|
32
32
|
"./types": "./src/types.ts"
|
|
33
33
|
},
|
|
34
34
|
"dependencies": {
|
|
35
|
-
"@atlaskit/adf-schema": "^
|
|
35
|
+
"@atlaskit/adf-schema": "^33.2.3",
|
|
36
36
|
"@atlaskit/analytics-namespaced-context": "^6.7.0",
|
|
37
37
|
"@atlaskit/analytics-next": "^9.1.0",
|
|
38
38
|
"@atlaskit/button": "^16.16.0",
|
|
39
|
-
"@atlaskit/editor-common": "^76.
|
|
39
|
+
"@atlaskit/editor-common": "^76.22.0",
|
|
40
40
|
"@atlaskit/editor-palette": "1.5.2",
|
|
41
41
|
"@atlaskit/editor-plugin-analytics": "^0.3.0",
|
|
42
42
|
"@atlaskit/editor-plugin-decorations": "^0.2.0",
|