@atlaskit/editor-plugin-guideline 0.2.0 → 0.3.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.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,16 @@
1
1
  # @atlaskit/editor-plugin-guideline
2
2
 
3
+ ## 0.3.0
4
+
5
+ ### Minor Changes
6
+
7
+ - [`d7aa08972c6`](https://bitbucket.org/atlassian/atlassian-frontend/commits/d7aa08972c6) - add style handler for the editor guideline plugin
8
+ - [`1dadcae5b09`](https://bitbucket.org/atlassian/atlassian-frontend/commits/1dadcae5b09) - COLLAB-2623 Updated API to newest interface and added utils to create default gridlines
9
+
10
+ ### Patch Changes
11
+
12
+ - Updated dependencies
13
+
3
14
  ## 0.2.0
4
15
 
5
16
  ### Minor Changes
@@ -14,21 +14,30 @@ var BasicGuidelineStyles = (0, _react.css)({
14
14
  width: '1px',
15
15
  height: '100%',
16
16
  zIndex: 0,
17
- transition: 'border-color 0.15s linear'
17
+ opacity: 1,
18
+ transition: 'border-color 0.15s linear, opacity 0.15s linear'
19
+ });
20
+ var ActiveGuidelineStyles = (0, _react.css)({
21
+ borderColor: "var(--ds-border-focused, ".concat(_colors.B200, ")")
22
+ });
23
+ var HiddenGuidelineStyles = (0, _react.css)({
24
+ opacity: 0
25
+ });
26
+ var DashedGuidelineStyles = (0, _react.css)({
27
+ borderLeftStyle: 'dashed'
18
28
  });
19
- var positionToStyle = function positionToStyle(position) {
20
- var left = position.left,
21
- right = position.right;
22
- return left ? {
23
- left: left
24
- } : {
25
- right: right
26
- };
27
- };
28
29
  var Guideline = function Guideline(props) {
30
+ var position = props.position,
31
+ active = props.active,
32
+ _props$show = props.show,
33
+ show = _props$show === void 0 ? true : _props$show,
34
+ style = props.style;
29
35
  return (0, _react.jsx)("div", {
30
- css: BasicGuidelineStyles,
31
- style: positionToStyle(props.position)
36
+ css: [BasicGuidelineStyles, active && ActiveGuidelineStyles, !show && HiddenGuidelineStyles, style === 'dashed' && DashedGuidelineStyles],
37
+ className: "guideline",
38
+ style: {
39
+ left: "".concat(position, "px")
40
+ }
32
41
  });
33
42
  };
34
43
  exports.Guideline = Guideline;
@@ -5,15 +5,14 @@ Object.defineProperty(exports, "__esModule", {
5
5
  value: true
6
6
  });
7
7
  exports.GuidelineContainer = void 0;
8
- var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray"));
9
- var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
10
- var _react = require("@emotion/react");
8
+ var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
9
+ var _react = require("react");
10
+ var _react2 = require("@emotion/react");
11
11
  var _editorSharedStyles = require("@atlaskit/editor-shared-styles");
12
12
  var _guideline = require("./guideline");
13
- var _types = require("./types");
14
- 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; }
15
- 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 */
16
- var guidelineContainerStyles = (0, _react.css)({
13
+ /** @jsx jsx */
14
+
15
+ var guidelineContainerStyles = (0, _react2.css)({
17
16
  position: 'fixed',
18
17
  height: '100vh',
19
18
  width: '100%',
@@ -22,52 +21,39 @@ var guidelineContainerStyles = (0, _react.css)({
22
21
  border: 'none',
23
22
  maxWidth: "".concat(_editorSharedStyles.akEditorFullWidthLayoutWidth, "px")
24
23
  });
25
- var guidelineSubContainerStyles = (0, _react.css)({
26
- position: 'relative'
27
- });
28
- var groupGuidelines = function groupGuidelines(guidelines) {
29
- var _guidelines$reduce;
30
- return guidelines.reduce(function (acc, curr) {
31
- var areaKey = curr.position.containerArea || _types.GuidelineContainerArea.EditorContent;
32
- var currentList = acc[areaKey];
33
- return _objectSpread(_objectSpread({}, acc), {}, (0, _defineProperty2.default)({}, areaKey, [].concat((0, _toConsumableArray2.default)(currentList), [curr])));
34
- }, (_guidelines$reduce = {}, (0, _defineProperty2.default)(_guidelines$reduce, _types.GuidelineContainerArea.EditorLeftMargin, []), (0, _defineProperty2.default)(_guidelines$reduce, _types.GuidelineContainerArea.EditorContent, []), (0, _defineProperty2.default)(_guidelines$reduce, _types.GuidelineContainerArea.EditorRightMargin, []), _guidelines$reduce));
35
- };
36
- var GuidelineSubContainer = function GuidelineSubContainer(props) {
37
- return (0, _react.jsx)("div", {
38
- css: guidelineSubContainerStyles,
39
- "data-container-id": props.containerId
40
- }, props.guidelines.map(function (guideline) {
41
- return (0, _react.jsx)(_guideline.Guideline, {
42
- key: guideline.key,
43
- position: guideline.position
44
- });
45
- }));
46
- };
47
24
  var GuidelineContainer = function GuidelineContainer(props) {
48
25
  var guidelines = props.guidelines,
49
26
  height = props.height,
50
- editorWidth = props.editorWidth;
51
- if (guidelines.length === 0) {
52
- return null;
53
- }
54
- var guidelineGroups = groupGuidelines(guidelines);
55
- return (0, _react.jsx)("div", {
27
+ editorWidth = props.editorWidth,
28
+ centerOffset = props.centerOffset;
29
+ var _useState = (0, _react.useState)(0),
30
+ _useState2 = (0, _slicedToArray2.default)(_useState, 2),
31
+ offset = _useState2[0],
32
+ setOffset = _useState2[1];
33
+ var ref = (0, _react.useRef)(null);
34
+ (0, _react.useLayoutEffect)(function () {
35
+ var _ref$current;
36
+ var rect = ref === null || ref === void 0 ? void 0 : (_ref$current = ref.current) === null || _ref$current === void 0 ? void 0 : _ref$current.getBoundingClientRect();
37
+ if (rect) {
38
+ // X pixels from guideline container left to editor center.
39
+ setOffset(centerOffset - rect.x);
40
+ }
41
+ }, [centerOffset, guidelines, editorWidth]);
42
+ return (0, _react2.jsx)("div", {
43
+ ref: ref,
56
44
  css: guidelineContainerStyles,
57
45
  style: {
58
- height: height,
59
- gridTemplateColumns: "[left] auto [editor] ".concat(editorWidth, "px [right] auto")
46
+ height: height
60
47
  },
61
48
  "data-testid": "guidelineContainer"
62
- }, (0, _react.jsx)(GuidelineSubContainer, {
63
- containerId: _types.GuidelineContainerArea.EditorLeftMargin,
64
- guidelines: guidelineGroups[_types.GuidelineContainerArea.EditorLeftMargin]
65
- }), (0, _react.jsx)(GuidelineSubContainer, {
66
- containerId: _types.GuidelineContainerArea.EditorContent,
67
- guidelines: guidelineGroups[_types.GuidelineContainerArea.EditorContent]
68
- }), (0, _react.jsx)(GuidelineSubContainer, {
69
- containerId: _types.GuidelineContainerArea.EditorRightMargin,
70
- guidelines: guidelineGroups[_types.GuidelineContainerArea.EditorRightMargin]
49
+ }, 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
+ });
71
57
  }));
72
58
  };
73
59
  exports.GuidelineContainer = GuidelineContainer;
@@ -10,6 +10,7 @@ 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
12
  var _guildelineContainer = require("./guildelineContainer");
13
+ var _utils = require("./utils");
13
14
  /** @jsx jsx */
14
15
 
15
16
  var guidelineStyles = (0, _react.css)({
@@ -66,6 +67,7 @@ var ContentComponent = function ContentComponent(_ref) {
66
67
  }, (0, _react.jsx)(_guildelineContainer.GuidelineContainer, {
67
68
  guidelines: guidelineState.guidelines,
68
69
  height: editorView.dom.scrollHeight,
70
+ centerOffset: (0, _utils.getEditorCenterX)(editorView),
69
71
  containerWidth: widthState.containerWidth,
70
72
  editorWidth: widthState.lineLength
71
73
  }));
package/dist/cjs/types.js CHANGED
@@ -2,12 +2,4 @@
2
2
 
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
- });
6
- exports.GuidelineContainerArea = void 0;
7
- var GuidelineContainerArea = /*#__PURE__*/function (GuidelineContainerArea) {
8
- GuidelineContainerArea["EditorLeftMargin"] = "editorLeftMargin";
9
- GuidelineContainerArea["EditorContent"] = "editorContent";
10
- GuidelineContainerArea["EditorRightMargin"] = "editorRightMargin";
11
- return GuidelineContainerArea;
12
- }({});
13
- exports.GuidelineContainerArea = GuidelineContainerArea;
5
+ });
@@ -0,0 +1,59 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
+ Object.defineProperty(exports, "__esModule", {
5
+ value: true
6
+ });
7
+ exports.innerGuidelines = exports.getEditorCenterX = void 0;
8
+ var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray"));
9
+ var _editorSharedStyles = require("@atlaskit/editor-shared-styles");
10
+ /**
11
+ * This function calculates the Editor's x axis of the center point
12
+ * in relation to the viewport
13
+ * @param editorView
14
+ * @returns x axis in number
15
+ */
16
+ var getEditorCenterX = function getEditorCenterX(editorView) {
17
+ var editorRect = editorView.dom.getBoundingClientRect();
18
+ return editorRect.width / 2 + editorRect.x;
19
+ };
20
+ exports.getEditorCenterX = getEditorCenterX;
21
+ var defaultGrids = [-6, -5, -4, -3, -2, -1, 0, 1, 2, 3, 4, 5, 6];
22
+ var innerGuidelines = function innerGuidelines(editorContainerWidth) {
23
+ var editorWidth = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : _editorSharedStyles.akEditorDefaultLayoutWidth;
24
+ var wideSpacing = editorWidth * _editorSharedStyles.breakoutWideScaleRatio / 2;
25
+ var fullWidthPadding = (_editorSharedStyles.akEditorBreakoutPadding + editorWidth - _editorSharedStyles.akEditorDefaultLayoutWidth) / 2;
26
+ var containerWidth = Math.min(editorContainerWidth, _editorSharedStyles.akEditorFullWidthLayoutWidth) / 2 - fullWidthPadding;
27
+ var fullWidthGuidelines = [{
28
+ key: "full_width_left",
29
+ position: {
30
+ x: -containerWidth
31
+ }
32
+ }, {
33
+ key: "full_width_right",
34
+ position: {
35
+ x: containerWidth
36
+ }
37
+ }];
38
+ var wideGuidelines = [{
39
+ key: "wide_left",
40
+ position: {
41
+ x: -wideSpacing
42
+ }
43
+ }, {
44
+ key: "wide_right",
45
+ position: {
46
+ x: wideSpacing
47
+ }
48
+ }];
49
+ var gridGuidelines = defaultGrids.map(function (val, index) {
50
+ return {
51
+ key: "grid_".concat(index),
52
+ position: {
53
+ x: val / 12 * editorWidth
54
+ }
55
+ };
56
+ });
57
+ return [].concat((0, _toConsumableArray2.default)(gridGuidelines), wideGuidelines, fullWidthGuidelines);
58
+ };
59
+ exports.innerGuidelines = innerGuidelines;
@@ -1,5 +1,5 @@
1
1
  {
2
2
  "name": "@atlaskit/editor-plugin-guideline",
3
- "version": "0.2.0",
3
+ "version": "0.3.0",
4
4
  "sideEffects": false
5
5
  }
@@ -1,26 +1,36 @@
1
1
  /** @jsx jsx */
2
2
  import { css, jsx } from '@emotion/react';
3
- import { N30A } from '@atlaskit/theme/colors';
3
+ import { B200, N30A } from '@atlaskit/theme/colors';
4
4
  const BasicGuidelineStyles = css({
5
5
  borderLeft: `1px solid ${`var(--ds-border, ${N30A})`}`,
6
6
  position: 'absolute',
7
7
  width: '1px',
8
8
  height: '100%',
9
9
  zIndex: 0,
10
- transition: 'border-color 0.15s linear'
10
+ opacity: 1,
11
+ transition: 'border-color 0.15s linear, opacity 0.15s linear'
11
12
  });
12
- const positionToStyle = position => {
13
+ const ActiveGuidelineStyles = css({
14
+ borderColor: `var(--ds-border-focused, ${B200})`
15
+ });
16
+ const HiddenGuidelineStyles = css({
17
+ opacity: 0
18
+ });
19
+ const DashedGuidelineStyles = css({
20
+ borderLeftStyle: 'dashed'
21
+ });
22
+ export const Guideline = props => {
13
23
  const {
14
- left,
15
- right
16
- } = position;
17
- return left ? {
18
- left
19
- } : {
20
- right
21
- };
22
- };
23
- export const Guideline = props => jsx("div", {
24
- css: BasicGuidelineStyles,
25
- style: positionToStyle(props.position)
26
- });
24
+ position,
25
+ active,
26
+ show = true,
27
+ style
28
+ } = props;
29
+ return jsx("div", {
30
+ css: [BasicGuidelineStyles, active && ActiveGuidelineStyles, !show && HiddenGuidelineStyles, style === 'dashed' && DashedGuidelineStyles],
31
+ className: "guideline",
32
+ style: {
33
+ left: `${position}px`
34
+ }
35
+ });
36
+ };
@@ -1,8 +1,8 @@
1
1
  /** @jsx jsx */
