@atlaskit/editor-plugin-guideline 0.3.4 → 0.3.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,17 @@
1
1
  # @atlaskit/editor-plugin-guideline
2
2
 
3
+ ## 0.3.6
4
+
5
+ ### Patch Changes
6
+
7
+ - [`3d065399b07`](https://bitbucket.org/atlassian/atlassian-frontend/commits/3d065399b07) - ED-18969 refactor guideline plugin interface.
8
+
9
+ ## 0.3.5
10
+
11
+ ### Patch Changes
12
+
13
+ - [`e8885f55db6`](https://bitbucket.org/atlassian/atlassian-frontend/commits/e8885f55db6) - ED-18969 implement relative guides support
14
+
3
15
  ## 0.3.4
4
16
 
5
17
  ### Patch Changes
package/README.md CHANGED
@@ -85,15 +85,19 @@ type GuidelineConfig = {
85
85
  ...
86
86
  active?: boolean;
87
87
  show?: boolean;
88
- style?: 'dashed' | 'solid'; // default solid
89
- color?: CSSToken;
88
+ styles: {
89
+ lineStyle?: 'dashed' | 'solid'; // default solid
90
+ color?: CSSToken;
91
+ capStyle?: 'line'
92
+ }
90
93
  };
91
94
  ```
92
95
 
93
96
  - `active` default `false`, equivalent to the `highlight` state in the `grid` plugin.
94
- - `style` default `solid`, and we also support `dashed`
95
97
  - `show` default `true` and you can also hide a guideline, could be useful when you need animations.
96
- - `color`: default `undefined` you can override the color of a guideline with a valid `css` color
98
+ - `styles.color`: default `undefined` you can override the color of a guideline with a valid `css` color
99
+ - `styles.lineStyle` default `solid`, and we also support `dashed`
100
+ - `styles.capStyle` default undefined, and support `line`
97
101
 
98
102
  ## TODO
99
103
  - [ ] Add unit/vr tests
@@ -0,0 +1,10 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.VAR_POSITION_OFFSET_Y = exports.VAR_POSITION_OFFSET_X = void 0;
7
+ var VAR_POSITION_OFFSET_X = '--guideline-offset-x';
8
+ exports.VAR_POSITION_OFFSET_X = VAR_POSITION_OFFSET_X;
9
+ var VAR_POSITION_OFFSET_Y = '--guideline-offset-y';
10
+ exports.VAR_POSITION_OFFSET_Y = VAR_POSITION_OFFSET_Y;
@@ -7,43 +7,86 @@ Object.defineProperty(exports, "__esModule", {
7
7
  exports.Guideline = void 0;
8
8
  var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
9
9
  var _react = require("@emotion/react");
10
+ var _guideline = require("@atlaskit/editor-common/guideline");
10
11
  var _colors = require("@atlaskit/theme/colors");
12
+ var _positionStyles = require("./positionStyles");
11
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; }
12
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; } /** @jsx jsx */
13
- var BasicGuidelineStyles = (0, _react.css)({
14
- borderLeft: "1px solid ".concat("var(--ds-border, ".concat(_colors.N30A, ")")),
15
+ var basicGuidelineStyles = (0, _react.css)({
15
16
  position: 'absolute',
16
- width: '1px',
17
- height: '100%',
18
17
  zIndex: 0,
19
- transform: 'translateX(-50%)',
20
18
  opacity: 1,
21
- transition: 'border-color 0.15s linear, opacity 0.15s linear'
19
+ transition: 'border-color 0.15s linear, opacity 0.15s linear',
20
+ borderColor: "".concat("var(--ds-border, ".concat(_colors.N30A, ")")),
21
+ borderStyle: 'solid'
22
+ });
23
+ var verticalStyles = (0, _react.css)({
24
+ borderWidth: "0 0 0 1px",
25
+ width: '1px',
26
+ height: '100%',
27
+ transform: 'translateX(-50%)'
28
+ });
29
+ var horizontalStyles = (0, _react.css)({
30
+ borderWidth: "1px 0 0 0",
31
+ width: '100%',
32
+ height: '1px',
33
+ transform: 'translateY(-50%)'
22
34
  });
23
- var ActiveGuidelineStyles = (0, _react.css)({
24
- borderColor: "var(--ds-border-focused, ".concat(_colors.B200, ")")
35
+ var activeGuidelineStyles = (0, _react.css)({
36
+ borderColor: "var(--ds-border-focused, ".concat(_colors.B200, ")"),
37
+ '&:before, &:after': {
38
+ backgroundColor: "var(--ds-border-focused, ".concat(_colors.B200, ")")
39
+ }
25
40
  });
26
- var HiddenGuidelineStyles = (0, _react.css)({
41
+ var hiddenGuidelineStyles = (0, _react.css)({
27
42
  opacity: 0
28
43
  });
29
- var DashedGuidelineStyles = (0, _react.css)({
44
+ var dashedGuidelineStyles = (0, _react.css)({
30
45
  borderLeftStyle: 'dashed'
31
46
  });
47
+ var verticalCapStyles = (0, _react.css)({
48
+ '&:before, &:after': {
49
+ backgroundColor: "var(--ds-border, ".concat(_colors.N30A, ")"),
50
+ content: '""',
51
+ position: 'absolute',
52
+ height: '10px',
53
+ width: '1px',
54
+ transform: 'translateY(-50%)'
55
+ },
56
+ '&:after': {
57
+ right: 0
58
+ }
59
+ });
60
+ var horizontalCapStyles = (0, _react.css)({
61
+ '&:before, &:after': {
62
+ backgroundColor: "".concat("var(--ds-border, ".concat(_colors.N30A, ")")),
63
+ content: '""',
64
+ position: 'absolute',
65
+ height: '1px',
66
+ width: '10px',
67
+ transform: 'translateX(-50%)'
68
+ },
69
+ '&:after': {
70
+ bottom: 0
71
+ }
72
+ });
32
73
  var Guideline = function Guideline(props) {
33
74
  var position = props.position,
34
75
  active = props.active,
35
76
  _props$show = props.show,
36
77
  show = _props$show === void 0 ? true : _props$show,
37
- style = props.style,
38
- color = props.color;
78
+ _props$styles = props.styles,
79
+ styles = _props$styles === void 0 ? {} : _props$styles;
80
+ var isVerticalPos = (0, _guideline.isVerticalPosition)(position);
81
+ var lineStyle = styles.lineStyle,
82
+ color = styles.color,
83
+ capStyle = styles.capStyle;
39
84
  return (0, _react.jsx)("div", {
40
- css: [BasicGuidelineStyles, active && ActiveGuidelineStyles, !show && HiddenGuidelineStyles, style === 'dashed' && DashedGuidelineStyles],
41
- className: "guideline",
42
- style: _objectSpread({
43
- left: "".concat(position, "px")
44
- }, color && {
85
+ css: [basicGuidelineStyles, isVerticalPos ? verticalStyles : horizontalStyles, capStyle === 'line' && (isVerticalPos ? horizontalCapStyles : verticalCapStyles), active && activeGuidelineStyles, !show && hiddenGuidelineStyles, lineStyle === 'dashed' && dashedGuidelineStyles],
86
+ style: _objectSpread(_objectSpread({}, color && {
45
87
  borderColor: "".concat(color)
46
- })
88
+ }), (0, _positionStyles.getPositionStyles)(position)),
89
+ className: "guideline"
47
90
  });
48
91
  };
49
92
  exports.Guideline = Guideline;
@@ -5,13 +5,17 @@ Object.defineProperty(exports, "__esModule", {
5
5
  value: true
6
6
  });
7
7
  exports.GuidelineContainer = void 0;
8
+ var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
9
+ var _objectWithoutProperties2 = _interopRequireDefault(require("@babel/runtime/helpers/objectWithoutProperties"));
10
+ var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
8
11
  var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
9
12
  var _react = require("react");
10
13
  var _react2 = require("@emotion/react");
11
14
  var _editorSharedStyles = require("@atlaskit/editor-shared-styles");
15
+ var _constants = require("./constants");
12
16
  var _guideline = require("./guideline");
17
+ var _excluded = ["key"];
13
18
  /** @jsx jsx */
14
-
15
19
  var guidelineContainerStyles = (0, _react2.css)({
16
20
  position: 'fixed',
17
21
  height: '100vh',
@@ -22,6 +26,7 @@ var guidelineContainerStyles = (0, _react2.css)({
22
26
  maxWidth: "".concat(_editorSharedStyles.akEditorFullWidthLayoutWidth, "px")
23
27
  });
24
28
  var GuidelineContainer = function GuidelineContainer(props) {
29
+ var _style;
25
30
  var guidelines = props.guidelines,
26
31
  height = props.height,
27
32
  editorWidth = props.editorWidth,
@@ -39,21 +44,18 @@ var GuidelineContainer = function GuidelineContainer(props) {
39
44
  setOffset(centerOffset - rect.x);
40
45
  }
41
46
  }, [centerOffset, guidelines, editorWidth]);
47
+ var style = (_style = {}, (0, _defineProperty2.default)(_style, _constants.VAR_POSITION_OFFSET_X, "".concat(offset, "px")), (0, _defineProperty2.default)(_style, _constants.VAR_POSITION_OFFSET_Y, "0px"), (0, _defineProperty2.default)(_style, "height", height), _style);
42
48
  return (0, _react2.jsx)("div", {
43
49
  ref: ref,
44
50
  css: guidelineContainerStyles,
45
- style: {
46
- height: height
47
- },
51
+ style: style,
48
52
  "data-testid": "guidelineContainer"
49
53
  }, guidelines.map(function (guideline) {
50
- return (0, _react2.jsx)(_guideline.Guideline, {
51
- key: guideline.key,
52
- position: guideline.position.x + offset,
53
- active: guideline.active,
54
- show: guideline.show,
55
- style: guideline.style
56
- });
54
+ var key = guideline.key,
55
+ guidelineProps = (0, _objectWithoutProperties2.default)(guideline, _excluded);
56
+ return (0, _react2.jsx)(_guideline.Guideline, (0, _extends2.default)({
57
+ key: key
58
+ }, guidelineProps));
57
59
  }));
58
60
  };
59
61
  exports.GuidelineContainer = GuidelineContainer;
@@ -9,7 +9,7 @@ var _prosemirrorState = require("prosemirror-state");
9
9
  var _hooks = require("@atlaskit/editor-common/hooks");
10
10
  var _safePlugin = require("@atlaskit/editor-common/safe-plugin");
11
11
  var _editorSharedStyles = require("@atlaskit/editor-shared-styles");
12
- var _guildelineContainer = require("./guildelineContainer");
12
+ var _guidelineContainer = require("./guidelineContainer");
13
13
  var _utils = require("./utils");
14
14
  /** @jsx jsx */
15
15
 
@@ -64,7 +64,7 @@ var ContentComponent = function ContentComponent(_ref) {
64
64
  }
65
65
  return (0, _react.jsx)("div", {
66
66
  css: guidelineStyles
67
- }, (0, _react.jsx)(_guildelineContainer.GuidelineContainer, {
67
+ }, (0, _react.jsx)(_guidelineContainer.GuidelineContainer, {
68
68
  guidelines: guidelineState.guidelines,
69
69
  height: editorView.dom.scrollHeight,
70
70
  centerOffset: (0, _utils.getEditorCenterX)(editorView),
@@ -0,0 +1,33 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.isNumber = exports.getPositionStyles = void 0;
7
+ var _guideline = require("@atlaskit/editor-common/guideline");
8
+ var _constants = require("./constants");
9
+ /* eslint-disable @atlaskit/design-system/ensure-design-token-usage/preview */
10
+
11
+ var isNumber = function isNumber(x) {
12
+ return typeof x === 'number' && !isNaN(x) && isFinite(x);
13
+ };
14
+ exports.isNumber = isNumber;
15
+ var getXPosition = function getXPosition(pixel) {
16
+ return isNumber(pixel) ? "calc(".concat(pixel, "px + var(").concat(_constants.VAR_POSITION_OFFSET_X, ", '0px'))") : 'unset';
17
+ };
18
+ var getYPosition = function getYPosition(pixel) {
19
+ return isNumber(pixel) ? "calc(".concat(pixel, "px + var(").concat(_constants.VAR_POSITION_OFFSET_Y, ", '0px'))") : 'unset';
20
+ };
21
+ var getPositionStyles = function getPositionStyles(pos) {
22
+ var _pos$y, _pos$x;
23
+ return (0, _guideline.isVerticalPosition)(pos) ? {
24
+ left: getXPosition(pos.x),
25
+ top: getYPosition((_pos$y = pos.y) === null || _pos$y === void 0 ? void 0 : _pos$y.start),
26
+ height: pos.y ? "".concat(pos.y.end - pos.y.start, "px") : '100%'
27
+ } : {
28
+ top: getYPosition(pos.y),
29
+ left: getXPosition((_pos$x = pos.x) === null || _pos$x === void 0 ? void 0 : _pos$x.start),
30
+ width: pos.x ? "".concat(pos.x.end - pos.x.start, "px") : '100%'
31
+ };
32
+ };
33
+ exports.getPositionStyles = getPositionStyles;
@@ -1,5 +1,5 @@
1
1
  {
2
2
  "name": "@atlaskit/editor-plugin-guideline",
3
- "version": "0.3.4",
3
+ "version": "0.3.6",
4
4
  "sideEffects": false
5
5
  }
@@ -0,0 +1,2 @@
1
+ export const VAR_POSITION_OFFSET_X = '--guideline-offset-x';
2
+ export const VAR_POSITION_OFFSET_Y = '--guideline-offset-y';
@@ -1,41 +1,87 @@
1
1
  /** @jsx jsx */
2
2
  import { css, jsx } from '@emotion/react';
3
+ import { isVerticalPosition } from '@atlaskit/editor-common/guideline';
3
4
  import { B200, N30A } from '@atlaskit/theme/colors';
4
- const BasicGuidelineStyles = css({
5
- borderLeft: `1px solid ${`var(--ds-border, ${N30A})`}`,
5
+ import { getPositionStyles } from './positionStyles';
6
+ const basicGuidelineStyles = css({
6
7
  position: 'absolute',
7
- width: '1px',
8
- height: '100%',
9
8
  zIndex: 0,
10
- transform: 'translateX(-50%)',
11
9
  opacity: 1,
12
- transition: 'border-color 0.15s linear, opacity 0.15s linear'
10
+ transition: 'border-color 0.15s linear, opacity 0.15s linear',
11
+ borderColor: `${`var(--ds-border, ${N30A})`}`,
12
+ borderStyle: 'solid'
13
+ });
14
+ const verticalStyles = css({
15
+ borderWidth: `0 0 0 1px`,
16
+ width: '1px',
17
+ height: '100%',
18
+ transform: 'translateX(-50%)'
13
19
  });
14
- const ActiveGuidelineStyles = css({
15
- borderColor: `var(--ds-border-focused, ${B200})`
20
+ const horizontalStyles = css({
21
+ borderWidth: `1px 0 0 0`,
22
+ width: '100%',
23
+ height: '1px',
24
+ transform: 'translateY(-50%)'
16
25
  });
17
- const HiddenGuidelineStyles = css({
26
+ const activeGuidelineStyles = css({
27
+ borderColor: `var(--ds-border-focused, ${B200})`,
28
+ '&:before, &:after': {
29
+ backgroundColor: `var(--ds-border-focused, ${B200})`
30
+ }
31
+ });
32
+ const hiddenGuidelineStyles = css({
18
33
  opacity: 0
19
34
  });
20
- const DashedGuidelineStyles = css({
35
+ const dashedGuidelineStyles = css({
21
36
  borderLeftStyle: 'dashed'
22
37
  });
38
+ const verticalCapStyles = css({
39
+ '&:before, &:after': {
40
+ backgroundColor: `var(--ds-border, ${N30A})`,
41
+ content: '""',
42
+ position: 'absolute',
43
+ height: '10px',
44
+ width: '1px',
45
+ transform: 'translateY(-50%)'
46
+ },
47
+ '&:after': {
48
+ right: 0
49
+ }
50
+ });
51
+ const horizontalCapStyles = css({
52
+ '&:before, &:after': {
53
+ backgroundColor: `${`var(--ds-border, ${N30A})`}`,
54
+ content: '""',
55
+ position: 'absolute',
56
+ height: '1px',
57
+ width: '10px',
58
+ transform: 'translateX(-50%)'
59
+ },
60
+ '&:after': {
61
+ bottom: 0
62
+ }
63
+ });
23
64
  export const Guideline = props => {
24
65
  const {
25
66
  position,
26
67
  active,
27
68
  show = true,
28
- style,
29
- color
69
+ styles = {}
30
70
  } = props;
71
+ const isVerticalPos = isVerticalPosition(position);
72
+ const {
73
+ lineStyle,
74
+ color,
75
+ capStyle
76
+ } = styles;
31
77
  return jsx("div", {
32
- css: [BasicGuidelineStyles, active && ActiveGuidelineStyles, !show && HiddenGuidelineStyles, style === 'dashed' && DashedGuidelineStyles],
33
- className: "guideline",
78
+ css: [basicGuidelineStyles, isVerticalPos ? verticalStyles : horizontalStyles, capStyle === 'line' && (isVerticalPos ? horizontalCapStyles : verticalCapStyles), active && activeGuidelineStyles, !show && hiddenGuidelineStyles, lineStyle === 'dashed' && dashedGuidelineStyles],
34
79
  style: {
35
- left: `${position}px`,
36
80
  ...(color && {
37
81
  borderColor: `${color}`
38
- })
39
- }
82
+ }),
83
+ ...getPositionStyles(position)
84
+ },
85
+ className: "guideline"
40
86
  });
41
87
  };
@@ -1,7 +1,9 @@
1
+ import _extends from "@babel/runtime/helpers/extends";
1
2
  /** @jsx jsx */
2
3
  import { useLayoutEffect, useRef, useState } from 'react';
3
4
  import { css, jsx } from '@emotion/react';
4
5
  import { akEditorFullWidthLayoutWidth } from '@atlaskit/editor-shared-styles';
6
+ import { VAR_POSITION_OFFSET_X, VAR_POSITION_OFFSET_Y } from './constants';
5
7
  import { Guideline } from './guideline';
6
8
  const guidelineContainerStyles = css({
7
9
  position: 'fixed',
@@ -29,20 +31,23 @@ export const GuidelineContainer = props => {
29
31
  setOffset(centerOffset - rect.x);
30
32
  }
31
33
  }, [centerOffset, guidelines, editorWidth]);
34
+ const style = {
35
+ [VAR_POSITION_OFFSET_X]: `${offset}px`,
36
+ [VAR_POSITION_OFFSET_Y]: `0px`,
37
+ height
38
+ };
32
39
  return jsx("div", {
33
40
  ref: ref,
34
41
  css: guidelineContainerStyles,
35
- style: {
36
- height
37
- },
42
+ style: style,
38
43
  "data-testid": "guidelineContainer"
39
44
  }, guidelines.map(guideline => {
40
- return jsx(Guideline, {
41
- key: guideline.key,
42
- position: guideline.position.x + offset,
43
- active: guideline.active,
44
- show: guideline.show,
45
- style: guideline.style
46
- });
45
+ const {
46
+ key,
47
+ ...guidelineProps
48
+ } = guideline;
49
+ return jsx(Guideline, _extends({
50
+ key: key
51
+ }, guidelineProps));
47
52
  }));
48
53
  };
@@ -4,7 +4,7 @@ import { PluginKey } from 'prosemirror-state';
4
4
  import { useSharedPluginState } from '@atlaskit/editor-common/hooks';
5
5
  import { SafePlugin } from '@atlaskit/editor-common/safe-plugin';
6
6
  import { akEditorGridLineZIndex } from '@atlaskit/editor-shared-styles';
7
- import { GuidelineContainer } from './guildelineContainer';
7
+ import { GuidelineContainer } from './guidelineContainer';
8
8
  import { getEditorCenterX } from './utils';
9
9
  const guidelineStyles = css({
10
10
  position: 'absolute',
@@ -0,0 +1,19 @@
1
+ /* eslint-disable @atlaskit/design-system/ensure-design-token-usage/preview */
2
+
3
+ import { isVerticalPosition } from '@atlaskit/editor-common/guideline';
4
+ import { VAR_POSITION_OFFSET_X, VAR_POSITION_OFFSET_Y } from './constants';
5
+ export const isNumber = x => typeof x === 'number' && !isNaN(x) && isFinite(x);
6
+ const getXPosition = pixel => isNumber(pixel) ? `calc(${pixel}px + var(${VAR_POSITION_OFFSET_X}, '0px'))` : 'unset';
7
+ const getYPosition = pixel => isNumber(pixel) ? `calc(${pixel}px + var(${VAR_POSITION_OFFSET_Y}, '0px'))` : 'unset';
8
+ export const getPositionStyles = pos => {
9
+ var _pos$y, _pos$x;
10
+ return isVerticalPosition(pos) ? {
11
+ left: getXPosition(pos.x),
12
+ top: getYPosition((_pos$y = pos.y) === null || _pos$y === void 0 ? void 0 : _pos$y.start),
13
+ height: pos.y ? `${pos.y.end - pos.y.start}px` : '100%'
14
+ } : {
15
+ top: getYPosition(pos.y),
16
+ left: getXPosition((_pos$x = pos.x) === null || _pos$x === void 0 ? void 0 : _pos$x.start),
17
+ width: pos.x ? `${pos.x.end - pos.x.start}px` : '100%'
18
+ };
19
+ };
@@ -1,5 +1,5 @@
1
1
  {
2
2
  "name": "@atlaskit/editor-plugin-guideline",
3
- "version": "0.3.4",
3
+ "version": "0.3.6",
4
4
  "sideEffects": false
5
5
  }
@@ -0,0 +1,2 @@
1
+ export var VAR_POSITION_OFFSET_X = '--guideline-offset-x';
2
+ export var VAR_POSITION_OFFSET_Y = '--guideline-offset-y';
@@ -3,40 +3,83 @@ 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
  /** @jsx jsx */
5
5
  import { css, jsx } from '@emotion/react';
6
+ import { isVerticalPosition } from '@atlaskit/editor-common/guideline';
6
7
  import { B200, N30A } from '@atlaskit/theme/colors';
7
- var BasicGuidelineStyles = css({
8
- borderLeft: "1px solid ".concat("var(--ds-border, ".concat(N30A, ")")),
8
+ import { getPositionStyles } from './positionStyles';
9
+ var basicGuidelineStyles = css({
9
10
  position: 'absolute',
10
- width: '1px',
11
- height: '100%',
12
11
  zIndex: 0,
13
- transform: 'translateX(-50%)',
14
12
  opacity: 1,
15
- transition: 'border-color 0.15s linear, opacity 0.15s linear'
13
+ transition: 'border-color 0.15s linear, opacity 0.15s linear',
14
+ borderColor: "".concat("var(--ds-border, ".concat(N30A, ")")),
15
+ borderStyle: 'solid'
16
+ });
17
+ var verticalStyles = css({
18
+ borderWidth: "0 0 0 1px",
19
+ width: '1px',
20
+ height: '100%',
21
+ transform: 'translateX(-50%)'
22
+ });
23
+ var horizontalStyles = css({
24
+ borderWidth: "1px 0 0 0",
25
+ width: '100%',
26
+ height: '1px',
27
+ transform: 'translateY(-50%)'
16
28
  });
17
- var ActiveGuidelineStyles = css({
18
- borderColor: "var(--ds-border-focused, ".concat(B200, ")")
29
+ var activeGuidelineStyles = css({
30
+ borderColor: "var(--ds-border-focused, ".concat(B200, ")"),
31
+ '&:before, &:after': {
32
+ backgroundColor: "var(--ds-border-focused, ".concat(B200, ")")
33
+ }
19
34
  });
20
- var HiddenGuidelineStyles = css({
35
+ var hiddenGuidelineStyles = css({
21
36
  opacity: 0
22
37
  });
23
- var DashedGuidelineStyles = css({
38
+ var dashedGuidelineStyles = css({
24
39
  borderLeftStyle: 'dashed'
25
40
  });
41
+ var verticalCapStyles = css({
42
+ '&:before, &:after': {
43
+ backgroundColor: "var(--ds-border, ".concat(N30A, ")"),
44
+ content: '""',
45
+ position: 'absolute',
46
+ height: '10px',
47
+ width: '1px',
48
+ transform: 'translateY(-50%)'
49
+ },
50
+ '&:after': {
51
+ right: 0
52
+ }
53
+ });
54
+ var horizontalCapStyles = css({
55
+ '&:before, &:after': {
56
+ backgroundColor: "".concat("var(--ds-border, ".concat(N30A, ")")),
57
+ content: '""',
58
+ position: 'absolute',
59
+ height: '1px',
60
+ width: '10px',
61
+ transform: 'translateX(-50%)'
62
+ },
63
+ '&:after': {
64
+ bottom: 0
65
+ }
66
+ });
26
67
  export var Guideline = function Guideline(props) {
27
68
  var position = props.position,
28
69
  active = props.active,
29
70
  _props$show = props.show,
30
71
  show = _props$show === void 0 ? true : _props$show,
31
- style = props.style,
32
- color = props.color;
72
+ _props$styles = props.styles,
73
+ styles = _props$styles === void 0 ? {} : _props$styles;
74
+ var isVerticalPos = isVerticalPosition(position);
75
+ var lineStyle = styles.lineStyle,
76
+ color = styles.color,
77
+ capStyle = styles.capStyle;
33
78
  return jsx("div", {
34
- css: [BasicGuidelineStyles, active && ActiveGuidelineStyles, !show && HiddenGuidelineStyles, style === 'dashed' && DashedGuidelineStyles],
35
- className: "guideline",
36
- style: _objectSpread({
37
- left: "".concat(position, "px")
38
- }, color && {
79
+ css: [basicGuidelineStyles, isVerticalPos ? verticalStyles : horizontalStyles, capStyle === 'line' && (isVerticalPos ? horizontalCapStyles : verticalCapStyles), active && activeGuidelineStyles, !show && hiddenGuidelineStyles, lineStyle === 'dashed' && dashedGuidelineStyles],
80
+ style: _objectSpread(_objectSpread({}, color && {
39
81
  borderColor: "".concat(color)
40
- })
82
+ }), getPositionStyles(position)),
83
+ className: "guideline"
41
84
  });
42
85
  };
@@ -1,8 +1,13 @@
1
+ import _extends from "@babel/runtime/helpers/extends";
2
+ import _objectWithoutProperties from "@babel/runtime/helpers/objectWithoutProperties";
3
+ import _defineProperty from "@babel/runtime/helpers/defineProperty";
1
4
  import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
5
+ var _excluded = ["key"];
2
6
  /** @jsx jsx */
3
7
  import { useLayoutEffect, useRef, useState } from 'react';
4
8
  import { css, jsx } from '@emotion/react';
5
9
  import { akEditorFullWidthLayoutWidth } from '@atlaskit/editor-shared-styles';
10
+ import { VAR_POSITION_OFFSET_X, VAR_POSITION_OFFSET_Y } from './constants';
6
11
  import { Guideline } from './guideline';
7
12
  var guidelineContainerStyles = css({
8
13
  position: 'fixed',
@@ -14,6 +19,7 @@ var guidelineContainerStyles = css({
14
19
  maxWidth: "".concat(akEditorFullWidthLayoutWidth, "px")
15
20
  });
16
21
  export var GuidelineContainer = function GuidelineContainer(props) {
22
+ var _style;
17
23
  var guidelines = props.guidelines,
18
24
  height = props.height,
19
25
  editorWidth = props.editorWidth,
@@ -31,20 +37,17 @@ export var GuidelineContainer = function GuidelineContainer(props) {
31
37
  setOffset(centerOffset - rect.x);
32
38
  }
33
39
  }, [centerOffset, guidelines, editorWidth]);
40
+ var style = (_style = {}, _defineProperty(_style, VAR_POSITION_OFFSET_X, "".concat(offset, "px")), _defineProperty(_style, VAR_POSITION_OFFSET_Y, "0px"), _defineProperty(_style, "height", height), _style);
34
41
  return jsx("div", {
35
42
  ref: ref,
36
43
  css: guidelineContainerStyles,
37
- style: {
38
- height: height
39
- },
44
+ style: style,
40
45
  "data-testid": "guidelineContainer"
41
46
  }, guidelines.map(function (guideline) {
42
- return jsx(Guideline, {
43
- key: guideline.key,
44
- position: guideline.position.x + offset,
45
- active: guideline.active,
46
- show: guideline.show,
47
- style: guideline.style
48
- });
47
+ var key = guideline.key,
48
+ guidelineProps = _objectWithoutProperties(guideline, _excluded);
49
+ return jsx(Guideline, _extends({
50
+ key: key
51
+ }, guidelineProps));
49
52
  }));
50
53
  };
@@ -4,7 +4,7 @@ import { PluginKey } from 'prosemirror-state';
4
4
  import { useSharedPluginState } from '@atlaskit/editor-common/hooks';
5
5
  import { SafePlugin } from '@atlaskit/editor-common/safe-plugin';
6
6
  import { akEditorGridLineZIndex } from '@atlaskit/editor-shared-styles';
7
- import { GuidelineContainer } from './guildelineContainer';
7
+ import { GuidelineContainer } from './guidelineContainer';
8
8
  import { getEditorCenterX } from './utils';
9
9
  var guidelineStyles = css({
10
10
  position: 'absolute',
@@ -0,0 +1,25 @@
1
+ /* eslint-disable @atlaskit/design-system/ensure-design-token-usage/preview */
2
+
3
+ import { isVerticalPosition } from '@atlaskit/editor-common/guideline';
4
+ import { VAR_POSITION_OFFSET_X, VAR_POSITION_OFFSET_Y } from './constants';
5
+ export var isNumber = function isNumber(x) {
6
+ return typeof x === 'number' && !isNaN(x) && isFinite(x);
7
+ };
8
+ var getXPosition = function getXPosition(pixel) {
9
+ return isNumber(pixel) ? "calc(".concat(pixel, "px + var(").concat(VAR_POSITION_OFFSET_X, ", '0px'))") : 'unset';
10
+ };
11
+ var getYPosition = function getYPosition(pixel) {
12
+ return isNumber(pixel) ? "calc(".concat(pixel, "px + var(").concat(VAR_POSITION_OFFSET_Y, ", '0px'))") : 'unset';
13
+ };
14
+ export var getPositionStyles = function getPositionStyles(pos) {
15
+ var _pos$y, _pos$x;
16
+ return isVerticalPosition(pos) ? {
17
+ left: getXPosition(pos.x),
18
+ top: getYPosition((_pos$y = pos.y) === null || _pos$y === void 0 ? void 0 : _pos$y.start),
19
+ height: pos.y ? "".concat(pos.y.end - pos.y.start, "px") : '100%'
20
+ } : {
21
+ top: getYPosition(pos.y),
22
+ left: getXPosition((_pos$x = pos.x) === null || _pos$x === void 0 ? void 0 : _pos$x.start),
23
+ width: pos.x ? "".concat(pos.x.end - pos.x.start, "px") : '100%'
24
+ };
25
+ };
@@ -1,5 +1,5 @@
1
1
  {
2
2
  "name": "@atlaskit/editor-plugin-guideline",
3
- "version": "0.3.4",
3
+ "version": "0.3.6",
4
4
  "sideEffects": false
5
5
  }
@@ -0,0 +1,2 @@
1
+ export declare const VAR_POSITION_OFFSET_X = "--guideline-offset-x";
2
+ export declare const VAR_POSITION_OFFSET_Y = "--guideline-offset-y";
@@ -1,12 +1,4 @@
1
1
  /** @jsx jsx */
2
2
  import { jsx } from '@emotion/react';
3
- import { CSSToken } from '@atlaskit/tokens';
4
- type Props = {
5
- position: number;
6
- active?: boolean;
7
- show?: boolean;
8
- style?: 'dashed' | 'solid';
9
- color?: CSSToken;
10
- };
11
- export declare const Guideline: (props: Props) => jsx.JSX.Element;
12
- export {};
3
+ import { GuidelineConfig } from './types';
4
+ export declare const Guideline: (props: Omit<GuidelineConfig, 'key'>) => jsx.JSX.Element;
@@ -0,0 +1,4 @@
1
+ import type { CSSProperties } from 'react';
2
+ import { Position } from './types';
3
+ export declare const isNumber: (x: unknown) => x is number;
4
+ export declare const getPositionStyles: (pos: Position) => CSSProperties;
@@ -1,21 +1 @@
1
- import { EditorView } from 'prosemirror-view';
2
- import { CSSToken } from '@atlaskit/tokens';
3
- export type Position = {
4
- x: number;
5
- };
6
- type GuidelineConfig = {
7
- key: string;
8
- position: Position;
9
- active?: boolean;
10
- show?: boolean;
11
- style?: 'dashed' | 'solid';
12
- color?: CSSToken;
13
- };
14
- type GuidelinePluginState = {
15
- guidelines: GuidelineConfig[];
16
- };
17
- interface GuidelinePluginOptions {
18
- }
19
- type DisplayGrid = (props: Required<GuidelinePluginState>) => boolean;
20
- type DisplayGuideline = (view: EditorView) => DisplayGrid;
21
- export type { GuidelinePluginState, GuidelinePluginOptions, GuidelineConfig, DisplayGuideline, };
1
+ export type { WidthTypes, Position, VerticalPosition, HorizontalPosition, GuidelineConfig, GuidelinePluginState, GuidelinePluginOptions, DisplayGuideline, DisplayGrid, } from '@atlaskit/editor-common/guideline';
@@ -0,0 +1,2 @@
1
+ export declare const VAR_POSITION_OFFSET_X = "--guideline-offset-x";
2
+ export declare const VAR_POSITION_OFFSET_Y = "--guideline-offset-y";
@@ -1,12 +1,4 @@
1
1
  /** @jsx jsx */
2
2
  import { jsx } from '@emotion/react';
3
- import { CSSToken } from '@atlaskit/tokens';
4
- type Props = {
5
- position: number;
6
- active?: boolean;
7
- show?: boolean;
8
- style?: 'dashed' | 'solid';
9
- color?: CSSToken;
10
- };
11
- export declare const Guideline: (props: Props) => jsx.JSX.Element;
12
- export {};
3
+ import { GuidelineConfig } from './types';
4
+ export declare const Guideline: (props: Omit<GuidelineConfig, 'key'>) => jsx.JSX.Element;
@@ -0,0 +1,4 @@
1
+ import type { CSSProperties } from 'react';
2
+ import { Position } from './types';
3
+ export declare const isNumber: (x: unknown) => x is number;
4
+ export declare const getPositionStyles: (pos: Position) => CSSProperties;
@@ -1,21 +1 @@
1
- import { EditorView } from 'prosemirror-view';
2
- import { CSSToken } from '@atlaskit/tokens';
3
- export type Position = {
4
- x: number;
5
- };
6
- type GuidelineConfig = {
7
- key: string;
8
- position: Position;
9
- active?: boolean;
10
- show?: boolean;
11
- style?: 'dashed' | 'solid';
12
- color?: CSSToken;
13
- };
14
- type GuidelinePluginState = {
15
- guidelines: GuidelineConfig[];
16
- };
17
- interface GuidelinePluginOptions {
18
- }
19
- type DisplayGrid = (props: Required<GuidelinePluginState>) => boolean;
20
- type DisplayGuideline = (view: EditorView) => DisplayGrid;
21
- export type { GuidelinePluginState, GuidelinePluginOptions, GuidelineConfig, DisplayGuideline, };
1
+ export type { WidthTypes, Position, VerticalPosition, HorizontalPosition, GuidelineConfig, GuidelinePluginState, GuidelinePluginOptions, DisplayGuideline, DisplayGrid, } from '@atlaskit/editor-common/guideline';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atlaskit/editor-plugin-guideline",
3
- "version": "0.3.4",
3
+ "version": "0.3.6",
4
4
  "description": "guideline plugin for @atlaskit/editor-core",
5
5
  "author": "Atlassian Pty Ltd",
6
6
  "license": "Apache-2.0",
@@ -23,11 +23,11 @@
23
23
  ".": "./src/index.ts"
24
24
  },
25
25
  "dependencies": {
26
- "@atlaskit/editor-common": "^74.15.0",
26
+ "@atlaskit/editor-common": "^74.26.0",
27
27
  "@atlaskit/editor-plugin-width": "^0.1.0",
28
- "@atlaskit/editor-shared-styles": "^2.4.0",
28
+ "@atlaskit/editor-shared-styles": "^2.5.0",
29
29
  "@atlaskit/theme": "^12.5.0",
30
- "@atlaskit/tokens": "^1.11.0",
30
+ "@atlaskit/tokens": "^1.13.0",
31
31
  "@babel/runtime": "^7.0.0",
32
32
  "@emotion/react": "^11.7.1",
33
33
  "prosemirror-state": "1.3.4",
@@ -37,6 +37,7 @@
37
37
  "react": "^16.8.0"
38
38
  },
39
39
  "devDependencies": {
40
+ "@af/visual-regression": "*",
40
41
  "@atlassian/atlassian-frontend-prettier-config-1.0.0": "npm:@atlassian/atlassian-frontend-prettier-config@1.0.0",
41
42
  "@testing-library/react": "^12.1.5",
42
43
  "react-dom": "^16.8.0",
package/report.api.md CHANGED
@@ -15,26 +15,13 @@
15
15
  <!--SECTION START: Main Entry Types-->
16
16
 
17
17
  ```ts
18
- import { CSSToken } from '@atlaskit/tokens';
19
- import { EditorView } from 'prosemirror-view';
18
+ import { DisplayGuideline } from '@atlaskit/editor-common/guideline';
19
+ import { GuidelineConfig } from '@atlaskit/editor-common/guideline';
20
+ import { GuidelinePluginState } from '@atlaskit/editor-common/guideline';
20
21
  import { NextEditorPlugin } from '@atlaskit/editor-common/types';
21
22
  import type { widthPlugin } from '@atlaskit/editor-plugin-width';
22
23
 
23
- // @public (undocumented)
24
- type DisplayGrid = (props: Required<GuidelinePluginState>) => boolean;
25
-
26
- // @public (undocumented)
27
- type DisplayGuideline = (view: EditorView) => DisplayGrid;
28
-
29
- // @public (undocumented)
30
- export type GuidelineConfig = {
31
- key: string;
32
- position: Position;
33
- active?: boolean;
34
- show?: boolean;
35
- style?: 'dashed' | 'solid';
36
- color?: CSSToken;
37
- };
24
+ export { GuidelineConfig };
38
25
 
39
26
  // @public (undocumented)
40
27
  export const guidelinePlugin: NextEditorPlugin<
@@ -48,16 +35,6 @@ export const guidelinePlugin: NextEditorPlugin<
48
35
  }
49
36
  >;
50
37
 
51
- // @public (undocumented)
52
- type GuidelinePluginState = {
53
- guidelines: GuidelineConfig[];
54
- };
55
-
56
- // @public (undocumented)
57
- type Position = {
58
- x: number;
59
- };
60
-
61
38
  // (No @packageDocumentation comment for this package)
62
39
  ```
63
40
 
@@ -4,26 +4,13 @@
4
4
 
5
5
  ```ts
6
6
 
7
- import { CSSToken } from '@atlaskit/tokens';
8
- import { EditorView } from 'prosemirror-view';
7
+ import { DisplayGuideline } from '@atlaskit/editor-common/guideline';
8
+ import { GuidelineConfig } from '@atlaskit/editor-common/guideline';
9
+ import { GuidelinePluginState } from '@atlaskit/editor-common/guideline';
9
10
  import { NextEditorPlugin } from '@atlaskit/editor-common/types';
10
11
  import type { widthPlugin } from '@atlaskit/editor-plugin-width';
11
12
 
12
- // @public (undocumented)
13
- type DisplayGrid = (props: Required<GuidelinePluginState>) => boolean;
14
-
15
- // @public (undocumented)
16
- type DisplayGuideline = (view: EditorView) => DisplayGrid;
17
-
18
- // @public (undocumented)
19
- export type GuidelineConfig = {
20
- key: string;
21
- position: Position;
22
- active?: boolean;
23
- show?: boolean;
24
- style?: 'dashed' | 'solid';
25
- color?: CSSToken;
26
- };
13
+ export { GuidelineConfig }
27
14
 
28
15
  // @public (undocumented)
29
16
  export const guidelinePlugin: NextEditorPlugin<'guideline', {
@@ -34,16 +21,6 @@ export const guidelinePlugin: NextEditorPlugin<'guideline', {
34
21
  };
35
22
  }>;
36
23
 
37
- // @public (undocumented)
38
- type GuidelinePluginState = {
39
- guidelines: GuidelineConfig[];
40
- };
41
-
42
- // @public (undocumented)
43
- type Position = {
44
- x: number;
45
- };
46
-
47
24
  // (No @packageDocumentation comment for this package)
48
25
 
49
26
  ```