@flowdrop/flowdrop 2.15.2 → 2.17.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.
Files changed (138) hide show
  1. package/CHANGELOG.md +140 -0
  2. package/README.md +10 -1
  3. package/dist/components/App.svelte +219 -6
  4. package/dist/components/App.svelte.d.ts +8 -0
  5. package/dist/components/CanvasToolbar.svelte +40 -3
  6. package/dist/components/CanvasToolbar.svelte.d.ts +5 -1
  7. package/dist/components/ConnectPortPicker.svelte +8 -4
  8. package/dist/components/DoctorMenu.svelte +208 -126
  9. package/dist/components/ImpactConfirm.svelte +341 -0
  10. package/dist/components/ImpactConfirm.svelte.d.ts +12 -0
  11. package/dist/components/Input.svelte +2 -2
  12. package/dist/components/Navbar.svelte +48 -3
  13. package/dist/components/Navbar.svelte.d.ts +4 -0
  14. package/dist/components/NodeSidebar.svelte +36 -15
  15. package/dist/components/NodeSidebar.svelte.d.ts +2 -0
  16. package/dist/components/NodeSwapPicker.svelte +4 -14
  17. package/dist/components/RunBar.svelte +36 -1
  18. package/dist/components/RunBar.svelte.d.ts +5 -0
  19. package/dist/components/RunInputsDialog.svelte +198 -0
  20. package/dist/components/RunInputsDialog.svelte.d.ts +34 -0
  21. package/dist/components/SchemaForm.svelte +2 -1
  22. package/dist/components/SchemaForm.svelte.d.ts +2 -1
  23. package/dist/components/WorkflowCompareDialog.svelte +177 -0
  24. package/dist/components/WorkflowCompareDialog.svelte.d.ts +10 -0
  25. package/dist/components/WorkflowEditor.svelte +88 -6
  26. package/dist/components/WorkflowEditor.svelte.d.ts +6 -0
  27. package/dist/components/WorkflowInterfaceEditor.svelte +14 -4
  28. package/dist/components/WorkflowInterfaceEntryCard.svelte +19 -3
  29. package/dist/components/WorkflowInterfaceEntryCard.svelte.d.ts +2 -0
  30. package/dist/components/form/FormAutocomplete.svelte +76 -12
  31. package/dist/components/nodes/NodeCard.svelte +2 -2
  32. package/dist/components/primitives/Button.svelte +1 -1
  33. package/dist/components/primitives/Button.svelte.d.ts +1 -1
  34. package/dist/components/primitives/Card.svelte +1 -1
  35. package/dist/components/primitives/Card.svelte.d.ts +1 -1
  36. package/dist/components/primitives/Checkbox.svelte +1 -1
  37. package/dist/components/primitives/Checkbox.svelte.d.ts +1 -1
  38. package/dist/components/primitives/Chip.svelte +1 -1
  39. package/dist/components/primitives/Chip.svelte.d.ts +1 -1
  40. package/dist/components/primitives/Combobox.svelte +1 -1
  41. package/dist/components/primitives/Combobox.svelte.d.ts +1 -1
  42. package/dist/components/primitives/Composer.svelte +1 -1
  43. package/dist/components/primitives/Composer.svelte.d.ts +1 -1
  44. package/dist/components/primitives/EmptyState.svelte +1 -1
  45. package/dist/components/primitives/EmptyState.svelte.d.ts +1 -1
  46. package/dist/components/primitives/Field.svelte +1 -1
  47. package/dist/components/primitives/Field.svelte.d.ts +1 -1
  48. package/dist/components/primitives/IconButton.svelte +1 -1
  49. package/dist/components/primitives/IconButton.svelte.d.ts +1 -1
  50. package/dist/components/primitives/Menu.svelte +1 -1
  51. package/dist/components/primitives/Menu.svelte.d.ts +1 -1
  52. package/dist/components/primitives/Notice.svelte +1 -1
  53. package/dist/components/primitives/Notice.svelte.d.ts +1 -1
  54. package/dist/components/primitives/PanelHeader.svelte +1 -1
  55. package/dist/components/primitives/PanelHeader.svelte.d.ts +1 -1
  56. package/dist/components/primitives/Segmented.svelte +2 -2
  57. package/dist/components/primitives/Segmented.svelte.d.ts +2 -2
  58. package/dist/components/primitives/Select.svelte +1 -1
  59. package/dist/components/primitives/Select.svelte.d.ts +1 -1
  60. package/dist/components/primitives/StatusPill.svelte +1 -1
  61. package/dist/components/primitives/StatusPill.svelte.d.ts +1 -1
  62. package/dist/components/primitives/Switch.svelte +1 -1
  63. package/dist/components/primitives/Switch.svelte.d.ts +1 -1
  64. package/dist/components/primitives/Tabs.svelte +2 -2
  65. package/dist/components/primitives/Tabs.svelte.d.ts +2 -2
  66. package/dist/components/primitives/Toolbar.svelte +1 -1
  67. package/dist/components/primitives/Toolbar.svelte.d.ts +1 -1
  68. package/dist/components/primitives/ToolbarSeparator.svelte +1 -1
  69. package/dist/components/primitives/ToolbarSeparator.svelte.d.ts +1 -1
  70. package/dist/components/toast/DismissibleToast.svelte +25 -6
  71. package/dist/components/toast/DismissibleToast.svelte.d.ts +3 -0
  72. package/dist/config/endpoints.d.ts +7 -0
  73. package/dist/config/endpoints.js +2 -1
  74. package/dist/editor/connectCandidates.d.ts +3 -0
  75. package/dist/editor/connectCandidates.js +14 -5
  76. package/dist/editor/index.d.ts +1 -1
  77. package/dist/editor/index.js +1 -1
  78. package/dist/helpers/workflowEditorHelper.d.ts +15 -0
  79. package/dist/helpers/workflowEditorHelper.js +9 -0
  80. package/dist/index.d.ts +1 -0
  81. package/dist/messages/defaults.d.ts +101 -0
  82. package/dist/messages/defaults.js +92 -1
  83. package/dist/openapi/v1/openapi.yaml +10 -2
  84. package/dist/schemas/v1/workflow.schema.json +1 -1
  85. package/dist/services/draftStorage.d.ts +24 -10
  86. package/dist/services/draftStorage.js +60 -35
  87. package/dist/services/globalSave.d.ts +28 -10
  88. package/dist/services/globalSave.js +135 -31
  89. package/dist/services/impactGate.d.ts +34 -0
  90. package/dist/services/impactGate.js +70 -0
  91. package/dist/services/impactService.d.ts +28 -0
  92. package/dist/services/impactService.js +71 -0
  93. package/dist/services/toastQueue.d.ts +9 -0
  94. package/dist/services/toastService.d.ts +4 -0
  95. package/dist/services/toastService.js +9 -3
  96. package/dist/services/workflowLaunchService.js +3 -1
  97. package/dist/settings/index.d.ts +2 -2
  98. package/dist/settings/index.js +1 -1
  99. package/dist/stores/doctorStore.svelte.d.ts +24 -1
  100. package/dist/stores/doctorStore.svelte.js +105 -2
  101. package/dist/stores/instanceContainer.svelte.d.ts +16 -0
  102. package/dist/stores/instanceContainer.svelte.js +22 -2
  103. package/dist/stores/saveConflictStore.svelte.d.ts +62 -0
  104. package/dist/stores/saveConflictStore.svelte.js +169 -0
  105. package/dist/stores/workflowStore.svelte.d.ts +7 -3
  106. package/dist/stores/workflowStore.svelte.js +14 -5
  107. package/dist/styles/toast.css +10 -1
  108. package/dist/svelte-app.d.ts +23 -0
  109. package/dist/svelte-app.js +114 -3
  110. package/dist/themes/scopedSkinCss.d.ts +22 -0
  111. package/dist/themes/scopedSkinCss.js +27 -1
  112. package/dist/types/doctor.d.ts +3 -1
  113. package/dist/types/events.d.ts +20 -0
  114. package/dist/types/events.js +2 -0
  115. package/dist/types/impact.d.ts +25 -0
  116. package/dist/types/impact.js +7 -0
  117. package/dist/types/index.d.ts +11 -1
  118. package/dist/types/settings.d.ts +31 -0
  119. package/dist/types/settings.js +132 -0
  120. package/dist/ui/index.d.ts +76 -0
  121. package/dist/ui/index.js +81 -0
  122. package/dist/utils/apiUrl.d.ts +55 -0
  123. package/dist/utils/apiUrl.js +117 -0
  124. package/dist/utils/draftRestore.d.ts +27 -0
  125. package/dist/utils/draftRestore.js +36 -0
  126. package/dist/utils/interfaceTags.js +4 -1
  127. package/dist/utils/nodeSearch.d.ts +10 -0
  128. package/dist/utils/nodeSearch.js +37 -0
  129. package/dist/utils/portal.js +45 -3
  130. package/dist/utils/runOffer.d.ts +21 -0
  131. package/dist/utils/runOffer.js +13 -0
  132. package/dist/utils/workflowCompare.d.ts +35 -0
  133. package/dist/utils/workflowCompare.js +84 -0
  134. package/dist/utils/workflowInterface.d.ts +26 -1
  135. package/dist/utils/workflowInterface.js +91 -11
  136. package/dist/webmcp/index.d.ts +5 -0
  137. package/dist/webmcp/index.js +5 -0
  138. package/package.json +8 -2