2
+ import { useLayoutEffect, useRef, useState } from 'react';
2
3
  import { css, jsx } from '@emotion/react';
3
4
  import { akEditorFullWidthLayoutWidth } from '@atlaskit/editor-shared-styles';
4
5
  import { Guideline } from './guideline';
5
- import { GuidelineContainerArea as Areas } from './types';
6
6
  const guidelineContainerStyles = css({
7
7
  position: 'fixed',
8
8
  height: '100vh',
@@ -12,53 +12,37 @@ const guidelineContainerStyles = css({
12
12
  border: 'none',
13
13
  maxWidth: `${akEditorFullWidthLayoutWidth}px`
14
14
  });
15
- const guidelineSubContainerStyles = css({
16
- position: 'relative'
17
- });
18
- const groupGuidelines = guidelines => guidelines.reduce((acc, curr) => {
19
- const areaKey = curr.position.containerArea || Areas.EditorContent;
20
- const currentList = acc[areaKey];
21
- return {
22
- ...acc,
23
- [areaKey]: [...currentList, curr]
24
- };
25
- }, {
26
- [Areas.EditorLeftMargin]: [],
27
- [Areas.EditorContent]: [],
28
- [Areas.EditorRightMargin]: []
29
- });
30
- const GuidelineSubContainer = props => jsx("div", {
31
- css: guidelineSubContainerStyles,
32
- "data-container-id": props.containerId
33
- }, props.guidelines.map(guideline => jsx(Guideline, {
34
- key: guideline.key,
35
- position: guideline.position
36
- })));
37
15
  export const GuidelineContainer = props => {
38
16
  const {
39
17
  guidelines,
40
18
  height,
41
- editorWidth
19
+ editorWidth,
20
+ centerOffset
42
21
  } = props;
43
- if (guidelines.length === 0) {
44
- return null;
45
- }
46
- const guidelineGroups = groupGuidelines(guidelines);
22
+ const [offset, setOffset] = useState(0);
23
+ const ref = useRef(null);
24
+ useLayoutEffect(() => {
25
+ var _ref$current;
26
+ const rect = ref === null || ref === void 0 ? void 0 : (_ref$current = ref.current) === null || _ref$current === void 0 ? void 0 : _ref$current.getBoundingClientRect();
27
+ if (rect) {
28
+ // X pixels from guideline container left to editor center.
29
+ setOffset(centerOffset - rect.x);
30
+ }
31
+ }, [centerOffset, guidelines, editorWidth]);
47
32
  return jsx("div", {
33
+ ref: ref,
48
34
  css: guidelineContainerStyles,
49
35
  style: {
50
- height,
51
- gridTemplateColumns: `[left] auto [editor] ${editorWidth}px [right] auto`
36
+ height
52
37
  },
53
38
  "data-testid": "guidelineContainer"
54
- }, jsx(GuidelineSubContainer, {
55
- containerId: Areas.EditorLeftMargin,
56
- guidelines: guidelineGroups[Areas.EditorLeftMargin]
57
- }), jsx(GuidelineSubContainer, {
58
- containerId: Areas.EditorContent,
59
- guidelines: guidelineGroups[Areas.EditorContent]
60
- }), jsx(GuidelineSubContainer, {
61
- containerId: Areas.EditorRightMargin,
62
- guidelines: guidelineGroups[Areas.EditorRightMargin]
39
+ }, 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
+ });
63
47
  }));
