@lvce-editor/find-widget-worker 3.17.0 → 3.18.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.
@@ -508,6 +508,9 @@ const restoreExistingError = (error, currentStack) => {
508
508
  };
509
509
  const restoreMethodNotFoundError = (error, currentStack) => {
510
510
  const restoredError = new JsonRpcError(error.message);
511
+ Object.assign(restoredError, {
512
+ code: error.code
513
+ });
511
514
  const parentStack = getParentStack(error);
512
515
  setStack(restoredError, `${parentStack}${NewLine}${currentStack}`);
513
516
  return restoredError;
@@ -527,9 +530,13 @@ const applyDataProperties = (restoredError, error) => {
527
530
  // @ts-ignore
528
531
  restoredError.codeFrame = error.data.codeFrame;
529
532
  }
530
- if (error.data.code) {
533
+ if (typeof error.data.code === 'string' || typeof error.data.code === 'number') {
531
534
  // @ts-ignore
532
- restoredError.code = error.data.code;
535
+ Object.defineProperty(restoredError, 'code', {
536
+ configurable: true,
537
+ value: error.data.code,
538
+ writable: true
539
+ });
533
540
  }
534
541
  if (error.data.type) {
535
542
  // @ts-ignore
@@ -550,7 +557,14 @@ const applyDirectProperties = (restoredError, error) => {
550
557
  }
551
558
  };
552
559
  const restoreMessageError = (error, _currentStack) => {
553
- const restoredError = constructError(error.message, error.type, error.name);
560
+ const restoredError = constructError(error.message, error.type || error.data?.type, error.name);
561
+ if (typeof error.code === 'string' || typeof error.code === 'number') {
562
+ Object.defineProperty(restoredError, 'code', {
563
+ configurable: true,
564
+ value: error.code,
565
+ writable: true
566
+ });
567
+ }
554
568
  if (error.data) {
555
569
  applyDataProperties(restoredError, error);
556
570
  } else {
@@ -558,6 +572,23 @@ const restoreMessageError = (error, _currentStack) => {
558
572
  }
559
573
  return restoredError;
560
574
  };
575
+ const getFallbackMessage = error => {
576
+ if (error && typeof error.message === 'string' && error.message) {
577
+ return error.message;
578
+ }
579
+ if (error && error.data) {
580
+ return getFallbackMessage(error.data);
581
+ }
582
+ const stringified = String(error);
583
+ if (stringified !== '[object Object]') {
584
+ return stringified;
585
+ }
586
+ try {
587
+ return JSON.stringify(error);
588
+ } catch {
589
+ return stringified;
590
+ }
591
+ };
561
592
  const restoreJsonRpcError = error => {
562
593
  const currentStack = getCurrentStack();
563
594
  if (error && error instanceof Error) {
@@ -566,13 +597,13 @@ const restoreJsonRpcError = error => {
566
597
  if (error && error.code && error.code === MethodNotFound) {
567
598
  return restoreMethodNotFoundError(error, currentStack);
568
599
  }
600
+ if (error && error.error) {
601
+ return restoreJsonRpcError(error.error);
602
+ }
569
603
  if (error && error.message) {
570
604
  return restoreMessageError(error);
571
605
  }
572
- if (typeof error === 'string') {
573
- return new Error(`JsonRpc Error: ${error}`);
574
- }
575
- return new Error(`JsonRpc Error: ${error}`);
606
+ return new Error(`JsonRpc Error: ${getFallbackMessage(error)}`);
576
607
  };
577
608
  const unwrapJsonRpcResult = responseMessage => {
578
609
  if ('error' in responseMessage) {
@@ -629,9 +660,9 @@ const getErrorProperty = (error, prettyError) => {
629
660
  return {
630
661
  code: Custom,
631
662
  data: {
632
- code: prettyError.code,
663
+ code: prettyError.code ?? error?.code,
633
664
  codeFrame: prettyError.codeFrame,
634
- name: prettyError.name,
665
+ name: prettyError.name ?? error?.name,
635
666
  stack: getStack(prettyError),
636
667
  type: getErrorType(prettyError)
637
668
  },
@@ -666,7 +697,12 @@ const getErrorResponseSimple = (id, error) => {
666
697
  return {
667
698
  error: {
668
699
  code: Custom,
669
- data: error,
700
+ data: error instanceof Error ? {
701
+ ...error,
702
+ code: 'code' in error ? error.code : undefined,
703
+ stack: error.stack,
704
+ type: error.name
705
+ } : error,
670
706
  // @ts-ignore
671
707
  message: error.message
672
708
  },
@@ -955,174 +991,10 @@ const CheckBox = 'checkbox';
955
991
  const Group = 'group';
956
992
  const None = 'none';
957
993
 
958
- const Audio = 0;
959
994
  const Button = 1;
960
- const Col = 2;
961
- const ColGroup = 3;
962
995
  const Div = 4;
963
- const H1 = 5;
964
- const Input = 6;
965
- const Kbd = 7;
966
- const Span = 8;
967
- const Table = 9;
968
- const TBody = 10;
969
- const Td = 11;
970
996
  const Text = 12;
971
- const Th = 13;
972
- const THead = 14;
973
- const Tr = 15;
974
- const I = 16;
975
- const Img = 17;
976
- const Root = 0;
977
- const Ins = 20;
978
- const Del = 21;
979
- const H2 = 22;
980
- const H3 = 23;
981
- const H4 = 24;
982
- const H5 = 25;
983
- const H6 = 26;
984
- const Article = 27;
985
- const Aside = 28;
986
- const Footer = 29;
987
- const Header = 30;
988
- const Nav = 40;
989
- const Section = 41;
990
- const Search = 42;
991
- const Dd = 43;
992
- const Dl = 44;
993
- const Figcaption = 45;
994
- const Figure = 46;
995
- const Hr = 47;
996
- const Li = 48;
997
- const Ol = 49;
998
- const P = 50;
999
- const Pre = 51;
1000
- const A = 53;
1001
- const Abbr = 54;
1002
- const Br = 55;
1003
- const Cite = 56;
1004
- const Data = 57;
1005
- const Time = 58;
1006
- const Tfoot = 59;
1007
- const Ul = 60;
1008
- const Video = 61;
1009
997
  const TextArea = 62;
1010
- const Select = 63;
1011
- const Option = 64;
1012
- const Code = 65;
1013
- const Label = 66;
1014
- const Dt = 67;
1015
- const Iframe = 68;
1016
- const Main = 69;
1017
- const Strong = 70;
1018
- const Em = 71;
1019
- const Style = 72;
1020
- const Html = 73;
1021
- const Head = 74;
1022
- const Title = 75;
1023
- const Meta = 76;
1024
- const Canvas = 77;
1025
- const Form = 78;
1026
- const BlockQuote = 79;
1027
- const Quote = 80;
1028
- const Circle = 81;
1029
- const Defs = 82;
1030
- const Ellipse = 83;
1031
- const G = 84;
1032
- const Line = 85;
1033
- const Path = 86;
1034
- const Polygon = 87;
1035
- const Polyline = 88;
1036
- const Rect = 89;
1037
- const Svg = 90;
1038
- const Use = 91;
1039
- const Reference = 100;
1040
-
1041
- const VirtualDomElements = {
1042
- __proto__: null,
1043
- A,
1044
- Abbr,
1045
- Article,
1046
- Aside,
1047
- Audio,
1048
- BlockQuote,
1049
- Br,
1050
- Button,
1051
- Canvas,
1052
- Circle,
1053
- Cite,
1054
- Code,
1055
- Col,
1056
- ColGroup,
1057
- Data,
1058
- Dd,
1059
- Defs,
1060
- Del,
1061
- Div,
1062
- Dl,
1063
- Dt,
1064
- Ellipse,
1065
- Em,
1066
- Figcaption,
1067
- Figure,
1068
- Footer,
1069
- Form,
1070
- G,
1071
- H1,
1072
- H2,
1073
- H3,
1074
- H4,
1075
- H5,
1076
- H6,
1077
- Head,
1078
- Header,
1079
- Hr,
1080
- Html,
1081
- I,
1082
- Iframe,
1083
- Img,
1084
- Input,
1085
- Ins,
1086
- Kbd,
1087
- Label,
1088
- Li,
1089
- Line,
1090
- Main,
1091
- Meta,
1092
- Nav,
1093
- Ol,
1094
- Option,
1095
- P,
1096
- Path,
1097
- Polygon,
1098
- Polyline,
1099
- Pre,
1100
- Quote,
1101
- Rect,
1102
- Reference,
1103
- Root,
1104
- Search,
1105
- Section,
1106
- Select,
1107
- Span,
1108
- Strong,
1109
- Style,
1110
- Svg,
1111
- TBody,
1112
- THead,
1113
- Table,
1114
- Td,
1115
- Text,
1116
- TextArea,
1117
- Tfoot,
1118
- Th,
1119
- Time,
1120
- Title,
1121
- Tr,
1122
- Ul,
1123
- Use,
1124
- Video
1125
- };
1126
998
 
1127
999
  const ClientX = 'event.clientX';
1128
1000
  const ClientY = 'event.clientY';
@@ -1192,7 +1064,8 @@ const create$1 = () => {
1192
1064
  const commandQueues = new Map();
1193
1065
  const generations = Object.create(null);
1194
1066
  const states = Object.create(null);
1195
- const commandMapRef = {};
1067
+ const commandMapRef = Object.create(null);
1068
+ const commandsById = Object.create(null);
1196
1069
  const getGeneration = uid => generations[uid] || 0;
1197
1070
  const isCurrentGeneration = (uid, generation) => {
1198
1071
  return states[uid] !== undefined && getGeneration(uid) === generation;
@@ -1254,6 +1127,18 @@ const create$1 = () => {
1254
1127
  delete states[key];
1255
1128
  }
1256
1129
  },
1130
+ createDirectEventCommandMap(requestRender) {
1131
+ return {
1132
+ async 'Viewlet.executeViewletCommand'(uid, command, ...args) {
1133
+ const fn = commandsById[command];
1134
+ if (!fn) {
1135
+ throw new Error(`Viewlet command not found: ${command}`);
1136
+ }
1137
+ await fn(uid, ...args);
1138
+ await requestRender(uid);
1139
+ }
1140
+ };
1141
+ },
1257
1142
  diff(uid, modules, numbers) {
1258
1143
  const {
1259
1144
  oldState,
@@ -1285,6 +1170,9 @@ const create$1 = () => {
1285
1170
  },
1286
1171
  registerCommands(commandMap) {
1287
1172
  Object.assign(commandMapRef, commandMap);
1173
+ for (const [key, fn] of Object.entries(commandMap)) {
1174
+ commandsById[toCommandId(key)] = fn;
1175
+ }
1288
1176
  },
1289
1177
  set(uid, oldState, newState, scheduledState) {
1290
1178
  const current = states[uid];
@@ -1816,6 +1704,14 @@ const buildRegex = (searchString, options) => {
1816
1704
  }
1817
1705
  };
1818
1706
 
1707
+ // eslint-disable-next-line @typescript-eslint/prefer-readonly-parameter-types -- Appends matches to the shared output array.
1708
+ const collectMatchesForLineInternal = (matches, line, lineIndex, regex) => {
1709
+ let lastMatch = regex.exec(line);
1710
+ while (lastMatch) {
1711
+ matches.push(lineIndex, lastMatch.index, lastMatch[0].length);
1712
+ lastMatch = regex.exec(line);
1713
+ }
1714
+ };
1819
1715
  const findRegexMatches = (lines, regex) => {
1820
1716
  if (!regex.global) {
1821
1717
  throw new Error('regex must be global');
@@ -1824,15 +1720,8 @@ const findRegexMatches = (lines, regex) => {
1824
1720
  length
1825
1721
  } = lines;
1826
1722
  const matches = [];
1827
- const collectMatchesForLine = (line, lineIndex) => {
1828
- let lastMatch = regex.exec(line);
1829
- while (lastMatch) {
1830
- matches.push(lineIndex, lastMatch.index, lastMatch[0].length);
1831
- lastMatch = regex.exec(line);
1832
- }
1833
- };
1834
1723
  for (let i = 0; i < length; i++) {
1835
- collectMatchesForLine(lines[i], i);
1724
+ collectMatchesForLineInternal(matches, lines[i], i, regex);
1836
1725
  }
1837
1726
  return new Uint32Array(matches);
1838
1727
  };
@@ -1974,11 +1863,11 @@ const togglePreserveCase = state => {
1974
1863
  const {
1975
1864
  preserveCase
1976
1865
  } = state;
1977
- // TODO update search results
1978
- return {
1866
+ const newState = {
1979
1867
  ...state,
1980
1868
  preserveCase: !preserveCase
1981
1869
  };
1870
+ return refresh(newState, newState.value, User$1);
1982
1871
  };
1983
1872
 
1984
1873
  const toggleUseRegularExpression = state => {
@@ -2981,8 +2870,6 @@ const text = data => {
2981
2870
  };
2982
2871
  };
2983
2872
 
2984
- new Set(Object.values(VirtualDomElements));
2985
-
2986
2873
  const FindWidget = 'FindWidget';
2987
2874
  const FindWidgetFind = 'FindWidgetFind';
2988
2875
  const FindWidgetMatchCount = 'FindWidgetMatchCount';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lvce-editor/find-widget-worker",
3
- "version": "3.17.0",
3
+ "version": "3.18.0",
4
4
  "description": "Web Worker for the find widget in Lvce Editor",
5
5
  "repository": {
6
6
  "type": "git",