|
56 | 56 | import { openDataStore } from "$lib/db"; |
57 | 57 | import { fontLUT } from "$lib/tiptap/extensions/fonts"; |
58 | 58 | import { tooltip } from "$lib/tooltip"; |
| 59 | + import { versions, type Version } from "$lib/types"; |
| 60 | + import { outputVersion } from "$lib/stores"; |
59 | 61 |
|
60 | 62 | let tiptapJSON: JSONContent = $state()!; |
61 | 63 |
|
|
65 | 67 | let colorDialog: Modal = $state()!; |
66 | 68 |
|
67 | 69 | let outputDialog: Modal = $state()!; |
68 | | - let outputVersion: "new" | "old" = $state("new"); |
| 70 | + let versionPopup: boolean = $state(false); |
69 | 71 |
|
70 | 72 | let doesContentExist: boolean = $state(false); |
71 | 73 | let shouldOptimise = $state(true); |
|
323 | 325 | editor!.commands.unsetAllMarks(); |
324 | 326 | } |
325 | 327 | } |
326 | | -
|
327 | | - function getTextComponentCount() { |
328 | | - const components = JSON.parse( |
329 | | - translateJSON(editor!.getJSON(), { |
330 | | - exportType: "standard", |
331 | | - indent: false, |
332 | | - exportVersion: outputVersion, |
333 | | - optimise: shouldOptimise, |
334 | | - }), |
335 | | - ); |
336 | | - if (Array.isArray(components)) { |
337 | | - return components.length; |
338 | | - } |
339 | | - return 1; |
340 | | - } |
341 | 328 | </script> |
342 | 329 |
|
343 | 330 | <svelte:window onkeydown={clearMarksHandler} /> |
|
533 | 520 | convert( |
534 | 521 | editor!.getJSON(), |
535 | 522 | "standard", |
536 | | - outputVersion, |
537 | 523 | shouldOptimise, |
538 | 524 | ), |
539 | 525 | ); |
|
550 | 536 | <code id="outputbox" class="inline break-all"> |
551 | 537 | <!-- {editor ? translateMOTD(tiptapJSON) : "Loading..."} --> |
552 | 538 | {editor |
553 | | - ? convert(tiptapJSON!, "standard", outputVersion, shouldOptimise) |
| 539 | + ? convert(tiptapJSON!, "standard", shouldOptimise) |
554 | 540 | : "Loading..."} |
555 | 541 | </code> |
556 | 542 | </p> |
557 | 543 | </div> |
558 | 544 | {#if doesContentExist} |
559 | 545 | <div class="mt-2 flex items-center space-x-2 select-none"> |
560 | | - <p class="font-lexend nomob text-xs text-white/60"> |
| 546 | + <!-- <p class="font-lexend nomob text-xs text-white/60"> |
561 | 547 | {editor |
562 | 548 | ? convert(tiptapJSON!, "standard", outputVersion, shouldOptimise) |
563 | 549 | .length |
|
567 | 553 | {getTextComponentCount()} components |
568 | 554 | </p> |
569 | 555 |
|
570 | | - <p class="font-lexend nomob text-xs text-white/60">•</p> |
| 556 | + <p class="font-lexend nomob text-xs text-white/60">•</p> --> |
571 | 557 |
|
572 | 558 | <p class="font-lexend text-xs text-white/60"> |
573 | 559 | click to change output settings: |
574 | 560 | </p> |
575 | | - <button |
576 | | - {@attach tooltip} |
577 | | - class="ml-1 rounded-md bg-zinc-800 px-1 font-mono select-none hover:bg-zinc-700" |
578 | | - aria-label="Click to toggle the output version. 1.21.5 drastically changed the format of text components, so make sure you select the correct version." |
579 | | - onclick={() => { |
580 | | - const ov = outputVersion; |
581 | | - if (ov == "new") { |
582 | | - outputVersion = "old"; |
583 | | - } else { |
584 | | - outputVersion = "new"; |
585 | | - } |
586 | | - }}>{outputVersion == "new" ? "1.21.5+" : "pre 1.21.5"}</button> |
| 561 | + |
| 562 | + <div class="relative inline-block"> |
| 563 | + {#if versionPopup} |
| 564 | + <div class="absolute bottom-full mb-2 left-1/2 -translate-x-1/2 bg-zinc-900 w-[400px] shadow-md shadow-zinc-950 px-2 py-2 rounded-md z-10 flex flex-col space-y-1"> |
| 565 | + <div class="flex items-center ml-[0.3rem]"> |
| 566 | + <span class="w-1/4 text-sm">version</span> |
| 567 | + <span class="w-3/4 text-sm">description</span> |
| 568 | + </div> |
| 569 | + {#each versions as v} |
| 570 | + <button |
| 571 | + class="rounded-md bg-zinc-800 p-2 select-none hover:bg-zinc-700 text-left flex items-center w-full" |
| 572 | + onclick={() => { |
| 573 | + $outputVersion = v; |
| 574 | + versionPopup = false; |
| 575 | + }}> |
| 576 | + <b class="w-1/4">{v.friendly}</b> |
| 577 | + <span class="w-3/4 text-xs">{v.description}</span> |
| 578 | + </button> |
| 579 | + {/each} |
| 580 | + </div> |
| 581 | + {/if} |
| 582 | + |
| 583 | + <button |
| 584 | + class="ml-1 rounded-md bg-zinc-800 px-1 font-mono select-none hover:bg-zinc-700" |
| 585 | + aria-label="Click to toggle the output version." |
| 586 | + onclick={() => { |
| 587 | + versionPopup = !versionPopup; |
| 588 | + }}>{$outputVersion.friendly}</button> |
| 589 | + </div> |
| 590 | + |
587 | 591 | <button |
588 | 592 | {@attach tooltip} |
589 | 593 | class="ml-1 rounded-md bg-zinc-800 px-1 font-mono select-none hover:bg-zinc-700" |
|
721 | 725 | </div> |
722 | 726 | </Modal> |
723 | 727 |
|
724 | | - {#await import("$lib/components/modals/ExportModal.svelte") then modal} |
| 728 | + <!-- {#await import("$lib/components/modals/ExportModal.svelte") then modal} |
725 | 729 | <modal.default |
726 | 730 | bind:outputDialog |
727 | 731 | bind:outputVersion |
728 | 732 | {editor} |
729 | 733 | {recentlyCopied} /> |
730 | | - {/await} |
| 734 | + {/await} --> |
731 | 735 |
|
732 | 736 | <Modal title="Import from NBT" bind:this={importDialog} key="I"> |
733 | 737 | <div class="flex w-full flex-col space-y-2"> |
|
0 commit comments