@axium/tasks 0.5.8 → 0.5.9

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.
@@ -2,6 +2,7 @@
2
2
  import { goto } from '$app/navigation';
3
3
  import { page } from '$app/state';
4
4
  import { fetchAPI, preferences, text } from '@axium/client';
5
+ import { contextMenu, dynamicRows, type ContextMenuItem } from '@axium/client/attachments';
5
6
  import { AccessControlDialog, Icon, Popover } from '@axium/client/components';
6
7
  import { copy } from '@axium/client/web';
7
8
  import { toastStatus } from '@axium/client/toast';
@@ -40,6 +41,30 @@
40
41
  return `[${task.completed ? 'x' : ' '}] ${task.summary}` + children;
41
42
  }
42
43
 
44
+ function taskActions(task: Task): WithRequired<ContextMenuItem, 'i'>[] {
45
+ const actions: WithRequired<ContextMenuItem, 'i'>[] = [
46
+ {
47
+ i: 'arrow-turn-down-right',
48
+ text: text('tasks.add_subtask'),
49
+ action: () => fetchAPI('PUT', 'task_lists/:id', { summary: '', parentId: task.id }, list.id).then(t => tasks.push(t)),
50
+ },
51
+ {
52
+ i: 'trash',
53
+ text: text('generic.delete'),
54
+ action: () =>
55
+ toastStatus(
56
+ fetchAPI('DELETE', 'tasks/:id', {}, task.id).then(() => {
57
+ tasks.splice(tasks.indexOf(task), 1);
58
+ }),
59
+ text('tasks.toast_task_deleted')
60
+ ),
61
+ },
62
+ ];
63
+ if (user?.preferences?.debug)
64
+ actions.push({ i: 'hashtag', text: text('tasks.copy_id'), action: () => copy('text/plain', task.id) });
65
+ return actions;
66
+ }
67
+
43
68
  let acl = $state<HTMLDialogElement>();
44
69
  </script>
45
70
 
@@ -76,48 +101,30 @@
76
101
  {/snippet}
77
102
 
