goblin-laboratory 2.2.1 → 2.2.2

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.
Files changed (62) hide show
  1. package/.editorconfig +9 -9
  2. package/.eslintrc.js +28 -28
  3. package/.zou-flow +3 -3
  4. package/README.md +107 -107
  5. package/carnotzet.js +10 -10
  6. package/config.js +13 -13
  7. package/laboratory.js +13 -13
  8. package/lib/.webpack-config.js +53 -53
  9. package/lib/carnotzet.js +118 -118
  10. package/lib/helpers.js +16 -16
  11. package/lib/index.js +66 -66
  12. package/package.json +47 -47
  13. package/widgets/connect-helpers/arrayEquals.js +5 -5
  14. package/widgets/connect-helpers/arraysEquals.js +24 -24
  15. package/widgets/connect-helpers/c.js +99 -99
  16. package/widgets/connect-helpers/join-models.js +16 -16
  17. package/widgets/connect-helpers/with-c.js +276 -276
  18. package/widgets/devtools.js +5 -5
  19. package/widgets/disconnect-overlay/styles.js +50 -50
  20. package/widgets/disconnect-overlay/widget.js +40 -40
  21. package/widgets/fields-view/widget.js +34 -34
  22. package/widgets/form/index.js +79 -79
  23. package/widgets/frame/widget.js +47 -47
  24. package/widgets/frontend-form/reducer.js +18 -18
  25. package/widgets/frontend-form/widget.js +15 -15
  26. package/widgets/importer/default.js +14 -14
  27. package/widgets/importer/importer.js +54 -53
  28. package/widgets/importer/index.js +4 -4
  29. package/widgets/index-browsers.js +195 -195
  30. package/widgets/index-electron-ws.js +153 -153
  31. package/widgets/index-electron.js +69 -69
  32. package/widgets/index.js +1 -1
  33. package/widgets/laboratory/service.js +542 -542
  34. package/widgets/laboratory/widget.js +98 -98
  35. package/widgets/maintenance/styles.js +38 -38
  36. package/widgets/maintenance/widget.js +65 -65
  37. package/widgets/props-binder/widget.js +48 -48
  38. package/widgets/renderer.js +85 -85
  39. package/widgets/root/index.js +54 -54
  40. package/widgets/searchkit/index.js +68 -68
  41. package/widgets/store/backend-reducer.js +116 -116
  42. package/widgets/store/commands-reducer.js +14 -14
  43. package/widgets/store/middlewares.js +171 -171
  44. package/widgets/store/network-reducer.js +23 -23
  45. package/widgets/store/root-reducer.js +35 -35
  46. package/widgets/store/store.js +40 -40
  47. package/widgets/store/widgets-reducer.js +95 -95
  48. package/widgets/theme-context/js-to-css.js +20 -20
  49. package/widgets/theme-context/widget.js +130 -130
  50. package/widgets/view/index.js +31 -31
  51. package/widgets/widget/index.js +1205 -1205
  52. package/widgets/widget/utils/connect.js +47 -47
  53. package/widgets/widget/utils/connectBackend.js +48 -48
  54. package/widgets/widget/utils/connectWidget.js +31 -31
  55. package/widgets/widget/utils/manifest.txt +134 -134
  56. package/widgets/widget/utils/shallowEqualShredder.js +36 -36
  57. package/widgets/widget/utils/widgets-actions.js +21 -21
  58. package/widgets/widget/utils/wrapMapStateToProps.js +26 -26
  59. package/widgets/with-desktop-id/widget.js +20 -20
  60. package/widgets/with-model/context.js +5 -5
  61. package/widgets/with-model/widget.js +42 -42
  62. package/widgets/with-workitem/widget.js +30 -30
