@canlooks/can-ui 0.0.106 → 0.0.107

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.
@@ -0,0 +1,13 @@
1
+ import { ReactNode } from 'react';
2
+ export type DeferredPropsWithoutValue = {
3
+ init?: ReactNode;
4
+ value?: undefined;
5
+ children?: ReactNode | ((updating: boolean, deferredValue: undefined) => ReactNode);
6
+ };
7
+ export type DeferredPropsWithValue<T> = {
8
+ init?: ReactNode;
9
+ value: T;
10
+ children?: ReactNode | ((updating: boolean, deferredValue: T) => ReactNode);
11
+ };
12
+ export declare function Deferred(props: DeferredPropsWithoutValue): ReactNode;
13
+ export declare function Deferred<T>(props: DeferredPropsWithValue<T>): ReactNode;
@@ -0,0 +1,18 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Deferred = Deferred;
4
+ const react_1 = require("react");
5
+ function Deferred({ init, value, children }) {
6
+ const [initialized, setInitialized] = (0, react_1.useState)(false);
7
+ const deferredInitialized = (0, react_1.useDeferredValue)(initialized);
8
+ (0, react_1.useEffect)(() => {
9
+ setInitialized(true);
10
+ }, []);
11
+ const deferredValue = (0, react_1.useDeferredValue)(value);
12
+ if (!deferredInitialized) {
13
+ return init;
14
+ }
15
+ return typeof children === 'function'
16
+ ? children(deferredValue !== value, deferredValue)
17
+ : children;
18
+ }
@@ -0,0 +1 @@
1
+ export * from './deferred';
@@ -0,0 +1,4 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const tslib_1 = require("tslib");
4
+ tslib_1.__exportStar(require("./deferred"), exports);
@@ -28,6 +28,7 @@ export * from './components/curd';
28
28
  export * from './components/dataGrid';
29
29
  export * from './components/dateTimePicker';
30
30
  export * from './components/dateTimeRangePicker';
31
+ export * from './components/deferred';
31
32
  export * from './components/descriptions';
32
33
  export * from './components/dialog';
33
34
  export * from './components/divider';
package/dist/cjs/index.js CHANGED
@@ -31,6 +31,7 @@ tslib_1.__exportStar(require("./components/curd"), exports);
31
31
  tslib_1.__exportStar(require("./components/dataGrid"), exports);
32
32
  tslib_1.__exportStar(require("./components/dateTimePicker"), exports);
33
33
  tslib_1.__exportStar(require("./components/dateTimeRangePicker"), exports);
34
+ tslib_1.__exportStar(require("./components/deferred"), exports);
34
35
  tslib_1.__exportStar(require("./components/descriptions"), exports);
35
36
  tslib_1.__exportStar(require("./components/dialog"), exports);
36
37
  tslib_1.__exportStar(require("./components/divider"), exports);
@@ -0,0 +1,13 @@
1
+ import { ReactNode } from 'react';
2
+ export type DeferredPropsWithoutValue = {
3
+ init?: ReactNode;
4
+ value?: undefined;
5
+ children?: ReactNode | ((updating: boolean, deferredValue: undefined) => ReactNode);
6
+ };
7
+ export type DeferredPropsWithValue<T> = {
8
+ init?: ReactNode;
9
+ value: T;
10
+ children?: ReactNode | ((updating: boolean, deferredValue: T) => ReactNode);
11
+ };
12
+ export declare function Deferred(props: DeferredPropsWithoutValue): ReactNode;
13
+ export declare function Deferred<T>(props: DeferredPropsWithValue<T>): ReactNode;
@@ -0,0 +1,15 @@
1
+ import { useDeferredValue, useEffect, useState } from 'react';
2
+ export function Deferred({ init, value, children }) {
3
+ const [initialized, setInitialized] = useState(false);
4
+ const deferredInitialized = useDeferredValue(initialized);
5
+ useEffect(() => {
6
+ setInitialized(true);
7
+ }, []);
8
+ const deferredValue = useDeferredValue(value);
9
+ if (!deferredInitialized) {
10
+ return init;
11
+ }
12
+ return typeof children === 'function'
13
+ ? children(deferredValue !== value, deferredValue)
14
+ : children;
15
+ }
@@ -0,0 +1 @@
1
+ export * from './deferred';
@@ -0,0 +1 @@
1
+ export * from './deferred';
@@ -28,6 +28,7 @@ export * from './components/curd';
28
28
  export * from './components/dataGrid';
29
29
  export * from './components/dateTimePicker';
30
30
  export * from './components/dateTimeRangePicker';
31
+ export * from './components/deferred';
31
32
  export * from './components/descriptions';
32
33
  export * from './components/dialog';
33
34
  export * from './components/divider';
package/dist/esm/index.js CHANGED
@@ -28,6 +28,7 @@ export * from './components/curd';
28
28
  export * from './components/dataGrid';
29
29
  export * from './components/dateTimePicker';
30
30
  export * from './components/dateTimeRangePicker';
31
+ export * from './components/deferred';
31
32
  export * from './components/descriptions';
32
33
  export * from './components/dialog';
33
34
  export * from './components/divider';