formanitor 0.0.43 → 0.0.44

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 CHANGED
@@ -12095,6 +12095,75 @@ var DynamicForm = () => {
12095
12095
  })
12096
12096
  ] });
12097
12097
  };
12098
+ function PlainSection({
12099
+ title,
12100
+ showHeading,
12101
+ children
12102
+ }) {
12103
+ return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "mb-6 space-y-4", children: [
12104
+ showHeading ? /* @__PURE__ */ jsxRuntime.jsx("h2", { className: "text-base font-medium text-foreground", children: title }) : null,
12105
+ children
12106
+ ] });
12107
+ }
12108
+ function renderSectionChildren(children) {
12109
+ return children.map((child, index) => {
12110
+ if (typeof child === "string") {
12111
+ return /* @__PURE__ */ jsxRuntime.jsx(FieldRenderer, { fieldId: child }, child);
12112
+ }
12113
+ if (child.type === "column_layout") {
12114
+ return /* @__PURE__ */ jsxRuntime.jsx(
12115
+ ColumnLayout,
12116
+ {
12117
+ columns: child.columns,
12118
+ label: child.label,
12119
+ children: child.children.map((fieldId) => /* @__PURE__ */ jsxRuntime.jsx(FieldRenderer, { fieldId }, fieldId))
12120
+ },
12121
+ child.id
12122
+ );
12123
+ }
12124
+ return /* @__PURE__ */ jsxRuntime.jsx(React15__namespace.default.Fragment, {}, index);
12125
+ });
12126
+ }
12127
+ var DynamicFormV2 = ({
12128
+ showTitle = true,
12129
+ sectionMode = "plain",
12130
+ showSectionTitles = true,
12131
+ className
12132
+ }) => {
12133
+ const store = useFormStore();
12134
+ const schema = store.getSchema();
12135
+ return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: cn("space-y-6", className), children: [
12136
+ showTitle ? /* @__PURE__ */ jsxRuntime.jsx("div", { className: "mb-4", children: /* @__PURE__ */ jsxRuntime.jsx("h1", { className: "text-2xl font-bold", children: schema.title }) }) : null,
12137
+ schema.layout.map((node) => {
12138
+ if (node.type === "section") {
12139
+ if (sectionMode === "accordion") {
12140
+ return /* @__PURE__ */ jsxRuntime.jsx(Section, { title: node.title, children: renderSectionChildren(node.children) }, node.id);
12141
+ }
12142
+ return /* @__PURE__ */ jsxRuntime.jsx(
12143
+ PlainSection,
12144
+ {
12145
+ title: node.title,
12146
+ showHeading: showSectionTitles,
12147
+ children: renderSectionChildren(node.children)
12148
+ },
12149
+ node.id
12150
+ );
12151
+ }
12152
+ if (node.type === "column_layout") {
12153
+ return /* @__PURE__ */ jsxRuntime.jsx(
12154
+ ColumnLayout,
12155
+ {
12156
+ columns: node.columns,
12157
+ label: node.label,
12158
+ children: node.children.map((fieldId) => /* @__PURE__ */ jsxRuntime.jsx(FieldRenderer, { fieldId }, fieldId))
12159
+ },
12160
+ node.id
12161
+ );
12162
+ }
12163
+ return null;
12164
+ })
12165
+ ] });
12166
+ };
12098
12167
  var SUGGESTION_KEYS = /* @__PURE__ */ new Set(["medications", "investigations", "procedures"]);
