@atlaskit/editor-plugin-paste 8.0.3 → 8.1.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.
Files changed (35) hide show
  1. package/CHANGELOG.md +17 -0
  2. package/dist/cjs/editor-actions/actions.js +1 -0
  3. package/dist/cjs/pastePlugin.js +18 -2
  4. package/dist/cjs/pastePluginType.js +9 -1
  5. package/dist/cjs/pm-plugins/main.js +4 -2
  6. package/dist/cjs/pm-plugins/reducer.js +14 -0
  7. package/dist/cjs/pm-plugins/util/sync-block.js +129 -0
  8. package/dist/cjs/ui/Flag.js +107 -0
  9. package/dist/es2019/editor-actions/actions.js +1 -0
  10. package/dist/es2019/pastePlugin.js +17 -2
  11. package/dist/es2019/pastePluginType.js +7 -1
  12. package/dist/es2019/pm-plugins/main.js +5 -3
  13. package/dist/es2019/pm-plugins/reducer.js +15 -0
  14. package/dist/es2019/pm-plugins/util/sync-block.js +121 -0
  15. package/dist/es2019/ui/Flag.js +102 -0
  16. package/dist/esm/editor-actions/actions.js +1 -0
  17. package/dist/esm/pastePlugin.js +17 -2
  18. package/dist/esm/pastePluginType.js +7 -1
  19. package/dist/esm/pm-plugins/main.js +5 -3
  20. package/dist/esm/pm-plugins/reducer.js +14 -0
  21. package/dist/esm/pm-plugins/util/sync-block.js +122 -0
  22. package/dist/esm/ui/Flag.js +98 -0
  23. package/dist/types/editor-actions/actions.d.ts +8 -3
  24. package/dist/types/index.d.ts +1 -1
  25. package/dist/types/pastePluginType.d.ts +23 -1
  26. package/dist/types/pm-plugins/main.d.ts +2 -2
  27. package/dist/types/pm-plugins/util/sync-block.d.ts +5 -0
  28. package/dist/types/ui/Flag.d.ts +8 -0
  29. package/dist/types-ts4.5/editor-actions/actions.d.ts +8 -3
  30. package/dist/types-ts4.5/index.d.ts +1 -1
  31. package/dist/types-ts4.5/pastePluginType.d.ts +23 -1
  32. package/dist/types-ts4.5/pm-plugins/main.d.ts +2 -2
  33. package/dist/types-ts4.5/pm-plugins/util/sync-block.d.ts +5 -0
  34. package/dist/types-ts4.5/ui/Flag.d.ts +8 -0
  35. package/package.json +12 -6
package/CHANGELOG.md CHANGED
@@ -1,5 +1,22 @@
1
1
  # @atlaskit/editor-plugin-paste
2
2
 
3
+ ## 8.1.1
4
+
5
+ ### Patch Changes
6
+
7
+ - Updated dependencies
8
+
9
+ ## 8.1.0
10
+
11
+ ### Minor Changes
12
+
13
+ - [`9068b92adf796`](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/commits/9068b92adf796) -
14
+ [ux] EDITOR-4439 Implement option to raise warn flag on paste for unsupported content
15
+
16
+ ### Patch Changes
17
+
18
+ - Updated dependencies
19
+
3
20
  ## 8.0.3
4
21
 
5
22
  ### Patch Changes
@@ -8,5 +8,6 @@ var PastePluginActionTypes = exports.PastePluginActionTypes = /*#__PURE__*/funct
8
8
  PastePluginActionTypes["START_TRACKING_PASTED_MACRO_POSITIONS"] = "START_TRACKING_PASTED_MACRO_POSITIONS";
9
9
  PastePluginActionTypes["STOP_TRACKING_PASTED_MACRO_POSITIONS"] = "STOP_TRACKING_PASTED_MACRO_POSITIONS";
10
10
  PastePluginActionTypes["ON_PASTE"] = "ON_PASTE";
11
+ PastePluginActionTypes["SET_ACTIVE_FLAG"] = "SET_ACTIVE_FLAG";
11
12
  return PastePluginActionTypes;
12
13
  }({});
@@ -1,12 +1,17 @@
1
1
  "use strict";
2
2
 
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
3
4
  Object.defineProperty(exports, "__esModule", {
4
5
  value: true
5
6
  });
6
7
  exports.pastePlugin = void 0;
8
+ var _react = _interopRequireDefault(require("react"));
9
+ var _platformFeatureFlags = require("@atlaskit/platform-feature-flags");
10
+ var _experiments = require("@atlaskit/tmp-editor-statsig/experiments");
7
11
  var _main = require("./pm-plugins/main");
