@fayz-ai/plugin-tasks 0.1.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.
Files changed (75) hide show
  1. package/dist/TasksContext.d.ts +20 -0
  2. package/dist/TasksContext.d.ts.map +1 -0
  3. package/dist/components/TaskCard.d.ts +10 -0
  4. package/dist/components/TaskCard.d.ts.map +1 -0
  5. package/dist/components/TaskDetail.d.ts +5 -0
  6. package/dist/components/TaskDetail.d.ts.map +1 -0
  7. package/dist/components/TaskLabelBadge.d.ts +9 -0
  8. package/dist/components/TaskLabelBadge.d.ts.map +1 -0
  9. package/dist/components/TaskPriorityBadge.d.ts +7 -0
  10. package/dist/components/TaskPriorityBadge.d.ts.map +1 -0
  11. package/dist/components/TaskQuickAdd.d.ts +5 -0
  12. package/dist/components/TaskQuickAdd.d.ts.map +1 -0
  13. package/dist/components/TaskStatusGroup.d.ts +7 -0
  14. package/dist/components/TaskStatusGroup.d.ts.map +1 -0
  15. package/dist/components/TasksDrawer.d.ts +3 -0
  16. package/dist/components/TasksDrawer.d.ts.map +1 -0
  17. package/dist/components/TasksFilterBar.d.ts +3 -0
  18. package/dist/components/TasksFilterBar.d.ts.map +1 -0
  19. package/dist/components/TasksGeneralSettings.d.ts +3 -0
  20. package/dist/components/TasksGeneralSettings.d.ts.map +1 -0
  21. package/dist/components/TasksTopbarButton.d.ts +15 -0
  22. package/dist/components/TasksTopbarButton.d.ts.map +1 -0
  23. package/dist/data/capability.test.d.ts +2 -0
  24. package/dist/data/capability.test.d.ts.map +1 -0
  25. package/dist/data/mock.d.ts +3 -0
  26. package/dist/data/mock.d.ts.map +1 -0
  27. package/dist/data/supabase.d.ts +3 -0
  28. package/dist/data/supabase.d.ts.map +1 -0
  29. package/dist/data/types.d.ts +13 -0
  30. package/dist/data/types.d.ts.map +1 -0
  31. package/dist/index.cjs +1108 -0
  32. package/dist/index.cjs.map +1 -0
  33. package/dist/index.d.ts +21 -0
  34. package/dist/index.d.ts.map +1 -0
  35. package/dist/index.js +1102 -0
  36. package/dist/index.js.map +1 -0
  37. package/dist/lib/tenant.d.ts +3 -0
  38. package/dist/lib/tenant.d.ts.map +1 -0
  39. package/dist/locales/en.d.ts +2 -0
  40. package/dist/locales/en.d.ts.map +1 -0
  41. package/dist/locales/index.d.ts +2 -0
  42. package/dist/locales/index.d.ts.map +1 -0
  43. package/dist/locales/pt-BR.d.ts +2 -0
  44. package/dist/locales/pt-BR.d.ts.map +1 -0
  45. package/dist/registries.d.ts +3 -0
  46. package/dist/registries.d.ts.map +1 -0
  47. package/dist/store.d.ts +27 -0
  48. package/dist/store.d.ts.map +1 -0
  49. package/dist/types.d.ts +68 -0
  50. package/dist/types.d.ts.map +1 -0
  51. package/package.json +55 -0
  52. package/src/TasksContext.tsx +24 -0
  53. package/src/components/TaskCard.tsx +81 -0
  54. package/src/components/TaskDetail.tsx +184 -0
  55. package/src/components/TaskLabelBadge.tsx +37 -0
  56. package/src/components/TaskPriorityBadge.tsx +21 -0
  57. package/src/components/TaskQuickAdd.tsx +42 -0
  58. package/src/components/TaskStatusGroup.tsx +44 -0
  59. package/src/components/TasksDrawer.tsx +94 -0
  60. package/src/components/TasksFilterBar.tsx +57 -0
  61. package/src/components/TasksGeneralSettings.tsx +29 -0
  62. package/src/components/TasksTopbarButton.tsx +64 -0
  63. package/src/data/capability.test.ts +43 -0
  64. package/src/data/mock.ts +143 -0
  65. package/src/data/supabase.ts +193 -0
  66. package/src/data/types.ts +16 -0
  67. package/src/index.ts +217 -0
  68. package/src/lib/tenant.ts +13 -0
  69. package/src/locales/en.ts +40 -0
  70. package/src/locales/index.ts +7 -0
  71. package/src/locales/pt-BR.ts +40 -0
  72. package/src/migrations/001_tasks_base.sql +57 -0
  73. package/src/registries.ts +32 -0
  74. package/src/store.ts +148 -0
  75. package/src/types.ts +94 -0
