-
Notifications
You must be signed in to change notification settings - Fork 716
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Json viewer #2561
Open
anjiazhuyouxing
wants to merge
17
commits into
DouyinFE:release
Choose a base branch
from
anjiazhuyouxing:json-viewer
base: release
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+11,046
−13
Open
Json viewer #2561
Changes from 3 commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
706c457
docs: Update CONTRIBUTING.md
pointhalo 1a88810
feat: json-viewer
b0cbc3f
docs: 模块注释
20bf9a7
docs: json-viewer API doc
cda569d
fix: fix some type error
37ca223
fix: infinite loop problem during parse
3b30c1a
fix: delete cursor problems
72afc1b
feat: use semi token
9103898
docs: rename api
189b629
docs: rename api
7408e51
fix: build json viewer
9211573
refactor: add json-viewer package
96bbe42
docs: json-viewer md
8ffdbb6
feat: serach foundation
0d2c835
fix: search bug
306e763
fix: story instance bug
bf4630c
fix: build type error
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,145 @@ | ||
--- | ||
localeCode: zh-CN | ||
order: 86 | ||
category: 展示类 | ||
title: Json-Viewer JSON编辑器 | ||
icon: doc-list | ||
dir: column | ||
noInline: true | ||
brief: 用于展示和编辑 JSON 数据 | ||
--- | ||
|
||
## 代码演示 | ||
|
||
### 如何引入 | ||
|
||
```jsx import | ||
import { JsonViewer } from '@douyinfe/semi-ui'; | ||
``` | ||
|
||
### 基本用法 | ||
|
||
JsonViewer 的基本用法。传入 value height 和 width 参数,设置组件的高度和宽度和初始值。 | ||
|
||
```jsx live=true dir="column" noInline=true | ||
import React from 'react'; | ||
import { JsonViewer } from '@douyinfe/semi-ui'; | ||
|
||
class SimpleList extends React.Component { | ||
render() { | ||
const data = `{ | ||
"name": "Semi", | ||
"version": "0.0.0" | ||
}`; | ||
|
||
return ( | ||
<div> | ||
<div style={{ marginRight: 16 }}> | ||
<h3 style={{ marginBottom: 16 }}>Default Size</h3> | ||
<JsonViewer height={400} width={700} value={data} /> | ||
</div> | ||
</div> | ||
); | ||
} | ||
} | ||
|
||
render(SimpleList); | ||
``` | ||
|
||
### 设置行高 | ||
|
||
配置 options 的 lineHeight 参数,设置固定行高(单位:px, 默认 20)。 | ||
|
||
```jsx live=true dir="column" noInline=true | ||
import React from 'react'; | ||
import { JsonViewer } from '@douyinfe/semi-ui'; | ||
|
||
class SimpleList extends React.Component { | ||
render() { | ||
const data = `{ | ||
"name": "Semi", | ||
"version": "0.0.0" | ||
}`; | ||
|
||
return ( | ||
<div> | ||
<div style={{ marginRight: 16 }}> | ||
<h3 style={{ marginBottom: 16 }}>Default Size</h3> | ||
<JsonViewer height={400} width={700} value={data} options={{ lineHeight: 25 }} /> | ||
</div> | ||
</div> | ||
); | ||
} | ||
} | ||
|
||
render(SimpleList); | ||
``` | ||
|
||
### 自动换行 | ||
|
||
配置 options 的 autoHeight 参数,设置组件是否自动换行。 | ||
|
||
```jsx live=true dir="column" noInline=true | ||
import React from 'react'; | ||
import { JsonViewer } from '@douyinfe/semi-ui'; | ||
|
||
class SimpleList extends React.Component { | ||
render() { | ||
const data = `{ | ||
"name": "Semi", | ||
"version": "0.0.0", | ||
"description": "lorem ipsum dolor sit amet, consectetur adipiscing elit.lorem ipsum dolor sit amet, consectetur adipiscing elit.lorem ipsum dolor sit amet, consectetur adipiscing elit.lorem ipsum dolor sit amet, consectetur adipiscing elit." | ||
}`; | ||
|
||
return ( | ||
<div> | ||
<div style={{ marginRight: 16 }}> | ||
<h3 style={{ marginBottom: 16 }}>Default Size</h3> | ||
<JsonViewer height={400} width={700} value={data} options={{ autoHeight: true }} /> | ||
</div> | ||
</div> | ||
); | ||
} | ||
} | ||
|
||
render(SimpleList); | ||
``` | ||
|
||
### 格式化配置 | ||
|
||
配置 options 的 formatOptions 参数,设置组件的格式化配置。 | ||
|
||
- tabSize: number, 设置缩进大小,4 表示每级缩进 4 个空格 | ||
- insertSpaces: boolean, true 表示使用空格进行缩进,false 表示使用制表符(Tab) | ||
- eol: string, 设置换行符,可以是\n,\r\n, | ||
|
||
```jsx live=true dir="column" noInline=true | ||
import React from 'react'; | ||
import { JsonViewer } from '@douyinfe/semi-ui'; | ||
|
||
class SimpleList extends React.Component { | ||
render() { | ||
const data = `{ | ||
"name": "Semi", | ||
"version": "0.0.0", | ||
"description": "lorem ipsum dolor sit amet, consectetur adipiscing elit.lorem ipsum dolor sit amet, consectetur adipiscing elit.lorem ipsum dolor sit amet, consectetur adipiscing elit.lorem ipsum dolor sit amet, consectetur adipiscing elit." | ||
}`; | ||
|
||
return ( | ||
<div> | ||
<div style={{ marginRight: 16 }}> | ||
<h3 style={{ marginBottom: 16 }}>Default Size</h3> | ||
<JsonViewer | ||
height={400} | ||
width={700} | ||
value={data} | ||
options={{ formatOptions: { tabSize: 2, insertSpaces: true, eol: '\n' } }} | ||
/> | ||
</div> | ||
</div> | ||
); | ||
} | ||
} | ||
|
||
render(SimpleList); | ||
pointhalo marked this conversation as resolved.
Show resolved
Hide resolved
|
||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -217,7 +217,8 @@ | |
"webpack": "^5.77.0", | ||
"webpack-cli": "^5.1.4", | ||
"webpack-dev-server": "^3.11.2", | ||
"webpackbar": "^5.0.0-3" | ||
"webpackbar": "^5.0.0-3", | ||
"worker-loader": "^3.0.8" | ||
}, | ||
"husky": { | ||
"hooks": { | ||
|
@@ -242,5 +243,6 @@ | |
"stylelint" | ||
] | ||
}, | ||
"license": "MIT" | ||
"license": "MIT", | ||
"packageManager": "[email protected]+sha512.a6b2f7906b721bba3d67d4aff083df04dad64c399707841b7acf00f6b133b7ac24255f2652fa22ae3534329dc6180534e98d17432037ff6fd140556e2bb3137e" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 这个pacakgeMannger 这行不要带上去 |
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
/** Based on https://github.com/microsoft/vscode-json-languageservice with modifications for custom requirements */ | ||
export function runWhenGlobalIdle(callback: (idleDeadline: IdleDeadline) => void) { | ||
const handler = window.requestIdleCallback(callback); | ||
let disposed = false; | ||
|
||
return { | ||
dispose: () => { | ||
if (disposed) { | ||
return; | ||
} | ||
disposed = true; | ||
window.cancelIdleCallback(handler); | ||
}, | ||
}; | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
后续加一个 【使用场景】
描述一下与直接使用 Monaco的区别
什么场景建议使用 Mocaco
什么场景建议使用 JsonViewer
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
以及 我们底层依赖什么包来做什么事情,例如使用 jsonc-parser来干什么,而在什么地方做了额外的改动处理。(2-3句话简短解释就行)