@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,299 @@
|
|
|
1
|
+
// useSPFxAadHttpClient.ts
|
|
2
|
+
// Hook to access Azure AD-secured APIs with state management
|
|
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 { useState, useCallback, useEffect } from 'react';
|
|
40
|
+
import { useSPFxContext } from './useSPFxContext';
|
|
41
|
+
/**
|
|
42
|
+
* Hook to access Azure AD-secured APIs with built-in state management
|
|
43
|
+
*
|
|
44
|
+
* Provides native AadHttpClient for authenticated Azure AD-secured API access.
|
|
45
|
+
* Offers two usage patterns:
|
|
46
|
+
*
|
|
47
|
+
* 1. **invoke()** - Automatic state management (loading + error tracking)
|
|
48
|
+
* 2. **client** - Direct access for full control
|
|
49
|
+
*
|
|
50
|
+
* For type safety, import SPFx types:
|
|
51
|
+
* ```typescript
|
|
52
|
+
* import type { AadHttpClient } from '@microsoft/sp-http';
|
|
53
|
+
* ```
|
|
54
|
+
*
|
|
55
|
+
* Requirements:
|
|
56
|
+
* - Add permissions to package-solution.json webApiPermissionRequests
|
|
57
|
+
* - Admin must grant permissions in SharePoint Admin Center
|
|
58
|
+
* - AadHttpClientFactory available in SPFx context
|
|
59
|
+
*
|
|
60
|
+
* @param initialResourceUrl - Azure AD resource URL or App ID (optional, can be set later)
|
|
61
|
+
*
|
|
62
|
+
* @example Using invoke with state management
|
|
63
|
+
* ```tsx
|
|
64
|
+
* function OrdersList() {
|
|
65
|
+
* const { invoke, isLoading, error, clearError, resourceUrl } = useSPFxAadHttpClient(
|
|
66
|
+
* 'https://api.contoso.com'
|
|
67
|
+
* );
|
|
68
|
+
* const [orders, setOrders] = useState<Order[]>([]);
|
|
69
|
+
*
|
|
70
|
+
* const loadOrders = () => {
|
|
71
|
+
* invoke(client =>
|
|
72
|
+
* client.get(
|
|
73
|
+
* `${resourceUrl}/api/orders`,
|
|
74
|
+
* AadHttpClient.configurations.v1
|
|
75
|
+
* ).then(res => res.json())
|
|
76
|
+
* ).then(data => setOrders(data));
|
|
77
|
+
* };
|
|
78
|
+
*
|
|
79
|
+
* useEffect(() => { loadOrders(); }, []);
|
|
80
|
+
*
|
|
81
|
+
* if (isLoading) return <Spinner />;
|
|
82
|
+
* if (error) return (
|
|
83
|
+
* <MessageBar messageBarType={MessageBarType.error}>
|
|
84
|
+
* {error.message}
|
|
85
|
+
* <Link onClick={() => { clearError(); loadOrders(); }}>Retry</Link>
|
|
86
|
+
* </MessageBar>
|
|
87
|
+
* );
|
|
88
|
+
*
|
|
89
|
+
* return <ul>{orders.map(o => <li key={o.id}>{o.total}</li>)}</ul>;
|
|
90
|
+
* }
|
|
91
|
+
* ```
|
|
92
|
+
*
|
|
93
|
+
* @example Using client directly for advanced control
|
|
94
|
+
* ```tsx
|
|
95
|
+
* import type { AadHttpClient } from '@microsoft/sp-http';
|
|
96
|
+
*
|
|
97
|
+
* function ProductsManager() {
|
|
98
|
+
* const { client, resourceUrl } = useSPFxAadHttpClient('https://api.contoso.com');
|
|
99
|
+
* const [products, setProducts] = useState([]);
|
|
100
|
+
* const [loading, setLoading] = useState(false);
|
|
101
|
+
*
|
|
102
|
+
* if (!client) return <Spinner label="Initializing AAD client..." />;
|
|
103
|
+
*
|
|
104
|
+
* const loadProducts = async () => {
|
|
105
|
+
* setLoading(true);
|
|
106
|
+
* try {
|
|
107
|
+
* const response = await client.get(
|
|
108
|
+
* `${resourceUrl}/api/products`,
|
|
109
|
+
* AadHttpClient.configurations.v1
|
|
110
|
+
* );
|
|
111
|
+
* const data = await response.json();
|
|
112
|
+
* setProducts(data);
|
|
113
|
+
* } catch (err) {
|
|
114
|
+
* console.error(err);
|
|
115
|
+
* } finally {
|
|
116
|
+
* setLoading(false);
|
|
117
|
+
* }
|
|
118
|
+
* };
|
|
119
|
+
*
|
|
120
|
+
* return (
|
|
121
|
+
* <>
|
|
122
|
+
* <button onClick={loadProducts} disabled={loading}>Load</button>
|
|
123
|
+
* {loading && <Spinner />}
|
|
124
|
+
* <DetailsList items={products} />
|
|
125
|
+
* </>
|
|
126
|
+
* );
|
|
127
|
+
* }
|
|
128
|
+
* ```
|
|
129
|
+
*
|
|
130
|
+
* @example CRUD operations with invoke
|
|
131
|
+
* ```tsx
|
|
132
|
+
* function ItemsManager() {
|
|
133
|
+
* const { invoke, isLoading, error, resourceUrl } = useSPFxAadHttpClient(
|
|
134
|
+
* 'https://api.contoso.com'
|
|
135
|
+
* );
|
|
136
|
+
* const [items, setItems] = useState([]);
|
|
137
|
+
*
|
|
138
|
+
* const loadItems = () => {
|
|
139
|
+
* invoke(client =>
|
|
140
|
+
* client.get(
|
|
141
|
+
* `${resourceUrl}/api/items`,
|
|
142
|
+
* AadHttpClient.configurations.v1
|
|
143
|
+
* ).then(res => res.json())
|
|
144
|
+
* ).then(data => setItems(data));
|
|
145
|
+
* };
|
|
146
|
+
*
|
|
147
|
+
* const createItem = (item: any) => {
|
|
148
|
+
* invoke(client =>
|
|
149
|
+
* client.post(
|
|
150
|
+
* `${resourceUrl}/api/items`,
|
|
151
|
+
* AadHttpClient.configurations.v1,
|
|
152
|
+
* { body: JSON.stringify(item) }
|
|
153
|
+
* ).then(res => res.json())
|
|
154
|
+
* ).then(loadItems);
|
|
155
|
+
* };
|
|
156
|
+
*
|
|
157
|
+
* const updateItem = (id: string, changes: any) => {
|
|
158
|
+
* invoke(client =>
|
|
159
|
+
* client.post(
|
|
160
|
+
* `${resourceUrl}/api/items/${id}`,
|
|
161
|
+
* AadHttpClient.configurations.v1,
|
|
162
|
+
* {
|
|
163
|
+
* headers: { 'X-HTTP-Method': 'PATCH' },
|
|
164
|
+
* body: JSON.stringify(changes)
|
|
165
|
+
* }
|
|
166
|
+
* )
|
|
167
|
+
* ).then(loadItems);
|
|
168
|
+
* };
|
|
169
|
+
*
|
|
170
|
+
* const deleteItem = (id: string) => {
|
|
171
|
+
* invoke(client =>
|
|
172
|
+
* client.post(
|
|
173
|
+
* `${resourceUrl}/api/items/${id}`,
|
|
174
|
+
* AadHttpClient.configurations.v1,
|
|
175
|
+
* { headers: { 'X-HTTP-Method': 'DELETE' } }
|
|
176
|
+
* )
|
|
177
|
+
* ).then(loadItems);
|
|
178
|
+
* };
|
|
179
|
+
*
|
|
180
|
+
* return (
|
|
181
|
+
* <ItemsUI
|
|
182
|
+
* items={items}
|
|
183
|
+
* loading={isLoading}
|
|
184
|
+
* error={error}
|
|
185
|
+
* onCreate={createItem}
|
|
186
|
+
* onUpdate={updateItem}
|
|
187
|
+
* onDelete={deleteItem}
|
|
188
|
+
* />
|
|
189
|
+
* );
|
|
190
|
+
* }
|
|
191
|
+
* ```
|
|
192
|
+
*
|
|
193
|
+
* @example Lazy initialization with setResourceUrl
|
|
194
|
+
* ```tsx
|
|
195
|
+
* function DynamicApi() {
|
|
196
|
+
* const { invoke, setResourceUrl, resourceUrl, clearError } = useSPFxAadHttpClient();
|
|
197
|
+
* const [data, setData] = useState(null);
|
|
198
|
+
*
|
|
199
|
+
* const loadFromApi = async (apiUrl: string) => {
|
|
200
|
+
* clearError();
|
|
201
|
+
* setResourceUrl(apiUrl);
|
|
202
|
+
*
|
|
203
|
+
* // Wait for client initialization, then fetch
|
|
204
|
+
* setTimeout(() => {
|
|
205
|
+
* invoke(client =>
|
|
206
|
+
* client.get(
|
|
207
|
+
* `${apiUrl}/api/data`,
|
|
208
|
+
* AadHttpClient.configurations.v1
|
|
209
|
+
* ).then(res => res.json())
|
|
210
|
+
* ).then(setData);
|
|
211
|
+
* }, 100);
|
|
212
|
+
* };
|
|
213
|
+
*
|
|
214
|
+
* return (
|
|
215
|
+
* <>
|
|
216
|
+
* <button onClick={() => loadFromApi('https://api1.contoso.com')}>API 1</button>
|
|
217
|
+
* <button onClick={() => loadFromApi('https://api2.contoso.com')}>API 2</button>
|
|
218
|
+
* {data && <pre>{JSON.stringify(data, null, 2)}</pre>}
|
|
219
|
+
* </>
|
|
220
|
+
* );
|
|
221
|
+
* }
|
|
222
|
+
* ```
|
|
223
|
+
*/
|
|
224
|
+
export function useSPFxAadHttpClient(initialResourceUrl) {
|
|
225
|
+
var _this = this;
|
|
226
|
+
var spfxContext = useSPFxContext().spfxContext;
|
|
227
|
+
// Extract factory from context
|
|
228
|
+
var ctx = spfxContext;
|
|
229
|
+
// State management
|
|
230
|
+
var _a = useState(initialResourceUrl), resourceUrl = _a[0], setResourceUrl = _a[1];
|
|
231
|
+
var _b = useState(undefined), client = _b[0], setClient = _b[1];
|
|
232
|
+
var _c = useState(false), isLoading = _c[0], setIsLoading = _c[1];
|
|
233
|
+
var _d = useState(undefined), error = _d[0], setError = _d[1];
|
|
234
|
+
// Initialize client when resourceUrl changes
|
|
235
|
+
useEffect(function () {
|
|
236
|
+
// Reset client immediately when resourceUrl changes
|
|
237
|
+
setClient(undefined);
|
|
238
|
+
if (!resourceUrl) {
|
|
239
|
+
return;
|
|
240
|
+
}
|
|
241
|
+
if (!ctx.aadHttpClientFactory) {
|
|
242
|
+
console.warn('AadHttpClientFactory not available in SPFx context');
|
|
243
|
+
return;
|
|
244
|
+
}
|
|
245
|
+
// Get AadHttpClient for the specified resource
|
|
246
|
+
ctx.aadHttpClientFactory
|
|
247
|
+
.getClient(resourceUrl)
|
|
248
|
+
.then(function (aadClient) {
|
|
249
|
+
setClient(aadClient);
|
|
250
|
+
})
|
|
251
|
+
.catch(function (err) {
|
|
252
|
+
console.error('Failed to initialize AadHttpClient:', err);
|
|
253
|
+
});
|
|
254
|
+
}, [resourceUrl, ctx.aadHttpClientFactory]);
|
|
255
|
+
// Invoke with automatic state management
|
|
256
|
+
var invoke = useCallback(function (fn) { return __awaiter(_this, void 0, void 0, function () {
|
|
257
|
+
var result, err_1, error_1;
|
|
258
|
+
return __generator(this, function (_a) {
|
|
259
|
+
switch (_a.label) {
|
|
260
|
+
case 0:
|
|
261
|
+
if (!client) {
|
|
262
|
+
throw new Error('AadHttpClient not initialized. Set resourceUrl and wait for client initialization.');
|
|
263
|
+
}
|
|
264
|
+
setIsLoading(true);
|
|
265
|
+
setError(undefined);
|
|
266
|
+
_a.label = 1;
|
|
267
|
+
case 1:
|
|
268
|
+
_a.trys.push([1, 3, 4, 5]);
|
|
269
|
+
return [4 /*yield*/, fn(client)];
|
|
270
|
+
case 2:
|
|
271
|
+
result = _a.sent();
|
|
272
|
+
return [2 /*return*/, result];
|
|
273
|
+
case 3:
|
|
274
|
+
err_1 = _a.sent();
|
|
275
|
+
error_1 = err_1 instanceof Error ? err_1 : new Error(String(err_1));
|
|
276
|
+
setError(error_1);
|
|
277
|
+
throw error_1;
|
|
278
|
+
case 4:
|
|
279
|
+
setIsLoading(false);
|
|
280
|
+
return [7 /*endfinally*/];
|
|
281
|
+
case 5: return [2 /*return*/];
|
|
282
|
+
}
|
|
283
|
+
});
|
|
284
|
+
}); }, [client]);
|
|
285
|
+
// Clear error helper
|
|
286
|
+
var clearError = useCallback(function () {
|
|
287
|
+
setError(undefined);
|
|
288
|
+
}, []);
|
|
289
|
+
return {
|
|
290
|
+
client: client,
|
|
291
|
+
invoke: invoke,
|
|
292
|
+
isLoading: isLoading,
|
|
293
|
+
error: error,
|
|
294
|
+
clearError: clearError,
|
|
295
|
+
setResourceUrl: setResourceUrl,
|
|
296
|
+
resourceUrl: resourceUrl,
|
|
297
|
+
};
|
|
298
|
+
}
|
|
299
|
+
//# sourceMappingURL=useSPFxAadHttpClient.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useSPFxAadHttpClient.js","sourceRoot":"","sources":["../../src/hooks/useSPFxAadHttpClient.ts"],"names":[],"mappings":"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"}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import type { ContainerSize } from '../core/types';
|
|
2
|
+
/**
|
|
3
|
+
* Return type for useSPFxContainerInfo hook
|
|
4
|
+
*/
|
|
5
|
+
export interface SPFxContainerInfo {
|
|
6
|
+
/** Container DOM element */
|
|
7
|
+
readonly element: HTMLElement | undefined;
|
|
8
|
+
/** Container size (width/height in pixels) */
|
|
9
|
+
readonly size: ContainerSize | undefined;
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* Hook to access container element and its size
|
|
13
|
+
*
|
|
14
|
+
* Automatically tracks container size changes using ResizeObserver
|
|
15
|
+
* Updates in real-time when container is resized
|
|
16
|
+
*
|
|
17
|
+
* Useful for:
|
|
18
|
+
* - Responsive layouts
|
|
19
|
+
* - Dynamic content sizing
|
|
20
|
+
* - Breakpoint calculations
|
|
21
|
+
* - Canvas/chart dimensions
|
|
22
|
+
*
|
|
23
|
+
* @returns Container element and size
|
|
24
|
+
*
|
|
25
|
+
* @example
|
|
26
|
+
* ```tsx
|
|
27
|
+
* function MyComponent() {
|
|
28
|
+
* const { element, size } = useSPFxContainerInfo();
|
|
29
|
+
*
|
|
30
|
+
* return (
|
|
31
|
+
* <div>
|
|
32
|
+
* {size && (
|
|
33
|
+
* <p>Container: {size.width}px × {size.height}px</p>
|
|
34
|
+
* )}
|
|
35
|
+
* </div>
|
|
36
|
+
* );
|
|
37
|
+
* }
|
|
38
|
+
* ```
|
|
39
|
+
*/
|
|
40
|
+
export declare function useSPFxContainerInfo(): SPFxContainerInfo;
|
|
41
|
+
//# sourceMappingURL=useSPFxContainerInfo.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useSPFxContainerInfo.d.ts","sourceRoot":"","sources":["../../src/hooks/useSPFxContainerInfo.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,eAAe,CAAC;AAEnD;;GAEG;AACH,MAAM,WAAW,iBAAiB;IAChC,4BAA4B;IAC5B,QAAQ,CAAC,OAAO,EAAE,WAAW,GAAG,SAAS,CAAC;IAE1C,8CAA8C;IAC9C,QAAQ,CAAC,IAAI,EAAE,aAAa,GAAG,SAAS,CAAC;CAC1C;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;AACH,wBAAgB,oBAAoB,IAAI,iBAAiB,CAaxD"}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
// useSPFxContainerInfo.ts
|
|
2
|
+
// Hook to access container element and size
|
|
3
|
+
import { useAtomValue, useSetAtom } from 'jotai';
|
|
4
|
+
import { spfxAtoms } from '../core/atoms.internal';
|
|
5
|
+
import { useResizeObserver } from '../utils/resize-observer.internal';
|
|
6
|
+
/**
|
|
7
|
+
* Hook to access container element and its size
|
|
8
|
+
*
|
|
9
|
+
* Automatically tracks container size changes using ResizeObserver
|
|
10
|
+
* Updates in real-time when container is resized
|
|
11
|
+
*
|
|
12
|
+
* Useful for:
|
|
13
|
+
* - Responsive layouts
|
|
14
|
+
* - Dynamic content sizing
|
|
15
|
+
* - Breakpoint calculations
|
|
16
|
+
* - Canvas/chart dimensions
|
|
17
|
+
*
|
|
18
|
+
* @returns Container element and size
|
|
19
|
+
*
|
|
20
|
+
* @example
|
|
21
|
+
* ```tsx
|
|
22
|
+
* function MyComponent() {
|
|
23
|
+
* const { element, size } = useSPFxContainerInfo();
|
|
24
|
+
*
|
|
25
|
+
* return (
|
|
26
|
+
* <div>
|
|
27
|
+
* {size && (
|
|
28
|
+
* <p>Container: {size.width}px × {size.height}px</p>
|
|
29
|
+
* )}
|
|
30
|
+
* </div>
|
|
31
|
+
* );
|
|
32
|
+
* }
|
|
33
|
+
* ```
|
|
34
|
+
*/
|
|
35
|
+
export function useSPFxContainerInfo() {
|
|
36
|
+
// Read container element and size directly from atoms
|
|
37
|
+
var element = useAtomValue(spfxAtoms.containerEl);
|
|
38
|
+
var size = useAtomValue(spfxAtoms.containerSize);
|
|
39
|
+
// Setup ResizeObserver with atom setter
|
|
40
|
+
var setSize = useSetAtom(spfxAtoms.containerSize);
|
|
41
|
+
useResizeObserver(element, setSize);
|
|
42
|
+
return {
|
|
43
|
+
element: element,
|
|
44
|
+
size: size,
|
|
45
|
+
};
|
|
46
|
+
}
|
|
47
|
+
//# sourceMappingURL=useSPFxContainerInfo.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useSPFxContainerInfo.js","sourceRoot":"","sources":["../../src/hooks/useSPFxContainerInfo.ts"],"names":[],"mappings":"AAAA,0BAA0B;AAC1B,4CAA4C;AAE5C,OAAO,EAAE,YAAY,EAAE,UAAU,EAAE,MAAM,OAAO,CAAC;AACjD,OAAO,EAAE,SAAS,EAAE,MAAM,wBAAwB,CAAC;AACnD,OAAO,EAAE,iBAAiB,EAAE,MAAM,mCAAmC,CAAC;AActE;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;AACH,MAAM,UAAU,oBAAoB;IAClC,sDAAsD;IACtD,IAAM,OAAO,GAAG,YAAY,CAAC,SAAS,CAAC,WAAW,CAAC,CAAC;IACpD,IAAM,IAAI,GAAG,YAAY,CAAC,SAAS,CAAC,aAAa,CAAC,CAAC;IAEnD,wCAAwC;IACxC,IAAM,OAAO,GAAG,UAAU,CAAC,SAAS,CAAC,aAAa,CAAC,CAAC;IACpD,iBAAiB,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC;IAEpC,OAAO;QACL,OAAO,SAAA;QACP,IAAI,MAAA;KACL,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Container size categories (Fluent UI 9 aligned)
|
|
3
|
+
*
|
|
4
|
+
* Based on official Fluent UI 9 responsive breakpoints:
|
|
5
|
+
* @see https://developer.microsoft.com/en-us/fluentui#/styles/web/responsive
|
|
6
|
+
*
|
|
7
|
+
* - small: 320-479px (Mobile portrait)
|
|
8
|
+
* - medium: 480-639px (Mobile landscape, small tablets)
|
|
9
|
+
* - large: 640-1023px (Tablets, single column)
|
|
10
|
+
* - xLarge: 1024-1365px (Laptop, desktop standard)
|
|
11
|
+
* - xxLarge: 1366-1919px (Large desktop, wide screen)
|
|
12
|
+
* - xxxLarge: >= 1920px (4K, ultra-wide, multi-column)
|
|
13
|
+
*/
|
|
14
|
+
export type SPFxContainerSize = 'small' | 'medium' | 'large' | 'xLarge' | 'xxLarge' | 'xxxLarge';
|
|
15
|
+
/**
|
|
16
|
+
* Return type for useSPFxContainerSize hook
|
|
17
|
+
*/
|
|
18
|
+
export interface SPFxContainerSizeInfo {
|
|
19
|
+
/** Container size category (Fluent UI 9 aligned) */
|
|
20
|
+
readonly size: SPFxContainerSize;
|
|
21
|
+
/** Is small container (320-479px) - mobile portrait */
|
|
22
|
+
readonly isSmall: boolean;
|
|
23
|
+
/** Is medium container (480-639px) - mobile landscape, small tablets */
|
|
24
|
+
readonly isMedium: boolean;
|
|
25
|
+
/** Is large container (640-1023px) - tablets, single column */
|
|
26
|
+
readonly isLarge: boolean;
|
|
27
|
+
/** Is extra large container (1024-1365px) - laptop, desktop standard */
|
|
28
|
+
readonly isXLarge: boolean;
|
|
29
|
+
/** Is extra extra large container (1366-1919px) - large desktop, wide screen */
|
|
30
|
+
readonly isXXLarge: boolean;
|
|
31
|
+
/** Is extra extra extra large container (>= 1920px) - 4K, ultra-wide, multi-column */
|
|
32
|
+
readonly isXXXLarge: boolean;
|
|
33
|
+
/** Actual container width in pixels */
|
|
34
|
+
readonly width: number;
|
|
35
|
+
/** Actual container height in pixels */
|
|
36
|
+
readonly height: number;
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Hook to get container size with Fluent UI 9 aligned breakpoints
|
|
40
|
+
*
|
|
41
|
+
* Automatically tracks container size changes and categorizes into
|
|
42
|
+
* Fluent UI 9 compatible size categories.
|
|
43
|
+
*
|
|
44
|
+
* Breakpoints (aligned with Fluent UI 9):
|
|
45
|
+
* - small: 320-479px (mobile portrait)
|
|
46
|
+
* - medium: 480-639px (mobile landscape, small tablets)
|
|
47
|
+
* - large: 640-1023px (tablets, single column)
|
|
48
|
+
* - xLarge: 1024-1365px (laptop, desktop standard)
|
|
49
|
+
* - xxLarge: 1366-1919px (large desktop, wide screen)
|
|
50
|
+
* - xxxLarge: >= 1920px (4K, ultra-wide, multi-column)
|
|
51
|
+
*
|
|
52
|
+
* Useful for:
|
|
53
|
+
* - Responsive layouts based on actual container space
|
|
54
|
+
* - Adaptive UI that works in sidebars, columns, or full width
|
|
55
|
+
* - Fluent UI 9 compatible responsive design
|
|
56
|
+
* - Making layout decisions based on available space
|
|
57
|
+
*
|
|
58
|
+
* @returns Container size information and helpers
|
|
59
|
+
*
|
|
60
|
+
* @example
|
|
61
|
+
* ```tsx
|
|
62
|
+
* function MyWebPart() {
|
|
63
|
+
* const { size, isSmall, isXXXLarge, width } = useSPFxContainerSize();
|
|
64
|
+
*
|
|
65
|
+
* // Decision based on size
|
|
66
|
+
* if (size === 'small') {
|
|
67
|
+
* return <CompactMobileView />;
|
|
68
|
+
* }
|
|
69
|
+
*
|
|
70
|
+
* if (size === 'medium' || size === 'large') {
|
|
71
|
+
* return <TabletView />;
|
|
72
|
+
* }
|
|
73
|
+
*
|
|
74
|
+
* if (size === 'xxxLarge') {
|
|
75
|
+
* return <UltraWideView columns={6} />; // 4K/ultra-wide
|
|
76
|
+
* }
|
|
77
|
+
*
|
|
78
|
+
* return <DesktopView columns={size === 'xxLarge' ? 4 : 3} />;
|
|
79
|
+
* }
|
|
80
|
+
* ```
|
|
81
|
+
*
|
|
82
|
+
* @example
|
|
83
|
+
* ```tsx
|
|
84
|
+
* function ResponsiveComponent() {
|
|
85
|
+
* const { isSmall, isMedium, isLarge, isXLarge, isXXLarge, isXXXLarge } = useSPFxContainerSize();
|
|
86
|
+
*
|
|
87
|
+
* return (
|
|
88
|
+
* <div>
|
|
89
|
+
* {isSmall && <MobileLayout />}
|
|
90
|
+
* {(isMedium || isLarge) && <TabletLayout />}
|
|
91
|
+
* {isXLarge && <DesktopLayout columns={3} />}
|
|
92
|
+
* {isXXLarge && <DesktopLayout columns={4} />}
|
|
93
|
+
* {isXXXLarge && <UltraWideLayout columns={6} />}
|
|
94
|
+
* </div>
|
|
95
|
+
* );
|
|
96
|
+
* }
|
|
97
|
+
* ```
|
|
98
|
+
*
|
|
99
|
+
* @example
|
|
100
|
+
* ```tsx
|
|
101
|
+
* function AdaptiveCard() {
|
|
102
|
+
* const { size, width, height } = useSPFxContainerSize();
|
|
103
|
+
*
|
|
104
|
+
* return (
|
|
105
|
+
* <div>
|
|
106
|
+
* <p>Container: {width}px × {height}px</p>
|
|
107
|
+
* <p>Size category: {size}</p>
|
|
108
|
+
* {size === 'small' && <StackedLayout />}
|
|
109
|
+
* {size === 'medium' && <TwoColumnLayout />}
|
|
110
|
+
* {size === 'large' && <ThreeColumnLayout />}
|
|
111
|
+
* {(size === 'xLarge' || size === 'xxLarge') && <MultiColumnLayout />}
|
|
112
|
+
* {size === 'xxxLarge' && <UltraWideLayout columns={6} />}
|
|
113
|
+
* </div>
|
|
114
|
+
* );
|
|
115
|
+
* }
|
|
116
|
+
* ```
|
|
117
|
+
*/
|
|
118
|
+
export declare function useSPFxContainerSize(): SPFxContainerSizeInfo;
|
|
119
|
+
//# sourceMappingURL=useSPFxContainerSize.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useSPFxContainerSize.d.ts","sourceRoot":"","sources":["../../src/hooks/useSPFxContainerSize.ts"],"names":[],"mappings":"AAMA;;;;;;;;;;;;GAYG;AACH,MAAM,MAAM,iBAAiB,GACzB,OAAO,GACP,QAAQ,GACR,OAAO,GACP,QAAQ,GACR,SAAS,GACT,UAAU,CAAC;AAEf;;GAEG;AACH,MAAM,WAAW,qBAAqB;IACpC,oDAAoD;IACpD,QAAQ,CAAC,IAAI,EAAE,iBAAiB,CAAC;IAEjC,uDAAuD;IACvD,QAAQ,CAAC,OAAO,EAAE,OAAO,CAAC;IAE1B,wEAAwE;IACxE,QAAQ,CAAC,QAAQ,EAAE,OAAO,CAAC;IAE3B,+DAA+D;IAC/D,QAAQ,CAAC,OAAO,EAAE,OAAO,CAAC;IAE1B,wEAAwE;IACxE,QAAQ,CAAC,QAAQ,EAAE,OAAO,CAAC;IAE3B,gFAAgF;IAChF,QAAQ,CAAC,SAAS,EAAE,OAAO,CAAC;IAE5B,sFAAsF;IACtF,QAAQ,CAAC,UAAU,EAAE,OAAO,CAAC;IAE7B,uCAAuC;IACvC,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IAEvB,wCAAwC;IACxC,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;CACzB;AAiDD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+EG;AACH,wBAAgB,oBAAoB,IAAI,qBAAqB,CAoB5D"}
|
|
@@ -0,0 +1,150 @@
|
|
|
1
|
+
// useSPFxContainerSize.ts
|
|
2
|
+
// Hook for container size detection with SharePoint-aligned breakpoints
|
|
3
|
+
import { useMemo } from 'react';
|
|
4
|
+
import { useSPFxContainerInfo } from './useSPFxContainerInfo';
|
|
5
|
+
/**
|
|
6
|
+
* Fluent UI 9 container size breakpoints
|
|
7
|
+
*
|
|
8
|
+
* Based on official Fluent UI 9 responsive breakpoints:
|
|
9
|
+
* - Small: 320px (mobile portrait)
|
|
10
|
+
* - Medium: 480px (mobile landscape, small tablets)
|
|
11
|
+
* - Large: 640px (tablets, single column)
|
|
12
|
+
* - XLarge: 1024px (laptop, desktop standard)
|
|
13
|
+
* - XXLarge: 1366px (large desktop, wide screen)
|
|
14
|
+
* - XXXLarge: 1920px (4K, ultra-wide, multi-column)
|
|
15
|
+
*
|
|
16
|
+
* @see https://developer.microsoft.com/en-us/fluentui#/styles/web/responsive
|
|
17
|
+
*/
|
|
18
|
+
var CONTAINER_SIZE_BREAKPOINTS = {
|
|
19
|
+
small: 480, // Fluent UI 9: Small → Medium (320-479 → 480+)
|
|
20
|
+
medium: 640, // Fluent UI 9: Medium → Large (480-639 → 640+)
|
|
21
|
+
large: 1024, // Fluent UI 9: Large → XLarge (640-1023 → 1024+)
|
|
22
|
+
xLarge: 1366, // Fluent UI 9: XLarge → XXLarge (1024-1365 → 1366+)
|
|
23
|
+
xxLarge: 1920, // Fluent UI 9: XXLarge → XXXLarge (1366-1919 → 1920+)
|
|
24
|
+
xxxLarge: Infinity, // No upper bound for XXXLarge (>= 1920px)
|
|
25
|
+
};
|
|
26
|
+
/**
|
|
27
|
+
* Get container size category from width
|
|
28
|
+
*
|
|
29
|
+
* @param width - Container width in pixels
|
|
30
|
+
* @returns Container size category
|
|
31
|
+
*/
|
|
32
|
+
function getContainerSize(width) {
|
|
33
|
+
if (width < CONTAINER_SIZE_BREAKPOINTS.small) {
|
|
34
|
+
return 'small'; // < 480px
|
|
35
|
+
}
|
|
36
|
+
if (width < CONTAINER_SIZE_BREAKPOINTS.medium) {
|
|
37
|
+
return 'medium'; // 480-639px
|
|
38
|
+
}
|
|
39
|
+
if (width < CONTAINER_SIZE_BREAKPOINTS.large) {
|
|
40
|
+
return 'large'; // 640-1023px
|
|
41
|
+
}
|
|
42
|
+
if (width < CONTAINER_SIZE_BREAKPOINTS.xLarge) {
|
|
43
|
+
return 'xLarge'; // 1024-1365px
|
|
44
|
+
}
|
|
45
|
+
if (width < CONTAINER_SIZE_BREAKPOINTS.xxLarge) {
|
|
46
|
+
return 'xxLarge'; // 1366-1919px
|
|
47
|
+
}
|
|
48
|
+
return 'xxxLarge'; // >= 1920px
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Hook to get container size with Fluent UI 9 aligned breakpoints
|
|
52
|
+
*
|
|
53
|
+
* Automatically tracks container size changes and categorizes into
|
|
54
|
+
* Fluent UI 9 compatible size categories.
|
|
55
|
+
*
|
|
56
|
+
* Breakpoints (aligned with Fluent UI 9):
|
|
57
|
+
* - small: 320-479px (mobile portrait)
|
|
58
|
+
* - medium: 480-639px (mobile landscape, small tablets)
|
|
59
|
+
* - large: 640-1023px (tablets, single column)
|
|
60
|
+
* - xLarge: 1024-1365px (laptop, desktop standard)
|
|
61
|
+
* - xxLarge: 1366-1919px (large desktop, wide screen)
|
|
62
|
+
* - xxxLarge: >= 1920px (4K, ultra-wide, multi-column)
|
|
63
|
+
*
|
|
64
|
+
* Useful for:
|
|
65
|
+
* - Responsive layouts based on actual container space
|
|
66
|
+
* - Adaptive UI that works in sidebars, columns, or full width
|
|
67
|
+
* - Fluent UI 9 compatible responsive design
|
|
68
|
+
* - Making layout decisions based on available space
|
|
69
|
+
*
|
|
70
|
+
* @returns Container size information and helpers
|
|
71
|
+
*
|
|
72
|
+
* @example
|
|
73
|
+
* ```tsx
|
|
74
|
+
* function MyWebPart() {
|
|
75
|
+
* const { size, isSmall, isXXXLarge, width } = useSPFxContainerSize();
|
|
76
|
+
*
|
|
77
|
+
* // Decision based on size
|
|
78
|
+
* if (size === 'small') {
|
|
79
|
+
* return <CompactMobileView />;
|
|
80
|
+
* }
|
|
81
|
+
*
|
|
82
|
+
* if (size === 'medium' || size === 'large') {
|
|
83
|
+
* return <TabletView />;
|
|
84
|
+
* }
|
|
85
|
+
*
|
|
86
|
+
* if (size === 'xxxLarge') {
|
|
87
|
+
* return <UltraWideView columns={6} />; // 4K/ultra-wide
|
|
88
|
+
* }
|
|
89
|
+
*
|
|
90
|
+
* return <DesktopView columns={size === 'xxLarge' ? 4 : 3} />;
|
|
91
|
+
* }
|
|
92
|
+
* ```
|
|
93
|
+
*
|
|
94
|
+
* @example
|
|
95
|
+
* ```tsx
|
|
96
|
+
* function ResponsiveComponent() {
|
|
97
|
+
* const { isSmall, isMedium, isLarge, isXLarge, isXXLarge, isXXXLarge } = useSPFxContainerSize();
|
|
98
|
+
*
|
|
99
|
+
* return (
|
|
100
|
+
* <div>
|
|
101
|
+
* {isSmall && <MobileLayout />}
|
|
102
|
+
* {(isMedium || isLarge) && <TabletLayout />}
|
|
103
|
+
* {isXLarge && <DesktopLayout columns={3} />}
|
|
104
|
+
* {isXXLarge && <DesktopLayout columns={4} />}
|
|
105
|
+
* {isXXXLarge && <UltraWideLayout columns={6} />}
|
|
106
|
+
* </div>
|
|
107
|
+
* );
|
|
108
|
+
* }
|
|
109
|
+
* ```
|
|
110
|
+
*
|
|
111
|
+
* @example
|
|
112
|
+
* ```tsx
|
|
113
|
+
* function AdaptiveCard() {
|
|
114
|
+
* const { size, width, height } = useSPFxContainerSize();
|
|
115
|
+
*
|
|
116
|
+
* return (
|
|
117
|
+
* <div>
|
|
118
|
+
* <p>Container: {width}px × {height}px</p>
|
|
119
|
+
* <p>Size category: {size}</p>
|
|
120
|
+
* {size === 'small' && <StackedLayout />}
|
|
121
|
+
* {size === 'medium' && <TwoColumnLayout />}
|
|
122
|
+
* {size === 'large' && <ThreeColumnLayout />}
|
|
123
|
+
* {(size === 'xLarge' || size === 'xxLarge') && <MultiColumnLayout />}
|
|
124
|
+
* {size === 'xxxLarge' && <UltraWideLayout columns={6} />}
|
|
125
|
+
* </div>
|
|
126
|
+
* );
|
|
127
|
+
* }
|
|
128
|
+
* ```
|
|
129
|
+
*/
|
|
130
|
+
export function useSPFxContainerSize() {
|
|
131
|
+
var containerSize = useSPFxContainerInfo().size;
|
|
132
|
+
return useMemo(function () {
|
|
133
|
+
var _a, _b;
|
|
134
|
+
var width = (_a = containerSize === null || containerSize === void 0 ? void 0 : containerSize.width) !== null && _a !== void 0 ? _a : 0;
|
|
135
|
+
var height = (_b = containerSize === null || containerSize === void 0 ? void 0 : containerSize.height) !== null && _b !== void 0 ? _b : 0;
|
|
136
|
+
var size = getContainerSize(width);
|
|
137
|
+
return {
|
|
138
|
+
size: size,
|
|
139
|
+
isSmall: size === 'small',
|
|
140
|
+
isMedium: size === 'medium',
|
|
141
|
+
isLarge: size === 'large',
|
|
142
|
+
isXLarge: size === 'xLarge',
|
|
143
|
+
isXXLarge: size === 'xxLarge',
|
|
144
|
+
isXXXLarge: size === 'xxxLarge',
|
|
145
|
+
width: width,
|
|
146
|
+
height: height,
|
|
147
|
+
};
|
|
148
|
+
}, [containerSize]);
|
|
149
|
+
}
|
|
150
|
+
//# sourceMappingURL=useSPFxContainerSize.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useSPFxContainerSize.js","sourceRoot":"","sources":["../../src/hooks/useSPFxContainerSize.ts"],"names":[],"mappings":"AAAA,0BAA0B;AAC1B,wEAAwE;AAExE,OAAO,EAAE,OAAO,EAAE,MAAM,OAAO,CAAC;AAChC,OAAO,EAAE,oBAAoB,EAAE,MAAM,wBAAwB,CAAC;AAuD9D;;;;;;;;;;;;GAYG;AACH,IAAM,0BAA0B,GAAG;IACjC,KAAK,EAAE,GAAG,EAAM,+CAA+C;IAC/D,MAAM,EAAE,GAAG,EAAK,+CAA+C;IAC/D,KAAK,EAAE,IAAI,EAAK,iDAAiD;IACjE,MAAM,EAAE,IAAI,EAAI,oDAAoD;IACpE,OAAO,EAAE,IAAI,EAAG,sDAAsD;IACtE,QAAQ,EAAE,QAAQ,EAAE,0CAA0C;CACtD,CAAC;AAEX;;;;;GAKG;AACH,SAAS,gBAAgB,CAAC,KAAa;IACrC,IAAI,KAAK,GAAG,0BAA0B,CAAC,KAAK,EAAE,CAAC;QAC7C,OAAO,OAAO,CAAC,CAAK,UAAU;IAChC,CAAC;IACD,IAAI,KAAK,GAAG,0BAA0B,CAAC,MAAM,EAAE,CAAC;QAC9C,OAAO,QAAQ,CAAC,CAAI,YAAY;IAClC,CAAC;IACD,IAAI,KAAK,GAAG,0BAA0B,CAAC,KAAK,EAAE,CAAC;QAC7C,OAAO,OAAO,CAAC,CAAK,aAAa;IACnC,CAAC;IACD,IAAI,KAAK,GAAG,0BAA0B,CAAC,MAAM,EAAE,CAAC;QAC9C,OAAO,QAAQ,CAAC,CAAI,cAAc;IACpC,CAAC;IACD,IAAI,KAAK,GAAG,0BAA0B,CAAC,OAAO,EAAE,CAAC;QAC/C,OAAO,SAAS,CAAC,CAAG,cAAc;IACpC,CAAC;IACD,OAAO,UAAU,CAAC,CAAI,YAAY;AACpC,CAAC;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+EG;AACH,MAAM,UAAU,oBAAoB;IAC1B,IAAM,aAAa,GAAK,oBAAoB,EAAE,KAA3B,CAA4B;IAEvD,OAAO,OAAO,CAAC;;QACb,IAAM,KAAK,GAAG,MAAA,aAAa,aAAb,aAAa,uBAAb,aAAa,CAAE,KAAK,mCAAI,CAAC,CAAC;QACxC,IAAM,MAAM,GAAG,MAAA,aAAa,aAAb,aAAa,uBAAb,aAAa,CAAE,MAAM,mCAAI,CAAC,CAAC;QAC1C,IAAM,IAAI,GAAG,gBAAgB,CAAC,KAAK,CAAC,CAAC;QAErC,OAAO;YACL,IAAI,MAAA;YACJ,OAAO,EAAE,IAAI,KAAK,OAAO;YACzB,QAAQ,EAAE,IAAI,KAAK,QAAQ;YAC3B,OAAO,EAAE,IAAI,KAAK,OAAO;YACzB,QAAQ,EAAE,IAAI,KAAK,QAAQ;YAC3B,SAAS,EAAE,IAAI,KAAK,SAAS;YAC7B,UAAU,EAAE,IAAI,KAAK,UAAU;YAC/B,KAAK,OAAA;YACL,MAAM,QAAA;SACP,CAAC;IACJ,CAAC,EAAE,CAAC,aAAa,CAAC,CAAC,CAAC;AACtB,CAAC"}
|