@phtngyn/cms 0.1.0-beta.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +13 -0
- package/README.md +90 -0
- package/dist/studio/assets/ActivityEntryRow-D--fRvWI.js +1 -0
- package/dist/studio/assets/ActivityView-D-XBBUHb.js +1 -0
- package/dist/studio/assets/CreateDocumentDialog-CH8UH1QM.js +1 -0
- package/dist/studio/assets/DocumentsView-CxRpmAxt.js +34 -0
- package/dist/studio/assets/DropdownMenu-BSb1l7fr.js +1 -0
- package/dist/studio/assets/Input-DVao38h7.js +3 -0
- package/dist/studio/assets/MediaView-BHrPIjxB.js +1 -0
- package/dist/studio/assets/Modal-VNrXGa5C.js +1 -0
- package/dist/studio/assets/OverviewView-DfP6-mLZ.js +1 -0
- package/dist/studio/assets/Select-BJZIs9sY.js +1 -0
- package/dist/studio/assets/SettingsView-CerHe-ua.js +1 -0
- package/dist/studio/assets/Skeleton-CWJNi3nS.js +1 -0
- package/dist/studio/assets/StudioPageHeader-DP9HDAF2.js +1 -0
- package/dist/studio/assets/UsersView-cP3REkH2.js +1 -0
- package/dist/studio/assets/collaboration-BLnCzfvV.js +4 -0
- package/dist/studio/assets/context-dY4fNbn3.js +1 -0
- package/dist/studio/assets/editor-CE07wW83.js +137 -0
- package/dist/studio/assets/gateway-BAyQgCse.js +10 -0
- package/dist/studio/assets/index-CjoaPLhZ.js +28 -0
- package/dist/studio/assets/index-s2rPqCmP.css +2 -0
- package/dist/studio/assets/render-BkxbK2St.js +83 -0
- package/dist/studio/assets/rolldown-runtime-DK3Fl9T5.js +1 -0
- package/dist/studio/assets/useMediaLibrary-D7qR7aBf.js +1 -0
- package/dist/studio/index.html +76 -0
- package/package.json +75 -0
- package/src/Authoring.d.ts +46 -0
- package/src/Authoring.js +1 -0
- package/src/AuthoringSchema-BQ5kbhVB.js +926 -0
- package/src/AuthoringSchema-BQ5kbhVB.js.map +1 -0
- package/src/Configuration-BGYFD2N1.js +150 -0
- package/src/Configuration-BGYFD2N1.js.map +1 -0
- package/src/Configuration.d.ts +44 -0
- package/src/Configuration.js +9 -0
- package/src/Configuration.js.map +1 -0
- package/src/DocumentEngine-Da0kWotL.js +851 -0
- package/src/DocumentEngine-Da0kWotL.js.map +1 -0
- package/src/DocumentModel.d.ts +30 -0
- package/src/DocumentModel.js +15 -0
- package/src/DocumentModel.js.map +1 -0
- package/src/HttpPaths-86qLGB90.js +15 -0
- package/src/HttpPaths-86qLGB90.js.map +1 -0
- package/src/Module.d.ts +12 -0
- package/src/Module.js +167 -0
- package/src/Module.js.map +1 -0
- package/src/StudioHttp-BTLLooh0.js +916 -0
- package/src/StudioHttp-BTLLooh0.js.map +1 -0
- package/src/connection-ZGtL54qY.js +94 -0
- package/src/connection-ZGtL54qY.js.map +1 -0
- package/src/installation-BNKaVjni.js +9128 -0
- package/src/installation-BNKaVjni.js.map +1 -0
- package/src/internal/authoring-compiler.js +120 -0
- package/src/internal/authoring-compiler.js.map +1 -0
- package/src/internal/authoring-metadata.js +163 -0
- package/src/internal/authoring-metadata.js.map +1 -0
- package/src/internal/cms-config.js +46 -0
- package/src/internal/cms-config.js.map +1 -0
- package/src/internal/component-metadata.js +37 -0
- package/src/internal/component-metadata.js.map +1 -0
- package/src/internal/configuration.js +93 -0
- package/src/internal/configuration.js.map +1 -0
- package/src/internal/document-model.js +236 -0
- package/src/internal/document-model.js.map +1 -0
- package/src/internal/field-metadata.js +6 -0
- package/src/internal/field-metadata.js.map +1 -0
- package/src/metadata-Czvi3E4K.js +190 -0
- package/src/metadata-Czvi3E4K.js.map +1 -0
- package/src/models-Citx8jBi.js +306 -0
- package/src/models-Citx8jBi.js.map +1 -0
- package/src/models-DS5ClMsH.js +153 -0
- package/src/models-DS5ClMsH.js.map +1 -0
- package/src/runtime/api.js +9 -0
- package/src/runtime/api.js.map +1 -0
- package/src/runtime/collaboration.js +40 -0
- package/src/runtime/collaboration.js.map +1 -0
- package/src/runtime/delivery/DocumentField.js +23 -0
- package/src/runtime/delivery/DocumentField.js.map +1 -0
- package/src/runtime/delivery/DocumentRenderer.js +51 -0
- package/src/runtime/delivery/DocumentRenderer.js.map +1 -0
- package/src/runtime/delivery/DocumentScope.js +41 -0
- package/src/runtime/delivery/DocumentScope.js.map +1 -0
- package/src/runtime/delivery/document-page.js +23 -0
- package/src/runtime/delivery/document-page.js.map +1 -0
- package/src/runtime/delivery/document.js +25 -0
- package/src/runtime/delivery/document.js.map +1 -0
- package/src/runtime/delivery/preview.d.ts +11 -0
- package/src/runtime/delivery/preview.js +6 -0
- package/src/runtime/delivery/preview.js.map +1 -0
- package/src/runtime/delivery/types.d.ts +80 -0
- package/src/runtime/delivery/types.js +1 -0
- package/src/runtime/delivery/useDocument.d.ts +6 -0
- package/src/runtime/delivery/useDocument.js +20 -0
- package/src/runtime/delivery/useDocument.js.map +1 -0
- package/src/runtime/delivery/useDocumentQuery.d.ts +7 -0
- package/src/runtime/delivery/useDocumentQuery.js +26 -0
- package/src/runtime/delivery/useDocumentQuery.js.map +1 -0
- package/src/runtime/installation.js +3 -0
- package/src/runtime/plugin.js +32 -0
- package/src/runtime/plugin.js.map +1 -0
- package/src/runtime/preview/CmsStudioPreviewMarker.js +15 -0
- package/src/runtime/preview/CmsStudioPreviewMarker.js.map +1 -0
- package/src/runtime/preview/comark-document.js +38 -0
- package/src/runtime/preview/comark-document.js.map +1 -0
- package/src/runtime/preview/connection.js +3 -0
- package/src/runtime/preview/controller.js +247 -0
- package/src/runtime/preview/controller.js.map +1 -0
- package/src/runtime/preview/plugin.client.js +70 -0
- package/src/runtime/preview/plugin.client.js.map +1 -0
- package/src/runtime/preview/preview.css +9 -0
- package/src/runtime/preview/protocol.d.ts +10 -0
- package/src/runtime/preview/protocol.js +11 -0
- package/src/runtime/preview/protocol.js.map +1 -0
- package/src/runtime/preview/store.js +4 -0
- package/src/runtime/preview/targets.js +102 -0
- package/src/runtime/preview/targets.js.map +1 -0
- package/src/runtime/studio-app.js +13 -0
- package/src/runtime/studio-app.js.map +1 -0
- package/src/store-Nl4uxEXx.js +221 -0
- package/src/store-Nl4uxEXx.js.map +1 -0
|
@@ -0,0 +1,221 @@
|
|
|
1
|
+
import { H as PublicPath, P as CollectionName, n as CmsMarkdownDocument, z as DocumentId } from "./models-Citx8jBi.js";
|
|
2
|
+
import { l as mutableJson, n as editorMetadata, u as mutableJsonObject } from "./metadata-Czvi3E4K.js";
|
|
3
|
+
import { CMS_PREVIEW_INLINE_HOST_ATTRIBUTE, CMS_PREVIEW_MARKER_TAG, CMS_PREVIEW_NODE_ATTRIBUTE, CMS_PREVIEW_TARGET_ATTRIBUTE, CMS_PREVIEW_WRAPPER_ATTRIBUTE } from "./runtime/preview/protocol.js";
|
|
4
|
+
import { toPreviewRenderDocument } from "./runtime/preview/comark-document.js";
|
|
5
|
+
import { Predicate, Result, Schema } from "effect";
|
|
6
|
+
import { shallowReactive } from "vue";
|
|
7
|
+
import { createComarkContext } from "comark";
|
|
8
|
+
|
|
9
|
+
//#region ../document/src/PreviewProjection.ts
|
|
10
|
+
var PreviewProjectionInvalid = class extends Schema.TaggedError()("PreviewProjection.Invalid", {
|
|
11
|
+
message: Schema.NonEmptyString,
|
|
12
|
+
cause: Schema.Defect()
|
|
13
|
+
}) {};
|
|
14
|
+
const NATIVE_BLOCK_TAGS = /* @__PURE__ */ new Set([
|
|
15
|
+
"blockquote",
|
|
16
|
+
"h1",
|
|
17
|
+
"h2",
|
|
18
|
+
"h3",
|
|
19
|
+
"h4",
|
|
20
|
+
"h5",
|
|
21
|
+
"h6",
|
|
22
|
+
"hr",
|
|
23
|
+
"img",
|
|
24
|
+
"li",
|
|
25
|
+
"math",
|
|
26
|
+
"ol",
|
|
27
|
+
"p",
|
|
28
|
+
"pre",
|
|
29
|
+
"table",
|
|
30
|
+
"tbody",
|
|
31
|
+
"td",
|
|
32
|
+
"th",
|
|
33
|
+
"thead",
|
|
34
|
+
"tr",
|
|
35
|
+
"ul"
|
|
36
|
+
]);
|
|
37
|
+
const INLINE_TAGS = /* @__PURE__ */ new Set([
|
|
38
|
+
"a",
|
|
39
|
+
"br",
|
|
40
|
+
"code",
|
|
41
|
+
"del",
|
|
42
|
+
"em",
|
|
43
|
+
"img",
|
|
44
|
+
"strong",
|
|
45
|
+
"u"
|
|
46
|
+
]);
|
|
47
|
+
/** Projects private authoring identities into an ephemeral preview without mutating the canonical body. */
|
|
48
|
+
function projectPreviewDocument(body, markers) {
|
|
49
|
+
return Result.try({
|
|
50
|
+
try: () => projectPreviewDocumentUnsafe(body, markers),
|
|
51
|
+
catch: (cause) => new PreviewProjectionInvalid({
|
|
52
|
+
cause,
|
|
53
|
+
message: cause instanceof Error && cause.message ? cause.message : "The preview projection is invalid."
|
|
54
|
+
})
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
function projectPreviewDocumentUnsafe(body, markers) {
|
|
58
|
+
const fallbacks = {};
|
|
59
|
+
let identifiedTargets = 0;
|
|
60
|
+
const cloneNodes = (nodes, componentId) => nodes.map((node) => {
|
|
61
|
+
if (Predicate.isString(node) || node[0] === null) return mutableJson(node);
|
|
62
|
+
const [tag, originalAttributes, ...originalChildren] = node;
|
|
63
|
+
const isSlot = tag === "template";
|
|
64
|
+
const isNative = NATIVE_BLOCK_TAGS.has(tag);
|
|
65
|
+
const attributes = mutableJsonObject(originalAttributes);
|
|
66
|
+
const metadata = editorMetadata(attributes);
|
|
67
|
+
const id = metadata?.nodeId;
|
|
68
|
+
if (id) {
|
|
69
|
+
identifiedTargets++;
|
|
70
|
+
if (componentId) fallbacks[id] = componentId;
|
|
71
|
+
if (!isSlot && !isNative) {
|
|
72
|
+
attributes[markers.nodeAttribute] = id;
|
|
73
|
+
attributes[markers.targetAttribute] = "component";
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
const children = [...cloneNodes(originalChildren, !isNative && !isSlot && id ? id : componentId)];
|
|
77
|
+
if (id && metadata?.implicitSlotId && !isNative && !isSlot && hasImplicitDefaultContent(originalChildren)) {
|
|
78
|
+
const slotId = metadata.implicitSlotId;
|
|
79
|
+
fallbacks[slotId] = id;
|
|
80
|
+
const markerChildren = hasInlineImplicitDefaultContent(originalChildren) ? children.splice(0) : [];
|
|
81
|
+
const markerAttributes = {
|
|
82
|
+
[markers.nodeAttribute]: slotId,
|
|
83
|
+
[markers.targetAttribute]: "slot",
|
|
84
|
+
[markers.wrapperAttribute]: ""
|
|
85
|
+
};
|
|
86
|
+
if (markerChildren.length) markerAttributes[markers.inlineHostAttribute] = "";
|
|
87
|
+
children.unshift([
|
|
88
|
+
markers.markerTag,
|
|
89
|
+
markerAttributes,
|
|
90
|
+
...markerChildren
|
|
91
|
+
]);
|
|
92
|
+
}
|
|
93
|
+
if (isSlot && id) children.unshift([markers.markerTag, {
|
|
94
|
+
[markers.nodeAttribute]: id,
|
|
95
|
+
[markers.targetAttribute]: "slot",
|
|
96
|
+
[markers.wrapperAttribute]: ""
|
|
97
|
+
}]);
|
|
98
|
+
const cloned = [
|
|
99
|
+
tag,
|
|
100
|
+
attributes,
|
|
101
|
+
...children
|
|
102
|
+
];
|
|
103
|
+
if (id && isNative) return previewWrapper(id, "native", cloned, markers);
|
|
104
|
+
if (id && !isNative && !isSlot) return previewWrapper(id, "component", cloned, markers);
|
|
105
|
+
return cloned;
|
|
106
|
+
});
|
|
107
|
+
const nodes = cloneNodes(body.nodes);
|
|
108
|
+
if (body.nodes.length && !identifiedTargets) throw new Error("Studio preview requires an identified authoring document.");
|
|
109
|
+
return {
|
|
110
|
+
body: CmsMarkdownDocument.make({
|
|
111
|
+
frontmatter: mutableJsonObject(body.frontmatter),
|
|
112
|
+
meta: mutableJsonObject(body.meta),
|
|
113
|
+
nodes
|
|
114
|
+
}),
|
|
115
|
+
fallbacks
|
|
116
|
+
};
|
|
117
|
+
}
|
|
118
|
+
function previewWrapper(nodeId, kind, child, markers) {
|
|
119
|
+
return [
|
|
120
|
+
markers.markerTag,
|
|
121
|
+
{
|
|
122
|
+
[markers.nodeAttribute]: nodeId,
|
|
123
|
+
[markers.targetAttribute]: kind,
|
|
124
|
+
[markers.wrapperAttribute]: ""
|
|
125
|
+
},
|
|
126
|
+
child
|
|
127
|
+
];
|
|
128
|
+
}
|
|
129
|
+
function hasImplicitDefaultContent(nodes) {
|
|
130
|
+
return !nodes.some((node) => Array.isArray(node) && node[0] === "template" && node[1].name === "default") && nodes.some((node) => Predicate.isString(node) ? Boolean(node) : node[0] !== "template");
|
|
131
|
+
}
|
|
132
|
+
function hasInlineImplicitDefaultContent(nodes) {
|
|
133
|
+
return nodes.length > 0 && nodes.every((node) => Predicate.isString(node) || Array.isArray(node) && node[0] !== null && INLINE_TAGS.has(node[0]));
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
//#endregion
|
|
137
|
+
//#region src/runtime/preview/store.ts
|
|
138
|
+
function createStudioPreviewStore(route) {
|
|
139
|
+
const context = createComarkContext();
|
|
140
|
+
const patches = shallowReactive(/* @__PURE__ */ new Map());
|
|
141
|
+
const registrations = /* @__PURE__ */ new Map();
|
|
142
|
+
const listeners = /* @__PURE__ */ new Set();
|
|
143
|
+
const manifest = () => ({
|
|
144
|
+
documents: renderedDocuments(registrations.values(), patches),
|
|
145
|
+
route: route()
|
|
146
|
+
});
|
|
147
|
+
const notify = () => {
|
|
148
|
+
const value = manifest();
|
|
149
|
+
for (const listener of listeners) listener(value);
|
|
150
|
+
};
|
|
151
|
+
return {
|
|
152
|
+
manifest,
|
|
153
|
+
async patch(document) {
|
|
154
|
+
const preview = createPreviewDocument(document.body);
|
|
155
|
+
const patched = Object.assign({}, document, { body: preview.body });
|
|
156
|
+
patches.set(document.id, patched);
|
|
157
|
+
const renderBody = toPreviewRenderDocument(preview.body);
|
|
158
|
+
context.get(document.id, renderBody).set(renderBody);
|
|
159
|
+
notify();
|
|
160
|
+
return preview.fallbacks;
|
|
161
|
+
},
|
|
162
|
+
register(document, role) {
|
|
163
|
+
const registration = Symbol(document.id);
|
|
164
|
+
registrations.set(registration, {
|
|
165
|
+
document,
|
|
166
|
+
role
|
|
167
|
+
});
|
|
168
|
+
notify();
|
|
169
|
+
return () => {
|
|
170
|
+
registrations.delete(registration);
|
|
171
|
+
notify();
|
|
172
|
+
};
|
|
173
|
+
},
|
|
174
|
+
resolve(document) {
|
|
175
|
+
return patches.get(document.id) ?? document;
|
|
176
|
+
},
|
|
177
|
+
routeChanged: notify,
|
|
178
|
+
subscribe(listener) {
|
|
179
|
+
listeners.add(listener);
|
|
180
|
+
listener(manifest());
|
|
181
|
+
return () => listeners.delete(listener);
|
|
182
|
+
}
|
|
183
|
+
};
|
|
184
|
+
}
|
|
185
|
+
function renderedDocuments(registrations, patches) {
|
|
186
|
+
const priority = {
|
|
187
|
+
embedded: 1,
|
|
188
|
+
primary: 4,
|
|
189
|
+
related: 2,
|
|
190
|
+
summary: 3
|
|
191
|
+
};
|
|
192
|
+
const documents = /* @__PURE__ */ new Map();
|
|
193
|
+
for (const registration of registrations) {
|
|
194
|
+
const document = patches.get(registration.document.id) ?? registration.document;
|
|
195
|
+
const current = documents.get(document.id);
|
|
196
|
+
if (current && priority[current.role] >= priority[registration.role]) continue;
|
|
197
|
+
documents.set(document.id, {
|
|
198
|
+
collection: CollectionName.make(document.collection),
|
|
199
|
+
documentId: DocumentId.make(document.id),
|
|
200
|
+
path: PublicPath.make(document.path),
|
|
201
|
+
role: registration.role,
|
|
202
|
+
title: document.title
|
|
203
|
+
});
|
|
204
|
+
}
|
|
205
|
+
return [...documents.values()].sort((left, right) => priority[right.role] - priority[left.role] || left.title.localeCompare(right.title));
|
|
206
|
+
}
|
|
207
|
+
function createPreviewDocument(body) {
|
|
208
|
+
const projection = projectPreviewDocument(body, {
|
|
209
|
+
inlineHostAttribute: CMS_PREVIEW_INLINE_HOST_ATTRIBUTE,
|
|
210
|
+
markerTag: CMS_PREVIEW_MARKER_TAG,
|
|
211
|
+
nodeAttribute: CMS_PREVIEW_NODE_ATTRIBUTE,
|
|
212
|
+
targetAttribute: CMS_PREVIEW_TARGET_ATTRIBUTE,
|
|
213
|
+
wrapperAttribute: CMS_PREVIEW_WRAPPER_ATTRIBUTE
|
|
214
|
+
});
|
|
215
|
+
if (Result.isFailure(projection)) throw projection.failure;
|
|
216
|
+
return projection.success;
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
//#endregion
|
|
220
|
+
export { createStudioPreviewStore as t };
|
|
221
|
+
//# sourceMappingURL=store-Nl4uxEXx.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"store-Nl4uxEXx.js","names":["CmsMarkdownDocumentSchema"],"sources":["../../../../document/src/PreviewProjection.ts","../../../src/runtime/preview/store.ts"],"sourcesContent":["import type { CmsMarkdownDocument, MarkdownNode } from '@internal/protocol/Documents'\nimport type { EditorNodeId } from '@internal/protocol/Documents'\nimport { CmsMarkdownDocument as CmsMarkdownDocumentSchema } from '@internal/protocol/Documents'\nimport { Predicate, Result, Schema } from 'effect'\nimport { mutableJson, mutableJsonObject } from './internal/comark/document-adapter'\nimport { editorMetadata } from './internal/editor/metadata'\n\nexport interface PreviewProjectionMarkers {\n readonly inlineHostAttribute: string\n readonly markerTag: string\n readonly nodeAttribute: string\n readonly targetAttribute: string\n readonly wrapperAttribute: string\n}\n\nexport interface PreviewProjection {\n readonly body: CmsMarkdownDocument\n readonly fallbacks: Readonly<Record<string, string>>\n}\n\nexport class PreviewProjectionInvalid extends Schema.TaggedError<PreviewProjectionInvalid>()(\n 'PreviewProjection.Invalid',\n {\n message: Schema.NonEmptyString,\n cause: Schema.Defect(),\n },\n) {}\n\nconst NATIVE_BLOCK_TAGS = new Set([\n 'blockquote',\n 'h1',\n 'h2',\n 'h3',\n 'h4',\n 'h5',\n 'h6',\n 'hr',\n 'img',\n 'li',\n 'math',\n 'ol',\n 'p',\n 'pre',\n 'table',\n 'tbody',\n 'td',\n 'th',\n 'thead',\n 'tr',\n 'ul',\n])\nconst INLINE_TAGS = new Set(['a', 'br', 'code', 'del', 'em', 'img', 'strong', 'u'])\n\n/** Projects private authoring identities into an ephemeral preview without mutating the canonical body. */\nexport function projectPreviewDocument(\n body: CmsMarkdownDocument,\n markers: PreviewProjectionMarkers,\n): Result.Result<PreviewProjection, PreviewProjectionInvalid> {\n return Result.try({\n try: () => projectPreviewDocumentUnsafe(body, markers),\n catch: (cause) =>\n new PreviewProjectionInvalid({\n cause,\n message: cause instanceof Error && cause.message ? cause.message : 'The preview projection is invalid.',\n }),\n })\n}\n\nfunction projectPreviewDocumentUnsafe(body: CmsMarkdownDocument, markers: PreviewProjectionMarkers): PreviewProjection {\n const fallbacks: Record<string, string> = {}\n let identifiedTargets = 0\n\n const cloneNodes = (nodes: ReadonlyArray<MarkdownNode>, componentId?: EditorNodeId): ReadonlyArray<Schema.Json> =>\n nodes.map((node) => {\n if (Predicate.isString(node) || node[0] === null) return mutableJson(node)\n const [tag, originalAttributes, ...originalChildren] = node\n const isSlot = tag === 'template'\n const isNative = NATIVE_BLOCK_TAGS.has(tag)\n const attributes = mutableJsonObject(originalAttributes)\n const metadata = editorMetadata(attributes)\n const id = metadata?.nodeId\n if (id) {\n identifiedTargets++\n if (componentId) fallbacks[id] = componentId\n if (!isSlot && !isNative) {\n attributes[markers.nodeAttribute] = id\n attributes[markers.targetAttribute] = 'component'\n }\n }\n\n const nextComponentId = !isNative && !isSlot && id ? id : componentId\n const children = [...cloneNodes(originalChildren, nextComponentId)]\n if (id && metadata?.implicitSlotId && !isNative && !isSlot && hasImplicitDefaultContent(originalChildren)) {\n const slotId = metadata.implicitSlotId\n fallbacks[slotId] = id\n const markerChildren = hasInlineImplicitDefaultContent(originalChildren) ? children.splice(0) : []\n const markerAttributes = {\n [markers.nodeAttribute]: slotId,\n [markers.targetAttribute]: 'slot',\n [markers.wrapperAttribute]: '',\n }\n if (markerChildren.length) markerAttributes[markers.inlineHostAttribute] = ''\n children.unshift([markers.markerTag, markerAttributes, ...markerChildren])\n }\n if (isSlot && id) {\n children.unshift([\n markers.markerTag,\n {\n [markers.nodeAttribute]: id,\n [markers.targetAttribute]: 'slot',\n [markers.wrapperAttribute]: '',\n },\n ])\n }\n const cloned: Schema.Json = [tag, attributes, ...children]\n if (id && isNative) return previewWrapper(id, 'native', cloned, markers)\n if (id && !isNative && !isSlot) return previewWrapper(id, 'component', cloned, markers)\n return cloned\n })\n\n const nodes = cloneNodes(body.nodes)\n if (body.nodes.length && !identifiedTargets)\n throw new Error('Studio preview requires an identified authoring document.')\n return {\n body: CmsMarkdownDocumentSchema.make({\n frontmatter: mutableJsonObject(body.frontmatter),\n meta: mutableJsonObject(body.meta),\n nodes,\n }),\n fallbacks,\n }\n}\n\nfunction previewWrapper(\n nodeId: EditorNodeId,\n kind: 'component' | 'native' | 'slot',\n child: Schema.Json,\n markers: PreviewProjectionMarkers,\n): Schema.Json {\n return [\n markers.markerTag,\n {\n [markers.nodeAttribute]: nodeId,\n [markers.targetAttribute]: kind,\n [markers.wrapperAttribute]: '',\n },\n child,\n ]\n}\n\nfunction hasImplicitDefaultContent(nodes: ReadonlyArray<MarkdownNode>): boolean {\n const hasExplicitDefault = nodes.some(\n (node) => Array.isArray(node) && node[0] === 'template' && node[1].name === 'default',\n )\n return (\n !hasExplicitDefault && nodes.some((node) => (Predicate.isString(node) ? Boolean(node) : node[0] !== 'template'))\n )\n}\n\nfunction hasInlineImplicitDefaultContent(nodes: ReadonlyArray<MarkdownNode>): boolean {\n return (\n nodes.length > 0 &&\n nodes.every(\n (node) => Predicate.isString(node) || (Array.isArray(node) && node[0] !== null && INLINE_TAGS.has(node[0])),\n )\n )\n}\n","import type { RenderedCompiledDocument, RenderedDocumentManifest } from '@internal/protocol/Preview'\nimport { projectPreviewDocument } from '@internal/document/PreviewProjection'\nimport { CollectionName } from '@internal/protocol/Configuration'\nimport { DocumentId, PublicPath } from '@internal/protocol/Documents'\nimport { Result } from 'effect'\nimport { createComarkContext } from 'comark'\nimport { shallowReactive } from 'vue'\nimport type { DeliveryDocument as PreviewCompiledDocument } from '../delivery/types'\nimport type { DocumentPreviewStore, PreviewDocumentRole } from '../delivery/preview'\nimport { toPreviewRenderDocument } from './comark-document'\nimport {\n CMS_PREVIEW_INLINE_HOST_ATTRIBUTE,\n CMS_PREVIEW_MARKER_TAG,\n CMS_PREVIEW_NODE_ATTRIBUTE,\n CMS_PREVIEW_TARGET_ATTRIBUTE,\n CMS_PREVIEW_WRAPPER_ATTRIBUTE,\n} from './protocol'\n\nexport { documentPreviewStoreKey, type DocumentPreviewStore, type PreviewDocumentRole } from '../delivery/preview'\nexport type { DeliveryDocument as PreviewCompiledDocument } from '../delivery/types'\n\nexport interface StudioPreviewStore extends DocumentPreviewStore {\n readonly manifest: () => RenderedDocumentManifest\n readonly patch: (document: PreviewCompiledDocument) => Promise<Readonly<Record<string, string>>>\n readonly routeChanged: () => void\n readonly subscribe: (listener: (manifest: RenderedDocumentManifest) => void) => () => void\n}\n\nexport function createStudioPreviewStore(route: () => RenderedDocumentManifest['route']): StudioPreviewStore {\n const context = createComarkContext()\n const patches = shallowReactive(new Map<string, PreviewCompiledDocument>())\n const registrations = new Map<\n symbol,\n { readonly document: PreviewCompiledDocument; readonly role: PreviewDocumentRole }\n >()\n const listeners = new Set<(manifest: RenderedDocumentManifest) => void>()\n const manifest = (): RenderedDocumentManifest => ({\n documents: renderedDocuments(registrations.values(), patches),\n route: route(),\n })\n const notify = (): void => {\n const value = manifest()\n for (const listener of listeners) listener(value)\n }\n\n return {\n manifest,\n async patch(document) {\n const preview = createPreviewDocument(document.body)\n const patched = Object.assign({}, document, { body: preview.body })\n patches.set(document.id, patched)\n const renderBody = toPreviewRenderDocument(preview.body)\n context.get(document.id, renderBody).set(renderBody)\n notify()\n return preview.fallbacks\n },\n register(document, role) {\n const registration = Symbol(document.id)\n registrations.set(registration, { document, role })\n notify()\n return () => {\n registrations.delete(registration)\n notify()\n }\n },\n resolve(document) {\n return patches.get(document.id) ?? document\n },\n routeChanged: notify,\n subscribe(listener) {\n listeners.add(listener)\n listener(manifest())\n return () => listeners.delete(listener)\n },\n }\n}\n\nfunction renderedDocuments(\n registrations: Iterable<{ readonly document: PreviewCompiledDocument; readonly role: PreviewDocumentRole }>,\n patches: ReadonlyMap<string, PreviewCompiledDocument>,\n): ReadonlyArray<RenderedCompiledDocument> {\n const priority = { embedded: 1, primary: 4, related: 2, summary: 3 } satisfies Record<PreviewDocumentRole, number>\n const documents = new Map<string, RenderedCompiledDocument>()\n for (const registration of registrations) {\n const document = patches.get(registration.document.id) ?? registration.document\n const current = documents.get(document.id)\n if (current && priority[current.role] >= priority[registration.role]) continue\n documents.set(document.id, {\n collection: CollectionName.make(document.collection),\n documentId: DocumentId.make(document.id),\n path: PublicPath.make(document.path),\n role: registration.role,\n title: document.title,\n })\n }\n return [...documents.values()].sort(\n (left, right) => priority[right.role] - priority[left.role] || left.title.localeCompare(right.title),\n )\n}\n\nfunction createPreviewDocument(body: PreviewCompiledDocument['body']) {\n const projection = projectPreviewDocument(body, {\n inlineHostAttribute: CMS_PREVIEW_INLINE_HOST_ATTRIBUTE,\n markerTag: CMS_PREVIEW_MARKER_TAG,\n nodeAttribute: CMS_PREVIEW_NODE_ATTRIBUTE,\n targetAttribute: CMS_PREVIEW_TARGET_ATTRIBUTE,\n wrapperAttribute: CMS_PREVIEW_WRAPPER_ATTRIBUTE,\n })\n if (Result.isFailure(projection)) throw projection.failure\n return projection.success\n}\n"],"mappings":";;;;;;;;;AAoBA,IAAa,2BAAb,cAA8C,OAAO,YAAsC,CAAC,CAC1F,6BACA;CACE,SAAS,OAAO;CAChB,OAAO,OAAO,OAAO;AACvB,CACF,CAAC,CAAC,CAAC;AAEH,MAAM,oCAAoB,IAAI,IAAI;CAChC;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;AACF,CAAC;AACD,MAAM,8BAAc,IAAI,IAAI;CAAC;CAAK;CAAM;CAAQ;CAAO;CAAM;CAAO;CAAU;AAAG,CAAC;;AAGlF,SAAgB,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