Skip to content
This repository has been archived by the owner on Apr 21, 2021. It is now read-only.

Commit

Permalink
Merge branch 'main' of github.com:ueberdosis/tiptap-next into main
Browse files Browse the repository at this point in the history
  • Loading branch information
hanspagel committed Jan 28, 2021
2 parents 62f42a2 + 1c0d56e commit cde0d86
Show file tree
Hide file tree
Showing 112 changed files with 605 additions and 208 deletions.
10 changes: 5 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@
"test:open": "cypress open --project tests",
"test": "cypress run --project tests --quiet --reporter list",
"build:docs": "yarn --cwd ./docs build",
"build:ci": "yarn clean:packages && for dir in packages/*; do package=${dir#'packages/'}; rollup -c --ci --scope @tiptap/$package; done",
"build:packages": "yarn clean:packages && for dir in packages/*; do package=${dir#'packages/'}; rollup -c --scope @tiptap/$package; done",
"build:ci": "yarn clean:packages && for dir in packages/*; do package=${dir#'packages/'}; rollup -c --ci --scope @tiptap/$package || exit 1; done",
"build:packages": "yarn clean:packages && for dir in packages/*; do package=${dir#'packages/'}; rollup -c --scope @tiptap/$package || exit 1; done",
"release": "yarn lint && yarn test && yarn build:packages && lerna publish",
"clean:packages": "rm -rf ./packages/*/dist",
"reset": "yarn clean:packages && rm -rf ./**/.cache && rm -rf ./**/node_modules && rm -rf ./yarn.lock && yarn install"
Expand All @@ -35,8 +35,8 @@
"@rollup/plugin-babel": "^5.2.1",
"@rollup/plugin-commonjs": "^17.0.0",
"@rollup/plugin-node-resolve": "^11.0.1",
"@typescript-eslint/eslint-plugin": "^4.14.0",
"@typescript-eslint/parser": "^4.14.0",
"@typescript-eslint/eslint-plugin": "^4.14.1",
"@typescript-eslint/parser": "^4.14.1",
"cypress": "^6.3.0",
"eslint": "^7.15.0",
"eslint-config-airbnb-base": "^14.2.0",
Expand All @@ -52,7 +52,7 @@
"rollup-plugin-terser": "^7.0.2",
"rollup-plugin-typescript2": "^0.29.0",
"rollup-plugin-vue": "5",
"typedoc": "^0.20.18",
"typedoc": "^0.20.19",
"typescript": "^4.1.3",
"vue": "^2.6.12"
}
Expand Down
19 changes: 19 additions & 0 deletions packages/core/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,25 @@
All notable changes to this project will be documented in this file.
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.

# [2.0.0-alpha.12](https://github.com/ueberdosis/tiptap-next/compare/@tiptap/core@2.0.0-alpha.11...@tiptap/core@2.0.0-alpha.12) (2021-01-28)

**Note:** Version bump only for package @tiptap/core





# [2.0.0-alpha.11](https://github.com/ueberdosis/tiptap-next/compare/@tiptap/core@2.0.0-alpha.10...@tiptap/core@2.0.0-alpha.11) (2021-01-28)


### Bug Fixes

* don’t merge classes ([dba0c1a](https://github.com/ueberdosis/tiptap-next/commit/dba0c1ac15e9beda3ebd027c67c969a4fe7ae7c7))





# [2.0.0-alpha.10](https://github.com/ueberdosis/tiptap-next/compare/@tiptap/core@2.0.0-alpha.9...@tiptap/core@2.0.0-alpha.10) (2021-01-06)

**Note:** Version bump only for package @tiptap/core
Expand Down
2 changes: 1 addition & 1 deletion packages/core/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@tiptap/core",
"description": "headless rich text editor",
"version": "2.0.0-alpha.10",
"version": "2.0.0-alpha.12",
"homepage": "https://tiptap.dev",
"keywords": [
"tiptap",
Expand Down
11 changes: 6 additions & 5 deletions packages/core/src/CommandManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {
ChainedCommands,
CanCommands,
CommandSpec,
CommandProps,
} from './types'
import getAllMethodNames from './utilities/getAllMethodNames'

Expand Down Expand Up @@ -41,7 +42,7 @@ export default class CommandManager {
return this.editor
}

public createCommands() {
public createCommands(): SingleCommands {
const { commands, editor } = this
const { state, view } = editor
const { tr } = state
Expand All @@ -64,7 +65,7 @@ export default class CommandManager {
})) as SingleCommands
}

public createChain(startTr?: Transaction, shouldDispatch = true) {
public createChain(startTr?: Transaction, shouldDispatch = true): ChainedCommands {
const { commands, editor } = this
const { state, view } = editor
const callbacks: boolean[] = []
Expand Down Expand Up @@ -99,7 +100,7 @@ export default class CommandManager {
}) as ChainedCommands
}

public createCan(startTr?: Transaction) {
public createCan(startTr?: Transaction): CanCommands {
const { commands, editor } = this
const { state } = editor
const dispatch = false
Expand All @@ -117,7 +118,7 @@ export default class CommandManager {
} as CanCommands
}

public buildProps(tr: Transaction, shouldDispatch = true) {
public buildProps(tr: Transaction, shouldDispatch = true): CommandProps {
const { editor, commands } = this
const { state, view } = editor

Expand All @@ -140,7 +141,7 @@ export default class CommandManager {
.entries(commands)
.map(([name, command]) => {
return [name, (...args: any[]) => command(...args)(props)]
}))
})) as SingleCommands
},
}

