payload-live-preview 2.0.6 → 2.1.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.
Files changed (116) hide show
  1. package/README.md +141 -38
  2. package/dist/adapters/astro/FragmentBridge.astro +25 -0
  3. package/dist/adapters/astro/PreviewBoundary.astro +2 -4
  4. package/dist/adapters/astro/RichText.astro +26 -5
  5. package/dist/adapters/astro/index.d.ts +41 -9
  6. package/dist/adapters/astro/index.js +1 -1
  7. package/dist/adapters/astro/index.js.map +1 -1
  8. package/dist/adapters/astro/middleware-entry.d.ts +3 -3
  9. package/dist/adapters/astro/middleware-entry.js +1 -1
  10. package/dist/adapters/astro/middleware-entry.js.map +1 -1
  11. package/dist/adapters/nextjs/index.d.ts +17 -12
  12. package/dist/adapters/nextjs/index.js +1 -1
  13. package/dist/adapters/nextjs/index.js.map +1 -1
  14. package/dist/adapters/nuxt/index.d.ts +11 -6
  15. package/dist/adapters/nuxt/index.js +1 -1
  16. package/dist/adapters/nuxt/index.js.map +1 -1
  17. package/dist/adapters/nuxt/module.d.ts +64 -13
  18. package/dist/adapters/nuxt/module.js +1 -1
  19. package/dist/adapters/nuxt/module.js.map +1 -1
  20. package/dist/adapters/react/index.d.ts +11 -7
  21. package/dist/adapters/react/index.js +1 -1
  22. package/dist/adapters/react/index.js.map +1 -1
  23. package/dist/adapters/sveltekit/index.d.ts +10 -5
  24. package/dist/adapters/sveltekit/index.js +1 -1
  25. package/dist/adapters/sveltekit/index.js.map +1 -1
  26. package/dist/adapters/vue/index.d.ts +10 -7
  27. package/dist/adapters/vue/index.js +1 -1
  28. package/dist/adapters/vue/index.js.map +1 -1
  29. package/dist/annotate.d.ts +15 -2
  30. package/dist/annotate.js.map +1 -1
  31. package/dist/client.cjs +1 -1
  32. package/dist/client.cjs.map +1 -1
  33. package/dist/client.d.cts +367 -266
  34. package/dist/client.d.ts +367 -266
  35. package/dist/client.js +1 -1
  36. package/dist/client.js.map +1 -1
  37. package/dist/codegen-cli.js.map +1 -1
  38. package/dist/codegen.cjs.map +1 -1
  39. package/dist/codegen.d.cts +7 -1
  40. package/dist/codegen.d.ts +7 -1
  41. package/dist/codegen.js.map +1 -1
  42. package/dist/core.cjs +1 -1
  43. package/dist/core.cjs.map +1 -1
  44. package/dist/core.d.cts +544 -392
  45. package/dist/core.d.ts +544 -392
  46. package/dist/core.js +1 -1
  47. package/dist/core.js.map +1 -1
  48. package/dist/doctor-cli.d.ts +1 -1
  49. package/dist/doctor-cli.js +1 -1
  50. package/dist/doctor-cli.js.map +1 -1
  51. package/dist/doctor.d.ts +2 -2
  52. package/dist/doctor.js +1 -1
  53. package/dist/doctor.js.map +1 -1
  54. package/dist/{document-session-BfBfLVpg.d.ts → document-session-DWi9H3Qk.d.ts} +7 -0
  55. package/dist/{fragment-endpoint-DATKU183.d.ts → fragment-endpoint-B2qcRw5T.d.ts} +22 -7
  56. package/dist/fragment.cjs +1 -1
  57. package/dist/fragment.cjs.map +1 -1
  58. package/dist/fragment.d.cts +37 -16
  59. package/dist/fragment.d.ts +37 -16
  60. package/dist/fragment.js +1 -1
  61. package/dist/fragment.js.map +1 -1
  62. package/dist/index.cjs +1 -1
  63. package/dist/index.cjs.map +1 -1
  64. package/dist/index.d.cts +598 -400
  65. package/dist/index.d.ts +598 -400
  66. package/dist/index.js +1 -1
  67. package/dist/index.js.map +1 -1
  68. package/dist/lean.cjs +1 -1
  69. package/dist/lean.cjs.map +1 -1
  70. package/dist/lean.d.cts +5 -2
  71. package/dist/lean.d.ts +5 -2
  72. package/dist/lean.js +1 -1
  73. package/dist/lean.js.map +1 -1
  74. package/dist/lexical.cjs +1 -1
  75. package/dist/lexical.cjs.map +1 -1
  76. package/dist/lexical.d.cts +32 -11
  77. package/dist/lexical.d.ts +32 -11
  78. package/dist/lexical.js +1 -1
  79. package/dist/lexical.js.map +1 -1
  80. package/dist/{locals-CNUGYbA_.d.ts → locals-B1mF3aTb.d.ts} +1 -1
  81. package/dist/{middleware-CWObDO37.d.ts → middleware-BGobLN9P.d.ts} +11 -5
  82. package/dist/migrate.js +1 -1
  83. package/dist/migrate.js.map +1 -1
  84. package/dist/{options-uHKrDM2U.d.ts → options-Cm8fC7dj.d.ts} +31 -1
  85. package/dist/payload.cjs +1 -1
  86. package/dist/payload.cjs.map +1 -1
  87. package/dist/payload.d.cts +18 -2
  88. package/dist/payload.d.ts +18 -2
  89. package/dist/payload.js +1 -1
  90. package/dist/payload.js.map +1 -1
  91. package/dist/plugin.cjs +2 -0
  92. package/dist/plugin.cjs.map +1 -0
  93. package/dist/plugin.d.cts +30 -0
  94. package/dist/plugin.d.ts +30 -0
  95. package/dist/plugin.js +2 -0
  96. package/dist/plugin.js.map +1 -0
  97. package/dist/plugins.cjs +1 -1
  98. package/dist/plugins.cjs.map +1 -1
  99. package/dist/plugins.d.cts +102 -29
  100. package/dist/plugins.d.ts +102 -29
  101. package/dist/plugins.js +1 -1
  102. package/dist/plugins.js.map +1 -1
  103. package/dist/{probe-Bzm4fYFL.d.ts → probe-DGPDsnbj.d.ts} +6 -2
  104. package/dist/server.cjs +1 -1
  105. package/dist/server.cjs.map +1 -1
  106. package/dist/server.d.cts +43 -4
  107. package/dist/server.d.ts +43 -4
  108. package/dist/server.js +1 -1
  109. package/dist/server.js.map +1 -1
  110. package/dist/structural.cjs +2 -2
  111. package/dist/structural.cjs.map +1 -1
  112. package/dist/structural.d.cts +61 -13
  113. package/dist/structural.d.ts +61 -13
  114. package/dist/structural.js +2 -2
  115. package/dist/structural.js.map +1 -1
  116. package/package.json +33 -4
@@ -1,3 +1,21 @@
1
+ /** The `Document` surface the sanitizer needs; jsdom, linkedom and happy-dom all provide it. */
2
+ interface SanitizerDocument {
3
+ createElement: (tagName: string) => {
4
+ innerHTML: string;
5
+ readonly content: ParentNode;
6
+ };
7
+ }
8
+ /**
9
+ * Supply a `Document` for SSR, e.g. linkedom's `parseHTML(...).document`;
10
+ * `null` clears it, for every entry. The fallback for a call that names no
11
+ * document of its own.
12
+ *
13
+ * @deprecated Since 2.1 a call names its document: `sanitizeHtml(html, { document })`,
14
+ * `lexicalToHtml(content, { document })`. The process-wide slot stays until 3.0
15
+ * (ADR 0007 ledger).
16
+ */
17
+ declare function setSanitizerDocument(doc: SanitizerDocument | null): void;
18
+
1
19
  /**
2
20
  * Lexical document types. Only `type` and `children` are required; every
3
21
  * other property is forwarded opaquely to the renderer for that node type.
@@ -42,6 +60,19 @@ interface LexicalRoot {
42
60
  interface LexicalRenderOptions {
43
61
  /** Pass the result through `sanitizeHtml()` (default `true`). */
