Skip to content
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
5 changes: 5 additions & 0 deletions .changeset/tricky-dogs-cross.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@qwik.dev/core': patch
---

FIX: The types for the JSX event handlers are more precise about their scope (e.g. no `document:OnQVisible$` or `onQIdle$`).
2 changes: 0 additions & 2 deletions packages/docs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@
"devDependencies": {
"@algolia/autocomplete-core": "1.7.4",
"@algolia/client-search": "4.14.3",
"@builder.io/qwik": "npm:@qwik.dev/core@*",
"@builder.io/qwik-city": "npm:@qwik.dev/router@*",
"@emotion/react": "11.14.0",
"@emotion/styled": "11.14.1",
"@modular-forms/qwik": "0.29.1",
Expand Down
2 changes: 1 addition & 1 deletion packages/docs/src/components/docsearch/doc-search.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ export const DocSearch = component$((props: DocSearchProps) => {
<div
class={{ docsearch: true, 'ai-result-open': aiResultOpen.value }}
window:onKeyDown$={[
sync$((event: KeyboardEvent) => {
sync$((event) => {
if (event.key === 'k' && (event.metaKey || event.ctrlKey)) {
event.preventDefault();
}
Expand Down
2 changes: 1 addition & 1 deletion packages/docs/src/components/theme-toggle/Brilliance.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { component$ } from '@builder.io/qwik';
import { component$ } from '@qwik.dev/core';

interface BrillianceIconProps {
class?: string;
Expand Down
2 changes: 1 addition & 1 deletion packages/docs/src/components/theme-toggle/Moon.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { component$ } from '@builder.io/qwik';
import { component$ } from '@qwik.dev/core';

interface MoonIconProps {
class?: string;
Expand Down
2 changes: 1 addition & 1 deletion packages/docs/src/components/theme-toggle/Sun.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { component$ } from '@builder.io/qwik';
import { component$ } from '@qwik.dev/core';

interface SunIconProps {
class?: string;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* The effective theme is stored on the `<html>` element as a `data-theme` attribute. There is also
* the `data-theme-auto` attribute which is present when the user has selected "auto" theme.
*/
import { component$, event$, isServer, useContext, useStyles$ } from '@builder.io/qwik';
import { component$, event$, isServer, useContext, useStyles$ } from '@qwik.dev/core';
import { useVisibleTask$ } from '@qwik.dev/core';
import { GlobalStore, type SiteStore } from '~/context';
import { BrillianceIcon } from './Brilliance';
Expand Down
42 changes: 35 additions & 7 deletions packages/docs/src/routes/api/qwik/api.json

Large diffs are not rendered by default.

97 changes: 31 additions & 66 deletions packages/docs/src/routes/api/qwik/index.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -2805,7 +2805,7 @@ export type QRL<TYPE = unknown> = {
getCaptured(): unknown[] | null;
getSymbol(): string;
getHash(): string;
dev: QRLDev | null;
dev?: QRLDev | null;
} & BivariantQrlFn<QrlArgs<TYPE>, QrlReturn<TYPE>>;
```

Expand Down Expand Up @@ -2913,7 +2913,7 @@ export type QRL<TYPE = unknown> = {
getCaptured(): unknown[] | null;
getSymbol(): string;
getHash(): string;
dev: QRLDev | null;
dev?: QRLDev | null;
} & BivariantQrlFn<QrlArgs<TYPE>, QrlReturn<TYPE>>;
```

Expand All @@ -2928,8 +2928,7 @@ export type QRLEventHandlerMulti<EV extends Event, EL> =
| QRL<EventHandler<EV, EL>>
| undefined
| null
| QRLEventHandlerMulti<EV, EL>[]
| EventHandler<EV, EL>;
| QRLEventHandlerMulti<EV, EL>[];
```

**References:** [QRL](#qrl), [EventHandler](#eventhandler), [QRLEventHandlerMulti](#qrleventhandlermulti)
Expand Down Expand Up @@ -3262,6 +3261,16 @@ export type QwikPointerEvent<T = Element> = NativePointerEvent;

[Edit this section](https://github.com/QwikDev/qwik/tree/main/packages/qwik/src/core/shared/jsx/types/jsx-qwik-events.ts)

## QwikResumeEvent

Emitted by qwik-core on the container element when it resumes from a paused state. You cannot put a Qwik event handler on the container so you must listen on the document instead.

```typescript
export type QwikResumeEvent = CustomEvent<{}>;
```

[Edit this section](https://github.com/QwikDev/qwik/tree/main/packages/qwik/src/core/shared/jsx/types/jsx-qwik-events.ts)

## QwikSubmitEvent

> Warning: This API is now obsolete.
Expand Down Expand Up @@ -3293,7 +3302,7 @@ export type QwikSVGElements = {

## QwikSymbolEvent

Emitted by qwik-loader when a module was lazily loaded
Emitted by qwik-loader on document when a module was lazily loaded

```typescript
export type QwikSymbolEvent = CustomEvent<{
Expand Down Expand Up @@ -3351,9 +3360,19 @@ export type QwikUIEvent<T = Element> = NativeUIEvent;

[Edit this section](https://github.com/QwikDev/qwik/tree/main/packages/qwik/src/core/shared/jsx/types/jsx-qwik-events.ts)

## QwikViewTransitionEvent

Emitted by qwik-core on document when the a view transition start

```typescript
export type QwikViewTransitionEvent = CustomEvent<ViewTransition>;
```

[Edit this section](https://github.com/QwikDev/qwik/tree/main/packages/qwik/src/core/shared/jsx/types/jsx-qwik-events.ts)

## QwikVisibleEvent

Emitted by qwik-loader when an element becomes visible. Used by `useVisibleTask$`
Handled by qwik-loader when an element becomes visible. Used by `useVisibleTask$`. Does not bubble.

```typescript
export type QwikVisibleEvent = CustomEvent<IntersectionObserverEntry>;
Expand Down Expand Up @@ -8728,68 +8747,14 @@ Function to extract.
## SyncQRL

```typescript
export interface SyncQRL<TYPE extends Function = any> extends QRL<TYPE>
export type SyncQRL<TYPE extends Function> = QRL<TYPE> & {
__brand__SyncQRL__: TYPE;
resolved: TYPE;
dev?: QRLDev | null;
} & BivariantQrlFn<QrlArgs<TYPE>, QrlReturn<TYPE>>;
```

**Extends:** [QRL](#qrl)&lt;TYPE&gt;

<table><thead><tr><th>

Property

</th><th>

Modifiers

</th><th>

Type

</th><th>

Description

</th></tr></thead>
<tbody><tr><td>

[\_\_brand\_\_SyncQRL\_\_](#)

</td><td>

</td><td>

TYPE

</td><td>

</td></tr>
<tr><td>

[dev](#)

</td><td>

</td><td>

QRLDev \| null

</td><td>

</td></tr>
<tr><td>

[resolved](#)

</td><td>

</td><td>

TYPE

</td><td>

</td></tr>
</tbody></table>
**References:** [QRL](#qrl)

[Edit this section](https://github.com/QwikDev/qwik/tree/main/packages/qwik/src/core/shared/qrl/qrl.public.ts)

Expand Down
36 changes: 16 additions & 20 deletions packages/docs/src/routes/demo/cookbook/drag&drop/basic/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,14 @@ export default component$(() => {
class="h-[25em] w-80 rounded-xl border-2 border-dashed border-gray-300 bg-white p-6 shadow-xs transition-all duration-300 hover:border-gray-400 [&[data-over]]:border-blue-300 [&[data-over]]:bg-blue-50"
preventdefault:dragover
preventdefault:drop
onDragOver$={sync$((_: DragEvent, currentTarget: HTMLDivElement) => {
onDragOver$={sync$((_, currentTarget) => {
currentTarget.setAttribute('data-over', 'true');
})}
onDragLeave$={sync$((_: DragEvent, currentTarget: HTMLDivElement) => {
onDragLeave$={sync$((_, currentTarget) => {
currentTarget.removeAttribute('data-over');
})}
onDrop$={[
sync$((e: DragEvent, currentTarget: HTMLDivElement) => {
sync$((e, currentTarget) => {
const id = e.dataTransfer?.getData('text');
currentTarget.dataset.droppedId = id;
currentTarget.removeAttribute('data-over');
Expand All @@ -51,14 +51,12 @@ export default component$(() => {
data-id={item.id}
class="min-h-[62px] mb-3 cursor-move select-none rounded-lg border border-gray-200 bg-white p-4 transition-all duration-200 hover:-translate-y-1 hover:shadow-md active:scale-95"
draggable
onDragStart$={sync$(
(e: DragEvent, currentTarget: HTMLDivElement) => {
const itemId = currentTarget.getAttribute('data-id');
if (e.dataTransfer && itemId) {
e.dataTransfer?.setData('text/plain', itemId);
}
onDragStart$={sync$((e, currentTarget) => {
const itemId = currentTarget.getAttribute('data-id');
if (e.dataTransfer && itemId) {
e.dataTransfer?.setData('text/plain', itemId);
}
)}
})}
>
<span class="text-lg text-gray-700">{item.content}</span>
</div>
Expand All @@ -69,14 +67,14 @@ export default component$(() => {
class="h-[25em] w-80 rounded-xl border-2 border-dashed border-gray-300 bg-white p-6 shadow-xs transition-all duration-300 hover:border-gray-400 [&[data-over]]:border-blue-300 [&[data-over]]:bg-blue-50"
preventdefault:dragover
preventdefault:drop
onDragOver$={sync$((_: DragEvent, currentTarget: HTMLDivElement) => {
onDragOver$={sync$((_, currentTarget) => {
currentTarget.setAttribute('data-over', 'true');
})}
onDragLeave$={sync$((_: DragEvent, currentTarget: HTMLDivElement) => {
onDragLeave$={sync$((_, currentTarget) => {
currentTarget.removeAttribute('data-over');
})}
onDrop$={[
sync$((e: DragEvent, currentTarget: HTMLDivElement) => {
sync$((e, currentTarget) => {
const id = e.dataTransfer?.getData('text');
currentTarget.dataset.droppedId = id;
currentTarget.removeAttribute('data-over');
Expand All @@ -101,14 +99,12 @@ export default component$(() => {
data-id={item.id}
class="min-h-[62px] mb-3 cursor-move select-none rounded-lg border border-gray-200 bg-white p-4 transition-all duration-200 hover:-translate-y-1 hover:shadow-md active:scale-95"
draggable
onDragStart$={sync$(
(e: DragEvent, currentTarget: HTMLDivElement) => {
const itemId = currentTarget.getAttribute('data-id');
if (e.dataTransfer && itemId) {
e.dataTransfer?.setData('text/plain', itemId);
}
onDragStart$={sync$((e, currentTarget) => {
const itemId = currentTarget.getAttribute('data-id');
if (e.dataTransfer && itemId) {
e.dataTransfer?.setData('text/plain', itemId);
}
)}
})}
>
<span class="text-lg text-gray-700">{item.content}</span>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ A typical way to deal with these limitations is to split the event handling into
1. `sync$()` which is called synchronously and can call methods such as `event.preventDefault()` and `event.stopPropagation()`.
2. `$()` which is called asynchronously and can close over the state and call other functions, and has no restriction on the size.

Because `sync$()` can't access the state what is the best strategy to deal with it? The answer is to use element attributes to pass state into the `sync$()` function.
Because `sync$()` can't access the state, what is the best strategy to deal with it? The answer is to use element attributes to pass state into the `sync$()` function.
> **NOTE:** If you only need to prevent the default behavior, you can simply use the standard [`preventDefault:{eventName}`](/docs/core/events/#prevent-default) syntax. This is strictly for when you need to chain events together synchronously

## Example: `sync$()` with state
Expand Down Expand Up @@ -57,7 +57,7 @@ export default component$(() => {
target="_blank"
data-should-prevent-default={shouldPreventDefault.value}
onClick$={[
sync$((e: MouseEvent, target: HTMLAnchorElement) => {
sync$((e, target) => {
if (target.hasAttribute('data-should-prevent-default')) {
e.preventDefault();
}
Expand Down
6 changes: 4 additions & 2 deletions packages/qwik/src/core/client/dom-container.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ import {
getQFuncs,
} from '../shared/utils/markers';
import { isSlotProp } from '../shared/utils/prop';
import { qDev } from '../shared/utils/qdev';
import { qDev, qTest } from '../shared/utils/qdev';
import {
convertScopedStyleIdsToArray,
convertStyleIdsToString,
Expand Down Expand Up @@ -148,7 +148,9 @@ export class DomContainer extends _SharedContainer implements IClientContainer {
this.$setServerData$();
element.setAttribute(QContainerAttr, QContainerValue.RESUMED);
element.qContainer = this;

if (!qTest && element.isConnected) {
element.dispatchEvent(new CustomEvent('qresume', { bubbles: true }));
}
const qwikStates = element.querySelectorAll('script[type="qwik/state"]');
if (qwikStates.length !== 0) {
const lastState = qwikStates[qwikStates.length - 1];
Expand Down
6 changes: 4 additions & 2 deletions packages/qwik/src/core/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -199,11 +199,13 @@ export { version } from './version';
//////////////////////////////////////////////////////////////////////////////////////////
export type {
KnownEventNames,
QwikSymbolEvent,
QwikVisibleEvent,
QwikIdleEvent,
QwikInitEvent,
QwikResumeEvent,
QwikSymbolEvent,
QwikTransitionEvent,
QwikViewTransitionEvent,
QwikVisibleEvent,
// old
NativeAnimationEvent,
NativeClipboardEvent,
Expand Down
20 changes: 11 additions & 9 deletions packages/qwik/src/core/qwik.core.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -651,7 +651,7 @@ export type QRL<TYPE = unknown> = {
getCaptured(): unknown[] | null;
getSymbol(): string;
getHash(): string;
dev: QRLDev | null;
dev?: QRLDev | null;
} & BivariantQrlFn<QrlArgs<TYPE>, QrlReturn<TYPE>>;

// @public
Expand All @@ -663,7 +663,7 @@ export const qrl: <T = any>(chunkOrFn: string | (() => Promise<any>), symbol: st
export const qrlDEV: <T = any>(chunkOrFn: string | (() => Promise<any>), symbol: string, opts: QRLDev, lexicalScopeCapture?: any[]) => QRL<T>;

// @public
export type QRLEventHandlerMulti<EV extends Event, EL> = QRL<EventHandler<EV, EL>> | undefined | null | QRLEventHandlerMulti<EV, EL>[] | EventHandler<EV, EL>;
export type QRLEventHandlerMulti<EV extends Event, EL> = QRL<EventHandler<EV, EL>> | undefined | null | QRLEventHandlerMulti<EV, EL>[];

// @internal
export const _qrlSync: <TYPE extends Function>(fn: TYPE, serializedFn?: string) => SyncQRL<TYPE>;
Expand Down Expand Up @@ -751,6 +751,9 @@ export type QwikMouseEvent<T = Element, E = NativeMouseEvent> = E;
// @public @deprecated (undocumented)
export type QwikPointerEvent<T = Element> = NativePointerEvent;

// @public
export type QwikResumeEvent = CustomEvent<{}>;

// @public @deprecated (undocumented)
export type QwikSubmitEvent<T = Element> = SubmitEvent;

Expand Down Expand Up @@ -779,6 +782,9 @@ export type QwikTransitionEvent<T = Element> = NativeTransitionEvent;
// @public @deprecated (undocumented)
export type QwikUIEvent<T = Element> = NativeUIEvent;

// @public
export type QwikViewTransitionEvent = CustomEvent<ViewTransition>;

// @public
export type QwikVisibleEvent = CustomEvent<IntersectionObserverEntry>;

Expand Down Expand Up @@ -1637,15 +1643,11 @@ export interface SVGProps<T extends Element> extends SVGAttributes, QwikAttribut
export const sync$: <T extends Function>(fn: T) => SyncQRL<T>;

// @public (undocumented)
export interface SyncQRL<TYPE extends Function = any> extends QRL<TYPE> {
// (undocumented)
export type SyncQRL<TYPE extends Function> = QRL<TYPE> & {
__brand__SyncQRL__: TYPE;
(...args: TYPE extends (...args: infer ARGS) => any ? ARGS : never): TYPE extends (...args: any[]) => infer RETURN ? RETURN : never;
// (undocumented)
dev: QRLDev | null;
// (undocumented)
resolved: TYPE;
}
dev?: QRLDev | null;
} & BivariantQrlFn<QrlArgs<TYPE>, QrlReturn<TYPE>>;

// @internal
export const _task: (_event: Event, element: Element) => void;
Expand Down
Loading