drill-widgets 2.7.2

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/lib.d.ts ADDED
@@ -0,0 +1,446 @@
1
+ import { CSSResult } from 'lit';
2
+ import { LitElement } from 'lit';
3
+ import { TemplateResult } from 'lit-html';
4
+
5
+ export declare type AssignmentCategory = "individual" | "role";
6
+
7
+ export declare type AssignmentType = IndividualAssignmentType | RoleAssignmentType;
8
+
9
+ declare interface BaseElement {
10
+ id: string;
11
+ type: string;
12
+ order: number;
13
+ metadata?: Record<string, any>;
14
+ visibility?: Visibility;
15
+ }
16
+
17
+ export declare interface BuilderConfig {
18
+ onWorkflowCreated?: (workflow: Workflow) => void;
19
+ onWorkflowDeleted?: (workflowId: string) => void;
20
+ onWorkflowUpdated?: (workflow: Workflow) => void;
21
+ }
22
+
23
+ export declare class BuilderWidget extends LitElement {
24
+ static styles: CSSResult;
25
+ private _templateData;
26
+ private _showStepModal;
27
+ private _stepFormData;
28
+ private _draggedStepId;
29
+ private _dragOverStepId;
30
+ private _selectedStepId;
31
+ private _questions;
32
+ onCancel?: () => void;
33
+ onSave?: (workflowJson: Workflow) => void;
34
+ onWorkflowCreated?: (workflow: Workflow) => void;
35
+ onWorkflowDeleted?: (workflowId: string) => void;
36
+ onWorkflowUpdated?: (workflow: Workflow) => void;
37
+ connectedCallback(): void;
38
+ private _getDefaultWorkflowData;
39
+ private _handleTitleChange;
40
+ private _handleDescriptionChange;
41
+ private _handleCancel;
42
+ private _handleSave;
43
+ private _addStep;
44
+ private _closeStepModal;
45
+ private _handleStepFormInput;
46
+ private _createStep;
47
+ private _selectStep;
48
+ private _getSelectedStep;
49
+ private _handleDragStart;
50
+ private _handleDragEnd;
51
+ private _handleDragOver;
52
+ private _handleDragLeave;
53
+ private _handleDrop;
54
+ private _addQuestion;
55
+ private _addContentElement;
56
+ private _updateQuestion;
57
+ private _updateContentElement;
58
+ private _deleteQuestion;
59
+ private _renderQuestionTypeSpecificFields;
60
+ private _renderContentTypeSpecificFields;
61
+ private _getQuestionTypeDisplayName;
62
+ private _getContentTypeDisplayName;
63
+ private _getCheckboxTypeDisplayName;
64
+ private _hasSteps;
65
+ private _getAssignmentDisplayText;
66
+ render(): TemplateResult<1>;
67
+ }
68
+
69
+ export declare interface ContentElement extends BaseElement {
70
+ type: "text" | "html" | "image" | "video" | "file" | "divider" | "markdown";
71
+ content: string;
72
+ url?: string;
73
+ alt?: string;
74
+ caption?: string;
75
+ }
76
+
77
+ /**
78
+ * Creates and mounts the Begin Workflow Builder widget.
79
+ * @param targetElementId The ID of the DOM element to mount the widget into.
80
+ * @param config Configuration options including callbacks.
81
+ */
82
+ export declare function createBuilder(targetElementId: string, config?: BuilderConfig): BuilderWidget | null;
83
+
84
+ /**
85
+ * Creates and mounts the Begin Workflow Runner widget.
86
+ * @param targetElementId The ID of the DOM element to mount the widget into.
87
+ * @param config Configuration options including instance and callbacks.
88
+ */
89
+ export declare function createRunner(targetElementId: string, config: RunnerConfig): RunnerWidget | null;
90
+
91
+ /**
92
+ * Generates print-ready HTML from a workflow instance
93
+ * This function replicates the print mode rendering from the runner widget
94
+ * but as a standalone utility that can be used server-side
95
+ */
96
+ export declare function generateInstanceHTML(instance: Instance, options?: HTMLExportOptions): HTMLExportResult;
97
+
98
+ export declare interface HTMLExportOptions {
99
+ title?: string;
100
+ includeStyles?: boolean;
101
+ customCSS?: string;
102
+ showTimestamps?: boolean;
103
+ }
104
+
105
+ export declare interface HTMLExportResult {
106
+ html: string;
107
+ title: string;
108
+ generatedAt: Date;
109
+ }
110
+
111
+ export declare type IndividualAssignmentType = "subject" | "creator" | "instance_assignee_select" | "specific_user";
112
+
113
+ export declare interface Instance {
114
+ id: string;
115
+ workflowId: string;
116
+ name: string;
117
+ dueDate?: Date | null;
118
+ status: "draft" | "active" | "completed" | "canceled";
119
+ createdAt: Date;
120
+ updatedAt: Date;
121
+ steps: Step[];
122
+ currentStepId?: string;
123
+ completedSteps: string[];
124
+ }
125
+
126
+ /** @deprecated Use QuestionElement instead */
127
+ export declare interface Question {
128
+ id: string;
129
+ label: string;
130
+ order: number;
131
+ type: "text" | "email" | "textarea" | "select" | "radio" | "checkbox" | "date" | "number" | "file_upload" | "signature";
132
+ required: boolean;
133
+ options?: string[];
134
+ placeholder?: string;
135
+ validation?: {
136
+ min?: number;
137
+ max?: number;
138
+ pattern?: string;
139
+ };
140
+ }
141
+
142
+ export declare interface QuestionElement extends BaseElement {
143
+ type: "text_input" | "textarea" | "select" | "number" | "radio" | "checkbox" | "date" | "file_upload" | "signature";
144
+ label: string;
145
+ required: boolean;
146
+ placeholder?: string;
147
+ options?: string[];
148
+ validations?: Record<string, any>;
149
+ }
150
+
151
+ export declare interface QuestionResponse {
152
+ elementId: string;
153
+ value: string | string[] | boolean | number | null;
154
+ answeredAt: Date;
155
+ }
156
+
157
+ /**
158
+ * Utility function to restore form data to a runner widget from an instance
159
+ * This can be used to restore form state after page refresh
160
+ * @param runnerWidget The runner widget instance
161
+ * @param instance The instance containing the form data to restore
162
+ */
163
+ export declare function restoreFormDataToRunner(runnerWidget: RunnerWidget, instance: Instance): void;
164
+
165
+ export declare type RoleAssignmentType = "instance_role_assignee_select";
166
+
167
+ export declare interface RunnerConfig {
168
+ instance?: Instance;
169
+ workflow?: Workflow;
170
+ mode?: string;
171
+ isLoading?: boolean;
172
+ currentUser?: {
173
+ targetId: string;
174
+ email: string;
175
+ };
176
+ onInstanceUpdated?: (detail: {
177
+ instanceId?: string;
178
+ workflowId?: string;
179
+ completedStepId?: string;
180
+ completedStepData?: {
181
+ id: string;
182
+ title: string;
183
+ responses: QuestionResponse[];
184
+ } | null;
185
+ completedSteps: string[];
186
+ currentStep?: {
187
+ id: string;
188
+ title: string;
189
+ } | null;
190
+ mode?: string;
191
+ }) => void;
192
+ onSignatureCaptured?: (detail: {
193
+ instanceId?: string;
194
+ stepId?: string;
195
+ questionId: string;
196
+ svgData: string;
197
+ dataURL: string;
198
+ }) => void;
199
+ onFileUploaded?: (detail: {
200
+ instanceId?: string;
201
+ stepId?: string;
202
+ questionId: string;
203
+ file: File;
204
+ fileName: string;
205
+ fileSize: number;
206
+ fileType: string;
207
+ }) => void;
208
+ }
209
+
210
+ export declare class RunnerWidget extends LitElement {
211
+ static styles: CSSResult[];
212
+ instance?: Instance;
213
+ workflow?: Workflow;
214
+ mode?: string;
215
+ isLoading?: boolean;
216
+ currentUser?: {
217
+ targetId: string;
218
+ email: string;
219
+ };
220
+ onSignatureCaptured?: (detail: {
221
+ instanceId?: string;
222
+ stepId?: string;
223
+ questionId: string;
224
+ svgData: string;
225
+ dataURL: string;
226
+ }) => void;
227
+ onFileUploaded?: (detail: {
228
+ instanceId?: string;
229
+ stepId?: string;
230
+ questionId: string;
231
+ file: File;
232
+ fileName: string;
233
+ fileSize: number;
234
+ fileType: string;
235
+ }) => void;
236
+ private _currentStepIndex;
237
+ private _formData;
238
+ private _validationErrors;
239
+ private _internalCompletedSteps;
240
+ private _formRestorationComplete;
241
+ private _savedSignatures;
242
+ private _replacingSignatures;
243
+ private _savedInstance?;
244
+ private _isSubmitted;
245
+ private _userStepsSubmitted;
246
+ private _justSaved;
247
+ private validationService;
248
+ private persistenceManager;
249
+ private signatureManager;
250
+ private responseTracker;
251
+ private navigationService;
252
+ private formStateManager;
253
+ private fileUploadManager;
254
+ willUpdate(changedProperties: Map<string | symbol, unknown>): void;
255
+ connectedCallback(): void;
256
+ disconnectedCallback(): void;
257
+ private _initializeServices;
258
+ private _updateNavigationService;
259
+ private _updateValidationService;
260
+ private _getRenderContext;
261
+ private _handleSignatureChange;
262
+ private _clearValidationError;
263
+ private _updateFormData;
264
+ private _handleFormDataUpdate;
265
+ private _initializeState;
266
+ private _initializePreviewMode;
267
+ private _initializeDefaultMode;
268
+ private _initializeViewOnlyMode;
269
+ private _initializePrintMode;
270
+ private _isStepAssignedToUser;
271
+ private _getAssignedSteps;
272
+ private _isCurrentStepAssigned;
273
+ private _renderNotAssignedView;
274
+ private get _currentStep();
275
+ private _validateStep;
276
+ private _handleInputChange;
277
+ private _handleCheckboxChange;
278
+ private _handleCheckboxGroupChange;
279
+ private _initializeSignaturePad;
280
+ private _handleResize;
281
+ private _clearSignature;
282
+ private _startReplaceSignature;
283
+ private _cancelReplaceSignature;
284
+ private _saveSignature;
285
+ private _hasSignatureChanged;
286
+ private _restoreInstanceResponses;
287
+ private _handleFileUpload;
288
+ private _captureSignaturesFromStep;
289
+ private _trackQuestionResponse;
290
+ private _renderQuestion;
291
+ private _renderContentElement;
292
+ private static readonly QUESTION_ELEMENT_TYPES;
293
+ private static readonly CONTENT_ELEMENT_TYPES;
294
+ private _isQuestionElement;
295
+ private _isContentElement;
296
+ private _renderStepElement;
297
+ private _renderStepWithElements;
298
+ private _renderAllStepsForPrint;
299
+ private _nextStep;
300
+ private _findNextAssignedStep;
301
+ private _isLastAssignedStep;
302
+ private _isLastStepInWorkflow;
303
+ private _goToStep;
304
+ private _submitUserSteps;
305
+ private _submit;
306
+ private _saveStep;
307
+ private _clearSavedFormData;
308
+ private _scrollToTop;
309
+ private _updateInstanceData;
310
+ private _restoreFormData;
311
+ private _updateCompletedStepsFromCurrentIndex;
312
+ private _restoreFormDataFromDOM;
313
+ private _restoreFormValuesToDOM;
314
+ private _updateInstanceWithFormData;
315
+ private _restoreSignatures;
316
+ private _saveFormDataToHistory;
317
+ private _extractFormDataFromDOM;
318
+ private _updateInstanceFromFormData;
319
+ /**
320
+ * Public method to update the instance with current form data
321
+ * This can be called by the parent application to sync form data with the instance
322
+ * @param triggerCallback Whether to trigger the instance-updated callback
323
+ */
324
+ updateInstanceFromFormData(triggerCallback?: boolean): void;
325
+ /**
326
+ * Public method to get the current form data
327
+ * This can be used to extract form data for external processing
328
+ */
329
+ getFormData(): {
330
+ [questionId: string]: any;
331
+ };
332
+ /**
333
+ * Public method to restore form data from browser's form restoration
334
+ * This can be called manually if needed
335
+ */
336
+ restoreFormData(): void;
337
+ /**
338
+ * Public method to clear saved form data from localStorage
339
+ * This can be called to reset the form state
340
+ */
341
+ clearSavedFormData(reason?: string): void;
342
+ private _renderUnifiedSubmissionView;
343
+ /**
344
+ * Check if the instance status indicates the workflow is completed
345
+ */
346
+ private _isInstanceCompleted;
347
+ /**
348
+ * Check if all of the current user's assigned steps are marked as completed in the instance
349
+ * This is used when instance status is "active" but user has finished their part
350
+ */
351
+ private _areUserStepsCompleted;
352
+ /**
353
+ * Determine if we should show the completion view based on instance status
354
+ * This replaces the old internal state-based completion logic
355
+ */
356
+ private _shouldShowCompletionView;
357
+ /**
358
+ * Handles mode-based content routing and basic validation
359
+ * Returns content for special modes or null to continue with normal rendering
360
+ */
361
+ private _renderModeBasedContent;
362
+ /**
363
+ * Validates and returns the current step
364
+ * Returns null if current step is invalid
365
+ */
366
+ private _validateCurrentStep;
367
+ /**
368
+ * Initializes step-specific assets like signature pads and form restoration
369
+ */
370
+ private _initializeStepAssets;
371
+ /**
372
+ * Renders the layout for the current step including navigation and form content
373
+ */
374
+ private _renderCurrentStepLayout;
375
+ private _renderMainContent;
376
+ render(): TemplateResult<1>;
377
+ }
378
+
379
+ export declare interface Step {
380
+ id: string;
381
+ order: number;
382
+ title: string;
383
+ description?: string;
384
+ elements: StepElement[];
385
+ assignment: StepAssignment;
386
+ status: StepStatus;
387
+ responses?: QuestionResponse[];
388
+ metadata?: Record<string, any>;
389
+ visibility?: Visibility;
390
+ }
391
+
392
+ export declare interface StepAssignment {
393
+ category: AssignmentCategory;
394
+ type: AssignmentType;
395
+ targetId?: string;
396
+ targetName?: string;
397
+ email?: string;
398
+ roleId?: string;
399
+ userId?: string;
400
+ metadata?: Record<string, any>;
401
+ }
402
+
403
+ /** @deprecated Use StepAssignment instead */
404
+ export declare interface StepAssignmentLegacy {
405
+ category: AssignmentCategory;
406
+ type: AssignmentType;
407
+ userId?: string;
408
+ userEmail?: string;
409
+ roleId?: string;
410
+ }
411
+
412
+ export declare type StepElement = ContentElement | QuestionElement;
413
+
414
+ export declare type StepStatus = "pending" | "active" | "completed" | "skipped";
415
+
416
+ /**
417
+ * Utility function to extract form data from a runner widget and update an instance
418
+ * This can be used to sync form data with an instance after page refresh
419
+ * @param runnerWidget The runner widget instance
420
+ * @param instance The instance to update
421
+ * @returns The updated instance with form data
422
+ */
423
+ export declare function updateInstanceFromRunnerForm(runnerWidget: RunnerWidget, instance: Instance): Instance;
424
+
425
+ export declare interface Visibility {
426
+ condition: "always" | "never" | "conditional";
427
+ logic?: "and" | "or";
428
+ rules?: VisibilityRule[];
429
+ }
430
+
431
+ export declare interface VisibilityRule {
432
+ type: "role" | "response" | "step_status";
433
+ operator: "equals" | "not_equals" | "contains" | "not_contains" | "in" | "not_in" | "exists" | "not_exists";
434
+ sourceId?: string;
435
+ value: any;
436
+ }
437
+
438
+ export declare interface Workflow {
439
+ id: string;
440
+ name: string;
441
+ description?: string;
442
+ steps: Step[];
443
+ assignment?: StepAssignment;
444
+ }
445
+
446
+ export { }
package/package.json ADDED
@@ -0,0 +1,66 @@
1
+ {
2
+ "name": "drill-widgets",
3
+ "version": "2.7.2",
4
+ "description": "Easily embed powerful workflow building and running capabilities into your web applications with Lit-based web components. Includes HTML export for server-side PDF generation.",
5
+ "scripts": {
6
+ "dev": "vite",
7
+ "build": "tsc && vite build && node scripts/build-html.js",
8
+ "preview": "vite preview",
9
+ "test": "echo \"Error: no test specified\" && exit 1"
10
+ },
11
+ "keywords": [
12
+ "workflow",
13
+ "forms",
14
+ "lit",
15
+ "web-components",
16
+ "builder",
17
+ "runner",
18
+ "typescript",
19
+ "html-export",
20
+ "pdf-generation",
21
+ "server-side"
22
+ ],
23
+ "author": "Clay Grumieaux <claygrumeo@gmail.com>",
24
+ "license": "UNLICENSED",
25
+ "type": "module",
26
+ "main": "./dist/begin-widgets.umd.js",
27
+ "module": "./dist/begin-widgets.es.js",
28
+ "types": "./dist/lib.d.ts",
29
+ "exports": {
30
+ ".": {
31
+ "types": "./dist/lib.d.ts",
32
+ "import": "./dist/begin-widgets.es.js",
33
+ "require": "./dist/begin-widgets.umd.js"
34
+ },
35
+ "./types": {
36
+ "types": "./dist/api-types.d.ts"
37
+ }
38
+ },
39
+ "dependencies": {
40
+ "lit": "^3.3.0",
41
+ "signature_pad": "^5.0.10",
42
+ "uuid": "^11.1.0",
43
+ "vite-plugin-dts": "^4.5.4"
44
+ },
45
+ "devDependencies": {
46
+ "@types/uuid": "^10.0.0",
47
+ "typescript": "^5.8.3",
48
+ "vite": "^6.3.0"
49
+ },
50
+ "repository": {
51
+ "type": "git",
52
+ "url": "git+https://github.com/claygrumeo/begin-widgets.git"
53
+ },
54
+ "bugs": {
55
+ "url": "https://github.com/claygrumeo/begin-widgets/issues"
56
+ },
57
+ "homepage": "https://github.com/claygrumeo/begin-widgets#readme",
58
+ "files": [
59
+ "dist/*.js",
60
+ "dist/*.d.ts",
61
+ "README.md"
62
+ ],
63
+ "publishConfig": {
64
+ "access": "public"
65
+ }
66
+ }