-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
options generic, html/image options complete
- Loading branch information
Showing
9 changed files
with
213 additions
and
15 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,17 @@ | ||
export const defaultOptions = { | ||
blockHeading: "", | ||
html: "" | ||
} | ||
|
||
export const optionsConfig = { | ||
blockHeading: { | ||
label: "Block Heading", | ||
type: "text", | ||
default: defaultOptions.blockHeading | ||
}, | ||
html: { | ||
label: "HTML", | ||
type: "textarea", | ||
default: defaultOptions.html | ||
} | ||
} |
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
29 changes: 29 additions & 0 deletions
29
src/lib/components/blocks/repeatable/image/image.options.js
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,29 @@ | ||
export const defaultOptions = { | ||
blockHeading: "", | ||
imageUrl: "", | ||
width: "", | ||
height: "", | ||
} | ||
|
||
export const optionsConfig = { | ||
blockHeading: { | ||
label: "Block Heading", | ||
type: "text", | ||
default: defaultOptions.blockHeading | ||
}, | ||
imageUrl: { | ||
label: "Image URL", | ||
type: "text", | ||
default: defaultOptions.imageUrl | ||
}, | ||
width: { | ||
label: "Width", | ||
type: "text", | ||
default: defaultOptions.width | ||
}, | ||
height: { | ||
label: "Height", | ||
type: "text", | ||
default: defaultOptions.height | ||
} | ||
} |
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 |
---|---|---|
@@ -1 +1,24 @@ | ||
<strong class="text-yellow-50">IMAGE COMPONENT</strong> | ||
<script lang="ts"> | ||
import { getContext, onMount, onDestroy, tick } from'svelte'; | ||
import { MY_RELAY_PAGE } from '$lib/contextKeys'; | ||
import Block from '$lib/components/wrappers/block.svelte'; | ||
import type { Writable } from 'svelte/store'; | ||
import type { MyRelayPage } from '$lib/core/MRP'; | ||
const MRP: Writable<MyRelayPage> = getContext(MY_RELAY_PAGE); | ||
export let key: string; | ||
export let id: string; | ||
</script> | ||
<Block key={key} id={id}> | ||
<svelte:fragment slot="content"> | ||
<img | ||
src={$MRP.loader.config.event.blocks[key]?.options?.imageUrl} | ||
alt={$MRP.loader.config.event.blocks[key]?.options?.imageUrl} | ||
width={$MRP.loader.config.event.blocks[key]?.options?.width || "100%"} | ||
height={$MRP.loader.config.event.blocks[key]?.options?.height || "auto"} | ||
/> | ||
</svelte:fragment> | ||
</Block> |
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,86 @@ | ||
<script lang="ts"> | ||
import { onMount, getContext } from "svelte"; | ||
import { writable, type Writable } from "svelte/store"; | ||
import type { MyRelayPage } from '$lib/core/MRP'; | ||
import { MY_RELAY_PAGE } from '$lib/contextKeys'; | ||
import { Input } from "$lib/components/ui/input/index.js"; | ||
import { Checkbox } from "$lib/components/ui/checkbox"; | ||
import { Label } from "$lib/components/ui/label/index.js"; | ||
import { Textarea } from "$lib/components/ui/textarea"; | ||
const MRP: Writable<MyRelayPage> = getContext(MY_RELAY_PAGE); | ||
const options: Writable<{ [key: string]: any }> = writable({}); | ||
const optionsConfig: Writable<{ [key: string]: any }> = writable({}); | ||
const loaded: Writable<boolean> = writable(false); | ||
export let change: (key: string, value: any) => undefined; | ||
export let key: string; | ||
$: type = (value: any) => { | ||
if(typeof value === 'object'){ | ||
if(value instanceof Array){ | ||
return 'array' | ||
} else if(value instanceof Object){ | ||
return 'object' | ||
} | ||
} | ||
return typeof value | ||
} | ||
const loadBlockOptions = async (key: string) => { | ||
await $MRP?.loader?.loadComponentOptions(key) | ||
const {options:_options, optionsConfig:config} = await $MRP?.loader?.loadComponentOptions(key) | ||
options.set(_options) | ||
optionsConfig.set(config) | ||
} | ||
onMount( async () => { | ||
await loadBlockOptions(key); | ||
loaded.set(true); | ||
}) | ||
$: inputName = (key: string) => $optionsConfig?.[key]?.label.replace(" ", "-").toLowerCase() | ||
$: inputLabel = (key: string) => $optionsConfig?.[key]?.label | ||
$: inputValue = (key: string) => $options?.[key] | ||
$: inputType = (key: string) => $optionsConfig?.[key]?.type | ||
</script> | ||
|
||
loaded: {$loaded} | ||
|
||
{#if $loaded} | ||
{#each Object.keys($optionsConfig) as optionKey} | ||
{#if inputType(optionKey) === 'text'} | ||
<Label for={inputName(optionKey)} >{inputLabel(optionKey)}</Label> | ||
<Input type="text" name={inputName(optionKey)} value={inputValue(optionKey)} on:change={event => change(optionKey, event?.target?.value)} /> | ||
{/if} | ||
{#if inputType(optionKey) === 'textarea'} | ||
<Label for={inputName(optionKey)} >{inputLabel(optionKey)}</Label> | ||
<Textarea name={inputName(optionKey)} value={inputValue(optionKey)} on:change={event => change(optionKey, event?.target?.value)}></Textarea> | ||
{/if} | ||
{#if inputType(optionKey) === 'checkbox'} | ||
<Label for={inputName(optionKey)} >{inputLabel(optionKey)}</Label> | ||
<Checkbox type="checkbox" name={inputName(optionKey)} checked={$options?.[optionKey]} on:change={event => change(optionKey, event?.target?.checked)} /> | ||
{/if} | ||
{#if inputType(optionKey) === 'radio'} | ||
<Label for={inputName(optionKey)} >{inputLabel(optionKey)}</Label> | ||
{#each $optionsConfig[optionKey].options as option} | ||
<input type="radio" name={inputName(optionKey)} value={option} checked={$options?.[optionKey] === option} on:change={event => change(optionKey, event?.target?.value)} /> | ||
{/each} | ||
{/if} | ||
{#if inputType(optionKey) === 'email'} | ||
<Label for={inputName(optionKey)} >{inputLabel(optionKey)}</Label> | ||
<Input type="email" name={inputName(optionKey)} value={inputValue(optionKey)} on:change={event => change(optionKey, event?.target?.value)} /> | ||
{/if} | ||
{#if inputType(optionKey) === 'url'} | ||
<Label for={inputName(optionKey)} >{inputLabel(optionKey)}</Label> | ||
<Input type="url" name={inputName(optionKey)} value={inputValue(optionKey)} on:change={event => change(optionKey, event?.target?.value)} /> | ||
{/if} | ||
{#if inputType(optionKey) === 'number'} | ||
<Label for={inputName(optionKey)} >{inputLabel(optionKey)}</Label> | ||
<Input type="number" name={inputName(optionKey)} value={inputValue(optionKey)} on:change={event => change(optionKey, event?.target?.value)} /> | ||
{/if} | ||
{/each} | ||
{/if} |
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