@invana/blocks 0.0.32 → 0.0.34

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
@@ -759,12 +759,17 @@ var FIELD_TYPE = {
759
759
  number: "number",
760
760
  text: "text",
761
761
  date: "text",
762
- select: "select"
762
+ select: "select",
763
+ textarea: "textarea",
764
+ checkbox: "boolean",
765
+ radio: "radio"
763
766
  };
764
- function boundsRule(f) {
765
- if (f.above == null && f.below == null) return void 0;
767
+ var blank = (v) => v == null || typeof v === "string" && v.trim() === "";
768
+ function rules(f) {
769
+ if (!f.required && f.above == null && f.below == null) return void 0;
766
770
  return {
767
771
  validate: (v) => {
772
+ if (f.required && (f.type === "checkbox" ? v !== true : blank(v))) return "Required";
768
773
  const n = Number(v);
769
774
  if (f.above != null && !(n > f.above)) return `Must be above ${f.above}`;
770
775
  if (f.below != null && !(n < f.below)) return `Must be below ${f.below}`;
@@ -772,22 +777,41 @@ function boundsRule(f) {
772
777
  }
773
778
  };
774
779
  }
780
+ function optionsOf(f) {
781
+ if (f.options) return f.options;
782
+ if (f.type === "select" && f.default != null) {
783
+ return [{ value: String(f.default), label: String(f.default) }];
784
+ }
785
+ return void 0;
786
+ }
775
787
  var toField = (f) => ({
776
788
  name: f.name,
777
789
  type: FIELD_TYPE[f.type],
790
+ control: f.type === "checkbox" ? "checkbox" : void 0,
778
791
  label: f.label,
779
792
  unit: f.unit,
780
793
  aside: f.aside,
781
794
  description: f.hint,
782
795
  group: f.group,
783
- rules: boundsRule(f),
784
- placeholder: ""
796
+ options: optionsOf(f),
797
+ rows: f.rows,
798
+ disabled: f.disabled,
799
+ rules: rules(f),
800
+ placeholder: f.placeholder ?? "",
801
+ // A long answer takes the row; so does a list of described choices.
802
+ colSpan: f.type === "textarea" || f.type === "radio" && f.options?.some((o) => o.description) ? 2 : void 0
785
803
  });
804
+ var initial = (f) => f.type === "checkbox" ? f.default ?? false : f.default;
786
805
  function withUnit(value, unit) {
787
806
  if (value == null || value === "") return "\u2014";
788
807
  if (!unit) return String(value);
789
808
  return /^[A-Za-z]/.test(unit) ? `${value} ${unit}` : `${value}${unit}`;
790
809
  }
810
+ function answerOf(f, value) {
811
+ if (f.type === "checkbox") return value === true ? "Yes" : "No";
812
+ const picked = f.options?.find((o) => o.value === value);
813
+ return picked ? picked.label : withUnit(value, f.unit);
814
+ }
791
815
  function FormAsk({ spec, state = "pending", value: given, onAction }) {
792
816
  const auto = React18__namespace.useId();
793
817
  const pending = state === "pending";
@@ -795,14 +819,14 @@ function FormAsk({ spec, state = "pending", value: given, onAction }) {
795
819
  const current = given ?? {};
796
820
  const top = spec.labels === "top";
797
821
  const defaults = Object.fromEntries(
798
- spec.fields.map((f) => [f.name, pending ? f.default : current[f.name]])
822
+ spec.fields.map((f) => [f.name, pending ? initial(f) : current[f.name]])
799
823
  );
800
824
  const form = reactHookForm.useForm({ defaultValues: { values: defaults }, mode: "onChange" });
801
825
  if (!pending && !editing) {
802
826
  return /* @__PURE__ */ jsxRuntime.jsx(
803
827
  AskSummary,
804
828
  {
805
- rows: spec.fields.map((f) => ({ label: f.label, value: withUnit(current[f.name], f.unit) })),
829
+ rows: spec.fields.map((f) => ({ label: f.label, value: answerOf(f, current[f.name]) })),
806
830
  change: state === "answered" ? "Change inputs" : void 0,
807
831
  onChange: () => setEditing(true)
808
832
  }
@@ -1237,7 +1261,7 @@ function MultistepAsk({ spec, state = "pending", value: given, onAction }) {
1237
1261
  setEditing(false);
1238
1262
  setReview(null);
1239
1263
  };
1240
- const initial = (step2) => editing ? current[step2.id] : "default" in step2 ? step2.default : void 0;
1264
+ const initial2 = (step2) => editing ? current[step2.id] : "default" in step2 ? step2.default : void 0;
1241
1265
  const index = Math.max(0, steps.findIndex((s) => s.id === item));
1242
1266
  const step = steps[index];
1243
1267
  const last = index === steps.length - 1;
@@ -1260,7 +1284,7 @@ function MultistepAsk({ spec, state = "pending", value: given, onAction }) {
1260
1284
  StepItem,
1261
1285
  {
1262
1286
  step: s,
1263
- value: initial(s),
1287
+ value: initial2(s),
1264
1288
  onStatusChange: (st) => setStatus((now) => ({ ...now, [s.id]: st }))
1265
1289
  },
1266
1290
  s.id
@@ -1578,7 +1602,7 @@ function CellText({ cell }) {
1578
1602
  }
1579
1603
  );
1580
1604
  }
1581
- function TableBlock({ spec, onAction }) {
1605
+ function TableBlock({ spec, onAction, seamless }) {
1582
1606
  const truncated = spec.total != null && spec.total > spec.rows.length;
1583
1607
  const highlighted = new Set(spec.highlight?.map((i) => spec.rows[i]));
1584
1608
  const data = spec.totals ? [...spec.rows, spec.totals] : spec.rows;
@@ -1601,7 +1625,8 @@ function TableBlock({ spec, onAction }) {
1601
1625
  columns,
1602
1626
  data,
1603
1627
  density: "compact",
1604
- seamless: true,
1628
+ bordered: false,
1629
+ seamless,
1605
1630
  enableSorting: false,
1606
1631
  enableColumnVisibility: false,
1607
1632
  minWidth: spec.columns.length > FITS ? spec.columns.length * COLUMN_MIN : void 0,