wx-svelte-comments 2.1.0 → 2.2.0
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 +6 -6
- package/readme.md +8 -2
- package/src/components/Layout.svelte +32 -16
- package/src/components/TextArea.svelte +1 -1
- package/whatsnew.md +11 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "wx-svelte-comments",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.2.0",
|
|
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,12 @@
|
|
|
32
32
|
},
|
|
33
33
|
"homepage": "https://svar.dev/svelte/core/",
|
|
34
34
|
"dependencies": {
|
|
35
|
-
"wx-comments-locales": "2.
|
|
35
|
+
"wx-comments-locales": "2.2.0",
|
|
36
36
|
"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.
|
|
37
|
+
"wx-lib-dom": "0.9.1",
|
|
38
|
+
"wx-lib-state": "1.9.3",
|
|
39
|
+
"wx-svelte-core": "2.2.0",
|
|
40
|
+
"wx-svelte-menu": "2.2.0"
|
|
41
41
|
},
|
|
42
42
|
"files": [
|
|
43
43
|
"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>
|
|
@@ -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
|
}
|
|
@@ -190,7 +205,8 @@
|
|
|
190
205
|
flow={render === "flow"}
|
|
191
206
|
{focus}
|
|
192
207
|
onpost={ev => add(ev.value)}
|
|
193
|
-
buttonLabel={
|
|
208
|
+
buttonLabel={"Add"}
|
|
209
|
+
bind:value
|
|
194
210
|
/>
|
|
195
211
|
{/if}
|
|
196
212
|
</div>
|
package/whatsnew.md
CHANGED
|
@@ -1,3 +1,13 @@
|
|
|
1
|
+
## 2.2.0
|
|
2
|
+
|
|
3
|
+
### New features
|
|
4
|
+
|
|
5
|
+
- Ability to localize text labels
|
|
6
|
+
|
|
7
|
+
### Fixes
|
|
8
|
+
|
|
9
|
+
- Input is not cleared when data is reloaded
|
|
10
|
+
|
|
1
11
|
## 2.1.0
|
|
2
12
|
|
|
3
13
|
- Using core@2.1.0, menu@2.1.0
|
|
@@ -16,7 +26,7 @@
|
|
|
16
26
|
|
|
17
27
|
### Updates
|
|
18
28
|
|
|
19
|
-
- Data sync
|
|
29
|
+
- Data sync API
|
|
20
30
|
|
|
21
31
|
## 0.1.0
|
|
22
32
|
|