@rkosafo/cai.components 0.0.23 → 0.0.25

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.
@@ -11,7 +11,8 @@
11
11
  appShortName,
12
12
  hideSidebar = false,
13
13
  menuItems = [],
14
- logo
14
+ logo,
15
+ isActiveFunction
15
16
  }: TFSidebarProps = $props();
16
17
 
17
18
  let activeUrl = $state('');
@@ -44,7 +45,7 @@
44
45
  {#if menuItems.length > 0}
45
46
  <ul class="side-menu top relative pt-4">
46
47
  {#each menuItems as item}
47
- {@const active = activeUrl === item.path}
48
+ {@const active = isActiveFunction ? isActiveFunction(item) : activeUrl === item.path}
48
49
  {@render menuItemSnippet(item, active)}
49
50
  {/each}
50
51
  </ul>
@@ -31,6 +31,7 @@ export interface TFSidebarProps {
31
31
  hideSidebar?: boolean;
32
32
  menuItems: IMenuItem[];
33
33
  logo?: Snippet;
34
+ isActiveFunction?: (val: IMenuItem) => boolean;
34
35
  }
35
36
  export interface IMenuItem {
36
37
  title: string;
@@ -271,8 +271,7 @@
271
271
  }
272
272
 
273
273
  async function handleAction({ action, data }: { action: string; data: FormData }) {
274
- let formData = Object.fromEntries(data.entries());
275
-
274
+ let formData = data;
276
275
  try {
277
276
  isLoading = true;
278
277
  const ret = editing
@@ -166,10 +166,30 @@
166
166
  return (hidden = true);
167
167
  }
168
168
 
169
- if (
170
- typeof onaction === 'function' &&
171
- onaction({ action: returnValue, data: combinedFormData }) === false
172
- ) {
169
+ // Convert FormData into a proper object with arrays
170
+ const data: Record<string, any> = {};
171
+ combinedFormData.forEach((value, key) => {
172
+ if (data[key] !== undefined) {
173
+ // Already exists, convert to array (or push to existing array)
174
+ if (!Array.isArray(data[key])) {
175
+ data[key] = [data[key]];
176
+ }
177
+ data[key].push(value);
178
+ } else {
179
+ data[key] = value;
180
+ }
181
+ });
182
+
183
+ // Optionally cast certain values
184
+ Object.keys(data).forEach((key) => {
185
+ if (data[key] === 'true') data[key] = true;
186
+ else if (data[key] === 'false') data[key] = false;
187
+ else if (!isNaN(data[key]) && data[key] !== '' && !Array.isArray(data[key])) {
188
+ data[key] = Number(data[key]);
189
+ }
190
+ });
191
+
192
+ if (typeof onaction === 'function' && onaction({ action: returnValue, data }) === false) {
173
193
  return;
174
194
  }
175
195
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rkosafo/cai.components",
3
- "version": "0.0.23",
3
+ "version": "0.0.25",
4
4
  "files": [
5
5
  "dist",
6
6
  "!dist/**/*.test.*",