12099
12168
  function shallowEqualKeys(a, b) {
12100
12169
  const keysA = Object.keys(a);
@@ -13022,65 +13091,126 @@ var ReadOnlyForm = ({ schema, submission }) => {
13022
13091
  };
13023
13092
  var FormControls = ({
13024
13093
  className,
13094
+ containerStyle,
13095
+ showWorkflowStatus = true,
13096
+ statusClassName,
13097
+ statusStyle,
13098
+ actionsClassName,
13099
+ actionsStyle,
13100
+ actionsFullWidth = false,
13101
+ buttonClassName,
13025
13102
  onSaveDraft,
13026
13103
  onSubmit
13027
13104
  }) => {
13028
- const { state, availableTransitions, submit, transition, hasPersistence, markSubmitAttempted } = useForm();
13105
+ const {
13106
+ state,
13107
+ availableTransitions,
13108
+ submit,
13109
+ transition,
13110
+ hasPersistence,
13111
+ markSubmitAttempted
13112
+ } = useForm();
13029
13113
  const hasUploadsInFlight = (state.pendingUploads ?? 0) > 0;
13030
13114
  const draftAvailable = onSaveDraft || hasPersistence && submit;
13031
13115
  const submitAvailable = onSubmit || availableTransitions.length > 0 && transition;
13032
13116
  if (!draftAvailable && !submitAvailable) {
13033
13117
  return null;
13034
13118
  }
13035
- return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: `flex gap-4 items-center justify-between p-4 border-t bg-white ${className || ""}`, children: [
13036
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center gap-4", children: [
13037
- /* @__PURE__ */ jsxRuntime.jsxs("span", { className: "font-bold text-sm text-gray-700", children: [
13038
- "State: ",
13039
- state.workflowState
13040
- ] }),
13041
- /* @__PURE__ */ jsxRuntime.jsx("span", { className: `text-sm ${state.isValid ? "text-green-600" : "text-red-600"}`, children: state.isValid ? "Valid" : "Invalid" })
13042
- ] }),
13043
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex gap-2", children: [
13044
- draftAvailable && /* @__PURE__ */ jsxRuntime.jsx(
13045
- Button,
13046
- {
13047
- onClick: onSaveDraft || submit,
13048
- variant: "outline",
13049
- size: "sm",
13050
- disabled: hasUploadsInFlight,
13051
- children: hasUploadsInFlight ? "Upload in progress\u2026" : "Save Draft"
13052
- }
13119
+ const useWideActions = !showWorkflowStatus && actionsFullWidth;
13120
+ const buttonCn = cn(
13121
+ buttonClassName,
13122
+ useWideActions && "w-full sm:flex-1 min-w-0"
13123
+ );
13124
+ return /* @__PURE__ */ jsxRuntime.jsxs(
13125
+ "div",
13126
+ {
13127
+ className: cn(
13128
+ "flex gap-4 border-t bg-white p-4 items-center",
13129
+ showWorkflowStatus ? "justify-between" : useWideActions ? "flex-col sm:flex-row sm:justify-stretch sm:gap-4" : "justify-end",
13130
+ className
13053
13131
  ),
13054
- submitAvailable && /* @__PURE__ */ jsxRuntime.jsx(jsxRuntime.Fragment, { children: availableTransitions.length > 0 ? availableTransitions.map((t) => /* @__PURE__ */ jsxRuntime.jsx(
13055
- Button,
13056
- {
13057
- onClick: () => {
13058
- markSubmitAttempted();
13059
- if (onSubmit) {
13060
- onSubmit(t.to);
13061
- } else {
13062
- transition(t.to);
13063
- }
13064
- },
13065
- disabled: !state.isValid || hasUploadsInFlight,
13066
- size: "sm",
13067
- children: hasUploadsInFlight ? "Upload in progress\u2026" : availableTransitions.length > 1 ? `Submit to ${t.to}` : "Submit"
13068
- },
13069
- t.to
13070
- )) : onSubmit ? /* @__PURE__ */ jsxRuntime.jsx(
13071
- Button,
13072
- {
13073
- onClick: () => {
13074
- markSubmitAttempted();
13075
- onSubmit(state.workflowState || "submit");
13076
- },
13077
- disabled: !state.isValid || hasUploadsInFlight,
13078
- size: "sm",
13079
- children: hasUploadsInFlight ? "Upload in progress\u2026" : "Submit"
13080
- }
13081
- ) : null })
13082
- ] })
13083
- ] });
13132
+ style: containerStyle,
13133
+ children: [
13134
+ showWorkflowStatus ? /* @__PURE__ */ jsxRuntime.jsxs(
13135
+ "div",
13136
+ {
13137
+ className: cn("flex items-center gap-4", statusClassName),
13138
+ style: statusStyle,
13139
+ children: [
13140
+ /* @__PURE__ */ jsxRuntime.jsxs("span", { className: "font-bold text-sm text-gray-700", children: [
13141
+ "State: ",
13142
+ state.workflowState
13143
+ ] }),
13144
+ /* @__PURE__ */ jsxRuntime.jsx(
13145
+ "span",
13146
+ {
13147
+ className: cn(
13148
+ "text-sm",
13149
+ state.isValid ? "text-green-600" : "text-red-600"
13150
+ ),
13151
+ children: state.isValid ? "Valid" : "Invalid"
13152
+ }
13153
+ )
13154
+ ]
13155
+ }
13156
+ ) : null,
13157
+ /* @__PURE__ */ jsxRuntime.jsxs(
13158
+ "div",
13159
+ {
13160
+ className: cn(
13161
+ "flex gap-2",
13162
+ useWideActions ? "w-full flex-col sm:flex-row sm:flex-1 sm:justify-end sm:max-w-none" : "flex-shrink-0",
13163
+ actionsClassName
13164
+ ),
13165
+ style: actionsStyle,
13166
+ children: [
13167
+ draftAvailable && /* @__PURE__ */ jsxRuntime.jsx(
13168
+ Button,
13169
+ {
13170
+ onClick: onSaveDraft || submit,
13171
+ variant: "outline",
13172
+ size: "sm",
13173
+ disabled: hasUploadsInFlight,
13174
+ className: buttonCn,
13175
+ children: hasUploadsInFlight ? "Upload in progress\u2026" : "Save Draft"
13176
+ }
13177
+ ),
13178
+ submitAvailable && /* @__PURE__ */ jsxRuntime.jsx(jsxRuntime.Fragment, { children: availableTransitions.length > 0 ? availableTransitions.map((t) => /* @__PURE__ */ jsxRuntime.jsx(
13179
+ Button,
13180
+ {
13181
+ onClick: () => {
13182
+ markSubmitAttempted();
13183
+ if (onSubmit) {
13184
+ onSubmit(t.to);
13185
+ } else {
13186
+ transition(t.to);
13187
+ }
13188
+ },
13189
+ disabled: !state.isValid || hasUploadsInFlight,
13190
+ size: "sm",
13191
+ className: buttonCn,
13192
+ children: hasUploadsInFlight ? "Upload in progress\u2026" : availableTransitions.length > 1 ? `Submit to ${t.to}` : "Submit"
13193
+ },
13194
+ t.to
13195
+ )) : onSubmit ? /* @__PURE__ */ jsxRuntime.jsx(
13196
+ Button,
13197
+ {
13198
+ onClick: () => {
13199
+ markSubmitAttempted();
13200
+ onSubmit(state.workflowState || "submit");
13201
+ },
13202
+ disabled: !state.isValid || hasUploadsInFlight,
13203
+ size: "sm",
13204
+ className: buttonCn,
13205
+ children: hasUploadsInFlight ? "Upload in progress\u2026" : "Submit"
13206
+ }
13207
+ ) : null })
13208
+ ]
13209
+ }
13210
+ )
13211
+ ]
13212
+ }
13213
+ );
13084
13214
  };
13085
13215
 
13086
13216
  // src/utils/createUploadHandler.ts
@@ -13117,6 +13247,7 @@ exports.AddInvestigationField = AddInvestigationField;
13117
13247
  exports.AddMedicationField = AddMedicationField;
13118
13248
  exports.DifferentialDiagnosis = DifferentialDiagnosis;
13119
13249
  exports.DynamicForm = DynamicForm;
13250
+ exports.DynamicFormV2 = DynamicFormV2;
13120
13251
  exports.EMAIL_REGEX = EMAIL_REGEX;
13121
13252
  exports.FieldRenderer = FieldRenderer;
13122
13253
  exports.FormControls = FormControls;