amis 1.6.0 → 1.6.1-beta.0
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/lib/RootRenderer.d.ts +2 -0
- package/lib/RootRenderer.js +19 -1
- package/lib/RootRenderer.js.map +2 -2
- package/lib/SchemaRenderer.js +52 -1
- package/lib/SchemaRenderer.js.map +2 -2
- package/lib/Scoped.d.ts +2 -0
- package/lib/Scoped.js +27 -1
- package/lib/Scoped.js.map +2 -2
- package/lib/actions/Action.d.ts +33 -0
- package/lib/actions/Action.js +100 -0
- package/lib/actions/Action.js.map +13 -0
- package/lib/actions/AjaxAction.d.ts +14 -0
- package/lib/actions/AjaxAction.js +68 -0
- package/lib/actions/AjaxAction.js.map +13 -0
- package/lib/actions/BreakAction.d.ts +12 -0
- package/lib/actions/BreakAction.js +28 -0
- package/lib/actions/BreakAction.js.map +13 -0
- package/lib/actions/BroadcastAction.d.ts +12 -0
- package/lib/actions/BroadcastAction.js +40 -0
- package/lib/actions/BroadcastAction.js.map +13 -0
- package/lib/actions/CmptAction.d.ts +12 -0
- package/lib/actions/CmptAction.js +40 -0
- package/lib/actions/CmptAction.js.map +13 -0
- package/lib/actions/ContinueAction.d.ts +12 -0
- package/lib/actions/ContinueAction.js +28 -0
- package/lib/actions/ContinueAction.js.map +13 -0
- package/lib/actions/CopyAction.d.ts +12 -0
- package/lib/actions/CopyAction.js +35 -0
- package/lib/actions/CopyAction.js.map +13 -0
- package/lib/actions/CustomAction.d.ts +12 -0
- package/lib/actions/CustomAction.js +43 -0
- package/lib/actions/CustomAction.js.map +13 -0
- package/lib/actions/DialogAction.d.ts +12 -0
- package/lib/actions/DialogAction.js +31 -0
- package/lib/actions/DialogAction.js.map +13 -0
- package/lib/actions/DrawerAction.d.ts +12 -0
- package/lib/actions/DrawerAction.js +31 -0
- package/lib/actions/DrawerAction.js.map +13 -0
- package/lib/actions/EmailAction.d.ts +12 -0
- package/lib/actions/EmailAction.js +37 -0
- package/lib/actions/EmailAction.js.map +13 -0
- package/lib/actions/LoopAction.d.ts +12 -0
- package/lib/actions/LoopAction.js +93 -0
- package/lib/actions/LoopAction.js.map +13 -0
- package/lib/actions/OpenPageAction.d.ts +12 -0
- package/lib/actions/OpenPageAction.js +33 -0
- package/lib/actions/OpenPageAction.js.map +13 -0
- package/lib/actions/ParallelAction.d.ts +5 -0
- package/lib/actions/ParallelAction.js +33 -0
- package/lib/actions/ParallelAction.js.map +13 -0
- package/lib/actions/SwitchAction.d.ts +8 -0
- package/lib/actions/SwitchAction.js +45 -0
- package/lib/actions/SwitchAction.js.map +13 -0
- package/lib/actions/index.d.ts +18 -0
- package/lib/actions/index.js +22 -0
- package/lib/actions/index.js.map +13 -0
- package/lib/components/AnchorNav.d.ts +20 -20
- package/lib/components/Button.d.ts +20 -20
- package/lib/components/CalendarMobile.d.ts +112 -86
- package/lib/components/CalendarMobile.js +85 -31
- package/lib/components/CalendarMobile.js.map +2 -2
- package/lib/components/Collapse.d.ts +20 -20
- package/lib/components/DatePicker.js +9 -3
- package/lib/components/DatePicker.js.map +2 -2
- package/lib/components/DateRangePicker.js +1 -0
- package/lib/components/DateRangePicker.js.map +2 -2
- package/lib/components/InputBox.d.ts +21 -21
- package/lib/components/ListGroup.d.ts +21 -21
- package/lib/components/ListMenu.d.ts +84 -84
- package/lib/components/MonthRangePicker.js +2 -1
- package/lib/components/MonthRangePicker.js.map +2 -2
- package/lib/components/Radios.d.ts +21 -21
- package/lib/components/Rating.d.ts +21 -21
- package/lib/components/ResultBox.d.ts +84 -84
- package/lib/components/Select.d.ts +238 -238
- package/lib/components/Select.js +4 -3
- package/lib/components/Select.js.map +2 -2
- package/lib/components/Timeline.js +1 -1
- package/lib/components/Timeline.js.map +2 -2
- package/lib/components/TimelineItem.d.ts +3 -2
- package/lib/components/TimelineItem.js +8 -9
- package/lib/components/TimelineItem.js.map +2 -2
- package/lib/components/Tree.d.ts +84 -84
- package/lib/components/formula/plugin.js +0 -1
- package/lib/components/formula/plugin.js.map +2 -2
- package/lib/env.d.ts +4 -0
- package/lib/env.js.map +2 -2
- package/lib/factory.d.ts +2 -1
- package/lib/factory.js +78 -0
- package/lib/factory.js.map +2 -2
- package/lib/helper.css.map +1 -1
- package/lib/index.d.ts +2 -0
- package/lib/index.js +3 -1
- package/lib/index.js.map +2 -2
- package/lib/renderers/Action.d.ts +1 -1
- package/lib/renderers/Action.js +26 -10
- package/lib/renderers/Action.js.map +2 -2
- package/lib/renderers/Custom.d.ts +1 -1
- package/lib/renderers/Custom.js +1 -1
- package/lib/renderers/Custom.js.map +1 -1
- package/lib/renderers/Form/DiffEditor.d.ts +6 -0
- package/lib/renderers/Form/Editor.d.ts +6 -0
- package/lib/renderers/Form/Options.js +9 -7
- package/lib/renderers/Form/Options.js.map +2 -2
- package/lib/renderers/Form/Select.js +3 -3
- package/lib/renderers/Form/Select.js.map +2 -2
- package/lib/renderers/Form/index.js +8 -1
- package/lib/renderers/Form/index.js.map +2 -2
- package/lib/renderers/Link.d.ts +1 -1
- package/lib/renderers/Link.js +27 -6
- package/lib/renderers/Link.js.map +2 -2
- package/lib/renderers/Nav.d.ts +21 -21
- package/lib/renderers/Remark.d.ts +1 -1
- package/lib/store/formItem.js +1 -1
- package/lib/store/formItem.js.map +2 -2
- package/lib/themes/ang-ie11.css +180 -1
- package/lib/themes/ang.css +180 -1
- package/lib/themes/ang.css.map +1 -1
- package/lib/themes/antd-ie11.css +184 -2
- package/lib/themes/antd.css +184 -2
- package/lib/themes/antd.css.map +1 -1
- package/lib/themes/cxd-ie11.css +182 -8
- package/lib/themes/cxd.css +182 -8
- package/lib/themes/cxd.css.map +1 -1
- package/lib/themes/dark-ie11.css +182 -1
- package/lib/themes/dark.css +182 -1
- package/lib/themes/dark.css.map +1 -1
- package/lib/themes/default.css +182 -8
- package/lib/themes/default.css.map +1 -1
- package/lib/utils/api.js +14 -3
- package/lib/utils/api.js.map +2 -2
- package/lib/utils/debug.d.ts +26 -0
- package/lib/utils/debug.js +351 -0
- package/lib/utils/debug.js.map +13 -0
- package/lib/utils/renderer-event.d.ts +38 -0
- package/lib/utils/renderer-event.js +28 -0
- package/lib/utils/renderer-event.js.map +13 -0
- package/package.json +1 -1
- package/scss/_properties.scss +2 -0
- package/scss/_variables.scss +1 -0
- package/scss/components/_calendar.scss +4 -0
- package/scss/components/_debug.scss +167 -0
- package/scss/components/_popup.scss +1 -1
- package/scss/components/form/_date-range.scss +33 -0
- package/scss/components/form/_form.scss +2 -0
- package/scss/themes/_antd-variables.scss +4 -1
- package/scss/themes/_common.scss +2 -0
- package/scss/themes/_cxd-variables.scss +2 -0
- package/scss/themes/_dark-variables.scss +3 -0
- package/scss/themes/cxd.scss +0 -7
- package/sdk/ang-ie11.css +211 -1
- package/sdk/ang.css +213 -1
- package/sdk/antd-ie11.css +213 -2
- package/sdk/antd.css +217 -2
- package/sdk/charts.js +16 -16
- package/sdk/codemirror.js +7 -7
- package/sdk/color-picker.js +65 -65
- package/sdk/cropperjs.js +2 -2
- package/sdk/cxd-ie11.css +211 -8
- package/sdk/cxd.css +215 -8
- package/sdk/dark-ie11.css +211 -1
- package/sdk/dark.css +215 -1
- package/sdk/exceljs.js +1 -1
- package/sdk/helper.css.map +1 -1
- package/sdk/markdown.js +69 -69
- package/sdk/papaparse.js +1 -1
- package/sdk/renderers/Form/CityDB.js +1 -1
- package/sdk/rest.js +18 -18
- package/sdk/rich-text.js +62 -62
- package/sdk/sdk-ie11.css +211 -8
- package/sdk/sdk.css +215 -8
- package/sdk/sdk.js +1293 -1257
- package/sdk/thirds/hls.js/hls.js +1 -1
- package/sdk/thirds/mpegts.js/mpegts.js +1 -1
- package/sdk/tinymce.js +57 -57
- package/src/RootRenderer.tsx +27 -1
- package/src/SchemaRenderer.tsx +70 -4
- package/src/Scoped.tsx +46 -4
- package/src/actions/Action.ts +138 -0
- package/src/actions/AjaxAction.ts +58 -0
- package/src/actions/BreakAction.ts +27 -0
- package/src/actions/BroadcastAction.ts +41 -0
- package/src/actions/CmptAction.ts +36 -0
- package/src/actions/ContinueAction.ts +27 -0
- package/src/actions/CopyAction.ts +41 -0
- package/src/actions/CustomAction.ts +46 -0
- package/src/actions/DialogAction.ts +28 -0
- package/src/actions/DrawerAction.ts +28 -0
- package/src/actions/EmailAction.ts +38 -0
- package/src/actions/LoopAction.ts +77 -0
- package/src/actions/OpenPageAction.ts +39 -0
- package/src/actions/ParallelAction.ts +26 -0
- package/src/actions/SwitchAction.ts +35 -0
- package/src/actions/index.ts +20 -0
- package/src/components/CalendarMobile.tsx +127 -32
- package/src/components/DatePicker.tsx +32 -2
- package/src/components/DateRangePicker.tsx +2 -1
- package/src/components/MonthRangePicker.tsx +2 -1
- package/src/components/Select.tsx +4 -3
- package/src/components/Timeline.tsx +9 -4
- package/src/components/TimelineItem.tsx +62 -29
- package/src/components/formula/plugin.ts +0 -2
- package/src/env.tsx +22 -0
- package/src/factory.tsx +87 -1
- package/src/index.tsx +4 -0
- package/src/renderers/Action.tsx +11 -2
- package/src/renderers/Custom.tsx +1 -1
- package/src/renderers/Form/Options.tsx +15 -7
- package/src/renderers/Form/Select.tsx +7 -3
- package/src/renderers/Form/index.tsx +7 -1
- package/src/renderers/Link.tsx +18 -3
- package/src/store/formItem.ts +1 -1
- package/src/utils/api.ts +15 -2
- package/src/utils/debug.tsx +438 -0
- package/src/utils/renderer-event.ts +75 -0
@@ -0,0 +1,438 @@
|
|
1
|
+
/**
|
2
|
+
* amis 运行时调试功能,为了避免循环引用,这个组件不要依赖 amis 里的组件
|
3
|
+
*/
|
4
|
+
|
5
|
+
import React, {Component, useEffect, useRef, useState} from 'react';
|
6
|
+
import cx from 'classnames';
|
7
|
+
import {findDOMNode, render} from 'react-dom';
|
8
|
+
import JsonView from 'react-json-view';
|
9
|
+
import {autorun, observable} from 'mobx';
|
10
|
+
import {observer} from 'mobx-react';
|
11
|
+
import {uuidv4} from './helper';
|
12
|
+
import position from './position';
|
13
|
+
|
14
|
+
class Log {
|
15
|
+
@observable cat = '';
|
16
|
+
@observable level = '';
|
17
|
+
@observable msg = '';
|
18
|
+
@observable ext? = '';
|
19
|
+
}
|
20
|
+
|
21
|
+
class AMISDebugStore {
|
22
|
+
/**
|
23
|
+
* 当前 tab
|
24
|
+
*/
|
25
|
+
@observable tab: 'log' | 'inspect' = 'log';
|
26
|
+
|
27
|
+
/**
|
28
|
+
* 显示位置,默认在右边
|
29
|
+
*/
|
30
|
+
@observable position: 'left' | 'right' = 'right';
|
31
|
+
|
32
|
+
/**
|
33
|
+
* 组件日志
|
34
|
+
*/
|
35
|
+
@observable logs: Log[] = [];
|
36
|
+
|
37
|
+
/**
|
38
|
+
* Debug 面板是否展开
|
39
|
+
*/
|
40
|
+
@observable isExpanded = false;
|
41
|
+
|
42
|
+
/**
|
43
|
+
* 是否是 inspect 模式,在这个模式下可以查看数据域
|
44
|
+
*/
|
45
|
+
@observable inspectMode = false;
|
46
|
+
|
47
|
+
/**
|
48
|
+
* 当前高亮的组件节点 id
|
49
|
+
*/
|
50
|
+
@observable hoverId: string;
|
51
|
+
|
52
|
+
/**
|
53
|
+
* 当前选中的组件节点 id
|
54
|
+
*/
|
55
|
+
@observable activeId: string;
|
56
|
+
}
|
57
|
+
|
58
|
+
const store = new AMISDebugStore();
|
59
|
+
|
60
|
+
interface ComponentInspect {
|
61
|
+
name: string;
|
62
|
+
component: any;
|
63
|
+
}
|
64
|
+
|
65
|
+
// 存储组件信息用于 debug
|
66
|
+
const ComponentInfo = {} as {[propName: string]: ComponentInspect};
|
67
|
+
|
68
|
+
const LogView = observer(({store}: {store: AMISDebugStore}) => {
|
69
|
+
const logs = store.logs;
|
70
|
+
return (
|
71
|
+
<>
|
72
|
+
{logs.map((log, index) => {
|
73
|
+
return (
|
74
|
+
<div className="AMISDebug-logLine" key={`log-${index}`}>
|
75
|
+
<div className="AMISDebug-logLineMsg">
|
76
|
+
[{log.cat}] {log.msg}
|
77
|
+
</div>
|
78
|
+
{log.ext ? (
|
79
|
+
<JsonView
|
80
|
+
name={null}
|
81
|
+
theme="monokai"
|
82
|
+
src={JSON.parse(log.ext)}
|
83
|
+
collapsed={true}
|
84
|
+
enableClipboard={false}
|
85
|
+
displayDataTypes={false}
|
86
|
+
iconStyle="square"
|
87
|
+
/>
|
88
|
+
) : null}
|
89
|
+
</div>
|
90
|
+
);
|
91
|
+
})}
|
92
|
+
</>
|
93
|
+
);
|
94
|
+
});
|
95
|
+
|
96
|
+
const AMISDebug = observer(({store}: {store: AMISDebugStore}) => {
|
97
|
+
const activeId = store.activeId;
|
98
|
+
const activeComponentInspect = ComponentInfo[activeId];
|
99
|
+
|
100
|
+
// 收集数据域里的数据
|
101
|
+
let start = activeComponentInspect?.component?.props?.data || {};
|
102
|
+
const stacks = [start];
|
103
|
+
|
104
|
+
while (Object.getPrototypeOf(start) !== Object.prototype) {
|
105
|
+
const superData = Object.getPrototypeOf(start);
|
106
|
+
if (Object.prototype.toString.call(superData) !== '[object Object]') {
|
107
|
+
break;
|
108
|
+
}
|
109
|
+
stacks.push(superData);
|
110
|
+
start = superData;
|
111
|
+
}
|
112
|
+
|
113
|
+
const stackDataView = [];
|
114
|
+
if (Object.keys(stacks[0]).length || stacks.length > 1) {
|
115
|
+
let level = 0;
|
116
|
+
for (const stack of stacks) {
|
117
|
+
stackDataView.push(
|
118
|
+
<div key={`data-${level}`}>
|
119
|
+
<h3>Data Level-{level}</h3>
|
120
|
+
<JsonView
|
121
|
+
key={`dataview-${stack}`}
|
122
|
+
name={null}
|
123
|
+
theme="monokai"
|
124
|
+
src={stack}
|
125
|
+
collapsed={level === 0 ? false : true}
|
126
|
+
enableClipboard={false}
|
127
|
+
displayDataTypes={false}
|
128
|
+
iconStyle="square"
|
129
|
+
/>
|
130
|
+
</div>
|
131
|
+
);
|
132
|
+
level += 1;
|
133
|
+
}
|
134
|
+
}
|
135
|
+
|
136
|
+
const panelRef = useRef(null);
|
137
|
+
|
138
|
+
const [isResizing, setResizing] = useState(false);
|
139
|
+
|
140
|
+
const [startX, setStartX] = useState(0);
|
141
|
+
|
142
|
+
const [panelWidth, setPanelWidth] = useState(0);
|
143
|
+
|
144
|
+
useEffect(() => {
|
145
|
+
const handleMouseUp = () => {
|
146
|
+
setResizing(false);
|
147
|
+
};
|
148
|
+
const handleMouseMove = (e: MouseEvent) => {
|
149
|
+
if (!isResizing) {
|
150
|
+
return;
|
151
|
+
}
|
152
|
+
const xOffset =
|
153
|
+
store.position === 'right' ? e.clientX - startX : startX - e.clientX;
|
154
|
+
const panel = panelRef.current! as HTMLElement;
|
155
|
+
const targetWidth = Math.max(200, panelWidth - xOffset);
|
156
|
+
panel.style.width = targetWidth + 'px';
|
157
|
+
if (e.stopPropagation) e.stopPropagation();
|
158
|
+
if (e.preventDefault) e.preventDefault();
|
159
|
+
e.cancelBubble = true;
|
160
|
+
return false;
|
161
|
+
};
|
162
|
+
if (isResizing) {
|
163
|
+
document.addEventListener('mousemove', handleMouseMove);
|
164
|
+
document.addEventListener('mouseup', handleMouseUp);
|
165
|
+
}
|
166
|
+
|
167
|
+
return () => {
|
168
|
+
if (isResizing) {
|
169
|
+
document.removeEventListener('mousemove', handleMouseMove);
|
170
|
+
document.removeEventListener('mouseup', handleMouseUp);
|
171
|
+
}
|
172
|
+
};
|
173
|
+
}, [isResizing]);
|
174
|
+
|
175
|
+
return (
|
176
|
+
<div
|
177
|
+
className={cx('AMISDebug', {
|
178
|
+
'is-expanded': store.isExpanded,
|
179
|
+
'is-left': store.position === 'left'
|
180
|
+
})}
|
181
|
+
ref={panelRef}
|
182
|
+
>
|
183
|
+
<div
|
184
|
+
className="AMISDebug-toggle"
|
185
|
+
onClick={() => {
|
186
|
+
store.isExpanded = true;
|
187
|
+
}}
|
188
|
+
>
|
189
|
+
{store.isExpanded ? (
|
190
|
+
<i className="fas fa-times"></i>
|
191
|
+
) : (
|
192
|
+
<i className="fas fa-bug"></i>
|
193
|
+
)}
|
194
|
+
</div>
|
195
|
+
<div className={cx('AMISDebug-content')}>
|
196
|
+
<div
|
197
|
+
className="AMISDebug-close"
|
198
|
+
title="Close"
|
199
|
+
onClick={() => {
|
200
|
+
store.isExpanded = false;
|
201
|
+
}}
|
202
|
+
>
|
203
|
+
<i className="fas fa-times" />
|
204
|
+
</div>
|
205
|
+
<div
|
206
|
+
className="AMISDebug-resize"
|
207
|
+
onMouseDown={event => {
|
208
|
+
setStartX(event.clientX);
|
209
|
+
setPanelWidth(
|
210
|
+
parseInt(
|
211
|
+
getComputedStyle(panelRef.current!).getPropertyValue('width'),
|
212
|
+
10
|
213
|
+
)
|
214
|
+
);
|
215
|
+
setResizing(true);
|
216
|
+
}}
|
217
|
+
></div>
|
218
|
+
<div className="AMISDebug-tab">
|
219
|
+
<button
|
220
|
+
className={cx({active: store.tab === 'log'})}
|
221
|
+
onClick={() => {
|
222
|
+
store.tab = 'log';
|
223
|
+
}}
|
224
|
+
>
|
225
|
+
Log
|
226
|
+
</button>
|
227
|
+
<button
|
228
|
+
className={cx({active: store.tab === 'inspect'})}
|
229
|
+
onClick={() => {
|
230
|
+
store.tab = 'inspect';
|
231
|
+
}}
|
232
|
+
>
|
233
|
+
Inspect
|
234
|
+
</button>
|
235
|
+
</div>
|
236
|
+
<div className="AMISDebug-changePosition">
|
237
|
+
{store.position === 'right' ? (
|
238
|
+
<i
|
239
|
+
className="fas fa-chevron-left"
|
240
|
+
title="move to left"
|
241
|
+
onClick={() => {
|
242
|
+
store.position = 'left';
|
243
|
+
}}
|
244
|
+
/>
|
245
|
+
) : (
|
246
|
+
<i
|
247
|
+
className="fas fa-chevron-right"
|
248
|
+
title="move to right"
|
249
|
+
onClick={() => {
|
250
|
+
store.position = 'right';
|
251
|
+
}}
|
252
|
+
/>
|
253
|
+
)}
|
254
|
+
</div>
|
255
|
+
{store.tab === 'log' ? (
|
256
|
+
<div className="AMISDebug-log">
|
257
|
+
<button
|
258
|
+
onClick={() => {
|
259
|
+
store.logs = [];
|
260
|
+
}}
|
261
|
+
>
|
262
|
+
Clear Log
|
263
|
+
</button>
|
264
|
+
<LogView store={store} />
|
265
|
+
</div>
|
266
|
+
) : null}
|
267
|
+
{store.tab === 'inspect' ? (
|
268
|
+
<div className="AMISDebug-inspect">
|
269
|
+
{activeId ? (
|
270
|
+
<>
|
271
|
+
<h3>
|
272
|
+
Component:{' '}
|
273
|
+
<span className="primary">{activeComponentInspect.name}</span>
|
274
|
+
</h3>
|
275
|
+
{stackDataView}
|
276
|
+
</>
|
277
|
+
) : (
|
278
|
+
'Click component to display inspect'
|
279
|
+
)}
|
280
|
+
</div>
|
281
|
+
) : null}
|
282
|
+
</div>
|
283
|
+
</div>
|
284
|
+
);
|
285
|
+
});
|
286
|
+
|
287
|
+
export let enableAMISDebug = false;
|
288
|
+
|
289
|
+
// 开启 debug 有两种方法,一个是设置 enableAMISDebug 全局变量,另一个是通过 amisDebug=1 query
|
290
|
+
if (
|
291
|
+
(window as any).enableAMISDebug ||
|
292
|
+
location.search.indexOf('amisDebug=1') !== -1
|
293
|
+
) {
|
294
|
+
enableAMISDebug = true;
|
295
|
+
// 页面只有一个
|
296
|
+
if (!(window as any).amisDebugElement) {
|
297
|
+
const amisDebugElement = document.createElement('div');
|
298
|
+
document.body.appendChild(amisDebugElement);
|
299
|
+
const element = <AMISDebug store={store} />;
|
300
|
+
render(element, amisDebugElement);
|
301
|
+
(window as any).amisDebugElement = true;
|
302
|
+
}
|
303
|
+
}
|
304
|
+
|
305
|
+
/**
|
306
|
+
* 鼠标移动到某个组件的效果
|
307
|
+
*/
|
308
|
+
function handleMouseMove(e: MouseEvent) {
|
309
|
+
if (!store.isExpanded) {
|
310
|
+
return;
|
311
|
+
}
|
312
|
+
const dom = e.target as HTMLElement;
|
313
|
+
const target = dom.closest(`[data-debug-id]`);
|
314
|
+
if (target) {
|
315
|
+
store.hoverId = target.getAttribute('data-debug-id')!;
|
316
|
+
}
|
317
|
+
}
|
318
|
+
|
319
|
+
/**
|
320
|
+
* 点选某个组件
|
321
|
+
*/
|
322
|
+
function handleMouseclick(e: MouseEvent) {
|
323
|
+
if (!store.isExpanded) {
|
324
|
+
return;
|
325
|
+
}
|
326
|
+
const dom = e.target as HTMLElement;
|
327
|
+
const target = dom.closest(`[data-debug-id]`);
|
328
|
+
if (target) {
|
329
|
+
store.activeId = target.getAttribute('data-debug-id')!;
|
330
|
+
store.tab = 'inspect';
|
331
|
+
}
|
332
|
+
}
|
333
|
+
|
334
|
+
// hover 及点击后的高亮
|
335
|
+
const amisHoverBox = document.createElement('div');
|
336
|
+
amisHoverBox.className = 'AMISDebug-hoverBox';
|
337
|
+
const amisActiveBox = document.createElement('div');
|
338
|
+
amisActiveBox.className = 'AMISDebug-activeBox';
|
339
|
+
|
340
|
+
autorun(() => {
|
341
|
+
const hoverId = store.hoverId;
|
342
|
+
const hoverElement = document.querySelector(
|
343
|
+
`[data-debug-id="${hoverId}"]`
|
344
|
+
) as HTMLElement;
|
345
|
+
if (hoverElement) {
|
346
|
+
const offset = position(hoverElement, document.body);
|
347
|
+
amisHoverBox.style.top = `${offset.top}px`;
|
348
|
+
amisHoverBox.style.left = `${offset.left}px`;
|
349
|
+
amisHoverBox.style.width = `${offset.width}px`;
|
350
|
+
amisHoverBox.style.height = `${offset.height}px`;
|
351
|
+
}
|
352
|
+
});
|
353
|
+
|
354
|
+
autorun(() => {
|
355
|
+
const activeId = store.activeId;
|
356
|
+
const activeElement = document.querySelector(
|
357
|
+
`[data-debug-id="${activeId}"]`
|
358
|
+
) as HTMLElement;
|
359
|
+
if (activeElement) {
|
360
|
+
const offset = position(activeElement, document.body);
|
361
|
+
amisActiveBox.style.top = `${offset.top}px`;
|
362
|
+
amisActiveBox.style.left = `${offset.left}px`;
|
363
|
+
amisActiveBox.style.width = `${offset.width}px`;
|
364
|
+
amisActiveBox.style.height = `${offset.height}px`;
|
365
|
+
}
|
366
|
+
});
|
367
|
+
|
368
|
+
if (enableAMISDebug) {
|
369
|
+
document.body.appendChild(amisHoverBox);
|
370
|
+
document.body.appendChild(amisActiveBox);
|
371
|
+
document.addEventListener('mousemove', handleMouseMove);
|
372
|
+
document.addEventListener('click', handleMouseclick);
|
373
|
+
}
|
374
|
+
|
375
|
+
interface DebugWrapperProps {
|
376
|
+
renderer: any;
|
377
|
+
}
|
378
|
+
|
379
|
+
export class DebugWrapper extends Component<DebugWrapperProps> {
|
380
|
+
componentDidMount() {
|
381
|
+
if (!enableAMISDebug) {
|
382
|
+
return;
|
383
|
+
}
|
384
|
+
const root = findDOMNode(this) as HTMLElement;
|
385
|
+
if (!root) {
|
386
|
+
return;
|
387
|
+
}
|
388
|
+
const {renderer} = this.props;
|
389
|
+
const debugId = uuidv4();
|
390
|
+
root.setAttribute('data-debug-id', debugId);
|
391
|
+
ComponentInfo[debugId] = {
|
392
|
+
name: renderer.name,
|
393
|
+
component: this.props.children
|
394
|
+
};
|
395
|
+
}
|
396
|
+
|
397
|
+
render() {
|
398
|
+
return this.props.children;
|
399
|
+
}
|
400
|
+
}
|
401
|
+
|
402
|
+
type Category = 'api' | 'event';
|
403
|
+
|
404
|
+
/**
|
405
|
+
* 一般调试日志
|
406
|
+
* @param msg 简单消息
|
407
|
+
* @param ext 扩展信息
|
408
|
+
*/
|
409
|
+
export function debug(cat: Category, msg: string, ext?: object) {
|
410
|
+
if (!enableAMISDebug) {
|
411
|
+
return;
|
412
|
+
}
|
413
|
+
const log = {
|
414
|
+
cat,
|
415
|
+
level: 'debug',
|
416
|
+
msg: msg,
|
417
|
+
ext: JSON.stringify(ext)
|
418
|
+
};
|
419
|
+
console.debug(log);
|
420
|
+
store.logs.push(log);
|
421
|
+
}
|
422
|
+
|
423
|
+
/**
|
424
|
+
* 警告日志
|
425
|
+
* @param msg 简单消息
|
426
|
+
* @param ext 扩展信息
|
427
|
+
*/
|
428
|
+
export function warning(cat: Category, msg: string, ext?: object) {
|
429
|
+
if (!enableAMISDebug) {
|
430
|
+
return;
|
431
|
+
}
|
432
|
+
store.logs.push({
|
433
|
+
cat,
|
434
|
+
level: 'warn',
|
435
|
+
msg: msg,
|
436
|
+
ext: JSON.stringify(ext)
|
437
|
+
});
|
438
|
+
}
|
@@ -0,0 +1,75 @@
|
|
1
|
+
import {ListenerAction, ListenerContext} from '../actions/Action';
|
2
|
+
|
3
|
+
// 事件监听器
|
4
|
+
export interface EventListeners {
|
5
|
+
[propName: string]: {
|
6
|
+
weight?: number; // 权重
|
7
|
+
actions: ListenerAction[]; // 执行的动作集
|
8
|
+
};
|
9
|
+
}
|
10
|
+
|
11
|
+
// 事件动作属性
|
12
|
+
export interface OnEventProps {
|
13
|
+
onEvent?: {
|
14
|
+
[propName: string]: {
|
15
|
+
weight?: number; // 权重
|
16
|
+
actions: ListenerAction[]; // 执行的动作集
|
17
|
+
};
|
18
|
+
};
|
19
|
+
}
|
20
|
+
|
21
|
+
// 渲染器事件监听器
|
22
|
+
export interface RendererEventListener {
|
23
|
+
renderer: ListenerContext;
|
24
|
+
type: string;
|
25
|
+
weight: number;
|
26
|
+
actions: ListenerAction[];
|
27
|
+
}
|
28
|
+
|
29
|
+
// 将事件上下文转成事件对象
|
30
|
+
export type RendererEvent<T, P = any> = {
|
31
|
+
context: T;
|
32
|
+
type: string;
|
33
|
+
prevented?: boolean; // 阻止原有动作执行
|
34
|
+
stoped?: boolean; // 阻止后续动作执行
|
35
|
+
data?: P;
|
36
|
+
preventDefault: () => void;
|
37
|
+
stopPropagation: () => void;
|
38
|
+
setData: (data: P) => void;
|
39
|
+
};
|
40
|
+
|
41
|
+
export interface RendererEventContext {
|
42
|
+
data?: any;
|
43
|
+
[propName: string]: any;
|
44
|
+
}
|
45
|
+
|
46
|
+
// 创建渲染器事件对象
|
47
|
+
export function createRendererEvent<T extends RendererEventContext>(
|
48
|
+
type: string,
|
49
|
+
context: T
|
50
|
+
): RendererEvent<T> {
|
51
|
+
const rendererEvent = {
|
52
|
+
context,
|
53
|
+
type,
|
54
|
+
prevented: false,
|
55
|
+
stoped: false,
|
56
|
+
preventDefault() {
|
57
|
+
rendererEvent.prevented = true;
|
58
|
+
},
|
59
|
+
|
60
|
+
stopPropagation() {
|
61
|
+
rendererEvent.stoped = true;
|
62
|
+
},
|
63
|
+
|
64
|
+
get data() {
|
65
|
+
return rendererEvent.context.data;
|
66
|
+
},
|
67
|
+
|
68
|
+
setData(data: any) {
|
69
|
+
rendererEvent.context.data = data;
|
70
|
+
}
|
71
|
+
};
|
72
|
+
return rendererEvent;
|
73
|
+
}
|
74
|
+
|
75
|
+
export default {};
|