@apvee/spfx-react-toolkit 1.0.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.
- package/LICENSE +21 -0
- package/README.md +2012 -0
- package/lib/core/atoms.internal.d.ts +53 -0
- package/lib/core/atoms.internal.d.ts.map +1 -0
- package/lib/core/atoms.internal.js +35 -0
- package/lib/core/atoms.internal.js.map +1 -0
- package/lib/core/context.internal.d.ts +23 -0
- package/lib/core/context.internal.d.ts.map +1 -0
- package/lib/core/context.internal.js +34 -0
- package/lib/core/context.internal.js.map +1 -0
- package/lib/core/index.d.ts +6 -0
- package/lib/core/index.d.ts.map +1 -0
- package/lib/core/index.js +6 -0
- package/lib/core/index.js.map +1 -0
- package/lib/core/provider-application-customizer.d.ts +57 -0
- package/lib/core/provider-application-customizer.d.ts.map +1 -0
- package/lib/core/provider-application-customizer.js +45 -0
- package/lib/core/provider-application-customizer.js.map +1 -0
- package/lib/core/provider-base.internal.d.ts +20 -0
- package/lib/core/provider-base.internal.d.ts.map +1 -0
- package/lib/core/provider-base.internal.js +126 -0
- package/lib/core/provider-base.internal.js.map +1 -0
- package/lib/core/provider-field-customizer.d.ts +58 -0
- package/lib/core/provider-field-customizer.d.ts.map +1 -0
- package/lib/core/provider-field-customizer.js +46 -0
- package/lib/core/provider-field-customizer.js.map +1 -0
- package/lib/core/provider-listview-commandset.d.ts +60 -0
- package/lib/core/provider-listview-commandset.d.ts.map +1 -0
- package/lib/core/provider-listview-commandset.js +48 -0
- package/lib/core/provider-listview-commandset.js.map +1 -0
- package/lib/core/provider-webpart.d.ts +48 -0
- package/lib/core/provider-webpart.d.ts.map +1 -0
- package/lib/core/provider-webpart.js +36 -0
- package/lib/core/provider-webpart.js.map +1 -0
- package/lib/core/types.d.ts +84 -0
- package/lib/core/types.d.ts.map +1 -0
- package/lib/core/types.js +4 -0
- package/lib/core/types.js.map +1 -0
- package/lib/hooks/index.d.ts +34 -0
- package/lib/hooks/index.d.ts.map +1 -0
- package/lib/hooks/index.js +34 -0
- package/lib/hooks/index.js.map +1 -0
- package/lib/hooks/useSPFxAadHttpClient.d.ts +231 -0
- package/lib/hooks/useSPFxAadHttpClient.d.ts.map +1 -0
- package/lib/hooks/useSPFxAadHttpClient.js +299 -0
- package/lib/hooks/useSPFxAadHttpClient.js.map +1 -0
- package/lib/hooks/useSPFxContainerInfo.d.ts +41 -0
- package/lib/hooks/useSPFxContainerInfo.d.ts.map +1 -0
- package/lib/hooks/useSPFxContainerInfo.js +47 -0
- package/lib/hooks/useSPFxContainerInfo.js.map +1 -0
- package/lib/hooks/useSPFxContainerSize.d.ts +119 -0
- package/lib/hooks/useSPFxContainerSize.d.ts.map +1 -0
- package/lib/hooks/useSPFxContainerSize.js +150 -0
- package/lib/hooks/useSPFxContainerSize.js.map +1 -0
- package/lib/hooks/useSPFxContext.d.ts +14 -0
- package/lib/hooks/useSPFxContext.d.ts.map +1 -0
- package/lib/hooks/useSPFxContext.js +16 -0
- package/lib/hooks/useSPFxContext.js.map +1 -0
- package/lib/hooks/useSPFxCorrelationInfo.d.ts +51 -0
- package/lib/hooks/useSPFxCorrelationInfo.d.ts.map +1 -0
- package/lib/hooks/useSPFxCorrelationInfo.js +58 -0
- package/lib/hooks/useSPFxCorrelationInfo.js.map +1 -0
- package/lib/hooks/useSPFxCrossSitePermissions.d.ts +81 -0
- package/lib/hooks/useSPFxCrossSitePermissions.d.ts.map +1 -0
- package/lib/hooks/useSPFxCrossSitePermissions.js +132 -0
- package/lib/hooks/useSPFxCrossSitePermissions.js.map +1 -0
- package/lib/hooks/useSPFxDisplayMode.d.ts +61 -0
- package/lib/hooks/useSPFxDisplayMode.d.ts.map +1 -0
- package/lib/hooks/useSPFxDisplayMode.js +69 -0
- package/lib/hooks/useSPFxDisplayMode.js.map +1 -0
- package/lib/hooks/useSPFxEnvironmentInfo.d.ts +63 -0
- package/lib/hooks/useSPFxEnvironmentInfo.d.ts.map +1 -0
- package/lib/hooks/useSPFxEnvironmentInfo.js +91 -0
- package/lib/hooks/useSPFxEnvironmentInfo.js.map +1 -0
- package/lib/hooks/useSPFxFluent9ThemeInfo.d.ts +105 -0
- package/lib/hooks/useSPFxFluent9ThemeInfo.d.ts.map +1 -0
- package/lib/hooks/useSPFxFluent9ThemeInfo.js +136 -0
- package/lib/hooks/useSPFxFluent9ThemeInfo.js.map +1 -0
- package/lib/hooks/useSPFxHubSiteInfo.d.ts +80 -0
- package/lib/hooks/useSPFxHubSiteInfo.d.ts.map +1 -0
- package/lib/hooks/useSPFxHubSiteInfo.js +127 -0
- package/lib/hooks/useSPFxHubSiteInfo.js.map +1 -0
- package/lib/hooks/useSPFxInstanceInfo.d.ts +41 -0
- package/lib/hooks/useSPFxInstanceInfo.d.ts.map +1 -0
- package/lib/hooks/useSPFxInstanceInfo.js +40 -0
- package/lib/hooks/useSPFxInstanceInfo.js.map +1 -0
- package/lib/hooks/useSPFxListInfo.d.ts +64 -0
- package/lib/hooks/useSPFxListInfo.d.ts.map +1 -0
- package/lib/hooks/useSPFxListInfo.js +70 -0
- package/lib/hooks/useSPFxListInfo.js.map +1 -0
- package/lib/hooks/useSPFxLocaleInfo.d.ts +123 -0
- package/lib/hooks/useSPFxLocaleInfo.d.ts.map +1 -0
- package/lib/hooks/useSPFxLocaleInfo.js +109 -0
- package/lib/hooks/useSPFxLocaleInfo.js.map +1 -0
- package/lib/hooks/useSPFxLogger.d.ts +108 -0
- package/lib/hooks/useSPFxLogger.d.ts.map +1 -0
- package/lib/hooks/useSPFxLogger.js +117 -0
- package/lib/hooks/useSPFxLogger.js.map +1 -0
- package/lib/hooks/useSPFxMSGraphClient.d.ts +200 -0
- package/lib/hooks/useSPFxMSGraphClient.d.ts.map +1 -0
- package/lib/hooks/useSPFxMSGraphClient.js +264 -0
- package/lib/hooks/useSPFxMSGraphClient.js.map +1 -0
- package/lib/hooks/useSPFxOneDriveAppData.d.ts +264 -0
- package/lib/hooks/useSPFxOneDriveAppData.d.ts.map +1 -0
- package/lib/hooks/useSPFxOneDriveAppData.js +395 -0
- package/lib/hooks/useSPFxOneDriveAppData.js.map +1 -0
- package/lib/hooks/useSPFxPageContext.d.ts +37 -0
- package/lib/hooks/useSPFxPageContext.d.ts.map +1 -0
- package/lib/hooks/useSPFxPageContext.js +49 -0
- package/lib/hooks/useSPFxPageContext.js.map +1 -0
- package/lib/hooks/useSPFxPageType.d.ts +82 -0
- package/lib/hooks/useSPFxPageType.d.ts.map +1 -0
- package/lib/hooks/useSPFxPageType.js +137 -0
- package/lib/hooks/useSPFxPageType.js.map +1 -0
- package/lib/hooks/useSPFxPerformance.d.ts +72 -0
- package/lib/hooks/useSPFxPerformance.d.ts.map +1 -0
- package/lib/hooks/useSPFxPerformance.js +167 -0
- package/lib/hooks/useSPFxPerformance.js.map +1 -0
- package/lib/hooks/useSPFxPermissions.d.ts +61 -0
- package/lib/hooks/useSPFxPermissions.d.ts.map +1 -0
- package/lib/hooks/useSPFxPermissions.js +73 -0
- package/lib/hooks/useSPFxPermissions.js.map +1 -0
- package/lib/hooks/useSPFxPnP.d.ts +539 -0
- package/lib/hooks/useSPFxPnP.d.ts.map +1 -0
- package/lib/hooks/useSPFxPnP.js +533 -0
- package/lib/hooks/useSPFxPnP.js.map +1 -0
- package/lib/hooks/useSPFxPnPContext.d.ts +290 -0
- package/lib/hooks/useSPFxPnPContext.d.ts.map +1 -0
- package/lib/hooks/useSPFxPnPContext.js +340 -0
- package/lib/hooks/useSPFxPnPContext.js.map +1 -0
- package/lib/hooks/useSPFxPnPList.d.ts +545 -0
- package/lib/hooks/useSPFxPnPList.d.ts.map +1 -0
- package/lib/hooks/useSPFxPnPList.js +906 -0
- package/lib/hooks/useSPFxPnPList.js.map +1 -0
- package/lib/hooks/useSPFxPnPSearch.d.ts +540 -0
- package/lib/hooks/useSPFxPnPSearch.d.ts.map +1 -0
- package/lib/hooks/useSPFxPnPSearch.js +672 -0
- package/lib/hooks/useSPFxPnPSearch.js.map +1 -0
- package/lib/hooks/useSPFxProperties.d.ts +80 -0
- package/lib/hooks/useSPFxProperties.d.ts.map +1 -0
- package/lib/hooks/useSPFxProperties.js +95 -0
- package/lib/hooks/useSPFxProperties.js.map +1 -0
- package/lib/hooks/useSPFxSPHttpClient.d.ts +218 -0
- package/lib/hooks/useSPFxSPHttpClient.d.ts.map +1 -0
- package/lib/hooks/useSPFxSPHttpClient.js +287 -0
- package/lib/hooks/useSPFxSPHttpClient.js.map +1 -0
- package/lib/hooks/useSPFxServiceScope.d.ts +107 -0
- package/lib/hooks/useSPFxServiceScope.d.ts.map +1 -0
- package/lib/hooks/useSPFxServiceScope.js +105 -0
- package/lib/hooks/useSPFxServiceScope.js.map +1 -0
- package/lib/hooks/useSPFxSiteInfo.d.ts +116 -0
- package/lib/hooks/useSPFxSiteInfo.d.ts.map +1 -0
- package/lib/hooks/useSPFxSiteInfo.js +109 -0
- package/lib/hooks/useSPFxSiteInfo.js.map +1 -0
- package/lib/hooks/useSPFxStorage.d.ts +81 -0
- package/lib/hooks/useSPFxStorage.d.ts.map +1 -0
- package/lib/hooks/useSPFxStorage.js +140 -0
- package/lib/hooks/useSPFxStorage.js.map +1 -0
- package/lib/hooks/useSPFxTeams.d.ts +63 -0
- package/lib/hooks/useSPFxTeams.d.ts.map +1 -0
- package/lib/hooks/useSPFxTeams.js +198 -0
- package/lib/hooks/useSPFxTeams.js.map +1 -0
- package/lib/hooks/useSPFxTenantProperty.d.ts +389 -0
- package/lib/hooks/useSPFxTenantProperty.d.ts.map +1 -0
- package/lib/hooks/useSPFxTenantProperty.js +683 -0
- package/lib/hooks/useSPFxTenantProperty.js.map +1 -0
- package/lib/hooks/useSPFxThemeInfo.d.ts +27 -0
- package/lib/hooks/useSPFxThemeInfo.d.ts.map +1 -0
- package/lib/hooks/useSPFxThemeInfo.js +33 -0
- package/lib/hooks/useSPFxThemeInfo.js.map +1 -0
- package/lib/hooks/useSPFxUserInfo.d.ts +47 -0
- package/lib/hooks/useSPFxUserInfo.d.ts.map +1 -0
- package/lib/hooks/useSPFxUserInfo.js +47 -0
- package/lib/hooks/useSPFxUserInfo.js.map +1 -0
- package/lib/hooks/useSPFxUserPhoto.d.ts +270 -0
- package/lib/hooks/useSPFxUserPhoto.d.ts.map +1 -0
- package/lib/hooks/useSPFxUserPhoto.js +346 -0
- package/lib/hooks/useSPFxUserPhoto.js.map +1 -0
- package/lib/index.d.ts +3 -0
- package/lib/index.d.ts.map +1 -0
- package/lib/index.js +3 -0
- package/lib/index.js.map +1 -0
- package/lib/utils/index.d.ts +1 -0
- package/lib/utils/index.d.ts.map +1 -0
- package/lib/utils/index.js +3 -0
- package/lib/utils/index.js.map +1 -0
- package/lib/utils/resize-observer.internal.d.ts +10 -0
- package/lib/utils/resize-observer.internal.d.ts.map +1 -0
- package/lib/utils/resize-observer.internal.js +34 -0
- package/lib/utils/resize-observer.internal.js.map +1 -0
- package/lib/utils/theme-subscription.internal.d.ts +11 -0
- package/lib/utils/theme-subscription.internal.d.ts.map +1 -0
- package/lib/utils/theme-subscription.internal.js +58 -0
- package/lib/utils/theme-subscription.internal.js.map +1 -0
- package/lib/utils/type-guards.internal.d.ts +35 -0
- package/lib/utils/type-guards.internal.d.ts.map +1 -0
- package/lib/utils/type-guards.internal.js +88 -0
- package/lib/utils/type-guards.internal.js.map +1 -0
- package/lib/webparts/spFxReactToolkitTest/SpFxReactToolkitTestWebPart.d.ts +13 -0
- package/lib/webparts/spFxReactToolkitTest/SpFxReactToolkitTestWebPart.d.ts.map +1 -0
- package/lib/webparts/spFxReactToolkitTest/SpFxReactToolkitTestWebPart.js +67 -0
- package/lib/webparts/spFxReactToolkitTest/SpFxReactToolkitTestWebPart.js.map +1 -0
- package/lib/webparts/spFxReactToolkitTest/SpFxReactToolkitTestWebPart.manifest.json +21 -0
- package/lib/webparts/spFxReactToolkitTest/assets/welcome-dark.png +0 -0
- package/lib/webparts/spFxReactToolkitTest/assets/welcome-light.png +0 -0
- package/lib/webparts/spFxReactToolkitTest/components/ISpFxReactToolkitTestProps.d.ts +8 -0
- package/lib/webparts/spFxReactToolkitTest/components/ISpFxReactToolkitTestProps.d.ts.map +1 -0
- package/lib/webparts/spFxReactToolkitTest/components/ISpFxReactToolkitTestProps.js +2 -0
- package/lib/webparts/spFxReactToolkitTest/components/ISpFxReactToolkitTestProps.js.map +1 -0
- package/lib/webparts/spFxReactToolkitTest/components/SpFxReactToolkitTest.d.ts +8 -0
- package/lib/webparts/spFxReactToolkitTest/components/SpFxReactToolkitTest.d.ts.map +1 -0
- package/lib/webparts/spFxReactToolkitTest/components/SpFxReactToolkitTest.js +1351 -0
- package/lib/webparts/spFxReactToolkitTest/components/SpFxReactToolkitTest.js.map +1 -0
- package/lib/webparts/spFxReactToolkitTest/components/SpFxReactToolkitTest.module.css +2 -0
- package/lib/webparts/spFxReactToolkitTest/components/SpFxReactToolkitTest.module.scss.d.ts +18 -0
- package/lib/webparts/spFxReactToolkitTest/components/SpFxReactToolkitTest.module.scss.d.ts.map +1 -0
- package/lib/webparts/spFxReactToolkitTest/components/SpFxReactToolkitTest.module.scss.js +19 -0
- package/lib/webparts/spFxReactToolkitTest/components/SpFxReactToolkitTest.module.scss.js.map +1 -0
- package/lib/webparts/spFxReactToolkitTest/loc/en-us.js +16 -0
- package/package.json +95 -0
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
// useSPFxSiteInfo.ts
|
|
2
|
+
// Hook to access site collection and web information
|
|
3
|
+
import { useSPFxPageContext } from './useSPFxPageContext';
|
|
4
|
+
/**
|
|
5
|
+
* Hook to access site collection and web information
|
|
6
|
+
*
|
|
7
|
+
* Provides comprehensive information about the current SharePoint web (site/subsite)
|
|
8
|
+
* and parent site collection in a unified, flat structure.
|
|
9
|
+
*
|
|
10
|
+
* **Property naming pattern**:
|
|
11
|
+
* - **Identity properties** (id, url, serverRelativeUrl): Prefixed with `web` or `site` for clarity
|
|
12
|
+
* - **Web metadata** (title, languageId, logoUrl): No prefix (unique to web, most commonly used)
|
|
13
|
+
* - **Site properties**: All prefixed with `site` for consistency
|
|
14
|
+
*
|
|
15
|
+
* **Web properties** (primary context - 90% use case):
|
|
16
|
+
* - webId, webUrl, webServerRelativeUrl: Web identity
|
|
17
|
+
* - title: Web display name (most commonly used)
|
|
18
|
+
* - languageId: Web language (LCID)
|
|
19
|
+
* - logoUrl: Site logo URL (for branding)
|
|
20
|
+
*
|
|
21
|
+
* **Site collection properties** (parent context - 30-40% specialized):
|
|
22
|
+
* - siteId, siteUrl, siteServerRelativeUrl: Site collection identity
|
|
23
|
+
* - siteClassification: Enterprise classification label (e.g., "Confidential", "Public")
|
|
24
|
+
* - siteGroup: Microsoft 365 Group information (if group-connected)
|
|
25
|
+
*
|
|
26
|
+
* Note: In most cases (90%), you'll use web properties. Site collection properties
|
|
27
|
+
* are for specialized scenarios like subsites navigation, classification displays,
|
|
28
|
+
* or Microsoft 365 Group detection.
|
|
29
|
+
*
|
|
30
|
+
* @returns Site collection and web information
|
|
31
|
+
*
|
|
32
|
+
* @example
|
|
33
|
+
* ```tsx
|
|
34
|
+
* function MyComponent() {
|
|
35
|
+
* const {
|
|
36
|
+
* webUrl, // Web URL (identity)
|
|
37
|
+
* title, // Web title (most common)
|
|
38
|
+
* languageId, // Web language
|
|
39
|
+
* logoUrl, // Site logo (branding)
|
|
40
|
+
* siteClassification, // Site classification (enterprise)
|
|
41
|
+
* siteGroup // M365 Group info (if group-connected)
|
|
42
|
+
* } = useSPFxSiteInfo();
|
|
43
|
+
*
|
|
44
|
+
* return (
|
|
45
|
+
* <header>
|
|
46
|
+
* {logoUrl && <img src={logoUrl} alt="Site logo" />}
|
|
47
|
+
* <h1>{title}</h1>
|
|
48
|
+
* <a href={webUrl}>Visit Site</a>
|
|
49
|
+
*
|
|
50
|
+
* {siteClassification && (
|
|
51
|
+
* <Label>Classification: {siteClassification}</Label>
|
|
52
|
+
* )}
|
|
53
|
+
*
|
|
54
|
+
* {siteGroup && (
|
|
55
|
+
* <Badge>
|
|
56
|
+
* {siteGroup.isPublic ? 'Public Team' : 'Private Team'}
|
|
57
|
+
* </Badge>
|
|
58
|
+
* )}
|
|
59
|
+
*
|
|
60
|
+
* <p>Language ID: {languageId}</p>
|
|
61
|
+
* </header>
|
|
62
|
+
* );
|
|
63
|
+
* }
|
|
64
|
+
* ```
|
|
65
|
+
*
|
|
66
|
+
* @example
|
|
67
|
+
* ```tsx
|
|
68
|
+
* // Cross-site navigation (subsite scenario)
|
|
69
|
+
* function Navigation() {
|
|
70
|
+
* const { webUrl, siteUrl, title } = useSPFxSiteInfo();
|
|
71
|
+
*
|
|
72
|
+
* return (
|
|
73
|
+
* <nav>
|
|
74
|
+
* <a href={siteUrl}>Site Collection Home</a>
|
|
75
|
+
* <span> / </span>
|
|
76
|
+
* <a href={webUrl}>{title}</a>
|
|
77
|
+
* </nav>
|
|
78
|
+
* );
|
|
79
|
+
* }
|
|
80
|
+
* ```
|
|
81
|
+
*/
|
|
82
|
+
export function useSPFxSiteInfo() {
|
|
83
|
+
var _a, _b;
|
|
84
|
+
var pageContext = useSPFxPageContext();
|
|
85
|
+
var siteObj = pageContext.site;
|
|
86
|
+
var webObj = pageContext.web;
|
|
87
|
+
// Try to get additional properties from legacy context
|
|
88
|
+
var legacy = pageContext.legacyPageContext;
|
|
89
|
+
return {
|
|
90
|
+
// Web identity (prefixed)
|
|
91
|
+
webId: webObj.id.toString(),
|
|
92
|
+
webUrl: webObj.absoluteUrl,
|
|
93
|
+
webServerRelativeUrl: webObj.serverRelativeUrl,
|
|
94
|
+
// Web metadata (no prefix - unique, most common)
|
|
95
|
+
title: webObj.title,
|
|
96
|
+
languageId: (_a = webObj.language) !== null && _a !== void 0 ? _a : 1033, // Default to English
|
|
97
|
+
logoUrl: webObj.logoUrl,
|
|
98
|
+
// Site collection (all prefixed)
|
|
99
|
+
siteId: siteObj.id.toString(),
|
|
100
|
+
siteUrl: siteObj.absoluteUrl,
|
|
101
|
+
siteServerRelativeUrl: siteObj.serverRelativeUrl,
|
|
102
|
+
siteClassification: legacy === null || legacy === void 0 ? void 0 : legacy.siteClassification,
|
|
103
|
+
siteGroup: siteObj.group ? {
|
|
104
|
+
id: siteObj.group.id.toString(),
|
|
105
|
+
isPublic: (_b = siteObj.group.isPublic) !== null && _b !== void 0 ? _b : false,
|
|
106
|
+
} : undefined,
|
|
107
|
+
};
|
|
108
|
+
}
|
|
109
|
+
//# sourceMappingURL=useSPFxSiteInfo.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useSPFxSiteInfo.js","sourceRoot":"","sources":["../../src/hooks/useSPFxSiteInfo.ts"],"names":[],"mappings":"AAAA,qBAAqB;AACrB,qDAAqD;AAErD,OAAO,EAAE,kBAAkB,EAAE,MAAM,sBAAsB,CAAC;AAsD1D;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6EG;AACH,MAAM,UAAU,eAAe;;IAC7B,IAAM,WAAW,GAAG,kBAAkB,EAAE,CAAC;IAEzC,IAAM,OAAO,GAAG,WAAW,CAAC,IAAI,CAAC;IACjC,IAAM,MAAM,GAAG,WAAW,CAAC,GAAG,CAAC;IAE/B,uDAAuD;IACvD,IAAM,MAAM,GAAI,WAId,CAAC,iBAAiB,CAAC;IAErB,OAAO;QACL,0BAA0B;QAC1B,KAAK,EAAE,MAAM,CAAC,EAAE,CAAC,QAAQ,EAAE;QAC3B,MAAM,EAAE,MAAM,CAAC,WAAW;QAC1B,oBAAoB,EAAE,MAAM,CAAC,iBAAiB;QAE9C,iDAAiD;QACjD,KAAK,EAAE,MAAM,CAAC,KAAK;QACnB,UAAU,EAAE,MAAA,MAAM,CAAC,QAAQ,mCAAI,IAAI,EAAE,qBAAqB;QAC1D,OAAO,EAAG,MAA0C,CAAC,OAAO;QAE5D,iCAAiC;QACjC,MAAM,EAAE,OAAO,CAAC,EAAE,CAAC,QAAQ,EAAE;QAC7B,OAAO,EAAE,OAAO,CAAC,WAAW;QAC5B,qBAAqB,EAAE,OAAO,CAAC,iBAAiB;QAChD,kBAAkB,EAAE,MAAM,aAAN,MAAM,uBAAN,MAAM,CAAE,kBAAkB;QAC9C,SAAS,EAAE,OAAO,CAAC,KAAK,CAAC,CAAC,CAAC;YACzB,EAAE,EAAE,OAAO,CAAC,KAAK,CAAC,EAAE,CAAC,QAAQ,EAAE;YAC/B,QAAQ,EAAE,MAAA,OAAO,CAAC,KAAK,CAAC,QAAQ,mCAAI,KAAK;SAC1C,CAAC,CAAC,CAAC,SAAS;KACd,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Return type for storage hooks
|
|
3
|
+
*/
|
|
4
|
+
export interface SPFxStorageHook<T> {
|
|
5
|
+
/** Current value */
|
|
6
|
+
readonly value: T;
|
|
7
|
+
/** Set new value */
|
|
8
|
+
readonly setValue: (value: T | ((prev: T) => T)) => void;
|
|
9
|
+
/** Remove value (reset to default) */
|
|
10
|
+
readonly remove: () => void;
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* Hook to use localStorage scoped to SPFx instance
|
|
14
|
+
*
|
|
15
|
+
* Creates a persisted state atom using Jotai's atomWithStorage.
|
|
16
|
+
* The storage key is automatically scoped to the SPFx instance ID,
|
|
17
|
+
* ensuring isolation between different web parts/extensions.
|
|
18
|
+
*
|
|
19
|
+
* Data persists across page reloads and sessions.
|
|
20
|
+
*
|
|
21
|
+
* Use for:
|
|
22
|
+
* - User preferences
|
|
23
|
+
* - Form drafts
|
|
24
|
+
* - Long-lived cache
|
|
25
|
+
* - Settings
|
|
26
|
+
*
|
|
27
|
+
* @param key - Storage key (will be prefixed with instance ID)
|
|
28
|
+
* @param defaultValue - Default value if not in storage
|
|
29
|
+
* @returns Storage hook with value, setValue, and remove
|
|
30
|
+
*
|
|
31
|
+
* @example
|
|
32
|
+
* ```tsx
|
|
33
|
+
* function MyComponent() {
|
|
34
|
+
* const { value, setValue } = useSPFxLocalStorage('view-mode', 'grid');
|
|
35
|
+
*
|
|
36
|
+
* return (
|
|
37
|
+
* <div>
|
|
38
|
+
* <p>View: {value}</p>
|
|
39
|
+
* <button onClick={() => setValue('list')}>List View</button>
|
|
40
|
+
* <button onClick={() => setValue('grid')}>Grid View</button>
|
|
41
|
+
* </div>
|
|
42
|
+
* );
|
|
43
|
+
* }
|
|
44
|
+
* ```
|
|
45
|
+
*/
|
|
46
|
+
export declare function useSPFxLocalStorage<T>(key: string, defaultValue: T): SPFxStorageHook<T>;
|
|
47
|
+
/**
|
|
48
|
+
* Hook to use sessionStorage scoped to SPFx instance
|
|
49
|
+
*
|
|
50
|
+
* Creates a persisted state atom using Jotai's atomWithStorage.
|
|
51
|
+
* The storage key is automatically scoped to the SPFx instance ID,
|
|
52
|
+
* ensuring isolation between different web parts/extensions.
|
|
53
|
+
*
|
|
54
|
+
* Data persists only for the current browser session/tab.
|
|
55
|
+
*
|
|
56
|
+
* Use for:
|
|
57
|
+
* - Temporary state
|
|
58
|
+
* - Session-specific cache
|
|
59
|
+
* - Tab-specific settings
|
|
60
|
+
* - Wizard state
|
|
61
|
+
*
|
|
62
|
+
* @param key - Storage key (will be prefixed with instance ID)
|
|
63
|
+
* @param defaultValue - Default value if not in storage
|
|
64
|
+
* @returns Storage hook with value, setValue, and remove
|
|
65
|
+
*
|
|
66
|
+
* @example
|
|
67
|
+
* ```tsx
|
|
68
|
+
* function WizardComponent() {
|
|
69
|
+
* const { value: step, setValue: setStep } = useSPFxSessionStorage('wizard-step', 1);
|
|
70
|
+
*
|
|
71
|
+
* return (
|
|
72
|
+
* <div>
|
|
73
|
+
* <p>Step: {step}</p>
|
|
74
|
+
* <button onClick={() => setStep(s => s + 1)}>Next</button>
|
|
75
|
+
* </div>
|
|
76
|
+
* );
|
|
77
|
+
* }
|
|
78
|
+
* ```
|
|
79
|
+
*/
|
|
80
|
+
export declare function useSPFxSessionStorage<T>(key: string, defaultValue: T): SPFxStorageHook<T>;
|
|
81
|
+
//# sourceMappingURL=useSPFxStorage.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useSPFxStorage.d.ts","sourceRoot":"","sources":["../../src/hooks/useSPFxStorage.ts"],"names":[],"mappings":"AAQA;;GAEG;AACH,MAAM,WAAW,eAAe,CAAC,CAAC;IAChC,oBAAoB;IACpB,QAAQ,CAAC,KAAK,EAAE,CAAC,CAAC;IAElB,oBAAoB;IACpB,QAAQ,CAAC,QAAQ,EAAE,CAAC,KAAK,EAAE,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,CAAC,KAAK,CAAC,CAAC,KAAK,IAAI,CAAC;IAEzD,sCAAsC;IACtC,QAAQ,CAAC,MAAM,EAAE,MAAM,IAAI,CAAC;CAC7B;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAiCG;AACH,wBAAgB,mBAAmB,CAAC,CAAC,EACnC,GAAG,EAAE,MAAM,EACX,YAAY,EAAE,CAAC,GACd,eAAe,CAAC,CAAC,CAAC,CA2BpB;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAgCG;AACH,wBAAgB,qBAAqB,CAAC,CAAC,EACrC,GAAG,EAAE,MAAM,EACX,YAAY,EAAE,CAAC,GACd,eAAe,CAAC,CAAC,CAAC,CAwDpB"}
|
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
// useSPFxStorage.ts
|
|
2
|
+
// Hooks for persisted storage scoped to SPFx instance
|
|
3
|
+
import { atomWithStorage } from 'jotai/utils';
|
|
4
|
+
import { useAtom } from 'jotai';
|
|
5
|
+
import { useMemo } from 'react';
|
|
6
|
+
import { useSPFxInstanceInfo } from './useSPFxInstanceInfo';
|
|
7
|
+
/**
|
|
8
|
+
* Hook to use localStorage scoped to SPFx instance
|
|
9
|
+
*
|
|
10
|
+
* Creates a persisted state atom using Jotai's atomWithStorage.
|
|
11
|
+
* The storage key is automatically scoped to the SPFx instance ID,
|
|
12
|
+
* ensuring isolation between different web parts/extensions.
|
|
13
|
+
*
|
|
14
|
+
* Data persists across page reloads and sessions.
|
|
15
|
+
*
|
|
16
|
+
* Use for:
|
|
17
|
+
* - User preferences
|
|
18
|
+
* - Form drafts
|
|
19
|
+
* - Long-lived cache
|
|
20
|
+
* - Settings
|
|
21
|
+
*
|
|
22
|
+
* @param key - Storage key (will be prefixed with instance ID)
|
|
23
|
+
* @param defaultValue - Default value if not in storage
|
|
24
|
+
* @returns Storage hook with value, setValue, and remove
|
|
25
|
+
*
|
|
26
|
+
* @example
|
|
27
|
+
* ```tsx
|
|
28
|
+
* function MyComponent() {
|
|
29
|
+
* const { value, setValue } = useSPFxLocalStorage('view-mode', 'grid');
|
|
30
|
+
*
|
|
31
|
+
* return (
|
|
32
|
+
* <div>
|
|
33
|
+
* <p>View: {value}</p>
|
|
34
|
+
* <button onClick={() => setValue('list')}>List View</button>
|
|
35
|
+
* <button onClick={() => setValue('grid')}>Grid View</button>
|
|
36
|
+
* </div>
|
|
37
|
+
* );
|
|
38
|
+
* }
|
|
39
|
+
* ```
|
|
40
|
+
*/
|
|
41
|
+
export function useSPFxLocalStorage(key, defaultValue) {
|
|
42
|
+
var instanceId = useSPFxInstanceInfo().id;
|
|
43
|
+
// Create scoped storage key
|
|
44
|
+
var scopedKey = 'spfx:' + instanceId + ':' + key;
|
|
45
|
+
// Create atom with storage (memoized to avoid recreation)
|
|
46
|
+
var storageAtom = useMemo(function () { return atomWithStorage(scopedKey, defaultValue); }, [scopedKey, defaultValue]);
|
|
47
|
+
var _a = useAtom(storageAtom), value = _a[0], setValue = _a[1];
|
|
48
|
+
// Remove function (reset to default)
|
|
49
|
+
var remove = function () {
|
|
50
|
+
setValue(defaultValue);
|
|
51
|
+
if (typeof localStorage !== 'undefined') {
|
|
52
|
+
localStorage.removeItem(scopedKey);
|
|
53
|
+
}
|
|
54
|
+
};
|
|
55
|
+
return {
|
|
56
|
+
value: value,
|
|
57
|
+
setValue: setValue,
|
|
58
|
+
remove: remove,
|
|
59
|
+
};
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* Hook to use sessionStorage scoped to SPFx instance
|
|
63
|
+
*
|
|
64
|
+
* Creates a persisted state atom using Jotai's atomWithStorage.
|
|
65
|
+
* The storage key is automatically scoped to the SPFx instance ID,
|
|
66
|
+
* ensuring isolation between different web parts/extensions.
|
|
67
|
+
*
|
|
68
|
+
* Data persists only for the current browser session/tab.
|
|
69
|
+
*
|
|
70
|
+
* Use for:
|
|
71
|
+
* - Temporary state
|
|
72
|
+
* - Session-specific cache
|
|
73
|
+
* - Tab-specific settings
|
|
74
|
+
* - Wizard state
|
|
75
|
+
*
|
|
76
|
+
* @param key - Storage key (will be prefixed with instance ID)
|
|
77
|
+
* @param defaultValue - Default value if not in storage
|
|
78
|
+
* @returns Storage hook with value, setValue, and remove
|
|
79
|
+
*
|
|
80
|
+
* @example
|
|
81
|
+
* ```tsx
|
|
82
|
+
* function WizardComponent() {
|
|
83
|
+
* const { value: step, setValue: setStep } = useSPFxSessionStorage('wizard-step', 1);
|
|
84
|
+
*
|
|
85
|
+
* return (
|
|
86
|
+
* <div>
|
|
87
|
+
* <p>Step: {step}</p>
|
|
88
|
+
* <button onClick={() => setStep(s => s + 1)}>Next</button>
|
|
89
|
+
* </div>
|
|
90
|
+
* );
|
|
91
|
+
* }
|
|
92
|
+
* ```
|
|
93
|
+
*/
|
|
94
|
+
export function useSPFxSessionStorage(key, defaultValue) {
|
|
95
|
+
var instanceId = useSPFxInstanceInfo().id;
|
|
96
|
+
// Create scoped storage key
|
|
97
|
+
var scopedKey = 'spfx:' + instanceId + ':' + key;
|
|
98
|
+
// Create atom with session storage
|
|
99
|
+
var storageAtom = useMemo(function () { return atomWithStorage(scopedKey, defaultValue, {
|
|
100
|
+
getItem: function (key) {
|
|
101
|
+
if (typeof sessionStorage === 'undefined') {
|
|
102
|
+
return defaultValue;
|
|
103
|
+
}
|
|
104
|
+
var item = sessionStorage.getItem(key);
|
|
105
|
+
if (item === null) {
|
|
106
|
+
return defaultValue;
|
|
107
|
+
}
|
|
108
|
+
try {
|
|
109
|
+
return JSON.parse(item);
|
|
110
|
+
}
|
|
111
|
+
catch (_a) {
|
|
112
|
+
return defaultValue;
|
|
113
|
+
}
|
|
114
|
+
},
|
|
115
|
+
setItem: function (key, value) {
|
|
116
|
+
if (typeof sessionStorage !== 'undefined') {
|
|
117
|
+
sessionStorage.setItem(key, JSON.stringify(value));
|
|
118
|
+
}
|
|
119
|
+
},
|
|
120
|
+
removeItem: function (key) {
|
|
121
|
+
if (typeof sessionStorage !== 'undefined') {
|
|
122
|
+
sessionStorage.removeItem(key);
|
|
123
|
+
}
|
|
124
|
+
},
|
|
125
|
+
}); }, [scopedKey, defaultValue]);
|
|
126
|
+
var _a = useAtom(storageAtom), value = _a[0], setValue = _a[1];
|
|
127
|
+
// Remove function (reset to default)
|
|
128
|
+
var remove = function () {
|
|
129
|
+
setValue(defaultValue);
|
|
130
|
+
if (typeof sessionStorage !== 'undefined') {
|
|
131
|
+
sessionStorage.removeItem(scopedKey);
|
|
132
|
+
}
|
|
133
|
+
};
|
|
134
|
+
return {
|
|
135
|
+
value: value,
|
|
136
|
+
setValue: setValue,
|
|
137
|
+
remove: remove,
|
|
138
|
+
};
|
|
139
|
+
}
|
|
140
|
+
//# sourceMappingURL=useSPFxStorage.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useSPFxStorage.js","sourceRoot":"","sources":["../../src/hooks/useSPFxStorage.ts"],"names":[],"mappings":"AAAA,oBAAoB;AACpB,sDAAsD;AAEtD,OAAO,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AAC9C,OAAO,EAAE,OAAO,EAAE,MAAM,OAAO,CAAC;AAChC,OAAO,EAAE,OAAO,EAAE,MAAM,OAAO,CAAC;AAChC,OAAO,EAAE,mBAAmB,EAAE,MAAM,uBAAuB,CAAC;AAgB5D;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAiCG;AACH,MAAM,UAAU,mBAAmB,CACjC,GAAW,E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K,IAAI,EAAE,CAAC;gBAClB,OAAO,YAAY,CAAC;YACtB,CAAC;YACD,IAAI,CAAC;gBACH,OAAO,IAAI,CAAC,KAAK,CAAC,IAAI,CAAM,CAAC;YAC/B,CAAC;YAAC,WAAM,CAAC;gBACP,OAAO,YAAY,CAAC;YACtB,CAAC;QACH,CAAC;QACD,OAAO,EAAE,UAAC,GAAG,EAAE,KAAK;YAClB,IAAI,OAAO,cAAc,KAAK,WAAW,EAAE,CAAC;gBAC1C,cAAc,CAAC,OAAO,CAAC,GAAG,EAAE,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC,CAAC;YACrD,CAAC;QACH,CAAC;QACD,UAAU,EAAE,UAAC,GAAG;YACd,IAAI,OAAO,cAAc,KAAK,WAAW,EAAE,CAAC;gBAC1C,cAAc,CAAC,UAAU,CAAC,GAAG,CAAC,CAAC;YACjC,CAAC;QACH,CAAC;KACF,CACF,EA7BK,CA6BL,EACD,CAAC,SAAS,EAAE,YAAY,CAAC,CAC1B,CAAC;IAEI,IAAA,KAAoB,OAAO,CAAC,WAAW,CAAC,EAAvC,KAAK,QAAA,EAAE,QAAQ,QAAwB,CAAC;IAE/C,qCAAqC;IACrC,IAAM,MAAM,GAAG;QACb,QAAQ,CAAC,YAAY,CAAC,CAAC;QACvB,IAAI,OAAO,cAAc,KAAK,WAAW,EAAE,CAAC;YAC1C,cAAc,CAAC,UAAU,CAAC,SAAS,CAAC,CAAC;QACvC,CAAC;IACH,CAAC,CAAC;IAEF,OAAO;QACL,KAAK,OAAA;QACL,QAAQ,UAAA;QACR,MAAM,QAAA;KACP,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Teams theme type
|
|
3
|
+
*/
|
|
4
|
+
export type TeamsTheme = 'default' | 'dark' | 'highContrast';
|
|
5
|
+
/**
|
|
6
|
+
* Return type for useSPFxTeams hook
|
|
7
|
+
*/
|
|
8
|
+
export interface SPFxTeamsInfo {
|
|
9
|
+
/** Whether Teams context is supported/available */
|
|
10
|
+
readonly supported: boolean;
|
|
11
|
+
/** Teams context object (if available) */
|
|
12
|
+
readonly context: unknown | undefined;
|
|
13
|
+
/** Current Teams theme */
|
|
14
|
+
readonly theme: TeamsTheme | undefined;
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Hook for Microsoft Teams context integration
|
|
18
|
+
*
|
|
19
|
+
* Provides access to Microsoft Teams context when SPFx component
|
|
20
|
+
* is running in Teams environment.
|
|
21
|
+
*
|
|
22
|
+
* Automatically initializes Teams SDK (supports both v1 and v2 APIs)
|
|
23
|
+
* and provides:
|
|
24
|
+
* - Teams context (team, channel, user info, etc.)
|
|
25
|
+
* - Teams theme (default, dark, high contrast)
|
|
26
|
+
* - Supported flag
|
|
27
|
+
*
|
|
28
|
+
* The initialization happens asynchronously on first mount.
|
|
29
|
+
*
|
|
30
|
+
* Useful for:
|
|
31
|
+
* - Teams-specific features
|
|
32
|
+
* - Theme synchronization
|
|
33
|
+
* - User context access
|
|
34
|
+
* - Channel/team information
|
|
35
|
+
* - Teams app integration
|
|
36
|
+
*
|
|
37
|
+
* @returns Teams context information
|
|
38
|
+
*
|
|
39
|
+
* @example
|
|
40
|
+
* ```tsx
|
|
41
|
+
* function MyComponent() {
|
|
42
|
+
* const { supported, context, theme } = useSPFxTeams();
|
|
43
|
+
*
|
|
44
|
+
* if (!supported) {
|
|
45
|
+
* return <div>Not in Teams</div>;
|
|
46
|
+
* }
|
|
47
|
+
*
|
|
48
|
+
* const teamsContext = context as {
|
|
49
|
+
* user?: { id: string };
|
|
50
|
+
* team?: { displayName: string };
|
|
51
|
+
* };
|
|
52
|
+
*
|
|
53
|
+
* return (
|
|
54
|
+
* <div className={`teams-theme-${theme}`}>
|
|
55
|
+
* <p>Team: {teamsContext.team?.displayName}</p>
|
|
56
|
+
* <p>Theme: {theme}</p>
|
|
57
|
+
* </div>
|
|
58
|
+
* );
|
|
59
|
+
* }
|
|
60
|
+
* ```
|
|
61
|
+
*/
|
|
62
|
+
export declare function useSPFxTeams(): SPFxTeamsInfo;
|
|
63
|
+
//# sourceMappingURL=useSPFxTeams.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useSPFxTeams.d.ts","sourceRoot":"","sources":["../../src/hooks/useSPFxTeams.ts"],"names":[],"mappings":"AAQA;;GAEG;AACH,MAAM,MAAM,UAAU,GAAG,SAAS,GAAG,MAAM,GAAG,cAAc,CAAC;AAE7D;;GAEG;AACH,MAAM,WAAW,aAAa;IAC5B,mDAAmD;IACnD,QAAQ,CAAC,SAAS,EAAE,OAAO,CAAC;IAE5B,0CAA0C;IAC1C,QAAQ,CAAC,OAAO,EAAE,OAAO,GAAG,SAAS,CAAC;IAEtC,0BAA0B;IAC1B,QAAQ,CAAC,KAAK,EAAE,UAAU,GAAG,SAAS,CAAC;CACxC;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6CG;AACH,wBAAgB,YAAY,IAAI,aAAa,CA2G5C"}
|
|
@@ -0,0 +1,198 @@
|
|
|
1
|
+
// useSPFxTeams.ts
|
|
2
|
+
// Hook for Microsoft Teams context integration
|
|
3
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
4
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
5
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
6
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
7
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
8
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
9
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
10
|
+
});
|
|
11
|
+
};
|
|
12
|
+
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
13
|
+
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
14
|
+
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
15
|
+
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
16
|
+
function step(op) {
|
|
17
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
18
|
+
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
19
|
+
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
20
|
+
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
21
|
+
switch (op[0]) {
|
|
22
|
+
case 0: case 1: t = op; break;
|
|
23
|
+
case 4: _.label++; return { value: op[1], done: false };
|
|
24
|
+
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
25
|
+
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
26
|
+
default:
|
|
27
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
28
|
+
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
29
|
+
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
30
|
+
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
31
|
+
if (t[2]) _.ops.pop();
|
|
32
|
+
_.trys.pop(); continue;
|
|
33
|
+
}
|
|
34
|
+
op = body.call(thisArg, _);
|
|
35
|
+
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
36
|
+
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
37
|
+
}
|
|
38
|
+
};
|
|
39
|
+
import { useEffect } from 'react';
|
|
40
|
+
import { useAtom } from 'jotai';
|
|
41
|
+
import { spfxAtoms } from '../core/atoms.internal';
|
|
42
|
+
import { useSPFxContext } from './useSPFxContext';
|
|
43
|
+
/**
|
|
44
|
+
* Hook for Microsoft Teams context integration
|
|
45
|
+
*
|
|
46
|
+
* Provides access to Microsoft Teams context when SPFx component
|
|
47
|
+
* is running in Teams environment.
|
|
48
|
+
*
|
|
49
|
+
* Automatically initializes Teams SDK (supports both v1 and v2 APIs)
|
|
50
|
+
* and provides:
|
|
51
|
+
* - Teams context (team, channel, user info, etc.)
|
|
52
|
+
* - Teams theme (default, dark, high contrast)
|
|
53
|
+
* - Supported flag
|
|
54
|
+
*
|
|
55
|
+
* The initialization happens asynchronously on first mount.
|
|
56
|
+
*
|
|
57
|
+
* Useful for:
|
|
58
|
+
* - Teams-specific features
|
|
59
|
+
* - Theme synchronization
|
|
60
|
+
* - User context access
|
|
61
|
+
* - Channel/team information
|
|
62
|
+
* - Teams app integration
|
|
63
|
+
*
|
|
64
|
+
* @returns Teams context information
|
|
65
|
+
*
|
|
66
|
+
* @example
|
|
67
|
+
* ```tsx
|
|
68
|
+
* function MyComponent() {
|
|
69
|
+
* const { supported, context, theme } = useSPFxTeams();
|
|
70
|
+
*
|
|
71
|
+
* if (!supported) {
|
|
72
|
+
* return <div>Not in Teams</div>;
|
|
73
|
+
* }
|
|
74
|
+
*
|
|
75
|
+
* const teamsContext = context as {
|
|
76
|
+
* user?: { id: string };
|
|
77
|
+
* team?: { displayName: string };
|
|
78
|
+
* };
|
|
79
|
+
*
|
|
80
|
+
* return (
|
|
81
|
+
* <div className={`teams-theme-${theme}`}>
|
|
82
|
+
* <p>Team: {teamsContext.team?.displayName}</p>
|
|
83
|
+
* <p>Theme: {theme}</p>
|
|
84
|
+
* </div>
|
|
85
|
+
* );
|
|
86
|
+
* }
|
|
87
|
+
* ```
|
|
88
|
+
*/
|
|
89
|
+
export function useSPFxTeams() {
|
|
90
|
+
var _this = this;
|
|
91
|
+
var spfxContext = useSPFxContext().spfxContext;
|
|
92
|
+
var _a = useAtom(spfxAtoms.teams), state = _a[0], setState = _a[1];
|
|
93
|
+
useEffect(function () {
|
|
94
|
+
// Skip if already initialized
|
|
95
|
+
if (state.initialized) {
|
|
96
|
+
return;
|
|
97
|
+
}
|
|
98
|
+
// Extract Teams SDK from context
|
|
99
|
+
var ctx = spfxContext;
|
|
100
|
+
var sdks = ctx.sdks;
|
|
101
|
+
var teamsSDK = sdks === null || sdks === void 0 ? void 0 : sdks.microsoftTeams;
|
|
102
|
+
if (!teamsSDK) {
|
|
103
|
+
setState({ supported: false, initialized: true });
|
|
104
|
+
return;
|
|
105
|
+
}
|
|
106
|
+
var disposed = false;
|
|
107
|
+
// Helper to apply context and theme
|
|
108
|
+
var apply = function (context, themeValue) {
|
|
109
|
+
if (disposed) {
|
|
110
|
+
return;
|
|
111
|
+
}
|
|
112
|
+
var normalizedTheme = ((themeValue === null || themeValue === void 0 ? void 0 : themeValue.toLowerCase()) === 'dark' ? 'dark' :
|
|
113
|
+
(themeValue === null || themeValue === void 0 ? void 0 : themeValue.toLowerCase()) === 'contrast' || (themeValue === null || themeValue === void 0 ? void 0 : themeValue.toLowerCase()) === 'highcontrast' ? 'highContrast' :
|
|
114
|
+
'default');
|
|
115
|
+
setState({
|
|
116
|
+
supported: true,
|
|
117
|
+
context: context,
|
|
118
|
+
theme: normalizedTheme,
|
|
119
|
+
initialized: true,
|
|
120
|
+
});
|
|
121
|
+
};
|
|
122
|
+
// Try v2 API (teams 2.0+)
|
|
123
|
+
var tryV2 = function () { return __awaiter(_this, void 0, void 0, function () {
|
|
124
|
+
var context, themeValue, _a;
|
|
125
|
+
var _b, _c;
|
|
126
|
+
return __generator(this, function (_d) {
|
|
127
|
+
switch (_d.label) {
|
|
128
|
+
case 0:
|
|
129
|
+
_d.trys.push([0, 3, , 4]);
|
|
130
|
+
if (!((_b = teamsSDK.app) === null || _b === void 0 ? void 0 : _b.getContext)) return [3 /*break*/, 2];
|
|
131
|
+
return [4 /*yield*/, teamsSDK.app.getContext()];
|
|
132
|
+
case 1:
|
|
133
|
+
context = _d.sent();
|
|
134
|
+
themeValue = (_c = context === null || context === void 0 ? void 0 : context.app) === null || _c === void 0 ? void 0 : _c.theme;
|
|
135
|
+
apply(context, themeValue);
|
|
136
|
+
return [2 /*return*/, true];
|
|
137
|
+
case 2: return [2 /*return*/, false];
|
|
138
|
+
case 3:
|
|
139
|
+
_a = _d.sent();
|
|
140
|
+
return [2 /*return*/, false];
|
|
141
|
+
case 4: return [2 /*return*/];
|
|
142
|
+
}
|
|
143
|
+
});
|
|
144
|
+
}); };
|
|
145
|
+
// Try v1 API (teams 1.x)
|
|
146
|
+
var tryV1 = function () {
|
|
147
|
+
return new Promise(function (resolve) {
|
|
148
|
+
try {
|
|
149
|
+
if (teamsSDK.getContext) {
|
|
150
|
+
teamsSDK.getContext(function (context) {
|
|
151
|
+
var themeValue = context === null || context === void 0 ? void 0 : context.theme;
|
|
152
|
+
apply(context, themeValue);
|
|
153
|
+
resolve(true);
|
|
154
|
+
});
|
|
155
|
+
}
|
|
156
|
+
else {
|
|
157
|
+
resolve(false);
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
catch (_a) {
|
|
161
|
+
resolve(false);
|
|
162
|
+
}
|
|
163
|
+
});
|
|
164
|
+
};
|
|
165
|
+
// Initialize async
|
|
166
|
+
var init = function () { return __awaiter(_this, void 0, void 0, function () {
|
|
167
|
+
var v2Success;
|
|
168
|
+
return __generator(this, function (_a) {
|
|
169
|
+
switch (_a.label) {
|
|
170
|
+
case 0: return [4 /*yield*/, tryV2()];
|
|
171
|
+
case 1:
|
|
172
|
+
v2Success = _a.sent();
|
|
173
|
+
if (!!v2Success) return [3 /*break*/, 3];
|
|
174
|
+
return [4 /*yield*/, tryV1()];
|
|
175
|
+
case 2:
|
|
176
|
+
_a.sent();
|
|
177
|
+
_a.label = 3;
|
|
178
|
+
case 3: return [2 /*return*/];
|
|
179
|
+
}
|
|
180
|
+
});
|
|
181
|
+
}); };
|
|
182
|
+
init().catch(function () {
|
|
183
|
+
// Fallback: mark as not supported
|
|
184
|
+
if (!disposed) {
|
|
185
|
+
setState({ supported: false, initialized: true });
|
|
186
|
+
}
|
|
187
|
+
});
|
|
188
|
+
return function () {
|
|
189
|
+
disposed = true;
|
|
190
|
+
};
|
|
191
|
+
}, [spfxContext, setState, state.initialized]);
|
|
192
|
+
return {
|
|
193
|
+
supported: state.supported,
|
|
194
|
+
context: state.context,
|
|
195
|
+
theme: state.theme,
|
|
196
|
+
};
|
|
197
|
+
}
|
|
198
|
+
//# sourceMappingURL=useSPFxTeams.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useSPFxTeams.js","sourceRoot":"","sources":["../../src/hooks/useSPFxTeams.ts"],"names":[],"mappings":"AAAA,kBAAkB;AAClB,+CAA+C;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAE/C,OAAO,EAAE,SAAS,EAAE,MAAM,OAAO,CAAC;AAClC,OAAO,EAAE,OAAO,EAAE,MAAM,OAAO,CAAC;AAChC,OAAO,EAAE,SAAS,EAAE,MAAM,wBAAwB,CAAC;AACnD,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAqBlD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6CG;AACH,MAAM,UAAU,YAAY;IAA5B,iBA2GC;IA1GS,IAAA,WAAW,GAAK,cAAc,EAAE,YAArB,CAAsB;IACnC,IAAA,KAAoB,OAAO,CAAC,SAAS,CAAC,KAAK,CAAC,EAA3C,KAAK,QAAA,EAAE,QAAQ,QAA4B,CAAC;IAEnD,SAAS,CAAC;QACR,8BAA8B;QAC9B,IAAI,KAAK,CAAC,WAAW,EAAE,CAAC;YACtB,OAAO;QACT,CAAC;QAED,iCAAiC;QACjC,IAAM,GAAG,GAAG,WAAsD,CAAC;QACnE,IAAM,IAAI,GAAG,GAAG,CAAC,IAAI,CAAC;QACtB,IAAM,QAAQ,GAAG,IAA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