From cf9b89ae2e37e669a9bcd2bdeec2fc952f51d605 Mon Sep 17 00:00:00 2001 From: cohitre Date: Fri, 1 Mar 2024 06:16:28 -0800 Subject: [PATCH] Adding buildBlockConfigurationDictionary to document-core (#54) --- packages/document-core/package-lock.json | 4 +- packages/document-core/package.json | 2 +- .../buildBlockConfigurationDictionary.ts | 12 ++++ packages/document-core/src/index.ts | 1 + packages/editor-sample/package-lock.json | 8 +-- packages/editor-sample/package.json | 2 +- .../src/documents/editor/core.tsx | 56 ++++++++++--------- .../src/documents/reader/core.tsx | 10 +++- 8 files changed, 57 insertions(+), 38 deletions(-) create mode 100644 packages/document-core/src/builders/buildBlockConfigurationDictionary.ts diff --git a/packages/document-core/package-lock.json b/packages/document-core/package-lock.json index a90cee9..18f6a2f 100644 --- a/packages/document-core/package-lock.json +++ b/packages/document-core/package-lock.json @@ -1,12 +1,12 @@ { "name": "@usewaypoint/document-core", - "version": "0.0.2", + "version": "0.0.4", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "@usewaypoint/document-core", - "version": "0.0.2", + "version": "0.0.4", "license": "MIT", "peerDependencies": { "react": "^16 || ^17 || ^18", diff --git a/packages/document-core/package.json b/packages/document-core/package.json index 2689af6..070692f 100644 --- a/packages/document-core/package.json +++ b/packages/document-core/package.json @@ -1,6 +1,6 @@ { "name": "@usewaypoint/document-core", - "version": "0.0.2", + "version": "0.0.4", "description": "Tools to render waypoint-style documents (core package)", "main": "dist/index.js", "types": "dist/index.d.ts", diff --git a/packages/document-core/src/builders/buildBlockConfigurationDictionary.ts b/packages/document-core/src/builders/buildBlockConfigurationDictionary.ts new file mode 100644 index 0000000..de3657f --- /dev/null +++ b/packages/document-core/src/builders/buildBlockConfigurationDictionary.ts @@ -0,0 +1,12 @@ +import { BaseZodDictionary, DocumentBlocksDictionary } from '../utils'; + +/** + * Identity function to type a DocumentBlocksDictionary + * @param blocks Main DocumentBlocksDictionary + * @returns typed DocumentBlocksDictionary + */ +export default function buildBlockConfigurationDictionary( + blocks: DocumentBlocksDictionary +) { + return blocks; +} diff --git a/packages/document-core/src/index.ts b/packages/document-core/src/index.ts index 02801d2..a1cb39a 100644 --- a/packages/document-core/src/index.ts +++ b/packages/document-core/src/index.ts @@ -1,4 +1,5 @@ export { default as buildBlockComponent } from './builders/buildBlockComponent'; export { default as buildBlockConfigurationSchema } from './builders/buildBlockConfigurationSchema'; +export { default as buildBlockConfigurationDictionary } from './builders/buildBlockConfigurationDictionary'; export { BlockConfiguration, DocumentBlocksDictionary } from './utils'; diff --git a/packages/editor-sample/package-lock.json b/packages/editor-sample/package-lock.json index fb3c6c4..91a82ab 100644 --- a/packages/editor-sample/package-lock.json +++ b/packages/editor-sample/package-lock.json @@ -22,7 +22,7 @@ "@usewaypoint/block-image": "^0.0.4", "@usewaypoint/block-spacer": "^0.0.2", "@usewaypoint/block-text": "^0.0.2", - "@usewaypoint/document-core": "^0.0.1", + "@usewaypoint/document-core": "^0.0.4", "codemirror": "^6.0.1", "highlight.js": "^11.9.0", "js-beautify": "^1.15.1", @@ -2102,9 +2102,9 @@ } }, "node_modules/@usewaypoint/document-core": { - "version": "0.0.1", - "resolved": "https://registry.npmjs.org/@usewaypoint/document-core/-/document-core-0.0.1.tgz", - "integrity": "sha512-DD6h3ObcDPq3POCi3IbjRUCYBUeqnJIzvrZ2gIRGVV4yd0XCXx6to02FDu33rH8zmsLWtx9NOyfXDlchybfzbw==", + "version": "0.0.4", + "resolved": "https://registry.npmjs.org/@usewaypoint/document-core/-/document-core-0.0.4.tgz", + "integrity": "sha512-xlPM5zexUhuRDsSwPVZ8cvemmsffLDb4wxlaAVMXi4ayO7ZHHrc9SiLiBkR8cnfQ3OvnHlZaO8YDsGmnckGqYw==", "peerDependencies": { "react": "^16 || ^17 || ^18", "zod": "^1 || ^2 || ^3" diff --git a/packages/editor-sample/package.json b/packages/editor-sample/package.json index bd63c7c..a6b64b8 100644 --- a/packages/editor-sample/package.json +++ b/packages/editor-sample/package.json @@ -22,7 +22,7 @@ "@usewaypoint/block-image": "^0.0.4", "@usewaypoint/block-spacer": "^0.0.2", "@usewaypoint/block-text": "^0.0.2", - "@usewaypoint/document-core": "^0.0.1", + "@usewaypoint/document-core": "^0.0.4", "codemirror": "^6.0.1", "highlight.js": "^11.9.0", "js-beautify": "^1.15.1", diff --git a/packages/editor-sample/src/documents/editor/core.tsx b/packages/editor-sample/src/documents/editor/core.tsx index dbb8075..056119d 100644 --- a/packages/editor-sample/src/documents/editor/core.tsx +++ b/packages/editor-sample/src/documents/editor/core.tsx @@ -1,30 +1,32 @@ import React from 'react'; import { z } from 'zod'; -import { Avatar, AvatarProps, AvatarPropsSchema } from '@usewaypoint/block-avatar'; -import { Button, ButtonProps, ButtonPropsSchema } from '@usewaypoint/block-button'; -import { Divider, DividerProps, DividerPropsSchema } from '@usewaypoint/block-divider'; -import { Heading, HeadingProps, HeadingPropsSchema } from '@usewaypoint/block-heading'; -import { Html, HtmlProps, HtmlPropsSchema } from '@usewaypoint/block-html'; -import { Image, ImageProps, ImagePropsSchema } from '@usewaypoint/block-image'; -import { Spacer, SpacerProps, SpacerPropsSchema } from '@usewaypoint/block-spacer'; -import { Text, TextProps, TextPropsSchema } from '@usewaypoint/block-text'; -import { buildBlockComponent, buildBlockConfigurationSchema } from '@usewaypoint/document-core'; +import { Avatar, AvatarPropsSchema } from '@usewaypoint/block-avatar'; +import { Button, ButtonPropsSchema } from '@usewaypoint/block-button'; +import { Divider, DividerPropsSchema } from '@usewaypoint/block-divider'; +import { Heading, HeadingPropsSchema } from '@usewaypoint/block-heading'; +import { Html, HtmlPropsSchema } from '@usewaypoint/block-html'; +import { Image, ImagePropsSchema } from '@usewaypoint/block-image'; +import { Spacer, SpacerPropsSchema } from '@usewaypoint/block-spacer'; +import { Text, TextPropsSchema } from '@usewaypoint/block-text'; +import { + buildBlockComponent, + buildBlockConfigurationDictionary, + buildBlockConfigurationSchema, +} from '@usewaypoint/document-core'; import { EditorColumnsContainer } from '../blocks/ColumnsContainer'; -import ColumnsContainerPropsSchema, { - ColumnsContainerProps, -} from '../blocks/ColumnsContainer/ColumnsContainerPropsSchema'; +import ColumnsContainerPropsSchema from '../blocks/ColumnsContainer/ColumnsContainerPropsSchema'; import { EditorContainer } from '../blocks/Container'; -import { ContainerProps, ContainerPropsSchema } from '../blocks/Container/ContainerPropsSchema'; -import { EditorEmailLayout, EmailLayoutProps } from '../blocks/EmailLayout'; +import { ContainerPropsSchema } from '../blocks/Container/ContainerPropsSchema'; +import { EditorEmailLayout } from '../blocks/EmailLayout'; import { EmailLayoutPropsSchema } from '../blocks/EmailLayout/EmailLayoutPropsSchema'; import EditorBlockWrapper from '../blocks/helpers/block-wrappers/EditorBlockWrapper'; -const EDITOR_DICTIONARY = { +const EDITOR_DICTIONARY = buildBlockConfigurationDictionary({ Avatar: { schema: AvatarPropsSchema, - Component: (props: AvatarProps) => ( + Component: (props) => ( @@ -32,7 +34,7 @@ const EDITOR_DICTIONARY = { }, Button: { schema: ButtonPropsSchema, - Component: (props: ButtonProps) => ( + Component: (props) => (