@focus-reactive/payload-plugin-visual-editing 1.2.0 → 1.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +265 -31
- package/dist/admin/InstantPreviewBroadcaster.js +44 -3
- package/dist/admin/InstantPreviewBroadcaster.js.map +1 -1
- package/dist/admin/PreviewPageBridge.d.ts +1 -0
- package/dist/admin/PreviewPageBridge.js +50 -0
- package/dist/admin/PreviewPageBridge.js.map +1 -0
- package/dist/admin/VisualEditingBridgeProvider.js +60 -35
- package/dist/admin/VisualEditingBridgeProvider.js.map +1 -1
- package/dist/admin/expandAndFocus.d.ts +1 -0
- package/dist/admin/expandAndFocus.js +122 -99
- package/dist/admin/expandAndFocus.js.map +1 -1
- package/dist/admin/index.d.ts +1 -0
- package/dist/admin/index.js +1 -0
- package/dist/admin/index.js.map +1 -1
- package/dist/admin/instantPreview/previewGrants.d.ts +14 -0
- package/dist/admin/instantPreview/previewGrants.js +62 -0
- package/dist/admin/instantPreview/previewGrants.js.map +1 -0
- package/dist/admin/instantPreview/usePreviewPage.d.ts +2 -1
- package/dist/admin/instantPreview/usePreviewPage.js +12 -3
- package/dist/admin/instantPreview/usePreviewPage.js.map +1 -1
- package/dist/admin/openField/openForms.d.ts +7 -0
- package/dist/admin/openField/openForms.js +40 -0
- package/dist/admin/openField/openForms.js.map +1 -1
- package/dist/admin/previewPages.d.ts +7 -0
- package/dist/admin/previewPages.js +13 -0
- package/dist/admin/previewPages.js.map +1 -0
- package/dist/client/createOverlay.js +3 -0
- package/dist/client/createOverlay.js.map +1 -1
- package/dist/client/index.d.ts +6 -6
- package/dist/client/index.js +5 -5
- package/dist/client/index.js.map +1 -1
- package/dist/client/instantPreview/instantPreview.js +1 -1
- package/dist/client/instantPreview/instantPreview.js.map +1 -1
- package/dist/client/instantPreview/liveFields.d.ts +2 -1
- package/dist/client/instantPreview/liveFields.js +32 -5
- package/dist/client/instantPreview/liveFields.js.map +1 -1
- package/dist/client/instantPreview/liveRichTextOf.d.ts +3 -0
- package/dist/client/instantPreview/liveRichTextOf.js +3 -0
- package/dist/client/instantPreview/liveRichTextOf.js.map +1 -1
- package/dist/client/instantPreview/unsavedRender/baseValues.d.ts +12 -0
- package/dist/client/instantPreview/unsavedRender/baseValues.js +130 -0
- package/dist/client/instantPreview/unsavedRender/baseValues.js.map +1 -0
- package/dist/client/instantPreview/unsavedRender/liveRichText.d.ts +29 -0
- package/dist/client/instantPreview/unsavedRender/liveRichText.js +117 -0
- package/dist/client/instantPreview/unsavedRender/liveRichText.js.map +1 -0
- package/dist/client/instantPreview/unsavedRender/optimisticValue.d.ts +6 -0
- package/dist/client/instantPreview/unsavedRender/optimisticValue.js +20 -0
- package/dist/client/instantPreview/unsavedRender/optimisticValue.js.map +1 -0
- package/dist/client/instantPreview/unsavedRender/renderSources.d.ts +26 -0
- package/dist/client/instantPreview/unsavedRender/renderSources.js +77 -0
- package/dist/client/instantPreview/unsavedRender/renderSources.js.map +1 -0
- package/dist/client/instantPreview/unsavedRender/unsavedRender.d.ts +6 -1
- package/dist/client/instantPreview/unsavedRender/unsavedRender.js +116 -17
- package/dist/client/instantPreview/unsavedRender/unsavedRender.js.map +1 -1
- package/dist/client/instantPreview/unsavedRender/valueSource.d.ts +17 -0
- package/dist/client/instantPreview/unsavedRender/valueSource.js +38 -0
- package/dist/client/instantPreview/unsavedRender/valueSource.js.map +1 -0
- package/dist/client/overlay/constants.d.ts +1 -2
- package/dist/client/overlay/constants.js +1 -7
- package/dist/client/overlay/constants.js.map +1 -1
- package/dist/client/overlay/fieldTracker.d.ts +2 -0
- package/dist/client/overlay/fieldTracker.js +140 -42
- package/dist/client/overlay/fieldTracker.js.map +1 -1
- package/dist/client/overlay/hoverController.js +3 -3
- package/dist/client/overlay/hoverController.js.map +1 -1
- package/dist/client/overlay/markerCleaner.d.ts +5 -0
- package/dist/client/overlay/markerCleaner.js +94 -0
- package/dist/client/overlay/markerCleaner.js.map +1 -0
- package/dist/client/overlay/markerExtractor.js +1 -1
- package/dist/client/overlay/markerExtractor.js.map +1 -1
- package/dist/client/overlay/mutationPipeline.d.ts +3 -0
- package/dist/client/overlay/mutationPipeline.js +15 -9
- package/dist/client/overlay/mutationPipeline.js.map +1 -1
- package/dist/client/overlay/pageNodes.d.ts +3 -0
- package/dist/client/overlay/pageNodes.js +34 -0
- package/dist/client/overlay/pageNodes.js.map +1 -0
- package/dist/client/overlayClickHandler.js +3 -2
- package/dist/client/overlayClickHandler.js.map +1 -1
- package/dist/client/overlayScope.d.ts +14 -0
- package/dist/client/overlayScope.js +23 -0
- package/dist/client/overlayScope.js.map +1 -0
- package/dist/client/previewGrant.d.ts +5 -0
- package/dist/client/previewGrant.js +34 -0
- package/dist/client/previewGrant.js.map +1 -0
- package/dist/client/react/LiveRichText.d.ts +17 -0
- package/dist/client/react/LiveRichText.js +32 -0
- package/dist/client/react/LiveRichText.js.map +1 -0
- package/dist/client/react/UnsavedRenderBoundary.js.map +1 -0
- package/dist/client/react/VisualEditingOverlay.js +60 -0
- package/dist/client/react/VisualEditingOverlay.js.map +1 -0
- package/dist/client/react/VisualEditingProvider.d.ts +21 -0
- package/dist/client/react/VisualEditingProvider.js +83 -0
- package/dist/client/react/VisualEditingProvider.js.map +1 -0
- package/dist/client/react/VisualEditingToggle.d.ts +1 -0
- package/dist/client/react/VisualEditingToggle.js +32 -0
- package/dist/client/react/VisualEditingToggle.js.map +1 -0
- package/dist/client/react/overlayContext.d.ts +2 -0
- package/dist/client/react/overlayContext.js +4 -0
- package/dist/client/react/overlayContext.js.map +1 -0
- package/dist/client/react/useIsomorphicLayoutEffect.js.map +1 -0
- package/dist/client/react/useUnsavedRender.d.ts +16 -0
- package/dist/client/react/useUnsavedRender.js +89 -0
- package/dist/client/react/useUnsavedRender.js.map +1 -0
- package/dist/client/saveEvents.d.ts +3 -0
- package/dist/client/saveEvents.js +27 -0
- package/dist/client/saveEvents.js.map +1 -0
- package/dist/client/session.d.ts +40 -0
- package/dist/client/session.js +100 -0
- package/dist/client/session.js.map +1 -0
- package/dist/client/sessionOverlay.d.ts +9 -0
- package/dist/client/sessionOverlay.js +74 -0
- package/dist/client/sessionOverlay.js.map +1 -0
- package/dist/client/toggle.d.ts +7 -0
- package/dist/client/toggle.js +158 -0
- package/dist/client/toggle.js.map +1 -0
- package/dist/client/withVisualEditingPath.d.ts +2 -0
- package/dist/client/withVisualEditingPath.js +5 -6
- package/dist/client/withVisualEditingPath.js.map +1 -1
- package/dist/dom/index.d.ts +6 -0
- package/dist/dom/index.js +7 -0
- package/dist/dom/index.js.map +1 -0
- package/dist/dom/liveRichTextElements.d.ts +8 -0
- package/dist/dom/liveRichTextElements.js +69 -0
- package/dist/dom/liveRichTextElements.js.map +1 -0
- package/dist/dom/mountVisualEditing.d.ts +16 -0
- package/dist/dom/mountVisualEditing.js +52 -0
- package/dist/dom/mountVisualEditing.js.map +1 -0
- package/dist/excludeValues.d.ts +0 -4
- package/dist/excludeValues.js +4 -4
- package/dist/excludeValues.js.map +1 -1
- package/dist/index.d.ts +4 -0
- package/dist/index.js +13 -4
- package/dist/index.js.map +1 -1
- package/dist/readUnsavedRichText.d.ts +16 -2
- package/dist/readUnsavedRichText.js +26 -7
- package/dist/readUnsavedRichText.js.map +1 -1
- package/dist/server/endpoints.d.ts +16 -0
- package/dist/server/endpoints.js +136 -0
- package/dist/server/endpoints.js.map +1 -0
- package/dist/server/markRead.js +3 -3
- package/dist/server/markRead.js.map +1 -1
- package/dist/server/markedReads.d.ts +1 -1
- package/dist/server/markedReads.js +4 -2
- package/dist/server/markedReads.js.map +1 -1
- package/dist/server/previewGrant.d.ts +9 -0
- package/dist/server/previewGrant.js +31 -0
- package/dist/server/previewGrant.js.map +1 -0
- package/dist/server/unsavedRichText/hooks.js +24 -9
- package/dist/server/unsavedRichText/hooks.js.map +1 -1
- package/dist/server/unsavedRichText/placeUnsavedState.js +1 -1
- package/dist/server/unsavedRichText/placeUnsavedState.js.map +1 -1
- package/dist/server/unsavedRichText/postedEditorState.js +3 -31
- package/dist/server/unsavedRichText/postedEditorState.js.map +1 -1
- package/dist/server/unsavedRichText/postedRequest.d.ts +2 -1
- package/dist/server/unsavedRichText/postedRequest.js +14 -4
- package/dist/server/unsavedRichText/postedRequest.js.map +1 -1
- package/dist/server/unsavedRichText/readAsUser.d.ts +7 -2
- package/dist/server/unsavedRichText/readAsUser.js +47 -16
- package/dist/server/unsavedRichText/readAsUser.js.map +1 -1
- package/dist/server/unsavedRichText/readContext.d.ts +6 -0
- package/dist/server/unsavedRichText/readContext.js +5 -0
- package/dist/server/unsavedRichText/readContext.js.map +1 -1
- package/dist/server/unsavedRichText/savedReferences.d.ts +5 -0
- package/dist/server/unsavedRichText/savedReferences.js +61 -0
- package/dist/server/unsavedRichText/savedReferences.js.map +1 -0
- package/dist/server/withDocumentControls.d.ts +10 -0
- package/dist/server/{withInstantPreview.js → withDocumentControls.js} +17 -7
- package/dist/server/withDocumentControls.js.map +1 -0
- package/dist/shared/buildAdminEditUrl.d.ts +1 -0
- package/dist/shared/buildAdminEditUrl.js +5 -1
- package/dist/shared/buildAdminEditUrl.js.map +1 -1
- package/dist/shared/protocol.d.ts +18 -0
- package/dist/shared/protocol.js +6 -0
- package/dist/shared/protocol.js.map +1 -1
- package/dist/shared/richText/editorStateTree.d.ts +2 -0
- package/dist/shared/richText/editorStateTree.js +34 -0
- package/dist/shared/richText/editorStateTree.js.map +1 -0
- package/dist/{server → shared}/richText/markTextLeaves.js +5 -5
- package/dist/shared/richText/markTextLeaves.js.map +1 -0
- package/dist/shared/richText/nodeKey.d.ts +3 -2
- package/dist/shared/richText/nodeKey.js +15 -6
- package/dist/shared/richText/nodeKey.js.map +1 -1
- package/dist/shared/richText/references.d.ts +16 -0
- package/dist/shared/richText/references.js +85 -0
- package/dist/shared/richText/references.js.map +1 -0
- package/dist/{server/unsavedRichText → shared/richText}/relatedIds.d.ts +1 -1
- package/dist/{server/unsavedRichText → shared/richText}/relatedIds.js +4 -4
- package/dist/shared/richText/relatedIds.js.map +1 -0
- package/dist/shared/richText/savedNodeFields.d.ts +3 -0
- package/dist/{server/unsavedRichText → shared/richText}/savedNodeFields.js +4 -4
- package/dist/shared/richText/savedNodeFields.js.map +1 -0
- package/dist/shared/shared.d.ts +14 -3
- package/dist/shared/shared.js +46 -1
- package/dist/shared/shared.js.map +1 -1
- package/dist/shared/stegaText.d.ts +2 -1
- package/dist/shared/stegaText.js +3 -1
- package/dist/shared/stegaText.js.map +1 -1
- package/package.json +26 -4
- package/dist/client/VisualEditingOverlay.js +0 -39
- package/dist/client/VisualEditingOverlay.js.map +0 -1
- package/dist/client/VisualEditingProvider.d.ts +0 -25
- package/dist/client/VisualEditingProvider.js +0 -68
- package/dist/client/VisualEditingProvider.js.map +0 -1
- package/dist/client/VisualEditingToggle.d.ts +0 -1
- package/dist/client/VisualEditingToggle.js +0 -153
- package/dist/client/VisualEditingToggle.js.map +0 -1
- package/dist/client/instantPreview/LiveRichText.d.ts +0 -16
- package/dist/client/instantPreview/LiveRichText.js +0 -18
- package/dist/client/instantPreview/LiveRichText.js.map +0 -1
- package/dist/client/instantPreview/unsavedRender/UnsavedRenderBoundary.js.map +0 -1
- package/dist/client/instantPreview/unsavedRender/useUnsavedRender.d.ts +0 -10
- package/dist/client/instantPreview/unsavedRender/useUnsavedRender.js +0 -118
- package/dist/client/instantPreview/unsavedRender/useUnsavedRender.js.map +0 -1
- package/dist/client/overlayContext.d.ts +0 -3
- package/dist/client/overlayContext.js +0 -5
- package/dist/client/overlayContext.js.map +0 -1
- package/dist/client/useIsomorphicLayoutEffect.js.map +0 -1
- package/dist/client/useVisualEditingOverlay.d.ts +0 -4
- package/dist/client/useVisualEditingOverlay.js +0 -33
- package/dist/client/useVisualEditingOverlay.js.map +0 -1
- package/dist/server/richText/markTextLeaves.js.map +0 -1
- package/dist/server/unsavedRichText/relatedIds.js.map +0 -1
- package/dist/server/unsavedRichText/savedNodeFields.d.ts +0 -2
- package/dist/server/unsavedRichText/savedNodeFields.js.map +0 -1
- package/dist/server/withInstantPreview.d.ts +0 -9
- package/dist/server/withInstantPreview.js.map +0 -1
- /package/dist/client/{instantPreview/unsavedRender → react}/UnsavedRenderBoundary.d.ts +0 -0
- /package/dist/client/{instantPreview/unsavedRender → react}/UnsavedRenderBoundary.js +0 -0
- /package/dist/client/{VisualEditingOverlay.d.ts → react/VisualEditingOverlay.d.ts} +0 -0
- /package/dist/client/{useIsomorphicLayoutEffect.d.ts → react/useIsomorphicLayoutEffect.d.ts} +0 -0
- /package/dist/client/{useIsomorphicLayoutEffect.js → react/useIsomorphicLayoutEffect.js} +0 -0
- /package/dist/{server → shared}/richText/markTextLeaves.d.ts +0 -0
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/server/unsavedRichText/postedRequest.ts"],"sourcesContent":["import type { Payload } from \"payload\";\n\nimport type { LiveRichTextField, VeEditorState } from \"../../shared/protocol.js\";\n\nimport { schemaPathOfRichText } from \"../../shared/editableSchema/editableSchema.js\";\nimport { isPlainObject } from \"../../shared/plainObject.js\";\nimport { isRichTextNodeKey } from \"../../shared/richText/nodeKey.js\";\nimport { isVeDocument, veDocumentOf } from \"../../shared/veDocument.js\";\nimport { isLocaleOf } from \"../localeCodesKeyingValues.js\";\nimport { schemaCacheOf } from \"../schemaCache.js\";\nimport { readJsonBody } from \"./jsonBody.js\";\nimport { readPostedEditorState } from \"./postedEditorState.js\";\n\nconst MAX_BYTES_PER_CHARACTER = 3;\nconst MAX_REQUEST_ENVELOPE_BYTES = 4096;\nconst MISSING_SCHEMA_CACHE_MESSAGE =\n \"readUnsavedRichText found no schema cache of the visual editing plugin in config.custom, so it reads no unsaved rich text. Turn on instantPreview of the plugin and keep its config.custom of the plugin when a later plugin replaces custom.\";\n\nexport type PostedRequest =\n | { headers: Headers; request: unknown }\n | { headers?: never; request: Request };\n\ntype DocumentToRead =\n | { collection: string; id: number | string; kind: \"collection\" }\n | { kind: \"global\"; slug: string };\n\nexport type Unsaved = {\n document: DocumentToRead;\n field: LiveRichTextField;\n fieldPath: string;\n locale: string | undefined;\n state: VeEditorState;\n};\n\nexport type User = Awaited<ReturnType<Payload[\"auth\"]>>[\"user\"];\n\nexport type SignedIn = { unsaved: Unsaved; user: NonNullable<User> };\n\nexport type PostedReadLimits = { maxStateLength: number; signal: AbortSignal };\n\nconst NUMBER_ID_TYPE = \"number\";\n\nconst readField = (field: unknown): LiveRichTextField | null => {\n if (!isPlainObject(field) || !isVeDocument(field) || typeof field.key !== \"string\") return null;\n if (isRichTextNodeKey(field.key)) return null;\n return { ...veDocumentOf(field as LiveRichTextField), key: field.key };\n};\n\nconst idOfCollection = (payload: Payload, collection: string, docId: string) => {\n const idType = payload.collections[collection]?.customIDType ?? payload.db.defaultIDType;\n if (idType !== NUMBER_ID_TYPE) return docId === \"\" ? null : docId;\n const id = Number(docId);\n return Number.isSafeInteger(id) && String(id) === docId ? id : null;\n};\n\nconst documentOf = (\n payload: Payload,\n { collectionSlug, docId, kind }: LiveRichTextField\n): DocumentToRead | null => {\n if (kind === \"global\") {\n const isGlobal = payload.config.globals.some(({ slug }) => slug === collectionSlug);\n return isGlobal && docId === undefined ? { kind, slug: collectionSlug } : null;\n }\n if (docId === undefined || !Object.hasOwn(payload.collections, collectionSlug)) return null;\n const id = idOfCollection(payload, collectionSlug, docId);\n return id === null ? null : { collection: collectionSlug, id, kind };\n};\n\nconst warnedOfMissingSchemaCache = new WeakSet<Payload>();\n\nconst warnOnceOfMissingSchemaCache = (payload: Payload): void => {\n if (warnedOfMissingSchemaCache.has(payload)) return;\n warnedOfMissingSchemaCache.add(payload);\n payload.logger.warn(MISSING_SCHEMA_CACHE_MESSAGE);\n};\n\nconst fieldPathOf = (payload: Payload, { collectionSlug, key }: LiveRichTextField) => {\n const schemaCache = schemaCacheOf(payload);\n if (!schemaCache) {\n warnOnceOfMissingSchemaCache(payload);\n return null;\n }\n const schema = schemaCache.get(collectionSlug, payload);\n return schema && schemaPathOfRichText(schema, key);\n};\n\nconst readUnsaved = (payload: Payload
|
|
1
|
+
{"version":3,"sources":["../../../src/server/unsavedRichText/postedRequest.ts"],"sourcesContent":["import type { Payload } from \"payload\";\n\nimport type { LiveRichTextField, VeEditorState } from \"../../shared/protocol.js\";\n\nimport { schemaPathOfRichText } from \"../../shared/editableSchema/editableSchema.js\";\nimport { isPlainObject } from \"../../shared/plainObject.js\";\nimport { isRichTextNodeKey } from \"../../shared/richText/nodeKey.js\";\nimport { isVeDocument, veDocumentOf } from \"../../shared/veDocument.js\";\nimport { isLocaleOf } from \"../localeCodesKeyingValues.js\";\nimport { schemaCacheOf } from \"../schemaCache.js\";\nimport { readJsonBody } from \"./jsonBody.js\";\nimport { readPostedEditorState } from \"./postedEditorState.js\";\n\nconst MAX_BYTES_PER_CHARACTER = 3;\nconst MAX_REQUEST_ENVELOPE_BYTES = 4096;\nconst MISSING_SCHEMA_CACHE_MESSAGE =\n \"readUnsavedRichText found no schema cache of the visual editing plugin in config.custom, so it reads no unsaved rich text. Turn on instantPreview of the plugin and keep its config.custom of the plugin when a later plugin replaces custom.\";\n\nexport type PostedRequest =\n | { headers: Headers; request: unknown }\n | { headers?: never; request: Request };\n\ntype DocumentToRead =\n | { collection: string; id: number | string; kind: \"collection\" }\n | { kind: \"global\"; slug: string };\n\nexport type Unsaved = {\n document: DocumentToRead;\n field: LiveRichTextField;\n fieldPath: string;\n locale: string | undefined;\n state: VeEditorState | null;\n};\n\nexport type User = Awaited<ReturnType<Payload[\"auth\"]>>[\"user\"];\n\nexport type SignedIn = { unsaved: Unsaved; user: NonNullable<User> };\n\nexport type PostedReadLimits = { maxStateLength: number; signal: AbortSignal };\n\nconst NUMBER_ID_TYPE = \"number\";\n\nconst readField = (field: unknown): LiveRichTextField | null => {\n if (!isPlainObject(field) || !isVeDocument(field) || typeof field.key !== \"string\") return null;\n if (isRichTextNodeKey(field.key)) return null;\n return { ...veDocumentOf(field as LiveRichTextField), key: field.key };\n};\n\nconst idOfCollection = (payload: Payload, collection: string, docId: string) => {\n const idType = payload.collections[collection]?.customIDType ?? payload.db.defaultIDType;\n if (idType !== NUMBER_ID_TYPE) return docId === \"\" ? null : docId;\n const id = Number(docId);\n return Number.isSafeInteger(id) && String(id) === docId ? id : null;\n};\n\nconst documentOf = (\n payload: Payload,\n { collectionSlug, docId, kind }: LiveRichTextField\n): DocumentToRead | null => {\n if (kind === \"global\") {\n const isGlobal = payload.config.globals.some(({ slug }) => slug === collectionSlug);\n return isGlobal && docId === undefined ? { kind, slug: collectionSlug } : null;\n }\n if (docId === undefined || !Object.hasOwn(payload.collections, collectionSlug)) return null;\n const id = idOfCollection(payload, collectionSlug, docId);\n return id === null ? null : { collection: collectionSlug, id, kind };\n};\n\nconst warnedOfMissingSchemaCache = new WeakSet<Payload>();\n\nconst warnOnceOfMissingSchemaCache = (payload: Payload): void => {\n if (warnedOfMissingSchemaCache.has(payload)) return;\n warnedOfMissingSchemaCache.add(payload);\n payload.logger.warn(MISSING_SCHEMA_CACHE_MESSAGE);\n};\n\nconst fieldPathOf = (payload: Payload, { collectionSlug, key }: LiveRichTextField) => {\n const schemaCache = schemaCacheOf(payload);\n if (!schemaCache) {\n warnOnceOfMissingSchemaCache(payload);\n return null;\n }\n const schema = schemaCache.get(collectionSlug, payload);\n return schema && schemaPathOfRichText(schema, key);\n};\n\nconst SAVED_VALUE = { state: null };\n\nconst postedStateOf = (\n posted: unknown,\n maxStateLength: number\n): { state: VeEditorState | null } | null => {\n if (posted === undefined) return SAVED_VALUE;\n const state = readPostedEditorState(posted, maxStateLength);\n return state && { state };\n};\n\nexport const readUnsaved = (\n payload: Payload,\n body: unknown,\n maxStateLength: number\n): Unsaved | null => {\n if (!isPlainObject(body)) return null;\n const field = readField(body.field);\n const document = field && documentOf(payload, field);\n const fieldPath = document && fieldPathOf(payload, field);\n const posted = fieldPath && postedStateOf(body.state, maxStateLength);\n if (!field || !document || !fieldPath || !posted || !isLocaleOf(payload, body.locale))\n return null;\n return { document, field, fieldPath, locale: body.locale, state: posted.state };\n};\n\nconst userOf = async (payload: Payload, headers: Headers): Promise<User> =>\n (await payload.auth({ headers })).user;\n\nexport const signInAndReadBody = async (\n payload: Payload,\n request: Request,\n { maxStateLength, signal }: PostedReadLimits\n): Promise<SignedIn | null> => {\n const user = await userOf(payload, request.headers);\n if (!user || signal.aborted) return null;\n const maxBodyBytes = maxStateLength * MAX_BYTES_PER_CHARACTER + MAX_REQUEST_ENVELOPE_BYTES;\n const body = await readJsonBody(request, maxBodyBytes, signal);\n const unsaved = readUnsaved(payload, body, maxStateLength);\n return unsaved && { unsaved, user };\n};\n\nexport const checkAndSignIn = async (\n payload: Payload,\n request: unknown,\n headers: Headers | undefined,\n { maxStateLength }: PostedReadLimits\n): Promise<SignedIn | null> => {\n const unsaved = readUnsaved(payload, request, maxStateLength);\n const user = unsaved && headers ? await userOf(payload, headers) : null;\n return unsaved && user ? { unsaved, user } : null;\n};\n"],"names":["schemaPathOfRichText","isPlainObject","isRichTextNodeKey","isVeDocument","veDocumentOf","isLocaleOf","schemaCacheOf","readJsonBody","readPostedEditorState","MAX_BYTES_PER_CHARACTER","MAX_REQUEST_ENVELOPE_BYTES","MISSING_SCHEMA_CACHE_MESSAGE","NUMBER_ID_TYPE","readField","field","key","idOfCollection","payload","collection","docId","idType","collections","customIDType","db","defaultIDType","id","Number","isSafeInteger","String","documentOf","collectionSlug","kind","isGlobal","config","globals","some","slug","undefined","Object","hasOwn","warnedOfMissingSchemaCache","WeakSet","warnOnceOfMissingSchemaCache","has","add","logger","warn","fieldPathOf","schemaCache","schema","get","SAVED_VALUE","state","postedStateOf","posted","maxStateLength","readUnsaved","body","document","fieldPath","locale","userOf","headers","auth","user","signInAndReadBody","request","signal","aborted","maxBodyBytes","unsaved","checkAndSignIn"],"mappings":"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"}
|
|
@@ -2,5 +2,10 @@ import type { Payload } from "payload";
|
|
|
2
2
|
import type { LiveRichTextField } from "../../shared/protocol.js";
|
|
3
3
|
import type { Unsaved, User } from "./postedRequest.js";
|
|
4
4
|
export type UnsavedRichTextDepth = number | ((field: LiveRichTextField) => number | undefined);
|
|
5
|
-
export
|
|
6
|
-
|
|
5
|
+
export type ReadAsUserOptions = {
|
|
6
|
+
depth: UnsavedRichTextDepth | undefined;
|
|
7
|
+
readWholeDocument: boolean;
|
|
8
|
+
savedReferencesOnly: boolean;
|
|
9
|
+
};
|
|
10
|
+
export declare const readKeyOf: (user: NonNullable<User>, unsaved: Unsaved) => string;
|
|
11
|
+
export declare const readAsUser: <Content>(payload: Payload, user: NonNullable<User>, unsaved: Unsaved, options: ReadAsUserOptions) => Promise<Content | null>;
|
|
@@ -1,19 +1,36 @@
|
|
|
1
|
-
import { valueAtKey } from "../../shared/fieldKey.js";
|
|
1
|
+
import { FIELD_PATH_SEPARATOR, valueAtKey } from "../../shared/fieldKey.js";
|
|
2
2
|
import { isPlainObject } from "../../shared/plainObject.js";
|
|
3
|
+
import { rootOf } from "../../shared/richText/editorNodes.js";
|
|
3
4
|
import { shapeOf } from "../../shared/richText/shapeOf.js";
|
|
4
5
|
import { isMetaInfo, META_KEY } from "../../shared/shared.js";
|
|
5
6
|
import { documentAddressOf, keyedFieldAddressOf } from "../../shared/veDocument.js";
|
|
6
|
-
import { UNSAVED_RICH_TEXT_CONTEXT_KEY } from "./readContext.js";
|
|
7
|
+
import { SAVED_REFERENCES_ONLY_CONTEXT_KEY, UNSAVED_RICH_TEXT_CONTEXT_KEY } from "./readContext.js";
|
|
8
|
+
import { withHeldReferences } from "./savedReferences.js";
|
|
9
|
+
const SAVED_READ = "saved";
|
|
10
|
+
const UNSAVED_READ = "unsaved";
|
|
7
11
|
const depthOf = (depth, field)=>typeof depth === "function" ? depth(field) : depth;
|
|
8
|
-
const
|
|
9
|
-
|
|
12
|
+
const selectOf = (fieldPath)=>({
|
|
13
|
+
[fieldPath.split(FIELD_PATH_SEPARATOR)[0] ?? fieldPath]: true
|
|
14
|
+
});
|
|
15
|
+
const placementOf = (field, state)=>state === null ? null : {
|
|
10
16
|
field,
|
|
11
17
|
isPlaced: false,
|
|
12
18
|
state
|
|
13
19
|
};
|
|
20
|
+
const readDocumentAs = (user, payload, { document, field, fieldPath, locale, state }, { depth, readWholeDocument, savedReferencesOnly })=>{
|
|
21
|
+
const placed = placementOf(field, state);
|
|
22
|
+
const restricted = savedReferencesOnly ? {
|
|
23
|
+
field,
|
|
24
|
+
isApplied: false
|
|
25
|
+
} : null;
|
|
14
26
|
const options = {
|
|
15
27
|
context: {
|
|
16
|
-
|
|
28
|
+
...placed && {
|
|
29
|
+
[UNSAVED_RICH_TEXT_CONTEXT_KEY]: placed
|
|
30
|
+
},
|
|
31
|
+
...restricted && {
|
|
32
|
+
[SAVED_REFERENCES_ONLY_CONTEXT_KEY]: restricted
|
|
33
|
+
},
|
|
17
34
|
visualEditing: true
|
|
18
35
|
},
|
|
19
36
|
depth: depthOf(depth, field),
|
|
@@ -21,6 +38,9 @@ const readDocumentAs = (user, payload, { document, field, locale, state }, depth
|
|
|
21
38
|
draft: true,
|
|
22
39
|
locale,
|
|
23
40
|
overrideAccess: false,
|
|
41
|
+
...!readWholeDocument && {
|
|
42
|
+
select: selectOf(fieldPath)
|
|
43
|
+
},
|
|
24
44
|
user
|
|
25
45
|
};
|
|
26
46
|
const read = document.kind === "global" ? payload.findGlobal({
|
|
@@ -33,28 +53,39 @@ const readDocumentAs = (user, payload, { document, field, locale, state }, depth
|
|
|
33
53
|
});
|
|
34
54
|
return {
|
|
35
55
|
placed,
|
|
36
|
-
read
|
|
56
|
+
read,
|
|
57
|
+
restricted
|
|
37
58
|
};
|
|
38
59
|
};
|
|
39
|
-
const
|
|
40
|
-
|
|
60
|
+
const isMarkedRichText = (content)=>isPlainObject(content) && isMetaInfo(content[META_KEY]) && rootOf(content) !== null;
|
|
61
|
+
const hasStructureOf = (content, field, state)=>{
|
|
41
62
|
const fieldAddress = keyedFieldAddressOf(field);
|
|
42
63
|
const shape = shapeOf(content, fieldAddress);
|
|
43
64
|
return shape !== null && shape === shapeOf(state, fieldAddress);
|
|
44
65
|
};
|
|
45
|
-
|
|
66
|
+
const isAnswerTo = (content, { field, state })=>isMarkedRichText(content) && (state === null || hasStructureOf(content, field, state));
|
|
67
|
+
const readTargetOf = ({ field, fieldPath, state })=>state === null ? [
|
|
68
|
+
SAVED_READ,
|
|
69
|
+
keyedFieldAddressOf(field)
|
|
70
|
+
] : [
|
|
71
|
+
UNSAVED_READ,
|
|
72
|
+
documentAddressOf(field),
|
|
73
|
+
fieldPath
|
|
74
|
+
];
|
|
75
|
+
export const readKeyOf = (user, unsaved)=>JSON.stringify([
|
|
46
76
|
user.collection,
|
|
47
77
|
user.id,
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
locale ?? null
|
|
78
|
+
unsaved.locale ?? null,
|
|
79
|
+
...readTargetOf(unsaved)
|
|
51
80
|
]);
|
|
52
|
-
export const readAsUser = async (payload, user, unsaved,
|
|
53
|
-
const { placed, read } = readDocumentAs(user, payload, unsaved,
|
|
81
|
+
export const readAsUser = async (payload, user, unsaved, options)=>{
|
|
82
|
+
const { placed, read, restricted } = readDocumentAs(user, payload, unsaved, options);
|
|
54
83
|
const document = await read;
|
|
55
|
-
if (!placed.isPlaced) return null;
|
|
84
|
+
if (placed && !placed.isPlaced) return null;
|
|
85
|
+
if (restricted && !restricted.isApplied) return null;
|
|
56
86
|
const content = valueAtKey(document, unsaved.field.key)?.value;
|
|
57
|
-
|
|
87
|
+
if (!isAnswerTo(content, unsaved)) return null;
|
|
88
|
+
return restricted ? withHeldReferences(content) : content;
|
|
58
89
|
};
|
|
59
90
|
|
|
60
91
|
//# sourceMappingURL=readAsUser.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/server/unsavedRichText/readAsUser.ts"],"sourcesContent":["import type { Payload } from \"payload\";\n\nimport type { LiveRichTextField } from \"../../shared/protocol.js\";\nimport type { Unsaved, User } from \"./postedRequest.js\";\nimport type { UnsavedRichText } from \"./readContext.js\";\n\nimport { valueAtKey } from \"../../shared/fieldKey.js\";\nimport { isPlainObject } from \"../../shared/plainObject.js\";\nimport { shapeOf } from \"../../shared/richText/shapeOf.js\";\nimport { isMetaInfo, META_KEY } from \"../../shared/shared.js\";\nimport { documentAddressOf, keyedFieldAddressOf } from \"../../shared/veDocument.js\";\nimport { UNSAVED_RICH_TEXT_CONTEXT_KEY } from \"./readContext.js\";\n\nexport type UnsavedRichTextDepth = number | ((field: LiveRichTextField) => number | undefined);\n\nconst depthOf = (depth: UnsavedRichTextDepth | undefined, field: LiveRichTextField) =>\n typeof depth === \"function\" ? depth(field) : depth;\n\nconst readDocumentAs = (\n user: User,\n payload: Payload,\n { document, field, locale, state }: Unsaved,\n depth
|
|
1
|
+
{"version":3,"sources":["../../../src/server/unsavedRichText/readAsUser.ts"],"sourcesContent":["import type { Payload, SelectType } from \"payload\";\n\nimport type { LiveRichTextField, VeEditorState } from \"../../shared/protocol.js\";\nimport type { Unsaved, User } from \"./postedRequest.js\";\nimport type { SavedReferencesOnly, UnsavedRichText } from \"./readContext.js\";\n\nimport { FIELD_PATH_SEPARATOR, valueAtKey } from \"../../shared/fieldKey.js\";\nimport { isPlainObject } from \"../../shared/plainObject.js\";\nimport { rootOf } from \"../../shared/richText/editorNodes.js\";\nimport { shapeOf } from \"../../shared/richText/shapeOf.js\";\nimport { isMetaInfo, META_KEY } from \"../../shared/shared.js\";\nimport { documentAddressOf, keyedFieldAddressOf } from \"../../shared/veDocument.js\";\nimport { SAVED_REFERENCES_ONLY_CONTEXT_KEY, UNSAVED_RICH_TEXT_CONTEXT_KEY } from \"./readContext.js\";\nimport { withHeldReferences } from \"./savedReferences.js\";\n\nexport type UnsavedRichTextDepth = number | ((field: LiveRichTextField) => number | undefined);\n\nexport type ReadAsUserOptions = {\n depth: UnsavedRichTextDepth | undefined;\n readWholeDocument: boolean;\n savedReferencesOnly: boolean;\n};\n\nconst SAVED_READ = \"saved\";\nconst UNSAVED_READ = \"unsaved\";\n\nconst depthOf = (depth: UnsavedRichTextDepth | undefined, field: LiveRichTextField) =>\n typeof depth === \"function\" ? depth(field) : depth;\n\nconst selectOf = (fieldPath: string): SelectType => ({\n [fieldPath.split(FIELD_PATH_SEPARATOR)[0] ?? fieldPath]: true,\n});\n\nconst placementOf = (field: LiveRichTextField, state: VeEditorState | null) =>\n state === null ? null : { field, isPlaced: false, state };\n\nconst readDocumentAs = (\n user: User,\n payload: Payload,\n { document, field, fieldPath, locale, state }: Unsaved,\n { depth, readWholeDocument, savedReferencesOnly }: ReadAsUserOptions\n): {\n placed: UnsavedRichText | null;\n read: Promise<unknown>;\n restricted: SavedReferencesOnly | null;\n} => {\n const placed = placementOf(field, state);\n const restricted = savedReferencesOnly ? { field, isApplied: false } : null;\n const options = {\n context: {\n ...(placed && { [UNSAVED_RICH_TEXT_CONTEXT_KEY]: placed }),\n ...(restricted && { [SAVED_REFERENCES_ONLY_CONTEXT_KEY]: restricted }),\n visualEditing: true,\n },\n depth: depthOf(depth, field),\n disableErrors: true,\n draft: true,\n locale,\n overrideAccess: false,\n ...(!readWholeDocument && { select: selectOf(fieldPath) }),\n user,\n };\n const read =\n document.kind === \"global\"\n ? payload.findGlobal({ ...options, slug: document.slug })\n : payload.findByID({ ...options, collection: document.collection, id: document.id });\n return { placed, read, restricted };\n};\n\nconst isMarkedRichText = (content: unknown): boolean =>\n isPlainObject(content) && isMetaInfo(content[META_KEY]) && rootOf(content) !== null;\n\nconst hasStructureOf = (content: unknown, field: LiveRichTextField, state: VeEditorState) => {\n const fieldAddress = keyedFieldAddressOf(field);\n const shape = shapeOf(content, fieldAddress);\n return shape !== null && shape === shapeOf(state, fieldAddress);\n};\n\nconst isAnswerTo = (content: unknown, { field, state }: Unsaved): boolean =>\n isMarkedRichText(content) && (state === null || hasStructureOf(content, field, state));\n\nconst readTargetOf = ({ field, fieldPath, state }: Unsaved) =>\n state === null\n ? [SAVED_READ, keyedFieldAddressOf(field)]\n : [UNSAVED_READ, documentAddressOf(field), fieldPath];\n\nexport const readKeyOf = (user: NonNullable<User>, unsaved: Unsaved): string =>\n JSON.stringify([user.collection, user.id, unsaved.locale ?? null, ...readTargetOf(unsaved)]);\n\nexport const readAsUser = async <Content>(\n payload: Payload,\n user: NonNullable<User>,\n unsaved: Unsaved,\n options: ReadAsUserOptions\n): Promise<Content | null> => {\n const { placed, read, restricted } = readDocumentAs(user, payload, unsaved, options);\n const document = await read;\n if (placed && !placed.isPlaced) return null;\n if (restricted && !restricted.isApplied) return null;\n\n const content = valueAtKey(document, unsaved.field.key)?.value;\n if (!isAnswerTo(content, unsaved)) return null;\n return (restricted ? withHeldReferences(content) : content) as Content;\n};\n"],"names":["FIELD_PATH_SEPARATOR","valueAtKey","isPlainObject","rootOf","shapeOf","isMetaInfo","META_KEY","documentAddressOf","keyedFieldAddressOf","SAVED_REFERENCES_ONLY_CONTEXT_KEY","UNSAVED_RICH_TEXT_CONTEXT_KEY","withHeldReferences","SAVED_READ","UNSAVED_READ","depthOf","depth","field","selectOf","fieldPath","split","placementOf","state","isPlaced","readDocumentAs","user","payload","document","locale","readWholeDocument","savedReferencesOnly","placed","restricted","isApplied","options","context","visualEditing","disableErrors","draft","overrideAccess","select","read","kind","findGlobal","slug","findByID","collection","id","isMarkedRichText","content","hasStructureOf","fieldAddress","shape","isAnswerTo","readTargetOf","readKeyOf","unsaved","JSON","stringify","readAsUser","key","value"],"mappings":"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"}
|
|
@@ -8,3 +8,9 @@ export type UnsavedRichText = {
|
|
|
8
8
|
};
|
|
9
9
|
export declare const unsavedRichTextOf: (context: RequestContext) => UnsavedRichText | null;
|
|
10
10
|
export declare const isUnsavedRichTextRead: (req: PayloadRequest) => boolean;
|
|
11
|
+
export declare const SAVED_REFERENCES_ONLY_CONTEXT_KEY = "__visualEditingSavedReferencesOnly";
|
|
12
|
+
export type SavedReferencesOnly = {
|
|
13
|
+
field: LiveRichTextField;
|
|
14
|
+
isApplied: boolean;
|
|
15
|
+
};
|
|
16
|
+
export declare const savedReferencesOnlyOf: (context: RequestContext) => SavedReferencesOnly | null;
|
|
@@ -5,5 +5,10 @@ export const unsavedRichTextOf = (context)=>{
|
|
|
5
5
|
return isPlainObject(unsaved) ? unsaved : null;
|
|
6
6
|
};
|
|
7
7
|
export const isUnsavedRichTextRead = (req)=>unsavedRichTextOf(req.context) !== null;
|
|
8
|
+
export const SAVED_REFERENCES_ONLY_CONTEXT_KEY = "__visualEditingSavedReferencesOnly";
|
|
9
|
+
export const savedReferencesOnlyOf = (context)=>{
|
|
10
|
+
const restricted = context[SAVED_REFERENCES_ONLY_CONTEXT_KEY];
|
|
11
|
+
return isPlainObject(restricted) ? restricted : null;
|
|
12
|
+
};
|
|
8
13
|
|
|
9
14
|
//# sourceMappingURL=readContext.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/server/unsavedRichText/readContext.ts"],"sourcesContent":["import type { PayloadRequest, RequestContext } from \"payload\";\n\nimport type { LiveRichTextField, VeEditorState } from \"../../shared/protocol.js\";\n\nimport { isPlainObject } from \"../../shared/plainObject.js\";\n\nexport const UNSAVED_RICH_TEXT_CONTEXT_KEY = \"__visualEditingUnsavedRichText\";\n\nexport type UnsavedRichText = {\n field: LiveRichTextField;\n isPlaced: boolean;\n state: VeEditorState;\n};\n\nexport const unsavedRichTextOf = (context: RequestContext): UnsavedRichText | null => {\n const unsaved = context[UNSAVED_RICH_TEXT_CONTEXT_KEY];\n return isPlainObject(unsaved) ? (unsaved as UnsavedRichText) : null;\n};\n\nexport const isUnsavedRichTextRead = (req: PayloadRequest): boolean =>\n unsavedRichTextOf(req.context) !== null;\n"],"names":["isPlainObject","UNSAVED_RICH_TEXT_CONTEXT_KEY","unsavedRichTextOf","context","unsaved","isUnsavedRichTextRead","req"],"mappings":"AAIA,SAASA,aAAa,QAAQ,8BAA8B;AAE5D,OAAO,MAAMC,gCAAgC,iCAAiC;AAQ9E,OAAO,MAAMC,oBAAoB,CAACC;IAChC,MAAMC,UAAUD,OAAO,CAACF,8BAA8B;IACtD,OAAOD,cAAcI,WAAYA,UAA8B;AACjE,EAAE;AAEF,OAAO,MAAMC,wBAAwB,CAACC,MACpCJ,kBAAkBI,IAAIH,OAAO,MAAM,KAAK"}
|
|
1
|
+
{"version":3,"sources":["../../../src/server/unsavedRichText/readContext.ts"],"sourcesContent":["import type { PayloadRequest, RequestContext } from \"payload\";\n\nimport type { LiveRichTextField, VeEditorState } from \"../../shared/protocol.js\";\n\nimport { isPlainObject } from \"../../shared/plainObject.js\";\n\nexport const UNSAVED_RICH_TEXT_CONTEXT_KEY = \"__visualEditingUnsavedRichText\";\n\nexport type UnsavedRichText = {\n field: LiveRichTextField;\n isPlaced: boolean;\n state: VeEditorState;\n};\n\nexport const unsavedRichTextOf = (context: RequestContext): UnsavedRichText | null => {\n const unsaved = context[UNSAVED_RICH_TEXT_CONTEXT_KEY];\n return isPlainObject(unsaved) ? (unsaved as UnsavedRichText) : null;\n};\n\nexport const isUnsavedRichTextRead = (req: PayloadRequest): boolean =>\n unsavedRichTextOf(req.context) !== null;\n\nexport const SAVED_REFERENCES_ONLY_CONTEXT_KEY = \"__visualEditingSavedReferencesOnly\";\n\nexport type SavedReferencesOnly = { field: LiveRichTextField; isApplied: boolean };\n\nexport const savedReferencesOnlyOf = (context: RequestContext): SavedReferencesOnly | null => {\n const restricted = context[SAVED_REFERENCES_ONLY_CONTEXT_KEY];\n return isPlainObject(restricted) ? (restricted as SavedReferencesOnly) : null;\n};\n"],"names":["isPlainObject","UNSAVED_RICH_TEXT_CONTEXT_KEY","unsavedRichTextOf","context","unsaved","isUnsavedRichTextRead","req","SAVED_REFERENCES_ONLY_CONTEXT_KEY","savedReferencesOnlyOf","restricted"],"mappings":"AAIA,SAASA,aAAa,QAAQ,8BAA8B;AAE5D,OAAO,MAAMC,gCAAgC,iCAAiC;AAQ9E,OAAO,MAAMC,oBAAoB,CAACC;IAChC,MAAMC,UAAUD,OAAO,CAACF,8BAA8B;IACtD,OAAOD,cAAcI,WAAYA,UAA8B;AACjE,EAAE;AAEF,OAAO,MAAMC,wBAAwB,CAACC,MACpCJ,kBAAkBI,IAAIH,OAAO,MAAM,KAAK;AAE1C,OAAO,MAAMI,oCAAoC,qCAAqC;AAItF,OAAO,MAAMC,wBAAwB,CAACL;IACpC,MAAMM,aAAaN,OAAO,CAACI,kCAAkC;IAC7D,OAAOP,cAAcS,cAAeA,aAAqC;AAC3E,EAAE"}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import type { Payload } from "payload";
|
|
2
|
+
export type IsPrivateCollection = (slug: unknown) => boolean;
|
|
3
|
+
export declare const isPrivateCollectionOf: (payload: Payload) => IsPrivateCollection;
|
|
4
|
+
export declare const withOnlyReferencesOf: (value: unknown, saved: unknown, isPrivateCollection: IsPrivateCollection) => unknown;
|
|
5
|
+
export declare const withHeldReferences: (value: unknown) => unknown;
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import { isPlainObject } from "../../shared/plainObject.js";
|
|
2
|
+
import { forEachEditorNode, mapEditorNodes, rootOf } from "../../shared/richText/editorNodes.js";
|
|
3
|
+
import { RELATED_VALUE_NODE_TYPES } from "../../shared/richText/nodeTypes.js";
|
|
4
|
+
import { documentKeyOf, relatedOf } from "../../shared/richText/references.js";
|
|
5
|
+
const HELD_REFERENCE_KEY = "__visualEditingHeldReference";
|
|
6
|
+
const COLLECTION_OF_PAYLOAD_PREFIX = "payload-";
|
|
7
|
+
export const isPrivateCollectionOf = (payload)=>(slug)=>typeof slug !== "string" || slug.startsWith(COLLECTION_OF_PAYLOAD_PREFIX) || Boolean(payload.collections[slug]?.config.auth);
|
|
8
|
+
const referenceKeysOf = (value)=>{
|
|
9
|
+
const keys = new Set();
|
|
10
|
+
forEachEditorNode(rootOf(value), (node)=>{
|
|
11
|
+
const related = relatedOf(node);
|
|
12
|
+
const key = related && documentKeyOf(related);
|
|
13
|
+
if (key !== null) keys.add(key);
|
|
14
|
+
});
|
|
15
|
+
return keys;
|
|
16
|
+
};
|
|
17
|
+
const withReference = (node, value)=>{
|
|
18
|
+
if (RELATED_VALUE_NODE_TYPES.has(node.type)) return {
|
|
19
|
+
...node,
|
|
20
|
+
value
|
|
21
|
+
};
|
|
22
|
+
const fields = node.fields;
|
|
23
|
+
return {
|
|
24
|
+
...node,
|
|
25
|
+
fields: {
|
|
26
|
+
...fields,
|
|
27
|
+
doc: {
|
|
28
|
+
...fields.doc,
|
|
29
|
+
value
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
};
|
|
33
|
+
};
|
|
34
|
+
const mapNodesOf = (value, map)=>{
|
|
35
|
+
const root = rootOf(value);
|
|
36
|
+
return root && isPlainObject(value) ? {
|
|
37
|
+
...value,
|
|
38
|
+
root: mapEditorNodes(root, map)
|
|
39
|
+
} : value;
|
|
40
|
+
};
|
|
41
|
+
export const withOnlyReferencesOf = (value, saved, isPrivateCollection)=>{
|
|
42
|
+
const savedKeys = referenceKeysOf(saved);
|
|
43
|
+
return mapNodesOf(value, (node)=>{
|
|
44
|
+
const related = relatedOf(node);
|
|
45
|
+
if (!related || related.value === null || related.value === undefined) return node;
|
|
46
|
+
const key = documentKeyOf(related);
|
|
47
|
+
const isResolved = key !== null && savedKeys.has(key) && !isPrivateCollection(related.relationTo);
|
|
48
|
+
if (isResolved) return node;
|
|
49
|
+
return {
|
|
50
|
+
...withReference(node, null),
|
|
51
|
+
[HELD_REFERENCE_KEY]: related.value
|
|
52
|
+
};
|
|
53
|
+
});
|
|
54
|
+
};
|
|
55
|
+
export const withHeldReferences = (value)=>mapNodesOf(value, (node)=>{
|
|
56
|
+
if (!Object.hasOwn(node, HELD_REFERENCE_KEY)) return node;
|
|
57
|
+
const { [HELD_REFERENCE_KEY]: held, ...rest } = node;
|
|
58
|
+
return withReference(rest, held);
|
|
59
|
+
});
|
|
60
|
+
|
|
61
|
+
//# sourceMappingURL=savedReferences.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/server/unsavedRichText/savedReferences.ts"],"sourcesContent":["import type { Payload } from \"payload\";\n\nimport type { PlainObject } from \"../../shared/plainObject.js\";\nimport type { EditorNode } from \"../../shared/richText/editorNodes.js\";\n\nimport { isPlainObject } from \"../../shared/plainObject.js\";\nimport { forEachEditorNode, mapEditorNodes, rootOf } from \"../../shared/richText/editorNodes.js\";\nimport { RELATED_VALUE_NODE_TYPES } from \"../../shared/richText/nodeTypes.js\";\nimport { documentKeyOf, relatedOf } from \"../../shared/richText/references.js\";\n\nconst HELD_REFERENCE_KEY = \"__visualEditingHeldReference\";\nconst COLLECTION_OF_PAYLOAD_PREFIX = \"payload-\";\n\nexport type IsPrivateCollection = (slug: unknown) => boolean;\n\nexport const isPrivateCollectionOf =\n (payload: Payload): IsPrivateCollection =>\n (slug) =>\n typeof slug !== \"string\" ||\n slug.startsWith(COLLECTION_OF_PAYLOAD_PREFIX) ||\n Boolean(payload.collections[slug]?.config.auth);\n\nconst referenceKeysOf = (value: unknown): Set<string> => {\n const keys = new Set<string>();\n forEachEditorNode(rootOf(value), (node) => {\n const related = relatedOf(node);\n const key = related && documentKeyOf(related);\n if (key !== null) keys.add(key);\n });\n return keys;\n};\n\nconst withReference = (node: EditorNode, value: unknown): EditorNode => {\n if (RELATED_VALUE_NODE_TYPES.has(node.type)) return { ...node, value };\n const fields = node.fields as PlainObject;\n return { ...node, fields: { ...fields, doc: { ...(fields.doc as PlainObject), value } } };\n};\n\nconst mapNodesOf = (value: unknown, map: (node: EditorNode) => EditorNode): unknown => {\n const root = rootOf(value);\n return root && isPlainObject(value) ? { ...value, root: mapEditorNodes(root, map) } : value;\n};\n\nexport const withOnlyReferencesOf = (\n value: unknown,\n saved: unknown,\n isPrivateCollection: IsPrivateCollection\n): unknown => {\n const savedKeys = referenceKeysOf(saved);\n return mapNodesOf(value, (node) => {\n const related = relatedOf(node);\n if (!related || related.value === null || related.value === undefined) return node;\n const key = documentKeyOf(related);\n const isResolved =\n key !== null && savedKeys.has(key) && !isPrivateCollection(related.relationTo);\n if (isResolved) return node;\n return { ...withReference(node, null), [HELD_REFERENCE_KEY]: related.value };\n });\n};\n\nexport const withHeldReferences = (value: unknown): unknown =>\n mapNodesOf(value, (node) => {\n if (!Object.hasOwn(node, HELD_REFERENCE_KEY)) return node;\n const { [HELD_REFERENCE_KEY]: held, ...rest } = node;\n return withReference(rest, held);\n });\n"],"names":["isPlainObject","forEachEditorNode","mapEditorNodes","rootOf","RELATED_VALUE_NODE_TYPES","documentKeyOf","relatedOf","HELD_REFERENCE_KEY","COLLECTION_OF_PAYLOAD_PREFIX","isPrivateCollectionOf","payload","slug","startsWith","Boolean","collections","config","auth","referenceKeysOf","value","keys","Set","node","related","key","add","withReference","has","type","fields","doc","mapNodesOf","map","root","withOnlyReferencesOf","saved","isPrivateCollection","savedKeys","undefined","isResolved","relationTo","withHeldReferences","Object","hasOwn","held","rest"],"mappings":"AAKA,SAASA,aAAa,QAAQ,8BAA8B;AAC5D,SAASC,iBAAiB,EAAEC,cAAc,EAAEC,MAAM,QAAQ,uCAAuC;AACjG,SAASC,wBAAwB,QAAQ,qCAAqC;AAC9E,SAASC,aAAa,EAAEC,SAAS,QAAQ,sCAAsC;AAE/E,MAAMC,qBAAqB;AAC3B,MAAMC,+BAA+B;AAIrC,OAAO,MAAMC,wBACX,CAACC,UACD,CAACC,OACC,OAAOA,SAAS,YAChBA,KAAKC,UAAU,CAACJ,iCAChBK,QAAQH,QAAQI,WAAW,CAACH,KAAK,EAAEI,OAAOC,MAAM;AAEpD,MAAMC,kBAAkB,CAACC;IACvB,MAAMC,OAAO,IAAIC;IACjBnB,kBAAkBE,OAAOe,QAAQ,CAACG;QAChC,MAAMC,UAAUhB,UAAUe;QAC1B,MAAME,MAAMD,WAAWjB,cAAciB;QACrC,IAAIC,QAAQ,MAAMJ,KAAKK,GAAG,CAACD;IAC7B;IACA,OAAOJ;AACT;AAEA,MAAMM,gBAAgB,CAACJ,MAAkBH;IACvC,IAAId,yBAAyBsB,GAAG,CAACL,KAAKM,IAAI,GAAG,OAAO;QAAE,GAAGN,IAAI;QAAEH;IAAM;IACrE,MAAMU,SAASP,KAAKO,MAAM;IAC1B,OAAO;QAAE,GAAGP,IAAI;QAAEO,QAAQ;YAAE,GAAGA,MAAM;YAAEC,KAAK;gBAAE,GAAID,OAAOC,GAAG;gBAAkBX;YAAM;QAAE;IAAE;AAC1F;AAEA,MAAMY,aAAa,CAACZ,OAAgBa;IAClC,MAAMC,OAAO7B,OAAOe;IACpB,OAAOc,QAAQhC,cAAckB,SAAS;QAAE,GAAGA,KAAK;QAAEc,MAAM9B,eAAe8B,MAAMD;IAAK,IAAIb;AACxF;AAEA,OAAO,MAAMe,uBAAuB,CAClCf,OACAgB,OACAC;IAEA,MAAMC,YAAYnB,gBAAgBiB;IAClC,OAAOJ,WAAWZ,OAAO,CAACG;QACxB,MAAMC,UAAUhB,UAAUe;QAC1B,IAAI,CAACC,WAAWA,QAAQJ,KAAK,KAAK,QAAQI,QAAQJ,KAAK,KAAKmB,WAAW,OAAOhB;QAC9E,MAAME,MAAMlB,cAAciB;QAC1B,MAAMgB,aACJf,QAAQ,QAAQa,UAAUV,GAAG,CAACH,QAAQ,CAACY,oBAAoBb,QAAQiB,UAAU;QAC/E,IAAID,YAAY,OAAOjB;QACvB,OAAO;YAAE,GAAGI,cAAcJ,MAAM,KAAK;YAAE,CAACd,mBAAmB,EAAEe,QAAQJ,KAAK;QAAC;IAC7E;AACF,EAAE;AAEF,OAAO,MAAMsB,qBAAqB,CAACtB,QACjCY,WAAWZ,OAAO,CAACG;QACjB,IAAI,CAACoB,OAAOC,MAAM,CAACrB,MAAMd,qBAAqB,OAAOc;QACrD,MAAM,EAAE,CAACd,mBAAmB,EAAEoC,IAAI,EAAE,GAAGC,MAAM,GAAGvB;QAChD,OAAOI,cAAcmB,MAAMD;IAC7B,GAAG"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { CollectionConfig, Config, GlobalConfig } from "payload";
|
|
2
|
+
type RootLivePreview = NonNullable<Config["admin"]>["livePreview"];
|
|
3
|
+
export type DocumentControlsOptions = {
|
|
4
|
+
rootLivePreview: RootLivePreview;
|
|
5
|
+
excludeFieldNames: string[];
|
|
6
|
+
instantPreview: boolean;
|
|
7
|
+
};
|
|
8
|
+
export declare const withDocumentControlsCollection: (collection: CollectionConfig, options: DocumentControlsOptions) => CollectionConfig;
|
|
9
|
+
export declare const withDocumentControlsGlobal: (global: GlobalConfig, options: DocumentControlsOptions) => GlobalConfig;
|
|
10
|
+
export {};
|
|
@@ -1,12 +1,20 @@
|
|
|
1
1
|
import { PACKAGE_NAME } from "../shared/packageName.js";
|
|
2
|
+
const PREVIEW_PAGE_BRIDGE_PATH = `${PACKAGE_NAME}/admin#PreviewPageBridge`;
|
|
2
3
|
const INSTANT_PREVIEW_COMPONENT_PATH = `${PACKAGE_NAME}/admin#InstantPreviewBroadcaster`;
|
|
3
4
|
const OPEN_FORM_ANNOUNCER_PATH = `${PACKAGE_NAME}/admin#OpenFormAnnouncer`;
|
|
4
5
|
const hasLivePreview = ({ admin, slug }, slugsPreviewedByRoot)=>Boolean(admin?.livePreview) || Boolean(slugsPreviewedByRoot?.includes(slug));
|
|
5
|
-
const
|
|
6
|
+
const documentControlsOf = (entity, slugsPreviewedByRoot, { excludeFieldNames, instantPreview })=>{
|
|
7
|
+
const isPreviewed = hasLivePreview(entity, slugsPreviewedByRoot);
|
|
8
|
+
return [
|
|
9
|
+
...isPreviewed ? [
|
|
10
|
+
{
|
|
11
|
+
path: PREVIEW_PAGE_BRIDGE_PATH
|
|
12
|
+
}
|
|
13
|
+
] : [],
|
|
6
14
|
{
|
|
7
15
|
path: OPEN_FORM_ANNOUNCER_PATH
|
|
8
16
|
},
|
|
9
|
-
...
|
|
17
|
+
...instantPreview && isPreviewed ? [
|
|
10
18
|
{
|
|
11
19
|
clientProps: {
|
|
12
20
|
excludeFieldNames
|
|
@@ -15,7 +23,9 @@ const instantPreviewControlsOf = (entity, slugsPreviewedByRoot, { excludeFieldNa
|
|
|
15
23
|
}
|
|
16
24
|
] : []
|
|
17
25
|
];
|
|
18
|
-
|
|
26
|
+
};
|
|
27
|
+
const withDocumentControlsIn = (entity, slotName, slugsPreviewedByRoot, options)=>{
|
|
28
|
+
const controls = documentControlsOf(entity, slugsPreviewedByRoot, options);
|
|
19
29
|
const components = entity.admin?.components;
|
|
20
30
|
const slot = components?.[slotName];
|
|
21
31
|
return {
|
|
@@ -28,14 +38,14 @@ const withInstantPreviewIn = (entity, slotName, slugsPreviewedByRoot, options)=>
|
|
|
28
38
|
...slot,
|
|
29
39
|
beforeDocumentControls: [
|
|
30
40
|
...slot?.beforeDocumentControls ?? [],
|
|
31
|
-
...
|
|
41
|
+
...controls
|
|
32
42
|
]
|
|
33
43
|
}
|
|
34
44
|
}
|
|
35
45
|
}
|
|
36
46
|
};
|
|
37
47
|
};
|
|
38
|
-
export const
|
|
39
|
-
export const
|
|
48
|
+
export const withDocumentControlsCollection = (collection, options)=>withDocumentControlsIn(collection, "edit", options.rootLivePreview?.collections, options);
|
|
49
|
+
export const withDocumentControlsGlobal = (global, options)=>withDocumentControlsIn(global, "elements", options.rootLivePreview?.globals, options);
|
|
40
50
|
|
|
41
|
-
//# sourceMappingURL=
|
|
51
|
+
//# sourceMappingURL=withDocumentControls.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/server/withDocumentControls.ts"],"sourcesContent":["import type { CollectionConfig, Config, CustomComponent, GlobalConfig } from \"payload\";\n\nimport { PACKAGE_NAME } from \"../shared/packageName.js\";\n\nconst PREVIEW_PAGE_BRIDGE_PATH = `${PACKAGE_NAME}/admin#PreviewPageBridge`;\nconst INSTANT_PREVIEW_COMPONENT_PATH = `${PACKAGE_NAME}/admin#InstantPreviewBroadcaster`;\nconst OPEN_FORM_ANNOUNCER_PATH = `${PACKAGE_NAME}/admin#OpenFormAnnouncer`;\n\ntype RootLivePreview = NonNullable<Config[\"admin\"]>[\"livePreview\"];\n\nexport type DocumentControlsOptions = {\n rootLivePreview: RootLivePreview;\n excludeFieldNames: string[];\n instantPreview: boolean;\n};\n\ntype SlotName = \"edit\" | \"elements\";\n\ntype ControlsSlot = { beforeDocumentControls?: CustomComponent[] };\n\ntype PreviewableEntity = {\n admin?: { components?: Partial<Record<SlotName, ControlsSlot>>; livePreview?: unknown };\n slug: string;\n};\n\nconst hasLivePreview = (\n { admin, slug }: PreviewableEntity,\n slugsPreviewedByRoot: readonly string[] | undefined\n): boolean => Boolean(admin?.livePreview) || Boolean(slugsPreviewedByRoot?.includes(slug));\n\nconst documentControlsOf = (\n entity: PreviewableEntity,\n slugsPreviewedByRoot: readonly string[] | undefined,\n { excludeFieldNames, instantPreview }: DocumentControlsOptions\n): CustomComponent[] => {\n const isPreviewed = hasLivePreview(entity, slugsPreviewedByRoot);\n return [\n ...(isPreviewed ? [{ path: PREVIEW_PAGE_BRIDGE_PATH }] : []),\n { path: OPEN_FORM_ANNOUNCER_PATH },\n ...(instantPreview && isPreviewed\n ? [{ clientProps: { excludeFieldNames }, path: INSTANT_PREVIEW_COMPONENT_PATH }]\n : []),\n ];\n};\n\nconst withDocumentControlsIn = <Entity extends PreviewableEntity>(\n entity: Entity,\n slotName: SlotName,\n slugsPreviewedByRoot: readonly string[] | undefined,\n options: DocumentControlsOptions\n): Entity => {\n const controls = documentControlsOf(entity, slugsPreviewedByRoot, options);\n const components = entity.admin?.components;\n const slot = components?.[slotName];\n return {\n ...entity,\n admin: {\n ...entity.admin,\n components: {\n ...components,\n [slotName]: {\n ...slot,\n beforeDocumentControls: [...(slot?.beforeDocumentControls ?? []), ...controls],\n },\n },\n },\n };\n};\n\nexport const withDocumentControlsCollection = (\n collection: CollectionConfig,\n options: DocumentControlsOptions\n): CollectionConfig =>\n withDocumentControlsIn(collection, \"edit\", options.rootLivePreview?.collections, options);\n\nexport const withDocumentControlsGlobal = (\n global: GlobalConfig,\n options: DocumentControlsOptions\n): GlobalConfig =>\n withDocumentControlsIn(global, \"elements\", options.rootLivePreview?.globals, options);\n"],"names":["PACKAGE_NAME","PREVIEW_PAGE_BRIDGE_PATH","INSTANT_PREVIEW_COMPONENT_PATH","OPEN_FORM_ANNOUNCER_PATH","hasLivePreview","admin","slug","slugsPreviewedByRoot","Boolean","livePreview","includes","documentControlsOf","entity","excludeFieldNames","instantPreview","isPreviewed","path","clientProps","withDocumentControlsIn","slotName","options","controls","components","slot","beforeDocumentControls","withDocumentControlsCollection","collection","rootLivePreview","collections","withDocumentControlsGlobal","global","globals"],"mappings":"AAEA,SAASA,YAAY,QAAQ,2BAA2B;AAExD,MAAMC,2BAA2B,CAAC,EAAED,aAAa,wBAAwB,CAAC;AAC1E,MAAME,iCAAiC,CAAC,EAAEF,aAAa,gCAAgC,CAAC;AACxF,MAAMG,2BAA2B,CAAC,EAAEH,aAAa,wBAAwB,CAAC;AAmB1E,MAAMI,iBAAiB,CACrB,EAAEC,KAAK,EAAEC,IAAI,EAAqB,EAClCC,uBACYC,QAAQH,OAAOI,gBAAgBD,QAAQD,sBAAsBG,SAASJ;AAEpF,MAAMK,qBAAqB,CACzBC,QACAL,sBACA,EAAEM,iBAAiB,EAAEC,cAAc,EAA2B;IAE9D,MAAMC,cAAcX,eAAeQ,QAAQL;IAC3C,OAAO;WACDQ,cAAc;YAAC;gBAAEC,MAAMf;YAAyB;SAAE,GAAG,EAAE;QAC3D;YAAEe,MAAMb;QAAyB;WAC7BW,kBAAkBC,cAClB;YAAC;gBAAEE,aAAa;oBAAEJ;gBAAkB;gBAAGG,MAAMd;YAA+B;SAAE,GAC9E,EAAE;KACP;AACH;AAEA,MAAMgB,yBAAyB,CAC7BN,QACAO,UACAZ,sBACAa;IAEA,MAAMC,WAAWV,mBAAmBC,QAAQL,sBAAsBa;IAClE,MAAME,aAAaV,OAAOP,KAAK,EAAEiB;IACjC,MAAMC,OAAOD,YAAY,CAACH,SAAS;IACnC,OAAO;QACL,GAAGP,MAAM;QACTP,OAAO;YACL,GAAGO,OAAOP,KAAK;YACfiB,YAAY;gBACV,GAAGA,UAAU;gBACb,CAACH,SAAS,EAAE;oBACV,GAAGI,IAAI;oBACPC,wBAAwB;2BAAKD,MAAMC,0BAA0B,EAAE;2BAAMH;qBAAS;gBAChF;YACF;QACF;IACF;AACF;AAEA,OAAO,MAAMI,iCAAiC,CAC5CC,YACAN,UAEAF,uBAAuBQ,YAAY,QAAQN,QAAQO,eAAe,EAAEC,aAAaR,SAAS;AAE5F,OAAO,MAAMS,6BAA6B,CACxCC,QACAV,UAEAF,uBAAuBY,QAAQ,YAAYV,QAAQO,eAAe,EAAEI,SAASX,SAAS"}
|
|
@@ -4,4 +4,5 @@ export type BuildAdminEditUrlArgs = Omit<VeIdentity, "key"> & {
|
|
|
4
4
|
adminBasePath?: string;
|
|
5
5
|
};
|
|
6
6
|
export type BuildAdminEditUrl = (args: BuildAdminEditUrlArgs) => string;
|
|
7
|
+
export declare const adminBaseOf: (adminBasePath: string) => string;
|
|
7
8
|
export declare const defaultBuildAdminEditUrl: BuildAdminEditUrl;
|
|
@@ -1,6 +1,10 @@
|
|
|
1
1
|
import { VE_FOCUS_PARAM } from "./protocol.js";
|
|
2
|
+
const TRAILING_SLASHES = /\/+$/u;
|
|
3
|
+
export const adminBaseOf = (adminBasePath)=>adminBasePath.replace(TRAILING_SLASHES, "");
|
|
2
4
|
export const defaultBuildAdminEditUrl = ({ docId, collectionSlug, kind, path, locale, adminBasePath = "/admin" })=>{
|
|
3
|
-
const
|
|
5
|
+
const admin = adminBaseOf(adminBasePath);
|
|
6
|
+
const slug = encodeURIComponent(collectionSlug);
|
|
7
|
+
const base = kind === "global" ? `${admin}/globals/${slug}` : `${admin}/collections/${slug}/${encodeURIComponent(String(docId))}`;
|
|
4
8
|
const parts = [];
|
|
5
9
|
if (path) parts.push(`${VE_FOCUS_PARAM}=${encodeURIComponent(path)}`);
|
|
6
10
|
if (locale) parts.push(`locale=${encodeURIComponent(locale)}`);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/shared/buildAdminEditUrl.ts"],"sourcesContent":["import type { VeIdentity } from \"./shared.js\";\n\nimport { VE_FOCUS_PARAM } from \"./protocol.js\";\n\nexport type BuildAdminEditUrlArgs = Omit<VeIdentity, \"key\"> & {\n locale?: string;\n adminBasePath?: string;\n};\n\nexport type BuildAdminEditUrl = (args: BuildAdminEditUrlArgs) => string;\n\nexport const defaultBuildAdminEditUrl: BuildAdminEditUrl = ({\n docId,\n collectionSlug,\n kind,\n path,\n locale,\n adminBasePath = \"/admin\",\n}) => {\n const base =\n kind === \"global\"\n ? `${
|
|
1
|
+
{"version":3,"sources":["../../src/shared/buildAdminEditUrl.ts"],"sourcesContent":["import type { VeIdentity } from \"./shared.js\";\n\nimport { VE_FOCUS_PARAM } from \"./protocol.js\";\n\nexport type BuildAdminEditUrlArgs = Omit<VeIdentity, \"key\"> & {\n locale?: string;\n adminBasePath?: string;\n};\n\nexport type BuildAdminEditUrl = (args: BuildAdminEditUrlArgs) => string;\n\nconst TRAILING_SLASHES = /\\/+$/u;\n\nexport const adminBaseOf = (adminBasePath: string): string =>\n adminBasePath.replace(TRAILING_SLASHES, \"\");\n\nexport const defaultBuildAdminEditUrl: BuildAdminEditUrl = ({\n docId,\n collectionSlug,\n kind,\n path,\n locale,\n adminBasePath = \"/admin\",\n}) => {\n const admin = adminBaseOf(adminBasePath);\n const slug = encodeURIComponent(collectionSlug);\n const base =\n kind === \"global\"\n ? `${admin}/globals/${slug}`\n : `${admin}/collections/${slug}/${encodeURIComponent(String(docId))}`;\n const parts: string[] = [];\n if (path) parts.push(`${VE_FOCUS_PARAM}=${encodeURIComponent(path)}`);\n if (locale) parts.push(`locale=${encodeURIComponent(locale)}`);\n return parts.length ? `${base}?${parts.join(\"&\")}` : base;\n};\n"],"names":["VE_FOCUS_PARAM","TRAILING_SLASHES","adminBaseOf","adminBasePath","replace","defaultBuildAdminEditUrl","docId","collectionSlug","kind","path","locale","admin","slug","encodeURIComponent","base","String","parts","push","length","join"],"mappings":"AAEA,SAASA,cAAc,QAAQ,gBAAgB;AAS/C,MAAMC,mBAAmB;AAEzB,OAAO,MAAMC,cAAc,CAACC,gBAC1BA,cAAcC,OAAO,CAACH,kBAAkB,IAAI;AAE9C,OAAO,MAAMI,2BAA8C,CAAC,EAC1DC,KAAK,EACLC,cAAc,EACdC,IAAI,EACJC,IAAI,EACJC,MAAM,EACNP,gBAAgB,QAAQ,EACzB;IACC,MAAMQ,QAAQT,YAAYC;IAC1B,MAAMS,OAAOC,mBAAmBN;IAChC,MAAMO,OACJN,SAAS,WACL,CAAC,EAAEG,MAAM,SAAS,EAAEC,KAAK,CAAC,GAC1B,CAAC,EAAED,MAAM,aAAa,EAAEC,KAAK,CAAC,EAAEC,mBAAmBE,OAAOT,QAAQ,CAAC;IACzE,MAAMU,QAAkB,EAAE;IAC1B,IAAIP,MAAMO,MAAMC,IAAI,CAAC,CAAC,EAAEjB,eAAe,CAAC,EAAEa,mBAAmBJ,MAAM,CAAC;IACpE,IAAIC,QAAQM,MAAMC,IAAI,CAAC,CAAC,OAAO,EAAEJ,mBAAmBH,QAAQ,CAAC;IAC7D,OAAOM,MAAME,MAAM,GAAG,CAAC,EAAEJ,KAAK,CAAC,EAAEE,MAAMG,IAAI,CAAC,KAAK,CAAC,GAAGL;AACvD,EAAE"}
|
|
@@ -7,6 +7,20 @@ export declare const DATA_VE_KEY_ATTR = "data-ve-key";
|
|
|
7
7
|
export declare const VE_IDENTITY_ATTRS: readonly string[];
|
|
8
8
|
export declare const VE_FOCUS_PARAM = "veFocus";
|
|
9
9
|
export type DocKind = "collection" | "global";
|
|
10
|
+
export declare const VE_READ_HEADER = "x-visual-editing";
|
|
11
|
+
export declare const VE_PREVIEW_GRANT_PATH = "/visual-editing/preview-grant";
|
|
12
|
+
export declare const VE_UNSAVED_RICH_TEXT_PATH = "/visual-editing/unsaved-rich-text";
|
|
13
|
+
export declare const VE_PREVIEW_GRANT_TYPE = "ve:preview-grant";
|
|
14
|
+
export type VePreviewGrantMessage = {
|
|
15
|
+
type: typeof VE_PREVIEW_GRANT_TYPE;
|
|
16
|
+
grant: string;
|
|
17
|
+
expiresAt: number;
|
|
18
|
+
};
|
|
19
|
+
export declare const VE_PREVIEW_GRANT_REQUEST_TYPE = "ve:preview-grant-request";
|
|
20
|
+
export type VePreviewGrantRequestMessage = {
|
|
21
|
+
type: typeof VE_PREVIEW_GRANT_REQUEST_TYPE;
|
|
22
|
+
pageId: string;
|
|
23
|
+
};
|
|
10
24
|
export declare const VE_MESSAGE_TYPE = "ve:open-field";
|
|
11
25
|
export type VeOpenFieldMessage = {
|
|
12
26
|
type: typeof VE_MESSAGE_TYPE;
|
|
@@ -43,6 +57,10 @@ export declare const VE_ANNOUNCE_REQUEST_TYPE = "ve:announce-request";
|
|
|
43
57
|
export type VeAnnounceRequestMessage = {
|
|
44
58
|
type: typeof VE_ANNOUNCE_REQUEST_TYPE;
|
|
45
59
|
};
|
|
60
|
+
export declare const VE_DOCUMENT_SAVED_TYPE = "ve:document-saved";
|
|
61
|
+
export type VeDocumentSavedMessage = Partial<VeLiveDocument> & {
|
|
62
|
+
type: typeof VE_DOCUMENT_SAVED_TYPE;
|
|
63
|
+
};
|
|
46
64
|
export declare const VE_FIELD_SNAPSHOT_TYPE = "ve:field-snapshot";
|
|
47
65
|
export type VeFieldSnapshotEntry = {
|
|
48
66
|
key: string;
|
package/dist/shared/protocol.js
CHANGED
|
@@ -13,12 +13,18 @@ export const VE_IDENTITY_ATTRS = [
|
|
|
13
13
|
DATA_VE_KEY_ATTR
|
|
14
14
|
];
|
|
15
15
|
export const VE_FOCUS_PARAM = "veFocus";
|
|
16
|
+
export const VE_READ_HEADER = "x-visual-editing";
|
|
17
|
+
export const VE_PREVIEW_GRANT_PATH = "/visual-editing/preview-grant";
|
|
18
|
+
export const VE_UNSAVED_RICH_TEXT_PATH = "/visual-editing/unsaved-rich-text";
|
|
19
|
+
export const VE_PREVIEW_GRANT_TYPE = "ve:preview-grant";
|
|
20
|
+
export const VE_PREVIEW_GRANT_REQUEST_TYPE = "ve:preview-grant-request";
|
|
16
21
|
export const VE_MESSAGE_TYPE = "ve:open-field";
|
|
17
22
|
export const DATA_VE_LIVE_ATTR = "data-ve-live";
|
|
18
23
|
export const VE_LIVE_OFF = "off";
|
|
19
24
|
export const VE_FIELDS_RENDERED_TYPE = "ve:fields-rendered";
|
|
20
25
|
export const VE_RICH_TEXT_RENDERED_TYPE = "ve:rich-text-rendered";
|
|
21
26
|
export const VE_ANNOUNCE_REQUEST_TYPE = "ve:announce-request";
|
|
27
|
+
export const VE_DOCUMENT_SAVED_TYPE = "ve:document-saved";
|
|
22
28
|
export const VE_FIELD_SNAPSHOT_TYPE = "ve:field-snapshot";
|
|
23
29
|
export const VE_FIELD_PATCH_TYPE = "ve:field-patch";
|
|
24
30
|
export const VE_RICH_TEXT_STRUCTURE_TYPE = "ve:rich-text-structure";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/shared/protocol.ts"],"sourcesContent":["export const DATA_VE_PATH_ATTR = \"data-ve-path\";\nexport const DATA_VE_DOC_ID_ATTR = \"data-ve-doc-id\";\nexport const DATA_VE_COLLECTION_ATTR = \"data-ve-collection\";\nexport const DATA_VE_KIND_ATTR = \"data-ve-kind\";\nexport const DATA_VE_LOCALE_ATTR = \"data-ve-locale\";\nexport const DATA_VE_KEY_ATTR = \"data-ve-key\";\n\nexport const VE_IDENTITY_ATTRS: readonly string[] = [\n DATA_VE_PATH_ATTR,\n DATA_VE_DOC_ID_ATTR,\n DATA_VE_COLLECTION_ATTR,\n DATA_VE_KIND_ATTR,\n DATA_VE_LOCALE_ATTR,\n DATA_VE_KEY_ATTR,\n];\n\nexport const VE_FOCUS_PARAM = \"veFocus\";\n\nexport type DocKind = \"collection\" | \"global\";\n\nexport const VE_MESSAGE_TYPE = \"ve:open-field\";\n\nexport type VeOpenFieldMessage = {\n type: typeof VE_MESSAGE_TYPE;\n path: string;\n key?: string;\n docId?: string;\n collectionSlug: string;\n kind: DocKind;\n locale?: string;\n};\n\nexport const DATA_VE_LIVE_ATTR = \"data-ve-live\";\nexport const VE_LIVE_OFF = \"off\";\n\nexport type VeDocument = {\n collectionSlug: string;\n kind: DocKind;\n docId?: string;\n};\n\nexport type VeLiveDocument = VeDocument & {\n locale?: string;\n};\n\nexport type VeRenderedFields = VeDocument & {\n keys: string[];\n};\n\nexport const VE_FIELDS_RENDERED_TYPE = \"ve:fields-rendered\";\n\nexport const VE_RICH_TEXT_RENDERED_TYPE = \"ve:rich-text-rendered\";\n\nexport type VeRenderedType = typeof VE_FIELDS_RENDERED_TYPE | typeof VE_RICH_TEXT_RENDERED_TYPE;\n\nexport type VeRenderedMessage<Type extends VeRenderedType> = {\n type: Type;\n pageId: string;\n locale?: string;\n rendered: VeRenderedFields[];\n};\n\nexport const VE_ANNOUNCE_REQUEST_TYPE = \"ve:announce-request\";\n\nexport type VeAnnounceRequestMessage = {\n type: typeof VE_ANNOUNCE_REQUEST_TYPE;\n};\n\nexport const VE_FIELD_SNAPSHOT_TYPE = \"ve:field-snapshot\";\n\nexport type VeFieldSnapshotEntry = {\n key: string;\n saved: string;\n value: string;\n};\n\nexport type VeFieldSnapshotMessage = VeLiveDocument & {\n type: typeof VE_FIELD_SNAPSHOT_TYPE;\n fields: VeFieldSnapshotEntry[];\n};\n\nexport const VE_FIELD_PATCH_TYPE = \"ve:field-patch\";\n\nexport type VeFieldPatch = {\n key: string;\n value: string;\n};\n\nexport type VeFieldPatchMessage = VeLiveDocument & {\n type: typeof VE_FIELD_PATCH_TYPE;\n patches: VeFieldPatch[];\n};\n\nexport const VE_RICH_TEXT_STRUCTURE_TYPE = \"ve:rich-text-structure\";\n\nexport type VeEditorState = Record<string, unknown>;\n\nexport type VeRichTextStructureMessage = VeLiveDocument & {\n type: typeof VE_RICH_TEXT_STRUCTURE_TYPE;\n key: string;\n shape: string;\n state: VeEditorState | null;\n};\n\nexport type LiveRichTextField = VeDocument & {\n key: string;\n};\n\nexport type LiveRichTextRequest = {\n field: LiveRichTextField;\n locale?: string;\n state: unknown;\n};\n"],"names":["DATA_VE_PATH_ATTR","DATA_VE_DOC_ID_ATTR","DATA_VE_COLLECTION_ATTR","DATA_VE_KIND_ATTR","DATA_VE_LOCALE_ATTR","DATA_VE_KEY_ATTR","VE_IDENTITY_ATTRS","VE_FOCUS_PARAM","VE_MESSAGE_TYPE","DATA_VE_LIVE_ATTR","VE_LIVE_OFF","VE_FIELDS_RENDERED_TYPE","VE_RICH_TEXT_RENDERED_TYPE","VE_ANNOUNCE_REQUEST_TYPE","VE_FIELD_SNAPSHOT_TYPE","VE_FIELD_PATCH_TYPE","VE_RICH_TEXT_STRUCTURE_TYPE"],"mappings":"AAAA,OAAO,MAAMA,oBAAoB,eAAe;AAChD,OAAO,MAAMC,sBAAsB,iBAAiB;AACpD,OAAO,MAAMC,0BAA0B,qBAAqB;AAC5D,OAAO,MAAMC,oBAAoB,eAAe;AAChD,OAAO,MAAMC,sBAAsB,iBAAiB;AACpD,OAAO,MAAMC,mBAAmB,cAAc;AAE9C,OAAO,MAAMC,oBAAuC;IAClDN;IACAC;IACAC;IACAC;IACAC;IACAC;CACD,CAAC;AAEF,OAAO,MAAME,iBAAiB,UAAU;AAIxC,OAAO,MAAMC,kBAAkB,gBAAgB;AAY/C,OAAO,MAAMC,oBAAoB,eAAe;AAChD,OAAO,MAAMC,cAAc,MAAM;AAgBjC,OAAO,MAAMC,0BAA0B,qBAAqB;AAE5D,OAAO,MAAMC,6BAA6B,wBAAwB;AAWlE,OAAO,MAAMC,2BAA2B,sBAAsB;AAM9D,OAAO,MAAMC,yBAAyB,oBAAoB;AAa1D,OAAO,MAAMC,sBAAsB,iBAAiB;AAYpD,OAAO,MAAMC,8BAA8B,yBAAyB"}
|
|
1
|
+
{"version":3,"sources":["../../src/shared/protocol.ts"],"sourcesContent":["export const DATA_VE_PATH_ATTR = \"data-ve-path\";\nexport const DATA_VE_DOC_ID_ATTR = \"data-ve-doc-id\";\nexport const DATA_VE_COLLECTION_ATTR = \"data-ve-collection\";\nexport const DATA_VE_KIND_ATTR = \"data-ve-kind\";\nexport const DATA_VE_LOCALE_ATTR = \"data-ve-locale\";\nexport const DATA_VE_KEY_ATTR = \"data-ve-key\";\n\nexport const VE_IDENTITY_ATTRS: readonly string[] = [\n DATA_VE_PATH_ATTR,\n DATA_VE_DOC_ID_ATTR,\n DATA_VE_COLLECTION_ATTR,\n DATA_VE_KIND_ATTR,\n DATA_VE_LOCALE_ATTR,\n DATA_VE_KEY_ATTR,\n];\n\nexport const VE_FOCUS_PARAM = \"veFocus\";\n\nexport type DocKind = \"collection\" | \"global\";\n\nexport const VE_READ_HEADER = \"x-visual-editing\";\n\nexport const VE_PREVIEW_GRANT_PATH = \"/visual-editing/preview-grant\";\n\nexport const VE_UNSAVED_RICH_TEXT_PATH = \"/visual-editing/unsaved-rich-text\";\n\nexport const VE_PREVIEW_GRANT_TYPE = \"ve:preview-grant\";\n\nexport type VePreviewGrantMessage = {\n type: typeof VE_PREVIEW_GRANT_TYPE;\n grant: string;\n expiresAt: number;\n};\n\nexport const VE_PREVIEW_GRANT_REQUEST_TYPE = \"ve:preview-grant-request\";\n\nexport type VePreviewGrantRequestMessage = {\n type: typeof VE_PREVIEW_GRANT_REQUEST_TYPE;\n pageId: string;\n};\n\nexport const VE_MESSAGE_TYPE = \"ve:open-field\";\n\nexport type VeOpenFieldMessage = {\n type: typeof VE_MESSAGE_TYPE;\n path: string;\n key?: string;\n docId?: string;\n collectionSlug: string;\n kind: DocKind;\n locale?: string;\n};\n\nexport const DATA_VE_LIVE_ATTR = \"data-ve-live\";\nexport const VE_LIVE_OFF = \"off\";\n\nexport type VeDocument = {\n collectionSlug: string;\n kind: DocKind;\n docId?: string;\n};\n\nexport type VeLiveDocument = VeDocument & {\n locale?: string;\n};\n\nexport type VeRenderedFields = VeDocument & {\n keys: string[];\n};\n\nexport const VE_FIELDS_RENDERED_TYPE = \"ve:fields-rendered\";\n\nexport const VE_RICH_TEXT_RENDERED_TYPE = \"ve:rich-text-rendered\";\n\nexport type VeRenderedType = typeof VE_FIELDS_RENDERED_TYPE | typeof VE_RICH_TEXT_RENDERED_TYPE;\n\nexport type VeRenderedMessage<Type extends VeRenderedType> = {\n type: Type;\n pageId: string;\n locale?: string;\n rendered: VeRenderedFields[];\n};\n\nexport const VE_ANNOUNCE_REQUEST_TYPE = \"ve:announce-request\";\n\nexport type VeAnnounceRequestMessage = {\n type: typeof VE_ANNOUNCE_REQUEST_TYPE;\n};\n\nexport const VE_DOCUMENT_SAVED_TYPE = \"ve:document-saved\";\n\nexport type VeDocumentSavedMessage = Partial<VeLiveDocument> & {\n type: typeof VE_DOCUMENT_SAVED_TYPE;\n};\n\nexport const VE_FIELD_SNAPSHOT_TYPE = \"ve:field-snapshot\";\n\nexport type VeFieldSnapshotEntry = {\n key: string;\n saved: string;\n value: string;\n};\n\nexport type VeFieldSnapshotMessage = VeLiveDocument & {\n type: typeof VE_FIELD_SNAPSHOT_TYPE;\n fields: VeFieldSnapshotEntry[];\n};\n\nexport const VE_FIELD_PATCH_TYPE = \"ve:field-patch\";\n\nexport type VeFieldPatch = {\n key: string;\n value: string;\n};\n\nexport type VeFieldPatchMessage = VeLiveDocument & {\n type: typeof VE_FIELD_PATCH_TYPE;\n patches: VeFieldPatch[];\n};\n\nexport const VE_RICH_TEXT_STRUCTURE_TYPE = \"ve:rich-text-structure\";\n\nexport type VeEditorState = Record<string, unknown>;\n\nexport type VeRichTextStructureMessage = VeLiveDocument & {\n type: typeof VE_RICH_TEXT_STRUCTURE_TYPE;\n key: string;\n shape: string;\n state: VeEditorState | null;\n};\n\nexport type LiveRichTextField = VeDocument & {\n key: string;\n};\n\nexport type LiveRichTextRequest = {\n field: LiveRichTextField;\n locale?: string;\n state: unknown;\n};\n"],"names":["DATA_VE_PATH_ATTR","DATA_VE_DOC_ID_ATTR","DATA_VE_COLLECTION_ATTR","DATA_VE_KIND_ATTR","DATA_VE_LOCALE_ATTR","DATA_VE_KEY_ATTR","VE_IDENTITY_ATTRS","VE_FOCUS_PARAM","VE_READ_HEADER","VE_PREVIEW_GRANT_PATH","VE_UNSAVED_RICH_TEXT_PATH","VE_PREVIEW_GRANT_TYPE","VE_PREVIEW_GRANT_REQUEST_TYPE","VE_MESSAGE_TYPE","DATA_VE_LIVE_ATTR","VE_LIVE_OFF","VE_FIELDS_RENDERED_TYPE","VE_RICH_TEXT_RENDERED_TYPE","VE_ANNOUNCE_REQUEST_TYPE","VE_DOCUMENT_SAVED_TYPE","VE_FIELD_SNAPSHOT_TYPE","VE_FIELD_PATCH_TYPE","VE_RICH_TEXT_STRUCTURE_TYPE"],"mappings":"AAAA,OAAO,MAAMA,oBAAoB,eAAe;AAChD,OAAO,MAAMC,sBAAsB,iBAAiB;AACpD,OAAO,MAAMC,0BAA0B,qBAAqB;AAC5D,OAAO,MAAMC,oBAAoB,eAAe;AAChD,OAAO,MAAMC,sBAAsB,iBAAiB;AACpD,OAAO,MAAMC,mBAAmB,cAAc;AAE9C,OAAO,MAAMC,oBAAuC;IAClDN;IACAC;IACAC;IACAC;IACAC;IACAC;CACD,CAAC;AAEF,OAAO,MAAME,iBAAiB,UAAU;AAIxC,OAAO,MAAMC,iBAAiB,mBAAmB;AAEjD,OAAO,MAAMC,wBAAwB,gCAAgC;AAErE,OAAO,MAAMC,4BAA4B,oCAAoC;AAE7E,OAAO,MAAMC,wBAAwB,mBAAmB;AAQxD,OAAO,MAAMC,gCAAgC,2BAA2B;AAOxE,OAAO,MAAMC,kBAAkB,gBAAgB;AAY/C,OAAO,MAAMC,oBAAoB,eAAe;AAChD,OAAO,MAAMC,cAAc,MAAM;AAgBjC,OAAO,MAAMC,0BAA0B,qBAAqB;AAE5D,OAAO,MAAMC,6BAA6B,wBAAwB;AAWlE,OAAO,MAAMC,2BAA2B,sBAAsB;AAM9D,OAAO,MAAMC,yBAAyB,oBAAoB;AAM1D,OAAO,MAAMC,yBAAyB,oBAAoB;AAa1D,OAAO,MAAMC,sBAAsB,iBAAiB;AAYpD,OAAO,MAAMC,8BAA8B,yBAAyB"}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { isPlainObject } from "../plainObject.js";
|
|
2
|
+
import { rootOf } from "./editorNodes.js";
|
|
3
|
+
const MAX_EDITOR_STATE_NESTING = 256;
|
|
4
|
+
const ROOT_NODE_TYPE = "root";
|
|
5
|
+
const isNestedWithin = (posted, maxNesting)=>{
|
|
6
|
+
const pending = [
|
|
7
|
+
{
|
|
8
|
+
nesting: 0,
|
|
9
|
+
value: posted
|
|
10
|
+
}
|
|
11
|
+
];
|
|
12
|
+
for(let next = pending.pop(); next !== undefined; next = pending.pop()){
|
|
13
|
+
const { nesting, value } = next;
|
|
14
|
+
if (typeof value !== "object" || value === null) continue;
|
|
15
|
+
if (nesting === maxNesting) return false;
|
|
16
|
+
for (const child of Object.values(value))pending.push({
|
|
17
|
+
nesting: nesting + 1,
|
|
18
|
+
value: child
|
|
19
|
+
});
|
|
20
|
+
}
|
|
21
|
+
return true;
|
|
22
|
+
};
|
|
23
|
+
const isNodeTree = (node)=>{
|
|
24
|
+
if (!isPlainObject(node) || typeof node.type !== "string") return false;
|
|
25
|
+
const { children } = node;
|
|
26
|
+
return children === undefined || Array.isArray(children) && children.every(isNodeTree);
|
|
27
|
+
};
|
|
28
|
+
export const isEditorStateTree = (state)=>{
|
|
29
|
+
const root = rootOf(state);
|
|
30
|
+
if (!root || !isNestedWithin(state, MAX_EDITOR_STATE_NESTING)) return false;
|
|
31
|
+
return root.type === ROOT_NODE_TYPE && isNodeTree(root);
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
//# sourceMappingURL=editorStateTree.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/shared/richText/editorStateTree.ts"],"sourcesContent":["import type { VeEditorState } from \"../protocol.js\";\n\nimport { isPlainObject } from \"../plainObject.js\";\nimport { rootOf } from \"./editorNodes.js\";\n\nconst MAX_EDITOR_STATE_NESTING = 256;\n\nconst ROOT_NODE_TYPE = \"root\";\n\ntype Nested = { nesting: number; value: unknown };\n\nconst isNestedWithin = (posted: unknown, maxNesting: number): boolean => {\n const pending: Nested[] = [{ nesting: 0, value: posted }];\n for (let next = pending.pop(); next !== undefined; next = pending.pop()) {\n const { nesting, value } = next;\n if (typeof value !== \"object\" || value === null) continue;\n if (nesting === maxNesting) return false;\n for (const child of Object.values(value)) pending.push({ nesting: nesting + 1, value: child });\n }\n return true;\n};\n\nconst isNodeTree = (node: unknown): boolean => {\n if (!isPlainObject(node) || typeof node.type !== \"string\") return false;\n const { children } = node;\n return children === undefined || (Array.isArray(children) && children.every(isNodeTree));\n};\n\nexport const isEditorStateTree = (state: unknown): state is VeEditorState => {\n const root = rootOf(state);\n if (!root || !isNestedWithin(state, MAX_EDITOR_STATE_NESTING)) return false;\n return root.type === ROOT_NODE_TYPE && isNodeTree(root);\n};\n"],"names":["isPlainObject","rootOf","MAX_EDITOR_STATE_NESTING","ROOT_NODE_TYPE","isNestedWithin","posted","maxNesting","pending","nesting","value","next","pop","undefined","child","Object","values","push","isNodeTree","node","type","children","Array","isArray","every","isEditorStateTree","state","root"],"mappings":"AAEA,SAASA,aAAa,QAAQ,oBAAoB;AAClD,SAASC,MAAM,QAAQ,mBAAmB;AAE1C,MAAMC,2BAA2B;AAEjC,MAAMC,iBAAiB;AAIvB,MAAMC,iBAAiB,CAACC,QAAiBC;IACvC,MAAMC,UAAoB;QAAC;YAAEC,SAAS;YAAGC,OAAOJ;QAAO;KAAE;IACzD,IAAK,IAAIK,OAAOH,QAAQI,GAAG,IAAID,SAASE,WAAWF,OAAOH,QAAQI,GAAG,GAAI;QACvE,MAAM,EAAEH,OAAO,EAAEC,KAAK,EAAE,GAAGC;QAC3B,IAAI,OAAOD,UAAU,YAAYA,UAAU,MAAM;QACjD,IAAID,YAAYF,YAAY,OAAO;QACnC,KAAK,MAAMO,SAASC,OAAOC,MAAM,CAACN,OAAQF,QAAQS,IAAI,CAAC;YAAER,SAASA,UAAU;YAAGC,OAAOI;QAAM;IAC9F;IACA,OAAO;AACT;AAEA,MAAMI,aAAa,CAACC;IAClB,IAAI,CAAClB,cAAckB,SAAS,OAAOA,KAAKC,IAAI,KAAK,UAAU,OAAO;IAClE,MAAM,EAAEC,QAAQ,EAAE,GAAGF;IACrB,OAAOE,aAAaR,aAAcS,MAAMC,OAAO,CAACF,aAAaA,SAASG,KAAK,CAACN;AAC9E;AAEA,OAAO,MAAMO,oBAAoB,CAACC;IAChC,MAAMC,OAAOzB,OAAOwB;IACpB,IAAI,CAACC,QAAQ,CAACtB,eAAeqB,OAAOvB,2BAA2B,OAAO;IACtE,OAAOwB,KAAKP,IAAI,KAAKhB,kBAAkBc,WAAWS;AACpD,EAAE"}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { withMarker } from "
|
|
2
|
-
import { toRichTextNodeMarker } from "
|
|
3
|
-
import { shapeOf } from "
|
|
4
|
-
import { addressOf, forEachTextLeaf } from "
|
|
5
|
-
import { rootOf } from "
|
|
1
|
+
import { withMarker } from "../stegaText.js";
|
|
2
|
+
import { toRichTextNodeMarker } from "./nodeKey.js";
|
|
3
|
+
import { shapeOf } from "./shapeOf.js";
|
|
4
|
+
import { addressOf, forEachTextLeaf } from "./textLeaves.js";
|
|
5
|
+
import { rootOf } from "./editorNodes.js";
|
|
6
6
|
export const markTextLeaves = (editorState, fieldAddress)=>{
|
|
7
7
|
const root = rootOf(editorState);
|
|
8
8
|
const shape = shapeOf(editorState, fieldAddress);
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/shared/richText/markTextLeaves.ts"],"sourcesContent":["import { withMarker } from \"../stegaText.js\";\nimport { toRichTextNodeMarker } from \"./nodeKey.js\";\nimport { shapeOf } from \"./shapeOf.js\";\nimport { addressOf, forEachTextLeaf } from \"./textLeaves.js\";\nimport { rootOf } from \"./editorNodes.js\";\n\nexport const markTextLeaves = (editorState: unknown, fieldAddress: string): void => {\n const root = rootOf(editorState);\n const shape = shapeOf(editorState, fieldAddress);\n if (!root || shape === null) return;\n forEachTextLeaf(root, (leaf, indexes) => {\n if (leaf.text === \"\") return;\n leaf.text = withMarker(leaf.text, toRichTextNodeMarker(addressOf(indexes), shape));\n });\n};\n"],"names":["withMarker","toRichTextNodeMarker","shapeOf","addressOf","forEachTextLeaf","rootOf","markTextLeaves","editorState","fieldAddress","root","shape","leaf","indexes","text"],"mappings":"AAAA,SAASA,UAAU,QAAQ,kBAAkB;AAC7C,SAASC,oBAAoB,QAAQ,eAAe;AACpD,SAASC,OAAO,QAAQ,eAAe;AACvC,SAASC,SAAS,EAAEC,eAAe,QAAQ,kBAAkB;AAC7D,SAASC,MAAM,QAAQ,mBAAmB;AAE1C,OAAO,MAAMC,iBAAiB,CAACC,aAAsBC;IACnD,MAAMC,OAAOJ,OAAOE;IACpB,MAAMG,QAAQR,QAAQK,aAAaC;IACnC,IAAI,CAACC,QAAQC,UAAU,MAAM;IAC7BN,gBAAgBK,MAAM,CAACE,MAAMC;QAC3B,IAAID,KAAKE,IAAI,KAAK,IAAI;QACtBF,KAAKE,IAAI,GAAGb,WAAWW,KAAKE,IAAI,EAAEZ,qBAAqBE,UAAUS,UAAUF;IAC7E;AACF,EAAE"}
|
|
@@ -8,6 +8,7 @@ export type RichTextNodeMarker = {
|
|
|
8
8
|
shape: string;
|
|
9
9
|
};
|
|
10
10
|
export declare const isRichTextNodeKey: (key: string) => boolean;
|
|
11
|
+
export declare const fieldKeyOfRichTextNode: (key: string) => string | null;
|
|
11
12
|
export declare const richTextNodeKeyOf: ({ address, fieldKey, shape }: RichTextNodeAddress) => string;
|
|
12
|
-
export declare const toRichTextNodeMarker: (address: string, shape: string) =>
|
|
13
|
-
export declare const fromRichTextNodeMarker: (
|
|
13
|
+
export declare const toRichTextNodeMarker: (address: string, shape: string) => string;
|
|
14
|
+
export declare const fromRichTextNodeMarker: (payload: unknown) => RichTextNodeMarker | null;
|