@bettercms-ai/kit 3.1.26 → 3.1.28
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/dist/controls/media.js +7 -1
- package/dist/controls/media.js.map +1 -1
- package/dist/controls/reference.js +2 -2
- package/dist/controls/reference.js.map +1 -1
- package/dist/controls/rich-text/editor.d.ts +1 -1
- package/dist/controls/rich-text/editor.js +25 -2
- package/dist/controls/rich-text/editor.js.map +1 -1
- package/dist/controls/rich-text/markdown.js +1 -1
- package/dist/controls/rich-text/markdown.js.map +1 -1
- package/dist/controls/slot.js +1 -1
- package/dist/controls/slot.js.map +1 -1
- package/dist/engine/frame.js +3 -1
- package/dist/engine/frame.js.map +1 -1
- package/dist/engine/kit-field.js +2 -0
- package/dist/engine/kit-field.js.map +1 -1
- package/dist/engine/slot.js +1 -1
- package/dist/engine/slot.js.map +1 -1
- package/dist/styles.css +1 -1
- package/package.json +1 -1
|
@@ -37,7 +37,7 @@ function inline(node, inCode = false) {
|
|
|
37
37
|
case "BR": return " \n";
|
|
38
38
|
case "IMG": return ` ?? ""})`;
|
|
39
39
|
case "A":
|
|
40
|
-
if (el.hasAttribute("target")) return el.outerHTML;
|
|
40
|
+
if (el.hasAttribute("target") || el.hasAttribute("rel")) return el.outerHTML;
|
|
41
41
|
return `[${kids()}](${el.getAttribute("href") ?? ""})`;
|
|
42
42
|
default: return kids();
|
|
43
43
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"markdown.js","names":[],"sources":["../../../src/controls/rich-text/markdown.ts"],"sourcesContent":["/**\n * RICH TEXT · a small HTML ⇄ Markdown converter for the field's Markdown mode and for pasting (V2 HEAD\n * controls/rich-text/markdown.ts). Covers headings, bold/italic/strike/underline, inline code, links, images, lists,\n * quotes, code blocks, rules and paragraphs. Anything else is kept as one line of raw HTML, which the reverse direction\n * passes through untouched (and the field's own rules then decide whether it may stay).\n */\nimport { esc, escAttr, sanitize } from \"./dom\";\n\n/* ── HTML → Markdown ───────────────────────────────────────────────── */\nconst escText = (s: string) => s.replace(/([\\\\`*[\\]~])/g, \"\\\\$1\");\n\nfunction inline(node: Node, inCode = false): string {\n if (node.nodeType === 3) {\n const t = (node.textContent ?? \"\").replace(/ /g, \" \");\n return inCode ? t : escText(t.replace(/\\s+/g, \" \"));\n }\n if (node.nodeType !== 1) return \"\";\n const el = node as HTMLElement;\n const kids = () => Array.from(el.childNodes).map((c) => inline(c, inCode)).join(\"\");\n const wrap = (mark: string) => {\n const inner = kids();\n if (!inner.trim()) return inner;\n const lead = inner.match(/^\\s*/)![0];\n const trail = inner.match(/\\s*$/)![0];\n return `${lead}${mark}${inner.trim()}${mark}${trail}`;\n };\n switch (el.tagName) {\n case \"STRONG\":\n case \"B\":\n return wrap(\"**\");\n case \"EM\":\n case \"I\":\n return wrap(\"_\");\n case \"S\":\n case \"STRIKE\":\n case \"DEL\":\n return wrap(\"~~\");\n case \"U\":\n return `<u>${kids()}</u>`;\n // footnote markers are written elsewhere; a plain x² / x₂ stays inline HTML, which Markdown allows\n case \"SUP\":\n return el.matches(\"[data-footnote]\") || el.querySelector(\":scope > a[href*='-fn-']\") ? kids() : `<sup>${kids()}</sup>`;\n case \"SUB\":\n return `<sub>${kids()}</sub>`;\n case \"CODE\":\n return \"`\" + (el.textContent ?? \"\").replace(/`/g, \"\") + \"`\";\n case \"BR\":\n return \" \\n\";\n case \"IMG\":\n return ` ?? \"\"})`;\n case \"A\":\n // a link that carries more than its address (opens in a new tab) keeps its markup, so Markdown mode drops nothing\n if (el.hasAttribute(\"target\")) return el.outerHTML;\n return `[${kids()}](${el.getAttribute(\"href\") ?? \"\"})`;\n default:\n return kids();\n }\n}\n\nconst isList = (n: Node) => n.nodeType === 1 && /^(UL|OL)$/.test((n as HTMLElement).tagName);\n\n/**\n * A list as Markdown lines. A list nested in an item is written under it, indented by the width of the item's marker\n * (RT-035), so the level survives the trip. Null (kept as markup) for what Markdown cannot say: an item of several\n * paragraphs, or text after an item's nested list.\n */\nfunction list(el: HTMLElement, pad = \"\"): string | null {\n if (el.querySelector(\"li > p + p\")) return null;\n const lines: string[] = [];\n let n = 0;\n for (const li of Array.from(el.children)) {\n if (li.tagName !== \"LI\") continue;\n const marker = el.tagName === \"OL\" ? `${++n}. ` : \"- \";\n const kids = Array.from(li.childNodes);\n const at = kids.findIndex(isList);\n const own = at < 0 ? kids : kids.slice(0, at);\n const rest = at < 0 ? [] : kids.slice(at);\n if (rest.some((k) => !isList(k) && (k.textContent ?? \"\").trim())) return null;\n lines.push(pad + marker + own.map((k) => inline(k)).join(\"\").trim().replace(/ {2}\\n/g, \" \"));\n for (const k of rest) {\n if (!isList(k)) continue;\n const inner = list(k as HTMLElement, pad + \" \".repeat(marker.length));\n if (inner === null) return null;\n lines.push(inner);\n }\n }\n return lines.join(\"\\n\");\n}\n\nexport function htmlToMarkdown(html: string): string {\n const doc = new DOMParser().parseFromString(`<body>${html}</body>`, \"text/html\");\n const out: string[] = [];\n for (const node of Array.from(doc.body.childNodes)) {\n if (node.nodeType === 3) {\n const t = inline(node).trim();\n if (t) out.push(t);\n continue;\n }\n if (node.nodeType !== 1) continue;\n const el = node as HTMLElement;\n const tag = el.tagName;\n const raw = () => out.push(el.outerHTML.replace(/\\n+/g, \" \"));\n if (/^H[1-6]$/.test(tag)) out.push(`${\"#\".repeat(Number(tag[1]))} ${inline(el).trim()}`);\n else if (tag === \"P\") {\n const s = inline(el).trim().replace(/^([#>]|\\d+\\.|[-+] |-{3})/, \"\\\\$1\");\n if (s) out.push(s);\n } else if (tag === \"UL\" || tag === \"OL\") {\n const l = list(el);\n if (l === null) raw();\n else out.push(l);\n } else if (tag === \"BLOCKQUOTE\") {\n const paras = el.querySelector(\"p,div\") ? Array.from(el.children).map((c) => inline(c).trim()) : [inline(el).trim()];\n out.push(paras.filter(Boolean).map((p) => p.split(\"\\n\").map((l) => `> ${l}`).join(\"\\n\")).join(\"\\n>\\n\"));\n } else if (tag === \"PRE\") out.push(\"```\\n\" + (el.textContent ?? \"\").replace(/\\n$/, \"\") + \"\\n```\");\n else if (tag === \"HR\") out.push(\"---\");\n else if (tag === \"FIGURE\" && el.querySelector(\":scope > img\")) {\n const img = el.querySelector(\"img\")!;\n const cap = el.querySelector(\"figcaption\")?.textContent?.trim();\n out.push(` ?? \"\"}${cap ? ` \"${cap.replace(/\"/g, \"'\")}\"` : \"\"})`);\n } else raw();\n }\n return out.join(\"\\n\\n\") + (out.length ? \"\\n\" : \"\");\n}\n\n/* ── Markdown → HTML ───────────────────────────────────────────────── */\nconst safeHref = (h: string) => (/^\\s*(javascript|vbscript|data:text)/i.test(h) ? \"#\" : h);\n\nexport function inlineMd(src: string): string {\n const slots: string[] = [];\n const hold = (html: string) => `\\u0000${slots.push(html) - 1}\\u0000`;\n let s = src.replace(/\\\\([\\\\`*_[\\]~#>+\\-.!])/g, (_, c: string) => hold(esc(c)));\n s = s.replace(/`([^`]+)`/g, (_, c: string) => hold(`<code>${esc(c)}</code>`));\n s = s.replace(/<a [^>]*>.*?<\\/a>/g, (m) => hold(m));\n s = esc(s);\n s = s.replace(/<(\\/?)u>/g, \"<$1u>\");\n s = s.replace(/!\\[([^\\]]*)\\]\\(([^)\\s]+)\\)/g, (_, a: string, u: string) => hold(`<img src=\"${escAttr(safeHref(u))}\" alt=\"${escAttr(a)}\">`));\n s = s.replace(/\\[([^\\]]+)\\]\\(([^)\\s]+)\\)/g, (_, t: string, u: string) => `<a href=\"${escAttr(safeHref(u))}\">${t}</a>`);\n s = s.replace(/\\*\\*([^*]+?)\\*\\*/g, \"<strong>$1</strong>\");\n s = s.replace(/__([^_]+?)__/g, \"<strong>$1</strong>\");\n s = s.replace(/(^|[^\\w*])\\*([^*\\s][^*]*?)\\*(?!\\*)/g, \"$1<em>$2</em>\");\n s = s.replace(/(^|[^\\w])_([^_\\s][^_]*?)_(?!\\w)/g, \"$1<em>$2</em>\");\n s = s.replace(/~~([^~]+?)~~/g, \"<s>$1</s>\");\n s = s.replace(/ {2,}\\n/g, \"<br>\").replace(/\\n/g, \" \");\n return s.replace(/\\u0000(\\d+)\\u0000/g, (_, i: string) => slots[Number(i)]);\n}\n\nconst RAW_BLOCK = /^<\\/?(div|table|figure|details|ul|ol|p|h[1-6]|blockquote|pre|hr|section|aside)\\b/i;\nconst RE = {\n fence: /^\\s*```/,\n heading: /^(#{1,6})\\s+(.*?)\\s*#*\\s*$/,\n hr: /^\\s*(-{3,}|\\*{3,}|_{3,})\\s*$/,\n image: /^!\\[([^\\]]*)\\]\\(([^)\\s]+)(?:\\s+\"([^\"]*)\")?\\)\\s*$/,\n quote: /^\\s*>/,\n ul: /^\\s*[-*+]\\s+(.*)$/,\n ol: /^\\s*\\d+[.)]\\s+(.*)$/,\n};\ntype ListLine = { indent: number; ordered: boolean; text: string };\n/**\n * A run of list lines as lists. A line indented two or more spaces past an item is that item's nested list (RT-035),\n * and a shallower line closes it; a line of the other kind at the same level starts a new list, as it always did.\n */\nfunction listHtml(items: ListLine[]): string {\n let html = \"\";\n for (let i = 0; i < items.length; ) {\n const { ordered, indent } = items[i];\n const tag = ordered ? \"ol\" : \"ul\";\n html += `<${tag}>`;\n while (i < items.length && items[i].ordered === ordered) {\n const item = items[i++];\n const kids: ListLine[] = [];\n while (i < items.length && items[i].indent >= indent + 2) kids.push(items[i++]);\n html += `<li>${inlineMd(item.text)}${kids.length ? listHtml(kids) : \"\"}</li>`;\n }\n html += `</${tag}>`;\n }\n return html;\n}\nconst startsBlock =(l: string) => RE.fence.test(l) || RE.heading.test(l) || RE.hr.test(l) || RE.quote.test(l) || RE.ul.test(l) || RE.ol.test(l) || RAW_BLOCK.test(l.trim());\n\n/** Throws on Markdown it cannot read (e.g. an unclosed code fence). */\nexport function markdownToHtml(md: string): string {\n const lines = md.replace(/\\r\\n?/g, \"\\n\").split(\"\\n\");\n const out: string[] = [];\n let i = 0;\n while (i < lines.length) {\n const line = lines[i];\n if (!line.trim()) {\n i++;\n continue;\n }\n if (RE.fence.test(line)) {\n const code: string[] = [];\n i++;\n while (i < lines.length && !RE.fence.test(lines[i])) code.push(lines[i++]);\n if (i >= lines.length) throw new Error(\"Unclosed code block\");\n i++;\n out.push(`<pre>${esc(code.join(\"\\n\"))}</pre>`);\n continue;\n }\n if (RAW_BLOCK.test(line.trim())) {\n const raw: string[] = [];\n while (i < lines.length && lines[i].trim()) raw.push(lines[i++]);\n out.push(raw.join(\" \"));\n continue;\n }\n let m = line.match(RE.heading);\n if (m) {\n out.push(`<h${m[1].length}>${inlineMd(m[2])}</h${m[1].length}>`);\n i++;\n continue;\n }\n if (RE.hr.test(line)) {\n out.push(\"<hr>\");\n i++;\n continue;\n }\n m = line.match(RE.image);\n if (m) {\n // an image keeps no caption in production rich text: a title becomes the line under it, never dropped\n out.push(`<figure><img src=\"${escAttr(safeHref(m[2]))}\" alt=\"${escAttr(m[1])}\"></figure>${m[3] ? `<p>${esc(m[3])}</p>` : \"\"}`);\n i++;\n continue;\n }\n if (RE.quote.test(line)) {\n const q: string[] = [];\n while (i < lines.length && RE.quote.test(lines[i])) q.push(lines[i++].replace(/^\\s*> ?/, \"\"));\n out.push(`<blockquote>${q.join(\"\\n\").split(/\\n\\s*\\n/).map(inlineMd).join(\"<br><br>\")}</blockquote>`);\n continue;\n }\n if (RE.ul.test(line) || RE.ol.test(line)) {\n const items: ListLine[] = [];\n while (i < lines.length && (RE.ul.test(lines[i]) || RE.ol.test(lines[i]))) {\n const l = lines[i++];\n const ordered = !RE.ul.test(l);\n items.push({ indent: l.match(/^\\s*/)![0].replace(/\\t/g, \" \").length, ordered, text: l.match(ordered ? RE.ol : RE.ul)![1] });\n }\n out.push(listHtml(items));\n continue;\n }\n const para: string[] = [];\n while (i < lines.length && lines[i].trim() && (para.length === 0 || !startsBlock(lines[i]))) para.push(lines[i++]);\n out.push(`<p>${inlineMd(para.join(\"\\n\"))}</p>`);\n }\n return sanitize(out.join(\"\"));\n}\n\n/** Does pasted plain text look like Markdown worth converting into blocks? */\nexport const looksLikeMarkdown =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K;CAChD;CACA,OAAO,SAAS,IAAI,KAAK,EAAE,CAAC;AAC9B;;AAGA,IAAa,qBAAqB,MAAc,UAAU,KAAK,CAAC,KAAK,6CAA6C,KAAK,CAAC,KAAK,oCAAoC,KAAK,CAAC"}
|
|
1
|
+
{"version":3,"file":"markdown.js","names":[],"sources":["../../../src/controls/rich-text/markdown.ts"],"sourcesContent":["/**\n * RICH TEXT · a small HTML ⇄ Markdown converter for the field's Markdown mode and for pasting (V2 HEAD\n * controls/rich-text/markdown.ts). Covers headings, bold/italic/strike/underline, inline code, links, images, lists,\n * quotes, code blocks, rules and paragraphs. Anything else is kept as one line of raw HTML, which the reverse direction\n * passes through untouched (and the field's own rules then decide whether it may stay).\n */\nimport { esc, escAttr, sanitize } from \"./dom\";\n\n/* ── HTML → Markdown ───────────────────────────────────────────────── */\nconst escText = (s: string) => s.replace(/([\\\\`*[\\]~])/g, \"\\\\$1\");\n\nfunction inline(node: Node, inCode = false): string {\n if (node.nodeType === 3) {\n const t = (node.textContent ?? \"\").replace(/ /g, \" \");\n return inCode ? t : escText(t.replace(/\\s+/g, \" \"));\n }\n if (node.nodeType !== 1) return \"\";\n const el = node as HTMLElement;\n const kids = () => Array.from(el.childNodes).map((c) => inline(c, inCode)).join(\"\");\n const wrap = (mark: string) => {\n const inner = kids();\n if (!inner.trim()) return inner;\n const lead = inner.match(/^\\s*/)![0];\n const trail = inner.match(/\\s*$/)![0];\n return `${lead}${mark}${inner.trim()}${mark}${trail}`;\n };\n switch (el.tagName) {\n case \"STRONG\":\n case \"B\":\n return wrap(\"**\");\n case \"EM\":\n case \"I\":\n return wrap(\"_\");\n case \"S\":\n case \"STRIKE\":\n case \"DEL\":\n return wrap(\"~~\");\n case \"U\":\n return `<u>${kids()}</u>`;\n // footnote markers are written elsewhere; a plain x² / x₂ stays inline HTML, which Markdown allows\n case \"SUP\":\n return el.matches(\"[data-footnote]\") || el.querySelector(\":scope > a[href*='-fn-']\") ? kids() : `<sup>${kids()}</sup>`;\n case \"SUB\":\n return `<sub>${kids()}</sub>`;\n case \"CODE\":\n return \"`\" + (el.textContent ?? \"\").replace(/`/g, \"\") + \"`\";\n case \"BR\":\n return \" \\n\";\n case \"IMG\":\n return ` ?? \"\"})`;\n case \"A\":\n // a link that carries more than its address (a new tab, or a rel such as nofollow) keeps its markup, so Markdown\n // mode drops nothing\n if (el.hasAttribute(\"target\") || el.hasAttribute(\"rel\")) return el.outerHTML;\n return `[${kids()}](${el.getAttribute(\"href\") ?? \"\"})`;\n default:\n return kids();\n }\n}\n\nconst isList = (n: Node) => n.nodeType === 1 && /^(UL|OL)$/.test((n as HTMLElement).tagName);\n\n/**\n * A list as Markdown lines. A list nested in an item is written under it, indented by the width of the item's marker\n * (RT-035), so the level survives the trip. Null (kept as markup) for what Markdown cannot say: an item of several\n * paragraphs, or text after an item's nested list.\n */\nfunction list(el: HTMLElement, pad = \"\"): string | null {\n if (el.querySelector(\"li > p + p\")) return null;\n const lines: string[] = [];\n let n = 0;\n for (const li of Array.from(el.children)) {\n if (li.tagName !== \"LI\") continue;\n const marker = el.tagName === \"OL\" ? `${++n}. ` : \"- \";\n const kids = Array.from(li.childNodes);\n const at = kids.findIndex(isList);\n const own = at < 0 ? kids : kids.slice(0, at);\n const rest = at < 0 ? [] : kids.slice(at);\n if (rest.some((k) => !isList(k) && (k.textContent ?? \"\").trim())) return null;\n lines.push(pad + marker + own.map((k) => inline(k)).join(\"\").trim().replace(/ {2}\\n/g, \" \"));\n for (const k of rest) {\n if (!isList(k)) continue;\n const inner = list(k as HTMLElement, pad + \" \".repeat(marker.length));\n if (inner === null) return null;\n lines.push(inner);\n }\n }\n return lines.join(\"\\n\");\n}\n\nexport function htmlToMarkdown(html: string): string {\n const doc = new DOMParser().parseFromString(`<body>${html}</body>`, \"text/html\");\n const out: string[] = [];\n for (const node of Array.from(doc.body.childNodes)) {\n if (node.nodeType === 3) {\n const t = inline(node).trim();\n if (t) out.push(t);\n continue;\n }\n if (node.nodeType !== 1) continue;\n const el = node as HTMLElement;\n const tag = el.tagName;\n const raw = () => out.push(el.outerHTML.replace(/\\n+/g, \" \"));\n if (/^H[1-6]$/.test(tag)) out.push(`${\"#\".repeat(Number(tag[1]))} ${inline(el).trim()}`);\n else if (tag === \"P\") {\n const s = inline(el).trim().replace(/^([#>]|\\d+\\.|[-+] |-{3})/, \"\\\\$1\");\n if (s) out.push(s);\n } else if (tag === \"UL\" || tag === \"OL\") {\n const l = list(el);\n if (l === null) raw();\n else out.push(l);\n } else if (tag === \"BLOCKQUOTE\") {\n const paras = el.querySelector(\"p,div\") ? Array.from(el.children).map((c) => inline(c).trim()) : [inline(el).trim()];\n out.push(paras.filter(Boolean).map((p) => p.split(\"\\n\").map((l) => `> ${l}`).join(\"\\n\")).join(\"\\n>\\n\"));\n } else if (tag === \"PRE\") out.push(\"```\\n\" + (el.textContent ?? \"\").replace(/\\n$/, \"\") + \"\\n```\");\n else if (tag === \"HR\") out.push(\"---\");\n else if (tag === \"FIGURE\" && el.querySelector(\":scope > img\")) {\n const img = el.querySelector(\"img\")!;\n const cap = el.querySelector(\"figcaption\")?.textContent?.trim();\n out.push(` ?? \"\"}${cap ? ` \"${cap.replace(/\"/g, \"'\")}\"` : \"\"})`);\n } else raw();\n }\n return out.join(\"\\n\\n\") + (out.length ? \"\\n\" : \"\");\n}\n\n/* ── Markdown → HTML ───────────────────────────────────────────────── */\nconst safeHref = (h: string) => (/^\\s*(javascript|vbscript|data:text)/i.test(h) ? \"#\" : h);\n\nexport function inlineMd(src: string): string {\n const slots: string[] = [];\n const hold = (html: string) => `\\u0000${slots.push(html) - 1}\\u0000`;\n let s = src.replace(/\\\\([\\\\`*_[\\]~#>+\\-.!])/g, (_, c: string) => hold(esc(c)));\n s = s.replace(/`([^`]+)`/g, (_, c: string) => hold(`<code>${esc(c)}</code>`));\n s = s.replace(/<a [^>]*>.*?<\\/a>/g, (m) => hold(m));\n s = esc(s);\n s = s.replace(/<(\\/?)u>/g, \"<$1u>\");\n s = s.replace(/!\\[([^\\]]*)\\]\\(([^)\\s]+)\\)/g, (_, a: string, u: string) => hold(`<img src=\"${escAttr(safeHref(u))}\" alt=\"${escAttr(a)}\">`));\n s = s.replace(/\\[([^\\]]+)\\]\\(([^)\\s]+)\\)/g, (_, t: string, u: string) => `<a href=\"${escAttr(safeHref(u))}\">${t}</a>`);\n s = s.replace(/\\*\\*([^*]+?)\\*\\*/g, \"<strong>$1</strong>\");\n s = s.replace(/__([^_]+?)__/g, \"<strong>$1</strong>\");\n s = s.replace(/(^|[^\\w*])\\*([^*\\s][^*]*?)\\*(?!\\*)/g, \"$1<em>$2</em>\");\n s = s.replace(/(^|[^\\w])_([^_\\s][^_]*?)_(?!\\w)/g, \"$1<em>$2</em>\");\n s = s.replace(/~~([^~]+?)~~/g, \"<s>$1</s>\");\n s = s.replace(/ {2,}\\n/g, \"<br>\").replace(/\\n/g, \" \");\n return s.replace(/\\u0000(\\d+)\\u0000/g, (_, i: string) => slots[Number(i)]);\n}\n\nconst RAW_BLOCK = /^<\\/?(div|table|figure|details|ul|ol|p|h[1-6]|blockquote|pre|hr|section|aside)\\b/i;\nconst RE = {\n fence: /^\\s*```/,\n heading: /^(#{1,6})\\s+(.*?)\\s*#*\\s*$/,\n hr: /^\\s*(-{3,}|\\*{3,}|_{3,})\\s*$/,\n image: /^!\\[([^\\]]*)\\]\\(([^)\\s]+)(?:\\s+\"([^\"]*)\")?\\)\\s*$/,\n quote: /^\\s*>/,\n ul: /^\\s*[-*+]\\s+(.*)$/,\n ol: /^\\s*\\d+[.)]\\s+(.*)$/,\n};\ntype ListLine = { indent: number; ordered: boolean; text: string };\n/**\n * A run of list lines as lists. A line indented two or more spaces past an item is that item's nested list (RT-035),\n * and a shallower line closes it; a line of the other kind at the same level starts a new list, as it always did.\n */\nfunction listHtml(items: ListLine[]): string {\n let html = \"\";\n for (let i = 0; i < items.length; ) {\n const { ordered, indent } = items[i];\n const tag = ordered ? \"ol\" : \"ul\";\n html += `<${tag}>`;\n while (i < items.length && items[i].ordered === ordered) {\n const item = items[i++];\n const kids: ListLine[] = [];\n while (i < items.length && items[i].indent >= indent + 2) kids.push(items[i++]);\n html += `<li>${inlineMd(item.text)}${kids.length ? listHtml(kids) : \"\"}</li>`;\n }\n html += `</${tag}>`;\n }\n return html;\n}\nconst startsBlock =(l: string) => RE.fence.test(l) || RE.heading.test(l) || RE.hr.test(l) || RE.quote.test(l) || RE.ul.test(l) || RE.ol.test(l) || RAW_BLOCK.test(l.trim());\n\n/** Throws on Markdown it cannot read (e.g. an unclosed code fence). */\nexport function markdownToHtml(md: string): string {\n const lines = md.replace(/\\r\\n?/g, \"\\n\").split(\"\\n\");\n const out: string[] = [];\n let i = 0;\n while (i < lines.length) {\n const line = lines[i];\n if (!line.trim()) {\n i++;\n continue;\n }\n if (RE.fence.test(line)) {\n const code: string[] = [];\n i++;\n while (i < lines.length && !RE.fence.test(lines[i])) code.push(lines[i++]);\n if (i >= lines.length) throw new Error(\"Unclosed code block\");\n i++;\n out.push(`<pre>${esc(code.join(\"\\n\"))}</pre>`);\n continue;\n }\n if (RAW_BLOCK.test(line.trim())) {\n const raw: string[] = [];\n while (i < lines.length && lines[i].trim()) raw.push(lines[i++]);\n out.push(raw.join(\" \"));\n continue;\n }\n let m = line.match(RE.heading);\n if (m) {\n out.push(`<h${m[1].length}>${inlineMd(m[2])}</h${m[1].length}>`);\n i++;\n continue;\n }\n if (RE.hr.test(line)) {\n out.push(\"<hr>\");\n i++;\n continue;\n }\n m = line.match(RE.image);\n if (m) {\n // an image keeps no caption in production rich text: a title becomes the line under it, never dropped\n out.push(`<figure><img src=\"${escAttr(safeHref(m[2]))}\" alt=\"${escAttr(m[1])}\"></figure>${m[3] ? `<p>${esc(m[3])}</p>` : \"\"}`);\n i++;\n continue;\n }\n if (RE.quote.test(line)) {\n const q: string[] = [];\n while (i < lines.length && RE.quote.test(lines[i])) q.push(lines[i++].replace(/^\\s*> ?/, \"\"));\n out.push(`<blockquote>${q.join(\"\\n\").split(/\\n\\s*\\n/).map(inlineMd).join(\"<br><br>\")}</blockquote>`);\n continue;\n }\n if (RE.ul.test(line) || RE.ol.test(line)) {\n const items: ListLine[] = [];\n while (i < lines.length && (RE.ul.test(lines[i]) || RE.ol.test(lines[i]))) {\n const l = lines[i++];\n const ordered = !RE.ul.test(l);\n items.push({ indent: l.match(/^\\s*/)![0].replace(/\\t/g, \" \").length, ordered, text: l.match(ordered ? RE.ol : RE.ul)![1] });\n }\n out.push(listHtml(items));\n continue;\n }\n const para: string[] = [];\n while (i < lines.length && lines[i].trim() && (para.length === 0 || !startsBlock(lines[i]))) para.push(lines[i++]);\n out.push(`<p>${inlineMd(para.join(\"\\n\"))}</p>`);\n }\n return sanitize(out.join(\"\"));\n}\n\n/** Does pasted plain text look like Markdown worth converting into blocks? */\nexport const looksLikeMarkdown = (t: string) => /\\n\\s*\\n/.test(t) || /^(#{1,6}\\s|[-*+]\\s|\\d+[.)]\\s|>\\s|```|---)/m.test(t) || /\\*\\*[^*]+\\*\\*|\\[[^\\]]+\\]\\([^)]+\\)/.test(t);\n"],"mappings":";;;;;;;;AASA,IAAM,WAAW,MAAc,EAAE,QAAQ,iBAAiB,MAAM;AAEhE,SAAS,OAAO,MAAY,SAAS,OAAe;CAClD,IAAI,KAAK,aAAa,GAAG;EACvB,MAAM,KAAK,KAAK,eAAe,GAAA,CAAI,QAAQ,MAAM,GAAG;EACpD,OAAO,SAAS,IAAI,QAAQ,EAAE,QAAQ,QAAQ,GAAG,CAAC;CACpD;CACA,IAAI,KAAK,aAAa,GAAG,OAAO;CAChC,MAAM,KAAK;CACX,MAAM,aAAa,MAAM,KAAK,GAAG,UAAU,CAAC,CAAC,KAAK,MAAM,OAAO,GAAG,MAAM,CAAC,CAAC,CAAC,KAAK,EAAE;CAClF,MAAM,QAAQ,SAAiB;EAC7B,MAAM,QAAQ,KAAK;EACnB,IAAI,CAAC,MAAM,KAAK,GAAG,OAAO;EAC1B,MAAM,OAAO,MAAM,MAAM,MAAM,CAAC,C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E,MAAM,IAAI,MAAM;IAChB,MAAM,UAAU,CAAC,GAAG,GAAG,KAAK,CAAC;IAC7B,MAAM,KAAK;KAAE,QAAQ,EAAE,MAAM,MAAM,CAAC,CAAE,EAAE,CAAC,QAAQ,OAAO,MAAM,CAAC,CAAC;KAAQ;KAAS,MAAM,EAAE,MAAM,UAAU,GAAG,KAAK,GAAG,EAAE,CAAC,CAAE;IAAG,CAAC;GAC/H;GACA,IAAI,KAAK,SAAS,KAAK,CAAC;GACxB;EACF;EACA,MAAM,OAAiB,CAAC;EACxB,OAAO,IAAI,MAAM,UAAU,MAAM,EAAE,CAAC,KAAK,MAAM,KAAK,WAAW,KAAK,CAAC,YAAY,MAAM,EAAE,IAAI,KAAK,KAAK,MAAM,IAAI;EACjH,IAAI,KAAK,MAAM,SAAS,KAAK,KAAK,IAAI,CAAC,EAAE,KAAK;CAChD;CACA,OAAO,SAAS,IAAI,KAAK,EAAE,CAAC;AAC9B;;AAGA,IAAa,qBAAqB,MAAc,UAAU,KAAK,CAAC,KAAK,6CAA6C,KAAK,CAAC,KAAK,oCAAoC,KAAK,CAAC"}
|
package/dist/controls/slot.js
CHANGED
|
@@ -195,7 +195,7 @@ function ComponentSlotControl({ field, value, onChange, readOnly, id, path }) {
|
|
|
195
195
|
className: "size-4"
|
|
196
196
|
})
|
|
197
197
|
}),
|
|
198
|
-
emptyLabel: slot.multiple ? "No blocks yet. Add one to start composing." : "No block yet. Choose one to fill this slot.",
|
|
198
|
+
emptyLabel: locked ? slot.multiple ? "No blocks yet." : "No block yet." : slot.multiple ? "No blocks yet. Add one to start composing." : "No block yet. Choose one to fill this slot.",
|
|
199
199
|
addButton: picker ?? /* @__PURE__ */ jsxs(SlotNote, { children: [
|
|
200
200
|
"No block library is connected to this editor, so ",
|
|
201
201
|
field.title,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"slot.js","names":[],"sources":["../../src/controls/slot.tsx"],"sourcesContent":["/**\n * COMPONENT SLOT — a prop that holds component instances (prod `slot`), on the engine's slot surface (engine/slot.tsx,\n * V2 HEAD 9829bf1): the block rows (icon tile, name, ⋯ menu, drag to reorder) and the compact searchable picker.\n *\n * What differs from V2's block slot is where the rows come from and what they store:\n * - the picker lists the host's slot catalog (`useSlotCatalog`): the project's components with the SERVER's\n * insertability verdict for each; one that can't go here stays in the list, disabled, with the reason under its name;\n * - a row opens in place and edits that child's own props through the host's `SlotChild`;\n * - the value is written in the stored shape (slot-services.ts): one `{ componentId, overrides? }`, or a list of them\n * for a multiple slot, every item spread back with the keys this control does not show (style, window).\n *\n * Refusals are said in words, never by an inert control: no catalog service, an unreadable stored value, the nesting cap.\n */\nimport * as React from \"react\";\nimport { IconPlus, IconSearch } from \"@tabler/icons-react\";\nimport { useKitServices } from \"../context\";\nimport { KitIcon } from \"../lib/icons\";\nimport { cn } from \"../lib/cn\";\nimport { Button } from \"../ui/button\";\nimport { Popover, PopoverContent, PopoverTrigger } from \"../ui/overlay\";\nimport { RowList, useListOps, type RowModel } from \"../engine/array\";\nimport type { FieldSchema } from \"../schema/types\";\nimport type { ControlProps } from \"../types\";\nimport { readSlot, slotList, SLOT_DEPTH_MAX, type KitComponentSlot, type KitSlotEntry, type KitSlotItem } from \"./slot-services\";\n\n/** How many slots deep the control sits: the host's SlotChild editor sits inside a provider one level down. */\nexport const SlotDepthContext = React.createContext(0);\n\nconst count = (n: number) => `${n} block${n === 1 ? \"\" : \"s\"}`;\nconst NO_CATALOG = { entries: [] as KitSlotEntry[], nameOf: () => undefined };\n\n/** A note in words, labelable and focusable (the field label's `for` lands on it). */\nfunction SlotNote({ id, children, tone = \"muted\" }: { id?: string; children: React.ReactNode; tone?: \"muted\" | \"warning\" }) {\n return (\n <output\n id={id}\n role=\"note\"\n tabIndex={id ? 0 : undefined}\n className={cn(\n \"block rounded-kit-sm text-kit-xs outline-none focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-kit-focus-ring focus-visible:[outline-style:solid] [html[data-input-modality=pointer]_&]:focus-visible:outline-none\",\n tone === \"warning\" ? \"text-kit-warning-fg\" : \"text-kit-fg-3\",\n )}\n >\n {children}\n </output>\n );\n}\n\nexport function ComponentSlotControl({ field, value, onChange, readOnly, id, path }: ControlProps) {\n const slot: KitComponentSlot = field.componentSlot ?? { multiple: false, min: 0, max: 1 };\n const depth = React.useContext(SlotDepthContext);\n const { useSlotCatalog, SlotChild, toast } = useKitServices();\n // a hook service: one identity for the life of the form, so it is called on every render or never\n const catalog = useSlotCatalog ? useSlotCatalog({ componentIds: slot.componentIds }) : null; // eslint-disable-line react-hooks/rules-of-hooks\n const read = readSlot(value);\n const items = read.items;\n const max = slot.multiple ? slot.max : 1;\n const [openId, setOpenId] = React.useState<string | null>(null);\n const nameOf = (componentId: string) => (catalog ?? NO_CATALOG).nameOf(componentId) ?? { title: catalog?.loading ? \"Loading…\" : componentId };\n const locked = readOnly || read.unreadable > 0;\n\n /* writes: the stored shape, never a `_key` (useListOps' duplicate adds one) */\n const write = (next: unknown[]) => {\n setOpenId(null);\n if (slot.multiple) return onChange(slotList(next));\n const [first] = slotList(next);\n onChange(first ?? { componentId: \"\" });\n };\n const opsField: FieldSchema = { ...field, validation: { ...field.validation, min: slot.multiple ? slot.min : 0, max } };\n const ops = useListOps(opsField, path, items, write);\n if (depth >= SLOT_DEPTH_MAX) return <SlotNote id={id}>Nested block limit reached. A slot this deep would render as nothing, so it can’t hold more blocks here.</SlotNote>;\n const pick = (componentId: string) => {\n if (!slot.multiple) {\n const cur = items[0];\n // a different component's overrides are keyed by the old component's props: dropped, never half-applied\n onChange(cur && cur.componentId === componentId ? cur : { componentId });\n setOpenId(null);\n return;\n }\n if (items.length >= max) return;\n onChange([...items, { componentId }]);\n setOpenId(`i${items.length}`);\n };\n const setOverrides = (index: number, overrides: Record<string, unknown>) => {\n const next = items.map((it, i) => (i === index ? { ...it, overrides } : it));\n if (slot.multiple) onChange(next);\n else onChange({ componentId: next[0].componentId, overrides });\n };\n\n const rows: RowModel[] = items.map((it, i) => {\n const name = nameOf(it.componentId);\n const entry = catalog?.entries.find((e) => e.id === it.componentId);\n return {\n id: `i${i}`,\n index: i,\n item: it,\n path: [...path, i],\n preview: { title: name.missing ? \"Missing block\" : name.title, icon: entry?.icon ?? \"box\", empty: false },\n extra: name.missing ? \"Deleted, or not in this project. Replace or remove it.\" : (entry?.category ?? `Block ${i + 1} of ${items.length}`),\n };\n });\n\n /*\n * A slot that takes exactly one block type adds it in one press (V2 content-form.tsx \"Add {child}\"): no picker to\n * choose from a list of one. Not insertable here → the picker, which says why. Undo puts the slot back as it was.\n */\n const only = slot.componentIds?.length === 1 ? catalog?.entries.find((e) => e.id === slot.componentIds![0]) : undefined;\n const quickAdd = only?.insertable && (slot.multiple || items.length === 0) ? only : undefined;\n const addOnly = (entry: KitSlotEntry) => {\n const before = value;\n pick(entry.id);\n toast?.(`${entry.title} added to ${field.title}`, { action: { label: \"Undo\", onClick: () => onChange(before) } });\n };\n\n const picker = quickAdd ? (\n <Button\n size=\"lg\"\n variant=\"ghost\"\n className=\"text-kit-fg-2\"\n leftIcon={<IconPlus stroke={1.5} />}\n disabled={locked || (slot.multiple && items.length >= max)}\n onClick={() => addOnly(quickAdd)}\n >\n Add {quickAdd.title}\n </Button>\n ) : catalog ? (\n <SlotPicker\n entries={catalog.entries}\n loading={catalog.loading}\n error={catalog.error}\n note={catalog.note}\n current={slot.multiple ? undefined : items[0]?.componentId}\n label={slot.multiple ? \"Add block\" : items.length ? \"Replace block\" : \"Choose a block\"}\n disabled={locked || (slot.multiple && items.length >= max)}\n onPick={pick}\n />\n ) : null;\n\n return (\n <div className=\"flex min-w-0 flex-col gap-1.5\" data-slot=\"kit-component-slot\">\n {read.unreadable > 0 ? (\n <SlotNote tone=\"warning\">\n {read.unreadable === 1 ? \"One child here isn't a block instance\" : `${read.unreadable} children here aren't block instances`} (blocks written by another editor). This editor\n would drop {read.unreadable === 1 ? \"it\" : \"them\"} on save, so the slot is shown read-only and its value is kept.\n </SlotNote>\n ) : null}\n {read.inherited && items.length === 0 ? <SlotNote>Shows the block’s own content until a block is added here.</SlotNote> : null}\n <div id={id} tabIndex={-1} className=\"min-w-0 outline-none\">\n <RowList\n field={opsField}\n rows={rows}\n readOnly={locked}\n layout=\"list\"\n mode=\"inline\"\n openId={openId}\n onOpen={(r) => setOpenId(openId === r.id ? null : r.id)}\n onCloseInline={() => setOpenId(null)}\n ops={ops}\n renderInline={(r) => {\n const it = r.item as KitSlotItem;\n const title = r.preview.title;\n if (nameOf(it.componentId).missing) return <SlotNote>This component no longer exists, so its props can’t be edited. Replace it or remove it.</SlotNote>;\n if (!SlotChild) return <SlotNote>This editor can’t open {title}’s own props.</SlotNote>;\n return (\n <SlotDepthContext.Provider value={depth + 1}>\n <SlotChild\n componentId={it.componentId}\n title={title}\n overrides={it.overrides && typeof it.overrides === \"object\" ? it.overrides : {}}\n onChange={(o) => setOverrides(r.index, o)}\n readOnly={locked}\n depth={depth + 1}\n />\n </SlotDepthContext.Provider>\n );\n }}\n leading={(r) => (\n <span className=\"flex size-7 shrink-0 items-center justify-center rounded-kit-md border border-kit-line bg-kit-control-bg text-kit-fg-2 shadow-kit-xs\">\n <KitIcon name={r.preview.icon} className=\"size-4\" />\n </span>\n )}\n emptyLabel={slot.multiple ? \"No blocks yet. Add one to start composing.\" : \"No block yet. Choose one to fill this slot.\"}\n addButton={picker ?? <SlotNote>No block library is connected to this editor, so {field.title} can’t be changed here.</SlotNote>}\n />\n </div>\n {slot.multiple ? (\n <span className=\"text-kit-xs text-kit-fg-3\">\n {items.length >= max ? `This slot holds at most ${count(max)}.` : slot.min > 0 ? `Between ${slot.min} and ${count(max)}.` : `Up to ${count(max)}.`}\n {slot.min > 0 && items.length > 0 && items.length <= slot.min ? ` It needs at least ${slot.min}, so none can be removed.` : \"\"}\n </span>\n ) : null}\n </div>\n );\n}\n\n/**\n * The compact block picker (engine/slot.tsx BlockPicker), over the slot catalog: grouped by family, searchable, ↵ adds.\n * A component the server says can't go here is listed disabled with its reason in place of the description.\n */\nexport function SlotPicker({\n entries,\n loading,\n error,\n note,\n current,\n label,\n disabled,\n onPick,\n}: {\n entries: KitSlotEntry[];\n loading?: boolean;\n error?: string;\n note?: string;\n current?: string;\n label: string;\n disabled?: boolean;\n onPick: (componentId: string) => void;\n}) {\n const [open, setOpen] = React.useState(false);\n const [q, setQ] = React.useState(\"\");\n const [active, setActive] = React.useState(0);\n const listId = React.useId();\n const list = entries.filter((b) => !q || `${b.title} ${b.category ?? \"\"} ${b.description ?? \"\"}`.toLowerCase().includes(q.toLowerCase()));\n const cats = Array.from(new Set(list.map((b) => b.category || \"Blocks\")));\n const flat = cats.flatMap((c) => list.filter((b) => (b.category || \"Blocks\") === c));\n const choose = (b: KitSlotEntry | undefined) => {\n if (!b || !b.insertable) return;\n onPick(b.id);\n setOpen(false);\n setQ(\"\");\n };\n const optionId = (i: number) => `${listId}-${i}`;\n return (\n <Popover\n open={open}\n onOpenChange={(o) => {\n setOpen(o);\n setQ(\"\");\n setActive(0);\n }}\n >\n <PopoverTrigger render={<Button size=\"sm\" variant=\"ghost\" className=\"text-kit-fg-2\" leftIcon={<IconPlus stroke={1.5} />} disabled={disabled} />}>{label}</PopoverTrigger>\n <PopoverContent className=\"w-[300px] p-0\" align=\"start\">\n <label className=\"flex h-10 items-center gap-2 border-b border-kit-line px-3 text-kit-fg-3\">\n <IconSearch className=\"size-4 shrink-0\" stroke={1.5} aria-hidden />\n <input\n autoFocus\n value={q}\n onChange={(e) => {\n setQ(e.target.value);\n setActive(0);\n }}\n onKeyDown={(e) => {\n if (e.key === \"ArrowDown\") {\n e.preventDefault();\n setActive((a) => (a + 1) % Math.max(1, flat.length));\n } else if (e.key === \"ArrowUp\") {\n e.preventDefault();\n setActive((a) => (a - 1 + flat.length) % Math.max(1, flat.length));\n } else if (e.key === \"Enter\") {\n e.preventDefault();\n choose(flat[active]);\n }\n }}\n placeholder=\"Search blocks\"\n aria-label=\"Search blocks\"\n role=\"combobox\"\n aria-expanded\n aria-controls={listId}\n aria-activedescendant={flat.length ? optionId(Math.min(active, flat.length - 1)) : undefined}\n className=\"h-full min-w-0 flex-1 bg-transparent text-kit-sm text-kit-fg outline-none placeholder:text-kit-fg-3\"\n />\n </label>\n <div id={listId} className=\"max-h-80 overflow-y-auto p-1\" role=\"listbox\" aria-label=\"Blocks\" aria-busy={loading || undefined}>\n {loading && entries.length === 0 ? (\n <p role=\"status\" className=\"px-3 py-6 text-center text-kit-sm text-kit-fg-3\">\n Loading blocks…\n </p>\n ) : null}\n {!loading && !error && flat.length === 0 ? <p className=\"px-3 py-6 text-center text-kit-sm text-kit-fg-3\">{entries.length ? \"No blocks match\" : \"This project has no blocks that can go here yet.\"}</p> : null}\n {error ? (\n <p role=\"alert\" className=\"px-3 py-3 text-kit-xs text-kit-danger-fg\">\n {error}\n </p>\n ) : null}\n {cats.map((c) => (\n <div key={c} role=\"group\" aria-label={c} className=\"pb-1\">\n <div aria-hidden className=\"px-2 pb-1 pt-1.5 text-kit-2xs font-medium text-kit-fg-3\">\n {c}\n </div>\n {list\n .filter((b) => (b.category || \"Blocks\") === c)\n .map((b) => {\n const i = flat.indexOf(b);\n return (\n <div\n key={b.id}\n id={optionId(i)}\n role=\"option\"\n aria-selected={b.id === current}\n aria-disabled={!b.insertable || undefined}\n onMouseEnter={() => setActive(i)}\n onMouseDown={(e) => e.preventDefault()}\n onClick={() => choose(b)}\n className={cn(\"flex w-full items-center gap-2.5 rounded-kit-md p-1.5 text-left\", b.insertable ? \"cursor-pointer\" : \"cursor-not-allowed\", i === active && \"bg-kit-hover\")}\n >\n <span className={cn(\"flex size-8 shrink-0 items-center justify-center rounded-kit-md border border-kit-line bg-kit-surface text-kit-fg-2 shadow-kit-xs\", !b.insertable && \"opacity-50\")}>\n <KitIcon name={b.icon ?? \"box\"} className=\"size-4\" />\n </span>\n <span className=\"min-w-0 flex-1\">\n <span className={cn(\"block truncate text-kit-sm\", b.insertable ? \"text-kit-fg\" : \"text-kit-fg-3\")}>{b.title}</span>\n {!b.insertable && b.reason ? (\n <span className=\"block text-kit-xs text-kit-fg-3\">{b.reason}</span>\n ) : b.description ? (\n <span className=\"block truncate text-kit-xs text-kit-fg-3\">{b.description}</span>\n ) : null}\n </span>\n </div>\n );\n })}\n </div>\n ))}\n </div>\n {note ? <p className=\"border-t border-kit-line px-3 py-2 text-kit-xs text-kit-fg-3\">{note}</p> : null}\n <div data-hint=\"shortcuts\" className=\"border-t border-kit-line px-3 py-1.5 text-kit-2xs text-kit-fg-3\">\n ↵ add · type to search\n </div>\n </PopoverContent>\n </Popover>\n );\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;AA0BA,IAAa,mBAAmB,MAAM,cAAc,CAAC;AAErD,IAAM,SAAS,MAAc,GAAG,EAAE,QAAQ,MAAM,IAAI,KAAK;AACzD,IAAM,aAAa;CAAE,SAAS,CAAC;CAAqB,cAAc,KAAA;AAAU;;AAG5E,SAAS,SAAS,EAAE,IAAI,UAAU,OAAO,WAAmF;CAC1H,OACE,oBAAC,UAAD;EACM;EACJ,MAAK;EACL,UAAU,KAAK,IAAI,KAAA;EACnB,WAAW,GACT,kPACA,SAAS,YAAY,wBAAwB,eAC/C;EAEC;CACK,CAAA;AAEZ;AAEA,SAAgB,qBAAqB,EAAE,OAAO,OAAO,UAAU,UAAU,IAAI,QAAsB;CACjG,MAAM,OAAyB,MAAM,iBAAiB;EAAE,UAAU;EAAO,KAAK;EAAG,KAAK;CAAE;CACxF,MAAM,QAAQ,MAAM,WAAW,gBAAgB;CAC/C,MAAM,EAAE,gBAAgB,WAAW,UAAU,eAAe;CAE5D,MAAM,UAAU,iBAAiB,eAAe,EAAE,cAAc,KAAK,aAAa,CAAC,IAAI;CACvF,MAAM,OAAO,SAAS,KAAK;CAC3B,MAAM,QAAQ,KAAK;CACnB,MAAM,MAAM,KAAK,WAAW,KAAK,MAAM;CACvC,MAAM,CAAC,QAAQ,aAAa,MAAM,SAAwB,IAAI;CAC9D,MAAM,UAAU,iBAAyB,WAA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AAC,CACA;MAlCK,GAAA,CAkCL,CACN;KACE;;IACJ,OAAO,oBAAC,KAAD;KAAG,WAAU;KAAgE,UAAA;IAAQ,CAAA,IAAI;IACjG,oBAAC,OAAD;KAAK,aAAU;KAAY,WAAU;KAAkE,UAAA;IAElG,CAAA;GACS;EACT,CAAA,CAAA;;AAEb"}
|
|
1
|
+
{"version":3,"file":"slot.js","names":[],"sources":["../../src/controls/slot.tsx"],"sourcesContent":["/**\n * COMPONENT SLOT — a prop that holds component instances (prod `slot`), on the engine's slot surface (engine/slot.tsx,\n * V2 HEAD 9829bf1): the block rows (icon tile, name, ⋯ menu, drag to reorder) and the compact searchable picker.\n *\n * What differs from V2's block slot is where the rows come from and what they store:\n * - the picker lists the host's slot catalog (`useSlotCatalog`): the project's components with the SERVER's\n * insertability verdict for each; one that can't go here stays in the list, disabled, with the reason under its name;\n * - a row opens in place and edits that child's own props through the host's `SlotChild`;\n * - the value is written in the stored shape (slot-services.ts): one `{ componentId, overrides? }`, or a list of them\n * for a multiple slot, every item spread back with the keys this control does not show (style, window).\n *\n * Refusals are said in words, never by an inert control: no catalog service, an unreadable stored value, the nesting cap.\n */\nimport * as React from \"react\";\nimport { IconPlus, IconSearch } from \"@tabler/icons-react\";\nimport { useKitServices } from \"../context\";\nimport { KitIcon } from \"../lib/icons\";\nimport { cn } from \"../lib/cn\";\nimport { Button } from \"../ui/button\";\nimport { Popover, PopoverContent, PopoverTrigger } from \"../ui/overlay\";\nimport { RowList, useListOps, type RowModel } from \"../engine/array\";\nimport type { FieldSchema } from \"../schema/types\";\nimport type { ControlProps } from \"../types\";\nimport { readSlot, slotList, SLOT_DEPTH_MAX, type KitComponentSlot, type KitSlotEntry, type KitSlotItem } from \"./slot-services\";\n\n/** How many slots deep the control sits: the host's SlotChild editor sits inside a provider one level down. */\nexport const SlotDepthContext = React.createContext(0);\n\nconst count = (n: number) => `${n} block${n === 1 ? \"\" : \"s\"}`;\nconst NO_CATALOG = { entries: [] as KitSlotEntry[], nameOf: () => undefined };\n\n/** A note in words, labelable and focusable (the field label's `for` lands on it). */\nfunction SlotNote({ id, children, tone = \"muted\" }: { id?: string; children: React.ReactNode; tone?: \"muted\" | \"warning\" }) {\n return (\n <output\n id={id}\n role=\"note\"\n tabIndex={id ? 0 : undefined}\n className={cn(\n \"block rounded-kit-sm text-kit-xs outline-none focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-kit-focus-ring focus-visible:[outline-style:solid] [html[data-input-modality=pointer]_&]:focus-visible:outline-none\",\n tone === \"warning\" ? \"text-kit-warning-fg\" : \"text-kit-fg-3\",\n )}\n >\n {children}\n </output>\n );\n}\n\nexport function ComponentSlotControl({ field, value, onChange, readOnly, id, path }: ControlProps) {\n const slot: KitComponentSlot = field.componentSlot ?? { multiple: false, min: 0, max: 1 };\n const depth = React.useContext(SlotDepthContext);\n const { useSlotCatalog, SlotChild, toast } = useKitServices();\n // a hook service: one identity for the life of the form, so it is called on every render or never\n const catalog = useSlotCatalog ? useSlotCatalog({ componentIds: slot.componentIds }) : null; // eslint-disable-line react-hooks/rules-of-hooks\n const read = readSlot(value);\n const items = read.items;\n const max = slot.multiple ? slot.max : 1;\n const [openId, setOpenId] = React.useState<string | null>(null);\n const nameOf = (componentId: string) => (catalog ?? NO_CATALOG).nameOf(componentId) ?? { title: catalog?.loading ? \"Loading…\" : componentId };\n const locked = readOnly || read.unreadable > 0;\n\n /* writes: the stored shape, never a `_key` (useListOps' duplicate adds one) */\n const write = (next: unknown[]) => {\n setOpenId(null);\n if (slot.multiple) return onChange(slotList(next));\n const [first] = slotList(next);\n onChange(first ?? { componentId: \"\" });\n };\n const opsField: FieldSchema = { ...field, validation: { ...field.validation, min: slot.multiple ? slot.min : 0, max } };\n const ops = useListOps(opsField, path, items, write);\n if (depth >= SLOT_DEPTH_MAX) return <SlotNote id={id}>Nested block limit reached. A slot this deep would render as nothing, so it can’t hold more blocks here.</SlotNote>;\n const pick = (componentId: string) => {\n if (!slot.multiple) {\n const cur = items[0];\n // a different component's overrides are keyed by the old component's props: dropped, never half-applied\n onChange(cur && cur.componentId === componentId ? cur : { componentId });\n setOpenId(null);\n return;\n }\n if (items.length >= max) return;\n onChange([...items, { componentId }]);\n setOpenId(`i${items.length}`);\n };\n const setOverrides = (index: number, overrides: Record<string, unknown>) => {\n const next = items.map((it, i) => (i === index ? { ...it, overrides } : it));\n if (slot.multiple) onChange(next);\n else onChange({ componentId: next[0].componentId, overrides });\n };\n\n const rows: RowModel[] = items.map((it, i) => {\n const name = nameOf(it.componentId);\n const entry = catalog?.entries.find((e) => e.id === it.componentId);\n return {\n id: `i${i}`,\n index: i,\n item: it,\n path: [...path, i],\n preview: { title: name.missing ? \"Missing block\" : name.title, icon: entry?.icon ?? \"box\", empty: false },\n extra: name.missing ? \"Deleted, or not in this project. Replace or remove it.\" : (entry?.category ?? `Block ${i + 1} of ${items.length}`),\n };\n });\n\n /*\n * A slot that takes exactly one block type adds it in one press (V2 content-form.tsx \"Add {child}\"): no picker to\n * choose from a list of one. Not insertable here → the picker, which says why. Undo puts the slot back as it was.\n */\n const only = slot.componentIds?.length === 1 ? catalog?.entries.find((e) => e.id === slot.componentIds![0]) : undefined;\n const quickAdd = only?.insertable && (slot.multiple || items.length === 0) ? only : undefined;\n const addOnly = (entry: KitSlotEntry) => {\n const before = value;\n pick(entry.id);\n toast?.(`${entry.title} added to ${field.title}`, { action: { label: \"Undo\", onClick: () => onChange(before) } });\n };\n\n const picker = quickAdd ? (\n <Button\n size=\"lg\"\n variant=\"ghost\"\n className=\"text-kit-fg-2\"\n leftIcon={<IconPlus stroke={1.5} />}\n disabled={locked || (slot.multiple && items.length >= max)}\n onClick={() => addOnly(quickAdd)}\n >\n Add {quickAdd.title}\n </Button>\n ) : catalog ? (\n <SlotPicker\n entries={catalog.entries}\n loading={catalog.loading}\n error={catalog.error}\n note={catalog.note}\n current={slot.multiple ? undefined : items[0]?.componentId}\n label={slot.multiple ? \"Add block\" : items.length ? \"Replace block\" : \"Choose a block\"}\n disabled={locked || (slot.multiple && items.length >= max)}\n onPick={pick}\n />\n ) : null;\n\n return (\n <div className=\"flex min-w-0 flex-col gap-1.5\" data-slot=\"kit-component-slot\">\n {read.unreadable > 0 ? (\n <SlotNote tone=\"warning\">\n {read.unreadable === 1 ? \"One child here isn't a block instance\" : `${read.unreadable} children here aren't block instances`} (blocks written by another editor). This editor\n would drop {read.unreadable === 1 ? \"it\" : \"them\"} on save, so the slot is shown read-only and its value is kept.\n </SlotNote>\n ) : null}\n {read.inherited && items.length === 0 ? <SlotNote>Shows the block’s own content until a block is added here.</SlotNote> : null}\n <div id={id} tabIndex={-1} className=\"min-w-0 outline-none\">\n <RowList\n field={opsField}\n rows={rows}\n readOnly={locked}\n layout=\"list\"\n mode=\"inline\"\n openId={openId}\n onOpen={(r) => setOpenId(openId === r.id ? null : r.id)}\n onCloseInline={() => setOpenId(null)}\n ops={ops}\n renderInline={(r) => {\n const it = r.item as KitSlotItem;\n const title = r.preview.title;\n if (nameOf(it.componentId).missing) return <SlotNote>This component no longer exists, so its props can’t be edited. Replace it or remove it.</SlotNote>;\n if (!SlotChild) return <SlotNote>This editor can’t open {title}’s own props.</SlotNote>;\n return (\n <SlotDepthContext.Provider value={depth + 1}>\n <SlotChild\n componentId={it.componentId}\n title={title}\n overrides={it.overrides && typeof it.overrides === \"object\" ? it.overrides : {}}\n onChange={(o) => setOverrides(r.index, o)}\n readOnly={locked}\n depth={depth + 1}\n />\n </SlotDepthContext.Provider>\n );\n }}\n leading={(r) => (\n <span className=\"flex size-7 shrink-0 items-center justify-center rounded-kit-md border border-kit-line bg-kit-control-bg text-kit-fg-2 shadow-kit-xs\">\n <KitIcon name={r.preview.icon} className=\"size-4\" />\n </span>\n )}\n emptyLabel={locked ? (slot.multiple ? \"No blocks yet.\" : \"No block yet.\") : slot.multiple ? \"No blocks yet. Add one to start composing.\" : \"No block yet. Choose one to fill this slot.\"}\n addButton={picker ?? <SlotNote>No block library is connected to this editor, so {field.title} can’t be changed here.</SlotNote>}\n />\n </div>\n {slot.multiple ? (\n <span className=\"text-kit-xs text-kit-fg-3\">\n {items.length >= max ? `This slot holds at most ${count(max)}.` : slot.min > 0 ? `Between ${slot.min} and ${count(max)}.` : `Up to ${count(max)}.`}\n {slot.min > 0 && items.length > 0 && items.length <= slot.min ? ` It needs at least ${slot.min}, so none can be removed.` : \"\"}\n </span>\n ) : null}\n </div>\n );\n}\n\n/**\n * The compact block picker (engine/slot.tsx BlockPicker), over the slot catalog: grouped by family, searchable, ↵ adds.\n * A component the server says can't go here is listed disabled with its reason in place of the description.\n */\nexport function SlotPicker({\n entries,\n loading,\n error,\n note,\n current,\n label,\n disabled,\n onPick,\n}: {\n entries: KitSlotEntry[];\n loading?: boolean;\n error?: string;\n note?: string;\n current?: string;\n label: string;\n disabled?: boolean;\n onPick: (componentId: string) => void;\n}) {\n const [open, setOpen] = React.useState(false);\n const [q, setQ] = React.useState(\"\");\n const [active, setActive] = React.useState(0);\n const listId = React.useId();\n const list = entries.filter((b) => !q || `${b.title} ${b.category ?? \"\"} ${b.description ?? \"\"}`.toLowerCase().includes(q.toLowerCase()));\n const cats = Array.from(new Set(list.map((b) => b.category || \"Blocks\")));\n const flat = cats.flatMap((c) => list.filter((b) => (b.category || \"Blocks\") === c));\n const choose = (b: KitSlotEntry | undefined) => {\n if (!b || !b.insertable) return;\n onPick(b.id);\n setOpen(false);\n setQ(\"\");\n };\n const optionId = (i: number) => `${listId}-${i}`;\n return (\n <Popover\n open={open}\n onOpenChange={(o) => {\n setOpen(o);\n setQ(\"\");\n setActive(0);\n }}\n >\n <PopoverTrigger render={<Button size=\"sm\" variant=\"ghost\" className=\"text-kit-fg-2\" leftIcon={<IconPlus stroke={1.5} />} disabled={disabled} />}>{label}</PopoverTrigger>\n <PopoverContent className=\"w-[300px] p-0\" align=\"start\">\n <label className=\"flex h-10 items-center gap-2 border-b border-kit-line px-3 text-kit-fg-3\">\n <IconSearch className=\"size-4 shrink-0\" stroke={1.5} aria-hidden />\n <input\n autoFocus\n value={q}\n onChange={(e) => {\n setQ(e.target.value);\n setActive(0);\n }}\n onKeyDown={(e) => {\n if (e.key === \"ArrowDown\") {\n e.preventDefault();\n setActive((a) => (a + 1) % Math.max(1, flat.length));\n } else if (e.key === \"ArrowUp\") {\n e.preventDefault();\n setActive((a) => (a - 1 + flat.length) % Math.max(1, flat.length));\n } else if (e.key === \"Enter\") {\n e.preventDefault();\n choose(flat[active]);\n }\n }}\n placeholder=\"Search blocks\"\n aria-label=\"Search blocks\"\n role=\"combobox\"\n aria-expanded\n aria-controls={listId}\n aria-activedescendant={flat.length ? optionId(Math.min(active, flat.length - 1)) : undefined}\n className=\"h-full min-w-0 flex-1 bg-transparent text-kit-sm text-kit-fg outline-none placeholder:text-kit-fg-3\"\n />\n </label>\n <div id={listId} className=\"max-h-80 overflow-y-auto p-1\" role=\"listbox\" aria-label=\"Blocks\" aria-busy={loading || undefined}>\n {loading && entries.length === 0 ? (\n <p role=\"status\" className=\"px-3 py-6 text-center text-kit-sm text-kit-fg-3\">\n Loading blocks…\n </p>\n ) : null}\n {!loading && !error && flat.length === 0 ? <p className=\"px-3 py-6 text-center text-kit-sm text-kit-fg-3\">{entries.length ? \"No blocks match\" : \"This project has no blocks that can go here yet.\"}</p> : null}\n {error ? (\n <p role=\"alert\" className=\"px-3 py-3 text-kit-xs text-kit-danger-fg\">\n {error}\n </p>\n ) : null}\n {cats.map((c) => (\n <div key={c} role=\"group\" aria-label={c} className=\"pb-1\">\n <div aria-hidden className=\"px-2 pb-1 pt-1.5 text-kit-2xs font-medium text-kit-fg-3\">\n {c}\n </div>\n {list\n .filter((b) => (b.category || \"Blocks\") === c)\n .map((b) => {\n const i = flat.indexOf(b);\n return (\n <div\n key={b.id}\n id={optionId(i)}\n role=\"option\"\n aria-selected={b.id === current}\n aria-disabled={!b.insertable || undefined}\n onMouseEnter={() => setActive(i)}\n onMouseDown={(e) => e.preventDefault()}\n onClick={() => choose(b)}\n className={cn(\"flex w-full items-center gap-2.5 rounded-kit-md p-1.5 text-left\", b.insertable ? \"cursor-pointer\" : \"cursor-not-allowed\", i === active && \"bg-kit-hover\")}\n >\n <span className={cn(\"flex size-8 shrink-0 items-center justify-center rounded-kit-md border border-kit-line bg-kit-surface text-kit-fg-2 shadow-kit-xs\", !b.insertable && \"opacity-50\")}>\n <KitIcon name={b.icon ?? \"box\"} className=\"size-4\" />\n </span>\n <span className=\"min-w-0 flex-1\">\n <span className={cn(\"block truncate text-kit-sm\", b.insertable ? \"text-kit-fg\" : \"text-kit-fg-3\")}>{b.title}</span>\n {!b.insertable && b.reason ? (\n <span className=\"block text-kit-xs text-kit-fg-3\">{b.reason}</span>\n ) : b.description ? (\n <span className=\"block truncate text-kit-xs text-kit-fg-3\">{b.description}</span>\n ) : null}\n </span>\n </div>\n );\n })}\n </div>\n ))}\n </div>\n {note ? <p className=\"border-t border-kit-line px-3 py-2 text-kit-xs text-kit-fg-3\">{note}</p> : null}\n <div data-hint=\"shortcuts\" className=\"border-t border-kit-line px-3 py-1.5 text-kit-2xs text-kit-fg-3\">\n ↵ add · type to search\n </div>\n </PopoverContent>\n </Popover>\n );\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;AA0BA,IAAa,mBAAmB,MAAM,cAAc,CAAC;AAErD,IAAM,SAAS,MAAc,GAAG,EAAE,QAAQ,MAAM,IAAI,KAAK;AACzD,IAAM,aAAa;CAAE,SAAS,CAAC;CAAqB,cAAc,KAAA;AAAU;;AAG5E,SAAS,SAAS,EAAE,IAAI,UAAU,OAAO,WAAmF;CAC1H,OACE,oBAAC,UAAD;EACM;EACJ,MAAK;EACL,UAAU,KAAK,IAAI,KAAA;EACnB,WAAW,GACT,kPACA,SAAS,YAAY,wBAAwB,eAC/C;EAEC;CACK,CAAA;AAEZ;AAEA,SAAgB,qBAAqB,EAAE,OAAO,OAAO,UAAU,UAAU,IAAI,QAAsB;CACjG,MAAM,OAAyB,MAAM,iBAAiB;EAAE,UAAU;EAAO,KAAK;EAAG,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D,CAAA,GACN,qBAAC,QAAD;UAAM,WAAU;UAAhB,UAAA,CACE,oBAAC,QAAD;WAAM,WAAW,GAAG,8BAA8B,EAAE,aAAa,gBAAgB,eAAe;WAAI,UAAA,EAAE;UAAY,CAAA,GACjH,CAAC,EAAE,cAAc,EAAE,SAClB,oBAAC,QAAD;WAAM,WAAU;WAAmC,UAAA,EAAE;UAAa,CAAA,IAChE,EAAE,cACJ,oBAAC,QAAD;WAAM,WAAU;WAA4C,UAAA,EAAE;UAAkB,CAAA,IAC9E,IACA;SACH,CAAA,CAAA;QArBE,GAAA,EAAE,EAqBJ;OAET,CAAC,CACA;MAlCK,GAAA,CAkCL,CACN;KACE;;IACJ,OAAO,oBAAC,KAAD;KAAG,WAAU;KAAgE,UAAA;IAAQ,CAAA,IAAI;IACjG,oBAAC,OAAD;KAAK,aAAU;KAAY,WAAU;KAAkE,UAAA;IAElG,CAAA;GACS;EACT,CAAA,CAAA;;AAEb"}
|
package/dist/engine/frame.js
CHANGED
|
@@ -226,6 +226,8 @@ function FrameHeader({ frame, context, title }) {
|
|
|
226
226
|
const bounds = frame.kind === "item" || frame.kind === "block" ? frame.field?.validation : void 0;
|
|
227
227
|
const atMax = bounds?.max != null && list.length >= bounds.max;
|
|
228
228
|
const atMin = bounds?.min != null && list.length <= bounds.min;
|
|
229
|
+
const env = useKitEnv();
|
|
230
|
+
const readOnly = frame.field ? resolveFieldAccess(frame.field, env).readOnly : !!env.readOnly;
|
|
229
231
|
const moved = React.useRef(false);
|
|
230
232
|
return /* @__PURE__ */ jsxs("div", {
|
|
231
233
|
className: "flex items-start gap-2.5 outline-none",
|
|
@@ -266,7 +268,7 @@ function FrameHeader({ frame, context, title }) {
|
|
|
266
268
|
onClick: () => step(1),
|
|
267
269
|
children: /* @__PURE__ */ jsx(IconArrowDown, { stroke: 1.5 })
|
|
268
270
|
}),
|
|
269
|
-
/* @__PURE__ */ jsxs(Menu, { children: [/* @__PURE__ */ jsx(Tooltip, {
|
|
271
|
+
readOnly ? null : /* @__PURE__ */ jsxs(Menu, { children: [/* @__PURE__ */ jsx(Tooltip, {
|
|
270
272
|
content: `${title} actions`,
|
|
271
273
|
children: /* @__PURE__ */ jsx(MenuTrigger, { render: /* @__PURE__ */ jsx(IconButton, {
|
|
272
274
|
label: `${title} actions`,
|
package/dist/engine/frame.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"frame.js","names":[],"sources":["../../src/engine/frame.tsx"],"sourcesContent":["/**\n * FrameView — what the panel shows for the current breadcrumb: the root fields, a drilled object / array item /\n * slot block (with \"2 of 4\" stepper, variant switcher and per-slot layout settings), the one button screen,\n * or a field's history as a stacked panel. Port of V2 engine/frame.tsx.\n *\n * FrameStage + useFrameNavigation — V2 schema-form's drill-in stage (direction-aware slide, scroll memory per frame,\n * focus on the entering frame, Esc / ⌥↑↓). Exported here so SchemaForm wires them without re-deriving the motion.\n *\n * FrameSlots — the frame draws other lanes' pieces (FieldList / FieldSection from grouping, ButtonScreen from link,\n * TableFrame from table). They arrive through context so this file never imports a module that does not exist yet;\n * a missing slot falls back to a plain field list (FieldList), the raw value (ButtonScreen, through\n * FallbackControl), a named note (TableFrame) or nothing (FieldSection). SchemaForm always hands ButtonScreen and TableFrame.\n */\nimport * as React from \"react\";\nimport { AnimatePresence, motion, useReducedMotion } from \"framer-motion\";\nimport { IconArrowDown, IconArrowUp, IconCopy, IconDots, IconTrash } from \"@tabler/icons-react\";\nimport { IconButton } from \"../ui/button\";\nimport { Menu, MenuContent, MenuItem, MenuSeparator, MenuTrigger, Tooltip } from \"../ui/overlay\";\nimport { Segmented } from \"../ui/controls\";\nimport { fitsSegmented } from \"../ui/choice-switch\";\nimport { Select } from \"../ui/select\";\nimport { resolveFieldAccess, useForm, useKitEnv, useKitServices } from \"../context\";\nimport { cn } from \"../lib/cn\";\nimport { HISTORY_SEGMENT, type FieldGroup, type FieldPath, type FieldSchema, type Fieldset } from \"../schema/types\";\nimport type { Frame } from \"../lib/frames\";\nimport { frameKeyOf, isObj, newKey } from \"../lib/path\";\nimport { condCtx, isHidden, previewOf } from \"../lib/schema\";\nimport { Thumb } from \"./bits\";\nimport { FallbackControl, KitField } from \"./kit-field\";\n\n/* ── Slots (other lanes) ───────────────────────────────────────────── */\nexport interface FrameFieldListProps {\n fields: FieldSchema[];\n fieldsets?: Fieldset[];\n groups?: FieldGroup[];\n basePath: FieldPath;\n memoryKey: string;\n}\nexport interface FrameSlots {\n /** grouping lane: engine/field-list.tsx `FieldList` */\n FieldList?: React.ComponentType<FrameFieldListProps>;\n /** grouping lane: engine/grouping.tsx `FieldSection` (the slot-settings section of a slot block) */\n FieldSection?: React.ComponentType<{ title: string; description?: string; collapsible?: boolean; children: React.ReactNode }>;\n /** link lane: controls/link.tsx `ButtonScreen` + `normLink` (the \"button\" frame) */\n ButtonScreen?: React.ComponentType<{ value: unknown; onChange: (v: unknown) => void; title: string; readOnly?: boolean }>;\n normLink?: (v: unknown) => { label?: string };\n /** table lane: controls/table.tsx `TableFrame` (tableRow / tableColumn frames) */\n TableFrame?: React.ComponentType<{ frame: Frame }>;\n}\nconst SlotsCtx = React.createContext<FrameSlots>({});\nexport const FrameSlotsProvider = SlotsCtx.Provider;\nexport const useFrameSlots = () => React.useContext(SlotsCtx);\n\n/** Stand-in until the grouping lane's FieldList lands: the frame's visible fields in schema order. */\nfunction PlainFieldList({ fields, basePath }: FrameFieldListProps) {\n const form = useForm()!;\n const raw = basePath.length ? form.getAt(basePath) : form.value;\n const parent = isObj(raw) ? raw : {};\n const cc = condCtx(form, basePath);\n const shown = fields.filter((f) => !isHidden(f, parent, cc));\n return (\n <div className=\"flex flex-col gap-5\">\n {shown.map((f) => (\n <div key={f.name} className=\"min-w-0\">\n <KitField field={f} path={[...basePath, f.name]} parent={parent} />\n </div>\n ))}\n {shown.length === 0 ? <p className=\"py-6 text-center text-kit-sm text-kit-fg-3\">No fields here yet.</p> : null}\n </div>\n );\n}\n\n/** A button frame outside SchemaForm (no ButtonScreen slot) edits the button's raw value (FallbackControl), never an empty body. */\nfunction RawButtonScreen({ frame }: { frame: Frame }) {\n const form = useForm()!;\n const id = React.useId();\n const field = frame.field ?? { name: String(frame.path.at(-1) ?? \"button\"), title: frame.title, type: \"button\" as const };\n return <FallbackControl field={field} value={form.getAt(frame.path)} onChange={(n) => form.setAt(frame.path, n)} id={id} path={frame.path} />;\n}\n\n/** The button frame: header (the button's label) + the kit ButtonScreen, read-only when the lens can't edit the field. */\nfunction ButtonFrame({ frame, parentTitle }: { frame: Frame; parentTitle?: string }) {\n const form = useForm()!;\n const env = useKitEnv();\n const slots = useFrameSlots();\n const v = form.getAt(frame.path);\n const ButtonScreen = slots.ButtonScreen;\n const readOnly = frame.field ? resolveFieldAccess(frame.field, env).readOnly : !!env.readOnly;\n return (\n <div className=\"flex flex-col gap-5\">\n <FrameHeader frame={frame} context={parentTitle ? `${frame.title} in ${parentTitle}` : frame.title} title={slots.normLink?.(v).label || frame.title} />\n {ButtonScreen ? <ButtonScreen value={v} onChange={(n) => form.setAt(frame.path, n)} title={frame.title} readOnly={readOnly} /> : <RawButtonScreen frame={frame} />}\n </div>\n );\n}\n\n/* ── FrameView ─────────────────────────────────────────────────────── */\nexport function FrameView({ frame, parentTitle }: { frame: Frame; parentTitle?: string }) {\n const form = useForm()!;\n const slots = useFrameSlots();\n const FieldList = slots.FieldList ?? PlainFieldList;\n if (frame.kind === \"history\") return null; // D61: a field's history is the host's one History panel (onFieldHistory)\n if (frame.kind === \"button\") return <ButtonFrame frame={frame} parentTitle={parentTitle} />;\n // D50: a table row or column drills exactly like an array item: the same header (title, n of N, ↑ ↓ ⋯), its cells below\n if (frame.kind === \"tableRow\" || frame.kind === \"tableColumn\") {\n const it = frame.item!;\n const TableFrame = slots.TableFrame;\n return (\n <div className=\"flex flex-col gap-5\">\n <FrameHeader frame={frame} context={`${it.itemSchema?.title} ${it.index + 1} of ${it.count} in ${frame.field?.title ?? \"the table\"}`} title={frame.title} />\n {TableFrame ? (\n <TableFrame frame={frame} />\n ) : (\n /* Only the kit table control opens a row or column frame; until it is ported the table is the host's control,\n which edits rows in place. A path restored into one says so instead of drawing an empty body. */\n <p role=\"note\" data-kit-legacy=\"table\" className=\"text-kit-sm text-kit-fg-3\">\n This table's rows and columns are edited in the table itself.\n </p>\n )}\n </div>\n );\n }\n if (frame.kind === \"root\") return <FieldList fields={frame.fields} fieldsets={frame.fieldsets} groups={frame.groups} basePath={[]} memoryKey=\"root\" />;\n const it = frame.item;\n const block = it?.block;\n const variants = block?.variants ?? [];\n const raw = form.getAt(frame.path);\n const cur = isObj(raw) ? raw : {};\n const FieldSection = slots.FieldSection;\n return (\n <div className=\"flex flex-col gap-5\">\n <FrameHeader frame={frame} context={frameContext(frame, parentTitle)} title={frame.title} />\n {block && variants.length > 1 ? (\n <div className=\"flex flex-col gap-1.5\">\n <span className=\"text-kit-sm font-medium text-kit-fg-2\">Layout</span>\n {fitsSegmented(variants.map((v) => v.name)) ? (\n <Segmented\n aria-label=\"Layout\"\n value={String(cur._variant ?? variants[0].id)}\n onChange={(v) => form.setAt([...frame.path, \"_variant\"], v)}\n items={variants.map((v) => ({ value: v.id, label: v.name }))}\n className=\"w-full [&>button]:flex-1\"\n />\n ) : (\n <Select\n aria-label=\"Variant\"\n value={String(cur._variant ?? variants[0].id)}\n onValueChange={(v) => form.setAt([...frame.path, \"_variant\"], v)}\n options={variants.map((v) => ({ value: v.id, label: v.name, description: v.description }))}\n />\n )}\n </div>\n ) : null}\n <FieldList fields={frame.fields} fieldsets={frame.fieldsets} groups={frame.groups} basePath={frame.path} memoryKey={`f:${frame.kind}:${it?.block?.name ?? it?.itemSchema?.name ?? frame.field?.name ?? \"\"}`} />\n {it?.slotField?.slotSettings?.length && FieldSection ? (\n <FieldSection title={`Layout in ${it.slotField.title.toLowerCase()}`} description=\"How this block sits in its parent. The block's own content is above.\" collapsible={false}>\n <FieldList fields={it.slotField.slotSettings} basePath={[...frame.path, \"_settings\"]} memoryKey={`slotset:${it.slotField.name}`} />\n </FieldSection>\n ) : null}\n </div>\n );\n}\n\n/**\n * The context line under a drilled frame's title: \"Tier 1 of 3 in Tiers\" for an item (the item noun is the item\n * schema's title, which the adapter reads back from prod `ui.itemLabel`), \"Address in Author\" for an object.\n */\nexport function frameContext(frame: Frame, parentTitle?: string): string {\n const it = frame.item;\n if (it) {\n const noun = (frame.kind === \"block\" ? it.block?.title : it.itemSchema?.title) ?? \"Item\";\n const owner = (frame.kind === \"block\" ? it.slotField?.title : frame.field?.title) ?? \"the list\";\n return `${noun} ${it.index + 1} of ${it.count} in ${owner}`;\n }\n return parentTitle ? `${frame.field?.title ?? \"Group\"} in ${parentTitle}` : \"Group\";\n}\n\n/**\n * CPO D43 — the drilled frame's header answers \"what am I editing, and where does it live?\":\n * [media?] Starter [↑] [↓] [⋯]\n * Tier 1 of 3 in Tiers\n * The big title lives HERE only; the breadcrumb above is the path (its current crumb is small, D38). Prev / next are\n * labelled icon buttons whose tooltips name the sibling (\"Previous tier: Starter\"). No eyebrow, no duplicate counter.\n * Title 14/24 semibold (owner call). The native title= on the truncating h2 is V2 parity (kit-engine deviation from\n * the dashboard's no-title rule, see run ledger #32).\n */\nexport function FrameHeader({ frame, context, title }: { frame: Frame; context: string; title: string }) {\n const form = useForm()!;\n const { toast } = useKitServices();\n const it = frame.item;\n const media = it ? previewOf(it.block ?? it.itemSchema, form.getAt(frame.path), it.index).media : undefined;\n const step = (d: -1 | 1) => {\n if (!it) return;\n const n = it.index + d;\n if (n < 0 || n >= it.count) return;\n form.navigate([...it.arrayPath, n]);\n };\n const listRaw = it ? form.getAt(it.arrayPath) : undefined;\n const list = Array.isArray(listRaw) ? listRaw : [];\n const noun = (it?.block?.title ?? it?.itemSchema?.title ?? \"item\").toLowerCase();\n const sibling = (i: number) =>\n it && i >= 0 && i < it.count ? (it.titleAt ? it.titleAt(i) : previewOf(it.block ?? it.itemSchema, list[i], i, it.block?.title ?? it.itemSchema?.title).title) : \"\";\n const prev = it ? sibling(it.index - 1) : \"\";\n const next = it ? sibling(it.index + 1) : \"\";\n /* NEW-Q22-ROWLIMIT: the list's own bounds hold here as on its row menu (array.tsx): a duplicate past the maximum or a\n remove below the minimum only left a held, unsavable list */\n const bounds = frame.kind === \"item\" || frame.kind === \"block\" ? frame.field?.validation : undefined;\n const atMax = bounds?.max != null && list.length >= bounds.max;\n const atMin = bounds?.min != null && list.length <= bounds.min;\n /* Duplicate / Remove move to another frame: the menu must not hand focus back to its trigger in the exiting frame\n (it unmounts, focus would drop to <body>); the stage focuses the entering frame instead */\n const moved = React.useRef(false);\n return (\n <div className=\"flex items-start gap-2.5 outline-none\" data-frame-header tabIndex={-1}>\n {media ? <Thumb media={media} size={36} /> : null}\n <div className=\"min-w-0 flex-1\">\n <h2 className=\"truncate text-kit-base font-semibold leading-6 text-kit-fg\" title={title}>\n {title}\n </h2>\n <p className=\"truncate text-kit-xs leading-4 text-kit-fg-3\">{context}</p>\n </div>\n {it ? (\n <div className=\"-mr-1 flex shrink-0 items-center gap-0.5 pt-0.5\">\n <IconButton\n label={prev ? `Previous ${noun}: ${prev}` : `No previous ${noun}`}\n tooltip={prev ? `Previous ${noun}: ${prev}` : `First ${noun}`}\n size=\"sm\"\n disabled={it.index === 0}\n onClick={() => step(-1)}\n >\n <IconArrowUp stroke={1.5} />\n </IconButton>\n <IconButton\n label={next ? `Next ${noun}: ${next}` : `No next ${noun}`}\n tooltip={next ? `Next ${noun}: ${next}` : `Last ${noun}`}\n size=\"sm\"\n disabled={it.index >= it.count - 1}\n onClick={() => step(1)}\n >\n <IconArrowDown stroke={1.5} />\n </IconButton>\n <Menu>\n <Tooltip content={`${title} actions`}>\n <MenuTrigger\n render={\n <IconButton label={`${title} actions`} tooltip={false} size=\"sm\">\n <IconDots stroke={1.5} />\n </IconButton>\n }\n />\n </Tooltip>\n <MenuContent align=\"end\" className=\"w-48\" finalFocus={() => !moved.current}>\n <MenuItem\n icon={<IconCopy stroke={1.5} />}\n disabled={atMax}\n onClick={() => {\n moved.current = true;\n const copy = isObj(list[it.index]) ? { ...(structuredClone(list[it.index]) as object), _key: newKey() } : list[it.index];\n form.setAt(it.arrayPath, [...list.slice(0, it.index + 1), copy, ...list.slice(it.index + 1)]);\n form.navigate([...it.arrayPath, it.index + 1]);\n toast?.success(\"Duplicated\", { description: \"You're now editing the copy.\" });\n }}\n >\n {atMax ? \"Duplicate · limit reached\" : \"Duplicate\"}\n </MenuItem>\n <MenuSeparator />\n <MenuItem\n danger\n icon={<IconTrash stroke={1.5} />}\n disabled={atMin}\n onClick={() => {\n moved.current = true;\n const prevList = list;\n form.navigate(parentFramePath(it.arrayPath));\n form.setAt(it.arrayPath, list.filter((_, j) => j !== it.index));\n toast?.(`“${title}” removed`, { action: { label: \"Undo\", onClick: () => form.setAt(it.arrayPath, prevList) }, duration: 10_000 });\n }}\n >\n {atMin ? `Remove · at least ${bounds?.min} required` : \"Remove\"}\n </MenuItem>\n </MenuContent>\n </Menu>\n </div>\n ) : null}\n </div>\n );\n}\n/** The frame that owns an array: drop the array field name (and the item index above it, if any). */\nconst parentFramePath = (arrayPath: FieldPath): FieldPath => arrayPath.slice(0, -1);\n\n/* ── Stage: direction-aware slide, scroll memory, focus, keys (V2 schema-form) ───────────────── */\n/** The title shown as `parentTitle` for the current frame (the root crumb's label for depth 1). */\nexport function parentTitleOf(frames: Frame[], rootLabel: string): string | undefined {\n if (frames.length < 2) return undefined;\n return frames.length === 2 ? rootLabel : frames[frames.length - 2].title;\n}\n\n/** Floating layers (Base UI popups carry these roles); keys and focus coming from one belong to that layer. */\nconst LAYER = \"[role=dialog],[role=menu],[role=listbox]\";\n\n/** Slide direction for a frame change: deeper → 1, shallower → −1, a sibling step → by index. */\nexport function frameDirection(prev: { depth: number; index: number; key: string }, frames: Frame[], key: string): 0 | 1 | -1 {\n if (prev.key === key) return 0;\n const cur = frames[frames.length - 1];\n if (frames.length > prev.depth) return 1;\n if (frames.length < prev.depth) return -1;\n return (cur.item?.index ?? 0) >= prev.index ? 1 : -1;\n}\n\n/**\n * The drill-in stack's behaviour. `root` wraps the form (keys bubble to it), `scroller` is the scrolling element (or\n * null when the host scrolls). Returns the current frame, its key, the slide direction and the form's onKeyDown.\n */\nexport function useFrameNavigation({\n frames,\n navigate,\n root,\n scroller,\n}: {\n frames: Frame[];\n navigate: (path: FieldPath) => void;\n root: React.RefObject<HTMLElement | null>;\n scroller: React.RefObject<HTMLElement | null>;\n}) {\n const current = frames[frames.length - 1];\n const frameKey = frameKeyOf(current.path);\n const prev = React.useRef({ depth: frames.length, index: current.item?.index ?? 0, key: frameKey });\n const dir = frameDirection(prev.current, frames, frameKey);\n const dirRef = React.useRef<number>(1);\n if (dir) dirRef.current = dir;\n\n const scrollMem = React.useRef(new Map<string, number>());\n React.useLayoutEffect(() => {\n const was = prev.current.key;\n if (was === frameKey) return;\n if (scroller.current) scrollMem.current.set(was, scroller.current.scrollTop);\n prev.current = { depth: frames.length, index: current.item?.index ?? 0, key: frameKey };\n const el = scroller.current;\n if (el) el.scrollTop = scrollMem.current.get(frameKey) ?? 0;\n const active = document.activeElement;\n /* a move started from a portalled menu (FrameHeader ⋯ → Duplicate / Remove) leaves focus in that layer, outside root */\n const layer = active && active !== document.body ? active.closest(LAYER) : null;\n const fromLayer = !!layer && !layer.contains(root.current);\n if (root.current && (active === document.body || root.current.contains(active) || fromLayer)) {\n // the exiting frame is still mounted during its exit animation — focus the ENTERING one\n const target = root.current.querySelector<HTMLElement>(`[data-frame-body=\"${CSS.escape(frameKey)}\"]`);\n target?.focus({ preventScroll: true });\n }\n });\n\n const onKeyDown = (e: React.KeyboardEvent) => {\n if (e.defaultPrevented) return;\n const t = e.target as HTMLElement;\n // ignore keys from floating layers opened by this form; a form INSIDE a dialog still handles its own keys\n // (V2 also listed Radix's popper wrapper; Base UI popups carry these roles themselves)\n const layer = t.closest(LAYER);\n if (layer && root.current && !layer.contains(root.current)) return;\n if (e.key === \"Escape\" && frames.length > 1 && !t.isContentEditable) {\n e.preventDefault();\n e.stopPropagation();\n navigate(frames[frames.length - 2].path);\n return;\n }\n const it = current.item;\n if (it && (e.key === \"ArrowUp\" || e.key === \"ArrowDown\")) {\n const typing = t.matches(\"input,textarea,select\") || t.isContentEditable;\n if (e.altKey || (!typing && t.matches(\"[data-frame-body],[data-frame-header]\"))) {\n const n = it.index + (e.key === \"ArrowUp\" ? -1 : 1);\n if (n >= 0 && n < it.count) {\n e.preventDefault();\n navigate([...it.arrayPath, n]);\n }\n }\n }\n };\n\n return { current, frameKey, dir: dirRef.current, onKeyDown };\n}\n\nconst EASE: [number, number, number, number] = [0.22, 1, 0.36, 1];\n\n/**\n * The frame body with V2's slide: 24px along the travel direction + fade, 220ms, ease [0.22, 1, 0.36, 1]; reduced\n * motion keeps only the fade. `before` renders inside the root frame above its fields (the synced-from note).\n */\nexport function FrameStage({\n frames,\n frameKey,\n dir,\n rootLabel,\n variant,\n before,\n review,\n}: {\n frames: Frame[];\n frameKey: string;\n dir: number;\n rootLabel: string;\n variant: \"panel\" | \"document\";\n before?: React.ReactNode;\n /** D61 Review changes is on: the clip leaves 16px on the left for the change bars */\n review?: boolean;\n}) {\n const reduce = useReducedMotion();\n const current = frames[frames.length - 1];\n return (\n // the drill slide is clipped sideways; with Review changes on (D61) the clip leaves 16px on the left for the change bars\n <div className=\"relative\" style={review ? { clipPath: \"inset(-100vh 0 -100vh -16px)\" } : { overflowX: \"clip\" }}>\n <AnimatePresence mode=\"popLayout\" initial={false} custom={dir}>\n <motion.div\n key={frameKey}\n custom={dir}\n variants={{\n enter: (d: number) => ({ x: reduce ? 0 : d * 24, opacity: 0 }),\n center: { x: 0, opacity: 1 },\n exit: (d: number) => ({ x: reduce ? 0 : d * -24, opacity: 0 }),\n }}\n initial=\"enter\"\n animate=\"center\"\n exit=\"exit\"\n transition={{ duration: 0.22, ease: EASE }}\n data-frame-body={frameKey}\n tabIndex={-1}\n className={cn(\"outline-none focus-visible:shadow-none\", variant === \"document\" ? \"py-1\" : \"px-4 py-4\")}\n >\n {current.kind === \"root\" ? before : null}\n <FrameView frame={current} parentTitle={parentTitleOf(frames, rootLabel)} />\n </motion.div>\n </AnimatePresence>\n </div>\n );\n}\n\nexport { HISTORY_SEGMENT };\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAiDA,IAAM,WAAW,MAAM,cAA0B,CAAC,CAAC;AACnD,IAAa,qBAAqB,SAAS;AAC3C,IAAa,sBAAsB,MAAM,WAAW,QAAQ;;AAG5D,SAAS,eAAe,EAAE,QAAQ,YAAiC;CACjE,MAAM,OAAO,QAAQ;CACrB,MAAM,MAAM,SAAS,SAAS,KAAK,MAAM,QAAQ,IAAI,KAAK;CAC1D,MAAM,SAAS,MAAM,GAAG,IAAI,MAAM,CAAC;CACnC,MAAM,KAAK,QAAQ,MAAM,QAAQ;CACjC,MAAM,QAAQ,OAAO,QAAQ,MAAM,CAAC,SAAS,GAAG,QAAQ,EAAE,CAAC;CAC3D,OACE,qBAAC,OAAD;EAAK,WAAU;EAAf,UAAA,CACG,MAAM,KAAK,MACV,oBAAC,OAAD;GAAkB,WAAU;GAC1B,UAAA,oBAAC,UAAD;IAAU,OAAO;IAAG,MAAM,CAAC,GAAG,UAAU,EAAE,IAAI;IAAW;GAAS,CAAA;EAC/D,GAFK,EAAE,IAEP,CACN,GACA,MAAM,WAAW,IAAI,oBAAC,KAAD;GAAG,WAAU;GAA6C,UAAA;EAAsB,CAAA,IAAI,IACvG;;AAET;;AAGA,SAAS,gBAAgB,EAAE,SAA2B;CACpD,MAAM,OAAO,QAAQ;CACrB,MAAM,KAAK,MAAM,MAAM;CACvB,MAAM,QAAQ,MAAM,SAAS;EAAE,MAAM,OAAO,MAAM,KAAK,GAAG,EAAE,KAAK,QAAQ;EAAG,OAAO,MAAM;EAAO,MAAM;CAAkB;CACxH,OAAO,oBAAC,iBAAD;EAAwB;EAAO,OAAO,KAAK,MAAM,MAAM,IAAI;EAAG,WAAW,MAAM,KAAK,MAAM,MAAM,MAAM,CAAC;EAAO;EAAI,MA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ACA,SAAQ;IACR,SAAQ;IACR,MAAK;IACL,YAAY;KAAE,UAAU;KAAM,MAAM;IAAK;IACzC,mBAAiB;IACjB,UAAU;IACV,WAAW,GAAG,0CAA0C,YAAY,aAAa,SAAS,WAAW;IAdvG,UAAA,CAgBG,QAAQ,SAAS,SAAS,SAAS,MACpC,oBAAC,WAAD;KAAW,OAAO;KAAS,aAAa,cAAc,QAAQ,SAAS;IAAI,CAAA,CACjE;GAjBL,GAAA,QAiBK;EACG,CAAA;CACd,CAAA;AAET"}
|
|
1
|
+
{"version":3,"file":"frame.js","names":[],"sources":["../../src/engine/frame.tsx"],"sourcesContent":["/**\n * FrameView — what the panel shows for the current breadcrumb: the root fields, a drilled object / array item /\n * slot block (with \"2 of 4\" stepper, variant switcher and per-slot layout settings), the one button screen,\n * or a field's history as a stacked panel. Port of V2 engine/frame.tsx.\n *\n * FrameStage + useFrameNavigation — V2 schema-form's drill-in stage (direction-aware slide, scroll memory per frame,\n * focus on the entering frame, Esc / ⌥↑↓). Exported here so SchemaForm wires them without re-deriving the motion.\n *\n * FrameSlots — the frame draws other lanes' pieces (FieldList / FieldSection from grouping, ButtonScreen from link,\n * TableFrame from table). They arrive through context so this file never imports a module that does not exist yet;\n * a missing slot falls back to a plain field list (FieldList), the raw value (ButtonScreen, through\n * FallbackControl), a named note (TableFrame) or nothing (FieldSection). SchemaForm always hands ButtonScreen and TableFrame.\n */\nimport * as React from \"react\";\nimport { AnimatePresence, motion, useReducedMotion } from \"framer-motion\";\nimport { IconArrowDown, IconArrowUp, IconCopy, IconDots, IconTrash } from \"@tabler/icons-react\";\nimport { IconButton } from \"../ui/button\";\nimport { Menu, MenuContent, MenuItem, MenuSeparator, MenuTrigger, Tooltip } from \"../ui/overlay\";\nimport { Segmented } from \"../ui/controls\";\nimport { fitsSegmented } from \"../ui/choice-switch\";\nimport { Select } from \"../ui/select\";\nimport { resolveFieldAccess, useForm, useKitEnv, useKitServices } from \"../context\";\nimport { cn } from \"../lib/cn\";\nimport { HISTORY_SEGMENT, type FieldGroup, type FieldPath, type FieldSchema, type Fieldset } from \"../schema/types\";\nimport type { Frame } from \"../lib/frames\";\nimport { frameKeyOf, isObj, newKey } from \"../lib/path\";\nimport { condCtx, isHidden, previewOf } from \"../lib/schema\";\nimport { Thumb } from \"./bits\";\nimport { FallbackControl, KitField } from \"./kit-field\";\n\n/* ── Slots (other lanes) ───────────────────────────────────────────── */\nexport interface FrameFieldListProps {\n fields: FieldSchema[];\n fieldsets?: Fieldset[];\n groups?: FieldGroup[];\n basePath: FieldPath;\n memoryKey: string;\n}\nexport interface FrameSlots {\n /** grouping lane: engine/field-list.tsx `FieldList` */\n FieldList?: React.ComponentType<FrameFieldListProps>;\n /** grouping lane: engine/grouping.tsx `FieldSection` (the slot-settings section of a slot block) */\n FieldSection?: React.ComponentType<{ title: string; description?: string; collapsible?: boolean; children: React.ReactNode }>;\n /** link lane: controls/link.tsx `ButtonScreen` + `normLink` (the \"button\" frame) */\n ButtonScreen?: React.ComponentType<{ value: unknown; onChange: (v: unknown) => void; title: string; readOnly?: boolean }>;\n normLink?: (v: unknown) => { label?: string };\n /** table lane: controls/table.tsx `TableFrame` (tableRow / tableColumn frames) */\n TableFrame?: React.ComponentType<{ frame: Frame }>;\n}\nconst SlotsCtx = React.createContext<FrameSlots>({});\nexport const FrameSlotsProvider = SlotsCtx.Provider;\nexport const useFrameSlots = () => React.useContext(SlotsCtx);\n\n/** Stand-in until the grouping lane's FieldList lands: the frame's visible fields in schema order. */\nfunction PlainFieldList({ fields, basePath }: FrameFieldListProps) {\n const form = useForm()!;\n const raw = basePath.length ? form.getAt(basePath) : form.value;\n const parent = isObj(raw) ? raw : {};\n const cc = condCtx(form, basePath);\n const shown = fields.filter((f) => !isHidden(f, parent, cc));\n return (\n <div className=\"flex flex-col gap-5\">\n {shown.map((f) => (\n <div key={f.name} className=\"min-w-0\">\n <KitField field={f} path={[...basePath, f.name]} parent={parent} />\n </div>\n ))}\n {shown.length === 0 ? <p className=\"py-6 text-center text-kit-sm text-kit-fg-3\">No fields here yet.</p> : null}\n </div>\n );\n}\n\n/** A button frame outside SchemaForm (no ButtonScreen slot) edits the button's raw value (FallbackControl), never an empty body. */\nfunction RawButtonScreen({ frame }: { frame: Frame }) {\n const form = useForm()!;\n const id = React.useId();\n const field = frame.field ?? { name: String(frame.path.at(-1) ?? \"button\"), title: frame.title, type: \"button\" as const };\n return <FallbackControl field={field} value={form.getAt(frame.path)} onChange={(n) => form.setAt(frame.path, n)} id={id} path={frame.path} />;\n}\n\n/** The button frame: header (the button's label) + the kit ButtonScreen, read-only when the lens can't edit the field. */\nfunction ButtonFrame({ frame, parentTitle }: { frame: Frame; parentTitle?: string }) {\n const form = useForm()!;\n const env = useKitEnv();\n const slots = useFrameSlots();\n const v = form.getAt(frame.path);\n const ButtonScreen = slots.ButtonScreen;\n const readOnly = frame.field ? resolveFieldAccess(frame.field, env).readOnly : !!env.readOnly;\n return (\n <div className=\"flex flex-col gap-5\">\n <FrameHeader frame={frame} context={parentTitle ? `${frame.title} in ${parentTitle}` : frame.title} title={slots.normLink?.(v).label || frame.title} />\n {ButtonScreen ? <ButtonScreen value={v} onChange={(n) => form.setAt(frame.path, n)} title={frame.title} readOnly={readOnly} /> : <RawButtonScreen frame={frame} />}\n </div>\n );\n}\n\n/* ── FrameView ─────────────────────────────────────────────────────── */\nexport function FrameView({ frame, parentTitle }: { frame: Frame; parentTitle?: string }) {\n const form = useForm()!;\n const slots = useFrameSlots();\n const FieldList = slots.FieldList ?? PlainFieldList;\n if (frame.kind === \"history\") return null; // D61: a field's history is the host's one History panel (onFieldHistory)\n if (frame.kind === \"button\") return <ButtonFrame frame={frame} parentTitle={parentTitle} />;\n // D50: a table row or column drills exactly like an array item: the same header (title, n of N, ↑ ↓ ⋯), its cells below\n if (frame.kind === \"tableRow\" || frame.kind === \"tableColumn\") {\n const it = frame.item!;\n const TableFrame = slots.TableFrame;\n return (\n <div className=\"flex flex-col gap-5\">\n <FrameHeader frame={frame} context={`${it.itemSchema?.title} ${it.index + 1} of ${it.count} in ${frame.field?.title ?? \"the table\"}`} title={frame.title} />\n {TableFrame ? (\n <TableFrame frame={frame} />\n ) : (\n /* Only the kit table control opens a row or column frame; until it is ported the table is the host's control,\n which edits rows in place. A path restored into one says so instead of drawing an empty body. */\n <p role=\"note\" data-kit-legacy=\"table\" className=\"text-kit-sm text-kit-fg-3\">\n This table's rows and columns are edited in the table itself.\n </p>\n )}\n </div>\n );\n }\n if (frame.kind === \"root\") return <FieldList fields={frame.fields} fieldsets={frame.fieldsets} groups={frame.groups} basePath={[]} memoryKey=\"root\" />;\n const it = frame.item;\n const block = it?.block;\n const variants = block?.variants ?? [];\n const raw = form.getAt(frame.path);\n const cur = isObj(raw) ? raw : {};\n const FieldSection = slots.FieldSection;\n return (\n <div className=\"flex flex-col gap-5\">\n <FrameHeader frame={frame} context={frameContext(frame, parentTitle)} title={frame.title} />\n {block && variants.length > 1 ? (\n <div className=\"flex flex-col gap-1.5\">\n <span className=\"text-kit-sm font-medium text-kit-fg-2\">Layout</span>\n {fitsSegmented(variants.map((v) => v.name)) ? (\n <Segmented\n aria-label=\"Layout\"\n value={String(cur._variant ?? variants[0].id)}\n onChange={(v) => form.setAt([...frame.path, \"_variant\"], v)}\n items={variants.map((v) => ({ value: v.id, label: v.name }))}\n className=\"w-full [&>button]:flex-1\"\n />\n ) : (\n <Select\n aria-label=\"Variant\"\n value={String(cur._variant ?? variants[0].id)}\n onValueChange={(v) => form.setAt([...frame.path, \"_variant\"], v)}\n options={variants.map((v) => ({ value: v.id, label: v.name, description: v.description }))}\n />\n )}\n </div>\n ) : null}\n <FieldList fields={frame.fields} fieldsets={frame.fieldsets} groups={frame.groups} basePath={frame.path} memoryKey={`f:${frame.kind}:${it?.block?.name ?? it?.itemSchema?.name ?? frame.field?.name ?? \"\"}`} />\n {it?.slotField?.slotSettings?.length && FieldSection ? (\n <FieldSection title={`Layout in ${it.slotField.title.toLowerCase()}`} description=\"How this block sits in its parent. The block's own content is above.\" collapsible={false}>\n <FieldList fields={it.slotField.slotSettings} basePath={[...frame.path, \"_settings\"]} memoryKey={`slotset:${it.slotField.name}`} />\n </FieldSection>\n ) : null}\n </div>\n );\n}\n\n/**\n * The context line under a drilled frame's title: \"Tier 1 of 3 in Tiers\" for an item (the item noun is the item\n * schema's title, which the adapter reads back from prod `ui.itemLabel`), \"Address in Author\" for an object.\n */\nexport function frameContext(frame: Frame, parentTitle?: string): string {\n const it = frame.item;\n if (it) {\n const noun = (frame.kind === \"block\" ? it.block?.title : it.itemSchema?.title) ?? \"Item\";\n const owner = (frame.kind === \"block\" ? it.slotField?.title : frame.field?.title) ?? \"the list\";\n return `${noun} ${it.index + 1} of ${it.count} in ${owner}`;\n }\n return parentTitle ? `${frame.field?.title ?? \"Group\"} in ${parentTitle}` : \"Group\";\n}\n\n/**\n * CPO D43 — the drilled frame's header answers \"what am I editing, and where does it live?\":\n * [media?] Starter [↑] [↓] [⋯]\n * Tier 1 of 3 in Tiers\n * The big title lives HERE only; the breadcrumb above is the path (its current crumb is small, D38). Prev / next are\n * labelled icon buttons whose tooltips name the sibling (\"Previous tier: Starter\"). No eyebrow, no duplicate counter.\n * Title 14/24 semibold (owner call). The native title= on the truncating h2 is V2 parity (kit-engine deviation from\n * the dashboard's no-title rule, see run ledger #32).\n */\nexport function FrameHeader({ frame, context, title }: { frame: Frame; context: string; title: string }) {\n const form = useForm()!;\n const { toast } = useKitServices();\n const it = frame.item;\n const media = it ? previewOf(it.block ?? it.itemSchema, form.getAt(frame.path), it.index).media : undefined;\n const step = (d: -1 | 1) => {\n if (!it) return;\n const n = it.index + d;\n if (n < 0 || n >= it.count) return;\n form.navigate([...it.arrayPath, n]);\n };\n const listRaw = it ? form.getAt(it.arrayPath) : undefined;\n const list = Array.isArray(listRaw) ? listRaw : [];\n const noun = (it?.block?.title ?? it?.itemSchema?.title ?? \"item\").toLowerCase();\n const sibling = (i: number) =>\n it && i >= 0 && i < it.count ? (it.titleAt ? it.titleAt(i) : previewOf(it.block ?? it.itemSchema, list[i], i, it.block?.title ?? it.itemSchema?.title).title) : \"\";\n const prev = it ? sibling(it.index - 1) : \"\";\n const next = it ? sibling(it.index + 1) : \"\";\n /* NEW-Q22-ROWLIMIT: the list's own bounds hold here as on its row menu (array.tsx): a duplicate past the maximum or a\n remove below the minimum only left a held, unsavable list */\n const bounds = frame.kind === \"item\" || frame.kind === \"block\" ? frame.field?.validation : undefined;\n const atMax = bounds?.max != null && list.length >= bounds.max;\n const atMin = bounds?.min != null && list.length <= bounds.min;\n /* NEW-Q48-ITEMACTIONS: a read-only list (a locked section, a viewer) offers no Duplicate / Remove: the host drops the\n write, so the menu only announced a change that never happened */\n const env = useKitEnv();\n const readOnly = frame.field ? resolveFieldAccess(frame.field, env).readOnly : !!env.readOnly;\n /* Duplicate / Remove move to another frame: the menu must not hand focus back to its trigger in the exiting frame\n (it unmounts, focus would drop to <body>); the stage focuses the entering frame instead */\n const moved = React.useRef(false);\n return (\n <div className=\"flex items-start gap-2.5 outline-none\" data-frame-header tabIndex={-1}>\n {media ? <Thumb media={media} size={36} /> : null}\n <div className=\"min-w-0 flex-1\">\n <h2 className=\"truncate text-kit-base font-semibold leading-6 text-kit-fg\" title={title}>\n {title}\n </h2>\n <p className=\"truncate text-kit-xs leading-4 text-kit-fg-3\">{context}</p>\n </div>\n {it ? (\n <div className=\"-mr-1 flex shrink-0 items-center gap-0.5 pt-0.5\">\n <IconButton\n label={prev ? `Previous ${noun}: ${prev}` : `No previous ${noun}`}\n tooltip={prev ? `Previous ${noun}: ${prev}` : `First ${noun}`}\n size=\"sm\"\n disabled={it.index === 0}\n onClick={() => step(-1)}\n >\n <IconArrowUp stroke={1.5} />\n </IconButton>\n <IconButton\n label={next ? `Next ${noun}: ${next}` : `No next ${noun}`}\n tooltip={next ? `Next ${noun}: ${next}` : `Last ${noun}`}\n size=\"sm\"\n disabled={it.index >= it.count - 1}\n onClick={() => step(1)}\n >\n <IconArrowDown stroke={1.5} />\n </IconButton>\n {readOnly ? null : (\n <Menu>\n <Tooltip content={`${title} actions`}>\n <MenuTrigger\n render={\n <IconButton label={`${title} actions`} tooltip={false} size=\"sm\">\n <IconDots stroke={1.5} />\n </IconButton>\n }\n />\n </Tooltip>\n <MenuContent align=\"end\" className=\"w-48\" finalFocus={() => !moved.current}>\n <MenuItem\n icon={<IconCopy stroke={1.5} />}\n disabled={atMax}\n onClick={() => {\n moved.current = true;\n const copy = isObj(list[it.index]) ? { ...(structuredClone(list[it.index]) as object), _key: newKey() } : list[it.index];\n form.setAt(it.arrayPath, [...list.slice(0, it.index + 1), copy, ...list.slice(it.index + 1)]);\n form.navigate([...it.arrayPath, it.index + 1]);\n toast?.success(\"Duplicated\", { description: \"You're now editing the copy.\" });\n }}\n >\n {atMax ? \"Duplicate · limit reached\" : \"Duplicate\"}\n </MenuItem>\n <MenuSeparator />\n <MenuItem\n danger\n icon={<IconTrash stroke={1.5} />}\n disabled={atMin}\n onClick={() => {\n moved.current = true;\n const prevList = list;\n form.navigate(parentFramePath(it.arrayPath));\n form.setAt(it.arrayPath, list.filter((_, j) => j !== it.index));\n toast?.(`“${title}” removed`, { action: { label: \"Undo\", onClick: () => form.setAt(it.arrayPath, prevList) }, duration: 10_000 });\n }}\n >\n {atMin ? `Remove · at least ${bounds?.min} required` : \"Remove\"}\n </MenuItem>\n </MenuContent>\n </Menu>\n )}\n </div>\n ) : null}\n </div>\n );\n}\n/** The frame that owns an array: drop the array field name (and the item index above it, if any). */\nconst parentFramePath = (arrayPath: FieldPath): FieldPath => arrayPath.slice(0, -1);\n\n/* ── Stage: direction-aware slide, scroll memory, focus, keys (V2 schema-form) ───────────────── */\n/** The title shown as `parentTitle` for the current frame (the root crumb's label for depth 1). */\nexport function parentTitleOf(frames: Frame[], rootLabel: string): string | undefined {\n if (frames.length < 2) return undefined;\n return frames.length === 2 ? rootLabel : frames[frames.length - 2].title;\n}\n\n/** Floating layers (Base UI popups carry these roles); keys and focus coming from one belong to that layer. */\nconst LAYER = \"[role=dialog],[role=menu],[role=listbox]\";\n\n/** Slide direction for a frame change: deeper → 1, shallower → −1, a sibling step → by index. */\nexport function frameDirection(prev: { depth: number; index: number; key: string }, frames: Frame[], key: string): 0 | 1 | -1 {\n if (prev.key === key) return 0;\n const cur = frames[frames.length - 1];\n if (frames.length > prev.depth) return 1;\n if (frames.length < prev.depth) return -1;\n return (cur.item?.index ?? 0) >= prev.index ? 1 : -1;\n}\n\n/**\n * The drill-in stack's behaviour. `root` wraps the form (keys bubble to it), `scroller` is the scrolling element (or\n * null when the host scrolls). Returns the current frame, its key, the slide direction and the form's onKeyDown.\n */\nexport function useFrameNavigation({\n frames,\n navigate,\n root,\n scroller,\n}: {\n frames: Frame[];\n navigate: (path: FieldPath) => void;\n root: React.RefObject<HTMLElement | null>;\n scroller: React.RefObject<HTMLElement | null>;\n}) {\n const current = frames[frames.length - 1];\n const frameKey = frameKeyOf(current.path);\n const prev = React.useRef({ depth: frames.length, index: current.item?.index ?? 0, key: frameKey });\n const dir = frameDirection(prev.current, frames, frameKey);\n const dirRef = React.useRef<number>(1);\n if (dir) dirRef.current = dir;\n\n const scrollMem = React.useRef(new Map<string, number>());\n React.useLayoutEffect(() => {\n const was = prev.current.key;\n if (was === frameKey) return;\n if (scroller.current) scrollMem.current.set(was, scroller.current.scrollTop);\n prev.current = { depth: frames.length, index: current.item?.index ?? 0, key: frameKey };\n const el = scroller.current;\n if (el) el.scrollTop = scrollMem.current.get(frameKey) ?? 0;\n const active = document.activeElement;\n /* a move started from a portalled menu (FrameHeader ⋯ → Duplicate / Remove) leaves focus in that layer, outside root */\n const layer = active && active !== document.body ? active.closest(LAYER) : null;\n const fromLayer = !!layer && !layer.contains(root.current);\n if (root.current && (active === document.body || root.current.contains(active) || fromLayer)) {\n // the exiting frame is still mounted during its exit animation — focus the ENTERING one\n const target = root.current.querySelector<HTMLElement>(`[data-frame-body=\"${CSS.escape(frameKey)}\"]`);\n target?.focus({ preventScroll: true });\n }\n });\n\n const onKeyDown = (e: React.KeyboardEvent) => {\n if (e.defaultPrevented) return;\n const t = e.target as HTMLElement;\n // ignore keys from floating layers opened by this form; a form INSIDE a dialog still handles its own keys\n // (V2 also listed Radix's popper wrapper; Base UI popups carry these roles themselves)\n const layer = t.closest(LAYER);\n if (layer && root.current && !layer.contains(root.current)) return;\n if (e.key === \"Escape\" && frames.length > 1 && !t.isContentEditable) {\n e.preventDefault();\n e.stopPropagation();\n navigate(frames[frames.length - 2].path);\n return;\n }\n const it = current.item;\n if (it && (e.key === \"ArrowUp\" || e.key === \"ArrowDown\")) {\n const typing = t.matches(\"input,textarea,select\") || t.isContentEditable;\n if (e.altKey || (!typing && t.matches(\"[data-frame-body],[data-frame-header]\"))) {\n const n = it.index + (e.key === \"ArrowUp\" ? -1 : 1);\n if (n >= 0 && n < it.count) {\n e.preventDefault();\n navigate([...it.arrayPath, n]);\n }\n }\n }\n };\n\n return { current, frameKey, dir: dirRef.current, onKeyDown };\n}\n\nconst EASE: [number, number, number, number] = [0.22, 1, 0.36, 1];\n\n/**\n * The frame body with V2's slide: 24px along the travel direction + fade, 220ms, ease [0.22, 1, 0.36, 1]; reduced\n * motion keeps only the fade. `before` renders inside the root frame above its fields (the synced-from note).\n */\nexport function FrameStage({\n frames,\n frameKey,\n dir,\n rootLabel,\n variant,\n before,\n review,\n}: {\n frames: Frame[];\n frameKey: string;\n dir: number;\n rootLabel: string;\n variant: \"panel\" | \"document\";\n before?: React.ReactNode;\n /** D61 Review changes is on: the clip leaves 16px on the left for the change bars */\n review?: boolean;\n}) {\n const reduce = useReducedMotion();\n const current = frames[frames.length - 1];\n return (\n // the drill slide is clipped sideways; with Review changes on (D61) the clip leaves 16px on the left for the change bars\n <div className=\"relative\" style={review ? { clipPath: \"inset(-100vh 0 -100vh -16px)\" } : { overflowX: \"clip\" }}>\n <AnimatePresence mode=\"popLayout\" initial={false} custom={dir}>\n <motion.div\n key={frameKey}\n custom={dir}\n variants={{\n enter: (d: number) => ({ x: reduce ? 0 : d * 24, opacity: 0 }),\n center: { x: 0, opacity: 1 },\n exit: (d: number) => ({ x: reduce ? 0 : d * -24, opacity: 0 }),\n }}\n initial=\"enter\"\n animate=\"center\"\n exit=\"exit\"\n transition={{ duration: 0.22, ease: EASE }}\n data-frame-body={frameKey}\n tabIndex={-1}\n className={cn(\"outline-none focus-visible:shadow-none\", variant === \"document\" ? \"py-1\" : \"px-4 py-4\")}\n >\n {current.kind === \"root\" ? before : null}\n <FrameView frame={current} parentTitle={parentTitleOf(frames, rootLabel)} />\n </motion.div>\n </AnimatePresence>\n </div>\n );\n}\n\nexport { HISTORY_SEGMENT };\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAiDA,IAAM,WAAW,MAAM,cAA0B,CAAC,CAAC;AACnD,IAAa,qBAAqB,SAAS;AAC3C,IAAa,sBAAsB,MAAM,WAAW,QAAQ;;AAG5D,SAAS,eAAe,EAAE,QAAQ,YAAiC;CACjE,MAAM,OAAO,QAAQ;CACrB,MAAM,MAAM,SAAS,SAAS,KAAK,MAAM,QAAQ,IAAI,KAAK;CAC1D,MAAM,SAAS,MAAM,GAAG,IAAI,MAAM,CAAC;CACnC,MAAM,KAAK,QAAQ,MAAM,QAAQ;CACjC,MAAM,QAAQ,OAAO,QAAQ,MAAM,CAAC,SAAS,GAAG,QAAQ,EAAE,CAAC;CAC3D,OACE,qBAAC,OAAD;EAAK,WAAU;EAAf,UAAA,CACG,MAAM,KAAK,MACV,oBAAC,OAAD;GAAkB,WAAU;GAC1B,UAAA,oBAAC,UAAD;IAAU,OAAO;IAAG,MAAM,CAAC,GAAG,UAAU,EAAE,IAAI;IAAW;GAAS,CAAA;EAC/D,GAFK,EAAE,IAEP,CACN,GACA,MAAM,WAAW,IAAI,oBAAC,KAAD;GAAG,WAAU;GAA6C,UAAA;EAAsB,CAAA,IAAI,IACvG;;AAET;;AAGA,SAAS,gBAAgB,EAAE,SAA2B;CACpD,MAAM,OAAO,QAAQ;CACrB,MAAM,KAAK,M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E,oBAAC,OAAD;EAAK,WAAU;EAAW,OAAO,SAAS,EAAE,UAAU,+BAA+B,IAAI,EAAE,WAAW,OAAO;EAC3G,UAAA,oBAAC,iBAAD;GAAiB,MAAK;GAAY,SAAS;GAAO,QAAQ;GACxD,UAAA,qBAAC,OAAO,KAAR;IAEE,QAAQ;IACR,UAAU;KACR,QAAQ,OAAe;MAAE,GAAG,SAAS,IAAI,IAAI;MAAI,SAAS;KAAE;KAC5D,QAAQ;MAAE,GAAG;MAAG,SAAS;KAAE;KAC3B,OAAO,OAAe;MAAE,GAAG,SAAS,IAAI,IAAI;MAAK,SAAS;KAAE;IAC9D;IACA,SAAQ;IACR,SAAQ;IACR,MAAK;IACL,YAAY;KAAE,UAAU;KAAM,MAAM;IAAK;IACzC,mBAAiB;IACjB,UAAU;IACV,WAAW,GAAG,0CAA0C,YAAY,aAAa,SAAS,WAAW;IAdvG,UAAA,CAgBG,QAAQ,SAAS,SAAS,SAAS,MACpC,oBAAC,WAAD;KAAW,OAAO;KAAS,aAAa,cAAc,QAAQ,SAAS;IAAI,CAAA,CACjE;GAjBL,GAAA,QAiBK;EACG,CAAA;CACd,CAAA;AAET"}
|
package/dist/engine/kit-field.js
CHANGED
|
@@ -463,6 +463,8 @@ function PlainValue({ field, value, id }) {
|
|
|
463
463
|
return /* @__PURE__ */ jsx("p", {
|
|
464
464
|
id,
|
|
465
465
|
tabIndex: 0,
|
|
466
|
+
role: "group",
|
|
467
|
+
"aria-labelledby": `${id}-label ${id}`,
|
|
466
468
|
"data-slot": "kit-plain",
|
|
467
469
|
className: cn("min-w-0 whitespace-pre-wrap break-words text-kit-sm leading-6 text-kit-fg outline-none", (field.type === "slug" || field.type === "url") && "font-kit-mono text-kit-xs leading-6"),
|
|
468
470
|
children: text || /* @__PURE__ */ jsx("span", {
|