diff --git a/src/lib/utils/copy.ts b/src/lib/utils/copy.ts new file mode 100644 index 0000000..0416973 --- /dev/null +++ b/src/lib/utils/copy.ts @@ -0,0 +1,19 @@ +export async function copyText(str: string) { + if (navigator.clipboard && navigator.permissions) { + await navigator.clipboard.writeText(str) + } + else { + const textArea = document.createElement('textArea') as HTMLTextAreaElement + textArea.value = str + textArea.style.width = '0' + textArea.style.position = 'fixed' + textArea.style.left = '-999px' + textArea.style.top = '10px' + textArea.setAttribute('readonly', 'readonly') + document.body.appendChild(textArea) + + textArea.select() + document.execCommand('copy') + document.body.removeChild(textArea) + } +} diff --git a/src/routes/+layout.svelte b/src/routes/+layout.svelte index 5b1f6c4..84a4020 100644 --- a/src/routes/+layout.svelte +++ b/src/routes/+layout.svelte @@ -1,5 +1,5 @@
-
-
XParCai Tools
- -
+ + + +
diff --git a/src/routes/json-to-ts-type/+page.svelte b/src/routes/json-to-ts-type/+page.svelte index 0b639cb..103c40c 100644 --- a/src/routes/json-to-ts-type/+page.svelte +++ b/src/routes/json-to-ts-type/+page.svelte @@ -1,13 +1,14 @@
-
- (isChoose = e.detail)} - > - 是否可选 - +
+
JSON TO TS TYPE
- + {#if !isJsonStr(jsonCode)} + + {/if} + {#if tsTypes.length > 0} - 复制 + generateTsType(tsTypes)}>复制 + (isChoose = e.detail)} + > + 全部可选 + - (chooseGroup = e.detail)} - > - {#each tsTypes as [tsTypeKey, tsTypeValue], tsTypeUid} - -
- {#each tsTypeValue as [optional, key, value], uid} - -
- {key} - {#if isChoose || optional} - ? - {/if} - : - {#if !isChoose} - - 可选 - - {/if} -
-
- {/each} -
-
- {/each} -
+ {#each tsTypes as [tsTypeKey, tsTypeValue], tsTypeUid} + +
+ {#each tsTypeValue as [optional, key, value], uid} + +
+ {key} + {#if isChoose || optional} + ? + {/if} + : + {#if !isChoose} + (optional = e.detail)} + > + 可选 + + {/if} +
+
+ {/each} +
+
+ {/each}
{/if}