1- ItemList := ImportComponent["ItemList.wlx"];
2- File = $Options["File"];
3- Level = $Options["Level"] + 1;
1+ Dropdown = ImportComponent["Dropdown.wlx"];
42
5- Icons = $Options["Icons"];
63
7- Parameters = $Options["Parameters"];
4+ Component[OptionsPattern[]] := With[{
5+ File = OptionValue["File"],
6+ Level = OptionValue["Level"] + 1,
87
9- Dropdown := ImportComponent["Dropdown.wlx"];
8+ ItemList = OptionValue["ListComponent"],
9+ Icons = OptionValue["Icons"],
1010
11- (*/* uids for events */*)
12- ButtonId = CreateUUID[];
13- Controller = CreateUUID[];
14- Port = $Options["Port"];
11+ Parameters = OptionValue["Parameters"],
1512
16- (*/* state of a widget */*)
17- State = "Empty";
13+ Port = OptionValue["Port"],
1814
19- (*/* handling clicks */*)
20- EventHandler[ButtonId, Function[Null,
21- Print[State];
22- Switch[State,
23- "Empty",
24- State = "Open";
25- With[{client = $Client},
26- EventFire[Controller, "Load", <|"Client"->client|>];
27- ],
28-
29- "Open",
30- State = "Hidden";
31- With[{client = $Client},
32- EventFire[Controller, "Hide", <|"Client"->client|>];
33- ],
34-
35- "Hidden",
36- State = "Open";
37- With[{client = $Client},
38- EventFire[Controller, "Show", <|"Client"->client|>];
39- ]
40- ];
41- ]];
42-
43- Selected = If[TrueQ[$Options["Selected"]], "bg-yellow-300", ""];
44-
45- <div style="position:relative">
46- <div class="rounded-md">
47- <button id="{ButtonId}" type="button" class="{Selected} flex items-center w-full text-left rounded-md pb-0.5 pt-0.5 pl-1 gap-x-1 text-sm text-gray-700 dark:text-gray-400" aria-controls="sub-menu-1" aria-expanded="false">
48-
49- <svg id="svg-{ButtonId}" class="text-gray-800 dark:text-gray-400 h-5 w-5 shrink-0" viewBox="0 0 20 20" fill="currentColor" aria-hidden="true">
50- <path fill-rule="evenodd" d="M7.21 14.77a.75.75 0 01.02-1.06L11.168 10 7.23 6.29a.75.75 0 111.04-1.08l4.5 4.25a.75.75 0 010 1.08l-4.5 4.25a.75.75 0 01-1.06-.02z" clip-rule="evenodd" />
51- </svg>
52- <svg class="h-4 w-4 shrink-0 text-gray-800 dark:text-gray-400 group-hover:text-indigo-500" fill="none" viewBox="0 0 24 24" stroke-width="1.5" stroke="currentColor" aria-hidden="true">
53- <path stroke-linecap="round" stroke-linejoin="round" d="M2.25 12.75V12A2.25 2.25 0 014.5 9.75h15A2.25 2.25 0 0121.75 12v.75m-8.69-6.44l-2.12-2.12a1.5 1.5 0 00-1.061-.44H4.5A2.25 2.25 0 002.25 6v12a2.25 2.25 0 002.25 2.25h15A2.25 2.25 0 0021.75 18V9a2.25 2.25 0 00-2.25-2.25h-5.379a1.5 1.5 0 01-1.06-.44z" />
54- </svg>
55- <FileBaseName><File/></FileBaseName>
15+ ButtonId = CreateUUID[],
16+ Controller = CreateUUID[],
17+
18+ Selected = If[TrueQ[OptionValue["Selected"]], "bg-yellow-300", ""]
19+
20+ }, Module[{State = "Empty", initialized = False},
21+
22+ (*/* handling clicks */*)
23+ EventHandler[ButtonId, Function[Null,
5624
57- </button>
25+ If[!initialized, (* /* FIXME. Make global destroy signal */*)
26+ initialized = True;
27+ With[{client = EventClone[$Client]},
28+ EventHandler[client, {"Closed" -> Function[Null,
29+ EventRemove[client];
30+ ClearAll[State];
31+ ClearAll[initialized];
32+ EventRemove[ButtonId];
33+ EventRemove[Controller];
34+ ]}];
35+ ];
36+ ];
37+
38+ Switch[State,
39+ "Empty",
40+ State = "Open";
41+ With[{client = $Client},
42+ EventFire[Controller, "Load", <|"Client"->client|>];
43+ ],
44+
45+ "Open",
46+ State = "Hidden";
47+ With[{client = $Client},
48+ EventFire[Controller, "Hide", <|"Client"->client|>];
49+ ],
50+
51+ "Hidden",
52+ State = "Open";
53+ With[{client = $Client},
54+ EventFire[Controller, "Show", <|"Client"->client|>];
55+ ]
56+ ];
57+ ]];
58+
59+
60+ <div style="position:relative">
61+ <div class="rounded-md">
62+ <button id="{ButtonId}" type="button" class="{Selected} flex items-center w-full text-left rounded-md pb-0.5 pt-0.5 pl-1 gap-x-1 text-sm text-gray-700 dark:text-gray-400" aria-controls="sub-menu-1" aria-expanded="false">
63+
64+ <svg id="svg-{ButtonId}" class="text-gray-800 dark:text-gray-400 h-5 w-5 shrink-0" viewBox="0 0 20 20" fill="currentColor" aria-hidden="true">
65+ <path fill-rule="evenodd" d="M7.21 14.77a.75.75 0 01.02-1.06L11.168 10 7.23 6.29a.75.75 0 111.04-1.08l4.5 4.25a.75.75 0 010 1.08l-4.5 4.25a.75.75 0 01-1.06-.02z" clip-rule="evenodd" />
66+ </svg>
67+ <svg class="h-4 w-4 shrink-0 text-gray-800 dark:text-gray-400 group-hover:text-indigo-500" fill="none" viewBox="0 0 24 24" stroke-width="1.5" stroke="currentColor" aria-hidden="true">
68+ <path stroke-linecap="round" stroke-linejoin="round" d="M2.25 12.75V12A2.25 2.25 0 014.5 9.75h15A2.25 2.25 0 0121.75 12v.75m-8.69-6.44l-2.12-2.12a1.5 1.5 0 00-1.061-.44H4.5A2.25 2.25 0 002.25 6v12a2.25 2.25 0 002.25 2.25h15A2.25 2.25 0 0021.75 18V9a2.25 2.25 0 00-2.25-2.25h-5.379a1.5 1.5 0 01-1.06-.44z" />
69+ </svg>
70+ <FileBaseName><File/></FileBaseName>
71+
72+ </button>
73+
74+ <Dropdown Parameters={Parameters} Filename={File} Port={Port}/>
75+ </div>
76+
77+ <WebUIEventListener Type={"click"} Id={ButtonId} Event={ButtonId} />
78+
79+ <WebUIJSBind Event={Controller}>
80+ const button = document.getElementById('svg-<ButtonId/>');
81+ this.on('Load', (data) => {
82+ button.classList.add('rotate-90', 'text-gray-500');
83+ });
5884
59- <Dropdown Parameters={Parameters} Filename={File} Port={Port}/>
60- </div>
85+ this.on('Show', (data) => {
86+ button.classList.add('rotate-90', 'text-gray-500');
87+ });
6188
62- <WebUIEventListener Type={"click"} Id={ButtonId} Event={ButtonId} />
89+ this.on('Hide', (data) => {
90+ button.classList.remove('rotate-90', 'text-gray-500');
91+ });
92+ </WebUIJSBind>
6393
64- <WebUIJSBind Event={Controller}>
65- const button = document.getElementById('svg-<ButtonId/>');
66- this.on('Load', (data) => {
67- button.classList.add('rotate-90', 'text-gray-500');
68- });
94+ <WebUILazyLoad Event={Controller}>
95+ <ItemList Port={Port} Icons={Icons} Parameters={Parameters} Level={Level} Class={"mt-0"} Path={File} />
96+ </WebUILazyLoad>
97+ </div>
6998
70- this.on('Show', (data) => {
71- button.classList.add('rotate-90', 'text-gray-500');
72- });
99+ ] ]
73100
74- this.on('Hide', (data) => {
75- button.classList.remove('rotate-90', 'text-gray-500');
76- });
77- </WebUIJSBind>
101+ Options[Component] = {"Selected"->False, "File"->"", "Level"->0, "Icons"->"", "Parameters"-><||>, "Port"->"", "ListComponent"->Null};
78102
79- <WebUILazyLoad Event={Controller}>
80- <ItemList Port={Port} Icons={Icons} Parameters={Parameters} Level={Level} Class={"mt-0"} Path={File} />
81- </WebUILazyLoad>
82- </div>
103+ Component
0 commit comments