@qwik.dev/core 2.0.0-beta.2 → 2.0.0-beta.23

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.
Files changed (136) hide show
  1. package/bindings/qwik.darwin-arm64.node +0 -0
  2. package/bindings/qwik.linux-x64-gnu.node +0 -0
  3. package/bindings/qwik.win32-x64-msvc.node +0 -0
  4. package/bindings/qwik_wasm_bg.wasm +0 -0
  5. package/dist/backpatch/index.d.ts +2 -0
  6. package/dist/backpatch/index.mjs +5 -0
  7. package/dist/backpatch/package.json +8 -0
  8. package/dist/backpatch-executor.debug.js +39 -0
  9. package/dist/backpatch-executor.js +1 -0
  10. package/dist/build/package.json +1 -1
  11. package/dist/cli.mjs +12953 -0
  12. package/dist/core-internal.d.ts +894 -511
  13. package/dist/core.min.mjs +1 -1
  14. package/dist/core.mjs +10207 -8327
  15. package/dist/core.mjs.map +1 -1
  16. package/dist/core.prod.mjs +5848 -4637
  17. package/dist/insights/vite/index.mjs +10 -10
  18. package/dist/loader/index.mjs +2 -2
  19. package/dist/loader/package.json +1 -1
  20. package/dist/optimizer.d.ts +16 -38
  21. package/dist/optimizer.mjs +2607 -3719
  22. package/dist/preloader.mjs +8 -11
  23. package/dist/qwikloader.debug.js +152 -132
  24. package/dist/qwikloader.js +1 -1
  25. package/dist/server.d.ts +38 -15
  26. package/dist/server.mjs +1224 -927
  27. package/dist/starters/adapters/aws-lambda/adapters/aws-lambda/{vite.config.mts → vite.config.ts} +2 -2
  28. package/dist/starters/adapters/aws-lambda/package.json +3 -2
  29. package/dist/starters/adapters/aws-lambda/src/entry_aws-lambda.tsx +2 -6
  30. package/dist/starters/adapters/azure-swa/adapters/azure-swa/{vite.config.mts → vite.config.ts} +2 -2
  31. package/dist/starters/adapters/azure-swa/package.json +3 -2
  32. package/dist/starters/adapters/azure-swa/src/entry.azure-swa.tsx +2 -3
  33. package/dist/starters/adapters/bun/adapters/bun/{vite.config.mts → vite.config.ts} +3 -3
  34. package/dist/starters/adapters/bun/package.json +3 -2
  35. package/dist/starters/adapters/bun/src/entry.bun.ts +0 -2
  36. package/dist/starters/adapters/cloud-run/adapters/cloud-run/{vite.config.mts → vite.config.ts} +2 -2
  37. package/dist/starters/adapters/cloud-run/package.json +3 -2
  38. package/dist/starters/adapters/cloud-run/src/entry.cloud-run.tsx +1 -3
  39. package/dist/starters/adapters/cloudflare-pages/adapters/cloudflare-pages/{vite.config.mts → vite.config.ts} +2 -2
  40. package/dist/starters/adapters/cloudflare-pages/package.json +3 -2
  41. package/dist/starters/adapters/cloudflare-pages/src/entry.cloudflare-pages.tsx +2 -3
  42. package/dist/starters/adapters/cloudflare-workers/README.md +52 -0
  43. package/dist/starters/adapters/cloudflare-workers/adapters/cloudflare-workers/vite.config.ts +15 -0
  44. package/dist/starters/adapters/cloudflare-workers/gitignore +3 -0
  45. package/dist/starters/adapters/cloudflare-workers/package.json +31 -0
  46. package/dist/starters/adapters/cloudflare-workers/public/.assetsignore +4 -0
  47. package/dist/starters/adapters/cloudflare-workers/public/_headers +11 -0
  48. package/dist/starters/adapters/cloudflare-workers/public/_redirects +1 -0
  49. package/dist/starters/adapters/cloudflare-workers/src/entry.cloudflare-pages.tsx +23 -0
  50. package/dist/starters/adapters/cloudflare-workers/worker-configuration.d.ts +5 -0
  51. package/dist/starters/adapters/cloudflare-workers/wrangler.jsonc +41 -0
  52. package/dist/starters/adapters/deno/adapters/deno/{vite.config.mts → vite.config.ts} +2 -2
  53. package/dist/starters/adapters/deno/package.json +3 -2
  54. package/dist/starters/adapters/deno/src/entry.deno.ts +0 -2
  55. package/dist/starters/adapters/express/adapters/express/{vite.config.mts → vite.config.ts} +2 -2
  56. package/dist/starters/adapters/express/package.json +4 -3
  57. package/dist/starters/adapters/express/src/entry.express.tsx +1 -3
  58. package/dist/starters/adapters/fastify/adapters/fastify/{vite.config.mts → vite.config.ts} +2 -2
  59. package/dist/starters/adapters/fastify/package.json +3 -2
  60. package/dist/starters/adapters/fastify/src/entry.fastify.tsx +1 -1
  61. package/dist/starters/adapters/fastify/src/plugins/fastify-qwik.ts +1 -2
  62. package/dist/starters/adapters/firebase/adapters/firebase/{vite.config.mts → vite.config.ts} +2 -2
  63. package/dist/starters/adapters/firebase/package.json +3 -2
  64. package/dist/starters/adapters/firebase/src/entry-firebase.tsx +2 -3
  65. package/dist/starters/adapters/netlify-edge/adapters/netlify-edge/{vite.config.mts → vite.config.ts} +2 -2
  66. package/dist/starters/adapters/netlify-edge/package.json +3 -2
  67. package/dist/starters/adapters/netlify-edge/src/entry.netlify-edge.tsx +2 -3
  68. package/dist/starters/adapters/node-server/adapters/node-server/{vite.config.mts → vite.config.ts} +2 -2
  69. package/dist/starters/adapters/node-server/package.json +3 -2
  70. package/dist/starters/adapters/node-server/src/entry.node-server.tsx +0 -2
  71. package/dist/starters/adapters/{static/adapters/static/vite.config.mts → ssg/adapters/ssg/vite.config.ts} +3 -3
  72. package/dist/starters/adapters/ssg/package.json +20 -0
  73. package/dist/starters/adapters/vercel-edge/README.md +2 -2
  74. package/dist/starters/adapters/vercel-edge/adapters/vercel-edge/{vite.config.mts → vite.config.ts} +2 -2
  75. package/dist/starters/adapters/vercel-edge/package.json +3 -2
  76. package/dist/starters/adapters/vercel-edge/src/entry.vercel-edge.tsx +2 -3
  77. package/dist/starters/adapters/vercel-edge/vercel.json +1 -1
  78. package/dist/starters/features/auth/package.json +1 -1
  79. package/dist/starters/features/compiled-i18n/package.json +37 -0
  80. package/dist/starters/features/compiled-i18n/src/components/locale-selector/locale-selector.tsx +30 -0
  81. package/dist/starters/features/compiled-i18n/src/entry.ssr.tsx +31 -0
  82. package/dist/starters/features/compiled-i18n/src/routes/plugin@compiled-i18n.ts +28 -0
  83. package/dist/starters/features/csr/index.html +23 -0
  84. package/dist/starters/features/csr/package.json +29 -0
  85. package/dist/starters/features/csr/src/root.tsx +15 -0
  86. package/dist/starters/features/csr/vite.config.ts +13 -0
  87. package/dist/starters/features/cypress/src/actions/example.action.ts +5 -0
  88. package/dist/starters/features/cypress/src/components/example/example.cy.tsx +50 -8
  89. package/dist/starters/features/cypress/src/components/example/example.tsx +13 -3
  90. package/dist/starters/features/cypress/src/loaders/example.loader.ts +5 -0
  91. package/dist/starters/features/pandacss/package.json +1 -1
  92. package/dist/starters/features/playwright/playwright-report/index.html +953 -930
  93. package/dist/starters/features/postcss/postcss.config.js +1 -1
  94. package/dist/starters/features/storybook/.storybook/tsconfig.json +0 -1
  95. package/dist/starters/features/styled-vanilla-extract/package.json +2 -1
  96. package/dist/starters/features/tailwind/package.json +2 -2
  97. package/dist/starters/features/tailwind/prettier.config.js +10 -0
  98. package/dist/starters/features/tailwind-v3/package.json +1 -1
  99. package/dist/starters/features/tailwind-v3/prettier.config.js +10 -0
  100. package/dist/testing/index.d.ts +809 -6
  101. package/dist/testing/index.mjs +14880 -11342
  102. package/dist/testing/package.json +1 -1
  103. package/handlers.mjs +1 -1
  104. package/package.json +30 -55
  105. package/public.d.ts +3 -1
  106. package/{qwik-cli.cjs → qwik-cli.mjs} +1 -1
  107. package/server.d.ts +2 -0
  108. package/bindings/qwik.darwin-x64.node +0 -0
  109. package/bindings/qwik.wasm.cjs +0 -471
  110. package/dist/build/index.cjs +0 -35
  111. package/dist/build/index.cjs.map +0 -7
  112. package/dist/build/index.dev.cjs +0 -37
  113. package/dist/build/index.dev.cjs.map +0 -7
  114. package/dist/build/index.prod.cjs +0 -37
  115. package/dist/build/index.prod.cjs.map +0 -7
  116. package/dist/cli.cjs +0 -5545
  117. package/dist/core.cjs +0 -11754
  118. package/dist/core.cjs.map +0 -1
  119. package/dist/core.prod.cjs +0 -5647
  120. package/dist/insights/index.qwik.cjs +0 -1
  121. package/dist/insights/vite/index.cjs +0 -1
  122. package/dist/loader/index.cjs +0 -4
  123. package/dist/optimizer.cjs +0 -4020
  124. package/dist/preloader.cjs +0 -269
  125. package/dist/server.cjs +0 -3027
  126. package/dist/starters/adapters/static/package.json +0 -19
  127. package/dist/starters/features/localize/package.json +0 -37
  128. package/dist/starters/features/localize/src/entry.ssr.tsx +0 -30
  129. package/dist/starters/features/localize/src/locales/message.en.json +0 -8
  130. package/dist/starters/features/localize/src/locales/message.it.json +0 -8
  131. package/dist/starters/features/localize/src/routes/[locale]/i18n-utils.ts +0 -94
  132. package/dist/starters/features/localize/src/routes/[locale]/index.tsx +0 -52
  133. package/dist/starters/features/localize/src/routes/[locale]/layout.tsx +0 -12
  134. package/dist/starters/features/tailwind/.prettierrc.js +0 -3
  135. package/dist/testing/index.cjs +0 -33287
  136. /package/dist/starters/adapters/{static → ssg}/README.md +0 -0
