@qwik.dev/core 2.0.0-beta.27 → 2.0.0-beta.28

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/dist/core.mjs CHANGED
@@ -1,6 +1,6 @@
1
1
  /**
2
2
  * @license
3
- * @qwik.dev/core 2.0.0-beta.27-dev+7fc6984
3
+ * @qwik.dev/core 2.0.0-beta.28-dev+fac55b7
4
4
  * Copyright QwikDev. All Rights Reserved.
5
5
  * Use of this source code is governed by an MIT-style license that can be
6
6
  * found in the LICENSE file at https://github.com/QwikDev/qwik/blob/main/LICENSE
@@ -1008,7 +1008,7 @@ const COMMA = ',';
1008
1008
  *
1009
1009
  * @public
1010
1010
  */
1011
- const version = "2.0.0-beta.27-dev+7fc6984";
1011
+ const version = "2.0.0-beta.28-dev+fac55b7";
1012
1012
 
1013
1013
  // keep this import from core/build so the cjs build works
1014
1014
  const createPlatform = () => {
@@ -10235,6 +10235,211 @@ function addQwikEventToSerializationContext(serializationCtx, key, qrl) {
10235
10235
  }
10236
10236
  }
10237
10237
 
10238
+ // <docs markdown="../readme.md#useOn">
10239
+ // !!DO NOT EDIT THIS COMMENT DIRECTLY!!!
10240
+ // (edit ../readme.md#useOn instead and run `pnpm docs.sync`)
10241
+ /**
10242
+ * Register a listener on the current component's host element.
10243
+ *
10244
+ * Used to programmatically add event listeners. Useful from custom `use*` methods, which do not
10245
+ * have access to the JSX. Otherwise, it's adding a JSX listener in the `<div>` is a better idea.
10246
+ *
10247
+ * Events are case sensitive.
10248
+ *
10249
+ * @public
10250
+ * @see `useOn`, `useOnWindow`, `useOnDocument`.
10251
+ */
10252
+ // </docs>
10253
+ const useOn = (event, eventQrl) => {
10254
+ _useOn("q-e:" /* EventNameHtmlScope.on */, event, eventQrl);
10255
+ };
10256
+ // <docs markdown="../readme.md#useOnDocument">
10257
+ // !!DO NOT EDIT THIS COMMENT DIRECTLY!!!
10258
+ // (edit ../readme.md#useOnDocument instead and run `pnpm docs.sync`)
10259
+ /**
10260
+ * Register a listener on `document`.
10261
+ *
10262
+ * Used to programmatically add event listeners. Useful from custom `use*` methods, which do not
10263
+ * have access to the JSX.
10264
+ *
10265
+ * Events are case sensitive.
10266
+ *
10267
+ * @public
10268
+ * @see `useOn`, `useOnWindow`, `useOnDocument`.
10269
+ *
10270
+ * ```tsx
10271
+ * function useScroll() {
10272
+ * useOnDocument(
10273
+ * 'scroll',
10274
+ * $((event) => {
10275
+ * console.log('body scrolled', event);
10276
+ * })
10277
+ * );
10278
+ * }
10279
+ *
10280
+ * const Cmp = component$(() => {
10281
+ * useScroll();
10282
+ * return <div>Profit!</div>;
10283
+ * });
10284
+ * ```
10285
+ */
10286
+ // </docs>
10287
+ const useOnDocument = (event, eventQrl) => {
10288
+ _useOn("q-d:" /* EventNameHtmlScope.document */, event, eventQrl);
10289
+ };
10290
+ // <docs markdown="../readme.md#useOnWindow">
10291
+ // !!DO NOT EDIT THIS COMMENT DIRECTLY!!!
10292
+ // (edit ../readme.md#useOnWindow instead and run `pnpm docs.sync`)
10293
+ /**
10294
+ * Register a listener on `window`.
10295
+ *
10296
+ * Used to programmatically add event listeners. Useful from custom `use*` methods, which do not
10297
+ * have access to the JSX.
10298
+ *
10299
+ * Events are case sensitive.
10300
+ *
10301
+ * @public
10302
+ * @see `useOn`, `useOnWindow`, `useOnDocument`.
10303
+ *
10304
+ * ```tsx
10305
+ * function useAnalytics() {
10306
+ * useOnWindow(
10307
+ * 'popstate',
10308
+ * $((event) => {
10309
+ * console.log('navigation happened', event);
10310
+ * // report to analytics
10311
+ * })
10312
+ * );
10313
+ * }
10314
+ *
10315
+ * const Cmp = component$(() => {
10316
+ * useAnalytics();
10317
+ * return <div>Profit!</div>;
10318
+ * });
10319
+ * ```
10320
+ */
10321
+ // </docs>
10322
+ const useOnWindow = (event, eventQrl) => {
10323
+ _useOn("q-w:" /* EventNameHtmlScope.window */, event, eventQrl);
10324
+ };
10325
+ const _useOn = (prefix, eventName, eventQrl) => {
10326
+ const { isAdded, addEvent } = useOnEventsSequentialScope();
10327
+ if (isAdded) {
10328
+ return;
10329
+ }
10330
+ if (eventQrl) {
10331
+ if (Array.isArray(eventName)) {
10332
+ for (const event of eventName) {
10333
+ addEvent(prefix + fromCamelToKebabCase(event), eventQrl);
10334
+ }
10335
+ }
10336
+ else {
10337
+ addEvent(prefix + fromCamelToKebabCase(eventName), eventQrl);
10338
+ }
10339
+ }
10340
+ };
10341
+ /**
10342
+ * This hook is like the `useSequentialScope` but it is specifically for `useOn`. This is needed
10343
+ * because we want to execute the `useOn` hooks only once and store the event listeners on the host
10344
+ * element. From Qwik V2 the component is rerunning when the promise is thrown, so we need to make
10345
+ * sure that the event listeners are not added multiple times.
10346
+ *
10347
+ * - The event listeners are stored in the `USE_ON_LOCAL` property.
10348
+ * - The `USE_ON_LOCAL_SEQ_IDX` is used to keep track of the index of the hook that calls this.
10349
+ * - The `USE_ON_LOCAL_FLAGS` is used to keep track of whether the event listener has been added or
10350
+ * not.
10351
+ */
10352
+ const useOnEventsSequentialScope = () => {
10353
+ const iCtx = useInvokeContext();
10354
+ const hostElement = iCtx.$hostElement$;
10355
+ const host = hostElement;
10356
+ let onMap = iCtx.$container$.getHostProp(host, USE_ON_LOCAL);
10357
+ if (onMap === null) {
10358
+ onMap = {};
10359
+ iCtx.$container$.setHostProp(host, USE_ON_LOCAL, onMap);
10360
+ }
10361
+ let seqIdx = iCtx.$container$.getHostProp(host, USE_ON_LOCAL_SEQ_IDX);
10362
+ if (seqIdx === null) {
10363
+ seqIdx = 0;
10364
+ }
10365
+ iCtx.$container$.setHostProp(host, USE_ON_LOCAL_SEQ_IDX, seqIdx + 1);
10366
+ let addedFlags = iCtx.$container$.getHostProp(host, USE_ON_LOCAL_FLAGS);
10367
+ if (addedFlags === null) {
10368
+ addedFlags = [];
10369
+ iCtx.$container$.setHostProp(host, USE_ON_LOCAL_FLAGS, addedFlags);
10370
+ }
10371
+ while (addedFlags.length <= seqIdx) {
10372
+ addedFlags.push(false);
10373
+ }
10374
+ const addEvent = (eventName, eventQrl) => {
10375
+ addedFlags[seqIdx] = true;
10376
+ let events = onMap[eventName];
10377
+ if (!events) {
10378
+ onMap[eventName] = events = [];
10379
+ }
10380
+ events.push(eventQrl);
10381
+ };
10382
+ return {
10383
+ isAdded: addedFlags[seqIdx],
10384
+ addEvent,
10385
+ };
10386
+ };
10387
+
10388
+ /**
10389
+ * HMR event handler. Replaces the component QRL with a fresh one and marks dirty.
10390
+ *
10391
+ * @internal
10392
+ */
10393
+ const _hmr = (event, element) => {
10394
+ const ctx = newInvokeContextFromDOM(event, element);
10395
+ const container = ctx.$container$;
10396
+ let host = ctx.$hostElement$;
10397
+ if (!container || !host) {
10398
+ return;
10399
+ }
10400
+ // host is a VNode from vnode_locate. Walk up to the nearest component VirtualVNode
10401
+ // (the one with OnRenderProp) so we can replace its QRL and mark it dirty.
10402
+ if (!container.getHostProp(host, OnRenderProp)) {
10403
+ const parent = container.getParentHost(host);
10404
+ if (!parent) {
10405
+ return;
10406
+ }
10407
+ host = parent;
10408
+ }
10409
+ // Replace the component QRL with a fresh one to bypass caching
10410
+ // TODO use a qrl registry to invalidate all QRLs from a parent
10411
+ const oldQrl = container.getHostProp(host, OnRenderProp);
10412
+ if (oldQrl) {
10413
+ const chunk = oldQrl.$chunk$;
10414
+ const now = Date.now();
10415
+ const bustUrl = chunk.includes('?') ? chunk + '&t=' + now : chunk + '?t=' + now;
10416
+ const freshQrl = qrl(bustUrl, oldQrl.$symbol$);
10417
+ freshQrl.$container$ = container;
10418
+ freshQrl.dev = oldQrl.dev;
10419
+ container.setHostProp(host, OnRenderProp, freshQrl);
10420
+ }
10421
+ markVNodeDirty(container, host, 4 /* ChoreBits.COMPONENT */);
10422
+ };
10423
+ /** Sanitize path to a valid CSS-safe event name (no colons, dots, slashes). */
10424
+ const toEventName = (devPath) => 'qHmr' + devPath.replace(/[^a-zA-Z0-9_]/g, '_');
10425
+ let hmrQrl;
10426
+ /**
10427
+ * Injected by the optimizer into component$ bodies in HMR mode. Registers a document event listener
10428
+ * that triggers component re-render on HMR updates.
10429
+ *
10430
+ * @internal
10431
+ */
10432
+ function _useHmr(devPath) {
10433
+ const iCtx = tryGetInvokeContext();
10434
+ if (!iCtx) {
10435
+ return;
10436
+ }
10437
+ hmrQrl ||= inlinedQrl(_hmr, '_hmr');
10438
+ // The event name must be CSS-attribute-safe (no colons, dots) because
10439
+ // the qwikloader uses querySelectorAll('[q-d\\:eventName]') to find handlers.
10440
+ useOnDocument(toEventName(devPath), hmrQrl);
10441
+ }
10442
+
10238
10443
  let loading = Promise.resolve();
