@player-ui/make-flow
Advanced tools
Comparing version 0.4.0--canary.129.4506 to 0.4.0--canary.131.4657
@@ -25,2 +25,21 @@ 'use strict'; | ||
var __defProp = Object.defineProperty; | ||
var __defProps = Object.defineProperties; | ||
var __getOwnPropDescs = Object.getOwnPropertyDescriptors; | ||
var __getOwnPropSymbols = Object.getOwnPropertySymbols; | ||
var __hasOwnProp = Object.prototype.hasOwnProperty; | ||
var __propIsEnum = Object.prototype.propertyIsEnumerable; | ||
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value; | ||
var __spreadValues = (a, b) => { | ||
for (var prop in b || (b = {})) | ||
if (__hasOwnProp.call(b, prop)) | ||
__defNormalProp(a, prop, b[prop]); | ||
if (__getOwnPropSymbols) | ||
for (var prop of __getOwnPropSymbols(b)) { | ||
if (__propIsEnum.call(b, prop)) | ||
__defNormalProp(a, prop, b[prop]); | ||
} | ||
return a; | ||
}; | ||
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b)); | ||
function unwrapJSend(obj) { | ||
@@ -33,3 +52,40 @@ const isJSend = "status" in obj && "data" in obj; | ||
} | ||
function makeFlow(obj) { | ||
const createDefaultNav = (flow, options) => { | ||
var _a, _b; | ||
if ((flow.navigation === void 0 || flow.navigation === null) && Array.isArray(flow.views) && flow.views.length === 1) { | ||
const navFlow = { | ||
startState: "VIEW_0", | ||
VIEW_0: { | ||
state_type: "VIEW", | ||
ref: (_a = flow.views[0].id) != null ? _a : `${flow.id}-views-0`, | ||
transitions: { | ||
"*": "END_done", | ||
Prev: "END_back" | ||
} | ||
}, | ||
END_done: { | ||
state_type: "END", | ||
outcome: (_b = options == null ? void 0 : options.outcome) != null ? _b : "doneWithFlow" | ||
}, | ||
END_back: { | ||
state_type: "END", | ||
outcome: "BACK" | ||
} | ||
}; | ||
if ((options == null ? void 0 : options.onStart) !== void 0) { | ||
navFlow.onStart = options.onStart; | ||
} | ||
if ((options == null ? void 0 : options.onEnd) !== void 0) { | ||
navFlow.onEnd = options.onEnd; | ||
} | ||
return __spreadProps(__spreadValues({}, flow), { | ||
navigation: { | ||
BEGIN: "Flow", | ||
Flow: navFlow | ||
} | ||
}); | ||
} | ||
return flow; | ||
}; | ||
function makeFlow(obj, args) { | ||
const objified = unwrapJSend(typeof obj === "string" ? JSON.parse(obj) : obj); | ||
@@ -55,3 +111,3 @@ if (Array.isArray(objified)) { | ||
if (type === exports.ObjType.FLOW) { | ||
return obj; | ||
return createDefaultNav(obj, args); | ||
} | ||
@@ -58,0 +114,0 @@ if (type === exports.ObjType.ASSET_WRAPPER) { |
@@ -1,2 +0,2 @@ | ||
import { Flow } from '@player-ui/types'; | ||
import { Flow, NavigationFlow, NavigationFlowEndState } from '@player-ui/types'; | ||
@@ -12,7 +12,18 @@ declare enum ObjType { | ||
interface NavOptions { | ||
/** An optional expression to run when this Flow starts */ | ||
onStart?: NavigationFlow['onStart']; | ||
/** An optional expression to run when this Flow ends */ | ||
onEnd?: NavigationFlow['onEnd']; | ||
/** | ||
* A description of _how_ the flow ended. | ||
* If this is a flow started from another flow, the outcome determines the flow transition | ||
*/ | ||
outcome?: NavigationFlowEndState['outcome']; | ||
} | ||
/** | ||
* Take any given object and try to convert it to a flow | ||
*/ | ||
declare function makeFlow(obj: any): Flow; | ||
declare function makeFlow(obj: any, args?: NavOptions): Flow; | ||
export { ObjType, identify, makeFlow }; |
@@ -21,2 +21,21 @@ var ObjType; | ||
var __defProp = Object.defineProperty; | ||
var __defProps = Object.defineProperties; | ||
var __getOwnPropDescs = Object.getOwnPropertyDescriptors; | ||
var __getOwnPropSymbols = Object.getOwnPropertySymbols; | ||
var __hasOwnProp = Object.prototype.hasOwnProperty; | ||
var __propIsEnum = Object.prototype.propertyIsEnumerable; | ||
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value; | ||
var __spreadValues = (a, b) => { | ||
for (var prop in b || (b = {})) | ||
if (__hasOwnProp.call(b, prop)) | ||
__defNormalProp(a, prop, b[prop]); | ||
if (__getOwnPropSymbols) | ||
for (var prop of __getOwnPropSymbols(b)) { | ||
if (__propIsEnum.call(b, prop)) | ||
__defNormalProp(a, prop, b[prop]); | ||
} | ||
return a; | ||
}; | ||
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b)); | ||
function unwrapJSend(obj) { | ||
@@ -29,3 +48,40 @@ const isJSend = "status" in obj && "data" in obj; | ||
} | ||
function makeFlow(obj) { | ||
const createDefaultNav = (flow, options) => { | ||
var _a, _b; | ||
if ((flow.navigation === void 0 || flow.navigation === null) && Array.isArray(flow.views) && flow.views.length === 1) { | ||
const navFlow = { | ||
startState: "VIEW_0", | ||
VIEW_0: { | ||
state_type: "VIEW", | ||
ref: (_a = flow.views[0].id) != null ? _a : `${flow.id}-views-0`, | ||
transitions: { | ||
"*": "END_done", | ||
Prev: "END_back" | ||
} | ||
}, | ||
END_done: { | ||
state_type: "END", | ||
outcome: (_b = options == null ? void 0 : options.outcome) != null ? _b : "doneWithFlow" | ||
}, | ||
END_back: { | ||
state_type: "END", | ||
outcome: "BACK" | ||
} | ||
}; | ||
if ((options == null ? void 0 : options.onStart) !== void 0) { | ||
navFlow.onStart = options.onStart; | ||
} | ||
if ((options == null ? void 0 : options.onEnd) !== void 0) { | ||
navFlow.onEnd = options.onEnd; | ||
} | ||
return __spreadProps(__spreadValues({}, flow), { | ||
navigation: { | ||
BEGIN: "Flow", | ||
Flow: navFlow | ||
} | ||
}); | ||
} | ||
return flow; | ||
}; | ||
function makeFlow(obj, args) { | ||
const objified = unwrapJSend(typeof obj === "string" ? JSON.parse(obj) : obj); | ||
@@ -51,3 +107,3 @@ if (Array.isArray(objified)) { | ||
if (type === ObjType.FLOW) { | ||
return obj; | ||
return createDefaultNav(obj, args); | ||
} | ||
@@ -54,0 +110,0 @@ if (type === ObjType.ASSET_WRAPPER) { |
@@ -131,2 +131,21 @@ (function webpackUniversalModuleDefinition(root, factory) { | ||
var __defProp = Object.defineProperty; | ||
var __defProps = Object.defineProperties; | ||
var __getOwnPropDescs = Object.getOwnPropertyDescriptors; | ||
var __getOwnPropSymbols = Object.getOwnPropertySymbols; | ||
var __hasOwnProp = Object.prototype.hasOwnProperty; | ||
var __propIsEnum = Object.prototype.propertyIsEnumerable; | ||
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value; | ||
var __spreadValues = (a, b) => { | ||
for (var prop in b || (b = {})) | ||
if (__hasOwnProp.call(b, prop)) | ||
__defNormalProp(a, prop, b[prop]); | ||
if (__getOwnPropSymbols) | ||
for (var prop of __getOwnPropSymbols(b)) { | ||
if (__propIsEnum.call(b, prop)) | ||
__defNormalProp(a, prop, b[prop]); | ||
} | ||
return a; | ||
}; | ||
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b)); | ||
function unwrapJSend(obj) { | ||
@@ -139,3 +158,40 @@ const isJSend = "status" in obj && "data" in obj; | ||
} | ||
function makeFlow(obj) { | ||
const createDefaultNav = (flow, options) => { | ||
var _a, _b; | ||
if ((flow.navigation === void 0 || flow.navigation === null) && Array.isArray(flow.views) && flow.views.length === 1) { | ||
const navFlow = { | ||
startState: "VIEW_0", | ||
VIEW_0: { | ||
state_type: "VIEW", | ||
ref: (_a = flow.views[0].id) != null ? _a : `${flow.id}-views-0`, | ||
transitions: { | ||
"*": "END_done", | ||
Prev: "END_back" | ||
} | ||
}, | ||
END_done: { | ||
state_type: "END", | ||
outcome: (_b = options == null ? void 0 : options.outcome) != null ? _b : "doneWithFlow" | ||
}, | ||
END_back: { | ||
state_type: "END", | ||
outcome: "BACK" | ||
} | ||
}; | ||
if ((options == null ? void 0 : options.onStart) !== void 0) { | ||
navFlow.onStart = options.onStart; | ||
} | ||
if ((options == null ? void 0 : options.onEnd) !== void 0) { | ||
navFlow.onEnd = options.onEnd; | ||
} | ||
return __spreadProps(__spreadValues({}, flow), { | ||
navigation: { | ||
BEGIN: "Flow", | ||
Flow: navFlow | ||
} | ||
}); | ||
} | ||
return flow; | ||
}; | ||
function makeFlow(obj, args) { | ||
const objified = unwrapJSend(typeof obj === "string" ? JSON.parse(obj) : obj); | ||
@@ -161,3 +217,3 @@ if (Array.isArray(objified)) { | ||
if (type === ObjType.FLOW) { | ||
return obj; | ||
return createDefaultNav(obj, args); | ||
} | ||
@@ -164,0 +220,0 @@ if (type === ObjType.ASSET_WRAPPER) { |
@@ -1,1 +0,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(r){if(t[r])return t[r].exports;var o=t[r]={i:r,l:!1,exports:{}};return e[r].call(o.exports,o,o.exports,n),o.l=!0,o.exports}return n.m=e,n.c=t,n.d=function(e,t,r){n.o(e,t)||Object.defineProperty(e,t,{enumerable:!0,get:r})},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 r=Object.create(null);if(n.r(r),Object.defineProperty(r,"default",{enumerable:!0,value:e}),2&t&&"string"!=typeof e)for(var o in e)n.d(r,o,function(t){return e[t]}.bind(null,o));return r},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 r,o;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}function u(e){const t=function(e){return"status"in e&&"data"in e?e.data:e}("string"===typeof e?JSON.parse(e):e);if(Array.isArray(t)){return u({id:"collection",type:"collection",values:t.map((e=>i(e)===r.ASSET?{asset:e}:e))})}const n=i(e);if(n===r.UNKNOWN)throw new Error("No clue how to convert this into a flow. Just do it yourself");return n===r.FLOW?e:n===r.ASSET_WRAPPER?u(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"}}}}}n.r(t),n.d(t,"ObjType",(function(){return r})),n.d(t,"identify",(function(){return i})),n.d(t,"makeFlow",(function(){return u})),(o=r||(r={}))[o.FLOW=0]="FLOW",o[o.ASSET=1]="ASSET",o[o.ASSET_WRAPPER=2]="ASSET_WRAPPER",o[o.UNKNOWN=3]="UNKNOWN"}])})); | ||
!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"}}}}}}])})); |
{ | ||
"name": "@player-ui/make-flow", | ||
"version": "0.4.0--canary.129.4506", | ||
"version": "0.4.0--canary.131.4657", | ||
"private": false, | ||
@@ -10,3 +10,3 @@ "publishConfig": { | ||
"dependencies": { | ||
"@player-ui/types": "0.4.0--canary.129.4506", | ||
"@player-ui/types": "0.4.0--canary.131.4657", | ||
"@babel/runtime": "7.15.4" | ||
@@ -13,0 +13,0 @@ }, |
@@ -1,2 +0,8 @@ | ||
import type { Flow, Asset, AssetWrapper } from '@player-ui/types'; | ||
import type { | ||
Flow, | ||
Asset, | ||
AssetWrapper, | ||
NavigationFlow, | ||
NavigationFlowEndState, | ||
} from '@player-ui/types'; | ||
import identify, { ObjType } from './identify'; | ||
@@ -30,6 +36,67 @@ | ||
interface NavOptions { | ||
/** An optional expression to run when this Flow starts */ | ||
onStart?: NavigationFlow['onStart']; | ||
/** An optional expression to run when this Flow ends */ | ||
onEnd?: NavigationFlow['onEnd']; | ||
/** | ||
* A description of _how_ the flow ended. | ||
* If this is a flow started from another flow, the outcome determines the flow transition | ||
*/ | ||
outcome?: NavigationFlowEndState['outcome']; | ||
} | ||
/** | ||
* create a default navigation if the flow was exactly one view and there is no navigation already | ||
*/ | ||
const createDefaultNav = (flow: Flow, options?: NavOptions): Flow => { | ||
if ( | ||
(flow.navigation === undefined || flow.navigation === null) && | ||
Array.isArray(flow.views) && | ||
flow.views.length === 1 | ||
) { | ||
const navFlow: NavigationFlow = { | ||
startState: 'VIEW_0', | ||
VIEW_0: { | ||
state_type: 'VIEW', | ||
ref: flow.views[0].id ?? `${flow.id}-views-0`, | ||
transitions: { | ||
'*': 'END_done', | ||
Prev: 'END_back', | ||
}, | ||
}, | ||
END_done: { | ||
state_type: 'END', | ||
outcome: options?.outcome ?? 'doneWithFlow', | ||
}, | ||
END_back: { | ||
state_type: 'END', | ||
outcome: 'BACK', | ||
}, | ||
}; | ||
if (options?.onStart !== undefined) { | ||
navFlow.onStart = options.onStart; | ||
} | ||
if (options?.onEnd !== undefined) { | ||
navFlow.onEnd = options.onEnd; | ||
} | ||
return { | ||
...flow, | ||
navigation: { | ||
BEGIN: 'Flow', | ||
Flow: navFlow, | ||
}, | ||
}; | ||
} | ||
return flow; | ||
}; | ||
/** | ||
* Take any given object and try to convert it to a flow | ||
*/ | ||
export function makeFlow(obj: any): Flow { | ||
export function makeFlow(obj: any, args?: NavOptions): Flow { | ||
const objified = unwrapJSend(typeof obj === 'string' ? JSON.parse(obj) : obj); | ||
@@ -64,3 +131,3 @@ | ||
if (type === ObjType.FLOW) { | ||
return obj; | ||
return createDefaultNav(obj, args); | ||
} | ||
@@ -67,0 +134,0 @@ |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
25874
696
+ Added@player-ui/types@0.4.0--canary.131.4657(transitive)
- Removed@player-ui/types@0.4.0--canary.129.4506(transitive)