cyano-mithril
Advanced tools
Comparing version 0.6.9 to 0.7.0
@@ -1,3 +0,2 @@ | ||
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("mithril")):"function"==typeof define&&define.amd?define(["exports","mithril"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self).cyanoMithril=e.cyanoMithril||{},e.m)}(this,(function(e,t){"use strict";function n(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}var r=n(t);function o(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);t&&(r=r.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),n.push.apply(n,r)}return n}function a(e){for(var t=1;t<arguments.length;t++){var n=null!=arguments[t]?arguments[t]:{};t%2?o(Object(n),!0).forEach((function(t){i(e,t,n[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(n)):o(Object(n)).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(n,t))}))}return e}function s(e){return(s="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e})(e)}function i(e,t,n){return t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function c(){return(c=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 u(e,t){return function(e){if(Array.isArray(e))return e}(e)||function(e,t){var n=e&&("undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"]);if(null==n)return;var r,o,a=[],s=!0,i=!1;try{for(n=n.call(e);!(s=(r=n.next()).done)&&(a.push(r.value),!t||a.length!==t);s=!0);}catch(e){i=!0,o=e}finally{try{s||null==n.return||n.return()}finally{if(i)throw o}}return a}(e,t)||function(e,t){if(!e)return;if("string"==typeof e)return l(e,t);var n=Object.prototype.toString.call(e).slice(8,-1);"Object"===n&&e.constructor&&(n=e.constructor.name);if("Map"===n||"Set"===n)return Array.from(e);if("Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n))return l(e,t)}(e,t)||function(){throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")} | ||
/*! (c) 2020 Andrea Giammarchi */()}function l(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}var d,f=JSON.stringify,p=String,m="object",y=function(e,t){return t},h=function(e,t,n){var r=p(t.push(n)-1);return e.set(n,r),r},g=function(e,t,n){for(var r=t&&s(t)===m?function(e,n){return""===e||-1<t.indexOf(e)?n:void 0}:t||y,o=new Map,a=[],i=[],c=+h(o,a,r.call({"":e},"",e)),u=!c;c<a.length;)u=!0,i[c]=f(a[c++],l,n);return"["+i.join(",")+"]";function l(e,t){if(u)return u=!u,t;var n=r.call(this,e,t);switch(s(n)){case m:if(null===n)return n;case"string":return o.get(n)||h(o,a,n)}return n}},b=Function.prototype.call.bind(Function.prototype.call),v=function(){return r.default.redraw()},w=function(e){var t=d,n=t.depsIndex;t.depsIndex+=1;var r=t.depsStates[n]||[],o=void 0===e||!!Array.isArray(e)&&(e.length>0?!e.every((function(e,t){return e===r[t]})):!t.setup);return void 0!==e&&(t.depsStates[n]=e),o},O=function(){var e=arguments.length>0&&void 0!==arguments[0]&&arguments[0];return function(t,n){var r=d;if(w(n)){var o=r.depsIndex,a=function(){var e=t();"function"==typeof e&&(r.teardowns.set(o,e),r.teardowns.set("_",v))},s=r.teardowns.get(o);try{"function"==typeof s&&s()}finally{r.teardowns.delete(o)}r.updates.push(e?function(){return new Promise((function(e){return requestAnimationFrame(e)})).then(a)}:a)}}},x=function(e,t){var n=d,r=n.statesIndex;return n.statesIndex+=1,n.setup||(n.states[r]=e),[n.states[r],function(e){var o=n.states[r],a=t?t(e,r):e;n.states[r]=a,g(a)!==g(o)&&v()},r]},j=O(!0),k=O();var S=function(e,t){var n=d,r=w(t),o=u(n.setup?x():x(e()),2),a=o[0],s=o[1];return n.setup&&r&&s(e()),a},I={accept:"accept",acceptcharset:"acceptcharset",accesskey:"accesskey",action:"action",allowfullscreen:"allowfullscreen",allowtransparency:"allowtransparency",alt:"alt",async:"async",autocomplete:"autocomplete",autofocus:"autofocus",autoplay:"autoplay",capture:"capture",cellpadding:"cellpadding",cellspacing:"cellspacing",challenge:"challenge",charset:"charset",checked:"checked",class:"className",classid:"classid",classname:"className",className:"className",colspan:"colspan",cols:"cols",content:"content",contenteditable:"contenteditable",contextmenu:"contextmenu",controls:"controls",coords:"coords",crossorigin:"crossorigin",data:"data",datetime:"datetime",default:"default",defer:"defer",dir:"dir",disabled:"disabled",download:"download",draggable:"draggable",enctype:"enctype",for:"for",form:"form",formaction:"formaction",formenctype:"formenctype",formmethod:"formmethod",formnovalidate:"formnovalidate",formtarget:"formtarget",frameborder:"frameborder",headers:"headers",height:"height",hidden:"hidden",high:"high",href:"href",hreflang:"hreflang",htmlfor:"htmlfor",httpequiv:"httpequiv",icon:"icon",id:"id",inputmode:"inputmode",integrity:"integrity",is:"is",keyparams:"keyparams",keytype:"keytype",kind:"kind",label:"label",lang:"lang",list:"list",loop:"loop",low:"low",manifest:"manifest",marginheight:"marginheight",marginwidth:"marginwidth",max:"max",maxlength:"maxlength",media:"media",mediagroup:"mediagroup",method:"method",min:"min",minlength:"minlength",multiple:"multiple",muted:"muted",name:"name",novalidate:"novalidate",nonce:"nonce",onblur:"onblur",onchange:"onchange",onclick:"onclick",onfocus:"onfocus",oninput:"oninput",onkeydown:"onkeydown",onkeyup:"onkeyup",onmousedown:"onmousedown",onmouseout:"onmouseout",onmouseover:"onmouseover",onmouseup:"onmouseup",onscroll:"onscroll",onsubmit:"onsubmit",ontouchend:"ontouchend",ontouchmove:"ontouchmove",ontouchstart:"ontouchstart",open:"open",optimum:"optimum",pattern:"pattern",placeholder:"placeholder",poster:"poster",preload:"preload",radiogroup:"radiogroup",readonly:"readonly",rel:"rel",required:"required",reversed:"reversed",role:"role",rowspan:"rowspan",rows:"rows",sandbox:"sandbox",scope:"scope",scoped:"scoped",scrolling:"scrolling",seamless:"seamless",selected:"selected",shape:"shape",size:"size",sizes:"sizes",span:"span",spellcheck:"spellcheck",src:"src",srcdoc:"srcdoc",srclang:"srclang",srcset:"srcset",start:"start",step:"step",style:"style",summary:"summary",tabindex:"tabindex",target:"target",title:"title",type:"type",usemap:"usemap",value:"value",width:"width",wmode:"wmode",wrap:"wrap"},P=r.default||{},A=P.trust;P.trust=function(e,t){return t?r.default(t,A(e)):A(e)},P.displayName="mithril",P.fragment=r.default.fragment;var M=r.default,E=function(e,t){var n=function(e){var t=d;d=e.state;try{e.state.updates.forEach(b)}finally{c(e.state,{setup:!0,updates:[],depsIndex:0,statesIndex:0}),d=t}};return{oninit:function(e){c(e.state,{setup:!1,states:[],statesIndex:0,depsStates:[],depsIndex:0,updates:[],cleanups:new Map,teardowns:new Map})},oncreate:n,onupdate:n,view:function(n){var r=d;d=n.state;try{return e(a(a(a({},t),n.attrs),{},{vnode:n,children:n.children}))}catch(e){console.error(e)}finally{d=r}},onremove:function(e){var t=d;d=e.state;try{e.state.teardowns.forEach(b)}finally{d=t}}}};e.a=I,e.cast=E,e.getRef=function(e){return{oncreate:function(t){return e(t.dom)}}},e.h=P,e.jsx=M,e.useCallback=function(e,t){return S((function(){return e}),t)},e.useEffect=j,e.useLayoutEffect=k,e.useMemo=S,e.useReducer=function(e,t,n){var r,o,a,s,i=d,c=!i.setup&&n?n(t):t;return r=u(x(c),3),o=r[0],a=r[1],s=r[2],[o,function(t){var n=i.states[s];return a(e(n,t))}]},e.useRef=function(e){return u(x({current:e}),1)[0]},e.useState=function(e){var t=d;return x(e,(function(e,n){return"function"==typeof e?e(t.states[n],n):e}))},Object.defineProperty(e,"__esModule",{value:!0})})); | ||
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("mithril"),require("mithril-hooks")):"function"==typeof define&&define.amd?define(["exports","mithril","mithril-hooks"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self).cyanoMithril={},e.m,e.mithrilHooks)}(this,(function(e,t,o){"use strict";function n(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}var a=n(t);const r={accept:"accept",acceptcharset:"acceptcharset",accesskey:"accesskey",action:"action",allowfullscreen:"allowfullscreen",allowtransparency:"allowtransparency",alt:"alt",async:"async",autocomplete:"autocomplete",autofocus:"autofocus",autoplay:"autoplay",capture:"capture",cellpadding:"cellpadding",cellspacing:"cellspacing",challenge:"challenge",charset:"charset",checked:"checked",class:"className",classid:"classid",classname:"className",className:"className",colspan:"colspan",cols:"cols",content:"content",contenteditable:"contenteditable",contextmenu:"contextmenu",controls:"controls",coords:"coords",crossorigin:"crossorigin",data:"data",datetime:"datetime",default:"default",defer:"defer",dir:"dir",disabled:"disabled",download:"download",draggable:"draggable",enctype:"enctype",for:"for",form:"form",formaction:"formaction",formenctype:"formenctype",formmethod:"formmethod",formnovalidate:"formnovalidate",formtarget:"formtarget",frameborder:"frameborder",headers:"headers",height:"height",hidden:"hidden",high:"high",href:"href",hreflang:"hreflang",htmlfor:"htmlfor",httpequiv:"httpequiv",icon:"icon",id:"id",inputmode:"inputmode",integrity:"integrity",is:"is",keyparams:"keyparams",keytype:"keytype",kind:"kind",label:"label",lang:"lang",list:"list",loop:"loop",low:"low",manifest:"manifest",marginheight:"marginheight",marginwidth:"marginwidth",max:"max",maxlength:"maxlength",media:"media",mediagroup:"mediagroup",method:"method",min:"min",minlength:"minlength",multiple:"multiple",muted:"muted",name:"name",novalidate:"novalidate",nonce:"nonce",onblur:"onblur",onchange:"onchange",onclick:"onclick",onfocus:"onfocus",oninput:"oninput",onkeydown:"onkeydown",onkeyup:"onkeyup",onmousedown:"onmousedown",onmouseout:"onmouseout",onmouseover:"onmouseover",onmouseup:"onmouseup",onscroll:"onscroll",onsubmit:"onsubmit",ontouchend:"ontouchend",ontouchmove:"ontouchmove",ontouchstart:"ontouchstart",open:"open",optimum:"optimum",pattern:"pattern",placeholder:"placeholder",poster:"poster",preload:"preload",radiogroup:"radiogroup",readonly:"readonly",rel:"rel",required:"required",reversed:"reversed",role:"role",rowspan:"rowspan",rows:"rows",sandbox:"sandbox",scope:"scope",scoped:"scoped",scrolling:"scrolling",seamless:"seamless",selected:"selected",shape:"shape",size:"size",sizes:"sizes",span:"span",spellcheck:"spellcheck",src:"src",srcdoc:"srcdoc",srclang:"srclang",srcset:"srcset",start:"start",step:"step",style:"style",summary:"summary",tabindex:"tabindex",target:"target",title:"title",type:"type",usemap:"usemap",value:"value",width:"width",wmode:"wmode",wrap:"wrap"},s=a.default,{trust:l}=a.default;s.trust=(e,t)=>t?s(t,l(e)):l(e);const c=a.default,i=o.withHooks;Object.defineProperty(e,"useCallback",{enumerable:!0,get:function(){return o.useCallback}}),Object.defineProperty(e,"useEffect",{enumerable:!0,get:function(){return o.useEffect}}),Object.defineProperty(e,"useLayoutEffect",{enumerable:!0,get:function(){return o.useLayoutEffect}}),Object.defineProperty(e,"useMemo",{enumerable:!0,get:function(){return o.useMemo}}),Object.defineProperty(e,"useReducer",{enumerable:!0,get:function(){return o.useReducer}}),Object.defineProperty(e,"useRef",{enumerable:!0,get:function(){return o.useRef}}),Object.defineProperty(e,"useState",{enumerable:!0,get:function(){return o.useState}}),e.a=r,e.cast=i,e.getRef=e=>({oncreate:t=>{e(t.dom)}}),e.h=s,e.jsx=c,Object.defineProperty(e,"__esModule",{value:!0})})); | ||
//# sourceMappingURL=cyano-mithril.js.map |
import m from 'mithril'; | ||
import { withHooks } from 'mithril-hooks'; | ||
export { | ||
useCallback, | ||
useEffect, | ||
useLayoutEffect, | ||
useMemo, | ||
useReducer, | ||
useRef, | ||
useState, | ||
} from 'mithril-hooks'; | ||
function ownKeys(object, enumerableOnly) { | ||
var keys = Object.keys(object); | ||
if (Object.getOwnPropertySymbols) { | ||
var symbols = Object.getOwnPropertySymbols(object); | ||
if (enumerableOnly) { | ||
symbols = symbols.filter(function (sym) { | ||
return Object.getOwnPropertyDescriptor(object, sym).enumerable; | ||
}); | ||
} | ||
keys.push.apply(keys, symbols); | ||
} | ||
return keys; | ||
} | ||
function _objectSpread2(target) { | ||
for (var i = 1; i < arguments.length; i++) { | ||
var source = arguments[i] != null ? arguments[i] : {}; | ||
if (i % 2) { | ||
ownKeys(Object(source), true).forEach(function (key) { | ||
_defineProperty(target, key, source[key]); | ||
}); | ||
} else if (Object.getOwnPropertyDescriptors) { | ||
Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); | ||
} else { | ||
ownKeys(Object(source)).forEach(function (key) { | ||
Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); | ||
}); | ||
} | ||
} | ||
return target; | ||
} | ||
function _typeof(obj) { | ||
"@babel/helpers - typeof"; | ||
if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { | ||
_typeof = function (obj) { | ||
return typeof obj; | ||
}; | ||
} else { | ||
_typeof = function (obj) { | ||
return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; | ||
}; | ||
} | ||
return _typeof(obj); | ||
} | ||
function _defineProperty(obj, key, value) { | ||
if (key in obj) { | ||
Object.defineProperty(obj, key, { | ||
value: value, | ||
enumerable: true, | ||
configurable: true, | ||
writable: true | ||
}); | ||
} else { | ||
obj[key] = value; | ||
} | ||
return obj; | ||
} | ||
function _extends() { | ||
_extends = Object.assign || function (target) { | ||
for (var i = 1; i < arguments.length; i++) { | ||
var source = arguments[i]; | ||
for (var key in source) { | ||
if (Object.prototype.hasOwnProperty.call(source, key)) { | ||
target[key] = source[key]; | ||
} | ||
} | ||
} | ||
return target; | ||
}; | ||
return _extends.apply(this, arguments); | ||
} | ||
function _slicedToArray(arr, i) { | ||
return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); | ||
} | ||
function _arrayWithHoles(arr) { | ||
if (Array.isArray(arr)) return arr; | ||
} | ||
function _iterableToArrayLimit(arr, i) { | ||
var _i = arr && (typeof Symbol !== "undefined" && arr[Symbol.iterator] || arr["@@iterator"]); | ||
if (_i == null) return; | ||
var _arr = []; | ||
var _n = true; | ||
var _d = false; | ||
var _s, _e; | ||
try { | ||
for (_i = _i.call(arr); !(_n = (_s = _i.next()).done); _n = true) { | ||
_arr.push(_s.value); | ||
if (i && _arr.length === i) break; | ||
} | ||
} catch (err) { | ||
_d = true; | ||
_e = err; | ||
} finally { | ||
try { | ||
if (!_n && _i["return"] != null) _i["return"](); | ||
} finally { | ||
if (_d) throw _e; | ||
} | ||
} | ||
return _arr; | ||
} | ||
function _unsupportedIterableToArray(o, minLen) { | ||
if (!o) return; | ||
if (typeof o === "string") return _arrayLikeToArray(o, minLen); | ||
var n = Object.prototype.toString.call(o).slice(8, -1); | ||
if (n === "Object" && o.constructor) n = o.constructor.name; | ||
if (n === "Map" || n === "Set") return Array.from(o); | ||
if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); | ||
} | ||
function _arrayLikeToArray(arr, len) { | ||
if (len == null || len > arr.length) len = arr.length; | ||
for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; | ||
return arr2; | ||
} | ||
function _nonIterableRest() { | ||
throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); | ||
} | ||
/*! (c) 2020 Andrea Giammarchi */ | ||
var $stringify = JSON.stringify; | ||
var Primitive = String; // it could be Number | ||
var primitive = 'string'; // it could be 'number' | ||
var object = 'object'; | ||
var noop = function noop(_, value) { | ||
return value; | ||
}; | ||
var set = function set(known, input, value) { | ||
var index = Primitive(input.push(value) - 1); | ||
known.set(value, index); | ||
return index; | ||
}; | ||
var stringify = function stringify(value, replacer, space) { | ||
var $ = replacer && _typeof(replacer) === object ? function (k, v) { | ||
return k === '' || -1 < replacer.indexOf(k) ? v : void 0; | ||
} : replacer || noop; | ||
var known = new Map(); | ||
var input = []; | ||
var output = []; | ||
var i = +set(known, input, $.call({ | ||
'': value | ||
}, '', value)); | ||
var firstRun = !i; | ||
while (i < input.length) { | ||
firstRun = true; | ||
output[i] = $stringify(input[i++], replace, space); | ||
} | ||
return '[' + output.join(',') + ']'; | ||
function replace(key, value) { | ||
if (firstRun) { | ||
firstRun = !firstRun; | ||
return value; | ||
} | ||
var after = $.call(this, key, value); | ||
switch (_typeof(after)) { | ||
case object: | ||
if (after === null) return after; | ||
case primitive: | ||
return known.get(after) || set(known, input, after); | ||
} | ||
return after; | ||
} | ||
}; | ||
var currentState; | ||
var call = Function.prototype.call.bind(Function.prototype.call); | ||
var scheduleRender = function scheduleRender() { | ||
return (// Call m within the function body so environments with a global instance of m (like flems.io) don't complain | ||
m.redraw() | ||
); | ||
}; | ||
var updateDeps = function updateDeps(deps) { | ||
var state = currentState; | ||
var depsIndex = state.depsIndex; | ||
state.depsIndex += 1; | ||
var prevDeps = state.depsStates[depsIndex] || []; | ||
var shouldRecompute = deps === undefined ? true // Always compute | ||
: Array.isArray(deps) ? deps.length > 0 ? !deps.every(function (x, i) { | ||
return x === prevDeps[i]; | ||
}) // Only compute when one of the deps has changed | ||
: !state.setup // Empty array: only compute at mount | ||
: false; // Invalid value, do nothing | ||
if (deps !== undefined) { | ||
state.depsStates[depsIndex] = deps; | ||
} | ||
return shouldRecompute; | ||
}; | ||
var effect = function effect() { | ||
var isAsync = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : false; | ||
return function (fn, deps) { | ||
var state = currentState; | ||
var shouldRecompute = updateDeps(deps); | ||
if (shouldRecompute) { | ||
var depsIndex = state.depsIndex; | ||
var runCallbackFn = function runCallbackFn() { | ||
var teardown = fn(); // A callback may return a function. If any, add it to the teardowns: | ||
if (typeof teardown === 'function') { | ||
// Store this this function to be called at cleanup and unmount | ||
state.teardowns.set(depsIndex, teardown); // At unmount, call re-render at least once | ||
state.teardowns.set('_', scheduleRender); | ||
} | ||
}; // First clean up any previous cleanup function | ||
var teardown = state.teardowns.get(depsIndex); | ||
try { | ||
if (typeof teardown === 'function') { | ||
teardown(); | ||
} | ||
} finally { | ||
state.teardowns["delete"](depsIndex); | ||
} | ||
state.updates.push(isAsync ? function () { | ||
return new Promise(function (resolve) { | ||
return requestAnimationFrame(resolve); | ||
}).then(runCallbackFn); | ||
} : runCallbackFn); | ||
} | ||
}; | ||
}; | ||
var updateState = function updateState(initialState, newValueFn) { | ||
var state = currentState; | ||
var index = state.statesIndex; | ||
state.statesIndex += 1; | ||
if (!state.setup) { | ||
state.states[index] = initialState; | ||
} | ||
return [state.states[index], function (value) { | ||
var previousValue = state.states[index]; | ||
var newValue = newValueFn ? newValueFn(value, index) : value; | ||
state.states[index] = newValue; | ||
if (stringify(newValue) !== stringify(previousValue)) { | ||
scheduleRender(); // Calling redraw multiple times: Mithril will drop extraneous redraw calls, so performance should not be an issue | ||
} | ||
}, index]; | ||
}; | ||
var useState = function useState(initialState) { | ||
var state = currentState; | ||
var newValueFn = function newValueFn(value, index) { | ||
return typeof value === 'function' ? value(state.states[index], index) : value; | ||
}; | ||
return updateState(initialState, newValueFn); | ||
}; | ||
var useEffect = effect(true); | ||
var useLayoutEffect = effect(); | ||
function useReducer(reducer, initialState, initFn) { | ||
var state = currentState; // From the React docs: You can also create the initial state lazily. To do this, you can pass an init function as the third argument. The initial state will be set to init(initialValue). | ||
var initValue = !state.setup && initFn ? initFn(initialState) : initialState; | ||
var getValueDispatch = function getValueDispatch() { | ||
var _updateState = updateState(initValue), | ||
_updateState2 = _slicedToArray(_updateState, 3), | ||
value = _updateState2[0], | ||
setValue = _updateState2[1], | ||
index = _updateState2[2]; | ||
var dispatch = function dispatch(action) { | ||
var previousValue = state.states[index]; | ||
return setValue( // Next state: | ||
reducer(previousValue, action)); | ||
}; | ||
return [value, dispatch]; | ||
}; | ||
return getValueDispatch(); | ||
} | ||
var useRef = function useRef(initialValue) { | ||
// A ref is a persisted object that will not be updated, so it has no setter | ||
var _updateState3 = updateState({ | ||
current: initialValue | ||
}), | ||
_updateState4 = _slicedToArray(_updateState3, 1), | ||
value = _updateState4[0]; | ||
return value; | ||
}; | ||
var useMemo = function useMemo(fn, deps) { | ||
var state = currentState; | ||
var shouldRecompute = updateDeps(deps); | ||
var _ref = !state.setup ? updateState(fn()) : updateState(), | ||
_ref2 = _slicedToArray(_ref, 2), | ||
memoized = _ref2[0], | ||
setMemoized = _ref2[1]; | ||
if (state.setup && shouldRecompute) { | ||
setMemoized(fn()); | ||
} | ||
return memoized; | ||
}; | ||
var useCallback = function useCallback(callback, deps) { | ||
return useMemo(function () { | ||
return callback; | ||
}, deps); | ||
}; | ||
var withHooks = function withHooks(renderFunction, initialAttrs) { | ||
var init = function init(vnode) { | ||
_extends(vnode.state, { | ||
setup: false, | ||
states: [], | ||
statesIndex: 0, | ||
depsStates: [], | ||
depsIndex: 0, | ||
updates: [], | ||
cleanups: new Map(), | ||
teardowns: new Map() // Keep track of teardowns even when the update was run only once | ||
}); | ||
}; | ||
var update = function update(vnode) { | ||
var prevState = currentState; | ||
currentState = vnode.state; | ||
try { | ||
vnode.state.updates.forEach(call); | ||
} finally { | ||
_extends(vnode.state, { | ||
setup: true, | ||
updates: [], | ||
depsIndex: 0, | ||
statesIndex: 0 | ||
}); | ||
currentState = prevState; | ||
} | ||
}; // eslint-disable-next-line consistent-return | ||
var render = function render(vnode) { | ||
var prevState = currentState; | ||
currentState = vnode.state; | ||
try { | ||
return renderFunction(_objectSpread2(_objectSpread2(_objectSpread2({}, initialAttrs), vnode.attrs), {}, { | ||
vnode: vnode, | ||
children: vnode.children | ||
})); | ||
} catch (e) { | ||
console.error(e); // eslint-disable-line no-console | ||
} finally { | ||
currentState = prevState; | ||
} | ||
}; | ||
var teardown = function teardown(vnode) { | ||
var prevState = currentState; | ||
currentState = vnode.state; | ||
try { | ||
vnode.state.teardowns.forEach(call); | ||
} finally { | ||
currentState = prevState; | ||
} | ||
}; | ||
return { | ||
oninit: init, | ||
oncreate: update, | ||
onupdate: update, | ||
view: render, | ||
onremove: teardown | ||
}; | ||
}; | ||
var htmlAttributes = { | ||
accept: "accept", | ||
acceptcharset: "acceptcharset", | ||
accesskey: "accesskey", | ||
action: "action", | ||
allowfullscreen: "allowfullscreen", | ||
allowtransparency: "allowtransparency", | ||
alt: "alt", | ||
async: "async", | ||
autocomplete: "autocomplete", | ||
autofocus: "autofocus", | ||
autoplay: "autoplay", | ||
capture: "capture", | ||
cellpadding: "cellpadding", | ||
cellspacing: "cellspacing", | ||
challenge: "challenge", | ||
charset: "charset", | ||
checked: "checked", | ||
"class": "className", | ||
classid: "classid", | ||
classname: "className", | ||
accept: 'accept', | ||
acceptcharset: 'acceptcharset', | ||
accesskey: 'accesskey', | ||
action: 'action', | ||
allowfullscreen: 'allowfullscreen', | ||
allowtransparency: 'allowtransparency', | ||
alt: 'alt', | ||
async: 'async', | ||
autocomplete: 'autocomplete', | ||
autofocus: 'autofocus', | ||
autoplay: 'autoplay', | ||
capture: 'capture', | ||
cellpadding: 'cellpadding', | ||
cellspacing: 'cellspacing', | ||
challenge: 'challenge', | ||
charset: 'charset', | ||
checked: 'checked', | ||
class: 'className', | ||
classid: 'classid', | ||
classname: 'className', | ||
// Special case: | ||
className: "className", | ||
colspan: "colspan", | ||
cols: "cols", | ||
content: "content", | ||
contenteditable: "contenteditable", | ||
contextmenu: "contextmenu", | ||
controls: "controls", | ||
coords: "coords", | ||
crossorigin: "crossorigin", | ||
data: "data", | ||
datetime: "datetime", | ||
"default": "default", | ||
defer: "defer", | ||
dir: "dir", | ||
disabled: "disabled", | ||
download: "download", | ||
draggable: "draggable", | ||
enctype: "enctype", | ||
"for": "for", | ||
form: "form", | ||
formaction: "formaction", | ||
formenctype: "formenctype", | ||
formmethod: "formmethod", | ||
formnovalidate: "formnovalidate", | ||
formtarget: "formtarget", | ||
frameborder: "frameborder", | ||
headers: "headers", | ||
height: "height", | ||
hidden: "hidden", | ||
high: "high", | ||
href: "href", | ||
hreflang: "hreflang", | ||
htmlfor: "htmlfor", | ||
httpequiv: "httpequiv", | ||
icon: "icon", | ||
id: "id", | ||
inputmode: "inputmode", | ||
integrity: "integrity", | ||
is: "is", | ||
keyparams: "keyparams", | ||
keytype: "keytype", | ||
kind: "kind", | ||
label: "label", | ||
lang: "lang", | ||
list: "list", | ||
loop: "loop", | ||
low: "low", | ||
manifest: "manifest", | ||
marginheight: "marginheight", | ||
marginwidth: "marginwidth", | ||
max: "max", | ||
maxlength: "maxlength", | ||
media: "media", | ||
mediagroup: "mediagroup", | ||
method: "method", | ||
min: "min", | ||
minlength: "minlength", | ||
multiple: "multiple", | ||
muted: "muted", | ||
name: "name", | ||
novalidate: "novalidate", | ||
nonce: "nonce", | ||
onblur: "onblur", | ||
onchange: "onchange", | ||
onclick: "onclick", | ||
onfocus: "onfocus", | ||
oninput: "oninput", | ||
onkeydown: "onkeydown", | ||
onkeyup: "onkeyup", | ||
onmousedown: "onmousedown", | ||
onmouseout: "onmouseout", | ||
onmouseover: "onmouseover", | ||
onmouseup: "onmouseup", | ||
onscroll: "onscroll", | ||
onsubmit: "onsubmit", | ||
ontouchend: "ontouchend", | ||
ontouchmove: "ontouchmove", | ||
ontouchstart: "ontouchstart", | ||
open: "open", | ||
optimum: "optimum", | ||
pattern: "pattern", | ||
placeholder: "placeholder", | ||
poster: "poster", | ||
preload: "preload", | ||
radiogroup: "radiogroup", | ||
readonly: "readonly", | ||
rel: "rel", | ||
required: "required", | ||
reversed: "reversed", | ||
role: "role", | ||
rowspan: "rowspan", | ||
rows: "rows", | ||
sandbox: "sandbox", | ||
scope: "scope", | ||
scoped: "scoped", | ||
scrolling: "scrolling", | ||
seamless: "seamless", | ||
selected: "selected", | ||
shape: "shape", | ||
size: "size", | ||
sizes: "sizes", | ||
span: "span", | ||
spellcheck: "spellcheck", | ||
src: "src", | ||
srcdoc: "srcdoc", | ||
srclang: "srclang", | ||
srcset: "srcset", | ||
start: "start", | ||
step: "step", | ||
style: "style", | ||
summary: "summary", | ||
tabindex: "tabindex", | ||
target: "target", | ||
title: "title", | ||
type: "type", | ||
usemap: "usemap", | ||
value: "value", | ||
width: "width", | ||
wmode: "wmode", | ||
wrap: "wrap" | ||
className: 'className', | ||
colspan: 'colspan', | ||
cols: 'cols', | ||
content: 'content', | ||
contenteditable: 'contenteditable', | ||
contextmenu: 'contextmenu', | ||
controls: 'controls', | ||
coords: 'coords', | ||
crossorigin: 'crossorigin', | ||
data: 'data', | ||
datetime: 'datetime', | ||
default: 'default', | ||
defer: 'defer', | ||
dir: 'dir', | ||
disabled: 'disabled', | ||
download: 'download', | ||
draggable: 'draggable', | ||
enctype: 'enctype', | ||
for: 'for', | ||
form: 'form', | ||
formaction: 'formaction', | ||
formenctype: 'formenctype', | ||
formmethod: 'formmethod', | ||
formnovalidate: 'formnovalidate', | ||
formtarget: 'formtarget', | ||
frameborder: 'frameborder', | ||
headers: 'headers', | ||
height: 'height', | ||
hidden: 'hidden', | ||
high: 'high', | ||
href: 'href', | ||
hreflang: 'hreflang', | ||
htmlfor: 'htmlfor', | ||
httpequiv: 'httpequiv', | ||
icon: 'icon', | ||
id: 'id', | ||
inputmode: 'inputmode', | ||
integrity: 'integrity', | ||
is: 'is', | ||
keyparams: 'keyparams', | ||
keytype: 'keytype', | ||
kind: 'kind', | ||
label: 'label', | ||
lang: 'lang', | ||
list: 'list', | ||
loop: 'loop', | ||
low: 'low', | ||
manifest: 'manifest', | ||
marginheight: 'marginheight', | ||
marginwidth: 'marginwidth', | ||
max: 'max', | ||
maxlength: 'maxlength', | ||
media: 'media', | ||
mediagroup: 'mediagroup', | ||
method: 'method', | ||
min: 'min', | ||
minlength: 'minlength', | ||
multiple: 'multiple', | ||
muted: 'muted', | ||
name: 'name', | ||
novalidate: 'novalidate', | ||
nonce: 'nonce', | ||
onblur: 'onblur', | ||
onchange: 'onchange', | ||
onclick: 'onclick', | ||
onfocus: 'onfocus', | ||
oninput: 'oninput', | ||
onkeydown: 'onkeydown', | ||
onkeyup: 'onkeyup', | ||
onmousedown: 'onmousedown', | ||
onmouseout: 'onmouseout', | ||
onmouseover: 'onmouseover', | ||
onmouseup: 'onmouseup', | ||
onscroll: 'onscroll', | ||
onsubmit: 'onsubmit', | ||
ontouchend: 'ontouchend', | ||
ontouchmove: 'ontouchmove', | ||
ontouchstart: 'ontouchstart', | ||
open: 'open', | ||
optimum: 'optimum', | ||
pattern: 'pattern', | ||
placeholder: 'placeholder', | ||
poster: 'poster', | ||
preload: 'preload', | ||
radiogroup: 'radiogroup', | ||
readonly: 'readonly', | ||
rel: 'rel', | ||
required: 'required', | ||
reversed: 'reversed', | ||
role: 'role', | ||
rowspan: 'rowspan', | ||
rows: 'rows', | ||
sandbox: 'sandbox', | ||
scope: 'scope', | ||
scoped: 'scoped', | ||
scrolling: 'scrolling', | ||
seamless: 'seamless', | ||
selected: 'selected', | ||
shape: 'shape', | ||
size: 'size', | ||
sizes: 'sizes', | ||
span: 'span', | ||
spellcheck: 'spellcheck', | ||
src: 'src', | ||
srcdoc: 'srcdoc', | ||
srclang: 'srclang', | ||
srcset: 'srcset', | ||
start: 'start', | ||
step: 'step', | ||
style: 'style', | ||
summary: 'summary', | ||
tabindex: 'tabindex', | ||
target: 'target', | ||
title: 'title', | ||
type: 'type', | ||
usemap: 'usemap', | ||
value: 'value', | ||
width: 'width', | ||
wmode: 'wmode', | ||
wrap: 'wrap', | ||
}; | ||
var a = htmlAttributes; | ||
var h = m || {}; | ||
var trust = h.trust; | ||
const a = htmlAttributes; | ||
const h = m; | ||
const { trust } = m; | ||
h.trust = (html, wrapper) => (wrapper ? h(wrapper, trust(html)) : trust(html)); | ||
const jsx = m; | ||
const getRef = fn => ({ | ||
oncreate: vnode => { | ||
fn(vnode.dom); | ||
}, | ||
}); | ||
const cast = withHooks; | ||
h.trust = function (html, wrapper) { | ||
return wrapper ? m(wrapper, trust(html)) : trust(html); | ||
}; | ||
h.displayName = "mithril"; | ||
h.fragment = m.fragment; | ||
var jsx = m; | ||
var getRef = function getRef(fn) { | ||
return { | ||
oncreate: function oncreate(vnode) { | ||
return fn(vnode.dom); | ||
} | ||
}; | ||
}; | ||
var cast = withHooks; | ||
export { a, cast, getRef, h, jsx, useCallback, useEffect, useLayoutEffect, useMemo, useReducer, useRef, useState }; | ||
export { a, cast, getRef, h, jsx }; |
{ | ||
"name": "cyano-mithril", | ||
"version": "0.6.9", | ||
"version": "0.7.0", | ||
"description": "Takes a base component and returns a Mithril component", | ||
@@ -8,9 +8,13 @@ "main": "dist/cyano-mithril", | ||
"scripts": { | ||
"npm-check-updates": "../../node_modules/npm-check-updates/bin/cli.js -u", | ||
"build": "node ../../node_modules/npm-run-all/bin/run-s/index.js build:*", | ||
"lint": "eslint ./src", | ||
"build:clean": "rm -rf dist/*", | ||
"build:rollup": "../../node_modules/rollup/dist/bin/rollup -c ../../scripts/rollup.umd.js && ../../node_modules/rollup/dist/bin/rollup -c ../../scripts/rollup.es.js", | ||
"build:clean": "rimraf dist/*", | ||
"build:types": "../../node_modules/typescript/bin/tsc --p tsconfig.gen.json", | ||
"build:module": "TYPESCRIPT=1 ENTRY=src/index.ts MODULE=1 MODULE_NAME=cyanoMithril ../../node_modules/rollup/dist/bin/rollup -c ../../scripts/rollup.config.ts", | ||
"build:umd": "TYPESCRIPT=1 ENTRY=src/index.ts MODULE=0 MODULE_NAME=cyanoMithril ../../node_modules/rollup/dist/bin/rollup -c ../../scripts/rollup.config.ts", | ||
"build:prettier": "../../node_modules/prettier/bin-prettier.js --config ../../.prettierrc.json --write \"./dist/*.{d.ts,module.js}\"", | ||
"build:size": "size-limit", | ||
"size:why": "size-limit --why" | ||
"size:why": "size-limit --why", | ||
"lint": "eslint --fix --ext .ts ./src", | ||
"prettier": "../../node_modules/prettier/bin-prettier.js --config ../../.prettierrc.json --write \"./{src,scripts}/**/*.{js,jsx,ts,tsx,ejs}\"", | ||
"npm-check-updates": "../../node_modules/npm-check-updates/bin/cli.js -u" | ||
}, | ||
@@ -21,2 +25,3 @@ "files": [ | ||
], | ||
"types": "dist", | ||
"author": "Arthur Clemens <arthurclemens@gmail.com> (http://visiblearea.com)", | ||
@@ -30,2 +35,3 @@ "homepage": "https://github.com/ArthurClemens/cyano", | ||
"@size-limit/preset-small-lib": "^4.10.2", | ||
"@types/mithril": "^2.0.7", | ||
"size-limit": "^4.10.2" | ||
@@ -32,0 +38,0 @@ }, |
Sorry, the diff of this file is not supported yet
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
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
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
8
751
28885
3
1