@liwe3/webcomponents-svelte 1.0.0 → 1.0.2
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/dist/AITextEditor.svelte
CHANGED
|
@@ -1,151 +1,212 @@
|
|
|
1
1
|
<script lang="ts">
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
2
|
+
import { onMount } from "svelte";
|
|
3
|
+
|
|
4
|
+
interface Props {
|
|
5
|
+
value?: string;
|
|
6
|
+
apiKey?: string;
|
|
7
|
+
suggestionDelay?: number;
|
|
8
|
+
systemPrompt?: string;
|
|
9
|
+
apiEndpoint?: string;
|
|
10
|
+
modelName?: string;
|
|
11
|
+
placeholder?: string;
|
|
12
|
+
|
|
13
|
+
onbeforesuggestion?: (data: any) => boolean;
|
|
14
|
+
onchange?: (value: string) => void;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
let {
|
|
18
|
+
value = $bindable(""),
|
|
19
|
+
apiKey = "",
|
|
20
|
+
suggestionDelay = 3000,
|
|
21
|
+
systemPrompt = $bindable(
|
|
22
|
+
"You are a helpful writing assistant. Continue the user's text naturally and coherently. Provide 1-3 sentences that would logically follow their writing. Keep the same tone and style. Do not repeat what they've already written."
|
|
23
|
+
),
|
|
24
|
+
apiEndpoint = "https://api.openai.com/v1/chat/completions",
|
|
25
|
+
modelName = "gpt-3.5-turbo",
|
|
26
|
+
placeholder = "Start writing your markdown text here...",
|
|
27
|
+
|
|
28
|
+
onbeforesuggestion,
|
|
29
|
+
onchange,
|
|
30
|
+
}: Props = $props();
|
|
31
|
+
|
|
32
|
+
let elementRef: HTMLElement;
|
|
33
|
+
let webComponent: any;
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* Updates the web component property and syncs with Svelte state
|
|
37
|
+
*/
|
|
38
|
+
const updateWebComponentProperty = (
|
|
39
|
+
propertyName: string,
|
|
40
|
+
newValue: any,
|
|
41
|
+
setterMethod?: string
|
|
42
|
+
) => {
|
|
43
|
+
if (!webComponent) return;
|
|
44
|
+
|
|
45
|
+
const method =
|
|
46
|
+
setterMethod ||
|
|
47
|
+
`set${propertyName.charAt(0).toUpperCase() + propertyName.slice(1)}`;
|
|
48
|
+
if (typeof webComponent[method] === "function") {
|
|
49
|
+
webComponent[method](newValue);
|
|
50
|
+
} else if (propertyName in webComponent) {
|
|
51
|
+
webComponent[propertyName] = newValue;
|
|
52
|
+
}
|
|
53
|
+
};
|
|
54
|
+
|
|
55
|
+
/**
|
|
56
|
+
* Syncs all props with the web component
|
|
57
|
+
*/
|
|
58
|
+
const syncAllProps = () => {
|
|
59
|
+
if (!webComponent) return;
|
|
60
|
+
|
|
61
|
+
updateWebComponentProperty("apiKey", apiKey);
|
|
62
|
+
updateWebComponentProperty("suggestionDelay", suggestionDelay);
|
|
63
|
+
updateWebComponentProperty("systemPrompt", systemPrompt);
|
|
64
|
+
updateWebComponentProperty("apiEndpoint", apiEndpoint);
|
|
65
|
+
updateWebComponentProperty("modelName", modelName);
|
|
66
|
+
|
|
67
|
+
// Set initial text value
|
|
68
|
+
if (value && webComponent.getText() !== value) {
|
|
69
|
+
webComponent.setText(value);
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
// Set placeholder
|
|
73
|
+
const textarea = webComponent.shadowRoot?.getElementById("editor");
|
|
74
|
+
if (textarea && placeholder) {
|
|
75
|
+
textarea.placeholder = placeholder;
|
|
76
|
+
}
|
|
77
|
+
};
|
|
78
|
+
|
|
79
|
+
$effect(() => {
|
|
80
|
+
if (webComponent && webComponent.getText() !== value) {
|
|
81
|
+
webComponent.setText(value);
|
|
82
|
+
}
|
|
83
|
+
});
|
|
84
|
+
|
|
85
|
+
$effect(() => {
|
|
86
|
+
if (webComponent) {
|
|
87
|
+
const textarea = webComponent.shadowRoot?.getElementById("editor");
|
|
88
|
+
if (textarea && placeholder) {
|
|
89
|
+
textarea.placeholder = placeholder;
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
});
|
|
93
|
+
|
|
94
|
+
onMount(async (): Promise<any> => {
|
|
95
|
+
// Dynamically import the web component
|
|
96
|
+
await import("@liwe3/webcomponents/ai-text-editor");
|
|
97
|
+
|
|
98
|
+
// Get reference to the web component
|
|
99
|
+
webComponent = elementRef;
|
|
100
|
+
|
|
101
|
+
// Sync all initial props
|
|
102
|
+
syncAllProps();
|
|
103
|
+
|
|
104
|
+
// Listen for changes from the web component
|
|
105
|
+
const handleChange = (event: CustomEvent) => {
|
|
106
|
+
const newValue = event.detail.value;
|
|
107
|
+
if (newValue !== value) {
|
|
108
|
+
value = newValue;
|
|
109
|
+
onchange?.(newValue);
|
|
110
|
+
}
|
|
111
|
+
};
|
|
112
|
+
|
|
113
|
+
// Forward beforeSuggestion event and allow parent to cancel
|
|
114
|
+
const handleBeforeSuggestion = (event: CustomEvent) => {
|
|
115
|
+
const cancel = onbeforesuggestion
|
|
116
|
+
? onbeforesuggestion(event.detail)
|
|
117
|
+
: false;
|
|
118
|
+
|
|
119
|
+
// propagate cancellation back to the underlying web component
|
|
120
|
+
if (cancel) event.preventDefault();
|
|
121
|
+
};
|
|
122
|
+
|
|
123
|
+
webComponent.addEventListener("change", handleChange);
|
|
124
|
+
webComponent.addEventListener(
|
|
125
|
+
"beforeSuggestion",
|
|
126
|
+
handleBeforeSuggestion as EventListener
|
|
127
|
+
);
|
|
128
|
+
|
|
129
|
+
// Cleanup
|
|
130
|
+
return () => {
|
|
131
|
+
webComponent?.removeEventListener("change", handleChange);
|
|
132
|
+
webComponent?.removeEventListener(
|
|
133
|
+
"beforeSuggestion",
|
|
134
|
+
handleBeforeSuggestion as EventListener
|
|
135
|
+
);
|
|
136
|
+
};
|
|
137
|
+
});
|
|
138
|
+
|
|
139
|
+
// Public methods to expose web component functionality
|
|
140
|
+
export const setText = (text: string) => {
|
|
141
|
+
value = text;
|
|
142
|
+
webComponent?.setText(text);
|
|
143
|
+
};
|
|
144
|
+
|
|
145
|
+
// Expose getText to parent components
|
|
146
|
+
export const getText = (): string => {
|
|
147
|
+
return webComponent?.getText() || "";
|
|
148
|
+
};
|
|
149
|
+
|
|
150
|
+
// Expose setContext to parent components
|
|
151
|
+
export const setContext = (context: string) => {
|
|
152
|
+
webComponent?.setContext(context);
|
|
153
|
+
};
|
|
154
|
+
|
|
155
|
+
// Expose getContext to parent components
|
|
156
|
+
export const getContext = (): string => {
|
|
157
|
+
return webComponent?.getContext() || "";
|
|
158
|
+
};
|
|
159
|
+
|
|
160
|
+
// Expose setSystemPrompt to allow changing the system prompt dynamically
|
|
161
|
+
export const setSystemPrompt = (prompt: string) => {
|
|
162
|
+
systemPrompt = prompt;
|
|
163
|
+
webComponent?.setSystemPrompt?.(prompt);
|
|
164
|
+
};
|
|
165
|
+
|
|
166
|
+
// Expose getSystemPrompt to parent components
|
|
167
|
+
export const getSystemPrompt = (): string => {
|
|
168
|
+
return webComponent?.getSystemPrompt() || systemPrompt;
|
|
169
|
+
};
|
|
170
|
+
|
|
171
|
+
// Expose setApiKey to parent components
|
|
172
|
+
export const setApiKey = (key: string) => {
|
|
173
|
+
webComponent?.setApiKey(key);
|
|
174
|
+
};
|
|
175
|
+
|
|
176
|
+
// Expose getApiKey to parent components
|
|
177
|
+
export const getApiKey = (): string => {
|
|
178
|
+
return webComponent?.getApiKey() || "";
|
|
179
|
+
};
|
|
180
|
+
|
|
181
|
+
// Expose setSuggestionDelay to parent components
|
|
182
|
+
export const setSuggestionDelay = (seconds: number) => {
|
|
183
|
+
webComponent?.setSuggestionDelay(seconds);
|
|
184
|
+
};
|
|
185
|
+
|
|
186
|
+
// Expose getSuggestionDelay to parent components
|
|
187
|
+
export const getSuggestionDelay = (): number => {
|
|
188
|
+
return webComponent?.getSuggestionDelay() || suggestionDelay;
|
|
189
|
+
};
|
|
190
|
+
|
|
191
|
+
// Expose setApiEndpoint to parent components
|
|
192
|
+
export const setApiEndpoint = (endpoint: string) => {
|
|
193
|
+
webComponent?.setApiEndpoint(endpoint);
|
|
194
|
+
};
|
|
195
|
+
|
|
196
|
+
// Expose getApiEndpoint to parent components
|
|
197
|
+
export const getApiEndpoint = (): string => {
|
|
198
|
+
return webComponent?.getApiEndpoint() || apiEndpoint;
|
|
199
|
+
};
|
|
200
|
+
|
|
201
|
+
// Expose setModelName to parent components
|
|
202
|
+
export const setModelName = (model: string) => {
|
|
203
|
+
webComponent?.setModelName(model);
|
|
204
|
+
};
|
|
205
|
+
|
|
206
|
+
// Expose getModelName to parent components
|
|
207
|
+
export const getModelName = (): string => {
|
|
208
|
+
return webComponent?.getModelName() || modelName;
|
|
209
|
+
};
|
|
149
210
|
</script>
|
|
150
211
|
|
|
151
212
|
<liwe3-ai-text-editor bind:this={elementRef}></liwe3-ai-text-editor>
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
|
|
1
|
+
interface Props {
|
|
2
2
|
value?: string;
|
|
3
3
|
apiKey?: string;
|
|
4
4
|
suggestionDelay?: number;
|
|
@@ -6,12 +6,24 @@ declare const AITextEditor: import("svelte").Component<{
|
|
|
6
6
|
apiEndpoint?: string;
|
|
7
7
|
modelName?: string;
|
|
8
8
|
placeholder?: string;
|
|
9
|
-
onbeforesuggestion: any;
|
|
10
|
-
onchange:
|
|
11
|
-
}
|
|
9
|
+
onbeforesuggestion?: (data: any) => boolean;
|
|
10
|
+
onchange?: (value: string) => void;
|
|
11
|
+
}
|
|
12
|
+
declare const AITextEditor: import("svelte").Component<Props, {
|
|
12
13
|
setText: (text: string) => void;
|
|
14
|
+
getText: () => string;
|
|
13
15
|
setContext: (context: string) => void;
|
|
16
|
+
getContext: () => string;
|
|
14
17
|
setSystemPrompt: (prompt: string) => void;
|
|
18
|
+
getSystemPrompt: () => string;
|
|
19
|
+
setApiKey: (key: string) => void;
|
|
20
|
+
getApiKey: () => string;
|
|
21
|
+
setSuggestionDelay: (seconds: number) => void;
|
|
22
|
+
getSuggestionDelay: () => number;
|
|
23
|
+
setApiEndpoint: (endpoint: string) => void;
|
|
24
|
+
getApiEndpoint: () => string;
|
|
25
|
+
setModelName: (model: string) => void;
|
|
26
|
+
getModelName: () => string;
|
|
15
27
|
}, "value" | "systemPrompt">;
|
|
16
28
|
type AITextEditor = ReturnType<typeof AITextEditor>;
|
|
17
29
|
export default AITextEditor;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"AITextEditor.svelte.d.ts","sourceRoot":"","sources":["../src/lib/AITextEditor.svelte.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"AITextEditor.svelte.d.ts","sourceRoot":"","sources":["../src/lib/AITextEditor.svelte.ts"],"names":[],"mappings":"AAME,UAAU,KAAK;IACb,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,WAAW,CAAC,EAAE,MAAM,CAAC;IAErB,kBAAkB,CAAC,EAAE,CAAC,IAAI,EAAE,GAAG,KAAK,OAAO,CAAC;IAC5C,QAAQ,CAAC,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,IAAI,CAAC;CACpC;AA4MH,QAAA,MAAM,YAAY;oBA5EQ,MAAM;mBAMT,MAAM;0BAKG,MAAM;sBAKZ,MAAM;8BAKI,MAAM;2BAMX,MAAM;qBAKV,MAAM;qBAKR,MAAM;kCAKS,MAAM;8BAKZ,MAAM;+BAKH,MAAM;0BAKb,MAAM;0BAKJ,MAAM;wBAKV,MAAM;4BASwB,CAAC;AAC3D,KAAK,YAAY,GAAG,UAAU,CAAC,OAAO,YAAY,CAAC,CAAC;AACpD,eAAe,YAAY,CAAC"}
|
package/dist/SmartSelect.svelte
CHANGED
|
@@ -1,147 +1,149 @@
|
|
|
1
1
|
<script lang="ts">
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
2
|
+
import { onMount } from "svelte";
|
|
3
|
+
import type { SelectOption } from "@liwe3/webcomponents";
|
|
4
|
+
|
|
5
|
+
interface Props {
|
|
6
|
+
multiple?: boolean;
|
|
7
|
+
searchable?: boolean;
|
|
8
|
+
placeholder?: string;
|
|
9
|
+
disabled?: boolean;
|
|
10
|
+
value?: string | string[];
|
|
11
|
+
options?: SelectOption[];
|
|
12
|
+
onchange?: (value: string | string[] | undefined) => void;
|
|
13
|
+
onopen?: (event: CustomEvent) => void;
|
|
14
|
+
onclose?: (event: CustomEvent) => void;
|
|
15
|
+
onsearch?: (event: CustomEvent) => void;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
let {
|
|
19
|
+
multiple = false,
|
|
20
|
+
searchable = false,
|
|
21
|
+
placeholder = "Select an option",
|
|
22
|
+
disabled = false,
|
|
23
|
+
value = $bindable(),
|
|
24
|
+
options = [],
|
|
25
|
+
onchange,
|
|
26
|
+
onopen,
|
|
27
|
+
onclose,
|
|
28
|
+
onsearch,
|
|
29
|
+
...restProps
|
|
30
|
+
}: Props = $props();
|
|
31
|
+
|
|
32
|
+
let smartSelectElement: HTMLElement;
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* Updates the web component's attributes based on props
|
|
36
|
+
*/
|
|
37
|
+
const updateAttributes = () => {
|
|
38
|
+
if (!smartSelectElement) return;
|
|
39
|
+
|
|
40
|
+
// Set boolean attributes
|
|
41
|
+
if (multiple) {
|
|
42
|
+
smartSelectElement.setAttribute("multiple", "");
|
|
43
|
+
} else {
|
|
44
|
+
smartSelectElement.removeAttribute("multiple");
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
if (searchable) {
|
|
48
|
+
smartSelectElement.setAttribute("searchable", "");
|
|
49
|
+
} else {
|
|
50
|
+
smartSelectElement.removeAttribute("searchable");
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
if (disabled) {
|
|
54
|
+
smartSelectElement.setAttribute("disabled", "");
|
|
55
|
+
} else {
|
|
56
|
+
smartSelectElement.removeAttribute("disabled");
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
// Set string attributes
|
|
60
|
+
smartSelectElement.setAttribute("placeholder", placeholder);
|
|
61
|
+
|
|
62
|
+
// Set options as JSON string
|
|
63
|
+
if (options.length > 0) {
|
|
64
|
+
smartSelectElement.setAttribute("options", JSON.stringify(options));
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
// Set value
|
|
68
|
+
if (value !== undefined && value !== null) {
|
|
69
|
+
if (Array.isArray(value)) {
|
|
70
|
+
(smartSelectElement as any).value = value;
|
|
71
|
+
} else {
|
|
72
|
+
(smartSelectElement as any).value = value;
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
};
|
|
76
|
+
|
|
77
|
+
/**
|
|
78
|
+
* Binds event listeners to the web component
|
|
79
|
+
*/
|
|
80
|
+
const bindEvents = () => {
|
|
81
|
+
if (!smartSelectElement) return;
|
|
82
|
+
|
|
83
|
+
smartSelectElement.addEventListener("change", (event) => {
|
|
84
|
+
const customEvent = event as CustomEvent;
|
|
85
|
+
value = customEvent.detail.value;
|
|
86
|
+
onchange?.(value);
|
|
87
|
+
});
|
|
88
|
+
|
|
89
|
+
smartSelectElement.addEventListener("open", (event) => {
|
|
90
|
+
onopen?.(event as CustomEvent);
|
|
91
|
+
});
|
|
92
|
+
|
|
93
|
+
smartSelectElement.addEventListener("close", (event) => {
|
|
94
|
+
onclose?.(event as CustomEvent);
|
|
95
|
+
});
|
|
96
|
+
|
|
97
|
+
smartSelectElement.addEventListener("search", (event) => {
|
|
98
|
+
onsearch?.(event as CustomEvent);
|
|
99
|
+
});
|
|
100
|
+
};
|
|
101
|
+
|
|
102
|
+
onMount(async () => {
|
|
103
|
+
// Dynamically import the web component
|
|
104
|
+
await import("@liwe3/webcomponents/smart-select");
|
|
105
|
+
|
|
106
|
+
updateAttributes();
|
|
107
|
+
bindEvents();
|
|
108
|
+
|
|
109
|
+
/*
|
|
109
110
|
// Watch for prop changes and update attributes
|
|
110
111
|
$effect(() => {
|
|
111
112
|
updateAttributes();
|
|
112
113
|
});
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
114
|
+
*/
|
|
115
|
+
});
|
|
116
|
+
|
|
117
|
+
/**
|
|
118
|
+
* Expose methods to parent component
|
|
119
|
+
*/
|
|
120
|
+
export const open = () => {
|
|
121
|
+
(smartSelectElement as any)?.open();
|
|
122
|
+
};
|
|
123
|
+
|
|
124
|
+
export const close = () => {
|
|
125
|
+
(smartSelectElement as any)?.close();
|
|
126
|
+
};
|
|
127
|
+
|
|
128
|
+
export const toggle = () => {
|
|
129
|
+
(smartSelectElement as any)?.toggle();
|
|
130
|
+
};
|
|
131
|
+
|
|
132
|
+
export const selectOption = (optionValue: string) => {
|
|
133
|
+
(smartSelectElement as any)?.selectOption(optionValue);
|
|
134
|
+
};
|
|
135
|
+
|
|
136
|
+
export const deselectOption = (optionValue: string) => {
|
|
137
|
+
(smartSelectElement as any)?.deselectOption(optionValue);
|
|
138
|
+
};
|
|
139
|
+
|
|
140
|
+
export const getSelectedOptions = () => {
|
|
141
|
+
return (smartSelectElement as any)?.getSelectedOptions() || [];
|
|
142
|
+
};
|
|
143
|
+
|
|
144
|
+
export const setOptions = (newOptions: SelectOption[]) => {
|
|
145
|
+
(smartSelectElement as any)?.setOptions(newOptions);
|
|
146
|
+
};
|
|
145
147
|
</script>
|
|
146
148
|
|
|
147
149
|
<!-- svelte-ignore a11y_unknown_aria_attribute -->
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { SelectOption } from
|
|
1
|
+
import type { SelectOption } from "@liwe3/webcomponents";
|
|
2
2
|
interface Props {
|
|
3
3
|
multiple?: boolean;
|
|
4
4
|
searchable?: boolean;
|
|
@@ -13,8 +13,8 @@ interface Props {
|
|
|
13
13
|
}
|
|
14
14
|
declare const SmartSelect: import("svelte").Component<Props, {
|
|
15
15
|
/**
|
|
16
|
-
|
|
17
|
-
|
|
16
|
+
* Expose methods to parent component
|
|
17
|
+
*/ open: () => void;
|
|
18
18
|
close: () => void;
|
|
19
19
|
toggle: () => void;
|
|
20
20
|
selectOption: (optionValue: string) => void;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SmartSelect.svelte.d.ts","sourceRoot":"","sources":["../src/lib/SmartSelect.svelte.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,sBAAsB,CAAC;
|
|
1
|
+
{"version":3,"file":"SmartSelect.svelte.d.ts","sourceRoot":"","sources":["../src/lib/SmartSelect.svelte.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,sBAAsB,CAAC;AAGvD,UAAU,KAAK;IACb,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,UAAU,CAAC,EAAE,OAAO,CAAC;IACrB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,KAAK,CAAC,EAAE,MAAM,GAAG,MAAM,EAAE,CAAC;IAC1B,OAAO,CAAC,EAAE,YAAY,EAAE,CAAC;IACzB,QAAQ,CAAC,EAAE,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,EAAE,GAAG,SAAS,KAAK,IAAI,CAAC;IAC1D,MAAM,CAAC,EAAE,CAAC,KAAK,EAAE,WAAW,KAAK,IAAI,CAAC;IACtC,OAAO,CAAC,EAAE,CAAC,KAAK,EAAE,WAAW,KAAK,IAAI,CAAC;IACvC,QAAQ,CAAC,EAAE,CAAC,KAAK,EAAE,WAAW,KAAK,IAAI,CAAC;CACzC;AAiJH,QAAA,MAAM,WAAW;IAHjB;;SAEK;;;gCAxBiC,MAAM;kCAIJ,MAAM;;6BAQX,YAAY,EAAE;WAaQ,CAAC;AAC1D,KAAK,WAAW,GAAG,UAAU,CAAC,OAAO,WAAW,CAAC,CAAC;AAClD,eAAe,WAAW,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@liwe3/webcomponents-svelte",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.2",
|
|
4
4
|
"description": "Svelte 5 wrappers for @liwe3/webcomponents",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"svelte": "./dist/index.js",
|
|
@@ -17,8 +17,9 @@
|
|
|
17
17
|
"!dist/**/*.spec.*"
|
|
18
18
|
],
|
|
19
19
|
"scripts": {
|
|
20
|
-
"
|
|
21
|
-
"
|
|
20
|
+
"dev": "svelte-package --watch",
|
|
21
|
+
"build": "svelte-package && publint",
|
|
22
|
+
"package": "svelte-package && publint",
|
|
22
23
|
"prepublishOnly": "pnpm run package",
|
|
23
24
|
"check": "svelte-check --tsconfig ./tsconfig.json",
|
|
24
25
|
"check:watch": "svelte-check --tsconfig ./tsconfig.json --watch"
|
|
@@ -40,6 +41,8 @@
|
|
|
40
41
|
},
|
|
41
42
|
"devDependencies": {
|
|
42
43
|
"@liwe3/webcomponents": "workspace:*",
|
|
44
|
+
"@sveltejs/adapter-auto": "^3.0.0",
|
|
45
|
+
"@sveltejs/kit": "^2.0.0",
|
|
43
46
|
"@sveltejs/package": "^2.0.0",
|
|
44
47
|
"@sveltejs/vite-plugin-svelte": "^5.0.0",
|
|
45
48
|
"publint": "^0.2.0",
|
|
@@ -52,4 +55,4 @@
|
|
|
52
55
|
"access": "public"
|
|
53
56
|
},
|
|
54
57
|
"packageManager": "pnpm@10.16.0"
|
|
55
|
-
}
|
|
58
|
+
}
|