Skip to content
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

release #272

Merged
merged 16 commits into from
Mar 20, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
refactor: use theme prop instead of darkHighlightMode
Dan0xE committed Feb 1, 2024
commit 80e705ca8cc1f4d7bae9ba6a3d805f8603fec907
52 changes: 26 additions & 26 deletions README.md
Original file line number Diff line number Diff line change
@@ -106,32 +106,32 @@ plugins: [

## Props

| Property | Description | Type | Default |
| ------------------------ | ------------------------------------------------------------------------------------ | --------------------------------- | ------- |
| data(v-model) | JSON data, support v-model when use editable | JSON object | - |
| collapsedNodeLength | Objects or arrays which length is greater than this threshold will be collapsed | number | - |
| deep | Paths greater than this depth will be collapsed | number | - |
| showLength | Show the length when collapsed | boolean | false |
| showLine | Show the line | boolean | true |
| showLineNumber | Show the line number | boolean | false |
| showIcon | Show the icon | boolean | false |
| showDoubleQuotes | Show doublequotes on key | boolean | true |
| virtual | Use virtual scroll | boolean | false |
| height | The height of list when using virtual | number | 400 |
| itemHeight | The height of node when using virtual | number | 20 |
| selectedValue(v-model) | Selected data path | string, array | - |
| rootPath | Root data path | string | `root` |
| nodeSelectable | Defines whether a node supports selection | (node) => boolean | - |
| selectableType | Support path select, default none | `multiple` \| `single` | - |
| showSelectController | Show the select controller | boolean | false |
| selectOnClickNode | Trigger select when click node | boolean | true |
| highlightSelectedNode | Support highlighting selected nodes | boolean | true |
| collapsedOnClickBrackets | Support click brackets to collapse | boolean | true |
| renderNodeKey | render node key, or use slot #renderNodeKey | ({ node, defaultKey }) => vNode | - |
| renderNodeValue | render node value, or use slot #renderNodeValue | ({ node, defaultValue }) => vNode | - |
| editable | Support editable | boolean | false |
| editableTrigger | Trigger | `click` \| `dblclick` | `click` |
| darkHighlightMode | Enables a dark theme for hover highlights, improving visibility on dark backgrounds. | boolean | false |
| Property | Description | Type | Default |
| ------------------------ | ----------------------------------------------------------------------------------------------------------------------- | --------------------------------- | ------- |
| data(v-model) | JSON data, support v-model when use editable | JSON object | - |
| collapsedNodeLength | Objects or arrays which length is greater than this threshold will be collapsed | number | - |
| deep | Paths greater than this depth will be collapsed | number | - |
| showLength | Show the length when collapsed | boolean | false |
| showLine | Show the line | boolean | true |
| showLineNumber | Show the line number | boolean | false |
| showIcon | Show the icon | boolean | false |
| showDoubleQuotes | Show doublequotes on key | boolean | true |
| virtual | Use virtual scroll | boolean | false |
| height | The height of list when using virtual | number | 400 |
| itemHeight | The height of node when using virtual | number | 20 |
| selectedValue(v-model) | Selected data path | string, array | - |
| rootPath | Root data path | string | `root` |
| nodeSelectable | Defines whether a node supports selection | (node) => boolean | - |
| selectableType | Support path select, default none | `multiple` \| `single` | - |
| showSelectController | Show the select controller | boolean | false |
| selectOnClickNode | Trigger select when click node | boolean | true |
| highlightSelectedNode | Support highlighting selected nodes | boolean | true |
| collapsedOnClickBrackets | Support click brackets to collapse | boolean | true |
| renderNodeKey | render node key, or use slot #renderNodeKey | ({ node, defaultKey }) => vNode | - |
| renderNodeValue | render node value, or use slot #renderNodeValue | ({ node, defaultValue }) => vNode | - |
| editable | Support editable | boolean | false |
| editableTrigger | Trigger | `click` \| `dblclick` | `click` |
| theme | Sets the theme of the component. Options are 'light' or 'dark', with dark mode enhancing visibility on dark backgrounds | `'light' \| 'dark'` | `light` |

## Events

9 changes: 6 additions & 3 deletions example/Basic.vue
Original file line number Diff line number Diff line change
@@ -47,8 +47,11 @@
<input v-model="state.setPathCollapsible" type="checkbox" />
</div>
<div>
<label>darkHighlightMode</label>
<input v-model="localDarkMode" type="checkbox" />
<label>theme</label>
<select v-model="localDarkMode">
<option value="light">light</option>
<option value="dark">dark</option>
</select>
</div>
</div>

@@ -67,7 +70,7 @@
<div class="block">
<h3>vue-json-pretty:</h3>
<vue-json-pretty
:darkHighlightMode="localDarkMode"
:theme="localDarkMode"
:data="state.data"
:deep="state.deep"
:path-collapsible="state.setPathCollapsible ? pathCollapsible : undefined"
9 changes: 6 additions & 3 deletions example/Editable.vue
Original file line number Diff line number Diff line change
@@ -35,15 +35,18 @@
</div>
</div>
<div>
<label>darkHighlightMode</label>
<input v-model="localDarkMode" type="checkbox" />
<label>theme</label>
<select v-model="localDarkMode">
<option value="light">light</option>
<option value="dark">dark</option>
</select>
</div>
</div>
<div class="block">
<h3>vue-json-pretty:</h3>
<vue-json-pretty
v-model:data="state.data"
:darkHighlightMode="localDarkMode"
:theme="localDarkMode"
:deep="state.deep"
:show-double-quotes="true"
:show-line="state.showLine"
9 changes: 6 additions & 3 deletions example/SelectControl.vue
Original file line number Diff line number Diff line change
@@ -58,8 +58,11 @@
</select>
</div>
<div>
<label>darkHighlightMode</label>
<input v-model="localDarkMode" type="checkbox" />
<label>theme</label>
<select v-model="localDarkMode">
<option value="light">light</option>
<option value="dark">dark</option>
</select>
</div>
</div>
<h3>v-model:selectedValue:</h3>
@@ -72,7 +75,7 @@
<vue-json-pretty
v-if="state.renderOK"
v-model:selectedValue="state.selectedValue"
:darkHighlightMode="localDarkMode"
:theme="localDarkMode"
:data="state.data"
:root-path="state.rootPath"
:deep="state.deep"
9 changes: 6 additions & 3 deletions example/VirtualList.vue
Original file line number Diff line number Diff line change
@@ -35,14 +35,17 @@
</div>
</div>
<div>
<label>darkHighlightMode</label>
<input v-model="localDarkMode" type="checkbox" />
<label>theme</label>
<select v-model="localDarkMode">
<option value="light">light</option>
<option value="dark">dark</option>
</select>
</div>
</div>
<div class="block">
<h3>vue-json-pretty(10000+ items):</h3>
<vue-json-pretty
:darkHighlightMode="localDarkMode"
:theme="localDarkMode"
:collapsed-node-length="state.collapsedNodeLength"
:virtual="true"
:item-height="+state.itemHeight"
5 changes: 3 additions & 2 deletions example/useDarkMode.ts
Original file line number Diff line number Diff line change
@@ -1,20 +1,21 @@
import { inject, ref, watch } from 'vue';

export function useDarkMode() {

Check warning on line 3 in example/useDarkMode.ts

GitHub Actions / Run Linters

Missing return type on function
const darkModeState = inject('darkModeState');
const globalDarkModeState = ref(darkModeState.isDarkMode);
const localDarkMode = ref(darkModeState.isDarkMode);
const localDarkMode = ref(darkModeState.isDarkMode ? 'dark' : 'light');

watch(
() => darkModeState.isDarkMode,
newVal => {
localDarkMode.value = newVal;
localDarkMode.value = newVal ? 'dark' : 'light';
globalDarkModeState.value = newVal;
},
);

const toggleLocalDarkMode = () => {
darkModeState.isDarkMode = !darkModeState.isDarkMode;
localDarkMode.value = darkModeState.isDarkMode ? 'dark' : 'light';
};

return { localDarkMode, toggleLocalDarkMode, globalDarkModeState };
10 changes: 5 additions & 5 deletions src/components/Tree/index.tsx
Original file line number Diff line number Diff line change
@@ -70,9 +70,9 @@ export default defineComponent({
onSelectedChange: {
type: Function as PropType<(newVal: string | string[], oldVal: string | string[]) => void>,
},
darkHighlightMode: {
type: Boolean,
default: false,
theme: {
type: String as PropType<'light' | 'dark'>,
default: 'light',
},
},

@@ -285,7 +285,7 @@ export default defineComponent({
key={item.id}
node={item}
collapsed={!!state.hiddenPaths[item.path]}
darkHighlightMode={props.darkHighlightMode}
theme={props.theme}
showDoubleQuotes={props.showDoubleQuotes}
showLength={props.showLength}
checked={selectedPaths.value.includes(item.path)}
@@ -321,7 +321,7 @@ export default defineComponent({
class={{
'vjs-tree': true,
'is-virtual': props.virtual,
'dark-highlight-mode': props.darkHighlightMode,
dark: props.theme === 'dark',
}}
onScroll={props.virtual ? handleTreeScroll : undefined}
style={
8 changes: 4 additions & 4 deletions src/components/TreeNode/index.tsx
Original file line number Diff line number Diff line change
@@ -64,9 +64,9 @@ export const treeNodePropsPass = {
type: Boolean,
default: false,
},
darkHighlightMode: {
type: Boolean,
default: false,
theme: {
type: String as PropType<'light' | 'dark'>,
default: 'light',
},
showKeyValueSpace: {
type: Boolean,
@@ -217,7 +217,7 @@ export default defineComponent({
'has-selector': props.showSelectController,
'has-carets': props.showIcon,
'is-highlight': props.highlightSelectedNode && props.checked,
'dark-highlight-mode': props.darkHighlightMode,
dark: props.theme === 'dark',
}}
onClick={handleNodeClick}
style={props.style}
2 changes: 1 addition & 1 deletion src/components/TreeNode/styles.less
Original file line number Diff line number Diff line change
@@ -36,7 +36,7 @@
}
}

&.dark-highlight-mode {
&.dark {
&.is-highlight,
&:hover {
background-color: @highlight-bg-color-dark;

Unchanged files with check annotations Beta

export const SunIcon = () => (

Check warning on line 1 in example/Icons.tsx

GitHub Actions / Run Linters

Missing return type on function
<svg
xmlns="http://www.w3.org/2000/svg"
width="24"
</svg>
);
export const MoonIcon = () => (

Check warning on line 25 in example/Icons.tsx

GitHub Actions / Run Linters

Missing return type on function
<svg
xmlns="http://www.w3.org/2000/svg"
width="24"
emitListener: boolean;
};
export default function useError(message: string, { emitListener }: UseErrorOptions) {

Check warning on line 7 in src/hooks/useError.ts

GitHub Actions / Run Linters

Missing return type on function
const emit = () => {
throw new Error(`[VueJsonPretty] ${message}`);
};