@lobb-js/studio 0.10.0 → 0.11.0

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,33 @@
1
+ <script lang="ts">
2
+ import type { EnumOption } from "@lobb-js/core";
3
+
4
+ interface Props {
5
+ value: any;
6
+ enum: EnumOption[] | string[];
7
+ }
8
+
9
+ const { value, enum: enumOptions }: Props = $props();
10
+
11
+ const levelClasses: Record<string, string> = {
12
+ success: "bg-green-100 text-green-700 border-green-200",
13
+ warning: "bg-yellow-100 text-yellow-700 border-yellow-300",
14
+ danger: "bg-red-100 text-red-700 border-red-200",
15
+ info: "bg-blue-100 text-blue-700 border-blue-200",
16
+ neutral: "bg-gray-100 text-gray-600 border-gray-200",
17
+ muted: "bg-gray-50 text-gray-400 border-gray-100",
18
+ };
19
+
20
+ const normalizedOptions = $derived(
21
+ (enumOptions as Array<string | EnumOption>).map((e) =>
22
+ typeof e === "string" ? { value: e, level: "neutral" as const } : e,
23
+ ),
24
+ );
25
+
26
+ const enumOption = $derived(normalizedOptions.find((e) => e.value === value));
27
+ </script>
28
+
29
+ {#if enumOption}
30
+ <span class="px-2 py-0.5 rounded-full text-xs font-medium border {levelClasses[enumOption.level]}">
31
+ {value}
32
+ </span>
33
+ {/if}
@@ -0,0 +1,8 @@
1
+ import type { EnumOption } from "@lobb-js/core";
2
+ interface Props {
3
+ value: any;
4
+ enum: EnumOption[] | string[];
5
+ }
6
+ declare const EnumBadge: import("svelte").Component<Props, {}, "">;
7
+ type EnumBadge = ReturnType<typeof EnumBadge>;
8
+ export default EnumBadge;
@@ -3,6 +3,7 @@
3
3
  import { ExternalLink } from "lucide-svelte";
4
4
  import UpdateDetailViewButton from "../detailView/update/updateDetailViewButton.svelte";
5
5
  import { getField } from "./utils";
6
+ import EnumBadge from "./enumBadge.svelte";
6
7
  import _ from "lodash";
7
8
  import { getStudioContext } from "../../context";
8
9
 
@@ -66,6 +67,8 @@
66
67
  {:else}
67
68
  <div class="text-muted-foreground">PARENT ID</div>
68
69
  {/if}
70
+ {:else if field?.enum}
71
+ <EnumBadge {value} enum={field.enum} />
69
72
  {:else if field.type === "datetime"}
70
73
  {@const date = new Date(value).toLocaleDateString()}
71
74
  {@const time = new Date(value).toLocaleTimeString()}
@@ -7,6 +7,8 @@
7
7
  import FieldCustomInput from "./fieldCustomInput.svelte";
8
8
  import Input from "../ui/input/input.svelte";
9
9
  import * as Select from "../../components/ui/select/index";
10
+ import EnumBadge from "../dataTable/enumBadge.svelte";
11
+ import type { EnumOption } from "@lobb-js/core";
10
12
  import Textarea from "../ui/textarea/textarea.svelte";
11
13
  import ForeingKeyInput from "../foreingKeyInput.svelte";
12
14
  import ExtensionsComponents from "../extensionsComponents.svelte";
@@ -91,6 +93,38 @@
91
93
  {destructive}
92
94
  />
93
95
  </ExtensionsComponents>
96
+ {:else if field.type === "string" && field.enum}
97
+ {@const rawEnum = field.enum as (string | EnumOption)[]}
98
+ {@const enumOptions = rawEnum.map((e): EnumOption => typeof e === "string" ? { value: e, level: "neutral" } : e)}
99
+ <Select.Root
100
+ type="single"
101
+ onValueChange={(newValue) => {
102
+ value = newValue;
103
+ }}
104
+ >
105
+ <Select.Trigger
106
+ placeholder={ui?.placeholder ? ui.placeholder : "NULL"}
107
+ class="
108
+ h-9 w-full bg-muted/30 pr-8
109
+ {destructive ? 'border-destructive bg-destructive/10' : ''}
110
+ "
111
+ >
112
+ {#if value}
113
+ <EnumBadge {value} enum={enumOptions} />
114
+ {:else}
115
+ NULL
116
+ {/if}
117
+ </Select.Trigger>
118
+ <Select.Content>
119
+ <Select.Group>
120
+ {#each enumOptions as option}
121
+ <Select.Item value={option.value} label={option.value}>
122
+ <EnumBadge value={option.value} enum={enumOptions} />
123
+ </Select.Item>
124
+ {/each}
125
+ </Select.Group>
126
+ </Select.Content>
127
+ </Select.Root>
94
128
  {:else if field.type === "string"}
95
129
  <!-- if the string has a validator of type enum -->
96
130
  {#if field.validators && field.validators.enum}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lobb-js/studio",
3
- "version": "0.10.0",
3
+ "version": "0.11.0",
4
4
  "type": "module",
5
5
  "publishConfig": {
6
6
  "access": "public"
@@ -41,6 +41,7 @@
41
41
  "postpublish": "./scripts/postpublish.sh"
42
42
  },
43
43
  "devDependencies": {
44
+ "@lobb-js/core": "^0.17.0",
44
45
  "@chromatic-com/storybook": "^4.1.2",
45
46
  "@storybook/addon-a11y": "^10.0.1",
46
47
  "@storybook/addon-docs": "^10.0.1",
@@ -0,0 +1,33 @@
1
+ <script lang="ts">
2
+ import type { EnumOption } from "@lobb-js/core";
3
+
4
+ interface Props {
5
+ value: any;
6
+ enum: EnumOption[] | string[];
7
+ }
8
+
9
+ const { value, enum: enumOptions }: Props = $props();
10
+
11
+ const levelClasses: Record<string, string> = {
12
+ success: "bg-green-100 text-green-700 border-green-200",
13
+ warning: "bg-yellow-100 text-yellow-700 border-yellow-300",
14
+ danger: "bg-red-100 text-red-700 border-red-200",
15
+ info: "bg-blue-100 text-blue-700 border-blue-200",
16
+ neutral: "bg-gray-100 text-gray-600 border-gray-200",
17
+ muted: "bg-gray-50 text-gray-400 border-gray-100",
18
+ };
19
+
20
+ const normalizedOptions = $derived(
21
+ (enumOptions as Array<string | EnumOption>).map((e) =>
22
+ typeof e === "string" ? { value: e, level: "neutral" as const } : e,
23
+ ),
24
+ );
25
+
26
+ const enumOption = $derived(normalizedOptions.find((e) => e.value === value));
27
+ </script>
28
+
29
+ {#if enumOption}
30
+ <span class="px-2 py-0.5 rounded-full text-xs font-medium border {levelClasses[enumOption.level]}">
31
+ {value}
32
+ </span>
33
+ {/if}
@@ -3,6 +3,7 @@
3
3
  import { ExternalLink } from "lucide-svelte";
4
4
  import UpdateDetailViewButton from "../detailView/update/updateDetailViewButton.svelte";
5
5
  import { getField } from "./utils";
6
+ import EnumBadge from "./enumBadge.svelte";
6
7
  import _ from "lodash";
7
8
  import { getStudioContext } from "../../context";
8
9
 
@@ -66,6 +67,8 @@
66
67
  {:else}
67
68
  <div class="text-muted-foreground">PARENT ID</div>
68
69
  {/if}
70
+ {:else if field?.enum}
71
+ <EnumBadge {value} enum={field.enum} />
69
72
  {:else if field.type === "datetime"}
70
73
  {@const date = new Date(value).toLocaleDateString()}
71
74
  {@const time = new Date(value).toLocaleTimeString()}
@@ -7,6 +7,8 @@
7
7
  import FieldCustomInput from "./fieldCustomInput.svelte";
8
8
  import Input from "../ui/input/input.svelte";
9
9
  import * as Select from "../../components/ui/select/index";
10
+ import EnumBadge from "../dataTable/enumBadge.svelte";
11
+ import type { EnumOption } from "@lobb-js/core";
10
12
  import Textarea from "../ui/textarea/textarea.svelte";
11
13
  import ForeingKeyInput from "../foreingKeyInput.svelte";
12
14
  import ExtensionsComponents from "../extensionsComponents.svelte";
@@ -91,6 +93,38 @@
91
93
  {destructive}
92
94
  />
93
95
  </ExtensionsComponents>
96
+ {:else if field.type === "string" && field.enum}
97
+ {@const rawEnum = field.enum as (string | EnumOption)[]}
98
+ {@const enumOptions = rawEnum.map((e): EnumOption => typeof e === "string" ? { value: e, level: "neutral" } : e)}
99
+ <Select.Root
100
+ type="single"
101
+ onValueChange={(newValue) => {
102
+ value = newValue;
103
+ }}
104
+ >
105
+ <Select.Trigger
106
+ placeholder={ui?.placeholder ? ui.placeholder : "NULL"}
107
+ class="
108
+ h-9 w-full bg-muted/30 pr-8
109
+ {destructive ? 'border-destructive bg-destructive/10' : ''}
110
+ "
111
+ >
112
+ {#if value}
113
+ <EnumBadge {value} enum={enumOptions} />
114
+ {:else}
115
+ NULL
116
+ {/if}
117
+ </Select.Trigger>
118
+ <Select.Content>
119
+ <Select.Group>
120
+ {#each enumOptions as option}
121
+ <Select.Item value={option.value} label={option.value}>
122
+ <EnumBadge value={option.value} enum={enumOptions} />
123
+ </Select.Item>
124
+ {/each}
125
+ </Select.Group>
126
+ </Select.Content>
127
+ </Select.Root>
94
128
  {:else if field.type === "string"}
95
129
  <!-- if the string has a validator of type enum -->
96
130
  {#if field.validators && field.validators.enum}