@web-atoms/core 2.2.97 → 2.2.102

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.
@@ -1,342 +1,342 @@
1
- import { App } from "../../App";
2
- import Bind from "../../core/Bind";
3
- import { BindableProperty } from "../../core/BindableProperty";
4
- import { IClassOf, IDisposable, IRect } from "../../core/types";
5
- import XNode from "../../core/XNode";
6
- import { AtomWindowViewModel } from "../../view-model/AtomWindowViewModel";
7
- import { AtomUI } from "../core/AtomUI";
8
- import { AtomTheme } from "../styles/AtomTheme";
9
- import { AtomWindowStyle } from "../styles/AtomWindowStyle";
10
- import { AtomControl } from "./AtomControl";
11
- import { AtomTemplate } from "./AtomTemplate";
12
-
13
- export function getTemplateParent(e: HTMLElement) {
14
- const tp = e._templateParent;
15
- if (tp) {
16
- return tp;
17
- }
18
- const p = e._logicalParent || e.parentElement;
19
- if (p) {
20
- return getTemplateParent(p);
21
- }
22
- }
23
-
24
- export class AtomWindowFrameTemplate extends AtomTemplate {
25
-
26
- public get templateParent(): AtomWindow {
27
- return getTemplateParent(this.element);
28
- }
29
-
30
- public commandPresenter: HTMLElement;
31
-
32
- public titlePresenter: HTMLElement;
33
-
34
- protected preCreate() {
35
- this.titlePresenter = null;
36
- this.commandPresenter = null;
37
- this.contentPresenter = null;
38
- super.preCreate();
39
- }
40
-
41
- protected create(): void {
42
-
43
- // remember, if you do not wish to use dynamic themes
44
- // then use one time binding
45
- this.render(<div
46
- class="frame"
47
- styleWidth={Bind.oneWay(() => this.templateParent.width || undefined)}
48
- styleHeight={Bind.oneWay(() => this.templateParent.height || undefined)}
49
- styleLeft={Bind.oneWay(() => this.templateParent.x >= 0 ? `${this.templateParent.x}px` : undefined)}
50
- styleTop={Bind.oneWay(() => this.templateParent.y >= 0 ? `${this.templateParent.y}px` : undefined)}
51
- styleMarginTop={Bind.oneWay(() => this.templateParent.x >= 0 ? "0" : undefined)}
52
- styleMarginLeft={Bind.oneWay(() => this.templateParent.x >= 0 ? "0" : undefined)}
53
- styleMarginRight={Bind.oneWay(() => this.templateParent.x >= 0 ? "0" : undefined)}
54
- styleMarginBottom={Bind.oneWay(() => this.templateParent.x >= 0 ? "0" : undefined)}>
55
- <div
56
- class="title-presenter"
57
- presenter={Bind.presenter("titlePresenter")}/>
58
- <div
59
- class="content-presenter"
60
- presenter={Bind.presenter("contentPresenter")}/>
61
- <div
62
- class="command-bar-presenter"
63
- presenter={Bind.presenter("commandPresenter")}/>
64
- </div>);
65
- // this.bind(this.element, "styleClass", [["templateParent", "controlStyle", "frame"]]);
66
- // this.bind(this.element, "styleWidth", [["templateParent", "width"]], false, (v) => v || undefined);
67
- // this.bind(this.element, "styleHeight", [["templateParent", "height"]], false, (v) => v || undefined);
68
- // this.bind(this.element, "styleLeft", [["templateParent", "x"]],
69
- // false, (v) => v >= 0 ? v + "px" : undefined);
70
- // this.bind(this.element, "styleTop", [["templateParent", "y"]],
71
- // false, (v) => v >= 0 ? v + "px" : undefined);
72
- // this.bind(this.element, "styleMarginTop", [["templateParent", "x"]], false, (v) => v >= 0 ? "0" : undefined);
73
- // this.bind(this.element, "styleMarginLeft", [["templateParent", "x"]],
74
- // false, (v) => v >= 0 ? "0" : undefined);
75
- // this.bind(this.element, "styleMarginRight", [["templateParent", "x"]],
76
- // false, (v) => v >= 0 ? "0" : undefined);
77
- // this.bind(this.element, "styleMarginBottom", [["templateParent", "x"]],
78
- // false, (v) => v >= 0 ? "0" : undefined);
79
- // // add title host
80
- // const titlePresenter = document.createElement("div");
81
- // this.bind(titlePresenter, "styleClass", [["templateParent", "controlStyle", "titlePresenter"]]);
82
- // // titleHost.classList.add(style.titleHost.className);
83
- // this.titlePresenter = titlePresenter;
84
- // this.element.appendChild(titlePresenter);
85
-
86
- // // add content presenter
87
- // const cp = document.createElement("div");
88
- // this.bind(cp, "styleClass", [["templateParent", "controlStyle", "content"]]);
89
- // // cp.classList.add(style.content.className);
90
- // this.contentPresenter = cp;
91
- // this.element.appendChild(cp);
92
-
93
- // // create command presenter
94
- // const cdp = document.createElement("div");
95
- // // cdp.classList.add(style.commandBar.className);
96
- // this.bind(cdp, "styleClass", [["templateParent", "controlStyle", "commandBar"]]);
97
- // this.commandPresenter = cdp;
98
- // this.element.appendChild(cdp);
99
-
100
- }
101
-
102
- }
103
-
104
- class AtomWindowTitleTemplate extends AtomControl {
105
-
106
- public get templateParent(): AtomWindow {
107
- return getTemplateParent(this.element);
108
- }
109
-
110
- protected create(): void {
111
-
112
- this.render(<div
113
- class="title-host">
114
- <span
115
- class="title"
116
- text={Bind.oneWay(() => this.templateParent.title)}
117
- />
118
- <button
119
- class="close-button"
120
- eventClick={Bind.event(() => this.templateParent.close())}
121
- />
122
- </div>);
123
-
124
- // this.bind(this.element, "styleClass", [["templateParent", "controlStyle", "titleHost"]]);
125
-
126
- // // add title
127
-
128
- // const title = document.createElement("span");
129
- // this.bind(title, "styleClass", [["templateParent", "controlStyle", "title"]]);
130
- // // title.classList.add(style.title.className);
131
- // this.bind(title, "text", [["templateParent", "title"]], false);
132
-
133
- // // add close button
134
- // const closeButton = document.createElement("button");
135
- // this.bind(closeButton, "styleClass", [["templateParent", "controlStyle", "closeButton"]]);
136
- // // closeButton.textContent = "x";
137
-
138
- // this.bindEvent(closeButton, "click", (e) => {
139
- // const w = getTemplateParent(this.element) as AtomWindow;
140
- // w.close();
141
- // });
142
-
143
- // // append title host > title
144
-
145
- // this.append(title);
146
- // this.append(closeButton);
147
- }
148
- }
149
-
150
- export class AtomWindow extends AtomControl {
151
-
152
- public static windowTemplate = XNode.prepare("windowTemplate", true, true);
153
-
154
- public static commandTemplate = XNode.prepare("commandTemplate", true, true);
155
-
156
- public static titleTemplate = XNode.prepare("titleTemplate", true, true);
157
-
158
- public static frameTemplate = XNode.prepare("frameTemplate", true, true);
159
-
160
- public get templateParent() {
161
- return getTemplateParent(this.element);
162
- }
163
-
164
- public title: string = "";
165
-
166
- public width: string = "";
167
-
168
- public height: string = "";
169
-
170
- public x: number = -1;
171
-
172
- public y: number = -1;
173
-
174
- public windowTemplate: IClassOf<AtomControl>;
175
-
176
- public commandTemplate: IClassOf<AtomControl>;
177
-
178
- public titleTemplate: IClassOf<AtomControl> = AtomWindowTitleTemplate;
179
-
180
- public frameTemplate: IClassOf<AtomWindowFrameTemplate> = AtomWindowFrameTemplate;
181
-
182
- private isReady: boolean = false;
183
-
184
- public onPropertyChanged(name: string): void {
185
- switch (name) {
186
- case "windowTemplate":
187
- case "commandTemplate":
188
- case "frameTemplate":
189
- this.invalidate();
190
- break;
191
- }
192
- }
193
-
194
- public close(): void {
195
-
196
- const vm = this.viewModel as AtomWindowViewModel;
197
- if (vm.cancel) {
198
- this.app.runAsync(() => vm.cancel());
199
- return;
200
- }
201
-
202
- const message = `atom-window-cancel:${(this as any).id}`;
203
- const device = this.app.resolve(App);
204
- device.broadcast(message, "cancelled");
205
- }
206
-
207
- public onUpdateUI(): void {
208
- if (!(this.windowTemplate && this.frameTemplate)) {
209
- return;
210
- }
211
-
212
- if (this.isReady) {
213
- return;
214
- }
215
-
216
- this.bind(this.element, "title", [["viewModel", "title"]]);
217
-
218
- // let us create frame first...
219
- const frame = new (this.frameTemplate)(this.app);
220
- const fe = frame.element;
221
-
222
- // setup drag and drop for the frame...
223
- const titleContent = new (this.titleTemplate)(this.app);
224
- (titleContent.element)._templateParent = this;
225
- frame.titlePresenter.appendChild(titleContent.element);
226
-
227
- this.setupDragging(frame.titlePresenter);
228
-
229
- this.element.classList.add("frame-host");
230
-
231
- fe._logicalParent = this.element;
232
- fe._templateParent = this;
233
-
234
- if (!frame.contentPresenter) {
235
- throw new Error("ContentPresenter must be set inside frameTemplate before creating window");
236
- }
237
-
238
- const content = new (this.windowTemplate)(this.app);
239
- (content.element)._templateParent = this;
240
- this.setElementClass(content.element, { content: 1 });
241
- frame.contentPresenter.appendChild(content.element);
242
-
243
- if (this.commandTemplate) {
244
- if (!frame.commandPresenter) {
245
- throw new Error("CommandPresenter must be set inside frameTemplate" +
246
- "before creating window if command template is present");
247
- }
248
- const command = new (this.commandTemplate)(this.app);
249
- (command.element)._templateParent = this;
250
- this.setElementClass(command.element, { "command-bar": 1 });
251
- frame.commandPresenter.appendChild(command.element);
252
- }
253
- this.append(frame);
254
-
255
- // lets center frame...
256
- setTimeout(() => {
257
- this.centerFrame(frame.element);
258
- }, 100);
259
- this.isReady = true;
260
- }
261
-
262
- protected preCreate() {
263
- this.defaultControlStyle = AtomWindowStyle;
264
- this.title = null;
265
- this.width = "";
266
- this.height = "";
267
- this.x = -1;
268
- this.y = -1;
269
- this.windowTemplate = null;
270
- this.commandTemplate = null;
271
- this.titleTemplate = AtomWindowTitleTemplate;
272
- this.frameTemplate = AtomWindowFrameTemplate;
273
- super.preCreate();
274
- this.render(<div
275
- styleClass={Bind.oneTime(() => this.controlStyle.name)}
276
- ></div>);
277
- }
278
-
279
- private centerFrame(e: HTMLElement): void {
280
- /// window is destroyed probably..
281
- if (!this.element) {
282
- return;
283
- }
284
- const parent = this.element.parentElement;
285
- if (parent as any === window || parent as any === document.body) {
286
- return;
287
- }
288
- if (parent.offsetWidth <= 0 || parent.offsetHeight <= 0) {
289
- setTimeout(() => {
290
- this.centerFrame(e);
291
- }, 100);
292
- return;
293
- }
294
-
295
- if (e.offsetWidth <= 0 || e.offsetHeight <= 0) {
296
- setTimeout(() => {
297
- this.centerFrame(e);
298
- }, 100);
299
- return;
300
- }
301
-
302
- const x = (parent.offsetWidth - e.offsetWidth) / 2;
303
- const y = (parent.offsetHeight - e.offsetHeight) / 2;
304
- this.x = x;
305
- this.y = y;
306
- e.style.opacity = "1";
307
- this.element.style.removeProperty("opacity");
308
- }
309
-
310
- private setupDragging(tp: HTMLElement): void {
311
- this.bindEvent(tp, "mousedown", (startEvent: MouseEvent) => {
312
- startEvent.preventDefault();
313
- const disposables: IDisposable[] = [];
314
- // const offset = AtomUI.screenOffset(tp);
315
- const offset = { x: tp.parentElement.offsetLeft, y: tp.parentElement.offsetTop };
316
- const rect: IRect = { x: startEvent.clientX, y: startEvent.clientY };
317
- const cursor = tp.style.cursor;
318
- tp.style.cursor = "move";
319
- disposables.push(this.bindEvent(document.body, "mousemove", (moveEvent: MouseEvent) => {
320
- const { clientX, clientY } = moveEvent;
321
- const dx = clientX - rect.x;
322
- const dy = clientY - rect.y;
323
-
324
- offset.x += dx;
325
- offset.y += dy;
326
-
327
- this.x = offset.x;
328
- this.y = offset.y;
329
-
330
- rect.x = clientX;
331
- rect.y = clientY;
332
- }));
333
- disposables.push(this.bindEvent(document.body, "mouseup", (endEvent: MouseEvent) => {
334
- tp.style.cursor = cursor;
335
- for (const iterator of disposables) {
336
- iterator.dispose();
337
- }
338
- }));
339
- });
340
- }
341
-
342
- }
1
+ import { App } from "../../App";
2
+ import Bind from "../../core/Bind";
3
+ import { BindableProperty } from "../../core/BindableProperty";
4
+ import { IClassOf, IDisposable, IRect } from "../../core/types";
5
+ import XNode from "../../core/XNode";
6
+ import { AtomWindowViewModel } from "../../view-model/AtomWindowViewModel";
7
+ import { AtomUI } from "../core/AtomUI";
8
+ import { AtomTheme } from "../styles/AtomTheme";
9
+ import { AtomWindowStyle } from "../styles/AtomWindowStyle";
10
+ import { AtomControl } from "./AtomControl";
11
+ import { AtomTemplate } from "./AtomTemplate";
12
+
13
+ export function getTemplateParent(e: HTMLElement) {
14
+ const tp = e._templateParent;
15
+ if (tp) {
16
+ return tp;
17
+ }
18
+ const p = e._logicalParent || e.parentElement;
19
+ if (p) {
20
+ return getTemplateParent(p);
21
+ }
22
+ }
23
+
24
+ export class AtomWindowFrameTemplate extends AtomTemplate {
25
+
26
+ public get templateParent(): AtomWindow {
27
+ return getTemplateParent(this.element) as AtomWindow;
28
+ }
29
+
30
+ public commandPresenter: HTMLElement;
31
+
32
+ public titlePresenter: HTMLElement;
33
+
34
+ protected preCreate() {
35
+ this.titlePresenter = null;
36
+ this.commandPresenter = null;
37
+ this.contentPresenter = null;
38
+ super.preCreate();
39
+ }
40
+
41
+ protected create(): void {
42
+
43
+ // remember, if you do not wish to use dynamic themes
44
+ // then use one time binding
45
+ this.render(<div
46
+ class="frame"
47
+ styleWidth={Bind.oneWay(() => this.templateParent.width || undefined)}
48
+ styleHeight={Bind.oneWay(() => this.templateParent.height || undefined)}
49
+ styleLeft={Bind.oneWay(() => this.templateParent.x >= 0 ? `${this.templateParent.x}px` : undefined)}
50
+ styleTop={Bind.oneWay(() => this.templateParent.y >= 0 ? `${this.templateParent.y}px` : undefined)}
51
+ styleMarginTop={Bind.oneWay(() => this.templateParent.x >= 0 ? "0" : undefined)}
52
+ styleMarginLeft={Bind.oneWay(() => this.templateParent.x >= 0 ? "0" : undefined)}
53
+ styleMarginRight={Bind.oneWay(() => this.templateParent.x >= 0 ? "0" : undefined)}
54
+ styleMarginBottom={Bind.oneWay(() => this.templateParent.x >= 0 ? "0" : undefined)}>
55
+ <div
56
+ class="title-presenter"
57
+ presenter={Bind.presenter("titlePresenter")}/>
58
+ <div
59
+ class="content-presenter"
60
+ presenter={Bind.presenter("contentPresenter")}/>
61
+ <div
62
+ class="command-bar-presenter"
63
+ presenter={Bind.presenter("commandPresenter")}/>
64
+ </div>);
65
+ // this.bind(this.element, "styleClass", [["templateParent", "controlStyle", "frame"]]);
66
+ // this.bind(this.element, "styleWidth", [["templateParent", "width"]], false, (v) => v || undefined);
67
+ // this.bind(this.element, "styleHeight", [["templateParent", "height"]], false, (v) => v || undefined);
68
+ // this.bind(this.element, "styleLeft", [["templateParent", "x"]],
69
+ // false, (v) => v >= 0 ? v + "px" : undefined);
70
+ // this.bind(this.element, "styleTop", [["templateParent", "y"]],
71
+ // false, (v) => v >= 0 ? v + "px" : undefined);
72
+ // this.bind(this.element, "styleMarginTop", [["templateParent", "x"]], false, (v) => v >= 0 ? "0" : undefined);
73
+ // this.bind(this.element, "styleMarginLeft", [["templateParent", "x"]],
74
+ // false, (v) => v >= 0 ? "0" : undefined);
75
+ // this.bind(this.element, "styleMarginRight", [["templateParent", "x"]],
76
+ // false, (v) => v >= 0 ? "0" : undefined);
77
+ // this.bind(this.element, "styleMarginBottom", [["templateParent", "x"]],
78
+ // false, (v) => v >= 0 ? "0" : undefined);
79
+ // // add title host
80
+ // const titlePresenter = document.createElement("div");
81
+ // this.bind(titlePresenter, "styleClass", [["templateParent", "controlStyle", "titlePresenter"]]);
82
+ // // titleHost.classList.add(style.titleHost.className);
83
+ // this.titlePresenter = titlePresenter;
84
+ // this.element.appendChild(titlePresenter);
85
+
86
+ // // add content presenter
87
+ // const cp = document.createElement("div");
88
+ // this.bind(cp, "styleClass", [["templateParent", "controlStyle", "content"]]);
89
+ // // cp.classList.add(style.content.className);
90
+ // this.contentPresenter = cp;
91
+ // this.element.appendChild(cp);
92
+
93
+ // // create command presenter
94
+ // const cdp = document.createElement("div");
95
+ // // cdp.classList.add(style.commandBar.className);
96
+ // this.bind(cdp, "styleClass", [["templateParent", "controlStyle", "commandBar"]]);
97
+ // this.commandPresenter = cdp;
98
+ // this.element.appendChild(cdp);
99
+
100
+ }
101
+
102
+ }
103
+
104
+ class AtomWindowTitleTemplate extends AtomControl {
105
+
106
+ public get templateParent(): AtomWindow {
107
+ return getTemplateParent(this.element) as AtomWindow;
108
+ }
109
+
110
+ protected create(): void {
111
+
112
+ this.render(<div
113
+ class="title-host">
114
+ <span
115
+ class="title"
116
+ text={Bind.oneWay(() => this.templateParent.title)}
117
+ />
118
+ <button
119
+ class="close-button"
120
+ eventClick={Bind.event(() => this.templateParent.close())}
121
+ />
122
+ </div>);
123
+
124
+ // this.bind(this.element, "styleClass", [["templateParent", "controlStyle", "titleHost"]]);
125
+
126
+ // // add title
127
+
128
+ // const title = document.createElement("span");
129
+ // this.bind(title, "styleClass", [["templateParent", "controlStyle", "title"]]);
130
+ // // title.classList.add(style.title.className);
131
+ // this.bind(title, "text", [["templateParent", "title"]], false);
132
+
133
+ // // add close button
134
+ // const closeButton = document.createElement("button");
135
+ // this.bind(closeButton, "styleClass", [["templateParent", "controlStyle", "closeButton"]]);
136
+ // // closeButton.textContent = "x";
137
+
138
+ // this.bindEvent(closeButton, "click", (e) => {
139
+ // const w = getTemplateParent(this.element) as AtomWindow;
140
+ // w.close();
141
+ // });
142
+
143
+ // // append title host > title
144
+
145
+ // this.append(title);
146
+ // this.append(closeButton);
147
+ }
148
+ }
149
+
150
+ export class AtomWindow extends AtomControl {
151
+
152
+ public static windowTemplate = XNode.prepare("windowTemplate", true, true);
153
+
154
+ public static commandTemplate = XNode.prepare("commandTemplate", true, true);
155
+
156
+ public static titleTemplate = XNode.prepare("titleTemplate", true, true);
157
+
158
+ public static frameTemplate = XNode.prepare("frameTemplate", true, true);
159
+
160
+ public get templateParent() {
161
+ return getTemplateParent(this.element);
162
+ }
163
+
164
+ public title: string = "";
165
+
166
+ public width: string = "";
167
+
168
+ public height: string = "";
169
+
170
+ public x: number = -1;
171
+
172
+ public y: number = -1;
173
+
174
+ public windowTemplate: IClassOf<AtomControl>;
175
+
176
+ public commandTemplate: IClassOf<AtomControl>;
177
+
178
+ public titleTemplate: IClassOf<AtomControl> = AtomWindowTitleTemplate;
179
+
180
+ public frameTemplate: IClassOf<AtomWindowFrameTemplate> = AtomWindowFrameTemplate;
181
+
182
+ private isReady: boolean = false;
183
+
184
+ public onPropertyChanged(name: string): void {
185
+ switch (name) {
186
+ case "windowTemplate":
187
+ case "commandTemplate":
188
+ case "frameTemplate":
189
+ this.invalidate();
190
+ break;
191
+ }
192
+ }
193
+
194
+ public close(): void {
195
+
196
+ const vm = this.viewModel as AtomWindowViewModel;
197
+ if (vm.cancel) {
198
+ this.app.runAsync(() => vm.cancel());
199
+ return;
200
+ }
201
+
202
+ const message = `atom-window-cancel:${(this as any).id}`;
203
+ const device = this.app.resolve(App);
204
+ device.broadcast(message, "cancelled");
205
+ }
206
+
207
+ public onUpdateUI(): void {
208
+ if (!(this.windowTemplate && this.frameTemplate)) {
209
+ return;
210
+ }
211
+
212
+ if (this.isReady) {
213
+ return;
214
+ }
215
+
216
+ this.bind(this.element, "title", [["viewModel", "title"]]);
217
+
218
+ // let us create frame first...
219
+ const frame = new (this.frameTemplate)(this.app);
220
+ const fe = frame.element;
221
+
222
+ // setup drag and drop for the frame...
223
+ const titleContent = new (this.titleTemplate)(this.app);
224
+ (titleContent.element)._templateParent = this;
225
+ frame.titlePresenter.appendChild(titleContent.element);
226
+
227
+ this.setupDragging(frame.titlePresenter);
228
+
229
+ this.element.classList.add("frame-host");
230
+
231
+ fe._logicalParent = this.element;
232
+ fe._templateParent = this;
233
+
234
+ if (!frame.contentPresenter) {
235
+ throw new Error("ContentPresenter must be set inside frameTemplate before creating window");
236
+ }
237
+
238
+ const content = new (this.windowTemplate)(this.app);
239
+ (content.element)._templateParent = this;
240
+ this.setElementClass(content.element, { content: 1 });
241
+ frame.contentPresenter.appendChild(content.element);
242
+
243
+ if (this.commandTemplate) {
244
+ if (!frame.commandPresenter) {
245
+ throw new Error("CommandPresenter must be set inside frameTemplate" +
246
+ "before creating window if command template is present");
247
+ }
248
+ const command = new (this.commandTemplate)(this.app);
249
+ (command.element)._templateParent = this;
250
+ this.setElementClass(command.element, { "command-bar": 1 });
251
+ frame.commandPresenter.appendChild(command.element);
252
+ }
253
+ this.append(frame);
254
+
255
+ // lets center frame...
256
+ setTimeout(() => {
257
+ this.centerFrame(frame.element);
258
+ }, 100);
259
+ this.isReady = true;
260
+ }
261
+
262
+ protected preCreate() {
263
+ this.defaultControlStyle = AtomWindowStyle;
264
+ this.title = null;
265
+ this.width = "";
266
+ this.height = "";
267
+ this.x = -1;
268
+ this.y = -1;
269
+ this.windowTemplate = null;
270
+ this.commandTemplate = null;
271
+ this.titleTemplate = AtomWindowTitleTemplate;
272
+ this.frameTemplate = AtomWindowFrameTemplate;
273
+ super.preCreate();
274
+ this.render(<div
275
+ styleClass={Bind.oneTime(() => this.controlStyle.name)}
276
+ ></div>);
277
+ }
278
+
279
+ private centerFrame(e: HTMLElement): void {
280
+ /// window is destroyed probably..
281
+ if (!this.element) {
282
+ return;
283
+ }
284
+ const parent = this.element.parentElement;
285
+ if (parent as any === window || parent as any === document.body) {
286
+ return;
287
+ }
288
+ if (parent.offsetWidth <= 0 || parent.offsetHeight <= 0) {
289
+ setTimeout(() => {
290
+ this.centerFrame(e);
291
+ }, 100);
292
+ return;
293
+ }
294
+
295
+ if (e.offsetWidth <= 0 || e.offsetHeight <= 0) {
296
+ setTimeout(() => {
297
+ this.centerFrame(e);
298
+ }, 100);
299
+ return;
300
+ }
301
+
302
+ const x = (parent.offsetWidth - e.offsetWidth) / 2;
303
+ const y = (parent.offsetHeight - e.offsetHeight) / 2;
304
+ this.x = x;
305
+ this.y = y;
306
+ e.style.opacity = "1";
307
+ this.element.style.removeProperty("opacity");
308
+ }
309
+
310
+ private setupDragging(tp: HTMLElement): void {
311
+ this.bindEvent(tp, "mousedown", (startEvent: MouseEvent) => {
312
+ startEvent.preventDefault();
313
+ const disposables: IDisposable[] = [];
314
+ // const offset = AtomUI.screenOffset(tp);
315
+ const offset = { x: tp.parentElement.offsetLeft, y: tp.parentElement.offsetTop };
316
+ const rect: IRect = { x: startEvent.clientX, y: startEvent.clientY };
317
+ const cursor = tp.style.cursor;
318
+ tp.style.cursor = "move";
319
+ disposables.push(this.bindEvent(document.body, "mousemove", (moveEvent: MouseEvent) => {
320
+ const { clientX, clientY } = moveEvent;
321
+ const dx = clientX - rect.x;
322
+ const dy = clientY - rect.y;
323
+
324
+ offset.x += dx;
325
+ offset.y += dy;
326
+
327
+ this.x = offset.x;
328
+ this.y = offset.y;
329
+
330
+ rect.x = clientX;
331
+ rect.y = clientY;
332
+ }));
333
+ disposables.push(this.bindEvent(document.body, "mouseup", (endEvent: MouseEvent) => {
334
+ tp.style.cursor = cursor;
335
+ for (const iterator of disposables) {
336
+ iterator.dispose();
337
+ }
338
+ }));
339
+ });
340
+ }
341
+
342
+ }