vite-uni-dev-tool 1.0.0 → 1.1.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.
Files changed (168) hide show
  1. package/README.md +46 -0
  2. package/dist/const.cjs +1 -1
  3. package/dist/const.d.ts +12 -0
  4. package/dist/const.d.ts.map +1 -1
  5. package/dist/const.js +1 -1
  6. package/dist/core-shared.d.ts +1 -1
  7. package/dist/core-shared.d.ts.map +1 -1
  8. package/dist/core-shared.js +1 -1
  9. package/dist/core.d.ts +10 -3
  10. package/dist/core.d.ts.map +1 -1
  11. package/dist/core.js +2 -2
  12. package/dist/i18n/locales/en.cjs +1 -1
  13. package/dist/i18n/locales/en.d.ts +81 -0
  14. package/dist/i18n/locales/en.d.ts.map +1 -1
  15. package/dist/i18n/locales/en.js +1 -1
  16. package/dist/i18n/locales/zh-Hans.cjs +1 -1
  17. package/dist/i18n/locales/zh-Hans.d.ts +82 -1
  18. package/dist/i18n/locales/zh-Hans.d.ts.map +1 -1
  19. package/dist/i18n/locales/zh-Hans.js +1 -1
  20. package/dist/modules/devConsole/index.cjs +1 -1
  21. package/dist/modules/devConsole/index.js +3 -3
  22. package/dist/modules/devEvent/index.cjs +3 -3
  23. package/dist/modules/devEvent/index.d.ts +1 -0
  24. package/dist/modules/devEvent/index.d.ts.map +1 -1
  25. package/dist/modules/devEvent/index.js +3 -3
  26. package/dist/modules/devIntercept/index.cjs +14 -13
  27. package/dist/modules/devIntercept/index.d.ts +19 -0
  28. package/dist/modules/devIntercept/index.d.ts.map +1 -1
  29. package/dist/modules/devIntercept/index.js +14 -13
  30. package/dist/modules/devStore/index.cjs +1 -1
  31. package/dist/modules/devStore/index.d.ts +21 -0
  32. package/dist/modules/devStore/index.d.ts.map +1 -1
  33. package/dist/modules/devStore/index.js +1 -1
  34. package/dist/plugins/uniDevTool/transform/transformMain.cjs +1 -1
  35. package/dist/plugins/uniDevTool/transform/transformMain.js +1 -1
  36. package/dist/type.d.ts +47 -2
  37. package/dist/type.d.ts.map +1 -1
  38. package/dist/utils/language.cjs +1 -1
  39. package/dist/utils/language.d.ts.map +1 -1
  40. package/dist/utils/language.js +1 -1
  41. package/dist/utils/object.cjs +1 -1
  42. package/dist/utils/object.d.ts.map +1 -1
  43. package/dist/utils/object.js +1 -1
  44. package/dist/v3/DevTool/components/BluetoothList/BluetoothItem.vue +199 -0
  45. package/dist/v3/DevTool/components/BluetoothList/BluetoothTool.vue +730 -0
  46. package/dist/v3/DevTool/components/BluetoothList/index.vue +167 -0
  47. package/dist/v3/{CaptureScreen → DevTool/components/CaptureScreen}/index.vue +109 -109
  48. package/dist/v3/{ConsoleList → DevTool/components/ConsoleList}/ConsoleItem.vue +225 -224
  49. package/dist/v3/{ConsoleList → DevTool/components/ConsoleList}/RunJSInput.vue +247 -249
  50. package/dist/v3/{ConsoleList → DevTool/components/ConsoleList}/index.vue +171 -160
  51. package/dist/v3/{ConsoleList → DevTool/components/ConsoleList}/staticTips.ts +1145 -1145
  52. package/dist/v3/{DevToolButton → DevTool/components/DevToolButton}/index.vue +7 -4
  53. package/dist/v3/{DevToolTitle → DevTool/components/DevToolTitle}/index.vue +24 -24
  54. package/dist/v3/{DevToolWindow → DevTool/components/DevToolWindow}/DevToolOverlay.vue +197 -182
  55. package/dist/v3/{DevToolWindow → DevTool/components/DevToolWindow}/const.ts +28 -5
  56. package/dist/v3/{DevToolWindow → DevTool/components/DevToolWindow}/hooks/dataUtils.ts +48 -48
  57. package/dist/v3/{DevToolWindow → DevTool/components/DevToolWindow}/hooks/useDevToolData.ts +387 -338
  58. package/dist/v3/{DevToolWindow → DevTool/components/DevToolWindow}/hooks/useDevToolHandlers.ts +629 -549
  59. package/dist/v3/{DevToolWindow → DevTool/components/DevToolWindow}/hooks/useDevToolOverlay.ts +197 -184
  60. package/dist/v3/{DevToolWindow → DevTool/components/DevToolWindow}/index.vue +67 -16
  61. package/dist/v3/{ElEvent → DevTool/components/ElEvent}/ElEventItem.vue +105 -105
  62. package/dist/v3/{ElEvent → DevTool/components/ElEvent}/index.vue +106 -109
  63. package/dist/v3/{Instance → DevTool/components/Instance}/components/InstanceTreeNode.vue +265 -265
  64. package/dist/v3/{Instance → DevTool/components/Instance}/flatten.ts +226 -226
  65. package/dist/v3/{Instance → DevTool/components/Instance}/index.vue +94 -94
  66. package/dist/v3/{Instance → DevTool/components/Instance}/registry.ts +49 -49
  67. package/dist/v3/{Instance → DevTool/components/Instance}/transformTree.ts +375 -375
  68. package/dist/v3/{Instance → DevTool/components/Instance}/transformTreeCtx.ts +268 -268
  69. package/dist/v3/{Instance → DevTool/components/Instance}/typing.d.ts +43 -43
  70. package/dist/v3/{InstanceDetail → DevTool/components/InstanceDetail}/index.vue +485 -485
  71. package/dist/v3/{JsonDetail → DevTool/components/JsonDetail}/index.vue +70 -70
  72. package/dist/v3/{NFCList → DevTool/components/NFCList}/NFCItem.vue +112 -113
  73. package/dist/v3/{NFCList → DevTool/components/NFCList}/NFCTool.vue +454 -478
  74. package/dist/v3/{NFCList → DevTool/components/NFCList}/const.ts +56 -56
  75. package/dist/v3/{NFCList → DevTool/components/NFCList}/index.vue +94 -98
  76. package/dist/v3/{NetworkList → DevTool/components/NetworkList}/InterceptConfig.vue +624 -608
  77. package/dist/v3/{NetworkList → DevTool/components/NetworkList}/InterceptItem.vue +140 -140
  78. package/dist/v3/{NetworkList → DevTool/components/NetworkList}/NetworkDetail.vue +287 -296
  79. package/dist/v3/{NetworkList → DevTool/components/NetworkList}/NetworkIntercept.vue +88 -93
  80. package/dist/v3/{NetworkList → DevTool/components/NetworkList}/NetworkItem.vue +163 -167
  81. package/dist/v3/{NetworkList → DevTool/components/NetworkList}/NetworkSend.vue +589 -556
  82. package/dist/v3/{NetworkList → DevTool/components/NetworkList}/const.ts +4 -4
  83. package/dist/v3/{NetworkList → DevTool/components/NetworkList}/hooks/useNetworkForm.ts +86 -86
  84. package/dist/v3/{NetworkList → DevTool/components/NetworkList}/index.vue +160 -160
  85. package/dist/v3/{NetworkList → DevTool/components/NetworkList}/utils.ts +101 -101
  86. package/dist/v3/{Performance → DevTool/components/Performance}/index.vue +498 -495
  87. package/dist/v3/{Performance → DevTool/components/Performance}/modules/PerformanceMetrics.vue +153 -153
  88. package/dist/v3/{Performance → DevTool/components/Performance}/modules/PerformanceWidget.vue +12 -9
  89. package/dist/v3/{Performance → DevTool/components/Performance}/modules/usePerformanceChart.ts +460 -460
  90. package/dist/v3/{Performance → DevTool/components/Performance}/modules/usePerformanceData.ts +258 -258
  91. package/dist/v3/{PiniaList → DevTool/components/PiniaList}/index.vue +93 -94
  92. package/dist/v3/{RouteList → DevTool/components/RouteList}/index.vue +21 -24
  93. package/dist/v3/{RunJS → DevTool/components/RunJS}/index.vue +148 -148
  94. package/dist/v3/{ScanCodeList → DevTool/components/ScanCodeList}/ScanCodeItem.vue +97 -98
  95. package/dist/v3/{ScanCodeList → DevTool/components/ScanCodeList}/index.vue +100 -104
  96. package/dist/v3/{SettingButton → DevTool/components/SettingButton}/index.vue +45 -45
  97. package/dist/v3/{SettingList → DevTool/components/SettingList}/index.vue +218 -150
  98. package/dist/v3/DevTool/components/SettingList/modules/SettingBarrage.vue +304 -0
  99. package/dist/v3/{SettingList → DevTool/components/SettingList}/modules/SettingDevTool.vue +212 -208
  100. package/dist/v3/{SettingList → DevTool/components/SettingList}/modules/SettingInfo.vue +157 -119
  101. package/dist/v3/{SettingList → DevTool/components/SettingList}/modules/SettingLanguage.vue +74 -74
  102. package/dist/v3/{SettingList → DevTool/components/SettingList}/modules/SettingLog.vue +230 -230
  103. package/dist/v3/{SettingList → DevTool/components/SettingList}/modules/SettingNetwork.vue +3 -3
  104. package/dist/v3/{SettingList → DevTool/components/SettingList}/modules/SettingTheme.vue +37 -7
  105. package/dist/v3/{SettingList → DevTool/components/SettingList}/typing.d.ts +2 -2
  106. package/dist/v3/{SourceCode → DevTool/components/SourceCode}/Line.vue +127 -116
  107. package/dist/v3/{SourceCode → DevTool/components/SourceCode}/index.vue +8 -8
  108. package/dist/v3/{SourceCode → DevTool/components/SourceCode}/parseCode.ts +609 -701
  109. package/dist/v3/{StorageList → DevTool/components/StorageList}/index.vue +174 -174
  110. package/dist/v3/{TransferList → DevTool/components/TransferList}/TransferDetail.vue +268 -268
  111. package/dist/v3/{TransferList → DevTool/components/TransferList}/TransferItem.vue +4 -4
  112. package/dist/v3/{TransferList → DevTool/components/TransferList}/index.vue +8 -8
  113. package/dist/v3/{UniEvent → DevTool/components/UniEvent}/UniEventItem.vue +6 -7
  114. package/dist/v3/{UniEvent → DevTool/components/UniEvent}/index.vue +6 -6
  115. package/dist/v3/{VuexList → DevTool/components/VuexList}/index.vue +84 -84
  116. package/dist/v3/{WebSocket → DevTool/components/WebSocket}/WebSocketDetail.vue +8 -8
  117. package/dist/v3/{WebSocket → DevTool/components/WebSocket}/WebSocketItem.vue +4 -4
  118. package/dist/v3/{WebSocket → DevTool/components/WebSocket}/index.vue +8 -8
  119. package/dist/v3/DevTool/index.vue +179 -5
  120. package/dist/v3/{AppTransition → components/AppTransition}/index.vue +176 -170
  121. package/dist/v3/{AutoSizer → components/AutoSizer}/index.vue +192 -192
  122. package/dist/v3/{AutoSizer → components/AutoSizer}/index1.vue +184 -184
  123. package/dist/v3/{AutoSizer → components/AutoSizer}/utils.ts +49 -49
  124. package/dist/v3/components/Barrage/BarrageItem.vue +137 -0
  125. package/dist/v3/components/Barrage/index.vue +202 -0
  126. package/dist/v3/{CircularButton → components/CircularButton}/index.vue +84 -84
  127. package/dist/v3/{CustomSwiper → components/CustomSwiper}/CustomSwiperItem.vue +49 -49
  128. package/dist/v3/{CustomSwiper → components/CustomSwiper}/index.vue +104 -104
  129. package/dist/v3/{DraggableContainer → components/DraggableContainer}/index.vue +1 -1
  130. package/dist/v3/{Empty → components/Empty}/index.vue +29 -29
  131. package/dist/v3/{FilterInput → components/FilterInput}/index.vue +1 -1
  132. package/dist/v3/{FilterSelect → components/FilterSelect}/index.vue +179 -179
  133. package/dist/v3/{JsonPretty → components/JsonPretty}/components/Brackets/index.vue +27 -27
  134. package/dist/v3/{JsonPretty → components/JsonPretty}/components/Carets/index.vue +59 -59
  135. package/dist/v3/{JsonPretty → components/JsonPretty}/components/CheckController/index.vue +136 -136
  136. package/dist/v3/{JsonPretty → components/JsonPretty}/components/TreeNode/index.vue +387 -381
  137. package/dist/v3/{JsonPretty → components/JsonPretty}/hooks/useClipboard.ts +21 -21
  138. package/dist/v3/{JsonPretty → components/JsonPretty}/hooks/useError.ts +21 -21
  139. package/dist/v3/{JsonPretty → components/JsonPretty}/index.vue +16 -13
  140. package/dist/v3/{JsonPretty → components/JsonPretty}/type.ts +127 -126
  141. package/dist/v3/{JsonPretty → components/JsonPretty}/utils/index.ts +169 -169
  142. package/dist/v3/{MovableContainer → components/MovableContainer}/index.vue +1 -1
  143. package/dist/v3/{Pick → components/Pick}/index.vue +322 -322
  144. package/dist/v3/{Tabs → components/Tabs}/index.vue +30 -4
  145. package/dist/v3/{Tag → components/Tag}/index.vue +113 -113
  146. package/dist/v3/{VirtualList → components/VirtualList}/AutoSize.vue +40 -40
  147. package/dist/v3/{VirtualList → components/VirtualList}/index.vue +416 -412
  148. package/dist/v3/hooks/useBluetooth/index.ts +561 -0
  149. package/dist/v3/hooks/useContainerStyle.ts +153 -153
  150. package/dist/v3/hooks/useNFC/index.ts +107 -107
  151. package/dist/v3/hooks/useNFC/typing.d.ts +396 -396
  152. package/dist/v3/hooks/useNFC/useNFCAndroid.ts +966 -966
  153. package/dist/v3/hooks/useNFC/useNFCMpWeiXin.ts +812 -812
  154. package/dist/v3/hooks/useNFC/utils.ts +754 -754
  155. package/dist/v3/hooks/useRequest/index.ts +586 -573
  156. package/dist/v3/hooks/useRequest/utils.ts +267 -267
  157. package/dist/v3/hooks/useScanCode/index.ts +206 -206
  158. package/dist/v3/hooks/useWebsocket/README.md +79 -0
  159. package/dist/v3/hooks/useWebsocket/index.ts +253 -0
  160. package/dist/v3/styles/theme.css +17 -10
  161. package/dist/v3/styles/theme.ts +12 -12
  162. package/package.json +59 -64
  163. package/dist/plugins/uniParseStock/index.d.ts +0 -10
  164. package/dist/plugins/uniParseStock/index.d.ts.map +0 -1
  165. /package/dist/v3/{DevToolWindow → DevTool/components/DevToolWindow}/index.css +0 -0
  166. /package/dist/v3/{SettingList → DevTool/components/SettingList}/index.css +0 -0
  167. /package/dist/v3/{Empty → components/Empty}/empty.png +0 -0
  168. /package/dist/v3/{VirtualList → components/VirtualList}/readme.md +0 -0
