From ff668eff311e8a1d0b495264c563862270f92779 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Benjamin=20B=C3=A4dorf?= Date: Sat, 12 Mar 2022 17:16:24 +0100 Subject: [PATCH] Fix TypeScript errors --- packages/core/lib/components/Block.tsx | 40 ++++++++++++++++---- packages/core/lib/components/BlockPicker.tsx | 4 +- packages/core/lib/components/ContextMenu.tsx | 8 ++++ packages/core/lib/types.ts | 22 +++++++---- packages/docs/package.json | 3 +- packages/heading/lib/edit.tsx | 30 ++++++++++++--- packages/image/lib/edit.tsx | 6 ++- packages/layout/lib/edit.tsx | 6 ++- packages/paragraph/lib/edit.tsx | 25 +++++++++--- 9 files changed, 115 insertions(+), 29 deletions(-) diff --git a/packages/core/lib/components/Block.tsx b/packages/core/lib/components/Block.tsx index 3c1e0fe..502427c 100644 --- a/packages/core/lib/components/Block.tsx +++ b/packages/core/lib/components/Block.tsx @@ -6,7 +6,15 @@ import { ref, Ref, } from 'vue'; -import { IBlockData } from '../types'; +import { + IBlockData, + OnUpdateBlockCb, + OnActivateNextCb, + OnRemoveSelfCb, + OnAppendBlockCb, + OnPrependBlockCb, + OnActivatePreviousCb, +} from '../types'; import { SbMode } from '../mode'; import { useResizeObserver, SymBlockDimensions } from '../use-resize-observer'; import { useActivation } from '../use-activation'; @@ -34,12 +42,30 @@ export const SbBlock = defineComponent({ type: String, default: null, }, - onUpdate: { type: Function, default: () => {} }, - onPrependBlock: { type: Function, default: () => {} }, - onAppendBlock: { type: Function, default: () => {} }, - onRemoveSelf: { type: Function, default: () => {} }, - onActivatePrevious: { type: Function, default: () => {} }, - onActivateNext: { type: Function, default: () => {} }, + onUpdate: { + type: (null as unknown) as PropType, + default: () => {}, + }, + onPrependBlock: { + type: (null as unknown) as PropType, + default: () => {}, + }, + onAppendBlock: { + type: (null as unknown) as PropType, + default: () => {}, + }, + onRemoveSelf: { + type: (null as unknown) as PropType, + default: () => {}, + }, + onActivatePrevious: { + type: (null as unknown) as PropType, + default: () => {}, + }, + onActivateNext: { + type: (null as unknown) as PropType, + default: () => {}, + }, }, setup(props, context) { diff --git a/packages/core/lib/components/BlockPicker.tsx b/packages/core/lib/components/BlockPicker.tsx index 4b5cdfc..c15e1e0 100644 --- a/packages/core/lib/components/BlockPicker.tsx +++ b/packages/core/lib/components/BlockPicker.tsx @@ -7,7 +7,7 @@ import { useDynamicBlocks } from '../use-dynamic-blocks'; import { IBlockDefinition } from '../types'; import { SbButton } from './Button'; -import { SbContextMenu } from './ContextMenu'; +import { SbContextMenu, IContextMenuSlotContext } from './ContextMenu'; import './BlockPicker.scss'; @@ -39,7 +39,7 @@ export const SbBlockPicker = defineComponent({ context.slots.context + context: (slotContext:IContextMenuSlotContext) => context.slots.context ? context.slots.context(slotContext) : Insert a block, default: ({ close }: { close: Function }) => blockList.value.map((block: IBlockDefinition) => ( diff --git a/packages/core/lib/components/ContextMenu.tsx b/packages/core/lib/components/ContextMenu.tsx index 2951a10..c008e95 100644 --- a/packages/core/lib/components/ContextMenu.tsx +++ b/packages/core/lib/components/ContextMenu.tsx @@ -2,11 +2,19 @@ import { watch, defineComponent, ref, + Ref, } from 'vue'; import { SbButton } from './Button'; import './ContextMenu.scss'; +export interface IContextMenuSlotContext { + opened: Ref; + open: () => void; + close: () => void; + toggle: () => void; +} + export const SbContextMenu = defineComponent({ name: 'sb-context-menu', diff --git a/packages/core/lib/types.ts b/packages/core/lib/types.ts index 963694e..c2e7019 100644 --- a/packages/core/lib/types.ts +++ b/packages/core/lib/types.ts @@ -13,15 +13,23 @@ export interface IBlockData { data: T; } +export type OnUpdateSelfCb = (updated: Partial) => void; +export type OnUpdateBlockCb = (updated: IBlockData) => void; +export type OnPrependBlockCb = (block: IBlockData) => void; +export type OnAppendBlockCb = (block: IBlockData) => void; +export type OnRemoveSelfCb = () => void; +export type OnActivatePreviousCb = () => void; +export type OnActivateNextCb = () => void; + export interface IBlockProps { - blockId: string; + blockId?: string; data?: T, - onUpdate?: (b?: IBlockData) => void; - onPrependBlock?: (b?: IBlockData) => void; - onAppendBlock?: (b?: IBlockData) => void; - onRemoveSelf?: () => void; - onActivateNext?: () => void; - onActivatePrevious?: () => void; + onUpdate?: OnUpdateSelfCb; + onPrependBlock?: OnPrependBlockCb; + onAppendBlock?: OnAppendBlockCb; + onRemoveSelf?: OnRemoveSelfCb; + onActivateNext?: OnActivateNextCb; + onActivatePrevious?: OnActivatePreviousCb; } export interface IBlockDefinition { diff --git a/packages/docs/package.json b/packages/docs/package.json index 1e26663..543a54e 100644 --- a/packages/docs/package.json +++ b/packages/docs/package.json @@ -22,7 +22,8 @@ }, "scripts": { "dev": "concurrently 'vuedx-typecheck --no-pretty --watch ./lib' 'vite'", - "build": "vuedx-typecheck --no-pretty ./lib && vite build" + "build": "vuedx-typecheck --no-pretty ./lib && vite build", + "typecheck": "vuedx-typecheck --no-pretty ./lib" }, "dependencies": { "@schlechtenburg/core": "^0.0.0", diff --git a/packages/heading/lib/edit.tsx b/packages/heading/lib/edit.tsx index 30d6db8..04e502f 100644 --- a/packages/heading/lib/edit.tsx +++ b/packages/heading/lib/edit.tsx @@ -13,6 +13,11 @@ import { useActivation, SbToolbar, SbSelect, + OnUpdateSelfCb, + OnAppendBlockCb, + OnRemoveSelfCb, + OnActivateNextCb, + OnActivatePreviousCb, } from '@schlechtenburg/core'; import { getDefaultData, @@ -33,11 +38,26 @@ export default defineComponent({ type: (null as unknown) as PropType, default: getDefaultData, }, - onUpdate: { type: Function, default: () => {} }, - onAppendBlock: { type: Function, default: () => {} }, - onRemoveSelf: { type: Function, default: () => {} }, - onActivateNext: { type: Function, default: () => {} }, - onActivatePrevious: { type: Function, default: () => {} }, + onUpdate: { + type: (null as unknown) as PropType>, + default: () => {}, + }, + onAppendBlock: { + type: (null as unknown) as PropType, + default: () => {}, + }, + onRemoveSelf: { + type: (null as unknown) as PropType, + default: () => {}, + }, + onActivateNext: { + type: (null as unknown) as PropType, + default: () => {}, + }, + onActivatePrevious: { + type: (null as unknown) as PropType, + default: () => {}, + }, }, setup(props) { diff --git a/packages/image/lib/edit.tsx b/packages/image/lib/edit.tsx index d2076d9..d73e83f 100644 --- a/packages/image/lib/edit.tsx +++ b/packages/image/lib/edit.tsx @@ -12,6 +12,7 @@ import { SbButton, SbBlock, IBlockData, + OnUpdateSelfCb, } from '@schlechtenburg/core'; import { IParagraphData } from '@schlechtenburg/paragraph'; import { @@ -27,7 +28,10 @@ export default defineComponent({ model, props: { - onUpdate: { type: Function, default: () => {} }, + onUpdate: { + type: (null as unknown) as PropType>, + default: () => {}, + }, data: { type: (null as unknown) as PropType, default: getDefaultData, diff --git a/packages/layout/lib/edit.tsx b/packages/layout/lib/edit.tsx index 02937b2..abbe53d 100644 --- a/packages/layout/lib/edit.tsx +++ b/packages/layout/lib/edit.tsx @@ -8,6 +8,7 @@ import { import { model, IBlockData, + OnUpdateSelfCb, useActivation, SbBlock, @@ -30,7 +31,10 @@ export default defineComponent({ model, props: { - onUpdate: { type: Function, default: () => {} }, + onUpdate: { + type: (null as unknown) as PropType>, + default: () => {}, + }, data: { type: (null as unknown) as PropType, default: getDefaultData, diff --git a/packages/paragraph/lib/edit.tsx b/packages/paragraph/lib/edit.tsx index 161f163..fad7dd1 100644 --- a/packages/paragraph/lib/edit.tsx +++ b/packages/paragraph/lib/edit.tsx @@ -32,11 +32,26 @@ export default defineComponent({ type: (null as unknown) as PropType, default: getDefaultData, }, - onUpdate: { type: Function, default: () => {} }, - onAppendBlock: { type: Function, default: () => {} }, - onRemoveSelf: { type: Function, default: () => {} }, - onActivateNext: { type: Function, default: () => {} }, - onActivatePrevious: { type: Function, default: () => {} }, + onUpdate: { + type: (null as unknown) as PropType<((block?: Partial) => void)>, + default: () => {}, + }, + onAppendBlock: { + type: (null as unknown) as PropType<((block?: any) => void)>, + default: () => {}, + }, + onRemoveSelf: { + type: (null as unknown) as PropType<() => void>, + default: () => {}, + }, + onActivateNext: { + type: (null as unknown) as PropType<() => void>, + default: () => {}, + }, + onActivatePrevious: { + type: (null as unknown) as PropType<() => void>, + default: () => {}, + }, }, setup(props) {