Skip to content

Commit c86f4d0

Browse files
authored
Merge pull request #17 from Datapack-Hub/main
tests, improved output modal
2 parents 0ed98db + d56fdc2 commit c86f4d0

37 files changed

+168
-89
lines changed

.github/workflows/ci.yml

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
# .github/workflows/ci.yml
2+
name: Automated Tests
3+
4+
on:
5+
pull_request:
6+
push:
7+
8+
jobs:
9+
build:
10+
runs-on: ubuntu-latest
11+
12+
strategy:
13+
matrix:
14+
node-version: [20.x]
15+
16+
steps:
17+
- name: Checkout code
18+
uses: actions/checkout@v3
19+
20+
- name: Use Node.js ${{ matrix.node-version }}
21+
uses: actions/setup-node@v3
22+
with:
23+
node-version: ${{ matrix.node-version }}
24+
cache: "npm"
25+
26+
- name: Install dependencies
27+
run: npm install
28+
29+
- name: Install Playwright dependencies
30+
run: npx playwright install
31+
32+
- name: Run tests
33+
run: npm test

bun.lock

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4,35 +4,35 @@
44
"": {
55
"name": "tools",
66
"dependencies": {
7-
"@tiptap/core": "^2.23.0",
8-
"@tiptap/extension-placeholder": "^2.23.0",
9-
"@tiptap/pm": "^2.23.0",
10-
"@tiptap/starter-kit": "^2.23.0",
7+
"@tiptap/core": "^2.23.1",
8+
"@tiptap/extension-placeholder": "^2.23.1",
9+
"@tiptap/pm": "^2.23.1",
10+
"@tiptap/starter-kit": "^2.23.1",
1111
"idb": "^8.0.3",
1212
"svelte-awesome-color-picker": "^4.0.2",
1313
"tippy.js": "^6.3.7",
1414
"typescript-color-gradient": "^4.0.1",
1515
},
1616
"devDependencies": {
1717
"@iconify-json/tabler": "^1.2.19",
18-
"@playwright/test": "^1.49.1",
18+
"@playwright/test": "^1.53.2",
1919
"@sveltejs/adapter-auto": "^6.0.1",
2020
"@sveltejs/kit": "^2.22.2",
2121
"@sveltejs/vite-plugin-svelte": "^5.1.0",
2222
"@tailwindcss/vite": "^4.1.11",
2323
"@testing-library/jest-dom": "^6.6.3",
2424
"@testing-library/svelte": "^5.2.8",
25-
"@tiptap/extension-color": "^2.23.0",
26-
"@tiptap/extension-font-family": "^2.23.0",
27-
"@tiptap/extension-text-style": "^2.23.0",
28-
"@tiptap/extension-underline": "^2.23.0",
29-
"@types/node": "^24.0.4",
25+
"@tiptap/extension-color": "^2.23.1",
26+
"@tiptap/extension-font-family": "^2.23.1",
27+
"@tiptap/extension-text-style": "^2.23.1",
28+
"@tiptap/extension-underline": "^2.23.1",
29+
"@types/node": "^24.0.8",
3030
"file-type": "^21.0.0",
3131
"jsdom": "^26.1.0",
32-
"prettier": "^3.6.1",
32+
"prettier": "^3.6.2",
3333
"prettier-plugin-svelte": "^3.4.0",
3434
"prettier-plugin-tailwindcss": "^0.6.13",
35-
"svelte": "^5.34.8",
35+
"svelte": "^5.34.9",
3636
"svelte-check": "^4.2.2",
3737
"tailwindcss": "^4.1.11",
3838
"tslib": "^2.8.1",

playwright.config.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,5 @@ export default defineConfig({
55
command: "npm run build && npm run preview",
66
port: 4173,
77
},
8-
testDir: "src/e2e",
8+
testDir: "src/tests/e2e",
99
});

src/app.html

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,12 @@
22
<html lang="en">
33
<head>
44
<meta charset="utf-8" />
5-
<link rel="icon" href="%sveltekit.assets%/dph.svg" />
6-
5+
<link rel="icon" type="image/png" href="/favicon-96x96.png" sizes="96x96" />
6+
<link rel="icon" type="image/svg+xml" href="/favicon.svg" />
7+
<link rel="shortcut icon" href="/favicon.ico" />
8+
<link rel="apple-touch-icon" sizes="180x180" href="/apple-touch-icon.png" />
9+
<meta name="apple-mobile-web-app-title" content="Text Editor" />
10+
<link rel="manifest" href="/site.webmanifest" />
711
<link
812
rel="preload"
913
as="font"

src/lib/components/CheckBox.svelte

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<script lang="ts">
2+
import IconTick from "~icons/tabler/check";
3+
4+
let { value = $bindable(), label }: { value: boolean; label: string } =
5+
$props();
6+
</script>
7+
8+
<div class="flex items-center gap-2">
9+
<button
10+
name={label}
11+
class="flex aspect-square size-8 flex-col items-center rounded-md bg-zinc-900"
12+
onclick={() => (value = !value)}>
13+
{#if value}
14+
<IconTick class="m-auto text-lg" />
15+
{/if}
16+
</button>
17+
</div>

src/lib/components/modals/CustomSourceModal.svelte

Lines changed: 5 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
<script lang="ts">
22
import Modal from "$lib/components/Modal.svelte";
3-
import IconTick from "~icons/tabler/check";
3+
import type { ExternalSources } from "$lib/types";
44
import IconScore from "~icons/tabler/123";
55
import IconSelector from "~icons/tabler/at";
66
import IconNBT from "~icons/tabler/braces";
77
import IconKeybind from "~icons/tabler/keyboard";
88
import IconTranslate from "~icons/tabler/language";
9-
import type { ExternalSources } from "$lib/types";
9+
import CheckBox from "../CheckBox.svelte";
1010
import MiniEditor from "../MiniEditor.svelte";
1111
1212
let {
@@ -214,14 +214,7 @@
214214
bind:value={customValues.nbt.path} />
215215

216216
<div class="mt-2 flex items-center space-x-2">
217-
<button
218-
class="flex aspect-square size-8 flex-col items-center rounded-md bg-zinc-900"
219-
onclick={() =>
220-
(customValues.nbt.interpret = !customValues.nbt.interpret)}>
221-
{#if customValues.nbt.interpret}
222-
<IconTick class="m-auto text-lg" />
223-
{/if}
224-
</button>
217+
<CheckBox bind:value={customValues.nbt.interpret} label="interpret" />
225218
<label for="interpret"
226219
>Interpret (parse nbt value as a text component)</label>
227220
</div>
@@ -258,14 +251,7 @@
258251
bind:value={customValues.nbt.path} />
259252

260253
<div class="mt-2 flex items-center space-x-2">
261-
<button
262-
class="flex aspect-square size-8 flex-col items-center rounded-md bg-zinc-900"
263-
onclick={() =>
264-
(customValues.nbt.interpret = !customValues.nbt.interpret)}>
265-
{#if customValues.nbt.interpret}
266-
<IconTick class="m-auto text-lg" />
267-
{/if}
268-
</button>
254+
<CheckBox bind:value={customValues.nbt.interpret} label="interpret" />
269255
<label for="interpret"
270256
>Interpret (parse nbt value as a text component)</label>
271257
</div>
@@ -302,14 +288,7 @@
302288
bind:value={customValues.nbt.path} />
303289

304290
<div class="mt-2 flex items-center space-x-2">
305-
<button
306-
class="flex aspect-square size-8 flex-col items-center rounded-md bg-zinc-900"
307-
onclick={() =>
308-
(customValues.nbt.interpret = !customValues.nbt.interpret)}>
309-
{#if customValues.nbt.interpret}
310-
<IconTick class="m-auto text-lg" />
311-
{/if}
312-
</button>
291+
<CheckBox bind:value={customValues.nbt.interpret} label="interpret" />
313292
<label for="interpret"
314293
>Interpret (parse nbt value as a text component)</label>
315294
</div>

src/lib/components/modals/ExportModal.svelte

Lines changed: 51 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,34 @@
11
<script lang="ts">
22
import Modal from "$lib/components/Modal.svelte";
3-
import IconCopy from "~icons/tabler/copy";
4-
import IconTick from "~icons/tabler/check";
5-
import { translateJSON, convert } from "$lib/text/nbt_or_json";
63
import { translateMOTD } from "$lib/text/motd";
4+
import { convert, translateJSON } from "$lib/text/nbt_or_json";
5+
import IconCopy from "~icons/tabler/copy";
6+
import CheckBox from "../CheckBox.svelte";
77
let {
88
outputDialog = $bindable(),
99
outputVersion = $bindable(),
1010
editor,
1111
recentlyCopied,
12-
indent,
13-
indentSize,
1412
shouldOptimise = true,
1513
} = $props();
14+
15+
let exportAsJSON = $state(false);
16+
17+
function exportThing(exportAsJSON: boolean) {
18+
if (!exportAsJSON) {
19+
return convert(
20+
editor.getJSON(),
21+
"item_lore",
22+
outputVersion,
23+
shouldOptimise,
24+
);
25+
}
26+
return translateJSON(editor.getJSON(), {
27+
exportType: "item_lore",
28+
exportVersion: outputVersion,
29+
optimise: shouldOptimise,
30+
});
31+
}
1632
</script>
1733

1834
<Modal title="More output formats" bind:this={outputDialog} big key="E">
@@ -21,29 +37,36 @@
2137
<option value="new">1.21.5+</option>
2238
<option value="old">Before 1.21.5</option>
2339
</select>
24-
<div class="mt-2 flex w-full flex-col">
25-
<p>For tellraw commands (send to chat):</p>
40+
<div class="flex w-full flex-col">
41+
{#if outputVersion == "new"}
42+
<div class="flex items-center space-x-2 mt-1">
43+
<CheckBox bind:value={exportAsJSON} label="json" />
44+
<span>Toggle JSON mode (for use in json files)</span>
45+
</div>
46+
{/if}
47+
48+
<p class="mt-2">As {outputVersion == "new" ? " " : "JSON "}text components:</p>
2649
<div class="flex items-start space-x-3 rounded-lg bg-zinc-950 p-3">
2750
<button
2851
class="rounded-md p-1 text-lg font-medium hover:bg-zinc-900 active:bg-white/10"
2952
onclick={() => {
3053
navigator.clipboard.writeText(
31-
"/tellraw @s " +
32-
convert(
33-
editor.getJSON(),
34-
"standard",
35-
outputVersion,
36-
shouldOptimise,
37-
),
54+
convert(
55+
editor.getJSON(),
56+
"standard",
57+
outputVersion,
58+
shouldOptimise,
59+
exportAsJSON
60+
),
3861
);
3962
recentlyCopied = true;
4063
setTimeout(() => (recentlyCopied = false), 2000);
4164
}}>
4265
<IconCopy />
4366
</button>
44-
<code class="inline-block max-h-56 w-full overflow-auto"
45-
>/tellraw @s {editor
46-
? convert(editor.getJSON(), "standard", outputVersion, shouldOptimise)
67+
<code class="inline-block max-h-56 w-full overflow-auto">
68+
{editor
69+
? convert(editor.getJSON(), "standard", outputVersion, shouldOptimise, exportAsJSON)
4770
: "Loading..."}
4871
</code>
4972
</div>
@@ -54,35 +77,24 @@
5477
class="rounded-md p-1 text-lg font-medium hover:bg-zinc-900 active:bg-white/10"
5578
onclick={() => {
5679
navigator.clipboard.writeText(
57-
`[lore=${convert(editor.getJSON(), "item_lore", outputVersion, shouldOptimise)}]`,
80+
`[lore=${convert(editor.getJSON(), "item_lore", outputVersion, shouldOptimise, exportAsJSON)}]`,
5881
);
5982
recentlyCopied = true;
6083
setTimeout(() => (recentlyCopied = false), 2000);
6184
}}>
6285
<IconCopy />
6386
</button>
64-
{#if outputVersion == "new"}
6587
<code class="inline-block max-h-56 w-full overflow-auto"
66-
>[lore={editor
88+
><span class="text-white/35">[lore=</span>{editor
6789
? convert(
68-
editor.getJSON(),
69-
"item_lore",
70-
outputVersion,
71-
shouldOptimise,
72-
)
73-
: "Loading..."}]
74-
</code>
75-
{:else}
76-
<code class="inline-block max-h-56 w-full overflow-auto"
77-
>[lore={editor
78-
? `'${translateJSON(editor.getJSON(), {
79-
exportType: "item_lore",
80-
exportVersion: outputVersion,
81-
optimise: shouldOptimise,
82-
})}`
83-
: "Loading..."}]
90+
editor.getJSON(),
91+
"item_lore",
92+
outputVersion,
93+
shouldOptimise,
94+
exportAsJSON
95+
)
96+
: "Loading..."}<span class="text-white/35">]</span>
8497
</code>
85-
{/if}
8698
</div>
8799

88100
<p class="mt-2">As a MOTD:</p>
@@ -103,7 +115,7 @@
103115
</code>
104116
</div>
105117

106-
<p class="mt-2">As JSON:</p>
118+
<!-- <p class="mt-2">As JSON:</p>
107119
<div class="flex items-start space-x-3 rounded-lg bg-zinc-950 p-3">
108120
<button
109121
class="rounded-md p-1 text-lg font-medium hover:bg-zinc-900 active:bg-white/10"
@@ -154,6 +166,6 @@
154166
min="1"
155167
bind:value={indentSize}
156168
class="w-fit rounded-md bg-zinc-900 p-2" />
157-
{/if}
169+
{/if} -->
158170
</div>
159171
</Modal>

src/lib/text/nbt_or_json.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -319,9 +319,10 @@ export function convert(
319319
exportType: "standard" | "item_lore" = "standard",
320320
exportVersion: "new" | "old" = "new",
321321
optimise: boolean,
322+
force_json: boolean = false
322323
): string {
323324
let out = translateJSON(jsonContent, { exportVersion, exportType, optimise });
324-
if (exportVersion == "new") {
325+
if (exportVersion == "new" && !force_json) {
325326
// only remove strings
326327
out = out.replace(/(?<=[{,]\s*)"[^"]*"\s*:/g, (match) =>
327328
match.replace(/"/g, ""),

src/routes/+page.svelte

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@
5757
import { fontLUT } from "$lib/tiptap/extensions/fonts";
5858
import { tooltip } from "$lib/tooltip";
5959
import { translateMOTD } from "$lib/text/motd";
60+
import ExportModal from "$lib/components/modals/ExportModal.svelte";
6061
6162
let tiptapJSON: JSONContent = $state()!;
6263
@@ -179,7 +180,7 @@
179180
FontsExtension,
180181
Placeholder.configure({
181182
placeholder:
182-
"Write text here, style it with the options above, and the output text components will appear at the bottom!",
183+
"Write text here, style it with the options above, and the output text components will appear at the bottom. You can also import text components with the Import button above!",
183184
}),
184185
],
185186
onTransaction: ({ editor: newEditor }) => {
@@ -569,9 +570,11 @@
569570
<p class="font-lexend nomob text-xs text-white/60">
570571
{getTextComponentCount()} components
571572
</p>
573+
572574
<p class="font-lexend nomob text-xs text-white/60">•</p>
575+
573576
<p class="font-lexend text-xs text-white/60">
574-
Click to change output settings:
577+
click to change output settings:
575578
</p>
576579
<button
577580
{@attach tooltip}
@@ -591,6 +594,12 @@
591594
aria-label="Click to toggle whether the output should be optimised (shortest possible output), or expanded (easier to edit manually)."
592595
onclick={() => (shouldOptimise = !shouldOptimise)}
593596
>{shouldOptimise ? "optimised" : "expanded"}</button>
597+
598+
<p class="font-lexend nomob text-xs text-white/60">•</p>
599+
600+
<button class="font-lexend text-xs text-white/60 underline" onclick={outputDialog?.open}>
601+
other output formats
602+
</button>
594603
</div>
595604
{/if}
596605
</div>
@@ -719,8 +728,6 @@
719728
bind:outputDialog
720729
bind:outputVersion
721730
{editor}
722-
{indent}
723-
{indentSize}
724731
{recentlyCopied} />
725732
{/await}
726733

0 commit comments

Comments
 (0)