@nil-/xit 0.4.12 → 0.4.14

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/test/Frame.svelte CHANGED
@@ -1,63 +1,103 @@
1
- <script lang="ts">import { xit } from "..";
2
- import { get } from "svelte/store";
3
- let {
4
- decoder,
5
- selected = -1,
6
- load
7
- } = $props();
8
- let { signals, values, load_frame_data, load_frame_ui } = xit();
9
- const frame_info = async (tag, decoder2) => {
10
- const { values: values2, unsub } = await load_frame_data("frame_info", tag);
11
- const load2 = async (key) => {
12
- const v = values2.json(key, [], {
13
- decode: decoder2,
14
- encode: () => {
15
- return new Uint8Array();
16
- }
1
+ <script lang="ts">
2
+ import { xit, type CoDec, type Action } from "..";
3
+ import { get } from "svelte/store";
4
+
5
+ import type { Snippet } from "svelte";
6
+
7
+ type ActionItem = {
8
+ name: string;
9
+ action: Action<HTMLElement>;
10
+ url: (tag: string) => string;
11
+ };
12
+
13
+ type Props = {
14
+ decoder: CoDec<any>["decode"];
15
+ selected?: number;
16
+ load: Snippet<
17
+ [
18
+ {
19
+ tags: string[];
20
+ inputs: ActionItem[];
21
+ outputs: ActionItem[];
22
+ }
23
+ ]
24
+ >;
25
+ };
26
+
27
+ let { decoder, selected = $bindable(-1), load }: Props = $props();
28
+
29
+ let { signals, values, load_frame_data, load_frame_ui } = xit();
30
+
31
+ const frame_info = async (tag: string, decoder: CoDec<any>["decode"]) => {
32
+ const { values, unsub } = await load_frame_data("frame_info", tag);
33
+ const load = async (key: string) => {
34
+ const v = values.json(key, [] as string[], {
35
+ decode: decoder,
36
+ encode: () => {
37
+ return new Uint8Array();
38
+ }
39
+ });
40
+ return Promise.all(
41
+ get(v)
42
+ .map((v) => {
43
+ const [frame_id, mark, g] = v.split(":");
44
+ if (g !== "V") {
45
+ return;
46
+ }
47
+ if (mark === "T") {
48
+ return load_frame_ui(frame_id, tag).then((f) => {
49
+ return {
50
+ name: frame_id,
51
+ action: f,
52
+ url: (tag) => `/?frame=${frame_id}&tag=${tag}`
53
+ } satisfies ActionItem;
54
+ });
55
+ } else if (mark === "U") {
56
+ return load_frame_ui(frame_id).then((f) => {
57
+ return {
58
+ name: frame_id,
59
+ action: f,
60
+ url: (tag) => `/?frame=${frame_id}`
61
+ } satisfies ActionItem;
62
+ });
63
+ }
64
+ })
65
+ .filter((v) => v != null)
66
+ );
67
+ };
68
+ const [inputs, outputs] = await Promise.all([load("inputs"), load("outputs")]);
69
+ unsub();
70
+ return { inputs, outputs };
71
+ };
72
+
73
+ const tags = values.json("tags", [] as string[], {
74
+ decode: decoder,
75
+ encode: () => new Uint8Array()
17
76
  });
18
- return Promise.all(
19
- get(v).map((v2) => {
20
- const [frame_id, mark, g] = v2.split(":");
21
- if (g !== "V") {
22
- return;
23
- }
24
- if (mark === "T") {
25
- return load_frame_ui(frame_id, tag).then((f) => {
26
- return { name: frame_id, action: f };
27
- });
28
- } else if (mark === "U") {
29
- return load_frame_ui(frame_id).then((f) => {
30
- return { name: frame_id, action: f };
31
- });
77
+
78
+ if ($tags.length > 0) {
79
+ selected = 0;
80
+ }
81
+
82
+ const finalize = signals.string("finalize");
83
+
84
+ let a_inputs = $state([] as ActionItem[]);
85
+ let a_outputs = $state([] as ActionItem[]);
86
+ let title = $derived(selected > $tags.length ? "" : $tags[selected]);
87
+ const update = async (v: number) => {
88
+ a_inputs = [];
89
+ a_outputs = [];
90
+ const t = $tags;
91
+ if (0 <= v && v < t.length) {
92
+ const { inputs, outputs } = await frame_info(t[v], decoder);
93
+ a_inputs = inputs;
94
+ a_outputs = outputs;
32
95
  }
33
- }).filter((v2) => v2 != null)
34
- );
35
- };
36
- const [inputs, outputs] = await Promise.all([load2("inputs"), load2("outputs")]);
37
- unsub();
38
- return { inputs, outputs };
39
- };
40
- const tags = values.json("tags", [], {
41
- decode: decoder,
42
- encode: () => new Uint8Array()
43
- });
44
- const finalize = signals.string("finalize");
45
- let a_inputs = $state([]);
46
- let a_outputs = $state([]);
47
- let title = $derived(selected > $tags.length ? "" : $tags[selected]);
48
- const update = async (v) => {
49
- a_inputs = [];
50
- a_outputs = [];
51
- const t = $tags;
52
- if (0 <= v && v < t.length) {
53
- const { inputs, outputs } = await frame_info(t[v], decoder);
54
- a_inputs = inputs;
55
- a_outputs = outputs;
56
- }
57
- };
58
- $effect(() => {
59
- update(selected);
60
- });
96
+ };
97
+
98
+ $effect(() => {
99
+ update(selected);
100
+ });
61
101
  </script>
62
102
 
63
103
  <svelte:head>
@@ -3,8 +3,9 @@ import type { Snippet } from "svelte";
3
3
  type ActionItem = {
4
4
  name: string;
5
5
  action: Action<HTMLElement>;
6
+ url: (tag: string) => string;
6
7
  };
7
- type $$ComponentProps = {
8
+ type Props = {
8
9
  decoder: CoDec<any>["decode"];
9
10
  selected?: number;
10
11
  load: Snippet<[
@@ -15,6 +16,6 @@ type $$ComponentProps = {
15
16
  }
16
17
  ]>;
17
18
  };
18
- declare const Frame: import("svelte").Component<$$ComponentProps, {}, "">;
19
+ declare const Frame: import("svelte").Component<Props, {}, "selected">;
19
20
  type Frame = ReturnType<typeof Frame>;
20
21
  export default Frame;
package/test/Main.svelte CHANGED
@@ -1,22 +1,18 @@
1
- <script lang="ts">import TestFrame from "./Frame.svelte";
2
- import Split from "../components/layouts/Split.svelte";
3
- import Scrollable from "../components/layouts/Scrollable.svelte";
4
- import { config } from "$xit/config.js";
5
- let { children } = $props();
6
- let selected = $state(-1);
1
+ <script lang="ts">
2
+ import TestFrame from "./Frame.svelte";
3
+ import Split from "../components/layouts/Split.svelte";
4
+ import Scrollable from "../components/layouts/Scrollable.svelte";
5
+
6
+ import type { Snippet } from "svelte";
7
+
8
+ import { config } from "$xit/config.js";
9
+
10
+ let { children }: { children?: Snippet<[string]> } = $props();
11
+
12
+ let selected = $state(-1);
7
13
  </script>
8
14
 
9
- {#snippet combo(tags: string[])}
10
- <div class="combo">
11
- <select bind:value={selected}>
12
- {#each tags as id, i}
13
- <option value={i}>{id}</option>
14
- {/each}
15
- </select>
16
- </div>
17
- {/snippet}
18
-
19
- <TestFrame decoder={config.codec.decode} {selected}>
15
+ <TestFrame decoder={config.codec.decode} bind:selected>
20
16
  {#snippet load({ tags, inputs, outputs })}
21
17
  <Scrollable>
22
18
  <Split vertical offset={200}>
@@ -30,11 +26,21 @@ let selected = $state(-1);
30
26
  </Scrollable>
31
27
  {/snippet}
32
28
  {#snippet side_b()}
33
- {@render combo(tags)}
29
+ <div class="combo">
30
+ <select bind:value={selected}>
31
+ {#each tags as id, i}
32
+ <option value={i}>{id}</option>
33
+ {/each}
34
+ </select>
35
+ </div>
36
+ {#if 0 <= selected && selected < tags.length }
34
37
  {@render children?.(tags[selected])}
35
- {#each inputs as { name }}
36
- <a href={`/?frame=${name}&tag=${tags[selected]}`} target="_blank">{name}</a>
37
- {/each}
38
+ <div style="display: flex; flex-direction: column;">
39
+ {#each inputs as { name, url }}
40
+ <a href={url(tags[selected])} target="_blank">{name}</a>
41
+ {/each}
42
+ </div>
43
+ {/if}
38
44
  {/snippet}
39
45
  </Split>
40
46
  </Scrollable>