formacao
This commit is contained in:
+40
-10
@@ -1,4 +1,3 @@
|
||||
"use strict";
|
||||
var __defProp = Object.defineProperty;
|
||||
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
||||
var __getOwnPropNames = Object.getOwnPropertyNames;
|
||||
@@ -80,11 +79,16 @@ const documentMetadataTag = (tag, props, preserveNodeType, supportSort, supportB
|
||||
let element = null;
|
||||
let created = false;
|
||||
const deDupeKeys = import_common.deDupeKeyMap[tag];
|
||||
const deDupeByKey = (0, import_common.shouldDeDupeByKey)(tag, supportSort);
|
||||
const isDeDupeCandidateLink = (e) => e.getAttribute("rel") === "stylesheet" && e.getAttribute(import_common.dataPrecedenceAttr) !== null;
|
||||
let existingElements = void 0;
|
||||
if (deDupeKeys.length > 0) {
|
||||
if (deDupeByKey) {
|
||||
const tags = head.querySelectorAll(tag);
|
||||
LOOP: for (const e of tags) {
|
||||
for (const key of import_common.deDupeKeyMap[tag]) {
|
||||
if (tag === "link" && !isDeDupeCandidateLink(e)) {
|
||||
continue;
|
||||
}
|
||||
for (const key of deDupeKeys) {
|
||||
if (e.getAttribute(key) === props[key]) {
|
||||
element = e;
|
||||
break LOOP;
|
||||
@@ -103,9 +107,9 @@ const documentMetadataTag = (tag, props, preserveNodeType, supportSort, supportB
|
||||
if (props[key] !== void 0) {
|
||||
e.setAttribute(key, props[key]);
|
||||
}
|
||||
if (props.rel) {
|
||||
e.setAttribute("rel", props.rel);
|
||||
}
|
||||
}
|
||||
if (props.rel) {
|
||||
e.setAttribute("rel", props.rel);
|
||||
}
|
||||
return e;
|
||||
})();
|
||||
@@ -119,7 +123,26 @@ const documentMetadataTag = (tag, props, preserveNodeType, supportSort, supportB
|
||||
}
|
||||
const insert = (0, import_hooks.useCallback)(
|
||||
(e) => {
|
||||
if (deDupeKeys.length > 0) {
|
||||
if (deDupeByKey) {
|
||||
if (tag === "link" && precedence !== void 0) {
|
||||
let found2 = false;
|
||||
for (const existingElement of head.querySelectorAll(tag)) {
|
||||
const existingPrecedence = existingElement.getAttribute(import_common.dataPrecedenceAttr);
|
||||
if (existingPrecedence === null) {
|
||||
head.insertBefore(e, existingElement);
|
||||
return;
|
||||
}
|
||||
if (found2 && existingPrecedence !== precedence) {
|
||||
head.insertBefore(e, existingElement);
|
||||
return;
|
||||
}
|
||||
if (existingPrecedence === precedence) {
|
||||
found2 = true;
|
||||
}
|
||||
}
|
||||
head.appendChild(e);
|
||||
return;
|
||||
}
|
||||
let found = false;
|
||||
for (const existingElement of head.querySelectorAll(tag)) {
|
||||
if (found && existingElement.getAttribute(import_common.dataPrecedenceAttr) !== precedence) {
|
||||
@@ -131,6 +154,10 @@ const documentMetadataTag = (tag, props, preserveNodeType, supportSort, supportB
|
||||
}
|
||||
}
|
||||
head.appendChild(e);
|
||||
} else if (tag === "link") {
|
||||
if (!head.contains(e)) {
|
||||
head.appendChild(e);
|
||||
}
|
||||
} else if (existingElements) {
|
||||
let found = false;
|
||||
for (const existingElement of existingElements) {
|
||||
@@ -148,7 +175,7 @@ const documentMetadataTag = (tag, props, preserveNodeType, supportSort, supportB
|
||||
existingElements = void 0;
|
||||
}
|
||||
},
|
||||
[precedence]
|
||||
[deDupeByKey, precedence, tag]
|
||||
);
|
||||
const ref = composeRef(props.ref, (e) => {
|
||||
const key = deDupeKeys[0];
|
||||
@@ -161,6 +188,9 @@ const documentMetadataTag = (tag, props, preserveNodeType, supportSort, supportB
|
||||
if (!onError && !onLoad) {
|
||||
return;
|
||||
}
|
||||
if (!key) {
|
||||
return;
|
||||
}
|
||||
let promise = blockingPromiseMap[e.getAttribute(key)] ||= new Promise(
|
||||
(resolve, reject) => {
|
||||
e.addEventListener("load", resolve);
|
||||
@@ -178,7 +208,7 @@ const documentMetadataTag = (tag, props, preserveNodeType, supportSort, supportB
|
||||
});
|
||||
if (supportBlocking && blocking === "render") {
|
||||
const key = import_common.deDupeKeyMap[tag][0];
|
||||
if (props[key]) {
|
||||
if (key && props[key]) {
|
||||
const value = props[key];
|
||||
const promise = blockingPromiseMap[value] ||= new Promise((resolve, reject) => {
|
||||
insert(element);
|
||||
@@ -254,7 +284,7 @@ const link = (props) => {
|
||||
ref: props.ref
|
||||
};
|
||||
}
|
||||
return documentMetadataTag("link", props, 1, "precedence" in props, true);
|
||||
return documentMetadataTag("link", props, 1, (0, import_common.isStylesheetLinkWithPrecedence)(props), true);
|
||||
};
|
||||
const meta = (props) => {
|
||||
return documentMetadataTag("meta", props, void 0, false, false);
|
||||
|
||||
Reference in New Issue
Block a user