package/dist/index.js ADDED
@@ -0,0 +1,1102 @@
1
+ import React4, { useEffect, useState, useCallback } from 'react';
2
+ import { createPluginContext, dedup } from '@fayz-ai/saas';
3
+ import { registerTranslations, createSafeDataProvider, useTranslation, getActiveTenantId, getSupabaseClientOptional } from '@fayz-ai/core';
4
+ import { createStore } from 'zustand/vanilla';
5
+ import { jsxs, jsx } from 'react/jsx-runtime';
6
+ import { CheckSquare, ClipboardList, Plus, ArrowLeft, ChevronDown, Calendar, Trash2, ListChecks, ChevronRight, AlertTriangle, ArrowUp, Minus, ArrowDown } from 'lucide-react';
7
+ import { Button, cn, Sheet, SheetContent, SheetHeader, SheetTitle, SheetDescription, SheetBody, Checkbox } from '@fayz-ai/ui';
8
+ import { useStore } from 'zustand';
9
+
10
+ // src/index.ts
11
+ var ctx = createPluginContext("TasksContextProvider");
12
+ var TasksContextProvider = ctx.ContextProvider;
13
+ ctx.useConfig;
14
+ ctx.useProvider;
15
+ var useTasksStore = ctx.useStore;
16
+
17
+ // src/data/mock.ts
18
+ function uid() {
19
+ return crypto.randomUUID?.() ?? String(Date.now());
20
+ }
21
+ function now() {
22
+ return (/* @__PURE__ */ new Date()).toISOString();
23
+ }
24
+ function today() {
25
+ return (/* @__PURE__ */ new Date()).toISOString().slice(0, 10);
26
+ }
27
+ var SEED_LABELS = [
28
+ { id: "lbl-bug", name: "Bug", color: "#ef4444", isActive: true, tenantId: "mock", createdAt: now() },
29
+ { id: "lbl-feature", name: "Feature", color: "#3b82f6", isActive: true, tenantId: "mock", createdAt: now() },
30
+ { id: "lbl-urgent", name: "Urgent", color: "#f59e0b", isActive: true, tenantId: "mock", createdAt: now() },
31
+ { id: "lbl-personal", name: "Personal", color: "#8b5cf6", isActive: true, tenantId: "mock", createdAt: now() }
32
+ ];
33
+ function makeSeedTasks() {
34
+ const base = {
35
+ tenantId: "mock",
36
+ description: null,
37
+ assignedToId: null,
38
+ assignedToName: null,
39
+ parentId: null,
40
+ labels: [],
41
+ createdById: null,
42
+ createdByName: null,
43
+ createdAt: now(),
44
+ updatedAt: now()
45
+ };
46
+ return [
47
+ { ...base, id: uid(), title: "Setup payment gateway", status: "todo", priority: "high", dueDate: today(), position: 0 },
48
+ { ...base, id: uid(), title: "Update menu photos", status: "todo", priority: "medium", dueDate: null, position: 1 },
49
+ { ...base, id: uid(), title: "Review monthly report", status: "in_progress", priority: "medium", dueDate: null, position: 0 },
50
+ { ...base, id: uid(), title: "Fix login bug", status: "in_progress", priority: "urgent", dueDate: today(), position: 1, labels: ["lbl-bug"] },
51
+ { ...base, id: uid(), title: "Onboard new employee", status: "done", priority: "low", dueDate: null, position: 0 }
52
+ ];
53
+ }
54
+ function matchesQuery(task, query) {
55
+ if (query.status) {
56
+ const statuses = Array.isArray(query.status) ? query.status : [query.status];
57
+ if (!statuses.includes(task.status)) return false;
58
+ }
59
+ if (query.priority) {
60
+ const priorities = Array.isArray(query.priority) ? query.priority : [query.priority];
61
+ if (!priorities.includes(task.priority)) return false;
62
+ }
63
+ if (query.assignedToId && task.assignedToId !== query.assignedToId) return false;
64
+ if (query.parentId !== void 0) {
65
+ if (query.parentId === null && task.parentId !== null) return false;
66
+ if (query.parentId !== null && task.parentId !== query.parentId) return false;
67
+ }
68
+ if (query.search) {
69
+ const s = query.search.toLowerCase();
70
+ if (!task.title.toLowerCase().includes(s)) return false;
71
+ }
72
+ if (query.overdue && task.dueDate) {
73
+ if (task.dueDate >= today()) return false;
74
+ }
75
+ return true;
76
+ }
77
+ function createMockTasksProvider() {
78
+ let tasks = makeSeedTasks();
79
+ const labels = [...SEED_LABELS];
80
+ return {
81
+ async getTasks(query) {
82
+ return tasks.filter((t) => matchesQuery(t, query)).sort((a, b) => a.position - b.position);
83
+ },
84
+ async getTaskById(id) {
85
+ return tasks.find((t) => t.id === id) ?? null;
86
+ },
87
+ async getSubtasks(parentId) {
88
+ return tasks.filter((t) => t.parentId === parentId).sort((a, b) => a.position - b.position);
89
+ },
90
+ async createTask(input) {
91
+ const statusTasks = tasks.filter((t) => t.status === (input.status ?? "todo") && t.parentId === (input.parentId ?? null));
92
+ const maxPos = statusTasks.reduce((max, t) => Math.max(max, t.position), -1);
93
+ const task = {
94
+ id: uid(),
95
+ title: input.title,
96
+ description: input.description ?? null,
97
+ status: input.status ?? "todo",
98
+ priority: input.priority ?? "medium",
99
+ dueDate: input.dueDate ?? null,
100
+ assignedToId: input.assignedToId ?? null,
101
+ assignedToName: null,
102
+ parentId: input.parentId ?? null,
103
+ labels: input.labels ?? [],
104
+ position: maxPos + 1,
105
+ createdById: null,
106
+ createdByName: null,
107
+ tenantId: "mock",
108
+ createdAt: now(),
109
+ updatedAt: now()
110
+ };
111
+ tasks.push(task);
112
+ return task;
113
+ },
114
+ async updateTask(id, input) {
115
+ const idx = tasks.findIndex((t) => t.id === id);
116
+ if (idx === -1) throw new Error("Task not found");
117
+ tasks[idx] = { ...tasks[idx], ...input, updatedAt: now() };
118
+ return tasks[idx];
119
+ },
120
+ async deleteTask(id) {
121
+ tasks = tasks.filter((t) => t.id !== id && t.parentId !== id);
122
+ },
123
+ async reorderTask(id, newPosition, status) {
124
+ const task = tasks.find((t) => t.id === id);
125
+ if (!task) return;
126
+ task.status = status;
127
+ task.position = newPosition;
128
+ task.updatedAt = now();
129
+ },
130
+ async getLabels() {
131
+ return labels.filter((l) => l.isActive);
132
+ },
133
+ async getSummary() {
134
+ const topLevel = tasks.filter((t) => t.parentId === null);
135
+ const d = today();
136
+ return {
137
+ total: topLevel.length,
138
+ todo: topLevel.filter((t) => t.status === "todo").length,
139
+ inProgress: topLevel.filter((t) => t.status === "in_progress").length,
140
+ done: topLevel.filter((t) => t.status === "done").length,
141
+ overdue: topLevel.filter((t) => t.dueDate != null && t.dueDate < d && t.status !== "done" && t.status !== "cancelled").length,
142
+ dueToday: topLevel.filter((t) => t.dueDate === d && t.status !== "done" && t.status !== "cancelled").length,
143
+ highPriority: topLevel.filter((t) => (t.priority === "high" || t.priority === "urgent") && t.status !== "done" && t.status !== "cancelled").length
144
+ };
145
+ }
146
+ };
147
+ }
148
+
149
+ // src/data/supabase.ts
150
+ function getTenantId() {
151
+ return getActiveTenantId();
152
+ }
153
+ function getClient() {
154
+ const supabase = getSupabaseClientOptional();
155
+ if (!supabase) throw new Error("Supabase not initialized");
156
+ return supabase;
157
+ }
158
+ function snakeToCamel(obj) {
159
+ const result = {};
160
+ for (const [key, value] of Object.entries(obj)) {
161
+ result[key.replace(/_([a-z])/g, (_, c) => c.toUpperCase())] = value;
162
+ }
163
+ return result;
164
+ }
165
+ function toTask(row) {
166
+ const t = snakeToCamel(row);
167
+ if (!Array.isArray(t.labels)) t.labels = [];
168
+ return t;
169
+ }
170
+ function createSupabaseTasksProvider() {
171
+ return {
172
+ async getTasks(query) {
173
+ const tenantId = getTenantId();
174
+ if (!tenantId) return [];
175
+ let q = getClient().from("tsk_tasks").select("*").eq("tenant_id", tenantId);
176
+ if (query.parentId === null) {
177
+ q = q.is("parent_id", null);
178
+ } else if (query.parentId) {
179
+ q = q.eq("parent_id", query.parentId);
180
+ }
181
+ if (query.status) {
182
+ const statuses = Array.isArray(query.status) ? query.status : [query.status];
183
+ q = q.in("status", statuses);
184
+ }
185
+ if (query.priority) {
186
+ const priorities = Array.isArray(query.priority) ? query.priority : [query.priority];
187
+ q = q.in("priority", priorities);
188
+ }
189
+ if (query.assignedToId) {
190
+ q = q.eq("assigned_to_id", query.assignedToId);
191
+ }
192
+ if (query.search) {
193
+ q = q.ilike("title", `%${query.search}%`);
194
+ }
195
+ if (query.overdue) {
196
+ q = q.lt("due_date", (/* @__PURE__ */ new Date()).toISOString().slice(0, 10)).not("status", "in", '("done","cancelled")');
197
+ }
198
+ q = q.order("position", { ascending: true }).order("created_at", { ascending: false });
199
+ const { data } = await q;
200
+ return (data ?? []).map(toTask);
201
+ },
202
+ async getTaskById(id) {
203
+ const { data } = await getClient().from("tsk_tasks").select("*").eq("id", id).maybeSingle();
204
+ return data ? toTask(data) : null;
205
+ },
206
+ async getSubtasks(parentId) {
207
+ const { data } = await getClient().from("tsk_tasks").select("*").eq("parent_id", parentId).order("position", { ascending: true });
208
+ return (data ?? []).map(toTask);
209
+ },
210
+ async createTask(input) {
211
+ const tenantId = getTenantId();
212
+ if (!tenantId) throw new Error("No active tenant");
213
+ const { data: maxData } = await getClient().from("tsk_tasks").select("position").eq("tenant_id", tenantId).eq("status", input.status ?? "todo").is("parent_id", input.parentId ?? null).order("position", { ascending: false }).limit(1);
214
+ const maxPos = maxData?.[0]?.position ?? -1;
215
+ const { data, error } = await getClient().from("tsk_tasks").insert({
216
+ tenant_id: tenantId,
217
+ title: input.title,
218
+ description: input.description ?? null,
219
+ status: input.status ?? "todo",
220
+ priority: input.priority ?? "medium",
221
+ due_date: input.dueDate ?? null,
222
+ assigned_to_id: input.assignedToId ?? null,
223
+ parent_id: input.parentId ?? null,
224
+ labels: input.labels ?? [],
225
+ position: maxPos + 1
226
+ }).select("*").single();
227
+ if (error) throw error;
228
+ return toTask(data);
229
+ },
230
+ async updateTask(id, input) {
231
+ const payload = { updated_at: (/* @__PURE__ */ new Date()).toISOString() };
232
+ if (input.title !== void 0) payload.title = input.title;
233
+ if (input.description !== void 0) payload.description = input.description;
234
+ if (input.status !== void 0) payload.status = input.status;
235
+ if (input.priority !== void 0) payload.priority = input.priority;
236
+ if (input.dueDate !== void 0) payload.due_date = input.dueDate;
237
+ if (input.assignedToId !== void 0) payload.assigned_to_id = input.assignedToId;
238
+ if (input.labels !== void 0) payload.labels = input.labels;
239
+ if (input.position !== void 0) payload.position = input.position;
240
+ const { data, error } = await getClient().from("tsk_tasks").update(payload).eq("id", id).select("*").single();
241
+ if (error) throw error;
242
+ return toTask(data);
243
+ },
244
+ async deleteTask(id) {
245
+ await getClient().from("tsk_tasks").delete().eq("id", id);
246
+ },
247
+ async reorderTask(id, newPosition, status) {
248
+ await getClient().from("tsk_tasks").update({ position: newPosition, status, updated_at: (/* @__PURE__ */ new Date()).toISOString() }).eq("id", id);
249
+ },
250
+ async getLabels() {
251
+ const tenantId = getTenantId();
252
+ if (!tenantId) return [];
253
+ const { data } = await getClient().from("tsk_labels").select("*").eq("tenant_id", tenantId).eq("is_active", true).order("name");
254
+ return (data ?? []).map((r) => snakeToCamel(r));
255
+ },
256
+ async getSummary() {
257
+ const tenantId = getTenantId();
258
+ if (!tenantId) return { total: 0, todo: 0, inProgress: 0, done: 0, overdue: 0, dueToday: 0, highPriority: 0 };
259
+ const { data } = await getClient().from("tsk_tasks").select("status, priority, due_date").eq("tenant_id", tenantId).is("parent_id", null);
260
+ const tasks = data ?? [];
261
+ const today2 = (/* @__PURE__ */ new Date()).toISOString().slice(0, 10);
262
+ return {
263
+ total: tasks.length,
264
+ todo: tasks.filter((t) => t.status === "todo").length,
265
+ inProgress: tasks.filter((t) => t.status === "in_progress").length,
266
+ done: tasks.filter((t) => t.status === "done").length,
267
+ overdue: tasks.filter((t) => t.due_date && t.due_date < today2 && t.status !== "done" && t.status !== "cancelled").length,
268
+ dueToday: tasks.filter((t) => t.due_date === today2 && t.status !== "done" && t.status !== "cancelled").length,
269
+ highPriority: tasks.filter((t) => (t.priority === "high" || t.priority === "urgent") && t.status !== "done" && t.status !== "cancelled").length
270
+ };
271
+ }
272
+ };
273
+ }
274
+ function createTasksStore(provider) {
275
+ return createStore((set, get) => ({
276
+ tasks: [],
277
+ tasksLoading: false,
278
+ labels: [],
279
+ summary: null,
280
+ summaryLoading: false,
281
+ drawerOpen: false,
282
+ selectedTaskId: null,
283
+ activeFilter: "all",
284
+ // ----- Data actions -----
285
+ async fetchTasks(query) {
286
+ return dedup("tasks:list", async () => {
287
+ set({ tasksLoading: true });
288
+ try {
289
+ const filter = get().activeFilter;
290
+ const q = {
291
+ parentId: null,
292
+ ...query,
293
+ ...filter !== "all" ? { status: filter } : {}
294
+ };
295
+ const tasks = await provider.getTasks(q);
296
+ set({ tasks, tasksLoading: false });
297
+ } catch {
298
+ set({ tasksLoading: false });
299
+ }
300
+ });
301
+ },
302
+ async fetchLabels() {
303
+ return dedup("tasks:labels", async () => {
304
+ try {
305
+ const labels = await provider.getLabels();
306
+ set({ labels });
307
+ } catch {
308
+ }
309
+ });
310
+ },
311
+ async fetchSummary() {
312
+ return dedup("tasks:summary", async () => {
313
+ set({ summaryLoading: true });
314
+ try {
315
+ const summary = await provider.getSummary();
316
+ set({ summary, summaryLoading: false });
317
+ } catch {
318
+ set({ summaryLoading: false });
319
+ }
320
+ });
321
+ },
322
+ async createTask(input) {
323
+ const task = await provider.createTask(input);
324
+ await get().fetchTasks();
325
+ await get().fetchSummary();
326
+ return task;
327
+ },
328
+ async updateTask(id, input) {
329
+ const task = await provider.updateTask(id, input);
330
+ set((s) => ({ tasks: s.tasks.map((t) => t.id === id ? task : t) }));
331
+ await get().fetchSummary();
332
+ return task;
333
+ },
334
+ async deleteTask(id) {
335
+ await provider.deleteTask(id);
336
+ set((s) => ({ tasks: s.tasks.filter((t) => t.id !== id), selectedTaskId: null }));
337
+ await get().fetchSummary();
338
+ },
339
+ async reorderTask(id, newPosition, status) {
340
+ await provider.reorderTask(id, newPosition, status);
341
+ await get().fetchTasks();
342
+ },
343
+ // ----- UI actions -----
344
+ openDrawer() {
345
+ set({ drawerOpen: true });
346
+ get().fetchTasks();
347
+ get().fetchLabels();
348
+ get().fetchSummary();
349
+ },
350
+ closeDrawer() {
351
+ set({ drawerOpen: false, selectedTaskId: null });
352
+ },
353
+ toggleDrawer() {
354
+ const { drawerOpen } = get();
355
+ if (drawerOpen) get().closeDrawer();
356
+ else get().openDrawer();
357
+ },
358
+ selectTask(id) {
359
+ set({ selectedTaskId: id });
360
+ },
361
+ setFilter(filter) {
362
+ set({ activeFilter: filter });
363
+ get().fetchTasks();
364
+ }
365
+ }));
366
+ }
367
+
368
+ // src/locales/en.ts
369
+ var en = {
370
+ "tasks.title": "Tasks",
371
+ "tasks.drawer.title": "Tasks",
372
+ "tasks.drawer.subtitle": "Manage your team tasks",
373
+ "tasks.quickAdd.placeholder": "Add a task...",
374
+ "tasks.filter.all": "All",
375
+ "tasks.filter.todo": "To Do",
376
+ "tasks.filter.inProgress": "In Progress",
377
+ "tasks.filter.done": "Done",
378
+ "tasks.status.todo": "To Do",
379
+ "tasks.status.in_progress": "In Progress",
380
+ "tasks.status.done": "Done",
381
+ "tasks.status.cancelled": "Cancelled",
382
+ "tasks.priority.low": "Low",
383
+ "tasks.priority.medium": "Medium",
384
+ "tasks.priority.high": "High",
385
+ "tasks.priority.urgent": "Urgent",
386
+ "tasks.detail.description": "Description",
387
+ "tasks.detail.descriptionPlaceholder": "Add a description...",
388
+ "tasks.detail.status": "Status",
389
+ "tasks.detail.priority": "Priority",
390
+ "tasks.detail.dueDate": "Due Date",
391
+ "tasks.detail.assignee": "Assigned To",
392
+ "tasks.detail.labels": "Labels",
393
+ "tasks.detail.subtasks": "Subtasks",
394
+ "tasks.detail.delete": "Delete Task",
395
+ "tasks.detail.deleteConfirm": "Are you sure you want to delete this task?",
396
+ "tasks.detail.created": "Created",
397
+ "tasks.detail.updated": "Updated",
398
+ "tasks.detail.addSubtask": "Add subtask...",
399
+ "tasks.detail.back": "Back to list",
400
+ "tasks.summary.overdue": "overdue",
401
+ "tasks.summary.dueToday": "due today",
402
+ "tasks.empty": "No tasks yet",
403
+ "tasks.empty.description": "Add your first task using the input above",
404
+ "tasks.settings.title": "Tasks",
405
+ "tasks.settings.general": "General",
406
+ "tasks.settings.defaultPriority": "Default Priority",
407
+ "tasks.settings.autoAssign": "Auto-assign tasks to creator"
408
+ };
409
+
410
+ // src/locales/pt-BR.ts
411
+ var ptBR = {
412
+ "tasks.title": "Tarefas",
413
+ "tasks.drawer.title": "Tarefas",
414
+ "tasks.drawer.subtitle": "Gerencie as tarefas da equipe",
415
+ "tasks.quickAdd.placeholder": "Adicionar tarefa...",
416
+ "tasks.filter.all": "Todas",
417
+ "tasks.filter.todo": "A Fazer",
418
+ "tasks.filter.inProgress": "Em Andamento",
419
+ "tasks.filter.done": "Conclu\xEDdas",
420
+ "tasks.status.todo": "A Fazer",
421
+ "tasks.status.in_progress": "Em Andamento",
422
+ "tasks.status.done": "Conclu\xEDda",
423
+ "tasks.status.cancelled": "Cancelada",
424
+ "tasks.priority.low": "Baixa",
425
+ "tasks.priority.medium": "M\xE9dia",
426
+ "tasks.priority.high": "Alta",
427
+ "tasks.priority.urgent": "Urgente",
428
+ "tasks.detail.description": "Descri\xE7\xE3o",
429
+ "tasks.detail.descriptionPlaceholder": "Adicionar descri\xE7\xE3o...",
430
+ "tasks.detail.status": "Status",
431
+ "tasks.detail.priority": "Prioridade",
432
+ "tasks.detail.dueDate": "Data de Vencimento",
433
+ "tasks.detail.assignee": "Respons\xE1vel",
434
+ "tasks.detail.labels": "Etiquetas",
435
+ "tasks.detail.subtasks": "Subtarefas",
436
+ "tasks.detail.delete": "Excluir Tarefa",
437
+ "tasks.detail.deleteConfirm": "Tem certeza que deseja excluir esta tarefa?",
438
+ "tasks.detail.created": "Criada em",
439
+ "tasks.detail.updated": "Atualizada em",
440
+ "tasks.detail.addSubtask": "Adicionar subtarefa...",
441
+ "tasks.detail.back": "Voltar \xE0 lista",
442
+ "tasks.summary.overdue": "atrasadas",
443
+ "tasks.summary.dueToday": "vencem hoje",
444
+ "tasks.empty": "Nenhuma tarefa ainda",
445
+ "tasks.empty.description": "Adicione sua primeira tarefa usando o campo acima",
446
+ "tasks.settings.title": "Tarefas",
447
+ "tasks.settings.general": "Geral",
448
+ "tasks.settings.defaultPriority": "Prioridade Padr\xE3o",
449
+ "tasks.settings.autoAssign": "Atribuir tarefas automaticamente ao criador"
450
+ };
451
+
452
+ // src/locales/index.ts
453
+ var tasksLocales = {
454
+ en,
455
+ "pt-BR": ptBR
456
+ };
457
+
458
+ // src/registries.ts
459
+ var taskLabelEntity = {
460
+ name: "Task Label",
461
+ namePlural: "Task Labels",
462
+ icon: "Tag",
463
+ displayField: "name",
464
+ defaultSort: "name",
465
+ fields: [
466
+ { key: "name", label: "Name", type: "text", required: true, showInTable: true },
467
+ { key: "color", label: "Color", type: "text", showInTable: true, defaultValue: "#6366f1" },
468
+ { key: "isActive", label: "Active", type: "boolean", showInTable: true, defaultValue: true }
469
+ ],
470
+ data: { table: "tsk_labels", tenantScoped: true }
471
+ };
472
+ var tasksRegistries = [
473
+ {
474
+ id: "task-labels",
475
+ entity: taskLabelEntity,
476
+ icon: "Tag",
477
+ description: "Labels for categorizing tasks",
478
+ display: "table",
479
+ seedData: [
480
+ { id: "lbl-bug", name: "Bug", color: "#ef4444", isActive: true },
481
+ { id: "lbl-feature", name: "Feature", color: "#3b82f6", isActive: true },
482
+ { id: "lbl-urgent", name: "Urgent", color: "#f59e0b", isActive: true },
483
+ { id: "lbl-personal", name: "Personal", color: "#8b5cf6", isActive: true }
484
+ ]
485
+ }
486
+ ];
487
+ function TasksGeneralSettings() {
488
+ const t = useTranslation();
489
+ return /* @__PURE__ */ jsxs("div", { className: "space-y-6", children: [
490
+ /* @__PURE__ */ jsxs("div", { children: [
491
+ /* @__PURE__ */ jsx("h3", { className: "text-sm font-semibold mb-1", children: t("tasks.settings.general") }),
492
+ /* @__PURE__ */ jsx("p", { className: "text-xs text-muted-foreground mb-3", children: t("tasks.drawer.subtitle") })
493
+ ] }),
494
+ /* @__PURE__ */ jsx("div", { className: "space-y-4", children: /* @__PURE__ */ jsxs("div", { className: "space-y-1.5", children: [
495
+ /* @__PURE__ */ jsx("label", { className: "text-sm font-medium", children: t("tasks.settings.defaultPriority") }),
496
+ /* @__PURE__ */ jsxs("select", { className: "w-full max-w-xs rounded-input border border-input bg-card shadow-[inset_0_1px_0_rgb(0_0_0_/0.06)] px-3 py-2 text-sm", children: [
497
+ /* @__PURE__ */ jsx("option", { value: "low", children: t("tasks.priority.low") }),
498
+ /* @__PURE__ */ jsx("option", { value: "medium", selected: true, children: t("tasks.priority.medium") }),
499
+ /* @__PURE__ */ jsx("option", { value: "high", children: t("tasks.priority.high") }),
500
+ /* @__PURE__ */ jsx("option", { value: "urgent", children: t("tasks.priority.urgent") })
501
+ ] })
502
+ ] }) })
503
+ ] });
504
+ }
505
+ var FILTERS = [
506
+ { key: "all", labelKey: "tasks.filter.all" },
507
+ { key: "todo", labelKey: "tasks.filter.todo" },
508
+ { key: "in_progress", labelKey: "tasks.filter.inProgress" },
509
+ { key: "done", labelKey: "tasks.filter.done" }
510
+ ];
511
+ function TasksFilterBar() {
512
+ const t = useTranslation();
513
+ const activeFilter = useTasksStore((s) => s.activeFilter);
514
+ const setFilter = useTasksStore((s) => s.setFilter);
515
+ const summary = useTasksStore((s) => s.summary);
516
+ const getCount = (key) => {
517
+ if (!summary) return void 0;
518
+ switch (key) {
519
+ case "all":
520
+ return summary.total;
521
+ case "todo":
522
+ return summary.todo;
523
+ case "in_progress":
524
+ return summary.inProgress;
525
+ case "done":
526
+ return summary.done;
527
+ default:
528
+ return void 0;
529
+ }
530
+ };
531
+ return /* @__PURE__ */ jsx("div", { className: "flex items-center gap-1 px-3 py-2 border-b overflow-x-auto", children: FILTERS.map(({ key, labelKey }) => {
532
+ const active = activeFilter === key;
533
+ const count = getCount(key);
534
+ return /* @__PURE__ */ jsxs(
535
+ "button",
536
+ {
537
+ type: "button",
538
+ onClick: () => setFilter(key),
539
+ className: `inline-flex items-center gap-1.5 rounded-full px-3 py-1 text-xs font-medium transition-colors whitespace-nowrap ${active ? "bg-primary text-primary-foreground" : "text-muted-foreground hover:bg-muted hover:text-foreground"}`,
540
+ children: [
541
+ t(labelKey),
542
+ count != null && /* @__PURE__ */ jsx("span", { className: `text-[10px] ${active ? "text-primary-foreground/80" : "text-muted-foreground"}`, children: count })
543
+ ]
544
+ },
545
+ key
546
+ );
547
+ }) });
548
+ }
549
+ function TaskQuickAdd({ parentId }) {
550
+ const t = useTranslation();
551
+ const createTask = useTasksStore((s) => s.createTask);
552
+ const [title, setTitle] = useState("");
553
+ const [loading, setLoading] = useState(false);
554
+ const handleSubmit = useCallback(async (e) => {
555
+ e.preventDefault();
556
+ const trimmed = title.trim();
557
+ if (!trimmed || loading) return;
558
+ setLoading(true);
559
+ try {
560
+ await createTask({
561
+ title: trimmed,
562
+ parentId: parentId ?? null
563
+ });
564
+ setTitle("");
565
+ } finally {
566
+ setLoading(false);
567
+ }
568
+ }, [title, loading, createTask, parentId]);
569
+ return /* @__PURE__ */ jsxs("form", { onSubmit: handleSubmit, className: "flex items-center gap-2 px-3 py-2 border-b", children: [
570
+ /* @__PURE__ */ jsx(Plus, { className: "h-4 w-4 shrink-0 text-muted-foreground" }),
571
+ /* @__PURE__ */ jsx(
572
+ "input",
573
+ {
574
+ type: "text",
575
+ value: title,
576
+ onChange: (e) => setTitle(e.target.value),
577
+ placeholder: parentId ? t("tasks.detail.addSubtask") : t("tasks.quickAdd.placeholder"),
578
+ className: "flex-1 bg-transparent text-sm outline-none placeholder:text-muted-foreground/60",
579
+ disabled: loading
580
+ }
581
+ )
582
+ ] });
583
+ }
584
+ var PRIORITY_CONFIG = {
585
+ low: { color: "text-muted-foreground", bg: "bg-muted", icon: ArrowDown },
586
+ medium: { color: "text-info-soft-foreground", bg: "bg-info-soft", icon: Minus },
587
+ high: { color: "text-warning-soft-foreground", bg: "bg-warning-soft", icon: ArrowUp },
588
+ urgent: { color: "text-destructive-soft-foreground", bg: "bg-destructive-soft", icon: AlertTriangle }
589
+ };
590
+ function TaskPriorityBadge({ priority, showLabel }) {
591
+ const cfg = PRIORITY_CONFIG[priority];
592
+ const Icon = cfg.icon;
593
+ return /* @__PURE__ */ jsxs("span", { className: `inline-flex items-center gap-1 rounded px-1.5 py-0.5 text-xs font-medium ${cfg.color} ${cfg.bg}`, children: [
594
+ /* @__PURE__ */ jsx(Icon, { className: "h-3 w-3" }),
595
+ showLabel && /* @__PURE__ */ jsx("span", { className: "capitalize", children: priority })
596
+ ] });
597
+ }
598
+ function TaskLabelBadge({ labelId }) {
599
+ const labels = useTasksStore((s) => s.labels);
600
+ const label = labels.find((l) => l.id === labelId);
601
+ if (!label) return null;
602
+ return /* @__PURE__ */ jsx(
603
+ "span",
604
+ {
605
+ className: "inline-flex items-center rounded-full px-2 py-0.5 text-[10px] font-medium leading-none",
606
+ style: {
607
+ backgroundColor: label.color + "20",
608
+ color: label.color
609
+ },
610
+ children: label.name
611
+ }
612
+ );
613
+ }
614
+ function TaskLabelBadges({ labelIds, max = 2 }) {
615
+ if (labelIds.length === 0) return null;
616
+ const visible = labelIds.slice(0, max);
617
+ const overflow = labelIds.length - max;
618
+ return /* @__PURE__ */ jsxs("span", { className: "inline-flex items-center gap-1", children: [
619
+ visible.map((id) => /* @__PURE__ */ jsx(TaskLabelBadge, { labelId: id }, id)),
620
+ overflow > 0 && /* @__PURE__ */ jsxs("span", { className: "text-[10px] text-muted-foreground", children: [
621
+ "+",
622
+ overflow
623
+ ] })
624
+ ] });
625
+ }
626
+ function isOverdue(dueDate) {
627
+ if (!dueDate) return false;
628
+ return dueDate < (/* @__PURE__ */ new Date()).toISOString().slice(0, 10);
629
+ }
630
+ function isToday(dueDate) {
631
+ if (!dueDate) return false;
632
+ return dueDate === (/* @__PURE__ */ new Date()).toISOString().slice(0, 10);
633
+ }
634
+ function formatDueDate(dueDate) {
635
+ const d = /* @__PURE__ */ new Date(dueDate + "T00:00:00");
636
+ return d.toLocaleDateString(void 0, { month: "short", day: "numeric" });
637
+ }
638
+ function TaskCard({ task, subtaskCount }) {
639
+ const selectTask = useTasksStore((s) => s.selectTask);
640
+ const updateTask = useTasksStore((s) => s.updateTask);
641
+ const isDone = task.status === "done";
642
+ const overdue = !isDone && isOverdue(task.dueDate);
643
+ const dueToday = !isDone && isToday(task.dueDate);
644
+ const handleCheck = (e) => {
645
+ e.stopPropagation();
646
+ updateTask(task.id, { status: isDone ? "todo" : "done" });
647
+ };
648
+ return /* @__PURE__ */ jsxs(
649
+ "div",
650
+ {
651
+ onClick: () => selectTask(task.id),
652
+ className: "group flex items-start gap-2.5 rounded-lg border border-transparent px-3 py-2.5 transition-colors hover:bg-muted bg-card shadow-button active:shadow-button-inset hover:border-border cursor-pointer",
653
+ children: [
654
+ /* @__PURE__ */ jsx("div", { className: "pt-0.5", onClick: handleCheck, children: /* @__PURE__ */ jsx(Checkbox, { checked: isDone, onChange: () => {
655
+ } }) }),
656
+ /* @__PURE__ */ jsxs("div", { className: "min-w-0 flex-1 space-y-1", children: [
657
+ /* @__PURE__ */ jsx("p", { className: `text-sm leading-snug ${isDone ? "line-through text-muted-foreground" : ""}`, children: task.title }),
658
+ /* @__PURE__ */ jsxs("div", { className: "flex flex-wrap items-center gap-1.5", children: [
659
+ /* @__PURE__ */ jsx(TaskPriorityBadge, { priority: task.priority }),
660
+ task.dueDate && /* @__PURE__ */ jsxs("span", { className: `inline-flex items-center gap-1 text-[11px] ${overdue ? "text-destructive font-medium" : dueToday ? "text-warning font-medium" : "text-muted-foreground"}`, children: [
661
+ /* @__PURE__ */ jsx(Calendar, { className: "h-3 w-3" }),
662
+ formatDueDate(task.dueDate)
663
+ ] }),
664
+ subtaskCount && subtaskCount.total > 0 && /* @__PURE__ */ jsxs("span", { className: "inline-flex items-center gap-1 text-[11px] text-muted-foreground", children: [
665
+ /* @__PURE__ */ jsx(ListChecks, { className: "h-3 w-3" }),
666
+ subtaskCount.done,
667
+ "/",
668
+ subtaskCount.total
669
+ ] }),
670
+ /* @__PURE__ */ jsx(TaskLabelBadges, { labelIds: task.labels, max: 2 })
671
+ ] })
672
+ ] }),
673
+ task.assignedToName && /* @__PURE__ */ jsx("div", { className: "flex h-6 w-6 shrink-0 items-center justify-center rounded-full bg-primary/10 text-[10px] font-medium text-primary", title: task.assignedToName, children: task.assignedToName.split(" ").map((n) => n[0]).join("").slice(0, 2).toUpperCase() })
674
+ ]
675
+ }
676
+ );
677
+ }
678
+ var STATUS_COLORS = {
679
+ todo: "bg-muted-foreground",
680
+ in_progress: "bg-info",
681
+ done: "bg-success",
682
+ cancelled: "bg-muted-foreground/60"
683
+ };
684
+ function TaskStatusGroup({ status, tasks }) {
685
+ const t = useTranslation();
686
+ const [collapsed, setCollapsed] = useState(status === "cancelled");
687
+ if (tasks.length === 0) return null;
688
+ const Chevron = collapsed ? ChevronRight : ChevronDown;
689
+ return /* @__PURE__ */ jsxs("div", { className: "space-y-0.5", children: [
690
+ /* @__PURE__ */ jsxs(
691
+ "button",
692
+ {
693
+ type: "button",
694
+ onClick: () => setCollapsed(!collapsed),
695
+ className: "flex w-full items-center gap-2 px-3 py-1.5 text-xs font-semibold text-muted-foreground uppercase tracking-wider hover:text-foreground transition-colors",
696
+ children: [
697
+ /* @__PURE__ */ jsx("span", { className: `h-2 w-2 rounded-full ${STATUS_COLORS[status]}` }),
698
+ /* @__PURE__ */ jsx("span", { children: t(`tasks.status.${status}`) }),
699
+ /* @__PURE__ */ jsxs("span", { className: "text-[10px] font-normal", children: [
700
+ "(",
701
+ tasks.length,
702
+ ")"
703
+ ] }),
704
+ /* @__PURE__ */ jsx(Chevron, { className: "ml-auto h-3.5 w-3.5" })
705
+ ]
706
+ }
707
+ ),
708
+ !collapsed && /* @__PURE__ */ jsx("div", { children: tasks.map((task) => /* @__PURE__ */ jsx(TaskCard, { task }, task.id)) })
709
+ ] });
710
+ }
711
+
712
+ // src/types.ts
713
+ var TASK_STATUSES = ["todo", "in_progress", "done", "cancelled"];
714
+ var TASK_PRIORITIES = ["low", "medium", "high", "urgent"];
715
+ var STATUS_DOT = {
716
+ todo: "bg-muted-foreground",
717
+ in_progress: "bg-info",
718
+ done: "bg-success",
719
+ cancelled: "bg-muted-foreground/60"
720
+ };
721
+ function formatDate(iso) {
722
+ return new Date(iso).toLocaleDateString(void 0, { month: "short", day: "numeric" });
723
+ }
724
+ function TaskDetail({ taskId }) {
725
+ const t = useTranslation();
726
+ const tasks = useTasksStore((s) => s.tasks);
727
+ const selectTask = useTasksStore((s) => s.selectTask);
728
+ const updateTask = useTasksStore((s) => s.updateTask);
729
+ const deleteTask = useTasksStore((s) => s.deleteTask);
730
+ const task = tasks.find((tt) => tt.id === taskId);
731
+ const [title, setTitle] = useState("");
732
+ const [description, setDescription] = useState("");
733
+ const [subtasks, setSubtasks] = useState([]);
734
+ useEffect(() => {
735
+ if (task) {
736
+ setTitle(task.title);
737
+ setDescription(task.description ?? "");
738
+ }
739
+ }, [task]);
740
+ useEffect(() => {
741
+ setSubtasks([]);
742
+ }, [taskId]);
743
+ const handleTitleBlur = useCallback(() => {
744
+ if (task && title.trim() && title !== task.title) {
745
+ updateTask(task.id, { title: title.trim() });
746
+ }
747
+ }, [task, title, updateTask]);
748
+ const handleDescriptionBlur = useCallback(() => {
749
+ if (task && description !== (task.description ?? "")) {
750
+ updateTask(task.id, { description: description || null });
751
+ }
752
+ }, [task, description, updateTask]);
753
+ const handleDelete = useCallback(() => {
754
+ if (task && confirm(t("tasks.detail.deleteConfirm"))) {
755
+ deleteTask(task.id);
756
+ }
757
+ }, [task, deleteTask, t]);
758
+ if (!task) {
759
+ return /* @__PURE__ */ jsxs("div", { className: "flex flex-col items-center justify-center py-8 text-muted-foreground", children: [
760
+ /* @__PURE__ */ jsx("p", { className: "text-sm", children: "Task not found" }),
761
+ /* @__PURE__ */ jsx("button", { type: "button", onClick: () => selectTask(null), className: "mt-2 text-xs text-primary hover:underline", children: t("tasks.detail.back") })
762
+ ] });
763
+ }
764
+ return /* @__PURE__ */ jsxs("div", { className: "space-y-3", children: [
765
+ /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-2", children: [
766
+ /* @__PURE__ */ jsx(
767
+ "button",
768
+ {
769
+ type: "button",
770
+ onClick: () => selectTask(null),
771
+ className: "flex h-7 w-7 shrink-0 items-center justify-center rounded-md text-muted-foreground hover:bg-muted hover:text-foreground transition-colors",
772
+ children: /* @__PURE__ */ jsx(ArrowLeft, { className: "h-4 w-4" })
773
+ }
774
+ ),
775
+ /* @__PURE__ */ jsx(
776
+ "input",
777
+ {
778
+ type: "text",
779
+ value: title,
780
+ onChange: (e) => setTitle(e.target.value),
781
+ onBlur: handleTitleBlur,
782
+ onKeyDown: (e) => {
783
+ if (e.key === "Enter") e.currentTarget.blur();
784
+ },
785
+ className: "flex-1 bg-transparent text-sm font-semibold outline-none"
786
+ }
787
+ )
788
+ ] }),
789
+ /* @__PURE__ */ jsxs("div", { className: "flex flex-wrap items-center gap-1.5", children: [
790
+ /* @__PURE__ */ jsxs("div", { className: "relative", children: [
791
+ /* @__PURE__ */ jsx(
792
+ "select",
793
+ {
794
+ value: task.status,
795
+ onChange: (e) => updateTask(task.id, { status: e.target.value }),
796
+ className: "appearance-none rounded-full border bg-background pl-5 pr-6 py-1 text-xs font-medium cursor-pointer hover:border-primary/40 transition-colors",
797
+ children: TASK_STATUSES.map((s) => /* @__PURE__ */ jsx("option", { value: s, children: t(`tasks.status.${s}`) }, s))
798
+ }
799
+ ),
800
+ /* @__PURE__ */ jsx("span", { className: `absolute left-2 top-1/2 -translate-y-1/2 h-2 w-2 rounded-full ${STATUS_DOT[task.status]}` }),
801
+ /* @__PURE__ */ jsx(ChevronDown, { className: "absolute right-1.5 top-1/2 -translate-y-1/2 h-3 w-3 text-muted-foreground pointer-events-none" })
802
+ ] }),
803
+ /* @__PURE__ */ jsxs("div", { className: "relative", children: [
804
+ /* @__PURE__ */ jsx(
805
+ "select",
806
+ {
807
+ value: task.priority,
808
+ onChange: (e) => updateTask(task.id, { priority: e.target.value }),
809
+ className: "appearance-none rounded-full border bg-background pl-2 pr-6 py-1 text-xs font-medium cursor-pointer hover:border-primary/40 transition-colors",
810
+ children: TASK_PRIORITIES.map((p) => /* @__PURE__ */ jsx("option", { value: p, children: t(`tasks.priority.${p}`) }, p))
811
+ }
812
+ ),
813
+ /* @__PURE__ */ jsx(ChevronDown, { className: "absolute right-1.5 top-1/2 -translate-y-1/2 h-3 w-3 text-muted-foreground pointer-events-none" })
814
+ ] }),
815
+ /* @__PURE__ */ jsxs("div", { className: "relative", children: [
816
+ /* @__PURE__ */ jsx(
817
+ "input",
818
+ {
819
+ type: "date",
820
+ value: task.dueDate ?? "",
821
+ onChange: (e) => updateTask(task.id, { dueDate: e.target.value || null }),
822
+ className: "appearance-none rounded-full border bg-background pl-6 pr-2 py-1 text-xs font-medium cursor-pointer hover:border-primary/40 transition-colors w-[120px]"
823
+ }
824
+ ),
825
+ /* @__PURE__ */ jsx(Calendar, { className: "absolute left-2 top-1/2 -translate-y-1/2 h-3 w-3 text-muted-foreground pointer-events-none" })
826
+ ] }),
827
+ task.labels.length > 0 && /* @__PURE__ */ jsx(TaskLabelBadges, { labelIds: task.labels, max: 3 })
828
+ ] }),
829
+ /* @__PURE__ */ jsx(
830
+ "textarea",
831
+ {
832
+ value: description,
833
+ onChange: (e) => setDescription(e.target.value),
834
+ onBlur: handleDescriptionBlur,
835
+ placeholder: t("tasks.detail.descriptionPlaceholder"),
836
+ rows: 3,
837
+ className: "w-full rounded-input border border-input bg-card shadow-[inset_0_1px_0_rgb(0_0_0_/0.06)] px-3 py-2 text-xs outline-none resize-none placeholder:text-muted-foreground/50 leading-relaxed"
838
+ }
839
+ ),
840
+ /* @__PURE__ */ jsxs("div", { children: [
841
+ /* @__PURE__ */ jsx("p", { className: "text-[10px] font-semibold text-muted-foreground uppercase tracking-wider mb-1", children: t("tasks.detail.subtasks") }),
842
+ /* @__PURE__ */ jsxs("div", { className: "rounded-md border overflow-hidden", children: [
843
+ /* @__PURE__ */ jsx(TaskQuickAdd, { parentId: task.id }),
844
+ subtasks.length > 0 && /* @__PURE__ */ jsx("div", { className: "divide-y", children: subtasks.map((st) => /* @__PURE__ */ jsx(TaskCard, { task: st }, st.id)) })
845
+ ] })
846
+ ] }),
847
+ /* @__PURE__ */ jsxs("div", { className: "flex items-center justify-between pt-2 border-t", children: [
848
+ /* @__PURE__ */ jsxs("span", { className: "text-[10px] text-muted-foreground", children: [
849
+ formatDate(task.createdAt),
850
+ " \xB7 ",
851
+ t("tasks.detail.updated"),
852
+ " ",
853
+ formatDate(task.updatedAt)
854
+ ] }),
855
+ /* @__PURE__ */ jsxs(
856
+ "button",
857
+ {
858
+ type: "button",
859
+ onClick: handleDelete,
860
+ className: "inline-flex items-center gap-1 text-[11px] text-muted-foreground hover:text-destructive transition-colors",
861
+ children: [
862
+ /* @__PURE__ */ jsx(Trash2, { className: "h-3 w-3" }),
863
+ t("tasks.detail.delete")
864
+ ]
865
+ }
866
+ )
867
+ ] })
868
+ ] });
869
+ }
870
+ var STATUS_ORDER = ["todo", "in_progress", "done", "cancelled"];
871
+ function TasksDrawer() {
872
+ const t = useTranslation();
873
+ const drawerOpen = useTasksStore((s) => s.drawerOpen);
874
+ const closeDrawer = useTasksStore((s) => s.closeDrawer);
875
+ const selectedTaskId = useTasksStore((s) => s.selectedTaskId);
876
+ const tasks = useTasksStore((s) => s.tasks);
877
+ const tasksLoading = useTasksStore((s) => s.tasksLoading);
878
+ const summary = useTasksStore((s) => s.summary);
879
+ const activeFilter = useTasksStore((s) => s.activeFilter);
880
+ const grouped = React4.useMemo(() => {
881
+ const map = /* @__PURE__ */ new Map();
882
+ for (const s of STATUS_ORDER) map.set(s, []);
883
+ for (const task of tasks) {
884
+ const group = map.get(task.status);
885
+ if (group) group.push(task);
886
+ }
887
+ return map;
888
+ }, [tasks]);
889
+ const summaryLine = React4.useMemo(() => {
890
+ if (!summary) return "";
891
+ const parts = [];
892
+ if (summary.overdue > 0) parts.push(`${summary.overdue} ${t("tasks.summary.overdue")}`);
893
+ if (summary.dueToday > 0) parts.push(`${summary.dueToday} ${t("tasks.summary.dueToday")}`);
894
+ return parts.join(" \xB7 ");
895
+ }, [summary, t]);
896
+ return /* @__PURE__ */ jsx(Sheet, { open: drawerOpen, onOpenChange: (v) => {
897
+ if (!v) closeDrawer();
898
+ }, children: /* @__PURE__ */ jsxs(SheetContent, { width: "max-w-lg", overlay: "dim", children: [
899
+ /* @__PURE__ */ jsxs(SheetHeader, { children: [
900
+ /* @__PURE__ */ jsx(SheetTitle, { children: t("tasks.drawer.title") }),
901
+ /* @__PURE__ */ jsx(SheetDescription, { children: summaryLine || t("tasks.drawer.subtitle") })
902
+ ] }),
903
+ !selectedTaskId && /* @__PURE__ */ jsx(TasksFilterBar, {}),
904
+ !selectedTaskId && /* @__PURE__ */ jsx(TaskQuickAdd, {}),
905
+ /* @__PURE__ */ jsx(SheetBody, { className: "px-0 py-0", children: selectedTaskId ? /* @__PURE__ */ jsx("div", { className: "px-5 py-4", children: /* @__PURE__ */ jsx(TaskDetail, { taskId: selectedTaskId }) }) : tasksLoading && tasks.length === 0 ? /* @__PURE__ */ jsx("div", { className: "flex items-center justify-center py-16", children: /* @__PURE__ */ jsx("div", { className: "h-5 w-5 animate-spin rounded-full border-2 border-primary border-t-transparent" }) }) : tasks.length === 0 ? /* @__PURE__ */ jsxs("div", { className: "flex flex-col items-center justify-center py-16 text-muted-foreground", children: [
906
+ /* @__PURE__ */ jsx(ClipboardList, { className: "h-10 w-10 mb-3 opacity-40" }),
907
+ /* @__PURE__ */ jsx("p", { className: "text-sm font-medium", children: t("tasks.empty") }),
908
+ /* @__PURE__ */ jsx("p", { className: "text-xs mt-1", children: t("tasks.empty.description") })
909
+ ] }) : activeFilter !== "all" ? /* @__PURE__ */ jsx("div", { className: "py-1", children: tasks.map((task) => /* @__PURE__ */ jsx("div", { className: "px-2", children: /* @__PURE__ */ jsx(TaskCard, { task }) }, task.id)) }) : /* @__PURE__ */ jsx("div", { className: "py-2 space-y-2", children: STATUS_ORDER.filter((s) => s !== "cancelled" || (grouped.get(s)?.length ?? 0) > 0).map((status) => /* @__PURE__ */ jsx(TaskStatusGroup, { status, tasks: grouped.get(status) ?? [] }, status)) }) })
910
+ ] }) });
911
+ }
912
+ function TasksTopbarButton({ config }) {
913
+ const { tasksConfig, tasksProvider, tasksStore } = config;
914
+ return /* @__PURE__ */ jsxs(TasksContextProvider, { config: tasksConfig, provider: tasksProvider, store: tasksStore, children: [
915
+ /* @__PURE__ */ jsx(TasksTopbarButtonInner, { store: tasksStore }),
916
+ /* @__PURE__ */ jsx(TasksDrawer, {})
917
+ ] });
918
+ }
919
+ function TasksTopbarButtonInner({ store }) {
920
+ const toggleDrawer = useStore(store, (s) => s.toggleDrawer);
921
+ const fetchSummary = useStore(store, (s) => s.fetchSummary);
922
+ const summary = useStore(store, (s) => s.summary);
923
+ useEffect(() => {
924
+ fetchSummary();
925
+ }, [fetchSummary]);
926
+ const pendingCount = summary ? summary.todo + summary.inProgress : 0;
927
+ return /* @__PURE__ */ jsxs(
928
+ Button,
929
+ {
930
+ variant: "ghost",
931
+ size: "icon",
932
+ className: cn("relative text-sidebar-foreground/70 hover:bg-sidebar/30 hover:text-sidebar-foreground"),
933
+ onClick: toggleDrawer,
934
+ "aria-label": "Tasks",
935
+ children: [
936
+ /* @__PURE__ */ jsx(CheckSquare, { className: "h-5 w-5" }),
937
+ pendingCount > 0 && /* @__PURE__ */ jsx(
938
+ "span",
939
+ {
940
+ className: cn(
941
+ "absolute -right-0.5 -top-0.5 flex items-center justify-center rounded-full bg-destructive text-destructive-foreground",
942
+ pendingCount > 9 ? "h-5 min-w-5 px-1 text-[10px]" : "h-4 w-4 text-[10px]"
943
+ ),
944
+ children: pendingCount > 99 ? "99+" : pendingCount
945
+ }
946
+ )
947
+ ]
948
+ }
949
+ );
950
+ }
951
+
952
+ // src/index.ts
953
+ var DEFAULT_LABELS = {
954
+ drawerTitle: "Tasks",
955
+ settingsTitle: "Tasks",
956
+ quickAddPlaceholder: "Add a task..."
957
+ };
958
+ function resolveConfig(options) {
959
+ return {
960
+ labels: { ...DEFAULT_LABELS, ...options?.labels }
961
+ };
962
+ }
963
+ var MIGRATION_001 = `-- Tasks Plugin: Base Tables
964
+ CREATE TABLE IF NOT EXISTS public.tsk_labels (
965
+ id uuid PRIMARY KEY DEFAULT gen_random_uuid(),
966
+ tenant_id uuid NOT NULL REFERENCES saas_core.tenants(id) ON DELETE CASCADE,
967
+ name text NOT NULL,
968
+ color text NOT NULL DEFAULT '#6366f1',
969
+ is_active boolean NOT NULL DEFAULT true,
970
+ created_at timestamptz NOT NULL DEFAULT now()
971
+ );
972
+ ALTER TABLE public.tsk_labels ENABLE ROW LEVEL SECURITY;
973
+ CREATE INDEX IF NOT EXISTS idx_tsk_labels_tenant ON public.tsk_labels(tenant_id);
974
+
975
+ CREATE TABLE IF NOT EXISTS public.tsk_tasks (
976
+ id uuid PRIMARY KEY DEFAULT gen_random_uuid(),
977
+ tenant_id uuid NOT NULL REFERENCES saas_core.tenants(id) ON DELETE CASCADE,
978
+ title text NOT NULL,
979
+ description text,
980
+ status text NOT NULL DEFAULT 'todo' CHECK (status IN ('todo','in_progress','done','cancelled')),
981
+ priority text NOT NULL DEFAULT 'medium' CHECK (priority IN ('low','medium','high','urgent')),
982
+ due_date date,
983
+ assigned_to_id uuid,
984
+ assigned_to_name text,
985
+ parent_id uuid REFERENCES public.tsk_tasks(id) ON DELETE CASCADE,
986
+ labels jsonb NOT NULL DEFAULT '[]'::jsonb,
987
+ position integer NOT NULL DEFAULT 0,
988
+ created_by_id uuid,
989
+ created_by_name text,
990
+ created_at timestamptz NOT NULL DEFAULT now(),
991
+ updated_at timestamptz NOT NULL DEFAULT now()
992
+ );
993
+ ALTER TABLE public.tsk_tasks ENABLE ROW LEVEL SECURITY;
994
+ CREATE INDEX IF NOT EXISTS idx_tsk_tasks_tenant ON public.tsk_tasks(tenant_id);
995
+ CREATE INDEX IF NOT EXISTS idx_tsk_tasks_status ON public.tsk_tasks(tenant_id, status);
996
+ CREATE INDEX IF NOT EXISTS idx_tsk_tasks_parent ON public.tsk_tasks(parent_id);
997
+ CREATE INDEX IF NOT EXISTS idx_tsk_tasks_assigned ON public.tsk_tasks(assigned_to_id);
998
+ CREATE INDEX IF NOT EXISTS idx_tsk_tasks_due ON public.tsk_tasks(tenant_id, due_date) WHERE due_date IS NOT NULL;
999
+
1000
+ -- RLS policies for tsk_tasks
1001
+ CREATE POLICY tsk_tasks_select ON public.tsk_tasks FOR SELECT TO authenticated USING (tenant_id IN (SELECT public.user_tenant_ids()));
1002
+ CREATE POLICY tsk_tasks_insert ON public.tsk_tasks FOR INSERT TO authenticated WITH CHECK (tenant_id IN (SELECT public.user_tenant_ids()));
1003
+ CREATE POLICY tsk_tasks_update ON public.tsk_tasks FOR UPDATE TO authenticated USING (tenant_id IN (SELECT public.user_tenant_ids()));
1004
+ CREATE POLICY tsk_tasks_delete ON public.tsk_tasks FOR DELETE TO authenticated USING (tenant_id IN (SELECT public.user_tenant_ids()));
1005
+ GRANT SELECT, INSERT, UPDATE, DELETE ON public.tsk_tasks TO authenticated;
1006
+
1007
+ -- RLS policies for tsk_labels
1008
+ CREATE POLICY tsk_labels_select ON public.tsk_labels FOR SELECT TO authenticated USING (tenant_id IN (SELECT public.user_tenant_ids()));
1009
+ CREATE POLICY tsk_labels_insert ON public.tsk_labels FOR INSERT TO authenticated WITH CHECK (tenant_id IN (SELECT public.user_tenant_ids()));
1010
+ CREATE POLICY tsk_labels_update ON public.tsk_labels FOR UPDATE TO authenticated USING (tenant_id IN (SELECT public.user_tenant_ids()));
1011
+ CREATE POLICY tsk_labels_delete ON public.tsk_labels FOR DELETE TO authenticated USING (tenant_id IN (SELECT public.user_tenant_ids()));
1012
+ GRANT SELECT, INSERT, UPDATE, DELETE ON public.tsk_labels TO authenticated;`;
1013
+ function createTasksPlugin(options) {
1014
+ const config = resolveConfig(options);
1015
+ registerTranslations(tasksLocales);
1016
+ const provider = options?.dataProvider ?? createSafeDataProvider(
1017
+ () => createSupabaseTasksProvider(),
1018
+ () => createMockTasksProvider()
1019
+ );
1020
+ const store = createTasksStore(provider);
1021
+ return {
1022
+ id: "tasks",
1023
+ name: config.labels.drawerTitle,
1024
+ icon: "CheckSquare",
1025
+ version: "1.0.0",
1026
+ scope: options?.scope ?? "universal",
1027
+ verticalId: options?.verticalId,
1028
+ defaultEnabled: true,
1029
+ dependencies: [],
1030
+ navigation: [],
1031
+ routes: [],
1032
+ widgets: [
1033
+ {
1034
+ id: "tasks-topbar-button",
1035
+ zone: "shell.topbar.end",
1036
+ component: TasksTopbarButton,
1037
+ order: 10,
1038
+ props: {
1039
+ tasksConfig: config,
1040
+ tasksProvider: provider,
1041
+ tasksStore: store
1042
+ }
1043
+ }
1044
+ ],
1045
+ aiTools: [
1046
+ {
1047
+ id: "tasks.summary",
1048
+ name: "getTasksSummary",
1049
+ description: "Returns a summary of pending tasks: total, overdue, due today, by status and priority.",
1050
+ icon: "CheckSquare",
1051
+ mode: "read",
1052
+ category: "Tasks",
1053
+ parameters: {
1054
+ type: "object",
1055
+ properties: {
1056
+ status: {
1057
+ type: "string",
1058
+ description: "Filter by task status",
1059
+ enum: ["todo", "in_progress", "done", "cancelled", "all"]
1060
+ }
1061
+ }
1062
+ },
1063
+ suggestions: [
1064
+ { label: "What tasks are overdue?" },
1065
+ { label: "How many tasks are pending?" },
1066
+ { label: "What's due today?" }
1067
+ ]
1068
+ }
1069
+ ],
1070
+ registries: tasksRegistries,
1071
+ settings: [
1072
+ {
1073
+ id: "tasks",
1074
+ label: config.labels.settingsTitle,
1075
+ icon: "CheckSquare",
1076
+ component: (() => {
1077
+ const Tab = () => React4.createElement(
1078
+ TasksContextProvider,
1079
+ { config, provider, store },
1080
+ React4.createElement(TasksGeneralSettings)
1081
+ );
1082
+ Tab.displayName = "TasksSettingsTab";
1083
+ return Tab;
1084
+ })(),
1085
+ order: 14
1086
+ }
1087
+ ],
1088
+ migrations: [
1089
+ {
1090
+ id: "tasks-001-base-tables",
1091
+ version: "1.0.0",
1092
+ sql: MIGRATION_001,
1093
+ description: "Create tsk_tasks and tsk_labels tables"
1094
+ }
1095
+ ],
1096
+ locales: tasksLocales
1097
+ };
1098
+ }
1099
+
1100
+ export { createTasksPlugin };
1101
+ //# sourceMappingURL=index.js.map
1102
+ //# sourceMappingURL=index.js.map