@poirazis/supercomponents-shared 1.2.15 → 1.2.16
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/dist/index.js +10576 -10510
- package/dist/index.umd.cjs +16 -15
- package/package.json +3 -3
- package/src/lib/SuperButton/SuperButton.svelte +16 -21
- package/src/lib/SuperField/SuperField.svelte +10 -11
- package/src/lib/SuperForm/InnerForm.svelte +9 -2
- package/src/lib/SuperForm/SuperForm.svelte +5 -5
- package/src/lib/SuperPopover/SuperPopover.svelte +1 -1
- package/src/lib/SuperTable/SuperTable.svelte +2 -4
- package/src/lib/SuperTableCells/CellCommon.css +97 -35
- package/src/lib/SuperTableCells/CellDatetime.svelte +2 -3
- package/src/lib/SuperTableCells/CellLink.svelte +8 -8
- package/src/lib/SuperTableCells/CellOptions.svelte +320 -237
- package/src/lib/SuperTableCells/CellOptionsAdvanced.svelte +186 -169
- package/src/lib/SuperTableCells/CellSkeleton.svelte +1 -1
- package/src/lib/SuperTableCells/CellString.svelte +19 -39
- package/src/lib/SuperTableCells/CellStringSimple.svelte +1 -4
- package/src/lib/SuperTableColumn/SuperTableColumn.svelte +1 -1
- package/src/lib/SuperTableColumn/parts/SuperColumnRow.svelte +1 -3
- package/src/lib/SuperTableCells/JSDOC_GUIDE.md +0 -869
|
@@ -2,7 +2,6 @@
|
|
|
2
2
|
import { getContext, createEventDispatcher, onMount, tick } from "svelte";
|
|
3
3
|
import SuperPopover from "../SuperPopover/SuperPopover.svelte";
|
|
4
4
|
import "./CellCommon.css";
|
|
5
|
-
|
|
6
5
|
import fsm from "svelte-fsm";
|
|
7
6
|
|
|
8
7
|
const dispatch = createEventDispatcher();
|
|
@@ -18,159 +17,62 @@
|
|
|
18
17
|
let editor;
|
|
19
18
|
let optionsList;
|
|
20
19
|
let options = memo([]);
|
|
21
|
-
let labels = {};
|
|
20
|
+
let labels = memo({});
|
|
22
21
|
let optionColors = {};
|
|
23
22
|
let filteredOptions = [];
|
|
24
23
|
let focusedOptionIdx = -1;
|
|
25
24
|
let timer;
|
|
26
25
|
let localValue = [];
|
|
27
26
|
|
|
28
|
-
let searchTerm =
|
|
29
|
-
let inputValue =
|
|
30
|
-
let isInitialLoad = false;
|
|
27
|
+
let searchTerm = null;
|
|
28
|
+
let inputValue = null;
|
|
31
29
|
let initLimit = 15;
|
|
30
|
+
let fetch;
|
|
31
|
+
let loading = false;
|
|
32
|
+
let optionsSource = "schema";
|
|
33
|
+
|
|
34
|
+
// Handle Options from Data Source
|
|
35
|
+
const dataSourceStore = memo(cellOptions?.datasource);
|
|
36
|
+
$: dataSourceStore.set(cellOptions.datasource);
|
|
37
|
+
|
|
38
|
+
$: ({
|
|
39
|
+
controlType,
|
|
40
|
+
optionsSource,
|
|
41
|
+
limit,
|
|
42
|
+
sortColumn,
|
|
43
|
+
sortOrder,
|
|
44
|
+
valueColumn,
|
|
45
|
+
labelColumn,
|
|
46
|
+
iconColumn,
|
|
47
|
+
colorColumn,
|
|
48
|
+
customOptions,
|
|
49
|
+
optionsViewMode,
|
|
50
|
+
role,
|
|
51
|
+
readonly,
|
|
52
|
+
disabled,
|
|
53
|
+
error,
|
|
54
|
+
color,
|
|
55
|
+
background,
|
|
56
|
+
filter,
|
|
57
|
+
pickerWidth,
|
|
58
|
+
} = cellOptions);
|
|
32
59
|
|
|
33
60
|
const createFetch = (datasource) => {
|
|
34
|
-
|
|
61
|
+
defaultQuery = QueryUtils.buildQuery(cellOptions.filter || []);
|
|
62
|
+
initLimit = limit || 15;
|
|
63
|
+
|
|
35
64
|
return fetchData({
|
|
36
65
|
API,
|
|
37
66
|
datasource,
|
|
38
67
|
options: {
|
|
68
|
+
query: defaultQuery,
|
|
39
69
|
sortColumn: cellOptions.sortColumn,
|
|
40
70
|
sortOrder: cellOptions.sortOrder,
|
|
41
|
-
limit
|
|
71
|
+
limit,
|
|
42
72
|
},
|
|
43
73
|
});
|
|
44
74
|
};
|
|
45
75
|
|
|
46
|
-
export const cellState = fsm("Loading", {
|
|
47
|
-
"*": {
|
|
48
|
-
goTo(state) {
|
|
49
|
-
return state;
|
|
50
|
-
},
|
|
51
|
-
refresh() {
|
|
52
|
-
$options = [];
|
|
53
|
-
return "Loading";
|
|
54
|
-
},
|
|
55
|
-
loadSchemaOptions() {
|
|
56
|
-
optionColors = fieldSchema?.optionColors || {};
|
|
57
|
-
$options = fieldSchema?.constraints?.inclusion || [];
|
|
58
|
-
labels = {};
|
|
59
|
-
filteredOptions = $options;
|
|
60
|
-
},
|
|
61
|
-
loadDataOptions(rows) {
|
|
62
|
-
$options = [];
|
|
63
|
-
labels = {};
|
|
64
|
-
if (rows && rows.length) {
|
|
65
|
-
rows.forEach((row) => {
|
|
66
|
-
$options.push(row[valueColumn]?.toString());
|
|
67
|
-
labels[row[valueColumn]] = row[labelColumn || valueColumn];
|
|
68
|
-
if (colorColumn) optionColors[row[valueColumn]] = row[colorColumn];
|
|
69
|
-
});
|
|
70
|
-
}
|
|
71
|
-
$options = $options;
|
|
72
|
-
filteredOptions = $options;
|
|
73
|
-
if (isInitialLoad) isInitialLoad = false;
|
|
74
|
-
},
|
|
75
|
-
loadCustomOptions() {
|
|
76
|
-
if (customOptions?.length) {
|
|
77
|
-
customOptions.forEach((row) => {
|
|
78
|
-
$options.push(row.value || row);
|
|
79
|
-
labels[row.value] = row.label || row;
|
|
80
|
-
});
|
|
81
|
-
}
|
|
82
|
-
$options = $options;
|
|
83
|
-
},
|
|
84
|
-
},
|
|
85
|
-
Loading: {
|
|
86
|
-
_enter() {
|
|
87
|
-
if (cellOptions.optionsSource != "data") return "View";
|
|
88
|
-
},
|
|
89
|
-
_exit() {
|
|
90
|
-
if (cellOptions.optionsSource == "custom") this.loadCustomOptions();
|
|
91
|
-
else if (optionsSource == "data") this.loadDataOptions($fetch?.rows);
|
|
92
|
-
else this.loadSchemaOptions();
|
|
93
|
-
|
|
94
|
-
filteredOptions = $options;
|
|
95
|
-
},
|
|
96
|
-
syncFetch(fetch) {
|
|
97
|
-
if (fetch?.loaded) {
|
|
98
|
-
return cellOptions.initialState || "View";
|
|
99
|
-
}
|
|
100
|
-
},
|
|
101
|
-
focus(e) {
|
|
102
|
-
if (!cellOptions.readonly && !cellOptions.disabled) {
|
|
103
|
-
return "Editing";
|
|
104
|
-
}
|
|
105
|
-
},
|
|
106
|
-
},
|
|
107
|
-
View: {
|
|
108
|
-
_enter() {
|
|
109
|
-
searchTerm = null;
|
|
110
|
-
editorState.filterOptions();
|
|
111
|
-
},
|
|
112
|
-
focus(e) {
|
|
113
|
-
if (!readonly && !disabled) {
|
|
114
|
-
return "Editing";
|
|
115
|
-
}
|
|
116
|
-
},
|
|
117
|
-
},
|
|
118
|
-
Editing: {
|
|
119
|
-
_enter() {
|
|
120
|
-
editorState.open();
|
|
121
|
-
originalValue = JSON.stringify(
|
|
122
|
-
Array.isArray(value) ? value : value ? [value] : [],
|
|
123
|
-
);
|
|
124
|
-
inputValue = multi ? "" : labels[localValue[0]] || localValue[0] || "";
|
|
125
|
-
|
|
126
|
-
dispatch("enteredit");
|
|
127
|
-
},
|
|
128
|
-
_exit() {
|
|
129
|
-
editorState.close();
|
|
130
|
-
dispatch("exitedit");
|
|
131
|
-
},
|
|
132
|
-
toggle(e) {
|
|
133
|
-
editorState.toggle();
|
|
134
|
-
},
|
|
135
|
-
focusout(e) {
|
|
136
|
-
dispatch("focusout");
|
|
137
|
-
|
|
138
|
-
// For debounced inputs, dispatch the current value immediately on focusout
|
|
139
|
-
if (cellOptions.debounce && isDirty) {
|
|
140
|
-
clearTimeout(timer);
|
|
141
|
-
dispatch("change", multi ? localValue : localValue[0]);
|
|
142
|
-
} else {
|
|
143
|
-
this.submit();
|
|
144
|
-
}
|
|
145
|
-
|
|
146
|
-
return "View";
|
|
147
|
-
},
|
|
148
|
-
popupfocusout(e) {
|
|
149
|
-
if (anchor != e?.relatedTarget) {
|
|
150
|
-
this.submit();
|
|
151
|
-
return "View";
|
|
152
|
-
}
|
|
153
|
-
},
|
|
154
|
-
submit() {
|
|
155
|
-
if (isDirty && !cellOptions.debounce) {
|
|
156
|
-
if (multi) dispatch("change", localValue);
|
|
157
|
-
else dispatch("change", localValue[0]);
|
|
158
|
-
}
|
|
159
|
-
},
|
|
160
|
-
clear() {
|
|
161
|
-
localValue = [];
|
|
162
|
-
anchor?.focus();
|
|
163
|
-
if (cellOptions.debounce) dispatch("change", null);
|
|
164
|
-
},
|
|
165
|
-
cancel() {
|
|
166
|
-
localValue = JSON.parse(originalValue);
|
|
167
|
-
searchTerm = null;
|
|
168
|
-
anchor?.blur();
|
|
169
|
-
return "View";
|
|
170
|
-
},
|
|
171
|
-
},
|
|
172
|
-
});
|
|
173
|
-
|
|
174
76
|
const editorState = fsm("Closed", {
|
|
175
77
|
"*": {
|
|
176
78
|
toggleOption(idx) {
|
|
@@ -189,7 +91,9 @@
|
|
|
189
91
|
if (localValue[0] == option) localValue.length = 0;
|
|
190
92
|
else localValue[0] = option;
|
|
191
93
|
|
|
192
|
-
|
|
94
|
+
localValue = [...localValue];
|
|
95
|
+
|
|
96
|
+
inputValue = $labels[localValue[0]] || localValue[0] || "";
|
|
193
97
|
}
|
|
194
98
|
|
|
195
99
|
if (cellOptions.debounce) {
|
|
@@ -211,44 +115,77 @@
|
|
|
211
115
|
}
|
|
212
116
|
},
|
|
213
117
|
filterOptions(term) {
|
|
214
|
-
if (
|
|
118
|
+
if (optionsSource == "data") {
|
|
215
119
|
// For datasource, update the fetch with filter
|
|
216
|
-
let appliedFilter =
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
valueType: "Value",
|
|
226
|
-
},
|
|
227
|
-
];
|
|
120
|
+
let appliedFilter = {};
|
|
121
|
+
|
|
122
|
+
// Start with base filter or create new one
|
|
123
|
+
if (
|
|
124
|
+
filter &&
|
|
125
|
+
typeof filter === "object" &&
|
|
126
|
+
Object.keys(filter).length > 0
|
|
127
|
+
) {
|
|
128
|
+
appliedFilter = JSON.parse(JSON.stringify(filter)); // Deep clone
|
|
228
129
|
} else {
|
|
229
|
-
|
|
130
|
+
// Create a base filter object
|
|
131
|
+
appliedFilter = {
|
|
132
|
+
logicalOperator: "all",
|
|
133
|
+
onEmptyFilter: "all",
|
|
134
|
+
groups: [],
|
|
135
|
+
};
|
|
230
136
|
}
|
|
137
|
+
|
|
138
|
+
// Add search term as a new filter group if provided
|
|
139
|
+
if (term != null && term.trim() !== "") {
|
|
140
|
+
const searchFilterGroup = {
|
|
141
|
+
logicalOperator: "any",
|
|
142
|
+
filters: [
|
|
143
|
+
{
|
|
144
|
+
valueType: "Value",
|
|
145
|
+
field: labelColumn || valueColumn,
|
|
146
|
+
type: "string",
|
|
147
|
+
constraints: {
|
|
148
|
+
type: "string",
|
|
149
|
+
length: {},
|
|
150
|
+
presence: false,
|
|
151
|
+
},
|
|
152
|
+
operator: "fuzzy",
|
|
153
|
+
noValue: false,
|
|
154
|
+
value: term,
|
|
155
|
+
},
|
|
156
|
+
],
|
|
157
|
+
};
|
|
158
|
+
|
|
159
|
+
// Add the search filter group
|
|
160
|
+
if (!appliedFilter.groups) {
|
|
161
|
+
appliedFilter.groups = [];
|
|
162
|
+
}
|
|
163
|
+
appliedFilter.groups.push(searchFilterGroup);
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
const query = QueryUtils.buildQuery(appliedFilter);
|
|
231
167
|
fetch?.update({
|
|
232
|
-
query
|
|
168
|
+
query,
|
|
233
169
|
});
|
|
234
|
-
// Keep filteredOptions in sync
|
|
235
|
-
filteredOptions = $options;
|
|
236
170
|
} else {
|
|
237
171
|
// Client-side filtering for non-datasource
|
|
238
172
|
if (term) {
|
|
239
173
|
filteredOptions = $options.filter((x) =>
|
|
240
|
-
x?.toLocaleLowerCase().
|
|
174
|
+
x?.toLocaleLowerCase().includes(term.toLocaleLowerCase()),
|
|
241
175
|
);
|
|
242
176
|
} else {
|
|
243
177
|
filteredOptions = $options;
|
|
244
178
|
}
|
|
245
179
|
}
|
|
246
180
|
},
|
|
181
|
+
clearFilter() {
|
|
182
|
+
searchTerm = null;
|
|
183
|
+
this.filterOptions();
|
|
184
|
+
},
|
|
247
185
|
},
|
|
248
186
|
Open: {
|
|
249
187
|
_enter() {
|
|
250
188
|
searchTerm = "";
|
|
251
|
-
this.filterOptions();
|
|
252
189
|
focusedOptionIdx = -1;
|
|
253
190
|
},
|
|
254
191
|
toggle() {
|
|
@@ -259,6 +196,7 @@
|
|
|
259
196
|
},
|
|
260
197
|
handleKeyboard(e) {
|
|
261
198
|
if (e.key === "Backspace" || e.key === "Delete") {
|
|
199
|
+
console.log(searchTerm, "before deletion");
|
|
262
200
|
searchTerm = searchTerm.slice(0, -1);
|
|
263
201
|
this.filterOptions(searchTerm);
|
|
264
202
|
} else if (e.key.length === 1 && /[a-zA-Z0-9]/.test(e.key)) {
|
|
@@ -347,10 +285,7 @@
|
|
|
347
285
|
},
|
|
348
286
|
},
|
|
349
287
|
Closed: {
|
|
350
|
-
_enter() {
|
|
351
|
-
searchTerm = null;
|
|
352
|
-
focusedOptionIdx = -1;
|
|
353
|
-
},
|
|
288
|
+
_enter() {},
|
|
354
289
|
toggle() {
|
|
355
290
|
return "Open";
|
|
356
291
|
},
|
|
@@ -402,6 +337,170 @@
|
|
|
402
337
|
},
|
|
403
338
|
});
|
|
404
339
|
|
|
340
|
+
export const cellState = fsm("View", {
|
|
341
|
+
"*": {
|
|
342
|
+
goTo(state) {
|
|
343
|
+
return state;
|
|
344
|
+
},
|
|
345
|
+
refresh() {
|
|
346
|
+
$options = [];
|
|
347
|
+
optionColors = {};
|
|
348
|
+
$labels = {};
|
|
349
|
+
filteredOptions = [];
|
|
350
|
+
if (optionsSource != "data") {
|
|
351
|
+
this.loadOptions(optionsSource);
|
|
352
|
+
}
|
|
353
|
+
return optionsSource == "data" ? "Loading" : "View";
|
|
354
|
+
},
|
|
355
|
+
reload() {
|
|
356
|
+
this.loadOptions(optionsSource);
|
|
357
|
+
},
|
|
358
|
+
loadSchemaOptions() {
|
|
359
|
+
try {
|
|
360
|
+
optionColors = fieldSchema?.optionColors || {};
|
|
361
|
+
$options = fieldSchema?.constraints?.inclusion || [];
|
|
362
|
+
$labels = {};
|
|
363
|
+
filteredOptions = $options;
|
|
364
|
+
} catch (e) {}
|
|
365
|
+
},
|
|
366
|
+
loadDataOptions(rows) {
|
|
367
|
+
$options = [];
|
|
368
|
+
$labels = {};
|
|
369
|
+
let primaryDisplay = labelColumn || labelColumn;
|
|
370
|
+
if (rows && rows.length) {
|
|
371
|
+
rows.forEach((row) => {
|
|
372
|
+
$options.push(row[valueColumn]);
|
|
373
|
+
$labels[row[valueColumn]] = row[primaryDisplay];
|
|
374
|
+
if (colorColumn) optionColors[row[valueColumn]] = row[colorColumn];
|
|
375
|
+
});
|
|
376
|
+
}
|
|
377
|
+
|
|
378
|
+
$options = $options;
|
|
379
|
+
filteredOptions = $options;
|
|
380
|
+
},
|
|
381
|
+
loadCustomOptions() {
|
|
382
|
+
if (customOptions?.length) {
|
|
383
|
+
customOptions.forEach((row) => {
|
|
384
|
+
$options.push(row.value || row);
|
|
385
|
+
$labels[row.value] = row.label || row;
|
|
386
|
+
});
|
|
387
|
+
}
|
|
388
|
+
$options = $options;
|
|
389
|
+
filteredOptions = $options;
|
|
390
|
+
},
|
|
391
|
+
loadOptions(src) {
|
|
392
|
+
if (src == "data") {
|
|
393
|
+
this.loadDataOptions($fetch?.rows);
|
|
394
|
+
} else if (src == "custom") {
|
|
395
|
+
this.loadCustomOptions();
|
|
396
|
+
} else {
|
|
397
|
+
this.loadSchemaOptions();
|
|
398
|
+
}
|
|
399
|
+
},
|
|
400
|
+
},
|
|
401
|
+
Loading: {
|
|
402
|
+
_enter() {
|
|
403
|
+
fetch = createFetch($dataSourceStore);
|
|
404
|
+
loading = true;
|
|
405
|
+
},
|
|
406
|
+
_exit() {
|
|
407
|
+
loading = false;
|
|
408
|
+
},
|
|
409
|
+
refresh() {},
|
|
410
|
+
reload() {},
|
|
411
|
+
syncFetch(fetch) {
|
|
412
|
+
if (fetch?.loaded) {
|
|
413
|
+
return cellOptions.initialState || "View";
|
|
414
|
+
}
|
|
415
|
+
},
|
|
416
|
+
focus(e) {
|
|
417
|
+
if (!cellOptions.readonly && !cellOptions.disabled) {
|
|
418
|
+
return "Editing";
|
|
419
|
+
}
|
|
420
|
+
},
|
|
421
|
+
},
|
|
422
|
+
View: {
|
|
423
|
+
_enter() {
|
|
424
|
+
searchTerm = null;
|
|
425
|
+
editorState.filterOptions();
|
|
426
|
+
},
|
|
427
|
+
toggle(e) {
|
|
428
|
+
if (cellOptions.disabled || cellOptions.readonly) return;
|
|
429
|
+
return "Editing";
|
|
430
|
+
},
|
|
431
|
+
focus(e) {
|
|
432
|
+
if (!readonly && !disabled) {
|
|
433
|
+
return "Editing";
|
|
434
|
+
}
|
|
435
|
+
},
|
|
436
|
+
},
|
|
437
|
+
Editing: {
|
|
438
|
+
_enter() {
|
|
439
|
+
editorState.open();
|
|
440
|
+
|
|
441
|
+
setTimeout(() => {
|
|
442
|
+
editor?.focus();
|
|
443
|
+
}, 30);
|
|
444
|
+
originalValue = JSON.stringify(
|
|
445
|
+
Array.isArray(value) ? value : value ? [value] : [],
|
|
446
|
+
);
|
|
447
|
+
inputValue = multi ? "" : $labels[localValue[0]] || localValue[0] || "";
|
|
448
|
+
|
|
449
|
+
dispatch("enteredit");
|
|
450
|
+
},
|
|
451
|
+
_exit() {
|
|
452
|
+
searchTerm = null;
|
|
453
|
+
inputValue = null;
|
|
454
|
+
editorState.close();
|
|
455
|
+
dispatch("exitedit");
|
|
456
|
+
},
|
|
457
|
+
toggle(e) {
|
|
458
|
+
if (!inputSelect && searchTerm) {
|
|
459
|
+
return;
|
|
460
|
+
}
|
|
461
|
+
e.preventDefault();
|
|
462
|
+
editorState.toggle();
|
|
463
|
+
},
|
|
464
|
+
focusout(e) {
|
|
465
|
+
if (anchor.contains(e.relatedTarget)) {
|
|
466
|
+
return;
|
|
467
|
+
}
|
|
468
|
+
|
|
469
|
+
if (cellOptions.debounce && isDirty) {
|
|
470
|
+
clearTimeout(timer);
|
|
471
|
+
dispatch("change", multi ? localValue : localValue[0]);
|
|
472
|
+
} else {
|
|
473
|
+
this.submit();
|
|
474
|
+
}
|
|
475
|
+
dispatch("focusout");
|
|
476
|
+
return "View";
|
|
477
|
+
},
|
|
478
|
+
popupfocusout(e) {
|
|
479
|
+
if (anchor != e?.relatedTarget) {
|
|
480
|
+
this.submit();
|
|
481
|
+
return "View";
|
|
482
|
+
}
|
|
483
|
+
},
|
|
484
|
+
submit() {
|
|
485
|
+
if (isDirty && !cellOptions.debounce) {
|
|
486
|
+
if (multi) dispatch("change", localValue);
|
|
487
|
+
else dispatch("change", localValue[0]);
|
|
488
|
+
}
|
|
489
|
+
},
|
|
490
|
+
clear() {
|
|
491
|
+
localValue = [];
|
|
492
|
+
anchor?.focus();
|
|
493
|
+
if (cellOptions.debounce) dispatch("change", null);
|
|
494
|
+
},
|
|
495
|
+
cancel() {
|
|
496
|
+
localValue = JSON.parse(originalValue);
|
|
497
|
+
searchTerm = null;
|
|
498
|
+
anchor?.blur();
|
|
499
|
+
return "View";
|
|
500
|
+
},
|
|
501
|
+
},
|
|
502
|
+
});
|
|
503
|
+
|
|
405
504
|
const colors = derivedMemo(options, ($options) => {
|
|
406
505
|
let obj = {};
|
|
407
506
|
$options.forEach(
|
|
@@ -448,54 +547,23 @@
|
|
|
448
547
|
Array.isArray(value) ? value : value ? [value] : [],
|
|
449
548
|
);
|
|
450
549
|
|
|
451
|
-
$: ({
|
|
452
|
-
controlType,
|
|
453
|
-
optionsSource,
|
|
454
|
-
valueColumn,
|
|
455
|
-
labelColumn,
|
|
456
|
-
iconColumn,
|
|
457
|
-
colorColumn,
|
|
458
|
-
customOptions,
|
|
459
|
-
optionsViewMode,
|
|
460
|
-
role,
|
|
461
|
-
readonly,
|
|
462
|
-
disabled,
|
|
463
|
-
error,
|
|
464
|
-
color,
|
|
465
|
-
background,
|
|
466
|
-
} = cellOptions);
|
|
467
|
-
|
|
468
|
-
// Handle Options from Data Source
|
|
469
|
-
const dataSourceStore = memo(cellOptions?.datasource ?? {});
|
|
470
|
-
$: dataSourceStore.set(cellOptions.datasource);
|
|
471
|
-
$: fetch = createFetch($dataSourceStore);
|
|
472
|
-
$: if (optionsSource == "data") {
|
|
473
|
-
initLimit = 15;
|
|
474
|
-
isInitialLoad = true;
|
|
475
|
-
}
|
|
476
|
-
$: query = QueryUtils.buildQuery(cellOptions.filter);
|
|
477
550
|
$: inputSelect = controlType == "inputSelect";
|
|
478
551
|
|
|
479
|
-
$:
|
|
480
|
-
|
|
481
|
-
query,
|
|
482
|
-
sortColumn: cellOptions.sortColumn,
|
|
483
|
-
sortOrder: cellOptions.sortOrder,
|
|
484
|
-
limit: initLimit,
|
|
485
|
-
});
|
|
552
|
+
$: defaultQuery = QueryUtils.buildQuery(filter || []);
|
|
553
|
+
$: fetch?.update?.({ query: defaultQuery });
|
|
486
554
|
|
|
487
555
|
$: cellState.syncFetch($fetch);
|
|
488
556
|
$: cellState.loadDataOptions($fetch?.rows);
|
|
489
557
|
|
|
490
558
|
// React to property changes
|
|
491
|
-
$: cellState.refresh(
|
|
559
|
+
$: cellState.refresh($dataSourceStore, optionsSource);
|
|
560
|
+
|
|
561
|
+
$: cellState.reload(
|
|
492
562
|
fieldSchema,
|
|
493
|
-
optionsSource,
|
|
494
563
|
labelColumn,
|
|
495
564
|
valueColumn,
|
|
496
565
|
iconColumn,
|
|
497
566
|
colorColumn,
|
|
498
|
-
$dataSourceStore,
|
|
499
567
|
customOptions,
|
|
500
568
|
);
|
|
501
569
|
|
|
@@ -510,18 +578,15 @@
|
|
|
510
578
|
$: inEdit = $cellState == "Editing";
|
|
511
579
|
$: pills = optionsViewMode == "pills";
|
|
512
580
|
$: bullets = optionsViewMode == "bullets";
|
|
581
|
+
$: plaintext = optionsViewMode == "text";
|
|
513
582
|
|
|
514
583
|
$: multi =
|
|
515
584
|
fieldSchema && fieldSchema.type ? fieldSchema.type == "array" : multi;
|
|
516
585
|
|
|
517
|
-
$: placeholder =
|
|
586
|
+
$: placeholder = cellOptions.placeholder || "";
|
|
518
587
|
$: icon = searchTerm && isEmpty ? "ph ph-magnifying-glass" : cellOptions.icon;
|
|
519
588
|
$: open = $editorState == "Open";
|
|
520
589
|
|
|
521
|
-
const focus = (node) => {
|
|
522
|
-
node?.focus();
|
|
523
|
-
};
|
|
524
|
-
|
|
525
590
|
onMount(() => {
|
|
526
591
|
if (autofocus)
|
|
527
592
|
setTimeout(() => {
|
|
@@ -543,15 +608,15 @@
|
|
|
543
608
|
class:disabled
|
|
544
609
|
class:readonly
|
|
545
610
|
class:error
|
|
546
|
-
style:color
|
|
547
|
-
style:background
|
|
548
611
|
class:inline={role == "inlineInput"}
|
|
549
612
|
class:tableCell={role == "tableCell"}
|
|
550
613
|
class:formInput={role == "formInput"}
|
|
551
614
|
class:has-popup={controlType == "select"}
|
|
552
615
|
class:open-popup={open}
|
|
616
|
+
style:color
|
|
617
|
+
style:background
|
|
553
618
|
on:focusin={cellState.focus}
|
|
554
|
-
on:focusout={cellState.focusout}
|
|
619
|
+
on:focusout={controlType != "inputSelect" ? cellState.focusout : undefined}
|
|
555
620
|
on:keydown={editorState.handleKeyboard}
|
|
556
621
|
on:mousedown={cellState.toggle}
|
|
557
622
|
>
|
|
@@ -581,7 +646,7 @@
|
|
|
581
646
|
{#if pills}
|
|
582
647
|
<div class="loope"></div>
|
|
583
648
|
{/if}
|
|
584
|
-
<span> {labels[val] || val} </span>
|
|
649
|
+
<span> {$labels[val] || val} </span>
|
|
585
650
|
</div>
|
|
586
651
|
{/each}
|
|
587
652
|
</div>
|
|
@@ -597,24 +662,24 @@
|
|
|
597
662
|
if (!multi) localValue[0] = e.target.value?.trim();
|
|
598
663
|
editorState.filterOptions(e.target.value);
|
|
599
664
|
}}
|
|
600
|
-
|
|
665
|
+
on:focusout={cellState.focusout}
|
|
601
666
|
{placeholder}
|
|
602
667
|
/>
|
|
603
|
-
<div
|
|
668
|
+
<div
|
|
669
|
+
class="control-icon"
|
|
670
|
+
style:border-left="1px solid var(--spectrum-global-color-blue-400)"
|
|
671
|
+
style:padding-left="0.75rem"
|
|
672
|
+
>
|
|
604
673
|
<i class="ph ph-caret-down"></i>
|
|
605
674
|
</div>
|
|
606
675
|
{:else}
|
|
607
676
|
<div class="value" class:placeholder={isEmpty && !searchTerm}>
|
|
608
|
-
{#if isEmpty
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
{multi || localValue.length > 1
|
|
615
|
-
? localValue.join(", ")
|
|
616
|
-
: labels[localValue[0]] || localValue[0]}
|
|
617
|
-
</span>
|
|
677
|
+
{#if isEmpty}
|
|
678
|
+
{#if open}
|
|
679
|
+
{searchTerm ? searchTerm : "Type to search..."}
|
|
680
|
+
{:else}
|
|
681
|
+
{loading ? "Loading..." : placeholder}
|
|
682
|
+
{/if}
|
|
618
683
|
{:else}
|
|
619
684
|
<div
|
|
620
685
|
class="items"
|
|
@@ -622,21 +687,28 @@
|
|
|
622
687
|
class:bullets
|
|
623
688
|
style:justify-content={cellOptions.align ?? "flex-start"}
|
|
624
689
|
>
|
|
625
|
-
{#
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
<
|
|
633
|
-
|
|
634
|
-
|
|
690
|
+
{#if plaintext}
|
|
691
|
+
{#each localValue as val, idx (val)}
|
|
692
|
+
{$labels[val] || val}
|
|
693
|
+
{idx < localValue.length - 1 ? ", " : ""}
|
|
694
|
+
{/each}
|
|
695
|
+
{:else}
|
|
696
|
+
{#each localValue as val, idx}
|
|
697
|
+
<div
|
|
698
|
+
class="item"
|
|
699
|
+
style:--option-color={$colors[val] ||
|
|
700
|
+
colorsArray[idx % colorsArray.length]}
|
|
701
|
+
>
|
|
702
|
+
<div class="loope"></div>
|
|
703
|
+
<span> {isObjects ? "JSON" : $labels[val] || val} </span>
|
|
704
|
+
</div>
|
|
705
|
+
{/each}
|
|
706
|
+
{/if}
|
|
635
707
|
</div>
|
|
636
708
|
{/if}
|
|
637
709
|
</div>
|
|
638
710
|
{#if !readonly && (role == "formInput" || inEdit)}
|
|
639
|
-
<i class="ph ph-caret-down control-icon"
|
|
711
|
+
<i class="ph ph-caret-down control-icon"></i>
|
|
640
712
|
{/if}
|
|
641
713
|
{/if}
|
|
642
714
|
</div>
|
|
@@ -644,9 +716,16 @@
|
|
|
644
716
|
<!-- svelte-ignore a11y-no-static-element-interactions -->
|
|
645
717
|
<!-- svelte-ignore a11y-click-events-have-key-events -->
|
|
646
718
|
{#if inEdit}
|
|
647
|
-
<SuperPopover
|
|
719
|
+
<SuperPopover
|
|
720
|
+
{anchor}
|
|
721
|
+
useAnchorWidth
|
|
722
|
+
minWidth={pickerWidth}
|
|
723
|
+
align="left"
|
|
724
|
+
maxHeight={250}
|
|
725
|
+
{open}
|
|
726
|
+
>
|
|
648
727
|
<div class="picker" on:mousedown|stopPropagation|preventDefault>
|
|
649
|
-
{#if searchTerm && !isEmpty}
|
|
728
|
+
{#if searchTerm && !inputSelect && !isEmpty}
|
|
650
729
|
<div class="searchControl">
|
|
651
730
|
<i
|
|
652
731
|
class="search-icon ph ph-magnifying-glass"
|
|
@@ -662,12 +741,14 @@
|
|
|
662
741
|
on:mouseleave={() => (focusedOptionIdx = -1)}
|
|
663
742
|
on:scroll={optionsSource == "data" ? editorState.handleScroll : null}
|
|
664
743
|
>
|
|
665
|
-
{#if
|
|
744
|
+
{#if $fetch?.loading && !$fetch?.loaded}
|
|
666
745
|
<div class="option loading">
|
|
667
746
|
<i class="ph ph-spinner spin"></i>
|
|
668
747
|
Loading...
|
|
669
748
|
</div>
|
|
670
|
-
{
|
|
749
|
+
{/if}
|
|
750
|
+
|
|
751
|
+
{#if filteredOptions?.length}
|
|
671
752
|
{#each filteredOptions as option, idx (idx)}
|
|
672
753
|
<div
|
|
673
754
|
class="option"
|
|
@@ -686,18 +767,20 @@
|
|
|
686
767
|
: "ph-fill ph-square"}
|
|
687
768
|
style:color={$colors[option]}
|
|
688
769
|
></i>
|
|
689
|
-
{labels[option] || option}
|
|
770
|
+
{$labels[option] || option}
|
|
690
771
|
</span>
|
|
691
772
|
<i class="ph ph-check"></i>
|
|
692
773
|
</div>
|
|
693
774
|
{/each}
|
|
694
|
-
{#if
|
|
775
|
+
{#if $fetch?.loading}
|
|
695
776
|
<div class="option loading">
|
|
696
777
|
<i class="ph ph-spinner spin"></i>
|
|
697
778
|
Loading more...
|
|
698
779
|
</div>
|
|
699
780
|
{/if}
|
|
700
|
-
{
|
|
781
|
+
{/if}
|
|
782
|
+
|
|
783
|
+
{#if filteredOptions?.length === 0 && $fetch.loaded}
|
|
701
784
|
<div class="option">
|
|
702
785
|
<span>
|
|
703
786
|
<i class="ri-close-line"></i>
|
|
@@ -714,7 +797,7 @@
|
|
|
714
797
|
.searchControl {
|
|
715
798
|
display: flex;
|
|
716
799
|
align-items: center;
|
|
717
|
-
height: 2rem;
|
|
800
|
+
min-height: 2rem;
|
|
718
801
|
border-bottom: 1px solid var(--spectrum-global-color-gray-300);
|
|
719
802
|
}
|
|
720
803
|
.options {
|
|
@@ -727,13 +810,13 @@
|
|
|
727
810
|
}
|
|
728
811
|
|
|
729
812
|
.option {
|
|
730
|
-
min-height: 1.
|
|
813
|
+
min-height: 1.85rem;
|
|
731
814
|
display: flex;
|
|
732
815
|
gap: 0.5rem;
|
|
733
816
|
align-items: center;
|
|
734
817
|
justify-content: space-between;
|
|
735
818
|
cursor: pointer;
|
|
736
|
-
padding:
|
|
819
|
+
padding: 0rem 0.5rem;
|
|
737
820
|
|
|
738
821
|
&.selected {
|
|
739
822
|
color: var(--spectrum-global-color-gray-800);
|