block editor
This commit is contained in:
@@ -71,7 +71,7 @@
|
|||||||
aria-labelledby="panelsStayOpen-headingOther">
|
aria-labelledby="panelsStayOpen-headingOther">
|
||||||
<div class="accordion-body">
|
<div class="accordion-body">
|
||||||
<NavbarMenu
|
<NavbarMenu
|
||||||
schemas={ channel.schemas.filter((sc) => !sc.isEntry && sc.type !== "files")}
|
schemas={ channel.schemas.filter((sc) => !sc.isEntry && sc.type === "collection")}
|
||||||
schema={schema}
|
schema={schema}
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -5,7 +5,7 @@
|
|||||||
|
|
||||||
const channel = getContext("channel");
|
const channel = getContext("channel");
|
||||||
let email = "";
|
let email = "";
|
||||||
let successAlert;
|
let message = "";
|
||||||
|
|
||||||
function login(e) {
|
function login(e) {
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
@@ -15,7 +15,8 @@
|
|||||||
email: email,
|
email: email,
|
||||||
})
|
})
|
||||||
.then((response) => {
|
.then((response) => {
|
||||||
|
console.log(response)
|
||||||
|
message = "You will receive an email with a login link"
|
||||||
})
|
})
|
||||||
.catch((error) => {
|
.catch((error) => {
|
||||||
});
|
});
|
||||||
@@ -23,8 +24,13 @@
|
|||||||
|
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<SuccessAlert bind:this={successAlert}/>
|
|
||||||
<div class="wrapper-tiny">
|
<div class="wrapper-tiny">
|
||||||
|
{#if message}
|
||||||
|
<div class="alert alert-info" role="alert">
|
||||||
|
{message}
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{:else}
|
||||||
|
|
||||||
<form on:submit={login}>
|
<form on:submit={login}>
|
||||||
<div class="mb-3">
|
<div class="mb-3">
|
||||||
@@ -34,6 +40,7 @@
|
|||||||
bind:value={email}
|
bind:value={email}
|
||||||
class="form-control"
|
class="form-control"
|
||||||
id="emailaddress"
|
id="emailaddress"
|
||||||
|
required
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
@@ -41,6 +48,8 @@
|
|||||||
<div class="text-center mt-5 d-block">
|
<div class="text-center mt-5 d-block">
|
||||||
<SpinnerButton label="Login"/>
|
<SpinnerButton label="Login"/>
|
||||||
</div>
|
</div>
|
||||||
</form>
|
|
||||||
|
|
||||||
|
|
||||||
|
</form>
|
||||||
|
{/if}
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -157,10 +157,10 @@
|
|||||||
|
|
||||||
{#if !["_graph", "_info"].includes(activeContentTab)}
|
{#if !["_graph", "_info"].includes(activeContentTab)}
|
||||||
<div class="shadow-lg "
|
<div class="shadow-lg "
|
||||||
style="position:fixed;bottom:0;left:0px;width:100%;background:rgba(255,255,255,1);z-index:1050"
|
style="position:fixed;bottom:0;left:0px;width:100%;background: rgb(28, 28, 28);z-index:1050"
|
||||||
>
|
>
|
||||||
<div
|
<div
|
||||||
class="d-flex mt-4 mb-3 align-items-center justify-content-center"
|
class="d-flex mt-3 mb-3 align-items-center justify-content-center"
|
||||||
>
|
>
|
||||||
<StatusSelect bind:status={record.status} {record} {schema}/>
|
<StatusSelect bind:status={record.status} {record} {schema}/>
|
||||||
{#if isCreateMode}
|
{#if isCreateMode}
|
||||||
|
|||||||
@@ -51,7 +51,7 @@
|
|||||||
|
|
||||||
</div>
|
</div>
|
||||||
{#if channel.previewTarget}
|
{#if channel.previewTarget}
|
||||||
<a href="{channel.previewTargetUrl}?schema={schema.name}&id={record.id}" target="_blank" class="btn btn-outline-info ms-3">
|
<a href="{channel.previewTargetUrl}?schema={schema.name}&id={record.id}" target="_blank" class="btn btn-info ms-3">
|
||||||
Preview
|
Preview
|
||||||
</a>
|
</a>
|
||||||
{/if}
|
{/if}
|
||||||
|
|||||||
@@ -4,32 +4,35 @@
|
|||||||
import BlockElements from "./BlockElements.svelte";
|
import BlockElements from "./BlockElements.svelte";
|
||||||
import {flip} from "svelte/animate";
|
import {flip} from "svelte/animate";
|
||||||
import {quintOut} from 'svelte/easing';
|
import {quintOut} from 'svelte/easing';
|
||||||
|
import {getContext} from "svelte";
|
||||||
|
const channel = getContext("channel");
|
||||||
export let record;
|
export let record;
|
||||||
export let field;
|
export let field;
|
||||||
export let value = [];
|
export let value = [];
|
||||||
export let schemas;
|
|
||||||
export let graph;
|
export let graph;
|
||||||
|
let blockSchema = channel.schemas.find((s) => s.name === field.schema);
|
||||||
|
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
|
||||||
|
<div class=" bg-light lx-card">
|
||||||
<div class="inline-card-wrapper">
|
<div class="inline-card-wrapper">
|
||||||
<BlockButtons
|
<BlockButtons
|
||||||
bind:blockData={value}
|
bind:blockData={value}
|
||||||
|
{blockSchema}
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
{#each value as blockItemData (blockItemData.id)}
|
{#each value as blockItemData (blockItemData.id)}
|
||||||
<div class="block-field-wrapper" animate:flip="{{delay: 250, duration: 250, easing: quintOut}}">
|
<div class="block-field-wrapper" animate:flip="{{delay: 250, duration: 250, easing: quintOut}}">
|
||||||
<BlockElements
|
<BlockElements
|
||||||
bind:block={blockItemData}
|
bind:block={blockItemData}
|
||||||
|
bind:blockData={value}
|
||||||
{record}
|
{record}
|
||||||
{field}
|
{field}
|
||||||
{schemas}
|
|
||||||
bind:graph
|
bind:graph
|
||||||
/>
|
/>
|
||||||
<BlockButtons
|
|
||||||
bind:blockData={value}
|
|
||||||
/>
|
|
||||||
</div>
|
</div>
|
||||||
{/each}
|
{/each}
|
||||||
|
|
||||||
|
</div>
|
||||||
@@ -1,25 +1,21 @@
|
|||||||
<script>
|
<script>
|
||||||
import Icon from "../../common/Icon.svelte";
|
import Icon from "../../common/Icon.svelte";
|
||||||
import {randomId} from "../../../helpers";
|
import {insertBlock} from "./block";
|
||||||
|
|
||||||
export let blockId;
|
export let blockId;
|
||||||
export let blockData;
|
export let blockData;
|
||||||
|
export let blockSchema;
|
||||||
$: showOptions = false;
|
$: showOptions = false;
|
||||||
let validUis = ["text", "textarea", "rich", "reference"];
|
let validUis = ["heading", "textarea", "rich", "reference"];
|
||||||
|
|
||||||
function createBlock(e, validUI) {
|
function createBlock(e, ui) {
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
blockData = [...blockData, {
|
blockData = insertBlock(blockData,ui);
|
||||||
ui: validUI,
|
|
||||||
id: randomId(),
|
|
||||||
key: "",
|
|
||||||
value: null
|
|
||||||
}];
|
|
||||||
showOptions = false;
|
showOptions = false;
|
||||||
|
|
||||||
}
|
}
|
||||||
</script>
|
|
||||||
|
|
||||||
|
</script>
|
||||||
|
<div class="d-flex justify-content-left mb-2 ">
|
||||||
<button
|
<button
|
||||||
type="button"
|
type="button"
|
||||||
class:is-first={!blockId}
|
class:is-first={!blockId}
|
||||||
@@ -28,23 +24,21 @@
|
|||||||
>
|
>
|
||||||
<Icon width={24} height={24} icon="circle-plus"/>
|
<Icon width={24} height={24} icon="circle-plus"/>
|
||||||
</button>
|
</button>
|
||||||
|
|
||||||
|
|
||||||
{#if showOptions}
|
{#if showOptions}
|
||||||
<div class="bg-light lx-card d-flex">
|
<div class="d-flex ">
|
||||||
{#each validUis as validUi}
|
{#each blockSchema.fields as validUi}
|
||||||
|
<div class="ms-2">
|
||||||
<div class="me-2">
|
|
||||||
<button
|
<button
|
||||||
class="btn btn-sm btn-primary"
|
class="btn btn-sm btn-primary"
|
||||||
on:click={(e) => createBlock(e, validUi)}
|
on:click={(e) => createBlock(e, validUi)}
|
||||||
>{validUi}
|
>{validUi.label}
|
||||||
</button>
|
</button>
|
||||||
</div>
|
</div>
|
||||||
{/each}
|
{/each}
|
||||||
</div>
|
</div>
|
||||||
{/if}
|
|
||||||
|
|
||||||
|
{/if}
|
||||||
|
</div>
|
||||||
<style>
|
<style>
|
||||||
:global(.block-field-wrapper) {
|
:global(.block-field-wrapper) {
|
||||||
display: flex;
|
display: flex;
|
||||||
@@ -61,9 +55,8 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
.block-buttons {
|
.block-buttons {
|
||||||
/* padding: 0 5px; */
|
padding: 0px;
|
||||||
display: inline-block;
|
|
||||||
z-index: 1;
|
z-index: 1;
|
||||||
margin: 10px auto 0;
|
margin: 0px ;
|
||||||
}
|
}
|
||||||
</style>
|
</style>
|
||||||
|
|||||||
@@ -1,41 +1,98 @@
|
|||||||
<script>
|
<script>
|
||||||
import Text from "./elements/Text.svelte";
|
import Heading from "./elements/Heading.svelte";
|
||||||
import Textarea from "./elements/Textarea.svelte";
|
import Textarea from "./elements/Textarea.svelte";
|
||||||
import Rich from "./elements/Rich.svelte";
|
import Rich from "./elements/Rich.svelte";
|
||||||
import Reference from "./elements/Reference.svelte";
|
import Reference from "./elements/Reference.svelte";
|
||||||
|
import Icon from "../../common/Icon.svelte";
|
||||||
|
import {insertBlock} from "./block";
|
||||||
|
import { getContext} from "svelte";
|
||||||
|
import File from "./elements/File.svelte";
|
||||||
|
|
||||||
|
const channel = getContext("channel");
|
||||||
export let record;
|
export let record;
|
||||||
|
export let blockData;
|
||||||
export let field;
|
export let field;
|
||||||
export let schemas;
|
|
||||||
export let graph;
|
export let graph;
|
||||||
|
|
||||||
export let block;
|
export let block;
|
||||||
|
let blockSchema = channel.schemas.find((s) => s.name === field.schema);
|
||||||
|
function createBlock(e, ui, blockId) {
|
||||||
|
e.preventDefault();
|
||||||
|
blockData = insertBlock(blockData, ui, blockId);
|
||||||
|
}
|
||||||
|
|
||||||
|
function deleteBlock(e, blockId) {
|
||||||
|
e.preventDefault();
|
||||||
|
blockData = blockData.filter(b => b.id !== blockId)
|
||||||
|
}
|
||||||
|
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<div class="card editor-field bg-light lx-card d-flex">
|
<div class="card editor-field d-flex">
|
||||||
<span class="text-muted d-block fs-6 mb-1">{block.ui}</span>
|
<div class="d-flex justify-content-between">
|
||||||
{#if block.ui === "text"}
|
<span class="text-muted d-block fs-6 mb-1">{block.meta.label} <i>{block.meta.info.name}</i> </span>
|
||||||
|
<div class="dropdown d-inline-block">
|
||||||
|
<button
|
||||||
|
class="btn btn-link btn-sm"
|
||||||
|
type="button"
|
||||||
|
data-bs-toggle="dropdown"
|
||||||
|
aria-expanded="false"
|
||||||
|
>
|
||||||
|
<Icon icon="ellipsis"/>
|
||||||
|
</button>
|
||||||
|
<div class="dropdown-menu">
|
||||||
|
|
||||||
<Text
|
<h6 class="dropdown-header">
|
||||||
|
Block id: <input class="form-control-plaintext" readonly value={block.id}/>
|
||||||
|
Block name: <input class="form-control-plaintext" readonly value={block.meta.name}/>
|
||||||
|
</h6>
|
||||||
|
<h6 class="dropdown-header">Actions</h6>
|
||||||
|
<button
|
||||||
|
class="dropdown-item"
|
||||||
|
on:click={(e) => deleteBlock(e, block.id)}
|
||||||
|
>Delete
|
||||||
|
</button
|
||||||
|
>
|
||||||
|
<h6 class="dropdown-header">Insert after</h6>
|
||||||
|
|
||||||
|
{#each blockSchema.fields as blockField}
|
||||||
|
<button
|
||||||
|
class="dropdown-item"
|
||||||
|
on:click={(e) => createBlock(e, blockField, block.id)}
|
||||||
|
>{blockField.label}
|
||||||
|
</button
|
||||||
|
>
|
||||||
|
{/each}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
{#if block.meta.info.name === "heading"}
|
||||||
|
|
||||||
|
<Heading
|
||||||
bind:block={block}
|
bind:block={block}
|
||||||
/>
|
/>
|
||||||
|
|
||||||
{:else if block.ui === "textarea"}
|
{:else if block.meta.info.name === "textarea"}
|
||||||
|
|
||||||
<Textarea
|
<Textarea
|
||||||
bind:block={block}
|
bind:block={block}
|
||||||
/>
|
/>
|
||||||
|
|
||||||
{:else if block.ui === "rich"}
|
{:else if block.meta.info.name === "rich"}
|
||||||
<Rich
|
<Rich
|
||||||
bind:block={block}
|
bind:block={block}
|
||||||
/>
|
/>
|
||||||
{:else if block.ui === "reference"}
|
{:else if block.meta.info.name === "file"}
|
||||||
|
<File
|
||||||
|
{record}
|
||||||
|
{field}
|
||||||
|
bind:graph
|
||||||
|
bind:block={block}
|
||||||
|
/>
|
||||||
|
{:else if block.meta.info.name === "reference"}
|
||||||
<Reference
|
<Reference
|
||||||
{record}
|
{record}
|
||||||
{field}
|
{field}
|
||||||
{schemas}
|
|
||||||
bind:graph
|
bind:graph
|
||||||
bind:block={block}
|
bind:block={block}
|
||||||
/>
|
/>
|
||||||
|
|||||||
@@ -0,0 +1,25 @@
|
|||||||
|
import {randomId} from "../../../helpers.js";
|
||||||
|
|
||||||
|
export function insertBlock(blockData, blockField, afterBlockId = null) {
|
||||||
|
|
||||||
|
if (!afterBlockId) {
|
||||||
|
return [{
|
||||||
|
meta: blockField,
|
||||||
|
id: randomId(),
|
||||||
|
value: null
|
||||||
|
}, ...blockData];
|
||||||
|
}
|
||||||
|
|
||||||
|
return blockData.reduce((carry, block) => {
|
||||||
|
carry.push(block)
|
||||||
|
if (block.id === afterBlockId) {
|
||||||
|
carry.push({
|
||||||
|
meta: blockField,
|
||||||
|
id: randomId(),
|
||||||
|
value: null
|
||||||
|
});
|
||||||
|
}
|
||||||
|
return carry;
|
||||||
|
}, []);
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,105 @@
|
|||||||
|
<script>
|
||||||
|
import {getContext} from "svelte";
|
||||||
|
import PreviewCard from "../../PreviewCard.svelte";
|
||||||
|
import {sortByField} from "../../../edges/sortEdges";
|
||||||
|
import ReferenceInlineButtons from "../../elements/ReferenceInlineButtons.svelte"
|
||||||
|
import Sortable from "../../../libs/Sortable.svelte";
|
||||||
|
import {insertEdges} from "../../elements/reference";
|
||||||
|
import BrowseModal from "../../elements/BrowseModal.svelte";
|
||||||
|
|
||||||
|
|
||||||
|
const channel = getContext("channel");
|
||||||
|
export let block;
|
||||||
|
export let record;
|
||||||
|
export let field;
|
||||||
|
export let graph;
|
||||||
|
let browseModal;
|
||||||
|
let blockFieldName = field.name + ":" + block.id;
|
||||||
|
|
||||||
|
$: references = graph.edges
|
||||||
|
.filter((edge) => edge.field === blockFieldName)
|
||||||
|
.map((edge) => {
|
||||||
|
return graph.records.find((increc) => increc.id === edge.target && record.id === edge.source);
|
||||||
|
}).filter((rec) => (rec?.id ? true : false)) ?? [];
|
||||||
|
|
||||||
|
let collections = channel.schemas.filter((aschema) =>
|
||||||
|
block.meta.collections.includes(aschema.name)
|
||||||
|
);
|
||||||
|
|
||||||
|
function removeReference(e) {
|
||||||
|
e.preventDefault();
|
||||||
|
graph.edges = graph.edges.filter(
|
||||||
|
(edge) => !(edge.target === e.detail && edge.field === blockFieldName)
|
||||||
|
);
|
||||||
|
block.value = graph.edges.filter(edge => edge.field === blockFieldName) ?? [];
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
function openBrowseModal(e, schema) {
|
||||||
|
e.preventDefault();
|
||||||
|
browseModal.open(schema);
|
||||||
|
}
|
||||||
|
|
||||||
|
function reorder(e) {
|
||||||
|
graph.edges = sortByField(e.detail.source, e.detail.target, graph.edges, blockFieldName);
|
||||||
|
}
|
||||||
|
|
||||||
|
function insert(e) {
|
||||||
|
e.preventDefault();
|
||||||
|
browseModal.close();
|
||||||
|
graph = insertEdges(graph,record,e.detail.records,blockFieldName,e.detail.action);
|
||||||
|
}
|
||||||
|
|
||||||
|
</script>
|
||||||
|
|
||||||
|
|
||||||
|
<div class="mb-0">
|
||||||
|
{#if block.meta.collections.length === 1}
|
||||||
|
<button
|
||||||
|
class="btn btn-outline-primary"
|
||||||
|
on:click={(e) => openBrowseModal(e, collections[0].name)}
|
||||||
|
>
|
||||||
|
Browse
|
||||||
|
</button>
|
||||||
|
{:else}
|
||||||
|
<div class="dropdown d-inline-block">
|
||||||
|
<button
|
||||||
|
class="btn btn-outline-primary btn-sm"
|
||||||
|
type="button"
|
||||||
|
data-bs-toggle="dropdown"
|
||||||
|
aria-expanded="false"
|
||||||
|
>
|
||||||
|
Browse
|
||||||
|
</button>
|
||||||
|
<ul class="dropdown-menu">
|
||||||
|
{#each collections as collection}
|
||||||
|
<li>
|
||||||
|
<!-- {`${channelurl}/content/${collection.name}?parent=${record.id}&parentfield=${field.name}`} -->
|
||||||
|
<a
|
||||||
|
class="dropdown-item"
|
||||||
|
on:click={(e) =>
|
||||||
|
openBrowseModal(e, collection.name)}
|
||||||
|
href="/">{collection.label}</a
|
||||||
|
>
|
||||||
|
</li>
|
||||||
|
{/each}
|
||||||
|
</ul>
|
||||||
|
</div>
|
||||||
|
{/if}
|
||||||
|
</div>
|
||||||
|
{#if references.length > 0}
|
||||||
|
<Sortable sortableClass="row row-cols-3 mt-3" on:update={reorder}>
|
||||||
|
{#each references as reference (reference.id)}
|
||||||
|
<div class="col mb-3">
|
||||||
|
<PreviewCard
|
||||||
|
classes="h-100"
|
||||||
|
record={reference}
|
||||||
|
hasDelete={true}
|
||||||
|
on:remove={removeReference}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
{/each}
|
||||||
|
</Sortable>
|
||||||
|
{/if}
|
||||||
|
|
||||||
|
<BrowseModal bind:this={browseModal} on:insert={insert}/>
|
||||||
@@ -1,72 +1,52 @@
|
|||||||
<script>
|
<script>
|
||||||
import {uniq, uniqBy} from "lodash";
|
import {getContext} from "svelte";
|
||||||
import PreviewCard from "../../PreviewCard.svelte";
|
import PreviewCard from "../../PreviewCard.svelte";
|
||||||
import {sortByField} from "../../../edges/sortEdges";
|
import {sortByField} from "../../../edges/sortEdges";
|
||||||
import ReferenceInlineButtons from "../../elements/ReferenceInlineButtons.svelte"
|
import ReferenceInlineButtons from "../../elements/ReferenceInlineButtons.svelte"
|
||||||
import Sortable from "../../../libs/Sortable.svelte";
|
import Sortable from "../../../libs/Sortable.svelte";
|
||||||
|
import {insertEdges} from "../../elements/reference";
|
||||||
|
|
||||||
|
|
||||||
|
const channel = getContext("channel");
|
||||||
export let block;
|
export let block;
|
||||||
export let record;
|
export let record;
|
||||||
export let field;
|
export let field;
|
||||||
export let schemas;
|
|
||||||
export let graph;
|
export let graph;
|
||||||
|
|
||||||
$: references = graph.edges
|
let blockFieldName = field.name + ":" + block.id;
|
||||||
.filter((edge) => edge.field === field.name && block.value?.includes(edge.target))
|
|
||||||
.map((edge) => {
|
|
||||||
return graph.records.find((increc) => increc.data.id === edge.target && record.data.id === edge.source);
|
|
||||||
}).filter((rec) => (rec?.data?.id ? true : false)) ?? [];
|
|
||||||
|
|
||||||
let collections = schemas.filter((aschema) =>
|
$: references = graph.edges
|
||||||
field.collections.includes(aschema.name)
|
.filter((edge) => edge.field === blockFieldName)
|
||||||
|
.map((edge) => {
|
||||||
|
return graph.records.find((increc) => increc.id === edge.target && record.id === edge.source);
|
||||||
|
}).filter((rec) => (rec?.id ? true : false)) ?? [];
|
||||||
|
|
||||||
|
let collections = channel.schemas.filter((aschema) =>
|
||||||
|
block.meta.collections.includes(aschema.name)
|
||||||
);
|
);
|
||||||
|
|
||||||
function removeReference(e) {
|
function removeReference(e) {
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
graph.edges = graph.edges.filter(
|
graph.edges = graph.edges.filter(
|
||||||
(edge) => !(edge.target === e.detail && edge.field === field.name)
|
(edge) => !(edge.target === e.detail && edge.field === blockFieldName)
|
||||||
);
|
);
|
||||||
block.value = graph.edges.filter(edge => edge.field === field.name && block.value?.includes(edge.target)).map((edge) => edge.target) ?? [];
|
block.value = graph.edges.filter(edge => edge.field === blockFieldName) ?? [];
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function reorder(e) {
|
function reorder(e) {
|
||||||
graph.edges = sortByField(e.detail.source, e.detail.target, graph.edges, field.name);
|
graph.edges = sortByField(e.detail.source, e.detail.target, graph.edges, blockFieldName);
|
||||||
}
|
}
|
||||||
|
|
||||||
function insert(e) {
|
function insert(e) {
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
const recordsToInsert = e.detail.records;
|
graph = insertEdges(graph,record,e.detail.records,blockFieldName,e.detail.action);
|
||||||
const action = e.detail.action;
|
|
||||||
let newEdges = recordsToInsert.map((r) => {
|
|
||||||
return {
|
|
||||||
schema: r.schema,
|
|
||||||
target: r.data.id,
|
|
||||||
source: record.data.id,
|
|
||||||
field: field.name,
|
|
||||||
rank: ""
|
|
||||||
};
|
|
||||||
});
|
|
||||||
|
|
||||||
let replacedEdges = graph.edges;
|
|
||||||
let newBlockValue = [];
|
|
||||||
if (action === "replace") {
|
|
||||||
newBlockValue = newEdges.map(edge => edge.target)
|
|
||||||
replacedEdges = replacedEdges.filter((edge) => edge.field !== field.name);
|
|
||||||
} else {
|
|
||||||
newBlockValue = [...block.value ?? [], ...newEdges.map(edge => edge.target)]
|
|
||||||
}
|
|
||||||
block.value = uniq(newBlockValue);
|
|
||||||
graph.records = uniqBy([...graph.records, ...recordsToInsert], (r) => r.data.id);
|
|
||||||
graph.edges = uniqBy([...replacedEdges, ...newEdges], (edge) => edge.target + edge.field);
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<div class="inline-card-wrapper">
|
<div class="inline-card-wrapper">
|
||||||
<ReferenceInlineButtons
|
<ReferenceInlineButtons
|
||||||
{field}
|
|
||||||
buttonClass="mt-2"
|
buttonClass="mt-2"
|
||||||
recordId={null}
|
recordId={null}
|
||||||
schemas={collections}
|
schemas={collections}
|
||||||
@@ -76,11 +56,10 @@
|
|||||||
</div>
|
</div>
|
||||||
{#if references.length > 0}
|
{#if references.length > 0}
|
||||||
<Sortable sortableClass="row row-cols-3 mt-3" on:update={reorder}>
|
<Sortable sortableClass="row row-cols-3 mt-3" on:update={reorder}>
|
||||||
{#each references as reference (reference.data.id)}
|
{#each references as reference (reference.id)}
|
||||||
<div class="col mb-3">
|
<div class="col mb-3">
|
||||||
<PreviewCard
|
<PreviewCard
|
||||||
classes="h-100"
|
classes="h-100"
|
||||||
{schemas}
|
|
||||||
record={reference}
|
record={reference}
|
||||||
hasDelete={true}
|
hasDelete={true}
|
||||||
on:remove={removeReference}
|
on:remove={removeReference}
|
||||||
|
|||||||
@@ -0,0 +1,24 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Lucent\Schema;
|
||||||
|
|
||||||
|
use Lucent\Primitive\Collection;
|
||||||
|
|
||||||
|
class BlockSchema implements Schema
|
||||||
|
{
|
||||||
|
|
||||||
|
public Type $type = Type::BLOCK;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param Collection<FieldInterface> $fields
|
||||||
|
*/
|
||||||
|
function __construct(
|
||||||
|
public string $name,
|
||||||
|
public string $label,
|
||||||
|
public Collection $fields
|
||||||
|
)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,54 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Lucent\Schema\BlockUi;
|
||||||
|
|
||||||
|
use Lucent\Schema\FieldInfo;
|
||||||
|
use Lucent\Schema\FieldInterface;
|
||||||
|
use Lucent\Schema\FieldType;
|
||||||
|
use Lucent\Schema\Validator\MinMaxInterface;
|
||||||
|
|
||||||
|
class File implements FieldInterface, MinMaxInterface
|
||||||
|
{
|
||||||
|
public FieldInfo $info;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param string[] $collections
|
||||||
|
*/
|
||||||
|
public function __construct(
|
||||||
|
public string $name,
|
||||||
|
public string $label,
|
||||||
|
public string $mime = "",
|
||||||
|
public ?int $min = null,
|
||||||
|
public ?int $max = null,
|
||||||
|
public array $collections = [],
|
||||||
|
)
|
||||||
|
{
|
||||||
|
$this->info = new FieldInfo("file", "File", FieldType::FILE);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function format(array $input, array $output): array
|
||||||
|
{
|
||||||
|
return $output;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function failMin(mixed $value): bool
|
||||||
|
{
|
||||||
|
if (is_null($value)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return count($value) < $this->min;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function failMax(mixed $value): bool
|
||||||
|
{
|
||||||
|
if (is_null($value)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return count($value) < $this->min;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
@@ -0,0 +1,33 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Lucent\Schema\BlockUi;
|
||||||
|
|
||||||
|
use Lucent\Schema\FieldInfo;
|
||||||
|
use Lucent\Schema\FieldInterface;
|
||||||
|
use Lucent\Schema\FieldType;
|
||||||
|
use Lucent\Schema\Nullable;
|
||||||
|
use Lucent\Schema\Validator\RequiredInterface;
|
||||||
|
|
||||||
|
class Heading implements FieldInterface
|
||||||
|
{
|
||||||
|
public FieldInfo $info;
|
||||||
|
|
||||||
|
public function __construct(
|
||||||
|
public string $name,
|
||||||
|
public string $label,
|
||||||
|
public ?int $min = null,
|
||||||
|
public ?int $max = null,
|
||||||
|
public string $default = "",
|
||||||
|
)
|
||||||
|
{
|
||||||
|
$this->info = new FieldInfo("heading", "Heading", FieldType::STRING);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function format(array $input, array $output): array
|
||||||
|
{
|
||||||
|
$output[$this->name] = $input[$this->name] ?? "";
|
||||||
|
return $output;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
@@ -0,0 +1,54 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Lucent\Schema\BlockUi;
|
||||||
|
|
||||||
|
use Lucent\Schema\FieldInfo;
|
||||||
|
use Lucent\Schema\FieldInterface;
|
||||||
|
use Lucent\Schema\FieldType;
|
||||||
|
use Lucent\Schema\Validator\MinMaxInterface;
|
||||||
|
|
||||||
|
class Reference implements FieldInterface, MinMaxInterface
|
||||||
|
{
|
||||||
|
public FieldInfo $info;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param string[] $collections
|
||||||
|
*/
|
||||||
|
public function __construct(
|
||||||
|
public string $name,
|
||||||
|
public string $label,
|
||||||
|
public ?int $min = null,
|
||||||
|
public ?int $max = null,
|
||||||
|
public array $collections = [],
|
||||||
|
public string $searchField = "",
|
||||||
|
public string $layout = "",
|
||||||
|
)
|
||||||
|
{
|
||||||
|
$this->info = new FieldInfo("reference", "Reference", FieldType::REFERENCE);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function format(array $input, array $output): array
|
||||||
|
{
|
||||||
|
return $output;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function failMin(mixed $value): bool
|
||||||
|
{
|
||||||
|
if (is_null($value)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return count($value) < $this->min;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function failMax(mixed $value): bool
|
||||||
|
{
|
||||||
|
if (is_null($value)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return count($value) < $this->min;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
@@ -0,0 +1,33 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Lucent\Schema\BlockUi;
|
||||||
|
|
||||||
|
use Lucent\Schema\FieldInfo;
|
||||||
|
use Lucent\Schema\FieldInterface;
|
||||||
|
use Lucent\Schema\FieldType;
|
||||||
|
use Lucent\Schema\Nullable;
|
||||||
|
use Lucent\Schema\Validator\RequiredInterface;
|
||||||
|
|
||||||
|
class Textarea implements FieldInterface
|
||||||
|
{
|
||||||
|
public FieldInfo $info;
|
||||||
|
|
||||||
|
public function __construct(
|
||||||
|
public string $name,
|
||||||
|
public string $label,
|
||||||
|
public ?int $min = null,
|
||||||
|
public ?int $max = null,
|
||||||
|
public string $default = "",
|
||||||
|
)
|
||||||
|
{
|
||||||
|
$this->info = new FieldInfo("textarea", "Textarea", FieldType::STRING);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function format(array $input, array $output): array
|
||||||
|
{
|
||||||
|
$output[$this->name] = $input[$this->name] ?? "";
|
||||||
|
return $output;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
@@ -35,6 +35,11 @@ class SchemaService
|
|||||||
isEntry: $schemaArr["isEntry"] ?? false,
|
isEntry: $schemaArr["isEntry"] ?? false,
|
||||||
color: $schemaArr["color"] ?? "",
|
color: $schemaArr["color"] ?? "",
|
||||||
titleTemplate: $schemaArr["titleTemplate"] ?? "",
|
titleTemplate: $schemaArr["titleTemplate"] ?? "",
|
||||||
|
),
|
||||||
|
"block" => new BlockSchema(
|
||||||
|
name: $schemaArr["name"],
|
||||||
|
label: $schemaArr["label"],
|
||||||
|
fields: (new Collection($schemaArr["fields"]))->map([$this, 'mapBlockFields'])
|
||||||
)
|
)
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -47,6 +52,13 @@ class SchemaService
|
|||||||
return new $className(...$field);
|
return new $className(...$field);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function mapBlockFields(array $field): FieldInterface
|
||||||
|
{
|
||||||
|
$className = "\\Lucent\Schema\BlockUi\\" . ucfirst($field["ui"]);
|
||||||
|
unset($field["ui"]);
|
||||||
|
return new $className(...$field);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
//
|
//
|
||||||
// /**
|
// /**
|
||||||
|
|||||||
@@ -7,4 +7,5 @@ enum Type: string
|
|||||||
{
|
{
|
||||||
case COLLECTION = 'collection';
|
case COLLECTION = 'collection';
|
||||||
case FILES = 'files';
|
case FILES = 'files';
|
||||||
|
case BLOCK = 'block';
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -19,6 +19,7 @@ class Block implements FieldInterface, RequiredInterface
|
|||||||
public bool $required = false,
|
public bool $required = false,
|
||||||
public string $default = "",
|
public string $default = "",
|
||||||
public bool $readonly = false,
|
public bool $readonly = false,
|
||||||
|
public string $schema = "",
|
||||||
public string $group = "",
|
public string $group = "",
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -14,7 +14,6 @@
|
|||||||
<link rel="stylesheet" href="/vendor/lucent/dist/{{ $manifest['main.css']["file"] }}" />
|
<link rel="stylesheet" href="/vendor/lucent/dist/{{ $manifest['main.css']["file"] }}" />
|
||||||
<script type="module" src="/vendor/lucent/dist/{{ $manifest['main.js']["file"] }}"></script>
|
<script type="module" src="/vendor/lucent/dist/{{ $manifest['main.js']["file"] }}"></script>
|
||||||
<link rel="icon" type="image/x-icon" href="/favicon.ico">
|
<link rel="icon" type="image/x-icon" href="/favicon.ico">
|
||||||
<link rel="icon" type="image/x-icon" href="/favicon.ico">
|
|
||||||
|
|
||||||
</head>
|
</head>
|
||||||
|
|
||||||
|
|||||||
@@ -7,13 +7,13 @@
|
|||||||
<meta name="csrf-token" content="{{ csrf_token() }}">
|
<meta name="csrf-token" content="{{ csrf_token() }}">
|
||||||
<title>@yield('title') - Lucent Data Platform</title>
|
<title>@yield('title') - Lucent Data Platform</title>
|
||||||
<!-- if development -->
|
<!-- if development -->
|
||||||
{{-- @php--}}
|
@php
|
||||||
{{-- echo '<script type="module" crossorigin src="http://127.0.0.1:5173/@vite/client"></script>';--}}
|
echo '<script type="module" crossorigin src="http://127.0.0.1:5173/@vite/client"></script>';
|
||||||
{{-- @endphp--}}
|
@endphp
|
||||||
{{-- <script type="module" crossorigin src="http://127.0.0.1:5173/main.js"></script>--}}
|
<script type="module" crossorigin src="http://127.0.0.1:5173/main.js"></script>
|
||||||
<!-- if production -->
|
<!-- if production -->
|
||||||
<link rel="stylesheet" href="/vendor/lucent/dist/{{ $manifest['main.css']["file"] }}" />
|
{{-- <link rel="stylesheet" href="/vendor/lucent/dist/{{ $manifest['main.css']["file"] }}" />--}}
|
||||||
<script type="module" src="/vendor/lucent/dist/{{ $manifest['main.js']["file"] }}"></script>
|
{{-- <script type="module" src="/vendor/lucent/dist/{{ $manifest['main.js']["file"] }}"></script>--}}
|
||||||
|
|
||||||
|
|
||||||
<link rel="icon" type="image/x-icon" href="/favicon.ico">
|
<link rel="icon" type="image/x-icon" href="/favicon.ico">
|
||||||
|
|||||||
Reference in New Issue
Block a user