diff --git a/CHANGELOG.md b/CHANGELOG.md index e51ed20..85ca945 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,16 +4,22 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). +## [2.2.2] - 2021-05-03 +## Changes +- Updated comments and docs to be more accurate and up to date ## [2.2.1] - 2021-03-04 ### Changed - socket.io dependency version bump ## [2.2.0] - 2021-02-19 ### Added +- Indexeddb additions to the userdata class + +### Changed +- update NPM modules to remove security vulnerabilities - This CHANGELOG - Fullscreen Plugin. The ability to add in a fullscreen button within container - Fullscreen Plugin Automated Testing - Fullscreen Plugin Documentation - Indexeddb additions to the userdata class -### Changed - update NPM modules to remove security vulnerabilities diff --git a/README.md b/README.md index 9825984..8c8237e 100644 --- a/README.md +++ b/README.md @@ -202,11 +202,11 @@ Some games will support many of these features, some none at all. We doubt one g Each plugin is responsible for one of the listed mechanics and should be provided a [HTML range input](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input/range), and an optional default value. -Each mechanic's value will range between 0 to 1, and the default initial value is aways 0.5. +Each mechanic's value will range between 0 to 1, and the default initial value is always 0.5. ```javascript import { - HitAreaScalePlugin, DragThresholdScalePlugin, HealtPlugin, ObjectCountPlugin, + HitAreaScalePlugin, DragThresholdScalePlugin, HealthPlugin, ObjectCountPlugin, CompletionPercentagePlugin, SpeedScalePlugin, TimersScalePlugin, InputCountPlugin, Container } from 'springroll-container'; @@ -420,7 +420,7 @@ For example the SoundPlugin can accept more than one volume slider or button if musicSliders: '#musicSlider, #musicSliderTwo', }); ``` -As long as the string you pass to the constructor is a valid selector string the plugin will use anything you pass to it. The plugins will keep settings in sync across the controls if neccessary as well. Sliders will update each other, buttons will set a dataSet attribute or class (see individual plugin sections for the exact attribute), and any other controls will match each other appropriately. +As long as the string you pass to the constructor is a valid selector string the plugin will use anything you pass to it. The plugins will keep settings in sync across the controls if necessary as well. Sliders will update each other, buttons will set a dataSet attribute or class (see individual plugin sections for the exact attribute), and any other controls will match each other appropriately. *Note: at this time there is no support for multiple HTMLElements as parameters. If you are passing an HTMLElement as the parameter rather than a selector string you cannot pass multiple controls. If you do wish to use multiple controls, pass the plugin a selector string instead. @@ -485,7 +485,73 @@ import { SavedData } from 'springroll-container'; // Firstly, construct the SavedData object. This is only needed for IndexedDB work savedData = new SavedData('dbName'); + +// Then, open a connection to the database. All changes to the structure of the database should be passed in here +``` +Additions is an optional parameter expecting a JSON object with any additions to the databases structure namely new [stores](https://developer.mozilla.org/en-US/docs/Web/API/IDBDatabase/createObjectStore) and [indexes](https://developer.mozilla.org/en-US/docs/Web/API/IDBObjectStore/createIndex). These are placed inside of an array + +Deletions is an optional parameter used to delete any [indexes](https://developer.mozilla.org/en-US/docs/Web/API/IDBObjectStore/deleteIndex) or [stores](https://developer.mozilla.org/en-US/docs/Web/API/IDBDatabase/deleteObjectStore) + +``` javascript + +let additions = { + stores: [{ + storeName: 'storeOne', + // optionally define a keyPath and/or set autoIncrement to true or false + options: { keyPath: "taskTitle" } + }, + { + storeName: 'storeTwo' + }], + indexes: [{ + indexName: 'newIndex', + keyPath: 'key', + // Any objectParameters for the Index + options: { + unique: false + } + }] +}; + +// Deletions is an optional parameter used to delete any indexes or stores +let deletions = { + stores: ['storeOne', 'storeTwo'], + indexes: ['newIndex'] +}; + +// Optionally pass in the new database version. Set to true to increment the database version. +// Leave this parameter out or pass in false to connect without making any changes to the structure of the database +let dbVersion = 1 + +// The name of the database to connect to +let dbName = 'dbName'; + +// Finally, pass these parameters in to establish a connection with the database +savedData.onOpenDb(dbName, dbVersion, additions, deletions); ``` + +There are other methods currently supported to interact with the database. These allow you to [Add a record](https://developer.mozilla.org/en-US/docs/Web/API/IDBObjectStore/add), [Deleting a record](https://developer.mozilla.org/en-US/docs/Web/API/IDBObjectStore/delete), [Reading](https://developer.mozilla.org/en-US/docs/Web/API/IDBObjectStore/get), [reading all records](https://developer.mozilla.org/en-US/docs/Web/API/IDBObjectStore/getAll) Each will return a success, or on failure, an error message + +``` javascript + +//Delete a record by the key in a specific store +savedData.IDBRemove('storeName', 'key'); + +// add a record to a store. The record can be any type of object accepted by indexedDB +savedData.IDBAdd('storeName', 'record'); + +// returns the record with the given key from the store with the given storeName +savedData.IDBRead('storeName', 'key'); + +// Finally, close the connection to the database +savedData.closeDb(); + +// Return all records from a database or optionally a specified amount defined by the second parameter +savedData.IDBReadAll('storeName'); +savedData.IDBReadAll('storeName', 5); + + + All other methods will work the same as the documentation [here](https://github.com/SpringRoll/SpringRoll/tree/main/src/state#userdata); diff --git a/dist/SpringRoll-Container-umd.js b/dist/SpringRoll-Container-umd.js index 5afffec..b9b0e22 100644 --- a/dist/SpringRoll-Container-umd.js +++ b/dist/SpringRoll-Container-umd.js @@ -1,2 +1,2 @@ -!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports):"function"==typeof define&&define.amd?define(["exports"],e):e((t=t||self).springroll=t.springroll||{})}(this,(function(t){"use strict";var e="URLSearchParams"in self,n="Symbol"in self&&"iterator"in Symbol,r="FileReader"in self&&"Blob"in self&&function(){try{return new Blob,!0}catch(t){return!1}}(),o="FormData"in self,i="ArrayBuffer"in self;if(i)var s=["[object Int8Array]","[object Uint8Array]","[object Uint8ClampedArray]","[object Int16Array]","[object Uint16Array]","[object Int32Array]","[object Uint32Array]","[object Float32Array]","[object Float64Array]"],a=ArrayBuffer.isView||function(t){return t&&s.indexOf(Object.prototype.toString.call(t))>-1};function u(t){if("string"!=typeof t&&(t=String(t)),/[^a-z0-9\-#$%&'*+.^_`|~]/i.test(t))throw new TypeError("Invalid character in header field name");return t.toLowerCase()}function l(t){return"string"!=typeof t&&(t=String(t)),t}function c(t){var e={next:function(){var e=t.shift();return{done:void 0===e,value:e}}};return n&&(e[Symbol.iterator]=function(){return e}),e}function d(t){this.map={},t instanceof d?t.forEach((function(t,e){this.append(e,t)}),this):Array.isArray(t)?t.forEach((function(t){this.append(t[0],t[1])}),this):t&&Object.getOwnPropertyNames(t).forEach((function(e){this.append(e,t[e])}),this)}function h(t){if(t.bodyUsed)return Promise.reject(new TypeError("Already read"));t.bodyUsed=!0}function f(t){return new Promise((function(e,n){t.onload=function(){e(t.result)},t.onerror=function(){n(t.error)}}))}function p(t){var e=new FileReader,n=f(e);return e.readAsArrayBuffer(t),n}function v(t){if(t.slice)return t.slice(0);var e=new Uint8Array(t.byteLength);return e.set(new Uint8Array(t)),e.buffer}function y(){return this.bodyUsed=!1,this._initBody=function(t){var n;this._bodyInit=t,t?"string"==typeof t?this._bodyText=t:r&&Blob.prototype.isPrototypeOf(t)?this._bodyBlob=t:o&&FormData.prototype.isPrototypeOf(t)?this._bodyFormData=t:e&&URLSearchParams.prototype.isPrototypeOf(t)?this._bodyText=t.toString():i&&r&&((n=t)&&DataView.prototype.isPrototypeOf(n))?(this._bodyArrayBuffer=v(t.buffer),this._bodyInit=new Blob([this._bodyArrayBuffer])):i&&(ArrayBuffer.prototype.isPrototypeOf(t)||a(t))?this._bodyArrayBuffer=v(t):this._bodyText=t=Object.prototype.toString.call(t):this._bodyText="",this.headers.get("content-type")||("string"==typeof t?this.headers.set("content-type","text/plain;charset=UTF-8"):this._bodyBlob&&this._bodyBlob.type?this.headers.set("content-type",this._bodyBlob.type):e&&URLSearchParams.prototype.isPrototypeOf(t)&&this.headers.set("content-type","application/x-www-form-urlencoded;charset=UTF-8"))},r&&(this.blob=function(){var t=h(this);if(t)return t;if(this._bodyBlob)return Promise.resolve(this._bodyBlob);if(this._bodyArrayBuffer)return Promise.resolve(new Blob([this._bodyArrayBuffer]));if(this._bodyFormData)throw new Error("could not read FormData body as blob");return Promise.resolve(new Blob([this._bodyText]))},this.arrayBuffer=function(){return this._bodyArrayBuffer?h(this)||Promise.resolve(this._bodyArrayBuffer):this.blob().then(p)}),this.text=function(){var t=h(this);if(t)return t;if(this._bodyBlob)return function(t){var e=new FileReader,n=f(e);return e.readAsText(t),n}(this._bodyBlob);if(this._bodyArrayBuffer)return Promise.resolve(function(t){for(var e=new Uint8Array(t),n=new Array(e.length),r=0;r-1?r:n),this.mode=e.mode||this.mode||null,this.signal=e.signal||this.signal,this.referrer=null,("GET"===this.method||"HEAD"===this.method)&&o)throw new TypeError("Body not allowed for GET or HEAD requests");this._initBody(o)}function b(t){var e=new FormData;return t.trim().split("&").forEach((function(t){if(t){var n=t.split("="),r=n.shift().replace(/\+/g," "),o=n.join("=").replace(/\+/g," ");e.append(decodeURIComponent(r),decodeURIComponent(o))}})),e}function S(t,e){e||(e={}),this.type="default",this.status=void 0===e.status?200:e.status,this.ok=this.status>=200&&this.status<300,this.statusText="statusText"in e?e.statusText:"OK",this.headers=new d(e.headers),this.url=e.url||"",this._initBody(t)}m.prototype.clone=function(){return new m(this,{body:this._bodyInit})},y.call(m.prototype),y.call(S.prototype),S.prototype.clone=function(){return new S(this._bodyInit,{status:this.status,statusText:this.statusText,headers:new d(this.headers),url:this.url})},S.error=function(){var t=new S(null,{status:0,statusText:""});return t.type="error",t};var w=[301,302,303,307,308];S.redirect=function(t,e){if(-1===w.indexOf(e))throw new RangeError("Invalid status code");return new S(null,{status:e,headers:{location:t}})};var k=self.DOMException;try{new k}catch(t){(k=function(t,e){this.message=t,this.name=e;var n=Error(t);this.stack=n.stack}).prototype=Object.create(Error.prototype),k.prototype.constructor=k}function E(t,e){return new Promise((function(n,o){var i=new m(t,e);if(i.signal&&i.signal.aborted)return o(new k("Aborted","AbortError"));var s=new XMLHttpRequest;function a(){s.abort()}s.onload=function(){var t,e,r={status:s.status,statusText:s.statusText,headers:(t=s.getAllResponseHeaders()||"",e=new d,t.replace(/\r?\n[\t ]+/g," ").split(/\r?\n/).forEach((function(t){var n=t.split(":"),r=n.shift().trim();if(r){var o=n.join(":").trim();e.append(r,o)}})),e)};r.url="responseURL"in s?s.responseURL:r.headers.get("X-Request-URL");var o="response"in s?s.response:s.responseText;n(new S(o,r))},s.onerror=function(){o(new TypeError("Network request failed"))},s.ontimeout=function(){o(new TypeError("Network request failed"))},s.onabort=function(){o(new k("Aborted","AbortError"))},s.open(i.method,i.url,!0),"include"===i.credentials?s.withCredentials=!0:"omit"===i.credentials&&(s.withCredentials=!1),"responseType"in s&&r&&(s.responseType="blob"),i.headers.forEach((function(t,e){s.setRequestHeader(e,t)})),i.signal&&(i.signal.addEventListener("abort",a),s.onreadystatechange=function(){4===s.readyState&&i.signal.removeEventListener("abort",a)}),s.send(void 0===i._bodyInit?null:i._bodyInit)}))}E.polyfill=!0,self.fetch||(self.fetch=E,self.Headers=d,self.Request=m,self.Response=S);var x="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{};function B(t,e){return t(e={exports:{}},e.exports),e.exports}var P=function(t){return t&&t.Math==Math&&t},L=P("object"==typeof globalThis&&globalThis)||P("object"==typeof window&&window)||P("object"==typeof self&&self)||P("object"==typeof x&&x)||Function("return this")(),_={CSSRuleList:0,CSSStyleDeclaration:0,CSSValueList:0,ClientRectList:0,DOMRectList:0,DOMStringList:0,DOMTokenList:1,DataTransferItemList:0,FileList:0,HTMLAllCollection:0,HTMLCollection:0,HTMLFormElement:0,HTMLSelectElement:0,MediaList:0,MimeTypeArray:0,NamedNodeMap:0,NodeList:1,PaintRequestList:0,Plugin:0,PluginArray:0,SVGLengthList:0,SVGNumberList:0,SVGPathSegList:0,SVGPointList:0,SVGStringList:0,SVGTransformList:0,SourceBufferList:0,StyleSheetList:0,TextTrackCueList:0,TextTrackList:0,TouchList:0},A=function(t){if("function"!=typeof t)throw TypeError(String(t)+" is not a function");return t},C=function(t,e,n){if(A(t),void 0===e)return t;switch(n){case 0:return function(){return t.call(e)};case 1:return function(n){return t.call(e,n)};case 2:return function(n,r){return t.call(e,n,r)};case 3:return function(n,r,o){return t.call(e,n,r,o)}}return function(){return t.apply(e,arguments)}},D=function(t){try{return!!t()}catch(t){return!0}},O={}.toString,V=function(t){return O.call(t).slice(8,-1)},I="".split,R=D((function(){return!Object("z").propertyIsEnumerable(0)}))?function(t){return"String"==V(t)?I.call(t,""):Object(t)}:Object,T=function(t){if(null==t)throw TypeError("Can't call method on "+t);return t},j=function(t){return Object(T(t))},M=Math.ceil,N=Math.floor,F=function(t){return isNaN(t=+t)?0:(t>0?N:M)(t)},K=Math.min,G=function(t){return t>0?K(F(t),9007199254740991):0},U=function(t){return"object"==typeof t?null!==t:"function"==typeof t},H=Array.isArray||function(t){return"Array"==V(t)},z=!D((function(){return 7!=Object.defineProperty({},1,{get:function(){return 7}})[1]})),q=L.document,W=U(q)&&U(q.createElement),X=function(t){return W?q.createElement(t):{}},Y=!z&&!D((function(){return 7!=Object.defineProperty(X("div"),"a",{get:function(){return 7}}).a})),$=function(t){if(!U(t))throw TypeError(String(t)+" is not an object");return t},J=function(t,e){if(!U(t))return t;var n,r;if(e&&"function"==typeof(n=t.toString)&&!U(r=n.call(t)))return r;if("function"==typeof(n=t.valueOf)&&!U(r=n.call(t)))return r;if(!e&&"function"==typeof(n=t.toString)&&!U(r=n.call(t)))return r;throw TypeError("Can't convert object to primitive value")},Q=Object.defineProperty,Z={f:z?Q:function(t,e,n){if($(t),e=J(e,!0),$(n),Y)try{return Q(t,e,n)}catch(t){}if("get"in n||"set"in n)throw TypeError("Accessors not supported");return"value"in n&&(t[e]=n.value),t}},tt=function(t,e){return{enumerable:!(1&t),configurable:!(2&t),writable:!(4&t),value:e}},et=z?function(t,e,n){return Z.f(t,e,tt(1,n))}:function(t,e,n){return t[e]=n,t},nt=function(t,e){try{et(L,t,e)}catch(n){L[t]=e}return e},rt="__core-js_shared__",ot=L[rt]||nt(rt,{}),it=B((function(t){(t.exports=function(t,e){return ot[t]||(ot[t]=void 0!==e?e:{})})("versions",[]).push({version:"3.6.5",mode:"global",copyright:"© 2020 Denis Pushkarev (zloirock.ru)"})})),st={}.hasOwnProperty,at=function(t,e){return st.call(t,e)},ut=0,lt=Math.random(),ct=function(t){return"Symbol("+String(void 0===t?"":t)+")_"+(++ut+lt).toString(36)},dt=!!Object.getOwnPropertySymbols&&!D((function(){return!String(Symbol())})),ht=dt&&!Symbol.sham&&"symbol"==typeof Symbol.iterator,ft=it("wks"),pt=L.Symbol,vt=ht?pt:pt&&pt.withoutSetter||ct,yt=function(t){return at(ft,t)||(dt&&at(pt,t)?ft[t]=pt[t]:ft[t]=vt("Symbol."+t)),ft[t]},gt=yt("species"),mt=function(t,e){var n;return H(t)&&("function"!=typeof(n=t.constructor)||n!==Array&&!H(n.prototype)?U(n)&&null===(n=n[gt])&&(n=void 0):n=void 0),new(void 0===n?Array:n)(0===e?0:e)},bt=[].push,St=function(t){var e=1==t,n=2==t,r=3==t,o=4==t,i=6==t,s=5==t||i;return function(a,u,l,c){for(var d,h,f=j(a),p=R(f),v=C(u,l,3),y=G(p.length),g=0,m=c||mt,b=e?m(a,y):n?m(a,0):void 0;y>g;g++)if((s||g in p)&&(h=v(d=p[g],g,f),t))if(e)b[g]=h;else if(h)switch(t){case 3:return!0;case 5:return d;case 6:return g;case 2:bt.call(b,d)}else if(o)return!1;return i?-1:r||o?o:b}},wt={forEach:St(0),map:St(1),filter:St(2),some:St(3),every:St(4),find:St(5),findIndex:St(6)},kt=function(t,e){var n=[][t];return!!n&&D((function(){n.call(null,e||function(){throw 1},1)}))},Et=Object.defineProperty,xt={},Bt=function(t){throw t},Pt=function(t,e){if(at(xt,t))return xt[t];e||(e={});var n=[][t],r=!!at(e,"ACCESSORS")&&e.ACCESSORS,o=at(e,0)?e[0]:Bt,i=at(e,1)?e[1]:void 0;return xt[t]=!!n&&!D((function(){if(r&&!z)return!0;var t={length:-1};r?Et(t,1,{enumerable:!0,get:Bt}):t[1]=1,n.call(t,o,i)}))},Lt=wt.forEach,_t=kt("forEach"),At=Pt("forEach"),Ct=_t&&At?[].forEach:function(t){return Lt(this,t,arguments.length>1?arguments[1]:void 0)};for(var Dt in _){var Ot=L[Dt],Vt=Ot&&Ot.prototype;if(Vt&&Vt.forEach!==Ct)try{et(Vt,"forEach",Ct)}catch(t){Vt.forEach=Ct}}var It,Rt=function(t){return R(T(t))},Tt=Math.max,jt=Math.min,Mt=function(t){return function(e,n,r){var o,i=Rt(e),s=G(i.length),a=function(t,e){var n=F(t);return n<0?Tt(n+e,0):jt(n,e)}(r,s);if(t&&n!=n){for(;s>a;)if((o=i[a++])!=o)return!0}else for(;s>a;a++)if((t||a in i)&&i[a]===n)return t||a||0;return!t&&-1}},Nt={includes:Mt(!0),indexOf:Mt(!1)},Ft={},Kt=Nt.indexOf,Gt=function(t,e){var n,r=Rt(t),o=0,i=[];for(n in r)!at(Ft,n)&&at(r,n)&&i.push(n);for(;e.length>o;)at(r,n=e[o++])&&(~Kt(i,n)||i.push(n));return i},Ut=["constructor","hasOwnProperty","isPrototypeOf","propertyIsEnumerable","toLocaleString","toString","valueOf"],Ht=Object.keys||function(t){return Gt(t,Ut)},zt=z?Object.defineProperties:function(t,e){$(t);for(var n,r=Ht(e),o=r.length,i=0;o>i;)Z.f(t,n=r[i++],e[n]);return t},qt=L,Wt=function(t){return"function"==typeof t?t:void 0},Xt=function(t,e){return arguments.length<2?Wt(qt[t])||Wt(L[t]):qt[t]&&qt[t][e]||L[t]&&L[t][e]},Yt=Xt("document","documentElement"),$t=it("keys"),Jt=function(t){return $t[t]||($t[t]=ct(t))},Qt=Jt("IE_PROTO"),Zt=function(){},te=function(t){return"