64
48
  };
@@ -5,6 +5,7 @@ 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
7
  import { GuidelineContainer } from './guildelineContainer';
8
+ import { getEditorCenterX } from './utils';
8
9
  const guidelineStyles = css({
9
10
  position: 'absolute',
10
11
  width: '100%',
@@ -60,6 +61,7 @@ const ContentComponent = ({
60
61
  }, jsx(GuidelineContainer, {
61
62
  guidelines: guidelineState.guidelines,
62
63
  height: editorView.dom.scrollHeight,
64
+ centerOffset: getEditorCenterX(editorView),
63
65
  containerWidth: widthState.containerWidth,
64
66
  editorWidth: widthState.lineLength
65
67
  }));
@@ -1,6 +1 @@
1
- export let GuidelineContainerArea = /*#__PURE__*/function (GuidelineContainerArea) {
2
- GuidelineContainerArea["EditorLeftMargin"] = "editorLeftMargin";
3
- GuidelineContainerArea["EditorContent"] = "editorContent";
4
- GuidelineContainerArea["EditorRightMargin"] = "editorRightMargin";
5
- return GuidelineContainerArea;
6
- }({});
1
+ export {};
@@ -0,0 +1,46 @@
1
+ import { akEditorBreakoutPadding, akEditorDefaultLayoutWidth, akEditorFullWidthLayoutWidth, breakoutWideScaleRatio } from '@atlaskit/editor-shared-styles';
2
+ /**
3
+ * This function calculates the Editor's x axis of the center point
4
+ * in relation to the viewport
5
+ * @param editorView
6
+ * @returns x axis in number
7
+ */
8
+ export const getEditorCenterX = editorView => {
9
+ const editorRect = editorView.dom.getBoundingClientRect();
10
+ return editorRect.width / 2 + editorRect.x;
11
+ };
12
+ const defaultGrids = [-6, -5, -4, -3, -2, -1, 0, 1, 2, 3, 4, 5, 6];
13
+ export const innerGuidelines = (editorContainerWidth, editorWidth = akEditorDefaultLayoutWidth) => {
14
+ const wideSpacing = editorWidth * breakoutWideScaleRatio / 2;
15
+ const fullWidthPadding = (akEditorBreakoutPadding + editorWidth - akEditorDefaultLayoutWidth) / 2;
16
+ const containerWidth = Math.min(editorContainerWidth, akEditorFullWidthLayoutWidth) / 2 - fullWidthPadding;
17
+ const fullWidthGuidelines = [{
18
+ key: `full_width_left`,
19
+ position: {
20
+ x: -containerWidth
21
+ }
22
+ }, {
23
+ key: `full_width_right`,
24
+ position: {
25
+ x: containerWidth
26
+ }
27
+ }];
28
+ const wideGuidelines = [{
29
+ key: `wide_left`,
30
+ position: {
31
+ x: -wideSpacing
32
+ }
33
+ }, {
34
+ key: `wide_right`,
35
+ position: {
36
+ x: wideSpacing
37
+ }
38
+ }];
39
+ const gridGuidelines = defaultGrids.map((val, index) => ({
40
+ key: `grid_${index}`,
41
+ position: {
42
+ x: val / 12 * editorWidth
43
+ }
44
+ }));
45
+ return [...gridGuidelines, ...wideGuidelines, ...fullWidthGuidelines];
46
+ };
@@ -1,5 +1,5 @@
1
1
  {
2
2
  "name": "@atlaskit/editor-plugin-guideline",
3
- "version": "0.2.0",
3
+ "version": "0.3.0",
4
4
  "sideEffects": false
5
5
  }
@@ -1,26 +1,35 @@
1
1
  /** @jsx jsx */
2
2
  import { css, jsx } from '@emotion/react';
3
- import { N30A } from '@atlaskit/theme/colors';
3
+ import { B200, N30A } from '@atlaskit/theme/colors';
4
4
  var BasicGuidelineStyles = css({
5
5
  borderLeft: "1px solid ".concat("var(--ds-border, ".concat(N30A, ")")),
6
6
  position: 'absolute',
7
7
  width: '1px',
8
8
  height: '100%',
9
9
  zIndex: 0,
10
- transition: 'border-color 0.15s linear'
10
+ opacity: 1,
11
+ transition: 'border-color 0.15s linear, opacity 0.15s linear'
12
+ });
13
+ var ActiveGuidelineStyles = css({
14
+ borderColor: "var(--ds-border-focused, ".concat(B200, ")")
15
+ });
16
+ var HiddenGuidelineStyles = css({
17
+ opacity: 0
18
+ });
19
+ var DashedGuidelineStyles = css({
20
+ borderLeftStyle: 'dashed'
11
21
  });
12
- var positionToStyle = function positionToStyle(position) {
13
- var left = position.left,
14
- right = position.right;
15
- return left ? {
16
- left: left
17
- } : {
18
- right: right
19
- };
20
- };
21
22
  export var Guideline = function Guideline(props) {
23
+ var position = props.position,
24
+ active = props.active,
25
+ _props$show = props.show,
26
+ show = _props$show === void 0 ? true : _props$show,
27
+ style = props.style;
22
28
  return jsx("div", {
23
- css: BasicGuidelineStyles,
24
- style: positionToStyle(props.position)
29
+ css: [BasicGuidelineStyles, active && ActiveGuidelineStyles, !show && HiddenGuidelineStyles, style === 'dashed' && DashedGuidelineStyles],
30
+ className: "guideline",
31
+ style: {
32
+ left: "".concat(position, "px")
33
+ }
25
34
  });
26
35
  };
@@ -1,12 +1,9 @@
1
- import _toConsumableArray from "@babel/runtime/helpers/toConsumableArray";
2
- import _defineProperty from "@babel/runtime/helpers/defineProperty";
3
- 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; }
4
- 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; }
1
+ import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
5
2
  /** @jsx jsx */
