@powerhousedao/academy 5.1.0-staging.0 → 5.1.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.
Files changed (76) hide show
  1. package/CHANGELOG.md +46 -1148
  2. package/blog/BeyondCommunication-ABlueprintForDevelopment.md +1 -2
  3. package/blog/TheChallengeOfChange.md +0 -1
  4. package/docs/academy/00-EthereumArgentinaHackathon.md +207 -0
  5. package/docs/academy/01-GetStarted/00-ExploreDemoPackage.mdx +27 -24
  6. package/docs/academy/01-GetStarted/01-CreateNewPowerhouseProject.md +10 -155
  7. package/docs/academy/01-GetStarted/02-DefineToDoListDocumentModel.md +35 -122
  8. package/docs/academy/01-GetStarted/03-ImplementOperationReducers.md +155 -178
  9. package/docs/academy/01-GetStarted/04-BuildToDoListEditor.md +218 -0
  10. package/docs/academy/{02-MasteryTrack/01-BuilderEnvironment → 01-GetStarted}/05-VetraStudio.md +22 -62
  11. package/docs/academy/01-GetStarted/06-ReactorMCP.md +58 -0
  12. package/docs/academy/01-GetStarted/_04-BuildToDoListEditor +1 -1
  13. package/docs/academy/02-MasteryTrack/01-BuilderEnvironment/03-BuilderTools.md +2 -2
  14. package/docs/academy/02-MasteryTrack/02-DocumentModelCreation/02-SpecifyTheStateSchema.md +44 -75
  15. package/docs/academy/02-MasteryTrack/02-DocumentModelCreation/03-SpecifyDocumentOperations.md +22 -28
  16. package/docs/academy/02-MasteryTrack/02-DocumentModelCreation/04-UseTheDocumentModelGenerator.md +31 -28
  17. package/docs/academy/02-MasteryTrack/02-DocumentModelCreation/05-ImplementDocumentReducers.md +206 -211
  18. package/docs/academy/02-MasteryTrack/02-DocumentModelCreation/06-ImplementDocumentModelTests.md +62 -176
  19. package/docs/academy/02-MasteryTrack/02-DocumentModelCreation/07-ExampleToDoListRepository.md +0 -21
  20. package/docs/academy/02-MasteryTrack/03-BuildingUserExperiences/01-BuildingDocumentEditors.md +319 -309
  21. package/docs/academy/02-MasteryTrack/03-BuildingUserExperiences/06-DocumentTools/00-DocumentToolbar.mdx +0 -4
  22. package/docs/academy/02-MasteryTrack/03-BuildingUserExperiences/06-DocumentTools/01-OperationHistory.md +0 -4
  23. package/docs/academy/02-MasteryTrack/05-Launch/04-ConfigureEnvironment.md +1 -1
  24. package/docs/academy/03-ExampleUsecases/Chatroom/02-CreateNewPowerhouseProject.md +35 -111
  25. package/docs/academy/03-ExampleUsecases/Chatroom/03-DefineChatroomDocumentModel.md +79 -195
  26. package/docs/academy/03-ExampleUsecases/Chatroom/04-ImplementOperationReducers.md +241 -435
  27. package/docs/academy/03-ExampleUsecases/Chatroom/05-ImplementChatroomEditor.md +27 -388
  28. package/docs/academy/03-ExampleUsecases/Chatroom/06-LaunchALocalReactor.md +7 -95
  29. package/docs/academy/03-ExampleUsecases/Chatroom/_category_.json +1 -1
  30. package/docs/academy/04-APIReferences/00-PowerhouseCLI.md +2 -6
  31. package/docs/academy/04-APIReferences/01-ReactHooks.md +501 -291
  32. package/docs/academy/05-Architecture/00-PowerhouseArchitecture.md +39 -7
  33. package/docs/academy/05-Architecture/02-ReferencingMonorepoPackages +65 -0
  34. package/docs/academy/05-Architecture/04-MovingBeyondCRUD +61 -0
  35. package/docs/academy/06-ComponentLibrary/00-DocumentEngineering.md +24 -72
  36. package/docs/academy/08-Glossary.md +0 -7
  37. package/docusaurus.config.ts +3 -28
  38. package/package.json +1 -1
  39. package/sidebars.ts +13 -49
  40. package/src/css/custom.css +18 -26
  41. package/docs/academy/01-GetStarted/04-WriteDocumentModelTests.md +0 -425
  42. package/docs/academy/01-GetStarted/05-BuildToDoListEditor.md +0 -557
  43. package/docs/academy/02-MasteryTrack/01-BuilderEnvironment/images/Modules.png +0 -0
  44. package/docs/academy/02-MasteryTrack/01-BuilderEnvironment/images/VetraStudioDrive.png +0 -0
  45. package/docs/academy/02-MasteryTrack/05-Launch/05-DockerDeployment.md +0 -384
  46. package/docs/academy/03-ExampleUsecases/TodoList/00-GetTheStarterCode.md +0 -24
  47. package/docs/academy/03-ExampleUsecases/TodoList/01-GenerateTodoListDocumentModel.md +0 -211
  48. package/docs/academy/03-ExampleUsecases/TodoList/02-ImplementTodoListDocumentModelReducerOperationHandlers.md +0 -171
  49. package/docs/academy/03-ExampleUsecases/TodoList/03-AddTestsForTodoListActions.md +0 -462
  50. package/docs/academy/03-ExampleUsecases/TodoList/04-GenerateTodoListDocumentEditor.md +0 -45
  51. package/docs/academy/03-ExampleUsecases/TodoList/05-ImplementTodoListDocumentEditorUIComponents.md +0 -422
  52. package/docs/academy/03-ExampleUsecases/TodoList/06-GenerateTodoDriveExplorer.md +0 -61
  53. package/docs/academy/03-ExampleUsecases/TodoList/07-AddSharedComponentForShowingTodoListStats.md +0 -384
  54. package/docs/academy/03-ExampleUsecases/TodoList/_category_.json +0 -8
  55. package/docs/academy/03-ExampleUsecases/VetraPackageLibrary/VetraPackageLibrary.md +0 -7
  56. package/docs/academy/03-ExampleUsecases/VetraPackageLibrary/_category_.json +0 -9
  57. package/docs/academy/04-APIReferences/06-VetraRemoteDrive.md +0 -160
  58. package/docs/academy/04-APIReferences/renown-sdk/00-Overview.md +0 -316
  59. package/docs/academy/04-APIReferences/renown-sdk/01-Authentication.md +0 -672
  60. package/docs/academy/04-APIReferences/renown-sdk/02-APIReference.md +0 -957
  61. package/docs/academy/04-APIReferences/renown-sdk/_category_.json +0 -8
  62. package/docs/academy/10-TodoListTutorial/02-ImplementTodoListDocumentModelReducerOperationHandlers.md +0 -171
  63. package/docs/academy/10-TodoListTutorial/03-AddTestsForTodoListActions.md +0 -462
  64. package/docs/academy/10-TodoListTutorial/05-ImplementTodoListDocumentEditorUIComponents.md +0 -422
  65. package/docs/academy/10-TodoListTutorial/07-AddSharedComponentForShowingTodoListStats.md +0 -370
  66. package/static/img/Vetra-logo-dark.svg +0 -11
  67. package/static/img/vetra-logo-light.svg +0 -11
  68. /package/docs/academy/02-MasteryTrack/03-BuildingUserExperiences/06-DocumentTools/{02-RevisionHistoryTimeline/360/237/232/247" → 02-RevisionHistoryTimeline} +0 -0
  69. /package/docs/academy/05-Architecture/05-DocumentModelTheory/{360/237/232/247 /01-WhatIsADocumentModel" → 01-WhatIsADocumentModel} +0 -0
  70. /package/docs/academy/05-Architecture/05-DocumentModelTheory/{360/237/232/247 /02-DAOandDocumentsModelsQ+A" → 02-DAOandDocumentsModelsQ+A} +0 -0
  71. /package/docs/academy/05-Architecture/05-DocumentModelTheory/{360/237/232/247 /02-domain-modeling" → 02-domain-modeling} +0 -0
  72. /package/docs/academy/05-Architecture/05-DocumentModelTheory/{360/237/232/247 /03-BenefitsOfDocumentModels" → 03-BenefitsOfDocumentModels} +0 -0
  73. /package/docs/academy/05-Architecture/05-DocumentModelTheory/{360/237/232/247 /04-UtilitiesAndTips" → 04-UtilitiesAndTips} +0 -0
  74. /package/docs/academy/05-Architecture/05-DocumentModelTheory/{360/237/232/247 /05-best-practices" → 05-best-practices} +0 -0
  75. /package/docs/academy/05-Architecture/05-DocumentModelTheory/{360/237/232/247 /_category_.json" → _category_.json} +0 -0
  76. /package/docs/academy/05-Architecture/05-DocumentModelTheory/{360/237/232/247 /three-data-layers.png" → three-data-layers.png} +0 -0
@@ -1,557 +0,0 @@
1
- # Build a to-do list editor
2
-
3
- :::tip Tutorial Repository
4
- 📦 **Reference Code**:
5
- - **Editor Scaffolding**: [step-5-generate-todo-list-document-editor](https://github.com/powerhouse-inc/todo-tutorial/tree/step-5-generate-todo-list-document-editor)
6
- - **Complete Editor UI**: [step-6-add-basic-todo-editor-ui-components](https://github.com/powerhouse-inc/todo-tutorial/tree/step-6-add-basic-todo-editor-ui-components)
7
-
8
- This tutorial covers two steps:
9
- 1. **Step 5**: Generating the editor template with `ph generate --editor`
10
- 2. **Step 6**: Building a complete, interactive UI with components for adding, editing, and deleting todos
11
-
12
- Compare implementations: `git diff step-5-generate-todo-list-document-editor step-6-add-basic-todo-editor-ui-components`
13
- :::
14
-
15
- <details>
16
- <summary>📖 How to use this tutorial</summary>
17
-
18
- This tutorial shows building from **generated scaffolding** (step-5) to **complete UI** (step-6).
19
-
20
- ### Compare your generated editor
21
-
22
- After running `ph generate --editor`:
23
-
24
- ```bash
25
- # Compare generated scaffolding with step-5
26
- git diff tutorial/step-5-generate-todo-list-document-editor -- editors/
27
-
28
- # View the generated editor template
29
- git show tutorial/step-5-generate-todo-list-document-editor:editors/todo-list-editor/editor.tsx
30
- ```
31
-
32
- ### Compare your custom components
33
-
34
- After building your UI:
35
-
36
- ```bash
37
- # Compare your complete editor with step-6
38
- git diff tutorial/step-6-add-basic-todo-editor-ui-components -- editors/
39
-
40
- # See what was added from scaffolding to complete UI
41
- git diff tutorial/step-5-generate-todo-list-document-editor..tutorial/step-6-add-basic-todo-editor-ui-components
42
- ```
43
-
44
- ### Browse the complete implementation
45
-
46
- Explore the production-ready component structure:
47
-
48
- ```bash
49
- # List all components in step-6
50
- git ls-tree -r --name-only tutorial/step-6-add-basic-todo-editor-ui-components editors/todo-list-editor/components/
51
-
52
- # View a specific component
53
- git show tutorial/step-6-add-basic-todo-editor-ui-components:editors/todo-list-editor/components/TodoList.tsx
54
- ```
55
-
56
- ### Visual comparison with GitHub Desktop
57
-
58
- After committing your editor code:
59
- 1. **Branch** menu → **"Compare to Branch..."**
60
- 2. Select `tutorial/step-5-generate-todo-list-document-editor` or `tutorial/step-6-add-basic-todo-editor-ui-components`
61
- 3. See all your custom components vs. the reference implementation
62
-
63
- See step 1 for detailed GitHub Desktop instructions.
64
-
65
- </details>
66
-
67
- In this chapter we will continue with the interface or editor implementation of the **To-do List** document model. This means you will create a simple user interface for the **To-do List** document model which will be used inside the Connect app to create, update and delete your ToDoList items.
68
-
69
- ## Add a document editor specification in Vetra Studio.
70
-
71
- Go back to Vetra Studio and click the 'Add new specification' button in the User Experiences column under 'Editors'. This will create an editor template for your document model.
72
-
73
- Give the editor the name `todo-list-editor` and select the correct document model. In our case that's the `powerhouse/todo-list`
74
-
75
- ### Editor implementation options
76
-
77
- When building your editor component within the Powerhouse ecosystem, you have several options for styling, allowing you to leverage your preferred methods:
78
-
79
- 1. **Default HTML Styling:** Standard HTML tags (`<h1>`, `<p>`, `<button>`, etc.) will render with default styles offered through the boilerplate.
80
- 2. **Tailwind CSS:** Connect Studio comes with Tailwind CSS integrated. You can directly use Tailwind utility classes for rapid, consistent styling without writing separate CSS files.
81
- 3. **Custom CSS Files:** You can import traditional CSS files (`.css`) to apply custom styles or integrate existing style libraries.
82
-
83
- Vetra Studio Preview provides a dynamic local environment, by running `ph vetra --watch` you can visualize your components instantly as you build them, regardless of the styling method you choose.
84
- Manual build steps are typically only needed when publishing packages.
85
-
86
- ## Build the editor with components
87
-
88
- We'll build the editor using a component-based approach for better organization and reusability. We'll create separate components for different UI features, making the code more maintainable and easier to understand.
89
-
90
- ### Component-based architecture
91
-
92
- The editor structure we'll build includes:
93
- - `editor.tsx` - Main editor wrapper (imports TodoList)
94
- - `TodoList.tsx` - Main container component that orchestrates all other components
95
- - `AddTodo.tsx` - Form component for adding new todos
96
- - `Todo.tsx` - Individual todo item component with edit/delete functionality
97
- - `Todos.tsx` - List wrapper component for rendering all todos
98
-
99
- :::tip
100
- The tutorial repository (step-6) includes additional components like `TodoListName`, `CloseButton`, and `UndoRedoButtons`. We'll focus on the core components here, but you can explore the complete implementation using the git commands shown above.
101
- :::
102
-
103
- ### Step 1: Update the main editor file
104
-
105
- First, update `editors/todo-list-editor/editor.tsx` to import and render the main `TodoList` component:
106
-
107
- ```tsx
108
- // removed-line
109
- import { EditTodoListName } from "./components/EditName.js";
110
- // added-line
111
- import { TodoList } from "./components/TodoList.js";
112
-
113
- /** Editor component for the Todo List document type */
114
- export function Editor() {
115
- return (
116
- <div className="py-4 px-8">
117
- // removed-line
118
- <EditTodoListName />
119
- // added-line
120
- <TodoList />
121
- </div>
122
- );
123
- }
124
- ```
125
-
126
- ### Step 2: Create the TodoList container component
127
-
128
- Create `editors/todo-list-editor/components/TodoList.tsx`. This is the main orchestrator that brings together all child components:
129
-
130
- ```tsx
131
- import { useSelectedTodoListDocument } from "todo-tutorial/document-models/todo-list";
132
- import { TodoListName } from "./TodoListName.js";
133
- import { Todos } from "./Todos.js";
134
- import { AddTodo } from "./AddTodo.js";
135
-
136
- /** Displays the selected todo list */
137
- export function TodoList() {
138
- const [selectedTodoList] = useSelectedTodoListDocument();
139
-
140
- if (!selectedTodoList) return null;
141
-
142
- const todos = selectedTodoList.state.global.items;
143
-
144
- return (
145
- <div>
146
- <section className="mb-4">
147
- <TodoListName />
148
- </section>
149
- <section className="mb-4">
150
- <Todos todos={todos} />
151
- </section>
152
- <section>
153
- <AddTodo />
154
- </section>
155
- </div>
156
- );
157
- }
158
- ```
159
-
160
- :::info Key Concept: useSelectedTodoListDocument hook
161
- The `useSelectedTodoListDocument` hook is generated by the Powerhouse CLI. It provides:
162
- 1. The current document state (`selectedTodoList`)
163
- 2. A dispatch function to send actions to the reducer
164
-
165
- This hook connects your React components to the document model's state and operations.
166
- :::
167
-
168
- ### Step 3: Create the AddTodo form component
169
-
170
- Create `editors/todo-list-editor/components/AddTodo.tsx` to handle adding new todo items:
171
-
172
- ```tsx
173
- import type { FormEventHandler } from "react";
174
- import { addTodoItem } from "todo-tutorial/document-models/todo-list";
175
- import { useSelectedTodoListDocument } from "todo-tutorial/document-models/todo-list";
176
-
177
- /** Component for adding a new todo item to the selected todo list */
178
- export function AddTodo() {
179
- // The hooks for getting documents also return a dispatch function
180
- // for dispatching actions to modify the document.
181
- // This is the same pattern you will have seen in React's `useReducer` hook,
182
- // except you don't need to pass the initial state.
183
- // The document we are working with _is_ the initial state.
184
- const [todoList, dispatch] = useSelectedTodoListDocument();
185
-
186
- if (!todoList) return null;
187
-
188
- const onSubmitAddTodo: FormEventHandler<HTMLFormElement> = (event) => {
189
- event.preventDefault();
190
-
191
- const form = event.currentTarget;
192
- const addTodoInput = form.elements.namedItem("addTodo") as HTMLInputElement;
193
- const text = addTodoInput.value;
194
- if (!text) return;
195
-
196
- // Dispatch the addTodoItem action - this will call the reducer
197
- // we implemented earlier and update the document state
198
- dispatch(addTodoItem({ text }));
199
-
200
- form.reset();
201
- };
202
-
203
- return (
204
- <form onSubmit={onSubmitAddTodo} className="flex mx-auto min-w-fit gap-2">
205
- <input
206
- className="py-1 px-2 grow min-w-fit placeholder:text-gray-600 rounded border border-gray-600 text-gray-800"
207
- type="text"
208
- name="addTodo"
209
- placeholder="What needs to be done?"
210
- autoFocus
211
- />
212
- <button
213
- type="submit"
214
- className="text-gray-600 rounded border border-gray-600 px-3 py-1"
215
- >
216
- Add
217
- </button>
218
- </form>
219
- );
220
- }
221
- ```
222
-
223
- **What's happening here:**
224
- - We use a form with `onSubmit` handler for better UX (Enter key support)
225
- - We extract the text value from the input field
226
- - We dispatch the `addTodoItem` action (generated from our SDL)
227
- - We reset the form after submission
228
-
229
- ### Step 4: Create the Todos list component
230
-
231
- Create `editors/todo-list-editor/components/Todos.tsx` to render the list of todos:
232
-
233
- ```tsx
234
- import type { TodoItem } from "todo-tutorial/document-models/todo-list";
235
- import { Todo } from "./Todo.js";
236
-
237
- type Props = {
238
- todos: TodoItem[];
239
- };
240
-
241
- /** Shows a list of the todo items in the selected todo list */
242
- export function Todos({ todos }: Props) {
243
- const hasTodos = todos.length > 0;
244
-
245
- if (!hasTodos) {
246
- return <p>Start adding things to your todo list</p>;
247
- }
248
-
249
- return (
250
- <ul>
251
- {todos.map((todo) => (
252
- <li key={todo.id}>
253
- <Todo todo={todo} />
254
- </li>
255
- ))}
256
- </ul>
257
- );
258
- }
259
- ```
260
-
261
- **What's happening here:**
262
- - We accept `todos` as a prop (passed from `TodoList` parent)
263
- - We show a helpful message if the list is empty
264
- - We map over todos and render a `Todo` component for each item
265
-
266
- ### Step 5: Create the Todo item component
267
-
268
- Create `editors/todo-list-editor/components/Todo.tsx` for individual todo items with edit and delete functionality:
269
-
270
- ```tsx
271
- import {
272
- useState,
273
- type ChangeEventHandler,
274
- type FormEventHandler,
275
- type MouseEventHandler,
276
- } from "react";
277
- import {
278
- deleteTodoItem,
279
- updateTodoItem,
280
- } from "todo-tutorial/document-models/todo-list";
281
- import type { TodoItem } from "todo-tutorial/document-models/todo-list";
282
- import { useSelectedTodoListDocument } from "todo-tutorial/document-models/todo-list";
283
-
284
- type Props = {
285
- todo: TodoItem;
286
- };
287
-
288
- /** Displays a single todo item in the selected todo list
289
- *
290
- * Allows checking/unchecking the todo item.
291
- * Allows editing the todo item text.
292
- * Allows deleting the todo item.
293
- */
294
- export function Todo({ todo }: Props) {
295
- const [isEditing, setIsEditing] = useState(false);
296
-
297
- // Even though this component is for a single todo item and not the whole list,
298
- // we can use the exact same hook for dispatching updates to it.
299
- // The dispatch function works for any action supported by a TodoList document.
300
- const [todoList, dispatch] = useSelectedTodoListDocument();
301
-
302
- if (!todoList) return null;
303
-
304
- const todoId = todo.id;
305
- const todoText = todo.text;
306
- const todoChecked = todo.checked;
307
-
308
- const onSubmitUpdateTodoText: FormEventHandler<HTMLFormElement> = (event) => {
309
- event.preventDefault();
310
-
311
- const form = event.currentTarget;
312
- const textInput = form.elements.namedItem("todoText") as HTMLInputElement;
313
- const text = textInput.value;
314
- if (!text) return;
315
-
316
- // We can use the dispatch function for any of the actions
317
- // supported by a TodoList document
318
- dispatch(updateTodoItem({ id: todo.id, text }));
319
- setIsEditing(false);
320
- };
321
-
322
- const onChangeTodoChecked: ChangeEventHandler<HTMLInputElement> = (event) => {
323
- dispatch(
324
- updateTodoItem({
325
- id: todo.id,
326
- checked: event.target.checked,
327
- }),
328
- );
329
- };
330
-
331
- const onClickDeleteTodo: MouseEventHandler<HTMLButtonElement> = () => {
332
- dispatch(deleteTodoItem({ id: todoId }));
333
- };
334
-
335
- const onClickEditTodo: MouseEventHandler<HTMLButtonElement> = () => {
336
- setIsEditing(true);
337
- };
338
-
339
- const onClickCancelEditTodo: MouseEventHandler<HTMLButtonElement> = () => {
340
- setIsEditing(false);
341
- };
342
-
343
- if (isEditing)
344
- return (
345
- <form
346
- className="flex gap-2 items-center justify-between"
347
- onSubmit={onSubmitUpdateTodoText}
348
- >
349
- <input
350
- className="p-1 grow"
351
- type="text"
352
- name="todoText"
353
- defaultValue={todoText}
354
- autoFocus
355
- />
356
- <div className="flex gap-2 grow-0">
357
- <button type="submit" className="text-sm text-gray-600">
358
- Save
359
- </button>
360
- <button
361
- className="text-sm text-red-800"
362
- onClick={onClickCancelEditTodo}
363
- >
364
- Cancel
365
- </button>
366
- </div>
367
- </form>
368
- );
369
-
370
- return (
371
- <div className="flex justify-between items-center">
372
- <div className="flex items-center gap-2 p-1">
373
- <input
374
- type="checkbox"
375
- checked={todoChecked}
376
- onChange={onChangeTodoChecked}
377
- />
378
- <span className={todoChecked ? "line-through" : ""}>{todoText}</span>
379
- </div>
380
- <span className="flex place-items-center gap-2 text-sm">
381
- <button className="text-gray-600" onClick={onClickEditTodo}>
382
- Edit
383
- </button>
384
- <button className="text-red-800" onClick={onClickDeleteTodo}>
385
- Delete
386
- </button>
387
- </span>
388
- </div>
389
- );
390
- }
391
- ```
392
-
393
- **What's happening here:**
394
- - We use local state (`isEditing`) to toggle between view and edit modes
395
- - We dispatch `updateTodoItem` for both checking and text editing
396
- - We dispatch `deleteTodoItem` to remove items
397
- - We use TypeScript event handlers for type safety
398
-
399
- ### Step 6: Create the TodoListName component
400
-
401
- Finally, create `editors/todo-list-editor/components/TodoListName.tsx` for displaying and editing the document name:
402
-
403
- ```tsx
404
- import { useState, type FormEventHandler } from "react";
405
- import { useSelectedTodoListDocument } from "todo-tutorial/document-models/todo-list";
406
- import { setName } from "document-model/document";
407
-
408
- /** Allows editing the name of the selected todo list */
409
- export function TodoListName() {
410
- const [isEditing, setIsEditing] = useState(false);
411
- const [selectedTodoList, dispatch] = useSelectedTodoListDocument();
412
-
413
- if (!selectedTodoList) return null;
414
-
415
- const documentName = selectedTodoList.name;
416
-
417
- const onSubmitEditName: FormEventHandler<HTMLFormElement> = (event) => {
418
- event.preventDefault();
419
-
420
- const form = event.currentTarget;
421
- const nameInput = form.elements.namedItem("name") as HTMLInputElement;
422
- const name = nameInput.value;
423
-
424
- if (name) {
425
- dispatch(setName(name));
426
- setIsEditing(false);
427
- }
428
- };
429
-
430
- if (isEditing) {
431
- return (
432
- <form onSubmit={onSubmitEditName}>
433
- <input
434
- name="name"
435
- defaultValue={documentName}
436
- className="text-xl font-bold"
437
- autoFocus
438
- />
439
- </form>
440
- );
441
- }
442
-
443
- return (
444
- <h1
445
- className="text-xl font-bold cursor-pointer"
446
- onClick={() => setIsEditing(true)}
447
- >
448
- {documentName}
449
- </h1>
450
- );
451
- }
452
- ```
453
-
454
- **What's happening here:**
455
- - We use the `setName` action from `document-model/document` (a built-in action)
456
- - We toggle between viewing and editing the name
457
- - Click the name to edit it
458
-
459
- ## Test your editor
460
-
461
- Now you can run the Vetra Studio Preview and see the **To-do List** editor in action:
462
-
463
- ```bash
464
- ph vetra --watch
465
- ```
466
-
467
- In the bottom right corner you'll find a new Document Model that you can create: **To-do List**.
468
- Click on it to create a new To-do List document.
469
-
470
- :::info Live Development
471
- The editor will update dynamically as you make changes, so you can experiment with styling and functionality while seeing your results appear in Vetra Studio in real-time.
472
- :::
473
-
474
- **Try it out:**
475
- 1. Add some todo items using the input form
476
- 2. Click on the document name to edit it
477
- 3. Check/uncheck items to mark them as complete
478
- 4. Click "Edit" on any item to modify its text
479
- 5. Click "Delete" to remove items
480
-
481
- Congratulations! 🎉
482
- If you managed to follow this tutorial until this point, you have successfully implemented the **To-do List** document model with its reducer operations and editor.
483
-
484
- ## Compare with the reference implementation
485
-
486
- The tutorial repository's step-6 branch includes additional enhancements you can explore:
487
-
488
- **Additional components in step-6:**
489
- ```
490
- editors/todo-list-editor/components/
491
- ├── CloseButton.tsx # Editor close functionality
492
- ├── UndoRedoButtons.tsx # Operation history navigation
493
- └── Stats.tsx # Display metadata (creation/modification times)
494
- ```
495
-
496
- **View individual components from the reference:**
497
-
498
- ```bash
499
- # See the enhanced TodoList component with all features
500
- git show tutorial/step-6-add-basic-todo-editor-ui-components:editors/todo-list-editor/components/TodoList.tsx
501
-
502
- # Explore the UndoRedoButtons component
503
- git show tutorial/step-6-add-basic-todo-editor-ui-components:editors/todo-list-editor/components/UndoRedoButtons.tsx
504
-
505
- # Compare your implementation with the reference
506
- git diff tutorial/step-6-add-basic-todo-editor-ui-components -- editors/todo-list-editor/
507
- ```
508
-
509
- :::tip Check your work
510
-
511
- To make sure everything works as expected:
512
-
513
- ```bash
514
- # Check types compile correctly
515
- pnpm tsc
516
-
517
- # Check linting passes
518
- pnpm lint
519
-
520
- # Run tests
521
- pnpm test
522
-
523
- # Test in Connect Studio
524
- ph connect
525
-
526
- # Compare with reference implementation
527
- git diff tutorial/step-6-add-basic-todo-editor-ui-components -- editors/todo-list-editor/
528
- ```
529
-
530
- In Connect, you should be able to:
531
- - Create a new To-do List document
532
- - Add, edit, and delete todo items
533
- - Check/uncheck items to mark them complete
534
-
535
- :::
536
-
537
- ## Key concepts learned
538
-
539
- In this tutorial you've learned:
540
-
541
- ✅ **Component-based architecture** - Breaking down complex UIs into reusable components
542
- ✅ **Document model hooks** - Using `useSelectedTodoListDocument` to connect React to your document state
543
- ✅ **Action dispatching** - How to dispatch operations (`addTodoItem`, `updateTodoItem`, `deleteTodoItem`) from your UI
544
- ✅ **Type-safe development** - Leveraging TypeScript with generated types from your SDL
545
- ✅ **Form handling** - Using React forms with proper event handlers
546
- ✅ **Local vs. document state** - When to use React `useState` vs. document model state
547
-
548
- ### Up next: Mastery Track
549
-
550
- In the [Mastery Track chapter: Document Model Creation](/academy/MasteryTrack/DocumentModelCreation/WhatIsADocumentModel) we guide you through the theoretics of the previous steps while creating a more advanced version of the To-do List.
551
-
552
- You will learn:
553
-
554
- - The in's & out's of a document model.
555
- - How to use UI & Scalar components from the Document Engineering system.
556
- - How to build Custom Drive Apps or Drive Explorers.
557
-