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