@techrox/page-studio-form 1.0.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/LICENSE +21 -0
- package/README.md +145 -0
- package/dist/index.cjs +2723 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.js +2792 -0
- package/dist/index.js.map +1 -0
- package/package.json +118 -0
- package/src/styles.css +20 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2024 techrox
|
|
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,145 @@
|
|
|
1
|
+
# @techrox/page-studio-form
|
|
2
|
+
|
|
3
|
+
Schema-driven structured-form page editor for admin CMS UIs. Companion to
|
|
4
|
+
[`@techrox/page-studio`](../editor) (the Puck visual builder). Both packages
|
|
5
|
+
edit the same page record; they differ in surface area:
|
|
6
|
+
|
|
7
|
+
- **page-studio** — drag-and-drop visual builder, for marketing pages where
|
|
8
|
+
block layout matters.
|
|
9
|
+
- **page-studio-form** — typed fields per page key (hero, summary, deliverables,
|
|
10
|
+
pricing rows…), for content-shaped pages where layout is fixed and only the
|
|
11
|
+
copy changes.
|
|
12
|
+
|
|
13
|
+
## What you get
|
|
14
|
+
|
|
15
|
+
- `<PageStudioForm />` — full admin shell: title, publish toggle, tabbed
|
|
16
|
+
content / SEO / preview / history panes.
|
|
17
|
+
- `<RichText />` — Notion-style WYSIWYG with toolbar, bubble menu, table
|
|
18
|
+
editing, callouts, columns, image upload.
|
|
19
|
+
- `<HistoryPanel />` — revision viewer with side-by-side diff + one-click
|
|
20
|
+
restore.
|
|
21
|
+
|
|
22
|
+
## Install
|
|
23
|
+
|
|
24
|
+
```bash
|
|
25
|
+
npm i @techrox/page-studio-form antd @ant-design/icons \
|
|
26
|
+
@tiptap/react @tiptap/starter-kit @tiptap/extension-underline \
|
|
27
|
+
@tiptap/extension-link @tiptap/extension-placeholder \
|
|
28
|
+
@tiptap/extension-text-align @tiptap/extension-text-style \
|
|
29
|
+
@tiptap/extension-color @tiptap/extension-highlight \
|
|
30
|
+
@tiptap/extension-table @tiptap/extension-table-row \
|
|
31
|
+
@tiptap/extension-task-list @tiptap/extension-task-item \
|
|
32
|
+
@tiptap/extension-character-count @tiptap/extension-typography \
|
|
33
|
+
@dnd-kit/core @dnd-kit/sortable @dnd-kit/utilities \
|
|
34
|
+
diff dayjs
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
Then import the styles once at the app root:
|
|
38
|
+
|
|
39
|
+
```js
|
|
40
|
+
import '@techrox/page-studio-form/styles.css';
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
## Usage
|
|
44
|
+
|
|
45
|
+
```jsx
|
|
46
|
+
import { PageStudioForm } from '@techrox/page-studio-form';
|
|
47
|
+
import NextLink from 'next/link';
|
|
48
|
+
import { useRouter } from 'next/navigation';
|
|
49
|
+
|
|
50
|
+
import {
|
|
51
|
+
savePage,
|
|
52
|
+
deletePage,
|
|
53
|
+
listRevisions,
|
|
54
|
+
restoreRevision,
|
|
55
|
+
uploadMedia,
|
|
56
|
+
} from '@/lib/admin-api';
|
|
57
|
+
import { getSchema, getContentDefaults } from '@/lib/page-schemas';
|
|
58
|
+
|
|
59
|
+
export default function EditorPage({ pageKey, initialPage }) {
|
|
60
|
+
const router = useRouter();
|
|
61
|
+
return (
|
|
62
|
+
<PageStudioForm
|
|
63
|
+
pageKey={pageKey}
|
|
64
|
+
initialPage={initialPage}
|
|
65
|
+
schema={getSchema(pageKey)}
|
|
66
|
+
contentDefaults={getContentDefaults(pageKey)}
|
|
67
|
+
livePath={`/pages/${pageKey}`}
|
|
68
|
+
homeHref="/admin/pages"
|
|
69
|
+
LinkComponent={NextLink}
|
|
70
|
+
adapter={{
|
|
71
|
+
savePage: (key, payload) => savePage(key, payload),
|
|
72
|
+
deletePage: (key) => deletePage(key),
|
|
73
|
+
loadHistory: (key) => listRevisions(key),
|
|
74
|
+
restoreRevision: (key, revId) => restoreRevision(key, revId),
|
|
75
|
+
uploadMedia: (formData) => uploadMedia(formData),
|
|
76
|
+
}}
|
|
77
|
+
onSaved={() => router.refresh()}
|
|
78
|
+
onDeleted={() => router.replace('/admin/pages')}
|
|
79
|
+
onRestored={() => router.refresh()}
|
|
80
|
+
/>
|
|
81
|
+
);
|
|
82
|
+
}
|
|
83
|
+
```
|
|
84
|
+
|
|
85
|
+
## Adapter contract
|
|
86
|
+
|
|
87
|
+
| Method | Signature | When called |
|
|
88
|
+
|---|---|---|
|
|
89
|
+
| `savePage` | `(key, payload) => Promise<{ page }>` | User clicks Save. `payload` has `{ title, seo, content, published }`. |
|
|
90
|
+
| `deletePage` | `(key) => Promise<void>` | User confirms "Remove override". |
|
|
91
|
+
| `loadHistory` | `(key) => Promise<{ revisions }>` | History tab mounts or user clicks Reload. |
|
|
92
|
+
| `restoreRevision` | `(key, revisionId) => Promise<void>` | User confirms Restore on a revision. |
|
|
93
|
+
| `uploadMedia` | `(FormData) => Promise<{ url }>` | RichText image upload / paste / drop. |
|
|
94
|
+
|
|
95
|
+
All adapter methods may throw; errors surface to the user via the AntD
|
|
96
|
+
`message` API. The package never reads cookies, talks to a router, or
|
|
97
|
+
performs side effects beyond rendering. Wiring those is the host's job
|
|
98
|
+
(via `onSaved` / `onDeleted` / `onRestored`).
|
|
99
|
+
|
|
100
|
+
## Schema shape
|
|
101
|
+
|
|
102
|
+
The `schema` prop is a flat array of `{ title, help?, fields[] }` sections.
|
|
103
|
+
Each `field` is one of:
|
|
104
|
+
|
|
105
|
+
| `type` | Renders | Notes |
|
|
106
|
+
|---|---|---|
|
|
107
|
+
| `text` | `<Input>` | Single line |
|
|
108
|
+
| `textarea` / `html-text` | `<TextArea>` | Multiline plain text |
|
|
109
|
+
| `richtext` | `<RichText>` | TipTap WYSIWYG; emits HTML |
|
|
110
|
+
| `list` | `<TextArea>` → string[] | One entry per line |
|
|
111
|
+
| `list-csv` | `<Input>` → string[] | Comma-separated |
|
|
112
|
+
| `repeater` | `<Form.List>` | Drag-sortable; `itemFields[]` recurses |
|
|
113
|
+
|
|
114
|
+
The host owns the schema registry — typically a `getSchema(pageKey)` map
|
|
115
|
+
keyed by page identifier.
|
|
116
|
+
|
|
117
|
+
## Branding
|
|
118
|
+
|
|
119
|
+
The form inherits the `--tps-*` CSS variables from the host. Override on
|
|
120
|
+
`:root` (or any parent) to retheme without touching package internals:
|
|
121
|
+
|
|
122
|
+
```css
|
|
123
|
+
:root {
|
|
124
|
+
--tps-primary: #6366F1;
|
|
125
|
+
--tps-accent: #EC4899;
|
|
126
|
+
--tps-bg-soft: #F1F5F9;
|
|
127
|
+
}
|
|
128
|
+
```
|
|
129
|
+
|
|
130
|
+
## Standalone components
|
|
131
|
+
|
|
132
|
+
`<RichText />` and `<HistoryPanel />` are exported separately if you only
|
|
133
|
+
need one piece:
|
|
134
|
+
|
|
135
|
+
```jsx
|
|
136
|
+
import { RichText, HistoryPanel } from '@techrox/page-studio-form';
|
|
137
|
+
|
|
138
|
+
<RichText value={html} onChange={setHtml} uploadMedia={uploadFn} />
|
|
139
|
+
```
|
|
140
|
+
|
|
141
|
+
## Companion packages
|
|
142
|
+
|
|
143
|
+
- **[@techrox/page-studio](../editor)** — drag-and-drop visual builder
|
|
144
|
+
- **[@techrox/page-studio-blocks](../blocks)** — the 50 blocks the builder ships with
|
|
145
|
+
- **[@techrox/page-studio-renderer](../renderer)** — public-page renderer for builder output
|