@automerge/automerge
Advanced tools
Comparing version 2.1.0-alpha.5 to 2.1.0-alpha.6
@@ -28,6 +28,6 @@ "use strict"; | ||
case "map": | ||
result[fullVal[1]] = (0, proxies_1.mapProxy)(context, fullVal[1], textV2, [prop], true); | ||
result[fullVal[1]] = (0, proxies_1.mapProxy)(context, fullVal[1], textV2, [prop]); | ||
break; | ||
case "list": | ||
result[fullVal[1]] = (0, proxies_1.listProxy)(context, fullVal[1], textV2, [prop], true); | ||
result[fullVal[1]] = (0, proxies_1.listProxy)(context, fullVal[1], textV2, [prop]); | ||
break; | ||
@@ -34,0 +34,0 @@ case "text": |
@@ -21,4 +21,4 @@ "use strict"; | ||
function valueAt(target, prop) { | ||
const { context, objectId, path, readonly, heads, textV2 } = target; | ||
const value = context.getWithType(objectId, prop, heads); | ||
const { context, objectId, path, textV2 } = target; | ||
const value = context.getWithType(objectId, prop); | ||
if (value === null) { | ||
@@ -33,11 +33,14 @@ return; | ||
case "map": | ||
return mapProxy(context, val, textV2, [...path, prop], readonly, heads); | ||
return mapProxy(context, val, textV2, [...path, prop]); | ||
case "list": | ||
return listProxy(context, val, textV2, [...path, prop], readonly, heads); | ||
return listProxy(context, val, textV2, [...path, prop]); | ||
case "text": | ||
if (textV2) { | ||
return context.text(val, heads); | ||
return context.text(val); | ||
} | ||
else { | ||
return textProxy(context, val, [...path, prop], readonly, heads); | ||
return textProxy(context, val, [ | ||
...path, | ||
prop, | ||
]); | ||
} | ||
@@ -61,9 +64,4 @@ case "str": | ||
case "counter": { | ||
if (readonly) { | ||
return new counter_1.Counter(val); | ||
} | ||
else { | ||
const counter = (0, counter_1.getWriteableCounter)(val, context, path, objectId, prop); | ||
return counter; | ||
} | ||
const counter = (0, counter_1.getWriteableCounter)(val, context, path, objectId, prop); | ||
return counter; | ||
} | ||
@@ -110,3 +108,3 @@ default: | ||
} | ||
else if (value[constants_1.OBJECT_ID]) { | ||
else if (isSameDocument(value, context)) { | ||
throw new RangeError("Cannot create a reference to an existing document object"); | ||
@@ -137,2 +135,12 @@ } | ||
} | ||
function isSameDocument(val, context) { | ||
var _b, _c; | ||
// this depends on __wbg_ptr being the wasm pointer | ||
// a new version of wasm-bindgen will break this | ||
// but the tests should expose the break | ||
if (val && ((_c = (_b = val[constants_1.STATE]) === null || _b === void 0 ? void 0 : _b.handle) === null || _c === void 0 ? void 0 : _c.__wbg_ptr) === context.__wbg_ptr) { | ||
return true; | ||
} | ||
return false; | ||
} | ||
const MapHandler = { | ||
@@ -158,5 +166,5 @@ get(target, key) { | ||
set(target, key, val) { | ||
const { context, objectId, path, readonly, frozen, textV2 } = target; | ||
const { context, objectId, path, textV2 } = target; | ||
target.cache = {}; // reset cache on set | ||
if (val && val[constants_1.OBJECT_ID]) { | ||
if (isSameDocument(val, context)) { | ||
throw new RangeError("Cannot create a reference to an existing document object"); | ||
@@ -172,12 +180,6 @@ } | ||
const [value, datatype] = import_value(val, textV2); | ||
if (frozen) { | ||
throw new RangeError("Attempting to use an outdated Automerge document"); | ||
} | ||
if (readonly) { | ||
throw new RangeError(`Object property "${key}" cannot be modified`); | ||
} | ||
switch (datatype) { | ||
case "list": { | ||
const list = context.putObject(objectId, key, []); | ||
const proxyList = listProxy(context, list, textV2, [...path, key], readonly); | ||
const proxyList = listProxy(context, list, textV2, [...path, key]); | ||
for (let i = 0; i < value.length; i++) { | ||
@@ -196,3 +198,3 @@ proxyList[i] = value[i]; | ||
const text = context.putObject(objectId, key, ""); | ||
const proxyText = textProxy(context, text, [...path, key], readonly); | ||
const proxyText = textProxy(context, text, [...path, key]); | ||
for (let i = 0; i < value.length; i++) { | ||
@@ -206,3 +208,3 @@ proxyText[i] = value.get(i); | ||
const map = context.putObject(objectId, key, {}); | ||
const proxyMap = mapProxy(context, map, textV2, [...path, key], readonly); | ||
const proxyMap = mapProxy(context, map, textV2, [...path, key]); | ||
for (const key in value) { | ||
@@ -219,7 +221,4 @@ proxyMap[key] = value[key]; | ||
deleteProperty(target, key) { | ||
const { context, objectId, readonly } = target; | ||
const { context, objectId } = target; | ||
target.cache = {}; // reset cache on delete | ||
if (readonly) { | ||
throw new RangeError(`Object property "${key}" cannot be modified`); | ||
} | ||
context.delete(objectId, key); | ||
@@ -244,5 +243,5 @@ return true; | ||
ownKeys(target) { | ||
const { context, objectId, heads } = target; | ||
const { context, objectId } = target; | ||
// FIXME - this is a tmp workaround until fix the dupe key bug in keys() | ||
const keys = context.keys(objectId, heads); | ||
const keys = context.keys(objectId); | ||
return [...new Set(keys)]; | ||
@@ -253,3 +252,3 @@ }, | ||
get(target, index) { | ||
const { context, objectId, heads } = target; | ||
const { context, objectId } = target; | ||
index = parseListIndex(index); | ||
@@ -273,3 +272,3 @@ if (index === Symbol.hasInstance) { | ||
if (index === "length") | ||
return context.length(objectId, heads); | ||
return context.length(objectId); | ||
if (typeof index === "number") { | ||
@@ -283,5 +282,5 @@ return valueAt(target, index); | ||
set(target, index, val) { | ||
const { context, objectId, path, readonly, frozen, textV2 } = target; | ||
const { context, objectId, path, textV2 } = target; | ||
index = parseListIndex(index); | ||
if (val && val[constants_1.OBJECT_ID]) { | ||
if (isSameDocument(val, context)) { | ||
throw new RangeError("Cannot create a reference to an existing document object"); | ||
@@ -297,8 +296,2 @@ } | ||
const [value, datatype] = import_value(val, textV2); | ||
if (frozen) { | ||
throw new RangeError("Attempting to use an outdated Automerge document"); | ||
} | ||
if (readonly) { | ||
throw new RangeError(`Object property "${index}" cannot be modified`); | ||
} | ||
switch (datatype) { | ||
@@ -313,3 +306,3 @@ case "list": { | ||
} | ||
const proxyList = listProxy(context, list, textV2, [...path, index], readonly); | ||
const proxyList = listProxy(context, list, textV2, [...path, index]); | ||
proxyList.splice(0, 0, ...value); | ||
@@ -337,3 +330,3 @@ break; | ||
} | ||
const proxyText = textProxy(context, text, [...path, index], readonly); | ||
const proxyText = textProxy(context, text, [...path, index]); | ||
proxyText.splice(0, 0, ...value); | ||
@@ -351,3 +344,3 @@ } | ||
} | ||
const proxyMap = mapProxy(context, map, textV2, [...path, index], readonly); | ||
const proxyMap = mapProxy(context, map, textV2, [...path, index]); | ||
for (const key in value) { | ||
@@ -379,6 +372,6 @@ proxyMap[key] = value[key]; | ||
has(target, index) { | ||
const { context, objectId, heads } = target; | ||
const { context, objectId } = target; | ||
index = parseListIndex(index); | ||
if (typeof index === "number") { | ||
return index < context.length(objectId, heads); | ||
return index < context.length(objectId); | ||
} | ||
@@ -388,5 +381,5 @@ return index === "length"; | ||
getOwnPropertyDescriptor(target, index) { | ||
const { context, objectId, heads } = target; | ||
const { context, objectId } = target; | ||
if (index === "length") | ||
return { writable: true, value: context.length(objectId, heads) }; | ||
return { writable: true, value: context.length(objectId) }; | ||
if (index === constants_1.OBJECT_ID) | ||
@@ -405,4 +398,4 @@ return { configurable: false, enumerable: false, value: objectId }; | ||
// but not uncommenting it causes for (i in list) {} to not enumerate values properly | ||
//const {context, objectId, heads } = target | ||
//for (let i = 0; i < target.context.length(objectId, heads); i++) { keys.push(i.toString()) } | ||
//const {context, objectId } = target | ||
//for (let i = 0; i < target.context.length(objectId); i++) { keys.push(i.toString()) } | ||
keys.push("length"); | ||
@@ -414,3 +407,3 @@ return keys; | ||
get(target, index) { | ||
const { context, objectId, heads } = target; | ||
const { context, objectId } = target; | ||
index = parseListIndex(index); | ||
@@ -434,3 +427,3 @@ if (index === Symbol.hasInstance) { | ||
if (index === "length") | ||
return context.length(objectId, heads); | ||
return context.length(objectId); | ||
if (typeof index === "number") { | ||
@@ -447,3 +440,3 @@ return valueAt(target, index); | ||
}); | ||
function mapProxy(context, objectId, textV2, path, readonly, heads) { | ||
function mapProxy(context, objectId, textV2, path) { | ||
const target = { | ||
@@ -453,5 +446,2 @@ context, | ||
path: path || [], | ||
readonly: !!readonly, | ||
frozen: false, | ||
heads, | ||
cache: {}, | ||
@@ -467,3 +457,3 @@ textV2, | ||
exports.mapProxy = mapProxy; | ||
function listProxy(context, objectId, textV2, path, readonly, heads) { | ||
function listProxy(context, objectId, textV2, path) { | ||
const target = { | ||
@@ -473,5 +463,2 @@ context, | ||
path: path || [], | ||
readonly: !!readonly, | ||
frozen: false, | ||
heads, | ||
cache: {}, | ||
@@ -487,3 +474,3 @@ textV2, | ||
exports.listProxy = listProxy; | ||
function textProxy(context, objectId, path, readonly, heads) { | ||
function textProxy(context, objectId, path) { | ||
const target = { | ||
@@ -493,5 +480,2 @@ context, | ||
path: path || [], | ||
readonly: !!readonly, | ||
frozen: false, | ||
heads, | ||
cache: {}, | ||
@@ -505,9 +489,9 @@ textV2: false, | ||
exports.textProxy = textProxy; | ||
function rootProxy(context, textV2, readonly) { | ||
function rootProxy(context, textV2) { | ||
/* eslint-disable-next-line */ | ||
return mapProxy(context, "_root", textV2, [], !!readonly); | ||
return mapProxy(context, "_root", textV2, []); | ||
} | ||
exports.rootProxy = rootProxy; | ||
function listMethods(target) { | ||
const { context, objectId, path, readonly, frozen, heads, textV2 } = target; | ||
const { context, objectId, path, textV2 } = target; | ||
const methods = { | ||
@@ -540,3 +524,3 @@ deleteAt(index, numDelete) { | ||
const text = context.putObject(objectId, i, ""); | ||
const proxyText = textProxy(context, text, [...path, i], readonly); | ||
const proxyText = textProxy(context, text, [...path, i]); | ||
for (let i = 0; i < value.length; i++) { | ||
@@ -556,3 +540,3 @@ proxyText[i] = value.get(i); | ||
for (let i = start; i < length; i++) { | ||
const value = context.getWithType(objectId, i, heads); | ||
const value = context.getWithType(objectId, i); | ||
if (value && (value[1] === o[constants_1.OBJECT_ID] || value[1] === o)) { | ||
@@ -597,12 +581,6 @@ return i; | ||
for (const val of vals) { | ||
if (val && val[constants_1.OBJECT_ID]) { | ||
if (isSameDocument(val, context)) { | ||
throw new RangeError("Cannot create a reference to an existing document object"); | ||
} | ||
} | ||
if (frozen) { | ||
throw new RangeError("Attempting to use an outdated Automerge document"); | ||
} | ||
if (readonly) { | ||
throw new RangeError("Sequence object cannot be modified outside of a change block"); | ||
} | ||
const result = []; | ||
@@ -621,3 +599,3 @@ for (let i = 0; i < del; i++) { | ||
const list = context.insertObject(objectId, index, []); | ||
const proxyList = listProxy(context, list, textV2, [...path, index], readonly); | ||
const proxyList = listProxy(context, list, textV2, [...path, index]); | ||
proxyList.splice(0, 0, ...value); | ||
@@ -633,3 +611,3 @@ break; | ||
const text = context.insertObject(objectId, index, ""); | ||
const proxyText = textProxy(context, text, [...path, index], readonly); | ||
const proxyText = textProxy(context, text, [...path, index]); | ||
proxyText.splice(0, 0, ...value); | ||
@@ -641,3 +619,3 @@ } | ||
const map = context.insertObject(objectId, index, {}); | ||
const proxyMap = mapProxy(context, map, textV2, [...path, index], readonly); | ||
const proxyMap = mapProxy(context, map, textV2, [...path, index]); | ||
for (const key in value) { | ||
@@ -679,3 +657,3 @@ proxyMap[key] = value[key]; | ||
let i = 0; | ||
const len = context.length(objectId, heads); | ||
const len = context.length(objectId); | ||
const iterator = { | ||
@@ -806,3 +784,3 @@ next: () => { | ||
function textMethods(target) { | ||
const { context, objectId, heads } = target; | ||
const { context, objectId } = target; | ||
const methods = { | ||
@@ -816,3 +794,3 @@ set(index, value) { | ||
toString() { | ||
return context.text(objectId, heads).replace(//g, ""); | ||
return context.text(objectId).replace(//g, ""); | ||
}, | ||
@@ -819,0 +797,0 @@ toSpans() { |
@@ -193,3 +193,3 @@ "use strict"; | ||
function from(initialState, _opts) { | ||
return change(init(_opts), d => Object.assign(d, initialState)); | ||
return _change(init(_opts), "from", {}, d => Object.assign(d, initialState)); | ||
} | ||
@@ -245,3 +245,3 @@ exports.from = from; | ||
if (typeof options === "function") { | ||
return _change(doc, {}, options); | ||
return _change(doc, "change", {}, options); | ||
} | ||
@@ -252,3 +252,3 @@ else if (typeof callback === "function") { | ||
} | ||
return _change(doc, options, callback); | ||
return _change(doc, "change", options, callback); | ||
} | ||
@@ -262,3 +262,3 @@ else { | ||
if (typeof options === "function") { | ||
return _change(doc, {}, options, scope); | ||
return _change(doc, "changeAt", {}, options, scope); | ||
} | ||
@@ -269,3 +269,3 @@ else if (typeof callback === "function") { | ||
} | ||
return _change(doc, options, callback, scope); | ||
return _change(doc, "changeAt", options, callback, scope); | ||
} | ||
@@ -277,3 +277,3 @@ else { | ||
exports.changeAt = changeAt; | ||
function progressDocument(doc, heads, callback) { | ||
function progressDocument(doc, source, heads, callback) { | ||
if (heads == null) { | ||
@@ -289,4 +289,3 @@ return doc; | ||
if (patches.length > 0) { | ||
const before = view(doc, headsBefore || []); | ||
callback(patches, { before, after: value }); | ||
callback(patches, { before: doc, after: value, source }); | ||
} | ||
@@ -301,3 +300,3 @@ nextDoc = value; | ||
} | ||
function _change(doc, options, callback, scope) { | ||
function _change(doc, source, options, callback, scope) { | ||
if (typeof callback !== "function") { | ||
@@ -331,3 +330,3 @@ throw new RangeError("invalid change function"); | ||
state.handle.integrate(); | ||
return progressDocument(doc, heads, options.patchCallback || state.patchCallback); | ||
return progressDocument(doc, source, heads, options.patchCallback || state.patchCallback); | ||
} | ||
@@ -368,3 +367,3 @@ } | ||
state.handle.emptyChange(options.message, options.time); | ||
return progressDocument(doc, heads); | ||
return progressDocument(doc, "emptyChange", heads); | ||
} | ||
@@ -442,3 +441,3 @@ exports.emptyChange = emptyChange; | ||
state.handle.loadIncremental(data); | ||
return progressDocument(doc, heads, opts.patchCallback || state.patchCallback); | ||
return progressDocument(doc, "loadIncremental", heads, opts.patchCallback || state.patchCallback); | ||
} | ||
@@ -503,3 +502,3 @@ exports.loadIncremental = loadIncremental; | ||
localState.handle.applyChanges(changes); | ||
return progressDocument(local, heads, localState.patchCallback); | ||
return progressDocument(local, "merge", heads, localState.patchCallback); | ||
} | ||
@@ -655,3 +654,3 @@ exports.merge = merge; | ||
return [ | ||
progressDocument(doc, heads, opts.patchCallback || state.patchCallback), | ||
progressDocument(doc, "applyChanges", heads, opts.patchCallback || state.patchCallback), | ||
]; | ||
@@ -779,3 +778,3 @@ } | ||
return [ | ||
progressDocument(doc, heads, opts.patchCallback || state.patchCallback), | ||
progressDocument(doc, "receiveSyncMessage", heads, opts.patchCallback || state.patchCallback), | ||
outSyncState, | ||
@@ -782,0 +781,0 @@ null, |
@@ -40,3 +40,4 @@ "use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.getConflicts = exports.marks = exports.unmark = exports.mark = exports.getCursorPosition = exports.getCursor = exports.splice = exports.load = exports.from = exports.clone = exports.init = exports.getBackend = exports.RawString = exports.deleteAt = exports.insertAt = exports.diff = exports.getObjectId = exports.isAutomerge = exports.toJS = exports.dump = exports.getMissingDeps = exports.decodeSyncMessage = exports.encodeSyncMessage = exports.decodeChange = exports.encodeChange = exports.initSyncState = exports.receiveSyncMessage = exports.generateSyncMessage = exports.decodeSyncState = exports.encodeSyncState = exports.equals = exports.getHistory = exports.applyChanges = exports.getAllChanges = exports.getChanges = exports.getLastLocalChange = exports.getActorId = exports.merge = exports.save = exports.loadIncremental = exports.emptyChange = exports.changeAt = exports.change = exports.getHeads = exports.free = exports.view = exports.Float64 = exports.Uint = exports.Int = exports.Counter = void 0; | ||
exports.marks = exports.unmark = exports.mark = exports.getCursorPosition = exports.getCursor = exports.splice = exports.load = exports.from = exports.clone = exports.init = exports.getBackend = exports.RawString = exports.deleteAt = exports.insertAt = exports.diff = exports.getObjectId = exports.isAutomerge = exports.toJS = exports.dump = exports.getMissingDeps = exports.decodeSyncMessage = exports.encodeSyncMessage = exports.decodeChange = exports.encodeChange = exports.initSyncState = exports.receiveSyncMessage = exports.generateSyncMessage = exports.decodeSyncState = exports.encodeSyncState = exports.equals = exports.getHistory = exports.applyChanges = exports.getAllChanges = exports.getChanges = exports.getLastLocalChange = exports.getActorId = exports.merge = exports.save = exports.saveIncremental = exports.loadIncremental = exports.emptyChange = exports.changeAt = exports.change = exports.getHeads = exports.free = exports.view = exports.Float64 = exports.Uint = exports.Int = exports.Counter = void 0; | ||
exports.getConflicts = void 0; | ||
var unstable_types_1 = require("./unstable_types"); | ||
@@ -56,2 +57,3 @@ Object.defineProperty(exports, "Counter", { enumerable: true, get: function () { return unstable_types_1.Counter; } }); | ||
Object.defineProperty(exports, "loadIncremental", { enumerable: true, get: function () { return stable_1.loadIncremental; } }); | ||
Object.defineProperty(exports, "saveIncremental", { enumerable: true, get: function () { return stable_1.saveIncremental; } }); | ||
Object.defineProperty(exports, "save", { enumerable: true, get: function () { return stable_1.save; } }); | ||
@@ -194,2 +196,17 @@ Object.defineProperty(exports, "merge", { enumerable: true, get: function () { return stable_1.merge; } }); | ||
} | ||
/** | ||
* Modify a string | ||
* | ||
* @typeParam T - The type of the value contained in the document | ||
* @param doc - The document to modify | ||
* @param path - The path to the string to modify | ||
* @param index - The position (as a {@link Cursor} or index) to edit. | ||
* If a cursor is used then the edit happens such that the cursor will | ||
* now point to the end of the newText, so you can continue to reuse | ||
* the same cursor for multiple calls to splice. | ||
* @param del - The number of code units to delete, a positive number | ||
* deletes N characters after the cursor, a negative number deletes | ||
* N characters before the cursor. | ||
* @param newText - The string to insert (if any). | ||
*/ | ||
function splice(doc, path, index, del, newText) { | ||
@@ -216,2 +233,20 @@ if (!(0, internal_state_1._is_proxy)(doc)) { | ||
exports.splice = splice; | ||
/** | ||
* Returns a cursor for the given position in a string. | ||
* | ||
* @remarks | ||
* A cursor represents a relative position, "before character X", | ||
* rather than an absolute position. As the document is edited, the | ||
* cursor remains stable relative to its context, just as you'd expect | ||
* from a cursor in a concurrent text editor. | ||
* | ||
* The string representation is shareable, and so you can use this both | ||
* to edit the document yourself (using {@link splice}) or to share multiple | ||
* collaborator's current cursor positions over the network. | ||
* | ||
* @typeParam T - The type of the value contained in the document | ||
* @param doc - The document | ||
* @param path - The path to the string | ||
* @param index - The current index of the position of the cursor | ||
*/ | ||
function getCursor(doc, path, index) { | ||
@@ -233,2 +268,11 @@ const state = (0, internal_state_1._state)(doc, false); | ||
exports.getCursor = getCursor; | ||
/** | ||
* Returns the current index of the cursor. | ||
* | ||
* @typeParam T - The type of the value contained in the document | ||
* | ||
* @param doc - The document | ||
* @param path - The path to the string | ||
* @param index - The cursor | ||
*/ | ||
function getCursorPosition(doc, path, cursor) { | ||
@@ -288,3 +332,3 @@ const state = (0, internal_state_1._state)(doc, false); | ||
exports.unmark = unmark; | ||
function marks(doc, prop) { | ||
function marks(doc, path) { | ||
const state = (0, internal_state_1._state)(doc, false); | ||
@@ -295,3 +339,4 @@ const objectId = (0, internal_state_1._obj)(doc); | ||
} | ||
const obj = `${objectId}/${prop}`; | ||
path.unshift(objectId); | ||
const obj = path.join("/"); | ||
try { | ||
@@ -298,0 +343,0 @@ return state.handle.marks(obj); |
@@ -23,6 +23,6 @@ import { Counter } from "./types"; | ||
case "map": | ||
result[fullVal[1]] = mapProxy(context, fullVal[1], textV2, [prop], true); | ||
result[fullVal[1]] = mapProxy(context, fullVal[1], textV2, [prop]); | ||
break; | ||
case "list": | ||
result[fullVal[1]] = listProxy(context, fullVal[1], textV2, [prop], true); | ||
result[fullVal[1]] = listProxy(context, fullVal[1], textV2, [prop]); | ||
break; | ||
@@ -29,0 +29,0 @@ case "text": |
/* eslint-disable @typescript-eslint/no-explicit-any */ | ||
import { Text } from "./text"; | ||
import { Counter, getWriteableCounter } from "./counter"; | ||
import { getWriteableCounter } from "./counter"; | ||
import { STATE, TRACE, IS_PROXY, OBJECT_ID, CLEAR_CACHE, COUNTER, INT, UINT, F64, } from "./constants"; | ||
@@ -18,4 +18,4 @@ import { RawString } from "./raw_string"; | ||
function valueAt(target, prop) { | ||
const { context, objectId, path, readonly, heads, textV2 } = target; | ||
const value = context.getWithType(objectId, prop, heads); | ||
const { context, objectId, path, textV2 } = target; | ||
const value = context.getWithType(objectId, prop); | ||
if (value === null) { | ||
@@ -30,11 +30,14 @@ return; | ||
case "map": | ||
return mapProxy(context, val, textV2, [...path, prop], readonly, heads); | ||
return mapProxy(context, val, textV2, [...path, prop]); | ||
case "list": | ||
return listProxy(context, val, textV2, [...path, prop], readonly, heads); | ||
return listProxy(context, val, textV2, [...path, prop]); | ||
case "text": | ||
if (textV2) { | ||
return context.text(val, heads); | ||
return context.text(val); | ||
} | ||
else { | ||
return textProxy(context, val, [...path, prop], readonly, heads); | ||
return textProxy(context, val, [ | ||
...path, | ||
prop, | ||
]); | ||
} | ||
@@ -58,9 +61,4 @@ case "str": | ||
case "counter": { | ||
if (readonly) { | ||
return new Counter(val); | ||
} | ||
else { | ||
const counter = getWriteableCounter(val, context, path, objectId, prop); | ||
return counter; | ||
} | ||
const counter = getWriteableCounter(val, context, path, objectId, prop); | ||
return counter; | ||
} | ||
@@ -107,3 +105,3 @@ default: | ||
} | ||
else if (value[OBJECT_ID]) { | ||
else if (isSameDocument(value, context)) { | ||
throw new RangeError("Cannot create a reference to an existing document object"); | ||
@@ -134,2 +132,12 @@ } | ||
} | ||
function isSameDocument(val, context) { | ||
var _b, _c; | ||
// this depends on __wbg_ptr being the wasm pointer | ||
// a new version of wasm-bindgen will break this | ||
// but the tests should expose the break | ||
if (val && ((_c = (_b = val[STATE]) === null || _b === void 0 ? void 0 : _b.handle) === null || _c === void 0 ? void 0 : _c.__wbg_ptr) === context.__wbg_ptr) { | ||
return true; | ||
} | ||
return false; | ||
} | ||
const MapHandler = { | ||
@@ -155,5 +163,5 @@ get(target, key) { | ||
set(target, key, val) { | ||
const { context, objectId, path, readonly, frozen, textV2 } = target; | ||
const { context, objectId, path, textV2 } = target; | ||
target.cache = {}; // reset cache on set | ||
if (val && val[OBJECT_ID]) { | ||
if (isSameDocument(val, context)) { | ||
throw new RangeError("Cannot create a reference to an existing document object"); | ||
@@ -169,12 +177,6 @@ } | ||
const [value, datatype] = import_value(val, textV2); | ||
if (frozen) { | ||
throw new RangeError("Attempting to use an outdated Automerge document"); | ||
} | ||
if (readonly) { | ||
throw new RangeError(`Object property "${key}" cannot be modified`); | ||
} | ||
switch (datatype) { | ||
case "list": { | ||
const list = context.putObject(objectId, key, []); | ||
const proxyList = listProxy(context, list, textV2, [...path, key], readonly); | ||
const proxyList = listProxy(context, list, textV2, [...path, key]); | ||
for (let i = 0; i < value.length; i++) { | ||
@@ -193,3 +195,3 @@ proxyList[i] = value[i]; | ||
const text = context.putObject(objectId, key, ""); | ||
const proxyText = textProxy(context, text, [...path, key], readonly); | ||
const proxyText = textProxy(context, text, [...path, key]); | ||
for (let i = 0; i < value.length; i++) { | ||
@@ -203,3 +205,3 @@ proxyText[i] = value.get(i); | ||
const map = context.putObject(objectId, key, {}); | ||
const proxyMap = mapProxy(context, map, textV2, [...path, key], readonly); | ||
const proxyMap = mapProxy(context, map, textV2, [...path, key]); | ||
for (const key in value) { | ||
@@ -216,7 +218,4 @@ proxyMap[key] = value[key]; | ||
deleteProperty(target, key) { | ||
const { context, objectId, readonly } = target; | ||
const { context, objectId } = target; | ||
target.cache = {}; // reset cache on delete | ||
if (readonly) { | ||
throw new RangeError(`Object property "${key}" cannot be modified`); | ||
} | ||
context.delete(objectId, key); | ||
@@ -241,5 +240,5 @@ return true; | ||
ownKeys(target) { | ||
const { context, objectId, heads } = target; | ||
const { context, objectId } = target; | ||
// FIXME - this is a tmp workaround until fix the dupe key bug in keys() | ||
const keys = context.keys(objectId, heads); | ||
const keys = context.keys(objectId); | ||
return [...new Set(keys)]; | ||
@@ -250,3 +249,3 @@ }, | ||
get(target, index) { | ||
const { context, objectId, heads } = target; | ||
const { context, objectId } = target; | ||
index = parseListIndex(index); | ||
@@ -270,3 +269,3 @@ if (index === Symbol.hasInstance) { | ||
if (index === "length") | ||
return context.length(objectId, heads); | ||
return context.length(objectId); | ||
if (typeof index === "number") { | ||
@@ -280,5 +279,5 @@ return valueAt(target, index); | ||
set(target, index, val) { | ||
const { context, objectId, path, readonly, frozen, textV2 } = target; | ||
const { context, objectId, path, textV2 } = target; | ||
index = parseListIndex(index); | ||
if (val && val[OBJECT_ID]) { | ||
if (isSameDocument(val, context)) { | ||
throw new RangeError("Cannot create a reference to an existing document object"); | ||
@@ -294,8 +293,2 @@ } | ||
const [value, datatype] = import_value(val, textV2); | ||
if (frozen) { | ||
throw new RangeError("Attempting to use an outdated Automerge document"); | ||
} | ||
if (readonly) { | ||
throw new RangeError(`Object property "${index}" cannot be modified`); | ||
} | ||
switch (datatype) { | ||
@@ -310,3 +303,3 @@ case "list": { | ||
} | ||
const proxyList = listProxy(context, list, textV2, [...path, index], readonly); | ||
const proxyList = listProxy(context, list, textV2, [...path, index]); | ||
proxyList.splice(0, 0, ...value); | ||
@@ -334,3 +327,3 @@ break; | ||
} | ||
const proxyText = textProxy(context, text, [...path, index], readonly); | ||
const proxyText = textProxy(context, text, [...path, index]); | ||
proxyText.splice(0, 0, ...value); | ||
@@ -348,3 +341,3 @@ } | ||
} | ||
const proxyMap = mapProxy(context, map, textV2, [...path, index], readonly); | ||
const proxyMap = mapProxy(context, map, textV2, [...path, index]); | ||
for (const key in value) { | ||
@@ -376,6 +369,6 @@ proxyMap[key] = value[key]; | ||
has(target, index) { | ||
const { context, objectId, heads } = target; | ||
const { context, objectId } = target; | ||
index = parseListIndex(index); | ||
if (typeof index === "number") { | ||
return index < context.length(objectId, heads); | ||
return index < context.length(objectId); | ||
} | ||
@@ -385,5 +378,5 @@ return index === "length"; | ||
getOwnPropertyDescriptor(target, index) { | ||
const { context, objectId, heads } = target; | ||
const { context, objectId } = target; | ||
if (index === "length") | ||
return { writable: true, value: context.length(objectId, heads) }; | ||
return { writable: true, value: context.length(objectId) }; | ||
if (index === OBJECT_ID) | ||
@@ -402,4 +395,4 @@ return { configurable: false, enumerable: false, value: objectId }; | ||
// but not uncommenting it causes for (i in list) {} to not enumerate values properly | ||
//const {context, objectId, heads } = target | ||
//for (let i = 0; i < target.context.length(objectId, heads); i++) { keys.push(i.toString()) } | ||
//const {context, objectId } = target | ||
//for (let i = 0; i < target.context.length(objectId); i++) { keys.push(i.toString()) } | ||
keys.push("length"); | ||
@@ -411,3 +404,3 @@ return keys; | ||
get(target, index) { | ||
const { context, objectId, heads } = target; | ||
const { context, objectId } = target; | ||
index = parseListIndex(index); | ||
@@ -431,3 +424,3 @@ if (index === Symbol.hasInstance) { | ||
if (index === "length") | ||
return context.length(objectId, heads); | ||
return context.length(objectId); | ||
if (typeof index === "number") { | ||
@@ -444,3 +437,3 @@ return valueAt(target, index); | ||
}); | ||
export function mapProxy(context, objectId, textV2, path, readonly, heads) { | ||
export function mapProxy(context, objectId, textV2, path) { | ||
const target = { | ||
@@ -450,5 +443,2 @@ context, | ||
path: path || [], | ||
readonly: !!readonly, | ||
frozen: false, | ||
heads, | ||
cache: {}, | ||
@@ -463,3 +453,3 @@ textV2, | ||
} | ||
export function listProxy(context, objectId, textV2, path, readonly, heads) { | ||
export function listProxy(context, objectId, textV2, path) { | ||
const target = { | ||
@@ -469,5 +459,2 @@ context, | ||
path: path || [], | ||
readonly: !!readonly, | ||
frozen: false, | ||
heads, | ||
cache: {}, | ||
@@ -482,3 +469,3 @@ textV2, | ||
} | ||
export function textProxy(context, objectId, path, readonly, heads) { | ||
export function textProxy(context, objectId, path) { | ||
const target = { | ||
@@ -488,5 +475,2 @@ context, | ||
path: path || [], | ||
readonly: !!readonly, | ||
frozen: false, | ||
heads, | ||
cache: {}, | ||
@@ -499,8 +483,8 @@ textV2: false, | ||
} | ||
export function rootProxy(context, textV2, readonly) { | ||
export function rootProxy(context, textV2) { | ||
/* eslint-disable-next-line */ | ||
return mapProxy(context, "_root", textV2, [], !!readonly); | ||
return mapProxy(context, "_root", textV2, []); | ||
} | ||
function listMethods(target) { | ||
const { context, objectId, path, readonly, frozen, heads, textV2 } = target; | ||
const { context, objectId, path, textV2 } = target; | ||
const methods = { | ||
@@ -533,3 +517,3 @@ deleteAt(index, numDelete) { | ||
const text = context.putObject(objectId, i, ""); | ||
const proxyText = textProxy(context, text, [...path, i], readonly); | ||
const proxyText = textProxy(context, text, [...path, i]); | ||
for (let i = 0; i < value.length; i++) { | ||
@@ -549,3 +533,3 @@ proxyText[i] = value.get(i); | ||
for (let i = start; i < length; i++) { | ||
const value = context.getWithType(objectId, i, heads); | ||
const value = context.getWithType(objectId, i); | ||
if (value && (value[1] === o[OBJECT_ID] || value[1] === o)) { | ||
@@ -590,12 +574,6 @@ return i; | ||
for (const val of vals) { | ||
if (val && val[OBJECT_ID]) { | ||
if (isSameDocument(val, context)) { | ||
throw new RangeError("Cannot create a reference to an existing document object"); | ||
} | ||
} | ||
if (frozen) { | ||
throw new RangeError("Attempting to use an outdated Automerge document"); | ||
} | ||
if (readonly) { | ||
throw new RangeError("Sequence object cannot be modified outside of a change block"); | ||
} | ||
const result = []; | ||
@@ -614,3 +592,3 @@ for (let i = 0; i < del; i++) { | ||
const list = context.insertObject(objectId, index, []); | ||
const proxyList = listProxy(context, list, textV2, [...path, index], readonly); | ||
const proxyList = listProxy(context, list, textV2, [...path, index]); | ||
proxyList.splice(0, 0, ...value); | ||
@@ -626,3 +604,3 @@ break; | ||
const text = context.insertObject(objectId, index, ""); | ||
const proxyText = textProxy(context, text, [...path, index], readonly); | ||
const proxyText = textProxy(context, text, [...path, index]); | ||
proxyText.splice(0, 0, ...value); | ||
@@ -634,3 +612,3 @@ } | ||
const map = context.insertObject(objectId, index, {}); | ||
const proxyMap = mapProxy(context, map, textV2, [...path, index], readonly); | ||
const proxyMap = mapProxy(context, map, textV2, [...path, index]); | ||
for (const key in value) { | ||
@@ -672,3 +650,3 @@ proxyMap[key] = value[key]; | ||
let i = 0; | ||
const len = context.length(objectId, heads); | ||
const len = context.length(objectId); | ||
const iterator = { | ||
@@ -799,3 +777,3 @@ next: () => { | ||
function textMethods(target) { | ||
const { context, objectId, heads } = target; | ||
const { context, objectId } = target; | ||
const methods = { | ||
@@ -809,3 +787,3 @@ set(index, value) { | ||
toString() { | ||
return context.text(objectId, heads).replace(//g, ""); | ||
return context.text(objectId).replace(//g, ""); | ||
}, | ||
@@ -812,0 +790,0 @@ toSpans() { |
@@ -176,3 +176,3 @@ var __rest = (this && this.__rest) || function (s, e) { | ||
export function from(initialState, _opts) { | ||
return change(init(_opts), d => Object.assign(d, initialState)); | ||
return _change(init(_opts), "from", {}, d => Object.assign(d, initialState)); | ||
} | ||
@@ -227,3 +227,3 @@ /** | ||
if (typeof options === "function") { | ||
return _change(doc, {}, options); | ||
return _change(doc, "change", {}, options); | ||
} | ||
@@ -234,3 +234,3 @@ else if (typeof callback === "function") { | ||
} | ||
return _change(doc, options, callback); | ||
return _change(doc, "change", options, callback); | ||
} | ||
@@ -243,3 +243,3 @@ else { | ||
if (typeof options === "function") { | ||
return _change(doc, {}, options, scope); | ||
return _change(doc, "changeAt", {}, options, scope); | ||
} | ||
@@ -250,3 +250,3 @@ else if (typeof callback === "function") { | ||
} | ||
return _change(doc, options, callback, scope); | ||
return _change(doc, "changeAt", options, callback, scope); | ||
} | ||
@@ -257,3 +257,3 @@ else { | ||
} | ||
function progressDocument(doc, heads, callback) { | ||
function progressDocument(doc, source, heads, callback) { | ||
if (heads == null) { | ||
@@ -269,4 +269,3 @@ return doc; | ||
if (patches.length > 0) { | ||
const before = view(doc, headsBefore || []); | ||
callback(patches, { before, after: value }); | ||
callback(patches, { before: doc, after: value, source }); | ||
} | ||
@@ -281,3 +280,3 @@ nextDoc = value; | ||
} | ||
function _change(doc, options, callback, scope) { | ||
function _change(doc, source, options, callback, scope) { | ||
if (typeof callback !== "function") { | ||
@@ -311,3 +310,3 @@ throw new RangeError("invalid change function"); | ||
state.handle.integrate(); | ||
return progressDocument(doc, heads, options.patchCallback || state.patchCallback); | ||
return progressDocument(doc, source, heads, options.patchCallback || state.patchCallback); | ||
} | ||
@@ -348,3 +347,3 @@ } | ||
state.handle.emptyChange(options.message, options.time); | ||
return progressDocument(doc, heads); | ||
return progressDocument(doc, "emptyChange", heads); | ||
} | ||
@@ -420,3 +419,3 @@ /** | ||
state.handle.loadIncremental(data); | ||
return progressDocument(doc, heads, opts.patchCallback || state.patchCallback); | ||
return progressDocument(doc, "loadIncremental", heads, opts.patchCallback || state.patchCallback); | ||
} | ||
@@ -478,3 +477,3 @@ /** | ||
localState.handle.applyChanges(changes); | ||
return progressDocument(local, heads, localState.patchCallback); | ||
return progressDocument(local, "merge", heads, localState.patchCallback); | ||
} | ||
@@ -623,3 +622,3 @@ /** | ||
return [ | ||
progressDocument(doc, heads, opts.patchCallback || state.patchCallback), | ||
progressDocument(doc, "applyChanges", heads, opts.patchCallback || state.patchCallback), | ||
]; | ||
@@ -740,3 +739,3 @@ } | ||
return [ | ||
progressDocument(doc, heads, opts.patchCallback || state.patchCallback), | ||
progressDocument(doc, "receiveSyncMessage", heads, opts.patchCallback || state.patchCallback), | ||
outSyncState, | ||
@@ -743,0 +742,0 @@ null, |
@@ -40,3 +40,3 @@ /** | ||
import { unstableConflictAt } from "./conflicts"; | ||
export { view, free, getHeads, change, changeAt, emptyChange, loadIncremental, save, merge, getActorId, getLastLocalChange, getChanges, getAllChanges, applyChanges, getHistory, equals, encodeSyncState, decodeSyncState, generateSyncMessage, receiveSyncMessage, initSyncState, encodeChange, decodeChange, encodeSyncMessage, decodeSyncMessage, getMissingDeps, dump, toJS, isAutomerge, getObjectId, diff, insertAt, deleteAt, } from "./stable"; | ||
export { view, free, getHeads, change, changeAt, emptyChange, loadIncremental, saveIncremental, save, merge, getActorId, getLastLocalChange, getChanges, getAllChanges, applyChanges, getHistory, equals, encodeSyncState, decodeSyncState, generateSyncMessage, receiveSyncMessage, initSyncState, encodeChange, decodeChange, encodeSyncMessage, decodeSyncMessage, getMissingDeps, dump, toJS, isAutomerge, getObjectId, diff, insertAt, deleteAt, } from "./stable"; | ||
import * as stable from "./stable"; | ||
@@ -148,2 +148,17 @@ export { RawString } from "./raw_string"; | ||
} | ||
/** | ||
* Modify a string | ||
* | ||
* @typeParam T - The type of the value contained in the document | ||
* @param doc - The document to modify | ||
* @param path - The path to the string to modify | ||
* @param index - The position (as a {@link Cursor} or index) to edit. | ||
* If a cursor is used then the edit happens such that the cursor will | ||
* now point to the end of the newText, so you can continue to reuse | ||
* the same cursor for multiple calls to splice. | ||
* @param del - The number of code units to delete, a positive number | ||
* deletes N characters after the cursor, a negative number deletes | ||
* N characters before the cursor. | ||
* @param newText - The string to insert (if any). | ||
*/ | ||
export function splice(doc, path, index, del, newText) { | ||
@@ -169,2 +184,20 @@ if (!_is_proxy(doc)) { | ||
} | ||
/** | ||
* Returns a cursor for the given position in a string. | ||
* | ||
* @remarks | ||
* A cursor represents a relative position, "before character X", | ||
* rather than an absolute position. As the document is edited, the | ||
* cursor remains stable relative to its context, just as you'd expect | ||
* from a cursor in a concurrent text editor. | ||
* | ||
* The string representation is shareable, and so you can use this both | ||
* to edit the document yourself (using {@link splice}) or to share multiple | ||
* collaborator's current cursor positions over the network. | ||
* | ||
* @typeParam T - The type of the value contained in the document | ||
* @param doc - The document | ||
* @param path - The path to the string | ||
* @param index - The current index of the position of the cursor | ||
*/ | ||
export function getCursor(doc, path, index) { | ||
@@ -185,2 +218,11 @@ const state = _state(doc, false); | ||
} | ||
/** | ||
* Returns the current index of the cursor. | ||
* | ||
* @typeParam T - The type of the value contained in the document | ||
* | ||
* @param doc - The document | ||
* @param path - The path to the string | ||
* @param index - The cursor | ||
*/ | ||
export function getCursorPosition(doc, path, cursor) { | ||
@@ -237,3 +279,3 @@ const state = _state(doc, false); | ||
} | ||
export function marks(doc, prop) { | ||
export function marks(doc, path) { | ||
const state = _state(doc, false); | ||
@@ -244,3 +286,4 @@ const objectId = _obj(doc); | ||
} | ||
const obj = `${objectId}/${prop}`; | ||
path.unshift(objectId); | ||
const obj = path.join("/"); | ||
try { | ||
@@ -247,0 +290,0 @@ return state.handle.marks(obj); |
import { Text } from "./text"; | ||
import { Automerge, type Heads, type ObjID, type Prop } from "@automerge/automerge-wasm"; | ||
import { Automerge, type ObjID, type Prop } from "@automerge/automerge-wasm"; | ||
import type { AutomergeValue, MapValue, ListValue } from "./types"; | ||
@@ -9,7 +9,4 @@ import { type AutomergeValue as UnstableAutomergeValue, MapValue as UnstableMapValue, ListValue as UnstableListValue } from "./unstable_types"; | ||
path: Array<Prop>; | ||
readonly: boolean; | ||
heads?: Array<string>; | ||
cache: object; | ||
trace?: any; | ||
frozen: boolean; | ||
}; | ||
@@ -26,9 +23,9 @@ export type Text2Target = TargetCommon & { | ||
type ListValueType<T extends Target> = T extends Text2Target ? UnstableListValue : T extends Text1Target ? ListValue : never; | ||
export declare function mapProxy<T extends Target>(context: Automerge, objectId: ObjID, textV2: boolean, path?: Prop[], readonly?: boolean, heads?: Heads): MapValueType<T>; | ||
export declare function listProxy<T extends Target>(context: Automerge, objectId: ObjID, textV2: boolean, path?: Prop[], readonly?: boolean, heads?: Heads): ListValueType<T>; | ||
export declare function mapProxy<T extends Target>(context: Automerge, objectId: ObjID, textV2: boolean, path: Prop[]): MapValueType<T>; | ||
export declare function listProxy<T extends Target>(context: Automerge, objectId: ObjID, textV2: boolean, path: Prop[]): ListValueType<T>; | ||
interface TextProxy extends Text { | ||
splice: (index: any, del: any, ...vals: any[]) => void; | ||
} | ||
export declare function textProxy(context: Automerge, objectId: ObjID, path?: Prop[], readonly?: boolean, heads?: Heads): TextProxy; | ||
export declare function rootProxy<T>(context: Automerge, textV2: boolean, readonly?: boolean): T; | ||
export declare function textProxy(context: Automerge, objectId: ObjID, path: Prop[]): TextProxy; | ||
export declare function rootProxy<T>(context: Automerge, textV2: boolean): T; | ||
export {}; |
@@ -27,5 +27,7 @@ export { Text } from "./text"; | ||
}; | ||
export type PatchSource = "from" | "emptyChange" | "change" | "changeAt" | "merge" | "loadIncremental" | "applyChanges" | "receiveSyncMessage"; | ||
export type PatchInfo<T> = { | ||
before: Doc<T>; | ||
after: Doc<T>; | ||
source: PatchSource; | ||
}; | ||
@@ -32,0 +34,0 @@ /** |
@@ -44,3 +44,3 @@ /** | ||
export type { ChangeOptions, ApplyOptions, ChangeFn } from "./stable"; | ||
export { view, free, getHeads, change, changeAt, emptyChange, loadIncremental, save, merge, getActorId, getLastLocalChange, getChanges, getAllChanges, applyChanges, getHistory, equals, encodeSyncState, decodeSyncState, generateSyncMessage, receiveSyncMessage, initSyncState, encodeChange, decodeChange, encodeSyncMessage, decodeSyncMessage, getMissingDeps, dump, toJS, isAutomerge, getObjectId, diff, insertAt, deleteAt, } from "./stable"; | ||
export { view, free, getHeads, change, changeAt, emptyChange, loadIncremental, saveIncremental, save, merge, getActorId, getLastLocalChange, getChanges, getAllChanges, applyChanges, getHistory, equals, encodeSyncState, decodeSyncState, generateSyncMessage, receiveSyncMessage, initSyncState, encodeChange, decodeChange, encodeSyncMessage, decodeSyncMessage, getMissingDeps, dump, toJS, isAutomerge, getObjectId, diff, insertAt, deleteAt, } from "./stable"; | ||
export type InitOptions<T> = { | ||
@@ -52,2 +52,4 @@ /** The actor ID to use for this document, a random one will be generated if `null` is passed */ | ||
patchCallback?: PatchCallback<T>; | ||
/** @hidden */ | ||
unchecked?: boolean; | ||
}; | ||
@@ -118,8 +120,50 @@ import { ActorId, Doc } from "./stable"; | ||
export declare function load<T>(data: Uint8Array, _opts?: ActorId | InitOptions<T>): Doc<T>; | ||
/** | ||
* Modify a string | ||
* | ||
* @typeParam T - The type of the value contained in the document | ||
* @param doc - The document to modify | ||
* @param path - The path to the string to modify | ||
* @param index - The position (as a {@link Cursor} or index) to edit. | ||
* If a cursor is used then the edit happens such that the cursor will | ||
* now point to the end of the newText, so you can continue to reuse | ||
* the same cursor for multiple calls to splice. | ||
* @param del - The number of code units to delete, a positive number | ||
* deletes N characters after the cursor, a negative number deletes | ||
* N characters before the cursor. | ||
* @param newText - The string to insert (if any). | ||
*/ | ||
export declare function splice<T>(doc: Doc<T>, path: stable.Prop[], index: number | Cursor, del: number, newText?: string): string[] | undefined; | ||
/** | ||
* Returns a cursor for the given position in a string. | ||
* | ||
* @remarks | ||
* A cursor represents a relative position, "before character X", | ||
* rather than an absolute position. As the document is edited, the | ||
* cursor remains stable relative to its context, just as you'd expect | ||
* from a cursor in a concurrent text editor. | ||
* | ||
* The string representation is shareable, and so you can use this both | ||
* to edit the document yourself (using {@link splice}) or to share multiple | ||
* collaborator's current cursor positions over the network. | ||
* | ||
* @typeParam T - The type of the value contained in the document | ||
* @param doc - The document | ||
* @param path - The path to the string | ||
* @param index - The current index of the position of the cursor | ||
*/ | ||
export declare function getCursor<T>(doc: Doc<T>, path: stable.Prop[], index: number): Cursor; | ||
/** | ||
* Returns the current index of the cursor. | ||
* | ||
* @typeParam T - The type of the value contained in the document | ||
* | ||
* @param doc - The document | ||
* @param path - The path to the string | ||
* @param index - The cursor | ||
*/ | ||
export declare function getCursorPosition<T>(doc: Doc<T>, path: stable.Prop[], cursor: Cursor): number; | ||
export declare function mark<T>(doc: Doc<T>, path: stable.Prop[], range: MarkRange, name: string, value: MarkValue): void; | ||
export declare function unmark<T>(doc: Doc<T>, path: stable.Prop[], range: MarkRange, name: string): void; | ||
export declare function marks<T>(doc: Doc<T>, prop: stable.Prop): Mark[]; | ||
export declare function marks<T>(doc: Doc<T>, path: stable.Prop[]): Mark[]; | ||
/** | ||
@@ -126,0 +170,0 @@ * Get the conflicts associated with a property |
@@ -7,3 +7,3 @@ { | ||
], | ||
"version": "2.1.0-alpha.5", | ||
"version": "2.1.0-alpha.6", | ||
"description": "Javascript implementation of automerge, backed by @automerge/automerge-wasm", | ||
@@ -28,3 +28,3 @@ "homepage": "https://github.com/automerge/automerge/tree/main/javascript", | ||
"build": "tsc -p config/mjs.json && tsc -p config/cjs.json && tsc -p config/declonly.json --emitDeclarationOnly", | ||
"test": "ts-mocha test/*.ts", | ||
"test": "ts-mocha --type-check test/*.ts", | ||
"deno:build": "denoify && node ./scripts/deno-prefixer.mjs", | ||
@@ -55,5 +55,5 @@ "deno:test": "deno test ./deno-tests/deno.ts --allow-read --allow-net", | ||
"dependencies": { | ||
"@automerge/automerge-wasm": "^0.2.4", | ||
"@automerge/automerge-wasm": "^0.2.5", | ||
"uuid": "^9.0.0" | ||
} | ||
} |
247473
6662