1.2.10 • Published 4 days ago

@asup/editor-v3 v1.2.10

Weekly downloads
-
License
MIT
Repository
github
Last release
4 days ago

npm size npm bundle size License: MIT

@asup/editor-v3

REACT Typescript Editor component, because I couldn't quite find what I wanted.

Installation

# with npm
npm install @asup/editor-v3

Usage

Context menu provider, takes a list of available actions and renders a context menu on appropriate click. Wrap around the elements that need to have the menu

import { EditorV3, EditorV3Align, EditorV3Styles, IEditorV3, EditorV3AtListItem } from '@asup/editor-v3';

... inside REACT component

<EditorV3
  id: string;
  input: string | IEditorV3;
  editable?: boolean;
  setText?: (ret: string) => void;
  setObject?: (ret: IEditorV3) => void;
  customStyleMap?: EditorV3Styles;
  allowNewLine?: boolean;
  textAlignment?: EditorV3Align;
  decimalAlignPercent?: number;
  style?: CSSProperties;
  resize?: boolean;
  spellCheck?: boolean;
  styleOnContextMenu?: boolean;
  allowMarkdown?: boolean;
  markdownSettings?: IMarkdownSettings;
  debounceMilliseconds?: number | null;
  atListFunction?: (at: string) => Promise<EditorV3AtListItem<Record<string, string>>[]>;
  ...rest (of HTMLDivElement)
/>

Properties

PropDescription
idHTML component id
inputInput string, can from plain text, JSON or HTML fragment
editableIf the value can be editedtrue
setTextFunction that receives the plain text in the control. Lines are separated by \n
setObjectFunction that receives the current IEditorV3 object
customStyleMapMap for CSS styles that can be used for formatting in the control
allowNewLineIf the control is allowed to have more than one linefalse
textAligmentAlignment for the text inside the controlEditorV3Align.left
decimalAlignPercentPercentage of the control width from the left hand side that the first decimal point will be placed when textAlignment = EditorV3Align.decimal60
styleCSS styles to apply to the outer control element
resizeIndicates whether the control can be resized or notfalse
spellCheckIndicates whether the control allows the browser spell check to runfalse
styleOnContextMenuIndicates if the available styles are shown on the context menutrue
markdownSettingsCharacters to use in markdownas below
debounceMilliSecondsNumber of milliseconds to wait before sending the response back via one of the setTTTT functions. If this is set to null the return will only be made when the component is blurrednull
atListFunctionFunction that will be called to return a list of available @matched items

Returns

The control can return any of or all of the following output types, and will accept any as an input.

Text

For when only the text matters, will operate as a normal control, returning text when the control is blurred.

Object

Object return

IEditorV3

{
  lines: [{
    textBlocks: [{
      text: string,
      style?: string,
      type?: "text" | "at",
      isLocked?: true | undefined,
      lineStartPosition?: number,
      atData?: Record<string, string>,
      maxAtListLength?: number,
    }],
    contentProps?: EditorV3ContentPropsInput
  }];
  contentProps?: EditorV3ContentPropsInput,
}

The values for contentProps will always be the same for all entries in the object, but are copied for convenience

AtListFunction

Assigning a function to this parameter will enable collaberative @mentions.

EditorV3ContentPropsInput

This is mainly for internal use, and will be over ridden by any settings in the editor, however given here for completeness

{
  allowMarkdown?: boolean,
  allowNewLine?: boolean,
  decimalAlignPercent?: number,
  markdownSettings?: IMarkdownSettings,
  showMarkdown?: boolean,
  styles?: EditorV3Styles,
  textAlignment?: EditorV3Align,
  atListFunction?: (typedString: string) => Promise<EditorV3AtListItem<Record<string, string>>[]>,
}

The value of style in any given text block, should match one of the keys in the style object, the CSS styles from the object will then be applied to the text block.

EditorV3Style extends React.CSSProperties {
  isLocked?: boolean;
}
EditorV3Styles {
  [styleName: string]: EditorV3Style;
}

isLocked has been added as a style property, to allow blocks to be non-editable. They still can be deleted in their entirety. This is used for @mention blocks.

Editor utility

Cut and paste

Styles pasted between different controls will be kept, other objects pasted into the control will be pasted as plain text.

1.2.10

4 days ago

1.2.9

11 days ago

1.2.8

1 month ago

1.2.7

1 month ago

1.2.6

1 month ago

1.2.5

1 month ago

1.2.4

2 months ago

1.2.3

2 months ago

1.2.2

2 months ago

1.2.1

2 months ago

1.2.0

2 months ago

1.1.6

3 months ago

1.1.5

3 months ago

1.1.4

4 months ago

1.1.3

4 months ago

1.1.2

4 months ago

1.1.1

5 months ago

1.1.0

6 months ago

1.0.5

6 months ago

1.0.2

10 months ago

1.0.1

10 months ago

1.0.4

10 months ago

1.0.3

10 months ago

1.0.0

1 year ago

0.1.0

1 year ago