import { type ComplexAttributeConverter, type CSSResultGroup, html, nothing, type PropertyValues, } from 'lit'; import { property, state } from 'lit/decorators.js'; import { ifDefined } from 'lit/directives/if-defined.js'; import type { ChromeString } from '../i18n/chrome-strings.js'; import { RoxyLocalizedElement } from '../i18n/localized-element.js'; import { baseStyles } from './base-styles.js'; import { buildRequest, FetchController } from './fetch-controller.js'; import { type InterpSection, renderInterpAccordion, } from './interp-accordion.js'; import { MarkupDataController } from './markup-data.js'; /** * Read the `submit-context` attribute into the object a proxied submit carries. * * @remarks * Hand-written rather than `type: Object`, which resolves malformed JSON to `null` in silence: a page whose context never left has nothing to look at, and the route it was meant for reports only that the value it expected is not there. One warning covers both refusals (unparseable, or parsed to something that is not an object) because both leave the request without a context, which is the fact worth reading. */ const submitContextConverter: ComplexAttributeConverter< Record | undefined > = { fromAttribute: (value) => { if (value == null) return undefined; try { const parsed: unknown = JSON.parse(value); if (parsed && typeof parsed === 'object' && !Array.isArray(parsed)) { return parsed as Record; } } catch { // Both refusals share the warning below. } console.warn( '[roxy-ui] submit-context must be a JSON object; sending the request without it.', ); return undefined; }, }; /** * Shared base for every data-driven Roxy component. Consolidates the things every component used to repeat by hand and adds the self-contained, drop-in behavior: controlled-mode hydration, an opt-in self-fetch (form, request, loading, error, empty), the typed `data` slot, and the render switch. A subclass implements one method, {@link RoxyDataElement.renderData}. * * @remarks * Two render modes, one component, which is the whole drop-in contract: * * - Controlled: a server (WordPress, JSX SSR, static HTML) fetches the response and injects it as a direct-child `