tiun 0.0.2 → 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,46 @@
|
|
|
1
|
+
import * as React from "react";
|
|
2
|
+
import type { ButtonBehaviour } from "../components/form/Pressee.js";
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Adds one button behaviour to a compatible control or configured component.
|
|
6
|
+
* @param behaviour The operation that will run on a click.
|
|
7
|
+
* @returns A decorator that appends the operation in composition order.
|
|
8
|
+
*/
|
|
9
|
+
function withButtonBehaviour(behaviour: ButtonBehaviour) {
|
|
10
|
+
/**
|
|
11
|
+
* Supplies a configured operation to the target.
|
|
12
|
+
* @param target React component accepting buttonBehaviours.
|
|
13
|
+
* @returns The component with its additional operation.
|
|
14
|
+
*/
|
|
15
|
+
return function decorate<Props extends object>(target: React.ComponentType<Props>): React.ComponentType<Props> {
|
|
16
|
+
/**
|
|
17
|
+
* Preserves the supplied operations and appends this decorator's operation.
|
|
18
|
+
* @param props Original component props and any preceding operations.
|
|
19
|
+
* @returns The target element with the expanded list.
|
|
20
|
+
*/
|
|
21
|
+
return function buttonBehaviour(props: Props): React.ReactElement {
|
|
22
|
+
const { buttonBehaviours = [] } = props as { readonly buttonBehaviours?: readonly ButtonBehaviour[] };
|
|
23
|
+
return React.createElement(target, { ...props, buttonBehaviours: [...buttonBehaviours, behaviour] });
|
|
24
|
+
};
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export const withAct = withButtonBehaviour({
|
|
29
|
+
name: "act",
|
|
30
|
+
/** @param input Configured click callback. @returns Its result or promise. */
|
|
31
|
+
run: ({ act }) => act(),
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
export const withReset = withButtonBehaviour({
|
|
35
|
+
name: "reset",
|
|
36
|
+
/** @param input Form and optional replacement values. @returns Completion of the replacement. */
|
|
37
|
+
run: ({ form, resetValues }) => form?.reset?.(resetValues),
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
export const withSubmit = withButtonBehaviour({
|
|
41
|
+
name: "submit",
|
|
42
|
+
/** @param input Form with its submit handler. @returns Completion of the form submission. */
|
|
43
|
+
run: ({ form }) => form?.submit?.() ?? false,
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
export const buttonDecorators = Object.freeze({ act: withAct, reset: withReset, submit: withSubmit });
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
import type { ComponentType, MouseEventHandler } from "react";
|
|
2
|
+
import type { RouterValue } from "./withRouter.js";
|
|
3
|
+
import type { Schema } from "../schema/Schema.js";
|
|
4
|
+
import type { ComponentDefinition } from "../config/components.js";
|
|
5
|
+
import { buttonDecorators } from "./buttonBehaviours.js";
|
|
6
|
+
import { withChildren } from "./withChildren.js";
|
|
7
|
+
import { hasCloseAction, withClose } from "./withClose.js";
|
|
8
|
+
import { modalColumn, withColumn } from "./withColumn.js";
|
|
9
|
+
|
|
10
|
+
const behaviourProperties = ["behaviours", "behaviour", "behavior", "behaviors"] as const;
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Resolves decorators enabled by recognized configuration properties.
|
|
14
|
+
* @param node Effective component definition with its defaults.
|
|
15
|
+
* @param schema Schema holding localized configuration errors.
|
|
16
|
+
* @returns Built-in decorators in the order specified in the definition.
|
|
17
|
+
*/
|
|
18
|
+
function implicitDecorators<T>(node: ComponentDefinition | undefined, schema: Schema<T>): ComponentDecorator[] {
|
|
19
|
+
if (!node) return [];
|
|
20
|
+
|
|
21
|
+
const decorators: ComponentDecorator[] = Object.hasOwn(node, "children") ? [withChildren] : [],
|
|
22
|
+
property = behaviourProperties.find((key) => Object.hasOwn(node, key));
|
|
23
|
+
if (node.of === "modal" && node.landing === "popup" && (modalColumn(node) || typeof node.mountTo === "string")) {
|
|
24
|
+
decorators.push(withColumn);
|
|
25
|
+
}
|
|
26
|
+
if (node.of === "modal" && hasCloseAction(node.actions)) {
|
|
27
|
+
decorators.push(withClose);
|
|
28
|
+
}
|
|
29
|
+
if (!property) return decorators;
|
|
30
|
+
|
|
31
|
+
const value = node[property],
|
|
32
|
+
entries = Array.isArray(value) ? value : [value];
|
|
33
|
+
for (const entry of entries) {
|
|
34
|
+
if (typeof entry !== "string" || !Object.hasOwn(buttonDecorators, entry)) {
|
|
35
|
+
throw new TypeError(schema.i18n.t("tiun.errors.component.behaviours", { name: node.name }));
|
|
36
|
+
}
|
|
37
|
+
decorators.push(buttonDecorators[entry as keyof typeof buttonDecorators]);
|
|
38
|
+
}
|
|
39
|
+
return decorators;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
export interface DecoratedProps {
|
|
43
|
+
readonly schema: Readonly<Pick<Schema<unknown>, "i18n" | "metadata">>;
|
|
44
|
+
readonly data?: unknown;
|
|
45
|
+
readonly onClick?: MouseEventHandler<HTMLDivElement> | undefined;
|
|
46
|
+
readonly router?: RouterValue;
|
|
47
|
+
readonly configuredDefinition?: ComponentDefinition | undefined;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
export type ComponentDecorator = <Props extends DecoratedProps>(
|
|
51
|
+
// eslint-disable-next-line @typescript-eslint/prefer-readonly-parameter-types -- React classes may own mutable state.
|
|
52
|
+
target: ComponentType<Props>,
|
|
53
|
+
) => ComponentType<Props>;
|
|
54
|
+
|
|
55
|
+
const compositions = new WeakMap<object, WeakMap<ComponentDecorator, object>>();
|
|
56
|
+
|
|
57
|
+
/**
|
|
58
|
+
* Applies one decorator and retains the result by the identities of both functions.
|
|
59
|
+
* @param component React ComponentType with the original props.
|
|
60
|
+
* @param decorate ComponentDecorator that preserves the props type.
|
|
61
|
+
* @returns ComponentType with the additional behavior.
|
|
62
|
+
*/
|
|
63
|
+
// eslint-disable-next-line func-style -- Keep the typed signature with its documentation.
|
|
64
|
+
function compose<Props extends DecoratedProps>(
|
|
65
|
+
// eslint-disable-next-line @typescript-eslint/prefer-readonly-parameter-types -- React classes can own mutable state.
|
|
66
|
+
component: ComponentType<Props>,
|
|
67
|
+
decorate: ComponentDecorator,
|
|
68
|
+
): ComponentType<Props> {
|
|
69
|
+
let entries = compositions.get(component);
|
|
70
|
+
if (!entries) {
|
|
71
|
+
entries = new WeakMap<ComponentDecorator, object>();
|
|
72
|
+
compositions.set(component, entries);
|
|
73
|
+
}
|
|
74
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-type-assertion -- This map is scoped to the input component and the decorator preserves its props.
|
|
75
|
+
const cached = entries.get(decorate) as ComponentType<Props> | undefined;
|
|
76
|
+
if (cached) {
|
|
77
|
+
return cached;
|
|
78
|
+
}
|
|
79
|
+
// eslint-disable-next-line one-var -- Compose only after checking the identity cache.
|
|
80
|
+
const result = decorate(component);
|
|
81
|
+
entries.set(decorate, result);
|
|
82
|
+
return result;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
/**
|
|
86
|
+
* Composes decorators in configuration order.
|
|
87
|
+
* @param target ComponentType of the original component.
|
|
88
|
+
* @param schema Schema holding the trusted decorator registry.
|
|
89
|
+
* @param declaration Unknown value of the component's with property.
|
|
90
|
+
* @param node Effective definition supplying implicit decorators, when available.
|
|
91
|
+
* @returns The original or decorated ComponentType with the same props.
|
|
92
|
+
*/
|
|
93
|
+
// eslint-disable-next-line func-style -- Keep the typed signature with its documentation.
|
|
94
|
+
export function decorateComponent<T, Props extends DecoratedProps>(
|
|
95
|
+
// eslint-disable-next-line @typescript-eslint/prefer-readonly-parameter-types -- React classes can own mutable state.
|
|
96
|
+
target: ComponentType<Props>,
|
|
97
|
+
// eslint-disable-next-line @typescript-eslint/prefer-readonly-parameter-types -- Resolve decorators on the existing schema.
|
|
98
|
+
schema: Schema<T>,
|
|
99
|
+
declaration: unknown,
|
|
100
|
+
node?: ComponentDefinition,
|
|
101
|
+
): ComponentType<Props> {
|
|
102
|
+
const decorators = [...new Set([...implicitDecorators(node, schema), ...schema.componentDecorators(declaration)])];
|
|
103
|
+
return decorators.reduceRight(compose<Props>, target);
|
|
104
|
+
}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import type { FieldProps, FormData, FormValue, TextValidation } from "../components/form/types.js";
|
|
2
|
+
|
|
3
|
+
/** Проверяет текст правилом исходного поля. Аргументы: rule, value, context; результат: true при ошибке. Пример: invalidText(/\\d/, "123", {}) → true. */
|
|
4
|
+
export function invalidText(
|
|
5
|
+
rule: TextValidation,
|
|
6
|
+
value: FormValue,
|
|
7
|
+
context: NonNullable<FieldProps["validation_context"]>,
|
|
8
|
+
state?: Readonly<FormData>,
|
|
9
|
+
): boolean {
|
|
10
|
+
if (typeof rule === "function") {
|
|
11
|
+
return Boolean(rule(value, context, state));
|
|
12
|
+
}
|
|
13
|
+
const fieldValue = value ?? "",
|
|
14
|
+
isMatch = (entry: FormValue, pattern: RegExp): boolean =>
|
|
15
|
+
(typeof entry === "string" || typeof entry === "number") &&
|
|
16
|
+
new RegExp(pattern.source, pattern.flags).test(String(entry));
|
|
17
|
+
|
|
18
|
+
if (Array.isArray(rule)) {
|
|
19
|
+
return !isMatch(fieldValue, rule[1]);
|
|
20
|
+
}
|
|
21
|
+
return typeof fieldValue === "object"
|
|
22
|
+
? Object.values(fieldValue).some((entry) => isMatch(entry, rule as RegExp))
|
|
23
|
+
: isMatch(fieldValue, rule as RegExp);
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
/** Возвращает первую ошибку поля с актуальным контекстом. Аргументы: props — свойства поля, data — данные формы, value — проверяемое значение (по умолчанию props.value); результат: текст ошибки либо пустая строка. Пример: fieldError(props, data, "обычна"). */
|
|
27
|
+
export function fieldError(
|
|
28
|
+
props: FieldProps,
|
|
29
|
+
data: FormData,
|
|
30
|
+
value: FormValue = props.value,
|
|
31
|
+
state?: Readonly<FormData>,
|
|
32
|
+
): string {
|
|
33
|
+
if (props.disabled) {
|
|
34
|
+
return "";
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
const containingValue = props.name
|
|
38
|
+
.split(".")
|
|
39
|
+
.slice(0, -1)
|
|
40
|
+
.reduce<FormValue>(
|
|
41
|
+
(entry, key) => (entry && typeof entry === "object" && !Array.isArray(entry) ? entry[key] : undefined),
|
|
42
|
+
data,
|
|
43
|
+
),
|
|
44
|
+
context =
|
|
45
|
+
props.validation_context ??
|
|
46
|
+
(containingValue && typeof containingValue === "object" && !Array.isArray(containingValue)
|
|
47
|
+
? containingValue
|
|
48
|
+
: {});
|
|
49
|
+
return (
|
|
50
|
+
Object.entries(props.validations ?? {}).find(([, rule]) => invalidText(rule, value, context, state))?.[0] ?? ""
|
|
51
|
+
);
|
|
52
|
+
}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import * as React from "react";
|
|
2
|
+
import { type AppearanceOptions, useAppearance, useAppearanceStyles } from "../services/useAppearance.js";
|
|
3
|
+
import type { ComponentType, ElementType, ReactElement, ReactNode } from "react";
|
|
4
|
+
import { ThemeContext } from "../theme/context.js";
|
|
5
|
+
import { Toast } from "../components/Toast.js";
|
|
6
|
+
|
|
7
|
+
interface AppearanceHostProps {
|
|
8
|
+
readonly children?: ReactNode;
|
|
9
|
+
readonly className?: string;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
type AppearanceProps = AppearanceOptions & AppearanceHostProps;
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* Connects an existing shell to appearance settings and its descendants to the shared context.
|
|
16
|
+
* @param target Component that renders a class and children.
|
|
17
|
+
* @returns The decorated shell with appearance handling.
|
|
18
|
+
*/
|
|
19
|
+
// eslint-disable-next-line @typescript-eslint/prefer-readonly-parameter-types -- React components can contain mutable instance state.
|
|
20
|
+
export const withAppearance = (target: ElementType<AppearanceHostProps>): ComponentType<AppearanceProps> =>
|
|
21
|
+
/**
|
|
22
|
+
* Supplies appearance to the shell's children and displays loading or save failures.
|
|
23
|
+
* @param props Appearance configuration and the original shell content.
|
|
24
|
+
* @returns The shell inside the appearance context.
|
|
25
|
+
*/
|
|
26
|
+
// eslint-disable-next-line @typescript-eslint/prefer-readonly-parameter-types -- The props carry a mutable HTTP client.
|
|
27
|
+
function appearanceHost(props: AppearanceProps): ReactElement {
|
|
28
|
+
const { context, retry } = useAppearance(props),
|
|
29
|
+
className = ["tiun-site-shell", context.configuration.class, props.className].filter(Boolean).join(" "),
|
|
30
|
+
daylight = useAppearanceStyles(context, props.meta ?? {}, props.ready !== false);
|
|
31
|
+
// eslint-disable-next-line one-var -- Keep the JSX for the shell separate from its state.
|
|
32
|
+
const children = (
|
|
33
|
+
<>
|
|
34
|
+
{props.children}
|
|
35
|
+
{context.error && <Toast tone="error" message={context.error} onRetry={retry} />}
|
|
36
|
+
{daylight.error && <Toast tone="error" message={daylight.error} onRetry={daylight.retry} />}
|
|
37
|
+
</>
|
|
38
|
+
);
|
|
39
|
+
|
|
40
|
+
return (
|
|
41
|
+
<ThemeContext.Provider value={context}>
|
|
42
|
+
{React.createElement(target, { className }, children)}
|
|
43
|
+
</ThemeContext.Provider>
|
|
44
|
+
);
|
|
45
|
+
};
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import * as React from "react";
|
|
2
|
+
import type { ComponentType, ReactElement } from "react";
|
|
3
|
+
import { FieldCaption } from "../components/form/FieldCaption.js";
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Supplies a field's caption slot with its configured title.
|
|
7
|
+
* @param Field Field component that accepts a caption slot and a title.
|
|
8
|
+
* @returns The field with the shared caption rendered in its slot.
|
|
9
|
+
*/
|
|
10
|
+
export const withCaption = <Props extends { readonly title?: string; readonly caption?: ReactElement }>(
|
|
11
|
+
// eslint-disable-next-line @typescript-eslint/prefer-readonly-parameter-types -- React components may hold mutable state.
|
|
12
|
+
field: ComponentType<Props>,
|
|
13
|
+
): ComponentType<Props> => {
|
|
14
|
+
/**
|
|
15
|
+
* Renders the title with the same formatting as other field captions.
|
|
16
|
+
* @param props Original field properties, including the localized title.
|
|
17
|
+
* @returns The field with its caption.
|
|
18
|
+
*/
|
|
19
|
+
return (props: Props): ReactElement =>
|
|
20
|
+
React.createElement(field, { ...props, caption: <FieldCaption as="span">{props.title}</FieldCaption> });
|
|
21
|
+
};
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import * as React from "react";
|
|
2
|
+
import type { ComponentDefinition } from "../config/components.js";
|
|
3
|
+
|
|
4
|
+
export type ChildrenRenderer = (
|
|
5
|
+
nodes: readonly ComponentDefinition[],
|
|
6
|
+
render: (node: ComponentDefinition) => React.ReactNode,
|
|
7
|
+
) => React.ReactNode;
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Mounts the configured children in declaration order.
|
|
11
|
+
* @param nodes The visible child definitions.
|
|
12
|
+
* @param render Renders one child with its inherited data and props.
|
|
13
|
+
* @returns The list of rendered children.
|
|
14
|
+
*/
|
|
15
|
+
const renderChildren: ChildrenRenderer = (nodes, render) => nodes.map(render);
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* Enables rendering configured children.
|
|
19
|
+
* @param target Component with a renderConfiguredChildren slot.
|
|
20
|
+
* @returns The component with the configured children renderer.
|
|
21
|
+
*/
|
|
22
|
+
export function withChildren<Props extends object>(target: React.ComponentType<Props>): React.ComponentType<Props> {
|
|
23
|
+
/**
|
|
24
|
+
* Passes the children renderer to the component.
|
|
25
|
+
* @param props Original component props.
|
|
26
|
+
* @returns The decorated component.
|
|
27
|
+
*/
|
|
28
|
+
return function configuredChildren(props: Props): React.ReactElement {
|
|
29
|
+
return React.createElement(target, { ...props, renderConfiguredChildren: renderChildren });
|
|
30
|
+
};
|
|
31
|
+
}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
@mixin styles {
|
|
2
|
+
.tiun-modal:has(> .tiun-modal-close) {
|
|
3
|
+
--tiun-modal-close-inset: 0.5rem;
|
|
4
|
+
--tiun-modal-close-size: 2rem;
|
|
5
|
+
padding-block-start: max(
|
|
6
|
+
var(--tiun-modal-padding, 1.5rem),
|
|
7
|
+
calc(var(--tiun-modal-close-size) + 2 * var(--tiun-modal-close-inset))
|
|
8
|
+
);
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
.tiun-modal-close {
|
|
12
|
+
position: absolute;
|
|
13
|
+
z-index: 1;
|
|
14
|
+
inset-block-start: var(--tiun-modal-close-inset, 0.5rem);
|
|
15
|
+
inset-inline-end: var(--tiun-modal-close-inset, 0.5rem);
|
|
16
|
+
display: grid;
|
|
17
|
+
place-items: center;
|
|
18
|
+
box-sizing: border-box;
|
|
19
|
+
inline-size: var(--tiun-modal-close-size, 2rem);
|
|
20
|
+
block-size: var(--tiun-modal-close-size, 2rem);
|
|
21
|
+
padding: 0;
|
|
22
|
+
border: 0;
|
|
23
|
+
border-radius: 50%;
|
|
24
|
+
background: var(--tiun-accent, #285b57);
|
|
25
|
+
color: var(--tiun-action-color, #fff);
|
|
26
|
+
box-shadow: 0 0.12rem 0.25rem #0003;
|
|
27
|
+
font: inherit;
|
|
28
|
+
font-size: 1.25rem;
|
|
29
|
+
line-height: 1;
|
|
30
|
+
cursor: pointer;
|
|
31
|
+
|
|
32
|
+
&:focus-visible {
|
|
33
|
+
outline: 0.12rem solid var(--tiun-accent, #285b57);
|
|
34
|
+
outline-offset: 0.12rem;
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { type ComponentType, type ReactElement, createElement } from "react";
|
|
2
|
+
import { Stock } from "../services/Stock.js";
|
|
3
|
+
import { useI18n } from "../concern/i18n.js";
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Checks whether the configured modal actions enable its close button.
|
|
7
|
+
* @param actions The modal's ordered actions, or an omitted property.
|
|
8
|
+
* @returns True when the list declares close.
|
|
9
|
+
*/
|
|
10
|
+
export const hasCloseAction = (actions: unknown): boolean => Array.isArray(actions) && actions.includes("close");
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Renders a labelled close button that requests dismissal from its modal.
|
|
14
|
+
* @param props The modal's dismissal callback.
|
|
15
|
+
* @returns The close button.
|
|
16
|
+
*/
|
|
17
|
+
const closeButton = ({ dismiss }: { readonly dismiss: () => void }): ReactElement => {
|
|
18
|
+
const { t: translate } = useI18n();
|
|
19
|
+
return createElement("button", {
|
|
20
|
+
// eslint-disable-next-line @typescript-eslint/naming-convention -- Native ARIA attribute.
|
|
21
|
+
"aria-label": translate("tiun.components.modal.close_yes"),
|
|
22
|
+
children: Stock.close.glyph,
|
|
23
|
+
className: "tiun-modal-close",
|
|
24
|
+
onClick: dismiss,
|
|
25
|
+
type: "button",
|
|
26
|
+
});
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* Enables a close control in the wrapped modal.
|
|
31
|
+
* @param target Component that renders the modal.
|
|
32
|
+
* @returns The component with the close control enabled.
|
|
33
|
+
*/
|
|
34
|
+
// eslint-disable-next-line func-style, @typescript-eslint/prefer-readonly-parameter-types -- React components may own mutable state.
|
|
35
|
+
export function withClose<Props extends object>(target: ComponentType<Props>): ComponentType<Props> {
|
|
36
|
+
/**
|
|
37
|
+
* Makes the close control available to the wrapped modal.
|
|
38
|
+
* @param props Properties passed through to the wrapped component.
|
|
39
|
+
* @returns The wrapped component with the close control enabled.
|
|
40
|
+
*/
|
|
41
|
+
return function closeControl(props: Props): ReactElement {
|
|
42
|
+
return createElement(target, { ...props, closeControl: closeButton });
|
|
43
|
+
};
|
|
44
|
+
}
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
import * as React from "react";
|
|
2
|
+
import type { ComponentType } from "react";
|
|
3
|
+
import { createContext, useContext, useLayoutEffect, useState } from "react";
|
|
4
|
+
import type { FormData } from "../components/form/types.js";
|
|
5
|
+
import type { ComponentDefinition } from "../config/components.js";
|
|
6
|
+
import type { DecoratedProps } from "./configuration.js";
|
|
7
|
+
import { RouterContext } from "./withRouter.js";
|
|
8
|
+
|
|
9
|
+
export const ColumnDraftContext = createContext<{
|
|
10
|
+
readonly data: FormData | undefined;
|
|
11
|
+
readonly remember: (data: FormData) => void;
|
|
12
|
+
} | null>(null);
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* Finds the direct column whose rows can contain routed children.
|
|
16
|
+
* @param node The configured modal definition.
|
|
17
|
+
* @returns Its first column, or undefined if the modal has no column.
|
|
18
|
+
*/
|
|
19
|
+
export function modalColumn(node: ComponentDefinition): ComponentDefinition | undefined {
|
|
20
|
+
return node.children?.find((child) => child.of === "column");
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* Checks whether a child declares a local fragment address.
|
|
25
|
+
* @param node A child within a row.
|
|
26
|
+
* @returns Whether the child is selected by a fragment.
|
|
27
|
+
*/
|
|
28
|
+
function hasFragmentMount(node: ComponentDefinition): boolean {
|
|
29
|
+
return typeof node.mountTo === "string" && /^#[^#]+$/.test(node.mountTo);
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* Selects the active routed child wherever the column places it.
|
|
34
|
+
* @param column The modal's column.
|
|
35
|
+
* @param active The child whose address matches the browser location.
|
|
36
|
+
* @returns The column with its common children and the selected child in their original positions.
|
|
37
|
+
*/
|
|
38
|
+
function shownColumn(column: ComponentDefinition, active: ComponentDefinition): ComponentDefinition {
|
|
39
|
+
return {
|
|
40
|
+
...column,
|
|
41
|
+
children:
|
|
42
|
+
column.children?.map((row) =>
|
|
43
|
+
row.of === "row" && row.children
|
|
44
|
+
? {
|
|
45
|
+
...row,
|
|
46
|
+
children: row.children
|
|
47
|
+
.filter((child) => !hasFragmentMount(child) || child === active)
|
|
48
|
+
.map((child) => (child === active ? { ...child, mountTo: undefined } : child)),
|
|
49
|
+
}
|
|
50
|
+
: row,
|
|
51
|
+
) ?? [],
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
/**
|
|
56
|
+
* Opens a configured modal at an address and selects the column's active child by hash.
|
|
57
|
+
* @param target The renderer for the modal definition and its children.
|
|
58
|
+
* @returns A routed modal renderer with a draft shared only within the open window.
|
|
59
|
+
*/
|
|
60
|
+
export function withColumn<Props extends DecoratedProps>(target: ComponentType<Props>): ComponentType<Props> {
|
|
61
|
+
/**
|
|
62
|
+
* Selects the visible branch and keeps the other rows mounted across transitions.
|
|
63
|
+
* @param props The modal rendering inputs, including its resolved definition.
|
|
64
|
+
* @returns The configured window, or null for an address that does not open it.
|
|
65
|
+
*/
|
|
66
|
+
return function routedColumn(props: Props): React.ReactNode {
|
|
67
|
+
const router = useContext(RouterContext),
|
|
68
|
+
node = props.configuredDefinition,
|
|
69
|
+
[draft, remember] = useState<FormData>();
|
|
70
|
+
const hash = router?.location.hash;
|
|
71
|
+
useLayoutEffect(() => {
|
|
72
|
+
remember(undefined);
|
|
73
|
+
}, [hash]);
|
|
74
|
+
if (!router || !node) return null;
|
|
75
|
+
const { pathname, search, url } = router.location,
|
|
76
|
+
{ navigate } = router,
|
|
77
|
+
column = modalColumn(node),
|
|
78
|
+
branches =
|
|
79
|
+
column?.children?.flatMap((row) =>
|
|
80
|
+
row.of === "row" ? (row.children ?? []).filter(hasFragmentMount) : [],
|
|
81
|
+
) ?? [],
|
|
82
|
+
active = branches.find((child) => child.mountTo === hash),
|
|
83
|
+
path = typeof node.mountTo === "string" ? router.path(node.mountTo) : undefined,
|
|
84
|
+
explicit = path ? new URL(path, url) : undefined;
|
|
85
|
+
if (branches.length > 0 && !active) return null;
|
|
86
|
+
if (node.mountTo !== undefined && (!hash || explicit?.hash !== hash || explicit.pathname !== pathname))
|
|
87
|
+
return null;
|
|
88
|
+
if (!active && !explicit) return null;
|
|
89
|
+
const definition =
|
|
90
|
+
column && active
|
|
91
|
+
? {
|
|
92
|
+
...node,
|
|
93
|
+
children: node.children?.map((child) => (child === column ? shownColumn(column, active) : child)),
|
|
94
|
+
}
|
|
95
|
+
: node;
|
|
96
|
+
|
|
97
|
+
/**
|
|
98
|
+
* Removes the current fragment and preserves the path and search parameters.
|
|
99
|
+
* @returns Nothing.
|
|
100
|
+
*/
|
|
101
|
+
function close(): void {
|
|
102
|
+
navigate(pathname + search, { replace: true });
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
return (
|
|
106
|
+
<ColumnDraftContext.Provider value={active ? { data: draft, remember } : null}>
|
|
107
|
+
{React.createElement(target, { ...props, definition, onModalClose: close })}
|
|
108
|
+
</ColumnDraftContext.Provider>
|
|
109
|
+
);
|
|
110
|
+
};
|
|
111
|
+
}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { type ComponentType, type ReactElement, createContext, createElement, useContext } from "react";
|
|
2
|
+
import { Stock } from "../services/Stock.js";
|
|
3
|
+
|
|
4
|
+
const externalAuthProviders = Object.freeze({
|
|
5
|
+
discord: { name: "Discord", stock: Stock.discord },
|
|
6
|
+
facebook: { name: "Facebook", stock: Stock.facebook },
|
|
7
|
+
github: { name: "GitHub", stock: Stock.github },
|
|
8
|
+
kakao: { name: "Kakao", stock: Stock.kakao },
|
|
9
|
+
ok: { name: "Одноклассники", stock: Stock.ok },
|
|
10
|
+
telegram: { name: "Telegram", stock: Stock.telegram },
|
|
11
|
+
vk: { name: "VK", stock: Stock.vk },
|
|
12
|
+
wechat: { name: "WeChat", stock: Stock.wechat },
|
|
13
|
+
weibo: { name: "Weibo", stock: Stock.weibo },
|
|
14
|
+
}),
|
|
15
|
+
providerContext = createContext<readonly Provider[]>([]),
|
|
16
|
+
/**
|
|
17
|
+
* Reads the sign-in services enabled around this component.
|
|
18
|
+
* @returns The ordered list of enabled services.
|
|
19
|
+
*/
|
|
20
|
+
useExternalAuth = (): readonly Provider[] => useContext(providerContext),
|
|
21
|
+
/**
|
|
22
|
+
* Builds a decorator for one sign-in service.
|
|
23
|
+
* @param service Name of a built-in service.
|
|
24
|
+
* @returns A decorator that adds the service to a compatible component.
|
|
25
|
+
*/
|
|
26
|
+
withExternalAuth =
|
|
27
|
+
(service: Provider): SignInDecorator =>
|
|
28
|
+
/**
|
|
29
|
+
* Adds the service to a compatible component tree.
|
|
30
|
+
* @param target Component that renders the sign-in actions.
|
|
31
|
+
* @returns The component with the service available to its children.
|
|
32
|
+
*/
|
|
33
|
+
// eslint-disable-next-line @typescript-eslint/prefer-readonly-parameter-types -- React components may own mutable state.
|
|
34
|
+
<Props extends object>(target: ComponentType<Props>): ComponentType<Props> =>
|
|
35
|
+
/**
|
|
36
|
+
* Passes the enabled services and original properties through.
|
|
37
|
+
* @param props Properties of the wrapped component.
|
|
38
|
+
* @returns The component in the extended provider context.
|
|
39
|
+
*/
|
|
40
|
+
function externalAuth(props: Props): ReactElement {
|
|
41
|
+
const enabled = useExternalAuth(),
|
|
42
|
+
value = [...new Set([...enabled, service])];
|
|
43
|
+
return createElement(providerContext.Provider, { value }, createElement(target, props));
|
|
44
|
+
};
|
|
45
|
+
|
|
46
|
+
type Provider = keyof typeof externalAuthProviders;
|
|
47
|
+
// eslint-disable-next-line @typescript-eslint/prefer-readonly-parameter-types -- React components may own mutable state.
|
|
48
|
+
type SignInDecorator = <Props extends object>(target: ComponentType<Props>) => ComponentType<Props>;
|
|
49
|
+
|
|
50
|
+
export { externalAuthProviders, useExternalAuth, withExternalAuth };
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
import * as React from "react";
|
|
2
|
+
import type { ComponentType, ReactElement } from "react";
|
|
3
|
+
import type { FieldProps, FormData, FormValue } from "../components/form/types.js";
|
|
4
|
+
import { isRecord, valueAt } from "../components/form/values.js";
|
|
5
|
+
import { useContext, useRef } from "react";
|
|
6
|
+
import { FormContext } from "../components/form/context.js";
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Заменяет целое значение по пути, сохраняя соседние поля.
|
|
10
|
+
* @param data Исходные данные.
|
|
11
|
+
* @param path Путь поля через точку.
|
|
12
|
+
* @param value Новое значение, в том числе целый JSON-объект.
|
|
13
|
+
* @returns Новые данные с заменённым значением.
|
|
14
|
+
*/
|
|
15
|
+
function changedData(data: FormData, path: string, value: FormValue): FormData {
|
|
16
|
+
const [key, ...rest] = path.split("."),
|
|
17
|
+
current = Object.hasOwn(data, key!) ? data[key!] : undefined;
|
|
18
|
+
return {
|
|
19
|
+
...data,
|
|
20
|
+
[key!]: rest.length ? changedData(isRecord(current) ? current : {}, rest.join("."), value) : value,
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* Изолирует управляемое поле и сохраняет доступ к обычному контексту Form.
|
|
26
|
+
* @param Component Компонент поля.
|
|
27
|
+
* @returns Поле, подключённое к контексту и обработчику изменений.
|
|
28
|
+
*/
|
|
29
|
+
export function withField<P extends FieldProps>(Component: ComponentType<P>): ComponentType<P> {
|
|
30
|
+
/**
|
|
31
|
+
* Снабжает одиночное управляемое поле данными и обработчиком, сохраняя контекст формы.
|
|
32
|
+
* @param props Свойства поля с обязательным обработчиком изменения.
|
|
33
|
+
* @returns Поле в контексте значений с наследованными настройками формы.
|
|
34
|
+
*/
|
|
35
|
+
function Controlled(props: P & Required<Pick<FieldProps, "onChange">>): ReactElement {
|
|
36
|
+
let data = changedData(props.contextData ?? {}, props.name, props.value);
|
|
37
|
+
if (props.humanized_name) {
|
|
38
|
+
data = changedData(data, props.humanized_name, props.humanized_value);
|
|
39
|
+
}
|
|
40
|
+
const form = useContext(FormContext),
|
|
41
|
+
snapshot = useRef(data);
|
|
42
|
+
snapshot.current = data;
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* Передаёт изменение родителю, учитывая предыдущие обновления в этом обработчике.
|
|
46
|
+
* @param path Путь изменённого значения.
|
|
47
|
+
* @param value Новое значение по этому пути.
|
|
48
|
+
* @returns Ничего.
|
|
49
|
+
*/
|
|
50
|
+
function update(path: string, value: FormValue): void {
|
|
51
|
+
const next = changedData(snapshot.current, path, value);
|
|
52
|
+
snapshot.current = next;
|
|
53
|
+
props.onChange(valueAt(next, props.name), { data: next, path, value });
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
return (
|
|
57
|
+
<FormContext.Provider value={{ ...form, data, update }}>
|
|
58
|
+
<Component {...props} />
|
|
59
|
+
</FormContext.Provider>
|
|
60
|
+
);
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
/**
|
|
64
|
+
* Подключает поле к форме, наследует её блокировку и применяет явный обработчик.
|
|
65
|
+
* @param props Свойства поля.
|
|
66
|
+
* @returns Поле с действующим контекстом.
|
|
67
|
+
*/
|
|
68
|
+
function Field(props: P): ReactElement {
|
|
69
|
+
const context = useContext(FormContext);
|
|
70
|
+
if (!props.onChange && !context) {
|
|
71
|
+
throw new Error("Provide onChange or render the field inside Form");
|
|
72
|
+
}
|
|
73
|
+
const disabled = Boolean(props.disabled || context?.disabled),
|
|
74
|
+
fieldProps: P = disabled === Boolean(props.disabled) ? props : { ...props, disabled },
|
|
75
|
+
field = fieldProps.onChange ? (
|
|
76
|
+
<Controlled {...fieldProps} onChange={fieldProps.onChange} />
|
|
77
|
+
) : (
|
|
78
|
+
<Component {...fieldProps} />
|
|
79
|
+
);
|
|
80
|
+
return disabled ? (
|
|
81
|
+
<fieldset disabled data-tiun-disabled="true" style={{ display: "contents" }}>
|
|
82
|
+
{field}
|
|
83
|
+
</fieldset>
|
|
84
|
+
) : (
|
|
85
|
+
field
|
|
86
|
+
);
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
Field.displayName = `Field(${Component.displayName ?? Component.name ?? "Field"})`;
|
|
90
|
+
return Field;
|
|
91
|
+
}
|