publ-echo 0.0.1

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 (57) hide show
  1. package/README.md +29 -0
  2. package/bin/cli.js +8 -0
  3. package/bitbucket-pipelines.yml +35 -0
  4. package/package.json +51 -0
  5. package/public/favicon.ico +0 -0
  6. package/public/index.html +43 -0
  7. package/public/logo192.png +0 -0
  8. package/public/logo512.png +0 -0
  9. package/public/manifest.json +25 -0
  10. package/public/robots.txt +3 -0
  11. package/src/App.tsx +28 -0
  12. package/src/examples/ReactGridLayout/ReactGridLayoutShowcase01.tsx +80 -0
  13. package/src/examples/ReactGridLayout/index.ts +1 -0
  14. package/src/examples/ResponsiveGridLayout/ResponsiveGridLayoutShowcase01.tsx +114 -0
  15. package/src/examples/ResponsiveGridLayout/index.ts +1 -0
  16. package/src/examples/index.ts +2 -0
  17. package/src/examples/utils.ts +15 -0
  18. package/src/index.tsx +21 -0
  19. package/src/lib/Draggable/Draggable.tsx +303 -0
  20. package/src/lib/Draggable/DraggableCore.tsx +352 -0
  21. package/src/lib/Draggable/constants.ts +12 -0
  22. package/src/lib/Draggable/index.ts +2 -0
  23. package/src/lib/Draggable/types.ts +74 -0
  24. package/src/lib/Draggable/utils/domHelpers.ts +284 -0
  25. package/src/lib/Draggable/utils/getPrefix.ts +42 -0
  26. package/src/lib/Draggable/utils/positionHelpers.ts +49 -0
  27. package/src/lib/Draggable/utils/types.ts +41 -0
  28. package/src/lib/Draggable/utils/validationHelpers.ts +23 -0
  29. package/src/lib/GridItem/GridItem.tsx +493 -0
  30. package/src/lib/GridItem/index.ts +1 -0
  31. package/src/lib/GridItem/types.ts +121 -0
  32. package/src/lib/GridItem/utils/calculateUtils.ts +173 -0
  33. package/src/lib/GridLayoutEditor/ReactGridLayout.tsx +662 -0
  34. package/src/lib/GridLayoutEditor/ResponsiveGridLayout.tsx +204 -0
  35. package/src/lib/GridLayoutEditor/index.ts +9 -0
  36. package/src/lib/GridLayoutEditor/styles/styles.css +133 -0
  37. package/src/lib/GridLayoutEditor/types.ts +199 -0
  38. package/src/lib/GridLayoutEditor/utils/renderHelpers.ts +737 -0
  39. package/src/lib/GridLayoutEditor/utils/responsiveUtils.ts +111 -0
  40. package/src/lib/PreviewGLE/ReactGridLayoutPreview.tsx +46 -0
  41. package/src/lib/PreviewGLE/ResponsiveGridLayoutPreview.tsx +54 -0
  42. package/src/lib/PreviewGLE/index.ts +2 -0
  43. package/src/lib/Resizable/Resizable.tsx +323 -0
  44. package/src/lib/Resizable/ResizableBox.tsx +109 -0
  45. package/src/lib/Resizable/index.ts +1 -0
  46. package/src/lib/Resizable/styles/styles.css +76 -0
  47. package/src/lib/Resizable/types.ts +96 -0
  48. package/src/lib/Resizable/utils/cloneElement.ts +15 -0
  49. package/src/lib/components/WidthProvider.tsx +71 -0
  50. package/src/lib/components/index.ts +1 -0
  51. package/src/lib/components/types.ts +19 -0
  52. package/src/lib/index.ts +4 -0
  53. package/src/react-app-env.d.ts +1 -0
  54. package/src/reportWebVitals.ts +15 -0
  55. package/src/setupTests.ts +5 -0
  56. package/src/utils/types.ts +3 -0
  57. package/tsconfig.json +26 -0
