From ed81701373e0925ae8b10af00edb27ca4929cbbf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=B8=A5=E6=B5=A9?= Date: Mon, 18 Nov 2024 15:32:33 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E6=9B=B4=E6=96=B0=20CI=20=E9=85=8D?= =?UTF-8?q?=E7=BD=AE=E4=BB=A5=E9=99=90=E5=88=B6=E6=8E=A8=E9=80=81=E5=88=B0?= =?UTF-8?q?=20main=20=E5=88=86=E6=94=AF=EF=BC=8C=E6=9B=B4=E6=96=B0=20READM?= =?UTF-8?q?E=20=E9=93=BE=E6=8E=A5=EF=BC=8C=E6=B7=BB=E5=8A=A0=E5=BF=85?= =?UTF-8?q?=E5=A1=AB=E9=A1=B9=E6=98=9F=E5=8F=B7=E6=8F=92=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/ci.yaml | 2 ++ README.md | 2 +- formkit.config.ts | 43 +++++++++++++++++++++++++++++++++++++-- src/App.vue | 7 +++++-- 4 files changed, 49 insertions(+), 5 deletions(-) diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 4f2c0b8..12807f0 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -1,6 +1,8 @@ # https://cn.vitejs.dev/guide/static-deploy on: push: + branches: + - main jobs: surge: diff --git a/README.md b/README.md index 2ba3208..01edf78 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # Vue FormKit Example -- https://github.com/mathsgod/formkit-element$0 +- https://github.com/mathsgod/formkit-element --- - https://themes.formkit.com/editor?theme=regenesis diff --git a/formkit.config.ts b/formkit.config.ts index 713de50..d3f7644 100644 --- a/formkit.config.ts +++ b/formkit.config.ts @@ -1,4 +1,4 @@ -import type { FormKitOptions } from '@formkit/core' +import type { FormKitExtendableSchemaRoot, FormKitNode, FormKitOptions } from '@formkit/core' import { createI18nPlugin, zh } from '@formkit/i18n' import { genesisIcons } from '@formkit/icons' import { checkbox, createLibraryPlugin, form, group, range, submit, text } from '@formkit/inputs' @@ -15,7 +15,46 @@ const theme = undefined; const icons = genesisIcons; const themePlugin = createThemePlugin(theme, icons/* , iconLoaderUrl, iconLoader */) + +const legends = ['checkbox_multi', 'radio_multi', 'repeater', 'transferlist']; +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.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?.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 + } + }) +} + export default { - plugins: [library, themePlugin, bindings, i18n, validation,], + plugins: [library, themePlugin, bindings, i18n, validation, addAsteriskPlugin], config: { rootClasses }, } satisfies FormKitOptions \ No newline at end of file diff --git a/src/App.vue b/src/App.vue index 1abf75a..69da120 100644 --- a/src/App.vue +++ b/src/App.vue @@ -15,16 +15,18 @@ const castNumber = (node: FormKitNode) => { onMounted(() => { + console.group('onMounted') const nameNode = getNode('nameNodeId') Object.assign(window, { nameNode }) - console.debug('[onMounted]', `nameNode :>> `, nameNode); + console.debug(`nameNode :>> `, nameNode); const schemaGroupInput = nameNode!.root.at('schemaGroup.input') - console.debug('[onMounted]', `schemaGroupInput :>> `, schemaGroupInput); + console.debug(`schemaGroupInput :>> `, schemaGroupInput); nameNode!.on('commit', ({ payload }) => { console.debug('[nameNode] [on commit]', `payload :>> `, payload); schemaGroupInput!.input(`姓名:${payload}`) }) + console.groupEnd() }) const SCHEMA: FormKitSchemaDefinition = [ @@ -89,6 +91,7 @@ const SCHEMA: FormKitSchemaDefinition = [ id="nameNodeId" label="姓名" help="别人都叫你什么?" + some-attr="some-attr-value" />