@player-ui/make-flow 0.4.0-next.0 → 0.4.0-next.10
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/index.cjs.js +58 -2
- package/dist/index.d.ts +13 -2
- package/dist/index.esm.js +58 -2
- package/dist/make-flow.dev.js +251 -0
- package/dist/make-flow.prod.js +1 -0
- package/package.json +12 -3
- package/src/index.ts +70 -3
package/dist/index.cjs.js
CHANGED
|
@@ -22,6 +22,25 @@ function identify(obj) {
|
|
|
22
22
|
return 3;
|
|
23
23
|
}
|
|
24
24
|
|
|
25
|
+
var __defProp = Object.defineProperty;
|
|
26
|
+
var __defProps = Object.defineProperties;
|
|
27
|
+
var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
|
|
28
|
+
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
29
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
30
|
+
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
31
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
32
|
+
var __spreadValues = (a, b) => {
|
|
33
|
+
for (var prop in b || (b = {}))
|
|
34
|
+
if (__hasOwnProp.call(b, prop))
|
|
35
|
+
__defNormalProp(a, prop, b[prop]);
|
|
36
|
+
if (__getOwnPropSymbols)
|
|
37
|
+
for (var prop of __getOwnPropSymbols(b)) {
|
|
38
|
+
if (__propIsEnum.call(b, prop))
|
|
39
|
+
__defNormalProp(a, prop, b[prop]);
|
|
40
|
+
}
|
|
41
|
+
return a;
|
|
42
|
+
};
|
|
43
|
+
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
25
44
|
function unwrapJSend(obj) {
|
|
26
45
|
const isJSend = "status" in obj && "data" in obj;
|
|
27
46
|
if (isJSend) {
|
|
@@ -29,7 +48,44 @@ function unwrapJSend(obj) {
|
|
|
29
48
|
}
|
|
30
49
|
return obj;
|
|
31
50
|
}
|
|
32
|
-
|
|
51
|
+
const createDefaultNav = (flow, options) => {
|
|
52
|
+
var _a, _b;
|
|
53
|
+
if ((flow.navigation === void 0 || flow.navigation === null) && Array.isArray(flow.views) && flow.views.length === 1) {
|
|
54
|
+
const navFlow = {
|
|
55
|
+
startState: "VIEW_0",
|
|
56
|
+
VIEW_0: {
|
|
57
|
+
state_type: "VIEW",
|
|
58
|
+
ref: (_a = flow.views[0].id) != null ? _a : `${flow.id}-views-0`,
|
|
59
|
+
transitions: {
|
|
60
|
+
"*": "END_done",
|
|
61
|
+
Prev: "END_back"
|
|
62
|
+
}
|
|
63
|
+
},
|
|
64
|
+
END_done: {
|
|
65
|
+
state_type: "END",
|
|
66
|
+
outcome: (_b = options == null ? void 0 : options.outcome) != null ? _b : "doneWithFlow"
|
|
67
|
+
},
|
|
68
|
+
END_back: {
|
|
69
|
+
state_type: "END",
|
|
70
|
+
outcome: "BACK"
|
|
71
|
+
}
|
|
72
|
+
};
|
|
73
|
+
if ((options == null ? void 0 : options.onStart) !== void 0) {
|
|
74
|
+
navFlow.onStart = options.onStart;
|
|
75
|
+
}
|
|
76
|
+
if ((options == null ? void 0 : options.onEnd) !== void 0) {
|
|
77
|
+
navFlow.onEnd = options.onEnd;
|
|
78
|
+
}
|
|
79
|
+
return __spreadProps(__spreadValues({}, flow), {
|
|
80
|
+
navigation: {
|
|
81
|
+
BEGIN: "Flow",
|
|
82
|
+
Flow: navFlow
|
|
83
|
+
}
|
|
84
|
+
});
|
|
85
|
+
}
|
|
86
|
+
return flow;
|
|
87
|
+
};
|
|
88
|
+
function makeFlow(obj, args) {
|
|
33
89
|
const objified = unwrapJSend(typeof obj === "string" ? JSON.parse(obj) : obj);
|
|
34
90
|
if (Array.isArray(objified)) {
|
|
35
91
|
const collection = {
|
|
@@ -50,7 +106,7 @@ function makeFlow(obj) {
|
|
|
50
106
|
throw new Error("No clue how to convert this into a flow. Just do it yourself");
|
|
51
107
|
}
|
|
52
108
|
if (type === exports.ObjType.FLOW) {
|
|
53
|
-
return obj;
|
|
109
|
+
return createDefaultNav(obj, args);
|
|
54
110
|
}
|
|
55
111
|
if (type === exports.ObjType.ASSET_WRAPPER) {
|
|
56
112
|
return makeFlow(obj.asset);
|
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Flow } from '@player-ui/types';
|
|
1
|
+
import { Flow, NavigationFlow, NavigationFlowEndState } from '@player-ui/types';
|
|
2
2
|
|
|
3
3
|
declare enum ObjType {
|
|
4
4
|
FLOW = 0,
|
|
@@ -9,9 +9,20 @@ declare enum ObjType {
|
|
|
9
9
|
/** Try to identify any object as an Asset or Flow */
|
|
10
10
|
declare function identify(obj: object): ObjType;
|
|
11
11
|
|
|
12
|
+
interface NavOptions {
|
|
13
|
+
/** An optional expression to run when this Flow starts */
|
|
14
|
+
onStart?: NavigationFlow['onStart'];
|
|
15
|
+
/** An optional expression to run when this Flow ends */
|
|
16
|
+
onEnd?: NavigationFlow['onEnd'];
|
|
17
|
+
/**
|
|
18
|
+
* A description of _how_ the flow ended.
|
|
19
|
+
* If this is a flow started from another flow, the outcome determines the flow transition
|
|
20
|
+
*/
|
|
21
|
+
outcome?: NavigationFlowEndState['outcome'];
|
|
22
|
+
}
|
|
12
23
|
/**
|
|
13
24
|
* Take any given object and try to convert it to a flow
|
|
14
25
|
*/
|
|
15
|
-
declare function makeFlow(obj: any): Flow;
|
|
26
|
+
declare function makeFlow(obj: any, args?: NavOptions): Flow;
|
|
16
27
|
|
|
17
28
|
export { ObjType, identify, makeFlow };
|
package/dist/index.esm.js
CHANGED
|
@@ -18,6 +18,25 @@ function identify(obj) {
|
|
|
18
18
|
return 3;
|
|
19
19
|
}
|
|
20
20
|
|
|
21
|
+
var __defProp = Object.defineProperty;
|
|
22
|
+
var __defProps = Object.defineProperties;
|
|
23
|
+
var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
|
|
24
|
+
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
25
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
26
|
+
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
27
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
28
|
+
var __spreadValues = (a, b) => {
|
|
29
|
+
for (var prop in b || (b = {}))
|
|
30
|
+
if (__hasOwnProp.call(b, prop))
|
|
31
|
+
__defNormalProp(a, prop, b[prop]);
|
|
32
|
+
if (__getOwnPropSymbols)
|
|
33
|
+
for (var prop of __getOwnPropSymbols(b)) {
|
|
34
|
+
if (__propIsEnum.call(b, prop))
|
|
35
|
+
__defNormalProp(a, prop, b[prop]);
|
|
36
|
+
}
|
|
37
|
+
return a;
|
|
38
|
+
};
|
|
39
|
+
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
21
40
|
function unwrapJSend(obj) {
|
|
22
41
|
const isJSend = "status" in obj && "data" in obj;
|
|
23
42
|
if (isJSend) {
|
|
@@ -25,7 +44,44 @@ function unwrapJSend(obj) {
|
|
|
25
44
|
}
|
|
26
45
|
return obj;
|
|
27
46
|
}
|
|
28
|
-
|
|
47
|
+
const createDefaultNav = (flow, options) => {
|
|
48
|
+
var _a, _b;
|
|
49
|
+
if ((flow.navigation === void 0 || flow.navigation === null) && Array.isArray(flow.views) && flow.views.length === 1) {
|
|
50
|
+
const navFlow = {
|
|
51
|
+
startState: "VIEW_0",
|
|
52
|
+
VIEW_0: {
|
|
53
|
+
state_type: "VIEW",
|
|
54
|
+
ref: (_a = flow.views[0].id) != null ? _a : `${flow.id}-views-0`,
|
|
55
|
+
transitions: {
|
|
56
|
+
"*": "END_done",
|
|
57
|
+
Prev: "END_back"
|
|
58
|
+
}
|
|
59
|
+
},
|
|
60
|
+
END_done: {
|
|
61
|
+
state_type: "END",
|
|
62
|
+
outcome: (_b = options == null ? void 0 : options.outcome) != null ? _b : "doneWithFlow"
|
|
63
|
+
},
|
|
64
|
+
END_back: {
|
|
65
|
+
state_type: "END",
|
|
66
|
+
outcome: "BACK"
|
|
67
|
+
}
|
|
68
|
+
};
|
|
69
|
+
if ((options == null ? void 0 : options.onStart) !== void 0) {
|
|
70
|
+
navFlow.onStart = options.onStart;
|
|
71
|
+
}
|
|
72
|
+
if ((options == null ? void 0 : options.onEnd) !== void 0) {
|
|
73
|
+
navFlow.onEnd = options.onEnd;
|
|
74
|
+
}
|
|
75
|
+
return __spreadProps(__spreadValues({}, flow), {
|
|
76
|
+
navigation: {
|
|
77
|
+
BEGIN: "Flow",
|
|
78
|
+
Flow: navFlow
|
|
79
|
+
}
|
|
80
|
+
});
|
|
81
|
+
}
|
|
82
|
+
return flow;
|
|
83
|
+
};
|
|
84
|
+
function makeFlow(obj, args) {
|
|
29
85
|
const objified = unwrapJSend(typeof obj === "string" ? JSON.parse(obj) : obj);
|
|
30
86
|
if (Array.isArray(objified)) {
|
|
31
87
|
const collection = {
|
|
@@ -46,7 +102,7 @@ function makeFlow(obj) {
|
|
|
46
102
|
throw new Error("No clue how to convert this into a flow. Just do it yourself");
|
|
47
103
|
}
|
|
48
104
|
if (type === ObjType.FLOW) {
|
|
49
|
-
return obj;
|
|
105
|
+
return createDefaultNav(obj, args);
|
|
50
106
|
}
|
|
51
107
|
if (type === ObjType.ASSET_WRAPPER) {
|
|
52
108
|
return makeFlow(obj.asset);
|
|
@@ -0,0 +1,251 @@
|
|
|
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["MakeFlow"] = factory();
|
|
8
|
+
else
|
|
9
|
+
root["MakeFlow"] = 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/core/make-flow/dist/index.esm.js");
|
|
95
|
+
/******/ })
|
|
96
|
+
/************************************************************************/
|
|
97
|
+
/******/ ({
|
|
98
|
+
|
|
99
|
+
/***/ "./bazel-out/k8-fastbuild/bin/core/make-flow/dist/index.esm.js":
|
|
100
|
+
/*!*********************************************************************!*\
|
|
101
|
+
!*** ./bazel-out/k8-fastbuild/bin/core/make-flow/dist/index.esm.js ***!
|
|
102
|
+
\*********************************************************************/
|
|
103
|
+
/*! exports provided: ObjType, identify, makeFlow */
|
|
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__, "ObjType", function() { return ObjType; });
|
|
109
|
+
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "identify", function() { return identify; });
|
|
110
|
+
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "makeFlow", function() { return makeFlow; });
|
|
111
|
+
var ObjType;
|
|
112
|
+
(function(ObjType2) {
|
|
113
|
+
ObjType2[ObjType2["FLOW"] = 0] = "FLOW";
|
|
114
|
+
ObjType2[ObjType2["ASSET"] = 1] = "ASSET";
|
|
115
|
+
ObjType2[ObjType2["ASSET_WRAPPER"] = 2] = "ASSET_WRAPPER";
|
|
116
|
+
ObjType2[ObjType2["UNKNOWN"] = 3] = "UNKNOWN";
|
|
117
|
+
})(ObjType || (ObjType = {}));
|
|
118
|
+
function identify(obj) {
|
|
119
|
+
if ("id" in obj && "type" in obj) {
|
|
120
|
+
return 1;
|
|
121
|
+
}
|
|
122
|
+
if ("asset" in obj && identify(obj.asset) === 1) {
|
|
123
|
+
return 2;
|
|
124
|
+
}
|
|
125
|
+
if ("navigation" in obj || "schema" in obj || "views" in obj) {
|
|
126
|
+
return 0;
|
|
127
|
+
}
|
|
128
|
+
return 3;
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
var __defProp = Object.defineProperty;
|
|
132
|
+
var __defProps = Object.defineProperties;
|
|
133
|
+
var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
|
|
134
|
+
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
135
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
136
|
+
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
137
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
138
|
+
var __spreadValues = (a, b) => {
|
|
139
|
+
for (var prop in b || (b = {}))
|
|
140
|
+
if (__hasOwnProp.call(b, prop))
|
|
141
|
+
__defNormalProp(a, prop, b[prop]);
|
|
142
|
+
if (__getOwnPropSymbols)
|
|
143
|
+
for (var prop of __getOwnPropSymbols(b)) {
|
|
144
|
+
if (__propIsEnum.call(b, prop))
|
|
145
|
+
__defNormalProp(a, prop, b[prop]);
|
|
146
|
+
}
|
|
147
|
+
return a;
|
|
148
|
+
};
|
|
149
|
+
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
150
|
+
function unwrapJSend(obj) {
|
|
151
|
+
const isJSend = "status" in obj && "data" in obj;
|
|
152
|
+
if (isJSend) {
|
|
153
|
+
return obj.data;
|
|
154
|
+
}
|
|
155
|
+
return obj;
|
|
156
|
+
}
|
|
157
|
+
const createDefaultNav = (flow, options) => {
|
|
158
|
+
var _a, _b;
|
|
159
|
+
if ((flow.navigation === void 0 || flow.navigation === null) && Array.isArray(flow.views) && flow.views.length === 1) {
|
|
160
|
+
const navFlow = {
|
|
161
|
+
startState: "VIEW_0",
|
|
162
|
+
VIEW_0: {
|
|
163
|
+
state_type: "VIEW",
|
|
164
|
+
ref: (_a = flow.views[0].id) != null ? _a : `${flow.id}-views-0`,
|
|
165
|
+
transitions: {
|
|
166
|
+
"*": "END_done",
|
|
167
|
+
Prev: "END_back"
|
|
168
|
+
}
|
|
169
|
+
},
|
|
170
|
+
END_done: {
|
|
171
|
+
state_type: "END",
|
|
172
|
+
outcome: (_b = options == null ? void 0 : options.outcome) != null ? _b : "doneWithFlow"
|
|
173
|
+
},
|
|
174
|
+
END_back: {
|
|
175
|
+
state_type: "END",
|
|
176
|
+
outcome: "BACK"
|
|
177
|
+
}
|
|
178
|
+
};
|
|
179
|
+
if ((options == null ? void 0 : options.onStart) !== void 0) {
|
|
180
|
+
navFlow.onStart = options.onStart;
|
|
181
|
+
}
|
|
182
|
+
if ((options == null ? void 0 : options.onEnd) !== void 0) {
|
|
183
|
+
navFlow.onEnd = options.onEnd;
|
|
184
|
+
}
|
|
185
|
+
return __spreadProps(__spreadValues({}, flow), {
|
|
186
|
+
navigation: {
|
|
187
|
+
BEGIN: "Flow",
|
|
188
|
+
Flow: navFlow
|
|
189
|
+
}
|
|
190
|
+
});
|
|
191
|
+
}
|
|
192
|
+
return flow;
|
|
193
|
+
};
|
|
194
|
+
function makeFlow(obj, args) {
|
|
195
|
+
const objified = unwrapJSend(typeof obj === "string" ? JSON.parse(obj) : obj);
|
|
196
|
+
if (Array.isArray(objified)) {
|
|
197
|
+
const collection = {
|
|
198
|
+
id: "collection",
|
|
199
|
+
type: "collection",
|
|
200
|
+
values: objified.map((v) => {
|
|
201
|
+
const type2 = identify(v);
|
|
202
|
+
if (type2 === ObjType.ASSET) {
|
|
203
|
+
return { asset: v };
|
|
204
|
+
}
|
|
205
|
+
return v;
|
|
206
|
+
})
|
|
207
|
+
};
|
|
208
|
+
return makeFlow(collection);
|
|
209
|
+
}
|
|
210
|
+
const type = identify(obj);
|
|
211
|
+
if (type === ObjType.UNKNOWN) {
|
|
212
|
+
throw new Error("No clue how to convert this into a flow. Just do it yourself");
|
|
213
|
+
}
|
|
214
|
+
if (type === ObjType.FLOW) {
|
|
215
|
+
return createDefaultNav(obj, args);
|
|
216
|
+
}
|
|
217
|
+
if (type === ObjType.ASSET_WRAPPER) {
|
|
218
|
+
return makeFlow(obj.asset);
|
|
219
|
+
}
|
|
220
|
+
return {
|
|
221
|
+
id: "generated-flow",
|
|
222
|
+
views: [obj],
|
|
223
|
+
data: {},
|
|
224
|
+
navigation: {
|
|
225
|
+
BEGIN: "FLOW_1",
|
|
226
|
+
FLOW_1: {
|
|
227
|
+
startState: "VIEW_1",
|
|
228
|
+
VIEW_1: {
|
|
229
|
+
state_type: "VIEW",
|
|
230
|
+
ref: obj.id,
|
|
231
|
+
transitions: {
|
|
232
|
+
"*": "END_Done"
|
|
233
|
+
}
|
|
234
|
+
},
|
|
235
|
+
END_Done: {
|
|
236
|
+
state_type: "END",
|
|
237
|
+
outcome: "done"
|
|
238
|
+
}
|
|
239
|
+
}
|
|
240
|
+
}
|
|
241
|
+
};
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
|
|
245
|
+
//# sourceMappingURL=index.esm.js.map
|
|
246
|
+
|
|
247
|
+
|
|
248
|
+
/***/ })
|
|
249
|
+
|
|
250
|
+
/******/ });
|
|
251
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
!function(e,t){"object"===typeof exports&&"object"===typeof module?module.exports=t():"function"===typeof define&&define.amd?define([],t):"object"===typeof exports?exports.MakeFlow=t():e.MakeFlow=t()}(this,(function(){return function(e){var t={};function n(o){if(t[o])return t[o].exports;var r=t[o]={i:o,l:!1,exports:{}};return e[o].call(r.exports,r,r.exports,n),r.l=!0,r.exports}return n.m=e,n.c=t,n.d=function(e,t,o){n.o(e,t)||Object.defineProperty(e,t,{enumerable:!0,get:o})},n.r=function(e){"undefined"!==typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},n.t=function(e,t){if(1&t&&(e=n(e)),8&t)return e;if(4&t&&"object"===typeof e&&e&&e.__esModule)return e;var o=Object.create(null);if(n.r(o),Object.defineProperty(o,"default",{enumerable:!0,value:e}),2&t&&"string"!=typeof e)for(var r in e)n.d(o,r,function(t){return e[t]}.bind(null,r));return o},n.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return n.d(t,"a",t),t},n.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},n.p="",n(n.s=0)}([function(e,t,n){"use strict";var o,r;function i(e){return"id"in e&&"type"in e?1:"asset"in e&&1===i(e.asset)?2:"navigation"in e||"schema"in e||"views"in e?0:3}n.r(t),n.d(t,"ObjType",(function(){return o})),n.d(t,"identify",(function(){return i})),n.d(t,"makeFlow",(function(){return y})),(r=o||(o={}))[r.FLOW=0]="FLOW",r[r.ASSET=1]="ASSET",r[r.ASSET_WRAPPER=2]="ASSET_WRAPPER",r[r.UNKNOWN=3]="UNKNOWN";var a=Object.defineProperty,u=Object.defineProperties,l=Object.getOwnPropertyDescriptors,s=Object.getOwnPropertySymbols,c=Object.prototype.hasOwnProperty,f=Object.prototype.propertyIsEnumerable,d=(e,t,n)=>t in e?a(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n;const p=(e,t)=>{var n,o,r;if((void 0===e.navigation||null===e.navigation)&&Array.isArray(e.views)&&1===e.views.length){const i={startState:"VIEW_0",VIEW_0:{state_type:"VIEW",ref:null!=(n=e.views[0].id)?n:`${e.id}-views-0`,transitions:{"*":"END_done",Prev:"END_back"}},END_done:{state_type:"END",outcome:null!=(o=null==t?void 0:t.outcome)?o:"doneWithFlow"},END_back:{state_type:"END",outcome:"BACK"}};return void 0!==(null==t?void 0:t.onStart)&&(i.onStart=t.onStart),void 0!==(null==t?void 0:t.onEnd)&&(i.onEnd=t.onEnd),r=((e,t)=>{for(var n in t||(t={}))c.call(t,n)&&d(e,n,t[n]);if(s)for(var n of s(t))f.call(t,n)&&d(e,n,t[n]);return e})({},e),u(r,l({navigation:{BEGIN:"Flow",Flow:i}}))}return e};function y(e,t){const n=function(e){return"status"in e&&"data"in e?e.data:e}("string"===typeof e?JSON.parse(e):e);if(Array.isArray(n)){return y({id:"collection",type:"collection",values:n.map((e=>i(e)===o.ASSET?{asset:e}:e))})}const r=i(e);if(r===o.UNKNOWN)throw new Error("No clue how to convert this into a flow. Just do it yourself");return r===o.FLOW?p(e,t):r===o.ASSET_WRAPPER?y(e.asset):{id:"generated-flow",views:[e],data:{},navigation:{BEGIN:"FLOW_1",FLOW_1:{startState:"VIEW_1",VIEW_1:{state_type:"VIEW",ref:e.id,transitions:{"*":"END_Done"}},END_Done:{state_type:"END",outcome:"done"}}}}}}])}));
|
package/package.json
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@player-ui/make-flow",
|
|
3
|
-
"version": "0.4.0-next.
|
|
3
|
+
"version": "0.4.0-next.10",
|
|
4
4
|
"private": false,
|
|
5
5
|
"publishConfig": {
|
|
6
6
|
"registry": "https://registry.npmjs.org"
|
|
7
7
|
},
|
|
8
8
|
"peerDependencies": {},
|
|
9
9
|
"dependencies": {
|
|
10
|
-
"@player-ui/types": "0.4.0-next.
|
|
10
|
+
"@player-ui/types": "0.4.0-next.10",
|
|
11
11
|
"@babel/runtime": "7.15.4"
|
|
12
12
|
},
|
|
13
13
|
"main": "dist/index.cjs.js",
|
|
@@ -51,6 +51,15 @@
|
|
|
51
51
|
{
|
|
52
52
|
"name": "Kelly Harrop",
|
|
53
53
|
"url": "https://github.com/kharrop"
|
|
54
|
+
},
|
|
55
|
+
{
|
|
56
|
+
"name": "Alejandro Fimbres",
|
|
57
|
+
"url": "https://github.com/lexfm"
|
|
58
|
+
},
|
|
59
|
+
{
|
|
60
|
+
"name": "Rafael Campos",
|
|
61
|
+
"url": "https://github.com/rafbcampos"
|
|
54
62
|
}
|
|
55
|
-
]
|
|
63
|
+
],
|
|
64
|
+
"bundle": "./dist/make-flow.prod.js"
|
|
56
65
|
}
|
package/src/index.ts
CHANGED
|
@@ -1,4 +1,10 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type {
|
|
2
|
+
Flow,
|
|
3
|
+
Asset,
|
|
4
|
+
AssetWrapper,
|
|
5
|
+
NavigationFlow,
|
|
6
|
+
NavigationFlowEndState,
|
|
7
|
+
} from '@player-ui/types';
|
|
2
8
|
import identify, { ObjType } from './identify';
|
|
3
9
|
|
|
4
10
|
export * from './identify';
|
|
@@ -27,10 +33,71 @@ function unwrapJSend(obj: object) {
|
|
|
27
33
|
return obj;
|
|
28
34
|
}
|
|
29
35
|
|
|
36
|
+
interface NavOptions {
|
|
37
|
+
/** An optional expression to run when this Flow starts */
|
|
38
|
+
onStart?: NavigationFlow['onStart'];
|
|
39
|
+
/** An optional expression to run when this Flow ends */
|
|
40
|
+
onEnd?: NavigationFlow['onEnd'];
|
|
41
|
+
/**
|
|
42
|
+
* A description of _how_ the flow ended.
|
|
43
|
+
* If this is a flow started from another flow, the outcome determines the flow transition
|
|
44
|
+
*/
|
|
45
|
+
outcome?: NavigationFlowEndState['outcome'];
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* create a default navigation if the flow was exactly one view and there is no navigation already
|
|
50
|
+
*/
|
|
51
|
+
const createDefaultNav = (flow: Flow, options?: NavOptions): Flow => {
|
|
52
|
+
if (
|
|
53
|
+
(flow.navigation === undefined || flow.navigation === null) &&
|
|
54
|
+
Array.isArray(flow.views) &&
|
|
55
|
+
flow.views.length === 1
|
|
56
|
+
) {
|
|
57
|
+
const navFlow: NavigationFlow = {
|
|
58
|
+
startState: 'VIEW_0',
|
|
59
|
+
VIEW_0: {
|
|
60
|
+
state_type: 'VIEW',
|
|
61
|
+
ref: flow.views[0].id ?? `${flow.id}-views-0`,
|
|
62
|
+
transitions: {
|
|
63
|
+
'*': 'END_done',
|
|
64
|
+
Prev: 'END_back',
|
|
65
|
+
},
|
|
66
|
+
},
|
|
67
|
+
END_done: {
|
|
68
|
+
state_type: 'END',
|
|
69
|
+
outcome: options?.outcome ?? 'doneWithFlow',
|
|
70
|
+
},
|
|
71
|
+
END_back: {
|
|
72
|
+
state_type: 'END',
|
|
73
|
+
outcome: 'BACK',
|
|
74
|
+
},
|
|
75
|
+
};
|
|
76
|
+
|
|
77
|
+
if (options?.onStart !== undefined) {
|
|
78
|
+
navFlow.onStart = options.onStart;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
if (options?.onEnd !== undefined) {
|
|
82
|
+
navFlow.onEnd = options.onEnd;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
return {
|
|
86
|
+
...flow,
|
|
87
|
+
navigation: {
|
|
88
|
+
BEGIN: 'Flow',
|
|
89
|
+
Flow: navFlow,
|
|
90
|
+
},
|
|
91
|
+
};
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
return flow;
|
|
95
|
+
};
|
|
96
|
+
|
|
30
97
|
/**
|
|
31
98
|
* Take any given object and try to convert it to a flow
|
|
32
99
|
*/
|
|
33
|
-
export function makeFlow(obj: any): Flow {
|
|
100
|
+
export function makeFlow(obj: any, args?: NavOptions): Flow {
|
|
34
101
|
const objified = unwrapJSend(typeof obj === 'string' ? JSON.parse(obj) : obj);
|
|
35
102
|
|
|
36
103
|
if (Array.isArray(objified)) {
|
|
@@ -60,7 +127,7 @@ export function makeFlow(obj: any): Flow {
|
|
|
60
127
|
}
|
|
61
128
|
|
|
62
129
|
if (type === ObjType.FLOW) {
|
|
63
|
-
return obj;
|
|
130
|
+
return createDefaultNav(obj, args);
|
|
64
131
|
}
|
|
65
132
|
|
|
66
133
|
if (type === ObjType.ASSET_WRAPPER) {
|