@craftware/crafty-sdk 0.8.0 → 0.9.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/README.md CHANGED
@@ -6,7 +6,9 @@ Official JavaScript SDK for the Crafty public API (current local implementation)
6
6
 
7
7
  This package ships an agent **skill** that teaches Claude, Cursor, and other agents how to configure a Crafty site through its MCP server and build against it with this SDK. It is included in the published package under `skills/crafty-cms/`.
8
8
 
9
- To activate it, copy it into your project's skills directory after installing the SDK:
9
+ The quickest way to install it, together with the CLI's `crafty-deploy` skill, is `npx @craftware/crafty-cli skills install` (into `.claude/skills/`; `--global` for `~/.claude/skills/`, `--dir=<path>` for other agents). The skills are also downloadable as zips for Claude.ai and Claude Desktop at https://docs.crafty.do/skills/crafty-cms.zip.
10
+
11
+ Or copy it into your project's skills directory after installing the SDK:
10
12
 
11
13
  ```bash
12
14
  cp -r node_modules/@craftware/crafty-sdk/skills/crafty-cms .claude/skills/
@@ -232,6 +234,24 @@ await crafty.analytics.load(); // "loaded" | "already-loaded" | "not-configured"
232
234
 
233
235
  Client-side loading misses crawlers that don't run JavaScript. Changes made in the admin show up on the next request with `get()`/`load()`; on Crafty Hosting they need a redeploy.
234
236
 
237
+ ## Structured data (JSON-LD)
238
+
239
+ Crafty turns content into schema.org JSON-LD so Google can show rich results (hours, address, prices, FAQ) and AI search engines get reliable facts. Don't write JSON-LD by hand:
240
+
241
+ - The business behind the site (type, address, hours, phone, social profiles) is set on the "Datos estructurados" admin screen or with the `configure_structured_data` MCP tool. The home page (`pages.get("home")`) and `crafty.site.get()` carry it in `structured_data`.
242
+ - A collection can be mapped to `Product`, `Article`, `BlogPosting`, `FAQPage`, `Event` or `Service` (collection editor or `structured_data` on `update_collection`). Each published entry then carries its JSON-LD in `structured_data`.
243
+
244
+ `crafty.structuredData(...sources)` returns the `<script type="application/ld+json">` tags for any mix of pages, entries, list responses, the site or JSON-LD objects (`""` when none has any). FAQPage objects are merged into one, as Google expects a single FAQPage per page:
245
+
246
+ ```ts
247
+ const page = await crafty.pages.get("home");
248
+ const faqs = await crafty.entries.list("faq");
249
+
250
+ head += crafty.structuredData(page, faqs); // LocalBusiness + one FAQPage with every question
251
+ ```
252
+
253
+ For questions that live in a page block, `crafty.faqPage(block.data.items)` builds the FAQPage from `{ question, answer }` items. `crafty.jsonLd(...sources)` returns the objects instead of HTML, for `useHead` / `<Head>` components.
254
+
235
255
  ## Request options (per call)
236
256
 
237
257
  Every method accepts `options?` as the last argument:
package/dist/client.d.ts CHANGED
@@ -10,6 +10,8 @@ import { LlmsResource } from "./resources/llms.js";
10
10
  import { MediaCollectionsResource } from "./resources/mediaCollections.js";
11
11
  import { MediaFilesResource } from "./resources/mediaFiles.js";
12
12
  import { PagesResource } from "./resources/pages.js";
13
+ import { SiteResource } from "./resources/site.js";
14
+ import { faqPage, jsonLd, structuredData } from "./structured-data.js";
13
15
  import type { CraftyClientConfig } from "./types/public.js";
14
16
  export type CraftyClient = {
15
17
  analytics: AnalyticsResource;
@@ -21,11 +23,15 @@ export type CraftyClient = {
21
23
  mediaCollections: MediaCollectionsResource;
22
24
  mediaFiles: MediaFilesResource;
23
25
  pages: PagesResource;
26
+ site: SiteResource;
24
27
  attrs: typeof attrs;
25
28
  attrsHtml: typeof attrsHtml;
26
29
  image: typeof imageUrl;
27
30
  srcset: typeof imageSrcSet;
28
31
  previewFromRequest: typeof previewFromRequest;
32
+ structuredData: typeof structuredData;
33
+ jsonLd: typeof jsonLd;
34
+ faqPage: typeof faqPage;
29
35
  };
30
36
  export declare function createCraftyClient(config: CraftyClientConfig): CraftyClient;
31
37
  //# sourceMappingURL=client.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AAE9C,OAAO,EAAE,WAAW,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC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,SAAS,EAAE,OAAO,SAAS,CAAC;IAC5B,KAAK,EAAE,OAAO,QAAQ,CAAC;IACvB,MAAM,EAAE,OAAO,WAAW,CAAC;IAC3B,kBAAkB,EAAE,OAAO,kBAAkB,CAAC;IAC9C,cAAc,EAAE,OAAO,cAAc,CAAC;IACtC,MAAM,EAAE,OAAO,MAAM,CAAC;IACtB,OAAO,EAAE,OAAO,OAAO,CAAC;CACzB,CAAC;AAEF,wBAAgB,kBAAkB,CAAC,MAAM,EAAE,kBAAkB,GAAG,YAAY,CAuB3E"}
package/dist/client.js CHANGED
@@ -11,6 +11,8 @@ import { LlmsResource } from "./resources/llms.js";
11
11
  import { MediaCollectionsResource } from "./resources/mediaCollections.js";
12
12
  import { MediaFilesResource } from "./resources/mediaFiles.js";
13
13
  import { PagesResource } from "./resources/pages.js";
14
+ import { SiteResource } from "./resources/site.js";
15
+ import { faqPage, jsonLd, structuredData } from "./structured-data.js";
14
16
  export function createCraftyClient(config) {
15
17
  const http = HttpClient.fromClientConfig(config);
16
18
  return {
@@ -23,11 +25,15 @@ export function createCraftyClient(config) {
23
25
  mediaCollections: new MediaCollectionsResource(http),
24
26
  mediaFiles: new MediaFilesResource(http),
25
27
  pages: new PagesResource(http),
28
+ site: new SiteResource(http),
26
29
  attrs,
27
30
  attrsHtml,
28
31
  image: imageUrl,
29
32
  srcset: imageSrcSet,
30
- previewFromRequest
33
+ previewFromRequest,
34
+ structuredData,
35
+ jsonLd,
36
+ faqPage
31
37
  };
32
38
  }
33
39
  //# sourceMappingURL=client.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"client.js","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AAC9C,OAAO,EAAE,UAAU,EAAE,MAAM,WAAW,CAAC;AACvC,OAAO,EAAE,WAAW,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AACnD,OAAO,EAAE,kBAAkB,EAA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AAC,IAAI,CAAC;QAC5B,gBAAgB,EAAE,IAAI,wBAAwB,CAAC,IAAI,CAAC;QACpD,UAAU,EAAE,IAAI,kBAAkB,CAAC,IAAI,CAAC;QACxC,KAAK,EAAE,IAAI,aAAa,CAAC,IAAI,CAAC;QAC9B,IAAI,EAAE,IAAI,YAAY,CAAC,IAAI,CAAC;QAC5B,KAAK;QACL,SAAS;QACT,KAAK,EAAE,QAAQ;QACf,MAAM,EAAE,WAAW;QACnB,kBAAkB;QAClB,cAAc;QACd,MAAM;QACN,OAAO;KACR,CAAC;AACJ,CAAC"}
@@ -1,4 +1,4 @@
1
- "use strict";var CraftyVisualEditing=(()=>{var I=Object.defineProperty;var Ie=Object.getOwnPropertyDescriptor;var Fe=Object.getOwnPropertyNames;var He=Object.prototype.hasOwnProperty;var We=(e,t)=>{for(var n in t)I(e,n,{get:t[n],enumerable:!0})},Ke=(e,t,n,r)=>{if(t&&typeof t=="object"||typeof t=="function")for(let i of Fe(t))!He.call(e,i)&&i!==n&&I(e,i,{get:()=>t[i],enumerable:!(r=Ie(t,i))||r.enumerable});return e};var $e=e=>Ke(I({},"__esModule",{value:!0}),e);var dt={};We(dt,{PROTOCOL_VERSION:()=>k,attrs:()=>F,attrsHtml:()=>le,enableVisualEditing:()=>Le});function De(e){if(e==null||typeof e!="object")return null;let t=e,n=typeof t.id=="string"?Number(t.id.trim()):t.id;return typeof n!="number"||!Number.isInteger(n)||n<=0?null:t.kind==="block"||t.kind==="entry"?{type:t.kind,id:n}:{type:typeof t.order=="number"&&typeof t.data=="object"&&t.data!==null&&"type"in t?"block":"entry",id:n}}function F(e,t,n={}){let r=De(e),i=typeof t=="string"?t.trim():"";if(r===null||i==="")return{};let l=r.type==="block"?{"data-crafty-block":String(r.id),"data-crafty-field":i}:{"data-crafty-entry":String(r.id),"data-crafty-field":i},a=typeof n.label=="string"?n.label.trim():"";a!==""&&(l["data-crafty-label"]=a);let s=typeof n.hrefField=="string"?n.hrefField.trim():"";if(s!==""){l["data-crafty-href-field"]=s;let d=typeof n.hrefLabel=="string"?n.hrefLabel.trim():"";d!==""&&(l["data-crafty-href-label"]=d)}return l}function le(e,t,n={}){return Object.entries(F(e,t,n)).map(([r,i])=>`${r}="${Ue(String(i))}"`).join(" ")}function Ue(e){return e.replace(/&/g,"&amp;").replace(/"/g,"&quot;").replace(/</g,"&lt;").replace(/>/g,"&gt;")}var $="crafty_preview";var T="crafty:preview-invalid",D="crafty:preview-content",U="crafty:preview-active",W="crafty:preview-token",ae="crafty:preview-url-token",Ge="crafty:preview-invalid-token",Ye="__CRAFTY_PREVIEW_CONTENT__",ze="__CRAFTY_PREVIEW_STATUS__";function A(){return typeof window=="undefined"?null:window}function H(e){var t,n;try{return(n=(t=A())==null?void 0:t.sessionStorage.getItem(e))!=null?n:null}catch{return null}}function K(e,t){var n;try{(n=A())==null||n.sessionStorage.setItem(e,t)}catch{}}function G(e){return typeof e=="string"&&e.trim()!==""?e.trim():null}function Be(e){try{return G(new URL(e,"http://localhost").searchParams.get($))}catch{return null}}function se(){var r;let e=A();if(e===null)return null;let t=Be(e.location.href),n;return t!==null&&t!==H(ae)?(K(ae,t),K(W,t),n=t):n=(r=G(H(W)))!=null?r:t,n!==null&&n===H(Ge)?null:n}function de(e){let t=G(e);t!==null&&K(W,t)}function ce(){let e=A(),t=e==null?void 0:e[Ye];return t?{page:t.page,entries:[...t.entries]}:{page:null,entries:[]}}function ue(){let e=A(),t=e==null?void 0:e[ze];return t==="active"||t==="invalid"?t:null}var fe="0.8.0";var k=1;var Xe=/^[A-Za-z0-9_-]+(?:\.[A-Za-z0-9_-]+|\[\d+\])*$/,je=/^[\x21-\x7E]+$/;function S(e){return typeof e=="object"&&e!==null&&!Array.isArray(e)}function qe(e){return typeof e=="number"&&Number.isInteger(e)&&e>0}function pe(e){if(typeof e!="string")return null;let t=e.trim();return t===""||t.length>255||!Xe.test(t)?null:t}function ye(e){return typeof e=="string"?e.trim().slice(0,120).trim():""}function x(e){if(!S(e))return null;let{type:t,id:n}=e,r=pe(e.field);return t!=="block"&&t!=="entry"||!qe(n)||r===null?null:{type:t,id:n,field:r}}function ge(e){let t=x(e);if(t===null||!S(e))return null;let n={...t},r=ye(e.label),i=pe(e.hrefField);if(r!==""&&(n.label=r),i!==null){n.hrefField=i;let l=ye(e.hrefLabel);l!==""&&(n.hrefLabel=l)}return n}function Qe(e){if(!S(e)||e.v!==1||typeof e.type!="string")return null;let t=e.payload===void 0?{}:e.payload;return S(t)?{type:e.type,payload:t}:null}function Ee(e){let t=Qe(e);if(t===null)return null;let{payload:n}=t;switch(t.type){case"crafty:token":{let r=typeof n.token=="string"?n.token.trim():"";return r!==""&&r.length<=4096&&je.test(r)?{v:1,type:"crafty:token",payload:{token:r}}:null}case"crafty:refresh":return{v:1,type:"crafty:refresh",payload:{}};case"crafty:highlight":{let r=x(n);return r?{v:1,type:"crafty:highlight",payload:r}:null}case"crafty:preview-field":{let r=x(n),i=n.value;return r&&typeof i=="string"&&i.length<=1e5?{v:1,type:"crafty:preview-field",payload:{...r,value:i}}:null}case"crafty:preview-reset":{let r=x(n);return r?{v:1,type:"crafty:preview-reset",payload:r}:null}default:return null}}var R="[data-crafty-field]";function L(e){var i;let t=e.getAttribute("data-crafty-block"),n=e.getAttribute("data-crafty-entry"),r=t!=null?t:n;return r===null?null:ge({type:t!==null?"block":"entry",id:r.trim()===""?Number.NaN:Number(r),field:(i=e.getAttribute("data-crafty-field"))!=null?i:"",label:e.getAttribute("data-crafty-label"),hrefField:e.getAttribute("data-crafty-href-field"),hrefLabel:e.getAttribute("data-crafty-href-label")})}function E(e){return`${e.type}:${e.id}:${e.field}`}function _(e){let t=[];return e.querySelectorAll(R).forEach(n=>{let r=L(n);r!==null&&t.push({element:n,field:r})}),t}function Y(e){let t=new Set,n=[];for(let{field:r}of e){let i=E(r);t.has(i)||(t.add(i),n.push(r))}return n}function ve(e){let t=new Map,n=new Map,r=a=>Array.from(e.querySelectorAll(R)).filter(s=>{let d=L(s);return d!==null&&E(d)===a}),i=(a,s)=>{var d;n.has(a)||n.set(a,(d=a.textContent)!=null?d:""),a.textContent!==s&&(a.textContent=s)},l=a=>{for(let[s,d]of n){let y=L(s);(a===null||y!==null&&E(y)===a)&&(s.textContent!==d&&(s.textContent=d),n.delete(s))}};return{set(a,s){let d=E(a);t.set(d,s),r(d).forEach(y=>i(y,s))},reset(a){let s=E(a);t.delete(s),l(s)},reapply(){for(let a of[...n.keys()])a.isConnected||n.delete(a);for(let[a,s]of t)r(a).forEach(d=>i(d,s))},resetAll(){t.clear(),l(null)},get size(){return t.size}}}var he=[/^https:\/\/([a-z0-9-]+\.)*crafty\.do$/];function me(e){try{return new URL(e).origin}catch{return null}}function ke(e,t){return e===""||e==="null"?!1:t.some(n=>typeof n=="string"?me(n)===e:(n.lastIndex=0,n.test(e)))}function be(e){let t=e.location.ancestorOrigins,n=t&&t.length>0?t[0]:void 0;if(typeof n=="string"&&n!=="")return n;let r=e.document.referrer;return r?me(r):null}var Ze="crafty-visual-editing-style",z="#4f46e5",B="crafty-ve-flash",Je=["[data-crafty-field]{cursor:pointer}",`.crafty-ve-box{position:fixed;top:0;left:0;pointer-events:none;z-index:2147483647;box-sizing:border-box;border:2px solid ${z};border-radius:4px;background:rgba(79,70,229,.06)}`,".crafty-ve-box[hidden]{display:none}",`.crafty-ve-label{position:absolute;left:-2px;bottom:100%;margin-bottom:4px;padding:2px 8px;max-width:320px;overflow:hidden;text-overflow:ellipsis;white-space:nowrap;border-radius:4px;background:${z};color:#fff;font:500 12px/1.5 system-ui,-apple-system,sans-serif}`,`.${B}{outline:2px dashed ${z} !important;outline-offset:2px !important}`].join(`
1
+ "use strict";var CraftyVisualEditing=(()=>{var I=Object.defineProperty;var Ie=Object.getOwnPropertyDescriptor;var Fe=Object.getOwnPropertyNames;var He=Object.prototype.hasOwnProperty;var We=(e,t)=>{for(var n in t)I(e,n,{get:t[n],enumerable:!0})},Ke=(e,t,n,r)=>{if(t&&typeof t=="object"||typeof t=="function")for(let i of Fe(t))!He.call(e,i)&&i!==n&&I(e,i,{get:()=>t[i],enumerable:!(r=Ie(t,i))||r.enumerable});return e};var $e=e=>Ke(I({},"__esModule",{value:!0}),e);var dt={};We(dt,{PROTOCOL_VERSION:()=>k,attrs:()=>F,attrsHtml:()=>le,enableVisualEditing:()=>Le});function De(e){if(e==null||typeof e!="object")return null;let t=e,n=typeof t.id=="string"?Number(t.id.trim()):t.id;return typeof n!="number"||!Number.isInteger(n)||n<=0?null:t.kind==="block"||t.kind==="entry"?{type:t.kind,id:n}:{type:typeof t.order=="number"&&typeof t.data=="object"&&t.data!==null&&"type"in t?"block":"entry",id:n}}function F(e,t,n={}){let r=De(e),i=typeof t=="string"?t.trim():"";if(r===null||i==="")return{};let l=r.type==="block"?{"data-crafty-block":String(r.id),"data-crafty-field":i}:{"data-crafty-entry":String(r.id),"data-crafty-field":i},a=typeof n.label=="string"?n.label.trim():"";a!==""&&(l["data-crafty-label"]=a);let s=typeof n.hrefField=="string"?n.hrefField.trim():"";if(s!==""){l["data-crafty-href-field"]=s;let d=typeof n.hrefLabel=="string"?n.hrefLabel.trim():"";d!==""&&(l["data-crafty-href-label"]=d)}return l}function le(e,t,n={}){return Object.entries(F(e,t,n)).map(([r,i])=>`${r}="${Ue(String(i))}"`).join(" ")}function Ue(e){return e.replace(/&/g,"&amp;").replace(/"/g,"&quot;").replace(/</g,"&lt;").replace(/>/g,"&gt;")}var $="crafty_preview";var T="crafty:preview-invalid",D="crafty:preview-content",U="crafty:preview-active",W="crafty:preview-token",ae="crafty:preview-url-token",Ge="crafty:preview-invalid-token",Ye="__CRAFTY_PREVIEW_CONTENT__",ze="__CRAFTY_PREVIEW_STATUS__";function A(){return typeof window=="undefined"?null:window}function H(e){var t,n;try{return(n=(t=A())==null?void 0:t.sessionStorage.getItem(e))!=null?n:null}catch{return null}}function K(e,t){var n;try{(n=A())==null||n.sessionStorage.setItem(e,t)}catch{}}function G(e){return typeof e=="string"&&e.trim()!==""?e.trim():null}function Be(e){try{return G(new URL(e,"http://localhost").searchParams.get($))}catch{return null}}function se(){var r;let e=A();if(e===null)return null;let t=Be(e.location.href),n;return t!==null&&t!==H(ae)?(K(ae,t),K(W,t),n=t):n=(r=G(H(W)))!=null?r:t,n!==null&&n===H(Ge)?null:n}function de(e){let t=G(e);t!==null&&K(W,t)}function ce(){let e=A(),t=e==null?void 0:e[Ye];return t?{page:t.page,entries:[...t.entries]}:{page:null,entries:[]}}function ue(){let e=A(),t=e==null?void 0:e[ze];return t==="active"||t==="invalid"?t:null}var fe="0.9.0";var k=1;var Xe=/^[A-Za-z0-9_-]+(?:\.[A-Za-z0-9_-]+|\[\d+\])*$/,je=/^[\x21-\x7E]+$/;function S(e){return typeof e=="object"&&e!==null&&!Array.isArray(e)}function qe(e){return typeof e=="number"&&Number.isInteger(e)&&e>0}function pe(e){if(typeof e!="string")return null;let t=e.trim();return t===""||t.length>255||!Xe.test(t)?null:t}function ye(e){return typeof e=="string"?e.trim().slice(0,120).trim():""}function x(e){if(!S(e))return null;let{type:t,id:n}=e,r=pe(e.field);return t!=="block"&&t!=="entry"||!qe(n)||r===null?null:{type:t,id:n,field:r}}function ge(e){let t=x(e);if(t===null||!S(e))return null;let n={...t},r=ye(e.label),i=pe(e.hrefField);if(r!==""&&(n.label=r),i!==null){n.hrefField=i;let l=ye(e.hrefLabel);l!==""&&(n.hrefLabel=l)}return n}function Qe(e){if(!S(e)||e.v!==1||typeof e.type!="string")return null;let t=e.payload===void 0?{}:e.payload;return S(t)?{type:e.type,payload:t}:null}function Ee(e){let t=Qe(e);if(t===null)return null;let{payload:n}=t;switch(t.type){case"crafty:token":{let r=typeof n.token=="string"?n.token.trim():"";return r!==""&&r.length<=4096&&je.test(r)?{v:1,type:"crafty:token",payload:{token:r}}:null}case"crafty:refresh":return{v:1,type:"crafty:refresh",payload:{}};case"crafty:highlight":{let r=x(n);return r?{v:1,type:"crafty:highlight",payload:r}:null}case"crafty:preview-field":{let r=x(n),i=n.value;return r&&typeof i=="string"&&i.length<=1e5?{v:1,type:"crafty:preview-field",payload:{...r,value:i}}:null}case"crafty:preview-reset":{let r=x(n);return r?{v:1,type:"crafty:preview-reset",payload:r}:null}default:return null}}var R="[data-crafty-field]";function L(e){var i;let t=e.getAttribute("data-crafty-block"),n=e.getAttribute("data-crafty-entry"),r=t!=null?t:n;return r===null?null:ge({type:t!==null?"block":"entry",id:r.trim()===""?Number.NaN:Number(r),field:(i=e.getAttribute("data-crafty-field"))!=null?i:"",label:e.getAttribute("data-crafty-label"),hrefField:e.getAttribute("data-crafty-href-field"),hrefLabel:e.getAttribute("data-crafty-href-label")})}function E(e){return`${e.type}:${e.id}:${e.field}`}function _(e){let t=[];return e.querySelectorAll(R).forEach(n=>{let r=L(n);r!==null&&t.push({element:n,field:r})}),t}function Y(e){let t=new Set,n=[];for(let{field:r}of e){let i=E(r);t.has(i)||(t.add(i),n.push(r))}return n}function ve(e){let t=new Map,n=new Map,r=a=>Array.from(e.querySelectorAll(R)).filter(s=>{let d=L(s);return d!==null&&E(d)===a}),i=(a,s)=>{var d;n.has(a)||n.set(a,(d=a.textContent)!=null?d:""),a.textContent!==s&&(a.textContent=s)},l=a=>{for(let[s,d]of n){let y=L(s);(a===null||y!==null&&E(y)===a)&&(s.textContent!==d&&(s.textContent=d),n.delete(s))}};return{set(a,s){let d=E(a);t.set(d,s),r(d).forEach(y=>i(y,s))},reset(a){let s=E(a);t.delete(s),l(s)},reapply(){for(let a of[...n.keys()])a.isConnected||n.delete(a);for(let[a,s]of t)r(a).forEach(d=>i(d,s))},resetAll(){t.clear(),l(null)},get size(){return t.size}}}var he=[/^https:\/\/([a-z0-9-]+\.)*crafty\.do$/];function me(e){try{return new URL(e).origin}catch{return null}}function ke(e,t){return e===""||e==="null"?!1:t.some(n=>typeof n=="string"?me(n)===e:(n.lastIndex=0,n.test(e)))}function be(e){let t=e.location.ancestorOrigins,n=t&&t.length>0?t[0]:void 0;if(typeof n=="string"&&n!=="")return n;let r=e.document.referrer;return r?me(r):null}var Ze="crafty-visual-editing-style",z="#4f46e5",B="crafty-ve-flash",Je=["[data-crafty-field]{cursor:pointer}",`.crafty-ve-box{position:fixed;top:0;left:0;pointer-events:none;z-index:2147483647;box-sizing:border-box;border:2px solid ${z};border-radius:4px;background:rgba(79,70,229,.06)}`,".crafty-ve-box[hidden]{display:none}",`.crafty-ve-label{position:absolute;left:-2px;bottom:100%;margin-bottom:4px;padding:2px 8px;max-width:320px;overflow:hidden;text-overflow:ellipsis;white-space:nowrap;border-radius:4px;background:${z};color:#fff;font:500 12px/1.5 system-ui,-apple-system,sans-serif}`,`.${B}{outline:2px dashed ${z} !important;outline-offset:2px !important}`].join(`
2
2
  `);function Ce(e){let t=e.defaultView,n=e.createElement("style");n.id=Ze,n.textContent=Je;let r=e.createElement("div");r.setAttribute("data-crafty-overlay",""),r.className="crafty-ve-box",r.hidden=!0;let i=e.createElement("span");i.className="crafty-ve-label",r.appendChild(i);let l=null,a=[],s,d=t==null?void 0:t.ResizeObserver,y=()=>{if(l===null)return;let c=l.getBoundingClientRect();r.style.top=`${c.top}px`,r.style.left=`${c.left}px`,r.style.width=`${c.width}px`,r.style.height=`${c.height}px`},f=typeof d=="function"?new d(()=>y()):null,v=c=>{l!==c&&(l!==null&&(f==null||f.unobserve(l)),l=c,l!==null&&(f==null||f.observe(l)))},g=()=>{a.forEach(c=>c.classList.remove(B)),a=[],s!==void 0&&(t==null||t.clearTimeout(s),s=void 0)},h=()=>{var c,m;n.isConnected||((c=e.head)!=null?c:e.documentElement).appendChild(n),r.isConnected||((m=e.body)!=null?m:e.documentElement).appendChild(r)};return h(),t==null||t.addEventListener("scroll",y,{capture:!0,passive:!0}),t==null||t.addEventListener("resize",y,{passive:!0}),{show(c,m){h(),v(c),i.textContent!==m&&(i.textContent=m),r.hidden=!1,y()},hide(){v(null),r.hidden=!0},reposition(){y()},flash(c,m){g(),a=[...c],a.forEach(w=>w.classList.add(B)),s=t==null?void 0:t.setTimeout(g,m)},ensureAttached:h,contains(c){return c!==null&&(r===c||r.contains(c)||n===c||n.contains(c))},destroy(){g(),t==null||t.removeEventListener("scroll",y,{capture:!0}),t==null||t.removeEventListener("resize",y),f==null||f.disconnect(),r.remove(),n.remove(),l=null}}}var j="crafty:scroll-y",et=50,tt=1500,nt=["data-crafty-field","data-crafty-block","data-crafty-entry","data-crafty-label","data-crafty-href-field","data-crafty-href-label"],N={active:!1,disable:()=>{}},b=null;function Le(e={}){var i;if(typeof window=="undefined"||typeof document=="undefined")return N;if(b!==null)return b;let t=window;if(t.parent===null||t.parent===t||se()===null)return N;let n=be(t);if(n===null||!ke(n,(i=e.adminOrigins)!=null?i:he))return N;let r=ue();return r==="invalid"?(we(t,n),N):(b=r==="active"?Oe(t,n,e):rt(t,n,e),b)}function we(e,t){let n={v:1,type:"crafty:preview-invalid",payload:{}};e.parent.postMessage(n,t)}function rt(e,t,n){var f;let r=null,i=!1,l=()=>{i=!0,e.removeEventListener(U,s),e.removeEventListener(T,d)},a=()=>{b===y&&(b=null)},s=()=>{i||(l(),r=Oe(e,t,n,a))},d=()=>{i||(l(),a(),we(e,t))},y={get active(){var v;return(v=r==null?void 0:r.active)!=null?v:!1},disable(){l(),r==null||r.disable(),a()}};return e.addEventListener(U,s),e.addEventListener(T,d),(f=n.client)==null||f.pages.list({per_page:1}).catch(()=>{}),y}function Oe(e,t,n,r){let i=e.document,l=Ce(i),a=ve(i),s=at(e),d=[],y=null,f,v=!1,g=!0,h=o=>{e.parent.postMessage(o,t)},c=()=>{var p,C,O;let o=Y(d),u=ce();y=Re(o),h({v:1,type:"crafty:ready",payload:{sdkVersion:fe,path:_e(e),fields:o,page:(C=(p=u.page)!=null?p:n.page)!=null?C:null,entries:it(u.entries,(O=n.entries)!=null?O:[])}})},m=()=>{f=void 0,g&&(l.ensureAttached(),d=_(i),a.reapply(),(v||Re(Y(d))!==y)&&(v=!1,c()))},w=()=>{g&&f===void 0&&(f=e.setTimeout(m,et))},q=new MutationObserver(o=>{o.some(u=>!l.contains(u.target))&&w()}),V=o=>{var u;return(u=o.label)!=null?u:o.field},Q=o=>{if(o.pointerType==="touch")return;let u=X(o.target);u!==null?l.show(u.element,V(u.field)):l.hide()},P=o=>{o.preventDefault(),o.stopPropagation()},Z=o=>{let u=X(o.target);if(u!==null){P(o),l.show(u.element,V(u.field)),h({v:1,type:"crafty:select",payload:u.field});return}let p=ot(o,e);p.kind!=="allow"&&(P(o),p.kind==="navigate"&&h({v:1,type:"crafty:navigate",payload:{path:p.path}}))},J=o=>{(X(o.target)!==null||xe(o.target)!==null)&&P(o)},ee=o=>{P(o)},te=o=>{o.key!=="Escape"||o.repeat||o.isComposing||o.defaultPrevented||h({v:1,type:"crafty:key",payload:{key:"Escape"}})},Se=o=>{var O;let u=E(o),p=_(i).find(Me=>E(Me.field)===u);if(p===void 0)return;let C=p.element;(O=C.scrollIntoView)==null||O.call(C,{block:"center",behavior:"smooth"}),l.show(p.element,V(p.field))},Ne=async()=>{if(n.onRefresh){try{await n.onRefresh()}finally{w()}return}try{e.sessionStorage.setItem(j,String(e.scrollY))}catch{}e.location.reload()},Ve=o=>{switch(o.type){case"crafty:token":de(o.payload.token);return;case"crafty:refresh":Ne().catch(u=>console.error("[crafty] onRefresh failed",u));return;case"crafty:highlight":Se(o.payload);return;case"crafty:preview-field":a.set(o.payload,o.payload.value),l.reposition();return;case"crafty:preview-reset":a.reset(o.payload),l.reposition();return}},ne=o=>{if(o.source!==e.parent||o.origin!==t)return;let u=Ee(o.data);u!==null&&Ve(u)},re=()=>{h({v:1,type:"crafty:preview-invalid",payload:{}})},ie=()=>{v=!0,w()},M=()=>{var o;g&&(d=_(i),c(),lt(e)&&l.flash(d.map(u=>u.element),(o=n.touchHighlightMs)!=null?o:tt),st(e,s))};e.addEventListener("message",ne),e.addEventListener("click",Z,!0),e.addEventListener("auxclick",J,!0),e.addEventListener("submit",ee,!0),e.addEventListener("keydown",te),i.addEventListener("pointerover",Q,!0),e.addEventListener(T,re),e.addEventListener(D,ie),q.observe(i.documentElement,{childList:!0,subtree:!0,attributes:!0,attributeFilter:nt}),i.readyState==="loading"?i.addEventListener("DOMContentLoaded",M,{once:!0}):M();let oe={get active(){return g},disable(){g&&(g=!1,e.removeEventListener("message",ne),e.removeEventListener("click",Z,!0),e.removeEventListener("auxclick",J,!0),e.removeEventListener("submit",ee,!0),e.removeEventListener("keydown",te),i.removeEventListener("pointerover",Q,!0),i.removeEventListener("DOMContentLoaded",M),e.removeEventListener(T,re),e.removeEventListener(D,ie),q.disconnect(),f!==void 0&&(e.clearTimeout(f),f=void 0),a.resetAll(),l.destroy(),b===oe&&(b=null),r==null||r())}};return oe}function Te(e){return e!==null&&typeof e.closest=="function"?e:null}function Re(e){return e.map(t=>{var n,r,i;return`${E(t)}|${(n=t.label)!=null?n:""}|${(r=t.hrefField)!=null?r:""}|${(i=t.hrefLabel)!=null?i:""}`}).join(`
3
3
  `)}function it(e,t){let n=new Set;return[...e,...t].filter(r=>{let i=`${r.collection}:${r.id}`;return n.has(i)?!1:(n.add(i),!0)})}function Ae(e){return e.searchParams.delete($),`${e.pathname}${e.search}`}function _e(e){return Ae(new URL(e.location.href))}var Pe="a[href], area[href]";function X(e){var r,i,l;let t=Te(e);if(t===null)return null;for(let a=t.closest(R);a!==null;a=(i=(r=a.parentElement)==null?void 0:r.closest(R))!=null?i:null){let s=L(a);if(s!==null)return{element:a,field:s}}let n=t.closest(Pe);return n!==null&&(l=_(n)[0])!=null?l:null}function xe(e){var t,n;return(n=(t=Te(e))==null?void 0:t.closest(Pe))!=null?n:null}function ot(e,t){var s;let n=xe(e.target);if(n===null)return{kind:"allow"};if(e.button!==0||e.metaKey||e.ctrlKey||e.shiftKey||e.altKey||n.hasAttribute("download"))return{kind:"block"};let r=n.getAttribute("target");if(r!==null&&r!==""&&r!=="_self")return{kind:"block"};let i=(s=n.getAttribute("href"))!=null?s:"",l;try{l=new URL(i,t.location.href)}catch{return{kind:"block"}}if(l.origin!==t.location.origin||l.protocol!=="http:"&&l.protocol!=="https:")return{kind:"block"};let a=Ae(l);return(l.hash!==""||i.startsWith("#"))&&a===_e(t)?{kind:"allow"}:{kind:"navigate",path:a}}function lt(e){return typeof e.matchMedia=="function"&&e.matchMedia("(hover: none)").matches}function at(e){try{let t=e.sessionStorage.getItem(j);e.sessionStorage.removeItem(j);let n=t===null?Number.NaN:Number(t);return Number.isFinite(n)?n:null}catch{return null}}function st(e,t){if(t===null)return;let n=()=>e.scrollTo(0,t);e.document.readyState==="complete"?n():e.addEventListener("load",n,{once:!0})}return $e(dt);})();
4
4
  //# sourceMappingURL=crafty-visual-editing.global.js.map
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../src/cdn.ts", "../src/attrs.ts", "../src/preview.ts", "../src/version.ts", "../src/visual-editing/protocol.ts", "../src/visual-editing/markers.ts", "../src/visual-editing/live-preview.ts", "../src/visual-editing/origin.ts", "../src/visual-editing/overlay.ts", "../src/visual-editing/bridge.ts"],
4
- "sourcesContent": ["/** Entry for the `<script>` build: exposed as `window.CraftyVisualEditing`. */\nexport { attrs, attrsHtml } from \"./attrs.js\";\nexport { enableVisualEditing } from \"./visual-editing/bridge.js\";\nexport { PROTOCOL_VERSION } from \"./visual-editing/protocol.js\";\n", "import type { CraftyBlock, CraftyEntry } from \"./types/public.js\";\n\nexport type CraftyEditTargetType = \"block\" | \"entry\";\n\n/**\n * A block or entry as returned by the API, or an explicit reference for\n * ambiguous shapes (e.g. an entry with fields named `order`, `data` and `type`).\n */\nexport type CraftyEditTarget =\n | CraftyBlock\n | CraftyEntry\n | { kind: CraftyEditTargetType; id: number | string };\n\nexport type CraftyAttrsOptions = {\n /** Human label shown by the visual editor, e.g. \"T\u00EDtulo de la secci\u00F3n\". */\n label?: string;\n /**\n * Field holding the link destination of this element (a button or link whose\n * text is `field`), e.g. `hero.cta.href`. The editor then edits both together.\n */\n hrefField?: string;\n /** Human label for `hrefField`. Defaults to \"Enlace\" in the editor. */\n hrefLabel?: string;\n};\n\nexport type CraftyEditAttributes = {\n \"data-crafty-block\"?: string;\n \"data-crafty-entry\"?: string;\n \"data-crafty-field\"?: string;\n \"data-crafty-label\"?: string;\n \"data-crafty-href-field\"?: string;\n \"data-crafty-href-label\"?: string;\n};\n\nexport function resolveEditTarget(\n target: CraftyEditTarget | null | undefined\n): { type: CraftyEditTargetType; id: number } | null {\n if (target === null || target === undefined || typeof target !== \"object\") {\n return null;\n }\n\n const record = target as Record<string, unknown>;\n const id = typeof record.id === \"string\" ? Number(record.id.trim()) : record.id;\n\n if (typeof id !== \"number\" || !Number.isInteger(id) || id <= 0) {\n return null;\n }\n\n if (record.kind === \"block\" || record.kind === \"entry\") {\n return { type: record.kind, id };\n }\n\n const looksLikeBlock =\n typeof record.order === \"number\" &&\n typeof record.data === \"object\" &&\n record.data !== null &&\n \"type\" in record;\n\n return { type: looksLikeBlock ? \"block\" : \"entry\", id };\n}\n\n/**\n * DOM attributes that let the visual editor map an element to a field.\n * Always emitted (static sites render them at build time without a token).\n * `field` is a top-level field key or a JSON path such as `sections[3].title`.\n */\nexport function attrs(\n target: CraftyEditTarget | null | undefined,\n field: string,\n options: CraftyAttrsOptions = {}\n): CraftyEditAttributes {\n const resolved = resolveEditTarget(target);\n const normalizedField = typeof field === \"string\" ? field.trim() : \"\";\n\n if (resolved === null || normalizedField === \"\") {\n return {};\n }\n\n const attributes: CraftyEditAttributes =\n resolved.type === \"block\"\n ? { \"data-crafty-block\": String(resolved.id), \"data-crafty-field\": normalizedField }\n : { \"data-crafty-entry\": String(resolved.id), \"data-crafty-field\": normalizedField };\n\n const label = typeof options.label === \"string\" ? options.label.trim() : \"\";\n\n if (label !== \"\") {\n attributes[\"data-crafty-label\"] = label;\n }\n\n const hrefField = typeof options.hrefField === \"string\" ? options.hrefField.trim() : \"\";\n\n if (hrefField !== \"\") {\n attributes[\"data-crafty-href-field\"] = hrefField;\n\n const hrefLabel = typeof options.hrefLabel === \"string\" ? options.hrefLabel.trim() : \"\";\n\n if (hrefLabel !== \"\") {\n attributes[\"data-crafty-href-label\"] = hrefLabel;\n }\n }\n\n return attributes;\n}\n\n/** Same as `attrs()`, rendered for HTML string templates. */\nexport function attrsHtml(\n target: CraftyEditTarget | null | undefined,\n field: string,\n options: CraftyAttrsOptions = {}\n): string {\n return Object.entries(attrs(target, field, options))\n .map(([name, value]) => `${name}=\"${escapeAttribute(String(value))}\"`)\n .join(\" \");\n}\n\nfunction escapeAttribute(value: string): string {\n return value\n .replace(/&/g, \"&amp;\")\n .replace(/\"/g, \"&quot;\")\n .replace(/</g, \"&lt;\")\n .replace(/>/g, \"&gt;\");\n}\n", "export const PREVIEW_QUERY_PARAM = \"crafty_preview\";\nexport const PREVIEW_HEADER = \"X-Crafty-Preview\";\nexport const PREVIEW_STATUS_HEADER = \"X-Crafty-Preview-Status\";\nexport const PREVIEW_INVALID_EVENT = \"crafty:preview-invalid\";\nexport const PREVIEW_CONTENT_EVENT = \"crafty:preview-content\";\nexport const PREVIEW_ACTIVE_EVENT = \"crafty:preview-active\";\n\nconst TOKEN_STORAGE_KEY = \"crafty:preview-token\";\nconst URL_TOKEN_STORAGE_KEY = \"crafty:preview-url-token\";\nconst INVALID_TOKEN_STORAGE_KEY = \"crafty:preview-invalid-token\";\nconst CONTENT_GLOBAL_KEY = \"__CRAFTY_PREVIEW_CONTENT__\";\nconst STATUS_GLOBAL_KEY = \"__CRAFTY_PREVIEW_STATUS__\";\n\nexport type PreviewPage = { id: number; slug: string };\nexport type PreviewEntry = { id: number; collection: string };\nexport type PreviewContent = { page: PreviewPage | null; entries: PreviewEntry[] };\n/** Last `X-Crafty-Preview-Status` the API answered in this window, or null before any preview request. */\nexport type PreviewStatus = \"active\" | \"invalid\";\n\n/** A URL, a Web `Request`, a Node `IncomingMessage` or an Express-style request. */\nexport type PreviewRequestLike =\n | string\n | URL\n | { url?: string | undefined; query?: Record<string, unknown> | undefined };\n\ntype ContentHost = Record<string, PreviewContent | undefined>;\n\nfunction browserWindow(): Window | null {\n return typeof window === \"undefined\" ? null : window;\n}\n\nfunction storageGet(key: string): string | null {\n try {\n return browserWindow()?.sessionStorage.getItem(key) ?? null;\n } catch {\n return null;\n }\n}\n\nfunction storageSet(key: string, value: string): void {\n try {\n browserWindow()?.sessionStorage.setItem(key, value);\n } catch {\n // Storage can be blocked (private mode, sandboxed frames); the URL token still works.\n }\n}\n\nfunction storageRemove(key: string): void {\n try {\n browserWindow()?.sessionStorage.removeItem(key);\n } catch {\n // Ignore blocked storage.\n }\n}\n\nfunction normalizeToken(value: unknown): string | null {\n return typeof value === \"string\" && value.trim() !== \"\" ? value.trim() : null;\n}\n\nfunction tokenFromUrl(url: string): string | null {\n try {\n return normalizeToken(new URL(url, \"http://localhost\").searchParams.get(PREVIEW_QUERY_PARAM));\n } catch {\n return null;\n }\n}\n\n/**\n * Preview token for browser requests. A token the URL brings for the first time\n * wins; afterwards the stored token wins, so a renewal received over\n * `postMessage` is not overwritten by the stale token still in the URL.\n */\nexport function readPreviewToken(): string | null {\n const win = browserWindow();\n\n if (win === null) {\n return null;\n }\n\n const urlToken = tokenFromUrl(win.location.href);\n let token: string | null;\n\n if (urlToken !== null && urlToken !== storageGet(URL_TOKEN_STORAGE_KEY)) {\n storageSet(URL_TOKEN_STORAGE_KEY, urlToken);\n storageSet(TOKEN_STORAGE_KEY, urlToken);\n token = urlToken;\n } else {\n token = normalizeToken(storageGet(TOKEN_STORAGE_KEY)) ?? urlToken;\n }\n\n return token !== null && token === storageGet(INVALID_TOKEN_STORAGE_KEY) ? null : token;\n}\n\n/**\n * Forgets a browser token the API reported invalid, so later requests stop\n * sending it (the stale copy in the URL included) until a new token arrives\n * over `postMessage` or a new URL. Explicit server-side tokens are untouched.\n */\nexport function discardPreviewToken(token: string): void {\n const win = browserWindow();\n const normalized = normalizeToken(token);\n\n if (win === null || normalized === null) {\n return;\n }\n\n const isStored = normalizeToken(storageGet(TOKEN_STORAGE_KEY)) === normalized;\n\n if (!isStored && tokenFromUrl(win.location.href) !== normalized) {\n return;\n }\n\n if (isStored) {\n storageRemove(TOKEN_STORAGE_KEY);\n }\n\n storageSet(INVALID_TOKEN_STORAGE_KEY, normalized);\n}\n\nexport function storePreviewToken(token: string): void {\n const normalized = normalizeToken(token);\n\n if (normalized !== null) {\n storageSet(TOKEN_STORAGE_KEY, normalized);\n }\n}\n\nexport function clearPreviewToken(): void {\n storageRemove(TOKEN_STORAGE_KEY);\n storageRemove(URL_TOKEN_STORAGE_KEY);\n storageRemove(INVALID_TOKEN_STORAGE_KEY);\n setPreviewStatus(null);\n}\n\n/** Server-side helper: the preview token of an incoming request, or null. */\nexport function previewFromRequest(request: PreviewRequestLike | null | undefined): string | null {\n if (request === null || request === undefined) {\n return null;\n }\n\n if (typeof request === \"string\" || request instanceof URL) {\n return tokenFromUrl(String(request));\n }\n\n const queryValue = request.query?.[PREVIEW_QUERY_PARAM];\n const fromQuery = normalizeToken(Array.isArray(queryValue) ? queryValue[0] : queryValue);\n\n if (fromQuery !== null) {\n return fromQuery;\n }\n\n return typeof request.url === \"string\" ? tokenFromUrl(request.url) : null;\n}\n\nexport function getPreviewContent(): PreviewContent {\n const win = browserWindow() as (Window & ContentHost) | null;\n const content = win?.[CONTENT_GLOBAL_KEY];\n\n return content ? { page: content.page, entries: [...content.entries] } : { page: null, entries: [] };\n}\n\nexport function recordPreviewContent(\n item: ({ type: \"page\" } & PreviewPage) | ({ type: \"entry\" } & PreviewEntry)\n): void {\n const win = browserWindow() as (Window & ContentHost) | null;\n\n if (win === null) {\n return;\n }\n\n const content = win[CONTENT_GLOBAL_KEY] ?? { page: null, entries: [] };\n win[CONTENT_GLOBAL_KEY] = content;\n\n if (item.type === \"page\") {\n content.page = { id: item.id, slug: item.slug };\n } else if (!content.entries.some((entry) => entry.id === item.id && entry.collection === item.collection)) {\n content.entries.push({ id: item.id, collection: item.collection });\n }\n\n dispatch(PREVIEW_CONTENT_EVENT);\n}\n\nexport function resetPreviewContent(): void {\n const win = browserWindow() as (Window & ContentHost) | null;\n\n if (win !== null) {\n win[CONTENT_GLOBAL_KEY] = undefined;\n }\n}\n\n/**\n * Kept on `window` (like the shown content) so a separately bundled bridge, such\n * as the `<script>` build, sees what the site's own SDK copy recorded.\n */\nexport function getPreviewStatus(): PreviewStatus | null {\n const win = browserWindow() as (Window & Record<string, unknown>) | null;\n const status = win?.[STATUS_GLOBAL_KEY];\n\n return status === \"active\" || status === \"invalid\" ? status : null;\n}\n\nfunction setPreviewStatus(status: PreviewStatus | null): void {\n const win = browserWindow() as (Window & Record<string, unknown>) | null;\n\n if (win !== null) {\n win[STATUS_GLOBAL_KEY] = status ?? undefined;\n }\n}\n\nexport function notifyPreviewActive(): void {\n setPreviewStatus(\"active\");\n dispatch(PREVIEW_ACTIVE_EVENT);\n}\n\nexport function notifyPreviewInvalid(): void {\n setPreviewStatus(\"invalid\");\n dispatch(PREVIEW_INVALID_EVENT);\n}\n\nfunction dispatch(name: string): void {\n const win = browserWindow();\n\n if (win !== null && typeof win.dispatchEvent === \"function\") {\n win.dispatchEvent(new Event(name));\n }\n}\n", "// Generated by scripts/write-version.mjs from package.json. Do not edit.\nexport const SDK_VERSION = \"0.8.0\";\n", "export const PROTOCOL_VERSION = 1;\n\nexport type CraftyTargetType = \"block\" | \"entry\";\nexport type CraftyFieldRef = { type: CraftyTargetType; id: number; field: string };\n/** `hrefField` is the field with the link destination of the same element (same target). */\nexport type CraftyMarkedField = CraftyFieldRef & { label?: string; hrefField?: string; hrefLabel?: string };\nexport type CraftyShownPage = { id: number; slug: string };\nexport type CraftyShownEntry = { id: number; collection: string };\n\nexport type ReadyPayload = {\n sdkVersion: string;\n path: string;\n fields: CraftyMarkedField[];\n page: CraftyShownPage | null;\n entries: CraftyShownEntry[];\n};\n\ntype Version = typeof PROTOCOL_VERSION;\n\n/**\n * Keys forwarded to the admin (`crafty:key`, SDK >= 0.4.1): the admin never\n * sees keydowns while focus is inside the iframe, so Escape could not close\n * its sheets and dialogs. Older admins ignore the message.\n */\nexport type ForwardedKey = \"Escape\";\ntype EmptyPayload = Record<string, never>;\n\n/** iframe -> admin. `crafty:ready` is a snapshot that may be re-sent; the last one wins. */\nexport type OutboundMessage =\n | { v: Version; type: \"crafty:ready\"; payload: ReadyPayload }\n | { v: Version; type: \"crafty:select\"; payload: CraftyMarkedField }\n | { v: Version; type: \"crafty:navigate\"; payload: { path: string } }\n | { v: Version; type: \"crafty:preview-invalid\"; payload: EmptyPayload }\n | { v: Version; type: \"crafty:key\"; payload: { key: ForwardedKey } };\n\n/** admin -> iframe. */\nexport type InboundMessage =\n | { v: Version; type: \"crafty:token\"; payload: { token: string } }\n | { v: Version; type: \"crafty:refresh\"; payload: EmptyPayload }\n | { v: Version; type: \"crafty:highlight\"; payload: CraftyFieldRef }\n | { v: Version; type: \"crafty:preview-field\"; payload: CraftyFieldRef & { value: string } }\n | { v: Version; type: \"crafty:preview-reset\"; payload: CraftyFieldRef };\n\n/** Same limits as the Crafty admin and backend (content_drafts.field / label). */\nconst MAX_FIELD_LENGTH = 255;\nconst MAX_LABEL_LENGTH = 120;\nconst MAX_TOKEN_LENGTH = 4096;\nconst MAX_VALUE_LENGTH = 100_000;\nconst MAX_PATH_LENGTH = 2048;\nconst FIELD_PATTERN = /^[A-Za-z0-9_-]+(?:\\.[A-Za-z0-9_-]+|\\[\\d+\\])*$/;\nconst TOKEN_PATTERN = /^[\\x21-\\x7E]+$/;\nconst CONTROL_CHARACTERS = /[\\u0000-\\u001F\\u007F]/;\nconst PATH_BASE = \"https://crafty.invalid\";\n\nfunction isRecord(value: unknown): value is Record<string, unknown> {\n return typeof value === \"object\" && value !== null && !Array.isArray(value);\n}\n\nfunction isPositiveInteger(value: unknown): value is number {\n return typeof value === \"number\" && Number.isInteger(value) && value > 0;\n}\n\nfunction parseFieldPath(value: unknown): string | null {\n if (typeof value !== \"string\") {\n return null;\n }\n\n const trimmed = value.trim();\n\n return trimmed === \"\" || trimmed.length > MAX_FIELD_LENGTH || !FIELD_PATTERN.test(trimmed) ? null : trimmed;\n}\n\nfunction parseLabel(value: unknown): string {\n return typeof value === \"string\" ? value.trim().slice(0, MAX_LABEL_LENGTH).trim() : \"\";\n}\n\nexport function parseFieldRef(value: unknown): CraftyFieldRef | null {\n if (!isRecord(value)) {\n return null;\n }\n\n const { type, id } = value;\n const field = parseFieldPath(value.field);\n\n if ((type !== \"block\" && type !== \"entry\") || !isPositiveInteger(id) || field === null) {\n return null;\n }\n\n return { type, id, field };\n}\n\n/** An invalid `hrefField` is dropped; the text field stays selectable. */\nexport function parseMarkedField(value: unknown): CraftyMarkedField | null {\n const ref = parseFieldRef(value);\n\n if (ref === null || !isRecord(value)) {\n return null;\n }\n\n const marked: CraftyMarkedField = { ...ref };\n const label = parseLabel(value.label);\n const hrefField = parseFieldPath(value.hrefField);\n\n if (label !== \"\") {\n marked.label = label;\n }\n\n if (hrefField !== null) {\n marked.hrefField = hrefField;\n\n const hrefLabel = parseLabel(value.hrefLabel);\n\n if (hrefLabel !== \"\") {\n marked.hrefLabel = hrefLabel;\n }\n }\n\n return marked;\n}\n\nfunction isSameOriginPath(value: string): boolean {\n if (!value.startsWith(\"/\") || value.startsWith(\"//\") || value.startsWith(\"/\\\\\")) {\n return false;\n }\n\n try {\n const url = new URL(value, PATH_BASE);\n\n // Dot segments can still resolve to a protocol-relative path (\"/.//evil.example\").\n return url.origin === PATH_BASE && !url.pathname.startsWith(\"//\") && !url.pathname.startsWith(\"/\\\\\");\n } catch {\n return false;\n }\n}\n\nfunction parsePath(value: unknown): string | null {\n if (typeof value !== \"string\" || value.length > MAX_PATH_LENGTH || CONTROL_CHARACTERS.test(value)) {\n return null;\n }\n\n return isSameOriginPath(value) ? value : null;\n}\n\nfunction parseShownEntry(value: unknown): CraftyShownEntry | null {\n return isRecord(value) && isPositiveInteger(value.id) && typeof value.collection === \"string\"\n ? { id: value.id, collection: value.collection }\n : null;\n}\n\nfunction readEnvelope(data: unknown): { type: string; payload: Record<string, unknown> } | null {\n if (!isRecord(data) || data.v !== PROTOCOL_VERSION || typeof data.type !== \"string\") {\n return null;\n }\n\n const payload = data.payload === undefined ? {} : data.payload;\n\n return isRecord(payload) ? { type: data.type, payload } : null;\n}\n\nexport function parseInboundMessage(data: unknown): InboundMessage | null {\n const message = readEnvelope(data);\n\n if (message === null) {\n return null;\n }\n\n const { payload } = message;\n\n switch (message.type) {\n case \"crafty:token\": {\n const token = typeof payload.token === \"string\" ? payload.token.trim() : \"\";\n\n return token !== \"\" && token.length <= MAX_TOKEN_LENGTH && TOKEN_PATTERN.test(token)\n ? { v: PROTOCOL_VERSION, type: \"crafty:token\", payload: { token } }\n : null;\n }\n case \"crafty:refresh\":\n return { v: PROTOCOL_VERSION, type: \"crafty:refresh\", payload: {} };\n case \"crafty:highlight\": {\n const ref = parseFieldRef(payload);\n\n return ref ? { v: PROTOCOL_VERSION, type: \"crafty:highlight\", payload: ref } : null;\n }\n case \"crafty:preview-field\": {\n const ref = parseFieldRef(payload);\n const value = payload.value;\n\n return ref && typeof value === \"string\" && value.length <= MAX_VALUE_LENGTH\n ? { v: PROTOCOL_VERSION, type: \"crafty:preview-field\", payload: { ...ref, value } }\n : null;\n }\n case \"crafty:preview-reset\": {\n const ref = parseFieldRef(payload);\n\n return ref ? { v: PROTOCOL_VERSION, type: \"crafty:preview-reset\", payload: ref } : null;\n }\n default:\n return null;\n }\n}\n\nexport function parseOutboundMessage(data: unknown): OutboundMessage | null {\n const message = readEnvelope(data);\n\n if (message === null) {\n return null;\n }\n\n const { payload } = message;\n\n switch (message.type) {\n case \"crafty:ready\": {\n const path = parsePath(payload.path);\n const rawPage = payload.page;\n\n if (typeof payload.sdkVersion !== \"string\" || path === null || !Array.isArray(payload.fields) || !Array.isArray(payload.entries)) {\n return null;\n }\n\n return {\n v: PROTOCOL_VERSION,\n type: \"crafty:ready\",\n payload: {\n sdkVersion: payload.sdkVersion,\n path,\n fields: payload.fields\n .map((field: unknown) => parseMarkedField(field))\n .filter((field): field is CraftyMarkedField => field !== null),\n page:\n isRecord(rawPage) && isPositiveInteger(rawPage.id) && typeof rawPage.slug === \"string\"\n ? { id: rawPage.id, slug: rawPage.slug }\n : null,\n entries: payload.entries\n .map((entry: unknown) => parseShownEntry(entry))\n .filter((entry): entry is CraftyShownEntry => entry !== null)\n }\n };\n }\n case \"crafty:select\": {\n const field = parseMarkedField(payload);\n\n return field ? { v: PROTOCOL_VERSION, type: \"crafty:select\", payload: field } : null;\n }\n case \"crafty:navigate\": {\n const path = parsePath(payload.path);\n\n return path ? { v: PROTOCOL_VERSION, type: \"crafty:navigate\", payload: { path } } : null;\n }\n case \"crafty:preview-invalid\":\n return { v: PROTOCOL_VERSION, type: \"crafty:preview-invalid\", payload: {} };\n case \"crafty:key\":\n return payload.key === \"Escape\" ? { v: PROTOCOL_VERSION, type: \"crafty:key\", payload: { key: \"Escape\" } } : null;\n default:\n return null;\n }\n}\n", "import { parseMarkedField, type CraftyFieldRef, type CraftyMarkedField } from \"./protocol.js\";\n\nexport const MARKED_SELECTOR = \"[data-crafty-field]\";\n\nexport type MarkedElement = { element: Element; field: CraftyMarkedField };\n\nexport function readMarkedField(element: Element): CraftyMarkedField | null {\n const blockId = element.getAttribute(\"data-crafty-block\");\n const entryId = element.getAttribute(\"data-crafty-entry\");\n const rawId = blockId ?? entryId;\n\n if (rawId === null) {\n return null;\n }\n\n return parseMarkedField({\n type: blockId !== null ? \"block\" : \"entry\",\n id: rawId.trim() === \"\" ? Number.NaN : Number(rawId),\n field: element.getAttribute(\"data-crafty-field\") ?? \"\",\n label: element.getAttribute(\"data-crafty-label\"),\n hrefField: element.getAttribute(\"data-crafty-href-field\"),\n hrefLabel: element.getAttribute(\"data-crafty-href-label\")\n });\n}\n\nexport function refKey(ref: CraftyFieldRef): string {\n return `${ref.type}:${ref.id}:${ref.field}`;\n}\n\nexport function scanMarked(root: ParentNode): MarkedElement[] {\n const marked: MarkedElement[] = [];\n\n root.querySelectorAll(MARKED_SELECTOR).forEach((element) => {\n const field = readMarkedField(element);\n\n if (field !== null) {\n marked.push({ element, field });\n }\n });\n\n return marked;\n}\n\nexport function uniqueFields(marked: MarkedElement[]): CraftyMarkedField[] {\n const seen = new Set<string>();\n const fields: CraftyMarkedField[] = [];\n\n for (const { field } of marked) {\n const key = refKey(field);\n\n if (!seen.has(key)) {\n seen.add(key);\n fields.push(field);\n }\n }\n\n return fields;\n}\n", "import { MARKED_SELECTOR, readMarkedField, refKey } from \"./markers.js\";\nimport type { CraftyFieldRef } from \"./protocol.js\";\n\nexport type LivePreview = {\n set(ref: CraftyFieldRef, value: string): void;\n reset(ref: CraftyFieldRef): void;\n reapply(): void;\n resetAll(): void;\n readonly size: number;\n};\n\n/**\n * Plain-text live preview. Values are written with `textContent` (never HTML),\n * and each element's own original text is kept so a reset restores exactly what\n * the site rendered, even for elements rendered after the value was set.\n */\nexport function createLivePreview(root: ParentNode): LivePreview {\n const values = new Map<string, string>();\n const originals = new Map<Element, string>();\n\n const matching = (key: string): Element[] =>\n Array.from(root.querySelectorAll(MARKED_SELECTOR)).filter((element) => {\n const field = readMarkedField(element);\n\n return field !== null && refKey(field) === key;\n });\n\n const write = (element: Element, value: string): void => {\n if (!originals.has(element)) {\n originals.set(element, element.textContent ?? \"\");\n }\n\n if (element.textContent !== value) {\n element.textContent = value;\n }\n };\n\n const restore = (key: string | null): void => {\n for (const [element, original] of originals) {\n const field = readMarkedField(element);\n\n if (key === null || (field !== null && refKey(field) === key)) {\n if (element.textContent !== original) {\n element.textContent = original;\n }\n\n originals.delete(element);\n }\n }\n };\n\n return {\n set(ref, value) {\n const key = refKey(ref);\n values.set(key, value);\n matching(key).forEach((element) => write(element, value));\n },\n reset(ref) {\n const key = refKey(ref);\n values.delete(key);\n restore(key);\n },\n reapply() {\n for (const element of [...originals.keys()]) {\n if (!element.isConnected) {\n originals.delete(element);\n }\n }\n\n for (const [key, value] of values) {\n matching(key).forEach((element) => write(element, value));\n }\n },\n resetAll() {\n values.clear();\n restore(null);\n },\n get size() {\n return values.size;\n }\n };\n}\n", "/** Crafty admin panels: https://crafty.do and https://<tenant>.crafty.do. */\nexport const DEFAULT_ADMIN_ORIGINS: ReadonlyArray<string | RegExp> = [/^https:\\/\\/([a-z0-9-]+\\.)*crafty\\.do$/];\n\nfunction originOf(value: string): string | null {\n try {\n return new URL(value).origin;\n } catch {\n return null;\n }\n}\n\nexport function isAllowedAdminOrigin(origin: string, allowlist: ReadonlyArray<string | RegExp>): boolean {\n if (origin === \"\" || origin === \"null\") {\n return false;\n }\n\n return allowlist.some((allowed) => {\n if (typeof allowed === \"string\") {\n return originOf(allowed) === origin;\n }\n\n allowed.lastIndex = 0;\n\n return allowed.test(origin);\n });\n}\n\n/**\n * Origin of the embedding admin. `ancestorOrigins` (Chromium, WebKit) cannot be\n * spoofed by the framed page; Firefox falls back to the referrer the admin sent\n * when it set the iframe `src`.\n */\nexport function resolveParentOrigin(win: Window): string | null {\n const ancestors = win.location.ancestorOrigins as ArrayLike<string> | undefined;\n const first = ancestors && ancestors.length > 0 ? ancestors[0] : undefined;\n\n if (typeof first === \"string\" && first !== \"\") {\n return first;\n }\n\n const referrer = win.document.referrer;\n\n return referrer ? originOf(referrer) : null;\n}\n", "const STYLE_ELEMENT_ID = \"crafty-visual-editing-style\";\nconst ACCENT = \"#4f46e5\";\n\nexport const FLASH_CLASS = \"crafty-ve-flash\";\n\nconst STYLES = [\n \"[data-crafty-field]{cursor:pointer}\",\n `.crafty-ve-box{position:fixed;top:0;left:0;pointer-events:none;z-index:2147483647;box-sizing:border-box;border:2px solid ${ACCENT};border-radius:4px;background:rgba(79,70,229,.06)}`,\n \".crafty-ve-box[hidden]{display:none}\",\n `.crafty-ve-label{position:absolute;left:-2px;bottom:100%;margin-bottom:4px;padding:2px 8px;max-width:320px;overflow:hidden;text-overflow:ellipsis;white-space:nowrap;border-radius:4px;background:${ACCENT};color:#fff;font:500 12px/1.5 system-ui,-apple-system,sans-serif}`,\n `.${FLASH_CLASS}{outline:2px dashed ${ACCENT} !important;outline-offset:2px !important}`\n].join(\"\\n\");\n\nexport type Overlay = {\n show(element: Element, label: string): void;\n hide(): void;\n /** Re-measures the highlighted element, e.g. after its content changed. */\n reposition(): void;\n flash(elements: Element[], durationMs: number): void;\n ensureAttached(): void;\n contains(node: Node | null): boolean;\n destroy(): void;\n};\n\nexport function createOverlay(doc: Document): Overlay {\n const win = doc.defaultView;\n const style = doc.createElement(\"style\");\n style.id = STYLE_ELEMENT_ID;\n style.textContent = STYLES;\n\n const box = doc.createElement(\"div\");\n box.setAttribute(\"data-crafty-overlay\", \"\");\n box.className = \"crafty-ve-box\";\n box.hidden = true;\n\n const label = doc.createElement(\"span\");\n label.className = \"crafty-ve-label\";\n box.appendChild(label);\n\n let target: Element | null = null;\n let flashed: Element[] = [];\n let flashTimer: number | undefined;\n const Observer = (win as (Window & { ResizeObserver?: typeof ResizeObserver }) | null)?.ResizeObserver;\n\n const place = (): void => {\n if (target === null) {\n return;\n }\n\n const rect = target.getBoundingClientRect();\n box.style.top = `${rect.top}px`;\n box.style.left = `${rect.left}px`;\n box.style.width = `${rect.width}px`;\n box.style.height = `${rect.height}px`;\n };\n\n const resizeObserver = typeof Observer === \"function\" ? new Observer(() => place()) : null;\n\n const track = (element: Element | null): void => {\n if (target === element) {\n return;\n }\n\n if (target !== null) {\n resizeObserver?.unobserve(target);\n }\n\n target = element;\n\n if (target !== null) {\n resizeObserver?.observe(target);\n }\n };\n\n const clearFlash = (): void => {\n flashed.forEach((element) => element.classList.remove(FLASH_CLASS));\n flashed = [];\n\n if (flashTimer !== undefined) {\n win?.clearTimeout(flashTimer);\n flashTimer = undefined;\n }\n };\n\n const ensureAttached = (): void => {\n if (!style.isConnected) {\n (doc.head ?? doc.documentElement).appendChild(style);\n }\n\n if (!box.isConnected) {\n (doc.body ?? doc.documentElement).appendChild(box);\n }\n };\n\n ensureAttached();\n win?.addEventListener(\"scroll\", place, { capture: true, passive: true });\n win?.addEventListener(\"resize\", place, { passive: true });\n\n return {\n show(element, text) {\n ensureAttached();\n track(element);\n\n if (label.textContent !== text) {\n label.textContent = text;\n }\n\n box.hidden = false;\n place();\n },\n hide() {\n track(null);\n box.hidden = true;\n },\n reposition() {\n place();\n },\n flash(elements, durationMs) {\n clearFlash();\n flashed = [...elements];\n flashed.forEach((element) => element.classList.add(FLASH_CLASS));\n flashTimer = win?.setTimeout(clearFlash, durationMs);\n },\n ensureAttached,\n contains(node) {\n return node !== null && (box === node || box.contains(node) || style === node || style.contains(node));\n },\n destroy() {\n clearFlash();\n win?.removeEventListener(\"scroll\", place, { capture: true });\n win?.removeEventListener(\"resize\", place);\n resizeObserver?.disconnect();\n box.remove();\n style.remove();\n target = null;\n }\n };\n}\n", "import type { CraftyClient } from \"../client.js\";\nimport {\n PREVIEW_ACTIVE_EVENT,\n PREVIEW_CONTENT_EVENT,\n PREVIEW_INVALID_EVENT,\n PREVIEW_QUERY_PARAM,\n getPreviewContent,\n getPreviewStatus,\n readPreviewToken,\n storePreviewToken\n} from \"../preview.js\";\nimport { SDK_VERSION } from \"../version.js\";\nimport { createLivePreview } from \"./live-preview.js\";\nimport { MARKED_SELECTOR, readMarkedField, refKey, scanMarked, uniqueFields, type MarkedElement } from \"./markers.js\";\nimport { DEFAULT_ADMIN_ORIGINS, isAllowedAdminOrigin, resolveParentOrigin } from \"./origin.js\";\nimport { createOverlay } from \"./overlay.js\";\nimport {\n PROTOCOL_VERSION,\n parseInboundMessage,\n type CraftyFieldRef,\n type CraftyMarkedField,\n type CraftyShownEntry,\n type CraftyShownPage,\n type InboundMessage,\n type OutboundMessage\n} from \"./protocol.js\";\n\nexport type VisualEditingOptions = {\n /** Allowed admin origins. Replaces the default (`https://*.crafty.do`). */\n adminOrigins?: ReadonlyArray<string | RegExp>;\n /** Re-fetch and re-render instead of a full reload when the admin asks for a refresh. */\n onRefresh?: () => void | Promise<void>;\n /** Page rendered by the server (SSR sites, where the browser did not fetch it). */\n page?: CraftyShownPage | null;\n /** Entries rendered by the server (SSR sites). */\n entries?: CraftyShownEntry[];\n /** How long touch devices highlight every editable after load. Default 1500 ms. */\n touchHighlightMs?: number;\n /**\n * Client used to confirm the preview token when no preview request has been\n * answered yet (one `pages.list({ per_page: 1 })` call). Without it the bridge\n * waits for the site's own first Crafty request to confirm the token.\n */\n client?: Pick<CraftyClient, \"pages\">;\n};\n\nexport type VisualEditingHandle = {\n readonly active: boolean;\n disable(): void;\n};\n\nconst SCROLL_STORAGE_KEY = \"crafty:scroll-y\";\nconst RESCAN_DELAY_MS = 50;\nconst DEFAULT_TOUCH_HIGHLIGHT_MS = 1500;\nconst WATCHED_ATTRIBUTES = [\n \"data-crafty-field\",\n \"data-crafty-block\",\n \"data-crafty-entry\",\n \"data-crafty-label\",\n \"data-crafty-href-field\",\n \"data-crafty-href-label\"\n];\n\nconst inactiveHandle: VisualEditingHandle = { active: false, disable: () => undefined };\nlet activeHandle: VisualEditingHandle | null = null;\n\n/**\n * Connects the page to the Crafty visual editor. No-op unless the page runs in\n * an iframe, carries a preview token, and its parent is an allowed admin origin.\n *\n * The default allowlist (`*.crafty.do`) also covers sites hosted by Crafty, so\n * the bridge stays inert (no overlay, no listeners, no messages) until the API\n * answers a preview request with `X-Crafty-Preview-Status: active`. On `invalid`\n * it only tells the admin `crafty:preview-invalid` and stays inert.\n */\nexport function enableVisualEditing(options: VisualEditingOptions = {}): VisualEditingHandle {\n if (typeof window === \"undefined\" || typeof document === \"undefined\") {\n return inactiveHandle;\n }\n\n if (activeHandle !== null) {\n return activeHandle;\n }\n\n const win = window;\n\n if (win.parent === null || win.parent === win || readPreviewToken() === null) {\n return inactiveHandle;\n }\n\n const parentOrigin = resolveParentOrigin(win);\n\n if (parentOrigin === null || !isAllowedAdminOrigin(parentOrigin, options.adminOrigins ?? DEFAULT_ADMIN_ORIGINS)) {\n return inactiveHandle;\n }\n\n const status = getPreviewStatus();\n\n if (status === \"invalid\") {\n postPreviewInvalid(win, parentOrigin);\n\n return inactiveHandle;\n }\n\n activeHandle = status === \"active\" ? startBridge(win, parentOrigin, options) : awaitConfirmation(win, parentOrigin, options);\n\n return activeHandle;\n}\n\nfunction postPreviewInvalid(win: Window, parentOrigin: string): void {\n const message: OutboundMessage = { v: PROTOCOL_VERSION, type: \"crafty:preview-invalid\", payload: {} };\n win.parent.postMessage(message, parentOrigin);\n}\n\n/**\n * Pending handle: waits for the API to confirm the token before starting the\n * bridge, verifying it through `options.client` when one is given.\n */\nfunction awaitConfirmation(win: Window, parentOrigin: string, options: VisualEditingOptions): VisualEditingHandle {\n let bridge: VisualEditingHandle | null = null;\n let settled = false;\n\n const stopWaiting = (): void => {\n settled = true;\n win.removeEventListener(PREVIEW_ACTIVE_EVENT, onActive);\n win.removeEventListener(PREVIEW_INVALID_EVENT, onInvalid);\n };\n\n const release = (): void => {\n if (activeHandle === handle) {\n activeHandle = null;\n }\n };\n\n const onActive = (): void => {\n if (settled) {\n return;\n }\n\n stopWaiting();\n bridge = startBridge(win, parentOrigin, options, release);\n };\n\n const onInvalid = (): void => {\n if (settled) {\n return;\n }\n\n stopWaiting();\n release();\n postPreviewInvalid(win, parentOrigin);\n };\n\n const handle: VisualEditingHandle = {\n get active() {\n return bridge?.active ?? false;\n },\n disable() {\n stopWaiting();\n bridge?.disable();\n release();\n }\n };\n\n win.addEventListener(PREVIEW_ACTIVE_EVENT, onActive);\n win.addEventListener(PREVIEW_INVALID_EVENT, onInvalid);\n\n // The status handlers above settle the outcome; request errors leave the bridge waiting.\n options.client?.pages.list({ per_page: 1 }).catch(() => undefined);\n\n return handle;\n}\n\nfunction startBridge(\n win: Window,\n parentOrigin: string,\n options: VisualEditingOptions,\n onDisable?: () => void\n): VisualEditingHandle {\n const doc = win.document;\n const overlay = createOverlay(doc);\n const livePreview = createLivePreview(doc);\n const pendingScrollY = takeStoredScroll(win);\n\n let marked: MarkedElement[] = [];\n let sentSignature: string | null = null;\n let rescanTimer: number | undefined;\n let forceReady = false;\n let active = true;\n\n const post = (message: OutboundMessage): void => {\n win.parent.postMessage(message, parentOrigin);\n };\n\n const sendReady = (): void => {\n const fields = uniqueFields(marked);\n const content = getPreviewContent();\n sentSignature = signatureOf(fields);\n\n post({\n v: PROTOCOL_VERSION,\n type: \"crafty:ready\",\n payload: {\n sdkVersion: SDK_VERSION,\n path: currentPath(win),\n fields,\n page: content.page ?? options.page ?? null,\n entries: mergeEntries(content.entries, options.entries ?? [])\n }\n });\n };\n\n const rescan = (): void => {\n rescanTimer = undefined;\n\n if (!active) {\n return;\n }\n\n overlay.ensureAttached();\n marked = scanMarked(doc);\n livePreview.reapply();\n\n if (forceReady || signatureOf(uniqueFields(marked)) !== sentSignature) {\n forceReady = false;\n sendReady();\n }\n };\n\n const scheduleRescan = (): void => {\n if (active && rescanTimer === undefined) {\n rescanTimer = win.setTimeout(rescan, RESCAN_DELAY_MS);\n }\n };\n\n const observer = new MutationObserver((records) => {\n if (records.some((record) => !overlay.contains(record.target))) {\n scheduleRescan();\n }\n });\n\n const labelOf = (field: CraftyMarkedField): string => field.label ?? field.field;\n\n const onPointerOver = (event: PointerEvent): void => {\n if (event.pointerType === \"touch\") {\n return;\n }\n\n const hit = hitFrom(event.target);\n\n if (hit !== null) {\n overlay.show(hit.element, labelOf(hit.field));\n } else {\n overlay.hide();\n }\n };\n\n const block = (event: Event): void => {\n event.preventDefault();\n event.stopPropagation();\n };\n\n /**\n * Runs in the capture phase on `window`, before any site listener, so a marked\n * element always selects even when it is (or sits inside) a link or button,\n * and nothing the site renders can take the iframe out of the editor.\n */\n const onClick = (event: MouseEvent): void => {\n const hit = hitFrom(event.target);\n\n if (hit !== null) {\n block(event);\n overlay.show(hit.element, labelOf(hit.field));\n post({ v: PROTOCOL_VERSION, type: \"crafty:select\", payload: hit.field });\n\n return;\n }\n\n const action = linkAction(event, win);\n\n if (action.kind === \"allow\") {\n return;\n }\n\n block(event);\n\n if (action.kind === \"navigate\") {\n post({ v: PROTOCOL_VERSION, type: \"crafty:navigate\", payload: { path: action.path } });\n }\n };\n\n /** Middle clicks open links in a new tab: never let them leave the editor. */\n const onAuxClick = (event: MouseEvent): void => {\n if (hitFrom(event.target) !== null || closestLink(event.target) !== null) {\n block(event);\n }\n };\n\n const onSubmit = (event: Event): void => {\n block(event);\n };\n\n /**\n * Escape pressed while focus is inside the iframe never reaches the admin\n * window: forward it so the admin closes its topmost sheet or dialog. Runs in\n * the bubble phase, after the site, and skips an Escape the site handled\n * (`preventDefault`, e.g. to close its own menu).\n */\n const onKeyDown = (event: KeyboardEvent): void => {\n if (event.key !== \"Escape\" || event.repeat || event.isComposing || event.defaultPrevented) {\n return;\n }\n\n post({ v: PROTOCOL_VERSION, type: \"crafty:key\", payload: { key: \"Escape\" } });\n };\n\n const highlight = (ref: CraftyFieldRef): void => {\n const key = refKey(ref);\n const match = scanMarked(doc).find((item) => refKey(item.field) === key);\n\n if (match === undefined) {\n return;\n }\n\n const element = match.element as Element & { scrollIntoView?: (options?: ScrollIntoViewOptions) => void };\n element.scrollIntoView?.({ block: \"center\", behavior: \"smooth\" });\n overlay.show(match.element, labelOf(match.field));\n };\n\n const refresh = async (): Promise<void> => {\n if (options.onRefresh) {\n try {\n await options.onRefresh();\n } finally {\n scheduleRescan();\n }\n\n return;\n }\n\n try {\n win.sessionStorage.setItem(SCROLL_STORAGE_KEY, String(win.scrollY));\n } catch {\n // Storage blocked: reload without restoring the scroll position.\n }\n\n win.location.reload();\n };\n\n const handleInbound = (message: InboundMessage): void => {\n switch (message.type) {\n case \"crafty:token\":\n storePreviewToken(message.payload.token);\n return;\n case \"crafty:refresh\":\n refresh().catch((error: unknown) => console.error(\"[crafty] onRefresh failed\", error));\n return;\n case \"crafty:highlight\":\n highlight(message.payload);\n return;\n case \"crafty:preview-field\":\n livePreview.set(message.payload, message.payload.value);\n overlay.reposition();\n return;\n case \"crafty:preview-reset\":\n livePreview.reset(message.payload);\n overlay.reposition();\n return;\n }\n };\n\n const onMessage = (event: MessageEvent): void => {\n if (event.source !== win.parent || event.origin !== parentOrigin) {\n return;\n }\n\n const message = parseInboundMessage(event.data);\n\n if (message !== null) {\n handleInbound(message);\n }\n };\n\n const onPreviewInvalid = (): void => {\n post({ v: PROTOCOL_VERSION, type: \"crafty:preview-invalid\", payload: {} });\n };\n\n const onPreviewContent = (): void => {\n forceReady = true;\n scheduleRescan();\n };\n\n const start = (): void => {\n if (!active) {\n return;\n }\n\n marked = scanMarked(doc);\n sendReady();\n\n if (isTouchDevice(win)) {\n overlay.flash(\n marked.map((item) => item.element),\n options.touchHighlightMs ?? DEFAULT_TOUCH_HIGHLIGHT_MS\n );\n }\n\n restoreScroll(win, pendingScrollY);\n };\n\n win.addEventListener(\"message\", onMessage);\n win.addEventListener(\"click\", onClick, true);\n win.addEventListener(\"auxclick\", onAuxClick, true);\n win.addEventListener(\"submit\", onSubmit, true);\n win.addEventListener(\"keydown\", onKeyDown);\n doc.addEventListener(\"pointerover\", onPointerOver, true);\n win.addEventListener(PREVIEW_INVALID_EVENT, onPreviewInvalid);\n win.addEventListener(PREVIEW_CONTENT_EVENT, onPreviewContent);\n observer.observe(doc.documentElement, {\n childList: true,\n subtree: true,\n attributes: true,\n attributeFilter: WATCHED_ATTRIBUTES\n });\n\n if (doc.readyState === \"loading\") {\n doc.addEventListener(\"DOMContentLoaded\", start, { once: true });\n } else {\n start();\n }\n\n const handle: VisualEditingHandle = {\n get active() {\n return active;\n },\n disable() {\n if (!active) {\n return;\n }\n\n active = false;\n win.removeEventListener(\"message\", onMessage);\n win.removeEventListener(\"click\", onClick, true);\n win.removeEventListener(\"auxclick\", onAuxClick, true);\n win.removeEventListener(\"submit\", onSubmit, true);\n win.removeEventListener(\"keydown\", onKeyDown);\n doc.removeEventListener(\"pointerover\", onPointerOver, true);\n doc.removeEventListener(\"DOMContentLoaded\", start);\n win.removeEventListener(PREVIEW_INVALID_EVENT, onPreviewInvalid);\n win.removeEventListener(PREVIEW_CONTENT_EVENT, onPreviewContent);\n observer.disconnect();\n\n if (rescanTimer !== undefined) {\n win.clearTimeout(rescanTimer);\n rescanTimer = undefined;\n }\n\n livePreview.resetAll();\n overlay.destroy();\n\n if (activeHandle === handle) {\n activeHandle = null;\n }\n\n onDisable?.();\n }\n };\n\n return handle;\n}\n\nfunction asElement(target: EventTarget | null): Element | null {\n return target !== null && typeof (target as Element).closest === \"function\" ? (target as Element) : null;\n}\n\nfunction signatureOf(fields: CraftyMarkedField[]): string {\n return fields.map((field) => `${refKey(field)}|${field.label ?? \"\"}|${field.hrefField ?? \"\"}|${field.hrefLabel ?? \"\"}`).join(\"\\n\");\n}\n\nfunction mergeEntries(fetched: CraftyShownEntry[], declared: CraftyShownEntry[]): CraftyShownEntry[] {\n const seen = new Set<string>();\n\n return [...fetched, ...declared].filter((entry) => {\n const key = `${entry.collection}:${entry.id}`;\n\n if (seen.has(key)) {\n return false;\n }\n\n seen.add(key);\n\n return true;\n });\n}\n\nfunction stripPreviewParam(url: URL): string {\n url.searchParams.delete(PREVIEW_QUERY_PARAM);\n\n return `${url.pathname}${url.search}`;\n}\n\nfunction currentPath(win: Window): string {\n return stripPreviewParam(new URL(win.location.href));\n}\n\ntype LinkAction = { kind: \"allow\" } | { kind: \"block\" } | { kind: \"navigate\"; path: string };\n\n/**\n * Only links fall back to their marked descendant: following them would leave\n * the editor. Buttons, `<summary>` and labels keep their own behavior (menus,\n * accordions, tabs) when the click misses the marked element.\n */\nconst LINK_SELECTOR = \"a[href], area[href]\";\n\n/**\n * The marked element a pointer or click target maps to: the innermost valid\n * marked ancestor (or the target itself), else the first marked element inside\n * the link that was clicked, so clicking a link button's padding or icon\n * selects its label.\n */\nfunction hitFrom(target: EventTarget | null): MarkedElement | null {\n const element = asElement(target);\n\n if (element === null) {\n return null;\n }\n\n for (let node = element.closest(MARKED_SELECTOR); node !== null; node = node.parentElement?.closest(MARKED_SELECTOR) ?? null) {\n const field = readMarkedField(node);\n\n if (field !== null) {\n return { element: node, field };\n }\n }\n\n const link = element.closest(LINK_SELECTOR);\n\n return link !== null ? (scanMarked(link)[0] ?? null) : null;\n}\n\nfunction closestLink(target: EventTarget | null): Element | null {\n return asElement(target)?.closest(LINK_SELECTOR) ?? null;\n}\n\n/**\n * What to do with a click that hit no marked element. Only same-page anchors\n * run as usual; same-origin links become `crafty:navigate`; anything that\n * would leave the editor (other origins, `mailto:`/`tel:`, new tabs,\n * downloads, modified clicks) is blocked.\n */\nfunction linkAction(event: MouseEvent, win: Window): LinkAction {\n const anchor = closestLink(event.target);\n\n if (anchor === null) {\n return { kind: \"allow\" };\n }\n\n if (event.button !== 0 || event.metaKey || event.ctrlKey || event.shiftKey || event.altKey || anchor.hasAttribute(\"download\")) {\n return { kind: \"block\" };\n }\n\n const target = anchor.getAttribute(\"target\");\n\n if (target !== null && target !== \"\" && target !== \"_self\") {\n return { kind: \"block\" };\n }\n\n const href = anchor.getAttribute(\"href\") ?? \"\";\n let url: URL;\n\n try {\n url = new URL(href, win.location.href);\n } catch {\n return { kind: \"block\" };\n }\n\n if (url.origin !== win.location.origin || (url.protocol !== \"http:\" && url.protocol !== \"https:\")) {\n return { kind: \"block\" };\n }\n\n const path = stripPreviewParam(url);\n\n if ((url.hash !== \"\" || href.startsWith(\"#\")) && path === currentPath(win)) {\n return { kind: \"allow\" };\n }\n\n return { kind: \"navigate\", path };\n}\n\nfunction isTouchDevice(win: Window): boolean {\n return typeof win.matchMedia === \"function\" && win.matchMedia(\"(hover: none)\").matches;\n}\n\nfunction takeStoredScroll(win: Window): number | null {\n try {\n const raw = win.sessionStorage.getItem(SCROLL_STORAGE_KEY);\n win.sessionStorage.removeItem(SCROLL_STORAGE_KEY);\n const scrollY = raw === null ? Number.NaN : Number(raw);\n\n return Number.isFinite(scrollY) ? scrollY : null;\n } catch {\n return null;\n }\n}\n\nfunction restoreScroll(win: Window, scrollY: number | null): void {\n if (scrollY === null) {\n return;\n }\n\n const apply = (): void => win.scrollTo(0, scrollY);\n\n if (win.document.readyState === \"complete\") {\n apply();\n } else {\n win.addEventListener(\"load\", apply, { once: true });\n }\n}\n"],
4
+ "sourcesContent": ["/** Entry for the `<script>` build: exposed as `window.CraftyVisualEditing`. */\nexport { attrs, attrsHtml } from \"./attrs.js\";\nexport { enableVisualEditing } from \"./visual-editing/bridge.js\";\nexport { PROTOCOL_VERSION } from \"./visual-editing/protocol.js\";\n", "import type { CraftyBlock, CraftyEntry } from \"./types/public.js\";\n\nexport type CraftyEditTargetType = \"block\" | \"entry\";\n\n/**\n * A block or entry as returned by the API, or an explicit reference for\n * ambiguous shapes (e.g. an entry with fields named `order`, `data` and `type`).\n */\nexport type CraftyEditTarget =\n | CraftyBlock\n | CraftyEntry\n | { kind: CraftyEditTargetType; id: number | string };\n\nexport type CraftyAttrsOptions = {\n /** Human label shown by the visual editor, e.g. \"T\u00EDtulo de la secci\u00F3n\". */\n label?: string;\n /**\n * Field holding the link destination of this element (a button or link whose\n * text is `field`), e.g. `hero.cta.href`. The editor then edits both together.\n */\n hrefField?: string;\n /** Human label for `hrefField`. Defaults to \"Enlace\" in the editor. */\n hrefLabel?: string;\n};\n\nexport type CraftyEditAttributes = {\n \"data-crafty-block\"?: string;\n \"data-crafty-entry\"?: string;\n \"data-crafty-field\"?: string;\n \"data-crafty-label\"?: string;\n \"data-crafty-href-field\"?: string;\n \"data-crafty-href-label\"?: string;\n};\n\nexport function resolveEditTarget(\n target: CraftyEditTarget | null | undefined\n): { type: CraftyEditTargetType; id: number } | null {\n if (target === null || target === undefined || typeof target !== \"object\") {\n return null;\n }\n\n const record = target as Record<string, unknown>;\n const id = typeof record.id === \"string\" ? Number(record.id.trim()) : record.id;\n\n if (typeof id !== \"number\" || !Number.isInteger(id) || id <= 0) {\n return null;\n }\n\n if (record.kind === \"block\" || record.kind === \"entry\") {\n return { type: record.kind, id };\n }\n\n const looksLikeBlock =\n typeof record.order === \"number\" &&\n typeof record.data === \"object\" &&\n record.data !== null &&\n \"type\" in record;\n\n return { type: looksLikeBlock ? \"block\" : \"entry\", id };\n}\n\n/**\n * DOM attributes that let the visual editor map an element to a field.\n * Always emitted (static sites render them at build time without a token).\n * `field` is a top-level field key or a JSON path such as `sections[3].title`.\n */\nexport function attrs(\n target: CraftyEditTarget | null | undefined,\n field: string,\n options: CraftyAttrsOptions = {}\n): CraftyEditAttributes {\n const resolved = resolveEditTarget(target);\n const normalizedField = typeof field === \"string\" ? field.trim() : \"\";\n\n if (resolved === null || normalizedField === \"\") {\n return {};\n }\n\n const attributes: CraftyEditAttributes =\n resolved.type === \"block\"\n ? { \"data-crafty-block\": String(resolved.id), \"data-crafty-field\": normalizedField }\n : { \"data-crafty-entry\": String(resolved.id), \"data-crafty-field\": normalizedField };\n\n const label = typeof options.label === \"string\" ? options.label.trim() : \"\";\n\n if (label !== \"\") {\n attributes[\"data-crafty-label\"] = label;\n }\n\n const hrefField = typeof options.hrefField === \"string\" ? options.hrefField.trim() : \"\";\n\n if (hrefField !== \"\") {\n attributes[\"data-crafty-href-field\"] = hrefField;\n\n const hrefLabel = typeof options.hrefLabel === \"string\" ? options.hrefLabel.trim() : \"\";\n\n if (hrefLabel !== \"\") {\n attributes[\"data-crafty-href-label\"] = hrefLabel;\n }\n }\n\n return attributes;\n}\n\n/** Same as `attrs()`, rendered for HTML string templates. */\nexport function attrsHtml(\n target: CraftyEditTarget | null | undefined,\n field: string,\n options: CraftyAttrsOptions = {}\n): string {\n return Object.entries(attrs(target, field, options))\n .map(([name, value]) => `${name}=\"${escapeAttribute(String(value))}\"`)\n .join(\" \");\n}\n\nfunction escapeAttribute(value: string): string {\n return value\n .replace(/&/g, \"&amp;\")\n .replace(/\"/g, \"&quot;\")\n .replace(/</g, \"&lt;\")\n .replace(/>/g, \"&gt;\");\n}\n", "export const PREVIEW_QUERY_PARAM = \"crafty_preview\";\nexport const PREVIEW_HEADER = \"X-Crafty-Preview\";\nexport const PREVIEW_STATUS_HEADER = \"X-Crafty-Preview-Status\";\nexport const PREVIEW_INVALID_EVENT = \"crafty:preview-invalid\";\nexport const PREVIEW_CONTENT_EVENT = \"crafty:preview-content\";\nexport const PREVIEW_ACTIVE_EVENT = \"crafty:preview-active\";\n\nconst TOKEN_STORAGE_KEY = \"crafty:preview-token\";\nconst URL_TOKEN_STORAGE_KEY = \"crafty:preview-url-token\";\nconst INVALID_TOKEN_STORAGE_KEY = \"crafty:preview-invalid-token\";\nconst CONTENT_GLOBAL_KEY = \"__CRAFTY_PREVIEW_CONTENT__\";\nconst STATUS_GLOBAL_KEY = \"__CRAFTY_PREVIEW_STATUS__\";\n\nexport type PreviewPage = { id: number; slug: string };\nexport type PreviewEntry = { id: number; collection: string };\nexport type PreviewContent = { page: PreviewPage | null; entries: PreviewEntry[] };\n/** Last `X-Crafty-Preview-Status` the API answered in this window, or null before any preview request. */\nexport type PreviewStatus = \"active\" | \"invalid\";\n\n/** A URL, a Web `Request`, a Node `IncomingMessage` or an Express-style request. */\nexport type PreviewRequestLike =\n | string\n | URL\n | { url?: string | undefined; query?: Record<string, unknown> | undefined };\n\ntype ContentHost = Record<string, PreviewContent | undefined>;\n\nfunction browserWindow(): Window | null {\n return typeof window === \"undefined\" ? null : window;\n}\n\nfunction storageGet(key: string): string | null {\n try {\n return browserWindow()?.sessionStorage.getItem(key) ?? null;\n } catch {\n return null;\n }\n}\n\nfunction storageSet(key: string, value: string): void {\n try {\n browserWindow()?.sessionStorage.setItem(key, value);\n } catch {\n // Storage can be blocked (private mode, sandboxed frames); the URL token still works.\n }\n}\n\nfunction storageRemove(key: string): void {\n try {\n browserWindow()?.sessionStorage.removeItem(key);\n } catch {\n // Ignore blocked storage.\n }\n}\n\nfunction normalizeToken(value: unknown): string | null {\n return typeof value === \"string\" && value.trim() !== \"\" ? value.trim() : null;\n}\n\nfunction tokenFromUrl(url: string): string | null {\n try {\n return normalizeToken(new URL(url, \"http://localhost\").searchParams.get(PREVIEW_QUERY_PARAM));\n } catch {\n return null;\n }\n}\n\n/**\n * Preview token for browser requests. A token the URL brings for the first time\n * wins; afterwards the stored token wins, so a renewal received over\n * `postMessage` is not overwritten by the stale token still in the URL.\n */\nexport function readPreviewToken(): string | null {\n const win = browserWindow();\n\n if (win === null) {\n return null;\n }\n\n const urlToken = tokenFromUrl(win.location.href);\n let token: string | null;\n\n if (urlToken !== null && urlToken !== storageGet(URL_TOKEN_STORAGE_KEY)) {\n storageSet(URL_TOKEN_STORAGE_KEY, urlToken);\n storageSet(TOKEN_STORAGE_KEY, urlToken);\n token = urlToken;\n } else {\n token = normalizeToken(storageGet(TOKEN_STORAGE_KEY)) ?? urlToken;\n }\n\n return token !== null && token === storageGet(INVALID_TOKEN_STORAGE_KEY) ? null : token;\n}\n\n/**\n * Forgets a browser token the API reported invalid, so later requests stop\n * sending it (the stale copy in the URL included) until a new token arrives\n * over `postMessage` or a new URL. Explicit server-side tokens are untouched.\n */\nexport function discardPreviewToken(token: string): void {\n const win = browserWindow();\n const normalized = normalizeToken(token);\n\n if (win === null || normalized === null) {\n return;\n }\n\n const isStored = normalizeToken(storageGet(TOKEN_STORAGE_KEY)) === normalized;\n\n if (!isStored && tokenFromUrl(win.location.href) !== normalized) {\n return;\n }\n\n if (isStored) {\n storageRemove(TOKEN_STORAGE_KEY);\n }\n\n storageSet(INVALID_TOKEN_STORAGE_KEY, normalized);\n}\n\nexport function storePreviewToken(token: string): void {\n const normalized = normalizeToken(token);\n\n if (normalized !== null) {\n storageSet(TOKEN_STORAGE_KEY, normalized);\n }\n}\n\nexport function clearPreviewToken(): void {\n storageRemove(TOKEN_STORAGE_KEY);\n storageRemove(URL_TOKEN_STORAGE_KEY);\n storageRemove(INVALID_TOKEN_STORAGE_KEY);\n setPreviewStatus(null);\n}\n\n/** Server-side helper: the preview token of an incoming request, or null. */\nexport function previewFromRequest(request: PreviewRequestLike | null | undefined): string | null {\n if (request === null || request === undefined) {\n return null;\n }\n\n if (typeof request === \"string\" || request instanceof URL) {\n return tokenFromUrl(String(request));\n }\n\n const queryValue = request.query?.[PREVIEW_QUERY_PARAM];\n const fromQuery = normalizeToken(Array.isArray(queryValue) ? queryValue[0] : queryValue);\n\n if (fromQuery !== null) {\n return fromQuery;\n }\n\n return typeof request.url === \"string\" ? tokenFromUrl(request.url) : null;\n}\n\nexport function getPreviewContent(): PreviewContent {\n const win = browserWindow() as (Window & ContentHost) | null;\n const content = win?.[CONTENT_GLOBAL_KEY];\n\n return content ? { page: content.page, entries: [...content.entries] } : { page: null, entries: [] };\n}\n\nexport function recordPreviewContent(\n item: ({ type: \"page\" } & PreviewPage) | ({ type: \"entry\" } & PreviewEntry)\n): void {\n const win = browserWindow() as (Window & ContentHost) | null;\n\n if (win === null) {\n return;\n }\n\n const content = win[CONTENT_GLOBAL_KEY] ?? { page: null, entries: [] };\n win[CONTENT_GLOBAL_KEY] = content;\n\n if (item.type === \"page\") {\n content.page = { id: item.id, slug: item.slug };\n } else if (!content.entries.some((entry) => entry.id === item.id && entry.collection === item.collection)) {\n content.entries.push({ id: item.id, collection: item.collection });\n }\n\n dispatch(PREVIEW_CONTENT_EVENT);\n}\n\nexport function resetPreviewContent(): void {\n const win = browserWindow() as (Window & ContentHost) | null;\n\n if (win !== null) {\n win[CONTENT_GLOBAL_KEY] = undefined;\n }\n}\n\n/**\n * Kept on `window` (like the shown content) so a separately bundled bridge, such\n * as the `<script>` build, sees what the site's own SDK copy recorded.\n */\nexport function getPreviewStatus(): PreviewStatus | null {\n const win = browserWindow() as (Window & Record<string, unknown>) | null;\n const status = win?.[STATUS_GLOBAL_KEY];\n\n return status === \"active\" || status === \"invalid\" ? status : null;\n}\n\nfunction setPreviewStatus(status: PreviewStatus | null): void {\n const win = browserWindow() as (Window & Record<string, unknown>) | null;\n\n if (win !== null) {\n win[STATUS_GLOBAL_KEY] = status ?? undefined;\n }\n}\n\nexport function notifyPreviewActive(): void {\n setPreviewStatus(\"active\");\n dispatch(PREVIEW_ACTIVE_EVENT);\n}\n\nexport function notifyPreviewInvalid(): void {\n setPreviewStatus(\"invalid\");\n dispatch(PREVIEW_INVALID_EVENT);\n}\n\nfunction dispatch(name: string): void {\n const win = browserWindow();\n\n if (win !== null && typeof win.dispatchEvent === \"function\") {\n win.dispatchEvent(new Event(name));\n }\n}\n", "// Generated by scripts/write-version.mjs from package.json. Do not edit.\nexport const SDK_VERSION = \"0.9.0\";\n", "export const PROTOCOL_VERSION = 1;\n\nexport type CraftyTargetType = \"block\" | \"entry\";\nexport type CraftyFieldRef = { type: CraftyTargetType; id: number; field: string };\n/** `hrefField` is the field with the link destination of the same element (same target). */\nexport type CraftyMarkedField = CraftyFieldRef & { label?: string; hrefField?: string; hrefLabel?: string };\nexport type CraftyShownPage = { id: number; slug: string };\nexport type CraftyShownEntry = { id: number; collection: string };\n\nexport type ReadyPayload = {\n sdkVersion: string;\n path: string;\n fields: CraftyMarkedField[];\n page: CraftyShownPage | null;\n entries: CraftyShownEntry[];\n};\n\ntype Version = typeof PROTOCOL_VERSION;\n\n/**\n * Keys forwarded to the admin (`crafty:key`, SDK >= 0.4.1): the admin never\n * sees keydowns while focus is inside the iframe, so Escape could not close\n * its sheets and dialogs. Older admins ignore the message.\n */\nexport type ForwardedKey = \"Escape\";\ntype EmptyPayload = Record<string, never>;\n\n/** iframe -> admin. `crafty:ready` is a snapshot that may be re-sent; the last one wins. */\nexport type OutboundMessage =\n | { v: Version; type: \"crafty:ready\"; payload: ReadyPayload }\n | { v: Version; type: \"crafty:select\"; payload: CraftyMarkedField }\n | { v: Version; type: \"crafty:navigate\"; payload: { path: string } }\n | { v: Version; type: \"crafty:preview-invalid\"; payload: EmptyPayload }\n | { v: Version; type: \"crafty:key\"; payload: { key: ForwardedKey } };\n\n/** admin -> iframe. */\nexport type InboundMessage =\n | { v: Version; type: \"crafty:token\"; payload: { token: string } }\n | { v: Version; type: \"crafty:refresh\"; payload: EmptyPayload }\n | { v: Version; type: \"crafty:highlight\"; payload: CraftyFieldRef }\n | { v: Version; type: \"crafty:preview-field\"; payload: CraftyFieldRef & { value: string } }\n | { v: Version; type: \"crafty:preview-reset\"; payload: CraftyFieldRef };\n\n/** Same limits as the Crafty admin and backend (content_drafts.field / label). */\nconst MAX_FIELD_LENGTH = 255;\nconst MAX_LABEL_LENGTH = 120;\nconst MAX_TOKEN_LENGTH = 4096;\nconst MAX_VALUE_LENGTH = 100_000;\nconst MAX_PATH_LENGTH = 2048;\nconst FIELD_PATTERN = /^[A-Za-z0-9_-]+(?:\\.[A-Za-z0-9_-]+|\\[\\d+\\])*$/;\nconst TOKEN_PATTERN = /^[\\x21-\\x7E]+$/;\nconst CONTROL_CHARACTERS = /[\\u0000-\\u001F\\u007F]/;\nconst PATH_BASE = \"https://crafty.invalid\";\n\nfunction isRecord(value: unknown): value is Record<string, unknown> {\n return typeof value === \"object\" && value !== null && !Array.isArray(value);\n}\n\nfunction isPositiveInteger(value: unknown): value is number {\n return typeof value === \"number\" && Number.isInteger(value) && value > 0;\n}\n\nfunction parseFieldPath(value: unknown): string | null {\n if (typeof value !== \"string\") {\n return null;\n }\n\n const trimmed = value.trim();\n\n return trimmed === \"\" || trimmed.length > MAX_FIELD_LENGTH || !FIELD_PATTERN.test(trimmed) ? null : trimmed;\n}\n\nfunction parseLabel(value: unknown): string {\n return typeof value === \"string\" ? value.trim().slice(0, MAX_LABEL_LENGTH).trim() : \"\";\n}\n\nexport function parseFieldRef(value: unknown): CraftyFieldRef | null {\n if (!isRecord(value)) {\n return null;\n }\n\n const { type, id } = value;\n const field = parseFieldPath(value.field);\n\n if ((type !== \"block\" && type !== \"entry\") || !isPositiveInteger(id) || field === null) {\n return null;\n }\n\n return { type, id, field };\n}\n\n/** An invalid `hrefField` is dropped; the text field stays selectable. */\nexport function parseMarkedField(value: unknown): CraftyMarkedField | null {\n const ref = parseFieldRef(value);\n\n if (ref === null || !isRecord(value)) {\n return null;\n }\n\n const marked: CraftyMarkedField = { ...ref };\n const label = parseLabel(value.label);\n const hrefField = parseFieldPath(value.hrefField);\n\n if (label !== \"\") {\n marked.label = label;\n }\n\n if (hrefField !== null) {\n marked.hrefField = hrefField;\n\n const hrefLabel = parseLabel(value.hrefLabel);\n\n if (hrefLabel !== \"\") {\n marked.hrefLabel = hrefLabel;\n }\n }\n\n return marked;\n}\n\nfunction isSameOriginPath(value: string): boolean {\n if (!value.startsWith(\"/\") || value.startsWith(\"//\") || value.startsWith(\"/\\\\\")) {\n return false;\n }\n\n try {\n const url = new URL(value, PATH_BASE);\n\n // Dot segments can still resolve to a protocol-relative path (\"/.//evil.example\").\n return url.origin === PATH_BASE && !url.pathname.startsWith(\"//\") && !url.pathname.startsWith(\"/\\\\\");\n } catch {\n return false;\n }\n}\n\nfunction parsePath(value: unknown): string | null {\n if (typeof value !== \"string\" || value.length > MAX_PATH_LENGTH || CONTROL_CHARACTERS.test(value)) {\n return null;\n }\n\n return isSameOriginPath(value) ? value : null;\n}\n\nfunction parseShownEntry(value: unknown): CraftyShownEntry | null {\n return isRecord(value) && isPositiveInteger(value.id) && typeof value.collection === \"string\"\n ? { id: value.id, collection: value.collection }\n : null;\n}\n\nfunction readEnvelope(data: unknown): { type: string; payload: Record<string, unknown> } | null {\n if (!isRecord(data) || data.v !== PROTOCOL_VERSION || typeof data.type !== \"string\") {\n return null;\n }\n\n const payload = data.payload === undefined ? {} : data.payload;\n\n return isRecord(payload) ? { type: data.type, payload } : null;\n}\n\nexport function parseInboundMessage(data: unknown): InboundMessage | null {\n const message = readEnvelope(data);\n\n if (message === null) {\n return null;\n }\n\n const { payload } = message;\n\n switch (message.type) {\n case \"crafty:token\": {\n const token = typeof payload.token === \"string\" ? payload.token.trim() : \"\";\n\n return token !== \"\" && token.length <= MAX_TOKEN_LENGTH && TOKEN_PATTERN.test(token)\n ? { v: PROTOCOL_VERSION, type: \"crafty:token\", payload: { token } }\n : null;\n }\n case \"crafty:refresh\":\n return { v: PROTOCOL_VERSION, type: \"crafty:refresh\", payload: {} };\n case \"crafty:highlight\": {\n const ref = parseFieldRef(payload);\n\n return ref ? { v: PROTOCOL_VERSION, type: \"crafty:highlight\", payload: ref } : null;\n }\n case \"crafty:preview-field\": {\n const ref = parseFieldRef(payload);\n const value = payload.value;\n\n return ref && typeof value === \"string\" && value.length <= MAX_VALUE_LENGTH\n ? { v: PROTOCOL_VERSION, type: \"crafty:preview-field\", payload: { ...ref, value } }\n : null;\n }\n case \"crafty:preview-reset\": {\n const ref = parseFieldRef(payload);\n\n return ref ? { v: PROTOCOL_VERSION, type: \"crafty:preview-reset\", payload: ref } : null;\n }\n default:\n return null;\n }\n}\n\nexport function parseOutboundMessage(data: unknown): OutboundMessage | null {\n const message = readEnvelope(data);\n\n if (message === null) {\n return null;\n }\n\n const { payload } = message;\n\n switch (message.type) {\n case \"crafty:ready\": {\n const path = parsePath(payload.path);\n const rawPage = payload.page;\n\n if (typeof payload.sdkVersion !== \"string\" || path === null || !Array.isArray(payload.fields) || !Array.isArray(payload.entries)) {\n return null;\n }\n\n return {\n v: PROTOCOL_VERSION,\n type: \"crafty:ready\",\n payload: {\n sdkVersion: payload.sdkVersion,\n path,\n fields: payload.fields\n .map((field: unknown) => parseMarkedField(field))\n .filter((field): field is CraftyMarkedField => field !== null),\n page:\n isRecord(rawPage) && isPositiveInteger(rawPage.id) && typeof rawPage.slug === \"string\"\n ? { id: rawPage.id, slug: rawPage.slug }\n : null,\n entries: payload.entries\n .map((entry: unknown) => parseShownEntry(entry))\n .filter((entry): entry is CraftyShownEntry => entry !== null)\n }\n };\n }\n case \"crafty:select\": {\n const field = parseMarkedField(payload);\n\n return field ? { v: PROTOCOL_VERSION, type: \"crafty:select\", payload: field } : null;\n }\n case \"crafty:navigate\": {\n const path = parsePath(payload.path);\n\n return path ? { v: PROTOCOL_VERSION, type: \"crafty:navigate\", payload: { path } } : null;\n }\n case \"crafty:preview-invalid\":\n return { v: PROTOCOL_VERSION, type: \"crafty:preview-invalid\", payload: {} };\n case \"crafty:key\":\n return payload.key === \"Escape\" ? { v: PROTOCOL_VERSION, type: \"crafty:key\", payload: { key: \"Escape\" } } : null;\n default:\n return null;\n }\n}\n", "import { parseMarkedField, type CraftyFieldRef, type CraftyMarkedField } from \"./protocol.js\";\n\nexport const MARKED_SELECTOR = \"[data-crafty-field]\";\n\nexport type MarkedElement = { element: Element; field: CraftyMarkedField };\n\nexport function readMarkedField(element: Element): CraftyMarkedField | null {\n const blockId = element.getAttribute(\"data-crafty-block\");\n const entryId = element.getAttribute(\"data-crafty-entry\");\n const rawId = blockId ?? entryId;\n\n if (rawId === null) {\n return null;\n }\n\n return parseMarkedField({\n type: blockId !== null ? \"block\" : \"entry\",\n id: rawId.trim() === \"\" ? Number.NaN : Number(rawId),\n field: element.getAttribute(\"data-crafty-field\") ?? \"\",\n label: element.getAttribute(\"data-crafty-label\"),\n hrefField: element.getAttribute(\"data-crafty-href-field\"),\n hrefLabel: element.getAttribute(\"data-crafty-href-label\")\n });\n}\n\nexport function refKey(ref: CraftyFieldRef): string {\n return `${ref.type}:${ref.id}:${ref.field}`;\n}\n\nexport function scanMarked(root: ParentNode): MarkedElement[] {\n const marked: MarkedElement[] = [];\n\n root.querySelectorAll(MARKED_SELECTOR).forEach((element) => {\n const field = readMarkedField(element);\n\n if (field !== null) {\n marked.push({ element, field });\n }\n });\n\n return marked;\n}\n\nexport function uniqueFields(marked: MarkedElement[]): CraftyMarkedField[] {\n const seen = new Set<string>();\n const fields: CraftyMarkedField[] = [];\n\n for (const { field } of marked) {\n const key = refKey(field);\n\n if (!seen.has(key)) {\n seen.add(key);\n fields.push(field);\n }\n }\n\n return fields;\n}\n", "import { MARKED_SELECTOR, readMarkedField, refKey } from \"./markers.js\";\nimport type { CraftyFieldRef } from \"./protocol.js\";\n\nexport type LivePreview = {\n set(ref: CraftyFieldRef, value: string): void;\n reset(ref: CraftyFieldRef): void;\n reapply(): void;\n resetAll(): void;\n readonly size: number;\n};\n\n/**\n * Plain-text live preview. Values are written with `textContent` (never HTML),\n * and each element's own original text is kept so a reset restores exactly what\n * the site rendered, even for elements rendered after the value was set.\n */\nexport function createLivePreview(root: ParentNode): LivePreview {\n const values = new Map<string, string>();\n const originals = new Map<Element, string>();\n\n const matching = (key: string): Element[] =>\n Array.from(root.querySelectorAll(MARKED_SELECTOR)).filter((element) => {\n const field = readMarkedField(element);\n\n return field !== null && refKey(field) === key;\n });\n\n const write = (element: Element, value: string): void => {\n if (!originals.has(element)) {\n originals.set(element, element.textContent ?? \"\");\n }\n\n if (element.textContent !== value) {\n element.textContent = value;\n }\n };\n\n const restore = (key: string | null): void => {\n for (const [element, original] of originals) {\n const field = readMarkedField(element);\n\n if (key === null || (field !== null && refKey(field) === key)) {\n if (element.textContent !== original) {\n element.textContent = original;\n }\n\n originals.delete(element);\n }\n }\n };\n\n return {\n set(ref, value) {\n const key = refKey(ref);\n values.set(key, value);\n matching(key).forEach((element) => write(element, value));\n },\n reset(ref) {\n const key = refKey(ref);\n values.delete(key);\n restore(key);\n },\n reapply() {\n for (const element of [...originals.keys()]) {\n if (!element.isConnected) {\n originals.delete(element);\n }\n }\n\n for (const [key, value] of values) {\n matching(key).forEach((element) => write(element, value));\n }\n },\n resetAll() {\n values.clear();\n restore(null);\n },\n get size() {\n return values.size;\n }\n };\n}\n", "/** Crafty admin panels: https://crafty.do and https://<tenant>.crafty.do. */\nexport const DEFAULT_ADMIN_ORIGINS: ReadonlyArray<string | RegExp> = [/^https:\\/\\/([a-z0-9-]+\\.)*crafty\\.do$/];\n\nfunction originOf(value: string): string | null {\n try {\n return new URL(value).origin;\n } catch {\n return null;\n }\n}\n\nexport function isAllowedAdminOrigin(origin: string, allowlist: ReadonlyArray<string | RegExp>): boolean {\n if (origin === \"\" || origin === \"null\") {\n return false;\n }\n\n return allowlist.some((allowed) => {\n if (typeof allowed === \"string\") {\n return originOf(allowed) === origin;\n }\n\n allowed.lastIndex = 0;\n\n return allowed.test(origin);\n });\n}\n\n/**\n * Origin of the embedding admin. `ancestorOrigins` (Chromium, WebKit) cannot be\n * spoofed by the framed page; Firefox falls back to the referrer the admin sent\n * when it set the iframe `src`.\n */\nexport function resolveParentOrigin(win: Window): string | null {\n const ancestors = win.location.ancestorOrigins as ArrayLike<string> | undefined;\n const first = ancestors && ancestors.length > 0 ? ancestors[0] : undefined;\n\n if (typeof first === \"string\" && first !== \"\") {\n return first;\n }\n\n const referrer = win.document.referrer;\n\n return referrer ? originOf(referrer) : null;\n}\n", "const STYLE_ELEMENT_ID = \"crafty-visual-editing-style\";\nconst ACCENT = \"#4f46e5\";\n\nexport const FLASH_CLASS = \"crafty-ve-flash\";\n\nconst STYLES = [\n \"[data-crafty-field]{cursor:pointer}\",\n `.crafty-ve-box{position:fixed;top:0;left:0;pointer-events:none;z-index:2147483647;box-sizing:border-box;border:2px solid ${ACCENT};border-radius:4px;background:rgba(79,70,229,.06)}`,\n \".crafty-ve-box[hidden]{display:none}\",\n `.crafty-ve-label{position:absolute;left:-2px;bottom:100%;margin-bottom:4px;padding:2px 8px;max-width:320px;overflow:hidden;text-overflow:ellipsis;white-space:nowrap;border-radius:4px;background:${ACCENT};color:#fff;font:500 12px/1.5 system-ui,-apple-system,sans-serif}`,\n `.${FLASH_CLASS}{outline:2px dashed ${ACCENT} !important;outline-offset:2px !important}`\n].join(\"\\n\");\n\nexport type Overlay = {\n show(element: Element, label: string): void;\n hide(): void;\n /** Re-measures the highlighted element, e.g. after its content changed. */\n reposition(): void;\n flash(elements: Element[], durationMs: number): void;\n ensureAttached(): void;\n contains(node: Node | null): boolean;\n destroy(): void;\n};\n\nexport function createOverlay(doc: Document): Overlay {\n const win = doc.defaultView;\n const style = doc.createElement(\"style\");\n style.id = STYLE_ELEMENT_ID;\n style.textContent = STYLES;\n\n const box = doc.createElement(\"div\");\n box.setAttribute(\"data-crafty-overlay\", \"\");\n box.className = \"crafty-ve-box\";\n box.hidden = true;\n\n const label = doc.createElement(\"span\");\n label.className = \"crafty-ve-label\";\n box.appendChild(label);\n\n let target: Element | null = null;\n let flashed: Element[] = [];\n let flashTimer: number | undefined;\n const Observer = (win as (Window & { ResizeObserver?: typeof ResizeObserver }) | null)?.ResizeObserver;\n\n const place = (): void => {\n if (target === null) {\n return;\n }\n\n const rect = target.getBoundingClientRect();\n box.style.top = `${rect.top}px`;\n box.style.left = `${rect.left}px`;\n box.style.width = `${rect.width}px`;\n box.style.height = `${rect.height}px`;\n };\n\n const resizeObserver = typeof Observer === \"function\" ? new Observer(() => place()) : null;\n\n const track = (element: Element | null): void => {\n if (target === element) {\n return;\n }\n\n if (target !== null) {\n resizeObserver?.unobserve(target);\n }\n\n target = element;\n\n if (target !== null) {\n resizeObserver?.observe(target);\n }\n };\n\n const clearFlash = (): void => {\n flashed.forEach((element) => element.classList.remove(FLASH_CLASS));\n flashed = [];\n\n if (flashTimer !== undefined) {\n win?.clearTimeout(flashTimer);\n flashTimer = undefined;\n }\n };\n\n const ensureAttached = (): void => {\n if (!style.isConnected) {\n (doc.head ?? doc.documentElement).appendChild(style);\n }\n\n if (!box.isConnected) {\n (doc.body ?? doc.documentElement).appendChild(box);\n }\n };\n\n ensureAttached();\n win?.addEventListener(\"scroll\", place, { capture: true, passive: true });\n win?.addEventListener(\"resize\", place, { passive: true });\n\n return {\n show(element, text) {\n ensureAttached();\n track(element);\n\n if (label.textContent !== text) {\n label.textContent = text;\n }\n\n box.hidden = false;\n place();\n },\n hide() {\n track(null);\n box.hidden = true;\n },\n reposition() {\n place();\n },\n flash(elements, durationMs) {\n clearFlash();\n flashed = [...elements];\n flashed.forEach((element) => element.classList.add(FLASH_CLASS));\n flashTimer = win?.setTimeout(clearFlash, durationMs);\n },\n ensureAttached,\n contains(node) {\n return node !== null && (box === node || box.contains(node) || style === node || style.contains(node));\n },\n destroy() {\n clearFlash();\n win?.removeEventListener(\"scroll\", place, { capture: true });\n win?.removeEventListener(\"resize\", place);\n resizeObserver?.disconnect();\n box.remove();\n style.remove();\n target = null;\n }\n };\n}\n", "import type { CraftyClient } from \"../client.js\";\nimport {\n PREVIEW_ACTIVE_EVENT,\n PREVIEW_CONTENT_EVENT,\n PREVIEW_INVALID_EVENT,\n PREVIEW_QUERY_PARAM,\n getPreviewContent,\n getPreviewStatus,\n readPreviewToken,\n storePreviewToken\n} from \"../preview.js\";\nimport { SDK_VERSION } from \"../version.js\";\nimport { createLivePreview } from \"./live-preview.js\";\nimport { MARKED_SELECTOR, readMarkedField, refKey, scanMarked, uniqueFields, type MarkedElement } from \"./markers.js\";\nimport { DEFAULT_ADMIN_ORIGINS, isAllowedAdminOrigin, resolveParentOrigin } from \"./origin.js\";\nimport { createOverlay } from \"./overlay.js\";\nimport {\n PROTOCOL_VERSION,\n parseInboundMessage,\n type CraftyFieldRef,\n type CraftyMarkedField,\n type CraftyShownEntry,\n type CraftyShownPage,\n type InboundMessage,\n type OutboundMessage\n} from \"./protocol.js\";\n\nexport type VisualEditingOptions = {\n /** Allowed admin origins. Replaces the default (`https://*.crafty.do`). */\n adminOrigins?: ReadonlyArray<string | RegExp>;\n /** Re-fetch and re-render instead of a full reload when the admin asks for a refresh. */\n onRefresh?: () => void | Promise<void>;\n /** Page rendered by the server (SSR sites, where the browser did not fetch it). */\n page?: CraftyShownPage | null;\n /** Entries rendered by the server (SSR sites). */\n entries?: CraftyShownEntry[];\n /** How long touch devices highlight every editable after load. Default 1500 ms. */\n touchHighlightMs?: number;\n /**\n * Client used to confirm the preview token when no preview request has been\n * answered yet (one `pages.list({ per_page: 1 })` call). Without it the bridge\n * waits for the site's own first Crafty request to confirm the token.\n */\n client?: Pick<CraftyClient, \"pages\">;\n};\n\nexport type VisualEditingHandle = {\n readonly active: boolean;\n disable(): void;\n};\n\nconst SCROLL_STORAGE_KEY = \"crafty:scroll-y\";\nconst RESCAN_DELAY_MS = 50;\nconst DEFAULT_TOUCH_HIGHLIGHT_MS = 1500;\nconst WATCHED_ATTRIBUTES = [\n \"data-crafty-field\",\n \"data-crafty-block\",\n \"data-crafty-entry\",\n \"data-crafty-label\",\n \"data-crafty-href-field\",\n \"data-crafty-href-label\"\n];\n\nconst inactiveHandle: VisualEditingHandle = { active: false, disable: () => undefined };\nlet activeHandle: VisualEditingHandle | null = null;\n\n/**\n * Connects the page to the Crafty visual editor. No-op unless the page runs in\n * an iframe, carries a preview token, and its parent is an allowed admin origin.\n *\n * The default allowlist (`*.crafty.do`) also covers sites hosted by Crafty, so\n * the bridge stays inert (no overlay, no listeners, no messages) until the API\n * answers a preview request with `X-Crafty-Preview-Status: active`. On `invalid`\n * it only tells the admin `crafty:preview-invalid` and stays inert.\n */\nexport function enableVisualEditing(options: VisualEditingOptions = {}): VisualEditingHandle {\n if (typeof window === \"undefined\" || typeof document === \"undefined\") {\n return inactiveHandle;\n }\n\n if (activeHandle !== null) {\n return activeHandle;\n }\n\n const win = window;\n\n if (win.parent === null || win.parent === win || readPreviewToken() === null) {\n return inactiveHandle;\n }\n\n const parentOrigin = resolveParentOrigin(win);\n\n if (parentOrigin === null || !isAllowedAdminOrigin(parentOrigin, options.adminOrigins ?? DEFAULT_ADMIN_ORIGINS)) {\n return inactiveHandle;\n }\n\n const status = getPreviewStatus();\n\n if (status === \"invalid\") {\n postPreviewInvalid(win, parentOrigin);\n\n return inactiveHandle;\n }\n\n activeHandle = status === \"active\" ? startBridge(win, parentOrigin, options) : awaitConfirmation(win, parentOrigin, options);\n\n return activeHandle;\n}\n\nfunction postPreviewInvalid(win: Window, parentOrigin: string): void {\n const message: OutboundMessage = { v: PROTOCOL_VERSION, type: \"crafty:preview-invalid\", payload: {} };\n win.parent.postMessage(message, parentOrigin);\n}\n\n/**\n * Pending handle: waits for the API to confirm the token before starting the\n * bridge, verifying it through `options.client` when one is given.\n */\nfunction awaitConfirmation(win: Window, parentOrigin: string, options: VisualEditingOptions): VisualEditingHandle {\n let bridge: VisualEditingHandle | null = null;\n let settled = false;\n\n const stopWaiting = (): void => {\n settled = true;\n win.removeEventListener(PREVIEW_ACTIVE_EVENT, onActive);\n win.removeEventListener(PREVIEW_INVALID_EVENT, onInvalid);\n };\n\n const release = (): void => {\n if (activeHandle === handle) {\n activeHandle = null;\n }\n };\n\n const onActive = (): void => {\n if (settled) {\n return;\n }\n\n stopWaiting();\n bridge = startBridge(win, parentOrigin, options, release);\n };\n\n const onInvalid = (): void => {\n if (settled) {\n return;\n }\n\n stopWaiting();\n release();\n postPreviewInvalid(win, parentOrigin);\n };\n\n const handle: VisualEditingHandle = {\n get active() {\n return bridge?.active ?? false;\n },\n disable() {\n stopWaiting();\n bridge?.disable();\n release();\n }\n };\n\n win.addEventListener(PREVIEW_ACTIVE_EVENT, onActive);\n win.addEventListener(PREVIEW_INVALID_EVENT, onInvalid);\n\n // The status handlers above settle the outcome; request errors leave the bridge waiting.\n options.client?.pages.list({ per_page: 1 }).catch(() => undefined);\n\n return handle;\n}\n\nfunction startBridge(\n win: Window,\n parentOrigin: string,\n options: VisualEditingOptions,\n onDisable?: () => void\n): VisualEditingHandle {\n const doc = win.document;\n const overlay = createOverlay(doc);\n const livePreview = createLivePreview(doc);\n const pendingScrollY = takeStoredScroll(win);\n\n let marked: MarkedElement[] = [];\n let sentSignature: string | null = null;\n let rescanTimer: number | undefined;\n let forceReady = false;\n let active = true;\n\n const post = (message: OutboundMessage): void => {\n win.parent.postMessage(message, parentOrigin);\n };\n\n const sendReady = (): void => {\n const fields = uniqueFields(marked);\n const content = getPreviewContent();\n sentSignature = signatureOf(fields);\n\n post({\n v: PROTOCOL_VERSION,\n type: \"crafty:ready\",\n payload: {\n sdkVersion: SDK_VERSION,\n path: currentPath(win),\n fields,\n page: content.page ?? options.page ?? null,\n entries: mergeEntries(content.entries, options.entries ?? [])\n }\n });\n };\n\n const rescan = (): void => {\n rescanTimer = undefined;\n\n if (!active) {\n return;\n }\n\n overlay.ensureAttached();\n marked = scanMarked(doc);\n livePreview.reapply();\n\n if (forceReady || signatureOf(uniqueFields(marked)) !== sentSignature) {\n forceReady = false;\n sendReady();\n }\n };\n\n const scheduleRescan = (): void => {\n if (active && rescanTimer === undefined) {\n rescanTimer = win.setTimeout(rescan, RESCAN_DELAY_MS);\n }\n };\n\n const observer = new MutationObserver((records) => {\n if (records.some((record) => !overlay.contains(record.target))) {\n scheduleRescan();\n }\n });\n\n const labelOf = (field: CraftyMarkedField): string => field.label ?? field.field;\n\n const onPointerOver = (event: PointerEvent): void => {\n if (event.pointerType === \"touch\") {\n return;\n }\n\n const hit = hitFrom(event.target);\n\n if (hit !== null) {\n overlay.show(hit.element, labelOf(hit.field));\n } else {\n overlay.hide();\n }\n };\n\n const block = (event: Event): void => {\n event.preventDefault();\n event.stopPropagation();\n };\n\n /**\n * Runs in the capture phase on `window`, before any site listener, so a marked\n * element always selects even when it is (or sits inside) a link or button,\n * and nothing the site renders can take the iframe out of the editor.\n */\n const onClick = (event: MouseEvent): void => {\n const hit = hitFrom(event.target);\n\n if (hit !== null) {\n block(event);\n overlay.show(hit.element, labelOf(hit.field));\n post({ v: PROTOCOL_VERSION, type: \"crafty:select\", payload: hit.field });\n\n return;\n }\n\n const action = linkAction(event, win);\n\n if (action.kind === \"allow\") {\n return;\n }\n\n block(event);\n\n if (action.kind === \"navigate\") {\n post({ v: PROTOCOL_VERSION, type: \"crafty:navigate\", payload: { path: action.path } });\n }\n };\n\n /** Middle clicks open links in a new tab: never let them leave the editor. */\n const onAuxClick = (event: MouseEvent): void => {\n if (hitFrom(event.target) !== null || closestLink(event.target) !== null) {\n block(event);\n }\n };\n\n const onSubmit = (event: Event): void => {\n block(event);\n };\n\n /**\n * Escape pressed while focus is inside the iframe never reaches the admin\n * window: forward it so the admin closes its topmost sheet or dialog. Runs in\n * the bubble phase, after the site, and skips an Escape the site handled\n * (`preventDefault`, e.g. to close its own menu).\n */\n const onKeyDown = (event: KeyboardEvent): void => {\n if (event.key !== \"Escape\" || event.repeat || event.isComposing || event.defaultPrevented) {\n return;\n }\n\n post({ v: PROTOCOL_VERSION, type: \"crafty:key\", payload: { key: \"Escape\" } });\n };\n\n const highlight = (ref: CraftyFieldRef): void => {\n const key = refKey(ref);\n const match = scanMarked(doc).find((item) => refKey(item.field) === key);\n\n if (match === undefined) {\n return;\n }\n\n const element = match.element as Element & { scrollIntoView?: (options?: ScrollIntoViewOptions) => void };\n element.scrollIntoView?.({ block: \"center\", behavior: \"smooth\" });\n overlay.show(match.element, labelOf(match.field));\n };\n\n const refresh = async (): Promise<void> => {\n if (options.onRefresh) {\n try {\n await options.onRefresh();\n } finally {\n scheduleRescan();\n }\n\n return;\n }\n\n try {\n win.sessionStorage.setItem(SCROLL_STORAGE_KEY, String(win.scrollY));\n } catch {\n // Storage blocked: reload without restoring the scroll position.\n }\n\n win.location.reload();\n };\n\n const handleInbound = (message: InboundMessage): void => {\n switch (message.type) {\n case \"crafty:token\":\n storePreviewToken(message.payload.token);\n return;\n case \"crafty:refresh\":\n refresh().catch((error: unknown) => console.error(\"[crafty] onRefresh failed\", error));\n return;\n case \"crafty:highlight\":\n highlight(message.payload);\n return;\n case \"crafty:preview-field\":\n livePreview.set(message.payload, message.payload.value);\n overlay.reposition();\n return;\n case \"crafty:preview-reset\":\n livePreview.reset(message.payload);\n overlay.reposition();\n return;\n }\n };\n\n const onMessage = (event: MessageEvent): void => {\n if (event.source !== win.parent || event.origin !== parentOrigin) {\n return;\n }\n\n const message = parseInboundMessage(event.data);\n\n if (message !== null) {\n handleInbound(message);\n }\n };\n\n const onPreviewInvalid = (): void => {\n post({ v: PROTOCOL_VERSION, type: \"crafty:preview-invalid\", payload: {} });\n };\n\n const onPreviewContent = (): void => {\n forceReady = true;\n scheduleRescan();\n };\n\n const start = (): void => {\n if (!active) {\n return;\n }\n\n marked = scanMarked(doc);\n sendReady();\n\n if (isTouchDevice(win)) {\n overlay.flash(\n marked.map((item) => item.element),\n options.touchHighlightMs ?? DEFAULT_TOUCH_HIGHLIGHT_MS\n );\n }\n\n restoreScroll(win, pendingScrollY);\n };\n\n win.addEventListener(\"message\", onMessage);\n win.addEventListener(\"click\", onClick, true);\n win.addEventListener(\"auxclick\", onAuxClick, true);\n win.addEventListener(\"submit\", onSubmit, true);\n win.addEventListener(\"keydown\", onKeyDown);\n doc.addEventListener(\"pointerover\", onPointerOver, true);\n win.addEventListener(PREVIEW_INVALID_EVENT, onPreviewInvalid);\n win.addEventListener(PREVIEW_CONTENT_EVENT, onPreviewContent);\n observer.observe(doc.documentElement, {\n childList: true,\n subtree: true,\n attributes: true,\n attributeFilter: WATCHED_ATTRIBUTES\n });\n\n if (doc.readyState === \"loading\") {\n doc.addEventListener(\"DOMContentLoaded\", start, { once: true });\n } else {\n start();\n }\n\n const handle: VisualEditingHandle = {\n get active() {\n return active;\n },\n disable() {\n if (!active) {\n return;\n }\n\n active = false;\n win.removeEventListener(\"message\", onMessage);\n win.removeEventListener(\"click\", onClick, true);\n win.removeEventListener(\"auxclick\", onAuxClick, true);\n win.removeEventListener(\"submit\", onSubmit, true);\n win.removeEventListener(\"keydown\", onKeyDown);\n doc.removeEventListener(\"pointerover\", onPointerOver, true);\n doc.removeEventListener(\"DOMContentLoaded\", start);\n win.removeEventListener(PREVIEW_INVALID_EVENT, onPreviewInvalid);\n win.removeEventListener(PREVIEW_CONTENT_EVENT, onPreviewContent);\n observer.disconnect();\n\n if (rescanTimer !== undefined) {\n win.clearTimeout(rescanTimer);\n rescanTimer = undefined;\n }\n\n livePreview.resetAll();\n overlay.destroy();\n\n if (activeHandle === handle) {\n activeHandle = null;\n }\n\n onDisable?.();\n }\n };\n\n return handle;\n}\n\nfunction asElement(target: EventTarget | null): Element | null {\n return target !== null && typeof (target as Element).closest === \"function\" ? (target as Element) : null;\n}\n\nfunction signatureOf(fields: CraftyMarkedField[]): string {\n return fields.map((field) => `${refKey(field)}|${field.label ?? \"\"}|${field.hrefField ?? \"\"}|${field.hrefLabel ?? \"\"}`).join(\"\\n\");\n}\n\nfunction mergeEntries(fetched: CraftyShownEntry[], declared: CraftyShownEntry[]): CraftyShownEntry[] {\n const seen = new Set<string>();\n\n return [...fetched, ...declared].filter((entry) => {\n const key = `${entry.collection}:${entry.id}`;\n\n if (seen.has(key)) {\n return false;\n }\n\n seen.add(key);\n\n return true;\n });\n}\n\nfunction stripPreviewParam(url: URL): string {\n url.searchParams.delete(PREVIEW_QUERY_PARAM);\n\n return `${url.pathname}${url.search}`;\n}\n\nfunction currentPath(win: Window): string {\n return stripPreviewParam(new URL(win.location.href));\n}\n\ntype LinkAction = { kind: \"allow\" } | { kind: \"block\" } | { kind: \"navigate\"; path: string };\n\n/**\n * Only links fall back to their marked descendant: following them would leave\n * the editor. Buttons, `<summary>` and labels keep their own behavior (menus,\n * accordions, tabs) when the click misses the marked element.\n */\nconst LINK_SELECTOR = \"a[href], area[href]\";\n\n/**\n * The marked element a pointer or click target maps to: the innermost valid\n * marked ancestor (or the target itself), else the first marked element inside\n * the link that was clicked, so clicking a link button's padding or icon\n * selects its label.\n */\nfunction hitFrom(target: EventTarget | null): MarkedElement | null {\n const element = asElement(target);\n\n if (element === null) {\n return null;\n }\n\n for (let node = element.closest(MARKED_SELECTOR); node !== null; node = node.parentElement?.closest(MARKED_SELECTOR) ?? null) {\n const field = readMarkedField(node);\n\n if (field !== null) {\n return { element: node, field };\n }\n }\n\n const link = element.closest(LINK_SELECTOR);\n\n return link !== null ? (scanMarked(link)[0] ?? null) : null;\n}\n\nfunction closestLink(target: EventTarget | null): Element | null {\n return asElement(target)?.closest(LINK_SELECTOR) ?? null;\n}\n\n/**\n * What to do with a click that hit no marked element. Only same-page anchors\n * run as usual; same-origin links become `crafty:navigate`; anything that\n * would leave the editor (other origins, `mailto:`/`tel:`, new tabs,\n * downloads, modified clicks) is blocked.\n */\nfunction linkAction(event: MouseEvent, win: Window): LinkAction {\n const anchor = closestLink(event.target);\n\n if (anchor === null) {\n return { kind: \"allow\" };\n }\n\n if (event.button !== 0 || event.metaKey || event.ctrlKey || event.shiftKey || event.altKey || anchor.hasAttribute(\"download\")) {\n return { kind: \"block\" };\n }\n\n const target = anchor.getAttribute(\"target\");\n\n if (target !== null && target !== \"\" && target !== \"_self\") {\n return { kind: \"block\" };\n }\n\n const href = anchor.getAttribute(\"href\") ?? \"\";\n let url: URL;\n\n try {\n url = new URL(href, win.location.href);\n } catch {\n return { kind: \"block\" };\n }\n\n if (url.origin !== win.location.origin || (url.protocol !== \"http:\" && url.protocol !== \"https:\")) {\n return { kind: \"block\" };\n }\n\n const path = stripPreviewParam(url);\n\n if ((url.hash !== \"\" || href.startsWith(\"#\")) && path === currentPath(win)) {\n return { kind: \"allow\" };\n }\n\n return { kind: \"navigate\", path };\n}\n\nfunction isTouchDevice(win: Window): boolean {\n return typeof win.matchMedia === \"function\" && win.matchMedia(\"(hover: none)\").matches;\n}\n\nfunction takeStoredScroll(win: Window): number | null {\n try {\n const raw = win.sessionStorage.getItem(SCROLL_STORAGE_KEY);\n win.sessionStorage.removeItem(SCROLL_STORAGE_KEY);\n const scrollY = raw === null ? Number.NaN : Number(raw);\n\n return Number.isFinite(scrollY) ? scrollY : null;\n } catch {\n return null;\n }\n}\n\nfunction restoreScroll(win: Window, scrollY: number | null): void {\n if (scrollY === null) {\n return;\n }\n\n const apply = (): void => win.scrollTo(0, scrollY);\n\n if (win.document.readyState === \"complete\") {\n apply();\n } else {\n win.addEventListener(\"load\", apply, { once: true });\n }\n}\n"],
5
5
  "mappings": "idAAA,IAAAA,GAAA,GAAAC,GAAAD,GAAA,sBAAAE,EAAA,UAAAC,EAAA,cAAAC,GAAA,wBAAAC,KCkCO,SAASC,GACdC,EACmD,CACnD,GAAIA,GAAW,MAAgC,OAAOA,GAAW,SAC/D,OAAO,KAGT,IAAMC,EAASD,EACTE,EAAK,OAAOD,EAAO,IAAO,SAAW,OAAOA,EAAO,GAAG,KAAK,CAAC,EAAIA,EAAO,GAE7E,OAAI,OAAOC,GAAO,UAAY,CAAC,OAAO,UAAUA,CAAE,GAAKA,GAAM,EACpD,KAGLD,EAAO,OAAS,SAAWA,EAAO,OAAS,QACtC,CAAE,KAAMA,EAAO,KAAM,GAAAC,CAAG,EAS1B,CAAE,KALP,OAAOD,EAAO,OAAU,UACxB,OAAOA,EAAO,MAAS,UACvBA,EAAO,OAAS,MAChB,SAAUA,EAEoB,QAAU,QAAS,GAAAC,CAAG,CACxD,CAOO,SAASC,EACdH,EACAI,EACAC,EAA8B,CAAC,EACT,CACtB,IAAMC,EAAWP,GAAkBC,CAAM,EACnCO,EAAkB,OAAOH,GAAU,SAAWA,EAAM,KAAK,EAAI,GAEnE,GAAIE,IAAa,MAAQC,IAAoB,GAC3C,MAAO,CA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AAI,SAAS,QAAW4F,EAAI,WAAa,SAAWA,EAAI,WAAa,SACtF,MAAO,CAAE,KAAM,OAAQ,EAGzB,IAAMS,EAAOV,GAAkBC,CAAG,EAElC,OAAKA,EAAI,OAAS,IAAMQ,EAAK,WAAW,GAAG,IAAMC,IAASzD,GAAY5C,CAAG,EAChE,CAAE,KAAM,OAAQ,EAGlB,CAAE,KAAM,WAAY,KAAAqG,CAAK,CAClC,CAEA,SAASnB,GAAclF,EAAsB,CAC3C,OAAO,OAAOA,EAAI,YAAe,YAAcA,EAAI,WAAW,eAAe,EAAE,OACjF,CAEA,SAAS4B,GAAiB5B,EAA4B,CACpD,GAAI,CACF,IAAMsG,EAAMtG,EAAI,eAAe,QAAQT,CAAkB,EACzDS,EAAI,eAAe,WAAWT,CAAkB,EAChD,IAAMgH,EAAUD,IAAQ,KAAO,OAAO,IAAM,OAAOA,CAAG,EAEtD,OAAO,OAAO,SAASC,CAAO,EAAIA,EAAU,IAC9C,MAAQ,CACN,OAAO,IACT,CACF,CAEA,SAASpB,GAAcnF,EAAauG,EAA8B,CAChE,GAAIA,IAAY,KACd,OAGF,IAAMC,EAAQ,IAAYxG,EAAI,SAAS,EAAGuG,CAAO,EAE7CvG,EAAI,SAAS,aAAe,WAC9BwG,EAAM,EAENxG,EAAI,iBAAiB,OAAQwG,EAAO,CAAE,KAAM,EAAK,CAAC,CAEtD",
6
6
  "names": ["cdn_exports", "__export", "PROTOCOL_VERSION", "attrs", "attrsHtml", "enableVisualEditing", "resolveEditTarget", "target", "record", "id", "attrs", "field", "options", "resolved", "normalizedField", "attributes", "label", "hrefField", "hrefLabel", "attrsHtml", "name", "value", "escapeAttribute", "PREVIEW_QUERY_PARAM", "PREVIEW_INVALID_EVENT", "PREVIEW_CONTENT_EVENT", "PREVIEW_ACTIVE_EVENT", "TOKEN_STORAGE_KEY", "URL_TOKEN_STORAGE_KEY", "INVALID_TOKEN_STORAGE_KEY", "CONTENT_GLOBAL_KEY", "STATUS_GLOBAL_KEY", "browserWindow", "storageGet", "key", "_a", "_b", "storageSet", "value", "normalizeToken", "value", "tokenFromUrl", "url", "PREVIEW_QUERY_PARAM", "readPreviewToken", "_a", "win", "browserWindow", "urlToken", "token", "storageGet", "URL_TOKEN_STORAGE_KEY", "storageSet", "TOKEN_STORAGE_KEY", "INVALID_TOKEN_STORAGE_KEY", "storePreviewToken", "token", "normalized", "normalizeToken", "storageSet", "TOKEN_STORAGE_KEY", "getPreviewContent", "win", "browserWindow", "content", "CONTENT_GLOBAL_KEY", "getPreviewStatus", "win", "browserWindow", "status", "STATUS_GLOBAL_KEY", "SDK_VERSION", "PROTOCOL_VERSION", "FIELD_PATTERN", "TOKEN_PATTERN", "isRecord", "value", "isPositiveInteger", "parseFieldPath", "trimmed", "FIELD_PATTERN", "parseLabel", "parseFieldRef", "type", "id", "field", "parseMarkedField", "ref", "marked", "label", "hrefField", "hrefLabel", "readEnvelope", "data", "isRecord", "payload", "parseInboundMessage", "message", "token", "TOKEN_PATTERN", "ref", "parseFieldRef", "value", "MARKED_SELECTOR", "readMarkedField", "element", "_a", "blockId", "entryId", "rawId", "parseMarkedField", "refKey", "ref", "scanMarked", "root", "marked", "field", "uniqueFields", "seen", "fields", "key", "createLivePreview", "root", "values", "originals", "matching", "key", "MARKED_SELECTOR", "element", "field", "readMarkedField", "refKey", "write", "value", "_a", "restore", "original", "ref", "DEFAULT_ADMIN_ORIGINS", "originOf", "value", "isAllowedAdminOrigin", "origin", "allowlist", "allowed", "resolveParentOrigin", "win", "ancestors", "first", "referrer", "STYLE_ELEMENT_ID", "ACCENT", "FLASH_CLASS", "STYLES", "createOverlay", "doc", "win", "style", "box", "label", "target", "flashed", "flashTimer", "Observer", "place", "rect", "resizeObserver", "track", "element", "clearFlash", "ensureAttached", "_a", "_b", "text", "elements", "durationMs", "node", "SCROLL_STORAGE_KEY", "RESCAN_DELAY_MS", "DEFAULT_TOUCH_HIGHLIGHT_MS", "WATCHED_ATTRIBUTES", "inactiveHandle", "activeHandle", "enableVisualEditing", "options", "_a", "win", "readPreviewToken", "parentOrigin", "resolveParentOrigin", "isAllowedAdminOrigin", "DEFAULT_ADMIN_ORIGINS", "status", "getPreviewStatus", "postPreviewInvalid", "startBridge", "awaitConfirmation", "message", "bridge", "settled", "stopWaiting", "PREVIEW_ACTIVE_EVENT", "onActive", "PREVIEW_INVALID_EVENT", "onInvalid", "release", "handle", "onDisable", "doc", "overlay", "createOverlay", "livePreview", "createLivePreview", "pendingScrollY", "takeStoredScroll", "marked", "sentSignature", "rescanTimer", "forceReady", "active", "post", "sendReady", "_b", "_c", "fields", "uniqueFields", "content", "getPreviewContent", "signatureOf", "SDK_VERSION", "currentPath", "mergeEntries", "rescan", "scanMarked", "scheduleRescan", "observer", "records", "record", "labelOf", "field", "onPointerOver", "event", "hit", "hitFrom", "block", "onClick", "action", "linkAction", "onAuxClick", "closestLink", "onSubmit", "onKeyDown", "highlight", "ref", "key", "refKey", "match", "item", "element", "refresh", "handleInbound", "storePreviewToken", "error", "onMessage", "parseInboundMessage", "onPreviewInvalid", "onPreviewContent", "start", "isTouchDevice", "restoreScroll", "PREVIEW_CONTENT_EVENT", "asElement", "target", "fetched", "declared", "seen", "entry", "stripPreviewParam", "url", "PREVIEW_QUERY_PARAM", "LINK_SELECTOR", "node", "MARKED_SELECTOR", "readMarkedField", "link", "anchor", "href", "path", "raw", "scrollY", "apply"]
7
7
  }
package/dist/index.d.ts CHANGED
@@ -5,12 +5,15 @@ export type { CraftyErrorCode } from "./errors.js";
5
5
  export { attrs, attrsHtml } from "./attrs.js";
6
6
  export type { CraftyAttrsOptions, CraftyEditAttributes, CraftyEditTarget, CraftyEditTargetType } from "./attrs.js";
7
7
  export { imageSrcSet, imageUrl } from "./image.js";
8
+ export { faqPage, jsonLd, serializeJsonLd, structuredData } from "./structured-data.js";
9
+ export type { FaqItem, StructuredDataSource } from "./structured-data.js";
8
10
  export { PREVIEW_HEADER, PREVIEW_INVALID_EVENT, PREVIEW_QUERY_PARAM, PREVIEW_STATUS_HEADER, clearPreviewToken, previewFromRequest, readPreviewToken, storePreviewToken } from "./preview.js";
9
11
  export type { PreviewContent, PreviewEntry, PreviewPage, PreviewRequestLike } from "./preview.js";
10
12
  export { ANALYTICS_FLAG } from "./resources/analytics.js";
11
13
  export type { AnalyticsLoadResult } from "./resources/analytics.js";
12
14
  export { ASSISTANT_FLAG } from "./resources/assistant.js";
13
15
  export type { AssistantLoadResult } from "./resources/assistant.js";
16
+ export type { CraftyFormCaptcha } from "./resources/captcha.js";
14
17
  export type { LlmsHandlerOptions, LlmsLinkTag } from "./resources/llms.js";
15
18
  export type * from "./types/public.js";
16
19
  export type * from "./types/blocks.js";
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,MAAM,aAAa,CAAC;AACjD,YAAY,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAEhD,OAAO,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAC1C,YAAY,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AAEnD,OAAO,EAAE,KAAK,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AAC9C,YAAY,EAAE,kBAAkB,EAAE,oBAAoB,EAAE,gBAAgB,EAAE,oBAAoB,EAAE,MAAM,YAAY,CAAC;AAEnH,OAAO,EAAE,WAAW,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AAEnD,OAAO,EACL,cAAc,EACd,qBAAqB,EACrB,mBAAmB,EACnB,qBAAqB,EACrB,iBAAiB,EACjB,kBAAkB,EAClB,gBAAgB,EAChB,iBAAiB,EAClB,MAAM,cAAc,CAAC;AACtB,YAAY,EAAE,cAAc,EAAE,YAAY,EAAE,WAAW,EAAE,kBAAkB,EAAE,MAAM,cAAc,CAAC;AAElG,OAAO,EAAE,cAAc,EAAE,MAAM,0BAA0B,CAAC;AAC1D,YAAY,EAAE,mBAAmB,EAAE,M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AO,EAAE,cAAc,EAAE,MAAM,0BAA0B,CAAC;AAC1D,YAAY,EAAE,mBAAmB,EAAE,MAAM,0BAA0B,CAAC;AACpE,YAAY,EAAE,iBAAiB,EAAE,MAAM,wBAAwB,CAAC;AAChE,YAAY,EAAE,kBAAkB,EAAE,WAAW,EAAE,MAAM,qBAAqB,CAAC;AAE3E,mBAAmB,mBAAmB,CAAC;AACvC,mBAAmB,mBAAmB,CAAC"}
package/dist/index.js CHANGED
@@ -2,6 +2,7 @@ export { createCraftyClient } from "./client.js";
2
2
  export { CraftyError } from "./errors.js";
3
3
  export { attrs, attrsHtml } from "./attrs.js";
4
4
  export { imageSrcSet, imageUrl } from "./image.js";
5
+ export { faqPage, jsonLd, serializeJsonLd, structuredData } from "./structured-data.js";
5
6
  export { PREVIEW_HEADER, PREVIEW_INVALID_EVENT, PREVIEW_QUERY_PARAM, PREVIEW_STATUS_HEADER, clearPreviewToken, previewFromRequest, readPreviewToken, storePreviewToken } from "./preview.js";
6
7
  export { ANALYTICS_FLAG } from "./resources/analytics.js";
7
8
  export { ASSISTANT_FLAG } from "./resources/assistant.js";
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,MAAM,aAAa,CAAC;AAGjD,OAAO,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAG1C,OAAO,EAAE,KAAK,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AAG9C,OAAO,EAAE,WAAW,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AAEnD,OAAO,EACL,cAAc,EACd,qBAAqB,EACrB,mBAAmB,EACnB,qBAAqB,EACrB,iBAAiB,EACjB,kBAAkB,EAClB,gBAAgB,EAChB,iBAAiB,EAClB,MAAM,cAAc,CAAC;AAGtB,OAAO,EAAE,cAAc,EAAE,MAAM,0BAA0B,CAAC;AAE1D,OAAO,EAAE,cAAc,EAAE,MAAM,0BAA0B,CAAC"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,MAAM,aAAa,CAAC;AAGjD,OAAO,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAG1C,OAAO,EAAE,KAAK,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AAG9C,OAAO,EAAE,WAAW,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AAEnD,OAAO,EAAE,OAAO,EAAE,MAAM,EAAE,eAAe,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAC;AAGxF,OAAO,EACL,cAAc,EACd,qBAAqB,EACrB,mBAAmB,EACnB,qBAAqB,EACrB,iBAAiB,EACjB,kBAAkB,EAClB,gBAAgB,EAChB,iBAAiB,EAClB,MAAM,cAAc,CAAC;AAGtB,OAAO,EAAE,cAAc,EAAE,MAAM,0BAA0B,CAAC;AAE1D,OAAO,EAAE,cAAc,EAAE,MAAM,0BAA0B,CAAC"}
@@ -0,0 +1,20 @@
1
+ import type { CraftyFormCaptchaConfig } from "../types/public.js";
2
+ /** A rendered captcha widget whose token goes with one form submission. */
3
+ export type CraftyFormCaptcha = {
4
+ provider: CraftyFormCaptchaConfig["provider"];
5
+ /** Request field the token is posted in. */
6
+ field: string;
7
+ /** Runs the challenge (invisible for Turnstile) and resolves with a fresh token. */
8
+ token(): Promise<string>;
9
+ /** Clears the widget so the next submission gets a new token. */
10
+ reset(): void;
11
+ /** Removes the widget from the page. */
12
+ remove(): void;
13
+ };
14
+ /**
15
+ * Renders the form's captcha widget into `container`. Turnstile runs
16
+ * invisibly and only shows a challenge when Cloudflare is unsure of the
17
+ * visitor; hCaptcha shows its checkbox.
18
+ */
19
+ export declare function renderCaptcha(config: CraftyFormCaptchaConfig, container: HTMLElement): Promise<CraftyFormCaptcha>;
20
+ //# sourceMappingURL=captcha.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"captcha.d.ts","sourceRoot":"","sources":["../../src/resources/captcha.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,oBAAoB,CAAC;AAElE,2EAA2E;AAC3E,MAAM,MAAM,iBAAiB,GAAG;IAC9B,QAAQ,EAAE,uBAAuB,CAAC,UAAU,CAAC,CAAC;IAC9C,4CAA4C;IAC5C,KAAK,EAAE,MAAM,CAAC;IACd,oFAAoF;IACpF,KAAK,IAAI,OAAO,CAAC,MAAM,CAAC,CAAC;IACzB,iEAAiE;IACjE,KAAK,IAAI,IAAI,CAAC;IACd,wCAAwC;IACxC,MAAM,IAAI,IAAI,CAAC;CAChB,CAAC;AAyDF;;;;GAIG;AACH,wBAAsB,aAAa,CAAC,MAAM,EAAE,uBAAuB,EAAE,SAAS,EAAE,WAAW,GAAG,OAAO,CAAC,iBAAiB,CAAC,CAmEvH"}
@@ -0,0 +1,100 @@
1
+ import { CraftyError } from "../errors.js";
2
+ const SCRIPTS = {
3
+ turnstile: "https://challenges.cloudflare.com/turnstile/v0/api.js?render=explicit",
4
+ hcaptcha: "https://js.hcaptcha.com/1/api.js?render=explicit"
5
+ };
6
+ const loading = new Map();
7
+ function loadApi(provider) {
8
+ const win = window;
9
+ const ready = win[provider];
10
+ if (ready) {
11
+ return Promise.resolve(ready);
12
+ }
13
+ const pending = loading.get(provider);
14
+ if (pending) {
15
+ return pending;
16
+ }
17
+ const promise = new Promise((resolve, reject) => {
18
+ const script = document.createElement("script");
19
+ script.src = SCRIPTS[provider];
20
+ script.async = true;
21
+ script.dataset.craftyCaptcha = provider;
22
+ script.addEventListener("load", () => {
23
+ const api = window[provider];
24
+ if (api) {
25
+ resolve(api);
26
+ }
27
+ else {
28
+ reject(new Error(`${provider} script loaded without its API.`));
29
+ }
30
+ });
31
+ script.addEventListener("error", () => reject(new Error(`Could not load the ${provider} script.`)));
32
+ document.head.appendChild(script);
33
+ });
34
+ promise.catch(() => loading.delete(provider));
35
+ loading.set(provider, promise);
36
+ return promise;
37
+ }
38
+ /**
39
+ * Renders the form's captcha widget into `container`. Turnstile runs
40
+ * invisibly and only shows a challenge when Cloudflare is unsure of the
41
+ * visitor; hCaptcha shows its checkbox.
42
+ */
43
+ export async function renderCaptcha(config, container) {
44
+ if (typeof window === "undefined" || typeof document === "undefined") {
45
+ throw new CraftyError({ code: "BAD_REQUEST", message: "The form captcha can only be rendered in a browser." });
46
+ }
47
+ let api;
48
+ try {
49
+ api = await loadApi(config.provider);
50
+ }
51
+ catch (cause) {
52
+ throw new CraftyError({ code: "NETWORK_ERROR", message: `Could not load the ${config.provider} captcha.`, cause });
53
+ }
54
+ let waiting = null;
55
+ const settle = (token, error) => {
56
+ const current = waiting;
57
+ waiting = null;
58
+ if (current && token) {
59
+ current.resolve(token);
60
+ }
61
+ else if (current) {
62
+ current.reject(error ?? new Error("Captcha failed."));
63
+ }
64
+ };
65
+ const params = {
66
+ sitekey: config.site_key,
67
+ callback: (token) => settle(token),
68
+ "error-callback": () => settle(null, new Error("Captcha failed.")),
69
+ "expired-callback": () => api.reset(widgetId)
70
+ };
71
+ if (config.provider === "turnstile") {
72
+ params.execution = "execute";
73
+ params.appearance = "interaction-only";
74
+ }
75
+ const widgetId = api.render(container, params);
76
+ return {
77
+ provider: config.provider,
78
+ field: config.token_field,
79
+ token() {
80
+ const existing = api.getResponse(widgetId);
81
+ if (existing) {
82
+ return Promise.resolve(existing);
83
+ }
84
+ if (config.provider === "hcaptcha") {
85
+ return Promise.reject(new CraftyError({ code: "BAD_REQUEST", message: "Complete the captcha before submitting." }));
86
+ }
87
+ return new Promise((resolve, reject) => {
88
+ waiting = { resolve, reject };
89
+ api.execute(widgetId);
90
+ });
91
+ },
92
+ reset() {
93
+ api.reset(widgetId);
94
+ },
95
+ remove() {
96
+ api.remove(widgetId);
97
+ }
98
+ };
99
+ }
100
+ //# sourceMappingURL=captcha.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"captcha.js","sourceRoot":"","sources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,OAAO,GAAG,EAAE,OAAO,EAAE,MAAM,EAAE,CAAC;gBAC9B,GAAG,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC;YACxB,CAAC,CAAC,CAAC;QACL,CAAC;QACD,KAAK;YACH,GAAG,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAC;QACtB,CAAC;QACD,MAAM;YACJ,GAAG,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC;QACvB,CAAC;KACF,CAAC;AACJ,CAAC"}
@@ -1,10 +1,19 @@
1
1
  import { HttpClient } from "../http.js";
2
- import type { FormListResponse, FormShowResponse, FormSubmitData, FormSubmitResponse, RequestOptions } from "../types/public.js";
2
+ import type { CraftyFormCaptcha } from "./captcha.js";
3
+ import type { CraftyForm, FormListResponse, FormShowResponse, FormSubmitData, FormSubmitResponse, RequestOptions } from "../types/public.js";
3
4
  export declare class FormsResource {
4
5
  private readonly http;
5
6
  constructor(http: HttpClient);
6
7
  list(options?: RequestOptions): Promise<FormListResponse>;
7
8
  get(slug: string, options?: RequestOptions): Promise<FormShowResponse>;
8
- submit(formSlug: string, data: FormSubmitData, options?: RequestOptions): Promise<FormSubmitResponse>;
9
+ /**
10
+ * Renders the form's captcha widget into `container` and resolves with it,
11
+ * or with null when the form needs no captcha. Pass it to `submit()` as
12
+ * `{ captcha }` and its token goes with the submission. Browser only.
13
+ */
14
+ captcha(form: Pick<CraftyForm, "captcha">, container: HTMLElement): Promise<CraftyFormCaptcha | null>;
15
+ submit(formSlug: string, data: FormSubmitData, options?: RequestOptions & {
16
+ captcha?: CraftyFormCaptcha | null;
17
+ }): Promise<FormSubmitResponse>;
9
18
  }
10
19
  //# sourceMappingURL=forms.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"forms.d.ts","sourceRoot":"","sources":["../../src/resources/forms.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AACxC,OAAO,KAAK,EACV,gBAAgB,EAChB,gBAAgB,EAChB,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AC,EAAE,cAAc,GAAG;QAAE,OAAO,CAAC,EAAE,iBAAiB,GAAG,IAAI,CAAA;KAAE,GAChE,OAAO,CAAC,kBAAkB,CAAC;CAuB/B"}
@@ -1,4 +1,5 @@
1
1
  import { CraftyError } from "../errors.js";
2
+ import { renderCaptcha } from "./captcha.js";
2
3
  export class FormsResource {
3
4
  http;
4
5
  constructor(http) {
@@ -10,6 +11,17 @@ export class FormsResource {
10
11
  get(slug, options) {
11
12
  return this.http.get(`/forms/${encodeURIComponent(slug)}`, this.http.withLocale(options));
12
13
  }
14
+ /**
15
+ * Renders the form's captcha widget into `container` and resolves with it,
16
+ * or with null when the form needs no captcha. Pass it to `submit()` as
17
+ * `{ captcha }` and its token goes with the submission. Browser only.
18
+ */
19
+ async captcha(form, container) {
20
+ if (!form.captcha) {
21
+ return null;
22
+ }
23
+ return renderCaptcha(form.captcha, container);
24
+ }
13
25
  async submit(formSlug, data, options) {
14
26
  const siteSlug = this.http.getSiteSlug();
15
27
  if (!siteSlug) {
@@ -18,7 +30,14 @@ export class FormsResource {
18
30
  message: "siteSlug is required in client config to submit forms."
19
31
  });
20
32
  }
21
- return this.http.post(`/sites/${encodeURIComponent(siteSlug)}/forms/${encodeURIComponent(formSlug)}/submit`, data, this.http.withLocale(options));
33
+ const { captcha, ...requestOptions } = options ?? {};
34
+ const body = captcha ? { ...data, [captcha.field]: await captcha.token() } : data;
35
+ try {
36
+ return await this.http.post(`/sites/${encodeURIComponent(siteSlug)}/forms/${encodeURIComponent(formSlug)}/submit`, body, this.http.withLocale(requestOptions));
37
+ }
38
+ finally {
39
+ captcha?.reset();
40
+ }
22
41
  }
23
42
  }
24
43
  //# sourceMappingURL=forms.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"forms.js","sourceRoot":"","sources":["../../src/resources/forms.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AAU3C,MAAM,OAAO,aAAa;IACY;IAApC,YAAoC,IAAgB;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,CAAC,IAAI,CAAC,UAAU,CAAC,cAAc,CAAC,CACrC,CAAC;QACJ,CAAC;gBAAS,CAAC;YACT,OAAO,EAAE,KAAK,EAAE,CAAC;QACnB,CAAC;IACH,CAAC;CACF"}
@@ -0,0 +1,12 @@
1
+ import type { HttpClient } from "../http.js";
2
+ import type { CraftySite, RequestOptions } from "../types/public.js";
3
+ export declare class SiteResource {
4
+ private readonly http;
5
+ constructor(http: HttpClient);
6
+ /**
7
+ * The site of the API key: name, locales and the business JSON-LD in
8
+ * `structured_data` (render it with `crafty.structuredData(site)`).
9
+ */
10
+ get(options?: RequestOptions): Promise<CraftySite>;
11
+ }
12
+ //# sourceMappingURL=site.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"site.d.ts","sourceRoot":"","sources":["../../src/resources/site.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AAC7C,OAAO,KAAK,EAAE,UAAU,EAAsB,cAAc,EAAE,MAAM,oBAAoB,CAAC;AAEzF,qBAAa,YAAY;IACJ,OAAO,CAAC,QAAQ,CAAC,IAAI;gBAAJ,IAAI,EAAE,UAAU;IAEpD;;;OAGG;IACU,GAAG,CAAC,OAAO,CAAC,EAAE,cAAc,GAAG,OAAO,CAAC,UAAU,CAAC;CAKhE"}
@@ -0,0 +1,15 @@
1
+ export class SiteResource {
2
+ http;
3
+ constructor(http) {
4
+ this.http = http;
5
+ }
6
+ /**
7
+ * The site of the API key: name, locales and the business JSON-LD in
8
+ * `structured_data` (render it with `crafty.structuredData(site)`).
9
+ */
10
+ async get(options) {
11
+ const response = await this.http.get("/site", options);
12
+ return response.data;
13
+ }
14
+ }
15
+ //# sourceMappingURL=site.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"site.js","sourceRoot":"","sources":["../../src/resources/site.ts"],"names":[],"mappings":"AAGA,MAAM,OAAO,YAAY;IACa;IAApC,YAAoC,IAAgB;QAAhB,SAAI,GAAJ,IAAI,CAAY;IAAG,CAAC;IAExD;;;OAGG;IACI,KAAK,CAAC,GAAG,CAAC,OAAwB;QACvC,MAAM,QAAQ,GAAG,MAAM,IAAI,CAAC,IAAI,CAAC,GAAG,CAAqB,OAAO,EAAE,OAAO,CAAC,CAAC;QAE3E,OAAO,QAAQ,CAAC,IAAI,CAAC;IACvB,CAAC;CACF"}
@@ -0,0 +1,41 @@
1
+ import type { CraftyJsonLd } from "./types/public.js";
2
+ /**
3
+ * Anything that carries schema.org JSON-LD: a page or entry (or its API
4
+ * response), a list response, the site, a JSON-LD object, or a list of them.
5
+ */
6
+ export type StructuredDataSource = CraftyJsonLd | {
7
+ structured_data?: CraftyJsonLd | null;
8
+ } | {
9
+ data: unknown;
10
+ } | null | undefined | readonly StructuredDataSource[];
11
+ export type FaqItem = {
12
+ question?: string | null;
13
+ answer?: string | null;
14
+ };
15
+ /**
16
+ * The JSON-LD objects found in the sources, in order. FAQPage objects are
17
+ * merged into one, since Google reads a single FAQPage per page: pass every
18
+ * FAQ entry of a list and get one FAQPage with all the questions.
19
+ */
20
+ export declare function jsonLd(...sources: StructuredDataSource[]): CraftyJsonLd[];
21
+ /**
22
+ * `<script type="application/ld+json">` tags for the sources, ready to put
23
+ * in `<head>` (or anywhere in `<body>`); "" when none carries JSON-LD.
24
+ *
25
+ * ```ts
26
+ * const page = await crafty.pages.get("home");
27
+ * head += crafty.structuredData(page); // LocalBusiness of the site
28
+ * ```
29
+ */
30
+ export declare function structuredData(...sources: StructuredDataSource[]): string;
31
+ /**
32
+ * FAQPage JSON-LD for questions that live in a page block (a repeater of
33
+ * question / answer), or null when no item has both.
34
+ */
35
+ export declare function faqPage(items: readonly FaqItem[] | null | undefined): CraftyJsonLd | null;
36
+ /**
37
+ * JSON for inside a `<script>` element: `<` is escaped so content can never
38
+ * close the tag, and U+2028/U+2029 so old parsers read it as JavaScript too.
39
+ */
40
+ export declare function serializeJsonLd(value: CraftyJsonLd): string;
41
+ //# sourceMappingURL=structured-data.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"structured-data.d.ts","sourceRoot":"","sources":["../src/structured-data.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AAEtD;;;GAGG;AACH,MAAM,MAAM,oBAAoB,GAC5B,YAAY,GACZ;IAAE,eAAe,CAAC,EAAE,YAAY,GAAG,IAAI,CAAA;CAAE,GACzC;IAAE,IAAI,EAAE,OAAO,CAAA;CAAE,GACjB,IAAI,GACJ,SAAS,GACT,SAAS,oBAAoB,EAAE,CAAC;AAEpC,MAAM,MAAM,OAAO,GAAG;IAAE,QAAQ,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IAAC,MAAM,CAAC,EAAE,MAAM,GAAG,IAAI,CAAA;CAAE,CAAC;AAE3E;;;;GAIG;AACH,wBAAgB,MAAM,CAAC,GAAG,OAAO,EAAE,oBAAoB,EAAE,GAAG,YAAY,EAAE,CAiBzE;AAED;;;;;;;;GAQG;AACH,wBAAgB,cAAc,CAAC,GAAG,OAAO,EAAE,oBAAoB,EAAE,GAAG,MAAM,CAIzE;AAED;;;GAGG;AACH,wBAAgB,OAAO,CAAC,KAAK,EAAE,SAAS,OAAO,EAAE,GAAG,IAAI,GAAG,SAAS,GAAG,YAAY,GAAG,IAAI,CAWzF;AAED;;;GAGG;AACH,wBAAgB,eAAe,CAAC,KAAK,EAAE,YAAY,GAAG,MAAM,CAK3D"}
@@ -0,0 +1,91 @@
1
+ /**
2
+ * The JSON-LD objects found in the sources, in order. FAQPage objects are
3
+ * merged into one, since Google reads a single FAQPage per page: pass every
4
+ * FAQ entry of a list and get one FAQPage with all the questions.
5
+ */
6
+ export function jsonLd(...sources) {
7
+ const found = [];
8
+ collect(sources, found, 0);
9
+ const faqs = found.filter((item) => item["@type"] === "FAQPage");
10
+ const first = faqs[0];
11
+ if (first === undefined || faqs.length < 2) {
12
+ return found;
13
+ }
14
+ const merged = {
15
+ ...first,
16
+ mainEntity: faqs.flatMap((faq) => (Array.isArray(faq.mainEntity) ? faq.mainEntity : faq.mainEntity ? [faq.mainEntity] : []))
17
+ };
18
+ return found.flatMap((item) => (item === first ? [merged] : faqs.includes(item) ? [] : [item]));
19
+ }
20
+ /**
21
+ * `<script type="application/ld+json">` tags for the sources, ready to put
22
+ * in `<head>` (or anywhere in `<body>`); "" when none carries JSON-LD.
23
+ *
24
+ * ```ts
25
+ * const page = await crafty.pages.get("home");
26
+ * head += crafty.structuredData(page); // LocalBusiness of the site
27
+ * ```
28
+ */
29
+ export function structuredData(...sources) {
30
+ return jsonLd(...sources)
31
+ .map((item) => `<script type="application/ld+json">${serializeJsonLd(item)}</script>`)
32
+ .join("\n");
33
+ }
34
+ /**
35
+ * FAQPage JSON-LD for questions that live in a page block (a repeater of
36
+ * question / answer), or null when no item has both.
37
+ */
38
+ export function faqPage(items) {
39
+ const questions = (items ?? [])
40
+ .map((item) => ({ question: text(item?.question), answer: text(item?.answer) }))
41
+ .filter((item) => item.question !== "" && item.answer !== "")
42
+ .map((item) => ({
43
+ "@type": "Question",
44
+ name: item.question,
45
+ acceptedAnswer: { "@type": "Answer", text: item.answer }
46
+ }));
47
+ return questions.length > 0 ? { "@context": "https://schema.org", "@type": "FAQPage", mainEntity: questions } : null;
48
+ }
49
+ /**
50
+ * JSON for inside a `<script>` element: `<` is escaped so content can never
51
+ * close the tag, and U+2028/U+2029 so old parsers read it as JavaScript too.
52
+ */
53
+ export function serializeJsonLd(value) {
54
+ return JSON.stringify(value)
55
+ .replace(/</g, "\\u003c")
56
+ .replace(/\u2028/g, "\\u2028")
57
+ .replace(/\u2029/g, "\\u2029");
58
+ }
59
+ const MAX_DEPTH = 4;
60
+ function collect(source, found, depth) {
61
+ if (source === null || source === undefined || depth > MAX_DEPTH) {
62
+ return;
63
+ }
64
+ if (Array.isArray(source)) {
65
+ for (const item of source) {
66
+ collect(item, found, depth + 1);
67
+ }
68
+ return;
69
+ }
70
+ if (typeof source !== "object") {
71
+ return;
72
+ }
73
+ const record = source;
74
+ if (typeof record["@type"] === "string" || Array.isArray(record["@type"])) {
75
+ if (!found.includes(record)) {
76
+ found.push(record);
77
+ }
78
+ return;
79
+ }
80
+ if ("structured_data" in record) {
81
+ collect(record.structured_data, found, depth + 1);
82
+ return;
83
+ }
84
+ if ("data" in record) {
85
+ collect(record.data, found, depth + 1);
86
+ }
87
+ }
88
+ function text(value) {
89
+ return typeof value === "string" ? value.trim() : "";
90
+ }
91
+ //# sourceMappingURL=structured-data.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"structured-data.js","sourceRoot":"","sources":["../src/structured-data.ts"],"names":[],"mappings":"AAgBA;;;;GAIG;AACH,MAAM,UAAU,MAAM,CAAC,GAAG,OAA+B;IACvD,MAAM,KAAK,GAAmB,EAAE,CAAC;IACjC,OAAO,CAAC,OAAO,EAAE,KAAK,EAAE,CAAC,CAAC,CAAC;IAE3B,MAAM,IAAI,GAAG,KAAK,CAAC,MAAM,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,OAAO,CAAC,KAAK,SAAS,CAAC,CAAC;IACjE,MAAM,KAAK,GAAG,IAAI,CAAC,CAAC,CAAC,CAAC;IAEtB,IAAI,KAAK,KAAK,SAAS,IAAI,IAAI,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;QAC3C,OAAO,KAAK,CAAC;IACf,CAAC;IAED,MAAM,MAAM,GAAiB;QAC3B,GAAG,KAAK;QACR,UAAU,EAAE,IAAI,CAAC,OAAO,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,GAAG,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,UAAU,CAAC,CAAC,CAAC,GAAG,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC;KAC7H,CAAC;IAEF,OAAO,KAAK,CAAC,OAAO,CAAC,CAA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,CAAC,CAAC;QAElD,OAAO;IACT,CAAC;IAED,IAAI,MAAM,IAAI,MAAM,EAAE,CAAC;QACrB,OAAO,CAAC,MAAM,CAAC,IAAI,EAAE,KAAK,EAAE,KAAK,GAAG,CAAC,CAAC,CAAC;IACzC,CAAC;AACH,CAAC;AAED,SAAS,IAAI,CAAC,KAAc;IAC1B,OAAO,OAAO,KAAK,KAAK,QAAQ,CAAC,CAAC,CAAC,KAAK,CAAC,IAAI,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;AACvD,CAAC"}
@@ -50,6 +50,12 @@ export type CraftyEntry = {
50
50
  status: "draft" | "published";
51
51
  published_at: string | null;
52
52
  display_title: string;
53
+ /**
54
+ * schema.org JSON-LD of the entry, present when its collection has a
55
+ * structured data mapping (null when a required property is empty).
56
+ * Render it with `crafty.structuredData(entry)`.
57
+ */
58
+ structured_data?: CraftyJsonLd | null;
53
59
  [key: string]: string | number | boolean | null | Record<string, unknown> | Array<unknown>;
54
60
  };
55
61
  export type CraftyPage = {
@@ -62,10 +68,32 @@ export type CraftyPage = {
62
68
  seo_title: string | null;
63
69
  seo_description: string | null;
64
70
  seo_image_id: number | null;
71
+ /**
72
+ * `pages.get()` only: the business JSON-LD on the home page, null on the
73
+ * others. Render it with `crafty.structuredData(page)`.
74
+ */
75
+ structured_data?: CraftyJsonLd | null;
65
76
  created_at: string | null;
66
77
  updated_at: string | null;
67
78
  blocks?: CraftyBlock[];
68
79
  };
80
+ /** A schema.org JSON-LD object (`@context`, `@type` and its properties). */
81
+ export type CraftyJsonLd = {
82
+ "@context"?: string;
83
+ "@type": string | string[];
84
+ [key: string]: unknown;
85
+ };
86
+ export type CraftySite = {
87
+ name: string;
88
+ slug: string;
89
+ /** Environment of the API key, e.g. "production". */
90
+ environment: string;
91
+ default_locale: string | null;
92
+ locales: string[];
93
+ /** Business JSON-LD (LocalBusiness, Organization…); null until the business data is filled in. */
94
+ structured_data: CraftyJsonLd | null;
95
+ };
96
+ export type CraftySiteResponse = SingleResponse<CraftySite>;
69
97
  export type CraftyMediaCollectionStats = {
70
98
  files_count: number;
71
99
  total_bytes: number;
@@ -274,10 +302,19 @@ export type CraftyForm = {
274
302
  success_message?: string;
275
303
  fields: Record<string, CraftyFormField>;
276
304
  status: "draft" | "published";
305
+ /** Whether submissions need a captcha token. Kept for older clients; read `captcha`. */
277
306
  hcaptcha_enabled: boolean;
307
+ /** The captcha widget to render. Present only when submissions need a captcha token. */
308
+ captcha?: CraftyFormCaptchaConfig;
278
309
  created_at: string;
279
310
  updated_at: string;
280
311
  };
312
+ export type CraftyFormCaptchaConfig = {
313
+ provider: "turnstile" | "hcaptcha";
314
+ site_key: string;
315
+ /** Request field the widget token is posted in. */
316
+ token_field: string;
317
+ };
281
318
  export type CraftyFormField = {
282
319
  label: string;
283
320
  type: "text" | "textarea" | "email" | "tel" | "number" | "select" | "checkbox" | "radio" | "date";
@@ -1 +1 @@
1
- {"version":3,"file":"public.d.ts","sourceRoot":"","sources":["../../src/types/public.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAA+C,MAAM,aAAa,CAAC;AAE5F,YAAY,EACV,WAAW,EACX,sBAAsB,EACtB,mBAAmB,EACpB,MAAM,aAAa,CAAC;AAErB,4DAA4D;AAC5D,MAAM,MAAM,eAAe,GACvB,QAAQ,GACR,MAAM,GACN,UAAU,GACV,KAAK,GACL,QAAQ,GACR,SAAS,GACT,SAAS,GACT,UAAU,GACV,QAAQ,GACR,MAAM,GACN,WAAW,GACX,gBAAgB,GAChB,YAAY,GACZ,UAAU,CAAC;AAEf,4EAA4E;AAC5E,MAAM,MAAM,kBAAkB,GAAG,MAAM,GAAG;IAAE,KAAK,EAAE,MAAM,CAAC;IAAC,KAAK,CAAC,EAAE,MAAM,CAAA;CAAE,CAAC;AAE5E;;;;;;GAMG;AACH,MAAM,MAAM,qBAAqB,GAAG;IAClC,IAAI,CAAC,EAAE,eAAe,GAAG,CAAC,MAAM,GAAG,EAAE,CAAC,CAAC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
- export declare const SDK_VERSION = "0.8.0";
1
+ export declare const SDK_VERSION = "0.9.0";
2
2
  //# sourceMappingURL=version.d.ts.map
package/dist/version.js CHANGED
@@ -1,3 +1,3 @@
1
1
  // Generated by scripts/write-version.mjs from package.json. Do not edit.
2
- export const SDK_VERSION = "0.8.0";
2
+ export const SDK_VERSION = "0.9.0";
3
3
  //# sourceMappingURL=version.js.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@craftware/crafty-sdk",
3
- "version": "0.8.0",
3
+ "version": "0.9.0",
4
4
  "private": false,
5
5
  "type": "module",
6
6
  "sideEffects": false,
@@ -8,6 +8,12 @@ metadata:
8
8
 
9
9
  # Crafty CMS (MCP + JavaScript SDK)
10
10
 
11
+ > **MCP prompt: `build-site`.** It takes a site from a business description to a published website: content model, pages, frontend with the SDK, preview and deploy, confirming the plan with you before it writes. Arguments: `description` (the business and what the site needs) and optionally `site_id` (an existing site). Needs a token with `crafty:write`.
12
+ >
13
+ > In Claude Code, type `/` and pick `mcp__<server>__build-site`, where `<server>` is the name you gave the Crafty server; other clients list it in their prompt menu. If your client does not show MCP prompts, ask the agent to call `get_guide getting-started` and follow it.
14
+ >
15
+ > Redesigning a client's existing site? The `redesign-site` prompt reads their current site and social media and proposes the new one before building it (see `get_guide migrate`).
16
+
11
17
  Crafty is a headless, multi-tenant CMS. There are two integration surfaces, and they are used at different stages:
12
18
 
13
19
  | Surface | Purpose | Auth | Use it to |
@@ -34,13 +40,13 @@ npm create crafty@latest mi-sitio -- --url=https://<tenant>.crafty.do
34
40
  # same flow: npx @craftware/crafty-cli create mi-sitio --url=https://<tenant>.crafty.do
35
41
  ```
36
42
 
37
- It asks for the framework and template (today: Astro, `astro-services` = "sitio de servicios"; Next.js and Nuxt are coming), logs in through the browser (device flow; the user approves, an admin account is needed), creates the site with the starter's block types, collections, form and demo content, configures the visual editor routes, and writes `.env` (`CRAFTY_API_URL`, `CRAFTY_API_KEY`, `CRAFTY_SITE`), `crafty.json` and `src/crafty.types.ts`. Then:
43
+ It asks for the framework and template (today: Astro, `astro-services` = "sitio de servicios" or `astro-docs` = "documentación"; Next.js and Nuxt are coming), logs in through the browser (device flow; the user approves, an admin account is needed), creates the site with the starter's block types, collections, form and demo content, configures the visual editor routes, and writes `.env` (`CRAFTY_API_URL`, `CRAFTY_API_KEY`, `CRAFTY_SITE`), `crafty.json` and `src/crafty.types.ts`. Then:
38
44
 
39
45
  ```bash
40
46
  cd mi-sitio && npm install && npm run dev # npm run deploy → Crafty Hosting
41
47
  ```
42
48
 
43
- - Flags (after `--`): `--url`, `--framework=astro`, `--template=astro-services`, `--name`, `--site=<slug>`, `--draft` (keep demo content as drafts; by default it is published so the static build shows it), `--yes` (no prompts). Agents should pass `--url` and `--yes` so nothing blocks on a prompt; the browser approval still needs the user.
49
+ - Flags (after `--`): `--url`, `--framework=astro`, `--template=astro-services|astro-docs`, `--name`, `--site=<slug>`, `--draft` (keep demo content as drafts; by default it is published so the static build shows it), `--yes` (no prompts). Agents should pass `--url` and `--yes` so nothing blocks on a prompt; the browser approval still needs the user.
44
50
  - The command is interactive only for the login: tell the user to open the printed URL and approve the code.
45
51
  - After it finishes, **read the project's `AGENTS.md`** and follow its conventions (one renderer per block type in `src/render/blocks/`, routes in `src/lib/routes.ts`, `npm run types` after changing the content model) instead of the generic steps in Phase 2.
46
52
  - If the site slug already exists it fails before creating anything; if provisioning fails midway it names the half-created site: delete it in the panel or rerun with another `--site`.
@@ -163,6 +169,8 @@ Serving `llms.txt` / `llms-full.txt` for AI agents and crawlers: `crafty.llms.ha
163
169
 
164
170
  Analytics and ad pixels (Google Tag Manager, GA4, Meta Pixel, TikTok Pixel): do **not** hard-code their snippets into the site. Set the IDs on the "Analítica" admin screen or with the `configure_analytics` MCP tool; Crafty hosting injects the official loaders into every HTML page on the next deploy. If the site already loads GA4 or pixels through GTM, set only the GTM container. Hosted elsewhere: render `(await crafty.analytics.get()).head` before `</head>` in SSR, or call `crafty.analytics.load()` once in the browser (it skips itself when the deploy already injected them). **Details: `references/sdk-development.md`.**
165
171
 
172
+ Structured data (schema.org JSON-LD for Google rich results and AI search): do **not** write JSON-LD by hand. Fill the business data (type, address, hours, phone, social profiles) with the `configure_structured_data` MCP tool, map collections to Product / Article / BlogPosting / FAQPage / Event / Service with `structured_data` on `create_collection` / `update_collection`, and render `crafty.structuredData(page, entries)` in `<head>`: the home page carries the business JSON-LD, mapped entries their own. For FAQ blocks, `crafty.structuredData(crafty.faqPage(block.data.items))`. **Details: `references/sdk-development.md`.**
173
+
166
174
  ## Phase 3 — Deploy a static site with the CLI
167
175
 
168
176
  ```bash
@@ -1,5 +1,11 @@
1
1
  # Migrating an existing site to Crafty
2
2
 
3
+ > **MCP prompt: `migrate-site`.** It runs this whole runbook for you and stops at every checkpoint for you to confirm. Arguments: `site_id` (the target site), `source` (the old site's URL, its `sitemap.xml` or a description of the export) and optionally `environment` (default `production`) and `research` (default `yes`: it also researches the brand on the web and proposes content the old site lacks; `no` for a strict 1:1 move). Needs a token with `crafty:write`.
4
+ >
5
+ > In Claude Code, type `/` and pick `mcp__<server>__migrate-site`, where `<server>` is the name you gave the Crafty server; other clients list it in their prompt menu. If your client does not show MCP prompts, ask the agent to call `get_guide migrate` and follow it.
6
+ >
7
+ > **Redesign instead of a 1:1 move? MCP prompt: `redesign-site`.** It studies the client's current site, social media and what the rest of the web says about them, sums up their brand, voice and content, and proposes a new site (site map, sections built from your block types, draft copy, visual direction) before it creates anything. Once you approve the proposal it builds it as drafts and never publishes. Arguments: `website` (the current site's URL) and optionally `social` (profile URLs or handles), `goals` and `site_id` (leave it out to make the proposal before the client has a Crafty site). Needs a token with `crafty:write`. Social networks often block automated reading, so be ready to paste the bio and a few posts or share screenshots.
8
+
3
9
  Runbook for moving a site that already exists (WordPress, Webflow, Wix, a static site, another headless CMS) into Crafty with an agent and the MCP server, without breaking its URLs. Work in this order; each phase has a checkpoint where a human confirms before the next one.
4
10
 
5
11
  Tools used: `bulk_upsert_entries`, `import_media_from_urls`, `upsert_redirects` (plus the usual `create_block_type`, `create_collection`, `create_page`, `publish_*`). Token scopes: `crafty:read` + `crafty:write`; add `crafty:publish` only for the final phase.
@@ -20,8 +26,9 @@ Build an inventory of every URL of the old site:
20
26
  1. Sources, best first: the CMS export or API (WordPress REST `/wp-json/wp/v2/posts?per_page=100&page=N`, `/pages`, `/media`; or the WXR export), `sitemap.xml` (and sitemap indexes), then a crawl of internal links from the home page.
21
27
  2. For each URL record: old path, title, type guess, language, last modified, the main content (HTML), the images and files it uses, and the old ID if known.
22
28
  3. Also collect the URLs that already redirect (HTTP 301/302) and anything in the old site's redirect plugin or `.htaccess`: those must be carried over too.
29
+ 4. Research the brand beyond its site: search the web for its name (Google Business profile and reviews, social media, press, directories and marketplaces, award or partner pages). List what the old site lacks as **proposed additions**: reviews and testimonials, FAQs drawn from customer questions, opening hours, locations, services or products listed elsewhere, awards, press mentions, social links. Give each one its source URL and how sure you are, flag information that contradicts the site or looks outdated, and never invent facts. Keep the additions apart from the inventory: they are proposals, not migrated content. Skip this step for a strict 1:1 move (the `migrate-site` prompt takes `research: "no"`).
23
30
 
24
- **Checkpoint:** show the user the counts per type and any URL you could not fetch.
31
+ **Checkpoint:** show the user the counts per type, any URL you could not fetch and the proposed additions. Only the additions the user picks are added, in phase 5, as new drafts.
25
32
 
26
33
  ## Phase 2 — Classify
27
34
 
@@ -58,7 +65,8 @@ Follow "Model content with block types first" in `SKILL.md`:
58
65
  1. Transform each item to the collection schema: clean the HTML (drop builder shortcodes, inline styles, tracking pixels), rewrite internal links to the **new** paths, and replace image URLs in the HTML with the `original_url` values from phase 4. Put media references (`cover`, `gallery`) as `media_id` values.
59
66
  2. `bulk_upsert_entries` with `{ site_id, collection_slug, entries: [{ slug, external_id, data }], dry_run: true }`. Fix every `failed` item (the errors name the field, e.g. `data.published_on: …`) and check `warnings` (dropped keys = a field missing from the schema).
60
67
  3. Run the same batch without `dry_run`. Entries are created as **drafts**; existing ones (same `external_id` or `slug`) are updated with a revision.
61
- 4. Singleton pages: `create_page` with `blocks` in the default locale; they start as drafts too. Other languages of the old site go in with `configure_locales` and `upsert_translation`, not as extra pages.
68
+ 4. Write the additions the user picked in phase 1 as new drafts (no `external_id` from the old site) and list them, with their sources, in the review report.
69
+ 5. Singleton pages: `create_page` with `blocks` in the default locale; they start as drafts too. Other languages of the old site go in with `configure_locales` and `upsert_translation`, not as extra pages.
62
70
 
63
71
  ## Phase 6 — Redirects
64
72
 
@@ -187,6 +187,7 @@ Types depend on the environment (generate with the key of the environment the co
187
187
  crafty.forms.list(options?) // => { data: CraftyForm[] } (requires apiKey)
188
188
  crafty.forms.get(slug, options?) // => { data: CraftyForm } (requires apiKey)
189
189
  crafty.forms.submit(formSlug, data, options?) // => { id, form_id, submitted_at } (public; apiKey optional, picks the environment)
190
+ crafty.forms.captcha(form, container) // => CraftyFormCaptcha | null (browser; renders the form's captcha widget)
190
191
  ```
191
192
 
192
193
  `forms.submit()` uses a **public** endpoint: the `X-API-Key`, when configured, only selects the environment (a staging key submits to staging, no key submits to production), but it **requires `siteSlug` in the client config** — calling it without one throws a synchronous `CraftyError` with code `BAD_REQUEST`.
@@ -205,6 +206,17 @@ const result = await crafty.forms.submit("contact", {
205
206
  // => { id, form_id, submitted_at }
206
207
  ```
207
208
 
209
+ Forms protected by a captcha return `captcha: { provider, site_key, token_field }` (absent otherwise), and their submissions are rejected with 422 without the widget token. In the browser, render the widget next to the form and pass it to `submit()`:
210
+
211
+ ```ts
212
+ const { data: form } = await crafty.forms.get("contact");
213
+ const captcha = await crafty.forms.captcha(form, document.querySelector("#captcha")!); // null when not needed
214
+
215
+ await crafty.forms.submit("contact", values, { captcha }); // adds the token, then resets the widget
216
+ ```
217
+
218
+ Turnstile runs invisibly and only shows a challenge to suspicious visitors. Without the SDK, load the provider script yourself and post the token in `captcha.token_field`.
219
+
208
220
  > Note the asymmetry: `collections.get()` returns the bare object, while `forms.get()` and `entries.get()` are wrapped in `{ data }`.
209
221
 
210
222
  ### `mediaCollections`
@@ -281,6 +293,19 @@ crafty.analytics.load(options?) // browser only => "loaded" | "already-loaded"
281
293
 
282
294
  Never hard-code GTM / GA4 / pixel snippets in the site, and never add GA4 both here and inside GTM (page views are counted twice).
283
295
 
296
+ ## Structured data
297
+
298
+ The public API serves schema.org JSON-LD in `structured_data`: on the home page (`pages.get(homeSlug)`, the business set with `configure_structured_data`), on `crafty.site.get()`, and on each published entry of a collection with a structured data mapping (`structured_data` on `create_collection` / `update_collection`). It is `null` when nothing is configured or a required property is empty.
299
+
300
+ ```ts
301
+ crafty.site.get(options?) // => { name, slug, environment, default_locale, locales, structured_data }
302
+ crafty.structuredData(...sources) // => '<script type="application/ld+json">…</script>' tags, "" when none
303
+ crafty.jsonLd(...sources) // => the JSON-LD objects, for useHead / <Head>
304
+ crafty.faqPage([{ question, answer }]) // => FAQPage JSON-LD for a FAQ block, or null
305
+ ```
306
+
307
+ Sources can be pages, entries, their API responses, list responses, the site or JSON-LD objects; FAQPage objects are merged into one per page. The script content escapes `<`, so it is safe to inject as raw HTML (`set:html`, `v-html`, `dangerouslySetInnerHTML`). Validate the result at https://search.google.com/test/rich-results.
308
+
284
309
  ## Error handling
285
310
 
286
311
  The SDK throws `CraftyError` for HTTP, timeout, abort, network, and config failures.