Home / File/ misc.js — svelte Source File

misc.js — svelte Source File

Architecture documentation for misc.js, a javascript file in the svelte codebase. 6 imports, 2 dependents.

File javascript ClientRuntime Hydration 6 imports 2 dependents 3 functions

Entity Profile

Dependency Diagram

graph LR
  56e684d7_8156_2bdf_6537_717e59d1e537["misc.js"]
  f3948b0d_b92a_0767_ba6c_832767f4e2bb["hydration.js"]
  56e684d7_8156_2bdf_6537_717e59d1e537 --> f3948b0d_b92a_0767_ba6c_832767f4e2bb
  9a9bbc27_46b6_021c_6d77_f736ed4b40f0["operations.js"]
  56e684d7_8156_2bdf_6537_717e59d1e537 --> 9a9bbc27_46b6_021c_6d77_f736ed4b40f0
  7bff6ec5_15bb_4289_1bd5_99cb794400ed["clear_text_content"]
  56e684d7_8156_2bdf_6537_717e59d1e537 --> 7bff6ec5_15bb_4289_1bd5_99cb794400ed
  f3bd5a62_2879_ccbe_7046_712cbf9eeaab["get_first_child"]
  56e684d7_8156_2bdf_6537_717e59d1e537 --> f3bd5a62_2879_ccbe_7046_712cbf9eeaab
  8e9a8b22_9754_09a3_8bf1_af0aeb68deca["task.js"]
  56e684d7_8156_2bdf_6537_717e59d1e537 --> 8e9a8b22_9754_09a3_8bf1_af0aeb68deca
  2cab0f64_6d19_d981_66e2_d2555c252702["queue_micro_task"]
  56e684d7_8156_2bdf_6537_717e59d1e537 --> 2cab0f64_6d19_d981_66e2_d2555c252702
  0acd2537_e1bf_d7ae_30d5_407378cfa4d3["attributes.js"]
  0acd2537_e1bf_d7ae_30d5_407378cfa4d3 --> 56e684d7_8156_2bdf_6537_717e59d1e537
  af7441d2_339a_2db1_88df_90dba2875c10["shared.js"]
  af7441d2_339a_2db1_88df_90dba2875c10 --> 56e684d7_8156_2bdf_6537_717e59d1e537
  style 56e684d7_8156_2bdf_6537_717e59d1e537 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

import { hydrating } from '../hydration.js';
import { clear_text_content, get_first_child } from '../operations.js';
import { queue_micro_task } from '../task.js';

/**
 * @param {HTMLElement} dom
 * @param {boolean} value
 * @returns {void}
 */
export function autofocus(dom, value) {
	if (value) {
		const body = document.body;
		dom.autofocus = true;

		queue_micro_task(() => {
			if (document.activeElement === body) {
				dom.focus();
			}
		});
	}
}

/**
 * The child of a textarea actually corresponds to the defaultValue property, so we need
 * to remove it upon hydration to avoid a bug when someone resets the form value.
 * @param {HTMLTextAreaElement} dom
 * @returns {void}
 */
export function remove_textarea_child(dom) {
	if (hydrating && get_first_child(dom) !== null) {
		clear_text_content(dom);
	}
}

let listening_to_form_reset = false;

export function add_form_reset_listener() {
	if (!listening_to_form_reset) {
		listening_to_form_reset = true;
		document.addEventListener(
			'reset',
			(evt) => {
				// Needs to happen one tick later or else the dom properties of the form
				// elements have not updated to their reset values yet
				Promise.resolve().then(() => {
					if (!evt.defaultPrevented) {
						for (const e of /**@type {HTMLFormElement} */ (evt.target).elements) {
							// @ts-expect-error
							e.__on_r?.();
						}
					}
				});
			},
			// In the capture phase to guarantee we get noticed of it (no possibility of stopPropagation)
			{ capture: true }
		);
	}
}

Domain

Subdomains

Frequently Asked Questions

What does misc.js do?
misc.js is a source file in the svelte codebase, written in javascript. It belongs to the ClientRuntime domain, Hydration subdomain.
What functions are defined in misc.js?
misc.js defines 3 function(s): add_form_reset_listener, autofocus, remove_textarea_child.
What does misc.js depend on?
misc.js imports 6 module(s): clear_text_content, get_first_child, hydration.js, operations.js, queue_micro_task, task.js.
What files import misc.js?
misc.js is imported by 2 file(s): attributes.js, shared.js.
Where is misc.js in the architecture?
misc.js is located at packages/svelte/src/internal/client/dom/elements/misc.js (domain: ClientRuntime, subdomain: Hydration, directory: packages/svelte/src/internal/client/dom/elements).

Analyze Your Own Codebase

Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.

Try Supermodel Free