neutralino-python 0.1.0__py3-none-any.whl

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 (521) hide show
  1. neutralino/__init__.py +88 -0
  2. neutralino/_catalog.py +297 -0
  3. neutralino/_data/LICENSE.neutralino-js-client +21 -0
  4. neutralino/_data/LICENSE.neutralinojs +1066 -0
  5. neutralino/_data/docs/cli.md +315 -0
  6. neutralino/_data/docs/custom-components.md +107 -0
  7. neutralino/_data/docs/custom-frontends.md +80 -0
  8. neutralino/_data/docs/desktop-helpers.md +296 -0
  9. neutralino/_data/docs/guide.md +131 -0
  10. neutralino/_data/docs/llms-full.txt +3921 -0
  11. neutralino/_data/docs/llms.txt +43 -0
  12. neutralino/_data/docs/manifests/components.json +20128 -0
  13. neutralino/_data/docs/manifests/examples.json +52 -0
  14. neutralino/_data/docs/manifests/native.json +3024 -0
  15. neutralino/_data/docs/manifests/schema.json +43 -0
  16. neutralino/_data/docs/manual-checklist.md +189 -0
  17. neutralino/_data/docs/packaging.md +252 -0
  18. neutralino/_data/docs/performance.md +15 -0
  19. neutralino/_data/docs/platforms.md +15 -0
  20. neutralino/_data/docs/reference/components.md +1685 -0
  21. neutralino/_data/docs/reference/native.md +148 -0
  22. neutralino/_data/docs/security.md +60 -0
  23. neutralino/_data/docs/ui.md +249 -0
  24. neutralino/_data/docs/updates.md +366 -0
  25. neutralino/_data/examples/README.md +6 -0
  26. neutralino/_data/examples/crud/README.md +36 -0
  27. neutralino/_data/examples/crud/app.py +243 -0
  28. neutralino/_data/examples/dashboard/README.md +36 -0
  29. neutralino/_data/examples/dashboard/app.py +367 -0
  30. neutralino/_data/examples/editor/README.md +35 -0
  31. neutralino/_data/examples/editor/app.py +190 -0
  32. neutralino/_data/examples/file-manager/README.md +40 -0
  33. neutralino/_data/examples/file-manager/app.py +120 -0
  34. neutralino/_data/examples/file-manager/frontend/index.html +20 -0
  35. neutralino/_data/examples/file-manager/frontend/main.js +55 -0
  36. neutralino/_data/examples/file-manager/frontend/neutralino.js +1 -0
  37. neutralino/_data/examples/file-manager/frontend/python-bridge.d.ts +207 -0
  38. neutralino/_data/examples/file-manager/frontend/python-bridge.mjs +854 -0
  39. neutralino/_data/examples/file-manager/frontend/style.css +4 -0
  40. neutralino/_data/examples/hybrid/README.md +48 -0
  41. neutralino/_data/examples/hybrid/app.py +80 -0
  42. neutralino/_data/examples/hybrid/components/counter.mjs +37 -0
  43. neutralino/_data/examples/hybrid/components/widget.mjs +23 -0
  44. neutralino/_data/examples/hybrid/styles.css +21 -0
  45. neutralino/_data/examples/hybrid/widget/package.json +20 -0
  46. neutralino/_data/examples/hybrid/widget/src/Widget.jsx +25 -0
  47. neutralino/_data/examples/hybrid/widget/vite.config.mjs +19 -0
  48. neutralino/_data/examples/monitor/README.md +36 -0
  49. neutralino/_data/examples/monitor/app.py +375 -0
  50. neutralino/_data/examples/react/README.md +90 -0
  51. neutralino/_data/examples/react/app.py +68 -0
  52. neutralino/_data/examples/react/frontend/.gitignore +5 -0
  53. neutralino/_data/examples/react/frontend/index.html +17 -0
  54. neutralino/_data/examples/react/frontend/package-lock.json +1232 -0
  55. neutralino/_data/examples/react/frontend/package.json +25 -0
  56. neutralino/_data/examples/react/frontend/scripts/prepare-bridge.mjs +49 -0
  57. neutralino/_data/examples/react/frontend/src/App.tsx +157 -0
  58. neutralino/_data/examples/react/frontend/src/backend.ts +21 -0
  59. neutralino/_data/examples/react/frontend/src/calls.test.ts +206 -0
  60. neutralino/_data/examples/react/frontend/src/calls.ts +306 -0
  61. neutralino/_data/examples/react/frontend/src/globals.d.ts +14 -0
  62. neutralino/_data/examples/react/frontend/src/hooks.ts +45 -0
  63. neutralino/_data/examples/react/frontend/src/main.tsx +13 -0
  64. neutralino/_data/examples/react/frontend/src/styles.css +11 -0
  65. neutralino/_data/examples/react/frontend/tsconfig.json +18 -0
  66. neutralino/_data/examples/react/frontend/vite.config.ts +9 -0
  67. neutralino/_data/examples/settings/README.md +38 -0
  68. neutralino/_data/examples/settings/app.py +440 -0
  69. neutralino/_data/examples/updater/.gitignore +2 -0
  70. neutralino/_data/examples/updater/README.md +82 -0
  71. neutralino/_data/examples/updater/app.py +160 -0
  72. neutralino/_data/examples/updater/app.toml +21 -0
  73. neutralino/_data/examples/updater/demo.py +107 -0
  74. neutralino/_data/examples/updater/requirements.txt +2 -0
  75. neutralino/_data/examples/updater/sources/github-private.toml +21 -0
  76. neutralino/_data/examples/updater/sources/github-public.toml +21 -0
  77. neutralino/_data/examples/vanilla/README.md +35 -0
  78. neutralino/_data/examples/vanilla/app.py +46 -0
  79. neutralino/_data/examples/vanilla/frontend/index.html +17 -0
  80. neutralino/_data/examples/vanilla/frontend/main.js +29 -0
  81. neutralino/_data/examples/vanilla/frontend/neutralino.js +1 -0
  82. neutralino/_data/examples/vanilla/frontend/python-bridge.d.ts +207 -0
  83. neutralino/_data/examples/vanilla/frontend/python-bridge.mjs +854 -0
  84. neutralino/_data/examples/vanilla/frontend/style.css +4 -0
  85. neutralino/_data/explorer/app.py +1328 -0
  86. neutralino/_data/explorer/catalogue.json +48179 -0
  87. neutralino/_data/explorer/explorer_previews.py +247 -0
  88. neutralino/_data/explorer/sources/native/always_on_top.py +55 -0
  89. neutralino/_data/explorer/sources/native/binary.py +125 -0
  90. neutralino/_data/explorer/sources/native/borderless.py +99 -0
  91. neutralino/_data/explorer/sources/native/broadcast.py +90 -0
  92. neutralino/_data/explorer/sources/native/config.py +78 -0
  93. neutralino/_data/explorer/sources/native/controls.py +140 -0
  94. neutralino/_data/explorer/sources/native/directory.py +163 -0
  95. neutralino/_data/explorer/sources/native/displays.py +75 -0
  96. neutralino/_data/explorer/sources/native/env.py +98 -0
  97. neutralino/_data/explorer/sources/native/events.py +124 -0
  98. neutralino/_data/explorer/sources/native/exec_command.py +79 -0
  99. neutralino/_data/explorer/sources/native/folder.py +70 -0
  100. neutralino/_data/explorer/sources/native/icon_badge.py +101 -0
  101. neutralino/_data/explorer/sources/native/image.py +119 -0
  102. neutralino/_data/explorer/sources/native/lifecycle.py +99 -0
  103. neutralino/_data/explorer/sources/native/locale.py +70 -0
  104. neutralino/_data/explorer/sources/native/main_menu.py +103 -0
  105. neutralino/_data/explorer/sources/native/message_box.py +101 -0
  106. neutralino/_data/explorer/sources/native/mouse.py +70 -0
  107. neutralino/_data/explorer/sources/native/multi_window.py +134 -0
  108. neutralino/_data/explorer/sources/native/notification.py +74 -0
  109. neutralino/_data/explorer/sources/native/open_external.py +81 -0
  110. neutralino/_data/explorer/sources/native/open_file.py +102 -0
  111. neutralino/_data/explorer/sources/native/paths.py +77 -0
  112. neutralino/_data/explorer/sources/native/print_snapshot.py +84 -0
  113. neutralino/_data/explorer/sources/native/read_write.py +192 -0
  114. neutralino/_data/explorer/sources/native/resources.py +110 -0
  115. neutralino/_data/explorer/sources/native/save_file.py +101 -0
  116. neutralino/_data/explorer/sources/native/server_mount.py +106 -0
  117. neutralino/_data/explorer/sources/native/sound.py +84 -0
  118. neutralino/_data/explorer/sources/native/spawn_process.py +128 -0
  119. neutralino/_data/explorer/sources/native/states.py +122 -0
  120. neutralino/_data/explorer/sources/native/stats_permissions.py +147 -0
  121. neutralino/_data/explorer/sources/native/storage.py +108 -0
  122. neutralino/_data/explorer/sources/native/system_info.py +115 -0
  123. neutralino/_data/explorer/sources/native/text.py +133 -0
  124. neutralino/_data/explorer/sources/native/trash.py +98 -0
  125. neutralino/_data/explorer/sources/native/tray.py +109 -0
  126. neutralino/_data/explorer/sources/native/watcher.py +167 -0
  127. neutralino/_data/explorer/sources/patterns/content_blocks.py +119 -0
  128. neutralino/_data/explorer/sources/patterns/dynamic_dashboard.py +121 -0
  129. neutralino/_data/explorer/sources/patterns/dynamic_form.py +120 -0
  130. neutralino/_data/explorer/sources/patterns/dynamic_table.py +109 -0
  131. neutralino/_data/explorer/sources/patterns/error_reporting.mjs +24 -0
  132. neutralino/_data/explorer/sources/patterns/error_reporting.py +124 -0
  133. neutralino/_data/explorer/sources/patterns/errors_timeouts.py +108 -0
  134. neutralino/_data/explorer/sources/patterns/feature_flags.py +99 -0
  135. neutralino/_data/explorer/sources/patterns/file_drop.py +126 -0
  136. neutralino/_data/explorer/sources/patterns/http_from_python.py +152 -0
  137. neutralino/_data/explorer/sources/patterns/keyboard_shortcuts.py +153 -0
  138. neutralino/_data/explorer/sources/patterns/live_config_reload.py +160 -0
  139. neutralino/_data/explorer/sources/patterns/logging.py +184 -0
  140. neutralino/_data/explorer/sources/patterns/long_tasks.py +121 -0
  141. neutralino/_data/explorer/sources/patterns/multi_window_sync.py +68 -0
  142. neutralino/_data/explorer/sources/patterns/navigation_from_backend.py +109 -0
  143. neutralino/_data/explorer/sources/patterns/onboarding.py +123 -0
  144. neutralino/_data/explorer/sources/patterns/optimistic_updates.py +89 -0
  145. neutralino/_data/explorer/sources/patterns/persistence.py +114 -0
  146. neutralino/_data/explorer/sources/patterns/python_calls_page.mjs +10 -0
  147. neutralino/_data/explorer/sources/patterns/python_calls_page.py +64 -0
  148. neutralino/_data/explorer/sources/patterns/python_push.py +84 -0
  149. neutralino/_data/explorer/sources/patterns/recurring_events.py +114 -0
  150. neutralino/_data/explorer/sources/patterns/roles_permissions.py +104 -0
  151. neutralino/_data/explorer/sources/patterns/scheduled_jobs.py +194 -0
  152. neutralino/_data/explorer/sources/patterns/settings_page.py +165 -0
  153. neutralino/_data/explorer/sources/patterns/sqlite.py +181 -0
  154. neutralino/_data/explorer/sources/patterns/streaming.py +102 -0
  155. neutralino/_data/explorer/sources/patterns/texts_i18n.py +81 -0
  156. neutralino/_data/explorer/sources/patterns/theme_from_backend.py +86 -0
  157. neutralino/_data/explorer/sources/patterns/updater.py +232 -0
  158. neutralino/_data/explorer/sources/workspace/calendar/app.py +547 -0
  159. neutralino/_data/explorer/sources/workspace/customers/app.py +467 -0
  160. neutralino/_data/explorer/sources/workspace/dashboard/README.md +36 -0
  161. neutralino/_data/explorer/sources/workspace/dashboard/app.py +367 -0
  162. neutralino/_data/explorer/sources/workspace/documents/app.py +511 -0
  163. neutralino/_data/explorer/sources/workspace/inbox/app.py +439 -0
  164. neutralino/_data/explorer/sources/workspace/orders/app.py +491 -0
  165. neutralino/_data/explorer/sources/workspace/reports/app.py +386 -0
  166. neutralino/_data/explorer/sources/workspace/settings/README.md +38 -0
  167. neutralino/_data/explorer/sources/workspace/settings/app.py +440 -0
  168. neutralino/_data/explorer/sources/workspace/system/README.md +36 -0
  169. neutralino/_data/explorer/sources/workspace/system/app.py +375 -0
  170. neutralino/_data/explorer/sources/workspace/tasks/app.py +462 -0
  171. neutralino/_data/renderer/LICENSES/@babel__runtime@7.29.17/LICENSE +22 -0
  172. neutralino/_data/renderer/LICENSES/@codemirror__autocomplete@6.20.4/LICENSE +21 -0
  173. neutralino/_data/renderer/LICENSES/@codemirror__commands@6.11.2/LICENSE +21 -0
  174. neutralino/_data/renderer/LICENSES/@codemirror__lang-css@6.3.1/LICENSE +21 -0
  175. neutralino/_data/renderer/LICENSES/@codemirror__lang-html@6.4.12/LICENSE +21 -0
  176. neutralino/_data/renderer/LICENSES/@codemirror__lang-javascript@6.2.5/LICENSE +21 -0
  177. neutralino/_data/renderer/LICENSES/@codemirror__lang-json@6.0.2/LICENSE +21 -0
  178. neutralino/_data/renderer/LICENSES/@codemirror__lang-markdown@6.5.3/LICENSE +21 -0
  179. neutralino/_data/renderer/LICENSES/@codemirror__lang-python@6.2.1/LICENSE +21 -0
  180. neutralino/_data/renderer/LICENSES/@codemirror__lang-sql@6.10.0/LICENSE +21 -0
  181. neutralino/_data/renderer/LICENSES/@codemirror__lang-yaml@6.1.3/LICENSE +21 -0
  182. neutralino/_data/renderer/LICENSES/@codemirror__language@6.13.1/LICENSE +21 -0
  183. neutralino/_data/renderer/LICENSES/@codemirror__search@6.7.3/LICENSE +21 -0
  184. neutralino/_data/renderer/LICENSES/@codemirror__state@6.7.6/LICENSE +21 -0
  185. neutralino/_data/renderer/LICENSES/@codemirror__view@6.44.2/LICENSE +21 -0
  186. neutralino/_data/renderer/LICENSES/@dnd-kit__accessibility@3.1.1/LICENSE +21 -0
  187. neutralino/_data/renderer/LICENSES/@dnd-kit__core@6.3.1/LICENSE +21 -0
  188. neutralino/_data/renderer/LICENSES/@dnd-kit__sortable@10.0.0/LICENSE +21 -0
  189. neutralino/_data/renderer/LICENSES/@dnd-kit__utilities@3.2.2/LICENSE +21 -0
  190. neutralino/_data/renderer/LICENSES/@emoji-mart__data@1.2.1/LICENSE +21 -0
  191. neutralino/_data/renderer/LICENSES/@floating-ui__core@1.8.0/LICENSE +20 -0
  192. neutralino/_data/renderer/LICENSES/@floating-ui__dom@1.8.0/LICENSE +20 -0
  193. neutralino/_data/renderer/LICENSES/@floating-ui__react-dom@2.1.9/LICENSE +20 -0
  194. neutralino/_data/renderer/LICENSES/@floating-ui__react@0.27.20/LICENSE +20 -0
  195. neutralino/_data/renderer/LICENSES/@floating-ui__utils@0.2.12/LICENSE +20 -0
  196. neutralino/_data/renderer/LICENSES/@lezer__common@1.5.7/LICENSE +21 -0
  197. neutralino/_data/renderer/LICENSES/@lezer__css@1.3.9/LICENSE +21 -0
  198. neutralino/_data/renderer/LICENSES/@lezer__highlight@1.2.5/LICENSE +21 -0
  199. neutralino/_data/renderer/LICENSES/@lezer__html@1.3.13/LICENSE +21 -0
  200. neutralino/_data/renderer/LICENSES/@lezer__javascript@1.5.7/LICENSE +21 -0
  201. neutralino/_data/renderer/LICENSES/@lezer__json@1.0.3/LICENSE +21 -0
  202. neutralino/_data/renderer/LICENSES/@lezer__lr@1.4.13/LICENSE +21 -0
  203. neutralino/_data/renderer/LICENSES/@lezer__markdown@1.8.3/LICENSE +21 -0
  204. neutralino/_data/renderer/LICENSES/@lezer__python@1.1.21/LICENSE +21 -0
  205. neutralino/_data/renderer/LICENSES/@lezer__yaml@1.0.4/LICENSE +21 -0
  206. neutralino/_data/renderer/LICENSES/@mantine__carousel@9.8.3/LICENSE +21 -0
  207. neutralino/_data/renderer/LICENSES/@mantine__charts@9.8.3/LICENSE +21 -0
  208. neutralino/_data/renderer/LICENSES/@mantine__code-highlight@9.8.3/LICENSE +21 -0
  209. neutralino/_data/renderer/LICENSES/@mantine__core@9.8.3/LICENSE +21 -0
  210. neutralino/_data/renderer/LICENSES/@mantine__dates@9.8.3/LICENSE +21 -0
  211. neutralino/_data/renderer/LICENSES/@mantine__dropzone@9.8.3/LICENSE +21 -0
  212. neutralino/_data/renderer/LICENSES/@mantine__emoji@9.8.3/LICENSE +21 -0
  213. neutralino/_data/renderer/LICENSES/@mantine__hooks@9.8.3/LICENSE +21 -0
  214. neutralino/_data/renderer/LICENSES/@mantine__lightbox@9.8.3/LICENSE +21 -0
  215. neutralino/_data/renderer/LICENSES/@mantine__notifications@9.8.3/LICENSE +21 -0
  216. neutralino/_data/renderer/LICENSES/@mantine__nprogress@9.8.3/LICENSE +21 -0
  217. neutralino/_data/renderer/LICENSES/@mantine__schedule@9.8.3/LICENSE +21 -0
  218. neutralino/_data/renderer/LICENSES/@mantine__spotlight@9.8.3/LICENSE +21 -0
  219. neutralino/_data/renderer/LICENSES/@mantine__store@9.8.3/LICENSE +21 -0
  220. neutralino/_data/renderer/LICENSES/@mantine__tiptap@9.8.3/LICENSE +21 -0
  221. neutralino/_data/renderer/LICENSES/@marijn__find-cluster-break@1.0.4/LICENSE +21 -0
  222. neutralino/_data/renderer/LICENSES/@reduxjs__toolkit@2.16.0/LICENSE +21 -0
  223. neutralino/_data/renderer/LICENSES/@tabler__icons-react@3.55.0/LICENSE +21 -0
  224. neutralino/_data/renderer/LICENSES/@tanstack__react-virtual@3.14.32/LICENSE +21 -0
  225. neutralino/_data/renderer/LICENSES/@tanstack__virtual-core@3.19.17/LICENSE +21 -0
  226. neutralino/_data/renderer/LICENSES/@tiptap__core@3.35.1/LICENSE.md +21 -0
  227. neutralino/_data/renderer/LICENSES/@tiptap__extension-blockquote@3.35.1/LICENSE.md +21 -0
  228. neutralino/_data/renderer/LICENSES/@tiptap__extension-bold@3.35.1/LICENSE.md +21 -0
  229. neutralino/_data/renderer/LICENSES/@tiptap__extension-code-block@3.35.1/LICENSE.md +21 -0
  230. neutralino/_data/renderer/LICENSES/@tiptap__extension-code@3.35.1/LICENSE.md +21 -0
  231. neutralino/_data/renderer/LICENSES/@tiptap__extension-document@3.35.1/LICENSE.md +21 -0
  232. neutralino/_data/renderer/LICENSES/@tiptap__extension-hard-break@3.35.1/LICENSE.md +21 -0
  233. neutralino/_data/renderer/LICENSES/@tiptap__extension-heading@3.35.1/LICENSE.md +21 -0
  234. neutralino/_data/renderer/LICENSES/@tiptap__extension-horizontal-rule@3.35.1/LICENSE.md +21 -0
  235. neutralino/_data/renderer/LICENSES/@tiptap__extension-italic@3.35.1/LICENSE.md +21 -0
  236. neutralino/_data/renderer/LICENSES/@tiptap__extension-link@3.35.1/LICENSE.md +21 -0
  237. neutralino/_data/renderer/LICENSES/@tiptap__extension-list@3.35.1/LICENSE.md +21 -0
  238. neutralino/_data/renderer/LICENSES/@tiptap__extension-paragraph@3.35.1/LICENSE.md +21 -0
  239. neutralino/_data/renderer/LICENSES/@tiptap__extension-strike@3.35.1/LICENSE.md +21 -0
  240. neutralino/_data/renderer/LICENSES/@tiptap__extension-text@3.35.1/LICENSE.md +21 -0
  241. neutralino/_data/renderer/LICENSES/@tiptap__extension-underline@3.35.1/LICENSE.md +21 -0
  242. neutralino/_data/renderer/LICENSES/@tiptap__extensions@3.35.1/LICENSE.md +21 -0
  243. neutralino/_data/renderer/LICENSES/@tiptap__react@3.35.1/LICENSE.md +21 -0
  244. neutralino/_data/renderer/LICENSES/@tiptap__starter-kit@3.35.1/LICENSE.md +21 -0
  245. neutralino/_data/renderer/LICENSES/attr-accept@4.0.1/LICENSE +22 -0
  246. neutralino/_data/renderer/LICENSES/clsx@2.1.1/license +9 -0
  247. neutralino/_data/renderer/LICENSES/crelt@1.0.7/LICENSE +19 -0
  248. neutralino/_data/renderer/LICENSES/d3-array@3.2.5/LICENSE +13 -0
  249. neutralino/_data/renderer/LICENSES/d3-color@3.1.1/LICENSE +13 -0
  250. neutralino/_data/renderer/LICENSES/d3-format@3.1.3/LICENSE +13 -0
  251. neutralino/_data/renderer/LICENSES/d3-interpolate@3.0.2/LICENSE +13 -0
  252. neutralino/_data/renderer/LICENSES/d3-path@3.1.1/LICENSE +13 -0
  253. neutralino/_data/renderer/LICENSES/d3-scale@4.0.3/LICENSE +13 -0
  254. neutralino/_data/renderer/LICENSES/d3-shape@3.2.1/LICENSE +13 -0
  255. neutralino/_data/renderer/LICENSES/d3-time-format@4.1.1/LICENSE +13 -0
  256. neutralino/_data/renderer/LICENSES/d3-time@3.1.1/LICENSE +13 -0
  257. neutralino/_data/renderer/LICENSES/dayjs@1.11.23/LICENSE +21 -0
  258. neutralino/_data/renderer/LICENSES/decimal.js-light@2.5.1/LICENCE.md +23 -0
  259. neutralino/_data/renderer/LICENSES/diff@9.0.0/LICENSE +29 -0
  260. neutralino/_data/renderer/LICENSES/dompurify@3.5.1/LICENSE +202 -0
  261. neutralino/_data/renderer/LICENSES/dompurify@3.5.1/LICENSE-MPL +373 -0
  262. neutralino/_data/renderer/LICENSES/embla-carousel-react@8.6.0/MIT-embla-carousel.txt +21 -0
  263. neutralino/_data/renderer/LICENSES/embla-carousel-reactive-utils@8.6.0/MIT-embla-carousel.txt +21 -0
  264. neutralino/_data/renderer/LICENSES/embla-carousel@8.6.0/MIT-embla-carousel.txt +21 -0
  265. neutralino/_data/renderer/LICENSES/es-toolkit@1.53.2/LICENSE +21 -0
  266. neutralino/_data/renderer/LICENSES/es-toolkit@1.53.2/NOTICE +39 -0
  267. neutralino/_data/renderer/LICENSES/eventemitter3@5.0.4/LICENSE +21 -0
  268. neutralino/_data/renderer/LICENSES/fast-equals@5.4.7/LICENSE +21 -0
  269. neutralino/_data/renderer/LICENSES/file-selector@5.0.3/LICENSE +21 -0
  270. neutralino/_data/renderer/LICENSES/get-nonce@1.0.1/LICENSE +21 -0
  271. neutralino/_data/renderer/LICENSES/immer@11.2.14/LICENSE +21 -0
  272. neutralino/_data/renderer/LICENSES/linkifyjs@4.4.0/LICENSE +19 -0
  273. neutralino/_data/renderer/LICENSES/marked@18.4.0/LICENSE +44 -0
  274. neutralino/_data/renderer/LICENSES/neutralino.js@6.11.0/LICENSE +21 -0
  275. neutralino/_data/renderer/LICENSES/orderedmap@2.1.1/LICENSE +19 -0
  276. neutralino/_data/renderer/LICENSES/packages.json +1838 -0
  277. neutralino/_data/renderer/LICENSES/prosemirror-commands@1.7.2/LICENSE +19 -0
  278. neutralino/_data/renderer/LICENSES/prosemirror-dropcursor@1.8.4/LICENSE +19 -0
  279. neutralino/_data/renderer/LICENSES/prosemirror-gapcursor@1.4.1/LICENSE +19 -0
  280. neutralino/_data/renderer/LICENSES/prosemirror-history@1.5.2/LICENSE +19 -0
  281. neutralino/_data/renderer/LICENSES/prosemirror-keymap@1.2.3/LICENSE +19 -0
  282. neutralino/_data/renderer/LICENSES/prosemirror-model@1.25.13/LICENSE +19 -0
  283. neutralino/_data/renderer/LICENSES/prosemirror-schema-list@1.6.1/LICENSE +19 -0
  284. neutralino/_data/renderer/LICENSES/prosemirror-state@1.4.4/LICENSE +19 -0
  285. neutralino/_data/renderer/LICENSES/prosemirror-transform@1.12.7/LICENSE +19 -0
  286. neutralino/_data/renderer/LICENSES/prosemirror-view@1.44.0/LICENSE +19 -0
  287. neutralino/_data/renderer/LICENSES/react-dom@19.3.1/LICENSE +21 -0
  288. neutralino/_data/renderer/LICENSES/react-dropzone@20.1.4/LICENSE +22 -0
  289. neutralino/_data/renderer/LICENSES/react-is@19.3.1/LICENSE +21 -0
  290. neutralino/_data/renderer/LICENSES/react-number-format@5.4.5/LICENSE +21 -0
  291. neutralino/_data/renderer/LICENSES/react-redux@9.3.1/LICENSE.md +21 -0
  292. neutralino/_data/renderer/LICENSES/react-remove-scroll-bar@2.3.8/MIT-react-remove-scroll-bar.txt +21 -0
  293. neutralino/_data/renderer/LICENSES/react-remove-scroll@2.7.2/LICENSE +21 -0
  294. neutralino/_data/renderer/LICENSES/react-style-singleton@2.2.3/LICENSE +21 -0
  295. neutralino/_data/renderer/LICENSES/react-transition-group@4.4.5/LICENSE +30 -0
  296. neutralino/_data/renderer/LICENSES/react@19.3.1/LICENSE +21 -0
  297. neutralino/_data/renderer/LICENSES/recharts@3.11.3/LICENSE +22 -0
  298. neutralino/_data/renderer/LICENSES/redux-thunk@3.1.0/LICENSE.md +21 -0
  299. neutralino/_data/renderer/LICENSES/redux@5.0.1/LICENSE.md +21 -0
  300. neutralino/_data/renderer/LICENSES/reselect@5.2.0/LICENSE +21 -0
  301. neutralino/_data/renderer/LICENSES/rolldown@1.3.4/LICENSE +25 -0
  302. neutralino/_data/renderer/LICENSES/rope-sequence@1.3.4/LICENSE +19 -0
  303. neutralino/_data/renderer/LICENSES/rrule@2.8.1/LICENCE +65 -0
  304. neutralino/_data/renderer/LICENSES/scheduler@0.28.0/LICENSE +21 -0
  305. neutralino/_data/renderer/LICENSES/style-mod@4.1.5/LICENSE +19 -0
  306. neutralino/_data/renderer/LICENSES/tiny-invariant@1.3.3/LICENSE +21 -0
  307. neutralino/_data/renderer/LICENSES/tslib@2.9.1/LICENSE.txt +12 -0
  308. neutralino/_data/renderer/LICENSES/use-callback-ref@1.3.3/LICENSE +21 -0
  309. neutralino/_data/renderer/LICENSES/use-sidecar@1.1.3/LICENSE +21 -0
  310. neutralino/_data/renderer/LICENSES/use-sync-external-store@1.7.0/LICENSE +21 -0
  311. neutralino/_data/renderer/LICENSES/victory-vendor@38.1.1/LICENSE.txt +150 -0
  312. neutralino/_data/renderer/LICENSES/vite@8.4.1/LICENSE.md +2320 -0
  313. neutralino/_data/renderer/LICENSES/w3c-keyname@2.2.8/LICENSE +19 -0
  314. neutralino/_data/renderer/assets/IconGripVertical-BlJrWVuo.js +1 -0
  315. neutralino/_data/renderer/assets/carousel-D1j1SkWR.css +1 -0
  316. neutralino/_data/renderer/assets/carousel-DniHwTLK.js +1 -0
  317. neutralino/_data/renderer/assets/chunk-CCkLOSkX.css +1 -0
  318. neutralino/_data/renderer/assets/chunk-Du0h7lB-.js +9 -0
  319. neutralino/_data/renderer/assets/codehighlight-CCe_blv1.js +10 -0
  320. neutralino/_data/renderer/assets/codehighlight-THJMNDh8.css +1 -0
  321. neutralino/_data/renderer/assets/codemirror-CinrNxVJ.js +2 -0
  322. neutralino/_data/renderer/assets/css-CMUk25uq.js +1 -0
  323. neutralino/_data/renderer/assets/dist-70Le0T2N.js +1 -0
  324. neutralino/_data/renderer/assets/dist-BCHbQlae.js +11 -0
  325. neutralino/_data/renderer/assets/dist-BXts23GT.js +1 -0
  326. neutralino/_data/renderer/assets/dist-D2RX2UgP.js +23 -0
  327. neutralino/_data/renderer/assets/dist-DikJK2lp.js +1 -0
  328. neutralino/_data/renderer/assets/dist-acbbRM1z.js +1 -0
  329. neutralino/_data/renderer/assets/dnd-DaaaVala.js +5 -0
  330. neutralino/_data/renderer/assets/dropzone-CeqF5SZx.js +1 -0
  331. neutralino/_data/renderer/assets/dropzone-aPCBPjDN.css +1 -0
  332. neutralino/_data/renderer/assets/embla-carousel-react.esm-CbyYjwMN.js +1 -0
  333. neutralino/_data/renderer/assets/emoji-BfRPfoVw.js +1 -0
  334. neutralino/_data/renderer/assets/emoji-DV8OzU1E.css +1 -0
  335. neutralino/_data/renderer/assets/esm-C5ZYjSBQ.js +82 -0
  336. neutralino/_data/renderer/assets/highlight-CB6hGb5A.js +3 -0
  337. neutralino/_data/renderer/assets/highlight-Dlb5DJwL.css +1 -0
  338. neutralino/_data/renderer/assets/html-Dad3kwIa.js +1 -0
  339. neutralino/_data/renderer/assets/icon-chunk-X3Kr0nh-.js +1 -0
  340. neutralino/_data/renderer/assets/index-CU0HB-J7.js +69 -0
  341. neutralino/_data/renderer/assets/index-TWpF4Lef.css +1 -0
  342. neutralino/_data/renderer/assets/javascript-BQb8vpw3.js +1 -0
  343. neutralino/_data/renderer/assets/json-BCFmxlML.js +1 -0
  344. neutralino/_data/renderer/assets/lightbox-BHtgbsUV.js +1 -0
  345. neutralino/_data/renderer/assets/lightbox-BzKDpkAD.css +1 -0
  346. neutralino/_data/renderer/assets/markdown-DSuAylvy.js +5 -0
  347. neutralino/_data/renderer/assets/markdown-DjaNWMgH.js +77 -0
  348. neutralino/_data/renderer/assets/python-pdbIAveZ.js +9 -0
  349. neutralino/_data/renderer/assets/richtext-DIAsHMuK.css +1 -0
  350. neutralino/_data/renderer/assets/richtext-Z6fG9G2_.js +137 -0
  351. neutralino/_data/renderer/assets/spotlight-Ccstaz1-.css +1 -0
  352. neutralino/_data/renderer/assets/spotlight-knlyJw_A.js +1 -0
  353. neutralino/_data/renderer/assets/sql-DLoQFEde.js +2 -0
  354. neutralino/_data/renderer/assets/with-selector-BOM9_OlN.js +1 -0
  355. neutralino/_data/renderer/assets/yaml-BJNzokSe.js +1 -0
  356. neutralino/_data/renderer/index.html +22 -0
  357. neutralino/_data/renderer/manifest.json +202 -0
  358. neutralino/_data/renderer/neutralino.js +1 -0
  359. neutralino/_data/renderer/shared/mantine-core.mjs +5 -0
  360. neutralino/_data/renderer/shared/mantine-hooks.mjs +5 -0
  361. neutralino/_data/renderer/shared/react-dom-client.mjs +5 -0
  362. neutralino/_data/renderer/shared/react-dom.mjs +6 -0
  363. neutralino/_data/renderer/shared/react-jsx-runtime.mjs +5 -0
  364. neutralino/_data/renderer/shared/react.mjs +6 -0
  365. neutralino/_data/skills/README.md +6 -0
  366. neutralino/_data/skills/neutralino-app-patterns/SKILL.md +101 -0
  367. neutralino/_data/skills/neutralino-app-patterns/references/dashboards-and-background-work.md +55 -0
  368. neutralino/_data/skills/neutralino-app-patterns/references/storage-and-settings.md +57 -0
  369. neutralino/_data/skills/neutralino-app-patterns/references/tables-and-crud.md +81 -0
  370. neutralino/_data/skills/neutralino-frontend/SKILL.md +121 -0
  371. neutralino/_data/skills/neutralino-frontend/references/bridge.md +63 -0
  372. neutralino/_data/skills/neutralino-frontend/references/custom-components.md +84 -0
  373. neutralino/_data/skills/neutralino-frontend/references/frameworks.md +61 -0
  374. neutralino/_data/skills/neutralino-maintenance/SKILL.md +85 -0
  375. neutralino/_data/skills/neutralino-maintenance/references/platforms-and-gates.md +35 -0
  376. neutralino/_data/skills/neutralino-maintenance/references/records.md +38 -0
  377. neutralino/_data/skills/neutralino-maintenance/references/review-process.md +36 -0
  378. neutralino/_data/skills/neutralino-native/SKILL.md +107 -0
  379. neutralino/_data/skills/neutralino-native/references/api-conventions.md +72 -0
  380. neutralino/_data/skills/neutralino-native/references/desktop-helpers.md +53 -0
  381. neutralino/_data/skills/neutralino-native/references/permissions-windows.md +53 -0
  382. neutralino/_data/skills/neutralino-packaging/SKILL.md +99 -0
  383. neutralino/_data/skills/neutralino-packaging/references/build-layout.md +51 -0
  384. neutralino/_data/skills/neutralino-packaging/references/managed-install.md +59 -0
  385. neutralino/_data/skills/neutralino-packaging/references/templates-and-config.md +63 -0
  386. neutralino/_data/skills/neutralino-python/SKILL.md +109 -0
  387. neutralino/_data/skills/neutralino-python/references/architecture.md +53 -0
  388. neutralino/_data/skills/neutralino-python/references/cli.md +60 -0
  389. neutralino/_data/skills/neutralino-python/references/platforms-security.md +44 -0
  390. neutralino/_data/skills/neutralino-rpc/SKILL.md +114 -0
  391. neutralino/_data/skills/neutralino-rpc/references/errors-and-limits.md +44 -0
  392. neutralino/_data/skills/neutralino-rpc/references/expose-and-context.md +74 -0
  393. neutralino/_data/skills/neutralino-rpc/references/streams-and-cancellation.md +53 -0
  394. neutralino/_data/skills/neutralino-ui/SKILL.md +115 -0
  395. neutralino/_data/skills/neutralino-ui/references/components-and-tree.md +74 -0
  396. neutralino/_data/skills/neutralino-ui/references/state-forms-events.md +85 -0
  397. neutralino/_data/skills/neutralino-ui/references/themes-profiles-assets.md +105 -0
  398. neutralino/_data/skills/neutralino-updates/SKILL.md +94 -0
  399. neutralino/_data/skills/neutralino-updates/references/config-and-api.md +80 -0
  400. neutralino/_data/skills/neutralino-updates/references/releases-and-install.md +77 -0
  401. neutralino/_data/skills/neutralino-updates/references/security-rollback.md +48 -0
  402. neutralino/_data/ui/contracts.json +32927 -0
  403. neutralino/_data/ui/emoji.json +1 -0
  404. neutralino/_data/upstream-lock.json +97 -0
  405. neutralino/_managed.py +1099 -0
  406. neutralino/_paths.py +220 -0
  407. neutralino/_platform.py +150 -0
  408. neutralino/_scaffold.py +344 -0
  409. neutralino/api/_base.py +99 -0
  410. neutralino/api/_custom.py +1350 -0
  411. neutralino/api/_dec.py +21 -0
  412. neutralino/api/_enc.py +80 -0
  413. neutralino/api/app.py +119 -0
  414. neutralino/api/clipboard.py +101 -0
  415. neutralino/api/computer.py +261 -0
  416. neutralino/api/custom.py +36 -0
  417. neutralino/api/debug.py +41 -0
  418. neutralino/api/extensions.py +57 -0
  419. neutralino/api/filesystem.py +633 -0
  420. neutralino/api/net.py +22 -0
  421. neutralino/api/os.py +508 -0
  422. neutralino/api/resources.py +124 -0
  423. neutralino/api/server.py +66 -0
  424. neutralino/api/storage.py +98 -0
  425. neutralino/api/types.py +342 -0
  426. neutralino/api/updater.py +22 -0
  427. neutralino/api/window.py +397 -0
  428. neutralino/application.py +1260 -0
  429. neutralino/bundle.py +187 -0
  430. neutralino/cli.py +629 -0
  431. neutralino/client.py +496 -0
  432. neutralino/config.py +671 -0
  433. neutralino/devtools.py +1973 -0
  434. neutralino/errors.py +142 -0
  435. neutralino/events.py +579 -0
  436. neutralino/execution.py +293 -0
  437. neutralino/extension.py +134 -0
  438. neutralino/frontend/python-bridge.d.ts +207 -0
  439. neutralino/frontend/python-bridge.mjs +854 -0
  440. neutralino/protocol.py +456 -0
  441. neutralino/py.typed +0 -0
  442. neutralino/rpc.py +1625 -0
  443. neutralino/runtime.py +591 -0
  444. neutralino/supervisor.py +866 -0
  445. neutralino/sync_client.py +376 -0
  446. neutralino/templates/default/app.py +32 -0
  447. neutralino/templates/default/frontend/app.js +28 -0
  448. neutralino/templates/default/frontend/index.html +26 -0
  449. neutralino/templates/default/frontend/neutralino.js +1 -0
  450. neutralino/templates/default/frontend/styles.css +8 -0
  451. neutralino/templates/default/gitignore.txt +3 -0
  452. neutralino/templates/default/neutralino.config.json +25 -0
  453. neutralino/templates/hybrid/README.md +17 -0
  454. neutralino/templates/hybrid/app.py +49 -0
  455. neutralino/templates/hybrid/components/counter.mjs +37 -0
  456. neutralino/templates/hybrid/styles.css +21 -0
  457. neutralino/templates/python-ui/README.md +15 -0
  458. neutralino/templates/python-ui/app.py +44 -0
  459. neutralino/templates/python-ui/gitignore.txt +3 -0
  460. neutralino/templates/python-ui/requirements.txt +4 -0
  461. neutralino/templates/react/README.md +28 -0
  462. neutralino/templates/react/app.py +52 -0
  463. neutralino/templates/react/components/widget.mjs +23 -0
  464. neutralino/templates/react/widget/package.json +20 -0
  465. neutralino/templates/react/widget/src/Widget.jsx +25 -0
  466. neutralino/templates/react/widget/vite.config.mjs +19 -0
  467. neutralino/transport.py +661 -0
  468. neutralino/types.py +93 -0
  469. neutralino/ui/__init__.py +139 -0
  470. neutralino/ui/_app.py +1529 -0
  471. neutralino/ui/_assets.py +407 -0
  472. neutralino/ui/_bases.py +1210 -0
  473. neutralino/ui/_behaviours.py +1066 -0
  474. neutralino/ui/_charts.py +732 -0
  475. neutralino/ui/_component.py +882 -0
  476. neutralino/ui/_dates.py +168 -0
  477. neutralino/ui/_desktop.py +879 -0
  478. neutralino/ui/_events.py +192 -0
  479. neutralino/ui/_filters.py +427 -0
  480. neutralino/ui/_forms.py +282 -0
  481. neutralino/ui/_protocol.py +201 -0
  482. neutralino/ui/_schedule.py +543 -0
  483. neutralino/ui/_security.py +106 -0
  484. neutralino/ui/_session.py +969 -0
  485. neutralino/ui/_state.py +199 -0
  486. neutralino/ui/_tables.py +256 -0
  487. neutralino/ui/_theme.py +154 -0
  488. neutralino/ui/blocks/__init__.py +19 -0
  489. neutralino/ui/blocks/_data.py +2239 -0
  490. neutralino/ui/blocks/_interactive.py +622 -0
  491. neutralino/ui/blocks/_layout.py +2967 -0
  492. neutralino/ui/components/__init__.py +81 -0
  493. neutralino/ui/components/_dates.py +879 -0
  494. neutralino/ui/components/_editors.py +217 -0
  495. neutralino/ui/components/_extensions.py +790 -0
  496. neutralino/ui/components/_extras.py +303 -0
  497. neutralino/ui/components/_generated.py +30565 -0
  498. neutralino/ui/components/_types.py +17 -0
  499. neutralino/ui/schema.py +824 -0
  500. neutralino/ui/validators.py +362 -0
  501. neutralino/updates/__init__.py +96 -0
  502. neutralino/updates/_http.py +320 -0
  503. neutralino/updates/_layout.py +762 -0
  504. neutralino/updates/archive.py +216 -0
  505. neutralino/updates/config.py +256 -0
  506. neutralino/updates/errors.py +97 -0
  507. neutralino/updates/install.sh.in +201 -0
  508. neutralino/updates/launcher.py +18 -0
  509. neutralino/updates/manager.py +808 -0
  510. neutralino/updates/manifest.py +196 -0
  511. neutralino/updates/release.py +314 -0
  512. neutralino/updates/semver.py +84 -0
  513. neutralino/updates/sources.py +392 -0
  514. neutralino/windows.py +316 -0
  515. neutralino_python-0.1.0.dist-info/METADATA +121 -0
  516. neutralino_python-0.1.0.dist-info/RECORD +521 -0
  517. neutralino_python-0.1.0.dist-info/WHEEL +4 -0
  518. neutralino_python-0.1.0.dist-info/entry_points.txt +3 -0
  519. neutralino_python-0.1.0.dist-info/licenses/LICENSE +21 -0
  520. neutralino_python-0.1.0.dist-info/licenses/THIRD_PARTY_NOTICES.md +16 -0
  521. neutralino_python-0.1.0.dist-info/licenses/src/neutralino/_data/renderer/LICENSES/packages.json +1838 -0