@@ -1,381 +1,387 @@
1
- <template>
2
- <view
3
- :class="{
4
- 'json-pretty-tree-node': true,
5
- 'has-selector': showSelectController,
6
- 'has-carets': showIcon,
7
- 'is-highlight': highlightSelectedNode && checked,
8
- 'json-pretty-tree-node-active': state.editing,
9
- dark: theme === 'dark',
10
- }"
11
- @click="handleNodeClick"
12
- @mouseover="handleNodeMouseover"
13
- :style="customStyle">
14
- <view v-if="showLineNumber" class="json-pretty-node-index">
15
- {{ node.id + 1 }}
16
- </view>
17
-
18
- <CheckController
19
- v-if="
20
- showSelectController &&
21
- selectable &&
22
- node.type !== 'objectEnd' &&
23
- node.type !== 'arrayEnd'
24
- "
25
- :isMultiple="isMultiple"
26
- :theme="theme"
27
- :checked="checked"
28
- @change="handleSelectedChange" />
29
-
30
- <view class="json-pretty-indent">
31
- <view
32
- v-for="(item, index) in Array(node.level)"
33
- :key="index"
34
- :class="{
35
- 'json-pretty-indent-unit': true,
36
- 'has-line': showLine,
37
- }">
38
- <view
39
- v-for="(_, i) in indent"
40
- :key="i"
41
- class="json-pretty-indent-space"></view>
42
- </view>
43
- <Carets v-if="showIcon" :nodeType="node.type" @click="handleIconClick" />
44
- </view>
45
-
46
- <view v-if="node.key" class="json-pretty-key">
47
- <slot name="render-node-key" :node="props.node" :default-key="prettyKey">
48
- {{ prettyKey }}
49
- </slot>
50
- <view class="json-pretty-colon">
51
- {{ `:${showKeyValueSpace ? ' ' : ''}` }}
52
- </view>
53
- </view>
54
-
55
- <view class="json-pretty-value-wrapper">
56
- <Brackets
57
- v-if="node.type !== 'content' && node.content"
58
- :data="node.content.toString()"
59
- @click="handleBracketsClick" />
60
-
61
- <view v-else :class="valueClass" @click="handleValueEdit">
62
- <input
63
- v-if="editable && state.editing"
64
- class="json-pretty-edit-input"
65
- :value="defaultValue"
66
- :focus="state.editing"
67
- @blur="handleInputBlur" />
68
- <view v-else>
69
- <slot
70
- name="render-node-value"
71
- :node="props.node"
72
- :default-value="defaultValue">
73
- {{ defaultValue }}
74
- </slot>
75
- <text v-if="node.showComma">,</text>
76
- </view>
77
- </view>
78
-
79
- <view v-if="showLength && collapsed" class="json-pretty-comment">
80
- // {{ node.length }} items
81
- </view>
82
- </view>
83
- <view class="json-pretty-tree-node-actions" v-if="showNodeActions">
84
- <slot name="render-node-actions" :copy="handleCopy">
85
- <view @click="handleCopy" class="json-pretty-tree-node-actions-item">
86
- copy
87
- </view>
88
- </slot>
89
- </view>
90
- </view>
91
- </template>
92
-
93
- <script lang="ts" setup>
94
- import { reactive, computed } from 'vue';
95
- import Brackets from '../Brackets/index.vue';
96
- import CheckController from '../CheckController/index.vue';
97
- import Carets from '../Carets/index.vue';
98
- import { getDataType, isFunction, stringToAutoType } from '../../utils';
99
-
100
- import type { NodeDataType, TreeNodeProps } from '../../type';
101
- import { getValueByPath } from '../../../../utils';
102
-
103
- const props = withDefaults(defineProps<TreeNodeProps>(), {
104
- rootPath: 'root',
105
- indent: 2,
106
- showDoubleQuotes: true,
107
- showLine: true,
108
- selectOnClickNode: true,
109
- highlightSelectedNode: true,
110
- theme: 'light',
111
- showKeyValueSpace: true,
112
- editableTrigger: 'click',
113
- checked: false,
114
-
115
- nodeSelectable: () => false,
116
- });
117
-
118
- const emit = defineEmits<{
119
- (e: 'nodeClick', node: NodeDataType): void;
120
- (e: 'nodeMouseover', node: NodeDataType): void;
121
- (e: 'bracketsClick', collapsed: boolean, node: NodeDataType): void;
122
- (e: 'iconClick', collapsed: boolean, node: NodeDataType): void;
123
- (e: 'selectedChange', node: NodeDataType): void;
124
- (e: 'valueChange', value: any, path: string): void;
125
- }>();
126
-
127
- const dataType = computed<string>(() => getDataType(props.node.content));
128
-
129
- const valueClass = computed(
130
- () => `json-pretty-value json-pretty-value-${dataType.value}`,
131
- );
132
-
133
- const prettyKey = computed(() =>
134
- props.showDoubleQuotes ? `"${props.node.key}"` : props.node.key,
135
- );
136
-
137
- const isMultiple = computed(() => props.selectableType === 'multiple');
138
-
139
- const isSingle = computed(() => props.selectableType === 'single');
140
-
141
- const selectable = computed(
142
- () =>
143
- isFunction(props?.nodeSelectable) &&
144
- props?.nodeSelectable?.(props.node) &&
145
- (isMultiple.value || isSingle.value),
146
- );
147
-
148
- const state = reactive({
149
- editing: false,
150
- });
151
-
152
- const handleInputBlur = (e: FocusEvent) => {
153
- const source = (e.detail as any).value;
154
- const value = stringToAutoType(source);
155
- emit('valueChange', value, props.node.path);
156
- state.editing = false;
157
- };
158
-
159
- const defaultValue = computed(() => {
160
- let value = props.node?.content;
161
- if (value === null) {
162
- value = 'null';
163
- } else if (value === undefined) {
164
- value = 'undefined';
165
- }
166
- return dataType.value === 'string' ? `"${value}"` : value?.toString();
167
- });
168
-
169
- const handleBracketsClick = () => {
170
- emit('bracketsClick', !props.collapsed, props.node);
171
- };
172
-
173
- const handleIconClick = () => {
174
- emit('iconClick', !props.collapsed, props.node);
175
- };
176
-
177
- const handleSelectedChange = () => {
178
- emit('selectedChange', props.node);
179
- };
180
-
181
- const handleNodeClick = () => {
182
- emit('nodeClick', props.node);
183
- if (selectable.value && props.selectOnClickNode) {
184
- emit('selectedChange', props.node);
185
- }
186
- };
187
-
188
- const handleNodeMouseover = () => {
189
- emit('nodeMouseover', props.node);
190
- };
191
-
192
- const handleValueEdit = (_e: MouseEvent) => {
193
- if (!props.editable) return;
194
-
195
- if (!state.editing) {
196
- state.editing = true;
197
- }
198
- };
199
-
200
- const handleCopy = () => {
201
- const { key, path } = props.node;
202
- const rootPath = props.rootPath;
203
-
204
- const content = getValueByPath(props.data, path.slice(rootPath.length));
205
-
206
- const copiedData = JSON.stringify(
207
- key ? { [key]: content } : content,
208
- null,
209
- 2,
210
- );
211
-
212
- uni.setClipboardData({
213
- data: copiedData,
214
- success() {
215
- uni.showToast({
216
- title: '复制成功',
217
- icon: 'none',
218
- });
219
- },
220
- fail() {
221
- uni.showToast({
222
- title: '复制失败',
223
- icon: 'none',
224
- });
225
- },
226
- });
227
- };
228
- </script>
229
- <style scoped>
230
- .json-pretty-tree-node {
231
- display: flex;
232
-
233
- /* align-items: center; */
234
- position: relative;
235
- line-height: 20px;
236
- }
237
-
238
- .json-pretty-tree-node.has-carets {
239
- padding-left: 15px;
240
- }
241
-
242
- .json-pretty-tree-node.has-selector,
243
- .json-pretty-tree-node.has-carets.has-selector {
244
- padding-left: 30px;
245
- }
246
-
247
- .json-pretty-tree-node.is-highlight,
248
- .json-pretty-tree-node:hover {
249
- background-color: var(--json-pretty-highlight-bg-color);
250
- border-radius: 4px;
251
- }
252
-
253
- .json-pretty-tree-node.is-highlight .json-pretty-tree-node-actions,
254
- .json-pretty-tree-node:hover .json-pretty-tree-node-actions {
255
- display: block;
256
- }
257
-
258
- .json-pretty-tree-node .json-pretty-indent {
259
- display: flex;
260
- position: relative;
261
- }
262
-
263
- .json-pretty-tree-node .json-pretty-indent-unit {
264
- display: flex;
265
- }
266
-
267
- .json-pretty-indent-space {
268
- width: 6px;
269
- }
270
-
271
- .json-pretty-tree-node .json-pretty-indent-unit.has-line {
272
- border-left: 1px dashed var(--json-pretty-border-color);
273
- }
274
-
275
- .json-pretty-tree-node .json-pretty-tree-node-actions {
276
- display: none;
277
- position: absolute;
278
- right: 0;
279
- top: 0;
280
- padding: 0 4px;
281
- background-color: var(--json-pretty-highlight-bg-color);
282
- border-radius: 4px;
283
- }
284
-
285
- .json-pretty-tree-node
286
- .json-pretty-tree-node-actions
287
- .json-pretty-tree-node-actions-item {
288
- cursor: pointer;
289
- }
290
-
291
- .json-pretty-tree-node
292
- .json-pretty-tree-node-actions
293
- .json-pretty-tree-node-actions-item:hover {
294
- color: var(--json-pretty-color-primary);
295
- }
296
-
297
- .json-pretty-tree-node.dark.is-highlight,
298
- .json-pretty-tree-node.dark:hover {
299
- background-color: var(--json-pretty-highlight-bg-color-dark);
300
- }
301
-
302
- .json-pretty-tree-node.dark .json-pretty-tree-node-actions {
303
- background-color: var(--json-pretty-highlight-bg-color-dark);
304
- }
305
-
306
- .json-pretty-tree-node-active {
307
- background-color: var(--json-pretty-highlight-bg-color);
308
- border-radius: 4px;
309
- }
310
-
311
- .json-pretty-tree-node-active .json-pretty-tree-node-actions {
312
- display: block;
313
- }
314
-
315
- .json-pretty-node-index {
316
- position: absolute;
317
- right: 100%;
318
- margin-right: 4px;
319
- user-select: none;
320
- }
321
-
322
- .json-pretty-colon {
323
- white-space: pre;
324
- }
325
-
326
- .json-pretty-comment {
327
- color: var(--json-pretty-color-primary);
328
- }
329
-
330
- .json-pretty-key {
331
- display: flex;
332
- }
333
-
334
- .json-pretty-value-wrapper {
335
- display: flex;
336
- align-items: center;
337
- }
338
-
339
- .json-pretty-value {
340
- /* word-break: break-all; */
341
-
342
- /* white-space: normal; */
343
-
344
- /* white-space: pre-line; */
345
- white-space: nowrap;
346
- }
347
-
348
- .json-pretty-value-null {
349
- color: var(--json-pretty-color-null);
350
- }
351
-
352
- .json-pretty-value-undefined {
353
- color: var(--json-pretty-color-undefined);
354
- }
355
-
356
- .json-pretty-value-number {
357
- color: var(--json-pretty-color-number);
358
- }
359
-
360
- .json-pretty-value-boolean {
361
- color: var(--json-pretty-color-boolean);
362
- }
363
-
364
- .json-pretty-value-string {
365
- color: var(--json-pretty-color-string);
366
- }
367
-
368
- .json-pretty-edit-input {
369
- padding: 0 8px;
370
- border: 1px solid #eee;
371
- box-shadow: none;
372
- box-sizing: border-box;
373
- font: unset;
374
- border-radius: 5px;
375
- font-family: inherit;
376
- color: #000;
377
- font-weight: 400;
378
- background-color: #fff;
379
- height: 16px;
380
- }
381
- </style>
1
+ <template>
2
+ <view
3
+ :class="{
4
+ 'json-pretty-tree-node': true,
5
+ 'has-selector': showSelectController,
6
+ 'has-carets': showIcon,
7
+ 'is-highlight': highlightSelectedNode && checked,
8
+ 'json-pretty-tree-node-active': state.editing,
9
+ dark: theme === 'dark',
10
+ }"
11
+ @click="handleNodeClick"
12
+ @mouseover="handleNodeMouseover"
13
+ :style="customStyle">
14
+ <view
15
+ v-if="showLineNumber"
16
+ class="json-pretty-node-index"
17
+ :style="{
18
+ width: `${Number(node.total?.toString().length || 1) * 8 + 10}px`,
19
+ }">
20
+ {{ node.id + 1 }}
21
+ </view>
22
+
23
+ <CheckController
24
+ v-if="
25
+ showSelectController &&
26
+ selectable &&
27
+ node.type !== 'objectEnd' &&
28
+ node.type !== 'arrayEnd'
29
+ "
30
+ :isMultiple="isMultiple"
31
+ :theme="theme"
32
+ :checked="checked"
33
+ @change="handleSelectedChange" />
34
+
35
+ <view class="json-pretty-indent">
36
+ <view
37
+ v-for="(item, index) in Array(node.level)"
38
+ :key="index"
39
+ :class="{
40
+ 'json-pretty-indent-unit': true,
41
+ 'has-line': showLine,
42
+ }">
43
+ <view
44
+ v-for="(_, i) in indent"
45
+ :key="i"
46
+ class="json-pretty-indent-space"></view>
47
+ </view>
48
+ <Carets v-if="showIcon" :nodeType="node.type" @click="handleIconClick" />
49
+ </view>
50
+
51
+ <view v-if="node.key" class="json-pretty-key">
52
+ <slot name="render-node-key" :node="props.node" :default-key="prettyKey">
53
+ {{ prettyKey }}
54
+ </slot>
55
+ <view class="json-pretty-colon">
56
+ {{ `:${showKeyValueSpace ? ' ' : ''}` }}
57
+ </view>
58
+ </view>
59
+
60
+ <view class="json-pretty-value-wrapper">
61
+ <Brackets
62
+ v-if="node.type !== 'content' && node.content"
63
+ :data="node.content.toString()"
64
+ @click="handleBracketsClick" />
65
+
66
+ <view v-else :class="valueClass" @click="handleValueEdit">
67
+ <input
68
+ v-if="editable && state.editing"
69
+ class="json-pretty-edit-input"
70
+ :value="defaultValue"
71
+ :focus="state.editing"
72
+ @blur="handleInputBlur" />
73
+ <view v-else>
74
+ <slot
75
+ name="render-node-value"
76
+ :node="props.node"
77
+ :default-value="defaultValue">
78
+ {{ defaultValue }}
79
+ </slot>
80
+ <text v-if="node.showComma">,</text>
81
+ </view>
82
+ </view>
83
+
84
+ <view v-if="showLength && collapsed" class="json-pretty-comment">
85
+ // {{ node.length }} items
86
+ </view>
87
+ </view>
88
+ <view class="json-pretty-tree-node-actions" v-if="showNodeActions">
89
+ <slot name="render-node-actions" :copy="handleCopy">
90
+ <view @click="handleCopy" class="json-pretty-tree-node-actions-item">
91
+ copy
92
+ </view>
93
+ </slot>
94
+ </view>
95
+ </view>
96
+ </template>
97
+
98
+ <script lang="ts" setup>
99
+ import { reactive, computed } from 'vue';
100
+ import Brackets from '../Brackets/index.vue';
101
+ import CheckController from '../CheckController/index.vue';
102
+ import Carets from '../Carets/index.vue';
103
+ import { getDataType, isFunction, stringToAutoType } from '../../utils';
104
+
105
+ import type { NodeDataType, TreeNodeProps } from '../../type';
106
+ import { getValueByPath } from '../../../../../utils';
107
+
108
+ const props = withDefaults(defineProps<TreeNodeProps>(), {
109
+ rootPath: 'root',
110
+ indent: 2,
111
+ showDoubleQuotes: true,
112
+ showLine: true,
113
+ selectOnClickNode: true,
114
+ highlightSelectedNode: true,
115
+ theme: 'light',
116
+ showKeyValueSpace: true,
117
+ editableTrigger: 'click',
118
+ checked: false,
119
+
120
+ nodeSelectable: () => false,
121
+ });
122
+
123
+ const emit = defineEmits<{
124
+ (e: 'nodeClick', node: NodeDataType): void;
125
+ (e: 'nodeMouseover', node: NodeDataType): void;
126
+ (e: 'bracketsClick', collapsed: boolean, node: NodeDataType): void;
127
+ (e: 'iconClick', collapsed: boolean, node: NodeDataType): void;
128
+ (e: 'selectedChange', node: NodeDataType): void;
129
+ (e: 'valueChange', value: any, path: string): void;
130
+ }>();
131
+
132
+ const dataType = computed<string>(() => getDataType(props.node.content));
133
+
134
+ const valueClass = computed(
135
+ () => `json-pretty-value json-pretty-value-${dataType.value}`,
136
+ );
137
+
138
+ const prettyKey = computed(() =>
139
+ props.showDoubleQuotes ? `"${props.node.key}"` : props.node.key,
140
+ );
141
+
142
+ const isMultiple = computed(() => props.selectableType === 'multiple');
143
+
144
+ const isSingle = computed(() => props.selectableType === 'single');
145
+
146
+ const selectable = computed(
147
+ () =>
148
+ isFunction(props?.nodeSelectable) &&
149
+ props?.nodeSelectable?.(props.node) &&
150
+ (isMultiple.value || isSingle.value),
151
+ );
152
+
153
+ const state = reactive({
154
+ editing: false,
155
+ });
156
+
157
+ const handleInputBlur = (e: FocusEvent) => {
158
+ const source = (e.detail as any).value;
159
+ const value = stringToAutoType(source);
160
+ emit('valueChange', value, props.node.path);
161
+ state.editing = false;
162
+ };
163
+
164
+ const defaultValue = computed(() => {
165
+ let value = props.node?.content;
166
+ if (value === null) {
167
+ value = 'null';
168
+ } else if (value === undefined) {
169
+ value = 'undefined';
170
+ }
171
+ return dataType.value === 'string' ? `"${value}"` : value?.toString();
172
+ });
173
+
174
+ const handleBracketsClick = () => {
175
+ emit('bracketsClick', !props.collapsed, props.node);
176
+ };
177
+
178
+ const handleIconClick = () => {
179
+ emit('iconClick', !props.collapsed, props.node);
180
+ };
181
+
182
+ const handleSelectedChange = () => {
183
+ emit('selectedChange', props.node);
184
+ };
185
+
186
+ const handleNodeClick = () => {
187
+ emit('nodeClick', props.node);
188
+ if (selectable.value && props.selectOnClickNode) {
189
+ emit('selectedChange', props.node);
190
+ }
191
+ };
192
+
193
+ const handleNodeMouseover = () => {
194
+ emit('nodeMouseover', props.node);
195
+ };
196
+
197
+ const handleValueEdit = (_e: MouseEvent) => {
198
+ if (!props.editable) return;
199
+
200
+ if (!state.editing) {
201
+ state.editing = true;
202
+ }
203
+ };
204
+
205
+ const handleCopy = () => {
206
+ const { key, path } = props.node;
207
+ const rootPath = props.rootPath;
208
+
209
+ const content = getValueByPath(props.data, path.slice(rootPath.length));
210
+
211
+ const copiedData = JSON.stringify(
212
+ key ? { [key]: content } : content,
213
+ null,
214
+ 2,
215
+ );
216
+
217
+ uni.setClipboardData({
218
+ data: copiedData,
219
+ success() {
220
+ uni.showToast({
221
+ title: '复制成功',
222
+ icon: 'none',
223
+ });
224
+ },
225
+ fail() {
226
+ uni.showToast({
227
+ title: '复制失败',
228
+ icon: 'none',
229
+ });
230
+ },
231
+ });
232
+ };
233
+ </script>
234
+ <style scoped>
235
+ .json-pretty-tree-node {
236
+ display: flex;
237
+
238
+ /* align-items: center; */
239
+ position: relative;
240
+ line-height: 20px;
241
+ }
242
+
243
+ .json-pretty-tree-node.has-carets {
244
+ padding-left: 15px;
245
+ }
246
+
247
+ .json-pretty-tree-node.has-selector,
248
+ .json-pretty-tree-node.has-carets.has-selector {
249
+ padding-left: 30px;
250
+ }
251
+
252
+ .json-pretty-tree-node.is-highlight,
253
+ .json-pretty-tree-node:hover {
254
+ background-color: var(--json-pretty-highlight-bg-color);
255
+ border-radius: 4px;
256
+ }
257
+
258
+ .json-pretty-tree-node.is-highlight .json-pretty-tree-node-actions,
259
+ .json-pretty-tree-node:hover .json-pretty-tree-node-actions {
260
+ display: block;
261
+ }
262
+
263
+ .json-pretty-tree-node .json-pretty-indent {
264
+ display: flex;
265
+ position: relative;
266
+ }
267
+
268
+ .json-pretty-tree-node .json-pretty-indent-unit {
269
+ display: flex;
270
+ }
271
+
272
+ .json-pretty-indent-space {
273
+ width: 6px;
274
+ }
275
+
276
+ .json-pretty-tree-node .json-pretty-indent-unit.has-line {
277
+ border-left: 1px dashed var(--json-pretty-border-color);
278
+ }
279
+
280
+ .json-pretty-tree-node .json-pretty-tree-node-actions {
281
+ display: none;
282
+ position: absolute;
283
+ right: 0;
284
+ top: 0;
285
+ padding: 0 4px;
286
+ background-color: var(--json-pretty-highlight-bg-color);
287
+ border-radius: 4px;
288
+ }
289
+
290
+ .json-pretty-tree-node
291
+ .json-pretty-tree-node-actions
292
+ .json-pretty-tree-node-actions-item {
293
+ cursor: pointer;
294
+ }
295
+
296
+ .json-pretty-tree-node
297
+ .json-pretty-tree-node-actions
298
+ .json-pretty-tree-node-actions-item:hover {
299
+ color: var(--json-pretty-color-primary);
300
+ }
301
+
302
+ .json-pretty-tree-node.dark.is-highlight,
303
+ .json-pretty-tree-node.dark:hover {
304
+ background-color: var(--json-pretty-highlight-bg-color-dark);
305
+ }
306
+
307
+ .json-pretty-tree-node.dark .json-pretty-tree-node-actions {
308
+ background-color: var(--json-pretty-highlight-bg-color-dark);
309
+ }
310
+
311
+ .json-pretty-tree-node-active {
312
+ background-color: var(--json-pretty-highlight-bg-color);
313
+ border-radius: 4px;
314
+ }
315
+
316
+ .json-pretty-tree-node-active .json-pretty-tree-node-actions {
317
+ display: block;
318
+ }
319
+
320
+ .json-pretty-node-index {
321
+ flex-shrink: 0;
322
+ text-align: right;
323
+ margin-right: 12px;
324
+ color: var(--json-pretty-comment-color);
325
+ user-select: none;
326
+ }
327
+
328
+ .json-pretty-colon {
329
+ white-space: pre;
330
+ }
331
+
332
+ .json-pretty-comment {
333
+ color: var(--json-pretty-color-primary);
334
+ }
335
+
336
+ .json-pretty-key {
337
+ display: flex;
338
+ }
339
+
340
+ .json-pretty-value-wrapper {
341
+ display: flex;
342
+ align-items: center;
343
+ }
344
+
345
+ .json-pretty-value {
346
+ /* word-break: break-all; */
347
+
348
+ /* white-space: normal; */
349
+
350
+ /* white-space: pre-line; */
351
+ white-space: nowrap;
352
+ }
353
+
354
+ .json-pretty-value-null {
355
+ color: var(--json-pretty-color-null);
356
+ }
357
+
358
+ .json-pretty-value-undefined {
359
+ color: var(--json-pretty-color-undefined);
360
+ }
361
+
362
+ .json-pretty-value-number {
363
+ color: var(--json-pretty-color-number);
364
+ }
365
+
366
+ .json-pretty-value-boolean {
367
+ color: var(--json-pretty-color-boolean);
368
+ }
369
+
370
+ .json-pretty-value-string {
371
+ color: var(--json-pretty-color-string);
372
+ }
373
+
374
+ .json-pretty-edit-input {
375
+ padding: 0 8px;
376
+ border: 1px solid #eee;
377
+ box-shadow: none;
378
+ box-sizing: border-box;
379
+ font: unset;
380
+ border-radius: 5px;
381
+ font-family: inherit;
382
+ color: #000;
383
+ font-weight: 400;
384
+ background-color: #fff;
385
+ height: 16px;
386
+ }
387
+ </style>