@lowdefy/engine 0.0.0-alpha.7 → 0.0.0-experimental-20231123124425
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/LICENSE +201 -0
- package/dist/Actions.js +231 -486
- package/dist/Blocks.js +563 -572
- package/dist/Events.js +126 -0
- package/dist/Requests.js +107 -134
- package/dist/State.js +56 -83
- package/dist/actions/createCallMethod.js +29 -0
- package/dist/actions/createDisplayMessage.js +20 -0
- package/dist/actions/createGetActions.js +27 -0
- package/dist/actions/createGetBlockId.js +20 -0
- package/dist/actions/createGetEvent.js +27 -0
- package/dist/actions/createGetGlobal.js +27 -0
- package/dist/actions/createGetInput.js +27 -0
- package/dist/actions/createGetPageId.js +20 -0
- package/dist/actions/createGetRequestDetails.js +27 -0
- package/dist/actions/createGetState.js +27 -0
- package/dist/actions/createGetUrlQuery.js +32 -0
- package/dist/actions/createGetUser.js +27 -0
- package/dist/actions/createLink.js +20 -0
- package/dist/actions/createLogin.js +20 -0
- package/dist/actions/createLogout.js +20 -0
- package/dist/actions/createRequest.js +26 -0
- package/dist/actions/createReset.js +22 -0
- package/dist/actions/createResetValidation.js +21 -0
- package/dist/actions/createSetGlobal.js +25 -0
- package/dist/actions/createSetState.js +25 -0
- package/dist/actions/createUpdateSession.js +20 -0
- package/dist/actions/createValidate.js +25 -0
- package/dist/actions/getActionMethods.js +63 -0
- package/dist/actions/getFromObject.js +42 -0
- package/dist/createLink.js +71 -0
- package/dist/getBlockMatcher.js +61 -0
- package/dist/getContext.js +106 -153
- package/dist/index.js +10 -63
- package/package.json +27 -26
- package/CHANGELOG.md +0 -38
- package/dist/BlockActions.js +0 -211
- package/dist/Mutations.js +0 -100
- package/dist/getFieldValues.js +0 -49
- package/dist/makeContextId.js +0 -44
package/dist/Actions.js
CHANGED
|
@@ -1,503 +1,248 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
this.scrollTo = this.scrollTo.bind(this);
|
|
34
|
-
this.setGlobal = this.setGlobal.bind(this);
|
|
35
|
-
this.setState = this.setState.bind(this);
|
|
36
|
-
this.validate = this.validate.bind(this);
|
|
37
|
-
this.actions = {
|
|
38
|
-
CallMethod: this.callMethod,
|
|
39
|
-
Request: this.request,
|
|
40
|
-
Link: this.link,
|
|
41
|
-
Message: this.message,
|
|
42
|
-
Reset: this.reset,
|
|
43
|
-
ScrollTo: this.scrollTo,
|
|
44
|
-
SetGlobal: this.setGlobal,
|
|
45
|
-
SetState: this.setState,
|
|
46
|
-
Validate: this.validate
|
|
47
|
-
};
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
static invalidAction(action) {
|
|
51
|
-
return () => Promise.reject({
|
|
52
|
-
errorMessage: action.error || 'Invalid action',
|
|
53
|
-
error: new Error("Invalid action: ".concat(JSON.stringify(action)))
|
|
54
|
-
});
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
build(actions) {
|
|
58
|
-
return actions.map(action => _objectSpread(_objectSpread({}, action), {}, {
|
|
59
|
-
fn: (_ref) => {
|
|
60
|
-
var {
|
|
61
|
-
args,
|
|
62
|
-
arrayIndices,
|
|
63
|
-
blockId
|
|
64
|
-
} = _ref;
|
|
65
|
-
return (0, _helpers.get)(this.actions, action.type, {
|
|
66
|
-
default: Actions.invalidAction(action)
|
|
67
|
-
})(action.params, action.success, action.error, args, arrayIndices, blockId);
|
|
68
|
-
}
|
|
69
|
-
}));
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
reset(_, successMessage, errorMessage) {
|
|
73
|
-
try {
|
|
74
|
-
this.context.State.resetState();
|
|
75
|
-
this.context.RootBlocks.reset(_helpers.serializer.deserializeFromString(this.context.State.frozenState));
|
|
76
|
-
this.context.update(); // Consider firing onReset and onResetAsync actions
|
|
77
|
-
} catch (error) {
|
|
78
|
-
// log e
|
|
79
|
-
return Promise.reject({
|
|
80
|
-
errorMessage: errorMessage || 'Failed to reset page.',
|
|
81
|
-
error
|
|
82
|
-
});
|
|
1
|
+
/*
|
|
2
|
+
Copyright 2020-2023 Lowdefy, Inc
|
|
3
|
+
|
|
4
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
you may not use this file except in compliance with the License.
|
|
6
|
+
You may obtain a copy of the License at
|
|
7
|
+
|
|
8
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
|
|
10
|
+
Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
See the License for the specific language governing permissions and
|
|
14
|
+
limitations under the License.
|
|
15
|
+
*/ import { type } from '@lowdefy/helpers';
|
|
16
|
+
import getActionMethods from './actions/getActionMethods.js';
|
|
17
|
+
let Actions = class Actions {
|
|
18
|
+
async callAsyncAction({ action, arrayIndices, block, event, index, responses }) {
|
|
19
|
+
try {
|
|
20
|
+
const response = await this.callAction({
|
|
21
|
+
action,
|
|
22
|
+
arrayIndices,
|
|
23
|
+
block,
|
|
24
|
+
event,
|
|
25
|
+
index,
|
|
26
|
+
responses
|
|
27
|
+
});
|
|
28
|
+
responses[action.id] = response;
|
|
29
|
+
} catch (error) {
|
|
30
|
+
responses[action.id] = error;
|
|
31
|
+
console.error(error);
|
|
32
|
+
}
|
|
83
33
|
}
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
34
|
+
async callActionLoop({ actions, arrayIndices, block, event, progress, responses }) {
|
|
35
|
+
for (const [index, action] of actions.entries()){
|
|
36
|
+
try {
|
|
37
|
+
if (action.async === true) {
|
|
38
|
+
this.callAsyncAction({
|
|
39
|
+
action,
|
|
40
|
+
arrayIndices,
|
|
41
|
+
block,
|
|
42
|
+
event,
|
|
43
|
+
index,
|
|
44
|
+
progress,
|
|
45
|
+
responses
|
|
46
|
+
});
|
|
47
|
+
} else {
|
|
48
|
+
const response = await this.callAction({
|
|
49
|
+
action,
|
|
50
|
+
arrayIndices,
|
|
51
|
+
block,
|
|
52
|
+
event,
|
|
53
|
+
index,
|
|
54
|
+
progress,
|
|
55
|
+
responses
|
|
56
|
+
});
|
|
57
|
+
responses[action.id] = response;
|
|
58
|
+
}
|
|
59
|
+
} catch (error) {
|
|
60
|
+
responses[action.id] = error;
|
|
61
|
+
throw {
|
|
62
|
+
error,
|
|
63
|
+
action
|
|
64
|
+
};
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
async callActions({ actions, arrayIndices, block, catchActions, event, eventName, progress }) {
|
|
69
|
+
const startTimestamp = new Date();
|
|
70
|
+
const responses = {};
|
|
71
|
+
try {
|
|
72
|
+
await this.callActionLoop({
|
|
73
|
+
actions,
|
|
74
|
+
arrayIndices,
|
|
75
|
+
block,
|
|
76
|
+
event,
|
|
77
|
+
responses,
|
|
78
|
+
progress
|
|
79
|
+
});
|
|
80
|
+
} catch (error) {
|
|
81
|
+
console.error(error);
|
|
82
|
+
try {
|
|
83
|
+
await this.callActionLoop({
|
|
84
|
+
actions: catchActions,
|
|
85
|
+
arrayIndices,
|
|
86
|
+
block,
|
|
87
|
+
event,
|
|
88
|
+
responses,
|
|
89
|
+
progress
|
|
90
|
+
});
|
|
91
|
+
} catch (errorCatch) {
|
|
92
|
+
console.error(errorCatch);
|
|
93
|
+
return {
|
|
94
|
+
blockId: block.blockId,
|
|
95
|
+
bounced: false,
|
|
96
|
+
endTimestamp: new Date(),
|
|
97
|
+
error,
|
|
98
|
+
errorCatch,
|
|
99
|
+
event,
|
|
100
|
+
eventName,
|
|
101
|
+
responses,
|
|
102
|
+
startTimestamp,
|
|
103
|
+
success: false
|
|
104
|
+
};
|
|
105
|
+
}
|
|
106
|
+
return {
|
|
107
|
+
blockId: block.blockId,
|
|
108
|
+
bounced: false,
|
|
109
|
+
endTimestamp: new Date(),
|
|
110
|
+
error,
|
|
111
|
+
event,
|
|
112
|
+
eventName,
|
|
113
|
+
responses,
|
|
114
|
+
startTimestamp,
|
|
115
|
+
success: false
|
|
116
|
+
};
|
|
106
117
|
}
|
|
107
|
-
|
|
108
118
|
return {
|
|
109
|
-
|
|
110
|
-
|
|
119
|
+
blockId: block.blockId,
|
|
120
|
+
bounced: false,
|
|
121
|
+
endTimestamp: new Date(),
|
|
122
|
+
event,
|
|
123
|
+
eventName,
|
|
124
|
+
responses,
|
|
125
|
+
startTimestamp,
|
|
126
|
+
success: true
|
|
111
127
|
};
|
|
112
|
-
} catch (error) {
|
|
113
|
-
// log e
|
|
114
|
-
return Promise.reject({
|
|
115
|
-
errorMessage: errorMessage || 'Failed to callMethod.',
|
|
116
|
-
error
|
|
117
|
-
});
|
|
118
|
-
}
|
|
119
|
-
})();
|
|
120
|
-
}
|
|
121
|
-
|
|
122
|
-
request(params, successMessage, errorMessage, args, arrayIndices) {
|
|
123
|
-
if (_helpers.type.isNone(params)) {
|
|
124
|
-
// Should this resolve or error
|
|
125
|
-
return Promise.resolve();
|
|
126
128
|
}
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
response
|
|
135
|
-
})).catch(error => {
|
|
136
|
-
if (errorMessage) {
|
|
137
|
-
return Promise.reject({
|
|
138
|
-
errorMessage,
|
|
139
|
-
error
|
|
140
|
-
});
|
|
141
|
-
}
|
|
142
|
-
|
|
143
|
-
try {
|
|
144
|
-
var {
|
|
145
|
-
displayTitle,
|
|
146
|
-
displayMessage
|
|
147
|
-
} = error.graphQLErrors[0].extensions;
|
|
148
|
-
return Promise.reject({
|
|
149
|
-
errorMessage: "".concat(displayTitle, ": ").concat(displayMessage),
|
|
150
|
-
error
|
|
151
|
-
});
|
|
152
|
-
} catch (e) {// Not a graphQLError, displayTitle, displayMessage do not exist
|
|
129
|
+
async callAction({ action, arrayIndices, block, event, index, progress, responses }) {
|
|
130
|
+
if (!this.actions[action.type]) {
|
|
131
|
+
throw {
|
|
132
|
+
error: new Error(`Invalid action type "${action.type}" at "${block.blockId}".`),
|
|
133
|
+
type: action.type,
|
|
134
|
+
index
|
|
135
|
+
};
|
|
153
136
|
}
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
137
|
+
const { output: parsedAction, errors: parserErrors } = this.context._internal.parser.parse({
|
|
138
|
+
actions: responses,
|
|
139
|
+
event,
|
|
140
|
+
arrayIndices,
|
|
141
|
+
input: action,
|
|
142
|
+
location: block.blockId
|
|
158
143
|
});
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
args,
|
|
166
|
-
arrayIndices
|
|
167
|
-
}).then(response => ({
|
|
168
|
-
successMessage,
|
|
169
|
-
response
|
|
170
|
-
})).catch(error => {
|
|
171
|
-
if (errorMessage) {
|
|
172
|
-
return Promise.reject({
|
|
173
|
-
errorMessage,
|
|
174
|
-
error
|
|
175
|
-
});
|
|
144
|
+
if (parserErrors.length > 0) {
|
|
145
|
+
throw {
|
|
146
|
+
error: parserErrors[0],
|
|
147
|
+
type: action.type,
|
|
148
|
+
index
|
|
149
|
+
};
|
|
176
150
|
}
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
return Promise.reject({
|
|
184
|
-
errorMessage: "".concat(displayTitle, ": ").concat(displayMessage),
|
|
185
|
-
error
|
|
186
|
-
});
|
|
187
|
-
} catch (e) {// Not a graphQLError, displayTitle, displayMessage do not exist
|
|
151
|
+
if (parsedAction.skip === true) {
|
|
152
|
+
return {
|
|
153
|
+
type: action.type,
|
|
154
|
+
skipped: true,
|
|
155
|
+
index
|
|
156
|
+
};
|
|
188
157
|
}
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
158
|
+
const messages = parsedAction.messages || {};
|
|
159
|
+
let response;
|
|
160
|
+
const closeLoading = this.displayMessage({
|
|
161
|
+
defaultMessage: 'Loading',
|
|
162
|
+
duration: 0,
|
|
163
|
+
message: messages.loading,
|
|
164
|
+
status: 'loading'
|
|
193
165
|
});
|
|
194
|
-
});
|
|
195
|
-
}
|
|
196
|
-
|
|
197
|
-
if (_helpers.type.isArray(params)) {
|
|
198
|
-
return this.context.Requests.callRequests({
|
|
199
|
-
requestIds: params,
|
|
200
|
-
args,
|
|
201
|
-
arrayIndices
|
|
202
|
-
}).then(response => ({
|
|
203
|
-
successMessage,
|
|
204
|
-
response
|
|
205
|
-
})).catch(error => {
|
|
206
|
-
if (errorMessage) {
|
|
207
|
-
return Promise.reject({
|
|
208
|
-
errorMessage,
|
|
209
|
-
error
|
|
210
|
-
});
|
|
211
|
-
}
|
|
212
|
-
|
|
213
166
|
try {
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
167
|
+
response = await this.actions[action.type]({
|
|
168
|
+
globals: this.context._internal.lowdefy._internal.globals,
|
|
169
|
+
methods: getActionMethods({
|
|
170
|
+
actions: responses,
|
|
171
|
+
arrayIndices,
|
|
172
|
+
blockId: block.blockId,
|
|
173
|
+
context: this.context,
|
|
174
|
+
event
|
|
175
|
+
}),
|
|
176
|
+
params: parsedAction.params
|
|
177
|
+
});
|
|
178
|
+
if (progress) {
|
|
179
|
+
progress();
|
|
180
|
+
}
|
|
181
|
+
} catch (error) {
|
|
182
|
+
responses[action.id] = {
|
|
183
|
+
error,
|
|
184
|
+
index,
|
|
185
|
+
type: action.type
|
|
186
|
+
};
|
|
187
|
+
const { output: parsedMessages, errors: parserErrors } = this.context._internal.parser.parse({
|
|
188
|
+
actions: responses,
|
|
189
|
+
event,
|
|
190
|
+
arrayIndices,
|
|
191
|
+
input: action.messages,
|
|
192
|
+
location: block.blockId
|
|
193
|
+
});
|
|
194
|
+
if (parserErrors.length > 0) {
|
|
195
|
+
// this condition is very unlikely since parser errors usually occur in the first parse.
|
|
196
|
+
throw {
|
|
197
|
+
error: parserErrors[0],
|
|
198
|
+
type: action.type,
|
|
199
|
+
index
|
|
200
|
+
};
|
|
201
|
+
}
|
|
202
|
+
closeLoading();
|
|
203
|
+
this.displayMessage({
|
|
204
|
+
defaultMessage: error.message,
|
|
205
|
+
duration: 6,
|
|
206
|
+
hideExplicitly: true,
|
|
207
|
+
message: (parsedMessages || {}).error,
|
|
208
|
+
status: 'error'
|
|
209
|
+
});
|
|
210
|
+
throw {
|
|
211
|
+
type: action.type,
|
|
212
|
+
error,
|
|
213
|
+
index
|
|
214
|
+
};
|
|
223
215
|
}
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
216
|
+
closeLoading();
|
|
217
|
+
this.displayMessage({
|
|
218
|
+
defaultMessage: 'Success',
|
|
219
|
+
message: messages.success,
|
|
220
|
+
status: 'success'
|
|
228
221
|
});
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
error: new Error("Invalid _request params: ".concat(params))
|
|
235
|
-
});
|
|
236
|
-
}
|
|
237
|
-
|
|
238
|
-
message() {
|
|
239
|
-
var params = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
240
|
-
var successMessage = arguments.length > 1 ? arguments[1] : undefined;
|
|
241
|
-
var errorMessage = arguments.length > 2 ? arguments[2] : undefined;
|
|
242
|
-
var args = arguments.length > 3 ? arguments[3] : undefined;
|
|
243
|
-
var arrayIndices = arguments.length > 4 ? arguments[4] : undefined;
|
|
244
|
-
var blockId = arguments.length > 5 ? arguments[5] : undefined;
|
|
245
|
-
|
|
246
|
-
try {
|
|
247
|
-
var {
|
|
248
|
-
output: parsed,
|
|
249
|
-
errors: parseErrors
|
|
250
|
-
} = this.context.parser.parse({
|
|
251
|
-
args,
|
|
252
|
-
arrayIndices,
|
|
253
|
-
input: params,
|
|
254
|
-
location: blockId
|
|
255
|
-
});
|
|
256
|
-
|
|
257
|
-
if (parseErrors.length > 0) {
|
|
258
|
-
return Promise.reject({
|
|
259
|
-
errorMessage: errorMessage || "Message failed.",
|
|
260
|
-
error: parseErrors
|
|
261
|
-
});
|
|
262
|
-
}
|
|
263
|
-
|
|
264
|
-
this.context.displayMessage[parsed.status || 'success']({
|
|
265
|
-
content: parsed.content || 'Success',
|
|
266
|
-
duration: _helpers.type.isNone(parsed.duration) ? 5 : parsed.duration
|
|
267
|
-
});
|
|
268
|
-
return Promise.resolve({
|
|
269
|
-
successMessage
|
|
270
|
-
});
|
|
271
|
-
} catch (error) {
|
|
272
|
-
return Promise.reject({
|
|
273
|
-
errorMessage: errorMessage || "Message failed.",
|
|
274
|
-
error
|
|
275
|
-
});
|
|
276
|
-
}
|
|
277
|
-
}
|
|
278
|
-
|
|
279
|
-
setState(value, successMessage, errorMessage, args, arrayIndices, blockId) {
|
|
280
|
-
try {
|
|
281
|
-
var {
|
|
282
|
-
output: parsed,
|
|
283
|
-
errors: stateParseErrors
|
|
284
|
-
} = this.context.parser.parse({
|
|
285
|
-
args,
|
|
286
|
-
arrayIndices,
|
|
287
|
-
input: value,
|
|
288
|
-
location: blockId
|
|
289
|
-
});
|
|
290
|
-
|
|
291
|
-
if (stateParseErrors.length > 0) {
|
|
292
|
-
return Promise.reject({
|
|
293
|
-
errorMessage: errorMessage || 'Failed to set state due to parser error.',
|
|
294
|
-
error: stateParseErrors
|
|
295
|
-
});
|
|
296
|
-
}
|
|
297
|
-
|
|
298
|
-
Object.keys(parsed).forEach(key => {
|
|
299
|
-
this.context.State.set((0, _helpers.applyArrayIndices)(arrayIndices, key), parsed[key]);
|
|
300
|
-
});
|
|
301
|
-
this.context.RootBlocks.reset();
|
|
302
|
-
this.context.update();
|
|
303
|
-
} catch (error) {
|
|
304
|
-
// log e
|
|
305
|
-
return Promise.reject({
|
|
306
|
-
errorMessage: errorMessage || 'Failed to set state.',
|
|
307
|
-
error
|
|
308
|
-
});
|
|
309
|
-
}
|
|
310
|
-
|
|
311
|
-
return Promise.resolve({
|
|
312
|
-
successMessage
|
|
313
|
-
});
|
|
314
|
-
}
|
|
315
|
-
|
|
316
|
-
setGlobal(value, successMessage, errorMessage, args, arrayIndices, blockId) {
|
|
317
|
-
try {
|
|
318
|
-
var {
|
|
319
|
-
output: parsed,
|
|
320
|
-
errors: globalParseErrors
|
|
321
|
-
} = this.context.parser.parse({
|
|
322
|
-
args,
|
|
323
|
-
arrayIndices,
|
|
324
|
-
input: value,
|
|
325
|
-
location: blockId
|
|
326
|
-
});
|
|
327
|
-
|
|
328
|
-
if (globalParseErrors.length > 0) {
|
|
329
|
-
return Promise.reject({
|
|
330
|
-
errorMessage: errorMessage || 'Failed to set global due to parser error.',
|
|
331
|
-
error: globalParseErrors
|
|
332
|
-
});
|
|
333
|
-
}
|
|
334
|
-
|
|
335
|
-
Object.keys(parsed).forEach(key => {
|
|
336
|
-
(0, _helpers.set)(this.context.lowdefyGlobal, (0, _helpers.applyArrayIndices)(arrayIndices, key), parsed[key]);
|
|
337
|
-
});
|
|
338
|
-
this.context.RootBlocks.reset();
|
|
339
|
-
this.context.update();
|
|
340
|
-
} catch (error) {
|
|
341
|
-
// log e
|
|
342
|
-
return Promise.reject({
|
|
343
|
-
errorMessage: errorMessage || 'Failed to set global.',
|
|
344
|
-
error
|
|
345
|
-
});
|
|
346
|
-
}
|
|
347
|
-
|
|
348
|
-
return Promise.resolve({
|
|
349
|
-
successMessage
|
|
350
|
-
});
|
|
351
|
-
}
|
|
352
|
-
|
|
353
|
-
scrollTo(params, successMessage, errorMessage, args, arrayIndices, blockId) {
|
|
354
|
-
var {
|
|
355
|
-
output: parsedParams,
|
|
356
|
-
errors: parserErrors
|
|
357
|
-
} = this.context.parser.parse({
|
|
358
|
-
args,
|
|
359
|
-
arrayIndices,
|
|
360
|
-
input: params,
|
|
361
|
-
location: blockId
|
|
362
|
-
});
|
|
363
|
-
|
|
364
|
-
if (parserErrors.length > 0) {
|
|
365
|
-
return Promise.reject({
|
|
366
|
-
errorMessage: errorMessage || 'Failed to scroll due to parser error.',
|
|
367
|
-
error: parserErrors
|
|
368
|
-
});
|
|
369
|
-
}
|
|
370
|
-
|
|
371
|
-
try {
|
|
372
|
-
if (parsedParams) {
|
|
373
|
-
if (parsedParams.blockId) {
|
|
374
|
-
var element = this.context.document.getElementById(parsedParams.blockId);
|
|
375
|
-
|
|
376
|
-
if (element) {
|
|
377
|
-
element.scrollIntoView(parsedParams.options);
|
|
378
|
-
}
|
|
379
|
-
} else {
|
|
380
|
-
this.context.window.scrollTo(parsedParams);
|
|
381
|
-
}
|
|
382
|
-
}
|
|
383
|
-
} catch (error) {
|
|
384
|
-
return Promise.reject({
|
|
385
|
-
errorMessage: errorMessage || 'Failed to scroll.',
|
|
386
|
-
error
|
|
387
|
-
});
|
|
388
|
-
}
|
|
389
|
-
|
|
390
|
-
return Promise.resolve({
|
|
391
|
-
successMessage
|
|
392
|
-
});
|
|
393
|
-
}
|
|
394
|
-
|
|
395
|
-
link(params, successMessage, errorMessage, args, arrayIndices, blockId) {
|
|
396
|
-
var {
|
|
397
|
-
output: parsedParams,
|
|
398
|
-
errors: parserErrors
|
|
399
|
-
} = this.context.parser.parse({
|
|
400
|
-
args,
|
|
401
|
-
arrayIndices,
|
|
402
|
-
input: params,
|
|
403
|
-
location: blockId
|
|
404
|
-
});
|
|
405
|
-
|
|
406
|
-
if (parserErrors.length > 0) {
|
|
407
|
-
return Promise.reject({
|
|
408
|
-
errorMessage: errorMessage || 'Failed to follow page link due to parser error.',
|
|
409
|
-
error: parserErrors
|
|
410
|
-
});
|
|
222
|
+
return {
|
|
223
|
+
type: action.type,
|
|
224
|
+
response,
|
|
225
|
+
index
|
|
226
|
+
};
|
|
411
227
|
}
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
}
|
|
421
|
-
|
|
422
|
-
if (parsedParams.pageId) {
|
|
423
|
-
pageId = parsedParams.pageId;
|
|
424
|
-
}
|
|
425
|
-
|
|
426
|
-
if (pageId) {
|
|
427
|
-
// set input for page before changing
|
|
428
|
-
if (!_helpers.type.isNone(parsedParams.input)) {
|
|
429
|
-
var nextContextId = (0, _makeContextId.default)({
|
|
430
|
-
pageId,
|
|
431
|
-
search: parsedParams.urlQuery,
|
|
432
|
-
blockId: pageId
|
|
433
|
-
});
|
|
434
|
-
this.context.allInputs[nextContextId] = parsedParams.input;
|
|
435
|
-
}
|
|
436
|
-
|
|
437
|
-
if (parsedParams.newWindow) {
|
|
438
|
-
this.context.window.open("".concat(this.context.window.location.origin, "/").concat(pageId).concat(lowdefyUrlQuery), '_blank').focus();
|
|
439
|
-
} else {
|
|
440
|
-
this.context.routeHistory.push("/".concat(pageId).concat(lowdefyUrlQuery));
|
|
441
|
-
}
|
|
442
|
-
} else if (parsedParams.url) {
|
|
443
|
-
if (parsedParams.newWindow) {
|
|
444
|
-
this.context.window.open("".concat(parsedParams.url).concat(lowdefyUrlQuery), '_blank').focus();
|
|
445
|
-
} else {
|
|
446
|
-
this.context.window.location.href = "".concat(parsedParams.url).concat(lowdefyUrlQuery);
|
|
228
|
+
displayMessage({ defaultMessage, duration, hideExplicitly, message, status }) {
|
|
229
|
+
let close = ()=>undefined;
|
|
230
|
+
if (hideExplicitly && message !== false || !hideExplicitly && !type.isNone(message)) {
|
|
231
|
+
close = this.context._internal.lowdefy._internal.displayMessage({
|
|
232
|
+
content: type.isString(message) ? message : defaultMessage,
|
|
233
|
+
duration,
|
|
234
|
+
status
|
|
235
|
+
});
|
|
447
236
|
}
|
|
448
|
-
|
|
449
|
-
if (parsedParams.newWindow) {
|
|
450
|
-
this.context.window.open("".concat(this.context.window.location.origin, "/").concat(lowdefyUrlQuery), '_blank').focus();
|
|
451
|
-
} else {
|
|
452
|
-
this.context.routeHistory.push("/".concat(lowdefyUrlQuery));
|
|
453
|
-
}
|
|
454
|
-
}
|
|
455
|
-
} catch (error) {
|
|
456
|
-
return Promise.reject({
|
|
457
|
-
errorMessage: errorMessage || 'Failed to follow link.',
|
|
458
|
-
error
|
|
459
|
-
});
|
|
237
|
+
return close;
|
|
460
238
|
}
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
try {
|
|
469
|
-
if (!_helpers.type.isNone(params) && !_helpers.type.isString(params) && !_helpers.type.isArray(params)) {
|
|
470
|
-
throw new Error('Invalid validate params.');
|
|
471
|
-
}
|
|
472
|
-
|
|
473
|
-
this.context.showValidationErrors = true;
|
|
474
|
-
var validationErrors = this.context.RootBlocks.validate();
|
|
475
|
-
|
|
476
|
-
if (params) {
|
|
477
|
-
var blockIds = _helpers.type.isString(params) ? [params] : params;
|
|
478
|
-
validationErrors = validationErrors.filter(block => {
|
|
479
|
-
return blockIds.includes(block.blockId);
|
|
480
|
-
});
|
|
481
|
-
}
|
|
482
|
-
|
|
483
|
-
if (validationErrors.length > 0) {
|
|
484
|
-
return Promise.reject({
|
|
485
|
-
errorMessage: errorMessage || "Your input has ".concat(validationErrors.length, " validation error").concat(validationErrors.length !== 1 ? 's' : '', ".")
|
|
486
|
-
});
|
|
487
|
-
}
|
|
488
|
-
} catch (error) {
|
|
489
|
-
return Promise.reject({
|
|
490
|
-
errorMessage: 'Failed to validate page input.',
|
|
491
|
-
error
|
|
492
|
-
});
|
|
239
|
+
constructor(context){
|
|
240
|
+
this.context = context;
|
|
241
|
+
this.callAction = this.callAction.bind(this);
|
|
242
|
+
this.callActionLoop = this.callActionLoop.bind(this);
|
|
243
|
+
this.callActions = this.callActions.bind(this);
|
|
244
|
+
this.displayMessage = this.displayMessage.bind(this);
|
|
245
|
+
this.actions = context._internal.lowdefy._internal.actions;
|
|
493
246
|
}
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
successMessage
|
|
497
|
-
});
|
|
498
|
-
}
|
|
499
|
-
|
|
500
|
-
}
|
|
501
|
-
|
|
502
|
-
var _default = Actions;
|
|
503
|
-
exports.default = _default;
|
|
247
|
+
};
|
|
248
|
+
export default Actions;
|