8
12
  var _plugin = require("./pm-plugins/move-analytics/plugin");
9
13
  var _pluginFactory = require("./pm-plugins/plugin-factory");
14
+ var _Flag = require("./ui/Flag");
10
15
  var pastePlugin = exports.pastePlugin = function pastePlugin(_ref) {
11
16
  var _api$featureFlags, _api$analytics;
12
17
  var config = _ref.config,
@@ -14,7 +19,8 @@ var pastePlugin = exports.pastePlugin = function pastePlugin(_ref) {
14
19
  var _ref2 = config !== null && config !== void 0 ? config : {},
15
20
  cardOptions = _ref2.cardOptions,
16
21
  sanitizePrivateContent = _ref2.sanitizePrivateContent,
17
- isFullPage = _ref2.isFullPage;
22
+ isFullPage = _ref2.isFullPage,
23
+ pasteWarningOptions = _ref2.pasteWarningOptions;
18
24
  var featureFlags = (api === null || api === void 0 || (_api$featureFlags = api.featureFlags) === null || _api$featureFlags === void 0 ? void 0 : _api$featureFlags.sharedState.currentState()) || {};
19
25
  var editorAnalyticsAPI = api === null || api === void 0 || (_api$analytics = api.analytics) === null || _api$analytics === void 0 ? void 0 : _api$analytics.actions;
20
26
  return {
@@ -28,7 +34,7 @@ var pastePlugin = exports.pastePlugin = function pastePlugin(_ref) {
28
34
  dispatchAnalyticsEvent = _ref3.dispatchAnalyticsEvent,
29
35
  dispatch = _ref3.dispatch,
30
36
  getIntl = _ref3.getIntl;
31
- return (0, _main.createPlugin)(schema, dispatchAnalyticsEvent, dispatch, featureFlags, api, getIntl, cardOptions, sanitizePrivateContent, providerFactory);
37
+ return (0, _main.createPlugin)(schema, dispatchAnalyticsEvent, dispatch, featureFlags, api, getIntl, cardOptions, sanitizePrivateContent, providerFactory, pasteWarningOptions);
32
38
  }
33
39
  }, {
34
40
  name: 'moveAnalyticsPlugin',
@@ -38,14 +44,24 @@ var pastePlugin = exports.pastePlugin = function pastePlugin(_ref) {
38
44
  }
39
45
  }];
40
46
  },
47
+ contentComponent: !(0, _experiments.editorExperiment)('platform_synced_block', true) || !(0, _platformFeatureFlags.fg)('platform_synced_block_dogfooding') ? undefined : function () {
48
+ if (!pasteWarningOptions) {
49
+ return null;
50
+ }
51
+ return /*#__PURE__*/_react.default.createElement(_react.default.Fragment, null, /*#__PURE__*/_react.default.createElement(_Flag.Flag, {
52
+ api: api
53
+ }));
54
+ },
41
55
  getSharedState: function getSharedState(editorState) {
42
56
  if (!editorState) {
43
57
  return {
58
+ activeFlag: null,
44
59
  lastContentPasted: null
45
60
  };
46
61
  }
47
62
  var pluginState = _pluginFactory.pluginKey.getState(editorState);
48
63
  return {
64
+ activeFlag: pluginState.activeFlag,
49
65
  lastContentPasted: pluginState.lastContentPasted
50
66
  };
51
67
  }
@@ -2,4 +2,12 @@
2
2
 
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
- });
5
+ });
6
+ exports.FLAG_TYPE = void 0;
7
+ var FLAG_TYPE = exports.FLAG_TYPE = /*#__PURE__*/function (FLAG_TYPE) {
8
+ FLAG_TYPE["WARNING"] = "warning";
9
+ FLAG_TYPE["ERROR"] = "error";
10
+ FLAG_TYPE["INFO"] = "info";
11
+ FLAG_TYPE["SUCCESS"] = "success";
12
+ return FLAG_TYPE;
13
+ }({});
@@ -38,6 +38,7 @@ var _pluginFactory = require("./plugin-factory");
38
38
  var _util = require("./util");
39
39
  var _handleVSCodeBlock = require("./util/edge-cases/handleVSCodeBlock");
40
40
  var _handlers = require("./util/handlers");
41
+ var _syncBlock2 = require("./util/sync-block");
41
42
  var _tinyMCE = require("./util/tinyMCE");
42
43
  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; } } }; }
