@lvce-editor/find-widget-worker 1.1.0 → 1.3.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.
@@ -887,7 +887,11 @@ const create$1 = (uid, x, y, width, height, parentUid) => {
887
887
  focus: 0,
888
888
  version: 0,
889
889
  lines: [],
890
- selections: []
890
+ selections: [],
891
+ editorX: x,
892
+ editorY: y,
893
+ editorWidth: width,
894
+ editorHeight: height
891
895
  };
892
896
  set$1(uid, state, state);
893
897
  return state;
@@ -906,7 +910,7 @@ const isEqual$2 = (oldState, newState) => {
906
910
  };
907
911
 
908
912
  const isEqual$1 = (oldState, newState) => {
909
- return oldState.version === newState.version;
913
+ return oldState.version === newState.version && oldState.replaceExpanded === newState.replaceExpanded && oldState.matchCount === newState.matchCount && oldState.matchIndex === newState.matchIndex;
910
914
  };
911
915
 
912
916
  const isEqual = (oldState, newState) => {
@@ -1008,6 +1012,11 @@ const handleBlur = async state => {
1008
1012
  };
1009
1013
  };
1010
1014
 
1015
+ const handleClickClose = state => {
1016
+ // TODO ask editor worker to dispose widget
1017
+ return state;
1018
+ };
1019
+
1011
1020
  const findRegexMatches = (lines, regex) => {
1012
1021
  if (!regex.global) {
1013
1022
  throw new Error('regex must be global');
@@ -1078,12 +1087,44 @@ const handleInput = (state, value) => {
1078
1087
  return refresh(state, value);
1079
1088
  };
1080
1089
 
1090
+ const getFindWidgetHeight = replaceExpanded => {
1091
+ const collapsedHeight = 30;
1092
+ const expandedHeight = 60;
1093
+ const newHeight = replaceExpanded ? expandedHeight : collapsedHeight;
1094
+ return newHeight;
1095
+ };
1096
+
1097
+ const toggleReplace = state => {
1098
+ const newExpanded = !state.replaceExpanded;
1099
+ const newHeight = getFindWidgetHeight(newExpanded);
1100
+ return {
1101
+ ...state,
1102
+ replaceExpanded: !state.replaceExpanded,
1103
+ height: newHeight
1104
+ };
1105
+ };
1106
+
1081
1107
  const commandIds = ['handleSliderPointerDown', 'handleSliderPointerMove'];
1082
1108
 
1083
1109
  const getCommandIds = () => {
1084
1110
  return commandIds;
1085
1111
  };
1086
1112
 
1113
+ const getFindWidgetPosition = (editorX, editorY, editorWidth) => {
1114
+ const width = 300;
1115
+ const height = 30;
1116
+ const paddingTop = 10;
1117
+ const paddingRight = 20;
1118
+ const x = editorX + editorWidth - width - paddingRight;
1119
+ const y = editorY + paddingTop;
1120
+ return {
1121
+ y,
1122
+ x,
1123
+ width,
1124
+ height
1125
+ };
1126
+ };
1127
+
1087
1128
  const rpcs = Object.create(null);
1088
1129
  const set$a = (id, rpc) => {
1089
1130
  rpcs[id] = rpc;
@@ -1144,10 +1185,19 @@ const getSelections = async editorUid => {
1144
1185
 
1145
1186
  const loadContent = async state => {
1146
1187
  const {
1147
- editorUid
1188
+ editorUid,
1189
+ editorWidth,
1190
+ editorX,
1191
+ editorY
1148
1192
  } = state;
1149
1193
  const lines = await getLines(editorUid);
1150
1194
  const selections = await getSelections(editorUid);
1195
+ const {
1196
+ x,
1197
+ y,
1198
+ width,
1199
+ height
1200
+ } = getFindWidgetPosition(editorX, editorY, editorWidth);
1151
1201
  if (lines.length === 0) {
1152
1202
  return state;
1153
1203
  }
@@ -1164,7 +1214,11 @@ const loadContent = async state => {
1164
1214
  matches,
1165
1215
  matchIndex: 0,
1166
1216
  matchCount,
1167
- version: 1
1217
+ version: 1,
1218
+ x,
1219
+ y,
1220
+ width,
1221
+ height
1168
1222
  };
1169
1223
  };
1170
1224
 
@@ -1184,14 +1238,19 @@ const renderBounds = (oldState, newState) => {
1184
1238
  return [SetBounds, uid, x, y, width, height];
1185
1239
  };
1186
1240
 
1241
+ const HandleBlur = 'handleBlur';
1187
1242
  const HandleClickClose = 'handleClickClose';
1243
+ const HandleClickFocusPreviousMatch = 'handleClickFocusPreviousMatch';
1188
1244
  const HandleClickNextMatch = 'handleClickNextMatch';
1189
1245
  const HandleClickPreviousMatch = 'handleClickPreviousMatch';
1190
1246
  const HandleClickReplace = 'handleClickReplace';
1247
+ const HandleClickToggleReplace = 'handleClickToggleReplace';
1191
1248
  const HandleClickReplaceAll = 'handleClickReplaceAll';
1192
1249
  const HandleFocus = 'handleFocus';
1193
1250
  const HandleInput = 'handleInput';
1194
1251
  const HandleReplaceFocus = 'handleReplaceFocus';
1252
+ const HandleFocusPrevious = 'handleFocusPrevious';
1253
+ const HandleFocusNext = 'handleFocusNext';
1195
1254
  const HandleReplaceInput = 'handleReplaceInput';
1196
1255
 
1197
1256
  const emptyObject = {};
@@ -1525,15 +1584,56 @@ const renderContent = (oldState, newState) => {
1525
1584
  return [SetDom2, uid, dom];
1526
1585
  };
1527
1586
 
1528
- const getEventListeners = uid => {
1529
- return [];
1587
+ const getEventListeners = (uid, widgetId) => {
1588
+ return [{
1589
+ name: HandleInput,
1590
+ params: ['executeWidgetCommand', 'FindWidget', 'FindWidget.handleInput', 0, widgetId, 'event.target.value']
1591
+ }, {
1592
+ name: HandleClickClose,
1593
+ params: ['executeWidgetCommand', 'FindWidget', 'FindWidget.handleClickClose', 0, widgetId]
1594
+ }, {
1595
+ name: HandleClickFocusPreviousMatch,
1596
+ params: ['executeWidgetCommand', 'FindWidget', 'FindWidget.handleClickPreviousMatch', 0, widgetId]
1597
+ }, {
1598
+ name: HandleClickNextMatch,
1599
+ params: ['executeWidgetCommand', 'FindWidget', 'FindWidget.handleClickNextMatch', 0, widgetId]
1600
+ }, {
1601
+ name: HandleClickReplace,
1602
+ params: ['executeWidgetCommand', 'FindWidget', 'FindWidget.handleClickReplace', 0, widgetId]
1603
+ }, {
1604
+ name: HandleClickReplace,
1605
+ params: ['executeWidgetCommand', 'FindWidget', 'FindWidget.handleClickReplaceAll', 0, widgetId]
1606
+ }, {
1607
+ name: HandleClickToggleReplace,
1608
+ params: ['executeWidgetCommand', 'FindWidget', 'FindWidget.toggleReplace', 0, widgetId]
1609
+ }, {
1610
+ name: HandleBlur,
1611
+ params: ['executeWidgetCommand', 'FindWidget', 'FindWidget.handleBlur', 0, widgetId]
1612
+ }, {
1613
+ name: HandleReplaceInput,
1614
+ params: ['executeWidgetCommand', 'FindWidget', 'FindWidget.handleReplaceInput', 0, widgetId]
1615
+ }, {
1616
+ name: HandleReplaceFocus,
1617
+ params: ['executeWidgetCommand', 'FindWidget', 'FindWidget.handleReplaceFocus', 0, widgetId]
1618
+ }, {
1619
+ name: HandleFocusPrevious,
1620
+ params: ['executeWidgetCommand', 'FindWidget', 'FindWidget.handleFocusPrevious', 0, widgetId]
1621
+ }, {
1622
+ name: HandleFocusNext,
1623
+ params: ['executeWidgetCommand', 'FindWidget', 'FindWidget.handleFocusNext', 0, widgetId]
1624
+ }, {
1625
+ name: HandleClickReplaceAll,
1626
+ params: ['executeWidgetCommand', 'FindWidget', 'FindWidget.handleClickReplaceAll', 0, widgetId]
1627
+ }];
1530
1628
  };
1531
1629
 
1630
+ const Find = 5;
1631
+
1532
1632
  const renderEventListeners = state => {
1533
1633
  const {
1534
1634
  uid
1535
1635
  } = state;
1536
- const eventListeners = getEventListeners();
1636
+ const eventListeners = getEventListeners(uid, Find);
1537
1637
  return [SetEventListeners, uid, eventListeners];
1538
1638
  };
1539
1639
 
@@ -1601,10 +1701,12 @@ const commandMap = {
1601
1701
  'FindWidget.focusPrevious': focusPrevious,
1602
1702
  'FindWidget.getCommandIds': getCommandIds,
1603
1703
  'FindWidget.handleBlur': handleBlur,
1704
+ 'FindWidget.handleClickClose': handleClickClose,
1604
1705
  'FindWidget.handleInput': handleInput,
1605
1706
  'FindWidget.loadContent': wrapCommand(loadContent),
1606
1707
  'FindWidget.render2': render2,
1607
- 'FindWidget.terminate': terminate
1708
+ 'FindWidget.terminate': terminate,
1709
+ 'FindWidget.toggleReplace': toggleReplace
1608
1710
  };
1609
1711
 
1610
1712
  const listen = async () => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lvce-editor/find-widget-worker",
3
- "version": "1.1.0",
3
+ "version": "1.3.0",
4
4
  "description": "Web Worker for the find widget in Lvce Editor",
5
5
  "repository": {
6
6
  "type": "git",