@lvce-editor/find-widget-worker 1.22.0 → 1.23.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/findWidgetWorkerMain.js +87 -32
- package/package.json +1 -1
|
@@ -843,6 +843,9 @@ const createMockRpc = ({
|
|
|
843
843
|
const invoke = (method, ...params) => {
|
|
844
844
|
invocations.push([method, ...params]);
|
|
845
845
|
const command = commandMap[method];
|
|
846
|
+
if (!command) {
|
|
847
|
+
throw new Error(`command ${method} not found`);
|
|
848
|
+
}
|
|
846
849
|
return command(...params);
|
|
847
850
|
};
|
|
848
851
|
const mockRpc = {
|
|
@@ -983,7 +986,10 @@ const create$1 = (uid, x, y, width, height, parentUid) => {
|
|
|
983
986
|
preserveCase: false,
|
|
984
987
|
resizerPointerDown: false,
|
|
985
988
|
minWidth: 400,
|
|
986
|
-
history: []
|
|
989
|
+
history: [],
|
|
990
|
+
inputErrorMessage: '',
|
|
991
|
+
inputHeight: 24,
|
|
992
|
+
inputLineHeight: 24
|
|
987
993
|
};
|
|
988
994
|
set$3(uid, state, state);
|
|
989
995
|
return state;
|
|
@@ -994,7 +1000,7 @@ const isEqual$7 = (oldState, newState) => {
|
|
|
994
1000
|
};
|
|
995
1001
|
|
|
996
1002
|
const isEqual$6 = (oldState, newState) => {
|
|
997
|
-
return newState.width === newState.width && oldState.height === newState.height && oldState.x === newState.x;
|
|
1003
|
+
return newState.width === newState.width && oldState.height === newState.height && oldState.x === newState.x && oldState.inputHeight === newState.inputHeight;
|
|
998
1004
|
};
|
|
999
1005
|
|
|
1000
1006
|
const isEqual$5 = (oldState, newState) => {
|
|
@@ -1340,7 +1346,18 @@ const buildRegex = (searchString, options) => {
|
|
|
1340
1346
|
const flags = matchCase ? 'g' : 'gi';
|
|
1341
1347
|
const pattern = useRegularExpression ? searchString : escapeRegExpCharacters(searchString);
|
|
1342
1348
|
const wrapped = matchWholeWord ? `\\b(?:${pattern})\\b` : pattern;
|
|
1343
|
-
|
|
1349
|
+
try {
|
|
1350
|
+
const regex = new RegExp(wrapped, flags);
|
|
1351
|
+
return {
|
|
1352
|
+
regex,
|
|
1353
|
+
error: ''
|
|
1354
|
+
};
|
|
1355
|
+
} catch (error) {
|
|
1356
|
+
return {
|
|
1357
|
+
regex: new RegExp(''),
|
|
1358
|
+
error: `${error}`
|
|
1359
|
+
};
|
|
1360
|
+
}
|
|
1344
1361
|
};
|
|
1345
1362
|
|
|
1346
1363
|
const findRegexMatches = (lines, regex) => {
|
|
@@ -1367,37 +1384,70 @@ const findRegexMatches = (lines, regex) => {
|
|
|
1367
1384
|
|
|
1368
1385
|
const findMatches = (lines, searchString, options) => {
|
|
1369
1386
|
if (searchString.length === 0) {
|
|
1370
|
-
return
|
|
1387
|
+
return {
|
|
1388
|
+
matches: new Uint32Array([]),
|
|
1389
|
+
error: ''
|
|
1390
|
+
};
|
|
1371
1391
|
}
|
|
1372
|
-
const
|
|
1373
|
-
|
|
1392
|
+
const {
|
|
1393
|
+
regex
|
|
1394
|
+
} = buildRegex(searchString, options);
|
|
1395
|
+
const matches = findRegexMatches(lines, regex);
|
|
1396
|
+
return {
|
|
1397
|
+
matches,
|
|
1398
|
+
error: ''
|
|
1399
|
+
};
|
|
1374
1400
|
};
|
|
1375
1401
|
|
|
1376
1402
|
const getMatchCount = matches => {
|
|
1377
1403
|
return matches.length / 2;
|
|
1378
1404
|
};
|
|
1379
1405
|
|
|
1406
|
+
const measureTextHeight = (value, lineHeight) => {
|
|
1407
|
+
if (!value) {
|
|
1408
|
+
return lineHeight;
|
|
1409
|
+
}
|
|
1410
|
+
// TODO for single line width, can use offscreencanvas to measure text width
|
|
1411
|
+
// for multiline text, can ask renderer process to measure text height
|
|
1412
|
+
const lines = value.split('\n');
|
|
1413
|
+
return lines.length * lineHeight;
|
|
1414
|
+
};
|
|
1415
|
+
|
|
1380
1416
|
const refresh$1 = (state, value, inputSource) => {
|
|
1381
1417
|
const {
|
|
1382
1418
|
lines,
|
|
1383
1419
|
matchCase,
|
|
1384
1420
|
useRegularExpression,
|
|
1385
|
-
matchWholeWord
|
|
1421
|
+
matchWholeWord,
|
|
1422
|
+
inputLineHeight
|
|
1386
1423
|
} = state;
|
|
1387
1424
|
const options = {
|
|
1388
1425
|
matchCase,
|
|
1389
1426
|
useRegularExpression,
|
|
1390
1427
|
matchWholeWord
|
|
1391
1428
|
};
|
|
1392
|
-
const
|
|
1429
|
+
const {
|
|
1430
|
+
matches,
|
|
1431
|
+
error
|
|
1432
|
+
} = findMatches(lines, value, options);
|
|
1433
|
+
const inputHeight = measureTextHeight(value, inputLineHeight);
|
|
1434
|
+
if (error) {
|
|
1435
|
+
return {
|
|
1436
|
+
...state,
|
|
1437
|
+
inputErrorMessage: error,
|
|
1438
|
+
inputHeight
|
|
1439
|
+
};
|
|
1440
|
+
}
|
|
1393
1441
|
const matchCount = getMatchCount(matches);
|
|
1394
1442
|
return {
|
|
1395
1443
|
...state,
|
|
1444
|
+
inputErrorMessage: error,
|
|
1445
|
+
inputHeight,
|
|
1446
|
+
inputSource,
|
|
1447
|
+
matchCount,
|
|
1396
1448
|
matches,
|
|
1397
1449
|
matchIndex: 0,
|
|
1398
|
-
|
|
1399
|
-
value,
|
|
1400
|
-
inputSource
|
|
1450
|
+
value
|
|
1401
1451
|
};
|
|
1402
1452
|
};
|
|
1403
1453
|
|
|
@@ -1564,10 +1614,6 @@ const handleClickClose = state => {
|
|
|
1564
1614
|
return close$1(state);
|
|
1565
1615
|
};
|
|
1566
1616
|
|
|
1567
|
-
const handleInput = (state, value, inputSource = User) => {
|
|
1568
|
-
return refresh(state, value, inputSource);
|
|
1569
|
-
};
|
|
1570
|
-
|
|
1571
1617
|
const handleFindWidgetFocus = (state, focusKey) => {
|
|
1572
1618
|
if (state.focus === focusKey) {
|
|
1573
1619
|
return state;
|
|
@@ -1748,6 +1794,10 @@ const focusPreviousElement = state => {
|
|
|
1748
1794
|
return focusElement(state, previousFocus);
|
|
1749
1795
|
};
|
|
1750
1796
|
|
|
1797
|
+
const handleInput = (state, value, inputSource = User) => {
|
|
1798
|
+
return refresh(state, value, inputSource);
|
|
1799
|
+
};
|
|
1800
|
+
|
|
1751
1801
|
const handleReplaceInput = (state, value, inputSource = User) => {
|
|
1752
1802
|
return {
|
|
1753
1803
|
...state,
|
|
@@ -2103,8 +2153,8 @@ const SearchToggleButtonExpanded = 'SearchToggleButtonExpanded';
|
|
|
2103
2153
|
const MaskIconChevronDown = 'MaskIconChevronDown';
|
|
2104
2154
|
const MaskIconChevronRight = 'MaskIconChevronRight';
|
|
2105
2155
|
|
|
2106
|
-
const getFindMatchCountClassName = (matchCount,
|
|
2107
|
-
if (
|
|
2156
|
+
const getFindMatchCountClassName = (matchCount, hasValue) => {
|
|
2157
|
+
if (hasValue && matchCount === 0) {
|
|
2108
2158
|
return mergeClassNames(FindWidgetMatchCount, FindWidgetMatchCountEmpty);
|
|
2109
2159
|
}
|
|
2110
2160
|
return FindWidgetMatchCount;
|
|
@@ -2170,7 +2220,7 @@ const getSearchFieldButtonVirtualDom = button => {
|
|
|
2170
2220
|
}];
|
|
2171
2221
|
};
|
|
2172
2222
|
|
|
2173
|
-
const getSearchFieldVirtualDom = (name, placeholder, onInput, insideButtons, outsideButtons, onFocus = '') => {
|
|
2223
|
+
const getSearchFieldVirtualDom = (name, placeholder, onInput, insideButtons, outsideButtons, onFocus = '', extraClassName = '') => {
|
|
2174
2224
|
const dom = [{
|
|
2175
2225
|
type: Div,
|
|
2176
2226
|
className: SearchField,
|
|
@@ -2178,7 +2228,7 @@ const getSearchFieldVirtualDom = (name, placeholder, onInput, insideButtons, out
|
|
|
2178
2228
|
childCount: 2
|
|
2179
2229
|
}, {
|
|
2180
2230
|
type: TextArea,
|
|
2181
|
-
className: MultilineInputBox,
|
|
2231
|
+
className: mergeClassNames(MultilineInputBox, extraClassName),
|
|
2182
2232
|
spellcheck: false,
|
|
2183
2233
|
autocapitalize: 'off',
|
|
2184
2234
|
autocorrect: 'off',
|
|
@@ -2198,14 +2248,15 @@ const getSearchFieldVirtualDom = (name, placeholder, onInput, insideButtons, out
|
|
|
2198
2248
|
return dom;
|
|
2199
2249
|
};
|
|
2200
2250
|
|
|
2201
|
-
const getFindWidgetFindVirtualDom = (matchCountText, buttons, fieldButtons, matchCount,
|
|
2251
|
+
const getFindWidgetFindVirtualDom = (matchCountText, buttons, fieldButtons, matchCount, hasValue, hasError) => {
|
|
2252
|
+
const extraClassName = hasError ? `InputValidationError` : '';
|
|
2202
2253
|
return [{
|
|
2203
2254
|
type: Div,
|
|
2204
2255
|
className: FindWidgetFind,
|
|
2205
2256
|
childCount: 5
|
|
2206
|
-
}, ...getSearchFieldVirtualDom(SearchValue, find(), HandleInput, fieldButtons, [], HandleFocus), {
|
|
2257
|
+
}, ...getSearchFieldVirtualDom(SearchValue, find(), HandleInput, fieldButtons, [], HandleFocus, extraClassName), {
|
|
2207
2258
|
type: Div,
|
|
2208
|
-
className: getFindMatchCountClassName(matchCount,
|
|
2259
|
+
className: getFindMatchCountClassName(matchCount, hasValue),
|
|
2209
2260
|
childCount: 1
|
|
2210
2261
|
}, text(matchCountText), ...buttons.flatMap(getIconButtonVirtualDom)];
|
|
2211
2262
|
};
|
|
@@ -2260,12 +2311,12 @@ const parentNode = {
|
|
|
2260
2311
|
childCount: 3,
|
|
2261
2312
|
role: Group
|
|
2262
2313
|
};
|
|
2263
|
-
const getFindWidgetVirtualDom = (matchCountText, replaceExpanded, findButtons, findFieldButtons, replaceButtons, replaceFieldButtons, matchCount, value) => {
|
|
2314
|
+
const getFindWidgetVirtualDom = (matchCountText, replaceExpanded, findButtons, findFieldButtons, replaceButtons, replaceFieldButtons, matchCount, value, hasError) => {
|
|
2264
2315
|
return [parentNode, ...getResizerVirtualDom(), ...getSearchToggleButtonVirtualDom(replaceExpanded, 'handleClickToggleReplace'), {
|
|
2265
2316
|
type: Div,
|
|
2266
2317
|
className: FindWidgetRight,
|
|
2267
2318
|
childCount: replaceExpanded ? 2 : 1
|
|
2268
|
-
}, ...getFindWidgetFindVirtualDom(matchCountText, findButtons, findFieldButtons, matchCount, value), ...getFindWidgetReplaceVirtualDom(replaceExpanded, replaceButtons)];
|
|
2319
|
+
}, ...getFindWidgetFindVirtualDom(matchCountText, findButtons, findFieldButtons, matchCount, Boolean(value), hasError), ...getFindWidgetReplaceVirtualDom(replaceExpanded, replaceButtons)];
|
|
2269
2320
|
};
|
|
2270
2321
|
|
|
2271
2322
|
const getMatchCountText = (matchIndex, matchCount) => {
|
|
@@ -2284,7 +2335,8 @@ const renderContent = (oldState, newState) => {
|
|
|
2284
2335
|
matchCase,
|
|
2285
2336
|
matchWholeWord,
|
|
2286
2337
|
useRegularExpression,
|
|
2287
|
-
preserveCase
|
|
2338
|
+
preserveCase,
|
|
2339
|
+
inputErrorMessage
|
|
2288
2340
|
} = newState;
|
|
2289
2341
|
const matchCountText = getMatchCountText(newState.matchIndex, newState.matchCount);
|
|
2290
2342
|
const {
|
|
@@ -2297,7 +2349,8 @@ const renderContent = (oldState, newState) => {
|
|
|
2297
2349
|
findFieldButtons,
|
|
2298
2350
|
replaceFieldButtons
|
|
2299
2351
|
} = getFindWidgetButtons(findButtonsEnabled, replaceButtonsEnabled, matchCase, matchWholeWord, useRegularExpression, preserveCase);
|
|
2300
|
-
const
|
|
2352
|
+
const hasError = Boolean(inputErrorMessage);
|
|
2353
|
+
const dom = getFindWidgetVirtualDom(matchCountText, replaceExpanded, findButtons, findFieldButtons, replaceButtons, replaceFieldButtons, matchCount, value, hasError);
|
|
2301
2354
|
return [SetDom2, uid, dom];
|
|
2302
2355
|
};
|
|
2303
2356
|
|
|
@@ -2307,14 +2360,16 @@ const renderCss = (oldState, newState) => {
|
|
|
2307
2360
|
width,
|
|
2308
2361
|
height,
|
|
2309
2362
|
x,
|
|
2310
|
-
y
|
|
2363
|
+
y,
|
|
2364
|
+
inputHeight
|
|
2311
2365
|
} = newState;
|
|
2312
2366
|
const css = `:root {
|
|
2313
|
-
|
|
2314
|
-
|
|
2315
|
-
|
|
2316
|
-
|
|
2317
|
-
}
|
|
2367
|
+
--FindWidgetWidth: ${width}px;
|
|
2368
|
+
--FindWidgetHeight: ${height}px;
|
|
2369
|
+
--FindWidgetX: ${x}px;
|
|
2370
|
+
--FindWidgetY: ${y}px;
|
|
2371
|
+
--FindWidgetInputHeight: ${inputHeight}px;
|
|
2372
|
+
}`;
|
|
2318
2373
|
return [SetCss, uid, css];
|
|
2319
2374
|
};
|
|
2320
2375
|
|