@atlaskit/editor-plugin-grid 0.1.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 +1 -0
- package/LICENSE.md +13 -0
- package/README.md +7 -0
- package/dist/cjs/index.js +12 -0
- package/dist/cjs/plugin.js +176 -0
- package/dist/cjs/types.js +5 -0
- package/dist/cjs/version.json +5 -0
- package/dist/es2019/index.js +1 -0
- package/dist/es2019/plugin.js +163 -0
- package/dist/es2019/types.js +1 -0
- package/dist/es2019/version.json +5 -0
- package/dist/esm/index.js +1 -0
- package/dist/esm/plugin.js +167 -0
- package/dist/esm/types.js +1 -0
- package/dist/esm/version.json +5 -0
- package/dist/types/index.d.ts +2 -0
- package/dist/types/plugin.d.ts +22 -0
- package/dist/types/types.d.ts +8 -0
- package/dist/types-ts4.5/index.d.ts +2 -0
- package/dist/types-ts4.5/plugin.d.ts +24 -0
- package/dist/types-ts4.5/types.d.ts +8 -0
- package/package.json +83 -0
- package/report.api.md +78 -0
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
# @atlaskit/editor-plugin-grid
|
package/LICENSE.md
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
Copyright 2023 Atlassian Pty Ltd
|
|
2
|
+
|
|
3
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
|
+
you may not use this file except in compliance with the License.
|
|
5
|
+
You may obtain a copy of the License at
|
|
6
|
+
|
|
7
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
+
|
|
9
|
+
Unless required by applicable law or agreed to in writing, software
|
|
10
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
11
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12
|
+
See the License for the specific language governing permissions and
|
|
13
|
+
limitations under the License.
|
package/README.md
ADDED
|
@@ -0,0 +1,176 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
+
Object.defineProperty(exports, "__esModule", {
|
|
5
|
+
value: true
|
|
6
|
+
});
|
|
7
|
+
exports.gridPlugin = exports.GRID_SIZE = void 0;
|
|
8
|
+
var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray"));
|
|
9
|
+
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
10
|
+
var _react = _interopRequireDefault(require("react"));
|
|
11
|
+
var _react2 = require("@emotion/react");
|
|
12
|
+
var _classnames = _interopRequireDefault(require("classnames"));
|
|
13
|
+
var _prosemirrorState = require("prosemirror-state");
|
|
14
|
+
var _hooks = require("@atlaskit/editor-common/hooks");
|
|
15
|
+
var _safePlugin = require("@atlaskit/editor-common/safe-plugin");
|
|
16
|
+
var _editorSharedStyles = require("@atlaskit/editor-shared-styles");
|
|
17
|
+
var GRID_SIZE = 12;
|
|
18
|
+
exports.GRID_SIZE = GRID_SIZE;
|
|
19
|
+
var key = new _prosemirrorState.PluginKey('gridPlugin');
|
|
20
|
+
var createDisplayGrid = function createDisplayGrid(view) {
|
|
21
|
+
return function (props) {
|
|
22
|
+
var dispatch = view.dispatch,
|
|
23
|
+
state = view.state;
|
|
24
|
+
var tr = state.tr.setMeta(key, props);
|
|
25
|
+
dispatch(tr);
|
|
26
|
+
return true;
|
|
27
|
+
};
|
|
28
|
+
};
|
|
29
|
+
var sides = ['left', 'right'];
|
|
30
|
+
var overflowHighlight = function overflowHighlight(highlights, side, start, size) {
|
|
31
|
+
if (!highlights.length) {
|
|
32
|
+
return false;
|
|
33
|
+
}
|
|
34
|
+
var minHighlight = highlights.reduce(function (prev, cur) {
|
|
35
|
+
return Math.min(prev, cur);
|
|
36
|
+
});
|
|
37
|
+
var maxHighlight = highlights.reduce(function (prev, cur) {
|
|
38
|
+
return Math.max(prev, cur);
|
|
39
|
+
});
|
|
40
|
+
if (side === 'left') {
|
|
41
|
+
return minHighlight < 0 && minHighlight <= -start && (typeof size === 'number' ? minHighlight >= -(start + size) : true);
|
|
42
|
+
} else {
|
|
43
|
+
return maxHighlight > GRID_SIZE && maxHighlight >= GRID_SIZE + start && (typeof size === 'number' ? maxHighlight <= GRID_SIZE + size : true);
|
|
44
|
+
}
|
|
45
|
+
};
|
|
46
|
+
var gutterGridLines = function gutterGridLines(editorMaxWidth, editorWidth, highlights, shouldCalcBreakoutGridLines) {
|
|
47
|
+
var gridLines = [];
|
|
48
|
+
if (!shouldCalcBreakoutGridLines) {
|
|
49
|
+
return gridLines;
|
|
50
|
+
}
|
|
51
|
+
var wideSpacing = (editorMaxWidth * _editorSharedStyles.breakoutWideScaleRatio - editorMaxWidth) / 2;
|
|
52
|
+
sides.forEach(function (side) {
|
|
53
|
+
gridLines.push( /*#__PURE__*/_react.default.createElement("div", {
|
|
54
|
+
key: side,
|
|
55
|
+
className: (0, _classnames.default)('gridLine', overflowHighlight(highlights, side, 0, 4) ? 'highlight' : ''),
|
|
56
|
+
style: (0, _defineProperty2.default)({
|
|
57
|
+
position: 'absolute'
|
|
58
|
+
}, side, "-".concat(wideSpacing, "px"))
|
|
59
|
+
}));
|
|
60
|
+
gridLines.push( /*#__PURE__*/_react.default.createElement("div", {
|
|
61
|
+
key: side + '-bk',
|
|
62
|
+
className: (0, _classnames.default)('gridLine', highlights.indexOf('full-width') > -1 ? 'highlight' : ''),
|
|
63
|
+
style: (0, _defineProperty2.default)({
|
|
64
|
+
position: 'absolute'
|
|
65
|
+
}, side, "-".concat((editorWidth - editorMaxWidth - _editorSharedStyles.akEditorBreakoutPadding) / 2, "px"))
|
|
66
|
+
}));
|
|
67
|
+
});
|
|
68
|
+
return gridLines;
|
|
69
|
+
};
|
|
70
|
+
var lineLengthGridLines = function lineLengthGridLines(highlights) {
|
|
71
|
+
var gridLines = [];
|
|
72
|
+
var gridSpacing = 100 / GRID_SIZE;
|
|
73
|
+
for (var i = 0; i <= GRID_SIZE; i++) {
|
|
74
|
+
var style = {
|
|
75
|
+
paddingLeft: "".concat(gridSpacing, "%")
|
|
76
|
+
};
|
|
77
|
+
gridLines.push( /*#__PURE__*/_react.default.createElement("div", {
|
|
78
|
+
key: i,
|
|
79
|
+
className: (0, _classnames.default)('gridLine', highlights.indexOf(i) > -1 ? 'highlight' : ''),
|
|
80
|
+
style: i < GRID_SIZE ? style : undefined
|
|
81
|
+
}));
|
|
82
|
+
}
|
|
83
|
+
return gridLines;
|
|
84
|
+
};
|
|
85
|
+
var Grid = function Grid(_ref3) {
|
|
86
|
+
var highlight = _ref3.highlight,
|
|
87
|
+
shouldCalcBreakoutGridLines = _ref3.shouldCalcBreakoutGridLines,
|
|
88
|
+
theme = _ref3.theme,
|
|
89
|
+
containerElement = _ref3.containerElement,
|
|
90
|
+
editorWidth = _ref3.editorWidth,
|
|
91
|
+
gridType = _ref3.gridType,
|
|
92
|
+
visible = _ref3.visible;
|
|
93
|
+
var editorMaxWidth = theme.layoutMaxWidth;
|
|
94
|
+
var gridLines = [].concat((0, _toConsumableArray2.default)(lineLengthGridLines(highlight)), (0, _toConsumableArray2.default)(gutterGridLines(editorMaxWidth, editorWidth, highlight, shouldCalcBreakoutGridLines)));
|
|
95
|
+
return /*#__PURE__*/_react.default.createElement("div", {
|
|
96
|
+
className: "gridParent"
|
|
97
|
+
}, /*#__PURE__*/_react.default.createElement("div", {
|
|
98
|
+
className: (0, _classnames.default)('gridContainer', gridType),
|
|
99
|
+
style: {
|
|
100
|
+
height: "".concat(containerElement.scrollHeight, "px"),
|
|
101
|
+
display: visible ? 'block' : 'none'
|
|
102
|
+
},
|
|
103
|
+
"data-testid": "gridContainer"
|
|
104
|
+
}, gridLines));
|
|
105
|
+
};
|
|
106
|
+
var ThemedGrid = (0, _react2.withTheme)(Grid);
|
|
107
|
+
var ContentComponent = function ContentComponent(_ref4) {
|
|
108
|
+
var _widthState$width, _gridState$gridType;
|
|
109
|
+
var api = _ref4.api,
|
|
110
|
+
editorView = _ref4.editorView,
|
|
111
|
+
options = _ref4.options;
|
|
112
|
+
var _useSharedPluginState = (0, _hooks.useSharedPluginState)(api, ['width', 'grid']),
|
|
113
|
+
widthState = _useSharedPluginState.widthState,
|
|
114
|
+
gridState = _useSharedPluginState.gridState;
|
|
115
|
+
if (!gridState) {
|
|
116
|
+
return null;
|
|
117
|
+
}
|
|
118
|
+
return /*#__PURE__*/_react.default.createElement(ThemedGrid, {
|
|
119
|
+
shouldCalcBreakoutGridLines: options && options.shouldCalcBreakoutGridLines,
|
|
120
|
+
editorWidth: (_widthState$width = widthState === null || widthState === void 0 ? void 0 : widthState.width) !== null && _widthState$width !== void 0 ? _widthState$width : _editorSharedStyles.akEditorFullPageMaxWidth,
|
|
121
|
+
containerElement: editorView.dom,
|
|
122
|
+
visible: gridState.visible,
|
|
123
|
+
gridType: (_gridState$gridType = gridState.gridType) !== null && _gridState$gridType !== void 0 ? _gridState$gridType : 'full',
|
|
124
|
+
highlight: gridState.highlight
|
|
125
|
+
});
|
|
126
|
+
};
|
|
127
|
+
var EMPTY_STATE = {
|
|
128
|
+
visible: false,
|
|
129
|
+
highlight: []
|
|
130
|
+
};
|
|
131
|
+
var gridPMPlugin = new _safePlugin.SafePlugin({
|
|
132
|
+
key: key,
|
|
133
|
+
state: {
|
|
134
|
+
init: function init() {
|
|
135
|
+
return EMPTY_STATE;
|
|
136
|
+
},
|
|
137
|
+
apply: function apply(tr, currentPluginState) {
|
|
138
|
+
var nextPluginState = tr.getMeta(key);
|
|
139
|
+
if (nextPluginState) {
|
|
140
|
+
return nextPluginState;
|
|
141
|
+
}
|
|
142
|
+
return currentPluginState;
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
});
|
|
146
|
+
var gridPlugin = function gridPlugin(options, api) {
|
|
147
|
+
return {
|
|
148
|
+
name: 'grid',
|
|
149
|
+
getSharedState: function getSharedState(editorState) {
|
|
150
|
+
if (!editorState) {
|
|
151
|
+
return null;
|
|
152
|
+
}
|
|
153
|
+
return key.getState(editorState);
|
|
154
|
+
},
|
|
155
|
+
actions: {
|
|
156
|
+
displayGrid: createDisplayGrid
|
|
157
|
+
},
|
|
158
|
+
pmPlugins: function pmPlugins() {
|
|
159
|
+
return [{
|
|
160
|
+
name: 'grid',
|
|
161
|
+
plugin: function plugin() {
|
|
162
|
+
return gridPMPlugin;
|
|
163
|
+
}
|
|
164
|
+
}];
|
|
165
|
+
},
|
|
166
|
+
contentComponent: function contentComponent(_ref5) {
|
|
167
|
+
var editorView = _ref5.editorView;
|
|
168
|
+
return /*#__PURE__*/_react.default.createElement(ContentComponent, {
|
|
169
|
+
editorView: editorView,
|
|
170
|
+
options: options,
|
|
171
|
+
api: api
|
|
172
|
+
});
|
|
173
|
+
}
|
|
174
|
+
};
|
|
175
|
+
};
|
|
176
|
+
exports.gridPlugin = gridPlugin;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { gridPlugin } from './plugin';
|
|
@@ -0,0 +1,163 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { withTheme } from '@emotion/react';
|
|
3
|
+
import classnames from 'classnames';
|
|
4
|
+
import { PluginKey } from 'prosemirror-state';
|
|
5
|
+
import { useSharedPluginState } from '@atlaskit/editor-common/hooks';
|
|
6
|
+
import { SafePlugin } from '@atlaskit/editor-common/safe-plugin';
|
|
7
|
+
import { akEditorBreakoutPadding, akEditorFullPageMaxWidth, breakoutWideScaleRatio } from '@atlaskit/editor-shared-styles';
|
|
8
|
+
export const GRID_SIZE = 12;
|
|
9
|
+
const key = new PluginKey('gridPlugin');
|
|
10
|
+
const createDisplayGrid = view => props => {
|
|
11
|
+
const {
|
|
12
|
+
dispatch,
|
|
13
|
+
state
|
|
14
|
+
} = view;
|
|
15
|
+
const tr = state.tr.setMeta(key, props);
|
|
16
|
+
dispatch(tr);
|
|
17
|
+
return true;
|
|
18
|
+
};
|
|
19
|
+
const sides = ['left', 'right'];
|
|
20
|
+
const overflowHighlight = (highlights, side, start, size) => {
|
|
21
|
+
if (!highlights.length) {
|
|
22
|
+
return false;
|
|
23
|
+
}
|
|
24
|
+
const minHighlight = highlights.reduce((prev, cur) => Math.min(prev, cur));
|
|
25
|
+
const maxHighlight = highlights.reduce((prev, cur) => Math.max(prev, cur));
|
|
26
|
+
if (side === 'left') {
|
|
27
|
+
return minHighlight < 0 && minHighlight <= -start && (typeof size === 'number' ? minHighlight >= -(start + size) : true);
|
|
28
|
+
} else {
|
|
29
|
+
return maxHighlight > GRID_SIZE && maxHighlight >= GRID_SIZE + start && (typeof size === 'number' ? maxHighlight <= GRID_SIZE + size : true);
|
|
30
|
+
}
|
|
31
|
+
};
|
|
32
|
+
const gutterGridLines = (editorMaxWidth, editorWidth, highlights, shouldCalcBreakoutGridLines) => {
|
|
33
|
+
const gridLines = [];
|
|
34
|
+
if (!shouldCalcBreakoutGridLines) {
|
|
35
|
+
return gridLines;
|
|
36
|
+
}
|
|
37
|
+
const wideSpacing = (editorMaxWidth * breakoutWideScaleRatio - editorMaxWidth) / 2;
|
|
38
|
+
sides.forEach(side => {
|
|
39
|
+
gridLines.push( /*#__PURE__*/React.createElement("div", {
|
|
40
|
+
key: side,
|
|
41
|
+
className: classnames('gridLine', overflowHighlight(highlights, side, 0, 4) ? 'highlight' : ''),
|
|
42
|
+
style: {
|
|
43
|
+
position: 'absolute',
|
|
44
|
+
[side]: `-${wideSpacing}px`
|
|
45
|
+
}
|
|
46
|
+
}));
|
|
47
|
+
gridLines.push( /*#__PURE__*/React.createElement("div", {
|
|
48
|
+
key: side + '-bk',
|
|
49
|
+
className: classnames('gridLine', highlights.indexOf('full-width') > -1 ? 'highlight' : ''),
|
|
50
|
+
style: {
|
|
51
|
+
position: 'absolute',
|
|
52
|
+
[side]: `-${(editorWidth - editorMaxWidth - akEditorBreakoutPadding) / 2}px`
|
|
53
|
+
}
|
|
54
|
+
}));
|
|
55
|
+
});
|
|
56
|
+
return gridLines;
|
|
57
|
+
};
|
|
58
|
+
const lineLengthGridLines = highlights => {
|
|
59
|
+
const gridLines = [];
|
|
60
|
+
const gridSpacing = 100 / GRID_SIZE;
|
|
61
|
+
for (let i = 0; i <= GRID_SIZE; i++) {
|
|
62
|
+
const style = {
|
|
63
|
+
paddingLeft: `${gridSpacing}%`
|
|
64
|
+
};
|
|
65
|
+
gridLines.push( /*#__PURE__*/React.createElement("div", {
|
|
66
|
+
key: i,
|
|
67
|
+
className: classnames('gridLine', highlights.indexOf(i) > -1 ? 'highlight' : ''),
|
|
68
|
+
style: i < GRID_SIZE ? style : undefined
|
|
69
|
+
}));
|
|
70
|
+
}
|
|
71
|
+
return gridLines;
|
|
72
|
+
};
|
|
73
|
+
const Grid = ({
|
|
74
|
+
highlight,
|
|
75
|
+
shouldCalcBreakoutGridLines,
|
|
76
|
+
theme,
|
|
77
|
+
containerElement,
|
|
78
|
+
editorWidth,
|
|
79
|
+
gridType,
|
|
80
|
+
visible
|
|
81
|
+
}) => {
|
|
82
|
+
const editorMaxWidth = theme.layoutMaxWidth;
|
|
83
|
+
let gridLines = [...lineLengthGridLines(highlight), ...gutterGridLines(editorMaxWidth, editorWidth, highlight, shouldCalcBreakoutGridLines)];
|
|
84
|
+
return /*#__PURE__*/React.createElement("div", {
|
|
85
|
+
className: "gridParent"
|
|
86
|
+
}, /*#__PURE__*/React.createElement("div", {
|
|
87
|
+
className: classnames('gridContainer', gridType),
|
|
88
|
+
style: {
|
|
89
|
+
height: `${containerElement.scrollHeight}px`,
|
|
90
|
+
display: visible ? 'block' : 'none'
|
|
91
|
+
},
|
|
92
|
+
"data-testid": "gridContainer"
|
|
93
|
+
}, gridLines));
|
|
94
|
+
};
|
|
95
|
+
const ThemedGrid = withTheme(Grid);
|
|
96
|
+
const ContentComponent = ({
|
|
97
|
+
api,
|
|
98
|
+
editorView,
|
|
99
|
+
options
|
|
100
|
+
}) => {
|
|
101
|
+
var _widthState$width, _gridState$gridType;
|
|
102
|
+
const {
|
|
103
|
+
widthState,
|
|
104
|
+
gridState
|
|
105
|
+
} = useSharedPluginState(api, ['width', 'grid']);
|
|
106
|
+
if (!gridState) {
|
|
107
|
+
return null;
|
|
108
|
+
}
|
|
109
|
+
return /*#__PURE__*/React.createElement(ThemedGrid, {
|
|
110
|
+
shouldCalcBreakoutGridLines: options && options.shouldCalcBreakoutGridLines,
|
|
111
|
+
editorWidth: (_widthState$width = widthState === null || widthState === void 0 ? void 0 : widthState.width) !== null && _widthState$width !== void 0 ? _widthState$width : akEditorFullPageMaxWidth,
|
|
112
|
+
containerElement: editorView.dom,
|
|
113
|
+
visible: gridState.visible,
|
|
114
|
+
gridType: (_gridState$gridType = gridState.gridType) !== null && _gridState$gridType !== void 0 ? _gridState$gridType : 'full',
|
|
115
|
+
highlight: gridState.highlight
|
|
116
|
+
});
|
|
117
|
+
};
|
|
118
|
+
const EMPTY_STATE = {
|
|
119
|
+
visible: false,
|
|
120
|
+
highlight: []
|
|
121
|
+
};
|
|
122
|
+
const gridPMPlugin = new SafePlugin({
|
|
123
|
+
key,
|
|
124
|
+
state: {
|
|
125
|
+
init() {
|
|
126
|
+
return EMPTY_STATE;
|
|
127
|
+
},
|
|
128
|
+
apply(tr, currentPluginState) {
|
|
129
|
+
const nextPluginState = tr.getMeta(key);
|
|
130
|
+
if (nextPluginState) {
|
|
131
|
+
return nextPluginState;
|
|
132
|
+
}
|
|
133
|
+
return currentPluginState;
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
});
|
|
137
|
+
export const gridPlugin = (options, api) => {
|
|
138
|
+
return {
|
|
139
|
+
name: 'grid',
|
|
140
|
+
getSharedState(editorState) {
|
|
141
|
+
if (!editorState) {
|
|
142
|
+
return null;
|
|
143
|
+
}
|
|
144
|
+
return key.getState(editorState);
|
|
145
|
+
},
|
|
146
|
+
actions: {
|
|
147
|
+
displayGrid: createDisplayGrid
|
|
148
|
+
},
|
|
149
|
+
pmPlugins() {
|
|
150
|
+
return [{
|
|
151
|
+
name: 'grid',
|
|
152
|
+
plugin: () => gridPMPlugin
|
|
153
|
+
}];
|
|
154
|
+
},
|
|
155
|
+
contentComponent: ({
|
|
156
|
+
editorView
|
|
157
|
+
}) => /*#__PURE__*/React.createElement(ContentComponent, {
|
|
158
|
+
editorView: editorView,
|
|
159
|
+
options: options,
|
|
160
|
+
api: api
|
|
161
|
+
})
|
|
162
|
+
};
|
|
163
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { gridPlugin } from './plugin';
|
|
@@ -0,0 +1,167 @@
|
|
|
1
|
+
import _toConsumableArray from "@babel/runtime/helpers/toConsumableArray";
|
|
2
|
+
import _defineProperty from "@babel/runtime/helpers/defineProperty";
|
|
3
|
+
import React from 'react';
|
|
4
|
+
import { withTheme } from '@emotion/react';
|
|
5
|
+
import classnames from 'classnames';
|
|
6
|
+
import { PluginKey } from 'prosemirror-state';
|
|
7
|
+
import { useSharedPluginState } from '@atlaskit/editor-common/hooks';
|
|
8
|
+
import { SafePlugin } from '@atlaskit/editor-common/safe-plugin';
|
|
9
|
+
import { akEditorBreakoutPadding, akEditorFullPageMaxWidth, breakoutWideScaleRatio } from '@atlaskit/editor-shared-styles';
|
|
10
|
+
export var GRID_SIZE = 12;
|
|
11
|
+
var key = new PluginKey('gridPlugin');
|
|
12
|
+
var createDisplayGrid = function createDisplayGrid(view) {
|
|
13
|
+
return function (props) {
|
|
14
|
+
var dispatch = view.dispatch,
|
|
15
|
+
state = view.state;
|
|
16
|
+
var tr = state.tr.setMeta(key, props);
|
|
17
|
+
dispatch(tr);
|
|
18
|
+
return true;
|
|
19
|
+
};
|
|
20
|
+
};
|
|
21
|
+
var sides = ['left', 'right'];
|
|
22
|
+
var overflowHighlight = function overflowHighlight(highlights, side, start, size) {
|
|
23
|
+
if (!highlights.length) {
|
|
24
|
+
return false;
|
|
25
|
+
}
|
|
26
|
+
var minHighlight = highlights.reduce(function (prev, cur) {
|
|
27
|
+
return Math.min(prev, cur);
|
|
28
|
+
});
|
|
29
|
+
var maxHighlight = highlights.reduce(function (prev, cur) {
|
|
30
|
+
return Math.max(prev, cur);
|
|
31
|
+
});
|
|
32
|
+
if (side === 'left') {
|
|
33
|
+
return minHighlight < 0 && minHighlight <= -start && (typeof size === 'number' ? minHighlight >= -(start + size) : true);
|
|
34
|
+
} else {
|
|
35
|
+
return maxHighlight > GRID_SIZE && maxHighlight >= GRID_SIZE + start && (typeof size === 'number' ? maxHighlight <= GRID_SIZE + size : true);
|
|
36
|
+
}
|
|
37
|
+
};
|
|
38
|
+
var gutterGridLines = function gutterGridLines(editorMaxWidth, editorWidth, highlights, shouldCalcBreakoutGridLines) {
|
|
39
|
+
var gridLines = [];
|
|
40
|
+
if (!shouldCalcBreakoutGridLines) {
|
|
41
|
+
return gridLines;
|
|
42
|
+
}
|
|
43
|
+
var wideSpacing = (editorMaxWidth * breakoutWideScaleRatio - editorMaxWidth) / 2;
|
|
44
|
+
sides.forEach(function (side) {
|
|
45
|
+
gridLines.push( /*#__PURE__*/React.createElement("div", {
|
|
46
|
+
key: side,
|
|
47
|
+
className: classnames('gridLine', overflowHighlight(highlights, side, 0, 4) ? 'highlight' : ''),
|
|
48
|
+
style: _defineProperty({
|
|
49
|
+
position: 'absolute'
|
|
50
|
+
}, side, "-".concat(wideSpacing, "px"))
|
|
51
|
+
}));
|
|
52
|
+
gridLines.push( /*#__PURE__*/React.createElement("div", {
|
|
53
|
+
key: side + '-bk',
|
|
54
|
+
className: classnames('gridLine', highlights.indexOf('full-width') > -1 ? 'highlight' : ''),
|
|
55
|
+
style: _defineProperty({
|
|
56
|
+
position: 'absolute'
|
|
57
|
+
}, side, "-".concat((editorWidth - editorMaxWidth - akEditorBreakoutPadding) / 2, "px"))
|
|
58
|
+
}));
|
|
59
|
+
});
|
|
60
|
+
return gridLines;
|
|
61
|
+
};
|
|
62
|
+
var lineLengthGridLines = function lineLengthGridLines(highlights) {
|
|
63
|
+
var gridLines = [];
|
|
64
|
+
var gridSpacing = 100 / GRID_SIZE;
|
|
65
|
+
for (var i = 0; i <= GRID_SIZE; i++) {
|
|
66
|
+
var style = {
|
|
67
|
+
paddingLeft: "".concat(gridSpacing, "%")
|
|
68
|
+
};
|
|
69
|
+
gridLines.push( /*#__PURE__*/React.createElement("div", {
|
|
70
|
+
key: i,
|
|
71
|
+
className: classnames('gridLine', highlights.indexOf(i) > -1 ? 'highlight' : ''),
|
|
72
|
+
style: i < GRID_SIZE ? style : undefined
|
|
73
|
+
}));
|
|
74
|
+
}
|
|
75
|
+
return gridLines;
|
|
76
|
+
};
|
|
77
|
+
var Grid = function Grid(_ref3) {
|
|
78
|
+
var highlight = _ref3.highlight,
|
|
79
|
+
shouldCalcBreakoutGridLines = _ref3.shouldCalcBreakoutGridLines,
|
|
80
|
+
theme = _ref3.theme,
|
|
81
|
+
containerElement = _ref3.containerElement,
|
|
82
|
+
editorWidth = _ref3.editorWidth,
|
|
83
|
+
gridType = _ref3.gridType,
|
|
84
|
+
visible = _ref3.visible;
|
|
85
|
+
var editorMaxWidth = theme.layoutMaxWidth;
|
|
86
|
+
var gridLines = [].concat(_toConsumableArray(lineLengthGridLines(highlight)), _toConsumableArray(gutterGridLines(editorMaxWidth, editorWidth, highlight, shouldCalcBreakoutGridLines)));
|
|
87
|
+
return /*#__PURE__*/React.createElement("div", {
|
|
88
|
+
className: "gridParent"
|
|
89
|
+
}, /*#__PURE__*/React.createElement("div", {
|
|
90
|
+
className: classnames('gridContainer', gridType),
|
|
91
|
+
style: {
|
|
92
|
+
height: "".concat(containerElement.scrollHeight, "px"),
|
|
93
|
+
display: visible ? 'block' : 'none'
|
|
94
|
+
},
|
|
95
|
+
"data-testid": "gridContainer"
|
|
96
|
+
}, gridLines));
|
|
97
|
+
};
|
|
98
|
+
var ThemedGrid = withTheme(Grid);
|
|
99
|
+
var ContentComponent = function ContentComponent(_ref4) {
|
|
100
|
+
var _widthState$width, _gridState$gridType;
|
|
101
|
+
var api = _ref4.api,
|
|
102
|
+
editorView = _ref4.editorView,
|
|
103
|
+
options = _ref4.options;
|
|
104
|
+
var _useSharedPluginState = useSharedPluginState(api, ['width', 'grid']),
|
|
105
|
+
widthState = _useSharedPluginState.widthState,
|
|
106
|
+
gridState = _useSharedPluginState.gridState;
|
|
107
|
+
if (!gridState) {
|
|
108
|
+
return null;
|
|
109
|
+
}
|
|
110
|
+
return /*#__PURE__*/React.createElement(ThemedGrid, {
|
|
111
|
+
shouldCalcBreakoutGridLines: options && options.shouldCalcBreakoutGridLines,
|
|
112
|
+
editorWidth: (_widthState$width = widthState === null || widthState === void 0 ? void 0 : widthState.width) !== null && _widthState$width !== void 0 ? _widthState$width : akEditorFullPageMaxWidth,
|
|
113
|
+
containerElement: editorView.dom,
|
|
114
|
+
visible: gridState.visible,
|
|
115
|
+
gridType: (_gridState$gridType = gridState.gridType) !== null && _gridState$gridType !== void 0 ? _gridState$gridType : 'full',
|
|
116
|
+
highlight: gridState.highlight
|
|
117
|
+
});
|
|
118
|
+
};
|
|
119
|
+
var EMPTY_STATE = {
|
|
120
|
+
visible: false,
|
|
121
|
+
highlight: []
|
|
122
|
+
};
|
|
123
|
+
var gridPMPlugin = new SafePlugin({
|
|
124
|
+
key: key,
|
|
125
|
+
state: {
|
|
126
|
+
init: function init() {
|
|
127
|
+
return EMPTY_STATE;
|
|
128
|
+
},
|
|
129
|
+
apply: function apply(tr, currentPluginState) {
|
|
130
|
+
var nextPluginState = tr.getMeta(key);
|
|
131
|
+
if (nextPluginState) {
|
|
132
|
+
return nextPluginState;
|
|
133
|
+
}
|
|
134
|
+
return currentPluginState;
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
});
|
|
138
|
+
export var gridPlugin = function gridPlugin(options, api) {
|
|
139
|
+
return {
|
|
140
|
+
name: 'grid',
|
|
141
|
+
getSharedState: function getSharedState(editorState) {
|
|
142
|
+
if (!editorState) {
|
|
143
|
+
return null;
|
|
144
|
+
}
|
|
145
|
+
return key.getState(editorState);
|
|
146
|
+
},
|
|
147
|
+
actions: {
|
|
148
|
+
displayGrid: createDisplayGrid
|
|
149
|
+
},
|
|
150
|
+
pmPlugins: function pmPlugins() {
|
|
151
|
+
return [{
|
|
152
|
+
name: 'grid',
|
|
153
|
+
plugin: function plugin() {
|
|
154
|
+
return gridPMPlugin;
|
|
155
|
+
}
|
|
156
|
+
}];
|
|
157
|
+
},
|
|
158
|
+
contentComponent: function contentComponent(_ref5) {
|
|
159
|
+
var editorView = _ref5.editorView;
|
|
160
|
+
return /*#__PURE__*/React.createElement(ContentComponent, {
|
|
161
|
+
editorView: editorView,
|
|
162
|
+
options: options,
|
|
163
|
+
api: api
|
|
164
|
+
});
|
|
165
|
+
}
|
|
166
|
+
};
|
|
167
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { EditorView } from 'prosemirror-view';
|
|
2
|
+
import { NextEditorPlugin } from '@atlaskit/editor-common/types';
|
|
3
|
+
import type { widthPlugin } from '@atlaskit/editor-plugin-width';
|
|
4
|
+
import type { GridPluginState } from './types';
|
|
5
|
+
export declare const GRID_SIZE = 12;
|
|
6
|
+
type Required<T> = {
|
|
7
|
+
[P in keyof T]-?: T[P];
|
|
8
|
+
};
|
|
9
|
+
type DisplayGrid = (props: Required<GridPluginState>) => boolean;
|
|
10
|
+
type CreateDisplayGrid = (view: EditorView) => DisplayGrid;
|
|
11
|
+
export interface GridPluginOptions {
|
|
12
|
+
shouldCalcBreakoutGridLines?: boolean;
|
|
13
|
+
}
|
|
14
|
+
export declare const gridPlugin: NextEditorPlugin<'grid', {
|
|
15
|
+
pluginConfiguration: GridPluginOptions | undefined;
|
|
16
|
+
dependencies: [typeof widthPlugin];
|
|
17
|
+
sharedState: GridPluginState | null;
|
|
18
|
+
actions: {
|
|
19
|
+
displayGrid: CreateDisplayGrid;
|
|
20
|
+
};
|
|
21
|
+
}>;
|
|
22
|
+
export {};
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { EditorView } from 'prosemirror-view';
|
|
2
|
+
import { NextEditorPlugin } from '@atlaskit/editor-common/types';
|
|
3
|
+
import type { widthPlugin } from '@atlaskit/editor-plugin-width';
|
|
4
|
+
import type { GridPluginState } from './types';
|
|
5
|
+
export declare const GRID_SIZE = 12;
|
|
6
|
+
type Required<T> = {
|
|
7
|
+
[P in keyof T]-?: T[P];
|
|
8
|
+
};
|
|
9
|
+
type DisplayGrid = (props: Required<GridPluginState>) => boolean;
|
|
10
|
+
type CreateDisplayGrid = (view: EditorView) => DisplayGrid;
|
|
11
|
+
export interface GridPluginOptions {
|
|
12
|
+
shouldCalcBreakoutGridLines?: boolean;
|
|
13
|
+
}
|
|
14
|
+
export declare const gridPlugin: NextEditorPlugin<'grid', {
|
|
15
|
+
pluginConfiguration: GridPluginOptions | undefined;
|
|
16
|
+
dependencies: [
|
|
17
|
+
typeof widthPlugin
|
|
18
|
+
];
|
|
19
|
+
sharedState: GridPluginState | null;
|
|
20
|
+
actions: {
|
|
21
|
+
displayGrid: CreateDisplayGrid;
|
|
22
|
+
};
|
|
23
|
+
}>;
|
|
24
|
+
export {};
|
package/package.json
ADDED
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@atlaskit/editor-plugin-grid",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Grid plugin for @atlaskit/editor-core",
|
|
5
|
+
"author": "Atlassian Pty Ltd",
|
|
6
|
+
"license": "Apache-2.0",
|
|
7
|
+
"publishConfig": {
|
|
8
|
+
"registry": "https://registry.npmjs.org/"
|
|
9
|
+
},
|
|
10
|
+
"atlassian": {
|
|
11
|
+
"team": "Editor",
|
|
12
|
+
"releaseModel": "scheduled"
|
|
13
|
+
},
|
|
14
|
+
"repository": "https://bitbucket.org/atlassian/atlassian-frontend",
|
|
15
|
+
"main": "dist/cjs/index.js",
|
|
16
|
+
"module": "dist/esm/index.js",
|
|
17
|
+
"module:es2019": "dist/es2019/index.js",
|
|
18
|
+
"types": "dist/types/index.d.ts",
|
|
19
|
+
"sideEffects": false,
|
|
20
|
+
"atlaskit:src": "src/index.ts",
|
|
21
|
+
"af:exports": {
|
|
22
|
+
".": "./src/index.ts"
|
|
23
|
+
},
|
|
24
|
+
"dependencies": {
|
|
25
|
+
"@atlaskit/editor-common": "^74.2.0",
|
|
26
|
+
"@atlaskit/editor-plugin-width": "^0.0.1",
|
|
27
|
+
"@atlaskit/editor-shared-styles": "^2.4.0",
|
|
28
|
+
"@babel/runtime": "^7.0.0",
|
|
29
|
+
"@emotion/react": "^11.7.1",
|
|
30
|
+
"classnames": "^2.2.5",
|
|
31
|
+
"prosemirror-state": "1.3.4",
|
|
32
|
+
"prosemirror-view": "1.23.7"
|
|
33
|
+
},
|
|
34
|
+
"peerDependencies": {
|
|
35
|
+
"react": "^16.8.0"
|
|
36
|
+
},
|
|
37
|
+
"devDependencies": {
|
|
38
|
+
"@atlaskit/docs": "*",
|
|
39
|
+
"@atlaskit/editor-core": "^184.0.0",
|
|
40
|
+
"@atlaskit/editor-test-helpers": "^18.2.0",
|
|
41
|
+
"@atlaskit/ssr": "*",
|
|
42
|
+
"@atlaskit/visual-regression": "*",
|
|
43
|
+
"@atlaskit/webdriver-runner": "*",
|
|
44
|
+
"@atlassian/atlassian-frontend-prettier-config-1.0.0": "npm:@atlassian/atlassian-frontend-prettier-config@1.0.0",
|
|
45
|
+
"@testing-library/react": "^12.1.5",
|
|
46
|
+
"react-dom": "^16.8.0",
|
|
47
|
+
"typescript": "~4.9.5",
|
|
48
|
+
"wait-for-expect": "^1.2.0"
|
|
49
|
+
},
|
|
50
|
+
"techstack": {
|
|
51
|
+
"@atlassian/frontend": {
|
|
52
|
+
"import-structure": [
|
|
53
|
+
"atlassian-conventions"
|
|
54
|
+
],
|
|
55
|
+
"circular-dependencies": [
|
|
56
|
+
"file-and-folder-level"
|
|
57
|
+
]
|
|
58
|
+
},
|
|
59
|
+
"@repo/internal": {
|
|
60
|
+
"dom-events": "use-bind-event-listener",
|
|
61
|
+
"analytics": [
|
|
62
|
+
"analytics-next"
|
|
63
|
+
],
|
|
64
|
+
"design-tokens": [
|
|
65
|
+
"color"
|
|
66
|
+
],
|
|
67
|
+
"theming": [
|
|
68
|
+
"react-context"
|
|
69
|
+
],
|
|
70
|
+
"ui-components": [
|
|
71
|
+
"lite-mode"
|
|
72
|
+
],
|
|
73
|
+
"deprecation": [
|
|
74
|
+
"no-deprecated-imports"
|
|
75
|
+
],
|
|
76
|
+
"styling": [
|
|
77
|
+
"static",
|
|
78
|
+
"emotion"
|
|
79
|
+
]
|
|
80
|
+
}
|
|
81
|
+
},
|
|
82
|
+
"prettier": "@atlassian/atlassian-frontend-prettier-config-1.0.0"
|
|
83
|
+
}
|
package/report.api.md
ADDED
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
<!-- API Report Version: 2.3 -->
|
|
2
|
+
|
|
3
|
+
## API Report File for "@atlaskit/editor-plugin-grid"
|
|
4
|
+
|
|
5
|
+
> Do not edit this file. This report is auto-generated using [API Extractor](https://api-extractor.com/).
|
|
6
|
+
> [Learn more about API reports](https://hello.atlassian.net/wiki/spaces/UR/pages/1825484529/Package+API+Reports)
|
|
7
|
+
|
|
8
|
+
### Table of contents
|
|
9
|
+
|
|
10
|
+
- [Main Entry Types](#main-entry-types)
|
|
11
|
+
- [Peer Dependencies](#peer-dependencies)
|
|
12
|
+
|
|
13
|
+
### Main Entry Types
|
|
14
|
+
|
|
15
|
+
<!--SECTION START: Main Entry Types-->
|
|
16
|
+
|
|
17
|
+
```ts
|
|
18
|
+
import { EditorView } from 'prosemirror-view';
|
|
19
|
+
import type { GridType } from '@atlaskit/editor-common/types';
|
|
20
|
+
import { NextEditorPlugin } from '@atlaskit/editor-common/types';
|
|
21
|
+
import type { widthPlugin } from '@atlaskit/editor-plugin-width';
|
|
22
|
+
|
|
23
|
+
// @public (undocumented)
|
|
24
|
+
type CreateDisplayGrid = (view: EditorView) => DisplayGrid;
|
|
25
|
+
|
|
26
|
+
// @public (undocumented)
|
|
27
|
+
type DisplayGrid = (props: Required_2<GridPluginState>) => boolean;
|
|
28
|
+
|
|
29
|
+
// @public (undocumented)
|
|
30
|
+
export const gridPlugin: NextEditorPlugin<
|
|
31
|
+
'grid',
|
|
32
|
+
{
|
|
33
|
+
pluginConfiguration: GridPluginOptions | undefined;
|
|
34
|
+
dependencies: [typeof widthPlugin];
|
|
35
|
+
sharedState: GridPluginState | null;
|
|
36
|
+
actions: {
|
|
37
|
+
displayGrid: CreateDisplayGrid;
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
>;
|
|
41
|
+
|
|
42
|
+
// @public (undocumented)
|
|
43
|
+
interface GridPluginOptions {
|
|
44
|
+
// (undocumented)
|
|
45
|
+
shouldCalcBreakoutGridLines?: boolean;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
// @public (undocumented)
|
|
49
|
+
type GridPluginState = {
|
|
50
|
+
visible: boolean;
|
|
51
|
+
gridType?: GridType;
|
|
52
|
+
highlight: Highlights;
|
|
53
|
+
};
|
|
54
|
+
|
|
55
|
+
// @public (undocumented)
|
|
56
|
+
export type Highlights = Array<'full-width' | 'wide' | number>;
|
|
57
|
+
|
|
58
|
+
// @public (undocumented)
|
|
59
|
+
type Required_2<T> = {
|
|
60
|
+
[P in keyof T]-?: T[P];
|
|
61
|
+
};
|
|
62
|
+
|
|
63
|
+
// (No @packageDocumentation comment for this package)
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
<!--SECTION END: Main Entry Types-->
|
|
67
|
+
|
|
68
|
+
### Peer Dependencies
|
|
69
|
+
|
|
70
|
+
<!--SECTION START: Peer Dependencies-->
|
|
71
|
+
|
|
72
|
+
```json
|
|
73
|
+
{
|
|
74
|
+
"react": "^16.8.0"
|
|
75
|
+
}
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
<!--SECTION END: Peer Dependencies-->
|