form-page-builder 0.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.
- package/LICENSE +21 -0
- package/README.md +107 -0
- package/dist/index.cjs +2395 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +534 -0
- package/dist/index.d.ts +534 -0
- package/dist/index.js +2402 -0
- package/dist/index.js.map +1 -0
- package/package.json +73 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 MainSolutionCoLtd
|
|
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,107 @@
|
|
|
1
|
+
# form-page-builder
|
|
2
|
+
|
|
3
|
+
[](https://www.npmjs.com/package/form-page-builder)
|
|
4
|
+
[](https://github.com/MainSolutionCoLtd/form-page-builder/actions/workflows/ci.yml)
|
|
5
|
+
[](./LICENSE)
|
|
6
|
+
|
|
7
|
+
**[Live demo](https://mainsolutioncoltd.github.io/form-page-builder/)**
|
|
8
|
+
|
|
9
|
+
Embeddable, bilingual (EN/JA by default, extensible), drag-and-drop form builder widget for React. Ships a single `<FormBuilder />` component with a Build mode (drag/drop canvas, field inspector) and a Preview mode (responsive, validating runtime form), plus a JSON export of the resulting document.
|
|
10
|
+
|
|
11
|
+
**This is a builder + viewer, not a data handler.** It builds and previews a JSON *schema* describing a form's fields, sections, and layout blocks (including plain content blocks like paragraphs and images, not just inputs). It never receives or stores real end-user submissions — Preview mode's "Submit" just shows a mock "here's what would be sent to your backend" modal. The only thing this package persists on its own is the *builder's own* draft/library state (via the pluggable `StorageAdapter` below); wiring actual form submissions to a backend is up to the host app.
|
|
12
|
+
|
|
13
|
+
## Install
|
|
14
|
+
|
|
15
|
+
```bash
|
|
16
|
+
npm install form-page-builder
|
|
17
|
+
# or, from a private GitHub repo:
|
|
18
|
+
npm install git+ssh://git@github.com/yourorg/form-page-builder.git
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
`react` and `react-dom` (>=18) are peer dependencies — install them in the consuming app if not already present.
|
|
22
|
+
|
|
23
|
+
## Usage (React / Next.js)
|
|
24
|
+
|
|
25
|
+
```tsx
|
|
26
|
+
import { FormBuilder } from "form-page-builder";
|
|
27
|
+
|
|
28
|
+
export default function BuilderPage() {
|
|
29
|
+
return <FormBuilder />;
|
|
30
|
+
}
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
In Next.js App Router, the package's entry already carries a `"use client"` directive, so it can be imported directly from a Server Component tree without you adding the directive yourself.
|
|
34
|
+
|
|
35
|
+
### Props
|
|
36
|
+
|
|
37
|
+
| Prop | Type | Description |
|
|
38
|
+
|---|---|---|
|
|
39
|
+
| `theme` | `Partial<Theme>` | Override default colors/layout spacing. |
|
|
40
|
+
| `themeEditable` | `boolean` | Show an in-app theme/spacing editor popover in the toolbar. |
|
|
41
|
+
| `language` | `string` | Initial builder language (defaults to the first entry in `languages`). |
|
|
42
|
+
| `languages` | `{ code: string; label: string }[]` | Language switcher options (default: EN/JA). |
|
|
43
|
+
| `strings` | partial override of runtime/validation strings, keyed by language code | |
|
|
44
|
+
| `chrome` | partial override of builder-UI strings, keyed by language code | |
|
|
45
|
+
| `storage` | `StorageAdapter` | Pluggable persistence backend for the builder's own draft/library — see below. |
|
|
46
|
+
|
|
47
|
+
### Persistence: `StorageAdapter`
|
|
48
|
+
|
|
49
|
+
By default the component autosaves a draft and a "saved forms" library to `window.localStorage`. To persist the builder's state to your own backend (a Next.js API route, a PHP endpoint, etc.) instead — for example to share drafts across devices — implement and pass a `StorageAdapter`:
|
|
50
|
+
|
|
51
|
+
```ts
|
|
52
|
+
interface StorageAdapter {
|
|
53
|
+
get(key: string): Promise<string | null>;
|
|
54
|
+
set(key: string, value: string): Promise<void>;
|
|
55
|
+
delete(key: string): Promise<void>;
|
|
56
|
+
}
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
```tsx
|
|
60
|
+
import { FormBuilder, type StorageAdapter } from "form-page-builder";
|
|
61
|
+
|
|
62
|
+
const apiStorage: StorageAdapter = {
|
|
63
|
+
async get(key) {
|
|
64
|
+
const res = await fetch(`/api/form-page-builder/${encodeURIComponent(key)}`);
|
|
65
|
+
if (!res.ok) return null;
|
|
66
|
+
return (await res.json()).value ?? null;
|
|
67
|
+
},
|
|
68
|
+
async set(key, value) {
|
|
69
|
+
await fetch(`/api/form-page-builder/${encodeURIComponent(key)}`, {
|
|
70
|
+
method: "PUT",
|
|
71
|
+
body: value,
|
|
72
|
+
});
|
|
73
|
+
},
|
|
74
|
+
async delete(key) {
|
|
75
|
+
await fetch(`/api/form-page-builder/${encodeURIComponent(key)}`, { method: "DELETE" });
|
|
76
|
+
},
|
|
77
|
+
};
|
|
78
|
+
|
|
79
|
+
<FormBuilder storage={apiStorage} />;
|
|
80
|
+
```
|
|
81
|
+
|
|
82
|
+
This is separate from — and unrelated to — however you choose to handle real end-user form submissions in your own app; this package doesn't send or receive those.
|
|
83
|
+
|
|
84
|
+
## Using this in a PHP app
|
|
85
|
+
|
|
86
|
+
There's no build target for raw PHP output — a React component tree still needs a JS bundler (Vite, Laravel Mix, Webpack Encore, `@wordpress/scripts`, etc.) to resolve `react`/`react-dom`/`lucide-react` and mount into a DOM node. If your PHP app already runs one of those pipelines (e.g. a Laravel + Vite or WordPress block setup), install this package the same way you would in Next.js, mount `<FormBuilder />` into a container element, and pass a `storage` adapter that calls your PHP API endpoints. There is intentionally no UMD/IIFE global-script build, since bundling React itself would risk duplicate React instances on pages that already load their own.
|
|
87
|
+
|
|
88
|
+
## Local development
|
|
89
|
+
|
|
90
|
+
```bash
|
|
91
|
+
npm install
|
|
92
|
+
npm run dev # Vite dev harness at http://localhost:5173, imports FormBuilder from src/
|
|
93
|
+
npm run typecheck
|
|
94
|
+
npm run build # tsup -> dist/ (ESM + CJS + .d.ts), the published package
|
|
95
|
+
npm run build:demo # vite build -> pages-dist/, the GitHub Pages demo site
|
|
96
|
+
```
|
|
97
|
+
|
|
98
|
+
## Releasing
|
|
99
|
+
|
|
100
|
+
Versioning and the changelog are managed by [Changesets](https://github.com/changesets/changesets); publishing to npm is a separate, deliberate step.
|
|
101
|
+
|
|
102
|
+
1. On your PR, describe the change for consumers: `npx changeset` (pick patch/minor/major, write a summary, commit the generated file in `.changeset/`).
|
|
103
|
+
2. Once merged to `main`, a bot opens/updates a **"Version Packages"** PR that bumps `package.json` and writes `CHANGELOG.md` from the accumulated changesets ([.github/workflows/version.yml](.github/workflows/version.yml)).
|
|
104
|
+
3. Merge that PR when you're ready to ship.
|
|
105
|
+
4. Cut a [GitHub Release](https://github.com/MainSolutionCoLtd/form-page-builder/releases/new) tagged `vX.Y.Z` matching the new version — this triggers [.github/workflows/release.yml](.github/workflows/release.yml), which builds and runs `npm publish` (requires the `NPM_TOKEN` repo secret).
|
|
106
|
+
|
|
107
|
+
Pushes to `main` also rebuild and redeploy the [live demo](https://mainsolutioncoltd.github.io/form-page-builder/) via [.github/workflows/pages.yml](.github/workflows/pages.yml).
|