@atlaskit/editor-common 74.36.4 → 74.38.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.
Files changed (79) hide show
  1. package/CHANGELOG.md +22 -0
  2. package/dist/cjs/guideline/constants.js +4 -2
  3. package/dist/cjs/guideline/defaultGuideline.js +4 -3
  4. package/dist/cjs/guideline/index.js +10 -4
  5. package/dist/cjs/guideline/snapping.js +42 -30
  6. package/dist/cjs/keymaps/index.js +11 -7
  7. package/dist/cjs/monitoring/error.js +1 -1
  8. package/dist/cjs/preset/index.js +8 -1
  9. package/dist/cjs/preset/plugin-commands.js +19 -0
  10. package/dist/cjs/preset/plugin-injection-api.js +28 -1
  11. package/dist/cjs/types/layout.js +5 -0
  12. package/dist/cjs/types/plugin-command.js +5 -0
  13. package/dist/cjs/types/selection.js +5 -0
  14. package/dist/cjs/ui/DropList/index.js +1 -1
  15. package/dist/cjs/ui/MediaSingle/styled.js +1 -1
  16. package/dist/cjs/version.json +1 -1
  17. package/dist/es2019/guideline/constants.js +2 -1
  18. package/dist/es2019/guideline/defaultGuideline.js +4 -3
  19. package/dist/es2019/guideline/index.js +2 -2
  20. package/dist/es2019/guideline/snapping.js +35 -27
  21. package/dist/es2019/keymaps/index.js +10 -7
  22. package/dist/es2019/monitoring/error.js +1 -1
  23. package/dist/es2019/preset/index.js +2 -1
  24. package/dist/es2019/preset/plugin-commands.js +14 -0
  25. package/dist/es2019/preset/plugin-injection-api.js +21 -1
  26. package/dist/es2019/types/layout.js +1 -0
  27. package/dist/es2019/types/plugin-command.js +1 -0
  28. package/dist/es2019/types/selection.js +1 -0
  29. package/dist/es2019/ui/DropList/index.js +1 -1
  30. package/dist/es2019/ui/MediaSingle/styled.js +8 -7
  31. package/dist/es2019/version.json +1 -1
  32. package/dist/esm/guideline/constants.js +2 -1
  33. package/dist/esm/guideline/defaultGuideline.js +4 -3
  34. package/dist/esm/guideline/index.js +2 -2
  35. package/dist/esm/guideline/snapping.js +40 -28
  36. package/dist/esm/keymaps/index.js +10 -7
  37. package/dist/esm/monitoring/error.js +1 -1
  38. package/dist/esm/preset/index.js +2 -1
  39. package/dist/esm/preset/plugin-commands.js +13 -0
  40. package/dist/esm/preset/plugin-injection-api.js +28 -1
  41. package/dist/esm/types/layout.js +1 -0
  42. package/dist/esm/types/plugin-command.js +1 -0
  43. package/dist/esm/types/selection.js +1 -0
  44. package/dist/esm/ui/DropList/index.js +1 -1
  45. package/dist/esm/ui/MediaSingle/styled.js +2 -1
  46. package/dist/esm/version.json +1 -1
  47. package/dist/types/collab/index.d.ts +25 -0
  48. package/dist/types/guideline/constants.d.ts +1 -0
  49. package/dist/types/guideline/dynamicGuideline.d.ts +1 -1
  50. package/dist/types/guideline/index.d.ts +3 -3
  51. package/dist/types/guideline/snapping.d.ts +12 -11
  52. package/dist/types/guideline/types.d.ts +13 -2
  53. package/dist/types/keymaps/index.d.ts +5 -1
  54. package/dist/types/preset/index.d.ts +1 -0
  55. package/dist/types/preset/plugin-commands.d.ts +3 -0
  56. package/dist/types/preset/plugin-injection-api.d.ts +1 -0
  57. package/dist/types/types/index.d.ts +4 -1
  58. package/dist/types/types/layout.d.ts +6 -0
  59. package/dist/types/types/next-editor-plugin.d.ts +10 -1
  60. package/dist/types/types/plugin-command.d.ts +7 -0
  61. package/dist/types/types/selection.d.ts +3 -0
  62. package/dist/types/ui/MediaSingle/styled.d.ts +3 -2
  63. package/dist/types-ts4.5/collab/index.d.ts +25 -0
  64. package/dist/types-ts4.5/guideline/constants.d.ts +1 -0
  65. package/dist/types-ts4.5/guideline/dynamicGuideline.d.ts +1 -1
  66. package/dist/types-ts4.5/guideline/index.d.ts +3 -3
  67. package/dist/types-ts4.5/guideline/snapping.d.ts +12 -11
  68. package/dist/types-ts4.5/guideline/types.d.ts +13 -2
  69. package/dist/types-ts4.5/keymaps/index.d.ts +5 -1
  70. package/dist/types-ts4.5/preset/index.d.ts +1 -0
  71. package/dist/types-ts4.5/preset/plugin-commands.d.ts +3 -0
  72. package/dist/types-ts4.5/preset/plugin-injection-api.d.ts +1 -0
  73. package/dist/types-ts4.5/types/index.d.ts +4 -1
  74. package/dist/types-ts4.5/types/layout.d.ts +6 -0
  75. package/dist/types-ts4.5/types/next-editor-plugin.d.ts +10 -1
  76. package/dist/types-ts4.5/types/plugin-command.d.ts +7 -0
  77. package/dist/types-ts4.5/types/selection.d.ts +3 -0
  78. package/dist/types-ts4.5/ui/MediaSingle/styled.d.ts +3 -2
  79. package/package.json +1 -1
