@pipelex/mthds-form 0.28.0 → 0.29.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/core/gate.js CHANGED
@@ -1,8 +1,8 @@
1
- export { apiInputsFromSchemaData, buildRunInputsSchema, gateRunInputs, prepareRunInputs, validateRunInputs } from '../chunk-4DPYGNJ3.js';
1
+ export { apiInputsFromSchemaData, buildRunInputsSchema, gateRunInputs, prepareRunInputs, validateRunInputs } from '../chunk-IBBAJXIO.js';
2
2
  import '../chunk-E6BIXJ6C.js';
3
+ import '../chunk-XO5OENNF.js';
3
4
  import '../chunk-Y2ND6W4W.js';
4
5
  import '../chunk-LBFZXYCY.js';
5
- import '../chunk-XO5OENNF.js';
6
6
  import '../chunk-OD3VYXUY.js';
7
7
  import '../chunk-WYH56SOZ.js';
8
8
  import '../chunk-V3OV2XQT.js';
@@ -0,0 +1,77 @@
1
+ /**
2
+ * What a person reads in place of an identifier: a field's name, and the value
3
+ * of a choice. Headless, so a host that draws its own choice control, a server
4
+ * that writes a summary and the package's own controls all word a value the
5
+ * same way.
6
+ *
7
+ * The descriptor carries an enum's values and nothing else: the standard has no
8
+ * display label for an option, and none is wanted. Its label is derived from
9
+ * the value here, by rule, and only what a person reads changes: the value a
10
+ * form stores, the JSON view, the copy control and the download all keep the
11
+ * code.
12
+ */
13
+ /**
14
+ * `full_name` → `Full name`. Only the first word is capitalised: these are
15
+ * labels, not titles, and Title Case on every word reads as a form from 2009.
16
+ * Takes IDENTIFIERS only - snake_case or kebab-case names, where a separator
17
+ * is structure. An authored `title` never goes through here: it is already
18
+ * human-facing, and its hyphens are spelling (`E-mail address`), not structure.
19
+ */
20
+ declare function humanizeFieldName(name: string): string;
21
+ /**
22
+ * An enum CODE as words: `keynote` → `Keynote`, `unit_price_differs_from_po`
23
+ * → `Unit price differs from po`, `HIGH_RISK` → `High risk`.
24
+ *
25
+ * It is `humanizeFieldName`, applied after an all-caps code of several words is
26
+ * lowercased. The capitals of `HIGH_RISK` are a convention of the code, not an
27
+ * emphasis its author meant, and "HIGH RISK" on a sentence-case page reads as
28
+ * an alarm.
29
+ *
30
+ * A single all-caps token is left exactly as written: `USD`, `EUR`, `OK` and
31
+ * `HIGH` hold no separator, and a lone capitalised word is far more often an
32
+ * acronym, a unit or a currency than a shouted word, so lowercasing it would
33
+ * misspell it ("Usd"). Only a code that is several words joined by `_` or `-`
34
+ * is taken to be capitalised by convention.
35
+ *
36
+ * Acronyms inside a longer code are not guessed: `po` stays `po` where a reader
37
+ * expects `PO`, just as a field name does. That is the price of deriving the
38
+ * label from the value rather than carrying one on the wire, and it is paid
39
+ * knowingly: a method's author who wants `PO` read writes the code so that it
40
+ * reads.
41
+ *
42
+ * Only a code is humanised. A value that is not an identifier is authored
43
+ * words already, and its separators are spelling rather than structure, so it
44
+ * is shown verbatim: `18-24`, `N/A` and `Very satisfied` do not start with a
45
+ * letter or hold something other than letters, digits, `_` and `-`. That is
46
+ * the line `humanizeFieldName` draws between an identifier and an authored
47
+ * title.
48
+ *
49
+ * This words ONE code, with no knowledge of the enum it belongs to. A choice
50
+ * control goes one step further: when two options of one enum would read the
51
+ * same, it shows that enum's codes instead (see `enumValueLabeler`).
52
+ */
53
+ declare function humanizeEnumValue(code: string): string;
54
+ /**
55
+ * How ONE enum's values read, as words: the labeler every choice control and
56
+ * every enum result goes through, so the options a form offers, the value a
57
+ * result shows and a host's own chips read alike. Built from the enum's
58
+ * options, it maps a value to what a person reads.
59
+ *
60
+ * A declared option reads as words (`humanizeEnumValue`), except in two cases,
61
+ * where the code is shown as written:
62
+ *
63
+ * - **Every option, when two of them would read the same.** `high_risk` and
64
+ * `HIGH_RISK`, or `foo-bar` and `foo_bar`, are distinct codes that humanise
65
+ * to one label, and a person offered two identical choices is choosing
66
+ * blind. Wording the others while showing those two as codes would make one
67
+ * enum read in two registers, so the whole enum falls back.
68
+ * - **A value the enum does not declare.** It is the payload disagreeing with
69
+ * its descriptor, and worded it could pass for an option it is not.
70
+ *
71
+ * This is the wording, not the decision to word: a builder-facing surface that
72
+ * must show the code the bundle spells (the control set's `studio`
73
+ * presentation) does not call it.
74
+ */
75
+ declare function enumValueLabeler(options: readonly string[]): (value: string) => string;
76
+
77
+ export { enumValueLabeler, humanizeEnumValue, humanizeFieldName };
@@ -0,0 +1,3 @@
1
+ export { enumValueLabeler, humanizeEnumValue, humanizeFieldName } from '../chunk-GHVVULHY.js';
2
+ //# sourceMappingURL=humanize.js.map
3
+ //# sourceMappingURL=humanize.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":[],"names":[],"mappings":"","file":"humanize.js"}
@@ -1,4 +1,5 @@
1
1
  export { BooleanRunField, ConceptCategory, DateRunField, EnumRunField, FileRunField, ListRunField, NumberRunField, ObjectRunField, ProseRunField, RunField, RunFieldCommon, RunFieldKind, TextConstraints, TextRunField, UnknownRunField, conceptCategory } from './descriptor.js';
