@type32/tasks 0.2.0 → 0.3.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/README.md CHANGED
@@ -137,7 +137,9 @@ fields:
137
137
 
138
138
  ## Views: boards, lists and calendars saved in the file
139
139
 
140
- A document can keep its views, so every app that opens it shows the same board. A view has a `type` (`list`, `board`, `calendar`, `timeline`, `table`), and optionally `groupBy`, `sortBy`, `sortDescending`, `listIds`, `openOnly` and `scale`. Group and sort keys are task keys (`listId`, `due`, `starred`…) or `values.<field id>`. An app keeps its own settings for a view on it as extra keys.
140
+ A document can keep its views, so every app that opens it shows the same board. A view has a `type` (`list`, `board`, `calendar`, `timeline`, `table`), and optionally `groupBy`, `sortBy`, `sortDescending`, `listIds`, `openOnly`, `scale` and `zoom` (a timeline's pixels a day). Group and sort keys are task keys (`listId`, `due`, `starred`…) or `values.<field id>`. An app keeps its own settings for a view on it as extra keys.
141
+
142
+ A task can carry its own `color`, and the built-in `assignees` field lists the people it's for: the document names them as the field's options (`{ id, title, color }`), and `values.assignees` holds their ids. iCalendar maps them to `ATTENDEE`.
141
143
 
142
144
  ```ts
143
145
  import { resolveFields, viewTasks } from "@type32/tasks";
package/SPEC.md CHANGED
@@ -1,4 +1,4 @@
1
- # Tasks format 1.1
1
+ # Tasks format 1.2
2
2
 
3
3
  One document format for todos, calendar events and timelines. A todo, an event and a timeline bar are the same object, a **task**; which one it is depends only on which time fields it has. Field names and meanings follow [JSCalendar (RFC 8984)](https://www.rfc-editor.org/rfc/rfc8984) where they overlap, so conversion stays mechanical.
4
4
 
@@ -7,7 +7,7 @@ A document can be written as JSON, YAML or TOML; the data model is identical. Ev
7
7
  ## Document
8
8
 
9
9
  ```yaml
10
- version: "1.1"
10
+ version: "1.2"
11
11
  lists: [] # optional
12
12
  fields: [] # optional
13
13
  views: [] # optional
@@ -93,6 +93,7 @@ A saved way of showing the tasks, so every app that opens the document shows the
93
93
  | `listIds` | Id[] | Only tasks in these lists or lists nested in them. Each must name a list. Absent: every task. |
94
94
  | `openOnly` | boolean | Only open tasks: status `todo` or `doing`. |
95
95
  | `scale` | string | Calendar: the period a page shows. Timeline: the period a column stands for. `day`, `week` or `month`; an app uses its default for a value it doesn't know. |
96
+ | `zoom` | number | Timeline: pixels a day, positive, for an app that zooms freely (1.2). It keeps `scale` at the preset nearest it, for apps that only know those. |
96
97
 
97
98
  A view never shows deleted tasks. Sorting:
98
99
 
@@ -118,6 +119,7 @@ A view never shows deleted tasks. Sorting:
118
119
  | `excludedDates` | (LocalDate \| LocalDateTime)[] | Occurrences to skip. Needs `recurrence`; same form as the anchor. |
119
120
  | `completedAt` | UTCDateTime | |
120
121
  | `starred` | boolean | Marked to stand out (a star or a flag). |
122
+ | `color` | Color | How apps draw the task (1.2). Absent: its list's `color`, then the app's own. |
121
123
  | `values` | object | Field id → value. See [Fields](#fields). |
122
124
 
123
125
  ### Kind
@@ -224,13 +226,16 @@ Every option merges on its own, so two devices adding options at the same time b
224
226
 
225
227
  Always present. A document may list a built-in field only to add options to it, or to change a built-in option's `title` and `color` by reusing its id. Its type, categories and other settings are locked, built-in options keep their category and can't be deleted.
226
228
 
227
- | Id | Type | Categories | Options |
228
- | ---------- | ----------- | --------------------------- | -------------------------- |
229
- | `status` | select | `todo doing done cancelled` | one per category, same ids |
230
- | `priority` | select | `low medium high` | one per category, same ids |
231
- | `tags` | multiSelect | none, `open` | none |
232
- | `progress` | number | 0–100 | |
233
- | `location` | text | | |
229
+ | Id | Type | Categories | Options |
230
+ | ----------- | ----------- | --------------------------- | -------------------------- |
231
+ | `status` | select | `todo doing done cancelled` | one per category, same ids |
232
+ | `priority` | select | `low medium high` | one per category, same ids |
233
+ | `tags` | multiSelect | none, `open` | none |
234
+ | `progress` | number | 0–100 | |
235
+ | `location` | text | | |
236
+ | `assignees` | multiSelect | none | none: the people (1.2) |
237
+
238
+ `assignees` (1.2) lists the people a task is for. Its options are the people: `title` their name, `color` the colour apps draw them in, and any extra keys an app keeps (an `email`, for iCalendar). Values must be option ids, so a person is renamed once for every task. A 1.0 or 1.1 document that has a custom field named `assignees` must rename it before it's read as 1.2.
234
239
 
235
240
  Built-in categories are what other apps rely on: any app knows a task with status `shipped` is done because `shipped` maps to `done`. A task without a status counts as `todo`.
236
241
 
@@ -264,32 +269,33 @@ Informative. How `toICS`/`fromICS` map to RFC 5545; other implementations should
264
269
 
265
270
  A task exports as a **VEVENT** when it has `start`, no `due`, and no status other than `cancelled`; otherwise as a **VTODO**. Deleted tasks are skipped.
266
271
 
267
- | Task | iCalendar |
268
- | ----------------------------------- | ------------------------------------------------------------------------------------------------------------ |
269
- | `id` | `UID` |
270
- | `updatedAt` | `LAST-MODIFIED` and `DTSTAMP`. Import prefers `LAST-MODIFIED`; neither → `1970-01-01T00:00:00Z` |
271
- | `title`, `notes`, `values.location` | `SUMMARY`, `DESCRIPTION`, `LOCATION` |
272
- | `start`, `due` | `DTSTART`, `DUE`, with `VALUE=DATE` for dates and `TZID=<IANA>` from `timeZone`. `timeZone: UTC` writes `…Z` |
273
- | `end` | VEVENT `DTEND`, one day later for dates (iCalendar ends are exclusive). VTODO: `DURATION` |
274
- | `duration` | `DURATION` |
275
- | status category | `STATUS`: todo `NEEDS-ACTION`, doing `IN-PROCESS`, done `COMPLETED`, cancelled `CANCELLED` |
276
- | priority category | `PRIORITY`: high 1, medium 5, low 9. Import: 1–4 high, 5 medium, 6–9 low |
277
- | `values.progress`, `completedAt` | VTODO `PERCENT-COMPLETE`, `COMPLETED` |
278
- | `values.tags` | `CATEGORIES` |
279
- | `parentId` | `RELATED-TO;RELTYPE=PARENT` (the default `RELTYPE`) |
280
- | `dependsOn` | `RELATED-TO;RELTYPE=DEPENDS-ON` (RFC 9253). Import also reads `FINISHTOSTART` from the predecessor |
281
- | `recurrence`, `excludedDates` | `RRULE`, `EXDATE`. `UNTIL` is written in UTC when the task has a time zone |
272
+ | Task | iCalendar |
273
+ | ----------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
274
+ | `id` | `UID` |
275
+ | `updatedAt` | `LAST-MODIFIED` and `DTSTAMP`. Import prefers `LAST-MODIFIED`; neither → `1970-01-01T00:00:00Z` |
276
+ | `title`, `notes`, `values.location` | `SUMMARY`, `DESCRIPTION`, `LOCATION` |
277
+ | `start`, `due` | `DTSTART`, `DUE`, with `VALUE=DATE` for dates and `TZID=<IANA>` from `timeZone`. `timeZone: UTC` writes `…Z` |
278
+ | `end` | VEVENT `DTEND`, one day later for dates (iCalendar ends are exclusive). VTODO: `DURATION` |
279
+ | `duration` | `DURATION` |
280
+ | status category | `STATUS`: todo `NEEDS-ACTION`, doing `IN-PROCESS`, done `COMPLETED`, cancelled `CANCELLED` |
281
+ | priority category | `PRIORITY`: high 1, medium 5, low 9. Import: 1–4 high, 5 medium, 6–9 low |
282
+ | `values.progress`, `completedAt` | VTODO `PERCENT-COMPLETE`, `COMPLETED` |
283
+ | `values.tags` | `CATEGORIES` |
284
+ | `values.assignees` | `ATTENDEE;CN=<title>;X-TASKS-ID=<id>`, at `mailto:<email>` when the option has an `email`, else at `urn:x-tasks:assignee:<id>`. Import: the option is `X-TASKS-ID`, else the id in that URI, else the email, else `CN`; options are added to the document's `assignees` field |
285
+ | `parentId` | `RELATED-TO;RELTYPE=PARENT` (the default `RELTYPE`) |
286
+ | `dependsOn` | `RELATED-TO;RELTYPE=DEPENDS-ON` (RFC 9253). Import also reads `FINISHTOSTART` from the predecessor |
287
+ | `recurrence`, `excludedDates` | `RRULE`, `EXDATE`. `UNTIL` is written in UTC when the task has a time zone |
282
288
 
283
289
  Time zones are referenced by IANA name without `VTIMEZONE` blocks (RFC 7809). On import, every time is converted to the zone of `DTSTART` (or `DUE`).
284
290
 
285
- **Lost on export:** lists, views, custom fields, custom status and priority options (exported as their category), `starred`, unknown keys, deleted tasks.
291
+ **Lost on export:** lists, views, custom fields, custom status and priority options (exported as their category), `starred`, `color`, unknown keys, deleted tasks.
286
292
 
287
293
  **Dropped on import, and reported:**
288
294
 
289
295
  - whole components: `RRULE` parts other than `FREQ` (daily to yearly), `INTERVAL`, `COUNT`, `UNTIL`, `BYDAY`, `BYMONTHDAY`, `BYMONTH`, and `WKST` (`WKST` is dropped only where it changes results); changed occurrences (`RECURRENCE-ID`); TZIDs that aren't IANA names; components that break a rule of this spec
290
296
  - single properties: `RDATE`, and relations to tasks not in the file
291
297
 
292
- Ignored on import: alarms, attendees, and other properties without a counterpart.
298
+ Ignored on import: alarms, attendees' roles and replies, and other properties without a counterpart.
293
299
 
294
300
  ## Validity
295
301
 
package/dist/index.d.mts CHANGED
@@ -59,6 +59,8 @@ interface View extends Synced {
59
59
  openOnly?: boolean;
60
60
  /** Calendar: the period a page shows. Timeline: the period a column stands for. `day`, `week` or `month`; apps use their default for one they don't know. */
61
61
  scale?: string;
62
+ /** Timeline: pixels a day, for an app that zooms freely; `scale` is then the preset nearest it. Positive. */
63
+ zoom?: number;
62
64
  }
63
65
  /** A choice of a select field. Each option is its own synced record. */
64
66
  interface FieldOption extends Synced {
@@ -71,7 +73,7 @@ interface FieldOption extends Synced {
71
73
  }
72
74
  /**
73
75
  * A custom field, or options added to a built-in one.
74
- * Built-in ids (`status`, `priority`, `tags`, `progress`, `location`) only take `options`;
76
+ * Built-in ids (`status`, `priority`, `tags`, `progress`, `location`, `assignees`) only take `options`;
75
77
  * custom fields need `title`, `type`, `updatedAt`.
76
78
  */
77
79
  interface FieldDefinition {
@@ -137,15 +139,17 @@ interface Task extends Synced {
137
139
  completedAt?: UTCDateTime;
138
140
  /** Marked to stand out (a star or a flag). */
139
141
  starred?: boolean;
142
+ /** `#rrggbb`: how apps draw the task. Absent: its list's colour, then the app's. */
143
+ color?: string;
140
144
  /**
141
- * Field id → value, built-in (`status`, `priority`, `tags`, `progress`, `location`) and custom alike.
145
+ * Field id → value, built-in (`status`, `priority`, `tags`, `progress`, `location`, `assignees`) and custom alike.
142
146
  * A key must name a field; a select value must be an option id. Read meanings with `resolveFields()`.
143
147
  */
144
148
  values?: Record<string, FieldValue>;
145
149
  }
146
150
  /** A whole file: lists, field definitions, views and tasks. */
147
151
  interface TaskDocument {
148
- /** `"1.1"`; readers accept any `1.x`. */
152
+ /** `"1.2"`; readers accept any `1.x`. */
149
153
  version: string;
150
154
  lists?: List[];
151
155
  fields?: FieldDefinition[];
package/dist/index.mjs CHANGED
@@ -76,7 +76,8 @@ const BUILT_IN_FIELDS = Object.assign(Object.create(null), {
76
76
  min: 0,
77
77
  max: 100
78
78
  }),
79
- location: builtIn("location", "Location", "text")
79
+ location: builtIn("location", "Location", "text"),
80
+ assignees: builtIn("assignees", "Assignees", "multiSelect")
80
81
  });
81
82
  /** Built-in fields merged with the document's `fields`. Deleted fields and options stay, flagged `deleted`. */
82
83
  function resolveFields(doc) {
@@ -204,7 +205,8 @@ const viewSchema = z.looseObject({
204
205
  sortDescending: z.boolean().exactOptional(),
205
206
  listIds: z.array(id).exactOptional(),
206
207
  openOnly: z.boolean().exactOptional(),
207
- scale: z.string().exactOptional()
208
+ scale: z.string().exactOptional(),
209
+ zoom: z.number().positive("expected a positive number of pixels a day").exactOptional()
208
210
  });
209
211
  const fieldSchema = z.looseObject({
210
212
  id,
@@ -267,6 +269,7 @@ const taskSchema = z.looseObject({
267
269
  excludedDates: z.array(local).exactOptional(),
268
270
  completedAt: utc$1.exactOptional(),
269
271
  starred: z.boolean().exactOptional(),
272
+ color: color.exactOptional(),
270
273
  values: z.record(z.string(), z.union([
271
274
  z.string(),
272
275
  z.number(),
@@ -1055,6 +1058,13 @@ function toICS(doc) {
1055
1058
  const valid = validate(doc);
1056
1059
  const fields = resolveFields(valid);
1057
1060
  const category = (fieldId, value) => fields[fieldId].options.find((o) => o.id === value)?.category;
1061
+ const people = new Map((valid.fields?.find((f) => f.id === "assignees")?.options ?? []).map((o) => [o.id, o]));
1062
+ const attendee = (id) => {
1063
+ const name = fields["assignees"].options.find((o) => o.id === id)?.title ?? id;
1064
+ const email = people.get(id)?.["email"];
1065
+ const address = typeof email === "string" ? `mailto:${email}` : `${ASSIGNEE_URI}${encodeURIComponent(id)}`;
1066
+ return `ATTENDEE;CN="${name.replace(/["\r\n]/g, "'")}";X-TASKS-ID="${id.replace(/["\r\n]/g, "")}":${address}`;
1067
+ };
1058
1068
  const lines = [
1059
1069
  "BEGIN:VCALENDAR",
1060
1070
  "VERSION:2.0",
@@ -1089,6 +1099,8 @@ function toICS(doc) {
1089
1099
  }
1090
1100
  const tags = values["tags"];
1091
1101
  if (Array.isArray(tags) && tags.length > 0) lines.push(`CATEGORIES:${tags.map(escape).join(",")}`);
1102
+ const assignees = values["assignees"];
1103
+ if (Array.isArray(assignees)) for (const id of assignees) lines.push(attendee(id));
1092
1104
  if (t.parentId !== void 0) lines.push(`RELATED-TO;RELTYPE=PARENT:${escape(t.parentId)}`);
1093
1105
  for (const id of t.dependsOn ?? []) lines.push(`RELATED-TO;RELTYPE=DEPENDS-ON:${escape(id)}`);
1094
1106
  if (t.recurrence) lines.push(`RRULE:${rrule(t.recurrence, zone)}`);
@@ -1155,12 +1167,13 @@ function fromICS(text) {
1155
1167
  const dropped = [];
1156
1168
  const tasks = [];
1157
1169
  const successors = [];
1170
+ const people = /* @__PURE__ */ new Map();
1158
1171
  readComponents(text).forEach((c, n) => {
1159
1172
  const uid = c.props.find((p) => p.name === "UID")?.value;
1160
1173
  try {
1161
1174
  if (uid === void 0) throw new Skip(`${c.type} without UID`);
1162
1175
  if (tasks.some((t) => t.id === uid)) throw new Skip("duplicate UID");
1163
- tasks.push(toTask(c, uid, dropped, successors));
1176
+ tasks.push(toTask(c, uid, dropped, successors, people));
1164
1177
  } catch (error) {
1165
1178
  if (!(error instanceof Skip || error instanceof RangeError)) throw error;
1166
1179
  dropped.push({
@@ -1173,9 +1186,18 @@ function fromICS(text) {
1173
1186
  const task = tasks.find((t) => t.id === after);
1174
1187
  if (task) task.dependsOn = [.../* @__PURE__ */ new Set([...task.dependsOn ?? [], before])];
1175
1188
  }
1189
+ const fields = people.size ? [{
1190
+ id: "assignees",
1191
+ options: [...people].map(([id, p]) => ({
1192
+ id,
1193
+ updatedAt: EPOCH,
1194
+ ...p
1195
+ }))
1196
+ }] : [];
1176
1197
  return {
1177
1198
  document: settle({
1178
1199
  version: "1.0",
1200
+ ...fields.length > 0 && { fields },
1179
1201
  tasks
1180
1202
  }, dropped),
1181
1203
  dropped
@@ -1217,7 +1239,21 @@ function settle(doc, dropped) {
1217
1239
  }
1218
1240
  }
1219
1241
  }
1220
- function toTask(c, uid, dropped, successors) {
1242
+ /** An attendee's address for an assignee without an email, so it comes back as the same option. */
1243
+ const ASSIGNEE_URI = "urn:x-tasks:assignee:";
1244
+ /** The option for an attendee: the id we wrote (`X-TASKS-ID`, or in our URI), else its email, else its name. */
1245
+ function personOf(p) {
1246
+ const title = p.params["CN"]?.trim();
1247
+ const address = p.value.trim();
1248
+ const ours = address.toLowerCase().startsWith(ASSIGNEE_URI) ? decodeURIComponent(address.slice(21)) : void 0;
1249
+ const email = /^mailto:/i.test(address) ? address.slice(7).toLowerCase() : void 0;
1250
+ const id = p.params["X-TASKS-ID"] || ours || email || title;
1251
+ return id ? [id, {
1252
+ title: title || id,
1253
+ ...email && { email }
1254
+ }] : void 0;
1255
+ }
1256
+ function toTask(c, uid, dropped, successors, people) {
1221
1257
  const all = (name) => c.props.filter((p) => p.name === name);
1222
1258
  const one = (name) => c.props.find((p) => p.name === name);
1223
1259
  if (one("RECURRENCE-ID")) throw new Skip("changed occurrences of a recurring item aren't supported");
@@ -1261,6 +1297,14 @@ function toTask(c, uid, dropped, successors) {
1261
1297
  if (completed) task.completedAt = instant(completed.value);
1262
1298
  const tags = [...new Set(all("CATEGORIES").flatMap((p) => unescape(p.value, true)).map((s) => s.trim()))].filter(Boolean);
1263
1299
  if (tags.length > 0) values["tags"] = tags;
1300
+ const assignees = /* @__PURE__ */ new Set();
1301
+ for (const p of all("ATTENDEE")) {
1302
+ const found = personOf(p);
1303
+ if (!found) continue;
1304
+ if (!people.has(found[0])) people.set(...found);
1305
+ assignees.add(found[0]);
1306
+ }
1307
+ if (assignees.size > 0) values["assignees"] = [...assignees];
1264
1308
  if (Object.keys(values).length > 0) task.values = values;
1265
1309
  for (const p of all("RELATED-TO")) {
1266
1310
  const target = unescape(p.value)[0];
package/dist/schema.json CHANGED
@@ -188,6 +188,10 @@
188
188
  },
189
189
  "scale": {
190
190
  "type": "string"
191
+ },
192
+ "zoom": {
193
+ "type": "number",
194
+ "exclusiveMinimum": 0
191
195
  }
192
196
  },
193
197
  "required": [
@@ -348,6 +352,10 @@
348
352
  "starred": {
349
353
  "type": "boolean"
350
354
  },
355
+ "color": {
356
+ "type": "string",
357
+ "pattern": "^#[0-9a-fA-F]{6}$"
358
+ },
351
359
  "values": {
352
360
  "type": "object",
353
361
  "propertyNames": {
package/llms.txt CHANGED
@@ -22,8 +22,9 @@ A task's kind comes from its time fields, never a type field: `start` plus `end`
22
22
  - Built-ins: `status: todo|doing|done|cancelled`, `priority: low|medium|high`, `tags: string[]`, `progress: 0–100`, `location: string`.
23
23
  - A custom field or custom option must be defined under `fields` before use. A custom status option maps to a built-in category: `{ id: shipped, title: Shipped, category: done, updatedAt }`.
24
24
  - Colors are `#rrggbb`.
25
- - `task.starred: boolean` marks a task to stand out (a star or flag).
26
- - Views (synced records like tasks): `{ id, title, type: list|board|calendar|timeline|table, groupBy?, sortBy?, sortDescending?, listIds?, openOnly?, scale?: day|week|month, updatedAt }`. `groupBy` is `listId`, `starred` or `values.<id>` of a select, multiSelect or boolean field; `sortBy` is `title`, `start`, `end`, `due`, `completedAt`, `updatedAt`, `starred` or `values.<id>` of any non-multiSelect field. Put app-specific view settings on the view as extra keys.
25
+ - `task.starred: boolean` marks a task to stand out (a star or flag). `task.color: "#rrggbb"` is how apps draw it (absent: its list's colour).
26
+ - `values.assignees` (built-in multiSelect) holds option ids: the people are the field's options (`fields: [{ id: assignees, options: [{ id, title, color?, updatedAt }] }]`).
27
+ - Views (synced records like tasks): `{ id, title, type: list|board|calendar|timeline|table, groupBy?, sortBy?, sortDescending?, listIds?, openOnly?, scale?: day|week|month, zoom?: number (timeline px a day), updatedAt }`. `groupBy` is `listId`, `starred` or `values.<id>` of a select, multiSelect or boolean field; `sortBy` is `title`, `start`, `end`, `due`, `completedAt`, `updatedAt`, `starred` or `values.<id>` of any non-multiSelect field. Put app-specific view settings on the view as extra keys.
27
28
  - Unknown keys anywhere are kept, except inside `recurrence`, where they're an error.
28
29
 
29
30
  ## Rules for writing code
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@type32/tasks",
3
- "version": "0.2.0",
3
+ "version": "0.3.0",
4
4
  "description": "One format for todos, events and timelines: schema, validation and parsing",
5
5
  "license": "MIT",
6
6
  "files": [