From 9b9444b6b08e1faec0cc3d299f7b9d804bdd13df Mon Sep 17 00:00:00 2001
From: mertsincan <sincan.mert@gmail.com>
Date: Fri, 7 Jul 2023 13:00:11 +0100
Subject: [PATCH] Refactor on directives

---
 components/lib/badgedirective/BadgeDirective.js | 1 +
 components/lib/basedirective/BaseDirective.js   | 7 +++----
 components/lib/focustrap/FocusTrap.js           | 8 +++-----
 components/lib/ripple/Ripple.js                 | 4 +++-
 components/lib/styleclass/StyleClass.js         | 2 ++
 components/lib/tooltip/Tooltip.js               | 2 ++
 6 files changed, 14 insertions(+), 10 deletions(-)

diff --git a/components/lib/badgedirective/BadgeDirective.js b/components/lib/badgedirective/BadgeDirective.js
index 1d51b6c9f..dbc1bf433 100644
--- a/components/lib/badgedirective/BadgeDirective.js
+++ b/components/lib/badgedirective/BadgeDirective.js
@@ -31,6 +31,7 @@ const BadgeDirective = BaseBadgeDirective.extend('badge', {
             !el.unstyled && DomHandler.addClass(badge, 'p-badge-dot');
         }
 
+        el.setAttribute('data-pd-badge', true);
         !el.unstyled && DomHandler.addClass(el, 'p-overlay-badge');
         el.setAttribute('data-p-overlay-badge', 'true');
         el.appendChild(badge);
diff --git a/components/lib/basedirective/BaseDirective.js b/components/lib/basedirective/BaseDirective.js
index 88f0d1ae2..16bfeb8a8 100644
--- a/components/lib/basedirective/BaseDirective.js
+++ b/components/lib/basedirective/BaseDirective.js
@@ -15,13 +15,12 @@ const BaseDirective = {
             : ObjectUtils.getItemValue(options, params);
     },
     _getPTValue: (instance = {}, obj = {}, key = '', params = {}, searchInDefaultPT = true) => {
-        const name = ObjectUtils.convertToFlatCase(instance.$name);
-        const datasetPrefix = name ? `data-pd-${name}` : '';
+        const datasetPrefix = 'data-pc-';
         const self = BaseDirective._getOptionValue(obj, key, params);
         const globalPT = searchInDefaultPT ? BaseDirective._getOptionValue(instance.defaultPT, key, params) : undefined;
         const merged = mergeProps(self, globalPT, {
-            ...(key === 'root' && { [datasetPrefix]: true }),
-            [`${datasetPrefix}-section`]: ObjectUtils.convertToFlatCase(key)
+            ...(key === 'root' && { [`${datasetPrefix}name`]: ObjectUtils.convertToFlatCase(instance.$name) }),
+            [`${datasetPrefix}section`]: ObjectUtils.convertToFlatCase(key)
         });
 
         return merged;
diff --git a/components/lib/focustrap/FocusTrap.js b/components/lib/focustrap/FocusTrap.js
index 51a900d9d..f9961a9b0 100644
--- a/components/lib/focustrap/FocusTrap.js
+++ b/components/lib/focustrap/FocusTrap.js
@@ -11,9 +11,7 @@ const FocusTrap = BaseFocusTrap.extend('focustrap', {
             this.autoFocus(el, binding);
         }
 
-        DomHandler.setAttributes(el, {
-            'p-bind': this.ptm('root')
-        });
+        el.setAttribute('data-pd-focustrap', true);
 
         this.$el = el;
     },
@@ -111,11 +109,11 @@ const FocusTrap = BaseFocusTrap.extend('focustrap', {
 
             firstFocusableElement.$_pfocustrap_lasthiddenfocusableelement = lastFocusableElement;
             firstFocusableElement.$_pfocustrap_focusableselector = firstFocusableSelector;
-            firstFocusableElement.setAttribute('data-pd-focustrap-section', 'firstfocusableelement');
+            firstFocusableElement.setAttribute('data-pc-section', 'firstfocusableelement');
 
             lastFocusableElement.$_pfocustrap_firsthiddenfocusableelement = firstFocusableElement;
             lastFocusableElement.$_pfocustrap_focusableselector = lastFocusableSelector;
-            lastFocusableElement.setAttribute('data-pd-focustrap-section', 'lastfocusableelement');
+            lastFocusableElement.setAttribute('data-pc-section', 'lastfocusableelement');
 
             el.prepend(firstFocusableElement);
             el.append(lastFocusableElement);
diff --git a/components/lib/ripple/Ripple.js b/components/lib/ripple/Ripple.js
index 56b528a18..846b71275 100644
--- a/components/lib/ripple/Ripple.js
+++ b/components/lib/ripple/Ripple.js
@@ -11,6 +11,8 @@ const Ripple = BaseRipple.extend('ripple', {
             this.create(el);
             this.bindEvents(el);
         }
+
+        el.setAttribute('data-pd-ripple', true);
     },
     unmounted(el) {
         this.remove(el);
@@ -91,7 +93,7 @@ const Ripple = BaseRipple.extend('ripple', {
             event.currentTarget.setAttribute('data-p-ink-active', 'false');
         },
         getInk(el) {
-            return el && el.children ? [...el.children].find((child) => DomHandler.getAttribute(child, 'data-pd-ripple')) : undefined;
+            return el && el.children ? [...el.children].find((child) => DomHandler.getAttribute(child, 'data-pc-name') === 'ripple') : undefined;
         }
     }
 });
diff --git a/components/lib/styleclass/StyleClass.js b/components/lib/styleclass/StyleClass.js
index 563f1b7d1..874feef86 100644
--- a/components/lib/styleclass/StyleClass.js
+++ b/components/lib/styleclass/StyleClass.js
@@ -3,6 +3,8 @@ import BaseStyleClass from './BaseStyleClass';
 
 const StyleClass = BaseStyleClass.extend('styleclass', {
     mounted(el, binding) {
+        el.setAttribute('data-pd-styleclass', true);
+
         this.bind(el, binding);
     },
     unmounted(el) {
diff --git a/components/lib/tooltip/Tooltip.js b/components/lib/tooltip/Tooltip.js
index 48a1793eb..2a44a3465 100755
--- a/components/lib/tooltip/Tooltip.js
+++ b/components/lib/tooltip/Tooltip.js
@@ -35,6 +35,8 @@ const Tooltip = BaseTooltip.extend('tooltip', {
         target.unstyled = options.instance.$primevue?.config?.unstyled || options.value?.unstyled || false;
 
         this.bindEvents(target, options);
+
+        el.setAttribute('data-pd-tooltip', true);
     },
     updated(el, options) {
         let target = this.getTarget(el);