@formvk/schema 0.0.0-stage → 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","names":["isFn","toArr"],"sources":["../src/shared.ts","../src/compiler.ts","../src/patches.ts","../src/transformer.ts","../src/schema.ts","../src/fragment.ts","../src/create-schema.ts","../src/expression.ts"],"sourcesContent":["import { isObservable, untracked } from '@formvk/reactive'\nimport { each, FormPath, isArr, isFn, isPlainObj, toArr } from '@formvk/shared'\n\nimport type { ISchema } from './types'\n\nconst REVA_ACTIONS_KEY = Symbol.for('__REVA_ACTIONS')\n\n/** 自定义扩展 key:xKey 形式(x + 大驼峰) */\nexport function isExtensionKey(key: string) {\n return /^x[A-Z]/.test(key)\n}\n\n/**\n * 值本身可以是函数的 schema key。\n * 这些 key 在编译/序列化/遍历时不能被当作 Schema 内部方法丢弃。\n */\nexport const SchemaFunctionKeys: Record<string, boolean> = {\n component: true,\n decorator: true,\n componentProps: true,\n decoratorProps: true,\n validator: true,\n reactions: true,\n}\n\nexport function isFunctionKey(key: string) {\n return isExtensionKey(key) || !!SchemaFunctionKeys[key]\n}\n\nexport const SchemaNestedMap: Record<string, boolean> = {\n parent: true,\n root: true,\n properties: true,\n patternProperties: true,\n additionalProperties: true,\n items: true,\n additionalItems: true,\n reactions: true,\n}\n\n/** schema key -> 字段状态 key */\nexport const SchemaStateMap: Record<string, string> = {\n title: 'title',\n description: 'description',\n default: 'initialValue',\n enum: 'dataSource',\n readOnly: 'readOnly',\n writeOnly: 'editable',\n content: 'content',\n data: 'data',\n value: 'value',\n editable: 'editable',\n disabled: 'disabled',\n readPretty: 'readPretty',\n visible: 'visible',\n hidden: 'hidden',\n display: 'display',\n pattern: 'pattern',\n validator: 'validator',\n decorator: 'decoratorType',\n component: 'componentType',\n decoratorProps: 'decoratorProps',\n componentProps: 'componentProps',\n}\n\n/** schema key -> 校验规则 key */\nexport const SchemaValidatorMap: Record<string, boolean> = {\n required: true,\n format: true,\n maxItems: true,\n minItems: true,\n maxLength: true,\n minLength: true,\n maximum: true,\n minimum: true,\n exclusiveMaximum: true,\n exclusiveMinimum: true,\n const: true,\n multipleOf: true,\n maxProperties: true,\n minProperties: true,\n uniqueItems: true,\n}\n\nexport const SchemaNormalKeys = Object.keys(SchemaStateMap)\n\nexport const SchemaValidatorKeys = Object.keys(SchemaValidatorMap)\n\nexport const hasOwnProperty = Object.prototype.hasOwnProperty\n\nexport function traverse(target: any, visitor: (value: any, path: Array<string | number>) => void) {\n const seenObjects: any[] = []\n const root = target\n function traverse(target: any, path: Array<string | number> = []) {\n if (isPlainObj(target)) {\n const seenIndex = seenObjects.indexOf(target)\n if (seenIndex > -1) {\n return\n }\n const addIndex = seenObjects.length\n seenObjects.push(target)\n if (isNoNeedCompileObject(target) && root !== target) {\n visitor(target, path)\n return\n }\n each(target, (value, key) => {\n traverse(value, path.concat(key))\n })\n seenObjects.splice(addIndex, 1)\n } else {\n visitor(target, path)\n }\n }\n traverse(target)\n}\n\nexport function traverseSchema(schema: ISchema, visitor: (value: any, path: any[], omitCompile?: boolean) => void) {\n if (schema['validator'] !== undefined) {\n visitor(schema['validator'], ['validator'], schema['compileOmitted']?.includes('validator'))\n }\n const seenObjects: any[] = []\n const root = schema\n function traverse(target: any, path: any[] = []) {\n if (\n path[0] === 'compileOmitted' ||\n path[0] === 'validator' ||\n path[0] === 'version' ||\n path[0] === '_isJSONSchemaObject'\n )\n return\n if (isFn(target) && !isFunctionKey(String(path[0]))) return\n if (SchemaNestedMap[path[0]]) return\n if ((schema['compileOmitted']?.indexOf(path[0]) ?? -1) > -1) {\n visitor(target, path, true)\n return\n }\n if (isPlainObj(target)) {\n if (path[0] === 'default' || path[0] === 'value') {\n visitor(target, path)\n return\n }\n const seenIndex = seenObjects.indexOf(target)\n if (seenIndex > -1) {\n return\n }\n const addIndex = seenObjects.length\n seenObjects.push(target)\n if (isNoNeedCompileObject(target) && root !== target) {\n visitor(target, path)\n return\n }\n each(target, (value, key) => {\n traverse(value, path.concat(key))\n })\n seenObjects.splice(addIndex, 1)\n } else {\n visitor(target, path)\n }\n }\n traverse(schema)\n}\n\nexport function isNoNeedCompileObject(source: any) {\n if ('$$typeof' in source && '_owner' in source) {\n return true\n }\n // Vue VNode / markRaw 对象:内部存在循环引用,且必须保持原始引用\n if (source['__v_isVNode'] || source['__v_skip']) {\n return true\n }\n if (source['_isAMomentObject']) {\n return true\n }\n // 使用实例标记判定,避免与 schema.ts 形成循环依赖\n if (source['_isJSONSchemaObject']) {\n return true\n }\n if (source[REVA_ACTIONS_KEY]) {\n return true\n }\n if (isFn(source['toJS'])) {\n return true\n }\n if (isFn(source['toJSON'])) {\n return true\n }\n if (isObservable(source)) {\n return true\n }\n return false\n}\n\nexport function createDataSource(source: any[]) {\n return toArr(source).map(item => {\n if (typeof item === 'object') {\n return item\n } else {\n return {\n label: item,\n value: item,\n }\n }\n })\n}\n\nexport function patchStateFormSchema(targetState: any, pattern: any[], compiled: any) {\n untracked(() => {\n const path = FormPath.parse(pattern)\n const segments = path.segments\n const key = segments[0]\n const isEnum = key === 'enum' && isArr(compiled)\n const schemaMapKey = SchemaStateMap[key]\n if (schemaMapKey) {\n FormPath.setIn(\n targetState,\n ([schemaMapKey] as Array<string | number>).concat(segments.slice(1)),\n isEnum ? createDataSource(compiled) : compiled\n )\n } else {\n const isValidatorKey = SchemaValidatorMap[key]\n if (isValidatorKey) {\n targetState['setValidatorRule']?.(key, compiled)\n }\n }\n })\n}\n","import type { IGeneralFieldState } from '@formvk/core'\nimport { untracked } from '@formvk/reactive'\nimport { FormPath, isArr, isFn, isPlainObj, isStr, reduce } from '@formvk/shared'\n\nimport { isNoNeedCompileObject, patchStateFormSchema, traverse, traverseSchema } from './shared'\nimport type { ISchema } from './types'\n\nconst ExpRE = /^\\s*\\{\\{([\\s\\S]*)\\}\\}\\s*$/\n\nconst Registry = {\n silent: false,\n compile(expression: string, scope: any = {}) {\n if (Registry.silent) {\n try {\n return new Function('$root', `with($root) { return (${expression}); }`)(scope)\n } catch {\n return undefined\n }\n } else {\n return new Function('$root', `with($root) { return (${expression}); }`)(scope)\n }\n },\n}\n\nexport function silent(value = true) {\n Registry.silent = !!value\n}\n\nexport function registerCompiler(compiler: (expression: string, scope: any) => any) {\n if (isFn(compiler)) {\n Registry.compile = compiler\n }\n}\n\nexport function shallowCompile<Source = any, Scope = any>(source: Source, scope?: Scope) {\n if (isStr(source)) {\n const matched = source.match(ExpRE)\n if (!matched) return source\n return Registry.compile(matched[1], scope)\n }\n return source\n}\n\n/**\n * 静态判断值中是否包含 `{{expression}}` 表达式。\n * 用于 demand 模式下判断 schema 补丁是否存在动态依赖,\n * 等价于 formily 的 `hasCollected`,但不需要额外的响应式收集标记。\n */\nfunction hasExpression(source: any): boolean {\n if (isStr(source)) {\n return ExpRE.test(source)\n }\n if (isArr(source)) {\n return source.some(hasExpression)\n }\n if (isPlainObj(source)) {\n if (isNoNeedCompileObject(source)) return false\n return Object.keys(source).some(key => hasExpression((source as any)[key]))\n }\n return false\n}\n\nexport function compile<Source = any, Scope = any>(source: Source, scope?: Scope): any {\n const seenObjects: any[] = []\n function compile(source: any): any {\n if (isStr(source)) {\n return shallowCompile(source, scope)\n } else if (isArr(source)) {\n return source.map((value: any) => compile(value))\n } else if (isPlainObj(source)) {\n if (isNoNeedCompileObject(source)) return source\n const seenIndex = seenObjects.indexOf(source)\n if (seenIndex > -1) {\n return source\n }\n const addIndex = seenObjects.length\n seenObjects.push(source)\n const results = reduce(\n source,\n (buf, value, key) => {\n ;(buf as any)[key] = compile(value)\n return buf\n },\n {} as Record<string, any>\n )\n seenObjects.splice(addIndex, 1)\n return results\n }\n return source\n }\n return compile(source)\n}\n\nexport function patchCompile(targetState: IGeneralFieldState, sourceState: any, scope: any) {\n traverse(sourceState, (value, pattern) => {\n const compiled = compile(value, scope)\n if (compiled === undefined) return\n const path = FormPath.parse(pattern)\n const key = path.segments[0]\n // 字段状态的 title/description 等是原型链上的 accessor,因此用 in 而不是 hasOwnProperty\n if (key in targetState) {\n untracked(() => FormPath.setIn(targetState as any, path, compiled))\n }\n })\n}\n\nexport function patchSchemaCompile(targetState: IGeneralFieldState, sourceSchema: ISchema, scope: any, demand = false) {\n traverseSchema(sourceSchema, (value, path, omitCompile) => {\n const dynamic = hasExpression(value)\n let compiled = value\n if (!omitCompile) {\n compiled = compile(value, scope)\n }\n if (compiled === undefined) return\n if (demand) {\n if (dynamic || !(targetState as any).initialized) {\n patchStateFormSchema(targetState, path, compiled)\n }\n } else {\n patchStateFormSchema(targetState, path, compiled)\n }\n })\n}\n","import { isFn } from '@formvk/shared'\n\nimport type { SchemaPatch } from './types'\n\nconst patches: SchemaPatch[] = []\n\nexport function reducePatches(schema: any) {\n return patches.reduce(\n (buf, patch) => {\n return patch(buf)\n },\n { ...schema }\n )\n}\n\nexport function registerPatches(...args: SchemaPatch[]) {\n args.forEach(patch => {\n if (isFn(patch)) {\n patches.push(patch)\n }\n })\n}\n","import type { Field, IFieldFactoryProps } from '@formvk/core'\nimport {\n onFieldInit,\n onFieldInputValueChange,\n onFieldInitialValueChange,\n onFieldMount,\n onFieldUnmount,\n onFieldValidateEnd,\n onFieldValidateFailed,\n onFieldValidateStart,\n onFieldValidateSuccess,\n onFieldValueChange,\n} from '@formvk/core'\nimport { autorun, observable, untracked } from '@formvk/reactive'\nimport { each, isArr, isFn, isPlainObj, isStr, lazyMerge, reduce, toArr } from '@formvk/shared'\n\nimport { patchCompile, patchSchemaCompile, shallowCompile } from './compiler'\nimport type { Schema } from './schema'\nimport type { IFieldStateSetterOptions, ISchema, ISchemaTransformerOptions, SchemaReaction } from './types'\n\nconst FieldEffects: Record<string, any> = {\n onFieldInit,\n onFieldMount,\n onFieldUnmount,\n onFieldValueChange,\n onFieldInputValueChange,\n onFieldInitialValueChange,\n onFieldValidateStart,\n onFieldValidateEnd,\n onFieldValidateFailed,\n onFieldValidateSuccess,\n}\n\nconst DefaultFieldEffects = ['onFieldInit', 'onFieldValueChange']\n\nfunction getDependencyValue(field: Field, pattern: string, property?: string) {\n const [target, path] = String(pattern).split(/\\s*#\\s*/)\n return field.query(target).getIn(path || property || 'value')\n}\n\nfunction getDependencies(\n field: Field,\n dependencies: Array<string | { name?: string; source?: string; property?: string }> | object\n) {\n if (isArr(dependencies)) {\n const results: any = []\n dependencies.forEach(pattern => {\n if (isStr(pattern)) {\n results.push(getDependencyValue(field, pattern))\n } else if (isPlainObj(pattern)) {\n const item = pattern as { name?: string; source?: string; property?: string }\n if (item.name && item.source) {\n results[item.name] = getDependencyValue(field, item.source, item.property)\n }\n }\n })\n return results\n } else if (isPlainObj(dependencies)) {\n return reduce(\n dependencies as Record<string, string>,\n (buf, pattern, key) => {\n buf[key] = getDependencyValue(field, pattern)\n return buf\n },\n {} as Record<string, any>\n )\n }\n return []\n}\n\nfunction setSchemaFieldState(options: IFieldStateSetterOptions, demand = false) {\n const { request, target, runner, field, scope } = options || {}\n if (!request) return\n if (target) {\n if (request.state) {\n field.form.setFieldState(target, state =>\n patchCompile(\n state,\n request.state,\n lazyMerge(scope as any, {\n $target: state,\n })\n )\n )\n }\n if (request.schema) {\n field.form.setFieldState(target, state =>\n patchSchemaCompile(\n state,\n request.schema!,\n lazyMerge(scope as any, {\n $target: state,\n }),\n demand\n )\n )\n }\n if (isStr(runner) && runner) {\n field.form.setFieldState(target, state => {\n shallowCompile(\n `{{function(){${runner}}}}`,\n lazyMerge(scope as any, {\n $target: state,\n })\n )()\n })\n }\n } else {\n if (request.state) {\n field.setState(state => patchCompile(state, request.state, scope))\n }\n if (request.schema) {\n field.setState(state => patchSchemaCompile(state, request.schema!, scope, demand))\n }\n if (isStr(runner) && runner) {\n shallowCompile(`{{function(){${runner}}}}`, scope)()\n }\n }\n}\n\nfunction getBaseScope(field: Field, options: ISchemaTransformerOptions = {}) {\n function $observable(target: any) {\n return observable(target)\n }\n function $props(props: any) {\n return field.setComponentProps(props)\n }\n function $effect(tracker: () => void) {\n return autorun(tracker)\n }\n function $memo<T>(callback: () => T) {\n return callback()\n }\n const $self = field\n const $form = field.form\n const $values = field.form.values\n return lazyMerge(\n {\n get $lookup() {\n return options?.scope?.$record ?? $values\n },\n get $records() {\n return field.records\n },\n get $record() {\n const record = field.record\n if (typeof record === 'object') {\n return lazyMerge(record, {\n get $lookup() {\n return options?.scope?.$record ?? $values\n },\n get $index() {\n return field.index\n },\n })\n }\n return record\n },\n get $index() {\n return field.index\n },\n },\n options.scope as any,\n {\n $form,\n $self,\n $observable,\n $effect,\n $memo,\n $props,\n $values,\n }\n )\n}\n\nfunction getBaseReactions(schema: ISchema, options: ISchemaTransformerOptions) {\n return (field: Field) => {\n setSchemaFieldState(\n {\n field,\n request: { schema },\n scope: getBaseScope(field, options),\n },\n true\n )\n }\n}\n\nfunction getUserReactions(schema: ISchema, options: ISchemaTransformerOptions) {\n const reactions: SchemaReaction[] = toArr(schema['reactions'])\n return reactions.map(unCompiled => {\n return (field: Field) => {\n const baseScope = getBaseScope(field, options)\n const reaction: any = shallowCompile(unCompiled, baseScope)\n if (!reaction) return\n if (isFn(reaction)) {\n return reaction(field, baseScope)\n }\n const { when, fulfill, otherwise, target, effects } = reaction\n function run() {\n const $deps = getDependencies(field, reaction.dependencies)\n const $dependencies = $deps\n const scope = lazyMerge(baseScope, {\n $target: null,\n $deps,\n $dependencies,\n })\n const compiledWhen = shallowCompile(when, scope)\n const condition = when ? compiledWhen : true\n const request = condition ? fulfill : otherwise\n const runner = request?.run\n setSchemaFieldState({\n field,\n target,\n request,\n runner,\n scope,\n })\n }\n\n if (target) {\n reaction.effects = effects?.length ? effects : DefaultFieldEffects\n }\n if (reaction.effects) {\n // 等价于 formily 的 autorun.memo(..., []):每个 reaction 只注册一次监听\n if (!reaction.__effectRegistered) {\n reaction.__effectRegistered = true\n untracked(() => {\n each(reaction.effects, (type: string) => {\n if (FieldEffects[type]) {\n FieldEffects[type](field.address, run)\n }\n })\n })\n }\n } else {\n run()\n }\n }\n })\n}\n\nexport function transformFieldProps(\n schema: Schema,\n options: ISchemaTransformerOptions = {}\n): IFieldFactoryProps<any, any> {\n return {\n name: schema.name as any,\n reactions: [getBaseReactions(schema, options)].concat(getUserReactions(schema, options)),\n }\n}\n","import type { IFieldFactoryProps } from '@formvk/core'\nimport { each, FormPath, isFn, isStr, map } from '@formvk/shared'\n\nimport { compile, registerCompiler, shallowCompile, silent } from './compiler'\nimport { reducePatches, registerPatches } from './patches'\nimport { isFunctionKey, SchemaNestedMap } from './shared'\nimport { transformFieldProps } from './transformer'\nimport type {\n ISchema,\n ISchemaTransformerOptions,\n SchemaEnum,\n SchemaKey,\n SchemaProperties,\n SchemaReactions,\n SchemaTypes,\n Slot,\n} from './types'\n\nexport class Schema implements ISchema {\n parent?: Schema\n root?: Schema\n name?: SchemaKey\n title?: ISchema['title']\n description?: ISchema['description']\n default?: any\n readOnly?: ISchema['readOnly']\n writeOnly?: ISchema['writeOnly']\n type?: SchemaTypes\n enum?: SchemaEnum\n const?: any\n multipleOf?: ISchema['multipleOf']\n exclusiveMaximum?: ISchema['exclusiveMaximum']\n maximum?: ISchema['maximum']\n exclusiveMinimum?: ISchema['exclusiveMinimum']\n minimum?: ISchema['minimum']\n maxLength?: ISchema['maxLength']\n minLength?: ISchema['minLength']\n pattern?: ISchema['pattern']\n maxItems?: ISchema['maxItems']\n minItems?: ISchema['minItems']\n uniqueItems?: ISchema['uniqueItems']\n maxProperties?: ISchema['maxProperties']\n minProperties?: ISchema['minProperties']\n required?: ISchema['required']\n format?: ISchema['format']\n $ref?: string\n $namespace?: string\n\n /** 嵌套 JSON Schema 描述 */\n definitions?: Record<string, Schema>\n properties?: Record<string, Schema>\n items?: Schema | Schema[]\n additionalItems?: Schema\n patternProperties?: Record<string, Schema>\n additionalProperties?: Schema\n\n /** 字段值 */\n value?: any\n /** 顺序描述 */\n index?: number\n /** 展示状态 */\n display?: ISchema['display']\n /** 校验器 */\n validator?: ISchema['validator']\n /** 装饰器 */\n decorator?: any\n /** 装饰器属性 */\n decoratorProps?: any\n /** 组件 */\n component?: any\n /** 组件属性 */\n componentProps?: any\n /** 组件响应器 */\n reactions?: SchemaReactions\n /** 内容 */\n content?: any\n data?: any\n visible?: boolean\n hidden?: boolean\n disabled?: boolean\n editable?: boolean\n readPretty?: boolean\n compileOmitted?: string[]\n slotNode?: Slot\n /** 渲染到父组件的具名插槽 */\n slot?: string;\n\n /** 第三方自定义扩展字段,使用 xKey 形式 */\n [key: `x${string}`]: any\n\n _isJSONSchemaObject = true\n\n version = '2.0'\n\n constructor(json: ISchema, parent?: Schema) {\n if (parent) {\n this.parent = parent\n this.root = parent.root\n } else {\n this.root = this\n }\n return this.fromJSON(json) as this\n }\n\n addProperty = (key: SchemaKey, schema: ISchema) => {\n this.properties = this.properties || {}\n this.properties[key] = new Schema(schema, this)\n this.properties[key].name = key\n return this.properties[key]\n }\n\n removeProperty = (key: SchemaKey) => {\n const schema = this.properties?.[key]\n delete this.properties?.[key]\n return schema\n }\n\n setProperties = (properties: SchemaProperties) => {\n for (const key in properties) {\n this.addProperty(key, properties[key])\n }\n return this\n }\n\n addPatternProperty = (key: SchemaKey, schema: ISchema) => {\n if (!schema) return\n this.patternProperties = this.patternProperties || {}\n this.patternProperties[key] = new Schema(schema, this)\n this.patternProperties[key].name = key\n return this.patternProperties[key]\n }\n\n removePatternProperty = (key: SchemaKey) => {\n const schema = this.patternProperties?.[key]\n delete this.patternProperties?.[key]\n return schema\n }\n\n setPatternProperties = (properties: SchemaProperties) => {\n if (!properties) return this\n for (const key in properties) {\n this.addPatternProperty(key, properties[key])\n }\n return this\n }\n\n setAdditionalProperties = (properties: ISchema) => {\n if (!properties) return\n this.additionalProperties = new Schema(properties)\n return this.additionalProperties\n }\n\n setItems = (schema: ISchema | ISchema[]) => {\n if (!schema) return\n if (Array.isArray(schema)) {\n this.items = schema.map(item => new Schema(item, this))\n } else {\n this.items = new Schema(schema, this)\n }\n return this.items\n }\n\n setAdditionalItems = (items: ISchema) => {\n if (!items) return\n this.additionalItems = new Schema(items, this)\n return this.additionalItems\n }\n\n findDefinitions = (ref: string) => {\n if (!ref || !this.root || !isStr(ref)) return\n if (ref.indexOf('#/') !== 0) return\n return FormPath.getIn(this.root, ref.substring(2).split('/'))\n }\n\n mapProperties = <T>(callback?: (schema: Schema, key: SchemaKey, index: number) => T): T[] => {\n return Schema.getOrderProperties(this).map(({ schema, key }, index) => {\n return callback?.(schema, key, index) as T\n })\n }\n\n mapPatternProperties = <T>(callback?: (schema: Schema, key: SchemaKey, index: number) => T): T[] => {\n return Schema.getOrderProperties(this, 'patternProperties').map(({ schema, key }, index) => {\n return callback?.(schema, key, index) as T\n })\n }\n\n reduceProperties = <P, R>(\n callback?: (buffer: P, schema: Schema, key: SchemaKey, index: number) => R,\n predicate?: P\n ): R => {\n let results: any = predicate\n Schema.getOrderProperties(this, 'properties').forEach(({ schema, key }, index) => {\n results = callback?.(results, schema, key, index)\n })\n return results\n }\n\n reducePatternProperties = <P, R>(\n callback?: (buffer: P, schema: Schema, key: SchemaKey, index: number) => R,\n predicate?: P\n ): R => {\n let results: any = predicate\n Schema.getOrderProperties(this, 'patternProperties').forEach(({ schema, key }, index) => {\n results = callback?.(results, schema, key, index)\n })\n return results\n }\n\n compile = (scope?: any) => {\n const schema = new Schema({}, this.parent)\n each(this, (value, key) => {\n if (isFn(value) && !isFunctionKey(key)) return\n if (key === 'parent' || key === 'root') return\n if (!SchemaNestedMap[key]) {\n ;(schema as any)[key] = value ? compile(value, scope) : value\n } else {\n ;(schema as any)[key] = value ? shallowCompile(value, scope) : value\n }\n })\n return schema\n }\n\n fromJSON = (json: ISchema) => {\n if (!json) return this\n if (Schema.isSchemaInstance(json)) return json\n each(reducePatches(json), (value, key) => {\n if (isFn(value) && !isFunctionKey(key)) return\n if (key === 'properties') {\n this.setProperties(value)\n } else if (key === 'patternProperties') {\n this.setPatternProperties(value)\n } else if (key === 'additionalProperties') {\n this.setAdditionalProperties(value)\n } else if (key === 'items') {\n this.setItems(value)\n } else if (key === 'additionalItems') {\n this.setAdditionalItems(value)\n } else if (key === '$ref') {\n this.fromJSON(this.findDefinitions(value))\n } else {\n ;(this as any)[key] = value\n }\n })\n return this\n }\n\n toJSON = (recursion = true): ISchema => {\n const results: any = {}\n each(this, (value: any, key) => {\n if ((isFn(value) && !isFunctionKey(key)) || key === 'parent' || key === 'root') return\n if (key === 'properties' || key === 'patternProperties') {\n if (!recursion) return\n results[key] = map(value, (item: Schema) => item?.toJSON?.())\n } else if (key === 'additionalProperties' || key === 'additionalItems') {\n if (!recursion) return\n results[key] = value?.toJSON?.()\n } else if (key === 'items') {\n if (!recursion) return\n if (Array.isArray(value)) {\n results[key] = value.map(item => item?.toJSON?.())\n } else {\n results[key] = value?.toJSON?.()\n }\n } else {\n results[key] = value\n }\n })\n return results\n }\n\n toFieldProps = (options?: ISchemaTransformerOptions): IFieldFactoryProps<any, any> => {\n return transformFieldProps(this, options)\n }\n\n static getOrderProperties = (schema: ISchema = {}, propertiesName: keyof ISchema = 'properties') => {\n const orderProperties = []\n const unorderProperties = []\n for (const key in schema[propertiesName]) {\n const item: any = (schema[propertiesName] as any)[key]\n const index = item?.['index']\n if (!isNaN(index)) {\n orderProperties[index] = { schema: item, key }\n } else {\n unorderProperties.push({ schema: item, key })\n }\n }\n return orderProperties.concat(unorderProperties).filter(item => !!item)\n }\n\n static compile = (expression: any, scope?: any) => {\n return compile(expression, scope)\n }\n\n static shallowCompile = (expression: any, scope?: any) => {\n return shallowCompile(expression, scope)\n }\n\n static isSchemaInstance = (value: any): value is Schema => {\n return value instanceof Schema\n }\n\n static registerCompiler = registerCompiler\n\n static registerPatches = registerPatches\n\n static silent = silent\n}\n","/// <reference types=\"vite/client\" />\nimport type {\n AnyComponent,\n ArraySchema,\n Fragment,\n FragmentOptions,\n FragmentPropsMap,\n ObjectSchema,\n SchemaCreator,\n SchemaPatchInput,\n SchemaPropertiesInput,\n VoidSchema,\n VoidSchemaCreator,\n} from './fragment-types'\nimport type { ISchema } from './types'\n\nfunction isFn(value: unknown): value is (...args: any[]) => any {\n return typeof value === 'function'\n}\n\nfunction isObj(value: unknown): value is Record<string, any> {\n return value !== null && typeof value === 'object'\n}\n\nfunction toArr<T>(value?: T | T[]): T[] {\n if (value === undefined) return []\n return Array.isArray(value) ? value : [value]\n}\n\nfunction sortPatches(patches: SchemaPatchInput[]) {\n const prePatches = patches.reduce<Array<Extract<SchemaPatchInput, (...args: any[]) => any>>>((pre, patch) => {\n if (!patch || typeof patch !== 'object') return pre\n if (patch.pre) pre.push(patch.patch)\n return pre\n }, [])\n\n return patches.reduce<Array<Extract<SchemaPatchInput, (...args: any[]) => any>>>((result, patch) => {\n if (!patch) return result\n if (typeof patch !== 'object') {\n result.push(patch)\n } else if (!patch.pre) {\n result.push(patch.patch)\n }\n return result\n }, prePatches)\n}\n\nfunction itemsPatch(schema: any, patches?: SchemaPatchInput | SchemaPatchInput[]) {\n if (schema.type === 'array') {\n const { items } = schema\n return {\n ...schema,\n items: isFn(items) ? items(patches) : items,\n }\n }\n return schema\n}\n\nfunction propertiesPatch(schema: any, patches?: SchemaPatchInput | SchemaPatchInput[]) {\n if (!('properties' in schema)) {\n return schema\n }\n const { properties } = schema\n if (!properties || !isObj(properties)) {\n return {\n ...schema,\n properties: undefined,\n }\n }\n return {\n ...schema,\n properties: Object.entries(properties).reduce<Record<string, ISchema>>((acc, [key, generator]) => {\n if (isFn(generator)) {\n acc[key] = generator(patches)\n return acc\n } else if (generator && isObj(generator)) {\n acc[key] = generator as ISchema\n return acc\n }\n return acc\n }, {}),\n }\n}\n\n/**\n * 默认装饰器补丁,语义对齐 formily-pro 的 defaultDecoratorPatch:\n * 仅处理 string 字段,且要求存在 title、未显式声明 decorator。\n */\nfunction createDefaultDecoratorPatch(decorator: any) {\n return (schema: ISchema): ISchema => {\n if (schema.type !== 'string' || schema.decorator !== undefined || schema.title === undefined) {\n return schema\n }\n return { ...schema, decorator }\n }\n}\n\n/**\n * 底层 schema 构造器。\n * 默认不内置任何 patch,组件 props 类型由 F / V / A 三个独立 map 注入。\n */\nexport function createFragment<\n F extends FragmentPropsMap = {},\n V extends FragmentPropsMap = {},\n A extends FragmentPropsMap = {},\n Scope extends object = {},\n DefaultDecorator extends AnyComponent<V> = AnyComponent<V>,\n>(options: FragmentOptions<V, DefaultDecorator> = {}): Fragment<F, V, A, Scope, DefaultDecorator> {\n const defaultDecoratorPatch = options.defaultDecorator\n ? createDefaultDecoratorPatch(options.defaultDecorator)\n : undefined\n\n function creator(_schema: any = {}): SchemaCreator | VoidSchemaCreator {\n return ((patches?: SchemaPatchInput | SchemaPatchInput[]) => {\n const realPatches = sortPatches([...toArr(defaultDecoratorPatch), ...toArr(options.patches), ...toArr(patches)])\n return (realPatches as any[])\n .concat([(schema: any) => itemsPatch(schema, patches), (schema: any) => propertiesPatch(schema, patches)])\n .reduce((acc, patch) => patch(acc), _schema) as ISchema\n }) as SchemaCreator | VoidSchemaCreator\n }\n\n function FField(schema?: Omit<ISchema, 'type'>) {\n return creator({ type: 'string', ...schema })\n }\n\n function FObject(properties?: any, schema?: Omit<ObjectSchema<V>, 'properties' | 'type'>) {\n return creator({ ...schema, properties, type: 'object' })\n }\n\n function FArray(items?: any, schema?: Omit<ArraySchema<A, V>, 'items' | 'type'>) {\n return creator({ ...schema, items, type: 'array' })\n }\n\n function FVoid(properties?: any, schema?: Omit<VoidSchema<V>, 'properties' | 'type'>) {\n return creator({ ...schema, properties, type: 'void' })\n }\n\n function transform(schema?: ISchema): ISchema {\n const loop = (schema?: ISchema): SchemaCreator | VoidSchemaCreator | undefined => {\n if (!schema) {\n return\n }\n\n const transformProperties = (properties?: Record<string, any>) => {\n if (!properties) {\n return\n }\n return Object.fromEntries(Object.entries(properties).map(([key, value]) => [key, loop(value)]))\n }\n\n if (schema.type === 'object') {\n const { properties, ...rest } = schema\n return FObject(transformProperties(properties) as SchemaPropertiesInput, rest)\n } else if (schema.type === 'array') {\n const { items, properties, ...rest } = schema\n return FArray(loop(items as ISchema), {\n ...rest,\n ...(properties ? { properties: transformProperties(properties) as SchemaPropertiesInput } : {}),\n })\n } else if (schema.type === 'void') {\n const { properties, ...rest } = schema\n return FVoid(transformProperties(properties), rest)\n }\n return FField(schema)\n }\n return loop(schema)?.() as ISchema\n }\n\n const fragmentBase = {\n Array: FArray,\n Object: FObject,\n Void: FVoid,\n Field: FField,\n transform,\n }\n\n // dev-only:同名同时登记为 void / array 时运行时按 array > void 静默取 array,这里给出一次显式提示\n if (import.meta.env.DEV) {\n const conflictedNames = (options.voidComponentNames ?? []).filter(name =>\n options.arrayComponentNames?.includes(name)\n )\n if (conflictedNames.length) {\n console.warn(\n `[formvk] Component name(s) \"${conflictedNames.join(', ')}\" are declared in both voidComponentNames and arrayComponentNames. The array classification takes precedence (array > void).`\n )\n }\n }\n\n // dev-only 去重:同一动态组件名的分类误用只告警一次\n const misclassifiedWarned = new Set<string>()\n\n const createFragmentByType = (type: string) => {\n if (options.arrayComponentNames?.includes(type)) {\n return (items?: any, schema?: any) => creator({ ...schema, items, type: 'array', component: type })\n }\n if (options.voidComponentNames?.includes(type)) {\n return (schema?: any) => creator({ ...schema, type: 'void', component: type })\n }\n // field 通道首参是 schema 对象;收到 creator 函数说明调用方按 array 约定 f.X(items) 使用却漏配 arrayComponentNames\n return (schema?: any) => {\n if (import.meta.env.DEV && isFn(schema) && !misclassifiedWarned.has(type)) {\n misclassifiedWarned.add(type)\n console.warn(\n `[formvk] Dynamic component \"${type}\" received a creator as its first argument but is not registered in arrayComponentNames, so it falls back to a field node (type: \"string\"). Register it in arrayComponentNames if it is an array component.`\n )\n }\n return creator({ ...schema, type: 'string', component: type })\n }\n }\n\n return new Proxy(fragmentBase, {\n get(target, type, receiver) {\n if (typeof type === 'string') {\n if (type in target) {\n return target[type as keyof typeof target]\n }\n if (type === 'toJSON') {\n return () => ({})\n }\n if (type === 'then') {\n // 显式置空 then:避免 fragment 被 Promise 链误识别为 thenable\n return undefined\n }\n return createFragmentByType(type)\n }\n return Reflect.get(target, type, receiver)\n },\n }) as unknown as Fragment<F, V, A, Scope, DefaultDecorator>\n}\n","import type {\n SchemaCreator,\n SchemaCreatorLike,\n SchemaPatchInput,\n SchemaPropertiesValues,\n ValidateSchemaProperties,\n} from './fragment-types'\nimport type { ISchema } from './types'\n\n/**\n * 对象 schema 快捷组装器。\n * 默认不内置任何 patch,creator 使用传入的 patches 展开。\n */\nexport function createSchema<\n Properties extends Record<string, unknown>,\n IValues extends SchemaPropertiesValues<Properties>,\n>(\n properties: Properties & ValidateSchemaProperties<Properties>,\n patches?: SchemaPatchInput | SchemaPatchInput[]\n): ISchema & {\n _$types$_: [IValues]\n} {\n const result = {\n type: 'object',\n properties: {},\n } as ISchema & {\n _$types$_: [IValues]\n }\n\n Object.keys(properties).forEach(key => {\n const generator = properties[key]\n if (typeof generator === 'function') {\n result.properties![key] = (generator as SchemaCreatorLike)(patches)\n } else if (generator && typeof generator === 'object') {\n result.properties![key] = generator as ISchema\n }\n })\n\n return result\n}\n\nexport type { SchemaCreator }\n","import type { SchemaExpression } from './types'\n\nconst variableName = /^[$A-Za-z_][0-9A-Za-z_$]*$/\n\nexport interface ExpressionFnOptions {\n /**\n * 是否展开参数\n * @default true\n * @example\n * objExp.fn.b('$args', { expand: false }) // {{function __b($args) {} return obj.b($args)}}\n * objExp.fn.b('$args', { expand: true }) // {{function __b(...$args) {} return obj.b(...$args)}}\n */\n expand?: boolean\n /**\n * 函数体\n * @example\n * objExp.fn.b('$args', 'title', { body: 'var title = $self.title' })\n * `{{function __b(...$args) {\n * var title = $self.title;\n * return obj.b(...$args, title)\n * }}}`\n */\n body?: string\n}\n\nexport type Args = '$args' | '$event' | ExpressionFnOptions | (string & {})\n\nexport type IExpressionStr<T, IsExp extends boolean> = T extends object\n ? {\n [K in keyof T]-?: ExpressionStr<IsExp> & (NonNullable<T[K]> & {}) & IExpressionStr<T[K], IsExp>\n }\n : NonNullable<T>\n\nexport type IExpressionFn<T> = {\n [K in keyof T]-?: T[K] extends (...args: any[]) => any\n ? (args?: Args, ..._args: Args[]) => SchemaExpression\n : T[K] extends object\n ? IExpressionFn<T[K]>\n : never\n}\n\nexport type Expression<T> = IExpressionStr<T, true> & {\n /**\n * 返回其中函数表达式集合\n * $args 表示函数的参数集合\n * $event 表示函数的第一个参数\n * $args 和 $event 不能同时传入\n * @example\n * objExp.fn.b('$args') // {{function __b(...$args) {} return obj.b(...$args)}}\n * objExp.fn.b('$event') // {{function __b($event) {} return obj.b($event)}}\n * objExp.fn.b('$self') // {{function __b() {} return obj.b($self)}}\n * // 不可以同时传入 $args 和 $event\n * objExp.fn.b('$args', '$event') // Error\n * objExp.fn.b('$args', '$self') // {{function __b(...$args) {} return obj.b(...$args, $self)}}\n * objExp.fn.b('$event', '$self') // {{function __b($event) {} return obj.b($event, $self)}}\n */\n fn: IExpressionFn<T>\n /**\n * 返回其中属性表达式集合\n * @example\n * objExp.exp.a // obj.a\n * objExp.exp['a.b'] // obj['a.b']\n * objExp.exp.a.b.c // obj.a.b.c\n */\n exp: IExpressionStr<T, false>\n}\n\nclass ExpressionStr<\n IsExp extends boolean,\n Result extends (IsExp extends true ? SchemaExpression : string & {}) = IsExp extends true ? SchemaExpression : string,\n> {\n constructor(\n private expression: string,\n private isExp: IsExp = false as IsExp\n ) {}\n\n getExpression(str: string) {\n return (this.isExp ? `{{${str}}}` : str) as Result\n }\n\n /**\n * 等于\n * @example\n * objExp.exp.a.eq(1) // obj.a === 1\n * objExp.exp.a.b.c.eq('1') // obj.a.b.c === \"1\"\n * objExp.exp.a.b.c.eq('$values.d', true) // obj.a.b.c === $values.d\n */\n eq(str: any, exp?: boolean) {\n return `${this.expression} === ${exp ? str : JSON.stringify(str)}` as Result\n }\n\n /**\n * 不等于\n * @example\n * objExp.exp.a.neq(1) // obj.a !== 1\n * objExp.exp.a.neq('$values.b', true) // obj.a !== $values.b\n */\n neq(str: any, exp?: boolean) {\n return `${this.expression} !== ${exp ? str : JSON.stringify(str)}` as Result\n }\n\n /**\n * 大于\n * @example\n * objExp.exp.a.gt('1') // obj.a > 1\n * objExp.exp.a.b.c.gt('1') // obj.a.b.c > 1\n */\n gt(str: any, exp?: boolean) {\n return `${this.expression} > ${exp ? str : JSON.stringify(str)}` as Result\n }\n\n /**\n * @example\n * objExp.exp.a.gte('1') // obj.a >= 1\n * objExp.exp.a.b.c.gte('1') // obj.a.b.c >= 1\n */\n gte(str: any, exp?: boolean) {\n return `${this.expression} >= ${exp ? str : JSON.stringify(str)}` as Result\n }\n\n /**\n * 小于\n * @example\n * objExp.exp.a.lt('1') // obj.a < 1\n * objExp.exp.a.b.c.lt('1') // obj.a.b.c < 1\n */\n lt(str: any, exp?: boolean) {\n return `${this.expression} < ${exp ? str : JSON.stringify(str)}` as Result\n }\n\n /**\n * 小于等于\n * @example\n * objExp.exp.a.lte(1) // obj.a <= 1\n * objExp.exp.a.b.c.lte('$values.d', true) // obj.a.b.c <= $values.d\n */\n lte(str: any, exp?: boolean) {\n return `${this.expression} <= ${exp ? str : JSON.stringify(str)}` as Result\n }\n\n /**\n * 与\n * @example\n * objExp.exp.a.and('1') // obj.a && 1\n */\n and(str: any, exp?: boolean) {\n return `${this.expression} && ${exp ? str : JSON.stringify(str)}` as Result\n }\n\n /**\n * 或\n * @example\n * objExp.exp.a.or(1) // obj.a || 1\n * objExp.exp.a.b.c.or('1') // obj.a.b.c || '1'\n * objExp.exp.a.or('1 || 2', true) // obj.a || 1 || 2\n * objExp.exp.a.or({b: 1}) // obj.a || {\"b\": 1}\n */\n or(str: any, exp?: boolean) {\n return `${this.expression} || ${exp ? str : JSON.stringify(str)}` as Result\n }\n\n /**\n * 取反\n * @example\n * objExp.exp.a.not() // !obj.a\n * objExp.exp.a.b.c.not() // !obj.a.b.c\n */\n not() {\n return `!${this.expression}` as Result\n }\n /**\n * 取bool值\n * @example\n * objExp.exp.a.bool() // !!obj.a\n * objExp.exp.a.b.c.bool() // !!obj.a.b.c\n */\n bool() {\n return `!!${this.expression}` as Result\n }\n\n /**\n * 三元表达式\n * @example\n * objExp.exp.a.ter(1, 2) // obj.a ? 1 : 2\n * objExp.exp.a.b.c.ter('1', '2') // obj.a.b.c ? \"1\" : \"2\"\n * objExp.exp.a.ter(\"obj.a\", \"abj.b\", true) // obj.a ? obj.a : abj.b\n */\n ter(a: any, b: any, exp?: boolean) {\n return `${this.expression} ? ${exp ? a : JSON.stringify(a)} : ${exp ? b : JSON.stringify(b)}` as Result\n }\n}\n\nexport function getExpression(expression: string, key: string): string {\n const isVariableName = variableName.test(key)\n\n return `${expression}${isVariableName ? `.${key}` : `[${JSON.stringify(key)}]`}`\n}\n\nfunction getLastArg(args: unknown[]): ExpressionFnOptions {\n const lastArg = args[args.length - 1]\n if (lastArg !== null && typeof lastArg === 'object') {\n return lastArg as ExpressionFnOptions\n }\n return {}\n}\n\nfunction getExpressionFn(expression: string, key: string): (...args: any[]) => any {\n const isVariableName = variableName.test(key)\n const funcName = isVariableName ? `__${key}` : '__IS_NOT_VARIABLE_NAME__'\n const expStr = getExpression(expression, key)\n const fn = function (...args: unknown[]) {\n const has$event = args.includes('$event')\n const has$args = args.includes('$args')\n if (has$event && has$args) {\n throw new Error('$event and $args cannot be passed in at the same time')\n }\n\n const lastArg = getLastArg(args)\n const { expand = true, body = '' } = lastArg\n if (body.includes('return')) {\n throw new Error('body cannot contain return')\n }\n const funcArgs = args\n .map(arg => {\n if (arg === '$args') {\n return expand ? '...$args' : '$args'\n }\n if (typeof arg === 'string') {\n return arg\n }\n })\n .filter(Boolean)\n .join(', ')\n\n const funcBody = `\n ${body}\n return ${expStr}(${funcArgs})`\n const $args = has$args ? (expand ? '...$args' : '$args') : has$event ? '$event' : ''\n return `{{function ${funcName}(${$args}) {${funcBody}\n}}}`\n }\n\n return new Proxy(fn, {\n get(_, key) {\n if (typeof key !== 'string') {\n throw new Error('key must be string')\n }\n\n return getExpressionFn(expStr, key)\n },\n apply(_, __, args) {\n return fn(...args)\n },\n })\n}\n\nexport function createExpressionFn<T>(expression: string): Expression<T>['fn'] {\n const fn = {} as Expression<T>['fn']\n\n return new Proxy(fn, {\n get(_, key) {\n if (typeof key !== 'string') {\n throw new Error('key must be string')\n }\n\n return getExpressionFn(expression, key)\n },\n })\n}\n\nfunction createExpressionStr(expression: string, isExp = false) {\n const expressionStr = new ExpressionStr(expression, isExp)\n const exp = expressionStr.getExpression(expression)\n\n const str = new String(exp)\n\n return new Proxy(str, {\n get(_, key, receiver) {\n if (typeof key === 'symbol') {\n if (key === Symbol.toPrimitive) {\n return () => exp\n }\n if (key === Symbol.toStringTag) {\n return 'String'\n }\n\n return Reflect.get(str, key, receiver).bind(exp)\n }\n\n // 过滤掉 __ 开头的属性\n // 过滤掉 String.prototype 上的属性\n // 过滤掉 Object.prototype 上的属性\n if (key.startsWith('__') || key in String.prototype || key in Object.prototype) {\n const result = Reflect.get(str, key, receiver)\n if (typeof result === 'function') {\n return result.bind(exp)\n }\n return result\n }\n\n // 过滤掉 toJSON 方法\n if (key === 'toJSON') {\n return () => exp\n }\n\n if (typeof expressionStr[key as keyof ExpressionStr<false>] === 'function') {\n return function (...args: unknown[]) {\n const result = (expressionStr[key as keyof ExpressionStr<false>] as (...args: any[]) => any)(...args)\n return expressionStr.getExpression(result)\n }\n }\n const expStr = getExpression(expression, key)\n\n return createExpressionStr(expStr, isExp)\n },\n })\n}\n\n/**\n * 返回一个对象的表达式主要方便于类型推导\n * @param expression 对象表达式 如 'obj'\n * @example\n * const objExp = createExpression<{ a: number; b: () => string,'1b': string }>('obj')\n * objExp.a // {{obj.a}}\n * objExp['1b'] // {{obj['1b']}}\n * objExp.fn.b() // {{function __b() {} return obj.b()}}\n * objExp.fn.b('$args') // {{function __b(...$args) {} return obj.b(...$args)}}\n * objExp.fn.b('$event') // {{function __b($event) {} return obj.b($event)}}\n * objExp.fn.b('$self', '$event') // {{function __b($event) {} return obj.b($self, $event)}}\n * objExp.fn.b('$self', '$args') // {{function __b(...$args) {} return obj.b($self, ...$args)}}\n */\nexport function createExpression<T extends object>(expression: string): Expression<T> {\n const obj: Record<string, unknown> = {}\n\n const fn = createExpressionFn<T>(expression)\n const exp = createExpressionStr(expression)\n return new Proxy(obj as Expression<T>, {\n get(_, key, receiver) {\n if (typeof key === 'symbol') {\n const value = Reflect.get(obj, key, receiver)\n if (typeof value === 'function') {\n return value.bind(obj)\n }\n return value\n }\n if (key === 'fn') {\n return fn\n }\n if (key === 'exp') {\n return exp\n }\n return createExpressionStr(getExpression(expression, key), true)\n },\n })\n}\n"],"mappings":";;;;AAKA,IAAM,mBAAmB,OAAO,IAAI,gBAAgB;;AAGpD,SAAgB,eAAe,KAAa;CAC1C,OAAO,UAAU,KAAK,GAAG;AAC3B;;;;;AAMA,IAAa,qBAA8C;CACzD,WAAW;CACX,WAAW;CACX,gBAAgB;CAChB,gBAAgB;CAChB,WAAW;CACX,WAAW;AACb;AAEA,SAAgB,cAAc,KAAa;CACzC,OAAO,eAAe,GAAG,KAAK,CAAC,CAAC,mBAAmB;AACrD;AAEA,IAAa,kBAA2C;CACtD,QAAQ;CACR,MAAM;CACN,YAAY;CACZ,mBAAmB;CACnB,sBAAsB;CACtB,OAAO;CACP,iBAAiB;CACjB,WAAW;AACb;;AAGA,IAAa,iBAAyC;CACpD,OAAO;CACP,aAAa;CACb,SAAS;CACT,MAAM;CACN,UAAU;CACV,WAAW;CACX,SAAS;CACT,MAAM;CACN,OAAO;CACP,UAAU;CACV,UAAU;CACV,YAAY;CACZ,SAAS;CACT,QAAQ;CACR,SAAS;CACT,SAAS;CACT,WAAW;CACX,WAAW;CACX,WAAW;CACX,gBAAgB;CAChB,gBAAgB;AAClB;;AAGA,IAAa,qBAA8C;CACzD,UAAU;CACV,QAAQ;CACR,UAAU;CACV,UAAU;CACV,WAAW;CACX,WAAW;CACX,SAAS;CACT,SAAS;CACT,kBAAkB;CAClB,kBAAkB;CAClB,OAAO;CACP,YAAY;CACZ,eAAe;CACf,eAAe;CACf,aAAa;AACf;AAEgC,OAAO,KAAK,cAAc;AAEvB,OAAO,KAAK,kBAA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QAAQ,UACV,aAAa;EAGf,IAAI,OAAO,cAAc,SAAuC,YAC9D,OAAO,SAAU,GAAG,MAAiB;GACnC,MAAM,SAAU,cAAc,IAAkC,CAA6B,GAAG,IAAI;GACpG,OAAO,cAAc,cAAc,MAAM;EAC3C;EAIF,OAAO,oBAFQ,cAAc,YAAY,GAEd,GAAQ,KAAK;CAC1C,EACF,CAAC;AACH;;;;;;;;;;;;;;AAeA,SAAgB,iBAAmC,YAAmC;CACpF,MAAM,MAA+B,CAAC;CAEtC,MAAM,KAAK,mBAAsB,UAAU;CAC3C,MAAM,MAAM,oBAAoB,UAAU;CAC1C,OAAO,IAAI,MAAM,KAAsB,EACrC,IAAI,GAAG,KAAK,UAAU;EACpB,IAAI,OAAO,QAAQ,UAAU;GAC3B,MAAM,QAAQ,QAAQ,IAAI,KAAK,KAAK,QAAQ;GAC5C,IAAI,OAAO,UAAU,YACnB,OAAO,MAAM,KAAK,GAAG;GAEvB,OAAO;EACT;EACA,IAAI,QAAQ,MACV,OAAO;EAET,IAAI,QAAQ,OACV,OAAO;EAET,OAAO,oBAAoB,cAAc,YAAY,GAAG,GAAG,IAAI;CACjE,EACF,CAAC;AACH"}
package/package.json CHANGED
@@ -1,6 +1,26 @@
1
1
  {
2
2
  "name": "@formvk/schema",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
3
+ "version": "0.1.0",
4
+ "description": "Formvk Schema",
5
+ "keywords": [
6
+ "form",
7
+ "formvk",
8
+ "formvk-schema",
9
+ "schema"
10
+ ],
11
+ "license": "MIT",
12
+ "author": "yiyunwan",
13
+ "type": "module",
14
+ "main": "dist/index.js",
15
+ "module": "dist/index.js",
16
+ "types": "dist/index.d.ts",
17
+ "dependencies": {
18
+ "@formvk/core": "^0.1.0",
19
+ "@formvk/reactive": "^0.1.0",
20
+ "@formvk/shared": "^0.1.0"
21
+ },
22
+ "devDependencies": {},
23
+ "scripts": {
24
+ "build": "tsc --noEmit && vite build"
25
+ }
6
26
  }
@@ -0,0 +1,334 @@
1
+ import { expect, test } from 'vitest'
2
+
3
+ import { compile, patchCompile, patchSchemaCompile, registerCompiler, shallowCompile, silent } from '../compiler'
4
+ import { Schema } from '../schema'
5
+
6
+ test('compile', () => {
7
+ expect(compile('{{123}}xx')).toEqual('{{123}}xx')
8
+ expect(compile('{{123}} ')).toEqual(123)
9
+ expect(compile('{{123}}')).toEqual(123)
10
+ expect(
11
+ compile({
12
+ hello: '{{123}}',
13
+ })
14
+ ).toEqual({
15
+ hello: 123,
16
+ })
17
+ expect(
18
+ compile({
19
+ array: ['{{123}}'],
20
+ })
21
+ ).toEqual({
22
+ array: [123],
23
+ })
24
+ const date: any = new Date()
25
+ date['expression'] = '{{123}}'
26
+ const compiledDate = compile(date)
27
+ expect(compiledDate).toEqual(date)
28
+ expect(compiledDate['expression']).toEqual('{{123}}')
29
+ const moment = { _isAMomentObject: true, expression: '{{123}}' }
30
+ const compiledMoment = compile(moment)
31
+ expect(compiledMoment).toEqual(moment)
32
+ expect(compiledMoment['expression']).toEqual('{{123}}')
33
+ const react = { _owner: true, $$typeof: true, expression: '{{123}}' }
34
+ const compiledReact = compile(react)
35
+ expect(compiledReact).toEqual(react)
36
+ expect(compiledReact['expression']).toEqual('{{123}}')
37
+ const actions = {
38
+ [Symbol.for('__REVA_ACTIONS')]: true,
39
+ expression: '{{123}}',
40
+ }
41
+ const compiledActions = compile(actions)
42
+ expect(compiledActions).toEqual(actions)
43
+ expect(compiledActions['expression']).toEqual('{{123}}')
44
+
45
+ const schema = new Schema({
46
+ type: 'object',
47
+ properties: {
48
+ aa: {
49
+ type: 'string',
50
+ component: 'Input',
51
+ componentProps: '{{123}}',
52
+ },
53
+ },
54
+ })
55
+ const compiledSchema = schema.compile()
56
+ expect(compiledSchema.toJSON()).toEqual(schema.toJSON())
57
+ expect(compiledSchema.properties?.['aa']['componentProps']).toEqual('{{123}}')
58
+ const toJSable = {
59
+ toJS() {
60
+ return {
61
+ aa: 123,
62
+ }
63
+ },
64
+ expression: '{{123}}',
65
+ }
66
+
67
+ const compiledToJSable = compile(toJSable)
68
+ expect(compiledToJSable).toEqual(toJSable)
69
+ expect(compiledToJSable['expression']).toEqual('{{123}}')
70
+
71
+ const toJSONable = {
72
+ toJSON() {
73
+ return {
74
+ aa: 123,
75
+ }
76
+ },
77
+ expression: '{{123}}',
78
+ }
79
+
80
+ const compiledToJSONable = compile(toJSONable)
81
+ expect(compiledToJSONable).toEqual(toJSONable)
82
+ expect(compiledToJSONable['expression']).toEqual('{{123}}')
83
+
84
+ const circularRef: any = {
85
+ expression: '{{123}}',
86
+ }
87
+ circularRef['self'] = circularRef
88
+
89
+ const compiledCircularRef = compile(circularRef)
90
+ expect(compiledCircularRef['expression']).toEqual(123)
91
+ })
92
+
93
+ test('shallowCompile', () => {
94
+ expect(shallowCompile('{{123}}xx')).toEqual('{{123}}xx')
95
+ expect(shallowCompile('{{123}} ')).toEqual(123)
96
+ expect(shallowCompile('{{123}}')).toEqual(123)
97
+ expect(
98
+ shallowCompile({
99
+ hello: '{{123}}',
100
+ })
101
+ ).toEqual({
102
+ hello: '{{123}}',
103
+ })
104
+ expect(
105
+ shallowCompile({
106
+ array: ['{{123}}'],
107
+ })
108
+ ).toEqual({
109
+ array: ['{{123}}'],
110
+ })
111
+ expect(shallowCompile(['{{123}}'])).toEqual(['{{123}}'])
112
+ expect(shallowCompile([{ kk: '{{123}}' }])).toEqual([{ kk: '{{123}}' }])
113
+ })
114
+
115
+ test('unsilent', () => {
116
+ silent(false)
117
+ expect(() => compile('{{ ( }}')).toThrowError()
118
+ })
119
+
120
+ test('silent', () => {
121
+ silent(true)
122
+ expect(() => compile('{{ ( }}')).not.toThrowError()
123
+ silent(false)
124
+ })
125
+
126
+ test('patchCompile', () => {
127
+ const targetState = {
128
+ title: '',
129
+ description: '',
130
+ dataSource: [22],
131
+ }
132
+ patchCompile(
133
+ targetState as any,
134
+ {
135
+ title: '132',
136
+ description: '{{"Hello world"}}',
137
+ dataSource: [1, 2, 3, '{{333}}'],
138
+ extend: '333',
139
+ },
140
+ {}
141
+ )
142
+ expect(targetState).toEqual({
143
+ title: '132',
144
+ description: 'Hello world',
145
+ dataSource: [1, 2, 3, 333],
146
+ })
147
+ })
148
+
149
+ test('patchSchemaCompile', () => {
150
+ const targetState = {
151
+ title: '',
152
+ description: '',
153
+ dataSource: [22],
154
+ }
155
+ patchSchemaCompile(
156
+ targetState as any,
157
+ {
158
+ title: '132',
159
+ description: '{{"Hello world"}}',
160
+ enum: [1, 2, 3, '{{333}}'],
161
+ reactions: {
162
+ fulfill: {
163
+ schema: {
164
+ title: 'hello',
165
+ },
166
+ },
167
+ },
168
+ version: '1.2.3',
169
+ },
170
+ {}
171
+ )
172
+ expect(targetState).toEqual({
173
+ title: '132',
174
+ description: 'Hello world',
175
+ dataSource: [
176
+ { label: 1, value: 1 },
177
+ { label: 2, value: 2 },
178
+ { label: 3, value: 3 },
179
+ { label: 333, value: 333 },
180
+ ],
181
+ })
182
+ })
183
+
184
+ test('patchSchemaCompile demand un initialized', () => {
185
+ function setValidatorRule(name: string, value: any) {
186
+ targetState[name] = value
187
+ }
188
+ const targetState: any = {
189
+ title: '',
190
+ description: '',
191
+ dataSource: [22],
192
+ setValidatorRule,
193
+ }
194
+ patchSchemaCompile(
195
+ targetState,
196
+ {
197
+ title: '132',
198
+ display: undefined,
199
+ hidden: null,
200
+ description: '{{"Hello world"}}',
201
+ enum: [1, 2, 3, '{{333}}'],
202
+ format: 'phone',
203
+ reactions: {
204
+ fulfill: {
205
+ schema: {
206
+ title: 'hello',
207
+ },
208
+ },
209
+ },
210
+ version: '1.2.3',
211
+ } as any,
212
+ {},
213
+ true
214
+ )
215
+ expect(targetState).toEqual({
216
+ title: '132',
217
+ description: 'Hello world',
218
+ hidden: null,
219
+ format: 'phone',
220
+ setValidatorRule,
221
+ dataSource: [
222
+ { label: 1, value: 1 },
223
+ { label: 2, value: 2 },
224
+ { label: 3, value: 3 },
225
+ { label: 333, value: 333 },
226
+ ],
227
+ })
228
+ })
229
+
230
+ test('patchSchemaCompile demand initialized keeps static keys', () => {
231
+ const targetState: any = {
232
+ initialized: true,
233
+ title: '',
234
+ description: '',
235
+ dataSource: [22],
236
+ }
237
+ patchSchemaCompile(
238
+ targetState,
239
+ {
240
+ title: '132',
241
+ description: '{{"Hello world"}}',
242
+ enum: [1, 2, 3],
243
+ version: '1.2.3',
244
+ },
245
+ {},
246
+ true
247
+ )
248
+ // 静态值不回写,表达式值视为动态依赖,仍然回写
249
+ expect(targetState).toEqual({
250
+ initialized: true,
251
+ title: '',
252
+ description: 'Hello world',
253
+ dataSource: [22],
254
+ })
255
+ })
256
+
257
+ test('patchSchemaCompile validator expression', () => {
258
+ const targetState: any = {
259
+ title: '',
260
+ validator: [],
261
+ }
262
+ patchSchemaCompile(
263
+ targetState,
264
+ {
265
+ title: '132',
266
+ validator: [
267
+ {
268
+ remoteCheckUniq: '{{field.value}}',
269
+ },
270
+ ],
271
+ version: '1.2.3',
272
+ },
273
+ {
274
+ field: {
275
+ value: 888,
276
+ },
277
+ }
278
+ )
279
+ expect(targetState).toEqual({
280
+ title: '132',
281
+ validator: [{ remoteCheckUniq: 888 }],
282
+ })
283
+
284
+ const targetOmitState: any = {
285
+ title: '',
286
+ validator: [],
287
+ }
288
+ patchSchemaCompile(
289
+ targetOmitState,
290
+ {
291
+ title: '132',
292
+ compileOmitted: ['validator'],
293
+ validator: [
294
+ {
295
+ remoteCheckUniq: '{{field.value}}',
296
+ },
297
+ ],
298
+ version: '1.2.3',
299
+ },
300
+ {
301
+ field: {
302
+ value: 888,
303
+ },
304
+ }
305
+ )
306
+ expect(targetOmitState).toEqual({
307
+ title: '132',
308
+ validator: [{ remoteCheckUniq: '{{field.value}}' }],
309
+ })
310
+ })
311
+
312
+ test('registerCompiler', () => {
313
+ registerCompiler(() => {
314
+ return 'compiled'
315
+ })
316
+ expect(compile('{{123}}xx')).toEqual('{{123}}xx')
317
+ expect(compile('{{123}} ')).toEqual('compiled')
318
+ expect(compile('{{123}}')).toEqual('compiled')
319
+ expect(
320
+ compile({
321
+ hello: '{{123}}',
322
+ })
323
+ ).toEqual({
324
+ hello: 'compiled',
325
+ })
326
+ expect(
327
+ compile({
328
+ array: ['{{123}}'],
329
+ })
330
+ ).toEqual({
331
+ array: ['compiled'],
332
+ })
333
+ registerCompiler(null as any)
334
+ })
@@ -0,0 +1,83 @@
1
+ import { describe, expect, test } from 'vitest'
2
+
3
+ import { createSchema } from '../create-schema'
4
+ import { createFragment } from '../fragment'
5
+
6
+ describe('createSchema', () => {
7
+ const f = createFragment()
8
+
9
+ test('should create schema', () => {
10
+ expect(
11
+ createSchema({
12
+ string: f.Field({ title: '字符串', component: 'Input' }),
13
+ })
14
+ ).toEqual({
15
+ type: 'object',
16
+ properties: {
17
+ string: {
18
+ type: 'string',
19
+ title: '字符串',
20
+ component: 'Input',
21
+ },
22
+ },
23
+ })
24
+ })
25
+
26
+ test('accepts plain schema and skips nil', () => {
27
+ expect(
28
+ createSchema({
29
+ plain: { type: 'number', title: '数字' },
30
+ empty: null,
31
+ missing: undefined,
32
+ })
33
+ ).toEqual({
34
+ type: 'object',
35
+ properties: {
36
+ plain: { type: 'number', title: '数字' },
37
+ },
38
+ })
39
+ })
40
+
41
+ test('forwards patches to creators', () => {
42
+ const schema = createSchema(
43
+ {
44
+ name: f.Field(),
45
+ },
46
+ [
47
+ inner => ({
48
+ ...inner,
49
+ data: { patched: true },
50
+ }),
51
+ ]
52
+ )
53
+ expect(schema.properties).toEqual({
54
+ name: {
55
+ type: 'string',
56
+ data: { patched: true },
57
+ },
58
+ })
59
+ })
60
+
61
+ test('composes nested createSchema', () => {
62
+ expect(
63
+ createSchema({
64
+ user: createSchema({
65
+ name: f.Field({ required: true }),
66
+ }),
67
+ })
68
+ ).toEqual({
69
+ type: 'object',
70
+ properties: {
71
+ user: {
72
+ type: 'object',
73
+ properties: {
74
+ name: {
75
+ type: 'string',
76
+ required: true,
77
+ },
78
+ },
79
+ },
80
+ },
81
+ })
82
+ })
83
+ })