|
|
|
@ -2528,71 +2528,93 @@ export function spread_dynamic_element_attributes(node, prev, attrs, css_hash) {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* @param {import('./types.js').Signal<Record<string, unknown>> | Record<string, unknown>} props_signal
|
|
|
|
* @type {ProxyHandler<{ props: Record<string | symbol, unknown>, exclude: Array<string | symbol> }>}}
|
|
|
|
* @param {string[]} rest
|
|
|
|
|
|
|
|
* @returns {Record<string, unknown>}
|
|
|
|
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
export function rest_props(props_signal, rest) {
|
|
|
|
const rest_props_handler = {
|
|
|
|
return derived(() => {
|
|
|
|
get(target, key) {
|
|
|
|
var props = unwrap(props_signal);
|
|
|
|
if (target.exclude.includes(key)) return;
|
|
|
|
|
|
|
|
return target.props[key];
|
|
|
|
observe(props);
|
|
|
|
},
|
|
|
|
|
|
|
|
getOwnPropertyDescriptor(target, key) {
|
|
|
|
/** @type {Record<string, unknown>} */
|
|
|
|
if (target.exclude.includes(key)) return;
|
|
|
|
var rest_props = {};
|
|
|
|
if (key in target.props) {
|
|
|
|
|
|
|
|
return {
|
|
|
|
for (const key in props) {
|
|
|
|
enumerable: true,
|
|
|
|
if (rest.includes(key)) continue;
|
|
|
|
configurable: true,
|
|
|
|
|
|
|
|
value: target.props[key]
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
has(target, key) {
|
|
|
|
|
|
|
|
if (target.exclude.includes(key)) return false;
|
|
|
|
|
|
|
|
return key in target.props;
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
ownKeys(target) {
|
|
|
|
|
|
|
|
/** @type {Array<string | symbol>} */
|
|
|
|
|
|
|
|
const keys = [];
|
|
|
|
|
|
|
|
|
|
|
|
const { enumerable } = /** @type {PropertyDescriptor} */ (get_descriptor(props, key));
|
|
|
|
for (let key in target.props) {
|
|
|
|
|
|
|
|
if (!target.exclude.includes(key)) keys.push(key);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
define_property(rest_props, key, {
|
|
|
|
return keys;
|
|
|
|
get: () => props[key],
|
|
|
|
|
|
|
|
enumerable
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
return rest_props;
|
|
|
|
/**
|
|
|
|
});
|
|
|
|
* @param {import('./types.js').Signal<Record<string, unknown>> | Record<string, unknown>} props
|
|
|
|
|
|
|
|
* @param {string[]} rest
|
|
|
|
|
|
|
|
* @returns {Record<string, unknown>}
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
export function rest_props(props, rest) {
|
|
|
|
|
|
|
|
return new Proxy({ props, exclude: rest }, rest_props_handler);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* @param {Record<string, unknown>[] | (() => Record<string, unknown>[])} props
|
|
|
|
* @template {Record<string | symbol, unknown>} T
|
|
|
|
* @returns {any}
|
|
|
|
* @type {ProxyHandler<{ props: Array<T | (() => T)> }>}}
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
export function spread_props(props) {
|
|
|
|
const spread_props_handler = {
|
|
|
|
if (typeof props === 'function') {
|
|
|
|
get(target, key) {
|
|
|
|
return derived(() => {
|
|
|
|
let i = target.props.length;
|
|
|
|
return spread_props(props());
|
|
|
|
while (i--) {
|
|
|
|
});
|
|
|
|
let p = target.props[i];
|
|
|
|
|
|
|
|
if (typeof p === 'function') p = p();
|
|
|
|
|
|
|
|
if (key in p) return p[key];
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
getOwnPropertyDescriptor() {
|
|
|
|
|
|
|
|
return { enumerable: true, configurable: true };
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
has(target, key) {
|
|
|
|
|
|
|
|
for (let p of target.props) {
|
|
|
|
|
|
|
|
if (typeof p === 'function') p = p();
|
|
|
|
|
|
|
|
if (key in p) return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/** @type {Record<string, unknown>} */
|
|
|
|
return false;
|
|
|
|
const merged_props = {};
|
|
|
|
},
|
|
|
|
let key;
|
|
|
|
ownKeys(target) {
|
|
|
|
for (let i = 0; i < props.length; i++) {
|
|
|
|
/** @type {Array<string | symbol>} */
|
|
|
|
const obj = props[i];
|
|
|
|
const keys = [];
|
|
|
|
for (key in obj) {
|
|
|
|
|
|
|
|
const desc = /** @type {PropertyDescriptor} */ (get_descriptor(obj, key));
|
|
|
|
for (let p of target.props) {
|
|
|
|
const getter = desc.get;
|
|
|
|
if (typeof p === 'function') p = p();
|
|
|
|
if (getter !== undefined) {
|
|
|
|
for (const key in p) {
|
|
|
|
define_property(merged_props, key, {
|
|
|
|
if (!keys.includes(key)) keys.push(key);
|
|
|
|
enumerable: true,
|
|
|
|
|
|
|
|
configurable: true,
|
|
|
|
|
|
|
|
get: getter
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
} else if (desc.get !== undefined) {
|
|
|
|
|
|
|
|
merged_props[key] = obj[key];
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
define_property(merged_props, key, {
|
|
|
|
|
|
|
|
enumerable: true,
|
|
|
|
|
|
|
|
configurable: true,
|
|
|
|
|
|
|
|
value: obj[key]
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return keys;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return merged_props;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
|
|
* @param {Array<Record<string, unknown> | (() => Record<string, unknown>)>} props
|
|
|
|
|
|
|
|
* @returns {any}
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
export function spread_props(...props) {
|
|
|
|
|
|
|
|
return new Proxy({ props }, spread_props_handler);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
|