@tiptap/extension-unique-id 2.0.0-beta.4 → 2.22.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +14 -0
- package/dist/helpers/findDuplicates.d.ts +5 -0
- package/dist/helpers/findDuplicates.d.ts.map +1 -0
- package/dist/helpers/removeDuplicates.d.ts +9 -0
- package/dist/helpers/removeDuplicates.d.ts.map +1 -0
- package/dist/{tiptap-extension-unique-id.cjs.js → index.cjs} +253 -282
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.ts +4 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/{tiptap-extension-unique-id.esm.js → index.js} +253 -282
- package/dist/index.js.map +1 -0
- package/dist/{tiptap-extension-unique-id.umd.js → index.umd.js} +255 -283
- package/dist/index.umd.js.map +1 -0
- package/dist/{tiptap-pro/packages/extension-unique-id/src/unique-id.d.ts → unique-id.d.ts} +10 -9
- package/dist/unique-id.d.ts.map +1 -0
- package/package.json +31 -13
- package/src/helpers/findDuplicates.ts +2 -2
- package/src/helpers/removeDuplicates.ts +1 -1
- package/src/index.ts +2 -2
- package/src/unique-id.ts +97 -33
- package/dist/tiptap-extension-unique-id.cjs.js.map +0 -1
- package/dist/tiptap-extension-unique-id.esm.js.map +0 -1
- package/dist/tiptap-extension-unique-id.umd.js.map +0 -1
- package/dist/tiptap-pro/packages/extension-unique-id/src/helpers/combineTransactionSteps.d.ts +0 -7
- package/dist/tiptap-pro/packages/extension-unique-id/src/helpers/findDuplicates.d.ts +0 -4
- package/dist/tiptap-pro/packages/extension-unique-id/src/helpers/getChangedRanges.d.ts +0 -12
- package/dist/tiptap-pro/packages/extension-unique-id/src/helpers/removeDuplicates.d.ts +0 -8
- package/dist/tiptap-pro/packages/extension-unique-id/src/index.d.ts +0 -3
- package/src/helpers/arrayDifference.ts +0 -35
- package/src/helpers/combineTransactionSteps.ts +0 -18
- package/src/helpers/getChangedRanges.ts +0 -78
|
@@ -1,78 +0,0 @@
|
|
|
1
|
-
import { Transform, Step } from 'prosemirror-transform'
|
|
2
|
-
import removeDuplicates from './removeDuplicates'
|
|
3
|
-
|
|
4
|
-
export type ChangedRange = {
|
|
5
|
-
oldStart: number,
|
|
6
|
-
oldEnd: number,
|
|
7
|
-
newStart: number,
|
|
8
|
-
newEnd: number,
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
/**
|
|
12
|
-
* Removes duplicated ranges and ranges that are
|
|
13
|
-
* fully captured by other ranges.
|
|
14
|
-
*/
|
|
15
|
-
function simplifyChangedRanges(changes: ChangedRange[]): ChangedRange[] {
|
|
16
|
-
const uniqueChanges = removeDuplicates(changes)
|
|
17
|
-
|
|
18
|
-
return uniqueChanges.length === 1
|
|
19
|
-
? uniqueChanges
|
|
20
|
-
: uniqueChanges.filter((change, index) => {
|
|
21
|
-
const rest = uniqueChanges.filter((_, i) => i !== index)
|
|
22
|
-
|
|
23
|
-
return !rest.some(otherChange => {
|
|
24
|
-
return change.oldStart >= otherChange.oldStart
|
|
25
|
-
&& change.oldEnd <= otherChange.oldEnd
|
|
26
|
-
&& change.newStart >= otherChange.newStart
|
|
27
|
-
&& change.newEnd <= otherChange.newEnd
|
|
28
|
-
})
|
|
29
|
-
})
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
/**
|
|
33
|
-
* Returns a list of changed ranges
|
|
34
|
-
* based on the first and last state of all steps.
|
|
35
|
-
*/
|
|
36
|
-
export default function getChangedRanges(transform: Transform): ChangedRange[] {
|
|
37
|
-
const { mapping, steps } = transform
|
|
38
|
-
const changes: ChangedRange[] = []
|
|
39
|
-
|
|
40
|
-
mapping.maps.forEach((stepMap, index) => {
|
|
41
|
-
// This accounts for step changes where no range was actually altered
|
|
42
|
-
// e.g. when setting a mark, node attribute, etc.
|
|
43
|
-
// @ts-ignore
|
|
44
|
-
if (!stepMap.ranges.length) {
|
|
45
|
-
const step = steps[index] as Step & {
|
|
46
|
-
from?: number,
|
|
47
|
-
to?: number,
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
if (step.from === undefined || step.to === undefined) {
|
|
51
|
-
return
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
changes.push({
|
|
55
|
-
oldStart: step.from,
|
|
56
|
-
oldEnd: step.to,
|
|
57
|
-
newStart: step.from,
|
|
58
|
-
newEnd: step.to,
|
|
59
|
-
})
|
|
60
|
-
} else {
|
|
61
|
-
stepMap.forEach((from, to) => {
|
|
62
|
-
const newStart = mapping.slice(index).map(from, -1)
|
|
63
|
-
const newEnd = mapping.slice(index).map(to)
|
|
64
|
-
const oldStart = mapping.invert().map(newStart, -1)
|
|
65
|
-
const oldEnd = mapping.invert().map(newEnd)
|
|
66
|
-
|
|
67
|
-
changes.push({
|
|
68
|
-
oldStart,
|
|
69
|
-
oldEnd,
|
|
70
|
-
newStart,
|
|
71
|
-
newEnd,
|
|
72
|
-
})
|
|
73
|
-
})
|
|
74
|
-
}
|
|
75
|
-
})
|
|
76
|
-
|
|
77
|
-
return simplifyChangedRanges(changes)
|
|
78
|
-
}
|