@jsonup/vue 0.0.1
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/LICENSE +21 -0
- package/README.md +49 -0
- package/dist/index.d.ts +274 -0
- package/dist/index.js +1024 -0
- package/dist/style.css +144 -0
- package/package.json +61 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Michael Cocova
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
# @jsonup/vue
|
|
2
|
+
|
|
3
|
+
供 `jsonup` JSON 查看器使用的 Vue 3 适配器和组件。
|
|
4
|
+
|
|
5
|
+
## 特性
|
|
6
|
+
|
|
7
|
+
- **Vue 3 集成**:提供 `<JsonupViewer />` 组件和 `useJsonDocument` 组合式函数。
|
|
8
|
+
- **高性能**:内置支持通过虚拟滚动(由 `virtua` 驱动)平滑渲染 10w+ 级 JSON 节点。
|
|
9
|
+
- **交互性**:支持节点的展开/折叠、选中和复制。
|
|
10
|
+
- **高度可定制**:提供插槽,用于深度定制行、属性和值的渲染。
|
|
11
|
+
|
|
12
|
+
## 安装
|
|
13
|
+
|
|
14
|
+
```bash
|
|
15
|
+
npm install @jsonup/vue @jsonup/core @jsonup/themes
|
|
16
|
+
# 或
|
|
17
|
+
pnpm add @jsonup/vue @jsonup/core @jsonup/themes
|
|
18
|
+
# 或
|
|
19
|
+
yarn add @jsonup/vue @jsonup/core @jsonup/themes
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
## 基础用法
|
|
23
|
+
|
|
24
|
+
```vue
|
|
25
|
+
<script setup>
|
|
26
|
+
import { githubLight } from "@jsonup/themes";
|
|
27
|
+
import { JsonupViewer } from "@jsonup/vue";
|
|
28
|
+
|
|
29
|
+
// 引入样式
|
|
30
|
+
import "@jsonup/vue/style.css";
|
|
31
|
+
|
|
32
|
+
const data = {
|
|
33
|
+
hello: "world",
|
|
34
|
+
items: [1, 2, 3],
|
|
35
|
+
};
|
|
36
|
+
</script>
|
|
37
|
+
|
|
38
|
+
<template>
|
|
39
|
+
<JsonupViewer :data="data" :theme="githubLight" virtual />
|
|
40
|
+
</template>
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
## 文档
|
|
44
|
+
|
|
45
|
+
如需获取完整文档、API 详细信息以及更多示例,请访问 [jsonup 官方文档](https://github.com/cocoa/jsonup)。
|
|
46
|
+
|
|
47
|
+
## 许可证
|
|
48
|
+
|
|
49
|
+
[MIT](../../LICENSE)
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,274 @@
|
|
|
1
|
+
import { CreateDocumentOptions, JsonDocument, JsonInput, JsonNode, JsonNodeId, JsonNodeIdentity } from "@jsonup/core";
|
|
2
|
+
import { InsertInput, MoveOptions } from "@jsonup/operation";
|
|
3
|
+
import { PropType, SlotsType, VNodeChild } from "vue";
|
|
4
|
+
import { JsonupTheme } from "@jsonup/themes";
|
|
5
|
+
|
|
6
|
+
//#region src/viewer-lines.d.ts
|
|
7
|
+
/**
|
|
8
|
+
* Jsonup 查看器行类型
|
|
9
|
+
* - `open`: 展开容器的起始行(包含起始括号)
|
|
10
|
+
* - `property`: 属性行(包含键值对)
|
|
11
|
+
* - `close`: 展开容器的结束行(包含结束括号)
|
|
12
|
+
* - `collapsed`: 折叠的容器行
|
|
13
|
+
*/
|
|
14
|
+
type JsonupViewerLineKind = 'open' | 'property' | 'close' | 'collapsed';
|
|
15
|
+
/**
|
|
16
|
+
* Jsonup 查看器行接口定义
|
|
17
|
+
*/
|
|
18
|
+
interface JsonupViewerLine {
|
|
19
|
+
/** 行的唯一标识符 */
|
|
20
|
+
id: string;
|
|
21
|
+
/** 行的类型 */
|
|
22
|
+
kind: JsonupViewerLineKind;
|
|
23
|
+
/** 关联的 JSON 节点 */
|
|
24
|
+
node: JsonNode;
|
|
25
|
+
/** 节点在树中的深度 */
|
|
26
|
+
depth: number;
|
|
27
|
+
/** 行的纯文本内容 */
|
|
28
|
+
text: string;
|
|
29
|
+
/** 行号(从 1 开始) */
|
|
30
|
+
lineNumber: number;
|
|
31
|
+
/** 行是否可交互(例如点击展开/折叠) */
|
|
32
|
+
interactive: boolean;
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* 基于可见节点创建查看器行数组
|
|
36
|
+
* @param document JSON 文档对象
|
|
37
|
+
* @param visibleNodes 可见的 JSON 节点数组
|
|
38
|
+
* @returns 生成的查看器行数组
|
|
39
|
+
*/
|
|
40
|
+
declare function createViewerLines(document: JsonDocument, visibleNodes: JsonNode[]): JsonupViewerLine[];
|
|
41
|
+
//#endregion
|
|
42
|
+
//#region src/JsonupViewer.d.ts
|
|
43
|
+
/**
|
|
44
|
+
* 查看器行插槽的属性接口
|
|
45
|
+
*/
|
|
46
|
+
interface JsonupViewerLineSlotProps {
|
|
47
|
+
/** 当前行对象 */
|
|
48
|
+
line: JsonupViewerLine;
|
|
49
|
+
/** 行的纯文本内容 */
|
|
50
|
+
text: string;
|
|
51
|
+
/** 行号(从 1 开始) */
|
|
52
|
+
lineNumber: number;
|
|
53
|
+
/** 切换节点展开/折叠状态的函数 */
|
|
54
|
+
toggle: () => void;
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* JSON 树形查看器组件
|
|
58
|
+
*/
|
|
59
|
+
declare const JsonupViewer: import("vue").DefineComponent<import("vue").ExtractPropTypes<{
|
|
60
|
+
/** 传入的 JSON 数据或已创建的 JSON 文档对象 */data: {
|
|
61
|
+
type: PropType<JsonInput | JsonDocument>;
|
|
62
|
+
required: true;
|
|
63
|
+
}; /** 是否显示行号 */
|
|
64
|
+
lineNumbers: {
|
|
65
|
+
type: BooleanConstructor;
|
|
66
|
+
default: boolean;
|
|
67
|
+
}; /** 是否开启虚拟滚动 */
|
|
68
|
+
virtual: {
|
|
69
|
+
type: BooleanConstructor;
|
|
70
|
+
default: boolean;
|
|
71
|
+
}; /** 默认是否展开根节点 */
|
|
72
|
+
defaultExpandedRoot: {
|
|
73
|
+
type: BooleanConstructor;
|
|
74
|
+
default: boolean;
|
|
75
|
+
}; /** 默认是否展开所有节点 */
|
|
76
|
+
defaultExpandedAll: {
|
|
77
|
+
type: BooleanConstructor;
|
|
78
|
+
default: boolean;
|
|
79
|
+
}; /** 默认展开的深度 */
|
|
80
|
+
defaultExpandedDepth: {
|
|
81
|
+
type: PropType<number | true>;
|
|
82
|
+
default: undefined;
|
|
83
|
+
}; /** 默认展开的节点路径集合 */
|
|
84
|
+
expandedPaths: {
|
|
85
|
+
type: PropType<Iterable<string>>;
|
|
86
|
+
default: undefined;
|
|
87
|
+
}; /** 节点的身份标识树,用于保持节点状态 */
|
|
88
|
+
identityTree: {
|
|
89
|
+
type: PropType<JsonNodeIdentity>;
|
|
90
|
+
default: undefined;
|
|
91
|
+
}; /** 是否克隆原始数据(避免修改原对象) */
|
|
92
|
+
cloneRaw: {
|
|
93
|
+
type: BooleanConstructor;
|
|
94
|
+
default: boolean;
|
|
95
|
+
}; /** 主题配置对象 */
|
|
96
|
+
theme: {
|
|
97
|
+
type: PropType<JsonupTheme | null>;
|
|
98
|
+
default: null;
|
|
99
|
+
}; /** 是否开启单词换行 */
|
|
100
|
+
wordWrap: {
|
|
101
|
+
type: BooleanConstructor;
|
|
102
|
+
default: boolean;
|
|
103
|
+
};
|
|
104
|
+
}>, () => import("vue").VNode<import("vue").RendererNode, import("vue").RendererElement, {
|
|
105
|
+
[key: string]: any;
|
|
106
|
+
}>, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").PublicProps, Readonly<import("vue").ExtractPropTypes<{
|
|
107
|
+
/** 传入的 JSON 数据或已创建的 JSON 文档对象 */data: {
|
|
108
|
+
type: PropType<JsonInput | JsonDocument>;
|
|
109
|
+
required: true;
|
|
110
|
+
}; /** 是否显示行号 */
|
|
111
|
+
lineNumbers: {
|
|
112
|
+
type: BooleanConstructor;
|
|
113
|
+
default: boolean;
|
|
114
|
+
}; /** 是否开启虚拟滚动 */
|
|
115
|
+
virtual: {
|
|
116
|
+
type: BooleanConstructor;
|
|
117
|
+
default: boolean;
|
|
118
|
+
}; /** 默认是否展开根节点 */
|
|
119
|
+
defaultExpandedRoot: {
|
|
120
|
+
type: BooleanConstructor;
|
|
121
|
+
default: boolean;
|
|
122
|
+
}; /** 默认是否展开所有节点 */
|
|
123
|
+
defaultExpandedAll: {
|
|
124
|
+
type: BooleanConstructor;
|
|
125
|
+
default: boolean;
|
|
126
|
+
}; /** 默认展开的深度 */
|
|
127
|
+
defaultExpandedDepth: {
|
|
128
|
+
type: PropType<number | true>;
|
|
129
|
+
default: undefined;
|
|
130
|
+
}; /** 默认展开的节点路径集合 */
|
|
131
|
+
expandedPaths: {
|
|
132
|
+
type: PropType<Iterable<string>>;
|
|
133
|
+
default: undefined;
|
|
134
|
+
}; /** 节点的身份标识树,用于保持节点状态 */
|
|
135
|
+
identityTree: {
|
|
136
|
+
type: PropType<JsonNodeIdentity>;
|
|
137
|
+
default: undefined;
|
|
138
|
+
}; /** 是否克隆原始数据(避免修改原对象) */
|
|
139
|
+
cloneRaw: {
|
|
140
|
+
type: BooleanConstructor;
|
|
141
|
+
default: boolean;
|
|
142
|
+
}; /** 主题配置对象 */
|
|
143
|
+
theme: {
|
|
144
|
+
type: PropType<JsonupTheme | null>;
|
|
145
|
+
default: null;
|
|
146
|
+
}; /** 是否开启单词换行 */
|
|
147
|
+
wordWrap: {
|
|
148
|
+
type: BooleanConstructor;
|
|
149
|
+
default: boolean;
|
|
150
|
+
};
|
|
151
|
+
}>> & Readonly<{}>, {
|
|
152
|
+
lineNumbers: boolean;
|
|
153
|
+
virtual: boolean;
|
|
154
|
+
defaultExpandedRoot: boolean;
|
|
155
|
+
defaultExpandedAll: boolean;
|
|
156
|
+
defaultExpandedDepth: number | true;
|
|
157
|
+
expandedPaths: Iterable<string>;
|
|
158
|
+
identityTree: JsonNodeIdentity;
|
|
159
|
+
cloneRaw: boolean;
|
|
160
|
+
theme: JsonupTheme | null;
|
|
161
|
+
wordWrap: boolean;
|
|
162
|
+
}, SlotsType<{
|
|
163
|
+
/** 自定义所有类型行的渲染,优先级低于特定类型的插槽 */line?: (props: JsonupViewerLineSlotProps) => VNodeChild; /** 自定义展开起始行的渲染 */
|
|
164
|
+
open?: (props: JsonupViewerLineSlotProps) => VNodeChild; /** 自定义属性行的渲染 */
|
|
165
|
+
property?: (props: JsonupViewerLineSlotProps) => VNodeChild; /** 自定义展开结束行的渲染 */
|
|
166
|
+
close?: (props: JsonupViewerLineSlotProps) => VNodeChild; /** 自定义折叠行的渲染 */
|
|
167
|
+
collapsed?: (props: JsonupViewerLineSlotProps) => VNodeChild; /** 自定义行号的渲染 */
|
|
168
|
+
lineNumber?: (props: JsonupViewerLineSlotProps) => VNodeChild;
|
|
169
|
+
}>, {}, {}, string, import("vue").ComponentProvideOptions, true, {}, any>;
|
|
170
|
+
//#endregion
|
|
171
|
+
//#region src/index.d.ts
|
|
172
|
+
/**
|
|
173
|
+
* useJsonDocument 组合式函数的选项接口
|
|
174
|
+
*/
|
|
175
|
+
interface UseJsonDocumentOptions extends CreateDocumentOptions {}
|
|
176
|
+
/**
|
|
177
|
+
* 用于管理和操作 JSON 文档的 Vue 组合式函数
|
|
178
|
+
* @param input 初始 JSON 输入数据或已存在的 JSON 文档
|
|
179
|
+
* @param options 创建文档时的配置选项
|
|
180
|
+
* @returns 包含文档状态和一系列操作方法的对象
|
|
181
|
+
*/
|
|
182
|
+
declare function useJsonDocument(input: JsonInput | JsonDocument, options?: UseJsonDocumentOptions): {
|
|
183
|
+
/** 当前的 JSON 文档对象 */document: import("vue").ShallowRef<JsonDocument, JsonDocument>; /** 文档中的所有节点列表 */
|
|
184
|
+
nodes: import("vue").ComputedRef<import("@jsonup/core").JsonNode[]>; /** 当前处于可见状态的节点列表(父节点已展开的节点) */
|
|
185
|
+
visibleNodes: import("vue").ComputedRef<import("@jsonup/core").JsonNode[]>; /** 当前已展开节点的路径集合 */
|
|
186
|
+
expandedPaths: import("vue").ComputedRef<Set<string>>;
|
|
187
|
+
/**
|
|
188
|
+
* 设置新的文档数据
|
|
189
|
+
* @param nextInput 新的 JSON 输入数据或文档
|
|
190
|
+
* @returns 新创建的 JSON 文档对象
|
|
191
|
+
*/
|
|
192
|
+
setDocument: (nextInput: JsonInput | JsonDocument) => JsonDocument;
|
|
193
|
+
/**
|
|
194
|
+
* 重置文档数据(等同于 setDocument)
|
|
195
|
+
* @param nextInput 新的 JSON 输入数据或文档
|
|
196
|
+
* @returns 新创建的 JSON 文档对象
|
|
197
|
+
*/
|
|
198
|
+
reset: (nextInput: JsonInput | JsonDocument) => JsonDocument; /** 文档的当前内部状态 */
|
|
199
|
+
state: import("vue").ComputedRef<import("@jsonup/core").JsonDocumentState>;
|
|
200
|
+
/**
|
|
201
|
+
* 切换指定节点的展开/折叠状态
|
|
202
|
+
* @param id 节点 ID
|
|
203
|
+
* @param expanded 可选的强制状态,true 为展开,false 为折叠
|
|
204
|
+
* @returns 更新后的 JSON 文档对象
|
|
205
|
+
*/
|
|
206
|
+
toggleExpanded: (id: JsonNodeId, expanded?: boolean) => JsonDocument;
|
|
207
|
+
/**
|
|
208
|
+
* 更新指定节点的值
|
|
209
|
+
* @param id 节点 ID
|
|
210
|
+
* @param value 新的节点值
|
|
211
|
+
* @returns 更新后的 JSON 文档对象
|
|
212
|
+
*/
|
|
213
|
+
updateValue: (id: JsonNodeId, value: unknown) => JsonDocument;
|
|
214
|
+
/**
|
|
215
|
+
* 在指定位置插入新节点
|
|
216
|
+
* @param id 目标节点 ID
|
|
217
|
+
* @param inputValue 要插入的输入值配置
|
|
218
|
+
* @returns 更新后的 JSON 文档对象
|
|
219
|
+
*/
|
|
220
|
+
insert: (id: JsonNodeId, inputValue: InsertInput) => JsonDocument;
|
|
221
|
+
/**
|
|
222
|
+
* 移除指定节点
|
|
223
|
+
* @param id 节点 ID
|
|
224
|
+
* @returns 更新后的 JSON 文档对象
|
|
225
|
+
*/
|
|
226
|
+
remove: (id: JsonNodeId) => JsonDocument;
|
|
227
|
+
/**
|
|
228
|
+
* 移动节点到新的父节点下
|
|
229
|
+
* @param id 要移动的节点 ID
|
|
230
|
+
* @param parentId 目标父节点 ID
|
|
231
|
+
* @param options 移动操作的高级选项
|
|
232
|
+
* @returns 更新后的 JSON 文档对象
|
|
233
|
+
*/
|
|
234
|
+
move: (id: JsonNodeId, parentId: JsonNodeId, options?: MoveOptions) => JsonDocument;
|
|
235
|
+
/**
|
|
236
|
+
* 重命名节点键名(仅针对对象属性)
|
|
237
|
+
* @param id 节点 ID
|
|
238
|
+
* @param nextKey 新的键名
|
|
239
|
+
* @returns 更新后的 JSON 文档对象
|
|
240
|
+
*/
|
|
241
|
+
renameKey: (id: JsonNodeId, nextKey: string) => JsonDocument;
|
|
242
|
+
/**
|
|
243
|
+
* 根据 ID 获取节点
|
|
244
|
+
* @param id 节点 ID
|
|
245
|
+
* @returns 匹配的节点对象,不存在时抛出错误或返回 null(取决于核心实现)
|
|
246
|
+
*/
|
|
247
|
+
getNode: (id: JsonNodeId) => import("@jsonup/core").JsonNode | undefined;
|
|
248
|
+
/**
|
|
249
|
+
* 根据 ID 获取节点的 JSONPath 路径
|
|
250
|
+
* @param id 节点 ID
|
|
251
|
+
* @returns 节点的路径字符串
|
|
252
|
+
*/
|
|
253
|
+
getPath: (id: JsonNodeId) => string | undefined;
|
|
254
|
+
/**
|
|
255
|
+
* 根据 JSONPath 路径查找节点
|
|
256
|
+
* @param path JSONPath 路径字符串
|
|
257
|
+
* @returns 匹配的节点对象,不存在时返回 undefined
|
|
258
|
+
*/
|
|
259
|
+
findByPath: (path: string) => import("@jsonup/core").JsonNode | undefined;
|
|
260
|
+
/**
|
|
261
|
+
* 在文档中搜索匹配的节点
|
|
262
|
+
* @param query 搜索关键字
|
|
263
|
+
* @returns 匹配的节点 ID 数组
|
|
264
|
+
*/
|
|
265
|
+
search: (query: string) => import("@jsonup/core").JsonNode[];
|
|
266
|
+
/**
|
|
267
|
+
* 将当前文档状态格式化为 JSON 字符串
|
|
268
|
+
* @param space 缩进的空格数,默认为 2
|
|
269
|
+
* @returns 格式化后的 JSON 字符串
|
|
270
|
+
*/
|
|
271
|
+
stringify: (space?: number) => string;
|
|
272
|
+
};
|
|
273
|
+
//#endregion
|
|
274
|
+
export { JsonupViewer, type JsonupViewerLine, type JsonupViewerLineKind, type JsonupViewerLineSlotProps, UseJsonDocumentOptions, createViewerLines, useJsonDocument };
|