@lvce-editor/settings-view 1.0.0 → 1.1.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 +236 -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,232 @@ 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 Div = 4;
|
|
985
|
+
const H1 = 5;
|
|
986
|
+
const Text = 12;
|
|
987
|
+
const VirtualDomElements = {
|
|
988
|
+
__proto__: null,
|
|
989
|
+
Div,
|
|
990
|
+
H1};
|
|
991
|
+
const text = data => {
|
|
992
|
+
return {
|
|
993
|
+
type: Text,
|
|
994
|
+
text: data,
|
|
995
|
+
childCount: 0
|
|
996
|
+
};
|
|
997
|
+
};
|
|
998
|
+
|
|
999
|
+
const getSettingsDom = state => {
|
|
1000
|
+
return [{
|
|
1001
|
+
type: VirtualDomElements.Div,
|
|
1002
|
+
childCount: 1
|
|
1003
|
+
}, {
|
|
1004
|
+
type: VirtualDomElements.H1,
|
|
1005
|
+
childCount: 1
|
|
1006
|
+
}, text('Settings Dom: TODO')];
|
|
1007
|
+
};
|
|
1008
|
+
|
|
1009
|
+
const renderItems = (oldState, newState) => {
|
|
1010
|
+
const dom = getSettingsDom();
|
|
1011
|
+
return ['Viewlet.setDom2', newState.id, dom];
|
|
1012
|
+
};
|
|
1013
|
+
|
|
1014
|
+
const getRenderer = diffType => {
|
|
1015
|
+
switch (diffType) {
|
|
1016
|
+
case RenderItems:
|
|
1017
|
+
return renderItems;
|
|
1018
|
+
default:
|
|
1019
|
+
throw new Error('unknown renderer');
|
|
1020
|
+
}
|
|
1021
|
+
};
|
|
1022
|
+
|
|
1023
|
+
const applyRender = (oldState, newState, diffResult) => {
|
|
1024
|
+
const commands = [];
|
|
1025
|
+
for (const item of diffResult) {
|
|
1026
|
+
const fn = getRenderer(item);
|
|
1027
|
+
commands.push(fn(oldState, newState));
|
|
1028
|
+
}
|
|
1029
|
+
return commands;
|
|
1030
|
+
};
|
|
1031
|
+
|
|
1032
|
+
const render2 = (uid, diffResult) => {
|
|
1033
|
+
const {
|
|
1034
|
+
oldState,
|
|
1035
|
+
newState
|
|
1036
|
+
} = get$1(uid);
|
|
1037
|
+
set$1(uid, newState, newState);
|
|
1038
|
+
const commands = applyRender(oldState, newState, diffResult);
|
|
1039
|
+
return commands;
|
|
1040
|
+
};
|
|
1041
|
+
|
|
1042
|
+
const renderActions = () => {
|
|
1043
|
+
return [];
|
|
1044
|
+
};
|
|
1045
|
+
|
|
1046
|
+
const commandMap = {
|
|
1047
|
+
'Initialize.initialize': initialize,
|
|
1048
|
+
'Settings.create': create$1,
|
|
1049
|
+
'Settings.getCommandIds': getCommandIds,
|
|
1050
|
+
'Settings.terminate': terminate,
|
|
1051
|
+
'Settings.diff2': diff2,
|
|
1052
|
+
'Settings.loadContent': wrapCommand(loadContent),
|
|
1053
|
+
'Settings.renderActions': renderActions,
|
|
1054
|
+
'Settings.render2': render2
|
|
1055
|
+
};
|
|
834
1056
|
|
|
835
1057
|
const rpcs = Object.create(null);
|
|
836
1058
|
const set$g = (id, rpc) => {
|
|
@@ -873,9 +1095,11 @@ const RendererWorker = {
|
|
|
873
1095
|
set: set$3};
|
|
874
1096
|
|
|
875
1097
|
const {
|
|
876
|
-
set
|
|
1098
|
+
set
|
|
1099
|
+
} = RendererWorker;
|
|
877
1100
|
|
|
878
1101
|
const listen = async () => {
|
|
1102
|
+
registerCommands(commandMap);
|
|
879
1103
|
const rpc = await WebWorkerRpcClient.create({
|
|
880
1104
|
commandMap: commandMap
|
|
881
1105
|
});
|