43 lines
1.5 KiB
JavaScript
43 lines
1.5 KiB
JavaScript
const require_rolldown_runtime = require('../rolldown-runtime.cjs');
|
|
const vue = require_rolldown_runtime.__toESM(require("vue"));
|
|
|
|
//#region src/shared/useForwardProps.ts
|
|
/**
|
|
* The `useForwardProps` function in TypeScript takes in a set of props and returns a computed value
|
|
* that combines default props with assigned props from the current instance.
|
|
* @param {T} props - The `props` parameter is an object that represents the props passed to a
|
|
* component.
|
|
* @returns computed value that combines the default props, preserved props, and assigned props.
|
|
*/
|
|
function useForwardProps(props) {
|
|
const vm = (0, vue.getCurrentInstance)();
|
|
const defaultProps = Object.keys(vm?.type.props ?? {}).reduce((prev, curr) => {
|
|
const defaultValue = (vm?.type.props[curr]).default;
|
|
if (defaultValue !== void 0) prev[curr] = defaultValue;
|
|
return prev;
|
|
}, {});
|
|
const refProps = (0, vue.toRef)(props);
|
|
return (0, vue.computed)(() => {
|
|
const preservedProps = {};
|
|
const assignedProps = vm?.vnode.props ?? {};
|
|
Object.keys(assignedProps).forEach((key) => {
|
|
preservedProps[(0, vue.camelize)(key)] = assignedProps[key];
|
|
});
|
|
return Object.keys({
|
|
...defaultProps,
|
|
...preservedProps
|
|
}).reduce((prev, curr) => {
|
|
if (refProps.value[curr] !== void 0) prev[curr] = refProps.value[curr];
|
|
return prev;
|
|
}, {});
|
|
});
|
|
}
|
|
|
|
//#endregion
|
|
Object.defineProperty(exports, 'useForwardProps', {
|
|
enumerable: true,
|
|
get: function () {
|
|
return useForwardProps;
|
|
}
|
|
});
|
|
//# sourceMappingURL=useForwardProps.cjs.map
|