@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,48 @@
|
|
|
1
|
+
// provider-listview-commandset.tsx
|
|
2
|
+
// Type-safe provider for ListView Command Sets
|
|
3
|
+
import * as React from 'react';
|
|
4
|
+
import { SPFxProviderBase } from './provider-base.internal';
|
|
5
|
+
/**
|
|
6
|
+
* SPFx context provider specifically for ListView Command Sets.
|
|
7
|
+
*
|
|
8
|
+
* This is a type-safe wrapper around the base provider that accepts a ListView Command Set instance
|
|
9
|
+
* directly without requiring type casting. Use this provider in ListView Command Sets instead of the
|
|
10
|
+
* generic `SPFxProvider`.
|
|
11
|
+
*
|
|
12
|
+
* @param props - The component props.
|
|
13
|
+
* @returns The provider component.
|
|
14
|
+
*
|
|
15
|
+
* @example
|
|
16
|
+
* ```tsx
|
|
17
|
+
* import { SPFxListViewCommandSetProvider } from 'spfx-react-toolkit';
|
|
18
|
+
* import { Dialog } from '@microsoft/sp-dialog';
|
|
19
|
+
*
|
|
20
|
+
* export default class MyCommandSet extends BaseListViewCommandSet<IMyProps> {
|
|
21
|
+
* public onExecute(event: IListViewCommandSetExecuteEventParameters): void {
|
|
22
|
+
* switch (event.itemId) {
|
|
23
|
+
* case 'COMMAND_1':
|
|
24
|
+
* // Create a dialog container
|
|
25
|
+
* const dialog = Dialog.alert({
|
|
26
|
+
* title: 'Custom Dialog',
|
|
27
|
+
* message: this._renderDialog()
|
|
28
|
+
* });
|
|
29
|
+
* break;
|
|
30
|
+
* }
|
|
31
|
+
* }
|
|
32
|
+
*
|
|
33
|
+
* private _renderDialog(): React.ReactElement {
|
|
34
|
+
* return React.createElement(
|
|
35
|
+
* SPFxListViewCommandSetProvider,
|
|
36
|
+
* { instance: this },
|
|
37
|
+
* React.createElement(MyComponent)
|
|
38
|
+
* );
|
|
39
|
+
* }
|
|
40
|
+
* }
|
|
41
|
+
* ```
|
|
42
|
+
*
|
|
43
|
+
* @public
|
|
44
|
+
*/
|
|
45
|
+
export function SPFxListViewCommandSetProvider(props) {
|
|
46
|
+
return React.createElement(SPFxProviderBase, { instance: props.instance }, props.children);
|
|
47
|
+
}
|
|
48
|
+
//# sourceMappingURL=provider-listview-commandset.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"provider-listview-commandset.js","sourceRoot":"","sources":["../../src/core/provider-listview-commandset.tsx"],"names":[],"mappings":"AAAA,mCAAmC;AACnC,+CAA+C;AAE/C,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAE/B,OAAO,EAAE,gBAAgB,EAAE,MAAM,0BAA0B,CAAC;AAoB5D;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAuCG;AACH,MAAM,UAAU,8BAA8B,CAC5C,KAAkD;IAElD,OAAO,oBAAC,gBAAgB,IAAC,QAAQ,EAAE,KAAK,CAAC,QAAiB,IAAG,KAAK,CAAC,QAAQ,CAAoB,CAAC;AAClG,CAAC"}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
import type { BaseClientSideWebPart } from '@microsoft/sp-webpart-base';
|
|
3
|
+
/**
|
|
4
|
+
* Props for the SPFx WebPart-specific provider component.
|
|
5
|
+
*
|
|
6
|
+
* @template TProps - The properties type for the WebPart.
|
|
7
|
+
* @public
|
|
8
|
+
*/
|
|
9
|
+
export interface SPFxWebPartProviderProps<TProps extends {} = {}> {
|
|
10
|
+
/**
|
|
11
|
+
* The SPFx WebPart instance.
|
|
12
|
+
*/
|
|
13
|
+
instance: BaseClientSideWebPart<TProps>;
|
|
14
|
+
/**
|
|
15
|
+
* The children to render within the provider.
|
|
16
|
+
*/
|
|
17
|
+
children?: React.ReactNode;
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* SPFx context provider specifically for WebParts.
|
|
21
|
+
*
|
|
22
|
+
* This is a type-safe wrapper around the base provider that accepts a WebPart instance
|
|
23
|
+
* directly without requiring type casting. Use this provider in WebParts instead of the
|
|
24
|
+
* generic `SPFxProvider`.
|
|
25
|
+
*
|
|
26
|
+
* @param props - The component props.
|
|
27
|
+
* @returns The provider component.
|
|
28
|
+
*
|
|
29
|
+
* @example
|
|
30
|
+
* ```tsx
|
|
31
|
+
* import { SPFxWebPartProvider } from 'spfx-react-toolkit';
|
|
32
|
+
*
|
|
33
|
+
* export default class MyWebPart extends BaseClientSideWebPart<IMyWebPartProps> {
|
|
34
|
+
* public render(): void {
|
|
35
|
+
* const element = React.createElement(
|
|
36
|
+
* SPFxWebPartProvider,
|
|
37
|
+
* { instance: this },
|
|
38
|
+
* React.createElement(MyComponent)
|
|
39
|
+
* );
|
|
40
|
+
* ReactDom.render(element, this.domElement);
|
|
41
|
+
* }
|
|
42
|
+
* }
|
|
43
|
+
* ```
|
|
44
|
+
*
|
|
45
|
+
* @public
|
|
46
|
+
*/
|
|
47
|
+
export declare function SPFxWebPartProvider<TProps extends {} = {}>(props: SPFxWebPartProviderProps<TProps>): JSX.Element;
|
|
48
|
+
//# sourceMappingURL=provider-webpart.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"provider-webpart.d.ts","sourceRoot":"","sources":["../../src/core/provider-webpart.tsx"],"names":[],"mappings":"AAGA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAC/B,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,4BAA4B,CAAC;AAGxE;;;;;GAKG;AACH,MAAM,WAAW,wBAAwB,CAAC,MAAM,SAAS,EAAE,GAAG,EAAE;IAC9D;;OAEG;IACH,QAAQ,EAAE,qBAAqB,CAAC,MAAM,CAAC,CAAC;IAExC;;OAEG;IACH,QAAQ,CAAC,EAAE,KAAK,CAAC,SAAS,CAAC;CAC5B;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;AACH,wBAAgB,mBAAmB,CAAC,MAAM,SAAS,EAAE,GAAG,EAAE,EACxD,KAAK,EAAE,wBAAwB,CAAC,MAAM,CAAC,GACtC,GAAG,CAAC,OAAO,CAEb"}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
// provider-webpart.tsx
|
|
2
|
+
// Type-safe provider for WebParts
|
|
3
|
+
import * as React from 'react';
|
|
4
|
+
import { SPFxProviderBase } from './provider-base.internal';
|
|
5
|
+
/**
|
|
6
|
+
* SPFx context provider specifically for WebParts.
|
|
7
|
+
*
|
|
8
|
+
* This is a type-safe wrapper around the base provider that accepts a WebPart instance
|
|
9
|
+
* directly without requiring type casting. Use this provider in WebParts instead of the
|
|
10
|
+
* generic `SPFxProvider`.
|
|
11
|
+
*
|
|
12
|
+
* @param props - The component props.
|
|
13
|
+
* @returns The provider component.
|
|
14
|
+
*
|
|
15
|
+
* @example
|
|
16
|
+
* ```tsx
|
|
17
|
+
* import { SPFxWebPartProvider } from 'spfx-react-toolkit';
|
|
18
|
+
*
|
|
19
|
+
* export default class MyWebPart extends BaseClientSideWebPart<IMyWebPartProps> {
|
|
20
|
+
* public render(): void {
|
|
21
|
+
* const element = React.createElement(
|
|
22
|
+
* SPFxWebPartProvider,
|
|
23
|
+
* { instance: this },
|
|
24
|
+
* React.createElement(MyComponent)
|
|
25
|
+
* );
|
|
26
|
+
* ReactDom.render(element, this.domElement);
|
|
27
|
+
* }
|
|
28
|
+
* }
|
|
29
|
+
* ```
|
|
30
|
+
*
|
|
31
|
+
* @public
|
|
32
|
+
*/
|
|
33
|
+
export function SPFxWebPartProvider(props) {
|
|
34
|
+
return React.createElement(SPFxProviderBase, { instance: props.instance }, props.children);
|
|
35
|
+
}
|
|
36
|
+
//# sourceMappingURL=provider-webpart.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"provider-webpart.js","sourceRoot":"","sources":["../../src/core/provider-webpart.tsx"],"names":[],"mappings":"AAAA,uBAAuB;AACvB,kCAAkC;AAElC,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAE/B,OAAO,EAAE,gBAAgB,EAAE,MAAM,0BAA0B,CAAC;AAoB5D;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;AACH,MAAM,UAAU,mBAAmB,CACjC,KAAuC;IAEvC,OAAO,oBAAC,gBAAgB,IAAC,QAAQ,EAAE,KAAK,CAAC,QAAiB,IAAG,KAAK,CAAC,QAAQ,CAAoB,CAAC;AAClG,CAAC"}
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
/// <reference types="react" />
|
|
2
|
+
import type { BaseClientSideWebPart } from '@microsoft/sp-webpart-base';
|
|
3
|
+
import type { BaseApplicationCustomizer } from '@microsoft/sp-application-base';
|
|
4
|
+
import type { BaseListViewCommandSet, BaseFieldCustomizer } from '@microsoft/sp-listview-extensibility';
|
|
5
|
+
/**
|
|
6
|
+
* Type of SPFx host component
|
|
7
|
+
*/
|
|
8
|
+
export type HostKind = 'WebPart' | 'AppCustomizer' | 'FieldCustomizer' | 'CommandSet' | 'ACE';
|
|
9
|
+
/**
|
|
10
|
+
* Union type for all SPFx component instances
|
|
11
|
+
* Uses actual SPFx base classes for full type safety and API access
|
|
12
|
+
*/
|
|
13
|
+
export type SPFxComponent<TProps extends {} = {}> = BaseClientSideWebPart<TProps> | BaseApplicationCustomizer<TProps> | BaseListViewCommandSet<TProps> | BaseFieldCustomizer<TProps>;
|
|
14
|
+
/**
|
|
15
|
+
* Union type for all SPFx context types
|
|
16
|
+
* Provides type-safe access to common context properties across all SPFx components
|
|
17
|
+
*
|
|
18
|
+
* @remarks
|
|
19
|
+
* All SPFx contexts include these common properties:
|
|
20
|
+
* - `pageContext` - SharePoint page context
|
|
21
|
+
* - `serviceScope` - Service locator for SPFx services
|
|
22
|
+
* - `instanceId` - Unique identifier for the component instance
|
|
23
|
+
*
|
|
24
|
+
* For component-specific properties, use type narrowing or casting:
|
|
25
|
+
* ```typescript
|
|
26
|
+
* const ctx = useSPFxContext();
|
|
27
|
+
* if (ctx.kind === 'WebPart') {
|
|
28
|
+
* const wpContext = ctx.spfxContext as WebPartContext;
|
|
29
|
+
* // Access WebPart-specific properties
|
|
30
|
+
* }
|
|
31
|
+
* ```
|
|
32
|
+
*/
|
|
33
|
+
export type SPFxContextType = BaseClientSideWebPart<any>['context'] | BaseApplicationCustomizer<any>['context'] | BaseListViewCommandSet<any>['context'] | BaseFieldCustomizer<any>['context'];
|
|
34
|
+
/**
|
|
35
|
+
* Container size information
|
|
36
|
+
*/
|
|
37
|
+
export interface ContainerSize {
|
|
38
|
+
readonly width: number;
|
|
39
|
+
readonly height: number;
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Props accepted by SPFxProvider (instance-based API)
|
|
43
|
+
*
|
|
44
|
+
* @example
|
|
45
|
+
* ```tsx
|
|
46
|
+
* // In your WebPart render():
|
|
47
|
+
* public render(): void {
|
|
48
|
+
* const element = React.createElement(
|
|
49
|
+
* SPFxProvider,
|
|
50
|
+
* { instance: this },
|
|
51
|
+
* React.createElement(MyComponent)
|
|
52
|
+
* );
|
|
53
|
+
* ReactDom.render(element, this.domElement);
|
|
54
|
+
* }
|
|
55
|
+
* ```
|
|
56
|
+
*/
|
|
57
|
+
export interface SPFxProviderProps<TProps extends {} = {}> {
|
|
58
|
+
/** SPFx component instance (WebPart, ApplicationCustomizer, etc.) */
|
|
59
|
+
readonly instance: SPFxComponent<TProps>;
|
|
60
|
+
/** Children to render */
|
|
61
|
+
readonly children?: React.ReactNode;
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* Context value provided by SPFxProvider
|
|
65
|
+
* Contains only static metadata, no reactive state
|
|
66
|
+
*
|
|
67
|
+
* @remarks
|
|
68
|
+
* The `spfxContext` property provides type-safe access to common SPFx context properties
|
|
69
|
+
* like `pageContext`, `serviceScope`, and `instanceId`. For component-specific properties,
|
|
70
|
+
* use type narrowing with the `kind` property.
|
|
71
|
+
*/
|
|
72
|
+
export interface SPFxContextValue {
|
|
73
|
+
/** Unique identifier for this SPFx instance */
|
|
74
|
+
readonly instanceId: string;
|
|
75
|
+
/**
|
|
76
|
+
* SPFx context object with full type safety
|
|
77
|
+
* Provides access to common properties: pageContext, serviceScope, instanceId
|
|
78
|
+
* For component-specific properties, use type narrowing based on `kind`
|
|
79
|
+
*/
|
|
80
|
+
readonly spfxContext: SPFxContextType;
|
|
81
|
+
/** Type of host component */
|
|
82
|
+
readonly kind: HostKind;
|
|
83
|
+
}
|
|
84
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/core/types.ts"],"names":[],"mappings":";AAGA,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,4BAA4B,CAAC;AACxE,OAAO,KAAK,EAAE,yBAAyB,EAAE,MAAM,gCAAgC,CAAC;AAChF,OAAO,KAAK,EAAE,sBAAsB,EAAE,mBAAmB,EAAE,MAAM,sCAAsC,CAAC;AAExG;;GAEG;AACH,MAAM,MAAM,QAAQ,GAChB,SAAS,GACT,eAAe,GACf,iBAAiB,GACjB,YAAY,GACZ,KAAK,CAAC;AAEV;;;GAGG;AACH,MAAM,MAAM,aAAa,CAAC,MAAM,SAAS,EAAE,GAAG,EAAE,IAC5C,qBAAqB,CAAC,MAAM,CAAC,GAC7B,yBAAyB,CAAC,MAAM,CAAC,GACjC,sBAAsB,CAAC,MAAM,CAAC,GAC9B,mBAAmB,CAAC,MAAM,CAAC,CAAC;AAEhC;;;;;;;;;;;;;;;;;;GAkBG;AAEH,MAAM,MAAM,eAAe,GAEvB,qBAAqB,CAAC,GAAG,CAAC,CAAC,SAAS,CAAC,GAErC,yBAAyB,CAAC,GAAG,CAAC,CAAC,SAAS,CAAC,GAEzC,sBAAsB,CAAC,GAAG,CAAC,CAAC,SAAS,CAAC,GAEtC,mBAAmB,CAAC,GAAG,CAAC,CAAC,SAAS,CAAC,CAAC;AAExC;;GAEG;AACH,MAAM,WAAW,aAAa;IAC5B,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IACvB,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;CACzB;AAED;;;;;;;;;;;;;;;GAeG;AACH,MAAM,WAAW,iBAAiB,CAAC,MAAM,SAAS,EAAE,GAAG,EAAE;IACvD,qEAAqE;IACrE,QAAQ,CAAC,QAAQ,EAAE,aAAa,CAAC,MAAM,CAAC,CAAC;IAEzC,yBAAyB;IACzB,QAAQ,CAAC,QAAQ,CAAC,EAAE,KAAK,CAAC,SAAS,CAAC;CACrC;AAED;;;;;;;;GAQG;AACH,MAAM,WAAW,gBAAgB;IAC/B,+CAA+C;IAC/C,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAC;IAE5B;;;;OAIG;IACH,QAAQ,CAAC,WAAW,EAAE,eAAe,CAAC;IAEtC,6BAA6B;IAC7B,QAAQ,CAAC,IAAI,EAAE,QAAQ,CAAC;CACzB"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/core/types.ts"],"names":[],"mappings":"AAAA,WAAW;AACX,+CAA+C"}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
export * from './useSPFxAadHttpClient';
|
|
2
|
+
export * from './useSPFxContainerInfo';
|
|
3
|
+
export * from './useSPFxContainerSize';
|
|
4
|
+
export * from './useSPFxCorrelationInfo';
|
|
5
|
+
export * from './useSPFxCrossSitePermissions';
|
|
6
|
+
export * from './useSPFxDisplayMode';
|
|
7
|
+
export * from './useSPFxEnvironmentInfo';
|
|
8
|
+
export * from './useSPFxFluent9ThemeInfo';
|
|
9
|
+
export * from './useSPFxHubSiteInfo';
|
|
10
|
+
export * from './useSPFxInstanceInfo';
|
|
11
|
+
export * from './useSPFxListInfo';
|
|
12
|
+
export * from './useSPFxLocaleInfo';
|
|
13
|
+
export * from './useSPFxLogger';
|
|
14
|
+
export * from './useSPFxMSGraphClient';
|
|
15
|
+
export * from './useSPFxOneDriveAppData';
|
|
16
|
+
export * from './useSPFxPageContext';
|
|
17
|
+
export * from './useSPFxPageType';
|
|
18
|
+
export * from './useSPFxPerformance';
|
|
19
|
+
export * from './useSPFxPermissions';
|
|
20
|
+
export * from './useSPFxPnP';
|
|
21
|
+
export * from './useSPFxPnPContext';
|
|
22
|
+
export * from './useSPFxPnPList';
|
|
23
|
+
export * from './useSPFxPnPSearch';
|
|
24
|
+
export * from './useSPFxProperties';
|
|
25
|
+
export * from './useSPFxSPHttpClient';
|
|
26
|
+
export * from './useSPFxServiceScope';
|
|
27
|
+
export * from './useSPFxSiteInfo';
|
|
28
|
+
export * from './useSPFxStorage';
|
|
29
|
+
export * from './useSPFxTeams';
|
|
30
|
+
export * from './useSPFxTenantProperty';
|
|
31
|
+
export * from './useSPFxThemeInfo';
|
|
32
|
+
export * from './useSPFxUserInfo';
|
|
33
|
+
export * from './useSPFxUserPhoto';
|
|
34
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/hooks/index.ts"],"names":[],"mappings":"AAAA,cAAc,wBAAwB,CAAC;AACvC,cAAc,wBAAwB,CAAC;AACvC,cAAc,wBAAwB,CAAC;AACvC,cAAc,0BAA0B,CAAC;AACzC,cAAc,+BAA+B,CAAC;AAC9C,cAAc,sBAAsB,CAAC;AACrC,cAAc,0BAA0B,CAAC;AACzC,cAAc,2BAA2B,CAAC;AAC1C,cAAc,sBAAsB,CAAC;AACrC,cAAc,uBAAuB,CAAC;AACtC,cAAc,mBAAmB,CAAC;AAClC,cAAc,qBAAqB,CAAC;AACpC,cAAc,iBAAiB,CAAC;AAChC,cAAc,wBAAwB,CAAC;AACvC,cAAc,0BAA0B,CAAC;AACzC,cAAc,sBAAsB,CAAC;AACrC,cAAc,mBAAmB,CAAC;AAClC,cAAc,sBAAsB,CAAC;AACrC,cAAc,sBAAsB,CAAC;AACrC,cAAc,cAAc,CAAC;AAC7B,cAAc,qBAAqB,CAAC;AACpC,cAAc,kBAAkB,CAAC;AACjC,cAAc,oBAAoB,CAAC;AACnC,cAAc,qBAAqB,CAAC;AACpC,cAAc,uBAAuB,CAAC;AACtC,cAAc,uBAAuB,CAAC;AACtC,cAAc,mBAAmB,CAAC;AAClC,cAAc,kBAAkB,CAAC;AACjC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,yBAAyB,CAAC;AACxC,cAAc,oBAAoB,CAAC;AACnC,cAAc,mBAAmB,CAAC;AAClC,cAAc,oBAAoB,CAAC"}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
export * from './useSPFxAadHttpClient';
|
|
2
|
+
export * from './useSPFxContainerInfo';
|
|
3
|
+
export * from './useSPFxContainerSize';
|
|
4
|
+
export * from './useSPFxCorrelationInfo';
|
|
5
|
+
export * from './useSPFxCrossSitePermissions';
|
|
6
|
+
export * from './useSPFxDisplayMode';
|
|
7
|
+
export * from './useSPFxEnvironmentInfo';
|
|
8
|
+
export * from './useSPFxFluent9ThemeInfo';
|
|
9
|
+
export * from './useSPFxHubSiteInfo';
|
|
10
|
+
export * from './useSPFxInstanceInfo';
|
|
11
|
+
export * from './useSPFxListInfo';
|
|
12
|
+
export * from './useSPFxLocaleInfo';
|
|
13
|
+
export * from './useSPFxLogger';
|
|
14
|
+
export * from './useSPFxMSGraphClient';
|
|
15
|
+
export * from './useSPFxOneDriveAppData';
|
|
16
|
+
export * from './useSPFxPageContext';
|
|
17
|
+
export * from './useSPFxPageType';
|
|
18
|
+
export * from './useSPFxPerformance';
|
|
19
|
+
export * from './useSPFxPermissions';
|
|
20
|
+
export * from './useSPFxPnP';
|
|
21
|
+
export * from './useSPFxPnPContext';
|
|
22
|
+
export * from './useSPFxPnPList';
|
|
23
|
+
export * from './useSPFxPnPSearch';
|
|
24
|
+
export * from './useSPFxProperties';
|
|
25
|
+
export * from './useSPFxSPHttpClient';
|
|
26
|
+
export * from './useSPFxServiceScope';
|
|
27
|
+
export * from './useSPFxSiteInfo';
|
|
28
|
+
export * from './useSPFxStorage';
|
|
29
|
+
export * from './useSPFxTeams';
|
|
30
|
+
export * from './useSPFxTenantProperty';
|
|
31
|
+
export * from './useSPFxThemeInfo';
|
|
32
|
+
export * from './useSPFxUserInfo';
|
|
33
|
+
export * from './useSPFxUserPhoto';
|
|
34
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/hooks/index.ts"],"names":[],"mappings":"AAAA,cAAc,wBAAwB,CAAC;AACvC,cAAc,wBAAwB,CAAC;AACvC,cAAc,wBAAwB,CAAC;AACvC,cAAc,0BAA0B,CAAC;AACzC,cAAc,+BAA+B,CAAC;AAC9C,cAAc,sBAAsB,CAAC;AACrC,cAAc,0BAA0B,CAAC;AACzC,cAAc,2BAA2B,CAAC;AAC1C,cAAc,sBAAsB,CAAC;AACrC,cAAc,uBAAuB,CAAC;AACtC,cAAc,mBAAmB,CAAC;AAClC,cAAc,qBAAqB,CAAC;AACpC,cAAc,iBAAiB,CAAC;AAChC,cAAc,wBAAwB,CAAC;AACvC,cAAc,0BAA0B,CAAC;AACzC,cAAc,sBAAsB,CAAC;AACrC,cAAc,mBAAmB,CAAC;AAClC,cAAc,sBAAsB,CAAC;AACrC,cAAc,sBAAsB,CAAC;AACrC,cAAc,cAAc,CAAC;AAC7B,cAAc,qBAAqB,CAAC;AACpC,cAAc,kBAAkB,CAAC;AACjC,cAAc,oBAAoB,CAAC;AACnC,cAAc,qBAAqB,CAAC;AACpC,cAAc,uBAAuB,CAAC;AACtC,cAAc,uBAAuB,CAAC;AACtC,cAAc,mBAAmB,CAAC;AAClC,cAAc,kBAAkB,CAAC;AACjC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,yBAAyB,CAAC;AACxC,cAAc,oBAAoB,CAAC;AACnC,cAAc,mBAAmB,CAAC;AAClC,cAAc,oBAAoB,CAAC"}
|
|
@@ -0,0 +1,231 @@
|
|
|
1
|
+
import type { AadHttpClient } from '@microsoft/sp-http';
|
|
2
|
+
/**
|
|
3
|
+
* Return type for useSPFxAadHttpClient hook
|
|
4
|
+
*/
|
|
5
|
+
export interface SPFxAadHttpClientInfo {
|
|
6
|
+
/**
|
|
7
|
+
* Native AadHttpClient from SPFx.
|
|
8
|
+
* Provides access to Azure AD-secured APIs with built-in authentication.
|
|
9
|
+
* Undefined until resourceUrl is set and client initialization completes.
|
|
10
|
+
*/
|
|
11
|
+
readonly client: AadHttpClient | undefined;
|
|
12
|
+
/**
|
|
13
|
+
* Invoke Azure AD API call with automatic state management.
|
|
14
|
+
* Tracks loading state and captures errors automatically.
|
|
15
|
+
*
|
|
16
|
+
* @param fn - Function that receives AadHttpClient and returns a promise
|
|
17
|
+
* @returns Promise with the result
|
|
18
|
+
*
|
|
19
|
+
* @example
|
|
20
|
+
* ```tsx
|
|
21
|
+
* const { invoke, resourceUrl } = useSPFxAadHttpClient('https://api.contoso.com');
|
|
22
|
+
*
|
|
23
|
+
* const data = await invoke(client =>
|
|
24
|
+
* client.get(`${resourceUrl}/api/orders`, AadHttpClient.configurations.v1)
|
|
25
|
+
* .then(res => res.json())
|
|
26
|
+
* );
|
|
27
|
+
* ```
|
|
28
|
+
*/
|
|
29
|
+
readonly invoke: <T>(fn: (client: AadHttpClient) => Promise<T>) => Promise<T>;
|
|
30
|
+
/**
|
|
31
|
+
* Loading state - true during invoke() calls.
|
|
32
|
+
* Does not track direct client usage.
|
|
33
|
+
*/
|
|
34
|
+
readonly isLoading: boolean;
|
|
35
|
+
/**
|
|
36
|
+
* Last error from invoke() calls.
|
|
37
|
+
* Does not capture errors from direct client usage.
|
|
38
|
+
*/
|
|
39
|
+
readonly error: Error | undefined;
|
|
40
|
+
/** Clear the current error */
|
|
41
|
+
readonly clearError: () => void;
|
|
42
|
+
/** Set or change the resource URL (triggers client re-initialization) */
|
|
43
|
+
readonly setResourceUrl: (url: string) => void;
|
|
44
|
+
/** Current Azure AD resource URL or App ID */
|
|
45
|
+
readonly resourceUrl: string | undefined;
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* Hook to access Azure AD-secured APIs with built-in state management
|
|
49
|
+
*
|
|
50
|
+
* Provides native AadHttpClient for authenticated Azure AD-secured API access.
|
|
51
|
+
* Offers two usage patterns:
|
|
52
|
+
*
|
|
53
|
+
* 1. **invoke()** - Automatic state management (loading + error tracking)
|
|
54
|
+
* 2. **client** - Direct access for full control
|
|
55
|
+
*
|
|
56
|
+
* For type safety, import SPFx types:
|
|
57
|
+
* ```typescript
|
|
58
|
+
* import type { AadHttpClient } from '@microsoft/sp-http';
|
|
59
|
+
* ```
|
|
60
|
+
*
|
|
61
|
+
* Requirements:
|
|
62
|
+
* - Add permissions to package-solution.json webApiPermissionRequests
|
|
63
|
+
* - Admin must grant permissions in SharePoint Admin Center
|
|
64
|
+
* - AadHttpClientFactory available in SPFx context
|
|
65
|
+
*
|
|
66
|
+
* @param initialResourceUrl - Azure AD resource URL or App ID (optional, can be set later)
|
|
67
|
+
*
|
|
68
|
+
* @example Using invoke with state management
|
|
69
|
+
* ```tsx
|
|
70
|
+
* function OrdersList() {
|
|
71
|
+
* const { invoke, isLoading, error, clearError, resourceUrl } = useSPFxAadHttpClient(
|
|
72
|
+
* 'https://api.contoso.com'
|
|
73
|
+
* );
|
|
74
|
+
* const [orders, setOrders] = useState<Order[]>([]);
|
|
75
|
+
*
|
|
76
|
+
* const loadOrders = () => {
|
|
77
|
+
* invoke(client =>
|
|
78
|
+
* client.get(
|
|
79
|
+
* `${resourceUrl}/api/orders`,
|
|
80
|
+
* AadHttpClient.configurations.v1
|
|
81
|
+
* ).then(res => res.json())
|
|
82
|
+
* ).then(data => setOrders(data));
|
|
83
|
+
* };
|
|
84
|
+
*
|
|
85
|
+
* useEffect(() => { loadOrders(); }, []);
|
|
86
|
+
*
|
|
87
|
+
* if (isLoading) return <Spinner />;
|
|
88
|
+
* if (error) return (
|
|
89
|
+
* <MessageBar messageBarType={MessageBarType.error}>
|
|
90
|
+
* {error.message}
|
|
91
|
+
* <Link onClick={() => { clearError(); loadOrders(); }}>Retry</Link>
|
|
92
|
+
* </MessageBar>
|
|
93
|
+
* );
|
|
94
|
+
*
|
|
95
|
+
* return <ul>{orders.map(o => <li key={o.id}>{o.total}</li>)}</ul>;
|
|
96
|
+
* }
|
|
97
|
+
* ```
|
|
98
|
+
*
|
|
99
|
+
* @example Using client directly for advanced control
|
|
100
|
+
* ```tsx
|
|
101
|
+
* import type { AadHttpClient } from '@microsoft/sp-http';
|
|
102
|
+
*
|
|
103
|
+
* function ProductsManager() {
|
|
104
|
+
* const { client, resourceUrl } = useSPFxAadHttpClient('https://api.contoso.com');
|
|
105
|
+
* const [products, setProducts] = useState([]);
|
|
106
|
+
* const [loading, setLoading] = useState(false);
|
|
107
|
+
*
|
|
108
|
+
* if (!client) return <Spinner label="Initializing AAD client..." />;
|
|
109
|
+
*
|
|
110
|
+
* const loadProducts = async () => {
|
|
111
|
+
* setLoading(true);
|
|
112
|
+
* try {
|
|
113
|
+
* const response = await client.get(
|
|
114
|
+
* `${resourceUrl}/api/products`,
|
|
115
|
+
* AadHttpClient.configurations.v1
|
|
116
|
+
* );
|
|
117
|
+
* const data = await response.json();
|
|
118
|
+
* setProducts(data);
|
|
119
|
+
* } catch (err) {
|
|
120
|
+
* console.error(err);
|
|
121
|
+
* } finally {
|
|
122
|
+
* setLoading(false);
|
|
123
|
+
* }
|
|
124
|
+
* };
|
|
125
|
+
*
|
|
126
|
+
* return (
|
|
127
|
+
* <>
|
|
128
|
+
* <button onClick={loadProducts} disabled={loading}>Load</button>
|
|
129
|
+
* {loading && <Spinner />}
|
|
130
|
+
* <DetailsList items={products} />
|
|
131
|
+
* </>
|
|
132
|
+
* );
|
|
133
|
+
* }
|
|
134
|
+
* ```
|
|
135
|
+
*
|
|
136
|
+
* @example CRUD operations with invoke
|
|
137
|
+
* ```tsx
|
|
138
|
+
* function ItemsManager() {
|
|
139
|
+
* const { invoke, isLoading, error, resourceUrl } = useSPFxAadHttpClient(
|
|
140
|
+
* 'https://api.contoso.com'
|
|
141
|
+
* );
|
|
142
|
+
* const [items, setItems] = useState([]);
|
|
143
|
+
*
|
|
144
|
+
* const loadItems = () => {
|
|
145
|
+
* invoke(client =>
|
|
146
|
+
* client.get(
|
|
147
|
+
* `${resourceUrl}/api/items`,
|
|
148
|
+
* AadHttpClient.configurations.v1
|
|
149
|
+
* ).then(res => res.json())
|
|
150
|
+
* ).then(data => setItems(data));
|
|
151
|
+
* };
|
|
152
|
+
*
|
|
153
|
+
* const createItem = (item: any) => {
|
|
154
|
+
* invoke(client =>
|
|
155
|
+
* client.post(
|
|
156
|
+
* `${resourceUrl}/api/items`,
|
|
157
|
+
* AadHttpClient.configurations.v1,
|
|
158
|
+
* { body: JSON.stringify(item) }
|
|
159
|
+
* ).then(res => res.json())
|
|
160
|
+
* ).then(loadItems);
|
|
161
|
+
* };
|
|
162
|
+
*
|
|
163
|
+
* const updateItem = (id: string, changes: any) => {
|
|
164
|
+
* invoke(client =>
|
|
165
|
+
* client.post(
|
|
166
|
+
* `${resourceUrl}/api/items/${id}`,
|
|
167
|
+
* AadHttpClient.configurations.v1,
|
|
168
|
+
* {
|
|
169
|
+
* headers: { 'X-HTTP-Method': 'PATCH' },
|
|
170
|
+
* body: JSON.stringify(changes)
|
|
171
|
+
* }
|
|
172
|
+
* )
|
|
173
|
+
* ).then(loadItems);
|
|
174
|
+
* };
|
|
175
|
+
*
|
|
176
|
+
* const deleteItem = (id: string) => {
|
|
177
|
+
* invoke(client =>
|
|
178
|
+
* client.post(
|
|
179
|
+
* `${resourceUrl}/api/items/${id}`,
|
|
180
|
+
* AadHttpClient.configurations.v1,
|
|
181
|
+
* { headers: { 'X-HTTP-Method': 'DELETE' } }
|
|
182
|
+
* )
|
|
183
|
+
* ).then(loadItems);
|
|
184
|
+
* };
|
|
185
|
+
*
|
|
186
|
+
* return (
|
|
187
|
+
* <ItemsUI
|
|
188
|
+
* items={items}
|
|
189
|
+
* loading={isLoading}
|
|
190
|
+
* error={error}
|
|
191
|
+
* onCreate={createItem}
|
|
192
|
+
* onUpdate={updateItem}
|
|
193
|
+
* onDelete={deleteItem}
|
|
194
|
+
* />
|
|
195
|
+
* );
|
|
196
|
+
* }
|
|
197
|
+
* ```
|
|
198
|
+
*
|
|
199
|
+
* @example Lazy initialization with setResourceUrl
|
|
200
|
+
* ```tsx
|
|
201
|
+
* function DynamicApi() {
|
|
202
|
+
* const { invoke, setResourceUrl, resourceUrl, clearError } = useSPFxAadHttpClient();
|
|
203
|
+
* const [data, setData] = useState(null);
|
|
204
|
+
*
|
|
205
|
+
* const loadFromApi = async (apiUrl: string) => {
|
|
206
|
+
* clearError();
|
|
207
|
+
* setResourceUrl(apiUrl);
|
|
208
|
+
*
|
|
209
|
+
* // Wait for client initialization, then fetch
|
|
210
|
+
* setTimeout(() => {
|
|
211
|
+
* invoke(client =>
|
|
212
|
+
* client.get(
|
|
213
|
+
* `${apiUrl}/api/data`,
|
|
214
|
+
* AadHttpClient.configurations.v1
|
|
215
|
+
* ).then(res => res.json())
|
|
216
|
+
* ).then(setData);
|
|
217
|
+
* }, 100);
|
|
218
|
+
* };
|
|
219
|
+
*
|
|
220
|
+
* return (
|
|
221
|
+
* <>
|
|
222
|
+
* <button onClick={() => loadFromApi('https://api1.contoso.com')}>API 1</button>
|
|
223
|
+
* <button onClick={() => loadFromApi('https://api2.contoso.com')}>API 2</button>
|
|
224
|
+
* {data && <pre>{JSON.stringify(data, null, 2)}</pre>}
|
|
225
|
+
* </>
|
|
226
|
+
* );
|
|
227
|
+
* }
|
|
228
|
+
* ```
|
|
229
|
+
*/
|
|
230
|
+
export declare function useSPFxAadHttpClient(initialResourceUrl?: string): SPFxAadHttpClientInfo;
|
|
231
|
+
//# sourceMappingURL=useSPFxAadHttpClient.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useSPFxAadHttpClient.d.ts","sourceRoot":"","sources":["../../src/hooks/useSPFxAadHttpClient.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AAExD;;GAEG;AACH,MAAM,WAAW,qBAAqB;IACpC;;;;OAIG;IACH,QAAQ,CAAC,MAAM,EAAE,aAAa,GAAG,SAAS,CAAC;IAE3C;;;;;;;;;;;;;;;;OAgBG;IACH,QAAQ,CAAC,MAAM,EAAE,CAAC,CAAC,EAAE,EAAE,EAAE,CAAC,MAAM,EAAE,aAAa,KAAK,OAAO,CAAC,CAAC,CAAC,KAAK,OAAO,CAAC,CAAC,CAAC,CAAC;IAE9E;;;OAGG;IACH,QAAQ,CAAC,SAAS,EAAE,OAAO,CAAC;IAE5B;;;OAGG;IACH,QAAQ,CAAC,KAAK,EAAE,KAAK,GAAG,SAAS,CAAC;IAElC,8BAA8B;IAC9B,QAAQ,CAAC,UAAU,EAAE,MAAM,IAAI,CAAC;IAEhC,yEAAyE;IACzE,QAAQ,CAAC,cAAc,EAAE,CAAC,GAAG,EAAE,MAAM,KAAK,IAAI,CAAC;IAE/C,8CAA8C;IAC9C,QAAQ,CAAC,WAAW,EAAE,MAAM,GAAG,SAAS,CAAC;CAC1C;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAsLG;AACH,wBAAgB,oBAAoB,CAAC,kBAAkB,CAAC,EAAE,MAAM,GAAG,qBAAqB,CAiFvF"}
|