@poirazis/supercomponents-shared 1.0.18 → 1.0.20
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 +3350 -3325
- package/dist/index.umd.cjs +7 -7
- package/package.json +1 -1
- package/src/lib/SuperForm/SuperForm.svelte +3 -0
- package/src/lib/SuperTable/SuperTable.svelte +5 -5
- package/src/lib/SuperTableCells/CellNumber.svelte +91 -64
- package/src/lib/SuperTableCells/CellString.svelte +8 -0
- package/src/lib/SuperTableColumn/parts/SuperColumnBody.svelte +1 -1
package/package.json
CHANGED
@@ -27,6 +27,7 @@
|
|
27
27
|
export let initialFormStep: string | number = 1;
|
28
28
|
export let disableSchemaValidation: boolean = false;
|
29
29
|
export let editAutoColumns: boolean = false;
|
30
|
+
export let provideContext: boolean = true;
|
30
31
|
|
31
32
|
// Export the full form API to be used by parents
|
32
33
|
export let form;
|
@@ -73,6 +74,7 @@
|
|
73
74
|
if (type !== "Update") {
|
74
75
|
return {};
|
75
76
|
}
|
77
|
+
|
76
78
|
const dsType = dataSource?.type;
|
77
79
|
if (dsType !== "table" && dsType !== "viewV2") {
|
78
80
|
return {};
|
@@ -136,6 +138,7 @@
|
|
136
138
|
{disableSchemaValidation}
|
137
139
|
{editAutoColumns}
|
138
140
|
{currentStep}
|
141
|
+
{provideContext}
|
139
142
|
on:change
|
140
143
|
on:reset
|
141
144
|
>
|
@@ -651,10 +651,8 @@
|
|
651
651
|
init() {
|
652
652
|
return "Init";
|
653
653
|
},
|
654
|
-
|
655
|
-
|
656
|
-
this.enrichRows();
|
657
|
-
this.calculateRowBoundaries();
|
654
|
+
refresh() {
|
655
|
+
stbData?.refresh();
|
658
656
|
},
|
659
657
|
enrichRows() {},
|
660
658
|
scrollToTop() {
|
@@ -972,7 +970,9 @@
|
|
972
970
|
canInsert,
|
973
971
|
$stbSortColumn,
|
974
972
|
fetchOnScroll,
|
975
|
-
rowHeight
|
973
|
+
rowHeight,
|
974
|
+
$stbSortColumn,
|
975
|
+
$stbSortOrder
|
976
976
|
);
|
977
977
|
|
978
978
|
// Scroll to Top when filter changes
|
@@ -1,104 +1,125 @@
|
|
1
|
-
<script>
|
2
|
-
import {
|
1
|
+
<script lang="ts">
|
2
|
+
import {
|
3
|
+
createEventDispatcher,
|
4
|
+
getContext,
|
5
|
+
onDestroy,
|
6
|
+
onMount,
|
7
|
+
} from "svelte";
|
3
8
|
import fsm from "svelte-fsm";
|
4
9
|
|
5
10
|
const { processStringSync } = getContext("sdk");
|
6
11
|
const context = getContext("context");
|
7
12
|
const dispatch = createEventDispatcher();
|
8
13
|
|
9
|
-
export let value;
|
10
|
-
export let formattedValue;
|
11
|
-
export let cellOptions;
|
12
|
-
export let autofocus;
|
14
|
+
export let value: number | null;
|
15
|
+
export let formattedValue: string | undefined;
|
16
|
+
export let cellOptions: any;
|
17
|
+
export let autofocus: boolean;
|
13
18
|
|
14
|
-
let originalValue = value;
|
15
|
-
let inEdit;
|
16
|
-
let localValue = value;
|
17
|
-
let editor;
|
18
|
-
|
19
|
-
|
20
|
-
$: inline = cellOptions.role == "inlineInput";
|
21
|
-
$: isDirty = inEdit && originalValue != localValue;
|
22
|
-
$: formattedValue = cellOptions.template
|
23
|
-
? processStringSync(cellOptions.template, {
|
24
|
-
...$context,
|
25
|
-
value: localValue,
|
26
|
-
})
|
27
|
-
: undefined;
|
28
|
-
|
29
|
-
$: placeholder =
|
30
|
-
cellOptions.readonly || cellOptions.disabled
|
31
|
-
? ""
|
32
|
-
: cellOptions.placeholder || "";
|
19
|
+
let originalValue: number | null = value;
|
20
|
+
let inEdit: boolean;
|
21
|
+
let localValue: number | null = value;
|
22
|
+
let editor: HTMLInputElement;
|
23
|
+
let lastEdit: Date | undefined;
|
24
|
+
let timer: ReturnType<typeof setTimeout>;
|
33
25
|
|
34
26
|
export let cellState = fsm(cellOptions.initialState ?? "View", {
|
35
27
|
"*": {
|
36
|
-
goTo(state) {
|
28
|
+
goTo(state: string) {
|
37
29
|
return state;
|
38
30
|
},
|
39
31
|
},
|
40
32
|
View: {
|
41
|
-
|
42
|
-
|
33
|
+
_enter() {
|
34
|
+
localValue = value;
|
43
35
|
},
|
44
|
-
|
45
|
-
|
46
|
-
|
36
|
+
reset() {
|
37
|
+
originalValue = value;
|
38
|
+
localValue = value;
|
39
|
+
lastEdit = undefined;
|
47
40
|
return "View";
|
48
41
|
},
|
49
|
-
|
50
|
-
|
51
|
-
unfocus() {
|
52
|
-
return "View";
|
42
|
+
focus() {
|
43
|
+
if (!cellOptions.readonly && !cellOptions.disabled) return "Editing";
|
53
44
|
},
|
54
45
|
},
|
55
|
-
Error: { check: "View" },
|
56
46
|
Editing: {
|
57
47
|
_enter() {
|
58
|
-
originalValue =
|
48
|
+
originalValue = value;
|
59
49
|
editor?.focus();
|
60
50
|
dispatch("enteredit");
|
61
51
|
},
|
62
52
|
_exit() {
|
53
|
+
originalValue = undefined;
|
63
54
|
dispatch("exitedit");
|
64
|
-
},
|
65
|
-
focusout() {
|
66
|
-
if (isDirty && !cellOptions.debounce) dispatch("change", localValue);
|
67
|
-
|
68
55
|
dispatch("focusout");
|
69
|
-
return "View";
|
70
56
|
},
|
71
57
|
clear() {
|
72
58
|
if (cellOptions.debounce) dispatch("change", null);
|
59
|
+
lastEdit = new Date();
|
73
60
|
localValue = null;
|
74
61
|
},
|
62
|
+
focusout(e: FocusEvent) {
|
63
|
+
this.submit();
|
64
|
+
},
|
65
|
+
submit() {
|
66
|
+
if (isDirty) {
|
67
|
+
dispatch("change", localValue);
|
68
|
+
}
|
69
|
+
return "View";
|
70
|
+
},
|
75
71
|
cancel() {
|
76
72
|
value = originalValue;
|
73
|
+
dispatch("cancel");
|
74
|
+
return "View";
|
75
|
+
},
|
76
|
+
debounce(e: KeyboardEvent) {
|
77
|
+
if (
|
78
|
+
(e.key.length === 1 &&
|
79
|
+
e.key !== "." &&
|
80
|
+
isNaN(Number(e.key)) &&
|
81
|
+
!e.ctrlKey) ||
|
82
|
+
e.keyCode == 32 ||
|
83
|
+
(e.key === "." && e.target.value.toString().indexOf(".") > -1)
|
84
|
+
) {
|
85
|
+
e.preventDefault();
|
86
|
+
return;
|
87
|
+
}
|
88
|
+
localValue = Number(e.target.value);
|
89
|
+
lastEdit = new Date();
|
90
|
+
if (cellOptions?.debounce) {
|
91
|
+
clearTimeout(timer);
|
92
|
+
timer = setTimeout(() => {
|
93
|
+
dispatch("change", localValue);
|
94
|
+
}, cellOptions.debounce ?? 0);
|
95
|
+
}
|
96
|
+
},
|
97
|
+
handleKeyboard(e: KeyboardEvent) {
|
98
|
+
if (e.key == "Enter") this.submit();
|
99
|
+
if (e.key == "Escape") this.cancel();
|
77
100
|
},
|
78
101
|
},
|
79
102
|
});
|
80
103
|
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
}
|
98
|
-
};
|
104
|
+
$: inEdit = $cellState == "Editing";
|
105
|
+
$: inline = cellOptions.role == "inlineInput";
|
106
|
+
$: isDirty = inEdit && originalValue != localValue;
|
107
|
+
$: formattedValue = cellOptions.template
|
108
|
+
? processStringSync(cellOptions.template, {
|
109
|
+
...$context,
|
110
|
+
value: localValue,
|
111
|
+
})
|
112
|
+
: undefined;
|
113
|
+
|
114
|
+
$: placeholder =
|
115
|
+
cellOptions.readonly || cellOptions.disabled
|
116
|
+
? ""
|
117
|
+
: cellOptions.placeholder || "";
|
118
|
+
|
119
|
+
$: cellState.reset(value);
|
99
120
|
|
100
|
-
function focus(element) {
|
101
|
-
setTimeout(element?.focus(), 10);
|
121
|
+
function focus(element: HTMLElement) {
|
122
|
+
setTimeout(() => element?.focus(), 10);
|
102
123
|
}
|
103
124
|
|
104
125
|
onMount(() => {
|
@@ -108,6 +129,11 @@
|
|
108
129
|
editor?.focus();
|
109
130
|
}, 30);
|
110
131
|
});
|
132
|
+
|
133
|
+
onDestroy(() => {
|
134
|
+
clearTimeout(timer);
|
135
|
+
cellState.reset();
|
136
|
+
});
|
111
137
|
</script>
|
112
138
|
|
113
139
|
<!-- svelte-ignore a11y-no-static-element-interactions -->
|
@@ -148,8 +174,9 @@
|
|
148
174
|
: "right "}
|
149
175
|
placeholder={cellOptions?.placeholder}
|
150
176
|
bind:value={localValue}
|
151
|
-
on:keydown={(e) => debounce(e)}
|
152
|
-
on:focusout={cellState.focusout}
|
177
|
+
on:keydown={(e) => cellState.debounce(e)}
|
178
|
+
on:focusout={(e) => cellState.focusout(e)}
|
179
|
+
on:keyup={(e) => cellState.handleKeyboard(e)}
|
153
180
|
use:focus
|
154
181
|
/>
|
155
182
|
<i class="ri-close-line clearIcon" on:mousedown|self={cellState.clear}> </i>
|
@@ -120,6 +120,14 @@
|
|
120
120
|
clearTimeout(timer);
|
121
121
|
cellState.reset();
|
122
122
|
});
|
123
|
+
|
124
|
+
$: if (inEdit)
|
125
|
+
console.log(
|
126
|
+
"Entering edit mode for cell",
|
127
|
+
value,
|
128
|
+
localValue,
|
129
|
+
originalValue
|
130
|
+
);
|
123
131
|
</script>
|
124
132
|
|
125
133
|
<!-- svelte-ignore a11y-no-noninteractive-tabindex -->
|