2
+ export { enumValueLabeler, humanizeEnumValue, humanizeFieldName } from './humanize.js';
2
3
  export { IOMultiplicity, InputForm, InputFormTopLevelField, OutputForm, PipeIOContract, PipeIOContracts, PipeInputContract, PipeInputFormDescriptor, PipeOutputContract, PipeOutputFormDescriptor } from 'mthds/protocol';
3
4
  export { buildResultField, buildRunFields, getPipeInputForm } from './derive.js';
4
5
  export { getPipeOutputForm } from './output-form.js';
@@ -4,17 +4,18 @@ export { addChosenFiles, chosenFilesAdded, roomForChosenFiles, sourceFileValue }
4
4
  export { collectStuffFiles } from '../chunk-56WECFBD.js';
5
5
  export { describeValidationError, displayValue, valueAtProperty } from '../chunk-RPA7DNSK.js';
6
6
  export { apiInputsFromRunValues, fieldsForContract, inputDataFromWorkingMemory, outputsFromPipeOutput, rjsfDataFromRunValues, runValuesFromInputs, runValuesFromStore, sameRunValues, setValueAtPath, storeInputDataFromRunValues } from '../chunk-ZX52CQJ4.js';
7
+ export { enumValueLabeler, humanizeEnumValue, humanizeFieldName } from '../chunk-GHVVULHY.js';
7
8
  export { narrowFileFormats } from '../chunk-CAKQ5VFT.js';
8
9
  export { NATIVE_CHOICE_CONCEPT_REF, NATIVE_COMPOSITE_CONCEPT_REF, NATIVE_DATE_CONCEPT_REF, NATIVE_HTML_CONCEPT_REF, NATIVE_PAGE_CONCEPT_REF, NATIVE_RATING_CONCEPT_REF, NATIVE_SEARCH_RESULT_CONCEPT_REF, NATIVE_YES_NO_CONCEPT_REF, TYPED_SCALAR_MARKERS, citedSource, formatDateContent, hasTypedScalarMarkers, isNativeCompositeNode, isNativeDateNode, isNativeHtmlNode, isNativePageNode, isNativeSearchResultNode, isViewableUrl, nativeVerdictOf, readChoiceContent, readCompositeContent, readDataUrl, readDateContent, readDocumentContent, readHtmlContent, readImageContent, readPageContent, readRatingContent, readSearchResultContent, readYesNoContent, splitCitations, viewableUrl } from '../chunk-QQK6Y55E.js';
