@automerge/automerge
Advanced tools
Comparing version 2.1.10 to 2.1.11-richtext-alpha.1
@@ -162,2 +162,3 @@ /** | ||
export function splice(doc, path, index, del, newText) { | ||
const objPath = absoluteObjPath(doc, path, "splice"); | ||
if (!_is_proxy(doc)) { | ||
@@ -167,12 +168,6 @@ throw new RangeError("object cannot be modified outside of a change block"); | ||
const state = _state(doc, false); | ||
const objectId = _obj(doc); | ||
if (!objectId) { | ||
throw new RangeError("invalid object for splice"); | ||
} | ||
_clear_cache(doc); | ||
path.unshift(objectId); | ||
const value = path.join("/"); | ||
index = cursorToIndex(state, value, index); | ||
index = cursorToIndex(state, objPath, index); | ||
try { | ||
return state.handle.splice(value, index, del, newText); | ||
return state.handle.splice(objPath, index, del, newText); | ||
} | ||
@@ -203,2 +198,3 @@ catch (e) { | ||
export function updateText(doc, path, newText) { | ||
const objPath = absoluteObjPath(doc, path, "updateText"); | ||
if (!_is_proxy(doc)) { | ||
@@ -208,11 +204,5 @@ throw new RangeError("object cannot be modified outside of a change block"); | ||
const state = _state(doc, false); | ||
const objectId = _obj(doc); | ||
if (!objectId) { | ||
throw new RangeError("invalid object for updateText"); | ||
} | ||
_clear_cache(doc); | ||
path.unshift(objectId); | ||
const value = path.join("/"); | ||
try { | ||
return state.handle.updateText(value, newText); | ||
return state.handle.updateText(objPath, newText); | ||
} | ||
@@ -223,2 +213,82 @@ catch (e) { | ||
} | ||
export function spans(doc, path) { | ||
const state = _state(doc, false); | ||
const objPath = absoluteObjPath(doc, path, "spans"); | ||
try { | ||
return state.handle.spans(objPath, state.heads); | ||
} | ||
catch (e) { | ||
throw new RangeError(`Cannot splice: ${e}`); | ||
} | ||
} | ||
export function block(doc, path, index) { | ||
const objPath = absoluteObjPath(doc, path, "splitBlock"); | ||
const state = _state(doc, false); | ||
index = cursorToIndex(state, objPath, index); | ||
try { | ||
return state.handle.getBlock(objPath, index); | ||
} | ||
catch (e) { | ||
throw new RangeError(`Cannot get block: ${e}`); | ||
} | ||
} | ||
export function splitBlock(doc, path, index, block) { | ||
if (!_is_proxy(doc)) { | ||
throw new RangeError("object cannot be modified outside of a change block"); | ||
} | ||
const objPath = absoluteObjPath(doc, path, "splitBlock"); | ||
const state = _state(doc, false); | ||
_clear_cache(doc); | ||
index = cursorToIndex(state, objPath, index); | ||
try { | ||
state.handle.splitBlock(objPath, index, block); | ||
} | ||
catch (e) { | ||
throw new RangeError(`Cannot splice: ${e}`); | ||
} | ||
} | ||
export function joinBlock(doc, path, index) { | ||
if (!_is_proxy(doc)) { | ||
throw new RangeError("object cannot be modified outside of a change block"); | ||
} | ||
const objPath = absoluteObjPath(doc, path, "joinBlock"); | ||
const state = _state(doc, false); | ||
_clear_cache(doc); | ||
index = cursorToIndex(state, objPath, index); | ||
try { | ||
state.handle.joinBlock(objPath, index); | ||
} | ||
catch (e) { | ||
throw new RangeError(`Cannot joinBlock: ${e}`); | ||
} | ||
} | ||
export function updateBlock(doc, path, index, block) { | ||
if (!_is_proxy(doc)) { | ||
throw new RangeError("object cannot be modified outside of a change block"); | ||
} | ||
const objPath = absoluteObjPath(doc, path, "updateBlock"); | ||
const state = _state(doc, false); | ||
_clear_cache(doc); | ||
index = cursorToIndex(state, objPath, index); | ||
try { | ||
state.handle.updateBlock(objPath, index, block); | ||
} | ||
catch (e) { | ||
throw new RangeError(`Cannot updateBlock: ${e}`); | ||
} | ||
} | ||
export function updateBlocks(doc, path, blocks) { | ||
if (!_is_proxy(doc)) { | ||
throw new RangeError("object cannot be modified outside of a change block"); | ||
} | ||
const objPath = absoluteObjPath(doc, path, "updateBlock"); | ||
const state = _state(doc, false); | ||
_clear_cache(doc); | ||
try { | ||
state.handle.updateBlocks(objPath, blocks); | ||
} | ||
catch (e) { | ||
throw new RangeError(`Cannot updateBlock: ${e}`); | ||
} | ||
} | ||
/** | ||
@@ -243,11 +313,6 @@ * Returns a cursor for the given position in a string. | ||
export function getCursor(doc, path, index) { | ||
const objPath = absoluteObjPath(doc, path, "getCursor"); | ||
const state = _state(doc, false); | ||
const objectId = _obj(doc); | ||
if (!objectId) { | ||
throw new RangeError("invalid object for getCursor"); | ||
} | ||
path.unshift(objectId); | ||
const value = path.join("/"); | ||
try { | ||
return state.handle.getCursor(value, index); | ||
return state.handle.getCursor(objPath, index); | ||
} | ||
@@ -268,11 +333,6 @@ catch (e) { | ||
export function getCursorPosition(doc, path, cursor) { | ||
const objPath = absoluteObjPath(doc, path, "getCursorPosition"); | ||
const state = _state(doc, false); | ||
const objectId = _obj(doc); | ||
if (!objectId) { | ||
throw new RangeError("invalid object for getCursorPosition"); | ||
} | ||
path.unshift(objectId); | ||
const value = path.join("/"); | ||
try { | ||
return state.handle.getCursorPosition(value, cursor); | ||
return state.handle.getCursorPosition(objPath, cursor); | ||
} | ||
@@ -284,2 +344,3 @@ catch (e) { | ||
export function mark(doc, path, range, name, value) { | ||
const objPath = absoluteObjPath(doc, path, "mark"); | ||
if (!_is_proxy(doc)) { | ||
@@ -289,10 +350,4 @@ throw new RangeError("object cannot be modified outside of a change block"); | ||
const state = _state(doc, false); | ||
const objectId = _obj(doc); | ||
if (!objectId) { | ||
throw new RangeError("invalid object for mark"); | ||
} | ||
path.unshift(objectId); | ||
const obj = path.join("/"); | ||
try { | ||
return state.handle.mark(obj, range, name, value); | ||
return state.handle.mark(objPath, range, name, value); | ||
} | ||
@@ -304,2 +359,3 @@ catch (e) { | ||
export function unmark(doc, path, range, name) { | ||
const objPath = absoluteObjPath(doc, path, "unmark"); | ||
if (!_is_proxy(doc)) { | ||
@@ -309,10 +365,4 @@ throw new RangeError("object cannot be modified outside of a change block"); | ||
const state = _state(doc, false); | ||
const objectId = _obj(doc); | ||
if (!objectId) { | ||
throw new RangeError("invalid object for unmark"); | ||
} | ||
path.unshift(objectId); | ||
const obj = path.join("/"); | ||
try { | ||
return state.handle.unmark(obj, range, name); | ||
return state.handle.unmark(objPath, range, name); | ||
} | ||
@@ -324,11 +374,6 @@ catch (e) { | ||
export function marks(doc, path) { | ||
const objPath = absoluteObjPath(doc, path, "marks"); | ||
const state = _state(doc, false); | ||
const objectId = _obj(doc); | ||
if (!objectId) { | ||
throw new RangeError("invalid object for marks"); | ||
} | ||
path.unshift(objectId); | ||
const obj = path.join("/"); | ||
try { | ||
return state.handle.marks(obj); | ||
return state.handle.marks(objPath); | ||
} | ||
@@ -340,11 +385,6 @@ catch (e) { | ||
export function marksAt(doc, path, index) { | ||
const objPath = absoluteObjPath(doc, path, "marksAt"); | ||
const state = _state(doc, false); | ||
const objectId = _obj(doc); | ||
if (!objectId) { | ||
throw new RangeError("invalid object for marksAt"); | ||
} | ||
path.unshift(objectId); | ||
const obj = path.join("/"); | ||
try { | ||
return state.handle.marksAt(obj, index); | ||
return state.handle.marksAt(objPath, index); | ||
} | ||
@@ -412,1 +452,10 @@ catch (e) { | ||
} | ||
function absoluteObjPath(doc, path, functionName) { | ||
path = path.slice(); | ||
const objectId = _obj(doc); | ||
if (!objectId) { | ||
throw new RangeError(`invalid object for ${functionName}`); | ||
} | ||
path.unshift(objectId); | ||
return path.join("/"); | ||
} |
@@ -166,3 +166,3 @@ /* eslint-disable @typescript-eslint/no-explicit-any */ | ||
if (key === STATE) | ||
return { handle: context }; | ||
return { handle: context, textV2: target.textV2 }; | ||
if (!cache[key]) { | ||
@@ -169,0 +169,0 @@ cache[key] = valueAt(target, key); |
@@ -89,6 +89,12 @@ var __rest = (this && this.__rest) || function (s, e) { | ||
if (textV2) { | ||
handle.registerDatatype("str", (n) => new RawString(n)); | ||
handle.registerDatatype("str", (n, { context }) => { | ||
if (context === "blockAttr") { | ||
return n; | ||
} | ||
else { | ||
return new RawString(n); | ||
} | ||
}); | ||
} | ||
else { | ||
// eslint-disable-next-line @typescript-eslint/no-explicit-any | ||
handle.registerDatatype("text", (n) => new Text(n)); | ||
@@ -523,3 +529,3 @@ } | ||
/** | ||
* Merge `local` into `remote` | ||
* Merge `remote` into `local` | ||
* @typeParam T - The type of values contained in each document | ||
@@ -526,0 +532,0 @@ * @param local - The document to merge changes into |
import { Counter } from "./types.js"; | ||
export { Counter, type Doc, Int, Uint, Float64, type Patch, type PatchCallback, type Mark, type MarkSet, type MarkRange, type MarkValue, type Cursor, type PatchInfo, type PatchSource, } from "./types.js"; | ||
export { Counter, type Doc, Int, Uint, Float64, type Patch, type MapObjType, type PatchCallback, type Mark, type MarkSet, type MarkRange, type MarkValue, type Cursor, type PatchInfo, type PatchSource, } from "./types.js"; | ||
import { RawString } from "./raw_string.js"; | ||
@@ -13,1 +13,2 @@ export { RawString } from "./raw_string.js"; | ||
export type ScalarValue = string | number | null | boolean | Date | Counter | Uint8Array | RawString; | ||
export type BlockAttrValue = string | number | boolean | null | Date | Uint8Array; |
@@ -37,7 +37,8 @@ /** | ||
*/ | ||
export { Counter, type Doc, Int, Uint, Float64, type Patch, type PatchCallback, type Mark, type MarkSet, type MarkRange, type MarkValue, type AutomergeValue, type ScalarValue, type PatchSource, type PatchInfo, } from "./next_types.js"; | ||
import type { Cursor, Mark, MarkSet, MarkRange, MarkValue } from "./next_types.js"; | ||
export { Counter, type Doc, Int, Uint, Float64, type Patch, type PatchCallback, type Mark, type MarkSet, type MarkRange, type MarkValue, type AutomergeValue, type BlockAttrValue, type ScalarValue, type PatchSource, type PatchInfo, } from "./next_types.js"; | ||
import type { BlockAttrValue, Cursor, Mark, MarkSet, MarkRange, MarkValue } from "./next_types.js"; | ||
import { type PatchCallback } from "./stable.js"; | ||
import { type UnstableConflicts as Conflicts } from "./conflicts.js"; | ||
export type { PutPatch, DelPatch, SpliceTextPatch, InsertPatch, IncPatch, SyncMessage, Heads, Cursor, } from "@automerge/automerge-wasm"; | ||
export type { PutPatch, DelPatch, SpliceTextPatch, InsertPatch, IncPatch, SyncMessage, Heads, Cursor, Span, SplitBlockPatch, JoinBlockPatch, UpdateBlockPatch, } from "@automerge/automerge-wasm"; | ||
import { type Span } from "@automerge/automerge-wasm"; | ||
export type { ActorId, Change, ChangeOptions, Prop, DecodedChange, DecodedSyncMessage, ApplyOptions, ChangeFn, ChangeAtResult, MaterializeValue, SyncState, } from "./stable.js"; | ||
@@ -166,2 +167,32 @@ 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, saveSince, } from "./stable.js"; | ||
export declare function updateText(doc: Doc<unknown>, path: stable.Prop[], newText: string): void; | ||
export declare function spans<T>(doc: Doc<T>, path: stable.Prop[]): Span[]; | ||
export declare function block<T>(doc: Doc<T>, path: stable.Prop[], index: number | Cursor): { | ||
type: string; | ||
parents: string[]; | ||
attrs: { | ||
[key: string]: import("@automerge/automerge-wasm").Value; | ||
}; | ||
} | null; | ||
export declare function splitBlock<T>(doc: Doc<T>, path: stable.Prop[], index: number | Cursor, block: { | ||
type: string; | ||
parents: string[]; | ||
attrs: { | ||
[key: string]: BlockAttrValue; | ||
}; | ||
}): void; | ||
export declare function joinBlock<T>(doc: Doc<T>, path: stable.Prop[], index: number | Cursor): void; | ||
export declare function updateBlock<T>(doc: Doc<T>, path: stable.Prop[], index: number | Cursor, block: { | ||
type: string; | ||
parents: string[]; | ||
attrs: { | ||
[key: string]: BlockAttrValue; | ||
}; | ||
}): void; | ||
export declare function updateBlocks<T>(doc: Doc<T>, path: stable.Prop[], blocks: ({ | ||
type: string; | ||
parents: string[]; | ||
attrs: { | ||
[key: string]: BlockAttrValue; | ||
}; | ||
} | string)[]): void; | ||
/** | ||
@@ -168,0 +199,0 @@ * Returns a cursor for the given position in a string. |
@@ -348,3 +348,3 @@ /** @hidden **/ | ||
/** | ||
* Merge `local` into `remote` | ||
* Merge `remote` into `local` | ||
* @typeParam T - The type of values contained in each document | ||
@@ -351,0 +351,0 @@ * @param local - The document to merge changes into |
@@ -7,3 +7,3 @@ export { Text } from "./text.js"; | ||
import type { Patch } from "@automerge/automerge-wasm"; | ||
export type { Cursor, Patch, MarkSet, Mark, MarkRange, } from "@automerge/automerge-wasm"; | ||
export type { Cursor, MapObjType, MarkSet, Mark, MarkRange, Patch, } from "@automerge/automerge-wasm"; | ||
export type AutomergeValue = ScalarValue | { | ||
@@ -10,0 +10,0 @@ [key: string]: AutomergeValue; |
@@ -7,3 +7,3 @@ { | ||
], | ||
"version": "2.1.10", | ||
"version": "2.1.11-richtext-alpha.1", | ||
"description": "Javascript implementation of automerge, backed by @automerge/automerge-wasm", | ||
@@ -74,5 +74,5 @@ "homepage": "https://github.com/automerge/automerge/tree/main/javascript", | ||
"dependencies": { | ||
"@automerge/automerge-wasm": "0.9.0", | ||
"@automerge/automerge-wasm": "0.10.0-richtext-alpha.1", | ||
"uuid": "^9.0.0" | ||
} | ||
} |
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
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
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
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
428670
13601
1
+ Added@automerge/automerge-wasm@0.10.0-richtext-alpha.1(transitive)
- Removed@automerge/automerge-wasm@0.9.0(transitive)