import { Property, Store, Resource, JSONValue, FetchOpts, JSONArray, OptionalClass } from '@tomic/lib'; /** * Hook for getting a Resource in a React component. Will try to fetch the * subject and add its parsed values to the store. */ export declare function useResource(subject?: string, opts?: FetchOpts): Resource; /** * Converts an array of Atomic URL strings to an array of Resources. * !! Make sure the array is stable by memoizing it !! */ export declare function useResources(subjects?: string[] | undefined, opts?: FetchOpts): Map; /** * Hook for using a Property. Will return `undefined` if the Property is not yet * loaded, and add Error strings to shortname and description if something goes wrong. */ export declare function useProperty(subject: string): Property; export type SetValue = (val: T | undefined) => Promise; /** Extra options for useValue hooks, mostly related to commits and validation */ type useValueOptions = { /** * Sends a Commit to the server when the value is changed. Disabled by * default. If this is false, you will need to manually call Resource.save() * to save changes */ commit?: boolean; /** * Performs datatype validation. Enabled by default, but this could cause some * slowdown when the first validation is done as the Property needs to be * present in the store, and might have to be fetched */ validate?: boolean; /** Amount of milliseconds to wait (debounce) before applying Commit. Defaults to 100. */ commitDebounce?: number; /** * A callback function that will be called when the validation fails. For * example, pass a `setError` function. If you want to remove the Error, return `undefined`. */ handleValidationError?: (e: Error | undefined) => unknown; }; /** * Similar to React's `useState` hook. Returns a Value and a Setter as an array * of two items. Value will be `undefined` if the Resource isn't loaded yet. The * generated Setter function can be called to set the value. Be sure to look at * the various options for useValueOptions (debounce, commits, error handling). * * ```typescript * // Simple usage: * const resource = useResource('https://atomicdata.dev/classes/Agent'); * const [shortname, setShortname] = useValue( * resource, * 'https://atomicdata.dev/properties/shortname', * ); * ``` * * ```typescript * // With options: * const resource = useResource('https://atomicdata.dev/classes/Agent'); * const [error, setError] = useState(null); * const [shortname, setShortname] = useValue( * resource, * 'https://atomicdata.dev/properties/shortname', * { * commit: true, * validate: true, * commitDebounce: 500, * handleValidationError: setError, * }, * ); * ``` */ export declare function useValue(resource: Resource, propertyURL: string, opts?: useValueOptions): [JSONValue | undefined, SetValue]; /** * Hook for getting and setting a stringified representation of an Atom in a * React component. See {@link useValue} */ export declare function useString(resource: Resource, propertyURL: string, opts?: useValueOptions): [string | undefined, SetValue]; export declare const noNestedSupport = "error:no_support_for_editing_nested_resources_yet"; /** * Hook for getting and setting a Subject. Converts Nested resources into paths. * See {@link useValue} for more info on using the `set` functionality. */ export declare function useSubject(resource: Resource, propertyURL: string, opts?: useValueOptions): [string | undefined, SetValue]; /** * Returns the most fitting title / name for a Resource. This is either the * Name, Shortname, Filename or truncated Subject URL of that resource. */ export declare function useTitle(resource: Resource, truncateLength?: number, opts?: useValueOptions): [string, SetValue]; /** * Hook for getting all URLs for some array. Returns the current Array (defaults * to empty array) and a callback for validation errors. See {@link useValue} */ export declare function useArray(resource: Resource, propertyURL: string, opts?: useValueOptions): [string[], SetValue, (vals: string[]) => void]; /** See {@link useValue} */ export declare function useNumber(resource: Resource, propertyURL: string, opts?: useValueOptions): [number | undefined, SetValue]; /** Returns false if there is no value for this propertyURL. See {@link useValue} */ export declare function useBoolean(resource: Resource, propertyURL: string, opts?: useValueOptions): [boolean, SetValue]; /** * Hook for getting a stringified representation of an Atom in a React * component. See {@link useValue} */ export declare function useDate(resource: Resource, propertyURL: string, opts?: useValueOptions): Date | undefined; /** Preferred way of using the store in a Component or Hook */ export declare function useStore(): Store; /** * Checks if the Agent has the appropriate rights to edit this resource. If you * don't explicitly pass an Agent URL, it will select the current Agent set by the store. */ export declare function useCanWrite(resource: Resource, agent?: string): [canWrite: boolean, message: string | undefined]; /** * The context must be provided by wrapping a high level React element in * `My App` */ export declare const StoreContext: import("react").Context; export {}; //# sourceMappingURL=hooks.d.ts.map