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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "wx-svelte-comments",
3
- "version": "2.1.0",
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.1.0",
35
+ "wx-comments-locales": "2.2.0",
36
36
  "wx-lib-data-provider": "1.6.0",
37
- "wx-lib-dom": "0.8.0",
38
- "wx-lib-state": "1.9.0",
39
- "wx-svelte-core": "2.1.0",
40
- "wx-svelte-menu": "2.1.0"
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
- A Svelte UI component for creating a comments section. Supports adding, editing, and deleting comments with ease.
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 { ...u, color: "hsl(" + getColor(u.id + u.name) + ", 100%, 85%)" };
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 { id: activeUser || -1, name: _("Me"), color: "hsl(225, 76%, 67%)" };
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((data) => {
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 = [ ...rawData ];
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={_("Add")}
208
+ buttonLabel={"Add"}
209
+ bind:value
194
210
  />
195
211
  {/if}
196
212
  </div>
@@ -50,7 +50,7 @@
50
50
  <TextArea placeholder={_("Add a comment...")} bind:value />
51
51
  </div>
52
52
  <div class="wx-textarea-bottombar">
53
- <Button type="primary" {onclick}>{buttonLabel}</Button>
53
+ <Button type="primary" {onclick}>{_(buttonLabel)}</Button>
54
54
  </div>
55
55
  </div>
56
56
 
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 api
29
+ - Data sync API
20
30
 
21
31
  ## 0.1.0
22
32