44
62
  readonly sanitize?: boolean;
63
+ /**
64
+ * The DOM the sanitizer parses with, for this call: an SSR document such as
65
+ * linkedom's or jsdom's. Without it the document `setSanitizerDocument()`
66
+ * supplied is used, then the global one; with neither the result is
67
+ * unsanitised and warns once.
68
+ */
69
+ readonly document?: SanitizerDocument;
70
+ /**
71
+ * Throw instead of returning unsanitised HTML when no document is available:
72
+ * the `SanitizerEnvironmentError` `sanitizeHtml()` throws (ADR 0025). Off in
73
+ * 2.x, where the call warns once and returns the markup; the default in 3.0.
74
+ */
75
+ readonly requireDocument?: boolean;
45
76
  /**
46
77
  * Called for every `block` or `inlineBlock` the registry has no renderer
47
78
  * for, with the block's slug as Payload sent it and the class its empty
@@ -53,7 +84,7 @@ interface LexicalRenderOptions {
53
84
  }
54
85
  /** @internal */
55
86
  declare function isLexicalContent(value: unknown): value is LexicalRoot;
56
- /** Render a Lexical document to HTML; without `setSanitizerDocument()` the result is unsanitised and warns once. */
87
+ /** Render a Lexical document to HTML; without a document the result is unsanitised and warns once, or throws under `requireDocument`. */
57
88
  declare function lexicalToHtml(content: LexicalRoot, options?: LexicalRenderOptions): string;
58
89
  /** Plain text of a document, paragraphs separated by `\n`. */
59
90
  declare function lexicalToPlainText(content: LexicalRoot): string;
@@ -105,14 +136,4 @@ declare function registeredBlockTypes(): readonly string[];
105
136
  /** Register every default block renderer under its kebab-, camel- and short slug. Idempotent. */
106
137
  declare function registerDefaultBlocks(): void;
107
138
 
108
- /** The `Document` surface the sanitizer needs; jsdom, linkedom and happy-dom all provide it. */
109
- interface SanitizerDocument {
110
- createElement: (tagName: string) => {
111
- innerHTML: string;
112
- readonly content: ParentNode;
113
- };
114
- }
115
- /** Supply a `Document` for SSR, e.g. linkedom's `parseHTML(...).document`; `null` clears it, for every entry. */
116
- declare function setSanitizerDocument(doc: SanitizerDocument | null): void;
117
-
118
139
  export { type BlockRenderContext, type BlockRenderer, type LexicalNode, type LexicalRenderOptions, type LexicalRoot, type NodeRenderer, type RenderNodeContext, type SanitizerDocument, TextFormat, isLexicalContent, lexicalToHtml, lexicalToPlainText, lookupBlockRenderer, lookup as lookupLexicalNode, registerBlockRenderer, registerDefaultBlocks, register as registerLexicalNode, registeredBlockTypes, setSanitizerDocument };
package/dist/lexical.d.ts CHANGED
@@ -1,3 +1,21 @@
1
+ /** The `Document` surface the sanitizer needs; jsdom, linkedom and happy-dom all provide it. */
2
+ interface SanitizerDocument {
3
+ createElement: (tagName: string) => {
4
+ innerHTML: string;
5
+ readonly content: ParentNode;
6
+ };
7
+ }
8
+ /**
9
+ * Supply a `Document` for SSR, e.g. linkedom's `parseHTML(...).document`;
10
+ * `null` clears it, for every entry. The fallback for a call that names no
11
+ * document of its own.
12
+ *
13
+ * @deprecated Since 2.1 a call names its document: `sanitizeHtml(html, { document })`,
14
+ * `lexicalToHtml(content, { document })`. The process-wide slot stays until 3.0
15
+ * (ADR 0007 ledger).
16
+ */
17
+ declare function setSanitizerDocument(doc: SanitizerDocument | null): void;
18
+
1
19
  /**
2
20
  * Lexical document types. Only `type` and `children` are required; every
3
21
  * other property is forwarded opaquely to the renderer for that node type.
@@ -42,6 +60,19 @@ interface LexicalRoot {
42
60
  interface LexicalRenderOptions {
43
61
  /** Pass the result through `sanitizeHtml()` (default `true`). */
44
62
  readonly sanitize?: boolean;
63
+ /**
64
+ * The DOM the sanitizer parses with, for this call: an SSR document such as
65
+ * linkedom's or jsdom's. Without it the document `setSanitizerDocument()`
66
+ * supplied is used, then the global one; with neither the result is
67
+ * unsanitised and warns once.
68
+ */
69
+ readonly document?: SanitizerDocument;
70
+ /**
71
+ * Throw instead of returning unsanitised HTML when no document is available:
72
+ * the `SanitizerEnvironmentError` `sanitizeHtml()` throws (ADR 0025). Off in
73
+ * 2.x, where the call warns once and returns the markup; the default in 3.0.
74
+ */
75
+ readonly requireDocument?: boolean;
45
76
  /**
46
77
  * Called for every `block` or `inlineBlock` the registry has no renderer
47
78
  * for, with the block's slug as Payload sent it and the class its empty
@@ -53,7 +84,7 @@ interface LexicalRenderOptions {
53
84
  }
54
85
  /** @internal */
55
86
  declare function isLexicalContent(value: unknown): value is LexicalRoot;
56
- /** Render a Lexical document to HTML; without `setSanitizerDocument()` the result is unsanitised and warns once. */
87
+ /** Render a Lexical document to HTML; without a document the result is unsanitised and warns once, or throws under `requireDocument`. */
57
88
  declare function lexicalToHtml(content: LexicalRoot, options?: LexicalRenderOptions): string;
58
89
  /** Plain text of a document, paragraphs separated by `\n`. */
59
90
  declare function lexicalToPlainText(content: LexicalRoot): string;
@@ -105,14 +136,4 @@ declare function registeredBlockTypes(): readonly string[];
105
136
  /** Register every default block renderer under its kebab-, camel- and short slug. Idempotent. */
106
137
  declare function registerDefaultBlocks(): void;
107
138
 
108
- /** The `Document` surface the sanitizer needs; jsdom, linkedom and happy-dom all provide it. */
109
- interface SanitizerDocument {
110
- createElement: (tagName: string) => {
111
- innerHTML: string;
112
- readonly content: ParentNode;
113
- };
114
- }
115
- /** Supply a `Document` for SSR, e.g. linkedom's `parseHTML(...).document`; `null` clears it, for every entry. */
116
- declare function setSanitizerDocument(doc: SanitizerDocument | null): void;
117
-
118
139
  export { type BlockRenderContext, type BlockRenderer, type LexicalNode, type LexicalRenderOptions, type LexicalRoot, type NodeRenderer, type RenderNodeContext, type SanitizerDocument, TextFormat, isLexicalContent, lexicalToHtml, lexicalToPlainText, lookupBlockRenderer, lookup as lookupLexicalNode, registerBlockRenderer, registerDefaultBlocks, register as registerLexicalNode, registeredBlockTypes, setSanitizerDocument };
