-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
* Added basic accordion. Added createOpenEditorHtml for the purpose of separating editor from HTML preview for more advanced editing scenarios. Created `ItemDescriptions` component to contain the three description editors. Swapped the `ItemDescriptionWithSidebarTab` to use `ItemDescriptions`. * Got the editor working and laying out properly. * Cleaned up Accordion appearance a bit. Enabled support for having an accordion item start as opened. Added some missing background colors for prose mirror light mode, as a temporary measure, to prevent transparent menu backgrounds. * Made the item descriptions data-driven. Added itemDescriptions and originalContext array to the item sheet context implementation and type definition. Ordered prop names alphabetically in the ItemSheetContext type definition. * Made the edit button for item descriptions more clickable by applying some horizontal padding to the button.
- Loading branch information
Showing
10 changed files
with
261 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
<script context="module" lang="ts"> | ||
import { setContext } from 'svelte'; | ||
import { writable, type Writable } from 'svelte/store'; | ||
export interface AccordionCtxType { | ||
selected?: Writable<object>; | ||
} | ||
</script> | ||
|
||
<script lang="ts"> | ||
export let multiple: boolean = false; | ||
$: setContext<AccordionCtxType>('ctx', { | ||
selected: multiple ? undefined : writable(), | ||
}); | ||
</script> | ||
|
||
{#key multiple} | ||
<div class={$$props.class}> | ||
<slot /> | ||
</div> | ||
{/key} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
<script lang="ts"> | ||
import { getContext, onMount } from 'svelte'; | ||
import type { AccordionCtxType } from './Accordion.svelte'; | ||
import { writable } from 'svelte/store'; | ||
import { slide } from 'svelte/transition'; | ||
import { quadInOut } from 'svelte/easing'; | ||
export let open: boolean = false; | ||
const ctx = getContext<AccordionCtxType>('ctx') ?? {}; | ||
const self = {}; | ||
const selected = ctx.selected ?? writable(); | ||
function toggle() { | ||
selected.set(open ? {} : self); | ||
} | ||
onMount(() => { | ||
if (open) { | ||
$selected = self; | ||
} | ||
return selected.subscribe((x) => (open = x === self)); | ||
}); | ||
</script> | ||
|
||
<section class="accordion-item"> | ||
<h2 class="accordion-item-header" class:open> | ||
<button | ||
class="accordion-item-toggle transparent-button" | ||
type="button" | ||
on:click={() => toggle()} | ||
> | ||
<span class="accordion-arrow" class:open | ||
><i class="fas fa-chevron-right" /></span | ||
> | ||
<slot name="header" /> | ||
</button> | ||
</h2> | ||
|
||
{#if open} | ||
<div | ||
class="accordion-item-content" | ||
transition:slide={{ duration: 200, easing: quadInOut }} | ||
> | ||
<slot /> | ||
</div> | ||
{:else} | ||
<div class="accordion-item-content hidden"> | ||
<slot /> | ||
</div> | ||
{/if} | ||
</section> | ||
|
||
<style lang="scss"> | ||
.accordion-item { | ||
margin-block-end: 0.5rem; | ||
} | ||
.accordion-item-header { | ||
padding: 0.25rem; | ||
background-color: var(--t5ek-faintest-color); | ||
margin: 0; | ||
} | ||
.accordion-item-toggle { | ||
display: flex; | ||
gap: 0.5rem; | ||
align-items: center; | ||
.accordion-arrow { | ||
font-size: 0.75rem; | ||
transition: transform 0.2s; | ||
&.open { | ||
transform: rotate(90deg); | ||
} | ||
} | ||
} | ||
.accordion-item-content { | ||
overflow-y: hidden; | ||
&.hidden { | ||
display: none; | ||
} | ||
} | ||
</style> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
<script lang="ts"> | ||
import { FoundryAdapter } from 'src/foundry/foundry-adapter'; | ||
/** | ||
* The HTML to render or to edit. | ||
*/ | ||
export let content: string; | ||
/** | ||
* The data field to update via form post, which will be applied to the entity the form represents (e.g., to the Actor). | ||
*/ | ||
export let target: string; | ||
</script> | ||
|
||
{@html FoundryAdapter.createOpenEditorHtml(content, target)} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
<script lang="ts"> | ||
import RerenderAfterFormSubmission from 'src/components/utility/RerenderAfterFormSubmission.svelte'; | ||
import { FoundryAdapter } from 'src/foundry/foundry-adapter'; | ||
import type { ItemSheetContext } from 'src/types/item'; | ||
import { getContext } from 'svelte'; | ||
import type { Readable } from 'svelte/store'; | ||
import Accordion from 'src/components/accordion/Accordion.svelte'; | ||
import AccordionItem from 'src/components/accordion/AccordionItem.svelte'; | ||
import OpenSheetEditor from 'src/components/editor/OpenSheetEditor.svelte'; | ||
let context = getContext<Readable<ItemSheetContext>>('context'); | ||
const localize = FoundryAdapter.localize; | ||
function onEditorActivation(node: HTMLElement) { | ||
if (editorIsActive) { | ||
editing = false; | ||
editorIsActive = false; | ||
return; | ||
} | ||
$context.activateFoundryJQueryListeners(node); | ||
editorIsActive = true; | ||
} | ||
let editing = false; | ||
let editorIsActive = false; | ||
let valueToEdit: string; | ||
let fieldToEdit: string; | ||
function edit(value: string, field: string) { | ||
valueToEdit = value; | ||
fieldToEdit = field; | ||
editing = true; | ||
} | ||
let accordionItemOpenStates = $context.itemDescriptions.map( | ||
(_, i) => i === 0 | ||
); | ||
</script> | ||
|
||
<div class="item-descriptions-container"> | ||
<Accordion multiple class={editing ? 'hidden' : ''}> | ||
{#each $context.itemDescriptions as itemDescription, i (itemDescription.field)} | ||
<AccordionItem bind:open={accordionItemOpenStates[i]}> | ||
<span | ||
slot="header" | ||
class="flex-1 flex-row justify-content-space-between" | ||
> | ||
{itemDescription.label} | ||
|
||
{#if $context.owner} | ||
<button | ||
type="button" | ||
class="inline-icon-button edit-item-description" | ||
on:click|stopPropagation={() => | ||
edit(itemDescription.content, itemDescription.field)} | ||
><i class="fas fa-edit" /></button | ||
> | ||
{/if} | ||
</span> | ||
{@html itemDescription.content} | ||
</AccordionItem> | ||
{/each} | ||
</Accordion> | ||
|
||
{#if editing} | ||
<RerenderAfterFormSubmission andOnValueChange={valueToEdit}> | ||
<article class="editor-container" use:onEditorActivation> | ||
<OpenSheetEditor content={valueToEdit} target={fieldToEdit} /> | ||
</article> | ||
</RerenderAfterFormSubmission> | ||
{/if} | ||
</div> | ||
|
||
<style lang="scss"> | ||
.item-descriptions-container { | ||
padding-right: 0.3125rem; | ||
.edit-item-description { | ||
padding-left: 2rem; | ||
padding-right: 0.125rem; | ||
} | ||
} | ||
</style> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters