@lvce-editor/editor-worker 1.9.0 → 1.11.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/api/api.d.ts CHANGED
@@ -1,22 +1,27 @@
1
1
  interface EventMap {
2
- 'ColorPicker.loadContent': (state: any) => Promise<any>
3
2
  'ColorPicker.handleSliderPointerDown': (state: any, x: number, y: number) => Promise<any>
4
3
  'ColorPicker.handleSliderPointerMove': (state: any, x: number, y: number) => Promise<any>
4
+ 'ColorPicker.loadContent': (state: any) => Promise<any>
5
+ 'ColorPicker.render': (oldState: any, newState: any) => Promise<any>
6
+ 'Editor.create': (options: any) => Promise<void>
7
+ 'Editor.offsetAt': (textDocument: any, positionRowIndex: number, positionColumnIndex: number) => Promise<any>
8
+ 'Editor.render': (editorUid: number) => Promise<any>
5
9
  'EditorCompletion.loadContent': (editorUid: number, state: any) => Promise<any>
6
10
  'EditorCompletion.selectCurrent': (editorUid: number, state: any) => Promise<any>
7
11
  'EditorCompletion.selectIndex': (editorUid: number, state: any, index: number) => Promise<any>
8
- 'Hover.getHoverInfo': (editorUid: number, position: any) => Promise<any>
9
- 'Font.ensure': (fontName: string, fontUrl: string) => Promise<void>
10
- 'Editor.create': (options: any) => Promise<void>
11
- 'Editor.render': (editorUid: number) => Promise<any>
12
- 'FindWidget.loadContent': (editorUid: number) => Promise<any>
13
- 'FindWidget.handleInput': (state: any, value: string) => Promise<any>
14
- 'FindWidget.focusIndex': (state: any, index: number) => Promise<any>
15
12
  'FindWidget.focusFirst': (state: any) => Promise<any>
13
+ 'FindWidget.focusIndex': (state: any, index: number) => Promise<any>
16
14
  'FindWidget.focusLast': (state: any) => Promise<any>
17
15
  'FindWidget.focusNext': (state: any) => Promise<any>
18
16
  'FindWidget.focusPrevious': (state: any) => Promise<any>
19
- 'Editor.offsetAt': (textDocument: any, positionRowIndex: number, positionColumnIndex: number) => Promise<any>
17
+ 'FindWidget.handleInput': (state: any, value: string) => Promise<any>
18
+ 'FindWidget.loadContent': (editorUid: number) => Promise<any>
19
+ 'Font.ensure': (fontName: string, fontUrl: string) => Promise<void>
20
+ 'Hover.getHoverInfo': (editorUid: number, position: any) => Promise<any>
21
+ 'Hover.handleSashPointerDown': (state: any, eventX: number, eventY: number) => Promise<any>
22
+ 'Hover.handleSashPointerMove': (state: any, eventX: number, eventY: number) => Promise<any>
23
+ 'Hover.handleSashPointerUp': (state: any, eventX: number, eventY: number) => Promise<any>
24
+ 'Hover.render': (oldState: any, newState: any) => Promise<any>
20
25
  }
21
26
 
22
27
  export interface EditorWorkerApi {
@@ -71,7 +71,7 @@ const getNewColor = (x, max) => {
71
71
  const newColor = `hsl(${hue}, 100%, 50%)`;
72
72
  return newColor;
73
73
  };
74
- const loadContent$2 = state => {
74
+ const loadContent$3 = state => {
75
75
  const max = 300;
76
76
  const x = 20;
77
77
  const color = getNewColor(x, max);
@@ -6571,7 +6571,7 @@ const disposeWithEditor = (state, editor) => {
6571
6571
  };
6572
6572
  const handleEditorClick = disposeWithEditor;
6573
6573
  const handleEditorBlur = disposeWithEditor;
6574
- const loadContent$1 = async (editorUid, state) => {
6574
+ const loadContent$2 = async (editorUid, state) => {
6575
6575
  const editor = getEditor(editorUid);
6576
6576
  const {
6577
6577
  itemHeight,
@@ -6646,8 +6646,8 @@ const select = async (state, editor, completionItem) => {
6646
6646
  editor.completionState = None;
6647
6647
  editor.completionUid = 0;
6648
6648
  }
6649
- await execute$1('Editor.applyEdit', changes);
6650
- // await Viewlet.dispose(uid)
6649
+ await invoke$3('Editor.applyEdit', changes);
6650
+ await invoke$3('Viewlet.dispose', state.uid);
6651
6651
  return state;
6652
6652
  };
6653
6653
  const selectIndex = (editorUid, state, index) => {
@@ -6717,7 +6717,7 @@ const getMatchCount = matches => {
6717
6717
  return matches.length / 2;
6718
6718
  };
6719
6719
 
6720
- const loadContent = editorId => {
6720
+ const loadContent$1 = editorId => {
6721
6721
  const editor = getEditor(editorId);
6722
6722
  const {
6723
6723
  selections,
@@ -7665,6 +7665,12 @@ const Diagnostic = 'Diagnostic';
7665
7665
  const EditorCursor = 'EditorCursor';
7666
7666
  const EditorRow = 'EditorRow';
7667
7667
  const EditorSelection = 'EditorSelection';
7668
+ const HoverDisplayString = 'HoverDisplayString';
7669
+ const HoverDocumentation = 'HoverDocumentation';
7670
+ const HoverEditorRow = 'HoverEditorRow';
7671
+ const HoverProblem = 'HoverProblem';
7672
+ const HoverProblemDetail = 'HoverProblemDetail';
7673
+ const HoverProblemMessage = 'HoverProblemMessage';
7668
7674
  const Viewlet = 'Viewlet';
7669
7675
 
7670
7676
  const getCursorsVirtualDom = cursors => {
@@ -7924,7 +7930,7 @@ const renderGutterInfo = {
7924
7930
  return ['renderGutter', dom];
7925
7931
  }
7926
7932
  };
7927
- const render$1 = [renderLines, renderSelections, renderScrollBarX, renderScrollBarY, renderFocus, renderDecorations, renderGutterInfo];
7933
+ const render$2 = [renderLines, renderSelections, renderScrollBarX, renderScrollBarY, renderFocus, renderDecorations, renderGutterInfo];
7928
7934
  const renderEditor = async id => {
7929
7935
  const instance = get$6(id);
7930
7936
  if (!instance) {
@@ -7936,7 +7942,7 @@ const renderEditor = async id => {
7936
7942
  } = instance;
7937
7943
  const commands = [];
7938
7944
  set$6(id, newState, newState);
7939
- for (const item of render$1) {
7945
+ for (const item of render$2) {
7940
7946
  if (!item.isEqual(oldState, newState)) {
7941
7947
  commands.push(await item.apply(oldState, newState));
7942
7948
  }
@@ -7944,7 +7950,7 @@ const renderEditor = async id => {
7944
7950
  return commands;
7945
7951
  };
7946
7952
 
7947
- const keep = ['ColorPicker.handleSliderPointerDown', 'ColorPicker.handleSliderPointerMove', 'ColorPicker.loadContent', 'Editor.create', 'Editor.getWordAt', 'Editor.getWordBefore', 'Editor.offsetAt', 'Editor.render', 'FindWidget.focusFirst', 'FindWidget.focusIndex', 'FindWidget.focusLast', 'FindWidget.focusNext', 'FindWidget.focusPrevious', 'FindWidget.handleInput', 'FindWidget.loadContent', 'Font.ensure', 'Hover.getHoverInfo', 'Initialize.initialize', 'EditorCompletion.advance', 'EditorCompletion.handleEditorBlur', 'EditorCompletion.handleEditorClick', 'EditorCompletion.handleEditorDeleteLeft', 'EditorCompletion.handleEditorType', 'EditorCompletion.loadContent', 'EditorCompletion.selectCurrent', 'EditorCompletion.selectIndex', 'ColorPicker.render'];
7953
+ const keep = ['ColorPicker.handleSliderPointerDown', 'ColorPicker.handleSliderPointerMove', 'ColorPicker.loadContent', 'Editor.create', 'Editor.getWordAt', 'Editor.getWordBefore', 'Editor.offsetAt', 'Editor.render', 'FindWidget.focusFirst', 'FindWidget.focusIndex', 'FindWidget.focusLast', 'FindWidget.focusNext', 'FindWidget.focusPrevious', 'FindWidget.handleInput', 'FindWidget.loadContent', 'Font.ensure', 'Hover.getHoverInfo', 'Initialize.initialize', 'EditorCompletion.advance', 'EditorCompletion.handleEditorBlur', 'EditorCompletion.handleEditorClick', 'EditorCompletion.handleEditorDeleteLeft', 'EditorCompletion.handleEditorType', 'EditorCompletion.loadContent', 'EditorCompletion.selectCurrent', 'EditorCompletion.selectIndex', 'ColorPicker.render', 'Hover.render', 'Hover.loadContent', 'Hover.handleSashPointerDown', 'Hover.handleSashPointerMove', 'Hover.handleSashPointerUp'];
7948
7954
 
7949
7955
  // TODO wrap commands globally, not per editor
7950
7956
  // TODO only store editor state in editor worker, not in renderer worker also
@@ -7967,6 +7973,7 @@ const wrapCommands = commands => {
7967
7973
  };
7968
7974
 
7969
7975
  const HandlePointerDown = 'handlePointerDown';
7976
+ const HandleSashPointerDown = 'handleSashPointerDown';
7970
7977
 
7971
7978
  const mergeClassNames = (...classNames) => {
7972
7979
  return classNames.filter(Boolean).join(' ');
@@ -8005,6 +8012,7 @@ const getColorPickerVirtualDom = () => {
8005
8012
  }];
8006
8013
  };
8007
8014
 
8015
+ const SetBounds = 'setBounds';
8008
8016
  const SetColor = 'setColor';
8009
8017
  const SetOffsetX = 'setOffsetX';
8010
8018
 
@@ -8033,8 +8041,168 @@ const renderColorPickerDom = {
8033
8041
  return ['Viewlet.setDom2', dom];
8034
8042
  }
8035
8043
  };
8036
- const render = [renderColorPickerDom, renderColor, renderOffsetX];
8044
+ const render$1 = [renderColorPickerDom, renderColor, renderOffsetX];
8037
8045
  const renderColorPicker = async (oldState, newState) => {
8046
+ const commands = [];
8047
+ for (const item of render$1) {
8048
+ if (!item.isEqual(oldState, newState)) {
8049
+ commands.push(item.apply(oldState, newState));
8050
+ }
8051
+ }
8052
+ return commands;
8053
+ };
8054
+
8055
+ const loadContent = async (editorUid, state, position) => {
8056
+ const hoverInfo = await getHover(editorUid, position);
8057
+ if (!hoverInfo) {
8058
+ return state;
8059
+ }
8060
+ const {
8061
+ lineInfos,
8062
+ documentation,
8063
+ x,
8064
+ y,
8065
+ matchingDiagnostics
8066
+ } = hoverInfo;
8067
+ return {
8068
+ ...state,
8069
+ lineInfos,
8070
+ documentation,
8071
+ x,
8072
+ y,
8073
+ diagnostics: matchingDiagnostics
8074
+ };
8075
+ };
8076
+ const handleSashPointerDown = (state, eventX, eventY) => {
8077
+ return state;
8078
+ };
8079
+ const handleSashPointerMove = (state, eventX, eventY) => {
8080
+ // @ts-ignore
8081
+ const {
8082
+ x,
8083
+ y
8084
+ } = state;
8085
+ const minWidth = 100;
8086
+ const newWidth = Math.max(eventX - x, minWidth);
8087
+ return {
8088
+ ...state,
8089
+ resizedWidth: newWidth
8090
+ };
8091
+ };
8092
+ const handleSashPointerUp = (state, eventX, eventY) => {
8093
+ return state;
8094
+ };
8095
+
8096
+ const getLineInfoVirtualDom = lineInfo => {
8097
+ const dom = [{
8098
+ type: Div,
8099
+ className: HoverEditorRow,
8100
+ childCount: lineInfo.length / 2
8101
+ }];
8102
+ for (let i = 0; i < lineInfo.length; i += 2) {
8103
+ const tokenText = lineInfo[i];
8104
+ const tokenClass = lineInfo[i + 1];
8105
+ dom.push({
8106
+ type: Span,
8107
+ className: tokenClass,
8108
+ childCount: 1
8109
+ },
8110
+ // @ts-ignore
8111
+ text(tokenText));
8112
+ }
8113
+ return dom;
8114
+ };
8115
+ const getLineInfosVirtualDom = lineInfos => {
8116
+ const dom = lineInfos.flatMap(getLineInfoVirtualDom);
8117
+ return dom;
8118
+ };
8119
+
8120
+ const hoverProblemMessage = {
8121
+ type: Span,
8122
+ className: HoverProblemMessage,
8123
+ childCount: 1
8124
+ };
8125
+ const hoverProblemDetail = {
8126
+ type: Span,
8127
+ className: HoverProblemDetail,
8128
+ childCount: 1
8129
+ };
8130
+ const getChildCount = (lineInfos, documentation, diagnostics) => {
8131
+ return lineInfos.length + documentation ? 1 : 0 + (diagnostics && diagnostics.length > 0) ? 1 : 0;
8132
+ };
8133
+ const getHoverVirtualDom = (lineInfos, documentation, diagnostics) => {
8134
+ const dom = [];
8135
+ dom.push({
8136
+ type: Div,
8137
+ className: 'Viewlet EditorHover',
8138
+ childCount: getChildCount(lineInfos, documentation, diagnostics) + 1
8139
+ });
8140
+ if (diagnostics && diagnostics.length > 0) {
8141
+ dom.push({
8142
+ type: Div,
8143
+ className: `${HoverDisplayString} ${HoverProblem}`,
8144
+ childCount: diagnostics.length * 2
8145
+ });
8146
+ for (const diagnostic of diagnostics) {
8147
+ dom.push(hoverProblemMessage, text(diagnostic.message), hoverProblemDetail, text(`${diagnostic.source} (${diagnostic.code})`));
8148
+ }
8149
+ }
8150
+ if (lineInfos.length > 0) {
8151
+ const lineInfosDom = getLineInfosVirtualDom(lineInfos);
8152
+ dom.push({
8153
+ type: Div,
8154
+ className: HoverDisplayString,
8155
+ childCount: lineInfos.length
8156
+ }, ...lineInfosDom);
8157
+ }
8158
+ if (documentation) {
8159
+ dom.push({
8160
+ type: Div,
8161
+ className: HoverDocumentation,
8162
+ childCount: 1
8163
+ }, text(documentation));
8164
+ }
8165
+ dom.push({
8166
+ type: Div,
8167
+ className: 'Sash SashVertical SashResize',
8168
+ childCount: 0,
8169
+ onPointerDown: HandleSashPointerDown
8170
+ });
8171
+ console.log({
8172
+ dom
8173
+ });
8174
+ return dom;
8175
+ };
8176
+
8177
+ const renderHoverDom = {
8178
+ isEqual(oldState, newState) {
8179
+ return oldState.lineInfos === newState.lineInfos && oldState.documentation === newState.documentation && oldState.minLineY === newState.minLineY && oldState.maxLineY === newState.maxLineY && oldState.diagnostics === newState.diagnostics;
8180
+ },
8181
+ apply(oldState, newState) {
8182
+ const dom = getHoverVirtualDom(newState.lineInfos, newState.documentation, newState.diagnostics);
8183
+ return [/* method */'Viewlet.setDom2', dom];
8184
+ }
8185
+ };
8186
+ const renderBounds = {
8187
+ isEqual(oldState, newState) {
8188
+ return oldState.x === newState.x && oldState.y === newState.y && oldState.resizedWidth === newState.resizedWidth;
8189
+ },
8190
+ apply(oldState, newState) {
8191
+ // @ts-ignore
8192
+ const {
8193
+ x,
8194
+ y,
8195
+ width,
8196
+ height,
8197
+ resizedWidth,
8198
+ uid
8199
+ } = newState;
8200
+ console.log('apply');
8201
+ return [SetBounds, x, y, resizedWidth, height];
8202
+ }
8203
+ };
8204
+ const render = [renderHoverDom, renderBounds];
8205
+ const renderHover = async (oldState, newState) => {
8038
8206
  const commands = [];
8039
8207
  for (const item of render) {
8040
8208
  if (!item.isEqual(oldState, newState)) {
@@ -8047,7 +8215,7 @@ const renderColorPicker = async (oldState, newState) => {
8047
8215
  const commandMap = {
8048
8216
  'ColorPicker.handleSliderPointerDown': handleSliderPointerDown,
8049
8217
  'ColorPicker.handleSliderPointerMove': handleSliderPointerMove,
8050
- 'ColorPicker.loadContent': loadContent$2,
8218
+ 'ColorPicker.loadContent': loadContent$3,
8051
8219
  'ColorPicker.render': renderColorPicker,
8052
8220
  'Editor.addCursorAbove': addCursorAbove,
8053
8221
  'Editor.addCursorBelow': addCursorBelow,
@@ -8172,7 +8340,7 @@ const commandMap = {
8172
8340
  'EditorCompletion.handleEditorClick': handleEditorClick,
8173
8341
  'EditorCompletion.handleEditorDeleteLeft': handleEditorDeleteLeft,
8174
8342
  'EditorCompletion.handleEditorType': handleEditorType,
8175
- 'EditorCompletion.loadContent': loadContent$1,
8343
+ 'EditorCompletion.loadContent': loadContent$2,
8176
8344
  'EditorCompletion.selectCurrent': selectCurrent,
8177
8345
  'EditorCompletion.selectIndex': selectIndex,
8178
8346
  'FindWidget.focusFirst': focusFirst,
@@ -8181,9 +8349,14 @@ const commandMap = {
8181
8349
  'FindWidget.focusNext': focusNext,
8182
8350
  'FindWidget.focusPrevious': focusPrevious,
8183
8351
  'FindWidget.handleInput': handleInput,
8184
- 'FindWidget.loadContent': loadContent,
8352
+ 'FindWidget.loadContent': loadContent$1,
8185
8353
  'Font.ensure': ensure,
8186
8354
  'Hover.getHoverInfo': getEditorHoverInfo,
8355
+ 'Hover.handleSashPointerDown': handleSashPointerDown,
8356
+ 'Hover.handleSashPointerMove': handleSashPointerMove,
8357
+ 'Hover.handleSashPointerUp': handleSashPointerUp,
8358
+ 'Hover.render': renderHover,
8359
+ 'Hover.loadContent': loadContent,
8187
8360
  'Initialize.initialize': intialize
8188
8361
  };
8189
8362
  wrapCommands(commandMap);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lvce-editor/editor-worker",
3
- "version": "1.9.0",
3
+ "version": "1.11.0",
4
4
  "description": "",
5
5
  "main": "dist/testWorkerMain.js",
6
6
  "type": "module",