@@ -896,8 +896,8 @@ export const $anyOp = s.$union($insertOp, $deleteOp, $textOp, $modifyOp)
896896/**
897897 * @template {string} [NodeName=any]
898898 * @template {{[k:string|number]:any}} [Attrs={}]
899- * @template {fingerprintTrait.Fingerprintable|never } [Children=never]
900- * @template {string|never } [Text=never]
899+ * @template {fingerprintTrait.Fingerprintable} [Children=never]
900+ * @template {string} [Text=never]
901901 * @template {s.Schema<Delta<any,any,any,any,any>>|null} [Schema=any]
902902 */
903903export class Delta {
@@ -1155,8 +1155,8 @@ const modDeltaCheck = d => {
11551155/**
11561156 * @template {string} [NodeName=any]
11571157 * @template {{[key:string|number]:any}} [Attrs={}]
1158- * @template {fingerprintTrait.Fingerprintable|never } [Children=never]
1159- * @template {string|never } [Text=never]
1158+ * @template {fingerprintTrait.Fingerprintable} [Children=never]
1159+ * @template {string} [Text=never]
11601160 * @template {s.Schema<Delta<any,any,any,any,any>>|null} [Schema=any]
11611161 * @extends {Delta<NodeName,Attrs,Children,Text,Schema> }
11621162 */
@@ -1734,8 +1734,32 @@ export class DeltaBuilder extends Delta {
17341734 console . info ( 'method rebaseOnInverse unimplemented' )
17351735 return this
17361736 }
1737+
1738+ /**
1739+ * Append child ops from one op to the other.
1740+ *
1741+ * delta.create().insert('a').append(delta.create().insert('b')) // => insert "ab"
1742+ *
1743+ * @template {DeltaAny} OtherDelta
1744+ * @param {OtherDelta } other
1745+ * @return {CastToDelta<OtherDelta> extends Delta<any,any,infer OtherChildren,infer OtherText,any> ? DeltaBuilder<NodeName,Attrs,Children|OtherChildren,Text|OtherText,Schema> : never }
1746+ */
1747+ append ( other ) {
1748+ // @todo Investigate. Above is a typescript issue. It is necessary to cast OtherDelta to a Delta first before
1749+ // inferring type, otherwise Children will contain Text.
1750+ for ( const child of other . children ) {
1751+ list . pushEnd ( this . children , child . clone ( ) )
1752+ }
1753+ // @ts -ignore
1754+ return this
1755+ }
17371756}
17381757
1758+ /**
1759+ * @template {DeltaAny} D
1760+ * @typedef {D extends DeltaBuilder<infer N,infer Attrs,infer Children,infer Text,infer Schema> ? Delta<N,Attrs,Children,Text,Schema> : D } CastToDelta
1761+ */
1762+
17391763/**
17401764 * @template {string} NodeName
17411765 * @template {{ [key: string|number]: any }} [Attrs={}]
@@ -1813,9 +1837,9 @@ export class $Delta extends s.Schema {
18131837 * @template {{ [k:string]:any }} [Formats={[k:string]:any}]
18141838 * @param {object } opts
18151839 * @param {NodeNameSchema? } [opts.name]
1816- * @param {AttrsSchema? } [opts.attrs]
1817- * @param {ChildrenSchema? } [opts.children]
1818- * @param {HasText } [opts.text]
1840+ * @param {AttrsSchema? } [opts.attrs] What key-value pairs are included.
1841+ * @param {ChildrenSchema? } [opts.children] The type of content in `insertOp`
1842+ * @param {HasText } [opts.text] Whether this delta contains text using `textOp`
18191843 * @param {Formats } [opts.formats]
18201844 * @param {Recursive } [opts.recursive]
18211845 * @return {[s.Unwrap<s.ReadSchema<NodeNameSchema>>,s.Unwrap<s.ReadSchema<AttrsSchema>>,s.Unwrap<s.ReadSchema<ChildrenSchema>>] extends [infer NodeName, infer Attrs, infer Children] ? s.Schema<Delta<
@@ -2132,7 +2156,6 @@ export const diff = (d1, d2) => {
21322156 * @param {DeltaBuilderAny } d
21332157 * @param {ChildrenOpAny[] } opsIs
21342158 * @param {ChildrenOpAny[] } opsShould
2135- *
21362159 */
21372160 const diffAndApply = ( d , opsIs , opsShould ) => {
21382161 // @todo unoptimized implementation. Convert content to array and diff that based on
@@ -2160,7 +2183,7 @@ export const diff = (d1, d2) => {
21602183 cd . insert = shouldContent . slice ( cd . index + adj , cd . index + adj + cd . insert . length )
21612184 adj += cd . remove . length - cd . insert . length
21622185 }
2163- for ( let i = 0 , lastIndex = 0 , currIndexOffset2 = 0 ; i < cdiff . length ; i ++ ) {
2186+ for ( let i = 0 , lastIndex = 0 ; i < cdiff . length ; i ++ ) {
21642187 const cd = cdiff [ i ]
21652188 d . retain ( cd . index - lastIndex )
21662189 let cdii = 0
0 commit comments