|
10 | 10 | { label: "Item Argument", value: "item-argument" }, |
11 | 11 | { label: "Component Argument", value: "component-argument" }, |
12 | 12 | { label: "Entity Argument", value: "entity-argument" }, |
13 | | - ]; |
| 13 | + ].sort((e1, e2) => e1.label.localeCompare(e2.label)); |
14 | 14 |
|
15 | 15 | const ENTITY_TYPES: Option[] = [ |
16 | 16 | "item", |
|
98 | 98 | "ender_crystal", |
99 | 99 | ] |
100 | 100 | .map((e) => ({ label: e, value: e })) |
101 | | - .sort((e1, e2) => e1.label.charCodeAt(0) - +e2.label.charCodeAt(0)); |
| 101 | + .sort((e1, e2) => e1.label.localeCompare(e2.label)); |
102 | 102 | </script> |
103 | 103 |
|
104 | 104 | <script lang="ts"> |
|
108 | 108 | let input = $state(""); |
109 | 109 | let output = $state(""); |
110 | 110 |
|
| 111 | + let copied = $state(false); |
| 112 | + $effect(() => { |
| 113 | + if (copied) { |
| 114 | + setTimeout(() => (copied = false), 1500); |
| 115 | + } |
| 116 | + }); |
| 117 | +
|
111 | 118 | let mode = $state<Option>(MODES[0]); |
112 | 119 |
|
113 | 120 | let entityType = $state<Option>(); |
|
122 | 129 | output = ""; |
123 | 130 | loading = true; |
124 | 131 | try { |
125 | | - const query = mode === MODES[3] ? "?entityType=" + entityType?.value : ""; |
126 | | - const response = await fetch( |
127 | | - "https://item-converter.papermc.io/convert-" + mode.value + query, |
128 | | - { |
129 | | - method: "POST", |
130 | | - body: input, |
131 | | - } |
132 | | - ); |
133 | | - if (response.status === 200) { |
134 | | - output = await response.text(); |
135 | | - toggleState(convertSuccess); |
136 | | - } else { |
137 | | - console.warn( |
138 | | - "Failed to convert command: " + |
139 | | - response.status + |
140 | | - ": " + |
141 | | - (await response.text()) |
142 | | - ); |
143 | | - toggleState(convertError); |
144 | | - } |
| 132 | + // const query = mode === MODES[3] ? "?entityType=" + entityType?.value : ""; |
| 133 | + // const response = await fetch( |
| 134 | + // "https://item-converter.papermc.io/convert-" + mode.value + query, |
| 135 | + // { |
| 136 | + // method: "POST", |
| 137 | + // body: input, |
| 138 | + // } |
| 139 | + // ); |
| 140 | + // if (response.status === 200) { |
| 141 | + // output = await response.text(); |
| 142 | + output = input; |
| 143 | + toggleState(convertSuccess); |
| 144 | + // } else { |
| 145 | + // console.warn( |
| 146 | + // "Failed to convert command: " + |
| 147 | + // response.status + |
| 148 | + // ": " + |
| 149 | + // (await response.text()) |
| 150 | + // ); |
| 151 | + // toggleState(convertError); |
| 152 | + // } |
145 | 153 | } catch (error) { |
146 | 154 | console.error("Failed to convert command: " + error); |
147 | 155 | toggleState(convertError); |
148 | 156 | } |
149 | 157 |
|
150 | 158 | loading = false; |
151 | 159 | }; |
| 160 | +
|
| 161 | + const copyToClipboard = () => { |
| 162 | + navigator.clipboard.writeText(output); |
| 163 | + copied = true; |
| 164 | + }; |
152 | 165 | </script> |
153 | 166 |
|
154 | 167 | <div class="item-command-converter"> |
|
162 | 175 | </p> |
163 | 176 |
|
164 | 177 | <div class="convert-controls"> |
165 | | - <button class="convert-content clickable" onclick={convert}>Convert</button> |
| 178 | + <button class="convert-content clickable convert-button" onclick={convert} |
| 179 | + >Convert</button |
| 180 | + > |
166 | 181 | {#if mode.value === "entity-argument"} |
167 | 182 | <p class="convert-content entity-type"> |
168 | 183 | Entity Type: |
|
192 | 207 | placeholder="Press 'Convert' to convert the command." |
193 | 208 | class="textarea-panel" |
194 | 209 | readonly |
| 210 | + bind:value={output} |
195 | 211 | ></textarea> |
196 | 212 | </p> |
197 | 213 |
|
198 | | - <button class="clickable">Copy output!</button> |
| 214 | + <button |
| 215 | + class:copied |
| 216 | + onclick={copyToClipboard} |
| 217 | + class="clickable" |
| 218 | + disabled={loading}>{copied ? "Copied!" : "Copy output!"}</button |
| 219 | + > |
199 | 220 | </div> |
200 | 221 |
|
201 | 222 | <style> |
202 | 223 | .item-command-converter { |
| 224 | + margin-top: 1rem; |
203 | 225 | padding: 1rem; |
204 | 226 | border: 2px; |
205 | 227 | border-style: solid; |
|
256 | 278 | padding: 0.25rem; |
257 | 279 | padding-left: 0.75rem; |
258 | 280 | padding-right: 0.75rem; |
| 281 | + transition: 0.15s; |
| 282 | + } |
| 283 | +
|
| 284 | + .clickable:hover { |
| 285 | + background-color: var(--sl-color-gray-5); |
| 286 | + transition: 0.15s; |
259 | 287 | } |
260 | 288 | </style> |
0 commit comments