formanitor 0.1.5 → 0.1.6
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/index.cjs +54 -28
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +17 -3
- package/dist/index.d.ts +17 -3
- package/dist/index.mjs +54 -29
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.d.cts
CHANGED
|
@@ -770,7 +770,10 @@ interface StoreConfig {
|
|
|
770
770
|
prefillData?: Record<string, any>;
|
|
771
771
|
role?: string;
|
|
772
772
|
onEvent?: EventListener;
|
|
773
|
+
/** Handler for image, media, and signature uploads; fallback for file upload when `onFileUpload` is omitted. */
|
|
773
774
|
onUpload?: UploadHandler;
|
|
775
|
+
/** Optional handler for `file_upload` fields only (`FormFileUploadWidget`). Uses `onUpload` when not set. */
|
|
776
|
+
onFileUpload?: UploadHandler;
|
|
774
777
|
onDraftChange?: DraftChangeHandler;
|
|
775
778
|
/**
|
|
776
779
|
* Auth / OTP configuration. Lets the host app supply the API base URL and
|
|
@@ -872,6 +875,8 @@ declare class FormStore {
|
|
|
872
875
|
*/
|
|
873
876
|
updateConfig(next: Partial<StoreConfig>): void;
|
|
874
877
|
getUploadHandler(): UploadHandler | undefined;
|
|
878
|
+
/** Resolved handler for `file_upload` widgets: `onFileUpload` ?? `onUpload`. */
|
|
879
|
+
getFileUploadHandler(): UploadHandler | undefined;
|
|
875
880
|
private preSubmitHandlers;
|
|
876
881
|
registerPreSubmitHandler(fieldId: string, fn: () => Promise<void>): void;
|
|
877
882
|
unregisterPreSubmitHandler(fieldId: string): void;
|
|
@@ -1194,14 +1199,23 @@ interface PresignedUploadResponse {
|
|
|
1194
1199
|
upload_method: 'PUT' | 'POST';
|
|
1195
1200
|
}
|
|
1196
1201
|
interface CreateUploadHandlerOptions {
|
|
1202
|
+
/** Data server origin (no trailing slash), e.g. `https://dataserver.example.com`. */
|
|
1197
1203
|
apiBaseUrl: string;
|
|
1198
1204
|
headers?: Record<string, string>;
|
|
1199
1205
|
}
|
|
1200
1206
|
/**
|
|
1201
|
-
*
|
|
1202
|
-
*
|
|
1207
|
+
* Handler for image / media / signature uploads: presign via
|
|
1208
|
+
* `POST …/api/forms/media-upload/` then PUT/POST file to `presigned_url`.
|
|
1209
|
+
* For `file_upload` fields with a different presign API, use
|
|
1210
|
+
* {@link createFileUploadHandler} as `config.onFileUpload`.
|
|
1203
1211
|
*/
|
|
1204
1212
|
declare function createUploadHandler(options: CreateUploadHandlerOptions): (file: File | Blob, filename: string) => Promise<string>;
|
|
1213
|
+
/**
|
|
1214
|
+
* Handler for `file_upload` fields (`FormFileUploadWidget`): presign via
|
|
1215
|
+
* `POST …/api/forms/media-presigned-get/` then PUT/POST file to `presigned_url`.
|
|
1216
|
+
* Pass this as `config.onFileUpload` on `FormProvider` (omit to use `onUpload` for files too).
|
|
1217
|
+
*/
|
|
1218
|
+
declare function createFileUploadHandler(options: CreateUploadHandlerOptions): (file: File | Blob, filename: string) => Promise<string>;
|
|
1205
1219
|
|
|
1206
1220
|
/** Shape of a medication as returned by AI analysis */
|
|
1207
1221
|
type AIMedication = {
|
|
@@ -1355,4 +1369,4 @@ declare const SmartTextareaWidget: React.FC<{
|
|
|
1355
1369
|
fieldId: string;
|
|
1356
1370
|
}>;
|
|
1357
1371
|
|
|
1358
|
-
export { type AIDifferentialDiagnosisItem, AddInvestigationField, type AddInvestigationFieldProps, AddMedicationField, type AddMedicationFieldProps, type BaseFieldDef, type BiometryIolWorkupFieldDef, type BiometryIolWorkupValue, type BiometryMethod, type CheckboxFieldDef, type ColumnLayout, type Computation, type Condition, type CreateUploadHandlerOptions, type DataSource, type DiagnosisGradeSelection, type DiagnosisTextareaFieldDef, type DiagnosisTextareaValue, type DiagnosticPackage, type DiagnosticPackageTest, DifferentialDiagnosis, type DifferentialDiagnosisFieldDef, type DifferentialDiagnosisItem, type DifferentialDiagnosisProps, type DoctorFrequentItems, DynamicForm, DynamicFormV2, type DynamicFormV2Props, type DynamicFormV2SectionMode, EMAIL_REGEX, type EditableTableColumnDef, type EditableTableFieldDef, type EventDefinition, type ExtractedKeywordMatch, type FieldDef, type FieldHandler, type FieldHandlersMap, type FieldPrefill, FieldRenderer, FieldRequiredIndicator, type FieldState, type FieldStyleClassNames, type FieldStyleConfig, type FieldType, type FileUploadFieldDef, type FollowupFieldDef, type FollowupValue, FormControls, type FormControlsProps, type FormDef, type FormErrors, FormFileUploadWidget, FormProvider, type FormState, FormStore, type FormValues, type FormulaComputation, type FormulaExpr, type FunctionalImpairmentDimension, type FunctionalImpairmentScoreFieldDef, type FunctionalImpairmentScoreValue, type GeneralSurgeryExaminationFieldDef, type GeneralSurgeryGradingFieldDef, type GeneralSurgerySmartHistoryFieldDef, type ImageUploadFieldDef, ImageUploadWidget, type Investigation, type InvestigationFrequentItem, type InvestigationSearchResult, type InvestigationsFieldDef, type LayoutNode, type LensAssessmentFieldDef, type LensAssessmentValue, type LocsGrades, MAR_MEDICATION_ORDERS_META_KEY, type MatchedCondition, type MediaUploadFieldDef, MediaUploadWidget, type Medication, type MedicationFrequentItem, type MedicationSearchResult, type MedicationsFieldDef, MultiStepForm, type MultiStepFormProps, type MultiStepLayoutNode, type MultiStepNode, type NumberFieldDef, type OBGExaminationFieldDef, type OBGPathwayFieldDef, type OtpInputFieldDef, type OtpVerifiedValue, type PainScaleFlagsFieldDef, type Permission, type PhoneInputFieldDef, type PresignedUploadResponse, type ProcedureFrequentItem, type ProceduresFieldDef, type RadioFieldDef, ReadOnlyForm, ReadOnlyImageUpload, ReadOnlyMediaUpload, ReadOnlySignature, ReadOnlyTable, type ReferralFieldDef, type ReferralItem, type RepeatableFieldDef, type RichTextFieldDef, RichTextWidget, type Rule, type RuleAction, type RuleResult, type ScoreComputation, type ScoreRange, type Section, type SectionChild, type SelectFieldDef, type SelectOption, type SignatureFieldDef, SignatureUploadWidget, type SliderFieldDef, SmartForm, type SmartFormProps, type SmartKeywordsResult, type SmartTextareaFieldDef, type SmartTextareaValue, SmartTextareaWidget, type StaticTextFieldDef, type StoreAuthConfig, type StoreConfig, type SubmissionData, type SuggestionTextareaFieldDef, type SumComputation, type SurgicalRiskFlagsFieldDef, type SurgicalRiskFlagsValue, type TextFieldDef, type ToggleFieldDef, Upload, type UploadProps, type UrologyExaminationFieldDef, type UrologyPathwayFieldDef, type UrologySmartHistoryFieldDef, type ValidationRule, type VitalsFieldDef, type WebhookDef, type Workflow, type WorkflowTransition, createUploadHandler, evaluateRules, fieldControlClass, fieldDescriptionClass, fieldErrorClass, fieldLabelClass, fieldMetaRequestsMarMedicationOrdersButton, fieldWrapperClass, isLabelVisible, useField, useFieldHandlers, useForm, useFormStore, useFrequentItems, usePackages, useSmartKeywords, validateField, validateForm };
|
|
1372
|
+
export { type AIDifferentialDiagnosisItem, AddInvestigationField, type AddInvestigationFieldProps, AddMedicationField, type AddMedicationFieldProps, type BaseFieldDef, type BiometryIolWorkupFieldDef, type BiometryIolWorkupValue, type BiometryMethod, type CheckboxFieldDef, type ColumnLayout, type Computation, type Condition, type CreateUploadHandlerOptions, type DataSource, type DiagnosisGradeSelection, type DiagnosisTextareaFieldDef, type DiagnosisTextareaValue, type DiagnosticPackage, type DiagnosticPackageTest, DifferentialDiagnosis, type DifferentialDiagnosisFieldDef, type DifferentialDiagnosisItem, type DifferentialDiagnosisProps, type DoctorFrequentItems, DynamicForm, DynamicFormV2, type DynamicFormV2Props, type DynamicFormV2SectionMode, EMAIL_REGEX, type EditableTableColumnDef, type EditableTableFieldDef, type EventDefinition, type ExtractedKeywordMatch, type FieldDef, type FieldHandler, type FieldHandlersMap, type FieldPrefill, FieldRenderer, FieldRequiredIndicator, type FieldState, type FieldStyleClassNames, type FieldStyleConfig, type FieldType, type FileUploadFieldDef, type FollowupFieldDef, type FollowupValue, FormControls, type FormControlsProps, type FormDef, type FormErrors, FormFileUploadWidget, FormProvider, type FormState, FormStore, type FormValues, type FormulaComputation, type FormulaExpr, type FunctionalImpairmentDimension, type FunctionalImpairmentScoreFieldDef, type FunctionalImpairmentScoreValue, type GeneralSurgeryExaminationFieldDef, type GeneralSurgeryGradingFieldDef, type GeneralSurgerySmartHistoryFieldDef, type ImageUploadFieldDef, ImageUploadWidget, type Investigation, type InvestigationFrequentItem, type InvestigationSearchResult, type InvestigationsFieldDef, type LayoutNode, type LensAssessmentFieldDef, type LensAssessmentValue, type LocsGrades, MAR_MEDICATION_ORDERS_META_KEY, type MatchedCondition, type MediaUploadFieldDef, MediaUploadWidget, type Medication, type MedicationFrequentItem, type MedicationSearchResult, type MedicationsFieldDef, MultiStepForm, type MultiStepFormProps, type MultiStepLayoutNode, type MultiStepNode, type NumberFieldDef, type OBGExaminationFieldDef, type OBGPathwayFieldDef, type OtpInputFieldDef, type OtpVerifiedValue, type PainScaleFlagsFieldDef, type Permission, type PhoneInputFieldDef, type PresignedUploadResponse, type ProcedureFrequentItem, type ProceduresFieldDef, type RadioFieldDef, ReadOnlyForm, ReadOnlyImageUpload, ReadOnlyMediaUpload, ReadOnlySignature, ReadOnlyTable, type ReferralFieldDef, type ReferralItem, type RepeatableFieldDef, type RichTextFieldDef, RichTextWidget, type Rule, type RuleAction, type RuleResult, type ScoreComputation, type ScoreRange, type Section, type SectionChild, type SelectFieldDef, type SelectOption, type SignatureFieldDef, SignatureUploadWidget, type SliderFieldDef, SmartForm, type SmartFormProps, type SmartKeywordsResult, type SmartTextareaFieldDef, type SmartTextareaValue, SmartTextareaWidget, type StaticTextFieldDef, type StoreAuthConfig, type StoreConfig, type SubmissionData, type SuggestionTextareaFieldDef, type SumComputation, type SurgicalRiskFlagsFieldDef, type SurgicalRiskFlagsValue, type TextFieldDef, type ToggleFieldDef, Upload, type UploadProps, type UrologyExaminationFieldDef, type UrologyPathwayFieldDef, type UrologySmartHistoryFieldDef, type ValidationRule, type VitalsFieldDef, type WebhookDef, type Workflow, type WorkflowTransition, createFileUploadHandler, createUploadHandler, evaluateRules, fieldControlClass, fieldDescriptionClass, fieldErrorClass, fieldLabelClass, fieldMetaRequestsMarMedicationOrdersButton, fieldWrapperClass, isLabelVisible, useField, useFieldHandlers, useForm, useFormStore, useFrequentItems, usePackages, useSmartKeywords, validateField, validateForm };
|
package/dist/index.d.ts
CHANGED
|
@@ -770,7 +770,10 @@ interface StoreConfig {
|
|
|
770
770
|
prefillData?: Record<string, any>;
|
|
771
771
|
role?: string;
|
|
772
772
|
onEvent?: EventListener;
|
|
773
|
+
/** Handler for image, media, and signature uploads; fallback for file upload when `onFileUpload` is omitted. */
|
|
773
774
|
onUpload?: UploadHandler;
|
|
775
|
+
/** Optional handler for `file_upload` fields only (`FormFileUploadWidget`). Uses `onUpload` when not set. */
|
|
776
|
+
onFileUpload?: UploadHandler;
|
|
774
777
|
onDraftChange?: DraftChangeHandler;
|
|
775
778
|
/**
|
|
776
779
|
* Auth / OTP configuration. Lets the host app supply the API base URL and
|
|
@@ -872,6 +875,8 @@ declare class FormStore {
|
|
|
872
875
|
*/
|
|
873
876
|
updateConfig(next: Partial<StoreConfig>): void;
|
|
874
877
|
getUploadHandler(): UploadHandler | undefined;
|
|
878
|
+
/** Resolved handler for `file_upload` widgets: `onFileUpload` ?? `onUpload`. */
|
|
879
|
+
getFileUploadHandler(): UploadHandler | undefined;
|
|
875
880
|
private preSubmitHandlers;
|
|
876
881
|
registerPreSubmitHandler(fieldId: string, fn: () => Promise<void>): void;
|
|
877
882
|
unregisterPreSubmitHandler(fieldId: string): void;
|
|
@@ -1194,14 +1199,23 @@ interface PresignedUploadResponse {
|
|
|
1194
1199
|
upload_method: 'PUT' | 'POST';
|
|
1195
1200
|
}
|
|
1196
1201
|
interface CreateUploadHandlerOptions {
|
|
1202
|
+
/** Data server origin (no trailing slash), e.g. `https://dataserver.example.com`. */
|
|
1197
1203
|
apiBaseUrl: string;
|
|
1198
1204
|
headers?: Record<string, string>;
|
|
1199
1205
|
}
|
|
1200
1206
|
/**
|
|
1201
|
-
*
|
|
1202
|
-
*
|
|
1207
|
+
* Handler for image / media / signature uploads: presign via
|
|
1208
|
+
* `POST …/api/forms/media-upload/` then PUT/POST file to `presigned_url`.
|
|
1209
|
+
* For `file_upload` fields with a different presign API, use
|
|
1210
|
+
* {@link createFileUploadHandler} as `config.onFileUpload`.
|
|
1203
1211
|
*/
|
|
1204
1212
|
declare function createUploadHandler(options: CreateUploadHandlerOptions): (file: File | Blob, filename: string) => Promise<string>;
|
|
1213
|
+
/**
|
|
1214
|
+
* Handler for `file_upload` fields (`FormFileUploadWidget`): presign via
|
|
1215
|
+
* `POST …/api/forms/media-presigned-get/` then PUT/POST file to `presigned_url`.
|
|
1216
|
+
* Pass this as `config.onFileUpload` on `FormProvider` (omit to use `onUpload` for files too).
|
|
1217
|
+
*/
|
|
1218
|
+
declare function createFileUploadHandler(options: CreateUploadHandlerOptions): (file: File | Blob, filename: string) => Promise<string>;
|
|
1205
1219
|
|
|
1206
1220
|
/** Shape of a medication as returned by AI analysis */
|
|
1207
1221
|
type AIMedication = {
|
|
@@ -1355,4 +1369,4 @@ declare const SmartTextareaWidget: React.FC<{
|
|
|
1355
1369
|
fieldId: string;
|
|
1356
1370
|
}>;
|
|
1357
1371
|
|
|
1358
|
-
export { type AIDifferentialDiagnosisItem, AddInvestigationField, type AddInvestigationFieldProps, AddMedicationField, type AddMedicationFieldProps, type BaseFieldDef, type BiometryIolWorkupFieldDef, type BiometryIolWorkupValue, type BiometryMethod, type CheckboxFieldDef, type ColumnLayout, type Computation, type Condition, type CreateUploadHandlerOptions, type DataSource, type DiagnosisGradeSelection, type DiagnosisTextareaFieldDef, type DiagnosisTextareaValue, type DiagnosticPackage, type DiagnosticPackageTest, DifferentialDiagnosis, type DifferentialDiagnosisFieldDef, type DifferentialDiagnosisItem, type DifferentialDiagnosisProps, type DoctorFrequentItems, DynamicForm, DynamicFormV2, type DynamicFormV2Props, type DynamicFormV2SectionMode, EMAIL_REGEX, type EditableTableColumnDef, type EditableTableFieldDef, type EventDefinition, type ExtractedKeywordMatch, type FieldDef, type FieldHandler, type FieldHandlersMap, type FieldPrefill, FieldRenderer, FieldRequiredIndicator, type FieldState, type FieldStyleClassNames, type FieldStyleConfig, type FieldType, type FileUploadFieldDef, type FollowupFieldDef, type FollowupValue, FormControls, type FormControlsProps, type FormDef, type FormErrors, FormFileUploadWidget, FormProvider, type FormState, FormStore, type FormValues, type FormulaComputation, type FormulaExpr, type FunctionalImpairmentDimension, type FunctionalImpairmentScoreFieldDef, type FunctionalImpairmentScoreValue, type GeneralSurgeryExaminationFieldDef, type GeneralSurgeryGradingFieldDef, type GeneralSurgerySmartHistoryFieldDef, type ImageUploadFieldDef, ImageUploadWidget, type Investigation, type InvestigationFrequentItem, type InvestigationSearchResult, type InvestigationsFieldDef, type LayoutNode, type LensAssessmentFieldDef, type LensAssessmentValue, type LocsGrades, MAR_MEDICATION_ORDERS_META_KEY, type MatchedCondition, type MediaUploadFieldDef, MediaUploadWidget, type Medication, type MedicationFrequentItem, type MedicationSearchResult, type MedicationsFieldDef, MultiStepForm, type MultiStepFormProps, type MultiStepLayoutNode, type MultiStepNode, type NumberFieldDef, type OBGExaminationFieldDef, type OBGPathwayFieldDef, type OtpInputFieldDef, type OtpVerifiedValue, type PainScaleFlagsFieldDef, type Permission, type PhoneInputFieldDef, type PresignedUploadResponse, type ProcedureFrequentItem, type ProceduresFieldDef, type RadioFieldDef, ReadOnlyForm, ReadOnlyImageUpload, ReadOnlyMediaUpload, ReadOnlySignature, ReadOnlyTable, type ReferralFieldDef, type ReferralItem, type RepeatableFieldDef, type RichTextFieldDef, RichTextWidget, type Rule, type RuleAction, type RuleResult, type ScoreComputation, type ScoreRange, type Section, type SectionChild, type SelectFieldDef, type SelectOption, type SignatureFieldDef, SignatureUploadWidget, type SliderFieldDef, SmartForm, type SmartFormProps, type SmartKeywordsResult, type SmartTextareaFieldDef, type SmartTextareaValue, SmartTextareaWidget, type StaticTextFieldDef, type StoreAuthConfig, type StoreConfig, type SubmissionData, type SuggestionTextareaFieldDef, type SumComputation, type SurgicalRiskFlagsFieldDef, type SurgicalRiskFlagsValue, type TextFieldDef, type ToggleFieldDef, Upload, type UploadProps, type UrologyExaminationFieldDef, type UrologyPathwayFieldDef, type UrologySmartHistoryFieldDef, type ValidationRule, type VitalsFieldDef, type WebhookDef, type Workflow, type WorkflowTransition, createUploadHandler, evaluateRules, fieldControlClass, fieldDescriptionClass, fieldErrorClass, fieldLabelClass, fieldMetaRequestsMarMedicationOrdersButton, fieldWrapperClass, isLabelVisible, useField, useFieldHandlers, useForm, useFormStore, useFrequentItems, usePackages, useSmartKeywords, validateField, validateForm };
|
|
1372
|
+
export { type AIDifferentialDiagnosisItem, AddInvestigationField, type AddInvestigationFieldProps, AddMedicationField, type AddMedicationFieldProps, type BaseFieldDef, type BiometryIolWorkupFieldDef, type BiometryIolWorkupValue, type BiometryMethod, type CheckboxFieldDef, type ColumnLayout, type Computation, type Condition, type CreateUploadHandlerOptions, type DataSource, type DiagnosisGradeSelection, type DiagnosisTextareaFieldDef, type DiagnosisTextareaValue, type DiagnosticPackage, type DiagnosticPackageTest, DifferentialDiagnosis, type DifferentialDiagnosisFieldDef, type DifferentialDiagnosisItem, type DifferentialDiagnosisProps, type DoctorFrequentItems, DynamicForm, DynamicFormV2, type DynamicFormV2Props, type DynamicFormV2SectionMode, EMAIL_REGEX, type EditableTableColumnDef, type EditableTableFieldDef, type EventDefinition, type ExtractedKeywordMatch, type FieldDef, type FieldHandler, type FieldHandlersMap, type FieldPrefill, FieldRenderer, FieldRequiredIndicator, type FieldState, type FieldStyleClassNames, type FieldStyleConfig, type FieldType, type FileUploadFieldDef, type FollowupFieldDef, type FollowupValue, FormControls, type FormControlsProps, type FormDef, type FormErrors, FormFileUploadWidget, FormProvider, type FormState, FormStore, type FormValues, type FormulaComputation, type FormulaExpr, type FunctionalImpairmentDimension, type FunctionalImpairmentScoreFieldDef, type FunctionalImpairmentScoreValue, type GeneralSurgeryExaminationFieldDef, type GeneralSurgeryGradingFieldDef, type GeneralSurgerySmartHistoryFieldDef, type ImageUploadFieldDef, ImageUploadWidget, type Investigation, type InvestigationFrequentItem, type InvestigationSearchResult, type InvestigationsFieldDef, type LayoutNode, type LensAssessmentFieldDef, type LensAssessmentValue, type LocsGrades, MAR_MEDICATION_ORDERS_META_KEY, type MatchedCondition, type MediaUploadFieldDef, MediaUploadWidget, type Medication, type MedicationFrequentItem, type MedicationSearchResult, type MedicationsFieldDef, MultiStepForm, type MultiStepFormProps, type MultiStepLayoutNode, type MultiStepNode, type NumberFieldDef, type OBGExaminationFieldDef, type OBGPathwayFieldDef, type OtpInputFieldDef, type OtpVerifiedValue, type PainScaleFlagsFieldDef, type Permission, type PhoneInputFieldDef, type PresignedUploadResponse, type ProcedureFrequentItem, type ProceduresFieldDef, type RadioFieldDef, ReadOnlyForm, ReadOnlyImageUpload, ReadOnlyMediaUpload, ReadOnlySignature, ReadOnlyTable, type ReferralFieldDef, type ReferralItem, type RepeatableFieldDef, type RichTextFieldDef, RichTextWidget, type Rule, type RuleAction, type RuleResult, type ScoreComputation, type ScoreRange, type Section, type SectionChild, type SelectFieldDef, type SelectOption, type SignatureFieldDef, SignatureUploadWidget, type SliderFieldDef, SmartForm, type SmartFormProps, type SmartKeywordsResult, type SmartTextareaFieldDef, type SmartTextareaValue, SmartTextareaWidget, type StaticTextFieldDef, type StoreAuthConfig, type StoreConfig, type SubmissionData, type SuggestionTextareaFieldDef, type SumComputation, type SurgicalRiskFlagsFieldDef, type SurgicalRiskFlagsValue, type TextFieldDef, type ToggleFieldDef, Upload, type UploadProps, type UrologyExaminationFieldDef, type UrologyPathwayFieldDef, type UrologySmartHistoryFieldDef, type ValidationRule, type VitalsFieldDef, type WebhookDef, type Workflow, type WorkflowTransition, createFileUploadHandler, createUploadHandler, evaluateRules, fieldControlClass, fieldDescriptionClass, fieldErrorClass, fieldLabelClass, fieldMetaRequestsMarMedicationOrdersButton, fieldWrapperClass, isLabelVisible, useField, useFieldHandlers, useForm, useFormStore, useFrequentItems, usePackages, useSmartKeywords, validateField, validateForm };
|
package/dist/index.mjs
CHANGED
|
@@ -1710,6 +1710,8 @@ var FormStore = class {
|
|
|
1710
1710
|
updateConfig(next) {
|
|
1711
1711
|
let needsReeval = false;
|
|
1712
1712
|
if (next.onUpload !== void 0) this.config.onUpload = next.onUpload;
|
|
1713
|
+
if (next.onFileUpload !== void 0)
|
|
1714
|
+
this.config.onFileUpload = next.onFileUpload;
|
|
1713
1715
|
if (next.onEvent !== void 0) this.config.onEvent = next.onEvent;
|
|
1714
1716
|
if (next.onDraftChange !== void 0) this.config.onDraftChange = next.onDraftChange;
|
|
1715
1717
|
if (next.voice !== void 0) this.config.voice = next.voice;
|
|
@@ -1730,6 +1732,10 @@ var FormStore = class {
|
|
|
1730
1732
|
getUploadHandler() {
|
|
1731
1733
|
return this.config.onUpload;
|
|
1732
1734
|
}
|
|
1735
|
+
/** Resolved handler for `file_upload` widgets: `onFileUpload` ?? `onUpload`. */
|
|
1736
|
+
getFileUploadHandler() {
|
|
1737
|
+
return this.config.onFileUpload ?? this.config.onUpload;
|
|
1738
|
+
}
|
|
1733
1739
|
preSubmitHandlers = /* @__PURE__ */ new Map();
|
|
1734
1740
|
registerPreSubmitHandler(fieldId, fn) {
|
|
1735
1741
|
this.preSubmitHandlers.set(fieldId, fn);
|
|
@@ -4038,7 +4044,7 @@ var FormFileUploadWidget = ({
|
|
|
4038
4044
|
const accept = def.accept ?? "*/*";
|
|
4039
4045
|
const maxSize = def.maxSize ?? 10 * 1024 * 1024;
|
|
4040
4046
|
const allowMultiple = def.multiple === true;
|
|
4041
|
-
const uploadHandler = store.
|
|
4047
|
+
const uploadHandler = store.getFileUploadHandler();
|
|
4042
4048
|
const showLabel = isLabelVisible(fieldDef);
|
|
4043
4049
|
if (!uploadHandler) {
|
|
4044
4050
|
return /* @__PURE__ */ jsxs("div", { className: fieldWrapperClass(fieldDef, "space-y-2"), children: [
|
|
@@ -4047,7 +4053,7 @@ var FormFileUploadWidget = ({
|
|
|
4047
4053
|
" ",
|
|
4048
4054
|
/* @__PURE__ */ jsx(FieldRequiredIndicator, { fieldDef })
|
|
4049
4055
|
] }) : null,
|
|
4050
|
-
/* @__PURE__ */ jsx("div", { className: "border-2 border-red-300 rounded-lg p-4 bg-red-50", children: /* @__PURE__ */ jsx("p", { className: "text-sm text-red-600", children: "Upload handler not configured.
|
|
4056
|
+
/* @__PURE__ */ jsx("div", { className: "border-2 border-red-300 rounded-lg p-4 bg-red-50", children: /* @__PURE__ */ jsx("p", { className: "text-sm text-red-600", children: "Upload handler not configured. Provide `config.onFileUpload` or `config.onUpload` on FormProvider." }) })
|
|
4051
4057
|
] });
|
|
4052
4058
|
}
|
|
4053
4059
|
const hasStoredValue = value !== null && value !== void 0 && value !== "" && !(Array.isArray(value) && value.length === 0);
|
|
@@ -16287,35 +16293,54 @@ var FormControls = ({
|
|
|
16287
16293
|
};
|
|
16288
16294
|
|
|
16289
16295
|
// src/utils/createUploadHandler.ts
|
|
16290
|
-
function
|
|
16296
|
+
function normalizeBaseUrl(apiBaseUrl) {
|
|
16297
|
+
return apiBaseUrl.replace(/\/+$/, "");
|
|
16298
|
+
}
|
|
16299
|
+
async function uploadViaPresignedEndpoint(options, presignPath, file, filename) {
|
|
16291
16300
|
const { apiBaseUrl, headers = {} } = options;
|
|
16292
|
-
|
|
16293
|
-
|
|
16294
|
-
|
|
16295
|
-
|
|
16296
|
-
|
|
16297
|
-
|
|
16298
|
-
|
|
16299
|
-
|
|
16300
|
-
})
|
|
16301
|
-
|
|
16302
|
-
|
|
16303
|
-
}
|
|
16304
|
-
|
|
16305
|
-
|
|
16306
|
-
|
|
16307
|
-
|
|
16308
|
-
|
|
16309
|
-
|
|
16310
|
-
|
|
16311
|
-
|
|
16312
|
-
|
|
16313
|
-
|
|
16314
|
-
}
|
|
16315
|
-
|
|
16316
|
-
|
|
16301
|
+
const base = normalizeBaseUrl(apiBaseUrl);
|
|
16302
|
+
const path = presignPath.startsWith("/") ? presignPath : `/${presignPath}`;
|
|
16303
|
+
const response = await fetch(`${base}${path}`, {
|
|
16304
|
+
method: "POST",
|
|
16305
|
+
headers: {
|
|
16306
|
+
"Content-Type": "application/json",
|
|
16307
|
+
...headers
|
|
16308
|
+
},
|
|
16309
|
+
body: JSON.stringify({ filename })
|
|
16310
|
+
});
|
|
16311
|
+
if (!response.ok) {
|
|
16312
|
+
throw new Error(`Failed to get presigned URL: ${response.statusText}`);
|
|
16313
|
+
}
|
|
16314
|
+
const presignedData = await response.json();
|
|
16315
|
+
const uploadResponse = await fetch(presignedData.presigned_url, {
|
|
16316
|
+
method: presignedData.upload_method,
|
|
16317
|
+
headers: {
|
|
16318
|
+
"Content-Type": presignedData.content_type
|
|
16319
|
+
},
|
|
16320
|
+
body: file
|
|
16321
|
+
});
|
|
16322
|
+
if (!uploadResponse.ok) {
|
|
16323
|
+
throw new Error(`Failed to upload file: ${uploadResponse.statusText}`);
|
|
16324
|
+
}
|
|
16325
|
+
return presignedData.s3_key;
|
|
16326
|
+
}
|
|
16327
|
+
function createUploadHandler(options) {
|
|
16328
|
+
return async (file, filename) => uploadViaPresignedEndpoint(
|
|
16329
|
+
options,
|
|
16330
|
+
"/api/forms/media-upload/",
|
|
16331
|
+
file,
|
|
16332
|
+
filename
|
|
16333
|
+
);
|
|
16334
|
+
}
|
|
16335
|
+
function createFileUploadHandler(options) {
|
|
16336
|
+
return async (file, filename) => uploadViaPresignedEndpoint(
|
|
16337
|
+
options,
|
|
16338
|
+
"/api/forms/media-presigned-get/",
|
|
16339
|
+
file,
|
|
16340
|
+
filename
|
|
16341
|
+
);
|
|
16317
16342
|
}
|
|
16318
16343
|
|
|
16319
|
-
export { AddInvestigationField, AddMedicationField, DifferentialDiagnosis, DynamicForm, DynamicFormV2, EMAIL_REGEX, FieldRenderer, FieldRequiredIndicator, FormControls, FormFileUploadWidget, FormProvider, FormStore, ImageUploadWidget, MAR_MEDICATION_ORDERS_META_KEY, MediaUploadWidget, MultiStepForm, ReadOnlyForm, ReadOnlyImageUpload, ReadOnlyMediaUpload, ReadOnlySignature, ReadOnlyTable, RichTextWidget, SignatureUploadWidget, SmartForm, SmartTextareaWidget, Upload3 as Upload, createUploadHandler, evaluateRules, fieldControlClass, fieldDescriptionClass, fieldErrorClass, fieldLabelClass, fieldMetaRequestsMarMedicationOrdersButton, fieldWrapperClass, isLabelVisible, useField, useFieldHandlers, useForm, useFormStore, useFrequentItems, usePackages, useSmartKeywords, validateField, validateForm };
|
|
16344
|
+
export { AddInvestigationField, AddMedicationField, DifferentialDiagnosis, DynamicForm, DynamicFormV2, EMAIL_REGEX, FieldRenderer, FieldRequiredIndicator, FormControls, FormFileUploadWidget, FormProvider, FormStore, ImageUploadWidget, MAR_MEDICATION_ORDERS_META_KEY, MediaUploadWidget, MultiStepForm, ReadOnlyForm, ReadOnlyImageUpload, ReadOnlyMediaUpload, ReadOnlySignature, ReadOnlyTable, RichTextWidget, SignatureUploadWidget, SmartForm, SmartTextareaWidget, Upload3 as Upload, createFileUploadHandler, createUploadHandler, evaluateRules, fieldControlClass, fieldDescriptionClass, fieldErrorClass, fieldLabelClass, fieldMetaRequestsMarMedicationOrdersButton, fieldWrapperClass, isLabelVisible, useField, useFieldHandlers, useForm, useFormStore, useFrequentItems, usePackages, useSmartKeywords, validateField, validateForm };
|
|
16320
16345
|
//# sourceMappingURL=index.mjs.map
|
|
16321
16346
|
//# sourceMappingURL=index.mjs.map
|