vite-uni-dev-tool 0.0.13 → 0.0.15

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 (130) hide show
  1. package/dist/core.js +1 -1
  2. package/dist/devIntercept/index.d.ts +3 -3
  3. package/dist/devIntercept/index.d.ts.map +1 -1
  4. package/dist/devIntercept/index.js +117 -114
  5. package/dist/plugins/uniDevTool/transform/transformApp.d.ts +32 -0
  6. package/dist/plugins/uniDevTool/transform/transformApp.d.ts.map +1 -0
  7. package/dist/plugins/uniDevTool/transform/transformApp.js +32 -0
  8. package/dist/plugins/uniDevTool/transform/transformMain.d.ts +26 -0
  9. package/dist/plugins/uniDevTool/transform/transformMain.d.ts.map +1 -0
  10. package/dist/plugins/uniDevTool/transform/transformMain.js +3 -0
  11. package/dist/plugins/uniDevTool/transform/transformVue.d.ts +41 -0
  12. package/dist/plugins/uniDevTool/transform/transformVue.d.ts.map +1 -0
  13. package/dist/plugins/uniDevTool/transform/transformVue.js +9 -0
  14. package/dist/plugins/uniDevTool/uniDevTool.d.ts +7 -3
  15. package/dist/plugins/uniDevTool/uniDevTool.d.ts.map +1 -1
  16. package/dist/plugins/uniDevTool/uniDevTool.js +3 -33
  17. package/dist/plugins/utils/index.d.ts +32 -0
  18. package/dist/plugins/utils/index.d.ts.map +1 -1
  19. package/dist/plugins/utils/index.js +1 -1
  20. package/dist/type.d.ts +2 -2
  21. package/dist/type.d.ts.map +1 -1
  22. package/dist/v2/AppInfo/index.vue +41 -0
  23. package/dist/v2/AutoSizer/index.vue +189 -0
  24. package/dist/v2/AutoSizer/index1.vue +193 -0
  25. package/dist/v2/AutoSizer/utils.ts +49 -0
  26. package/dist/v2/CaptureScreen/index.vue +78 -0
  27. package/dist/v2/CloseButton/index.vue +32 -0
  28. package/dist/v2/Connection/index.vue +94 -0
  29. package/dist/v2/ConsoleList/ConsoleItem.vue +235 -0
  30. package/dist/v2/ConsoleList/RunJSInput.vue +243 -0
  31. package/dist/v2/ConsoleList/index.vue +164 -0
  32. package/dist/v2/ConsoleList/staticTips.js +1144 -0
  33. package/dist/v2/DevTool/index.vue +162 -0
  34. package/dist/v2/DevToolButton/index.vue +228 -0
  35. package/dist/v2/DevToolTitle/index.vue +28 -0
  36. package/dist/v2/DevToolWindow/index.vue +1051 -0
  37. package/dist/v2/DeviceInfo/index.vue +48 -0
  38. package/dist/v2/Empty/empty.png +0 -0
  39. package/dist/v2/Empty/index.vue +40 -0
  40. package/dist/v2/FilterInput/index.vue +100 -0
  41. package/dist/v2/JsonPretty/components/Brackets/index.vue +30 -0
  42. package/dist/v2/JsonPretty/components/Carets/index.vue +65 -0
  43. package/dist/v2/JsonPretty/components/CheckController/index.vue +127 -0
  44. package/dist/v2/JsonPretty/components/TreeNode/index.vue +417 -0
  45. package/dist/v2/JsonPretty/hooks/useClipboard.ts +21 -0
  46. package/dist/v2/JsonPretty/hooks/useError.ts +21 -0
  47. package/dist/v2/JsonPretty/index.vue +531 -0
  48. package/dist/v2/JsonPretty/type.ts +125 -0
  49. package/dist/v2/JsonPretty/utils/index.js +211 -0
  50. package/dist/v2/NetworkList/NetworkDetail.vue +215 -0
  51. package/dist/v2/NetworkList/NetworkItem.vue +135 -0
  52. package/dist/v2/NetworkList/index.vue +148 -0
  53. package/dist/v2/PiniaList/index.vue +79 -0
  54. package/dist/v2/RouteList/index.vue +137 -0
  55. package/dist/v2/RunJS/index.vue +128 -0
  56. package/dist/v2/SettingList/index.vue +318 -0
  57. package/dist/v2/SourceCode/index.vue +237 -0
  58. package/dist/v2/StorageList/index.vue +165 -0
  59. package/dist/v2/SystemInfo/index.vue +49 -0
  60. package/dist/v2/Tabs/index.vue +127 -0
  61. package/dist/v2/Tag/index.vue +91 -0
  62. package/dist/v2/UniEvent/UniEventItem.vue +157 -0
  63. package/dist/v2/UniEvent/index.vue +127 -0
  64. package/dist/v2/UploadList/UploadDetail.vue +204 -0
  65. package/dist/v2/UploadList/UploadItem.vue +134 -0
  66. package/dist/v2/UploadList/index.vue +143 -0
  67. package/dist/v2/VirtualList/index.vue +140 -0
  68. package/dist/v2/VirtualListPro/AutoSize.vue +50 -0
  69. package/dist/v2/VirtualListPro/index.vue +255 -0
  70. package/dist/v2/VirtualListPro/readme.md +40 -0
  71. package/dist/v2/VuexList/index.vue +80 -0
  72. package/dist/v2/WebSocket/WebSocketItem.vue +129 -0
  73. package/dist/v2/WebSocket/WebSocketList.vue +183 -0
  74. package/dist/v2/WebSocket/index.vue +155 -0
  75. package/dist/v2/WindowInfo/index.vue +49 -0
  76. package/dist/v3/AppInfo/index.vue +35 -0
  77. package/dist/v3/AutoSizer/index.vue +193 -0
  78. package/dist/v3/AutoSizer/index1.vue +186 -0
  79. package/dist/v3/AutoSizer/utils.ts +49 -0
  80. package/dist/v3/CaptureScreen/index.vue +62 -0
  81. package/dist/v3/CloseButton/index.vue +29 -0
  82. package/dist/v3/Connection/index.vue +88 -0
  83. package/dist/v3/ConsoleList/ConsoleItem.vue +208 -0
  84. package/dist/v3/ConsoleList/RunJSInput.vue +240 -0
  85. package/dist/v3/ConsoleList/index.vue +139 -0
  86. package/dist/v3/ConsoleList/staticTips.ts +1145 -0
  87. package/dist/v3/DevTool/index.vue +217 -0
  88. package/dist/v3/DevToolButton/index.vue +210 -0
  89. package/dist/v3/DevToolTitle/index.vue +21 -0
  90. package/dist/v3/DevToolWindow/index.vue +1116 -0
  91. package/dist/v3/DeviceInfo/index.vue +32 -0
  92. package/dist/v3/Empty/empty.png +0 -0
  93. package/dist/v3/Empty/index.vue +28 -0
  94. package/dist/v3/FilterInput/index.vue +87 -0
  95. package/dist/v3/JsonPretty/components/Brackets/index.vue +23 -0
  96. package/dist/v3/JsonPretty/components/Carets/index.vue +59 -0
  97. package/dist/v3/JsonPretty/components/CheckController/index.vue +125 -0
  98. package/dist/v3/JsonPretty/components/TreeNode/index.vue +349 -0
  99. package/dist/v3/JsonPretty/hooks/useClipboard.ts +21 -0
  100. package/dist/v3/JsonPretty/hooks/useError.ts +21 -0
  101. package/dist/v3/JsonPretty/index.vue +476 -0
  102. package/dist/v3/JsonPretty/type.ts +125 -0
  103. package/dist/v3/JsonPretty/utils/index.ts +172 -0
  104. package/dist/v3/NetworkList/NetworkDetail.vue +194 -0
  105. package/dist/v3/NetworkList/NetworkItem.vue +120 -0
  106. package/dist/v3/NetworkList/index.vue +128 -0
  107. package/dist/v3/PiniaList/index.vue +64 -0
  108. package/dist/v3/RouteList/index.vue +121 -0
  109. package/dist/v3/RunJS/index.vue +128 -0
  110. package/dist/v3/SettingList/index.vue +313 -0
  111. package/dist/v3/SourceCode/index.vue +231 -0
  112. package/dist/v3/StorageList/index.vue +170 -0
  113. package/dist/v3/SystemInfo/index.vue +34 -0
  114. package/dist/v3/Tabs/index.vue +123 -0
  115. package/dist/v3/Tag/index.vue +89 -0
  116. package/dist/v3/UniEvent/UniEventItem.vue +126 -0
  117. package/dist/v3/UniEvent/index.vue +98 -0
  118. package/dist/v3/UploadList/UploadDetail.vue +192 -0
  119. package/dist/v3/UploadList/UploadItem.vue +117 -0
  120. package/dist/v3/UploadList/index.vue +117 -0
  121. package/dist/v3/VirtualList/index.vue +112 -0
  122. package/dist/v3/VirtualListPro/AutoSize.vue +43 -0
  123. package/dist/v3/VirtualListPro/index.vue +238 -0
  124. package/dist/v3/VirtualListPro/readme.md +40 -0
  125. package/dist/v3/VuexList/index.vue +54 -0
  126. package/dist/v3/WebSocket/WebSocketItem.vue +103 -0
  127. package/dist/v3/WebSocket/WebSocketList.vue +161 -0
  128. package/dist/v3/WebSocket/index.vue +124 -0
  129. package/dist/v3/WindowInfo/index.vue +33 -0
  130. package/package.json +1 -1