@@ -0,0 +1,81 @@
1
+ /**
2
+ * FlowDrop UI Module
3
+ *
4
+ * The design-system components the editor is built from: the primitives, the
5
+ * surfaces, and the text controls. They use the `--fd-*` tokens only, so a host
6
+ * that loads the package's styles gets the editor's look in its own pages.
7
+ *
8
+ * @module ui
9
+ *
10
+ * Experimental in 2.x: names and props may still change in a minor release
11
+ * while the design system settles. It becomes semver-stable no later than 3.0;
12
+ * pin a minor version (`~2.16.0`) if you depend on it.
13
+ *
14
+ * @example
15
+ * ```svelte
16
+ * <script>
17
+ * import { Button, Card } from '@flowdrop/flowdrop/ui';
18
+ * import '@flowdrop/flowdrop/styles/base.css';
19
+ * </script>
20
+ *
21
+ * <div class="flowdrop-scope" data-theme="light">
22
+ * <Card><Button variant="primary">Save</Button></Card>
23
+ * </div>
24
+ * ```
25
+ *
26
+ * The base styles (box-sizing, type, `color-scheme`) apply only inside
27
+ * `.flowdrop-root`, `.flowdrop-scope` or `.flowdrop-portal`, so wrap the host
28
+ * content that uses these components in one of them. Set `data-theme`
29
+ * (`light` or `dark`) on that wrapper: an overlay such as `SurfaceOverlay` is
30
+ * moved to `<body>` and takes the scheme from it. Without one, the overlay
31
+ * follows the editor's stored theme setting, which may not match the page.
32
+ *
33
+ * To give that content the editor's Graphite look, load tokens.css and add
34
+ * `skinCss(graphiteSkin, '.flowdrop-scope')` as a stylesheet. Dark mode is
35
+ * `data-theme="dark"` on the element the selector matches (here the
36
+ * `.flowdrop-scope` div); for the default `:root` the host sets it on `<html>`
37
+ * itself, which stays supported. Only the editor writing its theme to `<html>`
38
+ * (the mirror) is deprecated, removed in 3.0. The selector is scoped so the skin
39
+ * stays inside the wrapper; the default `:root` restyles the whole page.
40
+ *
41
+ * Built-in strings (labels, placeholders) are English by default and follow
42
+ * `setMessages` from `@flowdrop/flowdrop/core` when the host calls it in an
43
+ * ancestor component.
44
+ */
45
+ // ============================================================================
46
+ // Primitives
47
+ // ============================================================================
48
+ export { default as Button } from '../components/primitives/Button.svelte';
49
+ export { default as Card } from '../components/primitives/Card.svelte';
50
+ export { default as Checkbox } from '../components/primitives/Checkbox.svelte';
51
+ export { default as Chip } from '../components/primitives/Chip.svelte';
52
+ export { default as Combobox } from '../components/primitives/Combobox.svelte';
53
+ export { default as Composer } from '../components/primitives/Composer.svelte';
54
+ export { default as EmptyState } from '../components/primitives/EmptyState.svelte';
55
+ export { default as Field } from '../components/primitives/Field.svelte';
56
+ export { default as IconButton } from '../components/primitives/IconButton.svelte';
57
+ export { default as Menu } from '../components/primitives/Menu.svelte';
58
+ export { default as Notice } from '../components/primitives/Notice.svelte';
59
+ export { default as PanelHeader } from '../components/primitives/PanelHeader.svelte';
60
+ export { default as Segmented } from '../components/primitives/Segmented.svelte';
61
+ export { default as Select } from '../components/primitives/Select.svelte';
62
+ export { default as StatusPill } from '../components/primitives/StatusPill.svelte';
63
+ export { default as Switch } from '../components/primitives/Switch.svelte';
64
+ export { default as Tabs, tabId, tabPanelId } from '../components/primitives/Tabs.svelte';
65
+ export { default as Toolbar } from '../components/primitives/Toolbar.svelte';
66
+ export { default as ToolbarSeparator } from '../components/primitives/ToolbarSeparator.svelte';
67
+ // ============================================================================
68
+ // Surfaces
69
+ // ============================================================================
70
+ export { default as SurfaceOverlay } from '../components/surfaces/SurfaceOverlay.svelte';
71
+ export { default as TabbedSurface } from '../components/surfaces/TabbedSurface.svelte';
72
+ // ============================================================================
73
+ // Text controls
74
+ // ============================================================================
75
+ export { default as Input } from '../components/Input.svelte';
76
+ export { default as Textarea } from '../components/Textarea.svelte';
77
+ // ============================================================================
78
+ // Skin: the editor's look for a host's own pages
79
+ // ============================================================================
80
+ export { graphiteSkin } from '../skins/graphite.js';
81
+ export { skinCss } from '../themes/scopedSkinCss.js';
@@ -0,0 +1,55 @@
1
+ /**
2
+ * Resolve an autocomplete callback URL from node metadata.
3
+ *
4
+ * The URL's own form says what it is relative to:
5
+ *
6
+ * - `https://host/…` or `//host/…` names its own origin and is used as given.
7
+ * - `/path` is relative to the site and is used as given. A `prefix` (the
8
+ * `baseUrl` prop of `SchemaForm`) is put in front of it, as it always was.
9
+ * - `path` (no leading slash, optionally `./path`) is relative to the API
10
+ * base, so a backend can name its own endpoints without knowing where the
11
+ * editor reaches it, e.g. behind a hub's proxy mount
12
+ * (`secrets/options` under `/api/flowdrop/remotes/r1` →
13
+ * `/api/flowdrop/remotes/r1/secrets/options`). A `prefix` (a `SchemaForm`
14
+ * given a `baseUrl` prop) takes precedence: what the form was given beats
15
+ * the editor's base. With neither it is used as given.
16
+ *
17
+ * The base is treated as a folder: its last segment is kept, so
18
+ * `secrets/options` under `https://site/api/flowdrop` is
19
+ * `https://site/api/flowdrop/secrets/options`. This differs on purpose from
20
+ * `new URL()` and HTML resolution, which would drop `flowdrop`.
21
+ *
22
+ * Refused, the result is `null`: any URL with a tab or newline, a control
23
+ * character or space at either end, or a backslash in its path (the browser
24
+ * would fetch something other than its text says), and a no-slash URL that is
25
+ * empty, starts with `?` or `#`, or contains a `..` path segment (`%2e%2e`
26
+ * included).
27
+ *
28
+ * @param url - The URL from the schema's `autocomplete.url`
29
+ * @param base - The API base (`endpointConfig.baseUrl`), relative or absolute
30
+ * @param prefix - SchemaForm's `baseUrl` prop: goes in front of `/path` URLs,
31
+ * and, when set, is the base for no-slash URLs instead of `base`
32
+ * @returns The URL to fetch, or `null` when the URL is refused
33
+ */
34
+ export declare function resolveAutocompleteUrl(url: string, base?: string, prefix?: string): string | null;
35
+ /**
36
+ * Whether `url` is written relative to the API base: no scheme, no `//host`,
37
+ * no leading slash (`secrets/options`, `./secrets/options`).
38
+ */
39
+ export declare function isBaseRelative(url: string): boolean;
40
+ /**
41
+ * Whether `url` names its own origin: it has a scheme (`https://…`) or is
42
+ * `//host/…`.
43
+ */
44
+ export declare function isAbsoluteUrl(url: string): boolean;
45
+ /**
46
+ * Whether a request may carry the instance's auth: it goes to the page's own
47
+ * origin, or to the API base's origin under the base path. Decided on the URL
48
+ * the browser actually fetches, not on its text.
49
+ *
50
+ * @param requestUrl - The URL that is fetched
51
+ * @param apiBase - The API base (`endpointConfig.baseUrl`), relative or absolute
52
+ * @param pageUrl - The page's URL (`location.href`); without one (SSR) only an
53
+ * absolute URL under an absolute API base qualifies
54
+ */
55
+ export declare function mayCarryInstanceAuth(requestUrl: string, apiBase: string, pageUrl: string | undefined): boolean;
@@ -0,0 +1,117 @@
1
+ const HAS_SCHEME = /^[a-z][a-z\d+.-]*:/i;
2
+ /**
3
+ * Text the URL parser does not read as written: tab or newline anywhere (it
4
+ * drops them), a control character or space at either end (it trims them), or
5
+ * a backslash in the path (it reads `\` as `/`). With them, ` //host`, `/\host`
6
+ * and `/\t/host` are other hosts and `a\..\x` climbs out of the base.
7
+ */
8
+ // eslint-disable-next-line no-control-regex -- matching control characters is the point
9
+ const PARSER_REWRITES = /[\t\n\r]|^[\u0000-\u0020]|[\u0000-\u0020]$/;
10
+ /** A path segment the URL parser treats as `..`, including `%2e` spellings. */
11
+ function isDoubleDot(segment) {
12
+ return segment.replace(/%2e/gi, '.') === '..';
13
+ }
14
+ /**
15
+ * Whether a URL is refused in any form: its text is not what the parser reads
16
+ * (see PARSER_REWRITES).
17
+ */
18
+ function isAmbiguous(url) {
19
+ return PARSER_REWRITES.test(url) || url.split(/[?#]/, 1)[0].includes('\\');
20
+ }
21
+ /**
22
+ * Whether a no-slash URL is refused: empty, starting with `?` or `#`, or with
23
+ * a `..` path segment (the part before any `?` or `#`; `%2e%2e` counts). `./x`,
24
+ * `a/b` and `a..b` are fine.
25
+ */
26
+ function isMalformedBaseRelative(url) {
27
+ if (url === '' || url.startsWith('?') || url.startsWith('#'))
28
+ return true;
29
+ const path = url.split(/[?#]/, 1)[0];
30
+ return path.split('/').some(isDoubleDot);
31
+ }
32
+ /**
33
+ * Resolve an autocomplete callback URL from node metadata.
34
+ *
35
+ * The URL's own form says what it is relative to:
36
+ *
37
+ * - `https://host/…` or `//host/…` names its own origin and is used as given.
38
+ * - `/path` is relative to the site and is used as given. A `prefix` (the
39
+ * `baseUrl` prop of `SchemaForm`) is put in front of it, as it always was.
40
+ * - `path` (no leading slash, optionally `./path`) is relative to the API
41
+ * base, so a backend can name its own endpoints without knowing where the
42
+ * editor reaches it, e.g. behind a hub's proxy mount
43
+ * (`secrets/options` under `/api/flowdrop/remotes/r1` →
44
+ * `/api/flowdrop/remotes/r1/secrets/options`). A `prefix` (a `SchemaForm`
45
+ * given a `baseUrl` prop) takes precedence: what the form was given beats
46
+ * the editor's base. With neither it is used as given.
47
+ *
48
+ * The base is treated as a folder: its last segment is kept, so
49
+ * `secrets/options` under `https://site/api/flowdrop` is
50
+ * `https://site/api/flowdrop/secrets/options`. This differs on purpose from
51
+ * `new URL()` and HTML resolution, which would drop `flowdrop`.
52
+ *
53
+ * Refused, the result is `null`: any URL with a tab or newline, a control
54
+ * character or space at either end, or a backslash in its path (the browser
55
+ * would fetch something other than its text says), and a no-slash URL that is
56
+ * empty, starts with `?` or `#`, or contains a `..` path segment (`%2e%2e`
57
+ * included).
58
+ *
59
+ * @param url - The URL from the schema's `autocomplete.url`
60
+ * @param base - The API base (`endpointConfig.baseUrl`), relative or absolute
61
+ * @param prefix - SchemaForm's `baseUrl` prop: goes in front of `/path` URLs,
62
+ * and, when set, is the base for no-slash URLs instead of `base`
63
+ * @returns The URL to fetch, or `null` when the URL is refused
64
+ */
65
+ export function resolveAutocompleteUrl(url, base, prefix = '') {
66
+ if (isAmbiguous(url))
67
+ return null;
68
+ if (isAbsoluteUrl(url))
69
+ return url;
70
+ if (url.startsWith('/'))
71
+ return `${prefix}${url}`;
72
+ if (isMalformedBaseRelative(url))
73
+ return null;
74
+ const root = (prefix || base || '').replace(/\/+$/, '');
75
+ if (!root)
76
+ return url;
77
+ return `${root}/${url.replace(/^\.\//, '')}`;
78
+ }
79
+ /**
80
+ * Whether `url` is written relative to the API base: no scheme, no `//host`,
81
+ * no leading slash (`secrets/options`, `./secrets/options`).
82
+ */
83
+ export function isBaseRelative(url) {
84
+ return !HAS_SCHEME.test(url) && !url.startsWith('/');
85
+ }
86
+ /**
87
+ * Whether `url` names its own origin: it has a scheme (`https://…`) or is
88
+ * `//host/…`.
89
+ */
90
+ export function isAbsoluteUrl(url) {
91
+ return HAS_SCHEME.test(url) || url.startsWith('//');
92
+ }
93
+ /**
94
+ * Whether a request may carry the instance's auth: it goes to the page's own
95
+ * origin, or to the API base's origin under the base path. Decided on the URL
96
+ * the browser actually fetches, not on its text.
97
+ *
98
+ * @param requestUrl - The URL that is fetched
99
+ * @param apiBase - The API base (`endpointConfig.baseUrl`), relative or absolute
100
+ * @param pageUrl - The page's URL (`location.href`); without one (SSR) only an
101
+ * absolute URL under an absolute API base qualifies
102
+ */
103
+ export function mayCarryInstanceAuth(requestUrl, apiBase, pageUrl) {
104
+ try {
105
+ const target = new URL(requestUrl, pageUrl);
106
+ if (pageUrl && target.origin === new URL(pageUrl).origin)
107
+ return true;
108
+ if (!apiBase)
109
+ return false;
110
+ const root = new URL(`${apiBase.replace(/\/+$/, '')}/`, pageUrl);
111
+ return target.origin === root.origin && target.pathname.startsWith(root.pathname);
112
+ }
113
+ catch {
114
+ // Not parseable against the page (or no page at all): no instance auth.
115
+ return false;
116
+ }
117
+ }
@@ -0,0 +1,27 @@
1
+ /**
2
+ * Decides whether a stored draft is worth offering back to the user.
3
+ *
4
+ * Pure: the mount reads the draft and the loaded workflow, asks here, and
5
+ * shows the Restore / Discard toast only when this returns an offer.
6
+ *
7
+ * @module utils/draftRestore
8
+ */
9
+ import { type loadDraft } from '../services/draftStorage.js';
10
+ import type { Workflow } from '../types/index.js';
11
+ type StoredDraft = NonNullable<ReturnType<typeof loadDraft>>;
12
+ /** What the Restore / Discard toast needs to know about a draft. */
13
+ export interface DraftOffer {
14
+ /** ISO time the draft was written */
15
+ savedAt: string;
16
+ /** The workflow was saved after this draft started, so restoring overwrites that save */
17
+ savedSince: boolean;
18
+ }
19
+ /**
20
+ * The offer for a draft, or null when there is nothing to offer: no draft, no
21
+ * loaded workflow, a draft of another workflow, or a draft that matches what
22
+ * is loaded.
23
+ */
24
+ export declare function draftOffer(draft: StoredDraft | null, loaded: Workflow | null): DraftOffer | null;
25
+ /** Time of day for a draft written today, otherwise the date and time. */
26
+ export declare function draftTimeLabel(savedAt: string, now?: Date): string;
27
+ export {};
@@ -0,0 +1,36 @@
1
+ /**
2
+ * Decides whether a stored draft is worth offering back to the user.
3
+ *
4
+ * Pure: the mount reads the draft and the loaded workflow, asks here, and
5
+ * shows the Restore / Discard toast only when this returns an offer.
6
+ *
7
+ * @module utils/draftRestore
8
+ */
9
+ import { draftFingerprint } from '../services/draftStorage.js';
10
+ /**
11
+ * The offer for a draft, or null when there is nothing to offer: no draft, no
12
+ * loaded workflow, a draft of another workflow, or a draft that matches what
13
+ * is loaded.
14
+ */
15
+ export function draftOffer(draft, loaded) {
16
+ if (!draft || !loaded)
17
+ return null;
18
+ if (draft.workflow.id !== loaded.id)
19
+ return null;
20
+ if (draftFingerprint(draft.workflow) === draftFingerprint(loaded))
21
+ return null;
22
+ const base = draft.metadata.baseRevision;
23
+ return {
24
+ savedAt: draft.metadata.savedAt,
25
+ savedSince: base !== undefined && base !== String(loaded.revision)
26
+ };
27
+ }
28
+ /** Time of day for a draft written today, otherwise the date and time. */
29
+ export function draftTimeLabel(savedAt, now = new Date()) {
30
+ const when = new Date(savedAt);
31
+ if (Number.isNaN(when.getTime()))
32
+ return savedAt;
33
+ return when.toDateString() === now.toDateString()
34
+ ? when.toLocaleTimeString()
35
+ : when.toLocaleString();
36
+ }
@@ -178,7 +178,10 @@ export function exposePortAsEntry(workflow, target, id) {
178
178
  const candidate = exposableCandidate(workflow, target.nodeId, target.direction, target.portId);
179
179
  if (!candidate)
180
180
  return null;
181
- const entry = { ...entryFromBindablePort(candidate, []), id: trimmed };
181
+ const entry = {
182
+ ...entryFromBindablePort(candidate, [], workflow, target.direction),
183
+ id: trimmed
184
+ };
182
185
  return {
183
186
  interface: withSide(workflow, target.direction, [
184
187
  ...entriesOf(workflow, target.direction),
@@ -0,0 +1,10 @@
1
+ /**
2
+ * Palette search for node types: matches name, tags (keywords) and description,
3
+ * and orders matches so exact name and keyword hits come first.
4
+ */
5
+ import type { NodeMetadata } from '../types/index.js';
6
+ /**
7
+ * Filter and rank node types for a search query. A blank query returns the
8
+ * input unchanged. Equal scores keep the input (API) order.
9
+ */
10
+ export declare function searchNodeTypes(nodes: NodeMetadata[], query: string): NodeMetadata[];
@@ -0,0 +1,37 @@
1
+ /** Lower is better; null means no match. */
2
+ function scoreNode(node, query) {
3
+ const name = node.name.toLowerCase();
4
+ const tags = (node.tags ?? []).map((tag) => tag.toLowerCase());
5
+ if (name === query)
6
+ return 0;
7
+ if (tags.includes(query))
8
+ return 1;
9
+ if (name.startsWith(query))
10
+ return 2;
11
+ if (name.split(/\s+/).some((word) => word.startsWith(query)))
12
+ return 3;
13
+ if (name.includes(query))
14
+ return 4;
15
+ if (tags.some((tag) => tag.includes(query)))
16
+ return 5;
17
+ if ((node.description ?? '').toLowerCase().includes(query))
18
+ return 6;
19
+ return null;
20
+ }
21
+ /**
22
+ * Filter and rank node types for a search query. A blank query returns the
23
+ * input unchanged. Equal scores keep the input (API) order.
24
+ */
25
+ export function searchNodeTypes(nodes, query) {
26
+ const needle = query.trim().toLowerCase();
27
+ if (!needle)
28
+ return nodes;
29
+ const scored = [];
30
+ nodes.forEach((node, index) => {
31
+ const score = scoreNode(node, needle);
32
+ if (score !== null)
33
+ scored.push({ node, score, index });
34
+ });
35
+ scored.sort((a, b) => a.score - b.score || a.index - b.index);
36
+ return scored.map((entry) => entry.node);
37
+ }
@@ -16,6 +16,12 @@
16
16
  * resolved colour scheme, via the `themeScope` action), since that no longer
17
17
  * sits on <html>.
18
18
  *
19
+ * Outside an editor, inside a `.flowdrop-scope` element (a host page's wrapper
20
+ * around the `ui` components, or a library component such as SettingsPanel),
21
+ * the node gets the `flowdrop-scope` class, so skin rules keyed on that class
22
+ * still match it. If the nearest such element that sets `data-theme` exists, the
23
+ * node follows its `data-theme`; otherwise it follows the store.
24
+ *
19
25
  * Usage: `<div use:portal>…</div>` or `<div use:portal={targetElement}>…</div>`.
20
26
  * No-op during SSR (no `document`).
21
27
  */
@@ -23,10 +29,44 @@ import { themeScope } from './themeScope.svelte.js';
23
29
  /** Attribute that scopes one editor's skin (on `.flowdrop-root`, copied onto overlays). */
24
30
  export const SCOPE_ATTR = 'data-fd-scope';
25
31
  export const PORTAL_CLASS = 'flowdrop-portal';
32
+ /** The wrapper a host page puts around `ui` components (carries the skin and `data-theme`). */
33
+ const HOST_SCOPE_CLASS = 'flowdrop-scope';
26
34
  export function portal(node, target = undefined) {
35
+ // Read before the move, while the node still sits inside its ancestors.
36
+ const editorScope = node.closest(`[${SCOPE_ATTR}]`);
37
+ // Any `.flowdrop-scope` ancestor gives the overlay the class (and so the
38
+ // host's skin). Only one that sets `data-theme` decides the colour scheme:
39
+ // the library's own standalone components (SettingsPanel, SchemaForm,
40
+ // PlaygroundSurface, …) carry the class without one and follow the store.
41
+ const inHostScope = editorScope === null && node.closest(`.${HOST_SCOPE_CLASS}`) !== null;
42
+ const hostScope = inHostScope
43
+ ? node.closest(`.${HOST_SCOPE_CLASS}[data-theme]`)
44
+ : null;
27
45
  // The colour scheme is `data-theme` on the editor scope, not on <html>, so
28
- // an overlay on <body> gets its own (kept in step with the store).
29
- const theme = themeScope(node);
46
+ // an overlay on <body> gets its own (kept in step with the store). In a host
47
+ // wrapper it is copied from the wrapper instead, and follows its changes.
48
+ let theme;
49
+ if (hostScope) {
50
+ const copy = () => {
51
+ const value = hostScope.getAttribute('data-theme');
52
+ if (value === null)
53
+ node.removeAttribute('data-theme');
54
+ else
55
+ node.setAttribute('data-theme', value);
56
+ };
57
+ copy();
58
+ const observer = new MutationObserver(copy);
59
+ observer.observe(hostScope, { attributes: true, attributeFilter: ['data-theme'] });
60
+ theme = {
61
+ destroy() {
62
+ observer.disconnect();
63
+ node.removeAttribute('data-theme');
64
+ }
65
+ };
66
+ }
67
+ else {
68
+ theme = themeScope(node);
69
+ }
30
70
  let host = null;
31
71
  // Remembered across updates: after the first move the node no longer has the
32
72
  // editor as an ancestor to look the scope up on.
@@ -34,12 +74,14 @@ export function portal(node, target = undefined) {
34
74
  function mount(to) {
35
75
  if (typeof document === 'undefined')
36
76
  return;
37
- scope ??= node.closest(`[${SCOPE_ATTR}]`)?.getAttribute(SCOPE_ATTR) ?? null;
77
+ scope ??= editorScope?.getAttribute(SCOPE_ATTR) ?? null;
38
78
  host = to ?? document.body;
39
79
  host.appendChild(node);
40
80
  node.classList.add(PORTAL_CLASS);
41
81
  if (scope !== null)
42
82
  node.setAttribute(SCOPE_ATTR, scope);
83
+ if (inHostScope)
84
+ node.classList.add(HOST_SCOPE_CLASS);
43
85
  }
44
86
  mount(target);
45
87
  return {
@@ -0,0 +1,21 @@
1
+ /**
2
+ * Whether the editor offers a Run button in Edit mode.
3
+ *
4
+ * @module utils/runOffer
5
+ */
6
+ export interface RunOfferState {
7
+ /** `features.runButton` (default on). */
8
+ runButton: boolean | undefined;
9
+ /** The canvas is editable (`mode: 'edit'`). */
10
+ canvasEditable: boolean;
11
+ /** A run-history view of one pipeline, not the editor's workflow. */
12
+ pipelineId: string | undefined;
13
+ /** The id of the saved workflow, if it has one. */
14
+ workflowId: string | undefined;
15
+ /** The host supplied an `onRun` hook. */
16
+ hostCanRun: boolean;
17
+ /** The backend exposes the `workflows.run` endpoint. */
18
+ backendCanRun: boolean;
19
+ }
20
+ /** True when a Run button makes sense: editable, saved, and something can start the run. */
21
+ export declare function canOfferRun(state: RunOfferState): boolean;
@@ -0,0 +1,13 @@
1
+ /**
2
+ * Whether the editor offers a Run button in Edit mode.
3
+ *
4
+ * @module utils/runOffer
5
+ */
6
+ /** True when a Run button makes sense: editable, saved, and something can start the run. */
7
+ export function canOfferRun(state) {
8
+ return (state.runButton !== false &&
9
+ state.canvasEditable &&
10
+ !state.pipelineId &&
11
+ !!state.workflowId &&
12
+ (state.hostCanRun || state.backendCanRun));
13
+ }
@@ -0,0 +1,35 @@
1
+ /**
2
+ * Compare two versions of a workflow: yours and the saved one.
3
+ *
4
+ * Pure. Steps (nodes) match by id, wires (edges) by their four endpoints.
5
+ */
6
+ import type { Workflow } from '../types/index.js';
7
+ export interface WorkflowComparison {
8
+ name?: {
9
+ mine: string;
10
+ theirs: string;
11
+ };
12
+ description?: {
13
+ mine: string | undefined;
14
+ theirs: string | undefined;
15
+ };
16
+ nodesOnlyMine: {
17
+ id: string;
18
+ label: string;
19
+ }[];
20
+ nodesOnlyTheirs: {
21
+ id: string;
22
+ label: string;
23
+ }[];
24
+ nodesChanged: {
25
+ id: string;
26
+ label: string;
27
+ what: ('settings' | 'label' | 'position')[];
28
+ }[];
29
+ edgesOnlyMine: number;
30
+ edgesOnlyTheirs: number;
31
+ interfaceChanged: boolean;
32
+ chatChanged: boolean;
33
+ same: boolean;
34
+ }
35
+ export declare function compareWorkflows(mine: Workflow, theirs: Workflow): WorkflowComparison;
@@ -0,0 +1,84 @@
1
+ /**
2
+ * Compare two versions of a workflow: yours and the saved one.
3
+ *
4
+ * Pure. Steps (nodes) match by id, wires (edges) by their four endpoints.
5
+ */
6
+ import { nodeCanvasLabel } from './workflowInterface.js';
7
+ /** JSON with object keys sorted at every depth, so key order never counts as a change. */
8
+ function stable(value) {
9
+ return JSON.stringify(value ?? null, (_key, v) => {
10
+ if (v && typeof v === 'object' && !Array.isArray(v)) {
11
+ return Object.fromEntries(Object.keys(v)
12
+ .sort()
13
+ .map((k) => [k, v[k]]));
14
+ }
15
+ return v;
16
+ });
17
+ }
18
+ function nodeLabel(node) {
19
+ return nodeCanvasLabel(node);
20
+ }
21
+ function edgeKey(edge) {
22
+ return [edge.source, edge.sourceHandle ?? '', edge.target, edge.targetHandle ?? ''].join('\u0000');
23
+ }
24
+ function countOnlyIn(from, other) {
25
+ const keys = new Set(other.map(edgeKey));
26
+ return from.filter((e) => !keys.has(edgeKey(e))).length;
27
+ }
28
+ export function compareWorkflows(mine, theirs) {
29
+ const myNodes = new Map((mine.nodes ?? []).map((n) => [n.id, n]));
30
+ const theirNodes = new Map((theirs.nodes ?? []).map((n) => [n.id, n]));
31
+ const nodesOnlyMine = [...myNodes.values()]
32
+ .filter((n) => !theirNodes.has(n.id))
33
+ .map((n) => ({ id: n.id, label: nodeLabel(n) }));
34
+ const nodesOnlyTheirs = [...theirNodes.values()]
35
+ .filter((n) => !myNodes.has(n.id))
36
+ .map((n) => ({ id: n.id, label: nodeLabel(n) }));
37
+ const nodesChanged = [];
38
+ for (const [id, a] of myNodes) {
39
+ const b = theirNodes.get(id);
40
+ if (!b)
41
+ continue;
42
+ const what = [];
43
+ if (stable(a.data?.config) !== stable(b.data?.config))
44
+ what.push('settings');
45
+ if ((a.data?.label ?? '') !== (b.data?.label ?? ''))
46
+ what.push('label');
47
+ if (Math.abs((a.position?.x ?? 0) - (b.position?.x ?? 0)) > 1 ||
48
+ Math.abs((a.position?.y ?? 0) - (b.position?.y ?? 0)) > 1) {
49
+ what.push('position');
50
+ }
51
+ if (what.length > 0)
52
+ nodesChanged.push({ id, label: nodeLabel(a), what });
53
+ }
54
+ const edgesOnlyMine = countOnlyIn(mine.edges ?? [], theirs.edges ?? []);
55
+ const edgesOnlyTheirs = countOnlyIn(theirs.edges ?? [], mine.edges ?? []);
56
+ const interfaceChanged = stable(mine.interface) !== stable(theirs.interface);
57
+ const chatChanged = stable(mine.playground) !== stable(theirs.playground);
58
+ const result = {
59
+ nodesOnlyMine,
60
+ nodesOnlyTheirs,
61
+ nodesChanged,
62
+ edgesOnlyMine,
63
+ edgesOnlyTheirs,
64
+ interfaceChanged,
65
+ chatChanged,
66
+ same: false
67
+ };
68
+ if (mine.name !== theirs.name)
69
+ result.name = { mine: mine.name, theirs: theirs.name };
70
+ if ((mine.description ?? '') !== (theirs.description ?? '')) {
71
+ result.description = { mine: mine.description, theirs: theirs.description };
72
+ }
73
+ result.same =
74
+ !result.name &&
75
+ !result.description &&
76
+ nodesOnlyMine.length === 0 &&
77
+ nodesOnlyTheirs.length === 0 &&
78
+ nodesChanged.length === 0 &&
79
+ edgesOnlyMine === 0 &&
80
+ edgesOnlyTheirs === 0 &&
81
+ !interfaceChanged &&
82
+ !chatChanged;
83
+ return result;
84
+ }
@@ -211,6 +211,15 @@ export declare function nodeCanvasLabel(node: {
211
211
  config?: Record<string, unknown>;
212
212
  };
213
213
  }): string;
214
+ /**
215
+ * Tells same-named nodes apart in a picker: when two or more items with
216
+ * different node ids share a label, each of them gets " · <node id>" appended.
217
+ * Unique labels, and several ports of one node, stay as they are.
218
+ */
219
+ export declare function disambiguateLabels<T extends {
220
+ nodeId: string;
221
+ nodeLabel: string;
222
+ }>(items: T[]): T[];
214
223
  /** One inner port a `WorkflowInterfaceEntry` could bind to, plus its owning node. */
215
224
  export interface BindablePort {
216
225
  nodeId: string;
@@ -275,7 +284,23 @@ export declare function rankBindablePorts(workflow: Workflow, direction: 'input'
275
284
  * re-derives it. DN1's concern — a contract silently keyed on internal port
276
285
  * names — is about that ongoing coupling, which this does not introduce.
277
286
  */
278
- export declare function entryFromBindablePort(candidate: BindablePort, existingIds: Iterable<string>): WorkflowInterfaceEntry;
287
+ export declare function entryFromBindablePort(candidate: BindablePort, existingIds: Iterable<string>, workflow?: Workflow, direction?: 'input' | 'output'): WorkflowInterfaceEntry;
288
+ /** Port ids too generic to name a public entry: the node's title names it instead. */
289
+ export declare const GENERIC_PORT_IDS: readonly string[];
290
+ /**
291
+ * The id, title and type to seed a new entry with for a picked port.
292
+ *
293
+ * A generic port id (`data`, `value`, ...) says nothing about the contract, so
294
+ * the bound node's canvas label gives the id (snake_case) and the title. A
295
+ * `mixed` port takes the type of the port at the other end of an edge on its
296
+ * handle, when that one is typed. The id gets a numeric suffix only on a
297
+ * collision with `existingIds`.
298
+ */
299
+ export declare function suggestEntryFromBindablePort(workflow: Workflow | undefined, candidate: BindablePort, existingIds: Iterable<string>, direction?: 'input' | 'output'): {
300
+ id: string;
301
+ name: string;
302
+ dataType: string;
303
+ };
279
304
  /** The turn values an entry of this direction may carry, in selector order. */
280
305
  export declare function turnsFor(direction: 'input' | 'output'): readonly WorkflowInterfaceTurn[];
281
306
  /** Whether a value is in this library's turn vocabulary (either direction). */