日本語
コンポーザブル
Vue のエントリー(@eightkk/vue-weave)のコンポーザブルは、コアの純粋な状態を Vue の ref につなぎます。隠れたグローバルな状態は持たず、呼び出しごとに自分の状態を持ちます。コンポーネントには通常のプロップとして渡します。
| コンポーザブル | 用途 | リファレンス |
|---|---|---|
useLinkedSelection | 1 つのビューで選んだ項目に対応するものを、グラフ、タイムライン、負荷行、ツリーグリッドでハイライトする | Linked views |
useEditHistory | コンポーネントが表示する状態の「元に戻す」と「やり直す」 | 下記 |
useEditTransaction | 編集をサーバーのアダプター経由で保存し、保存中・失敗・競合の状態を扱う | 下記 |
useTimelineView | 元の行を変えずに GanttChart を検索、並べ替え、絞り込み、列の非表示にする | Typed fields and timeline views |
useWindowedData | 画面に見えている行と時間の範囲だけを、中断、重複排除、再試行付きで取得する | Partial data loading |
useAsyncGraphLayout | グラフのレイアウトを Worker や ELK.js で計算し、その間は仮のフレームを表示する | Asynchronous layouts |
最小の例
GanttChart の「元に戻す」と「やり直す」: 受け入れた編集ごとに commit し、state をチャートに渡します。
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()">元に戻す</button>
<button :disabled="!history.canRedo.value" @click="history.redo()">やり直す</button>
<GanttChart :rows="rows" :bars="history.state.value" :range="range" @edit="commit" />
</template>グラフとガントチャートの連動選択:
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" ... />例: 連動ビュー、ツリーグリッド。ガイド: データ、保存、連動ビュー。型: 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.
| Name | Meaning |
|---|---|
acceptedState, acceptedVersion | Last state and version the server accepted |
candidateState | State being saved, kept apart from the accepted state; undefined when not saving |
status | idle, saving, rejected, conflict or uncertain |
pendingTransaction | { operationId, kind, source, baseVersion } while saving or uncertain |
result | Last rejected, conflict or uncertain result until cleared |
canUndo, canRedo | Whether 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.