@kyro-cms/admin 0.12.5 → 0.12.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +32 -110
- package/dist/index.css +1 -1
- package/dist/index.d.cts +1 -3
- package/dist/index.d.ts +1 -3
- package/dist/index.js +32 -110
- package/package.json +7 -2
- package/src/components/AutoForm.tsx +35 -45
- package/src/components/DashboardMetrics.tsx +519 -290
- package/src/components/FieldRenderer.tsx +59 -47
- package/src/components/ListView.tsx +10 -5
- package/src/components/PluginsManager.tsx +37 -20
- package/src/components/Sidebar.astro +7 -14
- package/src/components/blocks/AccordionBlock.tsx +8 -4
- package/src/components/blocks/ArrayBlock.tsx +4 -3
- package/src/components/blocks/BlockEditModal.tsx +4 -3
- package/src/components/blocks/CardBlock.tsx +10 -2
- package/src/components/blocks/ChildBlocksTree.tsx +19 -18
- package/src/components/blocks/CodeBlock.tsx +7 -2
- package/src/components/blocks/FileBlock.tsx +6 -2
- package/src/components/blocks/GenericBlock.tsx +1 -1
- package/src/components/blocks/HeadingBlock.tsx +6 -2
- package/src/components/blocks/HeadingSubheadingBlock.tsx +7 -2
- package/src/components/blocks/HeroBlock.tsx +12 -3
- package/src/components/blocks/ImageBlock.tsx +8 -2
- package/src/components/blocks/ListBlock.tsx +6 -2
- package/src/components/blocks/ParagraphBlock.tsx +2 -2
- package/src/components/blocks/RelationshipBlock.tsx +10 -2
- package/src/components/blocks/VideoBlock.tsx +7 -2
- package/src/components/fields/AccordionField.tsx +1 -1
- package/src/components/fields/ArrayLayout.tsx +55 -58
- package/src/components/fields/BlocksField.tsx +1 -1
- package/src/components/fields/ChildrenField.tsx +3 -2
- package/src/components/fields/CodeField.tsx +3 -2
- package/src/components/fields/ColumnsField.tsx +3 -2
- package/src/components/fields/DateField.tsx +2 -2
- package/src/components/fields/FieldLayout.tsx +3 -3
- package/src/components/fields/GroupLayout.tsx +2 -2
- package/src/components/fields/MarkdownField.tsx +2 -2
- package/src/components/fields/NumberField.tsx +4 -4
- package/src/components/fields/RelationshipField.tsx +4 -1
- package/src/components/fields/RichTextField.tsx +200 -5
- package/src/components/fields/extensions/blockComponents.tsx +1 -1
- package/src/components/fields/extensions/blocksStore.ts +15 -12
- package/src/components/ui/Pagination.tsx +1 -1
- package/src/fields/index.ts +1 -1
- package/src/hooks/useAutoFormState.ts +7 -6
- package/src/index.ts +0 -1
- package/src/integration.ts +64 -26
- package/src/lib/api.ts +1 -0
- package/src/lib/config.ts +6 -19
- package/src/lib/core-types.ts +78 -0
- package/src/plugins/seo-admin.tsx +155 -0
- package/src/styles/main.css +2 -0
- package/src/vite-env.d.ts +10 -1
|
@@ -12,11 +12,12 @@ import { BlockEditModal } from "./BlockEditModal";
|
|
|
12
12
|
import { useStore } from "zustand";
|
|
13
13
|
import { BlocksContext } from "../fields/extensions/blocksStore";
|
|
14
14
|
import { useContext } from "react";
|
|
15
|
+
import type { BlockData } from "@kyro-cms/core/client";
|
|
15
16
|
|
|
16
17
|
interface ChildBlocksTreeProps {
|
|
17
18
|
blockId: string;
|
|
18
|
-
children:
|
|
19
|
-
onUpdateChildren: (children:
|
|
19
|
+
children: BlockData[];
|
|
20
|
+
onUpdateChildren: (children: BlockData[]) => void;
|
|
20
21
|
depth?: number;
|
|
21
22
|
maxDepth?: number;
|
|
22
23
|
}
|
|
@@ -61,12 +62,12 @@ export const ChildBlocksTree: React.FC<ChildBlocksTreeProps> = ({
|
|
|
61
62
|
}
|
|
62
63
|
return child;
|
|
63
64
|
});
|
|
64
|
-
onUpdateChildren(updated);
|
|
65
|
+
onUpdateChildren(updated as BlockData[]);
|
|
65
66
|
};
|
|
66
67
|
|
|
67
68
|
const handleUpdateChildChildren = (
|
|
68
69
|
childId: string,
|
|
69
|
-
newGrandchildren:
|
|
70
|
+
newGrandchildren: BlockData[],
|
|
70
71
|
) => {
|
|
71
72
|
const updated = children.map((child) => {
|
|
72
73
|
if (child.id === childId) {
|
|
@@ -89,7 +90,7 @@ export const ChildBlocksTree: React.FC<ChildBlocksTreeProps> = ({
|
|
|
89
90
|
});
|
|
90
91
|
};
|
|
91
92
|
|
|
92
|
-
const renderBlock = (child:
|
|
93
|
+
const renderBlock = (child: BlockData) => {
|
|
93
94
|
const hasChildren = child.children && child.children.length > 0;
|
|
94
95
|
const isExpanded = expandedIds.has(child.id);
|
|
95
96
|
const BlockComponent = getBlockComponent(child.type);
|
|
@@ -139,8 +140,8 @@ export const ChildBlocksTree: React.FC<ChildBlocksTreeProps> = ({
|
|
|
139
140
|
<div className="flex-1 min-w-0">
|
|
140
141
|
<div className="text-xs font-medium text-[var(--kyro-text-secondary)] truncate">
|
|
141
142
|
{getBlockDisplayLabel(child)}
|
|
142
|
-
{child.data?.text ? ` - ${child.data.text.slice(0, 30)}` : ""}
|
|
143
|
-
{child.data?.heading ? ` - ${child.data.heading.slice(0, 30)}` : ""}
|
|
143
|
+
{typeof child.data?.text === 'string' ? ` - ${child.data.text.slice(0, 30)}` : ""}
|
|
144
|
+
{typeof child.data?.heading === 'string' ? ` - ${child.data.heading.slice(0, 30)}` : ""}
|
|
144
145
|
</div>
|
|
145
146
|
{blockSchema?.admin?.description && (
|
|
146
147
|
<div className="text-[10px] text-[var(--kyro-text-muted)] mt-0.5 truncate opacity-80">
|
|
@@ -151,7 +152,7 @@ export const ChildBlocksTree: React.FC<ChildBlocksTreeProps> = ({
|
|
|
151
152
|
|
|
152
153
|
{hasChildren && (
|
|
153
154
|
<span className="text-[10px] bg-[var(--kyro-surface-accent)] px-2 py-0.5 rounded text-[var(--kyro-text-muted)] font-medium">
|
|
154
|
-
{child.children
|
|
155
|
+
{child.children?.length} nested
|
|
155
156
|
</span>
|
|
156
157
|
)}
|
|
157
158
|
|
|
@@ -203,7 +204,7 @@ export const ChildBlocksTree: React.FC<ChildBlocksTreeProps> = ({
|
|
|
203
204
|
<div className="mt-1">
|
|
204
205
|
<NestedChildBlocks
|
|
205
206
|
parentId={child.id}
|
|
206
|
-
children={child.children}
|
|
207
|
+
children={child.children ?? []}
|
|
207
208
|
onUpdateChildren={(newGrandchildren) =>
|
|
208
209
|
handleUpdateChildChildren(child.id, newGrandchildren)
|
|
209
210
|
}
|
|
@@ -297,8 +298,8 @@ export const ChildBlocksTree: React.FC<ChildBlocksTreeProps> = ({
|
|
|
297
298
|
|
|
298
299
|
interface NestedChildBlocksProps {
|
|
299
300
|
parentId: string;
|
|
300
|
-
children:
|
|
301
|
-
onUpdateChildren: (children:
|
|
301
|
+
children: BlockData[];
|
|
302
|
+
onUpdateChildren: (children: BlockData[]) => void;
|
|
302
303
|
depth: number;
|
|
303
304
|
maxDepth: number;
|
|
304
305
|
}
|
|
@@ -341,12 +342,12 @@ const NestedChildBlocks: React.FC<NestedChildBlocksProps> = ({
|
|
|
341
342
|
}
|
|
342
343
|
return child;
|
|
343
344
|
});
|
|
344
|
-
onUpdateChildren(updated);
|
|
345
|
+
onUpdateChildren(updated as BlockData[]);
|
|
345
346
|
};
|
|
346
347
|
|
|
347
348
|
const handleUpdateChildChildren = (
|
|
348
349
|
childId: string,
|
|
349
|
-
newGrandchildren:
|
|
350
|
+
newGrandchildren: BlockData[],
|
|
350
351
|
) => {
|
|
351
352
|
const updated = children.map((child) => {
|
|
352
353
|
if (child.id === childId) {
|
|
@@ -369,7 +370,7 @@ const NestedChildBlocks: React.FC<NestedChildBlocksProps> = ({
|
|
|
369
370
|
});
|
|
370
371
|
};
|
|
371
372
|
|
|
372
|
-
const renderBlock = (child:
|
|
373
|
+
const renderBlock = (child: BlockData) => {
|
|
373
374
|
const hasChildren = child.children && child.children.length > 0;
|
|
374
375
|
const isExpanded = expandedIds.has(child.id);
|
|
375
376
|
const BlockComponent = getBlockComponent(child.type);
|
|
@@ -419,8 +420,8 @@ const NestedChildBlocks: React.FC<NestedChildBlocksProps> = ({
|
|
|
419
420
|
<div className="flex-1 min-w-0">
|
|
420
421
|
<div className="text-xs font-medium text-[var(--kyro-text-secondary)] truncate">
|
|
421
422
|
{getBlockDisplayLabel(child)}
|
|
422
|
-
{child.data?.text ? ` - ${child.data.text.slice(0, 30)}` : ""}
|
|
423
|
-
{child.data?.heading ? ` - ${child.data.heading.slice(0, 30)}` : ""}
|
|
423
|
+
{typeof child.data?.text === 'string' ? ` - ${child.data.text.slice(0, 30)}` : ""}
|
|
424
|
+
{typeof child.data?.heading === 'string' ? ` - ${child.data.heading.slice(0, 30)}` : ""}
|
|
424
425
|
</div>
|
|
425
426
|
{blockSchema?.admin?.description && (
|
|
426
427
|
<div className="text-[10px] text-[var(--kyro-text-muted)] mt-0.5 truncate opacity-80">
|
|
@@ -431,7 +432,7 @@ const NestedChildBlocks: React.FC<NestedChildBlocksProps> = ({
|
|
|
431
432
|
|
|
432
433
|
{hasChildren && (
|
|
433
434
|
<span className="text-[10px] bg-[var(--kyro-surface-accent)] px-2 py-0.5 rounded text-[var(--kyro-text-muted)] font-medium">
|
|
434
|
-
{child.children
|
|
435
|
+
{child.children?.length} nested
|
|
435
436
|
</span>
|
|
436
437
|
)}
|
|
437
438
|
|
|
@@ -483,7 +484,7 @@ const NestedChildBlocks: React.FC<NestedChildBlocksProps> = ({
|
|
|
483
484
|
<div className="mt-1">
|
|
484
485
|
<NestedChildBlocks
|
|
485
486
|
parentId={child.id}
|
|
486
|
-
children={child.children}
|
|
487
|
+
children={child.children ?? []}
|
|
487
488
|
onUpdateChildren={(newGrandchildren) =>
|
|
488
489
|
handleUpdateChildChildren(child.id, newGrandchildren)
|
|
489
490
|
}
|
|
@@ -7,14 +7,19 @@ import { ChevronRight, X, Code2 } from "../ui/icons";
|
|
|
7
7
|
import { CodeField } from "../fields/CodeField";
|
|
8
8
|
import { useTranslation } from "react-i18next";
|
|
9
9
|
|
|
10
|
-
|
|
10
|
+
interface CodeBlockData {
|
|
11
|
+
language?: string;
|
|
12
|
+
code?: string;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export const CodeBlock: React.FC<{ block: { id: string; data?: Record<string, unknown> }; index: number }> = ({
|
|
11
16
|
block,
|
|
12
17
|
index,
|
|
13
18
|
}) => {
|
|
14
19
|
const { t } = useTranslation();
|
|
15
20
|
const blockData = useBlockById(block.id);
|
|
16
21
|
const { updateBlock, removeBlock, moveBlock } = useBlockActions();
|
|
17
|
-
const data = blockData?.data ?? block.data ?? {};
|
|
22
|
+
const data = (blockData?.data ?? block.data ?? {}) as CodeBlockData;
|
|
18
23
|
|
|
19
24
|
const handleChange = (field: string, value: unknown) => {
|
|
20
25
|
updateBlock(block.id, { data: { ...data, [field]: value } });
|
|
@@ -7,7 +7,11 @@ import { ChevronRight, X } from "../ui/icons";
|
|
|
7
7
|
import { UploadField } from "../fields/UploadField";
|
|
8
8
|
import { useTranslation } from "react-i18next";
|
|
9
9
|
|
|
10
|
-
|
|
10
|
+
interface FileBlockData {
|
|
11
|
+
file?: string | null;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export const FileBlock: React.FC<{ block: { id: string; data?: Record<string, unknown> }; index: number }> = ({
|
|
11
15
|
block,
|
|
12
16
|
index,
|
|
13
17
|
}) => {
|
|
@@ -15,7 +19,7 @@ export const FileBlock: React.FC<{ block: Record<string, unknown>; index: number
|
|
|
15
19
|
const blockData = useBlockById(block.id);
|
|
16
20
|
const { updateBlock, removeBlock, moveBlock } = useBlockActions();
|
|
17
21
|
|
|
18
|
-
const data = blockData?.data ?? block.data ?? {};
|
|
22
|
+
const data = (blockData?.data ?? block.data ?? {}) as FileBlockData;
|
|
19
23
|
|
|
20
24
|
const handleChange = (field: string, value: unknown) => {
|
|
21
25
|
updateBlock(block.id, { data: { ...data, [field]: value } });
|
|
@@ -4,7 +4,7 @@ import { FieldRenderer } from "../FieldRenderer";
|
|
|
4
4
|
import { useBlockById, useBlockActions } from "../fields/extensions/blocksStore";
|
|
5
5
|
|
|
6
6
|
interface GenericBlockProps {
|
|
7
|
-
block: Record<string, unknown>;
|
|
7
|
+
block: { id: string; data?: Record<string, unknown>; type?: string };
|
|
8
8
|
index: number;
|
|
9
9
|
blockSchema: Record<string, any>;
|
|
10
10
|
}
|
|
@@ -6,14 +6,18 @@ import {
|
|
|
6
6
|
import { HeadingField } from "../fields/HeadingField";
|
|
7
7
|
import { BlockWrapper } from "./BlockWrapper";
|
|
8
8
|
|
|
9
|
-
|
|
9
|
+
interface HeadingBlockData {
|
|
10
|
+
text?: string;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export const HeadingBlock: React.FC<{ block: { id: string; data?: Record<string, unknown> }; index: number }> = ({
|
|
10
14
|
block,
|
|
11
15
|
index,
|
|
12
16
|
}) => {
|
|
13
17
|
const blockData = useBlockById(block.id);
|
|
14
18
|
const { updateBlock } = useBlockActions();
|
|
15
19
|
|
|
16
|
-
const data = blockData?.data
|
|
20
|
+
const data = (blockData?.data ?? block.data ?? {}) as HeadingBlockData;
|
|
17
21
|
|
|
18
22
|
const handleChange = (field: string, value: unknown) => {
|
|
19
23
|
updateBlock(block.id, { data: { ...data, [field]: value } });
|
|
@@ -6,14 +6,19 @@ import {
|
|
|
6
6
|
import { HeadingSubheadingField } from "../fields/HeadingSubheadingField";
|
|
7
7
|
import { BlockWrapper } from "./BlockWrapper";
|
|
8
8
|
|
|
9
|
-
|
|
9
|
+
interface HeadingSubheadingBlockData {
|
|
10
|
+
title?: string;
|
|
11
|
+
subtitle?: string;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export const HeadingSubheadingBlock: React.FC<{ block: { id: string; data?: Record<string, unknown> }; index: number }> = ({
|
|
10
15
|
block,
|
|
11
16
|
index,
|
|
12
17
|
}) => {
|
|
13
18
|
const blockData = useBlockById(block.id);
|
|
14
19
|
const { updateBlock } = useBlockActions();
|
|
15
20
|
|
|
16
|
-
const data = blockData?.data
|
|
21
|
+
const data = (blockData?.data ?? block.data ?? {}) as HeadingSubheadingBlockData;
|
|
17
22
|
|
|
18
23
|
const handleChange = (field: string, value: unknown) => {
|
|
19
24
|
updateBlock(block.id, { data: { ...data, [field]: value } });
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import React from "react";
|
|
2
|
+
import type { BlockData } from "@kyro-cms/core/client";
|
|
2
3
|
import {
|
|
3
4
|
useBlockById,
|
|
4
5
|
useBlockActions,
|
|
@@ -9,7 +10,15 @@ import { UploadField } from "../fields/UploadField";
|
|
|
9
10
|
import { ChildBlocksTree } from "./ChildBlocksTree";
|
|
10
11
|
import { useTranslation } from "react-i18next";
|
|
11
12
|
|
|
12
|
-
|
|
13
|
+
interface HeroBlockData {
|
|
14
|
+
title?: string;
|
|
15
|
+
subtitle?: string;
|
|
16
|
+
ctaText?: string;
|
|
17
|
+
ctaUrl?: string;
|
|
18
|
+
bgImage?: string | null;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export const HeroBlock: React.FC<{ block: { id: string; data?: Record<string, unknown>; children?: BlockData[] }; index: number }> = ({
|
|
13
22
|
block,
|
|
14
23
|
index,
|
|
15
24
|
}) => {
|
|
@@ -17,8 +26,8 @@ export const HeroBlock: React.FC<{ block: Record<string, unknown>; index: number
|
|
|
17
26
|
const blockData = useBlockById(block.id);
|
|
18
27
|
const { updateBlock, removeBlock, moveBlock } = useBlockActions();
|
|
19
28
|
|
|
20
|
-
const data = blockData?.data ?? block.data ?? {};
|
|
21
|
-
const children = blockData?.children ?? block.children ?? [];
|
|
29
|
+
const data = (blockData?.data ?? block.data ?? {}) as HeroBlockData;
|
|
30
|
+
const children = (blockData?.children ?? block.children ?? []) as BlockData[];
|
|
22
31
|
|
|
23
32
|
const handleChange = (field: string, value: unknown) => {
|
|
24
33
|
updateBlock(block.id, { data: { ...data, [field]: value } });
|
|
@@ -7,14 +7,20 @@ import { ChevronRight, X } from "../ui/icons";
|
|
|
7
7
|
import { UploadField } from "../fields/UploadField";
|
|
8
8
|
import { useTranslation } from "react-i18next";
|
|
9
9
|
|
|
10
|
-
|
|
10
|
+
interface ImageBlockData {
|
|
11
|
+
src?: string | null;
|
|
12
|
+
alt?: string;
|
|
13
|
+
caption?: string;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export const ImageBlock: React.FC<{ block: { id: string; data?: Record<string, unknown> }; index: number }> = ({
|
|
11
17
|
block,
|
|
12
18
|
index,
|
|
13
19
|
}) => {
|
|
14
20
|
const { t } = useTranslation();
|
|
15
21
|
const blockData = useBlockById(block.id);
|
|
16
22
|
const { updateBlock, removeBlock, moveBlock } = useBlockActions();
|
|
17
|
-
const data = blockData?.data
|
|
23
|
+
const data = (blockData?.data ?? block.data ?? {}) as ImageBlockData;
|
|
18
24
|
|
|
19
25
|
const handleChange = (field: string, value: unknown) => {
|
|
20
26
|
updateBlock(block.id, { data: { ...data, [field]: value } });
|
|
@@ -7,7 +7,11 @@ import { ChevronRight, X } from "../ui/icons";
|
|
|
7
7
|
import { ListField } from "../fields/ListField";
|
|
8
8
|
import { useTranslation } from "react-i18next";
|
|
9
9
|
|
|
10
|
-
|
|
10
|
+
interface ListBlockData {
|
|
11
|
+
items?: string[];
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export const ListBlock: React.FC<{ block: { id: string; data?: Record<string, unknown> }; index: number }> = ({
|
|
11
15
|
block,
|
|
12
16
|
index,
|
|
13
17
|
}) => {
|
|
@@ -15,7 +19,7 @@ export const ListBlock: React.FC<{ block: Record<string, unknown>; index: number
|
|
|
15
19
|
const blockData = useBlockById(block.id);
|
|
16
20
|
const { updateBlock, removeBlock, moveBlock } = useBlockActions();
|
|
17
21
|
|
|
18
|
-
const data = blockData?.data
|
|
22
|
+
const data = (blockData?.data ?? block.data ?? {}) as ListBlockData;
|
|
19
23
|
const listItems = Array.isArray(data.items) ? data.items : [];
|
|
20
24
|
|
|
21
25
|
const handleChange = (items: string[]) => {
|
|
@@ -6,7 +6,7 @@ import {
|
|
|
6
6
|
import { BlockWrapper } from "./BlockWrapper";
|
|
7
7
|
import { useTranslation } from "react-i18next";
|
|
8
8
|
|
|
9
|
-
export const ParagraphBlock: React.FC<{ block: Record<string, unknown
|
|
9
|
+
export const ParagraphBlock: React.FC<{ block: { id: string; data?: Record<string, unknown> }; index: number }> = ({
|
|
10
10
|
block,
|
|
11
11
|
index,
|
|
12
12
|
}) => {
|
|
@@ -14,7 +14,7 @@ export const ParagraphBlock: React.FC<{ block: Record<string, unknown>; index: n
|
|
|
14
14
|
const blockData = useBlockById(block.id);
|
|
15
15
|
const { updateBlock } = useBlockActions();
|
|
16
16
|
|
|
17
|
-
const data = blockData?.data || block.data || {};
|
|
17
|
+
const data = (blockData?.data || block.data || {}) as { text?: string };
|
|
18
18
|
|
|
19
19
|
const handleChange = (field: string, value: unknown) => {
|
|
20
20
|
updateBlock(block.id, { data: { ...data, [field]: value } });
|
|
@@ -7,7 +7,15 @@ import { ChevronRight, X } from "../ui/icons";
|
|
|
7
7
|
import { RelationshipBlockField } from "../fields/RelationshipBlockField";
|
|
8
8
|
import { useTranslation } from "react-i18next";
|
|
9
9
|
|
|
10
|
-
|
|
10
|
+
interface RelationshipBlockData {
|
|
11
|
+
relationTo?: string;
|
|
12
|
+
hasMany?: boolean;
|
|
13
|
+
selectedIds?: string[];
|
|
14
|
+
selectedId?: string;
|
|
15
|
+
labelField?: string;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export const RelationshipBlock: React.FC<{ block: { id: string; data?: Record<string, unknown> }; index: number }> = ({
|
|
11
19
|
block,
|
|
12
20
|
index,
|
|
13
21
|
}) => {
|
|
@@ -15,7 +23,7 @@ export const RelationshipBlock: React.FC<{ block: Record<string, unknown>; index
|
|
|
15
23
|
const blockData = useBlockById(block.id);
|
|
16
24
|
const { updateBlock, removeBlock, moveBlock } = useBlockActions();
|
|
17
25
|
|
|
18
|
-
const data = blockData?.data ?? block.data ?? {};
|
|
26
|
+
const data = (blockData?.data ?? block.data ?? {}) as RelationshipBlockData;
|
|
19
27
|
|
|
20
28
|
const handleChange = (field: string, value: unknown) => {
|
|
21
29
|
updateBlock(block.id, { data: { ...data, [field]: value } });
|
|
@@ -7,7 +7,12 @@ import { ChevronRight, X } from "../ui/icons";
|
|
|
7
7
|
import { VideoField } from "../fields/VideoField";
|
|
8
8
|
import { useTranslation } from "react-i18next";
|
|
9
9
|
|
|
10
|
-
|
|
10
|
+
interface VideoBlockData {
|
|
11
|
+
src?: string;
|
|
12
|
+
title?: string;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export const VideoBlock: React.FC<{ block: { id: string; data?: Record<string, unknown> }; index: number }> = ({
|
|
11
16
|
block,
|
|
12
17
|
index,
|
|
13
18
|
}) => {
|
|
@@ -15,7 +20,7 @@ export const VideoBlock: React.FC<{ block: Record<string, unknown>; index: numbe
|
|
|
15
20
|
const blockData = useBlockById(block.id);
|
|
16
21
|
const { updateBlock, removeBlock, moveBlock } = useBlockActions();
|
|
17
22
|
|
|
18
|
-
const data = blockData?.data ?? block.data ?? {};
|
|
23
|
+
const data = (blockData?.data ?? block.data ?? {}) as VideoBlockData;
|
|
19
24
|
|
|
20
25
|
const handleChange = (field: string, value: unknown) => {
|
|
21
26
|
updateBlock(block.id, { data: { ...data, [field]: value } });
|
|
@@ -2,7 +2,7 @@ import React, { useState, useCallback } from "react";
|
|
|
2
2
|
import { ChevronDown, ChevronUp, Plus, X } from "../ui/icons";
|
|
3
3
|
import { useTranslation } from "react-i18next";
|
|
4
4
|
|
|
5
|
-
interface AccordionItem {
|
|
5
|
+
export interface AccordionItem {
|
|
6
6
|
title: string;
|
|
7
7
|
content: string;
|
|
8
8
|
}
|
|
@@ -27,7 +27,7 @@ interface ArrayLayoutProps {
|
|
|
27
27
|
renderField: (
|
|
28
28
|
field: Field,
|
|
29
29
|
parentData: Record<string, unknown>,
|
|
30
|
-
onChange: (value: unknown) => void,
|
|
30
|
+
onChange: (value: Record<string, unknown>) => void,
|
|
31
31
|
) => React.ReactNode;
|
|
32
32
|
disabled?: boolean;
|
|
33
33
|
}
|
|
@@ -46,12 +46,16 @@ interface SortableArrayItemProps {
|
|
|
46
46
|
setOpenIndex: (index: number | null) => void;
|
|
47
47
|
item: Record<string, unknown>;
|
|
48
48
|
field: Field;
|
|
49
|
-
renderField:
|
|
50
|
-
|
|
49
|
+
renderField: (
|
|
50
|
+
field: Field,
|
|
51
|
+
parentData: Record<string, unknown>,
|
|
52
|
+
onChange: (value: Record<string, unknown>) => void,
|
|
53
|
+
) => React.ReactNode;
|
|
54
|
+
onChangeItem: (newItem: Record<string, unknown>) => void;
|
|
51
55
|
onRemove: () => void;
|
|
52
56
|
disabled?: boolean;
|
|
53
57
|
compact: boolean;
|
|
54
|
-
getItemLabel: (item:
|
|
58
|
+
getItemLabel: (item: Record<string, unknown>) => string;
|
|
55
59
|
}
|
|
56
60
|
|
|
57
61
|
function SortableArrayItem({
|
|
@@ -68,31 +72,28 @@ function SortableArrayItem({
|
|
|
68
72
|
compact,
|
|
69
73
|
getItemLabel,
|
|
70
74
|
}: SortableArrayItemProps) {
|
|
71
|
-
|
|
75
|
+
const { t } = useTranslation();
|
|
72
76
|
const {
|
|
73
77
|
attributes,
|
|
74
78
|
listeners,
|
|
75
79
|
setNodeRef,
|
|
76
80
|
transform,
|
|
77
81
|
transition,
|
|
78
|
-
isDragging,
|
|
79
82
|
} = useSortable({ id });
|
|
80
83
|
|
|
81
84
|
const style = {
|
|
82
85
|
transform: CSS.Transform.toString(transform),
|
|
83
86
|
transition,
|
|
84
|
-
zIndex: isDragging ? 10 : 1,
|
|
85
|
-
opacity: isDragging ? 0.8 : 1,
|
|
86
87
|
};
|
|
87
88
|
|
|
89
|
+
const fields = (field as Field & { fields?: Field[] }).fields || [];
|
|
90
|
+
|
|
88
91
|
if (compact) {
|
|
89
92
|
return (
|
|
90
93
|
<div
|
|
91
94
|
ref={setNodeRef}
|
|
92
95
|
style={style}
|
|
93
|
-
className=
|
|
94
|
-
isDragging ? "bg-[var(--kyro-surface-accent)]/50" : ""
|
|
95
|
-
}`}
|
|
96
|
+
className="flex items-start gap-2 px-3 py-1.5 border-b border-[var(--kyro-border)] last:border-b-0"
|
|
96
97
|
>
|
|
97
98
|
<div
|
|
98
99
|
{...attributes}
|
|
@@ -104,8 +105,8 @@ function SortableArrayItem({
|
|
|
104
105
|
<span className="text-[10px] font-bold text-[var(--kyro-text-muted)] pt-2.5 min-w-[18px] text-center">
|
|
105
106
|
{index + 1}
|
|
106
107
|
</span>
|
|
107
|
-
<div className={`flex-1 min-w-0 ${
|
|
108
|
-
{
|
|
108
|
+
<div className={`flex-1 min-w-0 ${fields.length >= 3 ? "flex flex-col gap-1.5" : "flex items-start gap-1.5"}`}>
|
|
109
|
+
{fields.map((f: Field) => (
|
|
109
110
|
<div key={f.name} className="flex-1 min-w-0">
|
|
110
111
|
{renderField(f, item, onChangeItem)}
|
|
111
112
|
</div>
|
|
@@ -130,50 +131,44 @@ function SortableArrayItem({
|
|
|
130
131
|
<div
|
|
131
132
|
ref={setNodeRef}
|
|
132
133
|
style={style}
|
|
133
|
-
className={`border border-[var(--kyro-border)] rounded-
|
|
134
|
-
isDragging ? "border-[var(--kyro-primary)] shadow-md" : ""
|
|
135
|
-
}`}
|
|
134
|
+
className={`border border-[var(--kyro-border)] rounded-[var(--kyro-radius-md)] bg-[var(--kyro-surface-accent)]/10 overflow-hidden`}
|
|
136
135
|
>
|
|
137
|
-
<div className="
|
|
138
|
-
<div
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
setOpenIndex(isOpen ? null : index);
|
|
154
|
-
}
|
|
155
|
-
}}
|
|
156
|
-
className="text-xs font-bold tracking-widest text-[var(--kyro-text-muted)] truncate cursor-pointer flex-1 py-1 text-left"
|
|
157
|
-
>
|
|
158
|
-
{getItemLabel(item) || `Item ${index + 1}`}
|
|
136
|
+
<div className="flex items-center gap-2 px-4 py-3 bg-[var(--kyro-surface-accent)]/20 border-b border-[var(--kyro-border)]">
|
|
137
|
+
<div
|
|
138
|
+
{...attributes}
|
|
139
|
+
{...listeners}
|
|
140
|
+
className="p-1 cursor-grab active:cursor-grabbing text-[var(--kyro-text-muted)] hover:bg-[var(--kyro-surface-accent)] rounded flex-shrink-0"
|
|
141
|
+
>
|
|
142
|
+
<GripVertical className="w-3.5 h-3.5" />
|
|
143
|
+
</div>
|
|
144
|
+
|
|
145
|
+
<span className="text-xs font-bold text-[var(--kyro-text-muted)] min-w-[18px]">
|
|
146
|
+
{index + 1}
|
|
147
|
+
</span>
|
|
148
|
+
|
|
149
|
+
<div className="flex-1 min-w-0">
|
|
150
|
+
<span className="text-xs font-medium text-[var(--kyro-text-primary)] truncate block">
|
|
151
|
+
{getItemLabel(item) || `${field.label || field.name} Item`}
|
|
159
152
|
</span>
|
|
160
153
|
</div>
|
|
161
|
-
|
|
154
|
+
|
|
155
|
+
<div className="flex items-center gap-1 flex-shrink-0">
|
|
162
156
|
<button
|
|
163
157
|
type="button"
|
|
164
158
|
disabled={disabled}
|
|
165
|
-
onClick={
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
}}
|
|
169
|
-
className="text-[11px] font-bold text-[var(--kyro-error)] opacity-0 group-hover:opacity-100 transition-opacity disabled:opacity-30 hover:bg-[var(--kyro-danger-bg)] rounded px-1.5 py-0.5"
|
|
159
|
+
onClick={onRemove}
|
|
160
|
+
className="text-[var(--kyro-text-muted)] hover:text-[var(--kyro-error)] transition-colors disabled:opacity-30 p-1 rounded hover:bg-[var(--kyro-surface-accent)]"
|
|
161
|
+
title={t("tooltips.remove", { defaultValue: "Remove" })}
|
|
170
162
|
>
|
|
171
|
-
|
|
163
|
+
<svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2" strokeLinecap="round" strokeLinejoin="round">
|
|
164
|
+
<line x1="18" y1="6" x2="6" y2="18" /><line x1="6" y1="6" x2="18" y2="18" />
|
|
165
|
+
</svg>
|
|
172
166
|
</button>
|
|
167
|
+
|
|
173
168
|
<button
|
|
174
169
|
type="button"
|
|
175
170
|
onClick={() => setOpenIndex(isOpen ? null : index)}
|
|
176
|
-
className="p-1 hover:bg-[var(--kyro-surface-accent)]
|
|
171
|
+
className="p-1 rounded hover:bg-[var(--kyro-surface-accent)] transition-colors"
|
|
177
172
|
>
|
|
178
173
|
{isOpen ? (
|
|
179
174
|
<ChevronUp className="w-4 h-4 text-[var(--kyro-text-muted)]" />
|
|
@@ -185,7 +180,7 @@ function SortableArrayItem({
|
|
|
185
180
|
</div>
|
|
186
181
|
{isOpen && (
|
|
187
182
|
<div className="p-4 bg-[var(--kyro-surface)] space-y-4">
|
|
188
|
-
{
|
|
183
|
+
{fields.map((f: Field) =>
|
|
189
184
|
renderField(f, item, onChangeItem),
|
|
190
185
|
)}
|
|
191
186
|
</div>
|
|
@@ -201,7 +196,7 @@ export function ArrayLayout({
|
|
|
201
196
|
renderField,
|
|
202
197
|
disabled,
|
|
203
198
|
}: ArrayLayoutProps) {
|
|
204
|
-
const items = Array.isArray(value) ? value : [];
|
|
199
|
+
const items = (Array.isArray(value) ? value : []) as Record<string, unknown>[];
|
|
205
200
|
const fields = (field as Field & { fields?: { name?: string; type?: string; relationTo?: string; label?: string }[] }).fields || [];
|
|
206
201
|
const firstField = fields[0];
|
|
207
202
|
const labelField = firstField?.name || "user";
|
|
@@ -212,14 +207,14 @@ export function ArrayLayout({
|
|
|
212
207
|
React.useEffect(() => {
|
|
213
208
|
let needsUpdate = false;
|
|
214
209
|
const updated = items
|
|
215
|
-
.filter((item
|
|
210
|
+
.filter((item) => {
|
|
216
211
|
if (typeof item !== "object" || item === null) {
|
|
217
212
|
needsUpdate = true;
|
|
218
213
|
return false;
|
|
219
214
|
}
|
|
220
215
|
return true;
|
|
221
216
|
})
|
|
222
|
-
.map((item
|
|
217
|
+
.map((item) => {
|
|
223
218
|
if (!item.id && !item._key) {
|
|
224
219
|
needsUpdate = true;
|
|
225
220
|
return {
|
|
@@ -239,13 +234,14 @@ export function ArrayLayout({
|
|
|
239
234
|
const val = item[key];
|
|
240
235
|
if (val && typeof val === "string") return val;
|
|
241
236
|
}
|
|
242
|
-
|
|
237
|
+
const fieldsTyped = fields as Field[];
|
|
238
|
+
for (const f of fieldsTyped) {
|
|
243
239
|
if (f.type === "text" || f.type === "textarea") {
|
|
244
240
|
const val = item[f.name!];
|
|
245
241
|
if (val && typeof val === "string") return val;
|
|
246
242
|
}
|
|
247
|
-
if (f.type === "group" && (f as
|
|
248
|
-
for (const inner of (f as
|
|
243
|
+
if (f.type === "group" && (f as Field & { fields?: Field[] }).fields) {
|
|
244
|
+
for (const inner of (f as Field & { fields?: Field[] }).fields || []) {
|
|
249
245
|
if (inner.type === "text" || inner.type === "textarea") {
|
|
250
246
|
const group = item[f.name!] as Record<string, unknown> | undefined;
|
|
251
247
|
const val = group?.[inner.name!];
|
|
@@ -272,8 +268,8 @@ export function ArrayLayout({
|
|
|
272
268
|
const { active, over } = event;
|
|
273
269
|
if (!over || active.id === over.id) return;
|
|
274
270
|
|
|
275
|
-
const oldIndex = items.findIndex((item
|
|
276
|
-
const newIndex = items.findIndex((item
|
|
271
|
+
const oldIndex = items.findIndex((item) => (item.id || item._key) === active.id);
|
|
272
|
+
const newIndex = items.findIndex((item) => (item.id || item._key) === over.id);
|
|
277
273
|
|
|
278
274
|
if (oldIndex !== -1 && newIndex !== -1) {
|
|
279
275
|
const newItems = [...items];
|
|
@@ -284,7 +280,7 @@ export function ArrayLayout({
|
|
|
284
280
|
};
|
|
285
281
|
|
|
286
282
|
const itemIds = React.useMemo(() => {
|
|
287
|
-
return items.map((item
|
|
283
|
+
return items.map((item) => (item?.id || item?._key || "") as string);
|
|
288
284
|
}, [items]);
|
|
289
285
|
|
|
290
286
|
if (isRelationship) {
|
|
@@ -296,11 +292,12 @@ export function ArrayLayout({
|
|
|
296
292
|
name: labelField,
|
|
297
293
|
relationTo: (field as Field & { fields?: { relationTo?: string }[] }).fields?.[0]?.relationTo || "",
|
|
298
294
|
hasMany: true,
|
|
299
|
-
|
|
295
|
+
// Omit the inner field's label to avoid duplicate labels in the UI
|
|
296
|
+
label: undefined,
|
|
300
297
|
}}
|
|
301
298
|
value={(items as Record<string, unknown>[]).map((i) => i[labelField]).filter(Boolean)}
|
|
302
299
|
onChange={(newValue) => {
|
|
303
|
-
const newItems = (newValue || []).map((id: string) => ({
|
|
300
|
+
const newItems = ((newValue as string[]) || []).map((id: string) => ({
|
|
304
301
|
[labelField]: id,
|
|
305
302
|
id: Math.random().toString(36).substr(2, 9),
|
|
306
303
|
}));
|
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
import React from "react";
|
|
2
2
|
import { ChildBlocksTree } from "../blocks/ChildBlocksTree";
|
|
3
|
+
import type { BlockData } from "@kyro-cms/core/client";
|
|
3
4
|
|
|
4
5
|
interface ChildrenFieldProps {
|
|
5
6
|
blockId: string;
|
|
6
|
-
children:
|
|
7
|
-
onUpdateChildren: (newChildren:
|
|
7
|
+
children: BlockData[];
|
|
8
|
+
onUpdateChildren: (newChildren: BlockData[]) => void;
|
|
8
9
|
label?: string;
|
|
9
10
|
compact?: boolean;
|
|
10
11
|
}
|