@atlaskit/editor-common 74.36.1 → 74.36.2

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 (36) hide show
  1. package/CHANGELOG.md +6 -0
  2. package/dist/cjs/guideline/dynamicGuideline.js +9 -12
  3. package/dist/cjs/guideline/utils.js +44 -2
  4. package/dist/cjs/media-single/constants.js +4 -2
  5. package/dist/cjs/media-single/index.js +6 -0
  6. package/dist/cjs/media-single/utils.js +14 -1
  7. package/dist/cjs/monitoring/error.js +1 -1
  8. package/dist/cjs/ui/DropList/index.js +1 -1
  9. package/dist/cjs/version.json +1 -1
  10. package/dist/es2019/guideline/dynamicGuideline.js +10 -14
  11. package/dist/es2019/guideline/utils.js +44 -5
  12. package/dist/es2019/media-single/constants.js +2 -1
  13. package/dist/es2019/media-single/index.js +1 -1
  14. package/dist/es2019/media-single/utils.js +10 -2
  15. package/dist/es2019/monitoring/error.js +1 -1
  16. package/dist/es2019/ui/DropList/index.js +1 -1
  17. package/dist/es2019/version.json +1 -1
  18. package/dist/esm/guideline/dynamicGuideline.js +10 -13
  19. package/dist/esm/guideline/utils.js +42 -1
  20. package/dist/esm/media-single/constants.js +2 -1
  21. package/dist/esm/media-single/index.js +1 -1
  22. package/dist/esm/media-single/utils.js +13 -2
  23. package/dist/esm/monitoring/error.js +1 -1
  24. package/dist/esm/ui/DropList/index.js +1 -1
  25. package/dist/esm/version.json +1 -1
  26. package/dist/types/guideline/dynamicGuideline.d.ts +16 -5
  27. package/dist/types/guideline/utils.d.ts +14 -0
  28. package/dist/types/media-single/constants.d.ts +1 -0
  29. package/dist/types/media-single/index.d.ts +1 -1
  30. package/dist/types/media-single/utils.d.ts +7 -0
  31. package/dist/types-ts4.5/guideline/dynamicGuideline.d.ts +16 -5
  32. package/dist/types-ts4.5/guideline/utils.d.ts +14 -0
  33. package/dist/types-ts4.5/media-single/constants.d.ts +1 -0
  34. package/dist/types-ts4.5/media-single/index.d.ts +1 -1
  35. package/dist/types-ts4.5/media-single/utils.d.ts +7 -0
  36. package/package.json +1 -1
package/CHANGELOG.md CHANGED
@@ -1,5 +1,11 @@
1
1
  # @atlaskit/editor-common
2
2
 
3
+ ## 74.36.2
4
+
5
+ ### Patch Changes
6
+
7
+ - [`62d6f381722`](https://bitbucket.org/atlassian/atlassian-frontend/commits/62d6f381722) - ED-18969 preliminaary refactor for relative guideline.
8
+
3
9
  ## 74.36.1
4
10
 
5
11
  ### Patch Changes
@@ -13,6 +13,7 @@ var _constants = require("./constants");
13
13
  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; }
14
14
  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
15
  var generateDynamicGuidelines = function generateDynamicGuidelines(state, editorWidth) {
16
+ var styles = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
16
17
  var selectedNode = state.selection instanceof _state.NodeSelection && state.selection.node;
17
18
  var mediaSingleNode = (0, _utils.findChildren)(state.tr.doc, function (node) {
18
19
  return node.type === state.schema.nodes.mediaSingle;
@@ -30,40 +31,36 @@ var generateDynamicGuidelines = function generateDynamicGuidelines(state, editor
30
31
  width = _node$attrs.width,
31
32
  widthType = _node$attrs.widthType;
32
33
  var pixelWidth = (0, _mediaSingle.getMediaSinglePixelWidth)(width, editorWidth, widthType);
33
- var commonStyles = {
34
- style: 'dashed',
35
- show: true
36
- };
37
34
  var key = "".concat(_constants.MEDIA_DYNAMIC_GUIDELINE_PREFIX).concat(index);
38
35
  switch (layout) {
39
36
  case 'align-start':
40
37
  case 'wrap-left':
41
38
  return _objectSpread({
42
39
  position: {
43
- x: pixelWidth - offset
40
+ x: (0, _mediaSingle.roundToNearest)(pixelWidth - offset)
44
41
  },
45
42
  key: key
46
- }, commonStyles);
43
+ }, styles);
47
44
  case 'align-end':
48
45
  case 'wrap-right':
49
46
  return _objectSpread({
50
47
  position: {
51
- x: editorWidth - pixelWidth - offset
48
+ x: (0, _mediaSingle.roundToNearest)(offset - pixelWidth)
52
49
  },
53
50
  key: key
54
- }, commonStyles);
51
+ }, styles);
55
52
  case 'center':
56
53
  return [_objectSpread({
57
54
  position: {
58
- x: pixelWidth / 2
55
+ x: (0, _mediaSingle.roundToNearest)(pixelWidth / 2)
59
56
  },
60
57
  key: "".concat(key, "_right")
61
- }, commonStyles), _objectSpread({
58
+ }, styles), _objectSpread({
62
59
  position: {
63
- x: -pixelWidth / 2
60
+ x: -(0, _mediaSingle.roundToNearest)(pixelWidth / 2)
64
61
  },
65
62
  key: "".concat(key, "_left")
66
- }, commonStyles)];
63
+ }, styles)];
67
64
  // we ignore full-width and wide
