@payloadcms/ui 3.59.0-internal.ff6711a → 3.59.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 (56) hide show
  1. package/dist/elements/Collapsible/index.d.ts +2 -15
  2. package/dist/elements/Collapsible/index.d.ts.map +1 -1
  3. package/dist/elements/Collapsible/index.js +60 -59
  4. package/dist/elements/Collapsible/index.js.map +1 -1
  5. package/dist/elements/Collapsible/index.scss +2 -6
  6. package/dist/elements/DocumentDrawer/Provider.d.ts +1 -1
  7. package/dist/elements/DocumentDrawer/Provider.js.map +1 -1
  8. package/dist/elements/Nav/context.d.ts +0 -6
  9. package/dist/elements/Nav/context.d.ts.map +1 -1
  10. package/dist/elements/Nav/context.js +0 -6
  11. package/dist/elements/Nav/context.js.map +1 -1
  12. package/dist/elements/PageControls/index.d.ts +0 -9
  13. package/dist/elements/PageControls/index.d.ts.map +1 -1
  14. package/dist/elements/PageControls/index.js +45 -101
  15. package/dist/elements/PageControls/index.js.map +1 -1
  16. package/dist/elements/StickyToolbar/index.d.ts +0 -3
  17. package/dist/elements/StickyToolbar/index.d.ts.map +1 -1
  18. package/dist/elements/StickyToolbar/index.js +0 -3
  19. package/dist/elements/StickyToolbar/index.js.map +1 -1
  20. package/dist/exports/client/{CodeEditor-2AHTKKBE.js → CodeEditor-UTOLPRAV.js} +2 -2
  21. package/dist/exports/client/{chunk-6UH4KUYK.js → chunk-S2X3JKSP.js} +1 -1
  22. package/dist/exports/client/{chunk-6UH4KUYK.js.map → chunk-S2X3JKSP.js.map} +1 -1
  23. package/dist/exports/client/index.d.ts +2 -4
  24. package/dist/exports/client/index.d.ts.map +1 -1
  25. package/dist/exports/client/index.js +12 -12
  26. package/dist/exports/client/index.js.map +4 -4
  27. package/dist/fields/Code/index.d.ts.map +1 -1
  28. package/dist/fields/Code/index.js +1 -3
  29. package/dist/fields/Code/index.js.map +1 -1
  30. package/dist/fields/Slug/index.d.ts +8 -0
  31. package/dist/fields/Slug/index.d.ts.map +1 -0
  32. package/dist/fields/Slug/index.js +128 -0
  33. package/dist/fields/Slug/index.js.map +1 -0
  34. package/dist/fields/Slug/index.scss +17 -0
  35. package/dist/forms/Form/fieldReducer.d.ts.map +1 -1
  36. package/dist/forms/Form/fieldReducer.js +40 -16
  37. package/dist/forms/Form/fieldReducer.js.map +1 -1
  38. package/dist/forms/Form/types.d.ts +2 -2
  39. package/dist/forms/Form/types.js.map +1 -1
  40. package/dist/forms/RenderFields/context.d.ts +2 -2
  41. package/dist/forms/RenderFields/context.js +2 -2
  42. package/dist/forms/RenderFields/context.js.map +1 -1
  43. package/dist/hooks/useControllableState.d.ts +0 -2
  44. package/dist/hooks/useControllableState.d.ts.map +1 -1
  45. package/dist/hooks/useControllableState.js +11 -44
  46. package/dist/hooks/useControllableState.js.map +1 -1
  47. package/dist/providers/Config/index.d.ts +1 -1
  48. package/dist/providers/Config/index.js +1 -1
  49. package/dist/providers/Config/index.js.map +1 -1
  50. package/dist/styles.css +1 -1
  51. package/dist/utilities/handleLivePreview.d.ts +1 -1
  52. package/dist/utilities/handleLivePreview.d.ts.map +1 -1
  53. package/dist/utilities/handleLivePreview.js +1 -1
  54. package/dist/utilities/handleLivePreview.js.map +1 -1
  55. package/package.json +4 -4
  56. /package/dist/exports/client/{CodeEditor-2AHTKKBE.js.map → CodeEditor-UTOLPRAV.js.map} +0 -0
