( block: Block, opt_noId?: boolean, )
| 114 | * an insertion marker. |
| 115 | */ |
| 116 | export function blockToDomWithXY( |
| 117 | block: Block, |
| 118 | opt_noId?: boolean, |
| 119 | ): Element | DocumentFragment { |
| 120 | if (block.isInsertionMarker()) { |
| 121 | // Skip over insertion markers. |
| 122 | block = block.getChildren(false)[0]; |
| 123 | if (!block) { |
| 124 | // Disappears when appended. |
| 125 | return new DocumentFragment(); |
| 126 | } |
| 127 | } |
| 128 | |
| 129 | let width = 0; // Not used in LTR. |
| 130 | if (block.workspace.RTL) { |
| 131 | width = block.workspace.getWidth(); |
| 132 | } |
| 133 | |
| 134 | const element = blockToDom(block, opt_noId); |
| 135 | if (isElement(element)) { |
| 136 | const xy = block.getRelativeToSurfaceXY(); |
| 137 | element.setAttribute( |
| 138 | 'x', |
| 139 | String(Math.round(block.workspace.RTL ? width - xy.x : xy.x)), |
| 140 | ); |
| 141 | element.setAttribute('y', String(Math.round(xy.y))); |
| 142 | } |
| 143 | return element; |
| 144 | } |
| 145 | |
| 146 | /** |
| 147 | * Encode a field as XML. |
no test coverage detected