10239
10444
  const inflate = (container, target, typeId, data) => {
10240
10445
  if (typeId === 0 /* TypeIds.Plain */) {
@@ -12301,7 +12506,7 @@ const makeResolveFunction = (qrl, symbolFn) => {
12301
12506
  symbolRef = maybeThen(importP, (resolved) => {
12302
12507
  // We memoize the result on the symbolFn
12303
12508
  // Make sure not to memoize the wrapped function!
12304
- if (symbolFn) {
12509
+ if (!isDev && symbolFn) {
12305
12510
  symbolFn[symbol] = resolved;
12306
12511
  }
12307
12512
  return (symbolRef = qrl.resolved = bindCaptures(qrl, resolved));
@@ -13231,156 +13436,6 @@ const _useStyles = (styleQrl, transform, scoped) => {
13231
13436
  return styleId;
13232
13437
  };
13233
13438
 
13234
- // <docs markdown="../readme.md#useOn">
13235
- // !!DO NOT EDIT THIS COMMENT DIRECTLY!!!
13236
- // (edit ../readme.md#useOn instead and run `pnpm docs.sync`)
13237
- /**
13238
- * Register a listener on the current component's host element.
13239
- *
13240
- * Used to programmatically add event listeners. Useful from custom `use*` methods, which do not
13241
- * have access to the JSX. Otherwise, it's adding a JSX listener in the `<div>` is a better idea.
13242
- *
13243
- * Events are case sensitive.
13244
- *
13245
- * @public
13246
- * @see `useOn`, `useOnWindow`, `useOnDocument`.
13247
- */
13248
- // </docs>
13249
- const useOn = (event, eventQrl) => {
13250
- _useOn("q-e:" /* EventNameHtmlScope.on */, event, eventQrl);
13251
- };
13252
- // <docs markdown="../readme.md#useOnDocument">
13253
- // !!DO NOT EDIT THIS COMMENT DIRECTLY!!!
13254
- // (edit ../readme.md#useOnDocument instead and run `pnpm docs.sync`)
13255
- /**
13256
- * Register a listener on `document`.
13257
- *
13258
- * Used to programmatically add event listeners. Useful from custom `use*` methods, which do not
13259
- * have access to the JSX.
13260
- *
13261
- * Events are case sensitive.
13262
- *
13263
- * @public
13264
- * @see `useOn`, `useOnWindow`, `useOnDocument`.
13265
- *
13266
- * ```tsx
13267
- * function useScroll() {
13268
- * useOnDocument(
13269
- * 'scroll',
13270
- * $((event) => {
13271
- * console.log('body scrolled', event);
13272
- * })
13273
- * );
13274
- * }
13275
- *
13276
- * const Cmp = component$(() => {
13277
- * useScroll();
13278
- * return <div>Profit!</div>;
13279
- * });
13280
- * ```
13281
- */
13282
- // </docs>
13283
- const useOnDocument = (event, eventQrl) => {
13284
- _useOn("q-d:" /* EventNameHtmlScope.document */, event, eventQrl);
13285
- };
13286
- // <docs markdown="../readme.md#useOnWindow">
13287
- // !!DO NOT EDIT THIS COMMENT DIRECTLY!!!
13288
- // (edit ../readme.md#useOnWindow instead and run `pnpm docs.sync`)
13289
- /**
13290
- * Register a listener on `window`.
13291
- *
13292
- * Used to programmatically add event listeners. Useful from custom `use*` methods, which do not
13293
- * have access to the JSX.
13294
- *
13295
- * Events are case sensitive.
13296
- *
13297
- * @public
13298
- * @see `useOn`, `useOnWindow`, `useOnDocument`.
13299
- *
13300
- * ```tsx
13301
- * function useAnalytics() {
13302
- * useOnWindow(
13303
- * 'popstate',
13304
- * $((event) => {
13305
- * console.log('navigation happened', event);
13306
- * // report to analytics
13307
- * })
13308
- * );
13309
- * }
13310
- *
13311
- * const Cmp = component$(() => {
13312
- * useAnalytics();
13313
- * return <div>Profit!</div>;
13314
- * });
13315
- * ```
13316
- */
13317
- // </docs>
13318
- const useOnWindow = (event, eventQrl) => {
13319
- _useOn("q-w:" /* EventNameHtmlScope.window */, event, eventQrl);
13320
- };
13321
- const _useOn = (prefix, eventName, eventQrl) => {
13322
- const { isAdded, addEvent } = useOnEventsSequentialScope();
13323
- if (isAdded) {
13324
- return;
13325
- }
13326
- if (eventQrl) {
13327
- if (Array.isArray(eventName)) {
13328
- for (const event of eventName) {
13329
- addEvent(prefix + fromCamelToKebabCase(event), eventQrl);
13330
- }
13331
- }
13332
- else {
13333
- addEvent(prefix + fromCamelToKebabCase(eventName), eventQrl);
13334
- }
13335
- }
13336
- };
13337
- /**
13338
- * This hook is like the `useSequentialScope` but it is specifically for `useOn`. This is needed
13339
- * because we want to execute the `useOn` hooks only once and store the event listeners on the host
13340
- * element. From Qwik V2 the component is rerunning when the promise is thrown, so we need to make
13341
- * sure that the event listeners are not added multiple times.
13342
- *
13343
- * - The event listeners are stored in the `USE_ON_LOCAL` property.
13344
- * - The `USE_ON_LOCAL_SEQ_IDX` is used to keep track of the index of the hook that calls this.
13345
- * - The `USE_ON_LOCAL_FLAGS` is used to keep track of whether the event listener has been added or
13346
- * not.
13347
- */
13348
- const useOnEventsSequentialScope = () => {
13349
- const iCtx = useInvokeContext();
13350
- const hostElement = iCtx.$hostElement$;
13351
- const host = hostElement;
13352
- let onMap = iCtx.$container$.getHostProp(host, USE_ON_LOCAL);
13353
- if (onMap === null) {
13354
- onMap = {};
13355
- iCtx.$container$.setHostProp(host, USE_ON_LOCAL, onMap);
13356
- }
13357
- let seqIdx = iCtx.$container$.getHostProp(host, USE_ON_LOCAL_SEQ_IDX);
13358
- if (seqIdx === null) {
13359
- seqIdx = 0;
13360
- }
13361
- iCtx.$container$.setHostProp(host, USE_ON_LOCAL_SEQ_IDX, seqIdx + 1);
13362
- let addedFlags = iCtx.$container$.getHostProp(host, USE_ON_LOCAL_FLAGS);
13363
- if (addedFlags === null) {
13364
- addedFlags = [];
13365
- iCtx.$container$.setHostProp(host, USE_ON_LOCAL_FLAGS, addedFlags);
13366
- }
13367
- while (addedFlags.length <= seqIdx) {
13368
- addedFlags.push(false);
13369
- }
13370
- const addEvent = (eventName, eventQrl) => {
13371
- addedFlags[seqIdx] = true;
13372
- let events = onMap[eventName];
13373
- if (!events) {
13374
- onMap[eventName] = events = [];
13375
- }
13376
- events.push(eventQrl);
13377
- };
13378
- return {
13379
- isAdded: addedFlags[seqIdx],
13380
- addEvent,
13381
- };
13382
- };
13383
-
13384
13439
  const getSignal = (initialState) => {
13385
13440
  const value = isFunction(initialState) && !isQwikComponent(initialState)
13386
13441
  ? invoke(undefined, initialState)
@@ -13855,5 +13910,5 @@ if (import.meta.hot) {
13855
13910
  });
13856
13911
  }
13857
13912
 
13858
- export { $, Fragment, NoSerializeSymbol, PrefetchGraph, PrefetchServiceWorker, RenderOnce, Resource, SSRComment, SSRRaw, SSRStream, SSRStreamBlock, SerializerSymbol, SkipRender, Slot, _CONST_PROPS, DomContainer as _DomContainer, _EFFECT_BACK_REF, EMPTY_ARRAY as _EMPTY_ARRAY, EMPTY_OBJ as _EMPTY_OBJ, _IMMUTABLE, _SharedContainer, SubscriptionData as _SubscriptionData, _UNINITIALIZED, _VAR_PROPS, _captures, _chk, createQRL as _createQRL, _deserialize, _dumpState, _executeSsrChores, _fnSignal, _getConstProps, _getContextContainer, _getContextEvent, _getContextHostElement, getDomContainer as _getDomContainer, _getQContainerElement, _getVarProps, _hasStoreEffects, isJSXNode as _isJSXNode, isStore as _isStore, isStringifiable as _isStringifiable, isTask as _isTask, _jsxBranch, _jsxC, _jsxQ, _jsxS, _jsxSorted, _jsxSplit, mapApp_findIndx as _mapApp_findIndx, mapArray_get as _mapArray_get, mapArray_set as _mapArray_set, _noopQrl, _noopQrlDEV, preprocessState as _preprocessState, _qrlSync, qrlToString as _qrlToString, _regSymbol, _res, _resolveContextWithoutSequentialScope, _restProps, _rsc, _run, _serialize, setEvent as _setEvent, scheduleTask as _task, _val, verifySerializable as _verifySerializable, vnode_ensureElementInflated as _vnode_ensureElementInflated, vnode_getAttrKeys as _vnode_getAttrKeys, vnode_getFirstChild as _vnode_getFirstChild, vnode_isMaterialized as _vnode_isMaterialized, vnode_isTextVNode as _vnode_isTextVNode, vnode_isVirtualVNode as _vnode_isVirtualVNode, vnode_toString as _vnode_toString, _waitUntilRendered, _walkJSX, _wrapProp, _wrapSignal, component$, componentQrl, createAsync$, createAsyncSignal as createAsyncQrl, createComputed$, createComputedSignal as createComputedQrl, createContextId, h as createElement, createSerializer$, createSerializerSignal as createSerializerQrl, createSignal, event$, eventQrl, forceStoreEffects, getDomContainer, getLocale, getPlatform, h, implicit$FirstArg, inlinedQrl, inlinedQrlDEV, isSignal, jsx, jsxDEV, jsxs, noSerialize, qrl, qrlDEV, render, setPlatform, sync$, untrack, unwrapStore, useAsync$, useAsyncQrl, useComputed$, useComputedQrl, useConstant, useContext, useContextProvider, useErrorBoundary, useId, useLexicalScope, useOn, useOnDocument, useOnWindow, useResource$, useResourceQrl, useSerializer$, useSerializerQrl, useServerData, useSignal, useStore, useStyles$, useStylesQrl, useStylesScoped$, useStylesScopedQrl, useTask$, useTaskQrl, useVisibleTask$, useVisibleTaskQrl, version, withLocale };
13913
+ export { $, Fragment, NoSerializeSymbol, PrefetchGraph, PrefetchServiceWorker, RenderOnce, Resource, SSRComment, SSRRaw, SSRStream, SSRStreamBlock, SerializerSymbol, SkipRender, Slot, _CONST_PROPS, DomContainer as _DomContainer, _EFFECT_BACK_REF, EMPTY_ARRAY as _EMPTY_ARRAY, EMPTY_OBJ as _EMPTY_OBJ, _IMMUTABLE, _SharedContainer, SubscriptionData as _SubscriptionData, _UNINITIALIZED, _VAR_PROPS, _captures, _chk, createQRL as _createQRL, _deserialize, _dumpState, _executeSsrChores, _fnSignal, _getConstProps, _getContextContainer, _getContextEvent, _getContextHostElement, getDomContainer as _getDomContainer, _getQContainerElement, _getVarProps, _hasStoreEffects, _hmr, isJSXNode as _isJSXNode, isStore as _isStore, isStringifiable as _isStringifiable, isTask as _isTask, _jsxBranch, _jsxC, _jsxQ, _jsxS, _jsxSorted, _jsxSplit, mapApp_findIndx as _mapApp_findIndx, mapArray_get as _mapArray_get, mapArray_set as _mapArray_set, _noopQrl, _noopQrlDEV, preprocessState as _preprocessState, _qrlSync, qrlToString as _qrlToString, _regSymbol, _res, _resolveContextWithoutSequentialScope, _restProps, _rsc, _run, _serialize, setEvent as _setEvent, scheduleTask as _task, _useHmr, _val, verifySerializable as _verifySerializable, vnode_ensureElementInflated as _vnode_ensureElementInflated, vnode_getAttrKeys as _vnode_getAttrKeys, vnode_getFirstChild as _vnode_getFirstChild, vnode_isMaterialized as _vnode_isMaterialized, vnode_isTextVNode as _vnode_isTextVNode, vnode_isVirtualVNode as _vnode_isVirtualVNode, vnode_toString as _vnode_toString, _waitUntilRendered, _walkJSX, _wrapProp, _wrapSignal, component$, componentQrl, createAsync$, createAsyncSignal as createAsyncQrl, createComputed$, createComputedSignal as createComputedQrl, createContextId, h as createElement, createSerializer$, createSerializerSignal as createSerializerQrl, createSignal, event$, eventQrl, forceStoreEffects, getDomContainer, getLocale, getPlatform, h, implicit$FirstArg, inlinedQrl, inlinedQrlDEV, isSignal, jsx, jsxDEV, jsxs, noSerialize, qrl, qrlDEV, render, setPlatform, sync$, untrack, unwrapStore, useAsync$, useAsyncQrl, useComputed$, useComputedQrl, useConstant, useContext, useContextProvider, useErrorBoundary, useId, useLexicalScope, useOn, useOnDocument, useOnWindow, useResource$, useResourceQrl, useSerializer$, useSerializerQrl, useServerData, useSignal, useStore, useStyles$, useStylesQrl, useStylesScoped$, useStylesScopedQrl, useTask$, useTaskQrl, useVisibleTask$, useVisibleTaskQrl, version, withLocale };
13859
13914
  //# sourceMappingURL=core.mjs.map