feat:扩展插件前端能力,支持向响应式前端内追加自定义组件 - #293
Open
HarcoChen wants to merge 2 commits into
Open
Conversation
Reviewer's Guide扩展插件前端契约,使脚本可以在 schema 中声明非持久化的自定义元素;将后端的 manifest 解析和资源校验接入一个新的前端 SchemaForm 插件自定义元素生命周期时序图sequenceDiagram
participant SchemaForm
participant PluginSchemaElement
participant PluginFrontendLoader as pluginFrontendLoader
participant CustomElement
SchemaForm->>PluginSchemaElement: loadElement()
PluginSchemaElement->>pluginFrontendLoader: ensurePluginFrontendElement(descriptor)
pluginFrontendLoader->>pluginFrontendLoader: ensureStyle(url)
pluginFrontendLoader->>pluginFrontendLoader: loadEntryScript(entry_asset_url, cacheKey)
pluginFrontendLoader-->>PluginSchemaElement: waitForElement(element_tag)
PluginSchemaElement-->>SchemaForm: attachListeners()
CustomElement-->>PluginSchemaElement: handleFieldChange(event)
PluginSchemaElement->>SchemaForm: handlePluginFieldChange(detail)
SchemaForm->>SchemaForm: updateFieldValue(path, value)
CustomElement-->>PluginSchemaElement: handleFormPatch(event)
PluginSchemaElement->>SchemaForm: handlePluginFormPatch(detail)
SchemaForm->>SchemaForm: deepMergeRecord(modelValue, patch)
解析后端 plugin-element schema 字段的流程图flowchart TD
A[_build_schema_artifacts] --> B[_resolve_schema_frontend_elements]
B -->|iterate groups/fields| C{field_schema.type == plugin-element}
C -->|no| B
C -->|yes| D{frontend_plugin provided?}
D -->|no| E[raise ValueError]
D -->|yes| F[resolve_plugin_frontend_element]
F --> G[_load_frontend_dev_manifest]
G --> H{dev manifest found?}
H -->|yes| I[PluginFrontendDevManifest -> PluginFrontendElementDescriptor]
H -->|no| J[load_frontend_manifest]
J --> K[load_frontend_asset for entry/style]
K --> L[PluginFrontendElementDescriptor]
I --> M[set field_schema.persisted = False]
L --> M
M --> N[set field_schema.frontend_extension = descriptor.model_dump]
File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your Experience访问你的 dashboard 以:
Getting HelpOriginal review guide in EnglishReviewer's GuideExtends the plugin frontend contract so scripts can declare non-persistent custom elements in schemas, wiring backend manifest resolution and asset validation to a new frontend PluginSchemaElement renderer that loads plugin custom elements, syncs reactive props, and handles granular form updates, while also refactoring shared loader logic and adding tests/utilities. Sequence diagram for SchemaForm plugin custom element lifecyclesequenceDiagram
participant SchemaForm
participant PluginSchemaElement
participant PluginFrontendLoader as pluginFrontendLoader
participant CustomElement
SchemaForm->>PluginSchemaElement: loadElement()
PluginSchemaElement->>pluginFrontendLoader: ensurePluginFrontendElement(descriptor)
pluginFrontendLoader->>pluginFrontendLoader: ensureStyle(url)
pluginFrontendLoader->>pluginFrontendLoader: loadEntryScript(entry_asset_url, cacheKey)
pluginFrontendLoader-->>PluginSchemaElement: waitForElement(element_tag)
PluginSchemaElement-->>SchemaForm: attachListeners()
CustomElement-->>PluginSchemaElement: handleFieldChange(event)
PluginSchemaElement->>SchemaForm: handlePluginFieldChange(detail)
SchemaForm->>SchemaForm: updateFieldValue(path, value)
CustomElement-->>PluginSchemaElement: handleFormPatch(event)
PluginSchemaElement->>SchemaForm: handlePluginFormPatch(detail)
SchemaForm->>SchemaForm: deepMergeRecord(modelValue, patch)
Flow diagram for resolving backend plugin-element schema fieldsflowchart TD
A[_build_schema_artifacts] --> B[_resolve_schema_frontend_elements]
B -->|iterate groups/fields| C{field_schema.type == plugin-element}
C -->|no| B
C -->|yes| D{frontend_plugin provided?}
D -->|no| E[raise ValueError]
D -->|yes| F[resolve_plugin_frontend_element]
F --> G[_load_frontend_dev_manifest]
G --> H{dev manifest found?}
H -->|yes| I[PluginFrontendDevManifest -> PluginFrontendElementDescriptor]
H -->|no| J[load_frontend_manifest]
J --> K[load_frontend_asset for entry/style]
K --> L[PluginFrontendElementDescriptor]
I --> M[set field_schema.persisted = False]
L --> M
M --> N[set field_schema.frontend_extension = descriptor.model_dump]
File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
There was a problem hiding this comment.
Hey - 我已经审查了你的修改,看起来非常棒!
帮我变得更有用吧!请在每条评论上点 👍 或 👎,我会根据你的反馈改进后续的代码评审。
Original comment in English
Hey - I've reviewed your changes and they look great!
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Motivation
例如MFW、OKWW、MAAEND响应式布局并不令人满意,一个较为明显的例子是“任务列表”这样的一个组件。
当前采取的策略是这些脚本把所需的前端文件硬编码在MAS本体内,这样插件和本体还是耦合的。
PR希望更新契约以允许脚本向SchemaForm内追加自定义的组件。
Overview
Test
提交了一个Unit Test因为这是针对本体的修改。
Summary by Sourcery
为脚本/用户 schema 添加对非持久化插件自定义元素的支持,并将其接入响应式的 SchemaForm,使插件可以提供自己的前端组件。
New Features:
plugin-element字段,通过统一的描述符解析其前端资源,并根据插件 manifest 进行校验。scriptId、userId、scriptConfig、mode)暴露给 SchemaForm,使插件组件可以根据使用场景调整行为。Bug Fixes:
Enhancements:
ensurePluginFrontendElement帮助方法,在页面与 schema 字段之间共享。plugin-elementschema 字段视为仅运行时(非持久化)字段,并在渲染自定义元素时隐藏标准的 label/required 装饰。deep-mmerge工具及测试,用于在应用来自插件组件的嵌套表单补丁时避免覆盖同级字段。Tests:
plugin-element的 manifest 解析、对未声明元素的拒绝行为,以及plugin-elementschema 字段的非持久化特性及其正确接线。Original summary in English
Summary by Sourcery
Add support for non-persisted plugin custom elements in script/user schemas and wire them into the reactive SchemaForm so plugins can provide their own frontend components.
New Features:
Bug Fixes:
Enhancements:
Tests: