zenno: format
This commit is contained in:
@@ -17,7 +17,7 @@
|
||||
|
||||
const charas = $derived(characters ?? []);
|
||||
|
||||
const key = (v: Character) => ({id: v.chara_id, name: v.name});
|
||||
const key = (v: Character) => ({ id: v.chara_id, name: v.name });
|
||||
</script>
|
||||
|
||||
<Pick {id} items={charas} {key} bind:value {option} class={className} {required} />
|
||||
|
||||
+19
-19
@@ -3,17 +3,17 @@
|
||||
import type { ClassValue } from 'svelte/elements';
|
||||
import { stringsearch } from './stringsearch';
|
||||
|
||||
interface Props {
|
||||
id: string;
|
||||
items: T[];
|
||||
key: (t: T) => {id: number, name: string};
|
||||
value: T | undefined;
|
||||
option?: Snippet<[T]>;
|
||||
class?: ClassValue | null;
|
||||
required?: boolean;
|
||||
}
|
||||
interface Props {
|
||||
id: string;
|
||||
items: T[];
|
||||
key: (t: T) => { id: number; name: string };
|
||||
value: T | undefined;
|
||||
option?: Snippet<[T]>;
|
||||
class?: ClassValue | null;
|
||||
required?: boolean;
|
||||
}
|
||||
|
||||
let {id, items, key, value = $bindable(), option, class: className, required = false}: Props = $props();
|
||||
let { id, items, key, value = $bindable(), option, class: className, required = false }: Props = $props();
|
||||
|
||||
let popover: HTMLElement | undefined = $state();
|
||||
let optionsContainer: HTMLElement | undefined = $state();
|
||||
@@ -21,14 +21,14 @@
|
||||
|
||||
let search = $state('');
|
||||
|
||||
const its = $derived(items ?? []);
|
||||
const searched = $derived(stringsearch(search, its, (v) => key(v).name) || its);
|
||||
const its = $derived(items ?? []);
|
||||
const searched = $derived(stringsearch(search, its, (v) => key(v).name) || its);
|
||||
|
||||
$effect(() => {
|
||||
if (required && value == null && its.length > 0) {
|
||||
value = its[0];
|
||||
}
|
||||
});
|
||||
$effect(() => {
|
||||
if (required && value == null && its.length > 0) {
|
||||
value = its[0];
|
||||
}
|
||||
});
|
||||
|
||||
function setByElem(o: HTMLElement) {
|
||||
const j = parseInt(o.dataset.pickId ?? '');
|
||||
@@ -126,8 +126,8 @@
|
||||
</div>
|
||||
{/if}
|
||||
{#each searched as c (key(c).id)}
|
||||
{@const v = value != null ? key(value).id : 0}
|
||||
{@const k = key(c)}
|
||||
{@const v = value != null ? key(value).id : 0}
|
||||
{@const k = key(c)}
|
||||
<div
|
||||
class="h-8 w-full text-lg hover:cursor-pointer hover:bg-mist-300 hover:dark:bg-mist-900"
|
||||
role="option"
|
||||
|
||||
@@ -156,10 +156,10 @@ export interface SparkGroup {
|
||||
|
||||
export function byGroup(sparks: Spark[]): SparkGroup[] {
|
||||
const r = new Map<number, SparkGroup>();
|
||||
for (const {spark_id, name, description, spark_group, type, effects} of sparks) {
|
||||
for (const { spark_id, name, description, spark_group, type, effects } of sparks) {
|
||||
let g = r.get(spark_group);
|
||||
if (g == null) {
|
||||
g = {spark_group, name, description, type, effects, spark_ids: []};
|
||||
g = { spark_group, name, description, type, effects, spark_ids: [] };
|
||||
r.set(spark_group, g);
|
||||
}
|
||||
g.spark_ids.push(spark_id);
|
||||
|
||||
Reference in New Issue
Block a user