@@ -1,4 +1,5 @@
1
- import { ClientContainer } from '../internal';
1
+ import { ClientContainer } from '..';
2
+ import type { ClientContainer as ClientContainer_2 } from '../internal';
2
3
  import type { CorePlatform } from '..';
3
4
  import type { _DomContainer } from '../internal';
4
5
  import type { _ElementVNode } from '../internal';
@@ -10,6 +11,200 @@ import type { _Stringifiable } from '../internal';
10
11
  import type { _VirtualVNode } from '../internal';
11
12
  import type { _VNode } from '../internal';
12
13
 
14
+ declare interface AddRootFn {
15
+ (obj: unknown, returnRef?: never): number;
16
+ (obj: unknown, returnRef: true): SeenRef;
17
+ }
18
+
19
+ declare type AllSignalFlags = SignalFlags | WrappedSignalFlags | SerializationSignalFlags | AsyncSignalFlags;
20
+
21
+ /** @public */
22
+ declare interface AsyncSignal<T = unknown> extends ComputedSignal<T> {
23
+ /**
24
+ * Whether the signal is currently loading. This will trigger lazy loading of the signal, so you
25
+ * can use it like this:
26
+ *
27
+ * ```tsx
28
+ * signal.loading ? <Loading /> : signal.error ? <Error /> : <Component
29
+ * value={signal.value} />
30
+ * ```
31
+ */
32
+ loading: boolean;
33
+ /**
34
+ * The error that occurred while computing the signal, if any. This will be cleared when the
35
+ * signal is successfully computed.
36
+ */
37
+ error: Error | undefined;
38
+ /**
39
+ * Poll interval in ms. Writable and immediately effective when the signal has consumers. If set
40
+ * to `0`, polling stops.
41
+ */
42
+ interval: number;
43
+ /** A promise that resolves when the value is computed or rejected. */
44
+ promise(): Promise<void>;
45
+ /** Abort the current computation and run cleanups if needed. */
46
+ abort(reason?: any): void;
47
+ }
48
+
49
+ declare const enum AsyncSignalFlags {
50
+ EAGER_CLEANUP = 32,
51
+ AWAIT_PREVIOUS = 64
52
+ }
53
+
54
+ /** Class for back reference to the EffectSubscription */
55
+ declare abstract class BackRef {
56
+ [_EFFECT_BACK_REF]: Map<any, any> | undefined;
57
+ }
58
+
59
+ declare type BivariantQrlFn<ARGS extends any[], RETURN> = {
60
+ /**
61
+ * Resolve the QRL of closure and invoke it.
62
+ *
63
+ * @param args - Closure arguments.
64
+ * @returns A promise of the return value of the closure.
65
+ */
66
+ bivarianceHack(...args: ARGS): Promise<RETURN>;
67
+ }['bivarianceHack'];
68
+
69
+ declare const enum ChoreBits {
70
+ NONE = 0,
71
+ TASKS = 1,
72
+ NODE_DIFF = 2,
73
+ COMPONENT = 4,
74
+ NODE_PROPS = 8,
75
+ COMPUTE = 16,
76
+ CHILDREN = 32,
77
+ CLEANUP = 64,
78
+ DIRTY_MASK = 127
79
+ }
80
+
81
+ /**
82
+ * A computed signal is a signal which is calculated from other signals. When the signals change,
83
+ * the computed signal is recalculated, and if the result changed, all tasks which are tracking the
84
+ * signal will be re-run and all components that read the signal will be re-rendered.
85
+ *
86
+ * @public
87
+ */
88
+ declare interface ComputedSignal<T> extends ReadonlySignal<T> {
89
+ /**
90
+ * Use this to force running subscribers, for example when the calculated value mutates but
91
+ * remains the same object.
92
+ */
93
+ force(): void;
94
+ /**
95
+ * Use this to force recalculation and running subscribers, for example when the calculated value
96
+ * mutates but remains the same object.
97
+ */
98
+ invalidate(): void;
99
+ }
100
+
101
+ /**
102
+ * Effect is something which needs to happen (side-effect) due to signal value change.
103
+ *
104
+ * There are three types of effects:
105
+ *
106
+ * - `Task`: `useTask`, `useVisibleTask`, `useResource`
107
+ * - `VNode` and `ISsrNode`: Either a component or `<Signal>`
108
+ * - `Signal2`: A derived signal which contains a computation function.
109
+ */
110
+ declare type Consumer = Task | VNode | SignalImpl | ISsrNode;
111
+
112
+ /** @internal */
113
+ declare interface Container {
114
+ readonly $version$: string;
115
+ readonly $storeProxyMap$: ObjToProxyMap;
116
+ readonly $locale$: string;
117
+ readonly $getObjectById$: (id: number | string) => any;
118
+ readonly $serverData$: Record<string, any>;
119
+ $currentUniqueId$: number;
120
+ $buildBase$: string | null;
121
+ $renderPromise$: Promise<void> | null;
122
+ $resolveRenderPromise$: (() => void) | null;
123
+ $pendingCount$: number;
124
+ $checkPendingCount$(): void;
125
+ handleError(err: any, $host$: HostElement | null): void;
126
+ getParentHost(host: HostElement): HostElement | null;
127
+ setContext<T>(host: HostElement, context: ContextId<T>, value: T): void;
128
+ resolveContext<T>(host: HostElement, contextId: ContextId<T>): T | undefined;
129
+ setHostProp<T>(host: HostElement, name: string, value: T): void;
130
+ getHostProp<T>(host: HostElement, name: string): T | null;
131
+ $appendStyle$(content: string, styleId: string, host: HostElement, scoped: boolean): void;
132
+ /**
133
+ * When component is about to be executed, it may add/remove children. This can cause problems
134
+ * with the projection because deleting content will prevent the projection references from
135
+ * looking up vnodes. Therefore before we execute the component we need to ensure that all of its
136
+ * references to vnode are resolved.
137
+ *
138
+ * @param renderHost - Host element to ensure projection is resolved.
139
+ */
140
+ ensureProjectionResolved(host: HostElement): void;
141
+ serializationCtxFactory(NodeConstructor: {
142
+ new (...rest: any[]): {
143
+ __brand__: 'SsrNode';
144
+ };
145
+ } | null, DomRefConstructor: {
146
+ new (...rest: any[]): {
147
+ __brand__: 'DomRef';
148
+ };
149
+ } | null, symbolToChunkResolver: SymbolToChunkResolver, writer?: StreamWriter): SerializationContext;
150
+ }
151
+
152
+ /**
153
+ * ContextId is a typesafe ID for your context.
154
+ *
155
+ * Context is a way to pass stores to the child components without prop-drilling.
156
+ *
157
+ * Use `createContextId()` to create a `ContextId`. A `ContextId` is just a serializable identifier
158
+ * for the context. It is not the context value itself. See `useContextProvider()` and
159
+ * `useContext()` for the values. Qwik needs a serializable ID for the context so that the it can
160
+ * track context providers and consumers in a way that survives resumability.
161
+ *
162
+ * ### Example
163
+ *
164
+ * ```tsx
165
+ * // Declare the Context type.
166
+ * interface TodosStore {
167
+ * items: string[];
168
+ * }
169
+ * // Create a Context ID (no data is saved here.)
170
+ * // You will use this ID to both create and retrieve the Context.
171
+ * export const TodosContext = createContextId<TodosStore>('Todos');
172
+ *
173
+ * // Example of providing context to child components.
174
+ * export const App = component$(() => {
175
+ * useContextProvider(
176
+ * TodosContext,
177
+ * useStore<TodosStore>({
178
+ * items: ['Learn Qwik', 'Build Qwik app', 'Profit'],
179
+ * })
180
+ * );
181
+ *
182
+ * return <Items />;
183
+ * });
184
+ *
185
+ * // Example of retrieving the context provided by a parent component.
186
+ * export const Items = component$(() => {
187
+ * const todos = useContext(TodosContext);
188
+ * return (
189
+ * <ul>
190
+ * {todos.items.map((item) => (
191
+ * <li>{item}</li>
192
+ * ))}
193
+ * </ul>
194
+ * );
195
+ * });
196
+ *
197
+ * ```
198
+ *
199
+ * @public
200
+ */
201
+ declare interface ContextId<STATE> {
202
+ /** Design-time property to store type information for the context. */
203
+ readonly __brand_context_type__: STATE;
204
+ /** A unique ID for the context. */
205
+ readonly id: string;
206
+ }
207
+
13
208
  /**
14
209
  * Create emulated `Document` for server environment. Does not implement the full browser `document`
15
210
  * and `window` API. This api may be removed in the future.
@@ -31,6 +226,19 @@ export declare const createDOM: ({ html }?: {
31
226
  userEvent: (queryOrElement: string | Element | keyof HTMLElementTagNameMap | null, eventNameCamel: string | keyof WindowEventMap, eventPayload?: any) => Promise<void>;
32
227
  }>;
33
228
 
229
+ declare interface DescriptorBase<T = unknown, B = unknown> extends BackRef {
230
+ $flags$: number;
231
+ $index$: number;
232
+ $el$: HostElement;
233
+ $qrl$: QRLInternal<T>;
234
+ $state$: B | undefined;
235
+ $destroy$: (() => void) | null;
236
+ }
237
+
238
+ declare type DomRef = {
239
+ $ssrNode$: SsrNode;
240
+ };
241
+
34
242
  /** @public */