43
44
  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; } }
@@ -68,7 +69,7 @@ function isSharePointUrl(url) {
68
69
  return false;
69
70
  }
70
71
  }
71
- function createPlugin(schema, dispatchAnalyticsEvent, dispatch, featureFlags, pluginInjectionApi, getIntl, cardOptions, sanitizePrivateContent, providerFactory) {
72
+ function createPlugin(schema, dispatchAnalyticsEvent, dispatch, featureFlags, pluginInjectionApi, getIntl, cardOptions, sanitizePrivateContent, providerFactory, pasteWarningOptions) {
72
73
  var _pluginInjectionApi$a;
73
74
  var editorAnalyticsAPI = pluginInjectionApi === null || pluginInjectionApi === void 0 || (_pluginInjectionApi$a = pluginInjectionApi.analytics) === null || _pluginInjectionApi$a === void 0 ? void 0 : _pluginInjectionApi$a.actions;
74
75
  var atlassianMarkDownParser = new _editorMarkdownTransformer.MarkdownTransformer(schema, _paste.md);
@@ -123,6 +124,7 @@ function createPlugin(schema, dispatchAnalyticsEvent, dispatch, featureFlags, pl
123
124
  return new _safePlugin.SafePlugin({
124
125
  key: _pluginFactory.pluginKey,
125
126
  state: (0, _pluginFactory.createPluginState)(dispatch, {
127
+ activeFlag: null,
126
128
  pastedMacroPositions: {},
127
129
  lastContentPasted: null
128
130
  }),
@@ -327,7 +329,7 @@ function createPlugin(schema, dispatchAnalyticsEvent, dispatch, featureFlags, pl
327
329
  text: text
328
330
  });
329
331
  if ((0, _experiments.editorExperiment)('platform_synced_block', true)) {
330
- slice = (0, _transforms.transformSyncBlock)(slice, schema, (0, _util.getPasteSource)(event));
332
+ slice = (0, _syncBlock2.handleSyncBlocksPaste)(slice, schema, (0, _util.getPasteSource)(event), html, pasteWarningOptions, pluginInjectionApi);
331
333
  }
332
334
  var plainTextPasteSlice = (0, _utils.linkifyContent)(state.schema)(slice);
333
335
  if ((0, _analytics2.handlePasteAsPlainTextWithAnalytics)(editorAnalyticsAPI)(view, event, plainTextPasteSlice)(state, dispatch, view)) {
@@ -7,6 +7,8 @@ Object.defineProperty(exports, "__esModule", {
7
7
  exports.reducer = void 0;
8
8
  var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
9
9
  var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
10
+ var _platformFeatureFlags = require("@atlaskit/platform-feature-flags");
11
+ var _experiments = require("@atlaskit/tmp-editor-statsig/experiments");
10
12
  var _actions = require("../editor-actions/actions");
11
13
  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; }
12
14
  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; }
@@ -35,6 +37,18 @@ var reducer = exports.reducer = function reducer(state, action) {
35
37
  lastContentPasted: action.contentPasted
36
38
  });
37
39
  }
40
+ case _actions.PastePluginActionTypes.SET_ACTIVE_FLAG:
41
+ {
42
+ if (!(0, _experiments.editorExperiment)('platform_synced_block', true)) {
43
+ return state;
44
+ }
45
+ if (!(0, _platformFeatureFlags.fg)('platform_synced_block_dogfooding')) {
46
+ return state;
47
+ }
48
+ return _objectSpread(_objectSpread({}, state), {}, {
49
+ activeFlag: action.activeFlag
50
+ });
51
+ }
38
52
  default:
39
53
  return state;
40
54
  }
@@ -0,0 +1,129 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
+ Object.defineProperty(exports, "__esModule", {
5
+ value: true
6
+ });
7
+ exports.handleSyncBlocksPaste = void 0;
8
+ var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray"));
9
+ var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
10
+ var _adfSchema = require("@atlaskit/adf-schema");
11
+ var _utils = require("@atlaskit/editor-common/utils");
12
+ var _platformFeatureFlags = require("@atlaskit/platform-feature-flags");
13
+ var _actions = require("../../editor-actions/actions");
14
+ var _pastePluginType = require("../../pastePluginType");
15
+ var _pluginFactory = require("../../pm-plugins/plugin-factory");
16
+ 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; }
17
+ 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; }
18
+ var FLAG_ID = /*#__PURE__*/function (FLAG_ID) {
19
+ FLAG_ID["CANNOT_PASTE_CONTENT"] = "cannot-paste-content";
20
+ return FLAG_ID;
21
+ }(FLAG_ID || {});
22
+ var transformSyncBlockNode = function transformSyncBlockNode(node, schema, isFromEditor) {
23
+ // if copying from renderer, flatten out the content and remove the sync block
24
+ if (!isFromEditor) {
25
+ return node.content;
26
+ }
27
+
28
+ // sync blocks need a unique localId to function correctly
29
+ var newAttrs = _objectSpread(_objectSpread({}, node.attrs), {}, {
30
+ localId: _adfSchema.uuid.generate()
31
+ });
32
+ return schema.nodes.syncBlock.create(newAttrs, null, (0, _toConsumableArray2.default)(node.marks));
33
+ };
34
+ var transformBodiedSyncBlockNode = function transformBodiedSyncBlockNode(node, isFromEditor) {
35
+ // if copying from renderer, flatten out the content and remove the bodied sync block
36
+ if (!isFromEditor) {
37
+ return node.content;
38
+ }
39
+
40
+ // this is not possible as all bodiedSyncBlocks have already been converted into a syncBlock by now.
41
+ return node;
42
+ };
43
+ var showWarningFlag = function showWarningFlag(_ref) {
44
+ var api = _ref.api,
45
+ title = _ref.title,
46
+ description = _ref.description,
47
+ urlText = _ref.urlText,
48
+ urlHref = _ref.urlHref;
49
+ // Use setTimeout to dispatch transaction in next tick and avoid re-entrant dispatch
50
+ setTimeout(function () {
51
+ api === null || api === void 0 || api.core.actions.execute(function (_ref2) {
52
+ var tr = _ref2.tr;
53
+ var flag = {
54
+ id: FLAG_ID.CANNOT_PASTE_CONTENT,
55
+ description: description,
56
+ title: title,
57
+ urlText: urlText,
58
+ urlHref: urlHref,
59
+ type: _pastePluginType.FLAG_TYPE.WARNING
60
+ };
61
+ return tr.setMeta(_pluginFactory.pluginKey, {
62
+ type: _actions.PastePluginActionTypes.SET_ACTIVE_FLAG,
63
+ activeFlag: flag
64
+ });
65
+ });
66
+ }, 0);
67
+ };
68
+
69
+ // Check if rawHtml contains a synced block
70
+ // example: "<meta charset='utf-8'><html><head></head><body><div data-sync-block=\"\" data-local-id=\"\" data-resource-id=\"d64883c8-1270-431d-a1d3-51d36a1ed5f4\" data-prosemirror-content-type=\"node\" data-prosemirror-node-name=\"syncBlock\" data-prosemirror-node-block=\"true\" data-pm-slice=\"0 0 []\"></div></body></html>"
71
+ var hasSyncedBlockInRawHtml = function hasSyncedBlockInRawHtml(rawHtml) {
72
+ return rawHtml.includes('data-sync-block="');
73
+ };
74
+
75
+ /**
76
+ * If we are copying from editor, transform the copied source or reference sync block to a new reference sync block
77
+ * Otherwise, (e.g. if copying from renderer), flatten out the content and remove the sync block
78
+ * Also, show a warning flag if the pasted content contains a synced block and the paste warning options are configured.
79
+ */
80
+ var handleSyncBlocksPasteNew = function handleSyncBlocksPasteNew(slice, schema, pasteSource, rawHtml, pasteWarningOptions, api) {
81
+ var isFromEditor = pasteSource === 'fabric-editor';
82
+ var isSyncedBlockInRawHtml = hasSyncedBlockInRawHtml(rawHtml);
83
+ var hasSyncedBlockInSlice = false;
84
+ slice = (0, _utils.mapSlice)(slice, function (node) {
85
+ if (node.type === schema.nodes.syncBlock) {
86
+ hasSyncedBlockInSlice = true;
87
+ return transformSyncBlockNode(node, schema, isFromEditor);
88
+ } else if (node.type === schema.nodes.bodiedSyncBlock) {
89
+ hasSyncedBlockInSlice = true;
90
+ return transformBodiedSyncBlockNode(node, isFromEditor);
91
+ }
92
+ return node;
93
+ });
94
+ if (pasteWarningOptions !== null && pasteWarningOptions !== void 0 && pasteWarningOptions.cannotPasteSyncedBlock && !hasSyncedBlockInSlice && isSyncedBlockInRawHtml) {
95
+ var _pasteWarningOptions$, _pasteWarningOptions$2, _pasteWarningOptions$3, _pasteWarningOptions$4;
96
+ showWarningFlag({
97
+ api: api,
98
+ title: pasteWarningOptions === null || pasteWarningOptions === void 0 || (_pasteWarningOptions$ = pasteWarningOptions.cannotPasteSyncedBlock) === null || _pasteWarningOptions$ === void 0 ? void 0 : _pasteWarningOptions$.title,
99
+ description: pasteWarningOptions === null || pasteWarningOptions === void 0 || (_pasteWarningOptions$2 = pasteWarningOptions.cannotPasteSyncedBlock) === null || _pasteWarningOptions$2 === void 0 ? void 0 : _pasteWarningOptions$2.description,
100
+ urlText: pasteWarningOptions === null || pasteWarningOptions === void 0 || (_pasteWarningOptions$3 = pasteWarningOptions.cannotPasteSyncedBlock) === null || _pasteWarningOptions$3 === void 0 ? void 0 : _pasteWarningOptions$3.urlText,
101
+ urlHref: pasteWarningOptions === null || pasteWarningOptions === void 0 || (_pasteWarningOptions$4 = pasteWarningOptions.cannotPasteSyncedBlock) === null || _pasteWarningOptions$4 === void 0 ? void 0 : _pasteWarningOptions$4.urlHref
102
+ });
103
+ }
104
+ return slice;
105
+ };
106
+
107
+ /**
108
+ * If we are copying from editor, transform the copied source or reference sync block to a new reference sync block
109
+ * Otherwise, (e.g. if copying from renderer), flatten out the content and remove the sync block
110
+ */
111
+ var handleSyncBlocksPasteOld = function handleSyncBlocksPasteOld(slice, schema, pasteSource) {
112
+ var isFromEditor = pasteSource === 'fabric-editor';
113
+ slice = (0, _utils.mapSlice)(slice, function (node) {
114
+ if (node.type === schema.nodes.syncBlock) {
115
+ return transformSyncBlockNode(node, schema, isFromEditor);
116
+ } else if (node.type === schema.nodes.bodiedSyncBlock) {
117
+ return transformBodiedSyncBlockNode(node, isFromEditor);
118
+ }
119
+ return node;
120
+ });
121
+ return slice;
122
+ };
123
+ var handleSyncBlocksPaste = exports.handleSyncBlocksPaste = function handleSyncBlocksPaste(slice, schema, pasteSource, rawHtml, pasteWarningOptions, api) {
124
+ if ((0, _platformFeatureFlags.fg)('platform_synced_block_dogfooding')) {
125
+ return handleSyncBlocksPasteNew(slice, schema, pasteSource, rawHtml, pasteWarningOptions, api);
126
+ } else {
127
+ return handleSyncBlocksPasteOld(slice, schema, pasteSource);
128
+ }
129
+ };
@@ -0,0 +1,107 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
+ var _typeof = require("@babel/runtime/helpers/typeof");
5
+ Object.defineProperty(exports, "__esModule", {
6
+ value: true
7
+ });
8
+ exports.Flag = void 0;
9
+ var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
10
+ var _react = _interopRequireDefault(require("react"));
11
+ var _reactIntlNext = require("react-intl-next");
12
+ var _hooks = require("@atlaskit/editor-common/hooks");
13
+ var _flag = _interopRequireWildcard(require("@atlaskit/flag"));
14
+ var _statusError = _interopRequireDefault(require("@atlaskit/icon/core/status-error"));
15
+ var _statusSuccess = _interopRequireDefault(require("@atlaskit/icon/core/status-success"));
16
+ var _statusWarning = _interopRequireDefault(require("@atlaskit/icon/core/status-warning"));
17
+ var _actions = require("../editor-actions/actions");
18
+ var _pastePluginType = require("../pastePluginType");
19
+ var _pluginFactory = require("../pm-plugins/plugin-factory");
20
+ 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 _t in e) "default" !== _t && {}.hasOwnProperty.call(e, _t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, _t)) && (i.get || i.set) ? o(f, _t, i) : f[_t] = e[_t]); return f; })(e, t); }
21
+ 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; }
22
+ 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; }
23
+ var Flag = exports.Flag = function Flag(_ref) {
24
+ var api = _ref.api;
25
+ var _useSharedPluginState = (0, _hooks.useSharedPluginStateWithSelector)(api, ['paste'], function (states) {
26
+ var _states$pasteState;
27
+ return {
28
+ activeFlag: (_states$pasteState = states.pasteState) === null || _states$pasteState === void 0 ? void 0 : _states$pasteState.activeFlag
29
+ };
30
+ }),
31
+ activeFlag = _useSharedPluginState.activeFlag;
32
+ var _useIntl = (0, _reactIntlNext.useIntl)(),
33
+ formatMessage = _useIntl.formatMessage;
34
+ if (!activeFlag) {
35
+ return;
36
+ }
37
+ var type = activeFlag.type,
38
+ onDismissedCallback = activeFlag.onDismissed,
39
+ flagDescription = activeFlag.description,
40
+ flagTitle = activeFlag.title,
41
+ flagUrlText = activeFlag.urlText,
42
+ flagUrlHref = activeFlag.urlHref;
43
+ var description = flagDescription ? formatMessage(flagDescription) : undefined;
44
+ var title = flagTitle ? formatMessage(flagTitle) : undefined;
45
+ var urlText = flagUrlText ? formatMessage(flagUrlText) : undefined;
46
+ var onDismissed = function onDismissed() {
47
+ api === null || api === void 0 || api.core.actions.execute(function (_ref2) {
48
+ var tr = _ref2.tr;
49
+ onDismissedCallback === null || onDismissedCallback === void 0 || onDismissedCallback(tr);
50
+ var oldMeta = tr.getMeta(_pluginFactory.pluginKey);
51
+ tr.setMeta(_pluginFactory.pluginKey, _objectSpread(_objectSpread({}, oldMeta), {}, {
52
+ type: _actions.PastePluginActionTypes.SET_ACTIVE_FLAG,
53
+ activeFlag: false
54
+ }));
55
+ return tr;
56
+ });
57
+ api === null || api === void 0 || api.core.actions.focus();
58
+ };
59
+ var getActions = function getActions() {
60
+ var action = urlText && flagUrlHref ? {
61
+ content: urlText,
62
+ href: flagUrlHref
63
+ } : undefined;
64
+ if (action) {
65
+ return [{
66
+ content: action.content,
67
+ href: action.href,
68
+ target: '_blank'
69
+ }];
70
+ }
71
+ return undefined;
72
+ };
73
+ var getFlagComponent = function getFlagComponent() {
74
+ if (type === _pastePluginType.FLAG_TYPE.INFO || type === _pastePluginType.FLAG_TYPE.SUCCESS) {
75
+ return _flag.AutoDismissFlag;
76
+ }
77
+ return _flag.default;
78
+ };
79
+ var FlagComponent = getFlagComponent();
80
+ return /*#__PURE__*/_react.default.createElement(_flag.FlagGroup, null, /*#__PURE__*/_react.default.createElement(FlagComponent, {
81
+ onDismissed: onDismissed,
82
+ title: title,
83
+ description: description,
84
+ id: activeFlag.id,
85
+ testId: activeFlag.id,
86
+ icon: typeToIcon(type),
87
+ actions: getActions()
88
+ }));
89
+ };
90
+ var typeToIcon = function typeToIcon(type) {
91
+ if (type === 'error') {
92
+ return /*#__PURE__*/_react.default.createElement(_statusError.default, {
93
+ label: "",
94
+ color: "var(--ds-icon-danger, #C9372C)"
95
+ });
96
+ }
97
+ if (type === 'warning') {
98
+ return /*#__PURE__*/_react.default.createElement(_statusWarning.default, {
99
+ label: "",
100
+ color: "var(--ds-icon-warning, #E06C00)"
101
+ });
102
+ }
103
+ return /*#__PURE__*/_react.default.createElement(_statusSuccess.default, {
104
+ label: "",
105
+ color: "var(--ds-icon-success, #6A9A23)"
106
+ });
107
+ };
@@ -2,5 +2,6 @@ export let PastePluginActionTypes = /*#__PURE__*/function (PastePluginActionType
2
2
  PastePluginActionTypes["START_TRACKING_PASTED_MACRO_POSITIONS"] = "START_TRACKING_PASTED_MACRO_POSITIONS";
3
3
  PastePluginActionTypes["STOP_TRACKING_PASTED_MACRO_POSITIONS"] = "STOP_TRACKING_PASTED_MACRO_POSITIONS";
4
4
  PastePluginActionTypes["ON_PASTE"] = "ON_PASTE";
5
+ PastePluginActionTypes["SET_ACTIVE_FLAG"] = "SET_ACTIVE_FLAG";
5
6
  return PastePluginActionTypes;
6
7
  }({});