78
103
  {#snippet task_tree(node: TaskTreeNode, depth: number = 0, isCompletedMirror: boolean = false)}
79
- {const task = $derived(node.task)}
80
- <div class="task" style:margin-left="{depth * 1.75}em">
104
+ {const task = $derived(node.task),
105
+ actions = $derived(taskActions(task))}
106
+ <div class="task" style:margin-left="{depth * 1.75}em" {@attach contextMenu(...actions)}>
81
107
  {@render task_checkbox(node, !showCompletedInline && isCompletedMirror != task.completed)}
82
- <input
83
- type="text"
108
+ <textarea
84
109
  name="summary"
85
110
  class="editable-text"
111
+ rows="1"
86
112
  bind:value={task.summary}
113
+ onkeydown={e => {
114
+ if (e.key == 'Enter' && !e.isComposing) e.preventDefault();
115
+ }}
87
116
  oninput={e => {
88
- task.summary = e.currentTarget.value;
117
+ task.summary = e.currentTarget.value.replaceAll('\n', ' ');
89
118
  fetchAPI('PATCH', 'tasks/:id', { summary: task.summary }, task.id);
90
119
  }}
91
- />
120
+ {@attach dynamicRows(40, 1)}></textarea>
92
121
  <Popover showToggle="hover">
93
- <div
94
- class="menu-item"
95
- onclick={() => {
96
- fetchAPI('PUT', 'task_lists/:id', { summary: '', parentId: task.id }, list.id).then(t => tasks.push(t));
97
- }}
98
- >
99
- <Icon i="arrow-turn-down-right" />
100
- <span>{text('tasks.add_subtask')}</span>
101
- </div>
102
- <div
103
- class="menu-item"
104
- onclick={() =>
105
- toastStatus(
106
- fetchAPI('DELETE', 'tasks/:id', {}, task.id).then(() => {
107
- tasks.splice(tasks.indexOf(task), 1);
108
- }),
109
- text('tasks.toast_task_deleted')
110
- )}
111
- >
112
- <Icon i="trash" />
113
- <span>{text('generic.delete')}</span>
114
- </div>
115
- {#if user?.preferences?.debug}
116
- <div class="menu-item" onclick={() => copy('text/plain', task.id)}>
117
- <Icon i="hashtag" --size="14px" />
118
- <span>{text('tasks.copy_id')}</span>
122
+ {#each actions as item}
123
+ <div class="menu-item" onclick={item.action}>
124
+ <Icon i={item.i} />
125
+ <span>{item.text}</span>
119
126
  </div>
120
- {/if}
127
+ {/each}
121
128
  </Popover>
122
129
  </div>
123
130
  {#each node.subtasks as sub (sub.task.id)}
@@ -314,8 +321,9 @@
314
321
  }
315
322
  }
316
323
 
317
- input {
324
+ textarea {
318
325
  padding: 0.125em 0.25em;
326
+ width: 100%;
319
327
  }
320
328
  }
321
329
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@axium/tasks",
3
- "version": "0.5.8",
3
+ "version": "0.5.9",
4
4
  "author": "James Prevett <axium@jamespre.dev>",
5
5
  "description": "Tasks for Axium",
6
6
  "funding": {
@@ -37,8 +37,8 @@
37
37
  "build": "tsc"
38
38
  },
39
39
  "peerDependencies": {
40
- "@axium/client": ">=0.37.0",
41
- "@axium/core": ">=0.39.0",
40
+ "@axium/client": ">=0.39.0",
41
+ "@axium/core": ">=0.41.0",
42
42
  "@axium/server": ">=0.55.0",
43
43
  "@sveltejs/kit": "^2.27.3",
44
44
  "kysely": "^0.29.0",
@@ -0,0 +1,10 @@
1
+ <script lang="ts">
2
+ import { text } from '@axium/client';
3
+ import { TopBarContent } from '@axium/client/components';
4
+
5
+ const { children } = $props();
6
+ </script>
7
+
8
+ <TopBarContent name={text('app_name.tasks')} icon="list-check" href="/tasks" />
9
+
10
+ {@render children()}
@@ -1,6 +1,6 @@
1
1
  import { connect } from '@axium/client/socket';
2
2
  import { schemas } from '@axium/client/sync';
3
- import { getCurrentSession } from '@axium/client/user';
3
+ import { currentSession } from '@axium/client/user';
4
4
  import type { Session, UserPublic } from '@axium/core';
5
5
  import { TaskList } from '@axium/tasks/common';
6
6
 
@@ -11,7 +11,7 @@ export const ssr = false;
11
11
  export async function load({ parent }) {
12
12
  let { session }: { session?: (Session & { user: UserPublic }) | null } = await parent();
13
13
 
14
- session ||= await getCurrentSession().catch(() => null);
14
+ session ||= await currentSession();
15
15
 
16
16
  if (session) await connect().catch(() => null);
17
17
 
@@ -20,8 +20,6 @@
20
20
  </svelte:head>
21
21
 
22
22
  <div id="tasks-main">
23
- <h1>{text('app_name.tasks')}</h1>
24
-
25
23
  <div>
26
24
  <AppPreferencesDialog appId="tasks" userId={data.session.userId} schema={TasksPreferences} />
27
25
 
@@ -1,8 +1,6 @@
1
1
  import { fetchAPI } from '@axium/client/requests';
2
2
  import { redirect } from '@sveltejs/kit';
3
3
 
4
- export const ssr = false;
5
-
6
4
  export async function load({ parent }) {
7
5
  const { session } = await parent();
8
6
 
@@ -1,8 +1,6 @@
1
1
  import { fetchAPI } from '@axium/client/requests';
2
2
  import type { LoadEvent } from '@sveltejs/kit';
3
3
 
4
- export const ssr = false;
5
-
6
4
  export async function load({ params }: LoadEvent) {
7
5
  const list = await fetchAPI('GET', 'task_lists/:id', {}, params.id!);
8
6