@pipe0/react 0.1.6 → 0.2.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.
Files changed (85) hide show
  1. package/CHANGELOG.md +33 -0
  2. package/dist/components/compound/effect-catalog/card.d.mts +22 -0
  3. package/dist/components/compound/effect-catalog/card.d.mts.map +1 -0
  4. package/dist/components/compound/effect-catalog/card.mjs +82 -0
  5. package/dist/components/compound/effect-catalog/card.mjs.map +1 -0
  6. package/dist/components/compound/effect-catalog/category-filter.d.mts +27 -0
  7. package/dist/components/compound/effect-catalog/category-filter.d.mts.map +1 -0
  8. package/dist/components/compound/effect-catalog/category-filter.mjs +61 -0
  9. package/dist/components/compound/effect-catalog/category-filter.mjs.map +1 -0
  10. package/dist/components/compound/effect-catalog/empty.d.mts +17 -0
  11. package/dist/components/compound/effect-catalog/empty.d.mts.map +1 -0
  12. package/dist/components/compound/effect-catalog/empty.mjs +29 -0
  13. package/dist/components/compound/effect-catalog/empty.mjs.map +1 -0
  14. package/dist/components/compound/effect-catalog/index.d.mts +6 -0
  15. package/dist/components/compound/effect-catalog/list.d.mts +19 -0
  16. package/dist/components/compound/effect-catalog/list.d.mts.map +1 -0
  17. package/dist/components/compound/effect-catalog/list.mjs +33 -0
  18. package/dist/components/compound/effect-catalog/list.mjs.map +1 -0
  19. package/dist/components/compound/effect-catalog/root.d.mts +31 -0
  20. package/dist/components/compound/effect-catalog/root.d.mts.map +1 -0
  21. package/dist/components/compound/effect-catalog/root.mjs +67 -0
  22. package/dist/components/compound/effect-catalog/root.mjs.map +1 -0
  23. package/dist/components/compound/effect-catalog/search-filter.d.mts +21 -0
  24. package/dist/components/compound/effect-catalog/search-filter.d.mts.map +1 -0
  25. package/dist/components/compound/effect-catalog/search-filter.mjs +47 -0
  26. package/dist/components/compound/effect-catalog/search-filter.mjs.map +1 -0
  27. package/dist/components/compound/pipe-catalog/card.mjs +1 -1
  28. package/dist/components/compound/pipe-catalog/category-filter.mjs +1 -1
  29. package/dist/components/compound/pipe-catalog/provider-filter.mjs +1 -1
  30. package/dist/components/compound/pipe-catalog/root.mjs +1 -1
  31. package/dist/components/compound/pipe-form/content.d.mts +6 -1
  32. package/dist/components/compound/pipe-form/content.d.mts.map +1 -1
  33. package/dist/components/compound/pipe-form/content.mjs +3 -2
  34. package/dist/components/compound/pipe-form/content.mjs.map +1 -1
  35. package/dist/components/compound/search-catalog/active-filters.mjs +1 -1
  36. package/dist/components/compound/search-catalog/category-filter.mjs +1 -1
  37. package/dist/components/compound/search-catalog/provider-filter.mjs +1 -1
  38. package/dist/components/compound/search-form/content.d.mts +6 -1
  39. package/dist/components/compound/search-form/content.d.mts.map +1 -1
  40. package/dist/components/compound/search-form/content.mjs +3 -2
  41. package/dist/components/compound/search-form/content.mjs.map +1 -1
  42. package/dist/components/compound/searches-catalog/active-filters.mjs +1 -1
  43. package/dist/components/compound/searches-catalog/category-filter.mjs +1 -1
  44. package/dist/components/compound/searches-catalog/provider-filter.mjs +1 -1
  45. package/dist/components/defaults/adapters/exact-range-input.mjs +1 -1
  46. package/dist/components/defaults/adapters/json-extraction-input.mjs +1 -1
  47. package/dist/components/defaults/adapters/pipes-run-if-input.mjs +1 -1
  48. package/dist/components/defaults/catalog/card-derived.d.mts.map +1 -1
  49. package/dist/components/defaults/catalog/card-derived.mjs +6 -4
  50. package/dist/components/defaults/catalog/card-derived.mjs.map +1 -1
  51. package/dist/components/defaults/catalog/provider-avatars.mjs +3 -3
  52. package/dist/components/defaults/catalog/provider-avatars.mjs.map +1 -1
  53. package/dist/components/defaults/form/form-empty-state.mjs +23 -0
  54. package/dist/components/defaults/form/form-empty-state.mjs.map +1 -0
  55. package/dist/components/internal/LiquidEditor/LiquidEditor.mjs +2 -2
  56. package/dist/components/internal/LiquidEditor/LiquidEditor.mjs.map +1 -1
  57. package/dist/context/catalog-card-context.mjs +4 -2
  58. package/dist/context/catalog-card-context.mjs.map +1 -1
  59. package/dist/context/effect-catalog-card-context.d.mts +20 -0
  60. package/dist/context/effect-catalog-card-context.d.mts.map +1 -0
  61. package/dist/context/effect-catalog-card-context.mjs +13 -0
  62. package/dist/context/effect-catalog-card-context.mjs.map +1 -0
  63. package/dist/context/effect-catalog-context.d.mts +20 -0
  64. package/dist/context/effect-catalog-context.d.mts.map +1 -0
  65. package/dist/context/effect-catalog-context.mjs +13 -0
  66. package/dist/context/effect-catalog-context.mjs.map +1 -0
  67. package/dist/hooks/use-effect-catalog-table.d.mts +33 -0
  68. package/dist/hooks/use-effect-catalog-table.d.mts.map +1 -0
  69. package/dist/hooks/use-effect-catalog-table.mjs +104 -0
  70. package/dist/hooks/use-effect-catalog-table.mjs.map +1 -0
  71. package/dist/hooks/use-form-core.mjs +1 -1
  72. package/dist/hooks/use-form-core.mjs.map +1 -1
  73. package/dist/hooks/use-sheet-effect-form.d.mts +35 -0
  74. package/dist/hooks/use-sheet-effect-form.d.mts.map +1 -0
  75. package/dist/hooks/use-sheet-effect-form.mjs +104 -0
  76. package/dist/hooks/use-sheet-effect-form.mjs.map +1 -0
  77. package/dist/index.d.mts +12 -2
  78. package/dist/index.mjs +14 -4
  79. package/dist/styles/pipe0-form.css +1 -1
  80. package/dist/types/catalog-adapters.d.mts +22 -2
  81. package/dist/types/catalog-adapters.d.mts.map +1 -1
  82. package/dist/utils/build-section-handlers.mjs +3 -3
  83. package/dist/utils/build-section-handlers.mjs.map +1 -1
  84. package/dist/utils/catalog-helpers.d.mts +1 -1
  85. package/package.json +15 -25
@@ -1,5 +1,6 @@
1
- import { PipeCatalogContext } from "./pipe-catalog-context.mjs";
1
+ import { EffectCatalogCardContext } from "./effect-catalog-card-context.mjs";
2
2
  import { PipeCatalogCardContext } from "./pipe-catalog-card-context.mjs";
3
+ import { PipeCatalogContext } from "./pipe-catalog-context.mjs";
3
4
  import { SearchCatalogCardContext } from "./search-catalog-card-context.mjs";
4
5
  import { SearchCatalogContext } from "./search-catalog-context.mjs";
5
6
  import { SearchesCatalogCardContext } from "./searches-catalog-card-context.mjs";
@@ -12,7 +13,8 @@ function useAnyCatalogCardOptional() {
12
13
  const pipe = useContext(PipeCatalogCardContext);
13
14
  const search = useContext(SearchCatalogCardContext);
14
15
  const searches = useContext(SearchesCatalogCardContext);
15
- return pipe ?? search ?? searches;
16
+ const effect = useContext(EffectCatalogCardContext);
17
+ return pipe ?? search ?? searches ?? effect;
16
18
  }
