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,1328 @@
1
+ """neutralino-python Explorer: every catalogue row, its status and its evidence.
2
+
3
+ Run: ``neutralino explorer`` (from an installed package; works offline)
4
+
5
+ The catalogue (``catalogue.json``, generated by ``tools/generate_catalogue.py``
6
+ from the coverage rows and the UI contracts) lists all 449 rows. Each row has a
7
+ route ``/entry/<id>``; its page is built when it is first shown. A page shows
8
+ the classification and disposition as recorded, a live preview built with the
9
+ real component or block, the Python source of the row's example, the
10
+ component's props/events/slots, tests, evidence, limitations and related rows.
11
+ "Run example" starts the example as its own process (``sys.executable`` on a
12
+ temporary copy of the packaged source), never inside the Explorer; the Explorer
13
+ itself uses no native API (``profile="restricted"``).
14
+
15
+ On an entry with a component preview, "Edit properties" sets contract props on
16
+ the real preview component (errors shown per control, Reset restores the
17
+ example), the source tabs show the preview's Python and its React + Mantine
18
+ equivalent for the current props (native rows: the neutralino.js calls), and
19
+ "Export example" writes a runnable app.py (never overwriting) that "Run"
20
+ starts as its own process. "RPC log" lists the window's last calls with
21
+ bounded, redacted payload previews (``RpcEndpoint.observer``).
22
+ """
23
+
24
+ from __future__ import annotations
25
+
26
+ import asyncio
27
+ import contextlib
28
+ import importlib.util
29
+ import json
30
+ import os
31
+ import re
32
+ import shutil
33
+ import signal
34
+ import subprocess
35
+ import sys
36
+ import tempfile
37
+ import time
38
+ from collections import OrderedDict, deque
39
+ from collections.abc import Callable, Generator, Mapping
40
+ from pathlib import Path
41
+ from typing import Any, cast
42
+
43
+ from neutralino import ui
44
+ from neutralino.types import UNSET
45
+
46
+ HERE = Path(__file__).resolve().parent
47
+ TITLE = "neutralino-python Explorer"
48
+ DISPOSITION_COLORS = {"implemented": "teal", "frozen": "yellow", "excluded": "gray"}
49
+ NO_PREVIEW = {
50
+ "native-example": "Native examples call the runtime; use Run example to open one in its "
51
+ "own process with its own permission list.",
52
+ "integration-pattern": "This pattern runs as a standalone example (see Run example).",
53
+ "reference-application": "A complete application; it runs as its own process.",
54
+ "frontend-behaviour": "Frontend behaviour: shown by the tests and the API listed below.",
55
+ "excluded": "Excluded from the Python API; see the reason above.",
56
+ }
57
+
58
+
59
+ def _load_previews() -> Any:
60
+ spec = importlib.util.spec_from_file_location(
61
+ "neutralino_explorer_previews", HERE / "explorer_previews.py"
62
+ )
63
+ assert spec is not None and spec.loader is not None
64
+ mod = importlib.util.module_from_spec(spec)
65
+ spec.loader.exec_module(mod)
66
+ return mod
67
+
68
+
69
+ # ------------------------------------------------------------------ catalogue
70
+ class Catalogue:
71
+ """The packaged catalogue (read once, never modified)."""
72
+
73
+ def __init__(self, root: Path = HERE) -> None:
74
+ data = cast("dict[str, Any]", json.loads((root / "catalogue.json").read_text("utf-8")))
75
+ self.root = root.resolve()
76
+ self.groups: list[dict[str, Any]] = data["groups"]
77
+ self.entries: dict[str, dict[str, Any]] = {e["id"]: e for e in data["entries"]}
78
+ self.components: dict[str, dict[str, Any]] = data["components"]
79
+ self.renderers: dict[str, Any] = data["renderers"]
80
+
81
+ def group_title(self, gid: str) -> str:
82
+ return next((g["title"] for g in self.groups if g["id"] == gid), gid)
83
+
84
+ def source_path(self, rel: str) -> Path:
85
+ p = (self.root / rel).resolve()
86
+ if not p.is_relative_to(self.root / "sources") or not p.is_file():
87
+ raise FileNotFoundError(rel)
88
+ return p
89
+
90
+ def search(self, query: str, limit: int = 30) -> list[dict[str, Any]]:
91
+ """Entries whose id, title, group, subcategory or API contain every word."""
92
+ words = query.lower().split()
93
+ if not words:
94
+ return []
95
+ scored: list[tuple[int, int, dict[str, Any]]] = []
96
+ for i, e in enumerate(self.entries.values()):
97
+ title = str(e["title"]).lower()
98
+ hay = " ".join(
99
+ [e["id"], title, e["group"], e["subcategory"] or "", *e["public_api"]]
100
+ ).lower()
101
+ if all(w in hay for w in words):
102
+ q = " ".join(words)
103
+ rank = 0 if q in (e["id"].lower(), title) else 1 if title.startswith(q) else 2
104
+ scored.append((rank, i, e))
105
+ scored.sort(key=lambda t: (t[0], t[1]))
106
+ return [e for _, _, e in scored[:limit]]
107
+
108
+
109
+ # --------------------------------------------------------------------- runner
110
+ class Runner:
111
+ """Runs examples as separate processes from a temporary copy of the source."""
112
+
113
+ def __init__(self, catalogue: Catalogue) -> None:
114
+ self.catalogue = catalogue
115
+ self.procs: dict[str, subprocess.Popen[bytes]] = {}
116
+ self._dirs: dict[str, Path] = {}
117
+
118
+ def start(self, entry: dict[str, Any]) -> subprocess.Popen[bytes]:
119
+ ex = entry["example"]
120
+ if not ex or not ex["runnable"]:
121
+ raise ValueError(f"{entry['id']} has no runnable example")
122
+ self.stop(entry["id"])
123
+ main_rel = str(ex["source"])
124
+ if ex["path"].endswith("/"): # an application directory: keep its layout
125
+ base = "sources/" + ex["path"].removeprefix("examples/").rstrip("/")
126
+ else: # a script and its same-named companions
127
+ base = main_rel.rsplit("/", 1)[0]
128
+ work = Path(tempfile.mkdtemp(prefix="neutralino-explorer-"))
129
+ for rel in ex["files"]:
130
+ src = self.catalogue.source_path(rel)
131
+ dest = work / rel.removeprefix(base + "/")
132
+ dest.parent.mkdir(parents=True, exist_ok=True)
133
+ shutil.copyfile(src, dest)
134
+ script = work / main_rel.removeprefix(base + "/")
135
+ proc = self.start_script(entry["id"], script)
136
+ self._dirs[entry["id"]] = work
137
+ return proc
138
+
139
+ def start_script(self, key: str, script: Path) -> subprocess.Popen[bytes]:
140
+ """Run ``script`` as its own process (an exported example: its
141
+ directory belongs to the user and is kept when it stops)."""
142
+ self.stop(key)
143
+ proc = subprocess.Popen(
144
+ [sys.executable, str(script)],
145
+ cwd=script.parent,
146
+ stdin=subprocess.DEVNULL,
147
+ start_new_session=True,
148
+ )
149
+ self.procs[key] = proc
150
+ return proc
151
+
152
+ def running(self, entry_id: str) -> bool:
153
+ p = self.procs.get(entry_id)
154
+ return p is not None and p.poll() is None
155
+
156
+ def stop(self, entry_id: str, grace: float = 5.0) -> int | None:
157
+ """Stop the example (its whole process group) and remove its copy."""
158
+ proc = self.procs.pop(entry_id, None)
159
+ code: int | None = None
160
+ if proc is not None:
161
+ if proc.poll() is None:
162
+ self._signal(proc, signal.SIGTERM)
163
+ try:
164
+ proc.wait(grace)
165
+ except subprocess.TimeoutExpired:
166
+ self._signal(proc, signal.SIGKILL)
167
+ proc.wait()
168
+ code = proc.returncode
169
+ if hasattr(os, "killpg"): # leftovers of the group (e.g. its runtime)
170
+ with contextlib.suppress(OSError):
171
+ os.killpg(proc.pid, signal.SIGKILL)
172
+ work = self._dirs.pop(entry_id, None)
173
+ if work is not None:
174
+ shutil.rmtree(work, ignore_errors=True)
175
+ return code
176
+
177
+ def stop_all(self) -> None:
178
+ for entry_id in list(self.procs):
179
+ self.stop(entry_id)
180
+
181
+ @staticmethod
182
+ def _signal(proc: subprocess.Popen[bytes], sig: signal.Signals) -> None:
183
+ with contextlib.suppress(OSError):
184
+ if hasattr(os, "killpg"):
185
+ os.killpg(proc.pid, sig)
186
+ elif sig == signal.SIGTERM:
187
+ proc.terminate()
188
+ else:
189
+ proc.kill()
190
+
191
+
192
+ # ----------------------------------------------------------------------- UI
193
+ def _python_from_example(spec: dict[str, Any], indent: str = "", inline: bool = False) -> str:
194
+ """Python that builds a contract example (the same tree as the preview);
195
+ ``inline``: one expression (slot content), children passed as ``children=``."""
196
+ args = [f"{k}={v!r}" for k, v in spec.get("props", {}).items()]
197
+ for slot, kids in cast("dict[str, list[Any]]", spec.get("slots", {})).items():
198
+ built = [_python_from_example(k, inline=True) for k in kids]
199
+ args.append(f"{slot}={built[0] if len(built) == 1 else '[' + ', '.join(built) + ']'}")
200
+ kids = cast("list[dict[str, Any]]", spec.get("children", []))
201
+ if inline and kids:
202
+ inner = ", ".join(_python_from_example(k, inline=True) for k in kids)
203
+ args.append(f"children=[{inner}]")
204
+ call = f"ui.{spec['type']}({', '.join(args)})"
205
+ if not kids or inline:
206
+ return indent + call
207
+ body = "\n".join(_python_from_example(k, indent + " ") for k in kids)
208
+ return f"{indent}with {call}:\n{body}"
209
+
210
+
211
+ def _component_from_example(spec: dict[str, Any]) -> ui.Component:
212
+ """A detached component from a contract example ({type, props, slots, children})."""
213
+ cls = getattr(ui, spec["type"])
214
+ kw: dict[str, Any] = dict(spec.get("props", {}))
215
+ for slot, kids in cast("dict[str, list[Any]]", spec.get("slots", {})).items():
216
+ built = [_component_from_example(k) for k in kids]
217
+ kw[slot] = built if len(built) != 1 else built[0]
218
+ with ui.detached():
219
+ comp = cast("ui.Component", cls(**kw))
220
+ for k in spec.get("children", []):
221
+ cast("Any", comp).add(_component_from_example(k))
222
+ return comp
223
+
224
+
225
+ def entry_route(entry_id: str) -> str:
226
+ return f"/entry/{entry_id}"
227
+
228
+
229
+ # ------------------------------------------------------- property editing
230
+ SIZES = ["xs", "sm", "md", "lg", "xl"]
231
+ TEXT_KINDS = {"string", "color", "url", "icon"}
232
+
233
+
234
+ def coerce(prop: dict[str, Any], raw: Any) -> Any:
235
+ """The value an editor control's ``raw`` value means for contract ``prop``;
236
+ ``UNSET`` for an emptied number/JSON field (the component's default).
237
+ Raises ``ValueError`` with a message for the control."""
238
+ kind = prop["kind"]
239
+ if kind == "boolean":
240
+ if not isinstance(raw, bool):
241
+ raise ValueError("expected true or false")
242
+ return raw
243
+ if kind == "enum":
244
+ if raw not in prop.get("values", []):
245
+ raise ValueError(f"{raw!r} is not one of: " + ", ".join(prop.get("values", [])))
246
+ return raw
247
+ if kind in ("integer", "number"):
248
+ if raw is None or raw == "":
249
+ return UNSET
250
+ try:
251
+ num = float(raw) if isinstance(raw, str) else raw
252
+ except ValueError:
253
+ raise ValueError("expected a number") from None
254
+ if isinstance(num, bool) or not isinstance(num, (int, float)):
255
+ raise ValueError("expected a number")
256
+ if kind == "integer":
257
+ if num != int(num):
258
+ raise ValueError("expected a whole number")
259
+ return int(num)
260
+ return num
261
+ if kind == "size" or kind in TEXT_KINDS:
262
+ return "" if raw is None else str(raw)
263
+ text = "" if raw is None else str(raw)
264
+ if not text.strip():
265
+ return UNSET
266
+ try:
267
+ return json.loads(text)
268
+ except json.JSONDecodeError as err:
269
+ raise ValueError(
270
+ f"invalid JSON: {err.msg} (line {err.lineno}, column {err.colno})"
271
+ ) from None
272
+
273
+
274
+ def _error_props(control: ui.Component, error: Any) -> dict[str, Any]:
275
+ """The props that show ``error`` on an editor control (Mantine's JsonInput
276
+ shows ``validationError`` instead of ``error`` while its text is not JSON)."""
277
+ if isinstance(control, ui.JsonInput):
278
+ return {"error": error, "validation_error": error}
279
+ return {"error": error}
280
+
281
+
282
+ def _editor_text(value: Any) -> str:
283
+ """The JSON field text of a current value (empty when unset)."""
284
+ return "" if value is UNSET else json.dumps(value, ensure_ascii=False)
285
+
286
+
287
+ # ------------------------------------------------- custom frontend source
288
+ def _camel(name: str) -> str:
289
+ head, *rest = name.split("_")
290
+ return head + "".join(p[:1].upper() + p[1:] for p in rest)
291
+
292
+
293
+ def _icon_component(name: str) -> str:
294
+ return "Icon" + "".join(p[:1].upper() + p[1:] for p in name.split("-"))
295
+
296
+
297
+ def _jsx_attr(key: str, value: Any) -> str:
298
+ if value is True:
299
+ return key
300
+ if isinstance(value, str) and not any(c in value for c in '"{}\n\\'):
301
+ return f'{key}="{value}"'
302
+ return f"{key}={{{json.dumps(value, ensure_ascii=False)}}}"
303
+
304
+
305
+ def jsx_from_nodes(nodes: list[dict[str, Any]], renderers: dict[str, Any]) -> str:
306
+ """React + Mantine JSX equivalent of wire nodes (``Component.to_node()``):
307
+ the Mantine component the renderer draws for each node, with the props by
308
+ the renderer's (wire) names. Nodes drawn by a renderer-own adapter are
309
+ marked as such instead of being imitated."""
310
+ imports: dict[str, set[str]] = {}
311
+
312
+ def element(node: dict[str, Any], indent: str) -> list[str]:
313
+ props: dict[str, Any] = dict(node.get("props", {}))
314
+ slots: dict[str, list[dict[str, Any]]] = node.get("slots", {})
315
+ if node["type"] == "Icon" and isinstance(props.get("name"), str):
316
+ comp = _icon_component(props.pop("name"))
317
+ imports.setdefault("@tabler/icons-react", set()).add(comp)
318
+ attrs = [_jsx_attr(k, v) for k, v in props.items() if k != "visible"]
319
+ return [f"{indent}<{' '.join([comp, *attrs])} />"]
320
+ r = renderers.get(node["type"])
321
+ if r is None:
322
+ return [
323
+ f"{indent}{{/* ui.{node['type']}: drawn by the neutralino renderer's own "
324
+ "adapter; there is no single Mantine component to show */}"
325
+ ]
326
+ comp = r["component"]
327
+ imports.setdefault(r["package"], set()).add(comp)
328
+ text = props.pop(r["text"], None) if r.get("text") else None
329
+ attrs: list[str] = []
330
+ for k, v in props.items():
331
+ if k in ("visible", "sync"):
332
+ continue
333
+ if k in r.get("icons", []) and isinstance(v, str):
334
+ icon = _icon_component(v)
335
+ imports.setdefault("@tabler/icons-react", set()).add(icon)
336
+ attrs.append(f"{k}={{<{icon} />}}")
337
+ else:
338
+ attrs.append(_jsx_attr(k, v))
339
+ for slot, kids in slots.items():
340
+ if slot != "children" and kids:
341
+ inner = " ".join(line.strip() for k in kids for line in element(k, ""))
342
+ attrs.append(f"{_camel(slot)}={{{inner if len(kids) == 1 else f'<>{inner}</>'}}}")
343
+ children = slots.get("children", [])
344
+ head = " ".join([comp, *attrs])
345
+ if not children and text is None:
346
+ return [f"{indent}<{head} />"]
347
+ lines = [f"{indent}<{head}>"]
348
+ if text is not None:
349
+ t = str(text)
350
+ safe = not any(c in t for c in "{}<>\n")
351
+ lines.append(
352
+ f"{indent} {t if safe else '{' + json.dumps(t, ensure_ascii=False) + '}'}"
353
+ )
354
+ for k in children:
355
+ lines += element(k, indent + " ")
356
+ lines.append(f"{indent}</{comp}>")
357
+ return lines
358
+
359
+ body: list[str] = []
360
+ for n in nodes:
361
+ body += element(n, " ")
362
+ head = [
363
+ "// Custom-frontend equivalent of this preview: React + Mantine, with the",
364
+ "// props the neutralino renderer passes. Wrap the app in <MantineProvider>",
365
+ "// and import '@mantine/core/styles.css' (and the styles of other @mantine",
366
+ "// packages used). Event handlers are yours to add (onChange, onClick, ...).",
367
+ ]
368
+ head += [
369
+ f"import {{ {', '.join(sorted(names))} }} from '{pkg}';"
370
+ for pkg, names in sorted(imports.items())
371
+ ]
372
+ tail = [" </>", " );", "}", ""]
373
+ return "\n".join(
374
+ [*head, "", "export function Example() {", " return (", " <>", *body, *tail]
375
+ )
376
+
377
+
378
+ def js_from_native(native: dict[str, Any]) -> str:
379
+ """neutralino.js calls equivalent to a native example's Python calls."""
380
+ routes = sorted({r for c in native["calls"] for r in c["routes"]})
381
+ lines = [
382
+ "// Custom-frontend equivalent of this example's native calls with the Neutralino",
383
+ "// client: load neutralino.js by a script tag, call Neutralino.init() once.",
384
+ ]
385
+ if routes:
386
+ lines += [
387
+ "// The application's native_allow_list must include:",
388
+ "// " + ", ".join(routes),
389
+ ]
390
+ lines.append("")
391
+ for c in native["calls"]:
392
+ if c["client"] is None:
393
+ lines.append(
394
+ f"// {c['python']}: route {', '.join(c['routes'])} has no neutralino.js "
395
+ "export; call it in Python and expose the result (app.expose / backend.invoke)."
396
+ )
397
+ continue
398
+ args = list(c["positional"])
399
+ if c["options"]:
400
+ args.append("{ " + ", ".join(c["options"]) + " }")
401
+ lines.append(f"await Neutralino.{c['client']}({', '.join(args)}); // {c['python']}")
402
+ for ev in native["events"]:
403
+ lines.append(f"await Neutralino.events.on('{ev}', (event) => console.log(event.detail));")
404
+ return "\n".join(lines) + "\n"
405
+
406
+
407
+ FRONTEND_NOTES = {
408
+ "frontend-behaviour": "No custom-frontend source: this behaviour runs inside the "
409
+ "neutralino.ui renderer itself, there is no separate frontend code to show.",
410
+ "excluded": "No custom-frontend source: this row is excluded from the Python API.",
411
+ }
412
+ FRONTEND_NOTE_DEFAULT = (
413
+ "No custom-frontend source: this row is a Python application or pattern whose "
414
+ "frontend is the neutralino.ui renderer; a separate frontend equivalent is not meaningful."
415
+ )
416
+
417
+
418
+ # ------------------------------------------------------------- RPC log
419
+ SECRET_KEY = re.compile(r"token|passw(or)?d|secret|authorization|api[_-]?key|cookie", re.I)
420
+ PREVIEW_CHARS = 200
421
+ MAX_LOG = 200
422
+ LOG_HEAD = ["Call (time, direction, method, status, duration)", "Payload (redacted)"]
423
+ _MAX_ITEMS = 20
424
+ _MAX_DEPTH = 6
425
+
426
+
427
+ def redact(value: Any, depth: int = 0) -> Any:
428
+ """A bounded copy of ``value`` with the values of secret-looking keys
429
+ (token, password, secret, authorization, api_key, cookie; any case, at any
430
+ depth) replaced by "[redacted]"; long strings, lists and objects are cut."""
431
+ if depth >= _MAX_DEPTH:
432
+ return "…"
433
+ if isinstance(value, Mapping):
434
+ out: dict[str, Any] = {}
435
+ for i, (k, v) in enumerate(cast("Mapping[Any, Any]", value).items()):
436
+ if i >= _MAX_ITEMS:
437
+ out["…"] = f"{len(cast('Mapping[Any, Any]', value)) - i} more"
438
+ break
439
+ key = str(k)
440
+ out[key] = "[redacted]" if SECRET_KEY.search(key) else redact(v, depth + 1)
441
+ return out
442
+ if isinstance(value, (list, tuple)):
443
+ items: list[Any] = list(cast("Any", value))
444
+ cut = [redact(v, depth + 1) for v in items[:_MAX_ITEMS]]
445
+ return cut + ([f"… {len(items) - _MAX_ITEMS} more"] if len(items) > _MAX_ITEMS else [])
446
+ if isinstance(value, str) and len(value) > PREVIEW_CHARS:
447
+ return value[:PREVIEW_CHARS] + "…"
448
+ return value
449
+
450
+
451
+ def preview(value: Any, limit: int = PREVIEW_CHARS) -> str:
452
+ """Short redacted JSON text of a payload (at most ``limit`` characters)."""
453
+ text = json.dumps(redact(value), ensure_ascii=False, default=str)
454
+ return text if len(text) <= limit else text[: limit - 1] + "…"
455
+
456
+
457
+ class CallLog:
458
+ """The last ``size`` RPC calls of the Explorer's window (ring buffer). Only
459
+ redacted, truncated previews are kept, never the raw payloads.
460
+ ``on_change`` is called after each record except the page patches (the
461
+ log's own rendering is sent as patches: no feedback loop)."""
462
+
463
+ QUIET = frozenset({"ui_internal.patch"})
464
+
465
+ def __init__(self, size: int = MAX_LOG) -> None:
466
+ self.entries: deque[dict[str, Any]] = deque(maxlen=size)
467
+ self.on_change: Callable[[], None] | None = None
468
+
469
+ def record(self, call: dict[str, Any]) -> None:
470
+ error = call.get("error")
471
+ self.entries.append(
472
+ {
473
+ "time": time.strftime("%H:%M:%S"),
474
+ "direction": "page → Python" if call["direction"] == "in" else "Python → page",
475
+ "kind": call["kind"],
476
+ "method": call["method"],
477
+ "ms": round(float(call.get("duration", 0.0)) * 1000, 1),
478
+ "status": "ok" if error is None else str(error),
479
+ "preview": preview(call.get("params")),
480
+ }
481
+ )
482
+ if self.on_change is not None and call["method"] not in self.QUIET:
483
+ self.on_change()
484
+
485
+ def clear(self) -> None:
486
+ self.entries.clear()
487
+
488
+ def rows(self) -> list[list[str]]:
489
+ """Table rows, newest first."""
490
+ return [
491
+ [
492
+ f"{e['time']} {e['direction']}: {e['method']} · {e['status']} · {e['ms']:g} ms",
493
+ e["preview"],
494
+ ]
495
+ for e in reversed(self.entries)
496
+ ]
497
+
498
+
499
+ # ----------------------------------------------------- standalone export
500
+ def standalone_app(title: str, eid: str, specs: list[dict[str, Any]]) -> str:
501
+ """A runnable app.py that shows the contract examples ``specs`` (with the
502
+ current edited props); it imports only the public ``neutralino.ui`` API."""
503
+ names = ", ".join(dict.fromkeys(f"ui.{s['type']}" for s in specs))
504
+ body = "\n".join(_python_from_example(s, indent=" ") for s in specs)
505
+ return (
506
+ f'"""{title} ({eid}): standalone example generated by the neutralino-python\n'
507
+ f"Explorer from the public contract of {names}.\n\n"
508
+ 'Run: python app.py\n"""\n\n'
509
+ "from neutralino import ui\n\n"
510
+ f'app = ui.Application(title={title!r}, width=900, height=640, profile="restricted")\n\n\n'
511
+ '@app.page("/")\n'
512
+ "def home() -> None:\n"
513
+ ' with ui.Stack(gap="md", p="md"):\n'
514
+ f"{body}\n\n\n"
515
+ 'if __name__ == "__main__":\n'
516
+ " app.run()\n"
517
+ )
518
+
519
+
520
+ def default_export_dir(eid: str) -> Path:
521
+ return Path.home() / "neutralino-examples" / eid
522
+
523
+
524
+ def export_example(directory: str | Path, code: str) -> Path:
525
+ """Write ``code`` to ``<directory>/app.py``; never overwrites a file.
526
+ Raises ``ValueError`` (with a message for the user) when it cannot."""
527
+ d = Path(directory).expanduser()
528
+ if not d.is_absolute():
529
+ raise ValueError("give an absolute directory (or one starting with ~)")
530
+ if d.exists() and not d.is_dir():
531
+ raise ValueError(f"{d} exists and is not a directory")
532
+ target = d / "app.py"
533
+ if target.exists():
534
+ raise ValueError(f"{target} already exists; nothing was overwritten")
535
+ try:
536
+ d.mkdir(parents=True, exist_ok=True)
537
+ with target.open("x", encoding="utf-8") as f:
538
+ f.write(code)
539
+ except FileExistsError:
540
+ raise ValueError(f"{target} already exists; nothing was overwritten") from None
541
+ except OSError as err:
542
+ raise ValueError(f"cannot write {target}: {err.strerror or err}") from None
543
+ return target
544
+
545
+
546
+ class Explorer:
547
+ """Registers the Explorer's pages on ``app``.
548
+
549
+ A route's page is built when first shown and holds a single container; its
550
+ content is filled when the route is shown and removed again once more than
551
+ ``MAX_FILLED`` other routes were shown since, so browsing all 449 entries
552
+ keeps the window's component count bounded. ``pages`` maps each filled
553
+ route to its named components (title, preview, source, run, ...).
554
+ """
555
+
556
+ MAX_FILLED = 6
557
+
558
+ def __init__(self, app: ui.AsyncApplication, catalogue: Catalogue | None = None) -> None:
559
+ self.app = app
560
+ self.catalogue = catalogue or Catalogue()
561
+ self.runner = Runner(self.catalogue)
562
+ self.previews = _load_previews()
563
+ self.pages: dict[str, dict[str, Any]] = {}
564
+ self._tasks: set[asyncio.Task[None]] = set()
565
+ self._renderers: dict[str, Callable[[], None]] = {}
566
+ self._holders: dict[str, ui.Stack] = {}
567
+ self._filled: OrderedDict[str, None] = OrderedDict()
568
+ self.calls = CallLog()
569
+ self.calls.on_change = self._calls_changed
570
+ self._log_pending = False
571
+ self._register("/", self._home)
572
+ for g in self.catalogue.groups:
573
+ self._register(f"/group/{g['id']}", self._group_builder(g["id"]))
574
+ for eid in self.catalogue.entries:
575
+ self._register(entry_route(eid), self._entry_builder(eid))
576
+
577
+ # ------------------------------------------------------ navigation
578
+ def go(self, route: str) -> Callable[..., None]:
579
+ """An event handler that shows ``route`` in the window of the event."""
580
+
581
+ def handler(*_: Any) -> None:
582
+ w = ui.current_window()
583
+ if w is not None:
584
+ self.show(w, route)
585
+
586
+ return handler
587
+
588
+ def show(self, w: ui.Window, route: str) -> None:
589
+ self._fill(route) # a page built earlier may have been emptied
590
+ w.navigate(route) # builds (and fills) a page shown for the first time
591
+ self._trim(route)
592
+ self._holders[route].scroll_into_view(align="start") # open at the top
593
+
594
+ def _register(self, route: str, render: Callable[[], None]) -> None:
595
+ self._renderers[route] = render
596
+
597
+ def build() -> None:
598
+ holder = ui.Stack(gap=0)
599
+ self._holders[route] = holder
600
+ page = holder.parent
601
+ if page is not None: # back/forward or "#/route" from the page itself
602
+ page.on("navigate", self._page_navigated)
603
+ self._fill(route)
604
+
605
+ self.app.page(route)(build)
606
+
607
+ def _fill(self, route: str) -> None:
608
+ holder = self._holders.get(route)
609
+ if holder is None:
610
+ return
611
+ if route in self._filled:
612
+ self._filled.move_to_end(route)
613
+ return
614
+ with holder:
615
+ self._renderers[route]()
616
+ self._filled[route] = None
617
+
618
+ def _trim(self, current: str) -> None:
619
+ while len(self._filled) > self.MAX_FILLED:
620
+ old = next(r for r in self._filled if r != current)
621
+ del self._filled[old]
622
+ self._holders[old].clear()
623
+ self.pages.pop(old, None)
624
+
625
+ def _page_navigated(self, *_: Any) -> None:
626
+ w = ui.current_window()
627
+ if w is not None:
628
+ self._fill(w.route)
629
+ self._trim(w.route)
630
+
631
+ # ----------------------------------------------------------- frame
632
+ @contextlib.contextmanager
633
+ def _frame(self, route: str, group: str | None) -> Generator[dict[str, Any]]:
634
+ parts: dict[str, Any] = {}
635
+ self.pages[route] = parts
636
+ with ui.AppShell(
637
+ header_height=56, navbar_width=240, navbar_breakpoint="xs", padding="md"
638
+ ) as shell:
639
+ with ui.detached():
640
+ header = ui.Group(justify="space-between", p="sm")
641
+ navbar = ui.Stack(gap=0, p="xs")
642
+ self._observe_window()
643
+ with header:
644
+ ui.Title(TITLE, order=4)
645
+ with ui.Group(gap="xs"):
646
+ self._rpc_log(parts)
647
+ parts["search"] = ui.Button(
648
+ "Search (Ctrl+K)",
649
+ variant="default",
650
+ left_section=ui.Icon("search", size=14),
651
+ on_click=lambda: self._open_search(parts),
652
+ )
653
+ parts["spotlight"] = ui.Spotlight(
654
+ filter="python",
655
+ debounce=120,
656
+ limit=30,
657
+ actions=self._group_actions(),
658
+ nothing_found="No entry matches",
659
+ search_placeholder="Search 449 entries by id, title or API",
660
+ on_query_change=lambda e: self._search(parts, e.value or ""),
661
+ on_action=lambda e: self.go(self._action_route(e.action))(),
662
+ )
663
+ with navbar:
664
+ ui.NavLink(
665
+ label="Overview", active=group is None and route == "/", on_click=self.go("/")
666
+ )
667
+ for g in self.catalogue.groups:
668
+ ui.NavLink(
669
+ label=g["title"],
670
+ active=g["id"] == group,
671
+ right_section=ui.Badge(str(g["count"]), variant="light", size="sm"),
672
+ on_click=self.go(f"/group/{g['id']}"),
673
+ )
674
+ shell.add(header, slot="header")
675
+ shell.add(navbar, slot="navbar")
676
+ with ui.Stack(gap="md") as main:
677
+ parts["main"] = main
678
+ yield parts
679
+
680
+ def _group_actions(self) -> list[dict[str, Any]]:
681
+ return [
682
+ {"id": f"group:{g['id']}", "label": g["title"], "description": f"{g['count']} entries"}
683
+ for g in self.catalogue.groups
684
+ ]
685
+
686
+ def _open_search(self, parts: dict[str, Any]) -> None:
687
+ parts["spotlight"].opened = True
688
+
689
+ def _search(self, parts: dict[str, Any], query: str) -> None:
690
+ hits = self.catalogue.search(query)
691
+ parts["spotlight"].actions = (
692
+ [
693
+ {
694
+ "id": e["id"],
695
+ "label": e["title"],
696
+ "description": f"{e['id']} · {e['classification']} · {e['disposition']}",
697
+ "group": self.catalogue.group_title(e["group"]),
698
+ }
699
+ for e in hits
700
+ ]
701
+ if query.strip()
702
+ else self._group_actions()
703
+ )
704
+
705
+ def _action_route(self, action: str) -> str:
706
+ if action.startswith("group:"):
707
+ return f"/group/{action.removeprefix('group:')}"
708
+ return entry_route(action)
709
+
710
+ # --------------------------------------------------------- RPC log
711
+ def _observe_window(self) -> None:
712
+ """Log the RPC calls of the window being built (once its page is connected)."""
713
+ w = ui.current_window()
714
+ endpoint = w.session.endpoint if w is not None else None
715
+ if endpoint is not None and endpoint.observer is None:
716
+ endpoint.observer = self.calls.record
717
+
718
+ def _rpc_log(self, parts: dict[str, Any]) -> None:
719
+ parts["rpc_button"] = ui.Button(
720
+ "RPC log",
721
+ variant="default",
722
+ left_section=ui.Icon("activity", size=14),
723
+ on_click=lambda: self._open_log(parts),
724
+ )
725
+ with (
726
+ ui.Drawer(title="RPC log of this window", position="right", size="xl") as drawer,
727
+ ui.Stack(gap="xs"),
728
+ ):
729
+ ui.Text(
730
+ f"The last {MAX_LOG} calls between this window and Python; payloads are "
731
+ f"cut to {PREVIEW_CHARS} characters and secret-looking values are redacted. "
732
+ "The page patches that draw this log do not refresh it.",
733
+ size="xs",
734
+ c="dimmed",
735
+ )
736
+ with ui.Group(gap="xs"):
737
+ parts["rpc_count"] = ui.Text("", size="sm")
738
+ parts["rpc_clear"] = ui.Button(
739
+ "Clear", size="xs", variant="light", on_click=self._clear_log
740
+ )
741
+ parts["rpc_table"] = ui.Table(
742
+ data={"head": LOG_HEAD},
743
+ striped=True,
744
+ vertical_spacing="xs",
745
+ layout="fixed",
746
+ )
747
+ parts["rpc_drawer"] = drawer
748
+
749
+ def _open_log(self, parts: dict[str, Any]) -> None:
750
+ self._show_log(parts)
751
+ parts["rpc_drawer"].opened = True
752
+
753
+ def _clear_log(self) -> None:
754
+ self.calls.clear()
755
+ self._refresh_logs()
756
+
757
+ def _show_log(self, parts: dict[str, Any]) -> None:
758
+ rows = self.calls.rows()
759
+ parts["rpc_count"].update(text=f"{len(rows)} of at most {MAX_LOG} entries")
760
+ parts["rpc_table"].update(data={"head": LOG_HEAD, "body": rows})
761
+
762
+ def _calls_changed(self) -> None:
763
+ """Refresh open logs at most every 0.25 s (calls come in bursts)."""
764
+ if self._log_pending:
765
+ return
766
+ try:
767
+ loop = asyncio.get_running_loop()
768
+ except RuntimeError: # recorded outside the loop (tests): refresh now
769
+ self._refresh_logs()
770
+ return
771
+ self._log_pending = True
772
+ loop.call_later(0.25, self._refresh_logs)
773
+
774
+ def _refresh_logs(self) -> None:
775
+ self._log_pending = False
776
+ for parts in list(self.pages.values()):
777
+ drawer = parts.get("rpc_drawer")
778
+ if drawer is not None and not drawer.disposed and drawer.opened is True:
779
+ self._show_log(parts)
780
+
781
+ # ------------------------------------------------------------ home
782
+ def _home(self) -> None:
783
+ cat = self.catalogue
784
+ entries = list(cat.entries.values())
785
+ with self._frame("/", None) as parts:
786
+ parts["title"] = ui.Title("Catalogue overview", order=2)
787
+ ui.Text(
788
+ f"{len(entries)} entries: every component, block, hook, native API example, "
789
+ "pattern and workspace application of the showcase, with its recorded status. "
790
+ "Pick a group on the left or search with Ctrl+K."
791
+ )
792
+ counts: dict[str, int] = {}
793
+ for e in entries:
794
+ counts[e["disposition"]] = counts.get(e["disposition"], 0) + 1
795
+ with ui.Group(gap="xs"):
796
+ for d, n in sorted(counts.items()):
797
+ ui.Badge(f"{d}: {n}", color=DISPOSITION_COLORS.get(d, "blue"), variant="light")
798
+ with ui.SimpleGrid(cols=3, spacing="md"):
799
+ for g in cat.groups:
800
+ with ui.Paper(with_border=True, p="md"), ui.Stack(gap="xs"):
801
+ ui.Title(g["title"], order=4)
802
+ ui.Text(f"{g['count']} entries", c="dimmed", size="sm")
803
+ ui.Button(
804
+ "Open",
805
+ variant="light",
806
+ size="xs",
807
+ on_click=self.go(f"/group/{g['id']}"),
808
+ )
809
+
810
+ # ----------------------------------------------------------- group
811
+ def _group_builder(self, gid: str) -> Callable[[], None]:
812
+ def build() -> None:
813
+ route = f"/group/{gid}"
814
+ rows = [e for e in self.catalogue.entries.values() if e["group"] == gid]
815
+ with self._frame(route, gid) as parts:
816
+ parts["title"] = ui.Title(self.catalogue.group_title(gid), order=2)
817
+ subs: dict[str, list[dict[str, Any]]] = {}
818
+ for e in rows:
819
+ subs.setdefault(e["subcategory"] or "", []).append(e)
820
+ for sub, items in subs.items():
821
+ if sub:
822
+ ui.Title(sub, order=5, c="dimmed")
823
+ with ui.SimpleGrid(cols=2, spacing="xs", vertical_spacing=0):
824
+ for e in items:
825
+ ui.NavLink(
826
+ label=e["title"],
827
+ description=e["id"],
828
+ right_section=ui.Badge(
829
+ e["disposition"],
830
+ size="xs",
831
+ variant="light",
832
+ color=DISPOSITION_COLORS.get(e["disposition"], "blue"),
833
+ ),
834
+ on_click=self.go(entry_route(e["id"])),
835
+ )
836
+
837
+ return build
838
+
839
+ # ----------------------------------------------------------- entry
840
+ def _entry_builder(self, eid: str) -> Callable[[], None]:
841
+ def build() -> None:
842
+ self._entry(eid)
843
+
844
+ return build
845
+
846
+ def _entry(self, eid: str) -> None:
847
+ cat = self.catalogue
848
+ e = cat.entries[eid]
849
+ route = entry_route(eid)
850
+ with self._frame(route, e["group"]) as parts:
851
+ parts["entry"] = e
852
+ with ui.Group(gap="xs"):
853
+ ui.Button(
854
+ cat.group_title(e["group"]),
855
+ variant="subtle",
856
+ size="xs",
857
+ on_click=self.go(f"/group/{e['group']}"),
858
+ )
859
+ if e["subcategory"]:
860
+ ui.Text(f"/ {e['subcategory']}", size="sm", c="dimmed")
861
+ parts["title"] = ui.Title(e["title"], order=2)
862
+ with ui.Group(gap="xs"):
863
+ ui.Code(eid)
864
+ ui.Badge(e["classification"], variant="outline")
865
+ ui.Badge(
866
+ e["disposition"],
867
+ variant="light",
868
+ color=DISPOSITION_COLORS.get(e["disposition"], "blue"),
869
+ )
870
+ if e["implementation_phase"]:
871
+ ui.Badge(e["implementation_phase"], variant="default")
872
+ self._example_bar(e, parts)
873
+ if e["limitations"]:
874
+ with ui.Alert(
875
+ title="Limitations and notes",
876
+ color="orange" if e["disposition"] == "excluded" else "gray",
877
+ variant="light",
878
+ ):
879
+ for text in e["limitations"]:
880
+ ui.Text(text, size="sm")
881
+ self._preview(e, parts)
882
+ self._source(e, parts)
883
+ self._api(e)
884
+ self._tests(e)
885
+ if e["related"]:
886
+ ui.Title("Related", order=4)
887
+ with ui.Group(gap="xs"):
888
+ for rid in e["related"]:
889
+ ui.Button(
890
+ cat.entries[rid]["title"],
891
+ variant="light",
892
+ size="xs",
893
+ on_click=self.go(entry_route(rid)),
894
+ )
895
+
896
+ def _example_bar(self, e: dict[str, Any], parts: dict[str, Any]) -> None:
897
+ ex = e["example"]
898
+ if not ex:
899
+ return
900
+ if ex["missing"]:
901
+ parts["missing"] = ui.Alert(
902
+ title="Example not available yet",
903
+ text=f"{ex['path']} is named by this row but is not part of this build.",
904
+ color="yellow",
905
+ variant="light",
906
+ )
907
+ return
908
+ if not ex["runnable"]:
909
+ return
910
+ eid, route = e["id"], entry_route(e["id"])
911
+ proc = self.runner.procs.get(eid)
912
+ running = proc is not None and proc.poll() is None
913
+ with ui.Group(gap="xs"):
914
+ run = ui.Button(
915
+ "Run example", left_section=ui.Icon("player-play", size=14), disabled=running
916
+ )
917
+ stop = ui.Button("Stop", variant="default", disabled=not running)
918
+ status = ui.Text(
919
+ f"running (pid {proc.pid})"
920
+ if running and proc is not None
921
+ else f"{ex['path']} runs in its own process",
922
+ size="sm",
923
+ c="dimmed",
924
+ )
925
+ parts.update(run=run, stop=stop, status=status)
926
+
927
+ def show_state(text: str, running: bool) -> None:
928
+ p = self.pages.get(route) # the page may have been emptied and refilled since
929
+ if p is not None and "run" in p:
930
+ p["run"].update(disabled=running)
931
+ p["stop"].update(disabled=not running)
932
+ p["status"].update(text=text)
933
+
934
+ async def start(*_: Any) -> None:
935
+ proc = await asyncio.to_thread(self.runner.start, e)
936
+ show_state(f"running (pid {proc.pid})", True)
937
+ task = asyncio.get_running_loop().create_task(watch(proc))
938
+ self._tasks.add(task)
939
+ task.add_done_callback(self._tasks.discard)
940
+
941
+ async def watch(proc: subprocess.Popen[bytes]) -> None:
942
+ code = await asyncio.to_thread(proc.wait)
943
+ if self.runner.procs.get(eid) is proc:
944
+ await asyncio.to_thread(self.runner.stop, eid)
945
+ show_state(f"exited with status {code}", False)
946
+
947
+ async def halt(*_: Any) -> None:
948
+ code = await asyncio.to_thread(self.runner.stop, eid)
949
+ show_state(f"stopped (status {code})", False)
950
+
951
+ run.on("click", start)
952
+ stop.on("click", halt)
953
+
954
+ def _preview(self, e: dict[str, Any], parts: dict[str, Any]) -> None:
955
+ ui.Title("Live preview", order=4)
956
+ comps = [self.catalogue.components[n] for n in e["components"]]
957
+ block = e["block"]
958
+ roots: list[ui.Component] = []
959
+ specs: list[dict[str, Any]] = []
960
+ with ui.Stack(gap="sm") as box:
961
+ parts["preview"] = box
962
+ if block and block["name"] in self.previews.SAMPLES:
963
+ ui.Text(
964
+ f"ui.blocks.{block['name']}"
965
+ + (f" variant={block['variant']!r}" if block["variant"] else ""),
966
+ size="sm",
967
+ c="dimmed",
968
+ )
969
+ with ui.Paper(with_border=True, p="md", styles={"position": "relative"}) as frame:
970
+ self.previews.block_preview(block["name"], block["variant"])
971
+ roots += frame.children
972
+ elif comps and e["classification"] != "excluded":
973
+ for c in comps:
974
+ for i, ex in enumerate(c["examples"]):
975
+ label = ex.get("title") or f"example {i + 1}"
976
+ ui.Text(f"ui.{c['name']} · {label}", size="sm", c="dimmed")
977
+ with ui.Paper(
978
+ with_border=True, p="md", styles={"position": "relative"}
979
+ ) as frame:
980
+ spec = {
981
+ "type": c["name"],
982
+ **{k: v for k, v in ex.items() if k != "title"},
983
+ }
984
+ roots.append(frame.add(_component_from_example(spec)))
985
+ specs.append(spec)
986
+ else:
987
+ reason = NO_PREVIEW.get(e["classification"], "No visual preview for this entry.")
988
+ ui.Text(reason, c="dimmed", size="sm")
989
+ parts["preview_roots"] = roots
990
+ parts["specs"] = specs
991
+ if specs:
992
+ self._editor(e, parts, comps[0], roots[0], specs[0])
993
+ self._export_bar(e, parts)
994
+
995
+ # ------------------------------------------------- property editor
996
+ def _editor(
997
+ self,
998
+ e: dict[str, Any],
999
+ parts: dict[str, Any],
1000
+ contract: dict[str, Any],
1001
+ comp: ui.Component,
1002
+ spec: dict[str, Any],
1003
+ ) -> None:
1004
+ route = entry_route(e["id"])
1005
+ ed: dict[str, Any] = {
1006
+ "contract": contract,
1007
+ "component": comp,
1008
+ "spec": spec,
1009
+ "props": dict(spec.get("props", {})),
1010
+ "controls": {},
1011
+ }
1012
+ parts["edit"] = ed
1013
+ with ui.Paper(with_border=True, p="md"), ui.Stack(gap="xs"):
1014
+ with ui.Group(justify="space-between"):
1015
+ ui.Title(f"Edit properties: ui.{contract['name']} · example 1", order=5)
1016
+ parts["reset"] = ui.Button(
1017
+ "Reset",
1018
+ size="xs",
1019
+ variant="light",
1020
+ on_click=lambda: self.reset(route),
1021
+ )
1022
+ ui.Text(
1023
+ "Each change is set on the real component of the first preview; an "
1024
+ "invalid value shows its error and leaves the preview unchanged.",
1025
+ size="xs",
1026
+ c="dimmed",
1027
+ )
1028
+ with ui.SimpleGrid(cols=3, spacing="sm", vertical_spacing="xs"):
1029
+ for prop in contract["props"]:
1030
+ value = ed["props"].get(prop["name"], UNSET)
1031
+ ed["controls"][prop["name"]] = self._control(route, prop, value)
1032
+
1033
+ def _control(self, route: str, prop: dict[str, Any], value: Any) -> ui.Component:
1034
+ name, kind = prop["name"], prop["kind"]
1035
+
1036
+ def changed(ev: Any) -> None:
1037
+ self.edit(route, name, ev.value)
1038
+
1039
+ label = f"{name} ({kind})"
1040
+ if kind == "boolean":
1041
+ return ui.Switch(label=label, checked=value is True, on_change=changed)
1042
+ if kind in ("enum", "size") and (kind == "enum" or value is UNSET or value in SIZES):
1043
+ data = list(prop.get("values", [])) if kind == "enum" else SIZES
1044
+ return ui.Select(
1045
+ label=label,
1046
+ data=data,
1047
+ value=value if value in data else None,
1048
+ placeholder="default",
1049
+ on_change=changed,
1050
+ )
1051
+ if kind in ("integer", "number"):
1052
+ return ui.NumberInput(
1053
+ label=label,
1054
+ value=value if isinstance(value, (int, float)) else UNSET,
1055
+ allow_decimal=kind == "number",
1056
+ placeholder="default",
1057
+ on_change=changed,
1058
+ )
1059
+ if kind == "size" or kind in TEXT_KINDS:
1060
+ return ui.TextInput(
1061
+ label=label,
1062
+ value="" if value is UNSET else str(value),
1063
+ placeholder="default",
1064
+ on_change=changed,
1065
+ )
1066
+ return ui.JsonInput(
1067
+ label=f"{name} ({kind}, JSON)",
1068
+ value=_editor_text(value),
1069
+ placeholder="default",
1070
+ autosize=True,
1071
+ max_rows=6,
1072
+ on_change=changed,
1073
+ )
1074
+
1075
+ def edit(self, route: str, name: str, raw: Any) -> str | None:
1076
+ """Apply an editor change to the real preview component; returns the
1077
+ error shown next to the control (None: applied)."""
1078
+ parts = self.pages.get(route)
1079
+ if parts is None or "edit" not in parts:
1080
+ return None
1081
+ ed = parts["edit"]
1082
+ prop = next(p for p in ed["contract"]["props"] if p["name"] == name)
1083
+ control: ui.Component = ed["controls"][name]
1084
+ try:
1085
+ value = coerce(prop, raw)
1086
+ ed["component"].update(**{name: value})
1087
+ except ValueError as err: # includes the component's ValidationError
1088
+ control.update(**_error_props(control, str(err)))
1089
+ return str(err)
1090
+ control.update(**_error_props(control, UNSET))
1091
+ if value is UNSET:
1092
+ ed["props"].pop(name, None)
1093
+ else:
1094
+ ed["props"][name] = value
1095
+ self._update_sources(parts)
1096
+ return None
1097
+
1098
+ def reset(self, route: str) -> None:
1099
+ """Restore the example's props on the preview and in the controls."""
1100
+ parts = self.pages.get(route)
1101
+ if parts is None or "edit" not in parts:
1102
+ return
1103
+ ed = parts["edit"]
1104
+ original: dict[str, Any] = dict(ed["spec"].get("props", {}))
1105
+ names = [p["name"] for p in ed["contract"]["props"]]
1106
+ ed["component"].update(**{n: original.get(n, UNSET) for n in names})
1107
+ ed["props"] = original
1108
+ for prop in ed["contract"]["props"]:
1109
+ control: ui.Component = ed["controls"][prop["name"]]
1110
+ v = original.get(prop["name"], UNSET)
1111
+ if isinstance(control, ui.Switch):
1112
+ control.update(checked=v is True, error=UNSET)
1113
+ elif isinstance(control, ui.Select):
1114
+ control.update(value=v if isinstance(v, str) else None, error=UNSET)
1115
+ elif isinstance(control, ui.NumberInput):
1116
+ control.update(value=v if isinstance(v, (int, float)) else UNSET, error=UNSET)
1117
+ elif isinstance(control, ui.JsonInput):
1118
+ control.update(value=_editor_text(v), **_error_props(control, UNSET))
1119
+ else:
1120
+ control.update(value="" if v is UNSET else str(v), error=UNSET)
1121
+ self._update_sources(parts)
1122
+
1123
+ def current_specs(self, parts: dict[str, Any]) -> list[dict[str, Any]]:
1124
+ """The preview's contract examples, the first with its edited props."""
1125
+ specs: list[dict[str, Any]] = list(parts.get("specs", []))
1126
+ if specs and "edit" in parts:
1127
+ specs[0] = {**specs[0], "props": dict(parts["edit"]["props"])}
1128
+ return specs
1129
+
1130
+ # ------------------------------------------------- export and run
1131
+ def _export_bar(self, e: dict[str, Any], parts: dict[str, Any]) -> None:
1132
+ eid, route = e["id"], entry_route(e["id"])
1133
+ key = f"{eid}#export"
1134
+ with ui.Paper(with_border=True, p="md"), ui.Stack(gap="xs"):
1135
+ ui.Title("Standalone example", order=5)
1136
+ parts["export_dir"] = ui.TextInput(
1137
+ label="Export directory (app.py is written there; nothing is overwritten)",
1138
+ value=str(default_export_dir(eid)),
1139
+ )
1140
+ with ui.Group(gap="xs"):
1141
+ parts["export"] = ui.Button(
1142
+ "Export example",
1143
+ left_section=ui.Icon("download", size=14),
1144
+ on_click=lambda: self.export(route),
1145
+ )
1146
+ parts["run_export"] = ui.Button(
1147
+ "Run",
1148
+ variant="default",
1149
+ left_section=ui.Icon("player-play", size=14),
1150
+ disabled=True,
1151
+ )
1152
+ parts["stop_export"] = ui.Button("Stop", variant="default", disabled=True)
1153
+ parts["export_status"] = ui.Text(
1154
+ "Writes a runnable app.py with the current properties.", size="sm", c="dimmed"
1155
+ )
1156
+
1157
+ def show(text: str, running: bool | None = None) -> None:
1158
+ p = self.pages.get(route)
1159
+ if p is not None and "export_status" in p:
1160
+ p["export_status"].update(text=text)
1161
+ if running is not None:
1162
+ p["run_export"].update(disabled=running)
1163
+ p["stop_export"].update(disabled=not running)
1164
+
1165
+ async def run(*_: Any) -> None:
1166
+ p = self.pages.get(route)
1167
+ script = p.get("exported") if p else None
1168
+ if script is None:
1169
+ return
1170
+ proc = await asyncio.to_thread(self.runner.start_script, key, script)
1171
+ show(f"running {script} (pid {proc.pid})", True)
1172
+ task = asyncio.get_running_loop().create_task(watch(proc))
1173
+ self._tasks.add(task)
1174
+ task.add_done_callback(self._tasks.discard)
1175
+
1176
+ async def watch(proc: subprocess.Popen[bytes]) -> None:
1177
+ code = await asyncio.to_thread(proc.wait)
1178
+ if self.runner.procs.get(key) is proc:
1179
+ await asyncio.to_thread(self.runner.stop, key)
1180
+ show(f"exited with status {code}", False)
1181
+
1182
+ async def halt(*_: Any) -> None:
1183
+ code = await asyncio.to_thread(self.runner.stop, key)
1184
+ show(f"stopped (status {code})", False)
1185
+
1186
+ parts["run_export"].on("click", run)
1187
+ parts["stop_export"].on("click", halt)
1188
+
1189
+ def export(self, route: str) -> Path | None:
1190
+ """Write the standalone example of the page (its current properties)."""
1191
+ parts = self.pages.get(route)
1192
+ if parts is None or "export_dir" not in parts:
1193
+ return None
1194
+ e = parts["entry"]
1195
+ code = standalone_app(e["title"], e["id"], self.current_specs(parts))
1196
+ try:
1197
+ path = export_example(str(parts["export_dir"].value or ""), code)
1198
+ except ValueError as err:
1199
+ parts["export_status"].update(text=f"Not exported: {err}")
1200
+ return None
1201
+ parts["exported"] = path
1202
+ parts["export_status"].update(text=f"Wrote {path}")
1203
+ parts["run_export"].update(disabled=False)
1204
+ return path
1205
+
1206
+ # ----------------------------------------------------------- source
1207
+ def _source(self, e: dict[str, Any], parts: dict[str, Any]) -> None:
1208
+ ex = e["example"]
1209
+ ui.Title("Source", order=4)
1210
+ if ex and not ex["missing"] and ex["source"]:
1211
+ ui.Text(f"Python: {ex['path']}", size="sm", c="dimmed")
1212
+ elif parts.get("specs"):
1213
+ ui.Text(
1214
+ "Python: the code of the live preview (contract examples)", size="sm", c="dimmed"
1215
+ )
1216
+ else:
1217
+ ui.Text("No standalone Python example file for this entry.", c="dimmed", size="sm")
1218
+ files = self._source_files(e, parts)
1219
+ if files:
1220
+ parts["source"] = ui.CodeHighlightTabs(
1221
+ code=files,
1222
+ with_copy_button=True,
1223
+ with_expand_button=True,
1224
+ max_collapsed_height=360,
1225
+ )
1226
+ if not any(f["language"] != "python" for f in files):
1227
+ parts["frontend_note"] = ui.Text(
1228
+ FRONTEND_NOTES.get(e["classification"], FRONTEND_NOTE_DEFAULT),
1229
+ c="dimmed",
1230
+ size="sm",
1231
+ )
1232
+
1233
+ def _source_files(self, e: dict[str, Any], parts: dict[str, Any]) -> list[dict[str, str]]:
1234
+ """The source tabs: the example file, the preview's Python (current
1235
+ properties) and its custom-frontend equivalent where meaningful."""
1236
+ files: list[dict[str, str]] = []
1237
+ ex = e["example"]
1238
+ if ex and not ex["missing"] and ex["source"]:
1239
+ code = self.catalogue.source_path(ex["source"]).read_text("utf-8")
1240
+ files.append(
1241
+ {"file_name": ex["source"].rsplit("/", 1)[-1], "code": code, "language": "python"}
1242
+ )
1243
+ specs = self.current_specs(parts)
1244
+ if specs:
1245
+ code = "from neutralino import ui\n\n" + "\n\n".join(
1246
+ _python_from_example(s) for s in specs
1247
+ )
1248
+ files.append({"file_name": "preview.py", "code": code, "language": "python"})
1249
+ roots: list[ui.Component] = parts.get("preview_roots", [])
1250
+ if roots:
1251
+ jsx = jsx_from_nodes([r.to_node() for r in roots], self.catalogue.renderers)
1252
+ files.append({"file_name": "Example.jsx", "code": jsx, "language": "jsx"})
1253
+ elif e.get("native"):
1254
+ js = js_from_native(e["native"])
1255
+ files.append({"file_name": "frontend.js", "code": js, "language": "javascript"})
1256
+ return files
1257
+
1258
+ def _update_sources(self, parts: dict[str, Any]) -> None:
1259
+ if "source" in parts:
1260
+ parts["source"].update(code=self._source_files(parts["entry"], parts))
1261
+
1262
+ def _api(self, e: dict[str, Any]) -> None:
1263
+ ui.Title("Public API", order=4)
1264
+ if e["public_api"]:
1265
+ with ui.Group(gap="xs"):
1266
+ for a in e["public_api"]:
1267
+ ui.Code(a)
1268
+ else:
1269
+ ui.Text("None recorded.", c="dimmed", size="sm")
1270
+ for name in e["components"]:
1271
+ c = self.catalogue.components[name]
1272
+ ui.Title(f"ui.{name}", order=5)
1273
+ ui.Text(c["description"], size="sm")
1274
+ if c["props"]:
1275
+ ui.Table(
1276
+ data={
1277
+ "head": ["Prop", "Kind", "Notes"],
1278
+ "body": [
1279
+ [
1280
+ p["name"],
1281
+ p["kind"] + (" | None" if p.get("nullable") else ""),
1282
+ (" | ".join(p["values"]) + ". " if p.get("values") else "")
1283
+ + p.get("doc", ""),
1284
+ ]
1285
+ for p in c["props"]
1286
+ ],
1287
+ },
1288
+ striped=True,
1289
+ with_table_border=True,
1290
+ )
1291
+ events = ", ".join(ev["name"] for ev in c["events"]) or "none"
1292
+ slots = ", ".join(c["slots"]) or "none"
1293
+ ui.Text(
1294
+ f"Events: {events}. Slots: {slots}. Children: {'yes' if c['children'] else 'no'}.",
1295
+ size="sm",
1296
+ )
1297
+
1298
+ def _tests(self, e: dict[str, Any]) -> None:
1299
+ ui.Title(f"Tests ({len(e['tests'])})", order=4)
1300
+ if e["tests"]:
1301
+ with ui.List(size="sm", spacing=2):
1302
+ for t in e["tests"]:
1303
+ ui.ListItem(t)
1304
+ else:
1305
+ ui.Text("No test recorded.", c="dimmed", size="sm")
1306
+ ui.Title("Evidence", order=4)
1307
+ if e["evidence"]:
1308
+ for ev in e["evidence"]:
1309
+ ui.Text(" · ".join(f"{k}: {v}" for k, v in sorted(ev.items())), size="sm")
1310
+ else:
1311
+ ui.Text("No evidence recorded.", c="dimmed", size="sm")
1312
+
1313
+
1314
+ def build(app: ui.AsyncApplication, catalogue: Catalogue | None = None) -> Explorer:
1315
+ return Explorer(app, catalogue)
1316
+
1317
+
1318
+ def main() -> None:
1319
+ app = ui.AsyncApplication(title=TITLE, width=1200, height=820, profile="restricted")
1320
+ explorer = build(app)
1321
+ try:
1322
+ asyncio.run(app.run())
1323
+ finally:
1324
+ explorer.runner.stop_all()
1325
+
1326
+
1327
+ if __name__ == "__main__":
1328
+ main()