@prenta/component-blocks 0.3.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/CHANGELOG.md +230 -0
- package/LICENSE +21 -0
- package/README.md +88 -0
- package/dist/cli.d.ts +24 -0
- package/dist/cli.d.ts.map +1 -0
- package/dist/cli.js +306 -0
- package/dist/cli.js.map +1 -0
- package/dist/diff.d.ts +38 -0
- package/dist/diff.d.ts.map +1 -0
- package/dist/diff.js +524 -0
- package/dist/diff.js.map +1 -0
- package/dist/discriminated-union.d.ts +89 -0
- package/dist/discriminated-union.d.ts.map +1 -0
- package/dist/discriminated-union.js +131 -0
- package/dist/discriminated-union.js.map +1 -0
- package/dist/extract.d.ts +117 -0
- package/dist/extract.d.ts.map +1 -0
- package/dist/extract.js +1036 -0
- package/dist/extract.js.map +1 -0
- package/dist/index.d.ts +19 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +15 -0
- package/dist/index.js.map +1 -0
- package/dist/migrate.d.ts +59 -0
- package/dist/migrate.d.ts.map +1 -0
- package/dist/migrate.js +312 -0
- package/dist/migrate.js.map +1 -0
- package/dist/paths.d.ts +77 -0
- package/dist/paths.d.ts.map +1 -0
- package/dist/paths.js +288 -0
- package/dist/paths.js.map +1 -0
- package/dist/types.d.ts +229 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +12 -0
- package/dist/types.js.map +1 -0
- package/package.json +61 -0
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,230 @@
|
|
|
1
|
+
# @actuate-media/component-blocks
|
|
2
|
+
|
|
3
|
+
## 0.3.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- 5eea995: Product rename: ActuateCMS is now **Prenta**. Every package moves from the
|
|
8
|
+
`@actuate-media/*` scope to `@prenta/*` with simplified names (`@prenta/core`,
|
|
9
|
+
`@prenta/admin`, `create-prenta`), and version numbers continue from where the
|
|
10
|
+
old scope left off.
|
|
11
|
+
|
|
12
|
+
This is a clean break — no backwards-compat aliases:
|
|
13
|
+
- **npm packages**: `@actuate-media/cms-core` → `@prenta/core`,
|
|
14
|
+
`@actuate-media/cms-admin` → `@prenta/admin`, all other packages keep their
|
|
15
|
+
suffix under `@prenta/*`. `create-actuate-cms` → `create-prenta`
|
|
16
|
+
(`npm create prenta`), `create-actuate-astro` → `create-prenta-astro`.
|
|
17
|
+
CLI bins: `actuate`/`actuate-cms` → `prenta`/`prenta-cms`; `actuate-mcp` →
|
|
18
|
+
`prenta-mcp`.
|
|
19
|
+
- **Database**: migration `0012_rename_to_prenta` renames all 36 `actuate_*`
|
|
20
|
+
tables to `prenta_*` in place (plus prefixed constraints, indexes, and
|
|
21
|
+
sequences). Run `prisma migrate deploy` when upgrading.
|
|
22
|
+
- **Runtime identifiers**: `getActuateConfig` → `getPrentaConfig`,
|
|
23
|
+
`handleActuateAPI` → `handlePrentaAPI`, `ActuateClient` → `PrentaClient`,
|
|
24
|
+
`ActuateDB` → `PrentaDB`, config file `actuate.config.ts` →
|
|
25
|
+
`prenta.config.ts`, CSS scopes `.actuate-admin`/`.actuate-canvas` →
|
|
26
|
+
`.prenta-admin`/`.prenta-canvas`, preview protocol `actuate-preview:*` →
|
|
27
|
+
`prenta-preview:*`, webhook headers `X-Actuate-*` → `X-Prenta-*`, session
|
|
28
|
+
cookie `actuate_session` → `prenta_session`, env vars `ACTUATE_*` →
|
|
29
|
+
`PRENTA_*`, purge route `/api/actuate/purge` → `/api/prenta/purge`.
|
|
30
|
+
- **Sessions and webhooks**: all sessions reset on upgrade (cookie + JWT issuer
|
|
31
|
+
changed); webhook consumers must re-verify signatures against the new
|
|
32
|
+
`X-Prenta-*` headers.
|
|
33
|
+
|
|
34
|
+
The old `@actuate-media/*` packages are deprecated on npm and will receive no
|
|
35
|
+
further releases.
|
|
36
|
+
|
|
37
|
+
## 0.2.2
|
|
38
|
+
|
|
39
|
+
### Patch Changes
|
|
40
|
+
|
|
41
|
+
- 041a228: Add the MIT `license` field to every published package (previously missing) and correct `repository.url` to `github.com/actuate-media/actuatecms` (13 packages carried the wrong org).
|
|
42
|
+
|
|
43
|
+
## 0.2.1
|
|
44
|
+
|
|
45
|
+
### Patch Changes
|
|
46
|
+
|
|
47
|
+
- 854152d: Developer experience improvements from external-consumer feedback:
|
|
48
|
+
- Every published package now ships its `CHANGELOG.md` in the npm tarball, and packages that were missing a `README.md` (cli, cms-admin, cms-core, import, platform-vercel, all plugins, sections-react) now have one — so release notes and usage docs are visible on npmjs.com and in `node_modules`.
|
|
49
|
+
- New client-safe form validation entry point: `@actuate-media/cms-core/forms/client` exports `validateFormFieldClient()`, `validateFormValuesClient()`, visibility/conditional helpers, and the exact `FORM_EMAIL_RE` / `FORM_PHONE_RE` regexes the server enforces — zero Node dependencies, so public-site forms can mirror server rules without reimplementing them. The server validator now imports the same primitives, so client and server can never drift.
|
|
50
|
+
|
|
51
|
+
## 0.2.0
|
|
52
|
+
|
|
53
|
+
### Minor Changes
|
|
54
|
+
|
|
55
|
+
- 02df678: Phase 4, PR #2 — admin form generator + cross-file type resolution.
|
|
56
|
+
|
|
57
|
+
`@actuate-media/cms-admin` adds a new `componentBlock` field renderer:
|
|
58
|
+
- `<ComponentBlockField>` picks a component from the manifest's allow-list and renders a typed props form via a recursive `<PropInput>` dispatcher. Inputs vary per `PropType.kind` (string, number, boolean, enum, literal, object, array; unsupported kinds fall back to a JSON textarea with a hint).
|
|
59
|
+
- Picking a new component seeds the props object from each prop's `defaultValue`, with structural defaults for required props that lack a literal default.
|
|
60
|
+
- Live structural validation mirrors `validateComponentBlockValue` from cms-core and surfaces per-prop errors under the correct input on every keystroke.
|
|
61
|
+
- The new field is wired into `FieldRenderer`'s `FIELD_MAP` under `componentBlock` and exported from the package's main entry.
|
|
62
|
+
|
|
63
|
+
`@actuate-media/component-blocks` extends the extractor:
|
|
64
|
+
- Cross-file `import type { Foo } from './bar'` is now followed during extraction (with cycle detection + per-run caching). Renamed imports (`{ Foo as Bar }`) are stored under their local alias.
|
|
65
|
+
- TypeScript-ESM-style `.js` import specifiers resolve to their `.ts`/`.tsx` source siblings.
|
|
66
|
+
- Manifest `filePath` is now a POSIX-relative path from the `rootDir` instead of an absolute disk path, so a manifest generated on Windows is identical to one generated on Linux.
|
|
67
|
+
|
|
68
|
+
Bug fixes from Bugbot review:
|
|
69
|
+
- `<EnumInput>` placeholder option now clears the field to `undefined` instead of silently selecting the first enum value (`Number("")` → `0` regression).
|
|
70
|
+
- `getAllowedComponents` and `buildClientValidator` now agree on the meaning of `allow={[]}`: both treat an empty allow array as "no filter". Previously the picker showed every component while validation rejected every selection.
|
|
71
|
+
- Import scanner bail-out no longer skips 6 extra characters after `import` (the keyword-match index already points past `import`), so subsequent imports after a side-effect import are no longer silently swallowed.
|
|
72
|
+
- `defaultForType` now returns `null` (not `undefined`) for `union`, `reference`, and `unknown` kinds so the documented "never `undefined` in an array" invariant holds. `JsonFallback` treats both `null` and `undefined` as empty so the textarea doesn't show the literal string `null`. `seedPropsForComponent` skips seeding required props of those kinds so the validator's "Missing required prop" message doesn't fire the instant an editor picks the component (the prop stays absent until the editor provides a value via the JsonFallback).
|
|
73
|
+
- `safeJsonStringify` no longer short-circuits for strings; the JsonFallback textarea now round-trips strings through `"hello"` instead of bare `hello`, so users can keep editing without the field "locking" into a non-JSON form.
|
|
74
|
+
- `clientShapeError` now recurses into object props with required children. Passing `{}` for an object prop with required nested fields used to slip past the client validator and fail server-side; the validator now reports `Prop 'cta.label' is required but missing.` inline.
|
|
75
|
+
|
|
76
|
+
- 9b897d5: Phase 4, PR #3 — `diff` CLI + `ManifestDiff` types + tsconfig `paths` support.
|
|
77
|
+
|
|
78
|
+
New capabilities:
|
|
79
|
+
- **`actuate-component-blocks diff <old> <new>`** compares two manifests and reports added/removed components, prop additions/removals, type changes, required/optional transitions, and default-value transitions. Pretty text output by default, JSON with `--json`. Exit codes are CI-friendly: `0` clean, `2` breaking, `1` invalid invocation.
|
|
80
|
+
- **`diffManifests()`** pure function plus structured `ManifestDiff`, `ComponentChange`, `PropChange`, and `ChangeSeverity` types exported from the package. Severity classifier covers all `PropType` kinds including recursive array/object diffs and enum value gains/losses.
|
|
81
|
+
- **`formatManifestDiff()`** pretty-printer suitable for PR comments and CI logs (plain text, no ANSI).
|
|
82
|
+
- **tsconfig `paths` resolution** in the extractor — relative imports still work as before, and `import type { Foo } from '@/lib/types'` now resolves through the nearest `tsconfig.json` (walked up from `rootDir`), honoring `compilerOptions.baseUrl` + `paths`. A small JSONC stripper handles comments + trailing commas inside tsconfig files.
|
|
83
|
+
- New public helpers exported: `findTsconfig`, `readTsconfig`, `resolveTsconfigPath`, `stripJsonc`, plus the `TsconfigPaths` type.
|
|
84
|
+
- New regression tests: 20 for `paths.ts` (JSONC stripping, find/read, pattern matching, end-to-end extractor integration), 24 for `diff.ts` (every severity branch + pretty-printer), 5 for the `diff` CLI subcommand (exit codes, JSON mode, error paths).
|
|
85
|
+
|
|
86
|
+
Bug fixes from Bugbot review:
|
|
87
|
+
- `classifyObjectChange` now correctly classifies a nested object field flipping optional→required as `breaking`. Previously the function only compared field types via `propTypesEqual`; an existing field becoming required fell through to the `safe` branch, letting a breaking change past the CI gate.
|
|
88
|
+
- Removed dead `propTypesEqual` gate inside the array branch of `classifyTypeChange`. The condition was guaranteed-false at the call site (the outer gate already rejected equal array types), and inverting the logic could mis-classify recursive array diffs if the function were ever called outside `diffProp`. The array branch now always recurses into the itemType.
|
|
89
|
+
- `stripJsonc` no longer strips trailing commas embedded inside JSON string values. The old trailing-comma regex ran over the whole output and could silently corrupt strings like `"data,}"`; the trailing-comma pass now tracks string state and only acts outside quoted regions.
|
|
90
|
+
- `classifyObjectChange` now recursively classifies per-field type changes (via `classifyTypeChange`) and surfaces the worst severity, instead of returning the catch-all `unknown` for any field-type change. A `string → number` nested inside an object field is now correctly reported as `breaking` and the CI gate fires on it; an enum-value gain stays `safe`. Matches the existing recursive behavior of the array branch.
|
|
91
|
+
- `diffProp` now combines per-axis severities when a prop changes both its type and its required-ness in one revision. A "safe" type change (e.g. an enum gaining a value) that also flips optional → required surfaces as `breaking`; conversely, an unsafe type change stays `breaking` even if the prop simultaneously becomes optional. This realizes the function's documented "worst severity bubbles up" contract.
|
|
92
|
+
- `classifyObjectChange` no longer reports the misleading "Object gained optional field(s) only" reason when no fields were actually added. It now describes what really changed — newly added optional fields, existing fields becoming optional, and `defaultValue` adjustments — so CLI/JSON output reflects reality. Severity is unchanged (`safe`).
|
|
93
|
+
|
|
94
|
+
- 1675eac: Add component-aware blocks — Phase 4 foundation slice.
|
|
95
|
+
|
|
96
|
+
Ships the new `@actuate-media/component-blocks` package, which reads a directory of React component source files and emits a typed `Manifest` describing every exported component's props (`string` / `number` / `boolean` / `enum` / `union` / `object` / `array`). Same-file type aliases are resolved automatically. Includes a CLI (`actuate-component-blocks extract --root <dir> --out <file>`) and a programmatic `extractManifest()` API.
|
|
97
|
+
|
|
98
|
+
Adds the `componentBlock` field type to `@actuate-media/cms-core`, which consumes a manifest and validates stored block values — rejecting unknown components, missing required props, wrong-type values, and out-of-set enum picks. Field-level `allow` and `defaultComponent` options are supported.
|
|
99
|
+
|
|
100
|
+
This is the foundation slice; admin form generation, migration-diff CLI, and discriminated-union pickers ship in follow-up PRs. See `docs/component-blocks.md`.
|
|
101
|
+
|
|
102
|
+
- 95e6a76: Phase 4, PR #3b — `migrate` CLI + `migrateValue` / `migrateContentJson` API.
|
|
103
|
+
|
|
104
|
+
The companion to PR #3's `diff` command: where `diff` tells you what
|
|
105
|
+
changed between two manifests, `migrate` rewrites stored content so it
|
|
106
|
+
satisfies the new manifest's schema. Together they close the loop
|
|
107
|
+
between "you changed a component" and "your saved content still
|
|
108
|
+
validates" without putting that burden on editors.
|
|
109
|
+
|
|
110
|
+
New capabilities:
|
|
111
|
+
- **`actuate-component-blocks migrate <old> <new> <content>`** —
|
|
112
|
+
rewrite a JSON content file to match a new manifest. Default is a
|
|
113
|
+
dry-run that prints a human-readable summary; `--write` applies the
|
|
114
|
+
migration in place (or to `--out`); `--json` emits a structured
|
|
115
|
+
result for tooling. Accepts either a single `{ component, props }`
|
|
116
|
+
value or an array of them at the top level; other shapes pass
|
|
117
|
+
through with an informational issue rather than being silently
|
|
118
|
+
rewritten. Exit codes: `0` clean (dry-run or applied), `2`
|
|
119
|
+
unresolved issues — used as a CI gate, `1` invalid invocation.
|
|
120
|
+
- **`migrateValue()`** pure function — migrate a single
|
|
121
|
+
`ComponentBlockValue` against a manifest pair, returning the
|
|
122
|
+
rewritten value plus auto-applied changes and unresolved issues.
|
|
123
|
+
- **`migrateContentJson()`** convenience wrapper for whole-file JSON
|
|
124
|
+
inputs (single value or array), used by the CLI and suitable for
|
|
125
|
+
build-step automation.
|
|
126
|
+
- **`formatMigrationSummary()`** plain-text renderer suitable for PR
|
|
127
|
+
comments and CI logs.
|
|
128
|
+
- New structured types: `MigrationResult`, `MigrationChange`,
|
|
129
|
+
`MigrationIssue`, `MigrationAction`, `MigrationIssueKind`. Each
|
|
130
|
+
unresolvable transition is classified — `component-removed`,
|
|
131
|
+
`component-unknown`, `required-without-default`,
|
|
132
|
+
`became-required-missing`, `enum-value-invalid`, `type-changed`,
|
|
133
|
+
`unresolvable` — and paired with an actionable `hint`.
|
|
134
|
+
- New public `ComponentBlockValue` type so migration code doesn't
|
|
135
|
+
reach into `cms-admin` for the stored shape.
|
|
136
|
+
|
|
137
|
+
Auto-applied transitions: drop removed props, fill new required props
|
|
138
|
+
with declared `defaultValue`, pass through every change classified as
|
|
139
|
+
`safe` (required→optional, default-value-only changes, enum gains).
|
|
140
|
+
|
|
141
|
+
Flagged-for-editor transitions: new required prop without a default,
|
|
142
|
+
optional→required prop with no stored value, enum that dropped a value
|
|
143
|
+
the content currently uses, type-kind change (string→number etc.), and
|
|
144
|
+
any same-kind breaking transition the migrator can't safely resolve
|
|
145
|
+
on its own (e.g. an object losing a field).
|
|
146
|
+
|
|
147
|
+
Tests: 33 new unit tests in `migrate.test.ts` (every change/issue
|
|
148
|
+
kind, manifest-level and file-level cases, precomputed-diff path) +
|
|
149
|
+
9 new CLI integration tests (dry-run vs `--write`, `--out` redirect,
|
|
150
|
+
`--json`, exit codes for issues / invalid JSON / missing file,
|
|
151
|
+
array-content rewriting). Package test count: 108 → 141.
|
|
152
|
+
|
|
153
|
+
Docs: `docs/component-blocks.md` adds a "Migrating stored content"
|
|
154
|
+
section with the auto-applied vs flagged matrix, programmatic API
|
|
155
|
+
examples, and updated known-limits. Removes the "no migrate CLI yet"
|
|
156
|
+
note from the previous slice.
|
|
157
|
+
|
|
158
|
+
- 12e042c: Phase 4, PR #4 — discriminated-union picker + marketing-grade docs.
|
|
159
|
+
Closes Phase 4 of the competitive gaps roadmap.
|
|
160
|
+
|
|
161
|
+
The headline UX win: a `union` PropType whose variants share a single
|
|
162
|
+
required literal field (the discriminator) no longer falls through
|
|
163
|
+
to the JSON textarea. The admin form renders a variant `<select>` and
|
|
164
|
+
a recursive object form for the chosen variant's remaining fields,
|
|
165
|
+
keyed automatically off the TypeScript shape — no manifest
|
|
166
|
+
annotation, no schema language, no configuration.
|
|
167
|
+
|
|
168
|
+
**New `@actuate-media/component-blocks` exports:**
|
|
169
|
+
- `detectDiscriminator(propType)` — pure function. Inspects a union
|
|
170
|
+
PropType; returns `{ field, kind, variants[] }` when every variant
|
|
171
|
+
is an object sharing a required-literal field with distinct values,
|
|
172
|
+
or `null` otherwise. The rule is strict by design — a half-
|
|
173
|
+
discriminated union would silently accept invalid states.
|
|
174
|
+
- `findVariant(value, detected)` — locate the variant whose
|
|
175
|
+
discriminator value matches a stored value. Used by the form to
|
|
176
|
+
keep the picker in sync, and by the validator + future migrator to
|
|
177
|
+
route checks into the correct variant's schema.
|
|
178
|
+
- New types: `DiscriminatedUnion`, `DiscriminatedVariant`,
|
|
179
|
+
`DiscriminatorValue`.
|
|
180
|
+
|
|
181
|
+
**`@actuate-media/cms-admin` updates:**
|
|
182
|
+
- `<PropInput>` `union` branch now calls `detectDiscriminator` first;
|
|
183
|
+
on a hit it renders the new `DiscriminatedUnionInput` (variant
|
|
184
|
+
picker + recursive object form for the chosen variant's remaining
|
|
185
|
+
fields). Non-discriminated unions still fall back to the JSON
|
|
186
|
+
textarea with a clearer hint.
|
|
187
|
+
- Variant switching preserves fields that exist on both variants
|
|
188
|
+
(so `{ kind: 'link', label: 'Go' }` → `{ kind: 'modal', label: 'Go',
|
|
189
|
+
modalId: '' }` keeps the label), drops variant-exclusive fields,
|
|
190
|
+
and seeds new required fields from their declared defaults.
|
|
191
|
+
- `defaultForType` now returns a structural default for discriminated
|
|
192
|
+
unions (first variant + its required field defaults). A required
|
|
193
|
+
discriminated-union prop arrives on screen as a fully-editable form
|
|
194
|
+
rather than a `Missing required prop` error.
|
|
195
|
+
- `seedPropsForComponent` carries that forward — required
|
|
196
|
+
discriminated-union props seed cleanly; non-discriminated unions
|
|
197
|
+
/ references / unknowns still stay absent so the validator's
|
|
198
|
+
message and the data state agree honestly.
|
|
199
|
+
- `clientShapeError` routes discriminated-union values into the
|
|
200
|
+
matching variant's schema. New error messages: `cta.kind must be
|
|
201
|
+
one of: "link", "modal"`, `cta.modalId is required but missing`,
|
|
202
|
+
`cta must be an object with a 'kind' discriminator`. Same
|
|
203
|
+
precision as plain object props.
|
|
204
|
+
|
|
205
|
+
**Example component upgraded:**
|
|
206
|
+
- `examples/Hero.tsx` now ships a discriminated `cta` prop
|
|
207
|
+
(`{ kind: 'link', href, label } | { kind: 'modal', modalId, label }`).
|
|
208
|
+
The `/component-blocks-demo` live playground doubles as the
|
|
209
|
+
marketing artifact and exercise the picker end-to-end.
|
|
210
|
+
|
|
211
|
+
**Docs:**
|
|
212
|
+
- New `docs/component-blocks-intro.md` — marketing-grade landing page
|
|
213
|
+
with the comparison matrix vs schema-first CMSs and a 60-second
|
|
214
|
+
hands-on tour. The technical reference doc links to it from the top.
|
|
215
|
+
- `docs/component-blocks.md` gains a dedicated "Discriminated-union
|
|
216
|
+
picker" section covering the detection rule + programmatic API.
|
|
217
|
+
Known limits refreshed; "variant picker ships in PR #4" notes
|
|
218
|
+
removed.
|
|
219
|
+
- `docs/roadmap-status.md` marks Phase 4 as feature-complete /
|
|
220
|
+
in-review.
|
|
221
|
+
|
|
222
|
+
**Tests:** 18 new unit tests in `discriminated-union.test.ts`
|
|
223
|
+
(positive + negative cases for the detector, `findVariant` matching);
|
|
224
|
+
7 new helper tests covering `defaultForType` / `seedPropsForComponent`
|
|
225
|
+
/ `clientShapeError` for discriminated unions; existing extractor
|
|
226
|
+
test updated to assert the new Hero CTA shape via the public detector.
|
|
227
|
+
Workspace test counts: component-blocks 141 → 159, cms-admin 82 → 89.
|
|
228
|
+
|
|
229
|
+
This PR closes Phase 4. The next session can start fresh on
|
|
230
|
+
Phase 3 (real-time collaboration) or Phase 6 (importers).
|
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Actuate Media
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
# @prenta/component-blocks
|
|
2
|
+
|
|
3
|
+
Turn your real React components into typed CMS blocks. This is the first slice of Prenta's "component-aware blocks" — a feature no other headless CMS does well.
|
|
4
|
+
|
|
5
|
+
## What it does
|
|
6
|
+
|
|
7
|
+
You point this package at a directory of React components, it reads their TypeScript prop types, and emits a JSON manifest. The Prenta CMS uses that manifest to render the right admin form for each component, validate stored content against the real prop shape, and warn you when a content document references a component prop that no longer exists.
|
|
8
|
+
|
|
9
|
+
## Install
|
|
10
|
+
|
|
11
|
+
```bash
|
|
12
|
+
pnpm add -D @prenta/component-blocks
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
## Usage
|
|
16
|
+
|
|
17
|
+
### Programmatic
|
|
18
|
+
|
|
19
|
+
```ts
|
|
20
|
+
import { extractManifest } from '@prenta/component-blocks'
|
|
21
|
+
|
|
22
|
+
const manifest = extractManifest({
|
|
23
|
+
rootDir: './src/blocks',
|
|
24
|
+
filePattern: '**/*.tsx',
|
|
25
|
+
})
|
|
26
|
+
|
|
27
|
+
console.log(manifest.components.map((c) => c.name))
|
|
28
|
+
// → ['Hero', 'FeatureGrid', 'Testimonial']
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
### CLI
|
|
32
|
+
|
|
33
|
+
```bash
|
|
34
|
+
npx prenta-component-blocks extract \
|
|
35
|
+
--root ./src/blocks \
|
|
36
|
+
--out ./prenta-blocks.json
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
### Wire up the CMS field
|
|
40
|
+
|
|
41
|
+
In your `prenta.config.ts`:
|
|
42
|
+
|
|
43
|
+
```ts
|
|
44
|
+
import manifest from './prenta-blocks.json' assert { type: 'json' }
|
|
45
|
+
|
|
46
|
+
export default {
|
|
47
|
+
collections: {
|
|
48
|
+
pages: {
|
|
49
|
+
fields: {
|
|
50
|
+
body: {
|
|
51
|
+
type: 'componentBlock',
|
|
52
|
+
label: 'Page content',
|
|
53
|
+
manifest,
|
|
54
|
+
// Optional: restrict which components editors can pick
|
|
55
|
+
allow: ['Hero', 'FeatureGrid'],
|
|
56
|
+
},
|
|
57
|
+
},
|
|
58
|
+
},
|
|
59
|
+
},
|
|
60
|
+
}
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
## What gets extracted
|
|
64
|
+
|
|
65
|
+
| TypeScript type | Extracted `PropType.kind` |
|
|
66
|
+
| ----------------------------------------- | ------------------------------------------- |
|
|
67
|
+
| `string` / `number` / `boolean` | `string` / `number` / `boolean` |
|
|
68
|
+
| `"left" \| "right"` | `enum` with the literal values |
|
|
69
|
+
| `1 \| 2 \| 3` | `enum` with the literal values |
|
|
70
|
+
| `string \| number` | `union` of sub-types |
|
|
71
|
+
| `{ label: string }` (inline) | `object` with the nested fields |
|
|
72
|
+
| `string[]` / `Array<string>` | `array` with its `itemType` |
|
|
73
|
+
| Same-file `interface X { ... }` reference | Resolved to the inline shape |
|
|
74
|
+
| Cross-file imports, `ReactNode`, etc. | `reference` with `targetType: '<the name>'` |
|
|
75
|
+
| Anything the scanner can't classify | `unknown` |
|
|
76
|
+
|
|
77
|
+
The component's `displayName` comes from the component identifier (or `react-docgen-typescript`'s detected display name). JSDoc on the component populates `description`; JSDoc on individual props populates each prop's `description`. Destructuring defaults (e.g. `{ alignment = 'center' }`) are captured as `defaultValue`.
|
|
78
|
+
|
|
79
|
+
## What's next
|
|
80
|
+
|
|
81
|
+
This package ships the **foundation**. The forthcoming slices add:
|
|
82
|
+
|
|
83
|
+
- An admin form generator that renders the right input per `PropType`
|
|
84
|
+
- A CLI diff tool that flags incompatible prop changes between manifests
|
|
85
|
+
- Live-preview rendering of the selected block right inside the editor
|
|
86
|
+
- Discriminated-union and migration-prompt support
|
|
87
|
+
|
|
88
|
+
See `docs/component-blocks.md` for the design and `docs/roadmap-status.md` for the full Phase 4 plan.
|
package/dist/cli.d.ts
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
/**
|
|
3
|
+
* `prenta-component-blocks` — CLI for the extractor + diff + migrate.
|
|
4
|
+
*
|
|
5
|
+
* Usage:
|
|
6
|
+
* prenta-component-blocks extract \
|
|
7
|
+
* --root ./src/blocks \
|
|
8
|
+
* --out ./prenta-blocks.json \
|
|
9
|
+
* [--pattern '**\/*.tsx']
|
|
10
|
+
*
|
|
11
|
+
* prenta-component-blocks diff <old-manifest> <new-manifest> [--json]
|
|
12
|
+
*
|
|
13
|
+
* prenta-component-blocks migrate <old-manifest> <new-manifest> <content> \
|
|
14
|
+
* [--write] [--out <path>] [--json]
|
|
15
|
+
*
|
|
16
|
+
* Exit codes:
|
|
17
|
+
* 0 success (extract / clean diff / migration applied or dry-run with no issues)
|
|
18
|
+
* 1 user error (missing flag, file not found, etc.)
|
|
19
|
+
* 2 diff: breaking changes detected; migrate: unresolved issues found
|
|
20
|
+
*
|
|
21
|
+
* Kept deliberately small — no extra dependency on a CLI framework.
|
|
22
|
+
*/
|
|
23
|
+
export declare function runCli(argv?: string[]): number;
|
|
24
|
+
//# sourceMappingURL=cli.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cli.d.ts","sourceRoot":"","sources":["../src/cli.ts"],"names":[],"mappings":";AACA;;;;;;;;;;;;;;;;;;;;GAoBG;AA4HH,wBAAgB,MAAM,CAAC,IAAI,GAAE,MAAM,EAA0B,GAAG,MAAM,CAgDrE"}
|