@flowdrop/flowdrop 2.9.0 → 2.10.0
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/CHANGELOG.md +187 -0
- package/dist/commands/executor.js +52 -8
- package/dist/commands/types.d.ts +3 -0
- package/dist/components/App.svelte +8 -0
- package/dist/components/App.svelte.d.ts +6 -0
- package/dist/components/CanvasContextMenu.stories.svelte +63 -0
- package/dist/components/CanvasContextMenu.stories.svelte.d.ts +19 -0
- package/dist/components/CanvasContextMenu.svelte +259 -0
- package/dist/components/CanvasContextMenu.svelte.d.ts +16 -0
- package/dist/components/CanvasController.svelte +23 -1
- package/dist/components/CanvasController.svelte.d.ts +16 -0
- package/dist/components/UniversalNode.svelte +12 -13
- package/dist/components/WorkflowEditor.svelte +364 -27
- package/dist/components/WorkflowEditor.svelte.d.ts +7 -0
- package/dist/components/WorkflowInterfaceEditor.svelte +28 -3
- package/dist/components/WorkflowInterfaceEntryCard.svelte +112 -2
- package/dist/components/WorkflowInterfaceEntryCard.svelte.d.ts +3 -1
- package/dist/components/nodes/CaptionNode.stories.svelte +65 -0
- package/dist/components/nodes/CaptionNode.stories.svelte.d.ts +18 -0
- package/dist/components/nodes/CaptionNode.svelte +313 -0
- package/dist/components/nodes/CaptionNode.svelte.d.ts +16 -0
- package/dist/components/nodes/NotesNode.svelte +6 -0
- package/dist/components/playground/ChatBubble.svelte +2 -0
- package/dist/components/playground/ChatInput.svelte +18 -34
- package/dist/components/playground/ChatInput.svelte.d.ts +7 -0
- package/dist/components/playground/ControlPanel.svelte +27 -0
- package/dist/components/playground/ControlPanel.svelte.d.ts +12 -0
- package/dist/components/playground/ExecutionLogs.svelte +11 -8
- package/dist/components/playground/InterfaceInputForm.svelte +74 -0
- package/dist/components/playground/InterfaceInputForm.svelte.d.ts +14 -0
- package/dist/components/playground/LogRow.svelte +2 -0
- package/dist/components/playground/MessageCard.svelte +15 -3
- package/dist/components/playground/MessageNotice.svelte +2 -0
- package/dist/components/playground/MessageStream.svelte +87 -23
- package/dist/components/playground/OriginBadge.svelte +48 -0
- package/dist/components/playground/OriginBadge.svelte.d.ts +7 -0
- package/dist/components/playground/Playground.svelte +155 -38
- package/dist/components/playground/messageDisplay.d.ts +23 -1
- package/dist/components/playground/messageDisplay.js +49 -0
- package/dist/config/endpoints.d.ts +65 -0
- package/dist/config/endpoints.js +39 -0
- package/dist/core/index.d.ts +6 -3
- package/dist/core/index.js +2 -1
- package/dist/editor/contextMenu.d.ts +107 -0
- package/dist/editor/contextMenu.js +134 -0
- package/dist/editor/index.d.ts +2 -0
- package/dist/editor/index.js +1 -0
- package/dist/index.d.ts +1 -1
- package/dist/index.js +1 -1
- package/dist/messages/defaults.d.ts +63 -0
- package/dist/messages/defaults.js +59 -0
- package/dist/openapi/v1/openapi.yaml +356 -7
- package/dist/playground/commands/registry.js +4 -2
- package/dist/playground/index.d.ts +3 -2
- package/dist/playground/index.js +2 -1
- package/dist/registry/builtinNodeTypes.d.ts +1 -1
- package/dist/registry/builtinNodeTypes.js +1 -0
- package/dist/registry/builtinNodes.js +13 -0
- package/dist/registry/nodeComponentRegistry.d.ts +18 -0
- package/dist/registry/nodeComponentRegistry.js +14 -2
- package/dist/schemas/v1/workflow.schema.json +22 -1
- package/dist/services/historyService.d.ts +1 -1
- package/dist/services/historyService.js +2 -2
- package/dist/services/playgroundService.d.ts +35 -1
- package/dist/services/playgroundService.js +82 -36
- package/dist/stores/inlineEditStore.svelte.d.ts +35 -0
- package/dist/stores/inlineEditStore.svelte.js +63 -0
- package/dist/stores/instanceContainer.svelte.d.ts +6 -0
- package/dist/stores/instanceContainer.svelte.js +2 -0
- package/dist/stores/playgroundStore.svelte.d.ts +59 -2
- package/dist/stores/playgroundStore.svelte.js +128 -2
- package/dist/styles/base.css +8 -0
- package/dist/styles/tokens.css +8 -0
- package/dist/svelte-app.d.ts +15 -0
- package/dist/svelte-app.js +6 -4
- package/dist/types/index.d.ts +34 -1
- package/dist/types/index.js +11 -0
- package/dist/types/playground.d.ts +90 -9
- package/dist/types/playground.js +12 -4
- package/dist/utils/captionText.d.ts +43 -0
- package/dist/utils/captionText.js +49 -0
- package/dist/utils/focus.d.ts +16 -0
- package/dist/utils/focus.js +40 -0
- package/dist/utils/nodeTypes.js +1 -0
- package/dist/utils/nodeWrapper.js +2 -0
- package/dist/utils/workflowInterface.d.ts +83 -1
- package/dist/utils/workflowInterface.js +192 -1
- package/package.json +1 -1
|
@@ -28,12 +28,21 @@
|
|
|
28
28
|
import PortShapeSymbol from './ports/PortShapeSymbol.svelte';
|
|
29
29
|
import PortLaneChip from './ports/PortLaneChip.svelte';
|
|
30
30
|
import { m } from '../messages/index.js';
|
|
31
|
-
import
|
|
31
|
+
import {
|
|
32
|
+
DEFAULT_HISTORY_TURN_LIMIT,
|
|
33
|
+
type PortDataTypeConfig,
|
|
34
|
+
type WorkflowInterfaceEntry
|
|
35
|
+
} from '../types/index.js';
|
|
32
36
|
import type { PortCompatibilityChecker } from '../utils/connections.js';
|
|
33
37
|
import {
|
|
34
38
|
bindablePortKey,
|
|
35
39
|
describeInterfaceEntryStatus,
|
|
40
|
+
historyLimitOf,
|
|
41
|
+
historyLimitPatch,
|
|
42
|
+
isKnownTurn,
|
|
36
43
|
pullEntryFieldsFromPort,
|
|
44
|
+
turnPatch,
|
|
45
|
+
turnsFor,
|
|
37
46
|
type RankedBindablePort,
|
|
38
47
|
type InterfaceIssue,
|
|
39
48
|
type ResolvedInterfaceEntry
|
|
@@ -55,6 +64,8 @@
|
|
|
55
64
|
alreadyConnected?: boolean;
|
|
56
65
|
/** Label of the node feeding that competing edge, when there is one. */
|
|
57
66
|
conflictingSource?: string;
|
|
67
|
+
/** Input side only: the id of another input that already has this entry's turn. */
|
|
68
|
+
turnTakenBy?: string;
|
|
58
69
|
isFirst: boolean;
|
|
59
70
|
isLast: boolean;
|
|
60
71
|
onPatch: (patch: Partial<WorkflowInterfaceEntry>) => void;
|
|
@@ -72,6 +83,7 @@
|
|
|
72
83
|
footerIssues,
|
|
73
84
|
alreadyConnected = false,
|
|
74
85
|
conflictingSource,
|
|
86
|
+
turnTakenBy,
|
|
75
87
|
isFirst,
|
|
76
88
|
isLast,
|
|
77
89
|
onPatch,
|
|
@@ -86,7 +98,7 @@
|
|
|
86
98
|
*/
|
|
87
99
|
// The seed is meant to be read once.
|
|
88
100
|
// svelte-ignore state_referenced_locally
|
|
89
|
-
let fieldsOpen = $state(status?.status === 'type-mismatch');
|
|
101
|
+
let fieldsOpen = $state(status?.status === 'type-mismatch' || turnTakenBy !== undefined);
|
|
90
102
|
|
|
91
103
|
/** Statuses still explained in the footer (the rest render inline or as the dot). */
|
|
92
104
|
const FOOTER_STATUSES = new Set(['unbound', 'dangling', 'hidden', 'over-bound']);
|
|
@@ -106,6 +118,40 @@
|
|
|
106
118
|
return options;
|
|
107
119
|
}
|
|
108
120
|
|
|
121
|
+
/**
|
|
122
|
+
* Chat turn options for this direction. A stored value outside them — one
|
|
123
|
+
* from a newer server, or a value of the other direction — is listed too,
|
|
124
|
+
* so the select shows what is stored and never silently rewrites it.
|
|
125
|
+
*/
|
|
126
|
+
const turnOptions = $derived.by(() => {
|
|
127
|
+
const options: Array<{ value: string; label: string }> = turnsFor(
|
|
128
|
+
isInput ? 'input' : 'output'
|
|
129
|
+
).map((value) => ({ value, label: m().workflowInterface.turns[value] }));
|
|
130
|
+
const current = entry.turn;
|
|
131
|
+
if (current !== undefined && !options.some((option) => option.value === current)) {
|
|
132
|
+
options.push({
|
|
133
|
+
value: current,
|
|
134
|
+
label: isKnownTurn(current)
|
|
135
|
+
? m().workflowInterface.turns[current]
|
|
136
|
+
: m().workflowInterface.turnUnknown({ value: current })
|
|
137
|
+
});
|
|
138
|
+
}
|
|
139
|
+
return options;
|
|
140
|
+
});
|
|
141
|
+
|
|
142
|
+
/** The current turn's one-line description, when it is a known value. */
|
|
143
|
+
const turnDescription = $derived(
|
|
144
|
+
entry.turn !== undefined && isKnownTurn(entry.turn)
|
|
145
|
+
? m().workflowInterface.turnDescriptions[entry.turn]
|
|
146
|
+
: undefined
|
|
147
|
+
);
|
|
148
|
+
|
|
149
|
+
function setTurn(value: string): void {
|
|
150
|
+
// Only values the select offers reach here: the direction's vocabulary,
|
|
151
|
+
// '' for none, or the stored value itself (a no-op patch).
|
|
152
|
+
onPatch(turnPatch(entry, value));
|
|
153
|
+
}
|
|
154
|
+
|
|
109
155
|
/** Whether the binding picker is unfolded under the "Bound port" control. */
|
|
110
156
|
let pickerOpen = $state(false);
|
|
111
157
|
|
|
@@ -312,8 +358,53 @@
|
|
|
312
358
|
<summary>
|
|
313
359
|
<Icon icon="heroicons:chevron-right" />
|
|
314
360
|
{m().workflowInterface.moreOptions}
|
|
361
|
+
{#if entry.turn !== undefined}
|
|
362
|
+
<span class="wf-interface__turn-chip">
|
|
363
|
+
{isKnownTurn(entry.turn) ? m().workflowInterface.turns[entry.turn] : entry.turn}
|
|
364
|
+
</span>
|
|
365
|
+
{/if}
|
|
315
366
|
</summary>
|
|
316
367
|
<div class="wf-interface__more-body">
|
|
368
|
+
<div class="wf-interface__row">
|
|
369
|
+
<label class="wf-interface__field">
|
|
370
|
+
<span class="wf-interface__label">{m().workflowInterface.turnLabel}</span>
|
|
371
|
+
<Select
|
|
372
|
+
size="sm"
|
|
373
|
+
invalid={turnTakenBy !== undefined}
|
|
374
|
+
value={entry.turn ?? ''}
|
|
375
|
+
onchange={(e) => setTurn(e.currentTarget.value)}
|
|
376
|
+
>
|
|
377
|
+
<option value="">{m().workflowInterface.turnNone}</option>
|
|
378
|
+
{#each turnOptions as option (option.value)}
|
|
379
|
+
<option value={option.value}>{option.label}</option>
|
|
380
|
+
{/each}
|
|
381
|
+
</Select>
|
|
382
|
+
{#if turnTakenBy !== undefined}
|
|
383
|
+
<span class="wf-interface__inline wf-interface__inline--warning">
|
|
384
|
+
{m().workflowInterface.turnTakenInline({ id: turnTakenBy })}
|
|
385
|
+
</span>
|
|
386
|
+
{:else if turnDescription}
|
|
387
|
+
<span class="wf-interface__hint">{turnDescription}</span>
|
|
388
|
+
{/if}
|
|
389
|
+
</label>
|
|
390
|
+
{#if entry.turn === 'history'}
|
|
391
|
+
<label class="wf-interface__field">
|
|
392
|
+
<span class="wf-interface__label">{m().workflowInterface.historyLimitLabel}</span>
|
|
393
|
+
<Input
|
|
394
|
+
size="sm"
|
|
395
|
+
type="number"
|
|
396
|
+
min="1"
|
|
397
|
+
step="1"
|
|
398
|
+
value={historyLimitOf(entry) ?? ''}
|
|
399
|
+
placeholder={m().workflowInterface.historyLimitPlaceholder({
|
|
400
|
+
limit: DEFAULT_HISTORY_TURN_LIMIT
|
|
401
|
+
})}
|
|
402
|
+
onchange={(e) => onPatch(historyLimitPatch(entry, e.currentTarget.value))}
|
|
403
|
+
/>
|
|
404
|
+
</label>
|
|
405
|
+
{/if}
|
|
406
|
+
</div>
|
|
407
|
+
|
|
317
408
|
{#if boundTarget}
|
|
318
409
|
<div class="wf-interface__pull-row">
|
|
319
410
|
<Button
|
|
@@ -737,6 +828,25 @@
|
|
|
737
828
|
line-height: 1.4;
|
|
738
829
|
}
|
|
739
830
|
|
|
831
|
+
.wf-interface__hint {
|
|
832
|
+
font-size: var(--fd-text-xs);
|
|
833
|
+
line-height: 1.4;
|
|
834
|
+
color: var(--fd-muted-foreground);
|
|
835
|
+
}
|
|
836
|
+
|
|
837
|
+
/* The entry's chat turn, said at rest on the disclosure's summary. */
|
|
838
|
+
.wf-interface__turn-chip {
|
|
839
|
+
margin-left: var(--fd-space-xs);
|
|
840
|
+
padding: 0 var(--fd-space-xs);
|
|
841
|
+
border: 1px solid var(--fd-border);
|
|
842
|
+
border-radius: var(--fd-radius-full);
|
|
843
|
+
background-color: var(--fd-muted);
|
|
844
|
+
color: var(--fd-foreground);
|
|
845
|
+
font-size: var(--fd-text-2xs);
|
|
846
|
+
font-weight: 600;
|
|
847
|
+
line-height: 1.5;
|
|
848
|
+
}
|
|
849
|
+
|
|
740
850
|
.wf-interface__inline--warning {
|
|
741
851
|
color: var(--fd-warning);
|
|
742
852
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type
|
|
1
|
+
import { type PortDataTypeConfig, type WorkflowInterfaceEntry } from '../types/index.js';
|
|
2
2
|
import type { PortCompatibilityChecker } from '../utils/connections.js';
|
|
3
3
|
import { type RankedBindablePort, type InterfaceIssue, type ResolvedInterfaceEntry } from '../utils/workflowInterface.js';
|
|
4
4
|
interface Props {
|
|
@@ -17,6 +17,8 @@ interface Props {
|
|
|
17
17
|
alreadyConnected?: boolean;
|
|
18
18
|
/** Label of the node feeding that competing edge, when there is one. */
|
|
19
19
|
conflictingSource?: string;
|
|
20
|
+
/** Input side only: the id of another input that already has this entry's turn. */
|
|
21
|
+
turnTakenBy?: string;
|
|
20
22
|
isFirst: boolean;
|
|
21
23
|
isLast: boolean;
|
|
22
24
|
onPatch: (patch: Partial<WorkflowInterfaceEntry>) => void;
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
<script module lang="ts">
|
|
2
|
+
import { defineMeta } from '@storybook/addon-svelte-csf';
|
|
3
|
+
import NodeDecorator from '../../stories/NodeDecorator.svelte';
|
|
4
|
+
|
|
5
|
+
const { Story } = defineMeta({
|
|
6
|
+
title: 'Nodes/CaptionNode',
|
|
7
|
+
tags: ['autodocs'],
|
|
8
|
+
parameters: {
|
|
9
|
+
layout: 'centered'
|
|
10
|
+
}
|
|
11
|
+
});
|
|
12
|
+
|
|
13
|
+
/** Node data for a caption with the given text. */
|
|
14
|
+
function caption(label: string) {
|
|
15
|
+
return {
|
|
16
|
+
label,
|
|
17
|
+
config: {},
|
|
18
|
+
metadata: {
|
|
19
|
+
node_type_id: 'caption',
|
|
20
|
+
name: 'Caption',
|
|
21
|
+
description: 'Short high-contrast text that names or marks nearby nodes',
|
|
22
|
+
category: 'tools',
|
|
23
|
+
version: '1.0.0',
|
|
24
|
+
type: 'caption',
|
|
25
|
+
supportedTypes: ['caption'],
|
|
26
|
+
inputs: [],
|
|
27
|
+
outputs: []
|
|
28
|
+
}
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
</script>
|
|
32
|
+
|
|
33
|
+
<Story name="Tiny">
|
|
34
|
+
<NodeDecorator data={caption('A')} />
|
|
35
|
+
</Story>
|
|
36
|
+
|
|
37
|
+
<Story name="Section">
|
|
38
|
+
<NodeDecorator data={caption('Inputs')} />
|
|
39
|
+
</Story>
|
|
40
|
+
|
|
41
|
+
<Story name="Reminder">
|
|
42
|
+
<NodeDecorator data={caption('TODO: retry on 429')} />
|
|
43
|
+
</Story>
|
|
44
|
+
|
|
45
|
+
<Story name="Two lines">
|
|
46
|
+
<NodeDecorator
|
|
47
|
+
data={caption(
|
|
48
|
+
'Everything to the right of this caption runs once per customer record, in the order they arrive'
|
|
49
|
+
)}
|
|
50
|
+
/>
|
|
51
|
+
</Story>
|
|
52
|
+
|
|
53
|
+
<Story name="Too long (clamped)">
|
|
54
|
+
<NodeDecorator
|
|
55
|
+
data={caption(
|
|
56
|
+
'This caption is far too long for two lines of a five hundred pixel wide label so the clamp has to cut it off with an ellipsis and keep the full text in the tooltip instead of growing taller'
|
|
57
|
+
)}
|
|
58
|
+
/>
|
|
59
|
+
</Story>
|
|
60
|
+
|
|
61
|
+
<Story name="Dark theme">
|
|
62
|
+
<div data-theme="dark" style="background: #1a1a1e; padding: 8px;">
|
|
63
|
+
<NodeDecorator data={caption('Inputs')} />
|
|
64
|
+
</div>
|
|
65
|
+
</Story>
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
interface $$__sveltets_2_IsomorphicComponent<Props extends Record<string, any> = any, Events extends Record<string, any> = any, Slots extends Record<string, any> = any, Exports = {}, Bindings = string> {
|
|
2
|
+
new (options: import('svelte').ComponentConstructorOptions<Props>): import('svelte').SvelteComponent<Props, Events, Slots> & {
|
|
3
|
+
$$bindings?: Bindings;
|
|
4
|
+
} & Exports;
|
|
5
|
+
(internal: unknown, props: {
|
|
6
|
+
$$events?: Events;
|
|
7
|
+
$$slots?: Slots;
|
|
8
|
+
}): Exports & {
|
|
9
|
+
$set?: any;
|
|
10
|
+
$on?: any;
|
|
11
|
+
};
|
|
12
|
+
z_$$bindings?: Bindings;
|
|
13
|
+
}
|
|
14
|
+
declare const CaptionNode: $$__sveltets_2_IsomorphicComponent<Record<string, never>, {
|
|
15
|
+
[evt: string]: CustomEvent<any>;
|
|
16
|
+
}, {}, {}, string>;
|
|
17
|
+
type CaptionNode = InstanceType<typeof CaptionNode>;
|
|
18
|
+
export default CaptionNode;
|
|
@@ -0,0 +1,313 @@
|
|
|
1
|
+
<!--
|
|
2
|
+
Caption Node Component
|
|
3
|
+
|
|
4
|
+
A short, high-contrast line of text (one or two lines) that names or marks
|
|
5
|
+
nearby nodes. Text lives in `data.label`. It has no ports, no config panel
|
|
6
|
+
and no status overlay; it is edited in place (double-click, Enter on the
|
|
7
|
+
focused node, or the context menu) and the editor owns the write through
|
|
8
|
+
`data.onInlineCommit`.
|
|
9
|
+
-->
|
|
10
|
+
|
|
11
|
+
<script lang="ts">
|
|
12
|
+
import { tick, untrack } from 'svelte';
|
|
13
|
+
import type { Attachment } from 'svelte/attachments';
|
|
14
|
+
import { on } from 'svelte/events';
|
|
15
|
+
import { m } from '../../messages/index.js';
|
|
16
|
+
import { getInstance } from '../../stores/getInstance.svelte.js';
|
|
17
|
+
import { getEditorSettings } from '../../stores/settingsStore.svelte.js';
|
|
18
|
+
import { snapCaptionWidth } from '../../utils/captionText.js';
|
|
19
|
+
import { focusWhenVisible } from '../../utils/focus.js';
|
|
20
|
+
|
|
21
|
+
interface Props {
|
|
22
|
+
id: string;
|
|
23
|
+
data: {
|
|
24
|
+
label: string;
|
|
25
|
+
/**
|
|
26
|
+
* Called when an edit ends: the text as typed (the editor cleans it), or
|
|
27
|
+
* `null` when the edit was cancelled. The editor decides whether
|
|
28
|
+
* anything is written.
|
|
29
|
+
*/
|
|
30
|
+
onInlineCommit?: (id: string, text: string | null) => void;
|
|
31
|
+
};
|
|
32
|
+
selected?: boolean;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
let props: Props = $props();
|
|
36
|
+
|
|
37
|
+
const fd = getInstance();
|
|
38
|
+
const caption = $derived(m().nodes.caption);
|
|
39
|
+
|
|
40
|
+
/** Horizontal padding on each side, mirrors the CSS. */
|
|
41
|
+
const PADDING_X = 10;
|
|
42
|
+
|
|
43
|
+
let rootEl: HTMLDivElement | undefined = $state();
|
|
44
|
+
let editorEl: HTMLDivElement | undefined = $state();
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* One-line widths of the two measure spans, in px. `bind:offsetWidth` is
|
|
48
|
+
* unscaled by the viewport zoom (a bounding rect is not) and updates when a
|
|
49
|
+
* web font arrives, so the width below needs no font-loading hook.
|
|
50
|
+
*/
|
|
51
|
+
let textW = $state(0);
|
|
52
|
+
let placeholderW = $state(0);
|
|
53
|
+
|
|
54
|
+
let editing = $state(false);
|
|
55
|
+
/** Text as typed while editing; drives live width measurement. */
|
|
56
|
+
let draft = $state('');
|
|
57
|
+
/** The text is cut off by the two-line clamp; checked on hover, when the tooltip matters. */
|
|
58
|
+
let clipped = $state(false);
|
|
59
|
+
|
|
60
|
+
const label = $derived(props.data.label ?? '');
|
|
61
|
+
const shownText = $derived(editing ? draft : label);
|
|
62
|
+
const showPlaceholder = $derived(editing && draft === '');
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
* Width in px, snapped to the grid; undefined until the text has been
|
|
66
|
+
* measured, so the CSS minimum applies. While editing, the node is never
|
|
67
|
+
* narrower than the placeholder, so a new caption opens wide enough to show
|
|
68
|
+
* it on one line. The max width is the CSS `max-width`; it clamps this.
|
|
69
|
+
*/
|
|
70
|
+
const width = $derived(
|
|
71
|
+
textW === 0 && !editing
|
|
72
|
+
? undefined
|
|
73
|
+
: snapCaptionWidth(
|
|
74
|
+
Math.max(textW, editing ? placeholderW : 0) + 2 * PADDING_X,
|
|
75
|
+
getEditorSettings().gridSize
|
|
76
|
+
)
|
|
77
|
+
);
|
|
78
|
+
|
|
79
|
+
/** The tooltip shows the full text only when the clamp cuts it. */
|
|
80
|
+
function checkClipped(event: PointerEvent): void {
|
|
81
|
+
const el = event.currentTarget as HTMLElement;
|
|
82
|
+
clipped = el.scrollHeight > el.clientHeight + 1;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
// ---------------------------------------------------------------------------
|
|
86
|
+
// In-place editing
|
|
87
|
+
// ---------------------------------------------------------------------------
|
|
88
|
+
|
|
89
|
+
function startEditing(): void {
|
|
90
|
+
if (editing) return;
|
|
91
|
+
draft = label;
|
|
92
|
+
editing = true;
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
function requestEdit(): void {
|
|
96
|
+
fd.inlineEdit.request(props.id);
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
// Take edit requests addressed to this node; a request made before this
|
|
100
|
+
// mounted runs as soon as it registers.
|
|
101
|
+
$effect(() => {
|
|
102
|
+
const id = props.id;
|
|
103
|
+
return untrack(() => fd.inlineEdit.register(id, startEditing));
|
|
104
|
+
});
|
|
105
|
+
|
|
106
|
+
/** Select everything in the box, once it has focus. */
|
|
107
|
+
function selectContents(box: HTMLElement): void {
|
|
108
|
+
const selection = window.getSelection();
|
|
109
|
+
if (!selection) return;
|
|
110
|
+
const range = document.createRange();
|
|
111
|
+
range.selectNodeContents(box);
|
|
112
|
+
selection.removeAllRanges();
|
|
113
|
+
selection.addRange(range);
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
/**
|
|
117
|
+
* Drop a caret or selection that sits in the edit box before the box goes
|
|
118
|
+
* away. Left in place, the browser moves it to the box's parent when the
|
|
119
|
+
* box is removed, and WebKit, after the caret was moved with an arrow key,
|
|
120
|
+
* scrolls the nearest scrollable ancestor to reveal it: the canvas area
|
|
121
|
+
* jumps and every node appears to move.
|
|
122
|
+
*/
|
|
123
|
+
function dropCaret(): void {
|
|
124
|
+
const selection = window.getSelection();
|
|
125
|
+
if (selection && editorEl && editorEl.contains(selection.anchorNode)) {
|
|
126
|
+
selection.removeAllRanges();
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
function finish(save: boolean, refocusNode: boolean): void {
|
|
131
|
+
// The blur that follows an Enter or Escape finds the edit already over.
|
|
132
|
+
if (!editing) return;
|
|
133
|
+
const text = save ? (editorEl?.textContent ?? '') : null;
|
|
134
|
+
const wrapper = rootEl?.closest<HTMLElement>('.svelte-flow__node') ?? null;
|
|
135
|
+
dropCaret();
|
|
136
|
+
editing = false;
|
|
137
|
+
props.data.onInlineCommit?.(props.id, text);
|
|
138
|
+
if (refocusNode) {
|
|
139
|
+
// Keep keyboard users on the node.
|
|
140
|
+
void tick().then(() => wrapper?.isConnected && wrapper.focus({ preventScroll: true }));
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
function insertPlainText(text: string): void {
|
|
145
|
+
const clean = text.replace(/\s+/g, ' ');
|
|
146
|
+
if (!document.execCommand('insertText', false, clean)) {
|
|
147
|
+
const selection = window.getSelection();
|
|
148
|
+
if (!selection || selection.rangeCount === 0) return;
|
|
149
|
+
const range = selection.getRangeAt(0);
|
|
150
|
+
range.deleteContents();
|
|
151
|
+
range.insertNode(document.createTextNode(clean));
|
|
152
|
+
range.collapse(false);
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
/**
|
|
157
|
+
* Sets up the edit box: fills it with the current text and wires native
|
|
158
|
+
* listeners. Keys must not reach xyflow's Delete/Backspace and arrow
|
|
159
|
+
* handling, and `on()` (unlike an `onkeydown` attribute) is not delegated, so
|
|
160
|
+
* a real stopPropagation keeps them away. The box exists only while editing,
|
|
161
|
+
* so this runs once per edit.
|
|
162
|
+
*/
|
|
163
|
+
const editable: Attachment<HTMLDivElement> = (node) => {
|
|
164
|
+
// `plaintext-only` where supported; otherwise plain `true` plus paste
|
|
165
|
+
// handling below, which never lets markup in.
|
|
166
|
+
node.contentEditable = 'plaintext-only';
|
|
167
|
+
if (node.contentEditable !== 'plaintext-only') node.contentEditable = 'true';
|
|
168
|
+
node.textContent = untrack(() => label);
|
|
169
|
+
|
|
170
|
+
// Keep pointer interaction inside the box from selecting or dragging the node.
|
|
171
|
+
const stop = (event: Event): void => event.stopPropagation();
|
|
172
|
+
|
|
173
|
+
const removers = [
|
|
174
|
+
on(node, 'keydown', (event) => {
|
|
175
|
+
event.stopPropagation();
|
|
176
|
+
if (event.isComposing) return;
|
|
177
|
+
if (event.key === 'Enter') {
|
|
178
|
+
event.preventDefault();
|
|
179
|
+
finish(true, true);
|
|
180
|
+
} else if (event.key === 'Escape') {
|
|
181
|
+
event.preventDefault();
|
|
182
|
+
finish(false, true);
|
|
183
|
+
}
|
|
184
|
+
}),
|
|
185
|
+
on(node, 'keyup', stop),
|
|
186
|
+
on(node, 'beforeinput', (event) => {
|
|
187
|
+
// Newlines are never stored.
|
|
188
|
+
if (event.inputType === 'insertParagraph' || event.inputType === 'insertLineBreak') {
|
|
189
|
+
event.preventDefault();
|
|
190
|
+
}
|
|
191
|
+
}),
|
|
192
|
+
on(node, 'input', () => {
|
|
193
|
+
draft = node.textContent ?? '';
|
|
194
|
+
}),
|
|
195
|
+
on(node, 'paste', (event) => {
|
|
196
|
+
event.preventDefault();
|
|
197
|
+
insertPlainText(event.clipboardData?.getData('text/plain') ?? '');
|
|
198
|
+
}),
|
|
199
|
+
on(node, 'drop', (event) => event.preventDefault()),
|
|
200
|
+
on(node, 'blur', () => finish(true, false)),
|
|
201
|
+
on(node, 'dblclick', stop)
|
|
202
|
+
];
|
|
203
|
+
return () => removers.forEach((remove) => remove());
|
|
204
|
+
};
|
|
205
|
+
</script>
|
|
206
|
+
|
|
207
|
+
<!-- Presentational: focus, selection and keyboard activation live on xyflow's
|
|
208
|
+
node wrapper (see UniversalNode). Double-click is a mouse convenience. -->
|
|
209
|
+
<!-- svelte-ignore a11y_no_static_element_interactions -->
|
|
210
|
+
<div
|
|
211
|
+
class="flowdrop-caption-node"
|
|
212
|
+
class:flowdrop-caption-node--selected={props.selected}
|
|
213
|
+
class:flowdrop-caption-node--editing={editing}
|
|
214
|
+
bind:this={rootEl}
|
|
215
|
+
style:width={width === undefined ? undefined : `${width}px`}
|
|
216
|
+
ondblclick={requestEdit}
|
|
217
|
+
>
|
|
218
|
+
<!-- Invisible one-line copy of the text; its natural width sets the node width. -->
|
|
219
|
+
<span class="flowdrop-caption-node__measure" aria-hidden="true" bind:offsetWidth={textW}
|
|
220
|
+
>{shownText}</span
|
|
221
|
+
>
|
|
222
|
+
{#if editing}
|
|
223
|
+
<span class="flowdrop-caption-node__measure" aria-hidden="true" bind:offsetWidth={placeholderW}
|
|
224
|
+
>{caption.placeholder}</span
|
|
225
|
+
>
|
|
226
|
+
{/if}
|
|
227
|
+
|
|
228
|
+
{#if editing}
|
|
229
|
+
<div
|
|
230
|
+
class="flowdrop-caption-node__text flowdrop-caption-node__text--editing nodrag nopan nowheel"
|
|
231
|
+
class:flowdrop-caption-node__text--empty={showPlaceholder}
|
|
232
|
+
role="textbox"
|
|
233
|
+
tabindex="0"
|
|
234
|
+
aria-label={caption.editLabel}
|
|
235
|
+
data-placeholder={caption.placeholder}
|
|
236
|
+
bind:this={editorEl}
|
|
237
|
+
{@attach editable}
|
|
238
|
+
{@attach focusWhenVisible(selectContents)}
|
|
239
|
+
></div>
|
|
240
|
+
{:else}
|
|
241
|
+
<div
|
|
242
|
+
class="flowdrop-caption-node__text"
|
|
243
|
+
title={clipped ? label : undefined}
|
|
244
|
+
onpointerenter={checkClipped}
|
|
245
|
+
>
|
|
246
|
+
{label}
|
|
247
|
+
</div>
|
|
248
|
+
{/if}
|
|
249
|
+
</div>
|
|
250
|
+
|
|
251
|
+
<style>
|
|
252
|
+
.flowdrop-caption-node {
|
|
253
|
+
position: relative;
|
|
254
|
+
box-sizing: border-box;
|
|
255
|
+
min-width: 40px;
|
|
256
|
+
max-width: var(--fd-caption-node-max-width, 500px);
|
|
257
|
+
min-height: 40px;
|
|
258
|
+
padding: 10px;
|
|
259
|
+
border-radius: 6px;
|
|
260
|
+
background: var(--fd-caption-node-bg);
|
|
261
|
+
color: var(--fd-caption-node-fg);
|
|
262
|
+
font-family: var(--fd-font-mono);
|
|
263
|
+
font-size: 13px;
|
|
264
|
+
font-weight: 600;
|
|
265
|
+
line-height: 20px;
|
|
266
|
+
}
|
|
267
|
+
|
|
268
|
+
.flowdrop-caption-node--selected {
|
|
269
|
+
outline: 2px solid var(--fd-ring, currentColor);
|
|
270
|
+
outline-offset: 2px;
|
|
271
|
+
}
|
|
272
|
+
|
|
273
|
+
.flowdrop-caption-node__measure {
|
|
274
|
+
position: absolute;
|
|
275
|
+
top: 0;
|
|
276
|
+
left: 0;
|
|
277
|
+
width: max-content;
|
|
278
|
+
max-width: none;
|
|
279
|
+
white-space: nowrap;
|
|
280
|
+
visibility: hidden;
|
|
281
|
+
pointer-events: none;
|
|
282
|
+
font: inherit;
|
|
283
|
+
}
|
|
284
|
+
|
|
285
|
+
.flowdrop-caption-node__text {
|
|
286
|
+
display: -webkit-box;
|
|
287
|
+
-webkit-box-orient: vertical;
|
|
288
|
+
line-clamp: 2;
|
|
289
|
+
-webkit-line-clamp: 2;
|
|
290
|
+
overflow: hidden;
|
|
291
|
+
overflow-wrap: anywhere;
|
|
292
|
+
text-overflow: ellipsis;
|
|
293
|
+
min-height: 20px;
|
|
294
|
+
}
|
|
295
|
+
|
|
296
|
+
/* The clamp is lifted while typing so the whole text is visible. */
|
|
297
|
+
.flowdrop-caption-node__text--editing {
|
|
298
|
+
display: block;
|
|
299
|
+
line-clamp: none;
|
|
300
|
+
-webkit-line-clamp: unset;
|
|
301
|
+
overflow: visible;
|
|
302
|
+
outline: none;
|
|
303
|
+
cursor: text;
|
|
304
|
+
white-space: pre-wrap;
|
|
305
|
+
user-select: text;
|
|
306
|
+
}
|
|
307
|
+
|
|
308
|
+
.flowdrop-caption-node__text--empty::before {
|
|
309
|
+
content: attr(data-placeholder);
|
|
310
|
+
opacity: 0.55;
|
|
311
|
+
pointer-events: none;
|
|
312
|
+
}
|
|
313
|
+
</style>
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
interface Props {
|
|
2
|
+
id: string;
|
|
3
|
+
data: {
|
|
4
|
+
label: string;
|
|
5
|
+
/**
|
|
6
|
+
* Called when an edit ends: the text as typed (the editor cleans it), or
|
|
7
|
+
* `null` when the edit was cancelled. The editor decides whether
|
|
8
|
+
* anything is written.
|
|
9
|
+
*/
|
|
10
|
+
onInlineCommit?: (id: string, text: string | null) => void;
|
|
11
|
+
};
|
|
12
|
+
selected?: boolean;
|
|
13
|
+
}
|
|
14
|
+
declare const CaptionNode: import("svelte").Component<Props, {}, "">;
|
|
15
|
+
type CaptionNode = ReturnType<typeof CaptionNode>;
|
|
16
|
+
export default CaptionNode;
|
|
@@ -315,6 +315,12 @@
|
|
|
315
315
|
margin-bottom: 0;
|
|
316
316
|
}
|
|
317
317
|
|
|
318
|
+
/* h1/h2 keep their browser-default sizes (~2em/1.5em), which overflow a 20px row
|
|
319
|
+
and overlap when they wrap; give each of their lines two grid rows instead. */
|
|
320
|
+
.flowdrop-notes-node__body :global(:is(h1, h2)) {
|
|
321
|
+
line-height: 40px;
|
|
322
|
+
}
|
|
323
|
+
|
|
318
324
|
.flowdrop-notes-node__body :global(li) {
|
|
319
325
|
margin: 0;
|
|
320
326
|
line-height: 20px;
|
|
@@ -9,6 +9,7 @@
|
|
|
9
9
|
import type { PlaygroundMessage } from '../../types/playground.js';
|
|
10
10
|
import HierarchyTrail from './HierarchyTrail.svelte';
|
|
11
11
|
import MessageTagStrip from './MessageTagStrip.svelte';
|
|
12
|
+
import OriginBadge from './OriginBadge.svelte';
|
|
12
13
|
import MessageMarkdown from './MessageMarkdown.svelte';
|
|
13
14
|
import { formatDuration, formatTimestamp, getRoleIcon, getRoleLabel } from './messageDisplay.js';
|
|
14
15
|
import { m } from '../../messages/index.js';
|
|
@@ -45,6 +46,7 @@
|
|
|
45
46
|
<div class="message-bubble__content">
|
|
46
47
|
<div class="message-bubble__header">
|
|
47
48
|
<span class="message-bubble__role">{roleLabel}</span>
|
|
49
|
+
<OriginBadge {message} />
|
|
48
50
|
{#if showTimestamp}
|
|
49
51
|
<time
|
|
50
52
|
class="message-bubble__timestamp"
|