9
10
  export { getPipeOutputForm } from '../chunk-JIGRWJTV.js';
10
11
  export { buildResultField, buildRunFields, getPipeInputForm } from '../chunk-ZB4RYUKV.js';
11
12
  export { conceptCategory } from '../chunk-FABY3DEY.js';
12
13
  export { DOCUMENT_FORMATS, IMAGE_FORMATS, acceptLabel, acceptMap, formatsForKind, isAcceptedFile } from '../chunk-XCO6GTEC.js';
13
- export { apiInputsFromSchemaData, buildRunInputsSchema, gateRunInputs, prepareRunInputs, validateRunInputs } from '../chunk-4DPYGNJ3.js';
14
+ export { apiInputsFromSchemaData, buildRunInputsSchema, gateRunInputs, prepareRunInputs, validateRunInputs } from '../chunk-IBBAJXIO.js';
14
15
  export { deflateAllInputs, deflateInput, healStringWrappers, inflateAllInputs, inflateInput, pruneEmptyOptionals, resolveConceptCode } from '../chunk-E6BIXJ6C.js';
16
+ export { anyOptionalStructureOpen, computeReadiness, fieldFilled, foldsBehindOptionalDisclosure, isFilled, isFoldedOptional, isOptionalStructure, mustBeFilled, optionalStructureOpen, shownAsOptional } from '../chunk-XO5OENNF.js';
15
17
  import '../chunk-Y2ND6W4W.js';
16
18
  export { normalizeSchemaForRjsf, prepareSchemaForRjsf } from '../chunk-LBFZXYCY.js';
17
- export { anyOptionalStructureOpen, computeReadiness, fieldFilled, foldsBehindOptionalDisclosure, isFilled, isFoldedOptional, isOptionalStructure, mustBeFilled, optionalStructureOpen, shownAsOptional } from '../chunk-XO5OENNF.js';
18
19
  export { collapseNullable, collectSchemaDefs, derefSchema, flattenAnyOf, hoistDefsToRoot, resolveSchemaIndirection, schemaTypeOf } from '../chunk-OD3VYXUY.js';
19
20
  export { buildPipeRef, getPipeIOContract, inputMustBeFilled, isFixedCountInput, isOptionalInput, isPluralInput } from '../chunk-WYH56SOZ.js';
20
21
  import '../chunk-V3OV2XQT.js';
@@ -1,10 +1,11 @@
1
1
  "use client";
2
- import { cn, checkedAccentClass, focusOutlineClass, linkTextClass, selectedBorderClass, selectedFillClass, fieldControlClass, ResultRoot, ResultField, FieldRenderer, ToggleGroup, ToggleGroupItem, selectedFillStrongClass, Switch, Select, SelectTrigger, SelectValue, SelectContent, SelectItem } from '../chunk-II5TOORN.js';
2
+ import { cn, checkedAccentClass, focusOutlineClass, linkTextClass, selectedBorderClass, selectedFillClass, fieldControlClass, ResultRoot, ResultField, FieldRenderer, enumLabeler, useFieldPresentation, ToggleGroup, ToggleGroupItem, selectedFillStrongClass, Switch, Select, SelectTrigger, SelectValue, SelectContent, SelectItem } from '../chunk-RHX7LQRL.js';
3
3
  import '../chunk-4VAO6BDE.js';
4
4
  export { seedInputs } from '../chunk-VH5CDQDR.js';
5
5
  import '../chunk-L23R3JNQ.js';
6
6
  import '../chunk-56WECFBD.js';
7
7
  import '../chunk-ZX52CQJ4.js';
8
+ import '../chunk-GHVVULHY.js';
8
9
  import { isNativeValueNode, readDateContent, formatDateContent, isNativeHtmlNode, isNativeDateNode, isNativeCompositeNode } from '../chunk-QQK6Y55E.js';