@@ -1,54 +1,21 @@
1
- 'use client';
2
-
3
- import { c as _c } from "react/compiler-runtime";
4
1
  import { useCallback, useEffect, useRef, useState } from 'react';
5
2
  /**
6
3
  * A hook for managing state that can be controlled by props but also overridden locally.
7
4
  * Props always take precedence if they change, but local state can override them temporarily.
8
- *
9
- * @internal - may change or be removed without a major version bump
10
5
  */
11
6
  export function useControllableState(propValue, defaultValue) {
12
- const $ = _c(6);
13
7
  const [localValue, setLocalValue] = useState(propValue ?? defaultValue);
14
8
  const initialRenderRef = useRef(true);
15
- let t0;
16
- let t1;
17
- if ($[0] !== propValue) {
18
- t0 = () => {
19
- if (initialRenderRef.current) {
20
- initialRenderRef.current = false;
21
- return;
22
- }
23
- setLocalValue(propValue);
24
- };
25
- t1 = [propValue];
26
- $[0] = propValue;
27
- $[1] = t0;
28
- $[2] = t1;
29
- } else {
30
- t0 = $[1];
31
- t1 = $[2];
32
- }
33
- useEffect(t0, t1);
34
- let t2;
35
- if ($[3] === Symbol.for("react.memo_cache_sentinel")) {
36
- t2 = value => {
37
- setLocalValue(value);
38
- };
39
- $[3] = t2;
40
- } else {
41
- t2 = $[3];
42
- }
43
- const setValue = t2;
44
- let t3;
45
- if ($[4] !== localValue) {
46
- t3 = [localValue, setValue];
47
- $[4] = localValue;
48
- $[5] = t3;
49
- } else {
50
- t3 = $[5];
51
- }
52
- return t3;
9
+ useEffect(() => {
10
+ if (initialRenderRef.current) {
11
+ initialRenderRef.current = false;
12
+ return;
13
+ }
14
+ setLocalValue(propValue);
15
+ }, [propValue]);
16
+ const setValue = useCallback(value => {
17
+ setLocalValue(value);
18
+ }, []);
19
+ return [localValue, setValue];
53
20
  }
54
21
  //# sourceMappingURL=useControllableState.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"useControllableState.js","names":["c","_c","useCallback","useEffect","useRef","useState","useControllableState","propValue","defaultValue","$","localValue","setLocalValue","initialRenderRef","t0","t1","current","t2","Symbol","for","value","setValue","t3"],"sources":["../../src/hooks/useControllableState.ts"],"sourcesContent":["'use client'\nimport { useCallback, useEffect, useRef, useState } from 'react'\n\n/**\n * A hook for managing state that can be controlled by props but also overridden locally.\n * Props always take precedence if they change, but local state can override them temporarily.\n *\n * @internal - may change or be removed without a major version bump\n */\nexport function useControllableState<T>(\n propValue: T,\n defaultValue?: T,\n): [T, (value: ((prev: T) => T) | T) => void] {\n const [localValue, setLocalValue] = useState<T>(propValue ?? defaultValue)\n const initialRenderRef = useRef(true)\n\n useEffect(() => {\n if (initialRenderRef.current) {\n initialRenderRef.current = false\n return\n }\n\n setLocalValue(propValue)\n }, [propValue])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AA,OAAtBY,EAAsB;AAAA","ignoreList":[]}
