@plaudit/gutenberg-api-extensions 2.61.1 → 2.62.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.
|
@@ -1,10 +1,14 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { type ReactNode } from "react";
|
|
2
2
|
export type AwaitedProps<T extends object> = {
|
|
3
3
|
[K in keyof T]: Awaited<T[K]>;
|
|
4
4
|
};
|
|
5
5
|
export type PromisableComponentProps<T extends Awaited<object>> = {
|
|
6
6
|
promisedProps: T | Promise<T>;
|
|
7
|
-
initializing?: () => ReactNode;
|
|
7
|
+
initializing?: (() => ReactNode) | ReactNode;
|
|
8
8
|
renderer(props: AwaitedProps<T>): ReactNode;
|
|
9
9
|
};
|
|
10
|
-
export declare function PromisableComponent<T extends Awaited<object>>(props: PromisableComponentProps<T>):
|
|
10
|
+
export declare function PromisableComponent<T extends Awaited<object>>(props: PromisableComponentProps<T>): import("react/jsx-runtime").JSX.Element;
|
|
11
|
+
export type SuspendingResource<T> = {
|
|
12
|
+
read(): T;
|
|
13
|
+
promise: Promise<T>;
|
|
14
|
+
};
|
|
@@ -1,23 +1,48 @@
|
|
|
1
|
-
import { jsx as _jsx } from "react/jsx-runtime";
|
|
1
|
+
import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
2
|
import { Spinner } from '@wordpress/components';
|
|
3
|
-
import {
|
|
3
|
+
import { useMemo } from "@wordpress/element";
|
|
4
|
+
import { Suspense } from "react";
|
|
4
5
|
export function PromisableComponent(props) {
|
|
5
|
-
const
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
6
|
+
const promisedPropsResource = useWrappedArgsParameter(props.promisedProps);
|
|
7
|
+
return _jsx(Suspense, { fallback: typeof props.initializing === 'function' ? props.initializing() : _jsxs(_Fragment, { children: [_jsx(Spinner, {}), " ", props.initializing] }), children: _jsx(PromisableComponentDelegator, { promisedPropsResource: promisedPropsResource, children: props.renderer }) });
|
|
8
|
+
}
|
|
9
|
+
function PromisableComponentDelegator({ promisedPropsResource, children }) {
|
|
10
|
+
return children(promisedPropsResource.read());
|
|
11
|
+
}
|
|
12
|
+
function useWrappedArgsParameter(args) {
|
|
13
|
+
return useMemo(() => wrapPromise(Promise
|
|
14
|
+
.all(Object.entries(args)
|
|
15
|
+
.filter(([_, value]) => value instanceof Promise)
|
|
16
|
+
.map(async ([key, value]) => [key, await value]))
|
|
17
|
+
.then(entries => Object.fromEntries(entries))), Object.values(args));
|
|
18
|
+
}
|
|
19
|
+
function wrapPromise(promise, name) {
|
|
20
|
+
let status = 'pending';
|
|
21
|
+
let response = undefined;
|
|
22
|
+
let error = undefined;
|
|
23
|
+
const suspender = promise.then(res => {
|
|
24
|
+
status = 'success';
|
|
25
|
+
response = res;
|
|
26
|
+
}, err => {
|
|
27
|
+
status = 'error';
|
|
28
|
+
response = err;
|
|
29
|
+
});
|
|
30
|
+
return {
|
|
31
|
+
read: () => {
|
|
32
|
+
switch (status) {
|
|
33
|
+
case "success":
|
|
34
|
+
if (response === undefined) {
|
|
35
|
+
status = 'error';
|
|
36
|
+
throw error ?? (error = new Error(`Encountered a supposedly-fetched response${name ? ` for ${name}` : ''} that is still undefined`));
|
|
37
|
+
}
|
|
38
|
+
return response;
|
|
39
|
+
case "error":
|
|
40
|
+
throw error;
|
|
41
|
+
case "pending":
|
|
42
|
+
throw suspender;
|
|
43
|
+
}
|
|
44
|
+
},
|
|
45
|
+
promise
|
|
46
|
+
};
|
|
22
47
|
}
|
|
23
48
|
//# sourceMappingURL=PromisableComponent.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"PromisableComponent.js","sourceRoot":"","sources":["../../src/controls/PromisableComponent.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAC,OAAO,EAAC,MAAM,uBAAuB,CAAC;AAC9C,OAAO,EAAC,
|
|
1
|
+
{"version":3,"file":"PromisableComponent.js","sourceRoot":"","sources":["../../src/controls/PromisableComponent.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAC,OAAO,EAAC,MAAM,uBAAuB,CAAC;AAC9C,OAAO,EAAC,OAAO,EAAC,MAAM,oBAAoB,CAAC;AAE3C,OAAc,EAAC,QAAQ,EAAiB,MAAM,OAAO,CAAC;AAKtD,MAAM,UAAU,mBAAmB,CAA4B,KAAkC;IAChG,MAAM,qBAAqB,GAAG,uBAAuB,CAAC,KAAK,CAAC,aAAa,CAAC,CAAC;IAC3E,OAAO,KAAC,QAAQ,IAAC,QAAQ,EAAE,OAAO,KAAK,CAAC,YAAY,KAAK,UAAU,CAAC,CAAC,CAAC,KAAK,CAAC,YAAY,EAAE,CAAC,CAAC,CAAC,8BAAE,KAAC,OAAO,KAAG,OAAE,KAAK,CAAC,YAAY,IAAI,YACjI,KAAC,4BAA4B,IAAC,qBAAqB,EAAE,qBAAqB,EAAE,QAAQ,EAAE,KAAK,CAAC,QAAQ,GAAI,GAC9F,CAAC;AACb,CAAC;AACD,SAAS,4BAA4B,CACpC,EAAC,qBAAqB,EAAE,QAAQ,EAAgF;IAEhH,OAAO,QAAQ,CAAC,qBAAqB,CAAC,IAAI,EAAE,CAAC,CAAC;AAC/C,CAAC;AAGD,SAAS,uBAAuB,CAAe,IAAO;IACrD,OAAO,OAAO,CAAC,GAAG,EAAE,CAAC,WAAW,CAAC,OAAO;SACtC,GAAG,CAAC,MAAM,CAAC,OAAO,CAAC,IAAI,CAAC;SACvB,MAAM,CAAC,CAAC,CAAC,CAAC,EAAE,KAAK,CAAC,EAAE,EAAE,CAAC,KAAK,YAAY,OAAO,CAAC;SAChD,GAAG,CAAC,KAAK,EAAE,CAAC,GAAG,EAAE,KAAK,CAAC,EAAgD,EAAE,CAAC,CAA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