@supernova-studio/client 1.96.5 → 1.96.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.mts +101428 -143199
- package/dist/index.d.ts +101428 -143199
- package/dist/index.js +489 -99
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +5607 -5217
- package/dist/index.mjs.map +1 -1
- package/package.json +20 -9
- package/src/api/client.ts +62 -0
- package/src/api/conversion/analytics/index.ts +3 -0
- package/src/api/conversion/analytics/page-visits-to-comparison-dto.ts +65 -0
- package/src/api/conversion/analytics/page-visits-to-dto.ts +68 -0
- package/src/api/conversion/analytics/page-visits-to-heatmap-dto.ts +49 -0
- package/src/api/conversion/documentation/documentation-group-v1-to-dto.ts +114 -0
- package/src/api/conversion/documentation/documentation-group-v2-to-dto.ts +91 -0
- package/src/api/conversion/documentation/documentation-item-configuration-v1-to-dto.ts +52 -0
- package/src/api/conversion/documentation/documentation-item-configuration-v2-to-dto.ts +34 -0
- package/src/api/conversion/documentation/documentation-page-to-dto-utils.ts +134 -0
- package/src/api/conversion/documentation/documentation-page-v1-to-dto.ts +69 -0
- package/src/api/conversion/documentation/documentation-page-v2-to-dto.ts +84 -0
- package/src/api/conversion/documentation/documentation-settings-to-dto.ts +14 -0
- package/src/api/conversion/documentation/index.ts +8 -0
- package/src/api/conversion/export/index.ts +1 -0
- package/src/api/conversion/export/pipeline.ts +27 -0
- package/src/api/conversion/index.ts +4 -0
- package/src/api/conversion/integrations/git.ts +37 -0
- package/src/api/conversion/integrations/index.ts +2 -0
- package/src/api/conversion/integrations/integration.ts +37 -0
- package/src/api/dto/access-tokens/access-token.ts +45 -0
- package/src/api/dto/access-tokens/index.ts +1 -0
- package/src/api/dto/aux/color.ts +7 -0
- package/src/api/dto/aux/index.ts +4 -0
- package/src/api/dto/aux/meta.ts +8 -0
- package/src/api/dto/aux/object-metadata.ts +29 -0
- package/src/api/dto/aux/pagination.ts +8 -0
- package/src/api/dto/bff/app-bootstrap-data.ts +20 -0
- package/src/api/dto/bff/index.ts +1 -0
- package/src/api/dto/collections/index.ts +1 -0
- package/src/api/dto/collections/token-collection.ts +32 -0
- package/src/api/dto/design-systems/brand.ts +44 -0
- package/src/api/dto/design-systems/code-component-usage.ts +52 -0
- package/src/api/dto/design-systems/code-component.ts +101 -0
- package/src/api/dto/design-systems/code-history.ts +43 -0
- package/src/api/dto/design-systems/code-scan.ts +29 -0
- package/src/api/dto/design-systems/code-snapshots.ts +46 -0
- package/src/api/dto/design-systems/component.ts +40 -0
- package/src/api/dto/design-systems/contact.ts +11 -0
- package/src/api/dto/design-systems/data-source.ts +216 -0
- package/src/api/dto/design-systems/design-system.ts +75 -0
- package/src/api/dto/design-systems/documentation-search.ts +31 -0
- package/src/api/dto/design-systems/elements-diff.ts +14 -0
- package/src/api/dto/design-systems/figma-variables.ts +122 -0
- package/src/api/dto/design-systems/file.ts +71 -0
- package/src/api/dto/design-systems/import-job.ts +62 -0
- package/src/api/dto/design-systems/index.ts +24 -0
- package/src/api/dto/design-systems/members.ts +52 -0
- package/src/api/dto/design-systems/redirects.ts +33 -0
- package/src/api/dto/design-systems/role.ts +11 -0
- package/src/api/dto/design-systems/stats.ts +20 -0
- package/src/api/dto/design-systems/storybook.ts +45 -0
- package/src/api/dto/design-systems/user-design-systems.ts +10 -0
- package/src/api/dto/design-systems/version-room.ts +12 -0
- package/src/api/dto/design-systems/version.ts +56 -0
- package/src/api/dto/design-systems/view.ts +45 -0
- package/src/api/dto/design-tokens/design-token.ts +78 -0
- package/src/api/dto/design-tokens/index.ts +1 -0
- package/src/api/dto/documentation/analytics-v2.ts +80 -0
- package/src/api/dto/documentation/analytics.ts +32 -0
- package/src/api/dto/documentation/anchor.ts +15 -0
- package/src/api/dto/documentation/approvals.ts +21 -0
- package/src/api/dto/documentation/block-definition.ts +28 -0
- package/src/api/dto/documentation/block.ts +6 -0
- package/src/api/dto/documentation/documentation-page-snapshot.ts +18 -0
- package/src/api/dto/documentation/documentation.ts +34 -0
- package/src/api/dto/documentation/index.ts +11 -0
- package/src/api/dto/documentation/link-preview.ts +23 -0
- package/src/api/dto/documentation/publish.ts +23 -0
- package/src/api/dto/documentation/room.ts +12 -0
- package/src/api/dto/elements/components/figma-component-group.ts +19 -0
- package/src/api/dto/elements/components/figma-component.ts +56 -0
- package/src/api/dto/elements/components/index.ts +2 -0
- package/src/api/dto/elements/documentation/configuration.ts +20 -0
- package/src/api/dto/elements/documentation/draft-state.ts +37 -0
- package/src/api/dto/elements/documentation/group-action.ts +108 -0
- package/src/api/dto/elements/documentation/group-v1.ts +35 -0
- package/src/api/dto/elements/documentation/group-v2.ts +117 -0
- package/src/api/dto/elements/documentation/hierarchy.ts +25 -0
- package/src/api/dto/elements/documentation/index.ts +16 -0
- package/src/api/dto/elements/documentation/item-configuration-v1.ts +24 -0
- package/src/api/dto/elements/documentation/item-configuration-v2.ts +14 -0
- package/src/api/dto/elements/documentation/metadata.ts +8 -0
- package/src/api/dto/elements/documentation/page-actions-v2.ts +138 -0
- package/src/api/dto/elements/documentation/page-content.ts +15 -0
- package/src/api/dto/elements/documentation/page-dependencies.ts +30 -0
- package/src/api/dto/elements/documentation/page-v1.ts +21 -0
- package/src/api/dto/elements/documentation/page-v2.ts +132 -0
- package/src/api/dto/elements/documentation/settings.ts +9 -0
- package/src/api/dto/elements/documentation/structure.ts +37 -0
- package/src/api/dto/elements/elements-action-v2.ts +125 -0
- package/src/api/dto/elements/figma-nodes/figma-node-structure.ts +27 -0
- package/src/api/dto/elements/figma-nodes/figma-node-v1.ts +32 -0
- package/src/api/dto/elements/figma-nodes/figma-node-v2.ts +32 -0
- package/src/api/dto/elements/figma-nodes/figma-node.ts +103 -0
- package/src/api/dto/elements/figma-nodes/index.ts +5 -0
- package/src/api/dto/elements/figma-nodes/node-actions-v2.ts +25 -0
- package/src/api/dto/elements/frame-node-structures/frame-node-structure.ts +17 -0
- package/src/api/dto/elements/frame-node-structures/index.ts +1 -0
- package/src/api/dto/elements/get-elements-v2.ts +27 -0
- package/src/api/dto/elements/index.ts +7 -0
- package/src/api/dto/elements/properties/index.ts +2 -0
- package/src/api/dto/elements/properties/property-definitions.ts +75 -0
- package/src/api/dto/elements/properties/property-values.ts +50 -0
- package/src/api/dto/events/forge-project.ts +51 -0
- package/src/api/dto/events/index.ts +2 -0
- package/src/api/dto/events/workspace.ts +81 -0
- package/src/api/dto/export/exporter-property.ts +114 -0
- package/src/api/dto/export/exporter.ts +115 -0
- package/src/api/dto/export/filter.ts +20 -0
- package/src/api/dto/export/index.ts +5 -0
- package/src/api/dto/export/job.ts +114 -0
- package/src/api/dto/export/pipeline.ts +60 -0
- package/src/api/dto/figma-components/assets/download.ts +30 -0
- package/src/api/dto/figma-components/assets/index.ts +1 -0
- package/src/api/dto/figma-components/index.ts +1 -0
- package/src/api/dto/figma-exporter/figma-node.ts +11 -0
- package/src/api/dto/figma-exporter/index.ts +1 -0
- package/src/api/dto/files/files.ts +94 -0
- package/src/api/dto/files/index.ts +1 -0
- package/src/api/dto/forge/agent.ts +38 -0
- package/src/api/dto/forge/artifact.ts +94 -0
- package/src/api/dto/forge/feature-messages.ts +551 -0
- package/src/api/dto/forge/feature-room.ts +12 -0
- package/src/api/dto/forge/figma-node.ts +117 -0
- package/src/api/dto/forge/index.ts +28 -0
- package/src/api/dto/forge/iteration-message-old.ts +43 -0
- package/src/api/dto/forge/knowledge-item.ts +67 -0
- package/src/api/dto/forge/memory.ts +67 -0
- package/src/api/dto/forge/participant.ts +44 -0
- package/src/api/dto/forge/project-action.ts +123 -0
- package/src/api/dto/forge/project-artifact-room.ts +12 -0
- package/src/api/dto/forge/project-artifact.ts +85 -0
- package/src/api/dto/forge/project-context-feedback.ts +141 -0
- package/src/api/dto/forge/project-context-override.ts +41 -0
- package/src/api/dto/forge/project-context-scope.ts +23 -0
- package/src/api/dto/forge/project-context-v2.ts +228 -0
- package/src/api/dto/forge/project-context.ts +72 -0
- package/src/api/dto/forge/project-feature.ts +86 -0
- package/src/api/dto/forge/project-figma-node.ts +9 -0
- package/src/api/dto/forge/project-file.ts +48 -0
- package/src/api/dto/forge/project-invitation.ts +46 -0
- package/src/api/dto/forge/project-iteration-old.ts +54 -0
- package/src/api/dto/forge/project-member.ts +67 -0
- package/src/api/dto/forge/project-room.ts +12 -0
- package/src/api/dto/forge/project-section.ts +37 -0
- package/src/api/dto/forge/project.ts +105 -0
- package/src/api/dto/forge/relation.ts +34 -0
- package/src/api/dto/forge/threads.ts +153 -0
- package/src/api/dto/index.ts +25 -0
- package/src/api/dto/liveblocks/auth-response.ts +7 -0
- package/src/api/dto/liveblocks/index.ts +1 -0
- package/src/api/dto/mcp/index.ts +1 -0
- package/src/api/dto/mcp/stream.ts +17 -0
- package/src/api/dto/notifications/index.ts +2 -0
- package/src/api/dto/notifications/notifications.ts +65 -0
- package/src/api/dto/notifications/settings.ts +10 -0
- package/src/api/dto/portal/index.ts +1 -0
- package/src/api/dto/portal/portal-settings.ts +45 -0
- package/src/api/dto/sandboxes/index.ts +1 -0
- package/src/api/dto/sandboxes/template.ts +143 -0
- package/src/api/dto/storybook-sites/index.ts +1 -0
- package/src/api/dto/storybook-sites/storybook-sites.ts +60 -0
- package/src/api/dto/themes/index.ts +2 -0
- package/src/api/dto/themes/override.ts +27 -0
- package/src/api/dto/themes/theme.ts +53 -0
- package/src/api/dto/threads/index.ts +1 -0
- package/src/api/dto/threads/threads.ts +280 -0
- package/src/api/dto/trail-events/index.ts +1 -0
- package/src/api/dto/trail-events/trail-events.ts +172 -0
- package/src/api/dto/users/authenticated-user.ts +92 -0
- package/src/api/dto/users/index.ts +2 -0
- package/src/api/dto/users/user.ts +27 -0
- package/src/api/dto/workspaces/billing.ts +156 -0
- package/src/api/dto/workspaces/enums.ts +13 -0
- package/src/api/dto/workspaces/git.ts +32 -0
- package/src/api/dto/workspaces/index.ts +15 -0
- package/src/api/dto/workspaces/integrations.ts +34 -0
- package/src/api/dto/workspaces/invitations.ts +47 -0
- package/src/api/dto/workspaces/ip-whitelist.ts +33 -0
- package/src/api/dto/workspaces/knowledge-items-search.ts +37 -0
- package/src/api/dto/workspaces/login-screen.ts +42 -0
- package/src/api/dto/workspaces/membership.ts +55 -0
- package/src/api/dto/workspaces/npm-registry.ts +62 -0
- package/src/api/dto/workspaces/products.ts +45 -0
- package/src/api/dto/workspaces/subscription.ts +170 -0
- package/src/api/dto/workspaces/transfer-ownership.ts +7 -0
- package/src/api/dto/workspaces/untyped-data.ts +35 -0
- package/src/api/dto/workspaces/workspace.ts +49 -0
- package/src/api/endpoints/auth-tokens.ts +28 -0
- package/src/api/endpoints/codegen/codegen.ts +16 -0
- package/src/api/endpoints/codegen/ds-pipelines.ts +37 -0
- package/src/api/endpoints/codegen/exporters.ts +54 -0
- package/src/api/endpoints/codegen/index.ts +5 -0
- package/src/api/endpoints/codegen/jobs.ts +15 -0
- package/src/api/endpoints/codegen/pipelines.ts +55 -0
- package/src/api/endpoints/design-system/analytics.ts +14 -0
- package/src/api/endpoints/design-system/bff.ts +13 -0
- package/src/api/endpoints/design-system/code-snapshots.ts +47 -0
- package/src/api/endpoints/design-system/contact.ts +12 -0
- package/src/api/endpoints/design-system/design-systems.ts +90 -0
- package/src/api/endpoints/design-system/figma-node-structures.ts +20 -0
- package/src/api/endpoints/design-system/index.ts +11 -0
- package/src/api/endpoints/design-system/members.ts +24 -0
- package/src/api/endpoints/design-system/redirects.ts +46 -0
- package/src/api/endpoints/design-system/sources.ts +80 -0
- package/src/api/endpoints/design-system/storybook.ts +28 -0
- package/src/api/endpoints/design-system/versions/brands.ts +45 -0
- package/src/api/endpoints/design-system/versions/documentation.ts +107 -0
- package/src/api/endpoints/design-system/versions/ds-components.ts +30 -0
- package/src/api/endpoints/design-system/versions/elements-action.ts +65 -0
- package/src/api/endpoints/design-system/versions/elements.ts +27 -0
- package/src/api/endpoints/design-system/versions/figma-component-groups.ts +13 -0
- package/src/api/endpoints/design-system/versions/figma-components.ts +15 -0
- package/src/api/endpoints/design-system/versions/figma-frame-structures.ts +13 -0
- package/src/api/endpoints/design-system/versions/files.ts +43 -0
- package/src/api/endpoints/design-system/versions/import-jobs.ts +13 -0
- package/src/api/endpoints/design-system/versions/index.ts +19 -0
- package/src/api/endpoints/design-system/versions/overrides.ts +17 -0
- package/src/api/endpoints/design-system/versions/property-definitions.ts +43 -0
- package/src/api/endpoints/design-system/versions/property-values.ts +25 -0
- package/src/api/endpoints/design-system/versions/stats.ts +12 -0
- package/src/api/endpoints/design-system/versions/themes.ts +35 -0
- package/src/api/endpoints/design-system/versions/token-collections.ts +13 -0
- package/src/api/endpoints/design-system/versions/token-groups.ts +30 -0
- package/src/api/endpoints/design-system/versions/tokens.ts +29 -0
- package/src/api/endpoints/design-system/versions/versions.ts +90 -0
- package/src/api/endpoints/feedback.ts +60 -0
- package/src/api/endpoints/files.ts +25 -0
- package/src/api/endpoints/forge/agents.ts +54 -0
- package/src/api/endpoints/forge/artifacts.ts +54 -0
- package/src/api/endpoints/forge/documents.ts +18 -0
- package/src/api/endpoints/forge/feature-artifacts.ts +39 -0
- package/src/api/endpoints/forge/feature-iterations.ts +49 -0
- package/src/api/endpoints/forge/feature-messages.ts +68 -0
- package/src/api/endpoints/forge/features.ts +63 -0
- package/src/api/endpoints/forge/forge.ts +38 -0
- package/src/api/endpoints/forge/index.ts +16 -0
- package/src/api/endpoints/forge/iteration-tags.ts +13 -0
- package/src/api/endpoints/forge/memory.ts +41 -0
- package/src/api/endpoints/forge/project-contexts.ts +49 -0
- package/src/api/endpoints/forge/project-files.ts +41 -0
- package/src/api/endpoints/forge/project-invitations.ts +39 -0
- package/src/api/endpoints/forge/project-iterations.ts +65 -0
- package/src/api/endpoints/forge/project-members.ts +55 -0
- package/src/api/endpoints/forge/projects.ts +56 -0
- package/src/api/endpoints/index.ts +13 -0
- package/src/api/endpoints/liveblocks.ts +14 -0
- package/src/api/endpoints/mcp/index.ts +1 -0
- package/src/api/endpoints/mcp/streams.ts +21 -0
- package/src/api/endpoints/sandboxes/builds.ts +30 -0
- package/src/api/endpoints/sandboxes/index.ts +3 -0
- package/src/api/endpoints/sandboxes/sandboxes.ts +13 -0
- package/src/api/endpoints/sandboxes/templates.ts +16 -0
- package/src/api/endpoints/storybook-sites.ts +42 -0
- package/src/api/endpoints/threads.ts +38 -0
- package/src/api/endpoints/users.ts +26 -0
- package/src/api/endpoints/workspaces/billing.ts +24 -0
- package/src/api/endpoints/workspaces/chat-threads.ts +95 -0
- package/src/api/endpoints/workspaces/index.ts +9 -0
- package/src/api/endpoints/workspaces/integrations.ts +15 -0
- package/src/api/endpoints/workspaces/invites.ts +34 -0
- package/src/api/endpoints/workspaces/knowledge-items.ts +59 -0
- package/src/api/endpoints/workspaces/members.ts +31 -0
- package/src/api/endpoints/workspaces/npm-register.ts +20 -0
- package/src/api/endpoints/workspaces/subscription.ts +31 -0
- package/src/api/endpoints/workspaces/workspaces.ts +84 -0
- package/src/api/index.ts +6 -0
- package/src/api/payloads/design-systems/code-snapshots.ts +27 -0
- package/src/api/payloads/design-systems/index.ts +3 -0
- package/src/api/payloads/design-systems/update-design-system.ts +42 -0
- package/src/api/payloads/design-systems/version.ts +29 -0
- package/src/api/payloads/documentation/analytics.ts +36 -0
- package/src/api/payloads/documentation/block-definitions.ts +18 -0
- package/src/api/payloads/documentation/design-data-doc-diff.ts +7 -0
- package/src/api/payloads/documentation/index.ts +3 -0
- package/src/api/payloads/export/index.ts +1 -0
- package/src/api/payloads/export/pipeline.ts +111 -0
- package/src/api/payloads/index.ts +6 -0
- package/src/api/payloads/liveblocks/auth.ts +7 -0
- package/src/api/payloads/liveblocks/index.ts +1 -0
- package/src/api/payloads/users/index.ts +1 -0
- package/src/api/payloads/users/notifications/index.ts +1 -0
- package/src/api/payloads/users/notifications/notification-settings.ts +17 -0
- package/src/api/payloads/workspaces/index.ts +2 -0
- package/src/api/payloads/workspaces/workspace-configuration.ts +62 -0
- package/src/api/payloads/workspaces/workspace-integrations.ts +35 -0
- package/src/api/transport/index.ts +2 -0
- package/src/api/transport/request-executor-error.ts +60 -0
- package/src/api/transport/request-executor.ts +94 -0
- package/src/events/design-system.ts +21 -0
- package/src/events/event.ts +6 -0
- package/src/events/index.ts +2 -0
- package/src/index.ts +5 -0
- package/src/sync/docs-local-action-executor.ts +412 -0
- package/src/sync/docs-structure-repo.ts +283 -0
- package/src/sync/index.ts +5 -0
- package/src/sync/project-content-repo.ts +215 -0
- package/src/sync/project-local-action-executor.ts +415 -0
- package/src/sync/types.ts +37 -0
- package/src/utils/figma.ts +72 -0
- package/src/utils/hash.ts +62 -0
- package/src/utils/index.ts +4 -0
- package/src/utils/query.ts +41 -0
- package/src/utils/redirect-validation.ts +76 -0
- package/src/yjs/design-system-content/documentation-hierarchy.ts +35 -0
- package/src/yjs/design-system-content/index.ts +2 -0
- package/src/yjs/design-system-content/item-configuration.ts +62 -0
- package/src/yjs/docs-editor/blocks-to-prosemirror.ts +764 -0
- package/src/yjs/docs-editor/index.ts +7 -0
- package/src/yjs/docs-editor/list-tree-builder.ts +127 -0
- package/src/yjs/docs-editor/mock.ts +2271 -0
- package/src/yjs/docs-editor/model/block.ts +8 -0
- package/src/yjs/docs-editor/model/index.ts +2 -0
- package/src/yjs/docs-editor/model/page.ts +8 -0
- package/src/yjs/docs-editor/prosemirror/index.ts +3 -0
- package/src/yjs/docs-editor/prosemirror/inner-editor-schema.ts +145 -0
- package/src/yjs/docs-editor/prosemirror/main-editor-schema.ts +577 -0
- package/src/yjs/docs-editor/prosemirror/types.ts +19 -0
- package/src/yjs/docs-editor/prosemirror-to-blocks.ts +986 -0
- package/src/yjs/docs-editor/utils.ts +115 -0
- package/src/yjs/feature-room/backend.ts +36 -0
- package/src/yjs/feature-room/base.ts +109 -0
- package/src/yjs/feature-room/frontend.ts +53 -0
- package/src/yjs/feature-room/index.ts +3 -0
- package/src/yjs/forge-project-room/backend.ts +59 -0
- package/src/yjs/forge-project-room/base.ts +190 -0
- package/src/yjs/forge-project-room/index.ts +2 -0
- package/src/yjs/index.ts +7 -0
- package/src/yjs/thread-room/backend.ts +32 -0
- package/src/yjs/thread-room/base.ts +71 -0
- package/src/yjs/thread-room/frontend.ts +39 -0
- package/src/yjs/thread-room/index.ts +3 -0
- package/src/yjs/utils/index.ts +1 -0
- package/src/yjs/utils/key-value-storage.ts +57 -0
- package/src/yjs/version-room/backend.ts +101 -0
- package/src/yjs/version-room/base.ts +323 -0
- package/src/yjs/version-room/compute-dto.ts +387 -0
- package/src/yjs/version-room/frontend.ts +76 -0
- package/src/yjs/version-room/index.ts +6 -0
- package/src/yjs/version-room/types.ts +31 -0
- package/src/yjs/version-room/utils.ts +109 -0
|
@@ -0,0 +1,764 @@
|
|
|
1
|
+
import {
|
|
2
|
+
PageBlockCalloutType,
|
|
3
|
+
PageBlockDefinition,
|
|
4
|
+
PageBlockDefinitionProperty,
|
|
5
|
+
PageBlockDefinitionRichTextOptions,
|
|
6
|
+
PageBlockItemImageValue,
|
|
7
|
+
PageBlockItemRichTextEditorListNode,
|
|
8
|
+
PageBlockItemRichTextEditorNode,
|
|
9
|
+
PageBlockItemRichTextEditorParagraphNode,
|
|
10
|
+
PageBlockItemRichTextEditorValue,
|
|
11
|
+
PageBlockItemRichTextValue,
|
|
12
|
+
PageBlockItemTableCell,
|
|
13
|
+
PageBlockItemTableNode,
|
|
14
|
+
PageBlockItemTableRow,
|
|
15
|
+
PageBlockItemTableValue,
|
|
16
|
+
PageBlockTableCellAlignment,
|
|
17
|
+
PageBlockText,
|
|
18
|
+
PageBlockTextSpan,
|
|
19
|
+
PageBlockTextSpanAttribute,
|
|
20
|
+
PageSectionColumnV2,
|
|
21
|
+
PageSectionItemV2,
|
|
22
|
+
SupernovaException,
|
|
23
|
+
mapByUnique,
|
|
24
|
+
} from "@supernova-studio/model";
|
|
25
|
+
import { prosemirrorJSONToYXmlFragment } from "y-prosemirror";
|
|
26
|
+
import * as Y from "yjs";
|
|
27
|
+
import { ListNode, ListTreeBuilder } from "./list-tree-builder";
|
|
28
|
+
import { DocumentationPageEditorModel } from "./model";
|
|
29
|
+
import { PageBlockEditorModel, PageSectionEditorModel } from "./model/block";
|
|
30
|
+
import { mainEditorProsemirrorSchema } from "./prosemirror";
|
|
31
|
+
import { ProsemirrorMark, ProsemirrorNode } from "./prosemirror/types";
|
|
32
|
+
import { BlockDefinitionUtils, BlockParsingUtils } from "./utils";
|
|
33
|
+
|
|
34
|
+
//
|
|
35
|
+
// Types
|
|
36
|
+
//
|
|
37
|
+
|
|
38
|
+
type BaseInput = {
|
|
39
|
+
block: PageBlockEditorModel;
|
|
40
|
+
definition: PageBlockDefinition;
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
type InputWithProperty = BaseInput & {
|
|
44
|
+
property: PageBlockDefinitionProperty;
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
type RichTextInputWithValue = InputWithProperty & {
|
|
48
|
+
richTextPropertyValue: PageBlockItemRichTextValue;
|
|
49
|
+
};
|
|
50
|
+
|
|
51
|
+
//
|
|
52
|
+
// Implementation
|
|
53
|
+
//
|
|
54
|
+
|
|
55
|
+
export function pageToYDoc(doc: Y.Doc, page: DocumentationPageEditorModel, definitions: PageBlockDefinition[]) {
|
|
56
|
+
pageToYXmlFragment(page, definitions, doc.getXmlFragment("default"));
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
export function pageToYXmlFragment(
|
|
60
|
+
page: DocumentationPageEditorModel,
|
|
61
|
+
definitions: PageBlockDefinition[],
|
|
62
|
+
fragment: Y.XmlFragment
|
|
63
|
+
): Y.XmlFragment {
|
|
64
|
+
const doc = pageToProsemirrorDoc(page, definitions);
|
|
65
|
+
// console.log(JSON.stringify(doc, null, 2));
|
|
66
|
+
return prosemirrorJSONToYXmlFragment(mainEditorProsemirrorSchema, doc, fragment);
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
export function pageToProsemirrorDoc(
|
|
70
|
+
page: DocumentationPageEditorModel,
|
|
71
|
+
definitions: PageBlockDefinition[]
|
|
72
|
+
): ProsemirrorNode {
|
|
73
|
+
const definitionsMap = mapByUnique(definitions, d => d.id);
|
|
74
|
+
|
|
75
|
+
const children: ProsemirrorNode[] = [];
|
|
76
|
+
let blockBuffer: PageBlockEditorModel[] = [];
|
|
77
|
+
|
|
78
|
+
page.blocks.forEach(b => {
|
|
79
|
+
if (b.type === "Block") {
|
|
80
|
+
blockBuffer.push(b);
|
|
81
|
+
} else if (b.type === "Section") {
|
|
82
|
+
if (blockBuffer.length) {
|
|
83
|
+
children.push(...internalBlocksToProsemirrorNodes(blockBuffer, definitionsMap));
|
|
84
|
+
blockBuffer = [];
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
children.push(internalSectionToProsemirrorNode(b, definitionsMap));
|
|
88
|
+
}
|
|
89
|
+
});
|
|
90
|
+
|
|
91
|
+
if (blockBuffer.length) {
|
|
92
|
+
children.push(...internalBlocksToProsemirrorNodes(blockBuffer, definitionsMap));
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
return {
|
|
96
|
+
type: "doc",
|
|
97
|
+
content: children,
|
|
98
|
+
};
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
export function blockToProsemirrorNode(
|
|
102
|
+
block: PageBlockEditorModel,
|
|
103
|
+
definition: PageBlockDefinition
|
|
104
|
+
): ProsemirrorNode | null {
|
|
105
|
+
const definitionsMap = new Map<string, PageBlockDefinition>([[definition.id, definition]]);
|
|
106
|
+
const nodes = internalBlocksToProsemirrorNodes([block], definitionsMap);
|
|
107
|
+
return nodes[0] ?? null;
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
export function richTextPropertyValueToProsemirror(
|
|
111
|
+
richTextEditorValue: PageBlockItemRichTextEditorValue
|
|
112
|
+
): ProsemirrorNode {
|
|
113
|
+
return {
|
|
114
|
+
type: "doc",
|
|
115
|
+
content: richTextEditorValue.value.map(node => {
|
|
116
|
+
return serializeRichTextEditorNode(node);
|
|
117
|
+
}),
|
|
118
|
+
};
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
function serializeRichTextEditorNode(node: PageBlockItemRichTextEditorNode): ProsemirrorNode {
|
|
122
|
+
switch (node.type) {
|
|
123
|
+
case "Paragraph":
|
|
124
|
+
return serializeRichTextEditorParagraphNode(node);
|
|
125
|
+
|
|
126
|
+
case "List":
|
|
127
|
+
return serializeRichTextEditorListNode(node);
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
function serializeRichTextEditorParagraphNode(node: PageBlockItemRichTextEditorParagraphNode): ProsemirrorNode {
|
|
132
|
+
const content = serializeRichText(node.value);
|
|
133
|
+
return {
|
|
134
|
+
type: "paragraph",
|
|
135
|
+
...(content.length && { content }),
|
|
136
|
+
};
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
function serializeRichTextEditorListNode(node: PageBlockItemRichTextEditorListNode): ProsemirrorNode {
|
|
140
|
+
const type = node.listType === "OL" ? "orderedList" : "bulletList";
|
|
141
|
+
const attrs = node.listType === "OL" ? { start: 1 } : undefined;
|
|
142
|
+
const richTexts = node.value.length ? node.value : [{ spans: [] }];
|
|
143
|
+
|
|
144
|
+
return {
|
|
145
|
+
type,
|
|
146
|
+
...(attrs && { attrs }),
|
|
147
|
+
content: richTexts.map(n => {
|
|
148
|
+
const content = serializeRichText(n);
|
|
149
|
+
|
|
150
|
+
return {
|
|
151
|
+
type: "listItem",
|
|
152
|
+
content: [
|
|
153
|
+
{
|
|
154
|
+
type: "paragraph",
|
|
155
|
+
...(content.length && { content }),
|
|
156
|
+
},
|
|
157
|
+
],
|
|
158
|
+
};
|
|
159
|
+
}),
|
|
160
|
+
};
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
//
|
|
164
|
+
// Sections
|
|
165
|
+
//
|
|
166
|
+
|
|
167
|
+
function internalSectionToProsemirrorNode(
|
|
168
|
+
section: PageSectionEditorModel,
|
|
169
|
+
definitionsMap: Map<string, PageBlockDefinition>
|
|
170
|
+
): ProsemirrorNode {
|
|
171
|
+
return {
|
|
172
|
+
type: "tabsSection",
|
|
173
|
+
attrs: {
|
|
174
|
+
id: section.id,
|
|
175
|
+
...(section.variantId && { variantId: section.variantId }),
|
|
176
|
+
},
|
|
177
|
+
content: section.items.map(item => sectionItemToProsemirrorNode(item, definitionsMap)),
|
|
178
|
+
};
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
function sectionItemToProsemirrorNode(
|
|
182
|
+
sectionItem: PageSectionItemV2,
|
|
183
|
+
definitionsMap: Map<string, PageBlockDefinition>
|
|
184
|
+
): ProsemirrorNode {
|
|
185
|
+
return {
|
|
186
|
+
type: "sectionItem",
|
|
187
|
+
attrs: {
|
|
188
|
+
id: sectionItem.id,
|
|
189
|
+
title: sectionItem.title,
|
|
190
|
+
},
|
|
191
|
+
content: sectionItem.columns.map(column => sectionColumnToProsemirrorNode(column, definitionsMap)),
|
|
192
|
+
};
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
function sectionColumnToProsemirrorNode(
|
|
196
|
+
sectionColumn: PageSectionColumnV2,
|
|
197
|
+
definitionsMap: Map<string, PageBlockDefinition>
|
|
198
|
+
): ProsemirrorNode {
|
|
199
|
+
const blocks = internalBlocksToProsemirrorNodes(sectionColumn.blocks, definitionsMap);
|
|
200
|
+
|
|
201
|
+
if (!blocks.length) {
|
|
202
|
+
blocks.push({
|
|
203
|
+
type: "paragraph",
|
|
204
|
+
attrs: {
|
|
205
|
+
id: "id",
|
|
206
|
+
definitionId: "io.supernova.block.rich-text",
|
|
207
|
+
},
|
|
208
|
+
});
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
return {
|
|
212
|
+
type: "sectionItemColumn",
|
|
213
|
+
attrs: {
|
|
214
|
+
id: sectionColumn.id,
|
|
215
|
+
},
|
|
216
|
+
content: blocks,
|
|
217
|
+
};
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
//
|
|
221
|
+
// Blocks
|
|
222
|
+
//
|
|
223
|
+
|
|
224
|
+
function internalBlocksToProsemirrorNodes(
|
|
225
|
+
blocks: PageBlockEditorModel[],
|
|
226
|
+
definitionsMap: Map<string, PageBlockDefinition>
|
|
227
|
+
): ProsemirrorNode[] {
|
|
228
|
+
const result: ProsemirrorNode[] = [];
|
|
229
|
+
|
|
230
|
+
const listTreeBuilder = new ListTreeBuilder();
|
|
231
|
+
|
|
232
|
+
blocks.forEach(b => {
|
|
233
|
+
const definition = definitionsMap.get(b.data.packageId);
|
|
234
|
+
if (!definition) {
|
|
235
|
+
console.warn(`Could not find definition for ${b.id} (${b.data.packageId})`);
|
|
236
|
+
return;
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
const multiRichTextProp = BlockDefinitionUtils.firstMultiRichTextProperty(definition);
|
|
240
|
+
|
|
241
|
+
if (multiRichTextProp) {
|
|
242
|
+
// This is list
|
|
243
|
+
const node = listTreeBuilder.addWithProperty(b, multiRichTextProp);
|
|
244
|
+
if (node) {
|
|
245
|
+
result.push(serializeAsMultiRichTextBlock(node));
|
|
246
|
+
}
|
|
247
|
+
} else {
|
|
248
|
+
// This is not a list
|
|
249
|
+
// Flush the tree builder to inject a non-tree block after it
|
|
250
|
+
const tree = listTreeBuilder.flush();
|
|
251
|
+
if (tree) {
|
|
252
|
+
result.push(serializeAsMultiRichTextBlock(tree));
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
const node = internalBlockToProsemirrorNode(b, definition);
|
|
256
|
+
node && result.push(node);
|
|
257
|
+
}
|
|
258
|
+
});
|
|
259
|
+
|
|
260
|
+
const tree = listTreeBuilder.flush();
|
|
261
|
+
if (tree) {
|
|
262
|
+
result.push(serializeAsMultiRichTextBlock(tree));
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
return result;
|
|
266
|
+
}
|
|
267
|
+
|
|
268
|
+
function internalBlockToProsemirrorNode(
|
|
269
|
+
block: PageBlockEditorModel,
|
|
270
|
+
definition: PageBlockDefinition
|
|
271
|
+
): ProsemirrorNode | null {
|
|
272
|
+
// Single rich text
|
|
273
|
+
const richTextProperty = BlockDefinitionUtils.firstRichTextProperty(definition);
|
|
274
|
+
if (richTextProperty) {
|
|
275
|
+
return serializeAsRichTextBlock({
|
|
276
|
+
block: block,
|
|
277
|
+
definition: definition,
|
|
278
|
+
property: richTextProperty,
|
|
279
|
+
});
|
|
280
|
+
}
|
|
281
|
+
|
|
282
|
+
const tableProperty = BlockDefinitionUtils.firstTableProperty(definition);
|
|
283
|
+
if (tableProperty) {
|
|
284
|
+
return serializeAsTable({
|
|
285
|
+
block: block,
|
|
286
|
+
definition: definition,
|
|
287
|
+
property: tableProperty,
|
|
288
|
+
});
|
|
289
|
+
}
|
|
290
|
+
|
|
291
|
+
// Divider
|
|
292
|
+
if (block.data.packageId === "io.supernova.block.divider") {
|
|
293
|
+
return serializeAsDivider({
|
|
294
|
+
block: block,
|
|
295
|
+
definition: definition,
|
|
296
|
+
});
|
|
297
|
+
}
|
|
298
|
+
|
|
299
|
+
return serializeAsCustomBlock(block, definition);
|
|
300
|
+
}
|
|
301
|
+
|
|
302
|
+
//
|
|
303
|
+
// Single rich text blocks
|
|
304
|
+
//
|
|
305
|
+
|
|
306
|
+
function serializeAsRichTextBlock(input: InputWithProperty): ProsemirrorNode {
|
|
307
|
+
const { block, definition, property: richTextProperty } = input;
|
|
308
|
+
|
|
309
|
+
const blockItem = BlockParsingUtils.singleBlockItem(block);
|
|
310
|
+
const textPropertyValue = BlockParsingUtils.richTextPropertyValue(blockItem, richTextProperty.id);
|
|
311
|
+
|
|
312
|
+
const enrichedInput: RichTextInputWithValue = { ...input, richTextPropertyValue: textPropertyValue };
|
|
313
|
+
|
|
314
|
+
const parsedOptions = PageBlockDefinitionRichTextOptions.optional().parse(richTextProperty.options);
|
|
315
|
+
const style = parsedOptions?.richTextStyle ?? "Default";
|
|
316
|
+
|
|
317
|
+
switch (style) {
|
|
318
|
+
case "Callout":
|
|
319
|
+
return serializeAsCallout(enrichedInput);
|
|
320
|
+
case "Default":
|
|
321
|
+
return serializeAsParagraph(enrichedInput);
|
|
322
|
+
|
|
323
|
+
case "Quote":
|
|
324
|
+
return serializeAsBlockquote(enrichedInput);
|
|
325
|
+
|
|
326
|
+
case "Title1":
|
|
327
|
+
case "Title2":
|
|
328
|
+
case "Title3":
|
|
329
|
+
case "Title4":
|
|
330
|
+
case "Title5":
|
|
331
|
+
return serializeAsHeading(enrichedInput);
|
|
332
|
+
}
|
|
333
|
+
}
|
|
334
|
+
|
|
335
|
+
function serializeAsParagraph(input: RichTextInputWithValue): ProsemirrorNode {
|
|
336
|
+
return {
|
|
337
|
+
type: "paragraph",
|
|
338
|
+
attrs: serializeBlockNodeAttributes(input.block),
|
|
339
|
+
...serializeRichTextNodePart(input.richTextPropertyValue.value),
|
|
340
|
+
};
|
|
341
|
+
}
|
|
342
|
+
|
|
343
|
+
function serializeAsHeading(input: RichTextInputWithValue): ProsemirrorNode {
|
|
344
|
+
return {
|
|
345
|
+
type: "heading",
|
|
346
|
+
attrs: {
|
|
347
|
+
...serializeBlockNodeAttributes(input.block),
|
|
348
|
+
level: richTextHeadingLevel(input.property),
|
|
349
|
+
},
|
|
350
|
+
...serializeRichTextNodePart(input.richTextPropertyValue.value),
|
|
351
|
+
};
|
|
352
|
+
}
|
|
353
|
+
|
|
354
|
+
function serializeAsBlockquote(input: RichTextInputWithValue): ProsemirrorNode {
|
|
355
|
+
return {
|
|
356
|
+
type: "blockquote",
|
|
357
|
+
attrs: serializeBlockNodeAttributes(input.block),
|
|
358
|
+
...serializeRichTextNodePart(input.richTextPropertyValue.value),
|
|
359
|
+
};
|
|
360
|
+
}
|
|
361
|
+
|
|
362
|
+
function serializeAsCallout(input: RichTextInputWithValue): ProsemirrorNode {
|
|
363
|
+
const calloutType = input.richTextPropertyValue.calloutType ?? "Info";
|
|
364
|
+
|
|
365
|
+
return {
|
|
366
|
+
type: "callout",
|
|
367
|
+
attrs: {
|
|
368
|
+
...serializeBlockNodeAttributes(input.block),
|
|
369
|
+
type: serializeCalloutType(calloutType),
|
|
370
|
+
},
|
|
371
|
+
...serializeRichTextNodePart(input.richTextPropertyValue.value),
|
|
372
|
+
};
|
|
373
|
+
}
|
|
374
|
+
|
|
375
|
+
//
|
|
376
|
+
// Multi rich text blocks
|
|
377
|
+
//
|
|
378
|
+
|
|
379
|
+
function serializeAsMultiRichTextBlock(node: ListNode): ProsemirrorNode {
|
|
380
|
+
switch (node.listType) {
|
|
381
|
+
case "Ordered":
|
|
382
|
+
return serializeAsOrderedList(node);
|
|
383
|
+
|
|
384
|
+
case "Unordered":
|
|
385
|
+
return serializeAsUnorderedList(node);
|
|
386
|
+
}
|
|
387
|
+
}
|
|
388
|
+
|
|
389
|
+
function serializeAsOrderedList(tree: ListNode): ProsemirrorNode {
|
|
390
|
+
return {
|
|
391
|
+
type: "orderedList",
|
|
392
|
+
attrs: {
|
|
393
|
+
...serializeBlockNodeAttributes(tree.block),
|
|
394
|
+
start: "1",
|
|
395
|
+
},
|
|
396
|
+
content: serializeListContent(tree),
|
|
397
|
+
};
|
|
398
|
+
}
|
|
399
|
+
|
|
400
|
+
function serializeAsUnorderedList(tree: ListNode): ProsemirrorNode {
|
|
401
|
+
return {
|
|
402
|
+
type: "bulletList",
|
|
403
|
+
attrs: {
|
|
404
|
+
...serializeBlockNodeAttributes(tree.block),
|
|
405
|
+
},
|
|
406
|
+
content: serializeListContent(tree),
|
|
407
|
+
};
|
|
408
|
+
}
|
|
409
|
+
|
|
410
|
+
function serializeListContent(tree: ListNode): ProsemirrorNode[] {
|
|
411
|
+
const result: ProsemirrorNode[] = tree.leadingChildren.map(i => serializeAsTextListItem(i.text));
|
|
412
|
+
|
|
413
|
+
for (const child of tree.children) {
|
|
414
|
+
if (child.type === "ListItem") {
|
|
415
|
+
// Text list item
|
|
416
|
+
|
|
417
|
+
result.push(serializeAsTextListItem(child.text));
|
|
418
|
+
} else if (child.type === "List") {
|
|
419
|
+
// List list item
|
|
420
|
+
|
|
421
|
+
const previousNode = result[result.length - 1];
|
|
422
|
+
if (!previousNode) {
|
|
423
|
+
throw SupernovaException.shouldNotHappen("List node without previous node");
|
|
424
|
+
}
|
|
425
|
+
if (!previousNode.content) {
|
|
426
|
+
throw SupernovaException.shouldNotHappen("List item node has no content");
|
|
427
|
+
}
|
|
428
|
+
|
|
429
|
+
const serializedList = serializeAsMultiRichTextBlock(child);
|
|
430
|
+
previousNode.content.push(serializedList);
|
|
431
|
+
} else {
|
|
432
|
+
// Should noit happen
|
|
433
|
+
|
|
434
|
+
throw SupernovaException.shouldNotHappen(`Unknown list node type: ${child}`);
|
|
435
|
+
}
|
|
436
|
+
}
|
|
437
|
+
|
|
438
|
+
return result;
|
|
439
|
+
}
|
|
440
|
+
|
|
441
|
+
function serializeAsTextListItem(text: PageBlockText): ProsemirrorNode {
|
|
442
|
+
return {
|
|
443
|
+
type: "listItem",
|
|
444
|
+
content: [
|
|
445
|
+
{
|
|
446
|
+
type: "paragraph",
|
|
447
|
+
attrs: {
|
|
448
|
+
definitionId: "io.supernova.block.rich-text",
|
|
449
|
+
variantId: "default",
|
|
450
|
+
},
|
|
451
|
+
content: serializeRichText(text),
|
|
452
|
+
},
|
|
453
|
+
],
|
|
454
|
+
};
|
|
455
|
+
}
|
|
456
|
+
|
|
457
|
+
//
|
|
458
|
+
// Tables
|
|
459
|
+
//
|
|
460
|
+
|
|
461
|
+
function serializeAsTable(input: InputWithProperty): ProsemirrorNode {
|
|
462
|
+
const { block, definition, property: tableProperty } = input;
|
|
463
|
+
|
|
464
|
+
const blockItem = BlockParsingUtils.singleBlockItem(block);
|
|
465
|
+
const table = BlockParsingUtils.tablePropertyValue(blockItem, tableProperty.id);
|
|
466
|
+
|
|
467
|
+
return {
|
|
468
|
+
type: "tableContainer",
|
|
469
|
+
attrs: {
|
|
470
|
+
...serializeBlockNodeAttributes(input.block),
|
|
471
|
+
hasBorder: table.showBorder ?? true,
|
|
472
|
+
},
|
|
473
|
+
|
|
474
|
+
content: [
|
|
475
|
+
{
|
|
476
|
+
type: "table",
|
|
477
|
+
content: serializeTableRows(table),
|
|
478
|
+
},
|
|
479
|
+
],
|
|
480
|
+
};
|
|
481
|
+
}
|
|
482
|
+
|
|
483
|
+
function serializeTableRows(table: PageBlockItemTableValue): ProsemirrorNode[] {
|
|
484
|
+
// If no rows are present, we have to generate a least one empty row
|
|
485
|
+
const rows: PageBlockItemTableRow[] = table.value.length ? table.value : [{ cells: [] }];
|
|
486
|
+
|
|
487
|
+
return rows.map<ProsemirrorNode>((row, rowIndex) => {
|
|
488
|
+
const isHeaderRow = rowIndex === 0 && table.highlightHeaderRow === true;
|
|
489
|
+
|
|
490
|
+
// If no cells are present, we have to generate at least one cell
|
|
491
|
+
const cells: PageBlockItemTableCell[] = row.cells.length ? row.cells : [{ id: "", alignment: "Left", nodes: [] }];
|
|
492
|
+
|
|
493
|
+
return {
|
|
494
|
+
type: "tableRow",
|
|
495
|
+
content: cells.map<ProsemirrorNode>((cell, cellIndex) => {
|
|
496
|
+
const isHeaderColumn = cellIndex === 0 && table.highlightHeaderColumn === true;
|
|
497
|
+
|
|
498
|
+
return {
|
|
499
|
+
type: isHeaderRow || isHeaderColumn ? "tableHeader" : "tableCell",
|
|
500
|
+
attrs: {
|
|
501
|
+
...(cell.id && { id: cell.id }),
|
|
502
|
+
textAlign: serializeTableCellAlignment(cell.alignment),
|
|
503
|
+
colspan: 1,
|
|
504
|
+
rowspan: 1,
|
|
505
|
+
...(cell.columnWidth && { colwidth: [cell.columnWidth] }),
|
|
506
|
+
},
|
|
507
|
+
content: serializeTableCellNodes(cell),
|
|
508
|
+
};
|
|
509
|
+
}),
|
|
510
|
+
};
|
|
511
|
+
});
|
|
512
|
+
}
|
|
513
|
+
|
|
514
|
+
function serializeTableCellAlignment(alignment: PageBlockTableCellAlignment) {
|
|
515
|
+
switch (alignment) {
|
|
516
|
+
case "Left":
|
|
517
|
+
return "left";
|
|
518
|
+
case "Center":
|
|
519
|
+
return "center";
|
|
520
|
+
case "Right":
|
|
521
|
+
return "right";
|
|
522
|
+
|
|
523
|
+
default:
|
|
524
|
+
return "left";
|
|
525
|
+
}
|
|
526
|
+
}
|
|
527
|
+
|
|
528
|
+
function serializeTableCellNodes(cell: PageBlockItemTableCell): ProsemirrorNode[] {
|
|
529
|
+
const result = cell.nodes.map(serializeTableNode);
|
|
530
|
+
|
|
531
|
+
if (result.length) {
|
|
532
|
+
return result;
|
|
533
|
+
} else {
|
|
534
|
+
return [{ type: "paragraph" }];
|
|
535
|
+
}
|
|
536
|
+
}
|
|
537
|
+
|
|
538
|
+
function serializeTableNode(node: PageBlockItemTableNode): ProsemirrorNode {
|
|
539
|
+
switch (node.type) {
|
|
540
|
+
case "RichText":
|
|
541
|
+
return {
|
|
542
|
+
type: "paragraph",
|
|
543
|
+
attrs: {
|
|
544
|
+
id: node.id,
|
|
545
|
+
definitionId: "io.supernova.block.rich-text",
|
|
546
|
+
},
|
|
547
|
+
...serializeRichTextNodePart(node.value),
|
|
548
|
+
};
|
|
549
|
+
|
|
550
|
+
case "Image":
|
|
551
|
+
return {
|
|
552
|
+
type: "image",
|
|
553
|
+
attrs: {
|
|
554
|
+
id: node.id,
|
|
555
|
+
definitionId: "io.supernova.block.image",
|
|
556
|
+
items: JSON.stringify([
|
|
557
|
+
{
|
|
558
|
+
id: node.id,
|
|
559
|
+
props: {
|
|
560
|
+
image: {
|
|
561
|
+
...(node.alt && { alt: node.alt }),
|
|
562
|
+
...(node.caption && { caption: node.caption }),
|
|
563
|
+
...(node.alignment && { alignment: node.alignment }),
|
|
564
|
+
value: node.value,
|
|
565
|
+
} satisfies PageBlockItemImageValue,
|
|
566
|
+
},
|
|
567
|
+
},
|
|
568
|
+
]),
|
|
569
|
+
},
|
|
570
|
+
};
|
|
571
|
+
}
|
|
572
|
+
}
|
|
573
|
+
|
|
574
|
+
//
|
|
575
|
+
// Divider
|
|
576
|
+
//
|
|
577
|
+
|
|
578
|
+
function serializeAsDivider(input: BaseInput): ProsemirrorNode {
|
|
579
|
+
return {
|
|
580
|
+
type: "horizontalRule",
|
|
581
|
+
attrs: serializeBlockNodeAttributes(input.block),
|
|
582
|
+
};
|
|
583
|
+
}
|
|
584
|
+
|
|
585
|
+
//
|
|
586
|
+
// Attributes
|
|
587
|
+
//
|
|
588
|
+
|
|
589
|
+
function serializeBlockNodeAttributes(block: PageBlockEditorModel) {
|
|
590
|
+
return {
|
|
591
|
+
id: block.id,
|
|
592
|
+
definitionId: block.data.packageId,
|
|
593
|
+
...(block.data.variantId && { variantId: block.data.variantId }),
|
|
594
|
+
};
|
|
595
|
+
}
|
|
596
|
+
|
|
597
|
+
function richTextHeadingLevel(property: PageBlockDefinitionProperty): number | undefined {
|
|
598
|
+
const style = property.options?.richTextStyle;
|
|
599
|
+
if (!style) return undefined;
|
|
600
|
+
|
|
601
|
+
switch (style) {
|
|
602
|
+
case "Title1":
|
|
603
|
+
return 1;
|
|
604
|
+
case "Title2":
|
|
605
|
+
return 2;
|
|
606
|
+
case "Title3":
|
|
607
|
+
return 3;
|
|
608
|
+
case "Title4":
|
|
609
|
+
return 4;
|
|
610
|
+
case "Title5":
|
|
611
|
+
return 5;
|
|
612
|
+
case "Callout":
|
|
613
|
+
case "Default":
|
|
614
|
+
case "Quote":
|
|
615
|
+
return undefined;
|
|
616
|
+
}
|
|
617
|
+
}
|
|
618
|
+
|
|
619
|
+
function serializeCalloutType(calloutType: PageBlockCalloutType) {
|
|
620
|
+
switch (calloutType) {
|
|
621
|
+
case "Error":
|
|
622
|
+
return "critical";
|
|
623
|
+
case "Info":
|
|
624
|
+
return "neutral";
|
|
625
|
+
case "Success":
|
|
626
|
+
return "positive";
|
|
627
|
+
case "Warning":
|
|
628
|
+
return "warning";
|
|
629
|
+
case "Primary":
|
|
630
|
+
return "primary";
|
|
631
|
+
}
|
|
632
|
+
}
|
|
633
|
+
|
|
634
|
+
//
|
|
635
|
+
// Rich text
|
|
636
|
+
//
|
|
637
|
+
|
|
638
|
+
function serializeRichTextNodePart(richText: PageBlockText): Pick<ProsemirrorNode, "content"> {
|
|
639
|
+
const spans = serializeRichText(richText);
|
|
640
|
+
if (spans.length) return { content: spans };
|
|
641
|
+
return {};
|
|
642
|
+
}
|
|
643
|
+
|
|
644
|
+
function serializeRichText(richText: PageBlockText) {
|
|
645
|
+
return richText.spans.map(serializeTextSpan).flat();
|
|
646
|
+
}
|
|
647
|
+
|
|
648
|
+
function serializeTextSpan(span: PageBlockTextSpan): ProsemirrorNode[] {
|
|
649
|
+
const hardBreakType = "hardBreak";
|
|
650
|
+
|
|
651
|
+
const marks = span.attributes.map(serializeTextSpanAttribute);
|
|
652
|
+
|
|
653
|
+
const textParts = span.text.split("\n");
|
|
654
|
+
const interspersed: ProsemirrorNode[] = [
|
|
655
|
+
{
|
|
656
|
+
type: "text",
|
|
657
|
+
text: textParts[0],
|
|
658
|
+
|
|
659
|
+
...(marks.length && { marks: marks }),
|
|
660
|
+
},
|
|
661
|
+
];
|
|
662
|
+
|
|
663
|
+
for (let i = 1; i < textParts.length; i++) {
|
|
664
|
+
interspersed.push(
|
|
665
|
+
{
|
|
666
|
+
type: hardBreakType,
|
|
667
|
+
},
|
|
668
|
+
{
|
|
669
|
+
type: "text",
|
|
670
|
+
text: textParts[i],
|
|
671
|
+
|
|
672
|
+
...(marks.length && { marks: marks }),
|
|
673
|
+
}
|
|
674
|
+
);
|
|
675
|
+
}
|
|
676
|
+
|
|
677
|
+
return interspersed.filter(t => t.type === hardBreakType || !!t.text);
|
|
678
|
+
}
|
|
679
|
+
|
|
680
|
+
function serializeTextSpanAttribute(spanAttribute: PageBlockTextSpanAttribute): ProsemirrorMark {
|
|
681
|
+
switch (spanAttribute.type) {
|
|
682
|
+
case "Bold":
|
|
683
|
+
return { type: "bold", attrs: {} };
|
|
684
|
+
case "Italic":
|
|
685
|
+
return { type: "italic", attrs: {} };
|
|
686
|
+
case "Strikethrough":
|
|
687
|
+
return { type: "strike", attrs: {} };
|
|
688
|
+
case "Code":
|
|
689
|
+
return { type: "code", attrs: {} };
|
|
690
|
+
case "Comment":
|
|
691
|
+
return {
|
|
692
|
+
type: "commentHighlight",
|
|
693
|
+
attrs: {
|
|
694
|
+
highlightId: spanAttribute.commentHighlightId,
|
|
695
|
+
resolved: spanAttribute.commentIsResolved,
|
|
696
|
+
},
|
|
697
|
+
};
|
|
698
|
+
case "Link":
|
|
699
|
+
if (spanAttribute.link) {
|
|
700
|
+
return serializeLinkMark(
|
|
701
|
+
spanAttribute.link,
|
|
702
|
+
spanAttribute.openInNewTab ?? spanAttribute.openInNewWindow ?? false
|
|
703
|
+
);
|
|
704
|
+
} else if (spanAttribute.documentationItemId) {
|
|
705
|
+
return serializeLinkMark(
|
|
706
|
+
`@page:${spanAttribute.documentationItemId}`,
|
|
707
|
+
spanAttribute.openInNewTab ?? spanAttribute.openInNewWindow ?? false
|
|
708
|
+
);
|
|
709
|
+
} else {
|
|
710
|
+
return serializeLinkMark("about:blank", spanAttribute.openInNewTab ?? spanAttribute.openInNewWindow ?? false);
|
|
711
|
+
}
|
|
712
|
+
}
|
|
713
|
+
}
|
|
714
|
+
|
|
715
|
+
function serializeLinkMark(href: string, openInNewTab: boolean): ProsemirrorMark {
|
|
716
|
+
return {
|
|
717
|
+
type: "link",
|
|
718
|
+
attrs: {
|
|
719
|
+
href: href,
|
|
720
|
+
target: openInNewTab ? "_blank" : "_self",
|
|
721
|
+
rel: "noopener noreferrer nofollow",
|
|
722
|
+
class: "tiptap-link",
|
|
723
|
+
},
|
|
724
|
+
};
|
|
725
|
+
}
|
|
726
|
+
|
|
727
|
+
export function serializeAsCustomBlock(block: PageBlockEditorModel, definition: PageBlockDefinition): ProsemirrorNode {
|
|
728
|
+
const items = block.data.items.map(i => {
|
|
729
|
+
return {
|
|
730
|
+
id: i.id,
|
|
731
|
+
props: i.props,
|
|
732
|
+
linksTo: i.linksTo,
|
|
733
|
+
};
|
|
734
|
+
});
|
|
735
|
+
|
|
736
|
+
const columns = block.data.appearance?.numberOfColumns;
|
|
737
|
+
|
|
738
|
+
return {
|
|
739
|
+
type: serializeCustomBlockNodeType(block, definition),
|
|
740
|
+
attrs: {
|
|
741
|
+
id: block.id,
|
|
742
|
+
definitionId: block.data.packageId,
|
|
743
|
+
...(block.data.variantId && { variantId: block.data.variantId }),
|
|
744
|
+
items: JSON.stringify(items),
|
|
745
|
+
|
|
746
|
+
...(block.data.appearance && { appearance: JSON.stringify(block.data.appearance) }),
|
|
747
|
+
...(columns && { columns: columns }),
|
|
748
|
+
},
|
|
749
|
+
};
|
|
750
|
+
}
|
|
751
|
+
|
|
752
|
+
function serializeCustomBlockNodeType(block: PageBlockEditorModel, definition: PageBlockDefinition): string {
|
|
753
|
+
switch (block.data.packageId) {
|
|
754
|
+
case "io.supernova.block.image":
|
|
755
|
+
return "image";
|
|
756
|
+
|
|
757
|
+
default:
|
|
758
|
+
return "blockNode";
|
|
759
|
+
}
|
|
760
|
+
}
|
|
761
|
+
|
|
762
|
+
function nonNullFilter<T>(item: T | null): item is T {
|
|
763
|
+
return !!item;
|
|
764
|
+
}
|