This commit is contained in:
hanshiyang committed 2025-09-23 10:43:28 +08:00
commit 977ba1c283
456 files changed
+52892

No files matched your search

+49
View File
@@ -0,0 +1,49 @@
# Common API
## splitText
Feature: split text
Usage:
```javascript
import { splitText } from '@hufe921/canvas-editor'
splitText(text: string): string[]
```
## createDomFromElementList
Feature: Create a DOM tree based on the elementList
Usage:
```javascript
import { createDomFromElementList } from '@hufe921/canvas-editor'
createDomFromElementList(elementList: IElement[], options?: IEditorOption): HTMLDivElement
```
## getElementListByHTML
Feature: Create an elementList based on HTML
Usage:
```javascript
import { getElementListByHTML } from '@hufe921/canvas-editor'
getElementListByHTML(htmlText: string, options: IGetElementListByHTMLOption): IElement[]
```
## getTextFromElementList
Feature: Create text based on elementList
Usage:
```javascript
import { getTextFromElementList } from '@hufe921/canvas-editor'
getTextFromElementList(elementList: IElement[]): string
```
+24
View File
@@ -0,0 +1,24 @@
# Instance API
## How to Use
```javascript
import Editor from "@hufe921/canvas-editor"
const instance = new Editor(container, <IElement[]>data, options)
instance.apiName()
```
## destroy
Feature: Destroy the editor
Usage:
```javascript
instance.destroy()
```
::: warning
Only destroy the editor DOM and related events, menu bars, toolbars, external variables, etc. need to be handled by themselves.
:::
File diff suppressed because it is too large. Load diff
+333
View File
@@ -0,0 +1,333 @@
# Get Data Command
## How to Use
```javascript
import Editor from "@hufe921/canvas-editor"
const instance = new Editor(container, <IElement[]>data, options)
const value = instance.command.commandName()
```
## getValue
Feature: Get the current document value
Usage:
```javascript
const {
version: string
data: IEditorData
options: IEditorOption
} = instance.command.getValue(options?: IGetValueOption)
```
## getValueAsync
Feature: Get the current document value (async)
Usage:
```javascript
const {
version: string
data: IEditorData
options: IEditorOption
} = await instance.command.getValueAsync(options?: IGetValueOption)
```
## getImage
Feature: Gets the base64 string of the current page image
Usage:
```javascript
const base64StringList = await instance.command.getImage(option?: IGetImageOption)
```
## getOptions
Feature: Get editor options
Usage:
```javascript
const editorOption = await instance.command.getOptions()
```
## getWordCount
Feature: Get document word count
Usage:
```javascript
const wordCount = await instance.command.getWordCount()
```
## getCursorPosition
Feature: Get cursor position with coordinates
Usage:
```javascript
const range = instance.command.getCursorPosition()
```
## getRange
Feature: Get range
Usage:
```javascript
const range = instance.command.getRange()
```
## getRangeText
Feature: Get range text
Usage:
```javascript
const rangeText = instance.command.getRangeText()
```
## getRangeContext
Feature: Get range context
Usage:
```javascript
const rangeContext = instance.command.getRangeContext()
```
## getRangeRow
Feature: Get range row element list
Usage:
```javascript
const rowElementList = instance.command.getRangeRow()
```
## getKeywordRangeList
Feature: Get range list by keyword
Usage:
```javascript
const rangeList = instance.command.getKeywordRangeList()
```
## getKeywordContext
Feature: Get context list by keyword
Usage:
```javascript
const keywordContextList = instance.command.getKeywordContext(payload: string)
```
## getRangeParagraph
Feature: Get range paragraph element list
Usage:
```javascript
const paragraphElementList = instance.command.getRangeParagraph()
```
## getPaperMargin
Feature: Gets the margins
Usage:
```javascript
const [top: number, right: number, bottom: number, left: number] =
instance.command.getPaperMargin()
```
## getSearchNavigateInfo
Feature: Get search navigation information
Usage:
```javascript
const {
index: number;
count: number;
} = instance.command.getSearchNavigateInfo()
```
## getCatalog
Feature: Get directory
Usage:
```javascript
const catalog = await instance.command.getCatalog()
```
## getHTML
Feature: Get HTML
Usage:
```javascript
const {
header: string
main: string
footer: string
} = await instance.command.getHTML()
```
## getText
Feature: Get text
Usage:
```javascript
const {
header: string
main: string
footer: string
} = await instance.command.getText()
```
## getLocale
Feature: Get current locale
Usage:
```javascript
const locale = await instance.command.getLocale()
```
## getGroupIds
Feature: Get all group ids
Usage:
```javascript
const groupIds = await instance.command.getGroupIds()
```
## getControlValue
Feature: Get control value
Usage:
```javascript
const {
value: string | null
innerText: string | null
zone: EditorZone
elementList?: IElement[]
} = await instance.command.getControlValue(payload: IGetControlValueOption)
```
## getControlList
Feature: Get control list
Usage:
```javascript
const controlList = await instance.command.getControlList()
```
## getContainer
Feature: Get editor container
Usage:
```javascript
const container = await instance.command.getContainer()
```
## getTitleValue
Feature: Get title value
Usage:
```javascript
const {
value: string | null
elementList: IElement[]
zone: EditorZone
}[] = await instance.command.getTitleValue(payload: IGetTitleValueOption)
```
## getPositionContextByEvent
Feature: Get position context by mouse event
Usage:
```javascript
const {
pageNo: number
element: IElement | null
rangeRect: RangeRect | null
tableInfo: ITableInfoByEvent | null
}[] = await instance.command.getPositionContextByEvent(evt: MouseEvent, options?: IPositionContextByEventOption)
```
demo:
```javascript
instance.eventBus.on(
'mousemove',
debounce(evt => {
const positionContext = instance.command.getPositionContextByEvent(evt)
console.log(positionContext)
}, 200)
)``
```
## getElementById
Feature: Get element list by id
Usage:
```javascript
const elementList = await instance.command.getElementById(payload: IGetElementByIdOption)
```
## getAreaValue
Feature: Get area value
Usage:
```javascript
const {
id?: string
area: IArea
value: IElement[]
startPageNo: number
endPageNo: number
} = instance.command.getAreaValue(options: IGetAreaValueOption)
```
+44
View File
@@ -0,0 +1,44 @@
# Customize Contextmenu
## How to Use
```javascript
import Editor from "@hufe921/canvas-editor"
const instance = new Editor(container, <IElement[]>data, options)
instance.register.contextMenuList([
{
key?: string;
isDivider?: boolean;
icon?: string;
name?: string; // Use %s for selection text. Example: Search: %s
shortCut?: string;
disable?: boolean;
when?: (payload: IContextMenuContext) => boolean;
callback?: (command: Command, context: IContextMenuContext) => any;
childMenus?: IRegisterContextMenu[];
}
])
```
## getContextMenuList
Feature: Get context menu list
Usage:
```javascript
const contextMenuList = await instance.register.getContextMenuList()
```
Remark:
```javascript
// Example of modifying internal contextmenu
contextmenuList.forEach(menu => {
// Find the menu item through the menu key and modify its properties
if (menu.key === INTERNAL_CONTEXT_MENU_KEY.GLOBAL.PASTE) {
menu.when = () => false
}
})
```
+61
View File
@@ -0,0 +1,61 @@
# Internal Contextmenu
## Global
- Cut
- Copy
- Paste
- Select all
- Print
## Hyperlinks
- Delete the link
- Unlink
- Edit the link
## Image
- Change the picture
- Save as picture
- Text wrapping
- Embed
- Up down
- Surround
- Float above text
- Float below text
## Table
- Table borders
- All borders
- Borderless
- Dashed border
- Outer border
- Internal border
- Td borders
- Top border
- Right border
- Bottom border
- Left border
- Forward border
- Back border
- Vertical alignment
- Top alignment
- Center vertically
- Bottom end alignment
- Insert rows and columns
- Insert 1 row above
- Insert 1 row below
- Insert 1 column on the left
- Insert 1 column on the right side
- Delete rows and columns
- Delete 1 row
- Remove 1 column
- Delete the entire table
- Merge cells
- Cancel the merge
## control
- Delete the control
+234
View File
@@ -0,0 +1,234 @@
# Event Listening(eventBus)
## How to Use
```javascript
import Editor from "@hufe921/canvas-editor"
const instance = new Editor(container, <IElement[]>data, options)
// register
instance.eventBus.on<K keyof EventMap>(
eventName: K,
callback: EventMap[K]
)
// remove
instance.eventBus.off<K keyof EventMap>(
eventName: K,
callback: EventMap[K]
)
```
## rangeStyleChange
Feature: The selection style changes
Usage:
```javascript
instance.eventBus.on('rangeStyleChange', (payload: IRangeStyle) => void)
```
## visiblePageNoListChange
Feature: The visible page changes
Usage:
```javascript
instance.eventBus.on('visiblePageNoListChange', (payload: number[]) => void)
```
## intersectionPageNoChange
Feature: The current page changes
Usage:
```javascript
instance.eventBus.on('intersectionPageNoChange', (payload: number) => void)
```
## pageSizeChange
Feature: The current number of pages has changed
Usage:
```javascript
instance.eventBus.on('pageSizeChange', (payload: number) => void)
```
## pageScaleChange
Feature: The current page scaling has changed
Usage:
```javascript
instance.eventBus.on('pageScaleChange', (payload: number) => void)
```
## contentChange
Feature: The current content has changed
Usage:
```javascript
instance.eventBus.on('contentChange', () => void)
```
## controlChange
Feature: The control where the current cursor is located changes
Usage:
```javascript
instance.eventBus.on('controlChange', (payload: IControlChangeResult) => void)
```
## controlContentChange
Feature: The control content changes
Usage:
```javascript
instance.eventBus.on('controlContentChange', (payload: IControlContentChangeResult) => void)
```
## pageModeChange
Feature: The page mode changes
Usage:
```javascript
instance.eventBus.on('pageModeChange', (payload: PageMode) => void)
```
## saved
Feature: Document saved
Usage:
```javascript
instance.eventBus.on('saved', (payload: IEditorResult) => void)
```
## zoneChange
Feature: The zone changes
Usage:
```javascript
instance.eventBus.on('zoneChange', (payload: EditorZone) => void)
```
## mousemove
Feature: Editor mousemove event
Usage:
```javascript
instance.eventBus.on('mousemove', (evt: MouseEvent) => void)
```
## mouseenter
Feature: Editor mouseenter event
Usage:
```javascript
instance.eventBus.on('mouseenter', (evt: MouseEvent) => void)
```
## mouseleave
Feature: Editor mouseleave event
Usage:
```javascript
instance.eventBus.on('mouseleave', (evt: MouseEvent) => void)
```
## mousedown
Feature: Editor mousedown event
Usage:
```javascript
instance.eventBus.on('mousedown', (evt: MouseEvent) => void)
```
## mouseup
Feature: Editor mouseup event
Usage:
```javascript
instance.eventBus.on('mouseup', (evt: MouseEvent) => void)
```
## click
Feature: Editor click event
Usage:
```javascript
instance.eventBus.on('click', (evt: MouseEvent) => void)
```
## input
Feature: Editor input event
Usage:
```javascript
instance.eventBus.on('input', (evt: Event) => void)
```
## positionContextChange
Feature: The position context change
Usage:
```javascript
instance.eventBus.on('positionContextChange', (payload: IPositionContextChangePayload) => void)
```
## imageSizeChange
Feature: The image size change
Usage:
```javascript
instance.eventBus.on('imageSizeChange', (payload: { element: IElement }) => void)
```
## imageMousedown
Feature: The image mousedown event
Usage:
```javascript
instance.eventBus.on('imageMousedown', (payload: {
evt: MouseEvent
element: IElement
}) => void)
```
+112
View File
@@ -0,0 +1,112 @@
# i18n
## How to Use
```javascript
import Editor from "@hufe921/canvas-editor"
const instance = new Editor(container, <IElement[]>data, options)
// register
instance.register.langMap(locale: string, lang: ILang)
// set locale
instance.command.executeSetLocale(locale)
```
## ILang
```typescript
interface ILang {
contextmenu: {
global: {
cut: string
copy: string
paste: string
selectAll: string
print: string
}
control: {
delete: string
}
hyperlink: {
delete: string
cancel: string
edit: string
}
image: {
change: string
saveAs: string
textWrap: string
textWrapType: {
embed: string
upDown: string
surround: string
floatTop: string
floatBottom: string
}
}
table: {
insertRowCol: string
insertTopRow: string
insertBottomRow: string
insertLeftCol: string
insertRightCol: string
deleteRowCol: string
deleteRow: string
deleteCol: string
deleteTable: string
mergeCell: string
mergeCancelCell: string
verticalAlign: string
verticalAlignTop: string
verticalAlignMiddle: string
verticalAlignBottom: string
border: string
borderAll: string
borderEmpty: string
borderDash: string
borderExternal: string
borderInternal: string
borderTd: string
borderTdTop: string
borderTdRight: string
borderTdBottom: string
borderTdLeft: string
borderTdForward: string
borderTdBack: string
}
}
datePicker: {
now: string
confirm: string
return: string
timeSelect: string
weeks: {
sun: string
mon: string
tue: string
wed: string
thu: string
fri: string
sat: string
}
year: string
month: string
hour: string
minute: string
second: string
}
frame: {
header: string
footer: string
}
pageBreak: {
displayName: string
}
zone: {
headerTip: string
footerTip: string
}
}
```
+126
View File
@@ -0,0 +1,126 @@
# Event Listening(listener)
::: warning
The listener can only respond to one method, and no new listening methods will be added in the future. It is recommended to use eventBus for event listening.
:::
## How to Use
```javascript
import Editor from "@hufe921/canvas-editor"
const instance = new Editor(container, <IElement[]>data, options)
instance.listener.eventName = ()=>{}
```
## rangeStyleChange
Feature: The selection style changes
Usage:
```javascript
instance.listener.rangeStyleChange = (payload: IRangeStyle) => {}
```
## visiblePageNoListChange
Feature: The visible page changes
Usage:
```javascript
instance.listener.visiblePageNoListChange = (payload: number[]) => {}
```
## intersectionPageNoChange
Feature: The current page changes
Usage:
```javascript
instance.listener.intersectionPageNoChange = (payload: number) => {}
```
## pageSizeChange
Feature: The current page size has changed
Usage:
```javascript
instance.listener.pageSizeChange = (payload: number) => {}
```
## pageScaleChange
Feature: The current page scaling has changed
Usage:
```javascript
instance.listener.pageScaleChange = (payload: number) => {}
```
## contentChange
Feature: The current content has changed
Usage:
```javascript
instance.listener.contentChange = () => {}
```
## controlChange
Feature: The control where the current cursor is located changes
Usage:
```javascript
instance.listener.controlChange = (payload: IControlChangeResult) => {}
```
## controlContentChange
Feature: The control content changes
Usage:
```javascript
instance.listener.controlContentChange = (
payload: IControlContentChangeResult
) => {}
```
## pageModeChange
Feature: The page mode changes
Usage:
```javascript
instance.listener.pageModeChange = (payload: PageMode) => {}
```
## saved
Feature: Document saved
Usage:
```javascript
instance.listener.saved = (payload: IEditorResult) => {}
```
## zoneChange
Feature: 区域发生改变
Usage:
```javascript
instance.listener.zoneChange = (payload: EditorZone) => {}
```
+189
View File
@@ -0,0 +1,189 @@
# Configuration
## How to Use?
```javascript
import Editor from "@hufe921/canvas-editor"
new Editor(container, IEditorData | IElement[], {
// option
})
```
## Complete Configuration
```typescript
interface IEditorOption {
mode?: EditorMode // Editor mode: Edit, Clean (Visual aids are not displayed, For example: page break), ReadOnly, Form (Only editable within the control), Print (Visual aids are not displayed, Unwritten content control), Design (Do not handle configurations such as non deletable and read-only). default: Edit
locale?: string // Language. default: zhCN
defaultType?: string // Default element type. default: TEXT
defaultColor?: string // Default color. default: #000000
defaultFont?: string // Default font. default: Microsoft YaHei
defaultSize?: number // Default font size. default: 16
minSize?: number // Min font size。default: 5
maxSize?: number // Max font size。default: 72
defaultBasicRowMarginHeight?: number // Default line height。default: 8
defaultRowMargin?: number // Default line spacing. default: 1
defaultTabWidth?: number // Default tab width. default: 32
width?: number // Paper width. default: 794
height?: number // Paper height. default: 1123
scale?: number // scaling. default: 1
pageGap?: number // Paper spacing. default: 20
underlineColor?: string // Underline color. default: #000000
strikeoutColor?: string // Strikeout color. default: #FF0000
rangeColor?: string // Range color. default: #AECBFA
rangeAlpha?: number // Range transparency. default: 0.6
rangeMinWidth?: number // Range min width. default: 5
searchMatchColor?: string // Search for highlight color. default: #FFFF00
searchNavigateMatchColor?: string // Search navigation highlighted color.default: #AAD280
searchMatchAlpha?: number // Search for highlight transparency. default: 0.6
highlightAlpha?: number // Highlight element transparency. default: 0.6
highlightMarginHeight?: number // Highlight element margin height. default: 8
resizerColor?: string // Image sizer color. default: #4182D9
resizerSize?: number // Image sizer size. default: 5
marginIndicatorSize?: number // The margin indicator length. default: 35
marginIndicatorColor?: string // The margin indicator color. default: #BABABA
margins?: IMargin // Page margins. default: [100, 120, 100, 120]
pageMode?: PageMode // Paper mode: Linkage, Pagination. default: Pagination
renderMode?: RenderMode // Render mode: speed(multi words combination rendering), compatibility(word by word rendering:avoid environmental differences such as browse,fonts...). default: speed
defaultHyperlinkColor?: string // Default hyperlink color. default: #0000FF
table?: ITableOption // table configuration {tdPadding?:IPadding; defaultTrMinHeight?:number; defaultColMinWidth?:number}
header?: IHeader // Header information.{top?:number; maxHeightRadio?:MaxHeightRatio;}
footer?: IFooter // Footer information. {bottom?:number; maxHeightRadio?:MaxHeightRatio;}
pageNumber?: IPageNumber // Page number information. {bottom:number; size:number; font:string; color:string; rowFlex:RowFlex; format:string; numberType:NumberType;}
paperDirection?: PaperDirection // Paper orientation: portrait, landscape
inactiveAlpha?: number // When the body content is out of focus, transparency. default: 0.6
historyMaxRecordCount?: number // History (undo redo) maximum number of records. default: 100
printPixelRatio?: number // Print the pixel ratio (larger values are clearer, but larger sizes). default: 3
maskMargin?: IMargin // Masking margins above the editor(for example: menu bar, bottom toolbar)。default: [0, 0, 0, 0]
letterClass?: string[] // Alphabet class supported by typesetting. default: a-zA-Z. Built-in alternative alphabet class: LETTER_CLASS
contextMenuDisableKeys?: string[] // Disable context menu keys. default: []
shortcutDisableKeys?: string[] // Disable shortcut keys. default: []
scrollContainerSelector?: string // scroll container selector. default: document
pageOuterSelectionDisable?: boolean // Disable selection when the mouse moves out of the page. default: false
wordBreak?: WordBreak // Word and punctuation breaks: No punctuation in the first line of the BREAK_WORD &The word is not split, and the line is folded after BREAK_ALL full according to the width of the character. default: BREAK_WORD
watermark?: IWatermark // Watermark{data:string; color?:string; opacity?:number; size?:number; font?:string; numberType:NumberType;}
control?: IControlOption // Control {placeholderColor?:string; bracketColor?:string; prefix?:string; postfix?:string; borderWidth?: number; borderColor?: string; activeBackgroundColor?: string; disabledBackgroundColor?: string; existValueBackgroundColor?: string; noValueBackgroundColor?: string;}
checkbox?: ICheckboxOption // Checkbox {width?:number; height?:number; gap?:number; lineWidth?:number; fillStyle?:string; strokeStyle?: string; verticalAlign?: VerticalAlign;}
radio?: IRadioOption // Radio {width?:number; height?:number; gap?:number; lineWidth?:number; fillStyle?:string; strokeStyle?: string; verticalAlign?: VerticalAlign;}
cursor?: ICursorOption // Cursor style. {width?: number; color?: string; dragWidth?: number; dragColor?: string; dragFloatImageDisabled?: boolean;}
title?: ITitleOption // Title configuration.{ defaultFirstSize?: number; defaultSecondSize?: number; defaultThirdSize?: number defaultFourthSize?: number; defaultFifthSize?: number; defaultSixthSize?: number;}
placeholder?: IPlaceholder // Placeholder text
group?: IGroup // Group option. {opacity?:number; backgroundColor?:string; activeOpacity?:number; activeBackgroundColor?:string; disabled?:boolean; deletable?:boolean;}
pageBreak?: IPageBreak // PageBreak option。{font?:string; fontSize?:number; lineDash?:number[];}
zone?: IZoneOption // Zone option。{tipDisabled?:boolean;}
background?: IBackgroundOption // Background option. {color?:string; image?:string; size?:BackgroundSize; repeat?:BackgroundRepeat; applyPageNumbers?:number[]}。default: {color: '#FFFFFF'}
lineBreak?: ILineBreakOption // LineBreak option. {disabled?:boolean; color?:string; lineWidth?:number;}
separator?: ISeparatorOption // Separator option. {lineWidth?:number; strokeStyle?:string;}
lineNumber?: ILineNumberOption // LineNumber option. {size?:number; font?:string; color?:string; disabled?:boolean; right?:number}
pageBorder?: IPageBorderOption // PageBorder option. {color?:string; lineWidth:number; padding?:IPadding; disabled?:boolean;}
badge?: IBadgeOption // Badge option. {top?:number; left?:number}
modeRule?: IModeRule // mode rule option. {print:{imagePreviewerDisabled?: boolean}; readonly:{imagePreviewerDisabled?: boolean}; form:{controlDeletableDisabled?: boolean}}
}
```
## Table Configuration
```typescript
interface ITableOption {
tdPadding?: IPadding // Cell padding. default: [0, 5, 5, 5]
defaultTrMinHeight?: number // Default table row minimum height. default: 42
defaultColMinWidth?: number // Default minimum width for table columns (applied if the overall width is sufficient, otherwise
}
```
## Header Configuration
```typescript
interface IHeader {
top?: number // Size from the top of the page.default: 30
inactiveAlpha?: number // Transparency during deactivation. default: 1
maxHeightRadio?: MaxHeightRatio // Occupies the maximum height ratio of the page.default: HALF
disabled?: boolean // Whether to disable
editable?: boolean // Disable the header content from being edited
}
```
## Footer Configuration
```typescript
interface IFooter {
bottom?: number // The size from the bottom of the page.default: 30
inactiveAlpha?: number // Transparency during deactivation. default: 1
maxHeightRadio?: MaxHeightRatio // Occupies the maximum height ratio of the page.default: HALF
disabled?: boolean // Whether to disable
editable?: boolean // Disable the footer content from being edited
}
```
## Page Number Configuration
```typescript
interface IPageNumber {
bottom?: number // The size from the bottom of the page.default: 60
size?: number // font size. default: 12
font?: string // font. default: Microsoft YaHei
color?: string // font color. default: #000000
rowFlex?: RowFlex // Line alignment. default: CENTER
format?: string // Page number format. default: {pageNo}。example:{pageNo}/{pageCount}
numberType?: NumberType // The numeric type. default: ARABIC
disabled?: boolean // Whether to disable
startPageNo?: number // Start page number.default: 1
fromPageNo?: number // Page numbers appear from page number.default: 0
maxPageNo?: number | null // Max page number(starting from 0).default: null
}
```
## Watermark Configuration
```typescript
interface IWatermark {
data: string // text.
type?: WatermarkType
width?: number
height?: number
color?: string // color. default: #AEB5C0
opacity?: number // transparency. default: 0.3
size?: number // font size. default: 200
font?: string // font. default: Microsoft YaHei
repeat?: boolean // repeat watermark. default: false
gap?: [horizontal: number, vertical: number] // watermark spacing. default: [10,10]
numberType?: NumberType // The numeric type. default: ARABIC
}
```
## Placeholder Text Configuration
```typescript
interface IPlaceholder {
data: string // text.
color?: string // color. default: #DCDFE6
opacity?: number // transparency. default: 1
size?: number // font size. default: 16
font?: string // font. default: Microsoft YaHei
}
```
## LineNumber Configuration
```typescript
interface ILineNumberOption {
size?: number // font size. default: 12
font?: string // font. default: Microsoft YaHei
color?: string // color. default: #000000
disabled?: boolean // Whether to disable. default: false
right?: number // Distance from the main text. default: 20
type?: LineNumberType // Number type (renumber each page, consecutive numbering). default: continuity
}
```
## PageBorder Configuration
```typescript
interface IPageBorderOption {
color?: string // color. default: #000000
lineWidth?: number // line width. default: 1
padding?: IPadding // padding. default: [0, 0, 0, 0]
disabled?: boolean // Whether to disable. default: true
}
```
+47
View File
@@ -0,0 +1,47 @@
# Override
## How to Use
```javascript
import Editor from "@hufe921/canvas-editor"
const instance = new Editor(container, <IElement[]>data, options)
instance.override.overrideFunction = () => unknown | IOverrideResult
```
```typescript
interface IOverrideResult {
preventDefault?: boolean // Prevent the execution of internal default method. Default prevent
}
```
## paste
Feature: Override internal paste function
Usage:
```javascript
instance.override.paste = (evt?: ClipboardEvent) => unknown | IOverrideResult
```
## copy
Feature: Override internal copy function
Usage:
```javascript
instance.override.copy = () => unknown | IOverrideResult
```
## drop
Feature: Override internal drop function
Usage:
```javascript
instance.override.drop = (evt: DragEvent) => unknown | IOverrideResult
```
+25
View File
@@ -0,0 +1,25 @@
# Custom Plugin
::: tip
Official plugin: https://github.com/Hufe921/canvas-editor-plugin
:::
## Write a Plugin
```javascript
export function myPlugin(editor: Editor, options?: Option) {
// 1. update,see more:src/plugins/copy
editor.command.updateFunction = () => {}
// 2. add,see more:src/plugins/markdown
editor.command.addFunction = () => {}
// 3. listener, eventbus, shortcut, contextmenu, override...
}
```
## Use Plugin
```javascript
instance.use(myPlugin, options?: Option)
```
+125
View File
@@ -0,0 +1,125 @@
# Official plugin
::: tip
Official plugin: https://github.com/Hufe921/canvas-editor-plugin
Official plugin demo: https://hufe.club/canvas-editor-plugin
:::
## Barcode1d
```javascript
import Editor from "@hufe921/canvas-editor"
import barcode1DPlugin from "@hufe921/canvas-editor-plugin-barcode1d"
const instance = new Editor()
instance.use(barcode1DPlugin)
instance.executeInsertBarcode1D(
content: string,
width: number,
height: number,
options?: JsBarcode.Options
)
```
## Barcode2d
```javascript
import Editor from "@hufe921/canvas-editor"
import barcode2DPlugin from "@hufe921/canvas-editor-plugin-barcode2d"
const instance = new Editor()
instance.use(barcode2DPlugin, options?: IBarcode2DOption)
instance.executeInsertBarcode2D(
content: string,
width: number,
height: number,
hints?: Map<EncodeHintType, any>
)
```
## Code block
```javascript
import Editor from "@hufe921/canvas-editor"
import codeblockPlugin from "@hufe921/canvas-editor-plugin-codeblock"
const instance = new Editor()
instance.use(codeblockPlugin)
instance.executeInsertCodeblock(content: string)
```
## Word
```javascript
import Editor from '@hufe921/canvas-editor'
import docxPlugin from '@hufe921/canvas-editor-plugin-docx'
const instance = new Editor()
instance.use(docxPlugin)
command.executeImportDocx({
arrayBuffer: buffer
})
instance.executeExportDocx({
fileName: string
})
```
## Excel
```javascript
import Editor from '@hufe921/canvas-editor'
import excelPlugin from '@hufe921/canvas-editor-plugin-excel'
const instance = new Editor()
instance.use(excelPlugin)
command.executeImportExcel({
arrayBuffer: buffer
})
```
## Floating toolbar
```javascript
import Editor from '@hufe921/canvas-editor'
import floatingToolbarPlugin from '@hufe921/canvas-editor-plugin-floating-toolbar'
const instance = new Editor()
instance.use(floatingToolbarPlugin)
```
## Diagram
```javascript
import Editor from '@hufe921/canvas-editor'
import diagramPlugin from '@hufe921/canvas-editor-plugin-diagram'
const instance = new Editor()
instance.use(diagramPlugin)
command.executeLoadDiagram({
lang?: Lang
data?: string
onDestroy?: (message?: any) => void
})
```
## Convert uppercase and lowercase
```javascript
import Editor from '@hufe921/canvas-editor'
import casePlugin from '@hufe921/canvas-editor-plugin-case'
const instance = new Editor()
instance.use(casePlugin)
command.executeUpperCase()
command.executeLowerCase()
```
+209
View File
@@ -0,0 +1,209 @@
# Data Structure
```typescript
interface IElement {
// basic
id?: string;
type?: {
TEXT = 'text',
IMAGE = 'image',
TABLE = 'table',
HYPERLINK = 'hyperlink',
SUPERSCRIPT = 'superscript',
SUBSCRIPT = 'subscript',
SEPARATOR = 'separator',
PAGE_BREAK = 'pageBreak',
CONTROL = 'control',
CHECKBOX = 'checkbox',
RADIO = 'radio',
LATEX = 'latex',
TAB = 'tab',
DATE = 'date',
BLOCK = 'block'
};
value: string;
valueList?: IElement[]; // Use of composite elements (hyperlinks, titles, lists, and so on).
extension?: unknown;
externalId?: string;
hide?: boolean;
// style
font?: string;
size?: number;
width?: number;
height?: number;
bold?: boolean;
color?: string;
highlight?: string;
italic?: boolean;
underline?: boolean;
strikeout?: boolean;
rowFlex?: {
LEFT = 'left',
CENTER = 'center',
RIGHT = 'right',
ALIGNMENT = 'alignment',
JUSTIFY = 'justify'
};
rowMargin?: number;
letterSpacing?: number;
textDecoration?: {
style?: TextDecorationStyle;
};
// groupIds
groupIds?: string[];
// table
conceptId?: string;
colgroup?: {
width: number;
}[];
trList?: {
height: number;
pagingRepeat?: boolean;
extension?: unknown;
externalId?: string;
tdList: {
colspan: number;
rowspan: number;
conceptId?: string;
verticalAlign?: VerticalAlign;
backgroundColor?: string;
borderTypes?: TdBorder[];
slashTypes?: TdSlash[];
value: IElement[];
extension?: unknown;
externalId?: string;
disabled?: boolean;
deletable?: boolean;
}[];
}[];
borderType?: TableBorder;
borderColor?: string;
borderWidth?: number;
borderExternalWidth?: number;
tableToolDisabled?: boolean;
// Hyperlinks
url?: string;
// Superscript and subscript
actualSize?: number;
// Dividing line
dashArray?: number[];
// control
control?: {
type: {
TEXT = 'text',
SELECT = 'select',
CHECKBOX = 'checkbox',
RADIO = 'radio',
DATE = 'date',
NUMBER = 'number'
};
value: IElement[] | null;
placeholder?: string;
groupId?: string;
conceptId?: string;
prefix?: string;
postfix?: string;
preText?: string;
postText?: string;
minWidth?: number;
underline?: boolean;
border?: boolean;
extension?: unknown;
indentation?: ControlIndentation;
rowFlex?: RowFlex
deletable?: boolean;
disabled?: boolean;
pasteDisabled?: boolean;
hide?: boolean;
code: string | null;
min?: number;
max?: number;
flexDirection: FlexDirection;
valueSets: {
value: string;
code: string;
}[];
isMultiSelect?: boolean;
multiSelectDelimiter?: string;
dateFormat?: string;
font?: string;
size?: number;
bold?: boolean;
color?: string;
highlight?: string;
italic?: boolean;
strikeout?: boolean;
selectExclusiveOptions?: {
inputAble?: boolean;
}
};
controlComponent?: {
PREFIX = 'prefix',
POSTFIX = 'postfix',
PLACEHOLDER = 'placeholder',
VALUE = 'value',
CHECKBOX = 'checkbox',
RADIO = 'radio'
};
// checkbox
checkbox?: {
value: boolean | null;
};
// radio
radio?: {
value: boolean | null;
};
// LaTeX
laTexSVG?: string;
// date
dateFormat?: string;
// picture
imgDisplay?: {
INLINE = 'inline',
BLOCK = 'block'
}
imgFloatPosition?: {
x: number;
y: number;
pageNo?: number;
}
imgToolDisabled?: boolean;
// block
block?: {
type: {
IFRAME = 'iframe',
VIDEO = 'video'
};
iframeBlock?: {
src?: string;
srcdoc?: string;
};
videoBlock?: {
src: string;
};
};
// title
level?: TitleLevel;
title?: {
conceptId?: string;
deletable?: boolean;
disabled?: boolean;
};
// list
listType?: ListType;
listStyle?: ListStyle;
listWrap?: boolean;
// area
areaId?: string;
area?: {
extension?: unknown;
top?: number;
hide?: boolean;
borderColor?: string;
backgroundColor?: string;
mode?: AreaMode;
deletable?: boolean;
placeholder?: IPlaceholder;
};
}
```
+22
View File
@@ -0,0 +1,22 @@
# Custom shortcut keys
## How to use?
```javascript
import Editor from "@hufe921/canvas-editor"
const instance = new Editor(container, <IElement[]>data, options)
instance.register.shortcutList([
{
key: KeyMap;
ctrl?: boolean;
meta?: boolean;
mod?: boolean; // windows:ctrl || mac:command
shift?: boolean;
alt?: boolean;
isGlobal?: boolean;
callback?: (command: Command) => any;
disable?: boolean;
}
])
```
+189
View File
@@ -0,0 +1,189 @@
# Internal shortcut keys
## Backspace
Feature: Forward delete
## Delete
Feature: Backward delete
## Enter
Feature: Line break
## Shift + Enter
Feature: Line breaks within the list
## ←
Feature: Move to the left
## Shift + ←
Feature: Zoom the selection to the left
## Ctrl/Cmd + ←
Feature: Move to the left(jump word)
## Ctrl/Cmd + Shift + ←
Feature: Zoom the selection to the left(jump word)
## →
Feature: Move to the right
## Shift + →
Feature: Zoom the selection to the right
## Ctrl/Cmd + →
Feature: Move to the right(jump word)
## Ctrl/Cmd + Shift + →
Feature: Zoom the selection to the right(jump word)
## ↑
Feature: Move up
## Shift + ↑
Feature: Zoom up the selection
## ↓
Feature: Move down
## Shift + ↓
Feature: Zoom down the selection
## Esc
Feature: Exit format brush
## Tab
Feature: Increase indent/Move next control
## Shift + Tab
Feature: Move previous control
## Ctrl/Cmd + Z
Feature: Undo
## Ctrl/Cmd + Y
Feature: Redo
## Ctrl/Cmd + C
Feature: Copy
## Ctrl/Cmd + X
Feature: Cut
## Ctrl/Cmd + A
Feature: Select all
## Ctrl/Cmd + S
Feature: Save
## Ctrl/Cmd + {
Feature: Increase the font
## Ctrl/Cmd + }
Feature: Reduce the font
## Ctrl/Cmd + B
Feature: Bold
## Ctrl/Cmd + I
Feature: Italic
## Ctrl/Cmd + U
Feature: Underline
## Ctrl/Cmd + L
Feature: Line left
## Ctrl/Cmd + E
Feature: Line center
## Ctrl/Cmd + R
Feature: Line right
## Ctrl/Cmd + J
Feature: Both sides are aligned
## Ctrl/Cmd + Shift + J
Feature: Line justify
## Ctrl + Shift + X
Feature: Strikethrough
## Ctrl/Cmd + Shift + >
Feature: Superscript
## Ctrl/Cmd + Shift + <
Feature: Subscript
## Ctrl + Alt/Option + 0
Feature: Main body
## Ctrl + Alt/Option + 1
Feature: Header1
## Ctrl + Alt/Option + 2
Feature: Header2
## Ctrl + Alt/Option + 3
Feature: Header3
## Ctrl + Alt/Option + 4
Feature: Header4
## Ctrl + Alt/Option + 5
Feature: Header5
## Ctrl + Alt/Option + 6
Feature: Header6
## Ctrl/Cmd + Shift + I
Feature: Unordered list
## Ctrl/Cmd + Shift + U
Feature: Ordered list
+97
View File
@@ -0,0 +1,97 @@
# Getting Started
> WYSIWYG rich text editor.
Benefit from the complete self-implementation of cursor and text layout. The underlying rendering can also be rendered by svg, See code:[feature/svg](https://github.com/Hufe921/canvas-editor/tree/feature/svg); Or complete pdf drawing with pdfjs,See code:[feature/pdf](https://github.com/Hufe921/canvas-editor/tree/feature/pdf).
::: warning
The official only provides the editor core layer npm package, the menu bar or other external tools can refer to the document extension, or directly refer the implementation of [official](https://github.com/Hufe921/canvas-editor), See details [demo](https://hufe.club/canvas-editor/).
:::
## Features
- Rich text operations (Undo, Redo, Font, Size, Bold, Italic, Underline, Strikeout, Superscript, Alignment, Title, List, ...)
- Insert elements (Table, Image, Link, Code Block, Page Break, Math Formula, Date Picker, Block, ...)
- Print (Based on canvas to picture, pdf drawing)
- Controls (Select, Text, Date, Radio, Checkbox)
- Right-click menu (Internal, Custom)
- Shortcut keys (Internal, Custom)
- Drag and Drop(Text, Element, Control)
- Header, Footer, Page Number
- Page Margin
- Watermark
- Pagination
- Comment
- Catalog
- [Plugin](https://github.com/Hufe921/canvas-editor-plugin)
## TODO
- Computational performance
- Control rule
- Table paging
- Out of the box version for vue, react and other frameworks
## Step. 1: Download NPM Package
```sh
npm i @hufe921/canvas-editor --save
```
## Step. 2: Prepare Container
```html
<div class="canvas-editor"></div>
```
## Step. 3: Instantiate Editor
- Examples that only the body content is included
```javascript
import Editor from '@hufe921/canvas-editor'
new Editor(
document.querySelector('.canvas-editor'),
[
{
value: 'Hello World'
}
],
{}
)
```
- Examples that contain body, header, footer content
```javascript
import Editor from '@hufe921/canvas-editor'
new Editor(
document.querySelector('.canvas-editor'),
{
header: [
{
value: 'Header',
rowFlex: RowFlex.CENTER
}
],
main: [
{
value: 'Hello World'
}
],
footer: [
{
value: 'canvas-editor',
size: 12
}
]
},
{}
)
```
## Step. 4: Configuration Editor
See the next section for details