3
+ import { useLayoutEffect, useRef, useState } from 'react';
6
4
  import { css, jsx } from '@emotion/react';
7
5
  import { akEditorFullWidthLayoutWidth } from '@atlaskit/editor-shared-styles';
8
6
  import { Guideline } from './guideline';
9
- import { GuidelineContainerArea as Areas } from './types';
10
7
  var guidelineContainerStyles = css({
11
8
  position: 'fixed',
12
9
  height: '100vh',
@@ -16,51 +13,38 @@ var guidelineContainerStyles = css({
16
13
  border: 'none',
17
14
  maxWidth: "".concat(akEditorFullWidthLayoutWidth, "px")
18
15
  });
19
- var guidelineSubContainerStyles = css({
20
- position: 'relative'
21
- });
22
- var groupGuidelines = function groupGuidelines(guidelines) {
23
- var _guidelines$reduce;
24
- return guidelines.reduce(function (acc, curr) {
25
- var areaKey = curr.position.containerArea || Areas.EditorContent;
26
- var currentList = acc[areaKey];
27
- return _objectSpread(_objectSpread({}, acc), {}, _defineProperty({}, areaKey, [].concat(_toConsumableArray(currentList), [curr])));
28
- }, (_guidelines$reduce = {}, _defineProperty(_guidelines$reduce, Areas.EditorLeftMargin, []), _defineProperty(_guidelines$reduce, Areas.EditorContent, []), _defineProperty(_guidelines$reduce, Areas.EditorRightMargin, []), _guidelines$reduce));
29
- };
30
- var GuidelineSubContainer = function GuidelineSubContainer(props) {
31
- return jsx("div", {
32
- css: guidelineSubContainerStyles,
33
- "data-container-id": props.containerId
34
- }, props.guidelines.map(function (guideline) {
35
- return jsx(Guideline, {
36
- key: guideline.key,
37
- position: guideline.position
38
- });
39
- }));
40
- };
41
16
  export var GuidelineContainer = function GuidelineContainer(props) {
42
17
  var guidelines = props.guidelines,
43
18
  height = props.height,
44
- editorWidth = props.editorWidth;
45
- if (guidelines.length === 0) {
46
- return null;
47
- }
48
- var guidelineGroups = groupGuidelines(guidelines);
19
+ editorWidth = props.editorWidth,
20
+ centerOffset = props.centerOffset;
21
+ var _useState = useState(0),
22
+ _useState2 = _slicedToArray(_useState, 2),
23
+ offset = _useState2[0],
24
+ setOffset = _useState2[1];
25
+ var ref = useRef(null);
26
+ useLayoutEffect(function () {
27
+ var _ref$current;
28
+ var rect = ref === null || ref === void 0 ? void 0 : (_ref$current = ref.current) === null || _ref$current === void 0 ? void 0 : _ref$current.getBoundingClientRect();
29
+ if (rect) {
30
+ // X pixels from guideline container left to editor center.
31
+ setOffset(centerOffset - rect.x);
32
+ }
33
+ }, [centerOffset, guidelines, editorWidth]);
49
34
  return jsx("div", {
35
+ ref: ref,
50
36
  css: guidelineContainerStyles,
51
37
  style: {
52
- height: height,
53
- gridTemplateColumns: "[left] auto [editor] ".concat(editorWidth, "px [right] auto")
38
+ height: height
54
39
  },
55
40
  "data-testid": "guidelineContainer"
56
- }, jsx(GuidelineSubContainer, {
57
- containerId: Areas.EditorLeftMargin,
58
- guidelines: guidelineGroups[Areas.EditorLeftMargin]
59
- }), jsx(GuidelineSubContainer, {
60
- containerId: Areas.EditorContent,
61
- guidelines: guidelineGroups[Areas.EditorContent]
62
- }), jsx(GuidelineSubContainer, {
63
- containerId: Areas.EditorRightMargin,
64
- guidelines: guidelineGroups[Areas.EditorRightMargin]
41
+ }, 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
+ });
65
49
  }));
