@atlaskit/media-picker 66.1.5 → 66.2.1

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,39 @@
1
1
  # @atlaskit/media-picker
2
2
 
3
+ ## 66.2.1
4
+
5
+ ### Patch Changes
6
+
7
+ - [`ede6ee7aaab`](https://bitbucket.org/atlassian/atlassian-frontend/commits/ede6ee7aaab) - Updated tests, examples and moving towards /test-helper export in packages to prevent circular dependancies
8
+ - Updated dependencies
9
+
10
+ ## 66.2.0
11
+
12
+ ### Minor Changes
13
+
14
+ - [`b06cd74349c`](https://bitbucket.org/atlassian/atlassian-frontend/commits/b06cd74349c) - # Media Picker
15
+
16
+ Make Clipboard secured by adding `container` and `onPaste()` to `config` `prop`. These two params address customer dissatisfaction when attachments are pasted duplicated, or to unwanted Jira issues (https://product-fabric.atlassian.net/browse/MEX-2454).
17
+
18
+ Note for migration:
19
+ The added `container` parameter sets a boundary for copy-paste zone. This is to filter out noise from existing practice that is problematic. **To ensure the effectiveness of this fix, please avoid using global `document` as `container` in best effort; please avoid overlapped boundary in best effort**.
20
+
21
+ When `container` is not added, the behaviour falls back to legacy mechanism.
22
+
23
+ # Media Common
24
+
25
+ Add feature toggle (`securedClipboard` in `MediaFeatureFlags`) to control the rollout of Secured Clipboard (https://product-fabric.atlassian.net/browse/MEX-2454).
26
+
27
+ # Editor Core
28
+
29
+ Add support of the Secured Clipboard (https://product-fabric.atlassian.net/browse/MEX-2454).
30
+
31
+ Use feature flag `securedClipboard` to protect such change.
32
+
33
+ ### Patch Changes
34
+
35
+ - Updated dependencies
36
+
3
37
  ## 66.1.5
4
38
 
5
39
  ### Patch Changes
@@ -39,9 +39,36 @@ var defaultConfig = {
39
39
  };
40
40
  var COMPONENT_NAME = 'clipboard';
41
41
  var ClipboardImpl = /*#__PURE__*/function () {
42
- function ClipboardImpl(uploadService, createAnalyticsEvent, featureFlags) {
42
+ function ClipboardImpl(uploadService, container, onPaste, createAnalyticsEvent, featureFlags) {
43
+ var _this = this;
43
44
  (0, _classCallCheck2.default)(this, ClipboardImpl);
45
+ (0, _defineProperty2.default)(this, "handleEvent", function (event) {
46
+ var _this$onPaste;
47
+ var clipboardData = event.clipboardData;
48
+ if ((_this$onPaste = _this.onPaste) !== null && _this$onPaste !== void 0 && _this$onPaste.call(_this, event)) {
49
+ return;
50
+ }
51
+
52
+ // From https://product-fabric.atlassian.net/browse/MEX-1281 ,disable the handler if event target is input
53
+ if (event.target instanceof HTMLInputElement) {
54
+ return;
55
+ }
56
+ if (clipboardData && clipboardData.files) {
57
+ var fileSource = clipboardData.types.length === 1 ? _types.LocalFileSource.PastedScreenshot : _types.LocalFileSource.PastedFile;
58
+ var filesArray = getFilesFromClipboard(clipboardData.files).map(function (file) {
59
+ return {
60
+ file: file,
61
+ source: fileSource
62
+ };
63
+ });
64
+ if (filesArray.length > 0) {
65
+ _this.onFilesPasted(filesArray);
66
+ }
67
+ }
68
+ });
44
69
  this.uploadService = uploadService;
70
+ this.container = container;
71
+ this.onPaste = onPaste;
45
72
  this.createAnalyticsEvent = createAnalyticsEvent;
46
73
  this.featureFlags = featureFlags;
47
74
  }
@@ -49,22 +76,30 @@ var ClipboardImpl = /*#__PURE__*/function () {
49
76
  key: "activate",
50
77
  value: function activate() {
51
78
  this.deactivate();
52
- document.addEventListener('paste', ClipboardImpl.handleEvent);
53
- ClipboardImpl.instances.push(this);
79
+ if (!this.container) {
80
+ document.addEventListener('paste', ClipboardImpl.legacyHandleEvent);
81
+ ClipboardImpl.instances.push(this);
82
+ } else {
83
+ this.container.addEventListener('paste', this.handleEvent);
84
+ }
54
85
  }
55
86
  }, {
56
87
  key: "deactivate",
57
88
  value: function deactivate() {
58
- var index = ClipboardImpl.instances.indexOf(this);
59
- if (index > -1) {
60
- ClipboardImpl.instances.splice(index, 1);
89
+ if (!this.container) {
90
+ var index = ClipboardImpl.instances.indexOf(this);
91
+ if (index > -1) {
92
+ ClipboardImpl.instances.splice(index, 1);
93
+ } else {
94
+ /**
95
+ * We want to remove the handleEvent only when there are no more instances.
96
+ * Since handleEvent is static, if we remove it right away, and there is still an active instance,
97
+ * we will loose the clipboard functionality.
98
+ */
99
+ document.removeEventListener('paste', ClipboardImpl.legacyHandleEvent);
100
+ }
61
101
  } else {
62
- /**
63
- * We want to remove the handleEvent only when there are no more instances.
64
- * Since handleEvent is static, if we remove it right away, and there is still an active instance,
65
- * we will loose the clipboard functionality.
66
- */
67
- document.removeEventListener('paste', ClipboardImpl.handleEvent);
102
+ this.container.removeEventListener('paste', this.handleEvent);
68
103
  }
69
104
  }
70
105
  }, {
@@ -100,6 +135,10 @@ var ClipboardImpl = /*#__PURE__*/function () {
100
135
  analyticsEvent.fire(_mediaCommon.ANALYTICS_MEDIA_CHANNEL);
101
136
  }
102
137
  }
138
+
139
+ // The existing (semi)singleton (last in `instances`) event handler is proven to be problematic
140
+ // Replaced with the new mechanism in https://product-fabric.atlassian.net/browse/MEX-2454
141
+ // Remove after product adoption / rollout
103
142
  }], [{
104
143
  key: "latestInstance",
105
144
  get: function get() {
@@ -109,7 +148,7 @@ var ClipboardImpl = /*#__PURE__*/function () {
109
148
  return ClipboardImpl;
110
149
  }();
111
150
  (0, _defineProperty2.default)(ClipboardImpl, "instances", []);
112
- (0, _defineProperty2.default)(ClipboardImpl, "handleEvent", function (event) {
151
+ (0, _defineProperty2.default)(ClipboardImpl, "legacyHandleEvent", function (event) {
113
152
  // From https://product-fabric.atlassian.net/browse/MEX-1281 ,disable the handler if event target is input
114
153
  if (event.target instanceof HTMLInputElement) {
115
154
  return;
@@ -144,11 +183,11 @@ var ClipboardBase = /*#__PURE__*/function (_LocalUploadComponent) {
144
183
  (0, _inherits2.default)(ClipboardBase, _LocalUploadComponent);
145
184
  var _super = _createSuper(ClipboardBase);
146
185
  function ClipboardBase(props) {
147
- var _this;
186
+ var _this2;
148
187
  (0, _classCallCheck2.default)(this, ClipboardBase);
149
- _this = _super.call(this, props, COMPONENT_NAME);
150
- _this.clipboard = new ClipboardImpl(_this.uploadService, _this.props.createAnalyticsEvent, props.featureFlags);
151
- return _this;
188
+ _this2 = _super.call(this, props, COMPONENT_NAME);
189
+ _this2.clipboard = new ClipboardImpl(_this2.uploadService, _this2.props.config.container, _this2.props.config.onPaste, _this2.props.createAnalyticsEvent, props.featureFlags);
190
+ return _this2;
152
191
  }
153
192
  (0, _createClass2.default)(ClipboardBase, [{
154
193
  key: "componentDidMount",
@@ -12,8 +12,8 @@ var _crossCircle = _interopRequireDefault(require("@atlaskit/icon/glyph/cross-ci
12
12
  var _colors = require("@atlaskit/theme/colors");
13
13
  var _messages = require("./messages");
14
14
  var _reactIntlNext = require("react-intl-next");
15
- function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
16
- function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { (0, _defineProperty2.default)(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
15
+ 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; }
16
+ 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) { (0, _defineProperty2.default)(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; }
17
17
  var defaultOptions = {
18
18
  style: 'unit',
19
19
  unitDisplay: 'short',
@@ -9,7 +9,7 @@ var _mediaClient = require("@atlaskit/media-client");
9
9
  // Component name will be prefixed with "media-picker-" in logs. Check ufoExperiences in utils files
10
10
 
11
11
  var packageName = "@atlaskit/media-picker";
12
- var packageVersion = "66.1.5";
12
+ var packageVersion = "66.2.1";
13
13
  function getPackageAttributes(componentName) {
14
14
  return {
15
15
  packageName: packageName,
@@ -9,10 +9,10 @@ var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/de
9
9
  var _ufo = require("@atlaskit/ufo");
10
10
  var _mediaCommon = require("@atlaskit/media-common");
11
11
  var _mediaClient = require("@atlaskit/media-client");
12
- function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
13
- function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { (0, _defineProperty2.default)(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
12
+ 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; }
13
+ 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) { (0, _defineProperty2.default)(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; }
14
14
  var packageName = "@atlaskit/media-picker";
15
- var packageVersion = "66.1.5";
15
+ var packageVersion = "66.2.1";
16
16
  var ufoExperience;
17
17
  var initExperience = function initExperience(id, componentName) {
18
18
  if (!ufoExperience) {
@@ -24,8 +24,34 @@ const defaultConfig = {
24
24
  };
25
25
  const COMPONENT_NAME = 'clipboard';
26
26
  class ClipboardImpl {
27
- constructor(uploadService, createAnalyticsEvent, featureFlags) {
27
+ constructor(uploadService, container, onPaste, createAnalyticsEvent, featureFlags) {
28
+ _defineProperty(this, "handleEvent", event => {
29
+ var _this$onPaste;
30
+ const {
31
+ clipboardData
32
+ } = event;
33
+ if ((_this$onPaste = this.onPaste) !== null && _this$onPaste !== void 0 && _this$onPaste.call(this, event)) {
34
+ return;
35
+ }
36
+
37
+ // From https://product-fabric.atlassian.net/browse/MEX-1281 ,disable the handler if event target is input
38
+ if (event.target instanceof HTMLInputElement) {
39
+ return;
40
+ }
41
+ if (clipboardData && clipboardData.files) {
42
+ const fileSource = clipboardData.types.length === 1 ? LocalFileSource.PastedScreenshot : LocalFileSource.PastedFile;
43
+ const filesArray = getFilesFromClipboard(clipboardData.files).map(file => ({
44
+ file,
45
+ source: fileSource
46
+ }));
47
+ if (filesArray.length > 0) {
48
+ this.onFilesPasted(filesArray);
49
+ }
50
+ }
51
+ });
28
52
  this.uploadService = uploadService;
53
+ this.container = container;
54
+ this.onPaste = onPaste;
29
55
  this.createAnalyticsEvent = createAnalyticsEvent;
30
56
  this.featureFlags = featureFlags;
31
57
  }
@@ -34,20 +60,28 @@ class ClipboardImpl {
34
60
  }
35
61
  activate() {
36
62
  this.deactivate();
37
- document.addEventListener('paste', ClipboardImpl.handleEvent);
38
- ClipboardImpl.instances.push(this);
63
+ if (!this.container) {
64
+ document.addEventListener('paste', ClipboardImpl.legacyHandleEvent);
65
+ ClipboardImpl.instances.push(this);
66
+ } else {
67
+ this.container.addEventListener('paste', this.handleEvent);
68
+ }
39
69
  }
40
70
  deactivate() {
41
- const index = ClipboardImpl.instances.indexOf(this);
42
- if (index > -1) {
43
- ClipboardImpl.instances.splice(index, 1);
71
+ if (!this.container) {
72
+ const index = ClipboardImpl.instances.indexOf(this);
73
+ if (index > -1) {
74
+ ClipboardImpl.instances.splice(index, 1);
75
+ } else {
76
+ /**
77
+ * We want to remove the handleEvent only when there are no more instances.
78
+ * Since handleEvent is static, if we remove it right away, and there is still an active instance,
79
+ * we will loose the clipboard functionality.
80
+ */
81
+ document.removeEventListener('paste', ClipboardImpl.legacyHandleEvent);
82
+ }
44
83
  } else {
45
- /**
46
- * We want to remove the handleEvent only when there are no more instances.
47
- * Since handleEvent is static, if we remove it right away, and there is still an active instance,
48
- * we will loose the clipboard functionality.
49
- */
50
- document.removeEventListener('paste', ClipboardImpl.handleEvent);
84
+ this.container.removeEventListener('paste', this.handleEvent);
51
85
  }
52
86
  }
53
87
  onFilesPasted(files) {
@@ -79,9 +113,13 @@ class ClipboardImpl {
79
113
  analyticsEvent.fire(ANALYTICS_MEDIA_CHANNEL);
80
114
  }
81
115
  }
116
+
117
+ // The existing (semi)singleton (last in `instances`) event handler is proven to be problematic
118
+ // Replaced with the new mechanism in https://product-fabric.atlassian.net/browse/MEX-2454
119
+ // Remove after product adoption / rollout
82
120
  }
83
121
  _defineProperty(ClipboardImpl, "instances", []);
84
- _defineProperty(ClipboardImpl, "handleEvent", event => {
122
+ _defineProperty(ClipboardImpl, "legacyHandleEvent", event => {
85
123
  // From https://product-fabric.atlassian.net/browse/MEX-1281 ,disable the handler if event target is input
86
124
  if (event.target instanceof HTMLInputElement) {
87
125
  return;
@@ -115,7 +153,7 @@ _defineProperty(ClipboardImpl, "handleEvent", event => {
115
153
  export class ClipboardBase extends LocalUploadComponentReact {
116
154
  constructor(props) {
117
155
  super(props, COMPONENT_NAME);
118
- this.clipboard = new ClipboardImpl(this.uploadService, this.props.createAnalyticsEvent, props.featureFlags);
156
+ this.clipboard = new ClipboardImpl(this.uploadService, this.props.config.container, this.props.config.onPaste, this.props.createAnalyticsEvent, props.featureFlags);
119
157
  }
120
158
  componentDidMount() {
121
159
  this.clipboard.activate();
@@ -3,7 +3,7 @@ import { isRequestError } from '@atlaskit/media-client';
3
3
  // Component name will be prefixed with "media-picker-" in logs. Check ufoExperiences in utils files
4
4
 
5
5
  const packageName = "@atlaskit/media-picker";
6
- const packageVersion = "66.1.5";
6
+ const packageVersion = "66.2.1";
7
7
  export function getPackageAttributes(componentName) {
8
8
  return {
9
9
  packageName,
@@ -2,7 +2,7 @@ import { ConcurrentExperience, ExperiencePerformanceTypes, ExperienceTypes } fro
2
2
  import { getFeatureFlagKeysAllProducts } from '@atlaskit/media-common';
3
3
  import { getMediaEnvironment, getMediaRegion } from '@atlaskit/media-client';
4
4
  const packageName = "@atlaskit/media-picker";
5
- const packageVersion = "66.1.5";
5
+ const packageVersion = "66.2.1";
6
6
  let ufoExperience;
7
7
  const initExperience = (id, componentName) => {
8
8
  if (!ufoExperience) {
@@ -31,9 +31,36 @@ var defaultConfig = {
31
31
  };
32
32
  var COMPONENT_NAME = 'clipboard';
33
33
  var ClipboardImpl = /*#__PURE__*/function () {
34
- function ClipboardImpl(uploadService, createAnalyticsEvent, featureFlags) {
34
+ function ClipboardImpl(uploadService, container, onPaste, createAnalyticsEvent, featureFlags) {
35
+ var _this = this;
35
36
  _classCallCheck(this, ClipboardImpl);
37
+ _defineProperty(this, "handleEvent", function (event) {
38
+ var _this$onPaste;
39
+ var clipboardData = event.clipboardData;
40
+ if ((_this$onPaste = _this.onPaste) !== null && _this$onPaste !== void 0 && _this$onPaste.call(_this, event)) {
41
+ return;
42
+ }
43
+
44
+ // From https://product-fabric.atlassian.net/browse/MEX-1281 ,disable the handler if event target is input
45
+ if (event.target instanceof HTMLInputElement) {
46
+ return;
47
+ }
48
+ if (clipboardData && clipboardData.files) {
49
+ var fileSource = clipboardData.types.length === 1 ? LocalFileSource.PastedScreenshot : LocalFileSource.PastedFile;
50
+ var filesArray = getFilesFromClipboard(clipboardData.files).map(function (file) {
51
+ return {
52
+ file: file,
53
+ source: fileSource
54
+ };
55
+ });
56
+ if (filesArray.length > 0) {
57
+ _this.onFilesPasted(filesArray);
58
+ }
59
+ }
60
+ });
36
61
  this.uploadService = uploadService;
62
+ this.container = container;
63
+ this.onPaste = onPaste;
37
64
  this.createAnalyticsEvent = createAnalyticsEvent;
38
65
  this.featureFlags = featureFlags;
39
66
  }
@@ -41,22 +68,30 @@ var ClipboardImpl = /*#__PURE__*/function () {
41
68
  key: "activate",
42
69
  value: function activate() {
43
70
  this.deactivate();
44
- document.addEventListener('paste', ClipboardImpl.handleEvent);
45
- ClipboardImpl.instances.push(this);
71
+ if (!this.container) {
72
+ document.addEventListener('paste', ClipboardImpl.legacyHandleEvent);
73
+ ClipboardImpl.instances.push(this);
74
+ } else {
75
+ this.container.addEventListener('paste', this.handleEvent);
76
+ }
46
77
  }
47
78
  }, {
48
79
  key: "deactivate",
49
80
  value: function deactivate() {
50
- var index = ClipboardImpl.instances.indexOf(this);
51
- if (index > -1) {
52
- ClipboardImpl.instances.splice(index, 1);
81
+ if (!this.container) {
82
+ var index = ClipboardImpl.instances.indexOf(this);
83
+ if (index > -1) {
84
+ ClipboardImpl.instances.splice(index, 1);
85
+ } else {
86
+ /**
87
+ * We want to remove the handleEvent only when there are no more instances.
88
+ * Since handleEvent is static, if we remove it right away, and there is still an active instance,
89
+ * we will loose the clipboard functionality.
90
+ */
91
+ document.removeEventListener('paste', ClipboardImpl.legacyHandleEvent);
92
+ }
53
93
  } else {
54
- /**
55
- * We want to remove the handleEvent only when there are no more instances.
56
- * Since handleEvent is static, if we remove it right away, and there is still an active instance,
57
- * we will loose the clipboard functionality.
58
- */
59
- document.removeEventListener('paste', ClipboardImpl.handleEvent);
94
+ this.container.removeEventListener('paste', this.handleEvent);
60
95
  }
61
96
  }
62
97
  }, {
@@ -92,6 +127,10 @@ var ClipboardImpl = /*#__PURE__*/function () {
92
127
  analyticsEvent.fire(ANALYTICS_MEDIA_CHANNEL);
93
128
  }
94
129
  }
130
+
131
+ // The existing (semi)singleton (last in `instances`) event handler is proven to be problematic
132
+ // Replaced with the new mechanism in https://product-fabric.atlassian.net/browse/MEX-2454
133
+ // Remove after product adoption / rollout
95
134
  }], [{
96
135
  key: "latestInstance",
97
136
  get: function get() {
@@ -101,7 +140,7 @@ var ClipboardImpl = /*#__PURE__*/function () {
101
140
  return ClipboardImpl;
102
141
  }();
103
142
  _defineProperty(ClipboardImpl, "instances", []);
104
- _defineProperty(ClipboardImpl, "handleEvent", function (event) {
143
+ _defineProperty(ClipboardImpl, "legacyHandleEvent", function (event) {
105
144
  // From https://product-fabric.atlassian.net/browse/MEX-1281 ,disable the handler if event target is input
106
145
  if (event.target instanceof HTMLInputElement) {
107
146
  return;
@@ -136,11 +175,11 @@ export var ClipboardBase = /*#__PURE__*/function (_LocalUploadComponent) {
136
175
  _inherits(ClipboardBase, _LocalUploadComponent);
137
176
  var _super = _createSuper(ClipboardBase);
138
177
  function ClipboardBase(props) {
139
- var _this;
178
+ var _this2;
140
179
  _classCallCheck(this, ClipboardBase);
141
- _this = _super.call(this, props, COMPONENT_NAME);
142
- _this.clipboard = new ClipboardImpl(_this.uploadService, _this.props.createAnalyticsEvent, props.featureFlags);
143
- return _this;
180
+ _this2 = _super.call(this, props, COMPONENT_NAME);
181
+ _this2.clipboard = new ClipboardImpl(_this2.uploadService, _this2.props.config.container, _this2.props.config.onPaste, _this2.props.createAnalyticsEvent, props.featureFlags);
182
+ return _this2;
144
183
  }
145
184
  _createClass(ClipboardBase, [{
146
185
  key: "componentDidMount",
@@ -1,6 +1,6 @@
1
1
  import _defineProperty from "@babel/runtime/helpers/defineProperty";
2
- function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
3
- function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
2
+ 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; }
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 React from 'react';
5
5
  import { AutoDismissFlag, FlagGroup } from '@atlaskit/flag';
6
6
  import FailIcon from '@atlaskit/icon/glyph/cross-circle';
@@ -3,7 +3,7 @@ import { isRequestError } from '@atlaskit/media-client';
3
3
  // Component name will be prefixed with "media-picker-" in logs. Check ufoExperiences in utils files
4
4
 
5
5
  var packageName = "@atlaskit/media-picker";
6
- var packageVersion = "66.1.5";
6
+ var packageVersion = "66.2.1";
7
7
  export function getPackageAttributes(componentName) {
8
8
  return {
9
9
  packageName: packageName,
@@ -1,11 +1,11 @@
1
1
  import _defineProperty from "@babel/runtime/helpers/defineProperty";
2
- function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
3
- function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
2
+ 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; }
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 { ConcurrentExperience, ExperiencePerformanceTypes, ExperienceTypes } from '@atlaskit/ufo';
5
5
  import { getFeatureFlagKeysAllProducts } from '@atlaskit/media-common';
6
6
  import { getMediaEnvironment, getMediaRegion } from '@atlaskit/media-client';
7
7
  var packageName = "@atlaskit/media-picker";
8
- var packageVersion = "66.1.5";
8
+ var packageVersion = "66.2.1";
9
9
  var ufoExperience;
10
10
  var initExperience = function initExperience(id, componentName) {
11
11
  if (!ufoExperience) {
@@ -13,16 +13,19 @@ export type ClipboardProps = LocalUploadComponentBaseProps & {
13
13
  };
14
14
  declare class ClipboardImpl {
15
15
  private readonly uploadService;
16
+ private container?;
17
+ private onPaste?;
16
18
  private readonly createAnalyticsEvent?;
17
19
  featureFlags?: MediaFeatureFlags | undefined;
18
20
  static instances: ClipboardImpl[];
19
- constructor(uploadService: UploadService, createAnalyticsEvent?: CreateUIAnalyticsEvent | undefined, featureFlags?: MediaFeatureFlags | undefined);
21
+ constructor(uploadService: UploadService, container?: HTMLElement | undefined, onPaste?: ((event: ClipboardEvent) => boolean | undefined) | undefined, createAnalyticsEvent?: CreateUIAnalyticsEvent | undefined, featureFlags?: MediaFeatureFlags | undefined);
20
22
  static get latestInstance(): ClipboardImpl | undefined;
21
23
  activate(): void;
22
24
  deactivate(): void;
23
25
  onFilesPasted(files: LocalFileWithSource[]): void;
24
26
  private fireAnalyticsEvent;
25
- static handleEvent: (event: ClipboardEvent) => void;
27
+ static legacyHandleEvent: (event: ClipboardEvent) => void;
28
+ private handleEvent;
26
29
  }
27
30
  export declare class ClipboardBase extends LocalUploadComponentReact<ClipboardProps> {
28
31
  clipboard: ClipboardImpl;
@@ -1,5 +1,5 @@
1
1
  export { isImagePreview } from './domain/preview';
2
- export type { BrowserConfig, DropzoneConfig, UploadParams, UploadsStartEventPayload, UploadPreviewUpdateEventPayload, UploadEndEventPayload, UploadErrorEventPayload, UploadRejectionData, MediaFile, Preview, NonImagePreview, ImagePreview, MediaError, MediaErrorName, } from './types';
2
+ export type { BrowserConfig, DropzoneConfig, ClipboardConfig, UploadParams, UploadsStartEventPayload, UploadPreviewUpdateEventPayload, UploadEndEventPayload, UploadErrorEventPayload, UploadRejectionData, MediaFile, Preview, NonImagePreview, ImagePreview, MediaError, MediaErrorName, } from './types';
3
3
  export type { LocalUploadConfig } from './components/types';
4
4
  export { DropzoneLoader as Dropzone } from './components/dropzone';
5
5
  export { ClipboardLoader as Clipboard } from './components/clipboard';
@@ -63,6 +63,8 @@ export interface BrowserConfig extends LocalUploadConfig {
63
63
  readonly replaceFileId?: string;
64
64
  }
65
65
  export interface ClipboardConfig extends LocalUploadConfig {
66
+ container?: HTMLElement;
67
+ onPaste?: (event: ClipboardEvent) => boolean | undefined;
66
68
  }
67
69
  export interface DropzoneConfig extends LocalUploadConfig {
68
70
  container?: HTMLElement;
@@ -13,16 +13,19 @@ export type ClipboardProps = LocalUploadComponentBaseProps & {
13
13
  };
14
14
  declare class ClipboardImpl {
15
15
  private readonly uploadService;
16
+ private container?;
17
+ private onPaste?;
16
18
  private readonly createAnalyticsEvent?;
17
19
  featureFlags?: MediaFeatureFlags | undefined;
18
20
  static instances: ClipboardImpl[];
19
- constructor(uploadService: UploadService, createAnalyticsEvent?: CreateUIAnalyticsEvent | undefined, featureFlags?: MediaFeatureFlags | undefined);
21
+ constructor(uploadService: UploadService, container?: HTMLElement | undefined, onPaste?: ((event: ClipboardEvent) => boolean | undefined) | undefined, createAnalyticsEvent?: CreateUIAnalyticsEvent | undefined, featureFlags?: MediaFeatureFlags | undefined);
20
22
  static get latestInstance(): ClipboardImpl | undefined;
21
23
  activate(): void;
22
24
  deactivate(): void;
23
25
  onFilesPasted(files: LocalFileWithSource[]): void;
24
26
  private fireAnalyticsEvent;
25
- static handleEvent: (event: ClipboardEvent) => void;
27
+ static legacyHandleEvent: (event: ClipboardEvent) => void;
28
+ private handleEvent;
26
29
  }
27
30
  export declare class ClipboardBase extends LocalUploadComponentReact<ClipboardProps> {
28
31
  clipboard: ClipboardImpl;
@@ -1,5 +1,5 @@
1
1
  export { isImagePreview } from './domain/preview';
2
- export type { BrowserConfig, DropzoneConfig, UploadParams, UploadsStartEventPayload, UploadPreviewUpdateEventPayload, UploadEndEventPayload, UploadErrorEventPayload, UploadRejectionData, MediaFile, Preview, NonImagePreview, ImagePreview, MediaError, MediaErrorName, } from './types';
2
+ export type { BrowserConfig, DropzoneConfig, ClipboardConfig, UploadParams, UploadsStartEventPayload, UploadPreviewUpdateEventPayload, UploadEndEventPayload, UploadErrorEventPayload, UploadRejectionData, MediaFile, Preview, NonImagePreview, ImagePreview, MediaError, MediaErrorName, } from './types';
3
3
  export type { LocalUploadConfig } from './components/types';
4
4
  export { DropzoneLoader as Dropzone } from './components/dropzone';
5
5
  export { ClipboardLoader as Clipboard } from './components/clipboard';
@@ -63,6 +63,8 @@ export interface BrowserConfig extends LocalUploadConfig {
63
63
  readonly replaceFileId?: string;
64
64
  }
65
65
  export interface ClipboardConfig extends LocalUploadConfig {
66
+ container?: HTMLElement;
67
+ onPaste?: (event: ClipboardEvent) => boolean | undefined;
66
68
  }
67
69
  export interface DropzoneConfig extends LocalUploadConfig {
68
70
  container?: HTMLElement;
@@ -0,0 +1,107 @@
1
+ /* eslint-disable jsx-a11y/media-has-caption */
2
+ import React, { useEffect, useState } from 'react';
3
+ import {
4
+ MediaClient,
5
+ MediaFileArtifacts,
6
+ MediaType,
7
+ } from '@atlaskit/media-client';
8
+
9
+ type NativeMediaViewerProps = {
10
+ id: string;
11
+ mediaClient: MediaClient;
12
+ };
13
+
14
+ const getMimeTypeFromArtifact = (artifact: keyof MediaFileArtifacts) => {
15
+ switch (artifact) {
16
+ case 'image.png':
17
+ return 'image/png';
18
+ case 'document.pdf':
19
+ return 'application/pdf';
20
+ case 'video_640.mp4':
21
+ case 'video_1280.mp4':
22
+ return 'video/mp4';
23
+ case 'audio.mp3':
24
+ return 'audio/mpeg';
25
+ default:
26
+ return '';
27
+ }
28
+ };
29
+
30
+ const getArtifactUrl = (
31
+ client: MediaClient,
32
+ artifacts: MediaFileArtifacts,
33
+ artifact: keyof MediaFileArtifacts,
34
+ ) =>
35
+ client.mediaStore
36
+ .getArtifactURL(artifacts, artifact)
37
+ .then((url) => fetch(url))
38
+ .then((res) => res.blob())
39
+ .then((blob) => blob.slice(0, blob.size, getMimeTypeFromArtifact(artifact)))
40
+ .then((blob) => URL.createObjectURL(blob));
41
+
42
+ export const NativeMediaViewer = ({
43
+ id,
44
+ mediaClient,
45
+ }: NativeMediaViewerProps) => {
46
+ const [url, setUrl] = useState('');
47
+ const [mediaType, setMediaType] = useState<MediaType | null>(null);
48
+
49
+ useEffect(() => {
50
+ const setArtifactUrl = (
51
+ artifacts: MediaFileArtifacts,
52
+ artifact: keyof MediaFileArtifacts,
53
+ ) => {
54
+ getArtifactUrl(mediaClient, artifacts, artifact).then((url) =>
55
+ setUrl(url),
56
+ );
57
+ };
58
+ if (id) {
59
+ const subscribable = mediaClient.file.getFileState(id);
60
+ const { unsubscribe } = subscribable.subscribe((state) => {
61
+ if (state.status === 'processed') {
62
+ if (state.artifacts['document.pdf']) {
63
+ setArtifactUrl(state.artifacts, 'document.pdf');
64
+ setMediaType('doc');
65
+ } else if (state.artifacts['video_640.mp4']) {
66
+ setArtifactUrl(state.artifacts, 'video_640.mp4');
67
+ setMediaType('video');
68
+ } else if (state.artifacts['audio.mp3']) {
69
+ setArtifactUrl(state.artifacts, 'audio.mp3');
70
+ setMediaType('audio');
71
+ } else if (state.artifacts['image.png']) {
72
+ setArtifactUrl(state.artifacts, 'image.png');
73
+ setMediaType('image');
74
+ } else {
75
+ setMediaType('unknown');
76
+ }
77
+ } else if (state.status === 'failed-processing') {
78
+ setMediaType('unknown');
79
+ }
80
+ });
81
+
82
+ return unsubscribe;
83
+ }
84
+ return () => {};
85
+ }, [id, mediaClient]);
86
+
87
+ switch (mediaType) {
88
+ case 'image':
89
+ return <img style={{ width: '100%' }} src={url} />;
90
+ case 'video':
91
+ return <video style={{ width: '100%' }} src={url} />;
92
+ case 'audio':
93
+ return <audio style={{ width: '100%' }} src={url} />;
94
+ case 'doc':
95
+ return (
96
+ <object type="application/pdf" style={{ width: '100%' }} data={url}>
97
+ <embed type="application/pdf" src={url} />
98
+ </object>
99
+ );
100
+ case null:
101
+ return <div>Loading file ...</div>;
102
+ case 'unknown':
103
+ return <div>Unable to display file</div>;
104
+ default:
105
+ return <div>Unable to display file</div>;
106
+ }
107
+ };
@@ -1,12 +1,13 @@
1
1
  import React from 'react';
2
- import { PreviewImageWrapper, InfoWrapper } from './stylesWrapper';
2
+ import { PreviewImageWrapper } from './stylesWrapper';
3
3
  import { PreviewData } from './types';
4
- import { Card } from '@atlaskit/media-card';
5
- import { FileIdentifier } from '@atlaskit/media-client';
4
+ import { FileIdentifier, MediaClient } from '@atlaskit/media-client';
6
5
  import { createUploadMediaClientConfig } from '@atlaskit/media-test-helpers';
7
6
  import { Preview, ImagePreview } from '../src/types';
7
+ import { NativeMediaViewer } from './NativeMediaViewer';
8
8
 
9
9
  const mediaClientConfig = createUploadMediaClientConfig();
10
+ const mediaClient = new MediaClient(mediaClientConfig);
10
11
 
11
12
  export class UploadPreview extends React.Component<PreviewData> {
12
13
  getPreviewInfo(preview: Preview): string | null {
@@ -19,7 +20,7 @@ export class UploadPreview extends React.Component<PreviewData> {
19
20
  }
20
21
 
21
22
  render() {
22
- const { fileId, preview } = this.props;
23
+ const { fileId } = this.props;
23
24
 
24
25
  const identifier: FileIdentifier = {
25
26
  id: fileId,
@@ -28,10 +29,7 @@ export class UploadPreview extends React.Component<PreviewData> {
28
29
 
29
30
  return (
30
31
  <PreviewImageWrapper>
31
- <Card identifier={identifier} mediaClientConfig={mediaClientConfig} />
32
- {preview ? (
33
- <InfoWrapper>{this.getPreviewInfo(preview)}</InfoWrapper>
34
- ) : null}
32
+ <NativeMediaViewer id={identifier.id} mediaClient={mediaClient} />
35
33
  </PreviewImageWrapper>
36
34
  );
37
35
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atlaskit/media-picker",
3
- "version": "66.1.5",
3
+ "version": "66.2.1",
4
4
  "description": "Library for handling file uploads",
5
5
  "publishConfig": {
6
6
  "registry": "https://registry.npmjs.org/"
@@ -37,11 +37,11 @@
37
37
  "@atlaskit/analytics-next": "^9.1.0",
38
38
  "@atlaskit/flag": "^15.1.0",
39
39
  "@atlaskit/icon": "^21.11.0",
40
- "@atlaskit/media-client": "^23.1.0",
41
- "@atlaskit/media-common": "^8.0.0",
40
+ "@atlaskit/media-client": "^23.2.0",
41
+ "@atlaskit/media-common": "^8.2.0",
42
42
  "@atlaskit/media-ui": "^24.0.0",
43
43
  "@atlaskit/theme": "^12.4.0",
44
- "@atlaskit/tokens": "^1.15.0",
44
+ "@atlaskit/tokens": "^1.18.0",
45
45
  "@atlaskit/ufo": "^0.2.0",
46
46
  "@babel/runtime": "^7.0.0",
47
47
  "eventemitter2": "^4.1.0",
@@ -61,11 +61,10 @@
61
61
  "@atlaskit/analytics-listeners": "^8.7.0",
62
62
  "@atlaskit/analytics-namespaced-context": "^6.7.0",
63
63
  "@atlaskit/button": "^16.9.0",
64
- "@atlaskit/media-card": "^76.1.0",
65
64
  "@atlaskit/media-core": "^34.1.0",
66
65
  "@atlaskit/media-test-helpers": "^33.0.0",
67
66
  "@atlaskit/ssr": "*",
68
- "@atlaskit/tokens": "^1.15.0",
67
+ "@atlaskit/tokens": "^1.18.0",
69
68
  "@atlassian/atlassian-frontend-prettier-config-1.0.1": "npm:@atlassian/atlassian-frontend-prettier-config@1.0.1",
70
69
  "@atlassian/ufo": "^0.2.0",
71
70
  "@babel/plugin-proposal-numeric-separator": "^7.18.6",
package/report.api.md CHANGED
@@ -105,7 +105,12 @@ class Clipboard_2 extends React_2.PureComponent<
105
105
  export { Clipboard_2 as Clipboard };
106
106
 
107
107
  // @public (undocumented)
108
- interface ClipboardConfig extends LocalUploadConfig {}
108
+ export interface ClipboardConfig extends LocalUploadConfig {
109
+ // (undocumented)
110
+ container?: HTMLElement;
111
+ // (undocumented)
112
+ onPaste?: (event: ClipboardEvent) => boolean | undefined;
113
+ }
109
114
 
110
115
  // @public (undocumented)
111
116
  type ClipboardProps = LocalUploadComponentBaseProps & {
@@ -85,7 +85,11 @@ class Clipboard_2 extends React_2.PureComponent<ClipboardWithMediaClientConfigPr
85
85
  export { Clipboard_2 as Clipboard }
86
86
 
87
87
  // @public (undocumented)
88
- interface ClipboardConfig extends LocalUploadConfig {
88
+ export interface ClipboardConfig extends LocalUploadConfig {
89
+ // (undocumented)
90
+ container?: HTMLElement;
91
+ // (undocumented)
92
+ onPaste?: (event: ClipboardEvent) => boolean | undefined;
89
93
  }
90
94
 
91
95
  // @public (undocumented)