* Render the difference to another ydoc (which can be empty) and highlight the differences with * attributions. * * Note that deleted content that was not deleted in prevYdoc is rendered as an insertion with the * attribution `{ isDeleted: true, .. }`. * * @template {boolean} [Deep
(am = noAttributionsManager, opts = {})
| 793 | * @public |
| 794 | */ |
| 795 | toDelta (am = noAttributionsManager, opts = {}) { |
| 796 | const { itemsToRender = null, retainInserts = false, retainDeletes = false, deletedItems = null, modified = null, deep = false } = opts |
| 797 | const renderAttrs = modified?.get(this) || null |
| 798 | const renderChildren = !!(modified == null || modified.get(this)?.has(null)) |
| 799 | /** |
| 800 | * @type {delta.DeltaBuilderAny} |
| 801 | */ |
| 802 | const d = /** @type {any} */ (delta.create(this.name)) |
| 803 | const optsAll = modified == null ? opts : object.assign({}, opts, { modified: null }) |
| 804 | typeMapGetDelta(d, /** @type {any} */ (this), renderAttrs, am, deep, modified, deletedItems, itemsToRender, opts, optsAll) |
| 805 | if (renderChildren) { |
| 806 | /** |
| 807 | * @type {delta.FormattingAttributes} |
| 808 | */ |
| 809 | let currentAttributes = {} // saves all current attributes for insert |
| 810 | let usingCurrentAttributes = false |
| 811 | /** |
| 812 | * @type {delta.FormattingAttributes} |
| 813 | */ |
| 814 | let changedAttributes = {} // saves changed attributes for retain |
| 815 | let usingChangedAttributes = false |
| 816 | /** |
| 817 | * Logic for formatting attribute attribution |
| 818 | * Everything that comes after an formatting attribute is formatted by the user that created it. |
| 819 | * Two exceptions: |
| 820 | * - the user resets formatting to the previously known formatting that is not attributed |
| 821 | * - the user deletes a formatting attribute and hence restores the previously known formatting |
| 822 | * that is not attributed. |
| 823 | * @type {delta.FormattingAttributes} |
| 824 | */ |
| 825 | const previousUnattributedAttributes = {} // contains previously known unattributed formatting |
| 826 | /** |
| 827 | * @type {delta.FormattingAttributes} |
| 828 | */ |
| 829 | const previousAttributes = {} // The value before changes |
| 830 | /** |
| 831 | * @type {Array<import('./internals.js').AttributedContent<any>>} |
| 832 | */ |
| 833 | const cs = [] |
| 834 | for (let item = this._start; item !== null; cs.length = 0) { |
| 835 | if (itemsToRender != null) { |
| 836 | for (; item !== null && cs.length < 50; item = item.right) { |
| 837 | const rslice = itemsToRender.slice(item.id.client, item.id.clock, item.length) |
| 838 | let itemContent = rslice.length > 1 ? item.content.copy() : item.content |
| 839 | for (let ir = 0; ir < rslice.length; ir++) { |
| 840 | const idrange = rslice[ir] |
| 841 | const content = itemContent |
| 842 | if (ir !== rslice.length - 1) { |
| 843 | itemContent = itemContent.splice(idrange.len) |
| 844 | } |
| 845 | am.readContent(cs, item.id.client, idrange.clock, item.deleted, content, idrange.exists ? 2 : 0) |
| 846 | } |
| 847 | } |
| 848 | } else { |
| 849 | for (; item !== null && cs.length < 50; item = item.right) { |
| 850 | am.readContent(cs, item.id.client, item.id.clock, item.deleted, item.content, 1) |
| 851 | } |
| 852 | } |
no test coverage detected