{"version":3,"sources":["component-utils.js"],"names":["formatCurrency","formatDate","formatDateTime","formatNumber","isNumber","parseNumber","round","hide","show","Vue","createApp","initialData","arguments","length","undefined","components","data","_objectSpread","dispatch","name","argument","bubbles","event","target","dispatchEvent","CustomEvent","detail","mounted","element","this","setData","$mounted","$data","unmounted","app","directive","ctx","initialDisplay","el","style","display","effect","duration","arg","isNaN","parseInt","get","_unused","_unused2","listener","addEventListener","e","_components","_data","hasRegisteredComponents","registerComponents","vm","_app","document","querySelector","mount","contentUpdating","contentUpdated","unregisterComponents","_app2","unmount","removeEventListener","map","Map","has","set","render","templateElement","createElement","innerHTML"],"mappings":"w1CAAAA,eAAAC,WAAAC,eAAAC,aAAAC,SAAAC,YAAAC,KAAA,KAAA,oBACAC,KAAAC,IAAA,KAAA,iBACAC,YAAA,MAEA,SAAAC,YAAA,IAAAC,EAAA,EAAAC,UAAAC,QAAAC,KAAAA,IAAAF,UAAA,GAAAA,UAAA,GAAA,GAAAG,EAAA,EAAAH,UAAAC,QAAAC,KAAAA,IAAAF,UAAA,GAAAA,UAAA,GAAA,GAJAI,EAAAC,cAAAA,cAAAA,cAAA,GACAN,CAAA,EACAI,CAAA,EAEA,CAMAG,SAAA,SAAAC,EAAAC,GAAA,IAAAC,EAAAT,EAAA,EAAAA,UAAAC,QAAAC,KAAAA,IAAAF,UAAA,KAAAA,UAAA,IAAA,EAAAA,UAAAC,QAAAC,KAAAA,IAAAF,UAAA,GAAAA,UAAA,GAAAU,OAEAC,OAAAC,cAAA,IAAAC,YAAAN,EAAA,CAAAE,QAAAA,EAAAK,OAAAN,CAAA,CAAA,CAAA,CACA,EACApB,eAAAA,eACAC,WAAAA,WACAC,eAAAA,eACAC,aAAAA,aACAC,SAAAA,SACAuB,QAAA,SAAAC,GAAA,IAAAZ,EAAA,EAAAJ,UAAAC,QAAAC,KAAAA,IAAAF,UAAA,GAAAA,UAAA,GAAAiB,KAEAA,KAAAC,QAAAF,EAAAZ,CAAA,EAGAY,EAAAG,S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AAAM,EAAAD,CAAA,EAAA6C,MAAAhC,CAAA,EAJAA,EAAA8C,SAOA,QAnJAhE,UAwEAiB,QASA4B,mBAuBAQ,qBAoCAQ,MAOA","file":"component-utils.js","sourcesContent":["import { formatCurrency, formatDate, formatDateTime, formatNumber, isNumber, parseNumber, round } from 'intl-utils';\r\nimport { hide, show } from 'ui-utils';\r\nimport * as Vue from 'vue';\r\n\r\nexport function createApp(initialData = {}, components = {}) {\r\n // Merge the initial data, components and methods.\r\n const data = {\r\n ...initialData,\r\n ...components,\r\n ...{\r\n dispatch(name, argument, bubbles = true, e = event) {\r\n // Trigger the custom event.\r\n e.target.dispatchEvent(new CustomEvent(name, { bubbles: bubbles, detail: argument }));\r\n },\r\n formatCurrency,\r\n formatDate,\r\n formatDateTime,\r\n formatNumber,\r\n isNumber,\r\n mounted(element, data = this) {\r\n // Store the data against the element.\r\n this.setData(element, data);\r\n\r\n // Set that it has been mounted.\r\n element.$mounted = true;\r\n\r\n // Dispatch the mounted event.\r\n element.dispatchEvent(new CustomEvent('mounted', { detail: data }));\r\n },\r\n parseNumber,\r\n round,\r\n setData(element, data = this) {\r\n element.$data = data;\r\n },\r\n unmounted(element, data = this) {\r\n // Remove the data against the element.\r\n this.setData(element, null);\r\n\r\n // Set that it has been unmounted.\r\n element.$mounted = false;\r\n\r\n // Dispatch the unmounted event.\r\n element.dispatchEvent(new CustomEvent('unmounted', { detail: data }));\r\n }\r\n }\r\n };\r\n\r\n const app = Vue.createApp(data);\r\n\r\n // Register the custom directives.\r\n app.directive('kit-show', ctx => {\r\n const initialDisplay = ctx.el.style.display;\r\n\r\n ctx.effect(() => {\r\n const duration = ctx.arg ? (!isNaN(parseInt(ctx.arg)) ? parseInt(ctx.arg) : ctx.arg) : 400;\r\n\r\n // Note: The try/catch is used because sometimes jQuery throws an error (seems to happen when used within the edit view inside the list component, e.g. edit price band for a delivery method), therefore if an error is thrown then fallback to the default behaviour.\r\n if (ctx.get()) {\r\n try {\r\n show(ctx.el, duration);\r\n } catch {\r\n ctx.el.style.display = initialDisplay;\r\n }\r\n } else {\r\n try {\r\n hide(ctx.el, duration);\r\n } catch {\r\n ctx.el.style.display = 'none';\r\n }\r\n }\r\n });\r\n });\r\n\r\n return app;\r\n}\r\n\r\nexport function mounted(element, listener) {\r\n if (element.$mounted === true)\r\n listener(element.$data);\r\n else\r\n element.addEventListener('mounted', e => listener(e.detail));\r\n}\r\n\r\nlet hasRegisteredComponents = false, app, _components, _data;\r\n\r\nexport function registerComponents(components = {}, data = {}) {\r\n // Make sure the components have not already been registered.\r\n if (hasRegisteredComponents)\r\n throw 'You have already registered the components.';\r\n\r\n // Create and mount the app (if applicable).\r\n app = document.querySelector('[v-scope]') ? createApp(data, components) : null;\r\n const vm = app?.mount();\r\n\r\n // Store the components and data as they are used within the event handler.\r\n _components = components;\r\n _data = data;\r\n\r\n // Add the content event listeners.\r\n document.addEventListener('DOMContentUpdating', contentUpdating);\r\n document.addEventListener('DOMContentUpdated', contentUpdated);\r\n\r\n // Set that the components have been registered.\r\n hasRegisteredComponents = true;\r\n\r\n return vm;\r\n}\r\n\r\nexport function unregisterComponents() {\r\n // Make sure the components have been registered.\r\n if (!hasRegisteredComponents)\r\n return;\r\n\r\n // Unmount the app (if it has been mounted).\r\n app?.unmount();\r\n\r\n // Remove the content event handlers.\r\n document.removeEventListener('DOMContentUpdating', contentUpdating);\r\n document.removeEventListener('DOMContentUpdated', contentUpdated);\r\n\r\n // Set that the components have not been registered.\r\n hasRegisteredComponents = false;\r\n}\r\n\r\nconst map = new Map();\r\n\r\nfunction contentUpdating(e) {\r\n // Unmount the targetted element (if applicable). This fixes https://github.com/vuejs/vue-next/issues/2670.\r\n if (map.has(e.target))\r\n map.get(e.target).unmount();\r\n\r\n // Remove the mounted instance.\r\n map.delete(e.target);\r\n}\r\n\r\nfunction contentUpdated(e) {\r\n // Create and mount the app.\r\n const app = createApp(_data, _components);\r\n app.mount(e.target);\r\n\r\n // Store a reference to the mounted instance.\r\n map.set(e.target, app);\r\n}\r\n\r\nexport function render(templateElement, data = {}, components = {}) {\r\n const element = document.createElement('div');\r\n element.innerHTML = templateElement.innerHTML;\r\n\r\n createApp(data, components).mount(element);\r\n \r\n return element.innerHTML;\r\n}\r\n"]}