@lvce-editor/renderer-process 24.8.0 → 25.0.0
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/dist/rendererProcessMain.js +73 -71
- package/package.json +1 -1
|
@@ -3898,8 +3898,6 @@ const ElementActions = {
|
|
|
3898
3898
|
type
|
|
3899
3899
|
};
|
|
3900
3900
|
|
|
3901
|
-
const htmlElements = ['a', 'abbr', 'address', 'area', 'article', 'aside', 'audio', 'b', 'base', 'bdo', 'body', 'br', 'button', 'canvas', 'caption', 'center', 'cite', 'code', 'col', 'colgroup', 'command', 'datalist', 'dd', 'del', 'details', 'dfn', 'dialog', 'div', 'dl', 'dt', 'em', 'embed', 'fieldset', 'figcaption', 'figure', 'footer', 'form', 'h1', 'h2', 'h3', 'h4', 'h5', 'h6', 'head', 'hr', 'html', 'i', 'iframe', 'img', 'input', 'ins', 'kbd', 'label', 'legend', 'li', 'link', 'map', 'mark', 'menu', 'meta', 'meter', 'nav', 'noscript', 'object', 'ol', 'optgroup', 'option', 'output', 'p', 'param', 'pre', 'progress', 'q', 'rp', 'rt', 's', 'samp', 'script', 'section', 'select', 'small', 'source', 'span', 'strong', 'sub', 'sup', 'table', 'tbody', 'td', 'textarea', 'tfoot', 'th', 'thead', 'time', 'title', 'tr', 'track', 'u', 'ul', 'var', 'video', 'wbr'];
|
|
3902
|
-
|
|
3903
3901
|
const querySelectorByText = (root, text) => {
|
|
3904
3902
|
let node;
|
|
3905
3903
|
const elements = [];
|
|
@@ -3916,47 +3914,73 @@ const querySelectorByCss = selector => {
|
|
|
3916
3914
|
// @ts-ignore
|
|
3917
3915
|
return [...document.querySelectorAll(selector)];
|
|
3918
3916
|
};
|
|
3919
|
-
const
|
|
3920
|
-
|
|
3921
|
-
};
|
|
3922
|
-
const querySelector = selector => {
|
|
3923
|
-
if (typeof selector !== 'string') {
|
|
3924
|
-
throw new TypeError('selector must be of type string');
|
|
3925
|
-
}
|
|
3926
|
-
if (selector.startsWith('text=')) {
|
|
3927
|
-
return querySelectorByText(document.body, selector.slice('text='.length));
|
|
3928
|
-
}
|
|
3929
|
-
if (selector.includes('text=')) {
|
|
3930
|
-
const index = selector.indexOf('text=');
|
|
3931
|
-
const elements = querySelectorByCss(selector.slice(0, index));
|
|
3932
|
-
const text = selector.slice(index + 'text='.length);
|
|
3933
|
-
return elements.flatMap(element => {
|
|
3934
|
-
return querySelectorByText(element, text);
|
|
3935
|
-
});
|
|
3936
|
-
// for(const element of elements)
|
|
3937
|
-
}
|
|
3938
|
-
if (selector.startsWith('.')) {
|
|
3917
|
+
const querySelectorByCssFromRoot = (root, selector) => {
|
|
3918
|
+
if (root === document.body) {
|
|
3939
3919
|
return querySelectorByCss(selector);
|
|
3940
3920
|
}
|
|
3941
|
-
|
|
3942
|
-
|
|
3921
|
+
// @ts-ignore
|
|
3922
|
+
return [...root.querySelectorAll(selector)];
|
|
3923
|
+
};
|
|
3924
|
+
const selectorToString = parsedSelector => {
|
|
3925
|
+
let result = '';
|
|
3926
|
+
for (const part of parsedSelector) {
|
|
3927
|
+
if (part.type === 'css') {
|
|
3928
|
+
if (!result) {
|
|
3929
|
+
result = part.selector;
|
|
3930
|
+
continue;
|
|
3931
|
+
}
|
|
3932
|
+
result = `${result} >> ${part.selector}`;
|
|
3933
|
+
continue;
|
|
3934
|
+
}
|
|
3935
|
+
if (part.type === 'text') {
|
|
3936
|
+
if (!result) {
|
|
3937
|
+
result = `text=${part.text}`;
|
|
3938
|
+
continue;
|
|
3939
|
+
}
|
|
3940
|
+
result = `${result} text=${part.text}`;
|
|
3941
|
+
continue;
|
|
3942
|
+
}
|
|
3943
|
+
if (part.type === 'has-text') {
|
|
3944
|
+
result = `${result} "${part.text}"`;
|
|
3945
|
+
continue;
|
|
3946
|
+
}
|
|
3947
|
+
result = `${result}:nth(${part.index})`;
|
|
3943
3948
|
}
|
|
3944
|
-
|
|
3945
|
-
|
|
3949
|
+
return result;
|
|
3950
|
+
};
|
|
3951
|
+
const querySelector = parsedSelector => {
|
|
3952
|
+
if (!Array.isArray(parsedSelector)) {
|
|
3953
|
+
throw new TypeError('parsedSelector must be of type array');
|
|
3946
3954
|
}
|
|
3947
|
-
|
|
3948
|
-
|
|
3955
|
+
let elements = [document.body];
|
|
3956
|
+
for (const part of parsedSelector) {
|
|
3957
|
+
if (part.type === 'text') {
|
|
3958
|
+
elements = elements.flatMap(element => {
|
|
3959
|
+
return querySelectorByText(element, part.text);
|
|
3960
|
+
});
|
|
3961
|
+
continue;
|
|
3962
|
+
}
|
|
3963
|
+
if (part.type === 'css') {
|
|
3964
|
+
elements = elements.flatMap(element => {
|
|
3965
|
+
return querySelectorByCssFromRoot(element, part.selector);
|
|
3966
|
+
});
|
|
3967
|
+
continue;
|
|
3968
|
+
}
|
|
3969
|
+
if (part.type === 'has-text') {
|
|
3970
|
+
elements = elements.filter(element => element.textContent === part.text);
|
|
3971
|
+
continue;
|
|
3972
|
+
}
|
|
3973
|
+
if (part.type === 'nth') {
|
|
3974
|
+
const element = elements[part.index];
|
|
3975
|
+
elements = element ? [element] : [];
|
|
3976
|
+
continue;
|
|
3977
|
+
}
|
|
3978
|
+
throw new Error(`unsupported selector: ${selectorToString(parsedSelector)}`);
|
|
3949
3979
|
}
|
|
3950
|
-
|
|
3980
|
+
return elements;
|
|
3951
3981
|
};
|
|
3952
|
-
const
|
|
3953
|
-
|
|
3954
|
-
nth = -1
|
|
3955
|
-
} = {}) => {
|
|
3956
|
-
let elements = querySelector(selector);
|
|
3957
|
-
if (hasText) {
|
|
3958
|
-
elements = elements.filter(element => element.textContent === hasText);
|
|
3959
|
-
}
|
|
3982
|
+
const querySelectorOne = parsedSelector => {
|
|
3983
|
+
const elements = querySelector(parsedSelector);
|
|
3960
3984
|
if (elements.length === 0) {
|
|
3961
3985
|
return undefined;
|
|
3962
3986
|
}
|
|
@@ -3964,14 +3988,7 @@ const querySelectorWithOptions = (selector, {
|
|
|
3964
3988
|
const element = elements[0];
|
|
3965
3989
|
return element;
|
|
3966
3990
|
}
|
|
3967
|
-
|
|
3968
|
-
throw new Error(`too many matching elements for ${selector}, matching ${elements.length}`);
|
|
3969
|
-
}
|
|
3970
|
-
const element = elements[nth];
|
|
3971
|
-
if (!element) {
|
|
3972
|
-
throw new Error(`selector not found: ${selector}`);
|
|
3973
|
-
}
|
|
3974
|
-
return element;
|
|
3991
|
+
throw new Error(`too many matching elements for ${selectorToString(parsedSelector)}, matching ${elements.length}`);
|
|
3975
3992
|
};
|
|
3976
3993
|
|
|
3977
3994
|
const performAction2 = async (locator, fnName, options) => {
|
|
@@ -3979,10 +3996,7 @@ const performAction2 = async (locator, fnName, options) => {
|
|
|
3979
3996
|
string(fnName);
|
|
3980
3997
|
object(options);
|
|
3981
3998
|
const fn = ElementActions[fnName];
|
|
3982
|
-
const element =
|
|
3983
|
-
hasText: locator._hasText,
|
|
3984
|
-
nth: locator._nth
|
|
3985
|
-
});
|
|
3999
|
+
const element = querySelectorOne(locator._parsed);
|
|
3986
4000
|
if (!element) {
|
|
3987
4001
|
throw new Error(`element not found`);
|
|
3988
4002
|
}
|
|
@@ -3991,10 +4005,7 @@ const performAction2 = async (locator, fnName, options) => {
|
|
|
3991
4005
|
};
|
|
3992
4006
|
|
|
3993
4007
|
const toHaveText$1 = locator => {
|
|
3994
|
-
const element =
|
|
3995
|
-
hasText: locator._hasText,
|
|
3996
|
-
nth: locator._nth
|
|
3997
|
-
});
|
|
4008
|
+
const element = querySelectorOne(locator._parsed);
|
|
3998
4009
|
if (!element) {
|
|
3999
4010
|
return {
|
|
4000
4011
|
actual: '',
|
|
@@ -4010,10 +4021,7 @@ const toHaveAttribute$1 = (locator, {
|
|
|
4010
4021
|
key,
|
|
4011
4022
|
value
|
|
4012
4023
|
}) => {
|
|
4013
|
-
const element =
|
|
4014
|
-
hasText: locator._hasText,
|
|
4015
|
-
nth: locator._nth
|
|
4016
|
-
});
|
|
4024
|
+
const element = querySelectorOne(locator._parsed);
|
|
4017
4025
|
if (!element) {
|
|
4018
4026
|
return {
|
|
4019
4027
|
actual: '',
|
|
@@ -4027,7 +4035,7 @@ const toHaveAttribute$1 = (locator, {
|
|
|
4027
4035
|
};
|
|
4028
4036
|
};
|
|
4029
4037
|
const toHaveCount$1 = locator => {
|
|
4030
|
-
const elements = querySelector(locator.
|
|
4038
|
+
const elements = querySelector(locator._parsed);
|
|
4031
4039
|
const actualCount = elements.length;
|
|
4032
4040
|
return {
|
|
4033
4041
|
actual: actualCount
|
|
@@ -4055,7 +4063,7 @@ const toBeFocused$1 = locator => {
|
|
|
4055
4063
|
const toHaveClass$1 = (locator, {
|
|
4056
4064
|
className
|
|
4057
4065
|
}) => {
|
|
4058
|
-
const [element] = querySelector(locator.
|
|
4066
|
+
const [element] = querySelector(locator._parsed);
|
|
4059
4067
|
if (!element) {
|
|
4060
4068
|
return {
|
|
4061
4069
|
actual: '',
|
|
@@ -4068,7 +4076,7 @@ const toHaveClass$1 = (locator, {
|
|
|
4068
4076
|
};
|
|
4069
4077
|
};
|
|
4070
4078
|
const toHaveId$1 = locator => {
|
|
4071
|
-
const [element] = querySelector(locator.
|
|
4079
|
+
const [element] = querySelector(locator._parsed);
|
|
4072
4080
|
if (!element) {
|
|
4073
4081
|
return {
|
|
4074
4082
|
actual: '',
|
|
@@ -4083,7 +4091,7 @@ const toHaveId$1 = locator => {
|
|
|
4083
4091
|
const toHaveCss$1 = (locator, {
|
|
4084
4092
|
key
|
|
4085
4093
|
}) => {
|
|
4086
|
-
const [element] = querySelector(locator.
|
|
4094
|
+
const [element] = querySelector(locator._parsed);
|
|
4087
4095
|
if (!element) {
|
|
4088
4096
|
return {
|
|
4089
4097
|
actual: '',
|
|
@@ -4100,7 +4108,7 @@ const toHaveCss$1 = (locator, {
|
|
|
4100
4108
|
const toHaveJSProperty$1 = (locator, {
|
|
4101
4109
|
key
|
|
4102
4110
|
}) => {
|
|
4103
|
-
const [element] = querySelector(locator.
|
|
4111
|
+
const [element] = querySelector(locator._parsed);
|
|
4104
4112
|
if (!element) {
|
|
4105
4113
|
return {
|
|
4106
4114
|
actual: '',
|
|
@@ -4252,10 +4260,7 @@ const performAction = async (locator, fnName, options) => {
|
|
|
4252
4260
|
string(fnName);
|
|
4253
4261
|
object(options);
|
|
4254
4262
|
const fn = ElementActions[fnName];
|
|
4255
|
-
const element =
|
|
4256
|
-
hasText: locator._hasText,
|
|
4257
|
-
nth: locator._nth
|
|
4258
|
-
});
|
|
4263
|
+
const element = querySelectorOne(locator._parsed);
|
|
4259
4264
|
if (!element) {
|
|
4260
4265
|
throw new Error(`element not found`);
|
|
4261
4266
|
}
|
|
@@ -4270,10 +4275,7 @@ const performKeyBoardAction = (fnName, options) => {
|
|
|
4270
4275
|
};
|
|
4271
4276
|
const checkSingleElementCondition = async (locator, fnName, options) => {
|
|
4272
4277
|
const fn = SingleElementConditions[fnName];
|
|
4273
|
-
const element =
|
|
4274
|
-
hasText: locator._hasText,
|
|
4275
|
-
nth: locator._nth
|
|
4276
|
-
});
|
|
4278
|
+
const element = querySelectorOne(locator._parsed);
|
|
4277
4279
|
if (element) {
|
|
4278
4280
|
const successful = fn(element, options);
|
|
4279
4281
|
if (successful) {
|
|
@@ -4288,7 +4290,7 @@ const checkSingleElementCondition = async (locator, fnName, options) => {
|
|
|
4288
4290
|
};
|
|
4289
4291
|
const checkMultiElementCondition = async (locator, fnName, options) => {
|
|
4290
4292
|
const fn = MultiElementConditions[fnName];
|
|
4291
|
-
const elements = querySelector(locator.
|
|
4293
|
+
const elements = querySelector(locator._parsed);
|
|
4292
4294
|
const successful = fn(elements, options);
|
|
4293
4295
|
if (successful) {
|
|
4294
4296
|
return {
|