@fangzhongya/page 0.0.31 → 0.0.32
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/dist/_virtual/browser-detector.cjs +4 -0
- package/dist/_virtual/browser-detector.js +4 -0
- package/dist/_virtual/collection-utils.cjs +4 -0
- package/dist/_virtual/collection-utils.js +4 -0
- package/dist/_virtual/element-resize-detector.cjs +7 -0
- package/dist/_virtual/element-resize-detector.js +7 -0
- package/dist/_virtual/utils.cjs +4 -0
- package/dist/_virtual/utils.js +4 -0
- package/dist/components/design/design-grids2.cjs +15 -7
- package/dist/components/design/design-grids2.js +17 -9
- package/dist/components/design/design-operate2.cjs +2 -6
- package/dist/components/design/design-operate2.js +2 -6
- package/dist/components/design/design-resizable2.cjs +8 -3
- package/dist/components/design/design-resizable2.js +9 -4
- package/dist/components/design/grids/components/GridItem.cjs +5 -0
- package/dist/components/design/grids/components/GridItem.css +60 -0
- package/dist/components/design/grids/components/GridItem.js +5 -0
- package/dist/components/design/grids/components/GridItem2.cjs +502 -0
- package/dist/components/design/grids/components/GridItem2.js +502 -0
- package/dist/components/design/grids/components/GridLayout.cjs +5 -0
- package/dist/components/design/grids/components/GridLayout.css +5 -0
- package/dist/components/design/grids/components/GridLayout.js +5 -0
- package/dist/components/design/grids/components/GridLayout2.cjs +432 -0
- package/dist/components/design/grids/components/GridLayout2.js +432 -0
- package/dist/components/design/grids/composables/useGridProvider.cjs +13 -0
- package/dist/components/design/grids/composables/useGridProvider.d.ts +1 -0
- package/dist/components/design/grids/composables/useGridProvider.js +13 -0
- package/dist/components/design/grids/constants.cjs +8 -0
- package/dist/components/design/grids/constants.d.ts +5 -0
- package/dist/components/design/grids/constants.js +8 -0
- package/dist/components/design/grids/helpers/DOM.cjs +15 -0
- package/dist/components/design/grids/helpers/DOM.d.ts +2 -0
- package/dist/components/design/grids/helpers/DOM.js +15 -0
- package/dist/components/design/grids/helpers/draggableUtils.cjs +17 -0
- package/dist/components/design/grids/helpers/draggableUtils.d.ts +12 -0
- package/dist/components/design/grids/helpers/draggableUtils.js +17 -0
- package/dist/components/design/grids/helpers/responsiveUtils.cjs +43 -0
- package/dist/components/design/grids/helpers/responsiveUtils.d.ts +5 -0
- package/dist/components/design/grids/helpers/responsiveUtils.js +43 -0
- package/dist/components/design/grids/helpers/utils.cjs +222 -0
- package/dist/components/design/grids/helpers/utils.d.ts +24 -0
- package/dist/components/design/grids/helpers/utils.js +222 -0
- package/dist/components/design/grids/types/components.d.ts +20 -0
- package/dist/components/design/grids/types/grid-item.d.ts +45 -0
- package/dist/components/design/grids/types/grid-layout.d.ts +48 -0
- package/dist/components/design/grids/types/helpers.cjs +10 -0
- package/dist/components/design/grids/types/helpers.d.ts +33 -0
- package/dist/components/design/grids/types/helpers.js +10 -0
- package/dist/components/design/grids/types/index.d.ts +4 -0
- package/dist/components/design/{resizable2.cjs → resizable/resizable2.cjs} +21 -20
- package/dist/components/design/{resizable2.js → resizable/resizable2.js} +21 -20
- package/dist/components/index.css +33 -85
- package/dist/components/index2.cjs +22 -13
- package/dist/components/index2.js +23 -14
- package/dist/components/set/util.cjs +4 -2
- package/dist/components/set/util.d.ts +1 -0
- package/dist/components/set/util.js +4 -2
- package/dist/components/top/index2.cjs +47 -21
- package/dist/components/top/index2.js +53 -27
- package/dist/config/basics.cjs +2 -2
- package/dist/config/basics.js +2 -2
- package/dist/css/style.css +1361 -0
- package/dist/css/style2.css +5 -0
- package/dist/css/style3.css +3 -0
- package/dist/css/style4.css +117 -0
- package/dist/css/style5.css +5 -0
- package/dist/css/style6.css +60 -0
- package/dist/effect/design.cjs +1 -3
- package/dist/effect/design.js +1 -3
- package/dist/expand/{chunk-DSW4WFHO.cjs → chunk-QFRDDTJR.cjs} +1 -1
- package/dist/expand/{chunk-JTAMOZ6S.js → chunk-WMN3TQLR.js} +1 -1
- package/dist/expand/components.cjs +3 -3
- package/dist/expand/components.js +1 -1
- package/dist/expand/config.cjs +2 -2
- package/dist/expand/config.js +1 -1
- package/dist/index.css +1554 -0
- package/dist/node_modules/.pnpm/batch-processor@1.0.0/node_modules/batch-processor/src/batch-processor.cjs +121 -0
- package/dist/node_modules/.pnpm/batch-processor@1.0.0/node_modules/batch-processor/src/batch-processor.js +121 -0
- package/dist/node_modules/.pnpm/batch-processor@1.0.0/node_modules/batch-processor/src/utils.cjs +22 -0
- package/dist/node_modules/.pnpm/batch-processor@1.0.0/node_modules/batch-processor/src/utils.js +22 -0
- package/dist/node_modules/.pnpm/element-resize-detector@1.2.4/node_modules/element-resize-detector/src/browser-detector.cjs +37 -0
- package/dist/node_modules/.pnpm/element-resize-detector@1.2.4/node_modules/element-resize-detector/src/browser-detector.js +37 -0
- package/dist/node_modules/.pnpm/element-resize-detector@1.2.4/node_modules/element-resize-detector/src/collection-utils.cjs +22 -0
- package/dist/node_modules/.pnpm/element-resize-detector@1.2.4/node_modules/element-resize-detector/src/collection-utils.js +22 -0
- package/dist/node_modules/.pnpm/element-resize-detector@1.2.4/node_modules/element-resize-detector/src/detection-strategy/object.cjs +165 -0
- package/dist/node_modules/.pnpm/element-resize-detector@1.2.4/node_modules/element-resize-detector/src/detection-strategy/object.js +165 -0
- package/dist/node_modules/.pnpm/element-resize-detector@1.2.4/node_modules/element-resize-detector/src/detection-strategy/scroll.cjs +493 -0
- package/dist/node_modules/.pnpm/element-resize-detector@1.2.4/node_modules/element-resize-detector/src/detection-strategy/scroll.js +493 -0
- package/dist/node_modules/.pnpm/element-resize-detector@1.2.4/node_modules/element-resize-detector/src/element-resize-detector.cjs +241 -0
- package/dist/node_modules/.pnpm/element-resize-detector@1.2.4/node_modules/element-resize-detector/src/element-resize-detector.js +241 -0
- package/dist/node_modules/.pnpm/element-resize-detector@1.2.4/node_modules/element-resize-detector/src/element-utils.cjs +34 -0
- package/dist/node_modules/.pnpm/element-resize-detector@1.2.4/node_modules/element-resize-detector/src/element-utils.js +34 -0
- package/dist/node_modules/.pnpm/element-resize-detector@1.2.4/node_modules/element-resize-detector/src/id-generator.cjs +21 -0
- package/dist/node_modules/.pnpm/element-resize-detector@1.2.4/node_modules/element-resize-detector/src/id-generator.js +21 -0
- package/dist/node_modules/.pnpm/element-resize-detector@1.2.4/node_modules/element-resize-detector/src/id-handler.cjs +36 -0
- package/dist/node_modules/.pnpm/element-resize-detector@1.2.4/node_modules/element-resize-detector/src/id-handler.js +36 -0
- package/dist/node_modules/.pnpm/element-resize-detector@1.2.4/node_modules/element-resize-detector/src/listener-handler.cjs +51 -0
- package/dist/node_modules/.pnpm/element-resize-detector@1.2.4/node_modules/element-resize-detector/src/listener-handler.js +51 -0
- package/dist/node_modules/.pnpm/element-resize-detector@1.2.4/node_modules/element-resize-detector/src/reporter.cjs +39 -0
- package/dist/node_modules/.pnpm/element-resize-detector@1.2.4/node_modules/element-resize-detector/src/reporter.js +39 -0
- package/dist/node_modules/.pnpm/element-resize-detector@1.2.4/node_modules/element-resize-detector/src/state-handler.cjs +28 -0
- package/dist/node_modules/.pnpm/element-resize-detector@1.2.4/node_modules/element-resize-detector/src/state-handler.js +28 -0
- package/package.json +6 -4
- package/dist/node_modules/.pnpm/@derpierre65_vue3-dragable-_7ae65b0afcc3e3050cfdea0ae383bda4/node_modules/@derpierre65/vue3-dragable-grid-layout/dist/vue3-drr-grid-layout.cjs +0 -5963
- package/dist/node_modules/.pnpm/@derpierre65_vue3-dragable-_7ae65b0afcc3e3050cfdea0ae383bda4/node_modules/@derpierre65/vue3-dragable-grid-layout/dist/vue3-drr-grid-layout.js +0 -5963
- /package/dist/components/design/{resizable.cjs → resizable/resizable.cjs} +0 -0
- /package/dist/components/design/{resizable.js → resizable/resizable.js} +0 -0
|
@@ -0,0 +1,222 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
|
+
const helpers = require("../types/helpers.cjs");
|
|
4
|
+
function bottom(layout) {
|
|
5
|
+
let max = 0;
|
|
6
|
+
let bottomY;
|
|
7
|
+
for (let i = 0; i < layout.length; i++) {
|
|
8
|
+
bottomY = layout[i].y + layout[i].h;
|
|
9
|
+
if (bottomY > max) max = bottomY;
|
|
10
|
+
}
|
|
11
|
+
return max;
|
|
12
|
+
}
|
|
13
|
+
const cloneLayoutItem = (layoutItem) => JSON.parse(JSON.stringify(layoutItem));
|
|
14
|
+
function cloneLayout(layout) {
|
|
15
|
+
const newLayout = Array(layout.length);
|
|
16
|
+
for (let i = 0; i < layout.length; i++)
|
|
17
|
+
newLayout[i] = cloneLayoutItem(layout[i]);
|
|
18
|
+
return newLayout;
|
|
19
|
+
}
|
|
20
|
+
function collides(l1, l2) {
|
|
21
|
+
return !(l1 === l2 || l1.x + l1.w <= l2.x || l1.x >= l2.x + l2.w || l1.y + l1.h <= l2.y || l1.y >= l2.y + l2.h);
|
|
22
|
+
}
|
|
23
|
+
const getStatics = (layout) => layout.filter((l) => l.isStatic);
|
|
24
|
+
function compact(layout, verticalCompact) {
|
|
25
|
+
if (!layout) return;
|
|
26
|
+
const compareWith = getStatics(layout);
|
|
27
|
+
const sorted = sortLayoutItemsByRowCol(layout);
|
|
28
|
+
const out = Array(layout.length);
|
|
29
|
+
for (let i = 0; i < sorted.length; i++) {
|
|
30
|
+
let l = sorted[i];
|
|
31
|
+
if (!l.isStatic) {
|
|
32
|
+
l = compactItem(compareWith, l, verticalCompact);
|
|
33
|
+
compareWith.push(l);
|
|
34
|
+
}
|
|
35
|
+
out[layout.indexOf(l)] = l;
|
|
36
|
+
l.moved = false;
|
|
37
|
+
}
|
|
38
|
+
return out;
|
|
39
|
+
}
|
|
40
|
+
function getFirstCollision(layout, layoutItem) {
|
|
41
|
+
for (let i = 0, len = layout.length; i < len; i++) {
|
|
42
|
+
if (collides(layout[i], layoutItem)) return layout[i];
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
function compactItem(compareWith, l, verticalCompact) {
|
|
46
|
+
if (verticalCompact)
|
|
47
|
+
while (l.y > 0 && !getFirstCollision(compareWith, l)) l.y--;
|
|
48
|
+
let collides2 = getFirstCollision(compareWith, l);
|
|
49
|
+
while (collides2) {
|
|
50
|
+
l.y = collides2.y + collides2.h;
|
|
51
|
+
collides2 = getFirstCollision(compareWith, l);
|
|
52
|
+
}
|
|
53
|
+
return l;
|
|
54
|
+
}
|
|
55
|
+
function correctBounds(layout, bounds) {
|
|
56
|
+
const collidesWith = getStatics(layout);
|
|
57
|
+
for (let i = 0; i < layout.length; i++) {
|
|
58
|
+
const l = layout[i];
|
|
59
|
+
if (l.x + l.w > bounds.cols) l.x = bounds.cols - l.w;
|
|
60
|
+
if (l.x < 0) {
|
|
61
|
+
l.x = 0;
|
|
62
|
+
l.w = bounds.cols;
|
|
63
|
+
}
|
|
64
|
+
if (!l.isStatic) collidesWith.push(l);
|
|
65
|
+
else while (getFirstCollision(collidesWith, l)) l.y++;
|
|
66
|
+
}
|
|
67
|
+
return layout;
|
|
68
|
+
}
|
|
69
|
+
function getAllCollisions(layout, layoutItem) {
|
|
70
|
+
return layout.filter((l) => collides(l, layoutItem));
|
|
71
|
+
}
|
|
72
|
+
const getLayoutItem = (layout, id) => layout.filter((l) => l.id === id)[0];
|
|
73
|
+
function moveElement(layout, l, x, y, isUserAction, horizontalShift, preventCollision) {
|
|
74
|
+
if (l.isStatic) return layout;
|
|
75
|
+
const oldX = l.x;
|
|
76
|
+
const oldY = l.y;
|
|
77
|
+
const moving = {
|
|
78
|
+
DOWN: oldY < y,
|
|
79
|
+
LEFT: oldX > x,
|
|
80
|
+
RIGHT: oldX < x,
|
|
81
|
+
UP: oldY > y
|
|
82
|
+
};
|
|
83
|
+
l.x = x;
|
|
84
|
+
l.y = y;
|
|
85
|
+
l.moved = true;
|
|
86
|
+
let sorted = sortLayoutItemsByRowCol(layout);
|
|
87
|
+
if (moving.UP) sorted = sorted.reverse();
|
|
88
|
+
const collisions = getAllCollisions(sorted, l);
|
|
89
|
+
if (preventCollision && collisions.length) {
|
|
90
|
+
l.x = oldX;
|
|
91
|
+
l.y = oldY;
|
|
92
|
+
l.moved = false;
|
|
93
|
+
return layout;
|
|
94
|
+
}
|
|
95
|
+
for (let i = 0; i < collisions.length; i++) {
|
|
96
|
+
const collision = collisions[i];
|
|
97
|
+
if (collision.moved) continue;
|
|
98
|
+
if (l.y > collision.y && l.y - collision.y > collision.h / 4) continue;
|
|
99
|
+
const movingDirection = Object.keys(moving).filter((k) => moving[k])?.[0];
|
|
100
|
+
if (collision.isStatic)
|
|
101
|
+
layout = moveElementAwayFromCollision(
|
|
102
|
+
layout,
|
|
103
|
+
collision,
|
|
104
|
+
l,
|
|
105
|
+
isUserAction,
|
|
106
|
+
movingDirection,
|
|
107
|
+
horizontalShift
|
|
108
|
+
);
|
|
109
|
+
else
|
|
110
|
+
layout = moveElementAwayFromCollision(
|
|
111
|
+
layout,
|
|
112
|
+
l,
|
|
113
|
+
collision,
|
|
114
|
+
isUserAction,
|
|
115
|
+
movingDirection,
|
|
116
|
+
horizontalShift
|
|
117
|
+
);
|
|
118
|
+
}
|
|
119
|
+
return layout;
|
|
120
|
+
}
|
|
121
|
+
function moveElementAwayFromCollision(layout, collidesWith, itemToMove, isUserAction, movingDirection, horizontalShift) {
|
|
122
|
+
const preventCollision = false;
|
|
123
|
+
if (isUserAction) {
|
|
124
|
+
const fakeItem = {
|
|
125
|
+
h: itemToMove.h,
|
|
126
|
+
id: -1,
|
|
127
|
+
w: itemToMove.w,
|
|
128
|
+
x: itemToMove.x,
|
|
129
|
+
y: Math.max(collidesWith.y - itemToMove.h, 0)
|
|
130
|
+
};
|
|
131
|
+
if (!getFirstCollision(layout, fakeItem))
|
|
132
|
+
return moveElement(
|
|
133
|
+
layout,
|
|
134
|
+
itemToMove,
|
|
135
|
+
fakeItem.x,
|
|
136
|
+
fakeItem.y,
|
|
137
|
+
isUserAction,
|
|
138
|
+
horizontalShift,
|
|
139
|
+
preventCollision
|
|
140
|
+
);
|
|
141
|
+
}
|
|
142
|
+
const movingCordsData = {
|
|
143
|
+
$default: {
|
|
144
|
+
x: itemToMove.x,
|
|
145
|
+
y: itemToMove.y + 1
|
|
146
|
+
},
|
|
147
|
+
[helpers.MovingDirections.LEFT]: [
|
|
148
|
+
itemToMove.x + collidesWith.w,
|
|
149
|
+
collidesWith.y
|
|
150
|
+
],
|
|
151
|
+
[helpers.MovingDirections.RIGHT]: [
|
|
152
|
+
itemToMove.x - collidesWith.w,
|
|
153
|
+
collidesWith.y
|
|
154
|
+
],
|
|
155
|
+
[helpers.MovingDirections.UP]: [itemToMove.x, itemToMove.y + collidesWith.h],
|
|
156
|
+
[helpers.MovingDirections.DOWN]: [itemToMove.x, itemToMove.y - collidesWith.h]
|
|
157
|
+
};
|
|
158
|
+
if (horizontalShift) {
|
|
159
|
+
const horizontalDirection = movingDirection === helpers.MovingDirections.LEFT || movingDirection === helpers.MovingDirections.RIGHT;
|
|
160
|
+
if (movingDirection in movingCordsData && !(horizontalDirection && collidesWith.w < itemToMove.w && collidesWith.x !== itemToMove.x)) {
|
|
161
|
+
const [x, y] = movingCordsData[movingDirection];
|
|
162
|
+
movingCordsData.$default.x = x;
|
|
163
|
+
movingCordsData.$default.y = y;
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
return moveElement(
|
|
167
|
+
layout,
|
|
168
|
+
itemToMove,
|
|
169
|
+
movingCordsData.$default.x,
|
|
170
|
+
movingCordsData.$default.y,
|
|
171
|
+
horizontalShift,
|
|
172
|
+
preventCollision
|
|
173
|
+
);
|
|
174
|
+
}
|
|
175
|
+
function normalizeMargins(margin) {
|
|
176
|
+
return margin.length === 1 ? [margin[0], margin[0]] : margin;
|
|
177
|
+
}
|
|
178
|
+
const setTopLeft = (top, left, width, height) => {
|
|
179
|
+
return {
|
|
180
|
+
height: `${height}px`,
|
|
181
|
+
left: `${left}px`,
|
|
182
|
+
position: "absolute",
|
|
183
|
+
top: `${top}px`,
|
|
184
|
+
width: `${width}px`
|
|
185
|
+
};
|
|
186
|
+
};
|
|
187
|
+
function setTransform(top, left, width, height) {
|
|
188
|
+
return {
|
|
189
|
+
height: `${height}px`,
|
|
190
|
+
position: "absolute",
|
|
191
|
+
transform: `translate3d(${left}px,${top}px, 0)`,
|
|
192
|
+
width: `${width}px`
|
|
193
|
+
};
|
|
194
|
+
}
|
|
195
|
+
function sortLayoutItemsByRowCol(layout) {
|
|
196
|
+
return [...layout].sort((a, b) => {
|
|
197
|
+
if (a.y === b.y && a.x === b.x) return 0;
|
|
198
|
+
if (a.y > b.y || a.y === b.y && a.x > b.x) return 1;
|
|
199
|
+
return -1;
|
|
200
|
+
});
|
|
201
|
+
}
|
|
202
|
+
function stringReplacer(string, value, replacer) {
|
|
203
|
+
return string.trim().replace(value, replacer);
|
|
204
|
+
}
|
|
205
|
+
exports.bottom = bottom;
|
|
206
|
+
exports.cloneLayout = cloneLayout;
|
|
207
|
+
exports.cloneLayoutItem = cloneLayoutItem;
|
|
208
|
+
exports.collides = collides;
|
|
209
|
+
exports.compact = compact;
|
|
210
|
+
exports.compactItem = compactItem;
|
|
211
|
+
exports.correctBounds = correctBounds;
|
|
212
|
+
exports.getAllCollisions = getAllCollisions;
|
|
213
|
+
exports.getFirstCollision = getFirstCollision;
|
|
214
|
+
exports.getLayoutItem = getLayoutItem;
|
|
215
|
+
exports.getStatics = getStatics;
|
|
216
|
+
exports.moveElement = moveElement;
|
|
217
|
+
exports.moveElementAwayFromCollision = moveElementAwayFromCollision;
|
|
218
|
+
exports.normalizeMargins = normalizeMargins;
|
|
219
|
+
exports.setTopLeft = setTopLeft;
|
|
220
|
+
exports.setTransform = setTransform;
|
|
221
|
+
exports.sortLayoutItemsByRowCol = sortLayoutItemsByRowCol;
|
|
222
|
+
exports.stringReplacer = stringReplacer;
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { CSSProperties } from 'vue';
|
|
2
|
+
import { Id } from '../types/components';
|
|
3
|
+
import { CompleteMargins, Margin } from '../types';
|
|
4
|
+
import { Layout, LayoutItem, MovingDirection, setPositionFnc } from '../types/helpers';
|
|
5
|
+
export declare function bottom(layout: Layout): number;
|
|
6
|
+
export declare const cloneLayoutItem: (layoutItem: LayoutItem) => LayoutItem;
|
|
7
|
+
export declare function cloneLayout(layout: Layout): Layout;
|
|
8
|
+
export declare function collides(l1: LayoutItem, l2: LayoutItem): boolean;
|
|
9
|
+
export declare const getStatics: (layout: Layout) => LayoutItem[];
|
|
10
|
+
export declare function compact(layout: Layout, verticalCompact: boolean): Layout | undefined;
|
|
11
|
+
export declare function getFirstCollision(layout: Layout, layoutItem: LayoutItem): LayoutItem | void;
|
|
12
|
+
export declare function compactItem(compareWith: Layout, l: LayoutItem, verticalCompact: boolean): LayoutItem;
|
|
13
|
+
export declare function correctBounds(layout: Layout, bounds: {
|
|
14
|
+
cols: number;
|
|
15
|
+
}): Layout;
|
|
16
|
+
export declare function getAllCollisions(layout: Layout, layoutItem: LayoutItem): LayoutItem[];
|
|
17
|
+
export declare const getLayoutItem: (layout: Layout, id: Id) => LayoutItem;
|
|
18
|
+
export declare function moveElement(layout: Layout, l: LayoutItem, x: number, y: number, isUserAction: boolean, horizontalShift: boolean, preventCollision?: boolean): Layout;
|
|
19
|
+
export declare function moveElementAwayFromCollision(layout: Layout, collidesWith: LayoutItem, itemToMove: LayoutItem, isUserAction: boolean, movingDirection: MovingDirection, horizontalShift: boolean): Layout;
|
|
20
|
+
export declare function normalizeMargins(margin: Margin): CompleteMargins;
|
|
21
|
+
export declare const setTopLeft: setPositionFnc<CSSProperties>;
|
|
22
|
+
export declare function setTransform(top: number, left: number, width: number, height: number): CSSProperties;
|
|
23
|
+
export declare function sortLayoutItemsByRowCol(layout: Layout): Layout;
|
|
24
|
+
export declare function stringReplacer(string: string, value: string, replacer: string): string;
|
|
@@ -0,0 +1,222 @@
|
|
|
1
|
+
import { MovingDirections } from "../types/helpers.js";
|
|
2
|
+
function bottom(layout) {
|
|
3
|
+
let max = 0;
|
|
4
|
+
let bottomY;
|
|
5
|
+
for (let i = 0; i < layout.length; i++) {
|
|
6
|
+
bottomY = layout[i].y + layout[i].h;
|
|
7
|
+
if (bottomY > max) max = bottomY;
|
|
8
|
+
}
|
|
9
|
+
return max;
|
|
10
|
+
}
|
|
11
|
+
const cloneLayoutItem = (layoutItem) => JSON.parse(JSON.stringify(layoutItem));
|
|
12
|
+
function cloneLayout(layout) {
|
|
13
|
+
const newLayout = Array(layout.length);
|
|
14
|
+
for (let i = 0; i < layout.length; i++)
|
|
15
|
+
newLayout[i] = cloneLayoutItem(layout[i]);
|
|
16
|
+
return newLayout;
|
|
17
|
+
}
|
|
18
|
+
function collides(l1, l2) {
|
|
19
|
+
return !(l1 === l2 || l1.x + l1.w <= l2.x || l1.x >= l2.x + l2.w || l1.y + l1.h <= l2.y || l1.y >= l2.y + l2.h);
|
|
20
|
+
}
|
|
21
|
+
const getStatics = (layout) => layout.filter((l) => l.isStatic);
|
|
22
|
+
function compact(layout, verticalCompact) {
|
|
23
|
+
if (!layout) return;
|
|
24
|
+
const compareWith = getStatics(layout);
|
|
25
|
+
const sorted = sortLayoutItemsByRowCol(layout);
|
|
26
|
+
const out = Array(layout.length);
|
|
27
|
+
for (let i = 0; i < sorted.length; i++) {
|
|
28
|
+
let l = sorted[i];
|
|
29
|
+
if (!l.isStatic) {
|
|
30
|
+
l = compactItem(compareWith, l, verticalCompact);
|
|
31
|
+
compareWith.push(l);
|
|
32
|
+
}
|
|
33
|
+
out[layout.indexOf(l)] = l;
|
|
34
|
+
l.moved = false;
|
|
35
|
+
}
|
|
36
|
+
return out;
|
|
37
|
+
}
|
|
38
|
+
function getFirstCollision(layout, layoutItem) {
|
|
39
|
+
for (let i = 0, len = layout.length; i < len; i++) {
|
|
40
|
+
if (collides(layout[i], layoutItem)) return layout[i];
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
function compactItem(compareWith, l, verticalCompact) {
|
|
44
|
+
if (verticalCompact)
|
|
45
|
+
while (l.y > 0 && !getFirstCollision(compareWith, l)) l.y--;
|
|
46
|
+
let collides2 = getFirstCollision(compareWith, l);
|
|
47
|
+
while (collides2) {
|
|
48
|
+
l.y = collides2.y + collides2.h;
|
|
49
|
+
collides2 = getFirstCollision(compareWith, l);
|
|
50
|
+
}
|
|
51
|
+
return l;
|
|
52
|
+
}
|
|
53
|
+
function correctBounds(layout, bounds) {
|
|
54
|
+
const collidesWith = getStatics(layout);
|
|
55
|
+
for (let i = 0; i < layout.length; i++) {
|
|
56
|
+
const l = layout[i];
|
|
57
|
+
if (l.x + l.w > bounds.cols) l.x = bounds.cols - l.w;
|
|
58
|
+
if (l.x < 0) {
|
|
59
|
+
l.x = 0;
|
|
60
|
+
l.w = bounds.cols;
|
|
61
|
+
}
|
|
62
|
+
if (!l.isStatic) collidesWith.push(l);
|
|
63
|
+
else while (getFirstCollision(collidesWith, l)) l.y++;
|
|
64
|
+
}
|
|
65
|
+
return layout;
|
|
66
|
+
}
|
|
67
|
+
function getAllCollisions(layout, layoutItem) {
|
|
68
|
+
return layout.filter((l) => collides(l, layoutItem));
|
|
69
|
+
}
|
|
70
|
+
const getLayoutItem = (layout, id) => layout.filter((l) => l.id === id)[0];
|
|
71
|
+
function moveElement(layout, l, x, y, isUserAction, horizontalShift, preventCollision) {
|
|
72
|
+
if (l.isStatic) return layout;
|
|
73
|
+
const oldX = l.x;
|
|
74
|
+
const oldY = l.y;
|
|
75
|
+
const moving = {
|
|
76
|
+
DOWN: oldY < y,
|
|
77
|
+
LEFT: oldX > x,
|
|
78
|
+
RIGHT: oldX < x,
|
|
79
|
+
UP: oldY > y
|
|
80
|
+
};
|
|
81
|
+
l.x = x;
|
|
82
|
+
l.y = y;
|
|
83
|
+
l.moved = true;
|
|
84
|
+
let sorted = sortLayoutItemsByRowCol(layout);
|
|
85
|
+
if (moving.UP) sorted = sorted.reverse();
|
|
86
|
+
const collisions = getAllCollisions(sorted, l);
|
|
87
|
+
if (preventCollision && collisions.length) {
|
|
88
|
+
l.x = oldX;
|
|
89
|
+
l.y = oldY;
|
|
90
|
+
l.moved = false;
|
|
91
|
+
return layout;
|
|
92
|
+
}
|
|
93
|
+
for (let i = 0; i < collisions.length; i++) {
|
|
94
|
+
const collision = collisions[i];
|
|
95
|
+
if (collision.moved) continue;
|
|
96
|
+
if (l.y > collision.y && l.y - collision.y > collision.h / 4) continue;
|
|
97
|
+
const movingDirection = Object.keys(moving).filter((k) => moving[k])?.[0];
|
|
98
|
+
if (collision.isStatic)
|
|
99
|
+
layout = moveElementAwayFromCollision(
|
|
100
|
+
layout,
|
|
101
|
+
collision,
|
|
102
|
+
l,
|
|
103
|
+
isUserAction,
|
|
104
|
+
movingDirection,
|
|
105
|
+
horizontalShift
|
|
106
|
+
);
|
|
107
|
+
else
|
|
108
|
+
layout = moveElementAwayFromCollision(
|
|
109
|
+
layout,
|
|
110
|
+
l,
|
|
111
|
+
collision,
|
|
112
|
+
isUserAction,
|
|
113
|
+
movingDirection,
|
|
114
|
+
horizontalShift
|
|
115
|
+
);
|
|
116
|
+
}
|
|
117
|
+
return layout;
|
|
118
|
+
}
|
|
119
|
+
function moveElementAwayFromCollision(layout, collidesWith, itemToMove, isUserAction, movingDirection, horizontalShift) {
|
|
120
|
+
const preventCollision = false;
|
|
121
|
+
if (isUserAction) {
|
|
122
|
+
const fakeItem = {
|
|
123
|
+
h: itemToMove.h,
|
|
124
|
+
id: -1,
|
|
125
|
+
w: itemToMove.w,
|
|
126
|
+
x: itemToMove.x,
|
|
127
|
+
y: Math.max(collidesWith.y - itemToMove.h, 0)
|
|
128
|
+
};
|
|
129
|
+
if (!getFirstCollision(layout, fakeItem))
|
|
130
|
+
return moveElement(
|
|
131
|
+
layout,
|
|
132
|
+
itemToMove,
|
|
133
|
+
fakeItem.x,
|
|
134
|
+
fakeItem.y,
|
|
135
|
+
isUserAction,
|
|
136
|
+
horizontalShift,
|
|
137
|
+
preventCollision
|
|
138
|
+
);
|
|
139
|
+
}
|
|
140
|
+
const movingCordsData = {
|
|
141
|
+
$default: {
|
|
142
|
+
x: itemToMove.x,
|
|
143
|
+
y: itemToMove.y + 1
|
|
144
|
+
},
|
|
145
|
+
[MovingDirections.LEFT]: [
|
|
146
|
+
itemToMove.x + collidesWith.w,
|
|
147
|
+
collidesWith.y
|
|
148
|
+
],
|
|
149
|
+
[MovingDirections.RIGHT]: [
|
|
150
|
+
itemToMove.x - collidesWith.w,
|
|
151
|
+
collidesWith.y
|
|
152
|
+
],
|
|
153
|
+
[MovingDirections.UP]: [itemToMove.x, itemToMove.y + collidesWith.h],
|
|
154
|
+
[MovingDirections.DOWN]: [itemToMove.x, itemToMove.y - collidesWith.h]
|
|
155
|
+
};
|
|
156
|
+
if (horizontalShift) {
|
|
157
|
+
const horizontalDirection = movingDirection === MovingDirections.LEFT || movingDirection === MovingDirections.RIGHT;
|
|
158
|
+
if (movingDirection in movingCordsData && !(horizontalDirection && collidesWith.w < itemToMove.w && collidesWith.x !== itemToMove.x)) {
|
|
159
|
+
const [x, y] = movingCordsData[movingDirection];
|
|
160
|
+
movingCordsData.$default.x = x;
|
|
161
|
+
movingCordsData.$default.y = y;
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
return moveElement(
|
|
165
|
+
layout,
|
|
166
|
+
itemToMove,
|
|
167
|
+
movingCordsData.$default.x,
|
|
168
|
+
movingCordsData.$default.y,
|
|
169
|
+
horizontalShift,
|
|
170
|
+
preventCollision
|
|
171
|
+
);
|
|
172
|
+
}
|
|
173
|
+
function normalizeMargins(margin) {
|
|
174
|
+
return margin.length === 1 ? [margin[0], margin[0]] : margin;
|
|
175
|
+
}
|
|
176
|
+
const setTopLeft = (top, left, width, height) => {
|
|
177
|
+
return {
|
|
178
|
+
height: `${height}px`,
|
|
179
|
+
left: `${left}px`,
|
|
180
|
+
position: "absolute",
|
|
181
|
+
top: `${top}px`,
|
|
182
|
+
width: `${width}px`
|
|
183
|
+
};
|
|
184
|
+
};
|
|
185
|
+
function setTransform(top, left, width, height) {
|
|
186
|
+
return {
|
|
187
|
+
height: `${height}px`,
|
|
188
|
+
position: "absolute",
|
|
189
|
+
transform: `translate3d(${left}px,${top}px, 0)`,
|
|
190
|
+
width: `${width}px`
|
|
191
|
+
};
|
|
192
|
+
}
|
|
193
|
+
function sortLayoutItemsByRowCol(layout) {
|
|
194
|
+
return [...layout].sort((a, b) => {
|
|
195
|
+
if (a.y === b.y && a.x === b.x) return 0;
|
|
196
|
+
if (a.y > b.y || a.y === b.y && a.x > b.x) return 1;
|
|
197
|
+
return -1;
|
|
198
|
+
});
|
|
199
|
+
}
|
|
200
|
+
function stringReplacer(string, value, replacer) {
|
|
201
|
+
return string.trim().replace(value, replacer);
|
|
202
|
+
}
|
|
203
|
+
export {
|
|
204
|
+
bottom,
|
|
205
|
+
cloneLayout,
|
|
206
|
+
cloneLayoutItem,
|
|
207
|
+
collides,
|
|
208
|
+
compact,
|
|
209
|
+
compactItem,
|
|
210
|
+
correctBounds,
|
|
211
|
+
getAllCollisions,
|
|
212
|
+
getFirstCollision,
|
|
213
|
+
getLayoutItem,
|
|
214
|
+
getStatics,
|
|
215
|
+
moveElement,
|
|
216
|
+
moveElementAwayFromCollision,
|
|
217
|
+
normalizeMargins,
|
|
218
|
+
setTopLeft,
|
|
219
|
+
setTransform,
|
|
220
|
+
sortLayoutItemsByRowCol,
|
|
221
|
+
stringReplacer
|
|
222
|
+
};
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { INTERSECTION_OBSERVER_ID } from '../constants';
|
|
2
|
+
export type Dimension = 'h' | 'w' | 'x' | 'y';
|
|
3
|
+
export type Dimensions = Record<Dimension, number>;
|
|
4
|
+
export type GridItemClass = 'css-transforms' | 'disable-user-select' | 'no-touch' | 'resizing' | 'static' | 'vue-draggable-dragging' | 'vue-resizable';
|
|
5
|
+
export interface GridItemPosition {
|
|
6
|
+
height: number;
|
|
7
|
+
left: number;
|
|
8
|
+
top: number;
|
|
9
|
+
width: number;
|
|
10
|
+
}
|
|
11
|
+
export type GridLayoutEvent<TEventType extends string = string> = Dimensions & {
|
|
12
|
+
eventType: TEventType;
|
|
13
|
+
id: Id;
|
|
14
|
+
callback: () => void;
|
|
15
|
+
};
|
|
16
|
+
export type HTMLDivElementWithId = HTMLDivElement & Record<typeof INTERSECTION_OBSERVER_ID, string | number>;
|
|
17
|
+
export type HandleDragEventArgs = GridLayoutEvent<'dragmove' | 'dragstart' | 'dragend'>;
|
|
18
|
+
export type HandleResizeEventArgs = GridLayoutEvent<'resizestart' | 'resizeend' | 'resizemove'>;
|
|
19
|
+
export type Id = string | number;
|
|
20
|
+
export type IntersectionObserverConfig = IntersectionObserverInit;
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { Ref } from 'vue';
|
|
2
|
+
import { Margin } from './grid-layout';
|
|
3
|
+
import { Breakpoints, BreakpointsKeys } from './helpers';
|
|
4
|
+
import { Dimensions, GridItemPosition, Id } from './components';
|
|
5
|
+
export type GridItemEvents = {
|
|
6
|
+
nocResizeContainer: [payload: ResizePayload];
|
|
7
|
+
nocResize: [payload: ResizePayload];
|
|
8
|
+
nocResizeEnd: [payload: ResizePayload];
|
|
9
|
+
nocMove: [payload: MovePayload];
|
|
10
|
+
nocMoveEnd: [payload: MovePayload];
|
|
11
|
+
};
|
|
12
|
+
export interface GridItemProps {
|
|
13
|
+
breakpointCols: Breakpoints;
|
|
14
|
+
colNum: number;
|
|
15
|
+
scale?: number;
|
|
16
|
+
containerWidth: number;
|
|
17
|
+
h: number;
|
|
18
|
+
id: Id;
|
|
19
|
+
isDraggable: boolean;
|
|
20
|
+
isResizable: boolean;
|
|
21
|
+
lastBreakpoint: BreakpointsKeys;
|
|
22
|
+
margin: Margin;
|
|
23
|
+
maxRows: number;
|
|
24
|
+
rowHeight: number;
|
|
25
|
+
useCssTransforms: boolean;
|
|
26
|
+
w: number;
|
|
27
|
+
x: number;
|
|
28
|
+
y: number;
|
|
29
|
+
/**
|
|
30
|
+
* @deprecated
|
|
31
|
+
* @description Used only for compatibility after deleting mitt
|
|
32
|
+
*/
|
|
33
|
+
calculateStylesTrigger: Ref<boolean>;
|
|
34
|
+
dragAllowFrom?: string | null;
|
|
35
|
+
dragIgnoreFrom?: string;
|
|
36
|
+
dragOption?: object;
|
|
37
|
+
maxH?: number;
|
|
38
|
+
maxW?: number;
|
|
39
|
+
minH?: number;
|
|
40
|
+
minW?: number;
|
|
41
|
+
observer?: IntersectionObserver | undefined;
|
|
42
|
+
isStatic?: boolean;
|
|
43
|
+
}
|
|
44
|
+
export type MovePayload = Pick<Dimensions, 'x' | 'y'> & Record<'id', Id>;
|
|
45
|
+
export type ResizePayload = Pick<Dimensions, 'h' | 'w'> & Pick<GridItemPosition, 'height' | 'width'> & Record<'id', Id>;
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { GridItemEvents } from './grid-item';
|
|
2
|
+
import { Breakpoints, BreakpointsKeys, Layout, ResponsiveLayout } from './helpers';
|
|
3
|
+
import { Dimensions, HandleDragEventArgs, HandleResizeEventArgs, Id, IntersectionObserverConfig } from './components';
|
|
4
|
+
type LayoutEventKey = 'nocLayoutBeforeMount' | 'nocLayoutCreate' | 'nocLayoutMount' | 'nocLayoutReady' | 'nocLayoutUpdate';
|
|
5
|
+
type VModelEvents = {
|
|
6
|
+
'update:layout': [layout: Layout];
|
|
7
|
+
'update:breakpoints': [breakpoints: BreakpointsKeys];
|
|
8
|
+
};
|
|
9
|
+
type LayoutEvents = {
|
|
10
|
+
[Key in LayoutEventKey]: [layout: Layout];
|
|
11
|
+
};
|
|
12
|
+
export type CompleteMargins = [number, number];
|
|
13
|
+
export type GridItemPlaceholder = Dimensions & Record<'id', Id>;
|
|
14
|
+
export type GridLayoutEvents = Pick<GridItemEvents, 'nocResizeContainer'> & // Already in camelCase
|
|
15
|
+
LayoutEvents & VModelEvents & {
|
|
16
|
+
nocIntersectionObserve: [id: Id[]];
|
|
17
|
+
nocIntersectionUnobserve: [id: Id[]];
|
|
18
|
+
nocItemMove: GridItemEvents['nocMove'];
|
|
19
|
+
nocItemMoveEnd: GridItemEvents['nocMoveEnd'];
|
|
20
|
+
nocItemResize: GridItemEvents['nocResize'];
|
|
21
|
+
nocItemResizeEnd: GridItemEvents['nocResizeEnd'];
|
|
22
|
+
};
|
|
23
|
+
export interface GridLayoutProps {
|
|
24
|
+
colNum: number;
|
|
25
|
+
layout: Layout;
|
|
26
|
+
autoSize?: boolean;
|
|
27
|
+
breakpoints?: Breakpoints;
|
|
28
|
+
cols?: Breakpoints;
|
|
29
|
+
horizontalShift?: boolean;
|
|
30
|
+
intersectionObserverConfig?: IntersectionObserverConfig;
|
|
31
|
+
isDraggable?: boolean;
|
|
32
|
+
isResizable?: boolean;
|
|
33
|
+
margin?: Margin;
|
|
34
|
+
maxRows?: number;
|
|
35
|
+
preventCollision?: boolean;
|
|
36
|
+
responsive?: boolean;
|
|
37
|
+
responsiveLayouts?: ResponsiveLayout;
|
|
38
|
+
rowHeight?: number;
|
|
39
|
+
useCssTransforms?: boolean;
|
|
40
|
+
useObserver?: boolean;
|
|
41
|
+
verticalCompact?: boolean;
|
|
42
|
+
}
|
|
43
|
+
export interface GridProvidedValues {
|
|
44
|
+
handleDragEvent: (args: HandleDragEventArgs) => void;
|
|
45
|
+
handleResizeEvent: (args: HandleResizeEventArgs) => void;
|
|
46
|
+
}
|
|
47
|
+
export type Margin = [number] | CompleteMargins;
|
|
48
|
+
export {};
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
|
+
var MovingDirections = /* @__PURE__ */ ((MovingDirections2) => {
|
|
4
|
+
MovingDirections2["DOWN"] = "DOWN";
|
|
5
|
+
MovingDirections2["LEFT"] = "LEFT";
|
|
6
|
+
MovingDirections2["RIGHT"] = "RIGHT";
|
|
7
|
+
MovingDirections2["UP"] = "UP";
|
|
8
|
+
return MovingDirections2;
|
|
9
|
+
})(MovingDirections || {});
|
|
10
|
+
exports.MovingDirections = MovingDirections;
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { Id } from './components';
|
|
2
|
+
export type Breakpoints = RecordBreakpoint<number>;
|
|
3
|
+
export type BreakpointsKeys = 'lg' | 'md' | 'sm' | 'xs' | 'xxs' | '';
|
|
4
|
+
export type Layout = LayoutItem[];
|
|
5
|
+
export type LayoutItem = LayoutItemRequired & LayoutItemOptional;
|
|
6
|
+
export interface LayoutItemOptional {
|
|
7
|
+
minW?: number;
|
|
8
|
+
minH?: number;
|
|
9
|
+
maxW?: number;
|
|
10
|
+
maxH?: number;
|
|
11
|
+
moved?: boolean;
|
|
12
|
+
isStatic?: boolean;
|
|
13
|
+
isDraggable?: boolean;
|
|
14
|
+
isResizable?: boolean;
|
|
15
|
+
}
|
|
16
|
+
export interface LayoutItemRequired {
|
|
17
|
+
w: number;
|
|
18
|
+
h: number;
|
|
19
|
+
x: number;
|
|
20
|
+
y: number;
|
|
21
|
+
id: Id;
|
|
22
|
+
}
|
|
23
|
+
export type MovingDirection = keyof typeof MovingDirections;
|
|
24
|
+
export declare enum MovingDirections {
|
|
25
|
+
DOWN = "DOWN",
|
|
26
|
+
LEFT = "LEFT",
|
|
27
|
+
RIGHT = "RIGHT",
|
|
28
|
+
UP = "UP"
|
|
29
|
+
}
|
|
30
|
+
export type RecordBreakpoint<Type> = Partial<Record<BreakpointsKeys, Type>>;
|
|
31
|
+
export type ResponsiveLayout = RecordBreakpoint<Layout>;
|
|
32
|
+
export type findOrGenerateResponsiveLayoutFnc = (orgLayout: Layout, layouts: ResponsiveLayout, breakpoints: Breakpoints, breakpoint: BreakpointsKeys, lastBreakpoint: BreakpointsKeys, cols: number, verticalCompact: boolean) => Layout;
|
|
33
|
+
export type setPositionFnc<Position> = (top: number, left: number, width: number, height: number) => Position;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
var MovingDirections = /* @__PURE__ */ ((MovingDirections2) => {
|
|
2
|
+
MovingDirections2["DOWN"] = "DOWN";
|
|
3
|
+
MovingDirections2["LEFT"] = "LEFT";
|
|
4
|
+
MovingDirections2["RIGHT"] = "RIGHT";
|
|
5
|
+
MovingDirections2["UP"] = "UP";
|
|
6
|
+
return MovingDirections2;
|
|
7
|
+
})(MovingDirections || {});
|
|
8
|
+
export {
|
|
9
|
+
MovingDirections
|
|
10
|
+
};
|