@aerogel/core 0.0.0-next.5436b378dff7e64898bb7046afa2d5d574255b54

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.
Files changed (70) hide show
  1. package/.eslintrc.js +3 -0
  2. package/dist/aerogel-core.cjs.js +2 -0
  3. package/dist/aerogel-core.cjs.js.map +1 -0
  4. package/dist/aerogel-core.d.ts +609 -0
  5. package/dist/aerogel-core.esm.js +2 -0
  6. package/dist/aerogel-core.esm.js.map +1 -0
  7. package/noeldemartin.config.js +2 -0
  8. package/package.json +49 -0
  9. package/src/bootstrap/bootstrap.test.ts +113 -0
  10. package/src/bootstrap/hooks.ts +19 -0
  11. package/src/bootstrap/index.ts +36 -0
  12. package/src/bootstrap/options.ts +1 -0
  13. package/src/components/AGAppLayout.vue +11 -0
  14. package/src/components/AGAppOverlays.vue +39 -0
  15. package/src/components/basic/AGMarkdown.vue +20 -0
  16. package/src/components/basic/index.ts +3 -0
  17. package/src/components/forms/AGButton.vue +11 -0
  18. package/src/components/forms/AGForm.vue +26 -0
  19. package/src/components/forms/AGInput.vue +32 -0
  20. package/src/components/forms/index.ts +5 -0
  21. package/src/components/headless/forms/AGHeadlessButton.vue +51 -0
  22. package/src/components/headless/forms/AGHeadlessInput.ts +8 -0
  23. package/src/components/headless/forms/AGHeadlessInput.vue +54 -0
  24. package/src/components/headless/forms/AGHeadlessInputError.vue +22 -0
  25. package/src/components/headless/forms/AGHeadlessInputInput.vue +29 -0
  26. package/src/components/headless/forms/index.ts +4 -0
  27. package/src/components/headless/index.ts +2 -0
  28. package/src/components/headless/modals/AGHeadlessModal.ts +7 -0
  29. package/src/components/headless/modals/AGHeadlessModal.vue +84 -0
  30. package/src/components/headless/modals/AGHeadlessModalPanel.vue +20 -0
  31. package/src/components/headless/modals/AGHeadlessModalTitle.vue +13 -0
  32. package/src/components/headless/modals/index.ts +6 -0
  33. package/src/components/index.ts +8 -0
  34. package/src/components/modals/AGAlertModal.vue +15 -0
  35. package/src/components/modals/AGModal.ts +6 -0
  36. package/src/components/modals/AGModal.vue +18 -0
  37. package/src/components/modals/AGModalContext.ts +8 -0
  38. package/src/components/modals/AGModalContext.vue +22 -0
  39. package/src/components/modals/index.ts +5 -0
  40. package/src/directives/index.ts +13 -0
  41. package/src/directives/initial-focus.ts +11 -0
  42. package/src/errors/ServiceBootError.ts +9 -0
  43. package/src/forms/Form.test.ts +37 -0
  44. package/src/forms/Form.ts +154 -0
  45. package/src/forms/composition.ts +6 -0
  46. package/src/forms/index.ts +3 -0
  47. package/src/forms/utils.ts +36 -0
  48. package/src/lang/Lang.ts +21 -0
  49. package/src/lang/helpers.ts +5 -0
  50. package/src/lang/index.ts +89 -0
  51. package/src/main.ts +7 -0
  52. package/src/models/index.ts +18 -0
  53. package/src/routing/index.ts +33 -0
  54. package/src/services/Events.ts +85 -0
  55. package/src/services/Service.ts +91 -0
  56. package/src/services/index.ts +35 -0
  57. package/src/testing/stubs/lang/en.yaml +1 -0
  58. package/src/testing/stubs/models/User.ts +3 -0
  59. package/src/types/shims.d.ts +7 -0
  60. package/src/types/ts-reset.d.ts +1 -0
  61. package/src/types/vite.d.ts +3 -0
  62. package/src/ui/UI.state.ts +26 -0
  63. package/src/ui/UI.ts +118 -0
  64. package/src/ui/index.ts +37 -0
  65. package/src/utils/composition/events.ts +23 -0
  66. package/src/utils/index.ts +1 -0
  67. package/src/utils/markdown.ts +12 -0
  68. package/src/utils/vue.ts +144 -0
  69. package/tsconfig.json +19 -0
  70. package/vite.config.ts +17 -0
