@drayman/core 1.5.4 → 1.8.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/component-processor.js +30 -3
- package/dist/index.d.ts +2 -1
- package/dist/index.js +2 -2
- package/dist/utils.js +1 -1
- package/jsx-runtime.js +2 -2
- package/package.json +3 -3
|
@@ -97,14 +97,14 @@ const serializeComponentInstanceOptions = (options) => {
|
|
|
97
97
|
return serialized;
|
|
98
98
|
};
|
|
99
99
|
const renderedComps = {};
|
|
100
|
-
const initializeComponentInstance = async ({ componentInstanceId, browserCommands = [], extensionsPath, extensionsOptions, componentRootDir, componentName, componentOptions, componentNamePrefix = '' }) => {
|
|
100
|
+
const initializeComponentInstance = async ({ componentInstanceId, browserCommands = [], serverCommands = [], extensionsPath, extensionsOptions, componentRootDir, componentName, componentOptions, componentNamePrefix = '' }) => {
|
|
101
101
|
ComponentInstance.id = componentInstanceId;
|
|
102
102
|
if (extensionsPath) {
|
|
103
103
|
extensions = await require(path_1.default.join(process.cwd(), extensionsPath))(extensionsOptions);
|
|
104
104
|
}
|
|
105
105
|
const Browser = {};
|
|
106
106
|
for (const command of browserCommands) {
|
|
107
|
-
Browser[command] = async (data = {},
|
|
107
|
+
Browser[command] = async (data = {}, elements) => new Promise((resolve, reject) => {
|
|
108
108
|
const newData = {};
|
|
109
109
|
for (const key of Object.keys(data || {})) {
|
|
110
110
|
if (typeof data[key] === 'function') {
|
|
@@ -124,7 +124,32 @@ const initializeComponentInstance = async ({ componentInstanceId, browserCommand
|
|
|
124
124
|
callback: (response) => resolve(response),
|
|
125
125
|
once: true,
|
|
126
126
|
};
|
|
127
|
-
sendMessage({ type: 'browserCommand', payload: { data: newData, callbackId, command,
|
|
127
|
+
sendMessage({ type: 'browserCommand', payload: { data: newData, callbackId, command, elements } });
|
|
128
|
+
});
|
|
129
|
+
}
|
|
130
|
+
const Server = {};
|
|
131
|
+
for (const command of serverCommands) {
|
|
132
|
+
Server[command] = async (data = {}) => new Promise((resolve, reject) => {
|
|
133
|
+
const newData = {};
|
|
134
|
+
for (const key of Object.keys(data || {})) {
|
|
135
|
+
if (typeof data[key] === 'function') {
|
|
136
|
+
const callbackId = shortid_1.default.generate();
|
|
137
|
+
newData[key] = callbackId;
|
|
138
|
+
browserCallbacks[callbackId] = {
|
|
139
|
+
callback: async (response) => await data[key](response),
|
|
140
|
+
once: false,
|
|
141
|
+
};
|
|
142
|
+
}
|
|
143
|
+
else {
|
|
144
|
+
newData[key] = data[key];
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
const callbackId = shortid_1.default.generate();
|
|
148
|
+
browserCallbacks[callbackId] = {
|
|
149
|
+
callback: (response) => resolve(response),
|
|
150
|
+
once: true,
|
|
151
|
+
};
|
|
152
|
+
sendMessage({ type: 'serverCommand', payload: { data: newData, callbackId, command, } });
|
|
128
153
|
});
|
|
129
154
|
}
|
|
130
155
|
props = componentOptions || {};
|
|
@@ -163,6 +188,7 @@ const initializeComponentInstance = async ({ componentInstanceId, browserCommand
|
|
|
163
188
|
EventHub,
|
|
164
189
|
Components,
|
|
165
190
|
Browser,
|
|
191
|
+
Server,
|
|
166
192
|
ComponentInstance,
|
|
167
193
|
...extensions.importable,
|
|
168
194
|
});
|
|
@@ -234,6 +260,7 @@ const initializeComponentInstance = async ({ componentInstanceId, browserCommand
|
|
|
234
260
|
EventHub,
|
|
235
261
|
Components,
|
|
236
262
|
Browser,
|
|
263
|
+
Server,
|
|
237
264
|
ComponentInstance,
|
|
238
265
|
...extensions.importable,
|
|
239
266
|
});
|
package/dist/index.d.ts
CHANGED
|
@@ -27,7 +27,7 @@ export declare const saveComponent: ({ script, outputFile }: {
|
|
|
27
27
|
script: any;
|
|
28
28
|
outputFile: any;
|
|
29
29
|
}) => Promise<void>;
|
|
30
|
-
export declare const onInitializeComponentInstance: ({ namespaceId, extensionsPath, extensionsOptions, componentNamePrefix, componentName, componentRootDir, componentInstanceId, componentOptions, connectionId, emit, onComponentInstanceConsole, browserCommands, }: {
|
|
30
|
+
export declare const onInitializeComponentInstance: ({ namespaceId, extensionsPath, extensionsOptions, componentNamePrefix, componentName, componentRootDir, componentInstanceId, componentOptions, connectionId, emit, onComponentInstanceConsole, browserCommands, serverCommands, }: {
|
|
31
31
|
namespaceId?: any;
|
|
32
32
|
extensionsPath?: any;
|
|
33
33
|
extensionsOptions?: any;
|
|
@@ -40,6 +40,7 @@ export declare const onInitializeComponentInstance: ({ namespaceId, extensionsPa
|
|
|
40
40
|
emit: any;
|
|
41
41
|
onComponentInstanceConsole: any;
|
|
42
42
|
browserCommands: any;
|
|
43
|
+
serverCommands: any;
|
|
43
44
|
}) => Promise<void>;
|
|
44
45
|
export declare const onDisconnect: ({ connectionId }: {
|
|
45
46
|
connectionId: any;
|
package/dist/index.js
CHANGED
|
@@ -74,7 +74,7 @@ const saveComponent = async ({ script, outputFile }) => {
|
|
|
74
74
|
await fs_extra_1.default.outputFile(outputFile, transpiledComponentScript.outputText);
|
|
75
75
|
};
|
|
76
76
|
exports.saveComponent = saveComponent;
|
|
77
|
-
const onInitializeComponentInstance = async ({ namespaceId = null, extensionsPath = null, extensionsOptions = null, componentNamePrefix = '', componentName, componentRootDir, componentInstanceId, componentOptions, connectionId, emit, onComponentInstanceConsole, browserCommands, }) => {
|
|
77
|
+
const onInitializeComponentInstance = async ({ namespaceId = null, extensionsPath = null, extensionsOptions = null, componentNamePrefix = '', componentName, componentRootDir, componentInstanceId, componentOptions, connectionId, emit, onComponentInstanceConsole, browserCommands, serverCommands, }) => {
|
|
78
78
|
if (componentOptions && typeof componentOptions === 'string') {
|
|
79
79
|
componentOptions = JSON.parse(componentOptions);
|
|
80
80
|
}
|
|
@@ -119,7 +119,7 @@ const onInitializeComponentInstance = async ({ namespaceId = null, extensionsPat
|
|
|
119
119
|
emit({ type, payload, componentInstanceId });
|
|
120
120
|
}
|
|
121
121
|
});
|
|
122
|
-
worker.initializeComponentInstance({ browserCommands, componentNamePrefix, componentName, componentRootDir, componentOptions, componentInstanceId, extensionsPath, extensionsOptions });
|
|
122
|
+
worker.initializeComponentInstance({ browserCommands, serverCommands, componentNamePrefix, componentName, componentRootDir, componentOptions, componentInstanceId, extensionsPath, extensionsOptions });
|
|
123
123
|
await clearGarbage();
|
|
124
124
|
};
|
|
125
125
|
exports.onInitializeComponentInstance = onInitializeComponentInstance;
|
package/dist/utils.js
CHANGED
|
@@ -25,7 +25,7 @@ const render = async (raw, childRenderer = null, renderedArr = [], events = {},
|
|
|
25
25
|
// item = { ...rendered };
|
|
26
26
|
// }
|
|
27
27
|
item = { ...await parseFnType(item) };
|
|
28
|
-
const result = await childRenderer?.(item.type, `${parent}/${renderedArr.length}/${item.type}`, item.props);
|
|
28
|
+
const result = await childRenderer?.(item.type, item.key ? `${parent}/${item.key}/${item.type}` : `${parent}/${renderedArr.length}/${item.type}`, item.props);
|
|
29
29
|
if (result) {
|
|
30
30
|
await exports.render(result, childRenderer, renderedArr, events, `${parent}`);
|
|
31
31
|
}
|
package/jsx-runtime.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@drayman/core",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.8.0",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"scripts": {
|
|
@@ -22,7 +22,7 @@
|
|
|
22
22
|
"@babel/preset-env": "^7.13.15",
|
|
23
23
|
"@babel/preset-react": "^7.13.13",
|
|
24
24
|
"@babel/preset-typescript": "^7.13.0",
|
|
25
|
-
"@drayman/types": "^1.
|
|
25
|
+
"@drayman/types": "^1.8.0",
|
|
26
26
|
"@types/jest": "^26.0.22",
|
|
27
27
|
"@types/node": "^14.14.39",
|
|
28
28
|
"babel-jest": "^26.6.3",
|
|
@@ -39,5 +39,5 @@
|
|
|
39
39
|
"ts-node": "^9.1.1",
|
|
40
40
|
"typescript": "~4.1.5"
|
|
41
41
|
},
|
|
42
|
-
"gitHead": "
|
|
42
|
+
"gitHead": "01664c9380658f5f29e2f2ac185f5daa4921b435"
|
|
43
43
|
}
|