|
325 | 325 | editor!.commands.unsetAllMarks(); |
326 | 326 | } |
327 | 327 | } |
| 328 | +
|
| 329 | + function removeAllNodes(editor: Editor | undefined, type: string) { |
| 330 | + if (!editor) { return; } |
| 331 | + editor.commands.command(({ tr, state }) => { |
| 332 | + const nodeType = state.schema.nodes[type]; |
| 333 | + if (!nodeType) { |
| 334 | + console.warn(`Node type "${type}" not found in schema.`); |
| 335 | + return false; |
| 336 | + } |
| 337 | +
|
| 338 | + state.doc.descendants((node, pos) => { |
| 339 | + if (node.type === nodeType) { |
| 340 | + tr.delete(pos, pos + node.nodeSize); |
| 341 | + } |
| 342 | + return true; |
| 343 | + }); |
| 344 | +
|
| 345 | + editor.view.dispatch(tr); |
| 346 | + return true; |
| 347 | + }); |
| 348 | + } |
| 349 | +
|
| 350 | + let versionPopupConfirmationVisible = $state(false); |
| 351 | + let temporaryVersionConfirmation: Version | undefined = $state() |
| 352 | +
|
| 353 | + function changeOuptutVersion(version: Version | undefined, confirm = false) { |
| 354 | + if (!version) { return; } |
| 355 | +
|
| 356 | + if ($outputVersion.index > version.index && confirm == false) { |
| 357 | + versionPopupConfirmationVisible = true; |
| 358 | + temporaryVersionConfirmation = version |
| 359 | + return; |
| 360 | + } |
| 361 | +
|
| 362 | + outputVersion.set(version) |
| 363 | + versionPopup = false; |
| 364 | + versionPopupConfirmationVisible = false; |
| 365 | + temporaryVersionConfirmation = undefined; |
| 366 | +
|
| 367 | + if (version.index < 2) { // remove object keys |
| 368 | + removeAllNodes(editor, "object") |
| 369 | + } |
| 370 | +
|
| 371 | + tiptapJSON = editor!.getJSON(); |
| 372 | + } |
328 | 373 | </script> |
329 | 374 |
|
330 | 375 | <svelte:window onkeydown={clearMarksHandler} /> |
|
543 | 588 | </div> |
544 | 589 | {#if doesContentExist} |
545 | 590 | <div class="mt-2 flex items-center space-x-2 select-none"> |
546 | | - <!-- <p class="font-lexend nomob text-xs text-white/60"> |
547 | | - {editor |
548 | | - ? convert(tiptapJSON!, "standard", outputVersion, shouldOptimise) |
549 | | - .length |
550 | | - : 0} characters |
551 | | - </p> |
552 | | - <p class="font-lexend nomob text-xs text-white/60"> |
553 | | - {getTextComponentCount()} components |
554 | | - </p> |
555 | | -
|
556 | | - <p class="font-lexend nomob text-xs text-white/60">•</p> --> |
557 | | - |
558 | 591 | <p class="font-lexend text-xs text-white/60"> |
559 | 592 | click to change output settings: |
560 | 593 | </p> |
561 | 594 |
|
562 | 595 | <div class="relative inline-block"> |
563 | 596 | {#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> |
| 597 | + <div class="absolute bottom-full mb-2 left-1/2 -translate-x-1/2 bg-zinc-900 w-[400px] shadow-md shadow-zinc-950 rounded-md z-10 flex flex-col space-y-1"> |
| 598 | + {#if versionPopupConfirmationVisible} |
| 599 | + <div class="absolute w-full h-full bg-zinc-900 rounded-md px-4 py-4 backdrop-blur-md flex flex-col items-center"> |
| 600 | + <div class="m-auto flex flex-col"> |
| 601 | + <b>Warning:</b> |
| 602 | + <span>Changing to an earlier version could remove some elements of your text that are unsupported in this version.</span> |
| 603 | + <div class="flex space-x-2 mt-2"> |
| 604 | + <button class="bg-zinc-800 px-2 py-1 rounded-md hover:bg-zinc-700" onclick={() => changeOuptutVersion(temporaryVersionConfirmation, true)}>Change version</button> |
| 605 | + <button class="bg-zinc-800 px-2 py-1 rounded-md hover:bg-zinc-700" onclick={() => { |
| 606 | + versionPopupConfirmationVisible = false; |
| 607 | + temporaryVersionConfirmation = undefined; |
| 608 | + }}>Cancel</button> |
| 609 | + </div> |
| 610 | + </div> |
| 611 | + </div> |
| 612 | + {/if} |
| 613 | + <div class="px-2 py-2 space-y-1"> |
| 614 | + <div class="flex items-center ml-[0.3rem]"> |
| 615 | + <span class="w-1/4 text-sm">version</span> |
| 616 | + <span class="w-3/4 text-sm">description</span> |
| 617 | + </div> |
| 618 | + {#each versions as v} |
| 619 | + <button |
| 620 | + class="rounded-md bg-zinc-800 p-2 select-none hover:bg-zinc-700 text-left flex items-center w-full" |
| 621 | + onclick={() => changeOuptutVersion(v)}> |
| 622 | + <b class="w-1/4">{v.friendly}</b> |
| 623 | + <span class="w-3/4 text-xs">{v.description}</span> |
| 624 | + </button> |
| 625 | + {/each} |
| 626 | + <span class="ml-[0.3rem] text-xs text-zinc-400">* unreleased minecraft version</span> |
568 | 627 | </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 | 628 | </div> |
581 | 629 | {/if} |
582 | 630 |
|
583 | 631 | <button |
584 | 632 | class="ml-1 rounded-md bg-zinc-800 px-1 font-mono select-none hover:bg-zinc-700" |
585 | 633 | aria-label="Click to toggle the output version." |
586 | | - onclick={() => { |
587 | | - versionPopup = !versionPopup; |
588 | | - }}>{$outputVersion.friendly}</button> |
| 634 | + onclick={() => {versionPopup = !versionPopup}}>{$outputVersion.friendly}</button> |
589 | 635 | </div> |
590 | 636 |
|
591 | 637 | <button |
|
725 | 771 | </div> |
726 | 772 | </Modal> |
727 | 773 |
|
728 | | - <!-- {#await import("$lib/components/modals/ExportModal.svelte") then modal} |
| 774 | + {#await import("$lib/components/modals/ExportModal.svelte") then modal} |
729 | 775 | <modal.default |
730 | 776 | bind:outputDialog |
731 | | - bind:outputVersion |
732 | 777 | {editor} |
733 | 778 | {recentlyCopied} /> |
734 | | - {/await} --> |
| 779 | + {/await} |
735 | 780 |
|
736 | 781 | <Modal title="Import from NBT" bind:this={importDialog} key="I"> |
737 | 782 | <div class="flex w-full flex-col space-y-2"> |
|
0 commit comments