Skip to content

Commit

Permalink
feat: support union in computed
Browse files Browse the repository at this point in the history
  • Loading branch information
shigma committed Feb 16, 2023
1 parent 0d9f77a commit 4b5ec70
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
2 changes: 1 addition & 1 deletion packages/form/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "schemastery-vue",
"description": "Type driven schema validator",
"version": "2.0.0",
"version": "2.0.1",
"main": "src/index.ts",
"repository": {
"type": "git",
Expand Down
12 changes: 8 additions & 4 deletions packages/form/src/schema.vue
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
:prefix="prefix">
<slot></slot>
<template #after v-if="schema.meta.role === 'computed'">
<el-button v-if="config?.$switch" @click="addBranch">
<el-button v-if="isSwitch" @click="addBranch">
添加分支
</el-button>
<el-button class="ellipsis" v-else-if="check(schema, initial)" @click="addBranch">
Expand All @@ -36,7 +36,7 @@
</template>
</k-schema>

<div class="k-schema-group" v-if="schema.meta.role === 'computed' && config?.$switch">
<div class="k-schema-group" v-if="isSwitch">
<k-schema
v-for="(_, index) in config.$switch.branches"
v-model="config.$switch.branches[index].then"
Expand Down Expand Up @@ -86,7 +86,7 @@
<template #right>
<slot name="before"></slot>

<template v-if="schema.type === 'union' && schema.meta.role !== 'radio'">
<template v-if="schema.type === 'union' && schema.meta.role !== 'radio' && !isSwitch">
<el-select filterable v-model="selectModel" :disabled="disabled">
<el-option
v-for="(item, index) in choices"
Expand Down Expand Up @@ -181,7 +181,7 @@
</template>

<!-- union containing object -->
<template v-else-if="schema?.type === 'union' && choices.length > 1 && ['object', 'intersect'].includes(active?.type)">
<template v-else-if="schema?.type === 'union' && !isSwitch && choices.length > 1 && ['object', 'intersect'].includes(active?.type)">
<k-schema
v-model="config"
:initial="initial"
Expand Down Expand Up @@ -279,6 +279,10 @@ const isPrimitive = computed(() => {
&& active.value.meta.role !== 'textarea'
})
const isSwitch = computed(() => {
return props.schema?.meta.role === 'computed' && config.value?.$switch
})
const isComposite = computed(() => {
return ['array', 'dict'].includes(active.value.type) && active.value.meta.role !== 'table'
})
Expand Down

0 comments on commit 4b5ec70

Please sign in to comment.