@social-mail/social-mail-client 1.8.342 → 1.8.344
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/ui/SelectionUI.d.ts.map +1 -1
- package/dist/site-editor/editor/ui/SelectionUI.js +94 -122
- package/dist/site-editor/editor/ui/SelectionUI.js.map +1 -1
- package/dist/site-editor-app/SiteEditorApp.pack.js +94 -122
- 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/ui/SelectionUI.tsx +107 -151
package/package.json
CHANGED
|
@@ -7,8 +7,6 @@ import { BindEditor } from "../../properties/controls/PropertyEditor";
|
|
|
7
7
|
import "./SelectionUI.global.css";
|
|
8
8
|
import type HtmlPageEditor from "../HtmlPageEditor";
|
|
9
9
|
import { mobileScreenWidth, tabletScreenWidth } from "../sizes";
|
|
10
|
-
import type { SelectedElement } from "../SelectedElement";
|
|
11
|
-
import UndoRedo from "../UndoRedo";
|
|
12
10
|
declare global {
|
|
13
11
|
namespace JSX {
|
|
14
12
|
interface IntrinsicElements {
|
|
@@ -31,108 +29,49 @@ interface IRect {
|
|
|
31
29
|
|
|
32
30
|
const ps = (v, max) => (v* 100 / (max || 1)).toFixed(2);
|
|
33
31
|
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
)
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
: "styler-desktop");
|
|
68
|
-
|
|
69
|
-
const { selection, hover } = editor;
|
|
70
|
-
const selectedElement = selection.element;
|
|
71
|
-
const selectedParent = selectedElement.parentElement;
|
|
72
|
-
|
|
73
|
-
this.selectedElement = selectedElement;
|
|
74
|
-
this.selectedParent = selectedParent;
|
|
75
|
-
this.selection = selection;
|
|
76
|
-
this.hover = hover;
|
|
77
|
-
// const frameDocument = selectedElement.ownerDocument;
|
|
78
|
-
// const frame = editor.contentEditor;
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
const insetAttribute = `${prefix}-inset`;
|
|
82
|
-
const widthAttribute = `${prefix}-width`;
|
|
83
|
-
const heightAttribute = `${prefix}-height`;
|
|
84
|
-
|
|
85
|
-
this.insetAttribute = insetAttribute;
|
|
86
|
-
this.widthAttribute = widthAttribute;
|
|
87
|
-
this.heightAttribute = heightAttribute;
|
|
88
|
-
|
|
89
|
-
const oldWidth = selectedElement.getAttribute(widthAttribute);
|
|
90
|
-
const oldHeight = selectedElement.getAttribute(heightAttribute);
|
|
91
|
-
const oldInset = selectedElement.getAttribute(insetAttribute);
|
|
92
|
-
|
|
93
|
-
const style = selectedElement.ownerDocument.defaultView.getComputedStyle(selectedElement);
|
|
94
|
-
const width = selectedParent.offsetWidth;
|
|
95
|
-
const height = selectedParent.offsetHeight;
|
|
96
|
-
|
|
97
|
-
const left = parseFloat(style.left || "0");
|
|
98
|
-
const top = parseFloat(style.top || "0");
|
|
99
|
-
const bottom = parseFloat(style.bottom || "0");
|
|
100
|
-
const right = parseFloat(style.right || "0");
|
|
101
|
-
|
|
102
|
-
this.left = left;
|
|
103
|
-
this.top = top;
|
|
104
|
-
this.bottom = bottom;
|
|
105
|
-
this.right = right;
|
|
106
|
-
this.width = width;
|
|
107
|
-
this.height = height;
|
|
108
|
-
this.oldWidth = oldWidth;
|
|
109
|
-
this.oldHeight = oldHeight;
|
|
110
|
-
this.oldInset = oldInset;
|
|
111
|
-
|
|
112
|
-
const { undoRedo } = editor;
|
|
113
|
-
this.undoRedo = undoRedo;
|
|
114
|
-
|
|
115
|
-
const d = undoRedo.beginPause();
|
|
116
|
-
|
|
117
|
-
this.d = d;
|
|
118
|
-
this.resized = false;
|
|
119
|
-
}
|
|
32
|
+
const beginDrag = (editor: HtmlPageEditor, element: HTMLElement) => {
|
|
33
|
+
|
|
34
|
+
const prefix = editor.maxWidth === tabletScreenWidth
|
|
35
|
+
? "styler-tablet"
|
|
36
|
+
: (editor.maxWidth === mobileScreenWidth
|
|
37
|
+
? "styler-mobile"
|
|
38
|
+
: "styler-desktop");
|
|
39
|
+
|
|
40
|
+
const { selection, hover } = editor;
|
|
41
|
+
const selectedElement = selection.element;
|
|
42
|
+
const selectedParent = selectedElement.parentElement;
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
const insetAttribute = `${prefix}-inset`;
|
|
47
|
+
const widthAttribute = `${prefix}-width`;
|
|
48
|
+
const heightAttribute = `${prefix}-height`;
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+
const oldWidth = selectedElement.getAttribute(widthAttribute);
|
|
52
|
+
const oldHeight = selectedElement.getAttribute(heightAttribute);
|
|
53
|
+
const oldInset = selectedElement.getAttribute(insetAttribute);
|
|
54
|
+
|
|
55
|
+
const style = selectedElement.ownerDocument.defaultView.getComputedStyle(selectedElement);
|
|
56
|
+
const width = selectedParent.offsetWidth;
|
|
57
|
+
const height = selectedParent.offsetHeight;
|
|
58
|
+
|
|
59
|
+
const left = parseFloat(style.left || "0");
|
|
60
|
+
const top = parseFloat(style.top || "0");
|
|
61
|
+
const bottom = parseFloat(style.bottom || "0");
|
|
62
|
+
const right = parseFloat(style.right || "0");
|
|
63
|
+
|
|
64
|
+
const { undoRedo } = editor;
|
|
120
65
|
|
|
121
|
-
|
|
66
|
+
const d = undoRedo.beginPause();
|
|
122
67
|
|
|
123
|
-
|
|
68
|
+
let resized = false;
|
|
69
|
+
let changed = false;
|
|
70
|
+
let timer = void 0;
|
|
124
71
|
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
selectedElement,
|
|
129
|
-
oldInset,
|
|
130
|
-
insetAttribute,
|
|
131
|
-
widthAttribute,
|
|
132
|
-
heightAttribute,
|
|
133
|
-
selection,
|
|
134
|
-
hover
|
|
135
|
-
} = this;
|
|
72
|
+
const move = ({ dx, dy, fx}: { dx: number, dy: number, fx: (r: IRect, ) => IRect}) => {
|
|
73
|
+
|
|
74
|
+
changed = true;
|
|
136
75
|
|
|
137
76
|
const ri = {
|
|
138
77
|
left,
|
|
@@ -147,7 +86,7 @@ class SelectedCapture {
|
|
|
147
86
|
selectedElement.setAttribute(insetAttribute, inset);
|
|
148
87
|
|
|
149
88
|
if (!r.move) {
|
|
150
|
-
|
|
89
|
+
resized = true;
|
|
151
90
|
let widthDiff = -r.left;
|
|
152
91
|
let heightDiff = -r.top;
|
|
153
92
|
if (ri.bottom === r.bottom) {
|
|
@@ -162,25 +101,19 @@ class SelectedCapture {
|
|
|
162
101
|
selectedElement.setAttribute(heightAttribute, newHeight);
|
|
163
102
|
}
|
|
164
103
|
|
|
165
|
-
clearTimeout(this.timer);
|
|
166
|
-
|
|
104
|
+
// clearTimeout(this.timer);
|
|
105
|
+
setTimeout(() => {
|
|
167
106
|
selection.updateRect();
|
|
168
107
|
hover.updateRect();
|
|
169
108
|
}, 1);
|
|
170
|
-
}
|
|
109
|
+
};
|
|
171
110
|
|
|
172
|
-
commit() {
|
|
111
|
+
const commit = () => {
|
|
173
112
|
|
|
174
|
-
|
|
113
|
+
d.resume();
|
|
175
114
|
|
|
176
115
|
const records = [] as MutationRecord[];
|
|
177
116
|
|
|
178
|
-
const { oldInset, oldHeight, oldWidth, selectedElement,
|
|
179
|
-
insetAttribute, widthAttribute, heightAttribute,
|
|
180
|
-
undoRedo, editor,
|
|
181
|
-
selection, hover
|
|
182
|
-
} = this;
|
|
183
|
-
|
|
184
117
|
// push records...
|
|
185
118
|
records.push({
|
|
186
119
|
type: "attributes",
|
|
@@ -190,7 +123,7 @@ class SelectedCapture {
|
|
|
190
123
|
attributeNamespace: "",
|
|
191
124
|
} as MutationRecord);
|
|
192
125
|
|
|
193
|
-
if (
|
|
126
|
+
if (resized) {
|
|
194
127
|
records.push({
|
|
195
128
|
type: "attributes",
|
|
196
129
|
oldValue: oldWidth,
|
|
@@ -210,18 +143,28 @@ class SelectedCapture {
|
|
|
210
143
|
undoRedo.observe(records);
|
|
211
144
|
editor.commit();
|
|
212
145
|
|
|
213
|
-
clearTimeout(
|
|
214
|
-
|
|
146
|
+
clearTimeout(timer);
|
|
147
|
+
timer = setTimeout(() => {
|
|
215
148
|
selection.updateRect();
|
|
216
149
|
hover.updateRect();
|
|
217
150
|
}, 1);
|
|
218
|
-
}
|
|
219
|
-
|
|
151
|
+
};
|
|
152
|
+
|
|
153
|
+
return {
|
|
154
|
+
move,
|
|
155
|
+
commit,
|
|
156
|
+
selectedElement,
|
|
157
|
+
selectedParent,
|
|
158
|
+
get changed() {
|
|
159
|
+
return changed;
|
|
160
|
+
}
|
|
161
|
+
};
|
|
162
|
+
};
|
|
220
163
|
|
|
221
164
|
const setCapture = (editor: HtmlPageEditor, element: HTMLElement, e: PointerEvent, fx: (r: IRect, ) => IRect) => {
|
|
222
165
|
|
|
223
166
|
|
|
224
|
-
const sc =
|
|
167
|
+
const sc = beginDrag(editor, element);
|
|
225
168
|
|
|
226
169
|
const sx = e.clientX;
|
|
227
170
|
const sy = e.clientY;
|
|
@@ -293,9 +236,6 @@ const eventPointerDown = (editor: HtmlPageEditor, e: PointerEvent) => {
|
|
|
293
236
|
return;
|
|
294
237
|
}
|
|
295
238
|
|
|
296
|
-
currentElement.tabIndex = 0;
|
|
297
|
-
currentElement.focus();
|
|
298
|
-
|
|
299
239
|
const resize = element.getAttribute("data-resize");
|
|
300
240
|
if (resize) {
|
|
301
241
|
|
|
@@ -359,68 +299,84 @@ const eventKeyDown = (editor: HtmlPageEditor, e: KeyboardEvent) => {
|
|
|
359
299
|
return;
|
|
360
300
|
}
|
|
361
301
|
|
|
302
|
+
let sc: ReturnType<typeof beginDrag> = currentElement[keyboardEditingSymbol];
|
|
303
|
+
if (sc) {
|
|
304
|
+
return;
|
|
305
|
+
}
|
|
306
|
+
|
|
307
|
+
// e.preventDefault();
|
|
308
|
+
|
|
362
309
|
let dx = 0;
|
|
363
310
|
let dy = 0;
|
|
364
311
|
|
|
365
312
|
switch(e.key) {
|
|
366
313
|
case "ArrowDown":
|
|
367
314
|
// Do something for "down arrow" key press.
|
|
368
|
-
dy =
|
|
315
|
+
dy = 1;
|
|
369
316
|
break;
|
|
370
317
|
case "ArrowUp":
|
|
371
318
|
// Do something for "up arrow" key press.
|
|
372
|
-
dy =
|
|
319
|
+
dy = -1;
|
|
373
320
|
break;
|
|
374
321
|
case "ArrowLeft":
|
|
375
322
|
// Do something for "left arrow" key press.
|
|
376
|
-
dx =
|
|
323
|
+
dx = -1;
|
|
377
324
|
break;
|
|
378
325
|
case "ArrowRight":
|
|
379
326
|
// Do something for "right arrow" key press.
|
|
380
|
-
dx =
|
|
327
|
+
dx = 1;
|
|
381
328
|
break;
|
|
382
329
|
default:
|
|
383
330
|
return;
|
|
384
331
|
}
|
|
385
332
|
|
|
386
|
-
|
|
333
|
+
const sx = dx * 5;
|
|
334
|
+
const sy = dy * 5;
|
|
387
335
|
|
|
388
|
-
|
|
336
|
+
const fx = (r) => {
|
|
337
|
+
r.top += r.dy;
|
|
338
|
+
r.left += r.dx;
|
|
339
|
+
r.bottom -= r.dy;
|
|
340
|
+
r.right -= r.dx;
|
|
341
|
+
r.move = true;
|
|
342
|
+
return r;
|
|
343
|
+
};
|
|
389
344
|
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
r.left += r.dx;
|
|
393
|
-
r.bottom -= r.dy;
|
|
394
|
-
r.right -= r.dx;
|
|
395
|
-
r.move = true;
|
|
396
|
-
return r;
|
|
397
|
-
};
|
|
345
|
+
sc = beginDrag(editor, element);
|
|
346
|
+
currentElement[keyboardEditingSymbol] = sc;
|
|
398
347
|
|
|
399
|
-
|
|
400
|
-
currentElement[keyboardEditingSymbol] = sc;
|
|
348
|
+
sc.move({ dx, dy, fx });
|
|
401
349
|
|
|
350
|
+
const timer = setInterval(() => {
|
|
351
|
+
dx += sx;
|
|
352
|
+
dy += sy;
|
|
402
353
|
sc.move({ dx, dy, fx });
|
|
354
|
+
}, 250);
|
|
355
|
+
|
|
356
|
+
|
|
357
|
+
const release = () => {
|
|
358
|
+
clearInterval(timer);
|
|
359
|
+
currentElement[keyboardEditingSymbol] = void 0;
|
|
360
|
+
currentElement.removeEventListener("keyup", release);
|
|
361
|
+
sc.commit();
|
|
362
|
+
};
|
|
363
|
+
currentElement.addEventListener("keyup", release);
|
|
403
364
|
|
|
404
|
-
const timer = setInterval(() =>
|
|
405
|
-
sc.move({ dx, dy, fx })
|
|
406
|
-
, 250);
|
|
407
365
|
|
|
366
|
+
};
|
|
408
367
|
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
currentElement.removeEventListener("keyup", release);
|
|
413
|
-
sc.commit();
|
|
414
|
-
};
|
|
415
|
-
currentElement.addEventListener("keyup", release);
|
|
368
|
+
const updateFocus = (e, b) => {
|
|
369
|
+
if (b) {
|
|
370
|
+
e.focus();
|
|
416
371
|
}
|
|
417
|
-
|
|
372
|
+
return b;
|
|
418
373
|
};
|
|
419
374
|
|
|
420
375
|
export function SelectionUI() {
|
|
421
376
|
return <selected-element data-element="selection"
|
|
422
|
-
|
|
423
|
-
|
|
377
|
+
tabIndex="-1"
|
|
378
|
+
data-edit={BindEditor.oneWay((editor,e) => updateFocus(e, /relative/i.test(editor.selection.parentStyle.position)
|
|
379
|
+
&& /absolute|fixed/i.test(editor.selection.currentStyle.position) ? "1" : null))}
|
|
424
380
|
event-pointerdown={BindEditor.event(eventPointerDown as any)}
|
|
425
381
|
event-keydown={BindEditor.event(eventKeyDown as any)}
|
|
426
382
|
style-left={BindEditor.oneWay((e) => e.selection.left)}
|