68
65
  default:
69
66
  return [];
@@ -3,8 +3,9 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- exports.isVerticalPosition = exports.isNumber = exports.getContainerWidthOrFullEditorWidth = void 0;
6
+ exports.isVerticalPosition = exports.isNumber = exports.getMediaSingleDimensions = exports.getContainerWidthOrFullEditorWidth = void 0;
7
7
  var _editorSharedStyles = require("@atlaskit/editor-shared-styles");
8
+ var _mediaSingle = require("../media-single");
8
9
  var isNumber = function isNumber(x) {
9
10
  return typeof x === 'number' && !isNaN(x) && isFinite(x);
10
11
  };
@@ -21,4 +22,45 @@ exports.isVerticalPosition = isVerticalPosition;
21
22
  var getContainerWidthOrFullEditorWidth = function getContainerWidthOrFullEditorWidth(containerWidth) {
22
23
  return Math.min(containerWidth - _editorSharedStyles.akEditorGutterPadding * 2, _editorSharedStyles.akEditorFullWidthLayoutWidth) / 2;
23
24
  };
24
- exports.getContainerWidthOrFullEditorWidth = getContainerWidthOrFullEditorWidth;
25
+
26
+ /**
27
+ *
28
+ * @param mediaSingle the mediaSingle node
29
+ * @param editorWidth default 760, only use default if the mediaSingle is using pixel width
30
+ * @returns null or dimensions info
31
+ */
32
+ exports.getContainerWidthOrFullEditorWidth = getContainerWidthOrFullEditorWidth;
33
+ var getMediaSingleDimensions = function getMediaSingleDimensions(mediaSingle) {
34
+ var editorWidth = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : _editorSharedStyles.akEditorDefaultLayoutWidth;
35
+ if (mediaSingle.type !== mediaSingle.type.schema.nodes.mediaSingle) {
36
+ return null;
37
+ }
38
+ var mediaNode = mediaSingle.firstChild;
39
+ var _ref = (mediaNode === null || mediaNode === void 0 ? void 0 : mediaNode.attrs) || {},
40
+ width = _ref.width,
41
+ height = _ref.height;
42
+
43
+ // e.g. external image
44
+ if (!width || !height) {
45
+ return null;
46
+ }
47
+ var ratio = parseFloat((height / width).toFixed(2));
48
+ if (!mediaSingle.attrs.width) {
49
+ return {
50
+ width: width,
51
+ height: height,
52
+ originalWidth: width,
53
+ originalHeight: height,
54
+ ratio: ratio
55
+ };
56
+ }
57
+ var pixelWidth = (0, _mediaSingle.getMediaSinglePixelWidth)(mediaSingle.attrs.width, editorWidth, mediaSingle.attrs.widthType);
58
+ return {
59
+ width: (0, _mediaSingle.roundToNearest)(pixelWidth),
60
+ height: (0, _mediaSingle.roundToNearest)(pixelWidth * ratio),
61
+ originalWidth: width,
62
+ originalHeight: height,
63
+ ratio: ratio
64
+ };
65
+ };
66
+ exports.getMediaSingleDimensions = getMediaSingleDimensions;
@@ -3,7 +3,7 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- exports.wrappedLayouts = exports.MEDIA_SINGLE_SNAP_GAP = exports.MEDIA_SINGLE_MIN_PIXEL_WIDTH = exports.MEDIA_SINGLE_HIGHLIGHT_GAP = exports.MEDIA_SINGLE_HANDLE_MARGIN = exports.MEDIA_SINGLE_GUTTER_SIZE = exports.Layout = exports.DEFAULT_IMAGE_WIDTH = exports.DEFAULT_IMAGE_HEIGHT = void 0;
6
+ exports.wrappedLayouts = exports.MEDIA_SINGLE_SNAP_GAP = exports.MEDIA_SINGLE_MIN_PIXEL_WIDTH = exports.MEDIA_SINGLE_HIGHLIGHT_GAP = exports.MEDIA_SINGLE_HANDLE_MARGIN = exports.MEDIA_SINGLE_GUTTER_SIZE = exports.Layout = exports.DEFAULT_ROUNDING_INTERVAL = exports.DEFAULT_IMAGE_WIDTH = exports.DEFAULT_IMAGE_HEIGHT = void 0;
7
7
  var MEDIA_SINGLE_MIN_PIXEL_WIDTH = 24;
8
8
  exports.MEDIA_SINGLE_MIN_PIXEL_WIDTH = MEDIA_SINGLE_MIN_PIXEL_WIDTH;
9
9
  var MEDIA_SINGLE_SNAP_GAP = 3;
@@ -30,4 +30,6 @@ var Layout = /*#__PURE__*/function (Layout) {
30
30
  }({});
31
31
  exports.Layout = Layout;
