@zyro-sec/tui 0.0.0-stage → 1.0.2
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.
- package/AGENTS.md +6 -0
- package/bunfig.toml +4 -0
- package/package.json +79 -4
- package/src/app.tsx +1632 -0
- package/src/assets/backgrounds/anime.png +0 -0
- package/src/assets/backgrounds/circuit.jpg +0 -0
- package/src/assets/backgrounds/cyber-grid.jpg +0 -0
- package/src/assets/backgrounds/datacenter.jpg +0 -0
- package/src/assets/backgrounds/hacker-desk.jpg +0 -0
- package/src/assets/backgrounds/matrix-code.jpg +0 -0
- package/src/attention-sounds.bun.ts +8 -0
- package/src/attention-sounds.node.ts +16 -0
- package/src/attention.ts +189 -0
- package/src/audio.d.ts +9 -0
- package/src/audio.ts +49 -0
- package/src/clipboard.ts +68 -0
- package/src/component/background-image.tsx +26 -0
- package/src/component/command-palette.tsx +74 -0
- package/src/component/devtools-bar.tsx +611 -0
- package/src/component/dialog-agent.tsx +33 -0
- package/src/component/dialog-background.tsx +102 -0
- package/src/component/dialog-config.tsx +494 -0
- package/src/component/dialog-debug.tsx +90 -0
- package/src/component/dialog-error-details.tsx +130 -0
- package/src/component/dialog-experiments.tsx +101 -0
- package/src/component/dialog-go-upsell.tsx +448 -0
- package/src/component/dialog-highlights.tsx +88 -0
- package/src/component/dialog-image-preview.tsx +85 -0
- package/src/component/dialog-install-mcp.tsx +67 -0
- package/src/component/dialog-integration.tsx +1332 -0
- package/src/component/dialog-mcp.tsx +184 -0
- package/src/component/dialog-model-free.tsx +79 -0
- package/src/component/dialog-model.tsx +238 -0
- package/src/component/dialog-open.tsx +509 -0
- package/src/component/dialog-pair.tsx +123 -0
- package/src/component/dialog-session-list.tsx +328 -0
- package/src/component/dialog-session-rename.tsx +37 -0
- package/src/component/dialog-shell-output.tsx +194 -0
- package/src/component/dialog-skill.tsx +93 -0
- package/src/component/dialog-speed.tsx +48 -0
- package/src/component/dialog-stash.tsx +90 -0
- package/src/component/dialog-status.tsx +50 -0
- package/src/component/dialog-theme-list.tsx +56 -0
- package/src/component/dialog-update.tsx +144 -0
- package/src/component/dialog-variant.tsx +43 -0
- package/src/component/dialog-workspace-file-changes.tsx +187 -0
- package/src/component/dialog-workspaces.tsx +413 -0
- package/src/component/dialog-worktree-name.tsx +40 -0
- package/src/component/error-component.tsx +258 -0
- package/src/component/fade-in-text.tsx +113 -0
- package/src/component/go-upsell-art.ts +338 -0
- package/src/component/logo.tsx +79 -0
- package/src/component/masked-text.ts +59 -0
- package/src/component/media-source.ts +43 -0
- package/src/component/migration-overlay.tsx +73 -0
- package/src/component/model-options.tsx +121 -0
- package/src/component/one-cell-spinner.tsx +75 -0
- package/src/component/panel-host.tsx +64 -0
- package/src/component/patch-diff.tsx +211 -0
- package/src/component/plugin-route-missing.tsx +21 -0
- package/src/component/prompt/autocomplete.tsx +1005 -0
- package/src/component/prompt/draft-stash.ts +47 -0
- package/src/component/prompt/index.tsx +2080 -0
- package/src/component/prompt/local-attachment.ts +188 -0
- package/src/component/prompt/metadata.tsx +193 -0
- package/src/component/prompt/move.tsx +181 -0
- package/src/component/reconnecting.tsx +40 -0
- package/src/component/retry-provider.tsx +202 -0
- package/src/component/session-frame.tsx +408 -0
- package/src/component/session-tabs-rail.tsx +94 -0
- package/src/component/session-tabs.tsx +1789 -0
- package/src/component/shimmer-text.tsx +64 -0
- package/src/component/spinner-frames.ts +1 -0
- package/src/component/spinner-renderable.ts +126 -0
- package/src/component/spinner.tsx +50 -0
- package/src/component/startup-loading.tsx +63 -0
- package/src/component/tab-pulse.tsx +819 -0
- package/src/component/terminal-pane.tsx +377 -0
- package/src/component/theme-error-toast.tsx +20 -0
- package/src/component/title-shimmer.tsx +272 -0
- package/src/component/todo-item.tsx +27 -0
- package/src/component/usage.tsx +329 -0
- package/src/component/use-connected.tsx +14 -0
- package/src/config/index.tsx +438 -0
- package/src/config/keybind.ts +367 -0
- package/src/config/new-session-location.ts +16 -0
- package/src/config/v1/index.tsx +149 -0
- package/src/config/v1/keybind.ts +463 -0
- package/src/context/args.tsx +31 -0
- package/src/context/attention.tsx +23 -0
- package/src/context/client-mcp.tsx +119 -0
- package/src/context/client.tsx +76 -0
- package/src/context/clipboard.tsx +19 -0
- package/src/context/data.tsx +69 -0
- package/src/context/editor.ts +408 -0
- package/src/context/epilogue.tsx +14 -0
- package/src/context/event.ts +32 -0
- package/src/context/exit.tsx +8 -0
- package/src/context/helper.tsx +26 -0
- package/src/context/interactivity.tsx +20 -0
- package/src/context/keymap.tsx +515 -0
- package/src/context/local.tsx +723 -0
- package/src/context/location.tsx +80 -0
- package/src/context/log.tsx +24 -0
- package/src/context/panel.tsx +59 -0
- package/src/context/path-format.tsx +12 -0
- package/src/context/permission.tsx +18 -0
- package/src/context/program-status.ts +94 -0
- package/src/context/prompt.tsx +18 -0
- package/src/context/route.tsx +73 -0
- package/src/context/runtime.tsx +98 -0
- package/src/context/session-tabs-model.ts +263 -0
- package/src/context/session-tabs.tsx +508 -0
- package/src/context/session-terminals.tsx +136 -0
- package/src/context/storage.tsx +150 -0
- package/src/context/theme.tsx +447 -0
- package/src/context/thinking.ts +20 -0
- package/src/context/update-notification.tsx +158 -0
- package/src/devtools/index.ts +41 -0
- package/src/editor-zed-sqlite.bun.ts +1 -0
- package/src/editor-zed-sqlite.node.ts +21 -0
- package/src/editor-zed.ts +277 -0
- package/src/editor.ts +86 -0
- package/src/feature-plugins/home/footer.tsx +116 -0
- package/src/feature-plugins/prompt/btw.tsx +190 -0
- package/src/feature-plugins/prompt/footer.tsx +163 -0
- package/src/feature-plugins/prompt/goal.tsx +211 -0
- package/src/feature-plugins/sidebar/context.tsx +52 -0
- package/src/feature-plugins/sidebar/footer.tsx +126 -0
- package/src/feature-plugins/sidebar/limit.tsx +47 -0
- package/src/feature-plugins/sidebar/mcp.tsx +103 -0
- package/src/feature-plugins/sidebar/todo.tsx +58 -0
- package/src/feature-plugins/system/diff-viewer-file-menu.tsx +87 -0
- package/src/feature-plugins/system/diff-viewer-file-tree-utils.ts +174 -0
- package/src/feature-plugins/system/diff-viewer-file-tree.tsx +274 -0
- package/src/feature-plugins/system/diff-viewer-image.tsx +96 -0
- package/src/feature-plugins/system/diff-viewer.tsx +1380 -0
- package/src/feature-plugins/system/notifications.ts +102 -0
- package/src/feature-plugins/system/plugins.tsx +356 -0
- package/src/feature-plugins/system/stats-data.ts +18 -0
- package/src/feature-plugins/system/stats.tsx +217 -0
- package/src/feature-plugins/system/storybook/footer.tsx +51 -0
- package/src/feature-plugins/system/storybook/highlights.tsx +71 -0
- package/src/feature-plugins/system/storybook/index.tsx +153 -0
- package/src/feature-plugins/system/storybook/link-clicks.tsx +125 -0
- package/src/feature-plugins/system/storybook/merman-layouts.tsx +200 -0
- package/src/feature-plugins/system/storybook/one-cell-spinner.fixtures.ts +144 -0
- package/src/feature-plugins/system/storybook/one-cell-spinner.tsx +293 -0
- package/src/feature-plugins/system/storybook/session-location-missing.tsx +80 -0
- package/src/feature-plugins/system/storybook/session-tabs.tsx +571 -0
- package/src/feature-plugins/system/storybook/subcell-spinner.fixtures.ts +115 -0
- package/src/feature-plugins/system/storybook/todo.tsx +166 -0
- package/src/index.tsx +2 -0
- package/src/logo.ts +21 -0
- package/src/mini/catalog.shared.ts +116 -0
- package/src/mini/demo.ts +1086 -0
- package/src/mini/entry.body.ts +244 -0
- package/src/mini/footer.command.tsx +1205 -0
- package/src/mini/footer.form.tsx +647 -0
- package/src/mini/footer.menu.tsx +313 -0
- package/src/mini/footer.permission.tsx +562 -0
- package/src/mini/footer.prompt.tsx +1533 -0
- package/src/mini/footer.subagent.tsx +268 -0
- package/src/mini/footer.ts +1193 -0
- package/src/mini/footer.view.tsx +1022 -0
- package/src/mini/footer.width.ts +118 -0
- package/src/mini/form.shared.ts +241 -0
- package/src/mini/index.ts +7 -0
- package/src/mini/mono.ts +277 -0
- package/src/mini/permission.shared.ts +199 -0
- package/src/mini/prompt.editor.ts +74 -0
- package/src/mini/prompt.shared.ts +192 -0
- package/src/mini/runtime.boot.ts +98 -0
- package/src/mini/runtime.lifecycle.ts +393 -0
- package/src/mini/runtime.queue.ts +320 -0
- package/src/mini/runtime.ts +1117 -0
- package/src/mini/scrollback.shared.ts +82 -0
- package/src/mini/scrollback.surface.ts +548 -0
- package/src/mini/scrollback.writer.tsx +380 -0
- package/src/mini/session-data.ts +13 -0
- package/src/mini/session.shared.ts +113 -0
- package/src/mini/splash.ts +307 -0
- package/src/mini/stream-v2.fragment.ts +83 -0
- package/src/mini/stream-v2.image.ts +38 -0
- package/src/mini/stream-v2.subagent.ts +1130 -0
- package/src/mini/stream-v2.transport.ts +1916 -0
- package/src/mini/stream.ts +152 -0
- package/src/mini/theme.ts +328 -0
- package/src/mini/tool.public.ts +3 -0
- package/src/mini/tool.ts +1394 -0
- package/src/mini/turn-summary.ts +21 -0
- package/src/mini/types.ts +482 -0
- package/src/mini/variant.shared.ts +58 -0
- package/src/mini/verbosity.ts +84 -0
- package/src/model-preference.ts +206 -0
- package/src/parsers-config.ts +386 -0
- package/src/plugin/api.tsx +486 -0
- package/src/plugin/builtins.ts +35 -0
- package/src/plugin/context.tsx +757 -0
- package/src/plugin/discovery.ts +67 -0
- package/src/plugin/markdown.ts +18 -0
- package/src/plugin/render.tsx +116 -0
- package/src/plugin/runtime-plugin-support.bun.ts +11 -0
- package/src/plugin/runtime-plugin-support.node.ts +1 -0
- package/src/plugin/source.ts +1 -0
- package/src/plugin/structure.ts +159 -0
- package/src/plugin/watch.ts +113 -0
- package/src/prompt/attachment.ts +97 -0
- package/src/prompt/codec.ts +61 -0
- package/src/prompt/content.ts +22 -0
- package/src/prompt/directory-completion.ts +97 -0
- package/src/prompt/directory-recents.ts +36 -0
- package/src/prompt/display.ts +41 -0
- package/src/prompt/frecency.tsx +80 -0
- package/src/prompt/history.tsx +175 -0
- package/src/prompt/mention.ts +173 -0
- package/src/prompt/parse.ts +25 -0
- package/src/prompt/part.ts +35 -0
- package/src/prompt/restore.ts +39 -0
- package/src/prompt/stash.tsx +93 -0
- package/src/prompt/traits.ts +29 -0
- package/src/routes/home.tsx +180 -0
- package/src/routes/session/activity-summary.ts +101 -0
- package/src/routes/session/anchor-view.tsx +53 -0
- package/src/routes/session/anchors.ts +85 -0
- package/src/routes/session/composer/context.ts +24 -0
- package/src/routes/session/composer/index.tsx +143 -0
- package/src/routes/session/composer/scripts-tab.tsx +166 -0
- package/src/routes/session/composer/shell-tab.tsx +149 -0
- package/src/routes/session/composer/subagents-tab.tsx +264 -0
- package/src/routes/session/composer/tabs.ts +91 -0
- package/src/routes/session/composer/terminals-tab.tsx +114 -0
- package/src/routes/session/dialog-execute.tsx +276 -0
- package/src/routes/session/dialog-fork.tsx +87 -0
- package/src/routes/session/dialog-message.tsx +89 -0
- package/src/routes/session/dialog-timeline.tsx +43 -0
- package/src/routes/session/form.tsx +1177 -0
- package/src/routes/session/group-view.tsx +407 -0
- package/src/routes/session/grouping/session.ts +184 -0
- package/src/routes/session/grouping/tree.ts +111 -0
- package/src/routes/session/history.ts +59 -0
- package/src/routes/session/index.tsx +3922 -0
- package/src/routes/session/location-missing.tsx +81 -0
- package/src/routes/session/message-navigation.ts +48 -0
- package/src/routes/session/message-parts.tsx +322 -0
- package/src/routes/session/mount-budget.ts +38 -0
- package/src/routes/session/permission.tsx +622 -0
- package/src/routes/session/render-context.tsx +44 -0
- package/src/routes/session/rows.ts +493 -0
- package/src/routes/session/sidebar.tsx +80 -0
- package/src/routes/session/thinking-syntax.ts +8 -0
- package/src/runtime.tsx +1 -0
- package/src/simulation/semantics.ts +12 -0
- package/src/theme/assets/aura.json +69 -0
- package/src/theme/assets/ayu.json +80 -0
- package/src/theme/assets/carbonfox.json +248 -0
- package/src/theme/assets/catppuccin-frappe.json +230 -0
- package/src/theme/assets/catppuccin-macchiato.json +230 -0
- package/src/theme/assets/catppuccin.json +112 -0
- package/src/theme/assets/cobalt2.json +225 -0
- package/src/theme/assets/cursor.json +249 -0
- package/src/theme/assets/dracula.json +219 -0
- package/src/theme/assets/everforest.json +241 -0
- package/src/theme/assets/flexoki.json +237 -0
- package/src/theme/assets/github.json +233 -0
- package/src/theme/assets/gruvbox.json +242 -0
- package/src/theme/assets/kanagawa.json +77 -0
- package/src/theme/assets/lucent-orng.json +234 -0
- package/src/theme/assets/material.json +235 -0
- package/src/theme/assets/matrix.json +77 -0
- package/src/theme/assets/mercury.json +252 -0
- package/src/theme/assets/monokai.json +221 -0
- package/src/theme/assets/nightowl.json +221 -0
- package/src/theme/assets/nord.json +223 -0
- package/src/theme/assets/one-dark.json +84 -0
- package/src/theme/assets/opencode.json +245 -0
- package/src/theme/assets/orng.json +249 -0
- package/src/theme/assets/osaka-jade.json +93 -0
- package/src/theme/assets/palenight.json +222 -0
- package/src/theme/assets/rosepine.json +234 -0
- package/src/theme/assets/solarized.json +223 -0
- package/src/theme/assets/synthwave84.json +226 -0
- package/src/theme/assets/tokyonight.json +243 -0
- package/src/theme/assets/v2/opencode-classic.json +387 -0
- package/src/theme/assets/v2/opencode.json +395 -0
- package/src/theme/assets/vercel.json +245 -0
- package/src/theme/assets/vesper.json +218 -0
- package/src/theme/assets/zenburn.json +223 -0
- package/src/theme/color.ts +48 -0
- package/src/theme/component.ts +51 -0
- package/src/theme/discovery.ts +21 -0
- package/src/theme/index.ts +109 -0
- package/src/theme/resolve.ts +53 -0
- package/src/theme/system.ts +144 -0
- package/src/theme/v1.ts +70 -0
- package/src/ui/animation.ts +235 -0
- package/src/ui/border.ts +21 -0
- package/src/ui/dialog-alert.tsx +51 -0
- package/src/ui/dialog-confirm.tsx +62 -0
- package/src/ui/dialog-export-options.tsx +316 -0
- package/src/ui/dialog-export-result.tsx +84 -0
- package/src/ui/dialog-help.tsx +40 -0
- package/src/ui/dialog-prompt.tsx +180 -0
- package/src/ui/dialog-select.tsx +1006 -0
- package/src/ui/dialog.tsx +560 -0
- package/src/ui/file-path.tsx +112 -0
- package/src/ui/layout.ts +26 -0
- package/src/ui/link.tsx +51 -0
- package/src/ui/one-cell-motion.ts +111 -0
- package/src/ui/pane-resize-handle.tsx +33 -0
- package/src/ui/pane-resize.ts +76 -0
- package/src/ui/select-controller.ts +45 -0
- package/src/ui/session-link.ts +92 -0
- package/src/ui/spinner.ts +368 -0
- package/src/ui/subcell.ts +37 -0
- package/src/ui/toast.tsx +222 -0
- package/src/ui/working-directory-actions.tsx +66 -0
- package/src/util/collapse-tool-output.ts +95 -0
- package/src/util/config-directories.ts +53 -0
- package/src/util/connected-provider.ts +15 -0
- package/src/util/delayed-presence.ts +34 -0
- package/src/util/diff.ts +84 -0
- package/src/util/error-details.ts +21 -0
- package/src/util/error.ts +141 -0
- package/src/util/filetype.ts +135 -0
- package/src/util/form.ts +146 -0
- package/src/util/highlights.ts +51 -0
- package/src/util/locale.ts +81 -0
- package/src/util/marquee.ts +51 -0
- package/src/util/media.ts +43 -0
- package/src/util/model.ts +33 -0
- package/src/util/path-format.ts +37 -0
- package/src/util/path.ts +12 -0
- package/src/util/permission.ts +188 -0
- package/src/util/persistence.ts +42 -0
- package/src/util/presentation.ts +42 -0
- package/src/util/project.ts +7 -0
- package/src/util/record.ts +3 -0
- package/src/util/renderer.ts +15 -0
- package/src/util/scroll.ts +29 -0
- package/src/util/selection.ts +103 -0
- package/src/util/session.ts +103 -0
- package/src/util/signal.ts +49 -0
- package/src/util/single-flight.ts +12 -0
- package/src/util/string-width.bun.ts +1 -0
- package/src/util/string-width.node.ts +26 -0
- package/src/util/string-width.ts +1 -0
- package/src/util/system.ts +23 -0
- package/src/util/todo.ts +43 -0
- package/src/util/tool-display.ts +70 -0
- package/src/util/usage-limits.ts +152 -0
- package/src/util/watch.ts +24 -0
- package/test/app-lifecycle.test.tsx +2962 -0
- package/test/clear-session.test.tsx +67 -0
- package/test/cli/cmd/tui/integration-options.test.ts +98 -0
- package/test/cli/cmd/tui/model-options.test.ts +105 -0
- package/test/cli/cmd/tui/notifications.test.ts +356 -0
- package/test/cli/tui/__snapshots__/inline-tool-wrap-snapshot.test.tsx.snap +22 -0
- package/test/cli/tui/anchors.test.ts +77 -0
- package/test/cli/tui/collapse-tool-output.test.ts +14 -0
- package/test/cli/tui/command-palette.test.tsx +86 -0
- package/test/cli/tui/composer-keymap.test.tsx +346 -0
- package/test/cli/tui/data.test.tsx +3669 -0
- package/test/cli/tui/dialog-integration.test.tsx +588 -0
- package/test/cli/tui/dialog-mcp.test.tsx +197 -0
- package/test/cli/tui/dialog-open.test.tsx +1037 -0
- package/test/cli/tui/dialog-prompt.test.tsx +253 -0
- package/test/cli/tui/dialog-select.test.tsx +740 -0
- package/test/cli/tui/dialog-session-list.test.tsx +130 -0
- package/test/cli/tui/diff-viewer-file-tree.test.tsx +256 -0
- package/test/cli/tui/diff-viewer-image.test.tsx +172 -0
- package/test/cli/tui/diff-viewer.test.tsx +2510 -0
- package/test/cli/tui/form.test.tsx +950 -0
- package/test/cli/tui/group-boundary.test.ts +63 -0
- package/test/cli/tui/group-view.test.tsx +352 -0
- package/test/cli/tui/grouping-tree.test.ts +82 -0
- package/test/cli/tui/inline-tool-wrap-snapshot.test.tsx +248 -0
- package/test/cli/tui/input-scope.test.tsx +282 -0
- package/test/cli/tui/keymap-arguments.test.tsx +45 -0
- package/test/cli/tui/message-navigation.test.ts +164 -0
- package/test/cli/tui/mount-budget.test.ts +74 -0
- package/test/cli/tui/permission.test.ts +7 -0
- package/test/cli/tui/plugins-dialog.test.tsx +217 -0
- package/test/cli/tui/prompt-interrupt-status.test.tsx +25 -0
- package/test/cli/tui/prompt-move.test.tsx +446 -0
- package/test/cli/tui/reasoning-body.test.tsx +80 -0
- package/test/cli/tui/script-changes.test.ts +41 -0
- package/test/cli/tui/session-grouping.test.ts +21 -0
- package/test/cli/tui/session-history.test.ts +124 -0
- package/test/cli/tui/session-rows.test.ts +616 -0
- package/test/cli/tui/session-verbosity.test.ts +307 -0
- package/test/cli/tui/theme-mode.test.tsx +179 -0
- package/test/cli/tui/thinking.test.ts +36 -0
- package/test/cli/tui/toast.test.tsx +117 -0
- package/test/cli/tui/use-event.test.tsx +295 -0
- package/test/client-mcp.test.tsx +226 -0
- package/test/clipboard.test.ts +148 -0
- package/test/command-selection.test.tsx +123 -0
- package/test/compact-admission.test.tsx +251 -0
- package/test/completion-notices.test.tsx +197 -0
- package/test/component/animation-ticks.test.tsx +212 -0
- package/test/component/dialog-error-details.test.tsx +110 -0
- package/test/component/dialog-export-options.test.tsx +68 -0
- package/test/component/dialog-highlights.test.tsx +73 -0
- package/test/component/dialog-model.test.tsx +145 -0
- package/test/component/dialog-shell-output.test.tsx +255 -0
- package/test/component/dialog-speed.test.tsx +114 -0
- package/test/component/dialog-update.test.tsx +111 -0
- package/test/component/dialog-variant.test.tsx +24 -0
- package/test/component/go-upsell-art.test.tsx +110 -0
- package/test/component/retry-provider.test.tsx +288 -0
- package/test/component/session-tabs-marquee.test.tsx +100 -0
- package/test/component/session-tabs-mouse.test.tsx +216 -0
- package/test/component/session-tabs-rail.test.tsx +120 -0
- package/test/component/session-tabs-status.test.tsx +345 -0
- package/test/component/shimmer-text.test.tsx +37 -0
- package/test/component/spinner-renderable.test.tsx +133 -0
- package/test/component/tab-pulse.test.tsx +196 -0
- package/test/component/terminal-pane-theme.test.ts +68 -0
- package/test/config-v2.test.tsx +335 -0
- package/test/config.test.tsx +184 -0
- package/test/context/local-selection.test.tsx +204 -0
- package/test/context/local.test.ts +15 -0
- package/test/context/program-status.test.ts +73 -0
- package/test/context/session-retention.test.ts +234 -0
- package/test/context/session-tabs-model.test.ts +341 -0
- package/test/context/session-tabs.test.tsx +864 -0
- package/test/context/storage.test.ts +37 -0
- package/test/context/theme.test.tsx +183 -0
- package/test/copy-session-id.test.tsx +79 -0
- package/test/editor.test.ts +69 -0
- package/test/feature-plugins/diff-viewer-file-tree-utils.test.ts +234 -0
- package/test/feature-plugins/goal.test.tsx +126 -0
- package/test/feature-plugins/home-footer.test.ts +13 -0
- package/test/feature-plugins/prompt-footer.test.tsx +303 -0
- package/test/feature-plugins/sidebar-context.test.tsx +70 -0
- package/test/feature-plugins/sidebar-footer.test.tsx +139 -0
- package/test/fixture/animation-ticks.ts +19 -0
- package/test/fixture/app.ts +95 -0
- package/test/fixture/diff-image.ts +7 -0
- package/test/fixture/fixture.ts +27 -0
- package/test/fixture/frame.ts +25 -0
- package/test/fixture/local.tsx +158 -0
- package/test/fixture/plugin/client-reads/tui.tsx +9 -0
- package/test/fixture/plugin/dialog-throw/tui.tsx +11 -0
- package/test/fixture/plugin/native-resources/tui.tsx +26 -0
- package/test/fixture/plugin/setup-keymap/tui.tsx +72 -0
- package/test/fixture/plugin/slot-string/tui.tsx +10 -0
- package/test/fixture/tui-client.ts +186 -0
- package/test/fixture/tui-environment.tsx +47 -0
- package/test/fixture/tui-runtime.ts +21 -0
- package/test/highlights.test.ts +43 -0
- package/test/interactivity.test.tsx +46 -0
- package/test/keybind.test.ts +7 -0
- package/test/keymap-scope.test.tsx +271 -0
- package/test/keymap.test.tsx +244 -0
- package/test/markdown-streaming.test.tsx +49 -0
- package/test/mini/blocker.responsive.test.tsx +732 -0
- package/test/mini/catalog.shared.test.ts +76 -0
- package/test/mini/entry.body.test.ts +622 -0
- package/test/mini/fixture/catalog.ts +63 -0
- package/test/mini/fixture/footer-api.ts +69 -0
- package/test/mini/fixture/tool-part.ts +20 -0
- package/test/mini/footer-keymap.test.tsx +141 -0
- package/test/mini/footer.menu.test.ts +43 -0
- package/test/mini/footer.responsive.test.tsx +438 -0
- package/test/mini/footer.test.ts +446 -0
- package/test/mini/footer.view.test.tsx +2627 -0
- package/test/mini/footer.width.test.ts +120 -0
- package/test/mini/form.shared.test.ts +66 -0
- package/test/mini/permission.shared.test.ts +195 -0
- package/test/mini/prompt.editor.test.ts +118 -0
- package/test/mini/prompt.shared.test.ts +104 -0
- package/test/mini/runtime.boot.test.ts +118 -0
- package/test/mini/runtime.queue.test.ts +443 -0
- package/test/mini/runtime.test.ts +591 -0
- package/test/mini/scrollback.image.test.ts +213 -0
- package/test/mini/scrollback.surface.test.ts +1078 -0
- package/test/mini/session.shared.test.ts +267 -0
- package/test/mini/splash.test.ts +196 -0
- package/test/mini/stream-v2.transport.test.ts +4705 -0
- package/test/mini/stream.test.ts +52 -0
- package/test/mini/theme.test.ts +438 -0
- package/test/mini/tool.test.ts +134 -0
- package/test/mini/variant.shared.test.ts +58 -0
- package/test/mini/verbosity.test.ts +53 -0
- package/test/model-preference.test.ts +70 -0
- package/test/new-session-id.test.tsx +102 -0
- package/test/new-session-location.test.ts +30 -0
- package/test/panel.test.ts +71 -0
- package/test/plugin-discovery.test.ts +18 -0
- package/test/plugin-keymap.test.tsx +143 -0
- package/test/plugin-markdown.test.tsx +120 -0
- package/test/plugin-model.test.tsx +46 -0
- package/test/plugin-native-resources.test.tsx +11 -0
- package/test/plugin-select.test.tsx +391 -0
- package/test/plugin-slot-output.test.tsx +23 -0
- package/test/plugin-source.test.ts +871 -0
- package/test/plugin-toast.test.tsx +62 -0
- package/test/preload.ts +17 -0
- package/test/prompt/attachment.test.ts +138 -0
- package/test/prompt/autocomplete.test.ts +218 -0
- package/test/prompt/codec.test.ts +136 -0
- package/test/prompt/display.test.ts +72 -0
- package/test/prompt/draft-stash.test.ts +42 -0
- package/test/prompt/history-composer.test.tsx +52 -0
- package/test/prompt/history-provider.test.tsx +108 -0
- package/test/prompt/history.test.ts +94 -0
- package/test/prompt/jsonl.test.ts +24 -0
- package/test/prompt/local-attachment.test.ts +244 -0
- package/test/prompt/mention.test.ts +119 -0
- package/test/prompt/parse.test.ts +46 -0
- package/test/prompt/part.test.ts +40 -0
- package/test/prompt/persistence.test.ts +23 -0
- package/test/prompt/traits.test.ts +25 -0
- package/test/prompt-cursor.test.tsx +27 -0
- package/test/prompt-offset.test.tsx +58 -0
- package/test/prompt-paste.test.tsx +127 -0
- package/test/prompt-shell-failure.test.tsx +76 -0
- package/test/routes/composer-tabs.test.tsx +97 -0
- package/test/runtime.test.tsx +37 -0
- package/test/session-activity-anchor.test.tsx +180 -0
- package/test/session-backfill-disclosure.test.tsx +89 -0
- package/test/session-dialog-resync.test.tsx +122 -0
- package/test/session-fork-pending.test.tsx +60 -0
- package/test/session-group-navigation.test.tsx +252 -0
- package/test/session-history-interactions.test.tsx +305 -0
- package/test/session-history-reveal.test.tsx +108 -0
- package/test/session-home.test.tsx +401 -0
- package/test/session-interrupt-undo.test.tsx +98 -0
- package/test/session-media-refs.test.tsx +360 -0
- package/test/session-mount-budget.test.tsx +137 -0
- package/test/session-panel.test.tsx +721 -0
- package/test/session-shell-output.test.tsx +114 -0
- package/test/session-shell-stopped.test.tsx +107 -0
- package/test/session-subagent-navigation.test.tsx +44 -0
- package/test/session-submit-scroll.test.tsx +85 -0
- package/test/session-terminal-availability.test.tsx +80 -0
- package/test/session-wheel-focus.test.tsx +176 -0
- package/test/simulation/semantics.test.ts +23 -0
- package/test/stats.test.ts +33 -0
- package/test/stats.view.test.tsx +94 -0
- package/test/theme/v2/component.test.ts +87 -0
- package/test/theme/v2/resolve.test.ts +424 -0
- package/test/theme/v2/select.test.ts +25 -0
- package/test/theme/v2/types.typecheck.ts +57 -0
- package/test/theme/v2/v1-migrate.test.ts +397 -0
- package/test/theme.test.ts +150 -0
- package/test/ui/dialog-layout.test.tsx +56 -0
- package/test/ui/file-path.test.ts +61 -0
- package/test/ui/layout.test.ts +31 -0
- package/test/ui/link.test.tsx +60 -0
- package/test/ui/pane-resize-handle.test.tsx +134 -0
- package/test/ui/pane-resize.test.ts +258 -0
- package/test/ui/select-controller.test.ts +44 -0
- package/test/ui/session-link.test.tsx +325 -0
- package/test/usage-limits.test.tsx +162 -0
- package/test/util/added-patch.test.ts +44 -0
- package/test/util/connected-provider.test.ts +59 -0
- package/test/util/delayed-presence.test.ts +114 -0
- package/test/util/error-details.test.ts +26 -0
- package/test/util/error.test.ts +36 -0
- package/test/util/filetype.test.ts +23 -0
- package/test/util/form.test.ts +110 -0
- package/test/util/locale.test.ts +32 -0
- package/test/util/marquee.test.ts +45 -0
- package/test/util/media.test.ts +54 -0
- package/test/util/model.test.ts +70 -0
- package/test/util/path-format.test.ts +15 -0
- package/test/util/permission.test.ts +23 -0
- package/test/util/presentation.test.ts +30 -0
- package/test/util/renderer.test.ts +42 -0
- package/test/util/selection-copy-on-select.test.tsx +64 -0
- package/test/util/selection-keys.test.ts +172 -0
- package/test/util/selection.test.ts +115 -0
- package/test/util/session.test.ts +70 -0
- package/test/util/tool-display.test.ts +65 -0
- package/test/util/usage-limits.test.ts +154 -0
- package/tsconfig.json +13 -0
- package/README.md +0 -3
|
@@ -0,0 +1,1177 @@
|
|
|
1
|
+
import { createStore, unwrap } from "solid-js/store"
|
|
2
|
+
import { createEffect, createMemo, createSignal, For, onCleanup, onMount, Show } from "solid-js"
|
|
3
|
+
import { usePaste, useRenderer, useTerminalDimensions } from "@opentui/solid"
|
|
4
|
+
import {
|
|
5
|
+
decodePasteBytes,
|
|
6
|
+
stripAnsiSequences,
|
|
7
|
+
TextAttributes,
|
|
8
|
+
type BoxRenderable,
|
|
9
|
+
type ScrollBoxRenderable,
|
|
10
|
+
type TextareaRenderable,
|
|
11
|
+
} from "@opentui/core"
|
|
12
|
+
import { openUrl } from "@zyro-sec/util/open"
|
|
13
|
+
import { useTheme } from "../../context/theme"
|
|
14
|
+
import type { FormAnswer, FormField, FormValue } from "@zyro-sec/client"
|
|
15
|
+
import { useData, type FormWithLocation } from "../../context/data"
|
|
16
|
+
import { useClipboard } from "../../context/clipboard"
|
|
17
|
+
import { SplitBorder } from "../../ui/border"
|
|
18
|
+
import { useDialog } from "../../ui/dialog"
|
|
19
|
+
import { useToast } from "../../ui/toast"
|
|
20
|
+
import { Keymap } from "../../context/keymap"
|
|
21
|
+
import { useInteractivity } from "../../context/interactivity"
|
|
22
|
+
import { useCursorStyle } from "../../config"
|
|
23
|
+
import { errorMessage } from "../../util/error"
|
|
24
|
+
import {
|
|
25
|
+
formCustom,
|
|
26
|
+
formDisplayValue,
|
|
27
|
+
formInitialValues,
|
|
28
|
+
formLabel,
|
|
29
|
+
formRows,
|
|
30
|
+
formSelected,
|
|
31
|
+
formSetMultiselectCustom,
|
|
32
|
+
formTextual,
|
|
33
|
+
formToggleMultiselect,
|
|
34
|
+
formValidateValue,
|
|
35
|
+
isFormAnswerField,
|
|
36
|
+
} from "../../util/form"
|
|
37
|
+
import type { FormAnswerField } from "../../util/form"
|
|
38
|
+
|
|
39
|
+
export const FORM_MODE = "form"
|
|
40
|
+
|
|
41
|
+
function truncate(label: string, max: number) {
|
|
42
|
+
return label.length > max ? label.slice(0, max - 1).trimEnd() + "…" : label
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
type FormDraft = {
|
|
46
|
+
tab: number
|
|
47
|
+
answers: Record<string, FormValue | undefined>
|
|
48
|
+
custom: Record<string, string | undefined>
|
|
49
|
+
externalReady: Record<string, boolean>
|
|
50
|
+
selected: number
|
|
51
|
+
editing: boolean
|
|
52
|
+
error: string
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
// Holds in-progress answers per form across FormPrompt remounts, since the
|
|
56
|
+
// session route is keyed by sessionID and unmounts on tab switch. Mirrors
|
|
57
|
+
// component/prompt/draft-stash.ts: a draft is consumed on take.
|
|
58
|
+
const drafts = new Map<string, FormDraft>()
|
|
59
|
+
|
|
60
|
+
export function FormPrompt(props: { form: FormWithLocation }) {
|
|
61
|
+
const data = useData()
|
|
62
|
+
const theme = useTheme()
|
|
63
|
+
const renderer = useRenderer()
|
|
64
|
+
const dimensions = useTerminalDimensions()
|
|
65
|
+
const dialog = useDialog()
|
|
66
|
+
const keymap = Keymap.use()
|
|
67
|
+
const enabled = useInteractivity()
|
|
68
|
+
const active = () => enabled() && dialog.stack.length === 0 && keymap.mode.current() === FORM_MODE
|
|
69
|
+
const cursorStyle = useCursorStyle()
|
|
70
|
+
const clipboard = useClipboard()
|
|
71
|
+
const toast = useToast()
|
|
72
|
+
const configuredFields = props.form.fields.filter(isFormAnswerField)
|
|
73
|
+
const initial = formInitialValues(props.form.fields)
|
|
74
|
+
const draft = drafts.get(props.form.id)
|
|
75
|
+
drafts.delete(props.form.id)
|
|
76
|
+
|
|
77
|
+
const [tabHover, setTabHover] = createSignal<number | "confirm" | null>(null)
|
|
78
|
+
const [reviewContentHeight, setReviewContentHeight] = createSignal(0)
|
|
79
|
+
const [store, setStore] = createStore<FormDraft>(
|
|
80
|
+
draft ?? {
|
|
81
|
+
tab: 0,
|
|
82
|
+
answers: initial.answers,
|
|
83
|
+
custom: initial.custom,
|
|
84
|
+
externalReady: {},
|
|
85
|
+
selected: formSelected(configuredFields[0], configuredFields[0]?.default),
|
|
86
|
+
editing: false,
|
|
87
|
+
error: "",
|
|
88
|
+
},
|
|
89
|
+
)
|
|
90
|
+
|
|
91
|
+
let textarea: TextareaRenderable | undefined
|
|
92
|
+
const [inputTarget, setInputTarget] = createSignal<TextareaRenderable>()
|
|
93
|
+
let review: ScrollBoxRenderable | undefined
|
|
94
|
+
|
|
95
|
+
const message = createMemo(() => {
|
|
96
|
+
const value = props.form.metadata?.["message"]
|
|
97
|
+
return typeof value === "string" ? value : undefined
|
|
98
|
+
})
|
|
99
|
+
const fields = createMemo(() => {
|
|
100
|
+
const answers: Record<string, FormValue | undefined> = {}
|
|
101
|
+
return props.form.fields.filter((field) => {
|
|
102
|
+
if (field.type === "external") return true
|
|
103
|
+
const active = (field.when ?? []).every((when) => {
|
|
104
|
+
const value = answers[when.key]
|
|
105
|
+
if (value === undefined) return false
|
|
106
|
+
const hit = Array.isArray(value) ? value.some((item) => item === when.value) : value === when.value
|
|
107
|
+
return when.op === "eq" ? hit : !hit
|
|
108
|
+
})
|
|
109
|
+
if (active) answers[field.key] = store.answers[field.key]
|
|
110
|
+
return active
|
|
111
|
+
})
|
|
112
|
+
})
|
|
113
|
+
const single = createMemo(() => {
|
|
114
|
+
const list = fields()
|
|
115
|
+
if (list.length !== 1) return false
|
|
116
|
+
const field = list[0]
|
|
117
|
+
if (field.type === "external") return false
|
|
118
|
+
return field.type === "boolean" || (field.type === "string" && field.options !== undefined)
|
|
119
|
+
})
|
|
120
|
+
const tabs = createMemo(() => (single() ? 1 : fields().length + 1))
|
|
121
|
+
const tabbed = createMemo(() => {
|
|
122
|
+
const width = fields().reduce((sum, item) => sum + truncate(formLabel(item), 24).length + 3, "Submit".length + 3)
|
|
123
|
+
return width <= dimensions().width - 8
|
|
124
|
+
})
|
|
125
|
+
const completed = (item: FormField) => {
|
|
126
|
+
const value = store.answers[item.key]
|
|
127
|
+
if (value === undefined) return false
|
|
128
|
+
if (item.type === "external") return value === true
|
|
129
|
+
return formValidateValue(item, value) === undefined
|
|
130
|
+
}
|
|
131
|
+
const answered = createMemo(() => fields().filter(completed).length)
|
|
132
|
+
const field = createMemo(() => fields()[store.tab])
|
|
133
|
+
const answerField = createMemo(() => {
|
|
134
|
+
const current = field()
|
|
135
|
+
return current && isFormAnswerField(current) ? current : undefined
|
|
136
|
+
})
|
|
137
|
+
const externalField = createMemo(() => {
|
|
138
|
+
const current = field()
|
|
139
|
+
return current?.type === "external" ? current : undefined
|
|
140
|
+
})
|
|
141
|
+
const confirm = createMemo(() => !single() && store.tab >= fields().length)
|
|
142
|
+
const reviewMaxHeight = createMemo(() => Math.max(3, dimensions().height - 14))
|
|
143
|
+
const configuredRows = createMemo(() => {
|
|
144
|
+
const current = answerField()
|
|
145
|
+
return current ? formRows(current) : []
|
|
146
|
+
})
|
|
147
|
+
const rows = createMemo(() => {
|
|
148
|
+
const current = answerField()
|
|
149
|
+
if (!current) return []
|
|
150
|
+
const configured = configuredRows()
|
|
151
|
+
const value = store.answers[current.key]
|
|
152
|
+
if (current.type !== "multiselect" || !Array.isArray(value)) return configured
|
|
153
|
+
const known = new Set(configured.map((row) => row.value))
|
|
154
|
+
return [
|
|
155
|
+
...configured,
|
|
156
|
+
...value
|
|
157
|
+
.filter((item) => !known.has(item) && item !== store.custom[current.key])
|
|
158
|
+
.map((item) => ({ value: item, label: item, description: undefined })),
|
|
159
|
+
]
|
|
160
|
+
})
|
|
161
|
+
const textual = createMemo(() => {
|
|
162
|
+
if (confirm()) return false
|
|
163
|
+
return formTextual(answerField())
|
|
164
|
+
})
|
|
165
|
+
const custom = createMemo(() => {
|
|
166
|
+
return formCustom(answerField())
|
|
167
|
+
})
|
|
168
|
+
const multi = createMemo(() => answerField()?.type === "multiselect")
|
|
169
|
+
const placeholder = createMemo(() => {
|
|
170
|
+
const current = answerField()
|
|
171
|
+
if (current?.type === "string") {
|
|
172
|
+
if (current.placeholder) return current.placeholder
|
|
173
|
+
if (current.format === "email") return "name@example.com"
|
|
174
|
+
if (current.format === "uri") return "https://example.com"
|
|
175
|
+
if (current.format === "date") return "YYYY-MM-DD"
|
|
176
|
+
if (current.format === "date-time") return "YYYY-MM-DDTHH:MM:SSZ"
|
|
177
|
+
}
|
|
178
|
+
if (current?.type === "number" || current?.type === "integer") {
|
|
179
|
+
const minimum = typeof current.minimum === "number" ? current.minimum : undefined
|
|
180
|
+
const maximum = typeof current.maximum === "number" ? current.maximum : undefined
|
|
181
|
+
if (minimum !== undefined && maximum !== undefined) return `${minimum}-${maximum}`
|
|
182
|
+
if (minimum !== undefined) return `at least ${minimum}`
|
|
183
|
+
if (maximum !== undefined) return `at most ${maximum}`
|
|
184
|
+
}
|
|
185
|
+
return "Type your answer"
|
|
186
|
+
})
|
|
187
|
+
const other = createMemo(() => custom() && store.selected === rows().length)
|
|
188
|
+
const input = createMemo(() => store.custom[answerField()?.key ?? ""] ?? "")
|
|
189
|
+
const customPicked = createMemo(() => {
|
|
190
|
+
const value = input()
|
|
191
|
+
if (!value) return false
|
|
192
|
+
const answer = store.answers[answerField()?.key ?? ""]
|
|
193
|
+
if (Array.isArray(answer)) return answer.includes(value)
|
|
194
|
+
return answer === value
|
|
195
|
+
})
|
|
196
|
+
const customChecked = createMemo(() => customPicked() || (multi() && other() && store.editing))
|
|
197
|
+
const actionLabel = createMemo(() => {
|
|
198
|
+
if (confirm()) return "submit"
|
|
199
|
+
const external = externalField()
|
|
200
|
+
if (external) {
|
|
201
|
+
if (store.answers[external.key] === true) return "continue"
|
|
202
|
+
return store.externalReady[external.key] ? "I finished" : "open link"
|
|
203
|
+
}
|
|
204
|
+
if (multi()) {
|
|
205
|
+
if (other() && store.editing) return "done"
|
|
206
|
+
if (other() && !input()) return "edit"
|
|
207
|
+
return "toggle"
|
|
208
|
+
}
|
|
209
|
+
if (single()) return "submit"
|
|
210
|
+
return "confirm"
|
|
211
|
+
})
|
|
212
|
+
|
|
213
|
+
onCleanup(() => {
|
|
214
|
+
// A reply or cancel removes the form from data before this unmount runs, so a
|
|
215
|
+
// form still listed here is only hidden by navigation and worth restoring.
|
|
216
|
+
const pending = data.session.form
|
|
217
|
+
.list(props.form.sessionID, props.form.location)
|
|
218
|
+
?.some((item) => item.id === props.form.id)
|
|
219
|
+
if (!pending) return
|
|
220
|
+
// Textual answers live in the editor until committed, so capture them here.
|
|
221
|
+
const current = answerField()
|
|
222
|
+
const snapshot = unwrap(store)
|
|
223
|
+
drafts.set(props.form.id, {
|
|
224
|
+
...snapshot,
|
|
225
|
+
custom:
|
|
226
|
+
current && textarea && !textarea.isDestroyed
|
|
227
|
+
? { ...snapshot.custom, [current.key]: textarea.plainText }
|
|
228
|
+
: snapshot.custom,
|
|
229
|
+
})
|
|
230
|
+
})
|
|
231
|
+
|
|
232
|
+
// Refs publish after initialization so burst typing stays with the interceptor until the editor is ready.
|
|
233
|
+
createEffect(() => {
|
|
234
|
+
const target = inputTarget()
|
|
235
|
+
if (!target || target.isDestroyed) return
|
|
236
|
+
if (!active()) {
|
|
237
|
+
target.blur()
|
|
238
|
+
target.focusable = false
|
|
239
|
+
return
|
|
240
|
+
}
|
|
241
|
+
target.focusable = true
|
|
242
|
+
target.focus()
|
|
243
|
+
})
|
|
244
|
+
|
|
245
|
+
onCleanup(
|
|
246
|
+
keymap.intercept("key", ({ event, consume }) => {
|
|
247
|
+
if (!active()) return
|
|
248
|
+
if (textual() || !other() || (store.editing && renderer.currentFocusedEditor === textarea)) return
|
|
249
|
+
if (event.ctrl || event.meta || event.option || event.super || event.hyper) return
|
|
250
|
+
if ((!store.editing && event.sequence === " ") || !/^[^\p{C}\p{Zl}\p{Zp}]$/u.test(event.sequence)) return
|
|
251
|
+
const current = answerField()
|
|
252
|
+
if (!current) return
|
|
253
|
+
updateCustom(current, input() + event.sequence)
|
|
254
|
+
if (!store.editing) setStore("editing", true)
|
|
255
|
+
consume()
|
|
256
|
+
}),
|
|
257
|
+
)
|
|
258
|
+
|
|
259
|
+
function answer(key: string, value: FormValue | undefined) {
|
|
260
|
+
const field = fields().find((item) => item.key === key)
|
|
261
|
+
setStore(
|
|
262
|
+
"answers",
|
|
263
|
+
key,
|
|
264
|
+
Array.isArray(value) && value.length === 0 && field?.type === "multiselect" && !field.required
|
|
265
|
+
? undefined
|
|
266
|
+
: value,
|
|
267
|
+
)
|
|
268
|
+
setStore("error", "")
|
|
269
|
+
}
|
|
270
|
+
|
|
271
|
+
function reply(answer: FormAnswer) {
|
|
272
|
+
void data.session.form
|
|
273
|
+
.reply({ sessionID: props.form.sessionID, formID: props.form.id, answer }, props.form.location)
|
|
274
|
+
.catch(showError)
|
|
275
|
+
}
|
|
276
|
+
|
|
277
|
+
function replySingle(field: FormAnswerField, value: FormValue) {
|
|
278
|
+
reply({ [field.key]: value })
|
|
279
|
+
}
|
|
280
|
+
|
|
281
|
+
function pick(value: FormValue, customValue?: string) {
|
|
282
|
+
const current = answerField()
|
|
283
|
+
if (!current) return
|
|
284
|
+
const invalid = formValidateValue(current, value)
|
|
285
|
+
if (invalid) {
|
|
286
|
+
setStore("error", invalid)
|
|
287
|
+
return
|
|
288
|
+
}
|
|
289
|
+
answer(current.key, value)
|
|
290
|
+
if (customValue !== undefined) setStore("custom", current.key, customValue)
|
|
291
|
+
if (single()) {
|
|
292
|
+
replySingle(current, value)
|
|
293
|
+
return
|
|
294
|
+
}
|
|
295
|
+
selectTab(store.tab + 1)
|
|
296
|
+
}
|
|
297
|
+
|
|
298
|
+
function toggle(value: string) {
|
|
299
|
+
const current = answerField()
|
|
300
|
+
if (!current) return
|
|
301
|
+
answer(current.key, formToggleMultiselect(store.answers[current.key], value))
|
|
302
|
+
}
|
|
303
|
+
|
|
304
|
+
function updateCustom(current: FormAnswerField, value: string) {
|
|
305
|
+
const previous = store.custom[current.key]
|
|
306
|
+
if (previous === value) return
|
|
307
|
+
setStore("custom", current.key, value)
|
|
308
|
+
answer(
|
|
309
|
+
current.key,
|
|
310
|
+
current.type === "multiselect"
|
|
311
|
+
? formSetMultiselectCustom(store.answers[current.key], previous, value)
|
|
312
|
+
: value || undefined,
|
|
313
|
+
)
|
|
314
|
+
}
|
|
315
|
+
|
|
316
|
+
function selectTab(index: number) {
|
|
317
|
+
const next = fields()[index]
|
|
318
|
+
setStore("tab", index)
|
|
319
|
+
setStore("selected", next && isFormAnswerField(next) ? formSelected(next, store.answers[next.key]) : 0)
|
|
320
|
+
setStore("editing", false)
|
|
321
|
+
setStore("error", "")
|
|
322
|
+
}
|
|
323
|
+
|
|
324
|
+
function selectOption() {
|
|
325
|
+
if (other()) {
|
|
326
|
+
if (!multi()) {
|
|
327
|
+
setStore("editing", true)
|
|
328
|
+
return
|
|
329
|
+
}
|
|
330
|
+
const value = input()
|
|
331
|
+
if (value && customPicked()) {
|
|
332
|
+
toggle(value)
|
|
333
|
+
return
|
|
334
|
+
}
|
|
335
|
+
setStore("editing", true)
|
|
336
|
+
return
|
|
337
|
+
}
|
|
338
|
+
const row = rows()[store.selected]
|
|
339
|
+
if (!row) return
|
|
340
|
+
if (multi()) {
|
|
341
|
+
toggle(String(row.value))
|
|
342
|
+
return
|
|
343
|
+
}
|
|
344
|
+
pick(row.value)
|
|
345
|
+
}
|
|
346
|
+
|
|
347
|
+
function pasteCustom(value: string) {
|
|
348
|
+
const current = answerField()
|
|
349
|
+
if (!current || textual() || !custom() || confirm()) return false
|
|
350
|
+
setStore("selected", rows().length)
|
|
351
|
+
updateCustom(current, input() + value)
|
|
352
|
+
setStore("editing", true)
|
|
353
|
+
return true
|
|
354
|
+
}
|
|
355
|
+
|
|
356
|
+
usePaste((event) => {
|
|
357
|
+
if (!active()) return
|
|
358
|
+
const value = stripAnsiSequences(decodePasteBytes(event.bytes)).replace(/\r\n?/g, "\n")
|
|
359
|
+
if (store.editing && renderer.currentFocusedEditor === textarea) {
|
|
360
|
+
textarea.insertText(value)
|
|
361
|
+
event.preventDefault()
|
|
362
|
+
return
|
|
363
|
+
}
|
|
364
|
+
if (!pasteCustom(value)) return
|
|
365
|
+
event.preventDefault()
|
|
366
|
+
})
|
|
367
|
+
|
|
368
|
+
function pasteClipboard() {
|
|
369
|
+
return clipboard
|
|
370
|
+
.read()
|
|
371
|
+
.then((content) => {
|
|
372
|
+
if (!active() || content?.mime !== "text/plain") return
|
|
373
|
+
const value = stripAnsiSequences(content.data).replace(/\r\n?/g, "\n")
|
|
374
|
+
if (store.editing || textual()) {
|
|
375
|
+
textarea?.insertText(value)
|
|
376
|
+
return
|
|
377
|
+
}
|
|
378
|
+
pasteCustom(value)
|
|
379
|
+
})
|
|
380
|
+
.catch(toast.error)
|
|
381
|
+
}
|
|
382
|
+
|
|
383
|
+
function commitInput(text: string) {
|
|
384
|
+
const current = answerField()
|
|
385
|
+
if (!current) return false
|
|
386
|
+
const isTextual = textual()
|
|
387
|
+
const isMulti = multi()
|
|
388
|
+
if (!text) {
|
|
389
|
+
const value =
|
|
390
|
+
!isTextual && isMulti
|
|
391
|
+
? formSetMultiselectCustom(store.answers[current.key], store.custom[current.key], "")
|
|
392
|
+
: undefined
|
|
393
|
+
if (isTextual || !isMulti) {
|
|
394
|
+
const invalid = formValidateValue(current, value)
|
|
395
|
+
if (invalid) {
|
|
396
|
+
setStore("error", invalid)
|
|
397
|
+
return false
|
|
398
|
+
}
|
|
399
|
+
}
|
|
400
|
+
answer(current.key, value)
|
|
401
|
+
setStore("custom", current.key, "")
|
|
402
|
+
setStore("editing", false)
|
|
403
|
+
return true
|
|
404
|
+
}
|
|
405
|
+
|
|
406
|
+
if (isTextual && (current.type === "number" || current.type === "integer")) {
|
|
407
|
+
const value = Number(text)
|
|
408
|
+
const invalid = formValidateValue(current, value)
|
|
409
|
+
if (invalid) {
|
|
410
|
+
setStore("error", invalid)
|
|
411
|
+
return false
|
|
412
|
+
}
|
|
413
|
+
answer(current.key, value)
|
|
414
|
+
}
|
|
415
|
+
|
|
416
|
+
if (isTextual && current.type === "string") {
|
|
417
|
+
const invalid = formValidateValue(current, text)
|
|
418
|
+
if (invalid) {
|
|
419
|
+
setStore("error", invalid)
|
|
420
|
+
return false
|
|
421
|
+
}
|
|
422
|
+
answer(current.key, text)
|
|
423
|
+
}
|
|
424
|
+
|
|
425
|
+
if (!isTextual && isMulti) {
|
|
426
|
+
answer(current.key, formSetMultiselectCustom(store.answers[current.key], store.custom[current.key], text))
|
|
427
|
+
}
|
|
428
|
+
|
|
429
|
+
if (!isTextual && !isMulti) {
|
|
430
|
+
const invalid = formValidateValue(current, text)
|
|
431
|
+
if (invalid) {
|
|
432
|
+
setStore("error", invalid)
|
|
433
|
+
return false
|
|
434
|
+
}
|
|
435
|
+
answer(current.key, text)
|
|
436
|
+
}
|
|
437
|
+
|
|
438
|
+
const configured = current.type === "string" && current.options?.some((option) => option.value === text)
|
|
439
|
+
setStore("custom", current.key, configured ? "" : text)
|
|
440
|
+
setStore("editing", false)
|
|
441
|
+
return true
|
|
442
|
+
}
|
|
443
|
+
|
|
444
|
+
function submitInput(text: string, direction: 1 | -1 = 1) {
|
|
445
|
+
if (!commitInput(text)) {
|
|
446
|
+
if (direction === -1) selectTab((store.tab + direction + tabs()) % tabs())
|
|
447
|
+
return
|
|
448
|
+
}
|
|
449
|
+
if (!single()) selectTab((store.tab + direction + tabs()) % tabs())
|
|
450
|
+
}
|
|
451
|
+
|
|
452
|
+
function selectTabFromMouse(target?: FormField) {
|
|
453
|
+
const targetIndex = () => {
|
|
454
|
+
const index = target ? fields().findIndex((field) => field === target) : fields().length
|
|
455
|
+
return index === -1 ? fields().length : index
|
|
456
|
+
}
|
|
457
|
+
const move = () => selectTab(targetIndex())
|
|
458
|
+
if (!textual() && !store.editing) {
|
|
459
|
+
move()
|
|
460
|
+
return
|
|
461
|
+
}
|
|
462
|
+
if (!commitInput(textarea?.plainText?.trim() ?? "")) {
|
|
463
|
+
if (targetIndex() < store.tab) move()
|
|
464
|
+
return
|
|
465
|
+
}
|
|
466
|
+
move()
|
|
467
|
+
}
|
|
468
|
+
|
|
469
|
+
function cancel() {
|
|
470
|
+
void data.session.form
|
|
471
|
+
.cancel({ sessionID: props.form.sessionID, formID: props.form.id }, props.form.location)
|
|
472
|
+
.catch(showError)
|
|
473
|
+
}
|
|
474
|
+
|
|
475
|
+
function showError(error: unknown) {
|
|
476
|
+
setStore("error", errorMessage(error))
|
|
477
|
+
}
|
|
478
|
+
|
|
479
|
+
function openExternal() {
|
|
480
|
+
const current = externalField()
|
|
481
|
+
if (!current) return
|
|
482
|
+
setStore("error", "")
|
|
483
|
+
void openUrl(current.url)
|
|
484
|
+
.then(() => setStore("externalReady", { ...store.externalReady, [current.key]: true }))
|
|
485
|
+
.catch(() => setStore("error", "Could not open the browser. Copy the URL and continue manually."))
|
|
486
|
+
}
|
|
487
|
+
|
|
488
|
+
function copyExternal() {
|
|
489
|
+
const current = externalField()
|
|
490
|
+
if (!current) return
|
|
491
|
+
void clipboard
|
|
492
|
+
.write(current.url)
|
|
493
|
+
.then(() => {
|
|
494
|
+
setStore("externalReady", { ...store.externalReady, [current.key]: true })
|
|
495
|
+
toast.show({ message: "Copied URL to clipboard", variant: "info" })
|
|
496
|
+
})
|
|
497
|
+
.catch(toast.error)
|
|
498
|
+
}
|
|
499
|
+
|
|
500
|
+
function acknowledgeExternal() {
|
|
501
|
+
const current = externalField()
|
|
502
|
+
if (!current) return
|
|
503
|
+
if (store.answers[current.key] === true) {
|
|
504
|
+
selectTab(store.tab + 1)
|
|
505
|
+
return
|
|
506
|
+
}
|
|
507
|
+
if (!store.externalReady[current.key]) {
|
|
508
|
+
openExternal()
|
|
509
|
+
return
|
|
510
|
+
}
|
|
511
|
+
answer(current.key, true)
|
|
512
|
+
selectTab(store.tab + 1)
|
|
513
|
+
}
|
|
514
|
+
|
|
515
|
+
function submit() {
|
|
516
|
+
const unacknowledged = fields().find((field) => field.type === "external" && store.answers[field.key] !== true)
|
|
517
|
+
if (unacknowledged) {
|
|
518
|
+
setStore("error", `External action must be acknowledged: ${formLabel(unacknowledged)}`)
|
|
519
|
+
return
|
|
520
|
+
}
|
|
521
|
+
const invalid = fields()
|
|
522
|
+
.filter(isFormAnswerField)
|
|
523
|
+
.find((field) => formValidateValue(field, store.answers[field.key]))
|
|
524
|
+
if (invalid) {
|
|
525
|
+
setStore("error", formValidateValue(invalid, store.answers[invalid.key]) ?? "Invalid answer")
|
|
526
|
+
return
|
|
527
|
+
}
|
|
528
|
+
reply(
|
|
529
|
+
Object.fromEntries(
|
|
530
|
+
fields().flatMap((field) => {
|
|
531
|
+
const value = store.answers[field.key]
|
|
532
|
+
return value === undefined ? [] : [[field.key, value] as const]
|
|
533
|
+
}),
|
|
534
|
+
),
|
|
535
|
+
)
|
|
536
|
+
}
|
|
537
|
+
|
|
538
|
+
onMount(() => onCleanup(keymap.mode.push(FORM_MODE, () => dialog.stack.length === 0)))
|
|
539
|
+
|
|
540
|
+
Keymap.createLayer(() => ({
|
|
541
|
+
mode: FORM_MODE,
|
|
542
|
+
enabled: !confirm() && answerField() !== undefined,
|
|
543
|
+
commands: [
|
|
544
|
+
{
|
|
545
|
+
id: "prompt.paste",
|
|
546
|
+
title: "Paste from clipboard",
|
|
547
|
+
group: "Form",
|
|
548
|
+
run: (_input, event) => {
|
|
549
|
+
event?.preventDefault()
|
|
550
|
+
event?.stopPropagation()
|
|
551
|
+
return pasteClipboard()
|
|
552
|
+
},
|
|
553
|
+
},
|
|
554
|
+
],
|
|
555
|
+
}))
|
|
556
|
+
|
|
557
|
+
Keymap.createLayer(() => ({
|
|
558
|
+
mode: FORM_MODE,
|
|
559
|
+
priority: 1,
|
|
560
|
+
enabled: (store.editing || textual()) && !confirm(),
|
|
561
|
+
commands: [
|
|
562
|
+
{
|
|
563
|
+
id: "prompt.clear",
|
|
564
|
+
title: "Clear answer edit",
|
|
565
|
+
group: "Form",
|
|
566
|
+
run() {
|
|
567
|
+
const text = textarea?.plainText ?? ""
|
|
568
|
+
if (!text) {
|
|
569
|
+
if (textual()) {
|
|
570
|
+
cancel()
|
|
571
|
+
return
|
|
572
|
+
}
|
|
573
|
+
setStore("editing", false)
|
|
574
|
+
return
|
|
575
|
+
}
|
|
576
|
+
textarea?.setText("")
|
|
577
|
+
},
|
|
578
|
+
},
|
|
579
|
+
{
|
|
580
|
+
bind: "escape",
|
|
581
|
+
title: textual() ? "Dismiss form" : "Close answer edit",
|
|
582
|
+
group: "Form",
|
|
583
|
+
run: () => {
|
|
584
|
+
if (textual()) {
|
|
585
|
+
cancel()
|
|
586
|
+
return
|
|
587
|
+
}
|
|
588
|
+
setStore("editing", false)
|
|
589
|
+
},
|
|
590
|
+
},
|
|
591
|
+
{
|
|
592
|
+
bind: "tab",
|
|
593
|
+
title: "Next field",
|
|
594
|
+
group: "Form",
|
|
595
|
+
run: () => {
|
|
596
|
+
const text = textarea?.plainText?.trim() ?? ""
|
|
597
|
+
submitInput(text)
|
|
598
|
+
},
|
|
599
|
+
},
|
|
600
|
+
{
|
|
601
|
+
bind: "shift+tab",
|
|
602
|
+
title: "Previous field",
|
|
603
|
+
group: "Form",
|
|
604
|
+
run: () => {
|
|
605
|
+
const text = textarea?.plainText?.trim() ?? ""
|
|
606
|
+
submitInput(text, -1)
|
|
607
|
+
},
|
|
608
|
+
},
|
|
609
|
+
{
|
|
610
|
+
bind: "up",
|
|
611
|
+
title: "Leave answer edit",
|
|
612
|
+
group: "Form",
|
|
613
|
+
run: () => {
|
|
614
|
+
if (textual() || !textarea || textarea.isDestroyed || store.selected === 0) return false
|
|
615
|
+
if (textarea.scrollY + textarea.visualCursor.visualRow > 0) return false
|
|
616
|
+
setStore("editing", false)
|
|
617
|
+
setStore("selected", store.selected - 1)
|
|
618
|
+
},
|
|
619
|
+
},
|
|
620
|
+
{
|
|
621
|
+
bind: "return",
|
|
622
|
+
title: "Submit answer edit",
|
|
623
|
+
group: "Form",
|
|
624
|
+
run: () => {
|
|
625
|
+
const text = textarea?.plainText?.trim() ?? ""
|
|
626
|
+
const current = answerField()
|
|
627
|
+
if (!current) return
|
|
628
|
+
if (textual()) {
|
|
629
|
+
submitInput(text)
|
|
630
|
+
return
|
|
631
|
+
}
|
|
632
|
+
const wasMulti = multi()
|
|
633
|
+
if (!commitInput(text) || wasMulti || !text) return
|
|
634
|
+
if (single()) {
|
|
635
|
+
replySingle(current, text)
|
|
636
|
+
return
|
|
637
|
+
}
|
|
638
|
+
selectTab(store.tab + 1)
|
|
639
|
+
},
|
|
640
|
+
},
|
|
641
|
+
],
|
|
642
|
+
}))
|
|
643
|
+
|
|
644
|
+
Keymap.createLayer(() => {
|
|
645
|
+
const total = rows().length + (custom() ? 1 : 0)
|
|
646
|
+
const max = Math.min(total, 9)
|
|
647
|
+
const external = externalField()
|
|
648
|
+
|
|
649
|
+
return {
|
|
650
|
+
mode: FORM_MODE,
|
|
651
|
+
enabled: !store.editing && !textual(),
|
|
652
|
+
commands: [
|
|
653
|
+
{
|
|
654
|
+
id: "app.exit",
|
|
655
|
+
title: "Dismiss form",
|
|
656
|
+
group: "Form",
|
|
657
|
+
run: cancel,
|
|
658
|
+
},
|
|
659
|
+
{
|
|
660
|
+
bind: "left",
|
|
661
|
+
title: "Previous field",
|
|
662
|
+
group: "Form",
|
|
663
|
+
run: () => selectTab((store.tab - 1 + tabs()) % tabs()),
|
|
664
|
+
},
|
|
665
|
+
{
|
|
666
|
+
bind: "h",
|
|
667
|
+
title: "Previous field",
|
|
668
|
+
group: "Form",
|
|
669
|
+
run: () => selectTab((store.tab - 1 + tabs()) % tabs()),
|
|
670
|
+
},
|
|
671
|
+
{ bind: "right", title: "Next field", group: "Form", run: () => selectTab((store.tab + 1) % tabs()) },
|
|
672
|
+
{ bind: "l", title: "Next field", group: "Form", run: () => selectTab((store.tab + 1) % tabs()) },
|
|
673
|
+
{
|
|
674
|
+
bind: "tab",
|
|
675
|
+
title: "Next field",
|
|
676
|
+
group: "Form",
|
|
677
|
+
run: () => selectTab((store.tab + 1) % tabs()),
|
|
678
|
+
},
|
|
679
|
+
{
|
|
680
|
+
bind: "shift+tab",
|
|
681
|
+
title: "Previous field",
|
|
682
|
+
group: "Form",
|
|
683
|
+
run: () => selectTab((store.tab - 1 + tabs()) % tabs()),
|
|
684
|
+
},
|
|
685
|
+
...(external
|
|
686
|
+
? [
|
|
687
|
+
{
|
|
688
|
+
bind: "return",
|
|
689
|
+
title:
|
|
690
|
+
store.answers[external.key] === true
|
|
691
|
+
? "Continue"
|
|
692
|
+
: store.externalReady[external.key]
|
|
693
|
+
? "Confirm completion"
|
|
694
|
+
: "Open link",
|
|
695
|
+
group: "Form",
|
|
696
|
+
run: acknowledgeExternal,
|
|
697
|
+
},
|
|
698
|
+
{ bind: "c", title: "Copy link", group: "Form", run: copyExternal },
|
|
699
|
+
{ bind: "escape", title: "Dismiss form", group: "Form", run: cancel },
|
|
700
|
+
]
|
|
701
|
+
: confirm()
|
|
702
|
+
? [
|
|
703
|
+
{
|
|
704
|
+
bind: "return",
|
|
705
|
+
title: "Submit form",
|
|
706
|
+
group: "Form",
|
|
707
|
+
run: submit,
|
|
708
|
+
},
|
|
709
|
+
{
|
|
710
|
+
bind: "escape",
|
|
711
|
+
title: "Dismiss form",
|
|
712
|
+
group: "Form",
|
|
713
|
+
run: cancel,
|
|
714
|
+
},
|
|
715
|
+
{ bind: "up", title: "Scroll review", group: "Form", run: () => review?.scrollBy(-1) },
|
|
716
|
+
{ bind: "k", title: "Scroll review", group: "Form", run: () => review?.scrollBy(-1) },
|
|
717
|
+
{ bind: "down", title: "Scroll review", group: "Form", run: () => review?.scrollBy(1) },
|
|
718
|
+
{ bind: "j", title: "Scroll review", group: "Form", run: () => review?.scrollBy(1) },
|
|
719
|
+
]
|
|
720
|
+
: [
|
|
721
|
+
...Array.from({ length: max }, (_, index) => ({
|
|
722
|
+
bind: String(index + 1),
|
|
723
|
+
title: `Select answer ${index + 1}`,
|
|
724
|
+
group: "Form",
|
|
725
|
+
run: () => {
|
|
726
|
+
setStore("selected", index)
|
|
727
|
+
selectOption()
|
|
728
|
+
},
|
|
729
|
+
})),
|
|
730
|
+
{
|
|
731
|
+
bind: "up",
|
|
732
|
+
title: "Previous answer",
|
|
733
|
+
group: "Form",
|
|
734
|
+
run: () => setStore("selected", (store.selected - 1 + total) % total),
|
|
735
|
+
},
|
|
736
|
+
{
|
|
737
|
+
bind: "k",
|
|
738
|
+
title: "Previous answer",
|
|
739
|
+
group: "Form",
|
|
740
|
+
run: () => setStore("selected", (store.selected - 1 + total) % total),
|
|
741
|
+
},
|
|
742
|
+
{
|
|
743
|
+
bind: "down",
|
|
744
|
+
title: "Next answer",
|
|
745
|
+
group: "Form",
|
|
746
|
+
run: () => setStore("selected", (store.selected + 1) % total),
|
|
747
|
+
},
|
|
748
|
+
{
|
|
749
|
+
bind: "j",
|
|
750
|
+
title: "Next answer",
|
|
751
|
+
group: "Form",
|
|
752
|
+
run: () => setStore("selected", (store.selected + 1) % total),
|
|
753
|
+
},
|
|
754
|
+
{ bind: "return", title: "Select answer", group: "Form", run: () => selectOption() },
|
|
755
|
+
...(multi()
|
|
756
|
+
? [{ bind: "space", title: "Toggle answer", group: "Form", run: () => selectOption() }]
|
|
757
|
+
: []),
|
|
758
|
+
{
|
|
759
|
+
bind: "escape",
|
|
760
|
+
title: "Dismiss form",
|
|
761
|
+
group: "Form",
|
|
762
|
+
run: cancel,
|
|
763
|
+
},
|
|
764
|
+
]),
|
|
765
|
+
],
|
|
766
|
+
}
|
|
767
|
+
})
|
|
768
|
+
|
|
769
|
+
return (
|
|
770
|
+
<box
|
|
771
|
+
backgroundColor={theme.background.raised.base}
|
|
772
|
+
border={["left"]}
|
|
773
|
+
borderColor={theme.background.action.primary.focused}
|
|
774
|
+
customBorderChars={SplitBorder.customBorderChars}
|
|
775
|
+
>
|
|
776
|
+
<box gap={1} paddingLeft={1} paddingRight={3} paddingTop={1} paddingBottom={1}>
|
|
777
|
+
<box paddingLeft={1}>
|
|
778
|
+
<text fg={theme.text.muted}>{props.form.title}</text>
|
|
779
|
+
</box>
|
|
780
|
+
<Show when={message()}>
|
|
781
|
+
<box paddingLeft={1}>
|
|
782
|
+
<text fg={theme.text.base}>{message()}</text>
|
|
783
|
+
</box>
|
|
784
|
+
</Show>
|
|
785
|
+
<Show when={!single() && !tabbed()}>
|
|
786
|
+
<box flexDirection="row" gap={3} paddingLeft={1}>
|
|
787
|
+
<text fg={theme.text.muted}>
|
|
788
|
+
{confirm() ? "Review" : `Field ${Math.min(store.tab, fields().length - 1) + 1} of ${fields().length}`}
|
|
789
|
+
</text>
|
|
790
|
+
<Show when={fields().length > 0}>
|
|
791
|
+
<text fg={theme.text.muted}>
|
|
792
|
+
· {answered()}/{fields().length} completed
|
|
793
|
+
</text>
|
|
794
|
+
</Show>
|
|
795
|
+
</box>
|
|
796
|
+
</Show>
|
|
797
|
+
<Show when={!single() && tabbed()}>
|
|
798
|
+
<box flexDirection="row" paddingLeft={1}>
|
|
799
|
+
<For each={fields()}>
|
|
800
|
+
{(item, index) => {
|
|
801
|
+
const isTab = () => index() === store.tab
|
|
802
|
+
const color = () =>
|
|
803
|
+
isTab()
|
|
804
|
+
? theme.text.base
|
|
805
|
+
: tabHover() === index()
|
|
806
|
+
? theme.text.formfield.focused
|
|
807
|
+
: theme.text.muted
|
|
808
|
+
return (
|
|
809
|
+
<box
|
|
810
|
+
paddingRight={2}
|
|
811
|
+
backgroundColor={theme.background.raised.base}
|
|
812
|
+
onMouseOver={() => setTabHover(index())}
|
|
813
|
+
onMouseOut={() => setTabHover(null)}
|
|
814
|
+
onMouseUp={() => {
|
|
815
|
+
if (renderer.getSelection()?.getSelectedText()) return
|
|
816
|
+
selectTabFromMouse(item)
|
|
817
|
+
}}
|
|
818
|
+
>
|
|
819
|
+
<text fg={color()} attributes={isTab() ? TextAttributes.BOLD : undefined}>
|
|
820
|
+
{truncate(formLabel(item), 24)}
|
|
821
|
+
</text>
|
|
822
|
+
</box>
|
|
823
|
+
)
|
|
824
|
+
}}
|
|
825
|
+
</For>
|
|
826
|
+
<box
|
|
827
|
+
backgroundColor={theme.background.raised.base}
|
|
828
|
+
onMouseOver={() => setTabHover("confirm")}
|
|
829
|
+
onMouseOut={() => setTabHover(null)}
|
|
830
|
+
onMouseUp={() => {
|
|
831
|
+
if (renderer.getSelection()?.getSelectedText()) return
|
|
832
|
+
selectTabFromMouse()
|
|
833
|
+
}}
|
|
834
|
+
>
|
|
835
|
+
<text
|
|
836
|
+
fg={
|
|
837
|
+
confirm()
|
|
838
|
+
? theme.text.base
|
|
839
|
+
: tabHover() === "confirm"
|
|
840
|
+
? theme.text.formfield.focused
|
|
841
|
+
: theme.text.muted
|
|
842
|
+
}
|
|
843
|
+
attributes={confirm() ? TextAttributes.BOLD : undefined}
|
|
844
|
+
>
|
|
845
|
+
Submit
|
|
846
|
+
</text>
|
|
847
|
+
</box>
|
|
848
|
+
</box>
|
|
849
|
+
</Show>
|
|
850
|
+
|
|
851
|
+
<Show when={!confirm() && externalField()}>
|
|
852
|
+
{(external) => (
|
|
853
|
+
<box paddingLeft={1} gap={1}>
|
|
854
|
+
<Show when={external().title}>
|
|
855
|
+
<text fg={theme.text.base}>{external().title}</text>
|
|
856
|
+
</Show>
|
|
857
|
+
<Show when={external().description}>
|
|
858
|
+
<text fg={theme.text.muted}>{external().description}</text>
|
|
859
|
+
</Show>
|
|
860
|
+
<text
|
|
861
|
+
fg={theme.text.action.primary.base}
|
|
862
|
+
onMouseUp={() => {
|
|
863
|
+
if (renderer.getSelection()?.getSelectedText()) return
|
|
864
|
+
openExternal()
|
|
865
|
+
}}
|
|
866
|
+
>
|
|
867
|
+
{external().url}
|
|
868
|
+
</text>
|
|
869
|
+
<text
|
|
870
|
+
fg={store.answers[external().key] === true ? theme.text.feedback.success.base : theme.text.muted}
|
|
871
|
+
>
|
|
872
|
+
{store.answers[external().key] === true
|
|
873
|
+
? "✓ Acknowledged"
|
|
874
|
+
: store.externalReady[external().key]
|
|
875
|
+
? "Complete the external action, then press enter to confirm."
|
|
876
|
+
: "Open or copy the URL, complete the external action, then confirm."}
|
|
877
|
+
</text>
|
|
878
|
+
</box>
|
|
879
|
+
)}
|
|
880
|
+
</Show>
|
|
881
|
+
|
|
882
|
+
<Show when={!confirm() && answerField()}>
|
|
883
|
+
<box paddingLeft={1} gap={1}>
|
|
884
|
+
<box>
|
|
885
|
+
<text fg={theme.text.base}>{answerField()!.description ?? formLabel(answerField()!)}</text>
|
|
886
|
+
</box>
|
|
887
|
+
<Show when={textual() ? answerField()!.key : undefined} keyed>
|
|
888
|
+
<box paddingLeft={1}>
|
|
889
|
+
<textarea
|
|
890
|
+
cursorStyle={cursorStyle()}
|
|
891
|
+
ref={(val: TextareaRenderable) => {
|
|
892
|
+
textarea = val
|
|
893
|
+
val.traits = { status: "ANSWER" }
|
|
894
|
+
queueMicrotask(() => {
|
|
895
|
+
if (val.isDestroyed) return
|
|
896
|
+
val.gotoLineEnd()
|
|
897
|
+
setInputTarget(val)
|
|
898
|
+
})
|
|
899
|
+
}}
|
|
900
|
+
initialValue={
|
|
901
|
+
input() || formDisplayValue(answerField()!, store.answers[answerField()!.key], "(none)")
|
|
902
|
+
}
|
|
903
|
+
placeholder={placeholder()}
|
|
904
|
+
placeholderColor={theme.text.muted}
|
|
905
|
+
minHeight={1}
|
|
906
|
+
maxHeight={6}
|
|
907
|
+
textColor={theme.text.base}
|
|
908
|
+
focusedTextColor={theme.text.base}
|
|
909
|
+
cursorColor={theme.text.base}
|
|
910
|
+
/>
|
|
911
|
+
</box>
|
|
912
|
+
</Show>
|
|
913
|
+
<Show when={!textual()}>
|
|
914
|
+
<box>
|
|
915
|
+
<For each={rows()}>
|
|
916
|
+
{(row, i) => {
|
|
917
|
+
const active = () => i() === store.selected
|
|
918
|
+
const picked = () => {
|
|
919
|
+
const value = store.answers[answerField()?.key ?? ""]
|
|
920
|
+
if (Array.isArray(value)) return value.includes(String(row.value))
|
|
921
|
+
return value === row.value
|
|
922
|
+
}
|
|
923
|
+
return (
|
|
924
|
+
<box
|
|
925
|
+
onMouseMove={() => setStore("selected", i())}
|
|
926
|
+
onMouseDown={() => setStore("selected", i())}
|
|
927
|
+
onMouseUp={() => {
|
|
928
|
+
if (renderer.getSelection()?.getSelectedText()) return
|
|
929
|
+
selectOption()
|
|
930
|
+
}}
|
|
931
|
+
>
|
|
932
|
+
<box flexDirection="row">
|
|
933
|
+
<box
|
|
934
|
+
backgroundColor={theme.background.raised.base}
|
|
935
|
+
paddingRight={1}
|
|
936
|
+
>
|
|
937
|
+
<text
|
|
938
|
+
fg={active() ? theme.text.formfield.focused : theme.text.muted}
|
|
939
|
+
>{`${i() + 1}.`}</text>
|
|
940
|
+
</box>
|
|
941
|
+
<box
|
|
942
|
+
backgroundColor={theme.background.raised.base}
|
|
943
|
+
flexDirection="row"
|
|
944
|
+
>
|
|
945
|
+
<Show when={multi()}>
|
|
946
|
+
<text
|
|
947
|
+
width={4}
|
|
948
|
+
flexShrink={0}
|
|
949
|
+
fg={
|
|
950
|
+
active()
|
|
951
|
+
? theme.text.formfield.focused
|
|
952
|
+
: picked()
|
|
953
|
+
? theme.text.formfield.selected
|
|
954
|
+
: theme.text.muted
|
|
955
|
+
}
|
|
956
|
+
>
|
|
957
|
+
[{picked() ? "✓" : " "}]
|
|
958
|
+
</text>
|
|
959
|
+
</Show>
|
|
960
|
+
<text fg={active() ? theme.text.formfield.focused : theme.text.formfield.base}>
|
|
961
|
+
{row.label}
|
|
962
|
+
</text>
|
|
963
|
+
</box>
|
|
964
|
+
<Show when={!multi()}>
|
|
965
|
+
<text fg={theme.text.formfield.selected}>{picked() ? " ✓" : ""}</text>
|
|
966
|
+
</Show>
|
|
967
|
+
</box>
|
|
968
|
+
<Show when={row.description}>
|
|
969
|
+
<box paddingLeft={multi() ? 7 : 3}>
|
|
970
|
+
<text fg={theme.text.muted}>{row.description}</text>
|
|
971
|
+
</box>
|
|
972
|
+
</Show>
|
|
973
|
+
</box>
|
|
974
|
+
)
|
|
975
|
+
}}
|
|
976
|
+
</For>
|
|
977
|
+
<Show when={custom()}>
|
|
978
|
+
<box
|
|
979
|
+
onMouseMove={() => setStore("selected", rows().length)}
|
|
980
|
+
onMouseDown={() => setStore("selected", rows().length)}
|
|
981
|
+
onMouseUp={() => {
|
|
982
|
+
if (renderer.getSelection()?.getSelectedText()) return
|
|
983
|
+
selectOption()
|
|
984
|
+
}}
|
|
985
|
+
>
|
|
986
|
+
<box flexDirection="row">
|
|
987
|
+
<box
|
|
988
|
+
backgroundColor={theme.background.raised.base}
|
|
989
|
+
paddingRight={1}
|
|
990
|
+
>
|
|
991
|
+
<text fg={other() ? theme.text.formfield.focused : theme.text.muted}>
|
|
992
|
+
{`${rows().length + 1}.`}
|
|
993
|
+
</text>
|
|
994
|
+
</box>
|
|
995
|
+
<box
|
|
996
|
+
flexDirection="row"
|
|
997
|
+
flexGrow={1}
|
|
998
|
+
backgroundColor={theme.background.raised.base}
|
|
999
|
+
>
|
|
1000
|
+
<Show when={multi()}>
|
|
1001
|
+
<text
|
|
1002
|
+
width={4}
|
|
1003
|
+
flexShrink={0}
|
|
1004
|
+
fg={
|
|
1005
|
+
other()
|
|
1006
|
+
? theme.text.formfield.focused
|
|
1007
|
+
: customChecked()
|
|
1008
|
+
? theme.text.formfield.selected
|
|
1009
|
+
: theme.text.muted
|
|
1010
|
+
}
|
|
1011
|
+
>
|
|
1012
|
+
[{customChecked() ? "✓" : " "}]
|
|
1013
|
+
</text>
|
|
1014
|
+
</Show>
|
|
1015
|
+
<Show
|
|
1016
|
+
when={store.editing}
|
|
1017
|
+
fallback={
|
|
1018
|
+
<>
|
|
1019
|
+
<text fg={other() ? theme.text.formfield.focused : theme.text.formfield.base}>
|
|
1020
|
+
{input() || "Type your own answer"}
|
|
1021
|
+
</text>
|
|
1022
|
+
<Show when={!multi() && customPicked()}>
|
|
1023
|
+
<text fg={theme.text.formfield.selected}>✓</text>
|
|
1024
|
+
</Show>
|
|
1025
|
+
</>
|
|
1026
|
+
}
|
|
1027
|
+
>
|
|
1028
|
+
<textarea
|
|
1029
|
+
flexGrow={1}
|
|
1030
|
+
cursorStyle={cursorStyle()}
|
|
1031
|
+
ref={(val: TextareaRenderable) => {
|
|
1032
|
+
textarea = val
|
|
1033
|
+
val.traits = { status: "ANSWER" }
|
|
1034
|
+
queueMicrotask(() => {
|
|
1035
|
+
if (val.isDestroyed) return
|
|
1036
|
+
val.setText(input())
|
|
1037
|
+
val.gotoLineEnd()
|
|
1038
|
+
setInputTarget(val)
|
|
1039
|
+
})
|
|
1040
|
+
}}
|
|
1041
|
+
initialValue={input()}
|
|
1042
|
+
placeholder="Type your own answer"
|
|
1043
|
+
placeholderColor={theme.text.muted}
|
|
1044
|
+
minHeight={1}
|
|
1045
|
+
maxHeight={6}
|
|
1046
|
+
textColor={theme.text.formfield.focused}
|
|
1047
|
+
focusedTextColor={theme.text.formfield.focused}
|
|
1048
|
+
cursorColor={theme.text.formfield.focused}
|
|
1049
|
+
onContentChange={(value) => {
|
|
1050
|
+
const current = answerField()
|
|
1051
|
+
if (!current || !textarea || textarea.isDestroyed) return
|
|
1052
|
+
updateCustom(current, typeof value === "string" ? value : textarea.plainText)
|
|
1053
|
+
}}
|
|
1054
|
+
/>
|
|
1055
|
+
</Show>
|
|
1056
|
+
</box>
|
|
1057
|
+
</box>
|
|
1058
|
+
</box>
|
|
1059
|
+
</Show>
|
|
1060
|
+
</box>
|
|
1061
|
+
</Show>
|
|
1062
|
+
</box>
|
|
1063
|
+
</Show>
|
|
1064
|
+
|
|
1065
|
+
<Show when={confirm()}>
|
|
1066
|
+
<scrollbox
|
|
1067
|
+
maxHeight={reviewMaxHeight()}
|
|
1068
|
+
contentOptions={{ minHeight: 0 }}
|
|
1069
|
+
scrollbarOptions={{ visible: false }}
|
|
1070
|
+
ref={(r: ScrollBoxRenderable) => (review = r)}
|
|
1071
|
+
>
|
|
1072
|
+
<box
|
|
1073
|
+
onSizeChange={function (this: BoxRenderable) {
|
|
1074
|
+
setReviewContentHeight(this.height)
|
|
1075
|
+
}}
|
|
1076
|
+
>
|
|
1077
|
+
<For each={fields()}>
|
|
1078
|
+
{(item) => {
|
|
1079
|
+
if (item.type === "external") {
|
|
1080
|
+
const acknowledged = () => store.answers[item.key] === true
|
|
1081
|
+
return (
|
|
1082
|
+
<box paddingLeft={1}>
|
|
1083
|
+
<text>
|
|
1084
|
+
<span style={{ fg: theme.text.muted }}>{truncate(formLabel(item), 40)}:</span>{" "}
|
|
1085
|
+
<span
|
|
1086
|
+
style={{
|
|
1087
|
+
fg: acknowledged()
|
|
1088
|
+
? theme.text.feedback.success.base
|
|
1089
|
+
: theme.text.feedback.error.base,
|
|
1090
|
+
}}
|
|
1091
|
+
>
|
|
1092
|
+
{acknowledged() ? "Acknowledged" : "(acknowledgement required)"}
|
|
1093
|
+
</span>
|
|
1094
|
+
</text>
|
|
1095
|
+
</box>
|
|
1096
|
+
)
|
|
1097
|
+
}
|
|
1098
|
+
const value = () => formDisplayValue(item, store.answers[item.key], "(none)")
|
|
1099
|
+
const answered = () => store.answers[item.key] !== undefined
|
|
1100
|
+
const missing = () => !answered() && item.required === true
|
|
1101
|
+
const invalid = () => formValidateValue(item, store.answers[item.key])
|
|
1102
|
+
return (
|
|
1103
|
+
<box paddingLeft={1}>
|
|
1104
|
+
<text>
|
|
1105
|
+
<span style={{ fg: theme.text.muted }}>{truncate(formLabel(item), 40)}:</span>{" "}
|
|
1106
|
+
<span
|
|
1107
|
+
style={{
|
|
1108
|
+
fg:
|
|
1109
|
+
invalid() || missing()
|
|
1110
|
+
? theme.text.feedback.error.base
|
|
1111
|
+
: answered()
|
|
1112
|
+
? theme.text.base
|
|
1113
|
+
: theme.text.muted,
|
|
1114
|
+
}}
|
|
1115
|
+
>
|
|
1116
|
+
{invalid() ?? (answered() ? value() : missing() ? "(required)" : "(not answered)")}
|
|
1117
|
+
</span>
|
|
1118
|
+
</text>
|
|
1119
|
+
</box>
|
|
1120
|
+
)
|
|
1121
|
+
}}
|
|
1122
|
+
</For>
|
|
1123
|
+
</box>
|
|
1124
|
+
</scrollbox>
|
|
1125
|
+
</Show>
|
|
1126
|
+
</box>
|
|
1127
|
+
<box
|
|
1128
|
+
flexDirection="row"
|
|
1129
|
+
flexShrink={0}
|
|
1130
|
+
gap={1}
|
|
1131
|
+
paddingLeft={2}
|
|
1132
|
+
paddingRight={3}
|
|
1133
|
+
paddingBottom={1}
|
|
1134
|
+
justifyContent="space-between"
|
|
1135
|
+
>
|
|
1136
|
+
<box flexDirection="row" gap={2}>
|
|
1137
|
+
<Show when={!single()}>
|
|
1138
|
+
<text fg={theme.text.base}>
|
|
1139
|
+
{"⇆"} <span style={{ fg: theme.text.muted }}>tab</span>
|
|
1140
|
+
</text>
|
|
1141
|
+
</Show>
|
|
1142
|
+
<Show when={!confirm() && !textual() && !externalField() && !store.editing}>
|
|
1143
|
+
<text fg={theme.text.base}>
|
|
1144
|
+
{"↑↓"} <span style={{ fg: theme.text.muted }}>select</span>
|
|
1145
|
+
</text>
|
|
1146
|
+
</Show>
|
|
1147
|
+
<Show when={confirm() && reviewContentHeight() > reviewMaxHeight()}>
|
|
1148
|
+
<text fg={theme.text.base}>
|
|
1149
|
+
{"↑↓"} <span style={{ fg: theme.text.muted }}>scroll</span>
|
|
1150
|
+
</text>
|
|
1151
|
+
</Show>
|
|
1152
|
+
<text
|
|
1153
|
+
fg={theme.text.base}
|
|
1154
|
+
onMouseUp={() => {
|
|
1155
|
+
if (renderer.getSelection()?.getSelectedText()) return
|
|
1156
|
+
if (confirm()) submit()
|
|
1157
|
+
if (externalField()) acknowledgeExternal()
|
|
1158
|
+
}}
|
|
1159
|
+
>
|
|
1160
|
+
enter <span style={{ fg: theme.text.muted }}>{actionLabel()}</span>
|
|
1161
|
+
</text>
|
|
1162
|
+
<Show when={externalField()}>
|
|
1163
|
+
<text fg={theme.text.base} onMouseUp={copyExternal}>
|
|
1164
|
+
c <span style={{ fg: theme.text.muted }}>copy</span>
|
|
1165
|
+
</text>
|
|
1166
|
+
</Show>
|
|
1167
|
+
<text fg={theme.text.base} onMouseUp={cancel}>
|
|
1168
|
+
esc <span style={{ fg: theme.text.muted }}>{store.editing && !textual() ? "close" : "dismiss"}</span>
|
|
1169
|
+
</text>
|
|
1170
|
+
</box>
|
|
1171
|
+
<Show when={store.error}>
|
|
1172
|
+
<text fg={theme.text.feedback.error.base}>{store.error}</text>
|
|
1173
|
+
</Show>
|
|
1174
|
+
</box>
|
|
1175
|
+
</box>
|
|
1176
|
+
)
|
|
1177
|
+
}
|