Skip to content

Composables ​

The composables of the Vue entry (@eightkk/vue-weave) wire the pure state of the core to Vue refs. They hold no hidden global state: each call owns its state, and the components still receive plain props.

ComposableUse it toReference
useLinkedSelectionSelect an item in one view and highlight its counterparts in the graph, timeline, load rows and tree gridLinked views
useEditHistoryKeep undo and redo for the state your components showbelow
useEditTransactionSave each edit through your server adapter, with pending, failed and conflict statesbelow
useTimelineViewSearch, sort, filter and hide columns of a GanttChart without changing the source rowsTyped fields and timeline views
useWindowedDataFetch only the rows and time window on screen, with aborts, deduplication and retryPartial data loading
useAsyncGraphLayoutRun a graph layout in a Worker or through ELK.js and show provisional frames meanwhileAsynchronous layouts

Minimal example ​

Undo and redo for a GanttChart: commit each accepted edit, and bind state to the chart.

vue
<script setup lang="ts">
import { GanttChart, useEditHistory, type TimelineBar, type TimelineEdit } from '@eightkk/vue-weave'

const props = defineProps<{ initialBars: TimelineBar[]; rows: { id: string; label: string }[]; range: { start: number; end: number } }>()
const history = useEditHistory(props.initialBars)

function commit(change: TimelineEdit) {
  history.commit(history.state.value.map(bar => bar.id === change.id ? { ...bar, ...change.after } : bar))
}
</script>

<template>
  <button :disabled="!history.canUndo.value" @click="history.undo()">Undo</button>
  <button :disabled="!history.canRedo.value" @click="history.redo()">Redo</button>
  <GanttChart :rows="rows" :bars="history.state.value" :range="range" @edit="commit" />
</template>

Linked selection between a graph and a Gantt chart:

ts
import { useLinkedSelection, type ViewBinding, type ViewTargetEvent } from '@eightkk/vue-weave'

const bindings: ViewBinding[] = bars.flatMap(bar => [
  { entity: { kind: 'task', id: bar.id }, target: { view: 'graph', kind: 'node', id: bar.id } },
  { entity: { kind: 'task', id: bar.id }, target: { view: 'timeline', kind: 'bar', id: bar.id } },
])
const linked = useLinkedSelection({ bindings })
const activate = (event: ViewTargetEvent) => linked.select(event.target.view, [event.target])
// <NetworkGraph :selected-ids="linked.graph.value.selectedNodeIds" @target-activate="activate" ... />

Examples: Linked views, Tree grid. Guide: Data, saving and linked views. Types: useEditHistory, useEditTransaction, useLinkedSelection, useTimelineView, useWindowedData, useAsyncGraphLayout.

Application undo and redo ​

Import useEditHistory(initial, limit = 100) from the Vue entry point. It returns state, canUndo, canRedo, commit, undo, redo and reset. The limit is the maximum number of undo steps and must be a positive integer; invalid limits throw RangeError.

Pass a complete immutable snapshot to commit after accepting an edit. Snapshots are stored by reference, without cloning or freezing; do not mutate them after committing. Committing the current snapshot reference does nothing. A batch move or endpoint replacement can be one history entry. Committing after an undo discards the redo branch. undo and redo do nothing when unavailable; reset(snapshot) replaces the history and clears both branches. Persist accepted changes through the application storage layer.

Edit transactions and asynchronous saving ​

useEditTransaction(options) (Vue entry) confirms edits with a server before committing them. Types and pure state transitions (EditTransaction, SaveResult, TransactionOutcome, TransactionAdapter, createTransactionState, beginTransaction, settleTransaction, refreshTransactionState, clearTransactionResult) are exported from @eightkk/vue-weave/core.

Options: documentId, initialState, initialVersion, adapter, optional createOperationId() (defaults to crypto.randomUUID()), historyLimit (default 100) and onHistoryReset(reset). The adapter provides synchronous validate(state, changes) (return false or a reason string to reject), synchronous apply(state, changes) returning a new state, and save(request, candidate) returning Promise<SaveResult>. Versions are opaque and compared for equality only.

A request is { operationId, documentId, baseVersion, source, kind: 'changes', changes } or { ..., kind: 'restore', snapshot }. SaveResult is accepted (with the server's normalised state and new version), rejected (code), conflict (currentVersion) or uncertain. A save that throws or rejects is treated as uncertain.

NameMeaning
acceptedState, acceptedVersionLast state and version the server accepted
candidateStateState being saved, kept apart from the accepted state; undefined when not saving
statusidle, saving, rejected, conflict or uncertain
pendingTransaction{ operationId, kind, source, baseVersion } while saving or uncertain
resultLast rejected, conflict or uncertain result until cleared
canUndo, canRedoWhether history has a previous or next snapshot
submit(changes, { source }?)Validate, apply and save. Resolves to a TransactionOutcome
undo(), redo()Save the previous or next history snapshot as a restore transaction against the current acceptedVersion
refresh(state, version)Replace the accepted state, reset history and discard in-flight responses
historyReset{ reason: 'refresh', version } for the last reset, or undefined
reconcile(result)Settle an uncertain operation using a result fetched from the server
clearResult()Dismiss a rejected, conflict or uncertain result; the accepted input is unchanged

Outcomes add busy (another save for the document is in flight), invalid (failed synchronous validation, empty changes, nothing to undo or redo, or a validate, apply or createOperationId that throws, with the error message as reason; submit, undo and redo never throw and save nothing then) and discarded (a response that no longer matches the current operation or epoch, for example one that arrives after refresh). There is no validating status because validation is synchronous.

Only an accepted response changes anything. It replaces the accepted state with the server's state and records one history entry; a repeated accepted response for the same operation is ignored. For undo and redo the history position moves only after acceptance, and the entry is replaced by the server-normalised state; the server version is never rolled back and the remaining redo entries stay valid. A rejected, conflicting or uncertain save leaves the accepted state, version and history position unchanged, and a new accepted edit discards the redo branch. An uncertain save is never resent automatically; call reconcile or refresh. Blocking further saves until then is the application's job: while status is uncertain, submit, undo and redo still start a new save, which replaces the unknown operation in pendingTransaction (so it can no longer be reconciled) and is based on the accepted version from before it, so it ends as a conflict if the unknown save was applied. Disable saving, undo and redo while status is saving or uncertain, as the production demo does. Because restores send a whole snapshot, large documents send more data than a diff; an adapter may transmit a diff inside save, but acceptance is of the whole snapshot.

useEditHistory additionally returns peekUndo(), peekRedo() (the adjacent snapshot or undefined, position unchanged) and replaceCurrent(snapshot) (replace the current entry, keeping the others).

The server must apply each save as a conditional update on baseVersion, deduplicate by operationId, and commit all affected records atomically. See integration.

Related exported types: TransactionSource, TransactionStatus, TransactionCoreState, PendingTransaction, TransactionFailure, SettleResult, UseEditTransactionOptions, HistoryReset.

Released under the MIT License.