Fix TypeScript errors

This commit is contained in:
Benjamin Bädorf 2022-03-12 17:16:24 +01:00
parent 190a8be207
commit ff668eff31
No known key found for this signature in database
GPG key ID: 4406E80E13CD656C
9 changed files with 115 additions and 29 deletions

View file

@ -6,7 +6,15 @@ import {
ref, ref,
Ref, Ref,
} from 'vue'; } from 'vue';
import { IBlockData } from '../types'; import {
IBlockData,
OnUpdateBlockCb,
OnActivateNextCb,
OnRemoveSelfCb,
OnAppendBlockCb,
OnPrependBlockCb,
OnActivatePreviousCb,
} from '../types';
import { SbMode } from '../mode'; import { SbMode } from '../mode';
import { useResizeObserver, SymBlockDimensions } from '../use-resize-observer'; import { useResizeObserver, SymBlockDimensions } from '../use-resize-observer';
import { useActivation } from '../use-activation'; import { useActivation } from '../use-activation';
@ -34,12 +42,30 @@ export const SbBlock = defineComponent({
type: String, type: String,
default: null, default: null,
}, },
onUpdate: { type: Function, default: () => {} }, onUpdate: {
onPrependBlock: { type: Function, default: () => {} }, type: (null as unknown) as PropType<OnUpdateBlockCb>,
onAppendBlock: { type: Function, default: () => {} }, default: () => {},
onRemoveSelf: { type: Function, default: () => {} }, },
onActivatePrevious: { type: Function, default: () => {} }, onPrependBlock: {
onActivateNext: { type: Function, default: () => {} }, type: (null as unknown) as PropType<OnPrependBlockCb>,
default: () => {},
},
onAppendBlock: {
type: (null as unknown) as PropType<OnAppendBlockCb>,
default: () => {},
},
onRemoveSelf: {
type: (null as unknown) as PropType<OnRemoveSelfCb>,
default: () => {},
},
onActivatePrevious: {
type: (null as unknown) as PropType<OnActivatePreviousCb>,
default: () => {},
},
onActivateNext: {
type: (null as unknown) as PropType<OnActivateNextCb>,
default: () => {},
},
}, },
setup(props, context) { setup(props, context) {

View file

@ -7,7 +7,7 @@ import { useDynamicBlocks } from '../use-dynamic-blocks';
import { IBlockDefinition } from '../types'; import { IBlockDefinition } from '../types';
import { SbButton } from './Button'; import { SbButton } from './Button';
import { SbContextMenu } from './ContextMenu'; import { SbContextMenu, IContextMenuSlotContext } from './ContextMenu';
import './BlockPicker.scss'; import './BlockPicker.scss';
@ -39,7 +39,7 @@ export const SbBlockPicker = defineComponent({
<SbContextMenu <SbContextMenu
class="sb-tree-block-select" class="sb-tree-block-select"
v-slots={{ v-slots={{
context: (slotContext) => context.slots.context context: (slotContext:IContextMenuSlotContext) => context.slots.context
? context.slots.context(slotContext) ? context.slots.context(slotContext)
: <SbButton {...{ onClick: slotContext.toggle }}>Insert a block</SbButton>, : <SbButton {...{ onClick: slotContext.toggle }}>Insert a block</SbButton>,
default: ({ close }: { close: Function }) => blockList.value.map((block: IBlockDefinition<any>) => ( default: ({ close }: { close: Function }) => blockList.value.map((block: IBlockDefinition<any>) => (

View file

@ -2,11 +2,19 @@ import {
watch, watch,
defineComponent, defineComponent,
ref, ref,
Ref,
} from 'vue'; } from 'vue';
import { SbButton } from './Button'; import { SbButton } from './Button';
import './ContextMenu.scss'; import './ContextMenu.scss';
export interface IContextMenuSlotContext {
opened: Ref<boolean>;
open: () => void;
close: () => void;
toggle: () => void;
}
export const SbContextMenu = defineComponent({ export const SbContextMenu = defineComponent({
name: 'sb-context-menu', name: 'sb-context-menu',

View file

@ -13,15 +13,23 @@ export interface IBlockData<T> {
data: T; data: T;
} }
export type OnUpdateSelfCb<T> = (updated: Partial<T>) => void;
export type OnUpdateBlockCb = (updated: IBlockData<any>) => void;
export type OnPrependBlockCb = (block: IBlockData<any>) => void;
export type OnAppendBlockCb = (block: IBlockData<any>) => void;
export type OnRemoveSelfCb = () => void;
export type OnActivatePreviousCb = () => void;
export type OnActivateNextCb = () => void;
export interface IBlockProps<T> { export interface IBlockProps<T> {
blockId: string; blockId?: string;
data?: T, data?: T,
onUpdate?: (b?: IBlockData<T>) => void; onUpdate?: OnUpdateSelfCb<T>;
onPrependBlock?: (b?: IBlockData<T>) => void; onPrependBlock?: OnPrependBlockCb;
onAppendBlock?: (b?: IBlockData<T>) => void; onAppendBlock?: OnAppendBlockCb;
onRemoveSelf?: () => void; onRemoveSelf?: OnRemoveSelfCb;
onActivateNext?: () => void; onActivateNext?: OnActivateNextCb;
onActivatePrevious?: () => void; onActivatePrevious?: OnActivatePreviousCb;
} }
export interface IBlockDefinition<T> { export interface IBlockDefinition<T> {

View file

@ -22,7 +22,8 @@
}, },
"scripts": { "scripts": {
"dev": "concurrently 'vuedx-typecheck --no-pretty --watch ./lib' 'vite'", "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": { "dependencies": {
"@schlechtenburg/core": "^0.0.0", "@schlechtenburg/core": "^0.0.0",

View file

@ -13,6 +13,11 @@ import {
useActivation, useActivation,
SbToolbar, SbToolbar,
SbSelect, SbSelect,
OnUpdateSelfCb,
OnAppendBlockCb,
OnRemoveSelfCb,
OnActivateNextCb,
OnActivatePreviousCb,
} from '@schlechtenburg/core'; } from '@schlechtenburg/core';
import { import {
getDefaultData, getDefaultData,
@ -33,11 +38,26 @@ export default defineComponent({
type: (null as unknown) as PropType<IHeadingData>, type: (null as unknown) as PropType<IHeadingData>,
default: getDefaultData, default: getDefaultData,
}, },
onUpdate: { type: Function, default: () => {} }, onUpdate: {
onAppendBlock: { type: Function, default: () => {} }, type: (null as unknown) as PropType<OnUpdateSelfCb<IHeadingData>>,
onRemoveSelf: { type: Function, default: () => {} }, default: () => {},
onActivateNext: { type: Function, default: () => {} }, },
onActivatePrevious: { type: Function, default: () => {} }, onAppendBlock: {
type: (null as unknown) as PropType<OnAppendBlockCb>,
default: () => {},
},
onRemoveSelf: {
type: (null as unknown) as PropType<OnRemoveSelfCb>,
default: () => {},
},
onActivateNext: {
type: (null as unknown) as PropType<OnActivateNextCb>,
default: () => {},
},
onActivatePrevious: {
type: (null as unknown) as PropType<OnActivatePreviousCb>,
default: () => {},
},
}, },
setup(props) { setup(props) {

View file

@ -12,6 +12,7 @@ import {
SbButton, SbButton,
SbBlock, SbBlock,
IBlockData, IBlockData,
OnUpdateSelfCb,
} from '@schlechtenburg/core'; } from '@schlechtenburg/core';
import { IParagraphData } from '@schlechtenburg/paragraph'; import { IParagraphData } from '@schlechtenburg/paragraph';
import { import {
@ -27,7 +28,10 @@ export default defineComponent({
model, model,
props: { props: {
onUpdate: { type: Function, default: () => {} }, onUpdate: {
type: (null as unknown) as PropType<OnUpdateSelfCb<IImageData>>,
default: () => {},
},
data: { data: {
type: (null as unknown) as PropType<IImageData>, type: (null as unknown) as PropType<IImageData>,
default: getDefaultData, default: getDefaultData,

View file

@ -8,6 +8,7 @@ import {
import { import {
model, model,
IBlockData, IBlockData,
OnUpdateSelfCb,
useActivation, useActivation,
SbBlock, SbBlock,
@ -30,7 +31,10 @@ export default defineComponent({
model, model,
props: { props: {
onUpdate: { type: Function, default: () => {} }, onUpdate: {
type: (null as unknown) as PropType<OnUpdateSelfCb<ILayoutData>>,
default: () => {},
},
data: { data: {
type: (null as unknown) as PropType<ILayoutData>, type: (null as unknown) as PropType<ILayoutData>,
default: getDefaultData, default: getDefaultData,

View file

@ -32,11 +32,26 @@ export default defineComponent({
type: (null as unknown) as PropType<IParagraphData>, type: (null as unknown) as PropType<IParagraphData>,
default: getDefaultData, default: getDefaultData,
}, },
onUpdate: { type: Function, default: () => {} }, onUpdate: {
onAppendBlock: { type: Function, default: () => {} }, type: (null as unknown) as PropType<((block?: Partial<IParagraphData>) => void)>,
onRemoveSelf: { type: Function, default: () => {} }, default: () => {},
onActivateNext: { type: Function, default: () => {} }, },
onActivatePrevious: { type: Function, 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) { setup(props) {