Skip to content

Commit 7869e7f

Browse files
authored
Merge pull request #13 from Datapack-Hub/dev
Optional optimise button, neater UI, bug fixes, and more
2 parents 9988216 + da0a9c3 commit 7869e7f

File tree

15 files changed

+243
-240
lines changed

15 files changed

+243
-240
lines changed

src/app.css

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,13 +40,15 @@ button {
4040
padding-top: 4px;
4141
padding-bottom: 2px;
4242
z-index: 10;
43+
--custom-source-align: top;
4344
}
4445

4546
.hoverEvent {
4647
background-color: #3c3c40;
4748
border-bottom: solid #ffff55 2px;
4849
padding-top: 4px;
4950
z-index: 10;
51+
--custom-source-align: top;
5052
}
5153

5254
.obfuscated {

src/lib/components/modals/ExportModal.svelte

Lines changed: 24 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
recentlyCopied,
1111
indent,
1212
indentSize,
13+
shouldOptimise = true
1314
} = $props();
1415
</script>
1516

@@ -27,7 +28,7 @@
2728
onclick={() => {
2829
navigator.clipboard.writeText(
2930
"/tellraw @s " +
30-
convert(editor.getJSON(), "standard", outputVersion),
31+
convert(editor.getJSON(), "standard", outputVersion, shouldOptimise),
3132
);
3233
recentlyCopied = true;
3334
setTimeout(() => (recentlyCopied = false), 2000);
@@ -36,7 +37,7 @@
3637
</button>
3738
<code class="inline-block w-full overflow-auto max-h-56"
3839
>/tellraw @s {editor
39-
? convert(editor.getJSON(), "standard", outputVersion)
40+
? convert(editor.getJSON(), "standard", outputVersion, shouldOptimise)
4041
: "Loading..."}
4142
</code>
4243
</div>
@@ -47,7 +48,7 @@
4748
class="p-1 text-lg hover:bg-zinc-900 active:bg-white/10 rounded-md font-medium"
4849
onclick={() => {
4950
navigator.clipboard.writeText(
50-
`[lore=${convert(editor.getJSON(), "item_lore", outputVersion)}]`,
51+
`[lore=${convert(editor.getJSON(), "item_lore", outputVersion, shouldOptimise)}]`,
5152
);
5253
recentlyCopied = true;
5354
setTimeout(() => (recentlyCopied = false), 2000);
@@ -57,13 +58,17 @@
5758
{#if outputVersion == "new"}
5859
<code class="inline-block w-full overflow-auto max-h-56"
5960
>[lore={editor
60-
? convert(editor.getJSON(), "item_lore", outputVersion)
61+
? convert(editor.getJSON(), "item_lore", outputVersion, shouldOptimise)
6162
: "Loading..."}]
6263
</code>
6364
{:else}
6465
<code class="inline-block w-full overflow-auto max-h-56"
6566
>[lore={editor
66-
? `'${translate(editor.getJSON(), "item_lore", false, 0, outputVersion)}'`
67+
? `'${translate(editor.getJSON(), {
68+
exportType: "item_lore",
69+
exportVersion: outputVersion,
70+
optimise: shouldOptimise
71+
})}`
6772
: "Loading..."}]
6873
</code>
6974
{/if}
@@ -77,10 +82,13 @@
7782
navigator.clipboard.writeText(
7883
translate(
7984
editor.getJSON(),
80-
"standard",
81-
indent,
82-
indentSize,
83-
outputVersion,
85+
{
86+
exportType: "standard",
87+
exportVersion: outputVersion,
88+
indent,
89+
indentSize,
90+
optimise: shouldOptimise
91+
}
8492
),
8593
);
8694
recentlyCopied = true;
@@ -92,10 +100,13 @@
92100
><pre>{editor
93101
? translate(
94102
editor.getJSON(),
95-
"standard",
96-
indent,
97-
indentSize,
98-
outputVersion,
103+
{
104+
exportType: "standard",
105+
exportVersion: outputVersion,
106+
indent,
107+
indentSize,
108+
optimise: shouldOptimise
109+
}
99110
)
100111
: "Loading..."}</pre>
101112
</code>

src/lib/nbt.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@ import { type StringyMCText } from "./types";
66
export function convertToTextOrEmpty(raw: string): StringyMCText[] {
77
raw = raw.replace(/([,{]\s*)([a-zA-Z_$][a-zA-Z0-9_$]*)\s*:/g, '$1"$2":');
88

9+
// replace 1b and 0b
10+
raw = raw.replace(/(?<="\w+"\s*:\s*)\b1b\b/g, "true")
11+
raw = raw.replace(/(?<="\w+"\s*:\s*)\b0b\b/g, "false")
12+
913
let parsed: MinecraftText[] | MinecraftText | string;
1014

1115
try {

src/lib/tiptap/extensions/marks/ClickEventMark.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { Mark, mergeAttributes } from "@tiptap/core";
22

3-
import { type ClickEventAttributes } from "..";
3+
import { type ClickEventAttributes } from "../index";
44

55
export const ClickEventMark = Mark.create({
66
name: "clickEvent",

src/lib/tiptap/extensions/marks/HoverEventMark.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { Mark, mergeAttributes } from "@tiptap/core";
2-
import type { HoverEventAttributes } from "..";
2+
import type { HoverEventAttributes } from "../index";
33

44
export const HoverEventMark = Mark.create({
55
name: "hoverEvent",

src/lib/tiptap/extensions/nodes/BlockNBTNode.ts

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { Node, mergeAttributes, type CommandProps } from "@tiptap/core";
2-
import type { NodeOptions, BlockNBTAttributes } from "..";
2+
import type { NodeOptions, BlockNBTAttributes } from "../index";
33

44
export const BlockNBTNode = Node.create<NodeOptions>({
55
name: "block_nbt",
@@ -39,15 +39,14 @@ export const BlockNBTNode = Node.create<NodeOptions>({
3939
"data-nbt-node": "true",
4040
contenteditable: "false",
4141
style: `
42-
background-color: #3c3c40;
43-
padding: 1px 5px;
44-
border-radius: 4px;
45-
font-size: 0.9em;
46-
display: inline-flex;
47-
align-items: center;
48-
gap: 4px 6px;
49-
z-index:9;
50-
`,
42+
background-color: #18181b;
43+
padding: 1px 5px;
44+
border-radius: 4px;
45+
font-size: 1rem;
46+
display: inline-block;
47+
vertical-align: var(--custom-source-align, middle);
48+
text-decoration: inherit;
49+
`,
5150
}),
5251
["span", {}, `NBT: ${nbt}, ${block}`],
5352
];

src/lib/tiptap/extensions/nodes/EntityNBTNode.ts

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { Node, mergeAttributes, type CommandProps } from "@tiptap/core";
2-
import type { NodeOptions, EntityNBTAttributes } from "..";
2+
import type { NodeOptions, EntityNBTAttributes } from "../index";
33

44
export const EntityNBTNode = Node.create<NodeOptions>({
55
name: "entity_nbt",
@@ -25,7 +25,7 @@ export const EntityNBTNode = Node.create<NodeOptions>({
2525
parseHTML() {
2626
return [
2727
{
28-
tag: "span[data-nbt-node]",
28+
tag: "p[data-nbt-node]",
2929
},
3030
];
3131
},
@@ -34,21 +34,21 @@ export const EntityNBTNode = Node.create<NodeOptions>({
3434
const { nbt, entity } = node.attrs;
3535

3636
return [
37-
"span",
37+
"p",
3838
mergeAttributes(this.options.HTMLAttributes, HTMLAttributes, {
3939
"data-nbt-node": "true",
4040
contenteditable: "false",
4141
style: `
42-
background-color: #3c3c40;
43-
padding: 1px 5px;
42+
background-color: #18181b;
43+
padding: 0px 5px;
4444
border-radius: 4px;
45-
font-size: 0.9em;
46-
display: inline-flex;
47-
align-items: center;
48-
gap: 4px 6px;
45+
font-size: 0.9rem;
46+
display: inline-block;
47+
vertical-align: var(--custom-source-align, middle);
48+
text-decoration: inherit;
4949
`,
5050
}),
51-
["span", {}, `NBT: ${nbt}, ${entity}`],
51+
["p", {}, `NBT: ${nbt}, ${entity}`],
5252
];
5353
},
5454

src/lib/tiptap/extensions/nodes/KeybindNode.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { Node, mergeAttributes, type CommandProps } from "@tiptap/core";
2-
import type { NodeOptions, KeybindAttributes } from "..";
2+
import type { NodeOptions, KeybindAttributes } from "../index";
33

44
export const KeybindNode = Node.create<NodeOptions>({
55
name: "keybind",
@@ -37,13 +37,13 @@ export const KeybindNode = Node.create<NodeOptions>({
3737
"data-keybind-node": "true",
3838
contenteditable: "false",
3939
style: `
40-
background-color: #3c3c40;
41-
padding: 1px 5px;
40+
background-color: #18181b;
41+
padding: 0px 5px;
4242
border-radius: 4px;
43-
font-size: 0.9em;
44-
display: inline-flex;
45-
align-items: center;
46-
gap: 4px 6px;
43+
font-size: 0.9rem;
44+
display: inline-block;
45+
vertical-align: var(--custom-source-align, middle);
46+
text-decoration: inherit;
4747
`,
4848
}),
4949
["span", {}, `KEYBIND: ${key}`],

src/lib/tiptap/extensions/nodes/ScoreNode.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { Node, mergeAttributes, type CommandProps } from "@tiptap/core";
2-
import type { NodeOptions, ScoreAttributes } from "..";
2+
import type { NodeOptions, ScoreAttributes } from "../index";
33

44
export const ScoreNode = Node.create<NodeOptions>({
55
name: "score",
@@ -38,13 +38,13 @@ export const ScoreNode = Node.create<NodeOptions>({
3838
"data-score-node": "true",
3939
contenteditable: "false",
4040
style: `
41-
background-color: #3c3c40;
42-
padding: 1px 5px;
43-
border-radius: 4px;
44-
font-size: 0.9em;
45-
display: inline-flex;
46-
align-items: center;
47-
gap: 4px 6px;
41+
background-color: #18181b;
42+
padding: 0px 5px;
43+
border-radius: 4px;
44+
font-size: 0.9rem;
45+
display: inline-block;
46+
vertical-align: var(--custom-source-align, middle);
47+
text-decoration: inherit;
4848
`,
4949
}),
5050
["span", {}, `SCORE: ${name} - ${objective}`],

src/lib/tiptap/extensions/nodes/SelectorNode.ts

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { Node, mergeAttributes, type CommandProps } from "@tiptap/core";
2-
import type { NodeOptions, SelectorAttributes } from "..";
2+
import type { NodeOptions, SelectorAttributes } from "../index";
33

44
export const SelectorNode = Node.create<NodeOptions>({
55
name: "selector",
@@ -37,12 +37,13 @@ export const SelectorNode = Node.create<NodeOptions>({
3737
"data-selector-node": "true",
3838
contenteditable: "false",
3939
style: `
40-
background-color: #3c3c40;
41-
padding: 1px 5px;
40+
background-color: #18181b;
41+
padding: 0px 5px;
4242
border-radius: 4px;
43-
font-size: 0.9em;
43+
font-size: 0.9rem;
4444
display: inline-block;
45-
user-select: all;
45+
vertical-align: var(--custom-source-align, middle);
46+
text-decoration: inherit;
4647
`,
4748
}),
4849
["span", {}, `SELECTOR: ${selector}`],

0 commit comments

Comments
 (0)