tiun 0.0.2.1 → 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.
- checksums.yaml +4 -4
- data/.forgejo/workflows/codeberg-tests.yml +226 -0
- data/.gitignore +7 -3
- data/.prettierrc.json +5 -0
- data/.rubocop.yml +221 -0
- data/AGENTS.md +132 -0
- data/Appraisals +18 -0
- data/CONTRIBUTING.md +80 -0
- data/CONTRIBUTING.ru.md +326 -0
- data/Gemfile +20 -1
- data/README.md +52 -23
- data/README.ru.md +72 -0
- data/Rakefile +10 -4
- data/TODO +2 -6
- data/bin/console +4 -3
- data/config/cucumber.yml +1 -0
- data/cucumber.mjs +6 -0
- data/docs/backend.md +73 -0
- data/docs/backend.ru.md +73 -0
- data/docs/components/approved.md +39 -0
- data/docs/components/approved.ru.md +39 -0
- data/docs/components/attachment-field.md +7 -0
- data/docs/components/attachment-field.ru.md +8 -0
- data/docs/components/attachment.md +48 -0
- data/docs/components/attachment.ru.md +48 -0
- data/docs/components/avatar.md +39 -0
- data/docs/components/avatar.ru.md +37 -0
- data/docs/components/chip.md +119 -0
- data/docs/components/chip.ru.md +99 -0
- data/docs/components/configuration.md +137 -0
- data/docs/components/configuration.ru.md +138 -0
- data/docs/components/daylight.md +41 -0
- data/docs/components/daylight.ru.md +41 -0
- data/docs/components/defaults.md +148 -0
- data/docs/components/defaults.ru.md +149 -0
- data/docs/components/documents.md +64 -0
- data/docs/components/documents.ru.md +64 -0
- data/docs/components/external-form-fields.ru.md +137 -0
- data/docs/components/external-renderers.md +50 -0
- data/docs/components/external-renderers.ru.md +51 -0
- data/docs/components/feedback.md +76 -0
- data/docs/components/feedback.ru.md +76 -0
- data/docs/components/footer.md +49 -0
- data/docs/components/footer.ru.md +49 -0
- data/docs/components/forms.md +177 -0
- data/docs/components/forms.ru.md +177 -0
- data/docs/components/images.md +111 -0
- data/docs/components/images.ru.md +111 -0
- data/docs/components/index.md +140 -0
- data/docs/components/index.ru.md +140 -0
- data/docs/components/intro.md +150 -0
- data/docs/components/intro.ru.md +150 -0
- data/docs/components/login.md +600 -0
- data/docs/components/login.ru.md +602 -0
- data/docs/components/methods.md +59 -0
- data/docs/components/methods.ru.md +59 -0
- data/docs/components/player.md +72 -0
- data/docs/components/player.ru.md +69 -0
- data/docs/components/profile.md +82 -0
- data/docs/components/profile.ru.md +82 -0
- data/docs/components/record-manager.md +69 -0
- data/docs/components/record-manager.ru.md +69 -0
- data/docs/components/row-column.ru.md +51 -0
- data/docs/components/rtfer.md +76 -0
- data/docs/components/rtfer.ru.md +76 -0
- data/docs/components/schema-calendar.md +86 -0
- data/docs/components/schema-calendar.ru.md +84 -0
- data/docs/components/schema-records.md +166 -0
- data/docs/components/schema-records.ru.md +166 -0
- data/docs/components/signup.md +194 -0
- data/docs/components/signup.ru.md +194 -0
- data/docs/components/slug-flow.md +97 -0
- data/docs/components/slug-flow.ru.md +59 -0
- data/docs/components/stockee.md +21 -0
- data/docs/components/stockee.ru.md +21 -0
- data/docs/components/text-views.md +64 -0
- data/docs/components/text-views.ru.md +57 -0
- data/docs/components/theme.md +212 -0
- data/docs/components/theme.ru.md +212 -0
- data/docs/components/tooltip.md +37 -0
- data/docs/components/tooltip.ru.md +30 -0
- data/docs/components/validation.md +153 -0
- data/docs/components/validation.ru.md +154 -0
- data/docs/components.md +31 -0
- data/docs/components.ru.md +31 -0
- data/docs/controller-names.md +23 -0
- data/docs/controller-names.ru.md +23 -0
- data/docs/examples/dneslov-frontend.md +38 -0
- data/docs/examples/dneslov-frontend.ru.md +39 -0
- data/docs/examples/dneslov-frontend.yaml +266 -0
- data/docs/frontend.md +316 -0
- data/docs/frontend.ru.md +332 -0
- data/docs/migrations/component-configuration.md +48 -0
- data/docs/migrations/component-configuration.ru.md +40 -0
- data/docs/migrations/component-shell-proposal.md +108 -0
- data/docs/migrations/component-shell-proposal.ru.md +150 -0
- data/docs/migrations/theme-layout.md +83 -0
- data/docs/migrations/theme-layout.ru.md +97 -0
- data/docs/reference.md +45 -0
- data/docs/reference.ru.md +1763 -0
- data/docs/resources.md +348 -0
- data/docs/resources.ru.md +349 -0
- data/docs/tasks/DNE-542.md +11 -0
- data/docs/tasks/DNE-566.md +8 -0
- data/docs/tasks/chip-segments.md +54 -0
- data/docs/tasks/configured-profile.md +73 -0
- data/docs/tasks/frontend/auth-form.md +7 -0
- data/docs/tasks/frontend/avatar.md +5 -0
- data/docs/tasks/frontend/component-removal.md +11 -0
- data/docs/tasks/frontend/dynamic-field.md +6 -0
- data/docs/tasks/frontend/field-caption.md +38 -0
- data/docs/tasks/frontend/form-core.md +65 -0
- data/docs/tasks/frontend/form-field-context.md +16 -0
- data/docs/tasks/frontend/form-session-renewal.md +58 -0
- data/docs/tasks/frontend/frontend-components.md +7 -0
- data/docs/tasks/frontend/frontend-docs.md +6 -0
- data/docs/tasks/frontend/frontend-layout.md +13 -0
- data/docs/tasks/frontend/frontend-methods.md +15 -0
- data/docs/tasks/frontend/frontend-other.md +13 -0
- data/docs/tasks/frontend/frontend-services.md +7 -0
- data/docs/tasks/frontend/fusion.md +22 -0
- data/docs/tasks/frontend/heading-core.md +5 -0
- data/docs/tasks/frontend/i18n-scope.md +37 -0
- data/docs/tasks/frontend/index-runtime.md +48 -0
- data/docs/tasks/frontend/inline-form.md +7 -0
- data/docs/tasks/frontend/intro-core.md +11 -0
- data/docs/tasks/frontend/login.md +8 -0
- data/docs/tasks/frontend/menu-branch.md +5 -0
- data/docs/tasks/frontend/paginator.md +7 -0
- data/docs/tasks/frontend/records-core.md +35 -0
- data/docs/tasks/frontend/resource-source-core.md +12 -0
- data/docs/tasks/frontend/signup.md +8 -0
- data/docs/tasks/frontend/span-body.md +16 -0
- data/docs/tasks/frontend/text-commonee.md +48 -0
- data/docs/tasks/frontend/theme-field.md +31 -0
- data/docs/tasks/frontend/theme-menu.md +8 -0
- data/docs/tasks/frontend/theme-settings.md +10 -0
- data/docs/tasks/frontend/view-content-core.md +12 -0
- data/docs/tasks/frontend/view-source-core.md +12 -0
- data/docs/tasks/ruby-extension-compatibility.ru.md +74 -0
- data/docs/tasks/todo-code-climate.md +8 -0
- data/docs/tasks/todo-compatibility.md +50 -0
- data/docs/tasks/todo-reek.md +5 -0
- data/docs/tasks/todo-yard-inch.md +7 -0
- data/eslint.config.mjs +15 -0
- data/exe/tiun +1 -0
- data/gemfiles/rails_7_0.gemfile +16 -0
- data/gemfiles/rails_7_2.gemfile +17 -0
- data/lib/config/locale/browser.en.yml +43 -0
- data/lib/config/locale/browser.ru.yml +35 -0
- data/lib/config/locale/confirmation.en.yml +16 -0
- data/lib/config/locale/confirmation.ru.yml +16 -0
- data/lib/config/locale/errors.en.yml +57 -0
- data/lib/config/locale/errors.ru.yml +47 -0
- data/lib/config/locale/form_delay.en.yml +11 -0
- data/lib/config/locale/form_delay.ru.yml +11 -0
- data/lib/config/locale/recovery.en.yml +14 -0
- data/lib/config/locale/ru.yml +272 -6
- data/lib/config/routes.rb +5 -11
- data/lib/tasks/tiun/translations.rake +12 -0
- data/lib/tiun/actor/validate.rb +3 -2
- data/lib/tiun/actor.rb +13 -10
- data/lib/tiun/api_not_found.rb +16 -0
- data/lib/tiun/attributes.rb +8 -7
- data/lib/tiun/auth/attribute_models.rb +32 -0
- data/lib/tiun/auth/controller/discord.rb +26 -0
- data/lib/tiun/auth/controller/facebook.rb +62 -0
- data/lib/tiun/auth/controller/github.rb +37 -0
- data/lib/tiun/auth/controller/kakao.rb +33 -0
- data/lib/tiun/auth/controller/oauth.rb +167 -0
- data/lib/tiun/auth/controller/ok.rb +8 -0
- data/lib/tiun/auth/controller/telegram.rb +188 -0
- data/lib/tiun/auth/controller/vk.rb +85 -0
- data/lib/tiun/auth/controller/wechat.rb +58 -0
- data/lib/tiun/auth/controller/weibo.rb +28 -0
- data/lib/tiun/auth/controller.rb +467 -150
- data/lib/tiun/auth/json_session.rb +19 -0
- data/lib/tiun/auth/token_identity.rb +37 -0
- data/lib/tiun/auth/user_identity.rb +27 -0
- data/lib/tiun/auth/views/oauth_address.html.erb +23 -0
- data/lib/tiun/auth.rb +184 -45
- data/lib/tiun/carrier_wave_store.rb +59 -0
- data/lib/tiun/cli.rb +52 -32
- data/lib/tiun/concern/resources.rb +85 -0
- data/lib/tiun/config_source.rb +52 -0
- data/lib/tiun/content_range.rb +123 -0
- data/lib/tiun/context/merge.rb +117 -0
- data/lib/tiun/context.rb +39 -0
- data/lib/tiun/controller/auth/identity.rb +201 -0
- data/lib/tiun/controller/auth/registration.rb +23 -0
- data/lib/tiun/controller/auth.rb +198 -0
- data/lib/tiun/controller/auto.rb.erb +10 -0
- data/lib/tiun/controller/base/actions.rb +156 -0
- data/lib/tiun/controller/base/assignment.rb +101 -0
- data/lib/tiun/controller/base/parameters.rb +198 -0
- data/lib/tiun/controller/base/params.rb +166 -0
- data/lib/tiun/controller/base/records.rb +107 -0
- data/lib/tiun/controller/base/representation.rb +97 -0
- data/lib/tiun/controller/base/scopes.rb +132 -0
- data/lib/tiun/controller/base.rb +52 -0
- data/lib/tiun/controller/component_assets.rb +96 -0
- data/lib/tiun/controller/meta.rb +248 -0
- data/lib/tiun/controller/translations.rb +22 -0
- data/lib/tiun/controller.rb +13 -0
- data/lib/tiun/core/boot.rb +210 -0
- data/lib/tiun/core/contexts.rb +53 -0
- data/lib/tiun/core/controller_contexts.rb +42 -0
- data/lib/tiun/core/defaults.rb +215 -0
- data/lib/tiun/core/evaluation.rb +105 -0
- data/lib/tiun/core/field_attributes.rb +78 -0
- data/lib/tiun/core/files.rb +153 -0
- data/lib/tiun/core/generation.rb +234 -0
- data/lib/tiun/core/methods.rb +104 -0
- data/lib/tiun/core/names.rb +140 -0
- data/lib/tiun/core/registry.rb +97 -0
- data/lib/tiun/core/reloading.rb +77 -0
- data/lib/tiun/core/resources.rb +308 -0
- data/lib/tiun/core/routing/forward.rb +206 -0
- data/lib/tiun/core/routing.rb +323 -0
- data/lib/tiun/core/types.rb +88 -0
- data/lib/tiun/core.rb +26 -0
- data/lib/tiun/core_helper.rb +85 -13
- data/lib/tiun/engine.rb +64 -20
- data/lib/tiun/error_handling.rb +121 -0
- data/lib/tiun/hooks.rb +131 -0
- data/lib/tiun/mailer/confirmation.rb +37 -0
- data/lib/tiun/mailer/recovery.rb +16 -0
- data/lib/tiun/migration.rb +72 -50
- data/lib/tiun/mixins.rb +128 -19
- data/lib/tiun/model/account/identity.rb +93 -0
- data/lib/tiun/model/account.rb +180 -7
- data/lib/tiun/model/auth/bcrypt.rb +47 -0
- data/lib/tiun/model/auth.rb +162 -36
- data/lib/tiun/model/auto.rb.erb +12 -0
- data/lib/tiun/model/me.rb +133 -0
- data/lib/tiun/model/settings.rb +186 -0
- data/lib/tiun/model/token/recovery.rb +48 -0
- data/lib/tiun/model/token.rb +37 -3
- data/lib/tiun/model.rb +82 -69
- data/lib/tiun/notification/service.rb +18 -0
- data/lib/tiun/notification.rb +6 -0
- data/lib/tiun/policy/default.rb +7 -0
- data/lib/tiun/policy.rb +84 -8
- data/lib/tiun/proceed/allowed_errors.rb +217 -0
- data/lib/tiun/proceed/auth.rb +50 -0
- data/lib/tiun/proceed/description.rb +89 -0
- data/lib/tiun/proceed/enums.rb +225 -0
- data/lib/tiun/proceed/hooks.rb +51 -0
- data/lib/tiun/proceed/pass_over_paths.rb +40 -0
- data/lib/tiun/proceed/policy.rb +172 -0
- data/lib/tiun/proceed/registration.rb +69 -0
- data/lib/tiun/proceed/schemas/component_nodes.rb +436 -0
- data/lib/tiun/proceed/schemas/constants.rb +116 -0
- data/lib/tiun/proceed/schemas/content.rb +68 -0
- data/lib/tiun/proceed/schemas/definitions.rb +181 -0
- data/lib/tiun/proceed/schemas/dictionary.rb +144 -0
- data/lib/tiun/proceed/schemas/fields.rb +182 -0
- data/lib/tiun/proceed/schemas/models.rb +50 -0
- data/lib/tiun/proceed/schemas/spans.rb +86 -0
- data/lib/tiun/proceed/schemas/values.rb +94 -0
- data/lib/tiun/proceed/schemas/view_paths.rb +86 -0
- data/lib/tiun/proceed/schemas/view_readiness.rb +51 -0
- data/lib/tiun/proceed/schemas/views.rb +192 -0
- data/lib/tiun/proceed/schemas.rb +137 -0
- data/lib/tiun/proceed/services.rb +79 -0
- data/lib/tiun/proceed/token_lifetimes.rb +49 -0
- data/lib/tiun/proceed/translations.rb +45 -0
- data/lib/tiun/proceed/versions.rb +315 -0
- data/lib/tiun/proceed.rb +23 -0
- data/lib/tiun/router.rb +40 -0
- data/lib/tiun/routes/mounts.rb +277 -0
- data/lib/tiun/routes.rb +150 -0
- data/lib/tiun/service/auto.rb.erb +5 -0
- data/lib/tiun/service/email_confirmation.rb +36 -0
- data/lib/tiun/service/job.rb +16 -0
- data/lib/tiun/service.rb +82 -0
- data/lib/tiun/services/translation.rb +297 -0
- data/lib/tiun/themes.rb +98 -0
- data/lib/tiun/translations/database.rb +72 -0
- data/lib/tiun/translations.rb +279 -0
- data/lib/tiun/version.rb +3 -3
- data/lib/tiun.rb +79 -486
- data/package-lock.json +4836 -0
- data/package.json +103 -0
- data/scripts/build-application.mjs +39 -0
- data/scripts/build-css.mjs +21 -0
- data/scripts/ci-badges.mjs +54 -0
- data/scripts/ci-badges.test.mjs +46 -0
- data/scripts/ci-coverage.mjs +26 -0
- data/scripts/ci-quality.mjs +80 -0
- data/scripts/ci-quality.sh +21 -0
- data/scripts/ci-quality.test.mjs +59 -0
- data/scripts/clean.mjs +3 -0
- data/scripts/publish-ci-badges.sh +45 -0
- data/src/auth/configuration.ts +50 -0
- data/src/browser/contracts.js +7 -0
- data/src/browser/mount.d.ts +26 -0
- data/src/browser/mount.jsx +1 -0
- data/src/browser/styles.js +17 -0
- data/src/browser/tiun.scss +23 -0
- data/src/browser/tiun.ts +1 -0
- data/src/calendar/configuration.ts +98 -0
- data/src/components/Avatar.tsx +45 -0
- data/src/components/Calendar.tsx +441 -0
- data/src/components/CatchWrapper.tsx +55 -0
- data/src/components/Chip.tsx +267 -0
- data/src/components/Column.tsx +13 -0
- data/src/components/Component.tsx +1039 -0
- data/src/components/Enum.tsx +142 -0
- data/src/components/Figure.tsx +11 -0
- data/src/components/FlexText.tsx +101 -0
- data/src/components/Footer.tsx +13 -0
- data/src/components/Grid.tsx +36 -0
- data/src/components/Heading.tsx +64 -0
- data/src/components/Image.tsx +168 -0
- data/src/components/Index.tsx +391 -0
- data/src/components/Intro.tsx +536 -0
- data/src/components/Loader.tsx +116 -0
- data/src/components/Lorem.tsx +379 -0
- data/src/components/Markdown.d.ts +17 -0
- data/src/components/Markdown.jsx +118 -0
- data/src/components/Menu.tsx +50 -0
- data/src/components/Modal.tsx +143 -0
- data/src/components/Paginator.tsx +265 -0
- data/src/components/Player.tsx +269 -0
- data/src/components/Records.tsx +1063 -0
- data/src/components/Row.tsx +193 -0
- data/src/components/Span.tsx +122 -0
- data/src/components/Step.tsx +19 -0
- data/src/components/Stockee.tsx +50 -0
- data/src/components/Toast.tsx +125 -0
- data/src/components/Tooltip.tsx +214 -0
- data/src/components/View.tsx +278 -0
- data/src/components/_palette.scss +26 -0
- data/src/components/calendar-browser.scss +133 -0
- data/src/components/calendar.scss +217 -0
- data/src/components/chip-browser.scss +270 -0
- data/src/components/chips.scss +95 -0
- data/src/components/column.scss +4 -0
- data/src/components/dashboard-browser.scss +81 -0
- data/src/components/dashboard.scss +117 -0
- data/src/components/description-browser.scss +112 -0
- data/src/components/document.scss +43 -0
- data/src/components/enum-browser.scss +33 -0
- data/src/components/enums.scss +56 -0
- data/src/components/footer.scss +51 -0
- data/src/components/form/ActionButton.tsx +66 -0
- data/src/components/form/Attachment.tsx +200 -0
- data/src/components/form/Block.tsx +55 -0
- data/src/components/form/BooleanBox.tsx +58 -0
- data/src/components/form/Collection.tsx +89 -0
- data/src/components/form/DynamicInput.tsx +806 -0
- data/src/components/form/ErrorSpan.tsx +17 -0
- data/src/components/form/ExternalField.tsx +554 -0
- data/src/components/form/FieldCaption.tsx +35 -0
- data/src/components/form/Form.tsx +407 -0
- data/src/components/form/HiddenField.tsx +10 -0
- data/src/components/form/JsonEditor.tsx +443 -0
- data/src/components/form/Login.tsx +381 -0
- data/src/components/form/NumberField.tsx +75 -0
- data/src/components/form/Pressee.tsx +101 -0
- data/src/components/form/RtferField.tsx +94 -0
- data/src/components/form/SelectField.tsx +73 -0
- data/src/components/form/SlugFlow.tsx +296 -0
- data/src/components/form/TextArea.tsx +5 -0
- data/src/components/form/TextField.tsx +6 -0
- data/src/components/form/Wye.tsx +67 -0
- data/src/components/form/auth.scss +366 -0
- data/src/components/form/changes.ts +239 -0
- data/src/components/form/context.ts +31 -0
- data/src/components/form/createForm.tsx +109 -0
- data/src/components/form/dynamic-field.scss +20 -0
- data/src/components/form/dynamicMatching.ts +44 -0
- data/src/components/form/form-browser.scss +106 -0
- data/src/components/form/forms.scss +1570 -0
- data/src/components/form/formsLib.ts +76 -0
- data/src/components/form/identity.ts +10 -0
- data/src/components/form/input.scss +37 -0
- data/src/components/form/layout.ts +72 -0
- data/src/components/form/login-browser.scss +30 -0
- data/src/components/form/render.tsx +94 -0
- data/src/components/form/resourceFields.ts +87 -0
- data/src/components/form/types.ts +214 -0
- data/src/components/form/values.ts +266 -0
- data/src/components/image.scss +67 -0
- data/src/components/intro-browser.scss +106 -0
- data/src/components/intro.scss +158 -0
- data/src/components/loader.scss +86 -0
- data/src/components/menu.scss +24 -0
- data/src/components/player.scss +48 -0
- data/src/components/records-browser.scss +62 -0
- data/src/components/records.scss +181 -0
- data/src/components/row.scss +31 -0
- data/src/components/stockee.scss +26 -0
- data/src/components/theme-palettes/compat.scss +15 -0
- data/src/components/theme-palettes/dark.scss +237 -0
- data/src/components/theme-palettes/light.scss +21 -0
- data/src/components/theme.scss +34 -0
- data/src/components/tiun_core.scss +9 -0
- data/src/components/toast.scss +63 -0
- data/src/components/tooltip.scss +22 -0
- data/src/components/view-browser.scss +321 -0
- data/src/components/view-controls.scss +385 -0
- data/src/concern/application.ts +56 -0
- data/src/concern/calendarViewProps.ts +28 -0
- data/src/concern/chipViewProps.ts +60 -0
- data/src/concern/documentHead.ts +66 -0
- data/src/concern/i18n.ts +70 -0
- data/src/concern/resourceRequest.ts +25 -0
- data/src/concern/schemaText.ts +6 -0
- data/src/concern/slugFlowProps.ts +76 -0
- data/src/concern/spanOptions.ts +37 -0
- data/src/concern/spansViewProps.tsx +103 -0
- data/src/concern/useFormAccess.ts +324 -0
- data/src/concern/useRecordsResource.ts +60 -0
- data/src/config/application.ts +57 -0
- data/src/config/componentDefaults.ts +106 -0
- data/src/config/components.ts +436 -0
- data/src/config/names.ts +72 -0
- data/src/config/records.ts +34 -0
- data/src/decorators/buttonBehaviours.tsx +46 -0
- data/src/decorators/configuration.ts +104 -0
- data/src/decorators/validation.ts +52 -0
- data/src/decorators/withAppearance.tsx +45 -0
- data/src/decorators/withCaption.tsx +21 -0
- data/src/decorators/withChildren.tsx +31 -0
- data/src/decorators/withClose.scss +37 -0
- data/src/decorators/withClose.tsx +44 -0
- data/src/decorators/withColumn.tsx +111 -0
- data/src/decorators/withDiscordAuth.tsx +4 -0
- data/src/decorators/withExternalAuth.tsx +50 -0
- data/src/decorators/withFacebookAuth.tsx +4 -0
- data/src/decorators/withField.tsx +91 -0
- data/src/decorators/withForm.tsx +365 -0
- data/src/decorators/withGithubAuth.tsx +4 -0
- data/src/decorators/withKakaoAuth.tsx +4 -0
- data/src/decorators/withMenuBranch.scss +45 -0
- data/src/decorators/withMenuBranch.tsx +109 -0
- data/src/decorators/withOkAuth.tsx +4 -0
- data/src/decorators/withPlayerList.tsx +77 -0
- data/src/decorators/withQuickLinkMark.ts +57 -0
- data/src/decorators/withRecordForm.tsx +561 -0
- data/src/decorators/withRequestActivity.scss +7 -0
- data/src/decorators/withRequestActivity.tsx +21 -0
- data/src/decorators/withRouter.tsx +395 -0
- data/src/decorators/withRouterLink.tsx +54 -0
- data/src/decorators/withTelegramAuth.tsx +4 -0
- data/src/decorators/withTextControl.tsx +194 -0
- data/src/decorators/withUnique.scss +39 -0
- data/src/decorators/withUnique.tsx +172 -0
- data/src/decorators/withUnsavedChanges.scss +39 -0
- data/src/decorators/withUnsavedChanges.tsx +312 -0
- data/src/decorators/withValidation.ts +38 -0
- data/src/decorators/withVkAuth.tsx +4 -0
- data/src/decorators/withWechatAuth.tsx +4 -0
- data/src/decorators/withWeiboAuth.tsx +4 -0
- data/src/intro/config.ts +72 -0
- data/src/intro/position.ts +70 -0
- data/src/layout/units.ts +21 -0
- data/src/records/types.ts +67 -0
- data/src/routing/nativePaths.ts +16 -0
- data/src/routing/routes.ts +337 -0
- data/src/schema/Schema.ts +2034 -0
- data/src/schema/dates.ts +17 -0
- data/src/schema.ts +274 -0
- data/src/services/Meta.ts +64 -0
- data/src/services/Resource.ts +480 -0
- data/src/services/Stock.ts +156 -0
- data/src/services/browser/requestActivity.d.ts +7 -0
- data/src/services/browser/requestActivity.js +119 -0
- data/src/services/browser/slugColor.js +13 -0
- data/src/services/calendar/clock.ts +169 -0
- data/src/services/calendar/dates.ts +127 -0
- data/src/services/calendar/daylight.ts +301 -0
- data/src/services/calendar/useCalendarDaylight.ts +76 -0
- data/src/services/calendar/utcTimeSource.ts +41 -0
- data/src/services/enumLookup.ts +96 -0
- data/src/services/form/blankCondition.ts +61 -0
- data/src/services/form/hoardValidation.ts +84 -0
- data/src/services/i18n/I18n.ts +227 -0
- data/src/services/i18n/messages.ts +185 -0
- data/src/services/load.ts +60 -0
- data/src/services/methods/aboutData.d.ts +9 -0
- data/src/services/methods/aboutData.js +32 -0
- data/src/services/methods/calendarChoices.d.ts +1 -0
- data/src/services/methods/calendarChoices.js +9 -0
- data/src/services/methods/eventDates.ts +96 -0
- data/src/services/methods/forms.ts +22 -0
- data/src/services/methods/mount.jsx +34 -0
- data/src/services/methods/paschal.ts +45 -0
- data/src/services/methods/prepared.ts +193 -0
- data/src/services/methods/query.ts +30 -0
- data/src/services/methods/registry.ts +22 -0
- data/src/services/methods/resolveReadResource.ts +57 -0
- data/src/services/methods.ts +156 -0
- data/src/services/records/range.ts +39 -0
- data/src/services/records/resource.ts +90 -0
- data/src/services/records/useRecordPages.ts +266 -0
- data/src/services/session/renewal.ts +394 -0
- data/src/services/textLink.ts +11 -0
- data/src/services/timer.ts +25 -0
- data/src/services/useAppearance.ts +496 -0
- data/src/services/useSwitch.ts +146 -0
- data/src/theme/cache.ts +88 -0
- data/src/theme/configuration.ts +261 -0
- data/src/theme/context.ts +48 -0
- data/src/theme/resource.ts +106 -0
- data/tiun.gemspec +53 -45
- data/tools/rubocop/compact_block_braces.rb +39 -0
- data/tools/rubocop/i18n_decorators.rb +15 -0
- data/tools/rubocop/spacing.rb +96 -0
- data/tsconfig.build.json +26 -0
- data/tsconfig.json +27 -0
- metadata +628 -72
- data/.rspec +0 -3
- data/.travis.yml +0 -7
- data/lib/tiun/autocontroller.rb.erb +0 -20
- data/lib/tiun/autolistserializer.rb.erb +0 -9
- data/lib/tiun/automodel.rb.erb +0 -10
- data/lib/tiun/autoserializer.rb.erb +0 -9
- data/lib/tiun/base.rb +0 -405
- data/lib/tiun/core_controller.rb +0 -6
- data/lib/tiun/list_serializer.rb +0 -20
- data/lib/tiun/meta_controller.rb +0 -13
- data/lib/tiun/serializer.rb +0 -31
- /data/lib/tiun/{automigration.rb.erb → migration/auto.rb.erb} +0 -0
- /data/lib/tiun/{autopolicy.rb.erb → policy/auto.rb.erb} +0 -0
|
@@ -0,0 +1,2034 @@
|
|
|
1
|
+
import { settings as applicationSettings, object as configurationMapping } from "../config/application.js";
|
|
2
|
+
import { buttonDecorators } from "../decorators/buttonBehaviours.js";
|
|
3
|
+
import { withChildren } from "../decorators/withChildren.js";
|
|
4
|
+
import { type ComponentDecorator, type DecoratedProps, decorateComponent } from "../decorators/configuration.js";
|
|
5
|
+
import type { CalendarProps } from "../components/Calendar.js";
|
|
6
|
+
import type { ComponentDefinition, HtmlDefs } from "../config/components.js";
|
|
7
|
+
import type { ComponentType, MouseEvent, ReactElement, ReactNode } from "react";
|
|
8
|
+
import type {
|
|
9
|
+
ExternalFieldAdapter,
|
|
10
|
+
ExternalFieldDefinition,
|
|
11
|
+
FieldMeta,
|
|
12
|
+
FormMeta,
|
|
13
|
+
TextValidation,
|
|
14
|
+
} from "../components/form/types.js";
|
|
15
|
+
import { default as Markdown, type MarkdownProps } from "../components/Markdown.js";
|
|
16
|
+
import type { NamedRoute, RouteMatch } from "../routing/routes.js";
|
|
17
|
+
import {
|
|
18
|
+
bindingValue,
|
|
19
|
+
classProperties,
|
|
20
|
+
compileDocumentProperties,
|
|
21
|
+
compileProperties,
|
|
22
|
+
componentDefinitions,
|
|
23
|
+
configurationReferenceMap,
|
|
24
|
+
componentUid,
|
|
25
|
+
selectedProps,
|
|
26
|
+
} from "../config/components.js";
|
|
27
|
+
import { createElement, isValidElement } from "react";
|
|
28
|
+
import {
|
|
29
|
+
findConfigurationDefinition,
|
|
30
|
+
findResource,
|
|
31
|
+
findResourceMethod,
|
|
32
|
+
resourceAllowed,
|
|
33
|
+
} from "../services/Resource.js";
|
|
34
|
+
import { recordOperation, recordPath, resourceParameters } from "../services/records/resource.js";
|
|
35
|
+
import { Component } from "../components/Component.js";
|
|
36
|
+
import type { ComponentRegistry } from "../components/form/createForm.js";
|
|
37
|
+
import { Lorem } from "../components/Lorem.js";
|
|
38
|
+
import { enumLookup, type EnumLookup } from "../services/enumLookup.js";
|
|
39
|
+
import type { FlexTextInsertionProps } from "../components/FlexText.js";
|
|
40
|
+
import type { FrontendMethod } from "../services/methods.js";
|
|
41
|
+
import type { I18n } from "../services/i18n/I18n.js";
|
|
42
|
+
import type { ImageProps } from "../components/Image.js";
|
|
43
|
+
import type { IntroStep } from "../intro/config.js";
|
|
44
|
+
import type { PlayerLabels } from "../components/Player.js";
|
|
45
|
+
import type { RecordColumn } from "../records/types.js";
|
|
46
|
+
import type { ServerMeta } from "../services/Meta.js";
|
|
47
|
+
import { Stockee } from "../components/Stockee.js";
|
|
48
|
+
import { blankCondition } from "../services/form/blankCondition.js";
|
|
49
|
+
import { calendarClockSettings } from "../calendar/configuration.js";
|
|
50
|
+
import { compileRoutes } from "../routing/routes.js";
|
|
51
|
+
import { componentDefaults } from "../config/componentDefaults.js";
|
|
52
|
+
import { hoardValidation } from "../services/form/hoardValidation.js";
|
|
53
|
+
import { imageEvents } from "../components/Image.js";
|
|
54
|
+
import { invalidText } from "../decorators/validation.js";
|
|
55
|
+
import { methods } from "../services/methods.js";
|
|
56
|
+
import { schemaTimestamp } from "./dates.js";
|
|
57
|
+
import { stockee } from "../services/Stock.js";
|
|
58
|
+
import { translations } from "../services/i18n/I18n.js";
|
|
59
|
+
import { withDiscordAuth } from "../decorators/withDiscordAuth.js";
|
|
60
|
+
import { withFacebookAuth } from "../decorators/withFacebookAuth.js";
|
|
61
|
+
import { withGithubAuth } from "../decorators/withGithubAuth.js";
|
|
62
|
+
import { withKakaoAuth } from "../decorators/withKakaoAuth.js";
|
|
63
|
+
import { withOkAuth } from "../decorators/withOkAuth.js";
|
|
64
|
+
import { withQuickLinkMark } from "../decorators/withQuickLinkMark.js";
|
|
65
|
+
import { withRequestActivity } from "../decorators/withRequestActivity.js";
|
|
66
|
+
import { withTelegramAuth } from "../decorators/withTelegramAuth.js";
|
|
67
|
+
import { withVkAuth } from "../decorators/withVkAuth.js";
|
|
68
|
+
import { withWechatAuth } from "../decorators/withWechatAuth.js";
|
|
69
|
+
import { withWeiboAuth } from "../decorators/withWeiboAuth.js";
|
|
70
|
+
|
|
71
|
+
export interface SchemaCommandContext {
|
|
72
|
+
readonly source?: string;
|
|
73
|
+
}
|
|
74
|
+
export interface SchemaBlockProps<T> {
|
|
75
|
+
readonly schema: Schema<T>;
|
|
76
|
+
readonly data: T;
|
|
77
|
+
readonly block: {
|
|
78
|
+
readonly name: string;
|
|
79
|
+
readonly kind: "component";
|
|
80
|
+
readonly component: string;
|
|
81
|
+
readonly renderer?: string;
|
|
82
|
+
readonly resource?: string;
|
|
83
|
+
readonly source?: string;
|
|
84
|
+
};
|
|
85
|
+
}
|
|
86
|
+
export interface SchemaTextProps {
|
|
87
|
+
readonly source: string;
|
|
88
|
+
readonly href?: string;
|
|
89
|
+
readonly inline?: boolean;
|
|
90
|
+
readonly maxLength?: number | undefined;
|
|
91
|
+
}
|
|
92
|
+
export type SchemaTextRenderer = (props: SchemaTextProps) => ReactNode;
|
|
93
|
+
|
|
94
|
+
const inlineRenderers: readonly string[] = ["markdown_inline", "row_text", "name_text"],
|
|
95
|
+
/**
|
|
96
|
+
* Displays text through the standard Markdown component in its inline mode.
|
|
97
|
+
* @param props Markdown text and optional link.
|
|
98
|
+
* @returns The Markdown element.
|
|
99
|
+
*/
|
|
100
|
+
renderInlineMarkdown = (props: SchemaTextProps): ReactElement => createElement(Markdown, { ...props, inline: true }),
|
|
101
|
+
/**
|
|
102
|
+
* Renders plain text with the optional link supplied by the caller.
|
|
103
|
+
* @param props Text and its optional destination.
|
|
104
|
+
* @returns A span or an anchor containing the text.
|
|
105
|
+
*/
|
|
106
|
+
renderPlainText = ({ source, href }: SchemaTextProps): ReactElement => {
|
|
107
|
+
if (typeof href === "string" && href !== "") {
|
|
108
|
+
return createElement("a", { href }, source);
|
|
109
|
+
}
|
|
110
|
+
return createElement("span", null, source);
|
|
111
|
+
};
|
|
112
|
+
export interface SchemaRegistry<T> {
|
|
113
|
+
readonly commands?: Readonly<Record<string, (record: T, context?: SchemaCommandContext) => unknown>>;
|
|
114
|
+
readonly components?: Readonly<Record<string, ComponentType<SchemaBlockProps<T>>>>;
|
|
115
|
+
readonly decorators?: Readonly<Record<string, ComponentDecorator>>;
|
|
116
|
+
readonly insertions?: Readonly<Record<string, ComponentType<FlexTextInsertionProps>>>;
|
|
117
|
+
readonly renderers?: Readonly<Record<string, ComponentType<SchemaTextProps>>>;
|
|
118
|
+
readonly values?: Readonly<Record<string, (record: T) => ReactNode>>;
|
|
119
|
+
readonly actions?: Readonly<Record<string, (record: T, event: MouseEvent<HTMLAnchorElement>) => void>>;
|
|
120
|
+
readonly formComponents?: ComponentRegistry<Readonly<Record<string, unknown>>>;
|
|
121
|
+
readonly projectors?: Readonly<Record<string, (record: T) => unknown>>;
|
|
122
|
+
readonly validations?: Readonly<Record<string, TextValidation>>;
|
|
123
|
+
readonly methods?: Readonly<Record<string, FrontendMethod>>;
|
|
124
|
+
}
|
|
125
|
+
export interface SchemaOptions<T> {
|
|
126
|
+
readonly registry?: SchemaRegistry<T>;
|
|
127
|
+
readonly i18n?: I18n;
|
|
128
|
+
readonly onWarning?: (message: string) => void;
|
|
129
|
+
}
|
|
130
|
+
export interface SchemaIntro {
|
|
131
|
+
readonly id: string;
|
|
132
|
+
readonly field: string;
|
|
133
|
+
readonly text: string;
|
|
134
|
+
readonly seq_no: number;
|
|
135
|
+
readonly introduced_at: string;
|
|
136
|
+
readonly position?: IntroStep["position"];
|
|
137
|
+
}
|
|
138
|
+
export interface Layout extends HtmlDefs {
|
|
139
|
+
readonly header?: string;
|
|
140
|
+
readonly footer?: string;
|
|
141
|
+
readonly scroll?: boolean;
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
export interface SchemaViewMeta<T> {
|
|
145
|
+
readonly menu?: string;
|
|
146
|
+
readonly layout?: Layout;
|
|
147
|
+
readonly prepare?: string;
|
|
148
|
+
readonly contextMethod?: string;
|
|
149
|
+
readonly with?: unknown;
|
|
150
|
+
readonly native?: boolean;
|
|
151
|
+
readonly element?:
|
|
152
|
+
"span" | "spans" | "chip" | "name" | "flex_text" | "calendar" | "player" | "image" | "slug_flow" | "records";
|
|
153
|
+
readonly collectionLayout?: "grid" | "stack" | "list";
|
|
154
|
+
readonly gap?: number;
|
|
155
|
+
readonly domId?: string;
|
|
156
|
+
readonly flowMode?: "select" | "display";
|
|
157
|
+
readonly keyFrom?: string;
|
|
158
|
+
readonly fieldsToSelect?: string;
|
|
159
|
+
readonly showFirst?: "selected" | "skip";
|
|
160
|
+
readonly chooseCommand?: string;
|
|
161
|
+
readonly openCommand?: string;
|
|
162
|
+
readonly source?: string;
|
|
163
|
+
readonly viewAs?: "plain" | "card";
|
|
164
|
+
readonly description?: string;
|
|
165
|
+
readonly width?: string | number;
|
|
166
|
+
readonly height?: string | number;
|
|
167
|
+
readonly onClick?: string;
|
|
168
|
+
readonly props?: string;
|
|
169
|
+
readonly minHeight?: number;
|
|
170
|
+
readonly playingFrom?: string;
|
|
171
|
+
readonly labelFrom?: string;
|
|
172
|
+
readonly playCommand?: string;
|
|
173
|
+
readonly pauseCommand?: string;
|
|
174
|
+
readonly labels?: PlayerLabels;
|
|
175
|
+
readonly styleFrom?: string;
|
|
176
|
+
readonly calendarStyle?: "round" | "ortho";
|
|
177
|
+
readonly dayAppearance?: string;
|
|
178
|
+
readonly onUpdate?: string;
|
|
179
|
+
readonly catchFrom?: string;
|
|
180
|
+
readonly catchPeriod?: string;
|
|
181
|
+
readonly calendarClock?: ReturnType<typeof calendarClockSettings>;
|
|
182
|
+
readonly sources?: readonly string[];
|
|
183
|
+
readonly insertions?: string;
|
|
184
|
+
readonly insertionRenderer?: string;
|
|
185
|
+
readonly text?: string;
|
|
186
|
+
readonly href?: string;
|
|
187
|
+
readonly color?: string;
|
|
188
|
+
readonly tooltip?: string;
|
|
189
|
+
readonly renderer?: string;
|
|
190
|
+
readonly labelView?: string;
|
|
191
|
+
readonly className?: string;
|
|
192
|
+
readonly classFrom?: string;
|
|
193
|
+
readonly itemClassName?: string;
|
|
194
|
+
readonly item?: string;
|
|
195
|
+
readonly uid?: string | number | readonly unknown[];
|
|
196
|
+
readonly rowClassName?: string;
|
|
197
|
+
readonly headerClassName?: string;
|
|
198
|
+
readonly bodyClassName?: string;
|
|
199
|
+
readonly defaultExpandWhen?: string;
|
|
200
|
+
readonly accordion?: boolean;
|
|
201
|
+
readonly hideIfEmpty?: boolean;
|
|
202
|
+
readonly expandWhen?: string;
|
|
203
|
+
readonly empty?: string;
|
|
204
|
+
readonly avatar?: Readonly<{ image?: string; href: string; label?: string; action?: string; fallback?: string }>;
|
|
205
|
+
readonly body?: readonly RecordColumn<T>[];
|
|
206
|
+
readonly pagination?: {
|
|
207
|
+
readonly kind?: "hidden" | "button";
|
|
208
|
+
readonly autoloadUpto?: number;
|
|
209
|
+
readonly pageSize?: number;
|
|
210
|
+
readonly buttonStyle?: "text" | "circle";
|
|
211
|
+
readonly rangeUnit?: "pages" | "records";
|
|
212
|
+
};
|
|
213
|
+
readonly name: string;
|
|
214
|
+
readonly parent?: string;
|
|
215
|
+
readonly separator?: "/" | "#";
|
|
216
|
+
readonly mountTo?: string;
|
|
217
|
+
readonly component?: string;
|
|
218
|
+
readonly title?: string;
|
|
219
|
+
readonly columns: readonly RecordColumn<T>[];
|
|
220
|
+
readonly form?: FormMeta;
|
|
221
|
+
readonly intro: readonly SchemaIntro[];
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
type Data = Readonly<Record<string, unknown>>;
|
|
225
|
+
// eslint-disable-next-line one-var -- Registry and configuration name patterns are separate from field definitions.
|
|
226
|
+
const decoratorName = /^[a-z_][a-z0-9_]*$/u,
|
|
227
|
+
methodNamePattern = /^[\p{Ll}_][\p{Ll}\p{Nd}_]*(?:\.[\p{Ll}_][\p{Ll}\p{Nd}_]*)*$/u,
|
|
228
|
+
namePattern = /^[a-z_][a-z0-9_]*(?:\.[a-z_][a-z0-9_]*)*$/u,
|
|
229
|
+
referencePattern = /^[a-z_][a-z0-9_]*(?:\.[a-z_][a-z0-9_]*)*(?::\d+(?:\.\d+)*)?$/u,
|
|
230
|
+
standardDecorators: Readonly<Record<string, ComponentDecorator>> = Object.freeze({
|
|
231
|
+
...buttonDecorators,
|
|
232
|
+
children: withChildren,
|
|
233
|
+
// eslint-disable-next-line no-useless-computed-key -- This is a snake_case key from the configuration interface.
|
|
234
|
+
["discord_auth"]: withDiscordAuth,
|
|
235
|
+
// eslint-disable-next-line no-useless-computed-key -- This is a snake_case key from the configuration interface.
|
|
236
|
+
["facebook_auth"]: withFacebookAuth,
|
|
237
|
+
// eslint-disable-next-line no-useless-computed-key -- This is a snake_case key from the configuration interface.
|
|
238
|
+
["github_auth"]: withGithubAuth,
|
|
239
|
+
// eslint-disable-next-line no-useless-computed-key -- This is a snake_case key from the configuration interface.
|
|
240
|
+
["kakao_auth"]: withKakaoAuth,
|
|
241
|
+
// eslint-disable-next-line no-useless-computed-key -- This is a snake_case key from the configuration interface.
|
|
242
|
+
["ok_auth"]: withOkAuth,
|
|
243
|
+
// eslint-disable-next-line no-useless-computed-key -- This is a snake_case key from the configuration interface.
|
|
244
|
+
["quick_link_mark"]: withQuickLinkMark,
|
|
245
|
+
// eslint-disable-next-line no-useless-computed-key -- This is a snake_case key from the configuration interface.
|
|
246
|
+
["request_activity"]: withRequestActivity,
|
|
247
|
+
// eslint-disable-next-line no-useless-computed-key -- This is a snake_case key from the configuration interface.
|
|
248
|
+
["telegram_auth"]: withTelegramAuth,
|
|
249
|
+
// eslint-disable-next-line no-useless-computed-key -- This is a snake_case key from the configuration interface.
|
|
250
|
+
["vk_auth"]: withVkAuth,
|
|
251
|
+
// eslint-disable-next-line no-useless-computed-key -- This is a snake_case key from the configuration interface.
|
|
252
|
+
["wechat_auth"]: withWechatAuth,
|
|
253
|
+
// eslint-disable-next-line no-useless-computed-key -- This is a snake_case key from the configuration interface.
|
|
254
|
+
["weibo_auth"]: withWeiboAuth,
|
|
255
|
+
});
|
|
256
|
+
const fieldTypes = new Set([
|
|
257
|
+
"text",
|
|
258
|
+
"tale",
|
|
259
|
+
"select",
|
|
260
|
+
"boolean",
|
|
261
|
+
"number",
|
|
262
|
+
"hidden",
|
|
263
|
+
"block",
|
|
264
|
+
"collection",
|
|
265
|
+
"set",
|
|
266
|
+
"dynamic",
|
|
267
|
+
"json",
|
|
268
|
+
"rtfer",
|
|
269
|
+
"wye",
|
|
270
|
+
"attachment",
|
|
271
|
+
"component",
|
|
272
|
+
"layout",
|
|
273
|
+
]);
|
|
274
|
+
const contentKinds = new Set(["span", "spans", "name", "flex_text", "player", "slug_flow"]);
|
|
275
|
+
const externalPath = /^[A-Za-z_$][A-Za-z0-9_$]*(?:\.[A-Za-z_$][A-Za-z0-9_$]*)*$/;
|
|
276
|
+
const aliases = [
|
|
277
|
+
["context_value", "contextValue"],
|
|
278
|
+
["context_values", "contextValues"],
|
|
279
|
+
["input_type", "inputType"],
|
|
280
|
+
["on_blur", "onBlur"],
|
|
281
|
+
["on_enter", "onEnter"],
|
|
282
|
+
["display_scale", "displayScale"],
|
|
283
|
+
["true_value", "trueValue"],
|
|
284
|
+
["false_value", "falseValue"],
|
|
285
|
+
["max_bytes", "maxBytes"],
|
|
286
|
+
["sun_image", "sunImage"],
|
|
287
|
+
["moon_image", "moonImage"],
|
|
288
|
+
["loadpath", "pathname"],
|
|
289
|
+
["query_key", "queryKey"],
|
|
290
|
+
["subscribe_to", "subscribeTo"],
|
|
291
|
+
["code_names", "codeNames"],
|
|
292
|
+
["max_length", "maxLength"],
|
|
293
|
+
] as const;
|
|
294
|
+
const copied = [
|
|
295
|
+
"selectable",
|
|
296
|
+
"readonly",
|
|
297
|
+
"filter",
|
|
298
|
+
"wrap",
|
|
299
|
+
"source",
|
|
300
|
+
"humanized_name",
|
|
301
|
+
"key_name",
|
|
302
|
+
"value_name",
|
|
303
|
+
"display_scheme",
|
|
304
|
+
"context_names",
|
|
305
|
+
"visible_if",
|
|
306
|
+
"hint",
|
|
307
|
+
"limit",
|
|
308
|
+
"variant",
|
|
309
|
+
"width_kind",
|
|
310
|
+
"nested",
|
|
311
|
+
"eager_load",
|
|
312
|
+
"rows",
|
|
313
|
+
"unique_url",
|
|
314
|
+
"unique_field",
|
|
315
|
+
"default",
|
|
316
|
+
"humanized_default",
|
|
317
|
+
"disabled",
|
|
318
|
+
"accept",
|
|
319
|
+
"view",
|
|
320
|
+
"min",
|
|
321
|
+
"max",
|
|
322
|
+
"step",
|
|
323
|
+
"required",
|
|
324
|
+
"switch",
|
|
325
|
+
];
|
|
326
|
+
|
|
327
|
+
/**
|
|
328
|
+
* Determines whether a component uses the content definition compiler.
|
|
329
|
+
* @param node The component as received from metadata.
|
|
330
|
+
* @returns Whether the component needs content binding compilation.
|
|
331
|
+
*/
|
|
332
|
+
function isContentDefinition(node: Data): boolean {
|
|
333
|
+
if (typeof node.of !== "string") {
|
|
334
|
+
return false;
|
|
335
|
+
}
|
|
336
|
+
if (contentKinds.has(node.of)) {
|
|
337
|
+
return true;
|
|
338
|
+
}
|
|
339
|
+
if (node.of === "image") {
|
|
340
|
+
return Object.hasOwn(node, "source");
|
|
341
|
+
}
|
|
342
|
+
if (node.of === "calendar") {
|
|
343
|
+
return Object.hasOwn(node, "calendar_style");
|
|
344
|
+
}
|
|
345
|
+
if (node.of === "records") {
|
|
346
|
+
return Object.hasOwn(node, "item") || Object.hasOwn(node, "row");
|
|
347
|
+
}
|
|
348
|
+
return (
|
|
349
|
+
node.of === "chip" &&
|
|
350
|
+
(Object.hasOwn(node, "item") ||
|
|
351
|
+
(!Object.hasOwn(node, "segments") &&
|
|
352
|
+
typeof node.text === "string" &&
|
|
353
|
+
namePattern.test(node.text) &&
|
|
354
|
+
["href", "color", "class_from", "renderer"].some((key) => Object.hasOwn(node, key))))
|
|
355
|
+
);
|
|
356
|
+
}
|
|
357
|
+
|
|
358
|
+
/** Адаптер JSON-метаданных: функции выбираются только из реестров, ссылки переводятся при чтении. */
|
|
359
|
+
export class Schema<T> {
|
|
360
|
+
readonly configuredComponent: ReturnType<typeof componentDefaults>;
|
|
361
|
+
readonly componentDefinitions: Readonly<Record<string, ComponentDefinition>>;
|
|
362
|
+
readonly layout: Layout | undefined;
|
|
363
|
+
readonly pageDefinitions: Readonly<Record<string, ComponentDefinition>>;
|
|
364
|
+
readonly metadata: ServerMeta;
|
|
365
|
+
readonly i18n: I18n;
|
|
366
|
+
/** Подготовленные виды по имени компонента `of: view`. */
|
|
367
|
+
readonly views: Readonly<Record<string, SchemaViewMeta<T>>>;
|
|
368
|
+
readonly warnings: string[] = [];
|
|
369
|
+
public readonly enums: EnumLookup;
|
|
370
|
+
private readonly layouts: ReadonlyMap<string, Layout>;
|
|
371
|
+
private readonly markdownRenderers = new Map<boolean, ComponentType<SchemaTextProps>>();
|
|
372
|
+
private readonly fieldDefinitions: Readonly<Record<string, FormMeta>>;
|
|
373
|
+
private readonly contentDefinitions: Readonly<Record<string, SchemaViewMeta<T>>>;
|
|
374
|
+
private readonly registry: SchemaRegistry<T>;
|
|
375
|
+
private readonly onWarning: ((message: string) => void) | undefined;
|
|
376
|
+
private compiledRoutes?: ReturnType<typeof compileRoutes<T>>;
|
|
377
|
+
|
|
378
|
+
/**
|
|
379
|
+
* Создаёт схему с подготовленными видами, формами и определениями содержимого.
|
|
380
|
+
* @param meta Метаданные с объявлениями в `components`.
|
|
381
|
+
* @param options Реестры, переводы и обработчик предупреждений.
|
|
382
|
+
*/
|
|
383
|
+
constructor(meta: ServerMeta, options: SchemaOptions<T> = {}) {
|
|
384
|
+
const compiledDefinitions = componentDefinitions(meta.components),
|
|
385
|
+
compiledEntries = Object.entries(compiledDefinitions),
|
|
386
|
+
declaredNodes = Array.isArray(meta.components) ? meta.components.filter(isData) : [],
|
|
387
|
+
indexedNodes = new Map(declaredNodes.map((node) => [node.name, node])),
|
|
388
|
+
referencedChips = new Set(
|
|
389
|
+
declaredNodes
|
|
390
|
+
.filter((node) => node.of === "chip" && typeof node.item === "string")
|
|
391
|
+
.map((node) => findConfigurationDefinition(declaredNodes, String(node.item))?.name),
|
|
392
|
+
),
|
|
393
|
+
viewComponents = compiledEntries.filter(([, definition]) => definition.of === "view");
|
|
394
|
+
this.componentDefinitions = configurationReferenceMap(
|
|
395
|
+
compiledEntries.filter(([, definition]) => definition.of !== "view"),
|
|
396
|
+
compiledDefinitions,
|
|
397
|
+
);
|
|
398
|
+
this.pageDefinitions = configurationReferenceMap(viewComponents, compiledDefinitions);
|
|
399
|
+
this.metadata = meta;
|
|
400
|
+
this.i18n = options.i18n ?? translations;
|
|
401
|
+
this.enums = enumLookup(meta, this.i18n);
|
|
402
|
+
this.registry = options.registry ?? {};
|
|
403
|
+
this.onWarning = options.onWarning;
|
|
404
|
+
// eslint-disable-next-line one-var -- Compile layouts after setting the warning handler.
|
|
405
|
+
const settings = applicationSettings(meta),
|
|
406
|
+
{ layouts, defaultLayout } = this.compiledLayouts(settings.layouts);
|
|
407
|
+
this.configuredComponent = componentDefaults(settings.components);
|
|
408
|
+
this.layouts = layouts;
|
|
409
|
+
this.layout = defaultLayout;
|
|
410
|
+
if (typeof settings.layouts === "undefined") {
|
|
411
|
+
this.layout = this.compiledLayout(settings.layout, "settings.layout");
|
|
412
|
+
}
|
|
413
|
+
this.fieldDefinitions = configurationReferenceMap(
|
|
414
|
+
compiledEntries.flatMap(([name, declared]) => {
|
|
415
|
+
const { node } = this.configuredComponent(declared);
|
|
416
|
+
if (node.of !== "form" || node.fields === undefined) {
|
|
417
|
+
return [];
|
|
418
|
+
}
|
|
419
|
+
const path = `components.${name}.fields`;
|
|
420
|
+
if (!Array.isArray(node.fields)) {
|
|
421
|
+
this.warn(`${path}: expected list`);
|
|
422
|
+
return [];
|
|
423
|
+
}
|
|
424
|
+
return [[name, this.form(node.fields, path)]];
|
|
425
|
+
}),
|
|
426
|
+
compiledDefinitions,
|
|
427
|
+
);
|
|
428
|
+
this.views = configurationReferenceMap(
|
|
429
|
+
viewComponents.flatMap(([name, page]) => {
|
|
430
|
+
const view = this.compiledPage(this.configuredComponent(page).node);
|
|
431
|
+
return view ? [[name, view]] : [];
|
|
432
|
+
}),
|
|
433
|
+
compiledDefinitions,
|
|
434
|
+
);
|
|
435
|
+
this.contentDefinitions = configurationReferenceMap(
|
|
436
|
+
compiledEntries.flatMap(([name]) => {
|
|
437
|
+
const node = indexedNodes.get(name)!;
|
|
438
|
+
if (!isContentDefinition(node) && !(node.of === "chip" && referencedChips.has(name))) {
|
|
439
|
+
return [];
|
|
440
|
+
}
|
|
441
|
+
const definition = this.compiledContent(name, node);
|
|
442
|
+
return definition ? [[name, definition]] : [];
|
|
443
|
+
}),
|
|
444
|
+
compiledDefinitions,
|
|
445
|
+
);
|
|
446
|
+
}
|
|
447
|
+
|
|
448
|
+
/**
|
|
449
|
+
* Resolves the callback for a configured calendar selection.
|
|
450
|
+
* @param name The configured method name, if present.
|
|
451
|
+
* @param record The component data available to the update method.
|
|
452
|
+
* @param destination Optional binding selecting the recipient of the event.
|
|
453
|
+
* @returns The bound callback or undefined if no method was configured.
|
|
454
|
+
*/
|
|
455
|
+
public calendarUpdated(name: unknown, record?: unknown, destination?: unknown): CalendarProps["onUpdate"] {
|
|
456
|
+
let handler: CalendarProps["onUpdate"];
|
|
457
|
+
if (typeof name !== "undefined") {
|
|
458
|
+
const callback = typeof name === "string" && this.method(name)?.onUpdate;
|
|
459
|
+
if (typeof callback !== "function") {
|
|
460
|
+
throw new TypeError("calendar.on_update: expected a registered update method");
|
|
461
|
+
}
|
|
462
|
+
handler = (update): void => {
|
|
463
|
+
callback(update, record, this.binding(destination, record));
|
|
464
|
+
};
|
|
465
|
+
}
|
|
466
|
+
return handler;
|
|
467
|
+
}
|
|
468
|
+
|
|
469
|
+
/**
|
|
470
|
+
* Binds a named calendar appearance method to the data supplied to the component.
|
|
471
|
+
* @param name The configured name, if present.
|
|
472
|
+
* @param record The component data passed to the method for each day.
|
|
473
|
+
* @returns The calendar callback when a name was supplied.
|
|
474
|
+
*/
|
|
475
|
+
public calendarDayAppearance(name: unknown, record: unknown): CalendarProps["dayAppearance"] {
|
|
476
|
+
let handler: CalendarProps["dayAppearance"];
|
|
477
|
+
if (typeof name !== "undefined") {
|
|
478
|
+
const callback = typeof name === "string" && this.method(name)?.dayAppearance;
|
|
479
|
+
if (typeof callback !== "function") {
|
|
480
|
+
throw new TypeError(this.i18n.t("tiun.errors.calendar.day_appearance"));
|
|
481
|
+
}
|
|
482
|
+
handler = (day): ReturnType<NonNullable<CalendarProps["dayAppearance"]>> => callback(day, record);
|
|
483
|
+
}
|
|
484
|
+
return handler;
|
|
485
|
+
}
|
|
486
|
+
|
|
487
|
+
/**
|
|
488
|
+
* Resolves the context hook selected by a view.
|
|
489
|
+
* @param name The name in the view configuration.
|
|
490
|
+
* @returns A registered hook when the view selects one.
|
|
491
|
+
*/
|
|
492
|
+
public viewContext(name?: string): FrontendMethod["useView"] {
|
|
493
|
+
return this.method(name ?? "")?.useView;
|
|
494
|
+
}
|
|
495
|
+
|
|
496
|
+
/**
|
|
497
|
+
* Resolves the configured local submission handler.
|
|
498
|
+
* @param definition Prepared form declaration.
|
|
499
|
+
* @returns A handler for a configured local submission.
|
|
500
|
+
*/
|
|
501
|
+
public formSubmitted(definition: ComponentDefinition): FrontendMethod["onSubmit"] {
|
|
502
|
+
const name = definition.onSubmit;
|
|
503
|
+
let handler: FrontendMethod["onSubmit"];
|
|
504
|
+
if (typeof name === "string") {
|
|
505
|
+
const callback = this.method(name)?.onSubmit;
|
|
506
|
+
if (typeof callback !== "function") {
|
|
507
|
+
throw new TypeError(this.i18n.t("tiun.errors.form.local_submit", { name }));
|
|
508
|
+
}
|
|
509
|
+
handler = (values, record): unknown => callback(values, record, this.binding(definition.forwardTo, record));
|
|
510
|
+
}
|
|
511
|
+
return handler;
|
|
512
|
+
}
|
|
513
|
+
|
|
514
|
+
/**
|
|
515
|
+
* Resolves an ordered list of decorators from a component's with property.
|
|
516
|
+
* @param declaration Comma-separated names from the component definition, or undefined.
|
|
517
|
+
* @returns The registered decorators in declaration order.
|
|
518
|
+
*/
|
|
519
|
+
public componentDecorators(declaration: unknown): readonly ComponentDecorator[] {
|
|
520
|
+
if (typeof declaration === "undefined") {
|
|
521
|
+
return [];
|
|
522
|
+
}
|
|
523
|
+
if (typeof declaration !== "string") {
|
|
524
|
+
throw new TypeError(this.i18n.t("tiun.errors.component.decorator_list"));
|
|
525
|
+
}
|
|
526
|
+
const names = declaration.split(",").map((name) => name.trim());
|
|
527
|
+
if (new Set(names).size !== names.length || !names.every((name) => decoratorName.test(name))) {
|
|
528
|
+
throw new TypeError(this.i18n.t("tiun.errors.component.decorator_list"));
|
|
529
|
+
}
|
|
530
|
+
return names.map((name) => {
|
|
531
|
+
const external = this.registry.decorators,
|
|
532
|
+
standard = standardDecorators[name];
|
|
533
|
+
if (external && Object.hasOwn(external, name)) {
|
|
534
|
+
const handler = external[name];
|
|
535
|
+
if (typeof handler === "function") {
|
|
536
|
+
return handler;
|
|
537
|
+
}
|
|
538
|
+
}
|
|
539
|
+
if (Object.hasOwn(standardDecorators, name) && typeof standard === "function") {
|
|
540
|
+
return standard;
|
|
541
|
+
}
|
|
542
|
+
throw new TypeError(this.i18n.t("tiun.errors.component.decorator_missing", { name }));
|
|
543
|
+
});
|
|
544
|
+
}
|
|
545
|
+
|
|
546
|
+
/**
|
|
547
|
+
* Resolves a text rendering function and applies the settings of built-in renderer names.
|
|
548
|
+
* @param name Renderer name read from configuration.
|
|
549
|
+
* @returns A render function for the configured name, or undefined.
|
|
550
|
+
*/
|
|
551
|
+
public textRenderer(name: unknown): SchemaTextRenderer | undefined {
|
|
552
|
+
const renderer = typeof name === "string" && this.renderer(name),
|
|
553
|
+
standard = [renderInlineMarkdown, renderPlainText].find((entry): boolean => entry === renderer);
|
|
554
|
+
if (renderer !== false && typeof renderer !== "undefined" && !standard) {
|
|
555
|
+
return (props: SchemaTextProps): ReactNode => createElement(renderer, props);
|
|
556
|
+
}
|
|
557
|
+
return standard;
|
|
558
|
+
}
|
|
559
|
+
|
|
560
|
+
/** Extends trusted adapters while preserving metadata and the live translation store. */
|
|
561
|
+
withRegistry(additions: SchemaRegistry<T>): Schema<T> {
|
|
562
|
+
const keys = [
|
|
563
|
+
"components",
|
|
564
|
+
"decorators",
|
|
565
|
+
"values",
|
|
566
|
+
"renderers",
|
|
567
|
+
"insertions",
|
|
568
|
+
"actions",
|
|
569
|
+
"commands",
|
|
570
|
+
"formComponents",
|
|
571
|
+
"projectors",
|
|
572
|
+
"methods",
|
|
573
|
+
"validations",
|
|
574
|
+
] as const,
|
|
575
|
+
registry: SchemaRegistry<T> = {
|
|
576
|
+
...this.registry,
|
|
577
|
+
...additions,
|
|
578
|
+
...Object.fromEntries(keys.map((key) => [key, { ...this.registry[key], ...additions[key] }] as const)),
|
|
579
|
+
};
|
|
580
|
+
return new Schema(this.metadata, {
|
|
581
|
+
i18n: this.i18n,
|
|
582
|
+
registry,
|
|
583
|
+
...(this.onWarning ? { onWarning: this.onWarning } : {}),
|
|
584
|
+
});
|
|
585
|
+
}
|
|
586
|
+
|
|
587
|
+
/**
|
|
588
|
+
* Ищет вид в подготовленной схеме.
|
|
589
|
+
* @param name Имя компонента вида.
|
|
590
|
+
* @returns Подготовленный вид либо `undefined` для неизвестного имени.
|
|
591
|
+
*/
|
|
592
|
+
view(name: string): SchemaViewMeta<T> | undefined {
|
|
593
|
+
return Object.hasOwn(this.views, name) ? this.views[name] : undefined;
|
|
594
|
+
}
|
|
595
|
+
|
|
596
|
+
/**
|
|
597
|
+
* Сопоставляет адрес с настроенным видом.
|
|
598
|
+
* @param pathname Путь браузера.
|
|
599
|
+
* @param hash Фрагмент, переданный отдельно от пути.
|
|
600
|
+
* @returns Вид и параметры маршрута либо undefined.
|
|
601
|
+
*/
|
|
602
|
+
matchRoute(pathname: string, hash?: string): RouteMatch<T> | undefined {
|
|
603
|
+
return this.routes.match(pathname, hash);
|
|
604
|
+
}
|
|
605
|
+
|
|
606
|
+
/**
|
|
607
|
+
* Строит именованный путь по настроенному виду.
|
|
608
|
+
* @param target Вид, параметры, query и фрагмент.
|
|
609
|
+
* @returns Путь браузера либо undefined.
|
|
610
|
+
*/
|
|
611
|
+
path(target: NamedRoute): string | undefined {
|
|
612
|
+
return this.routes.path(target);
|
|
613
|
+
}
|
|
614
|
+
|
|
615
|
+
/** Возвращает имена компонентов, задействованных в маршрутах. */
|
|
616
|
+
get routeComponents(): readonly string[] {
|
|
617
|
+
return this.routes.components;
|
|
618
|
+
}
|
|
619
|
+
|
|
620
|
+
/** Возвращает предупреждения о шаблонах маршрутов. */
|
|
621
|
+
get routeWarnings(): readonly string[] {
|
|
622
|
+
return this.routes.warnings;
|
|
623
|
+
}
|
|
624
|
+
|
|
625
|
+
/** Собирает маршруты при первом обращении к ним и возвращает результат. */
|
|
626
|
+
private get routes(): ReturnType<typeof compileRoutes<T>> {
|
|
627
|
+
return (this.compiledRoutes ??= compileRoutes(this.views));
|
|
628
|
+
}
|
|
629
|
+
|
|
630
|
+
/** Resolves the prepared fields of a named form component. */
|
|
631
|
+
formFields(name: string): FormMeta | undefined {
|
|
632
|
+
return Object.hasOwn(this.fieldDefinitions, name) ? this.fieldDefinitions[name] : undefined;
|
|
633
|
+
}
|
|
634
|
+
|
|
635
|
+
/**
|
|
636
|
+
* Resolves the initial GET of a mounted form.
|
|
637
|
+
* @param definition The form definition with its resource name.
|
|
638
|
+
* @param identity The record identity for a parameterized resource.
|
|
639
|
+
* @param routeParameters Named values from the active route.
|
|
640
|
+
* @returns The path to read or undefined when the form has no available GET path.
|
|
641
|
+
*/
|
|
642
|
+
formRead(
|
|
643
|
+
definition: ComponentDefinition,
|
|
644
|
+
identity?: string | number,
|
|
645
|
+
routeParameters?: Readonly<Record<string, string>>,
|
|
646
|
+
): string | undefined {
|
|
647
|
+
const formResources = isData(definition.resources) ? definition.resources : undefined,
|
|
648
|
+
readResourceName = formResources?.access;
|
|
649
|
+
if (typeof readResourceName !== "string") {
|
|
650
|
+
return undefined;
|
|
651
|
+
}
|
|
652
|
+
if (!resourceAllowed(this.metadata, readResourceName, "get")) {
|
|
653
|
+
return undefined;
|
|
654
|
+
}
|
|
655
|
+
const operation = recordOperation(this.metadata, readResourceName, "get"),
|
|
656
|
+
parameters = resourceParameters(operation, formResources?.params, routeParameters);
|
|
657
|
+
if (
|
|
658
|
+
identity === undefined &&
|
|
659
|
+
parameters === undefined &&
|
|
660
|
+
/:[a-z_][a-z0-9_]*|<[a-z_][a-z0-9_]*>/i.test(operation.path)
|
|
661
|
+
) {
|
|
662
|
+
return undefined;
|
|
663
|
+
}
|
|
664
|
+
return recordPath(operation, identity, parameters);
|
|
665
|
+
}
|
|
666
|
+
|
|
667
|
+
/**
|
|
668
|
+
* Prepares the route and document layout of a named View.
|
|
669
|
+
* @param page The compiled View component.
|
|
670
|
+
* @returns The prepared route or undefined when its configuration is invalid.
|
|
671
|
+
*/
|
|
672
|
+
private compiledPage(page: ComponentDefinition): SchemaViewMeta<T> | undefined {
|
|
673
|
+
const { name, mountTo, parent, separator, className, menu, component } = page,
|
|
674
|
+
context: { contextMethod?: string; with?: unknown } = {},
|
|
675
|
+
source = `components.${name}`;
|
|
676
|
+
if (Object.hasOwn(page, "row")) {
|
|
677
|
+
this.warn(`${source}.row: declare records inside children`);
|
|
678
|
+
return undefined;
|
|
679
|
+
}
|
|
680
|
+
if (
|
|
681
|
+
(mountTo !== undefined && (typeof mountTo !== "string" || !mountTo)) ||
|
|
682
|
+
(parent !== undefined && (typeof parent !== "string" || !parent)) ||
|
|
683
|
+
(separator !== undefined && separator !== "/" && separator !== "#")
|
|
684
|
+
) {
|
|
685
|
+
this.warn(`${source}.mount_to: invalid mount point, parent or separator`);
|
|
686
|
+
return undefined;
|
|
687
|
+
}
|
|
688
|
+
const layout = this.pageLayout(page.html, page, source);
|
|
689
|
+
if (!layout) {
|
|
690
|
+
return undefined;
|
|
691
|
+
}
|
|
692
|
+
const labels: Record<string, string> = {};
|
|
693
|
+
if (menu !== undefined && (typeof menu !== "string" || !namePattern.test(menu))) {
|
|
694
|
+
throw new TypeError(`${source}.menu: expected component name`);
|
|
695
|
+
}
|
|
696
|
+
if (page.labels !== undefined) {
|
|
697
|
+
if (!isData(page.labels)) {
|
|
698
|
+
throw new TypeError(`${source}.labels: expected mapping`);
|
|
699
|
+
}
|
|
700
|
+
for (const key of ["loading"]) {
|
|
701
|
+
const value = page.labels[key];
|
|
702
|
+
if (value === null) {
|
|
703
|
+
continue;
|
|
704
|
+
}
|
|
705
|
+
if (typeof value === "string" && !value.startsWith(":")) {
|
|
706
|
+
labels[key] = value;
|
|
707
|
+
} else {
|
|
708
|
+
this.label(labels, key, value, `${source}.labels.${key}`);
|
|
709
|
+
}
|
|
710
|
+
}
|
|
711
|
+
}
|
|
712
|
+
if (typeof page.contextMethod === "string") {
|
|
713
|
+
context.contextMethod = page.contextMethod;
|
|
714
|
+
}
|
|
715
|
+
if (Object.hasOwn(page, "with")) {
|
|
716
|
+
context.with = page.with;
|
|
717
|
+
}
|
|
718
|
+
return Object.freeze({
|
|
719
|
+
...context,
|
|
720
|
+
columns: Object.freeze([]),
|
|
721
|
+
intro: Object.freeze([]),
|
|
722
|
+
layout,
|
|
723
|
+
name,
|
|
724
|
+
...(typeof menu === "string" ? { menu } : {}),
|
|
725
|
+
...(typeof mountTo === "string" ? { mountTo } : {}),
|
|
726
|
+
...(typeof parent === "string" ? { parent } : {}),
|
|
727
|
+
...(separator === "/" || separator === "#" ? { separator } : {}),
|
|
728
|
+
...(typeof className === "string" ? { className } : {}),
|
|
729
|
+
component: typeof component === "string" ? component : name,
|
|
730
|
+
labels: Object.freeze(labels),
|
|
731
|
+
});
|
|
732
|
+
}
|
|
733
|
+
|
|
734
|
+
/**
|
|
735
|
+
* Builds named layouts in metadata order.
|
|
736
|
+
* @param value Named layouts from settings.layouts.
|
|
737
|
+
* @returns Named layouts and the first marked default, if any.
|
|
738
|
+
*/
|
|
739
|
+
private compiledLayouts(value: unknown): {
|
|
740
|
+
layouts: ReadonlyMap<string, Layout>;
|
|
741
|
+
defaultLayout: Layout | undefined;
|
|
742
|
+
} {
|
|
743
|
+
const layouts = new Map<string, Layout>();
|
|
744
|
+
let defaultLayout: Layout | undefined;
|
|
745
|
+
if (value === undefined) {
|
|
746
|
+
return { defaultLayout, layouts };
|
|
747
|
+
}
|
|
748
|
+
if (!Array.isArray(value)) {
|
|
749
|
+
throw new TypeError("settings.layouts: expected list");
|
|
750
|
+
}
|
|
751
|
+
|
|
752
|
+
for (const entry of value) {
|
|
753
|
+
if (!isData(entry) || typeof entry.name !== "string" || !namePattern.test(entry.name)) {
|
|
754
|
+
throw new TypeError("settings.layouts: expected a named layout");
|
|
755
|
+
}
|
|
756
|
+
const path = `settings.layouts.${entry.name}`;
|
|
757
|
+
if (layouts.has(entry.name)) {
|
|
758
|
+
this.warn(`${path}: duplicate name`);
|
|
759
|
+
continue;
|
|
760
|
+
}
|
|
761
|
+
const layout = this.compiledDocument(entry, path);
|
|
762
|
+
layouts.set(entry.name, layout);
|
|
763
|
+
if (entry.default === true) {
|
|
764
|
+
if (defaultLayout) {
|
|
765
|
+
this.warn(`${path}.default: only one default layout is allowed`);
|
|
766
|
+
} else {
|
|
767
|
+
defaultLayout = layout;
|
|
768
|
+
}
|
|
769
|
+
}
|
|
770
|
+
}
|
|
771
|
+
return { defaultLayout, layouts };
|
|
772
|
+
}
|
|
773
|
+
|
|
774
|
+
/**
|
|
775
|
+
* Resolves the selected layout and applies document properties declared on the View.
|
|
776
|
+
* @param html Previous inline View document properties.
|
|
777
|
+
* @param raw View definition with its layout name and direct document properties.
|
|
778
|
+
* @param path Source path for schema diagnostics.
|
|
779
|
+
* @returns The effective layout or undefined for an unknown name.
|
|
780
|
+
*/
|
|
781
|
+
private pageLayout(html: HtmlDefs | undefined, raw: Data, path: string): Layout | undefined {
|
|
782
|
+
const configuredLayout = raw.layout,
|
|
783
|
+
layoutName = typeof configuredLayout === "string" ? configuredLayout : undefined,
|
|
784
|
+
selectedLayout = layoutName === undefined ? this.layout : this.layouts.get(layoutName);
|
|
785
|
+
if (layoutName !== undefined && !selectedLayout) {
|
|
786
|
+
this.warn(`${path}.layout: unknown layout ${layoutName}`);
|
|
787
|
+
return undefined;
|
|
788
|
+
}
|
|
789
|
+
const customLayout =
|
|
790
|
+
layoutName === undefined ? this.compiledLayout(configuredLayout, `${path}.layout`) : undefined,
|
|
791
|
+
document = this.compiledDocument(raw, path),
|
|
792
|
+
{ lang, dir } = { ...selectedLayout, ...html, ...customLayout, ...document };
|
|
793
|
+
return Object.freeze({
|
|
794
|
+
...selectedLayout,
|
|
795
|
+
...customLayout,
|
|
796
|
+
...(lang === undefined ? {} : { lang }),
|
|
797
|
+
...(dir === undefined ? {} : { dir }),
|
|
798
|
+
body: Object.freeze({ ...selectedLayout?.body, ...html?.body, ...customLayout?.body, ...document.body }),
|
|
799
|
+
head: Object.freeze({ ...selectedLayout?.head, ...html?.head, ...customLayout?.head, ...document.head }),
|
|
800
|
+
});
|
|
801
|
+
}
|
|
802
|
+
|
|
803
|
+
/**
|
|
804
|
+
* Compiles an inline layout and validates references to its shell components.
|
|
805
|
+
* @param value Legacy inline layout settings.
|
|
806
|
+
* @param path Source path for schema diagnostics.
|
|
807
|
+
* @returns The layout or undefined when no inline settings were supplied.
|
|
808
|
+
*/
|
|
809
|
+
private compiledLayout(value: unknown, path: string): Layout | undefined {
|
|
810
|
+
if (value === undefined) {
|
|
811
|
+
return undefined;
|
|
812
|
+
}
|
|
813
|
+
if (!isData(value)) {
|
|
814
|
+
throw new TypeError(`${path}: expected mapping`);
|
|
815
|
+
}
|
|
816
|
+
if (Object.hasOwn(value, "html")) {
|
|
817
|
+
throw new TypeError(`${path}.html: declare lang, dir, head and body directly in layout`);
|
|
818
|
+
}
|
|
819
|
+
const { header, footer, scroll } = value;
|
|
820
|
+
for (const [key, name] of [
|
|
821
|
+
["header", header],
|
|
822
|
+
["footer", footer],
|
|
823
|
+
] as const) {
|
|
824
|
+
if (name !== undefined && (typeof name !== "string" || !Object.hasOwn(this.componentDefinitions, name))) {
|
|
825
|
+
throw new TypeError(`${path}.${key}: unknown component ${String(name)}`);
|
|
826
|
+
}
|
|
827
|
+
}
|
|
828
|
+
if (scroll !== undefined && typeof scroll !== "boolean") {
|
|
829
|
+
throw new TypeError(`${path}.scroll: expected boolean`);
|
|
830
|
+
}
|
|
831
|
+
return Object.freeze({
|
|
832
|
+
...(typeof header === "string" ? { header } : {}),
|
|
833
|
+
...(typeof footer === "string" ? { footer } : {}),
|
|
834
|
+
...(typeof scroll === "boolean" ? { scroll } : {}),
|
|
835
|
+
...this.compiledDocument(value, path),
|
|
836
|
+
});
|
|
837
|
+
}
|
|
838
|
+
|
|
839
|
+
/**
|
|
840
|
+
* Compiles the direct document properties and preserves native attribute names.
|
|
841
|
+
* @param value A named layout or a raw View definition.
|
|
842
|
+
* @param path Source path for schema diagnostics.
|
|
843
|
+
* @returns Only the supported properties of the HTML document.
|
|
844
|
+
*/
|
|
845
|
+
private compiledDocument(value: Data, path: string): HtmlDefs {
|
|
846
|
+
const { lang, dir, head, body } = value;
|
|
847
|
+
if (lang !== undefined && typeof lang !== "string") {
|
|
848
|
+
throw new TypeError(`${path}.lang: expected string`);
|
|
849
|
+
}
|
|
850
|
+
if (dir !== undefined && typeof dir !== "string") {
|
|
851
|
+
throw new TypeError(`${path}.dir: expected string`);
|
|
852
|
+
}
|
|
853
|
+
if (head !== undefined && !isData(head)) {
|
|
854
|
+
throw new TypeError(`${path}.head: expected mapping`);
|
|
855
|
+
}
|
|
856
|
+
if (body !== undefined && !isData(body)) {
|
|
857
|
+
throw new TypeError(`${path}.body: expected mapping`);
|
|
858
|
+
}
|
|
859
|
+
return compileDocumentProperties({
|
|
860
|
+
...(lang === undefined ? {} : { lang }),
|
|
861
|
+
...(dir === undefined ? {} : { dir }),
|
|
862
|
+
...(head === undefined ? {} : { head }),
|
|
863
|
+
...(body === undefined ? {} : { body }),
|
|
864
|
+
});
|
|
865
|
+
}
|
|
866
|
+
|
|
867
|
+
/** Resolves the configuration of content rendered inside a page. */
|
|
868
|
+
definition(name: string): SchemaViewMeta<T> | undefined {
|
|
869
|
+
return (
|
|
870
|
+
this.view(name) ?? (Object.hasOwn(this.contentDefinitions, name) ? this.contentDefinitions[name] : undefined)
|
|
871
|
+
);
|
|
872
|
+
}
|
|
873
|
+
|
|
874
|
+
/**
|
|
875
|
+
* Resolves image bindings and selects image callbacks.
|
|
876
|
+
* @param name Name of the configured image.
|
|
877
|
+
* @param data Current record.
|
|
878
|
+
* @param input Props supplied by the React caller.
|
|
879
|
+
* @param configured Overrides from a component reference.
|
|
880
|
+
* @returns The resolved image settings or undefined if the definition cannot be used.
|
|
881
|
+
*/
|
|
882
|
+
image(
|
|
883
|
+
name: string,
|
|
884
|
+
data: T,
|
|
885
|
+
input: Readonly<Record<string, unknown>> = {},
|
|
886
|
+
configured?: ComponentDefinition,
|
|
887
|
+
): ImageProps | undefined {
|
|
888
|
+
const image = this.definition(name);
|
|
889
|
+
if (image?.element !== "image") {
|
|
890
|
+
return undefined;
|
|
891
|
+
}
|
|
892
|
+
const view: Data = { ...image, ...configured };
|
|
893
|
+
if (typeof view.source !== "string") {
|
|
894
|
+
return undefined;
|
|
895
|
+
}
|
|
896
|
+
|
|
897
|
+
const incoming = selectedProps(view.props, input),
|
|
898
|
+
measure = (value: unknown): number | undefined =>
|
|
899
|
+
typeof value === "number" && Number.isFinite(value) && value > 0 ? value : undefined,
|
|
900
|
+
parameter = (key: string, fallback?: unknown): unknown =>
|
|
901
|
+
Object.hasOwn(incoming, key) ? incoming[key] : this.binding(view[key] ?? fallback, data),
|
|
902
|
+
readText = (binding: unknown): string | undefined => {
|
|
903
|
+
const value = typeof binding === "string" ? this.value(binding, data) : undefined;
|
|
904
|
+
return typeof value === "string" ? value : undefined;
|
|
905
|
+
},
|
|
906
|
+
resolvedTitle = readText(view.labelFrom),
|
|
907
|
+
selectedDescription = parameter("description"),
|
|
908
|
+
selectedRenderer = this.textRenderer(view.renderer),
|
|
909
|
+
targetBinding = parameter("onClick"),
|
|
910
|
+
tooltip = this.tooltip(
|
|
911
|
+
Object.hasOwn(incoming, "tooltip") ? incoming.tooltip : view.tooltip,
|
|
912
|
+
data,
|
|
913
|
+
Object.hasOwn(incoming, "tooltip"),
|
|
914
|
+
),
|
|
915
|
+
usesAbsoluteUrl = typeof targetBinding === "string" && /^[a-z][a-z0-9+.-]*:/i.test(targetBinding),
|
|
916
|
+
viewSource = readText(view.source),
|
|
917
|
+
[width, height] = [measure(parameter("width", "$width")), measure(parameter("height", "$height"))];
|
|
918
|
+
let description: ReactNode,
|
|
919
|
+
title: ReactNode = resolvedTitle;
|
|
920
|
+
if (selectedRenderer && typeof resolvedTitle === "string" && resolvedTitle !== "") {
|
|
921
|
+
title = selectedRenderer({ source: resolvedTitle });
|
|
922
|
+
}
|
|
923
|
+
if (typeof selectedDescription === "string") {
|
|
924
|
+
description = selectedDescription;
|
|
925
|
+
if (selectedRenderer) {
|
|
926
|
+
description = selectedRenderer({ source: selectedDescription });
|
|
927
|
+
}
|
|
928
|
+
}
|
|
929
|
+
return {
|
|
930
|
+
alt: tooltip.text,
|
|
931
|
+
className: typeof view.className === "string" ? view.className : undefined,
|
|
932
|
+
description,
|
|
933
|
+
height,
|
|
934
|
+
minHeight: typeof view.minHeight === "number" ? view.minHeight : undefined,
|
|
935
|
+
native: typeof view.native === "boolean" ? view.native : undefined,
|
|
936
|
+
path: typeof targetBinding === "string" && !usesAbsoluteUrl ? targetBinding : undefined,
|
|
937
|
+
src: viewSource,
|
|
938
|
+
title,
|
|
939
|
+
tooltip: tooltip.content,
|
|
940
|
+
url: typeof targetBinding === "string" && usesAbsoluteUrl ? targetBinding : undefined,
|
|
941
|
+
variant: view.viewAs === "card" || view.viewAs === "plain" ? view.viewAs : undefined,
|
|
942
|
+
width,
|
|
943
|
+
...imageEvents(incoming),
|
|
944
|
+
};
|
|
945
|
+
}
|
|
946
|
+
|
|
947
|
+
/**
|
|
948
|
+
* Applies the trusted data preparation named in the component configuration.
|
|
949
|
+
* @param name Registered projector or method name.
|
|
950
|
+
* @param record Input data to prepare.
|
|
951
|
+
* @returns Prepared data, or the original data when no method was specified.
|
|
952
|
+
*/
|
|
953
|
+
prepare(name: string | undefined, record: T): unknown {
|
|
954
|
+
if (!name) {
|
|
955
|
+
return record;
|
|
956
|
+
}
|
|
957
|
+
let projector: ((record: T) => unknown) | undefined = this.method(name)?.prepare;
|
|
958
|
+
if (this.registry.projectors && Object.hasOwn(this.registry.projectors, name)) {
|
|
959
|
+
projector = this.registry.projectors[name] ?? projector;
|
|
960
|
+
}
|
|
961
|
+
if (!projector) {
|
|
962
|
+
throw new Error(`Unknown record projector: ${name}`);
|
|
963
|
+
}
|
|
964
|
+
return projector(record);
|
|
965
|
+
}
|
|
966
|
+
|
|
967
|
+
formComponents(): ComponentRegistry<Readonly<Record<string, unknown>>> {
|
|
968
|
+
return this.registry.formComponents ?? {};
|
|
969
|
+
}
|
|
970
|
+
|
|
971
|
+
/**
|
|
972
|
+
* Resolves the registered callback for a form that has saved its record.
|
|
973
|
+
* @param definition The compiled form definition.
|
|
974
|
+
* @returns The callback when the form declares one.
|
|
975
|
+
*/
|
|
976
|
+
formStored(definition: ComponentDefinition): FrontendMethod["onStored"] {
|
|
977
|
+
const name = definition.onStored;
|
|
978
|
+
if (name === undefined) {
|
|
979
|
+
return undefined;
|
|
980
|
+
}
|
|
981
|
+
const callback = typeof name === "string" ? this.method(name)?.onStored : undefined;
|
|
982
|
+
if (!callback) {
|
|
983
|
+
throw new TypeError(this.i18n.t("tiun.errors.form.stored_method"));
|
|
984
|
+
}
|
|
985
|
+
return callback;
|
|
986
|
+
}
|
|
987
|
+
|
|
988
|
+
private method(name: string): FrontendMethod | undefined {
|
|
989
|
+
if (this.registry.methods && Object.hasOwn(this.registry.methods, name)) {
|
|
990
|
+
return this.registry.methods[name];
|
|
991
|
+
}
|
|
992
|
+
return Object.hasOwn(methods, name) ? methods[name as keyof typeof methods] : undefined;
|
|
993
|
+
}
|
|
994
|
+
|
|
995
|
+
component(name?: string): ComponentType<SchemaBlockProps<T>> | undefined {
|
|
996
|
+
return name && this.registry.components && Object.hasOwn(this.registry.components, name)
|
|
997
|
+
? this.registry.components[name]
|
|
998
|
+
: undefined;
|
|
999
|
+
}
|
|
1000
|
+
|
|
1001
|
+
private readonly chipInsertions = new Map<string, ComponentType<FlexTextInsertionProps>>();
|
|
1002
|
+
|
|
1003
|
+
insertionRenderer(name?: string): ComponentType<FlexTextInsertionProps> | undefined {
|
|
1004
|
+
const registered =
|
|
1005
|
+
name && this.registry.insertions && Object.hasOwn(this.registry.insertions, name)
|
|
1006
|
+
? this.registry.insertions[name]
|
|
1007
|
+
: undefined,
|
|
1008
|
+
resolvedDefinition = name ? this.definition(name) : undefined;
|
|
1009
|
+
if (registered || !name || resolvedDefinition?.element !== "chip" || !resolvedDefinition.item) {
|
|
1010
|
+
return registered;
|
|
1011
|
+
}
|
|
1012
|
+
let renderer = this.chipInsertions.get(name);
|
|
1013
|
+
if (!renderer) {
|
|
1014
|
+
renderer = ({ values }) => createElement(Component<T>, { data: values, name, schema: this });
|
|
1015
|
+
this.chipInsertions.set(name, renderer);
|
|
1016
|
+
}
|
|
1017
|
+
return renderer;
|
|
1018
|
+
}
|
|
1019
|
+
|
|
1020
|
+
/**
|
|
1021
|
+
* Binds an explicitly registered route or data command without discarding its result.
|
|
1022
|
+
* @param name The registered command name.
|
|
1023
|
+
* @param record The record supplied to the command.
|
|
1024
|
+
* @param context Optional information about the origin of the command.
|
|
1025
|
+
* @returns The bound command, or undefined if the name is unregistered.
|
|
1026
|
+
*/
|
|
1027
|
+
// eslint-disable-next-line @typescript-eslint/member-ordering -- Keep the public registry lookups together.
|
|
1028
|
+
public command(name: string | undefined, record: T, context?: SchemaCommandContext): (() => unknown) | undefined {
|
|
1029
|
+
const handler =
|
|
1030
|
+
name && this.registry.commands && Object.hasOwn(this.registry.commands, name)
|
|
1031
|
+
? this.registry.commands[name]
|
|
1032
|
+
: undefined;
|
|
1033
|
+
return handler && ((): unknown => handler(record, context));
|
|
1034
|
+
}
|
|
1035
|
+
|
|
1036
|
+
/**
|
|
1037
|
+
* Resolves a registered text renderer or a standard one.
|
|
1038
|
+
* @param name Renderer selected in component configuration.
|
|
1039
|
+
* @returns The renderer, if the name is known.
|
|
1040
|
+
*/
|
|
1041
|
+
renderer(name?: string): ComponentType<SchemaTextProps> | undefined {
|
|
1042
|
+
const key = name ?? "";
|
|
1043
|
+
let result: ComponentType<SchemaTextProps> | undefined;
|
|
1044
|
+
if (this.registry.renderers && Object.hasOwn(this.registry.renderers, key)) {
|
|
1045
|
+
return this.registry.renderers[key];
|
|
1046
|
+
}
|
|
1047
|
+
if (key === "markdown" || inlineRenderers.includes(key)) {
|
|
1048
|
+
result = this.markdownRenderer(key !== "markdown");
|
|
1049
|
+
} else if (key === "plain") {
|
|
1050
|
+
result = renderPlainText;
|
|
1051
|
+
}
|
|
1052
|
+
return result;
|
|
1053
|
+
}
|
|
1054
|
+
|
|
1055
|
+
/**
|
|
1056
|
+
* Resolves the Markdown renderer with the decorators from the application settings.
|
|
1057
|
+
* @param inline Whether to render paragraphs inline.
|
|
1058
|
+
* @returns A Markdown renderer for the selected display mode.
|
|
1059
|
+
*/
|
|
1060
|
+
private markdownRenderer(inline: boolean): ComponentType<SchemaTextProps> {
|
|
1061
|
+
const cached = this.markdownRenderers.get(inline),
|
|
1062
|
+
{ node } = this.configuredComponent({ name: "markdown", of: "markdown" });
|
|
1063
|
+
if (cached) {
|
|
1064
|
+
return cached;
|
|
1065
|
+
}
|
|
1066
|
+
if (typeof node.with === "undefined") {
|
|
1067
|
+
if (inline) {
|
|
1068
|
+
return renderInlineMarkdown;
|
|
1069
|
+
}
|
|
1070
|
+
return Markdown;
|
|
1071
|
+
}
|
|
1072
|
+
// eslint-disable-next-line one-var -- Build the renderer only after checking the settings and the cache.
|
|
1073
|
+
const decorated = decorateComponent<T, MarkdownProps & DecoratedProps>(Markdown, this, node.with),
|
|
1074
|
+
/**
|
|
1075
|
+
* Renders Markdown with the selected decorators and display mode.
|
|
1076
|
+
* @param props Source text and presentation options.
|
|
1077
|
+
* @returns The decorated Markdown element.
|
|
1078
|
+
*/
|
|
1079
|
+
render = (props: SchemaTextProps): ReactElement =>
|
|
1080
|
+
createElement(decorated, { ...props, inline: inline || props.inline === true, schema: this });
|
|
1081
|
+
this.markdownRenderers.set(inline, render);
|
|
1082
|
+
return render;
|
|
1083
|
+
}
|
|
1084
|
+
|
|
1085
|
+
/**
|
|
1086
|
+
* Resolves an attachment preview from a named image or a registered renderer.
|
|
1087
|
+
* @param name The preview name declared on the attachment field.
|
|
1088
|
+
* @returns The preview configuration, if the name is available.
|
|
1089
|
+
*/
|
|
1090
|
+
private attachmentPreview(name: string): FieldMeta["preview"] {
|
|
1091
|
+
if (this.componentDefinitions[name]?.of === "image") {
|
|
1092
|
+
return {
|
|
1093
|
+
image: true,
|
|
1094
|
+
render: ({ source }) => createElement(Component<T>, { data: { source }, name, schema: this, source }),
|
|
1095
|
+
};
|
|
1096
|
+
}
|
|
1097
|
+
const render = this.textRenderer(name);
|
|
1098
|
+
let preview: FieldMeta["preview"];
|
|
1099
|
+
if (render) {
|
|
1100
|
+
preview = { render };
|
|
1101
|
+
}
|
|
1102
|
+
return preview;
|
|
1103
|
+
}
|
|
1104
|
+
|
|
1105
|
+
/**
|
|
1106
|
+
* Renders a tooltip from text, a binding or a trusted renderer selected by name.
|
|
1107
|
+
* - Splits a configured renderer:text pair before resolving the text binding.
|
|
1108
|
+
* @param value Configured value or literal property supplied by the caller.
|
|
1109
|
+
* @param data Current record used to resolve bindings.
|
|
1110
|
+
* @param literal Whether to pass the supplied value directly.
|
|
1111
|
+
* @returns The tooltip content and its optional text label.
|
|
1112
|
+
*/
|
|
1113
|
+
tooltip(
|
|
1114
|
+
value: unknown,
|
|
1115
|
+
data: T,
|
|
1116
|
+
literal = false,
|
|
1117
|
+
): { readonly content: ReactNode; readonly text?: string | undefined } {
|
|
1118
|
+
const pair = !literal && typeof value === "string" ? /^([a-z_][a-z0-9_.-]*):([\s\S]*)$/i.exec(value) : null,
|
|
1119
|
+
source = literal ? value : bindingValue(pair ? pair[2] : value, data, this.i18n.t, false),
|
|
1120
|
+
text = typeof source === "string" || typeof source === "number" ? String(source) : undefined;
|
|
1121
|
+
if (pair) {
|
|
1122
|
+
const [, name] = pair,
|
|
1123
|
+
renderText = this.textRenderer(name);
|
|
1124
|
+
if (renderText) {
|
|
1125
|
+
return { content: renderText({ source: text ?? "" }), text };
|
|
1126
|
+
}
|
|
1127
|
+
if (name !== "text") {
|
|
1128
|
+
throw new TypeError(`Unknown tooltip renderer: ${name}`);
|
|
1129
|
+
}
|
|
1130
|
+
return { content: text, text };
|
|
1131
|
+
}
|
|
1132
|
+
const content =
|
|
1133
|
+
typeof source === "function"
|
|
1134
|
+
? createElement(source as ComponentType<{ data: T }>, { data })
|
|
1135
|
+
: (text ?? (isValidElement(source) ? source : undefined));
|
|
1136
|
+
return { content, text };
|
|
1137
|
+
}
|
|
1138
|
+
|
|
1139
|
+
uid(value: unknown, data: unknown): string | number | undefined {
|
|
1140
|
+
return componentUid(value, data, this.i18n.t);
|
|
1141
|
+
}
|
|
1142
|
+
|
|
1143
|
+
binding(value: unknown, data: unknown): unknown {
|
|
1144
|
+
return bindingValue(value, data, this.i18n.t);
|
|
1145
|
+
}
|
|
1146
|
+
|
|
1147
|
+
private warn(message: string): void {
|
|
1148
|
+
this.warnings.push(message);
|
|
1149
|
+
this.onWarning?.(message);
|
|
1150
|
+
}
|
|
1151
|
+
|
|
1152
|
+
private label(target: object, property: string, reference: unknown, path: string): void {
|
|
1153
|
+
if (reference === undefined) {
|
|
1154
|
+
return;
|
|
1155
|
+
}
|
|
1156
|
+
if (typeof reference !== "string" || !reference.startsWith(":")) {
|
|
1157
|
+
this.warn(`${path}: expected translation reference`);
|
|
1158
|
+
return;
|
|
1159
|
+
}
|
|
1160
|
+
Object.defineProperty(target, property, { enumerable: true, get: () => this.i18n.t(reference) });
|
|
1161
|
+
}
|
|
1162
|
+
|
|
1163
|
+
private namedEntries(value: unknown, path: string): [string, Data][] {
|
|
1164
|
+
if (!Array.isArray(value)) {
|
|
1165
|
+
this.warn(`${path}: expected list`);
|
|
1166
|
+
return [];
|
|
1167
|
+
}
|
|
1168
|
+
const names = new Set<string>();
|
|
1169
|
+
|
|
1170
|
+
return value.flatMap((entry, index) => {
|
|
1171
|
+
if (!isData(entry) || typeof entry.name !== "string" || !namePattern.test(entry.name)) {
|
|
1172
|
+
this.warn(`${path}[${index}]: expected snake_case name`);
|
|
1173
|
+
return [];
|
|
1174
|
+
}
|
|
1175
|
+
if (names.has(entry.name)) {
|
|
1176
|
+
this.warn(`${path}[${index}]: duplicate name ${entry.name}`);
|
|
1177
|
+
return [];
|
|
1178
|
+
}
|
|
1179
|
+
names.add(entry.name);
|
|
1180
|
+
return [[entry.name, entry] as [string, Data]];
|
|
1181
|
+
});
|
|
1182
|
+
}
|
|
1183
|
+
|
|
1184
|
+
/**
|
|
1185
|
+
* Компилирует описание полей формы и сохраняет выбранный компонент в of.
|
|
1186
|
+
* @param value Упорядоченный список описаний полей из метаданных.
|
|
1187
|
+
* @param path Путь списка полей для предупреждений.
|
|
1188
|
+
* @returns Описания проверенных полей по имени.
|
|
1189
|
+
*/
|
|
1190
|
+
form(value: unknown, path: string): FormMeta {
|
|
1191
|
+
return Object.freeze(
|
|
1192
|
+
Object.fromEntries(
|
|
1193
|
+
this.namedEntries(value, path).flatMap(([name, field]) => {
|
|
1194
|
+
if (!isData(field) || typeof field.of !== "string" || !fieldTypes.has(field.of)) {
|
|
1195
|
+
this.warn(`${path}.${name}: unsupported field type (of)`);
|
|
1196
|
+
return [];
|
|
1197
|
+
}
|
|
1198
|
+
if (field.of === "component" && (typeof field.source !== "string" || !namePattern.test(field.source))) {
|
|
1199
|
+
this.warn(`${path}.${name}: component requires a registered source name`);
|
|
1200
|
+
return [];
|
|
1201
|
+
}
|
|
1202
|
+
const result: Record<string, unknown> = { of: field.of };
|
|
1203
|
+
if (field.of === "component" && typeof field.source === "string") {
|
|
1204
|
+
const external = this.externalField(field.source, `${path}.${name}`);
|
|
1205
|
+
if (external) result.external = external;
|
|
1206
|
+
}
|
|
1207
|
+
if (Object.hasOwn(field, "prepare")) {
|
|
1208
|
+
if (
|
|
1209
|
+
field.of !== "component" ||
|
|
1210
|
+
typeof field.prepare !== "string" ||
|
|
1211
|
+
!methodNamePattern.test(field.prepare)
|
|
1212
|
+
) {
|
|
1213
|
+
this.warn(`${path}.${name}.prepare: expected a method name on a component field`);
|
|
1214
|
+
return [];
|
|
1215
|
+
}
|
|
1216
|
+
const prepare = this.method(field.prepare)?.prepare;
|
|
1217
|
+
if (!prepare) {
|
|
1218
|
+
this.warn(`${path}.${name}.prepare: expected a registered prepare method`);
|
|
1219
|
+
return [];
|
|
1220
|
+
}
|
|
1221
|
+
result.prepareValue = prepare;
|
|
1222
|
+
}
|
|
1223
|
+
if (field.wait_to_send !== undefined) {
|
|
1224
|
+
const seconds = field.wait_to_send;
|
|
1225
|
+
const delay = typeof seconds === "number" && seconds >= 0 ? Math.round(seconds * 1000) : NaN;
|
|
1226
|
+
if (!Number.isSafeInteger(delay))
|
|
1227
|
+
this.warn(`${path}.${name}.wait_to_send: expected a duration in seconds`);
|
|
1228
|
+
else result.waitToSend = delay;
|
|
1229
|
+
}
|
|
1230
|
+
if (field.on_switch !== undefined) {
|
|
1231
|
+
const handler =
|
|
1232
|
+
typeof field.on_switch === "string" ? this.method(field.on_switch)?.onSwitch : undefined;
|
|
1233
|
+
if (field.of !== "wye" || typeof handler !== "function") {
|
|
1234
|
+
this.warn(`${path}.${name}.on_switch: expected a registered switch method on a wye field`);
|
|
1235
|
+
return [];
|
|
1236
|
+
}
|
|
1237
|
+
result.onSwitch = handler;
|
|
1238
|
+
}
|
|
1239
|
+
if (field.of === "wye") {
|
|
1240
|
+
if (field.values !== undefined) {
|
|
1241
|
+
const { values } = field;
|
|
1242
|
+
if (
|
|
1243
|
+
!Array.isArray(values) ||
|
|
1244
|
+
values.length !== 3 ||
|
|
1245
|
+
new Set(values).size !== 3 ||
|
|
1246
|
+
!values.every((value) => typeof value === "string" && value.length > 0)
|
|
1247
|
+
) {
|
|
1248
|
+
this.warn(`${path}.${name}.values: expected three distinct strings`);
|
|
1249
|
+
return [];
|
|
1250
|
+
}
|
|
1251
|
+
result.values = values;
|
|
1252
|
+
}
|
|
1253
|
+
if (field.pics !== undefined) {
|
|
1254
|
+
const pics = Array.isArray(field.pics)
|
|
1255
|
+
? field.pics.map((picture) => {
|
|
1256
|
+
if (!isData(picture)) {
|
|
1257
|
+
return undefined;
|
|
1258
|
+
}
|
|
1259
|
+
const source = picture.path ?? picture.url;
|
|
1260
|
+
if (typeof source === "string" && /^(?:\/(?!\/)|https?:\/\/)[^\s]+$/i.test(source)) {
|
|
1261
|
+
return { src: source };
|
|
1262
|
+
}
|
|
1263
|
+
return typeof picture.stock === "string" ? stockee(picture.stock) : undefined;
|
|
1264
|
+
})
|
|
1265
|
+
: [];
|
|
1266
|
+
if (pics.length !== 2 || pics.some((picture) => !picture)) {
|
|
1267
|
+
this.warn(`${path}.${name}.pics: expected two pictures`);
|
|
1268
|
+
return [];
|
|
1269
|
+
}
|
|
1270
|
+
result.pics = pics;
|
|
1271
|
+
}
|
|
1272
|
+
if (isData(field.labels)) {
|
|
1273
|
+
this.label(result, "title", field.labels.title, `${path}.${name}.labels.title`);
|
|
1274
|
+
const labels = field.labels.values;
|
|
1275
|
+
if (isData(labels)) {
|
|
1276
|
+
Object.defineProperty(result, "codeNames", {
|
|
1277
|
+
configurable: true,
|
|
1278
|
+
enumerable: true,
|
|
1279
|
+
get: () =>
|
|
1280
|
+
Object.fromEntries(
|
|
1281
|
+
Object.entries(labels)
|
|
1282
|
+
.filter((entry): entry is [string, string] => typeof entry[1] === "string")
|
|
1283
|
+
.map(([value, label]) => [value, this.i18n.t(label)]),
|
|
1284
|
+
),
|
|
1285
|
+
});
|
|
1286
|
+
}
|
|
1287
|
+
}
|
|
1288
|
+
}
|
|
1289
|
+
if (field.aliases !== undefined) {
|
|
1290
|
+
const names = typeof field.aliases === "string" ? [field.aliases] : field.aliases;
|
|
1291
|
+
if (
|
|
1292
|
+
Array.isArray(names) &&
|
|
1293
|
+
names.length &&
|
|
1294
|
+
names.every(
|
|
1295
|
+
(name) =>
|
|
1296
|
+
typeof name === "string" &&
|
|
1297
|
+
/^[a-z_][a-z0-9_]*$/.test(name) &&
|
|
1298
|
+
!["__proto__", "prototype", "constructor"].includes(name),
|
|
1299
|
+
)
|
|
1300
|
+
) {
|
|
1301
|
+
result.aliases = Object.freeze([...new Set(names)]);
|
|
1302
|
+
} else {
|
|
1303
|
+
this.warn(`${path}.${field.name}.aliases: expected field names`);
|
|
1304
|
+
}
|
|
1305
|
+
}
|
|
1306
|
+
if (typeof field.preview_renderer === "string") {
|
|
1307
|
+
result.preview = this.attachmentPreview(field.preview_renderer);
|
|
1308
|
+
}
|
|
1309
|
+
for (const key of copied) {
|
|
1310
|
+
if (Object.hasOwn(field, key)) {
|
|
1311
|
+
result[key] = field[key];
|
|
1312
|
+
}
|
|
1313
|
+
}
|
|
1314
|
+
for (const [server, client] of aliases) {
|
|
1315
|
+
if (server !== "code_names" && Object.hasOwn(field, server)) {
|
|
1316
|
+
result[client] = field[server];
|
|
1317
|
+
}
|
|
1318
|
+
}
|
|
1319
|
+
if (isData(field.transparency)) {
|
|
1320
|
+
result.transparency = field.transparency;
|
|
1321
|
+
}
|
|
1322
|
+
if (isData(field.states)) {
|
|
1323
|
+
const { fix } = field.states;
|
|
1324
|
+
result.states = isData(fix)
|
|
1325
|
+
? { ...field.states, fix: { color: fix.color, transientAction: fix.transient_action } }
|
|
1326
|
+
: field.states;
|
|
1327
|
+
}
|
|
1328
|
+
if (typeof field.resource === "string") {
|
|
1329
|
+
const { dynamic_limit: limit } = applicationSettings(this.metadata),
|
|
1330
|
+
matchedResource = findResource(this.metadata, field.resource),
|
|
1331
|
+
resourcePath = findResourceMethod(matchedResource, "get") ? matchedResource?.path : undefined;
|
|
1332
|
+
result.pathname =
|
|
1333
|
+
typeof resourcePath === "string" &&
|
|
1334
|
+
resourcePath.startsWith("/") &&
|
|
1335
|
+
!resourcePath.startsWith("//") &&
|
|
1336
|
+
!/[:?#\s]/.test(resourcePath)
|
|
1337
|
+
? resourcePath.replace(/^\//, "").replace(/\.json$/, "")
|
|
1338
|
+
: undefined;
|
|
1339
|
+
result.disabled = Boolean(field.disabled) || !result.pathname;
|
|
1340
|
+
if (
|
|
1341
|
+
field.limit === undefined &&
|
|
1342
|
+
typeof limit === "number" &&
|
|
1343
|
+
Number.isSafeInteger(limit) &&
|
|
1344
|
+
// eslint-disable-next-line @typescript-eslint/no-magic-numbers -- The minimum is one result.
|
|
1345
|
+
limit >= 1
|
|
1346
|
+
) {
|
|
1347
|
+
result.limit = limit;
|
|
1348
|
+
}
|
|
1349
|
+
}
|
|
1350
|
+
for (const key of ["title", "placeholder", "action"]) {
|
|
1351
|
+
if (!Object.hasOwn(result, key)) {
|
|
1352
|
+
this.label(result, key, field[key], `${path}.${name}.${key}`);
|
|
1353
|
+
}
|
|
1354
|
+
}
|
|
1355
|
+
for (const key of ["hint", "humanized_default"]) {
|
|
1356
|
+
if (typeof field[key] === "string" && String(field[key]).startsWith(":")) {
|
|
1357
|
+
this.label(result, key, field[key], `${path}.${name}.${key}`);
|
|
1358
|
+
}
|
|
1359
|
+
}
|
|
1360
|
+
if (field.meta !== undefined) {
|
|
1361
|
+
result.meta = this.form(field.meta, `${path}.${name}.meta`);
|
|
1362
|
+
}
|
|
1363
|
+
if (field.code_names !== undefined && !Object.hasOwn(result, "codeNames")) {
|
|
1364
|
+
const names = isData(field.code_names) ? field.code_names : {};
|
|
1365
|
+
Object.defineProperty(result, "codeNames", {
|
|
1366
|
+
enumerable: true,
|
|
1367
|
+
get: () =>
|
|
1368
|
+
Object.fromEntries(
|
|
1369
|
+
Object.entries(names)
|
|
1370
|
+
.filter((entry): entry is [string, string] => typeof entry[1] === "string")
|
|
1371
|
+
.map(([code, reference]) => [code, this.i18n.t(reference)]),
|
|
1372
|
+
),
|
|
1373
|
+
});
|
|
1374
|
+
}
|
|
1375
|
+
if (field.validations !== undefined) {
|
|
1376
|
+
const rules = this.rules(field.validations, `${path}.${name}.validations`);
|
|
1377
|
+
Object.defineProperty(result, "validations", {
|
|
1378
|
+
enumerable: true,
|
|
1379
|
+
get: () => this.translatedRules(rules),
|
|
1380
|
+
});
|
|
1381
|
+
}
|
|
1382
|
+
return [[name, Object.freeze(result)]];
|
|
1383
|
+
}),
|
|
1384
|
+
),
|
|
1385
|
+
);
|
|
1386
|
+
}
|
|
1387
|
+
|
|
1388
|
+
/**
|
|
1389
|
+
* Resolves the external package adapter declared for a configured form field.
|
|
1390
|
+
* @param source Name of the external component in application settings.
|
|
1391
|
+
* @param path Field configuration path used to report invalid adapter metadata.
|
|
1392
|
+
* @returns Prepared asset URLs and adapter, or undefined when the source is not external.
|
|
1393
|
+
*/
|
|
1394
|
+
private externalField(source: string, path: string): ExternalFieldDefinition | undefined {
|
|
1395
|
+
const { externals } = applicationSettings(this.metadata);
|
|
1396
|
+
if (!configurationMapping(externals) || !configurationMapping(externals.components)) {
|
|
1397
|
+
return;
|
|
1398
|
+
}
|
|
1399
|
+
// eslint-disable-next-line one-var -- The external component registry is checked before reading adapters.
|
|
1400
|
+
const { components } = externals;
|
|
1401
|
+
const definition = components && isData(components[source]) ? components[source] : undefined;
|
|
1402
|
+
if (!definition) return undefined;
|
|
1403
|
+
const adapter = definition.adapter;
|
|
1404
|
+
if (
|
|
1405
|
+
typeof definition.package !== "string" ||
|
|
1406
|
+
!definition.package ||
|
|
1407
|
+
typeof definition.script !== "string" ||
|
|
1408
|
+
!isData(adapter) ||
|
|
1409
|
+
typeof adapter.construct !== "string" ||
|
|
1410
|
+
!externalPath.test(adapter.construct) ||
|
|
1411
|
+
typeof adapter.value !== "string" ||
|
|
1412
|
+
!externalPath.test(adapter.value) ||
|
|
1413
|
+
typeof adapter.listen !== "string" ||
|
|
1414
|
+
!externalPath.test(adapter.listen)
|
|
1415
|
+
) {
|
|
1416
|
+
this.warn(`${path}.source: invalid external component adapter ${source}`);
|
|
1417
|
+
return undefined;
|
|
1418
|
+
}
|
|
1419
|
+
let valid = true;
|
|
1420
|
+
const events = (key: "immediate" | "change"): readonly string[] | undefined => {
|
|
1421
|
+
const value = adapter[key];
|
|
1422
|
+
if (value === undefined) return undefined;
|
|
1423
|
+
if (Array.isArray(value) && value.every((event) => typeof event === "string" && event.length > 0))
|
|
1424
|
+
return Object.freeze([...value]);
|
|
1425
|
+
this.warn(`${path}.source: adapter.${key} must be a list of event names`);
|
|
1426
|
+
valid = false;
|
|
1427
|
+
return undefined;
|
|
1428
|
+
};
|
|
1429
|
+
const method = (key: "readonly" | "disabled" | "destroy"): string | undefined => {
|
|
1430
|
+
const value = adapter[key];
|
|
1431
|
+
if (value === undefined) return undefined;
|
|
1432
|
+
if (typeof value === "string" && externalPath.test(value)) return value;
|
|
1433
|
+
this.warn(`${path}.source: adapter.${key} must be a property path`);
|
|
1434
|
+
valid = false;
|
|
1435
|
+
return undefined;
|
|
1436
|
+
};
|
|
1437
|
+
const options = adapter.options === undefined ? undefined : isData(adapter.options) ? adapter.options : undefined;
|
|
1438
|
+
if (adapter.options !== undefined && !options) {
|
|
1439
|
+
this.warn(`${path}.source: adapter.options must be a mapping`);
|
|
1440
|
+
valid = false;
|
|
1441
|
+
}
|
|
1442
|
+
const immediateEvents = events("immediate"),
|
|
1443
|
+
updateEvents = events("change");
|
|
1444
|
+
const readonlyMethod = method("readonly"),
|
|
1445
|
+
setDisabledMethod = method("disabled"),
|
|
1446
|
+
teardownMethod = method("destroy");
|
|
1447
|
+
const element =
|
|
1448
|
+
adapter.element === undefined || adapter.element === "div" || adapter.element === "textarea"
|
|
1449
|
+
? adapter.element
|
|
1450
|
+
: undefined;
|
|
1451
|
+
if (adapter.element !== undefined && element === undefined) {
|
|
1452
|
+
this.warn(`${path}.source: adapter.element must be div or textarea`);
|
|
1453
|
+
valid = false;
|
|
1454
|
+
}
|
|
1455
|
+
if (definition.style !== undefined && typeof definition.style !== "string") {
|
|
1456
|
+
this.warn(`${path}.source: style must be a package file path`);
|
|
1457
|
+
valid = false;
|
|
1458
|
+
}
|
|
1459
|
+
if (!valid) return undefined;
|
|
1460
|
+
const prepared: ExternalFieldAdapter = Object.freeze({
|
|
1461
|
+
...(element ? { element } : {}),
|
|
1462
|
+
construct: adapter.construct,
|
|
1463
|
+
listen: adapter.listen,
|
|
1464
|
+
value: adapter.value,
|
|
1465
|
+
...(immediateEvents ? { immediate: immediateEvents } : {}),
|
|
1466
|
+
...(updateEvents ? { change: updateEvents } : {}),
|
|
1467
|
+
...(readonlyMethod ? { readonly: readonlyMethod } : {}),
|
|
1468
|
+
...(setDisabledMethod ? { disabled: setDisabledMethod } : {}),
|
|
1469
|
+
...(teardownMethod ? { destroy: teardownMethod } : {}),
|
|
1470
|
+
...(options ? { options } : {}),
|
|
1471
|
+
});
|
|
1472
|
+
return Object.freeze({
|
|
1473
|
+
scriptPath: `/tiun/component-assets/${encodeURIComponent(source)}/script`,
|
|
1474
|
+
source,
|
|
1475
|
+
...(typeof definition.style === "string"
|
|
1476
|
+
? { stylePath: `/tiun/component-assets/${encodeURIComponent(source)}/style` }
|
|
1477
|
+
: {}),
|
|
1478
|
+
adapter: prepared,
|
|
1479
|
+
});
|
|
1480
|
+
}
|
|
1481
|
+
|
|
1482
|
+
/**
|
|
1483
|
+
* Compiles registered and table-backed field rules.
|
|
1484
|
+
* @param value Rule names mapped to references or descriptors.
|
|
1485
|
+
* @param path Field validation path for configuration warnings.
|
|
1486
|
+
* @returns Pairs of translation references and compiled rules.
|
|
1487
|
+
*/
|
|
1488
|
+
private rules(value: unknown, path: string): [string, TextValidation][] {
|
|
1489
|
+
if (!isData(value)) {
|
|
1490
|
+
this.warn(`${path}: expected mapping`);
|
|
1491
|
+
return [];
|
|
1492
|
+
}
|
|
1493
|
+
return Object.entries(value).flatMap(([name, reference]) => {
|
|
1494
|
+
if (isData(reference)) {
|
|
1495
|
+
const declaration =
|
|
1496
|
+
typeof reference.hoard === "string"
|
|
1497
|
+
? findConfigurationDefinition(this.metadata.types, reference.hoard)
|
|
1498
|
+
: undefined,
|
|
1499
|
+
rule = hoardValidation(
|
|
1500
|
+
declaration ? [declaration] : [],
|
|
1501
|
+
declaration ? { ...reference, hoard: declaration.name } : reference,
|
|
1502
|
+
(reason) => this.warn(`${path}.${name}: ${reason}`),
|
|
1503
|
+
);
|
|
1504
|
+
return rule ? [rule] : [];
|
|
1505
|
+
}
|
|
1506
|
+
const { methods: registered, validations } = this.registry,
|
|
1507
|
+
rule =
|
|
1508
|
+
registered && Object.hasOwn(registered, name)
|
|
1509
|
+
? registered[name]?.validate
|
|
1510
|
+
: validations && Object.hasOwn(validations, name)
|
|
1511
|
+
? validations[name]
|
|
1512
|
+
: (this.method(name)?.validate ?? blankCondition(name)),
|
|
1513
|
+
ruleIsSupported =
|
|
1514
|
+
typeof rule === "function" ||
|
|
1515
|
+
rule instanceof RegExp ||
|
|
1516
|
+
(Array.isArray(rule) && rule[0] === "!" && rule[1] instanceof RegExp);
|
|
1517
|
+
if (typeof reference !== "string" || !reference.startsWith(":") || !ruleIsSupported) {
|
|
1518
|
+
this.warn(`${path}.${name}: unknown validation or invalid translation reference`);
|
|
1519
|
+
return [];
|
|
1520
|
+
}
|
|
1521
|
+
return [[reference, rule as TextValidation]];
|
|
1522
|
+
});
|
|
1523
|
+
}
|
|
1524
|
+
|
|
1525
|
+
/** Сохраняет все проверки, даже когда их переводы совпадают. */
|
|
1526
|
+
private translatedRules(rules: readonly [string, TextValidation][]): Readonly<Record<string, TextValidation>> {
|
|
1527
|
+
const groups = new Map<string, TextValidation[]>();
|
|
1528
|
+
for (const [reference, rule] of rules) {
|
|
1529
|
+
const message = this.i18n.t(reference);
|
|
1530
|
+
groups.set(message, [...(groups.get(message) ?? []), rule]);
|
|
1531
|
+
}
|
|
1532
|
+
return Object.fromEntries(
|
|
1533
|
+
Array.from(groups, ([message, definitions]) => {
|
|
1534
|
+
const combined: TextValidation = (value, context, state) =>
|
|
1535
|
+
definitions.some((rule) => invalidText(rule, value, context, state));
|
|
1536
|
+
|
|
1537
|
+
return [message, definitions.length === 1 ? definitions[0]! : combined];
|
|
1538
|
+
}),
|
|
1539
|
+
);
|
|
1540
|
+
}
|
|
1541
|
+
|
|
1542
|
+
/**
|
|
1543
|
+
* Compiles column bindings and their configured text or nested views.
|
|
1544
|
+
* @param value Raw column declarations.
|
|
1545
|
+
* @param path Configuration path used for warnings.
|
|
1546
|
+
* @param name View name used for introductory steps.
|
|
1547
|
+
* @param requireTitle Whether each column needs a translation reference.
|
|
1548
|
+
* @param intro Collects the introductory steps from valid columns.
|
|
1549
|
+
* @returns The validated columns and their render functions.
|
|
1550
|
+
*/
|
|
1551
|
+
private viewColumns(
|
|
1552
|
+
value: unknown,
|
|
1553
|
+
path: string,
|
|
1554
|
+
name: string,
|
|
1555
|
+
requireTitle: boolean,
|
|
1556
|
+
intro: SchemaIntro[] = [],
|
|
1557
|
+
): readonly RecordColumn<T>[] {
|
|
1558
|
+
return this.namedEntries(value, path).flatMap(([key, column]) => {
|
|
1559
|
+
const binding = column.value,
|
|
1560
|
+
registeredTransform = typeof binding === "string" && this.valueMethod(binding),
|
|
1561
|
+
renderText = this.textRenderer(column.renderer),
|
|
1562
|
+
targetView =
|
|
1563
|
+
typeof column.view === "string" && referencePattern.test(column.view) ? column.view : undefined,
|
|
1564
|
+
usesConfiguredRendering = Boolean(targetView) || Object.hasOwn(column, "renderer");
|
|
1565
|
+
if (
|
|
1566
|
+
typeof binding !== "string" ||
|
|
1567
|
+
!namePattern.test(binding) ||
|
|
1568
|
+
(!usesConfiguredRendering && typeof registeredTransform !== "function") ||
|
|
1569
|
+
(requireTitle && (typeof column.title !== "string" || !column.title.startsWith(":")))
|
|
1570
|
+
) {
|
|
1571
|
+
this.warn(`${path}.${key}: unknown value transformer or invalid title`);
|
|
1572
|
+
return [];
|
|
1573
|
+
}
|
|
1574
|
+
if (usesConfiguredRendering && typeof targetView === "undefined" && !renderText) {
|
|
1575
|
+
this.warn(`${path}.${key}.renderer: unknown renderer; plain text used`);
|
|
1576
|
+
}
|
|
1577
|
+
const render = targetView
|
|
1578
|
+
? (record: T) =>
|
|
1579
|
+
createElement(Lorem<T>, { data: this.value(binding, record) as T, name: targetView, schema: this })
|
|
1580
|
+
: usesConfiguredRendering
|
|
1581
|
+
? this.renderedTextColumn(column, binding, renderText)
|
|
1582
|
+
: registeredTransform,
|
|
1583
|
+
result: Record<string, unknown> = { key, render },
|
|
1584
|
+
titleAsset = typeof column.icon === "string" ? stockee(column.icon) : undefined;
|
|
1585
|
+
if (titleAsset) {
|
|
1586
|
+
Object.defineProperty(result, "title", {
|
|
1587
|
+
enumerable: true,
|
|
1588
|
+
get: () =>
|
|
1589
|
+
createElement(Stockee, {
|
|
1590
|
+
asset: titleAsset,
|
|
1591
|
+
label: this.i18n.t(typeof column.title === "string" ? column.title : ""),
|
|
1592
|
+
}),
|
|
1593
|
+
});
|
|
1594
|
+
} else {
|
|
1595
|
+
this.label(result, "title", column.title, `${path}.${key}.title`);
|
|
1596
|
+
}
|
|
1597
|
+
for (const parameter of ["width", "head_to", "render_kind"]) {
|
|
1598
|
+
if (column[parameter] !== undefined) {
|
|
1599
|
+
result[parameter] = column[parameter];
|
|
1600
|
+
}
|
|
1601
|
+
}
|
|
1602
|
+
if (usesConfiguredRendering) {
|
|
1603
|
+
result.render_kind = "text";
|
|
1604
|
+
}
|
|
1605
|
+
if (typeof column.class === "string") {
|
|
1606
|
+
result.className = column.class;
|
|
1607
|
+
}
|
|
1608
|
+
if (column.intro !== undefined) {
|
|
1609
|
+
intro.push(...this.intro(column.intro, name, key));
|
|
1610
|
+
}
|
|
1611
|
+
return [Object.freeze(result) as unknown as RecordColumn<T>];
|
|
1612
|
+
});
|
|
1613
|
+
}
|
|
1614
|
+
|
|
1615
|
+
/**
|
|
1616
|
+
* Renders a cell using the same link rules as linked descriptions.
|
|
1617
|
+
* @param column The configured column properties.
|
|
1618
|
+
* @param binding The record field or registered value.
|
|
1619
|
+
* @param renderText Optional function rendering the cell text.
|
|
1620
|
+
* @returns A function rendering a cell from its record.
|
|
1621
|
+
*/
|
|
1622
|
+
private renderedTextColumn(
|
|
1623
|
+
column: Data,
|
|
1624
|
+
binding: string,
|
|
1625
|
+
renderText: SchemaTextRenderer | undefined,
|
|
1626
|
+
): (record: T) => ReactNode {
|
|
1627
|
+
return (record) => {
|
|
1628
|
+
const raw = this.value(binding, record);
|
|
1629
|
+
if (typeof raw !== "string" && typeof raw !== "number") {
|
|
1630
|
+
return isValidElement(raw) ? raw : null;
|
|
1631
|
+
}
|
|
1632
|
+
const source = String(raw);
|
|
1633
|
+
if (!source) {
|
|
1634
|
+
return null;
|
|
1635
|
+
}
|
|
1636
|
+
const boundLink =
|
|
1637
|
+
typeof column.href === "string" && namePattern.test(column.href)
|
|
1638
|
+
? this.value(column.href, record)
|
|
1639
|
+
: undefined,
|
|
1640
|
+
link = typeof boundLink === "string" && boundLink ? boundLink : undefined,
|
|
1641
|
+
runNavigation = typeof column.navigate === "string" ? this.command(column.navigate, record) : undefined;
|
|
1642
|
+
let renderedText: ReactNode = source;
|
|
1643
|
+
if (renderText) {
|
|
1644
|
+
const properties: { source: string; href?: string; inline?: boolean } = { source };
|
|
1645
|
+
if (typeof link === "string") {
|
|
1646
|
+
properties.href = link;
|
|
1647
|
+
}
|
|
1648
|
+
if (typeof column.inline === "boolean") {
|
|
1649
|
+
properties.inline = column.inline;
|
|
1650
|
+
}
|
|
1651
|
+
renderedText = renderText(properties);
|
|
1652
|
+
}
|
|
1653
|
+
if (!link) {
|
|
1654
|
+
return renderedText;
|
|
1655
|
+
}
|
|
1656
|
+
const destination = /^[a-z][a-z0-9+.-]*:/i.test(link) ? { url: link } : { path: link };
|
|
1657
|
+
return createElement(Lorem, {
|
|
1658
|
+
...destination,
|
|
1659
|
+
...(runNavigation ? { onNavigate: runNavigation } : {}),
|
|
1660
|
+
children: renderedText,
|
|
1661
|
+
});
|
|
1662
|
+
};
|
|
1663
|
+
}
|
|
1664
|
+
|
|
1665
|
+
private compiledContent(name: string, value: Data): SchemaViewMeta<T> | undefined {
|
|
1666
|
+
const element = value.of,
|
|
1667
|
+
hasChildItems =
|
|
1668
|
+
element === "spans" ||
|
|
1669
|
+
(element === "chip" && Object.hasOwn(value, "item")) ||
|
|
1670
|
+
(element === "records" && value.row === undefined),
|
|
1671
|
+
hasColumns = element === "span" || (element === "records" && !hasChildItems),
|
|
1672
|
+
{ uid } = value;
|
|
1673
|
+
if (
|
|
1674
|
+
hasChildItems &&
|
|
1675
|
+
(value.row !== undefined ||
|
|
1676
|
+
typeof value.item !== "string" ||
|
|
1677
|
+
!referencePattern.test(value.item) ||
|
|
1678
|
+
!(typeof uid === "string" || typeof uid === "number" || (Array.isArray(uid) && uid.length > 0)))
|
|
1679
|
+
) {
|
|
1680
|
+
this.warn(`components.${name}: ${String(element)} requires item and uid`);
|
|
1681
|
+
return undefined;
|
|
1682
|
+
}
|
|
1683
|
+
if (
|
|
1684
|
+
((element === "chip" && !hasChildItems) || element === "flex_text") &&
|
|
1685
|
+
(typeof value.text !== "string" || !namePattern.test(value.text) || value.row !== undefined)
|
|
1686
|
+
) {
|
|
1687
|
+
this.warn(`components.${name}: chip requires text binding and no row`);
|
|
1688
|
+
return undefined;
|
|
1689
|
+
}
|
|
1690
|
+
if (
|
|
1691
|
+
element === "name" &&
|
|
1692
|
+
(value.row !== undefined ||
|
|
1693
|
+
!Array.isArray(value.sources) ||
|
|
1694
|
+
!value.sources.length ||
|
|
1695
|
+
!value.sources.every((source) => typeof source === "string" && namePattern.test(source)))
|
|
1696
|
+
) {
|
|
1697
|
+
this.warn(`components.${name}: name requires source bindings and no row`);
|
|
1698
|
+
return undefined;
|
|
1699
|
+
}
|
|
1700
|
+
if (
|
|
1701
|
+
element === "calendar" &&
|
|
1702
|
+
(value.row !== undefined || !["round", "ortho"].includes(String(value.calendar_style)))
|
|
1703
|
+
) {
|
|
1704
|
+
this.warn(`components.${name}: calendar requires calendar_style and no row`);
|
|
1705
|
+
return undefined;
|
|
1706
|
+
}
|
|
1707
|
+
if (
|
|
1708
|
+
["player", "image"].includes(String(element)) &&
|
|
1709
|
+
(value.row !== undefined || typeof value.source !== "string" || !namePattern.test(value.source))
|
|
1710
|
+
) {
|
|
1711
|
+
this.warn(`components.${name}: player requires source binding and no row`);
|
|
1712
|
+
return undefined;
|
|
1713
|
+
}
|
|
1714
|
+
if (hasColumns && (!Array.isArray(value.row) || !value.row.length)) {
|
|
1715
|
+
this.warn(`components.${name}: nonempty row required`);
|
|
1716
|
+
return undefined;
|
|
1717
|
+
}
|
|
1718
|
+
const collectedIntro: SchemaIntro[] = [],
|
|
1719
|
+
columns = hasColumns
|
|
1720
|
+
? this.viewColumns(value.row, `components.${name}.row`, name, element !== "span", collectedIntro)
|
|
1721
|
+
: [];
|
|
1722
|
+
if (hasColumns && !columns.length) {
|
|
1723
|
+
this.warn(`components.${name}: no usable columns`);
|
|
1724
|
+
return undefined;
|
|
1725
|
+
}
|
|
1726
|
+
const result: Record<string, unknown> = {
|
|
1727
|
+
columns: Object.freeze(columns),
|
|
1728
|
+
intro: Object.freeze(collectedIntro.sort((a, b) => a.seq_no - b.seq_no)),
|
|
1729
|
+
name,
|
|
1730
|
+
};
|
|
1731
|
+
if (typeof value.prepare === "string" && methodNamePattern.test(value.prepare)) {
|
|
1732
|
+
result.prepare = value.prepare;
|
|
1733
|
+
}
|
|
1734
|
+
result.element = element;
|
|
1735
|
+
for (const key of ["text", "href", "color", "tooltip", "renderer", "insertions"]) {
|
|
1736
|
+
if (typeof value[key] === "string" && namePattern.test(value[key])) {
|
|
1737
|
+
result[key] = value[key];
|
|
1738
|
+
}
|
|
1739
|
+
}
|
|
1740
|
+
if (Array.isArray(value.sources)) {
|
|
1741
|
+
result.sources = Object.freeze(
|
|
1742
|
+
value.sources.filter((source) => typeof source === "string" && namePattern.test(source)),
|
|
1743
|
+
);
|
|
1744
|
+
}
|
|
1745
|
+
if (typeof value.insertion_renderer === "string" && namePattern.test(value.insertion_renderer)) {
|
|
1746
|
+
result.insertionRenderer = value.insertion_renderer;
|
|
1747
|
+
}
|
|
1748
|
+
if (element === "chip" && typeof value.label_view === "string" && referencePattern.test(value.label_view)) {
|
|
1749
|
+
result.labelView = value.label_view;
|
|
1750
|
+
}
|
|
1751
|
+
if (typeof value.style_from === "string" && namePattern.test(value.style_from)) {
|
|
1752
|
+
result.styleFrom = value.style_from;
|
|
1753
|
+
}
|
|
1754
|
+
if (value.calendar_style === "round" || value.calendar_style === "ortho") {
|
|
1755
|
+
result.calendarStyle = value.calendar_style;
|
|
1756
|
+
}
|
|
1757
|
+
if (typeof value.catch_from === "string") {
|
|
1758
|
+
result.catchFrom = value.catch_from;
|
|
1759
|
+
}
|
|
1760
|
+
if (typeof value.catch_period === "string") {
|
|
1761
|
+
result.catchPeriod = value.catch_period;
|
|
1762
|
+
}
|
|
1763
|
+
if (element === "calendar") {
|
|
1764
|
+
if (typeof value.day_appearance === "string") {
|
|
1765
|
+
result.dayAppearance = value.day_appearance;
|
|
1766
|
+
}
|
|
1767
|
+
if (typeof value.on_update === "string") {
|
|
1768
|
+
result.onUpdate = value.on_update;
|
|
1769
|
+
}
|
|
1770
|
+
let clock: ReturnType<typeof calendarClockSettings> | undefined;
|
|
1771
|
+
Object.defineProperty(result, "calendarClock", {
|
|
1772
|
+
get: () => (clock ??= calendarClockSettings(result.catchFrom, result.catchPeriod)),
|
|
1773
|
+
});
|
|
1774
|
+
}
|
|
1775
|
+
if (["player", "image"].includes(String(element))) {
|
|
1776
|
+
for (const [server, client] of [
|
|
1777
|
+
["source", "source"],
|
|
1778
|
+
["playing_from", "playingFrom"],
|
|
1779
|
+
["label_from", "labelFrom"],
|
|
1780
|
+
["on_play", "playCommand"],
|
|
1781
|
+
["on_pause", "pauseCommand"],
|
|
1782
|
+
] as const) {
|
|
1783
|
+
if (typeof value[server] === "string" && namePattern.test(value[server])) {
|
|
1784
|
+
result[client] = value[server];
|
|
1785
|
+
}
|
|
1786
|
+
}
|
|
1787
|
+
const labels: Record<string, string> = {};
|
|
1788
|
+
if (value.labels !== undefined && !isData(value.labels)) {
|
|
1789
|
+
this.warn(`components.${name}.labels: expected mapping`);
|
|
1790
|
+
}
|
|
1791
|
+
const configured = isData(value.labels) ? value.labels : {};
|
|
1792
|
+
for (const key of ["play", "pause", "loading", "error", "retry"]) {
|
|
1793
|
+
this.label(labels, key, configured[key], `components.${name}.labels.${key}`);
|
|
1794
|
+
}
|
|
1795
|
+
result.labels = Object.freeze(labels);
|
|
1796
|
+
}
|
|
1797
|
+
if (element === "slug_flow") {
|
|
1798
|
+
if (
|
|
1799
|
+
value.row !== undefined ||
|
|
1800
|
+
!["select", "display"].includes(String(value.flow_mode)) ||
|
|
1801
|
+
![value.source, value.key_from, value.label_from].every(
|
|
1802
|
+
(binding) => typeof binding === "string" && namePattern.test(binding),
|
|
1803
|
+
)
|
|
1804
|
+
) {
|
|
1805
|
+
this.warn(`components.${name}: slug_flow requires mode and source/key/label bindings`);
|
|
1806
|
+
return undefined;
|
|
1807
|
+
}
|
|
1808
|
+
result.flowMode = value.flow_mode;
|
|
1809
|
+
if (value.show_first !== undefined && value.show_first !== "selected" && value.show_first !== "skip") {
|
|
1810
|
+
this.warn(`components.${name}.show_first: expected selected or skip`);
|
|
1811
|
+
}
|
|
1812
|
+
result.showFirst = value.show_first === "selected" ? "selected" : "skip";
|
|
1813
|
+
for (const [server, client] of [
|
|
1814
|
+
["source", "source"],
|
|
1815
|
+
["key_from", "keyFrom"],
|
|
1816
|
+
["label_from", "labelFrom"],
|
|
1817
|
+
["fields_to_select", "fieldsToSelect"],
|
|
1818
|
+
["on_choose", "chooseCommand"],
|
|
1819
|
+
["on_open", "openCommand"],
|
|
1820
|
+
] as const) {
|
|
1821
|
+
if (typeof value[server] === "string" && namePattern.test(value[server])) {
|
|
1822
|
+
result[client] = value[server];
|
|
1823
|
+
}
|
|
1824
|
+
}
|
|
1825
|
+
}
|
|
1826
|
+
if (typeof value.props === "string") {
|
|
1827
|
+
selectedProps(value.props);
|
|
1828
|
+
result.props = value.props;
|
|
1829
|
+
}
|
|
1830
|
+
if (element === "image") {
|
|
1831
|
+
if (value.view_as === "plain" || value.view_as === "card") {
|
|
1832
|
+
result.viewAs = value.view_as;
|
|
1833
|
+
}
|
|
1834
|
+
for (const key of ["tooltip", "description", "width", "height"]) {
|
|
1835
|
+
if (typeof value[key] === "string" || typeof value[key] === "number") {
|
|
1836
|
+
result[key] = value[key];
|
|
1837
|
+
}
|
|
1838
|
+
}
|
|
1839
|
+
if (typeof value.on_click === "string") {
|
|
1840
|
+
result.onClick = value.on_click;
|
|
1841
|
+
}
|
|
1842
|
+
if (typeof value.min_height === "number" && Number.isFinite(value.min_height) && value.min_height >= 0) {
|
|
1843
|
+
result.minHeight = value.min_height;
|
|
1844
|
+
}
|
|
1845
|
+
}
|
|
1846
|
+
if (element === "records") {
|
|
1847
|
+
if (["grid", "stack", "list"].includes(String(value.layout))) {
|
|
1848
|
+
result.collectionLayout = value.layout;
|
|
1849
|
+
}
|
|
1850
|
+
if (typeof value.width === "number" && Number.isFinite(value.width) && value.width > 0) {
|
|
1851
|
+
result.width = value.width;
|
|
1852
|
+
}
|
|
1853
|
+
if (typeof value.gap === "number" && Number.isFinite(value.gap) && value.gap >= 0) {
|
|
1854
|
+
result.gap = value.gap;
|
|
1855
|
+
}
|
|
1856
|
+
if (typeof value.dom_id === "string" && /^[a-z][a-z0-9_-]*$/.test(value.dom_id)) {
|
|
1857
|
+
result.domId = value.dom_id;
|
|
1858
|
+
}
|
|
1859
|
+
}
|
|
1860
|
+
if (value.class !== undefined) {
|
|
1861
|
+
Object.assign(result, classProperties(value.class));
|
|
1862
|
+
}
|
|
1863
|
+
if (typeof value.class_from === "string" && namePattern.test(value.class_from)) {
|
|
1864
|
+
result.classFrom = value.class_from;
|
|
1865
|
+
}
|
|
1866
|
+
if (hasChildItems) {
|
|
1867
|
+
result.item = value.item;
|
|
1868
|
+
}
|
|
1869
|
+
if (uid !== undefined) {
|
|
1870
|
+
result.uid = Array.isArray(uid) ? Object.freeze([...uid]) : uid;
|
|
1871
|
+
}
|
|
1872
|
+
for (const [server, client] of Object.entries({ default_expand_when: "defaultExpandWhen" })) {
|
|
1873
|
+
if (typeof value[server] === "string") {
|
|
1874
|
+
result[client] = value[server];
|
|
1875
|
+
}
|
|
1876
|
+
}
|
|
1877
|
+
if (typeof value.accordion === "boolean") {
|
|
1878
|
+
result.accordion = value.accordion;
|
|
1879
|
+
}
|
|
1880
|
+
if (typeof value.row_class === "string") {
|
|
1881
|
+
result.rowClassName = value.row_class;
|
|
1882
|
+
}
|
|
1883
|
+
if (typeof value.hide_empty === "boolean") {
|
|
1884
|
+
result.hideIfEmpty = value.hide_empty;
|
|
1885
|
+
}
|
|
1886
|
+
if (typeof value.expand_when === "string" && namePattern.test(value.expand_when)) {
|
|
1887
|
+
result.expandWhen = value.expand_when;
|
|
1888
|
+
}
|
|
1889
|
+
if (value.body !== undefined) {
|
|
1890
|
+
result.body = Object.freeze(this.viewColumns(value.body, `components.${name}.body`, name, false));
|
|
1891
|
+
}
|
|
1892
|
+
if (isData(value.avatar) && typeof value.avatar.href === "string" && namePattern.test(value.avatar.href)) {
|
|
1893
|
+
const avatar: Record<string, string> = { href: value.avatar.href };
|
|
1894
|
+
for (const key of ["image", "label", "action", "fallback"]) {
|
|
1895
|
+
const entry = value.avatar[key];
|
|
1896
|
+
if (typeof entry === "string" && namePattern.test(entry)) {
|
|
1897
|
+
avatar[key] = entry;
|
|
1898
|
+
}
|
|
1899
|
+
}
|
|
1900
|
+
result.avatar = Object.freeze(avatar);
|
|
1901
|
+
}
|
|
1902
|
+
if (isData(value.pagination)) {
|
|
1903
|
+
const pagination: {
|
|
1904
|
+
kind?: "hidden" | "button";
|
|
1905
|
+
autoloadUpto?: number;
|
|
1906
|
+
pageSize?: number;
|
|
1907
|
+
buttonStyle?: "text" | "circle";
|
|
1908
|
+
rangeUnit?: "pages" | "records";
|
|
1909
|
+
} = {};
|
|
1910
|
+
if (value.pagination.kind === "hidden" || value.pagination.kind === "button") {
|
|
1911
|
+
pagination.kind = value.pagination.kind;
|
|
1912
|
+
}
|
|
1913
|
+
if (Number.isSafeInteger(value.pagination.autoload_upto) && Number(value.pagination.autoload_upto) > 0) {
|
|
1914
|
+
pagination.autoloadUpto = Number(value.pagination.autoload_upto);
|
|
1915
|
+
}
|
|
1916
|
+
if (
|
|
1917
|
+
Number.isInteger(value.pagination.per) &&
|
|
1918
|
+
Number(value.pagination.per) > 0 &&
|
|
1919
|
+
Number(value.pagination.per) <= 1000
|
|
1920
|
+
) {
|
|
1921
|
+
pagination.pageSize = Number(value.pagination.per);
|
|
1922
|
+
}
|
|
1923
|
+
if (value.pagination.button_style === "text" || value.pagination.button_style === "circle") {
|
|
1924
|
+
pagination.buttonStyle = value.pagination.button_style;
|
|
1925
|
+
}
|
|
1926
|
+
if (value.pagination.range_unit === "pages" || value.pagination.range_unit === "records") {
|
|
1927
|
+
pagination.rangeUnit = value.pagination.range_unit;
|
|
1928
|
+
}
|
|
1929
|
+
result.pagination = Object.freeze(pagination);
|
|
1930
|
+
}
|
|
1931
|
+
if (typeof value.native === "boolean") {
|
|
1932
|
+
result.native = value.native;
|
|
1933
|
+
}
|
|
1934
|
+
this.label(result, "title", value.title, `components.${name}.title`);
|
|
1935
|
+
this.label(result, "empty", value.empty, `components.${name}.empty`);
|
|
1936
|
+
if (typeof value.form === "string") {
|
|
1937
|
+
const fields = this.formFields(value.form);
|
|
1938
|
+
if (fields) {
|
|
1939
|
+
result.form = fields;
|
|
1940
|
+
} else {
|
|
1941
|
+
this.warn(`components.${name}.form: unknown form ${value.form}`);
|
|
1942
|
+
}
|
|
1943
|
+
}
|
|
1944
|
+
return Object.freeze(result) as unknown as SchemaViewMeta<T>;
|
|
1945
|
+
}
|
|
1946
|
+
|
|
1947
|
+
/**
|
|
1948
|
+
* Finds the value transformation registered under a configuration name.
|
|
1949
|
+
* @param name Name used by a field or column.
|
|
1950
|
+
* @returns The transformation if it is registered.
|
|
1951
|
+
*/
|
|
1952
|
+
private valueMethod(name: string): ((record: T) => unknown) | undefined {
|
|
1953
|
+
if (this.registry.values && Object.hasOwn(this.registry.values, name)) {
|
|
1954
|
+
return this.registry.values[name];
|
|
1955
|
+
}
|
|
1956
|
+
return this.method(name)?.value;
|
|
1957
|
+
}
|
|
1958
|
+
|
|
1959
|
+
/**
|
|
1960
|
+
* Resolves a registered value transformer or an own data path.
|
|
1961
|
+
* @param name Method name or dot-separated record path.
|
|
1962
|
+
* @param record Record supplied to the component.
|
|
1963
|
+
* @returns Projected value or the value at the record path.
|
|
1964
|
+
*/
|
|
1965
|
+
value(name: string, record: T): unknown {
|
|
1966
|
+
const method = this.valueMethod(name);
|
|
1967
|
+
if (method) {
|
|
1968
|
+
return method(record);
|
|
1969
|
+
}
|
|
1970
|
+
return name
|
|
1971
|
+
.split(".")
|
|
1972
|
+
.reduce<unknown>(
|
|
1973
|
+
(value, key) =>
|
|
1974
|
+
value && typeof value === "object" && Object.hasOwn(value, key)
|
|
1975
|
+
? (value as Record<string, unknown>)[key]
|
|
1976
|
+
: undefined,
|
|
1977
|
+
record,
|
|
1978
|
+
);
|
|
1979
|
+
}
|
|
1980
|
+
|
|
1981
|
+
/** Only explicitly supplied action handlers may handle an avatar click. */
|
|
1982
|
+
action(name: string, record: T, event: MouseEvent<HTMLAnchorElement>): void {
|
|
1983
|
+
const handler =
|
|
1984
|
+
this.registry.actions && Object.hasOwn(this.registry.actions, name) ? this.registry.actions[name] : undefined;
|
|
1985
|
+
handler?.(record, event);
|
|
1986
|
+
}
|
|
1987
|
+
|
|
1988
|
+
private intro(value: unknown, view: string, field: string): SchemaIntro[] {
|
|
1989
|
+
const path = `components.${view}.row.${field}.intro`;
|
|
1990
|
+
if (!Array.isArray(value)) {
|
|
1991
|
+
this.warn(`${path}: expected list`);
|
|
1992
|
+
return [];
|
|
1993
|
+
}
|
|
1994
|
+
const numbers = new Set<number>();
|
|
1995
|
+
|
|
1996
|
+
return value.flatMap((entry, index) => {
|
|
1997
|
+
const source = `${path}[${index}]`;
|
|
1998
|
+
if (
|
|
1999
|
+
!isData(entry) ||
|
|
2000
|
+
typeof entry.text !== "string" ||
|
|
2001
|
+
!entry.text.startsWith(":") ||
|
|
2002
|
+
schemaTimestamp(entry.introduced_at) === undefined
|
|
2003
|
+
) {
|
|
2004
|
+
this.warn(`${source}: intro requires translated text and introduced_at`);
|
|
2005
|
+
return [];
|
|
2006
|
+
}
|
|
2007
|
+
const seq_no = entry.seq_no === undefined ? index : entry.seq_no;
|
|
2008
|
+
if (typeof seq_no !== "number" || !Number.isInteger(seq_no) || seq_no < 0 || numbers.has(seq_no)) {
|
|
2009
|
+
this.warn(`${source}: invalid or duplicate seq_no`);
|
|
2010
|
+
return [];
|
|
2011
|
+
}
|
|
2012
|
+
numbers.add(seq_no);
|
|
2013
|
+
const rule: Record<string, unknown> = {
|
|
2014
|
+
field,
|
|
2015
|
+
id: `${view}:${field}:${seq_no}`,
|
|
2016
|
+
introduced_at: entry.introduced_at,
|
|
2017
|
+
seq_no,
|
|
2018
|
+
};
|
|
2019
|
+
this.label(rule, "text", entry.text, `${source}.text`);
|
|
2020
|
+
if (entry.position !== undefined) {
|
|
2021
|
+
if (["auto", "bottom", "right", "left", "top"].includes(String(entry.position))) {
|
|
2022
|
+
rule.position = entry.position;
|
|
2023
|
+
} else {
|
|
2024
|
+
this.warn(`${source}.position: invalid position`);
|
|
2025
|
+
}
|
|
2026
|
+
}
|
|
2027
|
+
return [Object.freeze(rule) as unknown as SchemaIntro];
|
|
2028
|
+
});
|
|
2029
|
+
}
|
|
2030
|
+
}
|
|
2031
|
+
|
|
2032
|
+
function isData(value: unknown): value is Data {
|
|
2033
|
+
return Boolean(value) && typeof value === "object" && !Array.isArray(value);
|
|
2034
|
+
}
|