@qwik.dev/react 2.0.0-beta.39 → 2.0.0-beta.40
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/index.qwik.mjs +381 -436
- package/lib/q-manifest.json +7 -6
- package/lib/vite.mjs +19 -28
- package/package.json +5 -5
package/lib/index.qwik.mjs
CHANGED
|
@@ -1,458 +1,403 @@
|
|
|
1
|
-
|
|
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 { useSignal, isServer, useOn, useOnDocument, inlinedQrl, _captures, _jsxSorted, _jsxSplit, _wrapProp, Slot, jsx, componentQrl, useStylesScopedQrl, useStore, useTaskQrl, isBrowser, noSerialize, RenderOnce, SkipRender, implicit$FirstArg } from "@qwik.dev/core";
|
|
1
|
+
import { RenderOnce, SkipRender, Slot, _captures, _jsxSorted, _jsxSplit, _wrapProp, componentQrl, implicit$FirstArg, inlinedQrl, isBrowser, isServer, jsx, noSerialize, useOn, useOnDocument, useSignal, useStore, useStylesScopedQrl, useTaskQrl } from "@qwik.dev/core";
|
|
5
2
|
import { Fragment } from "@qwik.dev/core/jsx-runtime";
|
|
6
|
-
import {
|
|
7
|
-
import { renderToString } from "react-dom/server";
|
|
8
|
-
import { createElement, createContext, Component, createRef } from "react";
|
|
3
|
+
import { SSRComment, SSRRaw, SSRStream, _addProjection, _getContextContainer, _getContextHostElement, _removeProjection, _setProjectionTarget, _updateProjectionProps } from "@qwik.dev/core/internal";
|
|
9
4
|
import { createRoot, hydrateRoot } from "react-dom/client";
|
|
10
5
|
import { flushSync } from "react-dom";
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
}
|
|
35
|
-
}
|
|
36
|
-
render() {
|
|
37
|
-
return createElement("q-slotc", {
|
|
38
|
-
class: this.context.scopeId,
|
|
39
|
-
suppressHydrationWarning: true,
|
|
40
|
-
dangerouslySetInnerHTML: {
|
|
41
|
-
__html: "<!--SLOT-->"
|
|
42
|
-
},
|
|
43
|
-
ref: this.slotC
|
|
44
|
-
});
|
|
45
|
-
}
|
|
6
|
+
import { renderToString } from "react-dom/server";
|
|
7
|
+
import { Component, createContext, createElement, createRef } from "react";
|
|
8
|
+
function _typeof(o) {
|
|
9
|
+
"@babel/helpers - typeof";
|
|
10
|
+
return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function(o) {
|
|
11
|
+
return typeof o;
|
|
12
|
+
} : function(o) {
|
|
13
|
+
return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o;
|
|
14
|
+
}, _typeof(o);
|
|
15
|
+
}
|
|
16
|
+
function toPrimitive(t, r) {
|
|
17
|
+
if ("object" != _typeof(t) || !t) return t;
|
|
18
|
+
var e = t[Symbol.toPrimitive];
|
|
19
|
+
if (void 0 !== e) {
|
|
20
|
+
var i = e.call(t, r || "default");
|
|
21
|
+
if ("object" != _typeof(i)) return i;
|
|
22
|
+
throw new TypeError("@@toPrimitive must return a primitive value.");
|
|
23
|
+
}
|
|
24
|
+
return ("string" === r ? String : Number)(t);
|
|
25
|
+
}
|
|
26
|
+
function toPropertyKey(t) {
|
|
27
|
+
var i = toPrimitive(t, "string");
|
|
28
|
+
return "symbol" == _typeof(i) ? i : i + "";
|
|
46
29
|
}
|
|
47
|
-
|
|
30
|
+
function _defineProperty(e, r, t) {
|
|
31
|
+
return (r = toPropertyKey(r)) in e ? Object.defineProperty(e, r, {
|
|
32
|
+
value: t,
|
|
33
|
+
enumerable: !0,
|
|
34
|
+
configurable: !0,
|
|
35
|
+
writable: !0
|
|
36
|
+
}) : e[r] = t, e;
|
|
37
|
+
}
|
|
38
|
+
var SlotCtx = createContext({ scopeId: "" });
|
|
39
|
+
var QwikProjectionCtx = createContext(null);
|
|
40
|
+
var SlotElement = class extends Component {
|
|
41
|
+
constructor(..._args) {
|
|
42
|
+
super(..._args);
|
|
43
|
+
_defineProperty(this, "slotC", createRef());
|
|
44
|
+
}
|
|
45
|
+
shouldComponentUpdate() {
|
|
46
|
+
return false;
|
|
47
|
+
}
|
|
48
|
+
componentDidMount() {
|
|
49
|
+
const slotC = this.slotC.current;
|
|
50
|
+
if (slotC) {
|
|
51
|
+
const { attachedEl, el } = this.context;
|
|
52
|
+
if (el) {
|
|
53
|
+
if (!attachedEl) slotC.appendChild(el);
|
|
54
|
+
else if (attachedEl !== slotC) throw new Error("already attached");
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
render() {
|
|
59
|
+
return createElement("q-slotc", {
|
|
60
|
+
class: this.context.scopeId,
|
|
61
|
+
suppressHydrationWarning: true,
|
|
62
|
+
dangerouslySetInnerHTML: { __html: "<!--SLOT-->" },
|
|
63
|
+
ref: this.slotC
|
|
64
|
+
});
|
|
65
|
+
}
|
|
66
|
+
};
|
|
67
|
+
_defineProperty(SlotElement, "contextType", SlotCtx);
|
|
48
68
|
function mainExactProps(slotEl, scopeId, RootCmp, props, projectionState) {
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
}
|
|
66
|
-
return tree;
|
|
69
|
+
let tree = createElement(SlotCtx.Provider, {
|
|
70
|
+
value: {
|
|
71
|
+
el: slotEl,
|
|
72
|
+
scopeId,
|
|
73
|
+
attachedEl: void 0
|
|
74
|
+
},
|
|
75
|
+
children: createElement(RootCmp, {
|
|
76
|
+
...props,
|
|
77
|
+
children: createElement(SlotElement, null)
|
|
78
|
+
})
|
|
79
|
+
});
|
|
80
|
+
if (projectionState) tree = createElement(QwikProjectionCtx.Provider, {
|
|
81
|
+
value: projectionState,
|
|
82
|
+
children: tree
|
|
83
|
+
});
|
|
84
|
+
return tree;
|
|
67
85
|
}
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
useOn("mouseover", activate);
|
|
94
|
-
}
|
|
95
|
-
if (clientEvent) {
|
|
96
|
-
useOn(clientEvent, activate);
|
|
97
|
-
}
|
|
98
|
-
if (opts?.event) {
|
|
99
|
-
useOn(opts?.event, activate);
|
|
100
|
-
}
|
|
101
|
-
}
|
|
102
|
-
return [
|
|
103
|
-
signal,
|
|
104
|
-
clientOnly,
|
|
105
|
-
activate
|
|
106
|
-
];
|
|
86
|
+
var useWakeupSignal = (props, opts = {}) => {
|
|
87
|
+
const signal = useSignal(false);
|
|
88
|
+
const activate = /*#__PURE__*/ inlinedQrl(() => {
|
|
89
|
+
const signal = _captures[0];
|
|
90
|
+
return signal.value = true;
|
|
91
|
+
}, "useWakeupSignal_activate_bbwdFkXhIMU", [signal]);
|
|
92
|
+
const clientOnly = !!(props["client:only"] || props["qwik:only"] || opts?.clientOnly);
|
|
93
|
+
const clientVisible = props["client:visible"] || props["qwik:visible"] || opts?.eagerness === "visible";
|
|
94
|
+
const clientIdle = props["client:idle"] || props["qwik:idle"] || opts?.eagerness === "idle";
|
|
95
|
+
const clientLoad = props["client:load"] || props["qwik:load"] || clientOnly || opts?.eagerness === "load";
|
|
96
|
+
const clientHover = props["client:hover"] || props["qwik:hover"] || opts?.eagerness === "hover";
|
|
97
|
+
const clientEvent = props["client:event"] || props["qwik:event"];
|
|
98
|
+
if (isServer) {
|
|
99
|
+
if (clientVisible) useOn("qvisible", activate);
|
|
100
|
+
if (clientIdle) useOnDocument("qidle", activate);
|
|
101
|
+
if (clientLoad) useOnDocument("qinit", activate);
|
|
102
|
+
if (clientHover) useOn("mouseover", activate);
|
|
103
|
+
if (clientEvent) useOn(clientEvent, activate);
|
|
104
|
+
if (opts?.event) useOn(opts?.event, activate);
|
|
105
|
+
}
|
|
106
|
+
return [
|
|
107
|
+
signal,
|
|
108
|
+
clientOnly,
|
|
109
|
+
activate
|
|
110
|
+
];
|
|
107
111
|
};
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
112
|
+
var HOST_PREFIX = "host:";
|
|
113
|
+
var getReactProps = (props) => {
|
|
114
|
+
const obj = {};
|
|
115
|
+
Object.keys(props).forEach((key) => {
|
|
116
|
+
if (!key.startsWith("client:") && !key.startsWith("qwik:") && !key.startsWith(HOST_PREFIX)) {
|
|
117
|
+
const normalizedKey = key.endsWith("$") ? key.slice(0, -1) : key;
|
|
118
|
+
obj[normalizedKey] = props[key];
|
|
119
|
+
}
|
|
120
|
+
});
|
|
121
|
+
return obj;
|
|
118
122
|
};
|
|
119
123
|
function main(slotEl, scopeId, RootCmp, props, projectionState) {
|
|
120
|
-
|
|
121
|
-
return mainExactProps(slotEl, scopeId, RootCmp, newProps, projectionState);
|
|
124
|
+
return mainExactProps(slotEl, scopeId, RootCmp, getReactProps(props), projectionState);
|
|
122
125
|
}
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
});
|
|
130
|
-
return obj;
|
|
126
|
+
var getHostProps = (props) => {
|
|
127
|
+
const obj = {};
|
|
128
|
+
Object.keys(props).forEach((key) => {
|
|
129
|
+
if (key.startsWith(HOST_PREFIX)) obj[key.slice(5)] = props[key];
|
|
130
|
+
});
|
|
131
|
+
return obj;
|
|
131
132
|
};
|
|
132
|
-
|
|
133
|
+
var _ssrProjectionRegistry = null;
|
|
133
134
|
function setSSRProjectionRegistry(registry) {
|
|
134
|
-
|
|
135
|
+
_ssrProjectionRegistry = registry;
|
|
135
136
|
}
|
|
136
137
|
function getSSRProjectionRegistry() {
|
|
137
|
-
|
|
138
|
+
return _ssrProjectionRegistry;
|
|
138
139
|
}
|
|
139
|
-
|
|
140
|
+
var SLOT_MARKER = "<!--SLOT-->";
|
|
140
141
|
function splitHtmlAtMarkers(html) {
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
lastIndex = match.index + match[0].length;
|
|
163
|
-
}
|
|
164
|
-
if (lastIndex < html.length) {
|
|
165
|
-
segments.push({
|
|
166
|
-
type: "html",
|
|
167
|
-
content: html.slice(lastIndex)
|
|
168
|
-
});
|
|
169
|
-
}
|
|
170
|
-
return segments;
|
|
142
|
+
const MARKER_RE = /<!--(?:SLOT|QWIK-PROJ:(.*?))-->/g;
|
|
143
|
+
const segments = [];
|
|
144
|
+
let lastIndex = 0;
|
|
145
|
+
let match;
|
|
146
|
+
while ((match = MARKER_RE.exec(html)) !== null) {
|
|
147
|
+
if (match.index > lastIndex) segments.push({
|
|
148
|
+
type: "html",
|
|
149
|
+
content: html.slice(lastIndex, match.index)
|
|
150
|
+
});
|
|
151
|
+
if (match[1] !== void 0) segments.push({
|
|
152
|
+
type: "proj",
|
|
153
|
+
slotName: match[1]
|
|
154
|
+
});
|
|
155
|
+
else segments.push({ type: "slot" });
|
|
156
|
+
lastIndex = match.index + match[0].length;
|
|
157
|
+
}
|
|
158
|
+
if (lastIndex < html.length) segments.push({
|
|
159
|
+
type: "html",
|
|
160
|
+
content: html.slice(lastIndex)
|
|
161
|
+
});
|
|
162
|
+
return segments;
|
|
171
163
|
}
|
|
172
164
|
async function renderFromServer(Host, reactCmp$, scopeId, props, ref, slotRef, hydrationProps) {
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
yield /* @__PURE__ */ _jsxSorted(SSRComment, null, {
|
|
214
|
-
data: "q:container-island"
|
|
215
|
-
}, null, 3, "cl_6");
|
|
216
|
-
const QwikComp = await entry.qrl.resolve();
|
|
217
|
-
yield jsx(QwikComp, entry.props);
|
|
218
|
-
yield /* @__PURE__ */ _jsxSorted(SSRComment, null, {
|
|
219
|
-
data: "/q:container-island"
|
|
220
|
-
}, null, 3, "cl_7");
|
|
221
|
-
}
|
|
222
|
-
}
|
|
223
|
-
}
|
|
224
|
-
yield /* @__PURE__ */ _jsxSorted(SSRComment, null, {
|
|
225
|
-
data: "/q:ignore"
|
|
226
|
-
}, null, 3, "cl_8");
|
|
227
|
-
}, 1, "cl_9"), 0, "cl_10"),
|
|
228
|
-
!hasSlot && /* @__PURE__ */ _jsxSorted("q-slot", {
|
|
229
|
-
ref: slotRef
|
|
230
|
-
}, null, /* @__PURE__ */ _jsxSorted(Slot, null, null, null, 3, "cl_11"), 1, "cl_12")
|
|
231
|
-
], 1, "cl_13");
|
|
232
|
-
}
|
|
233
|
-
return /* @__PURE__ */ _jsxSorted(Fragment, null, null, [
|
|
234
|
-
/* @__PURE__ */ _jsxSorted(Host, {
|
|
235
|
-
ref
|
|
236
|
-
}, null, [
|
|
237
|
-
/* @__PURE__ */ _jsxSorted(SSRComment, null, {
|
|
238
|
-
data: "q:container=html"
|
|
239
|
-
}, null, 3, "cl_14"),
|
|
240
|
-
/* @__PURE__ */ _jsxSorted(SSRRaw, {
|
|
241
|
-
data: html
|
|
242
|
-
}, null, null, 3, "cl_15"),
|
|
243
|
-
/* @__PURE__ */ _jsxSorted(SSRComment, null, {
|
|
244
|
-
data: "/q:container"
|
|
245
|
-
}, null, 3, "cl_16")
|
|
246
|
-
], 1, "cl_17"),
|
|
247
|
-
/* @__PURE__ */ _jsxSorted("q-slot", {
|
|
248
|
-
ref: slotRef
|
|
249
|
-
}, null, /* @__PURE__ */ _jsxSorted(Slot, null, null, null, 3, "cl_18"), 1, null)
|
|
250
|
-
], 1, "cl_19");
|
|
251
|
-
}
|
|
165
|
+
if (isServer) {
|
|
166
|
+
const Cmp = await reactCmp$.resolve();
|
|
167
|
+
const newProps = getReactProps(props);
|
|
168
|
+
Object.assign(hydrationProps, newProps);
|
|
169
|
+
const registry = { entries: /* @__PURE__ */ new Map() };
|
|
170
|
+
setSSRProjectionRegistry(registry);
|
|
171
|
+
const html = renderToString(mainExactProps(void 0, scopeId, Cmp, newProps));
|
|
172
|
+
setSSRProjectionRegistry(null);
|
|
173
|
+
const hasSlot = html.includes(SLOT_MARKER);
|
|
174
|
+
const hasProj = registry.entries.size > 0;
|
|
175
|
+
if (hasSlot || hasProj) {
|
|
176
|
+
const segments = splitHtmlAtMarkers(html);
|
|
177
|
+
return /*#__PURE__*/ _jsxSorted(Fragment, null, null, [/*#__PURE__*/ _jsxSplit(Host, {
|
|
178
|
+
ref,
|
|
179
|
+
...getHostProps(props)
|
|
180
|
+
}, null, /*#__PURE__*/ _jsxSorted(SSRStream, null, null, async function* () {
|
|
181
|
+
yield /*#__PURE__*/ _jsxSorted(SSRComment, null, { data: "q:ignore" }, null, 3, "cl_0");
|
|
182
|
+
for (const segment of segments) if (segment.type === "html") yield /*#__PURE__*/ _jsxSorted(SSRRaw, { data: _wrapProp(segment, "content") }, null, null, 3, "cl_1");
|
|
183
|
+
else if (segment.type === "slot") {
|
|
184
|
+
yield /*#__PURE__*/ _jsxSorted(SSRComment, null, { data: "q:container-island" }, null, 3, "cl_2");
|
|
185
|
+
yield /*#__PURE__*/ _jsxSorted("q-slot", { ref: slotRef }, null, /*#__PURE__*/ _jsxSorted(Slot, null, null, null, 3, "cl_3"), 1, "cl_4");
|
|
186
|
+
yield /*#__PURE__*/ _jsxSorted(SSRComment, null, { data: "/q:container-island" }, null, 3, "cl_5");
|
|
187
|
+
} else if (segment.type === "proj") {
|
|
188
|
+
const entry = registry.entries.get(segment.slotName);
|
|
189
|
+
if (entry) {
|
|
190
|
+
yield /*#__PURE__*/ _jsxSorted(SSRComment, null, { data: "q:container-island" }, null, 3, "cl_6");
|
|
191
|
+
const QwikComp = await entry.qrl.resolve();
|
|
192
|
+
yield jsx(QwikComp, entry.props);
|
|
193
|
+
yield /*#__PURE__*/ _jsxSorted(SSRComment, null, { data: "/q:container-island" }, null, 3, "cl_7");
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
yield /*#__PURE__*/ _jsxSorted(SSRComment, null, { data: "/q:ignore" }, null, 3, "cl_8");
|
|
197
|
+
}, 1, "cl_9"), 0, "cl_10"), !hasSlot && /*#__PURE__*/ _jsxSorted("q-slot", { ref: slotRef }, null, /*#__PURE__*/ _jsxSorted(Slot, null, null, null, 3, "cl_11"), 1, "cl_12")], 1, "cl_13");
|
|
198
|
+
}
|
|
199
|
+
return /*#__PURE__*/ _jsxSorted(Fragment, null, null, [/*#__PURE__*/ _jsxSorted(Host, { ref }, null, [
|
|
200
|
+
/*#__PURE__*/ _jsxSorted(SSRComment, null, { data: "q:container=html" }, null, 3, "cl_14"),
|
|
201
|
+
/*#__PURE__*/ _jsxSorted(SSRRaw, { data: html }, null, null, 3, "cl_15"),
|
|
202
|
+
/*#__PURE__*/ _jsxSorted(SSRComment, null, { data: "/q:container" }, null, 3, "cl_16")
|
|
203
|
+
], 1, "cl_17"), /*#__PURE__*/ _jsxSorted("q-slot", { ref: slotRef }, null, /*#__PURE__*/ _jsxSorted(Slot, null, null, null, 3, "cl_18"), 1, null)], 1, "cl_19");
|
|
204
|
+
}
|
|
252
205
|
}
|
|
253
206
|
function qwikifyQrl(reactCmp$, opts) {
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
queueMicrotask(() => root.unmount());
|
|
326
|
-
}
|
|
327
|
-
});
|
|
328
|
-
}
|
|
329
|
-
}, "qwikifyQrl_component_useTask_1_mwaGrLCLc2w", [
|
|
330
|
-
internalState,
|
|
331
|
-
signal
|
|
332
|
-
]));
|
|
333
|
-
if (isServer && !isClientOnly) {
|
|
334
|
-
const jsx2 = renderFromServer(TagName, reactCmp$2, stylesscoped$.scopeId, props, hostRef, slotRef, hydrationKeys);
|
|
335
|
-
return /* @__PURE__ */ _jsxSorted(RenderOnce, null, null, jsx2, 1, 2);
|
|
336
|
-
}
|
|
337
|
-
return /* @__PURE__ */ _jsxSorted(Fragment, null, null, [
|
|
338
|
-
/* @__PURE__ */ _jsxSplit(TagName, {
|
|
339
|
-
...getHostProps(props)
|
|
340
|
-
}, {
|
|
341
|
-
ref: (el) => {
|
|
342
|
-
if (isBrowser) {
|
|
343
|
-
queueMicrotask(() => {
|
|
344
|
-
const internalData = internalState.value;
|
|
345
|
-
if (internalData && !internalData.root) {
|
|
346
|
-
const root = internalData.root = createRoot(el);
|
|
347
|
-
root.render(main(slotRef.value, stylesscoped$.scopeId, internalData.cmp, props, internalData.projectionState));
|
|
348
|
-
}
|
|
349
|
-
});
|
|
350
|
-
} else {
|
|
351
|
-
hostRef.value = el;
|
|
352
|
-
}
|
|
353
|
-
}
|
|
354
|
-
}, SkipRender, 0, "sV_0"),
|
|
355
|
-
/* @__PURE__ */ _jsxSorted("q-slot", {
|
|
356
|
-
ref: slotRef
|
|
357
|
-
}, null, /* @__PURE__ */ _jsxSorted(Slot, null, null, null, 3, "sV_1"), 1, null)
|
|
358
|
-
], 1, "sV_2");
|
|
359
|
-
}, "qwikifyQrl_component_5bB3apdeFTY", [
|
|
360
|
-
opts,
|
|
361
|
-
reactCmp$
|
|
362
|
-
]));
|
|
207
|
+
return /*#__PURE__*/ componentQrl(/*#__PURE__*/ inlinedQrl((props) => {
|
|
208
|
+
const opts = _captures[0], reactCmp$ = _captures[1];
|
|
209
|
+
const stylesscoped$ = useStylesScopedQrl(/*#__PURE__*/ inlinedQrl(`q-slot{display:none} q-slotc,q-slotc>q-slot{display:contents}`, "qwikifyQrl_component_stylesscoped_useStylesScoped_5NfcSvFabPo"));
|
|
210
|
+
const hostRef = useSignal();
|
|
211
|
+
const slotRef = useSignal();
|
|
212
|
+
const internalState = useSignal();
|
|
213
|
+
const [signal, isClientOnly] = useWakeupSignal(props, opts);
|
|
214
|
+
const hydrationKeys = useStore({});
|
|
215
|
+
const TagName = opts?.tagName ?? "qwik-react";
|
|
216
|
+
useTaskQrl(/*#__PURE__*/ inlinedQrl(async ({ track }) => {
|
|
217
|
+
const hostRef = _captures[0], hydrationKeys = _captures[1], internalState = _captures[2], isClientOnly = _captures[3], props = _captures[4], reactCmp$ = _captures[5], signal = _captures[6], slotRef = _captures[7], stylesscoped$ = _captures[8];
|
|
218
|
+
const trackedProps = track(() => ({ ...props }));
|
|
219
|
+
track(signal);
|
|
220
|
+
if (!isBrowser) return;
|
|
221
|
+
let projectionState = null;
|
|
222
|
+
const container = _getContextContainer();
|
|
223
|
+
const hostVNode = _getContextHostElement();
|
|
224
|
+
if (container && hostVNode) projectionState = {
|
|
225
|
+
parentVNode: hostVNode,
|
|
226
|
+
container
|
|
227
|
+
};
|
|
228
|
+
if (internalState.value) {
|
|
229
|
+
if (internalState.value.root) internalState.value.root.render(main(slotRef.value, stylesscoped$.scopeId, internalState.value.cmp, trackedProps, internalState.value.projectionState));
|
|
230
|
+
} else {
|
|
231
|
+
let root = void 0;
|
|
232
|
+
const Cmp = await reactCmp$.resolve();
|
|
233
|
+
const hostElement = hostRef.value;
|
|
234
|
+
if (hostElement) {
|
|
235
|
+
if (isClientOnly) root = createRoot(hostElement);
|
|
236
|
+
else root = flushSync(() => {
|
|
237
|
+
return hydrateRoot(hostElement, mainExactProps(slotRef.value, stylesscoped$.scopeId, Cmp, hydrationKeys, projectionState));
|
|
238
|
+
});
|
|
239
|
+
if (isClientOnly || signal.value === false) root.render(main(slotRef.value, stylesscoped$.scopeId, Cmp, trackedProps, projectionState));
|
|
240
|
+
}
|
|
241
|
+
internalState.value = noSerialize({
|
|
242
|
+
cmp: Cmp,
|
|
243
|
+
root,
|
|
244
|
+
projectionState
|
|
245
|
+
});
|
|
246
|
+
}
|
|
247
|
+
}, "qwikifyQrl_component_useTask_JuFeaMCL0P0", [
|
|
248
|
+
hostRef,
|
|
249
|
+
hydrationKeys,
|
|
250
|
+
internalState,
|
|
251
|
+
isClientOnly,
|
|
252
|
+
props,
|
|
253
|
+
reactCmp$,
|
|
254
|
+
signal,
|
|
255
|
+
slotRef,
|
|
256
|
+
stylesscoped$
|
|
257
|
+
]));
|
|
258
|
+
useTaskQrl(/*#__PURE__*/ inlinedQrl(({ track, cleanup }) => {
|
|
259
|
+
const internalState = _captures[0], signal = _captures[1];
|
|
260
|
+
track(signal);
|
|
261
|
+
if (isBrowser) cleanup(() => {
|
|
262
|
+
const root = internalState.value?.root;
|
|
263
|
+
if (root) queueMicrotask(() => root.unmount());
|
|
264
|
+
});
|
|
265
|
+
}, "qwikifyQrl_component_useTask_1_mwaGrLCLc2w", [internalState, signal]));
|
|
266
|
+
if (isServer && !isClientOnly) {
|
|
267
|
+
const jsx = renderFromServer(TagName, reactCmp$, stylesscoped$.scopeId, props, hostRef, slotRef, hydrationKeys);
|
|
268
|
+
return /*#__PURE__*/ _jsxSorted(RenderOnce, null, null, jsx, 1, 2);
|
|
269
|
+
}
|
|
270
|
+
return /*#__PURE__*/ _jsxSorted(Fragment, null, null, [/*#__PURE__*/ _jsxSplit(TagName, { ...getHostProps(props) }, { ref: (el) => {
|
|
271
|
+
if (isBrowser) queueMicrotask(() => {
|
|
272
|
+
const internalData = internalState.value;
|
|
273
|
+
if (internalData && !internalData.root) (internalData.root = createRoot(el)).render(main(slotRef.value, stylesscoped$.scopeId, internalData.cmp, props, internalData.projectionState));
|
|
274
|
+
});
|
|
275
|
+
else hostRef.value = el;
|
|
276
|
+
} }, SkipRender, 0, "sV_0"), /*#__PURE__*/ _jsxSorted("q-slot", { ref: slotRef }, null, /*#__PURE__*/ _jsxSorted(Slot, null, null, null, 3, "sV_1"), 1, null)], 1, "sV_2");
|
|
277
|
+
}, "qwikifyQrl_component_5bB3apdeFTY", [opts, reactCmp$]));
|
|
363
278
|
}
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
279
|
+
var qwikify$ = /*#__PURE__*/ implicit$FirstArg(qwikifyQrl);
|
|
280
|
+
var slotCounter = 0;
|
|
281
|
+
/**
|
|
282
|
+
* Creates a React component that renders a Qwik component inside a qwikify$ React tree.
|
|
283
|
+
*
|
|
284
|
+
* This is the QRL form. Use `reactify$` for the convenience form with automatic `$()` wrapping.
|
|
285
|
+
*
|
|
286
|
+
* The returned React component must be rendered inside a `qwikify$()` React tree. It creates a div
|
|
287
|
+
* that Qwik renders into, while React ignores its contents.
|
|
288
|
+
*
|
|
289
|
+
* During SSR, a marker is emitted so that server-render.tsx can render the Qwik component inline
|
|
290
|
+
* inside `q:container-island` comments. On the client, Qwik resumes the SSR content naturally
|
|
291
|
+
* (events, signals, state are all serialized). For pure CSR, `_addProjection` renders from
|
|
292
|
+
* scratch.
|
|
293
|
+
*
|
|
294
|
+
* @param qwikCompQrl - A QRL wrapping a Qwik component (created with `component$`)
|
|
295
|
+
* @returns A React component that renders the Qwik component
|
|
296
|
+
*/ function reactifyQrl(qwikCompQrl) {
|
|
297
|
+
class QwikInReact extends Component {
|
|
298
|
+
constructor(..._args) {
|
|
299
|
+
super(..._args);
|
|
300
|
+
_defineProperty(this, "slotName", `_rq:${slotCounter++}`);
|
|
301
|
+
_defineProperty(this, "vnode", null);
|
|
302
|
+
_defineProperty(this, "divRef", createRef());
|
|
303
|
+
_defineProperty(this, "mounted", false);
|
|
304
|
+
_defineProperty(this, "pendingProps", null);
|
|
305
|
+
}
|
|
306
|
+
componentDidMount() {
|
|
307
|
+
this.mounted = true;
|
|
308
|
+
const projectionState = this.context;
|
|
309
|
+
if (!projectionState) {
|
|
310
|
+
if (typeof console !== "undefined") console.warn("reactify$: component must be rendered inside a qwikify$() React tree.");
|
|
311
|
+
return;
|
|
312
|
+
}
|
|
313
|
+
const div = this.divRef.current;
|
|
314
|
+
if (!div) return;
|
|
315
|
+
if (div.firstElementChild) return;
|
|
316
|
+
qwikCompQrl.resolve().then((QwikComp) => {
|
|
317
|
+
if (!this.mounted) return;
|
|
318
|
+
const name = QwikComp.displayName || QwikComp.name || "QwikComponent";
|
|
319
|
+
QwikInReact.displayName = `reactify$(${name})`;
|
|
320
|
+
const { parentVNode, container } = projectionState;
|
|
321
|
+
const reactProps = getReactProps(this.pendingProps || this.props);
|
|
322
|
+
this.vnode = _addProjection(container, parentVNode, qwikCompQrl, reactProps, this.slotName);
|
|
323
|
+
div.replaceChildren();
|
|
324
|
+
_setProjectionTarget(this.vnode, div);
|
|
325
|
+
});
|
|
326
|
+
}
|
|
327
|
+
componentWillUnmount() {
|
|
328
|
+
this.mounted = false;
|
|
329
|
+
if (this.vnode && this.context) {
|
|
330
|
+
_removeProjection(this.context.container, this.context.parentVNode, this.vnode, this.slotName);
|
|
331
|
+
this.vnode = null;
|
|
332
|
+
}
|
|
333
|
+
}
|
|
334
|
+
shouldComponentUpdate(nextProps) {
|
|
335
|
+
if (this.vnode && this.context) {
|
|
336
|
+
const reactProps = getReactProps(nextProps);
|
|
337
|
+
_updateProjectionProps(this.context.container, this.vnode, reactProps);
|
|
338
|
+
} else this.pendingProps = nextProps;
|
|
339
|
+
return false;
|
|
340
|
+
}
|
|
341
|
+
render() {
|
|
342
|
+
const registry = getSSRProjectionRegistry();
|
|
343
|
+
if (registry) {
|
|
344
|
+
const reactProps = getReactProps(this.props);
|
|
345
|
+
registry.entries.set(this.slotName, {
|
|
346
|
+
qrl: qwikCompQrl,
|
|
347
|
+
props: reactProps
|
|
348
|
+
});
|
|
349
|
+
return createElement("div", {
|
|
350
|
+
"data-qwik-projection": this.slotName,
|
|
351
|
+
suppressHydrationWarning: true,
|
|
352
|
+
dangerouslySetInnerHTML: { __html: `<!--QWIK-PROJ:${this.slotName}-->` }
|
|
353
|
+
});
|
|
354
|
+
}
|
|
355
|
+
return createElement("div", {
|
|
356
|
+
ref: this.divRef,
|
|
357
|
+
suppressHydrationWarning: true,
|
|
358
|
+
dangerouslySetInnerHTML: { __html: `<!--QWIK-PROJ:${this.slotName}-->` },
|
|
359
|
+
"data-qwik-projection": this.slotName
|
|
360
|
+
});
|
|
361
|
+
}
|
|
362
|
+
}
|
|
363
|
+
_defineProperty(QwikInReact, "contextType", QwikProjectionCtx);
|
|
364
|
+
QwikInReact.displayName = `reactify$(...)`;
|
|
365
|
+
return QwikInReact;
|
|
451
366
|
}
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
367
|
+
/**
|
|
368
|
+
* Creates a React component that renders a Qwik component inside a qwikify$ React tree.
|
|
369
|
+
*
|
|
370
|
+
* The returned React component must be rendered inside a `qwikify$()` React tree. It creates a div
|
|
371
|
+
* that Qwik renders into, while React ignores its contents.
|
|
372
|
+
*
|
|
373
|
+
* During SSR, the Qwik component is rendered as HTML inside `q:container-island` comments. On the
|
|
374
|
+
* client, the component re-renders via the external projection API.
|
|
375
|
+
*
|
|
376
|
+
* @example
|
|
377
|
+
*
|
|
378
|
+
* ```tsx
|
|
379
|
+
* import { component$ } from '@qwik.dev/core';
|
|
380
|
+
* import { qwikify$, reactify$ } from '@qwik.dev/react';
|
|
381
|
+
*
|
|
382
|
+
* const QwikCounter = component$(() => {
|
|
383
|
+
* const count = useSignal(0);
|
|
384
|
+
* return <button onClick$={() => count.value++}>{count.value}</button>;
|
|
385
|
+
* });
|
|
386
|
+
*
|
|
387
|
+
* const ReactCounter = reactify$(QwikCounter);
|
|
388
|
+
*
|
|
389
|
+
* const ReactApp = ({ children }) => (
|
|
390
|
+
* <div>
|
|
391
|
+
* <h1>React App</h1>
|
|
392
|
+
* <ReactCounter />
|
|
393
|
+
* {children}
|
|
394
|
+
* </div>
|
|
395
|
+
* );
|
|
396
|
+
*
|
|
397
|
+
* export const QwikifiedApp = qwikify$(ReactApp);
|
|
398
|
+
* ```
|
|
399
|
+
*
|
|
400
|
+
* @param qwikComp - A Qwik component (created with `component$`)
|
|
401
|
+
* @returns A React component that renders the Qwik component
|
|
402
|
+
*/ var reactify$ = /*#__PURE__*/ implicit$FirstArg(reactifyQrl);
|
|
403
|
+
export { qwikify$, qwikifyQrl, reactify$, reactifyQrl };
|
package/lib/q-manifest.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": "1",
|
|
3
|
-
"manifestHash": "
|
|
3
|
+
"manifestHash": "4qq332",
|
|
4
4
|
"options": {
|
|
5
5
|
"target": "lib",
|
|
6
6
|
"buildMode": "development",
|
|
@@ -13,10 +13,11 @@
|
|
|
13
13
|
"mapping": {},
|
|
14
14
|
"bundles": {
|
|
15
15
|
"../index.qwik.mjs": {
|
|
16
|
-
"size":
|
|
17
|
-
"total":
|
|
16
|
+
"size": 16446,
|
|
17
|
+
"total": 16446,
|
|
18
18
|
"origins": [
|
|
19
19
|
"src/index.qwik.ts",
|
|
20
|
+
"src/react/client.tsx",
|
|
20
21
|
"src/react/qwikify.tsx",
|
|
21
22
|
"src/react/reactify.ts",
|
|
22
23
|
"src/react/server-render.tsx",
|
|
@@ -25,8 +26,8 @@
|
|
|
25
26
|
"interactivity": 0
|
|
26
27
|
},
|
|
27
28
|
"../vite.mjs": {
|
|
28
|
-
"size":
|
|
29
|
-
"total":
|
|
29
|
+
"size": 396,
|
|
30
|
+
"total": 396,
|
|
30
31
|
"origins": [
|
|
31
32
|
"src/vite.ts"
|
|
32
33
|
],
|
|
@@ -42,7 +43,7 @@
|
|
|
42
43
|
"symbols": {},
|
|
43
44
|
"platform": {
|
|
44
45
|
"vite": "",
|
|
45
|
-
"rollup": "4.
|
|
46
|
+
"rollup": "4.23.0",
|
|
46
47
|
"env": "node",
|
|
47
48
|
"os": "linux",
|
|
48
49
|
"node": "24.15.0"
|
package/lib/vite.mjs
CHANGED
|
@@ -1,30 +1,21 @@
|
|
|
1
1
|
function qwikReact() {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
},
|
|
21
|
-
optimizeDeps: {
|
|
22
|
-
include: OPTIMIZE_DEPS
|
|
23
|
-
}
|
|
24
|
-
};
|
|
25
|
-
}
|
|
26
|
-
};
|
|
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 = ["react", "react-dom"];
|
|
11
|
+
return {
|
|
12
|
+
name: "vite-plugin-qwik-react",
|
|
13
|
+
config() {
|
|
14
|
+
return {
|
|
15
|
+
resolve: { dedupe: DEDUPE },
|
|
16
|
+
optimizeDeps: { include: OPTIMIZE_DEPS }
|
|
17
|
+
};
|
|
18
|
+
}
|
|
19
|
+
};
|
|
27
20
|
}
|
|
28
|
-
export {
|
|
29
|
-
qwikReact
|
|
30
|
-
};
|
|
21
|
+
export { qwikReact };
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@qwik.dev/react",
|
|
3
3
|
"description": "Qwik React allows adding React components into existing Qwik application",
|
|
4
|
-
"version": "2.0.0-beta.
|
|
4
|
+
"version": "2.0.0-beta.40",
|
|
5
5
|
"bugs": "https://github.com/QwikDev/qwik/issues",
|
|
6
6
|
"devDependencies": {
|
|
7
7
|
"@types/react": "19.2.14",
|
|
@@ -9,8 +9,8 @@
|
|
|
9
9
|
"react": "19.2.4",
|
|
10
10
|
"react-dom": "19.2.4",
|
|
11
11
|
"typescript": "5.9.3",
|
|
12
|
-
"vite": "
|
|
13
|
-
"@qwik.dev/core": "2.0.0-beta.
|
|
12
|
+
"vite": "8.2.1",
|
|
13
|
+
"@qwik.dev/core": "2.0.0-beta.40"
|
|
14
14
|
},
|
|
15
15
|
"engines": {
|
|
16
16
|
"node": "^18.17.0 || ^20.3.0 || >=21.0.0"
|
|
@@ -37,8 +37,8 @@
|
|
|
37
37
|
"@types/react-dom": "^18",
|
|
38
38
|
"react": "^18",
|
|
39
39
|
"react-dom": "^18",
|
|
40
|
-
"vite": ">=
|
|
41
|
-
"@qwik.dev/core": "^2.0.0-beta.
|
|
40
|
+
"vite": ">=8 <9",
|
|
41
|
+
"@qwik.dev/core": "^2.0.0-beta.40"
|
|
42
42
|
},
|
|
43
43
|
"publishConfig": {
|
|
44
44
|
"access": "public"
|