tiun 0.0.2.1 → 0.2.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.
Files changed (527) hide show
  1. checksums.yaml +4 -4
  2. data/.forgejo/workflows/codeberg-tests.yml +226 -0
  3. data/.gitignore +7 -3
  4. data/.prettierrc.json +5 -0
  5. data/.rubocop.yml +221 -0
  6. data/AGENTS.md +132 -0
  7. data/Appraisals +18 -0
  8. data/CONTRIBUTING.md +80 -0
  9. data/CONTRIBUTING.ru.md +326 -0
  10. data/Gemfile +20 -1
  11. data/README.md +52 -23
  12. data/README.ru.md +72 -0
  13. data/Rakefile +10 -4
  14. data/TODO +2 -6
  15. data/bin/console +4 -3
  16. data/config/cucumber.yml +1 -0
  17. data/cucumber.mjs +6 -0
  18. data/docs/backend.md +73 -0
  19. data/docs/backend.ru.md +73 -0
  20. data/docs/components/approved.md +39 -0
  21. data/docs/components/approved.ru.md +39 -0
  22. data/docs/components/attachment-field.md +7 -0
  23. data/docs/components/attachment-field.ru.md +8 -0
  24. data/docs/components/attachment.md +48 -0
  25. data/docs/components/attachment.ru.md +48 -0
  26. data/docs/components/avatar.md +39 -0
  27. data/docs/components/avatar.ru.md +37 -0
  28. data/docs/components/chip.md +119 -0
  29. data/docs/components/chip.ru.md +99 -0
  30. data/docs/components/configuration.md +137 -0
  31. data/docs/components/configuration.ru.md +138 -0
  32. data/docs/components/daylight.md +41 -0
  33. data/docs/components/daylight.ru.md +41 -0
  34. data/docs/components/defaults.md +148 -0
  35. data/docs/components/defaults.ru.md +149 -0
  36. data/docs/components/documents.md +64 -0
  37. data/docs/components/documents.ru.md +64 -0
  38. data/docs/components/external-form-fields.ru.md +137 -0
  39. data/docs/components/external-renderers.md +50 -0
  40. data/docs/components/external-renderers.ru.md +51 -0
  41. data/docs/components/feedback.md +76 -0
  42. data/docs/components/feedback.ru.md +76 -0
  43. data/docs/components/footer.md +49 -0
  44. data/docs/components/footer.ru.md +49 -0
  45. data/docs/components/forms.md +177 -0
  46. data/docs/components/forms.ru.md +177 -0
  47. data/docs/components/images.md +141 -0
  48. data/docs/components/images.ru.md +140 -0
  49. data/docs/components/index.md +140 -0
  50. data/docs/components/index.ru.md +140 -0
  51. data/docs/components/intro.md +150 -0
  52. data/docs/components/intro.ru.md +150 -0
  53. data/docs/components/login.md +602 -0
  54. data/docs/components/login.ru.md +604 -0
  55. data/docs/components/methods.md +59 -0
  56. data/docs/components/methods.ru.md +59 -0
  57. data/docs/components/player.md +72 -0
  58. data/docs/components/player.ru.md +69 -0
  59. data/docs/components/profile.md +84 -0
  60. data/docs/components/profile.ru.md +84 -0
  61. data/docs/components/record-manager.md +69 -0
  62. data/docs/components/record-manager.ru.md +69 -0
  63. data/docs/components/row-column.ru.md +51 -0
  64. data/docs/components/rtfer.md +76 -0
  65. data/docs/components/rtfer.ru.md +76 -0
  66. data/docs/components/schema-calendar.md +86 -0
  67. data/docs/components/schema-calendar.ru.md +84 -0
  68. data/docs/components/schema-records.md +168 -0
  69. data/docs/components/schema-records.ru.md +168 -0
  70. data/docs/components/signup.md +196 -0
  71. data/docs/components/signup.ru.md +196 -0
  72. data/docs/components/slug-flow.md +97 -0
  73. data/docs/components/slug-flow.ru.md +59 -0
  74. data/docs/components/stockee.md +21 -0
  75. data/docs/components/stockee.ru.md +21 -0
  76. data/docs/components/text-views.md +64 -0
  77. data/docs/components/text-views.ru.md +57 -0
  78. data/docs/components/theme.md +214 -0
  79. data/docs/components/theme.ru.md +214 -0
  80. data/docs/components/tooltip.md +37 -0
  81. data/docs/components/tooltip.ru.md +30 -0
  82. data/docs/components/validation.md +153 -0
  83. data/docs/components/validation.ru.md +154 -0
  84. data/docs/components.md +31 -0
  85. data/docs/components.ru.md +31 -0
  86. data/docs/controller-names.md +23 -0
  87. data/docs/controller-names.ru.md +23 -0
  88. data/docs/examples/dneslov-frontend.md +38 -0
  89. data/docs/examples/dneslov-frontend.ru.md +39 -0
  90. data/docs/examples/dneslov-frontend.yaml +266 -0
  91. data/docs/frontend.md +316 -0
  92. data/docs/frontend.ru.md +332 -0
  93. data/docs/migrations/component-configuration.md +48 -0
  94. data/docs/migrations/component-configuration.ru.md +40 -0
  95. data/docs/migrations/component-shell-proposal.md +108 -0
  96. data/docs/migrations/component-shell-proposal.ru.md +150 -0
  97. data/docs/migrations/theme-layout.md +83 -0
  98. data/docs/migrations/theme-layout.ru.md +97 -0
  99. data/docs/reference.md +45 -0
  100. data/docs/reference.ru.md +1763 -0
  101. data/docs/resources.md +348 -0
  102. data/docs/resources.ru.md +349 -0
  103. data/docs/tasks/DNE-542.md +11 -0
  104. data/docs/tasks/DNE-566.md +8 -0
  105. data/docs/tasks/chip-segments.md +54 -0
  106. data/docs/tasks/configured-profile.md +73 -0
  107. data/docs/tasks/frontend/auth-form.md +7 -0
  108. data/docs/tasks/frontend/avatar.md +5 -0
  109. data/docs/tasks/frontend/component-removal.md +11 -0
  110. data/docs/tasks/frontend/dynamic-field.md +6 -0
  111. data/docs/tasks/frontend/field-caption.md +38 -0
  112. data/docs/tasks/frontend/form-core.md +65 -0
  113. data/docs/tasks/frontend/form-field-context.md +16 -0
  114. data/docs/tasks/frontend/form-session-renewal.md +58 -0
  115. data/docs/tasks/frontend/frontend-components.md +7 -0
  116. data/docs/tasks/frontend/frontend-docs.md +6 -0
  117. data/docs/tasks/frontend/frontend-layout.md +13 -0
  118. data/docs/tasks/frontend/frontend-methods.md +15 -0
  119. data/docs/tasks/frontend/frontend-other.md +13 -0
  120. data/docs/tasks/frontend/frontend-services.md +7 -0
  121. data/docs/tasks/frontend/fusion.md +22 -0
  122. data/docs/tasks/frontend/heading-core.md +5 -0
  123. data/docs/tasks/frontend/i18n-scope.md +37 -0
  124. data/docs/tasks/frontend/index-runtime.md +48 -0
  125. data/docs/tasks/frontend/inline-form.md +7 -0
  126. data/docs/tasks/frontend/intro-core.md +11 -0
  127. data/docs/tasks/frontend/login.md +8 -0
  128. data/docs/tasks/frontend/menu-branch.md +5 -0
  129. data/docs/tasks/frontend/paginator.md +7 -0
  130. data/docs/tasks/frontend/records-core.md +35 -0
  131. data/docs/tasks/frontend/resource-source-core.md +12 -0
  132. data/docs/tasks/frontend/signup.md +8 -0
  133. data/docs/tasks/frontend/span-body.md +16 -0
  134. data/docs/tasks/frontend/text-commonee.md +48 -0
  135. data/docs/tasks/frontend/theme-field.md +31 -0
  136. data/docs/tasks/frontend/theme-menu.md +8 -0
  137. data/docs/tasks/frontend/theme-settings.md +10 -0
  138. data/docs/tasks/frontend/view-content-core.md +12 -0
  139. data/docs/tasks/frontend/view-source-core.md +12 -0
  140. data/docs/tasks/ruby-extension-compatibility.ru.md +74 -0
  141. data/docs/tasks/todo-code-climate.md +8 -0
  142. data/docs/tasks/todo-compatibility.md +50 -0
  143. data/docs/tasks/todo-reek.md +5 -0
  144. data/docs/tasks/todo-yard-inch.md +7 -0
  145. data/eslint.config.mjs +15 -0
  146. data/exe/tiun +1 -0
  147. data/gemfiles/rails_7_0.gemfile +16 -0
  148. data/gemfiles/rails_7_2.gemfile +17 -0
  149. data/lib/config/locale/browser.en.yml +43 -0
  150. data/lib/config/locale/browser.ru.yml +35 -0
  151. data/lib/config/locale/confirmation.en.yml +16 -0
  152. data/lib/config/locale/confirmation.ru.yml +16 -0
  153. data/lib/config/locale/errors.en.yml +57 -0
  154. data/lib/config/locale/errors.ru.yml +47 -0
  155. data/lib/config/locale/form_delay.en.yml +11 -0
  156. data/lib/config/locale/form_delay.ru.yml +11 -0
  157. data/lib/config/locale/recovery.en.yml +14 -0
  158. data/lib/config/locale/ru.yml +269 -6
  159. data/lib/config/routes.rb +5 -11
  160. data/lib/tasks/tiun/translations.rake +12 -0
  161. data/lib/tiun/actor/validate.rb +3 -2
  162. data/lib/tiun/actor.rb +13 -10
  163. data/lib/tiun/api_not_found.rb +16 -0
  164. data/lib/tiun/attributes.rb +8 -7
  165. data/lib/tiun/auth/attribute_models.rb +32 -0
  166. data/lib/tiun/auth/controller/discord.rb +26 -0
  167. data/lib/tiun/auth/controller/facebook.rb +62 -0
  168. data/lib/tiun/auth/controller/github.rb +37 -0
  169. data/lib/tiun/auth/controller/kakao.rb +33 -0
  170. data/lib/tiun/auth/controller/oauth.rb +167 -0
  171. data/lib/tiun/auth/controller/ok.rb +8 -0
  172. data/lib/tiun/auth/controller/telegram.rb +188 -0
  173. data/lib/tiun/auth/controller/vk.rb +85 -0
  174. data/lib/tiun/auth/controller/wechat.rb +58 -0
  175. data/lib/tiun/auth/controller/weibo.rb +28 -0
  176. data/lib/tiun/auth/controller.rb +467 -150
  177. data/lib/tiun/auth/json_session.rb +19 -0
  178. data/lib/tiun/auth/token_identity.rb +46 -0
  179. data/lib/tiun/auth/user_identity.rb +27 -0
  180. data/lib/tiun/auth/views/oauth_address.html.erb +23 -0
  181. data/lib/tiun/auth.rb +184 -45
  182. data/lib/tiun/carrier_wave_store.rb +59 -0
  183. data/lib/tiun/cli.rb +52 -32
  184. data/lib/tiun/concern/resources.rb +85 -0
  185. data/lib/tiun/config_source.rb +52 -0
  186. data/lib/tiun/content_range.rb +123 -0
  187. data/lib/tiun/context/merge.rb +117 -0
  188. data/lib/tiun/context.rb +39 -0
  189. data/lib/tiun/controller/auth/identity.rb +260 -0
  190. data/lib/tiun/controller/auth/registration.rb +46 -0
  191. data/lib/tiun/controller/auth.rb +198 -0
  192. data/lib/tiun/controller/auto.rb.erb +10 -0
  193. data/lib/tiun/controller/base/actions.rb +156 -0
  194. data/lib/tiun/controller/base/assignment.rb +101 -0
  195. data/lib/tiun/controller/base/parameters.rb +198 -0
  196. data/lib/tiun/controller/base/params.rb +166 -0
  197. data/lib/tiun/controller/base/records.rb +107 -0
  198. data/lib/tiun/controller/base/representation.rb +108 -0
  199. data/lib/tiun/controller/base/scopes.rb +132 -0
  200. data/lib/tiun/controller/base.rb +52 -0
  201. data/lib/tiun/controller/component_assets.rb +96 -0
  202. data/lib/tiun/controller/meta.rb +248 -0
  203. data/lib/tiun/controller/translations.rb +22 -0
  204. data/lib/tiun/controller.rb +13 -0
  205. data/lib/tiun/core/boot.rb +210 -0
  206. data/lib/tiun/core/contexts.rb +53 -0
  207. data/lib/tiun/core/controller_contexts.rb +42 -0
  208. data/lib/tiun/core/defaults.rb +215 -0
  209. data/lib/tiun/core/evaluation.rb +105 -0
  210. data/lib/tiun/core/field_attributes.rb +78 -0
  211. data/lib/tiun/core/files.rb +153 -0
  212. data/lib/tiun/core/generation.rb +234 -0
  213. data/lib/tiun/core/methods.rb +104 -0
  214. data/lib/tiun/core/names.rb +140 -0
  215. data/lib/tiun/core/registry.rb +97 -0
  216. data/lib/tiun/core/reloading.rb +77 -0
  217. data/lib/tiun/core/resources.rb +308 -0
  218. data/lib/tiun/core/routing/forward.rb +206 -0
  219. data/lib/tiun/core/routing.rb +323 -0
  220. data/lib/tiun/core/types.rb +88 -0
  221. data/lib/tiun/core.rb +26 -0
  222. data/lib/tiun/core_helper.rb +85 -13
  223. data/lib/tiun/engine.rb +64 -20
  224. data/lib/tiun/error_handling.rb +121 -0
  225. data/lib/tiun/hooks.rb +131 -0
  226. data/lib/tiun/mailer/confirmation.rb +45 -0
  227. data/lib/tiun/mailer/recovery.rb +16 -0
  228. data/lib/tiun/migration.rb +72 -50
  229. data/lib/tiun/mixins.rb +128 -19
  230. data/lib/tiun/model/account/identity.rb +93 -0
  231. data/lib/tiun/model/account.rb +256 -7
  232. data/lib/tiun/model/auth/bcrypt.rb +47 -0
  233. data/lib/tiun/model/auth.rb +164 -36
  234. data/lib/tiun/model/auto.rb.erb +12 -0
  235. data/lib/tiun/model/me.rb +214 -0
  236. data/lib/tiun/model/settings.rb +193 -0
  237. data/lib/tiun/model/token/recovery.rb +48 -0
  238. data/lib/tiun/model/token.rb +37 -3
  239. data/lib/tiun/model.rb +82 -69
  240. data/lib/tiun/notification/service.rb +18 -0
  241. data/lib/tiun/notification.rb +6 -0
  242. data/lib/tiun/policy/default.rb +7 -0
  243. data/lib/tiun/policy.rb +84 -8
  244. data/lib/tiun/proceed/allowed_errors.rb +217 -0
  245. data/lib/tiun/proceed/auth.rb +50 -0
  246. data/lib/tiun/proceed/description.rb +89 -0
  247. data/lib/tiun/proceed/enums.rb +225 -0
  248. data/lib/tiun/proceed/hooks.rb +51 -0
  249. data/lib/tiun/proceed/pass_over_paths.rb +40 -0
  250. data/lib/tiun/proceed/policy.rb +172 -0
  251. data/lib/tiun/proceed/registration.rb +69 -0
  252. data/lib/tiun/proceed/schemas/component_nodes.rb +436 -0
  253. data/lib/tiun/proceed/schemas/constants.rb +117 -0
  254. data/lib/tiun/proceed/schemas/content.rb +68 -0
  255. data/lib/tiun/proceed/schemas/definitions.rb +181 -0
  256. data/lib/tiun/proceed/schemas/dictionary.rb +144 -0
  257. data/lib/tiun/proceed/schemas/fields.rb +182 -0
  258. data/lib/tiun/proceed/schemas/models.rb +50 -0
  259. data/lib/tiun/proceed/schemas/spans.rb +87 -0
  260. data/lib/tiun/proceed/schemas/values.rb +94 -0
  261. data/lib/tiun/proceed/schemas/view_paths.rb +86 -0
  262. data/lib/tiun/proceed/schemas/view_readiness.rb +51 -0
  263. data/lib/tiun/proceed/schemas/views.rb +192 -0
  264. data/lib/tiun/proceed/schemas.rb +137 -0
  265. data/lib/tiun/proceed/services.rb +79 -0
  266. data/lib/tiun/proceed/token_lifetimes.rb +49 -0
  267. data/lib/tiun/proceed/translations.rb +45 -0
  268. data/lib/tiun/proceed/versions.rb +315 -0
  269. data/lib/tiun/proceed.rb +23 -0
  270. data/lib/tiun/router.rb +40 -0
  271. data/lib/tiun/routes/mounts.rb +280 -0
  272. data/lib/tiun/routes.rb +150 -0
  273. data/lib/tiun/service/auto.rb.erb +5 -0
  274. data/lib/tiun/service/email_confirmation.rb +108 -0
  275. data/lib/tiun/service/job.rb +16 -0
  276. data/lib/tiun/service.rb +82 -0
  277. data/lib/tiun/services/translation.rb +297 -0
  278. data/lib/tiun/themes.rb +98 -0
  279. data/lib/tiun/translations/database.rb +72 -0
  280. data/lib/tiun/translations.rb +279 -0
  281. data/lib/tiun/version.rb +3 -3
  282. data/lib/tiun.rb +79 -486
  283. data/package-lock.json +4836 -0
  284. data/package.json +103 -0
  285. data/scripts/build-application.mjs +39 -0
  286. data/scripts/build-css.mjs +21 -0
  287. data/scripts/ci-badges.mjs +54 -0
  288. data/scripts/ci-badges.test.mjs +46 -0
  289. data/scripts/ci-coverage.mjs +26 -0
  290. data/scripts/ci-quality.mjs +80 -0
  291. data/scripts/ci-quality.sh +21 -0
  292. data/scripts/ci-quality.test.mjs +59 -0
  293. data/scripts/clean.mjs +3 -0
  294. data/scripts/publish-ci-badges.sh +45 -0
  295. data/src/auth/configuration.ts +50 -0
  296. data/src/browser/contracts.js +7 -0
  297. data/src/browser/mount.d.ts +26 -0
  298. data/src/browser/mount.jsx +1 -0
  299. data/src/browser/styles.js +17 -0
  300. data/src/browser/tiun.scss +23 -0
  301. data/src/browser/tiun.ts +1 -0
  302. data/src/calendar/configuration.ts +98 -0
  303. data/src/components/Avatar.tsx +45 -0
  304. data/src/components/Calendar.tsx +441 -0
  305. data/src/components/CatchWrapper.tsx +55 -0
  306. data/src/components/Chip.tsx +267 -0
  307. data/src/components/Column.tsx +13 -0
  308. data/src/components/Component.tsx +1042 -0
  309. data/src/components/Enum.tsx +142 -0
  310. data/src/components/Figure.tsx +11 -0
  311. data/src/components/FlexText.tsx +101 -0
  312. data/src/components/Footer.tsx +13 -0
  313. data/src/components/Grid.tsx +36 -0
  314. data/src/components/Heading.tsx +64 -0
  315. data/src/components/Image.tsx +179 -0
  316. data/src/components/Index.tsx +560 -0
  317. data/src/components/Intro.tsx +536 -0
  318. data/src/components/Loader.tsx +118 -0
  319. data/src/components/Lorem.tsx +385 -0
  320. data/src/components/Markdown.d.ts +17 -0
  321. data/src/components/Markdown.jsx +118 -0
  322. data/src/components/Menu.tsx +50 -0
  323. data/src/components/Modal.tsx +150 -0
  324. data/src/components/Paginator.tsx +271 -0
  325. data/src/components/Player.tsx +269 -0
  326. data/src/components/Records.tsx +1090 -0
  327. data/src/components/Row.tsx +193 -0
  328. data/src/components/Span.tsx +122 -0
  329. data/src/components/Step.tsx +19 -0
  330. data/src/components/Stockee.tsx +50 -0
  331. data/src/components/Toast.tsx +125 -0
  332. data/src/components/Tooltip.tsx +214 -0
  333. data/src/components/View.tsx +278 -0
  334. data/src/components/_palette.scss +26 -0
  335. data/src/components/calendar-browser.scss +143 -0
  336. data/src/components/calendar.scss +217 -0
  337. data/src/components/chip-browser.scss +270 -0
  338. data/src/components/chips.scss +95 -0
  339. data/src/components/column.scss +4 -0
  340. data/src/components/dashboard-browser.scss +81 -0
  341. data/src/components/dashboard.scss +117 -0
  342. data/src/components/description-browser.scss +112 -0
  343. data/src/components/document.scss +43 -0
  344. data/src/components/enum-browser.scss +33 -0
  345. data/src/components/enums.scss +56 -0
  346. data/src/components/footer.scss +51 -0
  347. data/src/components/form/ActionButton.tsx +66 -0
  348. data/src/components/form/Attachment.tsx +200 -0
  349. data/src/components/form/Block.tsx +55 -0
  350. data/src/components/form/BooleanBox.tsx +58 -0
  351. data/src/components/form/Collection.tsx +89 -0
  352. data/src/components/form/DynamicInput.tsx +806 -0
  353. data/src/components/form/ErrorSpan.tsx +17 -0
  354. data/src/components/form/ExternalField.tsx +554 -0
  355. data/src/components/form/FieldCaption.tsx +35 -0
  356. data/src/components/form/Form.tsx +407 -0
  357. data/src/components/form/HiddenField.tsx +10 -0
  358. data/src/components/form/JsonEditor.tsx +443 -0
  359. data/src/components/form/Login.tsx +387 -0
  360. data/src/components/form/NumberField.tsx +75 -0
  361. data/src/components/form/Pressee.tsx +101 -0
  362. data/src/components/form/RtferField.tsx +94 -0
  363. data/src/components/form/SelectField.tsx +73 -0
  364. data/src/components/form/SlugFlow.tsx +296 -0
  365. data/src/components/form/TextArea.tsx +5 -0
  366. data/src/components/form/TextField.tsx +6 -0
  367. data/src/components/form/Wye.tsx +67 -0
  368. data/src/components/form/auth.scss +280 -0
  369. data/src/components/form/changes.ts +239 -0
  370. data/src/components/form/context.ts +31 -0
  371. data/src/components/form/createForm.tsx +109 -0
  372. data/src/components/form/dynamic-field.scss +20 -0
  373. data/src/components/form/dynamicMatching.ts +44 -0
  374. data/src/components/form/form-browser.scss +106 -0
  375. data/src/components/form/forms.scss +1571 -0
  376. data/src/components/form/formsLib.ts +76 -0
  377. data/src/components/form/identity.ts +10 -0
  378. data/src/components/form/input.scss +37 -0
  379. data/src/components/form/layout.ts +72 -0
  380. data/src/components/form/login-browser.scss +30 -0
  381. data/src/components/form/render.tsx +94 -0
  382. data/src/components/form/resourceFields.ts +87 -0
  383. data/src/components/form/types.ts +216 -0
  384. data/src/components/form/values.ts +266 -0
  385. data/src/components/image.scss +70 -0
  386. data/src/components/intro-browser.scss +106 -0
  387. data/src/components/intro.scss +158 -0
  388. data/src/components/loader.scss +86 -0
  389. data/src/components/menu.scss +24 -0
  390. data/src/components/player.scss +48 -0
  391. data/src/components/records-browser.scss +62 -0
  392. data/src/components/records.scss +185 -0
  393. data/src/components/row.scss +31 -0
  394. data/src/components/stockee.scss +26 -0
  395. data/src/components/theme-palettes/compat.scss +15 -0
  396. data/src/components/theme-palettes/dark.scss +238 -0
  397. data/src/components/theme-palettes/light.scss +21 -0
  398. data/src/components/theme.scss +34 -0
  399. data/src/components/tiun_core.scss +9 -0
  400. data/src/components/toast.scss +63 -0
  401. data/src/components/tooltip.scss +22 -0
  402. data/src/components/view-browser.scss +321 -0
  403. data/src/components/view-controls.scss +385 -0
  404. data/src/concern/application.ts +57 -0
  405. data/src/concern/calendarViewProps.ts +28 -0
  406. data/src/concern/chipViewProps.ts +60 -0
  407. data/src/concern/documentHead.ts +66 -0
  408. data/src/concern/i18n.ts +70 -0
  409. data/src/concern/resourceRequest.ts +25 -0
  410. data/src/concern/schemaText.ts +6 -0
  411. data/src/concern/slugFlowProps.ts +76 -0
  412. data/src/concern/spanOptions.ts +37 -0
  413. data/src/concern/spansViewProps.tsx +116 -0
  414. data/src/concern/useFormAccess.ts +324 -0
  415. data/src/concern/useRecordsResource.ts +62 -0
  416. data/src/config/application.ts +57 -0
  417. data/src/config/componentDefaults.ts +106 -0
  418. data/src/config/components.ts +436 -0
  419. data/src/config/names.ts +72 -0
  420. data/src/config/records.ts +34 -0
  421. data/src/decorators/buttonBehaviours.tsx +46 -0
  422. data/src/decorators/configuration.ts +104 -0
  423. data/src/decorators/validation.ts +52 -0
  424. data/src/decorators/withAppearance.tsx +45 -0
  425. data/src/decorators/withCaption.tsx +21 -0
  426. data/src/decorators/withChildren.tsx +31 -0
  427. data/src/decorators/withClose.scss +37 -0
  428. data/src/decorators/withClose.tsx +44 -0
  429. data/src/decorators/withColumn.tsx +111 -0
  430. data/src/decorators/withDiscordAuth.tsx +4 -0
  431. data/src/decorators/withExternalAuth.tsx +50 -0
  432. data/src/decorators/withFacebookAuth.tsx +4 -0
  433. data/src/decorators/withField.tsx +94 -0
  434. data/src/decorators/withForm.tsx +371 -0
  435. data/src/decorators/withGithubAuth.tsx +4 -0
  436. data/src/decorators/withKakaoAuth.tsx +4 -0
  437. data/src/decorators/withMenuBranch.scss +45 -0
  438. data/src/decorators/withMenuBranch.tsx +109 -0
  439. data/src/decorators/withOkAuth.tsx +4 -0
  440. data/src/decorators/withPlayerList.tsx +77 -0
  441. data/src/decorators/withQuickLinkMark.ts +57 -0
  442. data/src/decorators/withRecordForm.tsx +561 -0
  443. data/src/decorators/withRequestActivity.scss +7 -0
  444. data/src/decorators/withRequestActivity.tsx +21 -0
  445. data/src/decorators/withRouter.tsx +395 -0
  446. data/src/decorators/withRouterLink.tsx +54 -0
  447. data/src/decorators/withTelegramAuth.tsx +4 -0
  448. data/src/decorators/withTextControl.tsx +194 -0
  449. data/src/decorators/withUnique.scss +39 -0
  450. data/src/decorators/withUnique.tsx +172 -0
  451. data/src/decorators/withUnsavedChanges.scss +39 -0
  452. data/src/decorators/withUnsavedChanges.tsx +312 -0
  453. data/src/decorators/withValidation.ts +38 -0
  454. data/src/decorators/withVkAuth.tsx +4 -0
  455. data/src/decorators/withWechatAuth.tsx +4 -0
  456. data/src/decorators/withWeiboAuth.tsx +4 -0
  457. data/src/intro/config.ts +72 -0
  458. data/src/intro/position.ts +70 -0
  459. data/src/layout/units.ts +21 -0
  460. data/src/records/types.ts +67 -0
  461. data/src/routing/nativePaths.ts +16 -0
  462. data/src/routing/routes.ts +337 -0
  463. data/src/schema/Schema.ts +2044 -0
  464. data/src/schema/dates.ts +17 -0
  465. data/src/schema.ts +274 -0
  466. data/src/services/Meta.ts +64 -0
  467. data/src/services/Resource.ts +480 -0
  468. data/src/services/Stock.ts +156 -0
  469. data/src/services/browser/requestActivity.d.ts +7 -0
  470. data/src/services/browser/requestActivity.js +119 -0
  471. data/src/services/browser/slugColor.js +13 -0
  472. data/src/services/calendar/clock.ts +169 -0
  473. data/src/services/calendar/dates.ts +127 -0
  474. data/src/services/calendar/daylight.ts +328 -0
  475. data/src/services/calendar/useCalendarDaylight.ts +76 -0
  476. data/src/services/calendar/utcTimeSource.ts +41 -0
  477. data/src/services/enumLookup.ts +96 -0
  478. data/src/services/form/blankCondition.ts +61 -0
  479. data/src/services/form/hoardValidation.ts +84 -0
  480. data/src/services/i18n/I18n.ts +227 -0
  481. data/src/services/i18n/messages.ts +185 -0
  482. data/src/services/load.ts +60 -0
  483. data/src/services/methods/aboutData.d.ts +9 -0
  484. data/src/services/methods/aboutData.js +32 -0
  485. data/src/services/methods/calendarChoices.d.ts +1 -0
  486. data/src/services/methods/calendarChoices.js +9 -0
  487. data/src/services/methods/eventDates.ts +96 -0
  488. data/src/services/methods/forms.ts +22 -0
  489. data/src/services/methods/mount.jsx +34 -0
  490. data/src/services/methods/paschal.ts +45 -0
  491. data/src/services/methods/prepared.ts +193 -0
  492. data/src/services/methods/query.ts +30 -0
  493. data/src/services/methods/registry.ts +22 -0
  494. data/src/services/methods/resolveReadResource.ts +57 -0
  495. data/src/services/methods.ts +156 -0
  496. data/src/services/records/range.ts +39 -0
  497. data/src/services/records/resource.ts +90 -0
  498. data/src/services/records/useRecordPages.ts +286 -0
  499. data/src/services/session/renewal.ts +457 -0
  500. data/src/services/textLink.ts +11 -0
  501. data/src/services/timer.ts +25 -0
  502. data/src/services/useAppearance.ts +507 -0
  503. data/src/services/useSwitch.ts +152 -0
  504. data/src/theme/cache.ts +88 -0
  505. data/src/theme/configuration.ts +275 -0
  506. data/src/theme/context.ts +48 -0
  507. data/src/theme/resource.ts +106 -0
  508. data/tiun.gemspec +53 -45
  509. data/tools/rubocop/compact_block_braces.rb +39 -0
  510. data/tools/rubocop/i18n_decorators.rb +15 -0
  511. data/tools/rubocop/spacing.rb +96 -0
  512. data/tsconfig.build.json +26 -0
  513. data/tsconfig.json +27 -0
  514. metadata +628 -72
  515. data/.rspec +0 -3
  516. data/.travis.yml +0 -7
  517. data/lib/tiun/autocontroller.rb.erb +0 -20
  518. data/lib/tiun/autolistserializer.rb.erb +0 -9
  519. data/lib/tiun/automodel.rb.erb +0 -10
  520. data/lib/tiun/autoserializer.rb.erb +0 -9
  521. data/lib/tiun/base.rb +0 -405
  522. data/lib/tiun/core_controller.rb +0 -6
  523. data/lib/tiun/list_serializer.rb +0 -20
  524. data/lib/tiun/meta_controller.rb +0 -13
  525. data/lib/tiun/serializer.rb +0 -31
  526. /data/lib/tiun/{automigration.rb.erb → migration/auto.rb.erb} +0 -0
  527. /data/lib/tiun/{autopolicy.rb.erb → policy/auto.rb.erb} +0 -0
