@plasmicpkgs/antd5 0.0.138 → 0.0.139
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/dist/.tsbuildinfo +1 -1
- package/dist/antd.esm.js +7142 -6818
- package/dist/antd.esm.js.map +1 -1
- package/dist/index.d.ts +1 -3
- package/dist/index.js +7141 -6817
- package/dist/index.js.map +1 -1
- package/dist/react-utils.d.ts +2 -1
- package/dist/registerForm.d.ts +2 -2
- package/dist/registerSegmented.d.ts +20 -0
- package/dist/registerTabs.d.ts +2 -6
- package/package.json +4 -4
- package/skinny/react-utils-11b0221a.cjs.js +121 -0
- package/skinny/react-utils-11b0221a.cjs.js.map +1 -0
- package/skinny/react-utils-79d444f6.esm.js +112 -0
- package/skinny/react-utils-79d444f6.esm.js.map +1 -0
- package/skinny/react-utils.d.ts +2 -1
- package/skinny/registerConfigProvider.cjs.js +42 -11
- package/skinny/registerConfigProvider.cjs.js.map +1 -1
- package/skinny/registerConfigProvider.esm.js +43 -12
- package/skinny/registerConfigProvider.esm.js.map +1 -1
- package/skinny/registerForm.cjs.js +10 -7
- package/skinny/registerForm.cjs.js.map +1 -1
- package/skinny/registerForm.d.ts +2 -2
- package/skinny/registerForm.esm.js +8 -5
- package/skinny/registerForm.esm.js.map +1 -1
- package/skinny/registerSegmented.cjs.js +314 -0
- package/skinny/registerSegmented.cjs.js.map +1 -0
- package/skinny/registerSegmented.d.ts +20 -0
- package/skinny/registerSegmented.esm.js +304 -0
- package/skinny/registerSegmented.esm.js.map +1 -0
- package/skinny/registerSelect.cjs.js +372 -11
- package/skinny/registerSelect.cjs.js.map +1 -1
- package/skinny/registerSelect.esm.js +365 -4
- package/skinny/registerSelect.esm.js.map +1 -1
- package/skinny/registerTabs.cjs.js +21 -36
- package/skinny/registerTabs.cjs.js.map +1 -1
- package/skinny/registerTabs.d.ts +2 -6
- package/skinny/registerTabs.esm.js +21 -36
- package/skinny/registerTabs.esm.js.map +1 -1
package/dist/react-utils.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import React from "react";
|
|
2
2
|
export declare const isBrowser: boolean;
|
|
3
3
|
export declare const NONE: unique symbol;
|
|
4
|
-
export declare const useIsomorphicLayoutEffect: typeof React.
|
|
4
|
+
export declare const useIsomorphicLayoutEffect: typeof React.useLayoutEffect;
|
|
5
5
|
export declare function createElementWithChildren(elementType: any, props: any, children: React.ReactNode): React.ReactElement<any, string | React.JSXElementConstructor<any>>;
|
|
6
6
|
export declare function ensureNotArray(children: React.ReactNode): any;
|
|
7
7
|
/**
|
|
@@ -20,3 +20,4 @@ export declare function mergeRefs<T>(...refs: (React.Ref<T> | undefined)[]): (va
|
|
|
20
20
|
export declare function mergePropVals(name: string, val1: any, val2: any): any;
|
|
21
21
|
export declare function getElementTypeName(element: React.ReactElement): any;
|
|
22
22
|
export declare function reactNodeToString(reactNode: React.ReactNode): string;
|
|
23
|
+
export declare function useIsMounted(): () => boolean;
|
package/dist/registerForm.d.ts
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
|
+
import { DataOp, TableSchema } from "@plasmicapp/data-sources";
|
|
1
2
|
import { CodeComponentMode, ComponentHelpers } from "@plasmicapp/host";
|
|
3
|
+
import { CanvasComponentProps } from "@plasmicapp/host/registerComponent";
|
|
2
4
|
import { Form } from "antd";
|
|
3
5
|
import type { FormInstance, FormProps } from "antd/es/form";
|
|
4
6
|
import type { FormItemProps } from "antd/es/form/FormItem";
|
|
5
7
|
import type { FormListOperation, FormListProps } from "antd/es/form/FormList";
|
|
6
8
|
import React from "react";
|
|
7
9
|
import { Registerable } from "./utils";
|
|
8
|
-
import { CanvasComponentProps } from "@plasmicapp/host/registerComponent";
|
|
9
|
-
import { TableSchema, DataOp } from "@plasmicapp/data-sources";
|
|
10
10
|
export interface InternalFormItemProps extends Omit<FormItemProps, "rules"> {
|
|
11
11
|
rules?: PlasmicRule[];
|
|
12
12
|
noLabel?: boolean;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { Segmented } from "antd";
|
|
2
|
+
import React, { ReactElement } from "react";
|
|
3
|
+
import { Registerable } from "./utils";
|
|
4
|
+
export type AntdSegmentedOptionProps = {
|
|
5
|
+
value: string;
|
|
6
|
+
children: React.ReactNode;
|
|
7
|
+
};
|
|
8
|
+
export type AntdSegmentedProps = Omit<React.ComponentProps<typeof Segmented>, "options"> & {
|
|
9
|
+
options?: {
|
|
10
|
+
label: string;
|
|
11
|
+
value: string;
|
|
12
|
+
}[];
|
|
13
|
+
optionsSlot?: ReactElement;
|
|
14
|
+
useSlotOptions: boolean;
|
|
15
|
+
};
|
|
16
|
+
export declare function AntdSegmented(props: AntdSegmentedProps): React.JSX.Element;
|
|
17
|
+
export declare function AntdSegmentedOption(props: AntdSegmentedOptionProps): React.JSX.Element;
|
|
18
|
+
export declare const segmentedComponentName = "plasmic-antd5-segmented";
|
|
19
|
+
export declare const segmentedOptionComponentName = "plasmic-antd5-segmented-option";
|
|
20
|
+
export declare function registerSegmented(loader?: Registerable): void;
|
package/dist/registerTabs.d.ts
CHANGED
|
@@ -1,16 +1,12 @@
|
|
|
1
1
|
import { Tabs } from "antd";
|
|
2
|
-
import React from "react";
|
|
2
|
+
import React, { ReactElement } from "react";
|
|
3
3
|
import { Registerable } from "./utils";
|
|
4
4
|
export declare const tabsComponentName = "plasmic-antd5-tabs";
|
|
5
5
|
export declare const tabItemComponentName = "plasmic-antd5-tab-item";
|
|
6
6
|
type TabItemType = NonNullable<React.ComponentProps<typeof Tabs>["items"]>[number];
|
|
7
7
|
export declare const AntdTabItem: React.FC<TabItemType>;
|
|
8
8
|
type TabsProps = Omit<React.ComponentProps<typeof Tabs>, "items" | "animated" | "tabBarExtraContent" | "renderTabBar"> & {
|
|
9
|
-
items:
|
|
10
|
-
props: {
|
|
11
|
-
children: React.ReactElement<TabItemType>[];
|
|
12
|
-
};
|
|
13
|
-
} | React.ReactElement<TabItemType>;
|
|
9
|
+
items: ReactElement;
|
|
14
10
|
animated: boolean;
|
|
15
11
|
animateTabBar: boolean;
|
|
16
12
|
animateTabContent: boolean;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@plasmicpkgs/antd5",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.139",
|
|
4
4
|
"description": "Plasmic registration calls for antd components",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -62,10 +62,10 @@
|
|
|
62
62
|
"@babel/preset-env": "^7.22.15",
|
|
63
63
|
"@babel/preset-react": "^7.22.15",
|
|
64
64
|
"@babel/preset-typescript": "^7.22.15",
|
|
65
|
-
"@plasmicapp/data-sources": "0.1.
|
|
65
|
+
"@plasmicapp/data-sources": "0.1.120",
|
|
66
66
|
"@plasmicapp/host": "1.0.168",
|
|
67
67
|
"@plasmicapp/query": "0.1.70",
|
|
68
|
-
"@plasmicapp/react-web": "0.2.
|
|
68
|
+
"@plasmicapp/react-web": "0.2.264",
|
|
69
69
|
"@storybook/addon-actions": "^7.4.0",
|
|
70
70
|
"@storybook/addon-essentials": "^7.4.0",
|
|
71
71
|
"@storybook/addon-info": "^5.3.21",
|
|
@@ -99,5 +99,5 @@
|
|
|
99
99
|
"publishConfig": {
|
|
100
100
|
"access": "public"
|
|
101
101
|
},
|
|
102
|
-
"gitHead": "
|
|
102
|
+
"gitHead": "ed9053ca054f0345d29664c855003fc063aef81c"
|
|
103
103
|
}
|
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var classNames = require('classnames');
|
|
4
|
+
var React = require('react');
|
|
5
|
+
|
|
6
|
+
function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
|
|
7
|
+
|
|
8
|
+
var classNames__default = /*#__PURE__*/_interopDefault(classNames);
|
|
9
|
+
var React__default = /*#__PURE__*/_interopDefault(React);
|
|
10
|
+
|
|
11
|
+
var __defProp = Object.defineProperty;
|
|
12
|
+
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
13
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
14
|
+
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
15
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
16
|
+
var __spreadValues = (a, b) => {
|
|
17
|
+
for (var prop in b || (b = {}))
|
|
18
|
+
if (__hasOwnProp.call(b, prop))
|
|
19
|
+
__defNormalProp(a, prop, b[prop]);
|
|
20
|
+
if (__getOwnPropSymbols)
|
|
21
|
+
for (var prop of __getOwnPropSymbols(b)) {
|
|
22
|
+
if (__propIsEnum.call(b, prop))
|
|
23
|
+
__defNormalProp(a, prop, b[prop]);
|
|
24
|
+
}
|
|
25
|
+
return a;
|
|
26
|
+
};
|
|
27
|
+
const isBrowser = typeof window !== "undefined";
|
|
28
|
+
const NONE = Symbol("NONE");
|
|
29
|
+
isBrowser ? React__default.default.useLayoutEffect : React__default.default.useEffect;
|
|
30
|
+
function mergeProps(props, ...restProps) {
|
|
31
|
+
if (restProps.every((rest) => Object.keys(rest).length === 0)) {
|
|
32
|
+
return props;
|
|
33
|
+
}
|
|
34
|
+
const result = __spreadValues({}, props);
|
|
35
|
+
for (const rest of restProps) {
|
|
36
|
+
for (const key of Object.keys(rest)) {
|
|
37
|
+
result[key] = mergePropVals(key, result[key], rest[key]);
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
return result;
|
|
41
|
+
}
|
|
42
|
+
function updateRef(ref, value) {
|
|
43
|
+
if (!ref) {
|
|
44
|
+
return;
|
|
45
|
+
}
|
|
46
|
+
if (typeof ref === "function") {
|
|
47
|
+
ref(value);
|
|
48
|
+
} else {
|
|
49
|
+
if (!Object.isFrozen(ref)) {
|
|
50
|
+
ref.current = value;
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
function mergeRefs(...refs) {
|
|
55
|
+
return (value) => {
|
|
56
|
+
for (const ref of refs) {
|
|
57
|
+
updateRef(ref, value);
|
|
58
|
+
}
|
|
59
|
+
};
|
|
60
|
+
}
|
|
61
|
+
function mergePropVals(name, val1, val2) {
|
|
62
|
+
if (val1 === NONE || val2 === NONE) {
|
|
63
|
+
return null;
|
|
64
|
+
} else if (val1 == null) {
|
|
65
|
+
return val2;
|
|
66
|
+
} else if (val2 == null) {
|
|
67
|
+
return val1;
|
|
68
|
+
} else if (name === "className") {
|
|
69
|
+
return classNames__default.default(val1, val2);
|
|
70
|
+
} else if (name === "style") {
|
|
71
|
+
return __spreadValues(__spreadValues({}, val1), val2);
|
|
72
|
+
} else if (name === "ref") {
|
|
73
|
+
return mergeRefs(val1, val2);
|
|
74
|
+
} else if (typeof val1 !== typeof val2) {
|
|
75
|
+
return val2;
|
|
76
|
+
} else if (name.startsWith("on") && typeof val1 === "function") {
|
|
77
|
+
return (...args) => {
|
|
78
|
+
let res;
|
|
79
|
+
if (typeof val1 === "function") {
|
|
80
|
+
res = val1(...args);
|
|
81
|
+
}
|
|
82
|
+
if (typeof val2 === "function") {
|
|
83
|
+
res = val2(...args);
|
|
84
|
+
}
|
|
85
|
+
return res;
|
|
86
|
+
};
|
|
87
|
+
} else {
|
|
88
|
+
return val2;
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
function reactNodeToString(reactNode) {
|
|
92
|
+
let string = "";
|
|
93
|
+
if (typeof reactNode === "string") {
|
|
94
|
+
string = reactNode;
|
|
95
|
+
} else if (typeof reactNode === "number") {
|
|
96
|
+
string = reactNode.toString();
|
|
97
|
+
} else if (reactNode instanceof Array) {
|
|
98
|
+
reactNode.forEach(function(child) {
|
|
99
|
+
string += reactNodeToString(child);
|
|
100
|
+
});
|
|
101
|
+
} else if (React.isValidElement(reactNode)) {
|
|
102
|
+
string += reactNodeToString(reactNode.props.children);
|
|
103
|
+
}
|
|
104
|
+
return string;
|
|
105
|
+
}
|
|
106
|
+
function useIsMounted() {
|
|
107
|
+
const ref = React__default.default.useRef(false);
|
|
108
|
+
const isMounted = React__default.default.useCallback(() => ref.current, []);
|
|
109
|
+
React__default.default.useEffect(() => {
|
|
110
|
+
ref.current = true;
|
|
111
|
+
return () => {
|
|
112
|
+
ref.current = false;
|
|
113
|
+
};
|
|
114
|
+
}, []);
|
|
115
|
+
return isMounted;
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
exports.mergeProps = mergeProps;
|
|
119
|
+
exports.reactNodeToString = reactNodeToString;
|
|
120
|
+
exports.useIsMounted = useIsMounted;
|
|
121
|
+
//# sourceMappingURL=react-utils-11b0221a.cjs.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"react-utils-11b0221a.cjs.js","sources":["../src/react-utils.tsx"],"sourcesContent":["import classNames from \"classnames\";\nimport React, { isValidElement } from \"react\";\n\nexport const isBrowser = typeof window !== \"undefined\";\nexport const NONE = Symbol(\"NONE\");\n\nexport const useIsomorphicLayoutEffect = isBrowser\n ? React.useLayoutEffect\n : React.useEffect;\n\nexport function createElementWithChildren(\n elementType: any,\n props: any,\n children: React.ReactNode\n) {\n if (Array.isArray(children)) {\n return React.createElement(\n elementType,\n props,\n ...children\n ) as React.ReactElement;\n } else if (children || \"children\" in props) {\n // Only call React.createElement with `children` if there are actual children,\n // or if there was an explicit (albeit undefined) children passed via\n // props. Otherwise, if you pass `undefined` as the children argument\n // to React.createElement, the created element will have prop {children: undefined}.\n // If the `root` is an PlasmicGeneratedComponent, and these props with {children: undefined}\n // are used, then it will be taken as a `children` override, and will thus blank out\n // everything under the root node.\n return React.createElement(elementType, props, children);\n } else {\n return React.createElement(elementType, props);\n }\n}\n\nexport function ensureNotArray(children: React.ReactNode) {\n if (Array.isArray(children)) {\n if (children.length === 1) {\n return children[0];\n } else {\n return React.createElement(React.Fragment, {}, ...children);\n }\n } else {\n return children;\n }\n}\n\n/**\n * Flattens ReactNode into an array of ReactChild, but does NOT replace\n * missing keys with array index, as React.Children.toArray() does.\n */\nexport function toChildArray(children: React.ReactNode): React.ReactChild[] {\n if (isReactChild(children)) {\n return [children];\n } else if (Array.isArray(children)) {\n return children.flatMap(toChildArray);\n } else {\n return [];\n }\n}\n\nexport function isReactText(child: React.ReactNode): child is React.ReactText {\n return typeof child === \"string\" || typeof child === \"number\";\n}\n\nexport function isReactChild(\n child: React.ReactNode\n): child is React.ReactChild {\n return React.isValidElement(child) || isReactText(child);\n}\n\nexport function isReactFragment(\n child: React.ReactNode\n): child is React.ReactElement {\n return React.isValidElement(child) && child.type === React.Fragment;\n}\n\nexport function isReactNode(x: any) {\n return (\n typeof x === \"string\" || typeof x === \"number\" || React.isValidElement(x)\n );\n}\n\n// From https://stackoverflow.com/questions/54775790/forcing-excess-property-checking-on-variable-passed-to-typescript-function\n// We also wrap the error message in a Partial<> because otherwise Jetbrains IDEs will autocomplete the component with all the string methods as props - see https://github.com/plasmicapp/plasmic/issues/16.\nexport type StrictProps<T, TExpected> = Exclude<\n keyof T,\n keyof TExpected\n> extends never\n ? any\n : Partial<\"Unexpected extraneous props\">;\n\nexport type HTMLElementRefOf<T extends keyof JSX.IntrinsicElements> = Exclude<\n React.ComponentProps<T>[\"ref\"],\n string\n>;\n\nexport function mergeProps(\n props: Record<string, any>,\n ...restProps: Record<string, any>[]\n): Record<string, any> {\n if (restProps.every((rest) => Object.keys(rest).length === 0)) {\n return props;\n }\n\n const result = { ...props };\n\n for (const rest of restProps) {\n for (const key of Object.keys(rest)) {\n result[key] = mergePropVals(key, result[key], rest[key]);\n }\n }\n\n return result;\n}\n\nfunction updateRef<T>(ref: React.Ref<T> | undefined, value: T | null) {\n if (!ref) {\n return;\n }\n\n if (typeof ref === \"function\") {\n ref(value);\n } else {\n if (!Object.isFrozen(ref)) {\n (ref as React.MutableRefObject<T | null>).current = value;\n }\n }\n}\n\nexport function mergeRefs<T>(...refs: (React.Ref<T> | undefined)[]) {\n return (value: T) => {\n for (const ref of refs) {\n updateRef(ref, value);\n }\n };\n}\n\nexport function mergePropVals(name: string, val1: any, val2: any): any {\n if (val1 === NONE || val2 === NONE) {\n // The NONE sentinel always skips all merging and returns null\n return null;\n } else if (val1 == null) {\n // If either of them is nil, prefer the other\n return val2;\n } else if (val2 == null) {\n return val1;\n } else if (name === \"className\") {\n // Special case for className -- always combine both class names\n return classNames(val1, val2);\n } else if (name === \"style\") {\n // Special case for style -- always shallow-merge style dicts\n return { ...val1, ...val2 };\n } else if (name === \"ref\") {\n // Special case for ref\n return mergeRefs(val1, val2);\n } else if (typeof val1 !== typeof val2) {\n // If the type of the two values are different, then no way to merge them.\n // Prefer val2.\n return val2;\n } else if (name.startsWith(\"on\") && typeof val1 === \"function\") {\n // Special case for event handlers -- always call both handlers\n return (...args: any[]) => {\n let res: any;\n if (typeof val1 === \"function\") {\n res = val1(...args);\n }\n if (typeof val2 === \"function\") {\n res = val2(...args);\n }\n return res;\n };\n } else {\n // For all else, prefer val2\n return val2;\n }\n}\n\nexport function getElementTypeName(element: React.ReactElement) {\n if (typeof element.type === \"string\") {\n return element.type;\n } else {\n const comp = element.type as any;\n return comp.displayName ?? comp.name ?? comp.render?.name ?? \"Component\";\n }\n}\n\nexport function reactNodeToString(reactNode: React.ReactNode): string {\n let string = \"\";\n if (typeof reactNode === \"string\") {\n string = reactNode;\n } else if (typeof reactNode === \"number\") {\n string = reactNode.toString();\n } else if (reactNode instanceof Array) {\n reactNode.forEach(function (child) {\n string += reactNodeToString(child);\n });\n } else if (isValidElement(reactNode)) {\n string += reactNodeToString(reactNode.props.children);\n }\n return string;\n}\n\nexport function useIsMounted(): () => boolean {\n const ref = React.useRef<boolean>(false);\n const isMounted = React.useCallback(() => ref.current, []);\n\n React.useEffect(() => {\n ref.current = true;\n return () => {\n ref.current = false;\n };\n }, []);\n\n return isMounted;\n}\n"],"names":["React","classNames","isValidElement"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAGa,MAAA,SAAA,GAAY,OAAO,MAAW,KAAA,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kBAAkB,SAAoC,EAAA;AACpE,EAAA,IAAI,MAAS,GAAA,EAAA,CAAA;AACb,EAAI,IAAA,OAAO,cAAc,QAAU,EAAA;AACjC,IAAS,MAAA,GAAA,SAAA,CAAA;AAAA,GACX,MAAA,IAAW,OAAO,SAAA,KAAc,QAAU,EAAA;AACxC,IAAA,MAAA,GAAS,UAAU,QAAS,EAAA,CAAA;AAAA,GAC9B,MAAA,IAAW,qBAAqB,KAAO,EAAA;AACrC,IAAU,SAAA,CAAA,OAAA,CAAQ,SAAU,KAAO,EAAA;AACjC,MAAA,MAAA,IAAU,kBAAkB,KAAK,CAAA,CAAA;AAAA,KAClC,CAAA,CAAA;AAAA,GACH,MAAA,IAAWC,oBAAe,CAAA,SAAS,CAAG,EAAA;AACpC,IAAU,MAAA,IAAA,iBAAA,CAAkB,SAAU,CAAA,KAAA,CAAM,QAAQ,CAAA,CAAA;AAAA,GACtD;AACA,EAAO,OAAA,MAAA,CAAA;AACT,CAAA;AAEO,SAAS,YAA8B,GAAA;AAC5C,EAAM,MAAA,GAAA,GAAMF,sBAAM,CAAA,MAAA,CAAgB,KAAK,CAAA,CAAA;AACvC,EAAA,MAAM,YAAYA,sBAAM,CAAA,WAAA,CAAY,MAAM,GAAI,CAAA,OAAA,EAAS,EAAE,CAAA,CAAA;AAEzD,EAAAA,sBAAA,CAAM,UAAU,MAAM;AACpB,IAAA,GAAA,CAAI,OAAU,GAAA,IAAA,CAAA;AACd,IAAA,OAAO,MAAM;AACX,MAAA,GAAA,CAAI,OAAU,GAAA,KAAA,CAAA;AAAA,KAChB,CAAA;AAAA,GACF,EAAG,EAAE,CAAA,CAAA;AAEL,EAAO,OAAA,SAAA,CAAA;AACT;;;;;;"}
|
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
import classNames from 'classnames';
|
|
2
|
+
import React, { isValidElement } from 'react';
|
|
3
|
+
|
|
4
|
+
var __defProp = Object.defineProperty;
|
|
5
|
+
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
6
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
+
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
8
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
9
|
+
var __spreadValues = (a, b) => {
|
|
10
|
+
for (var prop in b || (b = {}))
|
|
11
|
+
if (__hasOwnProp.call(b, prop))
|
|
12
|
+
__defNormalProp(a, prop, b[prop]);
|
|
13
|
+
if (__getOwnPropSymbols)
|
|
14
|
+
for (var prop of __getOwnPropSymbols(b)) {
|
|
15
|
+
if (__propIsEnum.call(b, prop))
|
|
16
|
+
__defNormalProp(a, prop, b[prop]);
|
|
17
|
+
}
|
|
18
|
+
return a;
|
|
19
|
+
};
|
|
20
|
+
const isBrowser = typeof window !== "undefined";
|
|
21
|
+
const NONE = Symbol("NONE");
|
|
22
|
+
isBrowser ? React.useLayoutEffect : React.useEffect;
|
|
23
|
+
function mergeProps(props, ...restProps) {
|
|
24
|
+
if (restProps.every((rest) => Object.keys(rest).length === 0)) {
|
|
25
|
+
return props;
|
|
26
|
+
}
|
|
27
|
+
const result = __spreadValues({}, props);
|
|
28
|
+
for (const rest of restProps) {
|
|
29
|
+
for (const key of Object.keys(rest)) {
|
|
30
|
+
result[key] = mergePropVals(key, result[key], rest[key]);
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
return result;
|
|
34
|
+
}
|
|
35
|
+
function updateRef(ref, value) {
|
|
36
|
+
if (!ref) {
|
|
37
|
+
return;
|
|
38
|
+
}
|
|
39
|
+
if (typeof ref === "function") {
|
|
40
|
+
ref(value);
|
|
41
|
+
} else {
|
|
42
|
+
if (!Object.isFrozen(ref)) {
|
|
43
|
+
ref.current = value;
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
function mergeRefs(...refs) {
|
|
48
|
+
return (value) => {
|
|
49
|
+
for (const ref of refs) {
|
|
50
|
+
updateRef(ref, value);
|
|
51
|
+
}
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
function mergePropVals(name, val1, val2) {
|
|
55
|
+
if (val1 === NONE || val2 === NONE) {
|
|
56
|
+
return null;
|
|
57
|
+
} else if (val1 == null) {
|
|
58
|
+
return val2;
|
|
59
|
+
} else if (val2 == null) {
|
|
60
|
+
return val1;
|
|
61
|
+
} else if (name === "className") {
|
|
62
|
+
return classNames(val1, val2);
|
|
63
|
+
} else if (name === "style") {
|
|
64
|
+
return __spreadValues(__spreadValues({}, val1), val2);
|
|
65
|
+
} else if (name === "ref") {
|
|
66
|
+
return mergeRefs(val1, val2);
|
|
67
|
+
} else if (typeof val1 !== typeof val2) {
|
|
68
|
+
return val2;
|
|
69
|
+
} else if (name.startsWith("on") && typeof val1 === "function") {
|
|
70
|
+
return (...args) => {
|
|
71
|
+
let res;
|
|
72
|
+
if (typeof val1 === "function") {
|
|
73
|
+
res = val1(...args);
|
|
74
|
+
}
|
|
75
|
+
if (typeof val2 === "function") {
|
|
76
|
+
res = val2(...args);
|
|
77
|
+
}
|
|
78
|
+
return res;
|
|
79
|
+
};
|
|
80
|
+
} else {
|
|
81
|
+
return val2;
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
function reactNodeToString(reactNode) {
|
|
85
|
+
let string = "";
|
|
86
|
+
if (typeof reactNode === "string") {
|
|
87
|
+
string = reactNode;
|
|
88
|
+
} else if (typeof reactNode === "number") {
|
|
89
|
+
string = reactNode.toString();
|
|
90
|
+
} else if (reactNode instanceof Array) {
|
|
91
|
+
reactNode.forEach(function(child) {
|
|
92
|
+
string += reactNodeToString(child);
|
|
93
|
+
});
|
|
94
|
+
} else if (isValidElement(reactNode)) {
|
|
95
|
+
string += reactNodeToString(reactNode.props.children);
|
|
96
|
+
}
|
|
97
|
+
return string;
|
|
98
|
+
}
|
|
99
|
+
function useIsMounted() {
|
|
100
|
+
const ref = React.useRef(false);
|
|
101
|
+
const isMounted = React.useCallback(() => ref.current, []);
|
|
102
|
+
React.useEffect(() => {
|
|
103
|
+
ref.current = true;
|
|
104
|
+
return () => {
|
|
105
|
+
ref.current = false;
|
|
106
|
+
};
|
|
107
|
+
}, []);
|
|
108
|
+
return isMounted;
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
export { mergeProps as m, reactNodeToString as r, useIsMounted as u };
|
|
112
|
+
//# sourceMappingURL=react-utils-79d444f6.esm.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"react-utils-79d444f6.esm.js","sources":["../src/react-utils.tsx"],"sourcesContent":["import classNames from \"classnames\";\nimport React, { isValidElement } from \"react\";\n\nexport const isBrowser = typeof window !== \"undefined\";\nexport const NONE = Symbol(\"NONE\");\n\nexport const useIsomorphicLayoutEffect = isBrowser\n ? React.useLayoutEffect\n : React.useEffect;\n\nexport function createElementWithChildren(\n elementType: any,\n props: any,\n children: React.ReactNode\n) {\n if (Array.isArray(children)) {\n return React.createElement(\n elementType,\n props,\n ...children\n ) as React.ReactElement;\n } else if (children || \"children\" in props) {\n // Only call React.createElement with `children` if there are actual children,\n // or if there was an explicit (albeit undefined) children passed via\n // props. Otherwise, if you pass `undefined` as the children argument\n // to React.createElement, the created element will have prop {children: undefined}.\n // If the `root` is an PlasmicGeneratedComponent, and these props with {children: undefined}\n // are used, then it will be taken as a `children` override, and will thus blank out\n // everything under the root node.\n return React.createElement(elementType, props, children);\n } else {\n return React.createElement(elementType, props);\n }\n}\n\nexport function ensureNotArray(children: React.ReactNode) {\n if (Array.isArray(children)) {\n if (children.length === 1) {\n return children[0];\n } else {\n return React.createElement(React.Fragment, {}, ...children);\n }\n } else {\n return children;\n }\n}\n\n/**\n * Flattens ReactNode into an array of ReactChild, but does NOT replace\n * missing keys with array index, as React.Children.toArray() does.\n */\nexport function toChildArray(children: React.ReactNode): React.ReactChild[] {\n if (isReactChild(children)) {\n return [children];\n } else if (Array.isArray(children)) {\n return children.flatMap(toChildArray);\n } else {\n return [];\n }\n}\n\nexport function isReactText(child: React.ReactNode): child is React.ReactText {\n return typeof child === \"string\" || typeof child === \"number\";\n}\n\nexport function isReactChild(\n child: React.ReactNode\n): child is React.ReactChild {\n return React.isValidElement(child) || isReactText(child);\n}\n\nexport function isReactFragment(\n child: React.ReactNode\n): child is React.ReactElement {\n return React.isValidElement(child) && child.type === React.Fragment;\n}\n\nexport function isReactNode(x: any) {\n return (\n typeof x === \"string\" || typeof x === \"number\" || React.isValidElement(x)\n );\n}\n\n// From https://stackoverflow.com/questions/54775790/forcing-excess-property-checking-on-variable-passed-to-typescript-function\n// We also wrap the error message in a Partial<> because otherwise Jetbrains IDEs will autocomplete the component with all the string methods as props - see https://github.com/plasmicapp/plasmic/issues/16.\nexport type StrictProps<T, TExpected> = Exclude<\n keyof T,\n keyof TExpected\n> extends never\n ? any\n : Partial<\"Unexpected extraneous props\">;\n\nexport type HTMLElementRefOf<T extends keyof JSX.IntrinsicElements> = Exclude<\n React.ComponentProps<T>[\"ref\"],\n string\n>;\n\nexport function mergeProps(\n props: Record<string, any>,\n ...restProps: Record<string, any>[]\n): Record<string, any> {\n if (restProps.every((rest) => Object.keys(rest).length === 0)) {\n return props;\n }\n\n const result = { ...props };\n\n for (const rest of restProps) {\n for (const key of Object.keys(rest)) {\n result[key] = mergePropVals(key, result[key], rest[key]);\n }\n }\n\n return result;\n}\n\nfunction updateRef<T>(ref: React.Ref<T> | undefined, value: T | null) {\n if (!ref) {\n return;\n }\n\n if (typeof ref === \"function\") {\n ref(value);\n } else {\n if (!Object.isFrozen(ref)) {\n (ref as React.MutableRefObject<T | null>).current = value;\n }\n }\n}\n\nexport function mergeRefs<T>(...refs: (React.Ref<T> | undefined)[]) {\n return (value: T) => {\n for (const ref of refs) {\n updateRef(ref, value);\n }\n };\n}\n\nexport function mergePropVals(name: string, val1: any, val2: any): any {\n if (val1 === NONE || val2 === NONE) {\n // The NONE sentinel always skips all merging and returns null\n return null;\n } else if (val1 == null) {\n // If either of them is nil, prefer the other\n return val2;\n } else if (val2 == null) {\n return val1;\n } else if (name === \"className\") {\n // Special case for className -- always combine both class names\n return classNames(val1, val2);\n } else if (name === \"style\") {\n // Special case for style -- always shallow-merge style dicts\n return { ...val1, ...val2 };\n } else if (name === \"ref\") {\n // Special case for ref\n return mergeRefs(val1, val2);\n } else if (typeof val1 !== typeof val2) {\n // If the type of the two values are different, then no way to merge them.\n // Prefer val2.\n return val2;\n } else if (name.startsWith(\"on\") && typeof val1 === \"function\") {\n // Special case for event handlers -- always call both handlers\n return (...args: any[]) => {\n let res: any;\n if (typeof val1 === \"function\") {\n res = val1(...args);\n }\n if (typeof val2 === \"function\") {\n res = val2(...args);\n }\n return res;\n };\n } else {\n // For all else, prefer val2\n return val2;\n }\n}\n\nexport function getElementTypeName(element: React.ReactElement) {\n if (typeof element.type === \"string\") {\n return element.type;\n } else {\n const comp = element.type as any;\n return comp.displayName ?? comp.name ?? comp.render?.name ?? \"Component\";\n }\n}\n\nexport function reactNodeToString(reactNode: React.ReactNode): string {\n let string = \"\";\n if (typeof reactNode === \"string\") {\n string = reactNode;\n } else if (typeof reactNode === \"number\") {\n string = reactNode.toString();\n } else if (reactNode instanceof Array) {\n reactNode.forEach(function (child) {\n string += reactNodeToString(child);\n });\n } else if (isValidElement(reactNode)) {\n string += reactNodeToString(reactNode.props.children);\n }\n return string;\n}\n\nexport function useIsMounted(): () => boolean {\n const ref = React.useRef<boolean>(false);\n const isMounted = React.useCallback(() => ref.current, []);\n\n React.useEffect(() => {\n ref.current = true;\n return () => {\n ref.current = false;\n };\n }, []);\n\n return isMounted;\n}\n"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;AAGa,MAAA,SAAA,GAAY,OAAO,MAAW,KAAA,WAAA,CAAA;AAC9B,MAAA,IAAA,GAAO,OAAO,MAAM,CAAA,CAAA;AAEQ,SAAA,GACrC,KAAM,CAAA,eAAA,GACN,KAAM,CAAA,UAAA;AAyFM,SAAA,UAAA,CACd,UACG,SACkB,EAA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O,SAAA,KAAc,QAAU,EAAA;AACxC,IAAA,MAAA,GAAS,UAAU,QAAS,EAAA,CAAA;AAAA,GAC9B,MAAA,IAAW,qBAAqB,KAAO,EAAA;AACrC,IAAU,SAAA,CAAA,OAAA,CAAQ,SAAU,KAAO,EAAA;AACjC,MAAA,MAAA,IAAU,kBAAkB,KAAK,CAAA,CAAA;AAAA,KAClC,CAAA,CAAA;AAAA,GACH,MAAA,IAAW,cAAe,CAAA,SAAS,CAAG,EAAA;AACpC,IAAU,MAAA,IAAA,iBAAA,CAAkB,SAAU,CAAA,KAAA,CAAM,QAAQ,CAAA,CAAA;AAAA,GACtD;AACA,EAAO,OAAA,MAAA,CAAA;AACT,CAAA;AAEO,SAAS,YAA8B,GAAA;AAC5C,EAAM,MAAA,GAAA,GAAM,KAAM,CAAA,MAAA,CAAgB,KAAK,CAAA,CAAA;AACvC,EAAA,MAAM,YAAY,KAAM,CAAA,WAAA,CAAY,MAAM,GAAI,CAAA,OAAA,EAAS,EAAE,CAAA,CAAA;AAEzD,EAAA,KAAA,CAAM,UAAU,MAAM;AACpB,IAAA,GAAA,CAAI,OAAU,GAAA,IAAA,CAAA;AACd,IAAA,OAAO,MAAM;AACX,MAAA,GAAA,CAAI,OAAU,GAAA,KAAA,CAAA;AAAA,KAChB,CAAA;AAAA,GACF,EAAG,EAAE,CAAA,CAAA;AAEL,EAAO,OAAA,SAAA,CAAA;AACT;;;;"}
|
package/skinny/react-utils.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import React from "react";
|
|
2
2
|
export declare const isBrowser: boolean;
|
|
3
3
|
export declare const NONE: unique symbol;
|
|
4
|
-
export declare const useIsomorphicLayoutEffect: typeof React.
|
|
4
|
+
export declare const useIsomorphicLayoutEffect: typeof React.useLayoutEffect;
|
|
5
5
|
export declare function createElementWithChildren(elementType: any, props: any, children: React.ReactNode): React.ReactElement<any, string | React.JSXElementConstructor<any>>;
|
|
6
6
|
export declare function ensureNotArray(children: React.ReactNode): any;
|
|
7
7
|
/**
|
|
@@ -20,3 +20,4 @@ export declare function mergeRefs<T>(...refs: (React.Ref<T> | undefined)[]): (va
|
|
|
20
20
|
export declare function mergePropVals(name: string, val1: any, val2: any): any;
|
|
21
21
|
export declare function getElementTypeName(element: React.ReactElement): any;
|
|
22
22
|
export declare function reactNodeToString(reactNode: React.ReactNode): string;
|
|
23
|
+
export declare function useIsMounted(): () => boolean;
|
|
@@ -6,7 +6,9 @@ var query = require('@plasmicapp/query');
|
|
|
6
6
|
var antd = require('antd');
|
|
7
7
|
var enUS = require('antd/lib/locale/en_US.js');
|
|
8
8
|
var React = require('react');
|
|
9
|
+
var reactUtils = require('./react-utils-11b0221a.cjs.js');
|
|
9
10
|
var utils = require('./utils-174b9d45.cjs.js');
|
|
11
|
+
require('classnames');
|
|
10
12
|
require('@plasmicapp/host/registerComponent');
|
|
11
13
|
require('@plasmicapp/host/registerGlobalContext');
|
|
12
14
|
|
|
@@ -151,17 +153,24 @@ function InnerConfigProvider(props) {
|
|
|
151
153
|
}),
|
|
152
154
|
[app]
|
|
153
155
|
);
|
|
156
|
+
const enableLoadingBoundary = !!host.useSelector(
|
|
157
|
+
"plasmicInternalEnableLoadingBoundary"
|
|
158
|
+
);
|
|
154
159
|
if (!host.GlobalActionsProvider) {
|
|
155
160
|
warnOutdatedDeps();
|
|
156
161
|
}
|
|
157
|
-
|
|
162
|
+
let content = host.GlobalActionsProvider ? /* @__PURE__ */ React__default.default.createElement(
|
|
158
163
|
host.GlobalActionsProvider,
|
|
159
164
|
{
|
|
160
165
|
contextName: "plasmic-antd5-config-provider",
|
|
161
166
|
actions
|
|
162
167
|
},
|
|
163
168
|
children
|
|
164
|
-
) : children
|
|
169
|
+
) : children;
|
|
170
|
+
if (!removeLoading && enableLoadingBoundary) {
|
|
171
|
+
content = /* @__PURE__ */ React__default.default.createElement(React__default.default.Suspense, null, content);
|
|
172
|
+
}
|
|
173
|
+
return /* @__PURE__ */ React__default.default.createElement(React__default.default.Fragment, null, /* @__PURE__ */ React__default.default.createElement("style", { dangerouslySetInnerHTML: { __html: cssStyles } }), content, !removeLoading && /* @__PURE__ */ React__default.default.createElement(GlobalLoadingIndicator, { loadingText }));
|
|
165
174
|
}
|
|
166
175
|
let warned = false;
|
|
167
176
|
function warnOutdatedDeps() {
|
|
@@ -175,18 +184,40 @@ function warnOutdatedDeps() {
|
|
|
175
184
|
function GlobalLoadingIndicator(props) {
|
|
176
185
|
const { loadingText } = props;
|
|
177
186
|
const app = useAppContext();
|
|
187
|
+
const isLoadingRef = React__default.default.useRef(false);
|
|
188
|
+
const isMounted = reactUtils.useIsMounted();
|
|
189
|
+
const showLoading = React__default.default.useCallback(() => {
|
|
190
|
+
if (isMounted() && isLoadingRef.current) {
|
|
191
|
+
app.message.open({
|
|
192
|
+
content: loadingText != null ? loadingText : "Loading...",
|
|
193
|
+
duration: 0,
|
|
194
|
+
key: `plasmic-antd5-global-loading-indicator`
|
|
195
|
+
});
|
|
196
|
+
}
|
|
197
|
+
}, [app, loadingText, isMounted, isLoadingRef]);
|
|
198
|
+
const hideLoading = React__default.default.useCallback(() => {
|
|
199
|
+
setTimeout(() => {
|
|
200
|
+
if (isMounted() && !isLoadingRef.current) {
|
|
201
|
+
app.message.destroy(`plasmic-antd5-global-loading-indicator`);
|
|
202
|
+
}
|
|
203
|
+
}, 500);
|
|
204
|
+
}, [app, isMounted, isLoadingRef]);
|
|
178
205
|
React__default.default.useEffect(() => {
|
|
179
206
|
if (query.addLoadingStateListener) {
|
|
207
|
+
if (isLoadingRef.current) {
|
|
208
|
+
showLoading();
|
|
209
|
+
} else {
|
|
210
|
+
hideLoading();
|
|
211
|
+
}
|
|
180
212
|
return query.addLoadingStateListener(
|
|
181
213
|
(isLoading) => {
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
app.message.destroy(`plasmic-antd5-global-loading-indicator`);
|
|
214
|
+
isLoadingRef.current = isLoading;
|
|
215
|
+
if (isMounted()) {
|
|
216
|
+
if (isLoading) {
|
|
217
|
+
showLoading();
|
|
218
|
+
} else {
|
|
219
|
+
hideLoading();
|
|
220
|
+
}
|
|
190
221
|
}
|
|
191
222
|
},
|
|
192
223
|
// Disabled immediat because it's creating an infinite rendering
|
|
@@ -198,7 +229,7 @@ function GlobalLoadingIndicator(props) {
|
|
|
198
229
|
return () => {
|
|
199
230
|
};
|
|
200
231
|
}
|
|
201
|
-
}, [app]);
|
|
232
|
+
}, [app, isMounted, isLoadingRef, showLoading, hideLoading]);
|
|
202
233
|
return null;
|
|
203
234
|
}
|
|
204
235
|
const ForkedAppContext = React__default.default.createContext(void 0);
|