mirror of
https://github.com/primefaces/primevue.git
synced 2025-05-09 00:42:36 +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;
|
||||
}
|
||||
}
|
9
components/lib/utils/Utils.d.ts
vendored
9
components/lib/utils/Utils.d.ts
vendored
|
@ -102,6 +102,15 @@ export declare class ObjectUtils {
|
|||
static stringify(value: any, indent?: number, currentIndent?: number): string;
|
||||
}
|
||||
|
||||
export declare class HelperSet {
|
||||
constructor(options: { init?: any; type?: string });
|
||||
add(instance: any): void;
|
||||
update(): void;
|
||||
delete(instance: any): void;
|
||||
clear(): void;
|
||||
get(parentInstance?: any, slots?: any): any[] | null | undefined;
|
||||
}
|
||||
|
||||
export declare namespace ZIndexUtils {
|
||||
export function get(el?: HTMLElement): number;
|
||||
export function set(key: string, el: HTMLElement, baseZIndex?: number): void;
|
||||
|
|
|
@ -1,8 +1,9 @@
|
|||
import ConnectedOverlayScrollHandler from './ConnectedOverlayScrollHandler';
|
||||
import DomHandler from './DomHandler';
|
||||
import EventBus from './EventBus';
|
||||
import HelperSet from './HelperSet';
|
||||
import ObjectUtils from './ObjectUtils';
|
||||
import UniqueComponentId from './UniqueComponentId';
|
||||
import ZIndexUtils from './ZIndexUtils';
|
||||
|
||||
export { ConnectedOverlayScrollHandler, DomHandler, EventBus, ObjectUtils, UniqueComponentId, ZIndexUtils };
|
||||
export { ConnectedOverlayScrollHandler, DomHandler, EventBus, HelperSet, ObjectUtils, UniqueComponentId, ZIndexUtils };
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue