siteplane 0.2.1-rc.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
package/dist/index.d.ts
CHANGED
|
@@ -1,38 +1,105 @@
|
|
|
1
|
-
|
|
1
|
+
import { IgnoreReason } from './schema.js';
|
|
2
|
+
|
|
3
|
+
/** What `attrs` puts on an element: the path of an object read with the marking on, or nothing. */
|
|
4
|
+
type SiteplaneFieldAttributes = {
|
|
5
|
+
"data-siteplane-field"?: string;
|
|
6
|
+
};
|
|
7
|
+
/** What `ignore` puts on an element in a development build, or nothing. */
|
|
8
|
+
type SiteplaneIgnoreAttributes = {
|
|
9
|
+
"data-siteplane-ignore"?: IgnoreReason;
|
|
10
|
+
};
|
|
11
|
+
/**
|
|
12
|
+
* Plan 69 S3b (Dokument 68, 5.2): marks an element by hand for the editor and
|
|
13
|
+
* the count, for a value whose characters the code loses (shortened, split
|
|
14
|
+
* into paragraphs, rewritten by a helper) and for an image without `alt`:
|
|
15
|
+
* `<p {...siteplane.attrs(zeile, "preis")}>`. It gives something only for an
|
|
16
|
+
* object that `read` gave a `_path`, so only while the marking is on; on the
|
|
17
|
+
* server and in client components alike, as `_path` travels with the object.
|
|
18
|
+
*/
|
|
19
|
+
declare function attrs(object: unknown, field?: string): SiteplaneFieldAttributes;
|
|
20
|
+
/**
|
|
21
|
+
* Plan 69 S3b (Dokument 68, 5.2): a value without the invisible characters of
|
|
22
|
+
* the preview, like `stegaClean` of Sanity: texts, objects and lists; other
|
|
23
|
+
* values stay. Needed where code compares a text, turns it into a number or an
|
|
24
|
+
* address, writes it into an attribute, trims or splits it at white space, or
|
|
25
|
+
* judges or cuts it by its length.
|
|
26
|
+
*/
|
|
27
|
+
declare function clean<Value>(value: Value): Value;
|
|
28
|
+
/**
|
|
29
|
+
* Plan 69 S3b (Dokument 68, 7.2): leaves an element and everything in it that
|
|
30
|
+
* is not bound to content out of the count, with a reason:
|
|
31
|
+
* `<div {...siteplane.ignore("decoration")}>`. Only a development build gets
|
|
32
|
+
* the attribute, as only the dev server counts; Next.js fixes NODE_ENV when it
|
|
33
|
+
* builds, so visitors never get it.
|
|
34
|
+
*/
|
|
35
|
+
declare function ignore(reason: IgnoreReason): SiteplaneIgnoreAttributes;
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* Options of `siteplane.read`. `stega: false` reads without the invisible
|
|
39
|
+
* characters of the preview, e.g. for the title of a page (Dokument 68, 5.2);
|
|
40
|
+
* the marking itself comes with Plan 69 S3b.
|
|
41
|
+
*/
|
|
42
|
+
type SiteplaneReadOptions = {
|
|
43
|
+
stega?: boolean;
|
|
44
|
+
};
|
|
45
|
+
/** A link as the website reads it, value by value. */
|
|
2
46
|
type SiteplaneLink = {
|
|
3
47
|
href: string;
|
|
4
48
|
label: string;
|
|
5
49
|
};
|
|
6
|
-
/**
|
|
50
|
+
/**
|
|
51
|
+
* An image for `next/image`, spread whole (`<Image {...bild} />`). With `fill`
|
|
52
|
+
* the website leaves out width and height; with its own `style` it merges it
|
|
53
|
+
* (`style={{ ...bild.style, borderRadius: 8 }}`), or the focus point is lost. A
|
|
54
|
+
* plain `<img>` takes only `src`, `alt`, `width`, `height` and `style`.
|
|
55
|
+
*/
|
|
7
56
|
type SiteplaneImage = {
|
|
8
57
|
src: string;
|
|
9
58
|
alt: string;
|
|
10
|
-
width
|
|
11
|
-
height
|
|
59
|
+
width: number;
|
|
60
|
+
height: number;
|
|
61
|
+
/** Only with a focus point, e.g. `{ objectPosition: "80% 30%" }`. */
|
|
62
|
+
style?: {
|
|
63
|
+
objectPosition: string;
|
|
64
|
+
};
|
|
65
|
+
/** Only when Siteplane has a loading preview of the image, and then always together. */
|
|
66
|
+
placeholder?: "blur";
|
|
67
|
+
blurDataURL?: string;
|
|
12
68
|
};
|
|
13
|
-
type SiteplaneAttrs = {
|
|
14
|
-
"data-siteplane-field": string;
|
|
15
|
-
} | Record<string, never>;
|
|
16
|
-
/** The attribute the bridge finds the field by in the Draft Mode preview. */
|
|
17
|
-
declare function attrs(fieldId: string): SiteplaneAttrs;
|
|
18
69
|
|
|
19
70
|
/**
|
|
20
|
-
* The
|
|
71
|
+
* The globals of this website and the shape of their content. The generated
|
|
72
|
+
* `siteplane.generated.ts` adds them with `declare module "siteplane"`, as
|
|
73
|
+
* Payload's `GeneratedTypes`; `npx siteplane check` and `sync` write it.
|
|
74
|
+
*/
|
|
75
|
+
interface SiteplaneGlobals {
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* `siteplane.read(slug)`: the content of one global, typed by `SiteplaneGlobals`,
|
|
79
|
+
* and the helpers of `siteplane/client` for server components.
|
|
80
|
+
*/
|
|
81
|
+
type SiteplaneReader = {
|
|
82
|
+
read<Slug extends keyof SiteplaneGlobals>(slug: Slug, options?: SiteplaneReadOptions): Promise<SiteplaneGlobals[Slug]>;
|
|
83
|
+
attrs: typeof attrs;
|
|
84
|
+
clean: typeof clean;
|
|
85
|
+
ignore: typeof ignore;
|
|
86
|
+
};
|
|
87
|
+
/**
|
|
88
|
+
* Plan 69 S3a, S3b (Dokument 68, 5.1 and 5.2): the content of the website for
|
|
89
|
+
* server components, as it is published in Siteplane.
|
|
21
90
|
*
|
|
22
91
|
* ```tsx
|
|
23
|
-
* const
|
|
24
|
-
* <h1
|
|
92
|
+
* const home = await siteplane.read("home");
|
|
93
|
+
* <h1>{home.hero.title}</h1>
|
|
25
94
|
* ```
|
|
26
95
|
*
|
|
27
|
-
* All values of the site load once per request (React `cache()`)
|
|
28
|
-
*
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
attrs: typeof attrs;
|
|
36
|
-
};
|
|
96
|
+
* All values of the site load once per request (React `cache()`): cached for
|
|
97
|
+
* 60 seconds on the server, without cache on the dev server and in the
|
|
98
|
+
* preview. Without Siteplane a page shows the last good content of its server;
|
|
99
|
+
* without that it fails with a message that names the reason. In the editor's
|
|
100
|
+
* preview, and for the count request on the dev server, texts carry invisible
|
|
101
|
+
* characters with their path and objects `_path`; visitors get neither.
|
|
102
|
+
*/
|
|
103
|
+
declare const siteplane: SiteplaneReader;
|
|
37
104
|
|
|
38
|
-
export { type
|
|
105
|
+
export { type SiteplaneFieldAttributes, type SiteplaneGlobals, type SiteplaneIgnoreAttributes, type SiteplaneImage, type SiteplaneLink, type SiteplaneReadOptions, type SiteplaneReader, siteplane };
|
package/dist/index.js
CHANGED
|
@@ -1,11 +1,67 @@
|
|
|
1
1
|
import {
|
|
2
|
-
|
|
3
|
-
|
|
2
|
+
loadRequestValues,
|
|
3
|
+
readMarkingMode,
|
|
4
|
+
serverShared,
|
|
5
|
+
siteConfig,
|
|
6
|
+
siteSchema
|
|
7
|
+
} from "./chunk-IOFM5PE3.js";
|
|
4
8
|
import "./chunk-KZ3AQ6OA.js";
|
|
5
9
|
|
|
6
10
|
// src/index.ts
|
|
7
11
|
import { cache } from "react";
|
|
8
12
|
|
|
13
|
+
// src/client.ts
|
|
14
|
+
import { vercelStegaClean } from "@vercel/stega";
|
|
15
|
+
var FIELD_NAMES = /^[A-Za-z][A-Za-z0-9_]*(?:\.[A-Za-z][A-Za-z0-9_]*)*$/u;
|
|
16
|
+
function attrs(object, field) {
|
|
17
|
+
const path = typeof object === "object" && object !== null ? object._path : void 0;
|
|
18
|
+
if (typeof path !== "string") return {};
|
|
19
|
+
if (field === void 0) return { "data-siteplane-field": path };
|
|
20
|
+
if (FIELD_NAMES.test(field)) return { "data-siteplane-field": `${path}.${field}` };
|
|
21
|
+
console.warn(
|
|
22
|
+
`[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").`
|
|
23
|
+
);
|
|
24
|
+
return {};
|
|
25
|
+
}
|
|
26
|
+
function clean(value) {
|
|
27
|
+
return typeof value === "string" || typeof value === "object" && value !== null ? vercelStegaClean(value) : value;
|
|
28
|
+
}
|
|
29
|
+
function ignore(reason) {
|
|
30
|
+
return process.env.NODE_ENV === "development" ? { "data-siteplane-ignore": reason } : {};
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
// ../shared/dist/field-id.js
|
|
34
|
+
import { z } from "zod";
|
|
35
|
+
var FIELD_ID_PATTERN = /^[A-Za-z][A-Za-z0-9_-]*(\.[A-Za-z][A-Za-z0-9_-]*)+$/;
|
|
36
|
+
var FIELD_ID_MAX_LENGTH = 160;
|
|
37
|
+
var FIELD_SYNC_MAX_BYTES = 4 * 1024 * 1024;
|
|
38
|
+
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");
|
|
39
|
+
var FIELD_NAME_PATTERN = /^[A-Za-z][A-Za-z0-9_]*$/;
|
|
40
|
+
var FIELD_NAME_MAX_LENGTH = 64;
|
|
41
|
+
function isFieldName(value) {
|
|
42
|
+
return typeof value === "string" && value.length <= FIELD_NAME_MAX_LENGTH && FIELD_NAME_PATTERN.test(value);
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
// ../shared/dist/content-path.js
|
|
46
|
+
var ROW_KEY_PATTERN = /^[a-z][a-z0-9]{7}$/u;
|
|
47
|
+
function formatContentPath(steps) {
|
|
48
|
+
let path = "";
|
|
49
|
+
for (const step of steps) {
|
|
50
|
+
if ("field" in step)
|
|
51
|
+
path += path === "" ? step.field : `.${step.field}`;
|
|
52
|
+
else if ("key" in step)
|
|
53
|
+
path += `[_key=="${step.key}"]`;
|
|
54
|
+
else
|
|
55
|
+
path += `[${step.index}]`;
|
|
56
|
+
}
|
|
57
|
+
return path;
|
|
58
|
+
}
|
|
59
|
+
function isRowKey(value) {
|
|
60
|
+
return typeof value === "string" && ROW_KEY_PATTERN.test(value);
|
|
61
|
+
}
|
|
62
|
+
var letters = "abcdefghijklmnopqrstuvwxyz";
|
|
63
|
+
var lettersAndDigits = `${letters}0123456789`;
|
|
64
|
+
|
|
9
65
|
// ../shared/dist/field-values.js
|
|
10
66
|
var FIELD_VALUE_LIMITS = {
|
|
11
67
|
text: 256,
|
|
@@ -13,12 +69,43 @@ var FIELD_VALUE_LIMITS = {
|
|
|
13
69
|
linkLabel: 256,
|
|
14
70
|
linkHref: 2048,
|
|
15
71
|
imageSrc: 2048,
|
|
72
|
+
imageFile: 2048,
|
|
16
73
|
imageAlt: 300,
|
|
17
74
|
imageSize: 1e5
|
|
18
75
|
};
|
|
76
|
+
var FIELD_VALUE_PROBLEMS = [
|
|
77
|
+
"not_text",
|
|
78
|
+
"too_long",
|
|
79
|
+
"not_object",
|
|
80
|
+
"unknown_key",
|
|
81
|
+
"href_invalid",
|
|
82
|
+
"label_missing",
|
|
83
|
+
"label_too_long",
|
|
84
|
+
"asset_missing",
|
|
85
|
+
"src_invalid",
|
|
86
|
+
"alt_invalid",
|
|
87
|
+
"size_invalid",
|
|
88
|
+
"unknown_type"
|
|
89
|
+
];
|
|
90
|
+
var FIELD_VALUE_PROBLEM_TEXT = {
|
|
91
|
+
not_text: "it must be a string",
|
|
92
|
+
too_long: "it is too long (short text 256, long text 50,000 characters)",
|
|
93
|
+
not_object: "it must be an object",
|
|
94
|
+
unknown_key: "it has keys the field type does not know",
|
|
95
|
+
href_invalid: "href must be a path such as /menu, an anchor such as #contact, or start with http(s)://, mailto: or tel:",
|
|
96
|
+
label_missing: "a link needs a visible label",
|
|
97
|
+
label_too_long: "the label is longer than 256 characters",
|
|
98
|
+
asset_missing: "the image needs an asset uploaded to this site",
|
|
99
|
+
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")',
|
|
100
|
+
alt_invalid: "alt must be a string of at most 300 characters; it may be empty",
|
|
101
|
+
size_invalid: "width and height must be whole numbers from 1 to 100,000",
|
|
102
|
+
unknown_type: "this field type has no single value; a list is checked with its row type"
|
|
103
|
+
};
|
|
19
104
|
var linkKeys = ["href", "label"];
|
|
20
|
-
var
|
|
105
|
+
var renderedImageKeys = ["src", "alt", "width", "height"];
|
|
106
|
+
var fallbackImageKeys = ["src", "file", "alt", "width", "height"];
|
|
21
107
|
var contentImageKeys = ["assetId", "src", "alt", "width", "height"];
|
|
108
|
+
var controlCharacter = /[\u0000-\u001f\u007f-\u009f]/u;
|
|
22
109
|
var asciiBlank = /^[ \t\n\v\f\r]*$/u;
|
|
23
110
|
var uuidPattern = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/iu;
|
|
24
111
|
var webAddress = /^https?:\/\/[^/?#@]+(?:[/?#].*)?$/isu;
|
|
@@ -33,12 +120,44 @@ function fieldValueProblem(type, value, origin) {
|
|
|
33
120
|
return linkProblem(value);
|
|
34
121
|
case "image":
|
|
35
122
|
return imageProblem(value, origin);
|
|
123
|
+
case "array":
|
|
124
|
+
return "unknown_type";
|
|
36
125
|
}
|
|
37
126
|
}
|
|
38
127
|
function readFieldValue(type, value) {
|
|
39
|
-
const rendered = type === "link" ? pick(value, linkKeys) : type === "image" ? pick(value,
|
|
128
|
+
const rendered = type === "link" ? pick(value, linkKeys) : type === "image" ? pick(value, renderedImageKeys) : value;
|
|
40
129
|
return fieldValueProblem(type, rendered, "fallback") === null ? rendered : null;
|
|
41
130
|
}
|
|
131
|
+
var CONTENT_VALUE_LIMITS = { valueBytes: 256 * 1024, listDepth: 3, blurDataURL: 1024 };
|
|
132
|
+
var CONTENT_VALUE_PROBLEMS = [
|
|
133
|
+
...FIELD_VALUE_PROBLEMS,
|
|
134
|
+
"required",
|
|
135
|
+
"not_list",
|
|
136
|
+
"key_missing",
|
|
137
|
+
"key_invalid",
|
|
138
|
+
"key_duplicate",
|
|
139
|
+
"too_few_rows",
|
|
140
|
+
"too_many_rows",
|
|
141
|
+
"too_deep",
|
|
142
|
+
"too_large",
|
|
143
|
+
"focus_invalid",
|
|
144
|
+
"blur_invalid"
|
|
145
|
+
];
|
|
146
|
+
var CONTENT_VALUE_PROBLEM_TEXT = {
|
|
147
|
+
...FIELD_VALUE_PROBLEM_TEXT,
|
|
148
|
+
unknown_key: "it has keys the field type or the row type does not know",
|
|
149
|
+
required: "it is required and cannot be empty",
|
|
150
|
+
not_list: "a list must be an array of rows",
|
|
151
|
+
key_missing: "the row has no _key; Siteplane gives a key to each row you add",
|
|
152
|
+
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",
|
|
153
|
+
key_duplicate: "another row of this list has the same _key; remove the _key from the row you added",
|
|
154
|
+
too_few_rows: "the list has fewer rows than its minRows",
|
|
155
|
+
too_many_rows: "the list has more rows than its maxRows",
|
|
156
|
+
too_deep: "lists stand in lists at most three levels deep",
|
|
157
|
+
too_large: "the value is larger than 256 KB",
|
|
158
|
+
focus_invalid: "focus must be { x, y } with numbers from 0 to 1",
|
|
159
|
+
blur_invalid: "blurDataURL must be a data address of an image of at most 1 KB; Siteplane sets it"
|
|
160
|
+
};
|
|
42
161
|
function linkProblem(value) {
|
|
43
162
|
if (!isRecord(value))
|
|
44
163
|
return "not_object";
|
|
@@ -58,7 +177,8 @@ function imageProblem(value, origin) {
|
|
|
58
177
|
if (origin === "content" && (typeof value.assetId !== "string" || !uuidPattern.test(value.assetId))) {
|
|
59
178
|
return "asset_missing";
|
|
60
179
|
}
|
|
61
|
-
|
|
180
|
+
const source = value.file === void 0 ? isImageSource(value.src) : value.src === void 0 && isImportPath(value.file);
|
|
181
|
+
if (!source)
|
|
62
182
|
return "src_invalid";
|
|
63
183
|
if (typeof value.alt !== "string" || codePoints(value.alt) > FIELD_VALUE_LIMITS.imageAlt)
|
|
64
184
|
return "alt_invalid";
|
|
@@ -77,6 +197,9 @@ function isHref(value) {
|
|
|
77
197
|
function isImageSource(value) {
|
|
78
198
|
return isAddressText(value, FIELD_VALUE_LIMITS.imageSrc) && (isSitePath(value) || webAddress.test(value));
|
|
79
199
|
}
|
|
200
|
+
function isImportPath(value) {
|
|
201
|
+
return typeof value === "string" && value.length > 0 && codePoints(value) <= FIELD_VALUE_LIMITS.imageFile && !controlCharacter.test(value);
|
|
202
|
+
}
|
|
80
203
|
function isSitePath(value) {
|
|
81
204
|
return value.startsWith("/") && !value.startsWith("//");
|
|
82
205
|
}
|
|
@@ -108,31 +231,220 @@ function isRecord(value) {
|
|
|
108
231
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
109
232
|
}
|
|
110
233
|
|
|
111
|
-
// src/runtime/
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
234
|
+
// src/runtime/read.ts
|
|
235
|
+
var VALUE_TYPES = /* @__PURE__ */ new Set(["text", "textarea", "link", "image", "json"]);
|
|
236
|
+
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.";
|
|
237
|
+
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.";
|
|
238
|
+
function createReader(dependencies) {
|
|
239
|
+
return {
|
|
240
|
+
async read(slug, options = {}) {
|
|
241
|
+
if (!dependencies.config) throw new Error(noConfig);
|
|
242
|
+
findGlobal(dependencies.schema, slug);
|
|
243
|
+
const [values, marking] = await Promise.all([dependencies.loadValues(), dependencies.marking?.(options) ?? null]);
|
|
244
|
+
return readGlobal({
|
|
245
|
+
schema: dependencies.schema,
|
|
246
|
+
slug,
|
|
247
|
+
values,
|
|
248
|
+
stack: dependencies.stack,
|
|
249
|
+
marking,
|
|
250
|
+
missing: dependencies.missing ?? reportMissingContent
|
|
251
|
+
});
|
|
120
252
|
}
|
|
253
|
+
};
|
|
254
|
+
}
|
|
255
|
+
function readGlobal(input) {
|
|
256
|
+
const global = findGlobal(input.schema, input.slug);
|
|
257
|
+
const place = { path: input.slug, steps: [{ field: input.slug }], fieldId: null };
|
|
258
|
+
const result = readFields(global.fields, place, input.slug, input);
|
|
259
|
+
markPath(result, place, input);
|
|
260
|
+
return result;
|
|
261
|
+
}
|
|
262
|
+
function missingContentReporter(warn = console.warn) {
|
|
263
|
+
const reported = /* @__PURE__ */ new Set();
|
|
264
|
+
return (id, row) => {
|
|
265
|
+
if (reported.has(id)) return;
|
|
266
|
+
reported.add(id);
|
|
267
|
+
warn(
|
|
268
|
+
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.`
|
|
269
|
+
);
|
|
270
|
+
};
|
|
271
|
+
}
|
|
272
|
+
var reportMissingContent = (id, row) => serverShared("missingContent", () => missingContentReporter())(id, row);
|
|
273
|
+
function findGlobal(schema, slug) {
|
|
274
|
+
if (!isRecord2(schema) || !Array.isArray(schema.globals)) throw new Error(notFound);
|
|
275
|
+
const global = schema.globals.find((entry) => isRecord2(entry) && entry.slug === slug);
|
|
276
|
+
if (!isRecord2(global)) {
|
|
277
|
+
throw new Error(`[Siteplane] siteplane.schema.ts has no global ${JSON.stringify(slug)}. Add it to the description and run npx siteplane check.`);
|
|
121
278
|
}
|
|
279
|
+
return { fields: fieldsOf(global.fields) };
|
|
280
|
+
}
|
|
281
|
+
function fieldsOf(value) {
|
|
282
|
+
if (!Array.isArray(value)) return [];
|
|
283
|
+
return value.flatMap((entry) => {
|
|
284
|
+
if (!isRecord2(entry) || !isFieldName(entry.name) || typeof entry.type !== "string") return [];
|
|
285
|
+
return [
|
|
286
|
+
{
|
|
287
|
+
name: entry.name,
|
|
288
|
+
type: entry.type,
|
|
289
|
+
required: entry.required === true,
|
|
290
|
+
...Object.hasOwn(entry, "defaultValue") ? { defaultValue: entry.defaultValue } : {},
|
|
291
|
+
fields: fieldsOf(entry.fields)
|
|
292
|
+
}
|
|
293
|
+
];
|
|
294
|
+
});
|
|
295
|
+
}
|
|
296
|
+
function readFields(fields, place, id, input) {
|
|
297
|
+
const result = {};
|
|
298
|
+
for (const field of fields) {
|
|
299
|
+
const fieldId = `${id}.${field.name}`;
|
|
300
|
+
if (field.type === "group") {
|
|
301
|
+
const at2 = child(place, field.name, null);
|
|
302
|
+
const group = readFields(field.fields, at2, fieldId, input);
|
|
303
|
+
markPath(group, at2, input);
|
|
304
|
+
result[field.name] = group;
|
|
305
|
+
continue;
|
|
306
|
+
}
|
|
307
|
+
const at = child(place, field.name, fieldId);
|
|
308
|
+
const stored = Object.hasOwn(input.values, fieldId) ? input.values[fieldId] : void 0;
|
|
309
|
+
if (field.type === "array") {
|
|
310
|
+
const rows = readRows(field.fields, stored, at, input, 1, fieldId);
|
|
311
|
+
if (field.required && rows.length === 0) input.missing?.(fieldId);
|
|
312
|
+
result[field.name] = rows;
|
|
313
|
+
continue;
|
|
314
|
+
}
|
|
315
|
+
if (!VALUE_TYPES.has(field.type)) continue;
|
|
316
|
+
const value = readValue(field, stored, at, input);
|
|
317
|
+
if (value === void 0) {
|
|
318
|
+
if (field.required) input.missing?.(fieldId);
|
|
319
|
+
continue;
|
|
320
|
+
}
|
|
321
|
+
result[field.name] = value;
|
|
322
|
+
}
|
|
323
|
+
return result;
|
|
324
|
+
}
|
|
325
|
+
function readRows(fields, stored, place, input, depth, listPath) {
|
|
326
|
+
if (!Array.isArray(stored) || depth > CONTENT_VALUE_LIMITS.listDepth) return [];
|
|
327
|
+
const rows = [];
|
|
328
|
+
const keys = /* @__PURE__ */ new Set();
|
|
329
|
+
for (const item of stored) {
|
|
330
|
+
if (!isRecord2(item) || !isRowKey(item._key) || keys.has(item._key)) continue;
|
|
331
|
+
keys.add(item._key);
|
|
332
|
+
const at = {
|
|
333
|
+
path: formatContentPath([...place.steps, { key: item._key }]),
|
|
334
|
+
steps: [...place.steps, { key: item._key }],
|
|
335
|
+
fieldId: place.fieldId
|
|
336
|
+
};
|
|
337
|
+
const row = { _key: item._key };
|
|
338
|
+
markPath(row, at, input);
|
|
339
|
+
for (const field of fields) {
|
|
340
|
+
const inner = child(at, field.name, place.fieldId);
|
|
341
|
+
const fieldPath = `${listPath}.${field.name}`;
|
|
342
|
+
if (field.type === "array") {
|
|
343
|
+
const nested = readRows(field.fields, item[field.name], inner, input, depth + 1, fieldPath);
|
|
344
|
+
if (field.required && nested.length === 0 && depth < CONTENT_VALUE_LIMITS.listDepth) {
|
|
345
|
+
input.missing?.(fieldPath, { path: at.path, field: field.name });
|
|
346
|
+
}
|
|
347
|
+
row[field.name] = nested;
|
|
348
|
+
continue;
|
|
349
|
+
}
|
|
350
|
+
if (!VALUE_TYPES.has(field.type)) continue;
|
|
351
|
+
const value = Object.hasOwn(item, field.name) ? readValue(field, item[field.name], inner, input) : readValue(field, field.defaultValue, inner, input);
|
|
352
|
+
if (value === void 0) {
|
|
353
|
+
if (field.required) input.missing?.(fieldPath, { path: at.path, field: field.name });
|
|
354
|
+
continue;
|
|
355
|
+
}
|
|
356
|
+
row[field.name] = value;
|
|
357
|
+
}
|
|
358
|
+
rows.push(row);
|
|
359
|
+
}
|
|
360
|
+
return rows;
|
|
361
|
+
}
|
|
362
|
+
function readValue(field, value, place, input) {
|
|
363
|
+
if (value === null || value === void 0) return void 0;
|
|
364
|
+
const mark = (text) => input.marking ? input.marking.text(text, place) : text;
|
|
365
|
+
switch (field.type) {
|
|
366
|
+
case "text":
|
|
367
|
+
case "textarea": {
|
|
368
|
+
const text = readFieldValue(field.type === "text" ? "text" : "longText", value);
|
|
369
|
+
return text === null ? void 0 : mark(text);
|
|
370
|
+
}
|
|
371
|
+
case "link": {
|
|
372
|
+
const link = readFieldValue("link", value);
|
|
373
|
+
return link ? { href: link.href, label: mark(link.label) } : void 0;
|
|
374
|
+
}
|
|
375
|
+
case "image":
|
|
376
|
+
return readImage(value, input.stack, mark);
|
|
377
|
+
case "json":
|
|
378
|
+
return copyJson(value);
|
|
379
|
+
default:
|
|
380
|
+
return void 0;
|
|
381
|
+
}
|
|
382
|
+
}
|
|
383
|
+
function readImage(value, stack, mark) {
|
|
384
|
+
const image = readFieldValue("image", value);
|
|
385
|
+
if (!image || image.width === void 0 || image.height === void 0 || !isRecord2(value)) return void 0;
|
|
386
|
+
const result = { src: image.src, alt: mark(image.alt), width: image.width, height: image.height };
|
|
387
|
+
const { focus, blurDataURL } = value;
|
|
388
|
+
if (isFocus(focus)) result.style = { objectPosition: `${percent(focus.x)} ${percent(focus.y)}` };
|
|
389
|
+
if (stack === "next" && isBlurDataUrl(blurDataURL)) {
|
|
390
|
+
result.placeholder = "blur";
|
|
391
|
+
result.blurDataURL = blurDataURL;
|
|
392
|
+
}
|
|
393
|
+
return result;
|
|
394
|
+
}
|
|
395
|
+
var blurDataUrl = /^data:image\/[a-z0-9.+-]+;base64,[A-Za-z0-9+/]+={0,2}$/u;
|
|
396
|
+
function isBlurDataUrl(value) {
|
|
397
|
+
return typeof value === "string" && value.length <= CONTENT_VALUE_LIMITS.blurDataURL && blurDataUrl.test(value);
|
|
398
|
+
}
|
|
399
|
+
function isFocus(value) {
|
|
400
|
+
return isRecord2(value) && [value.x, value.y].every((part) => typeof part === "number" && Number.isFinite(part) && part >= 0 && part <= 1);
|
|
401
|
+
}
|
|
402
|
+
function percent(part) {
|
|
403
|
+
return `${Math.round(part * 1e4) / 100}%`;
|
|
404
|
+
}
|
|
405
|
+
function copyJson(value) {
|
|
406
|
+
if (typeof value !== "object") return value;
|
|
407
|
+
try {
|
|
408
|
+
return structuredClone(value);
|
|
409
|
+
} catch {
|
|
410
|
+
return void 0;
|
|
411
|
+
}
|
|
412
|
+
}
|
|
413
|
+
function child(place, name, fieldId) {
|
|
414
|
+
const steps = [...place.steps, { field: name }];
|
|
415
|
+
return { path: formatContentPath(steps), steps, fieldId };
|
|
416
|
+
}
|
|
417
|
+
function markPath(target, place, input) {
|
|
418
|
+
const path = input.marking?.path(place);
|
|
419
|
+
if (path) target._path = path;
|
|
420
|
+
}
|
|
421
|
+
function isRecord2(value) {
|
|
422
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
423
|
+
}
|
|
424
|
+
|
|
425
|
+
// src/runtime/stega.ts
|
|
426
|
+
import { vercelStegaCombine } from "@vercel/stega";
|
|
427
|
+
var UNMARKED_FIELDS = /* @__PURE__ */ new Set(["meta", "metadata", "openGraph", "seo"]);
|
|
428
|
+
function createMarking(options) {
|
|
122
429
|
return {
|
|
123
|
-
text: (
|
|
124
|
-
|
|
125
|
-
link: (fieldId, fallback) => read("link", fieldId, fallback),
|
|
126
|
-
image: (fieldId, fallback) => read("image", fieldId, fallback),
|
|
127
|
-
attrs
|
|
430
|
+
text: (value, place) => options.stega && value !== "" && !unmarked(place) ? vercelStegaCombine(value, place.path, false) : value,
|
|
431
|
+
path: (place) => place.path
|
|
128
432
|
};
|
|
129
433
|
}
|
|
130
|
-
function
|
|
131
|
-
return
|
|
434
|
+
function unmarked(place) {
|
|
435
|
+
return place.steps.some((step) => "field" in step && UNMARKED_FIELDS.has(step.field));
|
|
132
436
|
}
|
|
133
437
|
|
|
134
438
|
// src/index.ts
|
|
135
|
-
var
|
|
439
|
+
var reader = createReader({
|
|
440
|
+
config: siteConfig,
|
|
441
|
+
schema: siteSchema,
|
|
442
|
+
stack: "next",
|
|
443
|
+
loadValues: cache(loadRequestValues),
|
|
444
|
+
// Plan 69 S3b: the editor's preview and the count request on the dev server mark the content (Dokument 68, 5.2).
|
|
445
|
+
marking: async (options) => await readMarkingMode() ? createMarking({ stega: options.stega !== false }) : null
|
|
446
|
+
});
|
|
447
|
+
var siteplane = { read: reader.read, attrs, clean, ignore };
|
|
136
448
|
export {
|
|
137
449
|
siteplane
|
|
138
450
|
};
|
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
// ../shared/dist/site-analytics.js
|
|
2
|
+
var SITE_ANALYTICS_SEND_PATH = "/api/analytics/send";
|
|
3
|
+
var SITE_ANALYTICS_EVENT_ATTRIBUTE = "data-siteplane-event";
|
|
4
|
+
var SITE_ANALYTICS_LINK_EVENTS = {
|
|
5
|
+
outbound: "outbound-link",
|
|
6
|
+
tel: "tel-link",
|
|
7
|
+
mailto: "mailto-link"
|
|
8
|
+
};
|
|
9
|
+
function siteAnalyticsEndpoint(apiOrigin) {
|
|
10
|
+
return `${apiOrigin}${SITE_ANALYTICS_SEND_PATH}`;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
// ../shared/dist/siteplane-config.js
|
|
14
|
+
var siteIdPattern = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/u;
|
|
15
|
+
function readSiteplaneConfig(value) {
|
|
16
|
+
if (typeof value !== "object" || value === null)
|
|
17
|
+
return null;
|
|
18
|
+
const { siteId, apiOrigin, editorOrigins } = value;
|
|
19
|
+
if (typeof siteId !== "string" || !siteIdPattern.test(siteId) || !isWebOrigin(apiOrigin) || !Array.isArray(editorOrigins) || !editorOrigins.every(isWebOrigin)) {
|
|
20
|
+
return null;
|
|
21
|
+
}
|
|
22
|
+
return { siteId, apiOrigin, editorOrigins: [...editorOrigins] };
|
|
23
|
+
}
|
|
24
|
+
function isWebOrigin(value) {
|
|
25
|
+
if (typeof value !== "string")
|
|
26
|
+
return false;
|
|
27
|
+
try {
|
|
28
|
+
const url = new URL(value);
|
|
29
|
+
return (url.protocol === "https:" || url.protocol === "http:") && url.origin === value;
|
|
30
|
+
} catch {
|
|
31
|
+
return false;
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
// src/analytics.ts
|
|
36
|
+
function createAnalytics(config, deps = {}) {
|
|
37
|
+
const send = deps.send ?? sendEvent;
|
|
38
|
+
let lastUrl = null;
|
|
39
|
+
const page = () => ({
|
|
40
|
+
website: config.siteId,
|
|
41
|
+
hostname: location.hostname,
|
|
42
|
+
url: location.pathname + location.search,
|
|
43
|
+
screen: `${screen.width}x${screen.height}`
|
|
44
|
+
});
|
|
45
|
+
const emit = (payload) => send(config.endpoint, { type: "event", payload });
|
|
46
|
+
const onClick = (event) => {
|
|
47
|
+
if (event.type === "auxclick" && event.button !== 1) return;
|
|
48
|
+
const element = event.target instanceof Element ? event.target : null;
|
|
49
|
+
const name = element?.closest(`[${SITE_ANALYTICS_EVENT_ATTRIBUTE}]`)?.getAttribute(SITE_ANALYTICS_EVENT_ATTRIBUTE)?.trim();
|
|
50
|
+
if (name) return emit({ ...page(), name: name.slice(0, 100) });
|
|
51
|
+
const link = element?.closest("a[href]");
|
|
52
|
+
if (!(link instanceof HTMLAnchorElement)) return;
|
|
53
|
+
const kind = link.protocol === "tel:" ? SITE_ANALYTICS_LINK_EVENTS.tel : link.protocol === "mailto:" ? SITE_ANALYTICS_LINK_EVENTS.mailto : /^https?:$/u.test(link.protocol) && link.host !== location.host ? SITE_ANALYTICS_LINK_EVENTS.outbound : null;
|
|
54
|
+
if (kind) emit({ ...page(), name: kind, data: { url: link.href } });
|
|
55
|
+
};
|
|
56
|
+
return {
|
|
57
|
+
/** Counts the current page once; a later page names the previous one as referrer. */
|
|
58
|
+
pageView() {
|
|
59
|
+
const current = page();
|
|
60
|
+
if (current.url === lastUrl) return;
|
|
61
|
+
const referrer = lastUrl === null ? document.referrer : `${location.origin}${lastUrl}`;
|
|
62
|
+
lastUrl = current.url;
|
|
63
|
+
emit(referrer ? { ...current, referrer } : current);
|
|
64
|
+
},
|
|
65
|
+
/** Listens for clicks (and middle clicks) until the returned function runs. */
|
|
66
|
+
start() {
|
|
67
|
+
document.addEventListener("click", onClick, true);
|
|
68
|
+
document.addEventListener("auxclick", onClick, true);
|
|
69
|
+
return () => {
|
|
70
|
+
document.removeEventListener("click", onClick, true);
|
|
71
|
+
document.removeEventListener("auxclick", onClick, true);
|
|
72
|
+
};
|
|
73
|
+
}
|
|
74
|
+
};
|
|
75
|
+
}
|
|
76
|
+
function sendEvent(endpoint, body) {
|
|
77
|
+
try {
|
|
78
|
+
void fetch(endpoint, {
|
|
79
|
+
method: "POST",
|
|
80
|
+
body: JSON.stringify(body),
|
|
81
|
+
headers: { "content-type": "text/plain" },
|
|
82
|
+
credentials: "omit",
|
|
83
|
+
keepalive: true
|
|
84
|
+
}).catch(() => void 0);
|
|
85
|
+
} catch {
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
// src/internal/astro-client.ts
|
|
90
|
+
var analyticsStarted = false;
|
|
91
|
+
function startAnalytics(config) {
|
|
92
|
+
if (analyticsStarted) return;
|
|
93
|
+
analyticsStarted = true;
|
|
94
|
+
const analytics = createAnalytics(config);
|
|
95
|
+
analytics.start();
|
|
96
|
+
analytics.pageView();
|
|
97
|
+
document.addEventListener("astro:page-load", () => analytics.pageView());
|
|
98
|
+
}
|
|
99
|
+
function startPreviewBridge(input) {
|
|
100
|
+
if (!input.editorOrigin) return;
|
|
101
|
+
const base = input.base.replace(/\/+$/u, "");
|
|
102
|
+
void import("siteplane/internal/bridge").then(
|
|
103
|
+
({ startBridge }) => startBridge({
|
|
104
|
+
editorOrigin: input.editorOrigin,
|
|
105
|
+
refresh: () => window.location.reload(),
|
|
106
|
+
path: () => pathBelow(window.location.pathname, base)
|
|
107
|
+
})
|
|
108
|
+
);
|
|
109
|
+
}
|
|
110
|
+
function analyticsEndpoint(config) {
|
|
111
|
+
return siteAnalyticsEndpoint(readSiteplaneConfig(config)?.apiOrigin ?? "https://siteplane.io");
|
|
112
|
+
}
|
|
113
|
+
function pathBelow(pathname, base) {
|
|
114
|
+
if (!base) return pathname;
|
|
115
|
+
if (pathname === base) return "/";
|
|
116
|
+
return pathname.startsWith(`${base}/`) ? pathname.slice(base.length) : pathname;
|
|
117
|
+
}
|
|
118
|
+
export {
|
|
119
|
+
analyticsEndpoint,
|
|
120
|
+
startAnalytics,
|
|
121
|
+
startPreviewBridge
|
|
122
|
+
};
|