MCPcopy
hub / github.com/clauderic/dnd-kit / StyleInjector

Class StyleInjector

packages/dom/src/core/plugins/stylesheet/StyleInjector.ts:23–261  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

21>();
22
23export class StyleInjector extends CorePlugin<
24 DragDropManager,
25 StyleInjectorOptions
26> {
27 #registeredRules = new Set<string>();
28
29 @reactive
30 private accessor additionalRoots = new Set<Document | ShadowRoot>();
31
32 constructor(manager: DragDropManager, options?: StyleInjectorOptions) {
33 super(manager, options);
34
35 this.registerEffect(this.#syncStyles);
36 }
37
38 /**
39 * Registers CSS rules to be injected into the active drag operation's
40 * document and shadow roots. The StyleInjector handles tracking
41 * which roots need the styles and cleaning up when they're no longer needed.
42 *
43 * Returns a cleanup function that unregisters the rules.
44 */
45 public register(cssRules: string): CleanupFunction {
46 this.#registeredRules.add(cssRules);
47
48 return () => {
49 this.#registeredRules.delete(cssRules);
50 };
51 }
52
53 /**
54 * Adds an additional root to track for style injection.
55 * Returns a cleanup function that removes the root.
56 */
57 public addRoot(root: Document | ShadowRoot): CleanupFunction {
58 untracked(() => {
59 const roots = new Set(this.additionalRoots);
60 roots.add(root);
61 this.additionalRoots = roots;
62 });
63
64 return () => {
65 untracked(() => {
66 const roots = new Set(this.additionalRoots);
67 roots.delete(root);
68 this.additionalRoots = roots;
69 });
70 };
71 }
72
73 @derived
74 private get sourceRoot() {
75 const {source} = this.manager.dragOperation;
76 return getRoot(source?.element ?? null);
77 }
78
79 @derived
80 private get targetRoot() {

Callers

nothing calls this directly

Calls 1

configuratorFunction · 0.90

Tested by

no test coverage detected