Skip to content

Commit 5093c66

Browse files
authored
Merge pull request #5 from olliethedev/feat/remove_text_type
feat: remove default text type
2 parents 5a06b8d + 8bd8c79 commit 5093c66

39 files changed

+3454
-2120
lines changed

README.md

Lines changed: 47 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,6 @@ Add dev dependencies, since there currently seems to be an issue with shadcn/ui
3535
npm install -D @types/lodash.template @tailwindcss/typography @types/react-syntax-highlighter react-docgen-typescript tailwindcss-animate ts-morph ts-to-zod
3636
```
3737

38-
39-
4038
And that's it! You have a UI Builder that you can use to build your UI.
4139

4240
## Usage
@@ -82,11 +80,10 @@ const initialLayers: PageLayer[] = [
8280
children: [
8381
{
8482
id: "UzZY6Dp",
85-
type: "_text_",
86-
name: "Text",
87-
text: "Github",
88-
textType: "text",
83+
type: "span",
84+
name: "span",
8985
props: {},
86+
children: "Hello World",
9087
},
9188
{
9289
id: "hn3PF6A",
@@ -109,7 +106,7 @@ const initialLayers: PageLayer[] = [
109106

110107
const App = () => {
111108
const handleLayersChange = (updatedLayers: PageLayer[]) => {
112-
// Here you can save the updated layers to the database
109+
// Here you can send the updated layers to the backend
113110
console.log(updatedLayers);
114111
};
115112

@@ -218,7 +215,7 @@ Note: This project is an work in progress and the API will change.
218215

219216
### Layers
220217

221-
- **Layers** are the fundamental units representing components, text, or pages within the UI structure.
218+
- **Layers** are the fundamental units representing components or pages within the UI structure.
222219
- They form a hierarchical tree, allowing for complex and nested UI layouts.
223220
- Each layer possesses properties and can contain child layers, enabling modular and scalable UI designs.
224221

@@ -250,25 +247,15 @@ The `layer-store.ts` module defines the essential types used to manage UI layers
250247
```ts
251248

252249
export type Layer =
253-
| {
254-
id: string;
255-
name?: string;
256-
type: keyof typeof componentRegistry;
257-
props: Record<string, any>;
258-
children: Layer[];
259-
}
260-
| TextLayer
250+
| ComponentLayer
261251
| PageLayer;
262252

