@pipelex/mthds-form 0.27.0 → 0.28.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.
@@ -1,6 +1,6 @@
1
1
  import { planFileSave, planStuffSave, splitFileName, typedFileStem } from './chunk-4VAO6BDE.js';
2
2
  import { seedInputs, closeOptionalStructures, openOptionalStructures } from './chunk-VH5CDQDR.js';
3
- import { sourceFileValue, roomForChosenFiles, roomForDroppedFiles, addChosenFiles, placeDroppedFiles, chosenFilesAdded } from './chunk-NSHGLM6A.js';
3
+ import { sourceFileValue, roomForChosenFiles, roomForDroppedFiles, addChosenFiles, placeDroppedFiles, chosenFilesAdded } from './chunk-L23R3JNQ.js';
4
4
  import { readStuffFile } from './chunk-56WECFBD.js';
5
5
  import { apiInputsFromRunValues, sameRunValues, runValuesFromInputs, setValueAtPath } from './chunk-ZX52CQJ4.js';
6
6
  import { TYPED_SCALAR_MARKERS, viewableUrl, splitCitations, webHref, isNativeDateNode, isNativeHtmlNode, readHtmlContent, isNativeCompositeNode, readCompositeContent, isNativePageNode, nativeVerdictOf, isNativeSearchResultNode, readSearchResultContent, isNativeValueNode, readDateContent, formatDateContent, readPageContent, readYesNoContent, readRatingContent, readChoiceContent, readDocumentContent, readImageContent, readDataUrl, citedSource } from './chunk-QQK6Y55E.js';
