neutralino-python 0.1.0rc1__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-C2NUKJAE.js +1 -0
  315. neutralino/_data/renderer/assets/carousel-D1j1SkWR.css +1 -0
  316. neutralino/_data/renderer/assets/carousel-DHnOKa8c.js +1 -0
  317. neutralino/_data/renderer/assets/chunk-CCkLOSkX.css +1 -0
  318. neutralino/_data/renderer/assets/chunk-CLVygP7p.js +9 -0
  319. neutralino/_data/renderer/assets/codehighlight-CXJaU0yv.js +10 -0
  320. neutralino/_data/renderer/assets/codehighlight-THJMNDh8.css +1 -0
  321. neutralino/_data/renderer/assets/codemirror-DX0MbxKq.js +2 -0
  322. neutralino/_data/renderer/assets/css-BotC7byr.js +1 -0
  323. neutralino/_data/renderer/assets/dist-3kB5bJpS.js +23 -0
  324. neutralino/_data/renderer/assets/dist-6zrr4MrK.js +1 -0
  325. neutralino/_data/renderer/assets/dist-Beotrn8G.js +1 -0
  326. neutralino/_data/renderer/assets/dist-CCJHv8n0.js +11 -0
  327. neutralino/_data/renderer/assets/dist-CdYA9or5.js +1 -0
  328. neutralino/_data/renderer/assets/dist-D2p_6o_g.js +1 -0
  329. neutralino/_data/renderer/assets/dnd-DkNumIKC.js +5 -0
  330. neutralino/_data/renderer/assets/dropzone-aPCBPjDN.css +1 -0
  331. neutralino/_data/renderer/assets/dropzone-agrigkXv.js +1 -0
  332. neutralino/_data/renderer/assets/embla-carousel-react.esm-_ztrE73N.js +1 -0
  333. neutralino/_data/renderer/assets/emoji-Cj3VQHg8.js +1 -0
  334. neutralino/_data/renderer/assets/emoji-DV8OzU1E.css +1 -0
  335. neutralino/_data/renderer/assets/esm-DbOmMyz5.js +82 -0
  336. neutralino/_data/renderer/assets/highlight-Dlb5DJwL.css +1 -0
  337. neutralino/_data/renderer/assets/highlight-LH6Cyuz6.js +3 -0
  338. neutralino/_data/renderer/assets/html-CpATC083.js +1 -0
  339. neutralino/_data/renderer/assets/icon-chunk-C-4QDF6w.js +1 -0
  340. neutralino/_data/renderer/assets/index-CqHW60Dy.js +69 -0
  341. neutralino/_data/renderer/assets/index-TWpF4Lef.css +1 -0
  342. neutralino/_data/renderer/assets/javascript-D2QSKlDI.js +1 -0
  343. neutralino/_data/renderer/assets/json-D8zfYii3.js +1 -0
  344. neutralino/_data/renderer/assets/lightbox-BijRfmPy.js +1 -0
  345. neutralino/_data/renderer/assets/lightbox-BzKDpkAD.css +1 -0
  346. neutralino/_data/renderer/assets/markdown-Cpthnhzg.js +77 -0
  347. neutralino/_data/renderer/assets/markdown-CsS2tf5C.js +5 -0
  348. neutralino/_data/renderer/assets/python-B477ud9A.js +9 -0
  349. neutralino/_data/renderer/assets/richtext-BwtgvH7-.js +137 -0
  350. neutralino/_data/renderer/assets/richtext-DIAsHMuK.css +1 -0
  351. neutralino/_data/renderer/assets/spotlight-Ccstaz1-.css +1 -0
  352. neutralino/_data/renderer/assets/spotlight-Db1pwUWd.js +1 -0
  353. neutralino/_data/renderer/assets/sql-DbpHRl6F.js +2 -0
  354. neutralino/_data/renderer/assets/with-selector-CUfuSYau.js +1 -0
  355. neutralino/_data/renderer/assets/yaml-BPsr1O3S.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 +1261 -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.0rc1.dist-info/METADATA +117 -0
  516. neutralino_python-0.1.0rc1.dist-info/RECORD +521 -0
  517. neutralino_python-0.1.0rc1.dist-info/WHEEL +4 -0
  518. neutralino_python-0.1.0rc1.dist-info/entry_points.txt +3 -0
  519. neutralino_python-0.1.0rc1.dist-info/licenses/LICENSE +21 -0
  520. neutralino_python-0.1.0rc1.dist-info/licenses/THIRD_PARTY_NOTICES.md +16 -0
  521. neutralino_python-0.1.0rc1.dist-info/licenses/src/neutralino/_data/renderer/LICENSES/packages.json +1838 -0
