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