17
19
  /**
18
20
  * Returns whichever catalog root context is set (pipe / search / searches),
@@ -1 +1 @@
1
- {"version":3,"file":"catalog-card-context.mjs","names":[],"sources":["../../src/context/catalog-card-context.ts"],"sourcesContent":["import type { SyntheticEvent } from \"react\";\nimport { useContext } from \"react\";\nimport type { PipeCardData, SearchCardData, SearchesCardData } from \"../types/catalog-adapters.js\";\nimport { PipeCatalogCardContext } from \"./pipe-catalog-card-context.js\";\nimport { PipeCatalogContext } from \"./pipe-catalog-context.js\";\nimport { SearchCatalogCardContext } from \"./search-catalog-card-context.js\";\nimport { SearchCatalogContext } from \"./search-catalog-context.js\";\nimport { SearchesCatalogCardContext } from \"./searches-catalog-card-context.js\";\nimport { SearchesCatalogContext } from \"./searches-catalog-context.js\";\n\nexport type AnyCardData = PipeCardData | SearchCardData | SearchesCardData;\n\nexport interface AnyCardContextValue {\n card: AnyCardData;\n index: number;\n selected: boolean;\n onSelect: (e: SyntheticEvent) => void;\n}\n\n/**\n * Internal hook used by shared catalog card primitives. Reads whichever of the\n * three sibling card contexts is set; throws if rendered outside any catalog\n * card. The returned `card` is the union of the three variants — primitives\n * narrow via the discriminator (`pipeId` / `searchId` / `searchesId`).\n */\nexport function useAnyCatalogCard(): AnyCardContextValue {\n const pipe = useContext(PipeCatalogCardContext);\n const search = useContext(SearchCatalogCardContext);\n const searches = useContext(SearchesCatalogCardContext);\n const ctx = pipe ?? search ?? searches;\n if (ctx == null) {\n throw new Error(\n \"Catalog card primitives must be rendered inside a <PipeCatalogCard>, <SearchCatalogCard>, or <SearchesCatalogCard>.\",\n );\n }\n return ctx as AnyCardContextValue;\n}\n\n/** Like {@link useAnyCatalogCard} but returns null when outside a card. */\nexport function useAnyCatalogCardOptional(): AnyCardContextValue | null {\n const pipe = useContext(PipeCatalogCardContext);\n const search = useContext(SearchCatalogCardContext);\n const searches = useContext(SearchesCatalogCardContext);\n return (pipe ?? search ?? searches) as AnyCardContextValue | null;\n}\n\n/**\n * Returns whichever catalog root context is set (pipe / search / searches),\n * or null. Used by self-binding primitives that need access to mutators\n * (`addColumnFilter`) or reverse indexes from the catalog hook.\n */\nexport function useAnyCatalogContextOptional() {\n const pipe = useContext(PipeCatalogContext);\n const search = useContext(SearchCatalogContext);\n const searches = useContext(SearchesCatalogContext);\n return pipe ?? search ?? searches;\n}\n"],"mappings":";;;;;;;;;;AAuCA,SAAgB,4BAAwD;CACtE,MAAM,OAAO,WAAW,uBAAuB;CAC/C,MAAM,SAAS,WAAW,yBAAyB;CACnD,MAAM,WAAW,WAAW,2BAA2B;AACvD,QAAQ,QAAQ,UAAU;;;;;;;AAQ5B,SAAgB,+BAA+B;CAC7C,MAAM,OAAO,WAAW,mBAAmB;CAC3C,MAAM,SAAS,WAAW,qBAAqB;CAC/C,MAAM,WAAW,WAAW,uBAAuB;AACnD,QAAO,QAAQ,UAAU"}
1
+ {"version":3,"file":"catalog-card-context.mjs","names":[],"sources":["../../src/context/catalog-card-context.ts"],"sourcesContent":["import type { SyntheticEvent } from \"react\";\nimport { useContext } from \"react\";\nimport type {\n EffectCardData,\n PipeCardData,\n SearchCardData,\n SearchesCardData,\n} from \"../types/catalog-adapters.js\";\nimport { EffectCatalogCardContext } from \"./effect-catalog-card-context.js\";\nimport { PipeCatalogCardContext } from \"./pipe-catalog-card-context.js\";\nimport { PipeCatalogContext } from \"./pipe-catalog-context.js\";\nimport { SearchCatalogCardContext } from \"./search-catalog-card-context.js\";\nimport { SearchCatalogContext } from \"./search-catalog-context.js\";\nimport { SearchesCatalogCardContext } from \"./searches-catalog-card-context.js\";\nimport { SearchesCatalogContext } from \"./searches-catalog-context.js\";\n\nexport type AnyCardData = PipeCardData | SearchCardData | SearchesCardData | EffectCardData;\n\nexport interface AnyCardContextValue {\n card: AnyCardData;\n index: number;\n selected: boolean;\n onSelect: (e: SyntheticEvent) => void;\n}\n\n/**\n * Internal hook used by shared catalog card primitives. Reads whichever of the\n * three sibling card contexts is set; throws if rendered outside any catalog\n * card. The returned `card` is the union of the three variants — primitives\n * narrow via the discriminator (`pipeId` / `searchId` / `searchesId`).\n */\nexport function useAnyCatalogCard(): AnyCardContextValue {\n const pipe = useContext(PipeCatalogCardContext);\n const search = useContext(SearchCatalogCardContext);\n const searches = useContext(SearchesCatalogCardContext);\n const effect = useContext(EffectCatalogCardContext);\n const ctx = pipe ?? search ?? searches ?? effect;\n if (ctx == null) {\n throw new Error(\n \"Catalog card primitives must be rendered inside a <PipeCatalogCard>, <SearchCatalogCard>, <SearchesCatalogCard>, or <EffectCatalogCard>.\",\n );\n }\n return ctx as AnyCardContextValue;\n}\n\n/** Like {@link useAnyCatalogCard} but returns null when outside a card. */\nexport function useAnyCatalogCardOptional(): AnyCardContextValue | null {\n const pipe = useContext(PipeCatalogCardContext);\n const search = useContext(SearchCatalogCardContext);\n const searches = useContext(SearchesCatalogCardContext);\n const effect = useContext(EffectCatalogCardContext);\n return (pipe ?? search ?? searches ?? effect) as AnyCardContextValue | null;\n}\n\n/**\n * Returns whichever catalog root context is set (pipe / search / searches),\n * or null. Used by self-binding primitives that need access to mutators\n * (`addColumnFilter`) or reverse indexes from the catalog hook.\n */\nexport function useAnyCatalogContextOptional() {\n const pipe = useContext(PipeCatalogContext);\n const search = useContext(SearchCatalogContext);\n const searches = useContext(SearchesCatalogContext);\n return pipe ?? search ?? searches;\n}\n"],"mappings":";;;;;;;;;;;AA8CA,SAAgB,4BAAwD;CACtE,MAAM,OAAO,WAAW,uBAAuB;CAC/C,MAAM,SAAS,WAAW,yBAAyB;CACnD,MAAM,WAAW,WAAW,2BAA2B;CACvD,MAAM,SAAS,WAAW,yBAAyB;AACnD,QAAQ,QAAQ,UAAU,YAAY;;;;;;;AAQxC,SAAgB,+BAA+B;CAC7C,MAAM,OAAO,WAAW,mBAAmB;CAC3C,MAAM,SAAS,WAAW,qBAAqB;CAC/C,MAAM,WAAW,WAAW,uBAAuB;AACnD,QAAO,QAAQ,UAAU"}
@@ -0,0 +1,20 @@
1
+ import { EffectCardData } from "../types/catalog-adapters.mjs";
2
+ import * as _$react from "react";
3
+ import { SyntheticEvent } from "react";
4
+
5
+ //#region src/context/effect-catalog-card-context.d.ts
6
+ interface EffectCatalogCardContextValue {
7
+ card: EffectCardData;
8
+ index: number;
9
+ selected: boolean;
10
+ expanded: boolean;
11
+ /** Selection handler — fires the catalog root's `onSelectCard`. */
12
+ onSelect: (e: SyntheticEvent) => void;
13
+ /** Kept for parity with the other card variants; effect cards don't expand. */
14
+ setExpanded: (open: boolean) => void;
15
+ }
16
+ declare const EffectCatalogCardContext: _$react.Context<EffectCatalogCardContextValue | null>;
17
+ declare function useEffectCatalogCard(): EffectCatalogCardContextValue;
18
+ //#endregion
19
+ export { EffectCatalogCardContext, EffectCatalogCardContextValue, useEffectCatalogCard };
20
+ //# sourceMappingURL=effect-catalog-card-context.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"effect-catalog-card-context.d.mts","names":[],"sources":["../../src/context/effect-catalog-card-context.ts"],"mappings":";;;;;UAIiB,6BAAA;EACf,IAAA,EAAM,cAAA;EACN,KAAA;EACA,QAAA;EACA,QAAA;;EAEA,QAAA,GAAW,CAAA,EAAG,cAAA;EALd;EAOA,WAAA,GAAc,IAAA;AAAA;AAAA,cAGH,wBAAA,EAAwB,OAAA,CAAA,OAAA,CAAA,6BAAA;AAAA,iBAErB,oBAAA,CAAA,GAAwB,6BAAA"}
@@ -0,0 +1,13 @@
1
+ import { createContext, useContext } from "react";
2
+
3
+ //#region src/context/effect-catalog-card-context.ts
4
+ const EffectCatalogCardContext = createContext(null);
5
+ function useEffectCatalogCard() {
6
+ const value = useContext(EffectCatalogCardContext);
7
+ if (value == null) throw new Error("useEffectCatalogCard must be used inside <EffectCatalogCard>.");
8
+ return value;
9
+ }
10
+
11
+ //#endregion
12
+ export { EffectCatalogCardContext, useEffectCatalogCard };
13
+ //# sourceMappingURL=effect-catalog-card-context.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"effect-catalog-card-context.mjs","names":[],"sources":["../../src/context/effect-catalog-card-context.ts"],"sourcesContent":["import type { SyntheticEvent } from \"react\";\nimport { createContext, useContext } from \"react\";\nimport type { EffectCardData } from \"../types/catalog-adapters.js\";\n\nexport interface EffectCatalogCardContextValue {\n card: EffectCardData;\n index: number;\n selected: boolean;\n expanded: boolean;\n /** Selection handler — fires the catalog root's `onSelectCard`. */\n onSelect: (e: SyntheticEvent) => void;\n /** Kept for parity with the other card variants; effect cards don't expand. */\n setExpanded: (open: boolean) => void;\n}\n\nexport const EffectCatalogCardContext = createContext<EffectCatalogCardContextValue | null>(null);\n\nexport function useEffectCatalogCard(): EffectCatalogCardContextValue {\n const value = useContext(EffectCatalogCardContext);\n if (value == null) {\n throw new Error(\"useEffectCatalogCard must be used inside <EffectCatalogCard>.\");\n }\n return value;\n}\n"],"mappings":";;;AAeA,MAAa,2BAA2B,cAAoD,KAAK;AAEjG,SAAgB,uBAAsD;CACpE,MAAM,QAAQ,WAAW,yBAAyB;AAClD,KAAI,SAAS,KACX,OAAM,IAAI,MAAM,gEAAgE;AAElF,QAAO"}
@@ -0,0 +1,20 @@
1
+ import { EffectCardData } from "../types/catalog-adapters.mjs";
2
+ import { UseEffectCatalogTableReturn } from "../hooks/use-effect-catalog-table.mjs";
3
+ import * as _$react from "react";
4
+ import { SyntheticEvent } from "react";
5
+
6
+ //#region src/context/effect-catalog-context.d.ts
7
+ type EffectCatalogContextValue = UseEffectCatalogTableReturn & {
8
+ onSelectCard?: (card: EffectCardData, e: SyntheticEvent) => void;
9
+ /**
10
+ * Id of the currently expanded card row (drawer open), or `null`. Kept for
11
+ * parity with the other catalog variants; effect cards are not expandable.
12
+ */
13
+ expandedCardId: string | null;
14
+ setExpandedCardId: (id: string | null) => void;
15
+ };
16
+ declare const EffectCatalogContext: _$react.Context<EffectCatalogContextValue | null>;
17
+ declare function useEffectCatalogContext(): EffectCatalogContextValue;
18
+ //#endregion
19
+ export { EffectCatalogContext, EffectCatalogContextValue, useEffectCatalogContext };
20
+ //# sourceMappingURL=effect-catalog-context.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"effect-catalog-context.d.mts","names":[],"sources":["../../src/context/effect-catalog-context.ts"],"mappings":";;;;;;KAKY,yBAAA,GAA4B,2BAAA;EACtC,YAAA,IAAgB,IAAA,EAAM,cAAA,EAAgB,CAAA,EAAG,cAAA;;AAD3C;;;EAME,cAAA;EACA,iBAAA,GAAoB,EAAA;AAAA;AAAA,cAGT,oBAAA,EAAoB,OAAA,CAAA,OAAA,CAAA,yBAAA;AAAA,iBAEjB,uBAAA,CAAA,GAA2B,yBAAA"}
@@ -0,0 +1,13 @@
1
+ import { createContext, useContext } from "react";
2
+
3
+ //#region src/context/effect-catalog-context.ts
4
+ const EffectCatalogContext = createContext(null);
5
+ function useEffectCatalogContext() {
6
+ const value = useContext(EffectCatalogContext);
7
+ if (value == null) throw new Error("useEffectCatalogContext must be used inside <EffectCatalog>. Either render <EffectCatalog>...</EffectCatalog> or pass `context={useEffectCatalogTable()}`.");
8
+ return value;
9
+ }
10
+
11
+ //#endregion
12
+ export { EffectCatalogContext, useEffectCatalogContext };
13
+ //# sourceMappingURL=effect-catalog-context.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"effect-catalog-context.mjs","names":[],"sources":["../../src/context/effect-catalog-context.ts"],"sourcesContent":["import type { SyntheticEvent } from \"react\";\nimport { createContext, useContext } from \"react\";\nimport type { UseEffectCatalogTableReturn } from \"../hooks/use-effect-catalog-table.js\";\nimport type { EffectCardData } from \"../types/catalog-adapters.js\";\n\nexport type EffectCatalogContextValue = UseEffectCatalogTableReturn & {\n onSelectCard?: (card: EffectCardData, e: SyntheticEvent) => void;\n /**\n * Id of the currently expanded card row (drawer open), or `null`. Kept for\n * parity with the other catalog variants; effect cards are not expandable.\n */\n expandedCardId: string | null;\n setExpandedCardId: (id: string | null) => void;\n};\n\nexport const EffectCatalogContext = createContext<EffectCatalogContextValue | null>(null);\n\nexport function useEffectCatalogContext(): EffectCatalogContextValue {\n const value = useContext(EffectCatalogContext);\n if (value == null) {\n throw new Error(\n \"useEffectCatalogContext must be used inside <EffectCatalog>. \" +\n \"Either render <EffectCatalog>...</EffectCatalog> or pass `context={useEffectCatalogTable()}`.\",\n );\n }\n return value;\n}\n"],"mappings":";;;AAeA,MAAa,uBAAuB,cAAgD,KAAK;AAEzF,SAAgB,0BAAqD;CACnE,MAAM,QAAQ,WAAW,qBAAqB;AAC9C,KAAI,SAAS,KACX,OAAM,IAAI,MACR,6JAED;AAEH,QAAO"}
@@ -0,0 +1,33 @@
1
+ import { EffectCardData } from "../types/catalog-adapters.mjs";
2
+ import * as _$react from "react";
3
+ import { SheetEffectCatalogTableData, SheetEffectCategory } from "@pipe0/base";
4
+ import * as _$_tanstack_react_table0 from "@tanstack/react-table";
5
+ import { ColumnFilter } from "@tanstack/react-table";
6
+
7
+ //#region src/hooks/use-effect-catalog-table.d.ts
8
+ declare function useEffectCatalogTable(config?: {
9
+ initialColumnFilters?: ColumnFilter[];
10
+ /**
11
+ * Optional predicate to pre-filter the catalog (e.g. by `selectionMode`
12
+ * for the current row selection). Memoize it to keep the table stable.
13
+ */
14
+ filter?: (entry: SheetEffectCatalogTableData) => boolean;
15
+ }): {
16
+ table: _$_tanstack_react_table0.Table<SheetEffectCatalogTableData>;
17
+ cards: EffectCardData[];
18
+ cardsByCategory: {
19
+ category: SheetEffectCategory;
20
+ cards: EffectCardData[];
21
+ }[];
22
+ categoryCounts: Partial<Record<SheetEffectCategory, number>>;
23
+ baselineCardCount: number;
24
+ baselineCategoryCounts: Partial<Record<SheetEffectCategory, number>>;
25
+ category: SheetEffectCategory | null;
26
+ setCategory: (next: SheetEffectCategory | null) => void;
27
+ globalFilterInput: string;
28
+ setGlobalFilterInput: _$react.Dispatch<_$react.SetStateAction<string>>;
29
+ };
30
+ type UseEffectCatalogTableReturn = ReturnType<typeof useEffectCatalogTable>;
31
+ //#endregion
32
+ export { UseEffectCatalogTableReturn, useEffectCatalogTable };
33
+ //# sourceMappingURL=use-effect-catalog-table.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"use-effect-catalog-table.d.mts","names":[],"sources":["../../src/hooks/use-effect-catalog-table.ts"],"mappings":";;;;;;;iBAoCgB,qBAAA,CACd,MAAA;EACE,oBAAA,GAAuB,YAAA;;;AAF3B;;EAOI,MAAA,IAAU,KAAA,EAAO,2BAAA;AAAA;;;;cA6EL,mBAAA;WAA4B,cAAA;EAAA;;;;;sBA9BjC,mBAAA;;yCAAmB,OAAA,CAAA,cAAA;AAAA;AAAA,KAiFlB,2BAAA,GAA8B,UAAA,QAAkB,qBAAA"}
@@ -0,0 +1,104 @@
1
+ import { fuzzyFilter } from "../utils/catalog-helpers.mjs";
2
+ import { useDebounce } from "./use-debounce.mjs";
3
+ import { useCallback, useMemo, useState } from "react";
4
+ import { getInitialSheetEffectTableData, getLowestSheetEffectCreditAmount } from "@pipe0/base";
5
+ import { createColumnHelper, getCoreRowModel, getFilteredRowModel, useReactTable } from "@tanstack/react-table";
6
+
7
+ //#region src/hooks/use-effect-catalog-table.ts
8
+ const columnHelper = createColumnHelper();
9
+ const columns = [
10
+ columnHelper.accessor("effectId", {
11
+ filterFn: "includesString",
12
+ enableGlobalFilter: true
13
+ }),
14
+ columnHelper.accessor("description", {
15
+ filterFn: "fuzzy",
16
+ enableGlobalFilter: true
17
+ }),
18
+ columnHelper.accessor("label", {
19
+ filterFn: "includesString",
20
+ enableGlobalFilter: true
21
+ })
22
+ ];
23
+ function useEffectCatalogTable(config = {}) {
24
+ const [category, setCategory] = useState(null);
25
+ const { initialColumnFilters = [], filter } = config;
26
+ const baselineTableData = useMemo(() => filter ? getInitialSheetEffectTableData().filter(filter) : getInitialSheetEffectTableData(), [filter]);
27
+ const table = useReactTable({
28
+ columns,
29
+ data: useMemo(() => category ? baselineTableData.filter((e) => (e.categories ?? []).includes(category)) : baselineTableData, [baselineTableData, category]),
30
+ getCoreRowModel: getCoreRowModel(),
31
+ getFilteredRowModel: getFilteredRowModel(),
32
+ globalFilterFn: fuzzyFilter,
33
+ filterFns: { fuzzy: fuzzyFilter },
34
+ getColumnCanGlobalFilter: (column) => column.columnDef.enableGlobalFilter !== false,
35
+ initialState: {
36
+ columnFilters: initialColumnFilters,
37
+ pagination: { pageSize: 10 }
38
+ }
39
+ });
40
+ const [globalFilterInput, setGlobalFilterInput, setGlobalFilterImmediately] = useDebounce((v) => {
41
+ if (v === table.getState().globalFilter) return;
42
+ table.setGlobalFilter(v);
43
+ if (v) setCategory(null);
44
+ });
45
+ const handleCategoryChange = useCallback((next) => {
46
+ setCategory(next);
47
+ setGlobalFilterImmediately("");
48
+ }, [setGlobalFilterImmediately]);
49
+ const rows = table.getRowModel().rows;
50
+ const cards = useMemo(() => rows.map((row) => {
51
+ const entry = row.original;
52
+ const provider = entry.managedProviders[0] ?? "pipe0";
53
+ return {
54
+ effectId: entry.effectId,
55
+ baseEffect: entry.baseEffect,
56
+ label: entry.label,
57
+ description: entry.description,
58
+ provider,
59
+ providers: entry.managedProviders.length ? entry.managedProviders : [provider],
60
+ startingCreditAmount: getLowestSheetEffectCreditAmount(entry),
61
+ costMode: "per_result",
62
+ selectionMode: entry.selectionMode,
63
+ entry
64
+ };
65
+ }), [rows]);
66
+ return {
67
+ table,
68
+ cards,
69
+ cardsByCategory: useMemo(() => {
70
+ const groups = /* @__PURE__ */ new Map();
71
+ for (const card of cards) {
72
+ const cats = card.entry.categories ?? [];
73
+ for (const cat of cats) {
74
+ const arr = groups.get(cat);
75
+ if (arr) arr.push(card);
76
+ else groups.set(cat, [card]);
77
+ }
78
+ }
79
+ return Array.from(groups, ([category, group]) => ({
80
+ category,
81
+ cards: group
82
+ }));
83
+ }, [cards]),
84
+ categoryCounts: useMemo(() => {
85
+ const counts = {};
86
+ for (const card of cards) for (const cat of card.entry.categories ?? []) counts[cat] = (counts[cat] ?? 0) + 1;
87
+ return counts;
88
+ }, [cards]),
89
+ baselineCardCount: baselineTableData.length,
90
+ baselineCategoryCounts: useMemo(() => {
91
+ const counts = {};
92
+ for (const entry of baselineTableData) for (const cat of entry.categories ?? []) counts[cat] = (counts[cat] ?? 0) + 1;
93
+ return counts;
94
+ }, [baselineTableData]),
95
+ category,
96
+ setCategory: handleCategoryChange,
97
+ globalFilterInput,
98
+ setGlobalFilterInput
99
+ };
100
+ }
101
+
102
+ //#endregion
103
+ export { useEffectCatalogTable };
104
+ //# sourceMappingURL=use-effect-catalog-table.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"use-effect-catalog-table.mjs","names":[],"sources":["../../src/hooks/use-effect-catalog-table.ts"],"sourcesContent":["import {\n getInitialSheetEffectTableData,\n getLowestSheetEffectCreditAmount,\n type ProviderName,\n type SheetEffectCatalogTableData,\n type SheetEffectCategory,\n} from \"@pipe0/base\";\nimport {\n type ColumnFilter,\n createColumnHelper,\n getCoreRowModel,\n getFilteredRowModel,\n useReactTable,\n} from \"@tanstack/react-table\";\nimport { useCallback, useMemo, useState } from \"react\";\nimport type { EffectCardData } from \"../types/catalog-adapters.js\";\nimport { fuzzyFilter } from \"../utils/catalog-helpers.js\";\nimport { useDebounce } from \"./use-debounce.js\";\n\nconst columnHelper = createColumnHelper<SheetEffectCatalogTableData>();\n\nconst columns = [\n columnHelper.accessor(\"effectId\", {\n filterFn: \"includesString\",\n enableGlobalFilter: true,\n }),\n columnHelper.accessor(\"description\", {\n filterFn: \"fuzzy\" as any,\n enableGlobalFilter: true,\n }),\n columnHelper.accessor(\"label\", {\n filterFn: \"includesString\",\n enableGlobalFilter: true,\n }),\n];\n\nexport function useEffectCatalogTable(\n config: {\n initialColumnFilters?: ColumnFilter[];\n /**\n * Optional predicate to pre-filter the catalog (e.g. by `selectionMode`\n * for the current row selection). Memoize it to keep the table stable.\n */\n filter?: (entry: SheetEffectCatalogTableData) => boolean;\n } = {},\n) {\n const [category, setCategory] = useState<SheetEffectCategory | null>(null);\n const { initialColumnFilters = [] as ColumnFilter[], filter } = config;\n\n // Baseline (config.filter applied, but no category / global filter). Drives\n // the stable category-button counts so the row doesn't jump.\n const baselineTableData = useMemo(\n () =>\n filter ? getInitialSheetEffectTableData().filter(filter) : getInitialSheetEffectTableData(),\n [filter],\n );\n\n const initialEffectTableData = useMemo(\n () =>\n category\n ? baselineTableData.filter((e) => (e.categories ?? []).includes(category))\n : baselineTableData,\n [baselineTableData, category],\n );\n\n const table = useReactTable({\n columns,\n data: initialEffectTableData,\n getCoreRowModel: getCoreRowModel(),\n getFilteredRowModel: getFilteredRowModel(),\n globalFilterFn: fuzzyFilter,\n filterFns: {\n fuzzy: fuzzyFilter,\n },\n getColumnCanGlobalFilter: (column) => column.columnDef.enableGlobalFilter !== false,\n initialState: {\n columnFilters: initialColumnFilters,\n pagination: {\n pageSize: 10,\n },\n },\n });\n\n const [globalFilterInput, setGlobalFilterInput, setGlobalFilterImmediately] = useDebounce((v) => {\n if (v === table.getState().globalFilter) return;\n table.setGlobalFilter(v);\n if (v) setCategory(null);\n });\n\n const handleCategoryChange = useCallback(\n (next: SheetEffectCategory | null) => {\n setCategory(next);\n setGlobalFilterImmediately(\"\");\n },\n [setGlobalFilterImmediately],\n );\n\n const rows = table.getRowModel().rows;\n const cards = useMemo<EffectCardData[]>(\n () =>\n rows.map((row) => {\n const entry = row.original;\n const provider = (entry.managedProviders[0] ?? \"pipe0\") as ProviderName;\n return {\n effectId: entry.effectId,\n baseEffect: entry.baseEffect,\n label: entry.label,\n description: entry.description,\n provider,\n providers: entry.managedProviders.length ? entry.managedProviders : [provider],\n startingCreditAmount: getLowestSheetEffectCreditAmount(entry),\n costMode: \"per_result\" as const,\n selectionMode: entry.selectionMode,\n entry,\n };\n }),\n [rows],\n );\n\n const cardsByCategory = useMemo<\n { category: SheetEffectCategory; cards: EffectCardData[] }[]\n >(() => {\n const groups = new Map<SheetEffectCategory, EffectCardData[]>();\n for (const card of cards) {\n const cats = (card.entry.categories ?? []) as SheetEffectCategory[];\n for (const cat of cats) {\n const arr = groups.get(cat);\n if (arr) arr.push(card);\n else groups.set(cat, [card]);\n }\n }\n return Array.from(groups, ([category, group]) => ({ category, cards: group }));\n }, [cards]);\n\n const categoryCounts = useMemo<Partial<Record<SheetEffectCategory, number>>>(() => {\n const counts: Partial<Record<SheetEffectCategory, number>> = {};\n for (const card of cards) {\n for (const cat of (card.entry.categories ?? []) as SheetEffectCategory[]) {\n counts[cat] = (counts[cat] ?? 0) + 1;\n }\n }\n return counts;\n }, [cards]);\n\n // Stable counts based on the baseline (no category / global filter applied).\n const baselineCardCount = baselineTableData.length;\n const baselineCategoryCounts = useMemo<Partial<Record<SheetEffectCategory, number>>>(() => {\n const counts: Partial<Record<SheetEffectCategory, number>> = {};\n for (const entry of baselineTableData) {\n for (const cat of (entry.categories ?? []) as SheetEffectCategory[]) {\n counts[cat] = (counts[cat] ?? 0) + 1;\n }\n }\n return counts;\n }, [baselineTableData]);\n\n return {\n table,\n cards,\n cardsByCategory,\n categoryCounts,\n baselineCardCount,\n baselineCategoryCounts,\n\n category,\n setCategory: handleCategoryChange,\n globalFilterInput,\n setGlobalFilterInput,\n };\n}\n\nexport type UseEffectCatalogTableReturn = ReturnType<typeof useEffectCatalogTable>;\n"],"mappings":";;;;;;;AAmBA,MAAM,eAAe,oBAAiD;AAEtE,MAAM,UAAU;CACd,aAAa,SAAS,YAAY;EAChC,UAAU;EACV,oBAAoB;EACrB,CAAC;CACF,aAAa,SAAS,eAAe;EACnC,UAAU;EACV,oBAAoB;EACrB,CAAC;CACF,aAAa,SAAS,SAAS;EAC7B,UAAU;EACV,oBAAoB;EACrB,CAAC;CACH;AAED,SAAgB,sBACd,SAOI,EAAE,EACN;CACA,MAAM,CAAC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AAM,yBAAS,IAAI,KAA4C;AAC/D,QAAK,MAAM,QAAQ,OAAO;IACxB,MAAM,OAAQ,KAAK,MAAM,cAAc,EAAE;AACzC,SAAK,MAAM,OAAO,MAAM;KACtB,MAAM,MAAM,OAAO,IAAI,IAAI;AAC3B,SAAI,IAAK,KAAI,KAAK,KAAK;SAClB,QAAO,IAAI,KAAK,CAAC,KAAK,CAAC;;;AAGhC,UAAO,MAAM,KAAK,SAAS,CAAC,UAAU,YAAY;IAAE;IAAU,OAAO;IAAO,EAAE;KAC7E,CAAC,MAAM,CAAC;EA4BT,gBA1BqB,cAA4D;GACjF,MAAM,SAAuD,EAAE;AAC/D,QAAK,MAAM,QAAQ,MACjB,MAAK,MAAM,OAAQ,KAAK,MAAM,cAAc,EAAE,CAC5C,QAAO,QAAQ,OAAO,QAAQ,KAAK;AAGvC,UAAO;KACN,CAAC,MAAM,CAAC;EAmBT,mBAhBwB,kBAAkB;EAiB1C,wBAhB6B,cAA4D;GACzF,MAAM,SAAuD,EAAE;AAC/D,QAAK,MAAM,SAAS,kBAClB,MAAK,MAAM,OAAQ,MAAM,cAAc,EAAE,CACvC,QAAO,QAAQ,OAAO,QAAQ,KAAK;AAGvC,UAAO;KACN,CAAC,kBAAkB,CAAC;EAUrB;EACA,aAAa;EACb;EACA;EACD"}
@@ -169,7 +169,7 @@ function useFormCore(options) {
169
169
  suggestionsDisabled: false,
170
170
  suggestionsDisabledReason: void 0
171
171
  };
172
- const idKey = kind === "search" ? "search_id" : "pipe_id";
172
+ const idKey = kind === "search" ? "search_id" : kind === "effect" ? "effect_id" : "pipe_id";
173
173
  Promise.resolve(resolvers.getFieldContext({
174
174
  fieldPath: slot.fieldPath,
175
175
  query: "",
@@ -1 +1 @@
1
- {"version":3,"file":"use-form-core.mjs","names":[],"sources":["../../src/hooks/use-form-core.ts"],"sourcesContent":["import { zodResolver } from \"@hookform/resolvers/zod\";\nimport type {\n EnabledIf,\n EnabledResult,\n FormResolvers,\n FormSection,\n FormStore,\n GeneratedInputMeta,\n PipesEnvironment,\n ProviderName,\n} from \"@pipe0/base\";\nimport {\n type Dispatch,\n type SetStateAction,\n useCallback,\n useEffect,\n useMemo,\n useRef,\n useState,\n} from \"react\";\nimport { type FieldValues, type UseFormReturn, useForm } from \"react-hook-form\";\nimport type { AnyFieldProps, ConstantSuggestion, SecretSuggestion } from \"../types/field-props.js\";\nimport type { FormSectionHandle } from \"../types/form-handle.js\";\nimport { buildSectionHandles } from \"../utils/build-section-handlers.js\";\nimport { mergeFormStores } from \"../utils/merge-form-stores.js\";\n\n// ---------------------------------------------------------------------------\n// Public types\n// ---------------------------------------------------------------------------\n\nexport type ResourceStatus = \"idle\" | \"loading\" | \"ready\" | \"error\";\n\nexport type SlotId = \"field\" | \"suggestions\";\n\nexport type FieldEnabledState = {\n disabled: boolean;\n reason?: string;\n};\n\nexport type FieldLoadState = {\n status: ResourceStatus;\n /** Field-level disabled (from `meta.enabledIf`). */\n disabled: boolean;\n /** Field-level disabled reason. */\n disabledReason?: string;\n /** Suggestions sub-feature gate (from `optionsDef.enabledIf`). */\n suggestionsDisabled: boolean;\n /** Suggestions sub-feature reason. */\n suggestionsDisabledReason?: string;\n};\n\nexport interface UseFormCoreOptions<T extends FieldValues> {\n pipeOrSearchId: string;\n kind: \"pipe\" | \"search\";\n schema: any;\n publicKey: string;\n defaultValues?: T;\n formConfig: FormSection[];\n resolvers?: FormResolvers;\n store: FormStore;\n setStore: Dispatch<SetStateAction<FormStore>>;\n environment?: PipesEnvironment;\n /**\n * Form-level scope tags. Bundled into every `resolvers.getSecrets` call so\n * the backend can return only the secrets allowed in the declared scopes\n * (intersection on top of cascade visibility).\n */\n scopes?: string[];\n /**\n * Current team context. Bundled into every `resolvers.getSecrets` call so\n * the backend can restrict team-level secrets to exactly this team.\n */\n teamId?: string;\n}\n\nexport interface UseFormCoreReturn<T extends FieldValues> {\n connectionsStatus: ResourceStatus;\n /** Map of field path → load state for dynamic context_select_input fields. */\n fieldLoadStates: Record<string, FieldLoadState>;\n /** Subset of `fieldLoadStates` where `status === \"error\"`. RHF-style. */\n fieldLoaderErrors: Record<string, FieldLoadState>;\n /** Subset of `fieldLoadStates` where `status === \"loading\"`. RHF-style. */\n loadingFieldLoaders: Record<string, FieldLoadState>;\n /** True when any field loader has errored. */\n hasFieldLoaderError: boolean;\n /** True when any field loader is currently loading. */\n isFieldLoaderLoading: boolean;\n form: UseFormReturn<T, any, any>;\n sections: FormSectionHandle[];\n fields: AnyFieldProps[];\n reset: (values?: T) => void;\n}\n\ntype EnabledSlot = {\n fieldPath: string;\n slotId: SlotId;\n enabledIf: EnabledIf;\n /** Only present for \"suggestions\" slots — used to drive option fetching. */\n optionsDef?: {\n requires: { connection?: ProviderName; fields?: readonly string[] };\n };\n};\n\nfunction collectEnabledSlots(formConfig: FormSection[]): EnabledSlot[] {\n const out: EnabledSlot[] = [];\n for (const section of formConfig) {\n for (const group of section.groups) {\n for (const field of group.fields as GeneratedInputMeta[]) {\n if (field.enabledIf) {\n out.push({\n fieldPath: field.path,\n slotId: \"field\",\n enabledIf: field.enabledIf,\n });\n }\n const supportsOptionsDef =\n field.type === \"context_select_input\" || field.type === \"tagged_text_input\";\n if (supportsOptionsDef && \"optionsDef\" in field && field.optionsDef) {\n const optionsDef = field.optionsDef as EnabledSlot[\"optionsDef\"] & {\n enabledIf?: EnabledIf;\n };\n if (optionsDef?.enabledIf) {\n out.push({\n fieldPath: field.path,\n slotId: \"suggestions\",\n enabledIf: optionsDef.enabledIf,\n optionsDef,\n });\n } else {\n // Even without a sub-feature enabledIf, we still need to track\n // this field as having a fetchable suggestions slot — it's\n // always enabled and the fetch fires on every value change.\n out.push({\n fieldPath: field.path,\n slotId: \"suggestions\",\n enabledIf: () => ({ disabled: false }),\n optionsDef,\n });\n }\n }\n }\n }\n }\n return out;\n}\n\nfunction getPathValue(obj: unknown, path: string): unknown {\n const parts = path.split(\".\");\n let cur: any = obj;\n for (const part of parts) {\n if (cur == null) return undefined;\n cur = cur[part];\n }\n return cur;\n}\n\nfunction evalSlot(slot: EnabledSlot, payload: unknown): EnabledResult {\n return slot.enabledIf(payload);\n}\n\n// ---------------------------------------------------------------------------\n// Hook\n// ---------------------------------------------------------------------------\n\nexport function useFormCore<T extends FieldValues>(\n options: UseFormCoreOptions<T>,\n): UseFormCoreReturn<T> {\n const {\n schema,\n publicKey,\n defaultValues,\n formConfig,\n resolvers,\n pipeOrSearchId,\n kind,\n setStore,\n environment = \"production\",\n scopes,\n teamId,\n } = options;\n\n // Stable signature for `scopes` so its identity doesn't churn the effect\n // dep across renders when callers pass a fresh array literal each time.\n const scopesKey = useMemo(() => (scopes ? JSON.stringify(scopes) : \"\"), [scopes]);\n\n // --- Per-resource status ---\n const [connectionsStatus, setConnectionsStatus] = useState<ResourceStatus>(\n resolvers?.getConnections ? \"loading\" : \"idle\",\n );\n const [fieldLoadStates, setFieldLoadStates] = useState<Record<string, FieldLoadState>>({});\n\n // --- Form ---\n const form = useForm<T>({\n resolver: zodResolver(schema),\n defaultValues: defaultValues as any,\n });\n\n // --- Helpers ---\n const mergeStore = useCallback(\n (incoming: FormStore) => setStore((old) => mergeFormStores(old, incoming)),\n [setStore],\n );\n\n // --- Effect 1: Load connections ---\n useEffect(() => {\n if (!resolvers?.getConnections) {\n setConnectionsStatus(\"idle\");\n return;\n }\n\n let cancelled = false;\n setConnectionsStatus(\"loading\");\n\n Promise.resolve(resolvers.getConnections({ id: pipeOrSearchId, environment }))\n .then((conns) => {\n if (cancelled) return;\n\n mergeStore({\n field_options: {\n connections: {\n options: conns.map((c) => ({\n label: c.public_id,\n value: c.public_id,\n widgets: {\n provider_logo: { provider: c.provider as ProviderName },\n },\n })),\n },\n },\n });\n\n setConnectionsStatus(\"ready\");\n })\n .catch(() => {\n if (!cancelled) setConnectionsStatus(\"error\");\n });\n\n return () => {\n cancelled = true;\n };\n }, [pipeOrSearchId, environment, resolvers?.getConnections, mergeStore]);\n\n // --- Curried secrets search ---\n // Each keystroke in the reference picker fires this with the latest query.\n // The picker handles debounce + race-correctness; here we just bundle in\n // form-level args (environment / scopes / teamId) and call the resolver.\n // No caching: every call hits the resolver. Returns [] if no resolver.\n const getSecretsResolver = resolvers?.getSecrets;\n const searchSecrets = useCallback(\n async (query: string): Promise<SecretSuggestion[]> => {\n if (!getSecretsResolver) return [];\n return Promise.resolve(getSecretsResolver({ query, environment, scopes, teamId }));\n },\n // `scopesKey` is the stable serialization of `scopes`; depending on the\n // raw array would churn the callback identity on every parent render.\n // eslint-disable-next-line react-hooks/exhaustive-deps\n [getSecretsResolver, environment, scopesKey, teamId],\n );\n\n // --- Curried constants search ---\n // Mirrors `searchSecrets` exactly. Same per-keystroke contract, same\n // form-level arg bundling. Returns [] when no resolver is wired.\n const getConstantsResolver = resolvers?.getConstants;\n const searchConstants = useCallback(\n async (query: string): Promise<ConstantSuggestion[]> => {\n if (!getConstantsResolver) return [];\n return Promise.resolve(getConstantsResolver({ query, environment, scopes, teamId }));\n },\n // eslint-disable-next-line react-hooks/exhaustive-deps\n [getConstantsResolver, environment, scopesKey, teamId],\n );\n\n // --- Effect 2: Evaluate enabledIf slots + drive context_select fetching ---\n const slots = useMemo(() => collectEnabledSlots(formConfig), [formConfig]);\n\n // Subscribe to all form value changes so resolvers re-evaluate.\n const watchedValues = form.watch();\n\n // Evaluate every slot against the current payload. Keep the result\n // serialized so the effect's deps stay stable across reference-identical\n // re-renders.\n const slotResults = useMemo(() => {\n const out: Record<string, EnabledResult> = {};\n for (const slot of slots) {\n out[`${slot.fieldPath}::${slot.slotId}`] = evalSlot(slot, watchedValues);\n }\n return out;\n }, [slots, watchedValues]);\n const slotResultsSig = useMemo(() => JSON.stringify(slotResults), [slotResults]);\n\n // Track previous results so we can detect enabled→disabled transitions\n // (drives field-value clearing) and last-fired fetch signatures.\n const prevResultsRef = useRef<Record<string, EnabledResult>>({});\n const lastFiredSigRef = useRef<Record<string, string>>({});\n\n useEffect(() => {\n if (slots.length === 0) return;\n\n let cancelled = false;\n const nextLoadStates: Record<string, FieldLoadState> = {\n ...fieldLoadStates,\n };\n\n // Group slot results by field path for the load-state map.\n const byField: Record<string, { field?: EnabledResult; suggestions?: EnabledResult }> = {};\n for (const slot of slots) {\n const r = slotResults[`${slot.fieldPath}::${slot.slotId}`];\n if (r == null) continue;\n byField[slot.fieldPath] ??= {};\n byField[slot.fieldPath][slot.slotId] = r;\n }\n\n for (const slot of slots) {\n const key = `${slot.fieldPath}::${slot.slotId}`;\n const r = slotResults[key];\n if (r == null) continue;\n const prev = prevResultsRef.current[key];\n\n // Field-slot only: clear value on enabled→disabled transition.\n if (slot.slotId === \"field\" && r.disabled && prev != null && !prev.disabled) {\n form.setValue(slot.fieldPath as any, \"\" as any, {\n shouldDirty: true,\n shouldTouch: true,\n });\n }\n\n // Suggestions-slot: drive the existing context_select_input fetch.\n if (slot.slotId === \"suggestions\" && resolvers?.getFieldContext) {\n // If suggestions are gated, skip the fetch and reset dedupe so\n // re-enabling re-fires.\n if (r.disabled) {\n delete lastFiredSigRef.current[slot.fieldPath];\n continue;\n }\n\n // Resolve the connection for the legacy `requires.connection`\n // (still needed to pick the right secret for the fetch).\n const watchedConnections = (\n watchedValues as {\n connector?: { connections?: { connection?: string }[] };\n }\n )?.connector?.connections;\n const required = slot.optionsDef?.requires;\n\n let connectionId: string | undefined;\n if (required?.connection) {\n const match = watchedConnections?.find((c) =>\n c?.connection?.startsWith(`${required.connection}_`),\n );\n connectionId = match?.connection;\n // No matching connection — can't fetch, even if enabledIf passed.\n if (!connectionId) continue;\n }\n\n // Per-field signature for dedupe.\n const perFieldSig = JSON.stringify({\n connectionId,\n deps: required?.fields?.map((d) => getPathValue(watchedValues, d)) ?? [],\n });\n if (lastFiredSigRef.current[slot.fieldPath] === perFieldSig) continue;\n lastFiredSigRef.current[slot.fieldPath] = perFieldSig;\n\n // Mark loading for this field's fetch.\n const existing = nextLoadStates[slot.fieldPath];\n nextLoadStates[slot.fieldPath] = {\n status: \"loading\",\n disabled: existing?.disabled ?? false,\n disabledReason: existing?.disabledReason,\n suggestionsDisabled: false,\n suggestionsDisabledReason: undefined,\n };\n\n const idKey = kind === \"search\" ? \"search_id\" : \"pipe_id\";\n\n Promise.resolve(\n resolvers.getFieldContext({\n fieldPath: slot.fieldPath,\n query: \"\",\n payload: {\n ...(watchedValues as Record<string, unknown>),\n [idKey]: pipeOrSearchId,\n },\n }),\n )\n .then((incoming: FormStore) => {\n if (cancelled) return;\n mergeStore(incoming);\n setFieldLoadStates((s) => ({\n ...s,\n [slot.fieldPath]: {\n ...(s[slot.fieldPath] ?? {\n disabled: false,\n suggestionsDisabled: false,\n }),\n status: \"ready\",\n },\n }));\n })\n .catch(() => {\n if (cancelled) return;\n setFieldLoadStates((s) => ({\n ...s,\n [slot.fieldPath]: {\n ...(s[slot.fieldPath] ?? {\n disabled: false,\n suggestionsDisabled: false,\n }),\n status: \"error\",\n },\n }));\n });\n }\n }\n\n // Reflect the latest enabledIf evaluation into fieldLoadStates so the\n // adapters and field-wrapper can render the disabled state.\n for (const fieldPath of Object.keys(byField)) {\n const { field: fieldR, suggestions: sugR } = byField[fieldPath]!;\n const prevState = nextLoadStates[fieldPath];\n nextLoadStates[fieldPath] = {\n status: prevState?.status ?? \"idle\",\n disabled: fieldR == null ? (prevState?.disabled ?? false) : fieldR.disabled,\n disabledReason: fieldR == null ? prevState?.disabledReason : fieldR.message,\n suggestionsDisabled:\n sugR == null ? (prevState?.suggestionsDisabled ?? false) : sugR.disabled,\n suggestionsDisabledReason:\n sugR == null ? prevState?.suggestionsDisabledReason : sugR.message,\n };\n }\n\n setFieldLoadStates(nextLoadStates);\n prevResultsRef.current = slotResults;\n\n return () => {\n cancelled = true;\n };\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, [slotResultsSig, slots, pipeOrSearchId]);\n\n // --- Sections & fields ---\n const isSubmitted = form.formState.isSubmitted;\n const formErrors = form.formState.errors;\n\n // `watchedValues` and `formErrors` must be in the dep array: field handles\n // bake `form.getValues(path)` snapshots into `field.value` / textareaProps /\n // selectedValue, and adapters render those as controlled inputs. Without\n // these deps, the memo never refreshes on keystrokes and the controlled\n // inputs snap back to their stale snapshot — typing/selecting appears to\n // do nothing. See FieldRenderer's memo comment for the intended contract.\n const sections = useMemo(\n () =>\n buildSectionHandles(formConfig, form as any, publicKey, {\n fieldLoadStates,\n searchSecrets,\n searchConstants,\n }),\n // eslint-disable-next-line react-hooks/exhaustive-deps\n [\n formConfig,\n form,\n publicKey,\n fieldLoadStates,\n isSubmitted,\n searchSecrets,\n searchConstants,\n watchedValues,\n formErrors,\n ],\n );\n\n const fields = useMemo(\n () => sections.flatMap((s) => s.groups.flatMap((g) => g.fields)),\n [sections],\n );\n\n const { fieldLoaderErrors, loadingFieldLoaders, hasFieldLoaderError, isFieldLoaderLoading } =\n useMemo(() => {\n const errors: Record<string, FieldLoadState> = {};\n const loading: Record<string, FieldLoadState> = {};\n for (const [path, state] of Object.entries(fieldLoadStates)) {\n if (state.status === \"error\") errors[path] = state;\n else if (state.status === \"loading\") loading[path] = state;\n }\n return {\n fieldLoaderErrors: errors,\n loadingFieldLoaders: loading,\n hasFieldLoaderError: Object.keys(errors).length > 0,\n isFieldLoaderLoading: Object.keys(loading).length > 0,\n };\n }, [fieldLoadStates]);\n\n return {\n connectionsStatus,\n fieldLoadStates,\n fieldLoaderErrors,\n loadingFieldLoaders,\n hasFieldLoaderError,\n isFieldLoaderLoading,\n form,\n sections,\n fields,\n reset: form.reset,\n };\n}\n"],"mappings":";;;;;;;AAuGA,SAAS,oBAAoB,YAA0C;CACrE,MAAM,MAAqB,EAAE;AAC7B,MAAK,MAAM,WAAW,WACpB,MAAK,MAAM,SAAS,QAAQ,OAC1B,MAAK,MAAM,SAAS,MAAM,QAAgC;AACxD,MAAI,MAAM,UACR,KAAI,KAAK;GACP,WAAW,MAAM;GACjB,QAAQ;GACR,WAAW,MAAM;GAClB,CAAC;AAIJ,OADE,MAAM,SAAS,0BAA0B,MAAM,SAAS,wBAChC,gBAAgB,SAAS,MAAM,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SAAS,MAAM,EAAE,OAAO,SAAS,MAAM,EAAE,OAAO,CAAC,EAChE,CAAC,SAAS,CACX;CAED,MAAM,EAAE,mBAAmB,qBAAqB,qBAAqB,yBACnE,cAAc;EACZ,MAAM,SAAyC,EAAE;EACjD,MAAM,UAA0C,EAAE;AAClD,OAAK,MAAM,CAAC,MAAM,UAAU,OAAO,QAAQ,gBAAgB,CACzD,KAAI,MAAM,WAAW,QAAS,QAAO,QAAQ;WACpC,MAAM,WAAW,UAAW,SAAQ,QAAQ;AAEvD,SAAO;GACL,mBAAmB;GACnB,qBAAqB;GACrB,qBAAqB,OAAO,KAAK,OAAO,CAAC,SAAS;GAClD,sBAAsB,OAAO,KAAK,QAAQ,CAAC,SAAS;GACrD;IACA,CAAC,gBAAgB,CAAC;AAEvB,QAAO;EACL;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA,OAAO,KAAK;EACb"}
1
+ {"version":3,"file":"use-form-core.mjs","names":[],"sources":["../../src/hooks/use-form-core.ts"],"sourcesContent":["import { zodResolver } from \"@hookform/resolvers/zod\";\nimport type {\n EnabledIf,\n EnabledResult,\n FormResolvers,\n FormSection,\n FormStore,\n GeneratedInputMeta,\n PipesEnvironment,\n ProviderName,\n} from \"@pipe0/base\";\nimport {\n type Dispatch,\n type SetStateAction,\n useCallback,\n useEffect,\n useMemo,\n useRef,\n useState,\n} from \"react\";\nimport { type FieldValues, type UseFormReturn, useForm } from \"react-hook-form\";\nimport type { AnyFieldProps, ConstantSuggestion, SecretSuggestion } from \"../types/field-props.js\";\nimport type { FormSectionHandle } from \"../types/form-handle.js\";\nimport { buildSectionHandles } from \"../utils/build-section-handlers.js\";\nimport { mergeFormStores } from \"../utils/merge-form-stores.js\";\n\n// ---------------------------------------------------------------------------\n// Public types\n// ---------------------------------------------------------------------------\n\nexport type ResourceStatus = \"idle\" | \"loading\" | \"ready\" | \"error\";\n\nexport type SlotId = \"field\" | \"suggestions\";\n\nexport type FieldEnabledState = {\n disabled: boolean;\n reason?: string;\n};\n\nexport type FieldLoadState = {\n status: ResourceStatus;\n /** Field-level disabled (from `meta.enabledIf`). */\n disabled: boolean;\n /** Field-level disabled reason. */\n disabledReason?: string;\n /** Suggestions sub-feature gate (from `optionsDef.enabledIf`). */\n suggestionsDisabled: boolean;\n /** Suggestions sub-feature reason. */\n suggestionsDisabledReason?: string;\n};\n\nexport interface UseFormCoreOptions<T extends FieldValues> {\n pipeOrSearchId: string;\n kind: \"pipe\" | \"search\" | \"effect\";\n schema: any;\n publicKey: string;\n defaultValues?: T;\n formConfig: FormSection[];\n resolvers?: FormResolvers;\n store: FormStore;\n setStore: Dispatch<SetStateAction<FormStore>>;\n environment?: PipesEnvironment;\n /**\n * Form-level scope tags. Bundled into every `resolvers.getSecrets` call so\n * the backend can return only the secrets allowed in the declared scopes\n * (intersection on top of cascade visibility).\n */\n scopes?: string[];\n /**\n * Current team context. Bundled into every `resolvers.getSecrets` call so\n * the backend can restrict team-level secrets to exactly this team.\n */\n teamId?: string;\n}\n\nexport interface UseFormCoreReturn<T extends FieldValues> {\n connectionsStatus: ResourceStatus;\n /** Map of field path → load state for dynamic context_select_input fields. */\n fieldLoadStates: Record<string, FieldLoadState>;\n /** Subset of `fieldLoadStates` where `status === \"error\"`. RHF-style. */\n fieldLoaderErrors: Record<string, FieldLoadState>;\n /** Subset of `fieldLoadStates` where `status === \"loading\"`. RHF-style. */\n loadingFieldLoaders: Record<string, FieldLoadState>;\n /** True when any field loader has errored. */\n hasFieldLoaderError: boolean;\n /** True when any field loader is currently loading. */\n isFieldLoaderLoading: boolean;\n form: UseFormReturn<T, any, any>;\n sections: FormSectionHandle[];\n fields: AnyFieldProps[];\n reset: (values?: T) => void;\n}\n\ntype EnabledSlot = {\n fieldPath: string;\n slotId: SlotId;\n enabledIf: EnabledIf;\n /** Only present for \"suggestions\" slots — used to drive option fetching. */\n optionsDef?: {\n requires: { connection?: ProviderName; fields?: readonly string[] };\n };\n};\n\nfunction collectEnabledSlots(formConfig: FormSection[]): EnabledSlot[] {\n const out: EnabledSlot[] = [];\n for (const section of formConfig) {\n for (const group of section.groups) {\n for (const field of group.fields as GeneratedInputMeta[]) {\n if (field.enabledIf) {\n out.push({\n fieldPath: field.path,\n slotId: \"field\",\n enabledIf: field.enabledIf,\n });\n }\n const supportsOptionsDef =\n field.type === \"context_select_input\" || field.type === \"tagged_text_input\";\n if (supportsOptionsDef && \"optionsDef\" in field && field.optionsDef) {\n const optionsDef = field.optionsDef as EnabledSlot[\"optionsDef\"] & {\n enabledIf?: EnabledIf;\n };\n if (optionsDef?.enabledIf) {\n out.push({\n fieldPath: field.path,\n slotId: \"suggestions\",\n enabledIf: optionsDef.enabledIf,\n optionsDef,\n });\n } else {\n // Even without a sub-feature enabledIf, we still need to track\n // this field as having a fetchable suggestions slot — it's\n // always enabled and the fetch fires on every value change.\n out.push({\n fieldPath: field.path,\n slotId: \"suggestions\",\n enabledIf: () => ({ disabled: false }),\n optionsDef,\n });\n }\n }\n }\n }\n }\n return out;\n}\n\nfunction getPathValue(obj: unknown, path: string): unknown {\n const parts = path.split(\".\");\n let cur: any = obj;\n for (const part of parts) {\n if (cur == null) return undefined;\n cur = cur[part];\n }\n return cur;\n}\n\nfunction evalSlot(slot: EnabledSlot, payload: unknown): EnabledResult {\n return slot.enabledIf(payload);\n}\n\n// ---------------------------------------------------------------------------\n// Hook\n// ---------------------------------------------------------------------------\n\nexport function useFormCore<T extends FieldValues>(\n options: UseFormCoreOptions<T>,\n): UseFormCoreReturn<T> {\n const {\n schema,\n publicKey,\n defaultValues,\n formConfig,\n resolvers,\n pipeOrSearchId,\n kind,\n setStore,\n environment = \"production\",\n scopes,\n teamId,\n } = options;\n\n // Stable signature for `scopes` so its identity doesn't churn the effect\n // dep across renders when callers pass a fresh array literal each time.\n const scopesKey = useMemo(() => (scopes ? JSON.stringify(scopes) : \"\"), [scopes]);\n\n // --- Per-resource status ---\n const [connectionsStatus, setConnectionsStatus] = useState<ResourceStatus>(\n resolvers?.getConnections ? \"loading\" : \"idle\",\n );\n const [fieldLoadStates, setFieldLoadStates] = useState<Record<string, FieldLoadState>>({});\n\n // --- Form ---\n const form = useForm<T>({\n resolver: zodResolver(schema),\n defaultValues: defaultValues as any,\n });\n\n // --- Helpers ---\n const mergeStore = useCallback(\n (incoming: FormStore) => setStore((old) => mergeFormStores(old, incoming)),\n [setStore],\n );\n\n // --- Effect 1: Load connections ---\n useEffect(() => {\n if (!resolvers?.getConnections) {\n setConnectionsStatus(\"idle\");\n return;\n }\n\n let cancelled = false;\n setConnectionsStatus(\"loading\");\n\n Promise.resolve(resolvers.getConnections({ id: pipeOrSearchId, environment }))\n .then((conns) => {\n if (cancelled) return;\n\n mergeStore({\n field_options: {\n connections: {\n options: conns.map((c) => ({\n label: c.public_id,\n value: c.public_id,\n widgets: {\n provider_logo: { provider: c.provider as ProviderName },\n },\n })),\n },\n },\n });\n\n setConnectionsStatus(\"ready\");\n })\n .catch(() => {\n if (!cancelled) setConnectionsStatus(\"error\");\n });\n\n return () => {\n cancelled = true;\n };\n }, [pipeOrSearchId, environment, resolvers?.getConnections, mergeStore]);\n\n // --- Curried secrets search ---\n // Each keystroke in the reference picker fires this with the latest query.\n // The picker handles debounce + race-correctness; here we just bundle in\n // form-level args (environment / scopes / teamId) and call the resolver.\n // No caching: every call hits the resolver. Returns [] if no resolver.\n const getSecretsResolver = resolvers?.getSecrets;\n const searchSecrets = useCallback(\n async (query: string): Promise<SecretSuggestion[]> => {\n if (!getSecretsResolver) return [];\n return Promise.resolve(getSecretsResolver({ query, environment, scopes, teamId }));\n },\n // `scopesKey` is the stable serialization of `scopes`; depending on the\n // raw array would churn the callback identity on every parent render.\n // eslint-disable-next-line react-hooks/exhaustive-deps\n [getSecretsResolver, environment, scopesKey, teamId],\n );\n\n // --- Curried constants search ---\n // Mirrors `searchSecrets` exactly. Same per-keystroke contract, same\n // form-level arg bundling. Returns [] when no resolver is wired.\n const getConstantsResolver = resolvers?.getConstants;\n const searchConstants = useCallback(\n async (query: string): Promise<ConstantSuggestion[]> => {\n if (!getConstantsResolver) return [];\n return Promise.resolve(getConstantsResolver({ query, environment, scopes, teamId }));\n },\n // eslint-disable-next-line react-hooks/exhaustive-deps\n [getConstantsResolver, environment, scopesKey, teamId],\n );\n\n // --- Effect 2: Evaluate enabledIf slots + drive context_select fetching ---\n const slots = useMemo(() => collectEnabledSlots(formConfig), [formConfig]);\n\n // Subscribe to all form value changes so resolvers re-evaluate.\n const watchedValues = form.watch();\n\n // Evaluate every slot against the current payload. Keep the result\n // serialized so the effect's deps stay stable across reference-identical\n // re-renders.\n const slotResults = useMemo(() => {\n const out: Record<string, EnabledResult> = {};\n for (const slot of slots) {\n out[`${slot.fieldPath}::${slot.slotId}`] = evalSlot(slot, watchedValues);\n }\n return out;\n }, [slots, watchedValues]);\n const slotResultsSig = useMemo(() => JSON.stringify(slotResults), [slotResults]);\n\n // Track previous results so we can detect enabled→disabled transitions\n // (drives field-value clearing) and last-fired fetch signatures.\n const prevResultsRef = useRef<Record<string, EnabledResult>>({});\n const lastFiredSigRef = useRef<Record<string, string>>({});\n\n useEffect(() => {\n if (slots.length === 0) return;\n\n let cancelled = false;\n const nextLoadStates: Record<string, FieldLoadState> = {\n ...fieldLoadStates,\n };\n\n // Group slot results by field path for the load-state map.\n const byField: Record<string, { field?: EnabledResult; suggestions?: EnabledResult }> = {};\n for (const slot of slots) {\n const r = slotResults[`${slot.fieldPath}::${slot.slotId}`];\n if (r == null) continue;\n byField[slot.fieldPath] ??= {};\n byField[slot.fieldPath][slot.slotId] = r;\n }\n\n for (const slot of slots) {\n const key = `${slot.fieldPath}::${slot.slotId}`;\n const r = slotResults[key];\n if (r == null) continue;\n const prev = prevResultsRef.current[key];\n\n // Field-slot only: clear value on enabled→disabled transition.\n if (slot.slotId === \"field\" && r.disabled && prev != null && !prev.disabled) {\n form.setValue(slot.fieldPath as any, \"\" as any, {\n shouldDirty: true,\n shouldTouch: true,\n });\n }\n\n // Suggestions-slot: drive the existing context_select_input fetch.\n if (slot.slotId === \"suggestions\" && resolvers?.getFieldContext) {\n // If suggestions are gated, skip the fetch and reset dedupe so\n // re-enabling re-fires.\n if (r.disabled) {\n delete lastFiredSigRef.current[slot.fieldPath];\n continue;\n }\n\n // Resolve the connection for the legacy `requires.connection`\n // (still needed to pick the right secret for the fetch).\n const watchedConnections = (\n watchedValues as {\n connector?: { connections?: { connection?: string }[] };\n }\n )?.connector?.connections;\n const required = slot.optionsDef?.requires;\n\n let connectionId: string | undefined;\n if (required?.connection) {\n const match = watchedConnections?.find((c) =>\n c?.connection?.startsWith(`${required.connection}_`),\n );\n connectionId = match?.connection;\n // No matching connection — can't fetch, even if enabledIf passed.\n if (!connectionId) continue;\n }\n\n // Per-field signature for dedupe.\n const perFieldSig = JSON.stringify({\n connectionId,\n deps: required?.fields?.map((d) => getPathValue(watchedValues, d)) ?? [],\n });\n if (lastFiredSigRef.current[slot.fieldPath] === perFieldSig) continue;\n lastFiredSigRef.current[slot.fieldPath] = perFieldSig;\n\n // Mark loading for this field's fetch.\n const existing = nextLoadStates[slot.fieldPath];\n nextLoadStates[slot.fieldPath] = {\n status: \"loading\",\n disabled: existing?.disabled ?? false,\n disabledReason: existing?.disabledReason,\n suggestionsDisabled: false,\n suggestionsDisabledReason: undefined,\n };\n\n const idKey = kind === \"search\" ? \"search_id\" : kind === \"effect\" ? \"effect_id\" : \"pipe_id\";\n\n Promise.resolve(\n resolvers.getFieldContext({\n fieldPath: slot.fieldPath,\n query: \"\",\n payload: {\n ...(watchedValues as Record<string, unknown>),\n [idKey]: pipeOrSearchId,\n },\n }),\n )\n .then((incoming: FormStore) => {\n if (cancelled) return;\n mergeStore(incoming);\n setFieldLoadStates((s) => ({\n ...s,\n [slot.fieldPath]: {\n ...(s[slot.fieldPath] ?? {\n disabled: false,\n suggestionsDisabled: false,\n }),\n status: \"ready\",\n },\n }));\n })\n .catch(() => {\n if (cancelled) return;\n setFieldLoadStates((s) => ({\n ...s,\n [slot.fieldPath]: {\n ...(s[slot.fieldPath] ?? {\n disabled: false,\n suggestionsDisabled: false,\n }),\n status: \"error\",\n },\n }));\n });\n }\n }\n\n // Reflect the latest enabledIf evaluation into fieldLoadStates so the\n // adapters and field-wrapper can render the disabled state.\n for (const fieldPath of Object.keys(byField)) {\n const { field: fieldR, suggestions: sugR } = byField[fieldPath]!;\n const prevState = nextLoadStates[fieldPath];\n nextLoadStates[fieldPath] = {\n status: prevState?.status ?? \"idle\",\n disabled: fieldR == null ? (prevState?.disabled ?? false) : fieldR.disabled,\n disabledReason: fieldR == null ? prevState?.disabledReason : fieldR.message,\n suggestionsDisabled:\n sugR == null ? (prevState?.suggestionsDisabled ?? false) : sugR.disabled,\n suggestionsDisabledReason:\n sugR == null ? prevState?.suggestionsDisabledReason : sugR.message,\n };\n }\n\n setFieldLoadStates(nextLoadStates);\n prevResultsRef.current = slotResults;\n\n return () => {\n cancelled = true;\n };\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, [slotResultsSig, slots, pipeOrSearchId]);\n\n // --- Sections & fields ---\n const isSubmitted = form.formState.isSubmitted;\n const formErrors = form.formState.errors;\n\n // `watchedValues` and `formErrors` must be in the dep array: field handles\n // bake `form.getValues(path)` snapshots into `field.value` / textareaProps /\n // selectedValue, and adapters render those as controlled inputs. Without\n // these deps, the memo never refreshes on keystrokes and the controlled\n // inputs snap back to their stale snapshot — typing/selecting appears to\n // do nothing. See FieldRenderer's memo comment for the intended contract.\n const sections = useMemo(\n () =>\n buildSectionHandles(formConfig, form as any, publicKey, {\n fieldLoadStates,\n searchSecrets,\n searchConstants,\n }),\n // eslint-disable-next-line react-hooks/exhaustive-deps\n [\n formConfig,\n form,\n publicKey,\n fieldLoadStates,\n isSubmitted,\n searchSecrets,\n searchConstants,\n watchedValues,\n formErrors,\n ],\n );\n\n const fields = useMemo(\n () => sections.flatMap((s) => s.groups.flatMap((g) => g.fields)),\n [sections],\n );\n\n const { fieldLoaderErrors, loadingFieldLoaders, hasFieldLoaderError, isFieldLoaderLoading } =\n useMemo(() => {\n const errors: Record<string, FieldLoadState> = {};\n const loading: Record<string, FieldLoadState> = {};\n for (const [path, state] of Object.entries(fieldLoadStates)) {\n if (state.status === \"error\") errors[path] = state;\n else if (state.status === \"loading\") loading[path] = state;\n }\n return {\n fieldLoaderErrors: errors,\n loadingFieldLoaders: loading,\n hasFieldLoaderError: Object.keys(errors).length > 0,\n isFieldLoaderLoading: Object.keys(loading).length > 0,\n };\n }, [fieldLoadStates]);\n\n return {\n connectionsStatus,\n fieldLoadStates,\n fieldLoaderErrors,\n loadingFieldLoaders,\n hasFieldLoaderError,\n isFieldLoaderLoading,\n form,\n sections,\n fields,\n reset: form.reset,\n };\n}\n"],"mappings":";;;;;;;AAuGA,SAAS,oBAAoB,YAA0C;CACrE,MAAM,MAAqB,EAAE;AAC7B,MAAK,MAAM,WAAW,WACpB,MAAK,MAAM,SAAS,QAAQ,OAC1B,MAAK,MAAM,SAAS,MAAM,QAAgC;AACxD,MAAI,MAAM,UACR,KAAI,KAAK;GACP,WAAW,MAAM;GACjB,QAAQ;GACR,WAAW,MAAM;GAClB,CAAC;AAIJ,OADE,MAAM,SAAS,0BAA0B,MAAM,SAAS,wBAChC,gBAAgB,SAAS,MAAM,YAAY;GACnE,MAAM,aAAa,MAAM;AAGzB,OAAI,YAAY,UACd,KAAI,KAAK;IACP,WAAW,MAAM;IACjB,QAAQ;IACR,WAAW,WAAW;IACtB;IACD,CAAC;OAKF,KAAI,KAAK;IACP,WAAW,MAAM;IACjB,QAAQ;IACR,kBAAkB,EAAE,UAAU,OAAO;IACrC;IACD,CAAC;;;AAMZ,QAAO;;AAGT,SAAS,aAAa,KAAc,MAAuB;CACzD,MAAM,QAAQ,KAAK,MAAM,IAAI;CAC7B,IAAI,MAAW;AACf,MAAK,MAAM,QAAQ,OAAO;AACxB,MAAI,OAAO,KAAM,QAAO;AACxB,QAAM,IAAI;;AAEZ,QAAO;;AAGT,SAAS,SAAS,MAAmB,SAAiC;AACpE,QAAO,KAAK,U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IACA,CAAC,gBAAgB,CAAC;AAEvB,QAAO;EACL;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA,OAAO,KAAK;EACb"}
@@ -0,0 +1,35 @@
1
+ import { PipeFormContext } from "../context/pipe-form-context.mjs";
2
+ import { GroupMap, PathMap, SectionMap } from "../types/form-customization.mjs";
3
+ import { FormResolvers, FormStore, SheetEffectId, SheetEffectPayload, ValidationContext } from "@pipe0/base";
4
+
5
+ //#region src/hooks/use-sheet-effect-form.d.ts
6
+ interface UseSheetEffectFormOptions {
7
+ effectId: SheetEffectId;
8
+ publicKey: string;
9
+ defaultValues?: SheetEffectPayload;
10
+ resolvers?: FormResolvers;
11
+ validationContext?: ValidationContext;
12
+ store?: FormStore;
13
+ /** Hide / relabel / reorder sections by section key. `null` hides a section. */
14
+ sectionMap?: SectionMap;
15
+ /** Hide / relabel / reorder groups by group path. `null` hides a group. */
16
+ groupMap?: GroupMap;
17
+ /** Hide / relabel fields by field path. `null` hides a field. */
18
+ pathMap?: PathMap;
19
+ scopes?: string[];
20
+ teamId?: string;
21
+ }
22
+ /**
23
+ * Effect analog of `usePipeForm` — drives a form for a sheet-effect payload
24
+ * (e.g. `sheet:rows:dedupe@1`) from `getSheetEffectPayloadFormConfig`.
25
+ *
26
+ * Returns a `PipeFormContext`-shaped object so the existing `<PipeForm>`
27
+ * compound components render it unchanged (the context interface is
28
+ * structural; only the `id`/payload generics differ). A dedicated
29
+ * `SheetEffectForm` compound family can be split out once effect forms need
30
+ * to diverge visually.
31
+ */
32
+ declare function useSheetEffectForm(options: UseSheetEffectFormOptions): PipeFormContext;
33
+ //#endregion
34
+ export { UseSheetEffectFormOptions, useSheetEffectForm };
35
+ //# sourceMappingURL=use-sheet-effect-form.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"use-sheet-effect-form.d.mts","names":[],"sources":["../../src/hooks/use-sheet-effect-form.ts"],"mappings":";;;;;UAsBiB,yBAAA;EACf,QAAA,EAAU,aAAA;EACV,SAAA;EACA,aAAA,GAAgB,kBAAA;EAChB,SAAA,GAAY,aAAA;EACZ,iBAAA,GAAoB,iBAAA;EACpB,KAAA,GAAQ,SAAA;EAFI;EAIZ,UAAA,GAAa,UAAA;EAFL;EAIR,QAAA,GAAW,QAAA;EAAA;EAEX,OAAA,GAAU,OAAA;EACV,MAAA;EACA,MAAA;AAAA;;;;;;;;;;;iBAac,kBAAA,CAAmB,OAAA,EAAS,yBAAA,GAA4B,eAAA"}
@@ -0,0 +1,104 @@
1
+ import { asFormHandle } from "../utils/internal-form.mjs";
2
+ import { applyFormCustomization } from "../utils/build-section-handlers.mjs";
3
+ import { useFormCore } from "./use-form-core.mjs";
4
+ import { useMemo, useState } from "react";
5
+ import { getSheetEffectDefaultPayload, getSheetEffectPayloadFormConfig, getSheetEffectPayloadSchema } from "@pipe0/base";
6
+
7
+ //#region src/hooks/use-sheet-effect-form.ts
8
+ /**
9
+ * Effect analog of `usePipeForm` — drives a form for a sheet-effect payload
10
+ * (e.g. `sheet:rows:dedupe@1`) from `getSheetEffectPayloadFormConfig`.
11
+ *
12
+ * Returns a `PipeFormContext`-shaped object so the existing `<PipeForm>`
13
+ * compound components render it unchanged (the context interface is
14
+ * structural; only the `id`/payload generics differ). A dedicated
15
+ * `SheetEffectForm` compound family can be split out once effect forms need
16
+ * to diverge visually.
17
+ */
18
+ function useSheetEffectForm(options) {
19
+ const { effectId, publicKey, defaultValues, resolvers, validationContext, store: defaultFormStore, sectionMap, groupMap, pathMap, scopes, teamId } = options;
20
+ const schema = useMemo(() => getSheetEffectPayloadSchema(effectId), [effectId]);
21
+ const [store, setStore] = useState(defaultFormStore ?? { field_options: {} });
22
+ const core = useFormCore({
23
+ pipeOrSearchId: effectId,
24
+ kind: "effect",
25
+ schema,
26
+ publicKey,
27
+ defaultValues,
28
+ store,
29
+ setStore,
30
+ formConfig: useMemo(() => {
31
+ const defaultPayload = getSheetEffectDefaultPayload(effectId);
32
+ if (!defaultPayload) throw new Error("No default payload");
33
+ return getSheetEffectPayloadFormConfig({
34
+ effectPayload: defaultPayload,
35
+ store,
36
+ validationContext,
37
+ formResolvers: resolvers
38
+ });
39
+ }, [
40
+ effectId,
41
+ defaultValues,
42
+ validationContext,
43
+ store
44
+ ]),
45
+ resolvers,
46
+ environment: validationContext?.environment,
47
+ scopes,
48
+ teamId
49
+ });
50
+ const hasGetConnections = resolvers?.getConnections != null;
51
+ const customization = useMemo(() => ({
52
+ sectionMap: hasGetConnections ? sectionMap ?? {} : {
53
+ ...sectionMap ?? {},
54
+ connector: null
55
+ },
56
+ groupMap: groupMap ?? {},
57
+ pathMap: pathMap ?? {}
58
+ }), [
59
+ sectionMap,
60
+ groupMap,
61
+ pathMap,
62
+ hasGetConnections
63
+ ]);
64
+ const sections = useMemo(() => applyFormCustomization(core.sections, customization), [core.sections, customization]);
65
+ const fields = useMemo(() => sections.flatMap((s) => s.groups.flatMap((g) => g.fields)), [sections]);
66
+ const fieldPaths = useMemo(() => new Set(sections.flatMap((s) => s.groups.flatMap((g) => g.fields.map((f) => f.path)))), [sections]);
67
+ return useMemo(() => ({
68
+ id: effectId,
69
+ publicKey,
70
+ form: asFormHandle(core.form),
71
+ sections,
72
+ fields,
73
+ fieldPaths,
74
+ connectionsStatus: core.connectionsStatus,
75
+ fieldLoadStates: core.fieldLoadStates,
76
+ fieldLoaderErrors: core.fieldLoaderErrors,
77
+ loadingFieldLoaders: core.loadingFieldLoaders,
78
+ hasFieldLoaderError: core.hasFieldLoaderError,
79
+ isFieldLoaderLoading: core.isFieldLoaderLoading,
80
+ resolvers,
81
+ store,
82
+ reset: core.reset
83
+ }), [
84
+ effectId,
85
+ publicKey,
86
+ core.form,
87
+ sections,
88
+ fields,
89
+ fieldPaths,
90
+ core.connectionsStatus,
91
+ core.fieldLoadStates,
92
+ core.fieldLoaderErrors,
93
+ core.loadingFieldLoaders,
94
+ core.hasFieldLoaderError,
95
+ core.isFieldLoaderLoading,
96
+ resolvers,
97
+ store,
98
+ core.reset
99
+ ]);
100
+ }
101
+
102
+ //#endregion
103
+ export { useSheetEffectForm };
104
+ //# sourceMappingURL=use-sheet-effect-form.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"use-sheet-effect-form.mjs","names":[],"sources":["../../src/hooks/use-sheet-effect-form.ts"],"sourcesContent":["import {\n type FormResolvers,\n type FormStore,\n getSheetEffectDefaultPayload,\n getSheetEffectPayloadFormConfig,\n getSheetEffectPayloadSchema,\n type SheetEffectId,\n type SheetEffectPayload,\n type ValidationContext,\n} from \"@pipe0/base\";\nimport { useMemo, useState } from \"react\";\nimport type { PipeFormContext } from \"../context/pipe-form-context.js\";\nimport type {\n FormCustomizationState,\n GroupMap,\n PathMap,\n SectionMap,\n} from \"../types/form-customization.js\";\nimport { applyFormCustomization } from \"../utils/build-section-handlers.js\";\nimport { asFormHandle } from \"../utils/internal-form.js\";\nimport { useFormCore } from \"./use-form-core.js\";\n\nexport interface UseSheetEffectFormOptions {\n effectId: SheetEffectId;\n publicKey: string;\n defaultValues?: SheetEffectPayload;\n resolvers?: FormResolvers;\n validationContext?: ValidationContext;\n store?: FormStore;\n /** Hide / relabel / reorder sections by section key. `null` hides a section. */\n sectionMap?: SectionMap;\n /** Hide / relabel / reorder groups by group path. `null` hides a group. */\n groupMap?: GroupMap;\n /** Hide / relabel fields by field path. `null` hides a field. */\n pathMap?: PathMap;\n scopes?: string[];\n teamId?: string;\n}\n\n/**\n * Effect analog of `usePipeForm` — drives a form for a sheet-effect payload\n * (e.g. `sheet:rows:dedupe@1`) from `getSheetEffectPayloadFormConfig`.\n *\n * Returns a `PipeFormContext`-shaped object so the existing `<PipeForm>`\n * compound components render it unchanged (the context interface is\n * structural; only the `id`/payload generics differ). A dedicated\n * `SheetEffectForm` compound family can be split out once effect forms need\n * to diverge visually.\n */\nexport function useSheetEffectForm(options: UseSheetEffectFormOptions): PipeFormContext {\n const {\n effectId,\n publicKey,\n defaultValues,\n resolvers,\n validationContext,\n store: defaultFormStore,\n sectionMap,\n groupMap,\n pathMap,\n scopes,\n teamId,\n } = options;\n\n const schema = useMemo(() => getSheetEffectPayloadSchema(effectId), [effectId]);\n\n const [store, setStore] = useState<FormStore>(defaultFormStore ?? { field_options: {} });\n\n const formConfig = useMemo(() => {\n const defaultPayload = getSheetEffectDefaultPayload(effectId);\n if (!defaultPayload) throw new Error(\"No default payload\");\n\n return getSheetEffectPayloadFormConfig({\n effectPayload: defaultPayload as SheetEffectPayload,\n store,\n validationContext,\n formResolvers: resolvers,\n });\n }, [effectId, defaultValues, validationContext, store]);\n\n const core = useFormCore<SheetEffectPayload>({\n pipeOrSearchId: effectId,\n kind: \"effect\",\n schema,\n publicKey,\n defaultValues,\n store,\n setStore,\n formConfig,\n resolvers,\n environment: validationContext?.environment,\n scopes,\n teamId,\n });\n\n // Connector auto-hides without a `getConnections` resolver — mirrors\n // `usePipeForm`.\n const hasGetConnections = resolvers?.getConnections != null;\n const customization = useMemo<FormCustomizationState>(\n () => ({\n sectionMap: hasGetConnections\n ? (sectionMap ?? {})\n : { ...(sectionMap ?? {}), connector: null },\n groupMap: groupMap ?? {},\n pathMap: pathMap ?? {},\n }),\n [sectionMap, groupMap, pathMap, hasGetConnections],\n );\n\n const sections = useMemo(\n () => applyFormCustomization(core.sections, customization),\n [core.sections, customization],\n );\n\n const fields = useMemo(\n () => sections.flatMap((s) => s.groups.flatMap((g) => g.fields)),\n [sections],\n );\n\n const fieldPaths = useMemo(\n () => new Set(sections.flatMap((s) => s.groups.flatMap((g) => g.fields.map((f) => f.path)))),\n [sections],\n );\n\n return useMemo<PipeFormContext>(\n () => ({\n // Structural reuse of PipeFormContext — see the function docblock.\n id: effectId as unknown as PipeFormContext[\"id\"],\n publicKey,\n form: asFormHandle(core.form) as unknown as PipeFormContext[\"form\"],\n sections,\n fields,\n fieldPaths,\n connectionsStatus: core.connectionsStatus,\n fieldLoadStates: core.fieldLoadStates,\n fieldLoaderErrors: core.fieldLoaderErrors,\n loadingFieldLoaders: core.loadingFieldLoaders,\n hasFieldLoaderError: core.hasFieldLoaderError,\n isFieldLoaderLoading: core.isFieldLoaderLoading,\n resolvers,\n store,\n reset: core.reset as unknown as PipeFormContext[\"reset\"],\n }),\n [\n effectId,\n publicKey,\n core.form,\n sections,\n fields,\n fieldPaths,\n core.connectionsStatus,\n core.fieldLoadStates,\n core.fieldLoaderErrors,\n core.loadingFieldLoaders,\n core.hasFieldLoaderError,\n core.isFieldLoaderLoading,\n resolvers,\n store,\n core.reset,\n ],\n );\n}\n"],"mappings":";;;;;;;;;;;;;;;;;AAiDA,SAAgB,mBAAmB,SAAqD;CACtF,MAAM,EACJ,UACA,WACA,eACA,WACA,mBACA,OAAO,kBACP,YACA,UACA,SACA,QACA,WACE;CAEJ,MAAM,SAAS,cAAc,4BAA4B,SAAS,EAAE,CAAC,SAAS,CAAC;CAE/E,MAAM,CAAC,OAAO,YAAY,SAAoB,oBAAoB,EAAE,eAAe,EAAE,EAAE,CAAC;CAcxF,MAAM,OAAO,YAAgC;EAC3C,gBAAgB;EAChB,MAAM;EACN;EACA;EACA;EACA;EACA;EACA,YApBiB,cAAc;GAC/B,MAAM,iBAAiB,6BAA6B,SAAS;AAC7D,OAAI,CAAC,eAAgB,OAAM,IAAI,MAAM,qBAAqB;AAE1D,UAAO,gCAAgC;IACrC,eAAe;IACf;IACA;IACA,eAAe;IAChB,CAAC;KACD;GAAC;GAAU;GAAe;GAAmB;GAAM,CAAC;EAWrD;EACA,aAAa,mBAAmB;EAChC;EACA;EACD,CAAC;CAIF,MAAM,oBAAoB,WAAW,kBAAkB;CACvD,MAAM,gBAAgB,eACb;EACL,YAAY,oBACP,cAAc,EAAE,GACjB;GAAE,GAAI,cAAc,EAAE;GAAG,WAAW;GAAM;EAC9C,UAAU,YAAY,EAAE;EACxB,SAAS,WAAW,EAAE;EACvB,GACD;EAAC;EAAY;EAAU;EAAS;EAAkB,CACnD;CAED,MAAM,WAAW,cACT,uBAAuB,KAAK,UAAU,cAAc,EAC1D,CAAC,KAAK,UAAU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