Files
windmill/frontend/src/lib/components/PrefixedInput.svelte
wendrul 3dadcbe865 feat: forkables workspaces v0 (#6479)
* Add create_ephemeral workspace endpoint

* Add cli devShell

* List ephemeral workspaces + improve endpoint

* Add postgres function to clone a workspace (to be revisited)

* Clone workspace using the postgres function

* Add first iteration of ephemeral workspaces command

* Update display of forked workspaces

* Remove SQLX_OFFLINE

* Add UI to create ephemeral workspace

* Add option to exclude repository from being inherited to forks

* WIP: reworking cloning logic

* Fix cloning

* Fix redirect after creating fork

* Clean up cloning behaviour

* Rename ephemeral to fork

* emove ephemeral_workspaces table in favour of columns in  workspaces

* Fix display of forked workspaces

* Fix skip inherit git sync repo setting

* Fix fork invite display + creating fork as user

* Fix SideMenu bug

* Fix alignment

* Simplify migrations

* Update deletion of workspaces

* Delete forked workspace from cli

* Deleting fork workspaces from the UI as non-admin

* Update cli sync and fork creation to adapt to branches and forks

* Update fork prefix

* Remove skip tracking toggle

* Fix npm check warnings

* Fix last npm check

* fix: force stdin to Stdio::null for all user code execution (#6575)

Set stdin to Stdio::null for all Commands that execute user code across all supported languages to prevent unwanted input consumption. This affects Python, Deno, Bash, PowerShell, Go, Rust, PHP, Ruby, Java, C#, Ansible, Nu, and Bun executors.

The dedicated worker handler was intentionally left unchanged as it requires stdin for inter-process communication.

Co-authored-by: claude[bot] <209825114+claude[bot]@users.noreply.github.com>
Co-authored-by: windmill-internal-app[bot] <windmill-internal-app[bot]@users.noreply.github.com>

* Update ee-repo ref

* Update SQLx metadata

* Fix typos

---------

Co-authored-by: claude[bot] <209825114+claude[bot]@users.noreply.github.com>
Co-authored-by: windmill-internal-app[bot] <windmill-internal-app[bot]@users.noreply.github.com>
2025-09-10 17:42:45 +00:00

139 lines
3.6 KiB
Svelte

<script lang="ts">
let {
prefix = '',
value = $bindable(''),
placeholder = '',
class: className = '',
...restProps
} = $props()
let inputElement: HTMLInputElement = $state(null!)
let internalValue = $state(prefix + value)
// Update internal value when prop changes
$effect(() => {
internalValue = prefix + value
})
function handleInput(e) {
const newValue = e.target.value
// Ensure the value always starts with the prefix
if (newValue.startsWith(prefix)) {
internalValue = newValue
value = newValue.slice(prefix.length)
} else {
internalValue = prefix
value = ''
// Reset cursor position
if (inputElement) {
inputElement.value = prefix
inputElement.setSelectionRange(prefix.length, prefix.length)
}
}
}
function handleKeyDown(e) {
const cursorPos = e.target.selectionStart
const selectionEnd = e.target.selectionEnd
// Prevent backspace if cursor is at or before prefix end
if (e.key === 'Backspace') {
if (cursorPos <= prefix.length && selectionEnd <= prefix.length) {
e.preventDefault()
} else if (cursorPos <= prefix.length && selectionEnd > prefix.length) {
// If selection spans across prefix, only delete after prefix
e.preventDefault()
const newValue = prefix + internalValue.slice(selectionEnd)
internalValue = newValue
value = newValue.slice(prefix.length)
// Set cursor position after prefix
setTimeout(() => {
inputElement.setSelectionRange(prefix.length, prefix.length)
}, 0)
}
}
// Prevent delete key within prefix
if (e.key === 'Delete' && cursorPos < prefix.length) {
e.preventDefault()
}
// Prevent selecting all (Ctrl+A) from selecting the prefix
if ((e.ctrlKey || e.metaKey) && e.key === 'a') {
e.preventDefault()
inputElement.setSelectionRange(prefix.length, internalValue.length)
}
}
function handleClick() {
// Prevent cursor from being placed within prefix
if ((inputElement.selectionStart ?? 0) < prefix.length) {
inputElement.setSelectionRange(prefix.length, prefix.length)
}
}
function handleFocus() {
// Ensure cursor starts after prefix when focusing
if ((inputElement.selectionStart ?? 0) < prefix.length) {
inputElement.setSelectionRange(prefix.length, prefix.length)
}
}
function handlePaste(e) {
e.preventDefault()
const pasteData = e.clipboardData.getData('text')
const cursorPos = inputElement.selectionStart ?? 0
const selectionEnd = inputElement.selectionEnd ?? 0
if (cursorPos < prefix.length) {
// Paste at the end of prefix
internalValue = prefix + pasteData + internalValue.slice(prefix.length)
} else {
// Normal paste
internalValue =
internalValue.slice(0, cursorPos) + pasteData + internalValue.slice(selectionEnd)
}
value = internalValue.slice(prefix.length)
// Set cursor position after pasted content
const newCursorPos = Math.max(prefix.length, cursorPos) + pasteData.length
setTimeout(() => {
inputElement.setSelectionRange(newCursorPos, newCursorPos)
}, 0)
}
</script>
<input
bind:this={inputElement}
type="text"
{placeholder}
class="prefixed-input {className}"
value={internalValue}
oninput={handleInput}
onkeydown={handleKeyDown}
onclick={handleClick}
onfocus={handleFocus}
onpaste={handlePaste}
{...restProps}
/>
<style>
.prefixed-input {
/* Default styles - can be overridden by class prop */
padding: 8px 12px;
border: 1px solid #ccc;
border-radius: 4px;
font-size: 14px;
width: 100%;
box-sizing: border-box;
}
.prefixed-input:focus {
outline: none;
border-color: #4caf50;
box-shadow: 0 0 0 2px rgba(76, 175, 80, 0.1);
}
</style>