Skip to content

Commit

Permalink
release: v0.10.0
Browse files Browse the repository at this point in the history
  • Loading branch information
cloydlau committed Nov 28, 2022
1 parent 21a3c28 commit 0d2f489
Show file tree
Hide file tree
Showing 6 changed files with 72 additions and 66 deletions.
18 changes: 9 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ createApp()
"vue": "https://unpkg.com/vue/dist/vue.esm-browser.prod.js",
"vue-demi": "https://unpkg.com/vue-demi/lib/v3/index.mjs",
"vanilla-jsoneditor": "https://unpkg.com/vanilla-jsoneditor",
"json-editor-vue": "https://unpkg.com/json-editor-vue@0.9/dist/json-editor-vue.mjs"
"json-editor-vue": "https://unpkg.com/json-editor-vue@0.10/dist/json-editor-vue.mjs"
}
}
</script>
Expand All @@ -120,7 +120,7 @@ createApp()

##### Using the Global Build

> Not yet supported because `vanilla-jsoneditor` does not export UMD, please leave a message [here](https://github.com/josdejong/svelte-jsoneditor/discussions/196) if you need it.
> Not yet supported because `vanilla-jsoneditor` does not export UMD, please leave a message [here](https://github.com/josdejong/svelte-jsoneditor/discussions/196) if you need it.
```html
<!DOCTYPE html>
Expand All @@ -138,7 +138,7 @@ createApp()
<script src="https://unpkg.com/vue"></script>
<script src="https://unpkg.com/vue-demi"></script>
<!-- TODO --> <script src="./vanilla-jsoneditor.umd.js"></script>
<script src="https://unpkg.com/json-editor-vue"></script>
<script src="https://unpkg.com/json-editor-vue@0.10"></script>
<script>
const { createApp, ref } = Vue
Expand Down Expand Up @@ -210,7 +210,7 @@ Vue.use(JsonEditorVue, {
"vue": "https://unpkg.com/vue@2/dist/vue.esm.browser.min.js",
"vue-demi": "https://unpkg.com/vue-demi/lib/v2.7/index.mjs",
"vanilla-jsoneditor": "https://unpkg.com/vanilla-jsoneditor",
"json-editor-vue": "https://unpkg.com/json-editor-vue@0.9/dist/json-editor-vue.mjs"
"json-editor-vue": "https://unpkg.com/json-editor-vue@0.10/dist/json-editor-vue.mjs"
}
}
</script>
Expand All @@ -234,7 +234,7 @@ Vue.use(JsonEditorVue, {

##### Using the Global Build

> Not yet supported because `vanilla-jsoneditor` does not export UMD, please leave a message [here](https://github.com/josdejong/svelte-jsoneditor/discussions/196) if you need it.
> Not yet supported because `vanilla-jsoneditor` does not export UMD, please leave a message [here](https://github.com/josdejong/svelte-jsoneditor/discussions/196) if you need it.
```html
<!DOCTYPE html>
Expand All @@ -252,7 +252,7 @@ Vue.use(JsonEditorVue, {
<script src="https://unpkg.com/vue@2"></script>
<script src="https://unpkg.com/vue-demi"></script>
<!-- TODO --> <script src="./vanilla-jsoneditor.umd.js"></script>
<script src="https://unpkg.com/json-editor-vue"></script>
<script src="https://unpkg.com/json-editor-vue@0.10"></script>
<script>
new Vue({
components: { 'json-editor-vue': JsonEditorVue },
Expand Down Expand Up @@ -342,7 +342,7 @@ Vue.use(JsonEditorVue, {
"@vue/composition-api/dist/vue-composition-api.mjs": "https://unpkg.com/@vue/composition-api/dist/ vue-composition-api.mjs",
"vue-demi": "https://unpkg.com/vue-demi/lib/v2/index.mjs",
"vanilla-jsoneditor": "https://unpkg.com/vanilla-jsoneditor",
"json-editor-vue": "https://unpkg.com/json-editor-vue@0.9/dist/json-editor-vue.mjs"
"json-editor-vue": "https://unpkg.com/json-editor-vue@0.10/dist/json-editor-vue.mjs"
}
}
</script>
Expand All @@ -365,7 +365,7 @@ Vue.use(JsonEditorVue, {

##### Using the Global Build

> Not yet supported because `vanilla-jsoneditor` does not export UMD, please leave a message [here](https://github.com/josdejong/svelte-jsoneditor/discussions/196) if you need it.
> Not yet supported because `vanilla-jsoneditor` does not export UMD, please leave a message [here](https://github.com/josdejong/svelte-jsoneditor/discussions/196) if you need it.
```html
<!DOCTYPE html>
Expand All @@ -384,7 +384,7 @@ Vue.use(JsonEditorVue, {
<script src="https://unpkg.com/@vue/composition-api"></script>
<script src="https://unpkg.com/vue-demi"></script>
<!-- TODO --> <script src="./vanilla-jsoneditor.umd.js"></script>
<script src="https://unpkg.com/json-editor-vue"></script>
<script src="https://unpkg.com/json-editor-vue@0.10"></script>
<script>
const { createApp, ref } = VueCompositionAPI
Expand Down
18 changes: 9 additions & 9 deletions docs/README.zh-CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ createApp()
"vue": "https://unpkg.com/vue/dist/vue.esm-browser.prod.js",
"vue-demi": "https://unpkg.com/vue-demi/lib/v3/index.mjs",
"vanilla-jsoneditor": "https://unpkg.com/vanilla-jsoneditor",
"json-editor-vue": "https://unpkg.com/json-editor-vue@0.9/dist/json-editor-vue.mjs"
"json-editor-vue": "https://unpkg.com/json-editor-vue@0.10/dist/json-editor-vue.mjs"
}
}
</script>
Expand All @@ -118,7 +118,7 @@ createApp()

##### 使用全局构建版本

> 暂不支持(`vanilla-jsoneditor` 不提供 UMD 导出),如有需要请在[这里](https://github.com/josdejong/svelte-jsoneditor/discussions/196)留言。
> 暂不支持(`vanilla-jsoneditor` 不提供 UMD 导出),如有需要请在[这里](https://github.com/josdejong/svelte-jsoneditor/discussions/196)留言。
```html
<!DOCTYPE html>
Expand All @@ -136,7 +136,7 @@ createApp()
<script src="https://unpkg.com/vue"></script>
<script src="https://unpkg.com/vue-demi"></script>
<!-- TODO --> <script src="./vanilla-jsoneditor.umd.js"></script>
<script src="https://unpkg.com/json-editor-vue"></script>
<script src="https://unpkg.com/json-editor-vue@0.10"></script>
<script>
const { createApp, ref } = Vue
Expand Down Expand Up @@ -208,7 +208,7 @@ Vue.use(JsonEditorVue, {
"vue": "https://unpkg.com/vue@2/dist/vue.esm.browser.min.js",
"vue-demi": "https://unpkg.com/vue-demi/lib/v2.7/index.mjs",
"vanilla-jsoneditor": "https://unpkg.com/vanilla-jsoneditor",
"json-editor-vue": "https://unpkg.com/json-editor-vue@0.9/dist/json-editor-vue.mjs"
"json-editor-vue": "https://unpkg.com/json-editor-vue@0.10/dist/json-editor-vue.mjs"
}
}
</script>
Expand All @@ -232,7 +232,7 @@ Vue.use(JsonEditorVue, {

##### 使用全局构建版本

> 暂不支持(`vanilla-jsoneditor` 不提供 UMD 导出),如有需要请在[这里](https://github.com/josdejong/svelte-jsoneditor/discussions/196)留言。
> 暂不支持(`vanilla-jsoneditor` 不提供 UMD 导出),如有需要请在[这里](https://github.com/josdejong/svelte-jsoneditor/discussions/196)留言。
```html
<!DOCTYPE html>
Expand All @@ -250,7 +250,7 @@ Vue.use(JsonEditorVue, {
<script src="https://unpkg.com/vue@2"></script>
<script src="https://unpkg.com/vue-demi"></script>
<!-- TODO --> <script src="./vanilla-jsoneditor.umd.js"></script>
<script src="https://unpkg.com/json-editor-vue"></script>
<script src="https://unpkg.com/json-editor-vue@0.10"></script>
<script>
new Vue({
components: { 'json-editor-vue': JsonEditorVue },
Expand Down Expand Up @@ -340,7 +340,7 @@ Vue.use(JsonEditorVue, {
"@vue/composition-api/dist/vue-composition-api.mjs": "https://unpkg.com/@vue/composition-api/dist/ vue-composition-api.mjs",
"vue-demi": "https://unpkg.com/vue-demi/lib/v2/index.mjs",
"vanilla-jsoneditor": "https://unpkg.com/vanilla-jsoneditor",
"json-editor-vue": "https://unpkg.com/json-editor-vue@0.9/dist/json-editor-vue.mjs"
"json-editor-vue": "https://unpkg.com/json-editor-vue@0.10/dist/json-editor-vue.mjs"
}
}
</script>
Expand All @@ -363,7 +363,7 @@ Vue.use(JsonEditorVue, {

##### 使用全局构建版本

> 暂不支持(`vanilla-jsoneditor` 不提供 UMD 导出),如有需要请在[这里](https://github.com/josdejong/svelte-jsoneditor/discussions/196)留言。
> 暂不支持(`vanilla-jsoneditor` 不提供 UMD 导出),如有需要请在[这里](https://github.com/josdejong/svelte-jsoneditor/discussions/196)留言。
```html
<!DOCTYPE html>
Expand All @@ -382,7 +382,7 @@ Vue.use(JsonEditorVue, {
<script src="https://unpkg.com/@vue/composition-api"></script>
<script src="https://unpkg.com/vue-demi"></script>
<!-- TODO --> <script src="./vanilla-jsoneditor.umd.js"></script>
<script src="https://unpkg.com/json-editor-vue"></script>
<script src="https://unpkg.com/json-editor-vue@0.10"></script>
<script>
const { createApp, ref } = VueCompositionAPI
Expand Down
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "json-editor-vue",
"pascalCasedName": "JsonEditorVue",
"version": "0.9.2",
"version": "0.10.0",
"private": false,
"packageManager": "pnpm@latest",
"description": "JSON editor & viewer for Vue 2.6 / 2.7 / 3 & Nuxt 2 / 3.",
Expand Down Expand Up @@ -45,7 +45,7 @@
"doc": "vitepress dev --open /README",
"lint": "eslint --cache {src,__tests__}/**.*",
"build": "vite build",
"test-unit": "vitest",
"test-unit": "vitest run",
"coverage": "vitest run --coverage",
"release": "cl switchVue 3 && npx case-police --fix && npx lint-staged && pnpm test-unit && pnpm build && cl release"
},
Expand Down Expand Up @@ -99,4 +99,4 @@
"publishConfig": {
"registry": "https://registry.npmjs.org/"
}
}
}
2 changes: 1 addition & 1 deletion src/Component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import { JSONEditor } from 'vanilla-jsoneditor'
import { conclude } from 'vue-global-config'
import { debounce } from 'lodash-es'
import { pascalCasedName as name } from '../package.json'
import { globalAttrs, globalProps } from './index'
import { globalAttrs, globalProps } from './install'

export type Mode = 'tree' | 'text'

Expand Down
48 changes: 4 additions & 44 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,46 +1,6 @@
import type { Plugin } from 'vue'
import { useGlobalConfig } from 'vue-global-config'
import Component from './Component'
import type { Mode } from './Component'

type SFCWithInstall<T> = T & Plugin

const withInstall = <T, E extends Record<string, any>>(
main: T,
extra?: E,
) => {
(main as SFCWithInstall<T>).install = (app): void => {
for (const comp of [main, ...Object.values(extra ?? {})]) {
app.component(comp.name, comp)
}
}

if (extra) {
for (const [key, comp] of Object.entries(extra)) {
(main as any)[key] = comp
}
}
return main as SFCWithInstall<T> & E
}

const globalProps: Record<string, any> = {}
const globalAttrs: Record<string, any> = {}
const globalListeners: Record<string, any> = {}
const globalHooks: Record<string, any> = {}

const ComponentWithInstall = withInstall(Component)

ComponentWithInstall.install = (app: any, options = {}) => {
const { props, attrs, listeners, hooks } = useGlobalConfig(options, Component.props)
Object.assign(globalProps, props)
Object.assign(globalAttrs, attrs)
Object.assign(globalListeners, listeners)
Object.assign(globalHooks, hooks)
app.component(ComponentWithInstall.name, ComponentWithInstall)
}
import ComponentWithInstall from './install'
import type { Mode } from './install'

export default ComponentWithInstall
export {
globalProps, globalAttrs, globalListeners, globalHooks,
Mode,
}
export { Mode }

46 changes: 46 additions & 0 deletions src/install.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
import type { Plugin } from 'vue'
import { useGlobalConfig } from 'vue-global-config'
import Component from './Component'
import type { Mode } from './Component'

type SFCWithInstall<T> = T & Plugin

const withInstall = <T, E extends Record<string, any>>(
main: T,
extra?: E,
) => {
(main as SFCWithInstall<T>).install = (app): void => {
for (const comp of [main, ...Object.values(extra ?? {})]) {
app.component(comp.name, comp)
}
}

if (extra) {
for (const [key, comp] of Object.entries(extra)) {
(main as any)[key] = comp
}
}
return main as SFCWithInstall<T> & E
}

const globalProps: Record<string, any> = {}
const globalAttrs: Record<string, any> = {}
const globalListeners: Record<string, any> = {}
const globalHooks: Record<string, any> = {}

const ComponentWithInstall = withInstall(Component)

ComponentWithInstall.install = (app: any, options = {}) => {
const { props, attrs, listeners, hooks } = useGlobalConfig(options, Component.props)
Object.assign(globalProps, props)
Object.assign(globalAttrs, attrs)
Object.assign(globalListeners, listeners)
Object.assign(globalHooks, hooks)
app.component(ComponentWithInstall.name, ComponentWithInstall)
}

export default ComponentWithInstall
export {
globalProps, globalAttrs, globalListeners, globalHooks,
Mode,
}

0 comments on commit 0d2f489

Please sign in to comment.