@@ -0,0 +1,1210 @@
1
+ """Behavioural base classes used by generated components.
2
+
3
+ Generated wrappers (``components/_generated.py``) only declare contracts and
4
+ typed signatures; the behaviour of inputs, overlays, forms, tables and charts
5
+ lives here.
6
+ """
7
+
8
+ from __future__ import annotations
9
+
10
+ import asyncio
11
+ import inspect
12
+ import json
13
+ import logging
14
+ import re
15
+ from collections import deque
16
+ from collections.abc import Awaitable, Callable, Mapping, Sequence
17
+ from dataclasses import dataclass, field
18
+ from typing import TYPE_CHECKING, Any, ClassVar, Literal, cast
19
+
20
+ from ..errors import NeutralinoError, RpcError, ValidationError
21
+ from ..types import UNSET, Unset
22
+ from . import _charts
23
+ from ._component import TREE_LOCK, Component, Container, PropSpec, Subscription, convert
24
+ from ._events import ChangeEvent, Event, RowActionEvent, SubmitEvent, TableEvent
25
+ from ._protocol import check_value, to_wire
26
+ from .validators import FieldError
27
+
28
+ if TYPE_CHECKING:
29
+ from ._forms import FormLayout
30
+ from ._session import WindowSession
31
+
32
+ __all__ = [
33
+ "MAX_CUSTOM_EVENT_BYTES",
34
+ "ChartComponent",
35
+ "CustomBase",
36
+ "CustomComponentError",
37
+ "FormComponent",
38
+ "HotkeysBase",
39
+ "OverlayComponent",
40
+ "TableComponent",
41
+ "TablePage",
42
+ "TableQuery",
43
+ "ValueComponent",
44
+ "ValueContainer",
45
+ ]
46
+
47
+ log = logging.getLogger("neutralino.ui")
48
+
49
+ Validator = Callable[..., Any]
50
+ """``validator(value)`` or ``validator(value, values)`` (values of the whole
51
+ form by path) returning ``None`` when valid or an error (``str`` or
52
+ ``ui.validators.FieldError``), possibly awaitable."""
53
+
54
+ SyncPolicy = Literal["change", "debounce", "blur"]
55
+ SYNC_POLICIES: tuple[str, ...] = ("change", "debounce", "blur")
56
+
57
+
58
+ def _window_or_raise(comp: Component) -> WindowSession:
59
+ w = comp._window # pyright: ignore[reportPrivateUsage]
60
+ if w is None or not w.live:
61
+ raise RpcError("DISCONNECTED", f"{comp!r} is not shown in a mounted window")
62
+ return w
63
+
64
+
65
+ class ValueComponent(Component):
66
+ """An input with a committed ``value`` owned by Python.
67
+
68
+ The page keeps the draft while the user types and commits it according to
69
+ ``SYNC`` (``change``: every change, ``debounce``: after a pause and on
70
+ blur, ``blur``: on blur only). Form submissions always carry the current
71
+ draft. Assigning ``value`` from Python wins: the page replaces the draft
72
+ and drops older pending edits (edit revisions, ``vrev``).
73
+ """
74
+
75
+ VALUE_PROP: ClassVar[str] = "value"
76
+ CHANGE_EVENT: ClassVar[str] = "change"
77
+ SYNC: ClassVar[str] = "change"
78
+
79
+ _VALUE_COMMON: ClassVar[Mapping[str, PropSpec]] = {
80
+ # Per-instance commit policy (overrides the contract's ``SYNC``).
81
+ "sync": PropSpec("sync", "sync", "enum", values=SYNC_POLICIES),
82
+ }
83
+
84
+ def __init__(
85
+ self,
86
+ *,
87
+ validator: Validator | None = None,
88
+ sync: SyncPolicy | Unset = UNSET,
89
+ **kw: Any,
90
+ ) -> None:
91
+ super().__init__(**kw)
92
+ self.validator: Validator | None = validator
93
+ if sync is not UNSET:
94
+ self._props["sync"] = convert(self._VALUE_COMMON["sync"], sync)
95
+ # Form state: the value a form ``reset()`` returns to, and whether the
96
+ # user committed a change since (``touched``).
97
+ self._initial: Any = self._props.get(self.VALUE_PROP, UNSET)
98
+ self._touched = False
99
+
100
+ @property
101
+ def touched(self) -> bool:
102
+ """The user committed a change of this input (since construction or
103
+ the last form ``reset``)."""
104
+ return self._touched
105
+
106
+ @property
107
+ def dirty(self) -> bool:
108
+ """The committed value differs from the initial value."""
109
+ return self._props.get(self.VALUE_PROP, UNSET) != self._initial
110
+
111
+ def _form(self) -> FormComponent | None:
112
+ p = self.parent
113
+ while p is not None:
114
+ if isinstance(p, FormComponent):
115
+ return p
116
+ p = p.parent
117
+ return None
118
+
119
+ @classmethod
120
+ def _spec(cls, name: str) -> PropSpec:
121
+ spec = cls._VALUE_COMMON.get(name)
122
+ return spec if spec is not None else super()._spec(name)
123
+
124
+ @property
125
+ def sync(self) -> SyncPolicy:
126
+ """Effective commit policy: ``change`` (every change), ``debounce``
127
+ (after a pause, on blur and before any action) or ``blur`` (on blur,
128
+ Enter and before any action/submit). Form submissions always carry
129
+ the current draft whatever the policy."""
130
+ v = self.get_prop("sync")
131
+ return cast("SyncPolicy", self.SYNC if v is UNSET else v)
132
+
133
+ @sync.setter
134
+ def sync(self, value: SyncPolicy) -> None:
135
+ self.set_prop("sync", value)
136
+
137
+ def _value_prop(self) -> str | None:
138
+ return self.VALUE_PROP
139
+
140
+ def _on_client_event(self, name: str, payload: Mapping[str, Any]) -> Event | None:
141
+ if name != self.CHANGE_EVENT:
142
+ return super()._on_client_event(name, payload) # typed payloads are validated
143
+ if "value" not in payload:
144
+ raise ValidationError("change event without value")
145
+ new = payload["value"]
146
+ spec = self._spec(self.VALUE_PROP)
147
+ convert(spec, new) # validates type before committing
148
+ self._check_client_value(new)
149
+ old = self._commit_from_client(self.VALUE_PROP, new)
150
+ self._touched = True
151
+ form = self._form()
152
+ if form is not None:
153
+ form._field_committed(self) # pyright: ignore[reportPrivateUsage]
154
+ return ChangeEvent(
155
+ name=name,
156
+ sender=self,
157
+ payload=dict(payload),
158
+ value=self.get_prop(self.VALUE_PROP),
159
+ previous=None if old is UNSET else self._from_wire(self.VALUE_PROP, old),
160
+ )
161
+
162
+ def _check_client_value(self, value: Any) -> None:
163
+ """Server-side re-check of declared constraints (the page's are advisory)."""
164
+ limit = self._props.get("max_length") if "max_length" in self.PROPS else None
165
+ if isinstance(limit, int) and isinstance(value, str) and len(value) > limit:
166
+ raise ValidationError(f"value longer than max_length {limit}")
167
+ if isinstance(value, bool) or not isinstance(value, (int, float)):
168
+ return
169
+ lo = self._props.get("min") if "min" in self.PROPS else None
170
+ hi = self._props.get("max") if "max" in self.PROPS else None
171
+ if isinstance(lo, (int, float)) and value < lo:
172
+ raise ValidationError(f"value below min {lo}")
173
+ if isinstance(hi, (int, float)) and value > hi:
174
+ raise ValidationError(f"value above max {hi}")
175
+
176
+ def _check_submitted_value(self, value: Any) -> None:
177
+ """The same declared constraints, for a value arriving in a form
178
+ submission (errors go back to the field instead of reverting it)."""
179
+ self._check_client_value(value)
180
+
181
+ async def fetch_value(self) -> Any:
182
+ """Ask the page for the current draft (may be newer than ``value``)."""
183
+ w = _window_or_raise(self)
184
+ result = await w.command(self, "get_value")
185
+ if isinstance(result, Mapping) and "value" in result:
186
+ return cast("Mapping[str, Any]", result)["value"]
187
+ raise RpcError("PROTOCOL_ERROR", "page returned no value")
188
+
189
+ def get_value(self, timeout: float = 10.0) -> Any:
190
+ """Blocking :meth:`fetch_value` for worker threads (refuses the loop thread)."""
191
+ w = _window_or_raise(self)
192
+ loop = w.loop
193
+ assert loop is not None
194
+ try:
195
+ running = asyncio.get_running_loop()
196
+ except RuntimeError:
197
+ running = None
198
+ if running is not None:
199
+ raise RuntimeError(
200
+ "get_value() blocks: use 'await component.fetch_value()' in async code"
201
+ )
202
+ return asyncio.run_coroutine_threadsafe(self.fetch_value(), loop).result(timeout)
203
+
204
+ def reset(self) -> None:
205
+ """Clear the field error (the value is kept; assign ``value`` to change it)."""
206
+ if "error" in self.PROPS:
207
+ self.update(error=UNSET)
208
+
209
+ async def run_validator(
210
+ self, value: Any, values: Mapping[str, Any] | None = None
211
+ ) -> FieldError | None:
212
+ """Run ``validator`` (``(value)`` or ``(value, values)``): ``None`` or a typed error."""
213
+ from ._forms import run_validator
214
+
215
+ return await run_validator(self.validator, value, values or {}, self._window)
216
+
217
+
218
+ class ValueContainer(ValueComponent, Container):
219
+ """A value input that also holds children (RadioGroup, CheckboxGroup, ...)."""
220
+
221
+ CHILDREN: ClassVar[bool] = True
222
+
223
+
224
+ class OverlayComponent(Container):
225
+ """Modal/Drawer-like overlay: ``opened`` is Python-owned; ``close`` requests
226
+ (Escape, overlay click, close button) set it to False and call ``on_close``;
227
+ ``open`` (user-toggled popovers and menus) sets it to True.
228
+
229
+ A contract ``value`` (for example the ``step`` of a Tour) is committed from
230
+ the page like a :class:`ValueComponent` value and sends a ``ChangeEvent``."""
231
+
232
+ VALUE_PROP: ClassVar[str] = "" # empty: no committed value
233
+ CHANGE_EVENT: ClassVar[str] = "change"
234
+
235
+ def _value_prop(self) -> str | None:
236
+ return self.VALUE_PROP or None
237
+
238
+ def _on_client_event(self, name: str, payload: Mapping[str, Any]) -> Event | None:
239
+ if name == "close":
240
+ self._commit_from_client("opened", False)
241
+ elif name == "open" and "open" in self.EVENTS:
242
+ self._commit_from_client("opened", True)
243
+ elif self.VALUE_PROP and name == self.CHANGE_EVENT:
244
+ if "value" not in payload:
245
+ raise ValidationError("change event without value")
246
+ convert(self._spec(self.VALUE_PROP), payload["value"]) # type check before commit
247
+ old = self._commit_from_client(self.VALUE_PROP, payload["value"])
248
+ return ChangeEvent(
249
+ name=name,
250
+ sender=self,
251
+ payload=dict(payload),
252
+ value=self.get_prop(self.VALUE_PROP),
253
+ previous=None if old is UNSET else old,
254
+ )
255
+ return Event(name=name, sender=self, payload=dict(payload))
256
+
257
+ def open(self) -> None:
258
+ self.update(opened=True)
259
+
260
+ def close(self) -> None:
261
+ self.update(opened=False)
262
+
263
+
264
+ # ------------------------------------------------------------------ forms
265
+ class FormComponent(Container):
266
+ """A form: submission carries a complete snapshot of its named fields.
267
+
268
+ Fields are the named value components inside the form; ``ui.Field``
269
+ scopes and ``ui.FieldList`` items prefix their names, so values are
270
+ nested by dot path and errors are keyed by path (see ``_forms``). Hidden
271
+ fields are neither validated nor submitted.
272
+
273
+ Submitting validates the snapshot in Python (types, declared constraints
274
+ such as ``min``/``max``, ``max_length``, date bounds and FieldList
275
+ ``min_items``/``max_items``, ``required``, field validators with
276
+ ``(value)`` or ``(value, values)``, then ``validate``),
277
+ commits all values atomically and calls ``on_submit`` with the nested
278
+ values; errors go back to the fields. Concurrent submissions of the same
279
+ form are rejected (the page disables submit while one is pending); a
280
+ running async ``on_submit`` can be cancelled (``cancel_submit`` or the
281
+ page's Cancel button when ``cancelable``).
282
+ """
283
+
284
+ def __init__(
285
+ self,
286
+ *,
287
+ validate: Callable[[dict[str, Any]], Any] | None = None,
288
+ **kw: Any,
289
+ ) -> None:
290
+ super().__init__(**kw)
291
+ self.validate_fn = validate
292
+ self._submitting = False
293
+ self._submit_task: asyncio.Task[None] | None = None
294
+ self._cancel_requested = False
295
+ self.last_values: dict[str, Any] = {}
296
+ self.errors: dict[str, FieldError] = {}
297
+ """Errors of the last validation by path (``""``: form-level)."""
298
+ self._conditions: list[tuple[Component, Callable[[Mapping[str, Any]], Any]]] = []
299
+ # Per-field validation generation (field id -> counter), see _validate_field.
300
+ self._validation_gen: dict[str, int] = {}
301
+
302
+ @classmethod
303
+ def from_schema(
304
+ cls,
305
+ schema: Mapping[str, Any],
306
+ *,
307
+ actions: Any = None,
308
+ on_submit: Callable[..., Any] | None = None,
309
+ validate: Callable[[dict[str, Any]], Any] | None = None,
310
+ ) -> Any:
311
+ """Build a form from a declarative schema (server-driven forms)::
312
+
313
+ {"fields": [{"name": "email", "type": "email", "label": "E-mail",
314
+ "required": true},
315
+ {"name": "kind", "type": "select", "options": ["a", "b"]},
316
+ {"name": "vat", "type": "text", "pattern": "[A-Z]{2}\\d+",
317
+ "visible_when": {"field": "kind", "equals": "b"}},
318
+ {"name": "lines", "type": "list", "fields": [...]}],
319
+ "submit_label": "Save", "submit_action": "save_order"}
320
+
321
+ Field types: text, email, password, textarea, number, integer, select,
322
+ multiselect, segmented, checkbox, switch, date (ISO text), group
323
+ (nested ``ui.Field``), list (``ui.FieldList``). Validation keys
324
+ (required, min/max, min_length/max_length, pattern, matches_field)
325
+ become ``ui.validators`` rules; ``visible_when`` is data
326
+ (``{field, equals|not_equals|in|not_empty}``). Nothing is evaluated;
327
+ ``submit_action`` must be registered in ``actions``
328
+ (``ui.schema.Actions``). Invalid schemas raise ``ui.schema.SchemaError``."""
329
+ from .schema import build_form
330
+
331
+ return build_form(
332
+ schema,
333
+ form_cls=cls,
334
+ actions=actions,
335
+ on_submit=on_submit,
336
+ validate=validate,
337
+ )
338
+
339
+ # ------------------------------------------------------------ structure
340
+ def layout(self) -> FormLayout:
341
+ """Fields, groups (Field/FieldList) and hidden paths of this form."""
342
+ from ._forms import collect
343
+
344
+ return collect(self)
345
+
346
+ def fields(self) -> dict[str, ValueComponent]:
347
+ """Named value components inside this form (path -> component)."""
348
+ return self.layout().fields
349
+
350
+ def field(self, path: str) -> ValueComponent:
351
+ """The input at ``path`` (``KeyError`` if there is none)."""
352
+ return self.fields()[path]
353
+
354
+ def _committed(self, f: ValueComponent) -> Any:
355
+ """Committed value, typed (dates as ``date``/``datetime`` ...)."""
356
+ v = f.get_prop(f.VALUE_PROP)
357
+ return None if v is UNSET else v
358
+
359
+ @staticmethod
360
+ def _wire(f: ValueComponent) -> Any:
361
+ """Committed value as stored on the wire (what submit converts/commits)."""
362
+ with TREE_LOCK:
363
+ v = f._props.get(f.VALUE_PROP) # pyright: ignore[reportPrivateUsage]
364
+ return v
365
+
366
+ @staticmethod
367
+ def _typed(f: ValueComponent, wire: Any) -> Any:
368
+ return None if wire is None else f._from_wire(f.VALUE_PROP, wire) # pyright: ignore[reportPrivateUsage]
369
+
370
+ def values(self) -> dict[str, Any]:
371
+ """Committed values of the visible fields, nested by path."""
372
+ from ._forms import nest
373
+
374
+ lay = self.layout()
375
+ flat = {p: self._committed(f) for p, f in lay.fields.items() if p not in lay.hidden}
376
+ return nest(flat, _visible_lists(lay))
377
+
378
+ def _all_values(self, lay: FormLayout | None = None) -> dict[str, Any]:
379
+ from ._forms import nest
380
+
381
+ lay = lay or self.layout()
382
+ return nest({p: self._committed(f) for p, f in lay.fields.items()}, lay.lists)
383
+
384
+ @property
385
+ def dirty(self) -> bool:
386
+ """Some field (or list structure) differs from its initial value."""
387
+ return bool(self.dirty_fields())
388
+
389
+ def dirty_fields(self) -> list[str]:
390
+ """Paths of fields whose committed value differs from the initial one
391
+ (and of FieldLists whose items were added, removed or moved)."""
392
+ lay = self.layout()
393
+ out = [p for p, f in lay.fields.items() if f.dirty]
394
+ out += [p for p, g in lay.groups.items() if getattr(g, "dirty", False) is True]
395
+ return sorted(out)
396
+
397
+ @property
398
+ def touched(self) -> frozenset[str]:
399
+ """Paths of the fields the user changed (since construction/reset)."""
400
+ return frozenset(p for p, f in self.layout().fields.items() if f.touched)
401
+
402
+ def is_touched(self, path: str) -> bool:
403
+ return path in self.touched
404
+
405
+ @property
406
+ def submitting(self) -> bool:
407
+ return self._submitting
408
+
409
+ # ------------------------------------------------------ conditional fields
410
+ def show_when(
411
+ self, component: Component, when: Callable[[Mapping[str, Any]], Any]
412
+ ) -> Subscription:
413
+ """Conditional field: ``component`` is visible while
414
+ ``when(values)`` is truthy (``values``: all committed values, nested).
415
+ Re-evaluated after every committed change in the form and, with the
416
+ submitted snapshot, before validation; hidden fields are not
417
+ validated or submitted."""
418
+ if not callable(when): # pyright: ignore[reportUnnecessaryIsInstance]
419
+ raise ValidationError("show_when needs a callable")
420
+ entry = (component, when)
421
+ with TREE_LOCK:
422
+ self._conditions.append(entry)
423
+ self._apply_conditions(self._all_values())
424
+
425
+ def remove() -> None:
426
+ with TREE_LOCK:
427
+ if entry in self._conditions:
428
+ self._conditions.remove(entry)
429
+
430
+ sub = Subscription(remove)
431
+ component._add_cleanup(sub.dispose) # pyright: ignore[reportPrivateUsage]
432
+ return sub
433
+
434
+ def _apply_conditions(self, values: Mapping[str, Any]) -> None:
435
+ for comp, when in list(self._conditions):
436
+ if comp.disposed:
437
+ continue
438
+ show = bool(when(values))
439
+ if comp.visible != show:
440
+ comp.update(visible=show)
441
+
442
+ def _field_committed(self, f: ValueComponent) -> None:
443
+ """A field committed a page change (under the tree lock)."""
444
+ if self._conditions:
445
+ self._apply_conditions(self._all_values())
446
+ if "validate_on" in self.PROPS and self.get_prop("validate_on") == "change":
447
+ w = self._window
448
+ if w is not None and w.live:
449
+ gen = self._validation_gen.get(f.id, 0) + 1
450
+ self._validation_gen[f.id] = gen
451
+ w.call_soon(self._validate_field, f, gen, label="ui:validate")
452
+
453
+ async def _validate_field(self, f: ValueComponent, gen: int | None = None) -> None:
454
+ """Validate one field after a committed change. ``gen`` is the
455
+ field's validation generation at commit time: a result that is no
456
+ longer the newest (a later change or a submission started since) is
457
+ discarded, so a slow validation of an older value cannot overwrite
458
+ a newer result."""
459
+ if f.disposed:
460
+ return
461
+ lay = self.layout()
462
+ path = next((p for p, x in lay.fields.items() if x is f), None)
463
+ if path is None or path in lay.hidden:
464
+ return
465
+ v = self._committed(f)
466
+ err: FieldError | None
467
+ if _required(f) and _empty(v):
468
+ err = FieldError("required", "Required")
469
+ else:
470
+ err = await f.run_validator(v, self._all_values(lay))
471
+ with TREE_LOCK:
472
+ if gen is not None and self._validation_gen.get(f.id) != gen:
473
+ return # superseded
474
+ if err is None:
475
+ self.errors.pop(path, None)
476
+ else:
477
+ self.errors[path] = err
478
+ if "error" in f.PROPS and not f.disposed:
479
+ f.update(error=str(err) if err else UNSET)
480
+
481
+ # --------------------------------------------------------------- errors
482
+ def set_errors(self, errors: Mapping[str, Any]) -> None:
483
+ """Show errors by path (``None``/``""`` clears one); key ``""`` is the
484
+ form-level error. Paths may name fields, ``ui.Field`` scopes or
485
+ ``ui.FieldList`` lists. Use it for server checks outside a submission
486
+ (e.g. a debounced availability check)."""
487
+ lay = self.layout()
488
+ with TREE_LOCK:
489
+ for path, raw in errors.items():
490
+ err = FieldError.of(raw)
491
+ target: Component | None = (
492
+ self if path == "" else lay.fields.get(path) or lay.groups.get(path)
493
+ )
494
+ if target is None:
495
+ raise ValidationError(f"no field {path!r} in form")
496
+ if err is None:
497
+ self.errors.pop(path, None)
498
+ else:
499
+ self.errors[path] = err
500
+ if "error" in target.PROPS:
501
+ target.update(error=str(err) if err else UNSET)
502
+
503
+ def clear_errors(self) -> None:
504
+ lay = self.layout()
505
+ with TREE_LOCK:
506
+ self.errors = {}
507
+ for c in (*lay.fields.values(), *lay.groups.values(), self):
508
+ if "error" in c.PROPS and c.get_prop("error") is not UNSET:
509
+ c.update(error=UNSET)
510
+
511
+ # ----------------------------------------------------------- submission
512
+ async def handle_submit(
513
+ self, snapshot: Mapping[str, Any], window: WindowSession
514
+ ) -> dict[str, Any]:
515
+ if self._submitting:
516
+ return {"ok": False, "error": "a submission is already running", "busy": True}
517
+ # Busy from here, through async validators, until the handlers finish.
518
+ self._submitting = True
519
+ try:
520
+ return await self._handle_submit(snapshot, window)
521
+ finally:
522
+ self._submitting = False
523
+
524
+ async def _handle_submit(
525
+ self, snapshot: Mapping[str, Any], window: WindowSession
526
+ ) -> dict[str, Any]:
527
+ from ._forms import nest, run_validator
528
+
529
+ lay = self.layout()
530
+ by_id = {f.id: p for p, f in lay.fields.items()}
531
+ for f in lay.fields.values(): # pending per-field validations are superseded
532
+ self._validation_gen[f.id] = self._validation_gen.get(f.id, 0) + 1
533
+ if set(snapshot) - set(by_id):
534
+ raise ValidationError("submission names fields that are not in the form")
535
+ errors: dict[str, FieldError] = {}
536
+ converted: dict[str, Any] = {}
537
+ for path, f in lay.fields.items():
538
+ raw = snapshot[f.id] if f.id in snapshot else self._wire(f)
539
+ spec = f._spec(f.VALUE_PROP) # pyright: ignore[reportPrivateUsage]
540
+ try:
541
+ converted[path] = (
542
+ convert(spec, raw) if raw is not None or not spec.nullable else None
543
+ )
544
+ except ValidationError as err:
545
+ errors[path] = FieldError("type", str(err).split(": ", 1)[-1])
546
+ converted[path] = self._wire(f)
547
+ continue
548
+ if raw is not None:
549
+ # Declared constraints (min/max, max_length, date bounds, ...)
550
+ # exactly as a change event checks them: the page's are advisory.
551
+ try:
552
+ f._check_submitted_value(raw) # pyright: ignore[reportPrivateUsage]
553
+ except ValidationError as err:
554
+ errors[path] = FieldError("constraint", str(err).split(": ", 1)[-1])
555
+ if self._conditions:
556
+ with TREE_LOCK:
557
+ typed_all = {p: self._typed(lay.fields[p], v) for p, v in converted.items()}
558
+ self._apply_conditions(nest(typed_all, lay.lists))
559
+ lay = self.layout()
560
+ active = {p: v for p, v in converted.items() if p not in lay.hidden} # wire values
561
+ typed = {p: self._typed(lay.fields[p], v) for p, v in active.items()}
562
+ errors = {p: e for p, e in errors.items() if p not in lay.hidden}
563
+ errors.update(_list_limit_errors(lay))
564
+ # Validators, the form validator and handlers see typed values.
565
+ values = nest(typed, _visible_lists(lay))
566
+ for path, v in typed.items():
567
+ if path in errors and errors[path].code != "constraint":
568
+ continue
569
+ f = lay.fields[path]
570
+ if _required(f) and _empty(v):
571
+ errors[path] = FieldError("required", "Required")
572
+ continue
573
+ err = await run_validator(f.validator, v, values, window)
574
+ if err is not None:
575
+ # A field's own rule (e.g. a schema ``range``) explains a
576
+ # violated constraint better than the generic message.
577
+ errors[path] = err
578
+ if not errors and self.validate_fn is not None:
579
+ r = await _call_callback(window, "ui:validate", self.validate_fn, values)
580
+ if isinstance(r, (str, FieldError)) and str(r):
581
+ return self._fail(lay, {"": FieldError.of(r) or FieldError("invalid", str(r))})
582
+ if isinstance(r, Mapping):
583
+ for path, msg in cast("Mapping[str, Any]", r).items():
584
+ e = FieldError.of(msg)
585
+ if e is not None and (path in lay.fields or path in lay.groups or path == ""):
586
+ errors[path] = e
587
+ if errors:
588
+ return self._fail(lay, errors)
589
+ with TREE_LOCK:
590
+ for path, v in active.items():
591
+ f = lay.fields[path]
592
+ if v != self._wire(f):
593
+ f._touched = True # pyright: ignore[reportPrivateUsage]
594
+ f._commit_from_client(f.VALUE_PROP, v) # pyright: ignore[reportPrivateUsage]
595
+ self.clear_errors()
596
+ self.last_values = values
597
+ return await self._run_submit(values, window)
598
+
599
+ async def _run_submit(self, values: dict[str, Any], window: WindowSession) -> dict[str, Any]:
600
+ event = SubmitEvent(name="submit", sender=self, payload={}, window=window, values=values)
601
+ self._cancel_requested = False
602
+ task = asyncio.ensure_future(self._call_submit_handlers(event, window))
603
+ self._submit_task = task
604
+ try:
605
+ await task
606
+ except asyncio.CancelledError:
607
+ cur = asyncio.current_task()
608
+ if (
609
+ self._cancel_requested
610
+ and task.cancelled()
611
+ and (cur is None or not cur.cancelling())
612
+ ):
613
+ return {
614
+ "ok": False,
615
+ "errors": {},
616
+ "error": "Submission cancelled",
617
+ "cancelled": True,
618
+ }
619
+ raise
620
+ except ValidationError as err:
621
+ return {"ok": False, "errors": {}, "error": str(err)}
622
+ except Exception as err:
623
+ window.core.report_error(window, err, "ui:submit", notify=False)
624
+ return {"ok": False, "errors": {}, "error": "Submission failed"}
625
+ finally:
626
+ self._submit_task = None
627
+ return {"ok": True, "errors": {}, "error": None}
628
+
629
+ async def _call_submit_handlers(self, event: SubmitEvent, window: WindowSession) -> None:
630
+ for h in self.handlers("submit"):
631
+ fn = h.fn
632
+ args: tuple[Any, ...] = (event,) if h.arity == 1 else ()
633
+ if inspect.iscoroutinefunction(fn):
634
+ await fn(*args)
635
+ else:
636
+ r = await window.core.engine.run_in_thread(
637
+ "ui:submit", _with_window(window, fn), *args
638
+ )
639
+ if inspect.isawaitable(r):
640
+ await r
641
+
642
+ def cancel_submit(self) -> bool:
643
+ """Cancel the running ``on_submit`` (async handlers stop at their next
644
+ ``await``; a sync handler's thread finishes but its result is
645
+ discarded). The validated values stay committed. Thread-safe."""
646
+ task = self._submit_task
647
+ if task is None or task.done():
648
+ return False
649
+ self._cancel_requested = True
650
+ loop = task.get_loop()
651
+ try:
652
+ running = asyncio.get_running_loop()
653
+ except RuntimeError:
654
+ running = None
655
+ if running is loop:
656
+ task.cancel()
657
+ else:
658
+ loop.call_soon_threadsafe(task.cancel)
659
+ return True
660
+
661
+ def _fail(self, lay: FormLayout, errors: dict[str, FieldError]) -> dict[str, Any]:
662
+ out: dict[str, str] = {}
663
+ form_error: str | None = None
664
+ with TREE_LOCK:
665
+ self.errors = dict(errors)
666
+ for path, c in (*lay.fields.items(), *lay.groups.items()):
667
+ if "error" in c.PROPS:
668
+ e = errors.get(path)
669
+ c.update(error=str(e) if e else UNSET)
670
+ if e:
671
+ out[c.id] = str(e)
672
+ if "" in errors:
673
+ form_error = str(errors[""])
674
+ return {"ok": False, "errors": out, "error": form_error}
675
+
676
+ # ----------------------------------------------------------- reset/fresh
677
+ def reset(self, values: Mapping[str, Any] | None = None) -> None:
678
+ """Back to the initial state: FieldLists rebuild their initial items,
679
+ fields get their initial values (``values``, nested or by path, first
680
+ become the new initial values), errors and touched flags are
681
+ cleared, and the page drops its drafts."""
682
+ from ._forms import flatten
683
+
684
+ with TREE_LOCK:
685
+ lay = self.layout()
686
+ for g in lay.groups.values():
687
+ reset_items = getattr(g, "reset_items", None)
688
+ if callable(reset_items):
689
+ reset_items()
690
+ lay = self.layout()
691
+ if values:
692
+ for path, v in flatten(values):
693
+ f = lay.fields.get(path)
694
+ if f is None:
695
+ raise ValidationError(f"no field {path!r} in form")
696
+ f._initial = convert(f._spec(f.VALUE_PROP), v) # pyright: ignore[reportPrivateUsage]
697
+ for f in lay.fields.values():
698
+ f.update(**{f.VALUE_PROP: f._initial}) # pyright: ignore[reportPrivateUsage]
699
+ f._touched = False # pyright: ignore[reportPrivateUsage]
700
+ self.clear_errors()
701
+ if self._conditions:
702
+ self._apply_conditions(self._all_values())
703
+ self._command("reset")
704
+
705
+ async def snapshot(self) -> dict[str, Any]:
706
+ """The page's current drafts of the visible fields, nested by path
707
+ (fresh: includes text not committed yet; not validated, not committed)."""
708
+ from ._forms import nest
709
+
710
+ w = _window_or_raise(self)
711
+ res = await w.command(self, "get_value")
712
+ if not isinstance(res, Mapping) or not isinstance(
713
+ drafts := cast("Mapping[str, Any]", res).get("value"), Mapping
714
+ ):
715
+ raise RpcError("PROTOCOL_ERROR", "page returned no form values")
716
+ drafts = cast("Mapping[str, Any]", drafts)
717
+ lay = self.layout()
718
+ flat = {
719
+ p: self._typed(f, drafts[f.id]) if f.id in drafts else self._committed(f)
720
+ for p, f in lay.fields.items()
721
+ if p not in lay.hidden
722
+ }
723
+ return nest(flat, _visible_lists(lay))
724
+
725
+ def get_snapshot(self, timeout: float = 10.0) -> dict[str, Any]:
726
+ """Blocking :meth:`snapshot` for worker threads (refuses the loop thread)."""
727
+ w = _window_or_raise(self)
728
+ assert w.loop is not None
729
+ try:
730
+ asyncio.get_running_loop()
731
+ except RuntimeError:
732
+ return asyncio.run_coroutine_threadsafe(self.snapshot(), w.loop).result(timeout)
733
+ raise RuntimeError("get_snapshot() blocks: use 'await form.snapshot()' in async code")
734
+
735
+ def _on_client_event(self, name: str, payload: Mapping[str, Any]) -> Event | None:
736
+ if name == "cancel":
737
+ self.cancel_submit()
738
+ elif name == "reset":
739
+ self.reset()
740
+ return Event(name=name, sender=self, payload={})
741
+
742
+
743
+ def _visible_lists(lay: FormLayout) -> dict[str, int]:
744
+ return {k: n for k, n in lay.lists.items() if k not in lay.hidden_groups}
745
+
746
+
747
+ def _list_limit_errors(lay: FormLayout) -> dict[str, FieldError]:
748
+ """``min_items``/``max_items`` of the visible FieldLists (structure edits
749
+ enforce them, but a list can start outside its limits)."""
750
+ out: dict[str, FieldError] = {}
751
+ for path, n in _visible_lists(lay).items():
752
+ g = lay.groups[path]
753
+ mn = g.get_prop("min_items") if "min_items" in g.PROPS else None
754
+ mx = g.get_prop("max_items") if "max_items" in g.PROPS else None
755
+ if isinstance(mn, int) and n < mn:
756
+ out[path] = FieldError("min_items", f"Add at least {mn} items", {"min": mn})
757
+ elif isinstance(mx, int) and n > mx:
758
+ out[path] = FieldError("max_items", f"At most {mx} items", {"max": mx})
759
+ return out
760
+
761
+
762
+ def _required(f: Component) -> bool:
763
+ return "required" in f.PROPS and f.get_prop("required") is True
764
+
765
+
766
+ def _empty(v: Any) -> bool:
767
+ return v is None or (isinstance(v, (str, list)) and len(cast("Any", v)) == 0)
768
+
769
+
770
+ async def _call_callback(
771
+ window: WindowSession | None, label: str, fn: Callable[..., Any], *args: Any
772
+ ) -> Any:
773
+ """Run a user callback like a handler: coroutine functions on the loop,
774
+ plain functions on the engine's worker pool (they may block). Without a
775
+ window (unmounted, direct calls) it runs inline."""
776
+ if window is None or inspect.iscoroutinefunction(fn):
777
+ r = fn(*args)
778
+ else:
779
+ r = await window.core.engine.run_in_thread(label, _with_window(window, fn), *args)
780
+ if inspect.isawaitable(r):
781
+ r = await r
782
+ return r
783
+
784
+
785
+ def _with_window(window: WindowSession, fn: Callable[..., Any]) -> Callable[..., Any]:
786
+ from ._session import _current_window # pyright: ignore[reportPrivateUsage]
787
+
788
+ def run(*args: Any) -> Any:
789
+ tok = _current_window.set(window)
790
+ try:
791
+ return fn(*args)
792
+ finally:
793
+ _current_window.reset(tok)
794
+
795
+ return run
796
+
797
+
798
+ # ----------------------------------------------------------------- tables
799
+ @dataclass(frozen=True)
800
+ class TableQuery:
801
+ """What the page asks for: a window of rows (``offset``/``limit``) with
802
+ optional sort (column, "asc"/"desc"), per-column filters and search."""
803
+
804
+ offset: int = 0
805
+ limit: int = 50
806
+ sort: str | None = None
807
+ direction: str = "asc"
808
+ search: str | None = None
809
+ filters: dict[str, Any] = field(default_factory=dict[str, Any])
810
+
811
+
812
+ @dataclass(frozen=True)
813
+ class TablePage:
814
+ rows: Sequence[Mapping[str, Any]]
815
+ total: int | None = None
816
+
817
+
818
+ Provider = Callable[
819
+ [TableQuery],
820
+ "TablePage | Sequence[Mapping[str, Any]] | Awaitable[TablePage | Sequence[Mapping[str, Any]]]",
821
+ ]
822
+
823
+
824
+ class TableComponent(Component):
825
+ """DataTable: local ``rows`` (small data) or a ``provider`` callable that
826
+ returns only the requested window (server paging, sort, filter, search).
827
+ Only visible rows travel to the page; nothing loads the full dataset.
828
+
829
+ ``columns`` and ``row_actions`` are validated specs (``ui.Column``,
830
+ ``ui.RowAction`` or equivalent mappings). Page events are checked against
831
+ them: sort/filter only on sortable/filterable columns, ``row_action`` only
832
+ for declared actions, ``cell_edit`` only on editable columns (the value is
833
+ typed by the column kind), selection keys are JSON scalars."""
834
+
835
+ MAX_SELECTED: ClassVar[int] = 10_000
836
+
837
+ def __init__(self, *, provider: Provider | None = None, **kw: Any) -> None:
838
+ super().__init__(**kw)
839
+ if provider is not None and not callable(provider): # pyright: ignore[reportUnnecessaryIsInstance]
840
+ raise ValidationError("provider must be callable")
841
+ self.provider = provider
842
+ self._query_gen = 0
843
+ self.stats: dict[str, int] = {"queries": 0, "rows": 0}
844
+ """Provider calls answered and rows sent to the page (boundedness checks)."""
845
+ self._warned_unhandled = False
846
+
847
+ def _convert(self, name: str, value: Any, spec: PropSpec | None = None) -> Any:
848
+ from ._tables import normalize_actions, normalize_columns
849
+
850
+ if name == "columns" and value is not None:
851
+ value = normalize_columns(value)
852
+ elif name == "row_actions" and value is not None:
853
+ value = normalize_actions(value)
854
+ elif name == "selected" and value is not None:
855
+ value = self._check_keys(value)
856
+ return super()._convert(name, value, spec)
857
+
858
+ def _check_keys(self, keys: Any) -> list[Any]:
859
+ from ._tables import is_key
860
+
861
+ if not isinstance(keys, (list, tuple)):
862
+ raise ValidationError("keys must be a list")
863
+ out = list(cast("Sequence[Any]", keys))
864
+ if len(out) > self.MAX_SELECTED:
865
+ raise ValidationError(f"at most {self.MAX_SELECTED} keys")
866
+ if not all(is_key(k) for k in out):
867
+ raise ValidationError("row keys must be strings or safe integers")
868
+ return out
869
+
870
+ def _columns(self) -> dict[str, dict[str, Any]]:
871
+ cols = self._props.get("columns")
872
+ return {c["key"]: c for c in cast("list[dict[str, Any]]", cols or [])}
873
+
874
+ @property
875
+ def selected_keys(self) -> list[Any]:
876
+ """Keys of the selected rows (committed by ``selection_change``)."""
877
+ v = self._props.get("selected")
878
+ return list(cast("list[Any]", v)) if isinstance(v, list) else []
879
+
880
+ def _extra_node(self) -> dict[str, Any] | None:
881
+ actions = cast("list[dict[str, Any]]", self._props.get("row_actions") or [])
882
+ if actions and not self._handlers.get("row_action") and not self._warned_unhandled:
883
+ # Without a handler the page never sends row actions: say so once.
884
+ self._warned_unhandled = True
885
+ log.warning(
886
+ "%s %s declares row actions %s but has no row_action handler; "
887
+ "clicking them does nothing (pass on_row_action= or .on('row_action', ...))",
888
+ self.TYPE,
889
+ self.id,
890
+ [a["action"] for a in actions],
891
+ )
892
+ return {"remote": self.provider is not None, "qgen": self._query_gen}
893
+
894
+ def refresh(self) -> None:
895
+ """Tell the page to re-query the provider (data changed)."""
896
+ with TREE_LOCK:
897
+ self._query_gen += 1
898
+ if self._window is not None:
899
+ self._window.queue_set(self, {"__qgen": self._query_gen})
900
+
901
+ async def handle_query(self, raw: Mapping[str, Any], window: WindowSession) -> dict[str, Any]:
902
+ if self.provider is None:
903
+ raise ValidationError("table has no provider")
904
+ q = _parse_query(raw, window.core.limits.max_query_rows, self._columns())
905
+ r = await _call_callback(window, "ui:provider", self.provider, q)
906
+ page = r if isinstance(r, TablePage) else TablePage(rows=list(r))
907
+ rows = list(page.rows)[: q.limit] # the page bound: at most ``limit`` rows
908
+ # Rows are wire-checked with the default bounds: ``limit`` caps the row
909
+ # count above, not the number of keys in a row.
910
+ check_value(rows, path="rows")
911
+ total: Any = page.total
912
+ if total is not None and (
913
+ isinstance(total, bool) or not isinstance(total, int) or total < 0
914
+ ):
915
+ raise ValidationError("TablePage.total must be an int >= 0 or None")
916
+ self.stats["queries"] += 1
917
+ self.stats["rows"] += len(rows)
918
+ return {"rows": to_wire(rows), "total": total, "offset": q.offset}
919
+
920
+ def _check_action_shown(self, action: str, key: Any) -> None:
921
+ """A ``RowAction(when=field)`` on local ``rows`` is accepted only for a
922
+ row whose field is truthy, the same rule the page uses to show it."""
923
+ spec = next(
924
+ a
925
+ for a in cast("list[dict[str, Any]]", self._props.get("row_actions") or [])
926
+ if a["action"] == action
927
+ )
928
+ when = spec.get("when")
929
+ rows = self._props.get("rows") if "rows" in self.PROPS else None
930
+ if when is None or self.provider is not None or not isinstance(rows, list):
931
+ return
932
+ rk = self._props.get("row_key") or "id"
933
+ for r in cast("list[Any]", rows):
934
+ if isinstance(r, Mapping) and cast("Mapping[str, Any]", r).get(rk) == key:
935
+ v = cast("Mapping[str, Any]", r).get(when)
936
+ # JavaScript's Boolean(v) (rows reach the page as JSON): empty
937
+ # lists and objects count as true there, unlike in Python.
938
+ if (
939
+ v is not None
940
+ and v is not False
941
+ and v != ""
942
+ and not (isinstance(v, int | float) and (v == 0 or v != v))
943
+ ):
944
+ return
945
+ break
946
+ raise ValidationError(f"row_action: {action!r} is not available on this row")
947
+
948
+ def _on_client_event(self, name: str, payload: Mapping[str, Any]) -> Event | None:
949
+ from ._tables import convert_cell, is_key
950
+
951
+ if name == "row_action":
952
+ action = payload.get("action")
953
+ declared = {
954
+ a["action"]
955
+ for a in cast("list[dict[str, Any]]", self._props.get("row_actions") or [])
956
+ }
957
+ if not isinstance(action, str) or action not in declared:
958
+ raise ValidationError("row_action: not a declared row action")
959
+ key = payload.get("key")
960
+ if not is_key(key):
961
+ raise ValidationError("row_action: invalid row key")
962
+ self._check_action_shown(action, key)
963
+ return RowActionEvent(
964
+ name=name,
965
+ sender=self,
966
+ payload={"action": action, "key": key},
967
+ action=action,
968
+ key=key,
969
+ )
970
+ if name in ("selection_change", "row_click", "cell_edit", "sort"):
971
+ keys = self._check_keys(payload.get("keys", []))
972
+ column = payload.get("column")
973
+ value = payload.get("value")
974
+ cols = self._columns()
975
+ if name == "selection_change":
976
+ mode = self._props.get("selection", "none")
977
+ if mode == "none" or (mode == "single" and len(keys) > 1):
978
+ raise ValidationError(f"selection_change: selection is {mode!r}")
979
+ self._commit_from_client("selected", keys)
980
+ elif name == "cell_edit":
981
+ col = cols.get(column) if isinstance(column, str) else None
982
+ if col is None or not col.get("editable") or len(keys) != 1:
983
+ raise ValidationError("cell_edit: not an editable column of one row")
984
+ value = convert_cell(col.get("kind", "text"), value, f"cell_edit.{column}")
985
+ elif name == "sort":
986
+ col = cols.get(column) if isinstance(column, str) else None
987
+ if col is None or not col.get("sortable") or value not in ("asc", "desc"):
988
+ raise ValidationError("sort: not a sortable column/direction")
989
+ elif len(keys) != 1:
990
+ raise ValidationError("row_click: one row key")
991
+ return TableEvent(
992
+ name=name,
993
+ sender=self,
994
+ payload={"keys": keys, "column": column, "value": value},
995
+ keys=keys,
996
+ column=column if isinstance(column, str) else None,
997
+ value=value,
998
+ )
999
+ return Event(name=name, sender=self, payload=dict(payload))
1000
+
1001
+
1002
+ def _parse_query(
1003
+ raw: Mapping[str, Any], max_rows: int, columns: Mapping[str, Mapping[str, Any]] | None = None
1004
+ ) -> TableQuery:
1005
+ """Validate a page query; with ``columns``, sort must name a sortable
1006
+ column and filters filterable ones (select filters: one of the options)."""
1007
+ unknown = set(raw) - {"offset", "limit", "sort", "direction", "search", "filters"}
1008
+ if unknown:
1009
+ raise ValidationError(f"unknown query keys {sorted(unknown)}")
1010
+ offset, limit = raw.get("offset", 0), raw.get("limit", 50)
1011
+ if isinstance(offset, bool) or not isinstance(offset, int) or not 0 <= offset <= 2**53 - 1:
1012
+ raise ValidationError("offset must be an int >= 0")
1013
+ if isinstance(limit, bool) or not isinstance(limit, int) or not 0 < limit <= max_rows:
1014
+ raise ValidationError(f"limit must be an int in 1..{max_rows}")
1015
+ sort = raw.get("sort")
1016
+ if sort is not None and not isinstance(sort, str):
1017
+ raise ValidationError("sort must be a column name")
1018
+ if sort is not None and columns is not None and not (columns.get(sort) or {}).get("sortable"):
1019
+ raise ValidationError(f"column {sort!r} is not sortable")
1020
+ direction = raw.get("direction", "asc")
1021
+ if direction not in ("asc", "desc"):
1022
+ raise ValidationError("direction must be asc or desc")
1023
+ search = raw.get("search")
1024
+ if search is not None and (not isinstance(search, str) or len(search) > 500):
1025
+ raise ValidationError("search must be a string (at most 500 characters)")
1026
+ filters = raw.get("filters", {})
1027
+ if not isinstance(filters, Mapping):
1028
+ raise ValidationError("filters must be an object")
1029
+ check_value(filters, path="filters")
1030
+ filters = dict(cast("Mapping[str, Any]", filters))
1031
+ if columns is not None:
1032
+ for k, fv in filters.items():
1033
+ col = columns.get(k) or {}
1034
+ kind = col.get("filter")
1035
+ if kind is None:
1036
+ raise ValidationError(f"column {k!r} has no filter")
1037
+ if not isinstance(fv, str) or len(fv) > 500:
1038
+ raise ValidationError(f"filter {k!r}: expected text")
1039
+ if kind == "select" and fv not in col.get("options", []):
1040
+ raise ValidationError(f"filter {k!r}: not one of the options")
1041
+ return TableQuery(offset, limit, sort, cast("str", direction), search, filters)
1042
+
1043
+
1044
+ # ----------------------------------------------------------------- custom
1045
+ #: Largest ``data`` of one custom component event (UTF-8 JSON), both sides.
1046
+ MAX_CUSTOM_EVENT_BYTES = 256 * 1024
1047
+ _CUSTOM_EVENT_RE = re.compile(r"^[a-z][a-z0-9_]{0,63}$")
1048
+ _CUSTOM_PHASES = frozenset({"mount", "update", "command", "dispose", "render", "register"})
1049
+
1050
+
1051
+ class CustomComponentError(NeutralinoError):
1052
+ """A custom component failed in the page (reported by the renderer).
1053
+
1054
+ ``phase`` is ``mount``, ``update``, ``command``, ``dispose``, ``render`` or
1055
+ ``register`` (the module never registered the name); ``message`` is the
1056
+ page's error text (at most 500 characters). The page shows an error notice
1057
+ in place of the component; the rest of the page keeps working.
1058
+ """
1059
+
1060
+ def __init__(self, component: str, phase: str, message: str) -> None:
1061
+ super().__init__(f"custom component {component!r} failed in {phase}: {message}")
1062
+ self.component = component
1063
+ self.phase = phase
1064
+ self.message = message
1065
+
1066
+
1067
+ class CustomBase(Component):
1068
+ """Application-registered custom component (see ``CustomComponent``)."""
1069
+
1070
+ def send(self, name: str, data: Any = None) -> None:
1071
+ """Fire-and-forget: call the component's ``command(name, data)`` in the page."""
1072
+ check_value(data, path="data")
1073
+ self._command("custom", {"name": name, "data": to_wire(data)})
1074
+
1075
+ async def request(self, name: str, data: Any = None) -> Any:
1076
+ """Call ``command(name, data)`` in the page and return its JSON result."""
1077
+ check_value(data, path="data")
1078
+ w = _window_or_raise(self)
1079
+ return await w.command(self, "custom", {"name": name, "data": to_wire(data)})
1080
+
1081
+ def _on_client_event(self, name: str, payload: Mapping[str, Any]) -> Event | None:
1082
+ if name == "error":
1083
+ phase, message = payload.get("phase"), payload.get("message")
1084
+ if phase not in _CUSTOM_PHASES or not isinstance(message, str):
1085
+ raise ValidationError("malformed custom component error")
1086
+ message = message[:500]
1087
+ log.warning(
1088
+ "custom component %r failed in %s: %s", self.get_prop("component"), phase, message
1089
+ )
1090
+ return Event(name=name, sender=self, payload={"phase": phase, "message": message})
1091
+ ev_name = payload.get("name")
1092
+ if not isinstance(ev_name, str) or not _CUSTOM_EVENT_RE.fullmatch(ev_name):
1093
+ raise ValidationError("custom event without a valid name")
1094
+ data = payload.get("data")
1095
+ check_value(data, path="data")
1096
+ if len(json.dumps(data, separators=(",", ":")).encode()) > MAX_CUSTOM_EVENT_BYTES:
1097
+ raise ValidationError(f"custom event data larger than {MAX_CUSTOM_EVENT_BYTES} bytes")
1098
+ return Event(name=name, sender=self, payload={"name": ev_name, "data": data})
1099
+
1100
+ def _failure(self, event: Event) -> CustomComponentError:
1101
+ return CustomComponentError(
1102
+ str(self.get_prop("component")), event.payload["phase"], event.payload["message"]
1103
+ )
1104
+
1105
+
1106
+ # ----------------------------------------------------------------- charts
1107
+ class ChartComponent(Component):
1108
+ """Typed charts. ``data``/``series``/keys are validated before anything is
1109
+ sent (finite numbers or ``None`` gaps, keys matching the declared series).
1110
+ Time-series like charts keep a bounded ``data`` history (``max_points``)
1111
+ and stream appended points to the page in coalesced batches."""
1112
+
1113
+ DEFAULT_MAX_POINTS: ClassVar[int] = 1_000
1114
+
1115
+ def __init__(self, *, props: Mapping[str, Any] | None = None, **kw: Any) -> None:
1116
+ if props:
1117
+ conv = {n: self._convert(n, v) for n, v in props.items() if v is not UNSET}
1118
+ _charts.check_consistency(self.TYPE, conv)
1119
+ super().__init__(props=props, **kw)
1120
+
1121
+ def _convert(self, name: str, value: Any, spec: PropSpec | None = None) -> Any:
1122
+ wire = super()._convert(name, value, spec)
1123
+ return _charts.check_prop(self.TYPE, name, wire)
1124
+
1125
+ def update(self, **props: Any) -> None:
1126
+ conv = {n: self._convert(n, v) for n, v in props.items() if v is not UNSET}
1127
+ with TREE_LOCK:
1128
+ merged = {k: v for k, v in self._props.items() if props.get(k, 0) is not UNSET}
1129
+ merged.update(conv)
1130
+ _charts.check_consistency(self.TYPE, merged)
1131
+ super().update(**props)
1132
+
1133
+ def _max_points(self) -> int:
1134
+ m = self.get_prop("max_points") if "max_points" in self.PROPS else UNSET
1135
+ return m if isinstance(m, int) and m > 0 else self.DEFAULT_MAX_POINTS
1136
+
1137
+ def append(self, *points: Any) -> None:
1138
+ """Append data points (oldest beyond ``max_points`` are dropped)."""
1139
+ if self.TYPE not in _charts.STREAMING:
1140
+ raise ValidationError(f"{self.TYPE} does not stream; use update(data=...)")
1141
+ if not points:
1142
+ return
1143
+ if self.TYPE == "Sparkline":
1144
+ new = _charts.check_sparkline(list(points))
1145
+ else:
1146
+ new = convert(self._spec("data"), list(points))
1147
+ with TREE_LOCK:
1148
+ props = dict(self._props)
1149
+ props["data"] = new
1150
+ _charts.check_consistency(self.TYPE, props)
1151
+ cap = self._max_points()
1152
+ with TREE_LOCK:
1153
+ self._check_alive()
1154
+ cur = self._props.get("data")
1155
+ hist: deque[Any] = deque(
1156
+ cast("list[Any]", cur) if isinstance(cur, list) else [], maxlen=cap
1157
+ )
1158
+ hist.extend(new)
1159
+ self._props["data"] = list(hist)
1160
+ if self._window is not None:
1161
+ self._window.queue_append(self, "data", list(new[-cap:]), cap)
1162
+
1163
+ def extend(self, points: Sequence[Any]) -> None:
1164
+ self.append(*points)
1165
+
1166
+ def _on_client_event(self, name: str, payload: Mapping[str, Any]) -> Event | None:
1167
+ if name not in ("point_click", "slice_click", "bar_click", "legend_click"):
1168
+ return super()._on_client_event(name, payload)
1169
+ data = self.get_prop("data")
1170
+ rows = cast("list[Any]", data) if isinstance(data, list) else []
1171
+ if name == "legend_click":
1172
+ names = _charts.series_or_cell_names(self.TYPE, self._props)
1173
+ series = payload.get("series")
1174
+ if not isinstance(series, str) or series not in names:
1175
+ raise ValidationError(f"{self.TYPE}.legend_click: unknown series")
1176
+ return Event(name=name, sender=self, payload={"series": series})
1177
+ idx = payload.get("index")
1178
+ if isinstance(idx, bool) or not isinstance(idx, int) or not 0 <= idx < len(rows):
1179
+ raise ValidationError(f"{self.TYPE}.{name}: index outside the data")
1180
+ row: Any = rows[idx]
1181
+ fields: Mapping[str, Any] = cast("Mapping[str, Any]", row) if isinstance(row, dict) else {}
1182
+ out: dict[str, Any] = {"index": idx, "row": row}
1183
+ if name == "point_click":
1184
+ dk = self._props.get("data_key")
1185
+ out["label"] = fields.get(dk) if isinstance(dk, str) else None
1186
+ else:
1187
+ out["name"] = fields.get("name")
1188
+ return Event(name=name, sender=self, payload=out)
1189
+
1190
+
1191
+ # ---------------------------------------------------------------- hotkeys
1192
+ class HotkeysBase(Component):
1193
+ """Non-visual keyboard shortcuts: ``bindings`` follow the hotkey grammar
1194
+ (``normalize_binding``); a ``hotkey`` event carries the matched binding
1195
+ and is accepted only for a currently bound hotkey."""
1196
+
1197
+ def _convert(self, name: str, value: Any, spec: PropSpec | None = None) -> Any:
1198
+ if name == "bindings" and value is not None:
1199
+ from ._behaviours import normalize_bindings
1200
+
1201
+ value = normalize_bindings(value)
1202
+ return super()._convert(name, value, spec)
1203
+
1204
+ def _on_client_event(self, name: str, payload: Mapping[str, Any]) -> Event | None:
1205
+ ev = super()._on_client_event(name, payload)
1206
+ if name == "hotkey" and ev is not None:
1207
+ bound = self.get_prop("bindings")
1208
+ if not isinstance(bound, list) or ev.payload.get("value") not in bound:
1209
+ raise ValidationError("hotkey event for a binding that is not bound")
1210
+ return ev