@squaredr/fieldcraft-pro 0.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/dist/chunk-APHGEYG4.mjs +3168 -0
- package/dist/chunk-MQGR25NG.mjs +409 -0
- package/dist/chunk-NIKQEWPG.mjs +467 -0
- package/dist/form-builder/index.d.mts +367 -0
- package/dist/form-builder/index.d.ts +367 -0
- package/dist/form-builder/index.js +3201 -0
- package/dist/form-builder/index.mjs +1 -0
- package/dist/index.d.mts +9 -0
- package/dist/index.d.ts +9 -0
- package/dist/index.js +4111 -0
- package/dist/index.mjs +24 -0
- package/dist/response-viewer/index.d.mts +21 -0
- package/dist/response-viewer/index.d.ts +21 -0
- package/dist/response-viewer/index.js +469 -0
- package/dist/response-viewer/index.mjs +1 -0
- package/dist/styles.css +2 -0
- package/dist/theme-editor/index.d.mts +32 -0
- package/dist/theme-editor/index.d.ts +32 -0
- package/dist/theme-editor/index.js +413 -0
- package/dist/theme-editor/index.mjs +1 -0
- package/dist/theme-editor-styles.css +256 -0
- package/package.json +74 -0
|
@@ -0,0 +1,367 @@
|
|
|
1
|
+
import * as react from 'react';
|
|
2
|
+
import { ReactNode } from 'react';
|
|
3
|
+
import { FormEngineSchema, QuestionType, Section, Question, Option } from '@squaredr/fieldcraft-core';
|
|
4
|
+
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
5
|
+
import { ClassValue } from 'clsx';
|
|
6
|
+
import * as _dnd_kit_core from '@dnd-kit/core';
|
|
7
|
+
import { DragStartEvent, DragEndEvent } from '@dnd-kit/core';
|
|
8
|
+
|
|
9
|
+
declare const FormBuilder: react.ComponentType<FormBuilderProps>;
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* FormBuilder theme configuration.
|
|
13
|
+
* All values are CSS color strings (hex, oklch, hsl, etc.).
|
|
14
|
+
* Set these to customize the builder's appearance.
|
|
15
|
+
*/
|
|
16
|
+
type FormBuilderTheme = {
|
|
17
|
+
/** Main background of the entire builder */
|
|
18
|
+
background?: string;
|
|
19
|
+
/** Primary text color */
|
|
20
|
+
foreground?: string;
|
|
21
|
+
/** Card/panel background */
|
|
22
|
+
card?: string;
|
|
23
|
+
/** Primary accent color (buttons, selection, focus rings) */
|
|
24
|
+
primary?: string;
|
|
25
|
+
/** Text color on primary backgrounds */
|
|
26
|
+
primaryForeground?: string;
|
|
27
|
+
/** Secondary surfaces */
|
|
28
|
+
secondary?: string;
|
|
29
|
+
/** Text on secondary surfaces */
|
|
30
|
+
secondaryForeground?: string;
|
|
31
|
+
/** Muted background (disabled, subtle areas) */
|
|
32
|
+
muted?: string;
|
|
33
|
+
/** Muted text (labels, placeholders) */
|
|
34
|
+
mutedForeground?: string;
|
|
35
|
+
/** Hover/accent background */
|
|
36
|
+
accent?: string;
|
|
37
|
+
/** Text on accent background */
|
|
38
|
+
accentForeground?: string;
|
|
39
|
+
/** Destructive action color */
|
|
40
|
+
destructive?: string;
|
|
41
|
+
/** Text on destructive backgrounds */
|
|
42
|
+
destructiveForeground?: string;
|
|
43
|
+
/** Default border color */
|
|
44
|
+
border?: string;
|
|
45
|
+
/** Input border color */
|
|
46
|
+
input?: string;
|
|
47
|
+
/** Focus ring color */
|
|
48
|
+
ring?: string;
|
|
49
|
+
/** Border radius base (e.g. "6px", "0.375rem") */
|
|
50
|
+
radius?: string;
|
|
51
|
+
/** Surface color for panels/sidebars */
|
|
52
|
+
surface?: string;
|
|
53
|
+
/** Surface hover state */
|
|
54
|
+
surfaceHover?: string;
|
|
55
|
+
/** Main canvas background */
|
|
56
|
+
canvas?: string;
|
|
57
|
+
/** Panel background (palette, property panel) */
|
|
58
|
+
panel?: string;
|
|
59
|
+
/** Strong border color (for emphasis) */
|
|
60
|
+
borderStrong?: string;
|
|
61
|
+
/** Dim text color (secondary labels) */
|
|
62
|
+
textDim?: string;
|
|
63
|
+
};
|
|
64
|
+
|
|
65
|
+
type FormBuilderProps = {
|
|
66
|
+
/** Initial schema to load. If not provided, uses a default empty schema */
|
|
67
|
+
initialSchema?: FormEngineSchema;
|
|
68
|
+
/** Callback when schema changes */
|
|
69
|
+
onChange?: (schema: FormEngineSchema) => void;
|
|
70
|
+
/** Callback when user clicks "Save" */
|
|
71
|
+
onSave?: (schema: FormEngineSchema) => void;
|
|
72
|
+
/** Height of the builder container */
|
|
73
|
+
height?: string | number;
|
|
74
|
+
/** Theme customization — overrides CSS variables for all builder components */
|
|
75
|
+
theme?: FormBuilderTheme;
|
|
76
|
+
/** Additional CSS class name on the root element */
|
|
77
|
+
className?: string;
|
|
78
|
+
/** Extra content rendered in the toolbar, after the Save button */
|
|
79
|
+
toolbarExtra?: ReactNode;
|
|
80
|
+
/** Additional question type metadata — merged with built-in defaults (e.g. telehealth fields) */
|
|
81
|
+
questionTypes?: Record<string, QuestionTypeInfo>;
|
|
82
|
+
/** Additional palette categories — appended to built-in palette (e.g. telehealth categories) */
|
|
83
|
+
palette?: PaletteCategory[];
|
|
84
|
+
};
|
|
85
|
+
type BuilderState = {
|
|
86
|
+
schema: FormEngineSchema;
|
|
87
|
+
selectedItem: SelectedItem | null;
|
|
88
|
+
isDirty: boolean;
|
|
89
|
+
};
|
|
90
|
+
type SelectedItem = {
|
|
91
|
+
type: "question";
|
|
92
|
+
sectionId: string;
|
|
93
|
+
questionId: string;
|
|
94
|
+
} | {
|
|
95
|
+
type: "section";
|
|
96
|
+
sectionId: string;
|
|
97
|
+
};
|
|
98
|
+
type DragItem = {
|
|
99
|
+
type: "palette-item";
|
|
100
|
+
questionType: QuestionType;
|
|
101
|
+
} | {
|
|
102
|
+
type: "question";
|
|
103
|
+
sectionId: string;
|
|
104
|
+
questionId: string;
|
|
105
|
+
questionIndex: number;
|
|
106
|
+
} | {
|
|
107
|
+
type: "section";
|
|
108
|
+
sectionId: string;
|
|
109
|
+
sectionIndex: number;
|
|
110
|
+
};
|
|
111
|
+
type DropTarget = {
|
|
112
|
+
type: "section";
|
|
113
|
+
sectionId: string;
|
|
114
|
+
index: number;
|
|
115
|
+
} | {
|
|
116
|
+
type: "canvas";
|
|
117
|
+
index: number;
|
|
118
|
+
};
|
|
119
|
+
type QuestionTypeCategory = "text" | "numeric" | "selection" | "datetime" | "media" | "advanced" | "structural" | "content" | (string & {});
|
|
120
|
+
type PaletteCategory = {
|
|
121
|
+
category: string;
|
|
122
|
+
label: string;
|
|
123
|
+
types: string[];
|
|
124
|
+
};
|
|
125
|
+
type QuestionTypeInfo = {
|
|
126
|
+
type: QuestionType;
|
|
127
|
+
label: string;
|
|
128
|
+
category: QuestionTypeCategory;
|
|
129
|
+
icon: string;
|
|
130
|
+
description: string;
|
|
131
|
+
defaultConfig?: Record<string, unknown>;
|
|
132
|
+
requiresOptions?: boolean;
|
|
133
|
+
};
|
|
134
|
+
type PropertyPanelTab = "basic" | "validation" | "logic" | "advanced" | "options";
|
|
135
|
+
type MutationAction = {
|
|
136
|
+
type: "add-section";
|
|
137
|
+
section: Section;
|
|
138
|
+
index: number;
|
|
139
|
+
} | {
|
|
140
|
+
type: "remove-section";
|
|
141
|
+
sectionId: string;
|
|
142
|
+
} | {
|
|
143
|
+
type: "update-section";
|
|
144
|
+
sectionId: string;
|
|
145
|
+
updates: Partial<Section>;
|
|
146
|
+
} | {
|
|
147
|
+
type: "move-section";
|
|
148
|
+
sectionId: string;
|
|
149
|
+
newIndex: number;
|
|
150
|
+
} | {
|
|
151
|
+
type: "add-question";
|
|
152
|
+
sectionId: string;
|
|
153
|
+
question: Question;
|
|
154
|
+
index: number;
|
|
155
|
+
} | {
|
|
156
|
+
type: "remove-question";
|
|
157
|
+
sectionId: string;
|
|
158
|
+
questionId: string;
|
|
159
|
+
} | {
|
|
160
|
+
type: "update-question";
|
|
161
|
+
sectionId: string;
|
|
162
|
+
questionId: string;
|
|
163
|
+
updates: Partial<Question>;
|
|
164
|
+
} | {
|
|
165
|
+
type: "move-question";
|
|
166
|
+
sectionId: string;
|
|
167
|
+
questionId: string;
|
|
168
|
+
targetSectionId: string;
|
|
169
|
+
newIndex: number;
|
|
170
|
+
} | {
|
|
171
|
+
type: "duplicate-question";
|
|
172
|
+
sectionId: string;
|
|
173
|
+
questionId: string;
|
|
174
|
+
} | {
|
|
175
|
+
type: "add-option";
|
|
176
|
+
sectionId: string;
|
|
177
|
+
questionId: string;
|
|
178
|
+
option: Option;
|
|
179
|
+
index: number;
|
|
180
|
+
} | {
|
|
181
|
+
type: "remove-option";
|
|
182
|
+
sectionId: string;
|
|
183
|
+
questionId: string;
|
|
184
|
+
optionIndex: number;
|
|
185
|
+
} | {
|
|
186
|
+
type: "update-option";
|
|
187
|
+
sectionId: string;
|
|
188
|
+
questionId: string;
|
|
189
|
+
optionIndex: number;
|
|
190
|
+
updates: Partial<Option>;
|
|
191
|
+
};
|
|
192
|
+
|
|
193
|
+
declare function useBuilderTheme(): FormBuilderTheme;
|
|
194
|
+
type FormBuilderThemeProviderProps = {
|
|
195
|
+
theme?: FormBuilderTheme;
|
|
196
|
+
children: ReactNode;
|
|
197
|
+
};
|
|
198
|
+
declare function FormBuilderThemeProvider({ theme, children }: FormBuilderThemeProviderProps): react_jsx_runtime.JSX.Element;
|
|
199
|
+
|
|
200
|
+
/**
|
|
201
|
+
* SquaredR Dark theme preset.
|
|
202
|
+
* Matches squaredr.tech Ink + Cyan design system.
|
|
203
|
+
*/
|
|
204
|
+
declare const squaredrDarkPreset: FormBuilderTheme;
|
|
205
|
+
/**
|
|
206
|
+
* Clean light theme preset (default).
|
|
207
|
+
* Neutral colors that fit most apps.
|
|
208
|
+
*/
|
|
209
|
+
declare const cleanPreset: FormBuilderTheme;
|
|
210
|
+
|
|
211
|
+
/**
|
|
212
|
+
* Metadata for all question types available in the Pro palette.
|
|
213
|
+
* Icons are lucide-react component names (imported dynamically via ICON_MAP).
|
|
214
|
+
*
|
|
215
|
+
* 28 field types — general-purpose form building.
|
|
216
|
+
* Telehealth-specific fields (15) are in @squaredr/fieldcraft-pro-telehealth.
|
|
217
|
+
*/
|
|
218
|
+
declare const QUESTION_TYPE_INFO: Record<string, QuestionTypeInfo>;
|
|
219
|
+
/**
|
|
220
|
+
* Default palette layout with categories (28 Pro field types).
|
|
221
|
+
* Telehealth fields can be appended via FormBuilder's `palette` prop.
|
|
222
|
+
*/
|
|
223
|
+
declare const DEFAULT_PALETTE: ({
|
|
224
|
+
category: "text";
|
|
225
|
+
label: string;
|
|
226
|
+
types: string[];
|
|
227
|
+
} | {
|
|
228
|
+
category: "numeric";
|
|
229
|
+
label: string;
|
|
230
|
+
types: string[];
|
|
231
|
+
} | {
|
|
232
|
+
category: "selection";
|
|
233
|
+
label: string;
|
|
234
|
+
types: string[];
|
|
235
|
+
} | {
|
|
236
|
+
category: "datetime";
|
|
237
|
+
label: string;
|
|
238
|
+
types: string[];
|
|
239
|
+
} | {
|
|
240
|
+
category: "media";
|
|
241
|
+
label: string;
|
|
242
|
+
types: string[];
|
|
243
|
+
} | {
|
|
244
|
+
category: "content";
|
|
245
|
+
label: string;
|
|
246
|
+
types: string[];
|
|
247
|
+
} | {
|
|
248
|
+
category: "structural";
|
|
249
|
+
label: string;
|
|
250
|
+
types: string[];
|
|
251
|
+
} | {
|
|
252
|
+
category: "advanced";
|
|
253
|
+
label: string;
|
|
254
|
+
types: string[];
|
|
255
|
+
})[];
|
|
256
|
+
|
|
257
|
+
/**
|
|
258
|
+
* Generate unique IDs for sections, questions, and options.
|
|
259
|
+
* Format: {prefix}_{timestamp}_{random}
|
|
260
|
+
*/
|
|
261
|
+
declare function generateId(prefix: string): string;
|
|
262
|
+
declare function generateSectionId(): string;
|
|
263
|
+
declare function generateQuestionId(): string;
|
|
264
|
+
declare function generateOptionId(): string;
|
|
265
|
+
|
|
266
|
+
/**
|
|
267
|
+
* Pure functions for mutating FormEngineSchema.
|
|
268
|
+
* All functions return a new schema object (immutable updates).
|
|
269
|
+
*/
|
|
270
|
+
|
|
271
|
+
declare function addSection(schema: FormEngineSchema, section: Section, index: number): FormEngineSchema;
|
|
272
|
+
declare function removeSection(schema: FormEngineSchema, sectionId: string): FormEngineSchema;
|
|
273
|
+
declare function updateSection(schema: FormEngineSchema, sectionId: string, updates: Partial<Section>): FormEngineSchema;
|
|
274
|
+
declare function moveSection(schema: FormEngineSchema, sectionId: string, newIndex: number): FormEngineSchema;
|
|
275
|
+
declare function duplicateSection(schema: FormEngineSchema, sectionId: string): FormEngineSchema;
|
|
276
|
+
declare function addQuestion(schema: FormEngineSchema, sectionId: string, question: Question, index: number): FormEngineSchema;
|
|
277
|
+
declare function removeQuestion(schema: FormEngineSchema, sectionId: string, questionId: string): FormEngineSchema;
|
|
278
|
+
declare function updateQuestion(schema: FormEngineSchema, sectionId: string, questionId: string, updates: Partial<Question>): FormEngineSchema;
|
|
279
|
+
declare function moveQuestion(schema: FormEngineSchema, sectionId: string, questionId: string, targetSectionId: string, newIndex: number): FormEngineSchema;
|
|
280
|
+
declare function duplicateQuestion(schema: FormEngineSchema, sectionId: string, questionId: string): FormEngineSchema;
|
|
281
|
+
declare function addOption(schema: FormEngineSchema, sectionId: string, questionId: string, option: Option, index: number): FormEngineSchema;
|
|
282
|
+
declare function removeOption(schema: FormEngineSchema, sectionId: string, questionId: string, optionIndex: number): FormEngineSchema;
|
|
283
|
+
declare function updateOption(schema: FormEngineSchema, sectionId: string, questionId: string, optionIndex: number, updates: Partial<Option>): FormEngineSchema;
|
|
284
|
+
declare function moveOption(schema: FormEngineSchema, sectionId: string, questionId: string, oldIndex: number, newIndex: number): FormEngineSchema;
|
|
285
|
+
declare function findQuestion(schema: FormEngineSchema, sectionId: string, questionId: string): {
|
|
286
|
+
section: Section;
|
|
287
|
+
question: Question;
|
|
288
|
+
questionIndex: number;
|
|
289
|
+
} | null;
|
|
290
|
+
declare function findSection(schema: FormEngineSchema, sectionId: string): {
|
|
291
|
+
section: Section;
|
|
292
|
+
sectionIndex: number;
|
|
293
|
+
} | null;
|
|
294
|
+
|
|
295
|
+
declare function cn(...inputs: ClassValue[]): string;
|
|
296
|
+
|
|
297
|
+
/**
|
|
298
|
+
* Master state hook for the FormBuilder.
|
|
299
|
+
* Combines schema state, selection, and undo/redo.
|
|
300
|
+
*
|
|
301
|
+
* All mutation callbacks use a ref to read the latest schema,
|
|
302
|
+
* avoiding stale closures when multiple mutations fire in the
|
|
303
|
+
* same render tick.
|
|
304
|
+
*/
|
|
305
|
+
declare function useBuilderState(initialSchema: FormEngineSchema): {
|
|
306
|
+
schema: FormEngineSchema;
|
|
307
|
+
selectedItem: SelectedItem | null;
|
|
308
|
+
isDirty: boolean;
|
|
309
|
+
updateSchema: (newSchema: FormEngineSchema) => void;
|
|
310
|
+
addSection: (section: Section, index: number) => void;
|
|
311
|
+
removeSection: (sectionId: string) => void;
|
|
312
|
+
updateSection: (sectionId: string, updates: Partial<Section>) => void;
|
|
313
|
+
moveSection: (sectionId: string, newIndex: number) => void;
|
|
314
|
+
duplicateSection: (sectionId: string) => void;
|
|
315
|
+
addQuestion: (sectionId: string, question: Question, index: number) => void;
|
|
316
|
+
removeQuestion: (sectionId: string, questionId: string) => void;
|
|
317
|
+
updateQuestion: (sectionId: string, questionId: string, updates: Partial<Question>) => void;
|
|
318
|
+
moveQuestion: (sectionId: string, questionId: string, targetSectionId: string, newIndex: number) => void;
|
|
319
|
+
duplicateQuestion: (sectionId: string, questionId: string) => void;
|
|
320
|
+
selectQuestion: (sectionId: string, questionId: string) => void;
|
|
321
|
+
selectSection: (sectionId: string) => void;
|
|
322
|
+
clearSelection: () => void;
|
|
323
|
+
canUndo: boolean;
|
|
324
|
+
canRedo: boolean;
|
|
325
|
+
undo: () => void;
|
|
326
|
+
redo: () => void;
|
|
327
|
+
resetSchema: (newSchema: FormEngineSchema) => void;
|
|
328
|
+
markClean: () => void;
|
|
329
|
+
};
|
|
330
|
+
type BuilderStateHook = ReturnType<typeof useBuilderState>;
|
|
331
|
+
|
|
332
|
+
type UndoRedoState = {
|
|
333
|
+
canUndo: boolean;
|
|
334
|
+
canRedo: boolean;
|
|
335
|
+
undo: () => void;
|
|
336
|
+
redo: () => void;
|
|
337
|
+
push: (schema: FormEngineSchema) => void;
|
|
338
|
+
clear: () => void;
|
|
339
|
+
};
|
|
340
|
+
/**
|
|
341
|
+
* Hook for undo/redo functionality.
|
|
342
|
+
* Maintains a history stack of schemas with max 50 entries.
|
|
343
|
+
* Uses state for the index so canUndo/canRedo trigger re-renders.
|
|
344
|
+
* The history array is kept in a ref since its identity doesn't
|
|
345
|
+
* need to cause re-renders — only the index matters.
|
|
346
|
+
*/
|
|
347
|
+
declare function useUndoRedo(currentSchema: FormEngineSchema, setSchema: (schema: FormEngineSchema) => void): UndoRedoState;
|
|
348
|
+
|
|
349
|
+
/**
|
|
350
|
+
* Hook to wire up @dnd-kit drag-and-drop.
|
|
351
|
+
* Returns DndContext props and handlers.
|
|
352
|
+
*/
|
|
353
|
+
declare function useDragDrop(builderState: BuilderStateHook): {
|
|
354
|
+
sensors: _dnd_kit_core.SensorDescriptor<_dnd_kit_core.SensorOptions>[];
|
|
355
|
+
handleDragStart: (event: DragStartEvent) => void;
|
|
356
|
+
handleDragEnd: (event: DragEndEvent) => void;
|
|
357
|
+
handleDragCancel: () => void;
|
|
358
|
+
activeDragItem: DragItem | null;
|
|
359
|
+
};
|
|
360
|
+
|
|
361
|
+
/**
|
|
362
|
+
* Default empty schema for new forms.
|
|
363
|
+
* Contains one section with one question to get started.
|
|
364
|
+
*/
|
|
365
|
+
declare const DEFAULT_SCHEMA: FormEngineSchema;
|
|
366
|
+
|
|
367
|
+
export { type BuilderState, type BuilderStateHook, DEFAULT_PALETTE, DEFAULT_SCHEMA, type DragItem, type DropTarget, FormBuilder, type FormBuilderProps, type FormBuilderTheme, FormBuilderThemeProvider, type MutationAction, type PaletteCategory, type PropertyPanelTab, QUESTION_TYPE_INFO, type QuestionTypeCategory, type QuestionTypeInfo, type SelectedItem, type UndoRedoState, addOption, addQuestion, addSection, cleanPreset, cn, duplicateQuestion, duplicateSection, findQuestion, findSection, generateId, generateOptionId, generateQuestionId, generateSectionId, moveOption, moveQuestion, moveSection, removeOption, removeQuestion, removeSection, squaredrDarkPreset, updateOption, updateQuestion, updateSection, useBuilderState, useBuilderTheme, useDragDrop, useUndoRedo };
|