263-
export type ComponentLayer = Exclude<Layer, TextLayer>;
264-
265-
export type TextLayer = {
253+
export type ComponentLayer = {
266254
id: string;
267255
name?: string;
268-
type: '_text_';
256+
type: keyof typeof componentRegistry;
269257
props: Record<string, any>;
270-
text: string;
271-
textType: 'text' | 'markdown';
258+
children: Layer[] | string;
272259
};
273260

274261
export type PageLayer = {
@@ -277,15 +264,14 @@ export type PageLayer = {
277264
type: '_page_';
278265
props: Record<string, any>;
279266
children: Layer[];
280-
};
267+
}
281268

282269
interface LayerStore {
283270
pages: PageLayer[];
284271
selectedLayerId: string | null;
285272
selectedPageId: string;
286273
initialize: (pages: PageLayer[]) => void;
287274
addComponentLayer: (layerType: keyof typeof componentRegistry, parentId: string, parentPosition?: number) => void;
288-
addTextLayer: (text: string, textType: 'text' | 'markdown', parentId: string, parentPosition?: number) => void;
289275
addPageLayer: (pageId: string) => void;
290276
duplicateLayer: (layerId: string, parentId?: string) => void;
291277
removeLayer: (layerId: string) => void;
@@ -298,9 +284,8 @@ interface LayerStore {
298284

299285
```
300286

301-
- `Layer`: A union type representing any possible layer, encompassing component, text, or page layers.
302-
- `ComponentLayer`: Represents layers that are components, excluding text layers.
303-
- `TextLayer`: Represents layers containing text content. Text layers dont have children.
287+
- `Layer`: A union type representing any possible layer, encompassing component or page layers.
288+
- `ComponentLayer`: Represents layers that are components.
304289
- `PageLayer`: Represents layers that serve as pages containing other layers.
305290
- `LayerStore`: Defines the structure of the state, including pages, selected layer/page IDs, and various actions to manipulate layers.
306291

@@ -314,7 +299,7 @@ export interface RegistryEntry<T extends ReactComponentType<any>> {
314299
component?: T;
315300
schema: ZodObject<any>;
316301
from?: string;
317-
defaultChildren?: (ComponentLayer | TextLayer)[];
302+
defaultChildren?: (ComponentLayer)[];
318303
fieldOverrides?: Record<string, FieldConfigFunction>;
319304
}
320305

@@ -323,15 +308,15 @@ export type ComponentRegistry = Record<
323308
RegistryEntry<ReactComponentType<any>>
324309
>;
325310

326-
export type FieldConfigFunction = (layer: ComponentLayer | TextLayer) => FieldConfigItem;
311+
export type FieldConfigFunction = (layer: ComponentLayer) => FieldConfigItem;
327312

328313
export const componentRegistry: ComponentRegistry = {
329314
// ...YourOtherProjectComponentDefinitions
330315
...complexComponentDefinitions,
331316
...primitiveComponentDefinitions,
332317
} as const;
333318

334-
export const generateFieldOverrides = (layer: ComponentLayer | TextLayer): Record<string, FieldConfigItem> => {...}
319+
export const generateFieldOverrides = (layer: ComponentLayer): Record<string, FieldConfigItem> => {...}
335320

336321
```
337322

@@ -355,37 +340,50 @@ export const componentRegistry: ComponentRegistry = {
355340
Button: {
356341
component: Button,
357342
schema: z.object({
358-
className: z.string().optional(),
359-
asChild: z.boolean().optional(),
360-
children: z.any().optional(),
361-
variant: z.enum(["default", "destructive", "outline", "secondary", "ghost", "link"]).default("default"),
362-
size: z.enum(["default", "sm", "lg", "icon"]).default("default"),
343+
className: z.string().optional(),
344+
children: z.any().optional(),
345+
asChild: z.boolean().optional(),
346+
variant: z
347+
.enum([
348+
"default",
349+
"destructive",
350+
"outline",
351+
"secondary",
352+
"ghost",
353+
"link",
354+
])
355+
.default("default"),
356+
size: z.enum(["default", "sm", "lg", "icon"]).default("default"),
363357
}),
364358
from: "@/components/ui/button",
365359
defaultChildren: [
366-
{
367-
id: "button-text",
368-
type: "_text_",
369-
name: "Text",
370-
text: "Button",
371-
textType: "text",
372-
props: {},
373-
},
360+
{
361+
id: "button-text",
362+
type: "span",
363+
name: "span",
364+
props: {},
365+
children: "Button",
366+
} satisfies ComponentLayer,
374367
],
375368
fieldOverrides: {
376-
className: (layer) => classNameFieldOverrides(layer),
377-
children: (layer) => childrenFieldOverrides(layer),
378-
},
379-
},
369+
className:(layer)=> classNameFieldOverrides(layer),
370+
children: (layer)=> childrenFieldOverrides(layer)
371+
}
372+
}
380373
// ... Other component definitions
381374
};
382375
```
383376

384377
### Button Component:
385378
- `Schema`: Defines props like className, variant, and size with default values.
386-
- `Default Children`: A text layer with default text "Button".
379+
- `Default Children`: A span layer with default text "Button".
387380
- `Field Overrides`: Customizes form fields for className and children properties.
388381

382+
## Changelog
383+
384+
### v0.0.2
385+
- Removed _text_ layer type in favor of using span and Markdown components. You should migrate any layers stored in the database to use the new components. You can use the [migrateV1ToV2](lib/ui-builder/store/layer-utils.ts) function in layer-utils.ts to help with the migration.
386+
389387
## Development
390388

391389
Build component registry after updating lib or ui:
@@ -415,8 +413,8 @@ npm run test
415413
## Roadmap
416414

417415
- [ ] Increase test coverage
416+
- [ ] Refactor page layers to be more consistent with component layers
418417
- [ ] Improve performance
419-
- [ ] Rework text layers to be more consistent with component layers
420418
- [ ] Add form component definitions since we already depend on most shadcn/ui form components
421419
- [ ] Add option to add children component layers by reference to existing layers (this would be like figma component instances)
422420
- [ ] Add event handlers to component layers (onClick, onSubmit, etc)

0 commit comments

Comments
 (0)