@kyro-cms/studio 0.0.0-stage → 0.2.0
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/README.md +159 -2
- package/components/KyroStudioPage.astro +7 -0
- package/package.json +32 -3
- package/src/blocks.tsx +709 -0
- package/src/bridge.ts +55 -0
- package/src/fonts.ts +49 -0
- package/src/forms.tsx +194 -0
- package/src/image-framing.ts +33 -0
- package/src/index.ts +18 -0
- package/src/layout-styles.ts +93 -0
- package/src/picked-icon.tsx +26 -0
- package/src/primitives.tsx +144 -0
- package/src/react.tsx +306 -0
- package/src/references.ts +71 -0
- package/src/styles.ts +8 -0
- package/src/types.ts +36 -0
package/README.md
CHANGED
|
@@ -1,3 +1,160 @@
|
|
|
1
|
-
#
|
|
1
|
+
# Kyro Studio: visual composition, headless content
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Studio edits the existing page document's blocks. The Admin editor remains available for structured content. There is no separate Studio database, HTML content store, or publishing pipeline.
|
|
4
|
+
|
|
5
|
+
## Enable a page collection
|
|
6
|
+
|
|
7
|
+
```ts
|
|
8
|
+
const pages = {
|
|
9
|
+
slug: "pages",
|
|
10
|
+
admin: { studio: { field: "content" } },
|
|
11
|
+
fields: [{ name: "content", type: "blocks", blocks: [heroBlock] }],
|
|
12
|
+
versions: { drafts: true },
|
|
13
|
+
};
|
|
14
|
+
```
|
|
15
|
+
|
|
16
|
+
Studio requires `versions: { drafts: true }` so saving work cannot silently publish it. The built-in Pages template opts in. Other collections stay in the structured editor unless explicitly enabled. `studio.field` supports nested paths through named tabs and groups. Authentication and the collection's read/create/update permissions still apply.
|
|
17
|
+
|
|
18
|
+
## Render on a React frontend
|
|
19
|
+
|
|
20
|
+
```tsx
|
|
21
|
+
import { StudioPage } from "@kyro-cms/studio";
|
|
22
|
+
|
|
23
|
+
export function Page({ page }) {
|
|
24
|
+
return <StudioPage blocks={page.content || []} />;
|
|
25
|
+
}
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
Fetch `page` using the existing Kyro SDK/API. The shared Hero renderer implements the existing `hero` schema (`isMultiScreen`, `singleSlide`, `multiSlides`). No editor metadata is emitted unless `editing` is enabled. Hero carousel controls are available in Interact mode and in the hydrated frontend renderer. Extra semantic elements render alongside their owning block and remain editable in the inspector.
|
|
29
|
+
|
|
30
|
+
In an Astro website with `@astrojs/react` installed, the same renderer can be server rendered:
|
|
31
|
+
|
|
32
|
+
```astro
|
|
33
|
+
---
|
|
34
|
+
import { StudioPage } from "@kyro-cms/studio";
|
|
35
|
+
// Fetch a published page through your existing Kyro client.
|
|
36
|
+
const { page } = Astro.props;
|
|
37
|
+
---
|
|
38
|
+
<StudioPage blocks={page.content || []} />
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
## Use your own website components
|
|
42
|
+
|
|
43
|
+
Register the same component definition in the website and the admin's browser plugin entry. Keep this module browser-safe; never import server configuration, database adapters, or secrets.
|
|
44
|
+
|
|
45
|
+
```tsx
|
|
46
|
+
import { registerStudioComponent } from "@kyro-cms/studio";
|
|
47
|
+
import { WebsiteHero } from "./WebsiteHero";
|
|
48
|
+
|
|
49
|
+
registerStudioComponent({
|
|
50
|
+
type: "hero", // matches the collection's block slug
|
|
51
|
+
label: "Hero",
|
|
52
|
+
defaults: { isMultiScreen: false, singleSlide: { title: "Hello" } },
|
|
53
|
+
editableFields: ["singleSlide"],
|
|
54
|
+
Component: ({ block, editing }) => (
|
|
55
|
+
<WebsiteHero
|
|
56
|
+
data={block.singleSlide}
|
|
57
|
+
titleAttributes={editing ? { "data-kyro-field": "singleSlide.title" } : {}}
|
|
58
|
+
/>
|
|
59
|
+
),
|
|
60
|
+
});
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
Your component owns its website styles. Inline component styles or styles loaded inside that component work in the iframe. For CSS files, the integration must include those styles in the iframe too; the canvas does not inherit the admin or host document's styles. `data-kyro-field` is a path relative to a block, not a database identifier. Runtime registration updates the admin component library. Blocks absent from the page schema cannot be inserted.
|
|
64
|
+
|
|
65
|
+
For isolated rendering, `createStudioRegistry([...definitions])` and `<StudioPage registry={registry} ... />` avoid mutating the shared default registry. If you have other block types, register their renderers or supply `renderUnknown`; the built-in registry implements the complete library listed below.
|
|
66
|
+
|
|
67
|
+
## First version boundaries
|
|
68
|
+
|
|
69
|
+
- Independent canvas, section selection, schema-backed inspector, insertion, up/down ordering, removal, undo/redo, desktop/tablet/mobile canvas sizes.
|
|
70
|
+
- Ordinary structured blocks with stable IDs; existing draft/publish APIs and conflict handling.
|
|
71
|
+
- Shared React components, not automatic conversion of arbitrary HTML or Astro components.
|
|
72
|
+
- Structured nested layout editing and drag/drop are supported; arbitrary CSS design and a remote website bridge remain separate integrations.
|
|
73
|
+
- Canvas sizes represent layout widths, not a mobile browser emulator.
|
|
74
|
+
|
|
75
|
+
The shared renderer makes the registered library usable on a frontend today. Integrating a complete existing website requires registering its actual components and styles; a generic rendering of fields is not a substitute for that integration.
|
|
76
|
+
|
|
77
|
+
## Expanded library and unified workflow
|
|
78
|
+
|
|
79
|
+
The built-in library now covers all core semantic blocks, their inline elements, and basic layout/content additions (38 registered types). Use `studioPageBlocks` from the core templates export in your collection schema to allow the complete library; the registry never bypasses a collection's allowed block list.
|
|
80
|
+
|
|
81
|
+
```ts
|
|
82
|
+
import { studioPageBlocks } from "@kyro-cms/core/templates";
|
|
83
|
+
// In a server-side collection configuration:
|
|
84
|
+
const page = {
|
|
85
|
+
slug: "pages",
|
|
86
|
+
admin: { studio: { field: "content" } },
|
|
87
|
+
fields: [{ name: "content", type: "blocks", blocks: studioPageBlocks }],
|
|
88
|
+
versions: { drafts: true },
|
|
89
|
+
};
|
|
90
|
+
```
|
|
91
|
+
|
|
92
|
+
- Layout: Section, Container, Row, Column, Grid, Spacer, Divider.
|
|
93
|
+
- Content: Heading, Paragraph, Rich text, Button, List, Quote, Icon, Badge, Notice.
|
|
94
|
+
- Media: Image, Gallery, Video, Video showcase.
|
|
95
|
+
- Marketing: Hero, Cards, Feature split/grid, CTA, Testimonials, Stats, Logos, Pricing, Team, Process steps.
|
|
96
|
+
- Interactive: FAQ, Accordion, Tabs.
|
|
97
|
+
- Dynamic: Content feed and Form (require permitted resolved references and, for forms, a real submission adapter).
|
|
98
|
+
|
|
99
|
+
The Section → Container/Row/Grid → Column → content hierarchy is finite and serializable. Components have stable IDs across moves, duplicate operations generate fresh IDs, and the Layers tree supports nested selection and drag/drop into allowed containers. Up/down controls are also available. Search and grouped insertion respect the selected container. Property arrays expand the item selected on the canvas.
|
|
100
|
+
|
|
101
|
+
Design, Content, Settings, and History are views of ONE canonical document. Content exposes the structured fields, Settings excludes the composition and slug controls while retaining other page metadata, and History reuses the CMS version actions. Published rendering is independent of which editor last changed the document.
|
|
102
|
+
|
|
103
|
+
## Theme and frontend adapter
|
|
104
|
+
|
|
105
|
+
The renderer accepts `theme="system" | "light" | "dark"` and uses matching semantic surface, text, accent, and border tokens. Studio follows the workspace preference and offers the compact System/Light/Dark control. Theme preference is not written into the composition.
|
|
106
|
+
|
|
107
|
+
```astro
|
|
108
|
+
---
|
|
109
|
+
import KyroStudioPage from "@kyro-cms/studio/components/KyroStudioPage.astro";
|
|
110
|
+
import { resolveStudioReferences } from "@kyro-cms/studio";
|
|
111
|
+
// `page` must be the published version fetched by your existing frontend route.
|
|
112
|
+
const { page, client } = Astro.props;
|
|
113
|
+
const references = await resolveStudioReferences(page.content || [], async (collection, id) => {
|
|
114
|
+
// Adapt this callback to your existing SDK read, preserving its auth/access rules.
|
|
115
|
+
const response = await fetch(new URL(`/api/${collection}/${encodeURIComponent(id)}?draft=false`, Astro.url.origin));
|
|
116
|
+
if (!response.ok) return undefined;
|
|
117
|
+
return (await response.json()).data;
|
|
118
|
+
});
|
|
119
|
+
---
|
|
120
|
+
<KyroStudioPage blocks={page.content || []} references={references} theme="system" />
|
|
121
|
+
```
|
|
122
|
+
|
|
123
|
+
The Astro adapter requires the site's React integration and hydrates the shared components for carousel and tab interactions. A custom form integration belongs in a frontend React wrapper that imports/registers its actual form component, not a serialized function prop.
|
|
124
|
+
|
|
125
|
+
`collectStudioReferences`, `resolveStudioReferences`, and `getStudioIssues` support preflight and rendering. Unresolved references, missing component renderers, invalid nesting, and missing form adapters are explicit issues; the shared public renderer throws rather than silently omitting content. The Studio publish button blocks on these local preflight issues while still allowing draft saves. Server enforcement, connected deployment capabilities, preview sessions, forms, and delivery coordination are implemented in the core Studio routes. See the Studio guide on the documentation site for endpoint details.
|
|
126
|
+
|
|
127
|
+
The canvas has no outer border. Its Library and Inspector panels open independently, resize by dragging or arrow keys, and remember their sizes. Double-click a divider to reset its width. Smaller screens stack the editing panes instead of forcing desktop widths.
|
|
128
|
+
|
|
129
|
+
## Layout design controls
|
|
130
|
+
|
|
131
|
+
Section, Container, Row, Column, and Grid support content width, custom pixel dimensions, direction, alignment, distribution, preset and per-side spacing, individual row/column gaps, and overflow. Grid controls apply to Grid layouts.
|
|
132
|
+
|
|
133
|
+
Backgrounds support theme presets, custom colors, gradients, images, and muted looping videos. Media is chosen through upload fields. Image fit, media position, and overlay color/opacity are conditional on background type. Videos remain paused during editing. Text color, border style/width/color, radius, and opacity are available under Appearance.
|
|
134
|
+
|
|
135
|
+
Position controls include normal, absolute, sticky, and fixed positioning, offsets, and stacking order. Responsive overrides apply at tablet widths up to 1024px and mobile widths up to 600px. They cover padding, gap, direction, and grid columns.
|
|
136
|
+
|
|
137
|
+
HTML IDs and CSS classes attach to the layout wrapper. The CSS editor accepts declarations such as `border-radius: 20px; letter-spacing: 1px;` and custom properties. Declarations apply to that wrapper and override its visual controls. Selectors, braces, at-rules, and `!important` are excluded. Use classes in your frontend stylesheet for selector-based effects. The Icon element supports the admin's searchable Lucide and Heroicons picker.
|
|
138
|
+
|
|
139
|
+
### Studio mode and content-only delivery
|
|
140
|
+
|
|
141
|
+
Studio is opt-in: set `studio: { enabled: true }` in `defineKyroConfig`. Collection-level `admin.studio` identifies the composition field; it does not enable Studio globally.
|
|
142
|
+
|
|
143
|
+
| Global mode | Authoring | Default delivery |
|
|
144
|
+
| --- | --- | --- |
|
|
145
|
+
| Studio enabled | Content and layout blocks, with design controls | Full composition tree |
|
|
146
|
+
| Studio omitted or disabled | Content blocks; existing layouts/settings remain read-only | Content only |
|
|
147
|
+
|
|
148
|
+
This is a breaking delivery contract: disabling Studio changes API response shape. Restart after changing configuration and update consumers that expect layout wrappers. Merely disabling Studio never rewrites saved documents. Enabling it again exposes their preserved layout settings.
|
|
149
|
+
|
|
150
|
+
REST supports `?representation=content` (also with Studio enabled). GraphQL uses the same request URL parameter, for example `/api/graphql?representation=content`. tRPC find/findByID accept `representation: "content"`. `full` is rejected in headless mode. Content delivery unwraps Section/Container/Row/Column/Grid in order, drops Spacer/Divider, removes block design groups, and keeps content IDs, media placements and references. Relationship-populated content is projected too. The database adapter remains the internal canonical-data interface. Authenticated admin-session requests use a private canonical representation so editing content cannot inadvertently flatten saved layouts; this is not a public full-output option.
|
|
151
|
+
|
|
152
|
+
Saved draft-enabled documents have a **More actions → Convert / recover** action in the editor header. Review the wrapper count/type breakdown, then choose **Convert to content only**. The server saves the latest protected recovery snapshot first and creates an unpublished converted draft. Published data is unchanged until you publish. The recovery snapshot is available in the same dialog; restoring it creates a draft and never publishes it. Conversion/recovery requires read and update permission, a current preview revision, and an adapter supporting protected snapshots (Local, Drizzle, MongoDB). Stale previews fail with 409. Adapters without protected recovery cannot convert.
|
|
153
|
+
|
|
154
|
+
Recovery versions are excluded from ordinary draft selection, autosave reuse, and automatic history retention. Explicitly deleting a document/history still removes its snapshots. Conversion flattens content in document order, not visual CSS order; review multi-column compositions before publishing.
|
|
155
|
+
|
|
156
|
+
Only one recovery snapshot is offered per document. Each new conversion updates that protected slot to the latest pre-conversion state rather than accumulating recovery entries.
|
|
157
|
+
|
|
158
|
+
### Package build
|
|
159
|
+
|
|
160
|
+
Studio 0.2.0 ships React/TypeScript and Astro source for consumer bundlers. `pnpm --filter @kyro-cms/studio build` type-checks its source package before publication. Core/Admin 0.15.0 own the delivery-mode and protected conversion/recovery APIs.
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
---
|
|
2
|
+
import { StudioPage, type StudioBlock } from "../src/index";
|
|
3
|
+
/** Public frontend adapter. Fetch only the published page in the consuming route. */
|
|
4
|
+
interface Props { blocks: StudioBlock[]; references?: Map<string, Record<string, any>>; theme?: "system" | "light" | "dark" }
|
|
5
|
+
const { blocks, references = new Map(), theme = "system" } = Astro.props;
|
|
6
|
+
---
|
|
7
|
+
<StudioPage blocks={blocks} context={{ references }} theme={theme} client:load />
|
package/package.json
CHANGED
|
@@ -1,6 +1,35 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kyro-cms/studio",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
3
|
+
"version": "0.2.0",
|
|
4
|
+
"description": "Shared visual page components for Kyro Studio and React frontends",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "./src/index.ts",
|
|
7
|
+
"types": "./src/index.ts",
|
|
8
|
+
"exports": {
|
|
9
|
+
".": "./src/index.ts",
|
|
10
|
+
"./components/KyroStudioPage.astro": "./components/KyroStudioPage.astro"
|
|
11
|
+
},
|
|
12
|
+
"files": [
|
|
13
|
+
"src",
|
|
14
|
+
"README.md",
|
|
15
|
+
"components"
|
|
16
|
+
],
|
|
17
|
+
"peerDependencies": {
|
|
18
|
+
"react": "^19.0.0"
|
|
19
|
+
},
|
|
20
|
+
"license": "MIT",
|
|
21
|
+
"dependencies": {
|
|
22
|
+
"lucide-react": "^0.475.0",
|
|
23
|
+
"@heroicons/react": "^2.2.0",
|
|
24
|
+
"@kyro-cms/rich-text-react": "0.12.72"
|
|
25
|
+
},
|
|
26
|
+
"devDependencies": {
|
|
27
|
+
"@types/react": "^19.0.0",
|
|
28
|
+
"@types/react-dom": "^19.0.0",
|
|
29
|
+
"typescript": "^5.7.3"
|
|
30
|
+
},
|
|
31
|
+
"scripts": {
|
|
32
|
+
"build": "tsc --noEmit -p tsconfig.json",
|
|
33
|
+
"typecheck": "tsc --noEmit -p tsconfig.json"
|
|
34
|
+
}
|
|
6
35
|
}
|