@tmagic/stage 1.0.0-beta.7 → 1.0.0-rc.1

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/src/types.ts CHANGED
@@ -1,10 +1,31 @@
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
+
1
19
  import { MoveableOptions } from 'react-moveable/declaration/types';
2
20
 
3
21
  import { Id, MApp, MNode } from '@tmagic/schema';
4
22
 
23
+ import { GuidesType } from './const';
5
24
  import StageCore from './StageCore';
25
+ import StageDragResize from './StageDragResize';
26
+ import StageMask from './StageMask';
6
27
 
7
- export type CanSelect = (el: HTMLElement, stop: () => boolean) => boolean | Promise<boolean>;
28
+ export type CanSelect = (el: HTMLElement, event: MouseEvent, stop: () => boolean) => boolean | Promise<boolean>;
8
29
 
9
30
  export type StageCoreConfig = {
10
31
  /** 需要对齐的dom节点的CSS选择器字符串 */
@@ -35,29 +56,15 @@ export type Rect = {
35
56
  width: number;
36
57
  height: number;
37
58
  } & Offset;
38
-
39
59
  export interface Offset {
40
60
  left: number;
41
61
  top: number;
42
62
  }
43
63
 
44
- /*
45
- * Tencent is pleased to support the open source community by making TMagicEditor available.
46
- *
47
- * Copyright (C) 2021 THL A29 Limited, a Tencent company. All rights reserved.
48
- *
49
- * Licensed under the Apache License, Version 2.0 (the "License");
50
- * you may not use this file except in compliance with the License.
51
- * You may obtain a copy of the License at
52
- *
53
- * http://www.apache.org/licenses/LICENSE-2.0
54
- *
55
- * Unless required by applicable law or agreed to in writing, software
56
- * distributed under the License is distributed on an "AS IS" BASIS,
57
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
58
- * See the License for the specific language governing permissions and
59
- * limitations under the License.
60
- */
64
+ export interface GuidesEventData {
65
+ type: GuidesType;
66
+ guides: number[];
67
+ }
61
68
 
62
69
  export interface UpdateEventData {
63
70
  el: HTMLElement;
@@ -88,7 +95,7 @@ export interface RemoveData {
88
95
 
89
96
  export interface Runtime {
90
97
  beforeSelect?: (el: HTMLElement) => Promise<boolean> | boolean;
91
- getSnapElements?: (el: HTMLElement) => HTMLElement[];
98
+ getSnapElements?: (el?: HTMLElement) => HTMLElement[];
92
99
  updateRootConfig: (config: MApp) => void;
93
100
  updatePageId?: (id: Id) => void;
94
101
  select?: (id: Id) => Promise<HTMLElement> | HTMLElement;
@@ -109,13 +116,13 @@ export interface RuntimeWindow extends Window {
109
116
  magic: Magic;
110
117
  }
111
118
 
112
- export enum ZIndex {
113
- MASK = '99999',
114
- GHOST_EL = '99998',
119
+ export interface StageHighlightConfig {
120
+ core: StageCore;
121
+ container: HTMLElement;
115
122
  }
116
123
 
117
- export enum MouseButton {
118
- LEFT = 0,
119
- MIDDLE = 1,
120
- RIGHT = 2,
124
+ export interface TargetCalibrateConfig {
125
+ parent: HTMLElement;
126
+ mask: StageMask;
127
+ dr: StageDragResize;
121
128
  }
package/src/util.ts CHANGED
@@ -16,14 +16,9 @@
16
16
  * limitations under the License.
17
17
  */
18
18
 
19
+ import { Mode, SELECTED_CLASS } from './const';
19
20
  import type { Offset } from './types';
20
21
 
21
- export enum Mode {
22
- ABSOLUTE = 'absolute',
23
- FIXED = 'fixed',
24
- SORTABLE = 'sortable',
25
- }
26
-
27
22
  export const getOffset = (el: HTMLElement): Offset => {
28
23
  const { transform } = getComputedStyle(el);
29
24
  const { offsetParent } = el;
@@ -113,8 +108,63 @@ export const isFixed = (el?: HTMLElement): boolean => {
113
108
  return getComputedStyle(el).position === 'fixed';
114
109
  };
115
110
 
111
+ export const isFixedParent = (el: HTMLElement) => {
112
+ let fixed = false;
113
+ let dom = el;
114
+ while (dom) {
115
+ fixed = isFixed(dom);
116
+ if (fixed) {
117
+ break;
118
+ }
119
+ const { parentElement } = dom;
120
+ if (!parentElement || parentElement.tagName === 'BODY') {
121
+ break;
122
+ }
123
+ dom = parentElement;
124
+ }
125
+ return fixed;
126
+ };
127
+
116
128
  export const getMode = (el: HTMLElement): Mode => {
117
- if (isFixed(el)) return Mode.FIXED;
129
+ if (isFixedParent(el)) return Mode.FIXED;
118
130
  if (isStatic(el) || isRelative(el)) return Mode.SORTABLE;
119
131
  return Mode.ABSOLUTE;
120
132
  };
133
+
134
+ export const getScrollParent = (element: HTMLElement, includeHidden = false): HTMLElement | null => {
135
+ let style = getComputedStyle(element);
136
+ const overflowRegex = includeHidden ? /(auto|scroll|hidden)/ : /(auto|scroll)/;
137
+
138
+ if (isFixed(element)) return null;
139
+ for (let parent = element; parent.parentElement; ) {
140
+ parent = parent.parentElement;
141
+ style = getComputedStyle(parent);
142
+ if (isAbsolute(element) && isStatic(element)) {
143
+ continue;
144
+ }
145
+ if (overflowRegex.test(style.overflow + style.overflowY + style.overflowX)) return parent;
146
+ }
147
+
148
+ return null;
149
+ };
150
+
151
+ export const createDiv = ({ className, cssText }: { className: string; cssText: string }) => {
152
+ const el = globalThis.document.createElement('div');
153
+ el.className = className;
154
+ el.style.cssText = cssText;
155
+ return el;
156
+ };
157
+
158
+ export const removeSelectedClassName = (doc: Document) => {
159
+ const oldEl = doc.querySelector(`.${SELECTED_CLASS}`);
160
+
161
+ if (oldEl) {
162
+ oldEl.classList.remove(SELECTED_CLASS);
163
+ (oldEl.parentNode as HTMLDivElement)?.classList.remove(`${SELECTED_CLASS}-parent`);
164
+ }
165
+ };
166
+
167
+ export const addSelectedClassName = (el: Element) => {
168
+ el.classList.add(SELECTED_CLASS);
169
+ (el.parentNode as Element)?.classList.add(`${SELECTED_CLASS}-parent`);
170
+ };
package/tsconfig.json DELETED
@@ -1,9 +0,0 @@
1
- {
2
- "extends": "../../tsconfig.json",
3
- "compilerOptions": {
4
- "baseUrl": "../..",
5
- },
6
- "exclude": [
7
- "**/dist/**/*"
8
- ],
9
- }
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'));