Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@tiptap/core

Package Overview
Dependencies
Maintainers
2
Versions
331
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@tiptap/core - npm Package Compare versions

Comparing version 2.0.0-beta.50 to 2.0.0-beta.51

dist/packages/core/src/helpers/getSchemaByResolvedExtensions.d.ts

12

CHANGELOG.md

@@ -6,2 +6,14 @@ # Change Log

# [2.0.0-beta.51](https://github.com/ueberdosis/tiptap/compare/@tiptap/core@2.0.0-beta.50...@tiptap/core@2.0.0-beta.51) (2021-05-07)
### Bug Fixes
* add support for priority and nested extension for getSchema ([129ad83](https://github.com/ueberdosis/tiptap/commit/129ad83167900526d65c5c25da8249d0d65bcef7))
* remove editor from addExtensions context ([cbc0dd8](https://github.com/ueberdosis/tiptap/commit/cbc0dd8920ab7d36516387ceac59239f9162b4ec))
# [2.0.0-beta.50](https://github.com/ueberdosis/tiptap/compare/@tiptap/core@2.0.0-beta.49...@tiptap/core@2.0.0-beta.50) (2021-05-07)

@@ -8,0 +20,0 @@

1

dist/packages/core/src/Extension.d.ts

@@ -84,3 +84,2 @@ import { Plugin, Transaction } from 'prosemirror-state';

options: Options;
editor: Editor;
parent: ParentConfig<ExtensionConfig<Options>>['addExtensions'];

@@ -87,0 +86,0 @@ }) => Extensions;

@@ -11,4 +11,5 @@ import { Schema } from 'prosemirror-model';

constructor(extensions: Extensions, editor: Editor);
private flatten;
private sort;
static resolve(extensions: Extensions): Extensions;
static flatten(extensions: Extensions): Extensions;
static sort(extensions: Extensions): Extensions;
get commands(): RawCommands;

@@ -15,0 +16,0 @@ get plugins(): Plugin[];

@@ -89,3 +89,2 @@ import { DOMOutputSpec, MarkSpec, Mark as ProseMirrorMark, MarkType } from 'prosemirror-model';

options: Options;
editor: Editor;
parent: ParentConfig<MarkConfig<Options>>['addExtensions'];

@@ -92,0 +91,0 @@ }) => Extensions;

@@ -88,3 +88,2 @@ import { DOMOutputSpec, NodeSpec, Node as ProseMirrorNode, NodeType } from 'prosemirror-model';

options: Options;
editor: Editor;
parent: ParentConfig<NodeConfig<Options>>['addExtensions'];

@@ -91,0 +90,0 @@ }) => Extensions;

{
"name": "@tiptap/core",
"description": "headless rich text editor",
"version": "2.0.0-beta.50",
"version": "2.0.0-beta.51",
"homepage": "https://tiptap.dev",

@@ -43,3 +43,3 @@ "keywords": [

},
"gitHead": "243dc5e2167376ac0529dd5bd301de9bb659407a"
"gitHead": "bc24317f06642de638b3e790f970f6693410fca3"
}

@@ -102,3 +102,2 @@ import { Plugin, Transaction } from 'prosemirror-state'

options: Options,
editor: Editor,
parent: ParentConfig<ExtensionConfig<Options>>['addExtensions'],

@@ -105,0 +104,0 @@ }) => Extensions,

@@ -9,3 +9,3 @@ import { keymap } from 'prosemirror-keymap'

import getExtensionField from './helpers/getExtensionField'
import getSchema from './helpers/getSchema'
import getSchemaByResolvedExtensions from './helpers/getSchemaByResolvedExtensions'
import getSchemaTypeByName from './helpers/getSchemaTypeByName'

@@ -31,4 +31,4 @@ import getNodeType from './helpers/getNodeType'

this.editor = editor
this.extensions = this.sort(this.flatten(extensions))
this.schema = getSchema(this.extensions)
this.extensions = ExtensionManager.resolve(extensions)
this.schema = getSchemaByResolvedExtensions(this.extensions)

