neutralino-python 0.1.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- 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-BlJrWVuo.js +1 -0
- neutralino/_data/renderer/assets/carousel-D1j1SkWR.css +1 -0
- neutralino/_data/renderer/assets/carousel-DniHwTLK.js +1 -0
- neutralino/_data/renderer/assets/chunk-CCkLOSkX.css +1 -0
- neutralino/_data/renderer/assets/chunk-Du0h7lB-.js +9 -0
- neutralino/_data/renderer/assets/codehighlight-CCe_blv1.js +10 -0
- neutralino/_data/renderer/assets/codehighlight-THJMNDh8.css +1 -0
- neutralino/_data/renderer/assets/codemirror-CinrNxVJ.js +2 -0
- neutralino/_data/renderer/assets/css-CMUk25uq.js +1 -0
- neutralino/_data/renderer/assets/dist-70Le0T2N.js +1 -0
- neutralino/_data/renderer/assets/dist-BCHbQlae.js +11 -0
- neutralino/_data/renderer/assets/dist-BXts23GT.js +1 -0
- neutralino/_data/renderer/assets/dist-D2RX2UgP.js +23 -0
- neutralino/_data/renderer/assets/dist-DikJK2lp.js +1 -0
- neutralino/_data/renderer/assets/dist-acbbRM1z.js +1 -0
- neutralino/_data/renderer/assets/dnd-DaaaVala.js +5 -0
- neutralino/_data/renderer/assets/dropzone-CeqF5SZx.js +1 -0
- neutralino/_data/renderer/assets/dropzone-aPCBPjDN.css +1 -0
- neutralino/_data/renderer/assets/embla-carousel-react.esm-CbyYjwMN.js +1 -0
- neutralino/_data/renderer/assets/emoji-BfRPfoVw.js +1 -0
- neutralino/_data/renderer/assets/emoji-DV8OzU1E.css +1 -0
- neutralino/_data/renderer/assets/esm-C5ZYjSBQ.js +82 -0
- neutralino/_data/renderer/assets/highlight-CB6hGb5A.js +3 -0
- neutralino/_data/renderer/assets/highlight-Dlb5DJwL.css +1 -0
- neutralino/_data/renderer/assets/html-Dad3kwIa.js +1 -0
- neutralino/_data/renderer/assets/icon-chunk-X3Kr0nh-.js +1 -0
- neutralino/_data/renderer/assets/index-CU0HB-J7.js +69 -0
- neutralino/_data/renderer/assets/index-TWpF4Lef.css +1 -0
- neutralino/_data/renderer/assets/javascript-BQb8vpw3.js +1 -0
- neutralino/_data/renderer/assets/json-BCFmxlML.js +1 -0
- neutralino/_data/renderer/assets/lightbox-BHtgbsUV.js +1 -0
- neutralino/_data/renderer/assets/lightbox-BzKDpkAD.css +1 -0
- neutralino/_data/renderer/assets/markdown-DSuAylvy.js +5 -0
- neutralino/_data/renderer/assets/markdown-DjaNWMgH.js +77 -0
- neutralino/_data/renderer/assets/python-pdbIAveZ.js +9 -0
- neutralino/_data/renderer/assets/richtext-DIAsHMuK.css +1 -0
- neutralino/_data/renderer/assets/richtext-Z6fG9G2_.js +137 -0
- neutralino/_data/renderer/assets/spotlight-Ccstaz1-.css +1 -0
- neutralino/_data/renderer/assets/spotlight-knlyJw_A.js +1 -0
- neutralino/_data/renderer/assets/sql-DLoQFEde.js +2 -0
- neutralino/_data/renderer/assets/with-selector-BOM9_OlN.js +1 -0
- neutralino/_data/renderer/assets/yaml-BJNzokSe.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 +1260 -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.0.dist-info/METADATA +121 -0
- neutralino_python-0.1.0.dist-info/RECORD +521 -0
- neutralino_python-0.1.0.dist-info/WHEEL +4 -0
- neutralino_python-0.1.0.dist-info/entry_points.txt +3 -0
- neutralino_python-0.1.0.dist-info/licenses/LICENSE +21 -0
- neutralino_python-0.1.0.dist-info/licenses/THIRD_PARTY_NOTICES.md +16 -0
- neutralino_python-0.1.0.dist-info/licenses/src/neutralino/_data/renderer/LICENSES/packages.json +1838 -0
|
@@ -0,0 +1,790 @@
|
|
|
1
|
+
"""Extension components (P04.06): domain validation, typed events, commands.
|
|
2
|
+
|
|
3
|
+
The generated classes declare the contracts; these subclasses add what the
|
|
4
|
+
generic prop kinds cannot express:
|
|
5
|
+
|
|
6
|
+
* ``Carousel`` - slide index bounded by the slides that exist;
|
|
7
|
+
* ``Dropzone``/``DropzoneFullScreen`` - every dropped file is re-validated in
|
|
8
|
+
Python (count, size, MIME/extension allowlist, safe name); content is pulled
|
|
9
|
+
from the page in bounded chunks on demand (:meth:`DroppedFile.read`), never
|
|
10
|
+
as a local path the page could choose;
|
|
11
|
+
* ``EmojiPicker``/``EmojiPickerInput``/``EmojiPickerPopover`` - picks and
|
|
12
|
+
values are checked against the bundled emoji data (``_data/ui/emoji.json``);
|
|
13
|
+
* ``Lightbox`` - slide data allowlist and safe sources, index bounds;
|
|
14
|
+
* ``Spotlight`` - typed actions, hotkeys, trigger validation;
|
|
15
|
+
* ``DragDropList`` - typed items, reorder accepted only as a one-item move of
|
|
16
|
+
the current keys.
|
|
17
|
+
"""
|
|
18
|
+
|
|
19
|
+
from __future__ import annotations
|
|
20
|
+
|
|
21
|
+
import base64
|
|
22
|
+
import functools
|
|
23
|
+
import json
|
|
24
|
+
import mimetypes
|
|
25
|
+
import re
|
|
26
|
+
import unicodedata
|
|
27
|
+
from collections.abc import Mapping, Sequence
|
|
28
|
+
from dataclasses import dataclass, field
|
|
29
|
+
from importlib.resources import files
|
|
30
|
+
from typing import TYPE_CHECKING, Any, cast
|
|
31
|
+
|
|
32
|
+
from ...errors import RpcError, ValidationError
|
|
33
|
+
from .._behaviours import Pending, normalize_bindings, run_on_window
|
|
34
|
+
from .._component import TREE_LOCK, Component, PropSpec
|
|
35
|
+
from .._events import DropEvent, EmojiEvent, Event, ReorderEvent, SpotlightActionEvent
|
|
36
|
+
from ._generated import Carousel as _Carousel
|
|
37
|
+
from ._generated import DragDropList as _DragDropList
|
|
38
|
+
from ._generated import Dropzone as _Dropzone
|
|
39
|
+
from ._generated import DropzoneFullScreen as _DropzoneFullScreen
|
|
40
|
+
from ._generated import EmojiPicker as _EmojiPicker
|
|
41
|
+
from ._generated import EmojiPickerInput as _EmojiPickerInput
|
|
42
|
+
from ._generated import EmojiPickerPopover as _EmojiPickerPopover
|
|
43
|
+
from ._generated import Lightbox as _Lightbox
|
|
44
|
+
from ._generated import Spotlight as _Spotlight
|
|
45
|
+
|
|
46
|
+
if TYPE_CHECKING:
|
|
47
|
+
from .._session import WindowSession
|
|
48
|
+
|
|
49
|
+
__all__ = [
|
|
50
|
+
"DEFAULT_MAX_FILES",
|
|
51
|
+
"DEFAULT_MAX_SIZE",
|
|
52
|
+
"Carousel",
|
|
53
|
+
"DragDropList",
|
|
54
|
+
"DropEvent",
|
|
55
|
+
"DroppedFile",
|
|
56
|
+
"Dropzone",
|
|
57
|
+
"DropzoneFullScreen",
|
|
58
|
+
"EmojiEvent",
|
|
59
|
+
"EmojiPicker",
|
|
60
|
+
"EmojiPickerInput",
|
|
61
|
+
"EmojiPickerPopover",
|
|
62
|
+
"Lightbox",
|
|
63
|
+
"RejectedFile",
|
|
64
|
+
"ReorderEvent",
|
|
65
|
+
"Spotlight",
|
|
66
|
+
"SpotlightActionEvent",
|
|
67
|
+
"check_file_name",
|
|
68
|
+
"emoji_char",
|
|
69
|
+
"file_type_allowed",
|
|
70
|
+
]
|
|
71
|
+
|
|
72
|
+
|
|
73
|
+
def _str(v: Any, path: str, *, max_len: int, required: bool = True) -> str | None:
|
|
74
|
+
if v is None and not required:
|
|
75
|
+
return None
|
|
76
|
+
if not isinstance(v, str):
|
|
77
|
+
raise ValidationError(f"{path}: expected str")
|
|
78
|
+
if len(v) > max_len:
|
|
79
|
+
raise ValidationError(f"{path}: longer than {max_len} characters")
|
|
80
|
+
return v
|
|
81
|
+
|
|
82
|
+
|
|
83
|
+
def _records(value: Any, path: str, max_items: int) -> list[Mapping[str, Any]]:
|
|
84
|
+
if isinstance(value, (str, Mapping)) or not isinstance(value, Sequence):
|
|
85
|
+
raise ValidationError(f"{path}: expected a list of mappings")
|
|
86
|
+
items = list(cast("Sequence[Any]", value))
|
|
87
|
+
if len(items) > max_items:
|
|
88
|
+
raise ValidationError(f"{path}: more than {max_items} items")
|
|
89
|
+
for i, it in enumerate(items):
|
|
90
|
+
if not isinstance(it, Mapping):
|
|
91
|
+
raise ValidationError(f"{path}[{i}]: expected a mapping")
|
|
92
|
+
return cast("list[Mapping[str, Any]]", items)
|
|
93
|
+
|
|
94
|
+
|
|
95
|
+
def _keys(m: Mapping[str, Any], allowed: set[str], path: str) -> None:
|
|
96
|
+
extra = set(m) - allowed
|
|
97
|
+
if extra:
|
|
98
|
+
raise ValidationError(f"{path}: unknown keys {sorted(extra)} (allowed: {sorted(allowed)})")
|
|
99
|
+
|
|
100
|
+
|
|
101
|
+
# ===================================================================== Carousel
|
|
102
|
+
class Carousel(_Carousel):
|
|
103
|
+
__doc__ = _Carousel.__doc__
|
|
104
|
+
|
|
105
|
+
@property
|
|
106
|
+
def count(self) -> int:
|
|
107
|
+
"""Number of slides (CarouselSlide children)."""
|
|
108
|
+
return len(self.children)
|
|
109
|
+
|
|
110
|
+
def _check_client_value(self, value: Any) -> None:
|
|
111
|
+
super()._check_client_value(value)
|
|
112
|
+
n = self.count
|
|
113
|
+
if not isinstance(value, int) or not 0 <= value < max(n, 1):
|
|
114
|
+
raise ValidationError(
|
|
115
|
+
f"Carousel.slide_change: {value!r} is not a slide index (0..{n - 1})"
|
|
116
|
+
)
|
|
117
|
+
|
|
118
|
+
def _step(self, delta: int) -> None:
|
|
119
|
+
n = self.count
|
|
120
|
+
if n == 0:
|
|
121
|
+
return
|
|
122
|
+
cur = self.slide
|
|
123
|
+
i = (0 if not isinstance(cur, int) else cur) + delta
|
|
124
|
+
i = i % n if self.loop is True else min(max(i, 0), n - 1)
|
|
125
|
+
self.slide = i
|
|
126
|
+
|
|
127
|
+
def next(self) -> None:
|
|
128
|
+
"""Scroll to the next slide (wraps around when ``loop``)."""
|
|
129
|
+
self._step(1)
|
|
130
|
+
|
|
131
|
+
def previous(self) -> None:
|
|
132
|
+
"""Scroll to the previous slide (wraps around when ``loop``)."""
|
|
133
|
+
self._step(-1)
|
|
134
|
+
|
|
135
|
+
|
|
136
|
+
# ===================================================================== Dropzone
|
|
137
|
+
#: Default and hard limits of dropped files.
|
|
138
|
+
DEFAULT_MAX_SIZE = 10 * 1024 * 1024
|
|
139
|
+
DEFAULT_MAX_FILES = 10
|
|
140
|
+
_MAX_REPORTED = 200
|
|
141
|
+
_CHUNK = 512 * 1024
|
|
142
|
+
_TOKEN_RE = re.compile(r"^f[0-9a-z]{1,24}$")
|
|
143
|
+
_PAGE_CODES = frozenset({"file-too-large", "file-too-small", "file-invalid-type", "too-many-files"})
|
|
144
|
+
_WIN_RESERVED = re.compile(r"^(con|prn|aux|nul|com[0-9]|lpt[0-9])(\..*)?$", re.IGNORECASE)
|
|
145
|
+
_BIDI = frozenset("")
|
|
146
|
+
# Deterministic MIME table (the built-in one, not the machine's /etc/mime.types).
|
|
147
|
+
_MIME = mimetypes.MimeTypes(filenames=())
|
|
148
|
+
_ACCEPT_RE = re.compile(
|
|
149
|
+
r"^(\.[a-z0-9][a-z0-9_+\-]{0,31}|[a-z0-9][a-z0-9.+\-]{0,63}/(\*|[a-z0-9][a-z0-9.+\-]{0,126}))$"
|
|
150
|
+
)
|
|
151
|
+
|
|
152
|
+
|
|
153
|
+
def check_file_name(name: Any) -> str:
|
|
154
|
+
"""Return ``name`` (NFC) if it is a safe plain file name, else raise.
|
|
155
|
+
|
|
156
|
+
Refused: empty or longer than 255 UTF-8 bytes, path separators (``/``,
|
|
157
|
+
``\\``), ``.``/``..``, NUL, control and bidi-override characters,
|
|
158
|
+
trailing dots/spaces and Windows device names (``CON``, ``NUL``, ...).
|
|
159
|
+
"""
|
|
160
|
+
if not isinstance(name, str):
|
|
161
|
+
raise ValidationError("file name must be a string")
|
|
162
|
+
n = unicodedata.normalize("NFC", name)
|
|
163
|
+
if not n or len(n.encode("utf-8")) > 255:
|
|
164
|
+
raise ValidationError("file name is empty or longer than 255 bytes")
|
|
165
|
+
if "/" in n or "\\" in n:
|
|
166
|
+
raise ValidationError("file name contains a path separator")
|
|
167
|
+
if n in (".", ".."):
|
|
168
|
+
raise ValidationError("file name is '.' or '..'")
|
|
169
|
+
for ch in n:
|
|
170
|
+
if unicodedata.category(ch) in ("Cc", "Cs") or ch in _BIDI:
|
|
171
|
+
raise ValidationError("file name contains control characters")
|
|
172
|
+
if n != n.rstrip(". ") or n != n.lstrip(" "):
|
|
173
|
+
raise ValidationError("file name starts with a space or ends with a dot or space")
|
|
174
|
+
if _WIN_RESERVED.fullmatch(n):
|
|
175
|
+
raise ValidationError("file name is a reserved device name")
|
|
176
|
+
return n
|
|
177
|
+
|
|
178
|
+
|
|
179
|
+
def _display_name(name: Any) -> str:
|
|
180
|
+
"""A harmless label for a rejected name (never used as a path)."""
|
|
181
|
+
if not isinstance(name, str):
|
|
182
|
+
return "(invalid name)"
|
|
183
|
+
s = name.replace("\\", "/").rsplit("/", 1)[-1]
|
|
184
|
+
s = "".join("�" if unicodedata.category(c) in ("Cc", "Cs") or c in _BIDI else c for c in s)
|
|
185
|
+
return (s[:120] or "(invalid name)").strip() or "(invalid name)"
|
|
186
|
+
|
|
187
|
+
|
|
188
|
+
def _normalize_accept(value: Any) -> list[str]:
|
|
189
|
+
if isinstance(value, str) or not isinstance(value, Sequence):
|
|
190
|
+
raise ValidationError("accept: expected a list like ['image/*', '.csv']")
|
|
191
|
+
out: list[str] = []
|
|
192
|
+
for i, v in enumerate(cast("Sequence[Any]", value)):
|
|
193
|
+
if not isinstance(v, str):
|
|
194
|
+
raise ValidationError(f"accept[{i}]: expected str")
|
|
195
|
+
e = v.strip().lower()
|
|
196
|
+
if not _ACCEPT_RE.fullmatch(e):
|
|
197
|
+
raise ValidationError(
|
|
198
|
+
f"accept[{i}]: {v!r} is not a MIME type ('image/png'), wildcard ('image/*') "
|
|
199
|
+
"or extension ('.csv')"
|
|
200
|
+
)
|
|
201
|
+
if e not in out:
|
|
202
|
+
out.append(e)
|
|
203
|
+
return out
|
|
204
|
+
|
|
205
|
+
|
|
206
|
+
def _mime_match(mime: str, entry: str) -> bool:
|
|
207
|
+
if entry.endswith("/*"):
|
|
208
|
+
return mime.startswith(entry[:-1])
|
|
209
|
+
return mime == entry
|
|
210
|
+
|
|
211
|
+
|
|
212
|
+
def file_type_allowed(name: str, declared_type: str, accept: Sequence[str]) -> bool:
|
|
213
|
+
"""Whether a file passes the ``accept`` allowlist.
|
|
214
|
+
|
|
215
|
+
The type is derived from the file name's extension (Python's built-in
|
|
216
|
+
table); for MIME entries the extension's type must match and a type the
|
|
217
|
+
page declared, if any, must match too. Extension entries match by
|
|
218
|
+
extension. An empty allowlist accepts any type.
|
|
219
|
+
"""
|
|
220
|
+
if not accept:
|
|
221
|
+
return True
|
|
222
|
+
lower = name.lower()
|
|
223
|
+
ext = "." + lower.rsplit(".", 1)[1] if "." in lower else ""
|
|
224
|
+
guessed = _MIME.guess_type(lower, strict=False)[0] or ""
|
|
225
|
+
declared = declared_type.strip().lower()
|
|
226
|
+
for entry in accept:
|
|
227
|
+
if entry.startswith("."):
|
|
228
|
+
if ext == entry:
|
|
229
|
+
return True
|
|
230
|
+
elif (
|
|
231
|
+
guessed
|
|
232
|
+
and _mime_match(guessed, entry)
|
|
233
|
+
and (not declared or _mime_match(declared, entry))
|
|
234
|
+
):
|
|
235
|
+
return True
|
|
236
|
+
return False
|
|
237
|
+
|
|
238
|
+
|
|
239
|
+
@dataclass(frozen=True)
|
|
240
|
+
class RejectedFile:
|
|
241
|
+
"""A file the page or Python refused: ``name`` is a display label only."""
|
|
242
|
+
|
|
243
|
+
name: str
|
|
244
|
+
size: int | None
|
|
245
|
+
reasons: tuple[str, ...]
|
|
246
|
+
|
|
247
|
+
|
|
248
|
+
@dataclass(eq=False)
|
|
249
|
+
class DroppedFile:
|
|
250
|
+
"""An accepted file: validated safe ``name``, ``size`` in bytes, ``mime``
|
|
251
|
+
derived from the extension and the page's ``declared_type``.
|
|
252
|
+
|
|
253
|
+
The content stays in the page until :meth:`read` pulls it (bounded,
|
|
254
|
+
chunked); there is no local path. The page keeps the last 64 files of a
|
|
255
|
+
dropzone while it is mounted; :meth:`release` frees one earlier.
|
|
256
|
+
"""
|
|
257
|
+
|
|
258
|
+
name: str
|
|
259
|
+
size: int
|
|
260
|
+
mime: str
|
|
261
|
+
declared_type: str
|
|
262
|
+
token: str
|
|
263
|
+
_source: Component = field(repr=False)
|
|
264
|
+
_limit: int = field(repr=False, default=DEFAULT_MAX_SIZE)
|
|
265
|
+
|
|
266
|
+
def _session(self) -> WindowSession:
|
|
267
|
+
w = self._source._window # pyright: ignore[reportPrivateUsage]
|
|
268
|
+
if w is None or not w.live:
|
|
269
|
+
raise RpcError("DISCONNECTED", "the dropzone is not shown in a mounted window")
|
|
270
|
+
return w
|
|
271
|
+
|
|
272
|
+
def read(self) -> Pending[bytes]:
|
|
273
|
+
"""Content (``await`` it, or ``.result(timeout)`` in sync callbacks).
|
|
274
|
+
|
|
275
|
+
Pulled in chunks of at most 512 KiB; fails if the page returns more
|
|
276
|
+
or less than the validated size, or no longer has the file.
|
|
277
|
+
"""
|
|
278
|
+
w = self._session()
|
|
279
|
+
return run_on_window(w, "DroppedFile.read", lambda: self._read(w))
|
|
280
|
+
|
|
281
|
+
async def _read(self, w: WindowSession) -> bytes:
|
|
282
|
+
if self.size > self._limit:
|
|
283
|
+
raise ValidationError(f"{self.name}: larger than the dropzone limit")
|
|
284
|
+
out = bytearray()
|
|
285
|
+
while len(out) < self.size:
|
|
286
|
+
want = min(_CHUNK, self.size - len(out))
|
|
287
|
+
r = await w.command(
|
|
288
|
+
self._source,
|
|
289
|
+
"custom",
|
|
290
|
+
{"name": "read", "data": {"token": self.token, "offset": len(out), "length": want}},
|
|
291
|
+
)
|
|
292
|
+
if not isinstance(r, Mapping) or not isinstance(
|
|
293
|
+
cast("Mapping[str, Any]", r).get("data"), str
|
|
294
|
+
):
|
|
295
|
+
raise RpcError("PROTOCOL_ERROR", f"{self.name}: the page sent no data")
|
|
296
|
+
m = cast("Mapping[str, Any]", r)
|
|
297
|
+
if m.get("size") != self.size:
|
|
298
|
+
raise ValidationError(f"{self.name}: the file changed size in the page")
|
|
299
|
+
raw = cast("str", m["data"])
|
|
300
|
+
if len(raw) > (want + 2) // 3 * 4:
|
|
301
|
+
raise ValidationError(f"{self.name}: the page sent more than requested")
|
|
302
|
+
try:
|
|
303
|
+
chunk = base64.b64decode(raw, validate=True)
|
|
304
|
+
except ValueError:
|
|
305
|
+
raise ValidationError(f"{self.name}: invalid chunk encoding") from None
|
|
306
|
+
if len(chunk) != want:
|
|
307
|
+
raise ValidationError(f"{self.name}: short or oversized chunk from the page")
|
|
308
|
+
out += chunk
|
|
309
|
+
return bytes(out)
|
|
310
|
+
|
|
311
|
+
def text(self, encoding: str = "utf-8") -> Pending[str]:
|
|
312
|
+
"""Content decoded as text (strict decoding)."""
|
|
313
|
+
w = self._session()
|
|
314
|
+
|
|
315
|
+
async def run() -> str:
|
|
316
|
+
return (await self._read(w)).decode(encoding)
|
|
317
|
+
|
|
318
|
+
return run_on_window(w, "DroppedFile.text", run)
|
|
319
|
+
|
|
320
|
+
def release(self) -> None:
|
|
321
|
+
"""Let the page forget the file (later reads fail)."""
|
|
322
|
+
self._source._command("custom", {"name": "release", "data": {"tokens": [self.token]}}) # pyright: ignore[reportPrivateUsage]
|
|
323
|
+
|
|
324
|
+
|
|
325
|
+
def _int(v: Any, path: str, lo: int = 0, hi: int = 2**53 - 1) -> int:
|
|
326
|
+
if isinstance(v, bool) or not isinstance(v, int) or not lo <= v <= hi:
|
|
327
|
+
raise ValidationError(f"{path}: expected an integer {lo}..{hi}")
|
|
328
|
+
return v
|
|
329
|
+
|
|
330
|
+
|
|
331
|
+
class _DropzoneLogic(Component):
|
|
332
|
+
"""Validation and commands shared by Dropzone and DropzoneFullScreen."""
|
|
333
|
+
|
|
334
|
+
def _convert(self, name: str, value: Any, spec: PropSpec | None = None) -> Any:
|
|
335
|
+
if name == "accept":
|
|
336
|
+
value = _normalize_accept(value)
|
|
337
|
+
return super()._convert(name, value, spec)
|
|
338
|
+
|
|
339
|
+
def _limits(self) -> tuple[list[str], int, int]:
|
|
340
|
+
with TREE_LOCK:
|
|
341
|
+
accept = cast("list[str]", self._props.get("accept") or [])
|
|
342
|
+
size = self._props.get("max_size")
|
|
343
|
+
count = self._props.get("max_files")
|
|
344
|
+
multiple = self._props.get("multiple")
|
|
345
|
+
max_size = size if isinstance(size, int) else DEFAULT_MAX_SIZE
|
|
346
|
+
max_files = count if isinstance(count, int) else DEFAULT_MAX_FILES
|
|
347
|
+
if multiple is False:
|
|
348
|
+
max_files = 1
|
|
349
|
+
return accept, max_size, max_files
|
|
350
|
+
|
|
351
|
+
def open_picker(self) -> None:
|
|
352
|
+
"""Open the page's file chooser (as a click on the dropzone does)."""
|
|
353
|
+
self._command("custom", {"name": "open", "data": None})
|
|
354
|
+
|
|
355
|
+
def _on_client_event(self, name: str, payload: Mapping[str, Any]) -> Any:
|
|
356
|
+
if name != "drop":
|
|
357
|
+
return super()._on_client_event(name, payload)
|
|
358
|
+
_keys(payload, {"value"}, f"{self.TYPE}.drop")
|
|
359
|
+
v = payload.get("value")
|
|
360
|
+
if not isinstance(v, Mapping):
|
|
361
|
+
raise ValidationError(f"{self.TYPE}.drop: expected {{files, rejected}}")
|
|
362
|
+
m = cast("Mapping[str, Any]", v)
|
|
363
|
+
_keys(m, {"files", "rejected"}, f"{self.TYPE}.drop")
|
|
364
|
+
raw_files = _records(m.get("files", []), "drop.files", _MAX_REPORTED)
|
|
365
|
+
raw_rej = _records(m.get("rejected", []), "drop.rejected", _MAX_REPORTED)
|
|
366
|
+
accept, max_size, max_files = self._limits()
|
|
367
|
+
files: list[DroppedFile] = []
|
|
368
|
+
rejected: list[RejectedFile] = []
|
|
369
|
+
tokens: set[str] = set()
|
|
370
|
+
for i, f in enumerate(raw_files):
|
|
371
|
+
p = f"drop.files[{i}]"
|
|
372
|
+
_keys(f, {"token", "name", "size", "type"}, p)
|
|
373
|
+
token = f.get("token")
|
|
374
|
+
if not isinstance(token, str) or not _TOKEN_RE.fullmatch(token) or token in tokens:
|
|
375
|
+
raise ValidationError(f"{p}.token: invalid")
|
|
376
|
+
tokens.add(token)
|
|
377
|
+
size = _int(f.get("size"), f"{p}.size")
|
|
378
|
+
declared = cast("str", _str(f.get("type", ""), f"{p}.type", max_len=255))
|
|
379
|
+
reasons: list[str] = []
|
|
380
|
+
try:
|
|
381
|
+
safe = check_file_name(f.get("name"))
|
|
382
|
+
except ValidationError:
|
|
383
|
+
safe = None
|
|
384
|
+
reasons.append("invalid-name")
|
|
385
|
+
if size > max_size:
|
|
386
|
+
reasons.append("file-too-large")
|
|
387
|
+
if safe is not None and not file_type_allowed(safe, declared, accept):
|
|
388
|
+
reasons.append("file-invalid-type")
|
|
389
|
+
if reasons or safe is None:
|
|
390
|
+
rejected.append(RejectedFile(_display_name(f.get("name")), size, tuple(reasons)))
|
|
391
|
+
continue
|
|
392
|
+
mime = _MIME.guess_type(safe.lower(), strict=False)[0] or "application/octet-stream"
|
|
393
|
+
files.append(DroppedFile(safe, size, mime, declared, token, self, max_size))
|
|
394
|
+
if len(files) > max_files:
|
|
395
|
+
# Like the page (react-dropzone 20): the first max_files are kept,
|
|
396
|
+
# the rest are refused as too-many-files.
|
|
397
|
+
rejected = [
|
|
398
|
+
*rejected,
|
|
399
|
+
*(RejectedFile(f.name, f.size, ("too-many-files",)) for f in files[max_files:]),
|
|
400
|
+
]
|
|
401
|
+
files = files[:max_files]
|
|
402
|
+
for i, r in enumerate(raw_rej):
|
|
403
|
+
p = f"drop.rejected[{i}]"
|
|
404
|
+
_keys(r, {"name", "size", "type", "codes"}, p)
|
|
405
|
+
size = r.get("size")
|
|
406
|
+
codes_raw = r.get("codes", [])
|
|
407
|
+
if isinstance(codes_raw, str) or not isinstance(codes_raw, Sequence):
|
|
408
|
+
raise ValidationError(f"{p}.codes: expected a list")
|
|
409
|
+
codes = tuple(
|
|
410
|
+
c if c in _PAGE_CODES else "rejected" for c in cast("Sequence[Any]", codes_raw)[:8]
|
|
411
|
+
)
|
|
412
|
+
rejected.append(
|
|
413
|
+
RejectedFile(
|
|
414
|
+
_display_name(r.get("name")),
|
|
415
|
+
size
|
|
416
|
+
if isinstance(size, int) and not isinstance(size, bool) and size >= 0
|
|
417
|
+
else None,
|
|
418
|
+
codes or ("rejected",),
|
|
419
|
+
)
|
|
420
|
+
)
|
|
421
|
+
summary: dict[str, Any] = {
|
|
422
|
+
"files": [{"name": f.name, "size": f.size, "mime": f.mime} for f in files],
|
|
423
|
+
"rejected": [
|
|
424
|
+
{"name": r.name, "size": r.size, "reasons": list(r.reasons)} for r in rejected
|
|
425
|
+
],
|
|
426
|
+
}
|
|
427
|
+
if not files and tokens:
|
|
428
|
+
self._command("custom", {"name": "release", "data": {"tokens": sorted(tokens)}})
|
|
429
|
+
elif len(files) < len(tokens):
|
|
430
|
+
gone = sorted(tokens - {f.token for f in files})
|
|
431
|
+
self._command("custom", {"name": "release", "data": {"tokens": gone}})
|
|
432
|
+
return DropEvent(
|
|
433
|
+
name=name, sender=self, payload={"value": summary}, files=files, rejected=rejected
|
|
434
|
+
)
|
|
435
|
+
|
|
436
|
+
|
|
437
|
+
class Dropzone(_DropzoneLogic, _Dropzone):
|
|
438
|
+
__doc__ = _Dropzone.__doc__
|
|
439
|
+
|
|
440
|
+
|
|
441
|
+
class DropzoneFullScreen(_DropzoneLogic, _DropzoneFullScreen):
|
|
442
|
+
__doc__ = _DropzoneFullScreen.__doc__
|
|
443
|
+
|
|
444
|
+
|
|
445
|
+
# ======================================================================== Emoji
|
|
446
|
+
@functools.cache
|
|
447
|
+
def _emoji_data() -> tuple[dict[str, tuple[str, ...]], frozenset[str]]:
|
|
448
|
+
raw = json.loads((files("neutralino") / "_data/ui/emoji.json").read_text("utf-8"))
|
|
449
|
+
emojis = {k: tuple(v) for k, v in raw["emojis"].items()}
|
|
450
|
+
return emojis, frozenset(raw["categories"])
|
|
451
|
+
|
|
452
|
+
|
|
453
|
+
def emoji_char(emoji_id: str) -> str:
|
|
454
|
+
"""The character of a bundled emoji id (default skin tone)."""
|
|
455
|
+
emojis, _ = _emoji_data()
|
|
456
|
+
if emoji_id not in emojis:
|
|
457
|
+
raise ValidationError(f"unknown emoji id {emoji_id!r}")
|
|
458
|
+
return emojis[emoji_id][0]
|
|
459
|
+
|
|
460
|
+
|
|
461
|
+
def _emoji_id(v: Any, path: str) -> str:
|
|
462
|
+
emojis, _ = _emoji_data()
|
|
463
|
+
if not isinstance(v, str) or v not in emojis:
|
|
464
|
+
raise ValidationError(f"{path}: {v!r} is not a known emoji id")
|
|
465
|
+
return v
|
|
466
|
+
|
|
467
|
+
|
|
468
|
+
class _EmojiLogic(Component):
|
|
469
|
+
def _convert(self, name: str, value: Any, spec: PropSpec | None = None) -> Any:
|
|
470
|
+
if name == "recent" and isinstance(value, Sequence) and not isinstance(value, str):
|
|
471
|
+
for i, e in enumerate(cast("Sequence[Any]", value)):
|
|
472
|
+
_emoji_id(e, f"{self.TYPE}.recent[{i}]")
|
|
473
|
+
elif name == "categories" and isinstance(value, Sequence) and not isinstance(value, str):
|
|
474
|
+
_, cats = _emoji_data()
|
|
475
|
+
bad = [c for c in cast("Sequence[Any]", value) if c not in cats]
|
|
476
|
+
if bad:
|
|
477
|
+
raise ValidationError(f"{self.TYPE}.categories: unknown {bad}; use {sorted(cats)}")
|
|
478
|
+
return super()._convert(name, value, spec)
|
|
479
|
+
|
|
480
|
+
def _on_client_event(self, name: str, payload: Mapping[str, Any]) -> Any:
|
|
481
|
+
if name != "select":
|
|
482
|
+
return super()._on_client_event(name, payload)
|
|
483
|
+
_keys(payload, {"value"}, f"{self.TYPE}.select")
|
|
484
|
+
v = payload.get("value")
|
|
485
|
+
if not isinstance(v, Mapping):
|
|
486
|
+
raise ValidationError(f"{self.TYPE}.select: expected {{id, emoji, name}}")
|
|
487
|
+
m = cast("Mapping[str, Any]", v)
|
|
488
|
+
_keys(m, {"id", "emoji", "name"}, f"{self.TYPE}.select")
|
|
489
|
+
eid = _emoji_id(m.get("id"), f"{self.TYPE}.select.id")
|
|
490
|
+
ch = m.get("emoji")
|
|
491
|
+
if ch not in _emoji_data()[0][eid]:
|
|
492
|
+
raise ValidationError(f"{self.TYPE}.select: {ch!r} is not a form of {eid!r}")
|
|
493
|
+
nm = cast("str", _str(m.get("name", ""), f"{self.TYPE}.select.name", max_len=200))
|
|
494
|
+
return EmojiEvent(
|
|
495
|
+
name=name,
|
|
496
|
+
sender=self,
|
|
497
|
+
payload={"value": {"id": eid, "emoji": ch, "name": nm}},
|
|
498
|
+
id=eid,
|
|
499
|
+
emoji=cast("str", ch),
|
|
500
|
+
emoji_name=nm,
|
|
501
|
+
)
|
|
502
|
+
|
|
503
|
+
|
|
504
|
+
class EmojiPicker(_EmojiLogic, _EmojiPicker):
|
|
505
|
+
__doc__ = _EmojiPicker.__doc__
|
|
506
|
+
|
|
507
|
+
|
|
508
|
+
class EmojiPickerPopover(_EmojiLogic, _EmojiPickerPopover):
|
|
509
|
+
__doc__ = _EmojiPickerPopover.__doc__
|
|
510
|
+
|
|
511
|
+
|
|
512
|
+
class EmojiPickerInput(_EmojiPickerInput):
|
|
513
|
+
__doc__ = _EmojiPickerInput.__doc__
|
|
514
|
+
|
|
515
|
+
def _convert(self, name: str, value: Any, spec: PropSpec | None = None) -> Any:
|
|
516
|
+
if name == "value" and value is not None:
|
|
517
|
+
_emoji_id(value, "EmojiPickerInput.value")
|
|
518
|
+
return super()._convert(name, value, spec)
|
|
519
|
+
|
|
520
|
+
def _check_client_value(self, value: Any) -> None:
|
|
521
|
+
if value is not None:
|
|
522
|
+
_emoji_id(value, "EmojiPickerInput.change")
|
|
523
|
+
super()._check_client_value(value)
|
|
524
|
+
|
|
525
|
+
@property
|
|
526
|
+
def emoji(self) -> str | None:
|
|
527
|
+
"""Character of the current value (None when empty)."""
|
|
528
|
+
v = self.value
|
|
529
|
+
return emoji_char(v) if isinstance(v, str) else None
|
|
530
|
+
|
|
531
|
+
|
|
532
|
+
# ===================================================================== Lightbox
|
|
533
|
+
_SAFE_SRC = re.compile(
|
|
534
|
+
r"^(?:(?i:https?)://[^\s<>\"'`\\]{1,2000}|/?(?!/)[A-Za-z0-9_\-./~%+]{1,1000})$"
|
|
535
|
+
)
|
|
536
|
+
|
|
537
|
+
|
|
538
|
+
def safe_src(v: Any, path: str) -> str:
|
|
539
|
+
"""App-relative asset path ('custom/files/a.png') or an http(s) URL."""
|
|
540
|
+
s = cast("str", _str(v, path, max_len=2000))
|
|
541
|
+
if not _SAFE_SRC.fullmatch(s) or (
|
|
542
|
+
"://" not in s and any(seg in ("..", ".") for seg in s.split("/"))
|
|
543
|
+
):
|
|
544
|
+
raise ValidationError(f"{path}: only app asset paths or http(s) URLs are allowed")
|
|
545
|
+
return s
|
|
546
|
+
|
|
547
|
+
|
|
548
|
+
_SLIDE_KEYS = {"type", "src", "alt", "caption", "thumb_src", "poster", "label"}
|
|
549
|
+
|
|
550
|
+
|
|
551
|
+
class Lightbox(_Lightbox):
|
|
552
|
+
__doc__ = _Lightbox.__doc__
|
|
553
|
+
|
|
554
|
+
def _convert(self, name: str, value: Any, spec: PropSpec | None = None) -> Any:
|
|
555
|
+
if name == "slides":
|
|
556
|
+
out: list[dict[str, Any]] = []
|
|
557
|
+
for i, s in enumerate(_records(value, "Lightbox.slides", 1000)):
|
|
558
|
+
p = f"Lightbox.slides[{i}]"
|
|
559
|
+
_keys(s, _SLIDE_KEYS, p)
|
|
560
|
+
kind = s.get("type", "image")
|
|
561
|
+
if kind not in ("image", "video"):
|
|
562
|
+
raise ValidationError(f"{p}.type: 'image' or 'video'")
|
|
563
|
+
d: dict[str, Any] = {"type": kind, "src": safe_src(s.get("src"), f"{p}.src")}
|
|
564
|
+
for k in ("thumb_src", "poster"):
|
|
565
|
+
if s.get(k) is not None:
|
|
566
|
+
d[k] = safe_src(s[k], f"{p}.{k}")
|
|
567
|
+
for k in ("alt", "caption", "label"):
|
|
568
|
+
if s.get(k) is not None:
|
|
569
|
+
d[k] = _str(s[k], f"{p}.{k}", max_len=2000)
|
|
570
|
+
out.append(d)
|
|
571
|
+
value = out
|
|
572
|
+
return super()._convert(name, value, spec)
|
|
573
|
+
|
|
574
|
+
@property
|
|
575
|
+
def count(self) -> int:
|
|
576
|
+
s = self.slides
|
|
577
|
+
return len(s) if isinstance(s, Sequence) else 0
|
|
578
|
+
|
|
579
|
+
def _on_client_event(self, name: str, payload: Mapping[str, Any]) -> Any:
|
|
580
|
+
if name == "index_change":
|
|
581
|
+
v = payload.get("value")
|
|
582
|
+
if isinstance(v, bool) or not isinstance(v, int) or not 0 <= v < max(self.count, 1):
|
|
583
|
+
raise ValidationError(f"Lightbox.index_change: {v!r} is not a slide index")
|
|
584
|
+
return super()._on_client_event(name, payload)
|
|
585
|
+
|
|
586
|
+
def show(self, index: int = 0) -> None:
|
|
587
|
+
"""Open at ``index``."""
|
|
588
|
+
i: Any = index
|
|
589
|
+
if isinstance(i, bool) or not isinstance(i, int) or not 0 <= i < max(self.count, 1):
|
|
590
|
+
raise ValidationError(f"Lightbox.show: {index!r} is not a slide index")
|
|
591
|
+
self.update(index=index, opened=True)
|
|
592
|
+
|
|
593
|
+
def next(self) -> None:
|
|
594
|
+
n = self.count
|
|
595
|
+
if n:
|
|
596
|
+
cur = self.index if isinstance(self.index, int) else 0
|
|
597
|
+
self.index = (cur + 1) % n if self.loop is True else min(cur + 1, n - 1)
|
|
598
|
+
|
|
599
|
+
def previous(self) -> None:
|
|
600
|
+
n = self.count
|
|
601
|
+
if n:
|
|
602
|
+
cur = self.index if isinstance(self.index, int) else 0
|
|
603
|
+
self.index = (cur - 1) % n if self.loop is True else max(cur - 1, 0)
|
|
604
|
+
|
|
605
|
+
|
|
606
|
+
# ==================================================================== Spotlight
|
|
607
|
+
_ACTION_ID = re.compile(r"^[A-Za-z0-9_.:\-/#@+]{1,200}$")
|
|
608
|
+
_ACTION_KEYS = {"id", "label", "description", "group", "keywords", "icon", "disabled", "hotkey"}
|
|
609
|
+
|
|
610
|
+
|
|
611
|
+
class Spotlight(_Spotlight):
|
|
612
|
+
__doc__ = _Spotlight.__doc__
|
|
613
|
+
|
|
614
|
+
def _convert(self, name: str, value: Any, spec: PropSpec | None = None) -> Any:
|
|
615
|
+
if name == "shortcut":
|
|
616
|
+
value = normalize_bindings(value)
|
|
617
|
+
elif name == "actions":
|
|
618
|
+
out: list[dict[str, Any]] = []
|
|
619
|
+
seen: set[str] = set()
|
|
620
|
+
for i, a in enumerate(_records(value, "Spotlight.actions", 1000)):
|
|
621
|
+
p = f"Spotlight.actions[{i}]"
|
|
622
|
+
_keys(a, _ACTION_KEYS, p)
|
|
623
|
+
aid = a.get("id")
|
|
624
|
+
if not isinstance(aid, str) or not _ACTION_ID.fullmatch(aid):
|
|
625
|
+
raise ValidationError(f"{p}.id: 1-200 characters of [A-Za-z0-9_.:-/#@+]")
|
|
626
|
+
if aid in seen:
|
|
627
|
+
raise ValidationError(f"{p}.id: duplicate {aid!r}")
|
|
628
|
+
seen.add(aid)
|
|
629
|
+
d: dict[str, Any] = {
|
|
630
|
+
"id": aid,
|
|
631
|
+
"label": _str(a.get("label"), f"{p}.label", max_len=500),
|
|
632
|
+
}
|
|
633
|
+
for k, n in (("description", 1000), ("group", 200), ("icon", 64), ("hotkey", 40)):
|
|
634
|
+
if a.get(k) is not None:
|
|
635
|
+
d[k] = _str(a[k], f"{p}.{k}", max_len=n)
|
|
636
|
+
if a.get("keywords") is not None:
|
|
637
|
+
kw = a["keywords"]
|
|
638
|
+
if isinstance(kw, str) or not isinstance(kw, Sequence):
|
|
639
|
+
raise ValidationError(f"{p}.keywords: expected a list of str")
|
|
640
|
+
kws = list(cast("Sequence[Any]", kw))
|
|
641
|
+
if len(kws) > 50:
|
|
642
|
+
raise ValidationError(f"{p}.keywords: more than 50")
|
|
643
|
+
d["keywords"] = [_str(k, f"{p}.keywords", max_len=100) for k in kws]
|
|
644
|
+
if a.get("disabled") is not None:
|
|
645
|
+
if not isinstance(a["disabled"], bool):
|
|
646
|
+
raise ValidationError(f"{p}.disabled: expected bool")
|
|
647
|
+
d["disabled"] = a["disabled"]
|
|
648
|
+
out.append(d)
|
|
649
|
+
value = out
|
|
650
|
+
return super()._convert(name, value, spec)
|
|
651
|
+
|
|
652
|
+
def toggle(self) -> None:
|
|
653
|
+
self.opened = self.opened is not True
|
|
654
|
+
|
|
655
|
+
def action(self, action_id: str) -> dict[str, Any] | None:
|
|
656
|
+
"""The current action with this id (None if absent)."""
|
|
657
|
+
acts = self.actions
|
|
658
|
+
if isinstance(acts, Sequence):
|
|
659
|
+
for a in cast("Sequence[Mapping[str, Any]]", acts):
|
|
660
|
+
if a.get("id") == action_id:
|
|
661
|
+
return dict(a)
|
|
662
|
+
return None
|
|
663
|
+
|
|
664
|
+
def _on_client_event(self, name: str, payload: Mapping[str, Any]) -> Any:
|
|
665
|
+
if name == "action":
|
|
666
|
+
ev = cast("Event", super()._on_client_event(name, payload)) # typed string payload
|
|
667
|
+
aid = cast("str", ev.payload["value"])
|
|
668
|
+
item = self.action(aid)
|
|
669
|
+
if item is None or item.get("disabled") is True:
|
|
670
|
+
raise ValidationError(f"Spotlight.action: {aid!r} is not an enabled action")
|
|
671
|
+
return SpotlightActionEvent(
|
|
672
|
+
name=name, sender=self, payload=ev.payload, action=aid, item=item
|
|
673
|
+
)
|
|
674
|
+
return super()._on_client_event(name, payload)
|
|
675
|
+
|
|
676
|
+
|
|
677
|
+
# ================================================================= DragDropList
|
|
678
|
+
_ITEM_KEY = re.compile(r"^[A-Za-z0-9_.:\-/#@+]{1,200}$")
|
|
679
|
+
_ITEM_KEYS = {"key", "label", "description", "icon", "disabled", "cells"}
|
|
680
|
+
|
|
681
|
+
|
|
682
|
+
def _single_move(old: list[str], new: list[str]) -> tuple[str, int, int] | None:
|
|
683
|
+
"""(key, from, to) when ``new`` is ``old`` with one item moved (linear time)."""
|
|
684
|
+
if len(old) != len(new) or set(old) != set(new) or old == new:
|
|
685
|
+
return None
|
|
686
|
+
a = next(i for i in range(len(old)) if old[i] != new[i])
|
|
687
|
+
b = next(i for i in range(len(old) - 1, -1, -1) if old[i] != new[i])
|
|
688
|
+
if new[b] == old[a] and new[a:b] == old[a + 1 : b + 1]:
|
|
689
|
+
return old[a], a, b # moved down
|
|
690
|
+
if new[a] == old[b] and new[a + 1 : b + 1] == old[a:b]:
|
|
691
|
+
return old[b], b, a # moved up
|
|
692
|
+
return None
|
|
693
|
+
|
|
694
|
+
|
|
695
|
+
class DragDropList(_DragDropList):
|
|
696
|
+
__doc__ = _DragDropList.__doc__
|
|
697
|
+
|
|
698
|
+
def _convert(self, name: str, value: Any, spec: PropSpec | None = None) -> Any:
|
|
699
|
+
if name == "items":
|
|
700
|
+
out: list[dict[str, Any]] = []
|
|
701
|
+
seen: set[str] = set()
|
|
702
|
+
for i, it in enumerate(_records(value, "DragDropList.items", 1000)):
|
|
703
|
+
p = f"DragDropList.items[{i}]"
|
|
704
|
+
_keys(it, _ITEM_KEYS, p)
|
|
705
|
+
key = it.get("key")
|
|
706
|
+
if not isinstance(key, str) or not _ITEM_KEY.fullmatch(key):
|
|
707
|
+
raise ValidationError(f"{p}.key: 1-200 characters of [A-Za-z0-9_.:-/#@+]")
|
|
708
|
+
if key in seen:
|
|
709
|
+
raise ValidationError(f"{p}.key: duplicate {key!r}")
|
|
710
|
+
seen.add(key)
|
|
711
|
+
d: dict[str, Any] = {
|
|
712
|
+
"key": key,
|
|
713
|
+
"label": _str(it.get("label"), f"{p}.label", max_len=500),
|
|
714
|
+
}
|
|
715
|
+
for k, n in (("description", 2000), ("icon", 64)):
|
|
716
|
+
if it.get(k) is not None:
|
|
717
|
+
d[k] = _str(it[k], f"{p}.{k}", max_len=n)
|
|
718
|
+
if it.get("disabled") is not None:
|
|
719
|
+
if not isinstance(it["disabled"], bool):
|
|
720
|
+
raise ValidationError(f"{p}.disabled: expected bool")
|
|
721
|
+
d["disabled"] = it["disabled"]
|
|
722
|
+
if it.get("cells") is not None:
|
|
723
|
+
cells = it["cells"]
|
|
724
|
+
if isinstance(cells, str) or not isinstance(cells, Sequence):
|
|
725
|
+
raise ValidationError(f"{p}.cells: expected a list of str")
|
|
726
|
+
cl = list(cast("Sequence[Any]", cells))
|
|
727
|
+
if len(cl) > 20:
|
|
728
|
+
raise ValidationError(f"{p}.cells: more than 20")
|
|
729
|
+
d["cells"] = [_str(c, f"{p}.cells", max_len=1000) for c in cl]
|
|
730
|
+
out.append(d)
|
|
731
|
+
value = out
|
|
732
|
+
return super()._convert(name, value, spec)
|
|
733
|
+
|
|
734
|
+
def _items(self) -> list[dict[str, Any]]:
|
|
735
|
+
with TREE_LOCK:
|
|
736
|
+
v = self._props.get("items")
|
|
737
|
+
return [dict(x) for x in cast("list[dict[str, Any]]", v or [])]
|
|
738
|
+
|
|
739
|
+
@property
|
|
740
|
+
def keys(self) -> list[str]:
|
|
741
|
+
"""Item keys in their current order."""
|
|
742
|
+
return [cast("str", x["key"]) for x in self._items()]
|
|
743
|
+
|
|
744
|
+
def move(self, key: str, index: int) -> None:
|
|
745
|
+
"""Move the item ``key`` to ``index`` (the page follows)."""
|
|
746
|
+
items = self._items()
|
|
747
|
+
pos = next((i for i, x in enumerate(items) if x["key"] == key), None)
|
|
748
|
+
if pos is None:
|
|
749
|
+
raise ValidationError(f"DragDropList.move: no item {key!r}")
|
|
750
|
+
ix: Any = index
|
|
751
|
+
if isinstance(ix, bool) or not isinstance(ix, int) or not 0 <= ix < len(items):
|
|
752
|
+
raise ValidationError(f"DragDropList.move: index {index!r} out of range")
|
|
753
|
+
it = items.pop(pos)
|
|
754
|
+
items.insert(index, it)
|
|
755
|
+
self.items = items
|
|
756
|
+
|
|
757
|
+
def _resend(self) -> None:
|
|
758
|
+
with TREE_LOCK:
|
|
759
|
+
w = self._window
|
|
760
|
+
if w is not None and "items" in self._props:
|
|
761
|
+
w.queue_set(self, {"items": self._props["items"]})
|
|
762
|
+
|
|
763
|
+
def _on_client_event(self, name: str, payload: Mapping[str, Any]) -> Any:
|
|
764
|
+
if name != "reorder":
|
|
765
|
+
return super()._on_client_event(name, payload)
|
|
766
|
+
ev = cast("Event", super()._on_client_event(name, payload)) # typed string_list
|
|
767
|
+
new = list(cast("list[str]", ev.payload["value"]))
|
|
768
|
+
items = self._items()
|
|
769
|
+
old = [cast("str", x["key"]) for x in items]
|
|
770
|
+
mv = _single_move(old, new)
|
|
771
|
+
if (
|
|
772
|
+
self.disabled is True
|
|
773
|
+
or mv is None
|
|
774
|
+
or any(x.get("disabled") is True and x["key"] == mv[0] for x in items)
|
|
775
|
+
):
|
|
776
|
+
self._resend() # put the page back to Python's order
|
|
777
|
+
raise ValidationError("DragDropList.reorder: not a one-item move of the current keys")
|
|
778
|
+
key, i, j = mv
|
|
779
|
+
by = {x["key"]: x for x in items}
|
|
780
|
+
self._commit_from_client("items", [by[k] for k in new])
|
|
781
|
+
return ReorderEvent(
|
|
782
|
+
name=name,
|
|
783
|
+
sender=self,
|
|
784
|
+
payload={"value": new},
|
|
785
|
+
order=new,
|
|
786
|
+
previous=old,
|
|
787
|
+
key=key,
|
|
788
|
+
from_index=i,
|
|
789
|
+
to_index=j,
|
|
790
|
+
)
|