MCPcopy Create free account
hub / github.com/UI5/webcomponents / _updateSlots

Function _updateSlots

packages/base/src/UI5Element.ts:485–617  ·  view source on GitHub ↗

* @private

()

Source from the content-addressed store, hash-verified

483 * @private
484 */
485 async _updateSlots() {
486 const ctor = this.constructor as typeof UI5Element;
487 const slotsMap = ctor.getMetadata().getSlots();
488 const canSlotText = ctor.getMetadata().canSlotText();
489 const domChildren = Array.from(canSlotText ? this.childNodes : this.children) as Array<Node>;
490
491 const slotsCachedContentMap = new Map<string, Array<SlotValue>>(); // Store here the content of each slot before the mutation occurred
492 const propertyNameToSlotMap = new Map<string, string>(); // Used for reverse lookup to determine to which slot the property name corresponds
493
494 // Init the _state object based on the supported slots and store the previous values
495 for (const [slotName, slotData] of Object.entries(slotsMap)) { // eslint-disable-line
496 const propertyName = slotData.propertyName || slotName;
497 propertyNameToSlotMap.set(propertyName, slotName);
498 slotsCachedContentMap.set(propertyName, [...(this._state[propertyName] as Array<SlotValue>)]);
499 this._clearSlot(slotName, slotData);
500 }
501
502 const autoIncrementMap = new Map<string, number>();
503 const slottedChildrenMap = new Map<string, Array<{ child: Node, idx: number }>>();
504
505 domChildren.forEach((child, idx) => {
506 // Determine the type of the child (mainly by the slot attribute)
507 const slotName = getSlotName(child);
508 const slotData = slotsMap[slotName];
509
510 // Check if the slotName is supported
511 if (slotData === undefined) {
512 if (slotName !== "default") {
513 const validValues = Object.keys(slotsMap).join(", ");
514 console.warn(`Unknown slotName: ${slotName}, ignoring`, child, `Valid values are: ${validValues}`); // eslint-disable-line
515 }
516
517 return;
518 }
519
520 const propertyName = slotData.propertyName || slotName;
521
522 if (slottedChildrenMap.has(propertyName)) {
523 slottedChildrenMap.get(propertyName)!.push({ child, idx });
524 } else {
525 slottedChildrenMap.set(propertyName, [{ child, idx }]);
526 }
527 });
528
529 // Distribute the child in the _state object, keeping the Light DOM order,
530 // not the order elements are defined.
531 slottedChildrenMap.forEach((children, propertyName) => {
532 this._state[propertyName] = children.sort((a, b) => a.idx - b.idx).map(_ => _.child);
533 this._state[kebabToCamelCase(propertyName)] = this._state[propertyName];
534 });
535
536 const allChildrenUpgraded = domChildren.map(async child => {
537 // Determine the type of the child (mainly by the slot attribute)
538 const slotName = getSlotName(child);
539 const slotData = slotsMap[slotName];
540
541 // Check if the slotName is supported
542 if (slotData === undefined) {

Callers

nothing calls this directly

Calls 12

getSlotNameFunction · 0.85
kebabToCamelCaseFunction · 0.85
arraysAreEqualFunction · 0.85
setFormValueFunction · 0.85
getSlotsMethod · 0.80
getMetadataMethod · 0.80
canSlotTextMethod · 0.80
pushMethod · 0.80
getMethod · 0.80
validateSlotValueMethod · 0.80
isFormAssociatedMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…