@descope/web-component 4.1.0 → 4.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +14 -0
- package/dist/cjs/descope-wc/BaseDescopeWc.js +1 -1
- package/dist/cjs/descope-wc/BaseDescopeWc.js.map +1 -1
- package/dist/cjs/descope-wc/DescopeWc.js +1 -1
- package/dist/cjs/descope-wc/DescopeWc.js.map +1 -1
- package/dist/cjs/mixins/componentConditionsMixin.js.map +1 -1
- package/dist/esm/descope-wc/BaseDescopeWc.js +1 -1
- package/dist/esm/descope-wc/BaseDescopeWc.js.map +1 -1
- package/dist/esm/descope-wc/DescopeWc.js +1 -1
- package/dist/esm/descope-wc/DescopeWc.js.map +1 -1
- package/dist/esm/mixins/componentConditionsMixin.js.map +1 -1
- package/dist/index.d.ts +706 -280
- package/dist/index.js +2 -2
- package/package.json +3 -3
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"componentConditionsMixin.js","sources":["../../../src/lib/mixins/componentConditionsMixin.ts"],"sourcesContent":["/* eslint-disable import/prefer-default-export, no-param-reassign */\nimport { compose, createSingletonMixin } from '@descope/sdk-helpers';\nimport { loggerMixin } from '@descope/sdk-mixins';\nimport {\n REALTIME_CONDITION_DEBOUNCE_MS,\n REALTIME_CONDITION_EVENTS,\n} from '../helpers/realtime-conditions/config';\nimport {\n collectReferencedFormKeys,\n collectTouchedComponentIds,\n evaluateAll,\n FormSnapshot,\n} from '../helpers/realtime-conditions/evaluator';\nimport {\n apply,\n COMPONENT_ACTIONS,\n escapeSelector,\n} from '../helpers/realtime-conditions/applier';\nimport { DESCOPE_ATTRIBUTE_EXCLUDE_FIELD } from '../constants';\nimport type { RealtimeComponentsCondition, ScreenState } from '../types';\n\nconst LOG_PREFIX = 'component-conditions:';\n\n// What the mixin needs from its host: a way to subscribe to loading state\n// so input handling can pause while the next request is in flight. Defined\n// as an interface (not imported) to avoid a circular dependency on BaseDescopeWc.\nexport interface PausableHost {\n nextRequestStatus?: {\n // subscribe returns a token; pass that token to unsubscribe — not the handler.\n subscribe: (cb: (v: { isLoading: boolean }) => void) => string;\n unsubscribe?: (token: string) => void;\n };\n}\n\nexport interface RealtimeRuntime {\n conditions: RealtimeComponentsCondition[];\n // IDs of components that any rule can change\n touchedIds: Set<string>;\n // latest form values on screen\n snapshot: FormSnapshot;\n // what's currently applied on screen for touched components.\n // Compared against on each re-evaluation to know what to change.\n applied: Record<string, string>;\n // What the server told us to apply for these components. Stays fixed for\n // the screen's lifetime so we can fall back to it when a real-time rule\n // stops matching. Without this, a server-set action could disappear when\n // a real-time rule briefly fires on the same component.\n serverBaseline: Record<string, string>;\n debounceTimer: ReturnType<typeof setTimeout> | null;\n // true while paused (during submit, to avoid stale updates)\n paused: boolean;\n unsubscribePauseListener: (() => void) | null;\n // the listener we attach to form events (kept so we can detach)\n inputHandler: (e: Event) => void;\n // the screen root we work against\n root: HTMLElement | null;\n}\n\n// Some inputs already have `name=\"form.x\"`, others use `name=\"x\"`. Always\n// return the `form.x` form so it lines up with what rules reference.\nfunction toFormKey(name: string): string {\n return name.startsWith('form.') ? name : `form.${name}`;\n}\n\n// Try the full `form.x` first (descope components), then `x` (plain inputs).\nfunction findInputForFormKey(\n root: ParentNode,\n formKey: string,\n): Element | null {\n const bare = formKey.startsWith('form.')\n ? formKey.slice('form.'.length)\n : formKey;\n return (\n root.querySelector(`[name=\"${escapeSelector(formKey)}\"]`) ||\n root.querySelector(`[name=\"${escapeSelector(bare)}\"]`)\n );\n}\n\n// Read the current value off a form input. Reads JS properties (not HTML\n// attributes) so we pick up both the component's default and any value\n// carried over from earlier screens.\n//\n// Native <input type=checkbox> needs special handling: `.value` is always\n// \"on\", only `.checked` reflects the real state. Descope boolean components\n// (descope-checkbox, descope-switch-toggle) expose `.checked` on their class.\nfunction readInputValue(el: Element): unknown {\n if (el instanceof HTMLInputElement) {\n return el.type === 'checkbox' ? el.checked : el.value;\n }\n if ('checked' in el) {\n return (el as unknown as { checked: boolean }).checked;\n }\n if ('value' in el) {\n return (el as unknown as { value: unknown }).value;\n }\n return undefined;\n}\n\nfunction shallowEqualStringMap(\n a: Record<string, string>,\n b: Record<string, string>,\n): boolean {\n const keysA = Object.keys(a);\n const keysB = Object.keys(b);\n if (keysA.length !== keysB.length) return false;\n return keysA.every((k) => a[k] === b[k]);\n}\n\nfunction emptyRuntime(): RealtimeRuntime {\n return {\n conditions: [],\n touchedIds: new Set(),\n snapshot: {},\n applied: {},\n serverBaseline: {},\n debounceTimer: null,\n paused: false,\n unsubscribePauseListener: null,\n inputHandler: () => {},\n root: null,\n };\n}\n\n// For each touched component, pick the real-time action if a rule is firing\n// for it, otherwise fall back to the server's action. Components that no rule\n// touches are not in the result — those were already painted by\n// applyComponentsState.\nfunction effectiveActions(\n realtimeVerdict: Record<string, string>,\n serverBaseline: Record<string, string>,\n touchedIds: Set<string>,\n): Record<string, string> {\n const out: Record<string, string> = {};\n touchedIds.forEach((id) => {\n if (realtimeVerdict[id]) {\n out[id] = realtimeVerdict[id];\n } else if (serverBaseline[id]) {\n out[id] = serverBaseline[id];\n }\n });\n return out;\n}\n\nexport const componentConditionsMixin = createSingletonMixin(\n <T extends CustomElementConstructor>(superclass: T) => {\n // Pull in loggerMixin so `this.logger` is available no matter where\n // this mixin sits in the chain.\n const BaseClass = compose(loggerMixin)(superclass);\n\n return class ComponentConditionsMixin extends BaseClass {\n // One runtime per <descope-wc> element.\n #rtRuntime: RealtimeRuntime = emptyRuntime();\n\n /**\n * Apply the server's hide/disable/read-only actions to the DOM.\n * Logs unknown actions here (runs once per screen) but stays quiet on\n * the keystroke path to avoid log spam.\n */\n applyComponentsState(\n root: ParentNode,\n componentsState: Record<string, string> | undefined,\n ): void {\n if (!componentsState) return;\n Object.entries(componentsState).forEach(([id, action]) => {\n if (!(COMPONENT_ACTIONS as readonly string[]).includes(action)) {\n this.logger.error(\n `Unknown component action \"${action}\" for component with id \"${id}\"`,\n `Valid actions are ${COMPONENT_ACTIONS.map((a) => `\"${a}\"`).join(\n ', ',\n )}`,\n );\n }\n });\n apply(root, {}, componentsState);\n }\n\n /**\n * Set up real-time conditions for the current screen. Safe to call\n * twice — a second call rebuilds from screenState.\n *\n * Must run AFTER `updateScreenFromScreenState`, so the DOM reads below\n * see both server-shipped values and any component defaults from the\n * HTML.\n */\n initRealtimeConditions(\n rootElement: HTMLElement,\n screenState: ScreenState | undefined,\n ): void {\n this.#teardownRealtimeRuntime();\n\n const conditions = screenState?.realtimeComponentsConditions ?? [];\n if (!conditions.length) {\n this.logger.debug(\n `${LOG_PREFIX} no real-time rules to apply on this screen`,\n );\n return;\n }\n this.logger.info(\n `${LOG_PREFIX} found ${conditions.length} real-time rule(s) for this screen`,\n );\n\n // screenState.form uses \"phone\"; rules reference \"form.phone\".\n // Add the prefix on the way in.\n const initialSnapshot: FormSnapshot = {};\n Object.entries(screenState?.form ?? {}).forEach(([k, v]) => {\n initialSnapshot[`form.${k}`] = v;\n });\n\n // For every key the rules reference, read the current DOM value.\n // Component defaults (e.g. `checked=\"true\"` on a descope-checkbox)\n // live only in the HTML and don't make it into screenState.form, so\n // without this read the first evaluation would miss them.\n collectReferencedFormKeys(conditions).forEach((formKey) => {\n const el = findInputForFormKey(rootElement, formKey);\n if (!el) return;\n const v = readInputValue(el);\n if (v !== undefined) initialSnapshot[formKey] = v;\n });\n\n const touchedIds = collectTouchedComponentIds(conditions);\n\n // What to fall back to when a real-time rule stops matching for a\n // touched component — the actions set by server-only rules (rules\n // with no client-side conditions).\n const serverBaseline: Record<string, string> = {};\n // What's already painted on the DOM (touched components only), so\n // the first real-time evaluation can diff against the right state.\n const initialApplied: Record<string, string> = {};\n\n Object.entries(screenState?.componentsState ?? {}).forEach(\n ([id, action]) => {\n if (!touchedIds.has(id)) return;\n initialApplied[id] = action;\n },\n );\n\n Object.entries(screenState?.serverOnlyComponentsState ?? {}).forEach(\n ([id, action]) => {\n if (touchedIds.has(id)) {\n serverBaseline[id] = action;\n }\n },\n );\n\n const runtime: RealtimeRuntime = {\n conditions,\n touchedIds,\n snapshot: initialSnapshot,\n applied: initialApplied,\n serverBaseline,\n debounceTimer: null,\n paused: false,\n unsubscribePauseListener: null,\n inputHandler: () => {},\n root: rootElement,\n };\n\n // Re-run the rules now that we've read the real DOM values. The\n // server evaluated without seeing component defaults, so its\n // `componentsState` can disagree with what the user actually sees.\n // Apply the diff once before listening for input.\n const reconciled = effectiveActions(\n evaluateAll(conditions, initialSnapshot),\n serverBaseline,\n touchedIds,\n );\n if (!shallowEqualStringMap(initialApplied, reconciled)) {\n runtime.applied = apply(rootElement, initialApplied, reconciled);\n }\n\n runtime.inputHandler = (e: Event) =>\n this.#handleRealtimeInput(e as InputEvent);\n\n REALTIME_CONDITION_EVENTS.forEach((ev) => {\n rootElement.addEventListener(ev, runtime.inputHandler, true);\n });\n this.logger.debug(\n `${LOG_PREFIX} listening for \"${REALTIME_CONDITION_EVENTS.join(\n '\" and \"',\n )}\" events on form fields; ${\n Object.keys(initialApplied).length\n } component(s) start hidden / disabled / read-only by these rules`,\n );\n\n // Pause while a /next request is in flight. Without this, a debounced\n // evaluation could run between submit and the next screen render and\n // change components that are about to be replaced — causing flicker,\n // or hiding something the next screen needs visible.\n const pauseState = (this as unknown as PausableHost).nextRequestStatus;\n if (pauseState?.subscribe) {\n const handler = ({ isLoading }: { isLoading: boolean }) => {\n runtime.paused = isLoading;\n if (isLoading && runtime.debounceTimer) {\n clearTimeout(runtime.debounceTimer);\n runtime.debounceTimer = null;\n }\n };\n // subscribe returns a token; unsubscribe needs that token, not the\n // handler. Without storing it, handlers leak across screens and\n // keep old runtimes (and their DOM roots) alive.\n const token = pauseState.subscribe(handler);\n runtime.unsubscribePauseListener = () => {\n if (token !== undefined && token !== null) {\n pauseState.unsubscribe?.(token);\n }\n };\n }\n\n this.#rtRuntime = runtime;\n }\n\n #handleRealtimeInput(e: InputEvent): void {\n const runtime = this.#rtRuntime;\n if (!runtime.root || runtime.paused) return;\n\n const target = e.target as Element | null;\n if (!target) return;\n if (target.hasAttribute?.(DESCOPE_ATTRIBUTE_EXCLUDE_FIELD)) return;\n\n const name = target.getAttribute?.('name');\n if (!name) return;\n\n // Update the snapshot only — evaluation is debounced. Use readInputValue\n // so checkboxes read the same way as at mount; otherwise `target.value`\n // would be the string \"on\" for native checkboxes and break is-true rules.\n const key = toFormKey(name);\n runtime.snapshot[key] = readInputValue(target);\n\n if (runtime.debounceTimer) {\n clearTimeout(runtime.debounceTimer);\n }\n runtime.debounceTimer = setTimeout(() => {\n runtime.debounceTimer = null;\n this.#reEvaluateRealtime();\n }, REALTIME_CONDITION_DEBOUNCE_MS);\n }\n\n #reEvaluateRealtime(): void {\n const runtime = this.#rtRuntime;\n if (!runtime.root) return;\n\n let next: Record<string, string>;\n try {\n next = effectiveActions(\n evaluateAll(runtime.conditions, runtime.snapshot),\n runtime.serverBaseline,\n runtime.touchedIds,\n );\n } catch (e) {\n this.logger.error(\n `${LOG_PREFIX} failed to evaluate real-time rules — keeping the previous state`,\n (e as Error)?.message,\n );\n return;\n }\n\n const prevApplied = runtime.applied;\n if (shallowEqualStringMap(prevApplied, next)) return;\n\n this.logger.debug(\n `${LOG_PREFIX} form changed — updating components: was ${JSON.stringify(\n prevApplied,\n )}, now ${JSON.stringify(next)}`,\n );\n runtime.applied = apply(runtime.root, prevApplied, next);\n }\n\n // Clean up listeners and timers when the host leaves the DOM. Reaches\n // us only if BaseDescopeWc calls `super.disconnectedCallback?.()`;\n // otherwise teardown happens lazily on the next initRealtimeConditions.\n disconnectedCallback() {\n // disconnectedCallback isn't on HTMLElement in the lib types, but it\n // exists at runtime — forward into super in case the chain uses it.\n // @ts-expect-error custom-element lifecycle method missing from lib types\n super.disconnectedCallback?.();\n this.#teardownRealtimeRuntime();\n }\n\n #teardownRealtimeRuntime(): void {\n const r = this.#rtRuntime;\n if (r.debounceTimer) {\n clearTimeout(r.debounceTimer);\n }\n if (r.unsubscribePauseListener) {\n r.unsubscribePauseListener();\n }\n if (r.root) {\n // Undo anything we applied so the next screen starts clean. Skip\n // if the root is already gone (replaced by the next screen) —\n // nothing left to undo.\n if (Object.keys(r.applied).length > 0 && r.root.isConnected) {\n apply(r.root, r.applied, {});\n }\n REALTIME_CONDITION_EVENTS.forEach((ev) => {\n r.root!.removeEventListener(ev, r.inputHandler, true);\n });\n }\n this.#rtRuntime = emptyRuntime();\n }\n };\n },\n);\n"],"names":["LOG_PREFIX","readInputValue","el","HTMLInputElement","type","checked","value","shallowEqualStringMap","a","b","keysA","Object","keys","keysB","length","every","k","emptyRuntime","conditions","touchedIds","Set","snapshot","applied","serverBaseline","debounceTimer","paused","unsubscribePauseListener","inputHandler","root","effectiveActions","realtimeVerdict","out","forEach","id","componentConditionsMixin","createSingletonMixin","superclass","BaseClass","compose","loggerMixin","_a","constructor","_ComponentConditionsMixin_rtRuntime","set","this","applyComponentsState","componentsState","entries","action","COMPONENT_ACTIONS","includes","logger","error","map","join","apply","initRealtimeConditions","rootElement","screenState","__classPrivateFieldGet","_ComponentConditionsMixin_instances","_ComponentConditionsMixin_teardownRealtimeRuntime","call","_b","realtimeComponentsConditions","debug","info","initialSnapshot","_c","form","v","collectReferencedFormKeys","formKey","bare","startsWith","slice","querySelector","escapeSelector","findInputForFormKey","undefined","collectTouchedComponentIds","initialApplied","_d","has","_e","serverOnlyComponentsState","runtime","reconciled","evaluateAll","e","REALTIME_CONDITION_EVENTS","ev","addEventListener","pauseState","nextRequestStatus","subscribe","handler","isLoading","clearTimeout","token","unsubscribe","__classPrivateFieldSet","disconnectedCallback","super","target","hasAttribute","DESCOPE_ATTRIBUTE_EXCLUDE_FIELD","name","getAttribute","key","toFormKey","setTimeout","_ComponentConditionsMixin_reEvaluateRealtime","REALTIME_CONDITION_DEBOUNCE_MS","next","message","prevApplied","JSON","stringify","r","isConnected","removeEventListener"],"mappings":"6nBAqBA,MAAMA,EAAa,wBAgEnB,SAASC,EAAeC,GACtB,OAAIA,aAAcC,iBACG,aAAZD,EAAGE,KAAsBF,E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uB,CAAA"}
|
|
1
|
+
{"version":3,"file":"componentConditionsMixin.js","sources":["../../../src/lib/mixins/componentConditionsMixin.ts"],"sourcesContent":["/* eslint-disable import/prefer-default-export, no-param-reassign */\nimport { compose, createSingletonMixin } from '@descope/sdk-helpers';\nimport { loggerMixin } from '@descope/sdk-mixins';\nimport {\n REALTIME_CONDITION_DEBOUNCE_MS,\n REALTIME_CONDITION_EVENTS,\n} from '../helpers/realtime-conditions/config';\nimport {\n collectReferencedFormKeys,\n collectTouchedComponentIds,\n evaluateAll,\n FormSnapshot,\n} from '../helpers/realtime-conditions/evaluator';\nimport {\n apply,\n COMPONENT_ACTIONS,\n escapeSelector,\n} from '../helpers/realtime-conditions/applier';\nimport { DESCOPE_ATTRIBUTE_EXCLUDE_FIELD } from '../constants';\nimport type { RealtimeComponentsCondition, ScreenState } from '../types';\n\nconst LOG_PREFIX = 'component-conditions:';\n\n// What the mixin needs from its host: a way to subscribe to loading state\n// so input handling can pause while the next request is in flight. Defined\n// as an interface (not imported) to avoid a circular dependency on BaseDescopeWc.\nexport interface PausableHost {\n nextRequestStatus?: {\n // subscribe returns a token; pass that token to unsubscribe — not the handler.\n subscribe: (cb: (v: { isLoading: boolean }) => void) => string;\n unsubscribe?: (token: string) => void;\n };\n}\n\nexport interface RealtimeRuntime {\n conditions: RealtimeComponentsCondition[];\n // IDs of components that any rule can change\n touchedIds: Set<string>;\n // latest form values on screen\n snapshot: FormSnapshot;\n // what's currently applied on screen for touched components.\n // Compared against on each re-evaluation to know what to change.\n applied: Record<string, string>;\n // What the server told us to apply for these components. Stays fixed for\n // the screen's lifetime so we can fall back to it when a real-time rule\n // stops matching. Without this, a server-set action could disappear when\n // a real-time rule briefly fires on the same component.\n serverBaseline: Record<string, string>;\n debounceTimer: ReturnType<typeof setTimeout> | null;\n // true while paused (during submit, to avoid stale updates)\n paused: boolean;\n unsubscribePauseListener: (() => void) | null;\n // the listener we attach to form events (kept so we can detach)\n inputHandler: (e: Event) => void;\n // the screen root we work against\n root: HTMLElement | null;\n}\n\n// Some inputs already have `name=\"form.x\"`, others use `name=\"x\"`. Always\n// return the `form.x` form so it lines up with what rules reference.\nfunction toFormKey(name: string): string {\n return name.startsWith('form.') ? name : `form.${name}`;\n}\n\n// Try the full `form.x` first (descope components), then `x` (plain inputs).\nfunction findInputForFormKey(\n root: ParentNode,\n formKey: string,\n): Element | null {\n const bare = formKey.startsWith('form.')\n ? formKey.slice('form.'.length)\n : formKey;\n return (\n root.querySelector(`[name=\"${escapeSelector(formKey)}\"]`) ||\n root.querySelector(`[name=\"${escapeSelector(bare)}\"]`)\n );\n}\n\n// Read the current value off a form input. Reads JS properties (not HTML\n// attributes) so we pick up both the component's default and any value\n// carried over from earlier screens.\n//\n// Native <input type=checkbox> needs special handling: `.value` is always\n// \"on\", only `.checked` reflects the real state. Descope boolean components\n// (descope-checkbox, descope-switch-toggle) expose `.checked` on their class.\nfunction readInputValue(el: Element): unknown {\n if (el instanceof HTMLInputElement) {\n return el.type === 'checkbox' ? el.checked : el.value;\n }\n if ('checked' in el) {\n return (el as unknown as { checked: boolean }).checked;\n }\n if ('value' in el) {\n return (el as unknown as { value: unknown }).value;\n }\n return undefined;\n}\n\nfunction shallowEqualStringMap(\n a: Record<string, string>,\n b: Record<string, string>,\n): boolean {\n const keysA = Object.keys(a);\n const keysB = Object.keys(b);\n if (keysA.length !== keysB.length) return false;\n return keysA.every((k) => a[k] === b[k]);\n}\n\nfunction emptyRuntime(): RealtimeRuntime {\n return {\n conditions: [],\n touchedIds: new Set(),\n snapshot: {},\n applied: {},\n serverBaseline: {},\n debounceTimer: null,\n paused: false,\n unsubscribePauseListener: null,\n inputHandler: () => {},\n root: null,\n };\n}\n\n// For each touched component, pick the real-time action if a rule is firing\n// for it, otherwise fall back to the server's action. Components that no rule\n// touches are not in the result — those were already painted by\n// applyComponentsState.\nfunction effectiveActions(\n realtimeVerdict: Record<string, string>,\n serverBaseline: Record<string, string>,\n touchedIds: Set<string>,\n): Record<string, string> {\n const out: Record<string, string> = {};\n touchedIds.forEach((id) => {\n if (realtimeVerdict[id]) {\n out[id] = realtimeVerdict[id];\n } else if (serverBaseline[id]) {\n out[id] = serverBaseline[id];\n }\n });\n return out;\n}\n\nexport const componentConditionsMixin = createSingletonMixin(\n <T extends CustomElementConstructor>(superclass: T) => {\n // Pull in loggerMixin so `this.logger` is available no matter where\n // this mixin sits in the chain.\n const BaseClass = compose(loggerMixin)(superclass);\n\n return class ComponentConditionsMixin extends BaseClass {\n // One runtime per <descope-wc> element.\n #rtRuntime: RealtimeRuntime = emptyRuntime();\n\n /**\n * Apply the server's hide/disable/read-only actions to the DOM.\n * Logs unknown actions here (runs once per screen) but stays quiet on\n * the keystroke path to avoid log spam.\n */\n applyComponentsState(\n root: ParentNode,\n componentsState: Record<string, string> | undefined,\n ): void {\n if (!componentsState) return;\n Object.entries(componentsState).forEach(([id, action]) => {\n if (!(COMPONENT_ACTIONS as readonly string[]).includes(action)) {\n this.logger.error(\n `Unknown component action \"${action}\" for component with id \"${id}\"`,\n `Valid actions are ${COMPONENT_ACTIONS.map((a) => `\"${a}\"`).join(\n ', ',\n )}`,\n );\n }\n });\n apply(root, {}, componentsState);\n }\n\n /**\n * Set up real-time conditions for the current screen. Safe to call\n * twice — a second call rebuilds from screenState.\n *\n * Must run AFTER `updateScreenFromScreenState`, so the DOM reads below\n * see both server-shipped values and any component defaults from the\n * HTML.\n */\n initRealtimeConditions(\n rootElement: HTMLElement,\n screenState: ScreenState | undefined,\n ): void {\n this.#teardownRealtimeRuntime();\n\n const conditions = screenState?.realtimeComponentsConditions ?? [];\n if (!conditions.length) {\n this.logger.debug(\n `${LOG_PREFIX} no real-time rules to apply on this screen`,\n );\n return;\n }\n this.logger.info(\n `${LOG_PREFIX} found ${conditions.length} real-time rule(s) for this screen`,\n );\n\n // screenState.form uses \"phone\"; rules reference \"form.phone\".\n // Add the prefix on the way in.\n const initialSnapshot: FormSnapshot = {};\n Object.entries(screenState?.form ?? {}).forEach(([k, v]) => {\n initialSnapshot[`form.${k}`] = v;\n });\n\n // For every key the rules reference, read the current DOM value.\n // Component defaults (e.g. `checked=\"true\"` on a descope-checkbox)\n // live only in the HTML and don't make it into screenState.form, so\n // without this read the first evaluation would miss them.\n collectReferencedFormKeys(conditions).forEach((formKey) => {\n const el = findInputForFormKey(rootElement, formKey);\n if (!el) return;\n const v = readInputValue(el);\n if (v !== undefined) initialSnapshot[formKey] = v;\n });\n\n const touchedIds = collectTouchedComponentIds(conditions);\n\n // What to fall back to when a real-time rule stops matching for a\n // touched component — the actions set by server-only rules (rules\n // with no client-side conditions).\n const serverBaseline: Record<string, string> = {};\n // What's already painted on the DOM (touched components only), so\n // the first real-time evaluation can diff against the right state.\n const initialApplied: Record<string, string> = {};\n\n Object.entries(screenState?.componentsState ?? {}).forEach(\n ([id, action]) => {\n if (!touchedIds.has(id)) return;\n initialApplied[id] = action;\n },\n );\n\n Object.entries(screenState?.serverOnlyComponentsState ?? {}).forEach(\n ([id, action]) => {\n if (touchedIds.has(id)) {\n serverBaseline[id] = action;\n }\n },\n );\n\n const runtime: RealtimeRuntime = {\n conditions,\n touchedIds,\n snapshot: initialSnapshot,\n applied: initialApplied,\n serverBaseline,\n debounceTimer: null,\n paused: false,\n unsubscribePauseListener: null,\n inputHandler: () => {},\n root: rootElement,\n };\n\n // Re-run the rules now that we've read the real DOM values. The\n // server evaluated without seeing component defaults, so its\n // `componentsState` can disagree with what the user actually sees.\n // Apply the diff once before listening for input.\n const reconciled = effectiveActions(\n evaluateAll(conditions, initialSnapshot),\n serverBaseline,\n touchedIds,\n );\n if (!shallowEqualStringMap(initialApplied, reconciled)) {\n runtime.applied = apply(rootElement, initialApplied, reconciled);\n }\n\n runtime.inputHandler = (e: Event) =>\n this.#handleRealtimeInput(e as InputEvent);\n\n REALTIME_CONDITION_EVENTS.forEach((ev) => {\n rootElement.addEventListener(ev, runtime.inputHandler, true);\n });\n this.logger.debug(\n `${LOG_PREFIX} listening for \"${REALTIME_CONDITION_EVENTS.join(\n '\" and \"',\n )}\" events on form fields; ${\n Object.keys(initialApplied).length\n } component(s) start hidden / disabled / read-only by these rules`,\n );\n\n // Pause while a /next request is in flight. Without this, a debounced\n // evaluation could run between submit and the next screen render and\n // change components that are about to be replaced — causing flicker,\n // or hiding something the next screen needs visible.\n const pauseState = (this as unknown as PausableHost).nextRequestStatus;\n if (pauseState?.subscribe) {\n const handler = ({ isLoading }: { isLoading: boolean }) => {\n runtime.paused = isLoading;\n if (isLoading && runtime.debounceTimer) {\n clearTimeout(runtime.debounceTimer);\n runtime.debounceTimer = null;\n }\n };\n // subscribe returns a token; unsubscribe needs that token, not the\n // handler. Without storing it, handlers leak across screens and\n // keep old runtimes (and their DOM roots) alive.\n const token = pauseState.subscribe(handler);\n runtime.unsubscribePauseListener = () => {\n if (token !== undefined && token !== null) {\n pauseState.unsubscribe?.(token);\n }\n };\n }\n\n this.#rtRuntime = runtime;\n }\n\n #handleRealtimeInput(e: InputEvent): void {\n const runtime = this.#rtRuntime;\n if (!runtime.root || runtime.paused) return;\n\n const target = e.target as Element | null;\n if (!target) return;\n if (target.hasAttribute?.(DESCOPE_ATTRIBUTE_EXCLUDE_FIELD)) return;\n\n const name = target.getAttribute?.('name');\n if (!name) return;\n\n // Update the snapshot only — evaluation is debounced. Use readInputValue\n // so checkboxes read the same way as at mount; otherwise `target.value`\n // would be the string \"on\" for native checkboxes and break is-true rules.\n const key = toFormKey(name);\n runtime.snapshot[key] = readInputValue(target);\n\n if (runtime.debounceTimer) {\n clearTimeout(runtime.debounceTimer);\n }\n runtime.debounceTimer = setTimeout(() => {\n runtime.debounceTimer = null;\n this.#reEvaluateRealtime();\n }, REALTIME_CONDITION_DEBOUNCE_MS);\n }\n\n #reEvaluateRealtime(): void {\n const runtime = this.#rtRuntime;\n if (!runtime.root) return;\n\n let next: Record<string, string>;\n try {\n next = effectiveActions(\n evaluateAll(runtime.conditions, runtime.snapshot),\n runtime.serverBaseline,\n runtime.touchedIds,\n );\n } catch (e) {\n this.logger.error(\n `${LOG_PREFIX} failed to evaluate real-time rules — keeping the previous state`,\n (e as Error)?.message,\n );\n return;\n }\n\n const prevApplied = runtime.applied;\n if (shallowEqualStringMap(prevApplied, next)) return;\n\n this.logger.debug(\n `${LOG_PREFIX} form changed — updating components: was ${JSON.stringify(\n prevApplied,\n )}, now ${JSON.stringify(next)}`,\n );\n runtime.applied = apply(runtime.root, prevApplied, next);\n }\n\n // Clean up listeners and timers when the host leaves the DOM. Reaches\n // us only if BaseDescopeWc calls `super.disconnectedCallback?.()`;\n // otherwise teardown happens lazily on the next initRealtimeConditions.\n disconnectedCallback() {\n // disconnectedCallback isn't on HTMLElement in the lib types, but it\n // exists at runtime — forward into super in case the chain uses it.\n super.disconnectedCallback?.();\n this.#teardownRealtimeRuntime();\n }\n\n #teardownRealtimeRuntime(): void {\n const r = this.#rtRuntime;\n if (r.debounceTimer) {\n clearTimeout(r.debounceTimer);\n }\n if (r.unsubscribePauseListener) {\n r.unsubscribePauseListener();\n }\n if (r.root) {\n // Undo anything we applied so the next screen starts clean. Skip\n // if the root is already gone (replaced by the next screen) —\n // nothing left to undo.\n if (Object.keys(r.applied).length > 0 && r.root.isConnected) {\n apply(r.root, r.applied, {});\n }\n REALTIME_CONDITION_EVENTS.forEach((ev) => {\n r.root!.removeEventListener(ev, r.inputHandler, true);\n });\n }\n this.#rtRuntime = emptyRuntime();\n }\n };\n },\n);\n"],"names":["LOG_PREFIX","readInputValue","el","HTMLInputElement","type","checked","value","shallowEqualStringMap","a","b","keysA","Object","keys","keysB","length","every","k","emptyRuntime","conditions","touchedIds","Set","snapshot","applied","serverBaseline","debounceTimer","paused","unsubscribePauseListener","inputHandler","root","effectiveActions","realtimeVerdict","out","forEach","id","componentConditionsMixin","createSingletonMixin","superclass","BaseClass","compose","loggerMixin","_a","constructor","_ComponentConditionsMixin_rtRuntime","set","this","applyComponentsState","componentsState","entries","action","COMPONENT_ACTIONS","includes","logger","error","map","join","apply","initRealtimeConditions","rootElement","screenState","__classPrivateFieldGet","_ComponentConditionsMixin_instances","_ComponentConditionsMixin_teardownRealtimeRuntime","call","_b","realtimeComponentsConditions","debug","info","initialSnapshot","_c","form","v","collectReferencedFormKeys","formKey","bare","startsWith","slice","querySelector","escapeSelector","findInputForFormKey","undefined","collectTouchedComponentIds","initialApplied","_d","has","_e","serverOnlyComponentsState","runtime","reconciled","evaluateAll","e","REALTIME_CONDITION_EVENTS","ev","addEventListener","pauseState","nextRequestStatus","subscribe","handler","isLoading","clearTimeout","token","unsubscribe","__classPrivateFieldSet","disconnectedCallback","super","target","hasAttribute","DESCOPE_ATTRIBUTE_EXCLUDE_FIELD","name","getAttribute","key","toFormKey","setTimeout","_ComponentConditionsMixin_reEvaluateRealtime","REALTIME_CONDITION_DEBOUNCE_MS","next","message","prevApplied","JSON","stringify","r","isConnected","removeEventListener"],"mappings":"6nBAqBA,MAAMA,EAAa,wBAgEnB,SAASC,EAAeC,GACtB,OAAIA,aAAcC,iBACG,aAAZD,EAAGE,KAAsBF,EAAGG,QAAUH,EAAGI,MAE9C,YAAaJ,EACPA,EAAuCG,QAE7C,UAAWH,EACLA,EAAqCI,WAD/C,CAIF,CAEA,SAASC,EACPC,EACAC,GAEA,MAAMC,EAAQC,OAAOC,KAAKJ,GACpBK,EAAQF,OAAOC,KAAKH,GAC1B,OAAIC,EAAMI,SAAWD,EAAMC,QACpBJ,EAAMK,OAAOC,GAAMR,EAAEQ,KAAOP,EAAEO,IACvC,CAEA,SAASC,IACP,MAAO,CACLC,WAAY,GACZC,WAAY,IAAIC,IAChBC,SAAU,CAAE,EACZC,QAAS,CAAE,EACXC,eAAgB,CAAE,EAClBC,cAAe,KACfC,QAAQ,EACRC,yBAA0B,KAC1BC,aAAc,OACdC,KAAM,KAEV,CAMA,SAASC,EACPC,EACAP,EACAJ,GAEA,MAAMY,EAA8B,CAAA,EAQpC,OAPAZ,EAAWa,SAASC,IACdH,EAAgBG,GAClBF,EAAIE,GAAMH,EAAgBG,GACjBV,EAAe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