32
32
  var wrappedLayouts = ['wrap-left', 'wrap-right', 'align-end', 'align-start'];
33
- exports.wrappedLayouts = wrappedLayouts;
33
+ exports.wrappedLayouts = wrappedLayouts;
34
+ var DEFAULT_ROUNDING_INTERVAL = 0.5;
35
+ exports.DEFAULT_ROUNDING_INTERVAL = DEFAULT_ROUNDING_INTERVAL;
@@ -75,6 +75,12 @@ Object.defineProperty(exports, "getMediaSinglePixelWidth", {
75
75
  return _utils.getMediaSinglePixelWidth;
76
76
  }
77
77
  });
78
+ Object.defineProperty(exports, "roundToNearest", {
79
+ enumerable: true,
80
+ get: function get() {
81
+ return _utils.roundToNearest;
82
+ }
83
+ });
78
84
  Object.defineProperty(exports, "wrappedLayouts", {
79
85
  enumerable: true,
80
86
  get: function get() {
@@ -7,6 +7,7 @@ exports.calcMediaSinglePixelWidth = exports.calcMediaSingleMaxWidth = void 0;
7
7
  exports.calculateOffsetLeft = calculateOffsetLeft;
8
8
  exports.getMediaSingleInitialWidth = void 0;
9
9
  exports.getMediaSinglePixelWidth = getMediaSinglePixelWidth;
10
+ exports.roundToNearest = void 0;
10
11
  var _editorSharedStyles = require("@atlaskit/editor-shared-styles");
11
12
  var _constants = require("./constants");
12
13
  /**
@@ -127,4 +128,16 @@ function calculateOffsetLeft(insideInlineLike, insideLayout, pmViewDom, wrapper)
127
128
  offsetLeft = boundingRect.left - pmViewDom.getBoundingClientRect().left;
128
129
  }
129
130
  return offsetLeft;
130
- }
131
+ }
132
+
133
+ /**
134
+ * Returns the number rounded to the nearest interval.
135
+ * @param {number} value The number to round
136
+ * @param {number} interval The numeric interval to round to, default to 0.5
137
+ * @return {number} the rounded number
138
+ */
139
+ var roundToNearest = function roundToNearest(value) {
140
+ var interval = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : _constants.DEFAULT_ROUNDING_INTERVAL;
141
+ return Math.round(value / interval) * interval;
142
+ };
143
+ exports.roundToNearest = roundToNearest;
@@ -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.1";
19
+ var packageVersion = "74.36.2";
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
@@ -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.1";
27
+ var packageVersion = "74.36.2";
28
28
  var halfFocusRing = 1;
29
29
  var dropOffset = '0, 8';
30
30
  var DropList = /*#__PURE__*/function (_Component) {
@@ -1,5 +1,5 @@
1
1
  {
2
2
  "name": "@atlaskit/editor-common",
3
- "version": "74.36.1",
3
+ "version": "74.36.2",
4
4
  "sideEffects": false
5
5
  }
@@ -1,8 +1,8 @@
1
1
  import { NodeSelection } from '@atlaskit/editor-prosemirror/state';
2
2
  import { findChildren } from '@atlaskit/editor-prosemirror/utils';
3
- import { getMediaSinglePixelWidth } from '../media-single';
3
+ import { getMediaSinglePixelWidth, roundToNearest } from '../media-single';
4
4
  import { MEDIA_DYNAMIC_GUIDELINE_PREFIX } from './constants';
5
- export const generateDynamicGuidelines = (state, editorWidth) => {
5
+ export const generateDynamicGuidelines = (state, editorWidth, styles = {}) => {
6
6
  const selectedNode = state.selection instanceof NodeSelection && state.selection.node;
7
7
  const mediaSingleNode = findChildren(state.tr.doc, node => {
8
8
  return node.type === state.schema.nodes.mediaSingle;
@@ -22,43 +22,39 @@ export const generateDynamicGuidelines = (state, editorWidth) => {
22
22
  widthType
23
23
  } = node.attrs;
24
24
  const pixelWidth = getMediaSinglePixelWidth(width, editorWidth, widthType);
25
- const commonStyles = {
26
- style: 'dashed',
27
- show: true
28
- };
29
25
  const key = `${MEDIA_DYNAMIC_GUIDELINE_PREFIX}${index}`;
30
26
  switch (layout) {
31
27
  case 'align-start':
32
28
  case 'wrap-left':
33
29
  return {
34
30
  position: {
35
- x: pixelWidth - offset
31
+ x: roundToNearest(pixelWidth - offset)
36
32
  },
37
33
  key,
38
- ...commonStyles
34
+ ...styles
39
35
  };
40
36
  case 'align-end':
41
37
  case 'wrap-right':
42
38
  return {
43
39
  position: {
44
- x: editorWidth - pixelWidth - offset
40
+ x: roundToNearest(offset - pixelWidth)
45
41
  },
46
42
  key,
47
- ...commonStyles
43
+ ...styles
48
44
  };
49
45
  case 'center':
50
46
  return [{
51
47
  position: {
52
- x: pixelWidth / 2
48
+ x: roundToNearest(pixelWidth / 2)
53
49
  },
54
50
  key: `${key}_right`,
55
- ...commonStyles
51
+ ...styles
56
52
  }, {
57
53
  position: {
58
- x: -pixelWidth / 2
54
+ x: -roundToNearest(pixelWidth / 2)
59
55
  },
60
56
  key: `${key}_left`,
61
- ...commonStyles
57
+ ...styles
62
58
  }];
63
59
  // we ignore full-width and wide
64
60
  default:
@@ -1,11 +1,50 @@
1
- import { akEditorFullWidthLayoutWidth, akEditorGutterPadding } from '@atlaskit/editor-shared-styles';
1
+ import { akEditorDefaultLayoutWidth, akEditorFullWidthLayoutWidth, akEditorGutterPadding } from '@atlaskit/editor-shared-styles';
2
+ import { getMediaSinglePixelWidth, roundToNearest } from '../media-single';
2
3
  export const isNumber = x => typeof x === 'number' && !isNaN(x) && isFinite(x);
3
- export const isVerticalPosition = pos => {
4
- return isNumber(pos.x);
5
- };
4
+ export const isVerticalPosition = pos => isNumber(pos.x);
6
5
 
7
6
  /**
8
7
  * Calculates container or full editor width taking in account editor full width layout
9
8
  * width and editor gutter padding.
10
9
  */
11
- export const getContainerWidthOrFullEditorWidth = containerWidth => Math.min(containerWidth - akEditorGutterPadding * 2, akEditorFullWidthLayoutWidth) / 2;
10
+ export const getContainerWidthOrFullEditorWidth = containerWidth => Math.min(containerWidth - akEditorGutterPadding * 2, akEditorFullWidthLayoutWidth) / 2;
11
+
12
+ /**
13
+ *
14
+ * @param mediaSingle the mediaSingle node
15
+ * @param editorWidth default 760, only use default if the mediaSingle is using pixel width
16
+ * @returns null or dimensions info
17
+ */
18
+ export const getMediaSingleDimensions = (mediaSingle, editorWidth = akEditorDefaultLayoutWidth) => {
19
+ if (mediaSingle.type !== mediaSingle.type.schema.nodes.mediaSingle) {
20
+ return null;
21
+ }
22
+ const mediaNode = mediaSingle.firstChild;
23
+ const {
24
+ width,
25
+ height
26
+ } = (mediaNode === null || mediaNode === void 0 ? void 0 : mediaNode.attrs) || {};
27
+
28
+ // e.g. external image
29
+ if (!width || !height) {
30
+ return null;
31
+ }
32
+ const ratio = parseFloat((height / width).toFixed(2));
33
+ if (!mediaSingle.attrs.width) {
34
+ return {
35
+ width,
36
+ height,
37
+ originalWidth: width,
38
+ originalHeight: height,
39
+ ratio
40
+ };
41
+ }
42
+ const pixelWidth = getMediaSinglePixelWidth(mediaSingle.attrs.width, editorWidth, mediaSingle.attrs.widthType);
43
+ return {
44
+ width: roundToNearest(pixelWidth),
45
+ height: roundToNearest(pixelWidth * ratio),
46
+ originalWidth: width,
47
+ originalHeight: height,
48
+ ratio
49
+ };
50
+ };
@@ -15,4 +15,5 @@ export let Layout = /*#__PURE__*/function (Layout) {
15
15
  Layout["WRAP_LEFT"] = "wrap-left";
16
16
  return Layout;
17
17
  }({});
18
- export const wrappedLayouts = ['wrap-left', 'wrap-right', 'align-end', 'align-start'];
18
+ export const wrappedLayouts = ['wrap-left', 'wrap-right', 'align-end', 'align-start'];
19
+ export const DEFAULT_ROUNDING_INTERVAL = 0.5;
@@ -1,2 +1,2 @@
1
1
  export { MEDIA_SINGLE_MIN_PIXEL_WIDTH, MEDIA_SINGLE_SNAP_GAP, MEDIA_SINGLE_HIGHLIGHT_GAP, MEDIA_SINGLE_GUTTER_SIZE, Layout as MediaSingleLayout, DEFAULT_IMAGE_WIDTH, DEFAULT_IMAGE_HEIGHT, wrappedLayouts } from './constants';
2
- export { getMediaSinglePixelWidth, calcMediaSinglePixelWidth, calcMediaSingleMaxWidth, getMediaSingleInitialWidth, calculateOffsetLeft } from './utils';
2
+ export { getMediaSinglePixelWidth, calcMediaSinglePixelWidth, calcMediaSingleMaxWidth, getMediaSingleInitialWidth, calculateOffsetLeft, roundToNearest } from './utils';
@@ -1,5 +1,5 @@
1
1
  import { akEditorDefaultLayoutWidth, akEditorFullWidthLayoutWidth, akEditorGutterPadding, breakoutWideScaleRatio } from '@atlaskit/editor-shared-styles';
2
- import { DEFAULT_IMAGE_WIDTH, MEDIA_SINGLE_MIN_PIXEL_WIDTH, wrappedLayouts } from './constants';
2
+ import { DEFAULT_IMAGE_WIDTH, DEFAULT_ROUNDING_INTERVAL, MEDIA_SINGLE_MIN_PIXEL_WIDTH, wrappedLayouts } from './constants';
3
3
 
4
4
  /**
5
5
  * Convert media node width to pixel
@@ -110,4 +110,12 @@ export function calculateOffsetLeft(insideInlineLike, insideLayout, pmViewDom, w
110
110
  offsetLeft = boundingRect.left - pmViewDom.getBoundingClientRect().left;
111
111
  }
112
112
  return offsetLeft;
113
- }
113
+ }
114
+
115
+ /**
116
+ * Returns the number rounded to the nearest interval.
117
+ * @param {number} value The number to round
118
+ * @param {number} interval The numeric interval to round to, default to 0.5
119
+ * @return {number} the rounded number
120
+ */
121
+ export const roundToNearest = (value, interval = DEFAULT_ROUNDING_INTERVAL) => Math.round(value / interval) * interval;
@@ -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.1";
3
+ const packageVersion = "74.36.2";
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
@@ -8,7 +8,7 @@ import { themed } from '@atlaskit/theme/components';
8
8
  import { borderRadius } from '@atlaskit/theme/constants';
9
9
  import Layer from '../Layer';
10
10
  const packageName = "@atlaskit/editor-common";
11
- const packageVersion = "74.36.1";
11
+ const packageVersion = "74.36.2";
12
12
  const halfFocusRing = 1;
13
13
  const dropOffset = '0, 8';
14
14
  class DropList extends Component {
@@ -1,5 +1,5 @@
1
1
  {
2
2
  "name": "@atlaskit/editor-common",
3
- "version": "74.36.1",
3
+ "version": "74.36.2",
4
4
  "sideEffects": false
5
5
  }
@@ -3,9 +3,10 @@ function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (O
3
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; }
4
4
  import { NodeSelection } from '@atlaskit/editor-prosemirror/state';
5
5
  import { findChildren } from '@atlaskit/editor-prosemirror/utils';
6
- import { getMediaSinglePixelWidth } from '../media-single';
6
+ import { getMediaSinglePixelWidth, roundToNearest } from '../media-single';
7
7
  import { MEDIA_DYNAMIC_GUIDELINE_PREFIX } from './constants';
8
8
  export var generateDynamicGuidelines = function generateDynamicGuidelines(state, editorWidth) {
9
+ var styles = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
9
10
  var selectedNode = state.selection instanceof NodeSelection && state.selection.node;
10
11
  var mediaSingleNode = findChildren(state.tr.doc, function (node) {
11
12
  return node.type === state.schema.nodes.mediaSingle;
@@ -23,40 +24,36 @@ export var generateDynamicGuidelines = function generateDynamicGuidelines(state,
23
24
  width = _node$attrs.width,
24
25
  widthType = _node$attrs.widthType;
25
26
  var pixelWidth = getMediaSinglePixelWidth(width, editorWidth, widthType);
26
- var commonStyles = {
27
- style: 'dashed',
28
- show: true
29
- };
30
27
  var key = "".concat(MEDIA_DYNAMIC_GUIDELINE_PREFIX).concat(index);
31
28
  switch (layout) {
32
29
  case 'align-start':
33
30
  case 'wrap-left':
34
31
  return _objectSpread({
35
32
  position: {
36
- x: pixelWidth - offset
33
+ x: roundToNearest(pixelWidth - offset)
37
34
  },
38
35
  key: key
39
- }, commonStyles);
36
+ }, styles);
40
37
  case 'align-end':
41
38
  case 'wrap-right':
42
39
  return _objectSpread({
43
40
  position: {
44
- x: editorWidth - pixelWidth - offset
41
+ x: roundToNearest(offset - pixelWidth)
45
42
  },
46
43
  key: key
47
- }, commonStyles);
44
+ }, styles);
48
45
  case 'center':
49
46
  return [_objectSpread({
50
47
  position: {
51
- x: pixelWidth / 2
48
+ x: roundToNearest(pixelWidth / 2)
52
49
  },
53
50
  key: "".concat(key, "_right")
54
- }, commonStyles), _objectSpread({
51
+ }, styles), _objectSpread({
55
52
  position: {
56
- x: -pixelWidth / 2
53
+ x: -roundToNearest(pixelWidth / 2)
57
54
  },
58
55
  key: "".concat(key, "_left")
59
- }, commonStyles)];
56
+ }, styles)];
60
57
  // we ignore full-width and wide
61
58
  default:
62
59
  return [];
@@ -1,4 +1,5 @@
1
- import { akEditorFullWidthLayoutWidth, akEditorGutterPadding } from '@atlaskit/editor-shared-styles';
1
+ import { akEditorDefaultLayoutWidth, akEditorFullWidthLayoutWidth, akEditorGutterPadding } from '@atlaskit/editor-shared-styles';
2
+ import { getMediaSinglePixelWidth, roundToNearest } from '../media-single';
2
3
  export var isNumber = function isNumber(x) {
3
4
  return typeof x === 'number' && !isNaN(x) && isFinite(x);
4
5
  };
@@ -12,4 +13,44 @@ export var isVerticalPosition = function isVerticalPosition(pos) {
12
13
  */
13
14
  export var getContainerWidthOrFullEditorWidth = function getContainerWidthOrFullEditorWidth(containerWidth) {
14
15
  return Math.min(containerWidth - akEditorGutterPadding * 2, akEditorFullWidthLayoutWidth) / 2;
16
+ };
17
+
18
+ /**
19
+ *
20
+ * @param mediaSingle the mediaSingle node
21
+ * @param editorWidth default 760, only use default if the mediaSingle is using pixel width
22
+ * @returns null or dimensions info
23
+ */
24
+ export var getMediaSingleDimensions = function getMediaSingleDimensions(mediaSingle) {
25
+ var editorWidth = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : akEditorDefaultLayoutWidth;
26
+ if (mediaSingle.type !== mediaSingle.type.schema.nodes.mediaSingle) {
27
+ return null;
28
+ }
29
+ var mediaNode = mediaSingle.firstChild;
30
+ var _ref = (mediaNode === null || mediaNode === void 0 ? void 0 : mediaNode.attrs) || {},
31
+ width = _ref.width,
32
+ height = _ref.height;
33
+
34
+ // e.g. external image
35
+ if (!width || !height) {
36
+ return null;
37
+ }
38
+ var ratio = parseFloat((height / width).toFixed(2));
39
+ if (!mediaSingle.attrs.width) {
40
+ return {
41
+ width: width,
42
+ height: height,
43
+ originalWidth: width,
44
+ originalHeight: height,
45
+ ratio: ratio
46
+ };
47
+ }
48
+ var pixelWidth = getMediaSinglePixelWidth(mediaSingle.attrs.width, editorWidth, mediaSingle.attrs.widthType);
49
+ return {
50
+ width: roundToNearest(pixelWidth),
51
+ height: roundToNearest(pixelWidth * ratio),
52
+ originalWidth: width,
53
+ originalHeight: height,
54
+ ratio: ratio
55
+ };
15
56
  };
@@ -15,4 +15,5 @@ export var Layout = /*#__PURE__*/function (Layout) {
15
15
  Layout["WRAP_LEFT"] = "wrap-left";
16
16
  return Layout;
17
17
  }({});
18
- export var wrappedLayouts = ['wrap-left', 'wrap-right', 'align-end', 'align-start'];
18
+ export var wrappedLayouts = ['wrap-left', 'wrap-right', 'align-end', 'align-start'];
19
+ export var DEFAULT_ROUNDING_INTERVAL = 0.5;
@@ -1,2 +1,2 @@
1
1
  export { MEDIA_SINGLE_MIN_PIXEL_WIDTH, MEDIA_SINGLE_SNAP_GAP, MEDIA_SINGLE_HIGHLIGHT_GAP, MEDIA_SINGLE_GUTTER_SIZE, Layout as MediaSingleLayout, DEFAULT_IMAGE_WIDTH, DEFAULT_IMAGE_HEIGHT, wrappedLayouts } from './constants';
2
- export { getMediaSinglePixelWidth, calcMediaSinglePixelWidth, calcMediaSingleMaxWidth, getMediaSingleInitialWidth, calculateOffsetLeft } from './utils';
2
+ export { getMediaSinglePixelWidth, calcMediaSinglePixelWidth, calcMediaSingleMaxWidth, getMediaSingleInitialWidth, calculateOffsetLeft, roundToNearest } from './utils';
@@ -1,5 +1,5 @@
1
1
  import { akEditorDefaultLayoutWidth, akEditorFullWidthLayoutWidth, akEditorGutterPadding, breakoutWideScaleRatio } from '@atlaskit/editor-shared-styles';
2
- import { DEFAULT_IMAGE_WIDTH, MEDIA_SINGLE_MIN_PIXEL_WIDTH, wrappedLayouts } from './constants';
2
+ import { DEFAULT_IMAGE_WIDTH, DEFAULT_ROUNDING_INTERVAL, MEDIA_SINGLE_MIN_PIXEL_WIDTH, wrappedLayouts } from './constants';
3
3
 
4
4
  /**
5
5
  * Convert media node width to pixel
@@ -116,4 +116,15 @@ export function calculateOffsetLeft(insideInlineLike, insideLayout, pmViewDom, w
116
116
  offsetLeft = boundingRect.left - pmViewDom.getBoundingClientRect().left;
117
117
  }
118
118
  return offsetLeft;
119
- }
119
+ }
120
+
121
+ /**
122
+ * Returns the number rounded to the nearest interval.
123
+ * @param {number} value The number to round
124
+ * @param {number} interval The numeric interval to round to, default to 0.5
125
+ * @return {number} the rounded number
126
+ */
127
+ export var roundToNearest = function roundToNearest(value) {
128
+ var interval = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : DEFAULT_ROUNDING_INTERVAL;
129
+ return Math.round(value / interval) * interval;
130
+ };
@@ -6,7 +6,7 @@ function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (O
6
6
  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; }
7
7
  var SENTRY_DSN = 'https://0b10c8e02fb44d8796c047b102c9bee8@o55978.ingest.sentry.io/4505129224110080';
8
8
  var packageName = 'editor-common'; // Sentry doesn't accept '/' in its releases https://docs.sentry.io/platforms/javascript/configuration/releases/
9
- var packageVersion = "74.36.1";
9
+ var packageVersion = "74.36.2";
10
10
  var sanitiseSentryEvents = function sanitiseSentryEvents(data, _hint) {
11
11
  // Remove URL as it has UGC
12
12
  // TODO: Sanitise the URL instead of just removing it
@@ -18,7 +18,7 @@ import { themed } from '@atlaskit/theme/components';
18
18
  import { borderRadius } from '@atlaskit/theme/constants';
19
19
  import Layer from '../Layer';
20
20
  var packageName = "@atlaskit/editor-common";
21
- var packageVersion = "74.36.1";
21
+ var packageVersion = "74.36.2";
22
22
  var halfFocusRing = 1;
23
23
  var dropOffset = '0, 8';
24
24
  var DropList = /*#__PURE__*/function (_Component) {
@@ -1,5 +1,5 @@
1
1
  {
2
2
  "name": "@atlaskit/editor-common",
3
- "version": "74.36.1",
3
+ "version": "74.36.2",
4
4
  "sideEffects": false
5
5
  }
@@ -1,14 +1,25 @@
1
1
  import { EditorState } from '@atlaskit/editor-prosemirror/state';
2
- export declare const generateDynamicGuidelines: (state: EditorState, editorWidth: number) => ({
3
- style: string;
4
- show: boolean;
2
+ import type { GuidelineConfig } from './types';
3
+ export declare const generateDynamicGuidelines: (state: EditorState, editorWidth: number, styles?: Omit<GuidelineConfig, 'key' | 'position'>) => ({
4
+ styles?: {
5
+ capStyle?: "line" | undefined;
6
+ lineStyle?: "dashed" | "solid" | undefined;
7
+ color?: import("@atlaskit/tokens").CSSToken | undefined;
8
+ } | undefined;
9
+ show?: boolean | undefined;
10
+ active?: boolean | undefined;
5
11
  position: {
6
12
  x: number;
7
13
  };
8
14
  key: string;
9
15
  } | {
10
- style: string;
11
- show: boolean;
16
+ styles?: {
17
+ capStyle?: "line" | undefined;
18
+ lineStyle?: "dashed" | "solid" | undefined;
19
+ color?: import("@atlaskit/tokens").CSSToken | undefined;
20
+ } | undefined;
21
+ show?: boolean | undefined;
22
+ active?: boolean | undefined;
12
23
  position: {
13
24
  x: number;
14
25
  };
@@ -1,3 +1,4 @@
1
+ import type { Node as PMNode } from '@atlaskit/editor-prosemirror/model';
1
2
  import { Position, VerticalPosition } from './types';
2
3
  export declare const isNumber: (x: unknown) => x is number;
3
4
  export declare const isVerticalPosition: (pos: Position) => pos is VerticalPosition;
@@ -6,3 +7,16 @@ export declare const isVerticalPosition: (pos: Position) => pos is VerticalPosit
6
7
  * width and editor gutter padding.
7
8
  */
8
9
  export declare const getContainerWidthOrFullEditorWidth: (containerWidth: number) => number;
10
+ /**
11
+ *
12
+ * @param mediaSingle the mediaSingle node
13
+ * @param editorWidth default 760, only use default if the mediaSingle is using pixel width
14
+ * @returns null or dimensions info
15
+ */
16
+ export declare const getMediaSingleDimensions: (mediaSingle: PMNode, editorWidth?: number) => {
17
+ width: number;
18
+ height: number;
19
+ originalWidth: number;
20
+ originalHeight: number;
21
+ ratio: number;
22
+ } | null;
@@ -16,3 +16,4 @@ export declare enum Layout {
16
16
  WRAP_LEFT = "wrap-left"
17
17
  }
18
18
  export declare const wrappedLayouts: RichMediaLayout[];
19
+ export declare const DEFAULT_ROUNDING_INTERVAL = 0.5;
@@ -1,2 +1,2 @@
1
1
  export { MEDIA_SINGLE_MIN_PIXEL_WIDTH, MEDIA_SINGLE_SNAP_GAP, MEDIA_SINGLE_HIGHLIGHT_GAP, MEDIA_SINGLE_GUTTER_SIZE, Layout as MediaSingleLayout, DEFAULT_IMAGE_WIDTH, DEFAULT_IMAGE_HEIGHT, wrappedLayouts, } from './constants';
2
- export { getMediaSinglePixelWidth, calcMediaSinglePixelWidth, calcMediaSingleMaxWidth, getMediaSingleInitialWidth, calculateOffsetLeft, } from './utils';
2
+ export { getMediaSinglePixelWidth, calcMediaSinglePixelWidth, calcMediaSingleMaxWidth, getMediaSingleInitialWidth, calculateOffsetLeft, roundToNearest, } from './utils';
@@ -47,3 +47,10 @@ export declare const calcMediaSingleMaxWidth: (containerWidth: number) => number
47
47
  */
48
48
  export declare const getMediaSingleInitialWidth: (origWidth?: number, maxWidth?: number, minWidth?: number) => number;
49
49
  export declare function calculateOffsetLeft(insideInlineLike: boolean, insideLayout: boolean, pmViewDom: Element, wrapper?: HTMLElement): number;
50
+ /**
51
+ * Returns the number rounded to the nearest interval.
52
+ * @param {number} value The number to round
53
+ * @param {number} interval The numeric interval to round to, default to 0.5
54
+ * @return {number} the rounded number
55
+ */
56
+ export declare const roundToNearest: (value: number, interval?: number) => number;
@@ -1,14 +1,25 @@
1
1
  import { EditorState } from '@atlaskit/editor-prosemirror/state';
2
- export declare const generateDynamicGuidelines: (state: EditorState, editorWidth: number) => ({
3
- style: string;
4
- show: boolean;
2
+ import type { GuidelineConfig } from './types';
3
+ export declare const generateDynamicGuidelines: (state: EditorState, editorWidth: number, styles?: Omit<GuidelineConfig, 'key' | 'position'>) => ({
4
+ styles?: {
5
+ capStyle?: "line" | undefined;
6
+ lineStyle?: "dashed" | "solid" | undefined;
7
+ color?: import("@atlaskit/tokens").CSSToken | undefined;
8
+ } | undefined;
9
+ show?: boolean | undefined;
10
+ active?: boolean | undefined;
5
11
  position: {
6
12
  x: number;
7
13
  };
8
14
  key: string;
9
15
  } | {
10
- style: string;
11
- show: boolean;
16
+ styles?: {
17
+ capStyle?: "line" | undefined;
18
+ lineStyle?: "dashed" | "solid" | undefined;
19
+ color?: import("@atlaskit/tokens").CSSToken | undefined;
20
+ } | undefined;
21
+ show?: boolean | undefined;
22
+ active?: boolean | undefined;
12
23
  position: {
13
24
  x: number;
14
25
  };
@@ -1,3 +1,4 @@
1
+ import type { Node as PMNode } from '@atlaskit/editor-prosemirror/model';
1
2
  import { Position, VerticalPosition } from './types';
2
3
  export declare const isNumber: (x: unknown) => x is number;
3
4
  export declare const isVerticalPosition: (pos: Position) => pos is VerticalPosition;
@@ -6,3 +7,16 @@ export declare const isVerticalPosition: (pos: Position) => pos is VerticalPosit
6
7
  * width and editor gutter padding.
7
8
  */
8
9
  export declare const getContainerWidthOrFullEditorWidth: (containerWidth: number) => number;
10
+ /**
11
+ *
12
+ * @param mediaSingle the mediaSingle node
13
+ * @param editorWidth default 760, only use default if the mediaSingle is using pixel width
14
+ * @returns null or dimensions info
15
+ */
16
+ export declare const getMediaSingleDimensions: (mediaSingle: PMNode, editorWidth?: number) => {
17
+ width: number;
18
+ height: number;
19
+ originalWidth: number;
20
+ originalHeight: number;
21
+ ratio: number;
22
+ } | null;
@@ -16,3 +16,4 @@ export declare enum Layout {
16
16
  WRAP_LEFT = "wrap-left"
17
17
  }
18
18
  export declare const wrappedLayouts: RichMediaLayout[];
19
+ export declare const DEFAULT_ROUNDING_INTERVAL = 0.5;
@@ -1,2 +1,2 @@
1
1
  export { MEDIA_SINGLE_MIN_PIXEL_WIDTH, MEDIA_SINGLE_SNAP_GAP, MEDIA_SINGLE_HIGHLIGHT_GAP, MEDIA_SINGLE_GUTTER_SIZE, Layout as MediaSingleLayout, DEFAULT_IMAGE_WIDTH, DEFAULT_IMAGE_HEIGHT, wrappedLayouts, } from './constants';
2
- export { getMediaSinglePixelWidth, calcMediaSinglePixelWidth, calcMediaSingleMaxWidth, getMediaSingleInitialWidth, calculateOffsetLeft, } from './utils';
2
+ export { getMediaSinglePixelWidth, calcMediaSinglePixelWidth, calcMediaSingleMaxWidth, getMediaSingleInitialWidth, calculateOffsetLeft, roundToNearest, } from './utils';
@@ -47,3 +47,10 @@ export declare const calcMediaSingleMaxWidth: (containerWidth: number) => number
47
47
  */
48
48
  export declare const getMediaSingleInitialWidth: (origWidth?: number, maxWidth?: number, minWidth?: number) => number;
49
49
  export declare function calculateOffsetLeft(insideInlineLike: boolean, insideLayout: boolean, pmViewDom: Element, wrapper?: HTMLElement): number;
50
+ /**
51
+ * Returns the number rounded to the nearest interval.
52
+ * @param {number} value The number to round
53
+ * @param {number} interval The numeric interval to round to, default to 0.5
54
+ * @return {number} the rounded number
55
+ */
56
+ export declare const roundToNearest: (value: number, interval?: number) => number;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atlaskit/editor-common",
3
- "version": "74.36.1",
3
+ "version": "74.36.2",
4
4
  "description": "A package that contains common classes and components for editor and renderer",
5
5
  "publishConfig": {
6
6
  "registry": "https://registry.npmjs.org/"