@atlaskit/editor-plugin-guideline 0.1.0 → 0.2.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 +1,12 @@
1
1
  # @atlaskit/editor-plugin-guideline
2
+
3
+ ## 0.2.0
4
+
5
+ ### Minor Changes
6
+
7
+ - [`d8f19b90c43`](https://bitbucket.org/atlassian/atlassian-frontend/commits/d8f19b90c43) - COLLAB-2622 Update editor-plugin-guideline to support position config.
8
+
9
+ ### Patch Changes
10
+
11
+ - [`2625e4baea0`](https://bitbucket.org/atlassian/atlassian-frontend/commits/2625e4baea0) - COLLAB-2622 Setup React components for future works.
12
+ - Updated dependencies
@@ -0,0 +1,17 @@
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;
@@ -0,0 +1,34 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.Guideline = void 0;
7
+ var _react = require("@emotion/react");
8
+ var _colors = require("@atlaskit/theme/colors");
9
+ /** @jsx jsx */
10
+
11
+ var BasicGuidelineStyles = (0, _react.css)({
12
+ borderLeft: "1px solid ".concat("var(--ds-border, ".concat(_colors.N30A, ")")),
13
+ position: 'absolute',
14
+ width: '1px',
15
+ height: '100%',
16
+ zIndex: 0,
17
+ transition: 'border-color 0.15s linear'
18
+ });
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
+ var Guideline = function Guideline(props) {
29
+ return (0, _react.jsx)("div", {
30
+ css: BasicGuidelineStyles,
31
+ style: positionToStyle(props.position)
32
+ });
33
+ };
34
+ exports.Guideline = Guideline;
@@ -0,0 +1,73 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
+ Object.defineProperty(exports, "__esModule", {
5
+ value: true
6
+ });
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");
11
+ var _editorSharedStyles = require("@atlaskit/editor-shared-styles");
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)({
17
+ position: 'fixed',
18
+ height: '100vh',
19
+ width: '100%',
20
+ display: 'grid',
21
+ pointerEvents: 'none',
22
+ border: 'none',
23
+ maxWidth: "".concat(_editorSharedStyles.akEditorFullWidthLayoutWidth, "px")
24
+ });
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
+ var GuidelineContainer = function GuidelineContainer(props) {
48
+ var guidelines = props.guidelines,
49
+ 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", {
56
+ css: guidelineContainerStyles,
57
+ style: {
58
+ height: height,
59
+ gridTemplateColumns: "[left] auto [editor] ".concat(editorWidth, "px [right] auto")
60
+ },
61
+ "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]
71
+ }));
72
+ };
73
+ exports.GuidelineContainer = GuidelineContainer;
@@ -1,19 +1,41 @@
1
1
  "use strict";
2
2
 
3
- var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
3
  Object.defineProperty(exports, "__esModule", {
5
4
  value: true
6
5
  });
7
- exports.guidelinePlugin = void 0;
8
- var _react = _interopRequireDefault(require("react"));
6
+ exports.guidelinePlugin = exports.EMPTY_STATE = void 0;
7
+ var _react = require("@emotion/react");
9
8
  var _prosemirrorState = require("prosemirror-state");
10
9
  var _hooks = require("@atlaskit/editor-common/hooks");
11
10
  var _safePlugin = require("@atlaskit/editor-common/safe-plugin");
11
+ var _editorSharedStyles = require("@atlaskit/editor-shared-styles");
12
+ var _guildelineContainer = require("./guildelineContainer");
13
+ /** @jsx jsx */
14
+
15
+ var guidelineStyles = (0, _react.css)({
16
+ position: 'absolute',
17
+ width: '100%',
18
+ left: 0,
19
+ right: 0,
20
+ transform: "scale(1)",
21
+ zIndex: "".concat(_editorSharedStyles.akEditorGridLineZIndex, ";"),
22
+ display: 'flex',
23
+ justifyContent: 'center'
24
+ });
12
25
  var key = new _prosemirrorState.PluginKey('guidelinePlugin');
