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

Function blockToDom

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

Source from the content-addressed store, hash-verified

183 * an insertion marker.
184 */
185export function blockToDom(
186 block: Block,
187 opt_noId?: boolean,
188): Element | DocumentFragment {
189 // Skip over insertion markers.
190 if (block.isInsertionMarker()) {
191 const child = block.getChildren(false)[0];
192 if (child) {
193 return blockToDom(child);
194 } else {
195 // Disappears when appended.
196 return new DocumentFragment();
197 }
198 }
199
200 const element = utilsXml.createElement(block.isShadow() ? 'shadow' : 'block');
201 element.setAttribute('type', block.type);
202 if (!opt_noId) {
203 element.id = block.id;
204 }
205 if (block.mutationToDom) {
206 // Custom data for an advanced block.
207 const mutation = block.mutationToDom();
208 if (mutation && (mutation.hasChildNodes() || mutation.hasAttributes())) {
209 element.appendChild(mutation);
210 }
211 }
212
213 allFieldsToDom(block, element);
214
215 const commentText = block.getCommentText();
216 if (commentText) {
217 const comment = block.getIcon(IconType.COMMENT)!;
218 const size = comment.getBubbleSize();
219 const pinned = comment.bubbleIsVisible();
220 const location = comment.getBubbleLocation();
221
222 const commentElement = utilsXml.createElement('comment');
223 commentElement.appendChild(utilsXml.createTextNode(commentText));
224 commentElement.setAttribute('pinned', `${pinned}`);
225 commentElement.setAttribute('h', `${size.height}`);
226 commentElement.setAttribute('w', `${size.width}`);
227 if (location) {
228 commentElement.setAttribute(
229 'x',
230 `${
231 block.workspace.RTL
232 ? block.workspace.getWidth() - (location.x + size.width)
233 : location.x
234 }`,
235 );
236 commentElement.setAttribute('y', `${location.y}`);
237 }
238
239 element.appendChild(commentElement);
240 }
241
242 if (block.data) {

Callers 1

blockToDomWithXYFunction · 0.85

Calls 15

allFieldsToDomFunction · 0.85
cloneShadowFunction · 0.85
isInsertionMarkerMethod · 0.80
isShadowMethod · 0.80
getCommentTextMethod · 0.80
getIconMethod · 0.80
fromMethod · 0.80
getDisabledReasonsMethod · 0.80
getBubbleSizeMethod · 0.65
bubbleIsVisibleMethod · 0.65
getBubbleLocationMethod · 0.65
getWidthMethod · 0.65

Tested by

no test coverage detected