11<script >
22import { Theme , ThemeService } from ' @primeuix/styled' ;
3- import { findSingle , isClient } from ' @primeuix/utils/dom' ;
3+ import { findSingle , isElement } from ' @primeuix/utils/dom' ;
44import { getKeyValue , isArray , isFunction , isNotEmpty , isString , resolve , toFlatCase } from ' @primeuix/utils/object' ;
5- import { uuid } from ' @primeuix/utils/uuid' ;
65import Base from ' @primevue/core/base' ;
76import BaseStyle from ' @primevue/core/base/style' ;
7+ import { useAttrSelector } from ' @primevue/core/useattrselector' ;
88import { mergeProps } from ' vue' ;
99import BaseComponentStyle from ' ./style/BaseComponentStyle' ;
1010
@@ -62,6 +62,7 @@ export default {
6262 },
6363 scopedStyleEl: undefined ,
6464 rootEl: undefined ,
65+ uid: undefined ,
6566 $attrSelector: undefined ,
6667 beforeCreate () {
6768 const _usept = this .pt ? .[' _usept' ];
@@ -75,17 +76,18 @@ export default {
7576 const valueInConfig = _useptInConfig ? this .$primevue ? .config ? .pt ? .value : this .$primevue ? .config ? .pt ;
7677
7778 (valueInConfig || originalValueInConfig)? .[this .$ .type .name ]? .hooks ? .[' onBeforeCreate' ]? .();
78- this .$attrSelector = uuid (' pc' );
79+
80+ this .$attrSelector = useAttrSelector ();
81+ this .uid = this .$attrs .id || this .$attrSelector .replace (' pc' , ' pv_id_' );
7982 },
8083 created () {
8184 this ._hook (' onCreated' );
8285 },
8386 beforeMount () {
84- // @todo - improve performance
85- this .rootEl = findSingle (this .$el , ` [data-pc-name=" ${ toFlatCase ( this .$ . type . name ) } " ]` );
87+ // @deprecated - remove in v5
88+ this .rootEl = findSingle (isElement ( this .$el ) ? this . $el : this . $el ? . parentElement , ` [${ this .$attrSelector } ]` );
8689
8790 if (this .rootEl ) {
88- this .$attrSelector && ! this .rootEl .hasAttribute (this .$attrSelector ) && this .rootEl .setAttribute (this .$attrSelector , ' ' );
8991 this .rootEl .$pc = { name: this .$ .type .name , attrSelector: this .$attrSelector , ... this .$params };
9092 }
9193
@@ -245,7 +247,7 @@ export default {
245247 ... (key === ' root' && {
246248 [` ${ datasetPrefix} name` ]: toFlatCase (isExtended ? this .pt ? .[' data-pc-section' ] : this .$ .type .name ),
247249 ... (isExtended && { [` ${ datasetPrefix} extend` ]: toFlatCase (this .$ .type .name ) }),
248- ... ( isClient () && { [` ${ this .$attrSelector } ` ]: ' ' })
250+ [` ${ this .$attrSelector } ` ]: ' '
249251 }),
250252 [` ${ datasetPrefix} section` ]: toFlatCase (key)
251253 }
@@ -301,7 +303,11 @@ export default {
301303 },
302304 ptmi (key = ' ' , params = {}) {
303305 // inheritAttrs:true
304- return mergeProps (this .$_attrsWithoutPT , this .ptm (key, params));
306+ const attrs = mergeProps (this .$_attrsWithoutPT , this .ptm (key, params));
307+
308+ attrs? .hasOwnProperty (' id' ) && (attrs .id ?? = this .$id );
309+
310+ return attrs;
305311 },
306312 ptmo (obj = {}, key = ' ' , params = {}) {
307313 return this ._getPTValue (obj, key, { instance: this , ... params }, false );
@@ -330,6 +336,9 @@ export default {
330336 isUnstyled () {
331337 return this .unstyled !== undefined ? this .unstyled : this .$primevueConfig ? .unstyled ;
332338 },
339+ $id () {
340+ return this .$attrs .id || this .uid ;
341+ },
333342 $inProps () {
334343 const nodePropKeys = Object .keys (this .$ .vnode ? .props || {});
335344
0 commit comments