package/dist/lexical.js CHANGED
@@ -1,2 +1,2 @@
1
- var e=/* @__PURE__ */Symbol.for("payload-live-preview.trusted-types");var t=/* @__PURE__ */new Set(["http:","https:","mailto:","tel:"]),r=/^\s*(?:javascript|data|vbscript|file|blob|about)\s*:/i,n=/^(?:\.{1,2}\/|[a-zA-Z0-9_-]+\/?)/,o=/^[\\/]{2}/,i=/[\t\n\r]/g;function isSafeUrl(e){if("string"!=typeof e)return!1;const a=e.trim().replace(i,"");if(0===a.length)return!1;if(r.test(a))return!1;if(a.startsWith("#")||a.startsWith("?"))return!0;if(o.test(a))return!0;if(a.startsWith("/"))return!0;try{const e=new URL(a);return t.has(e.protocol)}catch{return n.test(a)}}function isExternalHttpUrl(e){const t=e.trim().replace(i,"");return/^https?:\/\//i.test(t)||o.test(t)}var a=/* @__PURE__ */new Set;function l(e){a.has(e)||(a.add(e),function(e){try{console.warn(e)}catch{}}(`[live-preview] LP0409: the strict sanitizer removed \`${e}\` from written markup; the 1.x default (\`sanitizerPolicy: 'compat'\`) kept it. ${function(e){return e.startsWith("data-payload-")?"A binding inside CMS content is refused by design — an editor could otherwise aim a write at any element on the page (docs/security.md)":"id"===e||"name"===e?"CMS content that can name an element can shadow a global of that name — DOM clobbering, refused by design (docs/security.md)":"List it in `allowedDataAttributes` if the page needs it, or set `sanitizerPolicy: 'compat'` to keep every `data-*` as 1.x did"}(e)}.`))}var s=/* @__PURE__ */new Set(["p","br","strong","b","em","i","u","s","strike","mark","small","h1","h2","h3","h4","h5","h6","ul","ol","li","dl","dt","dd","blockquote","code","pre","kbd","samp","var","a","span","div","section","article","aside","header","footer","nav","figure","figcaption","img","picture","source","audio","video","sub","sup","hr","time","abbr","cite","q","table","thead","tbody","tfoot","tr","th","td","caption","colgroup","col"]),c=/* @__PURE__ */new Set(["input","button","textarea","select","option","label"]),u=/* @__PURE__ */new Set(["script","style","iframe","object","embed","link","meta","base","form","input","button","select","textarea","svg","math","template","frame","frameset","noframes","noscript"]),d=/* @__PURE__ */new Set(["id","class","lang","dir","title","role","tabindex"]),p="aria-",f="data-",h={a:/* @__PURE__ */new Set(["href","target","rel","download","hreflang","type"]),img:/* @__PURE__ */new Set(["src","srcset","sizes","alt","width","height","loading","decoding"]),picture:/* @__PURE__ */new Set([]),source:/* @__PURE__ */new Set(["src","srcset","sizes","type","media"]),audio:/* @__PURE__ */new Set(["src","controls","autoplay","loop","muted","preload"]),video:/* @__PURE__ */new Set(["src","poster","controls","autoplay","loop","muted","preload","width","height","playsinline"]),time:/* @__PURE__ */new Set(["datetime"]),abbr:/* @__PURE__ */new Set(["title"]),q:/* @__PURE__ */new Set(["cite"]),blockquote:/* @__PURE__ */new Set(["cite"]),table:/* @__PURE__ */new Set(["summary"]),th:/* @__PURE__ */new Set(["colspan","rowspan","scope","headers","abbr"]),td:/* @__PURE__ */new Set(["colspan","rowspan","headers"]),col:/* @__PURE__ */new Set(["span"]),colgroup:/* @__PURE__ */new Set(["span"]),ol:/* @__PURE__ */new Set(["start","reversed","type"]),li:/* @__PURE__ */new Set(["value"]),code:/* @__PURE__ */new Set(["class"]),pre:/* @__PURE__ */new Set(["class"])},m=/* @__PURE__ */new Set(["href","src","cite","poster"]),g=class extends Error{name="SanitizerEnvironmentError"},b=/* @__PURE__ */new Set(["id","name","data-payload-key","data-payload-nested-key","data-payload-nested-template"]),y=/* @__PURE__ */Symbol.for("payload-live-preview.sanitizer-document");function setSanitizerDocument(e){globalThis[y]=e??void 0}function sanitizeHtml(t,r){return function(t){const r=$();if(!r)throw"undefined"!=typeof __INLINE_BUILD__&&__INLINE_BUILD__?new Error("sanitizeHtml needs a DOM"):new g("sanitizeHtml needs a DOM; provide one with setSanitizerDocument() during SSR.");if(""===t)return"";const n=function(){{const e=/* @__PURE__ */new Map;for(const[t,r]of Object.entries(h))e.set(t,r);return{allowedTags:s,attrByTag:e,allowFormControls:!1,templateMode:!1,mode:"strict",allowedData:/* @__PURE__ */new Set}}}(),o=r.createElement("template");return o.innerHTML=function(t){const r=function(){const t=function(){const t=globalThis,r=t[e];if(void 0!==r)return r;const n={};return t[e]=n,n}();if(void 0!==t.override)return t.override;if(void 0!==t.auto)return t.auto;const r=function(){const e=globalThis.trustedTypes;if("object"==typeof e&&null!==e)return"function"==typeof e.createPolicy?e:void 0}();try{t.auto=void 0===r?null:r.createPolicy("payload-live-preview",{createHTML:e=>e})}catch{t.auto=null}return t.auto}();return null===r?t:r.createHTML(t)}(t),v(o.content,n),o.innerHTML}(t)}function $(){if("undefined"==typeof __INLINE_BUILD__||!__INLINE_BUILD__){const e=globalThis[y];if(e)return e}if("undefined"!=typeof document)return document}function v(e,t){for(const r of Array.from(e.childNodes))1===r.nodeType?w(r,t):8===r.nodeType&&r.remove()}function w(e,t){const r=e.tagName.toLowerCase();if(!u.has(r)||t.allowFormControls&&c.has(r)){if(!t.allowedTags.has(r))return v(e,t),void e.replaceWith(...e.childNodes);!function(e,t,r){const n=r.attrByTag.get(t);for(const t of Array.from(e.attributes)){const o=t.name.toLowerCase();if(o.startsWith("on")||"style"===o)e.removeAttribute(t.name);else if("is"!==o){if("strict"===r.mode){if(r.templateMode&&b.has(o))continue;if("id"===o||"name"===o||o.startsWith("data-payload-")){e.removeAttribute(t.name),"name"===o&&!0!==n?.has(o)||l(o);continue}if(o.startsWith(f)){r.allowedData.has(o)||(e.removeAttribute(t.name),l(o));continue}if(d.has(o)||o.startsWith(p))continue}else if(d.has(o)||o.startsWith(p)||o.startsWith(f))continue;n?.has(o)?m.has(o)&&!isSafeUrl(t.value)?e.removeAttribute(t.name):"srcset"!==o||S(t.value)||e.removeAttribute(t.name):e.removeAttribute(t.name)}else e.setAttribute("is","")}}(e,r,t),"a"===r&&function(e){const t=e.getAttribute("href");null!==t&&isExternalHttpUrl(t)&&(e.setAttribute("rel","noopener noreferrer"),e.hasAttribute("target")||e.setAttribute("target","_blank"))}(e),v(e,t)}else e.remove()}function S(e){for(const t of e.split(",")){const e=t.trim();if(0===e.length)continue;const[r=e]=e.split(/\s/,1);if(!isSafeUrl(r))return!1}return!0}var k=Object.freeze({"&":"&amp;","<":"&lt;",">":"&gt;",'"':"&quot;","'":"&#x27;","/":"&#x2F;","`":"&#x60;","=":"&#x3D;"}),H=/[&<>"'/`=]/g;function escapeHtml(e){return e.replace(H,e=>k[e])}var T=Object.freeze({"&":"&amp;","<":"&lt;",">":"&gt;",'"':"&quot;","'":"&#x27;"}),A=/[&<>"']/g;function escapeHtmlAttribute(e){return e.replace(A,e=>T[e])}var _={BOLD:1,ITALIC:2,STRIKETHROUGH:4,UNDERLINE:8,CODE:16,SUBSCRIPT:32,SUPERSCRIPT:64,HIGHLIGHT:128},L={1:"left",2:"center",3:"right",4:"justify"},x=/* @__PURE__ */new Set(["left","center","right","justify","start","end"]);function C(e){const t=e.format;return"string"==typeof t&&x.has(t)?t:"number"==typeof t?L[t]:void 0}function U(e){const t=e.indent;return"number"==typeof t&&t>0?t:0}function I(e){return"rtl"===e.direction?' dir="rtl"':"ltr"===e.direction?' dir="ltr"':""}function z(e){const t=C(e),r=U(e),n=[];return void 0!==t&&n.push(`lp-align-${t}`),r>0&&n.push(`lp-indent-${String(r)}`),0===n.length?"":` class="${n.join(" ")}"`}var E=/* @__PURE__ */new Set(["h1","h2","h3","h4","h5","h6"]);function D(e){return"object"==typeof e&&null!==e?e:void 0}function B(e){return D(e)}function N(e){return e.replace(/[^a-zA-Z0-9_-]/g,"-").toLowerCase()}function j(e){return"string"==typeof e&&e.length>0?e:void 0}var M=' target="_blank" rel="noopener noreferrer"',R=(e,t)=>{const r=t.renderChildren(e.children??[]),n=D(e.fields),o=function(e,t){if("internal"===t?.linkType)return function(e){const t=D(D(e)?.value),r=t?.url;if("string"==typeof r&&r.length>0)return r;const n=t?.slug;return"string"==typeof n&&n.length>0?`/${n}`:void 0}(t.doc);const r=t?.url??e.url;return"string"==typeof r&&r.length>0?r:void 0}(e,n);if(void 0===o||!isSafeUrl(o))return r;const i="string"==typeof e.title?` title="${escapeHtml(e.title)}"`:"";return`<a href="${escapeHtmlAttribute(o)}"${function(e,t,r){if(!0===t?.newTab||isExternalHttpUrl(r))return M;const n="string"==typeof e.target?e.target:"";return""===n?"":"_blank"===n?M:` target="${escapeHtml(n)}"`}(e,n,o)}${i}>${r}</a>`};function W(e){if("string"==typeof e.text)return e.text;if(!e.children)return"";let t="";for(const r of e.children)t+=W(r);return t}function O(e){return`${"number"==typeof e.width?` width="${String(e.width)}"`:""}${"number"==typeof e.height?` height="${String(e.height)}"`:""}`}function P(e){return"string"==typeof e.mimeType?` type="${escapeHtmlAttribute(e.mimeType)}"`:""}var q=/* @__PURE__ */new Map;function G(e,t){q.set(e,t)}function F(e){return q.get(e)}function K(){return[...q.keys()]}function Z(e,t,r,n){const o=D(e.fields)??{},i="string"==typeof o.blockType?o.blockType:"",a=N(i),l=""===a?n:`${n} ${n}--${a}`;if(""!==i){const e=F(i)??F(a);if(e)return e(o,{renderChildren:t.renderChildren});t.onUnrenderedBlock?.(i,l)}return`<${r} class="${l}"></${r}>`}function J(e,t){return"number"==typeof t&&t>1?` ${e}="${String(t)}"`:""}var Q={text:e=>{let t=escapeHtml("string"==typeof e.text?e.text:"");const r="number"==typeof e.format?e.format:0;return 0!==(r&_.CODE)&&(t=`<code>${t}</code>`),0!==(r&_.BOLD)&&(t=`<strong>${t}</strong>`),0!==(r&_.ITALIC)&&(t=`<em>${t}</em>`),0!==(r&_.UNDERLINE)&&(t=`<u>${t}</u>`),0!==(r&_.STRIKETHROUGH)&&(t=`<s>${t}</s>`),0!==(r&_.SUBSCRIPT)&&(t=`<sub>${t}</sub>`),0!==(r&_.SUPERSCRIPT)&&(t=`<sup>${t}</sup>`),0!==(r&_.HIGHLIGHT)&&(t=`<mark>${t}</mark>`),t},paragraph:(e,t)=>{const r=t.renderChildren(e.children??[]);return`<p${I(e)}${z(e)}>${r}</p>`},heading:(e,t)=>{const r="string"==typeof e.tag?e.tag.toLowerCase():"h2",n=E.has(r)?r:"h2",o=t.renderChildren(e.children??[]);return`<${n}${I(e)}${z(e)}>${o}</${n}>`},list:(e,t)=>{const r="string"==typeof e.listType?e.listType:"bullet",n="number"===r?"ol":"ul",o="number"===r&&"number"==typeof e.start&&e.start>1?` start="${String(e.start)}"`:"",i="check"===r?' role="list"':"",a=t.renderChildren(e.children??[]);return`<${n}${I(e)}${z(e)}${o}${i}>${a}</${n}>`},listitem:(e,t)=>{const r=t.renderChildren(e.children??[]);if("boolean"==typeof e.checked)return`<li role="checkbox" aria-checked="${e.checked?"true":"false"}"${z(e)}>${r}</li>`;const n="number"==typeof e.value?` value="${escapeHtml(String(e.value))}"`:"";return`<li${I(e)}${z(e)}${n}>${r}</li>`},link:R,autolink:R,quote:(e,t)=>{const r=t.renderChildren(e.children??[]);return`<blockquote${I(e)}${z(e)}>${r}</blockquote>`},code:e=>{const t=N("string"==typeof e.language?e.language:"");return`<pre><code${""===t?"":` class="language-${t}"`}>${escapeHtml(W(e))}</code></pre>`},"code-highlight":e=>{const t="string"==typeof e.text?e.text:"";return`<span${"string"==typeof e.highlightType?` class="token-${N(e.highlightType)}"`:""}>${escapeHtml(t)}</span>`},linebreak:()=>"<br>",horizontalrule:()=>"<hr>",tab:()=>"\t",upload:e=>{const t=B(e.value);if(void 0===t)return"";const r=t.url;if("string"!=typeof r||!isSafeUrl(r))return"";const n="string"==typeof t.mimeType?t.mimeType:"";return n.startsWith("video/")?function(e,t){return`<video controls${O(e)}><source src="${escapeHtmlAttribute(t)}"${P(e)}></video>`}(t,r):n.startsWith("audio/")?function(e,t){return`<audio controls><source src="${escapeHtmlAttribute(t)}"${P(e)}></audio>`}(t,r):""===n||n.startsWith("image/")?function(e,t){const r="string"==typeof e.alt?escapeHtml(e.alt):"";return`<img src="${escapeHtmlAttribute(t)}" alt="${r}"${O(e)} loading="lazy" decoding="async">`}(t,r):function(e,t){const r="string"==typeof e.filename?escapeHtml(e.filename):escapeHtml(t);return`<a href="${escapeHtmlAttribute(t)}" target="_blank" rel="noopener noreferrer">${r}</a>`}(t,r)},relationship:e=>{const t="string"==typeof e.relationTo?e.relationTo:"",r=D(e.value),n=escapeHtml((r&&function(e){const t=j(e.title)??j(e.name)??j(e.slug);return void 0!==t?t:void 0===e.id?void 0:String(e.id)}(r))??`#${t}`),o=N(t),i=""===o?' class="lp-relation"':` class="lp-relation lp-relation--${o}"`,a=r?.url;return"string"==typeof a&&isSafeUrl(a)?`<a href="${escapeHtmlAttribute(a)}"${i}>${n}</a>`:`<span${i}>${n}</span>`},block:(e,t)=>Z(e,t,"div","lp-block"),inlineBlock:(e,t)=>Z(e,t,"span","lp-inline-block"),table:(e,t)=>`<table${I(e)}><tbody>${t.renderChildren(e.children??[])}</tbody></table>`,tablerow:(e,t)=>`<tr>${t.renderChildren(e.children??[])}</tr>`,tablecell:(e,t)=>{const r="number"==typeof e.headerState?e.headerState:0,n=3&r?"th":"td";return`<${n}${1===r?' scope="col"':2===r?' scope="row"':""}${J("colspan",e.colSpan)}${J("rowspan",e.rowSpan)}>${t.renderChildren(e.children??[])}</${n}>`}},V=/* @__PURE__ */new Map;function X(e,t){V.set(e,t)}function Y(e){return V.get(e)??Q[e]}var ee=!1;function te(e){if("object"!=typeof e||null===e)return!1;if(!("root"in e))return!1;const t=e.root;return"object"==typeof t&&null!==t&&"children"in t&&Array.isArray(t.children)}function re(e,t={}){if(!te(e))return"";const r=function(e){const t={renderChildren:e=>{let r="";for(const n of e)r+=oe(n,t);return r},resolveAlignment:C,resolveIndent:U,onUnrenderedBlock:e};return t}(t.onUnrenderedBlock).renderChildren(e.root.children);return!1===t.sanitize?r:void 0!==$()?sanitizeHtml(r):(function(){if(!ee){ee=!0;try{console.warn('[live-preview] lexicalToHtml() has no sanitizer document and returned unsanitised HTML; call setSanitizerDocument() (linkedom/jsdom) for server rendering, see "HTML sanitization" in docs/security.md.')}catch{}}}(),r)}function ne(e){return te(e)?e.root.children.map(ie).join("\n").trim():""}function oe(e,t){const r=Y(e.type);return r?r(e,t):void 0!==e.children?t.renderChildren(e.children):""}function ie(e){if("string"==typeof e.text)return e.text;if("linebreak"===e.type)return"\n";if(void 0===e.children)return"";let t="";for(const r of e.children)t+=ie(r);return t}function ae(e,t){const r=e[t];return"string"==typeof r&&r.length>0?r:void 0}function le(e,t){const r=ae(e,t);return void 0!==r&&isSafeUrl(r)?r:void 0}function se(e){const t=ae(e,"caption");return void 0!==t?`<figcaption>${escapeHtml(t)}</figcaption>`:""}var ce=(e,t)=>{const r=N(ae(e,"importance")??"info"),n=ae(e,"title"),o=ae(e,"text"),i=function(e){const t=e.body??e.content;if("object"!=typeof t||null===t)return;const r=t.root;return r&&Array.isArray(r.children)?r.children:void 0}(e);return`<aside class="lp-block-callout lp-block-callout--${r}">${void 0!==n?`<strong>${escapeHtml(n)}</strong>`:""}${void 0!==i?t.renderChildren(i):void 0!==o?`<p>${escapeHtml(o)}</p>`:""}</aside>`},ue=e=>{const t=B(e.image),r=t?.url??le(e,"imageUrl");if(void 0===r||!isSafeUrl(r))return"";const n=t?.alt??ae(e,"alt")??"";return`<figure class="lp-block-image"><img src="${escapeHtmlAttribute(r)}" alt="${escapeHtmlAttribute(n)}"${function(e){return`${"number"==typeof e?.width?` width="${String(e.width)}"`:""}${"number"==typeof e?.height?` height="${String(e.height)}"`:""}`}(t)} loading="lazy" decoding="async">${se(e)}</figure>`},de=e=>{const t=B(e.video),r=t?.url??le(e,"videoUrl");if(void 0===r||!isSafeUrl(r))return"";const n=t?.mimeType??ae(e,"mimeType"),o=void 0!==n?` type="${escapeHtmlAttribute(n)}"`:"",i=le(e,"poster");return`<figure class="lp-block-video"><video controls${void 0!==i?` poster="${escapeHtmlAttribute(i)}"`:""}><source src="${escapeHtmlAttribute(r)}"${o}></video>${se(e)}</figure>`},pe=e=>{const t=ae(e,"code")??ae(e,"content");if(void 0===t)return"";const r=N(ae(e,"language")??""),n=""===r?"":` class="language-${r}"`;return`<figure class="lp-block-code">${se(e)}<pre><code${n}>${escapeHtml(t)}</code></pre></figure>`},fe=e=>{const t=ae(e,"label")??ae(e,"text"),r=le(e,"href")??le(e,"url");if(void 0===t||void 0===r)return"";const n=ae(e,"lead"),o=void 0!==n?`<p class="lp-block-cta__lead">${escapeHtml(n)}</p>`:"",i=[he(t,r,!0)],a=ae(e,"secondaryLabel"),l=le(e,"secondaryHref");return void 0!==a&&void 0!==l&&i.push(he(a,l,!1)),`<div class="lp-block-cta">${o}<div class="lp-block-cta__actions">${i.join("")}</div></div>`};function he(e,t,r){const n=isExternalHttpUrl(t)?' target="_blank" rel="noopener noreferrer"':"";return`<a class="lp-block-cta__button lp-block-cta__button--${r?"primary":"secondary"}" href="${escapeHtmlAttribute(t)}"${n}>${escapeHtml(e)}</a>`}function me(){G("callout",ce),G("image-block",ue),G("imageBlock",ue),G("image",ue),G("video-block",de),G("videoBlock",de),G("video",de),G("code-block",pe),G("codeBlock",pe),G("code",pe),G("cta-block",fe),G("ctaBlock",fe),G("cta",fe)}export{_ as TextFormat,te as isLexicalContent,re as lexicalToHtml,ne as lexicalToPlainText,F as lookupBlockRenderer,Y as lookupLexicalNode,G as registerBlockRenderer,me as registerDefaultBlocks,X as registerLexicalNode,K as registeredBlockTypes,setSanitizerDocument};
1
+ function e(e,t){if(!function(){try{const e=globalThis.process?.env;return void 0!==e&&"production"!==e.NODE_ENV}catch{return!1}}())return;const n=globalThis,r=n.__payloadLivePreviewDeprecationsWarned??=/* @__PURE__ */new Set;if(!r.has(e)){r.add(e);try{console.warn(`[payload-live-preview] ${t}`)}catch{}}}var t=/* @__PURE__ */Symbol.for("payload-live-preview.trusted-types");function n(e){const n=function(){const e=function(){const e=globalThis,n=e[t];if(void 0!==n)return n;const r={};return e[t]=r,r}();if(void 0!==e.override)return e.override;if(void 0!==e.auto)return e.auto;const n=function(){const e=globalThis.trustedTypes;if("object"==typeof e&&null!==e)return"function"==typeof e.createPolicy?e:void 0}();try{e.auto=void 0===n?null:n.createPolicy("payload-live-preview",{createHTML:e=>e})}catch{e.auto=null}return e.auto}();return null===n?e:n.createHTML(e)}var r=/* @__PURE__ */new Set(["http:","https:","mailto:","tel:"]),o=/^(?:\.{1,2}\/|[a-zA-Z0-9_-]+\/?)/,i=/^[\\/]{2}/,a=/[\t\n\r]/g,l=/[\s\u0000-\u001f\u180e\u2000-\u2029]/g,s=/^([a-z][a-z0-9+.-]*):/i;function isSafeUrl(e){if("string"!=typeof e)return!1;const t=e.trim().replace(a,"");if(0===t.length)return!1;if(t.startsWith("#")||t.startsWith("?"))return!0;if(i.test(t))return!0;if(t.startsWith("/"))return!0;try{const e=new URL(t);return r.has(e.protocol)}catch{return o.test(t)&&!function(e){const t=s.exec(e.replace(l,""))?.[1];return void 0!==t&&!r.has(`${t.toLowerCase()}:`)}(t)}}function isExternalHttpUrl(e){const t=e.trim().replace(a,"");return/^https?:\/\//i.test(t)||i.test(t)}var c=/* @__PURE__ */new Set;function u(e){c.has(e)||(c.add(e),function(e){try{console.warn(e)}catch{}}(`[live-preview] LP0409: the strict sanitizer removed \`${e}\` from written markup; the 1.x default (\`sanitizerPolicy: 'compat'\`) kept it. ${function(e){return e.startsWith("data-payload-")?"A binding inside CMS content is refused by design — an editor could otherwise aim a write at any element on the page (docs/security.md)":"id"===e||"name"===e?"CMS content that can name an element can shadow a global of that name — DOM clobbering, refused by design (docs/security.md)":"Put it on an element the template owns, or set `sanitizerPolicy: 'compat'` to keep every `data-*` as 1.x did"}(e)}.`))}var d=/* @__PURE__ */new Set(["p","br","strong","b","em","i","u","s","strike","mark","small","h1","h2","h3","h4","h5","h6","ul","ol","li","dl","dt","dd","blockquote","code","pre","kbd","samp","var","a","span","div","section","article","aside","header","footer","nav","figure","figcaption","img","picture","source","audio","video","sub","sup","hr","time","abbr","cite","q","table","thead","tbody","tfoot","tr","th","td","caption","colgroup","col"]),p=/* @__PURE__ */new Set(["input","button","textarea","select","option","label"]),f=/* @__PURE__ */new Set(["script","style","iframe","object","embed","link","meta","base","form","input","button","select","textarea","svg","math","template","frame","frameset","noframes","noscript"]),m=/* @__PURE__ */new Set(["id","class","lang","dir","title","role","tabindex"]),h="aria-",g="data-",b={a:/* @__PURE__ */new Set(["href","target","rel","download","hreflang","type"]),img:/* @__PURE__ */new Set(["src","srcset","sizes","alt","width","height","loading","decoding"]),picture:/* @__PURE__ */new Set([]),source:/* @__PURE__ */new Set(["src","srcset","sizes","type","media"]),audio:/* @__PURE__ */new Set(["src","controls","autoplay","loop","muted","preload"]),video:/* @__PURE__ */new Set(["src","poster","controls","autoplay","loop","muted","preload","width","height","playsinline"]),time:/* @__PURE__ */new Set(["datetime"]),abbr:/* @__PURE__ */new Set(["title"]),q:/* @__PURE__ */new Set(["cite"]),blockquote:/* @__PURE__ */new Set(["cite"]),table:/* @__PURE__ */new Set(["summary"]),th:/* @__PURE__ */new Set(["colspan","rowspan","scope","headers","abbr"]),td:/* @__PURE__ */new Set(["colspan","rowspan","headers"]),col:/* @__PURE__ */new Set(["span"]),colgroup:/* @__PURE__ */new Set(["span"]),ol:/* @__PURE__ */new Set(["start","reversed","type"]),li:/* @__PURE__ */new Set(["value"]),code:/* @__PURE__ */new Set(["class"]),pre:/* @__PURE__ */new Set(["class"])},y=/* @__PURE__ */new Set(["href","src","cite","poster"]),$=class extends Error{name="SanitizerEnvironmentError"},v=/* @__PURE__ */new Set(["id","name","data-payload-key","data-payload-morph","data-payload-nested-key","data-payload-nested-template"]),w=/* @__PURE__ */Symbol.for("payload-live-preview.sanitizer-document");function setSanitizerDocument(t){e("set-sanitizer-document","`setSanitizerDocument()` is removed in 3.0: pass the document per call, `sanitizeHtml(html, { document })` or `lexicalToHtml(content, { document })` (ADR 0026)."),globalThis[w]=t??void 0}function sanitizeHtml(t,r){return function(t,r,o){const i=o?.document??S();if(!i)throw"undefined"!=typeof __INLINE_BUILD__&&__INLINE_BUILD__?new Error("sanitizeHtml needs a DOM"):new $("sanitizeHtml needs a DOM; pass one per call during SSR: { document } (linkedom, jsdom).");if(""===t)return"";const a=function(e,t){const n=e?.policy??t??"strict";if(!e){const e=/* @__PURE__ */new Map;for(const[t,n]of Object.entries(b))e.set(t,n);return{allowedTags:d,attrByTag:e,allowFormControls:!1,templateMode:!1,mode:n,allowedData:/* @__PURE__ */new Set}}const r=new Set(d);if(e.additionalAllowedTags?.forEach(e=>r.add(e)),!0===e.allowFormControls)for(const e of p)r.add(e);const o=/* @__PURE__ */new Map;for(const[e,t]of Object.entries(b))o.set(e,t);for(const[t,n]of Object.entries(e.additionalAllowedAttributes??{})){const e=new Set(o.get(t));for(const t of n)e.add(t);o.set(t,e)}return{allowedTags:r,attrByTag:o,allowFormControls:!0===e.allowFormControls,templateMode:!0===e.templateMode,mode:n,allowedData:new Set(e.allowedDataAttributes?.map(e=>e.toLowerCase()))}}(o,void 0);let l=t;for(let e=0;e<6;e+=1){const e=i.createElement("template");e.innerHTML=n(l),k(e.content,a);const t=e.innerHTML;if(t===l)return t;l=t}return e("sanitizer-unsettled",`sanitizeHtml: the output did not settle after ${String(6)} passes, so it returned an empty string (ADR 0016).`),""}(t,0,r)}function S(){if("undefined"==typeof __INLINE_BUILD__||!__INLINE_BUILD__){const e=globalThis[w];if(e)return e}if("undefined"!=typeof document)return document}function k(e,t){for(const n of Array.from(e.childNodes))1===n.nodeType?H(n,t):8===n.nodeType&&n.remove()}function H(e,t){const n=e.tagName.toLowerCase();if(!f.has(n)||t.allowFormControls&&p.has(n)){if(!t.allowedTags.has(n))return k(e,t),void e.replaceWith(...e.childNodes);!function(e,t,n){const r=n.attrByTag.get(t);for(const t of Array.from(e.attributes)){const o=t.name.toLowerCase();if(o.startsWith("on")||"style"===o)e.removeAttribute(t.name);else if("is"!==o){if("strict"===n.mode){if(n.templateMode&&v.has(o))continue;if("id"===o||"name"===o||o.startsWith("data-payload-")){e.removeAttribute(t.name),"name"===o&&!0!==r?.has(o)||u(o);continue}if(o.startsWith(g)){n.allowedData.has(o)||(e.removeAttribute(t.name),u(o));continue}if(m.has(o)||o.startsWith(h))continue}else if(m.has(o)||o.startsWith(h)||o.startsWith(g))continue;r?.has(o)?y.has(o)&&!isSafeUrl(t.value)?e.removeAttribute(t.name):"srcset"!==o||T(t.value)||e.removeAttribute(t.name):e.removeAttribute(t.name)}else e.setAttribute("is","")}}(e,n,t),"a"===n&&function(e){const t=e.getAttribute("href");null!==t&&isExternalHttpUrl(t)&&(e.setAttribute("rel","noopener noreferrer"),e.hasAttribute("target")||e.setAttribute("target","_blank"))}(e),k(e,t)}else e.remove()}function T(e){for(const t of e.split(",")){const e=t.trim();if(0===e.length)continue;const[n=e]=e.split(/\s/,1);if(!isSafeUrl(n)||!isSafeUrl(e))return!1}return!0}var A=Object.freeze({"&":"&amp;","<":"&lt;",">":"&gt;",'"':"&quot;","'":"&#x27;","/":"&#x2F;","`":"&#x60;","=":"&#x3D;"}),_=/[&<>"'/`=]/g;function escapeHtml(e){return e.replace(_,e=>A[e])}var C=Object.freeze({"&":"&amp;","<":"&lt;",">":"&gt;",'"':"&quot;","'":"&#x27;"}),L=/[&<>"']/g;function escapeHtmlAttribute(e){return e.replace(L,e=>C[e])}var x={BOLD:1,ITALIC:2,STRIKETHROUGH:4,UNDERLINE:8,CODE:16,SUBSCRIPT:32,SUPERSCRIPT:64,HIGHLIGHT:128},U={1:"left",2:"center",3:"right",4:"justify"},z=/* @__PURE__ */new Set(["left","center","right","justify","start","end"]);function I(e){const t=e.format;return"string"==typeof t&&z.has(t)?t:"number"==typeof t?U[t]:void 0}function D(e){const t=e.indent;return"number"==typeof t&&t>0?t:0}function E(e){return"rtl"===e.direction?' dir="rtl"':"ltr"===e.direction?' dir="ltr"':""}function B(e){const t=I(e),n=D(e),r=[];return void 0!==t&&r.push(`lp-align-${t}`),n>0&&r.push(`lp-indent-${String(n)}`),0===r.length?"":` class="${r.join(" ")}"`}var M=/* @__PURE__ */new Set(["h1","h2","h3","h4","h5","h6"]);function N(e){return"object"==typeof e&&null!==e?e:void 0}function j(e){return N(e)}function R(e){return e.replace(/[^a-zA-Z0-9_-]/g,"-").toLowerCase()}function O(e){return"string"==typeof e&&e.length>0?e:void 0}var W=' target="_blank" rel="noopener noreferrer"',P=(e,t)=>{const n=t.renderChildren(e.children??[]),r=N(e.fields),o=function(e,t){if("internal"===t?.linkType)return function(e){const t=N(N(e)?.value),n=t?.url;if("string"==typeof n&&n.length>0)return n;const r=t?.slug;return"string"==typeof r&&r.length>0?`/${r}`:void 0}(t.doc);const n=t?.url??e.url;return"string"==typeof n&&n.length>0?n:void 0}(e,r);if(void 0===o||!isSafeUrl(o))return n;const i="string"==typeof e.title?` title="${escapeHtml(e.title)}"`:"";return`<a href="${escapeHtmlAttribute(o)}"${function(e,t,n){if(!0===t?.newTab||isExternalHttpUrl(n))return W;const r="string"==typeof e.target?e.target:"";return""===r?"":"_blank"===r?W:` target="${escapeHtml(r)}"`}(e,r,o)}${i}>${n}</a>`};function q(e){if("string"==typeof e.text)return e.text;if(!e.children)return"";let t="";for(const n of e.children)t+=q(n);return t}function F(e){return`${"number"==typeof e.width?` width="${String(e.width)}"`:""}${"number"==typeof e.height?` height="${String(e.height)}"`:""}`}function G(e){return"string"==typeof e.mimeType?` type="${escapeHtmlAttribute(e.mimeType)}"`:""}var K=/* @__PURE__ */new Map;function Z(e,t){K.set(e,t)}function V(e){return K.get(e)}function J(){return[...K.keys()]}function Q(e,t,n,r){const o=N(e.fields)??{},i="string"==typeof o.blockType?o.blockType:"",a=R(i),l=""===a?r:`${r} ${r}--${a}`;if(""!==i){const e=V(i)??V(a);if(e)return e(o,{renderChildren:t.renderChildren});t.onUnrenderedBlock?.(i,l)}return`<${n} class="${l}"></${n}>`}function X(e,t){return"number"==typeof t&&t>1?` ${e}="${String(t)}"`:""}var Y={text:e=>{let t=escapeHtml("string"==typeof e.text?e.text:"");const n="number"==typeof e.format?e.format:0;return 0!==(n&x.CODE)&&(t=`<code>${t}</code>`),0!==(n&x.BOLD)&&(t=`<strong>${t}</strong>`),0!==(n&x.ITALIC)&&(t=`<em>${t}</em>`),0!==(n&x.UNDERLINE)&&(t=`<u>${t}</u>`),0!==(n&x.STRIKETHROUGH)&&(t=`<s>${t}</s>`),0!==(n&x.SUBSCRIPT)&&(t=`<sub>${t}</sub>`),0!==(n&x.SUPERSCRIPT)&&(t=`<sup>${t}</sup>`),0!==(n&x.HIGHLIGHT)&&(t=`<mark>${t}</mark>`),t},paragraph:(e,t)=>{const n=t.renderChildren(e.children??[]);return`<p${E(e)}${B(e)}>${n}</p>`},heading:(e,t)=>{const n="string"==typeof e.tag?e.tag.toLowerCase():"h2",r=M.has(n)?n:"h2",o=t.renderChildren(e.children??[]);return`<${r}${E(e)}${B(e)}>${o}</${r}>`},list:(e,t)=>{const n="string"==typeof e.listType?e.listType:"bullet",r="number"===n?"ol":"ul",o="number"===n&&"number"==typeof e.start&&e.start>1?` start="${String(e.start)}"`:"",i="check"===n?' role="list"':"",a=t.renderChildren(e.children??[]);return`<${r}${E(e)}${B(e)}${o}${i}>${a}</${r}>`},listitem:(e,t)=>{const n=t.renderChildren(e.children??[]);if("boolean"==typeof e.checked)return`<li role="checkbox" aria-checked="${e.checked?"true":"false"}"${B(e)}>${n}</li>`;const r="number"==typeof e.value?` value="${escapeHtml(String(e.value))}"`:"";return`<li${E(e)}${B(e)}${r}>${n}</li>`},link:P,autolink:P,quote:(e,t)=>{const n=t.renderChildren(e.children??[]);return`<blockquote${E(e)}${B(e)}>${n}</blockquote>`},code:e=>{const t=R("string"==typeof e.language?e.language:"");return`<pre><code${""===t?"":` class="language-${t}"`}>${escapeHtml(q(e))}</code></pre>`},"code-highlight":e=>{const t="string"==typeof e.text?e.text:"";return`<span${"string"==typeof e.highlightType?` class="token-${R(e.highlightType)}"`:""}>${escapeHtml(t)}</span>`},linebreak:()=>"<br>",horizontalrule:()=>"<hr>",tab:()=>"\t",upload:e=>{const t=j(e.value);if(void 0===t)return"";const n=t.url;if("string"!=typeof n||!isSafeUrl(n))return"";const r="string"==typeof t.mimeType?t.mimeType:"";return r.startsWith("video/")?function(e,t){return`<video controls${F(e)}><source src="${escapeHtmlAttribute(t)}"${G(e)}></video>`}(t,n):r.startsWith("audio/")?function(e,t){return`<audio controls><source src="${escapeHtmlAttribute(t)}"${G(e)}></audio>`}(t,n):""===r||r.startsWith("image/")?function(e,t){const n="string"==typeof e.alt?escapeHtml(e.alt):"";return`<img src="${escapeHtmlAttribute(t)}" alt="${n}"${F(e)} loading="lazy" decoding="async">`}(t,n):function(e,t){const n="string"==typeof e.filename?escapeHtml(e.filename):escapeHtml(t);return`<a href="${escapeHtmlAttribute(t)}" target="_blank" rel="noopener noreferrer">${n}</a>`}(t,n)},relationship:e=>{const t="string"==typeof e.relationTo?e.relationTo:"",n=N(e.value),r=escapeHtml((n&&function(e){const t=O(e.title)??O(e.name)??O(e.slug);return void 0!==t?t:void 0===e.id?void 0:String(e.id)}(n))??`#${t}`),o=R(t),i=""===o?' class="lp-relation"':` class="lp-relation lp-relation--${o}"`,a=n?.url;return"string"==typeof a&&isSafeUrl(a)?`<a href="${escapeHtmlAttribute(a)}"${i}>${r}</a>`:`<span${i}>${r}</span>`},block:(e,t)=>Q(e,t,"div","lp-block"),inlineBlock:(e,t)=>Q(e,t,"span","lp-inline-block"),table:(e,t)=>`<table${E(e)}><tbody>${t.renderChildren(e.children??[])}</tbody></table>`,tablerow:(e,t)=>`<tr>${t.renderChildren(e.children??[])}</tr>`,tablecell:(e,t)=>{const n="number"==typeof e.headerState?e.headerState:0,r=3&n?"th":"td";return`<${r}${1===n?' scope="col"':2===n?' scope="row"':""}${X("colspan",e.colSpan)}${X("rowspan",e.rowSpan)}>${t.renderChildren(e.children??[])}</${r}>`}},ee=/* @__PURE__ */new Map;function te(e,t){ee.set(e,t)}function ne(e){return ee.get(e)??Y[e]}var re=!1;function oe(e){if("object"!=typeof e||null===e)return!1;if(!("root"in e))return!1;const t=e.root;return"object"==typeof t&&null!==t&&"children"in t&&Array.isArray(t.children)}function ie(e,t={}){if(!oe(e))return"";const n=function(e){const t={renderChildren:e=>{let n="";for(const r of e)n+=le(r,t);return n},resolveAlignment:I,resolveIndent:D,onUnrenderedBlock:e};return t}(t.onUnrenderedBlock).renderChildren(e.root.children);return!1===t.sanitize?n:void 0!==t.document?sanitizeHtml(n,{document:t.document}):!0===t.requireDocument||void 0!==S()?sanitizeHtml(n):(function(){if(!re){re=!0;try{console.warn('[live-preview] lexicalToHtml() has no sanitizer document and returned unsanitised HTML; pass { document } (linkedom, jsdom) per call. 3.0 throws here instead: opt in now with { requireDocument: true }. See "HTML sanitization" in docs/security.md.')}catch{}}}(),n)}function ae(e){return oe(e)?e.root.children.map(se).join("\n").trim():""}function le(e,t){const n=ne(e.type);return n?n(e,t):void 0!==e.children?t.renderChildren(e.children):""}function se(e){if("string"==typeof e.text)return e.text;if("linebreak"===e.type)return"\n";if(void 0===e.children)return"";let t="";for(const n of e.children)t+=se(n);return t}function ce(e,t){const n=e[t];return"string"==typeof n&&n.length>0?n:void 0}function ue(e,t){const n=ce(e,t);return void 0!==n&&isSafeUrl(n)?n:void 0}function de(e){const t=ce(e,"caption");return void 0!==t?`<figcaption>${escapeHtml(t)}</figcaption>`:""}var pe=(e,t)=>{const n=R(ce(e,"importance")??"info"),r=ce(e,"title"),o=ce(e,"text"),i=function(e){const t=e.body??e.content;if("object"!=typeof t||null===t)return;const n=t.root;return n&&Array.isArray(n.children)?n.children:void 0}(e);return`<aside class="lp-block-callout lp-block-callout--${n}">${void 0!==r?`<strong>${escapeHtml(r)}</strong>`:""}${void 0!==i?t.renderChildren(i):void 0!==o?`<p>${escapeHtml(o)}</p>`:""}</aside>`},fe=e=>{const t=j(e.image),n=t?.url??ue(e,"imageUrl");if(void 0===n||!isSafeUrl(n))return"";const r=t?.alt??ce(e,"alt")??"";return`<figure class="lp-block-image"><img src="${escapeHtmlAttribute(n)}" alt="${escapeHtmlAttribute(r)}"${function(e){return`${"number"==typeof e?.width?` width="${String(e.width)}"`:""}${"number"==typeof e?.height?` height="${String(e.height)}"`:""}`}(t)} loading="lazy" decoding="async">${de(e)}</figure>`},me=e=>{const t=j(e.video),n=t?.url??ue(e,"videoUrl");if(void 0===n||!isSafeUrl(n))return"";const r=t?.mimeType??ce(e,"mimeType"),o=void 0!==r?` type="${escapeHtmlAttribute(r)}"`:"",i=ue(e,"poster");return`<figure class="lp-block-video"><video controls${void 0!==i?` poster="${escapeHtmlAttribute(i)}"`:""}><source src="${escapeHtmlAttribute(n)}"${o}></video>${de(e)}</figure>`},he=e=>{const t=ce(e,"code")??ce(e,"content");if(void 0===t)return"";const n=R(ce(e,"language")??""),r=""===n?"":` class="language-${n}"`;return`<figure class="lp-block-code">${de(e)}<pre><code${r}>${escapeHtml(t)}</code></pre></figure>`},ge=e=>{const t=ce(e,"label")??ce(e,"text"),n=ue(e,"href")??ue(e,"url");if(void 0===t||void 0===n)return"";const r=ce(e,"lead"),o=void 0!==r?`<p class="lp-block-cta__lead">${escapeHtml(r)}</p>`:"",i=[be(t,n,!0)],a=ce(e,"secondaryLabel"),l=ue(e,"secondaryHref");return void 0!==a&&void 0!==l&&i.push(be(a,l,!1)),`<div class="lp-block-cta">${o}<div class="lp-block-cta__actions">${i.join("")}</div></div>`};function be(e,t,n){const r=isExternalHttpUrl(t)?' target="_blank" rel="noopener noreferrer"':"";return`<a class="lp-block-cta__button lp-block-cta__button--${n?"primary":"secondary"}" href="${escapeHtmlAttribute(t)}"${r}>${escapeHtml(e)}</a>`}function ye(){Z("callout",pe),Z("image-block",fe),Z("imageBlock",fe),Z("image",fe),Z("video-block",me),Z("videoBlock",me),Z("video",me),Z("code-block",he),Z("codeBlock",he),Z("code",he),Z("cta-block",ge),Z("ctaBlock",ge),Z("cta",ge)}export{x as TextFormat,oe as isLexicalContent,ie as lexicalToHtml,ae as lexicalToPlainText,V as lookupBlockRenderer,ne as lookupLexicalNode,Z as registerBlockRenderer,ye as registerDefaultBlocks,te as registerLexicalNode,J as registeredBlockTypes,setSanitizerDocument};
2
2
  //# sourceMappingURL=lexical.js.map