@@ -1,6 +1,10 @@
1
+ import React from 'react';
2
+ import { fg } from '@atlaskit/platform-feature-flags';
3
+ import { editorExperiment } from '@atlaskit/tmp-editor-statsig/experiments';
1
4
  import { createPlugin } from './pm-plugins/main';
2
5
  import { createPlugin as createMoveAnalyticsPlugin } from './pm-plugins/move-analytics/plugin';
3
6
  import { pluginKey } from './pm-plugins/plugin-factory';
7
+ import { Flag } from './ui/Flag';
4
8
  export const pastePlugin = ({
5
9
  config,
6
10
  api
@@ -9,7 +13,8 @@ export const pastePlugin = ({
9
13
  const {
10
14
  cardOptions,
11
15
  sanitizePrivateContent,
12
- isFullPage
16
+ isFullPage,
17
+ pasteWarningOptions
13
18
  } = config !== null && config !== void 0 ? config : {};
14
19
  const featureFlags = (api === null || api === void 0 ? void 0 : (_api$featureFlags = api.featureFlags) === null || _api$featureFlags === void 0 ? void 0 : _api$featureFlags.sharedState.currentState()) || {};
15
20
  const editorAnalyticsAPI = api === null || api === void 0 ? void 0 : (_api$analytics = api.analytics) === null || _api$analytics === void 0 ? void 0 : _api$analytics.actions;
@@ -24,7 +29,7 @@ export const pastePlugin = ({
24
29
  dispatchAnalyticsEvent,
25
30
  dispatch,
26
31
  getIntl
27
- }) => createPlugin(schema, dispatchAnalyticsEvent, dispatch, featureFlags, api, getIntl, cardOptions, sanitizePrivateContent, providerFactory)
32
+ }) => createPlugin(schema, dispatchAnalyticsEvent, dispatch, featureFlags, api, getIntl, cardOptions, sanitizePrivateContent, providerFactory, pasteWarningOptions)
28
33
  }, {
29
34
  name: 'moveAnalyticsPlugin',
30
35
  plugin: ({
@@ -34,14 +39,24 @@ export const pastePlugin = ({
34
39
  }
35
40
  }];
36
41
  },
42
+ contentComponent: !editorExperiment('platform_synced_block', true) || !fg('platform_synced_block_dogfooding') ? undefined : () => {
43
+ if (!pasteWarningOptions) {
44
+ return null;
45
+ }
46
+ return /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement(Flag, {
47
+ api: api
48
+ }));
49
+ },
37
50
  getSharedState: editorState => {
38
51
  if (!editorState) {
39
52
  return {
53
+ activeFlag: null,
40
54
  lastContentPasted: null
41
55
  };
42
56
  }
43
57
  const pluginState = pluginKey.getState(editorState);
44
58
  return {
59
+ activeFlag: pluginState.activeFlag,
45
60
  lastContentPasted: pluginState.lastContentPasted
46
61
  };
47
62
  }
@@ -1 +1,7 @@
1
- export {};
1
+ export let FLAG_TYPE = /*#__PURE__*/function (FLAG_TYPE) {
2
+ FLAG_TYPE["WARNING"] = "warning";
3
+ FLAG_TYPE["ERROR"] = "error";
4
+ FLAG_TYPE["INFO"] = "info";
5
+ FLAG_TYPE["SUCCESS"] = "success";
6
+ return FLAG_TYPE;
7
+ }({});
@@ -9,7 +9,7 @@ import { isPastedFile as isPastedFileFromEvent, md } from '@atlaskit/editor-comm
9
9
  import { measureRender } from '@atlaskit/editor-common/performance/measure-render';
10
10
  import { SafePlugin } from '@atlaskit/editor-common/safe-plugin';
11
11
  import { SyncBlockRendererDataAttributeName } from '@atlaskit/editor-common/sync-block';
12
- import { transformSingleColumnLayout, transformSingleLineCodeBlockToCodeMark, transformSliceNestedExpandToExpand, transformSliceToDecisionList, transformSliceToJoinAdjacentCodeBlocks, transformSliceToRemoveLegacyContentMacro, transformSliceToRemoveMacroId, transformSyncBlock, removeBreakoutFromRendererSyncBlockHTML } from '@atlaskit/editor-common/transforms';
12
+ import { transformSingleColumnLayout, transformSingleLineCodeBlockToCodeMark, transformSliceNestedExpandToExpand, transformSliceToDecisionList, transformSliceToJoinAdjacentCodeBlocks, transformSliceToRemoveLegacyContentMacro, transformSliceToRemoveMacroId, removeBreakoutFromRendererSyncBlockHTML } from '@atlaskit/editor-common/transforms';
13
13
  import { containsAnyAnnotations, extractSliceFromStep, linkifyContent, mapChildren } from '@atlaskit/editor-common/utils';
14
14
  import { MarkdownTransformer } from '@atlaskit/editor-markdown-transformer';
15
15
  import { Fragment, Slice } from '@atlaskit/editor-prosemirror/model';
@@ -28,6 +28,7 @@ import { createPluginState, pluginKey as stateKey } from './plugin-factory';
28
28
  import { escapeBackslashAndLinksExceptCodeBlock, getPasteSource, htmlContainsSingleFile, htmlHasInvalidLinkTags, isPastedFromExcel, isPastedFromWord, removeDuplicateInvalidLinks, transformUnsupportedBlockCardToInline } from './util';
29
29
  import { handleVSCodeBlock } from './util/edge-cases/handleVSCodeBlock';
30
30
  import { handleMacroAutoConvert, handleMention, handleParagraphBlockMarks, handleTableContentPasteInBodiedExtension } from './util/handlers';
31
+ import { handleSyncBlocksPaste } from './util/sync-block';
31
32
  import { htmlHasIncompleteTable, isPastedFromTinyMCEConfluence, tryRebuildCompleteTableHtml } from './util/tinyMCE';
32
33
  export const isInsideBlockQuote = state => {
33
34
  const {
@@ -57,7 +58,7 @@ export function isSharePointUrl(url) {
57
58
  return false;
58
59
  }
59
60
  }
60
- export function createPlugin(schema, dispatchAnalyticsEvent, dispatch, featureFlags, pluginInjectionApi, getIntl, cardOptions, sanitizePrivateContent, providerFactory) {
61
+ export function createPlugin(schema, dispatchAnalyticsEvent, dispatch, featureFlags, pluginInjectionApi, getIntl, cardOptions, sanitizePrivateContent, providerFactory, pasteWarningOptions) {
61
62
  var _pluginInjectionApi$a;
62
63
  const editorAnalyticsAPI = pluginInjectionApi === null || pluginInjectionApi === void 0 ? void 0 : (_pluginInjectionApi$a = pluginInjectionApi.analytics) === null || _pluginInjectionApi$a === void 0 ? void 0 : _pluginInjectionApi$a.actions;
63
64
  const atlassianMarkDownParser = new MarkdownTransformer(schema, md);
@@ -89,6 +90,7 @@ export function createPlugin(schema, dispatchAnalyticsEvent, dispatch, featureFl
89
90
  return new SafePlugin({
90
91
  key: stateKey,
91
92
  state: createPluginState(dispatch, {
93
+ activeFlag: null,
92
94
  pastedMacroPositions: {},
93
95
  lastContentPasted: null
94
96
  }),
@@ -289,7 +291,7 @@ export function createPlugin(schema, dispatchAnalyticsEvent, dispatch, featureFl
289
291
  text
290
292
  });
291
293
  if (editorExperiment('platform_synced_block', true)) {
292
- slice = transformSyncBlock(slice, schema, getPasteSource(event));
294
+ slice = handleSyncBlocksPaste(slice, schema, getPasteSource(event), html, pasteWarningOptions, pluginInjectionApi);
293
295
  }
294
296
  const plainTextPasteSlice = linkifyContent(state.schema)(slice);
295
297
  if (handlePasteAsPlainTextWithAnalytics(editorAnalyticsAPI)(view, event, plainTextPasteSlice)(state, dispatch, view)) {
@@ -1,3 +1,5 @@
1
+ import { fg } from '@atlaskit/platform-feature-flags';
2
+ import { editorExperiment } from '@atlaskit/tmp-editor-statsig/experiments';
1
3
  import { PastePluginActionTypes as ActionTypes } from '../editor-actions/actions';
2
4
  export const reducer = (state, action) => {
3
5
  switch (action.type) {
@@ -26,6 +28,19 @@ export const reducer = (state, action) => {
26
28
  lastContentPasted: action.contentPasted
27
29
  };
28
30
  }
31
+ case ActionTypes.SET_ACTIVE_FLAG:
32
+ {
33
+ if (!editorExperiment('platform_synced_block', true)) {
34
+ return state;
35
+ }
36
+ if (!fg('platform_synced_block_dogfooding')) {
37
+ return state;
38
+ }
39
+ return {
40
+ ...state,
41
+ activeFlag: action.activeFlag
42
+ };
43
+ }
29
44
  default:
30
45
  return state;
31
46
  }