vite-uni-dev-tool 0.0.12 → 0.0.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/dist/const.d.ts +133 -0
- package/dist/const.d.ts.map +1 -0
- package/dist/const.js +36 -0
- package/dist/core.d.ts +52 -0
- package/dist/core.d.ts.map +1 -0
- package/dist/core.js +80 -0
- package/dist/devConsole/index.d.ts +169 -0
- package/dist/devConsole/index.d.ts.map +1 -0
- package/dist/devConsole/index.js +270 -0
- package/dist/devEvent/index.d.ts +286 -0
- package/dist/devEvent/index.d.ts.map +1 -0
- package/dist/devEvent/index.js +435 -0
- package/dist/devEventBus/index.d.ts +42 -0
- package/dist/devEventBus/index.d.ts.map +1 -0
- package/dist/devEventBus/index.js +70 -0
- package/dist/devIntercept/index.d.ts +119 -0
- package/dist/devIntercept/index.d.ts.map +1 -0
- package/dist/devIntercept/index.js +582 -0
- package/dist/devRunJS/index.d.ts +67 -0
- package/dist/devRunJS/index.d.ts.map +1 -0
- package/dist/devStore/index.d.ts +178 -0
- package/dist/devStore/index.d.ts.map +1 -0
- package/dist/devStore/index.js +395 -0
- package/dist/devToolInfo/index.d.ts +17 -0
- package/dist/devToolInfo/index.d.ts.map +1 -0
- package/dist/devToolInfo/index.js +15 -0
- package/{dev → dist}/plugins/uniDevTool/uniDevTool.d.ts +7 -1
- package/dist/plugins/uniDevTool/uniDevTool.d.ts.map +1 -0
- package/dist/plugins/uniDevTool/uniDevTool.js +35 -0
- package/{dev → dist}/plugins/utils/index.d.ts +3 -0
- package/{dev → dist}/plugins/utils/index.d.ts.map +1 -1
- package/dist/plugins/utils/index.js +1 -0
- package/dist/type.d.ts +264 -0
- package/dist/type.d.ts.map +1 -0
- package/dist/utils/array.d.ts +2 -0
- package/dist/utils/array.d.ts.map +1 -0
- package/dist/utils/array.js +12 -0
- package/dist/utils/date.d.ts +19 -0
- package/dist/utils/date.d.ts.map +1 -0
- package/dist/utils/date.js +40 -0
- package/dist/utils/file.d.ts +11 -0
- package/dist/utils/file.d.ts.map +1 -0
- package/dist/utils/file.js +87 -0
- package/dist/utils/function.d.ts +28 -0
- package/dist/utils/function.d.ts.map +1 -0
- package/dist/utils/function.js +46 -0
- package/dist/utils/index.d.ts +11 -0
- package/dist/utils/index.d.ts.map +1 -0
- package/dist/utils/index.js +55 -0
- package/dist/utils/ip.d.ts +5 -0
- package/dist/utils/ip.d.ts.map +1 -0
- package/dist/utils/ip.js +21 -0
- package/dist/utils/language.d.ts +29 -0
- package/dist/utils/language.d.ts.map +1 -0
- package/dist/utils/language.js +50 -0
- package/dist/utils/object.d.ts +49 -0
- package/dist/utils/object.d.ts.map +1 -0
- package/dist/utils/object.js +118 -0
- package/dist/utils/page.d.ts +7 -0
- package/dist/utils/page.d.ts.map +1 -0
- package/dist/utils/page.js +7 -0
- package/dist/utils/platform.d.ts +4 -0
- package/dist/utils/platform.d.ts.map +1 -0
- package/dist/utils/platform.js +14 -0
- package/dist/utils/string.d.ts +45 -0
- package/dist/utils/string.d.ts.map +1 -0
- package/dist/utils/string.js +88 -0
- package/dist/utils/utils.d.ts +16 -0
- package/dist/utils/utils.d.ts.map +1 -0
- package/dist/v2/AutoSizer/utils.d.ts +5 -0
- package/dist/v2/AutoSizer/utils.d.ts.map +1 -0
- package/dist/v2/JsonPretty/hooks/useClipboard.d.ts +4 -0
- package/dist/v2/JsonPretty/hooks/useClipboard.d.ts.map +1 -0
- package/dist/v2/JsonPretty/hooks/useError.d.ts +8 -0
- package/dist/v2/JsonPretty/hooks/useError.d.ts.map +1 -0
- package/dist/v2/JsonPretty/type.d.ts +93 -0
- package/dist/v2/JsonPretty/type.d.ts.map +1 -0
- package/dist/v3/AutoSizer/utils.d.ts +5 -0
- package/dist/v3/AutoSizer/utils.d.ts.map +1 -0
- package/dist/v3/ConsoleList/staticTips.d.ts +13 -0
- package/dist/v3/ConsoleList/staticTips.d.ts.map +1 -0
- package/dist/v3/JsonPretty/hooks/useClipboard.d.ts +4 -0
- package/dist/v3/JsonPretty/hooks/useClipboard.d.ts.map +1 -0
- package/dist/v3/JsonPretty/hooks/useError.d.ts +8 -0
- package/dist/v3/JsonPretty/hooks/useError.d.ts.map +1 -0
- package/dist/v3/JsonPretty/type.d.ts +93 -0
- package/dist/v3/JsonPretty/type.d.ts.map +1 -0
- package/dist/v3/JsonPretty/utils/index.d.ts +10 -0
- package/dist/v3/JsonPretty/utils/index.d.ts.map +1 -0
- package/package.json +5 -5
- package/dev/components/AppInfo/index.vue +0 -36
- package/dev/components/AutoSizer/index.vue +0 -193
- package/dev/components/AutoSizer/index1.vue +0 -186
- package/dev/components/AutoSizer/utils.ts +0 -49
- package/dev/components/Button/index.vue +0 -34
- package/dev/components/CaptureScreen/index.vue +0 -62
- package/dev/components/Checkbox/index.vue +0 -40
- package/dev/components/CloseButton/index.vue +0 -26
- package/dev/components/Code/index.vue +0 -230
- package/dev/components/Connection/index.vue +0 -88
- package/dev/components/ConsoleList/Code.vue +0 -227
- package/dev/components/ConsoleList/ConsoleItem.vue +0 -207
- package/dev/components/ConsoleList/RunJSInput.vue +0 -237
- package/dev/components/ConsoleList/index.vue +0 -139
- package/dev/components/ConsoleList/staticTips.ts +0 -1145
- package/dev/components/DevTool/index.vue +0 -188
- package/dev/components/DevToolButton/index.vue +0 -210
- package/dev/components/DevToolTitle/index.vue +0 -21
- package/dev/components/DevToolWindow/index.vue +0 -1053
- package/dev/components/DeviceInfo/index.vue +0 -32
- package/dev/components/Empty/empty.png +0 -0
- package/dev/components/Empty/index.vue +0 -28
- package/dev/components/FilterInput/index.vue +0 -86
- package/dev/components/JsonPretty/components/Brackets/index.vue +0 -23
- package/dev/components/JsonPretty/components/Carets/index.vue +0 -59
- package/dev/components/JsonPretty/components/CheckController/index.vue +0 -125
- package/dev/components/JsonPretty/components/TreeNode/index.vue +0 -349
- package/dev/components/JsonPretty/hooks/useClipboard.ts +0 -21
- package/dev/components/JsonPretty/hooks/useError.ts +0 -21
- package/dev/components/JsonPretty/index.vue +0 -476
- package/dev/components/JsonPretty/type.ts +0 -125
- package/dev/components/JsonPretty/utils/index.ts +0 -172
- package/dev/components/NetworkList/NetworkDetail.vue +0 -194
- package/dev/components/NetworkList/NetworkItem.vue +0 -119
- package/dev/components/NetworkList/index.vue +0 -128
- package/dev/components/PiniaList/index.vue +0 -64
- package/dev/components/RouteList/index.vue +0 -121
- package/dev/components/RunJS/index.vue +0 -128
- package/dev/components/SettingList/index.vue +0 -222
- package/dev/components/SourceCode/index.vue +0 -231
- package/dev/components/StorageList/index.vue +0 -170
- package/dev/components/SystemInfo/index.vue +0 -34
- package/dev/components/Tabs/index.vue +0 -123
- package/dev/components/Tag/index.vue +0 -89
- package/dev/components/UniEvent/UniEventItem.vue +0 -126
- package/dev/components/UniEvent/index.vue +0 -98
- package/dev/components/UploadList/UploadDetail.vue +0 -204
- package/dev/components/UploadList/UploadItem.vue +0 -117
- package/dev/components/UploadList/index.vue +0 -117
- package/dev/components/VirtualList/index.vue +0 -112
- package/dev/components/VirtualListPro/AutoSize.vue +0 -43
- package/dev/components/VirtualListPro/index.vue +0 -238
- package/dev/components/VirtualListPro/readme.md +0 -40
- package/dev/components/VuexList/index.vue +0 -54
- package/dev/components/WebSocket/WebSocketItem.vue +0 -103
- package/dev/components/WebSocket/WebSocketList.vue +0 -173
- package/dev/components/WebSocket/index.vue +0 -124
- package/dev/components/WindowInfo/index.vue +0 -33
- package/dev/const.ts +0 -164
- package/dev/core.ts +0 -118
- package/dev/devConsole/index.ts +0 -350
- package/dev/devEvent/index.ts +0 -810
- package/dev/devEventBus/index.ts +0 -94
- package/dev/devIntercept/index.ts +0 -745
- package/dev/devRunJS/index.ts +0 -170
- package/dev/devStore/index.ts +0 -732
- package/dev/devToolInfo/index.ts +0 -26
- package/dev/plugins/uniDevTool/uniDevTool.d.ts.map +0 -1
- package/dev/plugins/uniDevTool/uniDevTool.js +0 -36
- package/dev/plugins/utils/index.js +0 -1
- package/dev/shims-uni.d.ts +0 -43
- package/dev/type.ts +0 -291
- package/dev/utils/array.ts +0 -15
- package/dev/utils/date.ts +0 -75
- package/dev/utils/file.ts +0 -121
- package/dev/utils/function.ts +0 -192
- package/dev/utils/index.d.ts +0 -6
- package/dev/utils/index.ts +0 -51
- package/dev/utils/ip.ts +0 -79
- package/dev/utils/language.ts +0 -77
- package/dev/utils/object.ts +0 -306
- package/dev/utils/page.ts +0 -13
- package/dev/utils/platform.ts +0 -14
- package/dev/utils/string.ts +0 -133
- package/dev/utils/utils.ts +0 -198
- /package/{dev → dist}/index.d.ts +0 -0
- /package/{dev → dist}/index.d.ts.map +0 -0
- /package/{dev → dist}/index.js +0 -0
- /package/{dev → dist}/plugins/uniGlobalComponents/uniGlobalComponents.d.ts +0 -0
- /package/{dev → dist}/plugins/uniGlobalComponents/uniGlobalComponents.d.ts.map +0 -0
- /package/{dev → dist}/plugins/uniGlobalComponents/uniGlobalComponents.js +0 -0
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
import { ref } from "vue";
|
|
2
|
-
|
|
3
|
-
export function useClipboard() {
|
|
4
|
-
const copied = ref(false);
|
|
5
|
-
|
|
6
|
-
const copy = async (source: string) => {
|
|
7
|
-
try {
|
|
8
|
-
await navigator.clipboard.writeText(source);
|
|
9
|
-
copied.value = true;
|
|
10
|
-
setTimeout(() => {
|
|
11
|
-
copied.value = false;
|
|
12
|
-
}, 300);
|
|
13
|
-
} catch (err) {
|
|
14
|
-
console.error("[json-pretty] Copy failed: ", err);
|
|
15
|
-
}
|
|
16
|
-
};
|
|
17
|
-
|
|
18
|
-
return {
|
|
19
|
-
copy
|
|
20
|
-
};
|
|
21
|
-
}
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
import { watchEffect } from "vue";
|
|
2
|
-
|
|
3
|
-
type UseErrorOptions = {
|
|
4
|
-
emitListener: boolean;
|
|
5
|
-
};
|
|
6
|
-
|
|
7
|
-
export function useError(message: string, { emitListener }: UseErrorOptions) {
|
|
8
|
-
const emit = () => {
|
|
9
|
-
throw new Error(`[VueJsonPretty] ${message}`);
|
|
10
|
-
};
|
|
11
|
-
|
|
12
|
-
watchEffect(() => {
|
|
13
|
-
if (emitListener) {
|
|
14
|
-
emit();
|
|
15
|
-
}
|
|
16
|
-
});
|
|
17
|
-
|
|
18
|
-
return {
|
|
19
|
-
emit
|
|
20
|
-
};
|
|
21
|
-
}
|
|
@@ -1,476 +0,0 @@
|
|
|
1
|
-
<template>
|
|
2
|
-
<view
|
|
3
|
-
:class="{
|
|
4
|
-
'json-pretty-tree': true,
|
|
5
|
-
'is-virtual': virtual,
|
|
6
|
-
dark: theme === 'dark',
|
|
7
|
-
}"
|
|
8
|
-
:style="
|
|
9
|
-
showLineNumber
|
|
10
|
-
? {
|
|
11
|
-
paddingLeft: `${
|
|
12
|
-
Number(originFlatData.length.toString().length) * 12
|
|
13
|
-
}px`,
|
|
14
|
-
...style,
|
|
15
|
-
}
|
|
16
|
-
: style
|
|
17
|
-
"
|
|
18
|
-
>
|
|
19
|
-
<VirtualListPro
|
|
20
|
-
v-if="autoVirtual"
|
|
21
|
-
:height="state.height"
|
|
22
|
-
:pageSize="pageSize"
|
|
23
|
-
:data="flatData"
|
|
24
|
-
scroll-with-animation
|
|
25
|
-
showBackTop
|
|
26
|
-
>
|
|
27
|
-
<template v-slot="{ list, start }">
|
|
28
|
-
<AutoSize
|
|
29
|
-
v-for="(item, index) in list"
|
|
30
|
-
:index="start + index"
|
|
31
|
-
:key="start + index"
|
|
32
|
-
>
|
|
33
|
-
<TreeNode
|
|
34
|
-
:data="data"
|
|
35
|
-
:rootPath="rootPath"
|
|
36
|
-
:indent="indent"
|
|
37
|
-
:node="item"
|
|
38
|
-
:collapsed="!!state.hiddenPaths[item.path]"
|
|
39
|
-
:theme="theme"
|
|
40
|
-
:showDoubleQuotes="showDoubleQuotes"
|
|
41
|
-
:showLength="showLength"
|
|
42
|
-
:checked="selectedPaths.includes(item.path)"
|
|
43
|
-
:selectableType="selectableType"
|
|
44
|
-
:showLine="showLine"
|
|
45
|
-
:showLineNumber="showLineNumber"
|
|
46
|
-
:showSelectController="showSelectController"
|
|
47
|
-
:selectOnClickNode="selectOnClickNode"
|
|
48
|
-
:nodeSelectable="nodeSelectable"
|
|
49
|
-
:highlightSelectedNode="highlightSelectedNode"
|
|
50
|
-
:editable="editable"
|
|
51
|
-
:editableTrigger="editableTrigger"
|
|
52
|
-
:showIcon="showIcon"
|
|
53
|
-
:showKeyValueSpace="showKeyValueSpace"
|
|
54
|
-
:showNodeActions="showNodeActions"
|
|
55
|
-
@nodeClick="handleNodeClick"
|
|
56
|
-
@nodeMouseover="handleNodeMouseover"
|
|
57
|
-
@bracketsClick="handleBracketsClick"
|
|
58
|
-
@iconClick="handleIconClick"
|
|
59
|
-
@selectedChange="handleSelectedChange"
|
|
60
|
-
@valueChange="handleValueChange"
|
|
61
|
-
:style="
|
|
62
|
-
itemHeight && itemHeight !== 20
|
|
63
|
-
? { lineHeight: `${itemHeight}px` }
|
|
64
|
-
: {}
|
|
65
|
-
"
|
|
66
|
-
/>
|
|
67
|
-
</AutoSize>
|
|
68
|
-
</template>
|
|
69
|
-
</VirtualListPro>
|
|
70
|
-
<template v-else>
|
|
71
|
-
<TreeNode
|
|
72
|
-
v-for="item in state?.visibleData"
|
|
73
|
-
:key="item.id"
|
|
74
|
-
:data="data"
|
|
75
|
-
:rootPath="rootPath"
|
|
76
|
-
:indent="indent"
|
|
77
|
-
:node="item"
|
|
78
|
-
:collapsed="!!state.hiddenPaths[item.path]"
|
|
79
|
-
:theme="theme"
|
|
80
|
-
:showDoubleQuotes="showDoubleQuotes"
|
|
81
|
-
:showLength="showLength"
|
|
82
|
-
:checked="selectedPaths.includes(item.path)"
|
|
83
|
-
:selectableType="selectableType"
|
|
84
|
-
:showLine="showLine"
|
|
85
|
-
:showLineNumber="showLineNumber"
|
|
86
|
-
:showSelectController="showSelectController"
|
|
87
|
-
:selectOnClickNode="selectOnClickNode"
|
|
88
|
-
:nodeSelectable="nodeSelectable"
|
|
89
|
-
:highlightSelectedNode="highlightSelectedNode"
|
|
90
|
-
:editable="editable"
|
|
91
|
-
:editableTrigger="editableTrigger"
|
|
92
|
-
:showIcon="showIcon"
|
|
93
|
-
:showKeyValueSpace="showKeyValueSpace"
|
|
94
|
-
:showNodeActions="showNodeActions"
|
|
95
|
-
@nodeClick="handleNodeClick"
|
|
96
|
-
@nodeMouseover="handleNodeMouseover"
|
|
97
|
-
@bracketsClick="handleBracketsClick"
|
|
98
|
-
@iconClick="handleIconClick"
|
|
99
|
-
@selectedChange="handleSelectedChange"
|
|
100
|
-
@valueChange="handleValueChange"
|
|
101
|
-
:style="
|
|
102
|
-
itemHeight && itemHeight !== 20
|
|
103
|
-
? { lineHeight: `${itemHeight}px` }
|
|
104
|
-
: {}
|
|
105
|
-
"
|
|
106
|
-
/>
|
|
107
|
-
</template>
|
|
108
|
-
</view>
|
|
109
|
-
</template>
|
|
110
|
-
|
|
111
|
-
<script setup lang="ts">
|
|
112
|
-
import {
|
|
113
|
-
reactive,
|
|
114
|
-
computed,
|
|
115
|
-
watchEffect,
|
|
116
|
-
watch,
|
|
117
|
-
defineEmits,
|
|
118
|
-
onMounted,
|
|
119
|
-
onUpdated,
|
|
120
|
-
onUnmounted,
|
|
121
|
-
} from 'vue';
|
|
122
|
-
import TreeNode from './components/TreeNode/index.vue';
|
|
123
|
-
|
|
124
|
-
import VirtualListPro from '../VirtualListPro/index.vue';
|
|
125
|
-
import AutoSize from '../VirtualListPro/AutoSize.vue';
|
|
126
|
-
|
|
127
|
-
import { emitError, jsonFlatten, cloneDeep, isFunction } from './utils';
|
|
128
|
-
|
|
129
|
-
import type { NodeDataType, ScrollEvent, Tree } from './type';
|
|
130
|
-
import { setValueByPath } from '../../utils';
|
|
131
|
-
|
|
132
|
-
// 定义 emits 类型
|
|
133
|
-
type Emits = {
|
|
134
|
-
(event: 'nodeClick', node: NodeDataType): void;
|
|
135
|
-
(event: 'nodeMouseover', node: NodeDataType): void;
|
|
136
|
-
(event: 'bracketsClick', collapsed: boolean, node: NodeDataType): void;
|
|
137
|
-
(event: 'iconClick', collapsed: boolean, node: NodeDataType): void;
|
|
138
|
-
(
|
|
139
|
-
event: 'selectedChange',
|
|
140
|
-
newVal: string | string[],
|
|
141
|
-
oldVal: string | string[],
|
|
142
|
-
): void;
|
|
143
|
-
(event: 'update:selectedValue', value: string | string[]): void;
|
|
144
|
-
(event: 'update:data', data: any): void;
|
|
145
|
-
};
|
|
146
|
-
|
|
147
|
-
// 定义 props 和 emits
|
|
148
|
-
const props = withDefaults(defineProps<Tree>(), {
|
|
149
|
-
fontSize: '12px',
|
|
150
|
-
itemHeight: 20,
|
|
151
|
-
height: 400,
|
|
152
|
-
deep: Infinity,
|
|
153
|
-
collapsedNodeLength: Infinity,
|
|
154
|
-
collapsedOnClickBrackets: true,
|
|
155
|
-
pathCollapsible: () => false,
|
|
156
|
-
nodeSelectable: () => false,
|
|
157
|
-
|
|
158
|
-
rootPath: 'root',
|
|
159
|
-
indent: 2,
|
|
160
|
-
showDoubleQuotes: true,
|
|
161
|
-
showLine: true,
|
|
162
|
-
selectOnClickNode: true,
|
|
163
|
-
highlightSelectedNode: true,
|
|
164
|
-
theme: 'light',
|
|
165
|
-
showKeyValueSpace: true,
|
|
166
|
-
editableTrigger: 'click',
|
|
167
|
-
});
|
|
168
|
-
const emits = defineEmits<Emits>();
|
|
169
|
-
|
|
170
|
-
const originFlatData = computed(() => jsonFlatten(props.data, props.rootPath));
|
|
171
|
-
|
|
172
|
-
const pageSize = computed(() => {
|
|
173
|
-
return Math.ceil(props.height / props.itemHeight) + 5;
|
|
174
|
-
});
|
|
175
|
-
|
|
176
|
-
// 初始化折叠路径
|
|
177
|
-
const initHiddenPaths = (
|
|
178
|
-
deep: number,
|
|
179
|
-
collapsedNodeLength: number,
|
|
180
|
-
): Record<string, 1> => {
|
|
181
|
-
return originFlatData.value.reduce((acc, item) => {
|
|
182
|
-
const doCollapse = item.level >= deep || item.length >= collapsedNodeLength;
|
|
183
|
-
const pathComparison =
|
|
184
|
-
isFunction(props?.pathCollapsible) &&
|
|
185
|
-
props?.pathCollapsible?.(item as NodeDataType);
|
|
186
|
-
if (
|
|
187
|
-
(item.type === 'objectStart' || item.type === 'arrayStart') &&
|
|
188
|
-
(doCollapse || pathComparison)
|
|
189
|
-
) {
|
|
190
|
-
return {
|
|
191
|
-
...acc,
|
|
192
|
-
[item.path]: 1,
|
|
193
|
-
};
|
|
194
|
-
}
|
|
195
|
-
return acc;
|
|
196
|
-
}, {});
|
|
197
|
-
};
|
|
198
|
-
|
|
199
|
-
// 响应式状态
|
|
200
|
-
interface State {
|
|
201
|
-
translateY: number;
|
|
202
|
-
visibleData: NodeDataType[] | null;
|
|
203
|
-
hiddenPaths: Record<string, 1>;
|
|
204
|
-
height: number;
|
|
205
|
-
}
|
|
206
|
-
|
|
207
|
-
const state = reactive<State>({
|
|
208
|
-
translateY: 0,
|
|
209
|
-
visibleData: [],
|
|
210
|
-
hiddenPaths: initHiddenPaths(props.deep, props.collapsedNodeLength),
|
|
211
|
-
height: props.height ?? 400,
|
|
212
|
-
});
|
|
213
|
-
|
|
214
|
-
// 计算属性
|
|
215
|
-
const flatData = computed(() => {
|
|
216
|
-
let startHiddenItem: null | NodeDataType = null;
|
|
217
|
-
const data: NodeDataType[] = [];
|
|
218
|
-
const length = originFlatData.value.length;
|
|
219
|
-
for (let i = 0; i < length; i++) {
|
|
220
|
-
const cur = originFlatData.value[i];
|
|
221
|
-
const item: NodeDataType = {
|
|
222
|
-
...cur,
|
|
223
|
-
id: i,
|
|
224
|
-
};
|
|
225
|
-
const isHidden = state.hiddenPaths[item.path];
|
|
226
|
-
if (startHiddenItem && startHiddenItem.path === item.path) {
|
|
227
|
-
const isObject = startHiddenItem.type === 'objectStart';
|
|
228
|
-
const mergeItem: NodeDataType = {
|
|
229
|
-
...item,
|
|
230
|
-
...startHiddenItem,
|
|
231
|
-
showComma: item.showComma,
|
|
232
|
-
content: isObject ? '{...}' : '[...]',
|
|
233
|
-
type: isObject ? 'objectCollapsed' : 'arrayCollapsed',
|
|
234
|
-
};
|
|
235
|
-
startHiddenItem = null;
|
|
236
|
-
data.push(mergeItem);
|
|
237
|
-
} else if (isHidden && !startHiddenItem) {
|
|
238
|
-
startHiddenItem = item;
|
|
239
|
-
continue;
|
|
240
|
-
} else {
|
|
241
|
-
if (startHiddenItem) continue;
|
|
242
|
-
else data.push(item);
|
|
243
|
-
}
|
|
244
|
-
}
|
|
245
|
-
return data;
|
|
246
|
-
});
|
|
247
|
-
|
|
248
|
-
const selectedPaths = computed(() => {
|
|
249
|
-
const value = props.selectedValue;
|
|
250
|
-
if (value && props.selectableType === 'multiple' && Array.isArray(value)) {
|
|
251
|
-
return value;
|
|
252
|
-
}
|
|
253
|
-
return [value];
|
|
254
|
-
});
|
|
255
|
-
|
|
256
|
-
const propsErrorMessage = computed(() => {
|
|
257
|
-
const error =
|
|
258
|
-
props.selectableType &&
|
|
259
|
-
!props.selectOnClickNode &&
|
|
260
|
-
!props.showSelectController;
|
|
261
|
-
return error
|
|
262
|
-
? 'When selectableType is not null, selectOnClickNode and showSelectController cannot be false at the same time, because this will cause the selection to fail.'
|
|
263
|
-
: '';
|
|
264
|
-
});
|
|
265
|
-
|
|
266
|
-
const autoVirtual = computed(() => {
|
|
267
|
-
if (props.virtual) return true;
|
|
268
|
-
if (typeof props.autoVirtualRow === 'number') {
|
|
269
|
-
if (flatData.value.length > props.autoVirtualRow) {
|
|
270
|
-
return true;
|
|
271
|
-
}
|
|
272
|
-
}
|
|
273
|
-
return false;
|
|
274
|
-
});
|
|
275
|
-
|
|
276
|
-
// 更新可见数据
|
|
277
|
-
// 优化 虚拟列表,每项高度自适应
|
|
278
|
-
const updateVisibleData = (scrollTop: number = 0) => {
|
|
279
|
-
const flatDataValue = flatData.value ?? [];
|
|
280
|
-
if (autoVirtual.value) {
|
|
281
|
-
const visibleCount = props.height / props.itemHeight;
|
|
282
|
-
const scrollCount = Math.floor(scrollTop / props.itemHeight);
|
|
283
|
-
let start =
|
|
284
|
-
scrollCount < 0
|
|
285
|
-
? 0
|
|
286
|
-
: scrollCount + visibleCount > flatDataValue.length
|
|
287
|
-
? flatDataValue.length - visibleCount
|
|
288
|
-
: scrollCount;
|
|
289
|
-
if (start < 0) {
|
|
290
|
-
start = 0;
|
|
291
|
-
}
|
|
292
|
-
const end = start + visibleCount;
|
|
293
|
-
state.translateY = start * props.itemHeight;
|
|
294
|
-
state.visibleData = flatDataValue.filter(
|
|
295
|
-
(item, index) => index >= start && index < end,
|
|
296
|
-
);
|
|
297
|
-
} else {
|
|
298
|
-
state.visibleData = flatDataValue;
|
|
299
|
-
}
|
|
300
|
-
};
|
|
301
|
-
|
|
302
|
-
// 事件处理
|
|
303
|
-
const handleTreeScroll = (e: ScrollEvent) => {
|
|
304
|
-
updateVisibleData(e?.detail?.scrollTop ?? 0);
|
|
305
|
-
};
|
|
306
|
-
|
|
307
|
-
const handleSelectedChange = ({ path }: NodeDataType) => {
|
|
308
|
-
const type = props.selectableType;
|
|
309
|
-
if (type === 'multiple') {
|
|
310
|
-
const index = selectedPaths.value.findIndex((item) => item === path);
|
|
311
|
-
const newVal = [...selectedPaths.value];
|
|
312
|
-
if (index !== -1) {
|
|
313
|
-
newVal.splice(index, 1);
|
|
314
|
-
} else {
|
|
315
|
-
newVal.push(path);
|
|
316
|
-
}
|
|
317
|
-
emits('update:selectedValue', newVal);
|
|
318
|
-
|
|
319
|
-
emits('selectedChange', newVal, [...selectedPaths.value]);
|
|
320
|
-
} else if (type === 'single') {
|
|
321
|
-
if (selectedPaths.value[0] !== path) {
|
|
322
|
-
const [oldVal] = selectedPaths.value;
|
|
323
|
-
const newVal = path;
|
|
324
|
-
emits('update:selectedValue', newVal);
|
|
325
|
-
emits('selectedChange', newVal, oldVal);
|
|
326
|
-
}
|
|
327
|
-
}
|
|
328
|
-
};
|
|
329
|
-
|
|
330
|
-
const handleNodeClick = (node: NodeDataType) => {
|
|
331
|
-
emits('nodeClick', node);
|
|
332
|
-
};
|
|
333
|
-
|
|
334
|
-
const handleNodeMouseover = (node: NodeDataType) => {
|
|
335
|
-
emits('nodeMouseover', node);
|
|
336
|
-
};
|
|
337
|
-
|
|
338
|
-
const updateCollapsedPaths = (collapsed: boolean, path: string) => {
|
|
339
|
-
if (collapsed) {
|
|
340
|
-
state.hiddenPaths = {
|
|
341
|
-
...state.hiddenPaths,
|
|
342
|
-
[path]: 1,
|
|
343
|
-
};
|
|
344
|
-
} else {
|
|
345
|
-
const newPaths = { ...state.hiddenPaths };
|
|
346
|
-
delete newPaths[path];
|
|
347
|
-
state.hiddenPaths = newPaths;
|
|
348
|
-
}
|
|
349
|
-
|
|
350
|
-
if (path === props.rootPath) {
|
|
351
|
-
state.height = collapsed ? props.itemHeight : props.height;
|
|
352
|
-
}
|
|
353
|
-
};
|
|
354
|
-
|
|
355
|
-
const handleBracketsClick = (collapsed: boolean, node: NodeDataType) => {
|
|
356
|
-
if (props.collapsedOnClickBrackets) {
|
|
357
|
-
updateCollapsedPaths(collapsed, node.path);
|
|
358
|
-
}
|
|
359
|
-
emits('bracketsClick', collapsed, node);
|
|
360
|
-
};
|
|
361
|
-
|
|
362
|
-
const handleIconClick = (collapsed: boolean, node: NodeDataType) => {
|
|
363
|
-
updateCollapsedPaths(collapsed, node.path);
|
|
364
|
-
emits('iconClick', collapsed, node);
|
|
365
|
-
};
|
|
366
|
-
|
|
367
|
-
const handleValueChange = (value: unknown, path: string) => {
|
|
368
|
-
const newData = cloneDeep(props.data);
|
|
369
|
-
const rootPath = props.rootPath;
|
|
370
|
-
const key = path.slice(rootPath.length);
|
|
371
|
-
setValueByPath(newData, key, value);
|
|
372
|
-
emits('update:data', newData);
|
|
373
|
-
};
|
|
374
|
-
|
|
375
|
-
// 监听和副作用
|
|
376
|
-
watchEffect(() => {
|
|
377
|
-
if (propsErrorMessage.value) {
|
|
378
|
-
emitError(propsErrorMessage.value);
|
|
379
|
-
}
|
|
380
|
-
});
|
|
381
|
-
|
|
382
|
-
watchEffect(() => {
|
|
383
|
-
if (flatData.value) {
|
|
384
|
-
updateVisibleData();
|
|
385
|
-
}
|
|
386
|
-
});
|
|
387
|
-
|
|
388
|
-
watch(
|
|
389
|
-
() => props.deep,
|
|
390
|
-
(val) => {
|
|
391
|
-
if (val)
|
|
392
|
-
state.hiddenPaths = initHiddenPaths(val, props.collapsedNodeLength);
|
|
393
|
-
},
|
|
394
|
-
);
|
|
395
|
-
|
|
396
|
-
watch(
|
|
397
|
-
() => props.collapsedNodeLength,
|
|
398
|
-
(val) => {
|
|
399
|
-
if (val) state.hiddenPaths = initHiddenPaths(props.deep, val);
|
|
400
|
-
},
|
|
401
|
-
);
|
|
402
|
-
|
|
403
|
-
// 监听是否折叠,默认不折叠
|
|
404
|
-
watch(
|
|
405
|
-
() => props.collapsed,
|
|
406
|
-
(val) => {
|
|
407
|
-
if (val) {
|
|
408
|
-
updateCollapsedPaths(true, props.rootPath);
|
|
409
|
-
}
|
|
410
|
-
},
|
|
411
|
-
{
|
|
412
|
-
immediate: true,
|
|
413
|
-
},
|
|
414
|
-
);
|
|
415
|
-
|
|
416
|
-
// 生命周期钩子
|
|
417
|
-
onMounted(() => {
|
|
418
|
-
updateVisibleData();
|
|
419
|
-
});
|
|
420
|
-
|
|
421
|
-
onUpdated(() => {
|
|
422
|
-
// 可选的更新后操作
|
|
423
|
-
});
|
|
424
|
-
|
|
425
|
-
onUnmounted(() => {
|
|
426
|
-
// 清理操作
|
|
427
|
-
});
|
|
428
|
-
</script>
|
|
429
|
-
|
|
430
|
-
<style>
|
|
431
|
-
.json-pretty-tree {
|
|
432
|
-
/* theme color */
|
|
433
|
-
--json-pretty-color-primary: #9254de;
|
|
434
|
-
--json-pretty-color-info: #1d8ce0;
|
|
435
|
-
--json-pretty-color-error: #ff4d4f;
|
|
436
|
-
--json-pretty-color-success: #888888;
|
|
437
|
-
--json-pretty-color-nil: #020201;
|
|
438
|
-
|
|
439
|
-
/* field values color */
|
|
440
|
-
--json-pretty-color-string: var(--json-pretty-color-success);
|
|
441
|
-
--json-pretty-color-number: var(--json-pretty-color-info);
|
|
442
|
-
--json-pretty-color-boolean: var(--json-pretty-color-info);
|
|
443
|
-
--json-pretty-color-null: var(--json-pretty-color-nil);
|
|
444
|
-
--json-pretty-color-undefined: var(--json-pretty-color-nil);
|
|
445
|
-
|
|
446
|
-
/* highlight */
|
|
447
|
-
--json-pretty-highlight-bg-color: rgba(146, 84, 222, 0.1);
|
|
448
|
-
--json-pretty-highlight-bg-color-dark: #2e4558;
|
|
449
|
-
|
|
450
|
-
/* comment */
|
|
451
|
-
--json-pretty-comment-color: #bfcbd9;
|
|
452
|
-
|
|
453
|
-
/* common border-color */
|
|
454
|
-
--json-pretty-border-color: #bfcbd9;
|
|
455
|
-
|
|
456
|
-
font-family:
|
|
457
|
-
'Monaco', 'Menlo', 'Consolas', 'Bitstream Vera Sans Mono', monospace;
|
|
458
|
-
font-size: v-bind(fontSize);
|
|
459
|
-
text-align: left;
|
|
460
|
-
overflow: auto;
|
|
461
|
-
position: relative;
|
|
462
|
-
width: 100%;
|
|
463
|
-
}
|
|
464
|
-
|
|
465
|
-
.json-pretty-tree.is-virtual {
|
|
466
|
-
overflow: auto;
|
|
467
|
-
}
|
|
468
|
-
|
|
469
|
-
.json-pretty-tree-node {
|
|
470
|
-
white-space: nowrap;
|
|
471
|
-
}
|
|
472
|
-
|
|
473
|
-
.dark {
|
|
474
|
-
/* 深色主题样式 */
|
|
475
|
-
}
|
|
476
|
-
</style>
|
|
@@ -1,125 +0,0 @@
|
|
|
1
|
-
import type { CSSProperties } from 'vue';
|
|
2
|
-
|
|
3
|
-
export type JsonPrettyNodeProps = {
|
|
4
|
-
data: any;
|
|
5
|
-
rootPath: string;
|
|
6
|
-
indent: number;
|
|
7
|
-
showLength: boolean;
|
|
8
|
-
showDoubleQuotes: boolean;
|
|
9
|
-
renderNodeKey: any;
|
|
10
|
-
renderNodeValue: any;
|
|
11
|
-
};
|
|
12
|
-
export interface NodeDataType extends JSONFlattenReturnType {
|
|
13
|
-
id: number;
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
export interface JSONFlattenOptions {
|
|
17
|
-
key?: string;
|
|
18
|
-
index?: number;
|
|
19
|
-
showComma: boolean;
|
|
20
|
-
length: number;
|
|
21
|
-
type:
|
|
22
|
-
| 'content'
|
|
23
|
-
| 'objectStart'
|
|
24
|
-
| 'objectEnd'
|
|
25
|
-
| 'objectCollapsed'
|
|
26
|
-
| 'arrayStart'
|
|
27
|
-
| 'arrayEnd'
|
|
28
|
-
| 'arrayCollapsed';
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
export type JSONDataType =
|
|
32
|
-
| string
|
|
33
|
-
| number
|
|
34
|
-
| boolean
|
|
35
|
-
| unknown[]
|
|
36
|
-
| Record<string, unknown>
|
|
37
|
-
| null;
|
|
38
|
-
|
|
39
|
-
export interface JSONFlattenReturnType extends JSONFlattenOptions {
|
|
40
|
-
content: string | number | null | boolean;
|
|
41
|
-
level: number;
|
|
42
|
-
path: string;
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
export type StyleValue =
|
|
46
|
-
| false
|
|
47
|
-
| null
|
|
48
|
-
| undefined
|
|
49
|
-
| string
|
|
50
|
-
| CSSProperties
|
|
51
|
-
| Array<StyleValue>;
|
|
52
|
-
|
|
53
|
-
// 定义 Props 类型
|
|
54
|
-
type SelectableType = 'single' | 'multiple' | null;
|
|
55
|
-
|
|
56
|
-
export type TreeNodeProps = Partial<{
|
|
57
|
-
data: any;
|
|
58
|
-
indent: number;
|
|
59
|
-
showLength: boolean;
|
|
60
|
-
showDoubleQuotes: boolean;
|
|
61
|
-
selectableType: SelectableType;
|
|
62
|
-
showSelectController: boolean;
|
|
63
|
-
showLine: boolean;
|
|
64
|
-
showLineNumber: boolean;
|
|
65
|
-
showNodeActions: boolean;
|
|
66
|
-
selectOnClickNode: boolean;
|
|
67
|
-
highlightSelectedNode: boolean;
|
|
68
|
-
showIcon: boolean;
|
|
69
|
-
theme: string;
|
|
70
|
-
showKeyValueSpace: boolean;
|
|
71
|
-
editable: boolean;
|
|
72
|
-
editableTrigger: string;
|
|
73
|
-
node: NodeDataType;
|
|
74
|
-
checked: boolean;
|
|
75
|
-
collapsed: boolean;
|
|
76
|
-
style: CSSProperties;
|
|
77
|
-
fontSize: string;
|
|
78
|
-
onNodeClick: (node: NodeDataType) => void;
|
|
79
|
-
onNodeMouseover: (node: NodeDataType) => void;
|
|
80
|
-
onBracketsClick: (collapsed: boolean, node: NodeDataType) => void;
|
|
81
|
-
onIconClick: (collapsed: boolean, node: NodeDataType) => void;
|
|
82
|
-
onValueChange: (value: boolean, path: string) => void;
|
|
83
|
-
onSelectedChange: (node: NodeDataType) => void;
|
|
84
|
-
}> &
|
|
85
|
-
TreeNodeRequiredProps;
|
|
86
|
-
|
|
87
|
-
export type TreeNodeRequiredProps = {
|
|
88
|
-
node: NodeDataType;
|
|
89
|
-
rootPath: string;
|
|
90
|
-
nodeSelectable: (node: NodeDataType) => boolean;
|
|
91
|
-
};
|
|
92
|
-
|
|
93
|
-
export type TreeRequired = TreeNodeRequiredProps & {};
|
|
94
|
-
|
|
95
|
-
export type Tree = Partial<TreeNodeProps> &
|
|
96
|
-
Partial<
|
|
97
|
-
{
|
|
98
|
-
deep: number;
|
|
99
|
-
collapsedNodeLength: number;
|
|
100
|
-
virtual: boolean;
|
|
101
|
-
itemHeight: number;
|
|
102
|
-
height: number;
|
|
103
|
-
selectedValue: string | Array<any>;
|
|
104
|
-
collapsedOnClickBrackets: boolean;
|
|
105
|
-
style: CSSProperties;
|
|
106
|
-
pathCollapsible: (node: NodeDataType) => boolean;
|
|
107
|
-
/** 超过行数将会自动启用虚拟列表 */
|
|
108
|
-
autoVirtualRow: number;
|
|
109
|
-
} & TreeRequired
|
|
110
|
-
>;
|
|
111
|
-
|
|
112
|
-
export interface ScrollEvent {
|
|
113
|
-
detail: {
|
|
114
|
-
scrollLeft: number; // 横向滚动距离
|
|
115
|
-
scrollTop: number; // 纵向滚动距离
|
|
116
|
-
scrollHeight: number; // 可滚动区域的高度
|
|
117
|
-
scrollWidth: number; // 可滚动区域的宽度
|
|
118
|
-
deltaX: number; // 横向滚动增量
|
|
119
|
-
deltaY: number; // 纵向滚动增量
|
|
120
|
-
};
|
|
121
|
-
target: EventTarget; // 事件源组件
|
|
122
|
-
currentTarget: EventTarget; // 当前组件
|
|
123
|
-
timeStamp: number; // 事件触发时间戳
|
|
124
|
-
type: string; // 事件类型,这里是 'scroll'
|
|
125
|
-
}
|