13
- var displayGuideline = function displayGuideline(_view) {};
26
+ var displayGuideline = function displayGuideline(view) {
27
+ return function (props) {
28
+ var dispatch = view.dispatch,
29
+ state = view.state;
30
+ var tr = state.tr.setMeta(key, props);
31
+ dispatch(tr);
32
+ return true;
33
+ };
34
+ };
14
35
  var EMPTY_STATE = {
15
36
  guidelines: []
16
37
  };
38
+ exports.EMPTY_STATE = EMPTY_STATE;
17
39
  var guidelinePMPlugin = new _safePlugin.SafePlugin({
18
40
  key: key,
19
41
  state: {
@@ -36,10 +58,17 @@ var ContentComponent = function ContentComponent(_ref) {
36
58
  var _useSharedPluginState = (0, _hooks.useSharedPluginState)(api, ['width', 'guideline']),
37
59
  widthState = _useSharedPluginState.widthState,
38
60
  guidelineState = _useSharedPluginState.guidelineState;
39
- if (!guidelineState || !widthState) {
61
+ if (!widthState || !widthState.containerWidth || !widthState.lineLength || !guidelineState || !guidelineState.guidelines || guidelineState.guidelines.length === 0) {
40
62
  return null;
41
63
  }
42
- return /*#__PURE__*/_react.default.createElement("div", null);
64
+ return (0, _react.jsx)("div", {
65
+ css: guidelineStyles
66
+ }, (0, _react.jsx)(_guildelineContainer.GuidelineContainer, {
67
+ guidelines: guidelineState.guidelines,
68
+ height: editorView.dom.scrollHeight,
69
+ containerWidth: widthState.containerWidth,
70
+ editorWidth: widthState.lineLength
71
+ }));
43
72
  };
44
73
  var guidelinePlugin = function guidelinePlugin(options, api) {
45
74
  return {
@@ -63,7 +92,7 @@ var guidelinePlugin = function guidelinePlugin(options, api) {
63
92
  },
64
93
  contentComponent: function contentComponent(_ref2) {
65
94
  var editorView = _ref2.editorView;
66
- return /*#__PURE__*/_react.default.createElement(ContentComponent, {
95
+ return (0, _react.jsx)(ContentComponent, {
67
96
  editorView: editorView,
68
97
  options: options,
69
98
  api: api
package/dist/cjs/types.js CHANGED
@@ -2,4 +2,12 @@
2
2
 
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
- });
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;
@@ -1,5 +1,5 @@
1
1
  {
2
2
  "name": "@atlaskit/editor-plugin-guideline",
3
- "version": "0.1.0",
3
+ "version": "0.2.0",
4
4
  "sideEffects": false
5
5
  }
@@ -0,0 +1,6 @@
1
+ export const DEFAULT_GRIDS = [...Array(13).keys()].map(index => ({
2
+ key: `grid_${index}`,
3
+ position: {
4
+ left: `${index * 100 / 12}%`
5
+ }
6
+ }));
@@ -0,0 +1,26 @@
1
+ /** @jsx jsx */
2
+ import { css, jsx } from '@emotion/react';
3
+ import { N30A } from '@atlaskit/theme/colors';
4
+ const BasicGuidelineStyles = css({
5
+ borderLeft: `1px solid ${`var(--ds-border, ${N30A})`}`,
6
+ position: 'absolute',
7
+ width: '1px',
8
+ height: '100%',
9
+ zIndex: 0,
10
+ transition: 'border-color 0.15s linear'
11
+ });
12
+ const positionToStyle = position => {
13
+ 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
+ });
@@ -0,0 +1,64 @@
1
+ /** @jsx jsx */
2
+ import { css, jsx } from '@emotion/react';
3
+ import { akEditorFullWidthLayoutWidth } from '@atlaskit/editor-shared-styles';
4
+ import { Guideline } from './guideline';
5
+ import { GuidelineContainerArea as Areas } from './types';
6
+ const guidelineContainerStyles = css({
7
+ position: 'fixed',
8
+ height: '100vh',
9
+ width: '100%',
10
+ display: 'grid',
11
+ pointerEvents: 'none',
12
+ border: 'none',
13
+ maxWidth: `${akEditorFullWidthLayoutWidth}px`
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
+ export const GuidelineContainer = props => {
38
+ const {
39
+ guidelines,
40
+ height,
41
+ editorWidth
42
+ } = props;
43
+ if (guidelines.length === 0) {
44
+ return null;
45
+ }
46
+ const guidelineGroups = groupGuidelines(guidelines);
47
+ return jsx("div", {
48
+ css: guidelineContainerStyles,
49
+ style: {
50
+ height,
51
+ gridTemplateColumns: `[left] auto [editor] ${editorWidth}px [right] auto`
52
+ },
53
+ "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]
63
+ }));
64
+ };
@@ -1,10 +1,31 @@
1
- import React from 'react';
1
+ /** @jsx jsx */
2
+ import { css, jsx } from '@emotion/react';
2
3
  import { PluginKey } from 'prosemirror-state';
3
4
  import { useSharedPluginState } from '@atlaskit/editor-common/hooks';
4
5
  import { SafePlugin } from '@atlaskit/editor-common/safe-plugin';
6
+ import { akEditorGridLineZIndex } from '@atlaskit/editor-shared-styles';
7
+ import { GuidelineContainer } from './guildelineContainer';
8
+ const guidelineStyles = css({
9
+ position: 'absolute',
10
+ width: '100%',
11
+ left: 0,
12
+ right: 0,
13
+ transform: `scale(1)`,
14
+ zIndex: `${akEditorGridLineZIndex};`,
15
+ display: 'flex',
16
+ justifyContent: 'center'
17
+ });
5
18
  const key = new PluginKey('guidelinePlugin');
6
- const displayGuideline = _view => {};
7
- const EMPTY_STATE = {
19
+ const displayGuideline = view => props => {
20
+ const {
21
+ dispatch,
22
+ state
23
+ } = view;
24
+ const tr = state.tr.setMeta(key, props);
25
+ dispatch(tr);
26
+ return true;
27
+ };
28
+ export const EMPTY_STATE = {
8
29
  guidelines: []
9
30
  };
10
31
  const guidelinePMPlugin = new SafePlugin({
@@ -31,10 +52,17 @@ const ContentComponent = ({
31
52
  widthState,
32
53
  guidelineState
33
54
  } = useSharedPluginState(api, ['width', 'guideline']);
34
- if (!guidelineState || !widthState) {
55
+ if (!widthState || !widthState.containerWidth || !widthState.lineLength || !guidelineState || !guidelineState.guidelines || guidelineState.guidelines.length === 0) {
35
56
  return null;
36
57
  }
37
- return /*#__PURE__*/React.createElement("div", null);
58
+ return jsx("div", {
59
+ css: guidelineStyles
60
+ }, jsx(GuidelineContainer, {
61
+ guidelines: guidelineState.guidelines,
62
+ height: editorView.dom.scrollHeight,
63
+ containerWidth: widthState.containerWidth,
64
+ editorWidth: widthState.lineLength
65
+ }));
38
66
  };
39
67
  export const guidelinePlugin = (options, api) => ({
40
68
  name: 'guideline',
@@ -55,7 +83,7 @@ export const guidelinePlugin = (options, api) => ({
55
83
  },
56
84
  contentComponent: ({
57
85
  editorView
58
- }) => /*#__PURE__*/React.createElement(ContentComponent, {
86
+ }) => jsx(ContentComponent, {
59
87
  editorView: editorView,
60
88
  options: options,
61
89
  api: api
@@ -1 +1,6 @@
1
- export {};
1
+ export let GuidelineContainerArea = /*#__PURE__*/function (GuidelineContainerArea) {
2
+ GuidelineContainerArea["EditorLeftMargin"] = "editorLeftMargin";
3
+ GuidelineContainerArea["EditorContent"] = "editorContent";
4
+ GuidelineContainerArea["EditorRightMargin"] = "editorRightMargin";
5
+ return GuidelineContainerArea;
6
+ }({});
@@ -1,5 +1,5 @@
1
1
  {
2
2
  "name": "@atlaskit/editor-plugin-guideline",
3
- "version": "0.1.0",
3
+ "version": "0.2.0",
4
4
  "sideEffects": false
5
5
  }
@@ -0,0 +1,9 @@
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
+ });
@@ -0,0 +1,26 @@
1
+ /** @jsx jsx */
2
+ import { css, jsx } from '@emotion/react';
3
+ import { N30A } from '@atlaskit/theme/colors';
4
+ var BasicGuidelineStyles = css({
5
+ borderLeft: "1px solid ".concat("var(--ds-border, ".concat(N30A, ")")),
6
+ position: 'absolute',
7
+ width: '1px',
8
+ height: '100%',
9
+ zIndex: 0,
10
+ transition: 'border-color 0.15s linear'
11
+ });
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
+ export var Guideline = function Guideline(props) {
22
+ return jsx("div", {
23
+ css: BasicGuidelineStyles,
24
+ style: positionToStyle(props.position)
25
+ });
26
+ };
@@ -0,0 +1,66 @@
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; }
5
+ /** @jsx jsx */
6
+ import { css, jsx } from '@emotion/react';
7
+ import { akEditorFullWidthLayoutWidth } from '@atlaskit/editor-shared-styles';
8
+ import { Guideline } from './guideline';
9
+ import { GuidelineContainerArea as Areas } from './types';
10
+ var guidelineContainerStyles = css({
11
+ position: 'fixed',
12
+ height: '100vh',
13
+ width: '100%',
14
+ display: 'grid',
15
+ pointerEvents: 'none',
16
+ border: 'none',
17
+ maxWidth: "".concat(akEditorFullWidthLayoutWidth, "px")
18
+ });
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
+ export var GuidelineContainer = function GuidelineContainer(props) {
42
+ var guidelines = props.guidelines,
43
+ height = props.height,
44
+ editorWidth = props.editorWidth;
45
+ if (guidelines.length === 0) {
46
+ return null;
47
+ }
48
+ var guidelineGroups = groupGuidelines(guidelines);
49
+ return jsx("div", {
50
+ css: guidelineContainerStyles,
51
+ style: {
52
+ height: height,
53
+ gridTemplateColumns: "[left] auto [editor] ".concat(editorWidth, "px [right] auto")
54
+ },
55
+ "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]
65
+ }));
66
+ };
@@ -1,10 +1,31 @@
1
- import React from 'react';
1
+ /** @jsx jsx */
2
+ import { css, jsx } from '@emotion/react';
2
3
  import { PluginKey } from 'prosemirror-state';
3
4
  import { useSharedPluginState } from '@atlaskit/editor-common/hooks';
4
5
  import { SafePlugin } from '@atlaskit/editor-common/safe-plugin';
6
+ import { akEditorGridLineZIndex } from '@atlaskit/editor-shared-styles';
7
+ import { GuidelineContainer } from './guildelineContainer';
8
+ var guidelineStyles = css({
9
+ position: 'absolute',
10
+ width: '100%',
11
+ left: 0,
12
+ right: 0,
13
+ transform: "scale(1)",
14
+ zIndex: "".concat(akEditorGridLineZIndex, ";"),
15
+ display: 'flex',
16
+ justifyContent: 'center'
17
+ });
5
18
  var key = new PluginKey('guidelinePlugin');
6
- var displayGuideline = function displayGuideline(_view) {};
7
- var EMPTY_STATE = {
19
+ var displayGuideline = function displayGuideline(view) {
20
+ return function (props) {
21
+ var dispatch = view.dispatch,
22
+ state = view.state;
23
+ var tr = state.tr.setMeta(key, props);
24
+ dispatch(tr);
25
+ return true;
26
+ };
27
+ };
28
+ export var EMPTY_STATE = {
8
29
  guidelines: []
9
30
  };
10
31
  var guidelinePMPlugin = new SafePlugin({
@@ -29,10 +50,17 @@ var ContentComponent = function ContentComponent(_ref) {
29
50
  var _useSharedPluginState = useSharedPluginState(api, ['width', 'guideline']),
30
51
  widthState = _useSharedPluginState.widthState,
31
52
  guidelineState = _useSharedPluginState.guidelineState;
32
- if (!guidelineState || !widthState) {
53
+ if (!widthState || !widthState.containerWidth || !widthState.lineLength || !guidelineState || !guidelineState.guidelines || guidelineState.guidelines.length === 0) {
33
54
  return null;
34
55
  }
35
- return /*#__PURE__*/React.createElement("div", null);
56
+ return jsx("div", {
57
+ css: guidelineStyles
58
+ }, jsx(GuidelineContainer, {
59
+ guidelines: guidelineState.guidelines,
60
+ height: editorView.dom.scrollHeight,
61
+ containerWidth: widthState.containerWidth,
62
+ editorWidth: widthState.lineLength
63
+ }));
36
64
  };
37
65
  export var guidelinePlugin = function guidelinePlugin(options, api) {
38
66
  return {
@@ -56,7 +84,7 @@ export var guidelinePlugin = function guidelinePlugin(options, api) {
56
84
  },
57
85
  contentComponent: function contentComponent(_ref2) {
58
86
  var editorView = _ref2.editorView;
59
- return /*#__PURE__*/React.createElement(ContentComponent, {
87
+ return jsx(ContentComponent, {
60
88
  editorView: editorView,
61
89
  options: options,
62
90
  api: api
package/dist/esm/types.js CHANGED
@@ -1 +1,6 @@
1
- export {};
1
+ export var GuidelineContainerArea = /*#__PURE__*/function (GuidelineContainerArea) {
2
+ GuidelineContainerArea["EditorLeftMargin"] = "editorLeftMargin";
3
+ GuidelineContainerArea["EditorContent"] = "editorContent";
4
+ GuidelineContainerArea["EditorRightMargin"] = "editorRightMargin";
5
+ return GuidelineContainerArea;
6
+ }({});
@@ -1,5 +1,5 @@
1
1
  {
2
2
  "name": "@atlaskit/editor-plugin-guideline",
3
- "version": "0.1.0",
3
+ "version": "0.2.0",
4
4
  "sideEffects": false
5
5
  }
@@ -0,0 +1,2 @@
1
+ import { GuidelineConfig } from './types';
2
+ export declare const DEFAULT_GRIDS: GuidelineConfig[];
@@ -0,0 +1,8 @@
1
+ /** @jsx jsx */
2
+ import { jsx } from '@emotion/react';
3
+ import { GuidelinePosition } from './types';
4
+ type Props = {
5
+ position: GuidelinePosition;
6
+ };
7
+ export declare const Guideline: (props: Props) => jsx.JSX.Element;
8
+ export {};
@@ -0,0 +1,11 @@
1
+ /** @jsx jsx */
2
+ import { jsx } from '@emotion/react';
3
+ import { GuidelineConfig } from './types';
4
+ type ContainerProps = {
5
+ guidelines: GuidelineConfig[];
6
+ height: number;
7
+ containerWidth: number;
8
+ editorWidth: number;
9
+ };
10
+ export declare const GuidelineContainer: (props: ContainerProps) => jsx.JSX.Element | null;
11
+ export {};
@@ -1 +1,2 @@
1
1
  export { guidelinePlugin } from './plugin';
2
+ export type { GuidelineConfig } from './types';
@@ -1,6 +1,7 @@
1
1
  import { NextEditorPlugin } from '@atlaskit/editor-common/types';
2
2
  import type { widthPlugin } from '@atlaskit/editor-plugin-width';
3
3
  import { DisplayGuideline, GuidelinePluginState } from './types';
4
+ export declare const EMPTY_STATE: GuidelinePluginState;
4
5
  export declare const guidelinePlugin: NextEditorPlugin<'guideline', {
5
6
  dependencies: [typeof widthPlugin];
6
7
  sharedState: GuidelinePluginState | null;
@@ -1,15 +1,33 @@
1
1
  import { EditorView } from 'prosemirror-view';
2
- type Guideline = {
3
- key?: string;
2
+ type PositionValue = `${number}px` | `${number}%` | 0;
3
+ type PositionSide = {
4
+ left: PositionValue;
5
+ right?: never;
6
+ } | {
7
+ right: PositionValue;
8
+ left?: never;
9
+ };
10
+ export declare enum GuidelineContainerArea {
11
+ EditorLeftMargin = "editorLeftMargin",
12
+ EditorContent = "editorContent",
13
+ EditorRightMargin = "editorRightMargin"
14
+ }
15
+ type GuidelinePosition = {
16
+ containerArea?: GuidelineContainerArea;
17
+ } & PositionSide;
18
+ type GuidelineConfig = {
19
+ key: string;
20
+ position: GuidelinePosition;
4
21
  active?: boolean;
5
22
  show?: boolean;
6
23
  style?: 'dashed' | 'solid';
7
24
  color?: string;
8
25
  };
9
26
  type GuidelinePluginState = {
10
- guidelines: Guideline[];
27
+ guidelines: GuidelineConfig[];
11
28
  };
12
29
  interface GuidelinePluginOptions {
13
30
  }
14
- type DisplayGuideline = (view: EditorView) => void;
15
- export type { GuidelinePluginState, GuidelinePluginOptions, Guideline, DisplayGuideline, };
31
+ type DisplayGrid = (props: Required<GuidelinePluginState>) => boolean;
32
+ type DisplayGuideline = (view: EditorView) => DisplayGrid;
33
+ export type { GuidelinePluginState, GuidelinePluginOptions, GuidelineConfig, GuidelinePosition, DisplayGuideline, };
@@ -0,0 +1,2 @@
1
+ import { GuidelineConfig } from './types';
2
+ export declare const DEFAULT_GRIDS: GuidelineConfig[];
@@ -0,0 +1,8 @@
1
+ /** @jsx jsx */
2
+ import { jsx } from '@emotion/react';
3
+ import { GuidelinePosition } from './types';
4
+ type Props = {
5
+ position: GuidelinePosition;
6
+ };
7
+ export declare const Guideline: (props: Props) => jsx.JSX.Element;
8
+ export {};
@@ -0,0 +1,11 @@
1
+ /** @jsx jsx */
2
+ import { jsx } from '@emotion/react';
3
+ import { GuidelineConfig } from './types';
4
+ type ContainerProps = {
5
+ guidelines: GuidelineConfig[];
6
+ height: number;
7
+ containerWidth: number;
8
+ editorWidth: number;
9
+ };
10
+ export declare const GuidelineContainer: (props: ContainerProps) => jsx.JSX.Element | null;
11
+ export {};
@@ -1 +1,2 @@
1
1
  export { guidelinePlugin } from './plugin';
2
+ export type { GuidelineConfig } from './types';
@@ -1,6 +1,7 @@
1
1
  import { NextEditorPlugin } from '@atlaskit/editor-common/types';
2
2
  import type { widthPlugin } from '@atlaskit/editor-plugin-width';
3
3
  import { DisplayGuideline, GuidelinePluginState } from './types';
4
+ export declare const EMPTY_STATE: GuidelinePluginState;
4
5
  export declare const guidelinePlugin: NextEditorPlugin<'guideline', {
5
6
  dependencies: [
6
7
  typeof widthPlugin
@@ -1,15 +1,33 @@
1
1
  import { EditorView } from 'prosemirror-view';
2
- type Guideline = {
3
- key?: string;
2
+ type PositionValue = `${number}px` | `${number}%` | 0;
3
+ type PositionSide = {
4
+ left: PositionValue;
5
+ right?: never;
6
+ } | {
7
+ right: PositionValue;
8
+ left?: never;
9
+ };
10
+ export declare enum GuidelineContainerArea {
11
+ EditorLeftMargin = "editorLeftMargin",
12
+ EditorContent = "editorContent",
13
+ EditorRightMargin = "editorRightMargin"
14
+ }
15
+ type GuidelinePosition = {
16
+ containerArea?: GuidelineContainerArea;
17
+ } & PositionSide;
18
+ type GuidelineConfig = {
19
+ key: string;
20
+ position: GuidelinePosition;
4
21
  active?: boolean;
5
22
  show?: boolean;
6
23
  style?: 'dashed' | 'solid';
7
24
  color?: string;
8
25
  };
9
26
  type GuidelinePluginState = {
10
- guidelines: Guideline[];
27
+ guidelines: GuidelineConfig[];
11
28
  };
12
29
  interface GuidelinePluginOptions {
13
30
  }
14
- type DisplayGuideline = (view: EditorView) => void;
15
- export type { GuidelinePluginState, GuidelinePluginOptions, Guideline, DisplayGuideline, };
31
+ type DisplayGrid = (props: Required<GuidelinePluginState>) => boolean;
32
+ type DisplayGuideline = (view: EditorView) => DisplayGrid;
33
+ export type { GuidelinePluginState, GuidelinePluginOptions, GuidelineConfig, GuidelinePosition, DisplayGuideline, };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atlaskit/editor-plugin-guideline",
3
- "version": "0.1.0",
3
+ "version": "0.2.0",
4
4
  "description": "guideline plugin for @atlaskit/editor-core",
5
5
  "author": "Atlassian Pty Ltd",
6
6
  "license": "Apache-2.0",
@@ -22,9 +22,13 @@
22
22
  ".": "./src/index.ts"
23
23
  },
24
24
  "dependencies": {
25
- "@atlaskit/editor-common": "^74.2.0",
25
+ "@atlaskit/editor-common": "^74.3.0",
26
26
  "@atlaskit/editor-plugin-width": "^0.0.1",
27
+ "@atlaskit/editor-shared-styles": "^2.4.0",
28
+ "@atlaskit/theme": "^12.5.0",
29
+ "@atlaskit/tokens": "^1.4.2",
27
30
  "@babel/runtime": "^7.0.0",
31
+ "@emotion/react": "^11.7.1",
28
32
  "prosemirror-state": "1.3.4",
29
33
  "prosemirror-view": "1.23.7"
30
34
  },
@@ -33,8 +37,8 @@
33
37
  },
34
38
  "devDependencies": {
35
39
  "@atlaskit/docs": "*",
36
- "@atlaskit/editor-core": "^184.0.0",
37
- "@atlaskit/editor-test-helpers": "^18.2.0",
40
+ "@atlaskit/editor-core": "^185.0.0",
41
+ "@atlaskit/editor-test-helpers": "^18.5.0",
38
42
  "@atlaskit/ssr": "*",
39
43
  "@atlaskit/visual-regression": "*",
40
44
  "@atlaskit/webdriver-runner": "*",
package/report.api.md CHANGED
@@ -20,17 +20,31 @@ import { NextEditorPlugin } from '@atlaskit/editor-common/types';
20
20
  import type { widthPlugin } from '@atlaskit/editor-plugin-width';
21
21
 
22
22
  // @public (undocumented)
23
- type DisplayGuideline = (view: EditorView) => void;
23
+ type DisplayGrid = (props: Required<GuidelinePluginState>) => boolean;
24
24
 
25
25
  // @public (undocumented)
26
- type Guideline = {
27
- key?: string;
26
+ type DisplayGuideline = (view: EditorView) => DisplayGrid;
27
+
28
+ // @public (undocumented)
29
+ export type GuidelineConfig = {
30
+ key: string;
31
+ position: GuidelinePosition;
28
32
  active?: boolean;
29
33
  show?: boolean;
30
34
  style?: 'dashed' | 'solid';
31
35
  color?: string;
32
36
  };
33
37
 
38
+ // @public (undocumented)
39
+ enum GuidelineContainerArea {
40
+ // (undocumented)
41
+ EditorContent = 'editorContent',
42
+ // (undocumented)
43
+ EditorLeftMargin = 'editorLeftMargin',
44
+ // (undocumented)
45
+ EditorRightMargin = 'editorRightMargin',
46
+ }
47
+
34
48
  // @public (undocumented)
35
49
  export const guidelinePlugin: NextEditorPlugin<
36
50
  'guideline',
@@ -45,9 +59,28 @@ export const guidelinePlugin: NextEditorPlugin<
45
59
 
46
60
  // @public (undocumented)
47
61
  type GuidelinePluginState = {
48
- guidelines: Guideline[];
62
+ guidelines: GuidelineConfig[];
49
63
  };
50
64
 
65
+ // @public (undocumented)
66
+ type GuidelinePosition = {
67
+ containerArea?: GuidelineContainerArea;
68
+ } & PositionSide;
69
+
70
+ // @public (undocumented)
71
+ type PositionSide =
72
+ | {
73
+ left: PositionValue;
74
+ right?: never;
75
+ }
76
+ | {
77
+ right: PositionValue;
78
+ left?: never;
79
+ };
80
+
81
+ // @public (undocumented)
82
+ type PositionValue = 0 | `${number}%` | `${number}px`;
83
+
51
84
  // (No @packageDocumentation comment for this package)
52
85
  ```
53
86