siteplane 0.2.1 → 0.3.0
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 +4 -0
- package/README.md +181 -22
- package/THIRD-PARTY-NOTICES.md +16 -0
- package/dist/astro/SiteplaneAnalytics.astro +29 -0
- package/dist/astro/SiteplaneBridge.astro +19 -0
- package/dist/astro/client.js +26 -0
- package/dist/astro/index.d.ts +114 -0
- package/dist/astro/index.js +1772 -0
- package/dist/astro/middleware.js +574 -0
- package/dist/astro/route.js +161 -0
- package/dist/bin/siteplane.js +17734 -1490
- package/dist/chunk-46ZC6NGK.js +493 -0
- package/dist/chunk-IOFM5PE3.js +532 -0
- package/dist/client.d.ts +38 -0
- package/dist/client.js +24 -0
- package/dist/components.d.ts +3 -3
- package/dist/components.js +5 -17
- package/dist/index.d.ts +90 -23
- package/dist/index.js +334 -22
- package/dist/internal/astro-client.js +122 -0
- package/dist/internal/bridge.js +2 -1
- package/dist/internal/empty.js +6 -0
- package/dist/next.cjs +70 -27
- package/dist/next.d.ts +10 -7
- package/dist/next.js +72 -27
- package/dist/route.d.ts +2 -1
- package/dist/route.js +39 -26
- package/dist/schema-file.d.ts +11 -0
- package/dist/schema-file.js +6 -0
- package/dist/schema.d.ts +64 -0
- package/dist/schema.js +7 -0
- package/package.json +37 -2
- package/dist/chunk-BLJCWIYD.js +0 -340
|
@@ -0,0 +1,574 @@
|
|
|
1
|
+
import {
|
|
2
|
+
PREVIEW_COOKIE,
|
|
3
|
+
buildInfo,
|
|
4
|
+
createValueLoader,
|
|
5
|
+
runtimeCdnValuesUrl,
|
|
6
|
+
runtimeValuesUrl,
|
|
7
|
+
serverShared,
|
|
8
|
+
signingKeys,
|
|
9
|
+
siteConfig,
|
|
10
|
+
siteSchema,
|
|
11
|
+
verifySitePreviewToken,
|
|
12
|
+
webFetch
|
|
13
|
+
} from "../chunk-46ZC6NGK.js";
|
|
14
|
+
|
|
15
|
+
// ../shared/dist/field-id.js
|
|
16
|
+
import { z } from "zod";
|
|
17
|
+
var FIELD_ID_PATTERN = /^[A-Za-z][A-Za-z0-9_-]*(\.[A-Za-z][A-Za-z0-9_-]*)+$/;
|
|
18
|
+
var FIELD_ID_MAX_LENGTH = 160;
|
|
19
|
+
var FIELD_SYNC_MAX_BYTES = 4 * 1024 * 1024;
|
|
20
|
+
var fieldIdSchema = z.string().max(FIELD_ID_MAX_LENGTH, `A field ID has at most ${FIELD_ID_MAX_LENGTH} characters`).regex(FIELD_ID_PATTERN, "Invalid field id");
|
|
21
|
+
var FIELD_NAME_PATTERN = /^[A-Za-z][A-Za-z0-9_]*$/;
|
|
22
|
+
var FIELD_NAME_MAX_LENGTH = 64;
|
|
23
|
+
function isFieldName(value) {
|
|
24
|
+
return typeof value === "string" && value.length <= FIELD_NAME_MAX_LENGTH && FIELD_NAME_PATTERN.test(value);
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
// ../shared/dist/content-path.js
|
|
28
|
+
var ROW_KEY_PATTERN = /^[a-z][a-z0-9]{7}$/u;
|
|
29
|
+
function formatContentPath(steps) {
|
|
30
|
+
let path = "";
|
|
31
|
+
for (const step of steps) {
|
|
32
|
+
if ("field" in step)
|
|
33
|
+
path += path === "" ? step.field : `.${step.field}`;
|
|
34
|
+
else if ("key" in step)
|
|
35
|
+
path += `[_key=="${step.key}"]`;
|
|
36
|
+
else
|
|
37
|
+
path += `[${step.index}]`;
|
|
38
|
+
}
|
|
39
|
+
return path;
|
|
40
|
+
}
|
|
41
|
+
function isRowKey(value) {
|
|
42
|
+
return typeof value === "string" && ROW_KEY_PATTERN.test(value);
|
|
43
|
+
}
|
|
44
|
+
var letters = "abcdefghijklmnopqrstuvwxyz";
|
|
45
|
+
var lettersAndDigits = `${letters}0123456789`;
|
|
46
|
+
|
|
47
|
+
// ../shared/dist/field-values.js
|
|
48
|
+
var FIELD_VALUE_LIMITS = {
|
|
49
|
+
text: 256,
|
|
50
|
+
longText: 5e4,
|
|
51
|
+
linkLabel: 256,
|
|
52
|
+
linkHref: 2048,
|
|
53
|
+
imageSrc: 2048,
|
|
54
|
+
imageFile: 2048,
|
|
55
|
+
imageAlt: 300,
|
|
56
|
+
imageSize: 1e5
|
|
57
|
+
};
|
|
58
|
+
var FIELD_VALUE_PROBLEMS = [
|
|
59
|
+
"not_text",
|
|
60
|
+
"too_long",
|
|
61
|
+
"not_object",
|
|
62
|
+
"unknown_key",
|
|
63
|
+
"href_invalid",
|
|
64
|
+
"label_missing",
|
|
65
|
+
"label_too_long",
|
|
66
|
+
"asset_missing",
|
|
67
|
+
"src_invalid",
|
|
68
|
+
"alt_invalid",
|
|
69
|
+
"size_invalid",
|
|
70
|
+
"unknown_type"
|
|
71
|
+
];
|
|
72
|
+
var FIELD_VALUE_PROBLEM_TEXT = {
|
|
73
|
+
not_text: "it must be a string",
|
|
74
|
+
too_long: "it is too long (short text 256, long text 50,000 characters)",
|
|
75
|
+
not_object: "it must be an object",
|
|
76
|
+
unknown_key: "it has keys the field type does not know",
|
|
77
|
+
href_invalid: "href must be a path such as /menu, an anchor such as #contact, or start with http(s)://, mailto: or tel:",
|
|
78
|
+
label_missing: "a link needs a visible label",
|
|
79
|
+
label_too_long: "the label is longer than 256 characters",
|
|
80
|
+
asset_missing: "the image needs an asset uploaded to this site",
|
|
81
|
+
src_invalid: 'src must be a path such as /hero.jpg or an http(s) address; in an Astro project it may also be an imported image (import hero from "../assets/hero.jpg")',
|
|
82
|
+
alt_invalid: "alt must be a string of at most 300 characters; it may be empty",
|
|
83
|
+
size_invalid: "width and height must be whole numbers from 1 to 100,000",
|
|
84
|
+
unknown_type: "this field type has no single value; a list is checked with its row type"
|
|
85
|
+
};
|
|
86
|
+
var linkKeys = ["href", "label"];
|
|
87
|
+
var renderedImageKeys = ["src", "alt", "width", "height"];
|
|
88
|
+
var fallbackImageKeys = ["src", "file", "alt", "width", "height"];
|
|
89
|
+
var contentImageKeys = ["assetId", "src", "alt", "width", "height"];
|
|
90
|
+
var controlCharacter = /[\u0000-\u001f\u007f-\u009f]/u;
|
|
91
|
+
var asciiBlank = /^[ \t\n\v\f\r]*$/u;
|
|
92
|
+
var uuidPattern = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/iu;
|
|
93
|
+
var webAddress = /^https?:\/\/[^/?#@]+(?:[/?#].*)?$/isu;
|
|
94
|
+
function fieldValueProblem(type, value, origin) {
|
|
95
|
+
switch (type) {
|
|
96
|
+
case "text":
|
|
97
|
+
case "longText":
|
|
98
|
+
if (typeof value !== "string")
|
|
99
|
+
return "not_text";
|
|
100
|
+
return codePoints(value) > FIELD_VALUE_LIMITS[type] ? "too_long" : null;
|
|
101
|
+
case "link":
|
|
102
|
+
return linkProblem(value);
|
|
103
|
+
case "image":
|
|
104
|
+
return imageProblem(value, origin);
|
|
105
|
+
case "array":
|
|
106
|
+
return "unknown_type";
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
function readFieldValue(type, value) {
|
|
110
|
+
const rendered = type === "link" ? pick(value, linkKeys) : type === "image" ? pick(value, renderedImageKeys) : value;
|
|
111
|
+
return fieldValueProblem(type, rendered, "fallback") === null ? rendered : null;
|
|
112
|
+
}
|
|
113
|
+
var CONTENT_VALUE_LIMITS = { valueBytes: 256 * 1024, listDepth: 3, blurDataURL: 1024 };
|
|
114
|
+
var CONTENT_VALUE_PROBLEMS = [
|
|
115
|
+
...FIELD_VALUE_PROBLEMS,
|
|
116
|
+
"required",
|
|
117
|
+
"not_list",
|
|
118
|
+
"key_missing",
|
|
119
|
+
"key_invalid",
|
|
120
|
+
"key_duplicate",
|
|
121
|
+
"too_few_rows",
|
|
122
|
+
"too_many_rows",
|
|
123
|
+
"too_deep",
|
|
124
|
+
"too_large",
|
|
125
|
+
"focus_invalid",
|
|
126
|
+
"blur_invalid"
|
|
127
|
+
];
|
|
128
|
+
var CONTENT_VALUE_PROBLEM_TEXT = {
|
|
129
|
+
...FIELD_VALUE_PROBLEM_TEXT,
|
|
130
|
+
unknown_key: "it has keys the field type or the row type does not know",
|
|
131
|
+
required: "it is required and cannot be empty",
|
|
132
|
+
not_list: "a list must be an array of rows",
|
|
133
|
+
key_missing: "the row has no _key; Siteplane gives a key to each row you add",
|
|
134
|
+
key_invalid: "the row's _key must be eight lowercase letters and digits starting with a letter, as Siteplane gives them; never write a key by hand",
|
|
135
|
+
key_duplicate: "another row of this list has the same _key; remove the _key from the row you added",
|
|
136
|
+
too_few_rows: "the list has fewer rows than its minRows",
|
|
137
|
+
too_many_rows: "the list has more rows than its maxRows",
|
|
138
|
+
too_deep: "lists stand in lists at most three levels deep",
|
|
139
|
+
too_large: "the value is larger than 256 KB",
|
|
140
|
+
focus_invalid: "focus must be { x, y } with numbers from 0 to 1",
|
|
141
|
+
blur_invalid: "blurDataURL must be a data address of an image of at most 1 KB; Siteplane sets it"
|
|
142
|
+
};
|
|
143
|
+
function linkProblem(value) {
|
|
144
|
+
if (!isRecord(value))
|
|
145
|
+
return "not_object";
|
|
146
|
+
if (hasUnknownKey(value, linkKeys))
|
|
147
|
+
return "unknown_key";
|
|
148
|
+
if (!isHref(value.href))
|
|
149
|
+
return "href_invalid";
|
|
150
|
+
if (typeof value.label !== "string" || asciiBlank.test(value.label))
|
|
151
|
+
return "label_missing";
|
|
152
|
+
return codePoints(value.label) > FIELD_VALUE_LIMITS.linkLabel ? "label_too_long" : null;
|
|
153
|
+
}
|
|
154
|
+
function imageProblem(value, origin) {
|
|
155
|
+
if (!isRecord(value))
|
|
156
|
+
return "not_object";
|
|
157
|
+
if (hasUnknownKey(value, origin === "content" ? contentImageKeys : fallbackImageKeys))
|
|
158
|
+
return "unknown_key";
|
|
159
|
+
if (origin === "content" && (typeof value.assetId !== "string" || !uuidPattern.test(value.assetId))) {
|
|
160
|
+
return "asset_missing";
|
|
161
|
+
}
|
|
162
|
+
const source = value.file === void 0 ? isImageSource(value.src) : value.src === void 0 && isImportPath(value.file);
|
|
163
|
+
if (!source)
|
|
164
|
+
return "src_invalid";
|
|
165
|
+
if (typeof value.alt !== "string" || codePoints(value.alt) > FIELD_VALUE_LIMITS.imageAlt)
|
|
166
|
+
return "alt_invalid";
|
|
167
|
+
const sizeRequired = origin === "content";
|
|
168
|
+
for (const size of [value.width, value.height]) {
|
|
169
|
+
if (size === void 0 ? sizeRequired : !isImageSize(size))
|
|
170
|
+
return "size_invalid";
|
|
171
|
+
}
|
|
172
|
+
return null;
|
|
173
|
+
}
|
|
174
|
+
function isHref(value) {
|
|
175
|
+
if (!isAddressText(value, FIELD_VALUE_LIMITS.linkHref))
|
|
176
|
+
return false;
|
|
177
|
+
return isSitePath(value) || value.startsWith("#") || webAddress.test(value) || /^mailto:.+$/isu.test(value) || /^tel:\+?[0-9][0-9().-]*$/iu.test(value);
|
|
178
|
+
}
|
|
179
|
+
function isImageSource(value) {
|
|
180
|
+
return isAddressText(value, FIELD_VALUE_LIMITS.imageSrc) && (isSitePath(value) || webAddress.test(value));
|
|
181
|
+
}
|
|
182
|
+
function isImportPath(value) {
|
|
183
|
+
return typeof value === "string" && value.length > 0 && codePoints(value) <= FIELD_VALUE_LIMITS.imageFile && !controlCharacter.test(value);
|
|
184
|
+
}
|
|
185
|
+
function isSitePath(value) {
|
|
186
|
+
return value.startsWith("/") && !value.startsWith("//");
|
|
187
|
+
}
|
|
188
|
+
function isAddressText(value, maxLength) {
|
|
189
|
+
if (typeof value !== "string" || value.length === 0 || codePoints(value) > maxLength)
|
|
190
|
+
return false;
|
|
191
|
+
for (const character of value) {
|
|
192
|
+
const code = character.codePointAt(0);
|
|
193
|
+
if (code <= 32 || code === 127 || character === "\\")
|
|
194
|
+
return false;
|
|
195
|
+
}
|
|
196
|
+
return true;
|
|
197
|
+
}
|
|
198
|
+
function isImageSize(value) {
|
|
199
|
+
return typeof value === "number" && Number.isInteger(value) && value >= 1 && value <= FIELD_VALUE_LIMITS.imageSize;
|
|
200
|
+
}
|
|
201
|
+
function hasUnknownKey(value, keys) {
|
|
202
|
+
return Object.keys(value).some((key) => !keys.includes(key));
|
|
203
|
+
}
|
|
204
|
+
function pick(value, keys) {
|
|
205
|
+
if (!isRecord(value))
|
|
206
|
+
return value;
|
|
207
|
+
return Object.fromEntries(keys.filter((key) => key in value).map((key) => [key, value[key]]));
|
|
208
|
+
}
|
|
209
|
+
function codePoints(value) {
|
|
210
|
+
return Array.from(value).length;
|
|
211
|
+
}
|
|
212
|
+
function isRecord(value) {
|
|
213
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
// src/runtime/frame-ancestors.ts
|
|
217
|
+
var FRAME_ANCESTORS = /^frame-ancestors(?:\s|$)/iu;
|
|
218
|
+
function mergeFrameAncestors(policy, editorOrigins) {
|
|
219
|
+
const policies = (policy ?? "").split(",").map(
|
|
220
|
+
(text) => text.split(";").map((directive) => directive.trim()).filter(Boolean)
|
|
221
|
+
).filter((directives) => directives.length > 0);
|
|
222
|
+
let extended = false;
|
|
223
|
+
const merged = policies.map((directives) => {
|
|
224
|
+
const index = directives.findIndex((directive) => FRAME_ANCESTORS.test(directive));
|
|
225
|
+
if (index === -1) return directives;
|
|
226
|
+
extended = true;
|
|
227
|
+
const sources = (directives[index] ?? "").split(/\s+/u).slice(1);
|
|
228
|
+
const allowed = sources.some((source) => source.toLowerCase() === "'none'") ? editorOrigins : [...sources, ...editorOrigins.filter((origin) => !sources.includes(origin))];
|
|
229
|
+
return [
|
|
230
|
+
...directives.slice(0, index),
|
|
231
|
+
`frame-ancestors ${allowed.join(" ") || "'none'"}`,
|
|
232
|
+
// Browsers use the first directive of a name and ignore repeats.
|
|
233
|
+
...directives.slice(index + 1).filter((directive) => !FRAME_ANCESTORS.test(directive))
|
|
234
|
+
];
|
|
235
|
+
});
|
|
236
|
+
if (!extended) {
|
|
237
|
+
const own = `frame-ancestors ${["'self'", ...editorOrigins].join(" ")}`;
|
|
238
|
+
const last = merged.at(-1);
|
|
239
|
+
if (last) last.push(own);
|
|
240
|
+
else merged.push([own]);
|
|
241
|
+
}
|
|
242
|
+
return merged.map((directives) => directives.join("; ")).join(", ");
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
// src/runtime/read.ts
|
|
246
|
+
var VALUE_TYPES = /* @__PURE__ */ new Set(["text", "textarea", "link", "image", "json"]);
|
|
247
|
+
var notFound = "[Siteplane] siteplane.schema.ts was not found next to siteplane.config.json, or it has no default export defineSchema({ globals: [ \u2026 ] }). Describe the content there and run npx siteplane check. If the file was created while the dev server was running, restart the dev server: it looks for the file when it starts.";
|
|
248
|
+
var noConfig = "[Siteplane] siteplane.config.json is missing or invalid, so the content of this website cannot be read. Run npx siteplane init to connect it.";
|
|
249
|
+
function createReader(dependencies) {
|
|
250
|
+
return {
|
|
251
|
+
async read(slug, options = {}) {
|
|
252
|
+
if (!dependencies.config) throw new Error(noConfig);
|
|
253
|
+
findGlobal(dependencies.schema, slug);
|
|
254
|
+
const [values, marking] = await Promise.all([dependencies.loadValues(), dependencies.marking?.(options) ?? null]);
|
|
255
|
+
return readGlobal({
|
|
256
|
+
schema: dependencies.schema,
|
|
257
|
+
slug,
|
|
258
|
+
values,
|
|
259
|
+
stack: dependencies.stack,
|
|
260
|
+
marking,
|
|
261
|
+
missing: dependencies.missing ?? reportMissingContent
|
|
262
|
+
});
|
|
263
|
+
}
|
|
264
|
+
};
|
|
265
|
+
}
|
|
266
|
+
function readGlobal(input) {
|
|
267
|
+
const global = findGlobal(input.schema, input.slug);
|
|
268
|
+
const place = { path: input.slug, steps: [{ field: input.slug }], fieldId: null };
|
|
269
|
+
const result = readFields(global.fields, place, input.slug, input);
|
|
270
|
+
markPath(result, place, input);
|
|
271
|
+
return result;
|
|
272
|
+
}
|
|
273
|
+
function missingContentReporter(warn = console.warn) {
|
|
274
|
+
const reported = /* @__PURE__ */ new Set();
|
|
275
|
+
return (id, row) => {
|
|
276
|
+
if (reported.has(id)) return;
|
|
277
|
+
reported.add(id);
|
|
278
|
+
warn(
|
|
279
|
+
row ? `[Siteplane] The row ${row.path} has no value for its required field ${row.field} in Siteplane yet, so the page renders the row without it. Run npx siteplane content push to publish it.` : `[Siteplane] ${id} is required, but it has no content in Siteplane yet, so the page renders without it. Run npx siteplane content push to publish it.`
|
|
280
|
+
);
|
|
281
|
+
};
|
|
282
|
+
}
|
|
283
|
+
var reportMissingContent = (id, row) => serverShared("missingContent", () => missingContentReporter())(id, row);
|
|
284
|
+
function findGlobal(schema, slug) {
|
|
285
|
+
if (!isRecord2(schema) || !Array.isArray(schema.globals)) throw new Error(notFound);
|
|
286
|
+
const global = schema.globals.find((entry) => isRecord2(entry) && entry.slug === slug);
|
|
287
|
+
if (!isRecord2(global)) {
|
|
288
|
+
throw new Error(`[Siteplane] siteplane.schema.ts has no global ${JSON.stringify(slug)}. Add it to the description and run npx siteplane check.`);
|
|
289
|
+
}
|
|
290
|
+
return { fields: fieldsOf(global.fields) };
|
|
291
|
+
}
|
|
292
|
+
function fieldsOf(value) {
|
|
293
|
+
if (!Array.isArray(value)) return [];
|
|
294
|
+
return value.flatMap((entry) => {
|
|
295
|
+
if (!isRecord2(entry) || !isFieldName(entry.name) || typeof entry.type !== "string") return [];
|
|
296
|
+
return [
|
|
297
|
+
{
|
|
298
|
+
name: entry.name,
|
|
299
|
+
type: entry.type,
|
|
300
|
+
required: entry.required === true,
|
|
301
|
+
...Object.hasOwn(entry, "defaultValue") ? { defaultValue: entry.defaultValue } : {},
|
|
302
|
+
fields: fieldsOf(entry.fields)
|
|
303
|
+
}
|
|
304
|
+
];
|
|
305
|
+
});
|
|
306
|
+
}
|
|
307
|
+
function readFields(fields, place, id, input) {
|
|
308
|
+
const result = {};
|
|
309
|
+
for (const field of fields) {
|
|
310
|
+
const fieldId = `${id}.${field.name}`;
|
|
311
|
+
if (field.type === "group") {
|
|
312
|
+
const at2 = child(place, field.name, null);
|
|
313
|
+
const group = readFields(field.fields, at2, fieldId, input);
|
|
314
|
+
markPath(group, at2, input);
|
|
315
|
+
result[field.name] = group;
|
|
316
|
+
continue;
|
|
317
|
+
}
|
|
318
|
+
const at = child(place, field.name, fieldId);
|
|
319
|
+
const stored = Object.hasOwn(input.values, fieldId) ? input.values[fieldId] : void 0;
|
|
320
|
+
if (field.type === "array") {
|
|
321
|
+
const rows = readRows(field.fields, stored, at, input, 1, fieldId);
|
|
322
|
+
if (field.required && rows.length === 0) input.missing?.(fieldId);
|
|
323
|
+
result[field.name] = rows;
|
|
324
|
+
continue;
|
|
325
|
+
}
|
|
326
|
+
if (!VALUE_TYPES.has(field.type)) continue;
|
|
327
|
+
const value = readValue(field, stored, at, input);
|
|
328
|
+
if (value === void 0) {
|
|
329
|
+
if (field.required) input.missing?.(fieldId);
|
|
330
|
+
continue;
|
|
331
|
+
}
|
|
332
|
+
result[field.name] = value;
|
|
333
|
+
}
|
|
334
|
+
return result;
|
|
335
|
+
}
|
|
336
|
+
function readRows(fields, stored, place, input, depth, listPath) {
|
|
337
|
+
if (!Array.isArray(stored) || depth > CONTENT_VALUE_LIMITS.listDepth) return [];
|
|
338
|
+
const rows = [];
|
|
339
|
+
const keys = /* @__PURE__ */ new Set();
|
|
340
|
+
for (const item of stored) {
|
|
341
|
+
if (!isRecord2(item) || !isRowKey(item._key) || keys.has(item._key)) continue;
|
|
342
|
+
keys.add(item._key);
|
|
343
|
+
const at = {
|
|
344
|
+
path: formatContentPath([...place.steps, { key: item._key }]),
|
|
345
|
+
steps: [...place.steps, { key: item._key }],
|
|
346
|
+
fieldId: place.fieldId
|
|
347
|
+
};
|
|
348
|
+
const row = { _key: item._key };
|
|
349
|
+
markPath(row, at, input);
|
|
350
|
+
for (const field of fields) {
|
|
351
|
+
const inner = child(at, field.name, place.fieldId);
|
|
352
|
+
const fieldPath = `${listPath}.${field.name}`;
|
|
353
|
+
if (field.type === "array") {
|
|
354
|
+
const nested = readRows(field.fields, item[field.name], inner, input, depth + 1, fieldPath);
|
|
355
|
+
if (field.required && nested.length === 0 && depth < CONTENT_VALUE_LIMITS.listDepth) {
|
|
356
|
+
input.missing?.(fieldPath, { path: at.path, field: field.name });
|
|
357
|
+
}
|
|
358
|
+
row[field.name] = nested;
|
|
359
|
+
continue;
|
|
360
|
+
}
|
|
361
|
+
if (!VALUE_TYPES.has(field.type)) continue;
|
|
362
|
+
const value = Object.hasOwn(item, field.name) ? readValue(field, item[field.name], inner, input) : readValue(field, field.defaultValue, inner, input);
|
|
363
|
+
if (value === void 0) {
|
|
364
|
+
if (field.required) input.missing?.(fieldPath, { path: at.path, field: field.name });
|
|
365
|
+
continue;
|
|
366
|
+
}
|
|
367
|
+
row[field.name] = value;
|
|
368
|
+
}
|
|
369
|
+
rows.push(row);
|
|
370
|
+
}
|
|
371
|
+
return rows;
|
|
372
|
+
}
|
|
373
|
+
function readValue(field, value, place, input) {
|
|
374
|
+
if (value === null || value === void 0) return void 0;
|
|
375
|
+
const mark = (text) => input.marking ? input.marking.text(text, place) : text;
|
|
376
|
+
switch (field.type) {
|
|
377
|
+
case "text":
|
|
378
|
+
case "textarea": {
|
|
379
|
+
const text = readFieldValue(field.type === "text" ? "text" : "longText", value);
|
|
380
|
+
return text === null ? void 0 : mark(text);
|
|
381
|
+
}
|
|
382
|
+
case "link": {
|
|
383
|
+
const link = readFieldValue("link", value);
|
|
384
|
+
return link ? { href: link.href, label: mark(link.label) } : void 0;
|
|
385
|
+
}
|
|
386
|
+
case "image":
|
|
387
|
+
return readImage(value, input.stack, mark);
|
|
388
|
+
case "json":
|
|
389
|
+
return copyJson(value);
|
|
390
|
+
default:
|
|
391
|
+
return void 0;
|
|
392
|
+
}
|
|
393
|
+
}
|
|
394
|
+
function readImage(value, stack, mark) {
|
|
395
|
+
const image = readFieldValue("image", value);
|
|
396
|
+
if (!image || image.width === void 0 || image.height === void 0 || !isRecord2(value)) return void 0;
|
|
397
|
+
const result = { src: image.src, alt: mark(image.alt), width: image.width, height: image.height };
|
|
398
|
+
const { focus, blurDataURL } = value;
|
|
399
|
+
if (isFocus(focus)) result.style = { objectPosition: `${percent(focus.x)} ${percent(focus.y)}` };
|
|
400
|
+
if (stack === "next" && isBlurDataUrl(blurDataURL)) {
|
|
401
|
+
result.placeholder = "blur";
|
|
402
|
+
result.blurDataURL = blurDataURL;
|
|
403
|
+
}
|
|
404
|
+
return result;
|
|
405
|
+
}
|
|
406
|
+
var blurDataUrl = /^data:image\/[a-z0-9.+-]+;base64,[A-Za-z0-9+/]+={0,2}$/u;
|
|
407
|
+
function isBlurDataUrl(value) {
|
|
408
|
+
return typeof value === "string" && value.length <= CONTENT_VALUE_LIMITS.blurDataURL && blurDataUrl.test(value);
|
|
409
|
+
}
|
|
410
|
+
function isFocus(value) {
|
|
411
|
+
return isRecord2(value) && [value.x, value.y].every((part) => typeof part === "number" && Number.isFinite(part) && part >= 0 && part <= 1);
|
|
412
|
+
}
|
|
413
|
+
function percent(part) {
|
|
414
|
+
return `${Math.round(part * 1e4) / 100}%`;
|
|
415
|
+
}
|
|
416
|
+
function copyJson(value) {
|
|
417
|
+
if (typeof value !== "object") return value;
|
|
418
|
+
try {
|
|
419
|
+
return structuredClone(value);
|
|
420
|
+
} catch {
|
|
421
|
+
return void 0;
|
|
422
|
+
}
|
|
423
|
+
}
|
|
424
|
+
function child(place, name, fieldId) {
|
|
425
|
+
const steps = [...place.steps, { field: name }];
|
|
426
|
+
return { path: formatContentPath(steps), steps, fieldId };
|
|
427
|
+
}
|
|
428
|
+
function markPath(target, place, input) {
|
|
429
|
+
const path = input.marking?.path(place);
|
|
430
|
+
if (path) target._path = path;
|
|
431
|
+
}
|
|
432
|
+
function isRecord2(value) {
|
|
433
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
434
|
+
}
|
|
435
|
+
|
|
436
|
+
// src/runtime/stega.ts
|
|
437
|
+
import { vercelStegaCombine } from "@vercel/stega";
|
|
438
|
+
var UNMARKED_FIELDS = /* @__PURE__ */ new Set(["meta", "metadata", "openGraph", "seo"]);
|
|
439
|
+
function createMarking(options) {
|
|
440
|
+
return {
|
|
441
|
+
text: (value, place) => options.stega && value !== "" && !unmarked(place) ? vercelStegaCombine(value, place.path, false) : value,
|
|
442
|
+
path: (place) => place.path
|
|
443
|
+
};
|
|
444
|
+
}
|
|
445
|
+
function unmarked(place) {
|
|
446
|
+
return place.steps.some((step) => "field" in step && UNMARKED_FIELDS.has(step.field));
|
|
447
|
+
}
|
|
448
|
+
|
|
449
|
+
// src/client.ts
|
|
450
|
+
import { vercelStegaClean } from "@vercel/stega";
|
|
451
|
+
var FIELD_NAMES = /^[A-Za-z][A-Za-z0-9_]*(?:\.[A-Za-z][A-Za-z0-9_]*)*$/u;
|
|
452
|
+
function attrs(object, field) {
|
|
453
|
+
const path = typeof object === "object" && object !== null ? object._path : void 0;
|
|
454
|
+
if (typeof path !== "string") return {};
|
|
455
|
+
if (field === void 0) return { "data-siteplane-field": path };
|
|
456
|
+
if (FIELD_NAMES.test(field)) return { "data-siteplane-field": `${path}.${field}` };
|
|
457
|
+
console.warn(
|
|
458
|
+
`[Siteplane] siteplane.attrs(object, ${JSON.stringify(field)}) marks nothing: ${JSON.stringify(field)} is not the name of a field. Pass the object that holds the value and the name of its field as siteplane.schema.ts writes it, for example attrs(row, "price").`
|
|
459
|
+
);
|
|
460
|
+
return {};
|
|
461
|
+
}
|
|
462
|
+
function clean(value) {
|
|
463
|
+
return typeof value === "string" || typeof value === "object" && value !== null ? vercelStegaClean(value) : value;
|
|
464
|
+
}
|
|
465
|
+
|
|
466
|
+
// src/astro/client.ts
|
|
467
|
+
function ignore(reason) {
|
|
468
|
+
return import.meta.env.DEV ? { "data-siteplane-ignore": reason } : {};
|
|
469
|
+
}
|
|
470
|
+
|
|
471
|
+
// src/astro/middleware.ts
|
|
472
|
+
var astroPublishedRequest = (config, mode) => mode === "server" ? { url: runtimeCdnValuesUrl(config.apiOrigin, config.siteId), init: {} } : { url: runtimeValuesUrl(config.apiOrigin, config.siteId), init: {} };
|
|
473
|
+
function createSiteplaneMiddleware(dependencies) {
|
|
474
|
+
const { config, build } = dependencies;
|
|
475
|
+
const values = createValueLoader({
|
|
476
|
+
fetch: dependencies.fetch,
|
|
477
|
+
publishedRequest: astroPublishedRequest,
|
|
478
|
+
...dependencies.state ? { state: dependencies.state } : {},
|
|
479
|
+
...dependencies.log ? { log: dependencies.log } : {}
|
|
480
|
+
});
|
|
481
|
+
const load = (site, mode, previewToken) => once(() => values.load(site, { mode, previewToken }));
|
|
482
|
+
function setLocals(context, loadValues, preview, marked = false) {
|
|
483
|
+
const reader = createReader({
|
|
484
|
+
config,
|
|
485
|
+
schema: dependencies.schema,
|
|
486
|
+
stack: "astro",
|
|
487
|
+
loadValues,
|
|
488
|
+
...marked ? { marking: (options) => createMarking({ stega: options.stega !== false }) } : {}
|
|
489
|
+
});
|
|
490
|
+
context.locals.siteplane = { read: reader.read, attrs, clean, ignore };
|
|
491
|
+
context.locals.siteplanePreview = preview;
|
|
492
|
+
}
|
|
493
|
+
return async (context, next) => {
|
|
494
|
+
if (!config) {
|
|
495
|
+
setLocals(context, async () => ({}), null);
|
|
496
|
+
return next();
|
|
497
|
+
}
|
|
498
|
+
const count = dependencies.dev === true && context.locals.siteplaneCount === true;
|
|
499
|
+
if (context.isPrerendered) {
|
|
500
|
+
const stand = build.values;
|
|
501
|
+
setLocals(context, stand ? async () => stand : load(config, "dev", null), null, count);
|
|
502
|
+
return next();
|
|
503
|
+
}
|
|
504
|
+
const routeCaching = build.pageCache === "astro-route-cache";
|
|
505
|
+
const cache = build.preview && routeCaching ? routeCache(context) : null;
|
|
506
|
+
cache?.set(false);
|
|
507
|
+
const preview = build.drafts && (!routeCaching || cache) ? await readPreview(context, config, dependencies) : null;
|
|
508
|
+
const mode = preview ? "preview" : build.dev ? "dev" : "server";
|
|
509
|
+
setLocals(
|
|
510
|
+
context,
|
|
511
|
+
load(config, mode, preview?.token ?? null),
|
|
512
|
+
preview ? { editorOrigin: preview.editorOrigin } : null,
|
|
513
|
+
preview !== null || count
|
|
514
|
+
);
|
|
515
|
+
const response = await next();
|
|
516
|
+
cache?.set(false);
|
|
517
|
+
return preview ? previewResponse(response, config.editorOrigins) : response;
|
|
518
|
+
};
|
|
519
|
+
}
|
|
520
|
+
var onRequest = createSiteplaneMiddleware({
|
|
521
|
+
config: siteConfig,
|
|
522
|
+
schema: siteSchema,
|
|
523
|
+
build: buildInfo,
|
|
524
|
+
fetch: webFetch,
|
|
525
|
+
keys: signingKeys.keys,
|
|
526
|
+
now: () => /* @__PURE__ */ new Date(),
|
|
527
|
+
// Exactly this expression, which Vite fixes when it builds (Nachweis 2, Teil a).
|
|
528
|
+
dev: import.meta.env.DEV
|
|
529
|
+
});
|
|
530
|
+
async function readPreview(context, config, dependencies) {
|
|
531
|
+
try {
|
|
532
|
+
const token = context.cookies.get(PREVIEW_COOKIE)?.value;
|
|
533
|
+
if (!token) return null;
|
|
534
|
+
const claims = await verifySitePreviewToken(config, token, dependencies.keys, dependencies.now());
|
|
535
|
+
return claims ? { token, editorOrigin: claims.editor_origin } : null;
|
|
536
|
+
} catch {
|
|
537
|
+
return null;
|
|
538
|
+
}
|
|
539
|
+
}
|
|
540
|
+
function routeCache(context) {
|
|
541
|
+
const cache = context.cache;
|
|
542
|
+
return typeof cache === "object" && cache !== null && typeof cache.set === "function" ? cache : null;
|
|
543
|
+
}
|
|
544
|
+
var CDN_CACHE_HEADERS = [
|
|
545
|
+
"cdn-cache-control",
|
|
546
|
+
"vercel-cdn-cache-control",
|
|
547
|
+
"netlify-cdn-cache-control",
|
|
548
|
+
"cloudflare-cdn-cache-control",
|
|
549
|
+
"surrogate-control"
|
|
550
|
+
];
|
|
551
|
+
function previewResponse(response, editorOrigins) {
|
|
552
|
+
const policy = mergeFrameAncestors(response.headers.get("content-security-policy"), editorOrigins);
|
|
553
|
+
const forPreview = (headers) => {
|
|
554
|
+
headers.set("cache-control", "no-store");
|
|
555
|
+
headers.set("content-security-policy", policy);
|
|
556
|
+
for (const name of CDN_CACHE_HEADERS) headers.delete(name);
|
|
557
|
+
};
|
|
558
|
+
try {
|
|
559
|
+
forPreview(response.headers);
|
|
560
|
+
return response;
|
|
561
|
+
} catch {
|
|
562
|
+
const headers = new Headers(response.headers);
|
|
563
|
+
forPreview(headers);
|
|
564
|
+
return new Response(response.body, { status: response.status, statusText: response.statusText, headers });
|
|
565
|
+
}
|
|
566
|
+
}
|
|
567
|
+
function once(load) {
|
|
568
|
+
let value;
|
|
569
|
+
return () => value ??= load();
|
|
570
|
+
}
|
|
571
|
+
export {
|
|
572
|
+
createSiteplaneMiddleware,
|
|
573
|
+
onRequest
|
|
574
|
+
};
|