1
+ {"version":3,"file":"useControllableState.js","names":["useCallback","useEffect","useRef","useState","useControllableState","propValue","defaultValue","localValue","setLocalValue","initialRenderRef","current","setValue","value"],"sources":["../../src/hooks/useControllableState.ts"],"sourcesContent":["import { useCallback, useEffect, useRef, useState } from 'react'\n\n/**\n * A hook for managing state that can be controlled by props but also overridden locally.\n * Props always take precedence if they change, but local state can override them temporarily.\n */\nexport function useControllableState<T>(\n propValue: T,\n defaultValue?: T,\n): [T, (value: ((prev: T) => T) | T) => void] {\n const [localValue, setLocalValue] = useState<T>(propValue ?? defaultValue)\n const initialRenderRef = useRef(true)\n\n useEffect(() => {\n if (initialRenderRef.current) {\n initialRenderRef.current = false\n return\n }\n\n setLocalValue(propValue)\n }, [propValue])\n\n const setValue = useCallback((value: ((prev: T) => T) | T) => {\n setLocalValue(value)\n }, [])\n\n return [localValue, setValue]\n}\n"],"mappings":"AAAA,SAASA,WAAW,EAAEC,SAAS,EAAEC,MAAM,EAAEC,QAAQ,QAAQ;AAEzD;;;;AAIA,OAAO,SAASC,qBACdC,SAAY,EACZC,YAAgB;EAEhB,MAAM,CAACC,UAAA,EAAYC,aAAA,CAAc,GAAGL,QAAA,CAAYE,SAAA,IAAaC,YAAA;EAC7D,MAAMG,gBAAA,GAAmBP,MAAA,CAAO;EAEhCD,SAAA,CAAU;IACR,IAAIQ,gBAAA,CAAiBC,OAAO,EAAE;MAC5BD,gBAAA,CAAiBC,OAAO,GAAG;MAC3B;IACF;IAEAF,aAAA,CAAcH,SAAA;EAChB,GAAG,CAACA,SAAA,CAAU;EAEd,MAAMM,QAAA,GAAWX,WAAA,CAAaY,KAAA;IAC5BJ,aAAA,CAAcI,KAAA;EAChB,GAAG,EAAE;EAEL,OAAO,CAACL,UAAA,EAAYI,QAAA,CAAS;AAC/B","ignoreList":[]}
@@ -38,7 +38,7 @@ export declare const useConfig: () => ClientConfigContext;
38
38
  * If the config here has the same reference as the config from the layout, we
39
39
  * simply reuse the context from the layout to avoid unnecessary re-renders.
40
40
  *
41
- * @experimental This component is experimental and may change or be removed in future releases. Use at your own discretion.
41
+ * @experimental This component is experimental and may change or be removed in future releases. Use at your own risk.
42
42
  */