package/CHANGELOG.md CHANGED
@@ -1,5 +1,27 @@
1
1
  # @atlaskit/editor-common
2
2
 
3
+ ## 74.38.0
4
+
5
+ ### Minor Changes
6
+
7
+ - [`a675f834911`](https://bitbucket.org/atlassian/atlassian-frontend/commits/a675f834911) - Introduce `commands` optional parameter to `NextEditorPlugin`. It can be used similarly to `actions` in `NextEditorPlugin` but `commands` must adhere to the type of `PluginCommand`:
8
+
9
+ ```ts
10
+ type PluginCommand = ({ tr }: { tr: Transaction }) => Transaction | null;
11
+ ```
12
+
13
+ `PluginCommand`s are specifically used for code that is executed to modify a Transaction. They should be used in preference to the existing prosemirror `Command` type.
14
+
15
+ ### Patch Changes
16
+
17
+ - [`3bbe8f91f34`](https://bitbucket.org/atlassian/atlassian-frontend/commits/3bbe8f91f34) - refactor ResizableMediaSingleNext around guidelines and snapping
18
+
19
+ ## 74.37.0
20
+
21
+ ### Minor Changes
22
+
23
+ - [`8699cf99ceb`](https://bitbucket.org/atlassian/atlassian-frontend/commits/8699cf99ceb) - Exporting LayoutPluginOptions and CollabEditOptions from editor-common.
24
+
3
25
  ## 74.36.4
4
26
 
5
27
  ### Patch Changes
@@ -3,6 +3,8 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- exports.MEDIA_DYNAMIC_GUIDELINE_PREFIX = void 0;
6
+ exports.MEDIA_DYNAMIC_GUIDELINE_PREFIX = exports.INNER_GRID_GUIDELINE_PREFIX = void 0;
7
7
  var MEDIA_DYNAMIC_GUIDELINE_PREFIX = 'media_';
8
- exports.MEDIA_DYNAMIC_GUIDELINE_PREFIX = MEDIA_DYNAMIC_GUIDELINE_PREFIX;
8
+ exports.MEDIA_DYNAMIC_GUIDELINE_PREFIX = MEDIA_DYNAMIC_GUIDELINE_PREFIX;
9
+ var INNER_GRID_GUIDELINE_PREFIX = 'grid_';
10
+ exports.INNER_GRID_GUIDELINE_PREFIX = INNER_GRID_GUIDELINE_PREFIX;
@@ -8,19 +8,20 @@ exports.generateDefaultGuidelines = void 0;
8
8
  var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray"));
9
9
  var _memoizeOne = _interopRequireDefault(require("memoize-one"));
10
10
  var _editorSharedStyles = require("@atlaskit/editor-shared-styles");
11
+ var _mediaSingle = require("../media-single");
11
12
  var _utils = require("./utils");
12
13
  var getDefaultGuidelines = (0, _memoizeOne.default)(function (editorWidth) {
13
14
  return [-6, -5, -4, -3, -2, -1, 0, 1, 2, 3, 4, 5, 6].map(function (val, index) {
14
15
  return {
15
16
  key: "grid_".concat(index),
16
17
  position: {
17
- x: val / 12 * editorWidth
18
+ x: (0, _mediaSingle.roundToNearest)(val / 12 * editorWidth)
18
19
  }
19
20
  };
20
21
  });
21
22
  });
22
23
  var getWideGuidelines = (0, _memoizeOne.default)(function (editorWidth) {
23
- var wideSpacing = editorWidth * _editorSharedStyles.breakoutWideScaleRatio / 2;
24
+ var wideSpacing = (0, _mediaSingle.roundToNearest)(editorWidth * _editorSharedStyles.breakoutWideScaleRatio / 2);
24
25
  return [{
25
26
  key: "wide_left",
26
27
  position: {
@@ -34,7 +35,7 @@ var getWideGuidelines = (0, _memoizeOne.default)(function (editorWidth) {
34
35
  }];
35
36
  });
36
37
  var getFullWidthGuidelines = (0, _memoizeOne.default)(function (containerWidth) {
37
- var fullWidth = (0, _utils.getContainerWidthOrFullEditorWidth)(containerWidth);
38
+ var fullWidth = (0, _mediaSingle.roundToNearest)((0, _utils.getContainerWidthOrFullEditorWidth)(containerWidth));
38
39
  return [{
39
40
  key: "full_width_left",
40
41
  position: {
@@ -3,6 +3,12 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
+ Object.defineProperty(exports, "INNER_GRID_GUIDELINE_PREFIX", {
7
+ enumerable: true,
8
+ get: function get() {
9
+ return _constants.INNER_GRID_GUIDELINE_PREFIX;
10
+ }
11
+ });
6
12
  Object.defineProperty(exports, "MEDIA_DYNAMIC_GUIDELINE_PREFIX", {
7
13
  enumerable: true,
8
14
  get: function get() {
@@ -45,16 +51,16 @@ Object.defineProperty(exports, "getContainerWidthOrFullEditorWidth", {
45
51
  return _utils.getContainerWidthOrFullEditorWidth;
46
52
  }
47
53
  });
48
- Object.defineProperty(exports, "getGuidelinesWithHighlights", {
54
+ Object.defineProperty(exports, "getGuidelineSnaps", {
49
55
  enumerable: true,
50
56
  get: function get() {
51
- return _updateGuideline.getGuidelinesWithHighlights;
57
+ return _snapping.getGuidelineSnaps;
52
58
  }
53
59
  });
54
- Object.defineProperty(exports, "getSnapWidth", {
60
+ Object.defineProperty(exports, "getGuidelinesWithHighlights", {
55
61
  enumerable: true,
56
62
  get: function get() {
57
- return _snapping.getSnapWidth;
63
+ return _updateGuideline.getGuidelinesWithHighlights;
58
64
  }
59
65
  });
60
66
  Object.defineProperty(exports, "isVerticalPosition", {
@@ -1,27 +1,31 @@
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
- exports.getSnapWidth = exports.findClosestSnap = void 0;
7
- var _mediaSingle = require("../media-single");
7
+ exports.getGuidelineSnaps = exports.findClosestSnap = void 0;
8
+ var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray"));
9
+ var _memoizeOne = _interopRequireDefault(require("memoize-one"));
8
10
  var _constants = require("./constants");
11
+ var _utils = require("./utils");
9
12
  /**
10
13
  * Returns keys of guidelines that are closest to the image and withthin the snapGap.
11
14
  * If both default and dynamic guidelines present, only returns default guidelines
12
15
  */
13
- var findClosestSnap = function findClosestSnap(mediaSingleWidth, snapArray, snapTo) {
16
+ var findClosestSnap = function findClosestSnap(mediaSingleWidth, snapArray, guidelineSnaps) {
14
17
  var snapGap = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : 0;
15
18
  var closestGapIndex = snapArray.reduce(function (prev, curr, index) {
16
19
  return Math.abs(curr - mediaSingleWidth) < Math.abs(snapArray[prev] - mediaSingleWidth) ? index : prev;
17
20
  }, 0);
18
21
  var gap = Math.abs(snapArray[closestGapIndex] - mediaSingleWidth);
19
22
  if (gap < snapGap) {
20
- var snappingWidth = Math.round(snapTo[closestGapIndex].width);
23
+ var snappingWidth = snapArray[closestGapIndex];
21
24
  var guidelineKeys = [];
22
- snapTo.forEach(function (s) {
23
- if (Math.round(Math.abs(s.width)) === snappingWidth) {
24
- guidelineKeys.push(s.guidelineKey);
25
+ // find wich guideline have the matching snap width
26
+ guidelineSnaps.forEach(function (gs) {
27
+ if (gs.width === snappingWidth) {
28
+ guidelineKeys.push(gs.guidelineKey);
25
29
  }
26
30
  });
27
31
  var defaultGuidelineKeys = guidelineKeys.filter(function (guidelineKey) {
@@ -39,37 +43,45 @@ var findClosestSnap = function findClosestSnap(mediaSingleWidth, snapArray, snap
39
43
  keys: []
40
44
  };
41
45
  };
42
-
43
- /**
44
- * Get snapping widths and respective guideline keys
45
- */
46
46
  exports.findClosestSnap = findClosestSnap;
47
- var getSnapWidth = function getSnapWidth(guidelines, mediaSingleWidth, snap, layout) {
48
- return guidelines.map(function (guideline) {
49
- var _guideline$position;
50
- var positionX = (_guideline$position = guideline.position) !== null && _guideline$position !== void 0 && _guideline$position.x && typeof guideline.position.x === 'number' ? guideline.position.x : 0;
51
- if (layout === _mediaSingle.MediaSingleLayout.CENTER || layout === _mediaSingle.MediaSingleLayout.WIDE || layout === _mediaSingle.MediaSingleLayout.FULL_WIDTH) {
52
- return {
53
- guidelineKey: guideline.key,
54
- width: mediaSingleWidth + (snap - positionX) * 2
55
- };
56
- } else if (layout === _mediaSingle.MediaSingleLayout.ALIGN_END || layout === _mediaSingle.MediaSingleLayout.WRAP_RIGHT) {
47
+ var getGuidelineSnaps = (0, _memoizeOne.default)(function (guidelines, editorWidth) {
48
+ var layout = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 'center';
49
+ var offset = editorWidth / 2;
50
+ var getPositionX = function getPositionX(position) {
51
+ return (0, _utils.isVerticalPosition)(position) ? position.x : 0;
52
+ };
53
+ var calcXSnaps = function calcXSnaps(guidelineReference) {
54
+ var snapsWidth = guidelineReference.filter(function (g) {
55
+ return g.width > 0;
56
+ }).map(function (g) {
57
+ return g.width;
58
+ });
59
+ var uniqueSnapWidth = (0, _toConsumableArray2.default)(new Set(snapsWidth));
60
+ return snapsWidth.length ? uniqueSnapWidth : undefined;
61
+ };
62
+ var guidelinesSnapsReference = guidelines.map(function (guideline) {
63
+ var positionX = getPositionX(guideline.position);
64
+ if (['align-end', 'wrap-right'].includes(layout)) {
57
65
  return {
58
66
  guidelineKey: guideline.key,
59
- width: mediaSingleWidth + (snap - positionX)
67
+ width: offset - positionX
60
68
  };
61
- } else if (layout === _mediaSingle.MediaSingleLayout.ALIGN_START || layout === _mediaSingle.MediaSingleLayout.WRAP_LEFT) {
69
+ } else if (['align-start', 'wrap-left'].includes(layout)) {
62
70
  return {
63
71
  guidelineKey: guideline.key,
64
- width: mediaSingleWidth + positionX - snap
72
+ width: positionX + offset
65
73
  };
66
74
  }
67
75
  return {
68
- guidelineKey: '',
69
- width: 0
76
+ guidelineKey: guideline.key,
77
+ width: Math.abs(positionX) * 2
70
78
  };
71
- }).filter(function (guideline) {
72
- return guideline.guidelineKey !== '';
73
79
  });
74
- };
75
- exports.getSnapWidth = getSnapWidth;
80
+ return {
81
+ guidelineReference: guidelinesSnapsReference,
82
+ snaps: {
83
+ x: calcXSnaps(guidelinesSnapsReference)
84
+ }
85
+ };
86
+ });
87
+ exports.getGuidelineSnaps = getGuidelineSnaps;
@@ -80,6 +80,7 @@ Object.defineProperty(exports, "UP", {
80
80
  });
81
81
  exports.backspace = exports.altPaste = exports.alignLeft = exports.addRowBefore = exports.addRowAfter = exports.addLink = exports.addInlineComment = exports.addColumnBefore = exports.addColumnAfter = exports.addAltText = void 0;
82
82
  exports.bindKeymapWithCommand = bindKeymapWithCommand;
83
+ exports.bindKeymapWithPluginCommand = bindKeymapWithPluginCommand;
83
84
  exports.find = exports.escape = exports.enter = exports.deleteKey = exports.cut = exports.ctrlBackSpace = exports.copy = exports.clearFormatting = void 0;
84
85
  exports.findKeyMapForBrowser = findKeyMapForBrowser;
85
86
  exports.findKeymapByDescription = findKeymapByDescription;
@@ -104,6 +105,7 @@ var _taggedTemplateLiteral2 = _interopRequireDefault(require("@babel/runtime/hel
104
105
  var _react = _interopRequireWildcard(require("react"));
105
106
  var _react2 = require("@emotion/react");
106
107
  var _colors = require("@atlaskit/theme/colors");
108
+ var _pluginCommands = require("../preset/plugin-commands");
107
109
  var _utils = require("../utils");
108
110
  var _consts = require("./consts");
109
111
  var _keymap = require("./keymap");
@@ -352,15 +354,17 @@ function makeKeyMapWithCommon(description, common) {
352
354
  var mac = common.replace(/Mod/i, 'Cmd');
353
355
  return makeKeymap(description, windows, mac, common);
354
356
  }
357
+ function combineWithOldCommand(cmd, oldCmd) {
358
+ return function (state, dispatch, editorView) {
359
+ return oldCmd(state, dispatch) || cmd(state, dispatch, editorView);
360
+ };
361
+ }
355
362
  function bindKeymapWithCommand(shortcut, cmd, keymap) {
356
363
  var oldCmd = keymap[shortcut];
357
- var newCmd = cmd;
358
- if (keymap[shortcut]) {
359
- newCmd = function newCmd(state, dispatch, editorView) {
360
- return oldCmd(state, dispatch) || cmd(state, dispatch, editorView);
361
- };
362
- }
363
- keymap[shortcut] = newCmd;
364
+ keymap[shortcut] = oldCmd ? combineWithOldCommand(cmd, oldCmd) : cmd;
365
+ }
366
+ function bindKeymapWithPluginCommand(shortcut, cmd, keymap) {
367
+ bindKeymapWithCommand(shortcut, (0, _pluginCommands.pluginCommandToPMCommand)(cmd), keymap);
364
368
  }
365
369
  function findKeyMapForBrowser(keyMap) {
366
370
  if (keyMap) {
@@ -16,7 +16,7 @@ function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "functio
16
16
  function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || _typeof(obj) !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
17
17
  var SENTRY_DSN = 'https://0b10c8e02fb44d8796c047b102c9bee8@o55978.ingest.sentry.io/4505129224110080';
18
18
  var packageName = 'editor-common'; // Sentry doesn't accept '/' in its releases https://docs.sentry.io/platforms/javascript/configuration/releases/
19
- var packageVersion = "74.36.4";
19
+ var packageVersion = "74.38.0";
20
20
  var sanitiseSentryEvents = function sanitiseSentryEvents(data, _hint) {
21
21
  // Remove URL as it has UGC
22
22
  // TODO: Sanitise the URL instead of just removing it
@@ -15,5 +15,12 @@ Object.defineProperty(exports, "EditorPresetBuilder", {
15
15
  return _builder.EditorPresetBuilder;
16
16
  }
17
17
  });
18
+ Object.defineProperty(exports, "pluginCommandToPMCommand", {
19
+ enumerable: true,
20
+ get: function get() {
21
+ return _pluginCommands.pluginCommandToPMCommand;
22
+ }
23
+ });
18
24
  var _builder = require("./builder");
19
- var _pluginInjectionApi = require("./plugin-injection-api");
25
+ var _pluginInjectionApi = require("./plugin-injection-api");
26
+ var _pluginCommands = require("./plugin-commands");
@@ -0,0 +1,19 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.pluginCommandToPMCommand = pluginCommandToPMCommand;
7
+ function pluginCommandToPMCommand(command) {
8
+ return function (_ref, dispatch) {
9
+ var tr = _ref.tr;
10
+ var newTr = command === null || command === void 0 ? void 0 : command({
11
+ tr: tr
12
+ });
13
+ if (newTr) {
14
+ dispatch === null || dispatch === void 0 ? void 0 : dispatch(newTr);
15
+ return true;
16
+ }
17
+ return false;
18
+ };
19
+ }
@@ -22,6 +22,9 @@ function hasGetSharedState(plugin) {
22
22
  function hasActions(plugin) {
23
23
  return (0, _typeof2.default)(plugin.actions) === 'object';
24
24
  }
25
+ function hasCommands(plugin) {
26
+ return (0, _typeof2.default)(plugin.commands) === 'object';
27
+ }
25
28
  var filterPluginsWithListeners = function filterPluginsWithListeners(_ref) {
26
29
  var listeners = _ref.listeners,
27
30
  plugins = _ref.plugins;
@@ -121,6 +124,26 @@ var ActionsAPI = /*#__PURE__*/function () {
121
124
  }]);
122
125
  return ActionsAPI;
123
126
  }();
127
+ var PluginCommandsAPI = /*#__PURE__*/function () {
128
+ function PluginCommandsAPI() {
129
+ (0, _classCallCheck2.default)(this, PluginCommandsAPI);
130
+ }
131
+ (0, _createClass2.default)(PluginCommandsAPI, [{
132
+ key: "createAPI",
133
+ value: function createAPI(plugin) {
134
+ if (!plugin || !hasCommands(plugin)) {
135
+ return {};
136
+ }
137
+ return new Proxy(plugin.commands || {}, {
138
+ get: function get(target, prop, receiver) {
139
+ // We will be able to track perfomance here
140
+ return Reflect.get(target, prop);
141
+ }
142
+ });
143
+ }
144
+ }]);
145
+ return PluginCommandsAPI;
146
+ }();
124
147
  var SharedStateAPI = /*#__PURE__*/function () {
125
148
  function SharedStateAPI(_ref4) {
126
149
  var getEditorState = _ref4.getEditorState;
@@ -246,12 +269,14 @@ var EditorPluginInjectionAPI = /*#__PURE__*/function () {
246
269
  });
247
270
  this.plugins = new Map();
248
271
  this.actionsAPI = new ActionsAPI();
272
+ this.commandsAPI = new PluginCommandsAPI();
249
273
  }
250
274
  (0, _createClass2.default)(EditorPluginInjectionAPI, [{
251
275
  key: "api",
252
276
  value: function api() {
253
277
  var sharedStateAPI = this.sharedStateAPI,
254
278
  actionsAPI = this.actionsAPI,
279
+ commandsAPI = this.commandsAPI,
255
280
  getPluginByName = this.getPluginByName;
256
281
  var dependencies = new Proxy({}, {
257
282
  get: function get(target, prop, receiver) {
@@ -270,9 +295,11 @@ var EditorPluginInjectionAPI = /*#__PURE__*/function () {
270
295
  }
271
296
  var sharedState = sharedStateAPI.createAPI(plugin);
272
297
  var actions = actionsAPI.createAPI(plugin);
298
+ var commands = commandsAPI.createAPI(plugin);
273
299
  var proxyCoreAPI = {
274
300
  sharedState: sharedState,
275
- actions: actions
301
+ actions: actions,
302
+ commands: commands
276
303
  };
277
304
  return proxyCoreAPI;
278
305
  }
@@ -0,0 +1,5 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
@@ -0,0 +1,5 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
@@ -0,0 +1,5 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
@@ -24,7 +24,7 @@ var _templateObject, _templateObject2, _templateObject3;
24
24
  function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = (0, _getPrototypeOf2.default)(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = (0, _getPrototypeOf2.default)(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return (0, _possibleConstructorReturn2.default)(this, result); }; }
25
25
  function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } } /** @jsx jsx */
26
26
  var packageName = "@atlaskit/editor-common";
27
- var packageVersion = "74.36.4";
27
+ var packageVersion = "74.38.0";
28
28
  var halfFocusRing = 1;
29
29
  var dropOffset = '0, 8';
30
30
  var DropList = /*#__PURE__*/function (_Component) {
@@ -141,7 +141,7 @@ var MediaSingleDimensionHelper = function MediaSingleDimensionHelper(_ref) {
141
141
  isExtendedResizeExperienceOn = _ref.isExtendedResizeExperienceOn,
142
142
  _ref$isNestedNode = _ref.isNestedNode,
143
143
  isNestedNode = _ref$isNestedNode === void 0 ? false : _ref$isNestedNode;
144
- return (0, _react2.css)(_templateObject || (_templateObject = (0, _taggedTemplateLiteral2.default)(["\n /* For nested rich media items, set max-width to 100% */\n tr &,\n [data-layout-column] &,\n [data-node-type='expand'] & {\n max-width: 100%;\n }\n\n width: ", ";\n ", "\n max-width: ", ";\n &[class*='is-resizing'] {\n ", "\n }\n\n /* Handles responsiveness of non-nested, not-resizing nodes in editor */\n &[class*='not-resizing'] {\n ", "\n }\n\n float: ", ";\n margin: ", ";\n ", ";\n\n &:not(.is-resizing) {\n transition: width 100ms ease-in;\n }\n"])), mediaSingleWidth || pctWidth ? calcResizedWidth(layout, width || 0, containerWidth) : calcLegacyWidth(layout, width || 0, containerWidth, fullWidthMode, isResized), layout === 'full-width' && (0, _react2.css)(_templateObject2 || (_templateObject2 = (0, _taggedTemplateLiteral2.default)(["\n min-width: 100%;\n "]))), calcMaxWidth(layout, containerWidth), isExtendedResizeExperienceOn && "max-width: ".concat(calcMaxWidthWhenResizing(containerWidth, fullWidthMode, isNestedNode), ";\n\n ").concat(_utils.nonWrappedLayouts.includes(layout) && "margin-left: 50%;\n transform: translateX(-50%);", "\n\n .new-file-experience-wrapper {\n box-shadow: none;\n }"), !isNestedNode && "max-width: ".concat(layout !== 'full-width' && mediaSingleWidth && calcMaxWidthWhenNotResizing(containerWidth, mediaSingleWidth), ";\n\n ").concat(_utils.nonWrappedLayouts.includes(layout) && "margin-left: 50%;\n transform: translateX(-50%);", "\n\n // override min-width to counteract max-width set in old experience\n ").concat(layout === 'full-width' && "min-width: ".concat(getEffectiveFullWidth(containerWidth, fullWidthMode), " !important;"), ";"), float(layout), calcMargin(layout), isImageAligned(layout));
144
+ return (0, _react2.css)(_templateObject || (_templateObject = (0, _taggedTemplateLiteral2.default)(["\n /* For nested rich media items, set max-width to 100% */\n tr &,\n [data-layout-column] &,\n [data-node-type='expand'] & {\n max-width: 100%;\n }\n\n width: ", ";\n ", "\n max-width: ", ";\n ", "\n\n /* Handles responsiveness of non-nested, not-resizing nodes in editor */\n &[class*='not-resizing'] {\n ", "\n }\n\n float: ", ";\n margin: ", ";\n ", ";\n\n &:not(.is-resizing) {\n transition: width 100ms ease-in;\n }\n"])), mediaSingleWidth || pctWidth ? calcResizedWidth(layout, width || 0, containerWidth) : calcLegacyWidth(layout, width || 0, containerWidth, fullWidthMode, isResized), layout === 'full-width' && (0, _react2.css)(_templateObject2 || (_templateObject2 = (0, _taggedTemplateLiteral2.default)(["\n min-width: 100%;\n "]))), calcMaxWidth(layout, containerWidth), isExtendedResizeExperienceOn && "&[class*='is-resizing'] {\n .new-file-experience-wrapper {\n box-shadow: none !important;\n }\n\n max-width: ".concat(calcMaxWidthWhenResizing(containerWidth, fullWidthMode, isNestedNode), ";\n\n ").concat(_utils.nonWrappedLayouts.includes(layout) && "margin-left: 50%;\n transform: translateX(-50%);", "\n }"), !isNestedNode && "max-width: ".concat(layout !== 'full-width' && mediaSingleWidth && calcMaxWidthWhenNotResizing(containerWidth, mediaSingleWidth), ";\n\n ").concat(_utils.nonWrappedLayouts.includes(layout) && "margin-left: 50%;\n transform: translateX(-50%);", "\n\n // override min-width to counteract max-width set in old experience\n ").concat(layout === 'full-width' && "min-width: ".concat(getEffectiveFullWidth(containerWidth, fullWidthMode), " !important;"), ";"), float(layout), calcMargin(layout), isImageAligned(layout));
145
145
  };
146
146
  exports.MediaSingleDimensionHelper = MediaSingleDimensionHelper;
147
147
  var RenderFallbackContainer = function RenderFallbackContainer(_ref2) {
@@ -1,5 +1,5 @@
1
1
  {
2
2
  "name": "@atlaskit/editor-common",
3
- "version": "74.36.4",
3
+ "version": "74.38.0",
4
4
  "sideEffects": false
5
5
  }
@@ -1 +1,2 @@
1
- export const MEDIA_DYNAMIC_GUIDELINE_PREFIX = 'media_';
1
+ export const MEDIA_DYNAMIC_GUIDELINE_PREFIX = 'media_';
2
+ export const INNER_GRID_GUIDELINE_PREFIX = 'grid_';
@@ -1,16 +1,17 @@
1
1
  import memoizeOne from 'memoize-one';
2
2
  import { breakoutWideScaleRatio } from '@atlaskit/editor-shared-styles';
3
+ import { roundToNearest } from '../media-single';
3
4
  import { getContainerWidthOrFullEditorWidth } from './utils';
4
5
  const getDefaultGuidelines = memoizeOne(editorWidth => {
5
6
  return [-6, -5, -4, -3, -2, -1, 0, 1, 2, 3, 4, 5, 6].map((val, index) => ({
6
7
  key: `grid_${index}`,
7
8
  position: {
8
- x: val / 12 * editorWidth
9
+ x: roundToNearest(val / 12 * editorWidth)
9
10
  }
10
11
  }));
11
12
  });
12
13
  const getWideGuidelines = memoizeOne(editorWidth => {
13
- const wideSpacing = editorWidth * breakoutWideScaleRatio / 2;
14
+ const wideSpacing = roundToNearest(editorWidth * breakoutWideScaleRatio / 2);
14
15
  return [{
15
16
  key: `wide_left`,
16
17
  position: {
@@ -24,7 +25,7 @@ const getWideGuidelines = memoizeOne(editorWidth => {
24
25
  }];
25
26
  });
26
27
  const getFullWidthGuidelines = memoizeOne(containerWidth => {
27
- const fullWidth = getContainerWidthOrFullEditorWidth(containerWidth);
28
+ const fullWidth = roundToNearest(getContainerWidthOrFullEditorWidth(containerWidth));
28
29
  return [{
29
30
  key: `full_width_left`,
30
31
  position: {
@@ -2,6 +2,6 @@ export { generateDynamicGuidelines } from './dynamicGuideline';
2
2
  export { createFixedGuidelinesFromLengths, createGuidesFromLengths } from './fixedGuideline';
3
3
  export { generateDefaultGuidelines } from './defaultGuideline';
4
4
  export { getGuidelinesWithHighlights } from './updateGuideline';
5
- export { MEDIA_DYNAMIC_GUIDELINE_PREFIX } from './constants';
6
- export { getSnapWidth, findClosestSnap } from './snapping';
5
+ export { MEDIA_DYNAMIC_GUIDELINE_PREFIX, INNER_GRID_GUIDELINE_PREFIX } from './constants';
6
+ export { getGuidelineSnaps, findClosestSnap } from './snapping';
7
7
  export { isVerticalPosition, getContainerWidthOrFullEditorWidth } from './utils';
@@ -1,18 +1,21 @@
1
- import { MediaSingleLayout } from '../media-single';
1
+ import memoizeOne from 'memoize-one';
2
2
  import { MEDIA_DYNAMIC_GUIDELINE_PREFIX } from './constants';
3
+ import { isVerticalPosition } from './utils';
4
+
3
5
  /**
4
6
  * Returns keys of guidelines that are closest to the image and withthin the snapGap.
5
7
  * If both default and dynamic guidelines present, only returns default guidelines
6
8
  */
7
- export const findClosestSnap = (mediaSingleWidth, snapArray, snapTo, snapGap = 0) => {
9
+ export const findClosestSnap = (mediaSingleWidth, snapArray, guidelineSnaps, snapGap = 0) => {
8
10
  const closestGapIndex = snapArray.reduce((prev, curr, index) => Math.abs(curr - mediaSingleWidth) < Math.abs(snapArray[prev] - mediaSingleWidth) ? index : prev, 0);
9
11
  const gap = Math.abs(snapArray[closestGapIndex] - mediaSingleWidth);
10
12
  if (gap < snapGap) {
11
- const snappingWidth = Math.round(snapTo[closestGapIndex].width);
13
+ const snappingWidth = snapArray[closestGapIndex];
12
14
  let guidelineKeys = [];
13
- snapTo.forEach(s => {
14
- if (Math.round(Math.abs(s.width)) === snappingWidth) {
15
- guidelineKeys.push(s.guidelineKey);
15
+ // find wich guideline have the matching snap width
16
+ guidelineSnaps.forEach(gs => {
17
+ if (gs.width === snappingWidth) {
18
+ guidelineKeys.push(gs.guidelineKey);
16
19
  }
17
20
  });
18
21
  const defaultGuidelineKeys = guidelineKeys.filter(guidelineKey => !guidelineKey.startsWith(MEDIA_DYNAMIC_GUIDELINE_PREFIX));
@@ -28,33 +31,38 @@ export const findClosestSnap = (mediaSingleWidth, snapArray, snapTo, snapGap = 0
28
31
  keys: []
29
32
  };
30
33
  };
31
-
32
- /**
33
- * Get snapping widths and respective guideline keys
34
- */
35
- export const getSnapWidth = (guidelines, mediaSingleWidth, snap, layout) => {
36
- return guidelines.map(guideline => {
37
- var _guideline$position;
38
- const positionX = (_guideline$position = guideline.position) !== null && _guideline$position !== void 0 && _guideline$position.x && typeof guideline.position.x === 'number' ? guideline.position.x : 0;
39
- if (layout === MediaSingleLayout.CENTER || layout === MediaSingleLayout.WIDE || layout === MediaSingleLayout.FULL_WIDTH) {
40
- return {
41
- guidelineKey: guideline.key,
42
- width: mediaSingleWidth + (snap - positionX) * 2
43
- };
44
- } else if (layout === MediaSingleLayout.ALIGN_END || layout === MediaSingleLayout.WRAP_RIGHT) {
34
+ export const getGuidelineSnaps = memoizeOne((guidelines, editorWidth, layout = 'center') => {
35
+ const offset = editorWidth / 2;
36
+ const getPositionX = position => {
37
+ return isVerticalPosition(position) ? position.x : 0;
38
+ };
39
+ const calcXSnaps = guidelineReference => {
40
+ const snapsWidth = guidelineReference.filter(g => g.width > 0).map(g => g.width);
41
+ const uniqueSnapWidth = [...new Set(snapsWidth)];
42
+ return snapsWidth.length ? uniqueSnapWidth : undefined;
43
+ };
44
+ const guidelinesSnapsReference = guidelines.map(guideline => {
45
+ const positionX = getPositionX(guideline.position);
46
+ if (['align-end', 'wrap-right'].includes(layout)) {
45
47
  return {
46
48
  guidelineKey: guideline.key,
47
- width: mediaSingleWidth + (snap - positionX)
49
+ width: offset - positionX
48
50
  };
49
- } else if (layout === MediaSingleLayout.ALIGN_START || layout === MediaSingleLayout.WRAP_LEFT) {
51
+ } else if (['align-start', 'wrap-left'].includes(layout)) {
50
52
  return {
51
53
  guidelineKey: guideline.key,
52
- width: mediaSingleWidth + positionX - snap
54
+ width: positionX + offset
53
55
  };
54
56
  }
55
57
  return {
56
- guidelineKey: '',
57
- width: 0
58
+ guidelineKey: guideline.key,
59
+ width: Math.abs(positionX) * 2
58
60
  };
59
- }).filter(guideline => guideline.guidelineKey !== '');
60
- };
61
+ });
62
+ return {
63
+ guidelineReference: guidelinesSnapsReference,
64
+ snaps: {
65
+ x: calcXSnaps(guidelinesSnapsReference)
66
+ }
67
+ };
68
+ });
@@ -2,6 +2,7 @@
2
2
  import React, { Fragment } from 'react';
3
3
  import { css, jsx } from '@emotion/react';
4
4
  import { N400 } from '@atlaskit/theme/colors';
5
+ import { pluginCommandToPMCommand } from '../preset/plugin-commands';
5
6
  import { browser } from '../utils';
6
7
  export const addAltText = makeKeyMapWithCommon('Add Alt Text', 'Mod-Alt-y');
7
8
  export const navToEditorToolbar = makeKeyMapWithCommon('Navigate to editor toolbar', 'Alt-F9');
@@ -186,15 +187,17 @@ export function makeKeyMapWithCommon(description, common) {
186
187
  const mac = common.replace(/Mod/i, 'Cmd');
187
188
  return makeKeymap(description, windows, mac, common);
188
189
  }
190
+ function combineWithOldCommand(cmd, oldCmd) {
191
+ return (state, dispatch, editorView) => {
192
+ return oldCmd(state, dispatch) || cmd(state, dispatch, editorView);
193
+ };
194
+ }
189
195
  export function bindKeymapWithCommand(shortcut, cmd, keymap) {
190
196
  const oldCmd = keymap[shortcut];
191
- let newCmd = cmd;
192
- if (keymap[shortcut]) {
193
- newCmd = (state, dispatch, editorView) => {
194
- return oldCmd(state, dispatch) || cmd(state, dispatch, editorView);
195
- };
196
- }
197
- keymap[shortcut] = newCmd;
197
+ keymap[shortcut] = oldCmd ? combineWithOldCommand(cmd, oldCmd) : cmd;
198
+ }
199
+ export function bindKeymapWithPluginCommand(shortcut, cmd, keymap) {
200
+ bindKeymapWithCommand(shortcut, pluginCommandToPMCommand(cmd), keymap);
198
201
  }
199
202
  export function findKeyMapForBrowser(keyMap) {
200
203
  if (keyMap) {
@@ -1,6 +1,6 @@
1
1
  const SENTRY_DSN = 'https://0b10c8e02fb44d8796c047b102c9bee8@o55978.ingest.sentry.io/4505129224110080';
2
2
  const packageName = 'editor-common'; // Sentry doesn't accept '/' in its releases https://docs.sentry.io/platforms/javascript/configuration/releases/
3
- const packageVersion = "74.36.4";
3
+ const packageVersion = "74.38.0";
4
4
  const sanitiseSentryEvents = (data, _hint) => {
5
5
  // Remove URL as it has UGC
6
6
  // TODO: Sanitise the URL instead of just removing it
@@ -1,2 +1,3 @@
1
1
  export { EditorPresetBuilder } from './builder';
2
- export { EditorPluginInjectionAPI } from './plugin-injection-api';
2
+ export { EditorPluginInjectionAPI } from './plugin-injection-api';
3
+ export { pluginCommandToPMCommand } from './plugin-commands';
@@ -0,0 +1,14 @@
1
+ export function pluginCommandToPMCommand(command) {
2
+ return ({
3
+ tr
4
+ }, dispatch) => {
5
+ const newTr = command === null || command === void 0 ? void 0 : command({
6
+ tr
7
+ });
8
+ if (newTr) {
9
+ dispatch === null || dispatch === void 0 ? void 0 : dispatch(newTr);
10
+ return true;
11
+ }
12
+ return false;
13
+ };
14
+ }