@fluentui/react-utilities 9.2.1 → 9.2.2
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/CHANGELOG.json +24 -1
- package/CHANGELOG.md +11 -2
- package/lib/compose/getSlots.js.map +1 -1
- package/lib/compose/index.js.map +1 -1
- package/lib/compose/isResolvedShorthand.js.map +1 -1
- package/lib/compose/resolveShorthand.js.map +1 -1
- package/lib/compose/types.js.map +1 -1
- package/lib/hooks/index.js.map +1 -1
- package/lib/hooks/useControllableState.js.map +1 -1
- package/lib/hooks/useEventCallback.js.map +1 -1
- package/lib/hooks/useFirstMount.js.map +1 -1
- package/lib/hooks/useForceUpdate.js.map +1 -1
- package/lib/hooks/useId.js.map +1 -1
- package/lib/hooks/useIsomorphicLayoutEffect.js.map +1 -1
- package/lib/hooks/useMergedRefs.js.map +1 -1
- package/lib/hooks/useOnClickOutside.js.map +1 -1
- package/lib/hooks/useOnScrollOutside.js.map +1 -1
- package/lib/hooks/usePrevious.js.map +1 -1
- package/lib/hooks/useTimeout.js.map +1 -1
- package/lib/index.js.map +1 -1
- package/lib/ssr/SSRContext.js.map +1 -1
- package/lib/ssr/canUseDOM.js.map +1 -1
- package/lib/ssr/index.js.map +1 -1
- package/lib/trigger/applyTriggerPropsToChildren.js.map +1 -1
- package/lib/trigger/getTriggerChild.js.map +1 -1
- package/lib/trigger/index.js.map +1 -1
- package/lib/trigger/isFluentTrigger.js.map +1 -1
- package/lib/trigger/types.js.map +1 -1
- package/lib/utils/clamp.js.map +1 -1
- package/lib/utils/getNativeElementProps.js.map +1 -1
- package/lib/utils/getRTLSafeKey.js.map +1 -1
- package/lib/utils/getReactCallbackName.js.map +1 -1
- package/lib/utils/index.js.map +1 -1
- package/lib/utils/mergeCallbacks.js.map +1 -1
- package/lib/utils/omit.js.map +1 -1
- package/lib/utils/properties.js +1 -1
- package/lib/utils/properties.js.map +1 -1
- package/lib/utils/shouldPreventDefaultOnKeyDown.js.map +1 -1
- package/lib-amd/compose/getSlots.js +58 -0
- package/lib-amd/compose/getSlots.js.map +1 -0
- package/lib-amd/compose/index.js +9 -0
- package/lib-amd/compose/index.js.map +1 -0
- package/lib-amd/compose/isResolvedShorthand.js +40 -0
- package/lib-amd/compose/isResolvedShorthand.js.map +1 -0
- package/lib-amd/compose/resolveShorthand.js +27 -0
- package/lib-amd/compose/resolveShorthand.js.map +1 -0
- package/lib-amd/compose/types.js +5 -0
- package/lib-amd/compose/types.js.map +1 -0
- package/lib-amd/hooks/index.js +16 -0
- package/lib-amd/hooks/index.js.map +1 -0
- package/lib-amd/hooks/useControllableState.js +81 -0
- package/lib-amd/hooks/useControllableState.js.map +1 -0
- package/lib-amd/hooks/useEventCallback.js +36 -0
- package/lib-amd/hooks/useEventCallback.js.map +1 -0
- package/lib-amd/hooks/useFirstMount.js +26 -0
- package/lib-amd/hooks/useFirstMount.js.map +1 -0
- package/lib-amd/hooks/useForceUpdate.js +14 -0
- package/lib-amd/hooks/useForceUpdate.js.map +1 -0
- package/lib-amd/hooks/useId.js +32 -0
- package/lib-amd/hooks/useId.js.map +1 -0
- package/lib-amd/hooks/useIsomorphicLayoutEffect.js +17 -0
- package/lib-amd/hooks/useIsomorphicLayoutEffect.js.map +1 -0
- package/lib-amd/hooks/useMergedRefs.js +34 -0
- package/lib-amd/hooks/useMergedRefs.js.map +1 -0
- package/lib-amd/hooks/useOnClickOutside.js +116 -0
- package/lib-amd/hooks/useOnClickOutside.js.map +1 -0
- package/lib-amd/hooks/useOnScrollOutside.js +31 -0
- package/lib-amd/hooks/useOnScrollOutside.js.map +1 -0
- package/lib-amd/hooks/usePrevious.js +17 -0
- package/lib-amd/hooks/usePrevious.js.map +1 -0
- package/lib-amd/hooks/useTimeout.js +33 -0
- package/lib-amd/hooks/useTimeout.js.map +1 -0
- package/lib-amd/index.js +33 -0
- package/lib-amd/index.js.map +1 -0
- package/lib-amd/ssr/SSRContext.js +69 -0
- package/lib-amd/ssr/SSRContext.js.map +1 -0
- package/lib-amd/ssr/canUseDOM.js +16 -0
- package/lib-amd/ssr/canUseDOM.js.map +1 -0
- package/lib-amd/ssr/index.js +7 -0
- package/lib-amd/ssr/index.js.map +1 -0
- package/lib-amd/trigger/applyTriggerPropsToChildren.js +40 -0
- package/lib-amd/trigger/applyTriggerPropsToChildren.js.map +1 -0
- package/lib-amd/trigger/getTriggerChild.js +40 -0
- package/lib-amd/trigger/getTriggerChild.js.map +1 -0
- package/lib-amd/trigger/index.js +9 -0
- package/lib-amd/trigger/index.js.map +1 -0
- package/lib-amd/trigger/isFluentTrigger.js +15 -0
- package/lib-amd/trigger/isFluentTrigger.js.map +1 -0
- package/lib-amd/trigger/types.js +5 -0
- package/lib-amd/trigger/types.js.map +1 -0
- package/lib-amd/utils/clamp.js +16 -0
- package/lib-amd/utils/clamp.js.map +1 -0
- package/lib-amd/utils/getNativeElementProps.js +64 -0
- package/lib-amd/utils/getNativeElementProps.js.map +1 -0
- package/lib-amd/utils/getRTLSafeKey.js +24 -0
- package/lib-amd/utils/getRTLSafeKey.js.map +1 -0
- package/lib-amd/utils/index.js +12 -0
- package/lib-amd/utils/index.js.map +1 -0
- package/lib-amd/utils/mergeCallbacks.js +40 -0
- package/lib-amd/utils/mergeCallbacks.js.map +1 -0
- package/lib-amd/utils/omit.js +31 -0
- package/lib-amd/utils/omit.js.map +1 -0
- package/lib-amd/utils/properties.js +450 -0
- package/lib-amd/utils/properties.js.map +1 -0
- package/lib-amd/utils/shouldPreventDefaultOnKeyDown.js +26 -0
- package/lib-amd/utils/shouldPreventDefaultOnKeyDown.js.map +1 -0
- package/lib-commonjs/compose/getSlots.js.map +1 -1
- package/lib-commonjs/compose/index.js.map +1 -1
- package/lib-commonjs/compose/isResolvedShorthand.js.map +1 -1
- package/lib-commonjs/compose/resolveShorthand.js.map +1 -1
- package/lib-commonjs/hooks/index.js.map +1 -1
- package/lib-commonjs/hooks/useControllableState.js.map +1 -1
- package/lib-commonjs/hooks/useEventCallback.js.map +1 -1
- package/lib-commonjs/hooks/useFirstMount.js.map +1 -1
- package/lib-commonjs/hooks/useForceUpdate.js.map +1 -1
- package/lib-commonjs/hooks/useId.js.map +1 -1
- package/lib-commonjs/hooks/useIsomorphicLayoutEffect.js.map +1 -1
- package/lib-commonjs/hooks/useMergedRefs.js.map +1 -1
- package/lib-commonjs/hooks/useOnClickOutside.js.map +1 -1
- package/lib-commonjs/hooks/useOnScrollOutside.js.map +1 -1
- package/lib-commonjs/hooks/usePrevious.js.map +1 -1
- package/lib-commonjs/hooks/useTimeout.js.map +1 -1
- package/lib-commonjs/index.js.map +1 -1
- package/lib-commonjs/ssr/SSRContext.js.map +1 -1
- package/lib-commonjs/ssr/canUseDOM.js.map +1 -1
- package/lib-commonjs/ssr/index.js.map +1 -1
- package/lib-commonjs/trigger/applyTriggerPropsToChildren.js.map +1 -1
- package/lib-commonjs/trigger/getTriggerChild.js.map +1 -1
- package/lib-commonjs/trigger/index.js.map +1 -1
- package/lib-commonjs/trigger/isFluentTrigger.js.map +1 -1
- package/lib-commonjs/utils/clamp.js.map +1 -1
- package/lib-commonjs/utils/getNativeElementProps.js.map +1 -1
- package/lib-commonjs/utils/getRTLSafeKey.js.map +1 -1
- package/lib-commonjs/utils/getReactCallbackName.js.map +1 -1
- package/lib-commonjs/utils/index.js.map +1 -1
- package/lib-commonjs/utils/mergeCallbacks.js.map +1 -1
- package/lib-commonjs/utils/omit.js.map +1 -1
- package/lib-commonjs/utils/properties.js +1 -1
- package/lib-commonjs/utils/properties.js.map +1 -1
- package/lib-commonjs/utils/shouldPreventDefaultOnKeyDown.js.map +1 -1
- package/package.json +3 -4
@@ -0,0 +1,64 @@
|
|
1
|
+
define(["require", "exports", "tslib", "./properties"], function (require, exports, tslib_1, properties_1) {
|
2
|
+
"use strict";
|
3
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
4
|
+
exports.getPartitionedNativeProps = exports.getNativeElementProps = void 0;
|
5
|
+
var nativeElementMap = {
|
6
|
+
label: properties_1.labelProperties,
|
7
|
+
audio: properties_1.audioProperties,
|
8
|
+
video: properties_1.videoProperties,
|
9
|
+
ol: properties_1.olProperties,
|
10
|
+
li: properties_1.liProperties,
|
11
|
+
a: properties_1.anchorProperties,
|
12
|
+
button: properties_1.buttonProperties,
|
13
|
+
input: properties_1.inputProperties,
|
14
|
+
textarea: properties_1.textAreaProperties,
|
15
|
+
select: properties_1.selectProperties,
|
16
|
+
option: properties_1.optionProperties,
|
17
|
+
table: properties_1.tableProperties,
|
18
|
+
tr: properties_1.trProperties,
|
19
|
+
th: properties_1.thProperties,
|
20
|
+
td: properties_1.tdProperties,
|
21
|
+
colGroup: properties_1.colGroupProperties,
|
22
|
+
col: properties_1.colProperties,
|
23
|
+
fieldset: properties_1.fieldsetProperties,
|
24
|
+
form: properties_1.formProperties,
|
25
|
+
iframe: properties_1.iframeProperties,
|
26
|
+
img: properties_1.imgProperties,
|
27
|
+
time: properties_1.timeProperties,
|
28
|
+
dialog: properties_1.dialogProperties,
|
29
|
+
};
|
30
|
+
/**
|
31
|
+
* Given an element tagname and user props, filters the props to only allowed props for the given
|
32
|
+
* element type.
|
33
|
+
* @param tagName - Tag name (e.g. "div")
|
34
|
+
* @param props - Props object
|
35
|
+
* @param excludedPropNames - List of props to disallow
|
36
|
+
*/
|
37
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
38
|
+
function getNativeElementProps(tagName, props, excludedPropNames) {
|
39
|
+
var allowedPropNames = (tagName && nativeElementMap[tagName]) || properties_1.htmlElementProperties;
|
40
|
+
allowedPropNames.as = 1;
|
41
|
+
return properties_1.getNativeProps(props, allowedPropNames, excludedPropNames);
|
42
|
+
}
|
43
|
+
exports.getNativeElementProps = getNativeElementProps;
|
44
|
+
/**
|
45
|
+
* Splits the native props into ones that go to the `root` slot, and ones that go to the primary slot.
|
46
|
+
*
|
47
|
+
* This function is only for use with components that have a primary slot other than `root`.
|
48
|
+
* Most components should use {@link getNativeElementProps} for their root slot if it is the primary slot.
|
49
|
+
*
|
50
|
+
* @returns An object containing the native props for the `root` and primary slots.
|
51
|
+
*/
|
52
|
+
var getPartitionedNativeProps = function (_a) {
|
53
|
+
var primarySlotTagName = _a.primarySlotTagName, props = _a.props, excludedPropNames = _a.excludedPropNames;
|
54
|
+
return {
|
55
|
+
root: { style: props.style, className: props.className },
|
56
|
+
primary: getNativeElementProps(primarySlotTagName, props, tslib_1.__spreadArray(tslib_1.__spreadArray([], (excludedPropNames || [])), [
|
57
|
+
'style',
|
58
|
+
'className',
|
59
|
+
])),
|
60
|
+
};
|
61
|
+
};
|
62
|
+
exports.getPartitionedNativeProps = getPartitionedNativeProps;
|
63
|
+
});
|
64
|
+
//# sourceMappingURL=getNativeElementProps.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"getNativeElementProps.js","sourceRoot":"","sources":["../../../../../../../../packages/react-components/react-utilities/src/utils/getNativeElementProps.ts"],"names":[],"mappings":";;;;IA6BA,IAAM,gBAAgB,GAA2C;QAC/D,KAAK,EAAE,4BAAe;QACtB,KAAK,EAAE,4BAAe;QACtB,KAAK,EAAE,4BAAe;QACtB,EAAE,EAAE,yBAAY;QAChB,EAAE,EAAE,yBAAY;QAChB,CAAC,EAAE,6BAAgB;QACnB,MAAM,EAAE,6BAAgB;QACxB,KAAK,EAAE,4BAAe;QACtB,QAAQ,EAAE,+BAAkB;QAC5B,MAAM,EAAE,6BAAgB;QACxB,MAAM,EAAE,6BAAgB;QACxB,KAAK,EAAE,4BAAe;QACtB,EAAE,EAAE,yBAAY;QAChB,EAAE,EAAE,yBAAY;QAChB,EAAE,EAAE,yBAAY;QAChB,QAAQ,EAAE,+BAAkB;QAC5B,GAAG,EAAE,0BAAa;QAClB,QAAQ,EAAE,+BAAkB;QAC5B,IAAI,EAAE,2BAAc;QACpB,MAAM,EAAE,6BAAgB;QACxB,GAAG,EAAE,0BAAa;QAClB,IAAI,EAAE,2BAAc;QACpB,MAAM,EAAE,6BAAgB;KACzB,CAAC;IAEF;;;;;;OAMG;IACH,8DAA8D;IAC9D,SAAgB,qBAAqB,CACnC,OAAe,EACf,KAAS,EACT,iBAA4B;QAE5B,IAAM,gBAAgB,GAAG,CAAC,OAAO,IAAI,gBAAgB,CAAC,OAAO,CAAC,CAAC,IAAI,kCAAqB,CAAC;QACzF,gBAAgB,CAAC,EAAE,GAAG,CAAC,CAAC;QAExB,OAAO,2BAAc,CAAC,KAAK,EAAE,gBAAgB,EAAE,iBAAiB,CAAC,CAAC;IACpE,CAAC;IATD,sDASC;IAED;;;;;;;OAOG;IACI,IAAM,yBAAyB,GAAG,UAGvC,EAaD;YAZC,kBAAkB,wBAAA,EAClB,KAAK,WAAA,EACL,iBAAiB,uBAAA;QAWjB,OAAO;YACL,IAAI,EAAE,EAAE,KAAK,EAAE,KAAK,CAAC,KAAK,EAAE,SAAS,EAAE,KAAK,CAAC,SAAS,EAAE;YACxD,OAAO,EAAE,qBAAqB,CAAgC,kBAAkB,EAAE,KAAK,kDAClF,CAAC,iBAAiB,IAAI,EAAE,CAAC;gBAC5B,OAAO;gBACP,WAAW;eACX;SACH,CAAC;IACJ,CAAC,CAAC;IAzBW,QAAA,yBAAyB,6BAyBpC","sourcesContent":["import * as React from 'react';\nimport {\n labelProperties,\n audioProperties,\n videoProperties,\n olProperties,\n liProperties,\n anchorProperties,\n buttonProperties,\n inputProperties,\n textAreaProperties,\n selectProperties,\n optionProperties,\n tableProperties,\n trProperties,\n thProperties,\n tdProperties,\n colGroupProperties,\n colProperties,\n fieldsetProperties,\n formProperties,\n iframeProperties,\n imgProperties,\n htmlElementProperties,\n getNativeProps,\n timeProperties,\n dialogProperties,\n} from './properties';\n\nconst nativeElementMap: Record<string, Record<string, number>> = {\n label: labelProperties,\n audio: audioProperties,\n video: videoProperties,\n ol: olProperties,\n li: liProperties,\n a: anchorProperties,\n button: buttonProperties,\n input: inputProperties,\n textarea: textAreaProperties,\n select: selectProperties,\n option: optionProperties,\n table: tableProperties,\n tr: trProperties,\n th: thProperties,\n td: tdProperties,\n colGroup: colGroupProperties,\n col: colProperties,\n fieldset: fieldsetProperties,\n form: formProperties,\n iframe: iframeProperties,\n img: imgProperties,\n time: timeProperties,\n dialog: dialogProperties,\n};\n\n/**\n * Given an element tagname and user props, filters the props to only allowed props for the given\n * element type.\n * @param tagName - Tag name (e.g. \"div\")\n * @param props - Props object\n * @param excludedPropNames - List of props to disallow\n */\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport function getNativeElementProps<TAttributes extends React.HTMLAttributes<any>>(\n tagName: string,\n props: {},\n excludedPropNames?: string[],\n): TAttributes {\n const allowedPropNames = (tagName && nativeElementMap[tagName]) || htmlElementProperties;\n allowedPropNames.as = 1;\n\n return getNativeProps(props, allowedPropNames, excludedPropNames);\n}\n\n/**\n * Splits the native props into ones that go to the `root` slot, and ones that go to the primary slot.\n *\n * This function is only for use with components that have a primary slot other than `root`.\n * Most components should use {@link getNativeElementProps} for their root slot if it is the primary slot.\n *\n * @returns An object containing the native props for the `root` and primary slots.\n */\nexport const getPartitionedNativeProps = <\n Props extends Pick<React.HTMLAttributes<HTMLElement>, 'style' | 'className'>,\n ExcludedPropKeys extends Extract<keyof Props, string> = never\n>({\n primarySlotTagName,\n props,\n excludedPropNames,\n}: {\n /** The primary slot's element type (e.g. 'div') */\n primarySlotTagName: keyof JSX.IntrinsicElements;\n\n /** The component's props object */\n props: Props;\n\n /** List of native props to exclude from the returned value */\n excludedPropNames?: ExcludedPropKeys[];\n}) => {\n return {\n root: { style: props.style, className: props.className },\n primary: getNativeElementProps<Omit<Props, ExcludedPropKeys>>(primarySlotTagName, props, [\n ...(excludedPropNames || []),\n 'style',\n 'className',\n ]),\n };\n};\n"]}
|
@@ -0,0 +1,24 @@
|
|
1
|
+
define(["require", "exports"], function (require, exports) {
|
2
|
+
"use strict";
|
3
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
4
|
+
exports.getRTLSafeKey = void 0;
|
5
|
+
/**
|
6
|
+
* @internal
|
7
|
+
* Finds and swaps a provided key for it's right to left format.
|
8
|
+
*/
|
9
|
+
var getRTLSafeKey = function (key, dir) {
|
10
|
+
if (dir === 'rtl') {
|
11
|
+
switch (key) {
|
12
|
+
case 'ArrowLeft': {
|
13
|
+
return 'ArrowRight';
|
14
|
+
}
|
15
|
+
case 'ArrowRight': {
|
16
|
+
return 'ArrowLeft';
|
17
|
+
}
|
18
|
+
}
|
19
|
+
}
|
20
|
+
return key;
|
21
|
+
};
|
22
|
+
exports.getRTLSafeKey = getRTLSafeKey;
|
23
|
+
});
|
24
|
+
//# sourceMappingURL=getRTLSafeKey.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"getRTLSafeKey.js","sourceRoot":"","sources":["../../../../../../../../packages/react-components/react-utilities/src/utils/getRTLSafeKey.ts"],"names":[],"mappings":";;;;IAAA;;;OAGG;IACI,IAAM,aAAa,GAAG,UAAC,GAAW,EAAE,GAAkB;QAC3D,IAAI,GAAG,KAAK,KAAK,EAAE;YACjB,QAAQ,GAAG,EAAE;gBACX,KAAK,WAAW,CAAC,CAAC;oBAChB,OAAO,YAAY,CAAC;iBACrB;gBAED,KAAK,YAAY,CAAC,CAAC;oBACjB,OAAO,WAAW,CAAC;iBACpB;aACF;SACF;QAED,OAAO,GAAG,CAAC;IACb,CAAC,CAAC;IAdW,QAAA,aAAa,iBAcxB","sourcesContent":["/**\n * @internal\n * Finds and swaps a provided key for it's right to left format.\n */\nexport const getRTLSafeKey = (key: string, dir: 'ltr' | 'rtl') => {\n if (dir === 'rtl') {\n switch (key) {\n case 'ArrowLeft': {\n return 'ArrowRight';\n }\n\n case 'ArrowRight': {\n return 'ArrowLeft';\n }\n }\n }\n\n return key;\n};\n"]}
|
@@ -0,0 +1,12 @@
|
|
1
|
+
define(["require", "exports", "tslib", "./clamp", "./getNativeElementProps", "./getRTLSafeKey", "./mergeCallbacks", "./omit", "./properties", "./shouldPreventDefaultOnKeyDown"], function (require, exports, tslib_1, clamp_1, getNativeElementProps_1, getRTLSafeKey_1, mergeCallbacks_1, omit_1, properties_1, shouldPreventDefaultOnKeyDown_1) {
|
2
|
+
"use strict";
|
3
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
4
|
+
tslib_1.__exportStar(clamp_1, exports);
|
5
|
+
tslib_1.__exportStar(getNativeElementProps_1, exports);
|
6
|
+
tslib_1.__exportStar(getRTLSafeKey_1, exports);
|
7
|
+
tslib_1.__exportStar(mergeCallbacks_1, exports);
|
8
|
+
tslib_1.__exportStar(omit_1, exports);
|
9
|
+
tslib_1.__exportStar(properties_1, exports);
|
10
|
+
tslib_1.__exportStar(shouldPreventDefaultOnKeyDown_1, exports);
|
11
|
+
});
|
12
|
+
//# sourceMappingURL=index.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../../../../packages/react-components/react-utilities/src/utils/index.ts"],"names":[],"mappings":";;;IAAA,uCAAwB;IACxB,uDAAwC;IACxC,+CAAgC;IAChC,gDAAiC;IACjC,sCAAuB;IACvB,4CAA6B;IAC7B,+DAAgD","sourcesContent":["export * from './clamp';\nexport * from './getNativeElementProps';\nexport * from './getRTLSafeKey';\nexport * from './mergeCallbacks';\nexport * from './omit';\nexport * from './properties';\nexport * from './shouldPreventDefaultOnKeyDown';\n"]}
|
@@ -0,0 +1,40 @@
|
|
1
|
+
define(["require", "exports"], function (require, exports) {
|
2
|
+
"use strict";
|
3
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
4
|
+
exports.mergeCallbacks = void 0;
|
5
|
+
/**
|
6
|
+
* @internal
|
7
|
+
* Combine two event callbacks into a single callback function that calls each one in order.
|
8
|
+
*
|
9
|
+
* Usage example:
|
10
|
+
* ```ts
|
11
|
+
* state.slot.onChange = mergeCallbacks(state.slot.onChange, ev => {
|
12
|
+
* // Handle onChange
|
13
|
+
* });
|
14
|
+
* ```
|
15
|
+
*
|
16
|
+
* The primary use is to avoid the need to capture an existing callback (`state.slot.onChange` in the example) to a
|
17
|
+
* local variable before replacing with a new listener that calls the existing one. This helps avoid bugs like:
|
18
|
+
* * Infinite recursion by calling the re-assigned state.slot.onChange if it's not captured to a local variable.
|
19
|
+
* * Missing a call to the original onChange due to an early return or other conditional.
|
20
|
+
*
|
21
|
+
* If you need a callback that is stable between renders, wrap the result in {@link useEventCallback}.
|
22
|
+
*
|
23
|
+
* @param callback1 - The first callback to be called, or undefined
|
24
|
+
* @param callback2 - The second callback to be called, or undefined
|
25
|
+
*
|
26
|
+
* @returns A function that that calls the provided functions in order
|
27
|
+
*/
|
28
|
+
function mergeCallbacks(callback1, callback2) {
|
29
|
+
return function () {
|
30
|
+
var args = [];
|
31
|
+
for (var _i = 0; _i < arguments.length; _i++) {
|
32
|
+
args[_i] = arguments[_i];
|
33
|
+
}
|
34
|
+
callback1 === null || callback1 === void 0 ? void 0 : callback1.apply(void 0, args);
|
35
|
+
callback2 === null || callback2 === void 0 ? void 0 : callback2.apply(void 0, args);
|
36
|
+
};
|
37
|
+
}
|
38
|
+
exports.mergeCallbacks = mergeCallbacks;
|
39
|
+
});
|
40
|
+
//# sourceMappingURL=mergeCallbacks.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"mergeCallbacks.js","sourceRoot":"","sources":["../../../../../../../../packages/react-components/react-utilities/src/utils/mergeCallbacks.ts"],"names":[],"mappings":";;;;IAAA;;;;;;;;;;;;;;;;;;;;;;OAsBG;IACH,SAAgB,cAAc,CAC5B,SAAgD,EAChD,SAAgD;QAEhD,OAAO;YAAC,cAAa;iBAAb,UAAa,EAAb,qBAAa,EAAb,IAAa;gBAAb,yBAAa;;YACnB,SAAS,aAAT,SAAS,uBAAT,SAAS,eAAM,IAAI,CAAC,CAAC;YACrB,SAAS,aAAT,SAAS,uBAAT,SAAS,eAAM,IAAI,CAAC,CAAC;QACvB,CAAC,CAAC;IACJ,CAAC;IARD,wCAQC","sourcesContent":["/**\n * @internal\n * Combine two event callbacks into a single callback function that calls each one in order.\n *\n * Usage example:\n * ```ts\n * state.slot.onChange = mergeCallbacks(state.slot.onChange, ev => {\n * // Handle onChange\n * });\n * ```\n *\n * The primary use is to avoid the need to capture an existing callback (`state.slot.onChange` in the example) to a\n * local variable before replacing with a new listener that calls the existing one. This helps avoid bugs like:\n * * Infinite recursion by calling the re-assigned state.slot.onChange if it's not captured to a local variable.\n * * Missing a call to the original onChange due to an early return or other conditional.\n *\n * If you need a callback that is stable between renders, wrap the result in {@link useEventCallback}.\n *\n * @param callback1 - The first callback to be called, or undefined\n * @param callback2 - The second callback to be called, or undefined\n *\n * @returns A function that that calls the provided functions in order\n */\nexport function mergeCallbacks<Args extends unknown[]>(\n callback1: ((...args: Args) => void) | undefined,\n callback2: ((...args: Args) => void) | undefined,\n) {\n return (...args: Args) => {\n callback1?.(...args);\n callback2?.(...args);\n };\n}\n"]}
|
@@ -0,0 +1,31 @@
|
|
1
|
+
define(["require", "exports"], function (require, exports) {
|
2
|
+
"use strict";
|
3
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
4
|
+
exports.omit = void 0;
|
5
|
+
/**
|
6
|
+
* Tiny helper to do the minimal amount of work in duplicating an object but omitting some
|
7
|
+
* props. This ends up faster than using object ...rest or reduce to filter.
|
8
|
+
*
|
9
|
+
* This behaves very much like filteredAssign, but does not merge many objects together,
|
10
|
+
* uses an exclusion object map, and avoids spreads all for optimal performance.
|
11
|
+
*
|
12
|
+
* See perf test for background:
|
13
|
+
* https://jsperf.com/omit-vs-rest-vs-reduce/1
|
14
|
+
*
|
15
|
+
* @param obj - The object to clone
|
16
|
+
* @param exclusions - The array of keys to exclude
|
17
|
+
*/
|
18
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
19
|
+
function omit(obj, exclusions) {
|
20
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
21
|
+
var result = {};
|
22
|
+
for (var key in obj) {
|
23
|
+
if (exclusions.indexOf(key) === -1 && obj.hasOwnProperty(key)) {
|
24
|
+
result[key] = obj[key];
|
25
|
+
}
|
26
|
+
}
|
27
|
+
return result;
|
28
|
+
}
|
29
|
+
exports.omit = omit;
|
30
|
+
});
|
31
|
+
//# sourceMappingURL=omit.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"omit.js","sourceRoot":"","sources":["../../../../../../../../packages/react-components/react-utilities/src/utils/omit.ts"],"names":[],"mappings":";;;;IAAA;;;;;;;;;;;;OAYG;IACH,8DAA8D;IAC9D,SAAgB,IAAI,CAClB,GAAS,EACT,UAAsB;QAEtB,8DAA8D;QAC9D,IAAM,MAAM,GAAwB,EAAE,CAAC;QAEvC,KAAK,IAAM,GAAG,IAAI,GAAG,EAAE;YACrB,IAAI,UAAU,CAAC,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC,IAAI,GAAG,CAAC,cAAc,CAAC,GAAG,CAAC,EAAE;gBAC7D,MAAM,CAAC,GAAG,CAAC,GAAG,GAAG,CAAC,GAAG,CAAC,CAAC;aACxB;SACF;QAED,OAAO,MAAc,CAAC;IACxB,CAAC;IAdD,oBAcC","sourcesContent":["/**\n * Tiny helper to do the minimal amount of work in duplicating an object but omitting some\n * props. This ends up faster than using object ...rest or reduce to filter.\n *\n * This behaves very much like filteredAssign, but does not merge many objects together,\n * uses an exclusion object map, and avoids spreads all for optimal performance.\n *\n * See perf test for background:\n * https://jsperf.com/omit-vs-rest-vs-reduce/1\n *\n * @param obj - The object to clone\n * @param exclusions - The array of keys to exclude\n */\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport function omit<TObj extends Record<string, any>, Exclusions extends (keyof TObj)[]>(\n obj: TObj,\n exclusions: Exclusions,\n): Omit<TObj, Exclusions[number]> {\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n const result: Record<string, any> = {};\n\n for (const key in obj) {\n if (exclusions.indexOf(key) === -1 && obj.hasOwnProperty(key)) {\n result[key] = obj[key];\n }\n }\n\n return result as TObj;\n}\n"]}
|
@@ -0,0 +1,450 @@
|
|
1
|
+
define(["require", "exports"], function (require, exports) {
|
2
|
+
"use strict";
|
3
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
4
|
+
exports.getNativeProps = exports.divProperties = exports.dialogProperties = exports.imgProperties = exports.iframeProperties = exports.formProperties = exports.fieldsetProperties = exports.colProperties = exports.colGroupProperties = exports.tdProperties = exports.thProperties = exports.trProperties = exports.tableProperties = exports.optionProperties = exports.selectProperties = exports.textAreaProperties = exports.inputProperties = exports.buttonProperties = exports.timeProperties = exports.anchorProperties = exports.liProperties = exports.olProperties = exports.videoProperties = exports.audioProperties = exports.labelProperties = exports.htmlElementProperties = exports.microdataProperties = exports.baseElementProperties = exports.baseElementEvents = void 0;
|
5
|
+
var toObjectMap = function () {
|
6
|
+
var items = [];
|
7
|
+
for (var _i = 0; _i < arguments.length; _i++) {
|
8
|
+
items[_i] = arguments[_i];
|
9
|
+
}
|
10
|
+
var result = {};
|
11
|
+
for (var _a = 0, items_1 = items; _a < items_1.length; _a++) {
|
12
|
+
var item = items_1[_a];
|
13
|
+
var keys = Array.isArray(item) ? item : Object.keys(item);
|
14
|
+
for (var _b = 0, keys_1 = keys; _b < keys_1.length; _b++) {
|
15
|
+
var key = keys_1[_b];
|
16
|
+
result[key] = 1;
|
17
|
+
}
|
18
|
+
}
|
19
|
+
return result;
|
20
|
+
};
|
21
|
+
/**
|
22
|
+
* An array of events that are allowed on every html element type.
|
23
|
+
*
|
24
|
+
* @public
|
25
|
+
*/
|
26
|
+
exports.baseElementEvents = toObjectMap([
|
27
|
+
'onAuxClick',
|
28
|
+
'onCopy',
|
29
|
+
'onCut',
|
30
|
+
'onPaste',
|
31
|
+
'onCompositionEnd',
|
32
|
+
'onCompositionStart',
|
33
|
+
'onCompositionUpdate',
|
34
|
+
'onFocus',
|
35
|
+
'onFocusCapture',
|
36
|
+
'onBlur',
|
37
|
+
'onBlurCapture',
|
38
|
+
'onChange',
|
39
|
+
'onInput',
|
40
|
+
'onSubmit',
|
41
|
+
'onLoad',
|
42
|
+
'onError',
|
43
|
+
'onKeyDown',
|
44
|
+
'onKeyDownCapture',
|
45
|
+
'onKeyPress',
|
46
|
+
'onKeyUp',
|
47
|
+
'onAbort',
|
48
|
+
'onCanPlay',
|
49
|
+
'onCanPlayThrough',
|
50
|
+
'onDurationChange',
|
51
|
+
'onEmptied',
|
52
|
+
'onEncrypted',
|
53
|
+
'onEnded',
|
54
|
+
'onLoadedData',
|
55
|
+
'onLoadedMetadata',
|
56
|
+
'onLoadStart',
|
57
|
+
'onPause',
|
58
|
+
'onPlay',
|
59
|
+
'onPlaying',
|
60
|
+
'onProgress',
|
61
|
+
'onRateChange',
|
62
|
+
'onSeeked',
|
63
|
+
'onSeeking',
|
64
|
+
'onStalled',
|
65
|
+
'onSuspend',
|
66
|
+
'onTimeUpdate',
|
67
|
+
'onVolumeChange',
|
68
|
+
'onWaiting',
|
69
|
+
'onClick',
|
70
|
+
'onClickCapture',
|
71
|
+
'onContextMenu',
|
72
|
+
'onDoubleClick',
|
73
|
+
'onDrag',
|
74
|
+
'onDragEnd',
|
75
|
+
'onDragEnter',
|
76
|
+
'onDragExit',
|
77
|
+
'onDragLeave',
|
78
|
+
'onDragOver',
|
79
|
+
'onDragStart',
|
80
|
+
'onDrop',
|
81
|
+
'onMouseDown',
|
82
|
+
'onMouseDownCapture',
|
83
|
+
'onMouseEnter',
|
84
|
+
'onMouseLeave',
|
85
|
+
'onMouseMove',
|
86
|
+
'onMouseOut',
|
87
|
+
'onMouseOver',
|
88
|
+
'onMouseUp',
|
89
|
+
'onMouseUpCapture',
|
90
|
+
'onSelect',
|
91
|
+
'onTouchCancel',
|
92
|
+
'onTouchEnd',
|
93
|
+
'onTouchMove',
|
94
|
+
'onTouchStart',
|
95
|
+
'onScroll',
|
96
|
+
'onWheel',
|
97
|
+
'onPointerCancel',
|
98
|
+
'onPointerDown',
|
99
|
+
'onPointerEnter',
|
100
|
+
'onPointerLeave',
|
101
|
+
'onPointerMove',
|
102
|
+
'onPointerOut',
|
103
|
+
'onPointerOver',
|
104
|
+
'onPointerUp',
|
105
|
+
'onGotPointerCapture',
|
106
|
+
'onLostPointerCapture',
|
107
|
+
]);
|
108
|
+
/**
|
109
|
+
* An array of element attributes which are allowed on every html element type.
|
110
|
+
*
|
111
|
+
* @public
|
112
|
+
*/
|
113
|
+
exports.baseElementProperties = toObjectMap([
|
114
|
+
'accessKey',
|
115
|
+
'children',
|
116
|
+
'className',
|
117
|
+
'contentEditable',
|
118
|
+
'dir',
|
119
|
+
'draggable',
|
120
|
+
'hidden',
|
121
|
+
'htmlFor',
|
122
|
+
'id',
|
123
|
+
'lang',
|
124
|
+
'ref',
|
125
|
+
'role',
|
126
|
+
'style',
|
127
|
+
'tabIndex',
|
128
|
+
'title',
|
129
|
+
'translate',
|
130
|
+
'spellCheck',
|
131
|
+
'name', // global
|
132
|
+
]);
|
133
|
+
/**
|
134
|
+
* An array of microdata attributes that are allowed on every html element type.
|
135
|
+
*
|
136
|
+
* @public
|
137
|
+
*/
|
138
|
+
exports.microdataProperties = toObjectMap([
|
139
|
+
'itemID',
|
140
|
+
'itemProp',
|
141
|
+
'itemRef',
|
142
|
+
'itemScope',
|
143
|
+
'itemType', // global
|
144
|
+
]);
|
145
|
+
/**
|
146
|
+
* An array of HTML element properties and events.
|
147
|
+
*
|
148
|
+
* @public
|
149
|
+
*/
|
150
|
+
exports.htmlElementProperties = toObjectMap(exports.baseElementProperties, exports.baseElementEvents, exports.microdataProperties);
|
151
|
+
/**
|
152
|
+
* An array of LABEL tag properties and events.
|
153
|
+
*
|
154
|
+
* @public
|
155
|
+
*/
|
156
|
+
exports.labelProperties = toObjectMap(exports.htmlElementProperties, [
|
157
|
+
'form', // button, fieldset, input, label, meter, object, output, select, textarea
|
158
|
+
]);
|
159
|
+
/**
|
160
|
+
* An array of AUDIO tag properties and events.
|
161
|
+
|
162
|
+
* @public
|
163
|
+
*/
|
164
|
+
exports.audioProperties = toObjectMap(exports.htmlElementProperties, [
|
165
|
+
'height',
|
166
|
+
'loop',
|
167
|
+
'muted',
|
168
|
+
'preload',
|
169
|
+
'src',
|
170
|
+
'width', // canvas, embed, iframe, img, input, object, video
|
171
|
+
]);
|
172
|
+
/**
|
173
|
+
* An array of VIDEO tag properties and events.
|
174
|
+
*
|
175
|
+
* @public
|
176
|
+
*/
|
177
|
+
exports.videoProperties = toObjectMap(exports.audioProperties, [
|
178
|
+
'poster', // video
|
179
|
+
]);
|
180
|
+
/**
|
181
|
+
* An array of OL tag properties and events.
|
182
|
+
*
|
183
|
+
* @public
|
184
|
+
*/
|
185
|
+
exports.olProperties = toObjectMap(exports.htmlElementProperties, [
|
186
|
+
'start', // ol
|
187
|
+
]);
|
188
|
+
/**
|
189
|
+
* An array of LI tag properties and events.
|
190
|
+
*
|
191
|
+
* @public
|
192
|
+
*/
|
193
|
+
exports.liProperties = toObjectMap(exports.htmlElementProperties, [
|
194
|
+
'value', // button, input, li, option, meter, progress, param
|
195
|
+
]);
|
196
|
+
/**
|
197
|
+
* An array of A tag properties and events.
|
198
|
+
*
|
199
|
+
* @public
|
200
|
+
*/
|
201
|
+
exports.anchorProperties = toObjectMap(exports.htmlElementProperties, [
|
202
|
+
'download',
|
203
|
+
'href',
|
204
|
+
'hrefLang',
|
205
|
+
'media',
|
206
|
+
'rel',
|
207
|
+
'target',
|
208
|
+
'type', // a, button, input, link, menu, object, script, source, style
|
209
|
+
]);
|
210
|
+
/**
|
211
|
+
* An array of TIME tag properties and events.
|
212
|
+
*
|
213
|
+
* @public
|
214
|
+
*/
|
215
|
+
exports.timeProperties = toObjectMap(exports.htmlElementProperties, [
|
216
|
+
'dateTime', // time
|
217
|
+
]);
|
218
|
+
/**
|
219
|
+
* An array of BUTTON tag properties and events.
|
220
|
+
*
|
221
|
+
* @public
|
222
|
+
*/
|
223
|
+
exports.buttonProperties = toObjectMap(exports.htmlElementProperties, [
|
224
|
+
'autoFocus',
|
225
|
+
'disabled',
|
226
|
+
'form',
|
227
|
+
'formAction',
|
228
|
+
'formEncType',
|
229
|
+
'formMethod',
|
230
|
+
'formNoValidate',
|
231
|
+
'formTarget',
|
232
|
+
'type',
|
233
|
+
'value', // button, input, li, option, meter, progress, param,
|
234
|
+
]);
|
235
|
+
/**
|
236
|
+
* An array of INPUT tag properties and events.
|
237
|
+
*
|
238
|
+
* @public
|
239
|
+
*/
|
240
|
+
exports.inputProperties = toObjectMap(exports.buttonProperties, [
|
241
|
+
'accept',
|
242
|
+
'alt',
|
243
|
+
'autoCapitalize',
|
244
|
+
'autoComplete',
|
245
|
+
'checked',
|
246
|
+
'dirname',
|
247
|
+
'form',
|
248
|
+
'height',
|
249
|
+
'inputMode',
|
250
|
+
'list',
|
251
|
+
'max',
|
252
|
+
'maxLength',
|
253
|
+
'min',
|
254
|
+
'multiple',
|
255
|
+
'pattern',
|
256
|
+
'placeholder',
|
257
|
+
'readOnly',
|
258
|
+
'required',
|
259
|
+
'src',
|
260
|
+
'step',
|
261
|
+
'size',
|
262
|
+
'type',
|
263
|
+
'value',
|
264
|
+
'width', // canvas, embed, iframe, img, input, object, video
|
265
|
+
]);
|
266
|
+
/**
|
267
|
+
* An array of TEXTAREA tag properties and events.
|
268
|
+
*
|
269
|
+
* @public
|
270
|
+
*/
|
271
|
+
exports.textAreaProperties = toObjectMap(exports.buttonProperties, [
|
272
|
+
'autoCapitalize',
|
273
|
+
'cols',
|
274
|
+
'dirname',
|
275
|
+
'form',
|
276
|
+
'maxLength',
|
277
|
+
'placeholder',
|
278
|
+
'readOnly',
|
279
|
+
'required',
|
280
|
+
'rows',
|
281
|
+
'wrap', // textarea
|
282
|
+
]);
|
283
|
+
/**
|
284
|
+
* An array of SELECT tag properties and events.
|
285
|
+
*
|
286
|
+
* @public
|
287
|
+
*/
|
288
|
+
exports.selectProperties = toObjectMap(exports.buttonProperties, [
|
289
|
+
'form',
|
290
|
+
'multiple',
|
291
|
+
'required', // input, select, textarea
|
292
|
+
]);
|
293
|
+
exports.optionProperties = toObjectMap(exports.htmlElementProperties, [
|
294
|
+
'selected',
|
295
|
+
'value', // button, input, li, option, meter, progress, param
|
296
|
+
]);
|
297
|
+
/**
|
298
|
+
* An array of TABLE tag properties and events.
|
299
|
+
*
|
300
|
+
* @public
|
301
|
+
*/
|
302
|
+
exports.tableProperties = toObjectMap(exports.htmlElementProperties, [
|
303
|
+
'cellPadding',
|
304
|
+
'cellSpacing', // table
|
305
|
+
]);
|
306
|
+
/**
|
307
|
+
* An array of TR tag properties and events.
|
308
|
+
*
|
309
|
+
* @public
|
310
|
+
*/
|
311
|
+
exports.trProperties = exports.htmlElementProperties;
|
312
|
+
/**
|
313
|
+
* An array of TH tag properties and events.
|
314
|
+
*
|
315
|
+
* @public
|
316
|
+
*/
|
317
|
+
exports.thProperties = toObjectMap(exports.htmlElementProperties, [
|
318
|
+
'colSpan',
|
319
|
+
'rowSpan',
|
320
|
+
'scope', // th
|
321
|
+
]);
|
322
|
+
/**
|
323
|
+
* An array of TD tag properties and events.
|
324
|
+
*
|
325
|
+
* @public
|
326
|
+
*/
|
327
|
+
exports.tdProperties = toObjectMap(exports.htmlElementProperties, [
|
328
|
+
'colSpan',
|
329
|
+
'headers',
|
330
|
+
'rowSpan',
|
331
|
+
'scope', // th
|
332
|
+
]);
|
333
|
+
exports.colGroupProperties = toObjectMap(exports.htmlElementProperties, [
|
334
|
+
'span', // col, colgroup
|
335
|
+
]);
|
336
|
+
exports.colProperties = toObjectMap(exports.htmlElementProperties, [
|
337
|
+
'span', // col, colgroup
|
338
|
+
]);
|
339
|
+
/**
|
340
|
+
* An array of FIELDSET tag properties and events.
|
341
|
+
*
|
342
|
+
* @public
|
343
|
+
*/
|
344
|
+
exports.fieldsetProperties = toObjectMap(exports.htmlElementProperties, [
|
345
|
+
'disabled',
|
346
|
+
'form', // button, fieldset, input, label, meter, object, output, select, textarea
|
347
|
+
]);
|
348
|
+
/**
|
349
|
+
* An array of FORM tag properties and events.
|
350
|
+
*
|
351
|
+
* @public
|
352
|
+
*/
|
353
|
+
exports.formProperties = toObjectMap(exports.htmlElementProperties, [
|
354
|
+
'acceptCharset',
|
355
|
+
'action',
|
356
|
+
'encType',
|
357
|
+
'encType',
|
358
|
+
'method',
|
359
|
+
'noValidate',
|
360
|
+
'target', // form
|
361
|
+
]);
|
362
|
+
/**
|
363
|
+
* An array of IFRAME tag properties and events.
|
364
|
+
*
|
365
|
+
* @public
|
366
|
+
*/
|
367
|
+
exports.iframeProperties = toObjectMap(exports.htmlElementProperties, [
|
368
|
+
'allow',
|
369
|
+
'allowFullScreen',
|
370
|
+
'allowPaymentRequest',
|
371
|
+
'allowTransparency',
|
372
|
+
'csp',
|
373
|
+
'height',
|
374
|
+
'importance',
|
375
|
+
'referrerPolicy',
|
376
|
+
'sandbox',
|
377
|
+
'src',
|
378
|
+
'srcDoc',
|
379
|
+
'width', // canvas, embed, iframe, img, input, object, video,
|
380
|
+
]);
|
381
|
+
/**
|
382
|
+
* An array of IMAGE tag properties and events.
|
383
|
+
*
|
384
|
+
* @public
|
385
|
+
*/
|
386
|
+
exports.imgProperties = toObjectMap(exports.htmlElementProperties, [
|
387
|
+
'alt',
|
388
|
+
'crossOrigin',
|
389
|
+
'height',
|
390
|
+
'src',
|
391
|
+
'srcSet',
|
392
|
+
'useMap',
|
393
|
+
'width', // canvas, embed, iframe, img, input, object, video
|
394
|
+
]);
|
395
|
+
/**
|
396
|
+
* An array of DIALOG tag properties and events.
|
397
|
+
*
|
398
|
+
* @public
|
399
|
+
*/
|
400
|
+
exports.dialogProperties = toObjectMap(exports.htmlElementProperties, ['open', 'onCancel', 'onClose']);
|
401
|
+
/**
|
402
|
+
* An array of DIV tag properties and events.
|
403
|
+
*
|
404
|
+
* @public
|
405
|
+
*/
|
406
|
+
exports.divProperties = exports.htmlElementProperties;
|
407
|
+
/**
|
408
|
+
* Gets native supported props for an html element provided the allowance set. Use one of the property
|
409
|
+
* sets defined (divProperties, buttonPropertes, etc) to filter out supported properties from a given
|
410
|
+
* props set. Note that all data- and aria- prefixed attributes will be allowed.
|
411
|
+
* NOTE: getNativeProps should always be applied first when adding props to a react component. The
|
412
|
+
* non-native props should be applied second. This will prevent getNativeProps from overriding your custom props.
|
413
|
+
* For example, if props passed to getNativeProps has an onClick function and getNativeProps is added to
|
414
|
+
* the component after an onClick function is added, then the getNativeProps onClick will override it.
|
415
|
+
*
|
416
|
+
* @public
|
417
|
+
* @param props - The unfiltered input props
|
418
|
+
* @param allowedPropNames - The array or record of allowed prop names.
|
419
|
+
* @param excludedPropNames
|
420
|
+
* @returns The filtered props
|
421
|
+
*/
|
422
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
423
|
+
function getNativeProps(
|
424
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
425
|
+
props, allowedPropNames, excludedPropNames) {
|
426
|
+
// It'd be great to properly type this while allowing 'aria-` and 'data-' attributes like TypeScript does for
|
427
|
+
// JSX attributes, but that ability is hardcoded into the TS compiler with no analog in TypeScript typings.
|
428
|
+
// Then we'd be able to enforce props extends native props (including aria- and data- attributes), and then
|
429
|
+
// return native props.
|
430
|
+
// We should be able to do this once this PR is merged: https://github.com/microsoft/TypeScript/pull/26797
|
431
|
+
var isArray = Array.isArray(allowedPropNames);
|
432
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
433
|
+
var result = {};
|
434
|
+
var keys = Object.keys(props);
|
435
|
+
for (var _i = 0, keys_2 = keys; _i < keys_2.length; _i++) {
|
436
|
+
var key = keys_2[_i];
|
437
|
+
var isNativeProp = (!isArray && allowedPropNames[key]) ||
|
438
|
+
(isArray && allowedPropNames.indexOf(key) >= 0) ||
|
439
|
+
key.indexOf('data-') === 0 ||
|
440
|
+
key.indexOf('aria-') === 0;
|
441
|
+
if (isNativeProp && (!excludedPropNames || (excludedPropNames === null || excludedPropNames === void 0 ? void 0 : excludedPropNames.indexOf(key)) === -1)) {
|
442
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
443
|
+
result[key] = props[key];
|
444
|
+
}
|
445
|
+
}
|
446
|
+
return result;
|
447
|
+
}
|
448
|
+
exports.getNativeProps = getNativeProps;
|
449
|
+
});
|
450
|
+
//# sourceMappingURL=properties.js.map
|