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

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.343",
4
4
  "description": "",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -5,7 +5,7 @@ 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
10
  declare global {
11
11
  namespace JSX {
@@ -22,13 +22,14 @@ interface IRect {
22
22
  bottom;
23
23
  dx;
24
24
  dy;
25
- sx;
26
- sy;
25
+ // sx;
26
+ // sy;
27
27
  move?: boolean;
28
28
  }
29
29
 
30
- const setCapture = (editor: HtmlPageEditor, element: HTMLElement, e: PointerEvent, fx: (r: IRect, ) => IRect) => {
30
+ const ps = (v, max) => (v* 100 / (max || 1)).toFixed(2);
31
31
 
32
+ const beginDrag = (editor: HtmlPageEditor, element: HTMLElement) => {
32
33
 
33
34
  const prefix = editor.maxWidth === tabletScreenWidth
34
35
  ? "styler-tablet"
@@ -36,70 +37,56 @@ const setCapture = (editor: HtmlPageEditor, element: HTMLElement, e: PointerEven
36
37
  ? "styler-mobile"
37
38
  : "styler-desktop");
38
39
 
39
- const sx = e.clientX;
40
- const sy = e.clientY;
41
-
42
40
  const { selection, hover } = editor;
43
41
  const selectedElement = selection.element;
44
42
  const selectedParent = selectedElement.parentElement;
45
43
 
46
- const frameDocument = selectedElement.ownerDocument;
47
- const frame = editor.contentEditor;
48
44
 
49
45
 
50
46
  const insetAttribute = `${prefix}-inset`;
51
47
  const widthAttribute = `${prefix}-width`;
52
48
  const heightAttribute = `${prefix}-height`;
53
49
 
50
+
54
51
  const oldWidth = selectedElement.getAttribute(widthAttribute);
55
52
  const oldHeight = selectedElement.getAttribute(heightAttribute);
56
53
  const oldInset = selectedElement.getAttribute(insetAttribute);
57
54
 
58
- const records = [] as MutationRecord[];
59
-
60
-
61
55
  const style = selectedElement.ownerDocument.defaultView.getComputedStyle(selectedElement);
62
56
  const width = selectedParent.offsetWidth;
63
57
  const height = selectedParent.offsetHeight;
64
58
 
65
- const ps = (v, max) => (v* 100 / (max || 1)).toFixed(2);
66
-
67
- const { undoRedo } = editor;
68
-
69
- const d = undoRedo.beginPause();
70
-
71
59
  const left = parseFloat(style.left || "0");
72
60
  const top = parseFloat(style.top || "0");
73
61
  const bottom = parseFloat(style.bottom || "0");
74
62
  const right = parseFloat(style.right || "0");
75
63
 
76
- let moved = false;
64
+ const { undoRedo } = editor;
77
65
 
66
+ const d = undoRedo.beginPause();
67
+
68
+ let resized = false;
78
69
  let changed = false;
70
+ let timer = void 0;
71
+
72
+ const move = ({ dx, dy, fx}: { dx: number, dy: number, fx: (r: IRect, ) => IRect}) => {
73
+
74
+ changed = true;
79
75
 
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
76
  const ri = {
87
77
  left,
88
78
  top,
89
79
  right,
90
80
  bottom,
91
- sx,
92
- sy,
93
81
  dx,
94
82
  dy
95
83
  };
96
- changed = true;
97
84
  const r = fx(ri);
98
85
  const inset = `${ps(r.top, height)}% ${ps(r.right, width)}% ${ps(r.bottom, height)}% ${ps(r.left, width)}%`;
99
86
  selectedElement.setAttribute(insetAttribute, inset);
100
87
 
101
88
  if (!r.move) {
102
- moved = true;
89
+ resized = true;
103
90
  let widthDiff = -r.left;
104
91
  let heightDiff = -r.top;
105
92
  if (ri.bottom === r.bottom) {
@@ -114,22 +101,96 @@ const setCapture = (editor: HtmlPageEditor, element: HTMLElement, e: PointerEven
114
101
  selectedElement.setAttribute(heightAttribute, newHeight);
115
102
  }
116
103
 
104
+ // clearTimeout(this.timer);
117
105
  setTimeout(() => {
118
106
  selection.updateRect();
119
107
  hover.updateRect();
120
108
  }, 1);
121
109
  };
122
110
 
111
+ const commit = () => {
112
+
113
+ d.resume();
114
+
115
+ const records = [] as MutationRecord[];
116
+
117
+ // push records...
118
+ records.push({
119
+ type: "attributes",
120
+ oldValue: oldInset,
121
+ target: selectedElement as any,
122
+ attributeName: insetAttribute,
123
+ attributeNamespace: "",
124
+ } as MutationRecord);
125
+
126
+ if (resized) {
127
+ records.push({
128
+ type: "attributes",
129
+ oldValue: oldWidth,
130
+ target: selectedElement as any,
131
+ attributeName: widthAttribute,
132
+ attributeNamespace: "",
133
+ } as MutationRecord);
134
+ records.push({
135
+ type: "attributes",
136
+ oldValue: oldHeight,
137
+ target: selectedElement as any,
138
+ attributeName: heightAttribute,
139
+ attributeNamespace: "",
140
+ } as MutationRecord);
141
+ }
142
+
143
+ undoRedo.observe(records);
144
+ editor.commit();
145
+
146
+ clearTimeout(timer);
147
+ timer = setTimeout(() => {
148
+ selection.updateRect();
149
+ hover.updateRect();
150
+ }, 1);
151
+ };
152
+
153
+ return {
154
+ move,
155
+ commit,
156
+ selectedElement,
157
+ selectedParent,
158
+ get changed() {
159
+ return changed;
160
+ }
161
+ };
162
+ };
163
+
164
+ const setCapture = (editor: HtmlPageEditor, element: HTMLElement, e: PointerEvent, fx: (r: IRect, ) => IRect) => {
165
+
166
+
167
+ const sc = beginDrag(editor, element);
168
+
169
+ const sx = e.clientX;
170
+ const sy = e.clientY;
171
+
172
+ const captureMove = (evt: PointerEvent) => {
173
+ const dx = evt.clientX - sx;
174
+ const dy = evt.clientY - sy;
175
+ if (dx === 0 && dy === 0) {
176
+ return;
177
+ }
178
+ sc.move({ dx, dy, fx});
179
+ };
180
+
123
181
  element.addEventListener("pointermove", captureMove);
124
182
  element.setPointerCapture(e.pointerId);
125
183
  const release = (e1: PointerEvent) => {
126
184
  element.releasePointerCapture(e.pointerId);
127
185
  element.removeEventListener("pointermove", captureMove);
128
186
  element.removeEventListener("pointerup", release);
129
- captureMove(e1);
130
- d.resume();
131
187
 
132
- if (!changed) {
188
+ if (!sc.changed) {
189
+
190
+ const { selectedElement, selectedParent } = sc;
191
+ const frameDocument = selectedElement.ownerDocument;
192
+ const frame = editor.contentEditor;
193
+
133
194
 
134
195
  // try to select an element...
135
196
  const frameRect = frame.getBoundingClientRect();
@@ -163,40 +224,7 @@ const setCapture = (editor: HtmlPageEditor, element: HTMLElement, e: PointerEven
163
224
 
164
225
  return;
165
226
  }
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
-
227
+ sc.commit();
200
228
  };
201
229
  element.addEventListener("pointerup", release);
202
230
  };
@@ -205,9 +233,14 @@ const eventPointerDown = (editor: HtmlPageEditor, e: PointerEvent) => {
205
233
  const element = e.target as HTMLElement;
206
234
  const currentElement = e.currentTarget as HTMLElement;
207
235
  if (!currentElement.hasAttribute("data-edit")) {
236
+ setTimeout(() => currentElement.hasAttribute("data-edit")
237
+ ? currentElement.focus({ preventScroll: true })
238
+ : void 0, 250);
208
239
  return;
209
240
  }
210
241
 
242
+ currentElement.focus({ preventScroll: true });
243
+
211
244
  const resize = element.getAttribute("data-resize");
212
245
  if (resize) {
213
246
 
@@ -262,11 +295,81 @@ const eventPointerDown = (editor: HtmlPageEditor, e: PointerEvent) => {
262
295
 
263
296
  };
264
297
 
298
+ const keyboardEditingSymbol = Symbol("keyboardEditing");
299
+
300
+ const eventKeyDown = (editor: HtmlPageEditor, e: KeyboardEvent) => {
301
+ const element = e.target as HTMLElement;
302
+ const currentElement = e.currentTarget as HTMLElement;
303
+ if (!currentElement.hasAttribute("data-edit")) {
304
+ return;
305
+ }
306
+ // e.preventDefault();
307
+
308
+ let dx = 0;
309
+ let dy = 0;
310
+
311
+ switch(e.key) {
312
+ case "ArrowDown":
313
+ // Do something for "down arrow" key press.
314
+ dy = e.repeat ? 5 : 1;
315
+ break;
316
+ case "ArrowUp":
317
+ // Do something for "up arrow" key press.
318
+ dy = e.repeat ? -5 : -1;
319
+ break;
320
+ case "ArrowLeft":
321
+ // Do something for "left arrow" key press.
322
+ dx = e.repeat ? -5 : -1;
323
+ break;
324
+ case "ArrowRight":
325
+ // Do something for "right arrow" key press.
326
+ dx = e.repeat ? 5 : 1;
327
+ break;
328
+ default:
329
+ return;
330
+ }
331
+
332
+ let sc: ReturnType<typeof beginDrag> = currentElement[keyboardEditingSymbol];
333
+
334
+ if(!sc) {
335
+
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
+ };
344
+
345
+ sc = beginDrag(editor, element);
346
+ currentElement[keyboardEditingSymbol] = sc;
347
+
348
+ sc.move({ dx, dy, fx });
349
+
350
+ const timer = setInterval(() =>
351
+ sc.move({ dx, dy, fx })
352
+ , 250);
353
+
354
+
355
+ const release = () => {
356
+ clearInterval(timer);
357
+ currentElement[keyboardEditingSymbol] = void 0;
358
+ currentElement.removeEventListener("keyup", release);
359
+ sc.commit();
360
+ };
361
+ currentElement.addEventListener("keyup", release);
362
+ }
363
+
364
+ };
365
+
265
366
  export function SelectionUI() {
266
367
  return <selected-element data-element="selection"
368
+ tabIndex="-1"
267
369
  data-edit={BindEditor.oneWay((e) => /relative/i.test(e.selection.parentStyle.position)
268
370
  && /absolute|fixed/i.test(e.selection.currentStyle.position) ? "1" : null)}
269
371
  event-pointerdown={BindEditor.event(eventPointerDown as any)}
372
+ event-keydown={BindEditor.event(eventKeyDown as any)}
270
373
  style-left={BindEditor.oneWay((e) => e.selection.left)}
271
374
  style-top={BindEditor.oneWay((e) => e.selection.top)}
272
375
  style-width={BindEditor.oneWay((e) => e.selection.width)}