Expand Down
60 changes: 34 additions & 26 deletions packages/core/src/Editor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,15 @@ import createStyleTag from './utilities/createStyleTag'
import CommandManager from './CommandManager'
import ExtensionManager from './ExtensionManager'
import EventEmitter from './EventEmitter'
import { EditorOptions, EditorContent, CommandSpec } from './types'
import {
EditorOptions,
EditorContent,
CommandSpec,
CanCommands,
ChainedCommands,
SingleCommands,
AnyObject,
} from './types'
import * as extensions from './extensions'
import style from './style'

Expand Down Expand Up @@ -68,7 +76,7 @@ export class Editor extends EventEmitter {
/**
* This method is called after the proxy is initialized.
*/
private init() {
private init(): void {
this.createCommandManager()
this.createExtensionManager()
this.createSchema()
Expand Down Expand Up @@ -101,28 +109,28 @@ export class Editor extends EventEmitter {
/**
* An object of all registered commands.
*/
public get commands() {
public get commands(): SingleCommands {
return this.commandManager.createCommands()
}

/**
* Create a command chain to call multiple commands at once.
*/
public chain() {
public chain(): ChainedCommands {
return this.commandManager.createChain()
}

/**
* Check if a command or a command chain can be executed. Without executing it.
*/
public can() {
public can(): CanCommands {
return this.commandManager.createCan()
}

/**
* Inject CSS styles.
*/
private injectCSS() {
private injectCSS(): void {
if (this.options.injectCSS && document) {
this.css = createStyleTag(style)
}
Expand All @@ -133,7 +141,7 @@ export class Editor extends EventEmitter {
*
* @param options A list of options
*/
public setOptions(options: Partial<EditorOptions> = {}) {
public setOptions(options: Partial<EditorOptions> = {}): void {
this.options = { ...this.options, ...options }

if (this.view && this.state && !this.isDestroyed) {
Expand All @@ -144,14 +152,14 @@ export class Editor extends EventEmitter {
/**
* Returns whether the editor is editable.
*/
public get isEditable() {
public get isEditable(): boolean {
return this.view && this.view.editable
}

/**
* Returns the editor state.
*/
public get state() {
public get state(): EditorState {
return this.view.state
}

Expand All @@ -160,7 +168,7 @@ export class Editor extends EventEmitter {
*
* @param commands A list of commands
*/
public registerCommands(commands: { [key: string]: CommandSpec }) {
public registerCommands(commands: { [key: string]: CommandSpec }): void {
Object
.entries(commands)
.forEach(([name, command]) => this.registerCommand(name, command))
Expand All @@ -184,7 +192,7 @@ export class Editor extends EventEmitter {
* @param plugin A ProseMirror plugin
* @param handlePlugins Control how to merge the plugin into the existing plugins.
*/
public registerPlugin(plugin: Plugin, handlePlugins?: (newPlugin: Plugin, plugins: Plugin[]) => Plugin[]) {
public registerPlugin(plugin: Plugin, handlePlugins?: (newPlugin: Plugin, plugins: Plugin[]) => Plugin[]): void {
const plugins = typeof handlePlugins === 'function'
? handlePlugins(plugin, this.state.plugins)
: [plugin, ...this.state.plugins]
Expand All @@ -199,7 +207,7 @@ export class Editor extends EventEmitter {
*
* @param name The plugins name
*/
public unregisterPlugin(name: string) {
public unregisterPlugin(name: string): void {
const state = this.state.reconfigure({
// @ts-ignore
plugins: this.state.plugins.filter(plugin => !plugin.key.startsWith(`${name}$`)),
Expand All @@ -211,7 +219,7 @@ export class Editor extends EventEmitter {
/**
* Creates an extension manager.
*/
private createExtensionManager() {
private createExtensionManager(): void {
const coreExtensions = Object.entries(extensions).map(([, extension]) => extension)
const allExtensions = [...this.options.extensions, ...coreExtensions].filter(extension => {
return ['extension', 'node', 'mark'].includes(extension?.type)
Expand All @@ -223,21 +231,21 @@ export class Editor extends EventEmitter {
/**
* Creates an command manager.
*/
private createCommandManager() {
private createCommandManager(): void {
this.commandManager = new CommandManager(this.proxy)
}

/**
* Creates a ProseMirror schema.
*/
private createSchema() {
private createSchema(): void {
this.schema = this.extensionManager.schema
}

/**
* Creates a ProseMirror view.
*/
private createView() {
private createView(): void {
this.view = new EditorView(this.options.element, {
...this.options.editorProps,
dispatchTransaction: this.dispatchTransaction.bind(this),
Expand Down Expand Up @@ -265,7 +273,7 @@ export class Editor extends EventEmitter {
/**
* Creates all node views.
*/
public createNodeViews() {
public createNodeViews(): void {
this.view.setProps({
nodeViews: this.extensionManager.nodeViews,
})
Expand Down Expand Up @@ -304,7 +312,7 @@ export class Editor extends EventEmitter {
*
* @param transaction An editor state transaction
*/
private dispatchTransaction(transaction: Transaction) {
private dispatchTransaction(transaction: Transaction): void {
const state = this.state.apply(transaction)
const selectionHasChanged = !this.state.selection.eq(state.selection)

Expand Down Expand Up @@ -338,7 +346,7 @@ export class Editor extends EventEmitter {
*
* @param name Name of the node
*/
public getNodeAttributes(name: string) {
public getNodeAttributes(name: string): AnyObject {
return getNodeAttributes(this.state, name)
}

Expand All @@ -347,7 +355,7 @@ export class Editor extends EventEmitter {
*
* @param name Name of the mark
*/
public getMarkAttributes(name: string) {
public getMarkAttributes(name: string): AnyObject {
return getMarkAttributes(this.state, name)
}

Expand All @@ -374,21 +382,21 @@ export class Editor extends EventEmitter {
/**
* Get the document as JSON.
*/
public getJSON() {
public getJSON(): AnyObject {
return this.state.doc.toJSON()
}

/**
* Get the document as HTML.
*/
public getHTML() {
public getHTML(): string {
return getHTMLFromFragment(this.state.doc, this.schema)
}

/**
* Check if there is no content.
*/
public isEmpty() {
public isEmpty(): boolean {
const defaultContent = this.state.doc.type.createAndFill()?.toJSON()
const content = this.getJSON()

Expand All @@ -398,14 +406,14 @@ export class Editor extends EventEmitter {
/**
* Get the number of characters for the current document.
*/
public getCharacterCount() {
public getCharacterCount(): number {
return this.state.doc.content.size - 2
}

/**
* Destroy the editor.
*/
public destroy() {
public destroy(): void {
this.emit('destroy')

if (this.view) {
Expand All @@ -419,7 +427,7 @@ export class Editor extends EventEmitter {
/**
* Check if the editor is already destroyed.
*/
private get isDestroyed() {
private get isDestroyed(): boolean {
// @ts-ignore
return !this.view?.docView
}
Expand Down
8 changes: 4 additions & 4 deletions packages/core/src/EventEmitter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ export default class EventEmitter {

private callbacks: { [key: string]: Function[] } = {}

public on(event: string, fn: Function) {
public on(event: string, fn: Function): this {
if (!this.callbacks[event]) {
this.callbacks[event] = []
}
Expand All @@ -12,7 +12,7 @@ export default class EventEmitter {
return this
}

protected emit(event: string, ...args: any) {
protected emit(event: string, ...args: any): this {
const callbacks = this.callbacks[event]

if (callbacks) {
Expand All @@ -22,7 +22,7 @@ export default class EventEmitter {
return this
}

public off(event: string, fn?: Function) {
public off(event: string, fn?: Function): this {
const callbacks = this.callbacks[event]

if (callbacks) {
Expand All @@ -36,7 +36,7 @@ export default class EventEmitter {
return this
}

protected removeAllListeners() {
protected removeAllListeners(): void {
this.callbacks = {}
}
}
Loading

0 comments on commit cde0d86

Please sign in to comment.