/** * This Source Code is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. * * Copyright (c) Infonomic Company Limited */ import { type RefObject } from 'react'; /** * A dirty-tracked, ref-backed form slot with its own listener set — the shared * machinery behind the document-grain system fields (`path`, advertised * `availableLocales`, …). Each slot holds the current value, the value it was * loaded with, and a set of subscribers; a `set` that moves the value away from * its loaded baseline registers the slot's `dirtyKey` in the form's shared * dirty set (and clears it again when the value returns to baseline), so the * single Save button can branch on which buckets changed. * * Adding a new system slot is then a one-liner at the call site rather than a * copy of ref + initial-ref + listener-set + get/set/subscribe. */ export interface TrackedSlot { /** Current value (live ref read — not React state). */ get: () => T; /** Write a value; toggles `dirtyKey` against the loaded baseline. */ set: (value: T) => void; /** Subscribe to value changes; returns an unsubscribe fn. */ subscribe: (listener: (value: T) => void) => () => void; /** Re-baseline: adopt the current value as the new "clean" baseline (called on save). */ commitInitial: () => void; } export interface UseTrackedSlotConfig { /** Initial / loaded value. */ initial: T; /** Key registered in the shared dirty set while this slot diverges from baseline. */ dirtyKey: string; /** The form's shared dirty-key set. */ dirtyFields: RefObject>; /** Notify the form's meta listeners (drives hasChanges → Save button). */ notifyMeta: () => void; /** Equality against the baseline. Defaults to `===` (identity). */ isEqual?: (a: T, b: T) => boolean; /** Defensive copy on read-in / write. Defaults to identity (fine for immutables). */ clone?: (value: T) => T; } export declare function useTrackedSlot(config: UseTrackedSlotConfig): TrackedSlot;