mirror of
https://github.com/primefaces/primevue.git
synced 2025-05-09 17:02:38 +00:00
Fixed #4646 - Add custom wrapper support for helper components
This commit is contained in:
parent
7618f8ba7a
commit
f16bd6ab2e
14 changed files with 196 additions and 157 deletions
51
components/lib/utils/HelperSet.js
Normal file
51
components/lib/utils/HelperSet.js
Normal file
|
@ -0,0 +1,51 @@
|
|||
import ObjectUtils from './ObjectUtils';
|
||||
|
||||
export default class {
|
||||
helpers;
|
||||
type;
|
||||
constructor({ init, type }) {
|
||||
this.helpers = new Set(init);
|
||||
this.type = type;
|
||||
}
|
||||
add(instance) {
|
||||
this.helpers.add(instance);
|
||||
}
|
||||
update() {
|
||||
// @todo
|
||||
}
|
||||
delete(instance) {
|
||||
this.helpers.delete(instance);
|
||||
}
|
||||
clear() {
|
||||
this.helpers.clear();
|
||||
}
|
||||
get(parentInstance, slots) {
|
||||
const children = this._get(parentInstance, slots);
|
||||
const computed = children ? this._recursive([...this.helpers], children) : null;
|
||||
|
||||
return ObjectUtils.isNotEmpty(computed) ? computed : null;
|
||||
}
|
||||
_isMatched(instance, key) {
|
||||
const parent = instance?.parent;
|
||||
|
||||
return parent?.vnode?.key === key || (parent && this._isMatched(parent, key)) || false;
|
||||
}
|
||||
_get(parentInstance, slots) {
|
||||
return (slots || parentInstance?.$slots)?.default?.() || null;
|
||||
}
|
||||
_recursive(helpers = [], children = []) {
|
||||
let components = [];
|
||||
|
||||
children.forEach((child) => {
|
||||
if (child.children instanceof Array) {
|
||||
components = components.concat(this._recursive(components, child.children));
|
||||
} else if (child.type.name === this.type) {
|
||||
components.push(child);
|
||||
} else if (ObjectUtils.isNotEmpty(child.key)) {
|
||||
components = components.concat(helpers.filter((c) => this._isMatched(c, child.key)).map((c) => c.vnode));
|
||||
}
|
||||
});
|
||||
|
||||
return components;
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue