Skip to content

chore: move more element stuff #10780

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 10 commits into from
Mar 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions packages/svelte/src/internal/client/dom/blocks/await.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { is_promise } from '../../../common.js';
import { hydrate_block_anchor } from '../../hydration.js';
import { remove } from '../../reconciler.js';
import { hydrate_block_anchor } from '../hydration.js';
import { remove } from '../reconciler.js';
import { current_block, execute_effect, flushSync } from '../../runtime.js';
import { destroy_effect, render_effect } from '../../reactivity/effects.js';
import { trigger_transitions } from '../../transitions.js';
import { trigger_transitions } from '../elements/transitions.js';
import { AWAIT_BLOCK, UNINITIALIZED } from '../../constants.js';

/** @returns {import('../../types.js').AwaitBlock} */
Expand Down
6 changes: 3 additions & 3 deletions packages/svelte/src/internal/client/dom/blocks/css-props.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { namespace_svg } from '../../../../constants.js';
import { current_hydration_fragment, hydrate_block_anchor, hydrating } from '../../hydration.js';
import { empty } from '../../operations.js';
import { current_hydration_fragment, hydrate_block_anchor, hydrating } from '../hydration.js';
import { empty } from '../operations.js';
import { render_effect } from '../../reactivity/effects.js';
import { insert, remove } from '../../reconciler.js';
import { insert, remove } from '../reconciler.js';

