@social-mail/social-mail-client 1.8.342 → 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.342",
3
+ "version": "1.8.343",
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;
@@ -290,11 +233,13 @@ const eventPointerDown = (editor: HtmlPageEditor, e: PointerEvent) => {
290
233
  const element = e.target as HTMLElement;
291
234
  const currentElement = e.currentTarget as HTMLElement;
292
235
  if (!currentElement.hasAttribute("data-edit")) {
236
+ setTimeout(() => currentElement.hasAttribute("data-edit")
237
+ ? currentElement.focus({ preventScroll: true })
238
+ : void 0, 250);
293
239
  return;
294
240
  }
295
241
 
296
- currentElement.tabIndex = 0;
297
- currentElement.focus();
242
+ currentElement.focus({ preventScroll: true });
298
243
 
299
244
  const resize = element.getAttribute("data-resize");
300
245
  if (resize) {
@@ -358,6 +303,7 @@ const eventKeyDown = (editor: HtmlPageEditor, e: KeyboardEvent) => {
358
303
  if (!currentElement.hasAttribute("data-edit")) {
359
304
  return;
360
305
  }
306
+ // e.preventDefault();
361
307
 
362
308
  let dx = 0;
363
309
  let dy = 0;
@@ -383,7 +329,7 @@ const eventKeyDown = (editor: HtmlPageEditor, e: KeyboardEvent) => {
383
329
  return;
384
330
  }
385
331
 
386
- let sc: SelectedCapture = currentElement[keyboardEditingSymbol];
332
+ let sc: ReturnType<typeof beginDrag> = currentElement[keyboardEditingSymbol];
387
333
 
388
334
  if(!sc) {
389
335
 
@@ -396,7 +342,7 @@ const eventKeyDown = (editor: HtmlPageEditor, e: KeyboardEvent) => {
396
342
  return r;
397
343
  };
398
344
 
399
- sc = new SelectedCapture(editor, element);
345
+ sc = beginDrag(editor, element);
400
346
  currentElement[keyboardEditingSymbol] = sc;
401
347
 
402
348
  sc.move({ dx, dy, fx });
@@ -419,6 +365,7 @@ const eventKeyDown = (editor: HtmlPageEditor, e: KeyboardEvent) => {
419
365
 
420
366
  export function SelectionUI() {
421
367
  return <selected-element data-element="selection"
368
+ tabIndex="-1"
422
369
  data-edit={BindEditor.oneWay((e) => /relative/i.test(e.selection.parentStyle.position)
423
370
  && /absolute|fixed/i.test(e.selection.currentStyle.position) ? "1" : null)}
424
371
  event-pointerdown={BindEditor.event(eventPointerDown as any)}