@tmagic/stage 1.0.0-beta.10 → 1.0.0-beta.13
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/README.md +1 -0
- package/dist/tmagic-stage.es.js +177 -184
- package/dist/tmagic-stage.es.js.map +1 -1
- package/dist/tmagic-stage.umd.js +178 -186
- package/dist/tmagic-stage.umd.js.map +1 -1
- package/dist/types/src/StageCore.d.ts +4 -4
- package/dist/types/src/StageMask.d.ts +16 -0
- package/package.json +5 -4
- package/src/StageCore.ts +8 -8
- package/src/StageDragResize.ts +3 -2
- package/src/StageHighlight.ts +1 -0
- package/src/StageMask.ts +57 -25
- package/tsconfig.json +0 -9
- package/vite.config.ts +0 -27
package/src/StageMask.ts
CHANGED
|
@@ -25,7 +25,7 @@ import type { StageMaskConfig } from './types';
|
|
|
25
25
|
import { createDiv, getScrollParent, isFixedParent } from './util';
|
|
26
26
|
|
|
27
27
|
const wrapperClassName = 'editor-mask-wrapper';
|
|
28
|
-
const throttleTime =
|
|
28
|
+
const throttleTime = 100;
|
|
29
29
|
|
|
30
30
|
const hideScrollbar = () => {
|
|
31
31
|
const style = globalThis.document.createElement('style');
|
|
@@ -81,6 +81,8 @@ export default class StageMask extends Rule {
|
|
|
81
81
|
public height = 0;
|
|
82
82
|
public wrapperHeight = 0;
|
|
83
83
|
public wrapperWidth = 0;
|
|
84
|
+
public maxScrollTop = 0;
|
|
85
|
+
public maxScrollLeft = 0;
|
|
84
86
|
|
|
85
87
|
private mode: Mode = Mode.ABSOLUTE;
|
|
86
88
|
private pageResizeObserver: ResizeObserver | null = null;
|
|
@@ -104,6 +106,7 @@ export default class StageMask extends Rule {
|
|
|
104
106
|
this.wrapper.appendChild(this.content);
|
|
105
107
|
this.content.addEventListener('wheel', this.mouseWheelHandler);
|
|
106
108
|
this.content.addEventListener('mousemove', this.highlightHandler);
|
|
109
|
+
this.content.addEventListener('mouseleave', this.mouseLeaveHandler);
|
|
107
110
|
}
|
|
108
111
|
|
|
109
112
|
public setMode(mode: Mode) {
|
|
@@ -136,6 +139,10 @@ export default class StageMask extends Rule {
|
|
|
136
139
|
const { clientHeight, clientWidth } = entry.target;
|
|
137
140
|
this.setHeight(clientHeight);
|
|
138
141
|
this.setWidth(clientWidth);
|
|
142
|
+
|
|
143
|
+
this.fixScrollValue();
|
|
144
|
+
this.scroll();
|
|
145
|
+
this.core.dr.updateMoveable();
|
|
139
146
|
});
|
|
140
147
|
|
|
141
148
|
this.pageResizeObserver.observe(page);
|
|
@@ -145,6 +152,8 @@ export default class StageMask extends Rule {
|
|
|
145
152
|
const { clientHeight, clientWidth } = entry.target;
|
|
146
153
|
this.wrapperHeight = clientHeight;
|
|
147
154
|
this.wrapperWidth = clientWidth;
|
|
155
|
+
this.setMaxScrollLeft();
|
|
156
|
+
this.setMaxScrollTop();
|
|
148
157
|
});
|
|
149
158
|
this.wrapperResizeObserver.observe(this.wrapper);
|
|
150
159
|
}
|
|
@@ -173,12 +182,21 @@ export default class StageMask extends Rule {
|
|
|
173
182
|
this.pageScrollParent = null;
|
|
174
183
|
this.pageResizeObserver?.disconnect();
|
|
175
184
|
this.wrapperResizeObserver?.disconnect();
|
|
185
|
+
|
|
186
|
+
this.content.removeEventListener('mouseleave', this.mouseLeaveHandler);
|
|
176
187
|
super.destroy();
|
|
177
188
|
}
|
|
178
189
|
|
|
179
190
|
private scroll() {
|
|
180
191
|
let { scrollLeft, scrollTop } = this;
|
|
181
192
|
|
|
193
|
+
if (this.pageScrollParent) {
|
|
194
|
+
this.pageScrollParent.scrollTo({
|
|
195
|
+
top: scrollTop,
|
|
196
|
+
left: scrollLeft,
|
|
197
|
+
});
|
|
198
|
+
}
|
|
199
|
+
|
|
182
200
|
if (this.mode === Mode.FIXED) {
|
|
183
201
|
scrollLeft = 0;
|
|
184
202
|
scrollTop = 0;
|
|
@@ -198,6 +216,7 @@ export default class StageMask extends Rule {
|
|
|
198
216
|
*/
|
|
199
217
|
private setHeight(height: number): void {
|
|
200
218
|
this.height = height;
|
|
219
|
+
this.setMaxScrollTop();
|
|
201
220
|
this.content.style.height = `${height}px`;
|
|
202
221
|
}
|
|
203
222
|
|
|
@@ -207,9 +226,35 @@ export default class StageMask extends Rule {
|
|
|
207
226
|
*/
|
|
208
227
|
private setWidth(width: number): void {
|
|
209
228
|
this.width = width;
|
|
229
|
+
this.setMaxScrollLeft();
|
|
210
230
|
this.content.style.width = `${width}px`;
|
|
211
231
|
}
|
|
212
232
|
|
|
233
|
+
/**
|
|
234
|
+
* 计算并设置最大滚动宽度
|
|
235
|
+
*/
|
|
236
|
+
private setMaxScrollLeft(): void {
|
|
237
|
+
this.maxScrollLeft = this.width - this.wrapperWidth;
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
/**
|
|
241
|
+
* 计算并设置最大滚动高度
|
|
242
|
+
*/
|
|
243
|
+
private setMaxScrollTop(): void {
|
|
244
|
+
this.maxScrollTop = this.height - this.wrapperHeight;
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
/**
|
|
248
|
+
* 修复滚动距离
|
|
249
|
+
* 由于滚动容器变化等因素,会导致当前滚动的距离不正确
|
|
250
|
+
*/
|
|
251
|
+
private fixScrollValue(): void {
|
|
252
|
+
if (this.scrollTop < 0) this.scrollTop = 0;
|
|
253
|
+
if (this.scrollLeft < 0) this.scrollLeft = 0;
|
|
254
|
+
if (this.maxScrollTop < this.scrollTop) this.scrollTop = this.maxScrollTop;
|
|
255
|
+
if (this.maxScrollLeft < this.scrollLeft) this.scrollLeft = this.maxScrollLeft;
|
|
256
|
+
}
|
|
257
|
+
|
|
213
258
|
/**
|
|
214
259
|
* 点击事件处理函数
|
|
215
260
|
* @param event 事件对象
|
|
@@ -246,39 +291,26 @@ export default class StageMask extends Rule {
|
|
|
246
291
|
if (!this.page) throw new Error('page 未初始化');
|
|
247
292
|
|
|
248
293
|
const { deltaY, deltaX } = event;
|
|
249
|
-
const { height, wrapperHeight, width, wrapperWidth } = this;
|
|
250
294
|
|
|
251
|
-
|
|
252
|
-
|
|
295
|
+
if (this.page.clientHeight < this.wrapperHeight && deltaY) return;
|
|
296
|
+
if (this.page.clientWidth < this.wrapperWidth && deltaX) return;
|
|
253
297
|
|
|
254
|
-
if (maxScrollTop > 0) {
|
|
255
|
-
|
|
256
|
-
this.scrollTop = this.scrollTop + Math.min(maxScrollTop - this.scrollTop, deltaY);
|
|
257
|
-
} else {
|
|
258
|
-
this.scrollTop = Math.max(this.scrollTop + deltaY, 0);
|
|
259
|
-
}
|
|
298
|
+
if (this.maxScrollTop > 0) {
|
|
299
|
+
this.scrollTop = this.scrollTop + deltaY;
|
|
260
300
|
}
|
|
261
301
|
|
|
262
|
-
if (
|
|
263
|
-
|
|
264
|
-
this.scrollLeft = this.scrollLeft + Math.min(maxScrollLeft - this.scrollLeft, deltaX);
|
|
265
|
-
} else {
|
|
266
|
-
this.scrollLeft = Math.max(this.scrollLeft + deltaX, 0);
|
|
267
|
-
}
|
|
302
|
+
if (this.maxScrollLeft > 0) {
|
|
303
|
+
this.scrollLeft = this.scrollLeft + deltaX;
|
|
268
304
|
}
|
|
269
305
|
|
|
270
|
-
|
|
271
|
-
this.scrollTo(this.scrollLeft, this.scrollTop);
|
|
272
|
-
}
|
|
306
|
+
this.fixScrollValue();
|
|
273
307
|
|
|
274
|
-
if (this.pageScrollParent) {
|
|
275
|
-
this.pageScrollParent.scrollTo({
|
|
276
|
-
top: this.scrollTop,
|
|
277
|
-
left: this.scrollLeft,
|
|
278
|
-
});
|
|
279
|
-
}
|
|
280
308
|
this.scroll();
|
|
281
309
|
|
|
282
310
|
this.emit('scroll', event);
|
|
283
311
|
};
|
|
312
|
+
|
|
313
|
+
private mouseLeaveHandler = () => {
|
|
314
|
+
setTimeout(() => this.emit('clearHighlight'), throttleTime);
|
|
315
|
+
};
|
|
284
316
|
}
|
package/tsconfig.json
DELETED
package/vite.config.ts
DELETED
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
* Tencent is pleased to support the open source community by making TMagicEditor available.
|
|
3
|
-
*
|
|
4
|
-
* Copyright (C) 2021 THL A29 Limited, a Tencent company. All rights reserved.
|
|
5
|
-
*
|
|
6
|
-
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
7
|
-
* you may not use this file except in compliance with the License.
|
|
8
|
-
* You may obtain a copy of the License at
|
|
9
|
-
*
|
|
10
|
-
* http://www.apache.org/licenses/LICENSE-2.0
|
|
11
|
-
*
|
|
12
|
-
* Unless required by applicable law or agreed to in writing, software
|
|
13
|
-
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
14
|
-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
15
|
-
* See the License for the specific language governing permissions and
|
|
16
|
-
* limitations under the License.
|
|
17
|
-
*/
|
|
18
|
-
|
|
19
|
-
import { defineConfig } from 'vite';
|
|
20
|
-
|
|
21
|
-
import { getBaseConfig } from '../vite-config';
|
|
22
|
-
|
|
23
|
-
import pkg from './package.json';
|
|
24
|
-
|
|
25
|
-
const deps = Object.keys(pkg.dependencies);
|
|
26
|
-
|
|
27
|
-
export default defineConfig(getBaseConfig(deps, 'TMagicStage'));
|