@btree/core
Advanced tools
Comparing version 0.2.2 to 0.2.3
@@ -5,3 +5,3 @@ 'use strict'; | ||
var nanoid = require('nanoid'); | ||
var nanoid = _interopDefault(require('nanoid')); | ||
var produce = require('immer'); | ||
@@ -86,3 +86,3 @@ var produce__default = _interopDefault(produce); | ||
var root = _extends({ | ||
id: nanoid.nanoid(), | ||
id: nanoid(), | ||
name: name, | ||
@@ -144,3 +144,3 @@ type: "Root" | ||
return _extends({ | ||
id: nanoid.nanoid(), | ||
id: nanoid(), | ||
type: "Selector" | ||
@@ -160,3 +160,3 @@ /* Selector */ | ||
return _extends({ | ||
id: nanoid.nanoid(), | ||
id: nanoid(), | ||
type: "Sequence" | ||
@@ -176,3 +176,3 @@ /* Sequence */ | ||
return _extends({ | ||
id: nanoid.nanoid(), | ||
id: nanoid(), | ||
type: "Parallel" | ||
@@ -186,3 +186,3 @@ /* Parallel */ | ||
return _extends({ | ||
id: nanoid.nanoid(), | ||
id: nanoid(), | ||
name: name, | ||
@@ -203,3 +203,3 @@ type: "Condition" | ||
return _extends({ | ||
id: nanoid.nanoid(), | ||
id: nanoid(), | ||
type: "Portal" | ||
@@ -232,3 +232,3 @@ /* Portal */ | ||
return _extends({ | ||
id: nanoid.nanoid(), | ||
id: nanoid(), | ||
type: "State" | ||
@@ -243,3 +243,3 @@ /* State */ | ||
return _extends({ | ||
id: nanoid.nanoid(), | ||
id: nanoid(), | ||
type: "Invert" | ||
@@ -253,3 +253,3 @@ /* Invert */ | ||
return _extends({ | ||
id: nanoid.nanoid(), | ||
id: nanoid(), | ||
name: name, | ||
@@ -256,0 +256,0 @@ type: "Action" |
@@ -1,2 +0,2 @@ | ||
"use strict";var e,t=require("nanoid"),n=require("immer"),r=(e=n)&&"object"==typeof e&&"default"in e?e.default:e;function u(){return(u=Object.assign||function(e){for(var t=1;t<arguments.length;t++){var n=arguments[t];for(var r in n)Object.prototype.hasOwnProperty.call(n,r)&&(e[r]=n[r])}return e}).apply(this,arguments)}function a(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n<t;n++)r[n]=e[n];return r}function i(e){var t=e.getValue("$count",0);e.setValue("$count",t+1)}function s(e){var t;return{$nodeState:u((t={},t.$count=0,t.$wasRun=!1,t.$status="Ready",t),e),setValue:function(e,t){this.$nodeState[e]=t},getValue:function(e,t){return void 0===this.$nodeState?void 0===t?void 0:t:void 0===this.$nodeState[e]?t:this.$nodeState[e]}}}function c(e){return e&&"function"==typeof e.then}n.enablePatches(),exports.nodes={root:function(e,o){var l=this;return function(d,f){void 0===f&&(f={props:{},setState:function(){}});var h={},v=function(e){return e in h||(h[e]=[]),h[e]},p=u({id:t.nanoid(),name:e,type:"Root",children:o(),state:d,tick:function(e){if("undefined"!=typeof window){this.dispatchEvent(new CustomEvent("tickstart"));var t=function e(t,u,s){void 0===s&&(s={props:{},setState:function(){}});var o=u.state;switch(t.setValue("$wasRun",!0),t.type){case"Action":var l=t.getValue("$status");if("Running"===l){var d=t.getValue("$patches");if(d){var f=n.applyPatches(o,d);return t.setValue("$patches",void 0),t.setValue("$status","Success"),u.state=f,null==s.setState||s.setState(f),u.tick(s.props),"Success"}return l}i(t);var h=r(o,(function(e){return t.fn(e,s.props||{})}),(function(e){t.setValue("$patches",e),c(h)&&u.tick()}));return c(h)?(t.setValue("$status","Running"),"Running"):(u.state=h,null==s.setState||s.setState(h),t.setValue("$status","Success"),"Success");case"Condition":return i(t),t.setValue("$status","Running"),t.exec({state:o,node:t,root:u},s.props||{})?(t.setValue("$status","Success"),"Success"):(t.setValue("$status","Failure"),"Failure");case"Invert":i(t),t.setValue("$status","Running");var v=e(t.children,u,s);return"Failure"===v?(t.setValue("$status","Success"),"Success"):"Success"===v?(t.setValue("$status","Failure"),"Failure"):v;case"State":return i(t),e(t.children,u,s);case"Decorator":return i(t),t.decorator(e(t.children,u,s));case"Portal":case"Parallel":i(t),t.setValue("$status","Running");for(var p=[],$=0;$<t.children.length;$++)t.children[$].parent=t,p[$]=e(t.children[$],u,s);var y=p.filter((function(e){return"Success"===e})).length,S=p.filter((function(e){return"Failure"===e})).length;return y===t.children.length?(t.setValue("$status","Success"),"Success"):S===t.children.length?(t.setValue("$status","Failure"),"Failure"):(t.setValue("$status","Running"),"Running");case"Sequence":i(t),t.setValue("$status","Running");for(var g=t.getValue("$sequenceIndex",0);g<t.children.length;){var V=t.children[g];V.parent=t;var R=e(V,u,s);if("Success"!==R){if("Running"===R)return t.setValue("$status","Running"),"Running";if("Failure"===R)return t.setValue("$sequenceIndex",0),t.setValue("$status","Failure"),"Failure"}else t.setValue("$sequenceIndex",++g)}return t.setValue("$sequenceIndex",0),t.setValue("$status","Success"),"Success";case"Selector":i(t),t.setValue("$status","Running");for(var m,b=function(e){var t=0;if("undefined"==typeof Symbol||null==e[Symbol.iterator]){if(Array.isArray(e)||(e=function(e,t){if(e){if("string"==typeof e)return a(e,void 0);var n=Object.prototype.toString.call(e).slice(8,-1);return"Object"===n&&e.constructor&&(n=e.constructor.name),"Map"===n||"Set"===n?Array.from(n):"Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)?a(e,void 0):void 0}}(e)))return function(){return t>=e.length?{done:!0}:{done:!1,value:e[t++]}};throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}return(t=e[Symbol.iterator]()).next.bind(t)}(t.children);!(m=b()).done;){var w=m.value;w.parent=t;var E=e(w,u,s);if("Success"===E||"Running"===E)return t.setValue("$status",E),E}return t.setValue("$status","Failure"),"Failure";default:throw new Error("Invalid node type!")}}(this.children,this,u({},f,{props:e}));return function e(t,n){switch(t.type){case"Action":t.getValue("$wasRun")||t.setValue("$status","Ready");break;case"Portal":case"Invert":case"Parallel":case"Sequence":case"Selector":var r=Array.isArray(t.children)?t.children:[t.children],u=r.some((function(e){return"Running"===e.getValue("$status")})),a=!("Sequence"===t.type)||t.getValue("$sequenceIndex")+1===r.length||!1===t.getValue("$wasRun");!u&&a&&(t.setValue("$status","Ready"),"Sequence"===t.type&&t.setValue("$sequenceIndex",0),r.forEach((function(e){e.setValue("$status","Ready")})));for(var i=0;i<r.length;i++)e(r[i])}t.setValue("$wasRun",!1)}(this.children),this.dispatchEvent(new CustomEvent("tickend")),t}},addEventListener:function(e,t){-1===v(e).indexOf(t)&&h[e].push(t)},removeEventListener:function(e,t){var n=v(e).indexOf(t);-1!==n&&h[e].splice(n,1)},dispatchEvent:function(e){for(var t=v(e.type).slice(),n=0;n<t.length;n++)t[n].call(l,e);return!e.defaultPrevented}},s());return p.addEventListener=p.addEventListener.bind(p),p.removeEventListener=p.removeEventListener.bind(p),p.dispatchEvent=p.dispatchEvent.bind(p),p.tick=p.tick.bind(p),p}},selector:function(e){return u({id:t.nanoid(),type:"Selector",children:e},s())},sequence:function(e){var n;return u({id:t.nanoid(),type:"Sequence",children:e},s(((n={}).$sequenceIndex=0,n)))},parallel:function(e){return u({id:t.nanoid(),type:"Parallel",children:e},s())},condition:function(e,n){return u({id:t.nanoid(),name:e,type:"Condition",exec:function(e,t){return"function"!=typeof n||n(e.state,t)}},s())},portal:function(){return u({id:t.nanoid(),type:"Portal",children:[]},s(),{clear:function(){return this.children.splice(0,this.children.length),this},mount:function(e){return this.children.find((function(t){return t.id===e.id}))||this.children.push(e),this},unmount:function(e){var t=this.children.findIndex((function(t){return t.id===e.id}));return this.children.splice(t,1),this}})},state:function(e,n){return u({id:t.nanoid(),type:"State",children:n,state:e},s())},invert:function(e){return u({id:t.nanoid(),type:"Invert",children:e},s())},action:function(e,n){return u({id:t.nanoid(),name:e,type:"Action",fn:n},s())}}; | ||
"use strict";function e(e){return e&&"object"==typeof e&&"default"in e?e.default:e}var t=e(require("nanoid")),n=require("immer"),r=e(n);function u(){return(u=Object.assign||function(e){for(var t=1;t<arguments.length;t++){var n=arguments[t];for(var r in n)Object.prototype.hasOwnProperty.call(n,r)&&(e[r]=n[r])}return e}).apply(this,arguments)}function a(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n<t;n++)r[n]=e[n];return r}function s(e){var t=e.getValue("$count",0);e.setValue("$count",t+1)}function i(e){var t;return{$nodeState:u((t={},t.$count=0,t.$wasRun=!1,t.$status="Ready",t),e),setValue:function(e,t){this.$nodeState[e]=t},getValue:function(e,t){return void 0===this.$nodeState?void 0===t?void 0:t:void 0===this.$nodeState[e]?t:this.$nodeState[e]}}}function c(e){return e&&"function"==typeof e.then}n.enablePatches(),exports.nodes={root:function(e,l){var o=this;return function(d,f){void 0===f&&(f={props:{},setState:function(){}});var h={},v=function(e){return e in h||(h[e]=[]),h[e]},p=u({id:t(),name:e,type:"Root",children:l(),state:d,tick:function(e){if("undefined"!=typeof window){this.dispatchEvent(new CustomEvent("tickstart"));var t=function e(t,u,i){void 0===i&&(i={props:{},setState:function(){}});var l=u.state;switch(t.setValue("$wasRun",!0),t.type){case"Action":var o=t.getValue("$status");if("Running"===o){var d=t.getValue("$patches");if(d){var f=n.applyPatches(l,d);return t.setValue("$patches",void 0),t.setValue("$status","Success"),u.state=f,null==i.setState||i.setState(f),u.tick(i.props),"Success"}return o}s(t);var h=r(l,(function(e){return t.fn(e,i.props||{})}),(function(e){t.setValue("$patches",e),c(h)&&u.tick()}));return c(h)?(t.setValue("$status","Running"),"Running"):(u.state=h,null==i.setState||i.setState(h),t.setValue("$status","Success"),"Success");case"Condition":return s(t),t.setValue("$status","Running"),t.exec({state:l,node:t,root:u},i.props||{})?(t.setValue("$status","Success"),"Success"):(t.setValue("$status","Failure"),"Failure");case"Invert":s(t),t.setValue("$status","Running");var v=e(t.children,u,i);return"Failure"===v?(t.setValue("$status","Success"),"Success"):"Success"===v?(t.setValue("$status","Failure"),"Failure"):v;case"State":return s(t),e(t.children,u,i);case"Decorator":return s(t),t.decorator(e(t.children,u,i));case"Portal":case"Parallel":s(t),t.setValue("$status","Running");for(var p=[],$=0;$<t.children.length;$++)t.children[$].parent=t,p[$]=e(t.children[$],u,i);var y=p.filter((function(e){return"Success"===e})).length,S=p.filter((function(e){return"Failure"===e})).length;return y===t.children.length?(t.setValue("$status","Success"),"Success"):S===t.children.length?(t.setValue("$status","Failure"),"Failure"):(t.setValue("$status","Running"),"Running");case"Sequence":s(t),t.setValue("$status","Running");for(var g=t.getValue("$sequenceIndex",0);g<t.children.length;){var V=t.children[g];V.parent=t;var R=e(V,u,i);if("Success"!==R){if("Running"===R)return t.setValue("$status","Running"),"Running";if("Failure"===R)return t.setValue("$sequenceIndex",0),t.setValue("$status","Failure"),"Failure"}else t.setValue("$sequenceIndex",++g)}return t.setValue("$sequenceIndex",0),t.setValue("$status","Success"),"Success";case"Selector":s(t),t.setValue("$status","Running");for(var m,b=function(e){var t=0;if("undefined"==typeof Symbol||null==e[Symbol.iterator]){if(Array.isArray(e)||(e=function(e,t){if(e){if("string"==typeof e)return a(e,void 0);var n=Object.prototype.toString.call(e).slice(8,-1);return"Object"===n&&e.constructor&&(n=e.constructor.name),"Map"===n||"Set"===n?Array.from(n):"Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)?a(e,void 0):void 0}}(e)))return function(){return t>=e.length?{done:!0}:{done:!1,value:e[t++]}};throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}return(t=e[Symbol.iterator]()).next.bind(t)}(t.children);!(m=b()).done;){var w=m.value;w.parent=t;var E=e(w,u,i);if("Success"===E||"Running"===E)return t.setValue("$status",E),E}return t.setValue("$status","Failure"),"Failure";default:throw new Error("Invalid node type!")}}(this.children,this,u({},f,{props:e}));return function e(t,n){switch(t.type){case"Action":t.getValue("$wasRun")||t.setValue("$status","Ready");break;case"Portal":case"Invert":case"Parallel":case"Sequence":case"Selector":var r=Array.isArray(t.children)?t.children:[t.children],u=r.some((function(e){return"Running"===e.getValue("$status")})),a=!("Sequence"===t.type)||t.getValue("$sequenceIndex")+1===r.length||!1===t.getValue("$wasRun");!u&&a&&(t.setValue("$status","Ready"),"Sequence"===t.type&&t.setValue("$sequenceIndex",0),r.forEach((function(e){e.setValue("$status","Ready")})));for(var s=0;s<r.length;s++)e(r[s])}t.setValue("$wasRun",!1)}(this.children),this.dispatchEvent(new CustomEvent("tickend")),t}},addEventListener:function(e,t){-1===v(e).indexOf(t)&&h[e].push(t)},removeEventListener:function(e,t){var n=v(e).indexOf(t);-1!==n&&h[e].splice(n,1)},dispatchEvent:function(e){for(var t=v(e.type).slice(),n=0;n<t.length;n++)t[n].call(o,e);return!e.defaultPrevented}},i());return p.addEventListener=p.addEventListener.bind(p),p.removeEventListener=p.removeEventListener.bind(p),p.dispatchEvent=p.dispatchEvent.bind(p),p.tick=p.tick.bind(p),p}},selector:function(e){return u({id:t(),type:"Selector",children:e},i())},sequence:function(e){var n;return u({id:t(),type:"Sequence",children:e},i(((n={}).$sequenceIndex=0,n)))},parallel:function(e){return u({id:t(),type:"Parallel",children:e},i())},condition:function(e,n){return u({id:t(),name:e,type:"Condition",exec:function(e,t){return"function"!=typeof n||n(e.state,t)}},i())},portal:function(){return u({id:t(),type:"Portal",children:[]},i(),{clear:function(){return this.children.splice(0,this.children.length),this},mount:function(e){return this.children.find((function(t){return t.id===e.id}))||this.children.push(e),this},unmount:function(e){var t=this.children.findIndex((function(t){return t.id===e.id}));return this.children.splice(t,1),this}})},state:function(e,n){return u({id:t(),type:"State",children:n,state:e},i())},invert:function(e){return u({id:t(),type:"Invert",children:e},i())},action:function(e,n){return u({id:t(),name:e,type:"Action",fn:n},i())}}; | ||
//# sourceMappingURL=core.cjs.production.min.js.map |
@@ -1,2 +0,2 @@ | ||
import { nanoid } from 'nanoid'; | ||
import nanoid from 'nanoid'; | ||
import produce, { enablePatches, applyPatches } from 'immer'; | ||
@@ -3,0 +3,0 @@ |
{ | ||
"name": "@btree/core", | ||
"version": "0.2.2", | ||
"version": "0.2.3", | ||
"license": "MIT", | ||
@@ -29,6 +29,7 @@ "author": "Kasper Mikiewicz", | ||
"dependencies": { | ||
"@types/nanoid": "^2.1.0", | ||
"immer": "^6.0.3", | ||
"nanoid": "^2.0.0" | ||
}, | ||
"gitHead": "d2bb0fc3be9c04fae7308c7e8f28ec6effc233a0" | ||
"gitHead": "3536156cd497d3fe2e6c94ab342f9d75e1638897" | ||
} |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
139121
3
+ Added@types/nanoid@^2.1.0
+ Added@types/nanoid@2.1.0(transitive)
+ Added@types/node@22.10.10(transitive)
+ Addedundici-types@6.20.0(transitive)