@@ -133,3 +133,7 @@ this.extensions.forEach(extension => {

private flatten(extensions: Extensions): Extensions {
static resolve(extensions: Extensions): Extensions {
return ExtensionManager.sort(ExtensionManager.flatten(extensions))
}
static flatten(extensions: Extensions): Extensions {
return extensions

@@ -140,3 +144,2 @@ .map(extension => {

options: extension.options,
editor: this.editor,
}

@@ -160,3 +163,3 @@

private sort(extensions: Extensions): Extensions {
static sort(extensions: Extensions): Extensions {
const defaultPriority = 100

@@ -163,0 +166,0 @@

@@ -1,138 +0,10 @@

import { NodeSpec, MarkSpec, Schema } from 'prosemirror-model'
import { AnyConfig, Extensions } from '../types'
import { NodeConfig, MarkConfig } from '..'
import splitExtensions from './splitExtensions'
import getAttributesFromExtensions from './getAttributesFromExtensions'
import getRenderedAttributes from './getRenderedAttributes'
import isEmptyObject from '../utilities/isEmptyObject'
import injectExtensionAttributesToParseRule from './injectExtensionAttributesToParseRule'
import callOrReturn from '../utilities/callOrReturn'
import getExtensionField from './getExtensionField'
import { Schema } from 'prosemirror-model'
import getSchemaByResolvedExtensions from './getSchemaByResolvedExtensions'
import ExtensionManager from '../ExtensionManager'
import { Extensions } from '../types'
function cleanUpSchemaItem<T>(data: T) {
return Object.fromEntries(Object.entries(data).filter(([key, value]) => {
if (key === 'attrs' && isEmptyObject(value)) {
return false
}
return value !== null && value !== undefined
})) as T
}
export default function getSchema(extensions: Extensions): Schema {
const allAttributes = getAttributesFromExtensions(extensions)
const { nodeExtensions, markExtensions } = splitExtensions(extensions)
const topNode = nodeExtensions.find(extension => getExtensionField(extension, 'topNode'))?.name
const resolvedExtensions = ExtensionManager.resolve(extensions)
const nodes = Object.fromEntries(nodeExtensions.map(extension => {
const extensionAttributes = allAttributes.filter(attribute => attribute.type === extension.name)
const context = {
name: extension.name,
options: extension.options,
}
const extraNodeFields = extensions.reduce((fields, e) => {
const extendNodeSchema = getExtensionField<AnyConfig['extendNodeSchema']>(
e,
'extendNodeSchema',
context,
)
return {
...fields,
...(extendNodeSchema ? extendNodeSchema(extension) : {}),
}
}, {})
const schema: NodeSpec = cleanUpSchemaItem({
...extraNodeFields,
content: callOrReturn(getExtensionField<NodeConfig['content']>(extension, 'content', context)),
marks: callOrReturn(getExtensionField<NodeConfig['marks']>(extension, 'marks', context)),
group: callOrReturn(getExtensionField<NodeConfig['group']>(extension, 'group', context)),
inline: callOrReturn(getExtensionField<NodeConfig['inline']>(extension, 'inline', context)),
atom: callOrReturn(getExtensionField<NodeConfig['atom']>(extension, 'atom', context)),
selectable: callOrReturn(getExtensionField<NodeConfig['selectable']>(extension, 'selectable', context)),
draggable: callOrReturn(getExtensionField<NodeConfig['draggable']>(extension, 'draggable', context)),
code: callOrReturn(getExtensionField<NodeConfig['code']>(extension, 'code', context)),
defining: callOrReturn(getExtensionField<NodeConfig['defining']>(extension, 'defining', context)),
isolating: callOrReturn(getExtensionField<NodeConfig['isolating']>(extension, 'isolating', context)),
attrs: Object.fromEntries(extensionAttributes.map(extensionAttribute => {
return [extensionAttribute.name, { default: extensionAttribute?.attribute?.default }]
})),
})
const parseHTML = callOrReturn(getExtensionField<NodeConfig['parseHTML']>(extension, 'parseHTML', context))
if (parseHTML) {
schema.parseDOM = parseHTML
.map(parseRule => injectExtensionAttributesToParseRule(parseRule, extensionAttributes))
}
const renderHTML = getExtensionField<NodeConfig['renderHTML']>(extension, 'renderHTML', context)
if (renderHTML) {
schema.toDOM = node => renderHTML({
node,
HTMLAttributes: getRenderedAttributes(node, extensionAttributes),
})
}
return [extension.name, schema]
}))
const marks = Object.fromEntries(markExtensions.map(extension => {
const extensionAttributes = allAttributes.filter(attribute => attribute.type === extension.name)
const context = {
name: extension.name,
options: extension.options,
}
const extraMarkFields = extensions.reduce((fields, e) => {
const extendMarkSchema = getExtensionField<AnyConfig['extendMarkSchema']>(
e,
'extendMarkSchema',
context,
)
return {
...fields,
...(extendMarkSchema ? extendMarkSchema(extension) : {}),
}
}, {})
const schema: MarkSpec = cleanUpSchemaItem({
...extraMarkFields,
inclusive: callOrReturn(getExtensionField<NodeConfig['inclusive']>(extension, 'inclusive', context)),
excludes: callOrReturn(getExtensionField<NodeConfig['excludes']>(extension, 'excludes', context)),
group: callOrReturn(getExtensionField<NodeConfig['group']>(extension, 'group', context)),
spanning: callOrReturn(getExtensionField<NodeConfig['spanning']>(extension, 'spanning', context)),
attrs: Object.fromEntries(extensionAttributes.map(extensionAttribute => {
return [extensionAttribute.name, { default: extensionAttribute?.attribute?.default }]
})),
})
const parseHTML = callOrReturn(getExtensionField<MarkConfig['parseHTML']>(extension, 'parseHTML', context))
if (parseHTML) {
schema.parseDOM = parseHTML
.map(parseRule => injectExtensionAttributesToParseRule(parseRule, extensionAttributes))
}
const renderHTML = getExtensionField<MarkConfig['renderHTML']>(extension, 'renderHTML', context)
if (renderHTML) {
schema.toDOM = mark => renderHTML({
mark,
HTMLAttributes: getRenderedAttributes(mark, extensionAttributes),
})
}
return [extension.name, schema]
}))
return new Schema({
topNode,
nodes,
marks,
})
return getSchemaByResolvedExtensions(resolvedExtensions)
}

@@ -113,3 +113,2 @@ import {

options: Options,
editor: Editor,
parent: ParentConfig<MarkConfig<Options>>['addExtensions'],

@@ -116,0 +115,0 @@ }) => Extensions,

@@ -113,3 +113,2 @@ import {

options: Options,
editor: Editor,
parent: ParentConfig<NodeConfig<Options>>['addExtensions'],

@@ -116,0 +115,0 @@ }) => Extensions,

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc