@axium/tasks 0.1.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/LICENSE.md ADDED
@@ -0,0 +1,157 @@
1
+ # GNU LESSER GENERAL PUBLIC LICENSE
2
+
3
+ Version 3, 29 June 2007
4
+
5
+ Copyright (C) 2007 Free Software Foundation, Inc.
6
+ <https://fsf.org/>
7
+
8
+ Everyone is permitted to copy and distribute verbatim copies of this
9
+ license document, but changing it is not allowed.
10
+
11
+ This version of the GNU Lesser General Public License incorporates the
12
+ terms and conditions of version 3 of the GNU General Public License,
13
+ supplemented by the additional permissions listed below.
14
+
15
+ ## 0. Additional Definitions.
16
+
17
+ As used herein, "this License" refers to version 3 of the GNU Lesser
18
+ General Public License, and the "GNU GPL" refers to version 3 of the
19
+ GNU General Public License.
20
+
21
+ "The Library" refers to a covered work governed by this License, other
22
+ than an Application or a Combined Work as defined below.
23
+
24
+ An "Application" is any work that makes use of an interface provided
25
+ by the Library, but which is not otherwise based on the Library.
26
+ Defining a subclass of a class defined by the Library is deemed a mode
27
+ of using an interface provided by the Library.
28
+
29
+ A "Combined Work" is a work produced by combining or linking an
30
+ Application with the Library. The particular version of the Library
31
+ with which the Combined Work was made is also called the "Linked
32
+ Version".
33
+
34
+ The "Minimal Corresponding Source" for a Combined Work means the
35
+ Corresponding Source for the Combined Work, excluding any source code
36
+ for portions of the Combined Work that, considered in isolation, are
37
+ based on the Application, and not on the Linked Version.
38
+
39
+ The "Corresponding Application Code" for a Combined Work means the
40
+ object code and/or source code for the Application, including any data
41
+ and utility programs needed for reproducing the Combined Work from the
42
+ Application, but excluding the System Libraries of the Combined Work.
43
+
44
+ ## 1. Exception to Section 3 of the GNU GPL.
45
+
46
+ You may convey a covered work under sections 3 and 4 of this License
47
+ without being bound by section 3 of the GNU GPL.
48
+
49
+ ## 2. Conveying Modified Versions.
50
+
51
+ If you modify a copy of the Library, and, in your modifications, a
52
+ facility refers to a function or data to be supplied by an Application
53
+ that uses the facility (other than as an argument passed when the
54
+ facility is invoked), then you may convey a copy of the modified
55
+ version:
56
+
57
+ - a) under this License, provided that you make a good faith effort
58
+ to ensure that, in the event an Application does not supply the
59
+ function or data, the facility still operates, and performs
60
+ whatever part of its purpose remains meaningful, or
61
+ - b) under the GNU GPL, with none of the additional permissions of
62
+ this License applicable to that copy.
63
+
64
+ ## 3. Object Code Incorporating Material from Library Header Files.
65
+
66
+ The object code form of an Application may incorporate material from a
67
+ header file that is part of the Library. You may convey such object
68
+ code under terms of your choice, provided that, if the incorporated
69
+ material is not limited to numerical parameters, data structure
70
+ layouts and accessors, or small macros, inline functions and templates
71
+ (ten or fewer lines in length), you do both of the following:
72
+
73
+ - a) Give prominent notice with each copy of the object code that
74
+ the Library is used in it and that the Library and its use are
75
+ covered by this License.
76
+ - b) Accompany the object code with a copy of the GNU GPL and this
77
+ license document.
78
+
79
+ ## 4. Combined Works.
80
+
81
+ You may convey a Combined Work under terms of your choice that, taken
82
+ together, effectively do not restrict modification of the portions of
83
+ the Library contained in the Combined Work and reverse engineering for
84
+ debugging such modifications, if you also do each of the following:
85
+
86
+ - a) Give prominent notice with each copy of the Combined Work that
87
+ the Library is used in it and that the Library and its use are
88
+ covered by this License.
89
+ - b) Accompany the Combined Work with a copy of the GNU GPL and this
90
+ license document.
91
+ - c) For a Combined Work that displays copyright notices during
92
+ execution, include the copyright notice for the Library among
93
+ these notices, as well as a reference directing the user to the
94
+ copies of the GNU GPL and this license document.
95
+ - d) Do one of the following:
96
+ - 0) Convey the Minimal Corresponding Source under the terms of
97
+ this License, and the Corresponding Application Code in a form
98
+ suitable for, and under terms that permit, the user to
99
+ recombine or relink the Application with a modified version of
100
+ the Linked Version to produce a modified Combined Work, in the
101
+ manner specified by section 6 of the GNU GPL for conveying
102
+ Corresponding Source.
103
+ - 1) Use a suitable shared library mechanism for linking with
104
+ the Library. A suitable mechanism is one that (a) uses at run
105
+ time a copy of the Library already present on the user's
106
+ computer system, and (b) will operate properly with a modified
107
+ version of the Library that is interface-compatible with the
108
+ Linked Version.
109
+ - e) Provide Installation Information, but only if you would
110
+ otherwise be required to provide such information under section 6
111
+ of the GNU GPL, and only to the extent that such information is
112
+ necessary to install and execute a modified version of the
113
+ Combined Work produced by recombining or relinking the Application
114
+ with a modified version of the Linked Version. (If you use option
115
+ 4d0, the Installation Information must accompany the Minimal
116
+ Corresponding Source and Corresponding Application Code. If you
117
+ use option 4d1, you must provide the Installation Information in
118
+ the manner specified by section 6 of the GNU GPL for conveying
119
+ Corresponding Source.)
120
+
121
+ ## 5. Combined Libraries.
122
+
123
+ You may place library facilities that are a work based on the Library
124
+ side by side in a single library together with other library
125
+ facilities that are not Applications and are not covered by this
126
+ License, and convey such a combined library under terms of your
127
+ choice, if you do both of the following:
128
+
129
+ - a) Accompany the combined library with a copy of the same work
130
+ based on the Library, uncombined with any other library
131
+ facilities, conveyed under the terms of this License.
132
+ - b) Give prominent notice with the combined library that part of it
133
+ is a work based on the Library, and explaining where to find the
134
+ accompanying uncombined form of the same work.
135
+
136
+ ## 6. Revised Versions of the GNU Lesser General Public License.
137
+
138
+ The Free Software Foundation may publish revised and/or new versions
139
+ of the GNU Lesser General Public License from time to time. Such new
140
+ versions will be similar in spirit to the present version, but may
141
+ differ in detail to address new problems or concerns.
142
+
143
+ Each version is given a distinguishing version number. If the Library
144
+ as you received it specifies that a certain numbered version of the
145
+ GNU Lesser General Public License "or any later version" applies to
146
+ it, you have the option of following the terms and conditions either
147
+ of that published version or of any later version published by the
148
+ Free Software Foundation. If the Library as you received it does not
149
+ specify a version number of the GNU Lesser General Public License, you
150
+ may choose any version of the GNU Lesser General Public License ever
151
+ published by the Free Software Foundation.
152
+
153
+ If the Library as you received it specifies that a proxy can decide
154
+ whether future versions of the GNU Lesser General Public License shall
155
+ apply, that proxy's public statement of acceptance of any version is
156
+ permanent authorization for you to choose that version for the
157
+ Library.
package/README.md ADDED
@@ -0,0 +1,3 @@
1
+ # Axium Tasks
2
+
3
+ This is a plugin for managing tasks using Axium.
@@ -0,0 +1,2 @@
1
+ import type { TaskList } from './common.js';
2
+ export declare function parseList<const T extends TaskList>(list: T): T;
package/dist/client.js ADDED
@@ -0,0 +1,8 @@
1
+ export function parseList(list) {
2
+ list.created = new Date(list.created);
3
+ for (const task of list.tasks || []) {
4
+ task.created = new Date(task.created);
5
+ task.due = task.due ? new Date(task.due) : null;
6
+ }
7
+ return list;
8
+ }
@@ -0,0 +1,46 @@
1
+ import type { Permission } from '@axium/core';
2
+ import type { WithRequired } from 'utilium';
3
+ import * as z from 'zod';
4
+ export declare const TaskInit: z.ZodObject<{
5
+ summary: z.ZodDefault<z.ZodString>;
6
+ description: z.ZodNullable<z.ZodOptional<z.ZodString>>;
7
+ listId: z.ZodUUID;
8
+ parentId: z.ZodNullable<z.ZodOptional<z.ZodUUID>>;
9
+ completed: z.ZodOptional<z.ZodBoolean>;
10
+ due: z.ZodNullable<z.ZodOptional<z.ZodDate>>;
11
+ }, z.core.$strip>;
12
+ export type TaskInit = z.infer<typeof TaskInit>;
13
+ export interface Task extends TaskInit {
14
+ id: string;
15
+ created: Date;
16
+ }
17
+ export declare const TaskListInit: z.ZodObject<{
18
+ name: z.ZodString;
19
+ description: z.ZodNullable<z.ZodOptional<z.ZodString>>;
20
+ }, z.core.$strip>;
21
+ export type TaskListInit = z.infer<typeof TaskListInit>;
22
+ export interface TaskList extends TaskListInit {
23
+ id: string;
24
+ userId: string;
25
+ created: Date;
26
+ publicPermission: Permission;
27
+ tasks?: Task[];
28
+ }
29
+ declare module '@axium/core/api' {
30
+ interface _apiTypes {
31
+ 'users/:id/task_lists': {
32
+ GET: WithRequired<TaskList, 'tasks'>[];
33
+ PUT: [z.input<typeof TaskListInit>, TaskList];
34
+ };
35
+ 'task_lists/:id': {
36
+ GET: WithRequired<TaskList, 'tasks'>;
37
+ PATCH: [z.input<typeof TaskListInit>, TaskList];
38
+ PUT: [Omit<z.input<typeof TaskInit>, 'listId'>, Task];
39
+ DELETE: TaskList;
40
+ };
41
+ 'tasks/:id': {
42
+ PATCH: [Omit<z.input<typeof TaskInit>, 'listId'>, Task];
43
+ DELETE: Task;
44
+ };
45
+ }
46
+ }
package/dist/common.js ADDED
@@ -0,0 +1,13 @@
1
+ import * as z from 'zod';
2
+ export const TaskInit = z.object({
3
+ summary: z.string().max(100).default(''),
4
+ description: z.string().max(500).optional().nullable(),
5
+ listId: z.uuid(),
6
+ parentId: z.uuid().optional().nullable(),
7
+ completed: z.boolean().optional(),
8
+ due: z.date().optional().nullable(),
9
+ });
10
+ export const TaskListInit = z.object({
11
+ name: z.string().min(1).max(50),
12
+ description: z.string().max(500).optional().nullable(),
13
+ });
@@ -0,0 +1,56 @@
1
+ import './common.js';
2
+ import './server.js';
3
+ declare function statusText(): Promise<string>;
4
+ declare function db_init(): Promise<void>;
5
+ declare function db_wipe(): Promise<void>;
6
+ declare function remove(): Promise<void>;
7
+ declare const _default: {
8
+ statusText: typeof statusText;
9
+ hooks: {
10
+ db_init: typeof db_init;
11
+ db_wipe: typeof db_wipe;
12
+ remove: typeof remove;
13
+ };
14
+ name: string;
15
+ version: string;
16
+ author: string;
17
+ description: string;
18
+ funding: {
19
+ type: string;
20
+ url: string;
21
+ };
22
+ license: string;
23
+ repository: {
24
+ type: string;
25
+ url: string;
26
+ };
27
+ homepage: string;
28
+ bugs: {
29
+ url: string;
30
+ };
31
+ type: string;
32
+ main: string;
33
+ types: string;
34
+ exports: {
35
+ ".": string;
36
+ "./*": string;
37
+ "./components": string;
38
+ "./components/*": string;
39
+ };
40
+ routes: string;
41
+ files: string[];
42
+ scripts: {
43
+ build: string;
44
+ };
45
+ peerDependencies: {
46
+ "@axium/client": string;
47
+ "@axium/core": string;
48
+ "@axium/server": string;
49
+ "@sveltejs/kit": string;
50
+ utilium: string;
51
+ };
52
+ dependencies: {
53
+ zod: string;
54
+ };
55
+ };
56
+ export default _default;
package/dist/plugin.js ADDED
@@ -0,0 +1,69 @@
1
+ import * as acl from '@axium/server/acl';
2
+ import { addApp } from '@axium/server/apps';
3
+ import { count, createIndex, database, warnExists } from '@axium/server/database';
4
+ import { done, start } from '@axium/server/io';
5
+ import { sql } from 'kysely';
6
+ import pkg from '../package.json' with { type: 'json' };
7
+ import './common.js';
8
+ import './server.js';
9
+ async function statusText() {
10
+ const { tasks, task_lists } = await count('tasks', 'task_lists');
11
+ return `${tasks} tasks, ${task_lists} lists`;
12
+ }
13
+ async function db_init() {
14
+ start('Creating table task_lists');
15
+ await database.schema
16
+ .createTable('task_lists')
17
+ .addColumn('id', 'uuid', col => col.primaryKey().defaultTo(sql `gen_random_uuid()`))
18
+ .addColumn('userId', 'uuid', col => col.notNull().references('users.id').onDelete('cascade'))
19
+ .addColumn('created', 'timestamptz', col => col.notNull().defaultTo(sql `now()`))
20
+ .addColumn('publicPermission', 'integer', col => col.notNull().defaultTo(0))
21
+ .addColumn('name', 'text', col => col.notNull())
22
+ .addColumn('description', 'text')
23
+ .execute()
24
+ .then(done)
25
+ .catch(warnExists);
26
+ await createIndex('task_lists', 'userId');
27
+ await acl.createTable('task_lists');
28
+ start('Creating table tasks');
29
+ await database.schema
30
+ .createTable('tasks')
31
+ .addColumn('id', 'uuid', col => col.primaryKey().defaultTo(sql `gen_random_uuid()`))
32
+ .addColumn('created', 'timestamptz', col => col.notNull().defaultTo(sql `now()`))
33
+ .addColumn('listId', 'uuid', col => col.notNull().references('task_lists.id').onDelete('cascade'))
34
+ .addColumn('summary', 'text', col => col.notNull())
35
+ .addColumn('description', 'text')
36
+ .addColumn('parentId', 'uuid', col => col.references('tasks.id').onDelete('cascade'))
37
+ .addColumn('completed', 'boolean', col => col.notNull().defaultTo(false))
38
+ .addColumn('due', 'timestamptz')
39
+ .execute()
40
+ .then(done)
41
+ .catch(warnExists);
42
+ await createIndex('tasks', 'listId');
43
+ await createIndex('tasks', 'parentId');
44
+ }
45
+ async function db_wipe() {
46
+ start('Wiping data from tasks');
47
+ await database.deleteFrom('tasks').execute().then(done);
48
+ start('Wiping data from task_lists');
49
+ await database.deleteFrom('task_lists').execute().then(done);
50
+ await acl.wipeTable('task_lists');
51
+ }
52
+ async function remove() {
53
+ start('Dropping table tasks');
54
+ await database.schema.dropTable('tasks').execute().then(done);
55
+ start('Dropping table task_lists');
56
+ await database.schema.dropTable('task_lists').execute().then(done);
57
+ await acl.dropTable('task_lists');
58
+ }
59
+ addApp({
60
+ id: 'tasks',
61
+ name: 'Tasks',
62
+ icon: 'list-check',
63
+ version: pkg.version,
64
+ });
65
+ export default {
66
+ ...pkg,
67
+ statusText,
68
+ hooks: { db_init, db_wipe, remove },
69
+ };
@@ -0,0 +1,28 @@
1
+ import { Permission } from '@axium/core';
2
+ import type { Generated, GeneratedAlways } from 'kysely';
3
+ declare module '@axium/server/database' {
4
+ interface Schema {
5
+ tasks: {
6
+ id: GeneratedAlways<string>;
7
+ created: GeneratedAlways<Date>;
8
+ summary: string;
9
+ description?: string | null;
10
+ listId: string;
11
+ parentId?: string | null;
12
+ completed: Generated<boolean>;
13
+ due?: Date | null;
14
+ };
15
+ task_lists: {
16
+ id: GeneratedAlways<string>;
17
+ userId: string;
18
+ created: GeneratedAlways<Date>;
19
+ publicPermission: Generated<Permission>;
20
+ name: string;
21
+ description?: string | null;
22
+ };
23
+ }
24
+ interface ExpectedSchema {
25
+ tasks: ColumnTypes<Schema['tasks']>;
26
+ task_lists: ColumnTypes<Schema['task_lists']>;
27
+ }
28
+ }
package/dist/server.js ADDED
@@ -0,0 +1,142 @@
1
+ import { Permission } from '@axium/core';
2
+ import { checkAuthForItem, checkAuthForUser } from '@axium/server/auth';
3
+ import { database, expectedTypes } from '@axium/server/database';
4
+ import { parseBody, withError } from '@axium/server/requests';
5
+ import { addRoute } from '@axium/server/routes';
6
+ import * as z from 'zod';
7
+ import { TaskInit, TaskListInit } from './common.js';
8
+ import { jsonArrayFrom } from 'kysely/helpers/postgres';
9
+ expectedTypes.tasks = {
10
+ id: { type: 'uuid', required: true, hasDefault: true },
11
+ created: { type: 'timestamptz', required: true, hasDefault: true },
12
+ summary: { type: 'text', required: true },
13
+ description: { type: 'text' },
14
+ listId: { type: 'uuid', required: true },
15
+ parentId: { type: 'uuid' },
16
+ completed: { type: 'bool', required: true, hasDefault: true },
17
+ due: { type: 'timestamptz' },
18
+ };
19
+ expectedTypes.task_lists = {
20
+ id: { type: 'uuid', required: true, hasDefault: true },
21
+ userId: { type: 'uuid', required: true },
22
+ created: { type: 'timestamptz', required: true, hasDefault: true },
23
+ publicPermission: { type: 'int4', required: true, hasDefault: true },
24
+ name: { type: 'text', required: true },
25
+ description: { type: 'text' },
26
+ };
27
+ addRoute({
28
+ path: '/api/users/:id/task_lists',
29
+ params: { id: z.uuid() },
30
+ async GET(event) {
31
+ const userId = event.params.id;
32
+ await checkAuthForUser(event, userId);
33
+ const lists = await database
34
+ .selectFrom('task_lists')
35
+ .selectAll()
36
+ .select(eb => jsonArrayFrom(eb.selectFrom('tasks').selectAll().whereRef('tasks.listId', '=', 'task_lists.id')).as('tasks'))
37
+ .where('userId', '=', userId)
38
+ .execute()
39
+ .catch(withError('Could not get task lists'));
40
+ return lists.map(list => ({
41
+ ...list,
42
+ tasks: list.tasks.map(t => ({ ...t, created: new Date(t.created), due: t.due ? new Date(t.due) : null })),
43
+ }));
44
+ },
45
+ async PUT(event) {
46
+ const init = await parseBody(event, TaskListInit);
47
+ const userId = event.params.id;
48
+ await checkAuthForUser(event, userId);
49
+ return await database
50
+ .insertInto('task_lists')
51
+ .values({ ...init, userId })
52
+ .returningAll()
53
+ .executeTakeFirstOrThrow()
54
+ .catch(withError('Could not create task list'));
55
+ },
56
+ });
57
+ addRoute({
58
+ path: '/api/task_lists/:id',
59
+ params: { id: z.uuid() },
60
+ async GET(event) {
61
+ const id = event.params.id;
62
+ const { item } = await checkAuthForItem(event, 'task_lists', id, Permission.Read);
63
+ const tasks = await database
64
+ .selectFrom('tasks')
65
+ .selectAll()
66
+ .where('listId', '=', id)
67
+ .execute()
68
+ .catch(withError('Could not get tasks'));
69
+ return Object.assign(item, { tasks });
70
+ },
71
+ async PUT(event) {
72
+ const listId = event.params.id;
73
+ const init = await parseBody(event, TaskInit.omit({ listId: true }));
74
+ await checkAuthForItem(event, 'task_lists', listId, Permission.Edit);
75
+ return await database
76
+ .insertInto('tasks')
77
+ .values({ ...init, listId })
78
+ .returningAll()
79
+ .executeTakeFirstOrThrow()
80
+ .catch(withError('Could not update task list'));
81
+ },
82
+ async PATCH(event) {
83
+ const id = event.params.id;
84
+ await checkAuthForItem(event, 'task_lists', id, Permission.Edit);
85
+ const init = await parseBody(event, TaskListInit);
86
+ return await database
87
+ .updateTable('task_lists')
88
+ .set(init)
89
+ .where('id', '=', id)
90
+ .returningAll()
91
+ .executeTakeFirstOrThrow()
92
+ .catch(withError('Could not update task list'));
93
+ },
94
+ async DELETE(event) {
95
+ const id = event.params.id;
96
+ await checkAuthForItem(event, 'task_lists', id, Permission.Manage);
97
+ return await database
98
+ .deleteFrom('task_lists')
99
+ .where('id', '=', id)
100
+ .returningAll()
101
+ .executeTakeFirstOrThrow()
102
+ .catch(withError('Could not delete task list'));
103
+ },
104
+ });
105
+ addRoute({
106
+ path: '/api/tasks/:id',
107
+ params: { id: z.uuid() },
108
+ async PATCH(event) {
109
+ const init = await parseBody(event, TaskInit.omit({ listId: true }));
110
+ const id = event.params.id;
111
+ const task = await database
112
+ .selectFrom('tasks')
113
+ .select('listId')
114
+ .where('id', '=', id)
115
+ .executeTakeFirstOrThrow()
116
+ .catch(withError('Could not get task'));
117
+ await checkAuthForItem(event, 'task_lists', task.listId, Permission.Edit);
118
+ return await database
119
+ .updateTable('tasks')
120
+ .set(init)
121
+ .where('id', '=', id)
122
+ .returningAll()
123
+ .executeTakeFirstOrThrow()
124
+ .catch(withError('Could not update task'));
125
+ },
126
+ async DELETE(event) {
127
+ const id = event.params.id;
128
+ const task = await database
129
+ .selectFrom('tasks')
130
+ .select('listId')
131
+ .where('id', '=', id)
132
+ .executeTakeFirstOrThrow()
133
+ .catch(withError('Could not fetch task'));
134
+ await checkAuthForItem(event, 'task_lists', task.listId, Permission.Manage);
135
+ return await database
136
+ .deleteFrom('tasks')
137
+ .where('id', '=', id)
138
+ .returningAll()
139
+ .executeTakeFirstOrThrow()
140
+ .catch(withError('Could not delete task'));
141
+ },
142
+ });
@@ -0,0 +1,158 @@
1
+ <script lang="ts">
2
+ import { goto } from '$app/navigation';
3
+ import { fetchAPI } from '@axium/client/requests';
4
+ import { Icon, Popover } from '@axium/server/components';
5
+ import type { Task, TaskList } from '@axium/tasks/common';
6
+ import type { WithRequired } from 'utilium';
7
+
8
+ let { list = $bindable(), lists = $bindable() }: { list: WithRequired<TaskList, 'tasks'>; lists?: WithRequired<TaskList, 'tasks'>[] } =
9
+ $props();
10
+
11
+ let tasks = $state(list.tasks);
12
+ </script>
13
+
14
+ {#snippet task_tree(root: Task)}
15
+ <div class="task">
16
+ <label for="task-completed#{root.id}">
17
+ <Icon i="regular/circle{root.completed ? '-check' : ''}" --size="20px" />
18
+ </label>
19
+ <input
20
+ type="checkbox"
21
+ name="completed"
22
+ bind:checked={root.completed}
23
+ id="task-completed#{root.id}"
24
+ style:display="none"
25
+ onchange={e => {
26
+ root.completed = e.currentTarget.checked;
27
+ fetchAPI('PATCH', 'tasks/:id', { completed: root.completed }, root.id);
28
+ }}
29
+ />
30
+ <input
31
+ type="text"
32
+ name="summary"
33
+ class="editable-text"
34
+ bind:value={root.summary}
35
+ onchange={e => {
36
+ root.summary = e.currentTarget.value;
37
+ fetchAPI('PATCH', 'tasks/:id', { summary: root.summary }, root.id);
38
+ }}
39
+ />
40
+ <Popover>
41
+ <div
42
+ class="menu-item"
43
+ onclick={e => {
44
+ e.stopPropagation();
45
+ fetchAPI('DELETE', 'tasks/:id', {}, root.id).then(() => {
46
+ tasks.splice(tasks.indexOf(root), 1);
47
+ });
48
+ }}
49
+ >
50
+ <Icon i="trash" /> Delete
51
+ </div>
52
+ </Popover>
53
+ </div>
54
+ {#each tasks.filter(task => task.parentId == root.id) as child}
55
+ {@render task_tree(child)}
56
+ {/each}
57
+ {/snippet}
58
+
59
+ <div class="task-list">
60
+ <div class="task-list-header">
61
+ <input
62
+ type="text"
63
+ bind:value={list.name}
64
+ class="editable-text"
65
+ onblur={e => {
66
+ list.name = e.currentTarget.value;
67
+ fetchAPI('PATCH', 'task_lists/:id', { name: list.name }, list.id);
68
+ }}
69
+ />
70
+ <Popover>
71
+ <div
72
+ class="menu-item"
73
+ onclick={e => {
74
+ e.stopPropagation();
75
+ fetchAPI('DELETE', 'task_lists/:id', {}, list.id).then(() => {
76
+ if (!lists) goto('/tasks');
77
+ else lists.splice(lists.indexOf(list), 1);
78
+ });
79
+ }}
80
+ >
81
+ <Icon i="trash" /> Delete
82
+ </div>
83
+ </Popover>
84
+ </div>
85
+ <div>
86
+ <button
87
+ class="icon-text"
88
+ onclick={e => {
89
+ e.stopPropagation();
90
+ fetchAPI('PUT', 'task_lists/:id', { summary: '' }, list.id)
91
+ .then(t => t)
92
+ .then(tasks.push.bind(tasks));
93
+ }}
94
+ >
95
+ <Icon i="regular/circle-plus" /> Add Task
96
+ </button>
97
+ </div>
98
+ <h4>Pending</h4>
99
+ {#each tasks.filter(task => !task.parentId && !task.completed) as task}
100
+ {@render task_tree(task)}
101
+ {:else}
102
+ <i>No pending tasks.</i>
103
+ {/each}
104
+ <h4>Completed</h4>
105
+ {#each tasks.filter(task => !task.parentId && task.completed) as task}
106
+ {@render task_tree(task)}
107
+ {:else}
108
+ <i>No completed tasks.</i>
109
+ {/each}
110
+ </div>
111
+
112
+ <style>
113
+ .editable-text {
114
+ background: none;
115
+ border: none;
116
+ }
117
+
118
+ .task {
119
+ display: grid;
120
+ grid-template-columns: 1em 1fr 2em;
121
+ align-items: center;
122
+ gap: 1em;
123
+
124
+ .task {
125
+ padding-left: 1em;
126
+ }
127
+ }
128
+
129
+ .task-list {
130
+ display: flex;
131
+ flex-direction: column;
132
+ gap: 0.5em;
133
+ border-radius: 1em;
134
+ padding: 1em;
135
+ border: 1px solid #334;
136
+ background-color: #232325;
137
+ }
138
+
139
+ .task-list-header {
140
+ display: flex;
141
+ justify-content: space-between;
142
+ align-items: center;
143
+
144
+ input {
145
+ font-size: 1.5em;
146
+ font-weight: bold;
147
+ padding: 0;
148
+ }
149
+ }
150
+
151
+ .task :global(.popover-toggle) {
152
+ visibility: hidden;
153
+ }
154
+
155
+ .task:hover :global(.popover-toggle) {
156
+ visibility: visible;
157
+ }
158
+ </style>
package/lib/index.ts ADDED
@@ -0,0 +1 @@
1
+ export { default as TaskList } from './TaskList.svelte';
@@ -0,0 +1,12 @@
1
+ {
2
+ "extends": ["../tsconfig.json", "../.svelte-kit/tsconfig.json"],
3
+ "compilerOptions": {
4
+ "rootDir": "..",
5
+ "noEmit": true,
6
+ "module": "preserve",
7
+ "moduleResolution": "Bundler"
8
+ },
9
+ "include": ["**/*.svelte", "**/*.ts"],
10
+ "exclude": [],
11
+ "references": [{ "path": ".." }]
12
+ }
package/package.json ADDED
@@ -0,0 +1,47 @@
1
+ {
2
+ "name": "@axium/tasks",
3
+ "version": "0.1.0",
4
+ "author": "James Prevett <axium@jamespre.dev> (https://jamespre.dev)",
5
+ "description": "",
6
+ "funding": {
7
+ "type": "individual",
8
+ "url": "https://github.com/sponsors/james-pre"
9
+ },
10
+ "license": "LGPL-3.0-or-later",
11
+ "repository": {
12
+ "type": "git",
13
+ "url": "git+https://github.com/james-pre/axium.git"
14
+ },
15
+ "homepage": "https://github.com/james-pre/axium#readme",
16
+ "bugs": {
17
+ "url": "https://github.com/james-pre/axium/issues"
18
+ },
19
+ "type": "module",
20
+ "main": "dist/index.js",
21
+ "types": "dist/index.d.ts",
22
+ "exports": {
23
+ ".": "./dist/index.js",
24
+ "./*": "./dist/*.js",
25
+ "./components": "./lib/index.js",
26
+ "./components/*": "./lib/*.svelte"
27
+ },
28
+ "routes": "routes",
29
+ "files": [
30
+ "dist",
31
+ "lib",
32
+ "routes"
33
+ ],
34
+ "scripts": {
35
+ "build": "tsc"
36
+ },
37
+ "peerDependencies": {
38
+ "@axium/client": ">=0.1.0",
39
+ "@axium/core": ">=0.5.4",
40
+ "@axium/server": ">=0.22.0",
41
+ "@sveltejs/kit": "^2.27.3",
42
+ "utilium": "^2.3.8"
43
+ },
44
+ "dependencies": {
45
+ "zod": "^4.0.5"
46
+ }
47
+ }
@@ -0,0 +1,66 @@
1
+ <script lang="ts">
2
+ import { fetchAPI } from '@axium/client/requests';
3
+ import { Dialog, FormDialog, Icon } from '@axium/server/components';
4
+ import { parseList } from '@axium/tasks/client';
5
+ import { TaskListInit } from '@axium/tasks/common';
6
+ import { TaskList } from '@axium/tasks/components';
7
+
8
+ const { data } = $props();
9
+
10
+ let lists = $state(data.lists);
11
+ let dialog = $state<HTMLDialogElement>();
12
+ </script>
13
+
14
+ <svelte:head>
15
+ <title>Tasks</title>
16
+ </svelte:head>
17
+
18
+ <div class="tasks-main">
19
+ <h1>Tasks</h1>
20
+ <span>
21
+ <button class="icon-text" onclick={() => dialog!.showModal()}>
22
+ <Icon i="plus" /> New List
23
+ </button>
24
+ </span>
25
+ <div class="lists-container">
26
+ {#each lists as list}
27
+ <TaskList {list} bind:lists />
28
+ {/each}
29
+ </div>
30
+ </div>
31
+
32
+ <FormDialog
33
+ bind:dialog
34
+ submitText="Create List"
35
+ submit={async rawInit => {
36
+ const init = TaskListInit.parse(rawInit);
37
+ const result = await fetchAPI('PUT', 'users/:id/task_lists', init, data.session.userId);
38
+ parseList(result);
39
+ lists.push(Object.assign(result, { tasks: [] }));
40
+ }}
41
+ >
42
+ <div>
43
+ <label for="name">Name</label>
44
+ <input name="name" type="text" required />
45
+ </div>
46
+ <div>
47
+ <label for="description">Description <span class="subtle">(optional)</span></label>
48
+ <input name="description" type="text" />
49
+ </div>
50
+ </FormDialog>
51
+
52
+ <style>
53
+ .tasks-main {
54
+ padding: 2em;
55
+ inset: 0;
56
+ display: flex;
57
+ flex-direction: column;
58
+ gap: 1em;
59
+ }
60
+
61
+ .lists-container {
62
+ display: grid;
63
+ grid-template-columns: repeat(auto-fill, minmax(400px, 1fr));
64
+ gap: 1em;
65
+ }
66
+ </style>
@@ -0,0 +1,17 @@
1
+ import { fetchAPI } from '@axium/client/requests';
2
+ import { getCurrentSession } from '@axium/client/user';
3
+ import type { Session } from '@axium/core';
4
+ import { parseList } from '@axium/tasks/client';
5
+ import type { LoadEvent } from '@sveltejs/kit';
6
+
7
+ export async function load({ parent }: LoadEvent) {
8
+ let { session }: { session?: Session } = await parent();
9
+
10
+ session ||= await getCurrentSession();
11
+
12
+ const lists = await fetchAPI('GET', 'users/:id/task_lists', {}, session.userId);
13
+
14
+ for (const list of lists) parseList(list);
15
+
16
+ return { lists, session };
17
+ }
@@ -0,0 +1,11 @@
1
+ <script lang="ts">
2
+ import { TaskList } from '@axium/tasks/components';
3
+
4
+ const { data } = $props();
5
+ </script>
6
+
7
+ <svelte:head>
8
+ <title>Tasks — {data.list.name}</title>
9
+ </svelte:head>
10
+
11
+ <TaskList list={data.list} />
@@ -0,0 +1,11 @@
1
+ import { fetchAPI } from '@axium/client/requests';
2
+ import type { LoadEvent } from '@sveltejs/kit';
3
+ import { parseList } from '@axium/tasks/client';
4
+
5
+ export async function load({ params }: LoadEvent) {
6
+ const list = await fetchAPI('GET', 'task_lists/:id', {}, params.id!);
7
+
8
+ parseList(list);
9
+
10
+ return { list };
11
+ }
@@ -0,0 +1,12 @@
1
+ {
2
+ "extends": ["../tsconfig.json", "../.svelte-kit/tsconfig.json"],
3
+ "compilerOptions": {
4
+ "moduleResolution": "bundler",
5
+ "module": "esnext",
6
+ "noEmit": true,
7
+ "target": "esnext",
8
+ "rootDir": ".."
9
+ },
10
+ "include": ["**/*", "../lib/*"],
11
+ "references": [{ "path": ".." }]
12
+ }