@player-ui/external-action-plugin 0.3.1-next.0 → 0.3.1
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/external-action-plugin.dev.js +178 -0
- package/dist/external-action-plugin.prod.js +1 -0
- package/dist/index.cjs.js +11 -3
- package/dist/index.esm.js +11 -3
- package/package.json +12 -3
- package/src/index.ts +23 -8
|
@@ -0,0 +1,178 @@
|
|
|
1
|
+
(function webpackUniversalModuleDefinition(root, factory) {
|
|
2
|
+
if(typeof exports === 'object' && typeof module === 'object')
|
|
3
|
+
module.exports = factory();
|
|
4
|
+
else if(typeof define === 'function' && define.amd)
|
|
5
|
+
define([], factory);
|
|
6
|
+
else if(typeof exports === 'object')
|
|
7
|
+
exports["ExternalActionPlugin"] = factory();
|
|
8
|
+
else
|
|
9
|
+
root["ExternalActionPlugin"] = factory();
|
|
10
|
+
})(this, function() {
|
|
11
|
+
return /******/ (function(modules) { // webpackBootstrap
|
|
12
|
+
/******/ // The module cache
|
|
13
|
+
/******/ var installedModules = {};
|
|
14
|
+
/******/
|
|
15
|
+
/******/ // The require function
|
|
16
|
+
/******/ function __webpack_require__(moduleId) {
|
|
17
|
+
/******/
|
|
18
|
+
/******/ // Check if module is in cache
|
|
19
|
+
/******/ if(installedModules[moduleId]) {
|
|
20
|
+
/******/ return installedModules[moduleId].exports;
|
|
21
|
+
/******/ }
|
|
22
|
+
/******/ // Create a new module (and put it into the cache)
|
|
23
|
+
/******/ var module = installedModules[moduleId] = {
|
|
24
|
+
/******/ i: moduleId,
|
|
25
|
+
/******/ l: false,
|
|
26
|
+
/******/ exports: {}
|
|
27
|
+
/******/ };
|
|
28
|
+
/******/
|
|
29
|
+
/******/ // Execute the module function
|
|
30
|
+
/******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__);
|
|
31
|
+
/******/
|
|
32
|
+
/******/ // Flag the module as loaded
|
|
33
|
+
/******/ module.l = true;
|
|
34
|
+
/******/
|
|
35
|
+
/******/ // Return the exports of the module
|
|
36
|
+
/******/ return module.exports;
|
|
37
|
+
/******/ }
|
|
38
|
+
/******/
|
|
39
|
+
/******/
|
|
40
|
+
/******/ // expose the modules object (__webpack_modules__)
|
|
41
|
+
/******/ __webpack_require__.m = modules;
|
|
42
|
+
/******/
|
|
43
|
+
/******/ // expose the module cache
|
|
44
|
+
/******/ __webpack_require__.c = installedModules;
|
|
45
|
+
/******/
|
|
46
|
+
/******/ // define getter function for harmony exports
|
|
47
|
+
/******/ __webpack_require__.d = function(exports, name, getter) {
|
|
48
|
+
/******/ if(!__webpack_require__.o(exports, name)) {
|
|
49
|
+
/******/ Object.defineProperty(exports, name, { enumerable: true, get: getter });
|
|
50
|
+
/******/ }
|
|
51
|
+
/******/ };
|
|
52
|
+
/******/
|
|
53
|
+
/******/ // define __esModule on exports
|
|
54
|
+
/******/ __webpack_require__.r = function(exports) {
|
|
55
|
+
/******/ if(typeof Symbol !== 'undefined' && Symbol.toStringTag) {
|
|
56
|
+
/******/ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
57
|
+
/******/ }
|
|
58
|
+
/******/ Object.defineProperty(exports, '__esModule', { value: true });
|
|
59
|
+
/******/ };
|
|
60
|
+
/******/
|
|
61
|
+
/******/ // create a fake namespace object
|
|
62
|
+
/******/ // mode & 1: value is a module id, require it
|
|
63
|
+
/******/ // mode & 2: merge all properties of value into the ns
|
|
64
|
+
/******/ // mode & 4: return value when already ns object
|
|
65
|
+
/******/ // mode & 8|1: behave like require
|
|
66
|
+
/******/ __webpack_require__.t = function(value, mode) {
|
|
67
|
+
/******/ if(mode & 1) value = __webpack_require__(value);
|
|
68
|
+
/******/ if(mode & 8) return value;
|
|
69
|
+
/******/ if((mode & 4) && typeof value === 'object' && value && value.__esModule) return value;
|
|
70
|
+
/******/ var ns = Object.create(null);
|
|
71
|
+
/******/ __webpack_require__.r(ns);
|
|
72
|
+
/******/ Object.defineProperty(ns, 'default', { enumerable: true, value: value });
|
|
73
|
+
/******/ if(mode & 2 && typeof value != 'string') for(var key in value) __webpack_require__.d(ns, key, function(key) { return value[key]; }.bind(null, key));
|
|
74
|
+
/******/ return ns;
|
|
75
|
+
/******/ };
|
|
76
|
+
/******/
|
|
77
|
+
/******/ // getDefaultExport function for compatibility with non-harmony modules
|
|
78
|
+
/******/ __webpack_require__.n = function(module) {
|
|
79
|
+
/******/ var getter = module && module.__esModule ?
|
|
80
|
+
/******/ function getDefault() { return module['default']; } :
|
|
81
|
+
/******/ function getModuleExports() { return module; };
|
|
82
|
+
/******/ __webpack_require__.d(getter, 'a', getter);
|
|
83
|
+
/******/ return getter;
|
|
84
|
+
/******/ };
|
|
85
|
+
/******/
|
|
86
|
+
/******/ // Object.prototype.hasOwnProperty.call
|
|
87
|
+
/******/ __webpack_require__.o = function(object, property) { return Object.prototype.hasOwnProperty.call(object, property); };
|
|
88
|
+
/******/
|
|
89
|
+
/******/ // __webpack_public_path__
|
|
90
|
+
/******/ __webpack_require__.p = "";
|
|
91
|
+
/******/
|
|
92
|
+
/******/
|
|
93
|
+
/******/ // Load entry module and return exports
|
|
94
|
+
/******/ return __webpack_require__(__webpack_require__.s = "./bazel-out/k8-fastbuild/bin/plugins/external-action/core/dist/index.esm.js");
|
|
95
|
+
/******/ })
|
|
96
|
+
/************************************************************************/
|
|
97
|
+
/******/ ({
|
|
98
|
+
|
|
99
|
+
/***/ "./bazel-out/k8-fastbuild/bin/plugins/external-action/core/dist/index.esm.js":
|
|
100
|
+
/*!***********************************************************************************!*\
|
|
101
|
+
!*** ./bazel-out/k8-fastbuild/bin/plugins/external-action/core/dist/index.esm.js ***!
|
|
102
|
+
\***********************************************************************************/
|
|
103
|
+
/*! exports provided: ExternalActionPlugin */
|
|
104
|
+
/***/ (function(module, __webpack_exports__, __webpack_require__) {
|
|
105
|
+
|
|
106
|
+
"use strict";
|
|
107
|
+
__webpack_require__.r(__webpack_exports__);
|
|
108
|
+
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "ExternalActionPlugin", function() { return ExternalActionPlugin; });
|
|
109
|
+
var __async = (__this, __arguments, generator) => {
|
|
110
|
+
return new Promise((resolve, reject) => {
|
|
111
|
+
var fulfilled = (value) => {
|
|
112
|
+
try {
|
|
113
|
+
step(generator.next(value));
|
|
114
|
+
} catch (e) {
|
|
115
|
+
reject(e);
|
|
116
|
+
}
|
|
117
|
+
};
|
|
118
|
+
var rejected = (value) => {
|
|
119
|
+
try {
|
|
120
|
+
step(generator.throw(value));
|
|
121
|
+
} catch (e) {
|
|
122
|
+
reject(e);
|
|
123
|
+
}
|
|
124
|
+
};
|
|
125
|
+
var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
|
|
126
|
+
step((generator = generator.apply(__this, __arguments)).next());
|
|
127
|
+
});
|
|
128
|
+
};
|
|
129
|
+
class ExternalActionPlugin {
|
|
130
|
+
constructor(handler) {
|
|
131
|
+
this.name = "ExternalActionPlugin";
|
|
132
|
+
this.handler = handler;
|
|
133
|
+
}
|
|
134
|
+
apply(player) {
|
|
135
|
+
player.hooks.flowController.tap(this.name, (flowController) => {
|
|
136
|
+
flowController.hooks.flow.tap(this.name, (flow) => {
|
|
137
|
+
flow.hooks.transition.tap(this.name, (fromState, toState) => {
|
|
138
|
+
const { value: state } = toState;
|
|
139
|
+
if (state.state_type === "EXTERNAL") {
|
|
140
|
+
setTimeout(() => __async(this, null, function* () {
|
|
141
|
+
const shouldTransition = (currentState2) => {
|
|
142
|
+
var _a, _b;
|
|
143
|
+
return currentState2.status === "in-progress" && ((_b = (_a = currentState2.controllers.flow.current) == null ? void 0 : _a.currentState) == null ? void 0 : _b.value) === state;
|
|
144
|
+
};
|
|
145
|
+
const currentState = player.getState();
|
|
146
|
+
if (shouldTransition(currentState)) {
|
|
147
|
+
try {
|
|
148
|
+
const transitionValue = yield this.handler(state, currentState.controllers);
|
|
149
|
+
if (transitionValue !== void 0) {
|
|
150
|
+
const latestState = player.getState();
|
|
151
|
+
if (shouldTransition(latestState)) {
|
|
152
|
+
latestState.controllers.flow.transition(transitionValue);
|
|
153
|
+
} else {
|
|
154
|
+
player.logger.warn(`External state resolved with [${transitionValue}], but Player already navigated away from [${toState.name}]`);
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
} catch (error) {
|
|
158
|
+
if (error instanceof Error) {
|
|
159
|
+
currentState.fail(error);
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
}), 0);
|
|
164
|
+
}
|
|
165
|
+
});
|
|
166
|
+
});
|
|
167
|
+
});
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
|
|
172
|
+
//# sourceMappingURL=index.esm.js.map
|
|
173
|
+
|
|
174
|
+
|
|
175
|
+
/***/ })
|
|
176
|
+
|
|
177
|
+
/******/ });
|
|
178
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
!function(t,e){"object"===typeof exports&&"object"===typeof module?module.exports=e():"function"===typeof define&&define.amd?define([],e):"object"===typeof exports?exports.ExternalActionPlugin=e():t.ExternalActionPlugin=e()}(this,(function(){return function(t){var e={};function n(r){if(e[r])return e[r].exports;var o=e[r]={i:r,l:!1,exports:{}};return t[r].call(o.exports,o,o.exports,n),o.l=!0,o.exports}return n.m=t,n.c=e,n.d=function(t,e,r){n.o(t,e)||Object.defineProperty(t,e,{enumerable:!0,get:r})},n.r=function(t){"undefined"!==typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})},n.t=function(t,e){if(1&e&&(t=n(t)),8&e)return t;if(4&e&&"object"===typeof t&&t&&t.__esModule)return t;var r=Object.create(null);if(n.r(r),Object.defineProperty(r,"default",{enumerable:!0,value:t}),2&e&&"string"!=typeof t)for(var o in t)n.d(r,o,function(e){return t[e]}.bind(null,o));return r},n.n=function(t){var e=t&&t.__esModule?function(){return t.default}:function(){return t};return n.d(e,"a",e),e},n.o=function(t,e){return Object.prototype.hasOwnProperty.call(t,e)},n.p="",n(n.s=0)}([function(t,e,n){"use strict";n.r(e),n.d(e,"ExternalActionPlugin",(function(){return r}));class r{constructor(t){this.name="ExternalActionPlugin",this.handler=t}apply(t){t.hooks.flowController.tap(this.name,(e=>{e.hooks.flow.tap(this.name,(e=>{e.hooks.transition.tap(this.name,((e,n)=>{const{value:r}=n;"EXTERNAL"===r.state_type&&setTimeout((()=>{return e=this,o=null,i=function*(){const e=t=>{var e,n;return"in-progress"===t.status&&(null==(n=null==(e=t.controllers.flow.current)?void 0:e.currentState)?void 0:n.value)===r},o=t.getState();if(e(o))try{const i=yield this.handler(r,o.controllers);if(void 0!==i){const r=t.getState();e(r)?r.controllers.flow.transition(i):t.logger.warn(`External state resolved with [${i}], but Player already navigated away from [${n.name}]`)}}catch(i){i instanceof Error&&o.fail(i)}},new Promise(((t,n)=>{var r=t=>{try{a(i.next(t))}catch(e){n(e)}},l=t=>{try{a(i.throw(t))}catch(e){n(e)}},a=e=>e.done?t(e.value):Promise.resolve(e.value).then(r,l);a((i=i.apply(e,o)).next())}));var e,o,i}),0)}))}))}))}}}])}));
|
package/dist/index.cjs.js
CHANGED
|
@@ -34,13 +34,21 @@ class ExternalActionPlugin {
|
|
|
34
34
|
const { value: state } = toState;
|
|
35
35
|
if (state.state_type === "EXTERNAL") {
|
|
36
36
|
setTimeout(() => __async(this, null, function* () {
|
|
37
|
-
|
|
37
|
+
const shouldTransition = (currentState2) => {
|
|
38
|
+
var _a, _b;
|
|
39
|
+
return currentState2.status === "in-progress" && ((_b = (_a = currentState2.controllers.flow.current) == null ? void 0 : _a.currentState) == null ? void 0 : _b.value) === state;
|
|
40
|
+
};
|
|
38
41
|
const currentState = player.getState();
|
|
39
|
-
if (
|
|
42
|
+
if (shouldTransition(currentState)) {
|
|
40
43
|
try {
|
|
41
44
|
const transitionValue = yield this.handler(state, currentState.controllers);
|
|
42
45
|
if (transitionValue !== void 0) {
|
|
43
|
-
|
|
46
|
+
const latestState = player.getState();
|
|
47
|
+
if (shouldTransition(latestState)) {
|
|
48
|
+
latestState.controllers.flow.transition(transitionValue);
|
|
49
|
+
} else {
|
|
50
|
+
player.logger.warn(`External state resolved with [${transitionValue}], but Player already navigated away from [${toState.name}]`);
|
|
51
|
+
}
|
|
44
52
|
}
|
|
45
53
|
} catch (error) {
|
|
46
54
|
if (error instanceof Error) {
|
package/dist/index.esm.js
CHANGED
|
@@ -30,13 +30,21 @@ class ExternalActionPlugin {
|
|
|
30
30
|
const { value: state } = toState;
|
|
31
31
|
if (state.state_type === "EXTERNAL") {
|
|
32
32
|
setTimeout(() => __async(this, null, function* () {
|
|
33
|
-
|
|
33
|
+
const shouldTransition = (currentState2) => {
|
|
34
|
+
var _a, _b;
|
|
35
|
+
return currentState2.status === "in-progress" && ((_b = (_a = currentState2.controllers.flow.current) == null ? void 0 : _a.currentState) == null ? void 0 : _b.value) === state;
|
|
36
|
+
};
|
|
34
37
|
const currentState = player.getState();
|
|
35
|
-
if (
|
|
38
|
+
if (shouldTransition(currentState)) {
|
|
36
39
|
try {
|
|
37
40
|
const transitionValue = yield this.handler(state, currentState.controllers);
|
|
38
41
|
if (transitionValue !== void 0) {
|
|
39
|
-
|
|
42
|
+
const latestState = player.getState();
|
|
43
|
+
if (shouldTransition(latestState)) {
|
|
44
|
+
latestState.controllers.flow.transition(transitionValue);
|
|
45
|
+
} else {
|
|
46
|
+
player.logger.warn(`External state resolved with [${transitionValue}], but Player already navigated away from [${toState.name}]`);
|
|
47
|
+
}
|
|
40
48
|
}
|
|
41
49
|
} catch (error) {
|
|
42
50
|
if (error instanceof Error) {
|
package/package.json
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@player-ui/external-action-plugin",
|
|
3
|
-
"version": "0.3.1
|
|
3
|
+
"version": "0.3.1",
|
|
4
4
|
"private": false,
|
|
5
5
|
"publishConfig": {
|
|
6
6
|
"registry": "https://registry.npmjs.org"
|
|
7
7
|
},
|
|
8
8
|
"peerDependencies": {
|
|
9
|
-
"@player-ui/player": "0.3.1
|
|
9
|
+
"@player-ui/player": "0.3.1"
|
|
10
10
|
},
|
|
11
11
|
"dependencies": {
|
|
12
12
|
"@babel/runtime": "7.15.4"
|
|
@@ -52,6 +52,15 @@
|
|
|
52
52
|
{
|
|
53
53
|
"name": "Kelly Harrop",
|
|
54
54
|
"url": "https://github.com/kharrop"
|
|
55
|
+
},
|
|
56
|
+
{
|
|
57
|
+
"name": "Alejandro Fimbres",
|
|
58
|
+
"url": "https://github.com/lexfm"
|
|
59
|
+
},
|
|
60
|
+
{
|
|
61
|
+
"name": "Rafael Campos",
|
|
62
|
+
"url": "https://github.com/rafbcampos"
|
|
55
63
|
}
|
|
56
|
-
]
|
|
64
|
+
],
|
|
65
|
+
"bundle": "./dist/external-action-plugin.prod.js"
|
|
57
66
|
}
|
package/src/index.ts
CHANGED
|
@@ -1,4 +1,9 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type {
|
|
2
|
+
Player,
|
|
3
|
+
PlayerPlugin,
|
|
4
|
+
InProgressState,
|
|
5
|
+
PlayerFlowState,
|
|
6
|
+
} from '@player-ui/player';
|
|
2
7
|
import type { NavigationFlowExternalState } from '@player-ui/types';
|
|
3
8
|
|
|
4
9
|
export type ExternalStateHandler = (
|
|
@@ -22,16 +27,18 @@ export class ExternalActionPlugin implements PlayerPlugin {
|
|
|
22
27
|
flowController.hooks.flow.tap(this.name, (flow) => {
|
|
23
28
|
flow.hooks.transition.tap(this.name, (fromState, toState) => {
|
|
24
29
|
const { value: state } = toState;
|
|
25
|
-
|
|
26
30
|
if (state.state_type === 'EXTERNAL') {
|
|
27
31
|
setTimeout(async () => {
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
32
|
+
/** Helper for ensuring state is still current relative to external state this is handling */
|
|
33
|
+
const shouldTransition = (
|
|
34
|
+
currentState: PlayerFlowState
|
|
35
|
+
): currentState is InProgressState =>
|
|
31
36
|
currentState.status === 'in-progress' &&
|
|
32
37
|
currentState.controllers.flow.current?.currentState?.value ===
|
|
33
|
-
state
|
|
34
|
-
|
|
38
|
+
state;
|
|
39
|
+
|
|
40
|
+
const currentState = player.getState();
|
|
41
|
+
if (shouldTransition(currentState)) {
|
|
35
42
|
try {
|
|
36
43
|
const transitionValue = await this.handler(
|
|
37
44
|
state,
|
|
@@ -39,7 +46,15 @@ export class ExternalActionPlugin implements PlayerPlugin {
|
|
|
39
46
|
);
|
|
40
47
|
|
|
41
48
|
if (transitionValue !== undefined) {
|
|
42
|
-
|
|
49
|
+
// Ensure the Player is still in the same state after waiting for transitionValue
|
|
50
|
+
const latestState = player.getState();
|
|
51
|
+
if (shouldTransition(latestState)) {
|
|
52
|
+
latestState.controllers.flow.transition(transitionValue);
|
|
53
|
+
} else {
|
|
54
|
+
player.logger.warn(
|
|
55
|
+
`External state resolved with [${transitionValue}], but Player already navigated away from [${toState.name}]`
|
|
56
|
+
);
|
|
57
|
+
}
|
|
43
58
|
}
|
|
44
59
|
} catch (error) {
|
|
45
60
|
if (error instanceof Error) {
|