Webcards Editor is a powerful WYSIWYG page builder built on React/Redux in Typescript.
npm install webcards-editor
This is a WIP
I am building this as part of a project and it's still under development. Please submit any issues or feature requests to GitHub.
The API is currently still in development and there may be some breaking changes in the future.
import PageEditor from 'webcards-editor';
PageEditor component is the main component you'll have to use if all you want is to implement a simple page editor. This is the component responsible for loading content from the server into the editor and saving content from the editor to the server. All the details are handled by this component.
||Optional||The initial content of the page. This can be loaded in from the server as it is just a simple JSON object. It can also be generated manually using the
||Optional||The root of the content will try to automatically scale itself to 100vh, which can be an obstacle if you have extra toolbars above the editor. Settings this number to e.g. 100 will set the body to be 100vh - 100px.|
||Optional||When the save button on the toolbar is clicked this function is invoked and you can save the
import * as content from 'webcards-editor/dist/editor/content/content';
ContentIteminterface defines what an item in the editor is. Since we're never dealing with HTML directly this is the main type we use to determine what the page looks like. These are what you'll be saving and loading from the server, and you can use generators to convert these items into HTML.
It is not recommended you create these objects manually and instead to use the utility functions instead (see below). Creating them manually requires a lot of house-keeping, such as giving them unique IDs, maintaining parent references and their positions within a container.
This table is meant simply as a reference for querying the items.
||Required||A unique ID for the item|
||Required||The type of element. See
||Required||The item containing this item|
||Required||The index of the item relative to its siblings.|
||Required||Any information associated with the item, including style attributes. Custom attributes are allowed here.|
ContentItemto add a
childrenproperty. It's exactly like a
ContentItemexcept for the fact that it can contain other items itself.
As above, it is not recommended to create these objects manually. Use the utility functions instead.
||Required||An array of
|style||CSSProperties||Required||React CSS properties|
|*||any||Optional||You can add any other properties to the data item which might make it more useful. For example, the
Content creation utilities
createContentItem(type: string, data: ContentData)=>ContentItem
- Creates a blank item with a type and associated data. The item type is derived from the ID string passed in as the first argument. This is a bare-bones function and may not create any associated items (such as child elements in a template).
createContainerItem(type: string, data: ContentData, children: ContentItem)=>ContainerItem
createContentItem, this will do the same but return a
ContainerItemwith an array of children attached. This will automatically set the
parentreference of each child as well as their positions.
generateDefault(type: string, data?: ContentData, children?: ContentItem)=>ContentItem
- Generates a default instance of an
ItemType, identified by
createContentItemthis will do extra things that the
ItemTypewants, such as applying styles or even adding child items.
generateText(text: string, options?)=>ContentItem
- Generates a text item with populated with
ContentDataobject so must include a
styleattribute (even if empty), and a
variant(h1 - h6, p, span)
generateContainer(children: ContentItem, options?: ContentData)=>ContainerItem
- Utility to create a generic container with children.
- A row is a special type of container which can only contain columns. This is akin to rows and columns in Bootstrap.
generateColumn(span: IOneToTwelve, children?: ContentItem)=>ContainerItem
- Generates a column with a span between 1 and 12.
import * as itemTypes from 'webcards-editor/dist/editor/content/itemTypes';
Note: This namespace is not yet complete. Adding new items types and categories is not currently possible without editing the source code. This is meant as a reference for querying items and their types.
||Required||A unique ID for the item type, e.g. "text". This is used when calling
||Required||A human-friendly name which will be displayed in the left item list drawer.|
||Required||A human-friendly description which will be displayed when hovering over the handle in the left item list drawer.|
||Optional||A list of valid children that the item can contain. Use
||Optional||For some items it's easier to specify what they can't contain. For example,
||Required||Whether the item can be edited or not.|
||Optional||Additional settings for the type. These will generate controls in the right settings drawer. (See custom).|
||Optional||Generates a default instance of this type.|
||Optional||Generates HTML attributes for an item so it can be rendered by React. Useful for doing things such as,
This is a simple interface to help categorise items in the left item list drawer.
Note: It is still not possible to create new item type categories.
||Required||The human-readable name for the category.|
||Required||A list of items in this category.|
import * as custom from 'webcards-editor/dist/editor/content/custom';
Note: This namespace is not yet complete and is simply meant as a reference.
Custom settings can be applied to item types which will render controls for them in the right settings drawer. For example, a column might have a custom setting for its span, which might render a slider to control it.
- This is a the type of data that a custom setting can manipulate.
|NUMBER||A simple numerical value.|
- This is a data point that can be manipulated by the custom settings controls. It includes the type of data that can be manipulated, such as
NUMBER, and any rules associated with the setting of that data.
||Required||The type of data to be manipulated.|
||Required||Any associated rules for manipulating this data.|
- A custom setting as it will be seen in the UI. This includes its name, the property that you want to control and any rules about how that property is controlled.
||Required||The human readable name of the setting.|
||Required||The type and rules needed to manipulate the
||Required||An array of custom settings for this type.|
- A utility to create a type and rules for custom settings.
Below is an example of how custom type settings can be implemented. This particular example is used to change the column span of a column.