feat: 更新 Asterisk 插件的导入路径,优化配置文件结构
Some checks failed
/ test (push) Failing after 28s
/ surge (push) Successful in 48s

This commit is contained in:
严浩
2024-11-25 09:17:33 +08:00
parent 781eb610ce
commit 07320f09b0
2 changed files with 1 additions and 1 deletions

View 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
}
})
}