npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@asup/editor-v3

v1.3.10

Published

REACT Typescript Editor component

Downloads

534

Readme

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

| Prop | Description | | | :------------------- | :------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | -------------------- | | id | HTML component id | | | input | Input string, can from plain text, JSON or HTML fragment | | | editable | If the value can be edited | true | | setText | Function that receives the plain text in the control. Lines are separated by \n | | | setObject | Function that receives the current IEditorV3 object | | | customStyleMap | Map for CSS styles that can be used for formatting in the control | | | allowNewLine | If the control is allowed to have more than one line | false | | textAligment | Alignment for the text inside the control | EditorV3Align.left | | decimalAlignPercent | Percentage of the control width from the left hand side that the first decimal point will be placed when textAlignment = EditorV3Align.decimal | 60 | | style | CSS styles to apply to the outer control element | | | resize | Indicates whether the control can be resized or not | false | | spellCheck | Indicates whether the control allows the browser spell check to run | false | | styleOnContextMenu | Indicates if the available styles are shown on the context menu | true | | markdownSettings | Characters to use in markdown | as below | | debounceMilliSeconds | Number 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 blurred | null | | atListFunction | Function 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.