@phtngyn/cms 0.2.0-beta.1 → 0.2.0-beta.3
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/CHANGELOG.md +13 -0
- package/README.md +40 -45
- package/package.json +7 -5
- package/src/ApplicationTypes.d.ts +7 -5
- package/src/{Configuration-CjVUBBwa.js → Configuration-BU-UyGoH.js} +4 -4
- package/src/{Configuration-CjVUBBwa.js.map → Configuration-BU-UyGoH.js.map} +1 -1
- package/src/Configuration.d.ts +41 -24
- package/src/Configuration.js.map +1 -1
- package/src/Content.js +42 -19
- package/src/Content.js.map +1 -1
- package/src/{ContentTransfer-CTzGGKFV.js → ContentTransfer-BhF9G56s.js} +2 -2
- package/src/{ContentTransfer-CTzGGKFV.js.map → ContentTransfer-BhF9G56s.js.map} +1 -1
- package/src/{DocumentEngine-BbhfnTAc.js → DocumentEngine-ClhFXW9M.js} +4 -4
- package/src/{DocumentEngine-BbhfnTAc.js.map → DocumentEngine-ClhFXW9M.js.map} +1 -1
- package/src/DocumentModel.d.ts +6 -1
- package/src/DocumentModel.js +4 -3
- package/src/DocumentModel.js.map +1 -1
- package/src/{Forms-CfcI3tPU.js → Forms-BbkE7QfC.js} +47 -16
- package/src/Forms-BbkE7QfC.js.map +1 -0
- package/src/{Forms-02-p8qEw.js → Forms-DoB56hfe.js} +24 -7
- package/src/Forms-DoB56hfe.js.map +1 -0
- package/src/{Forms-BorTcIlp.d.ts → Forms-R0HoTR-o.d.ts} +30 -9
- package/src/Forms.d.ts +16 -15
- package/src/Forms.js.map +1 -1
- package/src/{I18n-BXlVunfa.d.ts → I18n-zbqpWxki.d.ts} +3 -1
- package/src/I18n.d.ts +1 -1
- package/src/Module.js +4 -2
- package/src/Module.js.map +1 -1
- package/src/{S3MediaObjects-DC0c8sYC.js → S3MediaObjects-CR3p1WTg.js} +21 -13
- package/src/S3MediaObjects-CR3p1WTg.js.map +1 -0
- package/src/cli.js +60 -34
- package/src/cli.js.map +1 -1
- package/src/{connection-BPf4BQUZ.js → connection-D5S9Iph-.js} +2 -2
- package/src/{connection-BPf4BQUZ.js.map → connection-D5S9Iph-.js.map} +1 -1
- package/src/{dev-lifecycle-vQLxwCFq.js → dev-lifecycle-D3f9-upa.js} +129 -42
- package/src/dev-lifecycle-D3f9-upa.js.map +1 -0
- package/src/{installation-DsGst1BH.js → installation-fZtNxtoW.js} +68 -41
- package/src/installation-fZtNxtoW.js.map +1 -0
- package/src/internal/authoring-catalog.js +2 -2
- package/src/internal/authoring-metadata.js +1 -1
- package/src/internal/configuration.js +149 -50
- package/src/internal/configuration.js.map +1 -1
- package/src/internal/dev-lifecycle.js +2 -2
- package/src/internal/diagnostics.js +47 -0
- package/src/internal/diagnostics.js.map +1 -0
- package/src/internal/document-model.js +2 -2
- package/src/internal/form-capabilities.js +1 -1
- package/src/internal/i18n.js +6 -1
- package/src/internal/i18n.js.map +1 -1
- package/src/internal/studio-app.js +8 -6
- package/src/internal/studio-app.js.map +1 -1
- package/src/{location-BgYhXEZp.js → location-CPX7oj0o.js} +2 -2
- package/src/{location-BgYhXEZp.js.map → location-CPX7oj0o.js.map} +1 -1
- package/src/{models-k2nXyD6q.js → models-C9kF9JlQ.js} +2 -2
- package/src/{models-k2nXyD6q.js.map → models-C9kF9JlQ.js.map} +1 -1
- package/src/{models-DgkGTFus.js → models-ChRxBChy.js} +4 -2
- package/src/{models-DgkGTFus.js.map → models-ChRxBChy.js.map} +1 -1
- package/src/runtime/delivery/context.js +1 -1
- package/src/runtime/delivery/plugin.js +3 -2
- package/src/runtime/delivery/plugin.js.map +1 -1
- package/src/runtime/forms/document.js +1 -1
- package/src/runtime/forms/useCmsForm.js +73 -46
- package/src/runtime/forms/useCmsForm.js.map +1 -1
- package/src/runtime/i18n/useCmsI18n.d.ts +1 -1
- package/src/runtime/i18n/useCmsI18n.js.map +1 -1
- package/src/runtime/installation.js +1 -1
- package/src/runtime/plugin.js +12 -4
- package/src/runtime/plugin.js.map +1 -1
- package/src/runtime/preview/connection.js +1 -1
- package/src/runtime/preview/controller.js +2 -2
- package/src/runtime/preview/plugin.client.js +3 -3
- package/src/runtime/preview/plugin.client.js.map +1 -1
- package/src/runtime/preview/store.js +1 -1
- package/src/runtime/sitemap.js +1 -1
- package/src/{store-BYgSt7E3.js → store-CCsjHaZm.js} +8 -8
- package/src/store-CCsjHaZm.js.map +1 -0
- package/studio/{CreateDocumentDialog-BdiM77bb.js → CreateDocumentDialog-DJ8c0WZb.js} +3 -3
- package/studio/{documentPlanning-B7fyUj9r.js → documentPlanning-CDb31mnl.js} +6417 -6358
- package/studio/host.css +1 -1
- package/studio/host.js +7612 -7249
- package/src/Forms-02-p8qEw.js.map +0 -1
- package/src/Forms-CfcI3tPU.js.map +0 -1
- package/src/S3MediaObjects-DC0c8sYC.js.map +0 -1
- package/src/dev-lifecycle-vQLxwCFq.js.map +0 -1
- package/src/installation-DsGst1BH.js.map +0 -1
- package/src/store-BYgSt7E3.js.map +0 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useCmsForm.js","names":[],"sources":["../../../../../src/runtime/forms/useCmsForm.ts"],"sourcesContent":["import type { MaybeRefOrGetter, Ref, ComputedRef, WritableComputedRef } from 'vue'\nimport type { FormDefinition, FormField, FormStep, FormSubmission, FormValues } from '@internal/protocol/Forms'\nimport { FormResult } from '@internal/protocol/Forms'\nimport { validateFormValues } from '@internal/document/Forms'\nimport { Result, Schema } from 'effect'\nimport {\n computed,\n getCurrentInstance,\n getCurrentScope,\n onScopeDispose,\n readonly,\n ref,\n shallowRef,\n toValue,\n useId,\n watch,\n} from 'vue'\nimport { CMS_FORM_SUBMIT_PATH } from '@internal/protocol/HttpPaths'\n\nexport interface UseCmsFormOptions {\n /** Replace the HTTP transport, retaining validation and submission state. */\n readonly submit?: (submission: FormSubmission, signal: AbortSignal) => Promise<FormResult>\n}\n\nexport interface CmsFormFieldController {\n readonly field: ComputedRef<FormField>\n readonly value: WritableComputedRef<FormValues[string]>\n readonly dirty: ComputedRef<boolean>\n readonly touched: ComputedRef<boolean>\n readonly valid: ComputedRef<boolean>\n readonly errors: ComputedRef<ReadonlyArray<string>>\n readonly controlAttrs: ComputedRef<{\n readonly id: string\n readonly name: string\n readonly required: boolean\n readonly 'aria-invalid': 'true' | undefined\n readonly 'aria-describedby': string | undefined\n }>\n readonly helpAttrs: { readonly id: string }\n readonly errorAttrs: { readonly id: string; readonly role: 'alert' }\n readonly touch: () => void\n}\n\nexport interface UseCmsFormReturn {\n readonly fields: ComputedRef<ReadonlyArray<FormField>>\n readonly steps: ComputedRef<ReadonlyArray<FormStep>>\n readonly values: Ref<Record<string, FormValues[string]>>\n readonly errors: Readonly<Ref<Readonly<Record<string, string>>>>\n readonly currentStep: ComputedRef<FormStep | undefined>\n readonly stepIndex: Readonly<Ref<number>>\n readonly isFirstStep: ComputedRef<boolean>\n readonly isLastStep: ComputedRef<boolean>\n readonly submitting: Readonly<Ref<boolean>>\n readonly isSuccess: Readonly<Ref<boolean>>\n readonly isPreview: ComputedRef<boolean>\n readonly submitError: Readonly<Ref<string | undefined>>\n readonly canSubmit: ComputedRef<boolean>\n readonly invalidFields: ComputedRef<ReadonlyArray<CmsFormFieldController>>\n readonly firstInvalidFieldId: ComputedRef<string | undefined>\n readonly field: (field: string | FormField) => CmsFormFieldController\n readonly next: () => boolean\n readonly previous: () => void\n readonly validate: () => boolean\n readonly submit: () => Promise<boolean>\n readonly reset: () => void\n}\n\n/** Headless, per-instance form state. Definition changes preserve answers for unchanged field types. */\nexport function useCmsForm(input: MaybeRefOrGetter<FormDefinition>, options: UseCmsFormOptions = {}): UseCmsFormReturn {\n const fieldIdPrefix = getCurrentInstance() ? useId() : 'cms-form'\n const definition = computed(() => toValue(input))\n const steps = computed(() => definition.value.steps)\n const fields = computed(() => steps.value.flatMap((step) => step.fields))\n const values = ref<Record<string, FormValues[string]>>({})\n const errors = shallowRef<Record<string, string>>({})\n const stepIndex = ref(0)\n const currentStep = computed(() => steps.value[stepIndex.value])\n const isFirstStep = computed(() => stepIndex.value === 0)\n const isLastStep = computed(() => stepIndex.value === steps.value.length - 1)\n const submitting = ref(false)\n const isSuccess = ref(false)\n const isPreview = computed(() => definition.value.preview)\n const submitError = shallowRef<string>()\n const touched = ref(new Set<string>())\n const controllers = new Map<string, CmsFormFieldController>()\n let controller: AbortController | undefined\n let generation = 0\n let previousFields = new Map<string, string>()\n\n const stop = watch(\n definition,\n (next, before) => {\n generation++\n controller?.abort()\n submitting.value = false\n\n const sameForm =\n before?.documentId === next.documentId &&\n JSON.stringify(before.nodePath) === JSON.stringify(next.nodePath) &&\n before.name === next.name\n\n values.value = Object.fromEntries(\n next.steps\n .flatMap((step) => step.fields)\n .map((field) => [\n field.id,\n sameForm && previousFields.get(field.id) === field.type\n ? (values.value[field.id] ?? null)\n : field.type === 'checkbox'\n ? false\n : field.type === 'number'\n ? null\n : '',\n ]),\n )\n previousFields = new Map(next.steps.flatMap((step) => step.fields).map((field) => [field.id, field.type]))\n stepIndex.value = Math.max(\n 0,\n next.steps.findIndex((step) => step.id === before?.steps[stepIndex.value]?.id),\n )\n errors.value = {}\n touched.value = new Set()\n submitError.value = undefined\n isSuccess.value = false\n },\n { immediate: true, deep: true, flush: 'sync' },\n )\n\n function validate(): boolean {\n touched.value = new Set(fields.value.map((field) => field.id))\n errors.value = validateFormValues(fields.value, values.value)\n\n return Object.keys(errors.value).length === 0\n }\n\n function field(input: string | FormField): CmsFormFieldController {\n const fieldId = Schema.is(Schema.String)(input) ? input : input.id\n const existing = controllers.get(fieldId)\n\n if (existing) return existing\n\n if (!fields.value.some((candidate) => candidate.id === fieldId))\n throw new Error(`Unknown CMS form field ${fieldId}.`)\n\n const current = computed(() => {\n const candidate = fields.value.find((field) => field.id === fieldId)\n\n if (!candidate) throw new Error(`CMS form field ${fieldId} no longer exists.`)\n\n return candidate\n })\n\n const controlId = `${fieldIdPrefix}-${encodeURIComponent(fieldId)}`\n const helpId = `${controlId}-help`\n const errorId = `${controlId}-error`\n\n const refreshError = () => {\n const issue = validateFormValues([current.value], values.value)[fieldId]\n const nextErrors = { ...errors.value }\n\n if (issue) nextErrors[fieldId] = issue\n else delete nextErrors[fieldId]\n errors.value = nextErrors\n }\n\n const controller: CmsFormFieldController = {\n field: current,\n value: computed({\n get: () => values.value[fieldId] ?? emptyFormValue(current.value),\n set: (value) => {\n values.value[fieldId] = normalizeFormValue(current.value, value)\n\n if (touched.value.has(fieldId) || errors.value[fieldId]) refreshError()\n },\n }),\n dirty: computed(() => values.value[fieldId] !== emptyFormValue(current.value)),\n touched: computed(() => touched.value.has(fieldId)),\n valid: computed(() => validateFormValues([current.value], values.value)[fieldId] === undefined),\n errors: computed(() => (errors.value[fieldId] ? [errors.value[fieldId]] : [])),\n controlAttrs: computed(() => {\n const fieldError = errors.value[fieldId]\n\n const describedBy = [current.value.help ? helpId : undefined, fieldError ? errorId : undefined]\n .filter((part) => part !== undefined)\n .join(' ')\n\n return {\n id: controlId,\n name: fieldId,\n required: current.value.required === true,\n 'aria-invalid': fieldError ? 'true' : undefined,\n 'aria-describedby': describedBy || undefined,\n }\n }),\n helpAttrs: { id: helpId },\n errorAttrs: { id: errorId, role: 'alert' },\n touch: () => {\n touched.value = new Set([...touched.value, fieldId])\n refreshError()\n },\n }\n\n controllers.set(fieldId, controller)\n\n return controller\n }\n\n function next(): boolean {\n if (submitting.value || isLastStep.value) return false\n const stepFields = currentStep.value?.fields ?? []\n touched.value = new Set([...touched.value, ...stepFields.map((field) => field.id)])\n const issues = validateFormValues(stepFields, values.value)\n errors.value = {\n ...Object.fromEntries(\n Object.entries(errors.value).filter(([id]) => !stepFields.some((field) => field.id === id)),\n ),\n ...issues,\n }\n\n if (Object.keys(issues).length) return false\n stepIndex.value++\n\n return true\n }\n\n function previous(): void {\n if (!submitting.value && !isFirstStep.value) stepIndex.value--\n }\n\n function reset(): void {\n generation++\n controller?.abort()\n submitting.value = false\n values.value = Object.fromEntries(fields.value.map((field) => [field.id, emptyFormValue(field)]))\n errors.value = {}\n touched.value = new Set()\n submitError.value = undefined\n isSuccess.value = false\n stepIndex.value = 0\n }\n\n async function submit(): Promise<boolean> {\n if (submitting.value || isSuccess.value) return false\n submitError.value = undefined\n\n if (!validate()) {\n stepIndex.value = Math.max(\n 0,\n steps.value.findIndex((step) => step.fields.some((field) => errors.value[field.id])),\n )\n\n return false\n }\n\n if (isPreview.value) {\n isSuccess.value = true\n\n return true\n }\n\n const currentGeneration = ++generation\n controller = new AbortController()\n submitting.value = true\n\n try {\n const { documentId, nodePath, revision } = definition.value\n\n const result = await (options.submit ?? send)(\n { documentId, nodePath, revision, values: { ...values.value } },\n controller.signal,\n )\n\n if (generation !== currentGeneration) return false\n errors.value = { ...result.errors }\n isSuccess.value = result.status === 'accepted'\n\n if (result.status === 'invalid')\n stepIndex.value = Math.max(\n 0,\n steps.value.findIndex((step) => step.fields.some((field) => errors.value[field.id])),\n )\n\n if (result.status !== 'accepted' && result.status !== 'invalid')\n submitError.value =\n result.status === 'stale'\n ? 'This form has changed. Reload the page before submitting.'\n : 'Submission failed. Please try again.'\n\n return isSuccess.value\n } catch {\n if (generation === currentGeneration) submitError.value = 'Submission failed. Please try again.'\n\n return false\n } finally {\n if (generation === currentGeneration) submitting.value = false\n }\n }\n\n if (getCurrentScope())\n onScopeDispose(() => {\n generation++\n controller?.abort()\n stop()\n })\n\n const invalidFields = computed(() => fields.value.map((entry) => field(entry)).filter((entry) => !entry.valid.value))\n const firstInvalidFieldId = computed(() => invalidFields.value[0]?.controlAttrs.value.id)\n const canSubmit = computed(() => !submitting.value && !isSuccess.value && invalidFields.value.length === 0)\n\n return {\n fields,\n steps,\n values,\n errors: readonly(errors),\n currentStep,\n stepIndex: readonly(stepIndex),\n isFirstStep,\n isLastStep,\n submitting: readonly(submitting),\n isSuccess: readonly(isSuccess),\n isPreview,\n submitError: readonly(submitError),\n canSubmit,\n invalidFields,\n firstInvalidFieldId,\n field,\n next,\n previous,\n validate,\n submit,\n reset,\n }\n}\n\nfunction normalizeFormValue(field: FormField, input: FormValues[string] | undefined): FormValues[string] {\n if (field.type === 'checkbox') return input === true\n\n if (field.type === 'number') {\n if (input === '' || input == null) return null\n const value = Schema.is(Schema.Finite)(input) || Schema.is(Schema.String)(input) ? Number(input) : Number.NaN\n\n if (Number.isFinite(value)) return value\n\n return Schema.is(Schema.String)(input) ? input : null\n }\n\n return Schema.is(Schema.String)(input) ? input : ''\n}\n\nfunction emptyFormValue(field: FormField): FormValues[string] {\n if (field.type === 'checkbox') return false\n\n if (field.type === 'number') return null\n\n return ''\n}\n\nasync function send(submission: FormSubmission, signal: AbortSignal): Promise<FormResult> {\n const response = await fetch(CMS_FORM_SUBMIT_PATH, {\n method: 'POST',\n headers: { 'content-type': 'application/json' },\n body: JSON.stringify(submission),\n signal,\n })\n\n if (!response.ok) throw new Error('Submission failed.')\n\n return Result.getOrThrow(Schema.decodeUnknownResult(FormResult)(await response.json()))\n}\n"],"mappings":";;;;;;;;AAoEA,SAAgB,WAAW,OAAyC,UAA6B,CAAC,GAAqB;CACrH,MAAM,gBAAgB,mBAAmB,IAAI,MAAM,IAAI;CACvD,MAAM,aAAa,eAAe,QAAQ,KAAK,CAAC;CAChD,MAAM,QAAQ,eAAe,WAAW,MAAM,KAAK;CACnD,MAAM,SAAS,eAAe,MAAM,MAAM,SAAS,SAAS,KAAK,MAAM,CAAC;CACxE,MAAM,SAAS,IAAwC,CAAC,CAAC;CACzD,MAAM,SAAS,WAAmC,CAAC,CAAC;CACpD,MAAM,YAAY,IAAI,CAAC;CACvB,MAAM,cAAc,eAAe,MAAM,MAAM,UAAU,MAAM;CAC/D,MAAM,cAAc,eAAe,UAAU,UAAU,CAAC;CACxD,MAAM,aAAa,eAAe,UAAU,UAAU,MAAM,MAAM,SAAS,CAAC;CAC5E,MAAM,aAAa,IAAI,KAAK;CAC5B,MAAM,YAAY,IAAI,KAAK;CAC3B,MAAM,YAAY,eAAe,WAAW,MAAM,OAAO;CACzD,MAAM,cAAc,WAAmB;CACv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AAe,KAAK,YAA4B,QAA0C;CACxF,MAAM,WAAW,MAAM,MAAM,sBAAsB;EACjD,QAAQ;EACR,SAAS,EAAE,gBAAgB,mBAAmB;EAC9C,MAAM,KAAK,UAAU,UAAU;EAC/B;CACF,CAAC;CAED,IAAI,CAAC,SAAS,IAAI,MAAM,IAAI,MAAM,oBAAoB;CAEtD,OAAO,OAAO,WAAW,OAAO,oBAAoB,UAAU,CAAC,CAAC,MAAM,SAAS,KAAK,CAAC,CAAC;AACxF"}
|
|
1
|
+
{"version":3,"file":"useCmsForm.js","names":[],"sources":["../../../../../src/runtime/forms/useCmsForm.ts"],"sourcesContent":["import type { MaybeRefOrGetter, Ref, ComputedRef } from 'vue'\nimport type { FormDefinition, FormField, FormStep, FormSubmission, FormValues } from '@internal/protocol/Forms'\nimport { FormResult } from '@internal/protocol/Forms'\nimport { validateFormValues } from '@internal/document/Forms'\nimport { Result, Schema } from 'effect'\nimport {\n computed,\n getCurrentInstance,\n getCurrentScope,\n onScopeDispose,\n readonly,\n ref,\n shallowRef,\n toValue,\n useId,\n watch,\n} from 'vue'\nimport { CMS_FORM_SUBMIT_PATH } from '@internal/protocol/HttpPaths'\n\nexport interface UseCmsFormOptions {\n /** Replace the HTTP transport, retaining validation and submission state. */\n readonly submit?: (submission: FormSubmission, signal: AbortSignal) => Promise<FormResult>\n}\n\nexport interface CmsFormControl {\n readonly field: FormField\n value: FormValues[string]\n readonly dirty: boolean\n readonly touched: boolean\n readonly valid: boolean\n readonly error: string | undefined\n readonly attrs: {\n readonly id: string\n readonly name: string\n readonly required: boolean\n readonly 'aria-invalid': 'true' | undefined\n readonly 'aria-describedby': string | undefined\n }\n readonly helpAttrs: { readonly id: string }\n readonly errorAttrs: { readonly id: string; readonly role: 'alert' }\n readonly touch: () => void\n}\n\nexport interface UseCmsFormReturn {\n readonly fields: ComputedRef<ReadonlyArray<FormField>>\n readonly steps: ComputedRef<ReadonlyArray<FormStep>>\n readonly values: Ref<Record<string, FormValues[string]>>\n readonly errors: Readonly<Ref<Readonly<Record<string, string>>>>\n readonly currentStep: ComputedRef<FormStep | undefined>\n readonly stepIndex: Readonly<Ref<number>>\n readonly isFirstStep: ComputedRef<boolean>\n readonly isLastStep: ComputedRef<boolean>\n readonly submitting: Readonly<Ref<boolean>>\n readonly isSuccess: Readonly<Ref<boolean>>\n readonly isPreview: ComputedRef<boolean>\n readonly submitError: Readonly<Ref<string | undefined>>\n readonly canSubmit: ComputedRef<boolean>\n readonly visibleControls: ComputedRef<ReadonlyArray<CmsFormControl>>\n readonly invalidControls: ComputedRef<ReadonlyArray<CmsFormControl>>\n readonly firstInvalidControlId: ComputedRef<string | undefined>\n readonly control: (field: string | FormField) => CmsFormControl\n readonly next: () => boolean\n readonly previous: () => void\n readonly validate: () => boolean\n readonly submit: () => Promise<boolean>\n readonly reset: () => void\n}\n\n/** Headless, per-instance form state. Definition changes preserve answers for unchanged field types. */\nexport function useCmsForm(input: MaybeRefOrGetter<FormDefinition>, options: UseCmsFormOptions = {}): UseCmsFormReturn {\n const fieldIdPrefix = getCurrentInstance() ? useId() : 'cms-form'\n const definition = computed(() => toValue(input))\n const steps = computed(() => definition.value.steps)\n const fields = computed(() => steps.value.flatMap((step) => step.fields))\n const values = ref<Record<string, FormValues[string]>>({})\n const errors = shallowRef<Record<string, string>>({})\n const stepIndex = shallowRef(0)\n const currentStep = computed(() => steps.value[stepIndex.value])\n const isFirstStep = computed(() => stepIndex.value === 0)\n const isLastStep = computed(() => stepIndex.value === steps.value.length - 1)\n const submitting = shallowRef(false)\n const isSuccess = shallowRef(false)\n const isPreview = computed(() => definition.value.preview)\n const submitError = shallowRef<string>()\n const touched = shallowRef(new Set<string>())\n const controls = new Map<string, CmsFormControl>()\n let controller: AbortController | undefined\n let generation = 0\n let previousFields = new Map<string, string>()\n\n const stop = watch(\n definition,\n (next, before) => {\n generation++\n controller?.abort()\n submitting.value = false\n\n const sameForm =\n before?.documentId === next.documentId &&\n JSON.stringify(before.nodePath) === JSON.stringify(next.nodePath) &&\n before.name === next.name\n\n values.value = Object.fromEntries(\n next.steps\n .flatMap((step) => step.fields)\n .map((field) => [\n field.id,\n sameForm && previousFields.get(field.id) === field.type\n ? (values.value[field.id] ?? null)\n : field.type === 'checkbox'\n ? false\n : field.type === 'number'\n ? null\n : '',\n ]),\n )\n previousFields = new Map(next.steps.flatMap((step) => step.fields).map((field) => [field.id, field.type]))\n stepIndex.value = Math.max(\n 0,\n next.steps.findIndex((step) => step.id === before?.steps[stepIndex.value]?.id),\n )\n errors.value = {}\n touched.value = new Set()\n submitError.value = undefined\n isSuccess.value = false\n },\n { immediate: true, deep: true, flush: 'sync' },\n )\n\n function validate(): boolean {\n touched.value = new Set(fields.value.map((field) => field.id))\n errors.value = validateFormValues(fields.value, values.value)\n\n return Object.keys(errors.value).length === 0\n }\n\n function control(input: string | FormField): CmsFormControl {\n const fieldId = Schema.is(Schema.String)(input) ? input : input.id\n const existing = controls.get(fieldId)\n\n if (existing) return existing\n\n if (!fields.value.some((candidate) => candidate.id === fieldId))\n throw new Error(`Unknown CMS form field ${fieldId}.`)\n\n const current = computed(() => {\n const candidate = fields.value.find((field) => field.id === fieldId)\n\n if (!candidate) throw new Error(`CMS form field ${fieldId} no longer exists.`)\n\n return candidate\n })\n\n const controlId = `${fieldIdPrefix}-${encodeURIComponent(fieldId)}`\n const helpId = `${controlId}-help`\n const errorId = `${controlId}-error`\n const helpAttrs: CmsFormControl['helpAttrs'] = { id: helpId }\n const errorAttrs: CmsFormControl['errorAttrs'] = { id: errorId, role: 'alert' }\n\n const refreshError = () => {\n const issue = validateFormValues([current.value], values.value)[fieldId]\n const nextErrors = { ...errors.value }\n\n if (issue) nextErrors[fieldId] = issue\n else delete nextErrors[fieldId]\n errors.value = nextErrors\n }\n\n const value = computed({\n get: () => values.value[fieldId] ?? emptyFormValue(current.value),\n set: (next) => {\n values.value[fieldId] = normalizeFormValue(current.value, next)\n\n if (touched.value.has(fieldId) || errors.value[fieldId]) refreshError()\n },\n })\n\n const dirty = computed(() => values.value[fieldId] !== emptyFormValue(current.value))\n\n const touchedState = computed(() => touched.value.has(fieldId))\n\n const valid = computed(() => validateFormValues([current.value], values.value)[fieldId] === undefined)\n\n const error = computed(() => errors.value[fieldId])\n\n const attrs = computed<CmsFormControl['attrs']>(() => {\n const fieldError = errors.value[fieldId]\n\n const describedBy = [current.value.help ? helpId : undefined, fieldError ? errorId : undefined]\n .filter((part) => part !== undefined)\n .join(' ')\n\n return {\n id: controlId,\n name: fieldId,\n required: current.value.required === true,\n 'aria-invalid': fieldError ? 'true' : undefined,\n 'aria-describedby': describedBy || undefined,\n }\n })\n\n const state: CmsFormControl = {\n get field() {\n return current.value\n },\n get value() {\n return value.value\n },\n set value(next) {\n value.value = next\n },\n get dirty() {\n return dirty.value\n },\n get touched() {\n return touchedState.value\n },\n get valid() {\n return valid.value\n },\n get error() {\n return error.value\n },\n get attrs() {\n return attrs.value\n },\n helpAttrs,\n errorAttrs,\n touch: () => {\n touched.value = new Set([...touched.value, fieldId])\n refreshError()\n },\n }\n\n controls.set(fieldId, state)\n\n return state\n }\n\n function next(): boolean {\n if (submitting.value || isLastStep.value) return false\n const stepFields = currentStep.value?.fields ?? []\n touched.value = new Set([...touched.value, ...stepFields.map((field) => field.id)])\n const issues = validateFormValues(stepFields, values.value)\n errors.value = {\n ...Object.fromEntries(\n Object.entries(errors.value).filter(([id]) => !stepFields.some((field) => field.id === id)),\n ),\n ...issues,\n }\n\n if (Object.keys(issues).length) return false\n stepIndex.value++\n\n return true\n }\n\n function previous(): void {\n if (!submitting.value && !isFirstStep.value) stepIndex.value--\n }\n\n function reset(): void {\n generation++\n controller?.abort()\n submitting.value = false\n values.value = Object.fromEntries(fields.value.map((field) => [field.id, emptyFormValue(field)]))\n errors.value = {}\n touched.value = new Set()\n submitError.value = undefined\n isSuccess.value = false\n stepIndex.value = 0\n }\n\n // oxlint-disable-next-line effecttsgo/async-function -- This Vue composable exposes a Promise to component submit handlers.\n async function submit(): Promise<boolean> {\n if (submitting.value || isSuccess.value) return false\n submitError.value = undefined\n\n if (!validate()) {\n stepIndex.value = Math.max(\n 0,\n steps.value.findIndex((step) => step.fields.some((field) => errors.value[field.id])),\n )\n\n return false\n }\n\n if (isPreview.value) {\n isSuccess.value = true\n\n return true\n }\n\n const currentGeneration = ++generation\n controller = new AbortController()\n submitting.value = true\n\n try {\n const { documentId, nodePath, revision } = definition.value\n\n const result = await (options.submit ?? send)(\n { documentId, nodePath, revision, values: { ...values.value } },\n controller.signal,\n )\n\n if (generation !== currentGeneration) return false\n errors.value = result.status === 'invalid' ? { ...result.errors } : {}\n isSuccess.value = result.status === 'accepted'\n\n if (result.status === 'invalid')\n stepIndex.value = Math.max(\n 0,\n steps.value.findIndex((step) => step.fields.some((field) => errors.value[field.id])),\n )\n\n if (result.status !== 'accepted' && result.status !== 'invalid')\n submitError.value =\n result.status === 'stale'\n ? 'This form has changed. Reload the page before submitting.'\n : 'Submission failed. Please try again.'\n\n return isSuccess.value\n } catch {\n if (generation === currentGeneration) submitError.value = 'Submission failed. Please try again.'\n\n return false\n } finally {\n if (generation === currentGeneration) submitting.value = false\n }\n }\n\n if (getCurrentScope())\n onScopeDispose(() => {\n generation++\n controller?.abort()\n stop()\n })\n\n const visibleControls = computed(() => currentStep.value?.fields.map((entry) => control(entry)) ?? [])\n const invalidControls = computed(() => fields.value.map((entry) => control(entry)).filter((entry) => !entry.valid))\n const firstInvalidControlId = computed(() => invalidControls.value[0]?.attrs.id)\n const canSubmit = computed(() => !submitting.value && !isSuccess.value && invalidControls.value.length === 0)\n\n return {\n fields,\n steps,\n values,\n errors: readonly(errors),\n currentStep,\n stepIndex: readonly(stepIndex),\n isFirstStep,\n isLastStep,\n submitting: readonly(submitting),\n isSuccess: readonly(isSuccess),\n isPreview,\n submitError: readonly(submitError),\n canSubmit,\n visibleControls,\n invalidControls,\n firstInvalidControlId,\n control,\n next,\n previous,\n validate,\n submit,\n reset,\n }\n}\n\nfunction normalizeFormValue(field: FormField, input: FormValues[string] | undefined): FormValues[string] {\n if (field.type === 'checkbox') return input === true\n\n if (field.type === 'number') {\n if (input === '' || input == null) return null\n const value = Schema.is(Schema.Finite)(input) || Schema.is(Schema.String)(input) ? Number(input) : Number.NaN\n\n if (Number.isFinite(value)) return value\n\n return Schema.is(Schema.String)(input) ? input : null\n }\n\n return Schema.is(Schema.String)(input) ? input : ''\n}\n\nfunction emptyFormValue(field: FormField): FormValues[string] {\n if (field.type === 'checkbox') return false\n\n if (field.type === 'number') return null\n\n return ''\n}\n\n// oxlint-disable-next-line effecttsgo/async-function -- This browser transport implements the composable's Promise-based submission seam.\nasync function send(submission: FormSubmission, signal: AbortSignal): Promise<FormResult> {\n // oxlint-disable-next-line effecttsgo/global-fetch -- Visitor form submission is a small browser transport that must preserve the caller's AbortSignal.\n const response = await fetch(CMS_FORM_SUBMIT_PATH, {\n method: 'POST',\n headers: { 'content-type': 'application/json' },\n body: JSON.stringify(submission),\n signal,\n })\n\n if (!response.ok) throw new Error('Submission failed.')\n\n return Result.getOrThrow(Schema.decodeUnknownResult(FormResult)(await response.json()))\n}\n"],"mappings":";;;;;;;;AAqEA,SAAgB,WAAW,OAAyC,UAA6B,CAAC,GAAqB;CACrH,MAAM,gBAAgB,mBAAmB,IAAI,MAAM,IAAI;CACvD,MAAM,aAAa,eAAe,QAAQ,KAAK,CAAC;CAChD,MAAM,QAAQ,eAAe,WAAW,MAAM,KAAK;CACnD,MAAM,SAAS,eAAe,MAAM,MAAM,SAAS,SAAS,KAAK,MAAM,CAAC;CACxE,MAAM,SAAS,IAAwC,CAAC,CAAC;CACzD,MAAM,SAAS,WAAmC,CAAC,CAAC;CACpD,MAAM,YAAY,WAAW,CAAC;CAC9B,MAAM,cAAc,eAAe,MAAM,MAAM,UAAU,MAAM;CAC/D,MAAM,cAAc,eAAe,UAAU,UAAU,CAAC;CACxD,MAAM,aAAa,eAAe,UAAU,UAAU,MAAM,MAAM,SAAS,CAAC;CAC5E,MAAM,aAAa,WAAW,KAAK;C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;CACvG,IAAI,MAAM,SAAS,YAAY,OAAO,UAAU;CAEhD,IAAI,MAAM,SAAS,UAAU;EAC3B,IAAI,UAAU,MAAM,SAAS,MAAM,OAAO;EAC1C,MAAM,QAAQ,OAAO,GAAG,OAAO,MAAM,CAAC,CAAC,KAAK,KAAK,OAAO,GAAG,OAAO,MAAM,CAAC,CAAC,KAAK,IAAI,OAAO,KAAK,IAAI;EAEnG,IAAI,OAAO,SAAS,KAAK,GAAG,OAAO;EAEnC,OAAO,OAAO,GAAG,OAAO,MAAM,CAAC,CAAC,KAAK,IAAI,QAAQ;CACnD;CAEA,OAAO,OAAO,GAAG,OAAO,MAAM,CAAC,CAAC,KAAK,IAAI,QAAQ;AACnD;AAEA,SAAS,eAAe,OAAsC;CAC5D,IAAI,MAAM,SAAS,YAAY,OAAO;CAEtC,IAAI,MAAM,SAAS,UAAU,OAAO;CAEpC,OAAO;AACT;AAGA,eAAe,KAAK,YAA4B,QAA0C;CAExF,MAAM,WAAW,MAAM,MAAM,sBAAsB;EACjD,QAAQ;EACR,SAAS,EAAE,gBAAgB,mBAAmB;EAC9C,MAAM,KAAK,UAAU,UAAU;EAC/B;CACF,CAAC;CAED,IAAI,CAAC,SAAS,IAAI,MAAM,IAAI,MAAM,oBAAoB;CAEtD,OAAO,OAAO,WAAW,OAAO,oBAAoB,UAAU,CAAC,CAAC,MAAM,SAAS,KAAK,CAAC,CAAC;AACxF"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { a as CmsMessageParameters, i as CmsMessageKey, r as CmsLocale } from "../../I18n-
|
|
1
|
+
import { a as CmsMessageParameters, i as CmsMessageKey, r as CmsLocale } from "../../I18n-zbqpWxki.js";
|
|
2
2
|
import { ComputedRef } from "vue";
|
|
3
3
|
//#region src/runtime/i18n/useCmsI18n.d.ts
|
|
4
4
|
export interface UseCmsI18nReturn {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useCmsI18n.js","names":["localePath","resolveLocalePath","switchLocalePath","resolveSwitchLocalePath"],"sources":["../../../../../src/runtime/i18n/useCmsI18n.ts"],"sourcesContent":["import configuration from '#cms/i18n'\nimport { useRoute, useState } from 'nuxt/app'\nimport { computed, type ComputedRef } from 'vue'\nimport type { CmsLocale, CmsMessageKey, CmsMessageParameters } from '../../I18n'\nimport {\n localeFromPath,\n localePath as resolveLocalePath,\n switchLocalePath as resolveSwitchLocalePath,\n translate,\n} from './translator'\n\nexport interface UseCmsI18nReturn {\n readonly locale: ComputedRef<CmsLocale>\n readonly localePath: (path: string, code?: CmsLocale) => string\n readonly switchLocalePath: (code: CmsLocale, destination?: string) => string\n readonly t: <Key extends CmsMessageKey>(\n key: Key,\n ...arguments_: keyof CmsMessageParameters<Key> extends never\n ? [parameters?: undefined]\n : [parameters: CmsMessageParameters<Key>]\n ) => string\n}\n\n/** URL-owned locale is reactive and isolated to the current Nuxt application/request. */\nexport function useCmsI18n(): UseCmsI18nReturn {\n const route = useRoute()\n const documentLocale = useState<string | undefined>('cms-document-locale', () => undefined)\n\n // SAFETY: compileCmsI18n generated CmsLocale from these exact runtime locale keys.\n const locale = computed<CmsLocale>(\n () => (documentLocale.value ?? localeFromPath(configuration, route.path)) as CmsLocale,\n )\n\n const warned = new Set<string>()\n\n function missing(key: string, code: string): void {\n const id = `${code}:${key}`\n\n if (!import.meta.dev || warned.has(id)) return\n warned.add(id)\n // Browser diagnostics should not add an Effect runtime to the website translation bundle.\n
|
|
1
|
+
{"version":3,"file":"useCmsI18n.js","names":["localePath","resolveLocalePath","switchLocalePath","resolveSwitchLocalePath"],"sources":["../../../../../src/runtime/i18n/useCmsI18n.ts"],"sourcesContent":["import configuration from '#cms/i18n'\nimport { useRoute, useState } from 'nuxt/app'\nimport { computed, type ComputedRef } from 'vue'\nimport type { CmsLocale, CmsMessageKey, CmsMessageParameters } from '../../I18n'\nimport {\n localeFromPath,\n localePath as resolveLocalePath,\n switchLocalePath as resolveSwitchLocalePath,\n translate,\n} from './translator'\n\nexport interface UseCmsI18nReturn {\n readonly locale: ComputedRef<CmsLocale>\n readonly localePath: (path: string, code?: CmsLocale) => string\n readonly switchLocalePath: (code: CmsLocale, destination?: string) => string\n readonly t: <Key extends CmsMessageKey>(\n key: Key,\n ...arguments_: keyof CmsMessageParameters<Key> extends never\n ? [parameters?: undefined]\n : [parameters: CmsMessageParameters<Key>]\n ) => string\n}\n\n/** URL-owned locale is reactive and isolated to the current Nuxt application/request. */\nexport function useCmsI18n(): UseCmsI18nReturn {\n const route = useRoute()\n const documentLocale = useState<string | undefined>('cms-document-locale', () => undefined)\n\n // SAFETY: compileCmsI18n generated CmsLocale from these exact runtime locale keys.\n const locale = computed<CmsLocale>(\n () => (documentLocale.value ?? localeFromPath(configuration, route.path)) as CmsLocale,\n )\n\n const warned = new Set<string>()\n\n function missing(key: string, code: string): void {\n const id = `${code}:${key}`\n\n if (!import.meta.dev || warned.has(id)) return\n warned.add(id)\n // oxlint-disable-next-line effecttsgo/global-console -- Browser diagnostics should not add an Effect runtime to the website translation bundle.\n console.warn(`[cms i18n] Missing message \"${key}\" for locale \"${code}\".`)\n }\n\n function t<Key extends CmsMessageKey>(\n key: Key,\n ...arguments_: keyof CmsMessageParameters<Key> extends never\n ? [parameters?: undefined]\n : [parameters: CmsMessageParameters<Key>]\n ): string {\n return translate(configuration, locale.value, key, arguments_[0], missing)\n }\n\n function localePath(path: string, code: CmsLocale = locale.value): string {\n return resolveLocalePath(configuration, path, code)\n }\n\n function switchLocalePath(code: CmsLocale, destination?: string): string {\n return destination === undefined\n ? resolveSwitchLocalePath(configuration, route.fullPath, code)\n : resolveLocalePath(configuration, destination, code)\n }\n\n return { locale, localePath, switchLocalePath, t }\n}\n"],"mappings":";;;;;;;AAwBA,SAAgB,aAA+B;CAC7C,MAAM,QAAQ,SAAS;CACvB,MAAM,iBAAiB,SAA6B,6BAA6B,MAAS;CAG1F,MAAM,SAAS,eACN,eAAe,SAAS,eAAe,eAAe,MAAM,IAAI,CACzE;CAEA,MAAM,yBAAS,IAAI,IAAY;CAE/B,SAAS,QAAQ,KAAa,MAAoB;EAChD,MAAM,KAAK,GAAG,KAAK,GAAG;EAEtB,IAAI,CAAC,YAAY,OAAO,OAAO,IAAI,EAAE,GAAG;EACxC,OAAO,IAAI,EAAE;EAEb,QAAQ,KAAK,+BAA+B,IAAI,gBAAgB,KAAK,GAAG;CAC1E;CAEA,SAAS,EACP,KACA,GAAG,YAGK;EACR,OAAO,UAAU,eAAe,OAAO,OAAO,KAAK,WAAW,IAAI,OAAO;CAC3E;CAEA,SAASA,aAAW,MAAc,OAAkB,OAAO,OAAe;EACxE,OAAOC,WAAkB,eAAe,MAAM,IAAI;CACpD;CAEA,SAASC,mBAAiB,MAAiB,aAA8B;EACvE,OAAO,gBAAgB,SACnBC,iBAAwB,eAAe,MAAM,UAAU,IAAI,IAC3DF,WAAkB,eAAe,aAAa,IAAI;CACxD;CAEA,OAAO;EAAE;EAAQ;EAAY;EAAkB;CAAE;AACnD"}
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import { n as scopedDatabaseUrl, r as toS3MediaObjectStoreOptions, t as installCms } from "../installation-
|
|
1
|
+
import { n as scopedDatabaseUrl, r as toS3MediaObjectStoreOptions, t as installCms } from "../installation-fZtNxtoW.js";
|
|
2
2
|
|
|
3
3
|
export { installCms, scopedDatabaseUrl, toS3MediaObjectStoreOptions };
|
package/src/runtime/plugin.js
CHANGED
|
@@ -1,14 +1,22 @@
|
|
|
1
1
|
import { resolveCmsInstallation } from "../internal/configuration.js";
|
|
2
|
-
import { t as installCms } from "../installation-
|
|
2
|
+
import { t as installCms } from "../installation-fZtNxtoW.js";
|
|
3
|
+
import { diagnosticFromCause, renderDiagnostic } from "../internal/diagnostics.js";
|
|
3
4
|
import { Effect } from "effect";
|
|
4
|
-
import { defineNitroPlugin, useNitroApp } from "nitropack/runtime";
|
|
5
|
+
import { defineNitroPlugin, useNitroApp, useRuntimeConfig } from "nitropack/runtime";
|
|
5
6
|
|
|
6
7
|
//#region src/runtime/plugin.ts
|
|
7
8
|
function createInstallationPlugin(authored, authoring) {
|
|
8
9
|
return defineNitroPlugin((nitro) => {
|
|
9
10
|
if (nitro.cmsInstallation) throw new Error("The CMS installation is already registered with Nitro.");
|
|
10
|
-
|
|
11
|
-
|
|
11
|
+
let configuration;
|
|
12
|
+
try {
|
|
13
|
+
configuration = resolveCmsInstallation(authored, useRuntimeConfig().cms, authoring);
|
|
14
|
+
} catch (cause) {
|
|
15
|
+
throw new Error(renderDiagnostic(diagnosticFromCause("startup.configuration", cause), false), { cause });
|
|
16
|
+
}
|
|
17
|
+
const installation = Effect.runPromise(installCms(configuration)).catch((cause) => {
|
|
18
|
+
throw new Error(renderDiagnostic(diagnosticFromCause("startup.installation", cause), false), { cause });
|
|
19
|
+
});
|
|
12
20
|
nitro.cmsInstallation = installation;
|
|
13
21
|
installation.catch((cause) => {
|
|
14
22
|
nitro.captureError(cause instanceof Error ? cause : new Error(String(cause)), {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"plugin.js","names":[],"sources":["../../../../src/runtime/plugin.ts"],"sourcesContent":["import type { CmsInstallation } from '@internal/platform-node/Installation'\nimport type { AuthoringCatalog } from '@internal/protocol/Configuration'\nimport type { CmsConfiguration } from '../Configuration'\nimport { Effect } from 'effect'\nimport { defineNitroPlugin, useNitroApp } from 'nitropack/runtime'\nimport { resolveCmsInstallation } from '../internal/configuration'\nimport { installCms } from './installation'\n\ndeclare module 'nitropack/types' {\n interface NitroApp {\n cmsInstallation?: Promise<CmsInstallation>\n }\n}\n\nexport function createInstallationPlugin(authored: CmsConfiguration, authoring: AuthoringCatalog) {\n return defineNitroPlugin((nitro) => {\n if (nitro.cmsInstallation) throw new Error('The CMS installation is already registered with Nitro.')\n
|
|
1
|
+
{"version":3,"file":"plugin.js","names":[],"sources":["../../../../src/runtime/plugin.ts"],"sourcesContent":["import type { CmsInstallation } from '@internal/platform-node/Installation'\nimport type { AuthoringCatalog } from '@internal/protocol/Configuration'\nimport type { CmsConfiguration } from '../Configuration'\nimport { Effect } from 'effect'\nimport { defineNitroPlugin, useNitroApp, useRuntimeConfig } from 'nitropack/runtime'\nimport { resolveCmsInstallation } from '../internal/configuration'\nimport { diagnosticFromCause, renderDiagnostic } from '../internal/diagnostics'\nimport { installCms } from './installation'\n\ndeclare module 'nitropack/types' {\n interface NitroApp {\n cmsInstallation?: Promise<CmsInstallation>\n }\n}\n\nexport function createInstallationPlugin(authored: CmsConfiguration, authoring: AuthoringCatalog) {\n return defineNitroPlugin((nitro) => {\n if (nitro.cmsInstallation) throw new Error('The CMS installation is already registered with Nitro.')\n let configuration\n\n try {\n configuration = resolveCmsInstallation(authored, useRuntimeConfig().cms, authoring)\n } catch (cause) {\n throw new Error(renderDiagnostic(diagnosticFromCause('startup.configuration', cause), false), { cause })\n }\n\n const installation = Effect.runPromise(installCms(configuration)).catch((cause: unknown) => {\n throw new Error(renderDiagnostic(diagnosticFromCause('startup.installation', cause), false), { cause })\n })\n\n nitro.cmsInstallation = installation\n\n void installation.catch((cause: unknown) => {\n nitro.captureError(cause instanceof Error ? cause : new Error(String(cause)), {\n fatal: true,\n tags: ['cms'],\n })\n })\n nitro.hooks.hook('close', () =>\n installation\n .then(\n (current) => current.close(),\n () => undefined,\n )\n .finally(() => {\n if (nitro.cmsInstallation === installation) nitro.cmsInstallation = undefined\n }),\n )\n })\n}\n\nexport function useCmsInstallation(): Promise<CmsInstallation> {\n const installation = useNitroApp().cmsInstallation\n\n if (!installation) throw new Error('The CMS installation has not been registered with Nitro.')\n\n return installation\n}\n"],"mappings":";;;;;;;AAeA,SAAgB,yBAAyB,UAA4B,WAA6B;CAChG,OAAO,mBAAmB,UAAU;EAClC,IAAI,MAAM,iBAAiB,MAAM,IAAI,MAAM,wDAAwD;EACnG,IAAI;EAEJ,IAAI;GACF,gBAAgB,uBAAuB,UAAU,iBAAiB,CAAC,CAAC,KAAK,SAAS;EACpF,SAAS,OAAO;GACd,MAAM,IAAI,MAAM,iBAAiB,oBAAoB,yBAAyB,KAAK,GAAG,KAAK,GAAG,EAAE,MAAM,CAAC;EACzG;EAEA,MAAM,eAAe,OAAO,WAAW,WAAW,aAAa,CAAC,CAAC,CAAC,OAAO,UAAmB;GAC1F,MAAM,IAAI,MAAM,iBAAiB,oBAAoB,wBAAwB,KAAK,GAAG,KAAK,GAAG,EAAE,MAAM,CAAC;EACxG,CAAC;EAED,MAAM,kBAAkB;EAExB,AAAK,aAAa,OAAO,UAAmB;GAC1C,MAAM,aAAa,iBAAiB,QAAQ,QAAQ,IAAI,MAAM,OAAO,KAAK,CAAC,GAAG;IAC5E,OAAO;IACP,MAAM,CAAC,KAAK;GACd,CAAC;EACH,CAAC;EACD,MAAM,MAAM,KAAK,eACf,aACG,MACE,YAAY,QAAQ,MAAM,SACrB,MACR,CAAC,CACA,cAAc;GACb,IAAI,MAAM,oBAAoB,cAAc,MAAM,kBAAkB;EACtE,CAAC,CACL;CACF,CAAC;AACH;AAEA,SAAgB,qBAA+C;CAC7D,MAAM,eAAe,YAAY,CAAC,CAAC;CAEnC,IAAI,CAAC,cAAc,MAAM,IAAI,MAAM,0DAA0D;CAE7F,OAAO;AACT"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { a as EditorNodeId, l as RevisionNumber, r as DocumentId } from "../../scalars-B2lgGUnj.js";
|
|
2
|
-
import { Et as RequestId } from "../../models-
|
|
3
|
-
import { r as PreviewIntentId } from "../../models-
|
|
2
|
+
import { Et as RequestId } from "../../models-ChRxBChy.js";
|
|
3
|
+
import { r as PreviewIntentId } from "../../models-C9kF9JlQ.js";
|
|
4
4
|
import { mountPreviewOverlay } from "./overlay.js";
|
|
5
5
|
import { clearPreviewTargets, decoratePreviewTargets, findPreviewNodeId, nearestPreviewElement, resolvePreviewTarget } from "./targets.js";
|
|
6
6
|
import { Crypto, Effect, PlatformError, Schema } from "effect";
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { o as PublicPath } from "../../scalars-B2lgGUnj.js";
|
|
2
|
-
import { t as openSitePreviewConnection } from "../../connection-
|
|
3
|
-
import { n as readPreviewLocation, r as withPreviewLocation } from "../../location-
|
|
2
|
+
import { t as openSitePreviewConnection } from "../../connection-D5S9Iph-.js";
|
|
3
|
+
import { n as readPreviewLocation, r as withPreviewLocation } from "../../location-CPX7oj0o.js";
|
|
4
4
|
import { formComponentsKey } from "../delivery/blocks.js";
|
|
5
5
|
import { documentPreviewStoreKey } from "../delivery/preview.js";
|
|
6
6
|
import { mountPreviewController } from "./controller.js";
|
|
7
|
-
import { t as createStudioPreviewStore } from "../../store-
|
|
7
|
+
import { t as createStudioPreviewStore } from "../../store-CCsjHaZm.js";
|
|
8
8
|
import { Result, Schema } from "effect";
|
|
9
9
|
import { inject, watch } from "vue";
|
|
10
10
|
import { defineNuxtPlugin, navigateTo, onNuxtReady, useNuxtApp, useState } from "nuxt/app";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"plugin.client.js","names":[],"sources":["../../../../../src/runtime/preview/plugin.client.ts"],"sourcesContent":["import { formComponentsKey } from '../delivery/blocks'\nimport { defineNuxtPlugin, navigateTo, onNuxtReady, useNuxtApp, useState } from 'nuxt/app'\nimport { inject, watch } from 'vue'\nimport { PublicPath } from '@internal/protocol/Documents'\nimport { readPreviewLocation, withPreviewLocation } from '@internal/protocol/Preview'\nimport { Result, Schema } from 'effect'\nimport { openSitePreviewConnection } from './connection'\nimport { mountPreviewController } from './controller'\nimport { createStudioPreviewStore, documentPreviewStoreKey } from './store'\n\nexport default defineNuxtPlugin({\n name: 'cms-preview',\n dependsOn: ['cms-blocks'],\n setup: () => {\n const parameters = readPreviewLocation(new URL(window.location.href))\n\n if (!parameters) return\n const route = () => Result.getOrThrow(Schema.decodeResult(PublicPath)(window.location.pathname))\n const forms = inject(formComponentsKey)\n const store = createStudioPreviewStore(route, () => forms?.value ?? [])\n const nuxtApp = useNuxtApp()\n nuxtApp.vueApp.provide(documentPreviewStoreKey, store)\n nuxtApp.hooks.hook('page:finish', store.routeChanged)\n\n const error = useState<string | null>('cms:preview-error', () => null)\n let patchError: string | null = null\n\n const mount = async () => {\n const connection = await openSitePreviewConnection({\n editorOrigin: parameters.editorOrigin,\n route: route(),\n sessionId: parameters.sessionId,\n })\n\n const sendError = () => connection.send({ type: 'preview:error', message: error.value ?? patchError })\n const stopError = watch(error, sendError, { immediate: true })\n\n const stopConnect = connection.subscribe((message) => {\n if (message.type === 'studio:connect') sendError()\n })\n\n const unmount = mountPreviewController({\n bridge: connection,\n onPatchError: (message) => {\n patchError = message\n sendError()\n },\n navigate: async (path) => {\n const target = withPreviewLocation(new URL(path, window.location.origin), parameters)\n await navigateTo(`${target.pathname}${target.search}${target.hash}`)\n },\n root: document,\n store,\n view: window,\n })\n\n window.addEventListener(\n 'pagehide',\n () => {\n stopError()\n stopConnect()\n unmount()\n void connection.close()\n },\n { once: true },\n )\n }\n\n onNuxtReady(mount)\n },\n})\n"],"mappings":";;;;;;;;;;;;AAUA,4BAAe,iBAAiB;CAC9B,MAAM;CACN,WAAW,CAAC,YAAY;CACxB,aAAa;EACX,MAAM,aAAa,oBAAoB,IAAI,IAAI,OAAO,SAAS,IAAI,CAAC;EAEpE,IAAI,CAAC,YAAY;EACjB,MAAM,cAAc,OAAO,WAAW,OAAO,aAAa,UAAU,CAAC,CAAC,OAAO,SAAS,QAAQ,CAAC;EAC/F,MAAM,QAAQ,OAAO,iBAAiB;EACtC,MAAM,QAAQ,yBAAyB,aAAa,OAAO,SAAS,CAAC,CAAC;EACtE,MAAM,UAAU,WAAW;EAC3B,QAAQ,OAAO,QAAQ,yBAAyB,KAAK;EACrD,QAAQ,MAAM,KAAK,eAAe,MAAM,YAAY;EAEpD,MAAM,QAAQ,SAAwB,2BAA2B,IAAI;EACrE,IAAI,aAA4B;
|
|
1
|
+
{"version":3,"file":"plugin.client.js","names":[],"sources":["../../../../../src/runtime/preview/plugin.client.ts"],"sourcesContent":["import { formComponentsKey } from '../delivery/blocks'\nimport { defineNuxtPlugin, navigateTo, onNuxtReady, useNuxtApp, useState } from 'nuxt/app'\nimport { inject, watch } from 'vue'\nimport { PublicPath } from '@internal/protocol/Documents'\nimport { readPreviewLocation, withPreviewLocation } from '@internal/protocol/Preview'\nimport { Result, Schema } from 'effect'\nimport { openSitePreviewConnection } from './connection'\nimport { mountPreviewController } from './controller'\nimport { createStudioPreviewStore, documentPreviewStoreKey } from './store'\n\nexport default defineNuxtPlugin({\n name: 'cms-preview',\n dependsOn: ['cms-blocks'],\n setup: () => {\n const parameters = readPreviewLocation(new URL(window.location.href))\n\n if (!parameters) return\n const route = () => Result.getOrThrow(Schema.decodeResult(PublicPath)(window.location.pathname))\n const forms = inject(formComponentsKey)\n const store = createStudioPreviewStore(route, () => forms?.value ?? [])\n const nuxtApp = useNuxtApp()\n nuxtApp.vueApp.provide(documentPreviewStoreKey, store)\n nuxtApp.hooks.hook('page:finish', store.routeChanged)\n\n const error = useState<string | null>('cms:preview-error', () => null)\n let patchError: string | null = null\n\n // oxlint-disable-next-line effecttsgo/async-function -- Nuxt's ready hook awaits this Promise-based browser connection setup.\n const mount = async () => {\n const connection = await openSitePreviewConnection({\n editorOrigin: parameters.editorOrigin,\n route: route(),\n sessionId: parameters.sessionId,\n })\n\n const sendError = () => connection.send({ type: 'preview:error', message: error.value ?? patchError })\n const stopError = watch(error, sendError, { immediate: true })\n\n const stopConnect = connection.subscribe((message) => {\n if (message.type === 'studio:connect') sendError()\n })\n\n const unmount = mountPreviewController({\n bridge: connection,\n onPatchError: (message) => {\n patchError = message\n sendError()\n },\n // oxlint-disable-next-line effecttsgo/async-function -- The preview controller accepts Nuxt's Promise-based navigation callback.\n navigate: async (path) => {\n const target = withPreviewLocation(new URL(path, window.location.origin), parameters)\n await navigateTo(`${target.pathname}${target.search}${target.hash}`)\n },\n root: document,\n store,\n view: window,\n })\n\n window.addEventListener(\n 'pagehide',\n () => {\n stopError()\n stopConnect()\n unmount()\n void connection.close()\n },\n { once: true },\n )\n }\n\n onNuxtReady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,QAAQ;IACR,AAAK,WAAW,MAAM;GACxB,GACA,EAAE,MAAM,KAAK,CACf;EACF;EAEA,YAAY,KAAK;CACnB;AACF,CAAC"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
import { documentPreviewStoreKey } from "../delivery/preview.js";
|
|
2
|
-
import { t as createStudioPreviewStore } from "../../store-
|
|
2
|
+
import { t as createStudioPreviewStore } from "../../store-CCsjHaZm.js";
|
|
3
3
|
|
|
4
4
|
export { createStudioPreviewStore, documentPreviewStoreKey };
|
package/src/runtime/sitemap.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { q as SitemapEntry } from "../models-
|
|
1
|
+
import { q as SitemapEntry } from "../models-ChRxBChy.js";
|
|
2
2
|
import { i as CMS_DELIVERY_SITEMAP_PATH } from "../HttpPaths-c9nLZ9H2.js";
|
|
3
3
|
import { useCmsInstallation } from "./plugin.js";
|
|
4
4
|
import { toNuxtSitemapEntries } from "./sitemap-entries.js";
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import { o as PublicPath, r as DocumentId } from "./scalars-B2lgGUnj.js";
|
|
2
|
-
import { Ct as CollectionName, n as CmsMarkdownDocument } from "./models-
|
|
3
|
-
import { f as mutableJson, p as mutableJsonObject } from "./Forms-
|
|
2
|
+
import { Ct as CollectionName, n as CmsMarkdownDocument } from "./models-ChRxBChy.js";
|
|
3
|
+
import { f as mutableJson, p as mutableJsonObject } from "./Forms-DoB56hfe.js";
|
|
4
4
|
import { n as editorMetadata } from "./metadata-BEZPWh-3.js";
|
|
5
5
|
import { prepareFormDocument } from "./runtime/forms/document.js";
|
|
6
6
|
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";
|
|
7
7
|
import { toPreviewRenderDocument } from "./runtime/preview/comark-document.js";
|
|
8
8
|
import { Predicate, Result, Schema } from "effect";
|
|
9
|
-
import {
|
|
9
|
+
import { shallowRef } from "vue";
|
|
10
10
|
import { createComarkContext } from "comark";
|
|
11
11
|
|
|
12
12
|
//#region ../document/src/PreviewProjection.ts
|
|
@@ -139,11 +139,11 @@ function hasInlineImplicitDefaultContent(nodes) {
|
|
|
139
139
|
//#region src/runtime/preview/store.ts
|
|
140
140
|
function createStudioPreviewStore(route, forms = () => []) {
|
|
141
141
|
const context = createComarkContext();
|
|
142
|
-
const patches =
|
|
142
|
+
const patches = shallowRef(/* @__PURE__ */ new Map());
|
|
143
143
|
const registrations = /* @__PURE__ */ new Map();
|
|
144
144
|
const listeners = /* @__PURE__ */ new Set();
|
|
145
145
|
const manifest = () => ({
|
|
146
|
-
documents: renderedDocuments(registrations.values(), patches),
|
|
146
|
+
documents: renderedDocuments(registrations.values(), patches.value),
|
|
147
147
|
route: route()
|
|
148
148
|
});
|
|
149
149
|
const notify = () => {
|
|
@@ -158,7 +158,7 @@ function createStudioPreviewStore(route, forms = () => []) {
|
|
|
158
158
|
...document,
|
|
159
159
|
body: preview.body
|
|
160
160
|
}, forms(), true);
|
|
161
|
-
patches.set(document.id, patched);
|
|
161
|
+
patches.value = new Map(patches.value).set(document.id, patched);
|
|
162
162
|
const renderBody = toPreviewRenderDocument(patched.body);
|
|
163
163
|
context.get(document.id, renderBody).set(renderBody);
|
|
164
164
|
notify();
|
|
@@ -177,7 +177,7 @@ function createStudioPreviewStore(route, forms = () => []) {
|
|
|
177
177
|
};
|
|
178
178
|
},
|
|
179
179
|
resolve(document) {
|
|
180
|
-
return patches.get(document.id) ?? document;
|
|
180
|
+
return patches.value.get(document.id) ?? document;
|
|
181
181
|
},
|
|
182
182
|
routeChanged: notify,
|
|
183
183
|
subscribe(listener) {
|
|
@@ -223,4 +223,4 @@ function createPreviewDocument(body) {
|
|
|
223
223
|
|
|
224
224
|
//#endregion
|
|
225
225
|
export { createStudioPreviewStore as t };
|
|
226
|
-
//# sourceMappingURL=store-
|
|
226
|
+
//# sourceMappingURL=store-CCsjHaZm.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"store-CCsjHaZm.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])\n\nconst INLINE_TAGS = new Set(['a', 'br', 'code', 'del', 'em', 'img', 'strong', 'u'])\n\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\n if (id) {\n identifiedTargets++\n\n if (componentId) fallbacks[id] = componentId\n\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\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\n const markerAttributes = {\n [markers.nodeAttribute]: slotId,\n [markers.targetAttribute]: 'slot',\n [markers.wrapperAttribute]: '',\n }\n\n if (markerChildren.length) markerAttributes[markers.inlineHostAttribute] = ''\n children.unshift([markers.markerTag, markerAttributes, ...markerChildren])\n }\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\n const cloned: Schema.Json = [tag, attributes, ...children]\n\n if (id && isNative) return previewWrapper(id, 'native', cloned, markers)\n\n if (id && !isNative && !isSlot) return previewWrapper(id, 'component', cloned, markers)\n\n return cloned\n })\n\n const nodes = cloneNodes(body.nodes)\n\n if (body.nodes.length && !identifiedTargets)\n throw new Error('Studio preview requires an identified authoring document.')\n\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\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 { prepareFormDocument } from '../forms/document'\nimport type { ComponentDefinition } from '@internal/protocol/Configuration'\nimport 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 { shallowRef } 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'\n\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(\n route: () => RenderedDocumentManifest['route'],\n forms: () => ReadonlyArray<ComponentDefinition> = () => [],\n): StudioPreviewStore {\n const context = createComarkContext()\n const patches = shallowRef(new Map<string, PreviewCompiledDocument>())\n\n const registrations = new Map<\n symbol,\n { readonly document: PreviewCompiledDocument; readonly role: PreviewDocumentRole }\n >()\n\n const listeners = new Set<(manifest: RenderedDocumentManifest) => void>()\n\n const manifest = (): RenderedDocumentManifest => ({\n documents: renderedDocuments(registrations.values(), patches.value),\n route: route(),\n })\n\n const notify = (): void => {\n const value = manifest()\n\n for (const listener of listeners) listener(value)\n }\n\n return {\n manifest,\n // oxlint-disable-next-line effecttsgo/async-function -- The Promise contract turns synchronous projection failures into patch rejections for the preview controller.\n async patch(document) {\n const preview = createPreviewDocument(document.body)\n const patched = prepareFormDocument({ ...document, body: preview.body }, forms(), true)\n patches.value = new Map(patches.value).set(document.id, patched)\n const renderBody = toPreviewRenderDocument(patched.body)\n context.get(document.id, renderBody).set(renderBody)\n notify()\n\n return preview.fallbacks\n },\n register(document, role) {\n const registration = Symbol(document.id)\n registrations.set(registration, { document, role })\n notify()\n\n return () => {\n registrations.delete(registration)\n notify()\n }\n },\n resolve(document) {\n return patches.value.get(document.id) ?? document\n },\n routeChanged: notify,\n subscribe(listener) {\n listeners.add(listener)\n listener(manifest())\n\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\n for (const registration of registrations) {\n const document = patches.get(registration.document.id) ?? registration.document\n const current = documents.get(document.id)\n\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\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\n if (Result.isFailure(projection)) throw projection.failure\n\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;AAED,MAAM,8BAAc,IAAI,IAAI;CAAC;CAAK;CAAM;CAAQ;CAAO;CAAM;CAAO;C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AAM,4BAAY,IAAI,IAAsC;CAE5D,KAAK,MAAM,gBAAgB,eAAe;EACxC,MAAM,WAAW,QAAQ,IAAI,aAAa,SAAS,EAAE,KAAK,aAAa;EACvE,MAAM,UAAU,UAAU,IAAI,SAAS,EAAE;EAEzC,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;CAEA,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;CAED,IAAI,OAAO,UAAU,UAAU,GAAG,MAAM,WAAW;CAEnD,OAAO,WAAW;AACpB"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { $ as e, $t as t, Ct as n, Ft as r, J as ee, K as i, Mt as a, Q as o, Tt as te, 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-Bzlh3zXt.js";
|
|
2
|
-
import { A as _, F as v, I as y, N as b, P as x, R as S,
|
|
2
|
+
import { A as _, F as v, I as y, N as b, P as x, R as S, _r as ne, a as re, n as ie, or as C, r as ae, sr as oe, t as w } from "./documentPlanning-CDb31mnl.js";
|
|
3
3
|
//#region src/documents/CreateDocumentDialog.vue?vue&type=script&setup=true&lang.ts
|
|
4
4
|
var se = { key: 2 }, ce = { class: "grid grid-flow-col auto-cols-fr overflow-x-auto rounded-md border border-default" }, T = ["title", "onClick"], E = { class: "block truncate" }, le = {
|
|
5
5
|
key: 0,
|
|
@@ -99,7 +99,7 @@ var se = { key: 2 }, ce = { class: "grid grid-flow-col auto-cols-fr overflow-x-a
|
|
|
99
99
|
}, ...t];
|
|
100
100
|
}), Q = s(() => !!z.value.trim() && !!K.value && !!Y.value && !Z.value);
|
|
101
101
|
r(z, (e) => {
|
|
102
|
-
V.value || (B.value =
|
|
102
|
+
V.value || (B.value = ie(e));
|
|
103
103
|
}), r(H, () => U.value = A, { flush: "sync" }), r(W, () => {
|
|
104
104
|
U.value = A, K.value || (H.value = $());
|
|
105
105
|
}, { flush: "sync" }), r(M, (e) => {
|
|
@@ -140,7 +140,7 @@ var se = { key: 2 }, ce = { class: "grid grid-flow-col auto-cols-fr overflow-x-a
|
|
|
140
140
|
}
|
|
141
141
|
}
|
|
142
142
|
return (t, r) => {
|
|
143
|
-
let a = y, s = x, d = v, f =
|
|
143
|
+
let a = y, s = x, d = v, f = re, b = ne, S = _;
|
|
144
144
|
return n(), e(S, {
|
|
145
145
|
open: M.value,
|
|
146
146
|
"onUpdate:open": r[6] ||= (e) => M.value = e,
|