@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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@social-mail/social-mail-client",
3
- "version": "1.8.342",
3
+ "version": "1.8.344",
4
4
  "description": "",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -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
- 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
- }
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
- move({ dx, dy, fx}: { dx: number, dy: number, fx: (r: IRect, ) => IRect}) {
66
+ const d = undoRedo.beginPause();
122
67
 
123
- this.changed = true;
68
+ let resized = false;
69
+ let changed = false;
70
+ let timer = void 0;
124
71
 
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;
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
- this.resized = true;
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
- this.timer = setTimeout(() => {
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
- this.d.resume();
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 (this.resized) {
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(this.timer);
214
- this.timer = setTimeout(() => {
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 = new SelectedCapture(editor, element);
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 = e.repeat ? 5 : 1;
315
+ dy = 1;
369
316
  break;
370
317
  case "ArrowUp":
371
318
  // Do something for "up arrow" key press.
372
- dy = e.repeat ? -5 : -1;
319
+ dy = -1;
373
320
  break;
374
321
  case "ArrowLeft":
375
322
  // Do something for "left arrow" key press.
376
- dx = e.repeat ? -5 : -1;
323
+ dx = -1;
377
324
  break;
378
325
  case "ArrowRight":
379
326
  // Do something for "right arrow" key press.
380
- dx = e.repeat ? 5 : 1;
327
+ dx = 1;
381
328
  break;
382
329
  default:
383
330
  return;
384
331
  }
385
332
 
386
- let sc: SelectedCapture = currentElement[keyboardEditingSymbol];
333
+ const sx = dx * 5;
334
+ const sy = dy * 5;
387
335
 
388
- if(!sc) {
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
- 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
- };
345
+ sc = beginDrag(editor, element);
346
+ currentElement[keyboardEditingSymbol] = sc;
398
347
 
399
- sc = new SelectedCapture(editor, element);
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
- const release = () => {
410
- clearInterval(timer);
411
- currentElement[keyboardEditingSymbol] = void 0;
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
- data-edit={BindEditor.oneWay((e) => /relative/i.test(e.selection.parentStyle.position)
423
- && /absolute|fixed/i.test(e.selection.currentStyle.position) ? "1" : null)}
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)}