@timeax/form-palette 0.0.6 → 0.0.8

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.mjs CHANGED
@@ -13412,6 +13412,25 @@ var FieldRegistry = class {
13412
13412
  }
13413
13413
  };
13414
13414
  _binding = new WeakMap();
13415
+ var CORE_PROP_KEYS = /* @__PURE__ */ new Set([
13416
+ "adapter",
13417
+ "schema",
13418
+ "exceptions",
13419
+ "persist",
13420
+ "name",
13421
+ "activateButtonOnChange",
13422
+ "onChange",
13423
+ "onUpdate",
13424
+ "changeBefore",
13425
+ "formRef",
13426
+ "valueBag",
13427
+ "valueFeed",
13428
+ "onFinish",
13429
+ "init",
13430
+ "onSubmit",
13431
+ "onSubmitted",
13432
+ "children"
13433
+ ]);
13415
13434
  function isPlainObject(value) {
13416
13435
  return typeof value === "object" && value !== null && !Array.isArray(value);
13417
13436
  }
@@ -13572,7 +13591,16 @@ function CoreProvider(props) {
13572
13591
  }
13573
13592
  return valid;
13574
13593
  }
13575
- async function submitWithAdapter(method, route, extra, ignoreForm, autoErr = true, autoRun = true) {
13594
+ function getAdapterPropsFrom(current) {
13595
+ const result = {};
13596
+ for (const key in current) {
13597
+ if (!CORE_PROP_KEYS.has(key)) {
13598
+ result[key] = current[key];
13599
+ }
13600
+ }
13601
+ return result;
13602
+ }
13603
+ async function submitWithAdapter(adapterOverride, extra, ignoreForm, autoErr = true, autoRun = true) {
13576
13604
  var _a2, _b;
13577
13605
  const currentProps = propsRef.current;
13578
13606
  const btn = buttonRef.current;
@@ -13604,6 +13632,10 @@ function CoreProvider(props) {
13604
13632
  ...collectValues(),
13605
13633
  ...extra != null ? extra : {}
13606
13634
  };
13635
+ let adapterConfig = {
13636
+ ...getAdapterPropsFrom(currentProps),
13637
+ ...adapterOverride
13638
+ };
13607
13639
  const event = {
13608
13640
  preventDefault() {
13609
13641
  this.continue = false;
@@ -13614,11 +13646,15 @@ function CoreProvider(props) {
13614
13646
  submissionValues = result;
13615
13647
  }
13616
13648
  },
13617
- setRoute(newRoute) {
13618
- route = newRoute;
13619
- },
13620
- setMethod(newMethod) {
13621
- method = newMethod;
13649
+ setConfig(arg1, arg2) {
13650
+ if (typeof arg1 === "string") {
13651
+ adapterConfig[arg1] = arg2;
13652
+ } else if (arg1 && typeof arg1 === "object") {
13653
+ adapterConfig = {
13654
+ ...adapterConfig,
13655
+ ...arg1
13656
+ };
13657
+ }
13622
13658
  },
13623
13659
  button: (_a2 = buttonRef.current) != null ? _a2 : void 0,
13624
13660
  get formData() {
@@ -13641,8 +13677,9 @@ function CoreProvider(props) {
13641
13677
  }
13642
13678
  const factory2 = (_b = getAdapter(adapterKey)) != null ? _b : localAdapter;
13643
13679
  const adapter2 = factory2({
13644
- method,
13645
- url: route,
13680
+ // adapter-specific config (url, method, config, etc.)
13681
+ ...adapterConfig,
13682
+ // core config
13646
13683
  data: submissionValues,
13647
13684
  callbacks: {
13648
13685
  onSuccess(ok) {
@@ -13802,9 +13839,12 @@ function CoreProvider(props) {
13802
13839
  return !deepEqual(original, current);
13803
13840
  },
13804
13841
  async prepare(type, route, extra, ignoreForm, autoErr) {
13842
+ const override = {
13843
+ method: type,
13844
+ url: route
13845
+ };
13805
13846
  return submitWithAdapter(
13806
- type,
13807
- route,
13847
+ override,
13808
13848
  extra,
13809
13849
  ignoreForm,
13810
13850
  autoErr,
@@ -13910,7 +13950,13 @@ function CoreProvider(props) {
13910
13950
  }
13911
13951
  },
13912
13952
  go(data, ignoreForm) {
13913
- void submitWithAdapter("post", "", data, ignoreForm, true, true);
13953
+ void submitWithAdapter(
13954
+ void 0,
13955
+ data,
13956
+ ignoreForm,
13957
+ true,
13958
+ true
13959
+ );
13914
13960
  },
13915
13961
  reset(inputs) {
13916
13962
  if (!inputs.length) return;
@@ -13932,7 +13978,13 @@ function CoreProvider(props) {
13932
13978
  buttonRef.current = btn;
13933
13979
  },
13934
13980
  async forceSubmit() {
13935
- await submitWithAdapter("post", "", void 0, false, true, true);
13981
+ await submitWithAdapter(
13982
+ void 0,
13983
+ void 0,
13984
+ false,
13985
+ true,
13986
+ true
13987
+ );
13936
13988
  },
13937
13989
  get fields() {
13938
13990
  return fetchAllNamedFields();
@@ -18344,7 +18396,7 @@ var Input = React54.forwardRef(
18344
18396
  );
18345
18397
  const baseBoxClasses = cx(
18346
18398
  "file:text-foreground placeholder:text-muted-foreground selection:bg-primary selection:text-primary-foreground dark:bg-input/30",
18347
- "border-input w-full min-w-0 rounded-md border bg-transparent shadow-xs",
18399
+ "border-input w-full min-w-0 rounded-md border bg-[var(--surfaces-input, transparent)] shadow-xs",
18348
18400
  "transition-[color,box-shadow] outline-none",
18349
18401
  "file:inline-flex file:h-7 file:border-0 file:bg-transparent file:text-sm file:font-medium",
18350
18402
  "disabled:pointer-events-none disabled:cursor-not-allowed disabled:opacity-50",
@@ -26335,7 +26387,7 @@ function SelectTrigger2({
26335
26387
  "data-slot": "select-trigger",
26336
26388
  "data-size": size4,
26337
26389
  className: cn(
26338
- "border-input data-[placeholder]:text-muted-foreground [&_svg:not([class*='text-'])]:text-muted-foreground focus-visible:border-ring focus-visible:ring-ring/50 aria-invalid:ring-destructive/20 dark:aria-invalid:ring-destructive/40 aria-invalid:border-destructive dark:bg-input/30 dark:hover:bg-input/50 flex w-fit items-center justify-between gap-2 rounded-md border bg-transparent px-3 py-2 text-sm whitespace-nowrap shadow-xs transition-[color,box-shadow] outline-none focus-visible:ring-[3px] disabled:cursor-not-allowed disabled:opacity-50 data-[size=default]:h-9 data-[size=sm]:h-8 *:data-[slot=select-value]:line-clamp-1 *:data-[slot=select-value]:flex *:data-[slot=select-value]:items-center *:data-[slot=select-value]:gap-2 [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4",
26390
+ "border-input data-[placeholder]:text-muted-foreground [&_svg:not([class*='text-'])]:text-muted-foreground focus-visible:border-ring focus-visible:ring-ring/50 aria-invalid:ring-destructive/20 dark:aria-invalid:ring-destructive/40 aria-invalid:border-destructive dark:bg-input/30 dark:hover:bg-input/50 flex w-fit items-center justify-between gap-2 rounded-md border bg-[var(--surfaces-input, transparent)] px-3 py-2 text-sm whitespace-nowrap shadow-xs transition-[color,box-shadow] outline-none focus-visible:ring-[3px] disabled:cursor-not-allowed disabled:opacity-50 data-[size=default]:h-9 data-[size=sm]:h-8 *:data-[slot=select-value]:line-clamp-1 *:data-[slot=select-value]:flex *:data-[slot=select-value]:items-center *:data-[slot=select-value]:gap-2 [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4",
26339
26391
  className
26340
26392
  ),
26341
26393
  ...props,
@@ -33481,7 +33533,7 @@ var Textarea = React54.forwardRef(
33481
33533
  const frameClasses = cn(
33482
33534
  "border-input placeholder:text-muted-foreground focus-within:border-ring focus-within:ring-ring/50 focus-within:ring-[3px]",
33483
33535
  "aria-invalid:ring-destructive/20 dark:aria-invalid:ring-destructive/40 aria-invalid:border-destructive",
33484
- "dark:bg-input/30 rounded-md border bg-transparent shadow-xs transition-[color,box-shadow] outline-none",
33536
+ "dark:bg-input/30 rounded-md border bg-[var(--surfaces-input, transparent)] shadow-xs transition-[color,box-shadow] outline-none",
33485
33537
  "disabled:cursor-not-allowed disabled:opacity-50"
33486
33538
  );
33487
33539
  const framePaddingClasses = cn(
@@ -41543,7 +41595,7 @@ var ShadcnFileVariant = React54.forwardRef(
41543
41595
  className: cn(
41544
41596
  "relative flex w-full cursor-pointer items-center gap-2 px-3 transition-all",
41545
41597
  heightCls,
41546
- (!joinControls || !hasExternalControls) && "rounded-md border border-input bg-background shadow-xs ring-offset-background hover:bg-accent/5 focus-within:ring-2 focus-within:ring-ring focus-within:ring-offset-2",
41598
+ (!joinControls || !hasExternalControls) && "rounded-md border border-input bg-[var(--surfaces-input, transparent)] shadow-xs ring-offset-background hover:bg-accent/5 focus-within:ring-2 focus-within:ring-ring focus-within:ring-offset-2",
41547
41599
  dragOver && "border-primary ring-2 ring-primary/20",
41548
41600
  isDisabled && "cursor-not-allowed opacity-50",
41549
41601
  error && "border-destructive text-destructive",
@@ -41746,7 +41798,7 @@ var ShadcnFileVariant = React54.forwardRef(
41746
41798
  children: [
41747
41799
  /* @__PURE__ */ jsxs("div", { className: cn(
41748
41800
  "flex w-full",
41749
- joinControls && extendBoxToControls && !showDropArea ? "items-stretch rounded-md border border-input bg-background shadow-xs ring-offset-background focus-within:ring-2 focus-within:ring-ring focus-within:ring-offset-2" : "items-start gap-2"
41801
+ joinControls && extendBoxToControls && !showDropArea ? "items-stretch rounded-md border border-input bg-[var(--surfaces-input, transparent)] shadow-xs ring-offset-background focus-within:ring-2 focus-within:ring-ring focus-within:ring-offset-2" : "items-start gap-2"
41750
41802
  ), children: [
41751
41803
  leadingControl && /* @__PURE__ */ jsx("div", { className: cn(
41752
41804
  "flex items-center",
@@ -41884,7 +41936,7 @@ function FieldGroup({ className, ...props }) {
41884
41936
  {
41885
41937
  "data-slot": "field-group",
41886
41938
  className: cn(
41887
- "group/field-group @container/field-group flex w-full flex-col gap-7 data-[slot=checkbox-group]:gap-3 [&>[data-slot=field-group]]:gap-4",
41939
+ "group/field-group flex w-full flex-col gap-7 data-[slot=checkbox-group]:gap-3 [&>[data-slot=field-group]]:gap-4",
41888
41940
  className
41889
41941
  ),
41890
41942
  ...props
@@ -42435,6 +42487,22 @@ function InputField(props) {
42435
42487
  }),
42436
42488
  [layout, sublabel, description, helpText, visualError, tagsContent]
42437
42489
  );
42490
+ const hasLabelSlotsAt = (placement) => {
42491
+ let found = false;
42492
+ graph.getSlotsFor("label", placement).render((slots) => {
42493
+ if (slots.length > 0) {
42494
+ found = true;
42495
+ }
42496
+ return null;
42497
+ });
42498
+ return found;
42499
+ };
42500
+ const hasLabelLeftSlots = hasLabelSlotsAt("left");
42501
+ const hasLabelRightSlots = hasLabelSlotsAt("right");
42502
+ const hasLabelAboveSlots = hasLabelSlotsAt("above");
42503
+ const hasLabelBelowSlots = hasLabelSlotsAt("below");
42504
+ const hasAnyLabelBlockContent = !!label || hasLabelLeftSlots || hasLabelRightSlots || hasLabelAboveSlots || hasLabelBelowSlots;
42505
+ const hasLabelRowContent = !!label || hasLabelLeftSlots || hasLabelRightSlots;
42438
42506
  const inlineLabelSide = lp === "right" ? "right" : lp === "hidden" ? "hidden" : "left";
42439
42507
  const inlineInputColClass = [
42440
42508
  isCompactInline ? "flex-none" : "flex-1 min-w-0",
@@ -42482,7 +42550,7 @@ function InputField(props) {
42482
42550
  )
42483
42551
  )
42484
42552
  ] });
42485
- const inlineLabelColumn = inlineLabelSide === "hidden" ? null : /* @__PURE__ */ jsxs(
42553
+ const inlineLabelColumn = inlineLabelSide === "hidden" || !hasAnyLabelBlockContent ? null : /* @__PURE__ */ jsxs(
42486
42554
  "div",
42487
42555
  {
42488
42556
  className: ["flex flex-col gap-0", inlineLabelColClass].filter(Boolean).join(" "),
@@ -42492,7 +42560,7 @@ function InputField(props) {
42492
42560
  (slot) => renderHelperSlot("label", slot, classes)
42493
42561
  )
42494
42562
  ),
42495
- /* @__PURE__ */ jsxs(
42563
+ hasLabelRowContent && /* @__PURE__ */ jsxs(
42496
42564
  "div",
42497
42565
  {
42498
42566
  className: [
@@ -42519,7 +42587,16 @@ function InputField(props) {
42519
42587
  children: /* @__PURE__ */ jsxs(FieldTitle, { children: [
42520
42588
  label,
42521
42589
  " ",
42522
- required ? /* @__PURE__ */ jsx("span", { className: cn("text-destructive", classes == null ? void 0 : classes.required), children: "*" }) : ""
42590
+ required ? /* @__PURE__ */ jsx(
42591
+ "span",
42592
+ {
42593
+ className: cn(
42594
+ "text-destructive",
42595
+ classes == null ? void 0 : classes.required
42596
+ ),
42597
+ children: "*"
42598
+ }
42599
+ ) : ""
42523
42600
  ] })
42524
42601
  }
42525
42602
  ),
@@ -42545,7 +42622,11 @@ function InputField(props) {
42545
42622
  "flex items-start gap-2",
42546
42623
  classes == null ? void 0 : classes.inlineRow
42547
42624
  ].filter(Boolean).join(" ");
42548
- const stackedGroupClassName = ["mt-1", classes == null ? void 0 : classes.group].filter(Boolean).join(" ");
42625
+ const hasStackedLabelBlock = lp !== "hidden" && hasAnyLabelBlockContent;
42626
+ const stackedGroupClassName = [
42627
+ hasStackedLabelBlock && hasLabelRowContent ? "mt-1" : null,
42628
+ classes == null ? void 0 : classes.group
42629
+ ].filter(Boolean).join(" ");
42549
42630
  const Element2 = contain ? "div" : React54.Fragment;
42550
42631
  const attrs = (a = "l") => contain ? a === "l" ? { className: "p-4 border-b border-input" } : { className: "px-4 pt-2 pb-4" } : {};
42551
42632
  return /* @__PURE__ */ jsx(
@@ -42581,7 +42662,7 @@ function InputField(props) {
42581
42662
  ) : (
42582
42663
  // STACKED MODE
42583
42664
  /* @__PURE__ */ jsxs(Fragment, { children: [
42584
- lp !== "hidden" && /* @__PURE__ */ jsxs(Element2, { ...attrs(), children: [
42665
+ hasStackedLabelBlock && /* @__PURE__ */ jsxs(Element2, { ...attrs(), children: [
42585
42666
  graph.getSlotsFor("label", "above").render(
42586
42667
  (slots) => slots.map(
42587
42668
  (slot) => renderHelperSlot(
@@ -42591,7 +42672,7 @@ function InputField(props) {
42591
42672
  )
42592
42673
  )
42593
42674
  ),
42594
- /* @__PURE__ */ jsxs(
42675
+ hasLabelRowContent && /* @__PURE__ */ jsxs(
42595
42676
  "div",
42596
42677
  {
42597
42678
  className: [
@@ -42618,7 +42699,16 @@ function InputField(props) {
42618
42699
  children: /* @__PURE__ */ jsxs(FieldTitle, { children: [
42619
42700
  label,
42620
42701
  " ",
42621
- required ? /* @__PURE__ */ jsx("span", { className: cn("text-destructive", classes == null ? void 0 : classes.required), children: "*" }) : ""
42702
+ required ? /* @__PURE__ */ jsx(
42703
+ "span",
42704
+ {
42705
+ className: cn(
42706
+ "text-destructive",
42707
+ classes == null ? void 0 : classes.required
42708
+ ),
42709
+ children: "*"
42710
+ }
42711
+ ) : ""
42622
42712
  ] })
42623
42713
  }
42624
42714
  ),
@@ -42777,7 +42867,7 @@ function normalizeInertiaError(raw) {
42777
42867
  return raw;
42778
42868
  }
42779
42869
  var createInertiaAdapter = (config3) => {
42780
- const { method, url, data, callbacks } = config3;
42870
+ const { method = "post", url, data, callbacks } = config3;
42781
42871
  const upperMethod = method.toUpperCase();
42782
42872
  function buildOptions(resolve, reject, extraOptions) {
42783
42873
  const merged = {