35
243
  export declare function domRender(jsx: JSXOutput, opts?: {
36
244
  debug?: boolean;
@@ -41,6 +249,58 @@ export declare function domRender(jsx: JSXOutput, opts?: {
41
249
  getStyles: () => Record<string, string | string[]>;
42
250
  }>;
43
251
 
252
+ /** @internal */
253
+ declare const _EFFECT_BACK_REF: unique symbol;
254
+
255
+ declare const enum EffectProperty {
256
+ COMPONENT = ":",
257
+ VNODE = "."
258
+ }
259
+
260
+ /**
261
+ * An effect consumer plus type of effect, back references to producers and additional data
262
+ *
263
+ * An effect can be trigger by one or more of signal inputs. The first step of re-running an effect
264
+ * is to clear its subscriptions so that the effect can re add new set of subscriptions. In order to
265
+ * clear the subscriptions we need to store them here.
266
+ *
267
+ * Imagine you have effect such as:
268
+ *
269
+ * ```
270
+ * function effect1() {
271
+ * console.log(signalA.value ? signalB.value : 'default');
272
+ * }
273
+ * ```
274
+ *
275
+ * In the above case the `signalB` needs to be unsubscribed when `signalA` is falsy. We do this by
276
+ * always clearing all of the subscriptions
277
+ *
278
+ * The `EffectSubscription` stores
279
+ *
280
+ * ```
281
+ * subscription1 = [effectConsumer1, EffectProperty.COMPONENT, Set[(signalA, signalB)]];
282
+ * ```
283
+ *
284
+ * The `signal1` and `signal2` back references are needed to "clear" existing subscriptions.
285
+ *
286
+ * Both `signalA` as well as `signalB` will have a reference to `subscription` to the so that the
287
+ * effect can be scheduled if either `signalA` or `signalB` triggers. The `subscription1` is shared
288
+ * between the signals.
289
+ *
290
+ * The second position `EffectProperty|string` store the property name of the effect.
291
+ *
292
+ * - Property name of the VNode
293
+ * - `EffectProperty.COMPONENT` if component
294
+ * - `EffectProperty.VNODE` if VNode
295
+ */
296
+ declare class EffectSubscription {
297
+ consumer: Consumer;
298
+ property: EffectProperty | string;
299
+ backRef: Set<SignalImpl | StoreTarget> | null;
300
+ data: SubscriptionData | null;
301
+ constructor(consumer: Consumer, property: EffectProperty | string, backRef?: Set<SignalImpl | StoreTarget> | null, data?: SubscriptionData | null);
302
+ }
303
+
44
304
  /**
45
305
  * Creates a simple DOM structure for testing components.
46
306
  *
@@ -79,6 +339,33 @@ export declare function expectDOM(actual: Element, expected: string): Promise<vo
79
339
  /** @public */
80
340
  export declare function getTestPlatform(): TestPlatform;
81
341
 
342
+ declare type HostElement = VNode | ISsrNode;
343
+
344
+ /** The shared state during an invoke() call */
345
+ declare interface InvokeContext {
346
+ /** The Virtual parent component for the current component code */
347
+ $hostElement$: HostElement | undefined;
348
+ /** The event we're currently handling */
349
+ $event$: PossibleEvents | undefined;
350
+ $effectSubscriber$: EffectSubscription | undefined;
351
+ $locale$: string | undefined;
352
+ $container$: Container | undefined;
353
+ }
354
+
355
+ declare interface ISsrNode {
356
+ id: string;
357
+ flags: SsrNodeFlags;
358
+ dirty: ChoreBits;
359
+ parentComponent: ISsrNode | null;
360
+ vnodeData: VNodeData;
361
+ currentFile: string | null;
362
+ setProp(name: string, value: any): void;
363
+ getProp(name: string): any;
364
+ removeProp(name: string): void;
365
+ addChild(child: ISsrNode): void;
366
+ setTreeNonUpdatable(): void;
367
+ }
368
+
82
369
  /** @public */
83
370
  declare interface MockDocument extends Document {
84
371
  }
@@ -98,39 +385,535 @@ declare interface MockWindow extends Window {
98
385
  document: MockDocument;
99
386
  }
100
387
 
388
+ declare interface NodePropData {
389
+ $scopedStyleIdPrefix$: string | null;
390
+ $isConst$: boolean;
391
+ }
392
+
393
+ declare type ObjToProxyMap = WeakMap<any, any>;
394
+
395
+ declare type PossibleEvents = Event | SimplifiedServerRequestEvent | typeof TaskEvent | typeof RenderEvent;
396
+
397
+ declare type Props = Record<string, unknown>;
398
+
399
+ /**
400
+ * The `QRL` type represents a lazy-loadable AND serializable resource.
401
+ *
402
+ * QRL stands for Qwik URL.
403
+ *
404
+ * Use `QRL` when you want to refer to a lazy-loaded resource. `QRL`s are most often used for code
405
+ * (functions) but can also be used for other resources such as `string`s in the case of styles.
406
+ *
407
+ * `QRL` is an opaque token that is generated by the Qwik Optimizer. (Do not rely on any properties
408
+ * in `QRL` as it may change between versions.)
409
+ *
410
+ * ## Creating `QRL` references
411
+ *
412
+ * Creating `QRL` is done using `$(...)` function. `$(...)` is a special marker for the Qwik
413
+ * Optimizer that marks that the code should be extracted into a lazy-loaded symbol.
414
+ *
415
+ * ```tsx
416
+ * useOnDocument(
417
+ * 'mousemove',
418
+ * $((event) => console.log('mousemove', event))
419
+ * );
420
+ * ```
421
+ *
422
+ * In the above code, the Qwik Optimizer detects `$(...)` and transforms the code as shown below:
423
+ *
424
+ * ```tsx
425
+ * // FILE: <current file>
426
+ * useOnDocument('mousemove', qrl('./chunk-abc.js', 'onMousemove'));
427
+ *
428
+ * // FILE: chunk-abc.js
429
+ * export const onMousemove = () => console.log('mousemove');
430
+ * ```
431
+ *
432
+ * NOTE: `qrl(...)` is a result of Qwik Optimizer transformation. You should never have to invoke
433
+ * this function directly in your application. The `qrl(...)` function should be invoked only after
434
+ * the Qwik Optimizer transformation.
435
+ *
436
+ * ## Using `QRL`s
437
+ *
438
+ * Use `QRL` type in your application when you want to get a lazy-loadable reference to a resource
439
+ * (most likely a function).
440
+ *
441
+ * ```tsx
442
+ * // Example of declaring a custom functions which takes callback as QRL.
443
+ * export function useMyFunction(callback: QRL<() => void>) {
444
+ * doExtraStuff();
445
+ * // The callback passed to `onDocument` requires `QRL`.
446
+ * useOnDocument('mousemove', callback);
447
+ * }
448
+ * ```
449
+ *
450
+ * In the above example, the way to think about the code is that you are not asking for a callback
451
+ * function but rather a reference to a lazy-loadable callback function. Specifically, the function
452
+ * loading should be delayed until it is actually needed. In the above example, the function would
453
+ * not load until after a `mousemove` event on `document` fires.
454
+ *
455
+ * ## Resolving `QRL` references
456
+ *
457
+ * At times it may be necessary to resolve a `QRL` reference to the actual value. This can be
458
+ * performed using `QRL.resolve(..)` function.
459
+ *
460
+ * ```tsx
461
+ * // Assume you have QRL reference to a greet function
462
+ * const lazyGreet: QRL<() => void> = $(() => console.log('Hello World!'));
463
+ *
464
+ * // Use `qrlImport` to load / resolve the reference.
465
+ * const greet: () => void = await lazyGreet.resolve();
466
+ *
467
+ * // Invoke it
468
+ * greet();
469
+ * ```
470
+ *
471
+ * NOTE: `element` is needed because `QRL`s are relative and need a base location to resolve
472
+ * against. The base location is encoded in the HTML in the form of `<div q:base="/url">`.
473
+ *
474
+ * ## `QRL.resolved`
475
+ *
476
+ * Once `QRL.resolve()` returns, the value is stored under `QRL.resolved`. This allows the value to
477
+ * be used without having to await `QRL.resolve()` again.
478
+ *
479
+ * ## Question: Why not just use `import()`?
480
+ *
481
+ * At first glance, `QRL` serves the same purpose as `import()`. However, there are three subtle
482
+ * differences that need to be taken into account.
483
+ *
484
+ * 1. `QRL`s must be serializable into HTML.
485
+ * 2. `QRL`s must be resolved by framework relative to `q:base`.
486
+ * 3. `QRL`s must be able to capture lexically scoped variables.
487
+ * 4. `QRL`s encapsulate the difference between running with and without Qwik Optimizer.
488
+ * 5. `QRL`s allow expressing lazy-loaded boundaries without thinking about chunk and symbol names.
489
+ *
490
+ * Let's assume that you intend to write code such as this:
491
+ *
492
+ * ```tsx
493
+ * return <button onClick={() => (await import('./chunk-abc.js')).onClick}>
494
+ * ```
495
+ *
496
+ * The above code needs to be serialized into DOM such as:
497
+ *
498
+ * ```
499
+ * <div q:base="/build/">
500
+ * <button q-e:click="./chunk-abc.js#onClick">...</button>
501
+ * </div>
502
+ * ```
503
+ *
504
+ * 1. Notice there is no easy way to extract chunk (`./chunk-abc.js`) and symbol (`onClick`) into HTML.
505
+ * 2. Notice that even if you could extract it, the `import('./chunk-abc.js')` would become relative to
506
+ * where the `import()` file is declared. Because it is our framework doing the load, the
507
+ * `./chunk-abc.js` would become relative to the framework file. This is not correct, as it
508
+ * should be relative to the original file generated by the bundler.
509
+ * 3. Next, the framework needs to resolve the `./chunk-abc.js` and needs a base location that is
510
+ * encoded in the HTML.
511
+ * 4. The QRL needs to be able to capture lexically scoped variables. (`import()` only allows loading
512
+ * top-level symbols which don't capture variables.)
513
+ * 5. As a developer, you don't want to think about `import` and naming the chunks and symbols. You
514
+ * just want to say: "this should be lazy."
515
+ *
516
+ * These are the main reasons why Qwik introduces its own concept of `QRL`.
517
+ *
518
+ * @public
519
+ * @see `$`
520
+ */
521
+ declare type QRL<TYPE = unknown> = {
522
+ __qwik_serializable__?: any;
523
+ __brand__QRL__?: TYPE;
524
+ /** Resolve the QRL and return the actual value. */
525
+ resolve(): Promise<TYPE>;
526
+ /** The resolved value, once `resolve()` returns. */
527
+ resolved: undefined | TYPE;
528
+ getCaptured(): unknown[] | null;
529
+ getSymbol(): string;
530
+ getHash(): string;
531
+ dev?: QRLDev | null;
532
+ } & BivariantQrlFn<QrlArgs<TYPE>, QrlReturn<TYPE>>;
533
+
534
+ declare type QrlArgs<T> = T extends (...args: infer ARGS) => any ? ARGS : unknown[];
535
+
536
+ /** @public */
537
+ declare interface QRLDev {
538
+ file: string;
539
+ lo: number;
540
+ hi: number;
541
+ }
542
+
543
+ /** @internal */
544
+ declare type QRLInternal<TYPE = unknown> = QRL<TYPE> & QRLInternalMethods<TYPE>;
545
+
546
+ declare type QRLInternalMethods<TYPE> = {
547
+ readonly $chunk$: string | null;
548
+ readonly $symbol$: string;
549
+ readonly $hash$: string;
550
+ /** If it's a string it's serialized */
551
+ $captures$: Readonly<unknown[]> | string | null;
552
+ dev: QRLDev | null;
553
+ resolve(container?: Container): Promise<TYPE>;
554
+ resolved: undefined | TYPE;
555
+ getSymbol(): string;
556
+ getHash(): string;
557
+ getCaptured(): unknown[] | null;
558
+ getFn(currentCtx?: InvokeContext, beforeFn?: () => void): TYPE extends (...args: any) => any ? (...args: Parameters<TYPE>) => ValueOrPromise<ReturnType<TYPE>> : unknown;
559
+ /**
560
+ * Needed for deserialization and importing. We don't always have the container while creating
561
+ * qrls in async sections of code
562
+ */
563
+ $container$: Container | null;
564
+ /** Only in dev mode */
565
+ $symbolRef$?: null | ValueOrPromise<TYPE>;
566
+ };
567
+
568
+ declare type QrlReturn<T> = T extends (...args: any) => infer R ? Awaited<R> : unknown;
569
+
570
+ /** @public */
571
+ declare interface ReadonlySignal<T = unknown> {
572
+ readonly value: T;
573
+ }
574
+
575
+ declare const RenderEvent = "qRender";
576
+
577
+ declare interface ResourceReturnInternal<T> {
578
+ __brand: 'resource';
579
+ value: Promise<T>;
580
+ loading: boolean;
581
+ signal: AsyncSignal<{
582
+ r: T;
583
+ }>;
584
+ }
585
+
586
+ /** Stores the location of an object. If no parent, it's a root. */
587
+ declare type SeenRef = {
588
+ $index$: number;
589
+ $parent$?: SeenRef | null;
590
+ };
591
+
592
+ declare interface SerializationContext {
593
+ $serialize$: () => ValueOrPromise<void>;
594
+ $symbolToChunkResolver$: SymbolToChunkResolver;
595
+ /**
596
+ * Map from object to parent and index reference.
597
+ *
598
+ * If object is found in `objMap` will return the parent reference and index path.
599
+ *
600
+ * `objMap` return:
601
+ *
602
+ * - `{ parent, index }` - The parent object and the index within that parent.
603
+ * - `undefined` - Object has not been seen yet.
604
+ */
605
+ getSeenRef: (obj: unknown) => SeenRef | undefined;
606
+ /** Returns the root index of the object, if it is a root. Otherwise returns undefined. */
607
+ $hasRootId$: (obj: unknown) => number | undefined;
608
+ /**
609
+ * Root objects which need to be serialized.
610
+ *
611
+ * Roots are entry points into the object graph. Typically the roots are held by the listeners.
612
+ *
613
+ * Returns the index of the root object.
614
+ */
615
+ $addRoot$: AddRootFn;
616
+ /** Mark an object as seen during serialization. This is used to handle backreferences and cycles */
617
+ $markSeen$: (obj: unknown, parent: SeenRef | undefined, index: number) => SeenRef;
618
+ $roots$: unknown[];
619
+ $promoteToRoot$: (ref: SeenRef, index?: number) => void;
620
+ $addSyncFn$($funcStr$: string | null, argsCount: number, fn: Function): number;
621
+ $isSsrNode$: (obj: unknown) => obj is SsrNode;
622
+ $isDomRef$: (obj: unknown) => obj is DomRef;
623
+ $writer$: StreamWriter;
624
+ $syncFns$: string[];
625
+ $eventQrls$: Set<QRL>;
626
+ $eventNames$: Set<string>;
627
+ $renderSymbols$: Set<string>;
628
+ $storeProxyMap$: ObjToProxyMap;
629
+ $eagerResume$: Set<unknown>;
630
+ $resources$: Set<ResourceReturnInternal<any>>;
631
+ $getProp$: (obj: any, prop: string) => any;
632
+ $setProp$: (obj: any, prop: string, value: any) => void;
633
+ }
634
+
635
+ declare const enum SerializationSignalFlags {
636
+ SERIALIZATION_STRATEGY_NEVER = 8,
637
+ SERIALIZATION_STRATEGY_ALWAYS = 16
638
+ }
639
+
640
+ /**
641
+ * A signal is a reactive value which can be read and written. When the signal is written, all tasks
642
+ * which are tracking the signal will be re-run and all components that read the signal will be
643
+ * re-rendered.
644
+ *
645
+ * Furthermore, when a signal value is passed as a prop to a component, the optimizer will
646
+ * automatically forward the signal. This means that `return <div title={signal.value}>hi</div>`
647
+ * will update the `title` attribute when the signal changes without having to re-render the
648
+ * component.
649
+ *
650
+ * @public
651
+ */
652
+ declare interface Signal<T = any> extends ReadonlySignal<T> {
653
+ value: T;
654
+ }
655
+
656
+ declare const enum SignalFlags {
657
+ INVALID = 1,
658
+ RUN_EFFECTS = 2
659
+ }
660
+
661
+ declare class SignalImpl<T = any> implements Signal<T> {
662
+ $untrackedValue$: T;
663
+ /** Store a list of effects which are dependent on this signal. */
664
+ $effects$: undefined | Set<EffectSubscription>;
665
+ $container$: Container | null;
666
+ $wrappedSignal$: WrappedSignalImpl<T> | null;
667
+ constructor(container: Container | null, value: T);
668
+ /**
669
+ * Use this to force running subscribers, for example when the calculated value has mutated but
670
+ * remained the same object
671
+ */
672
+ force(): void;
673
+ get untrackedValue(): T;
674
+ set untrackedValue(value: T);
675
+ get value(): T;
676
+ set value(value: T);
677
+ valueOf(): void;
678
+ toString(): string;
679
+ toJSON(): {
680
+ value: T;
681
+ };
682
+ }
683
+
684
+ declare type SimpleSsrAttrValue = string | Signal<SimpleSsrAttrValue> | boolean | object | null;
685
+
686
+ declare interface SimplifiedServerRequestEvent<T = unknown> {
687
+ url: URL;
688
+ locale: string | undefined;
689
+ request: Request;
690
+ }
691
+
692
+ declare type SsrAttrKey = string;
693
+
694
+ declare type SsrAttrs = Array<SsrAttrKey | SsrAttrValue>;
695
+
696
+ declare type SsrAttrValue = SimpleSsrAttrValue | Promise<SimpleSsrAttrValue>;
697
+
698
+ /** A selection of attributes of the real thing */
699
+ declare type SsrNode = {
700
+ id: string;
701
+ children: ISsrNode[] | null;
702
+ vnodeData: VNodeData;
703
+ [_EFFECT_BACK_REF]: Map<EffectProperty | string, EffectSubscription> | null;
704
+ };
705
+
706
+ declare const enum SsrNodeFlags {
707
+ Updatable = 1
708
+ }
709
+
101
710
  /** @public */
102
711
  export declare function ssrRenderToDom(jsx: JSXOutput, opts?: {
712
+ /** Print debug information to console. */
103
713
  debug?: boolean;
714
+ /** Treat JSX as raw, (don't wrap in in head/body) */
104
715
  raw?: boolean;
716
+ /** Include QwikLoader */
717
+ qwikLoader?: boolean;
718
+ /** Inject nodes into the document before test runs (for testing purposes) */
719
+ onBeforeResume?: (document: Document) => void;
105
720
  }): Promise<{
106
721
  container: _DomContainer;
107
722
  document: Document;
108
- vNode: _VirtualVNode | null;
723
+ vNode: _VNode | null;
109
724
  getStyles: () => Record<string, string | string[]>;
110
725
  }>;
111
726
 
727
+ declare type StoreTarget = Record<string | symbol, any>;
728
+
729
+ /** @internal */
730
+ declare interface StreamWriter {
731
+ write(chunk: string): void;
732
+ }
733
+
734
+ /** @internal */
735
+ declare class SubscriptionData {
736
+ data: NodePropData;
737
+ constructor(data: NodePropData);
738
+ }
739
+
740
+ declare type SymbolToChunkResolver = (symbol: string) => string;
741
+
742
+ declare class Task<T = unknown, B = T> extends BackRef implements DescriptorBase<unknown, Signal<B>> {
743
+ $flags$: number;
744
+ $index$: number;
745
+ $el$: HostElement;
746
+ $qrl$: QRLInternal<T>;
747
+ $state$: Signal<B> | undefined;
748
+ $destroy$: (() => void) | null;
749
+ constructor($flags$: number, $index$: number, $el$: HostElement, $qrl$: QRLInternal<T>, $state$: Signal<B> | undefined, $destroy$: (() => void) | null);
750
+ }
751
+
752
+ declare const TaskEvent = "qTask";
753
+
112
754
  /** @public */
113
755
  declare interface TestPlatform extends CorePlatform {
756
+ /**
757
+ * @deprecated No longer used, please use {@link waitForDrain} instead.
758
+ * @example With `ssrRenderToDom`
759
+ *
760
+ * ```ts
761
+ * import { waitForDrain } from '@qwik.dev/testing';
762
+ *
763
+ * const { container } = ssrRenderToDom(...);
764
+ * await waitForDrain(container);
765
+ * ```
766
+ *
767
+ * @example With `domRender`
768
+ *
769
+ * ```ts
770
+ * import { waitForDrain } from '@qwik.dev/testing';
771
+ *
772
+ * const { container } = domRender(...);
773
+ * await waitForDrain(container);
774
+ * ```
775
+ */
114
776
  flush: () => Promise<void>;
115
777
  }
116
778
 
117
779
  /**
118
- * Trigger an event in unit tests on an element.
780
+ * Trigger an event in unit tests on an element. Needs to be kept in sync with the Qwik Loader event
781
+ * dispatching.
782
+ *
783
+ * Events can be either case sensitive element-scoped events or scoped kebab-case.
119
784
  *
120
785
  * Future deprecation candidate.
121
786
  *
122
787
  * @public
123
788
  */
124
- export declare function trigger(root: Element, queryOrElement: string | Element | keyof HTMLElementTagNameMap | null, eventName: string, eventPayload?: any): Promise<void>;
789
+ export declare function trigger(root: Element, queryOrElement: string | Element | keyof HTMLElementTagNameMap | null, eventName: string, eventPayload?: any, options?: {
790
+ waitForIdle?: boolean;
791
+ }): Promise<void>;
792
+
793
+ /**
794
+ * Type representing a value which is either resolve or a promise.
795
+ *
796
+ * @public
797
+ */
798
+ declare type ValueOrPromise<T> = T | Promise<T>;
799
+
800
+ /** @internal */
801
+ declare abstract class VNode implements BackRef {
802
+ flags: VNodeFlags;
803
+ parent: VNode | null;
804
+ previousSibling: VNode | null | undefined;
805
+ nextSibling: VNode | null | undefined;
806
+ props: Props | null;
807
+ [_EFFECT_BACK_REF]: Map<any, any> | undefined;
808
+ slotParent: VNode | null;
809
+ dirty: ChoreBits;
810
+ dirtyChildren: VNode[] | null;
811
+ nextDirtyChildIndex: number;
812
+ constructor(flags: VNodeFlags, parent: VNode | null, previousSibling: VNode | null | undefined, nextSibling: VNode | null | undefined, props: Props | null);
813
+ toString(): string;
814
+ }
125
815
 
126
816
  /** @public */
127
817
  export declare function vnode_fromJSX(jsx: JSXOutput): {
128
- vParent: _ElementVNode;
818
+ vParent: _VirtualVNode | _ElementVNode;
129
819
  vNode: _VNode | null;
130
820
  document: _QDocument;
131
- container: ClientContainer;
821
+ container: ClientContainer_2;
132
822
  };
133
823
 
824
+ /**
825
+ * Array of numbers which describes virtual nodes in the tree.
826
+ *
827
+ * HTML can't account for:
828
+ *
829
+ * - Multiple text nodes in a row. (it treats it as a single text node)
830
+ * - Empty text nodes. (it ignores them)
831
+ * - And virtual nodes such as `<Fragment/>` or `<MyComponent/>`
832
+ *
833
+ * So we need to encode all of that information into the VNodeData.
834
+ *
835
+ * Encoding:
836
+ *
837
+ * - First position is special and encodes state information and stores VNodeDataFlag.
838
+ * - Positive numbers are text node lengths. (0 is a special case for empty text node)
839
+ * - Negative numbers are element counts.
840
+ * - `OPEN_FRAGMENT` is start of virtual node.
841
+ *
842
+ * - If `OPEN_FRAGMENT` than the previous node is an `Array` which contains the props (see
843
+ * `SsrAttrs`). NOTE: The array is never going to be the last item in the VNodeData, so we can
844
+ * always assume that the last item in `vNodeData` is a number.
845
+ * - `CLOSE_FRAGMENT` is end of virtual node.
846
+ *
847
+ * NOTE: This is how we store the information during the SSR streaming, once the SSR is complete
848
+ * this data needs to be serialized into a string and stored in the DOM as a script tag which has
849
+ * deferent serialization format.
850
+ */
851
+ declare type VNodeData = [VNodeDataFlag, ...(SsrAttrs | number)[]];
852
+
853
+ /**
854
+ * Flags for VNodeData (Flags con be bitwise combined)
855
+ *
856
+ * @internal
857
+ */
858
+ declare const enum VNodeDataFlag {
859
+ NONE = 0,
860
+ TEXT_DATA = 1,
861
+ VIRTUAL_NODE = 2,
862
+ ELEMENT_NODE = 4,
863
+ REFERENCE = 8,
864
+ SERIALIZE = 16
865
+ }
866
+
867
+ /**
868
+ * Flags for VNode.
869
+ *
870
+ * # Materialize vs Inflation
871
+ *
872
+ * - Materialized: The node has all of its children. Specifically `firstChild`/`lastChild` are NOT
873
+ * `undefined`. Materialization creates lazy instantiation of the children. NOTE: Only
874
+ * ElementVNode need to be materialized.
875
+ * - Inflation:
876
+ *
877
+ * - If Text: It means that it is safe to write to the node. When Text nodes are first Deserialized
878
+ * multiple text nodes can share the same DOM node. On write the sibling text nodes need to be
879
+ * converted into separate text nodes.
880
+ * - If Element: It means that the element tag attributes have not yet been read from the DOM.
881
+ *
882
+ * Inflation and materialization are not the same, they are two independent things.
883
+ *
884
+ * @internal
885
+ */
886
+ declare const enum VNodeFlags {
887
+ Element = 1,
888
+ Virtual = 2,
889
+ ELEMENT_OR_VIRTUAL_MASK = 3,
890
+ Text = 4,
891
+ ELEMENT_OR_TEXT_MASK = 5,
892
+ TYPE_MASK = 7,
893
+ INFLATED_TYPE_MASK = 15,
894
+ Inflated = 8,
895
+ Resolved = 16,
896
+ Deleted = 32,
897
+ HasIterationItems = 64,
898
+ InflatedIterationItems = 128,
899
+ Cursor = 256,
900
+ NAMESPACE_MASK = 1536,
901
+ NEGATED_NAMESPACE_MASK = -1537,
902
+ NS_html = 0,// http://www.w3.org/1999/xhtml
903
+ NS_svg = 512,// http://www.w3.org/2000/svg
904
+ NS_math = 1024
905
+ }
906
+
907
+ /**
908
+ * Wait for the scheduler to drain.
909
+ *
910
+ * This is useful when testing async code.
911
+ *
912
+ * @param container - The application container.
913
+ * @public
914
+ */
915
+ export declare function waitForDrain(container: Container): Promise<void>;
916
+
134
917
  /** @public */
135
918
  export declare function walkJSX(jsx: JSXOutput, apply: {
136
919
  enter: (jsx: JSXNodeInternal) => void;
@@ -138,4 +921,24 @@ export declare function walkJSX(jsx: JSXOutput, apply: {
138
921
  text: (text: _Stringifiable) => void;
139
922
  }): void;
140
923
 
924
+ declare const enum WrappedSignalFlags {
925
+ UNWRAP = 4
926
+ }
927
+
928
+ declare class WrappedSignalImpl<T> extends SignalImpl<T> implements BackRef {
929
+ $args$: any[];
930
+ $func$: (...args: any[]) => T;
931
+ $funcStr$: string | null;
932
+ $flags$: AllSignalFlags;
933
+ $hostElement$: HostElement | undefined;
934
+ [_EFFECT_BACK_REF]: Map<EffectProperty | string, EffectSubscription> | undefined;
935
+ constructor(container: Container | null, fn: (...args: any[]) => T, args: any[], fnStr: string | null, flags?: SignalFlags);
936
+ invalidate(): void;
937
+ get untrackedValue(): T;
938
+ $computeIfNeeded$(): void;
939
+ $unwrapIfSignal$(): SignalImpl<T> | WrappedSignalImpl<T>;
940
+ set value(_: any);
941
+ get value(): any;
942
+ }
943
+
141
944
  export { }