Browse Source

feat(@vben/plugins): tiptap 组件新增 maxHeight 属性支持

- 新增 maxHeight prop 支持限制编辑器最大高度
- 编辑器内容区超出最大高度时自动滚动
- 移除 style.css 中未使用的 CSS 规则
pull/7897/head
yuan.ji 5 months ago
parent
commit
e7eff0037c
  1. 6
      packages/effects/plugins/src/tiptap/style.css
  2. 13
      packages/effects/plugins/src/tiptap/tiptap.vue
  3. 1
      packages/effects/plugins/src/tiptap/types.ts
  4. 23
      playground/src/adapter/component/index.ts

6
packages/effects/plugins/src/tiptap/style.css

@ -1,9 +1,5 @@
@reference "@vben/tailwind-config/theme"; @reference "@vben/tailwind-config/theme";
.vben-tiptap-content > * + * {
@apply mt-3;
}
.vben-tiptap-content h1 { .vben-tiptap-content h1 {
@apply text-2xl font-bold leading-[1.4]; @apply text-2xl font-bold leading-[1.4];
} }
@ -50,8 +46,6 @@
.vben-tiptap-content img, .vben-tiptap-content img,
.vben-tiptap-content .vben-tiptap__image { .vben-tiptap-content .vben-tiptap__image {
@apply my-4 block h-auto rounded-2xl border border-border;
max-width: min(100%, 640px); max-width: min(100%, 640px);
} }

13
packages/effects/plugins/src/tiptap/tiptap.vue

@ -28,6 +28,7 @@ const props = withDefaults(defineProps<TipTapProps>(), {
extensions: undefined, extensions: undefined,
imageUpload: undefined, imageUpload: undefined,
minHeight: 240, minHeight: 240,
maxHeight: 400,
placeholder: $t('ui.tiptap.placeholder'), placeholder: $t('ui.tiptap.placeholder'),
previewable: true, previewable: true,
toolbar: true, toolbar: true,
@ -41,9 +42,14 @@ const contentMinHeight = computed(() =>
? `${props.minHeight}px` ? `${props.minHeight}px`
: props.minHeight, : props.minHeight,
); );
const contentMaxHeight = computed(() =>
typeof props.maxHeight === 'number'
? `${props.maxHeight}px`
: props.maxHeight,
);
const tiptapContentClass = cn( const tiptapContentClass = cn(
'vben-tiptap-content vben-tiptap__content', 'vben-tiptap-content vben-tiptap__content',
'text-foreground min-h-(--vben-tiptap-min-height) leading-7 outline-none', 'text-foreground max-h-(--vben-tiptap-max-height) min-h-(--vben-tiptap-min-height) overflow-auto leading-7 outline-none',
); );
const blobUrlTracker = new Set<string>(); const blobUrlTracker = new Set<string>();
const editor = useEditor({ const editor = useEditor({
@ -154,7 +160,10 @@ onBeforeUnmount(() => {
<template> <template>
<div <div
:style="{ '--vben-tiptap-min-height': contentMinHeight }" :style="{
'--vben-tiptap-min-height': contentMinHeight,
'--vben-tiptap-max-height': contentMaxHeight,
}"
class="vben-tiptap overflow-hidden rounded-xl border border-border bg-card" class="vben-tiptap overflow-hidden rounded-xl border border-border bg-card"
> >
<div <div

1
packages/effects/plugins/src/tiptap/types.ts

@ -30,6 +30,7 @@ export interface TipTapProps {
extensions?: Extensions; extensions?: Extensions;
imageUpload?: ImageUploadOptions; imageUpload?: ImageUploadOptions;
minHeight?: number | string; minHeight?: number | string;
maxHeight?: number | string;
placeholder?: string; placeholder?: string;
previewable?: boolean; previewable?: boolean;
toolbar?: boolean; toolbar?: boolean;

23
playground/src/adapter/component/index.ts

@ -73,6 +73,8 @@ import { isEmpty } from '@vben/utils';
import { VbenCollapsibleParams } from '@vben-core/shadcn-ui'; import { VbenCollapsibleParams } from '@vben-core/shadcn-ui';
import { message, Modal, notification } from 'ant-design-vue'; import { message, Modal, notification } from 'ant-design-vue';
import { upload_file } from '#/api/examples/upload';
type AdapterUploadProps = UploadProps & { type AdapterUploadProps = UploadProps & {
aspectRatio?: string; aspectRatio?: string;
crop?: boolean; crop?: boolean;
@ -722,7 +724,26 @@ async function initComponentAdapter() {
RadioGroup, RadioGroup,
RangePicker, RangePicker,
Rate, Rate,
RichEditor: withDefaultPlaceholder(VbenTiptap, 'input'), RichEditor: withDefaultPlaceholder(VbenTiptap, 'input', {
imageUpload: {
upload: (file: any, onProgress: any) => {
return new Promise((resolve, reject) => {
upload_file({
file,
onProgress({ percent }) {
onProgress?.(percent);
},
onSuccess(response) {
resolve(response);
},
onError() {
reject(new Error($t('ui.tiptap.upload.uploadFailed')));
},
});
});
},
},
}),
Select: withDefaultPlaceholder(Select, 'select'), Select: withDefaultPlaceholder(Select, 'select'),
Space, Space,
Switch, Switch,

Loading…
Cancel
Save