@lvce-editor/settings-view 1.0.0 → 1.2.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/settingsViewWorkerMain.js +402 -12
- package/package.json +1 -1
|
@@ -378,32 +378,32 @@ const create$4 = (method, params) => {
|
|
|
378
378
|
};
|
|
379
379
|
};
|
|
380
380
|
const callbacks = Object.create(null);
|
|
381
|
-
const set$
|
|
381
|
+
const set$2 = (id, fn) => {
|
|
382
382
|
callbacks[id] = fn;
|
|
383
383
|
};
|
|
384
|
-
const get$
|
|
384
|
+
const get$2 = id => {
|
|
385
385
|
return callbacks[id];
|
|
386
386
|
};
|
|
387
387
|
const remove = id => {
|
|
388
388
|
delete callbacks[id];
|
|
389
389
|
};
|
|
390
390
|
let id = 0;
|
|
391
|
-
const create$3 = () => {
|
|
391
|
+
const create$3$1 = () => {
|
|
392
392
|
return ++id;
|
|
393
393
|
};
|
|
394
394
|
const registerPromise = () => {
|
|
395
|
-
const id = create$3();
|
|
395
|
+
const id = create$3$1();
|
|
396
396
|
const {
|
|
397
397
|
resolve,
|
|
398
398
|
promise
|
|
399
399
|
} = Promise.withResolvers();
|
|
400
|
-
set$
|
|
400
|
+
set$2(id, resolve);
|
|
401
401
|
return {
|
|
402
402
|
id,
|
|
403
403
|
promise
|
|
404
404
|
};
|
|
405
405
|
};
|
|
406
|
-
const create$2 = (method, params) => {
|
|
406
|
+
const create$2$1 = (method, params) => {
|
|
407
407
|
const {
|
|
408
408
|
id,
|
|
409
409
|
promise
|
|
@@ -561,7 +561,7 @@ const warn = (...args) => {
|
|
|
561
561
|
console.warn(...args);
|
|
562
562
|
};
|
|
563
563
|
const resolve = (id, response) => {
|
|
564
|
-
const fn = get$
|
|
564
|
+
const fn = get$2(id);
|
|
565
565
|
if (!fn) {
|
|
566
566
|
console.log(response);
|
|
567
567
|
warn(`callback ${id} may already be disposed`);
|
|
@@ -728,7 +728,7 @@ const invokeHelper = async (ipc, method, params, useSendAndTransfer) => {
|
|
|
728
728
|
const {
|
|
729
729
|
message,
|
|
730
730
|
promise
|
|
731
|
-
} = create$2(method, params);
|
|
731
|
+
} = create$2$1(method, params);
|
|
732
732
|
if (useSendAndTransfer && ipc.sendAndTransfer) {
|
|
733
733
|
ipc.sendAndTransfer(message);
|
|
734
734
|
} else {
|
|
@@ -815,7 +815,7 @@ const listen$1 = async (module, options) => {
|
|
|
815
815
|
const ipc = module.wrap(rawIpc);
|
|
816
816
|
return ipc;
|
|
817
817
|
};
|
|
818
|
-
const create$
|
|
818
|
+
const create$3 = async ({
|
|
819
819
|
commandMap
|
|
820
820
|
}) => {
|
|
821
821
|
// TODO create a commandMap per rpc instance
|
|
@@ -827,10 +827,398 @@ const create$1 = async ({
|
|
|
827
827
|
};
|
|
828
828
|
const WebWorkerRpcClient = {
|
|
829
829
|
__proto__: null,
|
|
830
|
-
create: create$
|
|
830
|
+
create: create$3
|
|
831
831
|
};
|
|
832
832
|
|
|
833
|
-
const
|
|
833
|
+
const toCommandId = key => {
|
|
834
|
+
const dotIndex = key.indexOf('.');
|
|
835
|
+
return key.slice(dotIndex + 1);
|
|
836
|
+
};
|
|
837
|
+
const create$2 = () => {
|
|
838
|
+
const states = Object.create(null);
|
|
839
|
+
const commandMapRef = {};
|
|
840
|
+
return {
|
|
841
|
+
get(uid) {
|
|
842
|
+
return states[uid];
|
|
843
|
+
},
|
|
844
|
+
set(uid, oldState, newState) {
|
|
845
|
+
states[uid] = {
|
|
846
|
+
oldState,
|
|
847
|
+
newState
|
|
848
|
+
};
|
|
849
|
+
},
|
|
850
|
+
dispose(uid) {
|
|
851
|
+
delete states[uid];
|
|
852
|
+
},
|
|
853
|
+
getKeys() {
|
|
854
|
+
return Object.keys(states).map(key => {
|
|
855
|
+
return Number.parseInt(key);
|
|
856
|
+
});
|
|
857
|
+
},
|
|
858
|
+
clear() {
|
|
859
|
+
for (const key of Object.keys(states)) {
|
|
860
|
+
delete states[key];
|
|
861
|
+
}
|
|
862
|
+
},
|
|
863
|
+
wrapCommand(fn) {
|
|
864
|
+
const wrapped = async (uid, ...args) => {
|
|
865
|
+
const {
|
|
866
|
+
newState
|
|
867
|
+
} = states[uid];
|
|
868
|
+
const newerState = await fn(newState, ...args);
|
|
869
|
+
if (newState === newerState) {
|
|
870
|
+
return;
|
|
871
|
+
}
|
|
872
|
+
const latest = states[uid];
|
|
873
|
+
states[uid] = {
|
|
874
|
+
oldState: latest.oldState,
|
|
875
|
+
newState: newerState
|
|
876
|
+
};
|
|
877
|
+
};
|
|
878
|
+
return wrapped;
|
|
879
|
+
},
|
|
880
|
+
wrapGetter(fn) {
|
|
881
|
+
const wrapped = (uid, ...args) => {
|
|
882
|
+
const {
|
|
883
|
+
newState
|
|
884
|
+
} = states[uid];
|
|
885
|
+
return fn(newState, ...args);
|
|
886
|
+
};
|
|
887
|
+
return wrapped;
|
|
888
|
+
},
|
|
889
|
+
diff(uid, modules, numbers) {
|
|
890
|
+
const {
|
|
891
|
+
oldState,
|
|
892
|
+
newState
|
|
893
|
+
} = states[uid];
|
|
894
|
+
const diffResult = [];
|
|
895
|
+
for (let i = 0; i < modules.length; i++) {
|
|
896
|
+
const fn = modules[i];
|
|
897
|
+
if (!fn(oldState, newState)) {
|
|
898
|
+
diffResult.push(numbers[i]);
|
|
899
|
+
}
|
|
900
|
+
}
|
|
901
|
+
return diffResult;
|
|
902
|
+
},
|
|
903
|
+
getCommandIds() {
|
|
904
|
+
const keys = Object.keys(commandMapRef);
|
|
905
|
+
const ids = keys.map(toCommandId);
|
|
906
|
+
return ids;
|
|
907
|
+
},
|
|
908
|
+
registerCommands(commandMap) {
|
|
909
|
+
Object.assign(commandMapRef, commandMap);
|
|
910
|
+
}
|
|
911
|
+
};
|
|
912
|
+
};
|
|
913
|
+
const terminate = () => {
|
|
914
|
+
globalThis.close();
|
|
915
|
+
};
|
|
916
|
+
|
|
917
|
+
const {
|
|
918
|
+
get: get$1,
|
|
919
|
+
set: set$1,
|
|
920
|
+
wrapCommand,
|
|
921
|
+
getCommandIds,
|
|
922
|
+
registerCommands
|
|
923
|
+
} = create$2();
|
|
924
|
+
|
|
925
|
+
const create$1 = (id, uri, x, y, width, height) => {
|
|
926
|
+
const state = {
|
|
927
|
+
breakPointsExpanded: false,
|
|
928
|
+
breakPointsVisible: false,
|
|
929
|
+
focus: 0,
|
|
930
|
+
id,
|
|
931
|
+
uri,
|
|
932
|
+
x,
|
|
933
|
+
y,
|
|
934
|
+
width,
|
|
935
|
+
height
|
|
936
|
+
};
|
|
937
|
+
set$1(id, state, state);
|
|
938
|
+
};
|
|
939
|
+
|
|
940
|
+
const isEqual$1 = (oldState, newState) => {
|
|
941
|
+
return oldState.focus === newState.focus;
|
|
942
|
+
};
|
|
943
|
+
|
|
944
|
+
const isEqual = (oldState, newState) => {
|
|
945
|
+
return oldState === newState;
|
|
946
|
+
};
|
|
947
|
+
|
|
948
|
+
const RenderItems = 1;
|
|
949
|
+
const RenderFocus = 2;
|
|
950
|
+
|
|
951
|
+
const modules = [isEqual$1, isEqual];
|
|
952
|
+
const numbers = [RenderFocus, RenderItems];
|
|
953
|
+
|
|
954
|
+
const diff = (oldState, newState) => {
|
|
955
|
+
const diffResult = [];
|
|
956
|
+
for (let i = 0; i < modules.length; i++) {
|
|
957
|
+
const fn = modules[i];
|
|
958
|
+
if (!fn(oldState, newState)) {
|
|
959
|
+
diffResult.push(numbers[i]);
|
|
960
|
+
}
|
|
961
|
+
}
|
|
962
|
+
return diffResult;
|
|
963
|
+
};
|
|
964
|
+
|
|
965
|
+
const diff2 = uid => {
|
|
966
|
+
const {
|
|
967
|
+
oldState,
|
|
968
|
+
newState
|
|
969
|
+
} = get$1(uid);
|
|
970
|
+
const diffResult = diff(oldState, newState);
|
|
971
|
+
return diffResult;
|
|
972
|
+
};
|
|
973
|
+
|
|
974
|
+
const initialize = async () => {
|
|
975
|
+
// TODO
|
|
976
|
+
};
|
|
977
|
+
|
|
978
|
+
const loadContent = async (state, savedState) => {
|
|
979
|
+
return {
|
|
980
|
+
...state
|
|
981
|
+
};
|
|
982
|
+
};
|
|
983
|
+
|
|
984
|
+
const Viewlet$1 = 'Viewlet';
|
|
985
|
+
const ClassNames = {
|
|
986
|
+
__proto__: null,
|
|
987
|
+
Viewlet: Viewlet$1};
|
|
988
|
+
const mergeClassNames = (...classNames) => {
|
|
989
|
+
return classNames.filter(Boolean).join(' ');
|
|
990
|
+
};
|
|
991
|
+
const Div = 4;
|
|
992
|
+
const H1 = 5;
|
|
993
|
+
const Text = 12;
|
|
994
|
+
const VirtualDomElements = {
|
|
995
|
+
__proto__: null,
|
|
996
|
+
Div,
|
|
997
|
+
H1};
|
|
998
|
+
const text = data => {
|
|
999
|
+
return {
|
|
1000
|
+
type: Text,
|
|
1001
|
+
text: data,
|
|
1002
|
+
childCount: 0
|
|
1003
|
+
};
|
|
1004
|
+
};
|
|
1005
|
+
|
|
1006
|
+
const {
|
|
1007
|
+
Viewlet} = ClassNames;
|
|
1008
|
+
const Settings = 'Settings';
|
|
1009
|
+
|
|
1010
|
+
const getSettingsDom = state => {
|
|
1011
|
+
return [{
|
|
1012
|
+
type: VirtualDomElements.Div,
|
|
1013
|
+
childCount: 1,
|
|
1014
|
+
className: mergeClassNames(Viewlet, Settings)
|
|
1015
|
+
}, {
|
|
1016
|
+
type: VirtualDomElements.H1,
|
|
1017
|
+
childCount: 1
|
|
1018
|
+
}, text('Settings Dom: TODO')];
|
|
1019
|
+
};
|
|
1020
|
+
|
|
1021
|
+
const renderItems = (oldState, newState) => {
|
|
1022
|
+
const dom = getSettingsDom();
|
|
1023
|
+
return ['Viewlet.setDom2', newState.id, dom];
|
|
1024
|
+
};
|
|
1025
|
+
|
|
1026
|
+
const getRenderer = diffType => {
|
|
1027
|
+
switch (diffType) {
|
|
1028
|
+
case RenderItems:
|
|
1029
|
+
return renderItems;
|
|
1030
|
+
default:
|
|
1031
|
+
throw new Error('unknown renderer');
|
|
1032
|
+
}
|
|
1033
|
+
};
|
|
1034
|
+
|
|
1035
|
+
const applyRender = (oldState, newState, diffResult) => {
|
|
1036
|
+
const commands = [];
|
|
1037
|
+
for (const item of diffResult) {
|
|
1038
|
+
const fn = getRenderer(item);
|
|
1039
|
+
commands.push(fn(oldState, newState));
|
|
1040
|
+
}
|
|
1041
|
+
return commands;
|
|
1042
|
+
};
|
|
1043
|
+
|
|
1044
|
+
const render2 = (uid, diffResult) => {
|
|
1045
|
+
const {
|
|
1046
|
+
oldState,
|
|
1047
|
+
newState
|
|
1048
|
+
} = get$1(uid);
|
|
1049
|
+
set$1(uid, newState, newState);
|
|
1050
|
+
const commands = applyRender(oldState, newState, diffResult);
|
|
1051
|
+
return commands;
|
|
1052
|
+
};
|
|
1053
|
+
|
|
1054
|
+
const renderActions = () => {
|
|
1055
|
+
return [];
|
|
1056
|
+
};
|
|
1057
|
+
|
|
1058
|
+
const HandleClickCallStackItem = 'handleClickCallStackItem';
|
|
1059
|
+
const HandleClickWatchExpression = 'handleClickWatchExpression';
|
|
1060
|
+
const HandleClickWatchExpressionDelete = 'handleClickWatchExpressionDelete';
|
|
1061
|
+
const HandleClickCheckBox = 'handleClickCheckBox';
|
|
1062
|
+
const HandleClickContinue = 'handleClickContinue';
|
|
1063
|
+
const HandleClickDebugButton = 'handleClickDebugButton';
|
|
1064
|
+
const HandleClickPause = 'handleClickPause';
|
|
1065
|
+
const HandleClickScopeValue = 'handleClickScopeValue';
|
|
1066
|
+
const HandleClickSectionBreakPoints = 'handleClickSectionBreakPoints';
|
|
1067
|
+
const HandleClickSectionCallstack = 'handleClickSectionCallstack';
|
|
1068
|
+
const HandleClickSectionHeading = 'handleClickSectionHeading';
|
|
1069
|
+
const HandleClickSectionScope = 'handleClickSectionScope';
|
|
1070
|
+
const HandleClickSectionWatch = 'handleClickSectionWatch';
|
|
1071
|
+
const HandleClickStepInto = 'handleClickStepInto';
|
|
1072
|
+
const HandleClickStepOut = 'handleClickStepOut';
|
|
1073
|
+
const HandleClickStepOver = 'handleClickStepOver';
|
|
1074
|
+
const HandleDebugInput = 'handleDebugInput';
|
|
1075
|
+
const HandleClickSectionAction = 'handleClickSectionAction';
|
|
1076
|
+
const HandleInputFieldChange = 'handleInputFieldChange';
|
|
1077
|
+
const HandleInputBlur = 'handleInputBlur';
|
|
1078
|
+
const HandleSectionHeaderContextMenu = 'handleSectionHeaderContextMenu';
|
|
1079
|
+
const HandleWatchExpressionContextMenu = 'handleWatchExpressionContextMenu';
|
|
1080
|
+
|
|
1081
|
+
// TODo use numeric ids
|
|
1082
|
+
|
|
1083
|
+
const renderEventListeners = () => {
|
|
1084
|
+
return [{
|
|
1085
|
+
name: HandleClickContinue,
|
|
1086
|
+
params: ['handleClickContinue']
|
|
1087
|
+
}, {
|
|
1088
|
+
name: HandleClickDebugButton,
|
|
1089
|
+
params: ['handleClickDebugButton', 'event.target.name']
|
|
1090
|
+
}, {
|
|
1091
|
+
name: HandleClickPause,
|
|
1092
|
+
params: ['handleClickPause']
|
|
1093
|
+
}, {
|
|
1094
|
+
name: HandleClickStepOver,
|
|
1095
|
+
params: ['handleClickStepOver']
|
|
1096
|
+
}, {
|
|
1097
|
+
name: HandleClickStepInto,
|
|
1098
|
+
params: ['handleClickStepInto']
|
|
1099
|
+
}, {
|
|
1100
|
+
name: HandleClickStepOut,
|
|
1101
|
+
params: ['handleClickStepOut']
|
|
1102
|
+
}, {
|
|
1103
|
+
name: HandleClickSectionWatch,
|
|
1104
|
+
params: ['HandleClickSectionWatch']
|
|
1105
|
+
}, {
|
|
1106
|
+
name: HandleClickSectionBreakPoints,
|
|
1107
|
+
params: ['handleClickSectionBreakpoints']
|
|
1108
|
+
}, {
|
|
1109
|
+
name: HandleClickSectionScope,
|
|
1110
|
+
params: ['handleClickSectionScope']
|
|
1111
|
+
}, {
|
|
1112
|
+
name: HandleClickSectionCallstack,
|
|
1113
|
+
params: ['handleClickSectionCallstack']
|
|
1114
|
+
}, {
|
|
1115
|
+
name: HandleClickSectionBreakPoints,
|
|
1116
|
+
params: ['handleClickSectionBreakPoints']
|
|
1117
|
+
}, {
|
|
1118
|
+
name: HandleDebugInput,
|
|
1119
|
+
params: ['handleDebugInput', 'event.target.value']
|
|
1120
|
+
}, {
|
|
1121
|
+
name: HandleClickSectionHeading,
|
|
1122
|
+
params: ['handleClickSectionHeading', 'event.target.dataset.name', 'event.button'],
|
|
1123
|
+
preventDefault: true
|
|
1124
|
+
}, {
|
|
1125
|
+
name: HandleClickCheckBox,
|
|
1126
|
+
params: ['handleClickCheckBox', 'event.target.name']
|
|
1127
|
+
}, {
|
|
1128
|
+
name: HandleClickDebugButton,
|
|
1129
|
+
params: ['handleClickDebugButton', 'event.target.name']
|
|
1130
|
+
}, {
|
|
1131
|
+
name: HandleClickCallStackItem,
|
|
1132
|
+
params: ['handleClickCallStackItem', 'event.target.dataset.index']
|
|
1133
|
+
}, {
|
|
1134
|
+
name: HandleClickWatchExpression,
|
|
1135
|
+
params: ['handleClickWatchExpression', 'event.target.dataset.index', 'event.defaultPrevented']
|
|
1136
|
+
}, {
|
|
1137
|
+
name: HandleClickWatchExpressionDelete,
|
|
1138
|
+
params: ['handleClickWatchExpressionDelete', 'event.target.dataset.index'],
|
|
1139
|
+
preventDefault: true
|
|
1140
|
+
}, {
|
|
1141
|
+
name: HandleClickScopeValue,
|
|
1142
|
+
params: ['handleClickScopeValue', 'event.target.dataset.index', 'event.button']
|
|
1143
|
+
}, {
|
|
1144
|
+
name: HandleInputFieldChange,
|
|
1145
|
+
params: ['handleInputFieldChange', 'event.target.name', 'event.target.value']
|
|
1146
|
+
}, {
|
|
1147
|
+
name: HandleClickSectionAction,
|
|
1148
|
+
params: ['handleClickSectionAction', 'event.target.name']
|
|
1149
|
+
}, {
|
|
1150
|
+
name: HandleInputBlur,
|
|
1151
|
+
params: ['handleInputBlur']
|
|
1152
|
+
}, {
|
|
1153
|
+
name: HandleSectionHeaderContextMenu,
|
|
1154
|
+
params: ['handleSectionHeaderContextMenu', 'event.clientX', 'event.clientY', 'event.target.dataset.name'],
|
|
1155
|
+
preventDefault: true
|
|
1156
|
+
}, {
|
|
1157
|
+
name: HandleWatchExpressionContextMenu,
|
|
1158
|
+
params: ['handleWatchExpressionContextMenu', 'event.clientX', 'event.clientY', 'event.target.dataset.index'],
|
|
1159
|
+
preventDefault: true
|
|
1160
|
+
}];
|
|
1161
|
+
};
|
|
1162
|
+
|
|
1163
|
+
const getSavedMinLineY = savedState => {
|
|
1164
|
+
if (savedState && typeof savedState === 'object' && 'minLineY' in savedState && typeof savedState.minLineY === 'number') {
|
|
1165
|
+
return savedState.minLineY;
|
|
1166
|
+
}
|
|
1167
|
+
return 0;
|
|
1168
|
+
};
|
|
1169
|
+
const getSavedDeltaY = savedState => {
|
|
1170
|
+
if (savedState && typeof savedState === 'object' && 'deltaY' in savedState && typeof savedState.deltaY === 'number') {
|
|
1171
|
+
return savedState.deltaY;
|
|
1172
|
+
}
|
|
1173
|
+
return 0;
|
|
1174
|
+
};
|
|
1175
|
+
const getSavedWorkspacePath = savedState => {
|
|
1176
|
+
if (savedState && typeof savedState === 'object' && 'workspacePath' in savedState && typeof savedState.workspacePath === 'string') {
|
|
1177
|
+
return savedState.workspacePath;
|
|
1178
|
+
}
|
|
1179
|
+
return '';
|
|
1180
|
+
};
|
|
1181
|
+
const restoreState = savedState => {
|
|
1182
|
+
if (!savedState) {
|
|
1183
|
+
return {
|
|
1184
|
+
root: '',
|
|
1185
|
+
minLineY: 0,
|
|
1186
|
+
deltaY: 0
|
|
1187
|
+
};
|
|
1188
|
+
}
|
|
1189
|
+
const root = getSavedWorkspacePath(savedState);
|
|
1190
|
+
const minLineY = getSavedMinLineY(savedState);
|
|
1191
|
+
const deltaY = getSavedDeltaY(savedState);
|
|
1192
|
+
return {
|
|
1193
|
+
root,
|
|
1194
|
+
minLineY,
|
|
1195
|
+
deltaY
|
|
1196
|
+
};
|
|
1197
|
+
};
|
|
1198
|
+
|
|
1199
|
+
const saveState = uid => {
|
|
1200
|
+
return {
|
|
1201
|
+
expandedPaths: [],
|
|
1202
|
+
root: '',
|
|
1203
|
+
minLineY: 0,
|
|
1204
|
+
maxLineY: 0,
|
|
1205
|
+
deltaY: 0
|
|
1206
|
+
};
|
|
1207
|
+
};
|
|
1208
|
+
|
|
1209
|
+
const commandMap = {
|
|
1210
|
+
'Initialize.initialize': initialize,
|
|
1211
|
+
'Settings.create': create$1,
|
|
1212
|
+
'Settings.diff2': diff2,
|
|
1213
|
+
'Settings.getCommandIds': getCommandIds,
|
|
1214
|
+
'Settings.loadContent': wrapCommand(loadContent),
|
|
1215
|
+
'Settings.render2': render2,
|
|
1216
|
+
'Settings.renderActions': renderActions,
|
|
1217
|
+
'Settings.renderEventListeners': renderEventListeners,
|
|
1218
|
+
'Settings.restoreState': restoreState,
|
|
1219
|
+
'Settings.saveState': saveState,
|
|
1220
|
+
'Settings.terminate': terminate
|
|
1221
|
+
};
|
|
834
1222
|
|
|
835
1223
|
const rpcs = Object.create(null);
|
|
836
1224
|
const set$g = (id, rpc) => {
|
|
@@ -873,9 +1261,11 @@ const RendererWorker = {
|
|
|
873
1261
|
set: set$3};
|
|
874
1262
|
|
|
875
1263
|
const {
|
|
876
|
-
set
|
|
1264
|
+
set
|
|
1265
|
+
} = RendererWorker;
|
|
877
1266
|
|
|
878
1267
|
const listen = async () => {
|
|
1268
|
+
registerCommands(commandMap);
|
|
879
1269
|
const rpc = await WebWorkerRpcClient.create({
|
|
880
1270
|
commandMap: commandMap
|
|
881
1271
|
});
|