diff --git a/crates/loro-wasm/src/lib.rs b/crates/loro-wasm/src/lib.rs index 035888c01..a94df5739 100644 --- a/crates/loro-wasm/src/lib.rs +++ b/crates/loro-wasm/src/lib.rs @@ -3585,6 +3585,7 @@ impl LoroTreeNode { /// // / \ /// // node2 node /// ``` + // Using custom typescript for generic on returned node #[wasm_bindgen(js_name = "createNode", skip_typescript)] pub fn create_node(&self, index: Option) -> JsResult { let id = if let Some(index) = index { @@ -3596,27 +3597,8 @@ impl LoroTreeNode { Ok(node) } - /// Move this tree node to be a child of the parent. - /// If the parent is undefined, this node will be a root node. - /// - /// If the index is not provided, the node will be appended to the end. - /// - /// It's not allowed that the target is an ancestor of the parent. - /// - /// @example - /// ```ts - /// const doc = new LoroDoc(); - /// const tree = doc.getTree("tree"); - /// const root = tree.createNode(); - /// const node = root.createNode(); - /// const node2 = node.createNode(); - /// node2.move(undefined, 0); - /// // node2 root - /// // | - /// // node - /// - /// ``` - #[wasm_bindgen(js_name = "move")] + // Using custom typescript for generic parameter & optional argument + #[wasm_bindgen(js_name = "move", skip_typescript)] pub fn mov(&self, parent: &JsTreeNodeOrUndefined, index: Option) -> JsResult<()> { let parent: Option = parse_js_tree_node(parent)?; if let Some(index) = index { @@ -3728,12 +3710,8 @@ impl LoroTreeNode { .tree_node_to_js_obj(node, true) } - /// Get the parent node of this node. - /// - /// - The parent of the root node is `undefined`. - /// - The object returned is a new js object each time because it need to cross - /// the WASM boundary. - #[wasm_bindgen] + // Using custom typescript for generic parameter on the returned node + #[wasm_bindgen(skip_typescript)] pub fn parent(&self) -> JsResult> { let parent = self .tree @@ -3894,6 +3872,7 @@ impl LoroTree { } /// Get LoroTreeNode by the TreeID. + // Using custom typescript for generic parameter on the returned node #[wasm_bindgen(js_name = "getNodeByID", skip_typescript)] pub fn get_node_by_id(&self, target: &JsTreeID) -> Option { let target: JsValue = target.into(); @@ -5223,11 +5202,6 @@ export type TreeNodeJSON = Omit & { children: TreeNodeJSON[], } -interface LoroTree{ - toArray(): TreeNodeValue[]; - getNodes(options?: { withDeleted?: boolean } ): LoroTreeNode[]; -} - interface LoroMovableList { /** * Get the cursor position at the given pos. @@ -5956,6 +5930,8 @@ interface LoroTree = Record> */ getNodeByID(target: TreeID): LoroTreeNode; subscribe(listener: Listener): Subscription; + toArray(): TreeNodeValue[]; + getNodes(options?: { withDeleted?: boolean } ): LoroTreeNode[]; } interface LoroTreeNode = Record> { /** @@ -5983,7 +5959,36 @@ interface LoroTreeNode = Record; + /** + * Move this tree node to be a child of the parent. + * If the parent is undefined, this node will be a root node. + * + * If the index is not provided, the node will be appended to the end. + * + * It's not allowed that the target is an ancestor of the parent. + * + * @example + * ```ts + * const doc = new LoroDoc(); + * const tree = doc.getTree("tree"); + * const root = tree.createNode(); + * const node = root.createNode(); + * const node2 = node.createNode(); + * node2.move(undefined, 0); + * // node2 root + * // | + * // node + * + * ``` + */ move(parent?: LoroTreeNode, index?: number): void; + /** + * Get the parent node of this node. + * + * - The parent of the root node is `undefined`. + * - The object returned is a new js object each time because it need to cross + * the WASM boundary. + */ parent(): LoroTreeNode | undefined; /** * Get the children of this node.