@domql/utils 3.1.2 → 3.2.7
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.
- package/array.js +11 -5
- package/cache.js +3 -0
- package/component.js +3 -4
- package/dist/cjs/array.js +11 -5
- package/dist/cjs/component.js +4 -6
- package/dist/cjs/element.js +6 -6
- package/dist/cjs/env.js +1 -1
- package/dist/cjs/events.js +3 -3
- package/dist/cjs/extends.js +44 -28
- package/dist/cjs/function.js +3 -3
- package/dist/cjs/index.js +1 -0
- package/dist/cjs/key.js +2 -2
- package/dist/cjs/keys.js +29 -15
- package/dist/cjs/methods.js +88 -33
- package/dist/cjs/object.js +154 -141
- package/dist/cjs/props.js +43 -34
- package/dist/cjs/scope.js +1 -2
- package/dist/cjs/state.js +12 -11
- package/dist/cjs/string.js +15 -20
- package/dist/cjs/tags.js +71 -16
- package/dist/cjs/triggerEvent.js +90 -0
- package/dist/cjs/types.js +4 -12
- package/dist/esm/array.js +11 -5
- package/dist/esm/component.js +4 -6
- package/dist/esm/element.js +9 -27
- package/dist/esm/env.js +1 -1
- package/dist/esm/events.js +3 -3
- package/dist/esm/extends.js +48 -50
- package/dist/esm/function.js +3 -3
- package/dist/esm/index.js +1 -0
- package/dist/esm/key.js +2 -2
- package/dist/esm/keys.js +29 -15
- package/dist/esm/methods.js +86 -31
- package/dist/esm/object.js +158 -165
- package/dist/esm/props.js +43 -50
- package/dist/esm/scope.js +1 -2
- package/dist/esm/state.js +21 -38
- package/dist/esm/string.js +15 -20
- package/dist/esm/tags.js +71 -16
- package/dist/esm/triggerEvent.js +70 -0
- package/dist/esm/types.js +4 -12
- package/dist/iife/index.js +2779 -0
- package/element.js +2 -2
- package/events.js +3 -3
- package/extends.js +28 -17
- package/function.js +10 -9
- package/index.js +1 -0
- package/keys.js +25 -15
- package/log.js +0 -1
- package/methods.js +99 -24
- package/object.js +155 -215
- package/package.json +34 -13
- package/props.js +44 -27
- package/state.js +12 -12
- package/string.js +20 -38
- package/tags.js +45 -16
- package/triggerEvent.js +76 -0
- package/types.js +8 -25
- package/dist/cjs/package.json +0 -4
package/dist/cjs/props.js
CHANGED
|
@@ -40,6 +40,9 @@ var import_keys = require("./keys.js");
|
|
|
40
40
|
var import_events = require("./events.js");
|
|
41
41
|
var import_object = require("./object.js");
|
|
42
42
|
var import_types = require("./types.js");
|
|
43
|
+
var import_string = require("./string.js");
|
|
44
|
+
const RE_UPPER = /^[A-Z]/;
|
|
45
|
+
const RE_DIGITS = /^\d+$/;
|
|
43
46
|
const createProps = (element, parent, key) => {
|
|
44
47
|
const { props, __ref: ref } = element;
|
|
45
48
|
ref.__propsStack = [];
|
|
@@ -52,14 +55,20 @@ const createProps = (element, parent, key) => {
|
|
|
52
55
|
return { ...props };
|
|
53
56
|
};
|
|
54
57
|
function pickupPropsFromElement(obj, opts = {}) {
|
|
55
|
-
var _a, _b, _c;
|
|
56
58
|
const cachedKeys = opts.cachedKeys || [];
|
|
57
59
|
for (const key in obj) {
|
|
58
60
|
const value = obj[key];
|
|
59
|
-
const
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
61
|
+
const isEventHandler = key.length > 2 && key.charCodeAt(0) === 111 && key.charCodeAt(1) === 110 && key[2] === key[2].toUpperCase() && (0, import_types.isFunction)(value);
|
|
62
|
+
if (isEventHandler) {
|
|
63
|
+
const eventName = (0, import_string.lowercaseFirstLetter)(key.slice(2));
|
|
64
|
+
if (obj.on) obj.on[eventName] = value;
|
|
65
|
+
delete obj[key];
|
|
66
|
+
continue;
|
|
67
|
+
}
|
|
68
|
+
const hasDefine = (0, import_types.isObject)(this.define?.[key]);
|
|
69
|
+
const hasGlobalDefine = (0, import_types.isObject)(this.context?.define?.[key]);
|
|
70
|
+
const isElement = RE_UPPER.test(key) || RE_DIGITS.test(key);
|
|
71
|
+
const isBuiltin = import_keys.DOMQ_PROPERTIES.has(key);
|
|
63
72
|
if (!isElement && !isBuiltin && !hasDefine && !hasGlobalDefine) {
|
|
64
73
|
obj.props[key] = value;
|
|
65
74
|
delete obj[key];
|
|
@@ -69,11 +78,10 @@ function pickupPropsFromElement(obj, opts = {}) {
|
|
|
69
78
|
return obj;
|
|
70
79
|
}
|
|
71
80
|
function pickupElementFromProps(obj = this, opts) {
|
|
72
|
-
var _a, _b, _c;
|
|
73
81
|
const cachedKeys = opts.cachedKeys || [];
|
|
74
82
|
for (const key in obj.props) {
|
|
75
83
|
const value = obj.props[key];
|
|
76
|
-
const isEvent = key.
|
|
84
|
+
const isEvent = key.length > 2 && key.charCodeAt(0) === 111 && key.charCodeAt(1) === 110;
|
|
77
85
|
const isFn = (0, import_types.isFunction)(value);
|
|
78
86
|
if (isEvent && isFn) {
|
|
79
87
|
(0, import_events.addEventFromProps)(key, obj);
|
|
@@ -81,13 +89,15 @@ function pickupElementFromProps(obj = this, opts) {
|
|
|
81
89
|
continue;
|
|
82
90
|
}
|
|
83
91
|
if (cachedKeys.includes(key)) continue;
|
|
84
|
-
const hasDefine = (0, import_types.isObject)(
|
|
85
|
-
const hasGlobalDefine = (0, import_types.isObject)(
|
|
86
|
-
const isElement =
|
|
87
|
-
const isBuiltin = import_keys.DOMQ_PROPERTIES.
|
|
92
|
+
const hasDefine = (0, import_types.isObject)(this.define?.[key]);
|
|
93
|
+
const hasGlobalDefine = (0, import_types.isObject)(this.context?.define?.[key]);
|
|
94
|
+
const isElement = RE_UPPER.test(key) || RE_DIGITS.test(key);
|
|
95
|
+
const isBuiltin = import_keys.DOMQ_PROPERTIES.has(key);
|
|
88
96
|
if (isElement || isBuiltin || hasDefine || hasGlobalDefine) {
|
|
89
|
-
obj[key]
|
|
90
|
-
|
|
97
|
+
if (obj[key] === void 0 || value === null) {
|
|
98
|
+
obj[key] = value;
|
|
99
|
+
if (obj.props) delete obj.props[key];
|
|
100
|
+
}
|
|
91
101
|
}
|
|
92
102
|
}
|
|
93
103
|
return obj;
|
|
@@ -99,8 +109,9 @@ function propertizeElement(element = this) {
|
|
|
99
109
|
return element;
|
|
100
110
|
}
|
|
101
111
|
function propertizeUpdate(params = {}) {
|
|
102
|
-
|
|
103
|
-
|
|
112
|
+
if (!params.on) params.on = {};
|
|
113
|
+
if (!params.props) params.props = {};
|
|
114
|
+
return propertizeElement.call(this, params);
|
|
104
115
|
}
|
|
105
116
|
const objectizeStringProperty = (propValue) => {
|
|
106
117
|
if ((0, import_types.is)(propValue)("string", "number")) {
|
|
@@ -110,21 +121,16 @@ const objectizeStringProperty = (propValue) => {
|
|
|
110
121
|
};
|
|
111
122
|
const propExists = (prop, stack) => {
|
|
112
123
|
if (!prop || !stack.length) return false;
|
|
113
|
-
|
|
114
|
-
return stack.some((existing) => {
|
|
115
|
-
const existingKey = (0, import_types.isObject)(existing) ? JSON.stringify(existing) : existing;
|
|
116
|
-
return existingKey === key;
|
|
117
|
-
});
|
|
124
|
+
return stack.includes(prop);
|
|
118
125
|
};
|
|
119
126
|
const inheritParentProps = (element, parent) => {
|
|
120
|
-
var _a;
|
|
121
127
|
const { __ref: ref } = element;
|
|
122
128
|
const propsStack = ref.__propsStack || [];
|
|
123
129
|
const parentProps = parent.props;
|
|
124
130
|
if (!parentProps) return propsStack;
|
|
125
131
|
const matchParentKeyProps = parentProps[element.key];
|
|
126
132
|
const matchParentChildProps = parentProps.childProps;
|
|
127
|
-
const ignoreChildProps =
|
|
133
|
+
const ignoreChildProps = element.props?.ignoreChildProps;
|
|
128
134
|
if (matchParentChildProps && !ignoreChildProps) {
|
|
129
135
|
const childProps = objectizeStringProperty(matchParentChildProps);
|
|
130
136
|
propsStack.unshift(childProps);
|
|
@@ -135,9 +141,9 @@ const inheritParentProps = (element, parent) => {
|
|
|
135
141
|
}
|
|
136
142
|
return propsStack;
|
|
137
143
|
};
|
|
138
|
-
|
|
144
|
+
function update(props, options) {
|
|
139
145
|
const element = this.__element;
|
|
140
|
-
|
|
146
|
+
element.update({ props }, options);
|
|
141
147
|
}
|
|
142
148
|
function setPropsPrototype(element) {
|
|
143
149
|
const methods = { update: update.bind(element.props), __element: element };
|
|
@@ -146,16 +152,15 @@ function setPropsPrototype(element) {
|
|
|
146
152
|
const removeDuplicateProps = (propsStack) => {
|
|
147
153
|
const seen = /* @__PURE__ */ new Set();
|
|
148
154
|
return propsStack.filter((prop) => {
|
|
149
|
-
if (!prop || import_keys.PROPS_METHODS.
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
seen.add(key);
|
|
155
|
+
if (!prop || import_keys.PROPS_METHODS.has(prop)) return false;
|
|
156
|
+
if (seen.has(prop)) return false;
|
|
157
|
+
seen.add(prop);
|
|
153
158
|
return true;
|
|
154
159
|
});
|
|
155
160
|
};
|
|
156
161
|
const syncProps = (propsStack, element, opts) => {
|
|
157
162
|
element.props = propsStack.reduce((mergedProps, v) => {
|
|
158
|
-
if (import_keys.PROPS_METHODS.
|
|
163
|
+
if (import_keys.PROPS_METHODS.has(v)) return mergedProps;
|
|
159
164
|
while ((0, import_types.isFunction)(v)) v = (0, import_object.exec)(v, element);
|
|
160
165
|
return (0, import_object.deepMerge)(mergedProps, (0, import_object.deepClone)(v, { exclude: import_keys.PROPS_METHODS }));
|
|
161
166
|
}, {});
|
|
@@ -165,19 +170,20 @@ const syncProps = (propsStack, element, opts) => {
|
|
|
165
170
|
const createPropsStack = (element, parent) => {
|
|
166
171
|
const { props, __ref: ref } = element;
|
|
167
172
|
let propsStack = ref.__propsStack || [];
|
|
168
|
-
if (parent
|
|
173
|
+
if (parent?.props) {
|
|
169
174
|
const parentStack = inheritParentProps(element, parent);
|
|
170
175
|
propsStack = [...parentStack];
|
|
171
176
|
}
|
|
172
177
|
if ((0, import_types.isObject)(props)) propsStack.push(props);
|
|
173
|
-
else if (props === "inherit" &&
|
|
178
|
+
else if (props === "inherit" && parent?.props) propsStack.push(parent.props);
|
|
174
179
|
else if (props) propsStack.push(props);
|
|
175
180
|
if ((0, import_types.isArray)(ref.__extendsStack)) {
|
|
176
|
-
ref.__extendsStack.
|
|
181
|
+
for (let i = 0; i < ref.__extendsStack.length; i++) {
|
|
182
|
+
const _extends = ref.__extendsStack[i];
|
|
177
183
|
if (_extends.props && _extends.props !== props) {
|
|
178
184
|
propsStack.push(_extends.props);
|
|
179
185
|
}
|
|
180
|
-
}
|
|
186
|
+
}
|
|
181
187
|
}
|
|
182
188
|
ref.__propsStack = removeDuplicateProps(propsStack);
|
|
183
189
|
return ref.__propsStack;
|
|
@@ -198,7 +204,10 @@ const initProps = function(element, parent, options) {
|
|
|
198
204
|
else {
|
|
199
205
|
try {
|
|
200
206
|
applyProps(element, parent);
|
|
201
|
-
} catch {
|
|
207
|
+
} catch (e) {
|
|
208
|
+
if (element.context?.designSystem?.verbose) {
|
|
209
|
+
console.warn("initProps error at", ref.path?.join("."), e);
|
|
210
|
+
}
|
|
202
211
|
element.props = {};
|
|
203
212
|
ref.__propsStack = [];
|
|
204
213
|
}
|
package/dist/cjs/scope.js
CHANGED
|
@@ -22,7 +22,6 @@ __export(scope_exports, {
|
|
|
22
22
|
});
|
|
23
23
|
module.exports = __toCommonJS(scope_exports);
|
|
24
24
|
const createScope = (element, parent) => {
|
|
25
|
-
var _a;
|
|
26
25
|
const { __ref: ref } = element;
|
|
27
|
-
if (!element.scope) element.scope = parent.scope ||
|
|
26
|
+
if (!element.scope) element.scope = parent.scope || ref.root?.scope || {};
|
|
28
27
|
};
|
package/dist/cjs/state.js
CHANGED
|
@@ -35,12 +35,12 @@ var import_array = require("./array.js");
|
|
|
35
35
|
var import_keys = require("./keys.js");
|
|
36
36
|
var import_object = require("./object.js");
|
|
37
37
|
var import_types = require("./types.js");
|
|
38
|
-
const checkForStateTypes =
|
|
38
|
+
const checkForStateTypes = (element) => {
|
|
39
39
|
const { state: orig, props, __ref: ref } = element;
|
|
40
|
-
const state =
|
|
40
|
+
const state = props?.state || orig;
|
|
41
41
|
if ((0, import_types.isFunction)(state)) {
|
|
42
42
|
ref.__state = state;
|
|
43
|
-
return
|
|
43
|
+
return (0, import_object.exec)(state, element);
|
|
44
44
|
} else if ((0, import_types.is)(state)("string", "number")) {
|
|
45
45
|
ref.__state = state;
|
|
46
46
|
return { value: state };
|
|
@@ -107,7 +107,7 @@ const findInheritedState = (element, parent, options = {}) => {
|
|
|
107
107
|
const createInheritedState = (element, parent) => {
|
|
108
108
|
const ref = element.__ref;
|
|
109
109
|
const inheritedState = findInheritedState(element, parent);
|
|
110
|
-
if (
|
|
110
|
+
if (inheritedState === void 0) return element.state;
|
|
111
111
|
if ((0, import_types.is)(inheritedState)("object", "array")) {
|
|
112
112
|
return (0, import_object.deepClone)(inheritedState);
|
|
113
113
|
} else if ((0, import_types.is)(inheritedState)("string", "number", "boolean")) {
|
|
@@ -118,7 +118,7 @@ const createInheritedState = (element, parent) => {
|
|
|
118
118
|
};
|
|
119
119
|
const checkIfInherits = (element) => {
|
|
120
120
|
const { __ref: ref } = element;
|
|
121
|
-
const stateKey = ref
|
|
121
|
+
const stateKey = ref?.__state;
|
|
122
122
|
if (stateKey && (0, import_types.is)(stateKey)("number", "string", "boolean")) return true;
|
|
123
123
|
return false;
|
|
124
124
|
};
|
|
@@ -135,15 +135,16 @@ const createNestedObjectByKeyPath = (path, value) => {
|
|
|
135
135
|
const keys = path.split("/");
|
|
136
136
|
const obj = {};
|
|
137
137
|
let ref = obj;
|
|
138
|
-
keys.
|
|
139
|
-
|
|
140
|
-
ref =
|
|
141
|
-
|
|
138
|
+
const lastIdx = keys.length - 1;
|
|
139
|
+
for (let i = 0; i <= lastIdx; i++) {
|
|
140
|
+
ref[keys[i]] = i === lastIdx ? value || {} : {};
|
|
141
|
+
ref = ref[keys[i]];
|
|
142
|
+
}
|
|
142
143
|
return obj;
|
|
143
144
|
};
|
|
144
|
-
const applyDependentState =
|
|
145
|
+
const applyDependentState = (element, state) => {
|
|
145
146
|
const { __element } = state;
|
|
146
|
-
const origState =
|
|
147
|
+
const origState = (0, import_object.exec)(__element?.state, element);
|
|
147
148
|
if (!origState) return;
|
|
148
149
|
const dependentState = (0, import_object.deepClone)(origState, import_keys.STATE_METHODS);
|
|
149
150
|
const newDepends = { [element.key]: dependentState };
|
package/dist/cjs/string.js
CHANGED
|
@@ -48,15 +48,15 @@ const brackRegex = {
|
|
|
48
48
|
};
|
|
49
49
|
const getNestedValue = (obj, path) => {
|
|
50
50
|
return path.split(".").reduce((acc, part) => {
|
|
51
|
-
return acc
|
|
51
|
+
return acc?.[part];
|
|
52
52
|
}, obj);
|
|
53
53
|
};
|
|
54
|
-
function replaceLiteralsWithObjectFields(str, state
|
|
54
|
+
function replaceLiteralsWithObjectFields(str, state, options = {}) {
|
|
55
55
|
const { bracketsLength = 2 } = options;
|
|
56
56
|
const bracketPattern = bracketsLength === 3 ? "{{{" : "{{";
|
|
57
57
|
if (!str.includes(bracketPattern)) return str;
|
|
58
58
|
const reg = brackRegex[bracketsLength];
|
|
59
|
-
const obj = state || {};
|
|
59
|
+
const obj = state || this.state || {};
|
|
60
60
|
return str.replace(reg, (_, parentPath, variable) => {
|
|
61
61
|
if (parentPath) {
|
|
62
62
|
const parentLevels = (parentPath.match(/\.\.\//g) || []).length;
|
|
@@ -67,13 +67,13 @@ function replaceLiteralsWithObjectFields(str, state = {}, options = {}) {
|
|
|
67
67
|
}
|
|
68
68
|
const key = variable.trim();
|
|
69
69
|
if (key === "parent") {
|
|
70
|
-
return
|
|
70
|
+
return String(parentState.value ?? "");
|
|
71
71
|
}
|
|
72
72
|
const value = getNestedValue(parentState, key);
|
|
73
|
-
return
|
|
73
|
+
return String(value ?? "");
|
|
74
74
|
} else {
|
|
75
75
|
const value = getNestedValue(obj, variable.trim());
|
|
76
|
-
return
|
|
76
|
+
return String(value ?? "");
|
|
77
77
|
}
|
|
78
78
|
});
|
|
79
79
|
}
|
|
@@ -126,27 +126,22 @@ const findKeyPosition = (str, key) => {
|
|
|
126
126
|
endLineNumber
|
|
127
127
|
};
|
|
128
128
|
};
|
|
129
|
+
const RE_OCTAL = /\\([0-7]{1,3})/g;
|
|
129
130
|
const replaceOctalEscapeSequences = (str) => {
|
|
130
|
-
|
|
131
|
-
return str.replace(octalRegex, (match, p1) => {
|
|
132
|
-
const octalValue = parseInt(p1, 8);
|
|
133
|
-
const char = String.fromCharCode(octalValue);
|
|
134
|
-
return char;
|
|
135
|
-
});
|
|
131
|
+
return str.replace(RE_OCTAL, (_, p1) => String.fromCharCode(parseInt(p1, 8)));
|
|
136
132
|
};
|
|
137
133
|
const encodeNewlines = (str) => {
|
|
138
|
-
return str.
|
|
134
|
+
return str.replace(/\n/g, "/////n").replace(/`/g, "/////tilde").replace(/\$/g, "/////dlrsgn");
|
|
139
135
|
};
|
|
140
136
|
const decodeNewlines = (encodedStr) => {
|
|
141
|
-
return encodedStr.
|
|
137
|
+
return encodedStr.replace(/\/\/\/\/\/n/g, "\n").replace(/\/\/\/\/\/tilde/g, "`").replace(/\/\/\/\/\/dlrsgn/g, "$");
|
|
142
138
|
};
|
|
139
|
+
const RE_NON_ALNUM = /[^a-zA-Z0-9\s]/g;
|
|
143
140
|
const customEncodeURIComponent = (str) => {
|
|
144
|
-
return str.
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
return char;
|
|
149
|
-
}).join("");
|
|
141
|
+
return str.replace(
|
|
142
|
+
RE_NON_ALNUM,
|
|
143
|
+
(char) => "%" + char.charCodeAt(0).toString(16).toUpperCase()
|
|
144
|
+
);
|
|
150
145
|
};
|
|
151
146
|
const customDecodeURIComponent = (encodedStr) => {
|
|
152
147
|
return encodedStr.replace(
|
package/dist/cjs/tags.js
CHANGED
|
@@ -19,23 +19,14 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
19
19
|
var tags_exports = {};
|
|
20
20
|
__export(tags_exports, {
|
|
21
21
|
HTML_TAGS: () => HTML_TAGS,
|
|
22
|
+
SVG_TAGS: () => SVG_TAGS,
|
|
22
23
|
isValidHtmlTag: () => isValidHtmlTag
|
|
23
24
|
});
|
|
24
25
|
module.exports = __toCommonJS(tags_exports);
|
|
25
26
|
const HTML_TAGS = {
|
|
26
|
-
root: [
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
],
|
|
30
|
-
head: [
|
|
31
|
-
"title",
|
|
32
|
-
"base",
|
|
33
|
-
"meta",
|
|
34
|
-
"style",
|
|
35
|
-
"noscript",
|
|
36
|
-
"script"
|
|
37
|
-
],
|
|
38
|
-
body: [
|
|
27
|
+
root: ["body", "html"],
|
|
28
|
+
head: ["title", "base", "meta", "style", "noscript", "script"],
|
|
29
|
+
body: /* @__PURE__ */ new Set([
|
|
39
30
|
"string",
|
|
40
31
|
"style",
|
|
41
32
|
"fragment",
|
|
@@ -159,7 +150,71 @@ const HTML_TAGS = {
|
|
|
159
150
|
"wbr",
|
|
160
151
|
// SVG
|
|
161
152
|
"svg",
|
|
162
|
-
"path"
|
|
163
|
-
|
|
153
|
+
"path",
|
|
154
|
+
"circle",
|
|
155
|
+
"ellipse",
|
|
156
|
+
"line",
|
|
157
|
+
"polygon",
|
|
158
|
+
"polyline",
|
|
159
|
+
"rect",
|
|
160
|
+
"g",
|
|
161
|
+
"defs",
|
|
162
|
+
"symbol",
|
|
163
|
+
"use",
|
|
164
|
+
"text",
|
|
165
|
+
"tspan",
|
|
166
|
+
"image",
|
|
167
|
+
"clipPath",
|
|
168
|
+
"mask",
|
|
169
|
+
"pattern",
|
|
170
|
+
"marker",
|
|
171
|
+
"linearGradient",
|
|
172
|
+
"radialGradient",
|
|
173
|
+
"stop",
|
|
174
|
+
"filter",
|
|
175
|
+
"feGaussianBlur",
|
|
176
|
+
"feOffset",
|
|
177
|
+
"feMerge",
|
|
178
|
+
"feMergeNode",
|
|
179
|
+
"feBlend",
|
|
180
|
+
"feColorMatrix",
|
|
181
|
+
"feFlood",
|
|
182
|
+
"feComposite",
|
|
183
|
+
"foreignObject"
|
|
184
|
+
])
|
|
164
185
|
};
|
|
165
|
-
const
|
|
186
|
+
const SVG_TAGS = /* @__PURE__ */ new Set([
|
|
187
|
+
"svg",
|
|
188
|
+
"path",
|
|
189
|
+
"circle",
|
|
190
|
+
"ellipse",
|
|
191
|
+
"line",
|
|
192
|
+
"polygon",
|
|
193
|
+
"polyline",
|
|
194
|
+
"rect",
|
|
195
|
+
"g",
|
|
196
|
+
"defs",
|
|
197
|
+
"symbol",
|
|
198
|
+
"use",
|
|
199
|
+
"text",
|
|
200
|
+
"tspan",
|
|
201
|
+
"image",
|
|
202
|
+
"clipPath",
|
|
203
|
+
"mask",
|
|
204
|
+
"pattern",
|
|
205
|
+
"marker",
|
|
206
|
+
"linearGradient",
|
|
207
|
+
"radialGradient",
|
|
208
|
+
"stop",
|
|
209
|
+
"filter",
|
|
210
|
+
"feGaussianBlur",
|
|
211
|
+
"feOffset",
|
|
212
|
+
"feMerge",
|
|
213
|
+
"feMergeNode",
|
|
214
|
+
"feBlend",
|
|
215
|
+
"feColorMatrix",
|
|
216
|
+
"feFlood",
|
|
217
|
+
"feComposite",
|
|
218
|
+
"foreignObject"
|
|
219
|
+
]);
|
|
220
|
+
const isValidHtmlTag = (arg) => HTML_TAGS.body.has(arg);
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
var triggerEvent_exports = {};
|
|
20
|
+
__export(triggerEvent_exports, {
|
|
21
|
+
applyEvent: () => applyEvent,
|
|
22
|
+
applyEventUpdate: () => applyEventUpdate,
|
|
23
|
+
triggerEventOn: () => triggerEventOn,
|
|
24
|
+
triggerEventOnUpdate: () => triggerEventOnUpdate
|
|
25
|
+
});
|
|
26
|
+
module.exports = __toCommonJS(triggerEvent_exports);
|
|
27
|
+
var import_types = require("./types.js");
|
|
28
|
+
const getOnOrPropsEvent = (param, element) => {
|
|
29
|
+
const onEvent = element.on?.[param];
|
|
30
|
+
if (onEvent) return onEvent;
|
|
31
|
+
const props = element.props;
|
|
32
|
+
if (!props) return;
|
|
33
|
+
const propKey = "on" + param.charAt(0).toUpperCase() + param.slice(1);
|
|
34
|
+
return props[propKey];
|
|
35
|
+
};
|
|
36
|
+
const applyEvent = (param, element, state, context, options) => {
|
|
37
|
+
if (!(0, import_types.isFunction)(param)) return;
|
|
38
|
+
const result = param.call(
|
|
39
|
+
element,
|
|
40
|
+
element,
|
|
41
|
+
state || element.state,
|
|
42
|
+
context || element.context,
|
|
43
|
+
options
|
|
44
|
+
);
|
|
45
|
+
if (result && typeof result.then === "function") {
|
|
46
|
+
result.catch(() => {
|
|
47
|
+
});
|
|
48
|
+
}
|
|
49
|
+
return result;
|
|
50
|
+
};
|
|
51
|
+
const triggerEventOn = (param, element, options) => {
|
|
52
|
+
if (!element) {
|
|
53
|
+
throw new Error("Element is required");
|
|
54
|
+
}
|
|
55
|
+
const appliedFunction = getOnOrPropsEvent(param, element);
|
|
56
|
+
if (appliedFunction) {
|
|
57
|
+
const { state, context } = element;
|
|
58
|
+
return applyEvent(appliedFunction, element, state, context, options);
|
|
59
|
+
}
|
|
60
|
+
};
|
|
61
|
+
const applyEventUpdate = (param, updatedObj, element, state, context, options) => {
|
|
62
|
+
if (!(0, import_types.isFunction)(param)) return;
|
|
63
|
+
const result = param.call(
|
|
64
|
+
element,
|
|
65
|
+
updatedObj,
|
|
66
|
+
element,
|
|
67
|
+
state || element.state,
|
|
68
|
+
context || element.context,
|
|
69
|
+
options
|
|
70
|
+
);
|
|
71
|
+
if (result && typeof result.then === "function") {
|
|
72
|
+
result.catch(() => {
|
|
73
|
+
});
|
|
74
|
+
}
|
|
75
|
+
return result;
|
|
76
|
+
};
|
|
77
|
+
const triggerEventOnUpdate = (param, updatedObj, element, options) => {
|
|
78
|
+
const appliedFunction = getOnOrPropsEvent(param, element);
|
|
79
|
+
if (appliedFunction) {
|
|
80
|
+
const { state, context } = element;
|
|
81
|
+
return applyEventUpdate(
|
|
82
|
+
appliedFunction,
|
|
83
|
+
updatedObj,
|
|
84
|
+
element,
|
|
85
|
+
state,
|
|
86
|
+
context,
|
|
87
|
+
options
|
|
88
|
+
);
|
|
89
|
+
}
|
|
90
|
+
};
|
package/dist/cjs/types.js
CHANGED
|
@@ -50,12 +50,8 @@ const isObjectLike = (arg) => {
|
|
|
50
50
|
if (arg === null) return false;
|
|
51
51
|
return typeof arg === "object";
|
|
52
52
|
};
|
|
53
|
-
const isDefined = (arg) =>
|
|
54
|
-
|
|
55
|
-
};
|
|
56
|
-
const isUndefined = (arg) => {
|
|
57
|
-
return arg === void 0;
|
|
58
|
-
};
|
|
53
|
+
const isDefined = (arg) => arg !== void 0;
|
|
54
|
+
const isUndefined = (arg) => arg === void 0;
|
|
59
55
|
const TYPES = {
|
|
60
56
|
boolean: isBoolean,
|
|
61
57
|
array: isArray,
|
|
@@ -71,12 +67,8 @@ const TYPES = {
|
|
|
71
67
|
defined: isDefined
|
|
72
68
|
};
|
|
73
69
|
const is = (arg) => {
|
|
74
|
-
return (...args) =>
|
|
75
|
-
return args.map((val) => TYPES[val](arg)).filter((v) => v).length > 0;
|
|
76
|
-
};
|
|
70
|
+
return (...args) => args.some((val) => TYPES[val](arg));
|
|
77
71
|
};
|
|
78
72
|
const isNot = (arg) => {
|
|
79
|
-
return (...args) =>
|
|
80
|
-
return args.map((val) => TYPES[val](arg)).filter((v) => v).length === 0;
|
|
81
|
-
};
|
|
73
|
+
return (...args) => !args.some((val) => TYPES[val](arg));
|
|
82
74
|
};
|
package/dist/esm/array.js
CHANGED
|
@@ -4,9 +4,11 @@ const arrayContainsOtherArray = (arr1, arr2) => {
|
|
|
4
4
|
return arr2.every((val) => arr1.includes(val));
|
|
5
5
|
};
|
|
6
6
|
const getFrequencyInArray = (arr, value) => {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
7
|
+
let count = 0;
|
|
8
|
+
for (let i = 0; i < arr.length; i++) {
|
|
9
|
+
if (arr[i] === value) count++;
|
|
10
|
+
}
|
|
11
|
+
return count;
|
|
10
12
|
};
|
|
11
13
|
const removeFromArray = (arr, index) => {
|
|
12
14
|
if (isString(index)) index = parseInt(index);
|
|
@@ -100,8 +102,12 @@ const filterArraysFast = (sourceArr, excludeArr) => {
|
|
|
100
102
|
return sourceArr.filter((item) => !excludeSet.has(item));
|
|
101
103
|
};
|
|
102
104
|
const checkIfStringIsInArray = (string, arr) => {
|
|
103
|
-
if (!string) return;
|
|
104
|
-
|
|
105
|
+
if (!string) return 0;
|
|
106
|
+
let count = 0;
|
|
107
|
+
for (let i = 0; i < arr.length; i++) {
|
|
108
|
+
if (string.includes(arr[i])) count++;
|
|
109
|
+
}
|
|
110
|
+
return count;
|
|
105
111
|
};
|
|
106
112
|
const removeDuplicatesInArray = (arr) => {
|
|
107
113
|
if (!isArray(arr)) return arr;
|
package/dist/esm/component.js
CHANGED
|
@@ -1,10 +1,9 @@
|
|
|
1
1
|
import { createExtendsFromKeys } from "./extends.js";
|
|
2
2
|
import { isString } from "./types.js";
|
|
3
3
|
const matchesComponentNaming = (key) => {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
return /^[A-Z]*$/.test(firstCharKey);
|
|
4
|
+
if (!isString(key) || !key.length) return false;
|
|
5
|
+
const code = key.charCodeAt(0);
|
|
6
|
+
return code >= 65 && code <= 90;
|
|
8
7
|
};
|
|
9
8
|
function getCapitalCaseKeys(obj) {
|
|
10
9
|
return Object.keys(obj).filter((key) => /^[A-Z]/.test(key));
|
|
@@ -13,11 +12,10 @@ function getSpreadChildren(obj) {
|
|
|
13
12
|
return Object.keys(obj).filter((key) => /^\d+$/.test(key));
|
|
14
13
|
}
|
|
15
14
|
function isContextComponent(element, parent, passedKey) {
|
|
16
|
-
var _a, _b;
|
|
17
15
|
const { context } = parent || {};
|
|
18
16
|
const [extendsKey] = createExtendsFromKeys(passedKey);
|
|
19
17
|
const key = passedKey || extendsKey;
|
|
20
|
-
return
|
|
18
|
+
return context?.components?.[key] || context?.pages?.[key];
|
|
21
19
|
}
|
|
22
20
|
export {
|
|
23
21
|
getCapitalCaseKeys,
|