@@ -0,0 +1,2 @@
1
+ import"core-js/modules/esnext.async-iterator.map.js";import"core-js/modules/esnext.iterator.map.js";import{ref as e,inject as t,reactive as s,markRaw as a,nextTick as r,onUnmounted as o,defineComponent as n,toRef as l,openBlock as i,createBlock as u,unref as d,withCtx as c,renderSlot as m,provide as p,resolveDynamicComponent as f,normalizeProps as h,guardReactiveProps as v,computed as _,createCommentVNode as g,createElementVNode as y,createVNode as b,h as A,createApp as x,createElementBlock as w,Fragment as j,withModifiers as G,readonly as k,toDisplayString as M,mergeProps as $}from"vue";import"core-js/modules/esnext.async-iterator.for-each.js";import"core-js/modules/esnext.iterator.constructor.js";import"core-js/modules/esnext.iterator.for-each.js";import{fail as I,JSError as S,MagicObject as C,PromisedValue as H,facade as O,arr as P,tap as E,stringMatch as q,uuid as B,objectWithoutEmpty as F}from"@noeldemartin/utils";import"core-js/modules/esnext.async-iterator.reduce.js";import"core-js/modules/esnext.iterator.reduce.js";import{useI18n as L,createI18n as V}from"vue-i18n";import T from"@babel/runtime/helpers/esm/defineProperty";import{setEngine as N,IndexedDBEngine as D,bootModelsFromViteGlob as z}from"soukai";import{createRouter as K,createWebHistory as Q}from"vue-router";import"core-js/modules/esnext.string.at.js";import"core-js/modules/esnext.async-iterator.filter.js";import"core-js/modules/esnext.iterator.filter.js";import{Dialog as R,DialogPanel as U,DialogTitle as J}from"@headlessui/vue";import W from"dompurify";import{marked as X}from"marked";import"core-js/modules/esnext.async-iterator.some.js";import"core-js/modules/esnext.iterator.some.js";const Y=[];function Z(e){return{type:Array,default:e??(()=>[])}}function ee(){return{type:Boolean,default:arguments.length>0&&void 0!==arguments[0]&&arguments[0]}}function te(){return e()}function se(e){return e}function ae(e,t){const s=Object.values(e);return{type:String,default:t??s[0]??null,validator:e=>s.includes(e)}}function re(e){const a=t(e);return a?s(a):void 0}function oe(e,t){return re(e)??I(t??`Could not resolve '${e}' injection key`)}function ne(e,s){return t(e)??I(s??`Could not resolve '${e}' injection key`)}function le(e){return{type:e,default:null}}function ie(){return{type:Number,default:arguments.length>0&&void 0!==arguments[0]?arguments[0]:null}}function ue(){return{type:Object,default:arguments.length>0&&void 0!==arguments[0]?arguments[0]:null}}function de(){return{type:Array,required:!0}}function ce(e){const t=Object.values(e);return{type:String,required:!0,validator:e=>t.includes(e)}}function me(e){return{type:e,required:!0}}function pe(){return{type:Number,required:!0}}function fe(){return{type:Object,required:!0}}function he(){return{type:String,required:!0}}function ve(){return{type:String,default:arguments.length>0&&void 0!==arguments[0]?arguments[0]:null}}const _e={"initial-focus":{mounted(e,t){let{value:s}=t;!1!==s&&e.focus()}}};var ge=async e=>{Object.entries(_e).forEach((t=>{let[s,a]=t;return e.directive(s,a)}))};class ServiceBootError extends S{constructor(e,t){super(`Service '${e}' failed booting`,{cause:t})}}function ye(e){return class extends be{getInitialState(){return e.initialState}}}class be extends C{constructor(){super(),T(this,"_namespace",void 0),T(this,"_booted",void 0),T(this,"_state",void 0),this._namespace=new.target.name,this._booted=new H,this._state=s(this.getInitialState())}get booted(){return this._booted}launch(e){const handleError=e=>this._booted.reject(new ServiceBootError(this._namespace,e));this._namespace=e??this._namespace;try{this.boot().then((()=>this._booted.resolve())).catch(handleError)}catch(e){handleError(e)}return this._booted}__get(e){return this.hasState(e)?this.getState(e):super.__get(e)}__set(e,t){this.setState({[e]:t})}hasState(e){return e in this._state}getState(e){return e?this._state[e]:this._state}setState(e){Object.assign(this._state,e)}getInitialState(){return{}}async boot(){}}class Ae extends be{constructor(){super(...arguments),T(this,"listeners",{})}async emit(e,t){const s=[...this.listeners[e]??[]];await Promise.all(s.map((e=>e(t)))??[])}on(e,t){return(this.listeners[e]??=P([])).push(t),()=>this.off(e,t)}once(e,t){let s=null;return E((()=>s&&this.off(e,s)),(a=>{(this.listeners[e]??=P([])).push(s=function(){return a(),t(...arguments)})}))}off(e,t){const s=this.listeners[e];s&&(s.remove(t),s.isEmpty()&&delete this.listeners[e])}}var xe=O(new Ae);const we={$events:xe};async function je(e,t){await Promise.all(Object.entries(t).map((async e=>{let[t,s]=e;await s.launch(t.slice(1)).catch((e=>console.error(e)))}))),Object.assign(e.config.globalProperties,t)}var Ge=e=>je(e,we);var ke=O(new class extends be{constructor(){super(...arguments),T(this,"i18n",void 0)}setup(){this.i18n=L()}translate(e){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};return this.i18n?.t(e,t)??e}});function Me(e){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};return ke.translate(e,t)}const $e={$lang:ke};async function Ie(e){const t=e.defaultLocale??"en",s=e.fallbackLocale??"en",a=function(e){return Object.entries(e).reduce(((e,t)=>{let[s,a]=t;const r=q(s,/.*\/lang\/(.+)\.yaml/)?.[1];return r&&(e[r]=()=>a().then((e=>{let{default:t}=e;return t}))),e}),{})}(e.messages),r=a[t]??I(`Missing messages for '${t}' locale`),o={[t]:await r()};return V({locale:t,fallbackLocale:s,messages:o})}var Se=async(e,t)=>{const s=function(e){return e.lang?e.lang:e.langMessages?{messages:e.langMessages}:null}(t);if(!s)return;var a;a=()=>ke.setup(),Y.push(a);const r=await Ie(s);e.use(r),await je(e,$e)},Ce=async(e,t)=>{t.models&&(N(new D),z(t.models))};var He=async(e,t)=>{if(!t.routes)return;const s=function(e){return K({history:Q(e.basePath),routes:e.routes})}({routes:t.routes,basePath:t.basePath??__AG_BASE_PATH});e.use(s)},Oe=ye({initialState:{modals:[]}});const Pe={AlertModal:"alert-modal"};var Ee=O(new class extends Oe{constructor(){super(...arguments),T(this,"modalCallbacks",{}),T(this,"components",{})}alert(e){this.openModal(this.requireComponent(Pe.AlertModal),{message:e})}registerComponent(e,t){this.components[e]=t}async openModal(e,t){const s=B(),o={},n={id:s,properties:t??{},component:a(e),beforeClose:new Promise((e=>o.willClose=e)),afterClose:new Promise((e=>o.closed=e))},l=this.modals.at(-1),i=this.modals.concat(n);return this.modalCallbacks[n.id]=o,this.setState({modals:i}),await r(),await(l&&xe.emit("hide-modal",{id:l.id})),await Promise.all([l||xe.emit("show-overlays-backdrop"),xe.emit("show-modal",{id:n.id})]),n}async closeModal(e,t){await xe.emit("close-modal",{id:e,result:t})}async boot(){await super.boot(),this.watchModalEvents()}requireComponent(e){return this.components[e]??I(`UI Component '${e}' is not defined!`)}watchModalEvents(){xe.on("modal-will-close",(e=>{let{modal:t,result:s}=e;this.modalCallbacks[t.id]?.willClose?.(s),1===this.modals.length&&xe.emit("hide-overlays-backdrop")})),xe.on("modal-closed",(async e=>{let{modal:t,result:s}=e;this.setState({modals:this.modals.filter((e=>e.id!==t.id))}),this.modalCallbacks[t.id]?.closed?.(s),delete this.modalCallbacks[t.id];const a=this.modals.at(-1);await(a&&xe.emit("show-modal",{id:a.id}))}))}});function qe(e,t){const s=xe.on(e,t);o((()=>s()))}var Be=n({__name:"AGHeadlessModal",props:{cancellable:ee(!0)},setup(t,{expose:s}){const a=t,r=e(null),o=e(!0),n=e(!1),{modal:p}=oe("modal");async function f(){r.value?.$el&&(o.value=!0)}async function h(e){n.value||(xe.emit("modal-will-close",{modal:p,result:e}),await f(),n.value=!0,xe.emit("modal-closed",{modal:p,result:e}))}return qe("close-modal",(async({id:e,result:t})=>{e===p.id&&await h(t)})),qe("hide-modal",(async({id:e})=>{e===p.id&&await f()})),qe("show-modal",(async({id:e})=>{e===p.id&&await async function(){r.value?.$el&&(o.value=!1)}()})),s({close:h,cancellable:l(a,"cancellable")}),(e,s)=>(i(),u(d(R),{ref_key:"$root",ref:r,open:!0,onClose:s[0]||(s[0]=e=>t.cancellable&&h())},{default:c((()=>[m(e.$slots,"default",{close:h})])),_:3},512))}});Be.__file="src/components/headless/modals/AGHeadlessModal.vue";var Fe=n({__name:"AGModalContext",props:{modal:fe(),childIndex:pe()},setup(e){const t=e;return p("modal",{modal:l(t,"modal"),childIndex:l(t,"childIndex")}),(t,s)=>(i(),u(f(e.modal.component),h(v(e.modal.properties)),null,16))}});Fe.__file="src/components/modals/AGModalContext.vue";var Le=n({__name:"AGHeadlessModalPanel",setup(e){const t=oe("modal"),s=_((()=>Ee.modals[t.childIndex]??null));return(e,a)=>(i(),u(d(U),null,{default:c((()=>[m(e.$slots,"default"),s.value?(i(),u(Fe,{key:0,"child-index":d(t).childIndex+1,modal:s.value},null,8,["child-index","modal"])):g("v-if",!0)])),_:3}))}});Le.__file="src/components/headless/modals/AGHeadlessModalPanel.vue";const Ve={class:"fixed inset-0 flex items-center justify-center"},Te={class:"flex max-h-full flex-col overflow-auto p-4"};var Ne=n({__name:"AGModal",setup:e=>(e,t)=>(i(),u(Be,{class:"relative z-50"},{default:c((({close:t})=>[y("div",Ve,[b(Le,{class:"flex max-h-full max-w-full flex-col overflow-hidden bg-white"},{default:c((()=>[y("div",Te,[m(e.$slots,"default",{close:t})])])),_:2},1024)])])),_:3}))});function De(e){return t=X(e,{mangle:!1,headerIds:!1}),W.sanitize(t,{ADD_ATTR:["target"]});var t}Ne.__file="src/components/modals/AGModal.vue";var ze=n({__name:"AGMarkdown",props:{langKey:ve(),text:ve()},setup(e){const t=e,s=_((()=>t.text??(t.langKey&&Me(t.langKey)))),a=_((()=>s.value&&De(s.value))),r=()=>A("div",{class:"prose",innerHTML:a.value});return(e,t)=>(i(),u(r))}});ze.__file="src/components/basic/AGMarkdown.vue";var Ke=n({__name:"AGAlertModal",props:{message:he()},setup:e=>(t,s)=>(i(),u(Ne,null,{default:c((()=>[b(ze,{text:e.message},null,8,["text"])])),_:1}))});Ke.__file="src/components/modals/AGAlertModal.vue";const Qe={$ui:Ee};var Re=async(e,t)=>{const s={[Pe.AlertModal]:Ke};Object.entries({...s,...t.components}).forEach((e=>{let[t,s]=e;return Ee.registerComponent(t,s)})),await je(e,Qe)};async function Ue(e){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};const s=[ge,Se,Ce,He,Ge,Re],a=x({data:()=>({ready:!1}),mounted(){Y.forEach((e=>e())),this.ready=!0},render(){return this.ready?A(e):null}});await Promise.all(s.map((e=>e(a,t)))),a.mount("#app")}const Je={key:0};var We=n({__name:"AGAppOverlays",setup(t){const s=e(null),a=e(!0),r=_((()=>Ee.modals[0]??null));return qe("show-overlays-backdrop",(async()=>{s.value&&a.value&&(a.value=!1,s.value.classList.remove("opacity-0"))})),qe("hide-overlays-backdrop",(async()=>{s.value&&!a.value&&(a.value=!0,s.value.classList.add("opacity-0"))})),(e,t)=>(i(),w(j,null,[y("div",{ref_key:"$backdrop",ref:s,class:"pointer-events-none fixed inset-0 z-50 bg-black/30 opacity-0"},null,512),r.value?(i(),w("aside",Je,[b(Fe,{"child-index":1,modal:r.value},null,8,["modal"])])):g("v-if",!0)],64))}});We.__file="src/components/AGAppOverlays.vue";const Xe={class:"flex h-full flex-col text-base font-normal leading-tight text-gray-900 antialiased"};var Ye=n({__name:"AGAppLayout",setup:e=>(e,t)=>(i(),w("div",Xe,[m(e.$slots,"default"),b(We)]))});Ye.__file="src/components/AGAppLayout.vue";var Ze=n({__name:"AGHeadlessButton",props:{url:ve(),route:ve(),routeParams:ue((()=>({}))),routeQuery:ue((()=>({}))),submit:ee()},setup(e){const{url:t,route:s,routeParams:a,routeQuery:r,submit:o}=e,n=_((()=>s?{tag:"router-link",props:{to:F({name:s,params:a,query:r})}}:t?{tag:"a",props:{target:"_blank",href:t}}:{tag:"button",props:{type:o?"submit":"button"}}));return(e,t)=>(i(),u(f(n.value.tag),h(v(n.value.props)),{default:c((()=>[m(e.$slots,"default")])),_:3},16))}});Ze.__file="src/components/headless/forms/AGHeadlessButton.vue";var et=n({__name:"AGButton",setup:e=>(e,t)=>(i(),u(Ze,{class:"bg-indigo-600 px-2.5 py-1.5 text-white hover:bg-indigo-500 focus-visible:outline focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-indigo-600"},{default:c((()=>[m(e.$slots,"default")])),_:3}))});et.__file="src/components/forms/AGButton.vue";const tt=["onSubmit"];var st=n({__name:"AGForm",props:{form:ue()},emits:["submit"],setup(e,{emit:t}){const s=e;function a(){s.form&&!s.form.submit()||t("submit")}return p("form",s.form),(e,t)=>(i(),w("form",{onSubmit:G(a,["prevent"])},[m(e.$slots,"default")],40,tt))}});st.__file="src/components/forms/AGForm.vue";var at=n({__name:"AGHeadlessInput",props:{as:ve(),name:ve(),modelValue:ve()},emits:["update:modelValue"],setup(e,{expose:s,emit:a}){const r=e,o=_((()=>n&&r.name?n.errors[r.name]??null:null)),n=t("form"),l={id:B(),value:_((()=>n&&r.name?n.getFieldValue(r.name):r.modelValue)),errors:k(o),update(e){n&&r.name?n.setFieldValue(r.name,e):a("update:modelValue",e)}};return p("input",l),s(l),(t,s)=>e.as?(i(),u(f(e.as),{key:0},{default:c((()=>[m(t.$slots,"default")])),_:3})):m(t.$slots,"default",{key:1})}});at.__file="src/components/headless/forms/AGHeadlessInput.vue";const rt=["value","aria-invalid","aria-describedby"];var ot=n({__name:"AGHeadlessInputInput",setup(t){const s=e(),a=oe("input"),r=_((()=>a.value));function o(){s.value&&a.update(s.value.value)}return(e,t)=>(i(),w("input",{ref_key:"$input",ref:s,type:"text",value:r.value,"aria-invalid":d(a).errors?"true":"false","aria-describedby":d(a).errors?`${d(a).id}-error`:void 0,onInput:o},null,40,rt))}});ot.__file="src/components/headless/forms/AGHeadlessInputInput.vue";const nt=["id"];var lt=n({__name:"AGHeadlessInputError",setup(e){const t=oe("input"),s=_((()=>t.errors?Me(`errors.${t.errors[0]}`):null));return(e,a)=>s.value?(i(),w("p",{key:0,id:`${d(t).id}-error`},M(s.value),9,nt)):g("v-if",!0)}});lt.__file="src/components/headless/forms/AGHeadlessInputError.vue";var it=n({inheritAttrs:!1,__name:"AGInput",props:{name:ve()},setup(e){const t=te();return(s,a)=>(i(),u(at,{ref_key:"$input",ref:t,as:"div",class:"flex flex-col items-center",name:e.name},{default:c((()=>[b(ot,$(s.$attrs,{class:["block w-full border-0 py-1.5 text-gray-900 ring-1 ring-inset ring-gray-300 placeholder:text-gray-400 focus:ring-2 focus:ring-inset focus:ring-indigo-600",{"ring-1 ring-red-500":d(t)?.errors}]}),null,16,["class"]),b(lt,{class:"mt-1 text-sm text-red-500"})])),_:1},8,["name"]))}});it.__file="src/components/forms/AGInput.vue";var ut=n({__name:"AGHeadlessModalTitle",props:{as:ve("h2")},setup:e=>(t,s)=>(i(),u(d(J),{as:e.as},{default:c((()=>[m(t.$slots,"default")])),_:3},8,["as"]))});ut.__file="src/components/headless/modals/AGHeadlessModalTitle.vue";const dt={String:"string",Number:"number"};class ct extends C{constructor(t){super(),T(this,"errors",void 0),T(this,"_fields",void 0),T(this,"_data",void 0),T(this,"_valid",void 0),T(this,"_submitted",void 0),T(this,"_errors",void 0),this._fields=t,this._submitted=e(!1),this._valid=e(!0),this._data=this.getInitialData(t),this._errors=this.getInitialErrors(t),this.errors=k(this._errors)}get valid(){return this._valid.value}get submitted(){return this._submitted.value}setFieldValue(e,t){this._data[e]=t,this._submitted.value&&this.validate()}getFieldValue(e){return this._data[e]}validate(){const e=Object.entries(this._fields).reduce(((e,t)=>{let[s,a]=t;return e[s]=this.getFieldErrors(s,a),e}),{});return Object.assign(this._errors,e),this._valid.value=!Object.values(e).some((e=>null!==e))}submit(){return this._submitted.value=!0,this.validate()}__get(e){return e in this._fields?this._data[e]:super.__get(e)}__set(e,t){e in this._fields?Object.assign(this._data,{[e]:t}):super.__set(e,t)}getFieldErrors(e,t){const s=[];return t.rules?.includes("required")&&!this._data[e]&&s.push("required"),s.length>0?s:null}getInitialData(e){if(this.static().isConjuring())return{};const t=Object.entries(e).reduce(((e,t)=>{let[s,a]=t;return e[s]=a.default??null,e}),{});return s(t)}getInitialErrors(e){if(this.static().isConjuring())return{};const t=Object.keys(e).reduce(((e,t)=>(e[t]=null,e)),{});return s(t)}}function mt(e){return new ct(e)}function pt(e){return{default:e,type:dt.Number,rules:"required"}}function ft(e){return{default:e,type:dt.String,rules:"required"}}function ht(e){return{default:e,type:dt.Number}}function vt(e){return{default:e,type:dt.String}}export{Ye as AGAppLayout,et as AGButton,st as AGForm,Ze as AGHeadlessButton,at as AGHeadlessInput,Be as AGHeadlessModal,Le as AGHeadlessModalPanel,ut as AGHeadlessModalTitle,it as AGInput,ze as AGMarkdown,Ne as AGModal,Fe as AGModalContext,xe as Events,Ae as EventsService,dt as FormFieldTypes,ke as Lang,be as Service,Ee as UI,Pe as UIComponents,Z as arrayProp,ee as booleanProp,je as bootServices,Ue as bootstrapApplication,te as componentRef,se as defineDirective,ye as defineServiceState,ae as enumProp,ne as injectOrFail,re as injectReactive,oe as injectReactiveOrFail,Me as lang,le as mixedProp,ht as numberInput,ie as numberProp,ue as objectProp,de as requiredArrayProp,ce as requiredEnumProp,me as requiredMixedProp,pt as requiredNumberInput,pe as requiredNumberProp,fe as requiredObjectProp,ft as requiredStringInput,he as requiredStringProp,vt as stringInput,ve as stringProp,mt as useForm};
2
+ //# sourceMappingURL=aerogel-core.esm.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"aerogel-core.esm.js","sources":[],"sourcesContent":[],"names":[],"mappings":""}
@@ -0,0 +1,2 @@
1
+ /** @type {import('@noeldemartin/scripts').Config} */
2
+ module.exports = { vue: true };
package/package.json ADDED
@@ -0,0 +1,49 @@
1
+ {
2
+ "name": "@aerogel/core",
3
+ "description": "The Lightest Solid",
4
+ "version": "0.0.0-next.5436b378dff7e64898bb7046afa2d5d574255b54",
5
+ "main": "dist/aerogel-core.cjs.js",
6
+ "module": "dist/aerogel-core.esm.js",
7
+ "types": "dist/aerogel-core.d.ts",
8
+ "sideEffects": false,
9
+ "scripts": {
10
+ "build": "rm dist -rf && npm run build:js && npm run build:types",
11
+ "build:js": "noeldemartin-build-javascript",
12
+ "build:types": "noeldemartin-build-types",
13
+ "lint": "noeldemartin-lint src",
14
+ "publish-next": "noeldemartin-publish-next",
15
+ "test": "vitest --run"
16
+ },
17
+ "engines": {
18
+ "node": ">=18.x"
19
+ },
20
+ "repository": {
21
+ "type": "git",
22
+ "url": "https://github.com/NoelDeMartin/aerogeljs.git"
23
+ },
24
+ "keywords": [
25
+ "javascript",
26
+ "framework",
27
+ "solid"
28
+ ],
29
+ "author": "Noel De Martin",
30
+ "license": "MIT",
31
+ "bugs": {
32
+ "url": "https://github.com/NoelDeMartin/aerogeljs/issues"
33
+ },
34
+ "dependencies": {
35
+ "@headlessui/vue": "^1.7.14",
36
+ "@noeldemartin/utils": "0.4.0-next.65c07a35cd02a0aa1ed9e742f72036354eba5fa8",
37
+ "dompurify": "^3.0.3",
38
+ "marked": "^5.0.4",
39
+ "soukai": "^0.5.1",
40
+ "vue": "^3.3.0",
41
+ "vue-i18n": "9.3.0-beta.19",
42
+ "vue-router": "^4.2.1"
43
+ },
44
+ "devDependencies": {
45
+ "@types/dompurify": "^3.0.2",
46
+ "@types/marked": "^5.0.0",
47
+ "@vitejs/plugin-vue": "^4.2.3"
48
+ }
49
+ }
@@ -0,0 +1,113 @@
1
+ import { beforeEach, describe, expect, it, vi } from 'vitest';
2
+ import { createApp } from 'vue';
3
+ import { createI18n } from 'vue-i18n';
4
+ import { IndexedDBEngine, requireBootedModel, requireEngine } from 'soukai';
5
+ import { mock } from '@noeldemartin/utils';
6
+ import type { Component } from 'vue';
7
+
8
+ import Events from '@/services/Events';
9
+ import initialFocus from '@/directives/initial-focus';
10
+ import User from '@/testing/stubs/models/User';
11
+
12
+ import { bootstrapApplication } from './index';
13
+
14
+ describe('Aerogel', () => {
15
+
16
+ beforeEach(() => {
17
+ vi.mock('vue', async () => {
18
+ const vue = (await vi.importActual('vue')) as Object;
19
+
20
+ return {
21
+ ...vue,
22
+ createApp: vi.fn(() => ({
23
+ mount: vi.fn(),
24
+ use: vi.fn(),
25
+ directive: vi.fn(),
26
+ config: { globalProperties: {} },
27
+ })),
28
+ };
29
+ });
30
+ });
31
+
32
+ it('Initializes Soukai', async () => {
33
+ // Arrange
34
+ const rootComponent = mock<Component>();
35
+
36
+ // Act
37
+ await bootstrapApplication(rootComponent, {
38
+ models: import.meta.glob('@/testing/stubs/models/*', { eager: true }),
39
+ });
40
+
41
+ // Assert
42
+ expect(requireBootedModel('User')).toEqual(User);
43
+ expect(requireEngine()).toBeInstanceOf(IndexedDBEngine);
44
+ });
45
+
46
+ it('Initializes routes', async () => {
47
+ // Arrange
48
+ vi.mock('vue-router', () => ({
49
+ createRouter: vi.fn(() => ({ routerMock: true })),
50
+ createWebHistory: vi.fn(),
51
+ }));
52
+
53
+ const rootComponent = mock<Component>();
54
+
55
+ // Act
56
+ await bootstrapApplication(rootComponent, {
57
+ routes: [],
58
+ });
59
+
60
+ // Assert
61
+ expect(vi.mocked(createApp).mock.results[0]?.value.use).toHaveBeenCalledWith({ routerMock: true });
62
+ });
63
+
64
+ it('Initializes lang', async () => {
65
+ // Arrange
66
+ vi.mock('vue-i18n', () => ({ createI18n: vi.fn(() => ({ i18nMock: true })) }));
67
+
68
+ const rootComponent = mock<Component>();
69
+
70
+ // Act
71
+ await bootstrapApplication(rootComponent, {
72
+ langMessages: import.meta.glob('@/testing/stubs/lang/*'),
73
+ });
74
+
75
+ // Assert
76
+ const mockedCreateI18n = vi.mocked(createI18n);
77
+ const mockedCreateApp = vi.mocked(createApp);
78
+
79
+ expect(mockedCreateI18n).toHaveBeenCalled();
80
+ expect(mockedCreateI18n.mock.calls[0]?.[0].messages).key('en').to.exist;
81
+ expect(mockedCreateI18n.mock.calls[0]?.[0].messages?.['en']).key('foo').to.exist;
82
+ expect(mockedCreateApp.mock.results[0]?.value.use).toHaveBeenCalledWith({ i18nMock: true });
83
+ });
84
+
85
+ it('Boots services', async () => {
86
+ // Arrange
87
+ const rootComponent = mock<Component>();
88
+
89
+ // Act
90
+ await bootstrapApplication(rootComponent);
91
+
92
+ // Assert
93
+ const globals = vi.mocked(createApp).mock.results[0]?.value.config.globalProperties;
94
+
95
+ expect(globals).property('$events').to.exist;
96
+ expect(globals.$events).toBe(Events);
97
+ });
98
+
99
+ it('Registers directives', async () => {
100
+ // Arrange
101
+ const rootComponent = mock<Component>();
102
+
103
+ // Act
104
+ await bootstrapApplication(rootComponent);
105
+
106
+ // Assert
107
+ expect(vi.mocked(createApp).mock.results[0]?.value.directive).toHaveBeenCalledWith(
108
+ 'initial-focus',
109
+ initialFocus,
110
+ );
111
+ });
112
+
113
+ });
@@ -0,0 +1,19 @@
1
+ import type { App } from 'vue';
2
+
3
+ import type { BootstrapOptions } from '@/bootstrap/options';
4
+
5
+ const mountedHooks: Function[] = [];
6
+
7
+ export type BootstrapHook = (app: App, options: BootstrapOptions) => Promise<void>;
8
+
9
+ export function onAppMounted(hook: Function): void {
10
+ mountedHooks.push(hook);
11
+ }
12
+
13
+ export function runAppMountedHooks(): void {
14
+ mountedHooks.forEach((hook) => hook());
15
+ }
16
+
17
+ export function defineBootstrapHook<T extends BootstrapHook>(hook: T): T {
18
+ return hook;
19
+ }
@@ -0,0 +1,36 @@
1
+ import { createApp, h } from 'vue';
2
+ import type { Component } from 'vue';
3
+
4
+ import directives from '@/directives';
5
+ import lang from '@/lang';
6
+ import models from '@/models';
7
+ import routing from '@/routing';
8
+ import services from '@/services';
9
+ import ui from '@/ui';
10
+ import { runAppMountedHooks } from '@/bootstrap/hooks';
11
+ import type { BootstrapOptions } from '@/bootstrap/options';
12
+
13
+ export async function bootstrapApplication(rootComponent: Component, options: BootstrapOptions = {}): Promise<void> {
14
+ const hooks = [directives, lang, models, routing, services, ui];
15
+ const app = createApp({
16
+ data: () => ({
17
+ ready: false,
18
+ }),
19
+ mounted() {
20
+ runAppMountedHooks();
21
+
22
+ this.ready = true;
23
+ },
24
+ render() {
25
+ if (!this.ready) {
26
+ return null;
27
+ }
28
+
29
+ return h(rootComponent);
30
+ },
31
+ });
32
+
33
+ await Promise.all(hooks.map((hook) => hook(app, options)));
34
+
35
+ app.mount('#app');
36
+ }
@@ -0,0 +1 @@
1
+ export interface BootstrapOptions {}
@@ -0,0 +1,11 @@
1
+ <template>
2
+ <div class="flex h-full flex-col text-base font-normal leading-tight text-gray-900 antialiased">
3
+ <slot />
4
+
5
+ <AGAppOverlays />
6
+ </div>
7
+ </template>
8
+
9
+ <script setup lang="ts">
10
+ import AGAppOverlays from './AGAppOverlays.vue';
11
+ </script>
@@ -0,0 +1,39 @@
1
+ <template>
2
+ <div ref="$backdrop" class="pointer-events-none fixed inset-0 z-50 bg-black/30 opacity-0" />
3
+ <aside v-if="modal">
4
+ <AGModalContext :child-index="1" :modal="modal" />
5
+ </aside>
6
+ </template>
7
+
8
+ <script setup lang="ts">
9
+ import { computed, ref } from 'vue';
10
+
11
+ import UI from '@/ui/UI';
12
+ import { useEvent } from '@/utils/composition/events';
13
+
14
+ import AGModalContext from './modals/AGModalContext.vue';
15
+
16
+ const $backdrop = ref<HTMLElement | null>(null);
17
+ const backdropHidden = ref(true);
18
+ const modal = computed(() => UI.modals[0] ?? null);
19
+
20
+ useEvent('show-overlays-backdrop', async () => {
21
+ if (!$backdrop.value || !backdropHidden.value) {
22
+ return;
23
+ }
24
+
25
+ backdropHidden.value = false;
26
+
27
+ $backdrop.value.classList.remove('opacity-0');
28
+ });
29
+
30
+ useEvent('hide-overlays-backdrop', async () => {
31
+ if (!$backdrop.value || backdropHidden.value) {
32
+ return;
33
+ }
34
+
35
+ backdropHidden.value = true;
36
+
37
+ $backdrop.value.classList.add('opacity-0');
38
+ });
39
+ </script>
@@ -0,0 +1,20 @@
1
+ <template>
2
+ <root />
3
+ </template>
4
+
5
+ <script setup lang="ts">
6
+ import { computed, h } from 'vue';
7
+
8
+ import { renderMarkdown } from '@/utils/markdown';
9
+ import { stringProp } from '@/utils/vue';
10
+ import { lang } from '@/lang/helpers';
11
+
12
+ const props = defineProps({
13
+ langKey: stringProp(),
14
+ text: stringProp(),
15
+ });
16
+
17
+ const markdown = computed(() => props.text ?? (props.langKey && lang(props.langKey)));
18
+ const html = computed(() => markdown.value && renderMarkdown(markdown.value));
19
+ const root = () => h('div', { class: 'prose', innerHTML: html.value });
20
+ </script>
@@ -0,0 +1,3 @@
1
+ import AGMarkdown from './AGMarkdown.vue';
2
+
3
+ export { AGMarkdown };
@@ -0,0 +1,11 @@
1
+ <template>
2
+ <AGHeadlessButton
3
+ class="bg-indigo-600 px-2.5 py-1.5 text-white hover:bg-indigo-500 focus-visible:outline focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-indigo-600"
4
+ >
5
+ <slot />
6
+ </AGHeadlessButton>
7
+ </template>
8
+
9
+ <script setup lang="ts">
10
+ import AGHeadlessButton from '../headless/forms/AGHeadlessButton.vue';
11
+ </script>
@@ -0,0 +1,26 @@
1
+ <template>
2
+ <form @submit.prevent="submit">
3
+ <slot />
4
+ </form>
5
+ </template>
6
+
7
+ <script setup lang="ts">
8
+ import { provide } from 'vue';
9
+
10
+ import { objectProp } from '@/utils/vue';
11
+ import type Form from '@/forms/Form';
12
+
13
+ const props = defineProps({ form: objectProp<Form>() });
14
+
15
+ const emit = defineEmits<{ submit: [] }>();
16
+
17
+ provide('form', props.form);
18
+
19
+ function submit() {
20
+ if (props.form && !props.form.submit()) {
21
+ return;
22
+ }
23
+
24
+ emit('submit');
25
+ }
26
+ </script>
@@ -0,0 +1,32 @@
1
+ <template>
2
+ <AGHeadlessInput
3
+ ref="$input"
4
+ as="div"
5
+ class="flex flex-col items-center"
6
+ :name="name"
7
+ >
8
+ <AGHeadlessInputInput
9
+ v-bind="$attrs"
10
+ class="block w-full border-0 py-1.5 text-gray-900 ring-1 ring-inset ring-gray-300 placeholder:text-gray-400 focus:ring-2 focus:ring-inset focus:ring-indigo-600"
11
+ :class="{
12
+ 'ring-1 ring-red-500': $input?.errors,
13
+ }"
14
+ />
15
+ <AGHeadlessInputError class="mt-1 text-sm text-red-500" />
16
+ </AGHeadlessInput>
17
+ </template>
18
+
19
+ <script setup lang="ts">
20
+ import { componentRef, stringProp } from '@/utils/vue';
21
+
22
+ import type { IAGHeadlessInput } from '@/components/headless/forms/AGHeadlessInput';
23
+
24
+ import AGHeadlessInput from '../headless/forms/AGHeadlessInput.vue';
25
+ import AGHeadlessInputInput from '../headless/forms/AGHeadlessInputInput.vue';
26
+ import AGHeadlessInputError from '../headless/forms/AGHeadlessInputError.vue';
27
+
28
+ defineProps({ name: stringProp() });
29
+ defineOptions({ inheritAttrs: false });
30
+
31
+ const $input = componentRef<IAGHeadlessInput>();
32
+ </script>
@@ -0,0 +1,5 @@
1
+ import AGButton from './AGButton.vue';
2
+ import AGForm from './AGForm.vue';
3
+ import AGInput from './AGInput.vue';
4
+
5
+ export { AGButton, AGForm, AGInput };
@@ -0,0 +1,51 @@
1
+ <template>
2
+ <component :is="component.tag" v-bind="component.props">
3
+ <slot />
4
+ </component>
5
+ </template>
6
+
7
+ <script setup lang="ts">
8
+ import { computed } from 'vue';
9
+ import { objectWithoutEmpty } from '@noeldemartin/utils';
10
+ import type { LocationQuery, RouteLocation, RouteParams } from 'vue-router';
11
+
12
+ import { booleanProp, objectProp, stringProp } from '@/utils/vue';
13
+
14
+ const { url, route, routeParams, routeQuery, submit } = defineProps({
15
+ url: stringProp(),
16
+ route: stringProp(),
17
+ routeParams: objectProp<RouteParams>(() => ({})),
18
+ routeQuery: objectProp<LocationQuery>(() => ({})),
19
+ submit: booleanProp(),
20
+ });
21
+
22
+ const component = computed(() => {
23
+ if (route) {
24
+ return {
25
+ tag: 'router-link',
26
+ props: {
27
+ to: objectWithoutEmpty<Partial<RouteLocation>>({
28
+ name: route,
29
+ params: routeParams,
30
+ query: routeQuery,
31
+ }),
32
+ },
33
+ };
34
+ }
35
+
36
+ if (url) {
37
+ return {
38
+ tag: 'a',
39
+ props: {
40
+ target: '_blank',
41
+ href: url,
42
+ },
43
+ };
44
+ }
45
+
46
+ return {
47
+ tag: 'button',
48
+ props: { type: submit ? 'submit' : 'button' },
49
+ };
50
+ });
51
+ </script>
@@ -0,0 +1,8 @@
1
+ import type { ComputedRef, DeepReadonly, Ref } from 'vue';
2
+
3
+ export interface IAGHeadlessInput {
4
+ id: string;
5
+ value: ComputedRef<string | number | null>;
6
+ errors: DeepReadonly<Ref<string[] | null>>;
7
+ update(value: string | number | null): void;
8
+ }
@@ -0,0 +1,54 @@
1
+ <template>
2
+ <component :is="as" v-if="as">
3
+ <slot />
4
+ </component>
5
+ <slot v-else />
6
+ </template>
7
+
8
+ <script setup lang="ts">
9
+ import { computed, inject, provide, readonly } from 'vue';
10
+ import { uuid } from '@noeldemartin/utils';
11
+
12
+ import { stringProp } from '@/utils/vue';
13
+ import type Form from '@/forms/Form';
14
+
15
+ import type { IAGHeadlessInput } from './AGHeadlessInput';
16
+
17
+ const emit = defineEmits(['update:modelValue']);
18
+ const props = defineProps({
19
+ as: stringProp(),
20
+ name: stringProp(),
21
+ modelValue: stringProp(),
22
+ });
23
+ const errors = computed(() => {
24
+ if (!form || !props.name) {
25
+ return null;
26
+ }
27
+
28
+ return form.errors[props.name] ?? null;
29
+ });
30
+ const form = inject<Form>('form');
31
+ const publicApi: IAGHeadlessInput = {
32
+ id: uuid(),
33
+ value: computed(() => {
34
+ if (form && props.name) {
35
+ return form.getFieldValue(props.name);
36
+ }
37
+
38
+ return props.modelValue;
39
+ }),
40
+ errors: readonly(errors),
41
+ update(value) {
42
+ if (form && props.name) {
43
+ form.setFieldValue(props.name, value);
44
+
45
+ return;
46
+ }
47
+
48
+ emit('update:modelValue', value);
49
+ },
50
+ };
51
+
52
+ provide<IAGHeadlessInput>('input', publicApi);
53
+ defineExpose<IAGHeadlessInput>(publicApi);
54
+ </script>
@@ -0,0 +1,22 @@
1
+ <template>
2
+ <p v-if="errorMessage" :id="`${input.id}-error`">
3
+ {{ errorMessage }}
4
+ </p>
5
+ </template>
6
+
7
+ <script setup lang="ts">
8
+ import { injectReactiveOrFail } from '@/utils';
9
+
10
+ import type { IAGHeadlessInput } from './AGHeadlessInput';
11
+ import { computed } from 'vue';
12
+ import { lang } from '@/lang';
13
+
14
+ const input = injectReactiveOrFail<IAGHeadlessInput>('input');
15
+ const errorMessage = computed(() => {
16
+ if (!input.errors) {
17
+ return null;
18
+ }
19
+
20
+ return lang(`errors.${input.errors[0]}`);
21
+ });
22
+ </script>
@@ -0,0 +1,29 @@
1
+ <template>
2
+ <input
3
+ ref="$input"
4
+ type="text"
5
+ :value="value"
6
+ :aria-invalid="input.errors ? 'true' : 'false'"
7
+ :aria-describedby="input.errors ? `${input.id}-error` : undefined"
8
+ @input="update"
9
+ >
10
+ </template>
11
+
12
+ <script setup lang="ts">
13
+ import { computed, ref } from 'vue';
14
+
15
+ import { injectReactiveOrFail } from '@/utils';
16
+ import type { IAGHeadlessInput } from '@/components/headless/forms/AGHeadlessInput';
17
+
18
+ const $input = ref<HTMLInputElement>();
19
+ const input = injectReactiveOrFail<IAGHeadlessInput>('input');
20
+ const value = computed(() => input.value);
21
+
22
+ function update() {
23
+ if (!$input.value) {
24
+ return;
25
+ }
26
+
27
+ input.update($input.value.value);
28
+ }
29
+ </script>
@@ -0,0 +1,4 @@
1
+ import AGHeadlessButton from './AGHeadlessButton.vue';
2
+ import AGHeadlessInput from './AGHeadlessInput.vue';
3
+
4
+ export { AGHeadlessButton, AGHeadlessInput };
@@ -0,0 +1,2 @@
1
+ export * from './forms';
2
+ export * from './modals';
@@ -0,0 +1,7 @@
1
+ import type { IAGModal } from '@/components/modals/AGModal';
2
+
3
+ export interface IAGHeadlessModal extends IAGModal {}
4
+
5
+ export interface IAGHeadlessModalDefaultSlotProps {
6
+ close(result?: unknown): Promise<void>;
7
+ }