@dou-ui/gantt 0.1.0-alpha.12 → 0.1.0-alpha.13

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.
@@ -92,13 +92,13 @@ function withOrder(tasks) {
92
92
  * saved as JSON starts being edited together. Every task gets an `order`
93
93
  * key. Do it once, where the shared document is created.
94
94
  */
95
- function fillMaps(maps, doc) {
95
+ function fillMaps(maps, doc, options = {}) {
96
96
  const fill = () => {
97
97
  for (const task of withOrder(doc.tasks)) write(maps.tasks, task);
98
98
  for (const link of doc.links) write(maps.links, link);
99
99
  };
100
100
  const ydoc = maps.tasks.doc;
101
- if (ydoc) ydoc.transact(fill);
101
+ if (ydoc) ydoc.transact(fill, options.origin ?? null);
102
102
  else fill();
103
103
  }
104
104
  /** The tasks and links a transaction added, removed or changed. */
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","names":[],"sources":["../../src/collaboration/index.ts"],"sourcesContent":["import { collaborationColors } from 'dou-ui'\nimport { toRaw, watch } from 'vue'\nimport * as Y from 'yjs'\nimport { defineGanttExtension, type GanttExtension } from '../core/extension'\nimport type { GanttLink, GanttTask } from '../core/model'\nimport { isOrderKey, orderKeys } from '../core/order'\nimport type { GanttDocument, GanttStep, GanttTransaction } from '../core/transaction'\nimport { buildTree } from '../core/tree'\nimport { createPeers, type AwarenessLike, type GanttPresence } from './peers'\n\n/** How the people editing together see each other. */\nexport interface CollaborationUser {\n name: string\n /** The color of this user's outlines, any CSS color. Picked from the client id when left out. */\n color?: string\n}\n\nexport interface CollaborationOptions {\n /** Where the tasks live, e.g. `ydoc.getMap('tasks')`. */\n tasks: Y.Map<unknown>\n /** Where the links live, e.g. `ydoc.getMap('links')`; in the same `Y.Doc` as `tasks`. */\n links: Y.Map<unknown>\n /** Shares what each person selects and drags (`y-protocols/awareness`). */\n awareness?: AwarenessLike\n /** This user, shown to the others. Needs `awareness`. */\n user?: CollaborationUser\n}\n\nexport { collaborationColors }\n\ntype Shared = Y.Map<unknown>\ntype Item = Record<string, unknown>\n\n/** Folding is each person's own view: it stays out of the shared document. */\nconst LOCAL_FIELDS = new Set(['id', 'collapsed'])\n\nconst same = (a: unknown, b: unknown) =>\n a === b || (typeof a === 'object' && JSON.stringify(a) === JSON.stringify(b))\n\n/** A task or link as the map holds it, or `null` when it holds none. */\nfunction read<T>(map: Shared, id: string): T | null {\n const fields = map.get(id)\n if (!(fields instanceof Y.Map)) return null\n return { ...(fields.toJSON() as Item), id } as T\n}\n\n/** Where in `value` there is something JSON can't hold (a function, a component, a `Date`…), or `null`. */\nfunction unsharable(value: unknown, path: string, seen = new Set<object>()): string | null {\n if (value === null || ['string', 'number', 'boolean', 'undefined'].includes(typeof value))\n return null\n if (typeof value !== 'object') return path\n const proto = Object.getPrototypeOf(value)\n if (seen.has(value)) return path\n if (!Array.isArray(value) && proto !== Object.prototype && proto !== null) return path\n seen.add(value)\n for (const [key, item] of Object.entries(value)) {\n const found = unsharable(\n item,\n Array.isArray(value) ? `${path}[${key}]` : `${path}.${key}`,\n seen,\n )\n if (found) return found\n }\n return null\n}\n\n/*\n * Such a value reads back fine on this side, but the others get it without\n * the parts JSON can't hold: say so once per field while developing.\n */\nconst warned = new Set<string>()\nfunction checkSharable(id: string, key: string, value: unknown) {\n // the app's bundler replaces this, as for Vue's own warnings\n if (process.env.NODE_ENV === 'production' || warned.has(`${id}:${key}`)) return\n const path = unsharable(toRaw(value), key)\n if (!path) return\n warned.add(`${id}:${key}`)\n console.warn(\n `[@dou-ui/gantt] \"${id}\" has a value at ${path} that can't be shared: only JSON values reach the others. Keep components and functions out of the shared fields, for example by looking them up by name.`,\n )\n}\n\n/** Writes a task's or link's fields, only those that changed. */\nfunction write(map: Shared, value: GanttTask | GanttLink) {\n const item = value as unknown as Item\n const existing = map.get(value.id)\n let fields: Shared\n if (existing instanceof Y.Map) fields = existing\n // a new map joins the document first: it can't be read before\n else map.set(value.id, (fields = new Y.Map<unknown>()))\n for (const [key, field] of Object.entries(item)) {\n if (LOCAL_FIELDS.has(key) || field === undefined) continue\n checkSharable(value.id, key, field)\n if (!same(fields.get(key), field)) fields.set(key, field)\n }\n for (const key of Array.from(fields.keys()))\n if (!LOCAL_FIELDS.has(key) && item[key] === undefined) fields.delete(key)\n}\n\n/** The change that makes `local` match `shared`, keeping the local fields. */\nfunction patchFor<T extends object>(local: T, shared: T) {\n const a = local as Item\n const b = shared as Item\n const patch: Item = {}\n for (const key of new Set([...Object.keys(a), ...Object.keys(b)])) {\n if (LOCAL_FIELDS.has(key)) continue\n if (!same(a[key], b[key])) patch[key] = b[key]\n }\n return Object.keys(patch).length ? (patch as Partial<T>) : null\n}\n\n/**\n * Gives every task an `order` key, so that siblings sort alike for\n * everyone. Siblings whose keys are already in order keep them.\n */\nfunction withOrder(tasks: GanttTask[]): GanttTask[] {\n const tree = buildTree(tasks)\n const keys = new Map<string, string>()\n for (const siblings of tree.childrenOf.values()) {\n const ordered = siblings.every(\n (task, i) =>\n task.order != null &&\n isOrderKey(task.order) &&\n (i === 0 || siblings[i - 1]!.order! < task.order),\n )\n if (ordered) continue\n const fresh = orderKeys(siblings.length)\n siblings.forEach((task, i) => keys.set(task.id, fresh[i]!))\n }\n return keys.size\n ? tasks.map((task) => (keys.has(task.id) ? { ...task, order: keys.get(task.id) } : task))\n : tasks\n}\n\n/**\n * Writes tasks and links into empty maps, e.g. when a plan that so far was\n * saved as JSON starts being edited together. Every task gets an `order`\n * key. Do it once, where the shared document is created.\n */\nexport function fillMaps(\n maps: { tasks: Y.Map<unknown>; links: Y.Map<unknown> },\n doc: GanttDocument,\n) {\n const fill = () => {\n for (const task of withOrder(doc.tasks)) write(maps.tasks, task)\n for (const link of doc.links) write(maps.links, link)\n }\n const ydoc = maps.tasks.doc\n if (ydoc) ydoc.transact(fill)\n else fill()\n}\n\n/** The tasks and links a transaction added, removed or changed. */\nfunction touched(steps: readonly GanttStep[]) {\n const tasks = new Set<string>()\n const links = new Set<string>()\n for (const step of steps) {\n if (step.type === 'addTask') tasks.add(step.task.id)\n else if (step.type === 'addLink') links.add(step.link.id)\n else if (step.type === 'removeTask' || step.type === 'updateTask') tasks.add(step.id)\n else links.add(step.id)\n }\n return { tasks, links }\n}\n\n/** Gives the tasks a transaction added without an `order` key one, where they sort now. */\nfunction orderAdded(tr: GanttTransaction) {\n for (const step of tr.steps.slice()) {\n if (step.type !== 'addTask') continue\n const task = tr.getTask(step.task.id)\n if (!task || task.order != null) continue\n const parent = task.parent != null && tr.getTask(task.parent) ? task.parent : undefined\n const siblings = buildTree(tr.doc.tasks).childrenOf.get(parent) ?? []\n tr.moveTask(\n task.id,\n parent,\n siblings.findIndex((item) => item.id === task.id),\n )\n }\n}\n\n/**\n * Edit a Gantt chart together through a Yjs document. The tasks and links\n * live in two `Y.Map`s: the chart's `v-model` only mirrors them, and\n * changes made to `v-model` from outside are not written back. Undo only\n * takes back this user's own changes. Folding a summary stays local.\n */\nexport function collaboration(options: CollaborationOptions): GanttExtension {\n const { tasks, links } = options\n const ydoc = tasks.doc\n if (!ydoc || links.doc !== ydoc)\n throw new Error('[@dou-ui/gantt] tasks and links must be maps of the same Y.Doc')\n const { awareness, user } = options\n if (awareness && user) {\n const color = user.color ?? collaborationColors[ydoc.clientID % collaborationColors.length]\n awareness.setLocalStateField('user', { name: user.name, color })\n }\n\n /** This chart's own changes, which undo can take back. */\n const tracked = { gantt: 'tracked' }\n /** Changes that undo leaves alone, e.g. filling the maps. */\n const untracked = { gantt: 'untracked' }\n const undoManager = new Y.UndoManager([tasks, links], {\n trackedOrigins: new Set([tracked]),\n captureTimeout: 500,\n })\n /** Set while shared changes are applied to the chart, so they aren't written back. */\n let applying = false\n /** What undo or redo is running, to name the change. */\n let travelling: 'undo' | 'redo' | null = null\n let lastGroup: string | undefined\n\n function writeChanges(tr: GanttTransaction) {\n const { tasks: taskIds, links: linkIds } = touched(tr.steps)\n const taskById = new Map(tr.doc.tasks.map((task) => [task.id, task]))\n const linkById = new Map(tr.doc.links.map((link) => [link.id, link]))\n const tracking = tr.meta.history !== false\n // like the chart's own history: only changes in one group undo together\n if (tracking && (!tr.meta.group || tr.meta.group !== lastGroup)) undoManager.stopCapturing()\n if (tracking) lastGroup = tr.meta.group\n ydoc!.transact(\n () => {\n for (const id of taskIds) {\n const task = taskById.get(id)\n if (task) write(tasks, task)\n else tasks.delete(id)\n }\n for (const id of linkIds) {\n const link = linkById.get(id)\n if (link) write(links, link)\n else links.delete(id)\n }\n },\n tracking ? tracked : untracked,\n )\n }\n\n /** Adds steps to `tr` that bring the given tasks and links in line with the maps. */\n function pull(tr: GanttTransaction, taskIds: Iterable<string>, linkIds: Iterable<string>) {\n for (const id of taskIds) {\n const shared = read<GanttTask>(tasks, id)\n const local = tr.getTask(id)\n if (!shared) {\n if (local) tr.step({ type: 'removeTask', id })\n } else if (!local) tr.step({ type: 'addTask', task: shared })\n else {\n const patch = patchFor(local, shared)\n if (patch) tr.step({ type: 'updateTask', id, patch })\n }\n }\n for (const id of linkIds) {\n const shared = read<GanttLink>(links, id)\n const local = tr.getLink(id)\n if (!shared) {\n if (local) tr.step({ type: 'removeLink', id })\n } else if (!local) tr.step({ type: 'addLink', link: shared })\n else {\n const patch = patchFor(local, shared)\n if (patch) tr.step({ type: 'updateLink', id, patch })\n }\n }\n }\n\n return defineGanttExtension({\n name: 'collaboration',\n // after the other extensions, so it writes what they added\n priority: 0,\n transaction(tr) {\n if (applying) return\n orderAdded(tr)\n writeChanges(tr)\n },\n history: () => ({\n undo: () => run('undo'),\n redo: () => run('redo'),\n canUndo: () => undoManager.undoStack.length > 0,\n canRedo: () => undoManager.redoStack.length > 0,\n }),\n layers: awareness ? { above: [createPeers(awareness)] } : undefined,\n setup(context) {\n const apply = (fn: (tr: GanttTransaction) => void, origin: string) => {\n applying = true\n try {\n context.transact(fn, { history: false, schedule: false, origin })\n } finally {\n applying = false\n }\n }\n const current = (): GanttDocument => ({\n version: 1,\n tasks: toRaw(context.tasks.value),\n links: toRaw(context.links.value),\n })\n\n // the first one to open the plan brings its tasks; everyone else reads the maps\n if (!tasks.size && !links.size)\n ydoc.transact(() => fillMaps({ tasks, links }, current()), untracked)\n const doc = current()\n apply(\n (tr) =>\n pull(\n tr,\n new Set([...doc.tasks.map((task) => task.id), ...tasks.keys()]),\n new Set([...doc.links.map((link) => link.id), ...links.keys()]),\n ),\n 'remote',\n )\n\n // changes from others, and from undo: gathered per Yjs transaction\n const pending = { tasks: new Set<string>(), links: new Set<string>() }\n const gather =\n (map: Shared, into: Set<string>) =>\n (events: Y.YEvent<Y.Map<unknown>>[], transaction: Y.Transaction) => {\n if (transaction.origin === tracked || transaction.origin === untracked) return\n for (const event of events) {\n if (event.target === map) for (const key of event.changes.keys.keys()) into.add(key)\n else if (event.path.length) into.add(String(event.path[0]))\n }\n }\n const onTasks = gather(tasks, pending.tasks)\n const onLinks = gather(links, pending.links)\n const flush = () => {\n if (!pending.tasks.size && !pending.links.size) return\n const taskIds = [...pending.tasks]\n const linkIds = [...pending.links]\n pending.tasks.clear()\n pending.links.clear()\n apply((tr) => pull(tr, taskIds, linkIds), travelling ?? 'remote')\n }\n tasks.observeDeep(onTasks)\n links.observeDeep(onLinks)\n ydoc.on('afterTransaction', flush)\n\n let stopPresence: (() => void) | undefined\n if (awareness) {\n // what this user is dragging and has selected, for the others to see\n stopPresence = watch(\n [context.preview, context.selection],\n ([preview, selection]) => {\n const moving: GanttPresence['moving'] = []\n for (const [id, patch] of preview ?? []) {\n if (moving.length >= 100) break\n moving.push({ id, start: patch.start, end: patch.end })\n }\n awareness.setLocalStateField('gantt', {\n moving,\n selection: selection.slice(0, 100),\n } satisfies GanttPresence)\n },\n { immediate: true },\n )\n }\n\n return () => {\n tasks.unobserveDeep(onTasks)\n links.unobserveDeep(onLinks)\n ydoc.off('afterTransaction', flush)\n stopPresence?.()\n awareness?.setLocalStateField('gantt', null)\n }\n },\n })\n\n function run(action: 'undo' | 'redo') {\n const stack = action === 'undo' ? undoManager.undoStack : undoManager.redoStack\n if (!stack.length) return false\n travelling = action\n try {\n undoManager[action]()\n } finally {\n travelling = null\n }\n return true\n }\n}\n\nexport type { AwarenessLike, GanttPresence }\n"],"mappings":";;;;;;;;;AAkCA,IAAM,+BAAe,IAAI,IAAI,CAAC,MAAM,WAAW,CAAC;AAEhD,IAAM,QAAQ,GAAY,MACxB,MAAM,KAAM,OAAO,MAAM,YAAY,KAAK,UAAU,CAAC,MAAM,KAAK,UAAU,CAAC;;AAG7E,SAAS,KAAQ,KAAa,IAAsB;CAClD,MAAM,SAAS,IAAI,IAAI,EAAE;CACzB,IAAI,EAAE,kBAAkB,EAAE,MAAM,OAAO;CACvC,OAAO;EAAE,GAAI,OAAO,OAAO;EAAY;CAAG;AAC5C;;AAGA,SAAS,WAAW,OAAgB,MAAc,uBAAO,IAAI,IAAY,GAAkB;CACzF,IAAI,UAAU,QAAQ;EAAC;EAAU;EAAU;EAAW;CAAW,CAAC,CAAC,SAAS,OAAO,KAAK,GACtF,OAAO;CACT,IAAI,OAAO,UAAU,UAAU,OAAO;CACtC,MAAM,QAAQ,OAAO,eAAe,KAAK;CACzC,IAAI,KAAK,IAAI,KAAK,GAAG,OAAO;CAC5B,IAAI,CAAC,MAAM,QAAQ,KAAK,KAAK,UAAU,OAAO,aAAa,UAAU,MAAM,OAAO;CAClF,KAAK,IAAI,KAAK;CACd,KAAK,MAAM,CAAC,KAAK,SAAS,OAAO,QAAQ,KAAK,GAAG;EAC/C,MAAM,QAAQ,WACZ,MACA,MAAM,QAAQ,KAAK,IAAI,GAAG,KAAK,GAAG,IAAI,KAAK,GAAG,KAAK,GAAG,OACtD,IACF;EACA,IAAI,OAAO,OAAO;CACpB;CACA,OAAO;AACT;AAMA,IAAM,yBAAS,IAAI,IAAY;AAC/B,SAAS,cAAc,IAAY,KAAa,OAAgB;CAE9D,IAAA,QAAA,IAAA,aAA6B,gBAAgB,OAAO,IAAI,GAAG,GAAG,GAAG,KAAK,GAAG;CACzE,MAAM,OAAO,WAAW,MAAM,KAAK,GAAG,GAAG;CAC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;EAC1B,aAAa;EACb,IAAI;GACF,YAAY,OAAO,CAAC;EACtB,UAAU;GACR,aAAa;EACf;EACA,OAAO;CACT;AACF"}
1
+ {"version":3,"file":"index.js","names":[],"sources":["../../src/collaboration/index.ts"],"sourcesContent":["import { collaborationColors } from 'dou-ui'\nimport { toRaw, watch } from 'vue'\nimport * as Y from 'yjs'\nimport { defineGanttExtension, type GanttExtension } from '../core/extension'\nimport type { GanttLink, GanttTask } from '../core/model'\nimport { isOrderKey, orderKeys } from '../core/order'\nimport type { GanttDocument, GanttStep, GanttTransaction } from '../core/transaction'\nimport { buildTree } from '../core/tree'\nimport { createPeers, type AwarenessLike, type GanttPresence } from './peers'\n\n/** How the people editing together see each other. */\nexport interface CollaborationUser {\n name: string\n /** The color of this user's outlines, any CSS color. Picked from the client id when left out. */\n color?: string\n}\n\nexport interface CollaborationOptions {\n /** Where the tasks live, e.g. `ydoc.getMap('tasks')`. */\n tasks: Y.Map<unknown>\n /** Where the links live, e.g. `ydoc.getMap('links')`; in the same `Y.Doc` as `tasks`. */\n links: Y.Map<unknown>\n /** Shares what each person selects and drags (`y-protocols/awareness`). */\n awareness?: AwarenessLike\n /** This user, shown to the others. Needs `awareness`. */\n user?: CollaborationUser\n}\n\nexport { collaborationColors }\n\ntype Shared = Y.Map<unknown>\ntype Item = Record<string, unknown>\n\n/** Folding is each person's own view: it stays out of the shared document. */\nconst LOCAL_FIELDS = new Set(['id', 'collapsed'])\n\nconst same = (a: unknown, b: unknown) =>\n a === b || (typeof a === 'object' && JSON.stringify(a) === JSON.stringify(b))\n\n/** A task or link as the map holds it, or `null` when it holds none. */\nfunction read<T>(map: Shared, id: string): T | null {\n const fields = map.get(id)\n if (!(fields instanceof Y.Map)) return null\n return { ...(fields.toJSON() as Item), id } as T\n}\n\n/** Where in `value` there is something JSON can't hold (a function, a component, a `Date`…), or `null`. */\nfunction unsharable(value: unknown, path: string, seen = new Set<object>()): string | null {\n if (value === null || ['string', 'number', 'boolean', 'undefined'].includes(typeof value))\n return null\n if (typeof value !== 'object') return path\n const proto = Object.getPrototypeOf(value)\n if (seen.has(value)) return path\n if (!Array.isArray(value) && proto !== Object.prototype && proto !== null) return path\n seen.add(value)\n for (const [key, item] of Object.entries(value)) {\n const found = unsharable(\n item,\n Array.isArray(value) ? `${path}[${key}]` : `${path}.${key}`,\n seen,\n )\n if (found) return found\n }\n return null\n}\n\n/*\n * Such a value reads back fine on this side, but the others get it without\n * the parts JSON can't hold: say so once per field while developing.\n */\nconst warned = new Set<string>()\nfunction checkSharable(id: string, key: string, value: unknown) {\n // the app's bundler replaces this, as for Vue's own warnings\n if (process.env.NODE_ENV === 'production' || warned.has(`${id}:${key}`)) return\n const path = unsharable(toRaw(value), key)\n if (!path) return\n warned.add(`${id}:${key}`)\n console.warn(\n `[@dou-ui/gantt] \"${id}\" has a value at ${path} that can't be shared: only JSON values reach the others. Keep components and functions out of the shared fields, for example by looking them up by name.`,\n )\n}\n\n/** Writes a task's or link's fields, only those that changed. */\nfunction write(map: Shared, value: GanttTask | GanttLink) {\n const item = value as unknown as Item\n const existing = map.get(value.id)\n let fields: Shared\n if (existing instanceof Y.Map) fields = existing\n // a new map joins the document first: it can't be read before\n else map.set(value.id, (fields = new Y.Map<unknown>()))\n for (const [key, field] of Object.entries(item)) {\n if (LOCAL_FIELDS.has(key) || field === undefined) continue\n checkSharable(value.id, key, field)\n if (!same(fields.get(key), field)) fields.set(key, field)\n }\n for (const key of Array.from(fields.keys()))\n if (!LOCAL_FIELDS.has(key) && item[key] === undefined) fields.delete(key)\n}\n\n/** The change that makes `local` match `shared`, keeping the local fields. */\nfunction patchFor<T extends object>(local: T, shared: T) {\n const a = local as Item\n const b = shared as Item\n const patch: Item = {}\n for (const key of new Set([...Object.keys(a), ...Object.keys(b)])) {\n if (LOCAL_FIELDS.has(key)) continue\n if (!same(a[key], b[key])) patch[key] = b[key]\n }\n return Object.keys(patch).length ? (patch as Partial<T>) : null\n}\n\n/**\n * Gives every task an `order` key, so that siblings sort alike for\n * everyone. Siblings whose keys are already in order keep them.\n */\nfunction withOrder(tasks: GanttTask[]): GanttTask[] {\n const tree = buildTree(tasks)\n const keys = new Map<string, string>()\n for (const siblings of tree.childrenOf.values()) {\n const ordered = siblings.every(\n (task, i) =>\n task.order != null &&\n isOrderKey(task.order) &&\n (i === 0 || siblings[i - 1]!.order! < task.order),\n )\n if (ordered) continue\n const fresh = orderKeys(siblings.length)\n siblings.forEach((task, i) => keys.set(task.id, fresh[i]!))\n }\n return keys.size\n ? tasks.map((task) => (keys.has(task.id) ? { ...task, order: keys.get(task.id) } : task))\n : tasks\n}\n\nexport interface FillMapsOptions {\n /** The origin of the Yjs transaction, so the others can tell who wrote it. */\n origin?: unknown\n}\n\n/**\n * Writes tasks and links into empty maps, e.g. when a plan that so far was\n * saved as JSON starts being edited together. Every task gets an `order`\n * key. Do it once, where the shared document is created.\n */\nexport function fillMaps(\n maps: { tasks: Y.Map<unknown>; links: Y.Map<unknown> },\n doc: GanttDocument,\n options: FillMapsOptions = {},\n) {\n const fill = () => {\n for (const task of withOrder(doc.tasks)) write(maps.tasks, task)\n for (const link of doc.links) write(maps.links, link)\n }\n const ydoc = maps.tasks.doc\n if (ydoc) ydoc.transact(fill, options.origin ?? null)\n else fill()\n}\n\n/** The tasks and links a transaction added, removed or changed. */\nfunction touched(steps: readonly GanttStep[]) {\n const tasks = new Set<string>()\n const links = new Set<string>()\n for (const step of steps) {\n if (step.type === 'addTask') tasks.add(step.task.id)\n else if (step.type === 'addLink') links.add(step.link.id)\n else if (step.type === 'removeTask' || step.type === 'updateTask') tasks.add(step.id)\n else links.add(step.id)\n }\n return { tasks, links }\n}\n\n/** Gives the tasks a transaction added without an `order` key one, where they sort now. */\nfunction orderAdded(tr: GanttTransaction) {\n for (const step of tr.steps.slice()) {\n if (step.type !== 'addTask') continue\n const task = tr.getTask(step.task.id)\n if (!task || task.order != null) continue\n const parent = task.parent != null && tr.getTask(task.parent) ? task.parent : undefined\n const siblings = buildTree(tr.doc.tasks).childrenOf.get(parent) ?? []\n tr.moveTask(\n task.id,\n parent,\n siblings.findIndex((item) => item.id === task.id),\n )\n }\n}\n\n/**\n * Edit a Gantt chart together through a Yjs document. The tasks and links\n * live in two `Y.Map`s: the chart's `v-model` only mirrors them, and\n * changes made to `v-model` from outside are not written back. Undo only\n * takes back this user's own changes. Folding a summary stays local.\n */\nexport function collaboration(options: CollaborationOptions): GanttExtension {\n const { tasks, links } = options\n const ydoc = tasks.doc\n if (!ydoc || links.doc !== ydoc)\n throw new Error('[@dou-ui/gantt] tasks and links must be maps of the same Y.Doc')\n const { awareness, user } = options\n if (awareness && user) {\n const color = user.color ?? collaborationColors[ydoc.clientID % collaborationColors.length]\n awareness.setLocalStateField('user', { name: user.name, color })\n }\n\n /** This chart's own changes, which undo can take back. */\n const tracked = { gantt: 'tracked' }\n /** Changes that undo leaves alone, e.g. filling the maps. */\n const untracked = { gantt: 'untracked' }\n const undoManager = new Y.UndoManager([tasks, links], {\n trackedOrigins: new Set([tracked]),\n captureTimeout: 500,\n })\n /** Set while shared changes are applied to the chart, so they aren't written back. */\n let applying = false\n /** What undo or redo is running, to name the change. */\n let travelling: 'undo' | 'redo' | null = null\n let lastGroup: string | undefined\n\n function writeChanges(tr: GanttTransaction) {\n const { tasks: taskIds, links: linkIds } = touched(tr.steps)\n const taskById = new Map(tr.doc.tasks.map((task) => [task.id, task]))\n const linkById = new Map(tr.doc.links.map((link) => [link.id, link]))\n const tracking = tr.meta.history !== false\n // like the chart's own history: only changes in one group undo together\n if (tracking && (!tr.meta.group || tr.meta.group !== lastGroup)) undoManager.stopCapturing()\n if (tracking) lastGroup = tr.meta.group\n ydoc!.transact(\n () => {\n for (const id of taskIds) {\n const task = taskById.get(id)\n if (task) write(tasks, task)\n else tasks.delete(id)\n }\n for (const id of linkIds) {\n const link = linkById.get(id)\n if (link) write(links, link)\n else links.delete(id)\n }\n },\n tracking ? tracked : untracked,\n )\n }\n\n /** Adds steps to `tr` that bring the given tasks and links in line with the maps. */\n function pull(tr: GanttTransaction, taskIds: Iterable<string>, linkIds: Iterable<string>) {\n for (const id of taskIds) {\n const shared = read<GanttTask>(tasks, id)\n const local = tr.getTask(id)\n if (!shared) {\n if (local) tr.step({ type: 'removeTask', id })\n } else if (!local) tr.step({ type: 'addTask', task: shared })\n else {\n const patch = patchFor(local, shared)\n if (patch) tr.step({ type: 'updateTask', id, patch })\n }\n }\n for (const id of linkIds) {\n const shared = read<GanttLink>(links, id)\n const local = tr.getLink(id)\n if (!shared) {\n if (local) tr.step({ type: 'removeLink', id })\n } else if (!local) tr.step({ type: 'addLink', link: shared })\n else {\n const patch = patchFor(local, shared)\n if (patch) tr.step({ type: 'updateLink', id, patch })\n }\n }\n }\n\n return defineGanttExtension({\n name: 'collaboration',\n // after the other extensions, so it writes what they added\n priority: 0,\n transaction(tr) {\n if (applying) return\n orderAdded(tr)\n writeChanges(tr)\n },\n history: () => ({\n undo: () => run('undo'),\n redo: () => run('redo'),\n canUndo: () => undoManager.undoStack.length > 0,\n canRedo: () => undoManager.redoStack.length > 0,\n }),\n layers: awareness ? { above: [createPeers(awareness)] } : undefined,\n setup(context) {\n const apply = (fn: (tr: GanttTransaction) => void, origin: string) => {\n applying = true\n try {\n context.transact(fn, { history: false, schedule: false, origin })\n } finally {\n applying = false\n }\n }\n const current = (): GanttDocument => ({\n version: 1,\n tasks: toRaw(context.tasks.value),\n links: toRaw(context.links.value),\n })\n\n // the first one to open the plan brings its tasks; everyone else reads the maps\n if (!tasks.size && !links.size)\n ydoc.transact(() => fillMaps({ tasks, links }, current()), untracked)\n const doc = current()\n apply(\n (tr) =>\n pull(\n tr,\n new Set([...doc.tasks.map((task) => task.id), ...tasks.keys()]),\n new Set([...doc.links.map((link) => link.id), ...links.keys()]),\n ),\n 'remote',\n )\n\n // changes from others, and from undo: gathered per Yjs transaction\n const pending = { tasks: new Set<string>(), links: new Set<string>() }\n const gather =\n (map: Shared, into: Set<string>) =>\n (events: Y.YEvent<Y.Map<unknown>>[], transaction: Y.Transaction) => {\n if (transaction.origin === tracked || transaction.origin === untracked) return\n for (const event of events) {\n if (event.target === map) for (const key of event.changes.keys.keys()) into.add(key)\n else if (event.path.length) into.add(String(event.path[0]))\n }\n }\n const onTasks = gather(tasks, pending.tasks)\n const onLinks = gather(links, pending.links)\n const flush = () => {\n if (!pending.tasks.size && !pending.links.size) return\n const taskIds = [...pending.tasks]\n const linkIds = [...pending.links]\n pending.tasks.clear()\n pending.links.clear()\n apply((tr) => pull(tr, taskIds, linkIds), travelling ?? 'remote')\n }\n tasks.observeDeep(onTasks)\n links.observeDeep(onLinks)\n ydoc.on('afterTransaction', flush)\n\n let stopPresence: (() => void) | undefined\n if (awareness) {\n // what this user is dragging and has selected, for the others to see\n stopPresence = watch(\n [context.preview, context.selection],\n ([preview, selection]) => {\n const moving: GanttPresence['moving'] = []\n for (const [id, patch] of preview ?? []) {\n if (moving.length >= 100) break\n moving.push({ id, start: patch.start, end: patch.end })\n }\n awareness.setLocalStateField('gantt', {\n moving,\n selection: selection.slice(0, 100),\n } satisfies GanttPresence)\n },\n { immediate: true },\n )\n }\n\n return () => {\n tasks.unobserveDeep(onTasks)\n links.unobserveDeep(onLinks)\n ydoc.off('afterTransaction', flush)\n stopPresence?.()\n awareness?.setLocalStateField('gantt', null)\n }\n },\n })\n\n function run(action: 'undo' | 'redo') {\n const stack = action === 'undo' ? undoManager.undoStack : undoManager.redoStack\n if (!stack.length) return false\n travelling = action\n try {\n undoManager[action]()\n } finally {\n travelling = null\n }\n return true\n }\n}\n\nexport type { AwarenessLike, GanttPresence }\n"],"mappings":";;;;;;;;;AAkCA,IAAM,+BAAe,IAAI,IAAI,CAAC,MAAM,WAAW,CAAC;AAEhD,IAAM,QAAQ,GAAY,MACxB,MAAM,KAAM,OAAO,MAAM,YAAY,KAAK,UAAU,CAAC,MAAM,KAAK,UAAU,CAAC;;AAG7E,SAAS,KAAQ,KAAa,IAAsB;CAClD,MAAM,SAAS,IAAI,IAAI,EAAE;CACz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AM,UAAU,CAAC,GAAG,QAAQ,KAAK;IACjC,MAAM,UAAU,CAAC,GAAG,QAAQ,KAAK;IACjC,QAAQ,MAAM,MAAM;IACpB,QAAQ,MAAM,MAAM;IACpB,OAAO,OAAO,KAAK,IAAI,SAAS,OAAO,GAAG,cAAc,QAAQ;GAClE;GACA,MAAM,YAAY,OAAO;GACzB,MAAM,YAAY,OAAO;GACzB,KAAK,GAAG,oBAAoB,KAAK;GAEjC,IAAI;GACJ,IAAI,WAEF,eAAe,MACb,CAAC,QAAQ,SAAS,QAAQ,SAAS,IAClC,CAAC,SAAS,eAAe;IACxB,MAAM,SAAkC,CAAC;IACzC,KAAK,MAAM,CAAC,IAAI,UAAU,WAAW,CAAC,GAAG;KACvC,IAAI,OAAO,UAAU,KAAK;KAC1B,OAAO,KAAK;MAAE;MAAI,OAAO,MAAM;MAAO,KAAK,MAAM;KAAI,CAAC;IACxD;IACA,UAAU,mBAAmB,SAAS;KACpC;KACA,WAAW,UAAU,MAAM,GAAG,GAAG;IACnC,CAAyB;GAC3B,GACA,EAAE,WAAW,KAAK,CACpB;GAGF,aAAa;IACX,MAAM,cAAc,OAAO;IAC3B,MAAM,cAAc,OAAO;IAC3B,KAAK,IAAI,oBAAoB,KAAK;IAClC,eAAe;IACf,WAAW,mBAAmB,SAAS,IAAI;GAC7C;EACF;CACF,CAAC;CAED,SAAS,IAAI,QAAyB;EAEpC,IAAI,EADU,WAAW,SAAS,YAAY,YAAY,YAAY,UAAA,CAC3D,QAAQ,OAAO;EAC1B,aAAa;EACb,IAAI;GACF,YAAY,OAAO,CAAC;EACtB,UAAU;GACR,aAAa;EACf;EACA,OAAO;CACT;AACF"}
@@ -20,6 +20,10 @@ export interface CollaborationOptions {
20
20
  user?: CollaborationUser;
21
21
  }
22
22
  export { collaborationColors };
23
+ export interface FillMapsOptions {
24
+ /** The origin of the Yjs transaction, so the others can tell who wrote it. */
25
+ origin?: unknown;
26
+ }
23
27
  /**
24
28
  * Writes tasks and links into empty maps, e.g. when a plan that so far was
25
29
  * saved as JSON starts being edited together. Every task gets an `order`
@@ -28,7 +32,7 @@ export { collaborationColors };
28
32
  export declare function fillMaps(maps: {
29
33
  tasks: Y.Map<unknown>;
30
34
  links: Y.Map<unknown>;
31
- }, doc: GanttDocument): void;
35
+ }, doc: GanttDocument, options?: FillMapsOptions): void;
32
36
  /**
33
37
  * Edit a Gantt chart together through a Yjs document. The tasks and links
34
38
  * live in two `Y.Map`s: the chart's `v-model` only mirrors them, and
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dou-ui/gantt",
3
- "version": "0.1.0-alpha.12",
3
+ "version": "0.1.0-alpha.13",
4
4
  "description": "DouUI 的甘特图:任务排期、依赖与工作日历",
5
5
  "keywords": [
6
6
  "vue",
@@ -59,7 +59,7 @@
59
59
  "build": "vite build && vue-tsc -p tsconfig.build.json && bun scripts/build-style.ts"
60
60
  },
61
61
  "peerDependencies": {
62
- "dou-ui": "0.1.0-alpha.12",
62
+ "dou-ui": "0.1.0-alpha.13",
63
63
  "vue": "^3.5.0",
64
64
  "yjs": "^13.6.0"
65
65
  },
@@ -69,7 +69,7 @@
69
69
  }
70
70
  },
71
71
  "dependencies": {
72
- "@dou-ui/icons": "0.1.0-alpha.12"
72
+ "@dou-ui/icons": "0.1.0-alpha.13"
73
73
  },
74
74
  "devDependencies": {
75
75
  "y-protocols": "^1.0.7",