react-align 1.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +74 -0
- package/dist/Grid/GridArea/index.d.ts +19 -0
- package/dist/Grid/GridItem/index.d.ts +26 -0
- package/dist/Grid/GridSection/index.d.ts +13 -0
- package/dist/Grid/GridWrapper/index.d.ts +12 -0
- package/dist/Icon/icons.d.ts +14 -0
- package/dist/Icon/index.d.ts +12 -0
- package/dist/context.d.ts +7 -0
- package/dist/index.d.ts +6 -0
- package/dist/index.js +8 -0
- package/dist/react-align.cjs.development.js +727 -0
- package/dist/react-align.cjs.development.js.map +1 -0
- package/dist/react-align.cjs.production.min.js +2 -0
- package/dist/react-align.cjs.production.min.js.map +1 -0
- package/dist/react-align.esm.js +716 -0
- package/dist/react-align.esm.js.map +1 -0
- package/package.json +80 -0
- package/src/Grid/GridArea/index.tsx +177 -0
- package/src/Grid/GridItem/index.tsx +252 -0
- package/src/Grid/GridSection/index.tsx +46 -0
- package/src/Grid/GridWrapper/index.tsx +39 -0
- package/src/Grid/grid.css +78 -0
- package/src/Grid/interfaces.ts +5 -0
- package/src/Icon/Icons/alignCenter.svg +4 -0
- package/src/Icon/Icons/alignCenterV.svg +4 -0
- package/src/Icon/Icons/alignEnd.svg +4 -0
- package/src/Icon/Icons/alignEndV.svg +4 -0
- package/src/Icon/Icons/alignStart.svg +4 -0
- package/src/Icon/Icons/alignStartV.svg +4 -0
- package/src/Icon/Icons/horizontalExtend.svg +8 -0
- package/src/Icon/Icons/horizontalNormal.svg +7 -0
- package/src/Icon/Icons/moveArrows.svg +10 -0
- package/src/Icon/Icons/verticalExtend.svg +8 -0
- package/src/Icon/Icons/verticalNormal.svg +7 -0
- package/src/Icon/icons.ts +25 -0
- package/src/Icon/index.tsx +45 -0
- package/src/context.tsx +6 -0
- package/src/index.tsx +8 -0
- package/src/stories/GridArea.stories.tsx +28 -0
|
@@ -0,0 +1,716 @@
|
|
|
1
|
+
import React__default, { useContext, createContext, createElement, useRef, useState, useMemo, useCallback } from 'react';
|
|
2
|
+
import { DndProvider, useDrop, useDrag } from 'react-dnd';
|
|
3
|
+
import { HTML5Backend } from 'react-dnd-html5-backend';
|
|
4
|
+
import { css } from 'glamor';
|
|
5
|
+
|
|
6
|
+
var EditorModeContext = /*#__PURE__*/createContext({
|
|
7
|
+
enabled: undefined
|
|
8
|
+
});
|
|
9
|
+
var useEditorMode = function useEditorMode() {
|
|
10
|
+
return useContext(EditorModeContext);
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
function styleInject(css, ref) {
|
|
14
|
+
if ( ref === void 0 ) ref = {};
|
|
15
|
+
var insertAt = ref.insertAt;
|
|
16
|
+
|
|
17
|
+
if (!css || typeof document === 'undefined') { return; }
|
|
18
|
+
|
|
19
|
+
var head = document.head || document.getElementsByTagName('head')[0];
|
|
20
|
+
var style = document.createElement('style');
|
|
21
|
+
style.type = 'text/css';
|
|
22
|
+
|
|
23
|
+
if (insertAt === 'top') {
|
|
24
|
+
if (head.firstChild) {
|
|
25
|
+
head.insertBefore(style, head.firstChild);
|
|
26
|
+
} else {
|
|
27
|
+
head.appendChild(style);
|
|
28
|
+
}
|
|
29
|
+
} else {
|
|
30
|
+
head.appendChild(style);
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
if (style.styleSheet) {
|
|
34
|
+
style.styleSheet.cssText = css;
|
|
35
|
+
} else {
|
|
36
|
+
style.appendChild(document.createTextNode(css));
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
var css_248z = ".wrapper{height:100%}.section,.wrapper{display:flex;justify-content:space-between}.section{flex-direction:column}.area{border:1px solid transparent;border-radius:8px;box-sizing:border-box;display:flex;position:relative}.area-transition-in{transition:all .3s ease-in-out,min-height .5s ease-in-out .2s,min-width .5s ease-in-out .2s}.area-transition-out{transition:all .3s ease-in-out .4s,min-height .5s ease-in-out .2s,min-width .5s ease-in-out .2s}.item{border:1px solid transparent;border-radius:6px;box-sizing:border-box;margin:6px}.vertical{flex-direction:column}.vertical-r{flex-direction:column-reverse}.horizontal{flex-direction:row}.horizontal-r{flex-direction:row-reverse}.stretch{flex:auto}.middle{flex-grow:0;flex:auto}.just-centered{justify-content:center}.just-end{justify-content:flex-end}.end{align-items:flex-end}.hide{display:none}";
|
|
41
|
+
styleInject(css_248z);
|
|
42
|
+
|
|
43
|
+
var GridWrapper = function GridWrapper(_ref) {
|
|
44
|
+
var className = _ref.className,
|
|
45
|
+
enabled = _ref.enabled,
|
|
46
|
+
vertical = _ref.vertical,
|
|
47
|
+
stretch = _ref.stretch,
|
|
48
|
+
styles = _ref.styles,
|
|
49
|
+
editorStyles = _ref.editorStyles,
|
|
50
|
+
children = _ref.children;
|
|
51
|
+
return React__default.createElement("div", {
|
|
52
|
+
className: "wrapper " + className + " " + (vertical && 'vertical') + " " + (stretch && 'stretch'),
|
|
53
|
+
style: enabled ? editorStyles : styles
|
|
54
|
+
}, React__default.createElement(DndProvider, {
|
|
55
|
+
backend: HTML5Backend
|
|
56
|
+
}, React__default.createElement(EditorModeContext.Provider, {
|
|
57
|
+
value: {
|
|
58
|
+
enabled: enabled
|
|
59
|
+
}
|
|
60
|
+
}, children)));
|
|
61
|
+
};
|
|
62
|
+
|
|
63
|
+
function _extends() {
|
|
64
|
+
_extends = Object.assign || function (target) {
|
|
65
|
+
for (var i = 1; i < arguments.length; i++) {
|
|
66
|
+
var source = arguments[i];
|
|
67
|
+
|
|
68
|
+
for (var key in source) {
|
|
69
|
+
if (Object.prototype.hasOwnProperty.call(source, key)) {
|
|
70
|
+
target[key] = source[key];
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
return target;
|
|
76
|
+
};
|
|
77
|
+
|
|
78
|
+
return _extends.apply(this, arguments);
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
var GridSection = function GridSection(_ref) {
|
|
82
|
+
var className = _ref.className,
|
|
83
|
+
horizontal = _ref.horizontal,
|
|
84
|
+
stretch = _ref.stretch,
|
|
85
|
+
fixedWidth = _ref.fixedWidth,
|
|
86
|
+
fixedHeight = _ref.fixedHeight,
|
|
87
|
+
styles = _ref.styles,
|
|
88
|
+
editorStyles = _ref.editorStyles,
|
|
89
|
+
children = _ref.children;
|
|
90
|
+
|
|
91
|
+
var _useEditorMode = useEditorMode(),
|
|
92
|
+
enabled = _useEditorMode.enabled;
|
|
93
|
+
|
|
94
|
+
var stylesFromProps = enabled ? editorStyles : styles;
|
|
95
|
+
return React__default.createElement("div", {
|
|
96
|
+
className: "section " + className + " " + (horizontal && 'horizontal') + " " + (stretch && 'stretch'),
|
|
97
|
+
style: _extends({}, stylesFromProps, {
|
|
98
|
+
height: fixedHeight + 'px',
|
|
99
|
+
width: fixedWidth + 'px'
|
|
100
|
+
})
|
|
101
|
+
}, children);
|
|
102
|
+
};
|
|
103
|
+
|
|
104
|
+
var _path;
|
|
105
|
+
|
|
106
|
+
function _extends$1() { _extends$1 = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends$1.apply(this, arguments); }
|
|
107
|
+
|
|
108
|
+
function SvgHorizontalExtend(props) {
|
|
109
|
+
return /*#__PURE__*/createElement("svg", _extends$1({
|
|
110
|
+
width: 24,
|
|
111
|
+
height: 24,
|
|
112
|
+
fill: "none",
|
|
113
|
+
xmlns: "http://www.w3.org/2000/svg"
|
|
114
|
+
}, props), _path || (_path = /*#__PURE__*/createElement("path", {
|
|
115
|
+
d: "M1 20.25V3.75M23 20.25V3.75M12 12h8.5M17.5 9l3 3-3 3M12 12H4M7 15l-3-3 3-3",
|
|
116
|
+
stroke: "currentColor",
|
|
117
|
+
strokeWidth: 1.5,
|
|
118
|
+
strokeLinecap: "round",
|
|
119
|
+
strokeLinejoin: "round"
|
|
120
|
+
})));
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
var _path$1, _rect;
|
|
124
|
+
|
|
125
|
+
function _extends$2() { _extends$2 = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends$2.apply(this, arguments); }
|
|
126
|
+
|
|
127
|
+
function SvgHorizontalNormal(props) {
|
|
128
|
+
return /*#__PURE__*/createElement("svg", _extends$2({
|
|
129
|
+
width: 24,
|
|
130
|
+
height: 24,
|
|
131
|
+
fill: "none",
|
|
132
|
+
xmlns: "http://www.w3.org/2000/svg"
|
|
133
|
+
}, props), _path$1 || (_path$1 = /*#__PURE__*/createElement("path", {
|
|
134
|
+
d: "M1 12h5M3 9l3 3-3 3M23 12h-5M21 15l-3-3 3-3",
|
|
135
|
+
stroke: "currentColor",
|
|
136
|
+
strokeWidth: 1.5,
|
|
137
|
+
strokeLinecap: "round",
|
|
138
|
+
strokeLinejoin: "round"
|
|
139
|
+
})), _rect || (_rect = /*#__PURE__*/createElement("rect", {
|
|
140
|
+
x: 8.75,
|
|
141
|
+
y: 2.75,
|
|
142
|
+
width: 6.5,
|
|
143
|
+
height: 18.5,
|
|
144
|
+
rx: 1.25,
|
|
145
|
+
stroke: "currentColor",
|
|
146
|
+
strokeWidth: 1.5
|
|
147
|
+
})));
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
var _path$2;
|
|
151
|
+
|
|
152
|
+
function _extends$3() { _extends$3 = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends$3.apply(this, arguments); }
|
|
153
|
+
|
|
154
|
+
function SvgVerticalExtend(props) {
|
|
155
|
+
return /*#__PURE__*/createElement("svg", _extends$3({
|
|
156
|
+
width: 24,
|
|
157
|
+
height: 24,
|
|
158
|
+
fill: "none",
|
|
159
|
+
xmlns: "http://www.w3.org/2000/svg"
|
|
160
|
+
}, props), _path$2 || (_path$2 = /*#__PURE__*/createElement("path", {
|
|
161
|
+
d: "M3.75 1h16.5M3.75 23h16.5M12 12v8.5M15 17.5l-3 3-3-3M12 12V4M9 7l3-3 3 3",
|
|
162
|
+
stroke: "currentColor",
|
|
163
|
+
strokeWidth: 1.5,
|
|
164
|
+
strokeLinecap: "round",
|
|
165
|
+
strokeLinejoin: "round"
|
|
166
|
+
})));
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
var _path$3, _rect$1;
|
|
170
|
+
|
|
171
|
+
function _extends$4() { _extends$4 = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends$4.apply(this, arguments); }
|
|
172
|
+
|
|
173
|
+
function SvgVerticalNormal(props) {
|
|
174
|
+
return /*#__PURE__*/createElement("svg", _extends$4({
|
|
175
|
+
width: 24,
|
|
176
|
+
height: 24,
|
|
177
|
+
fill: "none",
|
|
178
|
+
xmlns: "http://www.w3.org/2000/svg"
|
|
179
|
+
}, props), _path$3 || (_path$3 = /*#__PURE__*/createElement("path", {
|
|
180
|
+
d: "M12 1v5M15 3l-3 3-3-3M12 23v-5M9 21l3-3 3 3",
|
|
181
|
+
stroke: "currentColor",
|
|
182
|
+
strokeWidth: 1.5,
|
|
183
|
+
strokeLinecap: "round",
|
|
184
|
+
strokeLinejoin: "round"
|
|
185
|
+
})), _rect$1 || (_rect$1 = /*#__PURE__*/createElement("rect", {
|
|
186
|
+
x: 21.25,
|
|
187
|
+
y: 8.75,
|
|
188
|
+
width: 6.5,
|
|
189
|
+
height: 18.5,
|
|
190
|
+
rx: 1.25,
|
|
191
|
+
transform: "rotate(90 21.25 8.75)",
|
|
192
|
+
stroke: "currentColor",
|
|
193
|
+
strokeWidth: 1.5
|
|
194
|
+
})));
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
var _path$4;
|
|
198
|
+
|
|
199
|
+
function _extends$5() { _extends$5 = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends$5.apply(this, arguments); }
|
|
200
|
+
|
|
201
|
+
function SvgMoveArrows(props) {
|
|
202
|
+
return /*#__PURE__*/createElement("svg", _extends$5({
|
|
203
|
+
width: 24,
|
|
204
|
+
height: 24,
|
|
205
|
+
fill: "none",
|
|
206
|
+
xmlns: "http://www.w3.org/2000/svg"
|
|
207
|
+
}, props), _path$4 || (_path$4 = /*#__PURE__*/createElement("path", {
|
|
208
|
+
d: "M14.651 19.098L12 21.749l-2.652-2.651M12 15v6.75M9.348 4.902L12 2.25l2.651 2.652M12 9V2.25M4.902 14.65L2.25 12l2.652-2.652M9 12H2.25M19.098 9.348l2.652 2.651-2.652 2.652M15 12h6.75",
|
|
209
|
+
stroke: "currentColor",
|
|
210
|
+
strokeWidth: 1.5,
|
|
211
|
+
strokeLinecap: "round",
|
|
212
|
+
strokeLinejoin: "round"
|
|
213
|
+
})));
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
var _rect$2, _path$5;
|
|
217
|
+
|
|
218
|
+
function _extends$6() { _extends$6 = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends$6.apply(this, arguments); }
|
|
219
|
+
|
|
220
|
+
function SvgAlignStart(props) {
|
|
221
|
+
return /*#__PURE__*/createElement("svg", _extends$6({
|
|
222
|
+
width: 24,
|
|
223
|
+
height: 24,
|
|
224
|
+
fill: "none",
|
|
225
|
+
xmlns: "http://www.w3.org/2000/svg"
|
|
226
|
+
}, props), _rect$2 || (_rect$2 = /*#__PURE__*/createElement("rect", {
|
|
227
|
+
width: 24,
|
|
228
|
+
height: 24,
|
|
229
|
+
rx: 4,
|
|
230
|
+
fill: "#000",
|
|
231
|
+
fillOpacity: 0.5
|
|
232
|
+
})), _path$5 || (_path$5 = /*#__PURE__*/createElement("path", {
|
|
233
|
+
fillRule: "evenodd",
|
|
234
|
+
clipRule: "evenodd",
|
|
235
|
+
d: "M5 5h14v14H5V5zM4 4h16v16H4V4zm2 6a1 1 0 012 0v4a1 1 0 11-2 0v-4zm3 0a1 1 0 012 0v4a1 1 0 11-2 0v-4zm4-1a1 1 0 00-1 1v4a1 1 0 102 0v-4a1 1 0 00-1-1z",
|
|
236
|
+
fill: "currentColor"
|
|
237
|
+
})));
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
var _rect$3, _path$6;
|
|
241
|
+
|
|
242
|
+
function _extends$7() { _extends$7 = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends$7.apply(this, arguments); }
|
|
243
|
+
|
|
244
|
+
function SvgAlignCenter(props) {
|
|
245
|
+
return /*#__PURE__*/createElement("svg", _extends$7({
|
|
246
|
+
width: 24,
|
|
247
|
+
height: 24,
|
|
248
|
+
fill: "none",
|
|
249
|
+
xmlns: "http://www.w3.org/2000/svg"
|
|
250
|
+
}, props), _rect$3 || (_rect$3 = /*#__PURE__*/createElement("rect", {
|
|
251
|
+
width: 24,
|
|
252
|
+
height: 24,
|
|
253
|
+
rx: 4,
|
|
254
|
+
fill: "#000",
|
|
255
|
+
fillOpacity: 0.5
|
|
256
|
+
})), _path$6 || (_path$6 = /*#__PURE__*/createElement("path", {
|
|
257
|
+
fillRule: "evenodd",
|
|
258
|
+
clipRule: "evenodd",
|
|
259
|
+
d: "M19 19H5V5h14v14zm1 1H4V4h16v16zm-4-6a1 1 0 11-2 0v-4a1 1 0 112 0v4zm-3 0a1 1 0 11-2 0v-4a1 1 0 112 0v4zm-4 1a1 1 0 001-1v-4a1 1 0 10-2 0v4a1 1 0 001 1z",
|
|
260
|
+
fill: "currentColor"
|
|
261
|
+
})));
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
var _rect$4, _path$7;
|
|
265
|
+
|
|
266
|
+
function _extends$8() { _extends$8 = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends$8.apply(this, arguments); }
|
|
267
|
+
|
|
268
|
+
function SvgAlignEnd(props) {
|
|
269
|
+
return /*#__PURE__*/createElement("svg", _extends$8({
|
|
270
|
+
width: 24,
|
|
271
|
+
height: 24,
|
|
272
|
+
fill: "none",
|
|
273
|
+
xmlns: "http://www.w3.org/2000/svg"
|
|
274
|
+
}, props), _rect$4 || (_rect$4 = /*#__PURE__*/createElement("rect", {
|
|
275
|
+
width: 24,
|
|
276
|
+
height: 24,
|
|
277
|
+
rx: 4,
|
|
278
|
+
fill: "#000",
|
|
279
|
+
fillOpacity: 0.5
|
|
280
|
+
})), _path$7 || (_path$7 = /*#__PURE__*/createElement("path", {
|
|
281
|
+
fillRule: "evenodd",
|
|
282
|
+
clipRule: "evenodd",
|
|
283
|
+
d: "M19 19H5V5h14v14zm1 1H4V4h16v16zm-2-6a1 1 0 11-2 0v-4a1 1 0 112 0v4zm-3 0a1 1 0 11-2 0v-4a1 1 0 112 0v4zm-4 1a1 1 0 001-1v-4a1 1 0 10-2 0v4a1 1 0 001 1z",
|
|
284
|
+
fill: "currentColor"
|
|
285
|
+
})));
|
|
286
|
+
}
|
|
287
|
+
|
|
288
|
+
var _rect$5, _path$8;
|
|
289
|
+
|
|
290
|
+
function _extends$9() { _extends$9 = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends$9.apply(this, arguments); }
|
|
291
|
+
|
|
292
|
+
function SvgAlignStartV(props) {
|
|
293
|
+
return /*#__PURE__*/createElement("svg", _extends$9({
|
|
294
|
+
width: 24,
|
|
295
|
+
height: 24,
|
|
296
|
+
fill: "none",
|
|
297
|
+
xmlns: "http://www.w3.org/2000/svg"
|
|
298
|
+
}, props), _rect$5 || (_rect$5 = /*#__PURE__*/createElement("rect", {
|
|
299
|
+
y: 24,
|
|
300
|
+
width: 24,
|
|
301
|
+
height: 24,
|
|
302
|
+
rx: 4,
|
|
303
|
+
transform: "rotate(-90 0 24)",
|
|
304
|
+
fill: "#000",
|
|
305
|
+
fillOpacity: 0.5
|
|
306
|
+
})), _path$8 || (_path$8 = /*#__PURE__*/createElement("path", {
|
|
307
|
+
fillRule: "evenodd",
|
|
308
|
+
clipRule: "evenodd",
|
|
309
|
+
d: "M19 5v14H5V5h14zm1-1v16H4V4h16zm-6 2a1 1 0 110 2h-4a1 1 0 110-2h4zm0 3a1 1 0 110 2h-4a1 1 0 110-2h4zm1 4a1 1 0 00-1-1h-4a1 1 0 100 2h4a1 1 0 001-1z",
|
|
310
|
+
fill: "currentColor"
|
|
311
|
+
})));
|
|
312
|
+
}
|
|
313
|
+
|
|
314
|
+
var _rect$6, _path$9;
|
|
315
|
+
|
|
316
|
+
function _extends$a() { _extends$a = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends$a.apply(this, arguments); }
|
|
317
|
+
|
|
318
|
+
function SvgAlignCenterV(props) {
|
|
319
|
+
return /*#__PURE__*/createElement("svg", _extends$a({
|
|
320
|
+
width: 24,
|
|
321
|
+
height: 24,
|
|
322
|
+
fill: "none",
|
|
323
|
+
xmlns: "http://www.w3.org/2000/svg"
|
|
324
|
+
}, props), _rect$6 || (_rect$6 = /*#__PURE__*/createElement("rect", {
|
|
325
|
+
y: 24,
|
|
326
|
+
width: 24,
|
|
327
|
+
height: 24,
|
|
328
|
+
rx: 4,
|
|
329
|
+
transform: "rotate(-90 0 24)",
|
|
330
|
+
fill: "#000",
|
|
331
|
+
fillOpacity: 0.5
|
|
332
|
+
})), _path$9 || (_path$9 = /*#__PURE__*/createElement("path", {
|
|
333
|
+
fillRule: "evenodd",
|
|
334
|
+
clipRule: "evenodd",
|
|
335
|
+
d: "M19 5v14H5V5h14zm1-1v16H4V4h16zm-6 4a1 1 0 110 2h-4a1 1 0 110-2h4zm0 3a1 1 0 110 2h-4a1 1 0 110-2h4zm1 4a1 1 0 00-1-1h-4a1 1 0 100 2h4a1 1 0 001-1z",
|
|
336
|
+
fill: "currentColor"
|
|
337
|
+
})));
|
|
338
|
+
}
|
|
339
|
+
|
|
340
|
+
var _rect$7, _path$a;
|
|
341
|
+
|
|
342
|
+
function _extends$b() { _extends$b = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends$b.apply(this, arguments); }
|
|
343
|
+
|
|
344
|
+
function SvgAlignEndV(props) {
|
|
345
|
+
return /*#__PURE__*/createElement("svg", _extends$b({
|
|
346
|
+
width: 24,
|
|
347
|
+
height: 24,
|
|
348
|
+
fill: "none",
|
|
349
|
+
xmlns: "http://www.w3.org/2000/svg"
|
|
350
|
+
}, props), _rect$7 || (_rect$7 = /*#__PURE__*/createElement("rect", {
|
|
351
|
+
y: 24,
|
|
352
|
+
width: 24,
|
|
353
|
+
height: 24,
|
|
354
|
+
rx: 4,
|
|
355
|
+
transform: "rotate(-90 0 24)",
|
|
356
|
+
fill: "#000",
|
|
357
|
+
fillOpacity: 0.5
|
|
358
|
+
})), _path$a || (_path$a = /*#__PURE__*/createElement("path", {
|
|
359
|
+
fillRule: "evenodd",
|
|
360
|
+
clipRule: "evenodd",
|
|
361
|
+
d: "M5 19V5h14v14H5zm-1 1V4h16v16H4zm6-2a1 1 0 110-2h4a1 1 0 110 2h-4zm0-3a1 1 0 110-2h4a1 1 0 110 2h-4zm-1-4a1 1 0 001 1h4a1 1 0 100-2h-4a1 1 0 00-1 1z",
|
|
362
|
+
fill: "currentColor"
|
|
363
|
+
})));
|
|
364
|
+
}
|
|
365
|
+
|
|
366
|
+
var Icons = {
|
|
367
|
+
horizontalExtend: SvgHorizontalExtend,
|
|
368
|
+
horizontalNormal: SvgHorizontalNormal,
|
|
369
|
+
verticalExtend: SvgVerticalExtend,
|
|
370
|
+
verticalNormal: SvgVerticalNormal,
|
|
371
|
+
moveArrows: SvgMoveArrows,
|
|
372
|
+
alignStart: SvgAlignStart,
|
|
373
|
+
alignCenter: SvgAlignCenter,
|
|
374
|
+
alignEnd: SvgAlignEnd,
|
|
375
|
+
alignStartV: SvgAlignStartV,
|
|
376
|
+
alignCenterV: SvgAlignCenterV,
|
|
377
|
+
alignEndV: SvgAlignEndV
|
|
378
|
+
};
|
|
379
|
+
|
|
380
|
+
var IconStyles = function IconStyles(size) {
|
|
381
|
+
return css({
|
|
382
|
+
cursor: 'pointer',
|
|
383
|
+
width: size || 24 + 'px',
|
|
384
|
+
height: size || 24 + 'px',
|
|
385
|
+
' svg': {
|
|
386
|
+
height: size || 24 + 'px',
|
|
387
|
+
width: size || 24 + 'px'
|
|
388
|
+
}
|
|
389
|
+
});
|
|
390
|
+
};
|
|
391
|
+
|
|
392
|
+
var Icon = function Icon(_ref) {
|
|
393
|
+
var className = _ref.className,
|
|
394
|
+
name = _ref.name,
|
|
395
|
+
size = _ref.size,
|
|
396
|
+
onClick = _ref.onClick,
|
|
397
|
+
styles = _ref.styles;
|
|
398
|
+
var LocalIconComponent = Icons[name];
|
|
399
|
+
return React__default.createElement(LocalIconComponent, Object.assign({
|
|
400
|
+
className: className
|
|
401
|
+
}, IconStyles(size), {
|
|
402
|
+
style: styles,
|
|
403
|
+
onClick: onClick
|
|
404
|
+
}));
|
|
405
|
+
};
|
|
406
|
+
|
|
407
|
+
var ItemType = {
|
|
408
|
+
ITEM: 'react-align_item',
|
|
409
|
+
GROUP: 'react-align_group'
|
|
410
|
+
};
|
|
411
|
+
|
|
412
|
+
var GridItem = function GridItem(_ref) {
|
|
413
|
+
var className = _ref.className,
|
|
414
|
+
children = _ref.children,
|
|
415
|
+
id = _ref.id,
|
|
416
|
+
index = _ref.index,
|
|
417
|
+
extendable = _ref.extendable,
|
|
418
|
+
extended = _ref.extended,
|
|
419
|
+
draggable = _ref.draggable,
|
|
420
|
+
onReorder = _ref.onReorder,
|
|
421
|
+
onMoveArea = _ref.onMoveArea,
|
|
422
|
+
onExtend = _ref.onExtend,
|
|
423
|
+
location = _ref.location,
|
|
424
|
+
end = _ref.end,
|
|
425
|
+
vertical = _ref.vertical,
|
|
426
|
+
styles = _ref.styles,
|
|
427
|
+
editorStyles = _ref.editorStyles,
|
|
428
|
+
iconSize = _ref.iconSize,
|
|
429
|
+
_ref$iconColor = _ref.iconColor,
|
|
430
|
+
iconColor = _ref$iconColor === void 0 ? 'rgb(255, 255, 255)' : _ref$iconColor;
|
|
431
|
+
var ref = useRef(null);
|
|
432
|
+
|
|
433
|
+
var _useEditorMode = useEditorMode(),
|
|
434
|
+
enabled = _useEditorMode.enabled;
|
|
435
|
+
|
|
436
|
+
var _useState = useState(false),
|
|
437
|
+
isHovered = _useState[0],
|
|
438
|
+
setHovered = _useState[1];
|
|
439
|
+
|
|
440
|
+
var handleExtend = function handleExtend() {
|
|
441
|
+
if (!extendable || !onExtend) return;
|
|
442
|
+
setHovered(false);
|
|
443
|
+
onExtend(id, !extended);
|
|
444
|
+
}; // ***************************************
|
|
445
|
+
// Drag n drop logic
|
|
446
|
+
|
|
447
|
+
|
|
448
|
+
var _useDrop = useDrop({
|
|
449
|
+
accept: [ItemType.ITEM, ItemType.GROUP],
|
|
450
|
+
collect: function collect(monitor) {
|
|
451
|
+
return {
|
|
452
|
+
handlerId: monitor.getHandlerId()
|
|
453
|
+
};
|
|
454
|
+
},
|
|
455
|
+
hover: function hover(item, monitor) {
|
|
456
|
+
var _ref$current;
|
|
457
|
+
|
|
458
|
+
if (!ref.current || !enabled || draggable) {
|
|
459
|
+
return;
|
|
460
|
+
}
|
|
461
|
+
|
|
462
|
+
var dragIndex = item.index;
|
|
463
|
+
var hoverIndex = index;
|
|
464
|
+
|
|
465
|
+
if (dragIndex === hoverIndex) {
|
|
466
|
+
return;
|
|
467
|
+
}
|
|
468
|
+
|
|
469
|
+
var hoverBoundingRect = (_ref$current = ref.current) == null ? void 0 : _ref$current.getBoundingClientRect();
|
|
470
|
+
var hoverMiddleY = (hoverBoundingRect.bottom - hoverBoundingRect.top) / 2;
|
|
471
|
+
var hoverMiddleX = (hoverBoundingRect.right - hoverBoundingRect.left) / 2;
|
|
472
|
+
var clientOffset = monitor.getClientOffset();
|
|
473
|
+
if (!clientOffset) return;
|
|
474
|
+
var hoverClientY = clientOffset.y - hoverBoundingRect.top;
|
|
475
|
+
var hoverClientX = clientOffset.x - hoverBoundingRect.left;
|
|
476
|
+
|
|
477
|
+
if (vertical) {
|
|
478
|
+
if (dragIndex < hoverIndex && hoverClientY < hoverMiddleY) {
|
|
479
|
+
return;
|
|
480
|
+
}
|
|
481
|
+
|
|
482
|
+
if (dragIndex > hoverIndex && hoverClientY > hoverMiddleY) {
|
|
483
|
+
return;
|
|
484
|
+
}
|
|
485
|
+
} else {
|
|
486
|
+
if (dragIndex < hoverIndex && hoverClientX < hoverMiddleX) {
|
|
487
|
+
return;
|
|
488
|
+
}
|
|
489
|
+
|
|
490
|
+
if (dragIndex > hoverIndex && hoverClientX > hoverMiddleX) {
|
|
491
|
+
return;
|
|
492
|
+
}
|
|
493
|
+
}
|
|
494
|
+
|
|
495
|
+
onReorder(item.id, location, dragIndex, hoverIndex);
|
|
496
|
+
}
|
|
497
|
+
}),
|
|
498
|
+
handlerId = _useDrop[0].handlerId,
|
|
499
|
+
drop = _useDrop[1];
|
|
500
|
+
|
|
501
|
+
var _useDrag = useDrag({
|
|
502
|
+
type: ItemType.ITEM,
|
|
503
|
+
item: {
|
|
504
|
+
id: id,
|
|
505
|
+
index: index
|
|
506
|
+
},
|
|
507
|
+
canDrag: draggable != null ? draggable : enabled,
|
|
508
|
+
end: function end(item, monitor) {
|
|
509
|
+
var dropResults = monitor.getDropResult();
|
|
510
|
+
|
|
511
|
+
if (dropResults) {
|
|
512
|
+
onMoveArea(item.id, dropResults.location, location);
|
|
513
|
+
}
|
|
514
|
+
},
|
|
515
|
+
collect: function collect(monitor) {
|
|
516
|
+
return {
|
|
517
|
+
isDragging: monitor.isDragging()
|
|
518
|
+
};
|
|
519
|
+
}
|
|
520
|
+
}),
|
|
521
|
+
isDragging = _useDrag[0].isDragging,
|
|
522
|
+
drag = _useDrag[1],
|
|
523
|
+
preview = _useDrag[2];
|
|
524
|
+
|
|
525
|
+
preview(drop(ref)); // ***************************************
|
|
526
|
+
// ***************************************
|
|
527
|
+
// External styles for editorMode or the vanilla grid
|
|
528
|
+
|
|
529
|
+
var stylesFromProps = enabled ? editorStyles : styles;
|
|
530
|
+
var itemStyles = useMemo(function () {
|
|
531
|
+
return {
|
|
532
|
+
opacity: isDragging ? 0.5 : 1,
|
|
533
|
+
minHeight: isHovered && enabled ? '40px' : undefined,
|
|
534
|
+
width: !vertical && extended ? '100%' : undefined,
|
|
535
|
+
minWidth: isHovered && enabled ? extendable ? '70px' : '30px' : undefined,
|
|
536
|
+
height: vertical && extended ? '100%' : undefined
|
|
537
|
+
};
|
|
538
|
+
}, [isDragging, isHovered, enabled, vertical, extended, extendable]);
|
|
539
|
+
var containerStyle = useMemo(function () {
|
|
540
|
+
return {
|
|
541
|
+
position: 'relative',
|
|
542
|
+
display: 'inline-block',
|
|
543
|
+
minHeight: isHovered && enabled ? '40px' : undefined,
|
|
544
|
+
width: !vertical && extended ? '100%' : undefined,
|
|
545
|
+
minWidth: isHovered && enabled ? extendable ? '70px' : '30px' : undefined,
|
|
546
|
+
height: vertical && extended ? '100%' : undefined
|
|
547
|
+
};
|
|
548
|
+
}, [isHovered, enabled, vertical, extended, extendable]);
|
|
549
|
+
var overlayStyles = {
|
|
550
|
+
position: 'absolute',
|
|
551
|
+
top: '0',
|
|
552
|
+
left: '0',
|
|
553
|
+
width: '100%',
|
|
554
|
+
height: '100%',
|
|
555
|
+
boxSizing: 'border-box',
|
|
556
|
+
background: 'rgba(0,0,0,0.6)',
|
|
557
|
+
borderRadius: '6px'
|
|
558
|
+
};
|
|
559
|
+
var buttonStyles = useMemo(function () {
|
|
560
|
+
return {
|
|
561
|
+
display: 'flex',
|
|
562
|
+
alignItems: end ? 'end' : 'start',
|
|
563
|
+
justifyContent: 'space-between',
|
|
564
|
+
padding: '6px',
|
|
565
|
+
"float": end ? 'right' : 'left'
|
|
566
|
+
};
|
|
567
|
+
}, [end]); // ***************************************
|
|
568
|
+
|
|
569
|
+
var childrenWithParentProps = React__default.Children.map(children, function (child) {
|
|
570
|
+
return React__default.cloneElement(child, {
|
|
571
|
+
extended: extended
|
|
572
|
+
});
|
|
573
|
+
});
|
|
574
|
+
return React__default.createElement("div", {
|
|
575
|
+
id: id,
|
|
576
|
+
ref: ref,
|
|
577
|
+
"data-handler-id": handlerId,
|
|
578
|
+
className: className + " item",
|
|
579
|
+
style: _extends({}, itemStyles, stylesFromProps),
|
|
580
|
+
onMouseEnter: function onMouseEnter() {
|
|
581
|
+
return setHovered(true);
|
|
582
|
+
},
|
|
583
|
+
onMouseLeave: function onMouseLeave() {
|
|
584
|
+
return setHovered(false);
|
|
585
|
+
}
|
|
586
|
+
}, React__default.createElement("div", {
|
|
587
|
+
style: containerStyle
|
|
588
|
+
}, (draggable != null ? draggable : enabled) && isHovered && React__default.createElement("div", {
|
|
589
|
+
style: overlayStyles
|
|
590
|
+
}, React__default.createElement("div", {
|
|
591
|
+
style: buttonStyles
|
|
592
|
+
}, React__default.createElement("div", {
|
|
593
|
+
ref: drag
|
|
594
|
+
}, React__default.createElement(Icon, {
|
|
595
|
+
name: "moveArrows",
|
|
596
|
+
size: iconSize,
|
|
597
|
+
styles: {
|
|
598
|
+
color: iconColor
|
|
599
|
+
}
|
|
600
|
+
})), extendable && React__default.createElement(Icon, {
|
|
601
|
+
name: vertical ? 'verticalExtend' : 'horizontalExtend',
|
|
602
|
+
size: iconSize,
|
|
603
|
+
styles: {
|
|
604
|
+
color: iconColor,
|
|
605
|
+
marginLeft: '8px'
|
|
606
|
+
},
|
|
607
|
+
onClick: handleExtend
|
|
608
|
+
}))), childrenWithParentProps));
|
|
609
|
+
};
|
|
610
|
+
|
|
611
|
+
var GridArea = function GridArea(_ref) {
|
|
612
|
+
var className = _ref.className,
|
|
613
|
+
vertical = _ref.vertical,
|
|
614
|
+
reverse = _ref.reverse,
|
|
615
|
+
stretch = _ref.stretch,
|
|
616
|
+
end = _ref.end,
|
|
617
|
+
droppable = _ref.droppable,
|
|
618
|
+
align = _ref.align,
|
|
619
|
+
onAlignChange = _ref.onAlignChange,
|
|
620
|
+
location = _ref.location,
|
|
621
|
+
children = _ref.children,
|
|
622
|
+
styles = _ref.styles,
|
|
623
|
+
editorStyles = _ref.editorStyles,
|
|
624
|
+
_ref$iconColor = _ref.iconColor,
|
|
625
|
+
iconColor = _ref$iconColor === void 0 ? '#FFFFFF' : _ref$iconColor;
|
|
626
|
+
|
|
627
|
+
var _useEditorMode = useEditorMode(),
|
|
628
|
+
enabled = _useEditorMode.enabled;
|
|
629
|
+
|
|
630
|
+
var handleAlignChange = useCallback(function (align) {
|
|
631
|
+
switch (align) {
|
|
632
|
+
case 'start':
|
|
633
|
+
onAlignChange == null ? void 0 : onAlignChange('centered');
|
|
634
|
+
break;
|
|
635
|
+
|
|
636
|
+
case 'centered':
|
|
637
|
+
onAlignChange == null ? void 0 : onAlignChange('end');
|
|
638
|
+
break;
|
|
639
|
+
|
|
640
|
+
default:
|
|
641
|
+
onAlignChange == null ? void 0 : onAlignChange('start');
|
|
642
|
+
break;
|
|
643
|
+
}
|
|
644
|
+
}, [onAlignChange]); // ***************************************
|
|
645
|
+
// Drop logic
|
|
646
|
+
|
|
647
|
+
var _useDrop = useDrop(function () {
|
|
648
|
+
return {
|
|
649
|
+
accept: [ItemType.ITEM, ItemType.GROUP],
|
|
650
|
+
drop: function drop() {
|
|
651
|
+
return {
|
|
652
|
+
location: location
|
|
653
|
+
};
|
|
654
|
+
},
|
|
655
|
+
collect: function collect(monitor) {
|
|
656
|
+
return {
|
|
657
|
+
isOver: monitor.isOver()
|
|
658
|
+
};
|
|
659
|
+
}
|
|
660
|
+
};
|
|
661
|
+
}),
|
|
662
|
+
isOver = _useDrop[0].isOver,
|
|
663
|
+
drop = _useDrop[1]; // ***************************************
|
|
664
|
+
// ***************************************
|
|
665
|
+
// Internal styles used
|
|
666
|
+
|
|
667
|
+
|
|
668
|
+
var buttonStyle = useMemo(function () {
|
|
669
|
+
return {
|
|
670
|
+
position: 'absolute',
|
|
671
|
+
left: vertical ? end ? 0 : undefined : '50%',
|
|
672
|
+
right: vertical ? !end ? 0 : undefined : '50%',
|
|
673
|
+
bottom: !vertical && !end ? 0 : vertical ? '50%' : undefined,
|
|
674
|
+
top: vertical ? '50%' : end ? 0 : undefined,
|
|
675
|
+
opacity: (droppable != null ? droppable : enabled) && align ? 1 : 0,
|
|
676
|
+
transition: 'all 0.5s ease-in-out'
|
|
677
|
+
};
|
|
678
|
+
}, [vertical, end, droppable, enabled, align]);
|
|
679
|
+
var mainStyles = useMemo(function () {
|
|
680
|
+
return {
|
|
681
|
+
opacity: isOver ? 0.8 : 1,
|
|
682
|
+
minHeight: !React__default.Children.count(children) && !enabled ? '0px' : '26px',
|
|
683
|
+
minWidth: !React__default.Children.count(children) && !enabled ? '0px' : '46px'
|
|
684
|
+
};
|
|
685
|
+
}, [isOver, children, enabled]);
|
|
686
|
+
var stylesFromProps = enabled ? editorStyles : styles; // ***************************************
|
|
687
|
+
// Rebuilds the GridItem children to receive their parent GridArea's 'end' and 'vertical' values.
|
|
688
|
+
// Used to know where to align the overlay buttons (end) and how to extend the GridItems (vertical).
|
|
689
|
+
|
|
690
|
+
var childrenWithParentProps = React__default.Children.map(children, function (child) {
|
|
691
|
+
return React__default.cloneElement(child, {
|
|
692
|
+
end: end,
|
|
693
|
+
vertical: vertical,
|
|
694
|
+
location: location
|
|
695
|
+
});
|
|
696
|
+
});
|
|
697
|
+
return React__default.createElement("div", {
|
|
698
|
+
ref: drop,
|
|
699
|
+
className: "\n " + className + "\n area\n " + (stretch && 'stretch') + "\n " + (end && 'end') + "\n " + (align === 'centered' ? 'just-centered' : align === 'end' ? 'just-end' : 'start') + "\n " + (vertical ? reverse ? 'vertical-r' : 'vertical' : reverse ? 'horizontal-r' : 'horizontal') + "\n " + (enabled ? 'area-transition-in' : 'area-transition-out') + "\n ",
|
|
700
|
+
style: _extends({}, mainStyles, stylesFromProps)
|
|
701
|
+
}, childrenWithParentProps, React__default.createElement("div", {
|
|
702
|
+
style: buttonStyle
|
|
703
|
+
}, React__default.createElement(Icon, {
|
|
704
|
+
name: align === 'centered' ? vertical ? 'alignCenterV' : 'alignCenter' : align === 'end' ? vertical ? 'alignEndV' : 'alignEnd' : vertical ? 'alignStartV' : 'alignStart',
|
|
705
|
+
styles: {
|
|
706
|
+
color: iconColor,
|
|
707
|
+
cursor: (droppable != null ? droppable : enabled) && align && !!React__default.Children.count(children) ? 'pointer' : 'default'
|
|
708
|
+
},
|
|
709
|
+
onClick: (droppable != null ? droppable : enabled) && align && !!React__default.Children.count(children) ? function () {
|
|
710
|
+
return handleAlignChange(align);
|
|
711
|
+
} : undefined
|
|
712
|
+
})));
|
|
713
|
+
};
|
|
714
|
+
|
|
715
|
+
export { GridArea, GridItem, GridSection, GridWrapper, Icon };
|
|
716
|
+
//# sourceMappingURL=react-align.esm.js.map
|