eddev 2.0.0-beta.38 → 2.0.0-beta.39
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/app/entry/ssr-root-client.d.ts +6 -0
- package/dist/app/entry/ssr-root.d.ts +10 -0
- package/dist/app/entry/ssr-root.js +24 -0
- package/dist/app/lib/blocks/EditableText.d.ts +41 -0
- package/dist/app/lib/blocks/EditableText.js +50 -0
- package/dist/app/lib/blocks/InnerBlocks.d.ts +52 -0
- package/dist/app/lib/blocks/InnerBlocks.js +63 -0
- package/dist/app/lib/blocks/defineBlock.d.ts +2 -0
- package/dist/app/lib/blocks/defineBlock.js +3 -0
- package/dist/app/lib/blocks/editor/controls.d.ts +10 -0
- package/dist/app/lib/blocks/editor/controls.js +20 -0
- package/dist/app/lib/blocks/index.d.ts +9 -0
- package/dist/app/lib/blocks/index.js +9 -0
- package/dist/app/lib/devtools/index.d.ts +1 -0
- package/dist/app/lib/devtools/index.js +1 -0
- package/dist/app/lib/devtools/tailwind.config.d.ts +23 -0
- package/dist/app/lib/devtools/tailwind.config.js +24 -0
- package/dist/app/lib/devtools/useQueryDebug.d.ts +15 -0
- package/dist/app/lib/devtools/useQueryDebug.js +10 -0
- package/dist/app/lib/dynamic/index.d.ts +1 -0
- package/dist/app/lib/dynamic/index.js +1 -0
- package/dist/app/lib/hooks/apiConfig.d.ts +20 -0
- package/dist/app/lib/hooks/apiConfig.js +9 -0
- package/dist/app/lib/hooks/index.d.ts +4 -0
- package/dist/app/lib/hooks/index.js +4 -0
- package/dist/app/lib/hooks/queryUtils.d.ts +49 -0
- package/dist/app/lib/hooks/queryUtils.js +182 -0
- package/dist/app/lib/hooks/useAppData.d.ts +4 -0
- package/dist/app/lib/hooks/useAppData.js +11 -0
- package/dist/app/lib/hooks/useRPC.d.ts +9 -0
- package/dist/app/lib/hooks/useRPC.js +9 -0
- package/dist/app/lib/internal/index.d.ts +4 -0
- package/dist/app/lib/internal/index.js +4 -0
- package/dist/app/lib/internal/internal-store.d.ts +9 -0
- package/dist/app/lib/internal/internal-store.js +7 -0
- package/dist/app/lib/legacy-stitches/createStitches.d.ts +615 -0
- package/dist/app/lib/legacy-stitches/createStitches.js +439 -0
- package/dist/app/lib/legacy-stitches/index.d.ts +1 -0
- package/dist/app/lib/legacy-stitches/index.js +1 -0
- package/dist/app/lib/routing/components/SSRRouter.d.ts +9 -0
- package/dist/app/lib/routing/components/SSRRouter.js +13 -0
- package/dist/app/lib/views/defineView.d.ts +4 -0
- package/dist/app/lib/views/defineView.js +3 -0
- package/dist/app/lib/views/index.d.ts +1 -0
- package/dist/app/lib/views/index.js +1 -0
- package/dist/app/server/defineRouter.d.ts +2 -0
- package/dist/app/server/defineRouter.js +4 -0
- package/dist/app/server/index.d.ts +4 -0
- package/dist/app/server/index.js +4 -0
- package/dist/app/server/proxy-wp-admin.d.ts +3 -0
- package/dist/app/server/proxy-wp-admin.js +105 -0
- package/dist/app/server/render-ssr-page.d.ts +5 -0
- package/dist/app/server/render-ssr-page.js +31 -0
- package/dist/app/server/server-context.d.ts +50 -0
- package/dist/app/server/server-context.js +145 -0
- package/dist/app/server/utils/headers.d.ts +5 -0
- package/dist/app/server/utils/headers.js +28 -0
- package/dist/app/server/utils/replace-host.d.ts +10 -0
- package/dist/app/server/utils/replace-host.js +61 -0
- package/dist/app/utils/wp.d.ts +26 -0
- package/dist/app/utils/wp.js +1 -0
- package/package.json +1 -1
|
@@ -0,0 +1,439 @@
|
|
|
1
|
+
import { createStitches as createBaseStitches, } from "../../../../stitches-archive/index.js";
|
|
2
|
+
const typeKeyMap = {
|
|
3
|
+
fontSize: "fontSizes",
|
|
4
|
+
fontFamily: "fonts",
|
|
5
|
+
lineHeight: "lineHeights",
|
|
6
|
+
letterSpacing: "letterSpacings",
|
|
7
|
+
fontWeight: "fontWeights",
|
|
8
|
+
};
|
|
9
|
+
export function parseBreakpoints(names, medias) {
|
|
10
|
+
const breakpoints = [];
|
|
11
|
+
// Add an initial breakpoint
|
|
12
|
+
breakpoints.push({ key: "initial", min: "0px", max: null });
|
|
13
|
+
// Parse each breakpoint
|
|
14
|
+
for (const key in medias) {
|
|
15
|
+
if (!names.includes(key))
|
|
16
|
+
continue;
|
|
17
|
+
const media = medias[key];
|
|
18
|
+
const minMatch = media.match(/min-width: ([0-9]+[a-z]+)/);
|
|
19
|
+
const maxMatch = media.match(/max-width: ([0-9]+[a-z]+)/);
|
|
20
|
+
if (!minMatch && !maxMatch)
|
|
21
|
+
continue;
|
|
22
|
+
breakpoints.push({
|
|
23
|
+
key,
|
|
24
|
+
min: minMatch ? minMatch[1] : null,
|
|
25
|
+
max: maxMatch ? maxMatch[1] : null,
|
|
26
|
+
});
|
|
27
|
+
}
|
|
28
|
+
// Ensure each breakpoint has a min/max value (except for first and last)
|
|
29
|
+
for (let i = 0; i < breakpoints.length; i++) {
|
|
30
|
+
const bp = breakpoints[i];
|
|
31
|
+
const prev = breakpoints[i - 1];
|
|
32
|
+
const next = breakpoints[i + 1];
|
|
33
|
+
if (bp.min === null && prev && prev.max) {
|
|
34
|
+
bp.min = prev.max;
|
|
35
|
+
}
|
|
36
|
+
if (bp.max === null && next && next.min) {
|
|
37
|
+
bp.max = next.min;
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
return breakpoints;
|
|
41
|
+
}
|
|
42
|
+
const unitless = (value) => parseFloat(value);
|
|
43
|
+
function parseTypography(theme, breakpoints, typography) {
|
|
44
|
+
const globals = {};
|
|
45
|
+
const typeVariants = {};
|
|
46
|
+
breakpoints.forEach((bp) => (globals["@" + bp.key] = {}));
|
|
47
|
+
globals["@editor"] = {};
|
|
48
|
+
const resolveValue = (scale, value) => {
|
|
49
|
+
if (typeof value === "string" && value.match(/^\$[a-z0-9\-\_]+$/)) {
|
|
50
|
+
// Single scale
|
|
51
|
+
return theme[scale][value.replace("$", "")];
|
|
52
|
+
}
|
|
53
|
+
else {
|
|
54
|
+
return value;
|
|
55
|
+
}
|
|
56
|
+
};
|
|
57
|
+
const resolveThemeVar = (scale, value) => {
|
|
58
|
+
if (typeof value === "string" && value.match(/^\$[a-z0-9\-\_]+$/)) {
|
|
59
|
+
// Single scale
|
|
60
|
+
return "$" + scale + value;
|
|
61
|
+
}
|
|
62
|
+
else {
|
|
63
|
+
return value;
|
|
64
|
+
}
|
|
65
|
+
};
|
|
66
|
+
for (const name in typography) {
|
|
67
|
+
const style = typography[name];
|
|
68
|
+
const variant = {};
|
|
69
|
+
typeVariants[name] = variant;
|
|
70
|
+
for (const key in style) {
|
|
71
|
+
const value = style[key];
|
|
72
|
+
const varName = `--type-${name}-${key}`;
|
|
73
|
+
variant[key] = `var(${varName})`;
|
|
74
|
+
const tokenPrefix = typeKeyMap[key];
|
|
75
|
+
if (typeof value === "string" || typeof value === "number") {
|
|
76
|
+
// A simple string or number value is used
|
|
77
|
+
globals["@initial"][varName] = resolveThemeVar(tokenPrefix, value);
|
|
78
|
+
}
|
|
79
|
+
else if (value && typeof value === "object") {
|
|
80
|
+
// A responsive object value
|
|
81
|
+
const unit = key === "lineHeight" ? "%" : "px";
|
|
82
|
+
const [tokenGlobals, initial] = getResponsiveObjectStyles(breakpoints, value, varName, unit);
|
|
83
|
+
for (const key in tokenGlobals) {
|
|
84
|
+
globals[key] = { ...globals[key], ...tokenGlobals[key] };
|
|
85
|
+
}
|
|
86
|
+
// const entries = Object.entries(value)
|
|
87
|
+
// entries.forEach(([bpName, responsiveValue], i) => {
|
|
88
|
+
// if (Array.isArray(responsiveValue)) {
|
|
89
|
+
// responsiveValue = responsiveValue[0]
|
|
90
|
+
// // An array in the format [value] signifies font locking between the current breakpoint and the next defined one
|
|
91
|
+
// const minSize = breakpoints.find((bp) => "@" + bp.key === bpName)?.min
|
|
92
|
+
// const nextBreakpoint = breakpoints.find((bp) => "@" + bp.key === entries[i + 1]?.[0])
|
|
93
|
+
// if (!nextBreakpoint)
|
|
94
|
+
// throw new Error(
|
|
95
|
+
// `Cannot create responsive '${key}' for '${name}' at breakpoint '${bpName}', since it is the last-defined breakpoint. Your last size should be a string/number/token.`
|
|
96
|
+
// )
|
|
97
|
+
// const maxSize = nextBreakpoint.min
|
|
98
|
+
// let responsiveValue2 = (value as any)["@" + nextBreakpoint.key]
|
|
99
|
+
// if (Array.isArray(responsiveValue2)) responsiveValue2 = responsiveValue2[0]
|
|
100
|
+
// let size1 = resolveValue(tokenPrefix, responsiveValue)
|
|
101
|
+
// let size2 = resolveValue(tokenPrefix, responsiveValue2)
|
|
102
|
+
// responsiveValue = `calc(${size1} + (100vw - ${minSize}) / (${unitless(maxSize)} - ${unitless(
|
|
103
|
+
// minSize
|
|
104
|
+
// )}) * (${unitless(size2)} - ${unitless(size1)}))`
|
|
105
|
+
// }
|
|
106
|
+
// globals[bpName][varName] = responsiveValue
|
|
107
|
+
// })
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
return { globalTypography: globals, typeVariants };
|
|
112
|
+
}
|
|
113
|
+
function parseGrid(theme, media, grid) {
|
|
114
|
+
const globalGrid = {};
|
|
115
|
+
const resolveThemeVar = (scale, value) => {
|
|
116
|
+
if (typeof value === "string" && value.match(/^\$[a-z0-9\-\_]+$/)) {
|
|
117
|
+
// Single scale
|
|
118
|
+
return "$" + scale + value;
|
|
119
|
+
}
|
|
120
|
+
else {
|
|
121
|
+
return value;
|
|
122
|
+
}
|
|
123
|
+
};
|
|
124
|
+
for (let [bpName, breakpoint] of Object.entries(grid.breakpoints)) {
|
|
125
|
+
globalGrid[bpName] = {
|
|
126
|
+
"--grid-columns": grid.columns,
|
|
127
|
+
"--grid-outer-width": breakpoint.container,
|
|
128
|
+
"--grid-inner-width": `calc(${breakpoint.container} - ${resolveThemeVar("spaces", breakpoint.margin)} * 2)`,
|
|
129
|
+
"--grid-gutter": breakpoint.gutter,
|
|
130
|
+
"--grid-margin": breakpoint.margin,
|
|
131
|
+
"--grid-col-width": `calc((var(--grid-inner-width) - (${grid.columns - 1} * var(--grid-gutter))) / ${grid.columns})`,
|
|
132
|
+
};
|
|
133
|
+
}
|
|
134
|
+
return { gridVariants: {}, globalGrid };
|
|
135
|
+
}
|
|
136
|
+
function parseResponsiveValue(val) {
|
|
137
|
+
if (Array.isArray(val)) {
|
|
138
|
+
return {
|
|
139
|
+
...parseResponsiveValue(val[0]),
|
|
140
|
+
lerpStart: true,
|
|
141
|
+
};
|
|
142
|
+
}
|
|
143
|
+
else if (typeof val === "string") {
|
|
144
|
+
if (val.match(/^x[0-9\.]+$/)) {
|
|
145
|
+
return {
|
|
146
|
+
lerpStart: false,
|
|
147
|
+
type: "multiplier",
|
|
148
|
+
value: parseFloat(val.replace(/^x/, "")),
|
|
149
|
+
};
|
|
150
|
+
}
|
|
151
|
+
else if (val.match(/^[0-9\.]+%$/)) {
|
|
152
|
+
return {
|
|
153
|
+
lerpStart: false,
|
|
154
|
+
type: "percent",
|
|
155
|
+
value: parseFloat(val.replace(/^x/, "")),
|
|
156
|
+
};
|
|
157
|
+
}
|
|
158
|
+
else if (val.match(/^[0-9\.]+px$/)) {
|
|
159
|
+
return {
|
|
160
|
+
lerpStart: false,
|
|
161
|
+
type: "px",
|
|
162
|
+
value: parseFloat(val.replace(/px$/, "")),
|
|
163
|
+
};
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
else if (typeof val === "number") {
|
|
167
|
+
return {
|
|
168
|
+
lerpStart: false,
|
|
169
|
+
type: "number",
|
|
170
|
+
value: val,
|
|
171
|
+
};
|
|
172
|
+
}
|
|
173
|
+
else if (val === undefined || val === null) {
|
|
174
|
+
return {
|
|
175
|
+
lerpStart: false,
|
|
176
|
+
type: "undefined",
|
|
177
|
+
};
|
|
178
|
+
}
|
|
179
|
+
return {
|
|
180
|
+
lerpStart: false,
|
|
181
|
+
type: "unknown",
|
|
182
|
+
value: val,
|
|
183
|
+
};
|
|
184
|
+
}
|
|
185
|
+
export function parseResponsiveObject(breakpoints, object) {
|
|
186
|
+
// Breakpoint hash
|
|
187
|
+
const breakpointHash = {};
|
|
188
|
+
for (let bp of breakpoints) {
|
|
189
|
+
breakpointHash[bp.key] = {
|
|
190
|
+
min: bp.min ? parseFloat(bp.min) : null,
|
|
191
|
+
max: bp.max ? parseFloat(bp.max) : null,
|
|
192
|
+
};
|
|
193
|
+
}
|
|
194
|
+
const result = [];
|
|
195
|
+
let lerpStart = "initial";
|
|
196
|
+
let lastDefined = "initial";
|
|
197
|
+
let concreteValues = {};
|
|
198
|
+
for (let bp of breakpoints) {
|
|
199
|
+
const value = parseResponsiveValue(object["@" + bp.key]);
|
|
200
|
+
const defined = value.type !== "undefined";
|
|
201
|
+
let base = !defined || value.type === "multiplier" ? lastDefined : bp.key;
|
|
202
|
+
lerpStart = value.lerpStart ? bp.key : lerpStart && !defined ? lerpStart : null;
|
|
203
|
+
if (value.type === "px" || value.type === "number") {
|
|
204
|
+
concreteValues[bp.key] = value.value;
|
|
205
|
+
}
|
|
206
|
+
else if (value.type === "multiplier") {
|
|
207
|
+
concreteValues[bp.key] = value.value * concreteValues[base];
|
|
208
|
+
}
|
|
209
|
+
else if (value.type === "percent") {
|
|
210
|
+
concreteValues[bp.key] = value.value;
|
|
211
|
+
}
|
|
212
|
+
result.push({
|
|
213
|
+
...value,
|
|
214
|
+
defined: defined,
|
|
215
|
+
breakpoint: bp.key,
|
|
216
|
+
lastBreakpoint: lastDefined,
|
|
217
|
+
baseBreakpoint: base,
|
|
218
|
+
lerping: lerpStart
|
|
219
|
+
? {
|
|
220
|
+
fromBP: lerpStart,
|
|
221
|
+
toBP: null,
|
|
222
|
+
minMedia: 0,
|
|
223
|
+
maxMedia: 0,
|
|
224
|
+
minValue: 0,
|
|
225
|
+
maxValue: 0,
|
|
226
|
+
}
|
|
227
|
+
: undefined,
|
|
228
|
+
concreteValue: concreteValues[bp.key],
|
|
229
|
+
});
|
|
230
|
+
if (defined) {
|
|
231
|
+
lastDefined = bp.key;
|
|
232
|
+
}
|
|
233
|
+
}
|
|
234
|
+
let nextBreakpoints = [];
|
|
235
|
+
let lastBreakpoint = null;
|
|
236
|
+
for (let i = breakpoints.length - 1; i >= 0; i--) {
|
|
237
|
+
const bp = breakpoints[i];
|
|
238
|
+
nextBreakpoints[i] = lastBreakpoint;
|
|
239
|
+
if (result[i].defined) {
|
|
240
|
+
lastBreakpoint = bp.key;
|
|
241
|
+
}
|
|
242
|
+
}
|
|
243
|
+
result.forEach((item, i) => {
|
|
244
|
+
if (item.lerping) {
|
|
245
|
+
item.lerping.toBP = nextBreakpoints[i];
|
|
246
|
+
}
|
|
247
|
+
});
|
|
248
|
+
result.forEach((item, i) => {
|
|
249
|
+
const lerp = item.lerping;
|
|
250
|
+
if (lerp) {
|
|
251
|
+
const fromBP = lerp.fromBP ? breakpointHash[lerp.fromBP] : null;
|
|
252
|
+
const toBP = lerp.toBP ? breakpointHash[lerp.toBP] : null;
|
|
253
|
+
if (!fromBP || fromBP.min === null) {
|
|
254
|
+
throw new Error(`Cannot create responsive style for first breakpoint`);
|
|
255
|
+
}
|
|
256
|
+
if (!toBP || toBP.min === null) {
|
|
257
|
+
throw new Error(`Cannot create responsive style for last breakpoint`);
|
|
258
|
+
}
|
|
259
|
+
lerp.minMedia = fromBP.min;
|
|
260
|
+
lerp.maxMedia = toBP.min;
|
|
261
|
+
lerp.minValue = item.concreteValue;
|
|
262
|
+
lerp.maxValue = result.find((o) => o.breakpoint === lerp.toBP).concreteValue;
|
|
263
|
+
}
|
|
264
|
+
});
|
|
265
|
+
return result;
|
|
266
|
+
}
|
|
267
|
+
export function getResponsiveObjectStyles(breakpoints, object, varName, unit = "px") {
|
|
268
|
+
// Prescale object
|
|
269
|
+
object = { ...object };
|
|
270
|
+
const parsed = parseResponsiveObject(breakpoints, object);
|
|
271
|
+
const globals = {};
|
|
272
|
+
for (let atom of parsed) {
|
|
273
|
+
if (atom.lerpStart && atom.lerping) {
|
|
274
|
+
const lerp = atom.lerping;
|
|
275
|
+
globals["@" + atom.breakpoint] = {
|
|
276
|
+
[varName]: `calc(${lerp.minValue}${unit} + (100vw - ${lerp.minMedia}${unit}) / (${lerp.maxMedia} - ${lerp.minMedia}) * (${lerp.maxValue} - ${lerp.minValue}))`,
|
|
277
|
+
};
|
|
278
|
+
}
|
|
279
|
+
else if (atom.concreteValue) {
|
|
280
|
+
globals["@" + atom.breakpoint] = {
|
|
281
|
+
[varName]: atom.concreteValue + unit,
|
|
282
|
+
};
|
|
283
|
+
}
|
|
284
|
+
else if (atom.defined) {
|
|
285
|
+
globals["@" + atom.breakpoint] = {
|
|
286
|
+
[varName]: atom.value,
|
|
287
|
+
};
|
|
288
|
+
}
|
|
289
|
+
}
|
|
290
|
+
return [globals, globals["@initial"]?.[varName]];
|
|
291
|
+
}
|
|
292
|
+
// parseResponsiveTokens({'@initial': blah, '@desktop': blah}, breakpoints, )
|
|
293
|
+
export function parseResponsiveTokens(theme, breakpoints) {
|
|
294
|
+
const globalResponsive = {
|
|
295
|
+
"@initial": {},
|
|
296
|
+
};
|
|
297
|
+
const initialResponsive = {};
|
|
298
|
+
for (const scale in theme) {
|
|
299
|
+
const initials = {};
|
|
300
|
+
initialResponsive[scale] = initials;
|
|
301
|
+
for (const key in theme[scale]) {
|
|
302
|
+
const val = theme[scale][key];
|
|
303
|
+
if (val && typeof val === "object") {
|
|
304
|
+
const [tokenGlobals, initial] = getResponsiveObjectStyles(breakpoints, val, "--" + scale + "-" + key);
|
|
305
|
+
for (const bp in tokenGlobals) {
|
|
306
|
+
globalResponsive[bp] = {
|
|
307
|
+
...globalResponsive[bp],
|
|
308
|
+
...tokenGlobals[bp],
|
|
309
|
+
};
|
|
310
|
+
}
|
|
311
|
+
initials[key] = initial;
|
|
312
|
+
}
|
|
313
|
+
else {
|
|
314
|
+
initials[key] = val;
|
|
315
|
+
}
|
|
316
|
+
}
|
|
317
|
+
}
|
|
318
|
+
return { initialResponsive, globalResponsive };
|
|
319
|
+
}
|
|
320
|
+
export function createStitches(config) {
|
|
321
|
+
const breakpoints = parseBreakpoints(config.breakpoints, config.media);
|
|
322
|
+
const { typeVariants, globalTypography } = parseTypography(config.theme, breakpoints, config.typography);
|
|
323
|
+
const { gridVariants, globalGrid } = parseGrid(config.theme, config.media, config.grid);
|
|
324
|
+
const { initialResponsive, globalResponsive } = parseResponsiveTokens(config.responsive, breakpoints);
|
|
325
|
+
const stitches = createBaseStitches({
|
|
326
|
+
// prefix: config.prefix,
|
|
327
|
+
media: {
|
|
328
|
+
initial: "",
|
|
329
|
+
...config.media,
|
|
330
|
+
},
|
|
331
|
+
theme: { ...config.theme, ...initialResponsive },
|
|
332
|
+
themeMap: config.themeMap,
|
|
333
|
+
utils: {
|
|
334
|
+
...(config.utils || {}),
|
|
335
|
+
typography: (key) => typeVariants[key],
|
|
336
|
+
m: (value) => ({
|
|
337
|
+
margin: value,
|
|
338
|
+
}),
|
|
339
|
+
mt: (value) => ({
|
|
340
|
+
marginTop: value,
|
|
341
|
+
}),
|
|
342
|
+
mr: (value) => ({
|
|
343
|
+
marginRight: value,
|
|
344
|
+
}),
|
|
345
|
+
mb: (value) => ({
|
|
346
|
+
marginBottom: value,
|
|
347
|
+
}),
|
|
348
|
+
ml: (value) => ({
|
|
349
|
+
marginLeft: value,
|
|
350
|
+
}),
|
|
351
|
+
mx: (value) => ({
|
|
352
|
+
marginLeft: value,
|
|
353
|
+
marginRight: value,
|
|
354
|
+
}),
|
|
355
|
+
my: (value) => ({
|
|
356
|
+
marginTop: value,
|
|
357
|
+
marginBottom: value,
|
|
358
|
+
}),
|
|
359
|
+
p: (value) => ({
|
|
360
|
+
padding: value,
|
|
361
|
+
}),
|
|
362
|
+
pt: (value) => ({
|
|
363
|
+
paddingTop: value,
|
|
364
|
+
}),
|
|
365
|
+
pr: (value) => ({
|
|
366
|
+
paddingRight: value,
|
|
367
|
+
}),
|
|
368
|
+
pb: (value) => ({
|
|
369
|
+
paddingBottom: value,
|
|
370
|
+
}),
|
|
371
|
+
pl: (value) => ({
|
|
372
|
+
paddingLeft: value,
|
|
373
|
+
}),
|
|
374
|
+
px: (value) => ({
|
|
375
|
+
paddingLeft: value,
|
|
376
|
+
paddingRight: value,
|
|
377
|
+
}),
|
|
378
|
+
py: (value) => ({
|
|
379
|
+
paddingTop: value,
|
|
380
|
+
paddingBottom: value,
|
|
381
|
+
}),
|
|
382
|
+
cols: (value) => ({
|
|
383
|
+
gridColumn: `auto / span ${value}`,
|
|
384
|
+
"--grid-columns": value,
|
|
385
|
+
}),
|
|
386
|
+
},
|
|
387
|
+
});
|
|
388
|
+
// Typography globals
|
|
389
|
+
const typeGlobals = {};
|
|
390
|
+
Object.entries(globalTypography).forEach(([key, styles]) => {
|
|
391
|
+
if (key === "@initial") {
|
|
392
|
+
typeGlobals[":root"] = styles;
|
|
393
|
+
}
|
|
394
|
+
else if (key === "@editor") {
|
|
395
|
+
typeGlobals[":root body.block-editor-page"] = styles;
|
|
396
|
+
}
|
|
397
|
+
else {
|
|
398
|
+
typeGlobals[key] = { ":root": styles };
|
|
399
|
+
}
|
|
400
|
+
});
|
|
401
|
+
stitches.globalCss(typeGlobals)();
|
|
402
|
+
// Grid globals
|
|
403
|
+
const gridGlobals = {};
|
|
404
|
+
Object.entries(globalGrid).forEach(([key, styles]) => {
|
|
405
|
+
if (key === "@initial") {
|
|
406
|
+
gridGlobals[":root"] = styles;
|
|
407
|
+
}
|
|
408
|
+
else if (key === "@editor") {
|
|
409
|
+
gridGlobals[":root body.block-editor-page"] = styles;
|
|
410
|
+
}
|
|
411
|
+
else {
|
|
412
|
+
gridGlobals[key] = { ":root": styles };
|
|
413
|
+
}
|
|
414
|
+
});
|
|
415
|
+
stitches.globalCss(gridGlobals)();
|
|
416
|
+
const responsiveGlobals = {};
|
|
417
|
+
Object.entries(globalResponsive).forEach(([key, styles]) => {
|
|
418
|
+
if (key === "@initial") {
|
|
419
|
+
responsiveGlobals[":root"] = styles;
|
|
420
|
+
}
|
|
421
|
+
else if (key === "@editor") {
|
|
422
|
+
responsiveGlobals[":root body.block-editor-page"] = styles;
|
|
423
|
+
}
|
|
424
|
+
else {
|
|
425
|
+
responsiveGlobals[key] = { ":root": styles };
|
|
426
|
+
}
|
|
427
|
+
});
|
|
428
|
+
stitches.globalCss(responsiveGlobals)();
|
|
429
|
+
const responsiveTokens = {};
|
|
430
|
+
return {
|
|
431
|
+
...stitches,
|
|
432
|
+
originalConfig: config,
|
|
433
|
+
breakpoints,
|
|
434
|
+
typeVariants,
|
|
435
|
+
gridVariants,
|
|
436
|
+
responsiveTokens,
|
|
437
|
+
responsiveGlobals,
|
|
438
|
+
};
|
|
439
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./createStitches.js";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./createStitches.js";
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { PropsWithChildren } from "react";
|
|
2
|
+
import { RouteLoader } from "../loader.js";
|
|
3
|
+
import { RouteState } from "../types.js";
|
|
4
|
+
type Props = PropsWithChildren<{
|
|
5
|
+
route: RouteState;
|
|
6
|
+
loader: RouteLoader;
|
|
7
|
+
}>;
|
|
8
|
+
export declare function SSRRouter(props: Props): import("react/jsx-runtime").JSX.Element;
|
|
9
|
+
export {};
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { RouterContext, RouterStateContext } from "../context.js";
|
|
3
|
+
import { useRouter } from "../hooks/useRouter.js";
|
|
4
|
+
import { useRouterState } from "../hooks/useRouterState.js";
|
|
5
|
+
import { AppRenderer } from "./RouteRenderer.js";
|
|
6
|
+
export function SSRRouter(props) {
|
|
7
|
+
const router = useRouter();
|
|
8
|
+
const routerState = useRouterState();
|
|
9
|
+
router.loader = props.loader;
|
|
10
|
+
routerState.history = [props.route];
|
|
11
|
+
routerState.activeRoute = props.route;
|
|
12
|
+
return (_jsx(RouterContext.Provider, { value: router, children: _jsx(RouterStateContext.Provider, { value: routerState, children: _jsx(AppRenderer, {}) }) }));
|
|
13
|
+
}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { ComponentType, PropsWithChildren, ReactNode } from "react";
|
|
2
|
+
type ExtendedViewProps<TName extends keyof ViewProps> = TName extends "_app" ? PropsWithChildren<ViewProps[TName]> : ViewProps[TName];
|
|
3
|
+
export declare function defineView<Name extends keyof ViewProps>(name: Name, component: (props: ExtendedViewProps<Name>) => ReactNode): ComponentType<ExtendedViewProps<Name>>;
|
|
4
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./defineView.js";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./defineView.js";
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
/// <reference types="vinxi/types/server" />
|
|
2
|
+
import { splitSetCookieString } from "cookie-es";
|
|
3
|
+
import { getProxyRequestHeaders, getRequestURL, getWebRequest } from "vinxi/http";
|
|
4
|
+
export async function proxyWpAdmin(event, serverContext) {
|
|
5
|
+
const replaceUrls = serverContext.replaceUrls;
|
|
6
|
+
const req = getWebRequest(event);
|
|
7
|
+
const proxyUrl = serverContext.getOriginUrl(getRequestURL(event).href);
|
|
8
|
+
// Prepare request headers to be sent to the origin server
|
|
9
|
+
const proxyHeaders = getProxyRequestHeaders(event);
|
|
10
|
+
proxyHeaders["X-ED-Dev-Proxy"] = "true";
|
|
11
|
+
// Forward the request to the origin server
|
|
12
|
+
const response = await fetch(proxyUrl, {
|
|
13
|
+
method: req.method,
|
|
14
|
+
referrer: req.referrer,
|
|
15
|
+
referrerPolicy: req.referrerPolicy,
|
|
16
|
+
headers: proxyHeaders,
|
|
17
|
+
body: req.method.match(/get|head|options/i) ? undefined : await req.blob(),
|
|
18
|
+
redirect: "manual",
|
|
19
|
+
cache: "no-cache",
|
|
20
|
+
});
|
|
21
|
+
const contentType = response.headers.get("content-type");
|
|
22
|
+
let body;
|
|
23
|
+
let res = { status: response.status, statusText: response.statusText, headers: new Headers() };
|
|
24
|
+
const cookies = [];
|
|
25
|
+
response.headers.forEach((value, key) => {
|
|
26
|
+
if (key === "content-encoding" || key === "content-length" || key === "transfer-encoding") {
|
|
27
|
+
return;
|
|
28
|
+
}
|
|
29
|
+
if (key === "set-cookie") {
|
|
30
|
+
cookies.push(...splitSetCookieString(value));
|
|
31
|
+
return;
|
|
32
|
+
}
|
|
33
|
+
if (key === "location" && replaceUrls) {
|
|
34
|
+
value = replaceUrls(value);
|
|
35
|
+
}
|
|
36
|
+
res.headers.set(key, value);
|
|
37
|
+
});
|
|
38
|
+
// Set cookies in the response headers
|
|
39
|
+
// TODO: May need to rewrite cookie domain here before setting.
|
|
40
|
+
if (cookies.length > 0) {
|
|
41
|
+
for (const cookie of cookies) {
|
|
42
|
+
res.headers.append("set-cookie", cookie);
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
// Replace URLs pointing to the origin server from the response itself
|
|
46
|
+
// This is only done for text-based content types, like application/json, text/plain, text/html etc
|
|
47
|
+
if (contentType?.match(/(application|text)\//)) {
|
|
48
|
+
if (replaceUrls) {
|
|
49
|
+
body = replaceUrls((await response.text()) ?? "");
|
|
50
|
+
}
|
|
51
|
+
// If the content type is text/html, inject the Vite assets into the response — assuming the placeholder comments are found
|
|
52
|
+
if (contentType.startsWith("text/html")) {
|
|
53
|
+
const clientManifest = serverContext.runtime.getManifest("admin");
|
|
54
|
+
const assets = await clientManifest.inputs[clientManifest.handler].assets();
|
|
55
|
+
body = body.replace("<!---VITE_HEADER--->", () => assets.map((asset) => renderAsset(asset)).join("\n"));
|
|
56
|
+
body = body.replace("<!---VITE_FOOTER--->", () => renderAsset({
|
|
57
|
+
tag: "script",
|
|
58
|
+
attrs: {
|
|
59
|
+
type: "module",
|
|
60
|
+
src: clientManifest.inputs[clientManifest.handler].output.path,
|
|
61
|
+
},
|
|
62
|
+
children: "",
|
|
63
|
+
}));
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
else {
|
|
67
|
+
// Otherwise just stream the response as is
|
|
68
|
+
body = response.body;
|
|
69
|
+
}
|
|
70
|
+
return new Response(body, res);
|
|
71
|
+
}
|
|
72
|
+
function printElement(element, props, innerText) {
|
|
73
|
+
if (typeof innerText === "string") {
|
|
74
|
+
return `<${element}${Object.entries(props)
|
|
75
|
+
.map(([key, value]) => ` ${key}="${value}"`)
|
|
76
|
+
.join("")}>${innerText}</${element}>`;
|
|
77
|
+
}
|
|
78
|
+
else {
|
|
79
|
+
return `<${element}${Object.entries(props)
|
|
80
|
+
.map(([key, value]) => ` ${key}="${value}"`)
|
|
81
|
+
.join("")} />`;
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
function renderAsset({ tag, attrs: { key, ...attrs } = {}, children, }) {
|
|
85
|
+
switch (tag) {
|
|
86
|
+
case "script":
|
|
87
|
+
if (attrs.src) {
|
|
88
|
+
return printElement("script", { ...attrs, key: attrs.src }, "");
|
|
89
|
+
}
|
|
90
|
+
else {
|
|
91
|
+
return printElement("script", {
|
|
92
|
+
...attrs,
|
|
93
|
+
key: key,
|
|
94
|
+
}, children ?? "");
|
|
95
|
+
}
|
|
96
|
+
case "link":
|
|
97
|
+
return printElement("link", { ...attrs, key: key });
|
|
98
|
+
case "style":
|
|
99
|
+
return printElement("style", {
|
|
100
|
+
...attrs,
|
|
101
|
+
key: key,
|
|
102
|
+
}, children ?? "");
|
|
103
|
+
}
|
|
104
|
+
return "";
|
|
105
|
+
}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import type { RouteData, TrackerTags } from "../lib/routing/types.js";
|
|
2
|
+
import { ServerContext } from "./server-context.js";
|
|
3
|
+
export declare function renderPageToSSRStream(pathname: string, initialData: RouteData & {
|
|
4
|
+
trackers?: TrackerTags;
|
|
5
|
+
}, serverContext: ServerContext): Promise<unknown>;
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { renderAsset } from "@vinxi/react";
|
|
3
|
+
import { Suspense } from "react";
|
|
4
|
+
import { renderToPipeableStream } from "react-dom/server";
|
|
5
|
+
import { SSRRoot } from "../entry/ssr-root.js";
|
|
6
|
+
import { RouteLoader } from "../lib/routing/loader.js";
|
|
7
|
+
export async function renderPageToSSRStream(pathname, initialData, serverContext) {
|
|
8
|
+
const clientManifest = serverContext.runtime.getManifest("client");
|
|
9
|
+
const assets = await clientManifest.inputs[clientManifest.handler].assets();
|
|
10
|
+
const jsx = (_jsx(SSRRoot, { assets: _jsx(Suspense, { children: assets.map((m) => renderAsset(m)) }), metaTags: initialData?.meta?.head || [], pathname: pathname, initialData: initialData, loader: new RouteLoader() }));
|
|
11
|
+
const stream = await new Promise(async (resolve, reject) => {
|
|
12
|
+
// console.log("Rendering to pipable")
|
|
13
|
+
const stream = renderToPipeableStream(jsx, {
|
|
14
|
+
onShellReady() {
|
|
15
|
+
// console.log("Shell ready")
|
|
16
|
+
resolve(stream);
|
|
17
|
+
},
|
|
18
|
+
onShellError(err) {
|
|
19
|
+
console.log("onShellError", err);
|
|
20
|
+
resolve("An error occurred");
|
|
21
|
+
},
|
|
22
|
+
onError(err, errInfo) {
|
|
23
|
+
console.log("Error occurred after shell ready", err, errInfo);
|
|
24
|
+
console.error(err);
|
|
25
|
+
},
|
|
26
|
+
bootstrapModules: [clientManifest.inputs[clientManifest.handler].output.path],
|
|
27
|
+
bootstrapScriptContent: `window.manifest = ${JSON.stringify(await clientManifest.json())};\nwindow._PAGE_DATA = ${JSON.stringify(initialData)};`,
|
|
28
|
+
});
|
|
29
|
+
});
|
|
30
|
+
return stream;
|
|
31
|
+
}
|