@phtngyn/cms 0.1.0-beta.0 → 0.1.0-beta.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +72 -1
- package/package.json +5 -5
- package/src/Authoring.d.ts +13 -1
- package/src/{AuthoringSchema-BQ5kbhVB.js → Configuration-DyKo0sLS.js} +595 -367
- package/src/Configuration-DyKo0sLS.js.map +1 -0
- package/src/{DocumentEngine-Da0kWotL.js → DocumentEngine-DYObwMDY.js} +44 -66
- package/src/DocumentEngine-DYObwMDY.js.map +1 -0
- package/src/DocumentModel.d.ts +4 -0
- package/src/DocumentModel.js.map +1 -1
- package/src/{HttpPaths-86qLGB90.js → HttpPaths-BbS21Jy8.js} +4 -2
- package/src/{HttpPaths-86qLGB90.js.map → HttpPaths-BbS21Jy8.js.map} +1 -1
- package/src/Module.js +27 -76
- package/src/Module.js.map +1 -1
- package/src/{StudioHttp-BTLLooh0.js → StudioHttp-jR2-bc01.js} +44 -242
- package/src/StudioHttp-jR2-bc01.js.map +1 -0
- package/src/{connection-ZGtL54qY.js → connection-CBTY-TzB.js} +3 -3
- package/src/{connection-ZGtL54qY.js.map → connection-CBTY-TzB.js.map} +1 -1
- package/src/{installation-BNKaVjni.js → installation-DeuBiFRE.js} +488 -236
- package/src/installation-DeuBiFRE.js.map +1 -0
- package/src/internal/authoring-catalog.js +147 -0
- package/src/internal/authoring-catalog.js.map +1 -0
- package/src/internal/authoring-compiler.js +2 -1
- package/src/internal/authoring-compiler.js.map +1 -1
- package/src/internal/authoring-metadata.js +67 -48
- package/src/internal/authoring-metadata.js.map +1 -1
- package/src/internal/configuration.js +5 -6
- package/src/internal/configuration.js.map +1 -1
- package/src/internal/document-model.js +3 -2
- package/src/internal/document-model.js.map +1 -1
- package/src/internal/studio-app.js +66 -0
- package/src/internal/studio-app.js.map +1 -0
- package/src/location-DtYv2aes.js +36 -0
- package/src/location-DtYv2aes.js.map +1 -0
- package/src/{metadata-Czvi3E4K.js → metadata-DE1Mc2td.js} +2 -2
- package/src/{metadata-Czvi3E4K.js.map → metadata-DE1Mc2td.js.map} +1 -1
- package/src/{models-Citx8jBi.js → models-BkMgeaOL.js} +252 -3
- package/src/models-BkMgeaOL.js.map +1 -0
- package/src/{models-DS5ClMsH.js → models-C3witQBK.js} +8 -31
- package/src/models-C3witQBK.js.map +1 -0
- package/src/runtime/blocks.js +17 -0
- package/src/runtime/blocks.js.map +1 -0
- package/src/runtime/collaboration.js +9 -4
- package/src/runtime/collaboration.js.map +1 -1
- package/src/runtime/delivery/DocumentRenderer.js +6 -3
- package/src/runtime/delivery/DocumentRenderer.js.map +1 -1
- package/src/runtime/delivery/blocks.js +6 -0
- package/src/runtime/delivery/blocks.js.map +1 -0
- package/src/runtime/delivery/context.js +12 -0
- package/src/runtime/delivery/context.js.map +1 -0
- package/src/runtime/delivery/document-page.js +5 -3
- package/src/runtime/delivery/document-page.js.map +1 -1
- package/src/runtime/delivery/document.js +18 -2
- package/src/runtime/delivery/document.js.map +1 -1
- package/src/runtime/delivery/error.js +11 -0
- package/src/runtime/delivery/error.js.map +1 -0
- package/src/runtime/delivery/plugin.js +21 -0
- package/src/runtime/delivery/plugin.js.map +1 -0
- package/src/runtime/delivery/useDocument.js +6 -3
- package/src/runtime/delivery/useDocument.js.map +1 -1
- package/src/runtime/delivery/useDocumentQuery.js +6 -3
- package/src/runtime/delivery/useDocumentQuery.js.map +1 -1
- package/src/runtime/installation.js +1 -1
- package/src/runtime/plugin.js +3 -3
- package/src/runtime/plugin.js.map +1 -1
- package/src/runtime/preview/connection.js +1 -1
- package/src/runtime/preview/controller.js +29 -10
- package/src/runtime/preview/controller.js.map +1 -1
- package/src/runtime/preview/overlay.js +65 -0
- package/src/runtime/preview/overlay.js.map +1 -0
- package/src/runtime/preview/plugin.client.js +21 -34
- package/src/runtime/preview/plugin.client.js.map +1 -1
- package/src/runtime/preview/preview.css +72 -4
- package/src/runtime/preview/store.js +1 -1
- package/src/runtime/studio-app.js +5 -1
- package/src/runtime/studio-app.js.map +1 -1
- package/src/runtime/studio-entry.js +36 -0
- package/src/runtime/studio-entry.js.map +1 -0
- package/src/runtime/studio-navigation.js +11 -0
- package/src/runtime/studio-navigation.js.map +1 -0
- package/src/{store-Nl4uxEXx.js → store-CfFFx9Ua.js} +3 -3
- package/src/{store-Nl4uxEXx.js.map → store-CfFFx9Ua.js.map} +1 -1
- package/studio/CreateDocumentDialog--L9lTfx6.js +256 -0
- package/studio/collaboration-DUuu678R.js +4565 -0
- package/studio/documentPlanning-BXX04Woe.js +28989 -0
- package/studio/dom-to-image-more.min-D6jGGdrW.js +877 -0
- package/studio/editor-PexnXkJY.js +30817 -0
- package/studio/host.css +3 -0
- package/studio/host.js +44179 -0
- package/studio/rolldown-runtime-B0aSnxlc.js +20 -0
- package/dist/studio/assets/ActivityEntryRow-D--fRvWI.js +0 -1
- package/dist/studio/assets/ActivityView-D-XBBUHb.js +0 -1
- package/dist/studio/assets/CreateDocumentDialog-CH8UH1QM.js +0 -1
- package/dist/studio/assets/DocumentsView-CxRpmAxt.js +0 -34
- package/dist/studio/assets/DropdownMenu-BSb1l7fr.js +0 -1
- package/dist/studio/assets/Input-DVao38h7.js +0 -3
- package/dist/studio/assets/MediaView-BHrPIjxB.js +0 -1
- package/dist/studio/assets/Modal-VNrXGa5C.js +0 -1
- package/dist/studio/assets/OverviewView-DfP6-mLZ.js +0 -1
- package/dist/studio/assets/Select-BJZIs9sY.js +0 -1
- package/dist/studio/assets/SettingsView-CerHe-ua.js +0 -1
- package/dist/studio/assets/Skeleton-CWJNi3nS.js +0 -1
- package/dist/studio/assets/StudioPageHeader-DP9HDAF2.js +0 -1
- package/dist/studio/assets/UsersView-cP3REkH2.js +0 -1
- package/dist/studio/assets/collaboration-BLnCzfvV.js +0 -4
- package/dist/studio/assets/context-dY4fNbn3.js +0 -1
- package/dist/studio/assets/editor-CE07wW83.js +0 -137
- package/dist/studio/assets/gateway-BAyQgCse.js +0 -10
- package/dist/studio/assets/index-CjoaPLhZ.js +0 -28
- package/dist/studio/assets/index-s2rPqCmP.css +0 -2
- package/dist/studio/assets/render-BkxbK2St.js +0 -83
- package/dist/studio/assets/rolldown-runtime-DK3Fl9T5.js +0 -1
- package/dist/studio/assets/useMediaLibrary-D7qR7aBf.js +0 -1
- package/dist/studio/index.html +0 -76
- package/src/AuthoringSchema-BQ5kbhVB.js.map +0 -1
- package/src/Configuration-BGYFD2N1.js +0 -150
- package/src/Configuration-BGYFD2N1.js.map +0 -1
- package/src/DocumentEngine-Da0kWotL.js.map +0 -1
- package/src/StudioHttp-BTLLooh0.js.map +0 -1
- package/src/installation-BNKaVjni.js.map +0 -1
- package/src/internal/component-metadata.js +0 -37
- package/src/internal/component-metadata.js.map +0 -1
- package/src/models-Citx8jBi.js.map +0 -1
- package/src/models-DS5ClMsH.js.map +0 -1
|
@@ -1 +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;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;EACxC;CACF;AACF;AAEA,SAAS,kBACP,eACA,SACyC;CACzC,MAAM,WAAW;EAAE,UAAU;EAAG,SAAS;EAAG,SAAS;EAAG,SAAS;CAAE;CACnE,MAAM,4BAAY,IAAI,IAAsC;CAC5D,KAAK,MAAM,gBAAgB,eAAe;EACxC,MAAM,WAAW,QAAQ,IAAI,aAAa,SAAS,EAAE,KAAK,aAAa;EACvE,MAAM,UAAU,UAAU,IAAI,SAAS,EAAE;EACzC,IAAI,WAAW,SAAS,QAAQ,SAAS,SAAS,aAAa,OAAO;EACtE,UAAU,IAAI,SAAS,IAAI;GACzB,YAAY,eAAe,KAAK,SAAS,UAAU;GACnD,YAAY,WAAW,KAAK,SAAS,EAAE;GACvC,MAAM,WAAW,KAAK,SAAS,IAAI;GACnC,MAAM,aAAa;GACnB,OAAO,SAAS;EAClB,CAAC;CACH;CACA,OAAO,CAAC,GAAG,UAAU,OAAO,CAAC,CAAC,CAAC,MAC5B,MAAM,UAAU,SAAS,MAAM,QAAQ,SAAS,KAAK,SAAS,KAAK,MAAM,cAAc,MAAM,KAAK,CACrG;AACF;AAEA,SAAS,sBAAsB,MAAuC;CACpE,MAAM,aAAa,uBAAuB,MAAM;EAC9C,qBAAqB;EACrB,WAAW;EACX,eAAe;EACf,iBAAiB;EACjB,kBAAkB;CACpB,CAAC;CACD,IAAI,OAAO,UAAU,UAAU,GAAG,MAAM,WAAW;CACnD,OAAO,WAAW;AACpB"}
|
|
1
|
+
{"version":3,"file":"store-CfFFx9Ua.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,uBACd,MACA,SAC4D;CAC5D,OAAO,OAAO,IAAI;EAChB,WAAW,6BAA6B,MAAM,OAAO;EACrD,QAAQ,UACN,IAAI,yBAAyB;GAC3B;GACA,SAAS,iBAAiB,SAAS,MAAM,UAAU,MAAM,UAAU;EACrE,CAAC;CACL,CAAC;AACH;AAEA,SAAS,6BAA6B,MAA2B,SAAsD;CACrH,MAAM,YAAoC,CAAC;CAC3C,IAAI,oBAAoB;CAExB,MAAM,cAAc,OAAoC,gBACtD,MAAM,KAAK,SAAS;EAClB,IAAI,UAAU,SAAS,IAAI,KAAK,KAAK,OAAO,MAAM,OAAO,YAAY,IAAI;EACzE,MAAM,CAAC,KAAK,oBAAoB,GAAG,oBAAoB;EACvD,MAAM,SAAS,QAAQ;EACvB,MAAM,WAAW,kBAAkB,IAAI,GAAG;EAC1C,MAAM,aAAa,kBAAkB,kBAAkB;EACvD,MAAM,WAAW,eAAe,UAAU;EAC1C,MAAM,KAAK,UAAU;EACrB,IAAI,IAAI;GACN;GACA,IAA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WAAW;AACpB"}
|
|
@@ -0,0 +1,256 @@
|
|
|
1
|
+
import { $ as e, $t as t, Ct as n, Ft as r, J as ee, K as te, Mt as i, Q as a, Tt as ne, Xt as o, Z as s, an as c, et as l, it as u, ot as d, pt as f, sn as p, tt as m, un as h, zt as g } from "./editor-PexnXkJY.js";
|
|
2
|
+
import { A as _, D as v, F as y, Gn as b, Kn as x, M as re, N as ie, i as ae, j as oe, n as se, r as S, t as C, tr as w } from "./documentPlanning-BXX04Woe.js";
|
|
3
|
+
//#region src/documents/CreateDocumentDialog.vue?vue&type=script&setup=true&lang.ts
|
|
4
|
+
var ce = { key: 2 }, T = { class: "grid grid-flow-col auto-cols-fr overflow-x-auto rounded-md border border-default" }, E = ["title", "onClick"], le = { class: "block truncate" }, ue = {
|
|
5
|
+
key: 0,
|
|
6
|
+
class: "mt-2 flex min-w-0 items-center justify-between gap-3 text-xs text-muted"
|
|
7
|
+
}, D = { class: "truncate" }, O = { class: "shrink-0 font-mono text-[11px] text-dimmed" }, k = {
|
|
8
|
+
key: 5,
|
|
9
|
+
class: "flex min-w-0 items-center gap-3 rounded-md border border-default px-3 py-2"
|
|
10
|
+
}, de = {
|
|
11
|
+
key: 6,
|
|
12
|
+
class: "-mt-2 text-xs text-error"
|
|
13
|
+
}, fe = {
|
|
14
|
+
key: 7,
|
|
15
|
+
class: "-mt-2 text-xs text-error"
|
|
16
|
+
}, pe = { class: "flex w-full justify-end gap-2" }, A = "__top_level__", j = /* @__PURE__ */ d({
|
|
17
|
+
__name: "CreateDocumentDialog",
|
|
18
|
+
props: /*@__PURE__*/ f({
|
|
19
|
+
catalog: {},
|
|
20
|
+
context: {}
|
|
21
|
+
}, {
|
|
22
|
+
open: { type: Boolean },
|
|
23
|
+
openModifiers: {}
|
|
24
|
+
}),
|
|
25
|
+
emits: /*@__PURE__*/ f(["close"], ["update:open"]),
|
|
26
|
+
setup(d, { emit: f }) {
|
|
27
|
+
let j = f, M = i(d, "open"), N = _(), P = N.bootstrap.documents, F = P.types.filter((e) => e.canCreate), I = (P.locales?.locales ?? []).map((e) => ({
|
|
28
|
+
label: ge(e),
|
|
29
|
+
value: String(e)
|
|
30
|
+
})), L = t(""), R = t(!1), z = o(""), B = o(""), V = o(!1), H = o(""), U = o(A), W = o(P.locales?.defaultLocale ?? ""), G = s(() => {
|
|
31
|
+
let e = F.map((e) => ({
|
|
32
|
+
collection: e.collection,
|
|
33
|
+
description: e.description,
|
|
34
|
+
key: `entry:${e.collection}`,
|
|
35
|
+
kind: "entry",
|
|
36
|
+
label: e.label,
|
|
37
|
+
type: e,
|
|
38
|
+
urlHint: e.addressPattern.replace(/:[a-z][\w.]*\*?/giu, "…")
|
|
39
|
+
}));
|
|
40
|
+
return [...F.filter((e) => e.addressPattern === "/:path*").slice(0, 1).flatMap((e) => {
|
|
41
|
+
let t = C(P, {
|
|
42
|
+
collection: e.collection,
|
|
43
|
+
locale: W.value || void 0,
|
|
44
|
+
location: { kind: "home" },
|
|
45
|
+
title: "Home"
|
|
46
|
+
});
|
|
47
|
+
return b(t) || d.catalog.entries.value.some((e) => e.document.path === t.success.path) ? [] : [{
|
|
48
|
+
collection: e.collection,
|
|
49
|
+
description: "The first document visitors see when they open the website.",
|
|
50
|
+
key: `home:${e.collection}`,
|
|
51
|
+
kind: "home",
|
|
52
|
+
label: "Home",
|
|
53
|
+
type: e,
|
|
54
|
+
urlHint: t.success.path
|
|
55
|
+
}];
|
|
56
|
+
}), ...e];
|
|
57
|
+
}), K = s(() => G.value.find((e) => e.key === H.value)), q = s(() => K.value?.kind === "home" ? { kind: "home" } : U.value === A ? {
|
|
58
|
+
kind: "entry",
|
|
59
|
+
slug: B.value
|
|
60
|
+
} : {
|
|
61
|
+
kind: "entry",
|
|
62
|
+
parent: U.value,
|
|
63
|
+
slug: B.value
|
|
64
|
+
}), J = s(() => {
|
|
65
|
+
let e = K.value;
|
|
66
|
+
if (!e || e.kind === "entry" && !B.value.trim()) return;
|
|
67
|
+
let t = {
|
|
68
|
+
collection: e.collection,
|
|
69
|
+
location: q.value,
|
|
70
|
+
title: z.value || "Untitled"
|
|
71
|
+
};
|
|
72
|
+
return C(P, W.value ? {
|
|
73
|
+
...t,
|
|
74
|
+
locale: W.value
|
|
75
|
+
} : t);
|
|
76
|
+
}), Y = s(() => {
|
|
77
|
+
let e = J.value;
|
|
78
|
+
return e && x(e) ? e.success : void 0;
|
|
79
|
+
}), X = s(() => {
|
|
80
|
+
let e = J.value;
|
|
81
|
+
return e && b(e) ? e.failure : "";
|
|
82
|
+
}), Z = s(() => Y.value && d.catalog.entries.value.some((e) => e.document.path === Y.value?.path)), me = s(() => {
|
|
83
|
+
let e = K.value;
|
|
84
|
+
if (!e || e.kind === "home" || !e.type.hierarchy) return [];
|
|
85
|
+
let t = d.catalog.entries.value.flatMap((t) => {
|
|
86
|
+
if (t.document.collection !== e.collection || t.document.locale !== (W.value || void 0)) return [];
|
|
87
|
+
let n = S(e.type, t);
|
|
88
|
+
return n ? [{
|
|
89
|
+
label: `${t.document.title} · /${n}`,
|
|
90
|
+
value: n
|
|
91
|
+
}] : [];
|
|
92
|
+
});
|
|
93
|
+
return d.context?.parent && !t.some((e) => e.value === d.context.parent) && t.push({
|
|
94
|
+
label: `/${d.context.parent}`,
|
|
95
|
+
value: d.context.parent
|
|
96
|
+
}), [{
|
|
97
|
+
label: "Top level",
|
|
98
|
+
value: A
|
|
99
|
+
}, ...t];
|
|
100
|
+
}), Q = s(() => !!z.value.trim() && !!K.value && !!Y.value && !Z.value);
|
|
101
|
+
r(z, (e) => {
|
|
102
|
+
V.value || (B.value = se(e));
|
|
103
|
+
}), r(H, () => U.value = A, { flush: "sync" }), r(W, () => {
|
|
104
|
+
U.value = A, K.value || (H.value = $());
|
|
105
|
+
}, { flush: "sync" }), r(M, (e) => {
|
|
106
|
+
e && (L.value = "", z.value = "", B.value = "", V.value = !1, W.value = d.context?.locale ?? P.locales?.defaultLocale ?? "", H.value = d.context?.collection ? `entry:${d.context.collection}` : $(), U.value = d.context?.parent || A, d.context?.slug && (B.value = d.context.slug, V.value = !0));
|
|
107
|
+
}, { immediate: !0 });
|
|
108
|
+
async function he() {
|
|
109
|
+
let e = K.value;
|
|
110
|
+
if (Q.value && e && !R.value) {
|
|
111
|
+
R.value = !0, L.value = "";
|
|
112
|
+
try {
|
|
113
|
+
let t = {
|
|
114
|
+
collection: e.collection,
|
|
115
|
+
location: q.value,
|
|
116
|
+
title: z.value
|
|
117
|
+
}, n = await N.gateway.documents.create(W.value ? {
|
|
118
|
+
...t,
|
|
119
|
+
locale: W.value
|
|
120
|
+
} : t);
|
|
121
|
+
await d.catalog.refresh(!0);
|
|
122
|
+
let r = d.catalog.byId(n.documentId);
|
|
123
|
+
if (!r) throw Error("The page was created but could not be opened.");
|
|
124
|
+
j("close", r.document.id);
|
|
125
|
+
} catch (e) {
|
|
126
|
+
L.value = y(e);
|
|
127
|
+
} finally {
|
|
128
|
+
R.value = !1;
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
function $() {
|
|
133
|
+
return G.value[0]?.key ?? "";
|
|
134
|
+
}
|
|
135
|
+
function ge(e) {
|
|
136
|
+
try {
|
|
137
|
+
return new Intl.DisplayNames(void 0, { type: "language" }).of(e) ?? e.toLocaleUpperCase();
|
|
138
|
+
} catch {
|
|
139
|
+
return e.toLocaleUpperCase();
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
return (t, r) => {
|
|
143
|
+
let i = ie, o = oe, s = re, d = ae, f = w, _ = v;
|
|
144
|
+
return n(), e(_, {
|
|
145
|
+
open: M.value,
|
|
146
|
+
"onUpdate:open": r[6] ||= (e) => M.value = e,
|
|
147
|
+
title: "New page",
|
|
148
|
+
description: "Add a document to your website.",
|
|
149
|
+
ui: { content: "max-w-lg" }
|
|
150
|
+
}, {
|
|
151
|
+
body: g(() => [a("form", {
|
|
152
|
+
id: "create-document-form",
|
|
153
|
+
class: "space-y-4",
|
|
154
|
+
onSubmit: te(he, ["prevent"])
|
|
155
|
+
}, [
|
|
156
|
+
L.value ? (n(), e(i, {
|
|
157
|
+
key: 0,
|
|
158
|
+
description: L.value,
|
|
159
|
+
color: "error",
|
|
160
|
+
variant: "subtle"
|
|
161
|
+
}, null, 8, ["description"])) : l("", !0),
|
|
162
|
+
G.value.length ? G.value.length > 1 ? (n(), m("fieldset", ce, [
|
|
163
|
+
r[7] ||= a("legend", { class: "mb-2 text-sm font-medium text-highlighted" }, "Collection", -1),
|
|
164
|
+
a("div", T, [(n(!0), m(ee, null, ne(G.value, (e) => (n(), m("button", {
|
|
165
|
+
key: e.key,
|
|
166
|
+
type: "button",
|
|
167
|
+
title: e.description,
|
|
168
|
+
class: p(["min-w-28 border-l border-default px-3 py-2 text-center text-sm transition-colors first:border-l-0", e.key === H.value ? "bg-muted font-medium text-highlighted" : "bg-default text-muted hover:bg-muted/50 hover:text-highlighted"]),
|
|
169
|
+
onClick: (t) => H.value = e.key
|
|
170
|
+
}, [a("span", le, h(e.label), 1)], 10, E))), 128))]),
|
|
171
|
+
K.value ? (n(), m("div", ue, [a("span", D, h(K.value.description), 1), a("code", O, h(K.value.urlHint), 1)])) : l("", !0)
|
|
172
|
+
])) : l("", !0) : (n(), e(i, {
|
|
173
|
+
key: 1,
|
|
174
|
+
title: "Document creation is not configured",
|
|
175
|
+
description: "A developer needs to make at least one collection creatable in Studio.",
|
|
176
|
+
color: "warning",
|
|
177
|
+
variant: "subtle"
|
|
178
|
+
})),
|
|
179
|
+
K.value ? (n(), m("div", {
|
|
180
|
+
key: 3,
|
|
181
|
+
class: p(["grid gap-4", c(I).length ? "sm:grid-cols-[minmax(0,2fr)_minmax(9rem,1fr)]" : ""])
|
|
182
|
+
}, [u(s, {
|
|
183
|
+
label: "Title",
|
|
184
|
+
required: ""
|
|
185
|
+
}, {
|
|
186
|
+
default: g(() => [u(o, {
|
|
187
|
+
modelValue: z.value,
|
|
188
|
+
"onUpdate:modelValue": r[0] ||= (e) => z.value = e,
|
|
189
|
+
autofocus: "",
|
|
190
|
+
placeholder: "About us",
|
|
191
|
+
class: "w-full"
|
|
192
|
+
}, null, 8, ["modelValue"])]),
|
|
193
|
+
_: 1
|
|
194
|
+
}), c(I).length ? (n(), e(s, {
|
|
195
|
+
key: 0,
|
|
196
|
+
label: "Language"
|
|
197
|
+
}, {
|
|
198
|
+
default: g(() => [u(d, {
|
|
199
|
+
modelValue: W.value,
|
|
200
|
+
"onUpdate:modelValue": r[1] ||= (e) => W.value = e,
|
|
201
|
+
items: c(I),
|
|
202
|
+
"value-key": "value",
|
|
203
|
+
class: "w-full"
|
|
204
|
+
}, null, 8, ["modelValue", "items"])]),
|
|
205
|
+
_: 1
|
|
206
|
+
})) : l("", !0)], 2)) : l("", !0),
|
|
207
|
+
K.value?.kind === "entry" ? (n(), m("div", {
|
|
208
|
+
key: 4,
|
|
209
|
+
class: p(["grid gap-4", K.value.type.hierarchy ? "sm:grid-cols-2" : ""])
|
|
210
|
+
}, [K.value.type.hierarchy ? (n(), e(s, {
|
|
211
|
+
key: 0,
|
|
212
|
+
label: "Parent document"
|
|
213
|
+
}, {
|
|
214
|
+
default: g(() => [u(d, {
|
|
215
|
+
modelValue: U.value,
|
|
216
|
+
"onUpdate:modelValue": r[2] ||= (e) => U.value = e,
|
|
217
|
+
items: me.value,
|
|
218
|
+
"value-key": "value",
|
|
219
|
+
class: "w-full"
|
|
220
|
+
}, null, 8, ["modelValue", "items"])]),
|
|
221
|
+
_: 1
|
|
222
|
+
})) : l("", !0), u(s, {
|
|
223
|
+
label: "URL ending",
|
|
224
|
+
required: ""
|
|
225
|
+
}, {
|
|
226
|
+
default: g(() => [u(o, {
|
|
227
|
+
modelValue: B.value,
|
|
228
|
+
"onUpdate:modelValue": [r[3] ||= (e) => B.value = e, r[4] ||= (e) => V.value = !0],
|
|
229
|
+
placeholder: "about-us",
|
|
230
|
+
class: "w-full"
|
|
231
|
+
}, null, 8, ["modelValue"])]),
|
|
232
|
+
_: 1
|
|
233
|
+
})], 2)) : l("", !0),
|
|
234
|
+
K.value ? (n(), m("div", k, [r[8] ||= a("span", { class: "shrink-0 text-xs text-muted" }, "URL", -1), a("p", { class: p(["min-w-0 flex-1 truncate text-right font-mono text-xs", Z.value ? "text-error" : "text-highlighted"]) }, h(Y.value?.path || K.value.urlHint), 3)])) : l("", !0),
|
|
235
|
+
Z.value ? (n(), m("p", de, "This URL is already in use.")) : X.value ? (n(), m("p", fe, h(X.value), 1)) : l("", !0)
|
|
236
|
+
], 32)]),
|
|
237
|
+
footer: g(() => [a("div", pe, [u(f, {
|
|
238
|
+
color: "neutral",
|
|
239
|
+
variant: "ghost",
|
|
240
|
+
label: "Cancel",
|
|
241
|
+
onClick: r[5] ||= (e) => M.value = !1
|
|
242
|
+
}), u(f, {
|
|
243
|
+
type: "submit",
|
|
244
|
+
form: "create-document-form",
|
|
245
|
+
color: "neutral",
|
|
246
|
+
label: "Create page",
|
|
247
|
+
loading: R.value,
|
|
248
|
+
disabled: !Q.value
|
|
249
|
+
}, null, 8, ["loading", "disabled"])])]),
|
|
250
|
+
_: 1
|
|
251
|
+
}, 8, ["open"]);
|
|
252
|
+
};
|
|
253
|
+
}
|
|
254
|
+
});
|
|
255
|
+
//#endregion
|
|
256
|
+
export { j as default };
|