@social-mail/social-mail-client 1.8.434 → 1.8.435
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/site-editor/editor/EditingSymbols.d.ts +2 -0
- package/dist/site-editor/editor/EditingSymbols.d.ts.map +1 -0
- package/dist/site-editor/editor/EditingSymbols.js +12 -0
- package/dist/site-editor/editor/EditingSymbols.js.map +1 -0
- package/dist/site-editor/editor/HtmlPageEditor.d.ts.map +1 -1
- package/dist/site-editor/editor/HtmlPageEditor.global.css +1 -1
- package/dist/site-editor/editor/HtmlPageEditor.global.css.map +1 -1
- package/dist/site-editor/editor/HtmlPageEditor.js +5 -11
- package/dist/site-editor/editor/HtmlPageEditor.js.map +1 -1
- package/dist/site-editor/editor/UndoRedo.d.ts.map +1 -1
- package/dist/site-editor/editor/UndoRedo.js +7 -2
- package/dist/site-editor/editor/UndoRedo.js.map +1 -1
- package/dist/site-editor/editor/guides/UIGuides.d.ts +12 -0
- package/dist/site-editor/editor/guides/UIGuides.d.ts.map +1 -0
- package/dist/site-editor/editor/guides/UIGuides.global.css +2 -0
- package/dist/site-editor/editor/guides/UIGuides.global.css.map +1 -0
- package/dist/site-editor/editor/guides/UIGuides.js +25 -0
- package/dist/site-editor/editor/guides/UIGuides.js.map +1 -0
- package/dist/site-editor/editor/ui/SelectionUI.d.ts.map +1 -1
- package/dist/site-editor/editor/ui/SelectionUI.js +63 -41
- package/dist/site-editor/editor/ui/SelectionUI.js.map +1 -1
- package/dist/site-editor/editor/ui/SnapGuides.d.ts +18 -4
- package/dist/site-editor/editor/ui/SnapGuides.d.ts.map +1 -1
- package/dist/site-editor/editor/ui/SnapGuides.js +152 -26
- package/dist/site-editor/editor/ui/SnapGuides.js.map +1 -1
- package/dist/site-editor-app/SiteEditorApp.pack.global.css +1 -1
- package/dist/site-editor-app/SiteEditorApp.pack.global.css.map +1 -1
- package/dist/site-editor-app/SiteEditorApp.pack.js +271 -81
- package/dist/site-editor-app/SiteEditorApp.pack.js.map +1 -1
- package/dist/site-editor-app/SiteEditorApp.pack.min.js +1 -1
- package/dist/site-editor-app/SiteEditorApp.pack.min.js.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +1 -1
- package/src/site-editor/editor/EditingSymbols.ts +1 -0
- package/src/site-editor/editor/HtmlPageEditor.global.css +0 -26
- package/src/site-editor/editor/HtmlPageEditor.tsx +2 -7
- package/src/site-editor/editor/UndoRedo.tsx +4 -0
- package/src/site-editor/editor/guides/UIGuides.global.css +42 -0
- package/src/site-editor/editor/guides/UIGuides.tsx +29 -0
- package/src/site-editor/editor/ui/SelectionUI.tsx +84 -44
- package/src/site-editor/editor/ui/SnapGuides.ts +181 -28
- package/styler-lite/styler.css +1 -1
- package/styler-lite/styler.css.map +1 -1
- package/styler-lite/styles/properties/size/size.css +24 -24
package/package.json
CHANGED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export const isDragged = Symbol.for("isDragged");
|
|
@@ -71,32 +71,6 @@
|
|
|
71
71
|
}
|
|
72
72
|
}
|
|
73
73
|
|
|
74
|
-
& > svg {
|
|
75
|
-
pointer-events: none;
|
|
76
|
-
& * {
|
|
77
|
-
pointer-events: none;
|
|
78
|
-
}
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
& > [data-element=hover] {
|
|
82
|
-
position: absolute;
|
|
83
|
-
outline: solid 1px green;
|
|
84
|
-
outline-color: #00940094;
|
|
85
|
-
pointer-events: none;
|
|
86
|
-
z-index: 20;
|
|
87
|
-
margin: 20px;
|
|
88
|
-
& > label {
|
|
89
|
-
position: absolute;
|
|
90
|
-
transform: translate(0, -100%);
|
|
91
|
-
background-color: #00940094;
|
|
92
|
-
color: white;
|
|
93
|
-
font-size: smaller;
|
|
94
|
-
text-transform: capitalize;
|
|
95
|
-
padding: 2px;
|
|
96
|
-
padding-left: 5px;
|
|
97
|
-
padding-right: 5px;
|
|
98
|
-
}
|
|
99
|
-
}
|
|
100
74
|
& > [data-element=drop-target] {
|
|
101
75
|
position: absolute;
|
|
102
76
|
background-color: #ff5e0097;
|
|
@@ -61,6 +61,7 @@ import InlinePopupButton from "@web-atoms/web-controls/dist/basic/InlinePopupBut
|
|
|
61
61
|
import { IAppFile } from "../../model/model";
|
|
62
62
|
import { SelectionUI } from "./ui/SelectionUI";
|
|
63
63
|
import { desktopScreenWidth, mobileScreenWidth, tabletScreenWidth } from "./sizes";
|
|
64
|
+
import UIGuides from "./guides/UIGuides";
|
|
64
65
|
|
|
65
66
|
const desktopWidth = desktopScreenWidth;
|
|
66
67
|
const tabletWidth = tabletScreenWidth;
|
|
@@ -325,13 +326,7 @@ export default class HtmlPageEditor extends AtomControl {
|
|
|
325
326
|
style-height={Bind.oneWay(() => this.dropTarget.height)}>
|
|
326
327
|
</div>
|
|
327
328
|
<SelectionUI/>
|
|
328
|
-
<
|
|
329
|
-
style-left={Bind.oneWay(() => this.hover.left)}
|
|
330
|
-
style-top={Bind.oneWay(() => this.hover.top)}
|
|
331
|
-
style-width={Bind.oneWay(() => this.hover.width)}
|
|
332
|
-
style-height={Bind.oneWay(() => this.hover.height)}>
|
|
333
|
-
<label text={Bind.oneWay(() => this.hover.name)}/>
|
|
334
|
-
</div>
|
|
329
|
+
<UIGuides/>
|
|
335
330
|
<div
|
|
336
331
|
data-element="content-frame">
|
|
337
332
|
<iframe
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { AtomBinder } from "@web-atoms/core/dist/core/AtomBinder";
|
|
2
2
|
import type HtmlPageEditor from "./HtmlPageEditor";
|
|
3
|
+
import { isDragged } from "./EditingSymbols";
|
|
3
4
|
|
|
4
5
|
interface IDocumentChange {
|
|
5
6
|
undo: (() => any)[];
|
|
@@ -56,6 +57,9 @@ export default class UndoRedo {
|
|
|
56
57
|
const { documentObserver } = this;
|
|
57
58
|
if (this.silent && documentObserver?.length) {
|
|
58
59
|
for (const x of records) {
|
|
60
|
+
if (x.target[isDragged]) {
|
|
61
|
+
continue;
|
|
62
|
+
}
|
|
59
63
|
for (const d of documentObserver) {
|
|
60
64
|
d(x);
|
|
61
65
|
}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
ui-guides {
|
|
2
|
+
display: block;
|
|
3
|
+
position: absolute;
|
|
4
|
+
outline: solid 1px green;
|
|
5
|
+
outline-color: #00940094;
|
|
6
|
+
pointer-events: none;
|
|
7
|
+
margin: 20px;
|
|
8
|
+
z-index: 400;
|
|
9
|
+
contain: paint;
|
|
10
|
+
|
|
11
|
+
& > label {
|
|
12
|
+
position: absolute;
|
|
13
|
+
right: 0;
|
|
14
|
+
top: 0;
|
|
15
|
+
background-color: #00940094;
|
|
16
|
+
color: white;
|
|
17
|
+
font-size: smaller;
|
|
18
|
+
text-transform: capitalize;
|
|
19
|
+
padding: 2px;
|
|
20
|
+
padding-left: 5px;
|
|
21
|
+
padding-right: 5px;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
& > h-guide {
|
|
25
|
+
display: block;
|
|
26
|
+
position: absolute;
|
|
27
|
+
border: solid 1px lightgreen;
|
|
28
|
+
left: 0;
|
|
29
|
+
right: 0;
|
|
30
|
+
top: -50px;
|
|
31
|
+
height: 1px;
|
|
32
|
+
}
|
|
33
|
+
& > v-guide {
|
|
34
|
+
display: block;
|
|
35
|
+
position: absolute;
|
|
36
|
+
border: solid 1px lightgreen;
|
|
37
|
+
left: -50px;
|
|
38
|
+
top: 0;
|
|
39
|
+
bottom: 0;
|
|
40
|
+
width: 1px;
|
|
41
|
+
}
|
|
42
|
+
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
/* eslint-disable @typescript-eslint/naming-convention */
|
|
2
|
+
/* eslint-disable @typescript-eslint/no-namespace */
|
|
3
|
+
import XNode from "@web-atoms/core/dist/core/XNode";
|
|
4
|
+
import { BindEditor } from "../../properties/controls/PropertyEditor";
|
|
5
|
+
|
|
6
|
+
import "./UIGuides.global.css";
|
|
7
|
+
|
|
8
|
+
declare global {
|
|
9
|
+
namespace JSX {
|
|
10
|
+
interface IntrinsicElements {
|
|
11
|
+
"ui-guides": any;
|
|
12
|
+
"h-guide": any;
|
|
13
|
+
"v-guide": any;
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export default function UIGuides() {
|
|
19
|
+
return <ui-guides
|
|
20
|
+
style-left={BindEditor.oneWay((e) => e.hover.left)}
|
|
21
|
+
style-top={BindEditor.oneWay((e) => e.hover.top)}
|
|
22
|
+
style-width={BindEditor.oneWay((e) => e.hover.width)}
|
|
23
|
+
style-height={BindEditor.oneWay((e) => e.hover.height)}
|
|
24
|
+
>
|
|
25
|
+
<label text={BindEditor.oneWay((e) => e.hover.name)}/>
|
|
26
|
+
<h-guide/>
|
|
27
|
+
<v-guide/>
|
|
28
|
+
</ui-guides>;
|
|
29
|
+
}
|
|
@@ -8,6 +8,8 @@ import "./SelectionUI.global.css";
|
|
|
8
8
|
import type HtmlPageEditor from "../HtmlPageEditor";
|
|
9
9
|
import { mobileScreenWidth, tabletScreenWidth } from "../sizes";
|
|
10
10
|
import SnapGuides from "./SnapGuides";
|
|
11
|
+
import { isDragged } from "../EditingSymbols";
|
|
12
|
+
|
|
11
13
|
declare global {
|
|
12
14
|
namespace JSX {
|
|
13
15
|
interface IntrinsicElements {
|
|
@@ -23,6 +25,10 @@ interface IRect {
|
|
|
23
25
|
bottom;
|
|
24
26
|
dx;
|
|
25
27
|
dy;
|
|
28
|
+
mx;
|
|
29
|
+
my;
|
|
30
|
+
width,
|
|
31
|
+
height,
|
|
26
32
|
// sx;
|
|
27
33
|
// sy;
|
|
28
34
|
move?: boolean;
|
|
@@ -30,9 +36,9 @@ interface IRect {
|
|
|
30
36
|
|
|
31
37
|
const ps = (v, max) => (v* 100 / (max || 1)).toFixed(2);
|
|
32
38
|
|
|
33
|
-
const beginDrag = (editor: HtmlPageEditor, element: HTMLElement) => {
|
|
39
|
+
const beginDrag = (direction: string, editor: HtmlPageEditor, element: HTMLElement) => {
|
|
34
40
|
|
|
35
|
-
const snaps = new SnapGuides(editor, element);
|
|
41
|
+
const snaps = new SnapGuides(direction, editor, element);
|
|
36
42
|
|
|
37
43
|
const prefix = editor.maxWidth === tabletScreenWidth
|
|
38
44
|
? "styler-tablet"
|
|
@@ -55,14 +61,14 @@ const beginDrag = (editor: HtmlPageEditor, element: HTMLElement) => {
|
|
|
55
61
|
const oldHeight = selectedElement.getAttribute(heightAttribute);
|
|
56
62
|
const oldInset = selectedElement.getAttribute(insetAttribute);
|
|
57
63
|
|
|
58
|
-
const style = selectedElement.ownerDocument.defaultView.getComputedStyle(selectedElement);
|
|
64
|
+
// const style = selectedElement.ownerDocument.defaultView.getComputedStyle(selectedElement);
|
|
59
65
|
const width = selectedParent.offsetWidth;
|
|
60
66
|
const height = selectedParent.offsetHeight;
|
|
61
67
|
|
|
62
|
-
const left = parseFloat(style.left || "0");
|
|
63
|
-
const top = parseFloat(style.top || "0");
|
|
64
|
-
const bottom = parseFloat(style.bottom || "0");
|
|
65
|
-
const right = parseFloat(style.right || "0");
|
|
68
|
+
// const left = parseFloat(style.left || "0");
|
|
69
|
+
// const top = parseFloat(style.top || "0");
|
|
70
|
+
// const bottom = parseFloat(style.bottom || "0");
|
|
71
|
+
// const right = parseFloat(style.right || "0");
|
|
66
72
|
|
|
67
73
|
const { undoRedo } = editor;
|
|
68
74
|
|
|
@@ -72,57 +78,89 @@ const beginDrag = (editor: HtmlPageEditor, element: HTMLElement) => {
|
|
|
72
78
|
let changed = false;
|
|
73
79
|
let timer = void 0;
|
|
74
80
|
|
|
81
|
+
|
|
82
|
+
let inset;
|
|
83
|
+
let newWidth;
|
|
84
|
+
let newHeight;
|
|
85
|
+
|
|
86
|
+
element[isDragged] = true;
|
|
87
|
+
|
|
88
|
+
editor.hover.update(selectedElement.parentElement);
|
|
89
|
+
|
|
90
|
+
let updateTimer = void 0;
|
|
91
|
+
|
|
75
92
|
const move = ({ dx, dy, fx}: { dx: number, dy: number, fx: (r: IRect, ) => IRect}) => {
|
|
76
93
|
|
|
77
94
|
changed = true;
|
|
78
95
|
|
|
79
|
-
|
|
96
|
+
const left = selectedElement.offsetLeft;
|
|
97
|
+
const top = selectedElement.offsetTop;
|
|
98
|
+
const elementWidth = selectedElement.offsetWidth;
|
|
99
|
+
const elementHeight = selectedElement.offsetHeight;
|
|
100
|
+
|
|
101
|
+
const mx = left + (elementWidth / 2);
|
|
102
|
+
const my = top + (elementHeight / 2);
|
|
103
|
+
|
|
104
|
+
const ri = {
|
|
80
105
|
left,
|
|
81
106
|
top,
|
|
82
|
-
right,
|
|
83
|
-
bottom,
|
|
107
|
+
right: width - (left + elementWidth),
|
|
108
|
+
bottom: height - (top + elementHeight),
|
|
109
|
+
width: elementWidth,
|
|
110
|
+
height: elementHeight,
|
|
111
|
+
mx,
|
|
112
|
+
my,
|
|
113
|
+
move: false,
|
|
84
114
|
dx,
|
|
85
115
|
dy
|
|
86
116
|
};
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
// ri = snaps.snap(ri);
|
|
117
|
+
let r = fx(ri);
|
|
118
|
+
r = snaps.snap(r);
|
|
90
119
|
|
|
91
|
-
|
|
92
|
-
selectedElement.
|
|
120
|
+
inset = `${ps(r.top, height)}% ${ps(r.right, width)}% ${ps(r.bottom, height)}% ${ps(r.left, width)}%`;
|
|
121
|
+
selectedElement.style.inset = inset;
|
|
93
122
|
|
|
94
123
|
if (!r.move) {
|
|
95
124
|
resized = true;
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
widthDiff -= r.right;
|
|
103
|
-
}
|
|
104
|
-
const newWidth = ps(width + widthDiff, width) + "%";
|
|
105
|
-
selectedElement.setAttribute(widthAttribute, newWidth);
|
|
106
|
-
const newHeight = ps(height + heightDiff, height) + "%";
|
|
107
|
-
selectedElement.setAttribute(heightAttribute, newHeight);
|
|
125
|
+
newWidth = ps(elementWidth + dx, width) + "%";
|
|
126
|
+
selectedElement.style.width = newWidth;
|
|
127
|
+
// // selectedElement.setAttribute(widthAttribute, newWidth);
|
|
128
|
+
newHeight = ps(elementHeight + dy, height) + "%";
|
|
129
|
+
selectedElement.style.height = newHeight;
|
|
130
|
+
// selectedElement.setAttribute(heightAttribute, newHeight);
|
|
108
131
|
}
|
|
109
132
|
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
133
|
+
|
|
134
|
+
if(!updateTimer) {
|
|
135
|
+
updateTimer = setTimeout(() => {
|
|
136
|
+
updateTimer = void 0;
|
|
137
|
+
selection.updateRect();
|
|
138
|
+
}, 10);
|
|
139
|
+
}
|
|
115
140
|
};
|
|
116
141
|
|
|
117
142
|
const resume = () => {
|
|
118
143
|
snaps.dispose();
|
|
119
144
|
d.resume();
|
|
145
|
+
element[isDragged] = void 0;
|
|
120
146
|
};
|
|
121
147
|
|
|
122
148
|
const commit = () => {
|
|
123
149
|
|
|
124
|
-
d.resume();
|
|
125
150
|
|
|
151
|
+
selectedElement.style.removeProperty("inset");
|
|
152
|
+
selectedElement.style.removeProperty("width");
|
|
153
|
+
selectedElement.style.removeProperty("height");
|
|
154
|
+
|
|
155
|
+
selectedElement.setAttribute(insetAttribute, inset);
|
|
156
|
+
if (newWidth) {
|
|
157
|
+
selectedElement.setAttribute(widthAttribute, newWidth);
|
|
158
|
+
}
|
|
159
|
+
if (newHeight) {
|
|
160
|
+
selectedElement.setAttribute(heightAttribute, newHeight);
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
d.resume();
|
|
126
164
|
const records = [] as MutationRecord[];
|
|
127
165
|
|
|
128
166
|
// push records...
|
|
@@ -173,13 +211,13 @@ const beginDrag = (editor: HtmlPageEditor, element: HTMLElement) => {
|
|
|
173
211
|
};
|
|
174
212
|
};
|
|
175
213
|
|
|
176
|
-
const setCapture = (editor: HtmlPageEditor, element: HTMLElement, e: PointerEvent, fx: (r: IRect, ) => IRect) => {
|
|
214
|
+
const setCapture = (direction: string, editor: HtmlPageEditor, element: HTMLElement, e: PointerEvent, fx: (r: IRect, ) => IRect) => {
|
|
177
215
|
|
|
178
216
|
|
|
179
|
-
const sc = beginDrag(editor, element);
|
|
217
|
+
const sc = beginDrag(direction, editor, element);
|
|
180
218
|
|
|
181
|
-
|
|
182
|
-
|
|
219
|
+
let sx = e.clientX;
|
|
220
|
+
let sy = e.clientY;
|
|
183
221
|
|
|
184
222
|
const captureMove = (evt: PointerEvent) => {
|
|
185
223
|
const dx = evt.clientX - sx;
|
|
@@ -187,6 +225,8 @@ const setCapture = (editor: HtmlPageEditor, element: HTMLElement, e: PointerEven
|
|
|
187
225
|
if (dx === 0 && dy === 0) {
|
|
188
226
|
return;
|
|
189
227
|
}
|
|
228
|
+
sx = evt.clientX;
|
|
229
|
+
sy = evt.clientY;
|
|
190
230
|
sc.move({ dx, dy, fx});
|
|
191
231
|
};
|
|
192
232
|
|
|
@@ -257,28 +297,28 @@ const eventPointerDown = (editor: HtmlPageEditor, e: PointerEvent) => {
|
|
|
257
297
|
// enable resizing...
|
|
258
298
|
switch(resize) {
|
|
259
299
|
case "lt":
|
|
260
|
-
setCapture(editor, element, e, (r) => {
|
|
300
|
+
setCapture(resize, editor, element, e, (r) => {
|
|
261
301
|
r.left += r.dx;
|
|
262
302
|
r.top += r.dy;
|
|
263
303
|
return r;
|
|
264
304
|
});
|
|
265
305
|
return;
|
|
266
306
|
case "rt":
|
|
267
|
-
setCapture(editor, element, e, (r) => {
|
|
307
|
+
setCapture(resize, editor, element, e, (r) => {
|
|
268
308
|
r.top += r.dy;
|
|
269
309
|
r.right -= r.dx;
|
|
270
310
|
return r;
|
|
271
311
|
});
|
|
272
312
|
return;
|
|
273
313
|
case "lb":
|
|
274
|
-
setCapture(editor, element, e, (r) => {
|
|
314
|
+
setCapture(resize, editor, element, e, (r) => {
|
|
275
315
|
r.left += r.dx;
|
|
276
316
|
r.bottom -= r.dy;
|
|
277
317
|
return r;
|
|
278
318
|
});
|
|
279
319
|
return;
|
|
280
320
|
case "rb":
|
|
281
|
-
setCapture(editor, element, e, (r) => {
|
|
321
|
+
setCapture(resize, editor, element, e, (r) => {
|
|
282
322
|
r.bottom -= r.dy;
|
|
283
323
|
r.right -= r.dx;
|
|
284
324
|
return r;
|
|
@@ -294,7 +334,7 @@ const eventPointerDown = (editor: HtmlPageEditor, e: PointerEvent) => {
|
|
|
294
334
|
|
|
295
335
|
// update snaps...
|
|
296
336
|
|
|
297
|
-
setCapture(editor, element, e, (r) => {
|
|
337
|
+
setCapture("move", editor, element, e, (r) => {
|
|
298
338
|
r.top += r.dy;
|
|
299
339
|
r.left += r.dx;
|
|
300
340
|
r.bottom -= r.dy;
|
|
@@ -361,7 +401,7 @@ const eventKeyDown = (editor: HtmlPageEditor, e: KeyboardEvent) => {
|
|
|
361
401
|
return r;
|
|
362
402
|
};
|
|
363
403
|
|
|
364
|
-
sc = beginDrag(editor, element);
|
|
404
|
+
sc = beginDrag("none", editor, element);
|
|
365
405
|
currentElement[keyboardEditingSymbol] = sc;
|
|
366
406
|
|
|
367
407
|
sc.move({ dx, dy, fx });
|
|
@@ -413,7 +453,7 @@ export function SelectionUI() {
|
|
|
413
453
|
style-top={BindEditor.oneWay((e) => e.selection.top)}
|
|
414
454
|
style-width={BindEditor.oneWay((e) => e.selection.width)}
|
|
415
455
|
style-height={BindEditor.oneWay((e) => e.selection.height)}>
|
|
416
|
-
|
|
456
|
+
<label text={BindEditor.oneWay((e) => e.selection.name)}/>
|
|
417
457
|
<i data-resize="lt"/>
|
|
418
458
|
<i data-resize="rt"/>
|
|
419
459
|
<i data-resize="lb"/>
|
|
@@ -1,7 +1,6 @@
|
|
|
1
|
-
import { ChildEnumerator } from "@web-atoms/core/dist/web/core/AtomUI";
|
|
2
1
|
import HtmlPageEditor from "../HtmlPageEditor";
|
|
3
2
|
|
|
4
|
-
const
|
|
3
|
+
const uiGuides = Symbol("ui-guides");
|
|
5
4
|
|
|
6
5
|
interface IRect {
|
|
7
6
|
left;
|
|
@@ -10,60 +9,214 @@ interface IRect {
|
|
|
10
9
|
bottom;
|
|
11
10
|
dx;
|
|
12
11
|
dy;
|
|
12
|
+
mx;
|
|
13
|
+
my;
|
|
14
|
+
width,
|
|
15
|
+
height,
|
|
13
16
|
// sx;
|
|
14
17
|
// sy;
|
|
15
18
|
move?: boolean;
|
|
16
19
|
}
|
|
17
20
|
export default class SnapGuides {
|
|
18
21
|
|
|
19
|
-
|
|
22
|
+
hGuide: HTMLDivElement;
|
|
23
|
+
vGuide: HTMLDivElement;
|
|
24
|
+
uiGuides: HTMLElement;
|
|
20
25
|
|
|
21
|
-
|
|
22
|
-
vl: SVGLineElement;
|
|
26
|
+
all = [] as { left, top, right, bottom, midX, midY, src }[];
|
|
23
27
|
|
|
24
28
|
constructor(
|
|
29
|
+
private direction: string,
|
|
25
30
|
private editor: HtmlPageEditor,
|
|
26
31
|
private e: HTMLElement
|
|
27
32
|
) {
|
|
28
33
|
if(!/selected/i.test(e.tagName)) {
|
|
29
34
|
e = e.parentElement;
|
|
30
35
|
}
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
36
|
+
|
|
37
|
+
const pe = e.parentElement;
|
|
38
|
+
|
|
39
|
+
const guides = (e[uiGuides] ??= editor.element.querySelector("ui-guides")) as HTMLElement;
|
|
40
|
+
|
|
41
|
+
this.hGuide = e["hGuide"] ??= guides.querySelector("h-guide");
|
|
42
|
+
this.vGuide = e["vGuide"] ??= guides.querySelector("v-guide");
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
const { all } = this;
|
|
46
|
+
const current = this.editor.selection.element;
|
|
47
|
+
|
|
48
|
+
const parent = current.parentElement;
|
|
49
|
+
|
|
50
|
+
let start = current.parentElement;
|
|
51
|
+
all.push({
|
|
52
|
+
src: start,
|
|
53
|
+
left: 0,
|
|
54
|
+
top: 0,
|
|
55
|
+
right: start.offsetWidth,
|
|
56
|
+
bottom: start.offsetHeight,
|
|
57
|
+
midX: start.offsetWidth /2,
|
|
58
|
+
midY: start.offsetHeight / 2
|
|
59
|
+
});
|
|
60
|
+
start = start.firstElementChild as HTMLElement;
|
|
61
|
+
if(start) {
|
|
62
|
+
if (start.offsetParent === parent && start !== current) {
|
|
63
|
+
all.push({
|
|
64
|
+
src: start,
|
|
65
|
+
left: start.offsetLeft,
|
|
66
|
+
top: start.offsetTop,
|
|
67
|
+
right: start.offsetLeft + start.offsetWidth,
|
|
68
|
+
bottom: start.offsetTop + start.offsetHeight,
|
|
69
|
+
midX: start.offsetLeft + (start.offsetWidth /2),
|
|
70
|
+
midY: start.offsetTop + (start.offsetHeight / 2)
|
|
71
|
+
});
|
|
72
|
+
}
|
|
73
|
+
do {
|
|
74
|
+
if (start !== current) {
|
|
75
|
+
all.push({
|
|
76
|
+
src: start,
|
|
77
|
+
left: start.offsetLeft,
|
|
78
|
+
top: start.offsetTop,
|
|
79
|
+
right: start.offsetLeft + start.offsetWidth,
|
|
80
|
+
bottom: start.offsetTop + start.offsetHeight,
|
|
81
|
+
midX: start.offsetLeft + (start.offsetWidth /2),
|
|
82
|
+
midY: start.offsetTop + (start.offsetHeight / 2)
|
|
83
|
+
});
|
|
84
|
+
}
|
|
85
|
+
start = start.nextElementSibling as HTMLElement;
|
|
86
|
+
} while(start);
|
|
44
87
|
}
|
|
45
|
-
|
|
46
|
-
this.vl.style.display = "none";
|
|
47
|
-
this.svg = svg;
|
|
88
|
+
console.log(all);
|
|
48
89
|
}
|
|
49
90
|
|
|
50
91
|
snap(rect: IRect) {
|
|
51
92
|
|
|
52
|
-
let
|
|
93
|
+
let moving = false;
|
|
94
|
+
let setLeft = false;
|
|
95
|
+
let setTop = false;
|
|
53
96
|
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
97
|
+
switch(this.direction) {
|
|
98
|
+
case "none":
|
|
99
|
+
return rect;
|
|
100
|
+
case "move":
|
|
101
|
+
moving = true;
|
|
102
|
+
setLeft = true;
|
|
103
|
+
setTop = true;
|
|
104
|
+
break;
|
|
105
|
+
case "lt":
|
|
106
|
+
setLeft = true;
|
|
107
|
+
setTop = true;
|
|
58
108
|
break;
|
|
109
|
+
case "rt":
|
|
110
|
+
setTop = true;
|
|
111
|
+
break;
|
|
112
|
+
case "lb":
|
|
113
|
+
setLeft = true;
|
|
114
|
+
break;
|
|
115
|
+
case "rb":
|
|
116
|
+
break;
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
|
|
120
|
+
const mpX = rect.mx;
|
|
121
|
+
const mpY = rect.my;
|
|
122
|
+
|
|
123
|
+
const x = rect.left;
|
|
124
|
+
const y = rect.top;
|
|
125
|
+
|
|
126
|
+
const rx = x + rect.width;
|
|
127
|
+
const ry = y + rect.height;
|
|
128
|
+
|
|
129
|
+
let vl = void 0 as number;
|
|
130
|
+
let hl = void 0 as number;
|
|
131
|
+
|
|
132
|
+
let dx;
|
|
133
|
+
let dy;
|
|
134
|
+
let fdx;
|
|
135
|
+
let fdy;
|
|
136
|
+
|
|
137
|
+
const range = 2;
|
|
138
|
+
|
|
139
|
+
for (const { left, top, right, midX, bottom, midY} of this.all) {
|
|
140
|
+
if (!vl) {
|
|
141
|
+
dx = mpX - midX;
|
|
142
|
+
if (dx >= -range && dx <= range) {
|
|
143
|
+
vl = midX;
|
|
144
|
+
fdx = dx;
|
|
145
|
+
} else {
|
|
146
|
+
dx = x - left;
|
|
147
|
+
if (dx >= -range && dx <= range) {
|
|
148
|
+
vl = left;
|
|
149
|
+
fdx = dx;
|
|
150
|
+
} else {
|
|
151
|
+
dx = rx - (right);
|
|
152
|
+
if(dx >= -range && dx <= range) {
|
|
153
|
+
vl = right;
|
|
154
|
+
fdx = dx;
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
}
|
|
59
158
|
}
|
|
159
|
+
if (!hl) {
|
|
160
|
+
dy = mpY - midY;
|
|
161
|
+
if (dy >= -range && dy <= range) {
|
|
162
|
+
hl = midY;
|
|
163
|
+
fdy = dy;
|
|
164
|
+
} else {
|
|
165
|
+
dy = y - top;
|
|
166
|
+
if (dy >= -range && dy <= range) {
|
|
167
|
+
hl = top;
|
|
168
|
+
fdy = dy;
|
|
169
|
+
} else {
|
|
170
|
+
dy = ry - (bottom);
|
|
171
|
+
if(dx >= -range && dx <= range) {
|
|
172
|
+
hl = bottom;
|
|
173
|
+
fdy = dy;
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
const v = this.vGuide;
|
|
181
|
+
if (vl) {
|
|
182
|
+
// if (moving) {
|
|
183
|
+
// rect.left += fdx;
|
|
184
|
+
// rect.right -= fdx;
|
|
185
|
+
// } else {
|
|
186
|
+
// if (setLeft) {
|
|
187
|
+
// rect.left += fdx;
|
|
188
|
+
// } else {
|
|
189
|
+
// rect.right -= fdx;
|
|
190
|
+
// }
|
|
191
|
+
// }
|
|
192
|
+
v.style.left = vl + "px";
|
|
193
|
+
} else {
|
|
194
|
+
v.removeAttribute("style");
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
const h = this.hGuide;
|
|
198
|
+
if (hl) {
|
|
199
|
+
// if (moving) {
|
|
200
|
+
// rect.top += fdy;
|
|
201
|
+
// rect.bottom -= fdy;
|
|
202
|
+
// } else {
|
|
203
|
+
// if (setTop) {
|
|
204
|
+
// rect.top += fdy;
|
|
205
|
+
// } else {
|
|
206
|
+
// rect.bottom -= fdy;
|
|
207
|
+
// }
|
|
208
|
+
// }
|
|
209
|
+
h.style.top = hl + "px";
|
|
210
|
+
} else {
|
|
211
|
+
h.removeAttribute("style");
|
|
60
212
|
}
|
|
61
213
|
|
|
62
214
|
return rect;
|
|
63
215
|
}
|
|
64
216
|
|
|
65
217
|
dispose() {
|
|
66
|
-
|
|
67
|
-
|
|
218
|
+
const { hGuide, vGuide } = this;
|
|
219
|
+
hGuide.removeAttribute("style");
|
|
220
|
+
vGuide.removeAttribute("style");
|
|
68
221
|
}
|
|
69
222
|
}
|