wx-svelte-comments 2.1.1 → 2.2.1
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/license.txt +1 -1
- package/package.json +7 -6
- package/readme.md +8 -2
- package/src/components/Comments.svelte +2 -1
- package/src/components/Layout.svelte +35 -18
- package/src/components/TextArea.svelte +1 -1
- package/whatsnew.md +18 -1
package/license.txt
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "wx-svelte-comments",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.2.1",
|
|
4
4
|
"description": "Simple Svelte component for adding a comments section on a page",
|
|
5
5
|
"productTag": "comments",
|
|
6
6
|
"productTrial": false,
|
|
@@ -32,12 +32,13 @@
|
|
|
32
32
|
},
|
|
33
33
|
"homepage": "https://svar.dev/svelte/core/",
|
|
34
34
|
"dependencies": {
|
|
35
|
-
"wx-comments-locales": "2.
|
|
35
|
+
"wx-comments-locales": "2.2.1",
|
|
36
|
+
"wx-core-locales": "2.2.1",
|
|
36
37
|
"wx-lib-data-provider": "1.6.0",
|
|
37
|
-
"wx-lib-dom": "0.
|
|
38
|
-
"wx-lib-state": "1.9.
|
|
39
|
-
"wx-svelte-core": "2.
|
|
40
|
-
"wx-svelte-menu": "2.
|
|
38
|
+
"wx-lib-dom": "0.9.1",
|
|
39
|
+
"wx-lib-state": "1.9.3",
|
|
40
|
+
"wx-svelte-core": "2.2.1",
|
|
41
|
+
"wx-svelte-menu": "2.2.1"
|
|
41
42
|
},
|
|
42
43
|
"files": [
|
|
43
44
|
"src",
|
package/readme.md
CHANGED
|
@@ -14,11 +14,17 @@
|
|
|
14
14
|
|
|
15
15
|
</div>
|
|
16
16
|
|
|
17
|
-
|
|
17
|
+
**SVAR Svelte Comments** is a UI component for creating a clean and modern comments section. Supports adding, editing, and deleting comments with ease.
|
|
18
|
+
|
|
19
|
+
<div align="center">
|
|
20
|
+
|
|
21
|
+
<img src="https://svar.dev/images/github/github-commenta.png" alt="SVAR Comments - Svelte Comments Section" style="width: 700px;">
|
|
22
|
+
|
|
23
|
+
</div>
|
|
18
24
|
|
|
19
25
|
### How to Use
|
|
20
26
|
|
|
21
|
-
To use the widget, simply import the package and include the component in your Svelte file:
|
|
27
|
+
To use the Comments widget, simply import the package and include the component in your Svelte file:
|
|
22
28
|
|
|
23
29
|
```svelte
|
|
24
30
|
<script>
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
import Layout from "./Layout.svelte";
|
|
3
3
|
import { Locale } from "wx-svelte-core";
|
|
4
4
|
import { en } from "wx-comments-locales";
|
|
5
|
+
import { en as coreEn } from "wx-core-locales";
|
|
5
6
|
|
|
6
7
|
const { ondata, onchange, value, ...props } = $props();
|
|
7
8
|
const finalData = $derived(ondata && value ? ondata(value) : value);
|
|
@@ -12,7 +13,7 @@
|
|
|
12
13
|
};
|
|
13
14
|
</script>
|
|
14
15
|
|
|
15
|
-
<Locale words={en} optional={true}>
|
|
16
|
+
<Locale words={{ ...coreEn, ...en }} optional={true}>
|
|
16
17
|
{#await finalData}
|
|
17
18
|
<Layout data={[]} {...props} onchange={handleOnchange} />
|
|
18
19
|
{:then data}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
<script>
|
|
2
|
-
import { getContext, setContext } from "svelte";
|
|
2
|
+
import { getContext, setContext, untrack } from "svelte";
|
|
3
3
|
import Messages from "./Messages.svelte";
|
|
4
4
|
import TextArea from "./TextArea.svelte";
|
|
5
5
|
import { ActionMenu } from "wx-svelte-menu";
|
|
@@ -18,7 +18,6 @@
|
|
|
18
18
|
focus = false,
|
|
19
19
|
} = $props();
|
|
20
20
|
|
|
21
|
-
let edit = $state(null);
|
|
22
21
|
const lang = getContext("wx-i18n");
|
|
23
22
|
const { calendar, comments, formats } = lang.getRaw();
|
|
24
23
|
const _ = lang.getGroup("comments");
|
|
@@ -31,13 +30,28 @@
|
|
|
31
30
|
dateStr: date => dateFormatter(date),
|
|
32
31
|
});
|
|
33
32
|
|
|
33
|
+
let edit = $state(null);
|
|
34
|
+
let value = $state("");
|
|
35
|
+
|
|
36
|
+
$effect(() => {
|
|
37
|
+
rawData;
|
|
38
|
+
untrack(() => {
|
|
39
|
+
// Clear editing state when rawData is updated
|
|
40
|
+
value = "";
|
|
41
|
+
edit = null;
|
|
42
|
+
});
|
|
43
|
+
});
|
|
44
|
+
|
|
34
45
|
const unknownUser = { id: 0, name: _("Unknown"), color: "hsl(0, 0%, 85%)" };
|
|
35
46
|
|
|
36
47
|
const users = $derived.by(() => {
|
|
37
48
|
if (!rawUsers) return [];
|
|
38
49
|
return rawUsers.map(u => {
|
|
39
|
-
if (!u.color)
|
|
40
|
-
return {
|
|
50
|
+
if (!u.color)
|
|
51
|
+
return {
|
|
52
|
+
...u,
|
|
53
|
+
color: "hsl(" + getColor(u.id + u.name) + ", 100%, 85%)",
|
|
54
|
+
};
|
|
41
55
|
return u;
|
|
42
56
|
});
|
|
43
57
|
});
|
|
@@ -46,7 +60,11 @@
|
|
|
46
60
|
if (typeof activeUser === "object") return activeUser;
|
|
47
61
|
const a = users.find(u => u.id === activeUser) || unknownUser;
|
|
48
62
|
if (a) return a;
|
|
49
|
-
return {
|
|
63
|
+
return {
|
|
64
|
+
id: activeUser || -1,
|
|
65
|
+
name: _("Me"),
|
|
66
|
+
color: "hsl(225, 76%, 67%)",
|
|
67
|
+
};
|
|
50
68
|
});
|
|
51
69
|
|
|
52
70
|
const data = $derived.by(() => {
|
|
@@ -83,11 +101,11 @@
|
|
|
83
101
|
};
|
|
84
102
|
|
|
85
103
|
rawData = [...data, comment];
|
|
86
|
-
if (onchange){
|
|
87
|
-
const res = onchange({ value:rawData, comment, action: "add" });
|
|
88
|
-
if (res && typeof res === "object"){
|
|
89
|
-
if (res.then){
|
|
90
|
-
res.then(
|
|
104
|
+
if (onchange) {
|
|
105
|
+
const res = onchange({ value: rawData, comment, action: "add" });
|
|
106
|
+
if (res && typeof res === "object") {
|
|
107
|
+
if (res.then) {
|
|
108
|
+
res.then(data => {
|
|
91
109
|
updateAfter(comment.id, data);
|
|
92
110
|
});
|
|
93
111
|
} else {
|
|
@@ -97,17 +115,15 @@
|
|
|
97
115
|
}
|
|
98
116
|
}
|
|
99
117
|
|
|
100
|
-
function updateAfter(id, data){
|
|
118
|
+
function updateAfter(id, data) {
|
|
101
119
|
const index = rawData.findIndex(d => d.id === id);
|
|
102
120
|
|
|
103
|
-
const copy = [
|
|
121
|
+
const copy = [...rawData];
|
|
104
122
|
copy[index] = { ...rawData[index], ...data };
|
|
105
123
|
rawData = copy;
|
|
106
124
|
}
|
|
107
125
|
|
|
108
126
|
function remove(id) {
|
|
109
|
-
if (edit === id) edit = null;
|
|
110
|
-
|
|
111
127
|
rawData = rawData.filter(d => d.id !== id);
|
|
112
128
|
onchange && onchange({ value: rawData, id, action: "delete" });
|
|
113
129
|
}
|
|
@@ -120,7 +136,6 @@
|
|
|
120
136
|
return comment;
|
|
121
137
|
} else return d;
|
|
122
138
|
});
|
|
123
|
-
edit = null;
|
|
124
139
|
|
|
125
140
|
onchange && onchange({ value: rawData, id, action: "update", comment });
|
|
126
141
|
}
|
|
@@ -159,7 +174,8 @@
|
|
|
159
174
|
},
|
|
160
175
|
];
|
|
161
176
|
|
|
162
|
-
let menu =
|
|
177
|
+
let menu = null;
|
|
178
|
+
const showMenu = ev => menu.show(ev);
|
|
163
179
|
</script>
|
|
164
180
|
|
|
165
181
|
<!-- svelte-ignore a11y_click_events_have_key_events -->
|
|
@@ -173,7 +189,7 @@
|
|
|
173
189
|
dataKey="commentMenuId"
|
|
174
190
|
onclick={handleActionMenu}
|
|
175
191
|
/>
|
|
176
|
-
<div class="wx-list" onclick={
|
|
192
|
+
<div class="wx-list" onclick={showMenu}>
|
|
177
193
|
<Messages
|
|
178
194
|
{author}
|
|
179
195
|
{render}
|
|
@@ -190,7 +206,8 @@
|
|
|
190
206
|
flow={render === "flow"}
|
|
191
207
|
{focus}
|
|
192
208
|
onpost={ev => add(ev.value)}
|
|
193
|
-
buttonLabel={
|
|
209
|
+
buttonLabel={"Add"}
|
|
210
|
+
bind:value
|
|
194
211
|
/>
|
|
195
212
|
{/if}
|
|
196
213
|
</div>
|
package/whatsnew.md
CHANGED
|
@@ -1,3 +1,20 @@
|
|
|
1
|
+
## 2.2.1
|
|
2
|
+
|
|
3
|
+
### Fixes
|
|
4
|
+
|
|
5
|
+
- Using in Salesforce environment
|
|
6
|
+
- Applying default base locale
|
|
7
|
+
|
|
8
|
+
## 2.2.0
|
|
9
|
+
|
|
10
|
+
### New features
|
|
11
|
+
|
|
12
|
+
- Ability to localize text labels
|
|
13
|
+
|
|
14
|
+
### Fixes
|
|
15
|
+
|
|
16
|
+
- Input is not cleared when data is reloaded
|
|
17
|
+
|
|
1
18
|
## 2.1.0
|
|
2
19
|
|
|
3
20
|
- Using core@2.1.0, menu@2.1.0
|
|
@@ -16,7 +33,7 @@
|
|
|
16
33
|
|
|
17
34
|
### Updates
|
|
18
35
|
|
|
19
|
-
- Data sync
|
|
36
|
+
- Data sync API
|
|
20
37
|
|
|
21
38
|
## 0.1.0
|
|
22
39
|
|