@social-mail/social-mail-client 1.8.339 → 1.8.342

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@social-mail/social-mail-client",
3
- "version": "1.8.339",
3
+ "version": "1.8.342",
4
4
  "description": "",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -5,8 +5,10 @@ import EditorPopupMenu from "../../menus/EditorPopupMenu";
5
5
  import { BindEditor } from "../../properties/controls/PropertyEditor";
6
6
 
7
7
  import "./SelectionUI.global.css";
8
- import HtmlPageEditor from "../HtmlPageEditor";
8
+ import type HtmlPageEditor from "../HtmlPageEditor";
9
9
  import { mobileScreenWidth, tabletScreenWidth } from "../sizes";
10
+ import type { SelectedElement } from "../SelectedElement";
11
+ import UndoRedo from "../UndoRedo";
10
12
  declare global {
11
13
  namespace JSX {
12
14
  interface IntrinsicElements {
@@ -22,84 +24,130 @@ interface IRect {
22
24
  bottom;
23
25
  dx;
24
26
  dy;
25
- sx;
26
- sy;
27
+ // sx;
28
+ // sy;
27
29
  move?: boolean;
28
30
  }
29
31
 
30
- const setCapture = (editor: HtmlPageEditor, element: HTMLElement, e: PointerEvent, fx: (r: IRect, ) => IRect) => {
31
-
32
-
33
- const prefix = editor.maxWidth === tabletScreenWidth
34
- ? "styler-tablet"
35
- : (editor.maxWidth === mobileScreenWidth
36
- ? "styler-mobile"
37
- : "styler-desktop");
38
-
39
- const sx = e.clientX;
40
- const sy = e.clientY;
41
-
42
- const { selection, hover } = editor;
43
- const selectedElement = selection.element;
44
- const selectedParent = selectedElement.parentElement;
45
-
46
- const frameDocument = selectedElement.ownerDocument;
47
- const frame = editor.contentEditor;
48
-
49
-
50
- const insetAttribute = `${prefix}-inset`;
51
- const widthAttribute = `${prefix}-width`;
52
- const heightAttribute = `${prefix}-height`;
53
-
54
- const oldWidth = selectedElement.getAttribute(widthAttribute);
55
- const oldHeight = selectedElement.getAttribute(heightAttribute);
56
- const oldInset = selectedElement.getAttribute(insetAttribute);
57
-
58
- const records = [] as MutationRecord[];
59
-
60
-
61
- const style = selectedElement.ownerDocument.defaultView.getComputedStyle(selectedElement);
62
- const width = selectedParent.offsetWidth;
63
- const height = selectedParent.offsetHeight;
64
-
65
- const ps = (v, max) => (v* 100 / (max || 1)).toFixed(2);
66
-
67
- const { undoRedo } = editor;
68
-
69
- const d = undoRedo.beginPause();
32
+ const ps = (v, max) => (v* 100 / (max || 1)).toFixed(2);
33
+
34
+ class SelectedCapture {
35
+
36
+ public left;
37
+ public top;
38
+ public width;
39
+ public height;
40
+ public right;
41
+ public bottom;
42
+ public oldInset;
43
+ public oldWidth;
44
+ public oldHeight;
45
+
46
+ d: { resume: () => void; };
47
+ selectedParent: HTMLElement;
48
+ selectedElement: HTMLElement;
49
+ insetAttribute: string;
50
+ widthAttribute: string;
51
+ heightAttribute: string;
52
+ resized: boolean;
53
+ selection: SelectedElement;
54
+ hover: SelectedElement;
55
+ undoRedo: UndoRedo;
56
+ changed: boolean;
57
+ timer: any;
58
+
59
+ constructor(
60
+ public editor: HtmlPageEditor,
61
+ public element: HTMLElement
62
+ ) {
63
+ const prefix = editor.maxWidth === tabletScreenWidth
64
+ ? "styler-tablet"
65
+ : (editor.maxWidth === mobileScreenWidth
66
+ ? "styler-mobile"
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
+ }
70
120
 
71
- const left = parseFloat(style.left || "0");
72
- const top = parseFloat(style.top || "0");
73
- const bottom = parseFloat(style.bottom || "0");
74
- const right = parseFloat(style.right || "0");
121
+ move({ dx, dy, fx}: { dx: number, dy: number, fx: (r: IRect, ) => IRect}) {
75
122
 
76
- let moved = false;
123
+ this.changed = true;
77
124
 
78
- let changed = false;
125
+ const {
126
+ left, top, bottom, right,
127
+ height, width,
128
+ selectedElement,
129
+ oldInset,
130
+ insetAttribute,
131
+ widthAttribute,
132
+ heightAttribute,
133
+ selection,
134
+ hover
135
+ } = this;
79
136
 
80
- const captureMove = (evt: PointerEvent) => {
81
- const dx = evt.clientX - sx;
82
- const dy = evt.clientY - sy;
83
- if (dx === 0 && dy === 0) {
84
- return;
85
- }
86
137
  const ri = {
87
138
  left,
88
139
  top,
89
140
  right,
90
141
  bottom,
91
- sx,
92
- sy,
93
142
  dx,
94
143
  dy
95
144
  };
96
- changed = true;
97
145
  const r = fx(ri);
98
146
  const inset = `${ps(r.top, height)}% ${ps(r.right, width)}% ${ps(r.bottom, height)}% ${ps(r.left, width)}%`;
99
147
  selectedElement.setAttribute(insetAttribute, inset);
100
148
 
101
149
  if (!r.move) {
102
- moved = true;
150
+ this.resized = true;
103
151
  let widthDiff = -r.left;
104
152
  let heightDiff = -r.top;
105
153
  if (ri.bottom === r.bottom) {
@@ -114,10 +162,77 @@ const setCapture = (editor: HtmlPageEditor, element: HTMLElement, e: PointerEven
114
162
  selectedElement.setAttribute(heightAttribute, newHeight);
115
163
  }
116
164
 
117
- setTimeout(() => {
165
+ clearTimeout(this.timer);
166
+ this.timer = setTimeout(() => {
167
+ selection.updateRect();
168
+ hover.updateRect();
169
+ }, 1);
170
+ }
171
+
172
+ commit() {
173
+
174
+ this.d.resume();
175
+
176
+ const records = [] as MutationRecord[];
177
+
178
+ const { oldInset, oldHeight, oldWidth, selectedElement,
179
+ insetAttribute, widthAttribute, heightAttribute,
180
+ undoRedo, editor,
181
+ selection, hover
182
+ } = this;
183
+
184
+ // push records...
185
+ records.push({
186
+ type: "attributes",
187
+ oldValue: oldInset,
188
+ target: selectedElement as any,
189
+ attributeName: insetAttribute,
190
+ attributeNamespace: "",
191
+ } as MutationRecord);
192
+
193
+ if (this.resized) {
194
+ records.push({
195
+ type: "attributes",
196
+ oldValue: oldWidth,
197
+ target: selectedElement as any,
198
+ attributeName: widthAttribute,
199
+ attributeNamespace: "",
200
+ } as MutationRecord);
201
+ records.push({
202
+ type: "attributes",
203
+ oldValue: oldHeight,
204
+ target: selectedElement as any,
205
+ attributeName: heightAttribute,
206
+ attributeNamespace: "",
207
+ } as MutationRecord);
208
+ }
209
+
210
+ undoRedo.observe(records);
211
+ editor.commit();
212
+
213
+ clearTimeout(this.timer);
214
+ this.timer = setTimeout(() => {
118
215
  selection.updateRect();
119
216
  hover.updateRect();
120
217
  }, 1);
218
+ }
219
+ }
220
+
221
+ const setCapture = (editor: HtmlPageEditor, element: HTMLElement, e: PointerEvent, fx: (r: IRect, ) => IRect) => {
222
+
223
+
224
+ const sc = new SelectedCapture(editor, element);
225
+
226
+ const sx = e.clientX;
227
+ const sy = e.clientY;
228
+
229
+ const captureMove = (evt: PointerEvent) => {
230
+ const dx = evt.clientX - sx;
231
+ const dy = evt.clientY - sy;
232
+ if (dx === 0 && dy === 0) {
233
+ return;
234
+ }
235
+ sc.move({ dx, dy, fx});
121
236
  };
122
237
 
123
238
  element.addEventListener("pointermove", captureMove);
@@ -126,10 +241,13 @@ const setCapture = (editor: HtmlPageEditor, element: HTMLElement, e: PointerEven
126
241
  element.releasePointerCapture(e.pointerId);
127
242
  element.removeEventListener("pointermove", captureMove);
128
243
  element.removeEventListener("pointerup", release);
129
- captureMove(e1);
130
- d.resume();
131
244
 
132
- if (!changed) {
245
+ if (!sc.changed) {
246
+
247
+ const { selectedElement, selectedParent } = sc;
248
+ const frameDocument = selectedElement.ownerDocument;
249
+ const frame = editor.contentEditor;
250
+
133
251
 
134
252
  // try to select an element...
135
253
  const frameRect = frame.getBoundingClientRect();
@@ -163,40 +281,7 @@ const setCapture = (editor: HtmlPageEditor, element: HTMLElement, e: PointerEven
163
281
 
164
282
  return;
165
283
  }
166
- // push records...
167
- records.push({
168
- type: "attributes",
169
- oldValue: oldInset,
170
- target: selectedElement as any,
171
- attributeName: insetAttribute,
172
- attributeNamespace: "",
173
- } as MutationRecord);
174
-
175
- if (moved) {
176
- records.push({
177
- type: "attributes",
178
- oldValue: oldWidth,
179
- target: selectedElement as any,
180
- attributeName: widthAttribute,
181
- attributeNamespace: "",
182
- } as MutationRecord);
183
- records.push({
184
- type: "attributes",
185
- oldValue: oldHeight,
186
- target: selectedElement as any,
187
- attributeName: heightAttribute,
188
- attributeNamespace: "",
189
- } as MutationRecord);
190
- }
191
-
192
- undoRedo.observe(records);
193
- editor.commit();
194
-
195
- setTimeout(() => {
196
- selection.updateRect();
197
- hover.updateRect();
198
- }, 1);
199
-
284
+ sc.commit();
200
285
  };
201
286
  element.addEventListener("pointerup", release);
202
287
  };
@@ -208,6 +293,9 @@ const eventPointerDown = (editor: HtmlPageEditor, e: PointerEvent) => {
208
293
  return;
209
294
  }
210
295
 
296
+ currentElement.tabIndex = 0;
297
+ currentElement.focus();
298
+
211
299
  const resize = element.getAttribute("data-resize");
212
300
  if (resize) {
213
301
 
@@ -262,11 +350,79 @@ const eventPointerDown = (editor: HtmlPageEditor, e: PointerEvent) => {
262
350
 
263
351
  };
264
352
 
353
+ const keyboardEditingSymbol = Symbol("keyboardEditing");
354
+
355
+ const eventKeyDown = (editor: HtmlPageEditor, e: KeyboardEvent) => {
356
+ const element = e.target as HTMLElement;
357
+ const currentElement = e.currentTarget as HTMLElement;
358
+ if (!currentElement.hasAttribute("data-edit")) {
359
+ return;
360
+ }
361
+
362
+ let dx = 0;
363
+ let dy = 0;
364
+
365
+ switch(e.key) {
366
+ case "ArrowDown":
367
+ // Do something for "down arrow" key press.
368
+ dy = e.repeat ? 5 : 1;
369
+ break;
370
+ case "ArrowUp":
371
+ // Do something for "up arrow" key press.
372
+ dy = e.repeat ? -5 : -1;
373
+ break;
374
+ case "ArrowLeft":
375
+ // Do something for "left arrow" key press.
376
+ dx = e.repeat ? -5 : -1;
377
+ break;
378
+ case "ArrowRight":
379
+ // Do something for "right arrow" key press.
380
+ dx = e.repeat ? 5 : 1;
381
+ break;
382
+ default:
383
+ return;
384
+ }
385
+
386
+ let sc: SelectedCapture = currentElement[keyboardEditingSymbol];
387
+
388
+ if(!sc) {
389
+
390
+ const fx = (r) => {
391
+ r.top += r.dy;
392
+ r.left += r.dx;
393
+ r.bottom -= r.dy;
394
+ r.right -= r.dx;
395
+ r.move = true;
396
+ return r;
397
+ };
398
+
399
+ sc = new SelectedCapture(editor, element);
400
+ currentElement[keyboardEditingSymbol] = sc;
401
+
402
+ sc.move({ dx, dy, fx });
403
+
404
+ const timer = setInterval(() =>
405
+ sc.move({ dx, dy, fx })
406
+ , 250);
407
+
408
+
409
+ const release = () => {
410
+ clearInterval(timer);
411
+ currentElement[keyboardEditingSymbol] = void 0;
412
+ currentElement.removeEventListener("keyup", release);
413
+ sc.commit();
414
+ };
415
+ currentElement.addEventListener("keyup", release);
416
+ }
417
+
418
+ };
419
+
265
420
  export function SelectionUI() {
266
421
  return <selected-element data-element="selection"
267
422
  data-edit={BindEditor.oneWay((e) => /relative/i.test(e.selection.parentStyle.position)
268
423
  && /absolute|fixed/i.test(e.selection.currentStyle.position) ? "1" : null)}
269
424
  event-pointerdown={BindEditor.event(eventPointerDown as any)}
425
+ event-keydown={BindEditor.event(eventKeyDown as any)}
270
426
  style-left={BindEditor.oneWay((e) => e.selection.left)}
271
427
  style-top={BindEditor.oneWay((e) => e.selection.top)}
272
428
  style-width={BindEditor.oneWay((e) => e.selection.width)}