Skip to content

Commit 328fa98

Browse files
authored
Merge pull request #29 from Datapack-Hub/main
Cleanup and better shadow button
2 parents bb88c6d + 027debc commit 328fa98

15 files changed

Lines changed: 108 additions & 57 deletions

playwright.config.ts

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

src/lib/components/modals/CustomSourceModal.svelte

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -402,7 +402,7 @@
402402
<Combobox
403403
items={defaultAtlases}
404404
type="single"
405-
inputProps={{ placeholder: "Type an alias or use a default..." }}
405+
inputProps={{ placeholder: "Defaults to minecraft:blocks" }}
406406
bind:value={customValues.object.atlas} />
407407
<p class="mt-2">Sprite</p>
408408
<input

src/lib/components/modals/ExportModal.svelte

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
import Modal from "$lib/components/Modal.svelte";
33
import { outputVersion } from "$lib/stores";
44
import { translateMOTD } from "$lib/text/motd";
5-
import { convert } from "$lib/text/nbt/nbt_or_json";
5+
import { convert } from "$lib/text/nbt/export";
66
import IconCopy from "~icons/tabler/copy";
77
import CheckBox from "../CheckBox.svelte";
88
let {

src/lib/components/text/MiniEditor.svelte

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,14 @@
1010
import IconColor from "~icons/tabler/palette";
1111
import IconSquare from "~icons/tabler/square-filled";
1212
import IconHollow from "~icons/tabler/square-x";
13-
import { convertToTextOrEmpty, snbtToDocument } from "../../text/nbt/nbt";
13+
import { convertToTextOrEmpty, snbtToDocument } from "../../text/nbt/import";
1414
1515
import {
1616
colorMap,
1717
defaultColorLUT,
1818
trueMarkOrUndefined,
1919
} from "$lib/text/utils";
20-
import { addTypeSpecificValues } from "$lib/text/nbt/nbt_or_json";
20+
import { addTypeSpecificValues } from "$lib/text/nbt/export";
2121
import {
2222
FontsExtension,
2323
Obfuscation,
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
<script lang="ts">
2+
import { tooltip } from "$lib/tooltip";
3+
import IconShadow from "~icons/tabler/shadow";
4+
5+
interface Props {
6+
/** DOM element of the label wrapper */
7+
labelElement: HTMLLabelElement | undefined;
8+
/** hex color */
9+
hex: string | null;
10+
/** input label */
11+
label: string;
12+
/** input name, useful in a native form */
13+
name?: string | undefined;
14+
/** directionality left to right, or right to left*/
15+
dir: "ltr" | "rtl";
16+
small?: boolean;
17+
}
18+
19+
let {
20+
labelElement = $bindable(),
21+
hex,
22+
label,
23+
name = undefined,
24+
dir,
25+
small,
26+
}: Props = $props();
27+
</script>
28+
29+
<button
30+
aria-label="Shadow Color"
31+
{@attach tooltip}
32+
class="p-1 {small
33+
? 'text-sm'
34+
: 'text-lg'} rounded-md font-medium hover:bg-white/3">
35+
<label bind:this={labelElement} {dir}>
36+
<IconShadow />
37+
</label>
38+
</button>

src/lib/components/text/TextStyleButtons.svelte

Lines changed: 29 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<script lang="ts">
2-
import { colorMap, defaultColorLUT } from "$lib/text/utils";
2+
import { colorMap } from "$lib/text/utils";
33
import { tooltip } from "$lib/tooltip";
44
import type { Editor } from "@tiptap/core";
55
import ColorPicker from "svelte-awesome-color-picker";
@@ -9,10 +9,13 @@
99
import IconShadow from "~icons/tabler/shadow";
1010
import IconStrikethrough from "~icons/tabler/strikethrough";
1111
import IconUnderline from "~icons/tabler/underline";
12+
import ShadowColorButton from "./ShadowColorButton.svelte";
1213
1314
const { editor, small = false }: { editor: Editor; small?: boolean } =
1415
$props();
1516
let shadowColorValue = $state("#ffffff");
17+
let shouldIgnoreInitInput = true;
18+
let isColorPickerOpen = $state(false);
1619
</script>
1720

1821
<button
@@ -80,42 +83,36 @@
8083
: ''}">
8184
<IconObfuscate />
8285
</button>
83-
<div class="mx-2 h-5 w-px bg-zinc-600"></div>
84-
{#if editor.isActive("shadowColor")}
85-
<button
86-
aria-label="Shadow Color"
87-
name="shadow_color"
88-
{@attach tooltip}
89-
class="p-1 {small
90-
? 'text-sm'
91-
: 'text-lg'} rounded-md bg-zinc-800 font-medium hover:bg-white/3"
92-
onclick={() => editor.chain().focus().unsetShadowColor().run()}>
93-
<IconShadow />
94-
</button>
86+
87+
{#if !editor.isActive("shadowColor") || isColorPickerOpen}
88+
<ColorPicker
89+
isAlpha={false}
90+
bind:hex={shadowColorValue}
91+
bind:isOpen={isColorPickerOpen}
92+
--cp-bg-color="#18181b"
93+
--cp-text-color="white"
94+
--cp-input-color="#0C0C0E"
95+
--cp-button-hover-color="#18181b"
96+
textInputModes={["hex"]}
97+
onInput={(c) => {
98+
if (isColorPickerOpen) {
99+
c.hex && editor.chain().focus().setShadowColor(c.hex).run();
100+
}
101+
}}
102+
swatches={Object.values(colorMap).map((c) => c.value)}
103+
components={{ input: ShadowColorButton }} />
95104
{:else}
96105
<button
97-
aria-label="Shadow Color"
98-
name="shadow_color"
106+
aria-label="Unset Shadow Color"
99107
{@attach tooltip}
108+
onclick={() => {
109+
shouldIgnoreInitInput = true;
110+
shadowColorValue = "#ffffff";
111+
editor.chain().focus().unsetShadowColor().run();
112+
}}
100113
class="p-1 {small
101114
? 'text-sm'
102-
: 'text-lg'} rounded-md font-medium hover:bg-white/3"
103-
onclick={() => {
104-
editor.chain().focus().setShadowColor(shadowColorValue).run();
105-
}}>
115+
: 'text-lg'} rounded-md bg-zinc-800 font-medium hover:bg-white/3">
106116
<IconShadow />
107117
</button>
108118
{/if}
109-
<!-- isAlpha is off because ARGB != RGBA and i want to get the update out -->
110-
<ColorPicker
111-
isAlpha={false}
112-
bind:hex={shadowColorValue}
113-
--cp-bg-color="#18181b"
114-
--cp-text-color="white"
115-
--cp-input-color="#0C0C0E"
116-
--cp-button-hover-color="#18181b"
117-
--input-size="20px"
118-
textInputModes={["hex"]}
119-
swatches={Object.values(colorMap).map((c) => c.value)}
120-
label="" />
121-
<div class="mx-2 h-5 w-px bg-zinc-600"></div>
Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,9 @@ export function addTypeSpecificValues(
6767
case "atlas_object":
6868
if (exportVersion.index >= 2) {
6969
current.object = "atlas";
70-
current.atlas = c.attrs?.atlas;
70+
if(current.atlas) {
71+
current.atlas = c.attrs?.atlas;
72+
}
7173
current.sprite = c.attrs?.sprite;
7274

7375
current.bold = undefined;

src/lib/text/nbt/optimiser.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -232,12 +232,10 @@ function mergeTextComponents(output: StringyMCText[]) {
232232
// Find shared style/interactivity properties between consecutive objects
233233
if (typeof current === "object" && typeof next === "object") {
234234
const sharedProperties = getSharedStyleProps(current, next);
235-
console.log("Shared Properties:", sharedProperties);
236235

237236
if (Object.keys(sharedProperties).length > 0) {
238237
let group = [current];
239238
collectAllFromIndex(i, group, output, sharedProperties);
240-
console.log("Group Collected:", group);
241239

242240
if (group.length < 1) {
243241
continue;

src/lib/tiptap/extensions/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ export interface SelectorAttributes {
4444
}
4545

4646
export interface AtlasObjectAttributes {
47-
atlas: string;
47+
atlas?: string;
4848
sprite: string;
4949
}
5050

0 commit comments

Comments
 (0)