/// import { ComputedElementProperties, HALJSONResource, NucleonV8N } from './types'; import { LitElement, PropertyDeclarations, TemplateResult } from 'lit-element'; import { Nucleon, Rumour } from '@foxy.io/sdk/core'; import { API } from './API'; import { UpdateEvent } from './UpdateEvent'; declare const NucleonElement_base: typeof LitElement & import("lit-element").Constructor & { inferredProperties: string[]; }; /** * Base class for custom elements working with remote HAL+JSON resources. * * @fires NucleonElement#update - Instance of `NucleonElement.UpdateEvent`. Dispatched on an element whenever it changes its state. * @fires NucleonElement#fetch - Instance of `NucleonElement.API.FetchEvent`. Emitted before each API request. * * @element foxy-nucleon * @since 1.1.0 */ export declare class NucleonElement extends NucleonElement_base { /** * Instances of this event are dispatched on an element whenever it changes its * state (e.g. when going from `busy` to `idle` or on `form` data change). * This event isn't cancelable, and it does not bubble. * @readonly */ static readonly UpdateEvent: typeof UpdateEvent; /** * Creates a tagged [Rumour](https://sdk.foxy.dev/classes/_core_index_.rumour.html) * instance if it doesn't exist or returns cached one otherwise. NucleonElements * use empty Rumour group by default. * @readonly */ static readonly Rumour: ((group: string) => Rumour) & import("lodash").MemoizedFunction; /** * Universal [API](https://sdk.foxy.dev/classes/_core_index_.api.html) client * that dispatches cancellable `FetchEvent` on an element before each request. * @readonly */ static readonly API: typeof API; static get inferredProperties(): string[]; /** @readonly */ static get properties(): PropertyDeclarations; /** * Array of validation functions. Each function accepts `element.form` and must return * either an error code string if form data fails the check or `true` otherwise. * Error codes are collected in `element.errors`. Empty by default. */ static get v8n(): NucleonV8N; /** * Optional ISO 639-1 code describing the language element content is written in. * Changing the `lang` attribute will update the value of this property. */ lang: string; /** * Optional URL of the collection this element's resource belongs to. * Changing the `parent` attribute will update the value of this property. */ parent: string; /** * Optional URI list of the related resources. If Rumour encounters a related * resource on creation or deletion, it will be reloaded from source. */ related: string[]; /** * Unique identifier for the virtual host used by the element to serve internal requests. * * Currently only one endpoint is supported: `foxy:///form/`. * This endpoint supports POST, GET, PATCH and DELETE methods and functions like a hAPI server. * * For example, `GET foxy://nucleon-123/form/subscriptions/allowNextDateModification/0` on a NucleonElement * with `fx:customer_portal_settings` will return the first item of the `subscriptions.allowNextDateModification` array. */ virtualHost: string | null; private __group; private __href; private __accessDeniedFor; private __unsubscribeFromRumour; private __fetchEventHandler; private __fetchEventQueue; private readonly __service; constructor(); /** * If network request returns non-2XX code, the entire error response * will be available via this getter. * * This property is readonly. Changing failure records via this property is * not guaranteed to work. NucleonElement does not provide a way to override error status. * * @since 1.4.0 */ get failure(): Response | null; /** * `true` if the last request failed because the token lacks the scope required * for the resource. Elements use this to render a specific "Access denied" * message instead of the generic error. * * This property is readonly. It tracks `.failure` and clears with it. */ get accessDenied(): boolean; /** * Array of validation errors returned from `NucleonElement.v8n` checks. * * This property is readonly. Adding or removing error codes via this property is * not guaranteed to work. NucleonElement does not provide a way to override validity status. */ get errors(): string[]; /** * Resource snapshot with edits applied. Empty object if unavailable. * * This property and its value are readonly. Assignments like `element.data.foo = 'bar'` * are not guaranteed to work. Please use `element.edit({ foo: 'bar' })` instead. * If you need to replace the entire data object, consider using `element.data`. */ get form(): Partial; /** * Resource snapshot as-is, no edits applied. Null if unavailable. * * Returned value is not reactive. Assignments like `element.data.foo = 'bar'` * are not guaranteed to work. Please set the property instead: `element.data = { ...element.data, foo: 'bar' }`. * If you're processing user input, consider using `element.form` and `element.edit()` instead. */ get data(): TData | null; set data(data: TData | null); /** * Rumour group. Elements in different groups will not share updates. Empty by default. * @example element.group = 'my-group' */ get group(): string; set group(value: string); /** * Optional URL of the resource to load. Switches element to `idle.template` state if empty (default). * @example element.href = 'https://demo.foxycart.com/s/customer/attributes/0' */ get href(): string; set href(value: string); /** * Checks if this element is in the given state. * @example element.in({ idle: 'snapshot' }) */ in['value']>(stateValue: TStateValue): this is this & ComputedElementProperties; /** * Clears all edits and emits the `update` event. * @example element.undo() */ undo(): void; /** * Applies an edit to the local resource snapshot or its template and emits the `update` event. * @example element.edit({ first_name: 'Alex' }) */ edit(data: Partial): void; /** * Submits the form, updating the resource if href isn't empty or creating it otherwise. * Emits multiple `update` events as element state changes. Has no effect on invalid forms. * @example element.submit() */ submit(reportValidity?: boolean): void; checkValidity(): boolean; reportValidity(): boolean; /** * Sends a DELETE request to `element.href` and clears local data on success. * Emits multiple update events as element state changes. * @example element.delete() */ delete(): void; /** * Fetches data from `element.href` in background, keeping the edits and v8n errors. * @example element.refresh() */ refresh(): void; render(): TemplateResult; /** @readonly */ connectedCallback(): void; /** @readonly */ disconnectedCallback(): void; applyInferredProperties(context: Map): void; /** Sends API request. Throws an error on non-2XX response. */ protected _fetch(...args: Parameters): Promise; protected _sendPost(edits: Partial, options?: { mode: 'collection' | 'action'; }): Promise; /** GETs `element.href`, shares response with the Rumour group and returns parsed JSON. */ protected _sendGet(): Promise; /** PATCHes `element.href`, shares response with the Rumour group and returns parsed JSON. */ protected _sendPatch(edits: Partial): Promise; /** DELETEs `element.href`, shares response with the Rumour group and returns parsed JSON. */ protected _sendDelete(): Promise; private get __state(); private __createService; private __createRumour; private __destroyRumour; private __createServer; private __destroyServer; private __handleRumourUpdate; private __processFetchEventQueue; private __flushFetchEventQueue; private __handleFetchEvent; } export {};