apprun 4.0.0 → 6.0.0-rc.0
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/CHANGELOG.md +235 -12
- package/LICENSE +1 -1
- package/README.md +225 -110
- package/apprun.d.ts +240 -34
- package/cli/app.js +29 -0
- package/cli/colors.js +69 -0
- package/cli/index.html +13 -0
- package/cli/index.js +96 -0
- package/dist/apprun-code.js +2 -0
- package/dist/apprun-code.js.map +1 -0
- package/dist/apprun-dev-tools.js +1 -1
- package/dist/apprun-dev-tools.js.map +1 -1
- package/dist/apprun-html.esm.js +34 -0
- package/dist/apprun-html.esm.js.map +1 -0
- package/dist/apprun-html.js +2 -1
- package/dist/apprun-html.js.LICENSE.txt +11 -0
- package/dist/apprun-html.js.map +1 -1
- package/dist/apprun-play.js +2 -0
- package/dist/apprun-play.js.map +1 -0
- package/dist/apprun.esm.js +2 -0
- package/dist/apprun.esm.js.map +1 -0
- package/dist/apprun.js +1 -1
- package/dist/apprun.js.map +1 -1
- package/dist/createState.js +2 -0
- package/dist/createState.js.map +1 -0
- package/esm/add-components.js +90 -0
- package/esm/add-components.js.map +1 -0
- package/esm/app.js +209 -0
- package/esm/app.js.map +1 -0
- package/esm/apprun-code.js +170 -0
- package/esm/apprun-code.js.map +1 -0
- package/esm/apprun-dev-tools-tests.js +95 -0
- package/esm/apprun-dev-tools-tests.js.map +1 -0
- package/esm/apprun-dev-tools.js +281 -0
- package/esm/apprun-dev-tools.js.map +1 -0
- package/esm/apprun-html.js +24 -0
- package/esm/apprun-html.js.map +1 -0
- package/esm/apprun-play.js +248 -0
- package/esm/apprun-play.js.map +1 -0
- package/esm/apprun.js +220 -0
- package/esm/apprun.js.map +1 -0
- package/esm/component.js +413 -0
- package/esm/component.js.map +1 -0
- package/esm/createState.js +9 -0
- package/esm/createState.js.map +1 -0
- package/esm/decorator.js +88 -0
- package/esm/decorator.js.map +1 -0
- package/esm/directive.js +306 -0
- package/esm/directive.js.map +1 -0
- package/esm/router.js +345 -0
- package/esm/router.js.map +1 -0
- package/esm/type-utils.js +90 -0
- package/esm/type-utils.js.map +1 -0
- package/esm/types.js +58 -0
- package/esm/types.js.map +1 -0
- package/esm/vdom-lit-html.js +65 -0
- package/esm/vdom-lit-html.js.map +1 -0
- package/esm/vdom-my-prop-attr.js +227 -0
- package/esm/vdom-my-prop-attr.js.map +1 -0
- package/esm/vdom-my.js +293 -0
- package/esm/vdom-my.js.map +1 -0
- package/esm/vdom-to-html.js +54 -0
- package/esm/vdom-to-html.js.map +1 -0
- package/esm/vdom.js +28 -0
- package/esm/vdom.js.map +1 -0
- package/esm/version.js +15 -0
- package/esm/version.js.map +1 -0
- package/esm/web-component.js +155 -0
- package/esm/web-component.js.map +1 -0
- package/jsx-runtime.js +2 -0
- package/jsx-runtime.js.map +1 -0
- package/package.json +90 -41
- package/.travis.yml +0 -10
- package/.vscode/launch.json +0 -19
- package/BACKERS.md +0 -3
- package/apprun-cli.js +0 -177
- package/cli-templates/_gitignore +0 -6
- package/cli-templates/component.ts_ +0 -16
- package/cli-templates/index.html +0 -11
- package/cli-templates/karma.conf.js +0 -24
- package/cli-templates/main.ts_ +0 -13
- package/cli-templates/readme.md +0 -7
- package/cli-templates/spa_index.html +0 -14
- package/cli-templates/spa_main.ts_ +0 -47
- package/cli-templates/spec.ts_ +0 -11
- package/cli-templates/tsconfig.json +0 -12
- package/cli-templates/webpack.config.js +0 -23
- package/demo-html/app.js +0 -2
- package/demo-html/app.js.map +0 -1
- package/demo-html/counter-c.html +0 -29
- package/demo-html/counter-wc-event.html +0 -29
- package/demo-html/counter-wc.html +0 -29
- package/demo-html/counter.html +0 -26
- package/demo-html/index.html +0 -14
- package/demo-html/main.tsx +0 -31
- package/docs/README.md +0 -326
- package/docs/index.html +0 -23
- package/index.html +0 -85
- package/logo.png +0 -0
- package/src/app.ts +0 -69
- package/src/apprun-dev-tools.tsx +0 -67
- package/src/apprun-html.ts +0 -13
- package/src/apprun.ts +0 -53
- package/src/component.ts +0 -189
- package/src/createComponent.tsx +0 -38
- package/src/decorator.ts +0 -36
- package/src/router.ts +0 -19
- package/src/types.ts +0 -9
- package/src/vdom-html.ts +0 -17
- package/src/vdom-my.ts +0 -191
- package/src/vdom-to-html.tsx +0 -45
- package/src/vdom.ts +0 -7
- package/src/web-component.ts +0 -29
- package/tests/app-rx.spec_ +0 -41
- package/tests/app.spec.ts +0 -122
- package/tests/application.spec.tsx +0 -23
- package/tests/component.spec.tsx +0 -296
- package/tests/custom-element.spec.tsx +0 -19
- package/tests/data-attr.spec.tsx +0 -42
- package/tests/decorator.spec.tsx +0 -104
- package/tests/fragment.spec.tsx +0 -79
- package/tests/hyperscript.spec.ts +0 -43
- package/tests/node-test.js +0 -7
- package/tests/router.spec.ts +0 -69
- package/tests/stateful-component.spec.tsx +0 -248
- package/tests/typed.spec.tsx +0 -63
- package/tests/vdom-html.spec.ts +0 -35
- package/tests/vdom-jsx.spec.tsx +0 -131
- package/tests/vdom-my.spec.tsx +0 -195
- package/tests/view-engine.spec.js +0 -59
- package/tsconfig.json +0 -11
- package/tslint.json +0 -124
- package/typescriptreact.json +0 -87
- package/viewEngine.js +0 -54
- package/webpack.config.js +0 -30
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define([],t):"object"==typeof exports?exports.apprun=t():e.apprun=t()}(this,(()=>(()=>{"use strict";var e={d:(t,r)=>{for(var n in r)e.o(r,n)&&!e.o(t,n)&&Object.defineProperty(t,n,{enumerable:!0,get:r[n]})},o:(e,t)=>Object.prototype.hasOwnProperty.call(e,t),r:e=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})}},t={};e.r(t),e.d(t,{createState:()=>q});var r=Symbol.for("immer-nothing"),n=Symbol.for("immer-draftable"),o=Symbol.for("immer-state");function i(e,...t){throw new Error(`[Immer] minified error nr: ${e}. Full error at: https://bit.ly/3cXEKWf`)}var c=Object.getPrototypeOf;function a(e){return!!e&&!!e[o]}function s(e){return!!e&&(f(e)||Array.isArray(e)||!!e[n]||!!e.constructor?.[n]||d(e)||h(e))}var u=Object.prototype.constructor.toString();function f(e){if(!e||"object"!=typeof e)return!1;const t=c(e);if(null===t)return!0;const r=Object.hasOwnProperty.call(t,"constructor")&&t.constructor;return r===Object||"function"==typeof r&&Function.toString.call(r)===u}function l(e,t){0===p(e)?Reflect.ownKeys(e).forEach((r=>{t(r,e[r],e)})):e.forEach(((r,n)=>t(n,r,e)))}function p(e){const t=e[o];return t?t.type_:Array.isArray(e)?1:d(e)?2:h(e)?3:0}function _(e,t){return 2===p(e)?e.has(t):Object.prototype.hasOwnProperty.call(e,t)}function y(e,t,r){const n=p(e);2===n?e.set(t,r):3===n?e.add(r):e[t]=r}function d(e){return e instanceof Map}function h(e){return e instanceof Set}function b(e){return e.copy_||e.base_}function m(e,t){if(d(e))return new Map(e);if(h(e))return new Set(e);if(Array.isArray(e))return Array.prototype.slice.call(e);const r=f(e);if(!0===t||"class_only"===t&&!r){const t=Object.getOwnPropertyDescriptors(e);delete t[o];let r=Reflect.ownKeys(t);for(let n=0;n<r.length;n++){const o=r[n],i=t[o];!1===i.writable&&(i.writable=!0,i.configurable=!0),(i.get||i.set)&&(t[o]={configurable:!0,writable:!0,enumerable:i.enumerable,value:e[o]})}return Object.create(c(e),t)}{const t=c(e);if(null!==t&&r)return{...e};const n=Object.create(t);return Object.assign(n,e)}}function v(e,t=!1){return P(e)||a(e)||!s(e)||(p(e)>1&&(e.set=e.add=e.clear=e.delete=g),Object.freeze(e),t&&Object.entries(e).forEach((([e,t])=>v(t,!0)))),e}function g(){i(2)}function P(e){return Object.isFrozen(e)}var S,w={};function O(e){const t=w[e];return t||i(0),t}function z(){return S}function j(e,t){t&&(O("Patches"),e.patches_=[],e.inversePatches_=[],e.patchListener_=t)}function F(e){A(e),e.drafts_.forEach(M),e.drafts_=null}function A(e){e===S&&(S=e.parent_)}function D(e){return S={drafts_:[],parent_:S,immer_:e,canAutoFreeze_:!0,unfinalizedDrafts_:0}}function M(e){const t=e[o];0===t.type_||1===t.type_?t.revoke_():t.revoked_=!0}function C(e,t){t.unfinalizedDrafts_=t.drafts_.length;const n=t.drafts_[0];return void 0!==e&&e!==n?(n[o].modified_&&(F(t),i(4)),s(e)&&(e=x(t,e),t.parent_||k(t,e)),t.patches_&&O("Patches").generateReplacementPatches_(n[o].base_,e,t.patches_,t.inversePatches_)):e=x(t,n,[]),F(t),t.patches_&&t.patchListener_(t.patches_,t.inversePatches_),e!==r?e:void 0}function x(e,t,r){if(P(t))return t;const n=t[o];if(!n)return l(t,((o,i)=>E(e,n,t,o,i,r))),t;if(n.scope_!==e)return t;if(!n.modified_)return k(e,n.base_,!0),n.base_;if(!n.finalized_){n.finalized_=!0,n.scope_.unfinalizedDrafts_--;const t=n.copy_;let o=t,i=!1;3===n.type_&&(o=new Set(t),t.clear(),i=!0),l(o,((o,c)=>E(e,n,t,o,c,r,i))),k(e,t,!1),r&&e.patches_&&O("Patches").generatePatches_(n,r,e.patches_,e.inversePatches_)}return n.copy_}function E(e,t,r,n,o,i,c){if(a(o)){const c=x(e,o,i&&t&&3!==t.type_&&!_(t.assigned_,n)?i.concat(n):void 0);if(y(r,n,c),!a(c))return;e.canAutoFreeze_=!1}else c&&r.add(o);if(s(o)&&!P(o)){if(!e.immer_.autoFreeze_&&e.unfinalizedDrafts_<1)return;x(e,o),t&&t.scope_.parent_||"symbol"==typeof n||!Object.prototype.propertyIsEnumerable.call(r,n)||k(e,o)}}function k(e,t,r=!1){!e.parent_&&e.immer_.autoFreeze_&&e.canAutoFreeze_&&v(t,r)}var N={get(e,t){if(t===o)return e;const r=b(e);if(!_(r,t))return function(e,t,r){const n=W(t,r);return n?"value"in n?n.value:n.get?.call(e.draft_):void 0}(e,r,t);const n=r[t];return e.finalized_||!s(n)?n:n===K(e.base_,t)?(I(e),e.copy_[t]=L(n,e)):n},has:(e,t)=>t in b(e),ownKeys:e=>Reflect.ownKeys(b(e)),set(e,t,r){const n=W(b(e),t);if(n?.set)return n.set.call(e.draft_,r),!0;if(!e.modified_){const n=K(b(e),t),a=n?.[o];if(a&&a.base_===r)return e.copy_[t]=r,e.assigned_[t]=!1,!0;if(((i=r)===(c=n)?0!==i||1/i==1/c:i!=i&&c!=c)&&(void 0!==r||_(e.base_,t)))return!0;I(e),U(e)}var i,c;return e.copy_[t]===r&&(void 0!==r||t in e.copy_)||Number.isNaN(r)&&Number.isNaN(e.copy_[t])||(e.copy_[t]=r,e.assigned_[t]=!0),!0},deleteProperty:(e,t)=>(void 0!==K(e.base_,t)||t in e.base_?(e.assigned_[t]=!1,I(e),U(e)):delete e.assigned_[t],e.copy_&&delete e.copy_[t],!0),getOwnPropertyDescriptor(e,t){const r=b(e),n=Reflect.getOwnPropertyDescriptor(r,t);return n?{writable:!0,configurable:1!==e.type_||"length"!==t,enumerable:n.enumerable,value:r[t]}:n},defineProperty(){i(11)},getPrototypeOf:e=>c(e.base_),setPrototypeOf(){i(12)}},R={};function K(e,t){const r=e[o];return(r?b(r):e)[t]}function W(e,t){if(!(t in e))return;let r=c(e);for(;r;){const e=Object.getOwnPropertyDescriptor(r,t);if(e)return e;r=c(r)}}function U(e){e.modified_||(e.modified_=!0,e.parent_&&U(e.parent_))}function I(e){e.copy_||(e.copy_=m(e.base_,e.scope_.immer_.useStrictShallowCopy_))}function L(e,t){const r=d(e)?O("MapSet").proxyMap_(e,t):h(e)?O("MapSet").proxySet_(e,t):function(e,t){const r=Array.isArray(e),n={type_:r?1:0,scope_:t?t.scope_:z(),modified_:!1,finalized_:!1,assigned_:{},parent_:t,base_:e,draft_:null,copy_:null,revoke_:null,isManual_:!1};let o=n,i=N;r&&(o=[n],i=R);const{revoke:c,proxy:a}=Proxy.revocable(o,i);return n.draft_=a,n.revoke_=c,a}(e,t);return(t?t.scope_:z()).drafts_.push(r),r}function T(e){if(!s(e)||P(e))return e;const t=e[o];let r;if(t){if(!t.modified_)return t.base_;t.finalized_=!0,r=m(e,t.scope_.immer_.useStrictShallowCopy_)}else r=m(e,!0);return l(r,((e,t)=>{y(r,e,T(t))})),t&&(t.finalized_=!1),r}l(N,((e,t)=>{R[e]=function(){return arguments[0]=arguments[0][0],t.apply(this,arguments)}})),R.deleteProperty=function(e,t){return R.set.call(this,e,t,void 0)},R.set=function(e,t,r){return N.set.call(this,e[0],t,r,e[0])};var X=new class{constructor(e){this.autoFreeze_=!0,this.useStrictShallowCopy_=!1,this.produce=(e,t,n)=>{if("function"==typeof e&&"function"!=typeof t){const r=t;t=e;const n=this;return function(e=r,...o){return n.produce(e,(e=>t.call(this,e,...o)))}}let o;if("function"!=typeof t&&i(6),void 0!==n&&"function"!=typeof n&&i(7),s(e)){const r=D(this),i=L(e,void 0);let c=!0;try{o=t(i),c=!1}finally{c?F(r):A(r)}return j(r,n),C(o,r)}if(!e||"object"!=typeof e){if(o=t(e),void 0===o&&(o=e),o===r&&(o=void 0),this.autoFreeze_&&v(o,!0),n){const t=[],r=[];O("Patches").generateReplacementPatches_(e,o,t,r),n(t,r)}return o}i(1)},this.produceWithPatches=(e,t)=>{if("function"==typeof e)return(t,...r)=>this.produceWithPatches(t,(t=>e(t,...r)));let r,n;return[this.produce(e,t,((e,t)=>{r=e,n=t})),r,n]},"boolean"==typeof e?.autoFreeze&&this.setAutoFreeze(e.autoFreeze),"boolean"==typeof e?.useStrictShallowCopy&&this.setUseStrictShallowCopy(e.useStrictShallowCopy)}createDraft(e){var t;s(e)||i(8),a(e)&&(a(t=e)||i(10),e=T(t));const r=D(this),n=L(e,void 0);return n[o].isManual_=!0,A(r),n}finishDraft(e,t){const r=e&&e[o];r&&r.isManual_||i(9);const{scope_:n}=r;return j(n,t),C(void 0,n)}setAutoFreeze(e){this.autoFreeze_=e}setUseStrictShallowCopy(e){this.useStrictShallowCopy_=e}applyPatches(e,t){let r;for(r=t.length-1;r>=0;r--){const n=t[r];if(0===n.path.length&&"replace"===n.op){e=n.value;break}}r>-1&&(t=t.slice(r+1));const n=O("Patches").applyPatches_;return a(e)?n(e,t):this.produce(e,(e=>n(e,t)))}},$=X.produce;function q(e){return(t,...r)=>$(t,(t=>{e(t,...r)}))}return X.produceWithPatches.bind(X),X.setAutoFreeze.bind(X),X.setUseStrictShallowCopy.bind(X),X.applyPatches.bind(X),X.createDraft.bind(X),X.finishDraft.bind(X),t})()));
|
|
2
|
+
//# sourceMappingURL=createState.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"dist/createState.js","mappings":"CAAA,SAA2CA,EAAMC,GAC1B,iBAAZC,SAA0C,iBAAXC,OACxCA,OAAOD,QAAUD,IACQ,mBAAXG,QAAyBA,OAAOC,IAC9CD,OAAO,GAAIH,GACe,iBAAZC,QACdA,QAAgB,OAAID,IAEpBD,EAAa,OAAIC,GAClB,CATD,CASGK,MAAM,I,mBCRT,IAAIC,EAAsB,CCA1BA,EAAwB,CAACL,EAASM,KACjC,IAAI,IAAIC,KAAOD,EACXD,EAAoBG,EAAEF,EAAYC,KAASF,EAAoBG,EAAER,EAASO,IAC5EE,OAAOC,eAAeV,EAASO,EAAK,CAAEI,YAAY,EAAMC,IAAKN,EAAWC,IAE1E,ECNDF,EAAwB,CAACQ,EAAKC,IAAUL,OAAOM,UAAUC,eAAeC,KAAKJ,EAAKC,GCClFT,EAAyBL,IACH,oBAAXkB,QAA0BA,OAAOC,aAC1CV,OAAOC,eAAeV,EAASkB,OAAOC,YAAa,CAAEC,MAAO,WAE7DX,OAAOC,eAAeV,EAAS,aAAc,CAAEoB,OAAO,GAAO,G,uCCJ9D,IAAIC,EAAUH,OAAOI,IAAI,iBACrBC,EAAYL,OAAOI,IAAI,mBACvBE,EAAcN,OAAOI,IAAI,eAkC7B,SAASG,EAAIC,KAAUC,GAMrB,MAAM,IAAIC,MACR,8BAA8BF,2CAElC,CAGA,IAAIG,EAAiBpB,OAAOoB,eA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AAKzB,GACfA,EAAMgB,wBAAwBS,KAAKzB,GAC9CA,EAAMmB,aAAaM,KAAKzB,GACzBA,EAAMiB,YAAYQ,KAAKzB,GACvBA,EAAMkB,YAAYO,KAAKzB,G","sources":["webpack://apprun/webpack/universalModuleDefinition","webpack://apprun/webpack/bootstrap","webpack://apprun/webpack/runtime/define property getters","webpack://apprun/webpack/runtime/hasOwnProperty shorthand","webpack://apprun/webpack/runtime/make namespace object","webpack://apprun/./node_modules/immer/dist/immer.mjs","webpack://apprun/./src/createState.ts"],"sourcesContent":["(function webpackUniversalModuleDefinition(root, factory) {\n\tif(typeof exports === 'object' && typeof module === 'object')\n\t\tmodule.exports = factory();\n\telse if(typeof define === 'function' && define.amd)\n\t\tdefine([], factory);\n\telse if(typeof exports === 'object')\n\t\texports[\"apprun\"] = factory();\n\telse\n\t\troot[\"apprun\"] = factory();\n})(this, () => {\nreturn ","// The require scope\nvar __webpack_require__ = {};\n\n","// define getter functions for harmony exports\n__webpack_require__.d = (exports, definition) => {\n\tfor(var key in definition) {\n\t\tif(__webpack_require__.o(definition, key) && !__webpack_require__.o(exports, key)) {\n\t\t\tObject.defineProperty(exports, key, { enumerable: true, get: definition[key] });\n\t\t}\n\t}\n};","__webpack_require__.o = (obj, prop) => (Object.prototype.hasOwnProperty.call(obj, prop))","// define __esModule on exports\n__webpack_require__.r = (exports) => {\n\tif(typeof Symbol !== 'undefined' && Symbol.toStringTag) {\n\t\tObject.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });\n\t}\n\tObject.defineProperty(exports, '__esModule', { value: true });\n};","// src/utils/env.ts\nvar NOTHING = Symbol.for(\"immer-nothing\");\nvar DRAFTABLE = Symbol.for(\"immer-draftable\");\nvar DRAFT_STATE = Symbol.for(\"immer-state\");\n\n// src/utils/errors.ts\nvar errors = process.env.NODE_ENV !== \"production\" ? [\n // All error codes, starting by 0:\n function(plugin) {\n return `The plugin for '${plugin}' has not been loaded into Immer. To enable the plugin, import and call \\`enable${plugin}()\\` when initializing your application.`;\n },\n function(thing) {\n return `produce can only be called on things that are draftable: plain objects, arrays, Map, Set or classes that are marked with '[immerable]: true'. Got '${thing}'`;\n },\n \"This object has been frozen and should not be mutated\",\n function(data) {\n return \"Cannot use a proxy that has been revoked. Did you pass an object from inside an immer function to an async process? \" + data;\n },\n \"An immer producer returned a new value *and* modified its draft. Either return a new value *or* modify the draft.\",\n \"Immer forbids circular references\",\n \"The first or second argument to `produce` must be a function\",\n \"The third argument to `produce` must be a function or undefined\",\n \"First argument to `createDraft` must be a plain object, an array, or an immerable object\",\n \"First argument to `finishDraft` must be a draft returned by `createDraft`\",\n function(thing) {\n return `'current' expects a draft, got: ${thing}`;\n },\n \"Object.defineProperty() cannot be used on an Immer draft\",\n \"Object.setPrototypeOf() cannot be used on an Immer draft\",\n \"Immer only supports deleting array indices\",\n \"Immer only supports setting array indices and the 'length' property\",\n function(thing) {\n return `'original' expects a draft, got: ${thing}`;\n }\n // Note: if more errors are added, the errorOffset in Patches.ts should be increased\n // See Patches.ts for additional errors\n] : [];\nfunction die(error, ...args) {\n if (process.env.NODE_ENV !== \"production\") {\n const e = errors[error];\n const msg = typeof e === \"function\" ? e.apply(null, args) : e;\n throw new Error(`[Immer] ${msg}`);\n }\n throw new Error(\n `[Immer] minified error nr: ${error}. Full error at: https://bit.ly/3cXEKWf`\n );\n}\n\n// src/utils/common.ts\nvar getPrototypeOf = Object.getPrototypeOf;\nfunction isDraft(value) {\n return !!value && !!value[DRAFT_STATE];\n}\nfunction isDraftable(value) {\n if (!value)\n return false;\n return isPlainObject(value) || Array.isArray(value) || !!value[DRAFTABLE] || !!value.constructor?.[DRAFTABLE] || isMap(value) || isSet(value);\n}\nvar objectCtorString = Object.prototype.constructor.toString();\nfunction isPlainObject(value) {\n if (!value || typeof value !== \"object\")\n return false;\n const proto = getPrototypeOf(value);\n if (proto === null) {\n return true;\n }\n const Ctor = Object.hasOwnProperty.call(proto, \"constructor\") && proto.constructor;\n if (Ctor === Object)\n return true;\n return typeof Ctor == \"function\" && Function.toString.call(Ctor) === objectCtorString;\n}\nfunction original(value) {\n if (!isDraft(value))\n die(15, value);\n return value[DRAFT_STATE].base_;\n}\nfunction each(obj, iter) {\n if (getArchtype(obj) === 0 /* Object */) {\n Reflect.ownKeys(obj).forEach((key) => {\n iter(key, obj[key], obj);\n });\n } else {\n obj.forEach((entry, index) => iter(index, entry, obj));\n }\n}\nfunction getArchtype(thing) {\n const state = thing[DRAFT_STATE];\n return state ? state.type_ : Array.isArray(thing) ? 1 /* Array */ : isMap(thing) ? 2 /* Map */ : isSet(thing) ? 3 /* Set */ : 0 /* Object */;\n}\nfunction has(thing, prop) {\n return getArchtype(thing) === 2 /* Map */ ? thing.has(prop) : Object.prototype.hasOwnProperty.call(thing, prop);\n}\nfunction get(thing, prop) {\n return getArchtype(thing) === 2 /* Map */ ? thing.get(prop) : thing[prop];\n}\nfunction set(thing, propOrOldValue, value) {\n const t = getArchtype(thing);\n if (t === 2 /* Map */)\n thing.set(propOrOldValue, value);\n else if (t === 3 /* Set */) {\n thing.add(value);\n } else\n thing[propOrOldValue] = value;\n}\nfunction is(x, y) {\n if (x === y) {\n return x !== 0 || 1 / x === 1 / y;\n } else {\n return x !== x && y !== y;\n }\n}\nfunction isMap(target) {\n return target instanceof Map;\n}\nfunction isSet(target) {\n return target instanceof Set;\n}\nfunction latest(state) {\n return state.copy_ || state.base_;\n}\nfunction shallowCopy(base, strict) {\n if (isMap(base)) {\n return new Map(base);\n }\n if (isSet(base)) {\n return new Set(base);\n }\n if (Array.isArray(base))\n return Array.prototype.slice.call(base);\n const isPlain = isPlainObject(base);\n if (strict === true || strict === \"class_only\" && !isPlain) {\n const descriptors = Object.getOwnPropertyDescriptors(base);\n delete descriptors[DRAFT_STATE];\n let keys = Reflect.ownKeys(descriptors);\n for (let i = 0; i < keys.length; i++) {\n const key = keys[i];\n const desc = descriptors[key];\n if (desc.writable === false) {\n desc.writable = true;\n desc.configurable = true;\n }\n if (desc.get || desc.set)\n descriptors[key] = {\n configurable: true,\n writable: true,\n // could live with !!desc.set as well here...\n enumerable: desc.enumerable,\n value: base[key]\n };\n }\n return Object.create(getPrototypeOf(base), descriptors);\n } else {\n const proto = getPrototypeOf(base);\n if (proto !== null && isPlain) {\n return { ...base };\n }\n const obj = Object.create(proto);\n return Object.assign(obj, base);\n }\n}\nfunction freeze(obj, deep = false) {\n if (isFrozen(obj) || isDraft(obj) || !isDraftable(obj))\n return obj;\n if (getArchtype(obj) > 1) {\n obj.set = obj.add = obj.clear = obj.delete = dontMutateFrozenCollections;\n }\n Object.freeze(obj);\n if (deep)\n Object.entries(obj).forEach(([key, value]) => freeze(value, true));\n return obj;\n}\nfunction dontMutateFrozenCollections() {\n die(2);\n}\nfunction isFrozen(obj) {\n return Object.isFrozen(obj);\n}\n\n// src/utils/plugins.ts\nvar plugins = {};\nfunction getPlugin(pluginKey) {\n const plugin = plugins[pluginKey];\n if (!plugin) {\n die(0, pluginKey);\n }\n return plugin;\n}\nfunction loadPlugin(pluginKey, implementation) {\n if (!plugins[pluginKey])\n plugins[pluginKey] = implementation;\n}\n\n// src/core/scope.ts\nvar currentScope;\nfunction getCurrentScope() {\n return currentScope;\n}\nfunction createScope(parent_, immer_) {\n return {\n drafts_: [],\n parent_,\n immer_,\n // Whenever the modified draft contains a draft from another scope, we\n // need to prevent auto-freezing so the unowned draft can be finalized.\n canAutoFreeze_: true,\n unfinalizedDrafts_: 0\n };\n}\nfunction usePatchesInScope(scope, patchListener) {\n if (patchListener) {\n getPlugin(\"Patches\");\n scope.patches_ = [];\n scope.inversePatches_ = [];\n scope.patchListener_ = patchListener;\n }\n}\nfunction revokeScope(scope) {\n leaveScope(scope);\n scope.drafts_.forEach(revokeDraft);\n scope.drafts_ = null;\n}\nfunction leaveScope(scope) {\n if (scope === currentScope) {\n currentScope = scope.parent_;\n }\n}\nfunction enterScope(immer2) {\n return currentScope = createScope(currentScope, immer2);\n}\nfunction revokeDraft(draft) {\n const state = draft[DRAFT_STATE];\n if (state.type_ === 0 /* Object */ || state.type_ === 1 /* Array */)\n state.revoke_();\n else\n state.revoked_ = true;\n}\n\n// src/core/finalize.ts\nfunction processResult(result, scope) {\n scope.unfinalizedDrafts_ = scope.drafts_.length;\n const baseDraft = scope.drafts_[0];\n const isReplaced = result !== void 0 && result !== baseDraft;\n if (isReplaced) {\n if (baseDraft[DRAFT_STATE].modified_) {\n revokeScope(scope);\n die(4);\n }\n if (isDraftable(result)) {\n result = finalize(scope, result);\n if (!scope.parent_)\n maybeFreeze(scope, result);\n }\n if (scope.patches_) {\n getPlugin(\"Patches\").generateReplacementPatches_(\n baseDraft[DRAFT_STATE].base_,\n result,\n scope.patches_,\n scope.inversePatches_\n );\n }\n } else {\n result = finalize(scope, baseDraft, []);\n }\n revokeScope(scope);\n if (scope.patches_) {\n scope.patchListener_(scope.patches_, scope.inversePatches_);\n }\n return result !== NOTHING ? result : void 0;\n}\nfunction finalize(rootScope, value, path) {\n if (isFrozen(value))\n return value;\n const state = value[DRAFT_STATE];\n if (!state) {\n each(\n value,\n (key, childValue) => finalizeProperty(rootScope, state, value, key, childValue, path)\n );\n return value;\n }\n if (state.scope_ !== rootScope)\n return value;\n if (!state.modified_) {\n maybeFreeze(rootScope, state.base_, true);\n return state.base_;\n }\n if (!state.finalized_) {\n state.finalized_ = true;\n state.scope_.unfinalizedDrafts_--;\n const result = state.copy_;\n let resultEach = result;\n let isSet2 = false;\n if (state.type_ === 3 /* Set */) {\n resultEach = new Set(result);\n result.clear();\n isSet2 = true;\n }\n each(\n resultEach,\n (key, childValue) => finalizeProperty(rootScope, state, result, key, childValue, path, isSet2)\n );\n maybeFreeze(rootScope, result, false);\n if (path && rootScope.patches_) {\n getPlugin(\"Patches\").generatePatches_(\n state,\n path,\n rootScope.patches_,\n rootScope.inversePatches_\n );\n }\n }\n return state.copy_;\n}\nfunction finalizeProperty(rootScope, parentState, targetObject, prop, childValue, rootPath, targetIsSet) {\n if (process.env.NODE_ENV !== \"production\" && childValue === targetObject)\n die(5);\n if (isDraft(childValue)) {\n const path = rootPath && parentState && parentState.type_ !== 3 /* Set */ && // Set objects are atomic since they have no keys.\n !has(parentState.assigned_, prop) ? rootPath.concat(prop) : void 0;\n const res = finalize(rootScope, childValue, path);\n set(targetObject, prop, res);\n if (isDraft(res)) {\n rootScope.canAutoFreeze_ = false;\n } else\n return;\n } else if (targetIsSet) {\n targetObject.add(childValue);\n }\n if (isDraftable(childValue) && !isFrozen(childValue)) {\n if (!rootScope.immer_.autoFreeze_ && rootScope.unfinalizedDrafts_ < 1) {\n return;\n }\n finalize(rootScope, childValue);\n if ((!parentState || !parentState.scope_.parent_) && typeof prop !== \"symbol\" && Object.prototype.propertyIsEnumerable.call(targetObject, prop))\n maybeFreeze(rootScope, childValue);\n }\n}\nfunction maybeFreeze(scope, value, deep = false) {\n if (!scope.parent_ && scope.immer_.autoFreeze_ && scope.canAutoFreeze_) {\n freeze(value, deep);\n }\n}\n\n// src/core/proxy.ts\nfunction createProxyProxy(base, parent) {\n const isArray = Array.isArray(base);\n const state = {\n type_: isArray ? 1 /* Array */ : 0 /* Object */,\n // Track which produce call this is associated with.\n scope_: parent ? parent.scope_ : getCurrentScope(),\n // True for both shallow and deep changes.\n modified_: false,\n // Used during finalization.\n finalized_: false,\n // Track which properties have been assigned (true) or deleted (false).\n assigned_: {},\n // The parent draft state.\n parent_: parent,\n // The base state.\n base_: base,\n // The base proxy.\n draft_: null,\n // set below\n // The base copy with any updated values.\n copy_: null,\n // Called by the `produce` function.\n revoke_: null,\n isManual_: false\n };\n let target = state;\n let traps = objectTraps;\n if (isArray) {\n target = [state];\n traps = arrayTraps;\n }\n const { revoke, proxy } = Proxy.revocable(target, traps);\n state.draft_ = proxy;\n state.revoke_ = revoke;\n return proxy;\n}\nvar objectTraps = {\n get(state, prop) {\n if (prop === DRAFT_STATE)\n return state;\n const source = latest(state);\n if (!has(source, prop)) {\n return readPropFromProto(state, source, prop);\n }\n const value = source[prop];\n if (state.finalized_ || !isDraftable(value)) {\n return value;\n }\n if (value === peek(state.base_, prop)) {\n prepareCopy(state);\n return state.copy_[prop] = createProxy(value, state);\n }\n return value;\n },\n has(state, prop) {\n return prop in latest(state);\n },\n ownKeys(state) {\n return Reflect.ownKeys(latest(state));\n },\n set(state, prop, value) {\n const desc = getDescriptorFromProto(latest(state), prop);\n if (desc?.set) {\n desc.set.call(state.draft_, value);\n return true;\n }\n if (!state.modified_) {\n const current2 = peek(latest(state), prop);\n const currentState = current2?.[DRAFT_STATE];\n if (currentState && currentState.base_ === value) {\n state.copy_[prop] = value;\n state.assigned_[prop] = false;\n return true;\n }\n if (is(value, current2) && (value !== void 0 || has(state.base_, prop)))\n return true;\n prepareCopy(state);\n markChanged(state);\n }\n if (state.copy_[prop] === value && // special case: handle new props with value 'undefined'\n (value !== void 0 || prop in state.copy_) || // special case: NaN\n Number.isNaN(value) && Number.isNaN(state.copy_[prop]))\n return true;\n state.copy_[prop] = value;\n state.assigned_[prop] = true;\n return true;\n },\n deleteProperty(state, prop) {\n if (peek(state.base_, prop) !== void 0 || prop in state.base_) {\n state.assigned_[prop] = false;\n prepareCopy(state);\n markChanged(state);\n } else {\n delete state.assigned_[prop];\n }\n if (state.copy_) {\n delete state.copy_[prop];\n }\n return true;\n },\n // Note: We never coerce `desc.value` into an Immer draft, because we can't make\n // the same guarantee in ES5 mode.\n getOwnPropertyDescriptor(state, prop) {\n const owner = latest(state);\n const desc = Reflect.getOwnPropertyDescriptor(owner, prop);\n if (!desc)\n return desc;\n return {\n writable: true,\n configurable: state.type_ !== 1 /* Array */ || prop !== \"length\",\n enumerable: desc.enumerable,\n value: owner[prop]\n };\n },\n defineProperty() {\n die(11);\n },\n getPrototypeOf(state) {\n return getPrototypeOf(state.base_);\n },\n setPrototypeOf() {\n die(12);\n }\n};\nvar arrayTraps = {};\neach(objectTraps, (key, fn) => {\n arrayTraps[key] = function() {\n arguments[0] = arguments[0][0];\n return fn.apply(this, arguments);\n };\n});\narrayTraps.deleteProperty = function(state, prop) {\n if (process.env.NODE_ENV !== \"production\" && isNaN(parseInt(prop)))\n die(13);\n return arrayTraps.set.call(this, state, prop, void 0);\n};\narrayTraps.set = function(state, prop, value) {\n if (process.env.NODE_ENV !== \"production\" && prop !== \"length\" && isNaN(parseInt(prop)))\n die(14);\n return objectTraps.set.call(this, state[0], prop, value, state[0]);\n};\nfunction peek(draft, prop) {\n const state = draft[DRAFT_STATE];\n const source = state ? latest(state) : draft;\n return source[prop];\n}\nfunction readPropFromProto(state, source, prop) {\n const desc = getDescriptorFromProto(source, prop);\n return desc ? `value` in desc ? desc.value : (\n // This is a very special case, if the prop is a getter defined by the\n // prototype, we should invoke it with the draft as context!\n desc.get?.call(state.draft_)\n ) : void 0;\n}\nfunction getDescriptorFromProto(source, prop) {\n if (!(prop in source))\n return void 0;\n let proto = getPrototypeOf(source);\n while (proto) {\n const desc = Object.getOwnPropertyDescriptor(proto, prop);\n if (desc)\n return desc;\n proto = getPrototypeOf(proto);\n }\n return void 0;\n}\nfunction markChanged(state) {\n if (!state.modified_) {\n state.modified_ = true;\n if (state.parent_) {\n markChanged(state.parent_);\n }\n }\n}\nfunction prepareCopy(state) {\n if (!state.copy_) {\n state.copy_ = shallowCopy(\n state.base_,\n state.scope_.immer_.useStrictShallowCopy_\n );\n }\n}\n\n// src/core/immerClass.ts\nvar Immer2 = class {\n constructor(config) {\n this.autoFreeze_ = true;\n this.useStrictShallowCopy_ = false;\n /**\n * The `produce` function takes a value and a \"recipe function\" (whose\n * return value often depends on the base state). The recipe function is\n * free to mutate its first argument however it wants. All mutations are\n * only ever applied to a __copy__ of the base state.\n *\n * Pass only a function to create a \"curried producer\" which relieves you\n * from passing the recipe function every time.\n *\n * Only plain objects and arrays are made mutable. All other objects are\n * considered uncopyable.\n *\n * Note: This function is __bound__ to its `Immer` instance.\n *\n * @param {any} base - the initial state\n * @param {Function} recipe - function that receives a proxy of the base state as first argument and which can be freely modified\n * @param {Function} patchListener - optional function that will be called with all the patches produced here\n * @returns {any} a new state, or the initial state if nothing was modified\n */\n this.produce = (base, recipe, patchListener) => {\n if (typeof base === \"function\" && typeof recipe !== \"function\") {\n const defaultBase = recipe;\n recipe = base;\n const self = this;\n return function curriedProduce(base2 = defaultBase, ...args) {\n return self.produce(base2, (draft) => recipe.call(this, draft, ...args));\n };\n }\n if (typeof recipe !== \"function\")\n die(6);\n if (patchListener !== void 0 && typeof patchListener !== \"function\")\n die(7);\n let result;\n if (isDraftable(base)) {\n const scope = enterScope(this);\n const proxy = createProxy(base, void 0);\n let hasError = true;\n try {\n result = recipe(proxy);\n hasError = false;\n } finally {\n if (hasError)\n revokeScope(scope);\n else\n leaveScope(scope);\n }\n usePatchesInScope(scope, patchListener);\n return processResult(result, scope);\n } else if (!base || typeof base !== \"object\") {\n result = recipe(base);\n if (result === void 0)\n result = base;\n if (result === NOTHING)\n result = void 0;\n if (this.autoFreeze_)\n freeze(result, true);\n if (patchListener) {\n const p = [];\n const ip = [];\n getPlugin(\"Patches\").generateReplacementPatches_(base, result, p, ip);\n patchListener(p, ip);\n }\n return result;\n } else\n die(1, base);\n };\n this.produceWithPatches = (base, recipe) => {\n if (typeof base === \"function\") {\n return (state, ...args) => this.produceWithPatches(state, (draft) => base(draft, ...args));\n }\n let patches, inversePatches;\n const result = this.produce(base, recipe, (p, ip) => {\n patches = p;\n inversePatches = ip;\n });\n return [result, patches, inversePatches];\n };\n if (typeof config?.autoFreeze === \"boolean\")\n this.setAutoFreeze(config.autoFreeze);\n if (typeof config?.useStrictShallowCopy === \"boolean\")\n this.setUseStrictShallowCopy(config.useStrictShallowCopy);\n }\n createDraft(base) {\n if (!isDraftable(base))\n die(8);\n if (isDraft(base))\n base = current(base);\n const scope = enterScope(this);\n const proxy = createProxy(base, void 0);\n proxy[DRAFT_STATE].isManual_ = true;\n leaveScope(scope);\n return proxy;\n }\n finishDraft(draft, patchListener) {\n const state = draft && draft[DRAFT_STATE];\n if (!state || !state.isManual_)\n die(9);\n const { scope_: scope } = state;\n usePatchesInScope(scope, patchListener);\n return processResult(void 0, scope);\n }\n /**\n * Pass true to automatically freeze all copies created by Immer.\n *\n * By default, auto-freezing is enabled.\n */\n setAutoFreeze(value) {\n this.autoFreeze_ = value;\n }\n /**\n * Pass true to enable strict shallow copy.\n *\n * By default, immer does not copy the object descriptors such as getter, setter and non-enumrable properties.\n */\n setUseStrictShallowCopy(value) {\n this.useStrictShallowCopy_ = value;\n }\n applyPatches(base, patches) {\n let i;\n for (i = patches.length - 1; i >= 0; i--) {\n const patch = patches[i];\n if (patch.path.length === 0 && patch.op === \"replace\") {\n base = patch.value;\n break;\n }\n }\n if (i > -1) {\n patches = patches.slice(i + 1);\n }\n const applyPatchesImpl = getPlugin(\"Patches\").applyPatches_;\n if (isDraft(base)) {\n return applyPatchesImpl(base, patches);\n }\n return this.produce(\n base,\n (draft) => applyPatchesImpl(draft, patches)\n );\n }\n};\nfunction createProxy(value, parent) {\n const draft = isMap(value) ? getPlugin(\"MapSet\").proxyMap_(value, parent) : isSet(value) ? getPlugin(\"MapSet\").proxySet_(value, parent) : createProxyProxy(value, parent);\n const scope = parent ? parent.scope_ : getCurrentScope();\n scope.drafts_.push(draft);\n return draft;\n}\n\n// src/core/current.ts\nfunction current(value) {\n if (!isDraft(value))\n die(10, value);\n return currentImpl(value);\n}\nfunction currentImpl(value) {\n if (!isDraftable(value) || isFrozen(value))\n return value;\n const state = value[DRAFT_STATE];\n let copy;\n if (state) {\n if (!state.modified_)\n return state.base_;\n state.finalized_ = true;\n copy = shallowCopy(value, state.scope_.immer_.useStrictShallowCopy_);\n } else {\n copy = shallowCopy(value, true);\n }\n each(copy, (key, childValue) => {\n set(copy, key, currentImpl(childValue));\n });\n if (state) {\n state.finalized_ = false;\n }\n return copy;\n}\n\n// src/plugins/patches.ts\nfunction enablePatches() {\n const errorOffset = 16;\n if (process.env.NODE_ENV !== \"production\") {\n errors.push(\n 'Sets cannot have \"replace\" patches.',\n function(op) {\n return \"Unsupported patch operation: \" + op;\n },\n function(path) {\n return \"Cannot apply patch, path doesn't resolve: \" + path;\n },\n \"Patching reserved attributes like __proto__, prototype and constructor is not allowed\"\n );\n }\n const REPLACE = \"replace\";\n const ADD = \"add\";\n const REMOVE = \"remove\";\n function generatePatches_(state, basePath, patches, inversePatches) {\n switch (state.type_) {\n case 0 /* Object */:\n case 2 /* Map */:\n return generatePatchesFromAssigned(\n state,\n basePath,\n patches,\n inversePatches\n );\n case 1 /* Array */:\n return generateArrayPatches(state, basePath, patches, inversePatches);\n case 3 /* Set */:\n return generateSetPatches(\n state,\n basePath,\n patches,\n inversePatches\n );\n }\n }\n function generateArrayPatches(state, basePath, patches, inversePatches) {\n let { base_, assigned_ } = state;\n let copy_ = state.copy_;\n if (copy_.length < base_.length) {\n ;\n [base_, copy_] = [copy_, base_];\n [patches, inversePatches] = [inversePatches, patches];\n }\n for (let i = 0; i < base_.length; i++) {\n if (assigned_[i] && copy_[i] !== base_[i]) {\n const path = basePath.concat([i]);\n patches.push({\n op: REPLACE,\n path,\n // Need to maybe clone it, as it can in fact be the original value\n // due to the base/copy inversion at the start of this function\n value: clonePatchValueIfNeeded(copy_[i])\n });\n inversePatches.push({\n op: REPLACE,\n path,\n value: clonePatchValueIfNeeded(base_[i])\n });\n }\n }\n for (let i = base_.length; i < copy_.length; i++) {\n const path = basePath.concat([i]);\n patches.push({\n op: ADD,\n path,\n // Need to maybe clone it, as it can in fact be the original value\n // due to the base/copy inversion at the start of this function\n value: clonePatchValueIfNeeded(copy_[i])\n });\n }\n for (let i = copy_.length - 1; base_.length <= i; --i) {\n const path = basePath.concat([i]);\n inversePatches.push({\n op: REMOVE,\n path\n });\n }\n }\n function generatePatchesFromAssigned(state, basePath, patches, inversePatches) {\n const { base_, copy_ } = state;\n each(state.assigned_, (key, assignedValue) => {\n const origValue = get(base_, key);\n const value = get(copy_, key);\n const op = !assignedValue ? REMOVE : has(base_, key) ? REPLACE : ADD;\n if (origValue === value && op === REPLACE)\n return;\n const path = basePath.concat(key);\n patches.push(op === REMOVE ? { op, path } : { op, path, value });\n inversePatches.push(\n op === ADD ? { op: REMOVE, path } : op === REMOVE ? { op: ADD, path, value: clonePatchValueIfNeeded(origValue) } : { op: REPLACE, path, value: clonePatchValueIfNeeded(origValue) }\n );\n });\n }\n function generateSetPatches(state, basePath, patches, inversePatches) {\n let { base_, copy_ } = state;\n let i = 0;\n base_.forEach((value) => {\n if (!copy_.has(value)) {\n const path = basePath.concat([i]);\n patches.push({\n op: REMOVE,\n path,\n value\n });\n inversePatches.unshift({\n op: ADD,\n path,\n value\n });\n }\n i++;\n });\n i = 0;\n copy_.forEach((value) => {\n if (!base_.has(value)) {\n const path = basePath.concat([i]);\n patches.push({\n op: ADD,\n path,\n value\n });\n inversePatches.unshift({\n op: REMOVE,\n path,\n value\n });\n }\n i++;\n });\n }\n function generateReplacementPatches_(baseValue, replacement, patches, inversePatches) {\n patches.push({\n op: REPLACE,\n path: [],\n value: replacement === NOTHING ? void 0 : replacement\n });\n inversePatches.push({\n op: REPLACE,\n path: [],\n value: baseValue\n });\n }\n function applyPatches_(draft, patches) {\n patches.forEach((patch) => {\n const { path, op } = patch;\n let base = draft;\n for (let i = 0; i < path.length - 1; i++) {\n const parentType = getArchtype(base);\n let p = path[i];\n if (typeof p !== \"string\" && typeof p !== \"number\") {\n p = \"\" + p;\n }\n if ((parentType === 0 /* Object */ || parentType === 1 /* Array */) && (p === \"__proto__\" || p === \"constructor\"))\n die(errorOffset + 3);\n if (typeof base === \"function\" && p === \"prototype\")\n die(errorOffset + 3);\n base = get(base, p);\n if (typeof base !== \"object\")\n die(errorOffset + 2, path.join(\"/\"));\n }\n const type = getArchtype(base);\n const value = deepClonePatchValue(patch.value);\n const key = path[path.length - 1];\n switch (op) {\n case REPLACE:\n switch (type) {\n case 2 /* Map */:\n return base.set(key, value);\n case 3 /* Set */:\n die(errorOffset);\n default:\n return base[key] = value;\n }\n case ADD:\n switch (type) {\n case 1 /* Array */:\n return key === \"-\" ? base.push(value) : base.splice(key, 0, value);\n case 2 /* Map */:\n return base.set(key, value);\n case 3 /* Set */:\n return base.add(value);\n default:\n return base[key] = value;\n }\n case REMOVE:\n switch (type) {\n case 1 /* Array */:\n return base.splice(key, 1);\n case 2 /* Map */:\n return base.delete(key);\n case 3 /* Set */:\n return base.delete(patch.value);\n default:\n return delete base[key];\n }\n default:\n die(errorOffset + 1, op);\n }\n });\n return draft;\n }\n function deepClonePatchValue(obj) {\n if (!isDraftable(obj))\n return obj;\n if (Array.isArray(obj))\n return obj.map(deepClonePatchValue);\n if (isMap(obj))\n return new Map(\n Array.from(obj.entries()).map(([k, v]) => [k, deepClonePatchValue(v)])\n );\n if (isSet(obj))\n return new Set(Array.from(obj).map(deepClonePatchValue));\n const cloned = Object.create(getPrototypeOf(obj));\n for (const key in obj)\n cloned[key] = deepClonePatchValue(obj[key]);\n if (has(obj, DRAFTABLE))\n cloned[DRAFTABLE] = obj[DRAFTABLE];\n return cloned;\n }\n function clonePatchValueIfNeeded(obj) {\n if (isDraft(obj)) {\n return deepClonePatchValue(obj);\n } else\n return obj;\n }\n loadPlugin(\"Patches\", {\n applyPatches_,\n generatePatches_,\n generateReplacementPatches_\n });\n}\n\n// src/plugins/mapset.ts\nfunction enableMapSet() {\n class DraftMap extends Map {\n constructor(target, parent) {\n super();\n this[DRAFT_STATE] = {\n type_: 2 /* Map */,\n parent_: parent,\n scope_: parent ? parent.scope_ : getCurrentScope(),\n modified_: false,\n finalized_: false,\n copy_: void 0,\n assigned_: void 0,\n base_: target,\n draft_: this,\n isManual_: false,\n revoked_: false\n };\n }\n get size() {\n return latest(this[DRAFT_STATE]).size;\n }\n has(key) {\n return latest(this[DRAFT_STATE]).has(key);\n }\n set(key, value) {\n const state = this[DRAFT_STATE];\n assertUnrevoked(state);\n if (!latest(state).has(key) || latest(state).get(key) !== value) {\n prepareMapCopy(state);\n markChanged(state);\n state.assigned_.set(key, true);\n state.copy_.set(key, value);\n state.assigned_.set(key, true);\n }\n return this;\n }\n delete(key) {\n if (!this.has(key)) {\n return false;\n }\n const state = this[DRAFT_STATE];\n assertUnrevoked(state);\n prepareMapCopy(state);\n markChanged(state);\n if (state.base_.has(key)) {\n state.assigned_.set(key, false);\n } else {\n state.assigned_.delete(key);\n }\n state.copy_.delete(key);\n return true;\n }\n clear() {\n const state = this[DRAFT_STATE];\n assertUnrevoked(state);\n if (latest(state).size) {\n prepareMapCopy(state);\n markChanged(state);\n state.assigned_ = /* @__PURE__ */ new Map();\n each(state.base_, (key) => {\n state.assigned_.set(key, false);\n });\n state.copy_.clear();\n }\n }\n forEach(cb, thisArg) {\n const state = this[DRAFT_STATE];\n latest(state).forEach((_value, key, _map) => {\n cb.call(thisArg, this.get(key), key, this);\n });\n }\n get(key) {\n const state = this[DRAFT_STATE];\n assertUnrevoked(state);\n const value = latest(state).get(key);\n if (state.finalized_ || !isDraftable(value)) {\n return value;\n }\n if (value !== state.base_.get(key)) {\n return value;\n }\n const draft = createProxy(value, state);\n prepareMapCopy(state);\n state.copy_.set(key, draft);\n return draft;\n }\n keys() {\n return latest(this[DRAFT_STATE]).keys();\n }\n values() {\n const iterator = this.keys();\n return {\n [Symbol.iterator]: () => this.values(),\n next: () => {\n const r = iterator.next();\n if (r.done)\n return r;\n const value = this.get(r.value);\n return {\n done: false,\n value\n };\n }\n };\n }\n entries() {\n const iterator = this.keys();\n return {\n [Symbol.iterator]: () => this.entries(),\n next: () => {\n const r = iterator.next();\n if (r.done)\n return r;\n const value = this.get(r.value);\n return {\n done: false,\n value: [r.value, value]\n };\n }\n };\n }\n [(DRAFT_STATE, Symbol.iterator)]() {\n return this.entries();\n }\n }\n function proxyMap_(target, parent) {\n return new DraftMap(target, parent);\n }\n function prepareMapCopy(state) {\n if (!state.copy_) {\n state.assigned_ = /* @__PURE__ */ new Map();\n state.copy_ = new Map(state.base_);\n }\n }\n class DraftSet extends Set {\n constructor(target, parent) {\n super();\n this[DRAFT_STATE] = {\n type_: 3 /* Set */,\n parent_: parent,\n scope_: parent ? parent.scope_ : getCurrentScope(),\n modified_: false,\n finalized_: false,\n copy_: void 0,\n base_: target,\n draft_: this,\n drafts_: /* @__PURE__ */ new Map(),\n revoked_: false,\n isManual_: false\n };\n }\n get size() {\n return latest(this[DRAFT_STATE]).size;\n }\n has(value) {\n const state = this[DRAFT_STATE];\n assertUnrevoked(state);\n if (!state.copy_) {\n return state.base_.has(value);\n }\n if (state.copy_.has(value))\n return true;\n if (state.drafts_.has(value) && state.copy_.has(state.drafts_.get(value)))\n return true;\n return false;\n }\n add(value) {\n const state = this[DRAFT_STATE];\n assertUnrevoked(state);\n if (!this.has(value)) {\n prepareSetCopy(state);\n markChanged(state);\n state.copy_.add(value);\n }\n return this;\n }\n delete(value) {\n if (!this.has(value)) {\n return false;\n }\n const state = this[DRAFT_STATE];\n assertUnrevoked(state);\n prepareSetCopy(state);\n markChanged(state);\n return state.copy_.delete(value) || (state.drafts_.has(value) ? state.copy_.delete(state.drafts_.get(value)) : (\n /* istanbul ignore next */\n false\n ));\n }\n clear() {\n const state = this[DRAFT_STATE];\n assertUnrevoked(state);\n if (latest(state).size) {\n prepareSetCopy(state);\n markChanged(state);\n state.copy_.clear();\n }\n }\n values() {\n const state = this[DRAFT_STATE];\n assertUnrevoked(state);\n prepareSetCopy(state);\n return state.copy_.values();\n }\n entries() {\n const state = this[DRAFT_STATE];\n assertUnrevoked(state);\n prepareSetCopy(state);\n return state.copy_.entries();\n }\n keys() {\n return this.values();\n }\n [(DRAFT_STATE, Symbol.iterator)]() {\n return this.values();\n }\n forEach(cb, thisArg) {\n const iterator = this.values();\n let result = iterator.next();\n while (!result.done) {\n cb.call(thisArg, result.value, result.value, this);\n result = iterator.next();\n }\n }\n }\n function proxySet_(target, parent) {\n return new DraftSet(target, parent);\n }\n function prepareSetCopy(state) {\n if (!state.copy_) {\n state.copy_ = /* @__PURE__ */ new Set();\n state.base_.forEach((value) => {\n if (isDraftable(value)) {\n const draft = createProxy(value, state);\n state.drafts_.set(value, draft);\n state.copy_.add(draft);\n } else {\n state.copy_.add(value);\n }\n });\n }\n }\n function assertUnrevoked(state) {\n if (state.revoked_)\n die(3, JSON.stringify(latest(state)));\n }\n loadPlugin(\"MapSet\", { proxyMap_, proxySet_ });\n}\n\n// src/immer.ts\nvar immer = new Immer2();\nvar produce = immer.produce;\nvar produceWithPatches = immer.produceWithPatches.bind(\n immer\n);\nvar setAutoFreeze = immer.setAutoFreeze.bind(immer);\nvar setUseStrictShallowCopy = immer.setUseStrictShallowCopy.bind(immer);\nvar applyPatches = immer.applyPatches.bind(immer);\nvar createDraft = immer.createDraft.bind(immer);\nvar finishDraft = immer.finishDraft.bind(immer);\nfunction castDraft(value) {\n return value;\n}\nfunction castImmutable(value) {\n return value;\n}\nexport {\n Immer2 as Immer,\n applyPatches,\n castDraft,\n castImmutable,\n createDraft,\n current,\n enableMapSet,\n enablePatches,\n finishDraft,\n freeze,\n DRAFTABLE as immerable,\n isDraft,\n isDraftable,\n NOTHING as nothing,\n original,\n produce,\n produceWithPatches,\n setAutoFreeze,\n setUseStrictShallowCopy\n};\n//# sourceMappingURL=immer.mjs.map","import { produce, Draft } from 'immer';\n\nexport function createState<T = unknown>(\n fn: (draft: Draft<T>, ...args: any[]) => void\n): (state: T, ...args: any[]) => T {\n return (state: T, ...args: any[]): T => {\n return produce(state, (draft) => {\n fn(draft, ...args);\n });\n };\n}\n"],"names":["root","factory","exports","module","define","amd","this","__webpack_require__","definition","key","o","Object","defineProperty","enumerable","get","obj","prop","prototype","hasOwnProperty","call","Symbol","toStringTag","value","NOTHING","for","DRAFTABLE","DRAFT_STATE","die","error","args","Error","getPrototypeOf","isDraft","isDraftable","isPlainObject","Array","isArray","constructor","isMap","isSet","objectCtorString","toString","proto","Ctor","Function","each","iter","getArchtype","Reflect","ownKeys","forEach","entry","index","thing","state","type_","has","set","propOrOldValue","t","add","target","Map","Set","latest","copy_","base_","shallowCopy","base","strict","slice","isPlain","descriptors","getOwnPropertyDescriptors","keys","i","length","desc","writable","configurable","create","assign","freeze","deep","isFrozen","clear","delete","dontMutateFrozenCollections","entries","currentScope","plugins","getPlugin","pluginKey","plugin","getCurrentScope","usePatchesInScope","scope","patchListener","patches_","inversePatches_","patchListener_","revokeScope","leaveScope","drafts_","revokeDraft","parent_","enterScope","immer2","immer_","canAutoFreeze_","unfinalizedDrafts_","draft","revoke_","revoked_","processResult","result","baseDraft","modified_","finalize","maybeFreeze","generateReplacementPatches_","rootScope","path","childValue","finalizeProperty","scope_","finalized_","resultEach","isSet2","generatePatches_","parentState","targetObject","rootPath","targetIsSet","res","assigned_","concat","autoFreeze_","propertyIsEnumerable","objectTraps","source","getDescriptorFromProto","draft_","readPropFromProto","peek","prepareCopy","createProxy","current2","currentState","x","y","markChanged","Number","isNaN","deleteProperty","getOwnPropertyDescriptor","owner","setPrototypeOf","arrayTraps","useStrictShallowCopy_","parent","proxyMap_","proxySet_","isManual_","traps","revoke","proxy","Proxy","revocable","createProxyProxy","push","currentImpl","copy","fn","arguments","apply","immer","config","produce","recipe","defaultBase","self","base2","hasError","p","ip","produceWithPatches","patches","inversePatches","autoFreeze","setAutoFreeze","useStrictShallowCopy","setUseStrictShallowCopy","createDraft","finishDraft","applyPatches","patch","op","applyPatchesImpl","applyPatches_","createState","bind"],"sourceRoot":""}
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
import app from './app'; // ADD: Global app instance access
|
|
2
|
+
// Type guard functions using the enhanced type system
|
|
3
|
+
function isComponentInstance(obj) {
|
|
4
|
+
return obj && typeof obj === 'object' && typeof obj.mount === 'function';
|
|
5
|
+
}
|
|
6
|
+
function isComponentConstructor(fn) {
|
|
7
|
+
return typeof fn === 'function' &&
|
|
8
|
+
fn.prototype &&
|
|
9
|
+
fn.prototype.constructor === fn &&
|
|
10
|
+
(fn.prototype.mount !== undefined ||
|
|
11
|
+
fn.prototype.state !== undefined ||
|
|
12
|
+
fn.prototype.view !== undefined);
|
|
13
|
+
}
|
|
14
|
+
function isFactoryFunction(fn) {
|
|
15
|
+
return typeof fn === 'function' && !isComponentConstructor(fn);
|
|
16
|
+
}
|
|
17
|
+
// Recursive function resolution with enhanced type checking
|
|
18
|
+
async function resolveComponent(component, maxDepth = 3) {
|
|
19
|
+
let resolved = component;
|
|
20
|
+
let depth = 0;
|
|
21
|
+
while (isFactoryFunction(resolved) && depth < maxDepth) {
|
|
22
|
+
try {
|
|
23
|
+
const result = await resolved();
|
|
24
|
+
if (result === resolved)
|
|
25
|
+
break; // Prevent infinite loops
|
|
26
|
+
resolved = result;
|
|
27
|
+
depth++;
|
|
28
|
+
}
|
|
29
|
+
catch (error) {
|
|
30
|
+
console.error(`Error executing component function: ${error}`);
|
|
31
|
+
break;
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
return resolved;
|
|
35
|
+
}
|
|
36
|
+
export default async (element, components) => {
|
|
37
|
+
for (const [route, component] of Object.entries(components)) {
|
|
38
|
+
if (!component || !route) {
|
|
39
|
+
console.error(`Invalid component configuration: component=${component}, route=${route}`);
|
|
40
|
+
continue;
|
|
41
|
+
}
|
|
42
|
+
// Check if it's a direct component instance
|
|
43
|
+
if (isComponentInstance(component)) {
|
|
44
|
+
const options = { route };
|
|
45
|
+
component.mount(element, options);
|
|
46
|
+
continue;
|
|
47
|
+
}
|
|
48
|
+
// Check if it's a component class constructor
|
|
49
|
+
if (isComponentConstructor(component)) {
|
|
50
|
+
const instance = new component();
|
|
51
|
+
const options = { route };
|
|
52
|
+
instance.mount(element, options);
|
|
53
|
+
continue;
|
|
54
|
+
}
|
|
55
|
+
// At this point it must be a function - resolve it
|
|
56
|
+
if (isFactoryFunction(component)) {
|
|
57
|
+
// Resolve the function to see what it returns
|
|
58
|
+
let resolved = await resolveComponent(component);
|
|
59
|
+
// Check if resolved result is a component instance
|
|
60
|
+
if (isComponentInstance(resolved)) {
|
|
61
|
+
const options = { route };
|
|
62
|
+
resolved.mount(element, options);
|
|
63
|
+
continue;
|
|
64
|
+
}
|
|
65
|
+
// Check if resolved result is a component constructor
|
|
66
|
+
if (isComponentConstructor(resolved)) {
|
|
67
|
+
const instance = new resolved();
|
|
68
|
+
const options = { route };
|
|
69
|
+
instance.mount(element, options);
|
|
70
|
+
continue;
|
|
71
|
+
}
|
|
72
|
+
// If resolved result is still a function or anything else, treat original as event handler with render wrapper
|
|
73
|
+
app.on(route, (...args) => {
|
|
74
|
+
const result = component(...args);
|
|
75
|
+
const target = typeof element === 'string'
|
|
76
|
+
? document.querySelector(element)
|
|
77
|
+
: element;
|
|
78
|
+
if (!target) {
|
|
79
|
+
console.error(`Element not found: ${element}`);
|
|
80
|
+
return;
|
|
81
|
+
}
|
|
82
|
+
return app.render(target, result);
|
|
83
|
+
});
|
|
84
|
+
continue;
|
|
85
|
+
}
|
|
86
|
+
// If we get here, it's an invalid component type
|
|
87
|
+
console.error(`Invalid component: component must be a class, instance, or function that returns a class/instance`);
|
|
88
|
+
}
|
|
89
|
+
};
|
|
90
|
+
//# sourceMappingURL=add-components.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"add-components.js","sourceRoot":"","sources":["../src/add-components.ts"],"names":[],"mappings":"AACA,OAAO,GAAG,MAAM,OAAO,CAAC,CAAC,kCAAkC;AAE3D,sDAAsD;AACtD,SAAS,mBAAmB,CAAC,GAAQ;IACnC,OAAO,GAAG,IAAI,OAAO,GAAG,KAAK,QAAQ,IAAI,OAAO,GAAG,CAAC,KAAK,KAAK,UAAU,CAAC;AAC3E,CAAC;AAED,SAAS,sBAAsB,CAAC,EAAO;IACrC,OAAO,OAAO,EAAE,KAAK,UAAU;QAC7B,EAAE,CAAC,SAAS;QACZ,EAAE,CAAC,SAAS,CAAC,WAAW,KAAK,EAAE;QAC/B,CAAC,EAAE,CAAC,SAAS,CAAC,KAAK,KAAK,SAAS;YAC/B,EAAE,CAAC,SAAS,CAAC,KAAK,KAAK,SAAS;YAChC,EAAE,CAAC,SAAS,CAAC,IAAI,KAAK,SAAS,CAAC,CAAC;AACvC,CAAC;AAED,SAAS,iBAAiB,CAAC,EAAO;IAChC,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AAuB,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;YACzD,CAAC,CAAC,CAAC;YACH,SAAS;QACX,CAAC;QAED,iDAAiD;QACjD,OAAO,CAAC,KAAK,CAAC,mGAAmG,CAAC,CAAC;IACrH,CAAC;AACH,CAAC,CAAA"}
|
package/esm/app.js
ADDED
|
@@ -0,0 +1,209 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Core AppRun application class and singleton instance
|
|
3
|
+
*
|
|
4
|
+
* This file provides:
|
|
5
|
+
* 1. App class - The core event system implementation with pub/sub capabilities
|
|
6
|
+
* - on(): Subscribe to events with options (once, delay, global)
|
|
7
|
+
* - off(): Unsubscribe from events with proper cleanup
|
|
8
|
+
* - run(): Publish events synchronously with error-event reporting
|
|
9
|
+
* - runAsync(): Publish events asynchronously with Promise support, returns handler values
|
|
10
|
+
*
|
|
11
|
+
* 2. Default app singleton - Global event bus instance
|
|
12
|
+
* - Created once and reused across the application
|
|
13
|
+
* - Stored in global scope (window/global) with version tracking
|
|
14
|
+
* - Prevents duplicate instances across different versions
|
|
15
|
+
*
|
|
16
|
+
* Features:
|
|
17
|
+
* - Event wildcards support with indexed wildcard subscriptions (events ending with '*')
|
|
18
|
+
* - Delayed event execution with subscription-owned timeout management
|
|
19
|
+
* - Once-only event subscriptions, including wildcard subscriptions
|
|
20
|
+
* - Async event handling with Promise.all
|
|
21
|
+
* - Central error event reporting with console fallback
|
|
22
|
+
* - Global event bus shared across components
|
|
23
|
+
* - Memory leak prevention with proper cleanup
|
|
24
|
+
*
|
|
25
|
+
* Type Safety Improvements (v3.35.1):
|
|
26
|
+
* - Added validation for event handler functions
|
|
27
|
+
* - Enhanced error handling in event execution
|
|
28
|
+
* - Improved null checks in delayed event handling
|
|
29
|
+
* - Better error reporting for invalid handlers
|
|
30
|
+
*
|
|
31
|
+
* Usage:
|
|
32
|
+
* ```ts
|
|
33
|
+
* // Subscribe to events
|
|
34
|
+
* app.on('event-name', (state, ...args) => {
|
|
35
|
+
* // Handle event
|
|
36
|
+
* });
|
|
37
|
+
*
|
|
38
|
+
* // Publish events (fire-and-forget)
|
|
39
|
+
* app.run('event-name', ...args);
|
|
40
|
+
*
|
|
41
|
+
* // Get return values from event handlers
|
|
42
|
+
* app.runAsync('event-name', data).then(results => {
|
|
43
|
+
* // Handle results array
|
|
44
|
+
* });
|
|
45
|
+
* ```
|
|
46
|
+
*/
|
|
47
|
+
import { APPRUN_VERSION_GLOBAL } from './version';
|
|
48
|
+
export class App {
|
|
49
|
+
constructor() {
|
|
50
|
+
this._reporting_error = false;
|
|
51
|
+
this._events = {};
|
|
52
|
+
this._wildcard_events = [];
|
|
53
|
+
}
|
|
54
|
+
on(name, fn, options = {}) {
|
|
55
|
+
this._events[name] = this._events[name] || [];
|
|
56
|
+
const sub = { fn, options };
|
|
57
|
+
this._events[name].push(sub);
|
|
58
|
+
if (name.endsWith('*')) {
|
|
59
|
+
this._wildcard_events.push({ name, prefix: name.replace('*', ''), sub });
|
|
60
|
+
this._wildcard_events.sort((a, b) => b.name.length - a.name.length);
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
off(name, fn) {
|
|
64
|
+
const subscribers = this._events[name] || [];
|
|
65
|
+
this._events[name] = subscribers.filter((sub) => sub.fn !== fn);
|
|
66
|
+
if (name.endsWith('*')) {
|
|
67
|
+
this._wildcard_events = this._wildcard_events.filter(item => !(item.name === name && item.sub.fn === fn));
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
find(name) {
|
|
71
|
+
return this._events[name];
|
|
72
|
+
}
|
|
73
|
+
run(name, ...args) {
|
|
74
|
+
const subscribers = this.getSubscribers(name, this._events);
|
|
75
|
+
if (this.debug)
|
|
76
|
+
console.assert(subscribers && subscribers.length > 0, 'No subscriber for event: ' + name);
|
|
77
|
+
subscribers.forEach((sub) => {
|
|
78
|
+
const { fn, options } = sub;
|
|
79
|
+
if (!fn || typeof fn !== 'function') {
|
|
80
|
+
console.error(`AppRun event handler for '${name}' is not a function:`, fn);
|
|
81
|
+
return false;
|
|
82
|
+
}
|
|
83
|
+
if (options.delay) {
|
|
84
|
+
this.delay(name, sub, args);
|
|
85
|
+
}
|
|
86
|
+
else {
|
|
87
|
+
try {
|
|
88
|
+
Object.keys(options).length > 0 ? fn.apply(this, [...args, options]) : fn.apply(this, args);
|
|
89
|
+
}
|
|
90
|
+
catch (error) {
|
|
91
|
+
this.reportError(name, error, { phase: 'run', args });
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
});
|
|
95
|
+
return subscribers.length;
|
|
96
|
+
}
|
|
97
|
+
once(name, fn, options = {}) {
|
|
98
|
+
this.on(name, fn, { ...options, once: true });
|
|
99
|
+
}
|
|
100
|
+
delay(name, sub, args) {
|
|
101
|
+
const source = sub._source || sub;
|
|
102
|
+
const { fn, options } = sub;
|
|
103
|
+
if (source._t)
|
|
104
|
+
clearTimeout(source._t);
|
|
105
|
+
source._t = setTimeout(() => {
|
|
106
|
+
clearTimeout(source._t);
|
|
107
|
+
source._t = null;
|
|
108
|
+
try {
|
|
109
|
+
Object.keys(options).length > 0 ? fn.apply(this, [...args, options]) : fn.apply(this, args);
|
|
110
|
+
}
|
|
111
|
+
catch (error) {
|
|
112
|
+
this.reportError(name, error, { phase: 'delay', args });
|
|
113
|
+
}
|
|
114
|
+
}, options.delay);
|
|
115
|
+
}
|
|
116
|
+
runAsync(name, ...args) {
|
|
117
|
+
const subscribers = this.getSubscribers(name, this._events);
|
|
118
|
+
if (this.debug)
|
|
119
|
+
console.assert(subscribers && subscribers.length > 0, 'No subscriber for event: ' + name);
|
|
120
|
+
const promises = subscribers.map(sub => {
|
|
121
|
+
const { fn, options } = sub;
|
|
122
|
+
if (!fn || typeof fn !== 'function') {
|
|
123
|
+
console.error(`AppRun async event handler for '${name}' is not a function:`, fn);
|
|
124
|
+
return Promise.resolve(null);
|
|
125
|
+
}
|
|
126
|
+
try {
|
|
127
|
+
const result = Object.keys(options).length > 0 ? fn.apply(this, [...args, options]) : fn.apply(this, args);
|
|
128
|
+
return Promise.resolve(result).catch(error => {
|
|
129
|
+
this.reportError(name, error, { phase: 'runAsync', args });
|
|
130
|
+
return Promise.reject(error);
|
|
131
|
+
});
|
|
132
|
+
}
|
|
133
|
+
catch (error) {
|
|
134
|
+
this.reportError(name, error, { phase: 'runAsync', args });
|
|
135
|
+
return Promise.reject(error);
|
|
136
|
+
}
|
|
137
|
+
});
|
|
138
|
+
return Promise.all(promises);
|
|
139
|
+
}
|
|
140
|
+
reportError(name, error, context = {}) {
|
|
141
|
+
const payload = { event: name, error, app: this, ...context };
|
|
142
|
+
const errorSubscribers = name === 'error' || this._reporting_error ? [] : this.getSubscribers('error', this._events);
|
|
143
|
+
if (errorSubscribers.length > 0) {
|
|
144
|
+
this._reporting_error = true;
|
|
145
|
+
try {
|
|
146
|
+
errorSubscribers.forEach(sub => {
|
|
147
|
+
try {
|
|
148
|
+
sub.fn.call(this, payload);
|
|
149
|
+
}
|
|
150
|
+
catch (errorHandlerError) {
|
|
151
|
+
console.error(`Error in error event handler:`, errorHandlerError);
|
|
152
|
+
}
|
|
153
|
+
});
|
|
154
|
+
}
|
|
155
|
+
finally {
|
|
156
|
+
this._reporting_error = false;
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
else if (context.phase === 'delay') {
|
|
160
|
+
console.error(`Error in delayed event handler for '${name}':`, error);
|
|
161
|
+
}
|
|
162
|
+
else if (context.phase === 'runAsync') {
|
|
163
|
+
console.error(`Error in async event handler for '${name}':`, error);
|
|
164
|
+
}
|
|
165
|
+
else {
|
|
166
|
+
console.error(`Error in event handler for '${name}':`, error);
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
removeOnceWildcardSubscriber(evt, sub) {
|
|
170
|
+
this._events[evt] = (this._events[evt] || []).filter(item => item !== sub);
|
|
171
|
+
this._wildcard_events = this._wildcard_events.filter(item => item.sub !== sub);
|
|
172
|
+
}
|
|
173
|
+
getSubscribers(name, events) {
|
|
174
|
+
const subscribers = events[name] || [];
|
|
175
|
+
const calls = subscribers.slice();
|
|
176
|
+
// Update the list of subscribers by pulling out those which will run once.
|
|
177
|
+
// We must do this update prior to running any of the events in case they
|
|
178
|
+
// cause additional events to be turned off or on.
|
|
179
|
+
events[name] = subscribers.filter((sub) => {
|
|
180
|
+
return !sub.options.once;
|
|
181
|
+
});
|
|
182
|
+
this._wildcard_events.filter(({ name: evt, prefix }) => evt !== name && name.startsWith(prefix))
|
|
183
|
+
.forEach(({ name: evt, sub }) => {
|
|
184
|
+
if (sub.options.once)
|
|
185
|
+
this.removeOnceWildcardSubscriber(evt, sub);
|
|
186
|
+
calls.push({
|
|
187
|
+
...sub,
|
|
188
|
+
_source: sub,
|
|
189
|
+
options: { ...sub.options, event: name }
|
|
190
|
+
});
|
|
191
|
+
});
|
|
192
|
+
return calls;
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
const AppRunVersions = APPRUN_VERSION_GLOBAL;
|
|
196
|
+
let _app;
|
|
197
|
+
const root = (typeof window !== 'undefined' ? window :
|
|
198
|
+
typeof global !== 'undefined' ? global :
|
|
199
|
+
typeof self !== 'undefined' ? self : {});
|
|
200
|
+
if (root.app && root._AppRunVersions) {
|
|
201
|
+
_app = root.app;
|
|
202
|
+
}
|
|
203
|
+
else {
|
|
204
|
+
_app = new App();
|
|
205
|
+
root.app = _app;
|
|
206
|
+
root._AppRunVersions = AppRunVersions;
|
|
207
|
+
}
|
|
208
|
+
export default _app;
|
|
209
|
+
//# sourceMappingURL=app.js.map
|
package/esm/app.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"app.js","sourceRoot":"","sources":["../src/app.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6CG;AAGH,OAAO,EAAE,qBAAqB,EAAE,MAAM,WAAW,CAAA;AAMjD,MAAM,OAAO,GAAG;IAMd;QAFQ,qBAAgB,GAAG,KAAK,CA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EAAE,GAAG,EAAE,GAAG,EAAE,EAAE,EAAE;YAC9B,IAAI,GAAG,CAAC,OAAO,CAAC,IAAI;gBAAE,IAAI,CAAC,4BAA4B,CAAC,GAAG,EAAE,GAAG,CAAC,CAAC;YAClE,KAAK,CAAC,IAAI,CAAC;gBACT,GAAG,GAAG;gBACN,OAAO,EAAE,GAAG;gBACZ,OAAO,EAAE,EAAE,GAAG,GAAG,CAAC,OAAO,EAAE,KAAK,EAAE,IAAI,EAAE;aACzC,CAAC,CAAC;QACL,CAAC,CAAC,CAAC;QACL,OAAO,KAAK,CAAC;IACf,CAAC;CACF;AAED,MAAM,cAAc,GAAG,qBAAqB,CAAC;AAC7C,IAAI,IAAS,CAAC;AACd,MAAM,IAAI,GAAG,CAAC,OAAO,MAAM,KAAK,WAAW,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC;IACpD,OAAO,MAAM,KAAK,WAAW,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC;QACtC,OAAO,IAAI,KAAK,WAAW,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAQ,CAAC;AAEpD,IAAI,IAAI,CAAC,GAAG,IAAI,IAAI,CAAC,eAAe,EAAE,CAAC;IACrC,IAAI,GAAG,IAAI,CAAC,GAAG,CAAC;AAClB,CAAC;KAAM,CAAC;IACN,IAAI,GAAG,IAAI,GAAG,EAAE,CAAC;IACjB,IAAI,CAAC,GAAG,GAAG,IAAI,CAAC;IAChB,IAAI,CAAC,eAAe,GAAG,cAAc,CAAC;AACxC,CAAC;AACD,eAAe,IAAI,CAAC"}
|
|
@@ -0,0 +1,170 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Inline AppRun code playground component.
|
|
3
|
+
*
|
|
4
|
+
* Renders editable source alongside an iframe preview and keeps DOM element
|
|
5
|
+
* access explicit now that Component.element is concretely typed.
|
|
6
|
+
*/
|
|
7
|
+
import { app, Component } from './apprun';
|
|
8
|
+
const styles = `
|
|
9
|
+
.CodeMirror, .apprun-play iframe {
|
|
10
|
+
height: 100%;
|
|
11
|
+
border: dotted gray 1px;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
.apprun-play {
|
|
15
|
+
height: 100%;
|
|
16
|
+
display: flex;
|
|
17
|
+
font-size: 1.1rem;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
.apprun-play .col {
|
|
21
|
+
margin: 2px;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
.apprun-play .editor, .apprun-play .preview {
|
|
25
|
+
width: 100%;
|
|
26
|
+
height: 100%;
|
|
27
|
+
}
|
|
28
|
+
`;
|
|
29
|
+
const encodeHTML = code => {
|
|
30
|
+
return code.replace(/&/g, '&')
|
|
31
|
+
.replace(/</g, '<')
|
|
32
|
+
.replace(/>/g, '>')
|
|
33
|
+
.replace(/"/g, '"')
|
|
34
|
+
.replace(/'/g, ''');
|
|
35
|
+
};
|
|
36
|
+
const code_html = code => `<!DOCTYPE html>
|
|
37
|
+
<html lang="en">
|
|
38
|
+
<head>
|
|
39
|
+
<meta charset="UTF-8">
|
|
40
|
+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
41
|
+
<meta http-equiv="X-UA-Compatible" content="ie=edge">
|
|
42
|
+
<title>AppRun Playground</title>
|
|
43
|
+
<style>
|
|
44
|
+
body {
|
|
45
|
+
font-family: "Benton Sans", "Helvetica Neue", helvetica, arial, sans-serif;
|
|
46
|
+
margin: 2em;
|
|
47
|
+
}
|
|
48
|
+
</style>
|
|
49
|
+
<script src="https://cdn.jsdelivr.net/npm/typescript@latest"></script>
|
|
50
|
+
<script src="dist/apprun-html.js"></script>
|
|
51
|
+
</head>
|
|
52
|
+
<body>
|
|
53
|
+
<pre id="code" style="display:none">${encodeHTML(code)}</pre>
|
|
54
|
+
<script type="module">
|
|
55
|
+
const code = document.getElementById('code').innerText;
|
|
56
|
+
const compiled = ts.transpileModule(code, {
|
|
57
|
+
compilerOptions: {
|
|
58
|
+
"jsx": "react",
|
|
59
|
+
"jsxFactory": "app.h",
|
|
60
|
+
"jsxFragmentFactory": "app.Fragment",
|
|
61
|
+
"target": "es2020",
|
|
62
|
+
"module": "esnext",
|
|
63
|
+
},
|
|
64
|
+
reportDiagnostics: true,
|
|
65
|
+
});
|
|
66
|
+
|
|
67
|
+
if (compiled.diagnostics && compiled.diagnostics.length) {
|
|
68
|
+
const pre = document.createElement('pre');
|
|
69
|
+
pre.style = 'font-size: 10px;';
|
|
70
|
+
pre.innerText = compiled.diagnostics.map(d => {
|
|
71
|
+
const start = d.start;
|
|
72
|
+
const end = d.start + d.length;
|
|
73
|
+
const line = code.substring(0, end).split('\\n').length;
|
|
74
|
+
const column = code.substring(0, end).split('\\n').pop().length;
|
|
75
|
+
return \`Line: \${line}, Column: \${column}, \${d.messageText}\`;
|
|
76
|
+
}).join('\\n');
|
|
77
|
+
document.body.appendChild(pre);
|
|
78
|
+
} else {
|
|
79
|
+
window.onerror = function () {
|
|
80
|
+
const pre = document.createElement('pre');
|
|
81
|
+
pre.style = 'font-size: 10px;';
|
|
82
|
+
pre.innerText = compiled.outputText;;
|
|
83
|
+
document.body.appendChild(pre);
|
|
84
|
+
};
|
|
85
|
+
const script = document.createElement('script');
|
|
86
|
+
script.type = 'module';
|
|
87
|
+
script.text = compiled.outputText;
|
|
88
|
+
document.body.appendChild(script);
|
|
89
|
+
}
|
|
90
|
+
</script>
|
|
91
|
+
</body>
|
|
92
|
+
</html>`;
|
|
93
|
+
class Play extends Component {
|
|
94
|
+
constructor() {
|
|
95
|
+
super(...arguments);
|
|
96
|
+
this.view = ({ code, hide_code }) => {
|
|
97
|
+
return app.h(app.Fragment, null,
|
|
98
|
+
app.h("style", null, styles),
|
|
99
|
+
hide_code ?
|
|
100
|
+
app.h("div", { class: "apprun-play" },
|
|
101
|
+
app.h("iframe", { class: "preview" }))
|
|
102
|
+
:
|
|
103
|
+
app.h("div", { class: "apprun-play" },
|
|
104
|
+
app.h("div", { class: "col", style: "width:75%" },
|
|
105
|
+
app.h("textarea", { class: "editor" }, code)),
|
|
106
|
+
app.h("div", { class: "col", style: "flex:1" },
|
|
107
|
+
app.h("iframe", { class: "preview" }))));
|
|
108
|
+
};
|
|
109
|
+
this.mounted = props => {
|
|
110
|
+
const element = this.element;
|
|
111
|
+
const code_id = props['code-id'];
|
|
112
|
+
const hide_code = props['hide-code'];
|
|
113
|
+
const code_width = props['code-width'];
|
|
114
|
+
let code_area;
|
|
115
|
+
if (code_id) {
|
|
116
|
+
code_area = document.getElementById(code_id);
|
|
117
|
+
}
|
|
118
|
+
else {
|
|
119
|
+
code_area = element.previousElementSibling ||
|
|
120
|
+
element.parentElement.previousElementSibling;
|
|
121
|
+
}
|
|
122
|
+
const code = code_area?.innerText // from div
|
|
123
|
+
|| code_area?.value // from textarea
|
|
124
|
+
|| element.textContent; // from child node
|
|
125
|
+
if (code_area)
|
|
126
|
+
code_area.style.display = 'none';
|
|
127
|
+
return { code, hide_code, code_width };
|
|
128
|
+
};
|
|
129
|
+
this.rendered = ({ code, hide_code, code_width }) => {
|
|
130
|
+
const element = this.element;
|
|
131
|
+
const textarea = element.querySelector(".apprun-play .editor");
|
|
132
|
+
let iframe = element.querySelector('.apprun-play .preview');
|
|
133
|
+
if (!iframe || !textarea)
|
|
134
|
+
return;
|
|
135
|
+
const run_code = code => {
|
|
136
|
+
const iframe_clone = iframe.cloneNode();
|
|
137
|
+
iframe.parentNode?.replaceChild(iframe_clone, iframe);
|
|
138
|
+
iframe = iframe_clone;
|
|
139
|
+
const doc = iframe.contentWindow?.document;
|
|
140
|
+
if (!doc)
|
|
141
|
+
return;
|
|
142
|
+
doc.open();
|
|
143
|
+
if (code.indexOf('<html') >= 0)
|
|
144
|
+
doc.write(code);
|
|
145
|
+
else
|
|
146
|
+
doc.write(code_html(code));
|
|
147
|
+
doc.close();
|
|
148
|
+
};
|
|
149
|
+
if (code)
|
|
150
|
+
run_code(code);
|
|
151
|
+
if (hide_code || !textarea)
|
|
152
|
+
return;
|
|
153
|
+
if (code_width)
|
|
154
|
+
textarea.parentElement.style.width = code_width;
|
|
155
|
+
if (typeof CodeMirror === 'undefined') {
|
|
156
|
+
textarea.onkeyup = () => run_code(textarea.value);
|
|
157
|
+
}
|
|
158
|
+
else {
|
|
159
|
+
const editor = CodeMirror.fromTextArea(textarea, {
|
|
160
|
+
lineNumbers: true,
|
|
161
|
+
mode: 'jsx'
|
|
162
|
+
});
|
|
163
|
+
editor.setValue(code);
|
|
164
|
+
editor.on('change', (cm) => run_code(cm.getValue()));
|
|
165
|
+
}
|
|
166
|
+
};
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
app.webComponent('apprun-code', Play);
|
|
170
|
+
//# sourceMappingURL=apprun-code.js.map
|