/**
* @param {Element | Text | Comment} anchor
Expand Down
10 changes: 5 additions & 5 deletions packages/svelte/src/internal/client/dom/blocks/each.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,14 @@ import {
hydrate_block_anchor,
hydrating,
set_current_hydration_fragment
} from '../../hydration.js';
import { clear_text_content, empty, map_get, map_set } from '../../operations.js';
import { insert, remove } from '../../reconciler.js';
} from '../hydration.js';
import { clear_text_content, empty } from '../operations.js';
import { insert, remove } from '../reconciler.js';
import { current_block, execute_effect } from '../../runtime.js';
import { destroy_effect, render_effect } from '../../reactivity/effects.js';
import { source, mutable_source, set } from '../../reactivity/sources.js';
import { trigger_transitions } from '../../transitions.js';
import { is_array, is_frozen } from '../../utils.js';
import { trigger_transitions } from '../elements/transitions.js';
import { is_array, is_frozen, map_get, map_set } from '../../utils.js';
import { EACH_BLOCK, EACH_ITEM_BLOCK, STATE_SYMBOL } from '../../constants.js';

const NEW_BLOCK = -1;
Expand Down
2 changes: 1 addition & 1 deletion packages/svelte/src/internal/client/dom/blocks/html.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { render_effect } from '../../reactivity/effects.js';
import { reconcile_html, remove } from '../../reconciler.js';
import { reconcile_html, remove } from '../reconciler.js';

/**
* @param {Element | Text | Comment} dom
Expand Down
6 changes: 3 additions & 3 deletions packages/svelte/src/internal/client/dom/blocks/if.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@ import {
hydrate_block_anchor,
hydrating,
set_current_hydration_fragment
} from '../../hydration.js';
import { remove } from '../../reconciler.js';
} from '../hydration.js';
import { remove } from '../reconciler.js';
import { current_block, execute_effect } from '../../runtime.js';
import { destroy_effect, render_effect } from '../../reactivity/effects.js';
import { trigger_transitions } from '../../transitions.js';
import { trigger_transitions } from '../elements/transitions.js';

/** @returns {import('../../types.js').IfBlock} */
function create_if_block() {
Expand Down
6 changes: 3 additions & 3 deletions packages/svelte/src/internal/client/dom/blocks/key.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { UNINITIALIZED, KEY_BLOCK } from '../../constants.js';
import { hydrate_block_anchor } from '../../hydration.js';
import { remove } from '../../reconciler.js';
import { hydrate_block_anchor } from '../hydration.js';
import { remove } from '../reconciler.js';
import { current_block, execute_effect } from '../../runtime.js';
import { destroy_effect, render_effect } from '../../reactivity/effects.js';
import { trigger_transitions } from '../../transitions.js';
import { trigger_transitions } from '../elements/transitions.js';
import { safe_not_equal } from '../../reactivity/equality.js';

/** @returns {import('../../types.js').KeyBlock} */
Expand Down
2 changes: 1 addition & 1 deletion packages/svelte/src/internal/client/dom/blocks/snippet.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { SNIPPET_BLOCK } from '../../constants.js';
import { render_effect } from '../../reactivity/effects.js';
import { remove } from '../../reconciler.js';
import { remove } from '../reconciler.js';
import { current_block, untrack } from '../../runtime.js';

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { DYNAMIC_COMPONENT_BLOCK } from '../../constants.js';
import { hydrate_block_anchor } from '../../hydration.js';
import { hydrate_block_anchor } from '../hydration.js';
import { destroy_effect, render_effect } from '../../reactivity/effects.js';
import { remove } from '../../reconciler.js';
import { remove } from '../reconciler.js';
import { current_block, execute_effect } from '../../runtime.js';
import { trigger_transitions } from '../../transitions.js';
import { trigger_transitions } from '../elements/transitions.js';

/**
* @template P
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { namespace_svg } from '../../../../constants.js';
import { DYNAMIC_ELEMENT_BLOCK } from '../../constants.js';
import { current_hydration_fragment, hydrate_block_anchor, hydrating } from '../../hydration.js';
import { empty } from '../../operations.js';
import { current_hydration_fragment, hydrate_block_anchor, hydrating } from '../hydration.js';
import { empty } from '../operations.js';
import { destroy_effect, render_effect } from '../../reactivity/effects.js';
import { insert, remove } from '../../reconciler.js';
import { insert, remove } from '../reconciler.js';
import { current_block, execute_effect } from '../../runtime.js';
import { is_array } from '../../utils.js';

Expand Down
6 changes: 3 additions & 3 deletions packages/svelte/src/internal/client/dom/blocks/svelte-head.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ import {
get_hydration_fragment,
hydrating,
set_current_hydration_fragment
} from '../../hydration.js';
import { empty } from '../../operations.js';
} from '../hydration.js';
import { empty } from '../operations.js';
import { render_effect } from '../../reactivity/effects.js';
import { remove } from '../../reconciler.js';
import { remove } from '../reconciler.js';
import { current_block } from '../../runtime.js';

/**
Expand Down
53 changes: 53 additions & 0 deletions packages/svelte/src/internal/client/dom/elements/actions.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
import { effect } from '../../reactivity/effects.js';
import { deep_read_state, untrack } from '../../runtime.js';

/**
* @template P
* @param {Element} dom
* @param {(dom: Element, value?: P) => import('#client').ActionPayload<P>} action
* @param {() => P} [value_fn]
* @returns {void}
*/
export function action(dom, action, value_fn) {
/** @type {undefined | import('#client').ActionPayload<P>} */
var payload = undefined;
var needs_deep_read = false;

// Action could come from a prop, therefore could be a signal, therefore untrack
// TODO we could take advantage of this and enable https://github.com/sveltejs/svelte/issues/6942
effect(() => {
if (value_fn) {
var value = value_fn();
untrack(() => {
if (payload === undefined) {
payload = action(dom, value) || {};
needs_deep_read = !!payload?.update;
} else {
var update = payload.update;
if (typeof update === 'function') {
update(value);
}
}
});
// Action's update method is coarse-grained, i.e. when anything in the passed value changes, update.
// This works in legacy mode because of mutable_source being updated as a whole, but when using $state
// together with actions and mutation, it wouldn't notice the change without a deep read.
if (needs_deep_read) {
deep_read_state(value);
}
} else {
untrack(() => (payload = action(dom)));
}
});

effect(() => {
if (payload !== undefined) {
var destroy = payload.destroy;
if (typeof destroy === 'function') {
return () => {
/** @type {Function} */ (destroy)();
};
}
}
});
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import { DEV } from 'esm-env';
import { hydrating } from '../../hydration.js';
import { hydrating } from '../hydration.js';
import { render_effect } from '../../reactivity/effects.js';
import { get_descriptors, object_assign } from '../../utils.js';
import { map_get, map_set } from '../../operations.js';
import { get_descriptors, map_get, map_set, object_assign } from '../../utils.js';
import { AttributeAliases, DelegatedEvents, namespace_svg } from '../../../../constants.js';
import { delegate } from './events.js';
import { autofocus } from './misc.js';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { DEV } from 'esm-env';
import { render_effect } from '../../reactivity/effects.js';
import { stringify } from '../../render.js';
import { render_effect } from '../../../reactivity/effects.js';
import { stringify } from '../../../render.js';

/**
* @param {HTMLInputElement} input
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { hydrating } from '../../hydration.js';
import { destroy_effect, managed_effect, render_effect } from '../../reactivity/effects.js';
import { destroy_effect, managed_effect, render_effect } from '../../../reactivity/effects.js';
import { listen } from './shared.js';

/** @param {TimeRanges} ranges */
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { render_effect } from '../../reactivity/effects.js';
import { get_descriptor } from '../../utils.js';
import { render_effect } from '../../../reactivity/effects.js';
import { get_descriptor } from '../../../utils.js';

/**
* Makes an `export`ed (non-prop) variable available on the `$$props` object
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { effect } from '../../reactivity/effects.js';
import { effect } from '../../../reactivity/effects.js';

/**
* Selects the correct option(s) (depending on whether this is a multiple select)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { render_effect } from '../../reactivity/effects.js';
import { render_effect } from '../../../reactivity/effects.js';

/**
* Fires the handler once immediately (unless corresponding arg is set to `false`),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { effect, render_effect } from '../../reactivity/effects.js';
import { untrack } from '../../runtime.js';
import { effect, render_effect } from '../../../reactivity/effects.js';
import { untrack } from '../../../runtime.js';

/**
* Resize observer singleton.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { STATE_SYMBOL } from '../../constants.js';
import { effect } from '../../reactivity/effects.js';
import { untrack } from '../../runtime.js';
import { STATE_SYMBOL } from '../../../constants.js';
import { effect } from '../../../reactivity/effects.js';
import { untrack } from '../../../runtime.js';

/**
* @param {any} bound_value
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { render_effect } from '../../reactivity/effects.js';
import { render_effect } from '../../../reactivity/effects.js';

/**
* @param {'innerHTML' | 'textContent' | 'innerText'} property
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { render_effect } from '../../reactivity/effects.js';
import { render_effect } from '../../../reactivity/effects.js';
import { listen } from './shared.js';

/**
Expand Down
4 changes: 2 additions & 2 deletions packages/svelte/src/internal/client/dom/elements/class.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { hydrating } from '../../hydration.js';
import { set_class_name } from '../../operations.js';
import { hydrating } from '../hydration.js';
import { set_class_name } from '../operations.js';
import { render_effect } from '../../reactivity/effects.js';

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { createClassComponent } from '../../legacy/legacy-client.js';
import { destroy_effect, render_effect } from './reactivity/effects.js';
import { open, close } from './dom/template.js';
import { define_property } from './utils.js';
import { createClassComponent } from '../../../../legacy/legacy-client.js';
import { destroy_effect, render_effect } from '../../reactivity/effects.js';
import { open, close } from '../template.js';
import { define_property } from '../../utils.js';

/**
* @typedef {Object} CustomElementPropDefinition
Expand Down
2 changes: 1 addition & 1 deletion packages/svelte/src/internal/client/dom/elements/misc.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { hydrating } from '../../hydration.js';
import { hydrating } from '../hydration.js';
import { render_effect } from '../../reactivity/effects.js';
import { current_block } from '../../runtime.js';

Expand Down
Loading