@entry-ui/qwik 0.4.0 → 0.6.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/lib/_internal/hooks/index.d.ts +1 -0
- package/lib/_internal/hooks/use-id-manager/index.d.ts +2 -0
- package/lib/_internal/hooks/use-id-manager/use-id-manager.d.ts +21 -0
- package/lib/_internal/hooks/use-id-manager/use-id-manager.qwik.mjs +25 -0
- package/lib/_internal/hooks/use-id-manager/use-id-manager.types.d.ts +56 -0
- package/lib/_internal/index.d.ts +1 -0
- package/lib/_internal/utilities/error/error.qwik.mjs +10 -0
- package/lib/_internal/utilities/warn/warn.qwik.mjs +10 -0
- package/lib/components/collapsible/contexts/collapsible-root-context/collapsible-root-context.d.ts +11 -0
- package/lib/components/collapsible/contexts/collapsible-root-context/collapsible-root-context.qwik.mjs +10 -0
- package/lib/components/collapsible/contexts/collapsible-root-context/collapsible-root-context.types.d.ts +58 -0
- package/lib/components/collapsible/contexts/collapsible-root-context/index.d.ts +2 -0
- package/lib/components/collapsible/contexts/collapsible-trigger-context/collapsible-trigger-context.d.ts +6 -0
- package/lib/components/collapsible/contexts/collapsible-trigger-context/collapsible-trigger-context.qwik.mjs +5 -0
- package/lib/components/collapsible/contexts/collapsible-trigger-context/collapsible-trigger-context.types.d.ts +13 -0
- package/lib/components/collapsible/contexts/collapsible-trigger-context/index.d.ts +2 -0
- package/lib/components/collapsible/contexts/index.d.ts +2 -0
- package/lib/components/collapsible/hooks/index.d.ts +2 -0
- package/lib/components/collapsible/hooks/use-collapsible-root-context/index.d.ts +2 -0
- package/lib/components/collapsible/hooks/use-collapsible-root-context/use-collapsible-root-context.d.ts +7 -0
- package/lib/components/collapsible/hooks/use-collapsible-root-context/use-collapsible-root-context.qwik.mjs +13 -0
- package/lib/components/collapsible/hooks/use-collapsible-root-context/use-collapsible-root-context.types.d.ts +22 -0
- package/lib/components/collapsible/hooks/use-collapsible-trigger-context/index.d.ts +2 -0
- package/lib/components/collapsible/hooks/use-collapsible-trigger-context/use-collapsible-trigger-context.d.ts +7 -0
- package/lib/components/collapsible/hooks/use-collapsible-trigger-context/use-collapsible-trigger-context.qwik.mjs +11 -0
- package/lib/components/collapsible/hooks/use-collapsible-trigger-context/use-collapsible-trigger-context.types.d.ts +13 -0
- package/lib/components/collapsible/index.d.ts +2 -0
- package/lib/components/collapsible/index.qwik.mjs +8 -0
- package/lib/components/collapsible/parts/collapsible-indicator/collapsible-indicator.d.ts +8 -0
- package/lib/components/collapsible/parts/collapsible-indicator/collapsible-indicator.qwik.mjs +27 -0
- package/lib/components/collapsible/parts/collapsible-indicator/collapsible-indicator.types.d.ts +15 -0
- package/lib/components/collapsible/parts/collapsible-indicator/index.d.ts +2 -0
- package/lib/components/collapsible/parts/collapsible-panel/collapsible-panel.d.ts +7 -0
- package/lib/components/collapsible/parts/collapsible-panel/collapsible-panel.qwik.mjs +169 -0
- package/lib/components/collapsible/parts/collapsible-panel/collapsible-panel.types.d.ts +31 -0
- package/lib/components/collapsible/parts/collapsible-panel/index.d.ts +2 -0
- package/lib/components/collapsible/parts/collapsible-root/collapsible-root.d.ts +7 -0
- package/lib/components/collapsible/parts/collapsible-root/collapsible-root.qwik.mjs +56 -0
- package/lib/components/collapsible/parts/collapsible-root/collapsible-root.types.d.ts +41 -0
- package/lib/components/collapsible/parts/collapsible-root/index.d.ts +2 -0
- package/lib/components/collapsible/parts/collapsible-trigger/collapsible-trigger.d.ts +7 -0
- package/lib/components/collapsible/parts/collapsible-trigger/collapsible-trigger.qwik.mjs +52 -0
- package/lib/components/collapsible/parts/collapsible-trigger/collapsible-trigger.types.d.ts +23 -0
- package/lib/components/collapsible/parts/collapsible-trigger/index.d.ts +2 -0
- package/lib/components/collapsible/parts/index.d.ts +8 -0
- package/lib/components/collapsible/parts/index.qwik.mjs +10 -0
- package/lib/components/index.d.ts +2 -0
- package/lib/components/toggle/contexts/index.d.ts +1 -0
- package/lib/components/toggle/contexts/toggle-root-context/index.d.ts +2 -0
- package/lib/components/toggle/contexts/toggle-root-context/toggle-root-context.d.ts +6 -0
- package/lib/components/toggle/contexts/toggle-root-context/toggle-root-context.qwik.mjs +5 -0
- package/lib/components/toggle/contexts/toggle-root-context/toggle-root-context.types.d.ts +22 -0
- package/lib/components/toggle/hooks/index.d.ts +1 -0
- package/lib/components/toggle/hooks/use-toggle-root-context/index.d.ts +2 -0
- package/lib/components/toggle/hooks/use-toggle-root-context/use-toggle-root-context.d.ts +7 -0
- package/lib/components/toggle/hooks/use-toggle-root-context/use-toggle-root-context.qwik.mjs +13 -0
- package/lib/components/toggle/hooks/use-toggle-root-context/use-toggle-root-context.types.d.ts +22 -0
- package/lib/components/toggle/index.d.ts +2 -0
- package/lib/components/toggle/index.qwik.mjs +6 -0
- package/lib/components/toggle/parts/index.d.ts +2 -0
- package/lib/components/toggle/parts/index.qwik.mjs +4 -0
- package/lib/components/toggle/parts/toggle-root/index.d.ts +2 -0
- package/lib/components/toggle/parts/toggle-root/toggle-root.d.ts +7 -0
- package/lib/components/toggle/parts/toggle-root/toggle-root.qwik.mjs +43 -0
- package/lib/components/toggle/parts/toggle-root/toggle-root.types.d.ts +41 -0
- package/lib/hooks/index.d.ts +2 -0
- package/lib/hooks/use-counter/index.d.ts +2 -0
- package/lib/hooks/use-counter/index.qwik.mjs +4 -0
- package/lib/hooks/use-counter/use-counter.d.ts +15 -0
- package/lib/hooks/use-counter/use-counter.qwik.mjs +113 -0
- package/lib/hooks/use-counter/use-counter.types.d.ts +73 -0
- package/lib/hooks/use-lifecycle/index.d.ts +2 -0
- package/lib/hooks/use-lifecycle/index.qwik.mjs +4 -0
- package/lib/hooks/use-lifecycle/use-lifecycle.d.ts +21 -0
- package/lib/hooks/use-lifecycle/use-lifecycle.qwik.mjs +59 -0
- package/lib/hooks/use-lifecycle/use-lifecycle.types.d.ts +33 -0
- package/lib/hooks/use-lifecycle/utilities/create-global-unmount-observer/create-global-unmount-observer.d.ts +13 -0
- package/lib/hooks/use-lifecycle/utilities/create-global-unmount-observer/create-global-unmount-observer.qwik.mjs +91 -0
- package/lib/hooks/use-lifecycle/utilities/create-global-unmount-observer/create-global-unmount-observer.types.d.ts +26 -0
- package/lib/hooks/use-lifecycle/utilities/create-global-unmount-observer/index.d.ts +2 -0
- package/lib/hooks/use-lifecycle/utilities/index.d.ts +1 -0
- package/lib/index.d.ts +1 -0
- package/lib/index.qwik.mjs +19 -3
- package/lib/types/entry-ui-qwik-event/entry-ui-qwik-event.types.d.ts +22 -0
- package/lib/types/entry-ui-qwik-event/index.d.ts +1 -0
- package/lib/types/entry-ui-qwik-event-state/entry-ui-qwik-event-state.types.d.ts +17 -0
- package/lib/types/entry-ui-qwik-event-state/index.d.ts +1 -0
- package/lib/types/index.d.ts +3 -0
- package/lib/types/signal-or-readonly-signal/index.d.ts +1 -0
- package/lib/types/signal-or-readonly-signal/signal-or-readonly-signal.types.d.ts +12 -0
- package/lib/utilities/index.d.ts +1 -0
- package/lib/utilities/make-event-preventable/index.d.ts +1 -0
- package/lib/utilities/make-event-preventable/index.qwik.mjs +4 -0
- package/lib/utilities/make-event-preventable/make-event-preventable.d.ts +20 -0
- package/lib/utilities/make-event-preventable/make-event-preventable.qwik.mjs +10 -0
- package/lib/utilities/merge-styles/merge-styles.types.d.ts +1 -1
- package/package.json +26 -2
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import type { ReadonlySignal, QRL } from '@qwik.dev/core';
|
|
2
|
+
/**
|
|
3
|
+
* Configuration parameters for the `useCounter` hook.
|
|
4
|
+
*/
|
|
5
|
+
export interface UseCounterParams {
|
|
6
|
+
/**
|
|
7
|
+
* The starting value of the counter.
|
|
8
|
+
* Must be a finite number. It will be automatically clamped if it
|
|
9
|
+
* falls outside the specified `min` and `max` range.
|
|
10
|
+
*
|
|
11
|
+
* @default 0
|
|
12
|
+
*/
|
|
13
|
+
initialCount?: number;
|
|
14
|
+
/**
|
|
15
|
+
* The amount by which the counter increases or decreases during
|
|
16
|
+
* increment and decrement operations. Must be a finite number.
|
|
17
|
+
*
|
|
18
|
+
* @default 1
|
|
19
|
+
*/
|
|
20
|
+
step?: number;
|
|
21
|
+
/**
|
|
22
|
+
* The lower numerical boundary of the counter.
|
|
23
|
+
* The counter value will never go below this limit.
|
|
24
|
+
* Must be less than or equal to `max`.
|
|
25
|
+
*
|
|
26
|
+
* @default -Number.MAX_VALUE
|
|
27
|
+
*/
|
|
28
|
+
min?: number;
|
|
29
|
+
/**
|
|
30
|
+
* The upper numerical boundary of the counter.
|
|
31
|
+
* The counter value will never exceed this limit.
|
|
32
|
+
* Must be greater than or equal to `min`.
|
|
33
|
+
*
|
|
34
|
+
* @default Number.MAX_VALUE
|
|
35
|
+
*/
|
|
36
|
+
max?: number;
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Represents the object returned by the `useCounter` hook.
|
|
40
|
+
*/
|
|
41
|
+
export interface UseCounterReturnValue {
|
|
42
|
+
/**
|
|
43
|
+
* A readonly signal representing the current numeric state of the counter.
|
|
44
|
+
* This signal is read-only, meaning its value can only be modified by calling
|
|
45
|
+
* specific `QRL` functions like `increment$`, `decrement$`, `set$`,
|
|
46
|
+
* or `reset$`, ensuring consistent and predictable state updates.
|
|
47
|
+
*/
|
|
48
|
+
count: ReadonlySignal<number>;
|
|
49
|
+
/**
|
|
50
|
+
* A `QRL` function that increases the counter value by the defined `step`.
|
|
51
|
+
* The resulting value is automatically clamped between `min` and `max`.
|
|
52
|
+
* Includes validation to ensure the operation results in a finite number.
|
|
53
|
+
*/
|
|
54
|
+
increment$: QRL<() => void>;
|
|
55
|
+
/**
|
|
56
|
+
* A `QRL` function that decreases the counter value by the defined `step`.
|
|
57
|
+
* The resulting value is automatically clamped between `min` and `max`.
|
|
58
|
+
* Includes validation to ensure the operation results in a finite number.
|
|
59
|
+
*/
|
|
60
|
+
decrement$: QRL<() => void>;
|
|
61
|
+
/**
|
|
62
|
+
* A `QRL` function that directly sets the counter to a specific numeric value.
|
|
63
|
+
* This function includes built-in validation; the value will only be updated if it
|
|
64
|
+
* is a finite number, and it will be clamped between `min` and `max`.
|
|
65
|
+
*/
|
|
66
|
+
set$: QRL<(value: number) => void>;
|
|
67
|
+
/**
|
|
68
|
+
* A `QRL` function that restores the counter to its defined `initialCount`.
|
|
69
|
+
* The `initialCount` value is re-clamped during this operation to ensure
|
|
70
|
+
* it still adheres to the current `min` and `max` constraints.
|
|
71
|
+
*/
|
|
72
|
+
reset$: QRL<() => void>;
|
|
73
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import type { UseLifecycleParams } from './use-lifecycle.types';
|
|
2
|
+
/**
|
|
3
|
+
* A hook that manages component lifecycle events with reliable server-to-browser continuity.
|
|
4
|
+
*
|
|
5
|
+
* This hook addresses a fundamental limitation in Qwik's standard `useTask$`: the fact that
|
|
6
|
+
* server-defined cleanup functions are not transferred to the client. Unlike `useVisibleTask$`,
|
|
7
|
+
* which forces eager execution and impacts performance, `useLifecycle` leverages a
|
|
8
|
+
* global `MutationObserver` and the `qresume` event to ensure cleanup logic is
|
|
9
|
+
* consistently executed when an element is removed from the DOM.
|
|
10
|
+
*
|
|
11
|
+
* Lifecycle synchronization is handled via:
|
|
12
|
+
* - **Mounting**: Executes `onMount$` during the initial task run (server or client).
|
|
13
|
+
* - **Unmounting**: Automatically registers the element for tracking upon resumption
|
|
14
|
+
* or client-side mounting, ensuring `onUnmount$` runs even if the component was SSR-ed.
|
|
15
|
+
*
|
|
16
|
+
* @remarks
|
|
17
|
+
* This hook was inspired by and contains logic adapted from the `useMountTask$` implementation
|
|
18
|
+
* in the **Qwik Design System (QDS)**.
|
|
19
|
+
* @see {@link https://github.com/kunai-consulting/qwik-design-system/blob/v2-migration/libs/base/src/hooks/use-unmount.tsx QDS use-unmount implementation}
|
|
20
|
+
*/
|
|
21
|
+
export declare const useLifecycle: (params: UseLifecycleParams) => void;
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import { useTask$, useOnDocument, $ } from "@qwik.dev/core";
|
|
2
|
+
import { isDev, isBrowser } from "@qwik.dev/core/build";
|
|
3
|
+
import { error } from "../../_internal/utilities/error/error.qwik.mjs";
|
|
4
|
+
import { createGlobalUnmountObserver } from "./utilities/create-global-unmount-observer/create-global-unmount-observer.qwik.mjs";
|
|
5
|
+
const globalUnmountObserver = createGlobalUnmountObserver();
|
|
6
|
+
const useLifecycle = (params) => {
|
|
7
|
+
const { element, onMount$, onUnmount$ } = params;
|
|
8
|
+
useTask$(async ({ cleanup }) => {
|
|
9
|
+
if (onMount$) {
|
|
10
|
+
try {
|
|
11
|
+
await Promise.resolve(onMount$());
|
|
12
|
+
} catch (err) {
|
|
13
|
+
if (isDev) {
|
|
14
|
+
error([
|
|
15
|
+
`An error occurred during the 'onMount$' lifecycle execution in 'useLifecycle' hook.`,
|
|
16
|
+
`The mount task failed.`,
|
|
17
|
+
`Check your 'onMount$' logic: ${err instanceof Error ? err.message : String(err)}`
|
|
18
|
+
]);
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
cleanup(async () => {
|
|
23
|
+
if (isBrowser && onUnmount$) {
|
|
24
|
+
const elementRef = element.value;
|
|
25
|
+
if (elementRef) {
|
|
26
|
+
globalUnmountObserver.remove({
|
|
27
|
+
element: elementRef,
|
|
28
|
+
qrl: onUnmount$
|
|
29
|
+
});
|
|
30
|
+
}
|
|
31
|
+
try {
|
|
32
|
+
await Promise.resolve(onUnmount$());
|
|
33
|
+
} catch (err) {
|
|
34
|
+
if (isDev) {
|
|
35
|
+
error([
|
|
36
|
+
`An error occurred during the 'onUnmount$' lifecycle execution in 'useLifecycle'.`,
|
|
37
|
+
`The cleanup task failed.`,
|
|
38
|
+
`Check your 'onUnmount$' logic: ${err instanceof Error ? err.message : String(err)}`
|
|
39
|
+
]);
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
});
|
|
44
|
+
});
|
|
45
|
+
useOnDocument("qresume", $(() => {
|
|
46
|
+
if (onUnmount$) {
|
|
47
|
+
const elementRef = element.value;
|
|
48
|
+
if (elementRef) {
|
|
49
|
+
globalUnmountObserver.add({
|
|
50
|
+
element: elementRef,
|
|
51
|
+
qrl: onUnmount$
|
|
52
|
+
});
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
}));
|
|
56
|
+
};
|
|
57
|
+
export {
|
|
58
|
+
useLifecycle
|
|
59
|
+
};
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import type { SignalOrReadonlySignal } from '@/types';
|
|
2
|
+
import type { QRL } from '@qwik.dev/core';
|
|
3
|
+
/**
|
|
4
|
+
* Configuration parameters for the `useLifecycle` hook.
|
|
5
|
+
*/
|
|
6
|
+
export interface UseLifecycleParams {
|
|
7
|
+
/**
|
|
8
|
+
* A signal containing the reference to the target element.
|
|
9
|
+
* This reference is essential for the global unmount observer to track the
|
|
10
|
+
* element's presence in the DOM. It ensures that the unmount logic is
|
|
11
|
+
* correctly associated with the specific node, enabling reliable detection
|
|
12
|
+
* of its removal even across the server-to-browser boundary.
|
|
13
|
+
*/
|
|
14
|
+
element: SignalOrReadonlySignal<HTMLElement | undefined | null>;
|
|
15
|
+
/**
|
|
16
|
+
* A `QRL` function executed when the component is first initialized or mounted.
|
|
17
|
+
* Unlike standard effects, this callback is designed to run within the `useTask$`
|
|
18
|
+
* scope, allowing for consistent initialization logic across both server and client
|
|
19
|
+
* environments.
|
|
20
|
+
*
|
|
21
|
+
* @default undefined
|
|
22
|
+
*/
|
|
23
|
+
onMount$?: QRL<() => void> | QRL<() => Promise<void>>;
|
|
24
|
+
/**
|
|
25
|
+
* A `QRL` function executed when the element is removed from the DOM.
|
|
26
|
+
* This callback is the primary solution for the "lost cleanup" problem in Qwik.
|
|
27
|
+
* It is reliably triggered by a `MutationObserver` when the associated `element`
|
|
28
|
+
* leaves the document tree.
|
|
29
|
+
*
|
|
30
|
+
* @default undefined
|
|
31
|
+
*/
|
|
32
|
+
onUnmount$?: QRL<() => void> | QRL<() => Promise<void>>;
|
|
33
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { CreateGlobalUnmountObserverReturnValue } from './create-global-unmount-observer.types';
|
|
2
|
+
/**
|
|
3
|
+
* A utility that creates a centralized observer to manage element unmounting across the application.
|
|
4
|
+
*
|
|
5
|
+
* This factory function returns an object with methods to track HTMLElements and execute
|
|
6
|
+
* associated cleanup QRLs when those elements are removed from the DOM. It solves
|
|
7
|
+
* the "ghost element" problem in Qwik by using a single `MutationObserver` instance,
|
|
8
|
+
* which is lazily initialized and automatically disconnected when no elements are
|
|
9
|
+
* being tracked, ensuring optimal memory management and performance.
|
|
10
|
+
* The observer uses a `WeakMap` internally to prevent memory leaks, allowing the
|
|
11
|
+
* garbage collector to reclaim elements even if they are still registered in the observer.
|
|
12
|
+
*/
|
|
13
|
+
export declare const createGlobalUnmountObserver: () => CreateGlobalUnmountObserverReturnValue;
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
import { isDev } from "@qwik.dev/core/build";
|
|
2
|
+
import { error } from "../../../../_internal/utilities/error/error.qwik.mjs";
|
|
3
|
+
const createGlobalUnmountObserver = () => {
|
|
4
|
+
let isInitialized = false;
|
|
5
|
+
let mutationObserver = void 0;
|
|
6
|
+
const qrlMap = /* @__PURE__ */ new WeakMap();
|
|
7
|
+
const elements = /* @__PURE__ */ new Set();
|
|
8
|
+
const processRemovedElements = () => {
|
|
9
|
+
const toRemove = [];
|
|
10
|
+
for (const element of elements) {
|
|
11
|
+
if (!document.contains(element)) {
|
|
12
|
+
toRemove.push(element);
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
for (const element of toRemove) {
|
|
16
|
+
const qrls = qrlMap.get(element);
|
|
17
|
+
if (qrls) {
|
|
18
|
+
const promises = [];
|
|
19
|
+
for (const qrl of qrls) {
|
|
20
|
+
const result = qrl();
|
|
21
|
+
if (result instanceof Promise) {
|
|
22
|
+
promises.push(result);
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
if (promises.length > 0) {
|
|
26
|
+
Promise.all(promises).catch((err) => {
|
|
27
|
+
if (isDev) {
|
|
28
|
+
error([
|
|
29
|
+
`An error occurred during the 'onUnmount$' lifecycle execution in 'useLifecycle' hook.`,
|
|
30
|
+
`Check the cleanup logic in your 'onUnmount$' QRL. `,
|
|
31
|
+
`One or more promises rejected during the element removal process: ${err instanceof Error ? err.message : String(err)}`
|
|
32
|
+
]);
|
|
33
|
+
}
|
|
34
|
+
});
|
|
35
|
+
}
|
|
36
|
+
qrls.clear();
|
|
37
|
+
}
|
|
38
|
+
qrlMap.delete(element);
|
|
39
|
+
elements.delete(element);
|
|
40
|
+
}
|
|
41
|
+
};
|
|
42
|
+
const cleanupObserver = () => {
|
|
43
|
+
if (mutationObserver && elements.size === 0) {
|
|
44
|
+
mutationObserver.disconnect();
|
|
45
|
+
mutationObserver = void 0;
|
|
46
|
+
isInitialized = false;
|
|
47
|
+
}
|
|
48
|
+
};
|
|
49
|
+
const initMutationObserver = () => {
|
|
50
|
+
if (isInitialized || typeof MutationObserver === "undefined") return;
|
|
51
|
+
isInitialized = true;
|
|
52
|
+
mutationObserver = new MutationObserver(() => {
|
|
53
|
+
processRemovedElements();
|
|
54
|
+
cleanupObserver();
|
|
55
|
+
});
|
|
56
|
+
mutationObserver.observe(document.body, {
|
|
57
|
+
childList: true,
|
|
58
|
+
subtree: true
|
|
59
|
+
});
|
|
60
|
+
};
|
|
61
|
+
const add = (params) => {
|
|
62
|
+
const { element, qrl } = params;
|
|
63
|
+
if (!qrlMap.has(element)) {
|
|
64
|
+
qrlMap.set(element, /* @__PURE__ */ new Set());
|
|
65
|
+
}
|
|
66
|
+
const qrls = qrlMap.get(element);
|
|
67
|
+
qrls.add(qrl);
|
|
68
|
+
elements.add(element);
|
|
69
|
+
if (!isInitialized) {
|
|
70
|
+
processRemovedElements();
|
|
71
|
+
}
|
|
72
|
+
initMutationObserver();
|
|
73
|
+
};
|
|
74
|
+
const remove = (params) => {
|
|
75
|
+
const { element, qrl } = params;
|
|
76
|
+
const qrls = qrlMap.get(element);
|
|
77
|
+
if (!qrls) return;
|
|
78
|
+
qrls.delete(qrl);
|
|
79
|
+
if (qrls.size === 0) {
|
|
80
|
+
elements.delete(element);
|
|
81
|
+
cleanupObserver();
|
|
82
|
+
}
|
|
83
|
+
};
|
|
84
|
+
return {
|
|
85
|
+
add,
|
|
86
|
+
remove
|
|
87
|
+
};
|
|
88
|
+
};
|
|
89
|
+
export {
|
|
90
|
+
createGlobalUnmountObserver
|
|
91
|
+
};
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import type { QRL } from '@qwik.dev/core';
|
|
2
|
+
/**
|
|
3
|
+
* Represents the object returned by the `createGlobalUnmountObserver` utility.
|
|
4
|
+
*/
|
|
5
|
+
export interface CreateGlobalUnmountObserverReturnValue {
|
|
6
|
+
/**
|
|
7
|
+
* Registers an element and its cleanup logic to be monitored.
|
|
8
|
+
* If the `MutationObserver` is not yet active, it will be initialized.
|
|
9
|
+
* If the element is already being tracked, the new `QRL` will be added
|
|
10
|
+
* to the existing set of cleanup tasks for that element.
|
|
11
|
+
*/
|
|
12
|
+
add: (params: {
|
|
13
|
+
element: HTMLElement;
|
|
14
|
+
qrl: QRL<() => void> | QRL<() => Promise<void>>;
|
|
15
|
+
}) => void;
|
|
16
|
+
/**
|
|
17
|
+
* Unregisters a specific cleanup QRL from an element.
|
|
18
|
+
* If no more `QRL`s are associated with the element, the element is removed
|
|
19
|
+
* from tracking. If no elements are left in the tracking set, the
|
|
20
|
+
* `MutationObserver` is disconnected to free up system resources.
|
|
21
|
+
*/
|
|
22
|
+
remove: (params: {
|
|
23
|
+
element: HTMLElement;
|
|
24
|
+
qrl: QRL<() => void> | QRL<() => Promise<void>>;
|
|
25
|
+
}) => void;
|
|
26
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './create-global-unmount-observer';
|
package/lib/index.d.ts
CHANGED
package/lib/index.qwik.mjs
CHANGED
|
@@ -1,16 +1,32 @@
|
|
|
1
1
|
import * as index from "./components/alert/parts/index.qwik.mjs";
|
|
2
|
-
import * as index$1 from "./components/
|
|
2
|
+
import * as index$1 from "./components/collapsible/parts/index.qwik.mjs";
|
|
3
|
+
import { useCollapsibleRootContext } from "./components/collapsible/hooks/use-collapsible-root-context/use-collapsible-root-context.qwik.mjs";
|
|
4
|
+
import { useCollapsibleTriggerContext } from "./components/collapsible/hooks/use-collapsible-trigger-context/use-collapsible-trigger-context.qwik.mjs";
|
|
5
|
+
import * as index$2 from "./components/separator/parts/index.qwik.mjs";
|
|
6
|
+
import * as index$3 from "./components/toggle/parts/index.qwik.mjs";
|
|
7
|
+
import { useToggleRootContext } from "./components/toggle/hooks/use-toggle-root-context/use-toggle-root-context.qwik.mjs";
|
|
3
8
|
import { useBoolean } from "./hooks/use-boolean/use-boolean.qwik.mjs";
|
|
4
9
|
import { useControllable } from "./hooks/use-controllable/use-controllable.qwik.mjs";
|
|
10
|
+
import { useCounter } from "./hooks/use-counter/use-counter.qwik.mjs";
|
|
5
11
|
import { useCycle } from "./hooks/use-cycle/use-cycle.qwik.mjs";
|
|
12
|
+
import { useLifecycle } from "./hooks/use-lifecycle/use-lifecycle.qwik.mjs";
|
|
13
|
+
import { makeEventPreventable } from "./utilities/make-event-preventable/make-event-preventable.qwik.mjs";
|
|
6
14
|
import { mergeRefs } from "./utilities/merge-refs/merge-refs.qwik.mjs";
|
|
7
15
|
import { mergeStyles } from "./utilities/merge-styles/merge-styles.qwik.mjs";
|
|
8
16
|
export {
|
|
9
17
|
index as Alert,
|
|
10
|
-
index$1 as
|
|
18
|
+
index$1 as Collapsible,
|
|
19
|
+
index$2 as Separator,
|
|
20
|
+
index$3 as Toggle,
|
|
21
|
+
makeEventPreventable,
|
|
11
22
|
mergeRefs,
|
|
12
23
|
mergeStyles,
|
|
13
24
|
useBoolean,
|
|
25
|
+
useCollapsibleRootContext,
|
|
26
|
+
useCollapsibleTriggerContext,
|
|
14
27
|
useControllable,
|
|
15
|
-
|
|
28
|
+
useCounter,
|
|
29
|
+
useCycle,
|
|
30
|
+
useLifecycle,
|
|
31
|
+
useToggleRootContext
|
|
16
32
|
};
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Represents a Qwik event augmented with Entry UI Qwik's custom prevention logic.
|
|
3
|
+
*
|
|
4
|
+
* This type extends the standard DOM event with additional methods and properties
|
|
5
|
+
* that allow for granular control over internal component handlers within the
|
|
6
|
+
* Entry UI Qwik library.
|
|
7
|
+
*/
|
|
8
|
+
export type EntryUIQwikEvent<EV extends Event> = EV & {
|
|
9
|
+
/**
|
|
10
|
+
* Prevents the internal Entry UI Qwik handler from executing for this event.
|
|
11
|
+
* When called, this method sets the `entryUIQwikHandlerPrevented` flag to `true`.
|
|
12
|
+
* Use this when you want to handle the event manually in a consumer-provided
|
|
13
|
+
* handler and prevent the component's default state updates or logic from firing.
|
|
14
|
+
*/
|
|
15
|
+
preventEntryUIQwikHandler: () => void;
|
|
16
|
+
/**
|
|
17
|
+
* Indicates whether the internal Entry UI Qwik logic has been prevented for this event.
|
|
18
|
+
* This property is read-only and is typically checked by internal component
|
|
19
|
+
* handlers to determine if they should skip their default execution logic.
|
|
20
|
+
*/
|
|
21
|
+
readonly entryUIQwikHandlerPrevented?: boolean;
|
|
22
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export type { EntryUIQwikEvent } from './entry-ui-qwik-event.types';
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Represents the state of a Qwik event within the Entry UI Qwik system.
|
|
3
|
+
*
|
|
4
|
+
* This type is a specialized version of the event object that includes only the
|
|
5
|
+
* state flag. It is typically used in internal component handlers to check
|
|
6
|
+
* if a previous handler in the execution chain has requested to prevent
|
|
7
|
+
* the default Entry UI Qwik logic.
|
|
8
|
+
*/
|
|
9
|
+
export type EntryUIQwikEventState<EV extends Event> = EV & {
|
|
10
|
+
/**
|
|
11
|
+
* Indicates whether the internal Entry UI Qwik logic has been prevented for this event.
|
|
12
|
+
* When `true`, it signals that a consumer or a preceding handler has invoked
|
|
13
|
+
* the prevention mechanism, and the current handler should likely skip
|
|
14
|
+
* its default state updates or behaviors.
|
|
15
|
+
*/
|
|
16
|
+
readonly entryUIQwikHandlerPrevented?: boolean;
|
|
17
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export type { EntryUIQwikEventState } from './entry-ui-qwik-event-state.types';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export type { SignalOrReadonlySignal } from './signal-or-readonly-signal.types';
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { Signal, ReadonlySignal } from '@qwik.dev/core';
|
|
2
|
+
/**
|
|
3
|
+
* Represents a signal that can be either mutable or readonly.
|
|
4
|
+
*
|
|
5
|
+
* This type is useful for component props or utilities that need to read from a signal
|
|
6
|
+
* without concerned whether it was created as a standard `Signal` (mutable) or
|
|
7
|
+
* a `ReadonlySignal` (typically derived from `useComputed$`). It supports:
|
|
8
|
+
*
|
|
9
|
+
* - `Signal<T>`: A standard, mutable Qwik signal.
|
|
10
|
+
* - `ReadonlySignal<T>`: A readonly signal, such as those returned by `useComputed$`.
|
|
11
|
+
*/
|
|
12
|
+
export type SignalOrReadonlySignal<T> = Signal<T> | ReadonlySignal<T>;
|
package/lib/utilities/index.d.ts
CHANGED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { makeEventPreventable } from './make-event-preventable';
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import type { EntryUIQwikEvent } from '@/types';
|
|
2
|
+
/**
|
|
3
|
+
* Augments a standard event with internal handler prevention capabilities.
|
|
4
|
+
*
|
|
5
|
+
* This utility function transforms a standard event object into an `EntryUIQwikEvent`.
|
|
6
|
+
* It adds a `preventEntryUIQwikHandler` method, allowing developers to flag
|
|
7
|
+
* an event during its execution. This flag can then be checked by subsequent
|
|
8
|
+
* handlers in any Qwik event chain (such as `onClick$`, `onKeyDown$`, or `onInput$`)
|
|
9
|
+
* to determine if the internal component logic should be bypassed.
|
|
10
|
+
*
|
|
11
|
+
* It is particularly useful when a consumer needs to intercept an event and
|
|
12
|
+
* conditionally prevent the component's default behavior or state updates
|
|
13
|
+
* (like toggling a state or closing a dialog) without necessarily stopping
|
|
14
|
+
* native event propagation or other DOM-level behaviors.
|
|
15
|
+
*
|
|
16
|
+
* When `preventEntryUIQwikHandler()` is called:
|
|
17
|
+
* - The internal property `entryUIQwikHandlerPrevented` is set to `true`.
|
|
18
|
+
* - Subsequent handlers in the event array can verify this flag to skip their logic.
|
|
19
|
+
*/
|
|
20
|
+
export declare const makeEventPreventable: <EV extends Event>(event: EV) => EntryUIQwikEvent<EV>;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
const makeEventPreventable = (event) => {
|
|
2
|
+
const entryUIQwikEvent = event;
|
|
3
|
+
entryUIQwikEvent.preventEntryUIQwikHandler = () => {
|
|
4
|
+
entryUIQwikEvent.entryUIQwikHandlerPrevented = true;
|
|
5
|
+
};
|
|
6
|
+
return entryUIQwikEvent;
|
|
7
|
+
};
|
|
8
|
+
export {
|
|
9
|
+
makeEventPreventable
|
|
10
|
+
};
|
|
@@ -6,7 +6,7 @@ import type { CSSProperties } from '@qwik.dev/core';
|
|
|
6
6
|
*
|
|
7
7
|
* - `string`: Standard inline CSS strings (e.g., `"color: red; padding: 10px"`).
|
|
8
8
|
*
|
|
9
|
-
* - `CSSProperties`: A structured object of CSS declarations (e.g., `{ color:
|
|
9
|
+
* - `CSSProperties`: A structured object of CSS declarations (e.g., `{ color: "red" }`).
|
|
10
10
|
*
|
|
11
11
|
* - `undefined`: Useful for conditional styling where a style might not be present.
|
|
12
12
|
* Since `boolean` is not accepted, use ternary operators or logical OR
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@entry-ui/qwik",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.6.0",
|
|
4
4
|
"description": "",
|
|
5
5
|
"keywords": [],
|
|
6
6
|
"homepage": "https://github.com/ZAHON/entry-ui#readme",
|
|
@@ -19,10 +19,18 @@
|
|
|
19
19
|
"types": "./lib/components/alert/index.d.ts",
|
|
20
20
|
"import": "./lib/components/alert/index.qwik.mjs"
|
|
21
21
|
},
|
|
22
|
+
"./collapsible": {
|
|
23
|
+
"types": "./lib/components/collapsible/index.d.ts",
|
|
24
|
+
"import": "./lib/components/collapsible/index.qwik.mjs"
|
|
25
|
+
},
|
|
22
26
|
"./separator": {
|
|
23
27
|
"types": "./lib/components/separator/index.d.ts",
|
|
24
28
|
"import": "./lib/components/separator/index.qwik.mjs"
|
|
25
29
|
},
|
|
30
|
+
"./toggle": {
|
|
31
|
+
"types": "./lib/components/toggle/index.d.ts",
|
|
32
|
+
"import": "./lib/components/toggle/index.qwik.mjs"
|
|
33
|
+
},
|
|
26
34
|
"./use-boolean": {
|
|
27
35
|
"types": "./lib/hooks/use-boolean/index.d.ts",
|
|
28
36
|
"import": "./lib/hooks/use-boolean/index.qwik.mjs"
|
|
@@ -31,10 +39,22 @@
|
|
|
31
39
|
"types": "./lib/hooks/use-controllable/index.d.ts",
|
|
32
40
|
"import": "./lib/hooks/use-controllable/index.qwik.mjs"
|
|
33
41
|
},
|
|
42
|
+
"./use-counter": {
|
|
43
|
+
"types": "./lib/hooks/use-counter/index.d.ts",
|
|
44
|
+
"import": "./lib/hooks/use-counter/index.qwik.mjs"
|
|
45
|
+
},
|
|
34
46
|
"./use-cycle": {
|
|
35
47
|
"types": "./lib/hooks/use-cycle/index.d.ts",
|
|
36
48
|
"import": "./lib/hooks/use-cycle/index.qwik.mjs"
|
|
37
49
|
},
|
|
50
|
+
"./use-lifecycle": {
|
|
51
|
+
"types": "./lib/hooks/use-lifecycle/index.d.ts",
|
|
52
|
+
"import": "./lib/hooks/use-lifecycle/index.qwik.mjs"
|
|
53
|
+
},
|
|
54
|
+
"./make-event-preventable": {
|
|
55
|
+
"types": "./lib/utilities/make-event-preventable/index.d.ts",
|
|
56
|
+
"import": "./lib/utilities/make-event-preventable/index.qwik.mjs"
|
|
57
|
+
},
|
|
38
58
|
"./merge-refs": {
|
|
39
59
|
"types": "./lib/utilities/merge-refs/index.d.ts",
|
|
40
60
|
"import": "./lib/utilities/merge-refs/index.qwik.mjs"
|
|
@@ -42,6 +62,9 @@
|
|
|
42
62
|
"./merge-styles": {
|
|
43
63
|
"types": "./lib/utilities/merge-styles/index.d.ts",
|
|
44
64
|
"import": "./lib/utilities/merge-styles/index.qwik.mjs"
|
|
65
|
+
},
|
|
66
|
+
"./types": {
|
|
67
|
+
"types": "./lib/types/index.d.ts"
|
|
45
68
|
}
|
|
46
69
|
},
|
|
47
70
|
"files": [
|
|
@@ -81,7 +104,7 @@
|
|
|
81
104
|
"qwik": "qwik"
|
|
82
105
|
},
|
|
83
106
|
"dependencies": {
|
|
84
|
-
"@entry-ui/utilities": "^0.
|
|
107
|
+
"@entry-ui/utilities": "^0.5.0"
|
|
85
108
|
},
|
|
86
109
|
"devDependencies": {
|
|
87
110
|
"@entry-ui/eslint": "workspace:*",
|
|
@@ -95,6 +118,7 @@
|
|
|
95
118
|
"jsdom": "^27.4.0",
|
|
96
119
|
"prettier": "^3.7.4",
|
|
97
120
|
"typescript": "^5.9.3",
|
|
121
|
+
"typescript-plugin-css-modules": "^5.2.0",
|
|
98
122
|
"undici": "^7.18.2",
|
|
99
123
|
"vite": "^7.3.1",
|
|
100
124
|
"vite-tsconfig-paths": "^6.0.4",
|