Skip to content

Commit

Permalink
fix: catch inner union check, close koishijs/koishi#1261
Browse files Browse the repository at this point in the history
  • Loading branch information
shigma committed Nov 13, 2023
1 parent ab00aa9 commit e93d34f
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 13 deletions.
10 changes: 4 additions & 6 deletions .github/workflows/build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ jobs:

steps:
- name: Check out
uses: actions/checkout@v3
uses: actions/checkout@v4
- name: Set up Node
uses: actions/setup-node@v3
uses: actions/setup-node@v4
with:
node-version: ${{ matrix.node-version }}
- name: Install
Expand All @@ -39,11 +39,9 @@ jobs:

steps:
- name: Check out
uses: actions/checkout@v3
uses: actions/checkout@v4
- name: Set up Node
uses: actions/setup-node@v3
with:
node-version: 18
uses: actions/setup-node@v4
- name: Install
run: yarn
- name: Build source
Expand Down
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": "7.1.2",
"version": "7.1.3",
"main": "src/index.ts",
"files": [
"src"
Expand Down
4 changes: 2 additions & 2 deletions packages/form/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { App, Component } from 'vue'
import { Schema, useDisabled, useEntries, useModel } from './utils'
import extensions, { Schema, useDisabled, useEntries, useModel } from './utils'
import SchemaBase from './base.vue'
import Primitive from './primitive.vue'
import SchemaCheckbox from './extensions/checkbox.vue'
Expand Down Expand Up @@ -31,7 +31,7 @@ export const form = Object.assign(SchemaBase, {
useModel,
useEntries,
useDisabled,
extensions: new Set(),
extensions,
install(app: App) {
app.component('k-form', KForm)
app.component('k-badge', KBadge)
Expand Down
6 changes: 3 additions & 3 deletions packages/form/src/schema.vue
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,8 @@
import { computed, PropType } from 'vue'
import { useI18n } from 'vue-i18n'
import { clone, deepEqual, isNullable } from 'cosmokit'
import { Schema, useI18nText } from './utils'
import form, { IconUndo, IconReset } from '.'
import extensions, { Schema, useI18nText } from './utils'
import { IconUndo, IconReset } from './icons'
import SchemaPrimitive from './primitive.vue'
import SchemaBase from './base.vue'
import zhCN from './locales/zh-CN.yml'
Expand Down Expand Up @@ -81,7 +81,7 @@ const isPrimitive = computed(() => {
})
const SchemaComponent = computed(() => {
const candidates = [...form.extensions].map((ext) => {
const candidates = [...extensions].map((ext) => {
if (ext.type && props.schema?.type !== ext.type) return
if (ext.role && props.schema?.meta.role !== ext.role) return
if (ext.validate) {
Expand Down
7 changes: 6 additions & 1 deletion packages/form/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,13 @@ import { clone, deepEqual, Dict, isNullable, valueMap } from 'cosmokit'
import { computed, getCurrentInstance, ref, watch, WatchStopHandle } from 'vue'
import { fallbackWithLocaleChain } from '@intlify/core-base'
import { useI18n } from 'vue-i18n'
import form from '.'

export { Schema }

const extensions = new Set<form.Extension>()
export default extensions

export function useI18nText() {
const composer = useI18n()
const context: any = {}
Expand Down Expand Up @@ -102,10 +106,11 @@ export function useModel<T = any>(options?: ConfigOptions<T>) {
const doWatch = () => watch(config, (value) => {
try {
if (options?.output) value = options.output(value)
const schema = optional(Schema(props.schema))
if (deepEqual(schema(value), props.schema.meta.default, options?.strict)) value = null
} catch {
return
}
if (deepEqual(Schema(props.schema)(value), props.schema.meta.default, options?.strict)) value = null
emit('update:modelValue', value)
}, { deep: true })

Expand Down

0 comments on commit e93d34f

Please sign in to comment.