feat: 更新 Asterisk 插件的导入路径,优化配置文件结构
This commit is contained in:
40
formkit.config.addAsteriskPlugin.ts
Normal file
40
formkit.config.addAsteriskPlugin.ts
Normal file
@ -0,0 +1,40 @@
|
||||
import type { FormKitNode } from "@formkit/core";
|
||||
|
||||
const legends = ['checkbox_multi', 'radio_multi', 'repeater', 'transferlist'];
|
||||
export function addAsteriskPlugin(node: FormKitNode) {
|
||||
if (['button', 'submit', 'hidden', 'group', 'list', 'meta'].includes(node.props.type)) return;
|
||||
|
||||
node.on('created', () => {
|
||||
const legendOrLabel = legends.includes(`${node.props.type}${node.props.options ? '_multi' : ''}`) ? 'legend' : 'label';
|
||||
|
||||
console.group('[node created]', node.props.label || node.props.submitLabel)
|
||||
console.debug(`node :>> `, node);
|
||||
console.debug(`node.props.definition :>> `, node.props.definition);
|
||||
// if (typeof node.props.definition!.schema === 'function') {
|
||||
// console.debug(`node.props.definition.schema.call :>> `, node.props.definition!.schema.call(node.props.definition, {}));
|
||||
// }
|
||||
console.debug(`legendOrLabel :>> `, legendOrLabel);
|
||||
console.groupEnd()
|
||||
if (!node.props.definition) return;
|
||||
|
||||
if (node.props.definition.schemaMemoKey) {
|
||||
node.props.definition.schemaMemoKey += `${node.props.options ? '_multi' : ''}_add_asterisk`;
|
||||
};
|
||||
|
||||
const schemaFn = node.props.definition.schema!;
|
||||
node.props.definition!.schema = (sectionsSchema = {}) => {
|
||||
sectionsSchema[legendOrLabel] = {
|
||||
children: ['$label', {
|
||||
$el: 'span',
|
||||
if: '$state.required',
|
||||
attrs: {
|
||||
class: '$classes.asterisk',
|
||||
},
|
||||
children: ['*']
|
||||
}]
|
||||
}
|
||||
|
||||
return typeof schemaFn === 'function' ? schemaFn(sectionsSchema) : schemaFn
|
||||
}
|
||||
})
|
||||
}
|
Reference in New Issue
Block a user