43
43
  export declare const PageConfigProvider: React.FC<{
44
44
  readonly children: React.ReactNode;
@@ -67,7 +67,7 @@ export const useConfig = () => use(RootConfigContext);
67
67
  * If the config here has the same reference as the config from the layout, we
68
68
  * simply reuse the context from the layout to avoid unnecessary re-renders.
69
69
  *
70
- * @experimental This component is experimental and may change or be removed in future releases. Use at your own discretion.
70
+ * @experimental This component is experimental and may change or be removed in future releases. Use at your own risk.
71
71
  */
72
72
  export const PageConfigProvider = t0 => {
73
73
  const $ = _c(7);
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","names":["c","_c","React","createContext","use","useCallback","useEffect","useMemo","useRef","useState","RootConfigContext","undefined","ConfigProvider","children","config","configFromProps","setConfig","isFirstRenderRef","current","collectionsBySlug","globalsBySlug","collection","collections","slug","global","globals","getEntityConfig","args","collectionSlug","globalSlug","value","_jsx","useConfig","PageConfigProvider","t0","$","rootConfig","setRootConfig","t1","t2","unauthenticated","t3"],"sources":["../../../src/providers/Config/index.tsx"],"sourcesContent":["/* eslint-disable perfectionist/sort-object-types */ // Need to disable this rule because the order of the overloads is important\n'use client'\nimport type {\n ClientCollectionConfig,\n ClientConfig,\n ClientGlobalConfig,\n CollectionSlug,\n GlobalSlug,\n} from 'payload'\n\nimport React, { createContext, use, useCallback, useEffect, useMemo, useRef, useState } from 'react'\n\ntype GetEntityConfigFn = {\n // Overload #1: collectionSlug only\n // @todo remove \"{} |\" in 4.0, which would be a breaking change\n (args: { collectionSlug: {} | CollectionSlug; globalSlug?: never }): ClientCollectionConfig\n\n // Overload #2: globalSlug only\n // @todo remove \"{} |\" in 4.0, which would be a breaking change\n (args: { collectionSlug?: never; globalSlug: {} | GlobalSlug }): ClientGlobalConfig\n\n // Overload #3: both/none (fall back to union | null)\n (args: {\n collectionSlug?: {} | CollectionSlug\n globalSlug?: {} | GlobalSlug\n }): ClientCollectionConfig | ClientGlobalConfig | null\n}\n\nexport type ClientConfigContext = {\n config: ClientConfig\n /**\n * Get a collection or global config by its slug. This is preferred over\n * using `config.collections.find` or `config.globals.find`, because\n * getEntityConfig uses a lookup map for O(1) lookups.\n */\n getEntityConfig: GetEntityConfigFn\n setConfig: (config: ClientConfig) => void\n}\n\nconst RootConfigContext = createContext<ClientConfigContext | undefined>(undefined)\n\nexport const ConfigProvider: React.FC<{\n readonly children: React.ReactNode\n readonly config: ClientConfig\n}> = ({ children, config: configFromProps }) => {\n const [config, setConfig] = useState<ClientConfig>(configFromProps)\n\n const isFirstRenderRef = useRef(true)\n\n // Need to update local config state if config from props changes, for HMR.\n // That way, config changes will be updated in the UI immediately without needing a refresh.\n useEffect(() => {\n if (isFirstRenderRef.current) {\n isFirstRenderRef.current = false\n return\n }\n\n setConfig(configFromProps)\n }, [configFromProps, setConfig])\n\n // Build lookup maps for collections and globals so we can do O(1) lookups by slug\n const { collectionsBySlug, globalsBySlug } = useMemo(() => {\n const collectionsBySlug: Record<string, ClientCollectionConfig> = {}\n const globalsBySlug: Record<string, ClientGlobalConfig> = {}\n\n for (const collection of config.collections) {\n collectionsBySlug[collection.slug] = collection\n }\n\n for (const global of config.globals) {\n globalsBySlug[global.slug] = global\n }\n\n return { collectionsBySlug, globalsBySlug }\n }, [config])\n\n const getEntityConfig = useCallback<GetEntityConfigFn>(\n (args) => {\n if ('collectionSlug' in args) {\n return collectionsBySlug[args.collectionSlug] ?? null\n }\n\n if ('globalSlug' in args) {\n return globalsBySlug[args.globalSlug] ?? null\n }\n\n return null as any\n },\n [collectionsBySlug, globalsBySlug],\n )\n\n const value = useMemo(\n () => ({ config, getEntityConfig, setConfig }),\n [config, getEntityConfig, setConfig],\n )\n\n return <RootConfigContext value={value}>{children}</RootConfigContext>\n}\n\nexport const useConfig = (): ClientConfigContext => use(RootConfigContext)\n\n/**\n * This provider shadows the `ConfigProvider` on the _page_ level, allowing us to\n * update the config when needed, e.g. after authentication.\n * The layout `ConfigProvider` is not updated on page navigation / authentication,\n * as the layout does not re-render in those cases.\n *\n * If the config here has the same reference as the config from the layout, we\n * simply reuse the context from the layout to avoid unnecessary re-renders.\n *\n * @experimental This component is experimental and may change or be removed in future releases. Use at your own discretion.\n */\nexport const PageConfigProvider: React.FC<{\n readonly children: React.ReactNode\n readonly config: ClientConfig\n}> = ({ children, config: configFromProps }) => {\n const { config: rootConfig, setConfig: setRootConfig } = useConfig()\n\n /**\n * This `useEffect` is required in order for the _page_ to be able to refresh the client config,\n * which may have been cached on the _layout_ level, where the `ConfigProvider` is managed.\n * Since the layout does not re-render on page navigation / authentication, we need to manually\n * update the config, as the user may have been authenticated in the process, which affects the client config.\n */\n useEffect(() => {\n setRootConfig(configFromProps)\n }, [configFromProps, setRootConfig])\n\n // If this component receives a different config than what is in context from the layout, it is stale.\n // While stale, we instantiate a new context provider that provides the new config until the root context is updated.\n // Unfortunately, referential equality alone does not work bc the reference is lost during server/client serialization,\n // so we need to also compare the `unauthenticated` property.\n if (\n rootConfig !== configFromProps &&\n rootConfig.unauthenticated !== configFromProps.unauthenticated\n ) {\n return <ConfigProvider config={configFromProps}>{children}</ConfigProvider>\n }\n\n return children\n}\n"],"mappings":"AAAA,sDAAsD;AACtD;;AAAA,SAAAA,CAAA,IAAAC,EAAA;;AASA,OAAOC,KAAA,IAASC,aAAa,EAAEC,GAAG,EAAEC,WAAW,EAAEC,SAAS,EAAEC,OAAO,EAAEC,MAAM,EAAEC,QAAQ,QAAQ;AA6B7F,MAAMC,iBAAA,gBAAoBP,aAAA,CAA+CQ,SAAA;AAEzE,OAAO,MAAMC,cAAA,GAGRA,CAAC;EAAEC,QAAQ;EAAEC,MAAA,EAAQC;AAAe,CAAE;EACzC,MAAM,CAACD,MAAA,EAAQE,SAAA,CAAU,GAAGP,QAAA,CAAuBM,eAAA;EAEnD,MAAME,gBAAA,GAAmBT,MAAA,CAAO;EAEh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A,CAAA,KAA2B5B,GAAA,CAAIM,iBAAA;AAExD;;;;;;;;;;;AAWA,OAAO,MAAMuB,kBAAA,GAGRC,EAAA;EAAA,MAAAC,CAAA,GAAAlC,EAAA;EAAC;IAAAY,QAAA;IAAAC,MAAA,EAAAC;EAAA,IAAAmB,EAAqC;EACzC;IAAApB,MAAA,EAAAsB,UAAA;IAAApB,SAAA,EAAAqB;EAAA,IAAyDL,SAAA;EAAA,IAAAM,EAAA;EAAA,IAAAC,EAAA;EAAA,IAAAJ,CAAA,QAAApB,eAAA,IAAAoB,CAAA,QAAAE,aAAA;IAQ/CC,EAAA,GAAAA,CAAA;MACRD,aAAA,CAActB,eAAA;IAAA;IACbwB,EAAA,IAACxB,eAAA,EAAiBsB,aAAA;IAAcF,CAAA,MAAApB,eAAA;IAAAoB,CAAA,MAAAE,aAAA;IAAAF,CAAA,MAAAG,EAAA;IAAAH,CAAA,MAAAI,EAAA;EAAA;IAAAD,EAAA,GAAAH,CAAA;IAAAI,EAAA,GAAAJ,CAAA;EAAA;EAFnC7B,SAAA,CAAUgC,EAEV,EAAGC,EAAgC;EAAA,IAOjCH,UAAA,KAAerB,eAAA,IACfqB,UAAA,CAAAI,eAAA,KAA+BzB,eAAA,CAAAyB,eAA+B;IAAA,IAAAC,EAAA;IAAA,IAAAN,CAAA,QAAAtB,QAAA,IAAAsB,CAAA,QAAApB,eAAA;MAEvD0B,EAAA,GAAAV,IAAA,CAAAnB,cAAA;QAAAE,MAAA,EAAwBC,eAAA;QAAAF;MAAA,C;;;;;;;WAAxB4B,E;;SAGF5B,QAAA;AAAA,CACT","ignoreList":[]}
1
+ {"version":3,"file":"index.js","names":["c","_c","React","createContext","use","useCallback","useEffect","useMemo","useRef","useState","RootConfigContext","undefined","ConfigProvider","children","config","configFromProps","setConfig","isFirstRenderRef","current","collectionsBySlug","globalsBySlug","collection","collections","slug","global","globals","getEntityConfig","args","collectionSlug","globalSlug","value","_jsx","useConfig","PageConfigProvider","t0","$","rootConfig","setRootConfig","t1","t2","unauthenticated","t3"],"sources":["../../../src/providers/Config/index.tsx"],"sourcesContent":["/* eslint-disable perfectionist/sort-object-types */ // Need to disable this rule because the order of the overloads is important\n'use client'\nimport type {\n ClientCollectionConfig,\n ClientConfig,\n ClientGlobalConfig,\n CollectionSlug,\n GlobalSlug,\n} from 'payload'\n\nimport React, { createContext, use, useCallback, useEffect, useMemo, useRef, useState } from 'react'\n\ntype GetEntityConfigFn = {\n // Overload #1: collectionSlug only\n // @todo remove \"{} |\" in 4.0, which would be a breaking change\n (args: { collectionSlug: {} | CollectionSlug; globalSlug?: never }): ClientCollectionConfig\n\n // Overload #2: globalSlug only\n // @todo remove \"{} |\" in 4.0, which would be a breaking change\n (args: { collectionSlug?: never; globalSlug: {} | GlobalSlug }): ClientGlobalConfig\n\n // Overload #3: both/none (fall back to union | null)\n (args: {\n collectionSlug?: {} | CollectionSlug\n globalSlug?: {} | GlobalSlug\n }): ClientCollectionConfig | ClientGlobalConfig | null\n}\n\nexport type ClientConfigContext = {\n config: ClientConfig\n /**\n * Get a collection or global config by its slug. This is preferred over\n * using `config.collections.find` or `config.globals.find`, because\n * getEntityConfig uses a lookup map for O(1) lookups.\n */\n getEntityConfig: GetEntityConfigFn\n setConfig: (config: ClientConfig) => void\n}\n\nconst RootConfigContext = createContext<ClientConfigContext | undefined>(undefined)\n\nexport const ConfigProvider: React.FC<{\n readonly children: React.ReactNode\n readonly config: ClientConfig\n}> = ({ children, config: configFromProps }) => {\n const [config, setConfig] = useState<ClientConfig>(configFromProps)\n\n const isFirstRenderRef = useRef(true)\n\n // Need to update local config state if config from props changes, for HMR.\n // That way, config changes will be updated in the UI immediately without needing a refresh.\n useEffect(() => {\n if (isFirstRenderRef.current) {\n isFirstRenderRef.current = false\n return\n }\n\n setConfig(configFromProps)\n }, [configFromProps, setConfig])\n\n // Build lookup maps for collections and globals so we can do O(1) lookups by slug\n const { collectionsBySlug, globalsBySlug } = useMemo(() => {\n const collectionsBySlug: Record<string, ClientCollectionConfig> = {}\n const globalsBySlug: Record<string, ClientGlobalConfig> = {}\n\n for (const collection of config.collections) {\n collectionsBySlug[collection.slug] = collection\n }\n\n for (const global of config.globals) {\n globalsBySlug[global.slug] = global\n }\n\n return { collectionsBySlug, globalsBySlug }\n }, [config])\n\n const getEntityConfig = useCallback<GetEntityConfigFn>(\n (args) => {\n if ('collectionSlug' in args) {\n return collectionsBySlug[args.collectionSlug] ?? null\n }\n\n if ('globalSlug' in args) {\n return globalsBySlug[args.globalSlug] ?? null\n }\n\n return null as any\n },\n [collectionsBySlug, globalsBySlug],\n )\n\n const value = useMemo(\n () => ({ config, getEntityConfig, setConfig }),\n [config, getEntityConfig, setConfig],\n )\n\n return <RootConfigContext value={value}>{children}</RootConfigContext>\n}\n\nexport const useConfig = (): ClientConfigContext => use(RootConfigContext)\n\n/**\n * This provider shadows the `ConfigProvider` on the _page_ level, allowing us to\n * update the config when needed, e.g. after authentication.\n * The layout `ConfigProvider` is not updated on page navigation / authentication,\n * as the layout does not re-render in those cases.\n *\n * If the config here has the same reference as the config from the layout, we\n * simply reuse the context from the layout to avoid unnecessary re-renders.\n *\n * @experimental This component is experimental and may change or be removed in future releases. Use at your own risk.\n */\nexport const PageConfigProvider: React.FC<{\n readonly children: React.ReactNode\n readonly config: ClientConfig\n}> = ({ children, config: configFromProps }) => {\n const { config: rootConfig, setConfig: setRootConfig } = useConfig()\n\n /**\n * This `useEffect` is required in order for the _page_ to be able to refresh the client config,\n * which may have been cached on the _layout_ level, where the `ConfigProvider` is managed.\n * Since the layout does not re-render on page navigation / authentication, we need to manually\n * update the config, as the user may have been authenticated in the process, which affects the client config.\n */\n useEffect(() => {\n setRootConfig(configFromProps)\n }, [configFromProps, setRootConfig])\n\n // If this component receives a different config than what is in context from the layout, it is stale.\n // While stale, we instantiate a new context provider that provides the new config until the root context is updated.\n // Unfortunately, referential equality alone does not work bc the reference is lost during server/client serialization,\n // so we need to also compare the `unauthenticated` property.\n if (\n rootConfig !== configFromProps &&\n rootConfig.unauthenticated !== configFromProps.unauthenticated\n ) {\n return <ConfigProvider config={configFromProps}>{children}</ConfigProvider>\n }\n\n return children\n}\n"],"mappings":"AAAA,sDAAsD;AACtD;;AAAA,SAAAA,CAAA,IAAAC,EAAA;;AASA,OAAOC,KAAA,IAASC,aAAa,EAAEC,GAAG,EAAEC,WAAW,EAAEC,SAAS,EAAEC,OAAO,EAAEC,MAAM,EAAEC,QAAQ,QAAQ;AA6B7F,MAAMC,iBAAA,gBAAoBP,aAAA,CAA+CQ,SAAA;AAEzE,OAAO,MAAMC,cAAA,GAGRA,CAAC;EAAEC,QAAQ;EAAEC,MAAA,EAAQC;AAAe,CAAE;EACzC,MAAM,CAACD,MAAA,EAAQE,SAAA,CAAU,GAAGP,QAAA,CAAuBM,eAAA;EAEnD,MAAME,gBAAA,GAAmBT,MAAA,CAAO;EAEhC;EACA;EACAF,SAAA,CAAU;IACR,IAAIW,gBAAA,CAAiBC,OAAO,EAAE;MAC5BD,gBAAA,CAAiBC,OAAO,GAAG;MAC3B;IACF;IAEAF,SAAA,CAAUD,eAAA;EACZ,GAAG,CAACA,eAAA,EAAiBC,SAAA,CAAU;EAE/B;EACA,MAAM;IAAEG,iBAAiB,EAAjBA,mBAAiB;IAAEC,aAAa,EAAbA;EAAa,CAAE,GAAGb,OAAA,CAAQ;IACnD,MAAMY,iBAAA,GAA4D,CAAC;IACnE,MAAMC,aAAA,GAAoD,CAAC;IAE3D,KAAK,MAAMC,UAAA,IAAcP,MAAA,CAAOQ,WAAW,EAAE;MAC3CH,iBAAiB,CAACE,UAAA,CAAWE,IAAI,CAAC,GAAGF,UAAA;IACvC;IAEA,KAAK,MAAMG,MAAA,IAAUV,MAAA,CAAOW,OAAO,EAAE;MACnCL,aAAa,CAACI,MAAA,CAAOD,IAAI,CAAC,GAAGC,MAAA;IAC/B;IAEA,OAAO;MAAEL,iBAAA;MAAmBC;IAAc;EAC5C,GAAG,CAACN,MAAA,CAAO;EAEX,MAAMY,eAAA,G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