@@ -0,0 +1,32 @@
1
+ <template>
2
+ <view class="device-info-content">
3
+ <JsonPretty :data="deviceInfo" v-if="showJson" />
4
+ <Empty v-else />
5
+ </view>
6
+ </template>
7
+ <script lang="ts" setup>
8
+ import { computed } from 'vue';
9
+ import Empty from '../Empty/index.vue';
10
+ import JsonPretty from '../JsonPretty/index.vue';
11
+ const props = defineProps<{
12
+ deviceInfo: Record<string, any>;
13
+ }>();
14
+
15
+ const showJson = computed(() => {
16
+ try {
17
+ const str = JSON.stringify(props.deviceInfo);
18
+ if (typeof props.deviceInfo === 'object' && (str === '' || str === '{}')) {
19
+ return false;
20
+ }
21
+ return true;
22
+ } catch (error) {
23
+ return false;
24
+ }
25
+ });
26
+ </script>
27
+ <style>
28
+ .device-info-content {
29
+ padding: 16px;
30
+ font-size: var(--dev-tool-base-font-size);
31
+ }
32
+ </style>
Binary file
@@ -0,0 +1,28 @@
1
+ <template>
2
+ <view class="dev-tool-empty">
3
+ <image :src="empty" class="dev-tool-empty-image" />
4
+ <text class="dev-tool-empty-text">{{ text ?? '暂无调试信息' }}</text>
5
+ </view>
6
+ </template>
7
+ <script lang="ts" setup>
8
+ import empty from './empty.png';
9
+ defineProps<{ text?: string }>();
10
+ </script>
11
+ <style scoped>
12
+ .dev-tool-empty {
13
+ display: flex;
14
+ flex-direction: column;
15
+ justify-content: center;
16
+ align-items: center;
17
+ margin: 0 auto;
18
+ }
19
+ .dev-tool-empty-image {
20
+ margin-top: 50px;
21
+ width: 50px;
22
+ height: 50px;
23
+ }
24
+
25
+ .dev-tool-empty-text {
26
+ color: #888;
27
+ }
28
+ </style>
@@ -0,0 +1,87 @@
1
+ <template>
2
+ <view class="filter-input-wrapper">
3
+ <input
4
+ :class="`filter-input`"
5
+ :value="modelValue"
6
+ :placeholder="placeholder || '请输入'"
7
+ @confirm="debounceInput"
8
+ />
9
+ <view class="filter-input-clear" @click="onClear"> × </view>
10
+ </view>
11
+ </template>
12
+ <script lang="ts" setup>
13
+ import { debounce } from '../../utils';
14
+ import { ref, onMounted } from 'vue';
15
+ const props = defineProps<{
16
+ placeholder?: string;
17
+ modelValue?: string;
18
+ }>();
19
+ const emit = defineEmits<{
20
+ (e: 'update:modelValue', value: string): void;
21
+ (e: 'search', value: string): void;
22
+ (e: 'openSearch', value: boolean): void;
23
+ }>();
24
+
25
+ const isActive = ref(false);
26
+
27
+ function onInput(e: any) {
28
+ const value = e.detail.value;
29
+ emit('update:modelValue', value);
30
+ emit('search', value);
31
+ }
32
+
33
+ function onClear() {
34
+ emit('update:modelValue', '');
35
+ emit('search', '');
36
+ }
37
+
38
+ function openSearch(open: boolean) {
39
+ isActive.value = open;
40
+ emit('openSearch', open);
41
+ if (!open && props.modelValue) {
42
+ emit('update:modelValue', '');
43
+ emit('search', '');
44
+ }
45
+ }
46
+
47
+ const debounceInput = debounce(onInput, 500);
48
+ </script>
49
+ <style scoped>
50
+ .filter-input-wrapper {
51
+ flex: 1;
52
+ display: flex;
53
+ align-items: center;
54
+ padding: 0 8px;
55
+ width: 100%;
56
+ height: 24px;
57
+
58
+ border-radius: 4px;
59
+ border: 1px solid var(--dev-tool-border-color);
60
+
61
+ background-color: var(--dev-tool-bg-color);
62
+ transition: background-color 0.3s;
63
+ box-sizing: border-box;
64
+ }
65
+
66
+ .filter-input {
67
+ flex: 1;
68
+ box-shadow: none;
69
+ box-sizing: border-box;
70
+ border-radius: 5;
71
+ font-family: inherit;
72
+ color: var(--dev-tool-text-color);
73
+ font-weight: 400;
74
+ font: unset;
75
+ height: 24px;
76
+ transition: color 0.3s;
77
+ }
78
+
79
+ .filter-input-clear {
80
+ padding-left: 8px;
81
+ }
82
+
83
+ .filter-input-icon {
84
+ width: 24px;
85
+ height: 24px;
86
+ }
87
+ </style>
@@ -0,0 +1,23 @@
1
+ <template>
2
+ <view class="json-pretty-tree-brackets" @click="onClick">
3
+ {{ data }}
4
+ </view>
5
+ </template>
6
+ <script lang="ts" setup>
7
+ defineProps<{ data: string }>();
8
+ const emit = defineEmits<{
9
+ (e: 'click', event: MouseEvent): void;
10
+ }>();
11
+
12
+ function onClick(e: MouseEvent) {
13
+ emit('click', e);
14
+ }
15
+ </script>
16
+ <style>
17
+ .json-pretty-tree-brackets {
18
+ cursor: pointer;
19
+ }
20
+ .json-pretty-tree-brackets:hover {
21
+ color: var(--json-pretty-primary-color);
22
+ }
23
+ </style>
@@ -0,0 +1,59 @@
1
+ <template>
2
+ <view
3
+ v-if="isOpen || isClose"
4
+ :class="`json-pretty-carets json-pretty-carets-${
5
+ isOpen ? 'open' : 'close'
6
+ }`"
7
+ @click="onClick"
8
+ >
9
+ <view class="json-pretty-caret-down"></view>
10
+ </view>
11
+ </template>
12
+ <script lang="ts" setup>
13
+ import { computed } from 'vue';
14
+ // import "./styles.less";
15
+ const props = defineProps<{ nodeType: string }>();
16
+ const emit = defineEmits<{
17
+ (e: 'click', event: MouseEvent): void;
18
+ }>();
19
+
20
+ const isOpen = computed(() => {
21
+ return props.nodeType === 'objectStart' || props.nodeType === 'arrayStart';
22
+ });
23
+
24
+ const isClose = computed(() => {
25
+ return (
26
+ props.nodeType === 'objectCollapsed' || props.nodeType === 'arrayCollapsed'
27
+ );
28
+ });
29
+
30
+ function onClick(e: MouseEvent) {
31
+ emit('click', e);
32
+ }
33
+ </script>
34
+ <style>
35
+ .json-pretty-carets {
36
+ position: absolute;
37
+ right: 0;
38
+ cursor: pointer;
39
+ }
40
+ .json-pretty-carets svg {
41
+ transition: transform 0.3s;
42
+ }
43
+
44
+ .json-pretty-carets::hover {
45
+ color: var(--json-pretty-primary-color);
46
+ }
47
+
48
+ .json-pretty-carets-close {
49
+ transform: rotate(-90deg);
50
+ }
51
+
52
+ .json-pretty-caret-down {
53
+ margin: 7px 4px;
54
+ border: 3px solid #000;
55
+ border-top-color: transparent;
56
+ border-left-color: transparent;
57
+ transform: rotate(45deg);
58
+ }
59
+ </style>
@@ -0,0 +1,125 @@
1
+ <template>
2
+ <view
3
+ :class="`json-pretty-check-controller ${model ? 'is-checked' : ''}`"
4
+ @click="onClick"
5
+ >
6
+ <!-- <view
7
+ :class="`json-pretty-check-controller-inner is-${uiType}`"
8
+ @click="onChange"
9
+ >
10
+ </view>
11
+ <input
12
+ :checked="model"
13
+ :class="`json-pretty-check-controller-original is-${uiType}`"
14
+ :type="uiType"
15
+ @change="onChange"
16
+ /> -->
17
+
18
+ <checkbox
19
+ v-if="uiType === 'checkbox'"
20
+ :checked="model"
21
+ style="transform: scale(0.6)"
22
+ @change="onChange"
23
+ />
24
+ <radio
25
+ v-if="uiType === 'radio'"
26
+ :checked="model"
27
+ style="transform: scale(0.6)"
28
+ @change="onChange"
29
+ />
30
+ </view>
31
+ </template>
32
+ <script lang="ts" setup>
33
+ import { computed } from 'vue';
34
+ const props = defineProps<{ checked: boolean; isMultiple: boolean }>();
35
+ const emit = defineEmits<{
36
+ (e: 'change', value: boolean): void;
37
+ (e: 'update:modelValue', value: boolean): void;
38
+ }>();
39
+
40
+ const uiType = computed(() => (props.isMultiple ? 'checkbox' : 'radio'));
41
+ const model = computed({
42
+ get: (): boolean => props.checked,
43
+ set: (val) => emit('update:modelValue', val),
44
+ });
45
+
46
+ function onChange() {
47
+ emit('change', !model.value);
48
+ }
49
+
50
+ function onClick(e: MouseEvent) {
51
+ e.stopPropagation();
52
+ }
53
+ </script>
54
+
55
+ <style>
56
+ .json-pretty-check-controller {
57
+ position: absolute;
58
+ left: 0;
59
+ }
60
+ .json-pretty-check-controller.is-checked .json-pretty-check-controller-inner {
61
+ background-color: var(--json-pretty-color-primary);
62
+ border-color: var(--json-pretty-color-primary);
63
+ }
64
+ .json-pretty-check-controller.is-checked
65
+ .json-pretty-check-controller-inner.is-checkbox:after {
66
+ transform: rotate(45deg) scaleY(1);
67
+ }
68
+ .json-pretty-check-controller.is-checked
69
+ .json-pretty-check-controller-inner.is-radio:after {
70
+ transform: translate(-50%, -50%) scale(1);
71
+ }
72
+ .json-pretty-check-controller .json-pretty-check-controller-inner {
73
+ display: inline-block;
74
+ position: relative;
75
+ border: 1px solid var(--json-pretty-border-color);
76
+ border-radius: 2px;
77
+ vertical-align: middle;
78
+ box-sizing: border-box;
79
+ width: 16px;
80
+ height: 16px;
81
+ background-color: #fff;
82
+ z-index: 1;
83
+ cursor: pointer;
84
+ transition:
85
+ border-color 0.25s cubic-bezier(0.71, -0.46, 0.29, 1.46),
86
+ background-color 0.25s cubic-bezier(0.71, -0.46, 0.29, 1.46);
87
+ }
88
+ .json-pretty-check-controller .json-pretty-check-controller-inner:after {
89
+ box-sizing: content-box;
90
+ content: '';
91
+ border: 2px solid #fff;
92
+ border-left: 0;
93
+ border-top: 0;
94
+ height: 8px;
95
+ left: 4px;
96
+ position: absolute;
97
+ top: 1px;
98
+ transform: rotate(45deg) scaleY(0);
99
+ width: 4px;
100
+ transition: transform 0.15s cubic-bezier(0.71, -0.46, 0.88, 0.6) 0.05s;
101
+ transform-origin: center;
102
+ }
103
+ .json-pretty-check-controller .json-pretty-check-controller-inner.is-radio {
104
+ border-radius: 100%;
105
+ }
106
+ .json-pretty-check-controller
107
+ .json-pretty-check-controller-inner.is-radio:after {
108
+ border-radius: 100%;
109
+ height: 4px;
110
+ background-color: #fff;
111
+ left: 50%;
112
+ top: 50%;
113
+ }
114
+ .json-pretty-check-controller .json-pretty-check-controller-original {
115
+ opacity: 0;
116
+ outline: none;
117
+ position: absolute;
118
+ z-index: -1;
119
+ top: 0;
120
+ left: 0;
121
+ right: 0;
122
+ bottom: 0;
123
+ margin: 0;
124
+ }
125
+ </style>
@@ -0,0 +1,349 @@
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="style"
14
+ >
15
+ <view v-if="showLineNumber" class="json-pretty-node-index">
16
+ {{ node.id + 1 }}
17
+ </view>
18
+
19
+ <CheckController
20
+ v-if="
21
+ showSelectController &&
22
+ selectable &&
23
+ node.type !== 'objectEnd' &&
24
+ node.type !== 'arrayEnd'
25
+ "
26
+ :isMultiple="isMultiple"
27
+ :checked="checked"
28
+ @change="handleSelectedChange"
29
+ />
30
+
31
+ <view class="json-pretty-indent">
32
+ <view
33
+ v-for="(item, index) in Array(node.level)"
34
+ :key="index"
35
+ :class="{
36
+ 'json-pretty-indent-unit': true,
37
+ 'has-line': showLine,
38
+ }"
39
+ >
40
+ <view v-for="() in Array(indent)" :key="Math.random()">&nbsp;</view>
41
+ </view>
42
+ <Carets v-if="showIcon" :nodeType="node.type" @click="handleIconClick" />
43
+ </view>
44
+
45
+ <view v-if="node.key" class="json-pretty-key">
46
+ <slot name="render-node-key" :node="props.node" :default-key="prettyKey">
47
+ {{ prettyKey }}
48
+ </slot>
49
+ <view class="json-pretty-colon">
50
+ {{ `:${showKeyValueSpace ? ' ' : ''}` }}
51
+ </view>
52
+ </view>
53
+
54
+ <view class="json-pretty-value-wrapper">
55
+ <Brackets
56
+ v-if="node.type !== 'content' && node.content"
57
+ :data="node.content.toString()"
58
+ @click="handleBracketsClick"
59
+ />
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
+ />
69
+ <view v-else>
70
+ <slot
71
+ name="render-node-value"
72
+ :node="props.node"
73
+ :default-value="defaultValue"
74
+ >
75
+ {{ defaultValue }}
76
+ </slot>
77
+ <text v-if="node.showComma">,</text>
78
+ </view>
79
+ </view>
80
+
81
+ <view v-if="showLength && collapsed" class="json-pretty-comment">
82
+ // {{ node.length }} items
83
+ </view>
84
+ </view>
85
+ <view class="json-pretty-tree-node-actions" v-if="showNodeActions">
86
+ <slot name="render-node-actions" :copy="handleCopy">
87
+ <view @click="handleCopy" class="json-pretty-tree-node-actions-item">
88
+ copy
89
+ </view>
90
+ </slot>
91
+ </view>
92
+ </view>
93
+ </template>
94
+
95
+ <script lang="ts" setup>
96
+ import { reactive, computed } from 'vue';
97
+ import Brackets from '../Brackets/index.vue';
98
+ import CheckController from '../CheckController/index.vue';
99
+ import Carets from '../Carets/index.vue';
100
+ import { getDataType, isFunction, stringToAutoType } from '../../utils';
101
+
102
+ import type { NodeDataType, TreeNodeProps } from '../../type';
103
+ import { getValueByPath } from '../../../../utils';
104
+
105
+ const props = withDefaults(defineProps<TreeNodeProps>(), {
106
+ rootPath: 'root',
107
+ indent: 2,
108
+ showDoubleQuotes: true,
109
+ showLine: true,
110
+ selectOnClickNode: true,
111
+ highlightSelectedNode: true,
112
+ theme: 'light',
113
+ showKeyValueSpace: true,
114
+ editableTrigger: 'click',
115
+ checked: false,
116
+ nodeSelectable: () => false,
117
+ });
118
+
119
+ const emit = defineEmits<{
120
+ (e: 'nodeClick', node: NodeDataType): void;
121
+ (e: 'nodeMouseover', node: NodeDataType): void;
122
+ (e: 'bracketsClick', collapsed: boolean, node: NodeDataType): void;
123
+ (e: 'iconClick', collapsed: boolean, node: NodeDataType): void;
124
+ (e: 'selectedChange', node: NodeDataType): void;
125
+ (e: 'valueChange', value: any, path: string): void;
126
+ }>();
127
+
128
+ const dataType = computed<string>(() => getDataType(props.node.content));
129
+
130
+ const valueClass = computed(
131
+ () => `json-pretty-value json-pretty-value-${dataType.value}`,
132
+ );
133
+
134
+ const prettyKey = computed(() =>
135
+ props.showDoubleQuotes ? `"${props.node.key}"` : props.node.key,
136
+ );
137
+
138
+ const isMultiple = computed(() => props.selectableType === 'multiple');
139
+
140
+ const isSingle = computed(() => props.selectableType === 'single');
141
+
142
+ const selectable = computed(
143
+ () =>
144
+ isFunction(props?.nodeSelectable) &&
145
+ props?.nodeSelectable?.(props.node) &&
146
+ (isMultiple.value || isSingle.value),
147
+ );
148
+
149
+ const state = reactive({
150
+ editing: false,
151
+ });
152
+
153
+ const handleInputBlur = (e: FocusEvent) => {
154
+ const source = (e.detail as any).value;
155
+ const value = stringToAutoType(source);
156
+ emit('valueChange', value, props.node.path);
157
+ state.editing = false;
158
+ };
159
+
160
+ const defaultValue = computed(() => {
161
+ let value = props.node?.content;
162
+ if (value === null) {
163
+ value = 'null';
164
+ } else if (value === undefined) {
165
+ value = 'undefined';
166
+ }
167
+ return dataType.value === 'string' ? `"${value}"` : value?.toString();
168
+ });
169
+
170
+ const handleBracketsClick = () => {
171
+ emit('bracketsClick', !props.collapsed, props.node);
172
+ };
173
+
174
+ const handleIconClick = () => {
175
+ emit('iconClick', !props.collapsed, props.node);
176
+ };
177
+
178
+ const handleSelectedChange = () => {
179
+ emit('selectedChange', props.node);
180
+ };
181
+
182
+ const handleNodeClick = () => {
183
+ emit('nodeClick', props.node);
184
+ if (selectable.value && props.selectOnClickNode) {
185
+ emit('selectedChange', props.node);
186
+ }
187
+ };
188
+
189
+ const handleNodeMouseover = () => {
190
+ emit('nodeMouseover', props.node);
191
+ };
192
+
193
+ const handleValueEdit = (e: MouseEvent) => {
194
+ if (!props.editable) return;
195
+
196
+ if (!state.editing) {
197
+ state.editing = true;
198
+ }
199
+ };
200
+
201
+ const handleCopy = () => {
202
+ const { key, path } = props.node;
203
+ const rootPath = props.rootPath;
204
+
205
+ const content = getValueByPath(props.data, path.slice(rootPath.length));
206
+
207
+ const copiedData = JSON.stringify(
208
+ key ? { [key]: content } : content,
209
+ null,
210
+ 2,
211
+ );
212
+
213
+ uni.setClipboardData({
214
+ data: copiedData,
215
+ success() {
216
+ uni.showToast({
217
+ title: '复制成功',
218
+ icon: 'none',
219
+ });
220
+ },
221
+ fail() {
222
+ uni.showToast({
223
+ title: '复制失败',
224
+ icon: 'none',
225
+ });
226
+ },
227
+ });
228
+ };
229
+ </script>
230
+ <style scoped>
231
+ .json-pretty-tree-node {
232
+ display: flex;
233
+ /* align-items: center; */
234
+ position: relative;
235
+ line-height: 20px;
236
+ }
237
+ .json-pretty-tree-node.has-carets {
238
+ padding-left: 15px;
239
+ }
240
+ .json-pretty-tree-node.has-selector,
241
+ .json-pretty-tree-node.has-carets.has-selector {
242
+ padding-left: 30px;
243
+ }
244
+ .json-pretty-tree-node.is-highlight,
245
+ .json-pretty-tree-node:hover {
246
+ background-color: var(--json-pretty-highlight-bg-color);
247
+ border-radius: 4px;
248
+ }
249
+ .json-pretty-tree-node.is-highlight .json-pretty-tree-node-actions,
250
+ .json-pretty-tree-node:hover .json-pretty-tree-node-actions {
251
+ display: block;
252
+ }
253
+ .json-pretty-tree-node .json-pretty-indent {
254
+ display: flex;
255
+ position: relative;
256
+ }
257
+ .json-pretty-tree-node .json-pretty-indent-unit {
258
+ display: flex;
259
+ }
260
+ .json-pretty-tree-node .json-pretty-indent-unit.has-line {
261
+ border-left: 1px dashed var(--json-pretty-border-color);
262
+ }
263
+ .json-pretty-tree-node .json-pretty-tree-node-actions {
264
+ display: none;
265
+ position: absolute;
266
+ right: 0;
267
+ top: 0;
268
+ padding: 0 4px;
269
+ background-color: var(--json-pretty-highlight-bg-color);
270
+ border-radius: 4px;
271
+ }
272
+ .json-pretty-tree-node
273
+ .json-pretty-tree-node-actions
274
+ .json-pretty-tree-node-actions-item {
275
+ cursor: pointer;
276
+ }
277
+ .json-pretty-tree-node
278
+ .json-pretty-tree-node-actions
279
+ .json-pretty-tree-node-actions-item:hover {
280
+ color: var(--json-pretty-color-primary);
281
+ }
282
+ .json-pretty-tree-node.dark.is-highlight,
283
+ .json-pretty-tree-node.dark:hover {
284
+ background-color: var(--json-pretty-highlight-bg-color-dark);
285
+ }
286
+ .json-pretty-tree-node.dark .json-pretty-tree-node-actions {
287
+ background-color: var(--json-pretty-highlight-bg-color-dark);
288
+ }
289
+ .json-pretty-tree-node-active {
290
+ background-color: var(--json-pretty-highlight-bg-color);
291
+ border-radius: 4px;
292
+ }
293
+ .json-pretty-tree-node-active .json-pretty-tree-node-actions {
294
+ display: block;
295
+ }
296
+ .json-pretty-node-index {
297
+ position: absolute;
298
+ right: 100%;
299
+ margin-right: 4px;
300
+ user-select: none;
301
+ }
302
+ .json-pretty-colon {
303
+ white-space: pre;
304
+ }
305
+ .json-pretty-comment {
306
+ color: var(--json-pretty-color-primary);
307
+ }
308
+ .json-pretty-key {
309
+ display: flex;
310
+ }
311
+ .json-pretty-value-wrapper {
312
+ display: flex;
313
+ align-items: center;
314
+ }
315
+ .json-pretty-value {
316
+ word-break: break-all;
317
+ white-space: normal;
318
+ /* white-space: pre-line; */
319
+ /* white-space: nowrap; */
320
+ }
321
+ .json-pretty-value-null {
322
+ color: var(--json-pretty-color-null);
323
+ }
324
+ .json-pretty-value-undefined {
325
+ color: var(--json-pretty-color-undefined);
326
+ }
327
+ .json-pretty-value-number {
328
+ color: var(--json-pretty-color-number);
329
+ }
330
+ .json-pretty-value-boolean {
331
+ color: var(--json-pretty-color-boolean);
332
+ }
333
+ .json-pretty-value-string {
334
+ color: var(--json-pretty-color-string);
335
+ }
336
+ .json-pretty-edit-input {
337
+ padding: 0px 8px;
338
+ border: 1px solid #eee;
339
+ box-shadow: none;
340
+ box-sizing: border-box;
341
+ border-radius: 5;
342
+ font-family: inherit;
343
+ color: #000;
344
+ font-weight: 400;
345
+ background-color: #fff;
346
+ font: unset;
347
+ height: 16px;
348
+ }
349
+ </style>