@gaddario98/react-core 2.1.7 → 2.1.9

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,4 +1,4 @@
1
- import {jsx,jsxs}from'react/jsx-runtime';import {useRef,useState,useEffect,useCallback,memo,useMemo,createContext,useContext}from'react';import {useApiValues,useApiConfigValue,useApi,queriesAtom}from'../queries/index.mjs';import {atom,useAtom,useStore}from'jotai';import {c}from'react/compiler-runtime';import {atomStateGenerator}from'../state/index.mjs';import equal from'fast-deep-equal';import {useFormValues,useFormManager}from'../form/index.mjs';import {atomFamily}from'jotai-family';import {QueryObserver}from'@tanstack/react-query';/******************************************************************************
1
+ import {jsx,jsxs}from'react/jsx-runtime';import {useRef,useState,useEffect,useCallback,memo,useMemo,createContext,useContext}from'react';import {c}from'react/compiler-runtime';import {atomStateGenerator}from'../state/index.mjs';import equal from'fast-deep-equal';import {useFormValues,useFormManager}from'../form/index.mjs';import {atom,useAtom}from'jotai';import {useApiValues,useApiConfigValue,useApi,useInvalidateQueries}from'../queries/index.mjs';import {atomFamily}from'jotai-family';import {QueryObserver}from'@tanstack/react-query';/******************************************************************************
2
2
  Copyright (c) Microsoft Corporation.
3
3
 
4
4
  Permission to use, copy, modify, and/or distribute this software for any
@@ -1534,147 +1534,88 @@ function useFormData({
1534
1534
  formData
1535
1535
  };
1536
1536
  };const EMPTY_ARRAY = [];
1537
- const usePageConfig = t0 => {
1538
- const $ = c(27);
1539
- const {
1540
- queries: t1,
1541
- form,
1542
- ns,
1543
- viewSettings: t2,
1544
- meta,
1545
- variables,
1546
- pageId
1547
- } = t0;
1548
- const queries = t1 === undefined ? EMPTY_ARRAY : t1;
1549
- let t3;
1550
- if ($[0] !== t2) {
1551
- t3 = t2 === undefined ? {} : t2;
1552
- $[0] = t2;
1553
- $[1] = t3;
1554
- } else {
1555
- t3 = $[1];
1556
- }
1557
- const viewSettings = t3;
1537
+ const usePageConfig = ({
1538
+ queries = EMPTY_ARRAY,
1539
+ form,
1540
+ ns,
1541
+ viewSettings = {},
1542
+ meta,
1543
+ variables,
1544
+ pageId
1545
+ }) => {
1546
+ // Use global config usage if needed, but per-page config is primary
1558
1547
  const globalConfig = usePageConfigValue();
1559
- let t4;
1560
- if ($[2] !== form || $[3] !== ns || $[4] !== pageId) {
1561
- t4 = {
1562
- form,
1563
- pageId,
1564
- ns
1565
- };
1566
- $[2] = form;
1567
- $[3] = ns;
1568
- $[4] = pageId;
1569
- $[5] = t4;
1570
- } else {
1571
- t4 = $[5];
1572
- }
1548
+ // 1. Form Management
1573
1549
  const {
1574
1550
  formData
1575
- } = usePageFormManager(t4);
1576
- let t5;
1577
- if ($[6] !== pageId || $[7] !== variables) {
1578
- t5 = {
1579
- pageId,
1580
- initialValues: variables
1581
- };
1582
- $[6] = pageId;
1583
- $[7] = variables;
1584
- $[8] = t5;
1585
- } else {
1586
- t5 = $[8];
1587
- }
1551
+ } = usePageFormManager({
1552
+ form,
1553
+ pageId,
1554
+ ns
1555
+ });
1588
1556
  const {
1589
1557
  get,
1590
1558
  set
1591
- } = usePageValues(t5);
1592
- let t6;
1593
- if ($[9] !== get || $[10] !== queries || $[11] !== set) {
1594
- let t7;
1595
- if ($[13] !== get || $[14] !== set) {
1596
- t7 = q => {
1597
- if (q.type === "mutation") {
1598
- const mutationConfig = typeof q.mutationConfig === "function" ? q.mutationConfig({
1599
- get,
1600
- set
1601
- }) : q.mutationConfig;
1602
- return Object.assign(Object.assign({}, q), {
1603
- mutationConfig
1604
- });
1605
- } else {
1606
- if (q.type === "query") {
1607
- const queryConfig = typeof q.queryConfig === "function" ? q.queryConfig({
1608
- get,
1609
- set
1610
- }) : q.queryConfig;
1611
- return Object.assign(Object.assign({}, q), {
1612
- queryConfig
1613
- });
1614
- }
1615
- }
1616
- return q;
1617
- };
1618
- $[13] = get;
1619
- $[14] = set;
1620
- $[15] = t7;
1621
- } else {
1622
- t7 = $[15];
1623
- }
1624
- t6 = queries.map(t7);
1625
- $[9] = get;
1626
- $[10] = queries;
1627
- $[11] = set;
1628
- $[12] = t6;
1629
- } else {
1630
- t6 = $[12];
1631
- }
1632
- const processedQueries = t6;
1633
- let t7;
1634
- if ($[16] !== pageId) {
1635
- t7 = {
1636
- persistToAtoms: true,
1637
- scopeId: pageId
1638
- };
1639
- $[16] = pageId;
1640
- $[17] = t7;
1641
- } else {
1642
- t7 = $[17];
1643
- }
1644
- useApi(processedQueries, t7);
1645
- let t8;
1646
- if ($[18] !== pageId || $[19] !== viewSettings) {
1647
- t8 = {
1648
- viewSettings,
1649
- pageId
1650
- };
1651
- $[18] = pageId;
1652
- $[19] = viewSettings;
1653
- $[20] = t8;
1654
- } else {
1655
- t8 = $[20];
1656
- }
1657
- const mappedViewSettings = useViewSettings(t8);
1658
- let t9;
1659
- if ($[21] !== form || $[22] !== formData || $[23] !== globalConfig || $[24] !== mappedViewSettings || $[25] !== meta) {
1660
- t9 = {
1559
+ } = usePageValues({
1560
+ pageId,
1561
+ initialValues: variables
1562
+ });
1563
+ // 2. Query Generation
1564
+ const processedQueries = useMemo(() => {
1565
+ return queries.map(q => {
1566
+ if (q.type === "mutation") {
1567
+ const mutationConfig = typeof q.mutationConfig === "function" ? q.mutationConfig({
1568
+ get,
1569
+ set
1570
+ }) : q.mutationConfig;
1571
+ return Object.assign(Object.assign({}, q), {
1572
+ mutationConfig
1573
+ });
1574
+ // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
1575
+ } else if (q.type === "query") {
1576
+ const queryConfig = typeof q.queryConfig === "function" ? q.queryConfig({
1577
+ get,
1578
+ set
1579
+ }) : q.queryConfig;
1580
+ return Object.assign(Object.assign({}, q), {
1581
+ queryConfig
1582
+ });
1583
+ }
1584
+ return q;
1585
+ });
1586
+ }, [queries, get, set]);
1587
+ useApi(processedQueries, {
1588
+ persistToAtoms: true,
1589
+ scopeId: pageId
1590
+ });
1591
+ const {
1592
+ invalidateQueries
1593
+ } = useInvalidateQueries();
1594
+ const refreshQueries = useCallback(() => {
1595
+ processedQueries.filter(el => el.type === "query").forEach(({
1596
+ queryConfig: queryConfig_0
1597
+ }) => {
1598
+ if (queryConfig_0 === null || queryConfig_0 === void 0 ? void 0 : queryConfig_0.queryKey) invalidateQueries([queryConfig_0 === null || queryConfig_0 === void 0 ? void 0 : queryConfig_0.queryKey]);
1599
+ });
1600
+ }, [processedQueries]);
1601
+ const mappedViewSettings = useViewSettings({
1602
+ viewSettings,
1603
+ pageId
1604
+ });
1605
+ // Merge custom configuration with defaults
1606
+ const mergedConfig = useMemo(() => {
1607
+ return {
1661
1608
  formData,
1662
1609
  form,
1663
1610
  mappedViewSettings,
1664
1611
  meta,
1665
- globalConfig
1612
+ globalConfig // Expose global config if needed
1666
1613
  };
1667
- $[21] = form;
1668
- $[22] = formData;
1669
- $[23] = globalConfig;
1670
- $[24] = mappedViewSettings;
1671
- $[25] = meta;
1672
- $[26] = t9;
1673
- } else {
1674
- t9 = $[26];
1675
- }
1676
- const mergedConfig = t9;
1677
- return mergedConfig;
1614
+ }, [formData, form, mappedViewSettings, meta, globalConfig]);
1615
+ return {
1616
+ mergedConfig,
1617
+ refreshQueries
1618
+ };
1678
1619
  };/**
1679
1620
  * Hook for evaluating and managing dynamic metadata.
1680
1621
  *
@@ -1921,7 +1862,10 @@ const MetadataManager = MetadataManagerImpl;const PageGenerator = _a => {
1921
1862
  viewSettings,
1922
1863
  ns
1923
1864
  } = useMemo(() => selectedProps, [selectedProps]);
1924
- const config = usePageConfig({
1865
+ const {
1866
+ mergedConfig,
1867
+ refreshQueries
1868
+ } = usePageConfig({
1925
1869
  queries,
1926
1870
  form,
1927
1871
  ns: ns !== null && ns !== void 0 ? ns : "",
@@ -1929,9 +1873,6 @@ const MetadataManager = MetadataManagerImpl;const PageGenerator = _a => {
1929
1873
  pageId: id,
1930
1874
  variables
1931
1875
  });
1932
- const {
1933
- mappedViewSettings
1934
- } = config;
1935
1876
  const {
1936
1877
  allContents,
1937
1878
  body,
@@ -1941,8 +1882,11 @@ const MetadataManager = MetadataManagerImpl;const PageGenerator = _a => {
1941
1882
  contents,
1942
1883
  pageId: id,
1943
1884
  ns,
1944
- pageConfig: config
1885
+ pageConfig: mergedConfig
1945
1886
  });
1887
+ const {
1888
+ mappedViewSettings
1889
+ } = mergedConfig;
1946
1890
  const LayoutComponent = useMemo(() => {
1947
1891
  var _a_0;
1948
1892
  return (_a_0 = mappedViewSettings.layoutComponent) !== null && _a_0 !== void 0 ? _a_0 : BodyContainer;
@@ -1960,13 +1904,6 @@ const MetadataManager = MetadataManagerImpl;const PageGenerator = _a => {
1960
1904
  return (_a_3 = mappedViewSettings.pageContainerProps) !== null && _a_3 !== void 0 ? _a_3 : {};
1961
1905
  }, [mappedViewSettings.pageContainerProps]);
1962
1906
  const layoutBody = useMemo(() => body, [body]);
1963
- const store = useStore();
1964
- const refreshQueries = useCallback(() => {
1965
- const val = store.get(queriesAtom);
1966
- Object.values(val).forEach(query => {
1967
- query.refetch();
1968
- });
1969
- }, [store]);
1970
1907
  return jsxs(PageContainerComponent, Object.assign({
1971
1908
  id: id
1972
1909
  }, pageContainerProps, {