66
50
  };
@@ -5,6 +5,7 @@ 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
7
  import { GuidelineContainer } from './guildelineContainer';
8
+ import { getEditorCenterX } from './utils';
8
9
  var guidelineStyles = css({
9
10
  position: 'absolute',
10
11
  width: '100%',
@@ -58,6 +59,7 @@ var ContentComponent = function ContentComponent(_ref) {
58
59
  }, jsx(GuidelineContainer, {
59
60
  guidelines: guidelineState.guidelines,
60
61
  height: editorView.dom.scrollHeight,
62
+ centerOffset: getEditorCenterX(editorView),
61
63
  containerWidth: widthState.containerWidth,
62
64
  editorWidth: widthState.lineLength
63
65
  }));
package/dist/esm/types.js CHANGED
@@ -1,6 +1 @@
1
- export var GuidelineContainerArea = /*#__PURE__*/function (GuidelineContainerArea) {
2
- GuidelineContainerArea["EditorLeftMargin"] = "editorLeftMargin";
3
- GuidelineContainerArea["EditorContent"] = "editorContent";
4
- GuidelineContainerArea["EditorRightMargin"] = "editorRightMargin";
5
- return GuidelineContainerArea;
6
- }({});
1
+ export {};
@@ -0,0 +1,50 @@
1
+ import _toConsumableArray from "@babel/runtime/helpers/toConsumableArray";
2
+ import { akEditorBreakoutPadding, akEditorDefaultLayoutWidth, akEditorFullWidthLayoutWidth, breakoutWideScaleRatio } from '@atlaskit/editor-shared-styles';
3
+ /**
4
+ * This function calculates the Editor's x axis of the center point
5
+ * in relation to the viewport
6
+ * @param editorView
7
+ * @returns x axis in number
8
+ */
9
+ export var getEditorCenterX = function getEditorCenterX(editorView) {
10
+ var editorRect = editorView.dom.getBoundingClientRect();
11
+ return editorRect.width / 2 + editorRect.x;
12
+ };
13
+ var defaultGrids = [-6, -5, -4, -3, -2, -1, 0, 1, 2, 3, 4, 5, 6];
14
+ export var innerGuidelines = function innerGuidelines(editorContainerWidth) {
15
+ var editorWidth = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : akEditorDefaultLayoutWidth;
16
+ var wideSpacing = editorWidth * breakoutWideScaleRatio / 2;
17
+ var fullWidthPadding = (akEditorBreakoutPadding + editorWidth - akEditorDefaultLayoutWidth) / 2;
18
+ var containerWidth = Math.min(editorContainerWidth, akEditorFullWidthLayoutWidth) / 2 - fullWidthPadding;
19
+ var fullWidthGuidelines = [{
20
+ key: "full_width_left",
21
+ position: {
22
+ x: -containerWidth
23
+ }
24
+ }, {
25
+ key: "full_width_right",
26
+ position: {
27
+ x: containerWidth
28
+ }
29
+ }];
30
+ var wideGuidelines = [{
31
+ key: "wide_left",
32
+ position: {
33
+ x: -wideSpacing
34
+ }
35
+ }, {
36
+ key: "wide_right",
37
+ position: {
38
+ x: wideSpacing
39
+ }
40
+ }];
41
+ var gridGuidelines = defaultGrids.map(function (val, index) {
42
+ return {
43
+ key: "grid_".concat(index),
44
+ position: {
45
+ x: val / 12 * editorWidth
46
+ }
47
+ };
48
+ });
49
+ return [].concat(_toConsumableArray(gridGuidelines), wideGuidelines, fullWidthGuidelines);
50
+ };
@@ -1,5 +1,5 @@
1
1
  {
2
2
  "name": "@atlaskit/editor-plugin-guideline",
3
- "version": "0.2.0",
3
+ "version": "0.3.0",
4
4
  "sideEffects": false
5
5
  }
@@ -1,8 +1,10 @@
1
1
  /** @jsx jsx */
2
2
  import { jsx } from '@emotion/react';
3
- import { GuidelinePosition } from './types';
4
3
  type Props = {
5
- position: GuidelinePosition;
4
+ position: number;
5
+ active?: boolean;
6
+ show?: boolean;
7
+ style?: 'dashed' | 'solid';
6
8
  };
7
9
  export declare const Guideline: (props: Props) => jsx.JSX.Element;
8
10
  export {};
@@ -1,11 +1,11 @@
1
- /** @jsx jsx */
2
1
  import { jsx } from '@emotion/react';
3
2
  import { GuidelineConfig } from './types';
4
3
  type ContainerProps = {
5
4
  guidelines: GuidelineConfig[];
6
5
  height: number;
6
+ centerOffset: number;
7
7
  containerWidth: number;
8
8
  editorWidth: number;
9
9
  };
10
- export declare const GuidelineContainer: (props: ContainerProps) => jsx.JSX.Element | null;
10
+ export declare const GuidelineContainer: (props: ContainerProps) => jsx.JSX.Element;
11
11
  export {};
@@ -1,23 +1,10 @@
1
1
  import { EditorView } from 'prosemirror-view';
2
- type PositionValue = `${number}px` | `${number}%` | 0;
3
- type PositionSide = {
4
- left: PositionValue;
5
- right?: never;
6
- } | {
7
- right: PositionValue;
8
- left?: never;
2
+ export type Position = {
3
+ x: number;
9
4
  };
10
- export declare enum GuidelineContainerArea {
11
- EditorLeftMargin = "editorLeftMargin",
12
- EditorContent = "editorContent",
13
- EditorRightMargin = "editorRightMargin"
14
- }
15
- type GuidelinePosition = {
16
- containerArea?: GuidelineContainerArea;
17
- } & PositionSide;
18
5
  type GuidelineConfig = {
19
6
  key: string;
20
- position: GuidelinePosition;
7
+ position: Position;
21
8
  active?: boolean;
22
9
  show?: boolean;
23
10
  style?: 'dashed' | 'solid';
@@ -30,4 +17,4 @@ interface GuidelinePluginOptions {
30
17
  }
31
18
  type DisplayGrid = (props: Required<GuidelinePluginState>) => boolean;
32
19
  type DisplayGuideline = (view: EditorView) => DisplayGrid;
33
- export type { GuidelinePluginState, GuidelinePluginOptions, GuidelineConfig, GuidelinePosition, DisplayGuideline, };
20
+ export type { GuidelinePluginState, GuidelinePluginOptions, GuidelineConfig, DisplayGuideline, };
@@ -0,0 +1,10 @@
1
+ import { EditorView } from 'prosemirror-view';
2
+ import { GuidelineConfig } from './types';
3
+ /**
4
+ * This function calculates the Editor's x axis of the center point
5
+ * in relation to the viewport
6
+ * @param editorView
7
+ * @returns x axis in number
8
+ */
9
+ export declare const getEditorCenterX: (editorView: EditorView) => number;
10
+ export declare const innerGuidelines: (editorContainerWidth: number, editorWidth?: number) => GuidelineConfig[];
@@ -1,8 +1,10 @@
1
1
  /** @jsx jsx */
2
2
  import { jsx } from '@emotion/react';
3
- import { GuidelinePosition } from './types';
4
3
  type Props = {
5
- position: GuidelinePosition;
4
+ position: number;
5
+ active?: boolean;
6
+ show?: boolean;
7
+ style?: 'dashed' | 'solid';
6
8
  };
7
9
  export declare const Guideline: (props: Props) => jsx.JSX.Element;
8
10
  export {};
@@ -1,11 +1,11 @@
1
- /** @jsx jsx */
2
1
  import { jsx } from '@emotion/react';
3
2
  import { GuidelineConfig } from './types';
4
3
  type ContainerProps = {
5
4
  guidelines: GuidelineConfig[];
6
5
  height: number;
6
+ centerOffset: number;
7
7
  containerWidth: number;
8
8
  editorWidth: number;
9
9
  };
10
- export declare const GuidelineContainer: (props: ContainerProps) => jsx.JSX.Element | null;
10
+ export declare const GuidelineContainer: (props: ContainerProps) => jsx.JSX.Element;
11
11
  export {};
@@ -1,23 +1,10 @@
1
1
  import { EditorView } from 'prosemirror-view';
2
- type PositionValue = `${number}px` | `${number}%` | 0;
3
- type PositionSide = {
4
- left: PositionValue;
5
- right?: never;
6
- } | {
7
- right: PositionValue;
8
- left?: never;
2
+ export type Position = {
3
+ x: number;
9
4
  };
10
- export declare enum GuidelineContainerArea {
11
- EditorLeftMargin = "editorLeftMargin",
12
- EditorContent = "editorContent",
13
- EditorRightMargin = "editorRightMargin"
14
- }
15
- type GuidelinePosition = {
16
- containerArea?: GuidelineContainerArea;
17
- } & PositionSide;
18
5
  type GuidelineConfig = {
19
6
  key: string;
20
- position: GuidelinePosition;
7
+ position: Position;
21
8
  active?: boolean;
22
9
  show?: boolean;
23
10
  style?: 'dashed' | 'solid';
@@ -30,4 +17,4 @@ interface GuidelinePluginOptions {
30
17
  }
31
18
  type DisplayGrid = (props: Required<GuidelinePluginState>) => boolean;
32
19
  type DisplayGuideline = (view: EditorView) => DisplayGrid;
33
- export type { GuidelinePluginState, GuidelinePluginOptions, GuidelineConfig, GuidelinePosition, DisplayGuideline, };
20
+ export type { GuidelinePluginState, GuidelinePluginOptions, GuidelineConfig, DisplayGuideline, };
@@ -0,0 +1,10 @@
1
+ import { EditorView } from 'prosemirror-view';
2
+ import { GuidelineConfig } from './types';
3
+ /**
4
+ * This function calculates the Editor's x axis of the center point
5
+ * in relation to the viewport
6
+ * @param editorView
7
+ * @returns x axis in number
8
+ */
9
+ export declare const getEditorCenterX: (editorView: EditorView) => number;
10
+ export declare const innerGuidelines: (editorContainerWidth: number, editorWidth?: number) => GuidelineConfig[];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atlaskit/editor-plugin-guideline",
3
- "version": "0.2.0",
3
+ "version": "0.3.0",
4
4
  "description": "guideline plugin for @atlaskit/editor-core",
5
5
  "author": "Atlassian Pty Ltd",
6
6
  "license": "Apache-2.0",
@@ -22,7 +22,7 @@
22
22
  ".": "./src/index.ts"
23
23
  },
24
24
  "dependencies": {
25
- "@atlaskit/editor-common": "^74.3.0",
25
+ "@atlaskit/editor-common": "^74.4.0",
26
26
  "@atlaskit/editor-plugin-width": "^0.0.1",
27
27
  "@atlaskit/editor-shared-styles": "^2.4.0",
28
28
  "@atlaskit/theme": "^12.5.0",
@@ -37,7 +37,7 @@
37
37
  },
38
38
  "devDependencies": {
39
39
  "@atlaskit/docs": "*",
40
- "@atlaskit/editor-core": "^185.0.0",
40
+ "@atlaskit/editor-core": "^185.1.0",
41
41
  "@atlaskit/editor-test-helpers": "^18.5.0",
42
42
  "@atlaskit/ssr": "*",
43
43
  "@atlaskit/visual-regression": "*",
@@ -1,17 +0,0 @@
1
- "use strict";
2
-
3
- var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
- Object.defineProperty(exports, "__esModule", {
5
- value: true
6
- });
7
- exports.DEFAULT_GRIDS = void 0;
8
- var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray"));
9
- var DEFAULT_GRIDS = (0, _toConsumableArray2.default)(Array(13).keys()).map(function (index) {
10
- return {
11
- key: "grid_".concat(index),
12
- position: {
13
- left: "".concat(index * 100 / 12, "%")
14
- }
15
- };
16
- });
17
- exports.DEFAULT_GRIDS = DEFAULT_GRIDS;
@@ -1,6 +0,0 @@
1
- export const DEFAULT_GRIDS = [...Array(13).keys()].map(index => ({
2
- key: `grid_${index}`,
3
- position: {
4
- left: `${index * 100 / 12}%`
5
- }
6
- }));
@@ -1,9 +0,0 @@
1
- import _toConsumableArray from "@babel/runtime/helpers/toConsumableArray";
2
- export var DEFAULT_GRIDS = _toConsumableArray(Array(13).keys()).map(function (index) {
3
- return {
4
- key: "grid_".concat(index),
5
- position: {
6
- left: "".concat(index * 100 / 12, "%")
7
- }
8
- };
9
- });
@@ -1,2 +0,0 @@
1
- import { GuidelineConfig } from './types';
2
- export declare const DEFAULT_GRIDS: GuidelineConfig[];
@@ -1,2 +0,0 @@
1
- import { GuidelineConfig } from './types';
2
- export declare const DEFAULT_GRIDS: GuidelineConfig[];