MCPcopy
hub / github.com/RaspberryPiFoundation/blockly / blockToDomWithXY

Function blockToDomWithXY

packages/blockly/core/xml.ts:116–144  ·  view source on GitHub ↗
(
  block: Block,
  opt_noId?: boolean,
)

Source from the content-addressed store, hash-verified

114 * an insertion marker.
115 */
116export 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.

Callers 1

workspaceToDomFunction · 0.85

Calls 6

blockToDomFunction · 0.85
isElementFunction · 0.85
isInsertionMarkerMethod · 0.80
getWidthMethod · 0.65
getChildrenMethod · 0.45

Tested by

no test coverage detected