@industream/flowmaker-flowbox-ui-components 0.0.12 → 0.0.13

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.
@@ -0,0 +1,210 @@
1
+ <script>
2
+ import { DEFAULT_COLUMNS, resolveColumn, resolveValue, resolveSearchText } from './picker-column-helpers';
3
+
4
+ let {
5
+ entries = [],
6
+ selectedIds = $bindable([]),
7
+ columns = DEFAULT_COLUMNS,
8
+ loading = false,
9
+ error = '',
10
+ emptyMessage = 'No entries found for this source connection.',
11
+ onSelectionChange = null
12
+ } = $props();
13
+
14
+ let searchQuery = $state('');
15
+
16
+ /** Resolved column descriptors for rendering — maps each column key to its label, resolver and render type */
17
+ const columnDescriptors = $derived(
18
+ columns
19
+ .map(k => { const col = resolveColumn(k); return col ? { key: k, ...col } : null; })
20
+ .filter(Boolean)
21
+ );
22
+
23
+ const filtered = $derived(() => {
24
+ if (!searchQuery.trim()) return entries;
25
+ const q = searchQuery.toLowerCase();
26
+ return entries.filter(e => resolveSearchText(e, columns).includes(q));
27
+ });
28
+
29
+ const selectedCount = $derived(selectedIds.length);
30
+ const totalCount = $derived(entries.length);
31
+ const allVisibleSelected = $derived(filtered().length > 0 && filtered().every(e => selectedIds.includes(e.id)));
32
+
33
+ function toggleEntry(id) {
34
+ selectedIds = selectedIds.indexOf(id) >= 0
35
+ ? selectedIds.filter(s => s !== id)
36
+ : [...selectedIds, id];
37
+ onSelectionChange?.(selectedIds);
38
+ }
39
+
40
+ function selectAll() {
41
+ const merged = new Set(selectedIds);
42
+ filtered().forEach(e => merged.add(e.id));
43
+ selectedIds = [...merged];
44
+ onSelectionChange?.(selectedIds);
45
+ }
46
+
47
+ function deselectAll() {
48
+ const visibleSet = new Set(filtered().map(e => e.id));
49
+ selectedIds = selectedIds.filter(id => !visibleSet.has(id));
50
+ onSelectionChange?.(selectedIds);
51
+ }
52
+
53
+ function toggleAll() {
54
+ allVisibleSelected ? deselectAll() : selectAll();
55
+ }
56
+ </script>
57
+
58
+ <div class="tag-browser">
59
+ <div class="toolbar">
60
+ <div class="search-wrapper">
61
+ <svg class="search-icon" viewBox="0 0 16 16" width="16" height="16">
62
+ <path d="M15.5 13.586L11.742 9.828A5.514 5.514 0 0 0 13 6.5 5.506 5.506 0 0 0 7.5 1 5.506 5.506 0 0 0 2 6.5 5.506 5.506 0 0 0 7.5 12a5.514 5.514 0 0 0 3.328-1.258l3.758 3.758zM3 6.5A4.505 4.505 0 0 1 7.5 2 4.505 4.505 0 0 1 12 6.5 4.505 4.505 0 0 1 7.5 11 4.505 4.505 0 0 1 3 6.5z" fill="currentColor"></path>
63
+ </svg>
64
+ <input type="text" class="search-input" placeholder="Search..." bind:value={searchQuery} />
65
+ </div>
66
+ <div class="toolbar-actions">
67
+ <span class="count-indicator">{selectedCount} / {totalCount} selected</span>
68
+ <button class="action-button" onclick={selectAll} disabled={loading || filtered().length === 0}>Select All</button>
69
+ <button class="action-button" onclick={deselectAll} disabled={loading || selectedCount === 0}>Deselect All</button>
70
+ </div>
71
+ </div>
72
+
73
+ {#if loading}
74
+ <div class="state-message"><div class="spinner"></div> <span>Loading catalog entries...</span></div>
75
+ {:else if error}
76
+ <div class="state-message error-state">
77
+ <svg viewBox="0 0 16 16" width="16" height="16"><path d="M8 1a7 7 0 1 0 0 14A7 7 0 0 0 8 1zm-.75 3.5h1.5v5h-1.5zm.75 8a1 1 0 1 1 0-2 1 1 0 0 1 0 2z" fill="currentColor"></path></svg>
78
+ <span>{error}</span>
79
+ </div>
80
+ {:else if entries.length === 0}
81
+ <div class="state-message empty-state"><span>{emptyMessage}</span></div>
82
+ {:else}
83
+ <div class="table-container">
84
+ <table class="entry-table">
85
+ <!-- Table headers: one checkbox column + one column per columnDescriptor -->
86
+ <thead>
87
+ <tr>
88
+ <th class="col-checkbox"><input type="checkbox" title="Toggle all visible" checked={allVisibleSelected} onchange={toggleAll} /></th>
89
+ {#each columnDescriptors as columnDescriptor (columnDescriptor.key)}
90
+ <th>{columnDescriptor.label}</th>
91
+ {/each}
92
+ </tr>
93
+ </thead>
94
+
95
+ <!-- Table body: one row per filtered catalog entry, cells rendered by column type -->
96
+ <tbody>
97
+ {#each filtered() as entry (entry.id)}
98
+ {@const isSelected = selectedIds.includes(entry.id)}
99
+ <tr class:selected={isSelected} onclick={() => toggleEntry(entry.id)}>
100
+ <td class="col-checkbox"><input type="checkbox" checked={isSelected} onclick={(e) => e.stopPropagation()} onchange={() => toggleEntry(entry.id)} /></td>
101
+
102
+ <!-- Render each column cell according to its type (text, code, pill, labels) -->
103
+ {#each columnDescriptors as columnDescriptor (columnDescriptor.key)}
104
+ {@const val = resolveValue(entry, columnDescriptor.key)}
105
+ <td title={columnDescriptor.type === 'text' ? (val ?? '') : ''}>
106
+ {#if columnDescriptor.type === 'labels' && Array.isArray(val)}
107
+ {#each val as label (label.id)}
108
+ <span class="label-pill">{label.name}</span>
109
+ {/each}
110
+ {:else if columnDescriptor.type === 'code'}
111
+ <code>{val ?? '-'}</code>
112
+ {:else if columnDescriptor.type === 'pill'}
113
+ {#if val}<span class="pill">{val}</span>{:else}-{/if}
114
+ {:else}
115
+ {val ?? '-'}
116
+ {/if}
117
+ </td>
118
+ {/each}
119
+ </tr>
120
+ {/each}
121
+ </tbody>
122
+ </table>
123
+ </div>
124
+ {#if filtered().length !== entries.length}
125
+ <div class="filter-info">Showing {filtered().length} of {entries.length} entries</div>
126
+ {/if}
127
+ {/if}
128
+ </div>
129
+
130
+ <style>
131
+ .tag-browser { gap: 0.5rem; }
132
+ .toolbar { gap: 0.5rem; }
133
+ .search-wrapper { position: relative; display: flex; align-items: center; }
134
+ .search-icon { position: absolute; left: 0.75rem; color: var(--cds-text-secondary, #525252); pointer-events: none; }
135
+ .search-input {
136
+ width: 100%; padding: 0.5rem 0.75rem 0.5rem 2.25rem;
137
+ background: var(--cds-field-01, #353535); border: none;
138
+ border-bottom: 1px solid var(--cds-border-strong-01, #6f6f6f);
139
+ color: var(--cds-text-primary, #f4f4f4); font-size: 0.875rem;
140
+ outline: none; transition: border-color 0.15s;
141
+ }
142
+ .search-input::placeholder { color: var(--cds-text-placeholder, #6f6f6f); }
143
+ .search-input:focus { border-bottom-color: var(--cds-focus, #0f62fe); }
144
+ .toolbar-actions { display: flex; align-items: center; gap: 0.5rem; }
145
+ .count-indicator { font-size: 0.75rem; color: var(--cds-text-secondary, #c6c6c6); margin-right: auto; }
146
+ .action-button {
147
+ padding: 0.25rem 0.75rem; background: transparent;
148
+ border: 1px solid var(--cds-border-strong-01, #6f6f6f);
149
+ color: var(--cds-text-primary, #f4f4f4); font-size: 0.75rem;
150
+ cursor: pointer; transition: background-color 0.15s;
151
+ }
152
+ .action-button:hover:not(:disabled) { background: var(--cds-layer-hover-01, #4c4c4c); }
153
+ .action-button:disabled { opacity: 0.5; cursor: not-allowed; }
154
+ .state-message {
155
+ display: flex; align-items: center; justify-content: center;
156
+ gap: 0.5rem; padding: 2rem;
157
+ color: var(--cds-text-secondary, #c6c6c6); font-size: 0.875rem;
158
+ }
159
+ .error-state { color: var(--cds-support-error, #fa4d56); }
160
+ .empty-state { color: var(--cds-text-helper, #8d8d8d); }
161
+ .spinner {
162
+ width: 1rem; height: 1rem;
163
+ border: 2px solid var(--cds-border-subtle-01, #e0e0e0);
164
+ border-top-color: var(--cds-interactive, #0f62fe);
165
+ border-radius: 50%; animation: spin 0.8s linear infinite;
166
+ }
167
+ @keyframes spin { to { transform: rotate(360deg); } }
168
+ .table-container {
169
+ max-height: 400px; overflow-y: auto;
170
+ border: 1px solid var(--cds-border-subtle-01, #393939);
171
+ }
172
+ .entry-table { width: 100%; border-collapse: collapse; font-size: 0.8125rem; }
173
+ .entry-table thead { position: sticky; top: 0; z-index: 1; }
174
+ .entry-table th {
175
+ background: var(--cds-layer-02, #262626);
176
+ color: var(--cds-text-secondary, #c6c6c6);
177
+ font-weight: 600; font-size: 0.75rem; text-transform: uppercase;
178
+ letter-spacing: 0.02em; padding: 0.5rem;
179
+ text-align: left; border-bottom: 1px solid var(--cds-border-subtle-01, #393939);
180
+ white-space: nowrap;
181
+ }
182
+ .entry-table td {
183
+ padding: 0.375rem 0.5rem;
184
+ border-bottom: 1px solid var(--cds-border-subtle-01, #393939);
185
+ color: var(--cds-text-primary, #f4f4f4);
186
+ white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
187
+ }
188
+ .entry-table tbody tr { cursor: pointer; transition: background-color 0.1s; }
189
+ .entry-table tbody tr:nth-child(even) { background: var(--cds-layer-01, #262626); }
190
+ .entry-table tbody tr:nth-child(odd) { background: var(--cds-layer-02, #2e2e2e); }
191
+ .entry-table tbody tr:hover { background: var(--cds-layer-hover-01, #4c4c4c); }
192
+ .entry-table tbody tr.selected { background: var(--cds-layer-selected-01, #3d3d3d); }
193
+ .entry-table tbody tr.selected:hover { background: var(--cds-layer-selected-hover-01, #4c4c4c); }
194
+ .col-checkbox { width: 2rem; text-align: center; }
195
+ .col-checkbox input[type="checkbox"] { cursor: pointer; accent-color: var(--cds-interactive, #0f62fe); }
196
+ code {
197
+ font-family: 'IBM Plex Mono', monospace; font-size: 0.75rem;
198
+ color: var(--cds-text-secondary, #c6c6c6);
199
+ }
200
+ .pill, .label-pill {
201
+ display: inline-block; padding: 0.0625rem 0.375rem;
202
+ background: var(--cds-tag-background-gray, #393939);
203
+ color: var(--cds-tag-color-gray, #c6c6c6);
204
+ font-size: 0.6875rem; border-radius: 1rem; margin-right: 0.25rem;
205
+ }
206
+ .filter-info {
207
+ font-size: 0.75rem; color: var(--cds-text-helper, #8d8d8d);
208
+ text-align: center; padding: 0.25rem;
209
+ }
210
+ </style>
@@ -0,0 +1,126 @@
1
+ /**
2
+ * Catalog entry column system.
3
+ *
4
+ * Declarative column definitions that drive both the TagBrowser table
5
+ * and the SelectedTags panel. Consumers pass an array of column keys
6
+ * (e.g. ['name', 'sourceParams.nodeId', 'dataType']) to control display.
7
+ *
8
+ * ── Static column keys ──────────────────────────────────────────────
9
+ *
10
+ * Key | Label | Source | Render
11
+ * -----------|-------------|-----------------------|--------
12
+ * 'name' | Name | CatalogEntry.name | text
13
+ * 'dataType' | Data Type | CatalogEntry.dataType | pill
14
+ * 'labels' | Labels | CatalogEntry.labels[] | labels
15
+ *
16
+ * ── Dynamic column keys (dot-path) ──────────────────────────────────
17
+ *
18
+ * Any key starting with 'sourceParams.' or 'metadata.' resolves the
19
+ * corresponding sub-property at runtime. No pre-registration needed.
20
+ *
21
+ * Key | Label | Source | Render
22
+ * -------------------------|------------|----------------------------------|--------
23
+ * 'sourceParams.nodeId' | Node ID | CatalogEntry.sourceParams.nodeId | code
24
+ * 'sourceParams.topic' | Topic | CatalogEntry.sourceParams.topic | code
25
+ * 'metadata.unit' | Unit | CatalogEntry.metadata.unit | pill
26
+ * 'metadata.description' | Description| CatalogEntry.metadata.description | text
27
+ * ... any other sub-key | (auto) | ... | (auto)
28
+ *
29
+ * Render types:
30
+ * - 'text' : plain text cell (truncated, with title tooltip)
31
+ * - 'code' : monospace <code> cell
32
+ * - 'pill' : small badge/pill (only rendered when value is truthy)
33
+ * - 'labels' : iterates Label[] array, renders each as a pill
34
+ *
35
+ * sourceParams.* keys default to 'code' rendering.
36
+ * metadata.* keys default to 'pill' rendering.
37
+ * Override by adding an explicit entry in COLUMN_DEFS.
38
+ */
39
+
40
+ import type { CatalogEntry, Label } from '@industream/datacatalog-client/dto';
41
+
42
+ /** How a cell should be rendered */
43
+ export type ColumnType = 'text' | 'code' | 'pill' | 'labels';
44
+
45
+ export interface ColumnDef {
46
+ label: string;
47
+ resolve: (entry: CatalogEntry) => unknown;
48
+ type: ColumnType;
49
+ }
50
+
51
+ /**
52
+ * Static column definitions for top-level CatalogEntry fields.
53
+ * For sourceParams / metadata sub-properties, use dot-path keys instead
54
+ * (see {@link resolveColumn}).
55
+ */
56
+ export const COLUMN_DEFS: Record<string, ColumnDef> = {
57
+ name: { label: 'Name', resolve: (e) => e.name, type: 'text' },
58
+ dataType: { label: 'Data Type', resolve: (e) => e.dataType, type: 'pill' },
59
+ labels: { label: 'Labels', resolve: (e) => e.labels ?? [], type: 'labels' },
60
+ };
61
+
62
+ /** Default columns for the tag browser table */
63
+ export const DEFAULT_COLUMNS: string[] = ['name', 'dataType', 'labels'];
64
+
65
+ /** Default columns for the selected tags display panel */
66
+ export const DEFAULT_SELECTED_COLUMNS_DISPLAY: string[] = ['name', 'dataType', 'labels'];
67
+
68
+ /**
69
+ * Capitalize a dot-path sub-key into a human-readable label.
70
+ * e.g. 'nodeId' → 'Node Id', 'pollInterval' → 'Poll Interval'
71
+ */
72
+ const humanize = (key: string): string =>
73
+ key.replace(/([A-Z])/g, ' $1').replace(/^./, (c) => c.toUpperCase()).trim();
74
+
75
+ /**
76
+ * Resolve a column definition for any key — static or dot-path.
77
+ *
78
+ * Static keys are looked up in COLUMN_DEFS.
79
+ * Dot-path keys (sourceParams.*, metadata.*) are resolved dynamically:
80
+ * - sourceParams.* → renders as 'code'
81
+ * - metadata.* → renders as 'pill'
82
+ */
83
+ export const resolveColumn = (key: string): ColumnDef | undefined => {
84
+ if (COLUMN_DEFS[key]) return COLUMN_DEFS[key];
85
+
86
+ if (key.startsWith('sourceParams.')) {
87
+ const prop = key.slice('sourceParams.'.length);
88
+ return {
89
+ label: humanize(prop),
90
+ resolve: (e) => (e.sourceParams as Record<string, unknown>)?.[prop],
91
+ type: 'code',
92
+ };
93
+ }
94
+
95
+ if (key.startsWith('metadata.')) {
96
+ const prop = key.slice('metadata.'.length);
97
+ return {
98
+ label: humanize(prop),
99
+ resolve: (e) => (e.metadata as Record<string, unknown>)?.[prop],
100
+ type: 'pill',
101
+ };
102
+ }
103
+
104
+ return undefined;
105
+ };
106
+
107
+ /**
108
+ * Resolve a single column value from a catalog entry.
109
+ */
110
+ export const resolveValue = (entry: CatalogEntry, key: string): unknown =>
111
+ resolveColumn(key)?.resolve(entry);
112
+
113
+ /**
114
+ * Build a lowercase search string from all active column values.
115
+ * Used by TagBrowser's search filter.
116
+ */
117
+ export const resolveSearchText = (entry: CatalogEntry, keys: string[]): string =>
118
+ keys
119
+ .map((key) => {
120
+ const val = resolveValue(entry, key);
121
+ if (val == null) return '';
122
+ if (Array.isArray(val)) return val.map((v: Label) => v.name ?? v).join(' ');
123
+ return String(val);
124
+ })
125
+ .join(' ')
126
+ .toLowerCase();
package/src/index.ts CHANGED
@@ -4,5 +4,7 @@ export type { SourceConnection } from './DCSourceConnection.svelte';
4
4
  export { default as DCCatalogEntry } from './DCCatalogEntry.svelte';
5
5
  export type { CatalogEntry, DataType, SourceType } from '@industream/datacatalog-client/dto';
6
6
 
7
-
7
+ export { default as DCCatalogEntryPicker } from './DCCatalogEntryPicker/DCCatalogEntryPicker.svelte';
8
+ export type { ColumnDef, ColumnType } from './DCCatalogEntryPicker/picker-column-helpers';
9
+ export { COLUMN_DEFS, DEFAULT_COLUMNS, DEFAULT_SELECTED_COLUMNS_DISPLAY, resolveColumn, resolveValue, resolveSearchText } from './DCCatalogEntryPicker/picker-column-helpers';
8
10