@@ -1,171 +1,171 @@
1
- //T:2019-02-27
2
- import _ from 'lodash';
3
- import helpers from 'xcraft-core-transport/lib/helpers.js';
4
-
5
- let nextGeneration = -1;
6
- const compensatorStates = {};
7
- let compensatorTimeout = null;
8
-
9
- function insertCompensators(store, action) {
10
- /* Provide the compensatored states to the reducer */
11
- action.compensatorStates = compensatorStates;
12
-
13
- /* (Re)start a timeout in case of no more NEW_BACKEND_STATE are received */
14
- if (compensatorTimeout) {
15
- clearTimeout(compensatorTimeout);
16
- compensatorTimeout = null;
17
- }
18
-
19
- if (Object.keys(compensatorStates).length) {
20
- compensatorTimeout = setTimeout(() => {
21
- store.dispatch({type: 'COMPENSATORS', compensatorStates});
22
- }, 300);
23
- }
24
- }
25
-
26
- const questMiddleware = (send) => (store) => (next) => (action) => {
27
- if (action.type === 'QUEST') {
28
- /* Provide the compensatored states to the reducer */
29
- insertCompensators(store, action);
30
-
31
- send('QUEST', action);
32
- }
33
- return next(action);
34
- };
35
-
36
- //TODO: better handling of model/service field
37
- const handleChange = (send, action, registry) => {
38
- const model = action.model.replace('backend.', '');
39
- const fields = model.split('.');
40
- if (fields.length === 0) {
41
- return;
42
- }
43
- const goblinId = fields.shift();
44
- let goblin = goblinId;
45
- if (goblin.indexOf('@') !== -1) {
46
- goblin = goblin.split('@')[0];
47
- }
48
- const _xcraftIPC = action.value !== null && typeof action.value === 'object';
49
- const changeFieldCommand = `${goblin}.change-${fields.join('.')}`;
50
- if (registry[changeFieldCommand]) {
51
- const questAction = {
52
- type: 'QUEST',
53
- cmd: changeFieldCommand,
54
- data: {
55
- id: goblinId,
56
- newValue: action.value,
57
- clientSessionId: action.clientSessionId,
58
- },
59
- _xcraftIPC,
60
- };
61
- send('QUEST', questAction);
62
- }
63
-
64
- const command = `${goblin}.change`;
65
- if (registry[command]) {
66
- const questAction = {
67
- type: 'QUEST',
68
- cmd: command,
69
- data: {
70
- id: goblinId,
71
- path: fields.join('.'),
72
- newValue: action.value,
73
- clientSessionId: action.clientSessionId,
74
- },
75
- _xcraftIPC,
76
- };
77
- send('QUEST', questAction);
78
- }
79
- };
80
-
81
- const handleChangeWithThrottle = _.debounce(handleChange, 200);
82
-
83
- const formMiddleware = (send) => (store) => (next) => (action) => {
84
- switch (action.type) {
85
- case 'FIELD-CHANGED':
86
- {
87
- if (action.path.startsWith('backend')) {
88
- const clientSessionId = store
89
- .getState()
90
- .backend.get(window.labId)
91
- .get('clientSessionId');
92
- handleChange(
93
- send,
94
- {model: action.path, value: action.value, clientSessionId},
95
- store.getState().commands.get('registry')
96
- );
97
- }
98
- }
99
- break;
100
- case 'rrf/batch': {
101
- for (const a of action.actions) {
102
- if (a.type === 'rrf/change' && !a.load) {
103
- handleChange(send, a, store.getState().commands.get('registry'));
104
- }
105
- }
106
- break;
107
- }
108
- case 'rrf/change': {
109
- if (!action.load) {
110
- handleChange(send, action, store.getState().commands.get('registry'));
111
- }
112
- break;
113
- }
114
- case 'hinter/search': {
115
- handleChangeWithThrottle(
116
- send,
117
- action,
118
- store.getState().commands.get('registry')
119
- );
120
- break;
121
- }
122
- }
123
- return next(action);
124
- };
125
-
126
- const transitMiddleware = (store) => (next) => (action) => {
127
- if (
128
- action.type === 'NEW_BACKEND_STATE' &&
129
- action.data &&
130
- action.data._xcraftMessage
131
- ) {
132
- action.data = helpers.fromXcraftJSON(action.data)[0].data;
133
-
134
- const generation = action.data.get('generation');
135
- if (action.data.get('_xcraftPatch')) {
136
- nextGeneration++;
137
-
138
- if (generation !== nextGeneration) {
139
- /* Resend the whole state because in this case, we lose some generations. */
140
- console.log(
141
- `${generation - nextGeneration - 1} generation(s) lost, resend`
142
- );
143
- action.renderer.send('RESEND');
144
- }
145
- } else {
146
- nextGeneration = generation;
147
- }
148
- action.nextGeneration = nextGeneration;
149
-
150
- insertCompensators(store, action);
151
- }
152
- return next(action);
153
- };
154
-
155
- export default (send) => {
156
- const _send = (type, action) => {
157
- let data = action;
158
- if (action.type === 'QUEST') {
159
- data = helpers.toXcraftJSON(action)[0];
160
- delete data.compensatorStates; /* only for the frontend and not serializable */
161
- }
162
-
163
- send(type, data);
164
- };
165
-
166
- return {
167
- formMiddleware: formMiddleware(_send),
168
- questMiddleware: questMiddleware(_send),
169
- transitMiddleware,
170
- };
171
- };
1
+ //T:2019-02-27
2
+ import _ from 'lodash';
3
+ import helpers from 'xcraft-core-transport/lib/helpers.js';
4
+
5
+ let nextGeneration = -1;
6
+ const compensatorStates = {};
7
+ let compensatorTimeout = null;
8
+
9
+ function insertCompensators(store, action) {
10
+ /* Provide the compensatored states to the reducer */
11
+ action.compensatorStates = compensatorStates;
12
+
13
+ /* (Re)start a timeout in case of no more NEW_BACKEND_STATE are received */
14
+ if (compensatorTimeout) {
15
+ clearTimeout(compensatorTimeout);
16
+ compensatorTimeout = null;
17
+ }
18
+
19
+ if (Object.keys(compensatorStates).length) {
20
+ compensatorTimeout = setTimeout(() => {
21
+ store.dispatch({type: 'COMPENSATORS', compensatorStates});
22
+ }, 300);
23
+ }
24
+ }
25
+
26
+ const questMiddleware = (send) => (store) => (next) => (action) => {
27
+ if (action.type === 'QUEST') {
28
+ /* Provide the compensatored states to the reducer */
29
+ insertCompensators(store, action);
30
+
31
+ send('QUEST', action);
32
+ }
33
+ return next(action);
34
+ };
35
+
36
+ //TODO: better handling of model/service field
37
+ const handleChange = (send, action, registry) => {
38
+ const model = action.model.replace('backend.', '');
39
+ const fields = model.split('.');
40
+ if (fields.length === 0) {
41
+ return;
42
+ }
43
+ const goblinId = fields.shift();
44
+ let goblin = goblinId;
45
+ if (goblin.indexOf('@') !== -1) {
46
+ goblin = goblin.split('@')[0];
47
+ }
48
+ const _xcraftIPC = action.value !== null && typeof action.value === 'object';
49
+ const changeFieldCommand = `${goblin}.change-${fields.join('.')}`;
50
+ if (registry[changeFieldCommand]) {
51
+ const questAction = {
52
+ type: 'QUEST',
53
+ cmd: changeFieldCommand,
54
+ data: {
55
+ id: goblinId,
56
+ newValue: action.value,
57
+ clientSessionId: action.clientSessionId,
58
+ },
59
+ _xcraftIPC,
60
+ };
61
+ send('QUEST', questAction);
62
+ }
63
+
64
+ const command = `${goblin}.change`;
65
+ if (registry[command]) {
66
+ const questAction = {
67
+ type: 'QUEST',
68
+ cmd: command,
69
+ data: {
70
+ id: goblinId,
71
+ path: fields.join('.'),
72
+ newValue: action.value,
73
+ clientSessionId: action.clientSessionId,
74
+ },
75
+ _xcraftIPC,
76
+ };
77
+ send('QUEST', questAction);
78
+ }
79
+ };
80
+
81
+ const handleChangeWithThrottle = _.debounce(handleChange, 200);
82
+
83
+ const formMiddleware = (send) => (store) => (next) => (action) => {
84
+ switch (action.type) {
85
+ case 'FIELD-CHANGED':
86
+ {
87
+ if (action.path.startsWith('backend')) {
88
+ const clientSessionId = store
89
+ .getState()
90
+ .backend.get(window.labId)
91
+ .get('clientSessionId');
92
+ handleChange(
93
+ send,
94
+ {model: action.path, value: action.value, clientSessionId},
95
+ store.getState().commands.get('registry')
96
+ );
97
+ }
98
+ }
99
+ break;
100
+ case 'rrf/batch': {
101
+ for (const a of action.actions) {
102
+ if (a.type === 'rrf/change' && !a.load) {
103
+ handleChange(send, a, store.getState().commands.get('registry'));
104
+ }
105
+ }
106
+ break;
107
+ }
108
+ case 'rrf/change': {
109
+ if (!action.load) {
110
+ handleChange(send, action, store.getState().commands.get('registry'));
111
+ }
112
+ break;
113
+ }
114
+ case 'hinter/search': {
115
+ handleChangeWithThrottle(
116
+ send,
117
+ action,
118
+ store.getState().commands.get('registry')
119
+ );
120
+ break;
121
+ }
122
+ }
123
+ return next(action);
124
+ };
125
+
126
+ const transitMiddleware = (store) => (next) => (action) => {
127
+ if (
128
+ action.type === 'NEW_BACKEND_STATE' &&
129
+ action.data &&
130
+ action.data._xcraftMessage
131
+ ) {
132
+ action.data = helpers.fromXcraftJSON(action.data)[0].data;
133
+
134
+ const generation = action.data.get('generation');
135
+ if (action.data.get('_xcraftPatch')) {
136
+ nextGeneration++;
137
+
138
+ if (generation !== nextGeneration) {
139
+ /* Resend the whole state because in this case, we lose some generations. */
140
+ console.log(
141
+ `${generation - nextGeneration - 1} generation(s) lost, resend`
142
+ );
143
+ action.renderer.send('RESEND');
144
+ }
145
+ } else {
146
+ nextGeneration = generation;
147
+ }
148
+ action.nextGeneration = nextGeneration;
149
+
150
+ insertCompensators(store, action);
151
+ }
152
+ return next(action);
153
+ };
154
+
155
+ export default (send) => {
156
+ const _send = (type, action) => {
157
+ let data = action;
158
+ if (action.type === 'QUEST') {
159
+ data = helpers.toXcraftJSON(action)[0];
160
+ delete data.compensatorStates; /* only for the frontend and not serializable */
161
+ }
162
+
163
+ send(type, data);
164
+ };
165
+
166
+ return {
167
+ formMiddleware: formMiddleware(_send),
168
+ questMiddleware: questMiddleware(_send),
169
+ transitMiddleware,
170
+ };
171
+ };
@@ -1,23 +1,23 @@
1
- import {fromJS} from 'immutable';
2
-
3
- const initialState = fromJS({
4
- hordes: {},
5
- hasOverlay: false,
6
- });
7
-
8
- export default (state = initialState, action = {}) => {
9
- if (action.type === 'CONNECTION_STATUS') {
10
- state = state.setIn(['hordes', action.horde], {
11
- lag: action.lag,
12
- delta: action.delta,
13
- overlay: action.overlay,
14
- message: action.message,
15
- noSocket: action.noSocket,
16
- });
17
-
18
- const hasOverlay = state.get('hordes').some(({overlay}) => overlay);
19
- return state.set('hasOverlay', hasOverlay);
20
- }
21
-
22
- return state;
23
- };
1
+ import {fromJS} from 'immutable';
2
+
3
+ const initialState = fromJS({
4
+ hordes: {},
5
+ hasOverlay: false,
6
+ });
7
+
8
+ export default (state = initialState, action = {}) => {
9
+ if (action.type === 'CONNECTION_STATUS') {
10
+ state = state.setIn(['hordes', action.horde], {
11
+ lag: action.lag,
12
+ delta: action.delta,
13
+ overlay: action.overlay,
14
+ message: action.message,
15
+ noSocket: action.noSocket,
16
+ });
17
+
18
+ const hasOverlay = state.get('hordes').some(({overlay}) => overlay);
19
+ return state.set('hasOverlay', hasOverlay);
20
+ }
21
+
22
+ return state;
23
+ };
@@ -1,35 +1,35 @@
1
- import {combineReducers} from 'redux';
2
- import backendReducer from 'goblin-laboratory/widgets/store/backend-reducer';
3
- import commandsReducer from 'goblin-laboratory/widgets/store/commands-reducer';
4
- import networkReducer from 'goblin-laboratory/widgets/store/network-reducer';
5
- import widgetsReducer from 'goblin-laboratory/widgets/store/widgets-reducer';
6
-
7
- import Shredder from 'xcraft-core-shredder';
8
- /**
9
- * This action type will be dispatched when your history
10
- * receives a location change.
11
- */
12
- export const LOCATION_CHANGE = '@@router/LOCATION_CHANGE';
13
-
14
- const initialState = new Shredder({
15
- location: null,
16
- }).state;
17
-
18
- export function routerReducer(state = initialState, {type, payload} = {}) {
19
- if (type === LOCATION_CHANGE) {
20
- return state.merge({
21
- location: payload.location,
22
- action: payload.action,
23
- });
24
- }
25
-
26
- return state;
27
- }
28
-
29
- export default combineReducers({
30
- router: routerReducer,
31
- commands: commandsReducer,
32
- network: networkReducer,
33
- backend: backendReducer,
34
- widgets: widgetsReducer,
35
- });
1
+ import {combineReducers} from 'redux';
2
+ import backendReducer from 'goblin-laboratory/widgets/store/backend-reducer';
3
+ import commandsReducer from 'goblin-laboratory/widgets/store/commands-reducer';
4
+ import networkReducer from 'goblin-laboratory/widgets/store/network-reducer';
5
+ import widgetsReducer from 'goblin-laboratory/widgets/store/widgets-reducer';
6
+
7
+ import Shredder from 'xcraft-core-shredder';
8
+ /**
9
+ * This action type will be dispatched when your history
10
+ * receives a location change.
11
+ */
12
+ export const LOCATION_CHANGE = '@@router/LOCATION_CHANGE';
13
+
14
+ const initialState = new Shredder({
15
+ location: null,
16
+ }).state;
17
+
18
+ export function routerReducer(state = initialState, {type, payload} = {}) {
19
+ if (type === LOCATION_CHANGE) {
20
+ return state.merge({
21
+ location: payload.location,
22
+ action: payload.action,
23
+ });
24
+ }
25
+
26
+ return state;
27
+ }
28
+
29
+ export default combineReducers({
30
+ router: routerReducer,
31
+ commands: commandsReducer,
32
+ network: networkReducer,
33
+ backend: backendReducer,
34
+ widgets: widgetsReducer,
35
+ });
@@ -1,40 +1,40 @@
1
- import {applyMiddleware, compose, createStore} from 'redux';
2
- import {routerMiddleware} from 'connected-react-router/immutable';
3
- import thunk from 'redux-thunk';
4
- import middlewares from './middlewares';
5
-
6
- const rootReducer = require('goblin-laboratory/widgets/store/root-reducer')
7
- .default;
8
-
9
- export default function configureStore(initialState, history, send) {
10
- const {transitMiddleware, formMiddleware, questMiddleware} = middlewares(
11
- send
12
- );
13
- const routerHistory = routerMiddleware(history);
14
-
15
- const composeEnhancers =
16
- (process.env.NODE_ENV === 'development' &&
17
- window.__REDUX_DEVTOOLS_EXTENSION_COMPOSE__) ||
18
- compose;
19
-
20
- const finalCreateStore = composeEnhancers(
21
- // Middleware you want to use in development:
22
- applyMiddleware(
23
- thunk,
24
- routerHistory,
25
- transitMiddleware,
26
- questMiddleware,
27
- formMiddleware
28
- )
29
- )(createStore);
30
-
31
- const store = finalCreateStore(rootReducer, initialState);
32
- if (module.hot) {
33
- module.hot.accept('goblin-laboratory/widgets/store/root-reducer', () => {
34
- const nextRootReducer = require('goblin-laboratory/widgets/store/root-reducer')
35
- .default;
36
- store.replaceReducer(nextRootReducer);
37
- });
38
- }
39
- return store;
40
- }
1
+ import {applyMiddleware, compose, createStore} from 'redux';
2
+ import {routerMiddleware} from 'connected-react-router/immutable';
3
+ import thunk from 'redux-thunk';
4
+ import middlewares from './middlewares';
5
+
6
+ const rootReducer = require('goblin-laboratory/widgets/store/root-reducer')
7
+ .default;
8
+
9
+ export default function configureStore(initialState, history, send) {
10
+ const {transitMiddleware, formMiddleware, questMiddleware} = middlewares(
11
+ send
12
+ );
13
+ const routerHistory = routerMiddleware(history);
14
+
15
+ const composeEnhancers =
16
+ (process.env.NODE_ENV === 'development' &&
17
+ window.__REDUX_DEVTOOLS_EXTENSION_COMPOSE__) ||
18
+ compose;
19
+
20
+ const finalCreateStore = composeEnhancers(
21
+ // Middleware you want to use in development:
22
+ applyMiddleware(
23
+ thunk,
24
+ routerHistory,
25
+ transitMiddleware,
26
+ questMiddleware,
27
+ formMiddleware
28
+ )
29
+ )(createStore);
30
+
31
+ const store = finalCreateStore(rootReducer, initialState);
32
+ if (module.hot) {
33
+ module.hot.accept('goblin-laboratory/widgets/store/root-reducer', () => {
34
+ const nextRootReducer = require('goblin-laboratory/widgets/store/root-reducer')
35
+ .default;
36
+ store.replaceReducer(nextRootReducer);
37
+ });
38
+ }
39
+ return store;
40
+ }