|
1 | 1 | <script lang="ts">
|
2 |
| - import { ExtraButtonComponent, TextComponent } from "obsidian"; |
| 2 | + import { |
| 3 | + addIcon, |
| 4 | + ButtonComponent, |
| 5 | + ExtraButtonComponent, |
| 6 | + TextComponent |
| 7 | + } from "obsidian"; |
3 | 8 |
|
4 |
| - import type { Layout } from "src/data/constants"; |
| 9 | + import type { Layout, StatblockItem } from "src/data/constants"; |
| 10 | + import type StatBlockPlugin from "src/main"; |
| 11 | + import { createEventDispatcher } from "svelte"; |
5 | 12 | import Creator from "./ui/Creator.svelte";
|
6 | 13 |
|
7 | 14 | export let layout: Layout;
|
| 15 | + export let plugin: StatBlockPlugin; |
| 16 | +
|
| 17 | + const dispatch = createEventDispatcher(); |
| 18 | +
|
| 19 | + const handleSorted = (e: CustomEvent<StatblockItem[]>) => { |
| 20 | + layout.blocks = [...e.detail]; |
| 21 | + }; |
| 22 | +
|
| 23 | + addIcon( |
| 24 | + "dropzone-grip", |
| 25 | + `<svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" data-prefix="fas" data-icon="grip-vertical" class="svg-inline--fa fa-grip-vertical fa-w-10" role="img" viewBox="0 0 320 512"><path fill="currentColor" d="M96 32H32C14.33 32 0 46.33 0 64v64c0 17.67 14.33 32 32 32h64c17.67 0 32-14.33 32-32V64c0-17.67-14.33-32-32-32zm0 160H32c-17.67 0-32 14.33-32 32v64c0 17.67 14.33 32 32 32h64c17.67 0 32-14.33 32-32v-64c0-17.67-14.33-32-32-32zm0 160H32c-17.67 0-32 14.33-32 32v64c0 17.67 14.33 32 32 32h64c17.67 0 32-14.33 32-32v-64c0-17.67-14.33-32-32-32zM288 32h-64c-17.67 0-32 14.33-32 32v64c0 17.67 14.33 32 32 32h64c17.67 0 32-14.33 32-32V64c0-17.67-14.33-32-32-32zm0 160h-64c-17.67 0-32 14.33-32 32v64c0 17.67 14.33 32 32 32h64c17.67 0 32-14.33 32-32v-64c0-17.67-14.33-32-32-32zm0 160h-64c-17.67 0-32 14.33-32 32v64c0 17.67 14.33 32 32 32h64c17.67 0 32-14.33 32-32v-64c0-17.67-14.33-32-32-32z"/></svg>` |
| 26 | + ); |
8 | 27 |
|
9 | 28 | let editingName = false;
|
10 | 29 | const name = (node: HTMLElement) => {
|
|
41 | 60 | });
|
42 | 61 | }
|
43 | 62 | };
|
| 63 | +
|
| 64 | + const add = (node: HTMLDivElement) => { |
| 65 | + new ExtraButtonComponent(node) |
| 66 | + .setIcon("plus-with-circle") |
| 67 | + .setTooltip("Add Block") |
| 68 | + .onClick(() => {}); |
| 69 | + }; |
| 70 | + const save = (node: HTMLDivElement) => { |
| 71 | + new ButtonComponent(node) |
| 72 | + .setIcon("checkmark") |
| 73 | + .setCta() |
| 74 | + .setTooltip("Save") |
| 75 | + .onClick(() => { |
| 76 | + dispatch("saved"); |
| 77 | + }); |
| 78 | + }; |
| 79 | + const cancel = (node: HTMLDivElement) => { |
| 80 | + new ExtraButtonComponent(node) |
| 81 | + .setIcon("cross") |
| 82 | + .setTooltip("Cancel") |
| 83 | + .onClick(() => { |
| 84 | + dispatch("cancel"); |
| 85 | + }); |
| 86 | + }; |
44 | 87 | </script>
|
45 | 88 |
|
46 |
| -<div class="name" use:name /> |
| 89 | +<div class="top"> |
| 90 | + <div class="name" use:name /> |
| 91 | + <div class="add" use:add /> |
| 92 | +</div> |
47 | 93 | <div class="creator-container">
|
48 | 94 | <div class="creator">
|
49 |
| - <Creator blocks={layout.blocks} /> |
| 95 | + <Creator blocks={layout.blocks} {plugin} on:sorted={handleSorted} /> |
50 | 96 | </div>
|
51 |
| - <div class="options" /> |
| 97 | +</div> |
| 98 | +<div class="bottom"> |
| 99 | + <div class="save" use:save /> |
| 100 | + <div class="cancel" use:cancel /> |
52 | 101 | </div>
|
53 | 102 |
|
54 | 103 | <style>
|
55 | 104 | .creator {
|
56 | 105 | max-width: 75vw;
|
57 | 106 | max-height: 75vh;
|
58 | 107 | }
|
| 108 | + .top { |
| 109 | + display: flex; |
| 110 | + align-items: center; |
| 111 | + justify-content: space-between; |
| 112 | + } |
59 | 113 | .name {
|
60 | 114 | display: flex;
|
61 | 115 | /* justify-content: space-between; */
|
|
66 | 120 | justify-content: flex-end;
|
67 | 121 | align-items: center;
|
68 | 122 | }
|
| 123 | + .bottom { |
| 124 | + display: flex; |
| 125 | + justify-content: flex-end; |
| 126 | + align-items: center; |
| 127 | + } |
69 | 128 | </style>
|
0 commit comments