@seamlet/astro 0.11.3 → 0.12.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,14 @@
1
+ // src/site-addresses.ts
2
+ var SITE_MODULE_FILE = "src/seamlet.ts";
3
+ var PREVIEW_PATH = "/preview";
4
+ var UPLOADS_PATH = "/media";
5
+ function uploadedPhotoPath(siteId, fileName) {
6
+ return `${UPLOADS_PATH}/${siteId}/${fileName}`;
7
+ }
8
+
9
+ export {
10
+ SITE_MODULE_FILE,
11
+ PREVIEW_PATH,
12
+ UPLOADS_PATH,
13
+ uploadedPhotoPath
14
+ };
@@ -4,6 +4,13 @@ var BAD_REQUEST = 400;
4
4
  var PAYLOAD_TOO_LARGE = 413;
5
5
  var UNSUPPORTED_MEDIA_TYPE = 415;
6
6
  var UPLOADED_PHOTO = /^[A-Za-z0-9_-]+\.webp$/u;
7
+ function previewHeadersOf(cmsOrigin) {
8
+ return {
9
+ "Content-Security-Policy": `frame-ancestors ${cmsOrigin}`,
10
+ "X-Robots-Tag": "noindex",
11
+ "Cache-Control": "no-store"
12
+ };
13
+ }
7
14
  async function readDraft(request) {
8
15
  const isJson = request.headers.get("Content-Type")?.startsWith("application/json") === true;
9
16
  if (!isJson) return refused(UNSUPPORTED_MEDIA_TYPE);
@@ -50,6 +57,7 @@ function refused(status) {
50
57
 
51
58
  export {
52
59
  MAX_DRAFT_BYTES,
60
+ previewHeadersOf,
53
61
  readDraft,
54
62
  isUploadedPhoto
55
63
  };
@@ -1,9 +1,12 @@
1
1
  import {
2
2
  formatFieldPath,
3
+ isJsonObject,
4
+ linesOf,
3
5
  normalizedLine,
4
6
  readRichText,
5
- resolveFieldPath
6
- } from "./chunk-DRDPKFHZ.js";
7
+ resolveFieldPath,
8
+ safeHref
9
+ } from "./chunk-ZS32CW5F.js";
7
10
 
8
11
  // src/bridge/editor-shortcuts.ts
9
12
  function shortcutOf(event) {
@@ -32,28 +35,20 @@ function imageFieldAt(schema, path) {
32
35
 
33
36
  // src/bridge/messages.ts
34
37
  var PROTOCOL_VERSION = 2;
35
- var EDITOR_KEYS = /* @__PURE__ */ new Set([
36
- "save",
37
- "undo",
38
- "redo",
39
- "escape"
40
- ]);
41
- var TEXT_FORMATS = /* @__PURE__ */ new Set([
42
- "bold",
43
- "italic",
44
- "list"
45
- ]);
46
- var TYPING_OUTCOMES = /* @__PURE__ */ new Set([
47
- "kept",
48
- "reverted"
49
- ]);
50
- function readPageMessage(data) {
51
- if (!isRecord(data)) return void 0;
52
- return isPageMessage(data) ? data : void 0;
53
- }
54
- function readEditorMessage(data) {
55
- if (!isRecord(data)) return void 0;
56
- return isEditorMessage(data) ? data : void 0;
38
+ var SHORTCUTS = ["save", "undo", "redo"];
39
+ var EDITOR_KEY_NAMES = [...SHORTCUTS, "escape"];
40
+ var TEXT_FORMAT_NAMES = ["bold", "italic", "list"];
41
+ var TYPING_OUTCOME_NAMES = ["kept", "reverted"];
42
+ var EDITOR_KEYS = new Set(EDITOR_KEY_NAMES);
43
+ var TEXT_FORMATS = new Set(TEXT_FORMAT_NAMES);
44
+ var TYPING_OUTCOMES = new Set(TYPING_OUTCOME_NAMES);
45
+ function readPageMessage(posted) {
46
+ if (!isJsonObject(posted)) return void 0;
47
+ return isPageMessage(posted) ? posted : void 0;
48
+ }
49
+ function readEditorMessage(posted) {
50
+ if (!isJsonObject(posted)) return void 0;
51
+ return isEditorMessage(posted) ? posted : void 0;
57
52
  }
58
53
  function isPageMessage(message) {
59
54
  switch (message["type"]) {
@@ -94,9 +89,9 @@ function isPageMessage(message) {
94
89
  function isEditorMessage(message) {
95
90
  switch (message["type"]) {
96
91
  case "connect":
97
- return isRecord(message["schema"]);
92
+ return isJsonObject(message["schema"]);
98
93
  case "render":
99
- return isRecord(message["content"]);
94
+ return isJsonObject(message["content"]);
100
95
  case "start-typing":
101
96
  return isString(message["path"]) && isString(message["text"]) && typeof message["isSingleLine"] === "boolean" && isPoint(message["point"]);
102
97
  case "start-rich-typing":
@@ -114,36 +109,36 @@ function isEditorMessage(message) {
114
109
  }
115
110
  }
116
111
  function isLayout(value) {
117
- if (!isRecord(value)) return false;
112
+ if (!isJsonObject(value)) return false;
118
113
  const markers = value["markers"];
119
114
  return Array.isArray(markers) && markers.every(isMarkerBox) && isViewport(value["viewport"]) && isOptional(value["link"], isLinkBox);
120
115
  }
121
116
  function isMarkerBox(value) {
122
- return isRecord(value) && isString(value["path"]) && isBox(value["box"]);
117
+ return isJsonObject(value) && isString(value["path"]) && isBox(value["box"]);
123
118
  }
124
119
  function isLinkBox(value) {
125
- return isRecord(value) && isString(value["href"]) && isBox(value["box"]);
120
+ return isJsonObject(value) && isString(value["href"]) && isBox(value["box"]);
126
121
  }
127
122
  function isClickTarget(value) {
128
- return isRecord(value) && isString(value["path"]) && isPoint(value["point"]);
123
+ return isJsonObject(value) && isString(value["path"]) && isPoint(value["point"]);
129
124
  }
130
125
  function isRichText(value) {
131
126
  return readRichText(value) !== void 0;
132
127
  }
133
128
  function isTypedSelection(value) {
134
- return isRecord(value) && isBox(value["box"]) && typeof value["isCollapsed"] === "boolean" && isTextFormats(value["formats"]);
129
+ return isJsonObject(value) && isBox(value["box"]) && typeof value["isCollapsed"] === "boolean" && isTextFormats(value["formats"]);
135
130
  }
136
131
  function isTextFormats(value) {
137
- return isRecord(value) && typeof value["isBold"] === "boolean" && typeof value["isItalic"] === "boolean" && typeof value["isList"] === "boolean" && isOptional(value["href"], isString);
132
+ return isJsonObject(value) && typeof value["isBold"] === "boolean" && typeof value["isItalic"] === "boolean" && typeof value["isList"] === "boolean" && isOptional(value["href"], isString);
138
133
  }
139
134
  function isBox(value) {
140
- return isRecord(value) && isNumber(value["top"]) && isNumber(value["left"]) && isNumber(value["width"]) && isNumber(value["height"]);
135
+ return isJsonObject(value) && isNumber(value["top"]) && isNumber(value["left"]) && isNumber(value["width"]) && isNumber(value["height"]);
141
136
  }
142
137
  function isViewport(value) {
143
- return isRecord(value) && isNumber(value["width"]) && isNumber(value["height"]);
138
+ return isJsonObject(value) && isNumber(value["width"]) && isNumber(value["height"]);
144
139
  }
145
140
  function isPoint(value) {
146
- return isRecord(value) && isNumber(value["x"]) && isNumber(value["y"]);
141
+ return isJsonObject(value) && isNumber(value["x"]) && isNumber(value["y"]);
147
142
  }
148
143
  function isFieldPath(value) {
149
144
  return Array.isArray(value) && value.every((segment) => isString(segment) || isNumber(segment));
@@ -151,9 +146,6 @@ function isFieldPath(value) {
151
146
  function isOptional(value, isPresent) {
152
147
  return value === void 0 || isPresent(value);
153
148
  }
154
- function isRecord(value) {
155
- return typeof value === "object" && value !== null && !Array.isArray(value);
156
- }
157
149
  function isString(value) {
158
150
  return typeof value === "string";
159
151
  }
@@ -377,9 +369,7 @@ function renderRichText(element, text) {
377
369
  }
378
370
  function renderInlineRichText(element, text) {
379
371
  const document = element.ownerDocument;
380
- const lines = text.flatMap(
381
- (block) => block.kind === "paragraph" ? [block.spans] : block.items
382
- );
372
+ const lines = linesOf(text);
383
373
  const nodes = lines.flatMap((line, index) => [
384
374
  ...index > 0 ? [document.createElement("br")] : [],
385
375
  ...lineNodes(document, line)
@@ -461,9 +451,10 @@ function spanNode(document, span) {
461
451
  const words = wordsNode(document, span.text);
462
452
  const italic = span.italic === true ? wrapped(document, "em", words) : words;
463
453
  const bold = span.bold === true ? wrapped(document, "strong", italic) : italic;
464
- if (span.href === void 0) return bold;
454
+ const href = span.href === void 0 ? void 0 : safeHref(span.href);
455
+ if (href === void 0) return bold;
465
456
  const link = wrapped(document, "a", bold);
466
- link.setAttribute("href", span.href);
457
+ link.setAttribute("href", href);
467
458
  return link;
468
459
  }
469
460
  function wordsNode(document, text) {
@@ -1,10 +1,14 @@
1
+ import {
2
+ UPLOADS_PATH
3
+ } from "./chunk-QCVWHHJC.js";
4
+
1
5
  // src/own-photos.ts
2
6
  var OWN_PHOTOS_PATH = "/seamlet-photos";
3
- var UPLOADS_PATH = "/media/";
7
+ var UPLOADS_FOLDER = `${UPLOADS_PATH}/`;
4
8
  var PARENT_SEGMENT = "..";
5
9
  function isOwnPhotoSrc(src) {
6
10
  const isOnSite = src.startsWith("/") && !src.startsWith("//");
7
- const isUpload = src.startsWith(UPLOADS_PATH);
11
+ const isUpload = src.startsWith(UPLOADS_FOLDER);
8
12
  const isPlainPath = !/[?#\\]/u.test(src);
9
13
  const climbsUp = src.split("/").includes(PARENT_SEGMENT);
10
14
  return isOnSite && !isUpload && isPlainPath && !climbsUp;