9
10
  export { brandManifestSchema } from '../chunk-QFX332LE.js';
10
11
  import '../chunk-ZB4RYUKV.js';
@@ -2123,6 +2124,7 @@ function Radio({
2123
2124
  }) {
2124
2125
  const id = useControlId(props.name);
2125
2126
  const field = useBoundField(props.value, bindings?.value, "", props);
2127
+ const labelOf = enumLabeler(props.options ?? [], useFieldPresentation());
2126
2128
  return /* @__PURE__ */ jsxs("fieldset", { className: "space-y-2", "aria-invalid": field.error ? true : void 0, children: [
2127
2129
  /* @__PURE__ */ jsx("legend", { className: LABEL, children: props.label }),
2128
2130
  /* @__PURE__ */ jsx("div", { className: "space-y-2", children: (props.options ?? []).map((option, index) => /* @__PURE__ */ jsxs("label", { className: "flex items-center gap-2 text-sm", children: [
@@ -2141,7 +2143,7 @@ function Radio({
2141
2143
  }
2142
2144
  }
2143
2145
  ),
2144
- /* @__PURE__ */ jsx("span", { children: option })
2146
+ /* @__PURE__ */ jsx("span", { children: labelOf(option) })
2145
2147
  ] }, `${index}-${option}`)) }),
2146
2148
  /* @__PURE__ */ jsx(FieldError, { message: field.error })
2147
2149
  ] });
@@ -2322,6 +2324,7 @@ function AccessibleSelect({ props, bindings, emit }) {
2322
2324
  hasValidation ? { checks: props.checks ?? [], validateOn } : void 0
2323
2325
  );
2324
2326
  const id = useControlId(props.name);
2327
+ const labelOf = enumLabeler(props.options ?? [], useFieldPresentation());
2325
2328
  return /* @__PURE__ */ jsxs("div", { className: "space-y-2", children: [
2326
2329
  /* @__PURE__ */ jsx("label", { htmlFor: id, className: "block text-sm leading-none font-medium", children: props.label }),
2327
2330
  /* @__PURE__ */ jsxs(
@@ -2335,7 +2338,7 @@ function AccessibleSelect({ props, bindings, emit }) {
2335
2338
  },
2336
2339
  children: [
2337
2340
  /* @__PURE__ */ jsx(SelectTrigger, { id, className: "w-full", children: /* @__PURE__ */ jsx(SelectValue, { placeholder: props.placeholder ?? "Select..." }) }),
2338
- /* @__PURE__ */ jsx(SelectContent, { children: (props.options ?? []).map((option, index) => /* @__PURE__ */ jsx(SelectItem, { value: option, children: option }, `${index}-${option}`)) })
2341
+ /* @__PURE__ */ jsx(SelectContent, { children: (props.options ?? []).map((option, index) => /* @__PURE__ */ jsx(SelectItem, { value: option, children: labelOf(option) }, `${index}-${option}`)) })
2339
2342
  ]
2340
2343
  }
2341
2344
  ),
@@ -2591,6 +2594,7 @@ function Segmented({ props, bindings, emit }) {
2591
2594
  const value = isBound ? boundValue ?? "" : localValue;
2592
2595
  const setValue = isBound ? setBoundValue : setLocalValue;
2593
2596
  const labelId = useControlId(props.name);
2597
+ const labelOf = enumLabeler(props.options ?? [], useFieldPresentation());
2594
2598
  return /* @__PURE__ */ jsxs("div", { className: "space-y-2", children: [
2595
2599
  /* @__PURE__ */ jsx("span", { id: labelId, className: "block text-sm leading-none font-medium", children: props.label }),
2596
2600
  /* @__PURE__ */ jsx(
@@ -2612,7 +2616,7 @@ function Segmented({ props, bindings, emit }) {
2612
2616
  variant: "outline",
2613
2617
  size: "sm",
2614
2618
  className: "rounded-full px-3.5 data-[state=on]:border-primary data-[state=on]:bg-primary data-[state=on]:text-primary-foreground",
2615
- children: option
2619
+ children: labelOf(option)
2616
2620
  },
2617
2621
  option
2618
2622
  ))