@fluentui/react-provider 9.4.6 → 9.5.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.json +22 -7
- package/CHANGELOG.md +15 -6
- package/dist/index.d.ts +20 -2
- package/lib/components/FluentProvider/FluentProvider.types.js.map +1 -1
- package/lib/components/FluentProvider/renderFluentProvider.js +10 -2
- package/lib/components/FluentProvider/renderFluentProvider.js.map +1 -1
- package/lib/components/FluentProvider/useFluentProvider.js +20 -5
- package/lib/components/FluentProvider/useFluentProvider.js.map +1 -1
- package/lib/components/FluentProvider/useFluentProviderThemeStyleTag.js +40 -16
- package/lib/components/FluentProvider/useFluentProviderThemeStyleTag.js.map +1 -1
- package/lib-commonjs/components/FluentProvider/renderFluentProvider.js +9 -1
- package/lib-commonjs/components/FluentProvider/renderFluentProvider.js.map +1 -1
- package/lib-commonjs/components/FluentProvider/useFluentProvider.js +17 -5
- package/lib-commonjs/components/FluentProvider/useFluentProvider.js.map +1 -1
- package/lib-commonjs/components/FluentProvider/useFluentProviderThemeStyleTag.js +43 -20
- package/lib-commonjs/components/FluentProvider/useFluentProviderThemeStyleTag.js.map +1 -1
- package/package.json +3 -3
package/CHANGELOG.json
CHANGED
@@ -2,22 +2,37 @@
|
|
2
2
|
"name": "@fluentui/react-provider",
|
3
3
|
"entries": [
|
4
4
|
{
|
5
|
-
"date": "
|
6
|
-
"tag": "@fluentui/react-provider_v9.
|
7
|
-
"version": "9.
|
5
|
+
"date": "Tue, 04 Apr 2023 18:42:19 GMT",
|
6
|
+
"tag": "@fluentui/react-provider_v9.5.1",
|
7
|
+
"version": "9.5.1",
|
8
8
|
"comments": {
|
9
9
|
"patch": [
|
10
10
|
{
|
11
11
|
"author": "beachball",
|
12
12
|
"package": "@fluentui/react-provider",
|
13
|
-
"comment": "Bump @fluentui/react-
|
14
|
-
"commit": "
|
13
|
+
"comment": "Bump @fluentui/react-tabster to v9.6.3",
|
14
|
+
"commit": "37a3a6eda1fd41086edd99a0b1560a8740f8c6c5"
|
15
15
|
},
|
16
16
|
{
|
17
17
|
"author": "beachball",
|
18
18
|
"package": "@fluentui/react-provider",
|
19
|
-
"comment": "Bump @fluentui/react-
|
20
|
-
"commit": "
|
19
|
+
"comment": "Bump @fluentui/react-utilities to v9.7.3",
|
20
|
+
"commit": "37a3a6eda1fd41086edd99a0b1560a8740f8c6c5"
|
21
|
+
}
|
22
|
+
]
|
23
|
+
}
|
24
|
+
},
|
25
|
+
{
|
26
|
+
"date": "Fri, 24 Mar 2023 10:15:27 GMT",
|
27
|
+
"tag": "@fluentui/react-provider_v9.5.0",
|
28
|
+
"version": "9.5.0",
|
29
|
+
"comments": {
|
30
|
+
"minor": [
|
31
|
+
{
|
32
|
+
"author": "lingfangao@hotmail.com",
|
33
|
+
"package": "@fluentui/react-provider",
|
34
|
+
"commit": "64d2ec1f40281eab9337df6d6065edef9ad0d312",
|
35
|
+
"comment": "feat: Render theme CSS variables in SSR style element"
|
21
36
|
}
|
22
37
|
]
|
23
38
|
}
|
package/CHANGELOG.md
CHANGED
@@ -1,18 +1,27 @@
|
|
1
1
|
# Change Log - @fluentui/react-provider
|
2
2
|
|
3
|
-
This log was last generated on
|
3
|
+
This log was last generated on Tue, 04 Apr 2023 18:42:19 GMT and should not be manually modified.
|
4
4
|
|
5
5
|
<!-- Start content -->
|
6
6
|
|
7
|
-
## [9.
|
7
|
+
## [9.5.1](https://github.com/microsoft/fluentui/tree/@fluentui/react-provider_v9.5.1)
|
8
8
|
|
9
|
-
|
10
|
-
[Compare changes](https://github.com/microsoft/fluentui/compare/@fluentui/react-provider_v9.
|
9
|
+
Tue, 04 Apr 2023 18:42:19 GMT
|
10
|
+
[Compare changes](https://github.com/microsoft/fluentui/compare/@fluentui/react-provider_v9.5.0..@fluentui/react-provider_v9.5.1)
|
11
11
|
|
12
12
|
### Patches
|
13
13
|
|
14
|
-
- Bump @fluentui/react-
|
15
|
-
- Bump @fluentui/react-
|
14
|
+
- Bump @fluentui/react-tabster to v9.6.3 ([PR #27430](https://github.com/microsoft/fluentui/pull/27430) by beachball)
|
15
|
+
- Bump @fluentui/react-utilities to v9.7.3 ([PR #27430](https://github.com/microsoft/fluentui/pull/27430) by beachball)
|
16
|
+
|
17
|
+
## [9.5.0](https://github.com/microsoft/fluentui/tree/@fluentui/react-provider_v9.5.0)
|
18
|
+
|
19
|
+
Fri, 24 Mar 2023 10:15:27 GMT
|
20
|
+
[Compare changes](https://github.com/microsoft/fluentui/compare/@fluentui/react-provider_v9.4.5..@fluentui/react-provider_v9.5.0)
|
21
|
+
|
22
|
+
### Minor changes
|
23
|
+
|
24
|
+
- feat: Render theme CSS variables in SSR style element ([PR #27277](https://github.com/microsoft/fluentui/pull/27277) by lingfangao@hotmail.com)
|
16
25
|
|
17
26
|
## [9.4.5](https://github.com/microsoft/fluentui/tree/@fluentui/react-provider_v9.4.5)
|
18
27
|
|
package/dist/index.d.ts
CHANGED
@@ -56,6 +56,19 @@ export declare type FluentProviderSlots = {
|
|
56
56
|
export declare type FluentProviderState = ComponentState<FluentProviderSlots> & Pick<FluentProviderProps, 'targetDocument'> & Required<Pick<FluentProviderProps, 'applyStylesToPortals' | 'customStyleHooks_unstable' | 'dir' | 'overrides_unstable'>> & {
|
57
57
|
theme: ThemeContextValue_unstable;
|
58
58
|
themeClassName: string;
|
59
|
+
/**
|
60
|
+
* Props used to render SSR theme variables style element
|
61
|
+
*/
|
62
|
+
serverStyleProps: {
|
63
|
+
/**
|
64
|
+
* CSS rule containing CSS variables
|
65
|
+
*/
|
66
|
+
cssRule: string;
|
67
|
+
/**
|
68
|
+
* Additional attributes applied to the style element
|
69
|
+
*/
|
70
|
+
attributes: Record<string, string>;
|
71
|
+
};
|
59
72
|
};
|
60
73
|
|
61
74
|
/**
|
@@ -81,9 +94,14 @@ export declare const useFluentProviderStyles_unstable: (state: FluentProviderSta
|
|
81
94
|
|
82
95
|
/**
|
83
96
|
* Writes a theme as css variables in a style tag on the provided targetDocument as a rule applied to a CSS class
|
84
|
-
*
|
97
|
+
* @internal
|
85
98
|
* @returns CSS class to apply the rule
|
86
99
|
*/
|
87
|
-
export declare const useFluentProviderThemeStyleTag: (options: Pick<FluentProviderState, 'theme' | 'targetDocument'>
|
100
|
+
export declare const useFluentProviderThemeStyleTag: (options: Pick<FluentProviderState, 'theme' | 'targetDocument'> & {
|
101
|
+
rendererAttributes: Record<string, string>;
|
102
|
+
}) => {
|
103
|
+
styleTagId: string;
|
104
|
+
rule: string;
|
105
|
+
};
|
88
106
|
|
89
107
|
export { }
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"names":[],"sources":["../../../src/components/FluentProvider/FluentProvider.types.ts"],"sourcesContent":["import type {\n OverridesContextValue_unstable as OverridesContextValue,\n ProviderContextValue_unstable as ProviderContextValue,\n TooltipVisibilityContextValue_unstable as TooltipVisibilityContextValue,\n ThemeClassNameContextValue_unstable as ThemeClassNameContextValue,\n ThemeContextValue_unstable as ThemeContextValue,\n CustomStyleHooksContextValue_unstable as CustomStyleHooksContextValue,\n} from '@fluentui/react-shared-contexts';\nimport type { PartialTheme } from '@fluentui/react-theme';\nimport type { ComponentProps, ComponentState, Slot } from '@fluentui/react-utilities';\n\nexport type FluentProviderSlots = {\n root: Slot<'div'>;\n};\n\n// exported for callers to avoid referencing react-shared-context\n// and applying Partial<> when passing custom style hooks.\nexport type FluentProviderCustomStyleHooks = Partial<CustomStyleHooksContextValue>;\n\nexport type FluentProviderProps = Omit<ComponentProps<FluentProviderSlots>, 'dir'> & {\n /**\n * Passes styles applied to a component down to portals if enabled.\n * @default true\n */\n applyStylesToPortals?: boolean;\n\n /** Sets the hooks for custom styling components. */\n // eslint-disable-next-line @typescript-eslint/naming-convention\n customStyleHooks_unstable?: FluentProviderCustomStyleHooks;\n\n /** Sets the direction of text & generated styles. */\n dir?: 'ltr' | 'rtl';\n\n /** Provides the document, can be undefined during SSR render. */\n targetDocument?: Document;\n\n /** Sets the theme used in a scope. */\n theme?: PartialTheme;\n\n // eslint-disable-next-line @typescript-eslint/naming-convention\n overrides_unstable?: OverridesContextValue;\n};\n\nexport type FluentProviderState = ComponentState<FluentProviderSlots> &\n Pick<FluentProviderProps, 'targetDocument'> &\n Required<\n Pick<FluentProviderProps, 'applyStylesToPortals' | 'customStyleHooks_unstable' | 'dir' | 'overrides_unstable'>\n > & {\n theme: ThemeContextValue;\n themeClassName: string;\n };\n\nexport type FluentProviderContextValues = Pick<\n FluentProviderState,\n 'customStyleHooks_unstable' | 'theme' | 'overrides_unstable'\n> & {\n provider: ProviderContextValue;\n themeClassName: ThemeClassNameContextValue;\n textDirection: 'ltr' | 'rtl';\n tooltip: TooltipVisibilityContextValue;\n};\n"],"mappings":"AAAA"}
|
1
|
+
{"version":3,"names":[],"sources":["../../../src/components/FluentProvider/FluentProvider.types.ts"],"sourcesContent":["import type {\n OverridesContextValue_unstable as OverridesContextValue,\n ProviderContextValue_unstable as ProviderContextValue,\n TooltipVisibilityContextValue_unstable as TooltipVisibilityContextValue,\n ThemeClassNameContextValue_unstable as ThemeClassNameContextValue,\n ThemeContextValue_unstable as ThemeContextValue,\n CustomStyleHooksContextValue_unstable as CustomStyleHooksContextValue,\n} from '@fluentui/react-shared-contexts';\nimport type { PartialTheme } from '@fluentui/react-theme';\nimport type { ComponentProps, ComponentState, Slot } from '@fluentui/react-utilities';\n\nexport type FluentProviderSlots = {\n root: Slot<'div'>;\n};\n\n// exported for callers to avoid referencing react-shared-context\n// and applying Partial<> when passing custom style hooks.\nexport type FluentProviderCustomStyleHooks = Partial<CustomStyleHooksContextValue>;\n\nexport type FluentProviderProps = Omit<ComponentProps<FluentProviderSlots>, 'dir'> & {\n /**\n * Passes styles applied to a component down to portals if enabled.\n * @default true\n */\n applyStylesToPortals?: boolean;\n\n /** Sets the hooks for custom styling components. */\n // eslint-disable-next-line @typescript-eslint/naming-convention\n customStyleHooks_unstable?: FluentProviderCustomStyleHooks;\n\n /** Sets the direction of text & generated styles. */\n dir?: 'ltr' | 'rtl';\n\n /** Provides the document, can be undefined during SSR render. */\n targetDocument?: Document;\n\n /** Sets the theme used in a scope. */\n theme?: PartialTheme;\n\n // eslint-disable-next-line @typescript-eslint/naming-convention\n overrides_unstable?: OverridesContextValue;\n};\n\nexport type FluentProviderState = ComponentState<FluentProviderSlots> &\n Pick<FluentProviderProps, 'targetDocument'> &\n Required<\n Pick<FluentProviderProps, 'applyStylesToPortals' | 'customStyleHooks_unstable' | 'dir' | 'overrides_unstable'>\n > & {\n theme: ThemeContextValue;\n themeClassName: string;\n /**\n * Props used to render SSR theme variables style element\n */\n serverStyleProps: {\n /**\n * CSS rule containing CSS variables\n */\n cssRule: string;\n /**\n * Additional attributes applied to the style element\n */\n attributes: Record<string, string>;\n };\n };\n\nexport type FluentProviderContextValues = Pick<\n FluentProviderState,\n 'customStyleHooks_unstable' | 'theme' | 'overrides_unstable'\n> & {\n provider: ProviderContextValue;\n themeClassName: ThemeClassNameContextValue;\n textDirection: 'ltr' | 'rtl';\n tooltip: TooltipVisibilityContextValue;\n};\n"],"mappings":"AAAA"}
|
@@ -1,7 +1,7 @@
|
|
1
1
|
import * as React from 'react';
|
2
2
|
import { TextDirectionProvider } from '@griffel/react';
|
3
3
|
import { OverridesProvider_unstable as OverridesProvider, Provider_unstable as Provider, TooltipVisibilityProvider_unstable as TooltipVisibilityProvider, ThemeProvider_unstable as ThemeProvider, ThemeClassNameProvider_unstable as ThemeClassNameProvider, CustomStyleHooksProvider_unstable as CustomStyleHooksProvider } from '@fluentui/react-shared-contexts';
|
4
|
-
import { getSlots } from '@fluentui/react-utilities';
|
4
|
+
import { canUseDOM, getSlots } from '@fluentui/react-utilities';
|
5
5
|
/**
|
6
6
|
* Render the final JSX of FluentProvider
|
7
7
|
*/
|
@@ -27,6 +27,14 @@ export const renderFluentProvider_unstable = (state, contextValues) => {
|
|
27
27
|
dir: contextValues.textDirection
|
28
28
|
}, /*#__PURE__*/React.createElement(OverridesProvider, {
|
29
29
|
value: contextValues.overrides_unstable
|
30
|
-
}, /*#__PURE__*/React.createElement(slots.root, slotProps.root,
|
30
|
+
}, /*#__PURE__*/React.createElement(slots.root, slotProps.root, canUseDOM() ? null : /*#__PURE__*/React.createElement("style", {
|
31
|
+
// Using dangerous HTML because react can escape characters
|
32
|
+
// which can lead to invalid CSS.
|
33
|
+
// eslint-disable-next-line react/no-danger
|
34
|
+
dangerouslySetInnerHTML: {
|
35
|
+
__html: state.serverStyleProps.cssRule
|
36
|
+
},
|
37
|
+
...state.serverStyleProps.attributes
|
38
|
+
}), slotProps.root.children))))))));
|
31
39
|
};
|
32
40
|
//# sourceMappingURL=renderFluentProvider.js.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"names":["React","TextDirectionProvider","OverridesProvider_unstable","OverridesProvider","Provider_unstable","Provider","TooltipVisibilityProvider_unstable","TooltipVisibilityProvider","ThemeProvider_unstable","ThemeProvider","ThemeClassNameProvider_unstable","ThemeClassNameProvider","CustomStyleHooksProvider_unstable","CustomStyleHooksProvider","getSlots","renderFluentProvider_unstable","state","contextValues","slots","slotProps","createElement","value","provider","theme","themeClassName","customStyleHooks_unstable","tooltip","dir","textDirection","overrides_unstable","root","children"],"sources":["../../../src/components/FluentProvider/renderFluentProvider.tsx"],"sourcesContent":["import * as React from 'react';\nimport { TextDirectionProvider } from '@griffel/react';\nimport {\n OverridesProvider_unstable as OverridesProvider,\n Provider_unstable as Provider,\n TooltipVisibilityProvider_unstable as TooltipVisibilityProvider,\n ThemeProvider_unstable as ThemeProvider,\n ThemeClassNameProvider_unstable as ThemeClassNameProvider,\n CustomStyleHooksProvider_unstable as CustomStyleHooksProvider,\n CustomStyleHooksContextValue_unstable as CustomStyleHooksContextValue,\n} from '@fluentui/react-shared-contexts';\nimport { getSlots } from '@fluentui/react-utilities';\nimport type {
|
1
|
+
{"version":3,"names":["React","TextDirectionProvider","OverridesProvider_unstable","OverridesProvider","Provider_unstable","Provider","TooltipVisibilityProvider_unstable","TooltipVisibilityProvider","ThemeProvider_unstable","ThemeProvider","ThemeClassNameProvider_unstable","ThemeClassNameProvider","CustomStyleHooksProvider_unstable","CustomStyleHooksProvider","canUseDOM","getSlots","renderFluentProvider_unstable","state","contextValues","slots","slotProps","createElement","value","provider","theme","themeClassName","customStyleHooks_unstable","tooltip","dir","textDirection","overrides_unstable","root","dangerouslySetInnerHTML","__html","serverStyleProps","cssRule","attributes","children"],"sources":["../../../src/components/FluentProvider/renderFluentProvider.tsx"],"sourcesContent":["import * as React from 'react';\nimport { TextDirectionProvider } from '@griffel/react';\nimport {\n OverridesProvider_unstable as OverridesProvider,\n Provider_unstable as Provider,\n TooltipVisibilityProvider_unstable as TooltipVisibilityProvider,\n ThemeProvider_unstable as ThemeProvider,\n ThemeClassNameProvider_unstable as ThemeClassNameProvider,\n CustomStyleHooksProvider_unstable as CustomStyleHooksProvider,\n CustomStyleHooksContextValue_unstable as CustomStyleHooksContextValue,\n} from '@fluentui/react-shared-contexts';\nimport { canUseDOM, getSlots } from '@fluentui/react-utilities';\nimport type { FluentProviderContextValues, FluentProviderState, FluentProviderSlots } from './FluentProvider.types';\n\n/**\n * Render the final JSX of FluentProvider\n */\nexport const renderFluentProvider_unstable = (\n state: FluentProviderState,\n contextValues: FluentProviderContextValues,\n) => {\n const { slots, slotProps } = getSlots<FluentProviderSlots>(state);\n\n // Typescript (vscode) incorrectly references the FluentProviderProps.customStyleHooks_unstable\n // instead of FluentProviderContextValues.customStyleHooks_unstable and thinks it is\n // Partial<CustomStyleHooksContextValue>, so it needs to be cast to Required<CustomStyleHooksContextValue>\n\n return (\n <Provider value={contextValues.provider}>\n <ThemeProvider value={contextValues.theme}>\n <ThemeClassNameProvider value={contextValues.themeClassName}>\n <CustomStyleHooksProvider\n value={contextValues.customStyleHooks_unstable as Required<CustomStyleHooksContextValue>}\n >\n <TooltipVisibilityProvider value={contextValues.tooltip}>\n <TextDirectionProvider dir={contextValues.textDirection}>\n <OverridesProvider value={contextValues.overrides_unstable}>\n <slots.root {...slotProps.root}>\n {canUseDOM() ? null : (\n <style\n // Using dangerous HTML because react can escape characters\n // which can lead to invalid CSS.\n // eslint-disable-next-line react/no-danger\n dangerouslySetInnerHTML={{ __html: state.serverStyleProps.cssRule }}\n {...state.serverStyleProps.attributes}\n />\n )}\n {slotProps.root.children}\n </slots.root>\n </OverridesProvider>\n </TextDirectionProvider>\n </TooltipVisibilityProvider>\n </CustomStyleHooksProvider>\n </ThemeClassNameProvider>\n </ThemeProvider>\n </Provider>\n );\n};\n"],"mappings":"AAAA,YAAYA,KAAA,MAAW;AACvB,SAASC,qBAAqB,QAAQ;AACtC,SACEC,0BAAA,IAA8BC,iBAAiB,EAC/CC,iBAAA,IAAqBC,QAAQ,EAC7BC,kCAAA,IAAsCC,yBAAyB,EAC/DC,sBAAA,IAA0BC,aAAa,EACvCC,+BAAA,IAAmCC,sBAAsB,EACzDC,iCAAA,IAAqCC,wBAAwB,QAExD;AACP,SAASC,SAAS,EAAEC,QAAQ,QAAQ;AAGpC;;;AAGA,OAAO,MAAMC,6BAAA,GAAgCA,CAC3CC,KAAA,EACAC,aAAA,KACG;EACH,MAAM;IAAEC,KAAA;IAAOC;EAAS,CAAE,GAAGL,QAAA,CAA8BE,KAAA;EAE3D;EACA;EACA;EAEA,oBACEjB,KAAA,CAAAqB,aAAA,CAAChB,QAAA;IAASiB,KAAA,EAAOJ,aAAA,CAAcK;kBAC7BvB,KAAA,CAAAqB,aAAA,CAACZ,aAAA;IAAca,KAAA,EAAOJ,aAAA,CAAcM;kBAClCxB,KAAA,CAAAqB,aAAA,CAACV,sBAAA;IAAuBW,KAAA,EAAOJ,aAAA,CAAcO;kBAC3CzB,KAAA,CAAAqB,aAAA,CAACR,wBAAA;IACCS,KAAA,EAAOJ,aAAA,CAAcQ;kBAErB1B,KAAA,CAAAqB,aAAA,CAACd,yBAAA;IAA0Be,KAAA,EAAOJ,aAAA,CAAcS;kBAC9C3B,KAAA,CAAAqB,aAAA,CAACpB,qBAAA;IAAsB2B,GAAA,EAAKV,aAAA,CAAcW;kBACxC7B,KAAA,CAAAqB,aAAA,CAAClB,iBAAA;IAAkBmB,KAAA,EAAOJ,aAAA,CAAcY;kBACtC9B,KAAA,CAAAqB,aAAA,CAACF,KAAA,CAAMY,IAAI,EAAKX,SAAA,CAAUW,IAAI,EAC3BjB,SAAA,KAAc,IAAI,gBACjBd,KAAA,CAAAqB,aAAA,CAAC;IACC;IACA;IACA;IACAW,uBAAA,EAAyB;MAAEC,MAAA,EAAQhB,KAAA,CAAMiB,gBAAgB,CAACC;IAAQ;IACjE,GAAGlB,KAAA,CAAMiB,gBAAgB,CAACE;IAE9B,EACAhB,SAAA,CAAUW,IAAI,CAACM,QAAQ;AAU5C"}
|
@@ -3,6 +3,7 @@ import { ThemeContext_unstable as ThemeContext, useFluent_unstable as useFluent,
|
|
3
3
|
import { getNativeElementProps, useMergedRefs } from '@fluentui/react-utilities';
|
4
4
|
import * as React from 'react';
|
5
5
|
import { useFluentProviderThemeStyleTag } from './useFluentProviderThemeStyleTag';
|
6
|
+
import { useRenderer_unstable } from '@griffel/react';
|
6
7
|
/**
|
7
8
|
* Create the state required to render FluentProvider.
|
8
9
|
*
|
@@ -46,6 +47,16 @@ export const useFluentProvider_unstable = (props, ref) => {
|
|
46
47
|
}
|
47
48
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
48
49
|
}, []);
|
50
|
+
const renderer = useRenderer_unstable();
|
51
|
+
var _renderer_styleElementAttributes;
|
52
|
+
const {
|
53
|
+
styleTagId,
|
54
|
+
rule
|
55
|
+
} = useFluentProviderThemeStyleTag({
|
56
|
+
theme: mergedTheme,
|
57
|
+
targetDocument,
|
58
|
+
rendererAttributes: (_renderer_styleElementAttributes = renderer.styleElementAttributes) !== null && _renderer_styleElementAttributes !== void 0 ? _renderer_styleElementAttributes : {}
|
59
|
+
});
|
49
60
|
return {
|
50
61
|
applyStylesToPortals,
|
51
62
|
// eslint-disable-next-line @typescript-eslint/naming-convention
|
@@ -55,10 +66,7 @@ export const useFluentProvider_unstable = (props, ref) => {
|
|
55
66
|
theme: mergedTheme,
|
56
67
|
// eslint-disable-next-line @typescript-eslint/naming-convention
|
57
68
|
overrides_unstable: mergedOverrides,
|
58
|
-
themeClassName:
|
59
|
-
theme: mergedTheme,
|
60
|
-
targetDocument
|
61
|
-
}),
|
69
|
+
themeClassName: styleTagId,
|
62
70
|
components: {
|
63
71
|
root: 'div'
|
64
72
|
},
|
@@ -68,7 +76,14 @@ export const useFluentProvider_unstable = (props, ref) => {
|
|
68
76
|
ref: useMergedRefs(ref, useFocusVisible({
|
69
77
|
targetDocument
|
70
78
|
}))
|
71
|
-
})
|
79
|
+
}),
|
80
|
+
serverStyleProps: {
|
81
|
+
cssRule: rule,
|
82
|
+
attributes: {
|
83
|
+
...renderer.styleElementAttributes,
|
84
|
+
id: styleTagId
|
85
|
+
}
|
86
|
+
}
|
72
87
|
};
|
73
88
|
};
|
74
89
|
function shallowMerge(a, b) {
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"names":["useFocusVisible","ThemeContext_unstable","ThemeContext","useFluent_unstable","useFluent","useOverrides_unstable","useOverrides","useCustomStyleHooks_unstable","useCustomStyleHooks","getNativeElementProps","useMergedRefs","React","useFluentProviderThemeStyleTag","useFluentProvider_unstable","props","ref","parentContext","parentTheme","useTheme","parentOverrides","parentCustomStyleHooks","applyStylesToPortals","customStyleHooks_unstable","dir","targetDocument","theme","overrides_unstable","overrides","mergedTheme","shallowMerge","mergedOverrides","mergedCustomStyleHooks","useEffect","process","env","NODE_ENV","undefined","console","warn","themeClassName","components","root","a","b","useContext"],"sources":["../../../src/components/FluentProvider/useFluentProvider.ts"],"sourcesContent":["import { useFocusVisible } from '@fluentui/react-tabster';\nimport {\n ThemeContext_unstable as ThemeContext,\n useFluent_unstable as useFluent,\n useOverrides_unstable as useOverrides,\n useCustomStyleHooks_unstable as useCustomStyleHooks,\n} from '@fluentui/react-shared-contexts';\nimport type {\n CustomStyleHooksContextValue_unstable as CustomStyleHooksContextValue,\n ThemeContextValue_unstable as ThemeContextValue,\n} from '@fluentui/react-shared-contexts';\n\nimport { getNativeElementProps, useMergedRefs } from '@fluentui/react-utilities';\nimport * as React from 'react';\nimport { useFluentProviderThemeStyleTag } from './useFluentProviderThemeStyleTag';\nimport type { FluentProviderProps, FluentProviderState } from './FluentProvider.types';\n\n/**\n * Create the state required to render FluentProvider.\n *\n * The returned state can be modified with hooks such as useFluentProviderStyles_unstable,\n * before being passed to renderFluentProvider_unstable.\n *\n * @param props - props from this instance of FluentProvider\n * @param ref - reference to root HTMLElement of FluentProvider\n */\nexport const useFluentProvider_unstable = (\n props: FluentProviderProps,\n ref: React.Ref<HTMLElement>,\n): FluentProviderState => {\n const parentContext = useFluent();\n const parentTheme = useTheme();\n const parentOverrides = useOverrides();\n const parentCustomStyleHooks = useCustomStyleHooks();\n\n /**\n * TODO: add merge functions to \"dir\" merge,\n * nesting providers with the same \"dir\" should not add additional attributes to DOM\n * see https://github.com/microsoft/fluentui/blob/0dc74a19f3aa5a058224c20505016fbdb84db172/packages/fluentui/react-northstar/src/utils/mergeProviderContexts.ts#L89-L93\n */\n const {\n applyStylesToPortals = true,\n // eslint-disable-next-line @typescript-eslint/naming-convention\n customStyleHooks_unstable,\n dir = parentContext.dir,\n targetDocument = parentContext.targetDocument,\n theme,\n overrides_unstable: overrides = {},\n } = props;\n const mergedTheme = shallowMerge(parentTheme, theme);\n\n const mergedOverrides = shallowMerge(parentOverrides, overrides);\n\n // parentCustomStyleHooks will not be a partial\n const mergedCustomStyleHooks = shallowMerge(\n parentCustomStyleHooks,\n customStyleHooks_unstable,\n ) as CustomStyleHooksContextValue;\n\n React.useEffect(() => {\n if (process.env.NODE_ENV !== 'production' && mergedTheme === undefined) {\n // eslint-disable-next-line no-console\n console.warn(`\n FluentProvider: your \"theme\" is not defined !\n =============================================\n Make sure your root FluentProvider has set a theme or you're setting the theme in your child FluentProvider.\n `);\n }\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, []);\n\n return {\n applyStylesToPortals,\n // eslint-disable-next-line @typescript-eslint/naming-convention\n customStyleHooks_unstable: mergedCustomStyleHooks,\n dir,\n targetDocument,\n theme: mergedTheme,\n // eslint-disable-next-line @typescript-eslint/naming-convention\n overrides_unstable: mergedOverrides,\n themeClassName:
|
1
|
+
{"version":3,"names":["useFocusVisible","ThemeContext_unstable","ThemeContext","useFluent_unstable","useFluent","useOverrides_unstable","useOverrides","useCustomStyleHooks_unstable","useCustomStyleHooks","getNativeElementProps","useMergedRefs","React","useFluentProviderThemeStyleTag","useRenderer_unstable","useFluentProvider_unstable","props","ref","parentContext","parentTheme","useTheme","parentOverrides","parentCustomStyleHooks","applyStylesToPortals","customStyleHooks_unstable","dir","targetDocument","theme","overrides_unstable","overrides","mergedTheme","shallowMerge","mergedOverrides","mergedCustomStyleHooks","useEffect","process","env","NODE_ENV","undefined","console","warn","renderer","_renderer_styleElementAttributes","styleTagId","rule","rendererAttributes","styleElementAttributes","themeClassName","components","root","serverStyleProps","cssRule","attributes","id","a","b","useContext"],"sources":["../../../src/components/FluentProvider/useFluentProvider.ts"],"sourcesContent":["import { useFocusVisible } from '@fluentui/react-tabster';\nimport {\n ThemeContext_unstable as ThemeContext,\n useFluent_unstable as useFluent,\n useOverrides_unstable as useOverrides,\n useCustomStyleHooks_unstable as useCustomStyleHooks,\n} from '@fluentui/react-shared-contexts';\nimport type {\n CustomStyleHooksContextValue_unstable as CustomStyleHooksContextValue,\n ThemeContextValue_unstable as ThemeContextValue,\n} from '@fluentui/react-shared-contexts';\n\nimport { getNativeElementProps, useMergedRefs } from '@fluentui/react-utilities';\nimport * as React from 'react';\nimport { useFluentProviderThemeStyleTag } from './useFluentProviderThemeStyleTag';\nimport type { FluentProviderProps, FluentProviderState } from './FluentProvider.types';\nimport { useRenderer_unstable } from '@griffel/react';\n\n/**\n * Create the state required to render FluentProvider.\n *\n * The returned state can be modified with hooks such as useFluentProviderStyles_unstable,\n * before being passed to renderFluentProvider_unstable.\n *\n * @param props - props from this instance of FluentProvider\n * @param ref - reference to root HTMLElement of FluentProvider\n */\nexport const useFluentProvider_unstable = (\n props: FluentProviderProps,\n ref: React.Ref<HTMLElement>,\n): FluentProviderState => {\n const parentContext = useFluent();\n const parentTheme = useTheme();\n const parentOverrides = useOverrides();\n const parentCustomStyleHooks = useCustomStyleHooks();\n\n /**\n * TODO: add merge functions to \"dir\" merge,\n * nesting providers with the same \"dir\" should not add additional attributes to DOM\n * see https://github.com/microsoft/fluentui/blob/0dc74a19f3aa5a058224c20505016fbdb84db172/packages/fluentui/react-northstar/src/utils/mergeProviderContexts.ts#L89-L93\n */\n const {\n applyStylesToPortals = true,\n // eslint-disable-next-line @typescript-eslint/naming-convention\n customStyleHooks_unstable,\n dir = parentContext.dir,\n targetDocument = parentContext.targetDocument,\n theme,\n overrides_unstable: overrides = {},\n } = props;\n const mergedTheme = shallowMerge(parentTheme, theme);\n\n const mergedOverrides = shallowMerge(parentOverrides, overrides);\n\n // parentCustomStyleHooks will not be a partial\n const mergedCustomStyleHooks = shallowMerge(\n parentCustomStyleHooks,\n customStyleHooks_unstable,\n ) as CustomStyleHooksContextValue;\n\n React.useEffect(() => {\n if (process.env.NODE_ENV !== 'production' && mergedTheme === undefined) {\n // eslint-disable-next-line no-console\n console.warn(`\n FluentProvider: your \"theme\" is not defined !\n =============================================\n Make sure your root FluentProvider has set a theme or you're setting the theme in your child FluentProvider.\n `);\n }\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, []);\n\n const renderer = useRenderer_unstable();\n const { styleTagId, rule } = useFluentProviderThemeStyleTag({\n theme: mergedTheme,\n targetDocument,\n rendererAttributes: renderer.styleElementAttributes ?? {},\n });\n return {\n applyStylesToPortals,\n // eslint-disable-next-line @typescript-eslint/naming-convention\n customStyleHooks_unstable: mergedCustomStyleHooks,\n dir,\n targetDocument,\n theme: mergedTheme,\n // eslint-disable-next-line @typescript-eslint/naming-convention\n overrides_unstable: mergedOverrides,\n themeClassName: styleTagId,\n\n components: {\n root: 'div',\n },\n\n root: getNativeElementProps('div', {\n ...props,\n dir,\n ref: useMergedRefs(ref, useFocusVisible<HTMLDivElement>({ targetDocument })),\n }),\n\n serverStyleProps: {\n cssRule: rule,\n attributes: {\n ...renderer.styleElementAttributes,\n id: styleTagId,\n },\n },\n };\n};\n\nfunction shallowMerge<T>(a: T, b: T): T {\n // Merge impacts perf: we should like to avoid it if it's possible\n if (a && b) {\n return { ...a, ...b };\n }\n\n if (a) {\n return a;\n }\n\n return b;\n}\n\nfunction useTheme(): ThemeContextValue {\n return React.useContext(ThemeContext);\n}\n"],"mappings":"AAAA,SAASA,eAAe,QAAQ;AAChC,SACEC,qBAAA,IAAyBC,YAAY,EACrCC,kBAAA,IAAsBC,SAAS,EAC/BC,qBAAA,IAAyBC,YAAY,EACrCC,4BAAA,IAAgCC,mBAAmB,QAC9C;AAMP,SAASC,qBAAqB,EAAEC,aAAa,QAAQ;AACrD,YAAYC,KAAA,MAAW;AACvB,SAASC,8BAA8B,QAAQ;AAE/C,SAASC,oBAAoB,QAAQ;AAErC;;;;;;;;;AASA,OAAO,MAAMC,0BAAA,GAA6BA,CACxCC,KAAA,EACAC,GAAA,KACwB;EACxB,MAAMC,aAAA,GAAgBb,SAAA;EACtB,MAAMc,WAAA,GAAcC,QAAA;EACpB,MAAMC,eAAA,GAAkBd,YAAA;EACxB,MAAMe,sBAAA,GAAyBb,mBAAA;EAE/B;;;;;EAKA,MAAM;IACJc,oBAAA,GAAuB,IAAI;IAC3B;IACAC,yBAAA;IACAC,GAAA,GAAMP,aAAA,CAAcO,GAAG;IACvBC,cAAA,GAAiBR,aAAA,CAAcQ,cAAc;IAC7CC,KAAA;IACAC,kBAAA,EAAoBC,SAAA,GAAY,CAAC;EAAC,CACnC,GAAGb,KAAA;EACJ,MAAMc,WAAA,GAAcC,YAAA,CAAaZ,WAAA,EAAaQ,KAAA;EAE9C,MAAMK,eAAA,GAAkBD,YAAA,CAAaV,eAAA,EAAiBQ,SAAA;EAEtD;EACA,MAAMI,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;EAEA,OAAOC,CAAA;AACT;AAEA,SAASnC,SAAA,EAA8B;EACrC,OAAOR,KAAA,CAAM4C,UAAU,CAACrD,YAAA;AAC1B"}
|
@@ -1,5 +1,4 @@
|
|
1
1
|
import { useId, useIsomorphicLayoutEffect } from '@fluentui/react-utilities';
|
2
|
-
import { useRenderer_unstable } from '@griffel/react';
|
3
2
|
import * as React from 'react';
|
4
3
|
import { fluentProviderClassNames } from './useFluentProviderStyles';
|
5
4
|
// String concatenation is used to prevent bundlers to complain with older versions of React
|
@@ -29,18 +28,18 @@ const insertSheet = (tag, rule) => {
|
|
29
28
|
};
|
30
29
|
/**
|
31
30
|
* Writes a theme as css variables in a style tag on the provided targetDocument as a rule applied to a CSS class
|
32
|
-
*
|
31
|
+
* @internal
|
33
32
|
* @returns CSS class to apply the rule
|
34
33
|
*/
|
35
34
|
export const useFluentProviderThemeStyleTag = options => {
|
36
35
|
const {
|
37
36
|
targetDocument,
|
38
|
-
theme
|
37
|
+
theme,
|
38
|
+
rendererAttributes
|
39
39
|
} = options;
|
40
|
-
const renderer = useRenderer_unstable();
|
41
40
|
const styleTag = React.useRef();
|
42
41
|
const styleTagId = useId(fluentProviderClassNames.root);
|
43
|
-
const styleElementAttributes =
|
42
|
+
const styleElementAttributes = rendererAttributes;
|
44
43
|
const cssVarsAsString = React.useMemo(() => {
|
45
44
|
return theme ? Object.keys(theme).reduce((cssVarRule, cssVar) => {
|
46
45
|
cssVarRule += `--${cssVar}: ${theme[cssVar]}; `;
|
@@ -48,19 +47,44 @@ export const useFluentProviderThemeStyleTag = options => {
|
|
48
47
|
}, '') : '';
|
49
48
|
}, [theme]);
|
50
49
|
const rule = `.${styleTagId} { ${cssVarsAsString} }`;
|
50
|
+
useHandleSSRStyleElements(targetDocument, styleTagId);
|
51
51
|
useInsertionEffect(() => {
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
52
|
+
// The style element could already have been created during SSR - no need to recreate it
|
53
|
+
const ssrStyleElement = targetDocument === null || targetDocument === void 0 ? void 0 : targetDocument.getElementById(styleTagId);
|
54
|
+
if (ssrStyleElement) {
|
55
|
+
styleTag.current = ssrStyleElement;
|
56
|
+
} else {
|
57
|
+
styleTag.current = createStyleTag(targetDocument, {
|
58
|
+
...styleElementAttributes,
|
59
|
+
id: styleTagId
|
60
|
+
});
|
61
|
+
if (styleTag.current) {
|
62
|
+
insertSheet(styleTag.current, rule);
|
63
|
+
}
|
62
64
|
}
|
65
|
+
return () => {
|
66
|
+
var _styleTag_current;
|
67
|
+
(_styleTag_current = styleTag.current) === null || _styleTag_current === void 0 ? void 0 : _styleTag_current.remove();
|
68
|
+
};
|
63
69
|
}, [styleTagId, targetDocument, rule, styleElementAttributes]);
|
64
|
-
return
|
70
|
+
return {
|
71
|
+
styleTagId,
|
72
|
+
rule
|
73
|
+
};
|
65
74
|
};
|
75
|
+
function useHandleSSRStyleElements(targetDocument, styleTagId) {
|
76
|
+
// Using a state factory so that this logic only runs once per render
|
77
|
+
// Each FluentProvider can create its own style element during SSR as a slot
|
78
|
+
// Moves all theme style elements to document head during render to avoid hydration errors.
|
79
|
+
// Should be strict mode safe since the logic is idempotent.
|
80
|
+
React.useState(() => {
|
81
|
+
if (!targetDocument) {
|
82
|
+
return;
|
83
|
+
}
|
84
|
+
const themeStyleElement = targetDocument.getElementById(styleTagId);
|
85
|
+
if (themeStyleElement) {
|
86
|
+
targetDocument.head.append(themeStyleElement);
|
87
|
+
}
|
88
|
+
});
|
89
|
+
}
|
66
90
|
//# sourceMappingURL=useFluentProviderThemeStyleTag.js.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"names":["useId","useIsomorphicLayoutEffect","
|
1
|
+
{"version":3,"names":["useId","useIsomorphicLayoutEffect","React","fluentProviderClassNames","useInsertionEffect","createStyleTag","target","elementAttributes","undefined","tag","createElement","Object","keys","forEach","attrName","setAttribute","head","appendChild","insertSheet","rule","sheet","cssRules","length","deleteRule","insertRule","process","env","NODE_ENV","console","error","useFluentProviderThemeStyleTag","options","targetDocument","theme","rendererAttributes","styleTag","useRef","styleTagId","root","styleElementAttributes","cssVarsAsString","useMemo","reduce","cssVarRule","cssVar","useHandleSSRStyleElements","ssrStyleElement","getElementById","current","id","_styleTag_current","remove","useState","themeStyleElement","append"],"sources":["../../../src/components/FluentProvider/useFluentProviderThemeStyleTag.ts"],"sourcesContent":["import { useId, useIsomorphicLayoutEffect } from '@fluentui/react-utilities';\nimport * as React from 'react';\n\nimport type { FluentProviderState } from './FluentProvider.types';\nimport { fluentProviderClassNames } from './useFluentProviderStyles';\n\n// String concatenation is used to prevent bundlers to complain with older versions of React\nconst useInsertionEffect = (React as never)['useInsertion' + 'Effect']\n ? (React as never)['useInsertion' + 'Effect']\n : useIsomorphicLayoutEffect;\n\nconst createStyleTag = (target: Document | undefined, elementAttributes: Record<string, string>) => {\n if (!target) {\n return undefined;\n }\n\n const tag = target.createElement('style');\n\n Object.keys(elementAttributes).forEach(attrName => {\n tag.setAttribute(attrName, elementAttributes[attrName]);\n });\n\n target.head.appendChild(tag);\n return tag;\n};\n\nconst insertSheet = (tag: HTMLStyleElement, rule: string) => {\n const sheet = tag.sheet;\n\n if (sheet) {\n if (sheet.cssRules.length > 0) {\n sheet.deleteRule(0);\n }\n sheet.insertRule(rule, 0);\n } else if (process.env.NODE_ENV !== 'production') {\n // eslint-disable-next-line no-console\n console.error('FluentProvider: No sheet available on styleTag, styles will not be inserted into DOM.');\n }\n};\n\n/**\n * Writes a theme as css variables in a style tag on the provided targetDocument as a rule applied to a CSS class\n * @internal\n * @returns CSS class to apply the rule\n */\nexport const useFluentProviderThemeStyleTag = (\n options: Pick<FluentProviderState, 'theme' | 'targetDocument'> & { rendererAttributes: Record<string, string> },\n) => {\n const { targetDocument, theme, rendererAttributes } = options;\n\n const styleTag = React.useRef<HTMLStyleElement | undefined | null>();\n\n const styleTagId = useId(fluentProviderClassNames.root);\n const styleElementAttributes = rendererAttributes;\n\n const cssVarsAsString = React.useMemo(() => {\n return theme\n ? (Object.keys(theme) as (keyof typeof theme)[]).reduce((cssVarRule, cssVar) => {\n cssVarRule += `--${cssVar}: ${theme[cssVar]}; `;\n return cssVarRule;\n }, '')\n : '';\n }, [theme]);\n\n const rule = `.${styleTagId} { ${cssVarsAsString} }`;\n\n useHandleSSRStyleElements(targetDocument, styleTagId);\n useInsertionEffect(() => {\n // The style element could already have been created during SSR - no need to recreate it\n const ssrStyleElement = targetDocument?.getElementById(styleTagId);\n if (ssrStyleElement) {\n styleTag.current = ssrStyleElement as HTMLStyleElement;\n } else {\n styleTag.current = createStyleTag(targetDocument, { ...styleElementAttributes, id: styleTagId });\n if (styleTag.current) {\n insertSheet(styleTag.current, rule);\n }\n }\n\n return () => {\n styleTag.current?.remove();\n };\n }, [styleTagId, targetDocument, rule, styleElementAttributes]);\n\n return { styleTagId, rule };\n};\n\nfunction useHandleSSRStyleElements(targetDocument: Document | undefined | null, styleTagId: string) {\n // Using a state factory so that this logic only runs once per render\n // Each FluentProvider can create its own style element during SSR as a slot\n // Moves all theme style elements to document head during render to avoid hydration errors.\n // Should be strict mode safe since the logic is idempotent.\n React.useState(() => {\n if (!targetDocument) {\n return;\n }\n\n const themeStyleElement = targetDocument.getElementById(styleTagId);\n if (themeStyleElement) {\n targetDocument.head.append(themeStyleElement);\n }\n });\n}\n"],"mappings":"AAAA,SAASA,KAAK,EAAEC,yBAAyB,QAAQ;AACjD,YAAYC,KAAA,MAAW;AAGvB,SAASC,wBAAwB,QAAQ;AAEzC;AACA,MAAMC,kBAAA,GAAqBF,KAAgB,CAAC,iBAAiB,SAAS,GAClEA,KAAgB,CAAC,iBAAiB,SAAS,GAC3CD,yBAAyB;AAE7B,MAAMI,cAAA,GAAiBA,CAACC,MAAA,EAA8BC,iBAAA,KAA8C;EAClG,IAAI,CAACD,MAAA,EAAQ;IACX,OAAOE,SAAA;EACT;EAEA,MAAMC,GAAA,GAAMH,MAAA,C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Md,IAAA,GAAQ,IAAGkB,UAAW,MAAKG,eAAgB,IAAG;EAEpDK,yBAAA,CAA0Bb,cAAA,EAAgBK,UAAA;EAC1CjC,kBAAA,CAAmB,MAAM;IACvB;IACA,MAAM0C,eAAA,GAAkBd,cAAA,aAAAA,cAAA,uBAAAA,cAAA,CAAgBe,cAAc,CAACV,UAAA;IACvD,IAAIS,eAAA,EAAiB;MACnBX,QAAA,CAASa,OAAO,GAAGF,eAAA;IACrB,OAAO;MACLX,QAAA,CAASa,OAAO,GAAG3C,cAAA,CAAe2B,cAAA,EAAgB;QAAE,GAAGO,sBAAsB;QAAEU,EAAA,EAAIZ;MAAW;MAC9F,IAAIF,QAAA,CAASa,OAAO,EAAE;QACpB9B,WAAA,CAAYiB,QAAA,CAASa,OAAO,EAAE7B,IAAA;MAChC;IACF;IAEA,OAAO,MAAM;UACX+B,iBAAA;MAAA,CAAAA,iBAAA,GAAAf,QAAA,CAASa,OAAO,cAAhBE,iBAAA,uBAAAA,iBAAA,CAAkBC,MAAA;IACpB;EACF,GAAG,CAACd,UAAA,EAAYL,cAAA,EAAgBb,IAAA,EAAMoB,sBAAA,CAAuB;EAE7D,OAAO;IAAEF,UAAA;IAAYlB;EAAK;AAC5B;AAEA,SAAS0B,0BAA0Bb,cAA2C,EAAEK,UAAkB,EAAE;EAClG;EACA;EACA;EACA;EACAnC,KAAA,CAAMkD,QAAQ,CAAC,MAAM;IACnB,IAAI,CAACpB,cAAA,EAAgB;MACnB;IACF;IAEA,MAAMqB,iBAAA,GAAoBrB,cAAA,CAAee,cAAc,CAACV,UAAA;IACxD,IAAIgB,iBAAA,EAAmB;MACrBrB,cAAA,CAAehB,IAAI,CAACsC,MAAM,CAACD,iBAAA;IAC7B;EACF;AACF"}
|
@@ -30,7 +30,15 @@ const renderFluentProvider_unstable = (state, contextValues)=>{
|
|
30
30
|
dir: contextValues.textDirection
|
31
31
|
}, /*#__PURE__*/ _react.createElement(_reactSharedContexts.OverridesProvider_unstable, {
|
32
32
|
value: contextValues.overrides_unstable
|
33
|
-
}, /*#__PURE__*/ _react.createElement(slots.root, slotProps.root,
|
33
|
+
}, /*#__PURE__*/ _react.createElement(slots.root, slotProps.root, (0, _reactUtilities.canUseDOM)() ? null : /*#__PURE__*/ _react.createElement("style", {
|
34
|
+
// Using dangerous HTML because react can escape characters
|
35
|
+
// which can lead to invalid CSS.
|
36
|
+
// eslint-disable-next-line react/no-danger
|
37
|
+
dangerouslySetInnerHTML: {
|
38
|
+
__html: state.serverStyleProps.cssRule
|
39
|
+
},
|
40
|
+
...state.serverStyleProps.attributes
|
41
|
+
}), slotProps.root.children))))))));
|
34
42
|
}; //# sourceMappingURL=renderFluentProvider.js.map
|
35
43
|
|
36
44
|
//# sourceMappingURL=renderFluentProvider.js.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"sources":["../../../lib/components/FluentProvider/renderFluentProvider.js"],"sourcesContent":["import * as React from 'react';\nimport { TextDirectionProvider } from '@griffel/react';\nimport { OverridesProvider_unstable as OverridesProvider, Provider_unstable as Provider, TooltipVisibilityProvider_unstable as TooltipVisibilityProvider, ThemeProvider_unstable as ThemeProvider, ThemeClassNameProvider_unstable as ThemeClassNameProvider, CustomStyleHooksProvider_unstable as CustomStyleHooksProvider } from '@fluentui/react-shared-contexts';\nimport { getSlots } from '@fluentui/react-utilities';\n/**\n * Render the final JSX of FluentProvider\n */\nexport const renderFluentProvider_unstable = (state, contextValues) => {\n const {\n slots,\n slotProps\n } = getSlots(state);\n // Typescript (vscode) incorrectly references the FluentProviderProps.customStyleHooks_unstable\n // instead of FluentProviderContextValues.customStyleHooks_unstable and thinks it is\n // Partial<CustomStyleHooksContextValue>, so it needs to be cast to Required<CustomStyleHooksContextValue>\n return /*#__PURE__*/React.createElement(Provider, {\n value: contextValues.provider\n }, /*#__PURE__*/React.createElement(ThemeProvider, {\n value: contextValues.theme\n }, /*#__PURE__*/React.createElement(ThemeClassNameProvider, {\n value: contextValues.themeClassName\n }, /*#__PURE__*/React.createElement(CustomStyleHooksProvider, {\n value: contextValues.customStyleHooks_unstable\n }, /*#__PURE__*/React.createElement(TooltipVisibilityProvider, {\n value: contextValues.tooltip\n }, /*#__PURE__*/React.createElement(TextDirectionProvider, {\n dir: contextValues.textDirection\n }, /*#__PURE__*/React.createElement(OverridesProvider, {\n value: contextValues.overrides_unstable\n }, /*#__PURE__*/React.createElement(slots.root, slotProps.root, state.root.children))))))));\n};\n//# sourceMappingURL=renderFluentProvider.js.map"],"names":["renderFluentProvider_unstable","state","contextValues","slots","slotProps","getSlots","React","createElement","Provider","value","provider","ThemeProvider","theme","ThemeClassNameProvider","themeClassName","CustomStyleHooksProvider","customStyleHooks_unstable","TooltipVisibilityProvider","tooltip","TextDirectionProvider","dir","textDirection","OverridesProvider","overrides_unstable","root","children"],"mappings":";;;;+BAOaA;;aAAAA;;;6DAPU;wBACe;qCAC6R;
|
1
|
+
{"version":3,"sources":["../../../lib/components/FluentProvider/renderFluentProvider.js"],"sourcesContent":["import * as React from 'react';\nimport { TextDirectionProvider } from '@griffel/react';\nimport { OverridesProvider_unstable as OverridesProvider, Provider_unstable as Provider, TooltipVisibilityProvider_unstable as TooltipVisibilityProvider, ThemeProvider_unstable as ThemeProvider, ThemeClassNameProvider_unstable as ThemeClassNameProvider, CustomStyleHooksProvider_unstable as CustomStyleHooksProvider } from '@fluentui/react-shared-contexts';\nimport { canUseDOM, getSlots } from '@fluentui/react-utilities';\n/**\n * Render the final JSX of FluentProvider\n */\nexport const renderFluentProvider_unstable = (state, contextValues) => {\n const {\n slots,\n slotProps\n } = getSlots(state);\n // Typescript (vscode) incorrectly references the FluentProviderProps.customStyleHooks_unstable\n // instead of FluentProviderContextValues.customStyleHooks_unstable and thinks it is\n // Partial<CustomStyleHooksContextValue>, so it needs to be cast to Required<CustomStyleHooksContextValue>\n return /*#__PURE__*/React.createElement(Provider, {\n value: contextValues.provider\n }, /*#__PURE__*/React.createElement(ThemeProvider, {\n value: contextValues.theme\n }, /*#__PURE__*/React.createElement(ThemeClassNameProvider, {\n value: contextValues.themeClassName\n }, /*#__PURE__*/React.createElement(CustomStyleHooksProvider, {\n value: contextValues.customStyleHooks_unstable\n }, /*#__PURE__*/React.createElement(TooltipVisibilityProvider, {\n value: contextValues.tooltip\n }, /*#__PURE__*/React.createElement(TextDirectionProvider, {\n dir: contextValues.textDirection\n }, /*#__PURE__*/React.createElement(OverridesProvider, {\n value: contextValues.overrides_unstable\n }, /*#__PURE__*/React.createElement(slots.root, slotProps.root, canUseDOM() ? null : /*#__PURE__*/React.createElement(\"style\", {\n // Using dangerous HTML because react can escape characters\n // which can lead to invalid CSS.\n // eslint-disable-next-line react/no-danger\n dangerouslySetInnerHTML: {\n __html: state.serverStyleProps.cssRule\n },\n ...state.serverStyleProps.attributes\n }), slotProps.root.children))))))));\n};\n//# sourceMappingURL=renderFluentProvider.js.map"],"names":["renderFluentProvider_unstable","state","contextValues","slots","slotProps","getSlots","React","createElement","Provider","value","provider","ThemeProvider","theme","ThemeClassNameProvider","themeClassName","CustomStyleHooksProvider","customStyleHooks_unstable","TooltipVisibilityProvider","tooltip","TextDirectionProvider","dir","textDirection","OverridesProvider","overrides_unstable","root","canUseDOM","dangerouslySetInnerHTML","__html","serverStyleProps","cssRule","attributes","children"],"mappings":";;;;+BAOaA;;aAAAA;;;6DAPU;wBACe;qCAC6R;gCAC/R;AAI7B,MAAMA,gCAAgC,CAACC,OAAOC,gBAAkB;IACrE,MAAM,EACJC,MAAK,EACLC,UAAS,EACV,GAAGC,IAAAA,wBAAQ,EAACJ;IACb,+FAA+F;IAC/F,oFAAoF;IACpF,0GAA0G;IAC1G,OAAO,WAAW,GAAEK,OAAMC,aAAa,CAACC,sCAAQ,EAAE;QAChDC,OAAOP,cAAcQ,QAAQ;IAC/B,GAAG,WAAW,GAAEJ,OAAMC,aAAa,CAACI,2CAAa,EAAE;QACjDF,OAAOP,cAAcU,KAAK;IAC5B,GAAG,WAAW,GAAEN,OAAMC,aAAa,CAACM,oDAAsB,EAAE;QAC1DJ,OAAOP,cAAcY,cAAc;IACrC,GAAG,WAAW,GAAER,OAAMC,aAAa,CAACQ,sDAAwB,EAAE;QAC5DN,OAAOP,cAAcc,yBAAyB;IAChD,GAAG,WAAW,GAAEV,OAAMC,aAAa,CAACU,uDAAyB,EAAE;QAC7DR,OAAOP,cAAcgB,OAAO;IAC9B,GAAG,WAAW,GAAEZ,OAAMC,aAAa,CAACY,6BAAqB,EAAE;QACzDC,KAAKlB,cAAcmB,aAAa;IAClC,GAAG,WAAW,GAAEf,OAAMC,aAAa,CAACe,+CAAiB,EAAE;QACrDb,OAAOP,cAAcqB,kBAAkB;IACzC,GAAG,WAAW,GAAEjB,OAAMC,aAAa,CAACJ,MAAMqB,IAAI,EAAEpB,UAAUoB,IAAI,EAAEC,IAAAA,yBAAS,MAAK,IAAI,GAAG,WAAW,GAAEnB,OAAMC,aAAa,CAAC,SAAS;QAC7H,2DAA2D;QAC3D,iCAAiC;QACjC,2CAA2C;QAC3CmB,yBAAyB;YACvBC,QAAQ1B,MAAM2B,gBAAgB,CAACC,OAAO;QACxC;QACA,GAAG5B,MAAM2B,gBAAgB,CAACE,UAAU;IACtC,EAAE,EAAE1B,UAAUoB,IAAI,CAACO,QAAQ;AAC7B,GACA,gDAAgD"}
|
@@ -12,6 +12,7 @@ const _reactSharedContexts = require("@fluentui/react-shared-contexts");
|
|
12
12
|
const _reactUtilities = require("@fluentui/react-utilities");
|
13
13
|
const _react = /*#__PURE__*/ _interopRequireWildcard(require("react"));
|
14
14
|
const _useFluentProviderThemeStyleTag = require("./useFluentProviderThemeStyleTag");
|
15
|
+
const _react1 = require("@griffel/react");
|
15
16
|
const useFluentProvider_unstable = (props, ref)=>{
|
16
17
|
const parentContext = (0, _reactSharedContexts.useFluent_unstable)();
|
17
18
|
const parentTheme = useTheme();
|
@@ -38,6 +39,13 @@ const useFluentProvider_unstable = (props, ref)=>{
|
|
38
39
|
}
|
39
40
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
40
41
|
}, []);
|
42
|
+
const renderer = (0, _react1.useRenderer_unstable)();
|
43
|
+
var _renderer_styleElementAttributes;
|
44
|
+
const { styleTagId , rule } = (0, _useFluentProviderThemeStyleTag.useFluentProviderThemeStyleTag)({
|
45
|
+
theme: mergedTheme,
|
46
|
+
targetDocument,
|
47
|
+
rendererAttributes: (_renderer_styleElementAttributes = renderer.styleElementAttributes) !== null && _renderer_styleElementAttributes !== void 0 ? _renderer_styleElementAttributes : {}
|
48
|
+
});
|
41
49
|
return {
|
42
50
|
applyStylesToPortals,
|
43
51
|
// eslint-disable-next-line @typescript-eslint/naming-convention
|
@@ -47,10 +55,7 @@ const useFluentProvider_unstable = (props, ref)=>{
|
|
47
55
|
theme: mergedTheme,
|
48
56
|
// eslint-disable-next-line @typescript-eslint/naming-convention
|
49
57
|
overrides_unstable: mergedOverrides,
|
50
|
-
themeClassName:
|
51
|
-
theme: mergedTheme,
|
52
|
-
targetDocument
|
53
|
-
}),
|
58
|
+
themeClassName: styleTagId,
|
54
59
|
components: {
|
55
60
|
root: 'div'
|
56
61
|
},
|
@@ -60,7 +65,14 @@ const useFluentProvider_unstable = (props, ref)=>{
|
|
60
65
|
ref: (0, _reactUtilities.useMergedRefs)(ref, (0, _reactTabster.useFocusVisible)({
|
61
66
|
targetDocument
|
62
67
|
}))
|
63
|
-
})
|
68
|
+
}),
|
69
|
+
serverStyleProps: {
|
70
|
+
cssRule: rule,
|
71
|
+
attributes: {
|
72
|
+
...renderer.styleElementAttributes,
|
73
|
+
id: styleTagId
|
74
|
+
}
|
75
|
+
}
|
64
76
|
};
|
65
77
|
};
|
66
78
|
function shallowMerge(a, b) {
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"sources":["../../../lib/components/FluentProvider/useFluentProvider.js"],"sourcesContent":["import { useFocusVisible } from '@fluentui/react-tabster';\nimport { ThemeContext_unstable as ThemeContext, useFluent_unstable as useFluent, useOverrides_unstable as useOverrides, useCustomStyleHooks_unstable as useCustomStyleHooks } from '@fluentui/react-shared-contexts';\nimport { getNativeElementProps, useMergedRefs } from '@fluentui/react-utilities';\nimport * as React from 'react';\nimport { useFluentProviderThemeStyleTag } from './useFluentProviderThemeStyleTag';\n/**\n * Create the state required to render FluentProvider.\n *\n * The returned state can be modified with hooks such as useFluentProviderStyles_unstable,\n * before being passed to renderFluentProvider_unstable.\n *\n * @param props - props from this instance of FluentProvider\n * @param ref - reference to root HTMLElement of FluentProvider\n */\nexport const useFluentProvider_unstable = (props, ref) => {\n const parentContext = useFluent();\n const parentTheme = useTheme();\n const parentOverrides = useOverrides();\n const parentCustomStyleHooks = useCustomStyleHooks();\n /**\n * TODO: add merge functions to \"dir\" merge,\n * nesting providers with the same \"dir\" should not add additional attributes to DOM\n * see https://github.com/microsoft/fluentui/blob/0dc74a19f3aa5a058224c20505016fbdb84db172/packages/fluentui/react-northstar/src/utils/mergeProviderContexts.ts#L89-L93\n */\n const {\n applyStylesToPortals = true,\n // eslint-disable-next-line @typescript-eslint/naming-convention\n customStyleHooks_unstable,\n dir = parentContext.dir,\n targetDocument = parentContext.targetDocument,\n theme,\n overrides_unstable: overrides = {}\n } = props;\n const mergedTheme = shallowMerge(parentTheme, theme);\n const mergedOverrides = shallowMerge(parentOverrides, overrides);\n // parentCustomStyleHooks will not be a partial\n const mergedCustomStyleHooks = shallowMerge(parentCustomStyleHooks, customStyleHooks_unstable);\n React.useEffect(() => {\n if (process.env.NODE_ENV !== 'production' && mergedTheme === undefined) {\n // eslint-disable-next-line no-console\n console.warn(`\n FluentProvider: your \"theme\" is not defined !\n =============================================\n Make sure your root FluentProvider has set a theme or you're setting the theme in your child FluentProvider.\n `);\n }\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, []);\n return {\n applyStylesToPortals,\n // eslint-disable-next-line @typescript-eslint/naming-convention\n customStyleHooks_unstable: mergedCustomStyleHooks,\n dir,\n targetDocument,\n theme: mergedTheme,\n // eslint-disable-next-line @typescript-eslint/naming-convention\n overrides_unstable: mergedOverrides,\n themeClassName:
|
1
|
+
{"version":3,"sources":["../../../lib/components/FluentProvider/useFluentProvider.js"],"sourcesContent":["import { useFocusVisible } from '@fluentui/react-tabster';\nimport { ThemeContext_unstable as ThemeContext, useFluent_unstable as useFluent, useOverrides_unstable as useOverrides, useCustomStyleHooks_unstable as useCustomStyleHooks } from '@fluentui/react-shared-contexts';\nimport { getNativeElementProps, useMergedRefs } from '@fluentui/react-utilities';\nimport * as React from 'react';\nimport { useFluentProviderThemeStyleTag } from './useFluentProviderThemeStyleTag';\nimport { useRenderer_unstable } from '@griffel/react';\n/**\n * Create the state required to render FluentProvider.\n *\n * The returned state can be modified with hooks such as useFluentProviderStyles_unstable,\n * before being passed to renderFluentProvider_unstable.\n *\n * @param props - props from this instance of FluentProvider\n * @param ref - reference to root HTMLElement of FluentProvider\n */\nexport const useFluentProvider_unstable = (props, ref) => {\n const parentContext = useFluent();\n const parentTheme = useTheme();\n const parentOverrides = useOverrides();\n const parentCustomStyleHooks = useCustomStyleHooks();\n /**\n * TODO: add merge functions to \"dir\" merge,\n * nesting providers with the same \"dir\" should not add additional attributes to DOM\n * see https://github.com/microsoft/fluentui/blob/0dc74a19f3aa5a058224c20505016fbdb84db172/packages/fluentui/react-northstar/src/utils/mergeProviderContexts.ts#L89-L93\n */\n const {\n applyStylesToPortals = true,\n // eslint-disable-next-line @typescript-eslint/naming-convention\n customStyleHooks_unstable,\n dir = parentContext.dir,\n targetDocument = parentContext.targetDocument,\n theme,\n overrides_unstable: overrides = {}\n } = props;\n const mergedTheme = shallowMerge(parentTheme, theme);\n const mergedOverrides = shallowMerge(parentOverrides, overrides);\n // parentCustomStyleHooks will not be a partial\n const mergedCustomStyleHooks = shallowMerge(parentCustomStyleHooks, customStyleHooks_unstable);\n React.useEffect(() => {\n if (process.env.NODE_ENV !== 'production' && mergedTheme === undefined) {\n // eslint-disable-next-line no-console\n console.warn(`\n FluentProvider: your \"theme\" is not defined !\n =============================================\n Make sure your root FluentProvider has set a theme or you're setting the theme in your child FluentProvider.\n `);\n }\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, []);\n const renderer = useRenderer_unstable();\n var _renderer_styleElementAttributes;\n const {\n styleTagId,\n rule\n } = useFluentProviderThemeStyleTag({\n theme: mergedTheme,\n targetDocument,\n rendererAttributes: (_renderer_styleElementAttributes = renderer.styleElementAttributes) !== null && _renderer_styleElementAttributes !== void 0 ? _renderer_styleElementAttributes : {}\n });\n return {\n applyStylesToPortals,\n // eslint-disable-next-line @typescript-eslint/naming-convention\n customStyleHooks_unstable: mergedCustomStyleHooks,\n dir,\n targetDocument,\n theme: mergedTheme,\n // eslint-disable-next-line @typescript-eslint/naming-convention\n overrides_unstable: mergedOverrides,\n themeClassName: styleTagId,\n components: {\n root: 'div'\n },\n root: getNativeElementProps('div', {\n ...props,\n dir,\n ref: useMergedRefs(ref, useFocusVisible({\n targetDocument\n }))\n }),\n serverStyleProps: {\n cssRule: rule,\n attributes: {\n ...renderer.styleElementAttributes,\n id: styleTagId\n }\n }\n };\n};\nfunction shallowMerge(a, b) {\n // Merge impacts perf: we should like to avoid it if it's possible\n if (a && b) {\n return {\n ...a,\n ...b\n };\n }\n if (a) {\n return a;\n }\n return b;\n}\nfunction useTheme() {\n return React.useContext(ThemeContext);\n}\n//# sourceMappingURL=useFluentProvider.js.map"],"names":["useFluentProvider_unstable","props","ref","parentContext","useFluent","parentTheme","useTheme","parentOverrides","useOverrides","parentCustomStyleHooks","useCustomStyleHooks","applyStylesToPortals","customStyleHooks_unstable","dir","targetDocument","theme","overrides_unstable","overrides","mergedTheme","shallowMerge","mergedOverrides","mergedCustomStyleHooks","React","useEffect","process","env","NODE_ENV","undefined","console","warn","renderer","useRenderer_unstable","_renderer_styleElementAttributes","styleTagId","rule","useFluentProviderThemeStyleTag","rendererAttributes","styleElementAttributes","themeClassName","components","root","getNativeElementProps","useMergedRefs","useFocusVisible","serverStyleProps","cssRule","attributes","id","a","b","useContext","ThemeContext"],"mappings":";;;;+BAeaA;;aAAAA;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,qCAAqB,EAAC,OAAO;YACjC,GAAGxC,KAAK;YACRY;YACAX,KAAKwC,IAAAA,6BAAa,EAACxC,KAAKyC,IAAAA,6BAAe,EAAC;gBACtC7B;YACF;QACF;QACA8B,kBAAkB;YAChBC,SAASX;YACTY,YAAY;gBACV,GAAGhB,SAASO,sBAAsB;gBAClCU,IAAId;YACN;QACF;IACF;AACF;AACA,SAASd,aAAa6B,CAAC,EAAEC,CAAC,EAAE;IAC1B,kEAAkE;IAClE,IAAID,KAAKC,GAAG;QACV,OAAO;YACL,GAAGD,CAAC;YACJ,GAAGC,CAAC;QACN;IACF,CAAC;IACD,IAAID,GAAG;QACL,OAAOA;IACT,CAAC;IACD,OAAOC;AACT;AACA,SAAS3C,WAAW;IAClB,OAAOgB,OAAM4B,UAAU,CAACC,0CAAY;AACtC,EACA,6CAA6C"}
|
@@ -8,11 +8,10 @@ Object.defineProperty(exports, "useFluentProviderThemeStyleTag", {
|
|
8
8
|
});
|
9
9
|
const _interopRequireWildcard = require("@swc/helpers/lib/_interop_require_wildcard.js").default;
|
10
10
|
const _reactUtilities = require("@fluentui/react-utilities");
|
11
|
-
const _react = require("
|
12
|
-
const _react1 = /*#__PURE__*/ _interopRequireWildcard(require("react"));
|
11
|
+
const _react = /*#__PURE__*/ _interopRequireWildcard(require("react"));
|
13
12
|
const _useFluentProviderStyles = require("./useFluentProviderStyles");
|
14
13
|
// String concatenation is used to prevent bundlers to complain with older versions of React
|
15
|
-
const useInsertionEffect =
|
14
|
+
const useInsertionEffect = _react['useInsertion' + 'Effect'] ? _react['useInsertion' + 'Effect'] : _reactUtilities.useIsomorphicLayoutEffect;
|
16
15
|
const createStyleTag = (target, elementAttributes)=>{
|
17
16
|
if (!target) {
|
18
17
|
return undefined;
|
@@ -37,12 +36,11 @@ const insertSheet = (tag, rule)=>{
|
|
37
36
|
}
|
38
37
|
};
|
39
38
|
const useFluentProviderThemeStyleTag = (options)=>{
|
40
|
-
const { targetDocument , theme } = options;
|
41
|
-
const
|
42
|
-
const styleTag = _react1.useRef();
|
39
|
+
const { targetDocument , theme , rendererAttributes } = options;
|
40
|
+
const styleTag = _react.useRef();
|
43
41
|
const styleTagId = (0, _reactUtilities.useId)(_useFluentProviderStyles.fluentProviderClassNames.root);
|
44
|
-
const styleElementAttributes =
|
45
|
-
const cssVarsAsString =
|
42
|
+
const styleElementAttributes = rendererAttributes;
|
43
|
+
const cssVarsAsString = _react.useMemo(()=>{
|
46
44
|
return theme ? Object.keys(theme).reduce((cssVarRule, cssVar)=>{
|
47
45
|
cssVarRule += `--${cssVar}: ${theme[cssVar]}; `;
|
48
46
|
return cssVarRule;
|
@@ -51,25 +49,50 @@ const useFluentProviderThemeStyleTag = (options)=>{
|
|
51
49
|
theme
|
52
50
|
]);
|
53
51
|
const rule = `.${styleTagId} { ${cssVarsAsString} }`;
|
52
|
+
useHandleSSRStyleElements(targetDocument, styleTagId);
|
54
53
|
useInsertionEffect(()=>{
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
54
|
+
// The style element could already have been created during SSR - no need to recreate it
|
55
|
+
const ssrStyleElement = targetDocument === null || targetDocument === void 0 ? void 0 : targetDocument.getElementById(styleTagId);
|
56
|
+
if (ssrStyleElement) {
|
57
|
+
styleTag.current = ssrStyleElement;
|
58
|
+
} else {
|
59
|
+
styleTag.current = createStyleTag(targetDocument, {
|
60
|
+
...styleElementAttributes,
|
61
|
+
id: styleTagId
|
62
|
+
});
|
63
|
+
if (styleTag.current) {
|
64
|
+
insertSheet(styleTag.current, rule);
|
65
|
+
}
|
65
66
|
}
|
67
|
+
return ()=>{
|
68
|
+
var _styleTag_current;
|
69
|
+
(_styleTag_current = styleTag.current) === null || _styleTag_current === void 0 ? void 0 : _styleTag_current.remove();
|
70
|
+
};
|
66
71
|
}, [
|
67
72
|
styleTagId,
|
68
73
|
targetDocument,
|
69
74
|
rule,
|
70
75
|
styleElementAttributes
|
71
76
|
]);
|
72
|
-
return
|
73
|
-
|
77
|
+
return {
|
78
|
+
styleTagId,
|
79
|
+
rule
|
80
|
+
};
|
81
|
+
};
|
82
|
+
function useHandleSSRStyleElements(targetDocument, styleTagId) {
|
83
|
+
// Using a state factory so that this logic only runs once per render
|
84
|
+
// Each FluentProvider can create its own style element during SSR as a slot
|
85
|
+
// Moves all theme style elements to document head during render to avoid hydration errors.
|
86
|
+
// Should be strict mode safe since the logic is idempotent.
|
87
|
+
_react.useState(()=>{
|
88
|
+
if (!targetDocument) {
|
89
|
+
return;
|
90
|
+
}
|
91
|
+
const themeStyleElement = targetDocument.getElementById(styleTagId);
|
92
|
+
if (themeStyleElement) {
|
93
|
+
targetDocument.head.append(themeStyleElement);
|
94
|
+
}
|
95
|
+
});
|
96
|
+
} //# sourceMappingURL=useFluentProviderThemeStyleTag.js.map
|
74
97
|
|
75
98
|
//# sourceMappingURL=useFluentProviderThemeStyleTag.js.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"sources":["../../../lib/components/FluentProvider/useFluentProviderThemeStyleTag.js"],"sourcesContent":["import { useId, useIsomorphicLayoutEffect } from '@fluentui/react-utilities';\nimport
|
1
|
+
{"version":3,"sources":["../../../lib/components/FluentProvider/useFluentProviderThemeStyleTag.js"],"sourcesContent":["import { useId, useIsomorphicLayoutEffect } from '@fluentui/react-utilities';\nimport * as React from 'react';\nimport { fluentProviderClassNames } from './useFluentProviderStyles';\n// String concatenation is used to prevent bundlers to complain with older versions of React\nconst useInsertionEffect = React['useInsertion' + 'Effect'] ? React['useInsertion' + 'Effect'] : useIsomorphicLayoutEffect;\nconst createStyleTag = (target, elementAttributes) => {\n if (!target) {\n return undefined;\n }\n const tag = target.createElement('style');\n Object.keys(elementAttributes).forEach(attrName => {\n tag.setAttribute(attrName, elementAttributes[attrName]);\n });\n target.head.appendChild(tag);\n return tag;\n};\nconst insertSheet = (tag, rule) => {\n const sheet = tag.sheet;\n if (sheet) {\n if (sheet.cssRules.length > 0) {\n sheet.deleteRule(0);\n }\n sheet.insertRule(rule, 0);\n } else if (process.env.NODE_ENV !== 'production') {\n // eslint-disable-next-line no-console\n console.error('FluentProvider: No sheet available on styleTag, styles will not be inserted into DOM.');\n }\n};\n/**\n * Writes a theme as css variables in a style tag on the provided targetDocument as a rule applied to a CSS class\n * @internal\n * @returns CSS class to apply the rule\n */\nexport const useFluentProviderThemeStyleTag = options => {\n const {\n targetDocument,\n theme,\n rendererAttributes\n } = options;\n const styleTag = React.useRef();\n const styleTagId = useId(fluentProviderClassNames.root);\n const styleElementAttributes = rendererAttributes;\n const cssVarsAsString = React.useMemo(() => {\n return theme ? Object.keys(theme).reduce((cssVarRule, cssVar) => {\n cssVarRule += `--${cssVar}: ${theme[cssVar]}; `;\n return cssVarRule;\n }, '') : '';\n }, [theme]);\n const rule = `.${styleTagId} { ${cssVarsAsString} }`;\n useHandleSSRStyleElements(targetDocument, styleTagId);\n useInsertionEffect(() => {\n // The style element could already have been created during SSR - no need to recreate it\n const ssrStyleElement = targetDocument === null || targetDocument === void 0 ? void 0 : targetDocument.getElementById(styleTagId);\n if (ssrStyleElement) {\n styleTag.current = ssrStyleElement;\n } else {\n styleTag.current = createStyleTag(targetDocument, {\n ...styleElementAttributes,\n id: styleTagId\n });\n if (styleTag.current) {\n insertSheet(styleTag.current, rule);\n }\n }\n return () => {\n var _styleTag_current;\n (_styleTag_current = styleTag.current) === null || _styleTag_current === void 0 ? void 0 : _styleTag_current.remove();\n };\n }, [styleTagId, targetDocument, rule, styleElementAttributes]);\n return {\n styleTagId,\n rule\n };\n};\nfunction useHandleSSRStyleElements(targetDocument, styleTagId) {\n // Using a state factory so that this logic only runs once per render\n // Each FluentProvider can create its own style element during SSR as a slot\n // Moves all theme style elements to document head during render to avoid hydration errors.\n // Should be strict mode safe since the logic is idempotent.\n React.useState(() => {\n if (!targetDocument) {\n return;\n }\n const themeStyleElement = targetDocument.getElementById(styleTagId);\n if (themeStyleElement) {\n targetDocument.head.append(themeStyleElement);\n }\n });\n}\n//# sourceMappingURL=useFluentProviderThemeStyleTag.js.map"],"names":["useFluentProviderThemeStyleTag","useInsertionEffect","React","useIsomorphicLayoutEffect","createStyleTag","target","elementAttributes","undefined","tag","createElement","Object","keys","forEach","attrName","setAttribute","head","appendChild","insertSheet","rule","sheet","cssRules","length","deleteRule","insertRule","process","env","NODE_ENV","console","error","options","targetDocument","theme","rendererAttributes","styleTag","useRef","styleTagId","useId","fluentProviderClassNames","root","styleElementAttributes","cssVarsAsString","useMemo","reduce","cssVarRule","cssVar","useHandleSSRStyleElements","ssrStyleElement","getElementById","current","id","_styleTag_current","remove","useState","themeStyleElement","append"],"mappings":";;;;+BAiCaA;;aAAAA;;;gCAjCoC;6DAC1B;yCACkB;AACzC,4FAA4F;AAC5F,MAAMC,qBAAqBC,MAAK,CAAC,iBAAiB,SAAS,GAAGA,MAAK,CAAC,iBAAiB,SAAS,GAAGC,yCAAyB;AAC1H,MAAMC,iBAAiB,CAACC,QAAQC,oBAAsB;IACpD,IAAI,CAACD,QAAQ;QACX,OAAOE;IACT,CAAC;IACD,MAAMC,MAAMH,OAAOI,aAAa,CAAC;IACjCC,OAAOC,IAAI,CAACL,mBAAmBM,OAAO,CAACC,CAAAA,WAAY;QACjDL,IAAIM,YAAY,CAACD,UAAUP,iBAAiB,CAACO,SAAS;IACxD;IACAR,OAAOU,IAAI,CAACC,WAAW,CAACR;IACxB,OAAOA;AACT;AACA,MAAMS,cAAc,CAACT,KAAKU,OAAS;IACjC,MAAMC,QAAQX,IAAIW,KAAK;IACvB,IAAIA,OAAO;QACT,IAAIA,MAAMC,QAAQ,CAACC,MAAM,GAAG,GAAG;YAC7BF,MAAMG,UAAU,CAAC;QACnB,CAAC;QACDH,MAAMI,UAAU,CAACL,MAAM;IACzB,OAAO,IAAIM,QAAQC,GAAG,CAACC,QAAQ,KAAK,cAAc;QAChD,sCAAsC;QACtCC,QAAQC,KAAK,CAAC;IAChB,CAAC;AACH;AAMO,MAAM5B,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AS2B,0BAA0Bf,cAAc,EAAEK,UAAU,EAAE;IAC7D,qEAAqE;IACrE,4EAA4E;IAC5E,2FAA2F;IAC3F,4DAA4D;IAC5DjC,OAAMkD,QAAQ,CAAC,IAAM;QACnB,IAAI,CAACtB,gBAAgB;YACnB;QACF,CAAC;QACD,MAAMuB,oBAAoBvB,eAAeiB,cAAc,CAACZ;QACxD,IAAIkB,mBAAmB;YACrBvB,eAAef,IAAI,CAACuC,MAAM,CAACD;QAC7B,CAAC;IACH;AACF,EACA,0DAA0D"}
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@fluentui/react-provider",
|
3
|
-
"version": "9.
|
3
|
+
"version": "9.5.1",
|
4
4
|
"description": "Fluent UI React provider component",
|
5
5
|
"main": "lib-commonjs/index.js",
|
6
6
|
"module": "lib/index.js",
|
@@ -35,9 +35,9 @@
|
|
35
35
|
"@griffel/core": "^1.9.0",
|
36
36
|
"@griffel/react": "^1.5.2",
|
37
37
|
"@fluentui/react-shared-contexts": "^9.3.3",
|
38
|
-
"@fluentui/react-tabster": "^9.6.
|
38
|
+
"@fluentui/react-tabster": "^9.6.3",
|
39
39
|
"@fluentui/react-theme": "^9.1.7",
|
40
|
-
"@fluentui/react-utilities": "^9.7.
|
40
|
+
"@fluentui/react-utilities": "^9.7.3",
|
41
41
|
"@swc/helpers": "^0.4.14"
|
42
42
|
},
|
43
43
|
"peerDependencies": {
|