@@ -0,0 +1,387 @@
1
+ import * as React from "react";
2
+ import type { LoginConfiguration, LoginMode } from "../../auth/configuration.js";
3
+ import { authResource, isObject } from "../../auth/configuration.js";
4
+ import { mergeData } from "../../services/methods/forms.js";
5
+ import { deserializedHash, metaToScheme, valueAt, valueToObject } from "./values.js";
6
+ import { externalAuthProviders, useExternalAuth } from "../../decorators/withExternalAuth.js";
7
+ import { useEffect, useRef, useState } from "react";
8
+ import type { AxiosInstance } from "axios";
9
+ import type { FormData } from "./types.js";
10
+ import { RecordFormModal } from "../../decorators/withRecordForm.js";
11
+ import { Schema } from "../../schema/Schema.js";
12
+ import type { ServerMeta } from "../../services/Meta.js";
13
+ import type { SessionUser } from "../../services/session/renewal.js";
14
+ import { Stock } from "../../services/Stock.js";
15
+ import { Stockee } from "../Stockee.js";
16
+ import { Toast } from "../Toast.js";
17
+ import axios from "axios";
18
+ import { findResource } from "../../services/Resource.js";
19
+ import { useI18n } from "../../concern/i18n.js";
20
+
21
+ const EMPTY_FORM = Object.freeze({}),
22
+ SESSION_PATH = "/api/v1/session.json";
23
+
24
+ /**
25
+ * Inputs for account controls embedded in an application that manages its own session.
26
+ * The component calls the host when sign-in succeeds or sign-out completes.
27
+ */
28
+ export interface LoginProps<User extends SessionUser> {
29
+ /** Current user, or null for a guest. */
30
+ readonly user: User | null;
31
+ /** Prepared metadata containing named forms and resources. */
32
+ readonly meta: ServerMeta;
33
+ /** Named operations, session resource and account navigation settings. */
34
+ readonly configuration?: LoginConfiguration;
35
+ /** Set to false to hold submission until the metadata is ready. */
36
+ readonly ready?: boolean;
37
+ /** HTTP client for requests. Defaults to axios. */
38
+ readonly client?: AxiosInstance;
39
+ /** Receives the user record with session data after a valid response. */
40
+ readonly onLogin: (user: User) => void | Promise<void>;
41
+ /** Clears the user in the host after sign-out succeeds. */
42
+ readonly onLogout: () => void | Promise<void>;
43
+ /** Browser path for the signed-in user link. */
44
+ readonly userPath?: string;
45
+ /** Opens the configured user view through host navigation. */
46
+ readonly onNavigate?: (view: string) => void;
47
+ /** Additional CSS class for the form dialog. */
48
+ readonly modalClassName?: string;
49
+ /** Controlled dialog mode. Null closes it. Omit it to keep local state. */
50
+ readonly activeForm?: LoginMode | null;
51
+ /** Receives the new dialog mode, or null when closing it. */
52
+ readonly onFormChange?: (form: LoginMode | null) => void;
53
+ }
54
+
55
+ /**
56
+ * Renders the account controls and form dialogs. For a guest, the decorated login dialog shows links for its enabled services.
57
+ * @param props Session, form metadata and callbacks provided by the host.
58
+ * @returns Account controls with the active dialog, if one was opened.
59
+ */
60
+ export function Login<User extends SessionUser>(props: LoginProps<User>) {
61
+ const authLocale = useI18n(),
62
+ externalAuth = useExternalAuth(),
63
+ { t } = authLocale,
64
+ client = props.client ?? axios,
65
+ config = props.configuration ?? {},
66
+ [localMode, setLocalMode] = useState<LoginMode | null>(null),
67
+ [notice, setNotice] = useState(""),
68
+ mode = props.user ? null : props.activeForm === undefined ? localMode : props.activeForm,
69
+ setMode = props.onFormChange ?? setLocalMode,
70
+ [pending, setPending] = useState(false),
71
+ transportAbortRef = useRef<AbortController | null>(null),
72
+ userKey = String(props.user?.id ?? props.user?.uid ?? ""),
73
+ versionRef = useRef(0),
74
+ workingRef = useRef(false);
75
+
76
+ useEffect(() => {
77
+ versionRef.current++;
78
+ transportAbortRef.current?.abort();
79
+ workingRef.current = false;
80
+ setLocalMode(null);
81
+ setPending(false);
82
+ setNotice("");
83
+ return () => {
84
+ versionRef.current++;
85
+ transportAbortRef.current?.abort();
86
+ };
87
+ }, [userKey]);
88
+
89
+ useEffect(() => {
90
+ if (props.activeForm !== undefined) {
91
+ versionRef.current++;
92
+ transportAbortRef.current?.abort();
93
+ }
94
+ }, [props.activeForm]);
95
+
96
+ const accountSchema = new Schema(props.meta, { i18n: authLocale }),
97
+ configuredMode = mode ? config.modes?.[mode] : undefined,
98
+ formName = mode === "recover" ? config.modes?.login?.form : configuredMode?.form,
99
+ modeFields = configuredMode && formName ? accountSchema.formFields(formName) : undefined,
100
+ primaryField = modeFields && Object.keys(modeFields)[0];
101
+ let fields = modeFields;
102
+ if (mode === "recover") {
103
+ const identifierField = primaryField && modeFields?.[primaryField];
104
+ fields =
105
+ primaryField && identifierField && identifierField.inputType !== "password"
106
+ ? { [primaryField]: identifierField }
107
+ : undefined;
108
+ }
109
+ const bootstrappedFormRef = useRef<{ identity: string; data: FormData; identifier?: string } | null>(null),
110
+ formIdentity = `${userKey}:${mode}`;
111
+ if (!configuredMode) {
112
+ bootstrappedFormRef.current = null;
113
+ } else if (bootstrappedFormRef.current?.identity !== formIdentity) {
114
+ const capturedIdentifier =
115
+ mode === "recover" && bootstrappedFormRef.current?.identity === `${userKey}:login`
116
+ ? bootstrappedFormRef.current.identifier
117
+ : undefined,
118
+ defaultValues = configuredMode.initial ?? EMPTY_FORM;
119
+ bootstrappedFormRef.current = {
120
+ data:
121
+ primaryField && capturedIdentifier !== undefined
122
+ ? mergeData(defaultValues, valueToObject(primaryField, capturedIdentifier))
123
+ : defaultValues,
124
+ identity: formIdentity,
125
+ };
126
+ }
127
+
128
+ const label = (value: string | undefined, fallback: string) => t((value || fallback).replace(/^:/, ""));
129
+
130
+ function close(): void {
131
+ versionRef.current++;
132
+ transportAbortRef.current?.abort();
133
+ setMode(null);
134
+ }
135
+
136
+ /** Переносит первое поле входа при переходе к восстановлению. Аргументы: новый режим и нажатие в текущем диалоге; результат: void. */
137
+ function selectMode(value: LoginMode, event: React.MouseEvent<HTMLButtonElement>): void {
138
+ if (value === mode) {
139
+ return;
140
+ }
141
+ if (
142
+ mode === "login" &&
143
+ value === "recover" &&
144
+ primaryField &&
145
+ fields?.[primaryField]?.inputType !== "password" &&
146
+ bootstrappedFormRef.current
147
+ ) {
148
+ const control = event.currentTarget.closest("dialog")?.querySelector("form")?.elements.namedItem(primaryField);
149
+ if (control && "value" in control && typeof control.value === "string") {
150
+ bootstrappedFormRef.current.identifier = control.value;
151
+ }
152
+ }
153
+ versionRef.current++;
154
+ transportAbortRef.current?.abort();
155
+ setMode(value);
156
+ }
157
+
158
+ /**
159
+ * Signs out of the active session and updates the host after the server confirms it.
160
+ * @returns Completion of the sign-out request.
161
+ */
162
+ async function logout(): Promise<void> {
163
+ if (workingRef.current) {
164
+ return;
165
+ }
166
+ workingRef.current = true;
167
+ setPending(true);
168
+ setNotice("");
169
+ const activeRevision = versionRef.current,
170
+ controller = new AbortController();
171
+ transportAbortRef.current = controller;
172
+ try {
173
+ await client.delete(authResource(props.meta, config.session_resource, "delete", SESSION_PATH), {
174
+ signal: controller.signal,
175
+ });
176
+ if (!controller.signal.aborted && activeRevision === versionRef.current) {
177
+ await props.onLogout();
178
+ }
179
+ } catch {
180
+ if (!controller.signal.aborted && activeRevision === versionRef.current) {
181
+ setNotice(t("tiun.components.login.errors.logout"));
182
+ }
183
+ } finally {
184
+ if (!controller.signal.aborted && activeRevision === versionRef.current) {
185
+ workingRef.current = false;
186
+ setPending(false);
187
+ }
188
+ }
189
+ }
190
+
191
+ const feedback = notice ? (
192
+ <Toast
193
+ message={notice}
194
+ onClose={() => {
195
+ setNotice("");
196
+ }}
197
+ />
198
+ ) : null,
199
+ /**
200
+ * Selects the default title key for the active authentication form.
201
+ * @param value The authentication mode or null before a form is opened.
202
+ * @returns The title's translation key.
203
+ */
204
+ formTitle = (value: LoginMode | null): string => {
205
+ if (typeof props.activeForm !== "undefined" && value === "signup") {
206
+ return "tiun.components.signup.title";
207
+ }
208
+ return `tiun.components.login.${value}`;
209
+ },
210
+ profileAvatar =
211
+ config.avatar_from && props.user ? accountSchema.value(config.avatar_from, props.user) : undefined,
212
+ profileAvatarSource =
213
+ typeof profileAvatar === "string" && /^(?:https?:\/\/|\/(?!\/))/.test(profileAvatar)
214
+ ? profileAvatar
215
+ : undefined;
216
+ return (
217
+ <div className="tiun-login" data-auth-owner={userKey}>
218
+ {feedback}
219
+ {props.user && (
220
+ <button type="button" className="tiun-auth-logout" disabled={pending} onClick={() => void logout()}>
221
+ {t("tiun.components.login.actions.logout")}
222
+ </button>
223
+ )}
224
+ {props.user ? (
225
+ <a
226
+ className="tiun-auth-avatar"
227
+ href={props.userPath}
228
+ aria-label={t("tiun.components.login.profile")}
229
+ onClick={(event) => {
230
+ if (
231
+ config.user_view &&
232
+ props.onNavigate &&
233
+ !event.ctrlKey &&
234
+ !event.metaKey &&
235
+ !event.shiftKey &&
236
+ !event.altKey &&
237
+ event.button === 0
238
+ ) {
239
+ event.preventDefault();
240
+ props.onNavigate(config.user_view);
241
+ }
242
+ }}
243
+ >
244
+ {profileAvatarSource ? <img src={profileAvatarSource} alt="" /> : <Stockee asset={Stock.signedUser} />}
245
+ </a>
246
+ ) : (
247
+ <button
248
+ type="button"
249
+ className="tiun-auth-avatar"
250
+ aria-label={t("tiun.components.login.login")}
251
+ onClick={() => {
252
+ setMode("login");
253
+ }}
254
+ >
255
+ <Stockee asset={Stock.user} />
256
+ </button>
257
+ )}
258
+ <RecordFormModal
259
+ key={userKey}
260
+ formKey={formIdentity}
261
+ {...(props.modalClassName ? { className: props.modalClassName } : {})}
262
+ data={configuredMode ? bootstrappedFormRef.current!.data : null}
263
+ meta={{
264
+ close: t("tiun.components.login.close"),
265
+ create: label(configuredMode?.labels?.action, formTitle(mode)),
266
+ form: fields ?? {},
267
+ remoteName: configuredMode?.root ?? "account",
268
+ remoteNames: "",
269
+ update: "",
270
+ }}
271
+ ready={props.ready !== false && Boolean(fields)}
272
+ i18n={{ title: { create: label(configuredMode?.labels?.title, formTitle(mode)), update: "" } }}
273
+ onClose={close}
274
+ errorText={() => label(configuredMode?.labels?.errors?.request, "tiun.components.login.errors.request")}
275
+ beforeForm={
276
+ <div className="tiun-auth-modes">
277
+ {(["login", "signup", "recover"] as const)
278
+ .filter((value) => config.modes?.[value])
279
+ .map((value) => {
280
+ const caption = label(config.modes?.[value]?.labels?.title, formTitle(value));
281
+
282
+ return (
283
+ <button
284
+ key={value}
285
+ type="button"
286
+ aria-pressed={value === mode}
287
+ title={caption}
288
+ onClick={selectMode.bind(null, value)}
289
+ >
290
+ {caption}
291
+ </button>
292
+ );
293
+ })}
294
+ </div>
295
+ }
296
+ afterForm={
297
+ Boolean(externalAuth.length) &&
298
+ !props.user &&
299
+ mode === "login" && (
300
+ <div className="tiun-auth-providers">
301
+ {externalAuth.map((service) => {
302
+ const { name, stock } = externalAuthProviders[service];
303
+ return (
304
+ <a
305
+ key={service}
306
+ className={`tiun-auth-provider tiun-auth-${service}`}
307
+ href={`/auth/${service}`}
308
+ aria-label={name}
309
+ title={name}
310
+ data-tiun-native
311
+ >
312
+ <Stockee asset={stock} />
313
+ </a>
314
+ );
315
+ })}
316
+ </div>
317
+ )
318
+ }
319
+ onSubmitData={async (values) => {
320
+ if (!configuredMode) {
321
+ throw new Error("Auth mode unavailable");
322
+ }
323
+ const isRecovery = mode === "recover",
324
+ method = isRecovery ? "post" : (configuredMode.method ?? "post"),
325
+ path = authResource(
326
+ props.meta,
327
+ configuredMode.resource,
328
+ method,
329
+ isRecovery ? undefined : SESSION_PATH,
330
+ );
331
+ let uno: string | undefined;
332
+ if (isRecovery) {
333
+ const accountSession = findResource(props.meta, config.session_resource ?? "session"),
334
+ login = findResource(props.meta, config.modes?.login?.resource ?? "session");
335
+ if (path === SESSION_PATH || path === accountSession?.path || path === login?.path) {
336
+ throw new TypeError(t("tiun.components.login.errors.configuration"));
337
+ }
338
+ const value =
339
+ primaryField && fields
340
+ ? valueAt(deserializedHash(values, metaToScheme(fields)), primaryField)
341
+ : undefined;
342
+ if (typeof value !== "string" || !value.trim()) {
343
+ throw new TypeError(t("tiun.components.login.errors.configuration"));
344
+ }
345
+ uno = value;
346
+ }
347
+
348
+ const capturedRevision = versionRef.current,
349
+ controller = new AbortController();
350
+ transportAbortRef.current = controller;
351
+ const response = await client({
352
+ method,
353
+ signal: controller.signal,
354
+ url: path,
355
+ ...(isRecovery
356
+ ? { params: { uno } }
357
+ : { data: configuredMode.root ? { [configuredMode.root]: values } : values }),
358
+ });
359
+ if (controller.signal.aborted || capturedRevision !== versionRef.current) {
360
+ throw new axios.CanceledError();
361
+ }
362
+ if (isRecovery && response.data !== true) {
363
+ throw new Error(
364
+ label(configuredMode.labels?.errors?.request, "tiun.components.login.errors.request"),
365
+ );
366
+ }
367
+ if (mode === "login") {
368
+ if (
369
+ !isObject(response.data) ||
370
+ (response.data.id == null && response.data.uid == null) ||
371
+ !isObject(response.data.session_token) ||
372
+ typeof response.data.session_token.code !== "string" ||
373
+ !response.data.session_token.code
374
+ ) {
375
+ throw new Error("Invalid auth response");
376
+ }
377
+ await props.onLogin(response.data as User);
378
+ } else if (configuredMode.labels?.success) {
379
+ setNotice(label(configuredMode.labels?.success, ""));
380
+ }
381
+ setMode(null);
382
+ return response.data;
383
+ }}
384
+ />
385
+ </div>
386
+ );
387
+ }
@@ -0,0 +1,75 @@
1
+ import * as React from "react";
2
+ import { useEffect, useRef } from "react";
3
+ import { ErrorSpan } from "./ErrorSpan.js";
4
+ import { FieldCaption } from "./FieldCaption.js";
5
+ import type { FieldProps } from "./types.js";
6
+ import type { ReactElement } from "react";
7
+ import { displayClass } from "./values.js";
8
+ import { withValidation, type FieldValidation } from "../../decorators/withValidation.js";
9
+ import { nodeId } from "./identity.js";
10
+ import { useForm } from "./context.js";
11
+ import { useI18n } from "../../concern/i18n.js";
12
+ import { withField } from "../../decorators/withField.js";
13
+
14
+ /** Numeric field with configured storage/display scale; native range/step constraints remain active. */
15
+ function NumberFieldBase(props: FieldProps & FieldValidation): ReactElement {
16
+ const { t } = useI18n(),
17
+ { update } = useForm(),
18
+ input = useRef<HTMLInputElement>(null),
19
+ stableId = useRef<string | undefined>(undefined);
20
+ stableId.current ??= nodeId();
21
+ const id = props.id ?? stableId.current,
22
+ scale = props.displayScale && props.displayScale > 0 ? props.displayScale : 1,
23
+ scaledValue = typeof props.value === "number" && Number.isFinite(props.value) ? props.value * scale : "",
24
+ storedValue = props.value,
25
+ validationMessage =
26
+ storedValue == null || storedValue === ""
27
+ ? props.required
28
+ ? t("tiun.components.number.errors.required")
29
+ : ""
30
+ : typeof storedValue !== "number" || !Number.isFinite(storedValue)
31
+ ? t("tiun.components.number.errors.required")
32
+ : props.min !== undefined && storedValue < props.min
33
+ ? t("tiun.components.number.errors.min", { minimum: props.min * scale })
34
+ : props.max !== undefined && storedValue > props.max
35
+ ? t("tiun.components.number.errors.max", { maximum: props.max * scale })
36
+ : props.step &&
37
+ Math.abs(
38
+ (storedValue - (props.min ?? 0)) / props.step -
39
+ Math.round((storedValue - (props.min ?? 0)) / props.step),
40
+ ) > 1e-8
41
+ ? t("tiun.components.number.errors.step", { step: props.step * scale })
42
+ : "",
43
+ visibleError = props.disabled ? "" : props.validateField() || validationMessage;
44
+
45
+ useEffect(() => {
46
+ input.current?.setCustomValidity(visibleError);
47
+ }, [visibleError]);
48
+
49
+ return (
50
+ <div
51
+ className={`tiun-field tiun-number-field ${displayClass(props.display_scheme ?? "12")} ${props.wrapperClassName ?? ""}`}
52
+ >
53
+ <FieldCaption htmlFor={id}>{props.title ?? props.i18n?.title}</FieldCaption>
54
+ <input
55
+ ref={input}
56
+ id={id}
57
+ name={props.name}
58
+ type="number"
59
+ value={scaledValue}
60
+ required={props.required}
61
+ min={props.min === undefined ? undefined : props.min * scale}
62
+ max={props.max === undefined ? undefined : props.max * scale}
63
+ step={props.step === undefined ? "any" : props.step * scale}
64
+ aria-invalid={Boolean(visibleError)}
65
+ aria-describedby={`${id}-error`}
66
+ onChange={(event) => {
67
+ update(props.name, event.currentTarget.value === "" ? null : event.currentTarget.valueAsNumber / scale);
68
+ }}
69
+ />
70
+ <ErrorSpan id={`${id}-error`} error={visibleError} />
71
+ </div>
72
+ );
73
+ }
74
+
75
+ export const NumberField = withField(withValidation<FieldProps>(NumberFieldBase));
@@ -0,0 +1,101 @@
1
+ import * as React from "react";
2
+ import type { ActionButtonProps } from "./ActionButton.js";
3
+ import type { FormContextValue } from "./context.js";
4
+ import type { FormData } from "./types.js";
5
+ import { ActionButton } from "./ActionButton.js";
6
+ import { FormContext } from "./context.js";
7
+ import { Toast } from "../Toast.js";
8
+
9
+ export type ResetValues = (data: FormData) => FormData;
10
+
11
+ export interface ButtonBehaviour {
12
+ readonly name: "act" | "reset" | "submit";
13
+ readonly run: (input: {
14
+ readonly act: () => unknown;
15
+ readonly form: FormContextValue | null;
16
+ readonly resetValues?: ResetValues | undefined;
17
+ }) => unknown;
18
+ }
19
+
20
+ interface PresseeProps extends Omit<ActionButtonProps, "onClick" | "type"> {
21
+ readonly buttonBehaviours?: readonly ButtonBehaviour[] | undefined;
22
+ readonly resetValues?: ResetValues | undefined;
23
+ readonly onClick?: ((event: React.MouseEvent<HTMLButtonElement>) => unknown) | undefined;
24
+ }
25
+
26
+ /**
27
+ * Renders a button with the behaviours selected by its decorators.
28
+ * @param props Native button properties, click callback and ordered behaviours.
29
+ * @returns A button that runs the configured steps in order.
30
+ */
31
+ export function Pressee({
32
+ buttonBehaviours = [],
33
+ disabled,
34
+ onClick,
35
+ pending,
36
+ resetValues,
37
+ succeeded,
38
+ ...props
39
+ }: PresseeProps): React.ReactElement {
40
+ const form = React.useContext(FormContext),
41
+ running = React.useRef(false),
42
+ [executing, setExecuting] = React.useState(false),
43
+ [error, setError] = React.useState<unknown>(),
44
+ hasSubmit = buttonBehaviours.some(({ name }) => name === "submit"),
45
+ hasReset = buttonBehaviours.some(({ name }) => name === "reset"),
46
+ single = buttonBehaviours.length === 1,
47
+ type = single && hasSubmit ? "submit" : single && hasReset && !resetValues ? "reset" : "button",
48
+ unavailable =
49
+ (hasSubmit && !form?.submit && (form !== null || type === "button")) ||
50
+ (hasReset && !form?.reset && (form !== null || type === "button"));
51
+
52
+ /**
53
+ * Runs a compound button action after reserving the control for this click.
54
+ * @param event The React click event passed to a configured act step.
55
+ * @returns Completion of the steps, or of a reset that could no longer finish.
56
+ */
57
+ async function run(event: React.MouseEvent<HTMLButtonElement>): Promise<void> {
58
+ if (running.current) return;
59
+ running.current = true;
60
+ setExecuting(true);
61
+ setError(undefined);
62
+ try {
63
+ for (const behaviour of buttonBehaviours) {
64
+ if ((await behaviour.run({ act: () => onClick?.(event), form, resetValues })) === false) break;
65
+ }
66
+ } catch (failure) {
67
+ setError(failure);
68
+ } finally {
69
+ running.current = false;
70
+ setExecuting(false);
71
+ }
72
+ }
73
+
74
+ /**
75
+ * Selects native handling, a plain click, or an ordered series of steps.
76
+ * @param event The React click event.
77
+ * @returns Nothing. Compound actions continue asynchronously.
78
+ */
79
+ function click(event: React.MouseEvent<HTMLButtonElement>): void {
80
+ if (type !== "button") return;
81
+ if (!buttonBehaviours.length) {
82
+ onClick?.(event);
83
+ return;
84
+ }
85
+ void run(event);
86
+ }
87
+
88
+ return (
89
+ <>
90
+ <ActionButton
91
+ {...props}
92
+ disabled={disabled || unavailable}
93
+ onClick={click}
94
+ pending={Boolean(pending || executing || (hasSubmit && form?.pending))}
95
+ succeeded={Boolean(succeeded || (hasSubmit && !hasReset && form?.stored && !form.dirty))}
96
+ type={type}
97
+ />
98
+ {error != null && <Toast error={error} />}
99
+ </>
100
+ );
101
+ }
@@ -0,0 +1,94 @@
1
+ import * as React from "react"
2
+ import { useLayoutEffect, useRef, useState } from "react"
3
+ import { ErrorSpan } from "./ErrorSpan.js"
4
+ import { FieldCaption } from "./FieldCaption.js"
5
+ import type { FieldProps } from "./types.js"
6
+ import { displayClass } from "./values.js"
7
+ import { withValidation, type FieldValidation } from "../../decorators/withValidation.js"
8
+ import { flushSync } from "react-dom"
9
+ import { nodeId } from "./identity.js"
10
+ import { useForm } from "./context.js"
11
+ import { useI18n } from "../../concern/i18n.js"
12
+ import { withField } from "../../decorators/withField.js"
13
+
14
+ /** Редактор HTML с визуальным и исходным режимами, встроенный в форму. */
15
+ export const RtferField = withField(withValidation<FieldProps>(function RtferField(props: FieldProps & FieldValidation) {
16
+ const { update, disabled: formDisabled } = useForm()
17
+ const { t } = useI18n()
18
+ const element = useRef<HTMLDivElement>(null)
19
+ const source = useRef<HTMLTextAreaElement>(null)
20
+ const identity = useRef<string>(undefined)
21
+ identity.current ??= nodeId()
22
+ const id = props.id ?? identity.current
23
+ const caption = props.title ?? props.i18n?.title
24
+ const label = caption ?? props.placeholder ?? props.name
25
+ const value = typeof props.value === "string" ? props.value : ""
26
+ const disabled = Boolean(props.disabled || formDisabled)
27
+ const readonly = Boolean(props.readonly)
28
+ const [isSource, setIsSource] = useState(false)
29
+ // eslint-disable-next-line one-var -- Prepare the edit references after computing the form values.
30
+ const current = useRef({ disabled, name: props.name, readonly, update }),
31
+ placeholder = props.placeholder ?? t("tiun.components.rtfer.placeholder"),
32
+ synchronized = useRef(value)
33
+ current.current = { disabled, name: props.name, readonly, update }
34
+ let error = props.validateField()
35
+ if (!error && props.required === true && value.trim() === "") {
36
+ error = t("tiun.components.rtfer.errors.required")
37
+ }
38
+
39
+ /** Записывает новое HTML-значение и завершает обновление до отправки формы. */
40
+ function store(html: string): void {
41
+ const state = current.current
42
+ if (state.disabled || state.readonly || html === synchronized.current) return
43
+ synchronized.current = html
44
+ flushSync(() => state.update(state.name, html))
45
+ }
46
+
47
+ function updateSource(html: string): void {
48
+ synchronized.current = html
49
+ const state = current.current
50
+ if (!state.disabled && !state.readonly) flushSync(() => state.update(state.name, html))
51
+ }
52
+
53
+ useLayoutEffect(() => {
54
+ if (value === synchronized.current) return
55
+ synchronized.current = value
56
+ if (element.current) element.current.innerHTML = value
57
+ if (source.current) source.current.value = value
58
+ }, [value])
59
+
60
+ useLayoutEffect(() => {
61
+ const editor = element.current
62
+ if (editor && editor.innerHTML !== value) editor.innerHTML = value
63
+ if (source.current && source.current.value !== value) source.current.value = value
64
+ }, [])
65
+
66
+ function format(command: string): void {
67
+ if (!element.current || disabled || readonly) return
68
+ element.current.focus()
69
+ document.execCommand(command)
70
+ store(element.current.innerHTML)
71
+ }
72
+
73
+ const editorId = `${id}-editor`
74
+ return <div className={`tiun-field tiun-rtfer ${displayClass(props.display_scheme ?? "12-12-12-12")} ${props.wrapperClassName ?? ""}`}>
75
+ {caption && <FieldCaption htmlFor={editorId}>{caption}</FieldCaption>}
76
+ <div className="tiun-rtfer-toolbar" role="toolbar" aria-label={label}>
77
+ <button type="button" aria-label={t("tiun.components.rtfer.bold")} disabled={disabled || readonly} onClick={() => { format("bold") }}><strong>B</strong></button>
78
+ <button type="button" aria-label={t("tiun.components.rtfer.italic")} disabled={disabled || readonly} onClick={() => { format("italic") }}><em>I</em></button>
79
+ <button type="button" aria-label={t("tiun.components.rtfer.underline")} disabled={disabled || readonly} onClick={() => { format("underline") }}><u>U</u></button>
80
+ <button type="button" aria-pressed={isSource} disabled={disabled || readonly} onClick={() => {
81
+ if (!isSource && element.current) { synchronized.current = element.current.innerHTML; if (source.current) source.current.value = element.current.innerHTML }
82
+ if (isSource && source.current) store(source.current.value)
83
+ setIsSource(!isSource)
84
+ }}>{t("tiun.components.rtfer.source")}</button>
85
+ </div>
86
+ <div ref={element} id={editorId} role="textbox" aria-label={label} aria-multiline="true" aria-invalid={Boolean(error)}
87
+ aria-describedby={`${id}-error`} aria-required={Boolean(props.required)} aria-readonly={readonly}
88
+ contentEditable={!isSource && !disabled && !readonly} suppressContentEditableWarning
89
+ data-placeholder={placeholder} hidden={isSource} onInput={event => store(event.currentTarget.innerHTML)} />
90
+ <textarea ref={source} aria-label={`${label}: ${t("tiun.components.rtfer.source")}`} hidden={!isSource} disabled={disabled} readOnly={readonly}
91
+ defaultValue={value} onInput={event => updateSource(event.currentTarget.value)} />
92
+ <ErrorSpan id={`${id}-error`} error={error} />
93
+ </div>
94
+ }))