@marianmeres/stuic 2.1.25 → 2.1.27

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.
@@ -169,16 +169,17 @@
169
169
  focus-within:border-input-accent focus-within:dark:border-input-accent-dark
170
170
  focus-within:ring-input-accent/20 focus-within:dark:ring-input-accent-dark/20
171
171
  focus-within:ring-4`,
172
- invalid &&
173
- twMerge(
174
- `border-input-accent-invalid dark:border-input-accent-invalid-dark
175
- focus-within:border-input-accent-invalid focus-within:dark:border-input-accent-invalid-dark
176
- focus-within:ring-input-accent-invalid/20 focus-within:dark:ring-input-accent-invalid-dark/20`,
177
- classInputBoxWrapInvalid
178
- ),
179
172
  disabled && "cursor-not-allowed opacity-50",
180
173
  _preset.inputBox.size[size],
181
- classInputBoxWrap
174
+ invalid
175
+ ? twMerge(
176
+ classInputBoxWrap,
177
+ `border-input-accent-invalid dark:border-input-accent-invalid-dark
178
+ focus-within:border-input-accent-invalid focus-within:dark:border-input-accent-invalid-dark
179
+ focus-within:ring-input-accent-invalid/20 focus-within:dark:ring-input-accent-invalid-dark/20`,
180
+ classInputBoxWrapInvalid
181
+ )
182
+ : classInputBoxWrap
182
183
  )}
183
184
  >
184
185
  <div class="flex">
@@ -13,6 +13,7 @@ export * from "./is-nullish.js";
13
13
  export * from "./maybe-json-parse.js";
14
14
  export * from "./maybe-json-stringify.js";
15
15
  export * from "./nl2br.js";
16
+ export * from "./observe-exists.svelte.js";
16
17
  export * from "./omit-pick.js";
17
18
  export * from "./oscillate.js";
18
19
  export * from "./paint.js";
@@ -13,6 +13,7 @@ export * from "./is-nullish.js";
13
13
  export * from "./maybe-json-parse.js";
14
14
  export * from "./maybe-json-stringify.js";
15
15
  export * from "./nl2br.js";
16
+ export * from "./observe-exists.svelte.js";
16
17
  export * from "./omit-pick.js";
17
18
  export * from "./oscillate.js";
18
19
  export * from "./paint.js";
@@ -0,0 +1,8 @@
1
+ /** Will observe DOM changes and triggers callback when element presence changes */
2
+ export declare function observeExists(selector: string, options?: Partial<{
3
+ rootElement: HTMLElement;
4
+ }>): {
5
+ readonly current: boolean;
6
+ disconnect(): void;
7
+ forceCheck(): void;
8
+ };
@@ -0,0 +1,40 @@
1
+ /** Will observe DOM changes and triggers callback when element presence changes */
2
+ export function observeExists(selector, options = {}) {
3
+ if (!selector)
4
+ throw new TypeError("Expecting non empty selector");
5
+ const { rootElement = document.body } = options;
6
+ const ns = `[observeExists] [${selector}]`;
7
+ const clog = (...args) => console.debug(ns, ...args);
8
+ const check = () => rootElement.querySelector(selector) !== null;
9
+ let current = $state(check());
10
+ //
11
+ const observer = new MutationObserver((mutations) => {
12
+ let shouldCheck = false;
13
+ for (const mutation of mutations) {
14
+ if (mutation.type === "childList") {
15
+ // was something added or removed?
16
+ if (mutation.addedNodes.length > 0 || mutation.removedNodes.length > 0) {
17
+ shouldCheck = true;
18
+ break;
19
+ }
20
+ }
21
+ }
22
+ if (shouldCheck)
23
+ current = check();
24
+ });
25
+ // start observing now
26
+ clog(`connecting...`);
27
+ observer.observe(rootElement, { childList: true, subtree: true });
28
+ return {
29
+ get current() {
30
+ return current;
31
+ },
32
+ disconnect() {
33
+ clog(`disconnecting...`);
34
+ observer.disconnect();
35
+ },
36
+ forceCheck() {
37
+ check();
38
+ },
39
+ };
40
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@marianmeres/stuic",
3
- "version": "2.1.25",
3
+ "version": "2.1.27",
4
4
  "scripts": {
5
5
  "dev": "vite dev",
6
6
  "build": "vite build && npm run prepack",