@ansiversa/components 0.0.128 → 0.0.129
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json
CHANGED
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
interface Props {
|
|
3
3
|
featureKey: string;
|
|
4
4
|
value: string;
|
|
5
|
+
valueSourceSelector?: string;
|
|
5
6
|
minChars?: number;
|
|
6
7
|
maxChars?: number;
|
|
7
8
|
label?: string;
|
|
@@ -13,6 +14,7 @@ interface Props {
|
|
|
13
14
|
const {
|
|
14
15
|
featureKey,
|
|
15
16
|
value,
|
|
17
|
+
valueSourceSelector,
|
|
16
18
|
minChars = 30,
|
|
17
19
|
maxChars = 1500,
|
|
18
20
|
label = "AI",
|
|
@@ -31,6 +33,7 @@ const componentId = `av-ai-assist-${Math.random().toString(36).slice(2, 10)}`;
|
|
|
31
33
|
{...rest}
|
|
32
34
|
x-data={`avAiAssist(${JSON.stringify({
|
|
33
35
|
featureKey,
|
|
36
|
+
valueSourceSelector: valueSourceSelector ?? null,
|
|
34
37
|
minChars,
|
|
35
38
|
maxChars,
|
|
36
39
|
label,
|
|
@@ -97,6 +100,10 @@ const componentId = `av-ai-assist-${Math.random().toString(36).slice(2, 10)}`;
|
|
|
97
100
|
if (typeof window !== "undefined" && !window.avAiAssist) {
|
|
98
101
|
window.avAiAssist = (config) => ({
|
|
99
102
|
featureKey: config.featureKey,
|
|
103
|
+
valueSourceSelector:
|
|
104
|
+
typeof config.valueSourceSelector === "string" && config.valueSourceSelector.trim()
|
|
105
|
+
? config.valueSourceSelector.trim()
|
|
106
|
+
: null,
|
|
100
107
|
minChars: Number(config.minChars ?? 30),
|
|
101
108
|
maxChars: Number(config.maxChars ?? 1500),
|
|
102
109
|
label: typeof config.label === "string" && config.label ? config.label : "AI",
|
|
@@ -109,8 +116,17 @@ const componentId = `av-ai-assist-${Math.random().toString(36).slice(2, 10)}`;
|
|
|
109
116
|
suggestions: [],
|
|
110
117
|
copiedIndex: null,
|
|
111
118
|
observer: null,
|
|
119
|
+
sourceElement: null,
|
|
112
120
|
|
|
113
121
|
init() {
|
|
122
|
+
if (this.valueSourceSelector) {
|
|
123
|
+
this.sourceElement = document.querySelector(this.valueSourceSelector);
|
|
124
|
+
if (this.sourceElement) {
|
|
125
|
+
this.sourceElement.addEventListener("input", () => this.syncValue());
|
|
126
|
+
this.sourceElement.addEventListener("change", () => this.syncValue());
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
|
|
114
130
|
this.syncValue();
|
|
115
131
|
|
|
116
132
|
if (typeof MutationObserver !== "undefined") {
|
|
@@ -136,6 +152,11 @@ const componentId = `av-ai-assist-${Math.random().toString(36).slice(2, 10)}`;
|
|
|
136
152
|
},
|
|
137
153
|
|
|
138
154
|
syncValue() {
|
|
155
|
+
if (this.sourceElement && typeof this.sourceElement.value === "string") {
|
|
156
|
+
this.value = this.sourceElement.value;
|
|
157
|
+
return;
|
|
158
|
+
}
|
|
159
|
+
|
|
139
160
|
const nextValue = this.$el.getAttribute("data-value") ?? "";
|
|
140
161
|
this.value = String(nextValue);
|
|
141
162
|
},
|