grapesjs-forms 0.0.0-stage → 0.1.1

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.
@@ -0,0 +1,69 @@
1
+ import type { FormDef, SubmissionData } from '../schema';
2
+ /** What a form write sends. */
3
+ export interface FormWrite {
4
+ id: string;
5
+ name: string;
6
+ fields: FormDef['fields'];
7
+ settings: FormDef['settings'];
8
+ attrs?: FormDef['attrs'];
9
+ }
10
+ /** What the site sends with the values. */
11
+ export interface SubmissionMeta {
12
+ /** The page address the form was sent from. */
13
+ url?: string;
14
+ referrer?: string;
15
+ /** grapesjs-pages record id of the page, when known. */
16
+ pageId?: string;
17
+ lang?: string;
18
+ [key: string]: unknown;
19
+ }
20
+ export interface Submission {
21
+ id: string;
22
+ formId: string;
23
+ data: SubmissionData;
24
+ meta?: SubmissionMeta;
25
+ createdAt: string;
26
+ }
27
+ /** What the backend answers to a submit. A server may send its own message or a redirect. */
28
+ export interface SubmitResult {
29
+ id?: string;
30
+ createdAt?: string;
31
+ message?: string;
32
+ redirect?: string;
33
+ }
34
+ export interface SubmissionPage {
35
+ items: Submission[];
36
+ total: number;
37
+ }
38
+ /** A write that hit a newer version (HTTP 412). */
39
+ export declare class ConflictError extends Error {
40
+ readonly status = 412;
41
+ constructor(message?: string);
42
+ }
43
+ /** A request the backend refused (validation: 422 with `errors` per field). */
44
+ export declare class StoreError extends Error {
45
+ readonly status: number;
46
+ /** `{ email: ['email'], name: ['required'] }` */
47
+ readonly errors: Record<string, string[]>;
48
+ constructor(message: string, status: number,
49
+ /** `{ email: ['email'], name: ['required'] }` */
50
+ errors?: Record<string, string[]>);
51
+ }
52
+ /**
53
+ * Where forms and their submissions live. Versions are opaque: a write with
54
+ * `ifVersion` fails with `ConflictError` when the form moved on.
55
+ */
56
+ export interface FormStore {
57
+ listForms(): Promise<FormDef[]>;
58
+ getForm(id: string): Promise<FormDef | undefined>;
59
+ saveForm(form: FormWrite, ifVersion?: string | number | null): Promise<FormDef>;
60
+ deleteForm(id: string): Promise<void>;
61
+ /** What the site does: sends one submission. Refuses invalid data with `StoreError` 422. */
62
+ submit(formId: string, data: SubmissionData, meta?: SubmissionMeta): Promise<SubmitResult>;
63
+ /** Newest first. */
64
+ listSubmissions?(formId: string, page?: {
65
+ limit?: number;
66
+ offset?: number;
67
+ }): Promise<SubmissionPage>;
68
+ deleteSubmission?(formId: string, id: string): Promise<void>;
69
+ }
@@ -0,0 +1,19 @@
1
+ import { type FormDef } from './schema';
2
+ /**
3
+ * SurveyJS JSON (survey-library / Survey Creator) in and out, for the parts
4
+ * that are plain forms: text inputs of every `inputType`, comment, dropdown,
5
+ * tagbox, radiogroup, checkbox, boolean, rating, file, html; panels and
6
+ * pages are flattened. Logic (visibleIf, expressions, matrices…) has no
7
+ * place in a plain HTML form: such questions are listed in `skipped`.
8
+ */
9
+ export interface SurveyImport {
10
+ form: FormDef;
11
+ /** `name (type)` of questions left out. */
12
+ skipped: string[];
13
+ }
14
+ type Json = Record<string, any>;
15
+ /** A SurveyJS survey as a form (an id is given by the caller). */
16
+ export declare function fromSurveyJs(json: Json, id?: string): SurveyImport;
17
+ /** A form as a SurveyJS survey (one page). Hidden fields become invisible text questions. */
18
+ export declare function toSurveyJs(form: FormDef): Json;
19
+ export {};
@@ -0,0 +1,79 @@
1
+ import type { BuildOptions } from './build';
2
+ import type { FormsLabels } from './i18n/types';
3
+ import type { FormDef, FormField, FormSettings, SubmissionData } from './schema';
4
+ import type { RestOptions } from './store/RestFormStore';
5
+ import type { FormStore, SubmissionMeta, SubmitResult } from './store/types';
6
+ import type { SurveyImport } from './surveyjs';
7
+ export interface FormsOptions {
8
+ /** Your own backend (wins over `rest`). */
9
+ store?: FormStore | null;
10
+ /** A server of openapi.yaml: forms and submissions. `null` — IndexedDB in the browser. */
11
+ rest?: RestOptions | null;
12
+ /**
13
+ * Base URL the published site posts to (`<submitUrl>/forms/<id>/submissions`).
14
+ * Default: `rest.url`. A form's own `settings.endpoint` wins.
15
+ */
16
+ submitUrl?: string | null;
17
+ /** IndexedDB database of the local store. */
18
+ dbName?: string;
19
+ /** Delay before an edit is saved, ms. */
20
+ autosaveDelay?: number;
21
+ /** Blocks of the forms (one per form + "New form"). */
22
+ blocks?: boolean;
23
+ /** Adds a small base stylesheet for forms to the project CSS once (it inherits the site's fonts and colours; restyle it freely). */
24
+ baseCss?: boolean;
25
+ /** Panel of the "Forms" button (`options` of the core layout); `null`/empty — auto. */
26
+ panelId?: string | null;
27
+ /** Texts (any key of the labels). */
28
+ labels?: Partial<FormsLabels>;
29
+ /** The plugin's own UI styles. */
30
+ injectCss?: boolean;
31
+ }
32
+ export interface ResolvedOptions {
33
+ store: FormStore | null;
34
+ rest: RestOptions | null;
35
+ submitUrl: string | null;
36
+ dbName: string;
37
+ autosaveDelay: number;
38
+ blocks: boolean;
39
+ baseCss: boolean;
40
+ panelId: string | null;
41
+ labels: Partial<FormsLabels>;
42
+ injectCss: boolean;
43
+ }
44
+ export interface FormInit {
45
+ id?: string;
46
+ name?: string;
47
+ fields?: Array<Partial<FormField>>;
48
+ settings?: FormSettings;
49
+ attrs?: Record<string, string>;
50
+ }
51
+ /** `editor.Forms` */
52
+ export interface FormsApi {
53
+ store: FormStore;
54
+ /** The forms (cached, sorted by name). */
55
+ list(): FormDef[];
56
+ get(id: string): FormDef | undefined;
57
+ reload(): Promise<FormDef[]>;
58
+ /** Creates a form (default fields: name, e-mail, message — unless `fields` is given). */
59
+ create(init?: FormInit): Promise<FormDef>;
60
+ /** Changes a form and saves it (debounced writes are flushed first). */
61
+ update(id: string, patch: Partial<Omit<FormDef, 'id' | 'version' | 'updatedAt'>>): Promise<FormDef>;
62
+ remove(id: string): Promise<void>;
63
+ duplicate(id: string): Promise<FormDef>;
64
+ /** Opens the forms editor (on a form). */
65
+ open(id?: string): void;
66
+ close(): void;
67
+ /** Where a form posts on the site ('' — no endpoint: the site handles `gjsf:submit`). */
68
+ actionOf(form: FormDef | string): string;
69
+ /** The form as HTML (for servers, e-mails, sites without GrapesJS; `enhanceForms()` turns it on). */
70
+ html(id: string, opts?: BuildOptions): string;
71
+ /** Sends a submission through the store (what the preview does). */
72
+ submit(id: string, data: SubmissionData, meta?: SubmissionMeta): Promise<SubmitResult>;
73
+ /** Rebuilds the components of a form (all when no id) in the open project. */
74
+ rebuild(id?: string): number;
75
+ importSurveyJs(json: Record<string, unknown>, into?: string): Promise<SurveyImport>;
76
+ exportSurveyJs(id: string): Record<string, unknown>;
77
+ /** Writes pending edits. */
78
+ flush(): Promise<void>;
79
+ }
@@ -0,0 +1,86 @@
1
+ import type { Translator } from '../i18n';
2
+ import { type FormDef, type SubmissionData } from '../schema';
3
+ import type { SubmissionMeta, SubmissionPage, SubmitResult } from '../store/types';
4
+ export interface EditorDeps {
5
+ t: Translator;
6
+ forms(): FormDef[];
7
+ form(id: string): FormDef | undefined;
8
+ create(): Promise<FormDef>;
9
+ duplicate(id: string): Promise<FormDef>;
10
+ remove(id: string): Promise<void>;
11
+ /** The whole edited form: kept at once, saved after a pause. */
12
+ change(form: FormDef): void;
13
+ /** Where the form posts by default (the endpoint hint). */
14
+ defaultAction(form: FormDef): string;
15
+ previewHtml(form: FormDef): string;
16
+ previewStyles(): {
17
+ css: string;
18
+ links: string[];
19
+ };
20
+ submit(id: string, data: SubmissionData, meta?: SubmissionMeta): Promise<SubmitResult>;
21
+ /** `null` — the store does not list submissions. */
22
+ submissions(id: string, page: {
23
+ limit: number;
24
+ offset: number;
25
+ }): Promise<SubmissionPage> | null;
26
+ deleteSubmission(id: string, sid: string): Promise<void>;
27
+ /** Replaces a form by JSON (own or SurveyJS); returns what was left out. */
28
+ applyJson(id: string, json: Record<string, unknown>): Promise<string[]>;
29
+ exportSurveyJs(id: string): Record<string, unknown>;
30
+ onError(e: unknown): void;
31
+ }
32
+ /**
33
+ * The forms editor: a list of forms on the left; for the open one its
34
+ * fields (palette → list → properties), settings, a preview styled like the
35
+ * open page, its submissions, and its JSON (own or SurveyJS).
36
+ */
37
+ export declare class FormEditor {
38
+ private readonly d;
39
+ readonly root: HTMLElement;
40
+ private cur;
41
+ private tab;
42
+ private selField;
43
+ private statusEl;
44
+ private body;
45
+ private listEl;
46
+ private propsEl;
47
+ private sideEl;
48
+ private subs;
49
+ private subsTotal;
50
+ private flashTimer;
51
+ constructor(d: EditorDeps);
52
+ private get t();
53
+ /** Opens on a form (the first when none given). */
54
+ show(id?: string | null): void;
55
+ get currentId(): string | null;
56
+ /** The forms changed elsewhere (a save came back, a reload): the list follows; the open form only when `reload`. */
57
+ setForms(reload?: boolean): void;
58
+ flash(text: string, error?: boolean): void;
59
+ destroy(): void;
60
+ private changed;
61
+ render(): void;
62
+ private renderSide;
63
+ private duplicate;
64
+ private removeForm;
65
+ private renderFields;
66
+ private addField;
67
+ private renderList;
68
+ private act;
69
+ /** The title row of the open field changes as its label / name is typed. */
70
+ private refreshRow;
71
+ /** A labelled input bound to `obj[key]`. */
72
+ private text;
73
+ private check;
74
+ /** Placeholder chips that insert into an input. */
75
+ private chips;
76
+ /** `{ name: value }` rows. */
77
+ private kv;
78
+ private optionsEditor;
79
+ private renderProps;
80
+ private renderSettings;
81
+ private renderPreview;
82
+ private renderSubmissions;
83
+ private renderJson;
84
+ }
85
+ /** RFC 4180 CSV with a BOM (Excel opens UTF-8). */
86
+ export declare function toCsv(head: string[], rows: string[][]): string;
@@ -0,0 +1,12 @@
1
+ type Attrs = Record<string, string | boolean | null | undefined | EventListener>;
2
+ type Child = Node | string | number | null | undefined | false | Child[];
3
+ /**
4
+ * Tiny element factory. Text always goes through text nodes (never
5
+ * innerHTML), `on*` keys become listeners, `false`/`null` attributes are
6
+ * skipped, `class` sets className.
7
+ */
8
+ export declare function h<K extends keyof HTMLElementTagNameMap>(tag: K, attrs?: Attrs, ...kids: Child[]): HTMLElementTagNameMap[K];
9
+ /** "Content" icon (stacked records) of the panel button. */
10
+ export declare function contentIcon(size: number): SVGSVGElement;
11
+ export declare const CONTENT_ICON_HTML: (size: number) => string;
12
+ export {};
@@ -0,0 +1,10 @@
1
+ export declare const STYLE_ID = "gjsf-style";
2
+ /** The editor's own UI (the modal); colours follow the GrapesJS theme variables. */
3
+ export declare const CSS = "\n.gjsf-modal .gjs-mdl-dialog{max-width:1180px;width:96%}\n.gjsf-modal .gjs-mdl-content{padding:0}\n.gjsf-ed{display:flex;height:min(78vh,760px);font-size:13px;text-align:start;font-family:var(--gjs-main-font,Helvetica,sans-serif)}\n.gjsf-ed *{box-sizing:border-box}\n.gjsf-side{width:200px;flex:none;border-inline-end:1px solid rgba(0,0,0,.25);display:flex;flex-direction:column;overflow:auto}\n.gjsf-side-list{list-style:none;margin:0;padding:0;flex:1}\n.gjsf-side-item{padding:8px 12px;cursor:pointer;border-inline-start:3px solid transparent;white-space:nowrap;overflow:hidden;text-overflow:ellipsis}\n.gjsf-side-item:hover{background:rgba(255,255,255,.06)}\n.gjsf-side-item.is-active{border-inline-start-color:var(--gjs-quaternary-color,#d278c9);background:rgba(255,255,255,.08)}\n.gjsf-main{flex:1;min-width:0;display:flex;flex-direction:column}\n.gjsf-head{display:flex;gap:8px;align-items:center;padding:8px 12px;border-bottom:1px solid rgba(0,0,0,.25)}\n.gjsf-head .gjsf-input{flex:1;font-size:15px;font-weight:600}\n.gjsf-status{font-size:11px;opacity:.75;white-space:nowrap}\n.gjsf-status.is-error{color:#ff8a80;opacity:1}\n.gjsf-tabs{display:flex;gap:2px;padding:0 8px;border-bottom:1px solid rgba(0,0,0,.25)}\n.gjsf-tab{background:none;border:0;border-bottom:2px solid transparent;color:inherit;padding:8px 12px;cursor:pointer;font:inherit;opacity:.75}\n.gjsf-tab.is-active{border-bottom-color:var(--gjs-quaternary-color,#d278c9);opacity:1}\n.gjsf-body{flex:1;min-height:0;overflow:auto}\n.gjsf-cols{display:flex;height:100%}\n.gjsf-palette{width:150px;flex:none;padding:8px;border-inline-end:1px solid rgba(0,0,0,.2);overflow:auto}\n.gjsf-palette button{display:flex;gap:6px;align-items:center;width:100%;text-align:start;margin:0 0 3px;padding:5px 8px;background:rgba(255,255,255,.06);border:1px solid rgba(255,255,255,.1);border-radius:3px;color:inherit;cursor:pointer;font:inherit}\n.gjsf-palette button:hover{background:rgba(255,255,255,.14)}\n.gjsf-ico{display:inline-block;width:18px;text-align:center;opacity:.8;font-size:12px}\n.gjsf-list{flex:1;min-width:0;padding:8px;overflow:auto;border-inline-end:1px solid rgba(0,0,0,.2)}\n.gjsf-row{display:flex;gap:6px;align-items:center;padding:6px 8px;margin-bottom:4px;border:1px solid rgba(255,255,255,.12);border-radius:4px;cursor:pointer}\n.gjsf-row:hover{background:rgba(255,255,255,.05)}\n.gjsf-row.is-active{border-color:var(--gjs-quaternary-color,#d278c9);background:rgba(255,255,255,.08)}\n.gjsf-row-main{flex:1;min-width:0}\n.gjsf-row-title{white-space:nowrap;overflow:hidden;text-overflow:ellipsis}\n.gjsf-row-sub{font-size:10px;opacity:.6;font-family:ui-monospace,Menlo,Consolas,monospace}\n.gjsf-row .gjsf-act{visibility:hidden}\n.gjsf-row:hover .gjsf-act,.gjsf-row.is-active .gjsf-act{visibility:visible}\n.gjsf-act{background:none;border:0;color:inherit;cursor:pointer;padding:2px 5px;border-radius:3px;font-size:12px}\n.gjsf-act:hover{background:rgba(255,255,255,.15)}\n.gjsf-act[disabled]{opacity:.3;cursor:default}\n.gjsf-props{width:330px;flex:none;padding:8px 12px;overflow:auto}\n.gjsf-pane{padding:12px;max-width:720px}\n.gjsf-f{display:block;margin:0 0 8px}\n.gjsf-f>span{display:block;font-size:11px;opacity:.85;margin-bottom:2px}\n.gjsf-f small{display:block;font-size:10px;opacity:.6;margin-top:2px}\n.gjsf-grid{display:grid;grid-template-columns:1fr 1fr 1fr;gap:6px}\n.gjsf-grid2{display:grid;grid-template-columns:1fr 1fr;gap:6px}\n.gjsf-input{display:block;width:100%;margin:0;padding:5px 8px;background:rgba(0,0,0,.25);border:1px solid rgba(255,255,255,.2);color:inherit;border-radius:3px;font:inherit}\n.gjsf-input option{color:#222}\ntextarea.gjsf-input{resize:vertical;min-height:54px}\n.gjsf-code{font-family:ui-monospace,Menlo,Consolas,monospace;font-size:12px}\n.gjsf-check{display:flex;align-items:center;gap:6px;margin:0 0 6px;cursor:pointer}\n.gjsf-kv{display:flex;gap:4px;margin-bottom:4px}\n.gjsf-kv .gjsf-input{flex:1;min-width:0}\n.gjsf-sec{margin:12px 0 6px;font-size:10px;font-weight:600;text-transform:uppercase;letter-spacing:.06em;opacity:.7}\n.gjsf-hint{opacity:.7;font-size:12px;margin:4px 0}\n.gjsf-chips{display:flex;flex-wrap:wrap;gap:3px;margin-top:4px}\n.gjsf-chip{background:rgba(255,255,255,.08);border:1px solid rgba(255,255,255,.15);border-radius:10px;padding:1px 7px;font-size:10px;cursor:pointer;color:inherit;font-family:ui-monospace,Menlo,Consolas,monospace}\n.gjsf-chip.is-build{border-style:dashed}\n.gjsf-btn{padding:6px 12px;border-radius:3px;border:0;cursor:pointer;color:inherit;font:inherit;background:rgba(255,255,255,.15)}\n.gjsf-btn:hover{background:rgba(255,255,255,.22)}\n.gjsf-btn.is-primary{background:var(--gjs-quaternary-color,#d278c9)}\n.gjsf-btn.is-danger:hover{background:#c62828}\n.gjsf-bar{display:flex;gap:6px;align-items:center;flex-wrap:wrap;margin:8px 0}\n.gjsf-side .gjsf-btn{margin:8px}\n.gjsf-empty{padding:24px;opacity:.7}\n.gjsf-frame{width:100%;height:calc(100% - 36px);border:0;background:#fff;display:block}\n.gjsf-frame-bar{display:flex;gap:8px;align-items:center;padding:6px 12px;font-size:11px;opacity:.85;height:36px}\n.gjsf-table-wrap{overflow:auto;max-height:100%}\n.gjsf-table{border-collapse:collapse;width:100%;font-size:12px}\n.gjsf-table th,.gjsf-table td{border-bottom:1px solid rgba(255,255,255,.1);padding:5px 8px;text-align:start;vertical-align:top;max-width:280px;overflow-wrap:anywhere}\n.gjsf-table th{position:sticky;top:0;background:var(--gjs-primary-color,#444);font-weight:600}\n.gjsf-err{color:#ff8a80}\n.gjsf-toggle{position:absolute;top:8px;right:96px;z-index:60;background:var(--gjs-primary-color,#444);color:var(--gjs-font-color,#ddd);border:1px solid rgba(255,255,255,.2);border-radius:4px;padding:6px 10px;cursor:pointer}\n";
4
+ export declare function injectCss(doc?: Document): void;
5
+ /**
6
+ * A small base stylesheet of the forms, written into the project CSS once
7
+ * (so it is the site's CSS: exported, editable in the Style Manager). It
8
+ * inherits fonts and colours; the button keeps the site's own button look.
9
+ */
10
+ export declare const BASE_FORM_CSS = "\n.gjsf-form{display:flex;flex-wrap:wrap;gap:16px;position:relative}\n.gjsf-field{flex:1 1 100%;min-width:0;margin:0;padding:0;border:0}\n.gjsf-w-1-2{flex-basis:calc(50% - 8px)}\n.gjsf-w-1-3{flex-basis:calc(33.333% - 11px)}\n.gjsf-w-2-3{flex-basis:calc(66.666% - 6px)}\n.gjsf-w-1-4{flex-basis:calc(25% - 12px)}\n.gjsf-w-3-4{flex-basis:calc(75% - 4px)}\n.gjsf-label{display:block;margin:0 0 6px;padding:0;font-weight:600}\n.gjsf-req{margin-left:2px;color:#c62828}\n.gjsf-input{display:block;width:100%;box-sizing:border-box;padding:10px 12px;font:inherit;color:inherit;background:transparent;border:1px solid rgba(127,127,127,.5);border-radius:4px}\n.gjsf-input:focus{outline:2px solid rgba(127,127,127,.35);outline-offset:1px}\n.gjsf-options{display:flex;flex-direction:column;gap:6px}\n.gjsf-option{display:flex;gap:8px;align-items:center;cursor:pointer;font-weight:400}\n.gjsf-help{margin-top:4px;font-size:.875em;opacity:.75}\n.gjsf-error{margin-top:4px;font-size:.875em;color:#c62828}\n.gjsf-error:empty{display:none}\n.has-error .gjsf-input{border-color:#c62828}\n.gjsf-heading{flex-basis:100%;margin:8px 0 0}\n.gjsf-text{flex-basis:100%;margin:0}\n.gjsf-actions{flex-basis:100%}\n.gjsf-submit{font:inherit;padding:10px 24px;cursor:pointer}\n.gjsf-message{flex-basis:100%}\n.gjsf-message:empty{display:none}\n.gjsf-form.is-sending{opacity:.7}\n.gjsf-form.is-error .gjsf-message{color:#c62828}\n";
@@ -0,0 +1,9 @@
1
+ /** Replaces each `%s` with the next argument. */
2
+ export declare const fmt: (s: string, ...args: Array<string | number>) => string;
3
+ export declare const clone: <T>(o: T) => T;
4
+ /** A random UUID v4, also outside secure contexts. */
5
+ export declare const uuid: () => string;
6
+ /** Logs instead of leaving an unhandled rejection. */
7
+ export declare const report: (e: unknown) => void;
8
+ /** A CSS-class-safe slug: `Contact us` → `contact-us`. */
9
+ export declare const slug: (s: string) => string;
package/openapi.yaml ADDED
@@ -0,0 +1,240 @@
1
+ openapi: 3.0.3
2
+ info:
3
+ title: grapesjs-forms backend
4
+ version: 1.0.0
5
+ description: |
6
+ What `RestFormStore` (plugin option `rest: { url }`) calls, and where the
7
+ published site posts. Paths are relative to the base URL.
8
+
9
+ - **Admin** (the editor): forms and their submissions. Protect them the way
10
+ the rest of your admin is protected (cookie session + `credentials`, or a
11
+ token through the `headers` option).
12
+ - **Public** (the site): `POST /forms/{id}/submissions`. The site posts to
13
+ `<submitUrl>/forms/<id>/submissions` (`submitUrl` defaults to `rest.url`;
14
+ a form's own `settings.endpoint` wins). Allow CORS for the site's origin
15
+ when it is not the API's.
16
+
17
+ Versions are opaque: `PUT` with `If-Match: "<version>"` answers 412 when
18
+ the form moved on. Errors are `{ error, errors? }`; `errors` maps a field
19
+ name to a list of codes or messages (the site shows them under the field;
20
+ known codes are turned into the form's texts).
21
+
22
+ Validate a submission against its form with `validateSubmission(form, data)`
23
+ (exported by the package, no DOM needed) or the same rules in your language
24
+ (see `src/schema.ts`). A filled honeypot field `_gjsf_hp` is a bot: answer
25
+ 201 and keep nothing.
26
+ servers:
27
+ - url: /api/forms
28
+ paths:
29
+ /forms:
30
+ get:
31
+ summary: All forms (admin)
32
+ responses:
33
+ '200':
34
+ description: OK
35
+ content:
36
+ application/json:
37
+ schema:
38
+ type: object
39
+ properties:
40
+ items: { type: array, items: { $ref: '#/components/schemas/Form' } }
41
+ /forms/{id}:
42
+ parameters:
43
+ - $ref: '#/components/parameters/id'
44
+ get:
45
+ summary: One form (admin)
46
+ responses:
47
+ '200': { description: OK, content: { application/json: { schema: { $ref: '#/components/schemas/Form' } } } }
48
+ '404': { $ref: '#/components/responses/Error' }
49
+ put:
50
+ summary: Creates or replaces a form (admin)
51
+ parameters:
52
+ - in: header
53
+ name: If-Match
54
+ required: false
55
+ schema: { type: string }
56
+ description: '"<version>" the client last saw; absent on create.'
57
+ requestBody:
58
+ required: true
59
+ content:
60
+ application/json:
61
+ schema: { $ref: '#/components/schemas/FormWrite' }
62
+ responses:
63
+ '200': { description: Replaced, content: { application/json: { schema: { $ref: '#/components/schemas/Form' } } } }
64
+ '201': { description: Created, content: { application/json: { schema: { $ref: '#/components/schemas/Form' } } } }
65
+ '412': { $ref: '#/components/responses/Error' }
66
+ '422': { $ref: '#/components/responses/Invalid' }
67
+ delete:
68
+ summary: Deletes a form and its submissions (admin)
69
+ responses:
70
+ '204': { description: Deleted }
71
+ '404': { $ref: '#/components/responses/Error' }
72
+ /forms/{id}/submissions:
73
+ parameters:
74
+ - $ref: '#/components/parameters/id'
75
+ post:
76
+ summary: Sends a submission (public — the site)
77
+ requestBody:
78
+ required: true
79
+ content:
80
+ application/json:
81
+ schema:
82
+ type: object
83
+ required: [data]
84
+ properties:
85
+ data: { $ref: '#/components/schemas/SubmissionData' }
86
+ meta: { $ref: '#/components/schemas/SubmissionMeta' }
87
+ multipart/form-data:
88
+ schema:
89
+ type: object
90
+ description: With file fields. Values by field name (repeated names — several values); `_meta` is the JSON of `meta`.
91
+ additionalProperties: true
92
+ properties:
93
+ _meta: { type: string }
94
+ responses:
95
+ '201':
96
+ description: Accepted
97
+ content:
98
+ application/json:
99
+ schema:
100
+ type: object
101
+ properties:
102
+ id: { type: string }
103
+ created_at: { type: string, format: date-time }
104
+ message: { type: string, description: Shown instead of the form's success message. }
105
+ redirect: { type: string, description: Opened instead of the form's redirect. }
106
+ '404': { $ref: '#/components/responses/Error' }
107
+ '422': { $ref: '#/components/responses/Invalid' }
108
+ '429': { $ref: '#/components/responses/Error' }
109
+ get:
110
+ summary: Submissions of a form, newest first (admin)
111
+ parameters:
112
+ - { in: query, name: limit, schema: { type: integer, default: 50, maximum: 200 } }
113
+ - { in: query, name: offset, schema: { type: integer, default: 0 } }
114
+ responses:
115
+ '200':
116
+ description: OK
117
+ content:
118
+ application/json:
119
+ schema:
120
+ type: object
121
+ properties:
122
+ items: { type: array, items: { $ref: '#/components/schemas/Submission' } }
123
+ total: { type: integer }
124
+ /forms/{id}/submissions/{sid}:
125
+ parameters:
126
+ - $ref: '#/components/parameters/id'
127
+ - { in: path, name: sid, required: true, schema: { type: string } }
128
+ delete:
129
+ summary: Deletes a submission (admin)
130
+ responses:
131
+ '204': { description: Deleted }
132
+ components:
133
+ parameters:
134
+ id:
135
+ in: path
136
+ name: id
137
+ required: true
138
+ schema: { type: string }
139
+ description: Form id (a UUID made by the editor).
140
+ responses:
141
+ Error:
142
+ description: Error
143
+ content:
144
+ application/json:
145
+ schema: { $ref: '#/components/schemas/Error' }
146
+ Invalid:
147
+ description: Validation failed
148
+ content:
149
+ application/json:
150
+ schema: { $ref: '#/components/schemas/Error' }
151
+ example:
152
+ error: The given data was invalid.
153
+ errors: { email: [email], agree: [required] }
154
+ schemas:
155
+ Error:
156
+ type: object
157
+ properties:
158
+ error: { type: string }
159
+ errors:
160
+ type: object
161
+ additionalProperties: { type: array, items: { type: string } }
162
+ description: 'By field: codes (required, email, url, number, min, max, minLength, maxLength, pattern, option, date, time, color) or ready messages.'
163
+ FormWrite:
164
+ type: object
165
+ required: [name, fields]
166
+ properties:
167
+ name: { type: string }
168
+ fields: { type: array, items: { $ref: '#/components/schemas/Field' } }
169
+ settings: { $ref: '#/components/schemas/Settings' }
170
+ attrs: { type: object, additionalProperties: { type: string }, description: Extra attributes of the <form>. }
171
+ Form:
172
+ allOf:
173
+ - $ref: '#/components/schemas/FormWrite'
174
+ - type: object
175
+ properties:
176
+ id: { type: string }
177
+ version: { oneOf: [{ type: string }, { type: integer }] }
178
+ updated_at: { type: string, format: date-time }
179
+ Field:
180
+ type: object
181
+ description: The JSON of the editor, kept as it is (camelCase inside).
182
+ required: [id, type, name]
183
+ properties:
184
+ id: { type: string }
185
+ type:
186
+ type: string
187
+ enum: [text, email, tel, url, number, password, textarea, select, radio, checkbox, checkboxes, date, time, datetime, range, color, file, hidden, heading, paragraph]
188
+ name: { type: string, description: 'Key in a submission ("" for heading / paragraph).' }
189
+ label: { type: string }
190
+ placeholder: { type: string }
191
+ help: { type: string }
192
+ required: { type: boolean }
193
+ value: { type: string, description: 'Default value; for hidden — the value sent. May hold {{placeholders}}.' }
194
+ options:
195
+ type: array
196
+ items: { type: object, properties: { label: { type: string }, value: { type: string } } }
197
+ multiple: { type: boolean }
198
+ min: { type: string }
199
+ max: { type: string }
200
+ step: { type: string }
201
+ minLength: { type: integer }
202
+ maxLength: { type: integer }
203
+ pattern: { type: string }
204
+ accept: { type: string }
205
+ autocomplete: { type: string }
206
+ rows: { type: integer }
207
+ readonly: { type: boolean }
208
+ disabled: { type: boolean }
209
+ width: { type: string, enum: [full, 1/2, 1/3, 2/3, 1/4, 3/4] }
210
+ attrs: { type: object, additionalProperties: { type: string } }
211
+ text: { type: string }
212
+ Settings:
213
+ type: object
214
+ properties:
215
+ endpoint: { type: string }
216
+ successMessage: { type: string }
217
+ errorMessage: { type: string }
218
+ redirect: { type: string }
219
+ reset: { type: boolean, default: true }
220
+ honeypot: { type: boolean, default: true }
221
+ submitLabel: { type: string }
222
+ SubmissionData:
223
+ type: object
224
+ additionalProperties: true
225
+ description: 'By field name: strings; checkboxes / multiple select — arrays; a single checkbox — boolean; plus `_gjsf_hp` (the honeypot, empty for people).'
226
+ SubmissionMeta:
227
+ type: object
228
+ properties:
229
+ url: { type: string }
230
+ referrer: { type: string }
231
+ lang: { type: string }
232
+ page_id: { type: string, description: grapesjs-pages record of the page. }
233
+ Submission:
234
+ type: object
235
+ properties:
236
+ id: { type: string }
237
+ form_id: { type: string }
238
+ data: { $ref: '#/components/schemas/SubmissionData' }
239
+ meta: { $ref: '#/components/schemas/SubmissionMeta' }
240
+ created_at: { type: string, format: date-time }
package/package.json CHANGED
@@ -1,6 +1,60 @@
1
1
  {
2
2
  "name": "grapesjs-forms",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
3
+ "version": "0.1.1",
4
+ "description": "GrapesJS plugin: a form editor of its own (field types, options, placeholders, attributes, hidden fields with values). A form becomes a component styled by the site's own CSS; submissions go to a REST API (openapi.yaml), IndexedDB or memory. SurveyJS JSON import/export.",
5
+ "type": "module",
6
+ "main": "./dist/grapesjs-forms.umd.cjs",
7
+ "module": "./dist/grapesjs-forms.js",
8
+ "types": "./dist/index.d.ts",
9
+ "unpkg": "./dist/grapesjs-forms.umd.js",
10
+ "jsdelivr": "./dist/grapesjs-forms.umd.js",
11
+ "exports": {
12
+ ".": {
13
+ "types": "./dist/index.d.ts",
14
+ "import": "./dist/grapesjs-forms.js",
15
+ "require": "./dist/grapesjs-forms.umd.cjs"
16
+ },
17
+ "./runtime": {
18
+ "types": "./dist/runtime/index.d.ts",
19
+ "import": "./dist/runtime.js"
20
+ }
21
+ },
22
+ "files": [
23
+ "dist",
24
+ "openapi.yaml",
25
+ "README.md",
26
+ "ARCHITECTURE.md",
27
+ "LICENSE"
28
+ ],
29
+ "sideEffects": false,
30
+ "scripts": {
31
+ "dev": "vite",
32
+ "build": "vite build && vite build -c vite.runtime.config.ts && tsc -p tsconfig.json --emitDeclarationOnly && node -e \"require('fs').copyFileSync('dist/grapesjs-forms.umd.cjs','dist/grapesjs-forms.umd.js')\"",
33
+ "typecheck": "tsc -p tsconfig.json --noEmit && tsc -p tsconfig.test.json",
34
+ "test": "vitest run",
35
+ "test:watch": "vitest",
36
+ "prepublishOnly": "npm run typecheck && npm test && npm run build"
37
+ },
38
+ "peerDependencies": {
39
+ "grapesjs": ">=0.21.0 <1.0.0"
40
+ },
41
+ "devDependencies": {
42
+ "fake-indexeddb": "^6.0.0",
43
+ "grapesjs": "0.21.13",
44
+ "jsdom": "^25.0.1",
45
+ "typescript": "5.6.3",
46
+ "vite": "5.4.11",
47
+ "vitest": "^2.1.9"
48
+ },
49
+ "keywords": [
50
+ "grapesjs",
51
+ "grapesjs-plugin",
52
+ "forms",
53
+ "form-builder",
54
+ "form-editor",
55
+ "submissions",
56
+ "surveyjs"
57
+ ],
58
+ "author": "Alexander Shibisty",
59
+ "license": "MIT"
60
+ }