@@ -353,6 +353,7 @@ var EN_FIELD_STRINGS = {
353
353
  replaceEnteredDescription: (name) => `Filling the form with \u201C${name}\u201D replaces every value in it.`,
354
354
  replaceEnteredConfirm: "Replace",
355
355
  exampleActions: (name) => `Actions for ${name}`,
356
+ openExample: "Open",
356
357
  renameExample: "Rename",
357
358
  deleteExample: "Delete",
358
359
  renameExampleTitle: "Rename the example",
@@ -537,6 +538,7 @@ var FR_FIELD_STRINGS = {
537
538
  replaceEnteredDescription: (name) => `Remplir le formulaire avec \xAB\xA0${name}\xA0\xBB remplace toutes ses valeurs.`,
538
539
  replaceEnteredConfirm: "Remplacer",
539
540
  exampleActions: (name) => `Actions pour ${name}`,
541
+ openExample: "Ouvrir",
540
542
  renameExample: "Renommer",
541
543
  deleteExample: "Supprimer",
542
544
  renameExampleTitle: "Renommer l\u2019exemple",
@@ -795,6 +797,10 @@ function useSourcePages(load, key) {
795
797
  updateItems
796
798
  };
797
799
  }
800
+ function drawsNothing(drawn) {
801
+ if (Array.isArray(drawn)) return drawn.every((item) => drawsNothing(item));
802
+ return drawn === null || drawn === void 0 || typeof drawn === "boolean" || drawn === "";
803
+ }
798
804
  function DimRows({ count = 4 }) {
799
805
  return /* @__PURE__ */ jsx("div", { "aria-hidden": "true", "data-dim-rows": true, className: "divide-y divide-border", children: Array.from({ length: count }, (_, index) => /* @__PURE__ */ jsxs("div", { className: "flex min-h-16 items-center gap-3 px-4 py-3 opacity-60", children: [
800
806
  /* @__PURE__ */ jsx("span", { className: "size-8 shrink-0 rounded-md bg-muted" }),
@@ -1268,9 +1274,6 @@ function rowMeta(s, file, format) {
1268
1274
  }
1269
1275
  return parts.join(" \xB7 ");
1270
1276
  }
1271
- function drawsNothing(glyph) {
1272
- return glyph === null || glyph === void 0 || typeof glyph === "boolean" || glyph === "";
1273
- }
1274
1277
  function FileRow({
1275
1278
  file,
1276
1279
  formats,
@@ -3026,6 +3029,8 @@ function FillWithExample({
3026
3029
  const afterControl = useRef(null);
3027
3030
  const rows = useRef(/* @__PURE__ */ new Map());
3028
3031
  const menus = useRef(/* @__PURE__ */ new Map());
3032
+ const handingOver = useRef(null);
3033
+ const latestChoice = useRef(() => void 0);
3029
3034
  const afterRowDialog = useRef(null);
3030
3035
  const register = (map, id) => (element) => {
3031
3036
  map.set(id, element);
@@ -3046,7 +3051,12 @@ function FillWithExample({
3046
3051
  setRenaming(null);
3047
3052
  setDeleting(null);
3048
3053
  }
3049
- if (source.hideWhenEmpty && !open && (answer ?? hasExamples) !== true) return null;
3054
+ const hidden = source.hideWhenEmpty === true && !open && (answer ?? hasExamples) !== true;
3055
+ if (hidden && (replacing || renaming || deleting)) {
3056
+ setReplacing(null);
3057
+ setRenaming(null);
3058
+ setDeleting(null);
3059
+ }
3050
3060
  const closeList = () => {
3051
3061
  if (source.hideWhenEmpty && pages.status === "ready") {
3052
3062
  if (pages.items.length > 0) setHasExamples(true);
@@ -3062,13 +3072,27 @@ function FillWithExample({
3062
3072
  if (disabled) return;
3063
3073
  onFill(runValuesFromInputs(example.inputs, fields), example);
3064
3074
  setReplacing(null);
3065
- closeList();
3075
+ if (open) closeList();
3066
3076
  };
3067
3077
  const choose = (example) => {
3078
+ if (disabled) return;
3068
3079
  if (touched) setReplacing(example);
3069
3080
  else fill(example);
3070
3081
  };
3071
- const manages = source.rename !== void 0 || source.delete !== void 0;
3082
+ useEffect(() => {
3083
+ latestChoice.current = hidden ? () => void 0 : choose;
3084
+ return () => {
3085
+ latestChoice.current = () => void 0;
3086
+ };
3087
+ });
3088
+ if (hidden) return null;
3089
+ const manages = source.open !== void 0 || source.rename !== void 0 || source.delete !== void 0;
3090
+ const handOver2 = () => {
3091
+ const example = handingOver.current;
3092
+ handingOver.current = null;
3093
+ if (!example || !source.open) return;
3094
+ queueMicrotask(() => source.open?.(example, () => latestChoice.current(example)));
3095
+ };
3072
3096
  const status = pages.status === "idle" || pages.status === "loading" ? s.examplesLoading : pages.status === "failed" ? s.examplesFailed : pages.more === "failed" ? s.loadMoreFailed : pages.items.length > 0 ? s.examplesShown(pages.items.length) : pages.empty ? s.examplesNone : s.examplesLoading;
3073
3097
  const returnFromRowDialog = () => {
3074
3098
  const next = afterRowDialog.current;
@@ -3111,6 +3135,7 @@ function FillWithExample({
3111
3135
  className: "top-auto max-h-[calc(100dvh-1.5rem)]",
3112
3136
  ref: sheet,
3113
3137
  returnFocus: () => control.current ?? afterControl.current,
3138
+ onCloseAutoFocus: handOver2,
3114
3139
  children: [
3115
3140
  /* @__PURE__ */ jsx("div", { className: "px-4 pt-4 pb-3", children: /* @__PURE__ */ jsxs("div", { className: "flex items-start gap-3", children: [
3116
3141
  /* @__PURE__ */ jsxs("div", { className: "min-w-0 flex-1 space-y-1 pt-1", children: [
@@ -3143,7 +3168,13 @@ function FillWithExample({
3143
3168
  "flex min-h-16 min-w-0 flex-1 items-center px-4 py-2.5 text-left transition-colors hover:bg-muted/60",
3144
3169
  focusOutlineInsetClass
3145
3170
  ),
3146
- children: /* @__PURE__ */ jsx("span", { className: "truncate text-[16px] font-medium text-foreground", children: example.name })
3171
+ children: /* @__PURE__ */ jsx(
3172
+ ExampleRowText,
3173
+ {
3174
+ name: example.name,
3175
+ detail: source.renderDetail?.(example, fields)
3176
+ }
3177
+ )
3147
3178
  }
3148
3179
  ),
3149
3180
  manages && // Not modal, so the question a menu item opens takes
@@ -3162,6 +3193,16 @@ function FillWithExample({
3162
3193
  }
3163
3194
  ),
3164
3195
  /* @__PURE__ */ jsxs(DropdownMenuContent, { align: "end", children: [
3196
+ source.open && /* @__PURE__ */ jsx(
3197
+ DropdownMenuItem,
3198
+ {
3199
+ onSelect: () => {
3200
+ handingOver.current = example;
3201
+ closeList();
3202
+ },
3203
+ children: s.openExample
3204
+ }
3205
+ ),
3165
3206
  source.rename && /* @__PURE__ */ jsx(DropdownMenuItem, { onSelect: () => setRenaming(example), children: s.renameExample }),
3166
3207
  source.delete && /* @__PURE__ */ jsx(
3167
3208
  DropdownMenuItem,
@@ -3211,7 +3252,7 @@ function FillWithExample({
3211
3252
  RenameExampleDialog,
3212
3253
  {
3213
3254
  example: renaming,
3214
- rename: source.rename,
3255
+ rename: source.rename.bind(source),
3215
3256
  returnFocus: returnFromRowDialog,
3216
3257
  onDone: (renamed) => {
3217
3258
  pages.updateItems(
@@ -3230,7 +3271,7 @@ function FillWithExample({
3230
3271
  DeleteExampleDialog,
3231
3272
  {
3232
3273
  example: deleting,
3233
- remove: source.delete,
3274
+ remove: source.delete.bind(source),
3234
3275
  returnFocus: returnFromRowDialog,
3235
3276
  onDone: (deleted) => {
3236
3277
  const index = pages.items.findIndex((item) => item.id === deleted.id);
@@ -3247,6 +3288,22 @@ function FillWithExample({
3247
3288
  )
3248
3289
  ] });
3249
3290
  }
3291
+ function ExampleRowText({ name, detail }) {
3292
+ return /* @__PURE__ */ jsxs("span", { className: "min-w-0 flex-1", children: [
3293
+ /* @__PURE__ */ jsx("span", { className: "block truncate text-[16px] font-medium text-foreground", children: name }),
3294
+ !drawsNothing(detail) && /* @__PURE__ */ jsxs(Fragment, { children: [
3295
+ " ",
3296
+ /* @__PURE__ */ jsx(
3297
+ "span",
3298
+ {
3299
+ "data-slot": "example-row-detail",
3300
+ className: "mt-0.5 block text-[13px] wrap-break-word text-muted-foreground",
3301
+ children: detail
3302
+ }
3303
+ )
3304
+ ] })
3305
+ ] });
3306
+ }
3250
3307
  function RenameExampleDialog({
3251
3308
  example,
3252
3309
  rename,
@@ -8452,5 +8509,5 @@ function pdfFileName(field, value, baseName) {
8452
8509
  }
8453
8510
 
8454
8511
  export { BooleanField, ConceptPill, DEFAULT_FIELD_STRINGS, DateField, DocumentField, EN_FIELD_STRINGS, EnumField, FIELD_STRINGS_BY_LOCALE, FR_FIELD_STRINGS, FieldDomIdProvider, FieldPresentationProvider, FieldRenderer, FieldShell, FieldStringsProvider, FilePicker, FilePickerEntry, FillWithExample, HtmlPreview, ImageField, JsonView, ListField, Markdown, MethodForm, NumberField, ObjectField, OptionalToggle, PdfDownloadButton, ProseField, ResultEnvProvider, ResultField, ResultRoot, SUPPORTED_LOCALES, Select, SelectContent, SelectItem, SelectTrigger, SelectValue, StuffViewer, Switch, TextField, ToggleGroup, ToggleGroupItem, UnknownField, checkedAccentClass, cn, fieldControlClass, fieldStringsFor, focusOutlineClass, humanizeFieldName, linkTextClass, renderHtmlPdf, resolveHtmlStorageUrls, saveInBrowser, selectedBorderClass, selectedFillClass, selectedFillStrongClass, useFieldDomId, useFieldPresentation, useFieldStrings, useMethodForm, useProseImages, useResolveRendition, useResolveShareUrl, useResolveUrl, useResolvedUrl };
8455
- //# sourceMappingURL=chunk-AZIUFSIQ.js.map
8456
- //# sourceMappingURL=chunk-AZIUFSIQ.js.map
8512
+ //# sourceMappingURL=chunk-II5TOORN.js.map
8513
+ //# sourceMappingURL=chunk-II5TOORN.js.map