vite-uni-dev-tool 1.1.0 → 1.2.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 (135) hide show
  1. package/README.md +8 -0
  2. package/dist/const.cjs +1 -1
  3. package/dist/const.d.ts +1 -0
  4. package/dist/const.d.ts.map +1 -1
  5. package/dist/const.js +1 -1
  6. package/dist/core.d.ts.map +1 -1
  7. package/dist/core.js +2 -2
  8. package/dist/i18n/locales/en.cjs +1 -1
  9. package/dist/i18n/locales/en.d.ts +5 -0
  10. package/dist/i18n/locales/en.d.ts.map +1 -1
  11. package/dist/i18n/locales/en.js +1 -1
  12. package/dist/i18n/locales/zh-Hans.cjs +1 -1
  13. package/dist/i18n/locales/zh-Hans.d.ts +5 -0
  14. package/dist/i18n/locales/zh-Hans.d.ts.map +1 -1
  15. package/dist/i18n/locales/zh-Hans.js +1 -1
  16. package/dist/modules/devIntercept/index.cjs +9 -9
  17. package/dist/modules/devIntercept/index.d.ts +1 -1
  18. package/dist/modules/devIntercept/index.d.ts.map +1 -1
  19. package/dist/modules/devIntercept/index.js +9 -9
  20. package/dist/modules/devStore/index.cjs +1 -1
  21. package/dist/modules/devStore/index.d.ts.map +1 -1
  22. package/dist/modules/devStore/index.js +1 -1
  23. package/dist/plugins/uniDevTool/transform/transformMain.cjs +3 -3
  24. package/dist/plugins/uniDevTool/transform/transformMain.d.ts +2 -1
  25. package/dist/plugins/uniDevTool/transform/transformMain.d.ts.map +1 -1
  26. package/dist/plugins/uniDevTool/transform/transformMain.js +3 -3
  27. package/dist/plugins/uniDevTool/transform/transformVue.cjs +31 -25
  28. package/dist/plugins/uniDevTool/transform/transformVue.d.ts +2 -1
  29. package/dist/plugins/uniDevTool/transform/transformVue.d.ts.map +1 -1
  30. package/dist/plugins/uniDevTool/transform/transformVue.js +30 -24
  31. package/dist/plugins/uniDevTool/uniDevTool.cjs +3 -3
  32. package/dist/plugins/uniDevTool/uniDevTool.d.ts +3 -1
  33. package/dist/plugins/uniDevTool/uniDevTool.d.ts.map +1 -1
  34. package/dist/plugins/uniDevTool/uniDevTool.js +3 -3
  35. package/dist/type.d.ts +3 -0
  36. package/dist/type.d.ts.map +1 -1
  37. package/dist/v3/DevTool/components/BluetoothList/BluetoothItem.vue +199 -199
  38. package/dist/v3/DevTool/components/BluetoothList/BluetoothTool.vue +730 -730
  39. package/dist/v3/DevTool/components/BluetoothList/index.vue +167 -167
  40. package/dist/v3/DevTool/components/CaptureScreen/index.vue +109 -109
  41. package/dist/v3/DevTool/components/ConsoleList/ConsoleItem.vue +230 -225
  42. package/dist/v3/DevTool/components/ConsoleList/RunJSInput.vue +247 -247
  43. package/dist/v3/DevTool/components/ConsoleList/index.vue +171 -171
  44. package/dist/v3/DevTool/components/ConsoleList/staticTips.ts +1145 -1145
  45. package/dist/v3/DevTool/components/DevToolTitle/index.vue +24 -24
  46. package/dist/v3/DevTool/components/DevToolWindow/DevToolOverlay.vue +197 -197
  47. package/dist/v3/DevTool/components/DevToolWindow/hooks/dataUtils.ts +48 -48
  48. package/dist/v3/DevTool/components/DevToolWindow/hooks/useDevToolData.ts +387 -387
  49. package/dist/v3/DevTool/components/DevToolWindow/hooks/useDevToolHandlers.ts +629 -629
  50. package/dist/v3/DevTool/components/DevToolWindow/hooks/useDevToolOverlay.ts +201 -197
  51. package/dist/v3/DevTool/components/ElEvent/ElEventItem.vue +105 -105
  52. package/dist/v3/DevTool/components/ElEvent/index.vue +106 -106
  53. package/dist/v3/DevTool/components/Instance/components/InstanceTreeNode.vue +265 -265
  54. package/dist/v3/DevTool/components/Instance/flatten.ts +226 -226
  55. package/dist/v3/DevTool/components/Instance/index.vue +94 -94
  56. package/dist/v3/DevTool/components/Instance/registry.ts +49 -49
  57. package/dist/v3/DevTool/components/Instance/transformTree.ts +375 -375
  58. package/dist/v3/DevTool/components/Instance/transformTreeCtx.ts +268 -268
  59. package/dist/v3/DevTool/components/Instance/typing.d.ts +43 -43
  60. package/dist/v3/DevTool/components/InstanceDetail/index.vue +485 -485
  61. package/dist/v3/DevTool/components/JsonDetail/index.vue +70 -70
  62. package/dist/v3/DevTool/components/NFCList/NFCItem.vue +112 -112
  63. package/dist/v3/DevTool/components/NFCList/NFCTool.vue +454 -454
  64. package/dist/v3/DevTool/components/NFCList/const.ts +56 -56
  65. package/dist/v3/DevTool/components/NFCList/index.vue +94 -94
  66. package/dist/v3/DevTool/components/NetworkList/InterceptConfig.vue +624 -624
  67. package/dist/v3/DevTool/components/NetworkList/InterceptItem.vue +140 -140
  68. package/dist/v3/DevTool/components/NetworkList/NetworkDetail.vue +287 -287
  69. package/dist/v3/DevTool/components/NetworkList/NetworkIntercept.vue +88 -88
  70. package/dist/v3/DevTool/components/NetworkList/NetworkItem.vue +163 -163
  71. package/dist/v3/DevTool/components/NetworkList/NetworkSend.vue +589 -589
  72. package/dist/v3/DevTool/components/NetworkList/const.ts +4 -4
  73. package/dist/v3/DevTool/components/NetworkList/hooks/useNetworkForm.ts +86 -86
  74. package/dist/v3/DevTool/components/NetworkList/index.vue +160 -160
  75. package/dist/v3/DevTool/components/NetworkList/utils.ts +101 -101
  76. package/dist/v3/DevTool/components/Performance/index.vue +498 -498
  77. package/dist/v3/DevTool/components/Performance/modules/PerformanceMetrics.vue +153 -153
  78. package/dist/v3/DevTool/components/Performance/modules/usePerformanceChart.ts +460 -460
  79. package/dist/v3/DevTool/components/Performance/modules/usePerformanceData.ts +258 -258
  80. package/dist/v3/DevTool/components/PiniaList/index.vue +93 -93
  81. package/dist/v3/DevTool/components/RunJS/index.vue +148 -148
  82. package/dist/v3/DevTool/components/ScanCodeList/ScanCodeItem.vue +97 -97
  83. package/dist/v3/DevTool/components/ScanCodeList/index.vue +100 -100
  84. package/dist/v3/DevTool/components/SettingButton/index.vue +45 -45
  85. package/dist/v3/DevTool/components/SettingList/index.vue +218 -218
  86. package/dist/v3/DevTool/components/SettingList/modules/SettingBarrage.vue +304 -304
  87. package/dist/v3/DevTool/components/SettingList/modules/SettingDevTool.vue +212 -212
  88. package/dist/v3/DevTool/components/SettingList/modules/SettingInfo.vue +157 -157
  89. package/dist/v3/DevTool/components/SettingList/modules/SettingLanguage.vue +74 -74
  90. package/dist/v3/DevTool/components/SettingList/modules/SettingLog.vue +230 -230
  91. package/dist/v3/DevTool/components/SettingList/typing.d.ts +2 -2
  92. package/dist/v3/DevTool/components/SourceCode/Line.vue +127 -127
  93. package/dist/v3/DevTool/components/SourceCode/parseCode.ts +609 -609
  94. package/dist/v3/DevTool/components/StorageList/index.vue +174 -174
  95. package/dist/v3/DevTool/components/TransferList/TransferDetail.vue +268 -268
  96. package/dist/v3/DevTool/components/VuexList/index.vue +84 -84
  97. package/dist/v3/DevTool/index.vue +1 -0
  98. package/dist/v3/components/AppTransition/index.vue +176 -176
  99. package/dist/v3/components/AutoSizer/index.vue +192 -192
  100. package/dist/v3/components/AutoSizer/index1.vue +184 -184
  101. package/dist/v3/components/AutoSizer/utils.ts +49 -49
  102. package/dist/v3/components/Barrage/BarrageItem.vue +137 -137
  103. package/dist/v3/components/Barrage/index.vue +202 -202
  104. package/dist/v3/components/CircularButton/index.vue +84 -84
  105. package/dist/v3/components/CustomSwiper/CustomSwiperItem.vue +49 -49
  106. package/dist/v3/components/CustomSwiper/index.vue +104 -104
  107. package/dist/v3/components/DevErrorBoundary/index.vue +380 -0
  108. package/dist/v3/components/Empty/index.vue +29 -29
  109. package/dist/v3/components/FilterSelect/index.vue +179 -179
  110. package/dist/v3/components/JsonPretty/components/Brackets/index.vue +27 -27
  111. package/dist/v3/components/JsonPretty/components/Carets/index.vue +59 -59
  112. package/dist/v3/components/JsonPretty/components/CheckController/index.vue +136 -136
  113. package/dist/v3/components/JsonPretty/components/TreeNode/index.vue +387 -387
  114. package/dist/v3/components/JsonPretty/hooks/useClipboard.ts +21 -21
  115. package/dist/v3/components/JsonPretty/hooks/useError.ts +21 -21
  116. package/dist/v3/components/JsonPretty/type.ts +127 -127
  117. package/dist/v3/components/JsonPretty/utils/index.ts +169 -169
  118. package/dist/v3/components/MovableContainer/index.vue +8 -4
  119. package/dist/v3/components/Pick/index.vue +322 -322
  120. package/dist/v3/components/Tag/index.vue +113 -113
  121. package/dist/v3/components/VirtualList/AutoSize.vue +40 -40
  122. package/dist/v3/components/VirtualList/index.vue +416 -416
  123. package/dist/v3/hooks/useBluetooth/index.ts +561 -561
  124. package/dist/v3/hooks/useContainerStyle.ts +153 -153
  125. package/dist/v3/hooks/useNFC/index.ts +107 -107
  126. package/dist/v3/hooks/useNFC/typing.d.ts +396 -396
  127. package/dist/v3/hooks/useNFC/useNFCAndroid.ts +966 -966
  128. package/dist/v3/hooks/useNFC/useNFCMpWeiXin.ts +812 -812
  129. package/dist/v3/hooks/useNFC/utils.ts +754 -754
  130. package/dist/v3/hooks/useRequest/index.ts +586 -586
  131. package/dist/v3/hooks/useRequest/utils.ts +267 -267
  132. package/dist/v3/hooks/useScanCode/index.ts +206 -206
  133. package/dist/v3/hooks/useWebsocket/index.ts +253 -253
  134. package/dist/v3/styles/theme.ts +12 -12
  135. package/package.json +9 -1
@@ -1,387 +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
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>
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>