@qwik.dev/react 0.0.0 → 2.0.0-alpha.1

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/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2024 QwikDev
4
+ Copyright (c) 2021 BuilderIO
5
+
6
+ Permission is hereby granted, free of charge, to any person obtaining a copy
7
+ of this software and associated documentation files (the "Software"), to deal
8
+ in the Software without restriction, including without limitation the rights
9
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10
+ copies of the Software, and to permit persons to whom the Software is
11
+ furnished to do so, subject to the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be included in all
14
+ copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,60 @@
1
+ # Qwik qwik-react ⚡️
2
+
3
+ - Create a component library
4
+ - Vite.js tooling.
5
+ - Prettier code formatter.
6
+
7
+ ## Development Builds
8
+
9
+ ### Client only
10
+
11
+ During development, the index.html is not a result of server-side rendering, but rather the Qwik app is built using client-side JavaScript only. This is ideal for development with Vite and its ability to reload modules quickly and on-demand. However, this mode is only for development and does not showcase "how" Qwik works since JavaScript is required to execute, and Vite imports many development modules for the app to work.
12
+
13
+ ```
14
+ npm run dev
15
+ ```
16
+
17
+ ### Server-side Rendering (SSR) and Client
18
+
19
+ Server-side rendered index.html, with client-side modules prefetched and loaded by the browser. This can be used to test out server-side rendered content during development, but will be slower than the client-only development builds.
20
+
21
+ ```
22
+ npm run dev.ssr
23
+ ```
24
+
25
+ ## Production Builds
26
+
27
+ A production build should generate the client and server modules by running both client and server build commands.
28
+
29
+ ```
30
+ npm run build
31
+ ```
32
+
33
+ ### Client Modules
34
+
35
+ Production build that creates only the client-side modules that are dynamically imported by the browser.
36
+
37
+ ```
38
+ npm run build.client
39
+ ```
40
+
41
+ ### Server Modules
42
+
43
+ Production build that creates the server-side render (SSR) module that is used by the server to render the HTML.
44
+
45
+ ```
46
+ npm run build.server
47
+ ```
48
+
49
+ ---
50
+
51
+ ## Related
52
+
53
+ - [Qwik Docs](https://qwik.dev/docs/)
54
+ - [Qwik on GitHub](https://github.com/QwikDev/qwik)
55
+ - [@QwikDev](https://twitter.com/QwikDev)
56
+ - [Discord](https://qwik.dev/chat)
57
+ - [Vite](https://vitejs.dev/)
58
+ - [Partytown](https://partytown.builder.io/)
59
+ - [Mitosis](https://github.com/BuilderIO/mitosis)
60
+ - [Builder.io](https://www.builder.io/)
@@ -0,0 +1,265 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
4
+ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
5
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
6
+ const jsxRuntime = require("@qwik.dev/core/jsx-runtime");
7
+ const core = require("@qwik.dev/core");
8
+ const build = require("@qwik.dev/core/build");
9
+ const client = require("react-dom/client");
10
+ const reactDom = require("react-dom");
11
+ const internal = require("@qwik.dev/core/internal");
12
+ const server = require("react-dom/server");
13
+ const react = require("react");
14
+ const SlotCtx = react.createContext({
15
+ scopeId: ""
16
+ });
17
+ function main(slotEl, scopeId, RootCmp, props) {
18
+ const newProps = getReactProps(props);
19
+ return mainExactProps(slotEl, scopeId, RootCmp, newProps);
20
+ }
21
+ function mainExactProps(slotEl, scopeId, RootCmp, props) {
22
+ return react.createElement(SlotCtx.Provider, {
23
+ value: {
24
+ el: slotEl,
25
+ scopeId,
26
+ attachedEl: void 0
27
+ },
28
+ children: react.createElement(RootCmp, {
29
+ ...props,
30
+ children: react.createElement(SlotElement, null)
31
+ })
32
+ });
33
+ }
34
+ class SlotElement extends react.Component {
35
+ constructor() {
36
+ super(...arguments);
37
+ __publicField(this, "slotC", react.createRef());
38
+ }
39
+ shouldComponentUpdate() {
40
+ return false;
41
+ }
42
+ componentDidMount() {
43
+ const slotC = this.slotC.current;
44
+ if (slotC) {
45
+ const { attachedEl, el } = this.context;
46
+ if (el) {
47
+ if (!attachedEl) {
48
+ slotC.appendChild(el);
49
+ } else if (attachedEl !== slotC) {
50
+ throw new Error("already attached");
51
+ }
52
+ }
53
+ }
54
+ }
55
+ render() {
56
+ return react.createElement("q-slotc", {
57
+ class: this.context.scopeId,
58
+ suppressHydrationWarning: true,
59
+ dangerouslySetInnerHTML: {
60
+ __html: "<!--SLOT-->"
61
+ },
62
+ ref: this.slotC
63
+ });
64
+ }
65
+ }
66
+ __publicField(SlotElement, "contextType", SlotCtx);
67
+ const getReactProps = (props) => {
68
+ const obj = {};
69
+ Object.keys(props).forEach((key) => {
70
+ if (!key.startsWith("client:") && !key.startsWith("qwik:") && !key.startsWith(HOST_PREFIX)) {
71
+ const normalizedKey = key.endsWith("$") ? key.slice(0, -1) : key;
72
+ obj[normalizedKey] = props[key];
73
+ }
74
+ });
75
+ return obj;
76
+ };
77
+ const getHostProps = (props) => {
78
+ const obj = {};
79
+ Object.keys(props).forEach((key) => {
80
+ if (key.startsWith(HOST_PREFIX)) {
81
+ obj[key.slice(HOST_PREFIX.length)] = props[key];
82
+ }
83
+ });
84
+ return obj;
85
+ };
86
+ const useWakeupSignal = (props, opts = {}) => {
87
+ const signal = core.useSignal(false);
88
+ const activate = core.$(() => signal.value = true);
89
+ const clientOnly = !!(props["client:only"] || props["qwik:only"] || opts?.clientOnly);
90
+ const clientVisible = props["client:visible"] || props["qwik:visible"] || opts?.eagerness === "visible";
91
+ const clientIdle = props["client:idle"] || props["qwik:idle"] || opts?.eagerness === "idle";
92
+ const clientLoad = props["client:load"] || props["qwik:load"] || clientOnly || opts?.eagerness === "load";
93
+ const clientHover = props["client:hover"] || props["qwik:hover"] || opts?.eagerness === "hover";
94
+ const clientEvent = props["client:event"] || props["qwik:event"];
95
+ if (build.isServer) {
96
+ if (clientVisible) {
97
+ core.useOn("qvisible", activate);
98
+ }
99
+ if (clientIdle) {
100
+ core.useOnDocument("qidle", activate);
101
+ }
102
+ if (clientLoad) {
103
+ core.useOnDocument("qinit", activate);
104
+ }
105
+ if (clientHover) {
106
+ core.useOn("mouseover", activate);
107
+ }
108
+ if (clientEvent) {
109
+ core.useOn(clientEvent, activate);
110
+ }
111
+ if (opts?.event) {
112
+ core.useOn(opts?.event, activate);
113
+ }
114
+ }
115
+ return [
116
+ signal,
117
+ clientOnly,
118
+ activate
119
+ ];
120
+ };
121
+ const HOST_PREFIX = "host:";
122
+ async function renderFromServer(Host, reactCmp$, scopeId, props, ref, slotRef, hydrationProps) {
123
+ if (build.isServer) {
124
+ const Cmp = await reactCmp$.resolve();
125
+ const newProps = getReactProps(props);
126
+ Object.assign(hydrationProps, newProps);
127
+ const html = server.renderToString(mainExactProps(void 0, scopeId, Cmp, newProps));
128
+ const index = html.indexOf("<!--SLOT-->");
129
+ if (index > 0) {
130
+ const part1 = html.slice(0, index);
131
+ const part2 = html.slice(index + "<!--SLOT-->".length);
132
+ return /* @__PURE__ */ jsxRuntime.jsx(Host, {
133
+ ref,
134
+ ...getHostProps(props),
135
+ children: /* @__PURE__ */ jsxRuntime.jsx(internal.SSRStream, {
136
+ children: async function* () {
137
+ yield /* @__PURE__ */ jsxRuntime.jsx(internal.SSRComment, {
138
+ data: "q:ignore"
139
+ });
140
+ yield /* @__PURE__ */ jsxRuntime.jsx(internal.SSRRaw, {
141
+ data: part1
142
+ });
143
+ yield /* @__PURE__ */ jsxRuntime.jsx(internal.SSRComment, {
144
+ data: "q:container-island"
145
+ });
146
+ yield /* @__PURE__ */ jsxRuntime.jsx("q-slot", {
147
+ ref: slotRef,
148
+ children: /* @__PURE__ */ jsxRuntime.jsx(core.Slot, {})
149
+ });
150
+ yield /* @__PURE__ */ jsxRuntime.jsx(internal.SSRComment, {
151
+ data: "/q:container-island"
152
+ });
153
+ yield /* @__PURE__ */ jsxRuntime.jsx(internal.SSRRaw, {
154
+ data: part2
155
+ });
156
+ yield /* @__PURE__ */ jsxRuntime.jsx(internal.SSRComment, {
157
+ data: "/q:ignore"
158
+ });
159
+ }
160
+ })
161
+ });
162
+ }
163
+ return /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, {
164
+ children: [
165
+ /* @__PURE__ */ jsxRuntime.jsxs(Host, {
166
+ ref,
167
+ children: [
168
+ /* @__PURE__ */ jsxRuntime.jsx(internal.SSRComment, {
169
+ data: "q:container=html"
170
+ }),
171
+ /* @__PURE__ */ jsxRuntime.jsx(internal.SSRRaw, {
172
+ data: html
173
+ }),
174
+ /* @__PURE__ */ jsxRuntime.jsx(internal.SSRComment, {
175
+ data: "/q:container"
176
+ })
177
+ ]
178
+ }),
179
+ /* @__PURE__ */ jsxRuntime.jsx("q-slot", {
180
+ ref: slotRef,
181
+ children: /* @__PURE__ */ jsxRuntime.jsx(core.Slot, {})
182
+ })
183
+ ]
184
+ });
185
+ }
186
+ }
187
+ function qwikifyQrl(reactCmp$, opts) {
188
+ return core.component$((props) => {
189
+ const { scopeId } = core.useStylesScoped$(`q-slot{display:none} q-slotc,q-slotc>q-slot{display:contents}`);
190
+ const hostRef = core.useSignal();
191
+ const slotRef = core.useSignal();
192
+ const internalState = core.useSignal();
193
+ const [signal, isClientOnly] = useWakeupSignal(props, opts);
194
+ const hydrationKeys = core.useStore({});
195
+ const TagName = opts?.tagName ?? "qwik-react";
196
+ core.useTask$(async ({ track }) => {
197
+ const trackedProps = track(() => ({
198
+ ...props
199
+ }));
200
+ track(signal);
201
+ if (!build.isBrowser) {
202
+ return;
203
+ }
204
+ if (internalState.value) {
205
+ if (internalState.value.root) {
206
+ internalState.value.root.render(main(slotRef.value, scopeId, internalState.value.cmp, trackedProps));
207
+ }
208
+ } else {
209
+ let root = void 0;
210
+ const Cmp = await reactCmp$.resolve();
211
+ const hostElement = hostRef.value;
212
+ if (hostElement) {
213
+ if (isClientOnly) {
214
+ root = client.createRoot(hostElement);
215
+ } else {
216
+ root = reactDom.flushSync(() => {
217
+ return client.hydrateRoot(hostElement, mainExactProps(slotRef.value, scopeId, Cmp, hydrationKeys));
218
+ });
219
+ }
220
+ if (isClientOnly || signal.value === false) {
221
+ root.render(main(slotRef.value, scopeId, Cmp, trackedProps));
222
+ }
223
+ }
224
+ internalState.value = core.noSerialize({
225
+ cmp: Cmp,
226
+ root
227
+ });
228
+ }
229
+ });
230
+ if (build.isServer && !isClientOnly) {
231
+ const jsx = renderFromServer(TagName, reactCmp$, scopeId, props, hostRef, slotRef, hydrationKeys);
232
+ return /* @__PURE__ */ jsxRuntime.jsx(core.RenderOnce, {
233
+ children: jsx
234
+ }, 2);
235
+ }
236
+ return /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, {
237
+ children: [
238
+ /* @__PURE__ */ jsxRuntime.jsx(TagName, {
239
+ ...getHostProps(props),
240
+ ref: (el) => {
241
+ if (build.isBrowser) {
242
+ queueMicrotask(() => {
243
+ const internalData = internalState.value;
244
+ if (internalData && !internalData.root) {
245
+ const root = internalData.root = client.createRoot(el);
246
+ root.render(main(slotRef.value, scopeId, internalData.cmp, props));
247
+ }
248
+ });
249
+ } else {
250
+ hostRef.value = el;
251
+ }
252
+ },
253
+ children: core.SkipRender
254
+ }),
255
+ /* @__PURE__ */ jsxRuntime.jsx("q-slot", {
256
+ ref: slotRef,
257
+ children: /* @__PURE__ */ jsxRuntime.jsx(core.Slot, {})
258
+ })
259
+ ]
260
+ });
261
+ });
262
+ }
263
+ const qwikify$ = /* @__PURE__ */ core.implicit$FirstArg(qwikifyQrl);
264
+ exports.qwikify$ = qwikify$;
265
+ exports.qwikifyQrl = qwikifyQrl;
@@ -0,0 +1,265 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
3
+ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
4
+ import { jsx, jsxs, Fragment } from "@qwik.dev/core/jsx-runtime";
5
+ import { useSignal, $, useOn, useOnDocument, Slot, component$, useStylesScoped$, useStore, useTask$, noSerialize, RenderOnce, SkipRender, implicit$FirstArg } from "@qwik.dev/core";
6
+ import { isServer, isBrowser } from "@qwik.dev/core/build";
7
+ import { createRoot, hydrateRoot } from "react-dom/client";
8
+ import { flushSync } from "react-dom";
9
+ import { SSRStream, SSRComment, SSRRaw } from "@qwik.dev/core/internal";
10
+ import { renderToString } from "react-dom/server";
11
+ import { createContext, createElement, Component, createRef } from "react";
12
+ const SlotCtx = createContext({
13
+ scopeId: ""
14
+ });
15
+ function main(slotEl, scopeId, RootCmp, props) {
16
+ const newProps = getReactProps(props);
17
+ return mainExactProps(slotEl, scopeId, RootCmp, newProps);
18
+ }
19
+ function mainExactProps(slotEl, scopeId, RootCmp, props) {
20
+ return createElement(SlotCtx.Provider, {
21
+ value: {
22
+ el: slotEl,
23
+ scopeId,
24
+ attachedEl: void 0
25
+ },
26
+ children: createElement(RootCmp, {
27
+ ...props,
28
+ children: createElement(SlotElement, null)
29
+ })
30
+ });
31
+ }
32
+ class SlotElement extends Component {
33
+ constructor() {
34
+ super(...arguments);
35
+ __publicField(this, "slotC", createRef());
36
+ }
37
+ shouldComponentUpdate() {
38
+ return false;
39
+ }
40
+ componentDidMount() {
41
+ const slotC = this.slotC.current;
42
+ if (slotC) {
43
+ const { attachedEl, el } = this.context;
44
+ if (el) {
45
+ if (!attachedEl) {
46
+ slotC.appendChild(el);
47
+ } else if (attachedEl !== slotC) {
48
+ throw new Error("already attached");
49
+ }
50
+ }
51
+ }
52
+ }
53
+ render() {
54
+ return createElement("q-slotc", {
55
+ class: this.context.scopeId,
56
+ suppressHydrationWarning: true,
57
+ dangerouslySetInnerHTML: {
58
+ __html: "<!--SLOT-->"
59
+ },
60
+ ref: this.slotC
61
+ });
62
+ }
63
+ }
64
+ __publicField(SlotElement, "contextType", SlotCtx);
65
+ const getReactProps = (props) => {
66
+ const obj = {};
67
+ Object.keys(props).forEach((key) => {
68
+ if (!key.startsWith("client:") && !key.startsWith("qwik:") && !key.startsWith(HOST_PREFIX)) {
69
+ const normalizedKey = key.endsWith("$") ? key.slice(0, -1) : key;
70
+ obj[normalizedKey] = props[key];
71
+ }
72
+ });
73
+ return obj;
74
+ };
75
+ const getHostProps = (props) => {
76
+ const obj = {};
77
+ Object.keys(props).forEach((key) => {
78
+ if (key.startsWith(HOST_PREFIX)) {
79
+ obj[key.slice(HOST_PREFIX.length)] = props[key];
80
+ }
81
+ });
82
+ return obj;
83
+ };
84
+ const useWakeupSignal = (props, opts = {}) => {
85
+ const signal = useSignal(false);
86
+ const activate = $(() => signal.value = true);
87
+ const clientOnly = !!(props["client:only"] || props["qwik:only"] || opts?.clientOnly);
88
+ const clientVisible = props["client:visible"] || props["qwik:visible"] || opts?.eagerness === "visible";
89
+ const clientIdle = props["client:idle"] || props["qwik:idle"] || opts?.eagerness === "idle";
90
+ const clientLoad = props["client:load"] || props["qwik:load"] || clientOnly || opts?.eagerness === "load";
91
+ const clientHover = props["client:hover"] || props["qwik:hover"] || opts?.eagerness === "hover";
92
+ const clientEvent = props["client:event"] || props["qwik:event"];
93
+ if (isServer) {
94
+ if (clientVisible) {
95
+ useOn("qvisible", activate);
96
+ }
97
+ if (clientIdle) {
98
+ useOnDocument("qidle", activate);
99
+ }
100
+ if (clientLoad) {
101
+ useOnDocument("qinit", activate);
102
+ }
103
+ if (clientHover) {
104
+ useOn("mouseover", activate);
105
+ }
106
+ if (clientEvent) {
107
+ useOn(clientEvent, activate);
108
+ }
109
+ if (opts?.event) {
110
+ useOn(opts?.event, activate);
111
+ }
112
+ }
113
+ return [
114
+ signal,
115
+ clientOnly,
116
+ activate
117
+ ];
118
+ };
119
+ const HOST_PREFIX = "host:";
120
+ async function renderFromServer(Host, reactCmp$, scopeId, props, ref, slotRef, hydrationProps) {
121
+ if (isServer) {
122
+ const Cmp = await reactCmp$.resolve();
123
+ const newProps = getReactProps(props);
124
+ Object.assign(hydrationProps, newProps);
125
+ const html = renderToString(mainExactProps(void 0, scopeId, Cmp, newProps));
126
+ const index = html.indexOf("<!--SLOT-->");
127
+ if (index > 0) {
128
+ const part1 = html.slice(0, index);
129
+ const part2 = html.slice(index + "<!--SLOT-->".length);
130
+ return /* @__PURE__ */ jsx(Host, {
131
+ ref,
132
+ ...getHostProps(props),
133
+ children: /* @__PURE__ */ jsx(SSRStream, {
134
+ children: async function* () {
135
+ yield /* @__PURE__ */ jsx(SSRComment, {
136
+ data: "q:ignore"
137
+ });
138
+ yield /* @__PURE__ */ jsx(SSRRaw, {
139
+ data: part1
140
+ });
141
+ yield /* @__PURE__ */ jsx(SSRComment, {
142
+ data: "q:container-island"
143
+ });
144
+ yield /* @__PURE__ */ jsx("q-slot", {
145
+ ref: slotRef,
146
+ children: /* @__PURE__ */ jsx(Slot, {})
147
+ });
148
+ yield /* @__PURE__ */ jsx(SSRComment, {
149
+ data: "/q:container-island"
150
+ });
151
+ yield /* @__PURE__ */ jsx(SSRRaw, {
152
+ data: part2
153
+ });
154
+ yield /* @__PURE__ */ jsx(SSRComment, {
155
+ data: "/q:ignore"
156
+ });
157
+ }
158
+ })
159
+ });
160
+ }
161
+ return /* @__PURE__ */ jsxs(Fragment, {
162
+ children: [
163
+ /* @__PURE__ */ jsxs(Host, {
164
+ ref,
165
+ children: [
166
+ /* @__PURE__ */ jsx(SSRComment, {
167
+ data: "q:container=html"
168
+ }),
169
+ /* @__PURE__ */ jsx(SSRRaw, {
170
+ data: html
171
+ }),
172
+ /* @__PURE__ */ jsx(SSRComment, {
173
+ data: "/q:container"
174
+ })
175
+ ]
176
+ }),
177
+ /* @__PURE__ */ jsx("q-slot", {
178
+ ref: slotRef,
179
+ children: /* @__PURE__ */ jsx(Slot, {})
180
+ })
181
+ ]
182
+ });
183
+ }
184
+ }
185
+ function qwikifyQrl(reactCmp$, opts) {
186
+ return component$((props) => {
187
+ const { scopeId } = useStylesScoped$(`q-slot{display:none} q-slotc,q-slotc>q-slot{display:contents}`);
188
+ const hostRef = useSignal();
189
+ const slotRef = useSignal();
190
+ const internalState = useSignal();
191
+ const [signal, isClientOnly] = useWakeupSignal(props, opts);
192
+ const hydrationKeys = useStore({});
193
+ const TagName = opts?.tagName ?? "qwik-react";
194
+ useTask$(async ({ track }) => {
195
+ const trackedProps = track(() => ({
196
+ ...props
197
+ }));
198
+ track(signal);
199
+ if (!isBrowser) {
200
+ return;
201
+ }
202
+ if (internalState.value) {
203
+ if (internalState.value.root) {
204
+ internalState.value.root.render(main(slotRef.value, scopeId, internalState.value.cmp, trackedProps));
205
+ }
206
+ } else {
207
+ let root = void 0;
208
+ const Cmp = await reactCmp$.resolve();
209
+ const hostElement = hostRef.value;
210
+ if (hostElement) {
211
+ if (isClientOnly) {
212
+ root = createRoot(hostElement);
213
+ } else {
214
+ root = flushSync(() => {
215
+ return hydrateRoot(hostElement, mainExactProps(slotRef.value, scopeId, Cmp, hydrationKeys));
216
+ });
217
+ }
218
+ if (isClientOnly || signal.value === false) {
219
+ root.render(main(slotRef.value, scopeId, Cmp, trackedProps));
220
+ }
221
+ }
222
+ internalState.value = noSerialize({
223
+ cmp: Cmp,
224
+ root
225
+ });
226
+ }
227
+ });
228
+ if (isServer && !isClientOnly) {
229
+ const jsx$1 = renderFromServer(TagName, reactCmp$, scopeId, props, hostRef, slotRef, hydrationKeys);
230
+ return /* @__PURE__ */ jsx(RenderOnce, {
231
+ children: jsx$1
232
+ }, 2);
233
+ }
234
+ return /* @__PURE__ */ jsxs(Fragment, {
235
+ children: [
236
+ /* @__PURE__ */ jsx(TagName, {
237
+ ...getHostProps(props),
238
+ ref: (el) => {
239
+ if (isBrowser) {
240
+ queueMicrotask(() => {
241
+ const internalData = internalState.value;
242
+ if (internalData && !internalData.root) {
243
+ const root = internalData.root = createRoot(el);
244
+ root.render(main(slotRef.value, scopeId, internalData.cmp, props));
245
+ }
246
+ });
247
+ } else {
248
+ hostRef.value = el;
249
+ }
250
+ },
251
+ children: SkipRender
252
+ }),
253
+ /* @__PURE__ */ jsx("q-slot", {
254
+ ref: slotRef,
255
+ children: /* @__PURE__ */ jsx(Slot, {})
256
+ })
257
+ ]
258
+ });
259
+ });
260
+ }
261
+ const qwikify$ = /* @__PURE__ */ implicit$FirstArg(qwikifyQrl);
262
+ export {
263
+ qwikify$,
264
+ qwikifyQrl
265
+ };
@@ -0,0 +1,12 @@
1
+ import { type RenderOptions } from '@qwik.dev/core';
2
+ /**
3
+ * Development entry point using only client-side modules:
4
+ *
5
+ * - Do not use this mode in production!
6
+ * - No SSR
7
+ * - No portion of the application is pre-rendered on the server.
8
+ * - All of the application is running eagerly in the browser.
9
+ * - More code is transferred to the browser than in SSR mode.
10
+ * - Optimizer/Serialization/Deserialization code is not exercised!
11
+ */
12
+ export default function (opts: RenderOptions): Promise<import("packages/qwik/core-internal").RenderResult>;
@@ -0,0 +1,3 @@
1
+ import { type RenderToStreamOptions } from '@qwik.dev/core/server';
2
+ /** Server-Side Render method to be called by a server. */
3
+ export default function (opts: RenderToStreamOptions): Promise<import("@qwik.dev/core/server").RenderToStreamResult>;
@@ -0,0 +1,2 @@
1
+ /** @jsxImportSource react */
2
+ export declare const App: import("packages/qwik/public").Component<import("../index.qwik").QwikifyProps<Record<any, any>>>;
@@ -0,0 +1,2 @@
1
+ export { qwikify$, qwikifyQrl } from './react/qwikify';
2
+ export type { QwikifyProps } from './react/types';
@@ -0,0 +1,2 @@
1
+ export { createRoot, hydrateRoot } from 'react-dom/client';
2
+ export { flushSync } from 'react-dom';
@@ -0,0 +1,9 @@
1
+ import { type QRL } from '@qwik.dev/core';
2
+ import type { FunctionComponent as ReactFC } from 'react';
3
+ import type { QwikifyOptions, QwikifyProps } from './types';
4
+ export declare function qwikifyQrl<PROPS extends Record<any, any>>(reactCmp$: QRL<ReactFC<PROPS & {
5
+ children?: any;
6
+ }>>, opts?: QwikifyOptions): import("@qwik.dev/core").Component<QwikifyProps<PROPS>>;
7
+ export declare const qwikify$: <PROPS extends Record<any, any>>(qrl: ReactFC<PROPS & {
8
+ children?: any;
9
+ }>, opts?: QwikifyOptions | undefined) => import("@qwik.dev/core").Component<QwikifyProps<PROPS>>;
@@ -0,0 +1,2 @@
1
+ import { type QRL, type Signal } from '@qwik.dev/core';
2
+ export declare function renderFromServer(Host: any, reactCmp$: QRL<any>, scopeId: string, props: Record<string, any>, ref: Signal<Element | undefined>, slotRef: Signal<Element | undefined>, hydrationProps: Record<string, any>): Promise<import("@qwik.dev/core").JSXOutput>;
@@ -0,0 +1,29 @@
1
+ import { Component } from 'react';
2
+ import type { QwikifyOptions, QwikifyProps } from './types';
3
+ interface SlotState {
4
+ el?: Element;
5
+ scopeId: string;
6
+ attachedEl?: Element;
7
+ }
8
+ declare const SlotCtx: import("react").Context<SlotState>;
9
+ export declare function main(slotEl: Element | undefined, scopeId: string, RootCmp: any, props: any): import("react").FunctionComponentElement<import("react").ProviderProps<SlotState>>;
10
+ export declare function mainExactProps(slotEl: Element | undefined, scopeId: string, RootCmp: any, props: any): import("react").FunctionComponentElement<import("react").ProviderProps<SlotState>>;
11
+ export declare class SlotElement extends Component {
12
+ static contextType: import("react").Context<SlotState>;
13
+ context: React.ContextType<typeof SlotCtx>;
14
+ slotC: import("react").RefObject<Element>;
15
+ shouldComponentUpdate(): boolean;
16
+ componentDidMount(): void;
17
+ render(): import("react").DOMElement<{
18
+ class: string;
19
+ suppressHydrationWarning: boolean;
20
+ dangerouslySetInnerHTML: {
21
+ __html: string;
22
+ };
23
+ ref: import("react").RefObject<Element>;
24
+ }, Element>;
25
+ }
26
+ export declare const getReactProps: (props: Record<string, any>) => Record<string, any>;
27
+ export declare const getHostProps: (props: Record<string, any>) => Record<string, any>;
28
+ export declare const useWakeupSignal: (props: QwikifyProps<{}>, opts?: QwikifyOptions) => readonly [import("@qwik.dev/core").Signal<boolean>, boolean, import("@qwik.dev/core").QRL<() => true>];
29
+ export {};
@@ -0,0 +1,86 @@
1
+ import type { QRL, Signal } from '@qwik.dev/core';
2
+ import type { FunctionComponent as ReactFC } from 'react';
3
+ import type { Root } from 'react-dom/client';
4
+ export interface Internal<PROPS> {
5
+ root: Root | undefined;
6
+ cmp: ReactFC<PROPS>;
7
+ }
8
+ export interface QwikifyBase {
9
+ /**
10
+ * The component eagerly hydrates when the document loads.
11
+ *
12
+ * **Use case:** Immediately-visible UI elements that need to be interactive as soon as possible.
13
+ */
14
+ 'client:load'?: boolean;
15
+ 'qwik:load'?: boolean;
16
+ /**
17
+ * The component eagerly hydrates when the browser first become idle, ie, when everything
18
+ * important as already run before.
19
+ *
20
+ * **Use case:** Lower-priority UI elements that don’t need to be immediately interactive.
21
+ */
22
+ 'client:idle'?: boolean;
23
+ 'qwik:idle'?: boolean;
24
+ /**
25
+ * The component eagerly hydrates when it becomes visible in the viewport.
26
+ *
27
+ * **Use case:** Low-priority UI elements that are either far down the page (“below the fold”) or
28
+ * so resource-intensive to load that you would prefer not to load them at all if the user never
29
+ * saw the element.
30
+ */
31
+ 'client:visible'?: boolean;
32
+ 'qwik:visible'?: boolean;
33
+ /**
34
+ * The component eagerly hydrates when the mouse is over the component.
35
+ *
36
+ * **Use case:** Lowest-priority UI elements which interactivity is not crucial, and only needs to
37
+ * run in desktop.
38
+ */
39
+ 'client:hover'?: boolean;
40
+ 'qwik:hover'?: boolean;
41
+ /** When `true`, the component will not run in SSR, only in the browser. */
42
+ 'client:only'?: boolean;
43
+ 'qwik:only'?: boolean;
44
+ /**
45
+ * This is an advanced API that allows to hydrate the component whenever the passed signal becomes
46
+ * `true`.
47
+ *
48
+ * This effectively allows you to implement custom strategies for hydration.
49
+ */
50
+ 'client:signal'?: Signal<boolean>;
51
+ 'qwik:signal'?: Signal<boolean>;
52
+ /** The component eagerly hydrates when specified DOM events are dispatched. */
53
+ 'client:event'?: string | string[];
54
+ 'qwik:event'?: string | string[];
55
+ /**
56
+ * Adds a `click` event listener to the host element, this event will be dispatched even if the
57
+ * react component is not hydrated.
58
+ */
59
+ 'host:onClick$'?: QRL<(ev: Event) => void>;
60
+ /**
61
+ * Adds a `blur` event listener to the host element, this event will be dispatched even if the
62
+ * react component is not hydrated.
63
+ */
64
+ 'host:onBlur$'?: QRL<(ev: Event) => void>;
65
+ /**
66
+ * Adds a `focus` event listener to the host element, this event will be dispatched even if the
67
+ * react component is not hydrated.
68
+ */
69
+ 'host:onFocus$'?: QRL<(ev: Event) => void>;
70
+ /**
71
+ * Adds a `mouseover` event listener to the host element, this event will be dispatched even if
72
+ * the react component is not hydrated.
73
+ */
74
+ 'host:onMouseOver$'?: QRL<(ev: Event) => void>;
75
+ children?: any;
76
+ }
77
+ export type TransformProps<PROPS extends Record<any, any>> = {
78
+ [K in keyof PROPS as K extends `on${string}` ? `${K}$` : K]: PROPS[K];
79
+ };
80
+ export type QwikifyProps<PROPS extends Record<any, any>> = TransformProps<PROPS> & QwikifyBase;
81
+ export interface QwikifyOptions {
82
+ tagName?: string;
83
+ eagerness?: 'load' | 'visible' | 'idle' | 'hover';
84
+ event?: string | string[];
85
+ clientOnly?: boolean;
86
+ }
@@ -0,0 +1 @@
1
+ export declare const Root: import("@qwik.dev/core").Component<unknown>;
@@ -0,0 +1 @@
1
+ export declare function qwikReact(): any;
package/lib/vite.cjs ADDED
@@ -0,0 +1,30 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
+ function qwikReact() {
4
+ const OPTIMIZE_DEPS = [
5
+ "react",
6
+ "react-dom",
7
+ "react-dom/client",
8
+ "react-dom/server",
9
+ "react/jsx-runtime",
10
+ "react/jsx-dev-runtime"
11
+ ];
12
+ const DEDUPE = [
13
+ "react",
14
+ "react-dom"
15
+ ];
16
+ return {
17
+ name: "vite-plugin-qwik-react",
18
+ config() {
19
+ return {
20
+ resolve: {
21
+ dedupe: DEDUPE
22
+ },
23
+ optimizeDeps: {
24
+ include: OPTIMIZE_DEPS
25
+ }
26
+ };
27
+ }
28
+ };
29
+ }
30
+ exports.qwikReact = qwikReact;
package/lib/vite.mjs ADDED
@@ -0,0 +1,30 @@
1
+ function qwikReact() {
2
+ const OPTIMIZE_DEPS = [
3
+ "react",
4
+ "react-dom",
5
+ "react-dom/client",
6
+ "react-dom/server",
7
+ "react/jsx-runtime",
8
+ "react/jsx-dev-runtime"
9
+ ];
10
+ const DEDUPE = [
11
+ "react",
12
+ "react-dom"
13
+ ];
14
+ return {
15
+ name: "vite-plugin-qwik-react",
16
+ config() {
17
+ return {
18
+ resolve: {
19
+ dedupe: DEDUPE
20
+ },
21
+ optimizeDeps: {
22
+ include: OPTIMIZE_DEPS
23
+ }
24
+ };
25
+ }
26
+ };
27
+ }
28
+ export {
29
+ qwikReact
30
+ };
package/package.json CHANGED
@@ -1,188 +1,71 @@
1
1
  {
2
2
  "name": "@qwik.dev/react",
3
- "description": "An open source framework for instant loading web apps at any scale, without the extra effort.",
4
- "version": "0.0.0",
5
- "author": "Qwik Team",
6
- "annotation": "This package.json is for internal use in the monorepo, the build actually makes a new package.json for the published package via scripts/package-json.ts",
7
- "bin": {
8
- "qwik": "./qwik-cli.cjs"
9
- },
10
- "publishConfig": {
11
- "access": "public"
12
- },
3
+ "description": "Qwik React allows adding React components into existing Qwik application",
4
+ "version": "2.0.0-alpha.1",
13
5
  "bugs": "https://github.com/QwikDev/qwik/issues",
14
- "dependencies": {},
15
- "devDependencies": {},
6
+ "devDependencies": {
7
+ "@types/react": "18.3.3",
8
+ "@types/react-dom": "18.3.0",
9
+ "react": "18.3.1",
10
+ "react-dom": "18.3.1",
11
+ "typescript": "5.4.5",
12
+ "vite": "5.4.10",
13
+ "@qwik.dev/core": "2.0.0-alpha.1"
14
+ },
16
15
  "engines": {
17
16
  "node": "^18.17.0 || ^20.3.0 || >=21.0.0"
18
17
  },
19
18
  "exports": {
20
19
  ".": {
21
- "types": "./public.d.ts",
22
- "import": {
23
- "development": "./dist/core.mjs",
24
- "production": "./dist/core.prod.mjs",
25
- "default": "./dist/core.prod.mjs",
26
- "min": "./dist/core.min.mjs"
27
- },
28
- "require": {
29
- "development": "./dist/core.cjs",
30
- "production": "./dist/core.prod.cjs",
31
- "default": "./dist/core.prod.cjs"
32
- }
33
- },
34
- "./cli": {
35
- "require": "./dist/cli.cjs"
36
- },
37
- "./internal": {
38
- "types": "./dist/core-internal.d.ts",
39
- "import": {
40
- "development": "./dist/core.mjs",
41
- "production": "./dist/core.prod.mjs",
42
- "default": "./dist/core.prod.mjs",
43
- "min": "./dist/core.min.mjs"
44
- },
45
- "require": {
46
- "development": "./dist/core.cjs",
47
- "production": "./dist/core.prod.cjs",
48
- "default": "./dist/core.prod.cjs"
49
- }
50
- },
51
- "./jsx-runtime": {
52
- "types": "./dist/jsx-runtime.d.ts",
53
- "import": {
54
- "development": "./dist/core.mjs",
55
- "production": "./dist/core.prod.mjs",
56
- "default": "./dist/core.prod.mjs",
57
- "min": "./dist/core.min.mjs"
58
- },
59
- "require": {
60
- "development": "./dist/core.cjs",
61
- "production": "./dist/core.prod.cjs",
62
- "default": "./dist/core.prod.cjs"
63
- }
64
- },
65
- "./jsx-dev-runtime": {
66
- "types": "./dist/jsx-runtime.d.ts",
67
- "import": {
68
- "development": "./dist/core.mjs",
69
- "production": "./dist/core.prod.mjs",
70
- "default": "./dist/core.mjs",
71
- "min": "./dist/core.min.mjs"
72
- },
73
- "require": {
74
- "development": "./dist/core.cjs",
75
- "production": "./dist/core.prod.cjs",
76
- "default": "./dist/core.cjs"
77
- }
78
- },
79
- "./build": {
80
- "types": "./dist/build/index.d.ts",
81
- "import": {
82
- "development": "./dist/build/index.dev.mjs",
83
- "production": "./dist/build/index.prod.mjs",
84
- "default": "./dist/build/index.mjs"
85
- },
86
- "require": {
87
- "development": "./dist/build/index.dev.cjs",
88
- "production": "./dist/build/index.prod.cjs",
89
- "default": "./dist/build/index.cjs"
90
- }
91
- },
92
- "./loader": {
93
- "types": "./dist/loader/index.d.ts",
94
- "import": "./dist/loader/index.mjs",
95
- "require": "./dist/loader/index.cjs"
96
- },
97
- "./insights": {
98
- "types": "./dist/insights/index.d.ts",
99
- "import": "./dist/insights/index.qwik.mjs",
100
- "require": "./dist/insights/index.qwik.cjs"
101
- },
102
- "./insights/vite": {
103
- "types": "./dist/insights/vite/index.d.ts",
104
- "import": "./dist/insights/vite/index.mjs",
105
- "require": "./dist/insights/vite/index.cjs"
20
+ "types": "./lib/types/index.qwik.d.ts",
21
+ "import": "./lib/index.qwik.mjs",
22
+ "require": "./lib/index.qwik.cjs"
106
23
  },
107
- "./optimizer.cjs": "./dist/optimizer.cjs",
108
- "./optimizer.mjs": "./dist/optimizer.mjs",
109
- "./optimizer": {
110
- "types": "./dist/optimizer.d.ts",
111
- "import": "./dist/optimizer.mjs",
112
- "require": "./dist/optimizer.cjs"
113
- },
114
- "./server.cjs": "./dist/server.cjs",
115
- "./server.mjs": "./dist/server.mjs",
116
- "./server": {
117
- "types": "./server.d.ts",
118
- "import": "./dist/server.mjs",
119
- "require": "./dist/server.cjs"
120
- },
121
- "./testing": {
122
- "types": "./dist/testing/index.d.ts",
123
- "import": "./dist/testing/index.mjs",
124
- "require": "./dist/testing/index.cjs"
125
- },
126
- "./qwikloader.js": "./dist/qwikloader.js",
127
- "./qwikloader.debug.js": "./dist/qwikloader.debug.js",
128
- "./qwik-prefetch.js": "./dist/qwik-prefetch.js",
129
- "./qwik-prefetch.debug.js": "./dist/qwik-prefetch.debug.js",
130
- "./package.json": "./dist/package.json"
24
+ "./vite": {
25
+ "types": "./lib/types/vite.d.ts",
26
+ "import": "./lib/vite.mjs",
27
+ "require": "./lib/vite.cjs"
28
+ }
131
29
  },
132
- "exports_annotation": "We use the build for the optimizer because esbuild doesn't like the html?raw imports in the server plugin and it's only used in the vite configs",
133
30
  "files": [
134
- "README.md",
135
- "LICENSE",
136
- "dist",
137
- "bindings",
138
- "build.d.ts",
139
- "cli.d.ts",
140
- "jsx-dev-runtime.d.ts",
141
- "jsx-runtime.d.ts",
142
- "loader.d.ts",
143
- "optimizer.d.ts",
144
- "public.d.ts",
145
- "server.d.ts",
146
- "testing.d.ts",
147
- "qwik-cli.cjs"
31
+ "lib",
32
+ "vite"
148
33
  ],
149
34
  "homepage": "https://qwik.dev/",
150
- "keywords": [
151
- "Builder.io",
152
- "framework",
153
- "generator",
154
- "prerender",
155
- "server-side-render",
156
- "ssg",
157
- "ssr",
158
- "static-site",
159
- "static-site-generator",
160
- "webapp",
161
- "website"
162
- ],
163
35
  "license": "MIT",
164
- "main": "./src/index.ts",
36
+ "main": "./lib/index.qwik.mjs",
165
37
  "peerDependencies": {
166
- "prettier": "*",
38
+ "@types/react": "^18",
39
+ "@types/react-dom": "^18",
40
+ "react": "^18",
41
+ "react-dom": "^18",
167
42
  "vite": "^5",
168
- "vitest": "^2"
43
+ "@qwik.dev/core": "^2.0.0-alpha.1"
169
44
  },
170
- "peerDependenciesMeta": {
171
- "vitest": {
172
- "optional": true
173
- },
174
- "prettier": {
175
- "optional": true
176
- }
45
+ "qwik": "./lib/index.qwik.mjs",
46
+ "publishConfig": {
47
+ "access": "public"
177
48
  },
178
49
  "repository": {
179
50
  "type": "git",
180
51
  "url": "https://github.com/QwikDev/qwik.git",
181
- "directory": "packages/qwik"
182
- },
183
- "scripts": {
184
- "build.insights": "cd src/insights && vite build --mode lib --emptyOutDir"
52
+ "directory": "packages/qwik-react"
185
53
  },
186
54
  "type": "module",
187
- "types": "./dist/core.d.ts"
188
- }
55
+ "types": "./lib/types/index.qwik.d.ts",
56
+ "scripts": {
57
+ "build": "npm run build.lib",
58
+ "build.client": "vite build",
59
+ "build.lib": "vite build --mode lib",
60
+ "build.ssr": "vite build --ssr src/entry.ssr.tsx",
61
+ "dev": "vite",
62
+ "dev.debug": "node --inspect-brk ../../node_modules/vite/bin/vite.js --mode ssr --force",
63
+ "dev.ssr": "vite --mode ssr",
64
+ "fmt": "prettier --write .",
65
+ "fmt.check": "prettier --check .",
66
+ "lint": "eslint \"src/**/*.ts*\"",
67
+ "release": "pnpm run -w build.local && pnpm publish",
68
+ "start": "npm run dev",
69
+ "typecheck": "tsc --noEmit"
70
+ }
71
+ }