veles 1.1.0 → 1.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -108,11 +108,20 @@ function executeComponent({ element, props }) {
|
|
|
108
108
|
}
|
|
109
109
|
//#endregion
|
|
110
110
|
//#region src/create-element/parse-children.ts
|
|
111
|
+
function flattenChildren(children) {
|
|
112
|
+
const flattenedChildren = [];
|
|
113
|
+
function append(child) {
|
|
114
|
+
if (Array.isArray(child)) child.forEach(append);
|
|
115
|
+
else flattenedChildren.push(child);
|
|
116
|
+
}
|
|
117
|
+
append(children);
|
|
118
|
+
return flattenedChildren;
|
|
119
|
+
}
|
|
111
120
|
function parseChildren({ children, htmlElement, velesNode, portal }) {
|
|
112
121
|
const childComponents = [];
|
|
113
122
|
if (children === void 0 || children === null) return childComponents;
|
|
114
123
|
let lastInsertedNode = null;
|
|
115
|
-
(
|
|
124
|
+
flattenChildren(children).forEach((childComponent) => {
|
|
116
125
|
if (typeof childComponent === "string") {
|
|
117
126
|
const textNode = createTextElement(childComponent);
|
|
118
127
|
htmlElement.append(textNode.html);
|
|
@@ -169,6 +178,11 @@ function parseChildren({ children, htmlElement, velesNode, portal }) {
|
|
|
169
178
|
}
|
|
170
179
|
//#endregion
|
|
171
180
|
//#region src/attribute-utils.ts
|
|
181
|
+
const FORM_VALUE_TAGS = new Set([
|
|
182
|
+
"INPUT",
|
|
183
|
+
"TEXTAREA",
|
|
184
|
+
"SELECT"
|
|
185
|
+
]);
|
|
172
186
|
const ENUMERATED_BOOLEAN_ATTRIBUTES = {
|
|
173
187
|
draggable: {
|
|
174
188
|
trueValue: "true",
|
|
@@ -188,6 +202,19 @@ const ENUMERATED_BOOLEAN_ATTRIBUTES = {
|
|
|
188
202
|
}
|
|
189
203
|
};
|
|
190
204
|
function assignDomAttribute({ htmlElement, attributeName, value, previousValue }) {
|
|
205
|
+
const normalizedAttributeName = attributeName.toLowerCase();
|
|
206
|
+
if (normalizedAttributeName === "value" && isFormValueElement(htmlElement)) {
|
|
207
|
+
assignFormValueProperty(htmlElement, value);
|
|
208
|
+
return;
|
|
209
|
+
}
|
|
210
|
+
if (normalizedAttributeName === "checked" && htmlElement.tagName === "INPUT") {
|
|
211
|
+
assignBooleanProperty(htmlElement, "checked", value);
|
|
212
|
+
return;
|
|
213
|
+
}
|
|
214
|
+
if (normalizedAttributeName === "selected" && htmlElement.tagName === "OPTION") {
|
|
215
|
+
assignBooleanProperty(htmlElement, "selected", value);
|
|
216
|
+
return;
|
|
217
|
+
}
|
|
191
218
|
if (attributeName === "style") {
|
|
192
219
|
assignStyle({
|
|
193
220
|
value,
|
|
@@ -197,7 +224,7 @@ function assignDomAttribute({ htmlElement, attributeName, value, previousValue }
|
|
|
197
224
|
return;
|
|
198
225
|
}
|
|
199
226
|
if (typeof value === "boolean") {
|
|
200
|
-
const enumeratedConfig = ENUMERATED_BOOLEAN_ATTRIBUTES[
|
|
227
|
+
const enumeratedConfig = ENUMERATED_BOOLEAN_ATTRIBUTES[normalizedAttributeName];
|
|
201
228
|
if (enumeratedConfig) {
|
|
202
229
|
htmlElement.setAttribute(attributeName, value ? enumeratedConfig.trueValue : enumeratedConfig.falseValue);
|
|
203
230
|
return;
|
|
@@ -212,6 +239,25 @@ function assignDomAttribute({ htmlElement, attributeName, value, previousValue }
|
|
|
212
239
|
}
|
|
213
240
|
htmlElement.setAttribute(attributeName, value);
|
|
214
241
|
}
|
|
242
|
+
function isFormValueElement(htmlElement) {
|
|
243
|
+
return FORM_VALUE_TAGS.has(htmlElement.tagName);
|
|
244
|
+
}
|
|
245
|
+
function assignFormValueProperty(htmlElement, value) {
|
|
246
|
+
if (htmlElement.tagName === "SELECT" && Array.isArray(value)) {
|
|
247
|
+
const selectedValues = new Set(value.map(String));
|
|
248
|
+
Array.from(htmlElement.options).forEach((option) => {
|
|
249
|
+
const shouldSelect = selectedValues.has(option.value);
|
|
250
|
+
if (option.selected !== shouldSelect) option.selected = shouldSelect;
|
|
251
|
+
});
|
|
252
|
+
return;
|
|
253
|
+
}
|
|
254
|
+
const normalizedValue = value == null ? "" : String(value);
|
|
255
|
+
if (htmlElement.value !== normalizedValue) htmlElement.value = normalizedValue;
|
|
256
|
+
}
|
|
257
|
+
function assignBooleanProperty(htmlElement, propertyName, value) {
|
|
258
|
+
const normalizedValue = Boolean(value);
|
|
259
|
+
if (htmlElement[propertyName] !== normalizedValue) htmlElement[propertyName] = normalizedValue;
|
|
260
|
+
}
|
|
215
261
|
function assignStyle({ value, previousValue, htmlElement }) {
|
|
216
262
|
if (value == null) {
|
|
217
263
|
htmlElement.style.cssText = "";
|
|
@@ -108,11 +108,20 @@ function executeComponent({ element, props }) {
|
|
|
108
108
|
}
|
|
109
109
|
//#endregion
|
|
110
110
|
//#region src/create-element/parse-children.ts
|
|
111
|
+
function flattenChildren(children) {
|
|
112
|
+
const flattenedChildren = [];
|
|
113
|
+
function append(child) {
|
|
114
|
+
if (Array.isArray(child)) child.forEach(append);
|
|
115
|
+
else flattenedChildren.push(child);
|
|
116
|
+
}
|
|
117
|
+
append(children);
|
|
118
|
+
return flattenedChildren;
|
|
119
|
+
}
|
|
111
120
|
function parseChildren({ children, htmlElement, velesNode, portal }) {
|
|
112
121
|
const childComponents = [];
|
|
113
122
|
if (children === void 0 || children === null) return childComponents;
|
|
114
123
|
let lastInsertedNode = null;
|
|
115
|
-
(
|
|
124
|
+
flattenChildren(children).forEach((childComponent) => {
|
|
116
125
|
if (typeof childComponent === "string") {
|
|
117
126
|
const textNode = createTextElement(childComponent);
|
|
118
127
|
htmlElement.append(textNode.html);
|
|
@@ -169,6 +178,11 @@ function parseChildren({ children, htmlElement, velesNode, portal }) {
|
|
|
169
178
|
}
|
|
170
179
|
//#endregion
|
|
171
180
|
//#region src/attribute-utils.ts
|
|
181
|
+
const FORM_VALUE_TAGS = new Set([
|
|
182
|
+
"INPUT",
|
|
183
|
+
"TEXTAREA",
|
|
184
|
+
"SELECT"
|
|
185
|
+
]);
|
|
172
186
|
const ENUMERATED_BOOLEAN_ATTRIBUTES = {
|
|
173
187
|
draggable: {
|
|
174
188
|
trueValue: "true",
|
|
@@ -188,6 +202,19 @@ const ENUMERATED_BOOLEAN_ATTRIBUTES = {
|
|
|
188
202
|
}
|
|
189
203
|
};
|
|
190
204
|
function assignDomAttribute({ htmlElement, attributeName, value, previousValue }) {
|
|
205
|
+
const normalizedAttributeName = attributeName.toLowerCase();
|
|
206
|
+
if (normalizedAttributeName === "value" && isFormValueElement(htmlElement)) {
|
|
207
|
+
assignFormValueProperty(htmlElement, value);
|
|
208
|
+
return;
|
|
209
|
+
}
|
|
210
|
+
if (normalizedAttributeName === "checked" && htmlElement.tagName === "INPUT") {
|
|
211
|
+
assignBooleanProperty(htmlElement, "checked", value);
|
|
212
|
+
return;
|
|
213
|
+
}
|
|
214
|
+
if (normalizedAttributeName === "selected" && htmlElement.tagName === "OPTION") {
|
|
215
|
+
assignBooleanProperty(htmlElement, "selected", value);
|
|
216
|
+
return;
|
|
217
|
+
}
|
|
191
218
|
if (attributeName === "style") {
|
|
192
219
|
assignStyle({
|
|
193
220
|
value,
|
|
@@ -197,7 +224,7 @@ function assignDomAttribute({ htmlElement, attributeName, value, previousValue }
|
|
|
197
224
|
return;
|
|
198
225
|
}
|
|
199
226
|
if (typeof value === "boolean") {
|
|
200
|
-
const enumeratedConfig = ENUMERATED_BOOLEAN_ATTRIBUTES[
|
|
227
|
+
const enumeratedConfig = ENUMERATED_BOOLEAN_ATTRIBUTES[normalizedAttributeName];
|
|
201
228
|
if (enumeratedConfig) {
|
|
202
229
|
htmlElement.setAttribute(attributeName, value ? enumeratedConfig.trueValue : enumeratedConfig.falseValue);
|
|
203
230
|
return;
|
|
@@ -212,6 +239,25 @@ function assignDomAttribute({ htmlElement, attributeName, value, previousValue }
|
|
|
212
239
|
}
|
|
213
240
|
htmlElement.setAttribute(attributeName, value);
|
|
214
241
|
}
|
|
242
|
+
function isFormValueElement(htmlElement) {
|
|
243
|
+
return FORM_VALUE_TAGS.has(htmlElement.tagName);
|
|
244
|
+
}
|
|
245
|
+
function assignFormValueProperty(htmlElement, value) {
|
|
246
|
+
if (htmlElement.tagName === "SELECT" && Array.isArray(value)) {
|
|
247
|
+
const selectedValues = new Set(value.map(String));
|
|
248
|
+
Array.from(htmlElement.options).forEach((option) => {
|
|
249
|
+
const shouldSelect = selectedValues.has(option.value);
|
|
250
|
+
if (option.selected !== shouldSelect) option.selected = shouldSelect;
|
|
251
|
+
});
|
|
252
|
+
return;
|
|
253
|
+
}
|
|
254
|
+
const normalizedValue = value == null ? "" : String(value);
|
|
255
|
+
if (htmlElement.value !== normalizedValue) htmlElement.value = normalizedValue;
|
|
256
|
+
}
|
|
257
|
+
function assignBooleanProperty(htmlElement, propertyName, value) {
|
|
258
|
+
const normalizedValue = Boolean(value);
|
|
259
|
+
if (htmlElement[propertyName] !== normalizedValue) htmlElement[propertyName] = normalizedValue;
|
|
260
|
+
}
|
|
215
261
|
function assignStyle({ value, previousValue, htmlElement }) {
|
|
216
262
|
if (value == null) {
|
|
217
263
|
htmlElement.style.cssText = "";
|
package/dist/index.cjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
-
const require__utils = require("./_utils-
|
|
2
|
+
const require__utils = require("./_utils-DbrPydEE.cjs");
|
|
3
3
|
//#region src/attach-component.ts
|
|
4
4
|
/**
|
|
5
5
|
* Attach Veles component tree to a regular HTML node.
|
package/dist/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { _ as onMount, a as identity, c as addPublicContext, d as popPublicContext, f as Fragment, g as hasCurrentLifecycleContext, h as createTextElement, i as getMountedNodeExecutedVersion, l as createContext, m as assignDomAttribute, n as callUnmountHandlers, o as renderTree, p as createElement, r as getExecutedComponentVelesNode, s as unique, t as callMountHandlers, u as getCurrentContext, v as onUnmount } from "./_utils-
|
|
1
|
+
import { _ as onMount, a as identity, c as addPublicContext, d as popPublicContext, f as Fragment, g as hasCurrentLifecycleContext, h as createTextElement, i as getMountedNodeExecutedVersion, l as createContext, m as assignDomAttribute, n as callUnmountHandlers, o as renderTree, p as createElement, r as getExecutedComponentVelesNode, s as unique, t as callMountHandlers, u as getCurrentContext, v as onUnmount } from "./_utils-BnAXelPu.js";
|
|
2
2
|
//#region src/attach-component.ts
|
|
3
3
|
/**
|
|
4
4
|
* Attach Veles component tree to a regular HTML node.
|
package/dist/jsx-runtime.cjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
-
const require__utils = require("./_utils-
|
|
2
|
+
const require__utils = require("./_utils-DbrPydEE.cjs");
|
|
3
3
|
exports.Fragment = require__utils.Fragment;
|
|
4
4
|
exports.jsx = require__utils.createElement;
|
|
5
5
|
exports.jsxDEV = require__utils.createElement;
|
package/dist/jsx-runtime.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { f as Fragment, p as createElement } from "./_utils-
|
|
1
|
+
import { f as Fragment, p as createElement } from "./_utils-BnAXelPu.js";
|
|
2
2
|
export { Fragment, createElement as jsx, createElement as jsxDEV, createElement as jsxs };
|