@atlaskit/editor-plugin-media 1.28.0 → 1.28.2
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 +17 -0
- package/dist/cjs/plugin.js +6 -0
- package/dist/cjs/pm-plugins/main.js +104 -94
- package/dist/cjs/toDOM-fixes/mediaSingle.js +13 -10
- package/dist/cjs/toDOM-fixes/toDOMAttrs.js +5 -9
- package/dist/es2019/plugin.js +6 -0
- package/dist/es2019/pm-plugins/main.js +67 -62
- package/dist/es2019/toDOM-fixes/mediaSingle.js +15 -13
- package/dist/es2019/toDOM-fixes/toDOMAttrs.js +8 -12
- package/dist/esm/plugin.js +6 -0
- package/dist/esm/pm-plugins/main.js +105 -95
- package/dist/esm/toDOM-fixes/mediaSingle.js +14 -11
- package/dist/esm/toDOM-fixes/toDOMAttrs.js +5 -9
- package/dist/types/next-plugin-type.d.ts +4 -1
- package/dist/types/pm-plugins/main.d.ts +2 -1
- package/dist/types/toDOM-fixes/toDOMAttrs.d.ts +0 -7
- package/dist/types-ts4.5/next-plugin-type.d.ts +4 -1
- package/dist/types-ts4.5/pm-plugins/main.d.ts +2 -1
- package/dist/types-ts4.5/toDOM-fixes/toDOMAttrs.d.ts +0 -7
- package/package.json +13 -13
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,22 @@
|
|
|
1
1
|
# @atlaskit/editor-plugin-media
|
|
2
2
|
|
|
3
|
+
## 1.28.2
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- [#128977](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/pull-requests/128977)
|
|
8
|
+
[`bfcf3686fbc97`](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/commits/bfcf3686fbc97) -
|
|
9
|
+
Improvement to setting media provider performance to only set it once.
|
|
10
|
+
|
|
11
|
+
## 1.28.1
|
|
12
|
+
|
|
13
|
+
### Patch Changes
|
|
14
|
+
|
|
15
|
+
- [#128613](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/pull-requests/128613)
|
|
16
|
+
[`9ca6a3874ec07`](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/commits/9ca6a3874ec07) -
|
|
17
|
+
[ED-24516] Fix prepareDiff to avoid toDOM usage
|
|
18
|
+
- Updated dependencies
|
|
19
|
+
|
|
3
20
|
## 1.28.0
|
|
4
21
|
|
|
5
22
|
### Minor Changes
|
package/dist/cjs/plugin.js
CHANGED
|
@@ -59,6 +59,7 @@ var mediaPlugin = exports.mediaPlugin = function mediaPlugin(_ref2) {
|
|
|
59
59
|
var _ref2$config = _ref2.config,
|
|
60
60
|
options = _ref2$config === void 0 ? {} : _ref2$config,
|
|
61
61
|
api = _ref2.api;
|
|
62
|
+
var previousMediaProvider;
|
|
62
63
|
return {
|
|
63
64
|
name: 'media',
|
|
64
65
|
getSharedState: function getSharedState(editorState) {
|
|
@@ -74,6 +75,11 @@ var mediaPlugin = exports.mediaPlugin = function mediaPlugin(_ref2) {
|
|
|
74
75
|
},
|
|
75
76
|
setProvider: function setProvider(provider) {
|
|
76
77
|
var _api$core$actions$exe;
|
|
78
|
+
// Prevent someone trying to set the exact same provider twice for performance reasons
|
|
79
|
+
if (previousMediaProvider === provider) {
|
|
80
|
+
return false;
|
|
81
|
+
}
|
|
82
|
+
previousMediaProvider = provider;
|
|
77
83
|
return (_api$core$actions$exe = api === null || api === void 0 ? void 0 : api.core.actions.execute(function (_ref3) {
|
|
78
84
|
var tr = _ref3.tr;
|
|
79
85
|
return tr.setMeta(_main.stateKey, {
|
|
@@ -98,102 +98,12 @@ var MediaPluginStateImplementation = exports.MediaPluginStateImplementation = /*
|
|
|
98
98
|
(0, _defineProperty2.default)(this, "taskManager", new _mediaTaskManager.MediaTaskManager());
|
|
99
99
|
(0, _defineProperty2.default)(this, "pickers", []);
|
|
100
100
|
(0, _defineProperty2.default)(this, "pickerPromises", []);
|
|
101
|
-
(0, _defineProperty2.default)(this, "setMediaProvider", /*#__PURE__*/function () {
|
|
102
|
-
var _ref = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee(mediaProvider) {
|
|
103
|
-
var viewMediaClientConfig, wrappedError, view, allowsUploads;
|
|
104
|
-
return _regenerator.default.wrap(function _callee$(_context) {
|
|
105
|
-
while (1) switch (_context.prev = _context.next) {
|
|
106
|
-
case 0:
|
|
107
|
-
if (mediaProvider) {
|
|
108
|
-
_context.next = 5;
|
|
109
|
-
break;
|
|
110
|
-
}
|
|
111
|
-
_this.destroyPickers();
|
|
112
|
-
_this.allowsUploads = false;
|
|
113
|
-
if (!_this.destroyed) {
|
|
114
|
-
_this.view.dispatch(_this.view.state.tr.setMeta(_pluginKey.stateKey, {
|
|
115
|
-
allowsUploads: _this.allowsUploads
|
|
116
|
-
}));
|
|
117
|
-
}
|
|
118
|
-
return _context.abrupt("return");
|
|
119
|
-
case 5:
|
|
120
|
-
_context.prev = 5;
|
|
121
|
-
_context.next = 8;
|
|
122
|
-
return mediaProvider;
|
|
123
|
-
case 8:
|
|
124
|
-
_this.mediaProvider = _context.sent;
|
|
125
|
-
// TODO [MS-2038]: remove once context api is removed
|
|
126
|
-
// We want to re assign the view and upload configs if they are missing for backwards compatibility
|
|
127
|
-
// as currently integrators can pass context || mediaClientConfig
|
|
128
|
-
if (!_this.mediaProvider.viewMediaClientConfig) {
|
|
129
|
-
viewMediaClientConfig = _this.mediaProvider.viewMediaClientConfig;
|
|
130
|
-
if (viewMediaClientConfig) {
|
|
131
|
-
_this.mediaProvider.viewMediaClientConfig = viewMediaClientConfig;
|
|
132
|
-
}
|
|
133
|
-
}
|
|
134
|
-
(0, _assert.default)(_this.mediaProvider.viewMediaClientConfig, "MediaProvider promise did not resolve to a valid instance of MediaProvider - ".concat(_this.mediaProvider));
|
|
135
|
-
_context.next = 21;
|
|
136
|
-
break;
|
|
137
|
-
case 13:
|
|
138
|
-
_context.prev = 13;
|
|
139
|
-
_context.t0 = _context["catch"](5);
|
|
140
|
-
wrappedError = new Error("Media functionality disabled due to rejected provider: ".concat(_context.t0 instanceof Error ? _context.t0.message : String(_context.t0)));
|
|
141
|
-
_this.errorReporter.captureException(wrappedError);
|
|
142
|
-
_this.destroyPickers();
|
|
143
|
-
_this.allowsUploads = false;
|
|
144
|
-
if (!_this.destroyed) {
|
|
145
|
-
_this.view.dispatch(_this.view.state.tr.setMeta(_pluginKey.stateKey, {
|
|
146
|
-
allowsUploads: _this.allowsUploads
|
|
147
|
-
}));
|
|
148
|
-
}
|
|
149
|
-
return _context.abrupt("return");
|
|
150
|
-
case 21:
|
|
151
|
-
_this.mediaClientConfig = _this.mediaProvider.viewMediaClientConfig;
|
|
152
|
-
_this.allowsUploads = !!_this.mediaProvider.uploadMediaClientConfig;
|
|
153
|
-
view = _this.view, allowsUploads = _this.allowsUploads; // make sure editable DOM node is mounted
|
|
154
|
-
if (!_this.destroyed && view && view.dom.parentNode) {
|
|
155
|
-
// make PM plugin aware of the state change to update UI during 'apply' hook
|
|
156
|
-
view.dispatch(view.state.tr.setMeta(_pluginKey.stateKey, {
|
|
157
|
-
allowsUploads: allowsUploads
|
|
158
|
-
}));
|
|
159
|
-
}
|
|
160
|
-
if (!_this.allowsUploads) {
|
|
161
|
-
_context.next = 35;
|
|
162
|
-
break;
|
|
163
|
-
}
|
|
164
|
-
_this.uploadMediaClientConfig = _this.mediaProvider.uploadMediaClientConfig;
|
|
165
|
-
if (!(_this.mediaProvider.uploadParams && _this.uploadMediaClientConfig)) {
|
|
166
|
-
_context.next = 32;
|
|
167
|
-
break;
|
|
168
|
-
}
|
|
169
|
-
_context.next = 30;
|
|
170
|
-
return _this.initPickers(_this.mediaProvider.uploadParams, _pickerFacade.default);
|
|
171
|
-
case 30:
|
|
172
|
-
_context.next = 33;
|
|
173
|
-
break;
|
|
174
|
-
case 32:
|
|
175
|
-
_this.destroyPickers();
|
|
176
|
-
case 33:
|
|
177
|
-
_context.next = 36;
|
|
178
|
-
break;
|
|
179
|
-
case 35:
|
|
180
|
-
_this.destroyPickers();
|
|
181
|
-
case 36:
|
|
182
|
-
case "end":
|
|
183
|
-
return _context.stop();
|
|
184
|
-
}
|
|
185
|
-
}, _callee, null, [[5, 13]]);
|
|
186
|
-
}));
|
|
187
|
-
return function (_x) {
|
|
188
|
-
return _ref.apply(this, arguments);
|
|
189
|
-
};
|
|
190
|
-
}());
|
|
191
101
|
(0, _defineProperty2.default)(this, "getMediaOptions", function () {
|
|
192
102
|
return _this.options;
|
|
193
103
|
});
|
|
194
|
-
(0, _defineProperty2.default)(this, "isMediaSchemaNode", function (
|
|
104
|
+
(0, _defineProperty2.default)(this, "isMediaSchemaNode", function (_ref) {
|
|
195
105
|
var _this$mediaOptions;
|
|
196
|
-
var type =
|
|
106
|
+
var type = _ref.type;
|
|
197
107
|
var _this$view$state$sche = _this.view.state.schema.nodes,
|
|
198
108
|
mediaInline = _this$view$state$sche.mediaInline,
|
|
199
109
|
mediaSingle = _this$view$state$sche.mediaSingle,
|
|
@@ -368,8 +278,8 @@ var MediaPluginStateImplementation = exports.MediaPluginStateImplementation = /*
|
|
|
368
278
|
*/
|
|
369
279
|
(0, _defineProperty2.default)(this, "handleMediaNodeUnmount", function (oldNode) {
|
|
370
280
|
_this.trackMediaNodeRemoval(oldNode);
|
|
371
|
-
_this.mediaNodes = _this.mediaNodes.filter(function (
|
|
372
|
-
var node =
|
|
281
|
+
_this.mediaNodes = _this.mediaNodes.filter(function (_ref2) {
|
|
282
|
+
var node = _ref2.node;
|
|
373
283
|
return oldNode !== node;
|
|
374
284
|
});
|
|
375
285
|
});
|
|
@@ -540,6 +450,106 @@ var MediaPluginStateImplementation = exports.MediaPluginStateImplementation = /*
|
|
|
540
450
|
return subscribedFn !== fn;
|
|
541
451
|
});
|
|
542
452
|
}
|
|
453
|
+
}, {
|
|
454
|
+
key: "setMediaProvider",
|
|
455
|
+
value: function () {
|
|
456
|
+
var _setMediaProvider = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee(mediaProvider) {
|
|
457
|
+
var viewMediaClientConfig, wrappedError, view, allowsUploads;
|
|
458
|
+
return _regenerator.default.wrap(function _callee$(_context) {
|
|
459
|
+
while (1) switch (_context.prev = _context.next) {
|
|
460
|
+
case 0:
|
|
461
|
+
if (!(this.previousMediaProvider === mediaProvider)) {
|
|
462
|
+
_context.next = 2;
|
|
463
|
+
break;
|
|
464
|
+
}
|
|
465
|
+
return _context.abrupt("return");
|
|
466
|
+
case 2:
|
|
467
|
+
this.previousMediaProvider = mediaProvider;
|
|
468
|
+
if (mediaProvider) {
|
|
469
|
+
_context.next = 8;
|
|
470
|
+
break;
|
|
471
|
+
}
|
|
472
|
+
this.destroyPickers();
|
|
473
|
+
this.allowsUploads = false;
|
|
474
|
+
if (!this.destroyed) {
|
|
475
|
+
this.view.dispatch(this.view.state.tr.setMeta(_pluginKey.stateKey, {
|
|
476
|
+
allowsUploads: this.allowsUploads
|
|
477
|
+
}));
|
|
478
|
+
}
|
|
479
|
+
return _context.abrupt("return");
|
|
480
|
+
case 8:
|
|
481
|
+
_context.prev = 8;
|
|
482
|
+
_context.next = 11;
|
|
483
|
+
return mediaProvider;
|
|
484
|
+
case 11:
|
|
485
|
+
this.mediaProvider = _context.sent;
|
|
486
|
+
// TODO [MS-2038]: remove once context api is removed
|
|
487
|
+
// We want to re assign the view and upload configs if they are missing for backwards compatibility
|
|
488
|
+
// as currently integrators can pass context || mediaClientConfig
|
|
489
|
+
if (!this.mediaProvider.viewMediaClientConfig) {
|
|
490
|
+
viewMediaClientConfig = this.mediaProvider.viewMediaClientConfig;
|
|
491
|
+
if (viewMediaClientConfig) {
|
|
492
|
+
this.mediaProvider.viewMediaClientConfig = viewMediaClientConfig;
|
|
493
|
+
}
|
|
494
|
+
}
|
|
495
|
+
(0, _assert.default)(this.mediaProvider.viewMediaClientConfig, "MediaProvider promise did not resolve to a valid instance of MediaProvider - ".concat(this.mediaProvider));
|
|
496
|
+
_context.next = 24;
|
|
497
|
+
break;
|
|
498
|
+
case 16:
|
|
499
|
+
_context.prev = 16;
|
|
500
|
+
_context.t0 = _context["catch"](8);
|
|
501
|
+
wrappedError = new Error("Media functionality disabled due to rejected provider: ".concat(_context.t0 instanceof Error ? _context.t0.message : String(_context.t0)));
|
|
502
|
+
this.errorReporter.captureException(wrappedError);
|
|
503
|
+
this.destroyPickers();
|
|
504
|
+
this.allowsUploads = false;
|
|
505
|
+
if (!this.destroyed) {
|
|
506
|
+
this.view.dispatch(this.view.state.tr.setMeta(_pluginKey.stateKey, {
|
|
507
|
+
allowsUploads: this.allowsUploads
|
|
508
|
+
}));
|
|
509
|
+
}
|
|
510
|
+
return _context.abrupt("return");
|
|
511
|
+
case 24:
|
|
512
|
+
this.mediaClientConfig = this.mediaProvider.viewMediaClientConfig;
|
|
513
|
+
this.allowsUploads = !!this.mediaProvider.uploadMediaClientConfig;
|
|
514
|
+
view = this.view, allowsUploads = this.allowsUploads; // make sure editable DOM node is mounted
|
|
515
|
+
if (!this.destroyed && view && view.dom.parentNode) {
|
|
516
|
+
// make PM plugin aware of the state change to update UI during 'apply' hook
|
|
517
|
+
view.dispatch(view.state.tr.setMeta(_pluginKey.stateKey, {
|
|
518
|
+
allowsUploads: allowsUploads
|
|
519
|
+
}));
|
|
520
|
+
}
|
|
521
|
+
if (!this.allowsUploads) {
|
|
522
|
+
_context.next = 38;
|
|
523
|
+
break;
|
|
524
|
+
}
|
|
525
|
+
this.uploadMediaClientConfig = this.mediaProvider.uploadMediaClientConfig;
|
|
526
|
+
if (!(this.mediaProvider.uploadParams && this.uploadMediaClientConfig)) {
|
|
527
|
+
_context.next = 35;
|
|
528
|
+
break;
|
|
529
|
+
}
|
|
530
|
+
_context.next = 33;
|
|
531
|
+
return this.initPickers(this.mediaProvider.uploadParams, _pickerFacade.default);
|
|
532
|
+
case 33:
|
|
533
|
+
_context.next = 36;
|
|
534
|
+
break;
|
|
535
|
+
case 35:
|
|
536
|
+
this.destroyPickers();
|
|
537
|
+
case 36:
|
|
538
|
+
_context.next = 39;
|
|
539
|
+
break;
|
|
540
|
+
case 38:
|
|
541
|
+
this.destroyPickers();
|
|
542
|
+
case 39:
|
|
543
|
+
case "end":
|
|
544
|
+
return _context.stop();
|
|
545
|
+
}
|
|
546
|
+
}, _callee, this, [[8, 16]]);
|
|
547
|
+
}));
|
|
548
|
+
function setMediaProvider(_x) {
|
|
549
|
+
return _setMediaProvider.apply(this, arguments);
|
|
550
|
+
}
|
|
551
|
+
return setMediaProvider;
|
|
552
|
+
}()
|
|
543
553
|
}, {
|
|
544
554
|
key: "setIsResizing",
|
|
545
555
|
value: function setIsResizing(isResizing) {
|
|
@@ -128,14 +128,13 @@ var mediaSingleSpecWithFixedToDOM = exports.mediaSingleSpecWithFixedToDOM = func
|
|
|
128
128
|
}
|
|
129
129
|
return _objectSpread(_objectSpread({}, mediaSingleNode), {}, {
|
|
130
130
|
toDOM: function toDOM(node) {
|
|
131
|
-
var _mediaSingleAttrs$lay
|
|
131
|
+
var _mediaSingleAttrs$lay;
|
|
132
132
|
var childNode = node.firstChild;
|
|
133
133
|
var mediaSingleAttrs = node.attrs;
|
|
134
134
|
var layout = (_mediaSingleAttrs$lay = mediaSingleAttrs === null || mediaSingleAttrs === void 0 ? void 0 : mediaSingleAttrs.layout) !== null && _mediaSingleAttrs$lay !== void 0 ? _mediaSingleAttrs$lay : 'center';
|
|
135
135
|
var mediaSingleWidth = mediaSingleAttrs === null || mediaSingleAttrs === void 0 ? void 0 : mediaSingleAttrs.width;
|
|
136
136
|
var widthType = mediaSingleAttrs === null || mediaSingleAttrs === void 0 ? void 0 : mediaSingleAttrs.widthType;
|
|
137
137
|
var dataAttrs = (0, _toDOMAttrs.getAttrsFromNodeMediaSingle)(mediaSingleOption.withExtendedWidthTypes, node);
|
|
138
|
-
var mediaAttrs = (childNode === null || childNode === void 0 || (_childNode$type = childNode.type) === null || _childNode$type === void 0 ? void 0 : _childNode$type.name) === 'media' ? (0, _toDOMAttrs.getMediaAttrs)('media', childNode) : undefined;
|
|
139
138
|
var _computeMediaSingleDi = computeMediaSingleDimensions({
|
|
140
139
|
childNode: childNode,
|
|
141
140
|
widthType: widthType,
|
|
@@ -145,16 +144,20 @@ var mediaSingleSpecWithFixedToDOM = exports.mediaSingleSpecWithFixedToDOM = func
|
|
|
145
144
|
height = _computeMediaSingleDi.height;
|
|
146
145
|
var layoutStyles = computeLayoutStyles(width, layout);
|
|
147
146
|
var style = "display: block; margin-top: ".concat("var(--ds-space-300, 24px)", "; margin-bottom: ", "var(--ds-space-300, 24px)", "; ", layoutStyles);
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
})]];
|
|
153
|
-
}
|
|
154
|
-
return ['div', dataAttrs, ['div', _objectSpread(_objectSpread({}, mediaAttrs), {}, {
|
|
147
|
+
var content = ['div', _objectSpread({
|
|
148
|
+
class: 'rich-media-item mediaSingleView-content-wrap image-center'
|
|
149
|
+
}, dataAttrs), ['div', {
|
|
150
|
+
class: 'css-13f4nzt-MediaWrapper',
|
|
155
151
|
// Transparent image workaround to control styling
|
|
156
152
|
style: "width: ".concat(width, "px; height: ").concat(height, "px; ").concat(style, " ").concat(skeletonStyling, " border-radius: ", "var(--ds-border-radius, 3px)", ";")
|
|
157
|
-
}
|
|
153
|
+
}, ['figure', {
|
|
154
|
+
class: 'media-single-node'
|
|
155
|
+
}, ['div', {}, ['div', {
|
|
156
|
+
class: 'media-content-wrap'
|
|
157
|
+
}, 0]]]]];
|
|
158
|
+
return ['div', {
|
|
159
|
+
class: 'mediaSingleView-content-wrap'
|
|
160
|
+
}, content];
|
|
158
161
|
}
|
|
159
162
|
});
|
|
160
163
|
};
|
|
@@ -64,17 +64,13 @@ var getAttrsFromNodeMediaSingle = exports.getAttrsFromNodeMediaSingle = function
|
|
|
64
64
|
width = _node$attrs.width;
|
|
65
65
|
var attrs = {
|
|
66
66
|
'data-node-type': 'mediaSingle',
|
|
67
|
-
'data-layout': layout
|
|
68
|
-
'data-width': ''
|
|
67
|
+
'data-layout': layout
|
|
69
68
|
};
|
|
70
69
|
if (width) {
|
|
71
70
|
attrs['data-width'] = isFinite(width) && Math.floor(width) === width ? width : width.toFixed(2);
|
|
72
71
|
}
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
});
|
|
78
|
-
}
|
|
79
|
-
return attrs;
|
|
72
|
+
var widthType = node.attrs.widthType;
|
|
73
|
+
return _objectSpread(_objectSpread({}, attrs), {}, {
|
|
74
|
+
'data-width-type': widthType || 'percentage'
|
|
75
|
+
});
|
|
80
76
|
};
|
package/dist/es2019/plugin.js
CHANGED
|
@@ -49,6 +49,7 @@ export const mediaPlugin = ({
|
|
|
49
49
|
config: options = {},
|
|
50
50
|
api
|
|
51
51
|
}) => {
|
|
52
|
+
let previousMediaProvider;
|
|
52
53
|
return {
|
|
53
54
|
name: 'media',
|
|
54
55
|
getSharedState(editorState) {
|
|
@@ -64,6 +65,11 @@ export const mediaPlugin = ({
|
|
|
64
65
|
},
|
|
65
66
|
setProvider: provider => {
|
|
66
67
|
var _api$core$actions$exe;
|
|
68
|
+
// Prevent someone trying to set the exact same provider twice for performance reasons
|
|
69
|
+
if (previousMediaProvider === provider) {
|
|
70
|
+
return false;
|
|
71
|
+
}
|
|
72
|
+
previousMediaProvider = provider;
|
|
67
73
|
return (_api$core$actions$exe = api === null || api === void 0 ? void 0 : api.core.actions.execute(({
|
|
68
74
|
tr
|
|
69
75
|
}) => tr.setMeta(stateKey, {
|
|
@@ -71,68 +71,6 @@ export class MediaPluginStateImplementation {
|
|
|
71
71
|
_defineProperty(this, "taskManager", new MediaTaskManager());
|
|
72
72
|
_defineProperty(this, "pickers", []);
|
|
73
73
|
_defineProperty(this, "pickerPromises", []);
|
|
74
|
-
_defineProperty(this, "setMediaProvider", async mediaProvider => {
|
|
75
|
-
if (!mediaProvider) {
|
|
76
|
-
this.destroyPickers();
|
|
77
|
-
this.allowsUploads = false;
|
|
78
|
-
if (!this.destroyed) {
|
|
79
|
-
this.view.dispatch(this.view.state.tr.setMeta(stateKey, {
|
|
80
|
-
allowsUploads: this.allowsUploads
|
|
81
|
-
}));
|
|
82
|
-
}
|
|
83
|
-
return;
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
// TODO disable (not destroy!) pickers until mediaProvider is resolved
|
|
87
|
-
try {
|
|
88
|
-
this.mediaProvider = await mediaProvider;
|
|
89
|
-
|
|
90
|
-
// TODO [MS-2038]: remove once context api is removed
|
|
91
|
-
// We want to re assign the view and upload configs if they are missing for backwards compatibility
|
|
92
|
-
// as currently integrators can pass context || mediaClientConfig
|
|
93
|
-
if (!this.mediaProvider.viewMediaClientConfig) {
|
|
94
|
-
const viewMediaClientConfig = this.mediaProvider.viewMediaClientConfig;
|
|
95
|
-
if (viewMediaClientConfig) {
|
|
96
|
-
this.mediaProvider.viewMediaClientConfig = viewMediaClientConfig;
|
|
97
|
-
}
|
|
98
|
-
}
|
|
99
|
-
assert(this.mediaProvider.viewMediaClientConfig, `MediaProvider promise did not resolve to a valid instance of MediaProvider - ${this.mediaProvider}`);
|
|
100
|
-
} catch (err) {
|
|
101
|
-
const wrappedError = new Error(`Media functionality disabled due to rejected provider: ${err instanceof Error ? err.message : String(err)}`);
|
|
102
|
-
this.errorReporter.captureException(wrappedError);
|
|
103
|
-
this.destroyPickers();
|
|
104
|
-
this.allowsUploads = false;
|
|
105
|
-
if (!this.destroyed) {
|
|
106
|
-
this.view.dispatch(this.view.state.tr.setMeta(stateKey, {
|
|
107
|
-
allowsUploads: this.allowsUploads
|
|
108
|
-
}));
|
|
109
|
-
}
|
|
110
|
-
return;
|
|
111
|
-
}
|
|
112
|
-
this.mediaClientConfig = this.mediaProvider.viewMediaClientConfig;
|
|
113
|
-
this.allowsUploads = !!this.mediaProvider.uploadMediaClientConfig;
|
|
114
|
-
const {
|
|
115
|
-
view,
|
|
116
|
-
allowsUploads
|
|
117
|
-
} = this;
|
|
118
|
-
// make sure editable DOM node is mounted
|
|
119
|
-
if (!this.destroyed && view && view.dom.parentNode) {
|
|
120
|
-
// make PM plugin aware of the state change to update UI during 'apply' hook
|
|
121
|
-
view.dispatch(view.state.tr.setMeta(stateKey, {
|
|
122
|
-
allowsUploads
|
|
123
|
-
}));
|
|
124
|
-
}
|
|
125
|
-
if (this.allowsUploads) {
|
|
126
|
-
this.uploadMediaClientConfig = this.mediaProvider.uploadMediaClientConfig;
|
|
127
|
-
if (this.mediaProvider.uploadParams && this.uploadMediaClientConfig) {
|
|
128
|
-
await this.initPickers(this.mediaProvider.uploadParams, PickerFacade);
|
|
129
|
-
} else {
|
|
130
|
-
this.destroyPickers();
|
|
131
|
-
}
|
|
132
|
-
} else {
|
|
133
|
-
this.destroyPickers();
|
|
134
|
-
}
|
|
135
|
-
});
|
|
136
74
|
_defineProperty(this, "getMediaOptions", () => this.options);
|
|
137
75
|
_defineProperty(this, "isMediaSchemaNode", ({
|
|
138
76
|
type
|
|
@@ -475,6 +413,73 @@ export class MediaPluginStateImplementation {
|
|
|
475
413
|
unsubscribeFromUploadInProgressState(fn) {
|
|
476
414
|
this.uploadInProgressSubscriptions = this.uploadInProgressSubscriptions.filter(subscribedFn => subscribedFn !== fn);
|
|
477
415
|
}
|
|
416
|
+
async setMediaProvider(mediaProvider) {
|
|
417
|
+
// Prevent someone trying to set the exact same provider twice for performance reasons
|
|
418
|
+
if (this.previousMediaProvider === mediaProvider) {
|
|
419
|
+
return;
|
|
420
|
+
}
|
|
421
|
+
this.previousMediaProvider = mediaProvider;
|
|
422
|
+
if (!mediaProvider) {
|
|
423
|
+
this.destroyPickers();
|
|
424
|
+
this.allowsUploads = false;
|
|
425
|
+
if (!this.destroyed) {
|
|
426
|
+
this.view.dispatch(this.view.state.tr.setMeta(stateKey, {
|
|
427
|
+
allowsUploads: this.allowsUploads
|
|
428
|
+
}));
|
|
429
|
+
}
|
|
430
|
+
return;
|
|
431
|
+
}
|
|
432
|
+
|
|
433
|
+
// TODO disable (not destroy!) pickers until mediaProvider is resolved
|
|
434
|
+
try {
|
|
435
|
+
this.mediaProvider = await mediaProvider;
|
|
436
|
+
|
|
437
|
+
// TODO [MS-2038]: remove once context api is removed
|
|
438
|
+
// We want to re assign the view and upload configs if they are missing for backwards compatibility
|
|
439
|
+
// as currently integrators can pass context || mediaClientConfig
|
|
440
|
+
if (!this.mediaProvider.viewMediaClientConfig) {
|
|
441
|
+
const viewMediaClientConfig = this.mediaProvider.viewMediaClientConfig;
|
|
442
|
+
if (viewMediaClientConfig) {
|
|
443
|
+
this.mediaProvider.viewMediaClientConfig = viewMediaClientConfig;
|
|
444
|
+
}
|
|
445
|
+
}
|
|
446
|
+
assert(this.mediaProvider.viewMediaClientConfig, `MediaProvider promise did not resolve to a valid instance of MediaProvider - ${this.mediaProvider}`);
|
|
447
|
+
} catch (err) {
|
|
448
|
+
const wrappedError = new Error(`Media functionality disabled due to rejected provider: ${err instanceof Error ? err.message : String(err)}`);
|
|
449
|
+
this.errorReporter.captureException(wrappedError);
|
|
450
|
+
this.destroyPickers();
|
|
451
|
+
this.allowsUploads = false;
|
|
452
|
+
if (!this.destroyed) {
|
|
453
|
+
this.view.dispatch(this.view.state.tr.setMeta(stateKey, {
|
|
454
|
+
allowsUploads: this.allowsUploads
|
|
455
|
+
}));
|
|
456
|
+
}
|
|
457
|
+
return;
|
|
458
|
+
}
|
|
459
|
+
this.mediaClientConfig = this.mediaProvider.viewMediaClientConfig;
|
|
460
|
+
this.allowsUploads = !!this.mediaProvider.uploadMediaClientConfig;
|
|
461
|
+
const {
|
|
462
|
+
view,
|
|
463
|
+
allowsUploads
|
|
464
|
+
} = this;
|
|
465
|
+
// make sure editable DOM node is mounted
|
|
466
|
+
if (!this.destroyed && view && view.dom.parentNode) {
|
|
467
|
+
// make PM plugin aware of the state change to update UI during 'apply' hook
|
|
468
|
+
view.dispatch(view.state.tr.setMeta(stateKey, {
|
|
469
|
+
allowsUploads
|
|
470
|
+
}));
|
|
471
|
+
}
|
|
472
|
+
if (this.allowsUploads) {
|
|
473
|
+
this.uploadMediaClientConfig = this.mediaProvider.uploadMediaClientConfig;
|
|
474
|
+
if (this.mediaProvider.uploadParams && this.uploadMediaClientConfig) {
|
|
475
|
+
await this.initPickers(this.mediaProvider.uploadParams, PickerFacade);
|
|
476
|
+
} else {
|
|
477
|
+
this.destroyPickers();
|
|
478
|
+
}
|
|
479
|
+
} else {
|
|
480
|
+
this.destroyPickers();
|
|
481
|
+
}
|
|
482
|
+
}
|
|
478
483
|
setIsResizing(isResizing) {
|
|
479
484
|
this.isResizing = isResizing;
|
|
480
485
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { mediaSingleSpec } from '@atlaskit/adf-schema';
|
|
2
2
|
import { fg } from '@atlaskit/platform-feature-flags';
|
|
3
|
-
import { getAttrsFromNodeMediaSingle
|
|
3
|
+
import { getAttrsFromNodeMediaSingle } from './toDOMAttrs';
|
|
4
4
|
const skeletonStyling = `background: ${"var(--ds-background-neutral, #091E420F)"}; outline: none;`;
|
|
5
5
|
export const wrappedLayouts = ['wrap-left', 'wrap-right', 'align-end', 'align-start'];
|
|
6
6
|
|
|
@@ -117,14 +117,13 @@ export const mediaSingleSpecWithFixedToDOM = mediaSingleOption => {
|
|
|
117
117
|
return {
|
|
118
118
|
...mediaSingleNode,
|
|
119
119
|
toDOM: node => {
|
|
120
|
-
var _mediaSingleAttrs$lay
|
|
120
|
+
var _mediaSingleAttrs$lay;
|
|
121
121
|
const childNode = node.firstChild;
|
|
122
122
|
const mediaSingleAttrs = node.attrs;
|
|
123
123
|
const layout = (_mediaSingleAttrs$lay = mediaSingleAttrs === null || mediaSingleAttrs === void 0 ? void 0 : mediaSingleAttrs.layout) !== null && _mediaSingleAttrs$lay !== void 0 ? _mediaSingleAttrs$lay : 'center';
|
|
124
124
|
const mediaSingleWidth = mediaSingleAttrs === null || mediaSingleAttrs === void 0 ? void 0 : mediaSingleAttrs.width;
|
|
125
125
|
const widthType = mediaSingleAttrs === null || mediaSingleAttrs === void 0 ? void 0 : mediaSingleAttrs.widthType;
|
|
126
126
|
const dataAttrs = getAttrsFromNodeMediaSingle(mediaSingleOption.withExtendedWidthTypes, node);
|
|
127
|
-
const mediaAttrs = (childNode === null || childNode === void 0 ? void 0 : (_childNode$type = childNode.type) === null || _childNode$type === void 0 ? void 0 : _childNode$type.name) === 'media' ? getMediaAttrs('media', childNode) : undefined;
|
|
128
127
|
const {
|
|
129
128
|
width,
|
|
130
129
|
height
|
|
@@ -135,18 +134,21 @@ export const mediaSingleSpecWithFixedToDOM = mediaSingleOption => {
|
|
|
135
134
|
});
|
|
136
135
|
const layoutStyles = computeLayoutStyles(width, layout);
|
|
137
136
|
const style = `display: block; margin-top: ${"var(--ds-space-300, 24px)"}; margin-bottom: ${"var(--ds-space-300, 24px)"}; ${layoutStyles}`;
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
}]];
|
|
144
|
-
}
|
|
145
|
-
return ['div', dataAttrs, ['div', {
|
|
146
|
-
...mediaAttrs,
|
|
137
|
+
const content = ['div', {
|
|
138
|
+
class: 'rich-media-item mediaSingleView-content-wrap image-center',
|
|
139
|
+
...dataAttrs
|
|
140
|
+
}, ['div', {
|
|
141
|
+
class: 'css-13f4nzt-MediaWrapper',
|
|
147
142
|
// Transparent image workaround to control styling
|
|
148
143
|
style: `width: ${width}px; height: ${height}px; ${style} ${skeletonStyling} border-radius: ${"var(--ds-border-radius, 3px)"};`
|
|
149
|
-
}
|
|
144
|
+
}, ['figure', {
|
|
145
|
+
class: 'media-single-node'
|
|
146
|
+
}, ['div', {}, ['div', {
|
|
147
|
+
class: 'media-content-wrap'
|
|
148
|
+
}, 0]]]]];
|
|
149
|
+
return ['div', {
|
|
150
|
+
class: 'mediaSingleView-content-wrap'
|
|
151
|
+
}, content];
|
|
150
152
|
}
|
|
151
153
|
};
|
|
152
154
|
};
|
|
@@ -50,20 +50,16 @@ export const getAttrsFromNodeMediaSingle = (withExtendedWidthTypes, node) => {
|
|
|
50
50
|
} = node.attrs;
|
|
51
51
|
const attrs = {
|
|
52
52
|
'data-node-type': 'mediaSingle',
|
|
53
|
-
'data-layout': layout
|
|
54
|
-
'data-width': ''
|
|
53
|
+
'data-layout': layout
|
|
55
54
|
};
|
|
56
55
|
if (width) {
|
|
57
56
|
attrs['data-width'] = isFinite(width) && Math.floor(width) === width ? width : width.toFixed(2);
|
|
58
57
|
}
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
};
|
|
67
|
-
}
|
|
68
|
-
return attrs;
|
|
58
|
+
const {
|
|
59
|
+
widthType
|
|
60
|
+
} = node.attrs;
|
|
61
|
+
return {
|
|
62
|
+
...attrs,
|
|
63
|
+
'data-width-type': widthType || 'percentage'
|
|
64
|
+
};
|
|
69
65
|
};
|
package/dist/esm/plugin.js
CHANGED
|
@@ -47,6 +47,7 @@ export var mediaPlugin = function mediaPlugin(_ref2) {
|
|
|
47
47
|
var _ref2$config = _ref2.config,
|
|
48
48
|
options = _ref2$config === void 0 ? {} : _ref2$config,
|
|
49
49
|
api = _ref2.api;
|
|
50
|
+
var previousMediaProvider;
|
|
50
51
|
return {
|
|
51
52
|
name: 'media',
|
|
52
53
|
getSharedState: function getSharedState(editorState) {
|
|
@@ -62,6 +63,11 @@ export var mediaPlugin = function mediaPlugin(_ref2) {
|
|
|
62
63
|
},
|
|
63
64
|
setProvider: function setProvider(provider) {
|
|
64
65
|
var _api$core$actions$exe;
|
|
66
|
+
// Prevent someone trying to set the exact same provider twice for performance reasons
|
|
67
|
+
if (previousMediaProvider === provider) {
|
|
68
|
+
return false;
|
|
69
|
+
}
|
|
70
|
+
previousMediaProvider = provider;
|
|
65
71
|
return (_api$core$actions$exe = api === null || api === void 0 ? void 0 : api.core.actions.execute(function (_ref3) {
|
|
66
72
|
var tr = _ref3.tr;
|
|
67
73
|
return tr.setMeta(stateKey, {
|
|
@@ -5,9 +5,9 @@ import _defineProperty from "@babel/runtime/helpers/defineProperty";
|
|
|
5
5
|
function _createForOfIteratorHelper(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (!it) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e) { throw _e; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var normalCompletion = true, didErr = false, err; return { s: function s() { it = it.call(o); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e2) { didErr = true; err = _e2; }, f: function f() { try { if (!normalCompletion && it.return != null) it.return(); } finally { if (didErr) throw err; } } }; }
|
|
6
6
|
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
|
|
7
7
|
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
|
|
8
|
+
import _regeneratorRuntime from "@babel/runtime/regenerator";
|
|
8
9
|
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
|
9
10
|
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
|
|
10
|
-
import _regeneratorRuntime from "@babel/runtime/regenerator";
|
|
11
11
|
import assert from 'assert';
|
|
12
12
|
import React from 'react';
|
|
13
13
|
import ReactDOM from 'react-dom';
|
|
@@ -83,102 +83,12 @@ export var MediaPluginStateImplementation = /*#__PURE__*/function () {
|
|
|
83
83
|
_defineProperty(this, "taskManager", new MediaTaskManager());
|
|
84
84
|
_defineProperty(this, "pickers", []);
|
|
85
85
|
_defineProperty(this, "pickerPromises", []);
|
|
86
|
-
_defineProperty(this, "setMediaProvider", /*#__PURE__*/function () {
|
|
87
|
-
var _ref = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee(mediaProvider) {
|
|
88
|
-
var viewMediaClientConfig, wrappedError, view, allowsUploads;
|
|
89
|
-
return _regeneratorRuntime.wrap(function _callee$(_context) {
|
|
90
|
-
while (1) switch (_context.prev = _context.next) {
|
|
91
|
-
case 0:
|
|
92
|
-
if (mediaProvider) {
|
|
93
|
-
_context.next = 5;
|
|
94
|
-
break;
|
|
95
|
-
}
|
|
96
|
-
_this.destroyPickers();
|
|
97
|
-
_this.allowsUploads = false;
|
|
98
|
-
if (!_this.destroyed) {
|
|
99
|
-
_this.view.dispatch(_this.view.state.tr.setMeta(stateKey, {
|
|
100
|
-
allowsUploads: _this.allowsUploads
|
|
101
|
-
}));
|
|
102
|
-
}
|
|
103
|
-
return _context.abrupt("return");
|
|
104
|
-
case 5:
|
|
105
|
-
_context.prev = 5;
|
|
106
|
-
_context.next = 8;
|
|
107
|
-
return mediaProvider;
|
|
108
|
-
case 8:
|
|
109
|
-
_this.mediaProvider = _context.sent;
|
|
110
|
-
// TODO [MS-2038]: remove once context api is removed
|
|
111
|
-
// We want to re assign the view and upload configs if they are missing for backwards compatibility
|
|
112
|
-
// as currently integrators can pass context || mediaClientConfig
|
|
113
|
-
if (!_this.mediaProvider.viewMediaClientConfig) {
|
|
114
|
-
viewMediaClientConfig = _this.mediaProvider.viewMediaClientConfig;
|
|
115
|
-
if (viewMediaClientConfig) {
|
|
116
|
-
_this.mediaProvider.viewMediaClientConfig = viewMediaClientConfig;
|
|
117
|
-
}
|
|
118
|
-
}
|
|
119
|
-
assert(_this.mediaProvider.viewMediaClientConfig, "MediaProvider promise did not resolve to a valid instance of MediaProvider - ".concat(_this.mediaProvider));
|
|
120
|
-
_context.next = 21;
|
|
121
|
-
break;
|
|
122
|
-
case 13:
|
|
123
|
-
_context.prev = 13;
|
|
124
|
-
_context.t0 = _context["catch"](5);
|
|
125
|
-
wrappedError = new Error("Media functionality disabled due to rejected provider: ".concat(_context.t0 instanceof Error ? _context.t0.message : String(_context.t0)));
|
|
126
|
-
_this.errorReporter.captureException(wrappedError);
|
|
127
|
-
_this.destroyPickers();
|
|
128
|
-
_this.allowsUploads = false;
|
|
129
|
-
if (!_this.destroyed) {
|
|
130
|
-
_this.view.dispatch(_this.view.state.tr.setMeta(stateKey, {
|
|
131
|
-
allowsUploads: _this.allowsUploads
|
|
132
|
-
}));
|
|
133
|
-
}
|
|
134
|
-
return _context.abrupt("return");
|
|
135
|
-
case 21:
|
|
136
|
-
_this.mediaClientConfig = _this.mediaProvider.viewMediaClientConfig;
|
|
137
|
-
_this.allowsUploads = !!_this.mediaProvider.uploadMediaClientConfig;
|
|
138
|
-
view = _this.view, allowsUploads = _this.allowsUploads; // make sure editable DOM node is mounted
|
|
139
|
-
if (!_this.destroyed && view && view.dom.parentNode) {
|
|
140
|
-
// make PM plugin aware of the state change to update UI during 'apply' hook
|
|
141
|
-
view.dispatch(view.state.tr.setMeta(stateKey, {
|
|
142
|
-
allowsUploads: allowsUploads
|
|
143
|
-
}));
|
|
144
|
-
}
|
|
145
|
-
if (!_this.allowsUploads) {
|
|
146
|
-
_context.next = 35;
|
|
147
|
-
break;
|
|
148
|
-
}
|
|
149
|
-
_this.uploadMediaClientConfig = _this.mediaProvider.uploadMediaClientConfig;
|
|
150
|
-
if (!(_this.mediaProvider.uploadParams && _this.uploadMediaClientConfig)) {
|
|
151
|
-
_context.next = 32;
|
|
152
|
-
break;
|
|
153
|
-
}
|
|
154
|
-
_context.next = 30;
|
|
155
|
-
return _this.initPickers(_this.mediaProvider.uploadParams, PickerFacade);
|
|
156
|
-
case 30:
|
|
157
|
-
_context.next = 33;
|
|
158
|
-
break;
|
|
159
|
-
case 32:
|
|
160
|
-
_this.destroyPickers();
|
|
161
|
-
case 33:
|
|
162
|
-
_context.next = 36;
|
|
163
|
-
break;
|
|
164
|
-
case 35:
|
|
165
|
-
_this.destroyPickers();
|
|
166
|
-
case 36:
|
|
167
|
-
case "end":
|
|
168
|
-
return _context.stop();
|
|
169
|
-
}
|
|
170
|
-
}, _callee, null, [[5, 13]]);
|
|
171
|
-
}));
|
|
172
|
-
return function (_x) {
|
|
173
|
-
return _ref.apply(this, arguments);
|
|
174
|
-
};
|
|
175
|
-
}());
|
|
176
86
|
_defineProperty(this, "getMediaOptions", function () {
|
|
177
87
|
return _this.options;
|
|
178
88
|
});
|
|
179
|
-
_defineProperty(this, "isMediaSchemaNode", function (
|
|
89
|
+
_defineProperty(this, "isMediaSchemaNode", function (_ref) {
|
|
180
90
|
var _this$mediaOptions;
|
|
181
|
-
var type =
|
|
91
|
+
var type = _ref.type;
|
|
182
92
|
var _this$view$state$sche = _this.view.state.schema.nodes,
|
|
183
93
|
mediaInline = _this$view$state$sche.mediaInline,
|
|
184
94
|
mediaSingle = _this$view$state$sche.mediaSingle,
|
|
@@ -353,8 +263,8 @@ export var MediaPluginStateImplementation = /*#__PURE__*/function () {
|
|
|
353
263
|
*/
|
|
354
264
|
_defineProperty(this, "handleMediaNodeUnmount", function (oldNode) {
|
|
355
265
|
_this.trackMediaNodeRemoval(oldNode);
|
|
356
|
-
_this.mediaNodes = _this.mediaNodes.filter(function (
|
|
357
|
-
var node =
|
|
266
|
+
_this.mediaNodes = _this.mediaNodes.filter(function (_ref2) {
|
|
267
|
+
var node = _ref2.node;
|
|
358
268
|
return oldNode !== node;
|
|
359
269
|
});
|
|
360
270
|
});
|
|
@@ -525,6 +435,106 @@ export var MediaPluginStateImplementation = /*#__PURE__*/function () {
|
|
|
525
435
|
return subscribedFn !== fn;
|
|
526
436
|
});
|
|
527
437
|
}
|
|
438
|
+
}, {
|
|
439
|
+
key: "setMediaProvider",
|
|
440
|
+
value: function () {
|
|
441
|
+
var _setMediaProvider = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee(mediaProvider) {
|
|
442
|
+
var viewMediaClientConfig, wrappedError, view, allowsUploads;
|
|
443
|
+
return _regeneratorRuntime.wrap(function _callee$(_context) {
|
|
444
|
+
while (1) switch (_context.prev = _context.next) {
|
|
445
|
+
case 0:
|
|
446
|
+
if (!(this.previousMediaProvider === mediaProvider)) {
|
|
447
|
+
_context.next = 2;
|
|
448
|
+
break;
|
|
449
|
+
}
|
|
450
|
+
return _context.abrupt("return");
|
|
451
|
+
case 2:
|
|
452
|
+
this.previousMediaProvider = mediaProvider;
|
|
453
|
+
if (mediaProvider) {
|
|
454
|
+
_context.next = 8;
|
|
455
|
+
break;
|
|
456
|
+
}
|
|
457
|
+
this.destroyPickers();
|
|
458
|
+
this.allowsUploads = false;
|
|
459
|
+
if (!this.destroyed) {
|
|
460
|
+
this.view.dispatch(this.view.state.tr.setMeta(stateKey, {
|
|
461
|
+
allowsUploads: this.allowsUploads
|
|
462
|
+
}));
|
|
463
|
+
}
|
|
464
|
+
return _context.abrupt("return");
|
|
465
|
+
case 8:
|
|
466
|
+
_context.prev = 8;
|
|
467
|
+
_context.next = 11;
|
|
468
|
+
return mediaProvider;
|
|
469
|
+
case 11:
|
|
470
|
+
this.mediaProvider = _context.sent;
|
|
471
|
+
// TODO [MS-2038]: remove once context api is removed
|
|
472
|
+
// We want to re assign the view and upload configs if they are missing for backwards compatibility
|
|
473
|
+
// as currently integrators can pass context || mediaClientConfig
|
|
474
|
+
if (!this.mediaProvider.viewMediaClientConfig) {
|
|
475
|
+
viewMediaClientConfig = this.mediaProvider.viewMediaClientConfig;
|
|
476
|
+
if (viewMediaClientConfig) {
|
|
477
|
+
this.mediaProvider.viewMediaClientConfig = viewMediaClientConfig;
|
|
478
|
+
}
|
|
479
|
+
}
|
|
480
|
+
assert(this.mediaProvider.viewMediaClientConfig, "MediaProvider promise did not resolve to a valid instance of MediaProvider - ".concat(this.mediaProvider));
|
|
481
|
+
_context.next = 24;
|
|
482
|
+
break;
|
|
483
|
+
case 16:
|
|
484
|
+
_context.prev = 16;
|
|
485
|
+
_context.t0 = _context["catch"](8);
|
|
486
|
+
wrappedError = new Error("Media functionality disabled due to rejected provider: ".concat(_context.t0 instanceof Error ? _context.t0.message : String(_context.t0)));
|
|
487
|
+
this.errorReporter.captureException(wrappedError);
|
|
488
|
+
this.destroyPickers();
|
|
489
|
+
this.allowsUploads = false;
|
|
490
|
+
if (!this.destroyed) {
|
|
491
|
+
this.view.dispatch(this.view.state.tr.setMeta(stateKey, {
|
|
492
|
+
allowsUploads: this.allowsUploads
|
|
493
|
+
}));
|
|
494
|
+
}
|
|
495
|
+
return _context.abrupt("return");
|
|
496
|
+
case 24:
|
|
497
|
+
this.mediaClientConfig = this.mediaProvider.viewMediaClientConfig;
|
|
498
|
+
this.allowsUploads = !!this.mediaProvider.uploadMediaClientConfig;
|
|
499
|
+
view = this.view, allowsUploads = this.allowsUploads; // make sure editable DOM node is mounted
|
|
500
|
+
if (!this.destroyed && view && view.dom.parentNode) {
|
|
501
|
+
// make PM plugin aware of the state change to update UI during 'apply' hook
|
|
502
|
+
view.dispatch(view.state.tr.setMeta(stateKey, {
|
|
503
|
+
allowsUploads: allowsUploads
|
|
504
|
+
}));
|
|
505
|
+
}
|
|
506
|
+
if (!this.allowsUploads) {
|
|
507
|
+
_context.next = 38;
|
|
508
|
+
break;
|
|
509
|
+
}
|
|
510
|
+
this.uploadMediaClientConfig = this.mediaProvider.uploadMediaClientConfig;
|
|
511
|
+
if (!(this.mediaProvider.uploadParams && this.uploadMediaClientConfig)) {
|
|
512
|
+
_context.next = 35;
|
|
513
|
+
break;
|
|
514
|
+
}
|
|
515
|
+
_context.next = 33;
|
|
516
|
+
return this.initPickers(this.mediaProvider.uploadParams, PickerFacade);
|
|
517
|
+
case 33:
|
|
518
|
+
_context.next = 36;
|
|
519
|
+
break;
|
|
520
|
+
case 35:
|
|
521
|
+
this.destroyPickers();
|
|
522
|
+
case 36:
|
|
523
|
+
_context.next = 39;
|
|
524
|
+
break;
|
|
525
|
+
case 38:
|
|
526
|
+
this.destroyPickers();
|
|
527
|
+
case 39:
|
|
528
|
+
case "end":
|
|
529
|
+
return _context.stop();
|
|
530
|
+
}
|
|
531
|
+
}, _callee, this, [[8, 16]]);
|
|
532
|
+
}));
|
|
533
|
+
function setMediaProvider(_x) {
|
|
534
|
+
return _setMediaProvider.apply(this, arguments);
|
|
535
|
+
}
|
|
536
|
+
return setMediaProvider;
|
|
537
|
+
}()
|
|
528
538
|
}, {
|
|
529
539
|
key: "setIsResizing",
|
|
530
540
|
value: function setIsResizing(isResizing) {
|
|
@@ -3,7 +3,7 @@ function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbol
|
|
|
3
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
4
|
import { mediaSingleSpec } from '@atlaskit/adf-schema';
|
|
5
5
|
import { fg } from '@atlaskit/platform-feature-flags';
|
|
6
|
-
import { getAttrsFromNodeMediaSingle
|
|
6
|
+
import { getAttrsFromNodeMediaSingle } from './toDOMAttrs';
|
|
7
7
|
var skeletonStyling = "background: ".concat("var(--ds-background-neutral, #091E420F)", "; outline: none;");
|
|
8
8
|
export var wrappedLayouts = ['wrap-left', 'wrap-right', 'align-end', 'align-start'];
|
|
9
9
|
|
|
@@ -120,14 +120,13 @@ export var mediaSingleSpecWithFixedToDOM = function mediaSingleSpecWithFixedToDO
|
|
|
120
120
|
}
|
|
121
121
|
return _objectSpread(_objectSpread({}, mediaSingleNode), {}, {
|
|
122
122
|
toDOM: function toDOM(node) {
|
|
123
|
-
var _mediaSingleAttrs$lay
|
|
123
|
+
var _mediaSingleAttrs$lay;
|
|
124
124
|
var childNode = node.firstChild;
|
|
125
125
|
var mediaSingleAttrs = node.attrs;
|
|
126
126
|
var layout = (_mediaSingleAttrs$lay = mediaSingleAttrs === null || mediaSingleAttrs === void 0 ? void 0 : mediaSingleAttrs.layout) !== null && _mediaSingleAttrs$lay !== void 0 ? _mediaSingleAttrs$lay : 'center';
|
|
127
127
|
var mediaSingleWidth = mediaSingleAttrs === null || mediaSingleAttrs === void 0 ? void 0 : mediaSingleAttrs.width;
|
|
128
128
|
var widthType = mediaSingleAttrs === null || mediaSingleAttrs === void 0 ? void 0 : mediaSingleAttrs.widthType;
|
|
129
129
|
var dataAttrs = getAttrsFromNodeMediaSingle(mediaSingleOption.withExtendedWidthTypes, node);
|
|
130
|
-
var mediaAttrs = (childNode === null || childNode === void 0 || (_childNode$type = childNode.type) === null || _childNode$type === void 0 ? void 0 : _childNode$type.name) === 'media' ? getMediaAttrs('media', childNode) : undefined;
|
|
131
130
|
var _computeMediaSingleDi = computeMediaSingleDimensions({
|
|
132
131
|
childNode: childNode,
|
|
133
132
|
widthType: widthType,
|
|
@@ -137,16 +136,20 @@ export var mediaSingleSpecWithFixedToDOM = function mediaSingleSpecWithFixedToDO
|
|
|
137
136
|
height = _computeMediaSingleDi.height;
|
|
138
137
|
var layoutStyles = computeLayoutStyles(width, layout);
|
|
139
138
|
var style = "display: block; margin-top: ".concat("var(--ds-space-300, 24px)", "; margin-bottom: ", "var(--ds-space-300, 24px)", "; ", layoutStyles);
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
})]];
|
|
145
|
-
}
|
|
146
|
-
return ['div', dataAttrs, ['div', _objectSpread(_objectSpread({}, mediaAttrs), {}, {
|
|
139
|
+
var content = ['div', _objectSpread({
|
|
140
|
+
class: 'rich-media-item mediaSingleView-content-wrap image-center'
|
|
141
|
+
}, dataAttrs), ['div', {
|
|
142
|
+
class: 'css-13f4nzt-MediaWrapper',
|
|
147
143
|
// Transparent image workaround to control styling
|
|
148
144
|
style: "width: ".concat(width, "px; height: ").concat(height, "px; ").concat(style, " ").concat(skeletonStyling, " border-radius: ", "var(--ds-border-radius, 3px)", ";")
|
|
149
|
-
}
|
|
145
|
+
}, ['figure', {
|
|
146
|
+
class: 'media-single-node'
|
|
147
|
+
}, ['div', {}, ['div', {
|
|
148
|
+
class: 'media-content-wrap'
|
|
149
|
+
}, 0]]]]];
|
|
150
|
+
return ['div', {
|
|
151
|
+
class: 'mediaSingleView-content-wrap'
|
|
152
|
+
}, content];
|
|
150
153
|
}
|
|
151
154
|
});
|
|
152
155
|
};
|
|
@@ -58,17 +58,13 @@ export var getAttrsFromNodeMediaSingle = function getAttrsFromNodeMediaSingle(wi
|
|
|
58
58
|
width = _node$attrs.width;
|
|
59
59
|
var attrs = {
|
|
60
60
|
'data-node-type': 'mediaSingle',
|
|
61
|
-
'data-layout': layout
|
|
62
|
-
'data-width': ''
|
|
61
|
+
'data-layout': layout
|
|
63
62
|
};
|
|
64
63
|
if (width) {
|
|
65
64
|
attrs['data-width'] = isFinite(width) && Math.floor(width) === width ? width : width.toFixed(2);
|
|
66
65
|
}
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
});
|
|
72
|
-
}
|
|
73
|
-
return attrs;
|
|
66
|
+
var widthType = node.attrs.widthType;
|
|
67
|
+
return _objectSpread(_objectSpread({}, attrs), {}, {
|
|
68
|
+
'data-width-type': widthType || 'percentage'
|
|
69
|
+
});
|
|
74
70
|
};
|
|
@@ -35,7 +35,10 @@ export type MediaNextEditorPluginType = NextEditorPlugin<'media', {
|
|
|
35
35
|
actions: {
|
|
36
36
|
insertMediaAsMediaSingle: InsertMediaAsMediaSingle;
|
|
37
37
|
/**
|
|
38
|
-
* Used to update the initial provider passed to the media plugin
|
|
38
|
+
* Used to update the initial provider passed to the media plugin.
|
|
39
|
+
*
|
|
40
|
+
* For performance reasons if you attempt to set the same provider more
|
|
41
|
+
* than once this method will fail and return false.
|
|
39
42
|
*
|
|
40
43
|
* @param provider Promise<MediaProvider>
|
|
41
44
|
* @returns {boolean} if setting the provider was successful or not
|
|
@@ -66,7 +66,8 @@ export declare class MediaPluginStateImplementation implements MediaPluginState
|
|
|
66
66
|
clone(): this;
|
|
67
67
|
subscribeToUploadInProgressState(fn: (isUploading: boolean) => void): void;
|
|
68
68
|
unsubscribeFromUploadInProgressState(fn: (isUploading: boolean) => void): void;
|
|
69
|
-
|
|
69
|
+
private previousMediaProvider;
|
|
70
|
+
setMediaProvider(mediaProvider?: Promise<MediaProvider>): Promise<void>;
|
|
70
71
|
getMediaOptions: () => MediaPluginOptions;
|
|
71
72
|
setIsResizing(isResizing: boolean): void;
|
|
72
73
|
setResizingWidth(width: number): void;
|
|
@@ -24,12 +24,5 @@ export declare const camelCaseToKebabCase: (str: string) => string;
|
|
|
24
24
|
* When we patch adf-schema with media `toDOM` fixes we can remove this.
|
|
25
25
|
*/
|
|
26
26
|
export declare const getAttrsFromNodeMediaSingle: (withExtendedWidthTypes: boolean, node: PMNode) => {
|
|
27
|
-
'data-node-type': string;
|
|
28
|
-
'data-layout': any;
|
|
29
|
-
'data-width': string;
|
|
30
|
-
} | {
|
|
31
27
|
'data-width-type': any;
|
|
32
|
-
'data-node-type': string;
|
|
33
|
-
'data-layout': any;
|
|
34
|
-
'data-width': string;
|
|
35
28
|
};
|
|
@@ -35,7 +35,10 @@ export type MediaNextEditorPluginType = NextEditorPlugin<'media', {
|
|
|
35
35
|
actions: {
|
|
36
36
|
insertMediaAsMediaSingle: InsertMediaAsMediaSingle;
|
|
37
37
|
/**
|
|
38
|
-
* Used to update the initial provider passed to the media plugin
|
|
38
|
+
* Used to update the initial provider passed to the media plugin.
|
|
39
|
+
*
|
|
40
|
+
* For performance reasons if you attempt to set the same provider more
|
|
41
|
+
* than once this method will fail and return false.
|
|
39
42
|
*
|
|
40
43
|
* @param provider Promise<MediaProvider>
|
|
41
44
|
* @returns {boolean} if setting the provider was successful or not
|
|
@@ -66,7 +66,8 @@ export declare class MediaPluginStateImplementation implements MediaPluginState
|
|
|
66
66
|
clone(): this;
|
|
67
67
|
subscribeToUploadInProgressState(fn: (isUploading: boolean) => void): void;
|
|
68
68
|
unsubscribeFromUploadInProgressState(fn: (isUploading: boolean) => void): void;
|
|
69
|
-
|
|
69
|
+
private previousMediaProvider;
|
|
70
|
+
setMediaProvider(mediaProvider?: Promise<MediaProvider>): Promise<void>;
|
|
70
71
|
getMediaOptions: () => MediaPluginOptions;
|
|
71
72
|
setIsResizing(isResizing: boolean): void;
|
|
72
73
|
setResizingWidth(width: number): void;
|
|
@@ -24,12 +24,5 @@ export declare const camelCaseToKebabCase: (str: string) => string;
|
|
|
24
24
|
* When we patch adf-schema with media `toDOM` fixes we can remove this.
|
|
25
25
|
*/
|
|
26
26
|
export declare const getAttrsFromNodeMediaSingle: (withExtendedWidthTypes: boolean, node: PMNode) => {
|
|
27
|
-
'data-node-type': string;
|
|
28
|
-
'data-layout': any;
|
|
29
|
-
'data-width': string;
|
|
30
|
-
} | {
|
|
31
27
|
'data-width-type': any;
|
|
32
|
-
'data-node-type': string;
|
|
33
|
-
'data-layout': any;
|
|
34
|
-
'data-width': string;
|
|
35
28
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@atlaskit/editor-plugin-media",
|
|
3
|
-
"version": "1.28.
|
|
3
|
+
"version": "1.28.2",
|
|
4
4
|
"description": "Media plugin for @atlaskit/editor-core",
|
|
5
5
|
"author": "Atlassian Pty Ltd",
|
|
6
6
|
"license": "Apache-2.0",
|
|
@@ -34,10 +34,10 @@
|
|
|
34
34
|
},
|
|
35
35
|
"dependencies": {
|
|
36
36
|
"@atlaskit/adf-schema": "^40.8.1",
|
|
37
|
-
"@atlaskit/analytics-namespaced-context": "^6.
|
|
38
|
-
"@atlaskit/analytics-next": "^10.
|
|
39
|
-
"@atlaskit/button": "^19.
|
|
40
|
-
"@atlaskit/editor-common": "^87.
|
|
37
|
+
"@atlaskit/analytics-namespaced-context": "^6.11.0",
|
|
38
|
+
"@atlaskit/analytics-next": "^10.1.0",
|
|
39
|
+
"@atlaskit/button": "^19.2.0",
|
|
40
|
+
"@atlaskit/editor-common": "^87.7.0",
|
|
41
41
|
"@atlaskit/editor-palette": "1.6.0",
|
|
42
42
|
"@atlaskit/editor-plugin-analytics": "^1.7.0",
|
|
43
43
|
"@atlaskit/editor-plugin-annotation": "1.19.0",
|
|
@@ -53,22 +53,22 @@
|
|
|
53
53
|
"@atlaskit/editor-prosemirror": "5.0.1",
|
|
54
54
|
"@atlaskit/editor-shared-styles": "^2.13.0",
|
|
55
55
|
"@atlaskit/editor-tables": "^2.8.0",
|
|
56
|
-
"@atlaskit/form": "^10.
|
|
57
|
-
"@atlaskit/icon": "^22.
|
|
56
|
+
"@atlaskit/form": "^10.5.0",
|
|
57
|
+
"@atlaskit/icon": "^22.12.0",
|
|
58
58
|
"@atlaskit/media-card": "^78.0.0",
|
|
59
59
|
"@atlaskit/media-client": "^27.3.0",
|
|
60
60
|
"@atlaskit/media-client-react": "^2.0.0",
|
|
61
61
|
"@atlaskit/media-common": "^11.3.0",
|
|
62
|
-
"@atlaskit/media-filmstrip": "^47.
|
|
62
|
+
"@atlaskit/media-filmstrip": "^47.2.0",
|
|
63
63
|
"@atlaskit/media-picker": "^66.4.0",
|
|
64
64
|
"@atlaskit/media-ui": "^25.10.0",
|
|
65
65
|
"@atlaskit/media-viewer": "^48.6.0",
|
|
66
66
|
"@atlaskit/platform-feature-flags": "^0.3.0",
|
|
67
|
-
"@atlaskit/primitives": "^
|
|
68
|
-
"@atlaskit/textfield": "^6.
|
|
69
|
-
"@atlaskit/theme": "^12.
|
|
70
|
-
"@atlaskit/tokens": "^1.
|
|
71
|
-
"@atlaskit/tooltip": "^18.
|
|
67
|
+
"@atlaskit/primitives": "^12.0.0",
|
|
68
|
+
"@atlaskit/textfield": "^6.5.0",
|
|
69
|
+
"@atlaskit/theme": "^12.12.0",
|
|
70
|
+
"@atlaskit/tokens": "^1.58.0",
|
|
71
|
+
"@atlaskit/tooltip": "^18.7.0",
|
|
72
72
|
"@babel/runtime": "^7.0.0",
|
|
73
73
|
"@emotion/react": "^11.7.1",
|
|
74
74
|
"bind-event-listener": "^3.0.0",
|