@atlaskit/editor-plugin-media 1.28.1 → 1.28.3

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 CHANGED
@@ -1,5 +1,19 @@
1
1
  # @atlaskit/editor-plugin-media
2
2
 
3
+ ## 1.28.3
4
+
5
+ ### Patch Changes
6
+
7
+ - Updated dependencies
8
+
9
+ ## 1.28.2
10
+
11
+ ### Patch Changes
12
+
13
+ - [#128977](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/pull-requests/128977)
14
+ [`bfcf3686fbc97`](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/commits/bfcf3686fbc97) -
15
+ Improvement to setting media provider performance to only set it once.
16
+
3
17
  ## 1.28.1
4
18
 
5
19
  ### Patch Changes
@@ -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 (_ref2) {
104
+ (0, _defineProperty2.default)(this, "isMediaSchemaNode", function (_ref) {
195
105
  var _this$mediaOptions;
196
- var type = _ref2.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 (_ref3) {
372
- var node = _ref3.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) {
@@ -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
  }
@@ -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 (_ref2) {
89
+ _defineProperty(this, "isMediaSchemaNode", function (_ref) {
180
90
  var _this$mediaOptions;
181
- var type = _ref2.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 (_ref3) {
357
- var node = _ref3.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) {
@@ -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
- setMediaProvider: (mediaProvider?: Promise<MediaProvider>) => Promise<void>;
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;
@@ -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
- setMediaProvider: (mediaProvider?: Promise<MediaProvider>) => Promise<void>;
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;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atlaskit/editor-plugin-media",
3
- "version": "1.28.1",
3
+ "version": "1.28.3",
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.10.0",
38
- "@atlaskit/analytics-next": "^10.0.0",
39
- "@atlaskit/button": "^19.1.0",
40
- "@atlaskit/editor-common": "^87.6.0",
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.10.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.4.0",
57
- "@atlaskit/icon": "^22.11.0",
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.1.0",
62
+ "@atlaskit/media-filmstrip": "^47.2.0",
63
63
  "@atlaskit/media-picker": "^66.4.0",
64
64
  "@atlaskit/media-ui": "^25.10.0",
65
- "@atlaskit/media-viewer": "^48.6.0",
65
+ "@atlaskit/media-viewer": "^48.7.0",
66
66
  "@atlaskit/platform-feature-flags": "^0.3.0",
67
67
  "@atlaskit/primitives": "^12.0.0",
68
- "@atlaskit/textfield": "^6.4.0",
69
- "@atlaskit/theme": "^12.11.0",
70
- "@atlaskit/tokens": "^1.57.0",
71
- "@atlaskit/tooltip": "^18.6.0",
68
+ "@atlaskit/textfield": "^6.5.0",
69
+ "@atlaskit/theme": "^13.0.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",