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,806 @@
|
|
|
1
|
+
import * as React from "react";
|
|
2
|
+
import type { FieldProps, FormData, FormValue } from "./types.js";
|
|
3
|
+
import type { ReactElement, ReactNode } from "react";
|
|
4
|
+
import { displayClass, isRecord, valueAt } from "./values.js";
|
|
5
|
+
import { matchesDynamicText, narrowsDynamicQuery } from "./dynamicMatching.js";
|
|
6
|
+
import { useEffect, useRef, useState } from "react";
|
|
7
|
+
import { Chip } from "../Chip.js";
|
|
8
|
+
import { ErrorSpan } from "./ErrorSpan.js";
|
|
9
|
+
import { FieldCaption } from "./FieldCaption.js";
|
|
10
|
+
import { Loader } from "../Loader.js";
|
|
11
|
+
import { loadResource, useLoad } from "../../services/load.js";
|
|
12
|
+
import { withValidation, type FieldValidation } from "../../decorators/withValidation.js";
|
|
13
|
+
import { nodeId } from "./identity.js";
|
|
14
|
+
import { toRem } from "../../layout/units.js";
|
|
15
|
+
import { useForm } from "./context.js";
|
|
16
|
+
import { useI18n } from "../../concern/i18n.js";
|
|
17
|
+
import { withField } from "../../decorators/withField.js";
|
|
18
|
+
|
|
19
|
+
export interface DynamicInputProps extends FieldProps {
|
|
20
|
+
readonly onPick?: (value: FormValue, caption: string) => void;
|
|
21
|
+
readonly onRange?: (begin: number, end: number) => void;
|
|
22
|
+
readonly error?: string;
|
|
23
|
+
readonly unfixedAction?: ReactNode;
|
|
24
|
+
}
|
|
25
|
+
interface Choice {
|
|
26
|
+
readonly key: FormValue;
|
|
27
|
+
readonly label: string;
|
|
28
|
+
}
|
|
29
|
+
interface CompleteChoices {
|
|
30
|
+
scope: string;
|
|
31
|
+
client: DynamicInputProps["client"];
|
|
32
|
+
query: string;
|
|
33
|
+
rows: Choice[];
|
|
34
|
+
total: number;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* Ищет варианты через Loader и даёт выбрать значение с подписью.
|
|
39
|
+
* - После снятия фиксации показывает уже известные варианты, пока текст и условия поиска прежние.
|
|
40
|
+
* @param props Настройки поля, адрес и контекст поиска, выбранное значение и обработчики.
|
|
41
|
+
* @returns Поле поиска, метеор текущего запроса и список вариантов.
|
|
42
|
+
*/
|
|
43
|
+
function DynamicSearch(props: DynamicInputProps & Required<Pick<DynamicInputProps, "onPick">>): ReactElement {
|
|
44
|
+
const { t } = useI18n(),
|
|
45
|
+
activeKey = isRecord(props.value) ? props.value.key : props.value,
|
|
46
|
+
caption = String(
|
|
47
|
+
isRecord(props.value)
|
|
48
|
+
? (props.value.value ?? "")
|
|
49
|
+
: (props.humanized_value ?? (activeKey === props.default ? props.humanized_default : undefined) ?? ""),
|
|
50
|
+
),
|
|
51
|
+
hasSelection = activeKey !== undefined && activeKey !== null && activeKey !== "",
|
|
52
|
+
itemAction = props.states?.fix,
|
|
53
|
+
selectionBackground = props.transparency ? (props.transparency.color ?? "transparent") : undefined,
|
|
54
|
+
shouldRevealAction = hasSelection && itemAction?.transientAction === true,
|
|
55
|
+
[isFixedActionVisible, setFixedActionVisible] = useState(false),
|
|
56
|
+
[text, setText] = useState(caption),
|
|
57
|
+
[open, setOpen] = useState(false),
|
|
58
|
+
[searchEnabled, setSearchEnabled] = useState(false),
|
|
59
|
+
[retry, setRetry] = useState(0),
|
|
60
|
+
supportsSearch = props.eager_load === true || text.length > 0,
|
|
61
|
+
[choices, setChoices] = useState<Choice[]>([]),
|
|
62
|
+
[total, setTotal] = useState<number>(),
|
|
63
|
+
[showTotal, setShowTotal] = useState(true),
|
|
64
|
+
[failed, setFailed] = useState(false),
|
|
65
|
+
{ loading, run, cancel } = useLoad(),
|
|
66
|
+
[active, setActive] = useState(-1),
|
|
67
|
+
[range, setRange] = useState<{ key: FormValue; caption: string; offsets: [number, number] }>(),
|
|
68
|
+
typedAutoFixRef = useRef<{ text: string; context: string } | undefined>(undefined),
|
|
69
|
+
untruncatedChoicesRef = useRef<CompleteChoices | undefined>(undefined),
|
|
70
|
+
valueResponseCache = useRef<(Omit<CompleteChoices, "total"> & { total: number | undefined }) | undefined>(
|
|
71
|
+
undefined,
|
|
72
|
+
),
|
|
73
|
+
widgetIdRef = useRef<string | undefined>(undefined);
|
|
74
|
+
widgetIdRef.current ??= nodeId();
|
|
75
|
+
const fieldId = props.id ?? widgetIdRef.current,
|
|
76
|
+
fieldRootRef = useRef<HTMLDivElement>(null),
|
|
77
|
+
inputRef = useRef<HTMLInputElement>(null),
|
|
78
|
+
popupRef = useRef<HTMLDivElement>(null),
|
|
79
|
+
pressedInPopupRef = useRef(false),
|
|
80
|
+
selectedLabelRef = useRef<HTMLSpanElement>(null),
|
|
81
|
+
releasedChoiceRef = useRef<{ choice: Choice; scope: string; client: DynamicInputProps["client"] } | undefined>(
|
|
82
|
+
undefined,
|
|
83
|
+
),
|
|
84
|
+
trackedKeyRef = useRef(activeKey),
|
|
85
|
+
transientActionTimer = useRef<ReturnType<typeof setTimeout> | undefined>(undefined),
|
|
86
|
+
valueContext: FormData = { ...props.contextValue };
|
|
87
|
+
for (const [name, value] of Object.entries(props.value_context ?? {})) {
|
|
88
|
+
const resolved = typeof value === "function" ? value() : value;
|
|
89
|
+
if (resolved !== undefined) {
|
|
90
|
+
valueContext[name] = resolved;
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
const context = JSON.stringify(valueContext),
|
|
94
|
+
searchScope = JSON.stringify([context, props.pathname, props.queryKey, props.key_name, props.value_name]);
|
|
95
|
+
|
|
96
|
+
function revealFixedAction(): void {
|
|
97
|
+
clearTimeout(transientActionTimer.current);
|
|
98
|
+
setFixedActionVisible(true);
|
|
99
|
+
transientActionTimer.current = setTimeout(() => {
|
|
100
|
+
const focused = fieldRootRef.current?.ownerDocument.activeElement;
|
|
101
|
+
if (focused?.classList.contains("tiun-chip-action") && fieldRootRef.current?.contains(focused)) {
|
|
102
|
+
selectedLabelRef.current?.focus();
|
|
103
|
+
}
|
|
104
|
+
setFixedActionVisible(false);
|
|
105
|
+
}, 5000);
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
useEffect(() => {
|
|
109
|
+
if (shouldRevealAction && trackedKeyRef.current !== activeKey) {
|
|
110
|
+
revealFixedAction();
|
|
111
|
+
} else {
|
|
112
|
+
setFixedActionVisible(false);
|
|
113
|
+
}
|
|
114
|
+
trackedKeyRef.current = activeKey;
|
|
115
|
+
return () => {
|
|
116
|
+
clearTimeout(transientActionTimer.current);
|
|
117
|
+
};
|
|
118
|
+
}, [activeKey, shouldRevealAction]);
|
|
119
|
+
|
|
120
|
+
useEffect(() => {
|
|
121
|
+
const document = fieldRootRef.current!.ownerDocument,
|
|
122
|
+
down = (event: PointerEvent): void => {
|
|
123
|
+
pressedInPopupRef.current = Boolean(popupRef.current?.contains(event.target as Node));
|
|
124
|
+
if (!fieldRootRef.current?.contains(event.target as Node)) {
|
|
125
|
+
setOpen(false);
|
|
126
|
+
}
|
|
127
|
+
},
|
|
128
|
+
focus = (event: FocusEvent): void => {
|
|
129
|
+
if (!pressedInPopupRef.current && !fieldRootRef.current?.contains(event.target as Node)) {
|
|
130
|
+
setOpen(false);
|
|
131
|
+
}
|
|
132
|
+
},
|
|
133
|
+
up = (): void => {
|
|
134
|
+
pressedInPopupRef.current = false;
|
|
135
|
+
};
|
|
136
|
+
|
|
137
|
+
document.addEventListener("focusin", focus, true);
|
|
138
|
+
document.addEventListener("pointerdown", down, true);
|
|
139
|
+
document.addEventListener("pointerup", up, true);
|
|
140
|
+
document.addEventListener("pointercancel", up, true);
|
|
141
|
+
return () => {
|
|
142
|
+
document.removeEventListener("focusin", focus, true);
|
|
143
|
+
document.removeEventListener("pointerdown", down, true);
|
|
144
|
+
document.removeEventListener("pointerup", up, true);
|
|
145
|
+
document.removeEventListener("pointercancel", up, true);
|
|
146
|
+
};
|
|
147
|
+
}, []);
|
|
148
|
+
|
|
149
|
+
useEffect(() => {
|
|
150
|
+
if (!open || !popupRef.current || !inputRef.current) {
|
|
151
|
+
return;
|
|
152
|
+
}
|
|
153
|
+
const document = fieldRootRef.current!.ownerDocument,
|
|
154
|
+
ownerWindow = document.defaultView!,
|
|
155
|
+
parentDialog = fieldRootRef.current!.closest("dialog"),
|
|
156
|
+
resize = (): void => {
|
|
157
|
+
if (!popupRef.current || !inputRef.current) {
|
|
158
|
+
return;
|
|
159
|
+
}
|
|
160
|
+
const { bottom } = inputRef.current.getBoundingClientRect();
|
|
161
|
+
if (bottom <= 0) {
|
|
162
|
+
return;
|
|
163
|
+
}
|
|
164
|
+
const limit = Math.min(
|
|
165
|
+
ownerWindow.innerHeight,
|
|
166
|
+
parentDialog
|
|
167
|
+
? parentDialog.getBoundingClientRect().bottom -
|
|
168
|
+
parseFloat(ownerWindow.getComputedStyle(parentDialog).borderBottomWidth || "0")
|
|
169
|
+
: ownerWindow.innerHeight,
|
|
170
|
+
),
|
|
171
|
+
rem = parseFloat(ownerWindow.getComputedStyle(document.documentElement).fontSize) || 16;
|
|
172
|
+
popupRef.current.style.maxHeight = toRem(
|
|
173
|
+
Math.max(0, Math.min(16 * rem, limit - bottom - rem * 0.06)),
|
|
174
|
+
popupRef.current,
|
|
175
|
+
);
|
|
176
|
+
};
|
|
177
|
+
|
|
178
|
+
resize();
|
|
179
|
+
const observer =
|
|
180
|
+
typeof ownerWindow.ResizeObserver === "function" ? new ownerWindow.ResizeObserver(resize) : undefined;
|
|
181
|
+
observer?.observe(inputRef.current);
|
|
182
|
+
if (parentDialog) {
|
|
183
|
+
observer?.observe(parentDialog);
|
|
184
|
+
}
|
|
185
|
+
ownerWindow.addEventListener("resize", resize);
|
|
186
|
+
document.addEventListener("scroll", resize, true);
|
|
187
|
+
return () => {
|
|
188
|
+
observer?.disconnect();
|
|
189
|
+
ownerWindow.removeEventListener("resize", resize);
|
|
190
|
+
document.removeEventListener("scroll", resize, true);
|
|
191
|
+
};
|
|
192
|
+
}, [open, supportsSearch, hasSelection]);
|
|
193
|
+
|
|
194
|
+
useEffect(() => {
|
|
195
|
+
setText(caption);
|
|
196
|
+
}, [caption]);
|
|
197
|
+
|
|
198
|
+
useEffect(() => {
|
|
199
|
+
inputRef.current?.setCustomValidity(props.error ?? "");
|
|
200
|
+
}, [props.error, hasSelection]);
|
|
201
|
+
|
|
202
|
+
useEffect(() => {
|
|
203
|
+
if (
|
|
204
|
+
untruncatedChoicesRef.current &&
|
|
205
|
+
(untruncatedChoicesRef.current.scope !== searchScope || untruncatedChoicesRef.current.client !== props.client)
|
|
206
|
+
) {
|
|
207
|
+
untruncatedChoicesRef.current = undefined;
|
|
208
|
+
}
|
|
209
|
+
if (
|
|
210
|
+
valueResponseCache.current &&
|
|
211
|
+
(valueResponseCache.current.scope !== searchScope || valueResponseCache.current.client !== props.client)
|
|
212
|
+
) {
|
|
213
|
+
valueResponseCache.current = undefined;
|
|
214
|
+
}
|
|
215
|
+
const released = releasedChoiceRef.current;
|
|
216
|
+
if (released && (released.scope !== searchScope || released.client !== props.client)) {
|
|
217
|
+
releasedChoiceRef.current = undefined;
|
|
218
|
+
}
|
|
219
|
+
if (!searchEnabled || hasSelection || !props.pathname) {
|
|
220
|
+
setFailed(false);
|
|
221
|
+
return;
|
|
222
|
+
}
|
|
223
|
+
if (!supportsSearch) {
|
|
224
|
+
setChoices([]);
|
|
225
|
+
setTotal(undefined);
|
|
226
|
+
setFailed(false);
|
|
227
|
+
setActive(-1);
|
|
228
|
+
return;
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
const autoFix = (rows: Choice[], total: number | undefined): void => {
|
|
232
|
+
if (
|
|
233
|
+
typedAutoFixRef.current?.text !== text ||
|
|
234
|
+
typedAutoFixRef.current.context !== context ||
|
|
235
|
+
total !== 1 ||
|
|
236
|
+
rows.length !== 1 ||
|
|
237
|
+
rows[0]!.label !== text
|
|
238
|
+
) {
|
|
239
|
+
return;
|
|
240
|
+
}
|
|
241
|
+
typedAutoFixRef.current = undefined;
|
|
242
|
+
pick(rows[0]!);
|
|
243
|
+
},
|
|
244
|
+
/**
|
|
245
|
+
* Matches choices by their translated caption or submitted identifier.
|
|
246
|
+
* @param rows {Choice[]} Choices returned by the lookup resource.
|
|
247
|
+
* @returns {Choice[]} Matching choices ordered by their displayed captions.
|
|
248
|
+
*/
|
|
249
|
+
// eslint-disable-next-line @typescript-eslint/prefer-readonly-parameter-types -- Each choice can contain a JSON form array.
|
|
250
|
+
filtered = (rows: readonly Choice[]): Choice[] =>
|
|
251
|
+
rows
|
|
252
|
+
.filter(
|
|
253
|
+
// eslint-disable-next-line @typescript-eslint/prefer-readonly-parameter-types -- The choice key is a submitted form value.
|
|
254
|
+
({ key, label }) =>
|
|
255
|
+
matchesDynamicText(label, text) ||
|
|
256
|
+
((typeof key === "string" || typeof key === "number") && matchesDynamicText(String(key), text)),
|
|
257
|
+
)
|
|
258
|
+
.sort((left, right) => left.label.localeCompare(right.label)),
|
|
259
|
+
previous = valueResponseCache.current;
|
|
260
|
+
const releasedChoice = releasedChoiceRef.current?.choice;
|
|
261
|
+
if (releasedChoice?.label === text) {
|
|
262
|
+
const knownChoices = filtered(previous?.rows ?? []).filter((row) => row.key !== releasedChoice.key);
|
|
263
|
+
setChoices([releasedChoice, ...knownChoices]);
|
|
264
|
+
setTotal(undefined);
|
|
265
|
+
setFailed(false);
|
|
266
|
+
setActive(-1);
|
|
267
|
+
return;
|
|
268
|
+
}
|
|
269
|
+
if (previous && previous.query === text) {
|
|
270
|
+
setChoices(filtered(previous.rows));
|
|
271
|
+
setTotal(previous.total);
|
|
272
|
+
setFailed(false);
|
|
273
|
+
setActive(-1);
|
|
274
|
+
autoFix(previous.rows, previous.total);
|
|
275
|
+
return;
|
|
276
|
+
}
|
|
277
|
+
const cached = untruncatedChoicesRef.current;
|
|
278
|
+
if (cached && narrowsDynamicQuery(cached.query, text)) {
|
|
279
|
+
setChoices(filtered(cached.rows));
|
|
280
|
+
setTotal(cached.total);
|
|
281
|
+
setFailed(false);
|
|
282
|
+
setActive(-1);
|
|
283
|
+
autoFix(cached.rows, cached.total);
|
|
284
|
+
return;
|
|
285
|
+
}
|
|
286
|
+
setFailed(false);
|
|
287
|
+
setChoices([]);
|
|
288
|
+
setTotal(undefined);
|
|
289
|
+
setActive(-1);
|
|
290
|
+
const requestPath = `/${props.pathname.replace(/^\/+/, "").replace(/\.json$/, "")}.json`;
|
|
291
|
+
void run(async (signal) => {
|
|
292
|
+
try {
|
|
293
|
+
const response = await loadResource(
|
|
294
|
+
requestPath,
|
|
295
|
+
{
|
|
296
|
+
params: {
|
|
297
|
+
per: props.limit ?? 512,
|
|
298
|
+
...(JSON.parse(context) as FormData),
|
|
299
|
+
[props.queryKey ?? "q"]: text,
|
|
300
|
+
},
|
|
301
|
+
signal,
|
|
302
|
+
},
|
|
303
|
+
props.client,
|
|
304
|
+
);
|
|
305
|
+
if (signal.aborted) {
|
|
306
|
+
return;
|
|
307
|
+
}
|
|
308
|
+
const body = response.data as FormValue,
|
|
309
|
+
choiceRows = Array.isArray(body) ? body : isRecord(body) && Array.isArray(body.list) ? body.list : [],
|
|
310
|
+
filteredChoices = choiceRows
|
|
311
|
+
.filter(isRecord)
|
|
312
|
+
.map((row) => ({
|
|
313
|
+
key: row[props.value_name ?? "key"],
|
|
314
|
+
label: String(row[props.key_name ?? "value"] ?? ""),
|
|
315
|
+
}))
|
|
316
|
+
.filter((row) => row.key != null),
|
|
317
|
+
headerMatch = /^\s*records\s+(?:(\d+)-(\d+)|\*)\/(\d+|\*)\s*$/i.exec(
|
|
318
|
+
String(response.headers["content-range"] ?? ""),
|
|
319
|
+
),
|
|
320
|
+
headerTotal = headerMatch && headerMatch[3] !== "*" ? Number(headerMatch[3]) : undefined,
|
|
321
|
+
payloadTotal = isRecord(body) && typeof body.total === "number" ? body.total : undefined,
|
|
322
|
+
total = headerTotal ?? payloadTotal,
|
|
323
|
+
wasFullyLoaded =
|
|
324
|
+
headerTotal !== undefined &&
|
|
325
|
+
((headerTotal === 0 && choiceRows.length === 0) ||
|
|
326
|
+
(Number(headerMatch?.[1]) === 0 &&
|
|
327
|
+
Number(headerMatch?.[2]) + 1 >= headerTotal &&
|
|
328
|
+
choiceRows.length >= headerTotal));
|
|
329
|
+
valueResponseCache.current = {
|
|
330
|
+
client: props.client,
|
|
331
|
+
query: text,
|
|
332
|
+
rows: filteredChoices,
|
|
333
|
+
scope: searchScope,
|
|
334
|
+
total,
|
|
335
|
+
};
|
|
336
|
+
untruncatedChoicesRef.current = wasFullyLoaded
|
|
337
|
+
? { client: props.client, query: text, rows: filteredChoices, scope: searchScope, total: headerTotal }
|
|
338
|
+
: undefined;
|
|
339
|
+
setChoices(filtered(filteredChoices));
|
|
340
|
+
setTotal(total);
|
|
341
|
+
setShowTotal(true);
|
|
342
|
+
if (headerTotal === undefined || wasFullyLoaded) {
|
|
343
|
+
autoFix(filteredChoices, total);
|
|
344
|
+
}
|
|
345
|
+
} catch {
|
|
346
|
+
if (!signal.aborted) {
|
|
347
|
+
setChoices([]);
|
|
348
|
+
setFailed(true);
|
|
349
|
+
}
|
|
350
|
+
}
|
|
351
|
+
});
|
|
352
|
+
return cancel;
|
|
353
|
+
}, [
|
|
354
|
+
searchEnabled,
|
|
355
|
+
retry,
|
|
356
|
+
hasSelection,
|
|
357
|
+
props.pathname,
|
|
358
|
+
props.queryKey,
|
|
359
|
+
props.key_name,
|
|
360
|
+
props.value_name,
|
|
361
|
+
props.client,
|
|
362
|
+
props.eager_load,
|
|
363
|
+
supportsSearch,
|
|
364
|
+
text,
|
|
365
|
+
context,
|
|
366
|
+
searchScope,
|
|
367
|
+
props.limit,
|
|
368
|
+
run,
|
|
369
|
+
cancel,
|
|
370
|
+
]);
|
|
371
|
+
|
|
372
|
+
/** Выбирает пару. Аргумент: choice — ответ API; результат: void. Пример: pick({key: "uno", label: "Имя"}). */
|
|
373
|
+
function pick(choice: Choice): void {
|
|
374
|
+
typedAutoFixRef.current = undefined;
|
|
375
|
+
releasedChoiceRef.current = undefined;
|
|
376
|
+
setRange(undefined);
|
|
377
|
+
setText(choice.label);
|
|
378
|
+
props.onPick(choice.key, choice.label);
|
|
379
|
+
setOpen(false);
|
|
380
|
+
setSearchEnabled(false);
|
|
381
|
+
setActive(-1);
|
|
382
|
+
}
|
|
383
|
+
|
|
384
|
+
function selectCaptionWithKeyboard(event: React.KeyboardEvent<HTMLSpanElement>): void {
|
|
385
|
+
if (
|
|
386
|
+
!props.selectable ||
|
|
387
|
+
!selectedLabelRef.current ||
|
|
388
|
+
!["ArrowLeft", "ArrowRight", "Home", "End"].includes(event.key)
|
|
389
|
+
) {
|
|
390
|
+
return;
|
|
391
|
+
}
|
|
392
|
+
event.preventDefault();
|
|
393
|
+
event.stopPropagation();
|
|
394
|
+
const captionNode = selectedLabelRef.current,
|
|
395
|
+
document = captionNode.ownerDocument,
|
|
396
|
+
selection = document.getSelection();
|
|
397
|
+
if (!selection) {
|
|
398
|
+
return;
|
|
399
|
+
}
|
|
400
|
+
|
|
401
|
+
const absoluteOffset = (node: Node | null, position: number): number => {
|
|
402
|
+
if (!node || !captionNode.contains(node)) {
|
|
403
|
+
return 0;
|
|
404
|
+
}
|
|
405
|
+
const prefix = document.createRange();
|
|
406
|
+
prefix.selectNodeContents(captionNode);
|
|
407
|
+
prefix.setEnd(node, position);
|
|
408
|
+
return prefix.toString().length;
|
|
409
|
+
},
|
|
410
|
+
anchor = absoluteOffset(selection.anchorNode, selection.anchorOffset),
|
|
411
|
+
focus = absoluteOffset(selection.focusNode, selection.focusOffset);
|
|
412
|
+
let next =
|
|
413
|
+
event.key === "Home"
|
|
414
|
+
? 0
|
|
415
|
+
: event.key === "End"
|
|
416
|
+
? caption.length
|
|
417
|
+
: Math.max(0, Math.min(caption.length, focus + (event.key === "ArrowLeft" ? -1 : 1)));
|
|
418
|
+
if (!event.shiftKey && !selection.isCollapsed && event.key.startsWith("Arrow")) {
|
|
419
|
+
next = event.key === "ArrowLeft" ? Math.min(anchor, focus) : Math.max(anchor, focus);
|
|
420
|
+
}
|
|
421
|
+
|
|
422
|
+
const at = (position: number): [Node, number] => {
|
|
423
|
+
const walker = document.createTreeWalker(captionNode, 4); // SHOW_TEXT
|
|
424
|
+
let node = walker.nextNode();
|
|
425
|
+
while (node) {
|
|
426
|
+
const length = node.textContent?.length ?? 0;
|
|
427
|
+
if (position <= length) {
|
|
428
|
+
return [node, position];
|
|
429
|
+
}
|
|
430
|
+
position -= length;
|
|
431
|
+
node = walker.nextNode();
|
|
432
|
+
}
|
|
433
|
+
return [captionNode, 0];
|
|
434
|
+
};
|
|
435
|
+
|
|
436
|
+
selection.setBaseAndExtent(...at(event.shiftKey ? anchor : next), ...at(next));
|
|
437
|
+
captureSelection();
|
|
438
|
+
}
|
|
439
|
+
|
|
440
|
+
function captureSelection(): void {
|
|
441
|
+
if (!props.selectable || !selectedLabelRef.current) {
|
|
442
|
+
return;
|
|
443
|
+
}
|
|
444
|
+
const selection = selectedLabelRef.current.ownerDocument.getSelection();
|
|
445
|
+
if (!selection?.rangeCount || selection.isCollapsed) {
|
|
446
|
+
setRange(undefined);
|
|
447
|
+
return;
|
|
448
|
+
}
|
|
449
|
+
const chosen = selection.getRangeAt(0);
|
|
450
|
+
if (
|
|
451
|
+
!selectedLabelRef.current.contains(chosen.startContainer) ||
|
|
452
|
+
!selectedLabelRef.current.contains(chosen.endContainer)
|
|
453
|
+
) {
|
|
454
|
+
setRange(undefined);
|
|
455
|
+
return;
|
|
456
|
+
}
|
|
457
|
+
const prefix = chosen.cloneRange();
|
|
458
|
+
prefix.selectNodeContents(selectedLabelRef.current);
|
|
459
|
+
prefix.setEnd(chosen.startContainer, chosen.startOffset);
|
|
460
|
+
const start = prefix.toString().length;
|
|
461
|
+
setRange({ caption, key: activeKey, offsets: [start, start + chosen.toString().length] });
|
|
462
|
+
}
|
|
463
|
+
|
|
464
|
+
useEffect(() => {
|
|
465
|
+
setRange(undefined);
|
|
466
|
+
if (!hasSelection || !props.selectable) {
|
|
467
|
+
return;
|
|
468
|
+
}
|
|
469
|
+
const document = fieldRootRef.current!.ownerDocument;
|
|
470
|
+
document.addEventListener("selectionchange", captureSelection);
|
|
471
|
+
return () => {
|
|
472
|
+
document.removeEventListener("selectionchange", captureSelection);
|
|
473
|
+
};
|
|
474
|
+
}, [activeKey, caption, hasSelection, props.selectable]);
|
|
475
|
+
|
|
476
|
+
const isPopupVisible = open && supportsSearch && (choices.length > 0 || failed),
|
|
477
|
+
rangeBegin = typeof props.begin === "number" ? props.begin : undefined,
|
|
478
|
+
rangeEnd = typeof props.end === "number" ? props.end : undefined,
|
|
479
|
+
rangeIsValid =
|
|
480
|
+
rangeBegin !== undefined &&
|
|
481
|
+
rangeEnd !== undefined &&
|
|
482
|
+
rangeBegin >= 0 &&
|
|
483
|
+
rangeEnd > rangeBegin &&
|
|
484
|
+
rangeEnd <= caption.length,
|
|
485
|
+
unsavedOffsets = range && range.key === activeKey && range.caption === caption ? range.offsets : undefined;
|
|
486
|
+
|
|
487
|
+
/**
|
|
488
|
+
* Снимает фиксацию и запоминает прежний вариант для повторного выбора.
|
|
489
|
+
* Аргументов нет. Возвращает void.
|
|
490
|
+
*/
|
|
491
|
+
function unfix(): void {
|
|
492
|
+
const label = text || String(activeKey);
|
|
493
|
+
releasedChoiceRef.current = { choice: { key: activeKey, label }, scope: searchScope, client: props.client };
|
|
494
|
+
typedAutoFixRef.current = undefined;
|
|
495
|
+
setRange(undefined);
|
|
496
|
+
setText(label);
|
|
497
|
+
props.onPick(null, label);
|
|
498
|
+
setShowTotal(false);
|
|
499
|
+
setOpen(false);
|
|
500
|
+
setSearchEnabled(false);
|
|
501
|
+
}
|
|
502
|
+
|
|
503
|
+
/**
|
|
504
|
+
* Shows choices for the text already in the field.
|
|
505
|
+
* - An empty input starts searching only in eager mode.
|
|
506
|
+
* - A failed lookup is retried when the closed list is opened again.
|
|
507
|
+
* @returns {void} Updates the search and popup state. Takes no arguments.
|
|
508
|
+
*/
|
|
509
|
+
// eslint-disable-next-line one-var -- The open event owns its retry separately from reset.
|
|
510
|
+
const openChoices = (): void => {
|
|
511
|
+
setOpen(true);
|
|
512
|
+
if (supportsSearch) {
|
|
513
|
+
setSearchEnabled(true);
|
|
514
|
+
if (failed && !open) {
|
|
515
|
+
const nextAttempt = 1;
|
|
516
|
+
setRetry((value) => value + nextAttempt);
|
|
517
|
+
}
|
|
518
|
+
}
|
|
519
|
+
};
|
|
520
|
+
|
|
521
|
+
/**
|
|
522
|
+
* Обновляет черновик и запускает поиск, когда пользователь меняет текст.
|
|
523
|
+
* @param event {React.FormEvent<HTMLInputElement>} Событие ввода с новым значением.
|
|
524
|
+
* @returns {void} Обновляет поле и список подсказок.
|
|
525
|
+
*/
|
|
526
|
+
function changeText(event: React.FormEvent<HTMLInputElement>): void {
|
|
527
|
+
const { value } = event.currentTarget;
|
|
528
|
+
if (value !== text) {
|
|
529
|
+
releasedChoiceRef.current = undefined;
|
|
530
|
+
}
|
|
531
|
+
typedAutoFixRef.current = { context, text: value };
|
|
532
|
+
setText(value);
|
|
533
|
+
props.onPick(null, value);
|
|
534
|
+
setOpen(true);
|
|
535
|
+
setSearchEnabled(true);
|
|
536
|
+
}
|
|
537
|
+
|
|
538
|
+
function keyDown(event: React.KeyboardEvent<HTMLInputElement>): void {
|
|
539
|
+
if (event.key === "Escape" && open) {
|
|
540
|
+
event.preventDefault();
|
|
541
|
+
event.stopPropagation();
|
|
542
|
+
setOpen(false);
|
|
543
|
+
} else if (event.key === "ArrowDown" || event.key === "ArrowUp") {
|
|
544
|
+
event.preventDefault();
|
|
545
|
+
setOpen(true);
|
|
546
|
+
|
|
547
|
+
setActive((previous) =>
|
|
548
|
+
choices.length
|
|
549
|
+
? previous < 0
|
|
550
|
+
? event.key === "ArrowDown"
|
|
551
|
+
? 0
|
|
552
|
+
: choices.length - 1
|
|
553
|
+
: (previous + (event.key === "ArrowDown" ? 1 : -1) + choices.length) % choices.length
|
|
554
|
+
: -1,
|
|
555
|
+
);
|
|
556
|
+
} else if (event.key === "Enter" && open) {
|
|
557
|
+
event.preventDefault();
|
|
558
|
+
const choice = choices[active >= 0 ? active : 0];
|
|
559
|
+
if (choice) {
|
|
560
|
+
pick(choice);
|
|
561
|
+
}
|
|
562
|
+
}
|
|
563
|
+
}
|
|
564
|
+
|
|
565
|
+
let totalHint: string | undefined;
|
|
566
|
+
if (typeof total === "number" && !total) {
|
|
567
|
+
totalHint = props.i18n?.noResults ?? t("tiun.components.dynamic.no_results");
|
|
568
|
+
}
|
|
569
|
+
return (
|
|
570
|
+
<div
|
|
571
|
+
ref={fieldRootRef}
|
|
572
|
+
data-has-action={Boolean(props.unfixedAction)}
|
|
573
|
+
aria-invalid={Boolean(props.error)}
|
|
574
|
+
data-variant={props.variant ?? "underline"}
|
|
575
|
+
className={`tiun-field tiun-text-field tiun-dynamic-field ${displayClass(props.display_scheme ?? "12-12-12-12")} ${props.wrapperClassName ?? ""}`}
|
|
576
|
+
onClick={shouldRevealAction ? revealFixedAction : undefined}
|
|
577
|
+
onBlur={(event) => {
|
|
578
|
+
if (!pressedInPopupRef.current && !fieldRootRef.current?.contains(event.relatedTarget)) {
|
|
579
|
+
setOpen(false);
|
|
580
|
+
}
|
|
581
|
+
}}
|
|
582
|
+
>
|
|
583
|
+
<FieldCaption htmlFor={fieldId}>{props.title ?? props.i18n?.title}</FieldCaption>
|
|
584
|
+
{hasSelection ? (
|
|
585
|
+
<Chip
|
|
586
|
+
variant="field"
|
|
587
|
+
className="tiun-dynamic-chip"
|
|
588
|
+
wrapperClassName="tiun-dynamic-selection"
|
|
589
|
+
color={selectionBackground ?? null}
|
|
590
|
+
action={!shouldRevealAction || isFixedActionVisible ? "remove" : null}
|
|
591
|
+
data={activeKey}
|
|
592
|
+
actionLabel={props.i18n?.remove ?? t("tiun.components.dynamic.unfix")}
|
|
593
|
+
onAct={unfix}
|
|
594
|
+
trailing={
|
|
595
|
+
props.selectable &&
|
|
596
|
+
unsavedOffsets && (
|
|
597
|
+
<button
|
|
598
|
+
type="button"
|
|
599
|
+
className="tiun-dynamic-apply"
|
|
600
|
+
onPointerDown={(event) => {
|
|
601
|
+
event.preventDefault();
|
|
602
|
+
}}
|
|
603
|
+
onMouseDown={(event) => {
|
|
604
|
+
event.preventDefault();
|
|
605
|
+
}}
|
|
606
|
+
onClick={() => {
|
|
607
|
+
props.onRange?.(...unsavedOffsets);
|
|
608
|
+
setRange(undefined);
|
|
609
|
+
}}
|
|
610
|
+
>
|
|
611
|
+
{props.i18n?.applyRange ?? t("tiun.components.dynamic.apply_range")}
|
|
612
|
+
</button>
|
|
613
|
+
)
|
|
614
|
+
}
|
|
615
|
+
>
|
|
616
|
+
<span
|
|
617
|
+
ref={selectedLabelRef}
|
|
618
|
+
title={caption}
|
|
619
|
+
style={{ color: itemAction?.color }}
|
|
620
|
+
role={shouldRevealAction ? "button" : undefined}
|
|
621
|
+
aria-expanded={shouldRevealAction ? isFixedActionVisible : undefined}
|
|
622
|
+
tabIndex={props.selectable || shouldRevealAction ? 0 : undefined}
|
|
623
|
+
onPointerUp={captureSelection}
|
|
624
|
+
onMouseUp={captureSelection}
|
|
625
|
+
onKeyUp={captureSelection}
|
|
626
|
+
onKeyDown={(event) => {
|
|
627
|
+
if (shouldRevealAction && (event.key === "Enter" || event.key === " ")) {
|
|
628
|
+
event.preventDefault();
|
|
629
|
+
event.stopPropagation();
|
|
630
|
+
revealFixedAction();
|
|
631
|
+
} else {
|
|
632
|
+
selectCaptionWithKeyboard(event);
|
|
633
|
+
}
|
|
634
|
+
}}
|
|
635
|
+
>
|
|
636
|
+
{rangeIsValid ? (
|
|
637
|
+
<>
|
|
638
|
+
{caption.slice(0, rangeBegin)}
|
|
639
|
+
<mark style={{ color: itemAction?.color }}>{caption.slice(rangeBegin, rangeEnd)}</mark>
|
|
640
|
+
{caption.slice(rangeEnd)}
|
|
641
|
+
</>
|
|
642
|
+
) : (
|
|
643
|
+
caption || String(activeKey)
|
|
644
|
+
)}
|
|
645
|
+
</span>
|
|
646
|
+
</Chip>
|
|
647
|
+
) : (
|
|
648
|
+
<input
|
|
649
|
+
ref={inputRef}
|
|
650
|
+
type="text"
|
|
651
|
+
id={fieldId}
|
|
652
|
+
name={props.name}
|
|
653
|
+
value={text}
|
|
654
|
+
style={{
|
|
655
|
+
backgroundColor: props.transparency?.state === "full" ? selectionBackground : undefined,
|
|
656
|
+
color: props.states?.edit?.color,
|
|
657
|
+
}}
|
|
658
|
+
placeholder={props.placeholder}
|
|
659
|
+
role="combobox"
|
|
660
|
+
aria-autocomplete="list"
|
|
661
|
+
aria-expanded={isPopupVisible}
|
|
662
|
+
aria-controls={`${fieldId}-list`}
|
|
663
|
+
aria-activedescendant={open && supportsSearch && active >= 0 ? `${fieldId}-option-${active}` : undefined}
|
|
664
|
+
aria-busy={loading}
|
|
665
|
+
aria-invalid={Boolean(props.error)}
|
|
666
|
+
aria-describedby={`${fieldId}-error`}
|
|
667
|
+
autoComplete="off"
|
|
668
|
+
onClick={openChoices}
|
|
669
|
+
onFocus={openChoices}
|
|
670
|
+
onInput={changeText}
|
|
671
|
+
onKeyDown={keyDown}
|
|
672
|
+
/>
|
|
673
|
+
)}
|
|
674
|
+
{!hasSelection && props.unfixedAction && <span className="tiun-dynamic-action">{props.unfixedAction}</span>}
|
|
675
|
+
{!hasSelection && (
|
|
676
|
+
<Loader
|
|
677
|
+
variant="comet"
|
|
678
|
+
loading={loading}
|
|
679
|
+
size={5 / 3}
|
|
680
|
+
className="tiun-dynamic-spinner"
|
|
681
|
+
label={props.i18n?.loading ?? t("tiun.common.loading")}
|
|
682
|
+
/>
|
|
683
|
+
)}
|
|
684
|
+
{!hasSelection && showTotal && total !== undefined && !loading && supportsSearch && (
|
|
685
|
+
<span
|
|
686
|
+
className="tiun-dynamic-total"
|
|
687
|
+
title={totalHint}
|
|
688
|
+
aria-label={props.i18n?.total ?? t("tiun.components.dynamic.total")}
|
|
689
|
+
>
|
|
690
|
+
{props.i18n?.of ?? t("tiun.components.dynamic.of")} {total}
|
|
691
|
+
</span>
|
|
692
|
+
)}
|
|
693
|
+
{!hasSelection && isPopupVisible && (
|
|
694
|
+
<div ref={popupRef} className="tiun-dynamic-popup">
|
|
695
|
+
{failed && (
|
|
696
|
+
<span role="status">{props.i18n?.failed ?? t("tiun.components.dynamic.errors.choices")}</span>
|
|
697
|
+
)}
|
|
698
|
+
<ul id={`${fieldId}-list`} role="listbox">
|
|
699
|
+
{choices.map((choice, index) => (
|
|
700
|
+
<li
|
|
701
|
+
key={`${String(choice.key)}-${index}`}
|
|
702
|
+
role="option"
|
|
703
|
+
id={`${fieldId}-option-${index}`}
|
|
704
|
+
aria-selected={index === active}
|
|
705
|
+
>
|
|
706
|
+
<button
|
|
707
|
+
type="button"
|
|
708
|
+
onMouseDown={(event) => {
|
|
709
|
+
event.preventDefault();
|
|
710
|
+
}}
|
|
711
|
+
onClick={() => {
|
|
712
|
+
pick(choice);
|
|
713
|
+
}}
|
|
714
|
+
>
|
|
715
|
+
{choice.label}
|
|
716
|
+
</button>
|
|
717
|
+
</li>
|
|
718
|
+
))}
|
|
719
|
+
</ul>
|
|
720
|
+
</div>
|
|
721
|
+
)}
|
|
722
|
+
<div className="tiun-dynamic-feedback">
|
|
723
|
+
<ErrorSpan id={`${fieldId}-error`} error={props.error} />
|
|
724
|
+
<span className="tiun-dynamic-error-reserve" aria-hidden="true">
|
|
725
|
+
{Object.keys(props.validations ?? {}).map((message) => (
|
|
726
|
+
<span key={message}>{message}</span>
|
|
727
|
+
))}
|
|
728
|
+
</span>
|
|
729
|
+
</div>
|
|
730
|
+
</div>
|
|
731
|
+
);
|
|
732
|
+
}
|
|
733
|
+
|
|
734
|
+
/**
|
|
735
|
+
* Adapts a search result to the field's key, caption and range.
|
|
736
|
+
* @param props Field settings and callbacks that override form updates.
|
|
737
|
+
* @returns Search controls connected to the surrounding form.
|
|
738
|
+
*/
|
|
739
|
+
function BoundInput(props: DynamicInputProps & FieldValidation): ReactElement {
|
|
740
|
+
const { data, update, setDraft } = useForm();
|
|
741
|
+
|
|
742
|
+
useEffect(() => () => setDraft?.(props.name, false), [props.name, setDraft]);
|
|
743
|
+
|
|
744
|
+
const parentParts = props.name.split(".").slice(0, -1),
|
|
745
|
+
rangeBeginPath = [...parentParts, "begin"].join("."),
|
|
746
|
+
rangeEndPath = [...parentParts, "end"].join("."),
|
|
747
|
+
selectionBegin = props.begin ?? valueAt(data, rangeBeginPath),
|
|
748
|
+
selectionEnd = props.end ?? valueAt(data, rangeEndPath);
|
|
749
|
+
|
|
750
|
+
/** Записывает пару без смешивания ключа и подписи. Аргументы: value, caption; результат: void. Пример: pick(null, "Святой") сохраняет черновую подпись без ключа. */
|
|
751
|
+
function pick(value: FormValue, caption: string): void {
|
|
752
|
+
if (!props.humanized_name) {
|
|
753
|
+
const originalCaption = String(props.humanized_value ?? props.humanized_default ?? "");
|
|
754
|
+
setDraft?.(props.name, value == null && caption !== originalCaption);
|
|
755
|
+
}
|
|
756
|
+
const previousKey = isRecord(props.value) ? props.value.key : props.value;
|
|
757
|
+
if (previousKey !== value) {
|
|
758
|
+
if (selectionBegin != null) {
|
|
759
|
+
update(rangeBeginPath, null);
|
|
760
|
+
}
|
|
761
|
+
if (selectionEnd != null) {
|
|
762
|
+
update(rangeEndPath, null);
|
|
763
|
+
}
|
|
764
|
+
}
|
|
765
|
+
update(props.name, value);
|
|
766
|
+
if (props.humanized_name) {
|
|
767
|
+
update(props.humanized_name, caption);
|
|
768
|
+
}
|
|
769
|
+
}
|
|
770
|
+
|
|
771
|
+
useEffect(() => {
|
|
772
|
+
if (props.value == null && props.default != null) {
|
|
773
|
+
pick(props.default, props.humanized_default ?? String(props.default));
|
|
774
|
+
}
|
|
775
|
+
}, [props.name, props.default]);
|
|
776
|
+
|
|
777
|
+
const error = props.validateField(props.value, { end: selectionEnd, start: selectionBegin });
|
|
778
|
+
return (
|
|
779
|
+
<DynamicSearch
|
|
780
|
+
{...props}
|
|
781
|
+
begin={selectionBegin}
|
|
782
|
+
end={selectionEnd}
|
|
783
|
+
error={props.error ?? error}
|
|
784
|
+
onPick={pick}
|
|
785
|
+
onRange={
|
|
786
|
+
props.onRange ??
|
|
787
|
+
((start, finish) => {
|
|
788
|
+
update(rangeBeginPath, start);
|
|
789
|
+
update(rangeEndPath, finish);
|
|
790
|
+
})
|
|
791
|
+
}
|
|
792
|
+
/>
|
|
793
|
+
);
|
|
794
|
+
}
|
|
795
|
+
|
|
796
|
+
const FormInput = withField(withValidation<DynamicInputProps>(BoundInput));
|
|
797
|
+
|
|
798
|
+
/**
|
|
799
|
+
* Searches for a record and either updates the form or calls a supplied handler.
|
|
800
|
+
* @param props Field settings and optional callbacks overriding form behavior.
|
|
801
|
+
* @returns A field whose value, caption and range use one search control.
|
|
802
|
+
*/
|
|
803
|
+
export function DynamicInput(props: DynamicInputProps): ReactElement {
|
|
804
|
+
const { onPick } = props;
|
|
805
|
+
return onPick ? <DynamicSearch {...props} onPick={onPick} /> : <FormInput {...props} />;
|
|
806
|
+
}
|