-
Notifications
You must be signed in to change notification settings - Fork 0
/
cumbia.js.map
7 lines (7 loc) · 13.5 KB
/
cumbia.js.map
1
2
3
4
5
6
7
{
"version": 3,
"sources": ["src/_version.ts", "src/utils/message.ts", "src/actionParser/utils/parseValues.ts", "src/actionParser/utils/caller.ts", "src/actionParser/data-action.ts", "src/actionParser/data-key.ts", "src/actionParser/lifecycle.ts", "src/core/pubsub.ts", "src/core/componentExecutor.ts", "src/core/createApp.ts", "src/utils/components/debug.ts", "src/cumbia.ts"],
"sourcesContent": ["export const version = '0.0.11';", "const logPrefix = '\uD83C\uDFBC Cumbia:';\nconst error = (msg: any) => console.error(`${logPrefix}`,msg);\nconst warn = (msg: any) => console.warn(`${logPrefix}`, msg);\nconst info = (msg: any) => console.info(`${logPrefix}`, msg);\n\nexport default { error, warn, info };\n", "import { BindedValues } from \"types/cumbiaTypes\";\n\nconst parseValues = (element: HTMLElement): BindedValues => {\n const dataValueAttr = 'data-value';\n const bindedValues: BindedValues = {};\n\n const values = element.querySelectorAll(`[${dataValueAttr}]`);\n\n values.forEach((valueElement: HTMLElement) => {\n const nameDefined =\n valueElement.getAttribute(dataValueAttr) || 'default_name';\n\n let value = valueElement.innerHTML;\n\n if (valueElement.tagName === 'INPUT') {\n value = (<HTMLInputElement>valueElement).value;\n }\n //TODO: Can we get a boolean or a integer from the value property of an element?\n\n bindedValues[nameDefined] = { el: valueElement, value };\n });\n\n return bindedValues;\n};\n\nexport default parseValues;\n", "import { ComponentActions } from 'types/cumbiaTypes';\nimport message from '../../utils/message';\nimport parseValues from './parseValues';\n\nexport type CallerValues = {\n prevent: boolean;\n};\n\nconst callFnWithValues =\n (\n element: HTMLElement,\n fnActions: ComponentActions,\n actionName: string,\n { prevent }: CallerValues,\n ) =>\n (e: Event) => {\n const fnTobind = fnActions[actionName];\n\n if (prevent) {\n e.preventDefault();\n }\n\n if (!fnTobind) {\n return message.warn(\n `Action -->\"${actionName}\"<-- not defined in component.`,\n );\n }\n\n const values = parseValues(element);\n\n fnTobind(values);\n };\n\nexport default callFnWithValues;\n", "import { ComponentActions } from 'types/cumbiaTypes';\nimport message from '../utils/message';\nimport callFnWithValues from './utils/caller';\n\nconst parseActions = (element: HTMLElement, fnActions: ComponentActions) => {\n const dataActionAttr = 'data-action';\n\n const actions = element.querySelectorAll(`[${dataActionAttr}]`);\n\n actions.forEach((actionElement: HTMLElement) => {\n const actionName =\n actionElement.getAttribute(dataActionAttr) || 'default_action_name';\n const actionType = actionElement.getAttribute('type');\n\n if (actionName === 'submit' || actionType === 'submit') {\n if (element.tagName !== 'FORM') {\n return message.error(`Trying to handle submit handler in an element different than a FORM: ${element}` );\n }\n\n element.addEventListener(\n 'submit',\n callFnWithValues(element, fnActions, actionName, { prevent: true }),\n );\n\n return;\n }\n\n if (actionElement.tagName === 'INPUT') {\n actionElement.addEventListener(\n 'change',\n callFnWithValues(element, fnActions, actionName, { prevent: false }),\n );\n\n return;\n }\n\n actionElement.addEventListener(\n 'click',\n callFnWithValues(element, fnActions, actionName, { prevent: false }),\n );\n });\n};\n\nexport default parseActions;\n", "import { ComponentActions } from 'types/cumbiaTypes';\nimport callFnWithValues from './utils/caller';\n\nconst parseKey = (element: HTMLElement, fnActions: ComponentActions) => {\n const dataActionAttr = 'data-action-key';\n\n const actions = element.querySelectorAll(`[${dataActionAttr}]`);\n actions.forEach((actionElement: HTMLElement) => {\n const actionName =\n actionElement.getAttribute(dataActionAttr) || 'default_action_name';\n\n actionElement.addEventListener(\n 'keyup',\n callFnWithValues(element, fnActions, actionName, { prevent: false }),\n );\n });\n};\n\nexport default parseKey;\n", "import { ComponentInstance } from 'types/cumbiaTypes';\nimport parseValues from './utils/parseValues';\n\nconst parseLifecycle = (instance: ComponentInstance, element: HTMLElement) => {\n const values = parseValues(element);\n if (instance.init) {\n instance.init(values);\n }\n};\n\nexport default parseLifecycle;\n", "import msg from \"../utils/message\";\nconst subscriptions = new Map<string, Array<(params: any) => void>>();\n\nexport const on = (topic: string, fn: any) => {\n const currentSubscriptions = subscriptions.get(topic) || [];\n currentSubscriptions.push(fn);\n subscriptions.set(topic, currentSubscriptions);\n};\n\ntype emitterType = <T>(topic: string, message: T) => void;\n\nexport const emit: emitterType = (topic, message) => {\n // msg.info({ topic, message });\n const fns = subscriptions.get(topic) || [];\n\n fns.forEach((fn) => {\n if (fn) {\n fn(message);\n } else {\n console.warn(\"Topic not found\");\n }\n });\n};\n\nexport default {\n on,\n emit,\n};\n", "import parseActions from \"../actionParser/data-action\";\nimport parseKey from \"../actionParser/data-key\";\nimport parseLifecycle from \"../actionParser/lifecycle\";\nimport { ComponentFactory } from \"types/cumbiaTypes\";\nimport message from \"../utils/message\";\nimport pubsub from \"./pubsub\";\nconst componentExecutor = (\n element: HTMLElement,\n componentFactory: Map<string, ComponentFactory>,\n name: string\n): void => {\n const cleanName = name.trim();\n\n if (!componentFactory.has(cleanName)) {\n return message.warn(`Component -->\"${cleanName}\"<-- was not found.`);\n }\n\n const fnComponent = componentFactory.get(cleanName);\n\n if (!fnComponent) {\n return message.error(\"Undefined component\");\n }\n\n const instanceComponent = fnComponent({ el: element, on: pubsub.on, emit: pubsub.emit });\n\n parseLifecycle(instanceComponent, element);\n\n if (instanceComponent?.actions) {\n parseActions(element, instanceComponent.actions);\n parseKey(element, instanceComponent.actions);\n }\n};\n\nexport default componentExecutor;\n", "import componentExecutor from \"./componentExecutor\";\nimport { ComponentFactory } from \"types/cumbiaTypes\";\nimport { CumbiaOptions } from \"types/cumbiaTypes\";\n\nexport const initialisedComponent = new Map<HTMLElement, boolean>();\nexport const componentFactory = new Map<string, ComponentFactory>();\n\nconst dataComponentAttr = \"data-component\";\n\nconst componentSeparator = \",\";\n\nconst createApp = (options: CumbiaOptions): void => {\n const htmlComponents = document.querySelectorAll(`[${dataComponentAttr}]`);\n\n htmlComponents.forEach((element: HTMLElement) => {\n if (initialisedComponent.has(element)) {\n return;\n } else {\n initialisedComponent.set(element, true);\n }\n\n const name = element.getAttribute(dataComponentAttr) || \"\";\n\n const allComponents = name.split(componentSeparator);\n\n allComponents.forEach((uniqueComponent) =>\n componentExecutor(element, componentFactory, uniqueComponent)\n );\n });\n\n if (options?.globalInitialisers && options.globalInitialisers.length) {\n options.globalInitialisers.forEach((globalFn) => {\n const elements = [...initialisedComponent.keys()];\n globalFn(elements);\n });\n }\n};\n\nexport default createApp;\n", "const globalCSS = `\n * {\n transition: outline 1s;\n }\n .debugIcon {\n position: fixed;\n top: 10px;\n right: 10px;\n height: 25px;\n cursor: pointer;\n background-image: url(\"https://github.com/neomaxzero/cumbia/blob/master/assets/logomin.png?raw=true\");\n background-size: contain;\n background-repeat: no-repeat;\n padding-left: 25px;\n padding-top: 2px;\n color: #888;\n }\n\n .signElement {\n outline: 3px solid deeppink;\n }\n`;\n\nconst debug = (components: Array<HTMLElement>) => { \n const css = document.createElement(\"style\");\n css.innerHTML = globalCSS;\n document.head.appendChild(css);\n\n const debugIcon = document.createElement(\"div\");\n debugIcon.classList.add(\"debugIcon\");\n\n debugIcon.innerHTML = 'DEBUG';\n document.body.appendChild(debugIcon);\n\n debugIcon.addEventListener(\"click\", () => {\n components.forEach((comp) => {\n comp.classList.add('signElement');\n\n setTimeout(() => {\n comp.classList.remove('signElement');\n }, 3000);\n });\n });\n};\n\nexport default debug;\n", "import { version } from \"./_version\";\n\nimport message from \"./utils/message\";\nimport { ComponentFactory } from \"types/cumbiaTypes\";\nimport createApp, { componentFactory } from \"./core/createApp\";\nimport { CumbiaOptions } from \"types/cumbiaTypes\";\nimport debug from \"./utils/components/debug\";\n\nconst addComponents = (\n components: Record<string, ComponentFactory>,\n options: CumbiaOptions\n) => {\n if (!Object.keys(components).length) {\n return message.error(\"No components passed\");\n }\n\n Object.keys(components).forEach((componentName:string) => {\n const component: ComponentFactory = components[componentName];\n\n if (!componentName) {\n return message.error(\n \"Component name not defined, please give a name to your component\"\n );\n }\n\n if (componentFactory.has(componentName)) {\n message.warn(\n `Name collision detected. ${componentName} was previously defined`\n );\n }\n componentFactory.set(componentName, component);\n });\n\n document.addEventListener(\"DOMContentLoaded\", function() { \n message.info(`Initializing ${version}`);\n message.info(`daleeeeeeeeeeeeeeeeeee\n `);\n\n createApp(options);\n });\n};\n\nexport { debug };\n\n\n\nexport default addComponents;\n"],
"mappings": ";AAAO,IAAM,UAAU;;;ACAvB,IAAM,YAAY;AAClB,IAAM,QAAQ,CAAC,QAAa,QAAQ,MAAM,GAAG,aAAY;AACzD,IAAM,OAAO,CAAC,QAAa,QAAQ,KAAK,GAAG,aAAa;AACxD,IAAM,OAAO,CAAC,QAAa,QAAQ,KAAK,GAAG,aAAa;AAExD,IAAO,kBAAQ,EAAE,OAAO,MAAM;;;ACH9B,IAAM,cAAc,CAAC,YAAuC;AAC1D,QAAM,gBAAgB;AACtB,QAAM,eAA6B;AAEnC,QAAM,SAAS,QAAQ,iBAAiB,IAAI;AAE5C,SAAO,QAAQ,CAAC,iBAA8B;AAC5C,UAAM,cACJ,aAAa,aAAa,kBAAkB;AAE9C,QAAI,QAAQ,aAAa;AAEzB,QAAI,aAAa,YAAY,SAAS;AACpC,cAA2B,aAAc;AAAA;AAI3C,iBAAa,eAAe,EAAE,IAAI,cAAc;AAAA;AAGlD,SAAO;AAAA;AAGT,IAAO,sBAAQ;;;ACjBf,IAAM,mBACJ,CACE,SACA,WACA,YACA,EAAE,cAEJ,CAAC,MAAa;AACZ,QAAM,WAAW,UAAU;AAE3B,MAAI,SAAS;AACX,MAAE;AAAA;AAGJ,MAAI,CAAC,UAAU;AACb,WAAO,gBAAQ,KACb,cAAc;AAAA;AAIlB,QAAM,SAAS,oBAAY;AAE3B,WAAS;AAAA;AAGb,IAAO,iBAAQ;;;AC7Bf,IAAM,eAAe,CAAC,SAAsB,cAAgC;AAC1E,QAAM,iBAAiB;AAEvB,QAAM,UAAU,QAAQ,iBAAiB,IAAI;AAE7C,UAAQ,QAAQ,CAAC,kBAA+B;AAC9C,UAAM,aACJ,cAAc,aAAa,mBAAmB;AAChD,UAAM,aAAa,cAAc,aAAa;A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