@alstar/studio 0.0.0-beta.15 → 0.0.0-beta.18

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 (52) hide show
  1. package/api/block.ts +0 -14
  2. package/components/AdminPanel.ts +11 -5
  3. package/components/BlockFieldRenderer.ts +26 -20
  4. package/components/BlockRenderer.ts +4 -4
  5. package/components/Entries.ts +1 -1
  6. package/components/Entry.ts +13 -7
  7. package/components/FieldRenderer.ts +14 -8
  8. package/components/LivePreview.ts +37 -0
  9. package/components/Render.ts +8 -3
  10. package/components/SiteLayout.ts +1 -4
  11. package/components/fields/Markdown.ts +10 -3
  12. package/components/fields/Reference.ts +71 -0
  13. package/components/fields/Slug.ts +6 -6
  14. package/components/fields/Text.ts +13 -8
  15. package/components/fields/index.ts +2 -1
  16. package/components/icons.ts +3 -0
  17. package/components/settings/ApiKeys.ts +4 -4
  18. package/components/settings/Backup.ts +3 -3
  19. package/components/settings/Users.ts +1 -1
  20. package/index.ts +11 -10
  21. package/package.json +5 -6
  22. package/pages/entry/[id].ts +7 -1
  23. package/pages/error.ts +7 -6
  24. package/pages/login.ts +1 -1
  25. package/pages/register.ts +2 -2
  26. package/public/studio/css/admin-panel.css +27 -9
  27. package/public/studio/css/blocks-field.css +25 -0
  28. package/public/studio/css/entry-page.css +4 -0
  29. package/public/studio/css/entry.css +35 -0
  30. package/public/studio/css/field.css +14 -0
  31. package/public/studio/css/live-preview.css +25 -0
  32. package/public/studio/css/settings.css +4 -0
  33. package/public/studio/js/live-preview.js +26 -0
  34. package/public/studio/js/markdown-editor.js +6 -0
  35. package/public/studio/js/sortable-list.js +6 -4
  36. package/public/studio/main.css +11 -12
  37. package/public/studio/main.js +1 -0
  38. package/queries/block.ts +127 -105
  39. package/queries/index.ts +3 -2
  40. package/schemas.ts +1 -1
  41. package/types.ts +51 -75
  42. package/utils/define.ts +3 -1
  43. package/utils/get-or-create-row.ts +2 -1
  44. package/utils/refresher.ts +56 -0
  45. package/utils/renderSSE.ts +8 -3
  46. package/utils/startup-log.ts +4 -4
  47. package/queries/block-2.ts +0 -339
  48. package/queries/db-types.ts +0 -15
  49. package/queries/getBlockTrees-2.ts +0 -71
  50. package/queries/getBlocks.ts +0 -214
  51. package/queries/structure-types.ts +0 -97
  52. package/utils/buildBlocksTree.ts +0 -44
