요소
요소는 보드의 눈에 띄는 내용입니다 : 텍스트, 이미지, 모양 및 커넥터. FBoard 정면을 통해 만든 변경은 정상 명령 경로, 그래서 undo, redo, 및 협업은 그들뿐만 아니라 적용.
요소 읽기
활성 페이지를 읽기 전에 활성 보드를 얻습니다. 안정된 ID, 유형, 경계 및 주문이 필요한 경우, 전체 내부 스냅 샷에 따라 대신 descriptors를 사용하십시오.
const board = univerAPI.getActiveBoard()if (!board) throw new Error('No active board')const elements = board.describeElements()const shapes = board.findElements({ elementType: univerAPI.Enum.BoardElementType.Shape,})도형 및 텍스트 삽입
저수준 성분 스냅샷을 건설하는 대신 semantic 삽입 방법을 사용하십시오. insertShape를 위해, transform는 기하학을 나르고, 반환된 살아있는 모양 손잡이는 원본과 작풍 APIs를 드러냅니다.
const shape = board.insertShape({ shapeType: univerAPI.Enum.ShapeTypeEnum.RoundRect, transform: { left: 80, top: 80, width: 180, height: 100 }, name: 'Review card',})if (!shape) throw new Error('Cannot insert shape')shape.getText().setText('Review')shape.setRotation(6)insertText는 독립 텍스트를 추가하고 insertImage 이미지를 추가합니다. 여러 요소가 하나의 명령으로 추가되면 일괄 변형을 사용합니다.
도형 텍스트 편집
아래 예에서 insertShape()에 의해 반환된 모양을 사용하거나 이전 섹션에서 얻어진 모양. getText()는 라이브 FShape텍스 핸들을 반환합니다. 텍스트를 읽으려면 getPlainText()를 호출하여 setText()가 모든 것을 교체하고 글꼴, 색상 및 정렬 방법을 포맷합니다.
if (!shape) throw new Error('Shape is not available')const shapeText = shape.getText()console.log(shapeText.getPlainText())shapeText .setText('Quarterly review') .setFontSize(18) .setColor('#2563eb') .setBold(true) .setHorizontalAlign(univerAPI.Enum.HorizontalAlign.CENTER) .setVerticalAlign(univerAPI.Enum.VerticalAlign.MIDDLE)setText()는 기존 텍스트를 대체합니다. 단일 모양이 여러 스타일을 필요로 할 때 setRichText()를 사용하십시오. 기존의 풍부한 텍스트를 수정하려면 getRichText()?.copy()을 편집하고 빌더를 편집하고 setRichText()로 전달하십시오. 분리 된 빌더가 자동으로 적용되지 않습니다. 텍스트 스타일 및 텍스트 상자 패딩 및 레이아웃가 추가 옵션을 설명합니다.
const richText = univerAPI.newRichText() .text('Quarterly ') .bold('review')shapeText.setRichText(richText)요소 연결
연결관은 기존하는 성분 ID에 붙일 수 있습니다. 그것의 작풍, 상표, 또는 엔드포인트가 나중에 변경될 때 반환 연결관 또는 그것의 ID를 지키십시오.
const target = board.insertShape({ shapeType: univerAPI.Enum.ShapeTypeEnum.Rect, transform: { left: 360, top: 80, width: 180, height: 100 },})if (!target) throw new Error('Cannot insert target')const connector = board.insertConnector({ fromElementId: shape.getId(), toElementId: target.getId(), style: { endMarker: { type: 'filledTriangle', size: 'md' } },})if (!connector) throw new Error('Cannot insert connector')요소 변형 및 배치
변경해야 할 속성 만 전달하십시오. 주문, 정렬, 배포 및 자동 레이아웃 방법은 요소 ID를 받아들입니다.
if (!board.setElementTransform(shape.getId(), { left: 120, top: 140, rotation: 12 })) { throw new Error('Cannot transform shape')}if (!board.bringElementsToFront([shape.getId()])) { throw new Error('Cannot bring shape to front')}요소 삭제
removeElement는 단일 요소를 제거하고 removeElements은 일괄 원자로를 제거합니다. 명령이 성공했는지 모두 반환합니다.
if (!board.removeElements([connector.id, target.getId()])) { throw new Error('Cannot remove elements')}프레임 그룹 및 스릴란을 위해 컨테이너 및 Swimlanes를 계속하십시오. 널 정면 참고와 Board Element 데이터 모델는 자세한 내용을 제공합니다.
이 가이드는 어떠셨나요?