@poirazis/supercomponents-shared 1.0.18 → 1.0.19

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@poirazis/supercomponents-shared",
3
- "version": "1.0.18",
3
+ "version": "1.0.19",
4
4
  "description": "Shared Svelte components library",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",
@@ -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
- async refresh() {
655
- if (stbData.loaded) await stbData?.refresh();
656
- this.enrichRows();
657
- this.calculateRowBoundaries();
654
+ refresh() {
655
+ stbData?.refresh();
658
656
  },
659
657
  enrichRows() {},
660
658
  scrollToTop() {
@@ -1,104 +1,119 @@
1
- <script>
2
- import { createEventDispatcher, getContext, onMount } from "svelte";
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
- $: inEdit = $cellState == "Editing";
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
  },
31
+ reset() {
32
+ localValue = value;
33
+ lastEdit = undefined;
34
+ return "View";
35
+ },
39
36
  },
40
37
  View: {
38
+ _enter() {
39
+ localValue = value;
40
+ },
41
41
  focus() {
42
42
  if (!cellOptions.readonly && !cellOptions.disabled) return "Editing";
43
43
  },
44
44
  },
45
- Hovered: {
46
- cancel: () => {
47
- return "View";
48
- },
49
- },
50
- Focused: {
51
- unfocus() {
52
- return "View";
53
- },
54
- },
55
- Error: { check: "View" },
56
45
  Editing: {
57
46
  _enter() {
58
- originalValue = localValue;
47
+ originalValue = value;
59
48
  editor?.focus();
60
49
  dispatch("enteredit");
61
50
  },
62
51
  _exit() {
52
+ originalValue = undefined;
63
53
  dispatch("exitedit");
64
- },
65
- focusout() {
66
- if (isDirty && !cellOptions.debounce) dispatch("change", localValue);
67
-
68
54
  dispatch("focusout");
69
- return "View";
70
55
  },
71
56
  clear() {
72
57
  if (cellOptions.debounce) dispatch("change", null);
58
+ lastEdit = new Date();
73
59
  localValue = null;
74
60
  },
61
+ focusout(e: FocusEvent) {
62
+ this.submit();
63
+ },
64
+ submit() {
65
+ if (isDirty) {
66
+ dispatch("change", localValue);
67
+ }
68
+ return "View";
69
+ },
75
70
  cancel() {
76
71
  value = originalValue;
72
+ dispatch("cancel");
73
+ return "View";
74
+ },
75
+ debounce(e: KeyboardEvent) {
76
+ if ((e.key.length === 1 && e.key !== "." && isNaN(Number(e.key)) && !e.ctrlKey) ||
77
+ e.keyCode == 32 ||
78
+ (e.key === "." && e.target.value.toString().indexOf(".") > -1)) {
79
+ e.preventDefault();
80
+ return;
81
+ }
82
+ localValue = Number(e.target.value);
83
+ lastEdit = new Date();
84
+ if (cellOptions?.debounce) {
85
+ clearTimeout(timer);
86
+ timer = setTimeout(() => {
87
+ dispatch("change", localValue);
88
+ }, cellOptions.debounce ?? 0);
89
+ }
90
+ },
91
+ handleKeyboard(e: KeyboardEvent) {
92
+ if (e.key == "Enter") this.submit();
93
+ if (e.key == "Escape") this.cancel();
77
94
  },
78
95
  },
79
96
  });
80
97
 
81
- let timer;
82
- const debounce = (e) => {
83
- // Abort Invalid Keys
84
- if (
85
- (e.key.length === 1 && e.key !== "." && isNaN(e.key) && !e.ctrlKey) ||
86
- e.keyCode == 32 ||
87
- (e.key === "." && e.target.value.toString().indexOf(".") > -1)
88
- ) {
89
- e.preventDefault();
90
- return;
91
- }
92
- if (cellOptions.debounce) {
93
- clearTimeout(timer);
94
- timer = setTimeout(() => {
95
- dispatch("change", localValue);
96
- }, cellOptions.debounce ?? 0);
97
- }
98
- };
98
+ $: inEdit = $cellState == "Editing";
99
+ $: inline = cellOptions.role == "inlineInput";
100
+ $: isDirty = inEdit && originalValue != localValue;
101
+ $: formattedValue = cellOptions.template
102
+ ? processStringSync(cellOptions.template, {
103
+ ...$context,
104
+ value: localValue,
105
+ })
106
+ : undefined;
107
+
108
+ $: placeholder =
109
+ cellOptions.readonly || cellOptions.disabled
110
+ ? ""
111
+ : cellOptions.placeholder || "";
99
112
 
100
- function focus(element) {
101
- setTimeout(element?.focus(), 10);
113
+ $: cellState.reset(value);
114
+
115
+ function focus(element: HTMLElement) {
116
+ setTimeout(() => element?.focus(), 10);
102
117
  }
103
118
 
104
119
  onMount(() => {
@@ -108,6 +123,11 @@
108
123
  editor?.focus();
109
124
  }, 30);
110
125
  });
126
+
127
+ onDestroy(() => {
128
+ clearTimeout(timer);
129
+ cellState.reset();
130
+ });
111
131
  </script>
112
132
 
113
133
  <!-- svelte-ignore a11y-no-static-element-interactions -->
@@ -148,8 +168,9 @@
148
168
  : "right "}
149
169
  placeholder={cellOptions?.placeholder}
150
170
  bind:value={localValue}
151
- on:keydown={(e) => debounce(e)}
152
- on:focusout={cellState.focusout}
171
+ on:keydown={(e) => cellState.debounce(e)}
172
+ on:focusout={(e) => cellState.focusout(e)}
173
+ on:keyup={(e) => cellState.handleKeyboard(e)}
153
174
  use:focus
154
175
  />
155
176
  <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 -->
@@ -34,7 +34,7 @@
34
34
  class:is-editing={editing}
35
35
  >
36
36
  {#if rows?.length}
37
- {#each $stbVisibleRows as index (index)}
37
+ {#each $stbVisibleRows as index}
38
38
  {#if rows[index]}
39
39
  <SuperColumnRow
40
40
  {isLast}