@@ -1,97 +0,0 @@
1
- // structure-types.ts
2
- import { type DBBase } from "./db-types.ts";
3
-
4
- /**
5
- * Extract helpers
6
- */
7
- type ArrayElement<T> = T extends readonly (infer U)[] ? U : never;
8
-
9
- /**
10
- * Field definition shape inferred from defineField(...) (the runtime helper)
11
- * We keep it generic as "any" shape but with the important properties present
12
- */
13
- type FieldDef = {
14
- readonly name: string;
15
- readonly type: string;
16
- readonly fields?: readonly any[]; // only present when type === 'blocks'
17
- };
18
-
19
- /**
20
- * Block definition shape inferred from defineBlock(...) (the runtime helper)
21
- */
22
- type BlockDef = {
23
- readonly name: string;
24
- readonly type: string;
25
- readonly fields?: readonly FieldDef[];
26
- };
27
-
28
- /**
29
- * Primitive field node (non-'blocks'): DBBase + kept fields but no children
30
- */
31
- type PrimitiveFieldNode<TField extends FieldDef> =
32
- DBBase & {
33
- readonly name: TField["name"];
34
- readonly type: TField["type"];
35
- // no children (leaf), no nested fields
36
- readonly children?: [];
37
- readonly fields?: {}; // empty object for leaf
38
- };
39
-
40
- /**
41
- * For 'blocks' typed field, we need:
42
- * - the block node representing the 'blocks' wrapper (has DBBase props)
43
- * - its 'children' are an array of BlockNodes corresponding to nested block defs supplied in the field's 'fields' array
44
- * - its 'fields' property is the mapping of its own child-field names (can be empty)
45
- */
46
- type BlocksFieldNode<
47
- TField extends FieldDef,
48
- TFieldDefs extends readonly BlockDef[]
49
- > = DBBase & {
50
- readonly name: TField["name"]; // e.g. "blocks" or "images"
51
- readonly type: "blocks"; // literally 'blocks'
52
- readonly children: BlockNodeFromBlockDefs<TFieldDefs>[]; // children are instances of the nested blocks
53
- readonly fields: FieldsFromFieldDefs<TFieldDefs[number]["fields"]>; // the blocks-wrapper's own fields mapping (if any)
54
- };
55
-
56
- /**
57
- * Build the 'fields' object for a set of FieldDef[].
58
- * Maps each field name -> either PrimitiveFieldNode or BlocksFieldNode recursively.
59
- */
60
- type FieldsFromFieldDefs<TDefs> =
61
- // If no fields
62
- TDefs extends readonly any[]
63
- ? {
64
- // For each field F in TDefs, map F['name'] -> node type
65
- [F in ArrayElement<TDefs> as F extends { name: infer N extends string } ? N : never]:
66
- F extends { type: "blocks"; fields: readonly BlockDef[] }
67
- ? BlocksFieldNode<F, F["fields"]>
68
- : PrimitiveFieldNode<F>;
69
- }
70
- : {};
71
-
72
- /**
73
- * A Block node type for a particular BlockDef.
74
- * - fields: mapping derived from the block's declared fields
75
- * - children: by default [], because in our final shape all immediate children are placed under 'fields' of the parent.
76
- * BUT for nodes that are themselves 'blocks' wrappers (i.e. appear as a Block instance of a nested block def),
77
- * their 'children' will contain actual child blocks (these are handled via BlocksFieldNode above).
78
- */
79
- export type BlockNode<T extends BlockDef> = DBBase & {
80
- readonly name: T["name"];
81
- readonly type: T["type"];
82
- readonly fields: FieldsFromFieldDefs<T["fields"]>;
83
- // for regular block nodes, children will usually be [] (top-level parent's children moved into fields)
84
- readonly children: [];
85
- };
86
-
87
- /**
88
- * Construct BlockNode unions for a set of block defs (used when blocks field has multiple block subdefs)
89
- */
90
- type BlockNodeFromBlockDefs<TDefs extends readonly BlockDef[]> =
91
- ArrayElement<TDefs> extends infer B ? (B extends BlockDef ? BlockNode<B> : never) : never;
92
-
93
- /**
94
- * The top-level forest return type when you pass a structure: it's an array of BlockNode of any top-level BlockDef
95
- */
96
- export type BlockTreeFromStructure<TStructure extends readonly BlockDef[]> =
97
- BlockNodeFromBlockDefs<TStructure>;
@@ -1,44 +0,0 @@
1
- type Block = {
2
- id: number
3
- name: string
4
- label: string
5
- type: string
6
- sort_order: number
7
- value: string | null
8
- options: any // JSON-parsed if necessary
9
- parent_id: number | null
10
- depth: number
11
- // ... you can add other fields if needed
12
- }
13
-
14
- type BlockWithChildren = Block & { fields: BlockWithChildren[] }
15
-
16
- export function buildBlockTree(blocks: Block[]): BlockWithChildren {
17
- const blockMap = new Map<number, BlockWithChildren>()
18
-
19
- // Initialize map with all blocks and empty `fields` array
20
- for (const block of blocks) {
21
- blockMap.set(block.id, { ...block, fields: [] })
22
- }
23
-
24
- const tree: BlockWithChildren[] = []
25
-
26
- for (const block of blocks) {
27
- const current = blockMap.get(block.id)!
28
-
29
- if (block.parent_id != null) {
30
- const parent = blockMap.get(block.parent_id)
31
- if (parent) {
32
- parent.fields.push(current)
33
- } else {
34
- console.warn(
35
- `Parent with id ${block.parent_id} not found for block ${block.id}`,
36
- )
37
- }
38
- } else {
39
- tree.push(current) // top-level (root) blocks
40
- }
41
- }
42
-
43
- return tree[0]
44
- }