@@ -0,0 +1,824 @@
1
+ """Server-driven UI: a validated JSON/dict schema -> a component tree.
2
+
3
+ A schema node names a *registered component type* (the typed components of
4
+ ``neutralino.ui``), its props (validated by the component's own contract),
5
+ children/slots and event bindings to *registered actions* (named Python
6
+ callables in an :class:`Actions` registry). Nothing in a schema is executed:
7
+ no code, no expressions, no callbacks, no imports. Unknown types, unknown or
8
+ invalid props, events the component does not have, actions that are not
9
+ registered, executable strings (``javascript:`` URLs, ``<script``, inline
10
+ ``on…=`` handlers), oversize or too deep payloads are rejected with a
11
+ :class:`SchemaError` naming the path::
12
+
13
+ actions = ui.schema.Actions()
14
+
15
+ @actions.action("save")
16
+ def save(ev: ui.schema.ActionEvent) -> None:
17
+ print(ev.args, ev.values)
18
+
19
+ tree = ui.schema.build(
20
+ {
21
+ "type": "Stack",
22
+ "children": [
23
+ {"type": "Title", "props": {"text": "Report", "order": 2}},
24
+ {"type": "Button", "props": {"label": "Save"},
25
+ "on": {"click": {"action": "save", "args": {"id": 3}}}},
26
+ ],
27
+ },
28
+ actions=actions,
29
+ )
30
+ page.add(tree.root) # or build inside ``with app.page("/")``
31
+
32
+ Node keys: ``type`` (required), ``props``, ``children``, ``slots``
33
+ (``{slot: [nodes]}``), ``on`` (``{event: action | {action, args}}``), ``key``
34
+ (name for :attr:`SchemaTree.refs`, to update widgets live), ``provider``
35
+ (DataTable: a registered data provider) and ``item`` (FieldList: the nodes of
36
+ one item). ``unknown="placeholder"`` renders unknown types as a neutral
37
+ notice instead of failing (content from newer servers).
38
+ """
39
+
40
+ from __future__ import annotations
41
+
42
+ import inspect
43
+ import json
44
+ import re
45
+ from collections.abc import Callable, Mapping, Sequence
46
+ from dataclasses import dataclass, field
47
+ from typing import Any, Final, Literal, cast
48
+
49
+ from ..errors import ValidationError
50
+ from ..types import UNSET
51
+ from ._component import Component, detached, handler_arity
52
+ from ._events import Event
53
+ from ._protocol import check_value
54
+
55
+ __all__ = [
56
+ "ActionEvent",
57
+ "Actions",
58
+ "SchemaError",
59
+ "SchemaLimits",
60
+ "SchemaTree",
61
+ "build",
62
+ "build_json",
63
+ "registered_types",
64
+ ]
65
+
66
+ NODE_KEYS: Final = frozenset(
67
+ {"type", "props", "children", "slots", "on", "key", "provider", "item"}
68
+ )
69
+ NAME_RE: Final = re.compile(r"^[a-z][a-z0-9_.\-]{0,63}$")
70
+ KEY_RE: Final = re.compile(r"^[A-Za-z][A-Za-z0-9_\-]{0,63}$")
71
+ # Types a schema may never create: application-defined frontend code and
72
+ # DOM-escaping helpers. Everything else comes from the typed registry.
73
+ DENIED_TYPES: Final = frozenset({"CustomComponent", "Portal", "FocusTrap", "Hotkeys", "Page"})
74
+ # Props a schema may never set (trusted markup bypasses sanitising).
75
+ DENIED_PROPS: Final = frozenset({"trusted"})
76
+ # Markup props the component itself sanitizes in the page (DOMPurify): they
77
+ # carry untrusted documents, so they are screened by the sanitizer instead of
78
+ # being rejected for containing tags.
79
+ SANITIZED_PROPS: Final = frozenset({("Html", "html")})
80
+ _EXEC_RE: Final = re.compile(
81
+ r"(?i)(?:^|[\s\"'=(])(?:javascript|vbscript|livescript)\s*:|data\s*:\s*(?:text/html|application/|image/svg)|<\s*script|<[^>]*\son[a-z]+\s*=|expression\s*\("
82
+ )
83
+
84
+
85
+ class SchemaError(ValidationError):
86
+ """An invalid schema; ``path`` points at the offending node or value."""
87
+
88
+ def __init__(self, path: str, message: str) -> None:
89
+ super().__init__(f"{path}: {message}")
90
+ self.path = path
91
+
92
+
93
+ @dataclass(frozen=True)
94
+ class SchemaLimits:
95
+ """Bounds of one schema (applied before anything is built)."""
96
+
97
+ max_bytes: int = 256 * 1024
98
+ max_nodes: int = 2_000
99
+ max_depth: int = 24
100
+ max_string: int = 20_000
101
+ max_args_bytes: int = 4_096
102
+
103
+
104
+ @dataclass
105
+ class ActionEvent:
106
+ """What a registered action receives: the action ``name`` and its static
107
+ ``args`` from the schema, the component event that triggered it
108
+ (``event``, e.g. a ``RowActionEvent``), the ``sender`` and, for form
109
+ submissions, the validated ``values``."""
110
+
111
+ name: str
112
+ args: dict[str, Any]
113
+ event: Event | None
114
+ sender: Component | None
115
+ values: dict[str, Any] = field(default_factory=dict[str, Any])
116
+
117
+
118
+ class Actions:
119
+ """Registry of named Python actions and table data providers a schema may
120
+ reference. Handlers take no argument or one :class:`ActionEvent`; sync
121
+ handlers run on a worker thread, async ones on the loop (like any UI
122
+ callback)."""
123
+
124
+ def __init__(self) -> None:
125
+ self._actions: dict[str, Callable[..., Any]] = {}
126
+ self._providers: dict[str, Callable[..., Any]] = {}
127
+
128
+ def add(self, name: str, fn: Callable[..., Any]) -> None:
129
+ if not NAME_RE.fullmatch(name):
130
+ raise ValidationError(f"invalid action name {name!r}")
131
+ if name in self._actions:
132
+ raise ValidationError(f"action {name!r} is already registered")
133
+ handler_arity(fn) # 0 or 1 positional argument, checked now
134
+ self._actions[name] = fn
135
+
136
+ def action(self, name: str) -> Callable[[Callable[..., Any]], Callable[..., Any]]:
137
+ """Decorator: ``@actions.action("save")``."""
138
+
139
+ def deco(fn: Callable[..., Any]) -> Callable[..., Any]:
140
+ self.add(name, fn)
141
+ return fn
142
+
143
+ return deco
144
+
145
+ def add_provider(self, name: str, fn: Callable[..., Any]) -> None:
146
+ """A DataTable provider (``TableQuery -> TablePage``) usable as ``"provider": name``."""
147
+ if not NAME_RE.fullmatch(name):
148
+ raise ValidationError(f"invalid provider name {name!r}")
149
+ if not callable(fn): # pyright: ignore[reportUnnecessaryIsInstance]
150
+ raise ValidationError("provider must be callable")
151
+ self._providers[name] = fn
152
+
153
+ def __contains__(self, name: object) -> bool:
154
+ return name in self._actions
155
+
156
+ def names(self) -> list[str]:
157
+ return sorted(self._actions)
158
+
159
+ def _handler(self, name: str, args: dict[str, Any], event_name: str) -> Callable[..., Any]:
160
+ fn = self._actions[name]
161
+ wants = handler_arity(fn) == 1
162
+
163
+ def make(ev: Event) -> ActionEvent:
164
+ values = getattr(ev, "values", None)
165
+ return ActionEvent(
166
+ name=name,
167
+ args=dict(args),
168
+ event=ev,
169
+ sender=ev.sender,
170
+ values=dict(cast("dict[str, Any]", values)) if isinstance(values, dict) else {},
171
+ )
172
+
173
+ if inspect.iscoroutinefunction(fn):
174
+
175
+ async def run_async(ev: Event) -> Any:
176
+ return await (fn(make(ev)) if wants else fn())
177
+
178
+ run_async.__name__ = f"action:{name}"
179
+ return run_async
180
+
181
+ def run(ev: Event) -> Any:
182
+ return fn(make(ev)) if wants else fn()
183
+
184
+ run.__name__ = f"action:{name}"
185
+ return run
186
+
187
+
188
+ @dataclass
189
+ class SchemaTree:
190
+ """A built tree: ``root`` plus the components named by ``key``."""
191
+
192
+ root: Component
193
+ refs: dict[str, Component]
194
+ placeholders: list[str]
195
+
196
+
197
+ def registered_types() -> dict[str, type[Component]]:
198
+ """Component types a schema may use (the typed registry minus denied ones)."""
199
+ from . import components as comps
200
+
201
+ out: dict[str, type[Component]] = {}
202
+ for name in comps.__all__:
203
+ cls = getattr(comps, name, None)
204
+ if (
205
+ isinstance(cls, type)
206
+ and issubclass(cls, Component)
207
+ and getattr(cls, "TYPE", None) == name
208
+ and name not in DENIED_TYPES
209
+ ):
210
+ out[name] = cls
211
+ return out
212
+
213
+
214
+ def _check_strings(v: Any, path: str, limits: SchemaLimits) -> None:
215
+ stack: list[tuple[Any, str]] = [(v, path)]
216
+ while stack:
217
+ x, p = stack.pop()
218
+ if isinstance(x, str):
219
+ if len(x) > limits.max_string:
220
+ raise SchemaError(p, f"text longer than {limits.max_string} characters")
221
+ if _EXEC_RE.search(x):
222
+ raise SchemaError(
223
+ p, "executable content (script, javascript: URL or inline handler)"
224
+ )
225
+ elif isinstance(x, Mapping):
226
+ for k, item in cast("Mapping[str, Any]", x).items():
227
+ if k.startswith("__"):
228
+ raise SchemaError(p, f"reserved key {k!r}")
229
+ stack.append((item, f"{p}.{k}"))
230
+ elif isinstance(x, list):
231
+ for i, item in enumerate(cast("list[Any]", x)):
232
+ stack.append((item, f"{p}[{i}]"))
233
+
234
+
235
+ def _preflight(spec: Any, limits: SchemaLimits) -> None:
236
+ if not isinstance(spec, Mapping):
237
+ raise SchemaError("root", "a schema is an object with a type")
238
+ try:
239
+ check_value(spec, max_depth=limits.max_depth * 4, path="root")
240
+ except ValidationError as err:
241
+ raise SchemaError("root", f"not plain bounded JSON ({err})") from None
242
+ size = len(json.dumps(spec, separators=(",", ":"), ensure_ascii=False).encode())
243
+ if size > limits.max_bytes:
244
+ raise SchemaError("root", f"schema is {size} bytes (limit {limits.max_bytes})")
245
+
246
+
247
+ Unknown = Literal["error", "placeholder"]
248
+
249
+
250
+ class _Builder:
251
+ def __init__(
252
+ self,
253
+ actions: Actions | None,
254
+ limits: SchemaLimits,
255
+ unknown: Unknown,
256
+ types: Mapping[str, type[Component]],
257
+ ) -> None:
258
+ self.actions = actions or Actions()
259
+ self.limits = limits
260
+ self.unknown: Unknown = unknown
261
+ self.types = types
262
+ self.nodes = 0
263
+ self.refs: dict[str, Component] = {}
264
+ self.placeholders: list[str] = []
265
+
266
+ def node(self, spec: Any, path: str, depth: int) -> Component:
267
+ if depth > self.limits.max_depth:
268
+ raise SchemaError(path, f"nested deeper than {self.limits.max_depth}")
269
+ self.nodes += 1
270
+ if self.nodes > self.limits.max_nodes:
271
+ raise SchemaError(path, f"more than {self.limits.max_nodes} nodes")
272
+ if not isinstance(spec, Mapping):
273
+ raise SchemaError(path, "a node is an object with a type")
274
+ m = cast("Mapping[str, Any]", spec)
275
+ bad = set(m) - NODE_KEYS
276
+ if bad:
277
+ raise SchemaError(path, f"unknown node keys {sorted(bad)}")
278
+ tname = m.get("type")
279
+ if not isinstance(tname, str):
280
+ raise SchemaError(path, "type must be a string")
281
+ cls = self.types.get(tname)
282
+ if cls is None:
283
+ if self.unknown == "placeholder" and re.fullmatch(
284
+ r"[A-Za-z][A-Za-z0-9_.\-]{0,63}", tname
285
+ ):
286
+ self.placeholders.append(f"{path}:{tname}")
287
+ return self._placeholder(tname)
288
+ raise SchemaError(path, f"unknown or not allowed component type {tname!r}")
289
+ props = m.get("props", {})
290
+ if not isinstance(props, Mapping):
291
+ raise SchemaError(f"{path}.props", "props must be an object")
292
+ props = dict(cast("Mapping[str, Any]", props))
293
+ allowed = set(cls.PROPS) | set(Component._COMMON) # pyright: ignore[reportPrivateUsage]
294
+ for k in props:
295
+ if k in DENIED_PROPS or k.startswith(("on_", "_")) or k not in allowed:
296
+ raise SchemaError(f"{path}.props.{k}", f"{tname} has no schema prop {k!r}")
297
+ _check_strings(
298
+ {k: v for k, v in props.items() if (tname, k) not in SANITIZED_PROPS},
299
+ f"{path}.props",
300
+ self.limits,
301
+ )
302
+ kwargs: dict[str, Any] = dict(props)
303
+ # DataTable data comes from a registered provider, never from the schema.
304
+ if "provider" in m:
305
+ pname = m["provider"]
306
+ if "provider" not in inspect.signature(cls.__init__).parameters:
307
+ raise SchemaError(f"{path}.provider", f"{tname} takes no provider")
308
+ fn = self.actions._providers.get(pname) if isinstance(pname, str) else None # pyright: ignore[reportPrivateUsage]
309
+ if fn is None:
310
+ raise SchemaError(f"{path}.provider", f"provider {pname!r} is not registered")
311
+ kwargs["provider"] = fn
312
+ if "item" in m:
313
+ if tname != "FieldList":
314
+ raise SchemaError(f"{path}.item", "only a FieldList has an item template")
315
+ items = m["item"]
316
+ if not isinstance(items, list):
317
+ raise SchemaError(f"{path}.item", "item is a list of nodes")
318
+ item_specs = cast("list[Any]", items)
319
+
320
+ def template(specs: list[Any] = item_specs, p: str = path, d: int = depth) -> None:
321
+ # called inside the new FieldListItem: build and attach there
322
+ from ._component import _build_stack # pyright: ignore[reportPrivateUsage]
323
+
324
+ sub = _Builder(self.actions, self.limits, self.unknown, self.types)
325
+ built = [sub.node(s, f"{p}.item[{i}]", d + 1) for i, s in enumerate(specs)]
326
+ stack = _build_stack.get()
327
+ for c in built:
328
+ stack[-1].add(c)
329
+
330
+ # validate the item nodes once now (the template rebuilds them per item)
331
+ probe = _Builder(self.actions, self.limits, self.unknown, self.types)
332
+ probe.nodes = self.nodes
333
+ for i, s in enumerate(item_specs):
334
+ probe.node(s, f"{path}.item[{i}]", depth + 1).remove()
335
+ self.nodes = probe.nodes
336
+
337
+ kwargs["template"] = template
338
+ try:
339
+ with detached():
340
+ comp = cls(**kwargs)
341
+ except ValidationError as err:
342
+ raise SchemaError(f"{path}.props", str(err)) from None
343
+ except TypeError as err:
344
+ raise SchemaError(f"{path}.props", f"invalid props for {tname}: {err}") from None
345
+ for ev_name, binding in self._bindings(m.get("on"), cls, path):
346
+ action, args = binding
347
+ comp.on(ev_name, self.actions._handler(action, args, ev_name)) # pyright: ignore[reportPrivateUsage]
348
+ kids = m.get("children", [])
349
+ if not isinstance(kids, list):
350
+ raise SchemaError(f"{path}.children", "children is a list of nodes")
351
+ if kids and not cls.CHILDREN:
352
+ raise SchemaError(f"{path}.children", f"{tname} takes no children")
353
+ for i, k in enumerate(cast("list[Any]", kids)):
354
+ comp.add(self.node(k, f"{path}.children[{i}]", depth + 1))
355
+ slots = m.get("slots", {})
356
+ if not isinstance(slots, Mapping):
357
+ raise SchemaError(f"{path}.slots", "slots is an object of node lists")
358
+ for sname, sk in cast("Mapping[str, Any]", slots).items():
359
+ if sname not in cls.SLOTS:
360
+ raise SchemaError(f"{path}.slots.{sname}", f"{tname} has no slot {sname!r}")
361
+ if not isinstance(sk, list):
362
+ raise SchemaError(f"{path}.slots.{sname}", "a slot is a list of nodes")
363
+ for i, k in enumerate(cast("list[Any]", sk)):
364
+ comp.add(self.node(k, f"{path}.slots.{sname}[{i}]", depth + 1), slot=sname)
365
+ key = m.get("key")
366
+ if key is not None:
367
+ if not isinstance(key, str) or not KEY_RE.fullmatch(key):
368
+ raise SchemaError(f"{path}.key", "key: letters, digits, '_' and '-'")
369
+ if key in self.refs:
370
+ raise SchemaError(f"{path}.key", f"duplicate key {key!r}")
371
+ self.refs[key] = comp
372
+ return comp
373
+
374
+ def _bindings(
375
+ self, on: Any, cls: type[Component], path: str
376
+ ) -> list[tuple[str, tuple[str, dict[str, Any]]]]:
377
+ if on is None:
378
+ return []
379
+ if not isinstance(on, Mapping):
380
+ raise SchemaError(f"{path}.on", "on is an object {event: action}")
381
+ out: list[tuple[str, tuple[str, dict[str, Any]]]] = []
382
+ for ev_name, b in cast("Mapping[str, Any]", on).items():
383
+ p = f"{path}.on.{ev_name}"
384
+ if ev_name not in cls.EVENTS:
385
+ raise SchemaError(p, f"{cls.TYPE} has no event {ev_name!r}")
386
+ if isinstance(b, str):
387
+ action, args = b, {}
388
+ elif isinstance(b, Mapping):
389
+ bm = cast("Mapping[str, Any]", b)
390
+ if set(bm) - {"action", "args"}:
391
+ raise SchemaError(p, "a binding is {action, args}")
392
+ action, args = bm.get("action"), bm.get("args", {})
393
+ else:
394
+ raise SchemaError(p, "a binding is an action name or {action, args}")
395
+ if not isinstance(action, str) or action not in self.actions:
396
+ raise SchemaError(p, f"action {action!r} is not registered")
397
+ if not isinstance(args, Mapping):
398
+ raise SchemaError(f"{p}.args", "args is an object")
399
+ _check_strings(args, f"{p}.args", self.limits)
400
+ if len(json.dumps(args)) > self.limits.max_args_bytes:
401
+ raise SchemaError(
402
+ f"{p}.args", f"args larger than {self.limits.max_args_bytes} bytes"
403
+ )
404
+ out.append((ev_name, (action, dict(cast("Mapping[str, Any]", args)))))
405
+ return out
406
+
407
+ def _placeholder(self, tname: str) -> Component:
408
+ from .components import Alert
409
+
410
+ with detached():
411
+ return Alert(
412
+ title="Unsupported content",
413
+ text=f"This view contains a block of type '{tname}' that this app cannot show.",
414
+ color="gray",
415
+ variant="light",
416
+ )
417
+
418
+
419
+ def build(
420
+ spec: Mapping[str, Any],
421
+ *,
422
+ actions: Actions | None = None,
423
+ unknown: Literal["error", "placeholder"] = "error",
424
+ limits: SchemaLimits | None = None,
425
+ types: Sequence[str] | None = None,
426
+ ) -> SchemaTree:
427
+ """Validate ``spec`` and build its component tree.
428
+
429
+ Built inside a container's ``with`` block, the root attaches there like
430
+ any component; otherwise it is detached (``parent.add(tree.root)``).
431
+ ``types`` narrows the allowed component types further (an allowlist).
432
+ The whole schema is validated before anything is attached: on error
433
+ nothing is added and :class:`SchemaError` names the path."""
434
+ from ._component import TREE_LOCK, _build_stack # pyright: ignore[reportPrivateUsage]
435
+
436
+ if unknown not in ("error", "placeholder"):
437
+ raise ValidationError("unknown must be 'error' or 'placeholder'")
438
+ lim = limits or SchemaLimits()
439
+ _preflight(spec, lim)
440
+ reg = registered_types()
441
+ if types is not None:
442
+ extra = set(types) - set(reg)
443
+ if extra:
444
+ raise ValidationError(f"not registered types: {sorted(extra)}")
445
+ reg = {k: v for k, v in reg.items() if k in set(types)}
446
+ b = _Builder(actions, lim, unknown, reg)
447
+ root = b.node(spec, "root", 0)
448
+ stack = _build_stack.get()
449
+ if stack:
450
+ with TREE_LOCK:
451
+ stack[-1].add(root)
452
+ return SchemaTree(root=root, refs=b.refs, placeholders=b.placeholders)
453
+
454
+
455
+ def build_json(
456
+ text: str | bytes,
457
+ *,
458
+ actions: Actions | None = None,
459
+ unknown: Literal["error", "placeholder"] = "error",
460
+ limits: SchemaLimits | None = None,
461
+ types: Sequence[str] | None = None,
462
+ ) -> SchemaTree:
463
+ """:func:`build` from JSON text (size checked before parsing; NaN and
464
+ duplicate keys rejected)."""
465
+ lim = limits or SchemaLimits()
466
+ raw = text.encode() if isinstance(text, str) else text
467
+ if len(raw) > lim.max_bytes:
468
+ raise SchemaError("root", f"schema is {len(raw)} bytes (limit {lim.max_bytes})")
469
+
470
+ def no_dupes(pairs: list[tuple[str, Any]]) -> dict[str, Any]:
471
+ d: dict[str, Any] = {}
472
+ for k, v in pairs:
473
+ if k in d:
474
+ raise SchemaError("root", f"duplicate key {k!r}")
475
+ d[k] = v
476
+ return d
477
+
478
+ def no_const(c: str) -> Any:
479
+ raise SchemaError("root", f"{c} is not JSON")
480
+
481
+ try:
482
+ spec = json.loads(raw, object_pairs_hook=no_dupes, parse_constant=no_const)
483
+ except (ValueError, RecursionError) as err:
484
+ if isinstance(err, SchemaError):
485
+ raise
486
+ raise SchemaError("root", f"invalid JSON ({type(err).__name__})") from None
487
+ return build(spec, actions=actions, unknown=unknown, limits=lim, types=types)
488
+
489
+
490
+ # ---------------------------------------------------------------- dynamic forms
491
+ FIELD_KEYS: Final = frozenset(
492
+ {
493
+ "name",
494
+ "type",
495
+ "label",
496
+ "description",
497
+ "placeholder",
498
+ "default",
499
+ "required",
500
+ "options",
501
+ "min",
502
+ "max",
503
+ "min_length",
504
+ "max_length",
505
+ "pattern",
506
+ "pattern_message",
507
+ "matches_field",
508
+ "message",
509
+ "visible_when",
510
+ "fields",
511
+ "min_items",
512
+ "max_items",
513
+ "add_label",
514
+ "sync",
515
+ "disabled",
516
+ }
517
+ )
518
+ FORM_KEYS: Final = frozenset(
519
+ {"fields", "submit_label", "reset_label", "cancelable", "validate_on", "submit_action"}
520
+ )
521
+ FIELD_TYPES: Final = (
522
+ "text",
523
+ "email",
524
+ "password",
525
+ "textarea",
526
+ "number",
527
+ "integer",
528
+ "select",
529
+ "multiselect",
530
+ "segmented",
531
+ "checkbox",
532
+ "switch",
533
+ "date",
534
+ "group",
535
+ "list",
536
+ )
537
+ MAX_FORM_FIELDS: Final = 1_000
538
+ _DATE_RE: Final = re.compile(r"^\d{4}-\d{2}-\d{2}$")
539
+
540
+
541
+ def _iso_date_rule() -> Any:
542
+ import datetime as _dt
543
+
544
+ from .validators import Rule
545
+
546
+ def check(v: Any, _: Mapping[str, Any]) -> bool:
547
+ return (
548
+ isinstance(v, str) and bool(_DATE_RE.fullmatch(v)) and bool(_dt.date.fromisoformat(v))
549
+ )
550
+
551
+ return Rule("date", check, "Use a date like 2024-12-31")
552
+
553
+
554
+ def _predicate(spec: Any, path: str) -> Callable[[Mapping[str, Any]], bool]:
555
+ """``visible_when`` as data: ``{field, equals | not_equals | in | not_empty}``."""
556
+ from .validators import _lookup # pyright: ignore[reportPrivateUsage]
557
+
558
+ if not isinstance(spec, Mapping):
559
+ raise SchemaError(path, "visible_when is {field, equals|not_equals|in|not_empty}")
560
+ m = cast("Mapping[str, Any]", spec)
561
+ ops = set(m) - {"field"}
562
+ if (
563
+ not isinstance(m.get("field"), str)
564
+ or len(ops) != 1
565
+ or not ops
566
+ <= {
567
+ "equals",
568
+ "not_equals",
569
+ "in",
570
+ "not_empty",
571
+ }
572
+ ):
573
+ raise SchemaError(path, "visible_when is {field, equals|not_equals|in|not_empty}")
574
+ target: str = m["field"]
575
+ op = ops.pop()
576
+ arg = m[op]
577
+ if op == "in" and not isinstance(arg, list):
578
+ raise SchemaError(path, "visible_when.in must be a list")
579
+ if op == "not_empty" and arg is not True:
580
+ raise SchemaError(path, "visible_when.not_empty must be true")
581
+
582
+ def when(values: Mapping[str, Any]) -> bool:
583
+ v = _lookup(values, target)
584
+ if op == "equals":
585
+ return v == arg
586
+ if op == "not_equals":
587
+ return v != arg
588
+ if op == "in":
589
+ return v in cast("list[Any]", arg)
590
+ return v not in (None, "", [], False)
591
+
592
+ return when
593
+
594
+
595
+ class _FormBuilder:
596
+ def __init__(self, limits: SchemaLimits) -> None:
597
+ self.limits = limits
598
+ self.count = 0
599
+ self.conditions: list[tuple[Component, Callable[[Mapping[str, Any]], bool]]] = []
600
+
601
+ def fields(self, specs: Any, path: str, depth: int) -> None:
602
+ if not isinstance(specs, list) or not specs:
603
+ raise SchemaError(path, "fields is a non-empty list")
604
+ if depth > 6:
605
+ raise SchemaError(path, "groups/lists nested deeper than 6")
606
+ names: set[str] = set()
607
+ for i, f in enumerate(cast("list[Any]", specs)):
608
+ self.field(f, f"{path}[{i}]", depth, names)
609
+
610
+ def field(self, spec: Any, path: str, depth: int, names: set[str]) -> None:
611
+ from . import components as c
612
+ from . import validators as v
613
+
614
+ self.count += 1
615
+ if self.count > MAX_FORM_FIELDS:
616
+ raise SchemaError(path, f"more than {MAX_FORM_FIELDS} fields")
617
+ if not isinstance(spec, Mapping):
618
+ raise SchemaError(path, "a field is an object")
619
+ m = cast("Mapping[str, Any]", spec)
620
+ bad = set(m) - FIELD_KEYS
621
+ if bad:
622
+ raise SchemaError(path, f"unknown field keys {sorted(bad)}")
623
+ _check_strings(m, path, self.limits)
624
+ name, ftype = m.get("name"), m.get("type", "text")
625
+ if not isinstance(name, str) or not re.fullmatch(r"[A-Za-z_][A-Za-z0-9_]{0,63}", name):
626
+ raise SchemaError(f"{path}.name", "a field name: letters, digits and '_'")
627
+ if name in names:
628
+ raise SchemaError(f"{path}.name", f"duplicate field {name!r}")
629
+ names.add(name)
630
+ if ftype not in FIELD_TYPES:
631
+ raise SchemaError(f"{path}.type", f"one of {list(FIELD_TYPES)}")
632
+ rule_keys = ("min", "max", "min_length", "max_length", "pattern", "pattern_message")
633
+ rule_keys += ("matches_field", "message")
634
+ rule_spec: dict[str, Any] = {k: m[k] for k in rule_keys if k in m}
635
+ if ftype not in ("number", "integer") and {"min", "max"} & set(rule_spec):
636
+ raise SchemaError(path, "min/max apply to number fields (use min_length/max_length)")
637
+ common: dict[str, Any] = {"name": name}
638
+ for k in ("label", "description", "placeholder"):
639
+ if k in m:
640
+ common[k] = m[k]
641
+ if "required" in m:
642
+ if not isinstance(m["required"], bool):
643
+ raise SchemaError(f"{path}.required", "expected a boolean")
644
+ common["required"] = m["required"]
645
+ if "disabled" in m:
646
+ common["disabled"] = m["disabled"]
647
+ if "sync" in m:
648
+ common["sync"] = m["sync"]
649
+ options = m.get("options")
650
+ try:
651
+ comp: Component
652
+ with detached():
653
+ if ftype == "group":
654
+ legend: Any = m.get("label", UNSET)
655
+ comp = c.Field(name=name, legend=legend)
656
+ with comp:
657
+ self.fields(m.get("fields"), f"{path}.fields", depth + 1)
658
+ elif ftype == "list":
659
+ item_specs = m.get("fields")
660
+ self._probe(item_specs, f"{path}.fields", depth + 1)
661
+
662
+ def template(specs: Any = item_specs, p: str = path, d: int = depth) -> None:
663
+ sub = _FormBuilder(self.limits)
664
+ sub.fields(specs, f"{p}.fields", d + 1)
665
+
666
+ kw: dict[str, Any] = {"name": name, "template": template}
667
+ for k in ("min_items", "max_items", "add_label", "label", "description"):
668
+ if k in m:
669
+ kw[k] = m[k]
670
+ default = m.get("default", [])
671
+ if not isinstance(default, list):
672
+ raise SchemaError(f"{path}.default", "a list default is a list of objects")
673
+ kw["initial"] = cast("list[Any]", default)
674
+ comp = c.FieldList(**kw)
675
+ else:
676
+ comp = self._input(ftype, common, m, options, rule_spec, path)
677
+ except ValidationError as err:
678
+ if isinstance(err, SchemaError):
679
+ raise
680
+ raise SchemaError(path, str(err)) from None
681
+ if ftype in ("group", "list"):
682
+ if rule_spec:
683
+ raise SchemaError(path, "validation keys apply to inputs, not groups/lists")
684
+ else:
685
+ try:
686
+ rule = v.from_spec(rule_spec) if rule_spec else None
687
+ except ValidationError as err:
688
+ raise SchemaError(path, str(err)) from None
689
+ extra: list[Any] = []
690
+ if ftype == "email":
691
+ extra.append(v.email())
692
+ elif ftype == "integer":
693
+ extra.append(v.integer())
694
+ elif ftype == "date":
695
+ extra.append(_iso_date_rule())
696
+ elif ftype in ("select", "segmented", "multiselect") and options is not None:
697
+ extra.append(v.one_of(cast("list[Any]", options)))
698
+ rules = [r for r in (*extra, rule) if r is not None]
699
+ if rules:
700
+ cast("Any", comp).validator = rules[0] if len(rules) == 1 else v.all_of(*rules)
701
+ if "visible_when" in m:
702
+ self.conditions.append((comp, _predicate(m["visible_when"], f"{path}.visible_when")))
703
+ from ._component import _build_stack # pyright: ignore[reportPrivateUsage]
704
+
705
+ _build_stack.get()[-1].add(comp)
706
+
707
+ def _probe(self, specs: Any, path: str, depth: int) -> None:
708
+ from .components import FieldListItem
709
+
710
+ with detached():
711
+ probe = FieldListItem()
712
+ sub = _FormBuilder(self.limits)
713
+ sub.count = self.count
714
+ with probe:
715
+ sub.fields(specs, path, depth)
716
+ self.count = sub.count
717
+ probe.remove()
718
+
719
+ def _input(
720
+ self,
721
+ ftype: str,
722
+ common: dict[str, Any],
723
+ m: Mapping[str, Any],
724
+ options: Any,
725
+ rule_spec: dict[str, Any],
726
+ path: str,
727
+ ) -> Component:
728
+ from . import components as c
729
+
730
+ default = m.get("default")
731
+ if ftype in ("select", "multiselect", "segmented"):
732
+ if not isinstance(options, list) or not options:
733
+ raise SchemaError(f"{path}.options", f"a {ftype} needs options")
734
+ elif options is not None:
735
+ raise SchemaError(f"{path}.options", f"a {ftype} field has no options")
736
+ kw = dict(common)
737
+ opts: Any = cast("Any", options)
738
+ if ftype in ("text", "email", "date", "password", "textarea"):
739
+ if "max_length" in rule_spec and ftype != "password":
740
+ kw["max_length"] = rule_spec["max_length"]
741
+ cls = {"password": c.PasswordInput, "textarea": c.Textarea}.get(ftype, c.TextInput)
742
+ return cls(value="" if default is None else default, **kw)
743
+ if ftype in ("number", "integer"):
744
+ for k in ("min", "max"):
745
+ if k in rule_spec:
746
+ kw[k] = rule_spec[k]
747
+ if ftype == "integer":
748
+ kw["allow_decimal"] = False
749
+ return c.NumberInput(**({"value": default} if default is not None else {}), **kw)
750
+ if ftype == "select":
751
+ if default is not None:
752
+ kw["value"] = default
753
+ return c.Select(data=opts, **kw)
754
+ if ftype == "multiselect":
755
+ return c.MultiSelect(data=opts, value=default if default is not None else [], **kw)
756
+ if ftype == "segmented":
757
+ kw.pop("label", None)
758
+ kw.pop("description", None)
759
+ kw.pop("placeholder", None)
760
+ kw.pop("required", None)
761
+ return c.SegmentedControl(
762
+ data=opts, value=default if default is not None else opts[0], **kw
763
+ )
764
+ kw.pop("placeholder", None)
765
+ cls2 = c.Checkbox if ftype == "checkbox" else c.Switch
766
+ return cls2(checked=bool(default) if default is not None else False, **kw)
767
+
768
+
769
+ def build_form(
770
+ schema: Mapping[str, Any],
771
+ *,
772
+ form_cls: type[Component] | None = None,
773
+ actions: Actions | None = None,
774
+ on_submit: Callable[..., Any] | None = None,
775
+ validate: Callable[[dict[str, Any]], Any] | None = None,
776
+ limits: SchemaLimits | None = None,
777
+ ) -> Component:
778
+ """A ``ui.Form`` from a declarative form schema (see ``Form.from_schema``)."""
779
+ from . import components as c
780
+
781
+ lim = limits or SchemaLimits()
782
+ _preflight(schema, lim)
783
+ bad = set(schema) - FORM_KEYS
784
+ if bad:
785
+ raise SchemaError("form", f"unknown form keys {sorted(bad)}")
786
+ _check_strings({k: v for k, v in schema.items() if k != "fields"}, "form", lim)
787
+ cls = form_cls or c.Form
788
+ kw: dict[str, Any] = {}
789
+ for k in ("cancelable", "validate_on"):
790
+ if k in schema:
791
+ kw[k] = schema[k]
792
+ handlers: list[Callable[..., Any]] = []
793
+ if on_submit is not None:
794
+ handlers.append(on_submit)
795
+ sa = schema.get("submit_action")
796
+ if sa is not None:
797
+ if actions is None or not isinstance(sa, str) or sa not in actions:
798
+ raise SchemaError("form.submit_action", f"action {sa!r} is not registered")
799
+ handlers.append(actions._handler(sa, {}, "submit")) # pyright: ignore[reportPrivateUsage]
800
+ try:
801
+ with detached():
802
+ form = cls(validate=validate, **kw) # type: ignore[call-arg]
803
+ except ValidationError as err:
804
+ raise SchemaError("form", str(err)) from None
805
+ fb = _FormBuilder(lim)
806
+ with cast("Any", form):
807
+ fb.fields(schema.get("fields"), "form.fields", 0)
808
+ with c.Group(gap="xs"):
809
+ c.Button(str(schema.get("submit_label", "Submit")), type="submit")
810
+ if "reset_label" in schema:
811
+ c.Button(str(schema["reset_label"]), type="reset", variant="default")
812
+ for h in handlers:
813
+ form.on("submit", h)
814
+ from ._bases import FormComponent
815
+
816
+ assert isinstance(form, FormComponent)
817
+ for comp, when in fb.conditions:
818
+ form.show_when(comp, when)
819
+ from ._component import _build_stack # pyright: ignore[reportPrivateUsage]
820
+
821
+ stack = _build_stack.get()
822
+ if stack:
823
+ stack[-1].add(form)
824
+ return form