@atlaskit/editor-plugin-media 24.0.10 → 24.1.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
CHANGED
|
@@ -1,5 +1,23 @@
|
|
|
1
1
|
# @atlaskit/editor-plugin-media
|
|
2
2
|
|
|
3
|
+
## 24.1.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- [`051cd10867eae`](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/commits/051cd10867eae) -
|
|
8
|
+
Expose uploadStatus and mentionProviderStatus to distinguish pending providers from unavailable
|
|
9
|
+
capabilities. Under platform_editor_ssr_toolbar_optimistic, keep mention and media toolbar buttons
|
|
10
|
+
enabled while providers are pending, avoiding class changes on successful initialization while
|
|
11
|
+
preserving existing insertion restrictions.
|
|
12
|
+
|
|
13
|
+
When a view-only synchronous SSR media provider accompanies a pending full provider, keep uploads
|
|
14
|
+
pending until the full provider resolves instead of treating the SSR config as a permission
|
|
15
|
+
denial.
|
|
16
|
+
|
|
17
|
+
### Patch Changes
|
|
18
|
+
|
|
19
|
+
- Updated dependencies
|
|
20
|
+
|
|
3
21
|
## 24.0.10
|
|
4
22
|
|
|
5
23
|
### Patch Changes
|
|
@@ -28,6 +28,7 @@ var _view3 = require("@atlaskit/editor-prosemirror/view");
|
|
|
28
28
|
var _cellSelection = require("@atlaskit/editor-tables/cell-selection");
|
|
29
29
|
var _mediaClient = require("@atlaskit/media-client");
|
|
30
30
|
var _mediaCommon = require("@atlaskit/media-common");
|
|
31
|
+
var _isExperimentEnabled = require("@atlaskit/platform-feature-experiments/is-experiment-enabled");
|
|
31
32
|
var _mediaNodeUpdater = require("../nodeviews/mediaNodeUpdater");
|
|
32
33
|
var _helpers = _interopRequireWildcard(require("../pm-plugins/commands/helpers"));
|
|
33
34
|
var helpers = _helpers;
|
|
@@ -40,7 +41,7 @@ var _actions = require("./actions");
|
|
|
40
41
|
var _mediaTaskManager = require("./mediaTaskManager");
|
|
41
42
|
var _pickerFacade = _interopRequireDefault(require("./picker-facade"));
|
|
42
43
|
var _pluginKey = require("./plugin-key");
|
|
43
|
-
function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function _interopRequireWildcard(e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, default: e }; if (null === e || "object" != _typeof(e) && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (var
|
|
44
|
+
function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function _interopRequireWildcard(e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, default: e }; if (null === e || "object" != _typeof(e) && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (var _t4 in e) "default" !== _t4 && {}.hasOwnProperty.call(e, _t4) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, _t4)) && (i.get || i.set) ? o(f, _t4, i) : f[_t4] = e[_t4]); return f; })(e, t); }
|
|
44
45
|
function _createForOfIteratorHelper(r, e) { var t = "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (!t) { if (Array.isArray(r) || (t = _unsupportedIterableToArray(r)) || e && r && "number" == typeof r.length) { t && (r = t); var _n = 0, F = function F() {}; return { s: F, n: function n() { return _n >= r.length ? { done: !0 } : { done: !1, value: r[_n++] }; }, e: function e(r) { throw r; }, 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 o, a = !0, u = !1; return { s: function s() { t = t.call(r); }, n: function n() { var r = t.next(); return a = r.done, r; }, e: function e(r) { u = !0, o = r; }, f: function f() { try { a || null == t.return || t.return(); } finally { if (u) throw o; } } }; }
|
|
45
46
|
function _unsupportedIterableToArray(r, a) { if (r) { if ("string" == typeof r) return _arrayLikeToArray(r, a); var t = {}.toString.call(r).slice(8, -1); return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : void 0; } }
|
|
46
47
|
function _arrayLikeToArray(r, a) { (null == a || a > r.length) && (a = r.length); for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e]; return n; }
|
|
@@ -79,6 +80,7 @@ var MediaPluginStateImplementation = exports.MediaPluginStateImplementation = /*
|
|
|
79
80
|
_this$mediaOptions2;
|
|
80
81
|
(0, _classCallCheck2.default)(this, MediaPluginStateImplementation);
|
|
81
82
|
(0, _defineProperty2.default)(this, "allowsUploads", false);
|
|
83
|
+
(0, _defineProperty2.default)(this, "uploadStatus", 'pending');
|
|
82
84
|
(0, _defineProperty2.default)(this, "ignoreLinks", false);
|
|
83
85
|
(0, _defineProperty2.default)(this, "waitForMediaUpload", true);
|
|
84
86
|
(0, _defineProperty2.default)(this, "allUploadsFinished", true);
|
|
@@ -658,7 +660,15 @@ var MediaPluginStateImplementation = exports.MediaPluginStateImplementation = /*
|
|
|
658
660
|
var nodes = _state.schema.nodes;
|
|
659
661
|
(0, _assert.default)(nodes.media && (nodes.mediaGroup || nodes.mediaSingle), 'Editor: unable to init media plugin - media or mediaGroup/mediaSingle node absent in schema');
|
|
660
662
|
if (mediaOptions !== null && mediaOptions !== void 0 && mediaOptions.syncProvider) {
|
|
661
|
-
this.setMediaProvider(mediaOptions
|
|
663
|
+
this.setMediaProvider(mediaOptions.syncProvider);
|
|
664
|
+
if (mediaOptions.provider && (0, _isExperimentEnabled.isExperimentEnabled)('platform_editor_ssr_toolbar_optimistic')) {
|
|
665
|
+
// The synchronous SSR provider may only support viewing. Keep its view
|
|
666
|
+
// config, but wait for the full provider before deciding upload availability.
|
|
667
|
+
if (!this.allowsUploads) {
|
|
668
|
+
this.uploadStatus = 'pending';
|
|
669
|
+
}
|
|
670
|
+
this.setMediaProvider(mediaOptions.provider);
|
|
671
|
+
}
|
|
662
672
|
} else if (mediaOptions !== null && mediaOptions !== void 0 && mediaOptions.provider) {
|
|
663
673
|
this.setMediaProvider(mediaOptions === null || mediaOptions === void 0 ? void 0 : mediaOptions.provider);
|
|
664
674
|
}
|
|
@@ -706,11 +716,11 @@ var MediaPluginStateImplementation = exports.MediaPluginStateImplementation = /*
|
|
|
706
716
|
key: "setMediaProvider",
|
|
707
717
|
value: function () {
|
|
708
718
|
var _setMediaProvider = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee(mediaProvider) {
|
|
709
|
-
var viewMediaClientConfig, wrappedError, view, allowsUploads, _t;
|
|
719
|
+
var resolvedProvider, viewMediaClientConfig, wrappedError, view, allowsUploads, _t, _t2;
|
|
710
720
|
return _regenerator.default.wrap(function (_context) {
|
|
711
721
|
while (1) switch (_context.prev = _context.next) {
|
|
712
722
|
case 0:
|
|
713
|
-
if (!(this.previousMediaProvider === mediaProvider)) {
|
|
723
|
+
if (!(this.previousMediaProvider === mediaProvider && !((0, _isExperimentEnabled.isExperimentEnabled)('platform_editor_ssr_toolbar_optimistic') && this.uploadStatus === 'pending' && !mediaProvider))) {
|
|
714
724
|
_context.next = 1;
|
|
715
725
|
break;
|
|
716
726
|
}
|
|
@@ -723,7 +733,8 @@ var MediaPluginStateImplementation = exports.MediaPluginStateImplementation = /*
|
|
|
723
733
|
}
|
|
724
734
|
this.destroyPickers();
|
|
725
735
|
this.allowsUploads = false;
|
|
726
|
-
|
|
736
|
+
this.uploadStatus = 'unavailable';
|
|
737
|
+
if (!this.destroyed && (this.view || !(0, _isExperimentEnabled.isExperimentEnabled)('platform_editor_ssr_toolbar_optimistic'))) {
|
|
727
738
|
this.view.dispatch(this.view.state.tr.setMeta(_pluginKey.stateKey, {
|
|
728
739
|
allowsUploads: this.allowsUploads
|
|
729
740
|
}));
|
|
@@ -738,12 +749,21 @@ var MediaPluginStateImplementation = exports.MediaPluginStateImplementation = /*
|
|
|
738
749
|
_context.next = 3;
|
|
739
750
|
return mediaProvider;
|
|
740
751
|
case 3:
|
|
741
|
-
|
|
752
|
+
_t = _context.sent;
|
|
742
753
|
_context.next = 5;
|
|
743
754
|
break;
|
|
744
755
|
case 4:
|
|
745
|
-
|
|
756
|
+
_t = mediaProvider;
|
|
746
757
|
case 5:
|
|
758
|
+
resolvedProvider = _t;
|
|
759
|
+
if (!((0, _isExperimentEnabled.isExperimentEnabled)('platform_editor_ssr_toolbar_optimistic') && (this.destroyed || this.previousMediaProvider !== mediaProvider))) {
|
|
760
|
+
_context.next = 6;
|
|
761
|
+
break;
|
|
762
|
+
}
|
|
763
|
+
return _context.abrupt("return");
|
|
764
|
+
case 6:
|
|
765
|
+
this.mediaProvider = resolvedProvider;
|
|
766
|
+
|
|
747
767
|
// Ignored via go/ees007
|
|
748
768
|
// eslint-disable-next-line @atlaskit/editor/enforce-todo-comment-format
|
|
749
769
|
// TODO [MS-2038]: remove once context api is removed
|
|
@@ -756,24 +776,32 @@ var MediaPluginStateImplementation = exports.MediaPluginStateImplementation = /*
|
|
|
756
776
|
}
|
|
757
777
|
}
|
|
758
778
|
(0, _assert.default)(this.mediaProvider.viewMediaClientConfig, "MediaProvider promise did not resolve to a valid instance of MediaProvider - ".concat(this.mediaProvider));
|
|
759
|
-
_context.next =
|
|
779
|
+
_context.next = 9;
|
|
760
780
|
break;
|
|
761
|
-
case
|
|
762
|
-
_context.prev =
|
|
763
|
-
|
|
764
|
-
|
|
781
|
+
case 7:
|
|
782
|
+
_context.prev = 7;
|
|
783
|
+
_t2 = _context["catch"](2);
|
|
784
|
+
if (!((0, _isExperimentEnabled.isExperimentEnabled)('platform_editor_ssr_toolbar_optimistic') && (this.destroyed || this.previousMediaProvider !== mediaProvider))) {
|
|
785
|
+
_context.next = 8;
|
|
786
|
+
break;
|
|
787
|
+
}
|
|
788
|
+
return _context.abrupt("return");
|
|
789
|
+
case 8:
|
|
790
|
+
wrappedError = new Error("Media functionality disabled due to rejected provider: ".concat(_t2 instanceof Error ? _t2.message : String(_t2)));
|
|
765
791
|
this.errorReporter.captureException(wrappedError);
|
|
766
792
|
this.destroyPickers();
|
|
767
793
|
this.allowsUploads = false;
|
|
768
|
-
|
|
794
|
+
this.uploadStatus = 'unavailable';
|
|
795
|
+
if (!this.destroyed && (this.view || !(0, _isExperimentEnabled.isExperimentEnabled)('platform_editor_ssr_toolbar_optimistic'))) {
|
|
769
796
|
this.view.dispatch(this.view.state.tr.setMeta(_pluginKey.stateKey, {
|
|
770
797
|
allowsUploads: this.allowsUploads
|
|
771
798
|
}));
|
|
772
799
|
}
|
|
773
800
|
return _context.abrupt("return");
|
|
774
|
-
case
|
|
801
|
+
case 9:
|
|
775
802
|
this.mediaClientConfig = this.mediaProvider.viewMediaClientConfig;
|
|
776
803
|
this.allowsUploads = !!this.mediaProvider.uploadMediaClientConfig;
|
|
804
|
+
this.uploadStatus = this.allowsUploads ? 'available' : 'unavailable';
|
|
777
805
|
view = this.view, allowsUploads = this.allowsUploads; // make sure editable DOM node is mounted
|
|
778
806
|
if (!this.destroyed && view && view.dom.parentNode) {
|
|
779
807
|
// make PM plugin aware of the state change to update UI during 'apply' hook
|
|
@@ -782,31 +810,31 @@ var MediaPluginStateImplementation = exports.MediaPluginStateImplementation = /*
|
|
|
782
810
|
}));
|
|
783
811
|
}
|
|
784
812
|
if (!this.allowsUploads) {
|
|
785
|
-
_context.next =
|
|
813
|
+
_context.next = 13;
|
|
786
814
|
break;
|
|
787
815
|
}
|
|
788
816
|
this.uploadMediaClientConfig = this.mediaProvider.uploadMediaClientConfig;
|
|
789
817
|
if (!(this.mediaProvider.uploadParams && this.uploadMediaClientConfig)) {
|
|
790
|
-
_context.next =
|
|
818
|
+
_context.next = 11;
|
|
791
819
|
break;
|
|
792
820
|
}
|
|
793
|
-
_context.next = 8;
|
|
794
|
-
return this.initPickers(this.mediaProvider.uploadParams, _pickerFacade.default);
|
|
795
|
-
case 8:
|
|
796
821
|
_context.next = 10;
|
|
797
|
-
|
|
798
|
-
case 9:
|
|
799
|
-
this.destroyPickers();
|
|
822
|
+
return this.initPickers(this.mediaProvider.uploadParams, _pickerFacade.default);
|
|
800
823
|
case 10:
|
|
801
824
|
_context.next = 12;
|
|
802
825
|
break;
|
|
803
826
|
case 11:
|
|
804
827
|
this.destroyPickers();
|
|
805
828
|
case 12:
|
|
829
|
+
_context.next = 14;
|
|
830
|
+
break;
|
|
831
|
+
case 13:
|
|
832
|
+
this.destroyPickers();
|
|
833
|
+
case 14:
|
|
806
834
|
case "end":
|
|
807
835
|
return _context.stop();
|
|
808
836
|
}
|
|
809
|
-
}, _callee, this, [[2,
|
|
837
|
+
}, _callee, this, [[2, 7]]);
|
|
810
838
|
}));
|
|
811
839
|
function setMediaProvider(_x) {
|
|
812
840
|
return _setMediaProvider.apply(this, arguments);
|
|
@@ -906,6 +934,10 @@ var MediaPluginStateImplementation = exports.MediaPluginStateImplementation = /*
|
|
|
906
934
|
key: "setView",
|
|
907
935
|
value: function setView(view) {
|
|
908
936
|
this.view = view;
|
|
937
|
+
if ((0, _isExperimentEnabled.isExperimentEnabled)('platform_editor_ssr_toolbar_optimistic') && this.uploadStatus === 'pending' && !this.previousMediaProvider) {
|
|
938
|
+
// No provider was configured for this client editor. SSR has no view and stays pending.
|
|
939
|
+
this.uploadStatus = 'unavailable';
|
|
940
|
+
}
|
|
909
941
|
}
|
|
910
942
|
}, {
|
|
911
943
|
key: "destroy",
|
|
@@ -924,7 +956,7 @@ var MediaPluginStateImplementation = exports.MediaPluginStateImplementation = /*
|
|
|
924
956
|
value: function () {
|
|
925
957
|
var _initPickers = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee2(uploadParams, Picker) {
|
|
926
958
|
var _this3 = this;
|
|
927
|
-
var errorReporter, pickers, pickerPromises, pickerFacadeConfig, customPicker,
|
|
959
|
+
var errorReporter, pickers, pickerPromises, pickerFacadeConfig, customPicker, _t3;
|
|
928
960
|
return _regenerator.default.wrap(function (_context2) {
|
|
929
961
|
while (1) switch (_context2.prev = _context2.next) {
|
|
930
962
|
case 0:
|
|
@@ -949,11 +981,11 @@ var MediaPluginStateImplementation = exports.MediaPluginStateImplementation = /*
|
|
|
949
981
|
}
|
|
950
982
|
customPicker = new Picker('customMediaPicker', pickerFacadeConfig, this.options.customMediaPicker).init();
|
|
951
983
|
pickerPromises.push(customPicker);
|
|
952
|
-
|
|
984
|
+
_t3 = pickers;
|
|
953
985
|
_context2.next = 2;
|
|
954
986
|
return customPicker;
|
|
955
987
|
case 2:
|
|
956
|
-
|
|
988
|
+
_t3.push.call(_t3, this.customPicker = _context2.sent);
|
|
957
989
|
case 3:
|
|
958
990
|
pickers.forEach(function (picker) {
|
|
959
991
|
picker.onNewMedia(_this3.insertFile);
|
|
@@ -17,6 +17,7 @@ import { Decoration, DecorationSet } from '@atlaskit/editor-prosemirror/view';
|
|
|
17
17
|
import { CellSelection } from '@atlaskit/editor-tables/cell-selection';
|
|
18
18
|
import { isFileIdentifier } from '@atlaskit/media-client';
|
|
19
19
|
import { getMediaFeatureFlag } from '@atlaskit/media-common';
|
|
20
|
+
import { isExperimentEnabled } from '@atlaskit/platform-feature-experiments/is-experiment-enabled';
|
|
20
21
|
import { createMediaNodeUpdater } from '../nodeviews/mediaNodeUpdater';
|
|
21
22
|
// Ignored via go/ees005
|
|
22
23
|
// eslint-disable-next-line import/no-namespace
|
|
@@ -56,6 +57,7 @@ export class MediaPluginStateImplementation {
|
|
|
56
57
|
constructor(_state, options, mediaOptions, _dispatch, pluginInjectionApi) {
|
|
57
58
|
var _this$mediaOptions2;
|
|
58
59
|
_defineProperty(this, "allowsUploads", false);
|
|
60
|
+
_defineProperty(this, "uploadStatus", 'pending');
|
|
59
61
|
_defineProperty(this, "ignoreLinks", false);
|
|
60
62
|
_defineProperty(this, "waitForMediaUpload", true);
|
|
61
63
|
_defineProperty(this, "allUploadsFinished", true);
|
|
@@ -649,7 +651,15 @@ export class MediaPluginStateImplementation {
|
|
|
649
651
|
} = _state.schema;
|
|
650
652
|
assert(nodes.media && (nodes.mediaGroup || nodes.mediaSingle), 'Editor: unable to init media plugin - media or mediaGroup/mediaSingle node absent in schema');
|
|
651
653
|
if (mediaOptions !== null && mediaOptions !== void 0 && mediaOptions.syncProvider) {
|
|
652
|
-
this.setMediaProvider(mediaOptions
|
|
654
|
+
this.setMediaProvider(mediaOptions.syncProvider);
|
|
655
|
+
if (mediaOptions.provider && isExperimentEnabled('platform_editor_ssr_toolbar_optimistic')) {
|
|
656
|
+
// The synchronous SSR provider may only support viewing. Keep its view
|
|
657
|
+
// config, but wait for the full provider before deciding upload availability.
|
|
658
|
+
if (!this.allowsUploads) {
|
|
659
|
+
this.uploadStatus = 'pending';
|
|
660
|
+
}
|
|
661
|
+
this.setMediaProvider(mediaOptions.provider);
|
|
662
|
+
}
|
|
653
663
|
} else if (mediaOptions !== null && mediaOptions !== void 0 && mediaOptions.provider) {
|
|
654
664
|
this.setMediaProvider(mediaOptions === null || mediaOptions === void 0 ? void 0 : mediaOptions.provider);
|
|
655
665
|
}
|
|
@@ -687,14 +697,15 @@ export class MediaPluginStateImplementation {
|
|
|
687
697
|
}
|
|
688
698
|
async setMediaProvider(mediaProvider) {
|
|
689
699
|
// Prevent someone trying to set the exact same provider twice for performance reasons
|
|
690
|
-
if (this.previousMediaProvider === mediaProvider) {
|
|
700
|
+
if (this.previousMediaProvider === mediaProvider && !(isExperimentEnabled('platform_editor_ssr_toolbar_optimistic') && this.uploadStatus === 'pending' && !mediaProvider)) {
|
|
691
701
|
return;
|
|
692
702
|
}
|
|
693
703
|
this.previousMediaProvider = mediaProvider;
|
|
694
704
|
if (!mediaProvider) {
|
|
695
705
|
this.destroyPickers();
|
|
696
706
|
this.allowsUploads = false;
|
|
697
|
-
|
|
707
|
+
this.uploadStatus = 'unavailable';
|
|
708
|
+
if (!this.destroyed && (this.view || !isExperimentEnabled('platform_editor_ssr_toolbar_optimistic'))) {
|
|
698
709
|
this.view.dispatch(this.view.state.tr.setMeta(stateKey, {
|
|
699
710
|
allowsUploads: this.allowsUploads
|
|
700
711
|
}));
|
|
@@ -706,11 +717,11 @@ export class MediaPluginStateImplementation {
|
|
|
706
717
|
// eslint-disable-next-line @atlaskit/editor/enforce-todo-comment-format
|
|
707
718
|
// TODO disable (not destroy!) pickers until mediaProvider is resolved
|
|
708
719
|
try {
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
|
|
712
|
-
this.mediaProvider = mediaProvider;
|
|
720
|
+
const resolvedProvider = mediaProvider instanceof Promise ? await mediaProvider : mediaProvider;
|
|
721
|
+
if (isExperimentEnabled('platform_editor_ssr_toolbar_optimistic') && (this.destroyed || this.previousMediaProvider !== mediaProvider)) {
|
|
722
|
+
return;
|
|
713
723
|
}
|
|
724
|
+
this.mediaProvider = resolvedProvider;
|
|
714
725
|
|
|
715
726
|
// Ignored via go/ees007
|
|
716
727
|
// eslint-disable-next-line @atlaskit/editor/enforce-todo-comment-format
|
|
@@ -725,11 +736,15 @@ export class MediaPluginStateImplementation {
|
|
|
725
736
|
}
|
|
726
737
|
assert(this.mediaProvider.viewMediaClientConfig, `MediaProvider promise did not resolve to a valid instance of MediaProvider - ${this.mediaProvider}`);
|
|
727
738
|
} catch (err) {
|
|
739
|
+
if (isExperimentEnabled('platform_editor_ssr_toolbar_optimistic') && (this.destroyed || this.previousMediaProvider !== mediaProvider)) {
|
|
740
|
+
return;
|
|
741
|
+
}
|
|
728
742
|
const wrappedError = new Error(`Media functionality disabled due to rejected provider: ${err instanceof Error ? err.message : String(err)}`);
|
|
729
743
|
this.errorReporter.captureException(wrappedError);
|
|
730
744
|
this.destroyPickers();
|
|
731
745
|
this.allowsUploads = false;
|
|
732
|
-
|
|
746
|
+
this.uploadStatus = 'unavailable';
|
|
747
|
+
if (!this.destroyed && (this.view || !isExperimentEnabled('platform_editor_ssr_toolbar_optimistic'))) {
|
|
733
748
|
this.view.dispatch(this.view.state.tr.setMeta(stateKey, {
|
|
734
749
|
allowsUploads: this.allowsUploads
|
|
735
750
|
}));
|
|
@@ -738,6 +753,7 @@ export class MediaPluginStateImplementation {
|
|
|
738
753
|
}
|
|
739
754
|
this.mediaClientConfig = this.mediaProvider.viewMediaClientConfig;
|
|
740
755
|
this.allowsUploads = !!this.mediaProvider.uploadMediaClientConfig;
|
|
756
|
+
this.uploadStatus = this.allowsUploads ? 'available' : 'unavailable';
|
|
741
757
|
const {
|
|
742
758
|
view,
|
|
743
759
|
allowsUploads
|
|
@@ -841,6 +857,10 @@ export class MediaPluginStateImplementation {
|
|
|
841
857
|
}
|
|
842
858
|
setView(view) {
|
|
843
859
|
this.view = view;
|
|
860
|
+
if (isExperimentEnabled('platform_editor_ssr_toolbar_optimistic') && this.uploadStatus === 'pending' && !this.previousMediaProvider) {
|
|
861
|
+
// No provider was configured for this client editor. SSR has no view and stays pending.
|
|
862
|
+
this.uploadStatus = 'unavailable';
|
|
863
|
+
}
|
|
844
864
|
}
|
|
845
865
|
destroy() {
|
|
846
866
|
if (this.destroyed) {
|
|
@@ -26,6 +26,7 @@ import { Decoration, DecorationSet } from '@atlaskit/editor-prosemirror/view';
|
|
|
26
26
|
import { CellSelection } from '@atlaskit/editor-tables/cell-selection';
|
|
27
27
|
import { isFileIdentifier } from '@atlaskit/media-client';
|
|
28
28
|
import { getMediaFeatureFlag } from '@atlaskit/media-common';
|
|
29
|
+
import { isExperimentEnabled } from '@atlaskit/platform-feature-experiments/is-experiment-enabled';
|
|
29
30
|
import { createMediaNodeUpdater } from '../nodeviews/mediaNodeUpdater';
|
|
30
31
|
// Ignored via go/ees005
|
|
31
32
|
// eslint-disable-next-line import/no-namespace
|
|
@@ -71,6 +72,7 @@ export var MediaPluginStateImplementation = /*#__PURE__*/function () {
|
|
|
71
72
|
_this$mediaOptions2;
|
|
72
73
|
_classCallCheck(this, MediaPluginStateImplementation);
|
|
73
74
|
_defineProperty(this, "allowsUploads", false);
|
|
75
|
+
_defineProperty(this, "uploadStatus", 'pending');
|
|
74
76
|
_defineProperty(this, "ignoreLinks", false);
|
|
75
77
|
_defineProperty(this, "waitForMediaUpload", true);
|
|
76
78
|
_defineProperty(this, "allUploadsFinished", true);
|
|
@@ -650,7 +652,15 @@ export var MediaPluginStateImplementation = /*#__PURE__*/function () {
|
|
|
650
652
|
var nodes = _state.schema.nodes;
|
|
651
653
|
assert(nodes.media && (nodes.mediaGroup || nodes.mediaSingle), 'Editor: unable to init media plugin - media or mediaGroup/mediaSingle node absent in schema');
|
|
652
654
|
if (mediaOptions !== null && mediaOptions !== void 0 && mediaOptions.syncProvider) {
|
|
653
|
-
this.setMediaProvider(mediaOptions
|
|
655
|
+
this.setMediaProvider(mediaOptions.syncProvider);
|
|
656
|
+
if (mediaOptions.provider && isExperimentEnabled('platform_editor_ssr_toolbar_optimistic')) {
|
|
657
|
+
// The synchronous SSR provider may only support viewing. Keep its view
|
|
658
|
+
// config, but wait for the full provider before deciding upload availability.
|
|
659
|
+
if (!this.allowsUploads) {
|
|
660
|
+
this.uploadStatus = 'pending';
|
|
661
|
+
}
|
|
662
|
+
this.setMediaProvider(mediaOptions.provider);
|
|
663
|
+
}
|
|
654
664
|
} else if (mediaOptions !== null && mediaOptions !== void 0 && mediaOptions.provider) {
|
|
655
665
|
this.setMediaProvider(mediaOptions === null || mediaOptions === void 0 ? void 0 : mediaOptions.provider);
|
|
656
666
|
}
|
|
@@ -698,11 +708,11 @@ export var MediaPluginStateImplementation = /*#__PURE__*/function () {
|
|
|
698
708
|
key: "setMediaProvider",
|
|
699
709
|
value: function () {
|
|
700
710
|
var _setMediaProvider = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee(mediaProvider) {
|
|
701
|
-
var viewMediaClientConfig, wrappedError, view, allowsUploads, _t;
|
|
711
|
+
var resolvedProvider, viewMediaClientConfig, wrappedError, view, allowsUploads, _t, _t2;
|
|
702
712
|
return _regeneratorRuntime.wrap(function (_context) {
|
|
703
713
|
while (1) switch (_context.prev = _context.next) {
|
|
704
714
|
case 0:
|
|
705
|
-
if (!(this.previousMediaProvider === mediaProvider)) {
|
|
715
|
+
if (!(this.previousMediaProvider === mediaProvider && !(isExperimentEnabled('platform_editor_ssr_toolbar_optimistic') && this.uploadStatus === 'pending' && !mediaProvider))) {
|
|
706
716
|
_context.next = 1;
|
|
707
717
|
break;
|
|
708
718
|
}
|
|
@@ -715,7 +725,8 @@ export var MediaPluginStateImplementation = /*#__PURE__*/function () {
|
|
|
715
725
|
}
|
|
716
726
|
this.destroyPickers();
|
|
717
727
|
this.allowsUploads = false;
|
|
718
|
-
|
|
728
|
+
this.uploadStatus = 'unavailable';
|
|
729
|
+
if (!this.destroyed && (this.view || !isExperimentEnabled('platform_editor_ssr_toolbar_optimistic'))) {
|
|
719
730
|
this.view.dispatch(this.view.state.tr.setMeta(stateKey, {
|
|
720
731
|
allowsUploads: this.allowsUploads
|
|
721
732
|
}));
|
|
@@ -730,12 +741,21 @@ export var MediaPluginStateImplementation = /*#__PURE__*/function () {
|
|
|
730
741
|
_context.next = 3;
|
|
731
742
|
return mediaProvider;
|
|
732
743
|
case 3:
|
|
733
|
-
|
|
744
|
+
_t = _context.sent;
|
|
734
745
|
_context.next = 5;
|
|
735
746
|
break;
|
|
736
747
|
case 4:
|
|
737
|
-
|
|
748
|
+
_t = mediaProvider;
|
|
738
749
|
case 5:
|
|
750
|
+
resolvedProvider = _t;
|
|
751
|
+
if (!(isExperimentEnabled('platform_editor_ssr_toolbar_optimistic') && (this.destroyed || this.previousMediaProvider !== mediaProvider))) {
|
|
752
|
+
_context.next = 6;
|
|
753
|
+
break;
|
|
754
|
+
}
|
|
755
|
+
return _context.abrupt("return");
|
|
756
|
+
case 6:
|
|
757
|
+
this.mediaProvider = resolvedProvider;
|
|
758
|
+
|
|
739
759
|
// Ignored via go/ees007
|
|
740
760
|
// eslint-disable-next-line @atlaskit/editor/enforce-todo-comment-format
|
|
741
761
|
// TODO [MS-2038]: remove once context api is removed
|
|
@@ -748,24 +768,32 @@ export var MediaPluginStateImplementation = /*#__PURE__*/function () {
|
|
|
748
768
|
}
|
|
749
769
|
}
|
|
750
770
|
assert(this.mediaProvider.viewMediaClientConfig, "MediaProvider promise did not resolve to a valid instance of MediaProvider - ".concat(this.mediaProvider));
|
|
751
|
-
_context.next =
|
|
771
|
+
_context.next = 9;
|
|
752
772
|
break;
|
|
753
|
-
case
|
|
754
|
-
_context.prev =
|
|
755
|
-
|
|
756
|
-
|
|
773
|
+
case 7:
|
|
774
|
+
_context.prev = 7;
|
|
775
|
+
_t2 = _context["catch"](2);
|
|
776
|
+
if (!(isExperimentEnabled('platform_editor_ssr_toolbar_optimistic') && (this.destroyed || this.previousMediaProvider !== mediaProvider))) {
|
|
777
|
+
_context.next = 8;
|
|
778
|
+
break;
|
|
779
|
+
}
|
|
780
|
+
return _context.abrupt("return");
|
|
781
|
+
case 8:
|
|
782
|
+
wrappedError = new Error("Media functionality disabled due to rejected provider: ".concat(_t2 instanceof Error ? _t2.message : String(_t2)));
|
|
757
783
|
this.errorReporter.captureException(wrappedError);
|
|
758
784
|
this.destroyPickers();
|
|
759
785
|
this.allowsUploads = false;
|
|
760
|
-
|
|
786
|
+
this.uploadStatus = 'unavailable';
|
|
787
|
+
if (!this.destroyed && (this.view || !isExperimentEnabled('platform_editor_ssr_toolbar_optimistic'))) {
|
|
761
788
|
this.view.dispatch(this.view.state.tr.setMeta(stateKey, {
|
|
762
789
|
allowsUploads: this.allowsUploads
|
|
763
790
|
}));
|
|
764
791
|
}
|
|
765
792
|
return _context.abrupt("return");
|
|
766
|
-
case
|
|
793
|
+
case 9:
|
|
767
794
|
this.mediaClientConfig = this.mediaProvider.viewMediaClientConfig;
|
|
768
795
|
this.allowsUploads = !!this.mediaProvider.uploadMediaClientConfig;
|
|
796
|
+
this.uploadStatus = this.allowsUploads ? 'available' : 'unavailable';
|
|
769
797
|
view = this.view, allowsUploads = this.allowsUploads; // make sure editable DOM node is mounted
|
|
770
798
|
if (!this.destroyed && view && view.dom.parentNode) {
|
|
771
799
|
// make PM plugin aware of the state change to update UI during 'apply' hook
|
|
@@ -774,31 +802,31 @@ export var MediaPluginStateImplementation = /*#__PURE__*/function () {
|
|
|
774
802
|
}));
|
|
775
803
|
}
|
|
776
804
|
if (!this.allowsUploads) {
|
|
777
|
-
_context.next =
|
|
805
|
+
_context.next = 13;
|
|
778
806
|
break;
|
|
779
807
|
}
|
|
780
808
|
this.uploadMediaClientConfig = this.mediaProvider.uploadMediaClientConfig;
|
|
781
809
|
if (!(this.mediaProvider.uploadParams && this.uploadMediaClientConfig)) {
|
|
782
|
-
_context.next =
|
|
810
|
+
_context.next = 11;
|
|
783
811
|
break;
|
|
784
812
|
}
|
|
785
|
-
_context.next = 8;
|
|
786
|
-
return this.initPickers(this.mediaProvider.uploadParams, PickerFacade);
|
|
787
|
-
case 8:
|
|
788
813
|
_context.next = 10;
|
|
789
|
-
|
|
790
|
-
case 9:
|
|
791
|
-
this.destroyPickers();
|
|
814
|
+
return this.initPickers(this.mediaProvider.uploadParams, PickerFacade);
|
|
792
815
|
case 10:
|
|
793
816
|
_context.next = 12;
|
|
794
817
|
break;
|
|
795
818
|
case 11:
|
|
796
819
|
this.destroyPickers();
|
|
797
820
|
case 12:
|
|
821
|
+
_context.next = 14;
|
|
822
|
+
break;
|
|
823
|
+
case 13:
|
|
824
|
+
this.destroyPickers();
|
|
825
|
+
case 14:
|
|
798
826
|
case "end":
|
|
799
827
|
return _context.stop();
|
|
800
828
|
}
|
|
801
|
-
}, _callee, this, [[2,
|
|
829
|
+
}, _callee, this, [[2, 7]]);
|
|
802
830
|
}));
|
|
803
831
|
function setMediaProvider(_x) {
|
|
804
832
|
return _setMediaProvider.apply(this, arguments);
|
|
@@ -898,6 +926,10 @@ export var MediaPluginStateImplementation = /*#__PURE__*/function () {
|
|
|
898
926
|
key: "setView",
|
|
899
927
|
value: function setView(view) {
|
|
900
928
|
this.view = view;
|
|
929
|
+
if (isExperimentEnabled('platform_editor_ssr_toolbar_optimistic') && this.uploadStatus === 'pending' && !this.previousMediaProvider) {
|
|
930
|
+
// No provider was configured for this client editor. SSR has no view and stays pending.
|
|
931
|
+
this.uploadStatus = 'unavailable';
|
|
932
|
+
}
|
|
901
933
|
}
|
|
902
934
|
}, {
|
|
903
935
|
key: "destroy",
|
|
@@ -916,7 +948,7 @@ export var MediaPluginStateImplementation = /*#__PURE__*/function () {
|
|
|
916
948
|
value: function () {
|
|
917
949
|
var _initPickers = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee2(uploadParams, Picker) {
|
|
918
950
|
var _this3 = this;
|
|
919
|
-
var errorReporter, pickers, pickerPromises, pickerFacadeConfig, customPicker,
|
|
951
|
+
var errorReporter, pickers, pickerPromises, pickerFacadeConfig, customPicker, _t3;
|
|
920
952
|
return _regeneratorRuntime.wrap(function (_context2) {
|
|
921
953
|
while (1) switch (_context2.prev = _context2.next) {
|
|
922
954
|
case 0:
|
|
@@ -941,11 +973,11 @@ export var MediaPluginStateImplementation = /*#__PURE__*/function () {
|
|
|
941
973
|
}
|
|
942
974
|
customPicker = new Picker('customMediaPicker', pickerFacadeConfig, this.options.customMediaPicker).init();
|
|
943
975
|
pickerPromises.push(customPicker);
|
|
944
|
-
|
|
976
|
+
_t3 = pickers;
|
|
945
977
|
_context2.next = 2;
|
|
946
978
|
return customPicker;
|
|
947
979
|
case 2:
|
|
948
|
-
|
|
980
|
+
_t3.push.call(_t3, this.customPicker = _context2.sent);
|
|
949
981
|
case 3:
|
|
950
982
|
pickers.forEach(function (picker) {
|
|
951
983
|
picker.onNewMedia(_this3.insertFile);
|
|
@@ -21,6 +21,7 @@ export declare const MEDIA_PLUGIN_IS_RESIZING_KEY = "mediaSinglePlugin.isResizin
|
|
|
21
21
|
export declare const MEDIA_PLUGIN_RESIZING_WIDTH_KEY = "mediaSinglePlugin.resizing-width";
|
|
22
22
|
export declare class MediaPluginStateImplementation implements MediaPluginState {
|
|
23
23
|
allowsUploads: boolean;
|
|
24
|
+
uploadStatus: 'pending' | 'available' | 'unavailable';
|
|
24
25
|
mediaClientConfig?: MediaClientConfig;
|
|
25
26
|
uploadMediaClientConfig?: MediaClientConfig;
|
|
26
27
|
ignoreLinks: boolean;
|
|
@@ -76,6 +76,8 @@ export interface MediaPluginState {
|
|
|
76
76
|
updateElement: () => void;
|
|
77
77
|
updateMediaSingleNodeAttrs: (id: string, attrs: object) => undefined | boolean;
|
|
78
78
|
uploadMediaClientConfig?: MediaClientConfig;
|
|
79
|
+
/** Initial upload capability resolution; does not grant permission to upload. */
|
|
80
|
+
uploadStatus?: 'pending' | 'available' | 'unavailable';
|
|
79
81
|
videoControlsWrapperRef?: HTMLElement;
|
|
80
82
|
waitForMediaUpload: boolean;
|
|
81
83
|
waitForPendingTasks: (timeout?: number, lastTask?: Promise<MediaState | null>) => Promise<MediaState | null>;
|