@lvce-editor/editor-worker 7.1.0 → 7.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.
@@ -1132,14 +1132,14 @@ const getModule$2 = id => {
1132
1132
  const applyWidgetChange = async (editor, widget, changes) => {
1133
1133
  const module = getModule$2(widget.id);
1134
1134
  if (changes.length === 1 && changes[0].origin === EditorType && module.handleEditorType) {
1135
- const newState = await module.handleEditorType(editor, widget.newState);
1135
+ const newState = await module.handleEditorType(widget.newState);
1136
1136
  return {
1137
1137
  ...widget,
1138
1138
  newState
1139
1139
  };
1140
1140
  }
1141
1141
  if (changes.length === 1 && changes[0].origin === DeleteLeft && module.handleEditorDeleteLeft) {
1142
- const newState = await module.handleEditorDeleteLeft(editor, widget.newState);
1142
+ const newState = await module.handleEditorDeleteLeft(widget.newState);
1143
1143
  return {
1144
1144
  ...widget,
1145
1145
  newState
@@ -7697,6 +7697,29 @@ const renderFull$4 = (oldState, newState) => {
7697
7697
  return commands;
7698
7698
  };
7699
7699
 
7700
+ const updateWidget = (editor, widgetId, newState) => {
7701
+ // TODO avoid closure
7702
+ const isWidget = widget => {
7703
+ return widget.id === widgetId;
7704
+ };
7705
+ const childIndex = editor.widgets.findIndex(isWidget);
7706
+ if (childIndex === -1) {
7707
+ return editor;
7708
+ }
7709
+ // TODO scroll up/down if necessary
7710
+ const childWidget = editor.widgets[childIndex];
7711
+ const newWidget = {
7712
+ ...childWidget,
7713
+ oldState: childWidget.newState,
7714
+ newState
7715
+ };
7716
+ const newWidgets = [...editor.widgets.slice(0, childIndex), newWidget, ...editor.widgets.slice(childIndex + 1)];
7717
+ return {
7718
+ ...editor,
7719
+ widgets: newWidgets
7720
+ };
7721
+ };
7722
+
7700
7723
  const render$c = widget => {
7701
7724
  const commands = renderFull$4(widget.oldState, widget.newState);
7702
7725
  const wrappedCommands = [];
@@ -7719,17 +7742,28 @@ const remove$7 = widget => {
7719
7742
  return [['Viewlet.dispose', widget.newState.uid]];
7720
7743
  };
7721
7744
  const createFn = key => {
7722
- const fn = async (state, ...args) => {
7745
+ const widgetId = Completion;
7746
+ const isWidget = widget => {
7747
+ return widget.id === widgetId;
7748
+ };
7749
+ const fn = async (editor, ...args) => {
7750
+ const childIndex = editor.widgets.findIndex(isWidget);
7751
+ // TODO scroll up/down if necessary
7752
+ const childWidget = editor.widgets[childIndex];
7753
+ const state = childWidget.newState;
7723
7754
  const {
7724
7755
  uid
7725
7756
  } = state;
7726
7757
  await invoke$3(`Completions.${key}`, uid, ...args);
7727
7758
  const diff = await invoke$3('Completions.diff2', uid);
7728
7759
  const commands = await invoke$3('Completions.render2', uid, diff);
7729
- return {
7760
+ const newState = {
7730
7761
  ...state,
7731
7762
  commands
7732
7763
  };
7764
+ const latest = get$4(editor.uid).newState;
7765
+ const newEditor = updateWidget(latest, widgetId, newState);
7766
+ return newEditor;
7733
7767
  };
7734
7768
  return fn;
7735
7769
  };
@@ -8021,26 +8055,6 @@ const getWidgetInvoke = widgetId => {
8021
8055
  }
8022
8056
  };
8023
8057
 
8024
- const updateWidget = (editor, widgetId, newState) => {
8025
- // TODO avoid closure
8026
- const isWidget = widget => {
8027
- return widget.id === widgetId;
8028
- };
8029
- const childIndex = editor.widgets.findIndex(isWidget);
8030
- // TODO scroll up/down if necessary
8031
- const childWidget = editor.widgets[childIndex];
8032
- const newWidget = {
8033
- ...childWidget,
8034
- oldState: childWidget.newState,
8035
- newState
8036
- };
8037
- const newWidgets = [...editor.widgets.slice(0, childIndex), newWidget, ...editor.widgets.slice(childIndex + 1)];
8038
- return {
8039
- ...editor,
8040
- widgets: newWidgets
8041
- };
8042
- };
8043
-
8044
8058
  const executeWidgetCommand = async (editor, name, method, _uid, widgetId, ...params) => {
8045
8059
  const invoke = getWidgetInvoke(widgetId);
8046
8060
  const actualMethod = method.slice(name.length + 1);
@@ -9719,13 +9733,16 @@ const widgetCommands = {
9719
9733
  'FindWidget.focusReplaceAllButton': Find,
9720
9734
  'FindWidget.focusNextMatchButton': Find,
9721
9735
  'FindWidget.focusPreviousMatchButton': Find,
9722
- 'FindWidget.focusCloseButton': Find,
9723
- 'EditorCompletion.handleWheel': Completion,
9724
- 'EditorCompletion.focusFirst': Completion,
9725
- 'EditorCompletion.focusNext': Completion,
9726
- 'EditorCompletion.focusPrevious': Completion,
9727
- 'EditorCompletion.focusIndex': Completion,
9728
- 'EditorCompletion.focusLast': Completion
9736
+ 'FindWidget.focusCloseButton': Find
9737
+
9738
+ // 'EditorCompletion.handleWheel': WidgetId.Completion,
9739
+ // 'EditorCompletion.focusFirst': WidgetId.Completion,
9740
+ // 'EditorCompletion.focusNext': WidgetId.Completion,
9741
+ // 'EditorCompletion.focusPrevious': WidgetId.Completion,
9742
+ // 'EditorCompletion.focusIndex': WidgetId.Completion,
9743
+ // 'EditorCompletion.focusLast': WidgetId.Completion,
9744
+ // 'EditorCompletion.selectCurrent': WidgetId.Completion,
9745
+ // 'EditorCompletion.selectIndex': WidgetId.Completion,
9729
9746
  };
9730
9747
 
9731
9748
  // TODO wrap commands globally, not per editor
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lvce-editor/editor-worker",
3
- "version": "7.1.0",
3
+ "version": "7.3.0",
4
4
  "description": "",
5
5
  "license": "MIT",
6
6
  "author": "Lvce Editor",