formacao
This commit is contained in:
+11
-4
@@ -100,22 +100,29 @@ var createCssJsxDomObjects = ({ id }) => {
|
||||
});
|
||||
return [cssObject, Style2];
|
||||
};
|
||||
var createCssContext = ({ id }) => {
|
||||
var createCssContext = ({
|
||||
id,
|
||||
classNameSlug,
|
||||
onInvalidSlug
|
||||
}) => {
|
||||
const [cssObject, Style2] = createCssJsxDomObjects({ id });
|
||||
const newCssClassNameObject = (cssClassName) => {
|
||||
cssClassName.toString = cssObject.toString;
|
||||
return cssClassName;
|
||||
};
|
||||
const css2 = (strings, ...values) => {
|
||||
return newCssClassNameObject(cssCommon(strings, values));
|
||||
return newCssClassNameObject(cssCommon(strings, values, classNameSlug, onInvalidSlug));
|
||||
};
|
||||
const cx2 = (...args) => {
|
||||
args = cxCommon(args);
|
||||
return css2(Array(args.length).fill(""), ...args);
|
||||
};
|
||||
const keyframes2 = keyframesCommon;
|
||||
const keyframes2 = (strings, ...values) => keyframesCommon(strings, values, classNameSlug, onInvalidSlug);
|
||||
const viewTransition2 = ((strings, ...values) => {
|
||||
return newCssClassNameObject(viewTransitionCommon(strings, values));
|
||||
return newCssClassNameObject(
|
||||
viewTransitionCommon(strings, values, classNameSlug, onInvalidSlug)
|
||||
// eslint-disable-line @typescript-eslint/no-explicit-any
|
||||
);
|
||||
});
|
||||
return {
|
||||
css: css2,
|
||||
|
||||
+47
-10
@@ -1,7 +1,13 @@
|
||||
// src/jsx/dom/intrinsic-element/components.ts
|
||||
import { useContext } from "../../context.js";
|
||||
import { use, useCallback, useMemo, useState } from "../../hooks/index.js";
|
||||
import { dataPrecedenceAttr, deDupeKeyMap, domRenderers } from "../../intrinsic-element/common.js";
|
||||
import {
|
||||
dataPrecedenceAttr,
|
||||
deDupeKeyMap,
|
||||
domRenderers,
|
||||
isStylesheetLinkWithPrecedence,
|
||||
shouldDeDupeByKey
|
||||
} from "../../intrinsic-element/common.js";
|
||||
import { FormContext, registerAction } from "../hooks/index.js";
|
||||
import { createPortal, getNameSpaceContext } from "../render.js";
|
||||
var clearCache = () => {
|
||||
@@ -49,11 +55,16 @@ var documentMetadataTag = (tag, props, preserveNodeType, supportSort, supportBlo
|
||||
let element = null;
|
||||
let created = false;
|
||||
const deDupeKeys = deDupeKeyMap[tag];
|
||||
const deDupeByKey = shouldDeDupeByKey(tag, supportSort);
|
||||
const isDeDupeCandidateLink = (e) => e.getAttribute("rel") === "stylesheet" && e.getAttribute(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 deDupeKeyMap[tag]) {
|
||||
if (tag === "link" && !isDeDupeCandidateLink(e)) {
|
||||
continue;
|
||||
}
|
||||
for (const key of deDupeKeys) {
|
||||
if (e.getAttribute(key) === props[key]) {
|
||||
element = e;
|
||||
break LOOP;
|
||||
@@ -72,9 +83,9 @@ var documentMetadataTag = (tag, props, preserveNodeType, supportSort, supportBlo
|
||||
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;
|
||||
})();
|
||||
@@ -88,7 +99,26 @@ var documentMetadataTag = (tag, props, preserveNodeType, supportSort, supportBlo
|
||||
}
|
||||
const insert = 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(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(dataPrecedenceAttr) !== precedence) {
|
||||
@@ -100,6 +130,10 @@ var documentMetadataTag = (tag, props, preserveNodeType, supportSort, supportBlo
|
||||
}
|
||||
}
|
||||
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) {
|
||||
@@ -117,7 +151,7 @@ var documentMetadataTag = (tag, props, preserveNodeType, supportSort, supportBlo
|
||||
existingElements = void 0;
|
||||
}
|
||||
},
|
||||
[precedence]
|
||||
[deDupeByKey, precedence, tag]
|
||||
);
|
||||
const ref = composeRef(props.ref, (e) => {
|
||||
const key = deDupeKeys[0];
|
||||
@@ -130,6 +164,9 @@ var documentMetadataTag = (tag, props, preserveNodeType, supportSort, supportBlo
|
||||
if (!onError && !onLoad) {
|
||||
return;
|
||||
}
|
||||
if (!key) {
|
||||
return;
|
||||
}
|
||||
let promise = blockingPromiseMap[e.getAttribute(key)] ||= new Promise(
|
||||
(resolve, reject) => {
|
||||
e.addEventListener("load", resolve);
|
||||
@@ -147,7 +184,7 @@ var documentMetadataTag = (tag, props, preserveNodeType, supportSort, supportBlo
|
||||
});
|
||||
if (supportBlocking && blocking === "render") {
|
||||
const key = deDupeKeyMap[tag][0];
|
||||
if (props[key]) {
|
||||
if (key && props[key]) {
|
||||
const value = props[key];
|
||||
const promise = blockingPromiseMap[value] ||= new Promise((resolve, reject) => {
|
||||
insert(element);
|
||||
@@ -223,7 +260,7 @@ var link = (props) => {
|
||||
ref: props.ref
|
||||
};
|
||||
}
|
||||
return documentMetadataTag("link", props, 1, "precedence" in props, true);
|
||||
return documentMetadataTag("link", props, 1, isStylesheetLinkWithPrecedence(props), true);
|
||||
};
|
||||
var meta = (props) => {
|
||||
return documentMetadataTag("meta", props, void 0, false, false);
|
||||
|
||||
+39
-17
@@ -45,6 +45,17 @@ var getEventSpec = (key) => {
|
||||
};
|
||||
var toAttributeName = (element, key) => nameSpaceContext && element instanceof SVGElement && /[A-Z]/.test(key) && (key in element.style || // Presentation attributes are findable in style object. "clip-path", "font-size", "stroke-width", etc.
|
||||
key.match(/^(?:o|pai|str|u|ve)/)) ? key.replace(/([A-Z])/g, "-$1").toLowerCase() : key;
|
||||
var normalizeFormValue = (value) => value === null || value === void 0 || value === false ? null : value;
|
||||
var applySelectValue = (select, props) => {
|
||||
if (!("value" in props)) {
|
||||
return;
|
||||
}
|
||||
select.value = normalizeFormValue(props["value"]);
|
||||
if (!select.multiple && select.selectedIndex === -1) {
|
||||
select.selectedIndex = 0;
|
||||
}
|
||||
};
|
||||
var isIgnorableAttributeError = (error) => error instanceof DOMException && error.name === "InvalidCharacterError";
|
||||
var applyProps = (container, attributes, oldAttributes) => {
|
||||
attributes ||= {};
|
||||
for (let key in attributes) {
|
||||
@@ -88,18 +99,14 @@ var applyProps = (container, attributes, oldAttributes) => {
|
||||
} else {
|
||||
if (key === "value") {
|
||||
const nodeName = container.nodeName;
|
||||
if (nodeName === "INPUT" || nodeName === "TEXTAREA" || nodeName === "SELECT") {
|
||||
if (nodeName === "SELECT") {
|
||||
continue;
|
||||
} else if (nodeName === "INPUT" || nodeName === "TEXTAREA") {
|
||||
;
|
||||
container.value = value === null || value === void 0 || value === false ? null : value;
|
||||
container.value = normalizeFormValue(value);
|
||||
if (nodeName === "TEXTAREA") {
|
||||
container.textContent = value;
|
||||
continue;
|
||||
} else if (nodeName === "SELECT") {
|
||||
if (container.selectedIndex === -1) {
|
||||
;
|
||||
container.selectedIndex = 0;
|
||||
}
|
||||
continue;
|
||||
}
|
||||
}
|
||||
} else if (key === "checked" && container.nodeName === "INPUT" || key === "selected" && container.nodeName === "OPTION") {
|
||||
@@ -107,14 +114,20 @@ var applyProps = (container, attributes, oldAttributes) => {
|
||||
container[key] = value;
|
||||
}
|
||||
const k = toAttributeName(container, key);
|
||||
if (value === null || value === void 0 || value === false) {
|
||||
container.removeAttribute(k);
|
||||
} else if (value === true) {
|
||||
container.setAttribute(k, "");
|
||||
} else if (typeof value === "string" || typeof value === "number") {
|
||||
container.setAttribute(k, value);
|
||||
} else {
|
||||
container.setAttribute(k, value.toString());
|
||||
try {
|
||||
if (value === null || value === void 0 || value === false) {
|
||||
container.removeAttribute(k);
|
||||
} else if (value === true) {
|
||||
container.setAttribute(k, "");
|
||||
} else if (typeof value === "string" || typeof value === "number") {
|
||||
container.setAttribute(k, value);
|
||||
} else {
|
||||
container.setAttribute(k, value.toString());
|
||||
}
|
||||
} catch (e) {
|
||||
if (!isIgnorableAttributeError(e)) {
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -130,7 +143,13 @@ var applyProps = (container, attributes, oldAttributes) => {
|
||||
} else if (key === "ref") {
|
||||
refCleanupMap.get(container)?.();
|
||||
} else {
|
||||
container.removeAttribute(toAttributeName(container, key));
|
||||
try {
|
||||
container.removeAttribute(toAttributeName(container, key));
|
||||
} catch (e) {
|
||||
if (!isIgnorableAttributeError(e)) {
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -268,6 +287,9 @@ var applyNodeObject = (node, container, isNew) => {
|
||||
el = child.e ||= child.n ? document.createElementNS(child.n, child.tag) : document.createElement(child.tag);
|
||||
applyProps(el, child.props, child.pP);
|
||||
applyNodeObject(child, el, isNewLocal);
|
||||
if (child.tag === "select") {
|
||||
applySelectValue(el, child.props);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (child.tag === HONO_PORTAL_ELEMENT) {
|
||||
|
||||
Reference in New Issue
Block a user