@elytracms/studio 0.0.105 → 0.0.106
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/components/builder/builder-store.d.ts +19 -3
- package/dist/components/builder/builder-store.js +24 -13
- package/dist/components/builder/builder-store.js.map +1 -1
- package/dist/components/builder/clipboard-actions.js +6 -5
- package/dist/components/builder/clipboard-actions.js.map +1 -1
- package/dist/components/builder/composition-field-editor.js +4 -2
- package/dist/components/builder/composition-field-editor.js.map +1 -1
- package/dist/components/cms/duplicate-document.js +5 -5
- package/dist/components/cms/duplicate-document.js.map +1 -1
- package/dist/components/cms/rich-text/editor.d.ts +7 -1
- package/dist/components/cms/rich-text/editor.js +9 -4
- package/dist/components/cms/rich-text/editor.js.map +1 -1
- package/dist/components/cms/rich-text/embed-identity.d.ts +36 -0
- package/dist/components/cms/rich-text/embed-identity.js +114 -0
- package/dist/components/cms/rich-text/embed-identity.js.map +1 -0
- package/dist/components/cms/rich-text/extensions.d.ts +7 -1
- package/dist/components/cms/rich-text/extensions.js +7 -1
- package/dist/components/cms/rich-text/extensions.js.map +1 -1
- package/dist/components/cms/rich-text/insert.d.ts +10 -5
- package/dist/components/cms/rich-text/insert.js +10 -12
- package/dist/components/cms/rich-text/insert.js.map +1 -1
- package/dist/components/components/component-preview.d.ts +0 -2
- package/dist/components/components/component-preview.js +0 -4
- package/dist/components/components/component-preview.js.map +1 -1
- package/dist/components/components/transfer-dialog.js +3 -1
- package/dist/components/components/transfer-dialog.js.map +1 -1
- package/dist/components/components/transfer.d.ts +12 -8
- package/dist/components/components/transfer.js +16 -15
- package/dist/components/components/transfer.js.map +1 -1
- package/dist/lib/ai/translate-document.js +47 -4
- package/dist/lib/ai/translate-document.js.map +1 -1
- package/dist/lib/ai/writer-form.js +5 -4
- package/dist/lib/ai/writer-form.js.map +1 -1
- package/dist/lib/engine-version.d.ts +1 -1
- package/dist/lib/engine-version.js +1 -1
- package/dist/lib/engine-version.js.map +1 -1
- package/dist/lib/i18n/messages.de.js +4 -1
- package/dist/lib/i18n/messages.de.js.map +1 -1
- package/dist/lib/i18n/messages.en.d.ts +3 -0
- package/dist/lib/i18n/messages.en.js +4 -1
- package/dist/lib/i18n/messages.en.js.map +1 -1
- package/dist/lib/persona/labels.js +1 -0
- package/dist/lib/persona/labels.js.map +1 -1
- package/dist/lib/registry/preview.d.ts +2 -1
- package/dist/lib/registry/preview.js +8 -3
- package/dist/lib/registry/preview.js.map +1 -1
- package/package.json +3 -3
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
import { Extension } from '@tiptap/react';
|
|
2
|
+
import { Plugin, PluginKey } from '@tiptap/pm/state';
|
|
3
|
+
import { isComponentNodeValue, withFreshNodeIds } from '@elytracms/core/cms-core';
|
|
4
|
+
import { COMPONENT_EMBED_NODE_TYPE } from './component-embed.js';
|
|
5
|
+
/**
|
|
6
|
+
* **Identity in the flow editor** (EC-776, owner ruling 2026-11-04: a component node id is
|
|
7
|
+
* unique within the whole document). The embed atom is draggable, and a drop with Alt (macOS) /
|
|
8
|
+
* Ctrl COPIES the slice instead of moving it — the copy carried the original's `attrs.node`, id
|
|
9
|
+
* and all. Identity is minted where content is copied, so this plugin re-mints, after every
|
|
10
|
+
* user transaction that changed the document, each embed occurrence the transaction ADDED whose id
|
|
11
|
+
* the document already holds: the whole embedded subtree, through `withFreshNodeIds` (the one copy).
|
|
12
|
+
*
|
|
13
|
+
* "Added" follows the transaction's own mapping, not document order: an occurrence that maps from
|
|
14
|
+
* an occurrence of the previous document keeps its id — a move (deleted at one place, inserted at
|
|
15
|
+
* another, one transaction) leaves one occurrence, nothing to re-mint; a copy dropped BEFORE its
|
|
16
|
+
* original is the one re-minted. Stored twins (drift the validator names as `duplicate-node-id`)
|
|
17
|
+
* both map from the previous document and are left as stored; so is an external re-push of the
|
|
18
|
+
* stored value (`setContent` with `emitUpdate: false` sets TipTap's `preventUpdate` meta) — the
|
|
19
|
+
* editor never rewrites storage on load.
|
|
20
|
+
*
|
|
21
|
+
* Pure ProseMirror (`appendTransaction`), pinned in node through prosemirror-state.
|
|
22
|
+
*/
|
|
23
|
+
export const EMBED_IDENTITY_EXTENSION = 'elytraEmbedIdentity';
|
|
24
|
+
const KEY = new PluginKey(EMBED_IDENTITY_EXTENSION);
|
|
25
|
+
function embedIdOf(node) {
|
|
26
|
+
if (node.type.name !== COMPONENT_EMBED_NODE_TYPE)
|
|
27
|
+
return undefined;
|
|
28
|
+
const embedded = node.attrs.node;
|
|
29
|
+
return isComponentNodeValue(embedded) ? embedded.id : undefined;
|
|
30
|
+
}
|
|
31
|
+
/** Every embed with a readable node, in document order. */
|
|
32
|
+
function occurrencesIn(doc) {
|
|
33
|
+
const out = [];
|
|
34
|
+
doc.descendants((node, pos) => {
|
|
35
|
+
if (node.type.name !== COMPONENT_EMBED_NODE_TYPE)
|
|
36
|
+
return true;
|
|
37
|
+
const id = embedIdOf(node);
|
|
38
|
+
if (id !== undefined)
|
|
39
|
+
out.push({ pos, id });
|
|
40
|
+
return false; // an atom: nothing inside
|
|
41
|
+
});
|
|
42
|
+
return out;
|
|
43
|
+
}
|
|
44
|
+
/** Where `pos` of the previous document sits after `transactions` — `undefined` once deleted. */
|
|
45
|
+
function mapForward(pos, transactions) {
|
|
46
|
+
let at = pos;
|
|
47
|
+
for (const tr of transactions) {
|
|
48
|
+
const result = tr.mapping.mapResult(at, 1);
|
|
49
|
+
if (result.deleted)
|
|
50
|
+
return undefined;
|
|
51
|
+
at = result.pos;
|
|
52
|
+
}
|
|
53
|
+
return at;
|
|
54
|
+
}
|
|
55
|
+
/** The re-mint transaction for `transactions`, or `null` when no added embed repeats an id. */
|
|
56
|
+
export function remintCopiedEmbeds(transactions, oldState, newState, options) {
|
|
57
|
+
if (!transactions.some((tr) => tr.docChanged))
|
|
58
|
+
return null;
|
|
59
|
+
// An external re-push of the stored value: storage is the validator's to judge, never rewritten here.
|
|
60
|
+
if (transactions.some((tr) => tr.getMeta('preventUpdate') === true))
|
|
61
|
+
return null;
|
|
62
|
+
const after = occurrencesIn(newState.doc);
|
|
63
|
+
const counts = new Map();
|
|
64
|
+
for (const { id } of after)
|
|
65
|
+
counts.set(id, (counts.get(id) ?? 0) + 1);
|
|
66
|
+
if (![...counts.values()].some((count) => count > 1))
|
|
67
|
+
return null;
|
|
68
|
+
const carried = new Set();
|
|
69
|
+
for (const { pos } of occurrencesIn(oldState.doc)) {
|
|
70
|
+
const mapped = mapForward(pos, transactions);
|
|
71
|
+
if (mapped !== undefined)
|
|
72
|
+
carried.add(mapped);
|
|
73
|
+
}
|
|
74
|
+
// Per repeated id: the occurrences that map from the previous document keep it; with none, the
|
|
75
|
+
// first in document order does. Every other occurrence is a copy.
|
|
76
|
+
const keeps = new Set();
|
|
77
|
+
for (const [id, count] of counts) {
|
|
78
|
+
if (count < 2)
|
|
79
|
+
continue;
|
|
80
|
+
const of = after.filter((occurrence) => occurrence.id === id);
|
|
81
|
+
const kept = of.filter((occurrence) => carried.has(occurrence.pos));
|
|
82
|
+
for (const occurrence of kept.length > 0 ? kept : of.slice(0, 1))
|
|
83
|
+
keeps.add(occurrence.pos);
|
|
84
|
+
}
|
|
85
|
+
let tr = null;
|
|
86
|
+
for (const { pos, id } of after) {
|
|
87
|
+
if ((counts.get(id) ?? 0) < 2 || keeps.has(pos))
|
|
88
|
+
continue;
|
|
89
|
+
const node = newState.doc.nodeAt(pos);
|
|
90
|
+
const fresh = withFreshNodeIds(node.attrs.node, options.newId, {
|
|
91
|
+
lookupManifest: options.lookupManifest,
|
|
92
|
+
});
|
|
93
|
+
// An atom of the same size: re-marking it moves no other position.
|
|
94
|
+
tr = (tr ?? newState.tr).setNodeMarkup(pos, undefined, { ...node.attrs, node: fresh });
|
|
95
|
+
}
|
|
96
|
+
return tr;
|
|
97
|
+
}
|
|
98
|
+
/** The ProseMirror plugin ({@link remintCopiedEmbeds} after every transaction). */
|
|
99
|
+
export function embedIdentityPlugin(options) {
|
|
100
|
+
return new Plugin({
|
|
101
|
+
key: KEY,
|
|
102
|
+
appendTransaction: (transactions, oldState, newState) => remintCopiedEmbeds(transactions, oldState, newState, options),
|
|
103
|
+
});
|
|
104
|
+
}
|
|
105
|
+
/** The TipTap extension the editor's set carries ({@link buildRichTextExtensions}). */
|
|
106
|
+
export function createEmbedIdentity(options) {
|
|
107
|
+
return Extension.create({
|
|
108
|
+
name: EMBED_IDENTITY_EXTENSION,
|
|
109
|
+
addProseMirrorPlugins() {
|
|
110
|
+
return [embedIdentityPlugin(options)];
|
|
111
|
+
},
|
|
112
|
+
});
|
|
113
|
+
}
|
|
114
|
+
//# sourceMappingURL=embed-identity.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"embed-identity.js","sourceRoot":"","sources":["../../../../src/components/cms/rich-text/embed-identity.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,eAAe,CAAA;AACzC,OAAO,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAA;AAGpD,OAAO,EAAE,oBAAoB,EAAE,gBAAgB,EAAE,MAAM,0BAA0B,CAAA;AAGjF,OAAO,EAAE,yBAAyB,EAAE,MAAM,mBAAmB,CAAA;AAE7D;;;;;;;;;;;;;;;;;GAiBG;AAEH,MAAM,CAAC,MAAM,wBAAwB,GAAG,qBAAqB,CAAA;AAS7D,MAAM,GAAG,GAAG,IAAI,SAAS,CAAC,wBAAwB,CAAC,CAAA;AAOnD,SAAS,SAAS,CAAC,IAAY;IAC7B,IAAI,IAAI,CAAC,IAAI,CAAC,IAAI,KAAK,yBAAyB;QAAE,OAAO,SAAS,CAAA;IAClE,MAAM,QAAQ,GAAY,IAAI,CAAC,KAAK,CAAC,IAAI,CAAA;IACzC,OAAO,oBAAoB,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC,CAAC,SAAS,CAAA;AACjE,CAAC;AAED,2DAA2D;AAC3D,SAAS,aAAa,CAAC,GAAW;I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,CAAC;QACtB,IAAI,EAAE,wBAAwB;QAC9B,qBAAqB;YACnB,OAAO,CAAC,mBAAmB,CAAC,OAAO,CAAC,CAAC,CAAA;QACvC,CAAC;KACF,CAAC,CAAA;AACJ,CAAC","sourcesContent":["import { Extension } from '@tiptap/react'\nimport { Plugin, PluginKey } from '@tiptap/pm/state'\nimport type { EditorState, Transaction } from '@tiptap/pm/state'\nimport type { Node as PmNode } from '@tiptap/pm/model'\nimport { isComponentNodeValue, withFreshNodeIds } from '@elytracms/core/cms-core'\nimport type { PropFieldLookup } from '@elytracms/core/cms-core'\nimport type { IdFactory } from '@elytracms/core/determinism'\nimport { COMPONENT_EMBED_NODE_TYPE } from './component-embed'\n\n/**\n * **Identity in the flow editor** (EC-776, owner ruling 2026-11-04: a component node id is\n * unique within the whole document). The embed atom is draggable, and a drop with Alt (macOS) /\n * Ctrl COPIES the slice instead of moving it — the copy carried the original's `attrs.node`, id\n * and all. Identity is minted where content is copied, so this plugin re-mints, after every\n * user transaction that changed the document, each embed occurrence the transaction ADDED whose id\n * the document already holds: the whole embedded subtree, through `withFreshNodeIds` (the one copy).\n *\n * \"Added\" follows the transaction's own mapping, not document order: an occurrence that maps from\n * an occurrence of the previous document keeps its id — a move (deleted at one place, inserted at\n * another, one transaction) leaves one occurrence, nothing to re-mint; a copy dropped BEFORE its\n * original is the one re-minted. Stored twins (drift the validator names as `duplicate-node-id`)\n * both map from the previous document and are left as stored; so is an external re-push of the\n * stored value (`setContent` with `emitUpdate: false` sets TipTap's `preventUpdate` meta) — the\n * editor never rewrites storage on load.\n *\n * Pure ProseMirror (`appendTransaction`), pinned in node through prosemirror-state.\n */\n\nexport const EMBED_IDENTITY_EXTENSION = 'elytraEmbedIdentity'\n\nexport interface EmbedIdentityOptions {\n /** THE id factory (EC-578): UUIDs in the studio, a sequential factory in fixtures. */\n readonly newId: IdFactory\n /** The project's prop declarations — the copy re-mints the nodes the embed's props hold. */\n readonly lookupManifest: PropFieldLookup\n}\n\nconst KEY = new PluginKey(EMBED_IDENTITY_EXTENSION)\n\ninterface Occurrence {\n readonly pos: number\n readonly id: string\n}\n\nfunction embedIdOf(node: PmNode): string | undefined {\n if (node.type.name !== COMPONENT_EMBED_NODE_TYPE) return undefined\n const embedded: unknown = node.attrs.node\n return isComponentNodeValue(embedded) ? embedded.id : undefined\n}\n\n/** Every embed with a readable node, in document order. */\nfunction occurrencesIn(doc: PmNode): Occurrence[] {\n const out: Occurrence[] = []\n doc.descendants((node, pos) => {\n if (node.type.name !== COMPONENT_EMBED_NODE_TYPE) return true\n const id = embedIdOf(node)\n if (id !== undefined) out.push({ pos, id })\n return false // an atom: nothing inside\n })\n return out\n}\n\n/** Where `pos` of the previous document sits after `transactions` — `undefined` once deleted. */\nfunction mapForward(pos: number, transactions: readonly Transaction[]): number | undefined {\n let at = pos\n for (const tr of transactions) {\n const result = tr.mapping.mapResult(at, 1)\n if (result.deleted) return undefined\n at = result.pos\n }\n return at\n}\n\n/** The re-mint transaction for `transactions`, or `null` when no added embed repeats an id. */\nexport function remintCopiedEmbeds(\n transactions: readonly Transaction[],\n oldState: EditorState,\n newState: EditorState,\n options: EmbedIdentityOptions,\n): Transaction | null {\n if (!transactions.some((tr) => tr.docChanged)) return null\n // An external re-push of the stored value: storage is the validator's to judge, never rewritten here.\n if (transactions.some((tr) => tr.getMeta('preventUpdate') === true)) return null\n const after = occurrencesIn(newState.doc)\n const counts = new Map<string, number>()\n for (const { id } of after) counts.set(id, (counts.get(id) ?? 0) + 1)\n if (![...counts.values()].some((count) => count > 1)) return null\n\n const carried = new Set<number>()\n for (const { pos } of occurrencesIn(oldState.doc)) {\n const mapped = mapForward(pos, transactions)\n if (mapped !== undefined) carried.add(mapped)\n }\n // Per repeated id: the occurrences that map from the previous document keep it; with none, the\n // first in document order does. Every other occurrence is a copy.\n const keeps = new Set<number>()\n for (const [id, count] of counts) {\n if (count < 2) continue\n const of = after.filter((occurrence) => occurrence.id === id)\n const kept = of.filter((occurrence) => carried.has(occurrence.pos))\n for (const occurrence of kept.length > 0 ? kept : of.slice(0, 1)) keeps.add(occurrence.pos)\n }\n let tr: Transaction | null = null\n for (const { pos, id } of after) {\n if ((counts.get(id) ?? 0) < 2 || keeps.has(pos)) continue\n const node = newState.doc.nodeAt(pos)!\n const fresh = withFreshNodeIds(node.attrs.node as Parameters<typeof withFreshNodeIds>[0], options.newId, {\n lookupManifest: options.lookupManifest,\n })\n // An atom of the same size: re-marking it moves no other position.\n tr = (tr ?? newState.tr).setNodeMarkup(pos, undefined, { ...node.attrs, node: fresh })\n }\n return tr\n}\n\n/** The ProseMirror plugin ({@link remintCopiedEmbeds} after every transaction). */\nexport function embedIdentityPlugin(options: EmbedIdentityOptions): Plugin {\n return new Plugin({\n key: KEY,\n appendTransaction: (transactions, oldState, newState) => remintCopiedEmbeds(transactions, oldState, newState, options),\n })\n}\n\n/** The TipTap extension the editor's set carries ({@link buildRichTextExtensions}). */\nexport function createEmbedIdentity(options: EmbedIdentityOptions) {\n return Extension.create({\n name: EMBED_IDENTITY_EXTENSION,\n addProseMirrorPlugins() {\n return [embedIdentityPlugin(options)]\n },\n })\n}\n"]}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type { Extensions } from '@tiptap/react';
|
|
2
2
|
import type { SlashCommandOptions } from './slash-command.js';
|
|
3
|
+
import type { EmbedIdentityOptions } from './embed-identity.js';
|
|
3
4
|
/**
|
|
4
5
|
* The TipTap extension set for the CMS rich-text editor (EC-314).
|
|
5
6
|
*
|
|
@@ -29,7 +30,12 @@ import type { SlashCommandOptions } from './slash-command.js';
|
|
|
29
30
|
*
|
|
30
31
|
* `slash` wires the Notion-style `/` menu to the editor's shared image/embed pickers
|
|
31
32
|
* (omit an action to hide that slash item).
|
|
33
|
+
*
|
|
34
|
+
* `identity` (EC-776, required) — the embed identity plugin's id factory and prop
|
|
35
|
+
* declarations: an embed COPIED inside the editor (an Alt/Ctrl drag) gets fresh ids for its
|
|
36
|
+
* whole subtree, so one value never holds one component id twice (`./embed-identity`).
|
|
32
37
|
*/
|
|
33
|
-
export declare function buildRichTextExtensions(options
|
|
38
|
+
export declare function buildRichTextExtensions(options: {
|
|
34
39
|
slash?: SlashCommandOptions;
|
|
40
|
+
identity: EmbedIdentityOptions;
|
|
35
41
|
}): Extensions;
|
|
@@ -7,6 +7,7 @@ import { AssetImage } from './asset-image.js';
|
|
|
7
7
|
import { ComponentEmbed } from './component-embed.js';
|
|
8
8
|
import { UnknownNodeCarrier } from './unknown-node.js';
|
|
9
9
|
import { createSlashCommand } from './slash-command.js';
|
|
10
|
+
import { createEmbedIdentity } from './embed-identity.js';
|
|
10
11
|
/**
|
|
11
12
|
* The TipTap extension set for the CMS rich-text editor (EC-314).
|
|
12
13
|
*
|
|
@@ -36,8 +37,12 @@ import { createSlashCommand } from './slash-command.js';
|
|
|
36
37
|
*
|
|
37
38
|
* `slash` wires the Notion-style `/` menu to the editor's shared image/embed pickers
|
|
38
39
|
* (omit an action to hide that slash item).
|
|
40
|
+
*
|
|
41
|
+
* `identity` (EC-776, required) — the embed identity plugin's id factory and prop
|
|
42
|
+
* declarations: an embed COPIED inside the editor (an Alt/Ctrl drag) gets fresh ids for its
|
|
43
|
+
* whole subtree, so one value never holds one component id twice (`./embed-identity`).
|
|
39
44
|
*/
|
|
40
|
-
export function buildRichTextExtensions(options
|
|
45
|
+
export function buildRichTextExtensions(options) {
|
|
41
46
|
return [
|
|
42
47
|
StarterKit.configure({
|
|
43
48
|
link: false,
|
|
@@ -50,6 +55,7 @@ export function buildRichTextExtensions(options = {}) {
|
|
|
50
55
|
UnknownNodeCarrier,
|
|
51
56
|
Placeholder.configure({ placeholder: translate('richText.placeholder') }),
|
|
52
57
|
createSlashCommand(options.slash ?? {}),
|
|
58
|
+
createEmbedIdentity(options.identity),
|
|
53
59
|
];
|
|
54
60
|
}
|
|
55
61
|
//# sourceMappingURL=extensions.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"extensions.js","sourceRoot":"","sources":["../../../../src/components/cms/rich-text/extensions.ts"],"names":[],"mappings":"AAAA,OAAO,UAAU,MAAM,qBAAqB,CAAA;AAC5C,OAAO,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAA;AAEhD,OAAO,EAAE,SAAS,EAAE,MAAM,mBAAmB,CAAA;AAC7C,OAAO,EAAE,OAAO,EAAE,MAAM,YAAY,CAAA;AACpC,OAAO,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAA;AACtC,OAAO,EAAE,UAAU,EAAE,MAAM,eAAe,CAAA;AAC1C,OAAO,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAA;AAClD,OAAO,EAAE,kBAAkB,EAAE,MAAM,gBAAgB,CAAA;AACnD,OAAO,EAAE,kBAAkB,EAAE,MAAM,iBAAiB,CAAA;
|
|
1
|
+
{"version":3,"file":"extensions.js","sourceRoot":"","sources":["../../../../src/components/cms/rich-text/extensions.ts"],"names":[],"mappings":"AAAA,OAAO,UAAU,MAAM,qBAAqB,CAAA;AAC5C,OAAO,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAA;AAEhD,OAAO,EAAE,SAAS,EAAE,MAAM,mBAAmB,CAAA;AAC7C,OAAO,EAAE,OAAO,EAAE,MAAM,YAAY,CAAA;AACpC,OAAO,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAA;AACtC,OAAO,EAAE,UAAU,EAAE,MAAM,eAAe,CAAA;AAC1C,OAAO,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAA;AAClD,OAAO,EAAE,kBAAkB,EAAE,MAAM,gBAAgB,CAAA;AACnD,OAAO,EAAE,kBAAkB,EAAE,MAAM,iBAAiB,CAAA;AAEpD,OAAO,EAAE,mBAAmB,EAAE,MAAM,kBAAkB,CAAA;AAGtD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAiCG;AACH,MAAM,UAAU,uBAAuB,CAAC,OAGvC;IACC,OAAO;QACL,UAAU,CAAC,SAAS,CAAC;YACnB,IAAI,EAAE,KAAK;YACX,OAAO,EAAE,EAAE,MAAM,EAAE,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,EAAE;SACxC,CAAC;QACF,OAAO,CAAC,SAAS,CAAC,EAAE,WAAW,EAAE,KAAK,EAAE,QAAQ,EAAE,IAAI,EAAE,WAAW,EAAE,IAAI,EAAE,CAAC;QAC5E,QAAQ;QACR,UAAU;QACV,cAAc;QACd,kBAAkB;QAClB,WAAW,CAAC,SAAS,CAAC,EAAE,WAAW,EAAE,SAAS,CAAC,sBAAsB,CAAC,EAAE,CAAC;QACzE,kBAAkB,CAAC,OAAO,CAAC,KAAK,IAAI,EAAE,CAAC;QACvC,mBAAmB,CAAC,OAAO,CAAC,QAAQ,CAAC;KACtC,CAAA;AACH,CAAC","sourcesContent":["import StarterKit from '@tiptap/starter-kit'\nimport { Placeholder } from '@tiptap/extensions'\nimport type { Extensions } from '@tiptap/react'\nimport { translate } from '../../../lib/i18n'\nimport { RefLink } from './ref-link'\nimport { FontSize } from './font-size'\nimport { AssetImage } from './asset-image'\nimport { ComponentEmbed } from './component-embed'\nimport { UnknownNodeCarrier } from './unknown-node'\nimport { createSlashCommand } from './slash-command'\nimport type { SlashCommandOptions } from './slash-command'\nimport { createEmbedIdentity } from './embed-identity'\nimport type { EmbedIdentityOptions } from './embed-identity'\n\n/**\n * The TipTap extension set for the CMS rich-text editor (EC-314).\n *\n * Deliberately matches the storage vocabulary (`@elytracms/core/rich-text` schema)\n * one-for-one so every editor document round-trips through `parseRichTextValue` /\n * the delivery renderer with no format change:\n *\n * - **StarterKit** supplies `doc/paragraph/text/heading/bulletList/orderedList/\n * listItem/blockquote/codeBlock/hardBreak/horizontalRule` and the marks\n * `bold/italic/code/strike/underline` — all ProseMirror-standard names identical\n * to storage. Its bundled `link` is disabled and replaced by {@link RefLink} so\n * internal-document links can carry a structured `ref` (EC-290). Headings allow\n * all six levels so existing `h4`–`h6` content is preserved even though the\n * toolbar surfaces only 1–3.\n * - {@link AssetImage} / {@link ComponentEmbed} declare the two reference-carrying\n * atoms (asset image, embedded registry component) so existing content of those\n * kinds survives a round-trip verbatim rather than being dropped by the schema.\n * - {@link UnknownNodeCarrier} (EC-547) is the editor-only opaque atom the\n * storage⇄editor projection wraps any OTHER stored node type into, so the\n * closed ProseMirror schema can never drop a node the flow editor does not\n * natively edit — the EC-500 D3 round-trip law.\n * - {@link FontSize} declares the semantic font-size mark (EC-411) so a sized run\n * round-trips (an undeclared mark would be silently dropped on load).\n *\n * No `allow` gating lives here — that governs *insertion* (the embed picker) and\n * *validation* (`validateRichTextEmbeds`), not which nodes the schema tolerates.\n *\n * `slash` wires the Notion-style `/` menu to the editor's shared image/embed pickers\n * (omit an action to hide that slash item).\n *\n * `identity` (EC-776, required) — the embed identity plugin's id factory and prop\n * declarations: an embed COPIED inside the editor (an Alt/Ctrl drag) gets fresh ids for its\n * whole subtree, so one value never holds one component id twice (`./embed-identity`).\n */\nexport function buildRichTextExtensions(options: {\n slash?: SlashCommandOptions\n identity: EmbedIdentityOptions\n}): Extensions {\n return [\n StarterKit.configure({\n link: false,\n heading: { levels: [1, 2, 3, 4, 5, 6] },\n }),\n RefLink.configure({ openOnClick: false, autolink: true, linkOnPaste: true }),\n FontSize,\n AssetImage,\n ComponentEmbed,\n UnknownNodeCarrier,\n Placeholder.configure({ placeholder: translate('richText.placeholder') }),\n createSlashCommand(options.slash ?? {}),\n createEmbedIdentity(options.identity),\n ]\n}\n"]}
|
|
@@ -2,6 +2,7 @@ import type { Editor } from '@tiptap/react';
|
|
|
2
2
|
import { assetNode } from '@elytracms/core/cms-core';
|
|
3
3
|
import type { ComponentNode } from '@elytracms/core/project-graph';
|
|
4
4
|
import type { ComponentManifest } from '@elytracms/core/component-registry';
|
|
5
|
+
import type { IdFactory } from '@elytracms/core/determinism';
|
|
5
6
|
import type { AssetsStore } from '../../assets/assets-store.js';
|
|
6
7
|
/**
|
|
7
8
|
* Reference-carrying node insertions shared by the toolbar controls and the slash
|
|
@@ -29,18 +30,22 @@ export declare function assetImageAttrs(assetId: string, assets: AssetsStore | n
|
|
|
29
30
|
export declare function insertAssetImage(editor: Editor, assetId: string, assets: AssetsStore | null): void;
|
|
30
31
|
/**
|
|
31
32
|
* Insert a `componentEmbed` wrapping a fresh ComponentNode built from manifest
|
|
32
|
-
* defaults
|
|
33
|
-
*
|
|
33
|
+
* defaults, its id minted by the editor's injected factory (`newId`, EC-578 / EC-776).
|
|
34
|
+
* With `select: true` the inserted node is then selected — so a host embed inspector
|
|
35
|
+
* (0.0.41) opens straight onto its props for editing.
|
|
34
36
|
*/
|
|
35
|
-
export declare function insertComponentEmbed(editor: Editor, manifest: ComponentManifest, options
|
|
37
|
+
export declare function insertComponentEmbed(editor: Editor, manifest: ComponentManifest, options: {
|
|
38
|
+
newId: IdFactory;
|
|
36
39
|
select?: boolean;
|
|
37
40
|
}): void;
|
|
38
41
|
/**
|
|
39
42
|
* A fresh embedded ComponentNode (mirrors builder node-factory). EC-591 / ratified
|
|
40
43
|
* 2f: NO props — an absent prop is `undefined`, so the implementation's own default
|
|
41
|
-
* applies; the manifest `default` is a hint, never baked into the stored node.
|
|
44
|
+
* applies; the manifest `default` is a hint, never baked into the stored node. Its id
|
|
45
|
+
* comes from the injected factory (EC-578 / EC-776 — it used `crypto.randomUUID` with a
|
|
46
|
+
* `Math.random` fallback, outside the factory).
|
|
42
47
|
*/
|
|
43
|
-
export declare function embedNodeFromManifest(manifest: ComponentManifest): ComponentNode;
|
|
48
|
+
export declare function embedNodeFromManifest(manifest: ComponentManifest, newId: IdFactory): ComponentNode;
|
|
44
49
|
/**
|
|
45
50
|
* The components embeddable in a rich-text field or prop (EC-584, ratified 4b): its
|
|
46
51
|
* declared `allow` (a closed set — EC-544: an empty one offers nothing), else the
|
|
@@ -35,17 +35,18 @@ export function insertAssetImage(editor, assetId, assets) {
|
|
|
35
35
|
}
|
|
36
36
|
/**
|
|
37
37
|
* Insert a `componentEmbed` wrapping a fresh ComponentNode built from manifest
|
|
38
|
-
* defaults
|
|
39
|
-
*
|
|
38
|
+
* defaults, its id minted by the editor's injected factory (`newId`, EC-578 / EC-776).
|
|
39
|
+
* With `select: true` the inserted node is then selected — so a host embed inspector
|
|
40
|
+
* (0.0.41) opens straight onto its props for editing.
|
|
40
41
|
*/
|
|
41
42
|
export function insertComponentEmbed(editor, manifest, options) {
|
|
42
|
-
const embed = embedNodeFromManifest(manifest);
|
|
43
|
+
const embed = embedNodeFromManifest(manifest, options.newId);
|
|
43
44
|
editor
|
|
44
45
|
.chain()
|
|
45
46
|
.focus()
|
|
46
47
|
.insertContent({ type: COMPONENT_EMBED_NODE_TYPE, attrs: { node: embed } })
|
|
47
48
|
.run();
|
|
48
|
-
if (options
|
|
49
|
+
if (options.select)
|
|
49
50
|
selectComponentEmbed(editor, embed.id);
|
|
50
51
|
}
|
|
51
52
|
/**
|
|
@@ -73,10 +74,12 @@ function selectComponentEmbed(editor, id) {
|
|
|
73
74
|
/**
|
|
74
75
|
* A fresh embedded ComponentNode (mirrors builder node-factory). EC-591 / ratified
|
|
75
76
|
* 2f: NO props — an absent prop is `undefined`, so the implementation's own default
|
|
76
|
-
* applies; the manifest `default` is a hint, never baked into the stored node.
|
|
77
|
+
* applies; the manifest `default` is a hint, never baked into the stored node. Its id
|
|
78
|
+
* comes from the injected factory (EC-578 / EC-776 — it used `crypto.randomUUID` with a
|
|
79
|
+
* `Math.random` fallback, outside the factory).
|
|
77
80
|
*/
|
|
78
|
-
export function embedNodeFromManifest(manifest) {
|
|
79
|
-
return { id:
|
|
81
|
+
export function embedNodeFromManifest(manifest, newId) {
|
|
82
|
+
return { id: newId(), componentId: manifest.id, props: {} };
|
|
80
83
|
}
|
|
81
84
|
/**
|
|
82
85
|
* The components embeddable in a rich-text field or prop (EC-584, ratified 4b): its
|
|
@@ -93,9 +96,4 @@ export function listEmbeddable(allow, registered) {
|
|
|
93
96
|
const vocabulary = resolveAllow(allow, FIELD_TYPES.richText.defaultAllow);
|
|
94
97
|
return registered.filter((manifest) => placementRefusal({ componentId: manifest.id, view: toManifestView(manifest), allow: vocabulary }) === null);
|
|
95
98
|
}
|
|
96
|
-
/** A unique id for an embedded node (studio runs in the browser; crypto is present). */
|
|
97
|
-
function newEmbedId() {
|
|
98
|
-
const uuid = globalThis.crypto?.randomUUID?.();
|
|
99
|
-
return uuid ? `embed-${uuid}` : `embed-${Math.random().toString(36).slice(2)}`;
|
|
100
|
-
}
|
|
101
99
|
//# sourceMappingURL=insert.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"insert.js","sourceRoot":"","sources":["../../../../src/components/cms/rich-text/insert.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,SAAS,EAAE,MAAM,0BAA0B,CAAA;AACpD,OAAO,EAAE,WAAW,EAAE,MAAM,0BAA0B,CAAA;AACtD,OAAO,EAAE,gBAAgB,EAAE,YAAY,EAAE,MAAM,+BAA+B,CAAA;AAE9E,OAAO,EAAE,cAAc,EAAE,MAAM,oCAAoC,CAAA;
|
|
1
|
+
{"version":3,"file":"insert.js","sourceRoot":"","sources":["../../../../src/components/cms/rich-text/insert.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,SAAS,EAAE,MAAM,0BAA0B,CAAA;AACpD,OAAO,EAAE,WAAW,EAAE,MAAM,0BAA0B,CAAA;AACtD,OAAO,EAAE,gBAAgB,EAAE,YAAY,EAAE,MAAM,+BAA+B,CAAA;AAE9E,OAAO,EAAE,cAAc,EAAE,MAAM,oCAAoC,CAAA;AAGnE,OAAO,EAAE,yBAAyB,EAAE,MAAM,mBAAmB,CAAA;AAG7D;;;;GAIG;AAEH;;;;;GAKG;AACH,MAAM,CAAC,MAAM,mBAAmB,GAAsB,CAAC,OAAO,CAAC,CAAA;AAE/D;;;;;GAKG;AACH,MAAM,UAAU,eAAe,CAAC,OAAe,EAAE,MAA0B;IACzE,MAAM,MAAM,GAAG,MAAM,EAAE,MAAM,CAAC,IAAI,CAAC,CAAC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QAAQ,GAAG,IAAI,CAAC,KAAK,CAAC,IAA8B,CAAA;YAC1D,IAAI,QAAQ,EAAE,EAAE,KAAK,EAAE,EAAE,CAAC;gBACxB,GAAG,GAAG,EAAE,CAAA;gBACR,OAAO,KAAK,CAAA;YACd,CAAC;QACH,CAAC;QACD,OAAO,IAAI,CAAA;IACb,CAAC,CAAC,CAAA;IACF,IAAI,GAAG,IAAI,CAAC;QAAE,MAAM,CAAC,QAAQ,CAAC,gBAAgB,CAAC,GAAG,CAAC,CAAA;AACrD,CAAC;AAED;;;;;;GAMG;AACH,MAAM,UAAU,qBAAqB,CAAC,QAA2B,EAAE,KAAgB;IACjF,OAAO,EAAE,EAAE,EAAE,KAAK,EAAE,EAAE,WAAW,EAAE,QAAQ,CAAC,EAAE,EAAE,KAAK,EAAE,EAAE,EAAE,CAAA;AAC7D,CAAC;AAED;;;;;;;;;;GAUG;AACH,MAAM,UAAU,cAAc,CAC5B,KAA2B,EAC3B,UAA+B;IAE/B,MAAM,UAAU,GAAG,YAAY,CAAC,KAAK,EAAE,WAAW,CAAC,QAAQ,CAAC,YAAa,CAAC,CAAA;IAC1E,OAAO,UAAU,CAAC,MAAM,CACtB,CAAC,QAAQ,EAAE,EAAE,CAAC,gBAAgB,CAAC,EAAE,WAAW,EAAE,QAAQ,CAAC,EAAE,EAAE,IAAI,EAAE,cAAc,CAAC,QAAQ,CAAC,EAAE,KAAK,EAAE,UAAU,EAAE,CAAC,KAAK,IAAI,CACzH,CAAA;AACH,CAAC","sourcesContent":["import type { Editor } from '@tiptap/react'\nimport { assetNode } from '@elytracms/core/cms-core'\nimport { FIELD_TYPES } from '@elytracms/core/cms-core'\nimport { placementRefusal, resolveAllow } from '@elytracms/core/project-graph'\nimport type { ComponentNode } from '@elytracms/core/project-graph'\nimport { toManifestView } from '@elytracms/core/component-registry'\nimport type { ComponentManifest } from '@elytracms/core/component-registry'\nimport type { IdFactory } from '@elytracms/core/determinism'\nimport { COMPONENT_EMBED_NODE_TYPE } from './component-embed'\nimport type { AssetsStore } from '../../assets/assets-store'\n\n/**\n * Reference-carrying node insertions shared by the toolbar controls and the slash\n * menu (EC-314). Centralised so both entry points produce byte-identical envelopes\n * (the shapes `reference-extraction` indexes).\n */\n\n/**\n * What the rich-text image insert accepts (EC-588): images, in the structured `accept`\n * vocabulary every picker takes — stated once here rather than as a file-input literal\n * at the call site. The picker derives its grid filter, its Upload dialog and its drop\n * rule from it, like a field's own `accept`.\n */\nexport const INLINE_IMAGE_ACCEPT: readonly string[] = ['image']\n\n/**\n * The `image` node attrs for a project asset: the canonical `attrs.ref` plus an\n * editor-display `src` snapshot. NO `alt` (EC-587, ASSETS D19): an asset-pinned image's\n * alt is the asset's, read at render through the one reader — a snapshot here went\n * stale on the first alt edit (and read the legacy column only). Pure, for the test.\n */\nexport function assetImageAttrs(assetId: string, assets: AssetsStore | null): { src: string; ref: ReturnType<typeof assetNode> } {\n const record = assets?.assets.find((a) => a.id === assetId)\n return { src: record?.url ?? '', ref: assetNode(assetId) }\n}\n\n/** Insert an `image` node for a project asset (canonical `attrs.ref`, snapshot `src`). */\nexport function insertAssetImage(editor: Editor, assetId: string, assets: AssetsStore | null): void {\n editor\n .chain()\n .focus()\n .insertContent({ type: 'image', attrs: assetImageAttrs(assetId, assets) })\n .run()\n}\n\n/**\n * Insert a `componentEmbed` wrapping a fresh ComponentNode built from manifest\n * defaults, its id minted by the editor's injected factory (`newId`, EC-578 / EC-776).\n * With `select: true` the inserted node is then selected — so a host embed inspector\n * (0.0.41) opens straight onto its props for editing.\n */\nexport function insertComponentEmbed(\n editor: Editor,\n manifest: ComponentManifest,\n options: { newId: IdFactory; select?: boolean },\n): void {\n const embed = embedNodeFromManifest(manifest, options.newId)\n editor\n .chain()\n .focus()\n .insertContent({ type: COMPONENT_EMBED_NODE_TYPE, attrs: { node: embed } })\n .run()\n if (options.select) selectComponentEmbed(editor, embed.id)\n}\n\n/**\n * Select the just-inserted embed by its unique embedded-node id. Located by scan\n * (rather than fragile position arithmetic after `insertContent`, which may split a\n * paragraph or append a trailing block); the id is unique so the first match is it.\n */\nfunction selectComponentEmbed(editor: Editor, id: string): void {\n let pos = -1\n editor.state.doc.descendants((node, at) => {\n if (pos >= 0) return false\n if (node.type.name === COMPONENT_EMBED_NODE_TYPE) {\n const embedded = node.attrs.node as { id?: string } | null\n if (embedded?.id === id) {\n pos = at\n return false\n }\n }\n return true\n })\n if (pos >= 0) editor.commands.setNodeSelection(pos)\n}\n\n/**\n * A fresh embedded ComponentNode (mirrors builder node-factory). EC-591 / ratified\n * 2f: NO props — an absent prop is `undefined`, so the implementation's own default\n * applies; the manifest `default` is a hint, never baked into the stored node. Its id\n * comes from the injected factory (EC-578 / EC-776 — it used `crypto.randomUUID` with a\n * `Math.random` fallback, outside the factory).\n */\nexport function embedNodeFromManifest(manifest: ComponentManifest, newId: IdFactory): ComponentNode {\n return { id: newId(), componentId: manifest.id, props: {} }\n}\n\n/**\n * The components embeddable in a rich-text field or prop (EC-584, ratified 4b): its\n * declared `allow` (a closed set — EC-544: an empty one offers nothing), else the\n * `richText` TYPE's default, declared once in the per-FieldType definition\n * (`FIELD_TYPES.richText.defaultAllow`): any canvas-eligible component that fills no\n * LAYOUT role — a Stack or Grid mid-paragraph is a layout surface's job. Judged by the\n * ONE core placement judge (role exclusion + `isCanvasEligible`, carried on the\n * manifest view), the same verdict the composition validator reaches — so the embed\n * picker, the toolbar, the slash menu and the inspector's rich-text editor offer\n * exactly what publishes.\n */\nexport function listEmbeddable(\n allow: string[] | undefined,\n registered: ComponentManifest[],\n): ComponentManifest[] {\n const vocabulary = resolveAllow(allow, FIELD_TYPES.richText.defaultAllow!)\n return registered.filter(\n (manifest) => placementRefusal({ componentId: manifest.id, view: toManifestView(manifest), allow: vocabulary }) === null,\n )\n}\n"]}
|
|
@@ -28,8 +28,6 @@ export interface PreviewState {
|
|
|
28
28
|
}
|
|
29
29
|
/** Preview state for a manifest: the fixture selection + the live prop overrides. */
|
|
30
30
|
export declare function usePreviewState(manifest: ComponentManifest): PreviewState;
|
|
31
|
-
/** Re-id a preview node into the canvas `node-<n>` namespace for embedding (transfer). */
|
|
32
|
-
export declare function embedNodeFrom(node: ComponentNode, id: string): ComponentNode;
|
|
33
31
|
/**
|
|
34
32
|
* The live preview surface: the fixture-state selector (when a component declares
|
|
35
33
|
* more than one) plus the rendered node. Server-only components (EC-191
|
|
@@ -53,10 +53,6 @@ export function usePreviewState(manifest) {
|
|
|
53
53
|
node,
|
|
54
54
|
};
|
|
55
55
|
}
|
|
56
|
-
/** Re-id a preview node into the canvas `node-<n>` namespace for embedding (transfer). */
|
|
57
|
-
export function embedNodeFrom(node, id) {
|
|
58
|
-
return { ...node, id };
|
|
59
|
-
}
|
|
60
56
|
/**
|
|
61
57
|
* The live preview surface: the fixture-state selector (when a component declares
|
|
62
58
|
* more than one) plus the rendered node. Server-only components (EC-191
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"component-preview.js","sourceRoot":"","sources":["../../../src/components/components/component-preview.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAE,SAAS,EAAE,WAAW,EAAE,SAAS,EAAE,OAAO,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAA;AAEpF,OAAO,EAAE,YAAY,EAAE,MAAM,WAAW,CAAA;AACxC,OAAO,EAAE,UAAU,EAAE,SAAS,EAAE,MAAM,cAAc,CAAA;AACpD,OAAO,EAAE,UAAU,EAAE,MAAM,kCAAkC,CAAA;AAE7D,OAAO,EAAE,UAAU,EAAE,MAAM,+BAA+B,CAAA;AAG1D,OAAO,EAAE,aAAa,EAAE,MAAM,oCAAoC,CAAA;AAClE,OAAO,EAAE,eAAe,EAAE,iBAAiB,EAAE,cAAc,EAAE,MAAM,oBAAoB,CAAA;AAEvF,OAAO,EAAE,YAAY,EAAE,MAAM,4BAA4B,CAAA;AAEzD,OAAO,EAAE,KAAK,EAAE,MAAM,EAAE,IAAI,EAAE,KAAK,EAAE,GAAG,EAAE,MAAM,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CAAC,EAAE,EAAE,EAAE,CAAC,CACtB,KAAC,IAAI,IAAU,IAAI,EAAC,OAAO,YACxB,EAAE,IADM,EAAE,CAEN,CACR,CAAC,IACE,CACP,CAAC,CAAC,CAAC,IAAI,KApBA,IAAI,CAAC,IAAI,CAqBb,CACP,CAAC,GACE,IACA,CACT,CAAA;AACH,CAAC","sourcesContent":["import { Component, useCallback, useEffect, useMemo, useRef, useState } from 'react'\nimport type { ReactNode } from 'react'\nimport { createPortal } from 'react-dom'\nimport { MonitorOff, RotateCcw } from 'lucide-react'\nimport { renderNode } from '@elytracms/core/runtime-renderer'\nimport type { RenderContext } from '@elytracms/core/runtime-renderer'\nimport { staticProp } from '@elytracms/core/project-graph'\nimport type { ComponentNode, JsonValue } from '@elytracms/core/project-graph'\nimport type { ComponentManifest, PropField } from '@elytracms/core/component-registry'\nimport { manifestSlots } from '@elytracms/core/component-registry'\nimport { componentStatus, getStudioRegistry, previewContext } from '../../lib/registry'\nimport type { StudioRegistry } from '../../lib/registry'\nimport { previewSpecs } from '../../lib/registry/preview'\nimport type { PreviewSpec } from '../../lib/registry/preview'\nimport { Badge, Button, Code, Field, Row, Spacer, Stack, TabButton, Text } from '@elytracms/studio/ui'\nimport { localizedLabel, translate } from '../../lib/i18n'\nimport { cn } from '../../lib/utils'\nimport { resolveDeploymentCanvasTheme } from '../../lib/workspace'\nimport { wireCanvasChrome } from '../builder/canvas-chrome'\nimport { getCanvasStylesheetUrl } from '../builder/canvas-stylesheet'\nimport { useCanvasViewports, viewportWidth } from '../builder/canvas-breakpoints'\nimport type { ViewportOption } from '../builder/canvas-breakpoints'\nimport { PropValueControl } from '../cms/prop-fields'\n\n/**\n * EC-320 — the editable component preview. A component's declared preview states\n * (fixtures) select the SAMPLE STATE (slot content, base props); on top of that\n * the user edits individual prop values in the Props sidebar and the preview\n * re-renders live through the SAME runtime-renderer path the Builder and export\n * use (EC-054). Slots follow the selected fixture — full slot-tree editing is out\n * of scope for this reference surface (that's the composition editor's job); the\n * Slots pane documents what a component accepts and which state supplies content.\n */\n\nexport interface PreviewState {\n specs: PreviewSpec[]\n index: number\n setIndex: (i: number) => void\n /** Per-prop static-value overrides applied over the selected fixture. */\n overrides: Record<string, JsonValue>\n setOverride: (name: string, value: JsonValue) => void\n clearOverride: (name: string) => void\n resetAll: () => void\n dirty: boolean\n /** The live node: the selected fixture with prop overrides applied. */\n node: ComponentNode\n}\n\n/** Preview state for a manifest: the fixture selection + the live prop overrides. */\nexport function usePreviewState(manifest: ComponentManifest): PreviewState {\n // EC-591: a fixture-less component previews the seeded Default — role-aware, so it needs the registry.\n const specs = useMemo(() => previewSpecs(manifest, getStudioRegistry().registry), [manifest])\n const [index, setIndexRaw] = useState(0)\n const [overrides, setOverrides] = useState<Record<string, JsonValue>>({})\n\n // Switching preview state resets prop edits — they were relative to the old state.\n const setIndex = (i: number) => {\n setIndexRaw(i)\n setOverrides({})\n }\n const setOverride = (name: string, value: JsonValue) =>\n setOverrides((o) => ({ ...o, [name]: value }))\n const clearOverride = (name: string) =>\n setOverrides((o) => {\n const next = { ...o }\n delete next[name]\n return next\n })\n const resetAll = () => setOverrides({})\n\n const base = specs[Math.min(index, specs.length - 1)]?.node\n const node = useMemo<ComponentNode>(() => {\n const fixture = base ?? { id: `preview-${manifest.id}`, componentId: manifest.id, props: {} }\n const props = { ...(fixture.props ?? {}) }\n for (const [name, value] of Object.entries(overrides)) props[name] = staticProp(value)\n return { ...fixture, props }\n }, [base, overrides, manifest.id])\n\n return {\n specs,\n index: Math.min(index, Math.max(specs.length - 1, 0)),\n setIndex,\n overrides,\n setOverride,\n clearOverride,\n resetAll,\n dirty: Object.keys(overrides).length > 0,\n node,\n }\n}\n\n/** Re-id a preview node into the canvas `node-<n>` namespace for embedding (transfer). */\nexport function embedNodeFrom(node: ComponentNode, id: string): ComponentNode {\n return { ...node, id }\n}\n\n/**\n * The live preview surface: the fixture-state selector (when a component declares\n * more than one) plus the rendered node. Server-only components (EC-191\n * `clientRenderable: false`) can't run on the client-rendered canvas, so they show\n * a documented fallback rather than risk a crash; a missing implementation falls\n * back through the renderer itself (the incompatible state).\n */\nexport function ComponentPreview({\n manifest,\n studio,\n state,\n}: {\n manifest: ComponentManifest\n studio: StudioRegistry\n state: PreviewState\n}) {\n const ctx = useMemo(() => previewContext(studio), [studio])\n const serverOnly = manifest.clientRenderable === false\n const status = componentStatus(studio, manifest)\n const displayName = localizedLabel(manifest.title, manifest.id)\n\n // EC-330: the same config-sourced breakpoint set the builder canvas toolbar\n // offers (`canvas-breakpoints.ts`) — reused, not redefined, so a preview and\n // the real canvas never disagree about the site's responsive widths.\n // Defaults to the always-present 'full' (responsive) option.\n const { viewports } = useCanvasViewports()\n const [viewport, setViewport] = useState(viewports[0]!.key)\n\n return (\n <div className=\"flex h-full min-h-0 flex-col\">\n <Row gap=\"1\" wrap align=\"center\" className=\"shrink-0 border-b border-border px-3 py-2\">\n {state.specs.length > 1 ? (\n <Row\n gap=\"1\"\n wrap\n role=\"group\"\n aria-label={translate('components.fixtureRunner.statesAria')}\n >\n {state.specs.map((spec, i) => (\n <TabButton key={spec.name} active={i === state.index} onClick={() => state.setIndex(i)}>\n {spec.name}\n </TabButton>\n ))}\n </Row>\n ) : null}\n <Spacer />\n <Row\n gap=\"1\"\n wrap\n role=\"group\"\n aria-label={translate('components.preview.breakpointAria')}\n >\n {viewports.map((option) => (\n <PreviewBreakpointButton\n key={option.key}\n option={option}\n active={option.key === viewport}\n onSelect={() => setViewport(option.key)}\n />\n ))}\n </Row>\n {state.dirty ? (\n <Button variant=\"ghost\" size=\"sm\" onClick={state.resetAll} data-testid=\"preview-reset\">\n <RotateCcw /> {translate('components.preview.reset')}\n </Button>\n ) : null}\n </Row>\n\n <div\n className=\"canvas-grid min-h-0 flex-1 overflow-auto p-6\"\n data-fixture-state={state.specs[state.index]?.name}\n >\n {serverOnly ? (\n <ServerOnlyNotice />\n ) : (\n <ComponentPreviewFrame\n node={state.node}\n ctx={ctx}\n displayName={displayName}\n width={viewportWidth(viewports, viewport)}\n />\n )}\n {status === 'incompatible' && !serverOnly ? (\n <Text size=\"xs\" tone=\"muted\" className=\"mx-auto mt-3 max-w-2xl\">\n {translate('components.preview.incompatibleNote')}\n </Text>\n ) : null}\n </div>\n </div>\n )\n}\n\n/**\n * One breakpoint option in the preview's width switcher. Mirrors the builder\n * canvas toolbar's `ViewportButton` (`composition-field-editor.tsx`) — same\n * `Button`/active-state styling — but drives LOCAL preview state instead of\n * the builder store (this surface has no composition/undo stack).\n *\n * EC-328: evaluated against the shared `TabButton`/`SegmentedControl`\n * primitives and kept separate — it's built on the shared `Button` (not a\n * bare hand-rolled `<button>`, so it wasn't part of the duplication those\n * primitives address), and carries an interpolated `aria-label` plus a\n * conditional px-value `title` tooltip neither primitive's terse API models.\n */\nfunction PreviewBreakpointButton({\n option,\n active,\n onSelect,\n}: {\n option: ViewportOption\n active: boolean\n onSelect: () => void\n}) {\n return (\n <Button\n size=\"sm\"\n variant=\"ghost\"\n aria-label={translate('builder.canvas.viewportPreviewAria', { label: option.label })}\n aria-pressed={active}\n title={\n option.px !== undefined\n ? `${option.label} · ${option.px}px`\n : translate('builder.canvas.viewportWidthTitle', { label: option.label })\n }\n onClick={onSelect}\n className={cn('px-2 text-xs', active && 'bg-accent text-accent-foreground')}\n >\n {option.label}\n </Button>\n )\n}\n\nfunction ServerOnlyNotice() {\n return (\n <div className=\"mx-auto grid max-w-2xl place-items-center rounded-lg border border-dashed border-border bg-muted/30 p-8 text-center\">\n <Stack gap=\"2\" align=\"center\">\n <MonitorOff className=\"size-5 text-muted-foreground\" aria-hidden />\n <Text size=\"sm\" weight=\"medium\">\n {translate('components.preview.serverOnlyTitle')}\n </Text>\n <Text size=\"xs\" tone=\"muted\" className=\"max-w-sm\">\n {translate('components.preview.serverOnlyBody')}\n </Text>\n </Stack>\n </div>\n )\n}\n\n/** Floor for the auto-height iframe — never collapses to a sliver while empty/loading. */\nconst MIN_PREVIEW_HEIGHT = 360\n\n/**\n * The live preview render surface. Reuses the BuilderCanvas styling mechanism\n * (EC-061, `canvas.tsx`) — since EC-414 through the SAME code path, `wireCanvasChrome`\n * (closing the EC-389 follow-up): the component renders inside an ISOLATED\n * same-origin iframe that `<link>`s the project's canvas stylesheet\n * (`getCanvasStylesheetUrl()` — the consumer's theme entry; in the legacy merged\n * world also the studio CSS), so a component built with the site's Tailwind theme\n * previews with the site's styles, exactly as it does on the canvas and in\n * delivery. Using the iframe (not the studio DOM) is what keeps the delivery CSS\n * scoped and off the studio chrome.\n *\n * Unlike the builder canvas, this iframe's document is deliberately left OUT of\n * the studio's own dark/light class: this is a standalone-component reference\n * surface (not a full page), so its own negative space around the component must\n * read as a light, site-like backdrop — never the studio chrome's current theme\n * (a black frame is exactly what leaks through when the studio is dark-themed and\n * the iframe root inherits that class). The chrome's world probe supplies that\n * backdrop: the neutral backdrop rules in the new world, the studio `:root`\n * (light) tokens in the legacy one.\n *\n * Sizing: width is driven by the caller (the breakpoint selector); height is\n * measured live from the rendered content via `ResizeObserver` (EC-330) so a\n * preset switch or a prop edit — both of which change what's portaled into\n * `doc.body` — always show without clipping or dead space.\n *\n * The render is wrapped in {@link PreviewErrorBoundary} so a component that throws\n * shows the EC-191 fallback instead of taking the whole Components view down.\n */\nfunction ComponentPreviewFrame({\n node,\n ctx,\n displayName,\n width,\n}: {\n node: ComponentNode\n ctx: RenderContext\n displayName: string\n /** CSS width for the iframe — '100%' (responsive) or a fixed breakpoint px width. */\n width: string\n}) {\n const iframeRef = useRef<HTMLIFrameElement>(null)\n const [doc, setDoc] = useState<Document | null>(null)\n const [height, setHeight] = useState(MIN_PREVIEW_HEIGHT)\n\n const wireUp = useCallback(() => {\n const d = iframeRef.current?.contentDocument\n if (!d || !d.body) return\n // ONE code path with the builder canvas (EC-414 AD-B item 4): stylesheet\n // link + chrome css + consumer canvas theme + the world probe. No kit\n // tokens here — this is a registry-level reference surface, not a project\n // page. The dev theme notice is the builder canvas's job, not this pane's.\n wireCanvasChrome(d, {\n stylesheetUrl: getCanvasStylesheetUrl(),\n theme: resolveDeploymentCanvasTheme(),\n })\n setDoc(d)\n }, [])\n\n // Handle the already-loaded case (srcDoc can load before onLoad attaches).\n useEffect(() => {\n if (iframeRef.current?.contentDocument?.readyState === 'complete') wireUp()\n }, [wireUp])\n\n // Auto-height (EC-330): a same-origin iframe exposes its own document, so a\n // `ResizeObserver` on the BODY tracks its live (height: auto) content size —\n // re-firing on its own whenever the portaled render changes (preset switch,\n // prop edit), no manual re-measure wiring needed. Attached per `doc` (re-runs\n // whenever the iframe reloads), not just on mount. Loop-safety: the observed\n // element (the iframe's body) is never the element this effect resizes (the\n // IFRAME itself) — writing height never feeds back into the observed box, and\n // width is never derived from height, so there is no growth loop. Guarded for\n // environments without ResizeObserver (jsdom/tests, older embeds).\n useEffect(() => {\n const body = doc?.body\n if (!body || typeof ResizeObserver === 'undefined') return\n const measure = () => setHeight(Math.max(body.scrollHeight, MIN_PREVIEW_HEIGHT))\n measure()\n const observer = new ResizeObserver(measure)\n observer.observe(body)\n return () => observer.disconnect()\n }, [doc])\n\n return (\n <>\n <iframe\n ref={iframeRef}\n onLoad={wireUp}\n title={translate('components.detail.tab.preview')}\n style={{ width, height, maxWidth: '100%' }}\n className=\"mx-auto block rounded-lg border border-border bg-background shadow-sm\"\n srcDoc=\"<!doctype html><html><head></head><body></body></html>\"\n />\n {doc\n ? createPortal(\n <PreviewErrorBoundary displayName={displayName} resetKey={node}>\n <PreviewLiveRender node={node} ctx={ctx} />\n </PreviewErrorBoundary>,\n doc.body,\n )\n : null}\n </>\n )\n}\n\n/** Renders the node through the runtime renderer, INSIDE a component render so the\n * error boundary catches synchronous render throws (mirrors the blocks-panel\n * thumbnail's `LiveRender`). */\nfunction PreviewLiveRender({ node, ctx }: { node: ComponentNode; ctx: RenderContext }) {\n return <>{renderNode(node, ctx)}</>\n}\n\ninterface PreviewBoundaryState {\n error: Error | null\n}\n\n/**\n * EC-191 resilience for the Components view: a component whose render throws — a\n * missing provider/context (e.g. a prop control that needs a document's\n * `CollectionViewSource`), a runtime bug — shows the documented \"preview\n * unavailable\" fallback ({@link PreviewUnavailable}) instead of taking the whole\n * view down. It resets when the previewed `resetKey` (the node) changes, so\n * switching the fixture state or editing a prop retries the render.\n */\nexport class PreviewErrorBoundary extends Component<\n { children: ReactNode; displayName: string; resetKey: unknown },\n PreviewBoundaryState\n> {\n override state: PreviewBoundaryState = { error: null }\n\n static getDerivedStateFromError(error: Error): PreviewBoundaryState {\n return { error }\n }\n\n override componentDidUpdate(prev: Readonly<{ resetKey: unknown }>) {\n if (this.state.error && prev.resetKey !== this.props.resetKey) {\n this.setState({ error: null })\n }\n }\n\n override render(): ReactNode {\n if (this.state.error) {\n return <PreviewUnavailable displayName={this.props.displayName} error={this.state.error} />\n }\n return this.props.children\n }\n}\n\n/**\n * The EC-191 fallback panel — component name + \"preview unavailable\" + the error.\n * Rendered INTO the preview iframe (which carries only the project stylesheet, and\n * may carry none in tests), so it uses inline styles rather than studio UI classes\n * — the EC-414 AD-B chrome contract, with the `.ec-chrome` containment recipe on\n * its root (walked by the chrome contract test).\n */\nexport function PreviewUnavailable({ displayName, error }: { displayName: string; error: Error }) {\n return (\n <div\n data-preview-unavailable\n className=\"ec-chrome\"\n style={{\n boxSizing: 'border-box',\n maxWidth: '42rem',\n margin: '0 auto',\n border: '1px dashed rgba(120,120,120,0.5)',\n borderRadius: 8,\n padding: '24px 28px',\n background: 'rgba(127,127,127,0.06)',\n color: 'rgba(90,90,90,0.95)',\n font: '14px/1.5 system-ui, -apple-system, sans-serif',\n textAlign: 'center',\n }}\n >\n <div style={{ fontWeight: 600 }}>⚠ {translate('components.preview.unavailableTitle')}</div>\n <div style={{ marginTop: 4, fontWeight: 600, opacity: 0.9 }}>{displayName}</div>\n <div style={{ marginTop: 6, fontSize: 13, opacity: 0.85, wordBreak: 'break-word' }}>\n {error.message}\n </div>\n </div>\n )\n}\n\n/**\n * The editable Props pane (right inspector). Every non-`blocks` prop is edited\n * through the shared {@link PropValueControl} — the exact control set documents\n * use (EC-190/EC-314 phase 4) — so a change re-renders the preview immediately.\n * `blocks` props are a canvas (composition) concern, edited in a document, not here.\n */\nexport function PropsEditorPane({\n manifest,\n state,\n}: {\n manifest: ComponentManifest\n state: PreviewState\n}) {\n const editable = Object.entries(manifest.props).filter(([, spec]) => spec.type !== 'blocks')\n const fixture = state.specs[state.index]?.node\n if (editable.length === 0) {\n return (\n <Text size=\"sm\" tone=\"subtle\" className=\"p-4\">\n {translate('components.fieldInspector.noProps')}\n </Text>\n )\n }\n return (\n <Stack gap=\"4\" className=\"p-4\">\n {editable.map(([name, spec]) => {\n const id = `prop-${name}`\n const overridden = state.overrides[name] !== undefined\n return (\n <Field\n key={name}\n label={\n <Row gap=\"2\">\n <span>{localizedLabel((spec as PropField).form?.label, name)}</span>\n {overridden ? <Badge variant=\"info\">{translate('components.preview.edited')}</Badge> : null}\n </Row>\n }\n htmlFor={id}\n hint={localizedLabel((spec as PropField).form?.description) || undefined}\n >\n <PropValueControl\n id={id}\n name={name}\n spec={spec as PropField}\n value={\n overridden\n ? staticProp(state.overrides[name]!)\n : (fixture?.props?.[name] ?? undefined)\n }\n onSet={(v) => state.setOverride(name, v)}\n onClear={() => state.clearOverride(name)}\n />\n </Field>\n )\n })}\n {state.dirty ? (\n <Button variant=\"outline\" size=\"sm\" onClick={state.resetAll} className=\"self-start\">\n <RotateCcw /> {translate('components.preview.resetProps')}\n </Button>\n ) : null}\n </Stack>\n )\n}\n\n/**\n * The Slots pane (right inspector): the component's declared child regions and,\n * for a fixture that supplies slot content, a note that the preview's slot content\n * follows the selected state. Documents the pragmatic scope call — no slot-tree\n * editing on this reference surface.\n */\nexport function SlotsInfoPane({ manifest }: { manifest: ComponentManifest }) {\n // EC-591 (COMPOSITION #14): the DERIVED slots — a `blocks` prop (a Section's\n // `body`) is a child region too, exactly as the canvas, validator and renderer see it.\n const slots = manifestSlots(manifest)\n if (slots.length === 0) {\n return (\n <Text size=\"sm\" tone=\"subtle\" className=\"p-4\">\n {translate('components.fieldInspector.noSlots')}\n </Text>\n )\n }\n return (\n <Stack gap=\"3\" className=\"p-4\">\n <Text size=\"xs\" tone=\"muted\">\n {translate('components.preview.slotsNote')}\n </Text>\n <div className=\"divide-y divide-border rounded-md border border-border\">\n {slots.map((slot) => (\n <div key={slot.name} className=\"flex flex-col gap-1 p-3\">\n <Row gap=\"2\">\n <Code tone=\"primary\">{slot.name}</Code>\n {slot.required ? (\n <Badge variant=\"warning\">{translate('common.required')}</Badge>\n ) : (\n <Badge variant=\"outline\">{translate('common.optional')}</Badge>\n )}\n </Row>\n {slot.allow && slot.allow.length > 0 ? (\n <Row gap=\"2\" className=\"text-xs\" wrap>\n <Text size=\"xs\" tone=\"subtle\">\n {translate('components.fieldInspector.allows')}\n </Text>\n {slot.allow.map((id) => (\n <Code key={id} tone=\"muted\">\n {id}\n </Code>\n ))}\n </Row>\n ) : null}\n </div>\n ))}\n </div>\n </Stack>\n )\n}\n"]}
|
|
1
|
+
{"version":3,"file":"component-preview.js","sourceRoot":"","sources":["../../../src/components/components/component-preview.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAE,SAAS,EAAE,WAAW,EAAE,SAAS,EAAE,OAAO,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAA;AAEpF,OAAO,EAAE,YAAY,EAAE,MAAM,WAAW,CAAA;AACxC,OAAO,EAAE,UAAU,EAAE,SAAS,EAAE,MAAM,cAAc,CAAA;AACpD,OAAO,EAAE,UAAU,EAAE,MAAM,kCAAkC,CAAA;AAE7D,OAAO,EAAE,UAAU,EAAE,MAAM,+BAA+B,CAAA;AAG1D,OAAO,EAAE,aAAa,EAAE,MAAM,oCAAoC,CAAA;AAClE,OAAO,EAAE,eAAe,EAAE,iBAAiB,EAAE,cAAc,EAAE,MAAM,oBAAoB,CAAA;AAEvF,OAAO,EAAE,YAAY,EAAE,MAAM,4BAA4B,CAAA;AAEzD,OAAO,EAAE,KAAK,EAAE,MAAM,EAAE,IAAI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,CAEN,CACR,CAAC,IACE,CACP,CAAC,CAAC,CAAC,IAAI,KApBA,IAAI,CAAC,IAAI,CAqBb,CACP,CAAC,GACE,IACA,CACT,CAAA;AACH,CAAC","sourcesContent":["import { Component, useCallback, useEffect, useMemo, useRef, useState } from 'react'\nimport type { ReactNode } from 'react'\nimport { createPortal } from 'react-dom'\nimport { MonitorOff, RotateCcw } from 'lucide-react'\nimport { renderNode } from '@elytracms/core/runtime-renderer'\nimport type { RenderContext } from '@elytracms/core/runtime-renderer'\nimport { staticProp } from '@elytracms/core/project-graph'\nimport type { ComponentNode, JsonValue } from '@elytracms/core/project-graph'\nimport type { ComponentManifest, PropField } from '@elytracms/core/component-registry'\nimport { manifestSlots } from '@elytracms/core/component-registry'\nimport { componentStatus, getStudioRegistry, previewContext } from '../../lib/registry'\nimport type { StudioRegistry } from '../../lib/registry'\nimport { previewSpecs } from '../../lib/registry/preview'\nimport type { PreviewSpec } from '../../lib/registry/preview'\nimport { Badge, Button, Code, Field, Row, Spacer, Stack, TabButton, Text } from '@elytracms/studio/ui'\nimport { localizedLabel, translate } from '../../lib/i18n'\nimport { cn } from '../../lib/utils'\nimport { resolveDeploymentCanvasTheme } from '../../lib/workspace'\nimport { wireCanvasChrome } from '../builder/canvas-chrome'\nimport { getCanvasStylesheetUrl } from '../builder/canvas-stylesheet'\nimport { useCanvasViewports, viewportWidth } from '../builder/canvas-breakpoints'\nimport type { ViewportOption } from '../builder/canvas-breakpoints'\nimport { PropValueControl } from '../cms/prop-fields'\n\n/**\n * EC-320 — the editable component preview. A component's declared preview states\n * (fixtures) select the SAMPLE STATE (slot content, base props); on top of that\n * the user edits individual prop values in the Props sidebar and the preview\n * re-renders live through the SAME runtime-renderer path the Builder and export\n * use (EC-054). Slots follow the selected fixture — full slot-tree editing is out\n * of scope for this reference surface (that's the composition editor's job); the\n * Slots pane documents what a component accepts and which state supplies content.\n */\n\nexport interface PreviewState {\n specs: PreviewSpec[]\n index: number\n setIndex: (i: number) => void\n /** Per-prop static-value overrides applied over the selected fixture. */\n overrides: Record<string, JsonValue>\n setOverride: (name: string, value: JsonValue) => void\n clearOverride: (name: string) => void\n resetAll: () => void\n dirty: boolean\n /** The live node: the selected fixture with prop overrides applied. */\n node: ComponentNode\n}\n\n/** Preview state for a manifest: the fixture selection + the live prop overrides. */\nexport function usePreviewState(manifest: ComponentManifest): PreviewState {\n // EC-591: a fixture-less component previews the seeded Default — role-aware, so it needs the registry.\n const specs = useMemo(() => previewSpecs(manifest, getStudioRegistry().registry), [manifest])\n const [index, setIndexRaw] = useState(0)\n const [overrides, setOverrides] = useState<Record<string, JsonValue>>({})\n\n // Switching preview state resets prop edits — they were relative to the old state.\n const setIndex = (i: number) => {\n setIndexRaw(i)\n setOverrides({})\n }\n const setOverride = (name: string, value: JsonValue) =>\n setOverrides((o) => ({ ...o, [name]: value }))\n const clearOverride = (name: string) =>\n setOverrides((o) => {\n const next = { ...o }\n delete next[name]\n return next\n })\n const resetAll = () => setOverrides({})\n\n const base = specs[Math.min(index, specs.length - 1)]?.node\n const node = useMemo<ComponentNode>(() => {\n const fixture = base ?? { id: `preview-${manifest.id}`, componentId: manifest.id, props: {} }\n const props = { ...(fixture.props ?? {}) }\n for (const [name, value] of Object.entries(overrides)) props[name] = staticProp(value)\n return { ...fixture, props }\n }, [base, overrides, manifest.id])\n\n return {\n specs,\n index: Math.min(index, Math.max(specs.length - 1, 0)),\n setIndex,\n overrides,\n setOverride,\n clearOverride,\n resetAll,\n dirty: Object.keys(overrides).length > 0,\n node,\n }\n}\n\n/**\n * The live preview surface: the fixture-state selector (when a component declares\n * more than one) plus the rendered node. Server-only components (EC-191\n * `clientRenderable: false`) can't run on the client-rendered canvas, so they show\n * a documented fallback rather than risk a crash; a missing implementation falls\n * back through the renderer itself (the incompatible state).\n */\nexport function ComponentPreview({\n manifest,\n studio,\n state,\n}: {\n manifest: ComponentManifest\n studio: StudioRegistry\n state: PreviewState\n}) {\n const ctx = useMemo(() => previewContext(studio), [studio])\n const serverOnly = manifest.clientRenderable === false\n const status = componentStatus(studio, manifest)\n const displayName = localizedLabel(manifest.title, manifest.id)\n\n // EC-330: the same config-sourced breakpoint set the builder canvas toolbar\n // offers (`canvas-breakpoints.ts`) — reused, not redefined, so a preview and\n // the real canvas never disagree about the site's responsive widths.\n // Defaults to the always-present 'full' (responsive) option.\n const { viewports } = useCanvasViewports()\n const [viewport, setViewport] = useState(viewports[0]!.key)\n\n return (\n <div className=\"flex h-full min-h-0 flex-col\">\n <Row gap=\"1\" wrap align=\"center\" className=\"shrink-0 border-b border-border px-3 py-2\">\n {state.specs.length > 1 ? (\n <Row\n gap=\"1\"\n wrap\n role=\"group\"\n aria-label={translate('components.fixtureRunner.statesAria')}\n >\n {state.specs.map((spec, i) => (\n <TabButton key={spec.name} active={i === state.index} onClick={() => state.setIndex(i)}>\n {spec.name}\n </TabButton>\n ))}\n </Row>\n ) : null}\n <Spacer />\n <Row\n gap=\"1\"\n wrap\n role=\"group\"\n aria-label={translate('components.preview.breakpointAria')}\n >\n {viewports.map((option) => (\n <PreviewBreakpointButton\n key={option.key}\n option={option}\n active={option.key === viewport}\n onSelect={() => setViewport(option.key)}\n />\n ))}\n </Row>\n {state.dirty ? (\n <Button variant=\"ghost\" size=\"sm\" onClick={state.resetAll} data-testid=\"preview-reset\">\n <RotateCcw /> {translate('components.preview.reset')}\n </Button>\n ) : null}\n </Row>\n\n <div\n className=\"canvas-grid min-h-0 flex-1 overflow-auto p-6\"\n data-fixture-state={state.specs[state.index]?.name}\n >\n {serverOnly ? (\n <ServerOnlyNotice />\n ) : (\n <ComponentPreviewFrame\n node={state.node}\n ctx={ctx}\n displayName={displayName}\n width={viewportWidth(viewports, viewport)}\n />\n )}\n {status === 'incompatible' && !serverOnly ? (\n <Text size=\"xs\" tone=\"muted\" className=\"mx-auto mt-3 max-w-2xl\">\n {translate('components.preview.incompatibleNote')}\n </Text>\n ) : null}\n </div>\n </div>\n )\n}\n\n/**\n * One breakpoint option in the preview's width switcher. Mirrors the builder\n * canvas toolbar's `ViewportButton` (`composition-field-editor.tsx`) — same\n * `Button`/active-state styling — but drives LOCAL preview state instead of\n * the builder store (this surface has no composition/undo stack).\n *\n * EC-328: evaluated against the shared `TabButton`/`SegmentedControl`\n * primitives and kept separate — it's built on the shared `Button` (not a\n * bare hand-rolled `<button>`, so it wasn't part of the duplication those\n * primitives address), and carries an interpolated `aria-label` plus a\n * conditional px-value `title` tooltip neither primitive's terse API models.\n */\nfunction PreviewBreakpointButton({\n option,\n active,\n onSelect,\n}: {\n option: ViewportOption\n active: boolean\n onSelect: () => void\n}) {\n return (\n <Button\n size=\"sm\"\n variant=\"ghost\"\n aria-label={translate('builder.canvas.viewportPreviewAria', { label: option.label })}\n aria-pressed={active}\n title={\n option.px !== undefined\n ? `${option.label} · ${option.px}px`\n : translate('builder.canvas.viewportWidthTitle', { label: option.label })\n }\n onClick={onSelect}\n className={cn('px-2 text-xs', active && 'bg-accent text-accent-foreground')}\n >\n {option.label}\n </Button>\n )\n}\n\nfunction ServerOnlyNotice() {\n return (\n <div className=\"mx-auto grid max-w-2xl place-items-center rounded-lg border border-dashed border-border bg-muted/30 p-8 text-center\">\n <Stack gap=\"2\" align=\"center\">\n <MonitorOff className=\"size-5 text-muted-foreground\" aria-hidden />\n <Text size=\"sm\" weight=\"medium\">\n {translate('components.preview.serverOnlyTitle')}\n </Text>\n <Text size=\"xs\" tone=\"muted\" className=\"max-w-sm\">\n {translate('components.preview.serverOnlyBody')}\n </Text>\n </Stack>\n </div>\n )\n}\n\n/** Floor for the auto-height iframe — never collapses to a sliver while empty/loading. */\nconst MIN_PREVIEW_HEIGHT = 360\n\n/**\n * The live preview render surface. Reuses the BuilderCanvas styling mechanism\n * (EC-061, `canvas.tsx`) — since EC-414 through the SAME code path, `wireCanvasChrome`\n * (closing the EC-389 follow-up): the component renders inside an ISOLATED\n * same-origin iframe that `<link>`s the project's canvas stylesheet\n * (`getCanvasStylesheetUrl()` — the consumer's theme entry; in the legacy merged\n * world also the studio CSS), so a component built with the site's Tailwind theme\n * previews with the site's styles, exactly as it does on the canvas and in\n * delivery. Using the iframe (not the studio DOM) is what keeps the delivery CSS\n * scoped and off the studio chrome.\n *\n * Unlike the builder canvas, this iframe's document is deliberately left OUT of\n * the studio's own dark/light class: this is a standalone-component reference\n * surface (not a full page), so its own negative space around the component must\n * read as a light, site-like backdrop — never the studio chrome's current theme\n * (a black frame is exactly what leaks through when the studio is dark-themed and\n * the iframe root inherits that class). The chrome's world probe supplies that\n * backdrop: the neutral backdrop rules in the new world, the studio `:root`\n * (light) tokens in the legacy one.\n *\n * Sizing: width is driven by the caller (the breakpoint selector); height is\n * measured live from the rendered content via `ResizeObserver` (EC-330) so a\n * preset switch or a prop edit — both of which change what's portaled into\n * `doc.body` — always show without clipping or dead space.\n *\n * The render is wrapped in {@link PreviewErrorBoundary} so a component that throws\n * shows the EC-191 fallback instead of taking the whole Components view down.\n */\nfunction ComponentPreviewFrame({\n node,\n ctx,\n displayName,\n width,\n}: {\n node: ComponentNode\n ctx: RenderContext\n displayName: string\n /** CSS width for the iframe — '100%' (responsive) or a fixed breakpoint px width. */\n width: string\n}) {\n const iframeRef = useRef<HTMLIFrameElement>(null)\n const [doc, setDoc] = useState<Document | null>(null)\n const [height, setHeight] = useState(MIN_PREVIEW_HEIGHT)\n\n const wireUp = useCallback(() => {\n const d = iframeRef.current?.contentDocument\n if (!d || !d.body) return\n // ONE code path with the builder canvas (EC-414 AD-B item 4): stylesheet\n // link + chrome css + consumer canvas theme + the world probe. No kit\n // tokens here — this is a registry-level reference surface, not a project\n // page. The dev theme notice is the builder canvas's job, not this pane's.\n wireCanvasChrome(d, {\n stylesheetUrl: getCanvasStylesheetUrl(),\n theme: resolveDeploymentCanvasTheme(),\n })\n setDoc(d)\n }, [])\n\n // Handle the already-loaded case (srcDoc can load before onLoad attaches).\n useEffect(() => {\n if (iframeRef.current?.contentDocument?.readyState === 'complete') wireUp()\n }, [wireUp])\n\n // Auto-height (EC-330): a same-origin iframe exposes its own document, so a\n // `ResizeObserver` on the BODY tracks its live (height: auto) content size —\n // re-firing on its own whenever the portaled render changes (preset switch,\n // prop edit), no manual re-measure wiring needed. Attached per `doc` (re-runs\n // whenever the iframe reloads), not just on mount. Loop-safety: the observed\n // element (the iframe's body) is never the element this effect resizes (the\n // IFRAME itself) — writing height never feeds back into the observed box, and\n // width is never derived from height, so there is no growth loop. Guarded for\n // environments without ResizeObserver (jsdom/tests, older embeds).\n useEffect(() => {\n const body = doc?.body\n if (!body || typeof ResizeObserver === 'undefined') return\n const measure = () => setHeight(Math.max(body.scrollHeight, MIN_PREVIEW_HEIGHT))\n measure()\n const observer = new ResizeObserver(measure)\n observer.observe(body)\n return () => observer.disconnect()\n }, [doc])\n\n return (\n <>\n <iframe\n ref={iframeRef}\n onLoad={wireUp}\n title={translate('components.detail.tab.preview')}\n style={{ width, height, maxWidth: '100%' }}\n className=\"mx-auto block rounded-lg border border-border bg-background shadow-sm\"\n srcDoc=\"<!doctype html><html><head></head><body></body></html>\"\n />\n {doc\n ? createPortal(\n <PreviewErrorBoundary displayName={displayName} resetKey={node}>\n <PreviewLiveRender node={node} ctx={ctx} />\n </PreviewErrorBoundary>,\n doc.body,\n )\n : null}\n </>\n )\n}\n\n/** Renders the node through the runtime renderer, INSIDE a component render so the\n * error boundary catches synchronous render throws (mirrors the blocks-panel\n * thumbnail's `LiveRender`). */\nfunction PreviewLiveRender({ node, ctx }: { node: ComponentNode; ctx: RenderContext }) {\n return <>{renderNode(node, ctx)}</>\n}\n\ninterface PreviewBoundaryState {\n error: Error | null\n}\n\n/**\n * EC-191 resilience for the Components view: a component whose render throws — a\n * missing provider/context (e.g. a prop control that needs a document's\n * `CollectionViewSource`), a runtime bug — shows the documented \"preview\n * unavailable\" fallback ({@link PreviewUnavailable}) instead of taking the whole\n * view down. It resets when the previewed `resetKey` (the node) changes, so\n * switching the fixture state or editing a prop retries the render.\n */\nexport class PreviewErrorBoundary extends Component<\n { children: ReactNode; displayName: string; resetKey: unknown },\n PreviewBoundaryState\n> {\n override state: PreviewBoundaryState = { error: null }\n\n static getDerivedStateFromError(error: Error): PreviewBoundaryState {\n return { error }\n }\n\n override componentDidUpdate(prev: Readonly<{ resetKey: unknown }>) {\n if (this.state.error && prev.resetKey !== this.props.resetKey) {\n this.setState({ error: null })\n }\n }\n\n override render(): ReactNode {\n if (this.state.error) {\n return <PreviewUnavailable displayName={this.props.displayName} error={this.state.error} />\n }\n return this.props.children\n }\n}\n\n/**\n * The EC-191 fallback panel — component name + \"preview unavailable\" + the error.\n * Rendered INTO the preview iframe (which carries only the project stylesheet, and\n * may carry none in tests), so it uses inline styles rather than studio UI classes\n * — the EC-414 AD-B chrome contract, with the `.ec-chrome` containment recipe on\n * its root (walked by the chrome contract test).\n */\nexport function PreviewUnavailable({ displayName, error }: { displayName: string; error: Error }) {\n return (\n <div\n data-preview-unavailable\n className=\"ec-chrome\"\n style={{\n boxSizing: 'border-box',\n maxWidth: '42rem',\n margin: '0 auto',\n border: '1px dashed rgba(120,120,120,0.5)',\n borderRadius: 8,\n padding: '24px 28px',\n background: 'rgba(127,127,127,0.06)',\n color: 'rgba(90,90,90,0.95)',\n font: '14px/1.5 system-ui, -apple-system, sans-serif',\n textAlign: 'center',\n }}\n >\n <div style={{ fontWeight: 600 }}>⚠ {translate('components.preview.unavailableTitle')}</div>\n <div style={{ marginTop: 4, fontWeight: 600, opacity: 0.9 }}>{displayName}</div>\n <div style={{ marginTop: 6, fontSize: 13, opacity: 0.85, wordBreak: 'break-word' }}>\n {error.message}\n </div>\n </div>\n )\n}\n\n/**\n * The editable Props pane (right inspector). Every non-`blocks` prop is edited\n * through the shared {@link PropValueControl} — the exact control set documents\n * use (EC-190/EC-314 phase 4) — so a change re-renders the preview immediately.\n * `blocks` props are a canvas (composition) concern, edited in a document, not here.\n */\nexport function PropsEditorPane({\n manifest,\n state,\n}: {\n manifest: ComponentManifest\n state: PreviewState\n}) {\n const editable = Object.entries(manifest.props).filter(([, spec]) => spec.type !== 'blocks')\n const fixture = state.specs[state.index]?.node\n if (editable.length === 0) {\n return (\n <Text size=\"sm\" tone=\"subtle\" className=\"p-4\">\n {translate('components.fieldInspector.noProps')}\n </Text>\n )\n }\n return (\n <Stack gap=\"4\" className=\"p-4\">\n {editable.map(([name, spec]) => {\n const id = `prop-${name}`\n const overridden = state.overrides[name] !== undefined\n return (\n <Field\n key={name}\n label={\n <Row gap=\"2\">\n <span>{localizedLabel((spec as PropField).form?.label, name)}</span>\n {overridden ? <Badge variant=\"info\">{translate('components.preview.edited')}</Badge> : null}\n </Row>\n }\n htmlFor={id}\n hint={localizedLabel((spec as PropField).form?.description) || undefined}\n >\n <PropValueControl\n id={id}\n name={name}\n spec={spec as PropField}\n value={\n overridden\n ? staticProp(state.overrides[name]!)\n : (fixture?.props?.[name] ?? undefined)\n }\n onSet={(v) => state.setOverride(name, v)}\n onClear={() => state.clearOverride(name)}\n />\n </Field>\n )\n })}\n {state.dirty ? (\n <Button variant=\"outline\" size=\"sm\" onClick={state.resetAll} className=\"self-start\">\n <RotateCcw /> {translate('components.preview.resetProps')}\n </Button>\n ) : null}\n </Stack>\n )\n}\n\n/**\n * The Slots pane (right inspector): the component's declared child regions and,\n * for a fixture that supplies slot content, a note that the preview's slot content\n * follows the selected state. Documents the pragmatic scope call — no slot-tree\n * editing on this reference surface.\n */\nexport function SlotsInfoPane({ manifest }: { manifest: ComponentManifest }) {\n // EC-591 (COMPOSITION #14): the DERIVED slots — a `blocks` prop (a Section's\n // `body`) is a child region too, exactly as the canvas, validator and renderer see it.\n const slots = manifestSlots(manifest)\n if (slots.length === 0) {\n return (\n <Text size=\"sm\" tone=\"subtle\" className=\"p-4\">\n {translate('components.fieldInspector.noSlots')}\n </Text>\n )\n }\n return (\n <Stack gap=\"3\" className=\"p-4\">\n <Text size=\"xs\" tone=\"muted\">\n {translate('components.preview.slotsNote')}\n </Text>\n <div className=\"divide-y divide-border rounded-md border border-border\">\n {slots.map((slot) => (\n <div key={slot.name} className=\"flex flex-col gap-1 p-3\">\n <Row gap=\"2\">\n <Code tone=\"primary\">{slot.name}</Code>\n {slot.required ? (\n <Badge variant=\"warning\">{translate('common.required')}</Badge>\n ) : (\n <Badge variant=\"outline\">{translate('common.optional')}</Badge>\n )}\n </Row>\n {slot.allow && slot.allow.length > 0 ? (\n <Row gap=\"2\" className=\"text-xs\" wrap>\n <Text size=\"xs\" tone=\"subtle\">\n {translate('components.fieldInspector.allows')}\n </Text>\n {slot.allow.map((id) => (\n <Code key={id} tone=\"muted\">\n {id}\n </Code>\n ))}\n </Row>\n ) : null}\n </div>\n ))}\n </div>\n </Stack>\n )\n}\n"]}
|
|
@@ -4,7 +4,7 @@ import { FilePlus2, FileText, Loader2, Search } from 'lucide-react';
|
|
|
4
4
|
import { STUDIO_PROJECT_ROUTE, studioPath, useNavigate } from '@elytracms/studio/router';
|
|
5
5
|
import { Button, Code, Dialog, DialogContent, DialogDescription, DialogFooter, DialogHeader, DialogTitle, Input, Row, Stack, Text, } from '@elytracms/studio/ui';
|
|
6
6
|
import { cn } from '../../lib/utils.js';
|
|
7
|
-
import { getStudioRegistry } from '../../lib/registry/index.js';
|
|
7
|
+
import { getStudioRegistry, studioManifestLookup } from '../../lib/registry/index.js';
|
|
8
8
|
import { localizedLabel, translate } from '../../lib/i18n/index.js';
|
|
9
9
|
import { CmsSessionGate } from '../project-session.js';
|
|
10
10
|
import { CmsProvider, useCms } from '../cms/cms-store.js';
|
|
@@ -107,6 +107,7 @@ export function TransferPicker({ projectId, node, onClose, }) {
|
|
|
107
107
|
node,
|
|
108
108
|
newId: cms.newDocumentId,
|
|
109
109
|
locales: cms.localeConfig,
|
|
110
|
+
lookupManifest: studioManifestLookup(),
|
|
110
111
|
});
|
|
111
112
|
await persistAndOpen(doc, target);
|
|
112
113
|
}
|
|
@@ -128,6 +129,7 @@ export function TransferPicker({ projectId, node, onClose, }) {
|
|
|
128
129
|
node,
|
|
129
130
|
locale: cms.activeLocale,
|
|
130
131
|
newId: cms.newDocumentId,
|
|
132
|
+
lookupManifest: studioManifestLookup(),
|
|
131
133
|
});
|
|
132
134
|
await persistAndOpen(doc, target, { patches, revision: cms.revisionOfView(current) });
|
|
133
135
|
}
|