tiptap-extension-auto-joiner
Advanced tools
Comparing version 0.1.2 to 0.1.3
@@ -1380,21 +1380,23 @@ import { Extension, getNodeType } from '@tiptap/core'; | ||
// Find all ranges where we might want to join. | ||
var ranges = []; | ||
for (var i = 0; i < tr.mapping.maps.length; i++) { | ||
var map = tr.mapping.maps[i]; | ||
for (var j = 0; j < ranges.length; j++) | ||
let ranges = []; | ||
for (let i = 0; i < tr.mapping.maps.length; i++) { | ||
let map = tr.mapping.maps[i]; | ||
if (!map) | ||
continue; | ||
for (let j = 0; j < ranges.length; j++) | ||
ranges[j] = map.map(ranges[j]); | ||
map.forEach(function (_s, _e, from, to) { return ranges.push(from, to); }); | ||
map.forEach((_s, _e, from, to) => ranges.push(from, to)); | ||
} | ||
// Figure out which joinable points exist inside those ranges, | ||
// by checking all node boundaries in their parent nodes. | ||
var joinable = []; | ||
for (var i = 0; i < ranges.length; i += 2) { | ||
var from = ranges[i], to = ranges[i + 1]; | ||
var $from = tr.doc.resolve(from), depth = $from.sharedDepth(to), parent_1 = $from.node(depth); | ||
for (var index = $from.indexAfter(depth), pos = $from.after(depth + 1); pos <= to; ++index) { | ||
var after = parent_1.maybeChild(index); | ||
let joinable = []; | ||
for (let i = 0; i < ranges.length; i += 2) { | ||
let from = ranges[i], to = ranges[i + 1]; | ||
let $from = tr.doc.resolve(from), depth = $from.sharedDepth(to), parent = $from.node(depth); | ||
for (let index = $from.indexAfter(depth), pos = $from.after(depth + 1); pos <= to; ++index) { | ||
let after = parent.maybeChild(index); | ||
if (!after) | ||
break; | ||
if (index && joinable.indexOf(pos) == -1) { | ||
var before = parent_1.child(index - 1); | ||
let before = parent.child(index - 1); | ||
if (before.type == after.type && nodeTypes.includes(before.type)) | ||
@@ -1406,6 +1408,6 @@ joinable.push(pos); | ||
} | ||
var joined = false; | ||
let joined = false; | ||
// Join the joinable points | ||
joinable.sort(function (a, b) { return a - b; }); | ||
for (var i = joinable.length - 1; i >= 0; i--) { | ||
joinable.sort((a, b) => a - b); | ||
for (let i = joinable.length - 1; i >= 0; i--) { | ||
if (canJoin(tr.doc, joinable[i])) { | ||
@@ -1418,5 +1420,5 @@ newTr.join(joinable[i]); | ||
} | ||
var AutoJoiner = Extension.create({ | ||
const AutoJoiner = Extension.create({ | ||
name: "autoJoiner", | ||
addOptions: function () { | ||
addOptions() { | ||
return { | ||
@@ -1426,11 +1428,10 @@ elementsToJoin: [], | ||
}, | ||
addProseMirrorPlugins: function () { | ||
var _this = this; | ||
var plugin = new PluginKey(this.name); | ||
var joinableNodes = [ | ||
addProseMirrorPlugins() { | ||
const plugin = new PluginKey(this.name); | ||
const joinableNodes = [ | ||
this.editor.schema.nodes.bulletList, | ||
this.editor.schema.nodes.orderedList, | ||
]; | ||
this.options.elementsToJoin.forEach(function (element) { | ||
var nodeTyp = getNodeType(element, _this.editor.schema); | ||
this.options.elementsToJoin.forEach((element) => { | ||
const nodeTyp = getNodeType(element, this.editor.schema); | ||
joinableNodes.push(nodeTyp); | ||
@@ -1441,9 +1442,8 @@ }); | ||
key: plugin, | ||
appendTransaction: function (transactions, _, newState) { | ||
appendTransaction(transactions, _, newState) { | ||
// Create a new transaction. | ||
var newTr = newState.tr; | ||
var joined = false; | ||
for (var _i = 0, transactions_1 = transactions; _i < transactions_1.length; _i++) { | ||
var transaction = transactions_1[_i]; | ||
var anotherJoin = autoJoin(transaction, newTr, joinableNodes); | ||
let newTr = newState.tr; | ||
let joined = false; | ||
for (const transaction of transactions) { | ||
const anotherJoin = autoJoin(transaction, newTr, joinableNodes); | ||
joined = anotherJoin || joined; | ||
@@ -1450,0 +1450,0 @@ } |
@@ -1383,21 +1383,23 @@ (function (global, factory) { | ||
// Find all ranges where we might want to join. | ||
var ranges = []; | ||
for (var i = 0; i < tr.mapping.maps.length; i++) { | ||
var map = tr.mapping.maps[i]; | ||
for (var j = 0; j < ranges.length; j++) | ||
let ranges = []; | ||
for (let i = 0; i < tr.mapping.maps.length; i++) { | ||
let map = tr.mapping.maps[i]; | ||
if (!map) | ||
continue; | ||
for (let j = 0; j < ranges.length; j++) | ||
ranges[j] = map.map(ranges[j]); | ||
map.forEach(function (_s, _e, from, to) { return ranges.push(from, to); }); | ||
map.forEach((_s, _e, from, to) => ranges.push(from, to)); | ||
} | ||
// Figure out which joinable points exist inside those ranges, | ||
// by checking all node boundaries in their parent nodes. | ||
var joinable = []; | ||
for (var i = 0; i < ranges.length; i += 2) { | ||
var from = ranges[i], to = ranges[i + 1]; | ||
var $from = tr.doc.resolve(from), depth = $from.sharedDepth(to), parent_1 = $from.node(depth); | ||
for (var index = $from.indexAfter(depth), pos = $from.after(depth + 1); pos <= to; ++index) { | ||
var after = parent_1.maybeChild(index); | ||
let joinable = []; | ||
for (let i = 0; i < ranges.length; i += 2) { | ||
let from = ranges[i], to = ranges[i + 1]; | ||
let $from = tr.doc.resolve(from), depth = $from.sharedDepth(to), parent = $from.node(depth); | ||
for (let index = $from.indexAfter(depth), pos = $from.after(depth + 1); pos <= to; ++index) { | ||
let after = parent.maybeChild(index); | ||
if (!after) | ||
break; | ||
if (index && joinable.indexOf(pos) == -1) { | ||
var before = parent_1.child(index - 1); | ||
let before = parent.child(index - 1); | ||
if (before.type == after.type && nodeTypes.includes(before.type)) | ||
@@ -1409,6 +1411,6 @@ joinable.push(pos); | ||
} | ||
var joined = false; | ||
let joined = false; | ||
// Join the joinable points | ||
joinable.sort(function (a, b) { return a - b; }); | ||
for (var i = joinable.length - 1; i >= 0; i--) { | ||
joinable.sort((a, b) => a - b); | ||
for (let i = joinable.length - 1; i >= 0; i--) { | ||
if (canJoin(tr.doc, joinable[i])) { | ||
@@ -1421,5 +1423,5 @@ newTr.join(joinable[i]); | ||
} | ||
var AutoJoiner = core.Extension.create({ | ||
const AutoJoiner = core.Extension.create({ | ||
name: "autoJoiner", | ||
addOptions: function () { | ||
addOptions() { | ||
return { | ||
@@ -1429,11 +1431,10 @@ elementsToJoin: [], | ||
}, | ||
addProseMirrorPlugins: function () { | ||
var _this = this; | ||
var plugin = new state.PluginKey(this.name); | ||
var joinableNodes = [ | ||
addProseMirrorPlugins() { | ||
const plugin = new state.PluginKey(this.name); | ||
const joinableNodes = [ | ||
this.editor.schema.nodes.bulletList, | ||
this.editor.schema.nodes.orderedList, | ||
]; | ||
this.options.elementsToJoin.forEach(function (element) { | ||
var nodeTyp = core.getNodeType(element, _this.editor.schema); | ||
this.options.elementsToJoin.forEach((element) => { | ||
const nodeTyp = core.getNodeType(element, this.editor.schema); | ||
joinableNodes.push(nodeTyp); | ||
@@ -1444,9 +1445,8 @@ }); | ||
key: plugin, | ||
appendTransaction: function (transactions, _, newState) { | ||
appendTransaction(transactions, _, newState) { | ||
// Create a new transaction. | ||
var newTr = newState.tr; | ||
var joined = false; | ||
for (var _i = 0, transactions_1 = transactions; _i < transactions_1.length; _i++) { | ||
var transaction = transactions_1[_i]; | ||
var anotherJoin = autoJoin(transaction, newTr, joinableNodes); | ||
let newTr = newState.tr; | ||
let joined = false; | ||
for (const transaction of transactions) { | ||
const anotherJoin = autoJoin(transaction, newTr, joinableNodes); | ||
joined = anotherJoin || joined; | ||
@@ -1453,0 +1453,0 @@ } |
{ | ||
"name": "tiptap-extension-auto-joiner", | ||
"description": "joins nearby nodes of the same type like list items", | ||
"version": "0.1.2", | ||
"version": "0.1.3", | ||
"author": { | ||
@@ -20,4 +20,4 @@ "name": "Niclas Gregor", | ||
"require": "./dist/index.cjs", | ||
"types": "./dist/index.d.ts" | ||
} | ||
"types": "./dist/src/index.d.ts" | ||
} | ||
}, | ||
@@ -27,3 +27,4 @@ "main": "dist/index.cjs", | ||
"umd": "dist/index.umd.js", | ||
"types": "dist/index.d.ts", | ||
"types": "dist/src/index.d.ts", | ||
"type": "module", | ||
"files": [ | ||
@@ -30,0 +31,0 @@ "dist" |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
934605
11
4353
Yes