diff --git a/package-lock.json b/package-lock.json index 15a77109..57d88005 100644 --- a/package-lock.json +++ b/package-lock.json @@ -649,7 +649,6 @@ "integrity": "sha512-NZyJarBfL7nWwIq+FDL6Zp/yHEhePMNnnJ0y3qfieCrmNvYct8uvtiV41UvlSe6apAfk0fY1FbWx+NwfmpvtTg==", "dev": true, "license": "MIT", - "peer": true, "bin": { "acorn": "bin/acorn" }, @@ -1547,7 +1546,6 @@ "deprecated": "This version is no longer supported. Please see https://eslint.org/version-support for other options.", "dev": true, "license": "MIT", - "peer": true, "dependencies": { "@eslint-community/eslint-utils": "^4.2.0", "@eslint-community/regexpp": "^4.6.1", @@ -1755,7 +1753,6 @@ "integrity": "sha512-whOE1HFo/qJDyX4SnXzP4N6zOWn79WhnCUY/iDR0mPfQZO8wcYE4JClzI2oZrhBnnMUCBCHZhO6VQyoBU95mZA==", "dev": true, "license": "MIT", - "peer": true, "dependencies": { "@rtsao/scc": "^1.1.0", "array-includes": "^3.1.9", @@ -1826,7 +1823,6 @@ "integrity": "sha512-jDex9s7D/Qial8AGVIHq4W7NswpUD5DPDL2RH8Lzd9EloWUuvUkHfv4FRLMipH5q2UtyurorBkPeNi1wVWNh3Q==", "dev": true, "license": "MIT", - "peer": true, "dependencies": { "builtins": "^5.0.1", "eslint-plugin-es": "^4.1.0", @@ -1889,7 +1885,6 @@ "integrity": "sha512-57Zzfw8G6+Gq7axm2Pdo3gW/Rx3h9Yywgn61uE/3elTCOePEHVrn2i5CdfBwA1BLK0Q0WqctICIUSqXZW/VprQ==", "dev": true, "license": "ISC", - "peer": true, "engines": { "node": "^12.22.0 || ^14.17.0 || >=16.0.0" }, @@ -1906,7 +1901,6 @@ "integrity": "sha512-Qteup0SqU15kdocexFNAJMvCJEfa2xUKNV4CC1xsVMrIIqEy3SQ/rqyxCWNzfrd3/ldy6HMlD2e0JDVpDg2qIA==", "dev": true, "license": "MIT", - "peer": true, "dependencies": { "array-includes": "^3.1.8", "array.prototype.findlast": "^1.2.5", diff --git a/src/index.js b/src/index.js index 94b3d754..7fe08088 100644 --- a/src/index.js +++ b/src/index.js @@ -123,7 +123,8 @@ export { readIdMap, readIdSet, decodeIdMap, - diffDocsToDelta + diffDocsToDelta, + getPathTo } from './internals.js' const glo = /** @type {any} */ (typeof globalThis !== 'undefined' diff --git a/src/utils/YEvent.js b/src/utils/YEvent.js index 3f4bbacf..42930471 100644 --- a/src/utils/YEvent.js +++ b/src/utils/YEvent.js @@ -2,7 +2,10 @@ import { diffIdSet, mergeIdSets, noAttributionsManager, - AbstractAttributionManager, Item, AbstractType, Transaction, AbstractStruct // eslint-disable-line + Doc, AbstractAttributionManager, Item, AbstractType, Transaction, AbstractStruct, // eslint-disable-line + createAbsolutePositionFromRelativePosition, + createRelativePosition, + AbsolutePosition } from '../internals.js' import * as map from 'lib0/map' @@ -187,28 +190,24 @@ export class YEvent { * * @param {_YType} parent * @param {_YType} child target + * @param {AbstractAttributionManager} am * @return {Array} Path to the target * * @private * @function */ -const getPathTo = (parent, child) => { +export const getPathTo = (parent, child, am = noAttributionsManager) => { const path = [] + const doc = /** @type {Doc} */ (parent.doc) while (child._item !== null && child !== parent) { if (child._item.parentSub !== null) { // parent is map-ish path.unshift(child._item.parentSub) } else { + const parent = /** @type {import('../utils/types.js').YType} */ (child._item.parent) // parent is array-ish - let i = 0 - let c = /** @type {import('../utils/types.js').YType} */ (child._item.parent)._start - while (c !== child._item && c !== null) { - if (!c.deleted && c.countable) { - i += c.length - } - c = c.right - } - path.unshift(i) + const apos = /** @type {AbsolutePosition} */ (createAbsolutePositionFromRelativePosition(createRelativePosition(parent, child._item.id), doc, false, am)) + path.unshift(apos.index) } child = /** @type {_YType} */ (child._item.parent) } diff --git a/test.html b/test.html index f19aa0da..81f76dda 100644 --- a/test.html +++ b/test.html @@ -2,14 +2,14 @@ - Testing yjs + Testing @y/y