2021-03-16 04:54:22 +00:00
|
|
|
import LocaleReceiver from '../locale-provider/LocaleReceiver';
|
|
|
|
import warning from '../_util/warning';
|
|
|
|
import TransButton from '../_util/transButton';
|
|
|
|
import raf from '../_util/raf';
|
2021-09-25 08:51:32 +00:00
|
|
|
import { isStyleSupport } from '../_util/styleChecker';
|
2021-03-16 04:54:22 +00:00
|
|
|
import Editable from './Editable';
|
|
|
|
import measure from './util';
|
2021-06-26 01:35:40 +00:00
|
|
|
import type { TypographyProps } from './Typography';
|
|
|
|
import Typography from './Typography';
|
2021-03-16 04:54:22 +00:00
|
|
|
import ResizeObserver from '../vc-resize-observer';
|
|
|
|
import Tooltip from '../tooltip';
|
|
|
|
import copy from '../_util/copy-to-clipboard';
|
|
|
|
import CheckOutlined from '@ant-design/icons-vue/CheckOutlined';
|
|
|
|
import CopyOutlined from '@ant-design/icons-vue/CopyOutlined';
|
|
|
|
import EditOutlined from '@ant-design/icons-vue/EditOutlined';
|
2022-03-26 14:52:54 +00:00
|
|
|
import type { VNodeTypes, CSSProperties, PropType, HTMLAttributes } from 'vue';
|
2021-03-16 04:54:22 +00:00
|
|
|
import {
|
|
|
|
defineComponent,
|
|
|
|
reactive,
|
|
|
|
ref,
|
|
|
|
onMounted,
|
|
|
|
onBeforeUnmount,
|
|
|
|
watch,
|
|
|
|
watchEffect,
|
|
|
|
nextTick,
|
|
|
|
computed,
|
|
|
|
toRaw,
|
|
|
|
} from 'vue';
|
|
|
|
import useConfigInject from '../_util/hooks/useConfigInject';
|
2021-08-29 02:44:24 +00:00
|
|
|
import type { EventHandler } from '../_util/EventInterface';
|
2021-09-25 08:51:32 +00:00
|
|
|
import omit from '../_util/omit';
|
2021-12-15 14:27:07 +00:00
|
|
|
import type { AutoSizeType } from '../input/inputProps';
|
2021-03-16 04:54:22 +00:00
|
|
|
|
|
|
|
export type BaseType = 'secondary' | 'success' | 'warning' | 'danger';
|
|
|
|
|
|
|
|
const isLineClampSupport = isStyleSupport('webkitLineClamp');
|
|
|
|
const isTextOverflowSupport = isStyleSupport('textOverflow');
|
|
|
|
|
|
|
|
export interface CopyConfig {
|
|
|
|
text?: string;
|
|
|
|
onCopy?: () => void;
|
|
|
|
tooltip?: boolean;
|
|
|
|
}
|
|
|
|
|
|
|
|
export interface EditConfig {
|
|
|
|
editing?: boolean;
|
|
|
|
tooltip?: boolean;
|
|
|
|
onStart?: () => void;
|
|
|
|
onChange?: (value: string) => void;
|
|
|
|
onCancel?: () => void;
|
|
|
|
onEnd?: () => void;
|
|
|
|
maxlength?: number;
|
|
|
|
autoSize?: boolean | AutoSizeType;
|
2022-03-12 01:56:32 +00:00
|
|
|
triggerType?: ('icon' | 'text')[];
|
2021-03-16 04:54:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
export interface EllipsisConfig {
|
|
|
|
rows?: number;
|
|
|
|
expandable?: boolean;
|
|
|
|
suffix?: string;
|
|
|
|
symbol?: string;
|
2021-08-29 02:44:24 +00:00
|
|
|
onExpand?: EventHandler;
|
2021-03-16 04:54:22 +00:00
|
|
|
onEllipsis?: (ellipsis: boolean) => void;
|
2022-01-11 15:23:07 +00:00
|
|
|
tooltip?: any;
|
2021-03-16 04:54:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
export interface BlockProps extends TypographyProps {
|
|
|
|
title?: string;
|
|
|
|
editable?: boolean | EditConfig;
|
|
|
|
copyable?: boolean | CopyConfig;
|
|
|
|
type?: BaseType;
|
|
|
|
disabled?: boolean;
|
|
|
|
ellipsis?: boolean | EllipsisConfig;
|
|
|
|
// decorations
|
|
|
|
code?: boolean;
|
|
|
|
mark?: boolean;
|
|
|
|
underline?: boolean;
|
|
|
|
delete?: boolean;
|
|
|
|
strong?: boolean;
|
|
|
|
keyboard?: boolean;
|
|
|
|
content?: string;
|
|
|
|
}
|
|
|
|
|
|
|
|
interface Locale {
|
|
|
|
edit?: string;
|
|
|
|
copy?: string;
|
|
|
|
copied?: string;
|
|
|
|
expand?: string;
|
|
|
|
}
|
|
|
|
|
|
|
|
interface InternalBlockProps extends BlockProps {
|
|
|
|
component: string;
|
|
|
|
}
|
|
|
|
|
|
|
|
const ELLIPSIS_STR = '...';
|
|
|
|
|
2022-03-26 14:52:54 +00:00
|
|
|
export const baseProps = () => ({
|
|
|
|
editable: {
|
|
|
|
type: [Boolean, Object] as PropType<InternalBlockProps['editable']>,
|
|
|
|
default: undefined as InternalBlockProps['editable'],
|
|
|
|
},
|
|
|
|
copyable: {
|
|
|
|
type: [Boolean, Object] as PropType<InternalBlockProps['copyable']>,
|
|
|
|
default: undefined as InternalBlockProps['copyable'],
|
|
|
|
},
|
|
|
|
prefixCls: String,
|
|
|
|
component: String,
|
|
|
|
type: String as PropType<BaseType>,
|
|
|
|
disabled: { type: Boolean, default: undefined },
|
|
|
|
ellipsis: {
|
|
|
|
type: [Boolean, Object] as PropType<InternalBlockProps['ellipsis']>,
|
|
|
|
default: undefined as InternalBlockProps['ellipsis'],
|
|
|
|
},
|
|
|
|
code: { type: Boolean, default: undefined },
|
|
|
|
mark: { type: Boolean, default: undefined },
|
|
|
|
underline: { type: Boolean, default: undefined },
|
|
|
|
delete: { type: Boolean, default: undefined },
|
|
|
|
strong: { type: Boolean, default: undefined },
|
|
|
|
keyboard: { type: Boolean, default: undefined },
|
|
|
|
content: String,
|
|
|
|
'onUpdate:content': Function as PropType<(content: string) => void>,
|
|
|
|
});
|
|
|
|
|
|
|
|
const Base = defineComponent({
|
2021-03-16 04:54:22 +00:00
|
|
|
name: 'Base',
|
|
|
|
inheritAttrs: false,
|
2022-03-26 14:52:54 +00:00
|
|
|
props: baseProps(),
|
|
|
|
// emits: ['update:content'],
|
2021-03-16 04:54:22 +00:00
|
|
|
setup(props, { slots, attrs, emit }) {
|
2022-03-12 01:56:32 +00:00
|
|
|
const { prefixCls, direction } = useConfigInject('typography', props);
|
2021-03-16 04:54:22 +00:00
|
|
|
|
|
|
|
const state = reactive({
|
|
|
|
edit: false,
|
|
|
|
copied: false,
|
|
|
|
ellipsisText: '',
|
|
|
|
ellipsisContent: null,
|
|
|
|
isEllipsis: false,
|
|
|
|
expanded: false,
|
|
|
|
clientRendered: false,
|
|
|
|
//locale
|
|
|
|
expandStr: '',
|
|
|
|
copyStr: '',
|
|
|
|
copiedStr: '',
|
|
|
|
editStr: '',
|
|
|
|
|
|
|
|
copyId: undefined,
|
|
|
|
rafId: undefined,
|
|
|
|
prevProps: undefined,
|
|
|
|
|
|
|
|
originContent: '',
|
|
|
|
});
|
|
|
|
|
|
|
|
const contentRef = ref();
|
|
|
|
const editIcon = ref();
|
2021-06-23 15:08:16 +00:00
|
|
|
const ellipsis = computed((): EllipsisConfig => {
|
|
|
|
const ellipsis = props.ellipsis;
|
|
|
|
if (!ellipsis) return {};
|
|
|
|
|
|
|
|
return {
|
|
|
|
rows: 1,
|
|
|
|
expandable: false,
|
|
|
|
...(typeof ellipsis === 'object' ? ellipsis : null),
|
|
|
|
};
|
|
|
|
});
|
2021-03-16 04:54:22 +00:00
|
|
|
onMounted(() => {
|
|
|
|
state.clientRendered = true;
|
|
|
|
});
|
|
|
|
|
|
|
|
onBeforeUnmount(() => {
|
2021-11-29 09:53:09 +00:00
|
|
|
clearTimeout(state.copyId);
|
2021-03-16 04:54:22 +00:00
|
|
|
raf.cancel(state.rafId);
|
|
|
|
});
|
|
|
|
|
|
|
|
watch(
|
|
|
|
[() => ellipsis.value.rows, () => props.content],
|
|
|
|
() => {
|
|
|
|
nextTick(() => {
|
|
|
|
resizeOnNextFrame();
|
|
|
|
});
|
|
|
|
},
|
|
|
|
{ flush: 'post', deep: true, immediate: true },
|
|
|
|
);
|
|
|
|
|
|
|
|
watchEffect(() => {
|
2021-06-08 06:18:54 +00:00
|
|
|
if (props.content === undefined) {
|
2021-03-16 04:54:22 +00:00
|
|
|
warning(
|
|
|
|
!props.editable,
|
|
|
|
'Typography',
|
|
|
|
'When `editable` is enabled, please use `content` instead of children',
|
|
|
|
);
|
|
|
|
warning(
|
|
|
|
!props.ellipsis,
|
|
|
|
'Typography',
|
|
|
|
'When `ellipsis` is enabled, please use `content` instead of children',
|
|
|
|
);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
function getChildrenText(): string {
|
|
|
|
return props.ellipsis || props.editable ? props.content : contentRef.value?.$el?.innerText;
|
|
|
|
}
|
|
|
|
|
|
|
|
// =============== Expand ===============
|
|
|
|
function onExpandClick(e: MouseEvent) {
|
|
|
|
const { onExpand } = ellipsis.value;
|
|
|
|
state.expanded = true;
|
|
|
|
onExpand?.(e);
|
|
|
|
}
|
|
|
|
// ================ Edit ================
|
2021-04-29 10:32:06 +00:00
|
|
|
function onEditClick(e: MouseEvent) {
|
|
|
|
e.preventDefault();
|
2021-03-16 04:54:22 +00:00
|
|
|
state.originContent = props.content;
|
|
|
|
triggerEdit(true);
|
|
|
|
}
|
|
|
|
|
|
|
|
function onEditChange(value: string) {
|
|
|
|
onContentChange(value);
|
|
|
|
triggerEdit(false);
|
|
|
|
}
|
|
|
|
function onContentChange(value: string) {
|
|
|
|
const { onChange } = editable.value;
|
|
|
|
if (value !== props.content) {
|
|
|
|
emit('update:content', value);
|
2021-03-16 07:39:44 +00:00
|
|
|
onChange?.(value);
|
2021-03-16 04:54:22 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function onEditCancel() {
|
2021-06-07 09:35:03 +00:00
|
|
|
editable.value.onCancel?.();
|
2021-03-16 04:54:22 +00:00
|
|
|
triggerEdit(false);
|
|
|
|
}
|
|
|
|
|
|
|
|
// ================ Copy ================
|
|
|
|
function onCopyClick(e: MouseEvent) {
|
|
|
|
e.preventDefault();
|
|
|
|
const { copyable } = props;
|
|
|
|
|
|
|
|
const copyConfig = {
|
|
|
|
...(typeof copyable === 'object' ? copyable : null),
|
|
|
|
};
|
|
|
|
|
|
|
|
if (copyConfig.text === undefined) {
|
|
|
|
copyConfig.text = getChildrenText();
|
|
|
|
}
|
|
|
|
|
|
|
|
copy(copyConfig.text || '');
|
|
|
|
|
|
|
|
state.copied = true;
|
|
|
|
nextTick(() => {
|
|
|
|
if (copyConfig.onCopy) {
|
|
|
|
copyConfig.onCopy();
|
|
|
|
}
|
|
|
|
|
2021-11-29 09:53:09 +00:00
|
|
|
state.copyId = setTimeout(() => {
|
2021-03-16 04:54:22 +00:00
|
|
|
state.copied = false;
|
|
|
|
}, 3000);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
const editable = computed(() => {
|
|
|
|
const editable = props.editable;
|
|
|
|
if (!editable) return { editing: state.edit };
|
|
|
|
|
|
|
|
return {
|
|
|
|
editing: state.edit,
|
|
|
|
...(typeof editable === 'object' ? editable : null),
|
|
|
|
};
|
|
|
|
});
|
|
|
|
|
|
|
|
function triggerEdit(edit: boolean) {
|
|
|
|
const { onStart } = editable.value;
|
|
|
|
if (edit && onStart) {
|
|
|
|
onStart();
|
|
|
|
}
|
|
|
|
|
|
|
|
state.edit = edit;
|
|
|
|
nextTick(() => {
|
|
|
|
if (!edit) {
|
|
|
|
editIcon.value?.focus();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
// ============== Ellipsis ==============
|
|
|
|
function resizeOnNextFrame() {
|
|
|
|
raf.cancel(state.rafId);
|
|
|
|
state.rafId = raf(() => {
|
|
|
|
// Do not bind `syncEllipsis`. It need for test usage on prototype
|
|
|
|
syncEllipsis();
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
const canUseCSSEllipsis = computed(() => {
|
|
|
|
const { rows, expandable, suffix, onEllipsis, tooltip } = ellipsis.value;
|
|
|
|
|
|
|
|
if (suffix || tooltip) return false;
|
|
|
|
|
|
|
|
// Can't use css ellipsis since we need to provide the place for button
|
|
|
|
if (props.editable || props.copyable || expandable || onEllipsis) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (rows === 1) {
|
|
|
|
return isTextOverflowSupport;
|
|
|
|
}
|
|
|
|
|
|
|
|
return isLineClampSupport;
|
|
|
|
});
|
|
|
|
|
|
|
|
const syncEllipsis = () => {
|
|
|
|
const { ellipsisText, isEllipsis } = state;
|
|
|
|
const { rows, suffix, onEllipsis } = ellipsis.value;
|
|
|
|
if (
|
|
|
|
!rows ||
|
|
|
|
rows < 0 ||
|
|
|
|
!contentRef.value?.$el ||
|
|
|
|
state.expanded ||
|
|
|
|
props.content === undefined
|
|
|
|
)
|
|
|
|
return;
|
|
|
|
|
|
|
|
// Do not measure if css already support ellipsis
|
|
|
|
if (canUseCSSEllipsis.value) return;
|
|
|
|
|
2021-06-23 15:08:16 +00:00
|
|
|
const {
|
|
|
|
content,
|
|
|
|
text,
|
|
|
|
ellipsis: ell,
|
|
|
|
} = measure(
|
2021-03-16 04:54:22 +00:00
|
|
|
contentRef.value?.$el,
|
|
|
|
{ rows, suffix },
|
|
|
|
props.content,
|
|
|
|
renderOperations(true),
|
|
|
|
ELLIPSIS_STR,
|
|
|
|
);
|
|
|
|
|
|
|
|
if (ellipsisText !== text || state.isEllipsis !== ell) {
|
|
|
|
state.ellipsisText = text;
|
|
|
|
state.ellipsisContent = content;
|
|
|
|
state.isEllipsis = ell;
|
|
|
|
if (isEllipsis !== ell && onEllipsis) {
|
|
|
|
onEllipsis(ell);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
function wrapperDecorations(
|
|
|
|
{ mark, code, underline, delete: del, strong, keyboard }: BlockProps,
|
|
|
|
content,
|
|
|
|
) {
|
|
|
|
let currentContent = content;
|
|
|
|
|
|
|
|
function wrap(needed: boolean, Tag: string) {
|
|
|
|
if (!needed) return;
|
|
|
|
|
|
|
|
currentContent = <Tag>{currentContent}</Tag>;
|
|
|
|
}
|
|
|
|
|
|
|
|
wrap(strong, 'strong');
|
|
|
|
wrap(underline, 'u');
|
|
|
|
wrap(del, 'del');
|
|
|
|
wrap(code, 'code');
|
|
|
|
wrap(mark, 'mark');
|
|
|
|
wrap(keyboard, 'kbd');
|
|
|
|
|
|
|
|
return currentContent;
|
|
|
|
}
|
|
|
|
|
|
|
|
function renderExpand(forceRender?: boolean) {
|
|
|
|
const { expandable, symbol } = ellipsis.value;
|
|
|
|
|
|
|
|
if (!expandable) return null;
|
|
|
|
|
|
|
|
// force render expand icon for measure usage or it will cause dead loop
|
|
|
|
if (!forceRender && (state.expanded || !state.isEllipsis)) return null;
|
|
|
|
const expandContent =
|
|
|
|
(slots.ellipsisSymbol ? slots.ellipsisSymbol() : symbol) || state.expandStr;
|
|
|
|
|
|
|
|
return (
|
|
|
|
<a
|
|
|
|
key="expand"
|
|
|
|
class={`${prefixCls.value}-expand`}
|
|
|
|
onClick={onExpandClick}
|
|
|
|
aria-label={state.expandStr}
|
|
|
|
>
|
|
|
|
{expandContent}
|
|
|
|
</a>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
function renderEdit() {
|
|
|
|
if (!props.editable) return;
|
|
|
|
|
2022-03-12 01:56:32 +00:00
|
|
|
const { tooltip, triggerType = ['icon'] } = props.editable as EditConfig;
|
2021-03-16 04:54:22 +00:00
|
|
|
const icon = slots.editableIcon ? slots.editableIcon() : <EditOutlined role="button" />;
|
|
|
|
const title = slots.editableTooltip ? slots.editableTooltip() : state.editStr;
|
|
|
|
const ariaLabel = typeof title === 'string' ? title : '';
|
|
|
|
|
2022-03-12 01:56:32 +00:00
|
|
|
return triggerType.indexOf('icon') !== -1 ? (
|
2021-03-16 04:54:22 +00:00
|
|
|
<Tooltip key="edit" title={tooltip === false ? '' : title}>
|
|
|
|
<TransButton
|
2021-06-07 09:35:03 +00:00
|
|
|
ref={editIcon}
|
2021-03-16 04:54:22 +00:00
|
|
|
class={`${prefixCls.value}-edit`}
|
|
|
|
onClick={onEditClick}
|
|
|
|
aria-label={ariaLabel}
|
|
|
|
>
|
|
|
|
{icon}
|
|
|
|
</TransButton>
|
|
|
|
</Tooltip>
|
2022-03-12 01:56:32 +00:00
|
|
|
) : null;
|
2021-03-16 04:54:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function renderCopy() {
|
|
|
|
if (!props.copyable) return;
|
|
|
|
|
|
|
|
const { tooltip } = props.copyable as CopyConfig;
|
|
|
|
const defaultTitle = state.copied ? state.copiedStr : state.copyStr;
|
|
|
|
const title = slots.copyableTooltip
|
|
|
|
? slots.copyableTooltip({ copied: state.copied })
|
|
|
|
: defaultTitle;
|
|
|
|
const ariaLabel = typeof title === 'string' ? title : '';
|
|
|
|
const defaultIcon = state.copied ? <CheckOutlined /> : <CopyOutlined />;
|
|
|
|
const icon = slots.copyableIcon
|
|
|
|
? slots.copyableIcon({ copied: !!state.copied })
|
|
|
|
: defaultIcon;
|
|
|
|
|
|
|
|
return (
|
|
|
|
<Tooltip key="copy" title={tooltip === false ? '' : title}>
|
|
|
|
<TransButton
|
|
|
|
class={[
|
|
|
|
`${prefixCls.value}-copy`,
|
|
|
|
{ [`${prefixCls.value}-copy-success`]: state.copied },
|
|
|
|
]}
|
|
|
|
onClick={onCopyClick}
|
|
|
|
aria-label={ariaLabel}
|
|
|
|
>
|
|
|
|
{icon}
|
|
|
|
</TransButton>
|
|
|
|
</Tooltip>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
function renderEditInput() {
|
|
|
|
const { class: className, style } = attrs;
|
2021-06-07 09:35:03 +00:00
|
|
|
const { maxlength, autoSize, onEnd } = editable.value;
|
2021-03-16 04:54:22 +00:00
|
|
|
|
|
|
|
return (
|
|
|
|
<Editable
|
|
|
|
class={className}
|
|
|
|
style={style}
|
|
|
|
prefixCls={prefixCls.value}
|
|
|
|
value={props.content}
|
|
|
|
originContent={state.originContent}
|
|
|
|
maxlength={maxlength}
|
|
|
|
autoSize={autoSize}
|
|
|
|
onSave={onEditChange}
|
|
|
|
onChange={onContentChange}
|
|
|
|
onCancel={onEditCancel}
|
2021-06-07 09:35:03 +00:00
|
|
|
onEnd={onEnd}
|
2022-03-12 01:56:32 +00:00
|
|
|
direction={direction.value}
|
|
|
|
v-slots={{ enterIcon: slots.editableEnterIcon }}
|
2021-03-16 04:54:22 +00:00
|
|
|
/>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
function renderOperations(forceRenderExpanded?: boolean) {
|
|
|
|
return [renderExpand(forceRenderExpanded), renderEdit(), renderCopy()].filter(node => node);
|
|
|
|
}
|
|
|
|
|
|
|
|
return () => {
|
2022-03-12 01:56:32 +00:00
|
|
|
const { editing, triggerType = ['icon'] } = editable.value;
|
2021-03-16 04:54:22 +00:00
|
|
|
const children =
|
|
|
|
props.ellipsis || props.editable
|
2021-06-08 06:18:54 +00:00
|
|
|
? props.content !== undefined
|
2021-03-16 04:54:22 +00:00
|
|
|
? props.content
|
|
|
|
: slots.default?.()
|
|
|
|
: slots.default
|
|
|
|
? slots.default()
|
|
|
|
: props.content;
|
|
|
|
|
|
|
|
if (editing) {
|
|
|
|
return renderEditInput();
|
|
|
|
}
|
|
|
|
return (
|
|
|
|
<LocaleReceiver
|
|
|
|
componentName="Text"
|
|
|
|
children={(locale: Locale) => {
|
2021-06-23 15:08:16 +00:00
|
|
|
const {
|
|
|
|
type,
|
|
|
|
disabled,
|
|
|
|
content,
|
|
|
|
class: className,
|
|
|
|
style,
|
|
|
|
...restProps
|
|
|
|
} = {
|
2021-03-16 04:54:22 +00:00
|
|
|
...props,
|
2022-03-26 14:52:54 +00:00
|
|
|
...(attrs as HTMLAttributes),
|
2021-03-16 04:54:22 +00:00
|
|
|
};
|
|
|
|
const { rows, suffix, tooltip } = ellipsis.value;
|
|
|
|
|
|
|
|
const { edit, copy: copyStr, copied, expand } = locale;
|
|
|
|
|
|
|
|
state.editStr = edit;
|
|
|
|
state.copyStr = copyStr;
|
|
|
|
state.copiedStr = copied;
|
|
|
|
state.expandStr = expand;
|
|
|
|
|
|
|
|
const textProps = omit(restProps, [
|
|
|
|
'prefixCls',
|
|
|
|
'editable',
|
|
|
|
'copyable',
|
|
|
|
'ellipsis',
|
|
|
|
'mark',
|
|
|
|
'code',
|
|
|
|
'delete',
|
|
|
|
'underline',
|
|
|
|
'strong',
|
|
|
|
'keyboard',
|
2022-03-26 14:52:54 +00:00
|
|
|
'onUpdate:content',
|
2021-03-16 04:54:22 +00:00
|
|
|
]);
|
|
|
|
|
|
|
|
const cssEllipsis = canUseCSSEllipsis.value;
|
|
|
|
const cssTextOverflow = rows === 1 && cssEllipsis;
|
|
|
|
const cssLineClamp = rows && rows > 1 && cssEllipsis;
|
|
|
|
|
|
|
|
let textNode = children as VNodeTypes;
|
|
|
|
let ariaLabel: string | undefined;
|
|
|
|
|
|
|
|
// Only use js ellipsis when css ellipsis not support
|
|
|
|
if (rows && state.isEllipsis && !state.expanded && !cssEllipsis) {
|
|
|
|
const { title } = restProps;
|
|
|
|
let restContent = title || '';
|
|
|
|
|
|
|
|
if (!title && (typeof children === 'string' || typeof children === 'number')) {
|
|
|
|
restContent = String(children);
|
|
|
|
}
|
|
|
|
|
|
|
|
// show rest content as title on symbol
|
|
|
|
restContent = restContent?.slice(String(state.ellipsisContent || '').length);
|
|
|
|
// We move full content to outer element to avoid repeat read the content by accessibility
|
|
|
|
textNode = (
|
|
|
|
<>
|
|
|
|
{toRaw(state.ellipsisContent)}
|
|
|
|
<span title={restContent} aria-hidden="true">
|
|
|
|
{ELLIPSIS_STR}
|
|
|
|
</span>
|
|
|
|
{suffix}
|
|
|
|
</>
|
|
|
|
);
|
|
|
|
} else {
|
|
|
|
textNode = (
|
|
|
|
<>
|
|
|
|
{children}
|
|
|
|
{suffix}
|
|
|
|
</>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
textNode = wrapperDecorations(props, textNode);
|
|
|
|
|
|
|
|
const showTooltip =
|
|
|
|
tooltip && rows && state.isEllipsis && !state.expanded && !cssEllipsis;
|
|
|
|
const title = slots.ellipsisTooltip ? slots.ellipsisTooltip() : tooltip;
|
|
|
|
return (
|
|
|
|
<ResizeObserver onResize={resizeOnNextFrame} disabled={!rows}>
|
|
|
|
<Typography
|
2021-06-07 09:35:03 +00:00
|
|
|
ref={contentRef}
|
2021-03-16 04:54:22 +00:00
|
|
|
class={[
|
2021-06-07 09:35:03 +00:00
|
|
|
{
|
|
|
|
[`${prefixCls.value}-${type}`]: type,
|
|
|
|
[`${prefixCls.value}-disabled`]: disabled,
|
|
|
|
[`${prefixCls.value}-ellipsis`]: rows,
|
2022-03-12 01:56:32 +00:00
|
|
|
[`${prefixCls.value}-single-line`]: rows === 1 && !state.isEllipsis,
|
2021-06-07 09:35:03 +00:00
|
|
|
[`${prefixCls.value}-ellipsis-single-line`]: cssTextOverflow,
|
|
|
|
[`${prefixCls.value}-ellipsis-multiple-line`]: cssLineClamp,
|
|
|
|
},
|
2021-03-16 04:54:22 +00:00
|
|
|
className,
|
|
|
|
]}
|
|
|
|
style={{
|
|
|
|
...(style as CSSProperties),
|
|
|
|
WebkitLineClamp: cssLineClamp ? rows : undefined,
|
|
|
|
}}
|
|
|
|
aria-label={ariaLabel}
|
2022-03-12 01:56:32 +00:00
|
|
|
direction={direction.value}
|
|
|
|
onClick={triggerType.indexOf('text') !== -1 ? onEditClick : () => {}}
|
2021-03-16 04:54:22 +00:00
|
|
|
{...textProps}
|
|
|
|
>
|
|
|
|
{showTooltip ? (
|
|
|
|
<Tooltip title={tooltip === true ? children : title}>
|
|
|
|
<span>{textNode}</span>
|
|
|
|
</Tooltip>
|
|
|
|
) : (
|
|
|
|
textNode
|
|
|
|
)}
|
|
|
|
{renderOperations()}
|
|
|
|
</Typography>
|
|
|
|
</ResizeObserver>
|
|
|
|
);
|
|
|
|
}}
|
|
|
|
/>
|
|
|
|
);
|
|
|
|
};
|
|
|
|
},
|
|
|
|
});
|
|
|
|
|
|
|
|
export default Base;
|