Press n or j to go to the next uncovered block, b, p or k for the previous block.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 | 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 5x 5x 5x 1x 1x 6x 6x 6x 6x 6x 6x 6x 6x 6x | import {
computed,
inject,
InjectionKey,
provide,
ref,
Ref,
shallowRef,
} from 'vue'
import { FormItemData } from './types'
export type SmartFormState = {
emit: {
(name: 'update:modelValue', data: Record<string, any>): void
(
name: 'itemChange',
id: string,
value: any,
prev: any,
itemData: FormItemData,
ctx?: any
): void
}
el: Ref<HTMLElement | null>
labelWidth: Ref<string>
labelPosition: Ref<LabelPoistion>
itemClass: Ref<string | undefined>
modelValue: Ref<Record<string, any>>
rules: Ref<Record<string, any>>
}
export type LabelPoistion = 'left' | 'top' | 'sticky' | 'none'
export const SMART_FORM_STATE: InjectionKey<SmartFormState> =
Symbol('SMART_FORM_STATE')
export const provideFormState = (s: SmartFormState) => {
provide(SMART_FORM_STATE, s)
return s
}
export const useSmartFormState = () =>
inject(SMART_FORM_STATE, {
el: shallowRef(null),
labelPosition: computed((): LabelPoistion => 'left'),
labelWidth: computed(() => '20px'),
itemClass: ref(''),
emit: () => {},
modelValue: ref({}),
rules: ref({}),
})
|