wx-svelte-tasklist 2.0.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 +21 -0
- package/package.json +53 -0
- package/readme.md +51 -0
- package/src/components/Layout.svelte +136 -0
- package/src/components/Task.svelte +192 -0
- package/src/components/Tasklist.svelte +26 -0
- package/src/index.js +3 -0
- package/whatsnew.md +11 -0
package/license.txt
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2023 XB Software Sp. z o.o.
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/package.json
ADDED
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "wx-svelte-tasklist",
|
|
3
|
+
"version": "2.0.1",
|
|
4
|
+
"description": "Simple Svelte component for adding a task list section on a page",
|
|
5
|
+
"productTag": "tasklist",
|
|
6
|
+
"productTrial": false,
|
|
7
|
+
"type": "module",
|
|
8
|
+
"scripts": {
|
|
9
|
+
"build": "vite build",
|
|
10
|
+
"build:dist": "vite build --mode dist",
|
|
11
|
+
"build:tests": "vite build --mode test",
|
|
12
|
+
"lint": "yarn eslint ./demos ./src",
|
|
13
|
+
"start": "vite --open",
|
|
14
|
+
"start:tests": "vite --open=/tests/ --host 0.0.0.0 --port 5100 --mode test",
|
|
15
|
+
"test": "true",
|
|
16
|
+
"test:cypress": "cypress run -P ./ --config \"baseUrl=http://localhost:5100/tests\""
|
|
17
|
+
},
|
|
18
|
+
"svelte": "src/index.js",
|
|
19
|
+
"exports": {
|
|
20
|
+
".": {
|
|
21
|
+
"svelte": "./src/index.js"
|
|
22
|
+
},
|
|
23
|
+
"./package.json": "./package.json"
|
|
24
|
+
},
|
|
25
|
+
"license": "MIT",
|
|
26
|
+
"repository": {
|
|
27
|
+
"type": "git",
|
|
28
|
+
"url": "https://github.com/svar-widgets/tasklist.git"
|
|
29
|
+
},
|
|
30
|
+
"bugs": {
|
|
31
|
+
"url": "https://forum.svar.dev"
|
|
32
|
+
},
|
|
33
|
+
"homepage": "https://svar.dev/svelte/tasklist/",
|
|
34
|
+
"dependencies": {
|
|
35
|
+
"wx-tasklist-locales": "2.0.1",
|
|
36
|
+
"wx-lib-data-provider": "1.6.0",
|
|
37
|
+
"wx-svelte-core": "2.0.1",
|
|
38
|
+
"wx-lib-dom": "0.7.1",
|
|
39
|
+
"wx-lib-state": "1.9.0"
|
|
40
|
+
},
|
|
41
|
+
"files": [
|
|
42
|
+
"src",
|
|
43
|
+
"readme.md",
|
|
44
|
+
"whatsnew.md",
|
|
45
|
+
"license.txt"
|
|
46
|
+
],
|
|
47
|
+
"keywords": [
|
|
48
|
+
"svelte",
|
|
49
|
+
"tasks",
|
|
50
|
+
"ui component",
|
|
51
|
+
"tasklist section"
|
|
52
|
+
]
|
|
53
|
+
}
|
package/readme.md
ADDED
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
<div align="center">
|
|
2
|
+
|
|
3
|
+
# SVAR Svelte Tasklist
|
|
4
|
+
|
|
5
|
+
[](https://www.npmjs.com/package/wx-svelte-tasklist)
|
|
6
|
+
[](https://github.com/svar-widgets/tasklist/blob/main/license.txt)
|
|
7
|
+
[](https://www.npmjs.com/package/wx-svelte-tasklist)
|
|
8
|
+
|
|
9
|
+
</div>
|
|
10
|
+
|
|
11
|
+
<div align="center">
|
|
12
|
+
|
|
13
|
+
[Documentation](https://docs.svar.dev/svelte/core/tasklist/) • [Demos](https://docs.svar.dev/svelte/core/samples-tasklist/#/base/willow)
|
|
14
|
+
|
|
15
|
+
</div>
|
|
16
|
+
|
|
17
|
+
A Svelte UI component for rendering editable list of tasks
|
|
18
|
+
|
|
19
|
+
### How to Use
|
|
20
|
+
|
|
21
|
+
To use the widget, simply import the package and include the component in your Svelte file:
|
|
22
|
+
|
|
23
|
+
```svelte
|
|
24
|
+
<script>
|
|
25
|
+
import { Tasklist } from "wx-svelte-tasklist";
|
|
26
|
+
|
|
27
|
+
const value = [];
|
|
28
|
+
</script>
|
|
29
|
+
|
|
30
|
+
<Tasklist {value} />
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
### How to Modify
|
|
34
|
+
|
|
35
|
+
Typically, you don't need to modify the code. However, if you wish to do so, follow these steps:
|
|
36
|
+
|
|
37
|
+
1. Run `yarn` to install dependencies. Note that this project is a monorepo using `yarn` workspaces, so npm will not work
|
|
38
|
+
2. Start the project in development mode with `yarn start`
|
|
39
|
+
|
|
40
|
+
### Run Tests
|
|
41
|
+
|
|
42
|
+
To run the test:
|
|
43
|
+
|
|
44
|
+
1. Start the test examples with:
|
|
45
|
+
```sh
|
|
46
|
+
yarn start:tests
|
|
47
|
+
```
|
|
48
|
+
2. In a separate console, run the end-to-end tests with:
|
|
49
|
+
```sh
|
|
50
|
+
yarn test:cypress
|
|
51
|
+
```
|
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
<script>
|
|
2
|
+
import { getContext } from "svelte";
|
|
3
|
+
import { Button } from "wx-svelte-core";
|
|
4
|
+
import { delegateClick } from "wx-lib-dom";
|
|
5
|
+
import { tempID } from "wx-lib-state";
|
|
6
|
+
import Task from "./Task.svelte";
|
|
7
|
+
|
|
8
|
+
let { data: rawData, readonly = false, onchange } = $props();
|
|
9
|
+
|
|
10
|
+
const _ = getContext("wx-i18n").getGroup("tasklist");
|
|
11
|
+
|
|
12
|
+
const data = $derived(rawData ?? []);
|
|
13
|
+
let edit = $state(null);
|
|
14
|
+
let editTask = $state(null);
|
|
15
|
+
|
|
16
|
+
function openEditor() {
|
|
17
|
+
edit = -1;
|
|
18
|
+
editTask = { id: -1, content: "", state: false };
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
function add(content) {
|
|
22
|
+
const task = {
|
|
23
|
+
id: tempID(),
|
|
24
|
+
content,
|
|
25
|
+
state: false,
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
rawData = [...data, task];
|
|
29
|
+
if (onchange) {
|
|
30
|
+
const res = onchange({ value: rawData, task, action: "add" });
|
|
31
|
+
if (res && typeof res === "object") {
|
|
32
|
+
if (res.then) {
|
|
33
|
+
res.then(data => {
|
|
34
|
+
updateAfter(task.id, data);
|
|
35
|
+
});
|
|
36
|
+
} else {
|
|
37
|
+
updateAfter(task.id, res);
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
function updateAfter(id, data) {
|
|
44
|
+
const index = rawData.findIndex(d => d.id === id);
|
|
45
|
+
|
|
46
|
+
const copy = [...rawData];
|
|
47
|
+
copy[index] = { ...rawData[index], ...data };
|
|
48
|
+
rawData = copy;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
function remove(id) {
|
|
52
|
+
if (edit === id) edit = null;
|
|
53
|
+
|
|
54
|
+
rawData = rawData.filter(d => d.id !== id);
|
|
55
|
+
if (id !== -1)
|
|
56
|
+
onchange && onchange({ value: rawData, id, action: "delete" });
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
function update(id, content, status) {
|
|
60
|
+
let task;
|
|
61
|
+
rawData = rawData.map(d => {
|
|
62
|
+
if (d.id === id) {
|
|
63
|
+
task = { ...d, content, status };
|
|
64
|
+
return task;
|
|
65
|
+
} else return d;
|
|
66
|
+
});
|
|
67
|
+
edit = null;
|
|
68
|
+
|
|
69
|
+
onchange && onchange({ value: rawData, id, action: "update", task });
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
function onremove(id) {
|
|
73
|
+
remove(id);
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
function onupdate({ task, content, status, next }) {
|
|
77
|
+
if (task.id === -1) {
|
|
78
|
+
edit = null;
|
|
79
|
+
if (content) {
|
|
80
|
+
add(content);
|
|
81
|
+
if (next) {
|
|
82
|
+
openEditor();
|
|
83
|
+
}
|
|
84
|
+
} else {
|
|
85
|
+
remove(task.id);
|
|
86
|
+
}
|
|
87
|
+
} else {
|
|
88
|
+
if (content) update(task.id, content, status);
|
|
89
|
+
else remove(task.id);
|
|
90
|
+
edit = null;
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
const bodyClickHandlers = {
|
|
95
|
+
dblclick: id => {
|
|
96
|
+
if (!readonly) edit = id;
|
|
97
|
+
},
|
|
98
|
+
};
|
|
99
|
+
</script>
|
|
100
|
+
|
|
101
|
+
<div class="wx-tasks-list">
|
|
102
|
+
<div class="wx-list" use:delegateClick={bodyClickHandlers}>
|
|
103
|
+
{#each data as task (task.id)}
|
|
104
|
+
<Task {task} {edit} {onupdate} {onremove} {readonly} />
|
|
105
|
+
{/each}
|
|
106
|
+
{#if edit === -1}
|
|
107
|
+
<Task task={editTask} {edit} {onupdate} {onremove} />
|
|
108
|
+
{/if}
|
|
109
|
+
</div>
|
|
110
|
+
{#if !readonly && edit !== -1}
|
|
111
|
+
<div class="wx-button">
|
|
112
|
+
<Button onclick={openEditor}>{_("Add task")}</Button>
|
|
113
|
+
</div>
|
|
114
|
+
{/if}
|
|
115
|
+
</div>
|
|
116
|
+
|
|
117
|
+
<style>
|
|
118
|
+
.wx-tasks-list {
|
|
119
|
+
height: 100%;
|
|
120
|
+
width: 100%;
|
|
121
|
+
display: flex;
|
|
122
|
+
flex-direction: column;
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
.wx-button {
|
|
126
|
+
width: 100%;
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
.wx-list {
|
|
130
|
+
display: flex;
|
|
131
|
+
flex-direction: column;
|
|
132
|
+
margin-bottom: 4px;
|
|
133
|
+
overflow-y: auto;
|
|
134
|
+
flex: 1;
|
|
135
|
+
}
|
|
136
|
+
</style>
|
|
@@ -0,0 +1,192 @@
|
|
|
1
|
+
<script>
|
|
2
|
+
import { getContext } from "svelte";
|
|
3
|
+
import { Checkbox } from "wx-svelte-core";
|
|
4
|
+
import { clickOutside } from "wx-lib-dom";
|
|
5
|
+
|
|
6
|
+
let { task, edit, readonly, onupdate, onremove } = $props();
|
|
7
|
+
|
|
8
|
+
const _ = getContext("wx-i18n").getGroup("tasklist");
|
|
9
|
+
|
|
10
|
+
let textarea = $state();
|
|
11
|
+
function adjustHeight() {
|
|
12
|
+
textarea.style.height = textarea.scrollHeight + 2 + "px";
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
let content = "";
|
|
16
|
+
function handleContent() {
|
|
17
|
+
content = textarea.value;
|
|
18
|
+
adjustHeight();
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
function handleStatus({ value }) {
|
|
22
|
+
onupdate({
|
|
23
|
+
task,
|
|
24
|
+
status: value ? 1 : 0,
|
|
25
|
+
content: content || task.content,
|
|
26
|
+
});
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
function saveTask(next) {
|
|
30
|
+
onupdate({ task, content: content, status: task.status, next });
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
function handleKeydown(e) {
|
|
34
|
+
if (e.key === "Escape") {
|
|
35
|
+
onupdate({ task, status: task.status, content: "" });
|
|
36
|
+
} else if (e.key === "Enter" && !e.shiftKey) {
|
|
37
|
+
e.preventDefault();
|
|
38
|
+
saveTask(true);
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
$effect(() => {
|
|
43
|
+
if (textarea) {
|
|
44
|
+
content = textarea.value = task.content;
|
|
45
|
+
textarea.focus();
|
|
46
|
+
adjustHeight();
|
|
47
|
+
}
|
|
48
|
+
});
|
|
49
|
+
</script>
|
|
50
|
+
|
|
51
|
+
<div class="wx-task" class:wx-done={task.status}>
|
|
52
|
+
<div class="wx-checkbox-wrapper">
|
|
53
|
+
{#if edit === task.id}
|
|
54
|
+
<div class="wx-icon-add"><i class="wxi-plus"></i></div>
|
|
55
|
+
{:else}
|
|
56
|
+
<Checkbox onchange={handleStatus} value={task.status} />
|
|
57
|
+
{/if}
|
|
58
|
+
</div>
|
|
59
|
+
|
|
60
|
+
<div class="wx-wrapper">
|
|
61
|
+
{#if edit === task.id}
|
|
62
|
+
<textarea
|
|
63
|
+
bind:this={textarea}
|
|
64
|
+
class="wx-texarea"
|
|
65
|
+
placeholder={_("Enter the task...")}
|
|
66
|
+
use:clickOutside={saveTask}
|
|
67
|
+
onkeydown={handleKeydown}
|
|
68
|
+
oninput={handleContent}
|
|
69
|
+
></textarea>
|
|
70
|
+
{:else}
|
|
71
|
+
<div class="wx-text-wrapper" data-id={task.id}>
|
|
72
|
+
<span class="wx-text">{task.content}</span>
|
|
73
|
+
</div>
|
|
74
|
+
{/if}
|
|
75
|
+
</div>
|
|
76
|
+
|
|
77
|
+
<div class="wx-icon-close">
|
|
78
|
+
{#if !readonly && edit !== task.id}
|
|
79
|
+
<i class="wxi-close" onclick={() => onremove(task.id)}></i>
|
|
80
|
+
{/if}
|
|
81
|
+
</div>
|
|
82
|
+
</div>
|
|
83
|
+
|
|
84
|
+
<style>
|
|
85
|
+
.wx-task {
|
|
86
|
+
display: flex;
|
|
87
|
+
padding: 8px 0 4px;
|
|
88
|
+
height: fit-content;
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
.wx-task {
|
|
92
|
+
border-top: 1px solid var(--wx-color-disabled);
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
.wx-task:last-child {
|
|
96
|
+
border-bottom: 1px solid var(--wx-color-disabled);
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
.wx-checkbox-wrapper :global(label span:first-child:before) {
|
|
100
|
+
border-radius: 50%;
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
.wx-task.wx-done
|
|
104
|
+
.wx-checkbox-wrapper
|
|
105
|
+
:global(input:checked ~ label span:first-child:before) {
|
|
106
|
+
background: #00d19a;
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
.wx-wrapper {
|
|
110
|
+
flex: 1;
|
|
111
|
+
min-height: 20px;
|
|
112
|
+
margin-left: 16px;
|
|
113
|
+
min-height: 30px;
|
|
114
|
+
height: fit-content;
|
|
115
|
+
overflow: hidden;
|
|
116
|
+
margin-top: -5px;
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
.wx-texarea {
|
|
120
|
+
display: block;
|
|
121
|
+
width: 100%;
|
|
122
|
+
resize: none;
|
|
123
|
+
outline: none;
|
|
124
|
+
height: 30px;
|
|
125
|
+
font-family: var(--wx-input-font-family);
|
|
126
|
+
font-size: var(--wx-input-font-size);
|
|
127
|
+
line-height: var(--wx-input-line-height);
|
|
128
|
+
font-weight: var(--wx-input-font-weigth);
|
|
129
|
+
text-align: var(--wx-input-text-align);
|
|
130
|
+
color: var(--wx-input-font-color);
|
|
131
|
+
border: var(--wx-input-border);
|
|
132
|
+
border-radius: var(--wx-input-border-radius);
|
|
133
|
+
background: var(--wx-input-background);
|
|
134
|
+
padding: var(--wx-input-padding);
|
|
135
|
+
box-sizing: border-box;
|
|
136
|
+
word-wrap: break-word;
|
|
137
|
+
overflow: hidden;
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
.wx-texarea:focus {
|
|
141
|
+
border: var(--wx-input-border-focus);
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
.wx-texarea::placeholder {
|
|
145
|
+
color: var(--wx-input-placeholder-color);
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
.wx-text-wrapper {
|
|
149
|
+
padding: var(--wx-input-padding);
|
|
150
|
+
border: var(--wx-input-border);
|
|
151
|
+
border: 1px solid transparent;
|
|
152
|
+
border-radius: 3px;
|
|
153
|
+
width: 100%;
|
|
154
|
+
min-height: 30px;
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
.wx-text {
|
|
158
|
+
word-wrap: break-word;
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
.wx-done .wx-text {
|
|
162
|
+
text-decoration: line-through;
|
|
163
|
+
opacity: 0.6;
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
.wx-task:hover .wx-icon-close {
|
|
167
|
+
opacity: 1;
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
.wx-icon-add {
|
|
171
|
+
font-size: var(--wx-checkbox-size);
|
|
172
|
+
color: var(--wx-color-font-alt);
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
.wx-icon-close {
|
|
176
|
+
color: var(--wx-color-font-alt);
|
|
177
|
+
margin-left: 8px;
|
|
178
|
+
font-size: 20px;
|
|
179
|
+
height: 20px;
|
|
180
|
+
width: 20px;
|
|
181
|
+
opacity: 0;
|
|
182
|
+
transition: 0.3s linear;
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
.wx-icon-close .wxi-close {
|
|
186
|
+
cursor: pointer;
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
.wx-icon-close .wxi-close:hover {
|
|
190
|
+
color: var(--wx-color-danger);
|
|
191
|
+
}
|
|
192
|
+
</style>
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
<script>
|
|
2
|
+
import Layout from "./Layout.svelte";
|
|
3
|
+
import { Locale } from "wx-svelte-core";
|
|
4
|
+
import { en } from "wx-tasklist-locales";
|
|
5
|
+
|
|
6
|
+
const { ondata, onchange, value, ...props } = $props();
|
|
7
|
+
const finalData = $derived(ondata && value ? ondata(value) : value);
|
|
8
|
+
|
|
9
|
+
const handleOnchange = e => {
|
|
10
|
+
e.originalValue = value;
|
|
11
|
+
return onchange && onchange(e);
|
|
12
|
+
};
|
|
13
|
+
</script>
|
|
14
|
+
|
|
15
|
+
<Locale words={en} optional={true}>
|
|
16
|
+
{#await finalData}
|
|
17
|
+
<Layout
|
|
18
|
+
data={[]}
|
|
19
|
+
readonly={true}
|
|
20
|
+
{...props}
|
|
21
|
+
onchange={handleOnchange}
|
|
22
|
+
/>
|
|
23
|
+
{:then data}
|
|
24
|
+
<Layout {data} {...props} onchange={handleOnchange} />
|
|
25
|
+
{/await}
|
|
26
|
+
</Locale>
|
package/src/index.js
ADDED