{"version":3,"sources":["src/components/context/consumer/consumes-decorator.tsx"],"names":["Consumes","args","target","propertyKey","context","elementAttribute","contextKey","componentWillLoad","connectedCallback","disconnectedCallback","__syContextConsumesKeys","find","el","push","__syContextConsumesMount","element","this","constructor","name","__syContextConsumesElements","forEach","key","changeValue","newValue","dispatchEvent","CustomEvent","detail","bubbles","composed","__syContextConsumesWrapped","async","hookReturn","call","unsubscribe"],"mappings":"SAEgBA,EAASC,GACvB,MAAO,CAACC,EAAaC,KACnB,MAAMC,SAAiBH,IAAS,SAAWA,EAAOA,GAAMG,QACxD,MAAMC,SAA0BJ,IAAS,SAAW,KAAOA,GAAMI,kBAAoB,KACrF,MAAMC,EAAaF,GAAWD,EAE9B,MAAMI,kBAAEA,EAAiBC,kBAAEA,EAAiBC,qBAAEA,GAAyBP,EAEvEA,EAAOQ,wBAA0BR,EAAOQ,yBAA2B,GACnE,IAAKR,EAAOQ,wBAAwBC,MAAMC,GAAOA,EAAGN,aAAeA,IAAa,CAC9EJ,EAAOQ,wBAAwBG,KAAK,CAAEP,WAAAA,EAAYH,YAAAA,IAGpDD,EAAOY,yBAA2B,WAChC,MAAMC,EAAUC,KAAKX,GACrB,IAAKU,EAAS,CACZ,KAAM,6EAA6EC,MAAMC,aAAaC,uHAGxGF,KAAKG,4BAA8BH,KAAKG,6BAA+B,GAEvEH,KAAKN,wBAAwBU,SAASC,IACpC,IAAKL,KAAKG,4BAA4BE,EAAIf,YAAa,CACrDU,KAAKG,4BAA4BE,EAAIf,YAAc,CACjDe,IAAAA,EACAC,YAAcC,IACZP,KAAKK,EAAIlB,aAAeoB,QAMhCP,KAAKN,wBAAwBU,SAASC,IACpCN,GAASS,cACP,IAAIC,YAAwC,gCAAiC,CAC3EC,OAAQ,CACNtB,QAASiB,EAAIf,WACbM,GAAII,KAAKG,4BAA4BE,EAAIf,aAE3CqB,QAAS,KACTC,SAAU,YAMlB,IAAK1B,EAAO2B,2BAA4B,CACtC3B,EAAO2B,2BAA6B,KACpC3B,EAAOK,kBAAoBuB,iBACzB,MAAMC,EAAaxB,GAAmByB,KAAKhB,MAC3CA,KAAKF,2BACL,OAAOiB,GAET7B,EAAOM,kBAAoBsB,iBACzB,MAAMC,EAAavB,GAAmBwB,KAAKhB,MAC3CA,KAAKF,2BACL,OAAOiB,GAET7B,EAAOO,qBAAuBqB,iBAC5B,MAAMC,EAAatB,GAAsBuB,KAAKhB,MAC9CA,KAAKN,wBAAwBU,SAASC,IACpC,GAAIL,KAAKG,4BAA4BE,EAAIf,aAAa2B,YAAa,CACjEjB,KAAKG,4BAA4BE,EAAIf,aAAa2B,kBAItD,OAAOF","sourcesContent":["import { SubscribeConsumerEventData } from './consumer';\n\nexport function Consumes(args?: string | { context?: string; elementAttribute?: string }) {\n return (target: any, propertyKey: string): void => {\n const context = typeof args === 'string' ? args : args?.context;\n const elementAttribute = typeof args === 'string' ? 'el' : args?.elementAttribute || 'el';\n const contextKey = context ?? propertyKey;\n\n const { componentWillLoad, connectedCallback, disconnectedCallback } = target;\n\n target.__syContextConsumesKeys = target.__syContextConsumesKeys || [];\n if (!target.__syContextConsumesKeys.find((el) => el.contextKey === contextKey)) {\n target.__syContextConsumesKeys.push({ contextKey, propertyKey });\n }\n\n target.__syContextConsumesMount = function () {\n const element = this[elementAttribute];\n if (!element) {\n throw `@Consumes decorators requires '@Element' to be defined in the component (\"${this?.constructor?.name}\"). The @Element attribute name is, by default, 'el'. You can change it with a parameter in @Consumes decorator.`;\n }\n\n this.__syContextConsumesElements = this.__syContextConsumesElements || {};\n\n this.__syContextConsumesKeys.forEach((key) => {\n if (!this.__syContextConsumesElements[key.contextKey]) {\n this.__syContextConsumesElements[key.contextKey] = {\n key,\n changeValue: (newValue) => {\n this[key.propertyKey] = newValue;\n },\n };\n }\n });\n\n this.__syContextConsumesKeys.forEach((key) => {\n element?.dispatchEvent(\n new CustomEvent('syContextConsumerDidSubscribe', {\n detail: {\n context: key.contextKey,\n el: this.__syContextConsumesElements[key.contextKey],\n },\n bubbles: true,\n composed: true,\n }),\n );\n });\n };\n\n if (!target.__syContextConsumesWrapped) {\n target.__syContextConsumesWrapped = true;\n target.componentWillLoad = async function () {\n const hookReturn = componentWillLoad?.call(this);\n this.__syContextConsumesMount();\n return hookReturn;\n };\n target.connectedCallback = async function () {\n const hookReturn = connectedCallback?.call(this);\n this.__syContextConsumesMount();\n return hookReturn;\n };\n target.disconnectedCallback = async function () {\n const hookReturn = disconnectedCallback?.call(this);\n this.__syContextConsumesKeys.forEach((key) => {\n if (this.__syContextConsumesElements[key.contextKey]?.unsubscribe) {\n this.__syContextConsumesElements[key.contextKey]?.unsubscribe();\n }\n });\n\n return hookReturn;\n };\n }\n };\n}\n"]}