@@ -0,0 +1,173 @@
1
+ import { ResizeHandleAxis } from "../../Resizable/types";
2
+ import { Position, PositionParams } from "../../GridLayoutEditor/types";
3
+
4
+ export type RowHeight = number | ((width: number) => number);
5
+
6
+ export function calcGridColWidth(positionParams: PositionParams): number {
7
+ const { margin, containerPadding, containerWidth, cols } = positionParams;
8
+
9
+ return (
10
+ (containerWidth - margin[0] * (cols - 1) - containerPadding[0] * 2) / cols
11
+ );
12
+ }
13
+
14
+ export function calcGridItemWHPx(
15
+ gridUnits: number,
16
+ colOrRowSize: number,
17
+ marginPx: number
18
+ ): number {
19
+ if (!Number.isFinite(gridUnits)) return gridUnits;
20
+
21
+ return Math.round(
22
+ colOrRowSize * gridUnits + Math.max(0, gridUnits - 1) * marginPx
23
+ );
24
+ }
25
+
26
+ export const resolveRowHeight = (rowHeight: RowHeight, width: number) =>
27
+ typeof rowHeight === "number" ? rowHeight : rowHeight(width);
28
+
29
+ export function calcGridItemPosition(
30
+ positionParams: PositionParams,
31
+ x: number,
32
+ y: number,
33
+ z: number,
34
+ w: number,
35
+ h: number,
36
+ state?: {
37
+ resizing?: { width: number; height: number; top: number; left: number };
38
+ dragging?: { top: number; left: number };
39
+ }
40
+ ): Position {
41
+ const { margin, containerPadding, rowHeight } = positionParams;
42
+ const colWidth = calcGridColWidth(positionParams);
43
+ const rowHeightNumber = resolveRowHeight(rowHeight, colWidth);
44
+
45
+ const result = {
46
+ left: Math.round((colWidth + margin[0]) * x + containerPadding[0]),
47
+ top: Math.round((rowHeightNumber + margin[1]) * y + containerPadding[1]),
48
+ width: w === Infinity ? w : calcGridItemWHPx(w, colWidth, margin[0]),
49
+ height:
50
+ h === Infinity ? h : calcGridItemWHPx(h, rowHeightNumber, margin[1]),
51
+ };
52
+
53
+ if (state && state.resizing) {
54
+ result.width = Math.round(state.resizing.width);
55
+ result.height = Math.round(state.resizing.height);
56
+ result.top = Math.round(state.resizing.top);
57
+ result.left = Math.round(state.resizing.left);
58
+ } else {
59
+ result.width = calcGridItemWHPx(w, colWidth, margin[0]);
60
+ result.height = calcGridItemWHPx(h, rowHeightNumber, margin[1]);
61
+ }
62
+
63
+ if (state && state.dragging) {
64
+ result.top = Math.round(state.dragging.top);
65
+ result.left = Math.round(state.dragging.left);
66
+ } else {
67
+ result.top = Math.round(
68
+ (rowHeightNumber + margin[1]) * y + containerPadding[1]
69
+ );
70
+ result.left = Math.round((colWidth + margin[0]) * x + containerPadding[0]);
71
+ }
72
+
73
+ // result.z = z;
74
+
75
+ return result;
76
+ }
77
+
78
+ export function calcXY(
79
+ positionParams: PositionParams,
80
+ top: number,
81
+ left: number,
82
+ w: number,
83
+ h: number
84
+ ): { x: number; y: number } {
85
+ const { margin, cols, rowHeight, maxRows } = positionParams;
86
+ const colWidth = calcGridColWidth(positionParams);
87
+ const rowHeightNumber = resolveRowHeight(rowHeight, colWidth);
88
+
89
+ let x = Math.round((left - margin[0]) / (colWidth + margin[0]));
90
+ let y = Math.round((top - margin[1]) / (rowHeightNumber + margin[1]));
91
+
92
+ // Capping
93
+ x = clamp(x, 0, cols - w);
94
+ y = clamp(y, 0, maxRows - h);
95
+
96
+ return { x, y };
97
+ }
98
+
99
+ export function calcWH(
100
+ positionParams: PositionParams,
101
+ { width, height }: { width: number; height: number },
102
+ x: number,
103
+ y: number,
104
+ handleAxis?: ResizeHandleAxis,
105
+ prevW?: number,
106
+ prevH?: number
107
+ ): { w: number; h: number } {
108
+ const { margin, maxRows, cols, rowHeight } = positionParams;
109
+ const colWidth = calcGridColWidth(positionParams);
110
+ const rowHeightNumber = resolveRowHeight(rowHeight, colWidth);
111
+
112
+ let w = Math.round((width + margin[0]) / (colWidth + margin[0]));
113
+ let h = Math.round((height + margin[1]) / (rowHeightNumber + margin[1]));
114
+
115
+ // // Capping
116
+ // w = clamp(w, 0, cols - x);
117
+ // h = clamp(h, 0, maxRows - y);
118
+
119
+ if (handleAxis === "nw") {
120
+ if (x <= 0 && y <= 0 && prevW && prevH) {
121
+ w = Math.max(Math.min(w, prevW), 0);
122
+ h = Math.max(Math.min(h, prevH), 0);
123
+ }
124
+
125
+ if (x <= 0 && prevW) {
126
+ w = Math.max(Math.min(w, prevW), 0);
127
+ h = Math.max(Math.min(h, maxRows - y), 0);
128
+ }
129
+
130
+ if (y <= 0 && prevH) {
131
+ h = Math.max(Math.min(h, prevH), 0);
132
+ }
133
+ }
134
+
135
+ if (handleAxis === "w" || handleAxis === "sw") {
136
+ if (x <= 0 && prevW) {
137
+ w = Math.max(Math.min(w, prevW), 0);
138
+ h = Math.max(Math.min(h, maxRows - y), 0);
139
+ }
140
+ }
141
+
142
+ if (handleAxis === "n") {
143
+ if (y <= 0 && prevH) {
144
+ w = Math.max(Math.min(w, cols - x), 0);
145
+ h = Math.max(Math.min(h, prevH), 0);
146
+ }
147
+ }
148
+
149
+ if (handleAxis === "ne") {
150
+ if (y <= 0 && prevH) {
151
+ w = Math.max(Math.min(w, cols - x), 0);
152
+ h = Math.max(Math.min(h, prevH), 0);
153
+ } else {
154
+ w = Math.max(Math.min(w, cols - x), 0);
155
+ h = Math.max(Math.min(h, maxRows - y), 0);
156
+ }
157
+ }
158
+
159
+ if (handleAxis === "e" || handleAxis === "se") {
160
+ w = Math.max(Math.min(w, cols - x), 0);
161
+ h = Math.max(Math.min(h, maxRows - y), 0);
162
+ }
163
+
164
+ return { w, h };
165
+ }
166
+
167
+ export function clamp(
168
+ num: number,
169
+ lowerBound: number,
170
+ upperBound: number
171
+ ): number {
172
+ return Math.max(Math.min(num, upperBound), lowerBound);
173
+ }