{"version":3,"sources":["decorators.ts"],"sourcesContent":["import { Datex, handleClassDecoratorWithOptionalArgs } from \"datex-core-legacy/mod.ts\";\nimport { handleClassDecoratorWithArgs, handleClassFieldDecoratorWithOptionalArgs } from \"datex-core-legacy/js_adapter/decorators.ts\";\nimport { getCloneKeys, Component } from \"../components/Component.ts\";\nimport { getCallerFile } from \"datex-core-legacy/utils/caller_metadata.ts\";\nimport { domContext, domUtils } from \"../app/dom-context.ts\";\nimport { getTransformWrapper } from \"../uix-dom/datex-bindings/transform-wrapper.ts\";\nimport { client_type } from \"datex-core-legacy/utils/constants.ts\";\nimport { Class, Decorators } from \"datex-core-legacy/datex_all.ts\";\nimport { Path } from \"datex-core-legacy/utils/path.ts\";\n\n\ntype ComponentClass = \n\ttypeof Component & \n\t(new (...args: unknown[]) => unknown) &  // fix abstract class\n\t{_init_module: string, _module: string, _use_resources: boolean} // access protected properties\n\nconst transformWrapper = getTransformWrapper(domUtils, domContext)\n\nexport function initDefaultOptions<T extends Record<string, unknown>>(url:string, componentClass: ComponentClass, defaultOptions?:Partial<Datex.DatexObjectPartialInit<T>>) {\n\turl = Object.hasOwn(componentClass, \"_init_module\") ?\n\t\tcomponentClass._init_module :\n\t\turl;\n\n\tif (!url) {\n\t\tconsole.log(new Error().stack)\n\t\tthrow new Error(\"Could not get the location of the UIX component '\"+componentClass.name+\"'. This should not happen\");\n\t}\n\n\tif (componentClass.prototype instanceof Component) {\n\n\t\t// set auto module (url from stack trace), not if module === null => resources was disabled with @NoResources\n\t\tif (url && componentClass._module !== null) componentClass._module = url;\n\t\t// default value of _use_resources is true (independent of parent class), if it was not overriden for this Component with @NoResources\n\t\tif (!Object.hasOwn(componentClass, '_use_resources')) componentClass._use_resources = true;\n\n\t\t// preload css files\n\t\tcomponentClass.preloadStylesheets?.();\n\n\t\tconst name = String(componentClass.name).split(/([A-Z][a-z]+)/).filter(t=>!!t).map(t=>t.toLowerCase()).join(\"-\"); // convert from CamelCase to snake-case\n\n\t\tconst datex_type = Datex.Type.get(\"std\", \"uix\", name);\n\n\t\t// js module reference\n\t\tif (client_type == \"deno\") {\n\t\t\tdatex_type.jsTypeDefModule = url;\n\t\t}\n\n\t\t// create template class for component\n\t\tconst new_class = Datex.createTemplateClass(componentClass, datex_type, true) as ComponentClass;\n\n\t\t// Object.defineProperty(componentClass, Datex.DX_TYPE, {set:(v)=>{console.log(\"set\",v,new Error().stack)}, get:()=>datex_type});\n\n\t\tcomponentClass[Datex.DX_TYPE] = datex_type;\n\n\t\tconst html_interface = Datex.Type.get('html').interface_config!;\n\t\tdatex_type.interface_config.cast_no_tuple = html_interface.cast_no_tuple; // handle casts from object\n\t\t\n\t\t//Object.assign(datex_type.interface_config, transformWrapper)\n\t\t\n\n\t\tdatex_type.interface_config.serialize = (value) => {\n\n\t\t\t// serialize html part (style, attr, content)\n\t\t\tconst html_serialized = <Record<string,any>> html_interface.serialize!(value);\n\n\t\t\thtml_serialized.p = {};\n\n\t\t\t// add additional properties (same as in Datex.Runtime.serializeValue)\n            const pointer = Datex.Pointer.getByValue(value)\n            for (const key of datex_type.visible_children){\n\t\t\t\thtml_serialized.p[key] = pointer?.shadow_object?.[key] ?? value[key];\n            }\n\n\t\t\t// add props object\n\t\t\thtml_serialized.p['props'] = pointer?.shadow_object?.props ?? value.props;\n\n\t\t\treturn html_serialized;\n\t\t}\n\n\t\t// define custom DOM element after everything is initialized\n\t\tdomContext.customElements.define(\"uix-\" + name, componentClass as typeof HTMLElement)\n\t\treturn new_class\n\t}\n\telse throw new Error(\"Invalid @defaultOptions - class must extend Component\")\n}\n\n/**\n * @NoResources: disable external resource loading (.css, .dx), must be located below the @defaultOptions decorator\n */\nexport function NoResources(value: typeof Component, context: ClassDecoratorContext) {\n\t// was called after @Component\n\tif (Object.hasOwn(value, '_module')) {\n\t\tthrow new Error(\"Please put the @NoResources decorator for the component '\"+context.name+\"' below the @defaultOptions decorator\");\n\t}\n\t(value as ComponentClass)._use_resources = false;\n}\n\n\nexport const ID_PROPS: unique symbol = Symbol(\"ID_PROPS\");\nexport const CONTENT_PROPS: unique symbol = Symbol(\"CONTENT_PROPS\");\nexport const CHILD_PROPS: unique symbol = Symbol(\"CHILD_PROPS\");\nexport const LAYOUT_PROPS: unique symbol = Symbol(\"LAYOUT_PROPS\");\nexport const IMPORT_PROPS: unique symbol = Symbol(\"IMPORT_PROPS\");\nexport const STANDALONE_PROPS: unique symbol = Symbol(\"STANDALONE_PROPS\");\nexport const ORIGIN_PROPS: unique symbol = Symbol(\"ORIGIN_PROPS\");\n\n/** \\@id to automatically assign a element id to a component property */\nexport function id(id:string): (value: undefined, context: ClassFieldDecoratorContext) => void\nexport function id(value: undefined, context: ClassFieldDecoratorContext): void\nexport function id(id:string|undefined, context?: ClassFieldDecoratorContext) {\n\treturn handleClassFieldDecoratorWithOptionalArgs([id], context, ([id], context) => {\n\t\tDecorators.setMetadata(context, ID_PROPS, id ?? context.name);\n\t})\n}\n\n\n/** \\@content to automatically assign a element id to a component property and add element to component content (#content) */\nexport function content(id:string): (value: undefined, context: ClassFieldDecoratorContext) => void\nexport function content(value: undefined, context: ClassFieldDecoratorContext): void\nexport function content(id:string|undefined, context?: ClassFieldDecoratorContext) {\n\treturn handleClassFieldDecoratorWithOptionalArgs([id], context, ([id], context) => {\n\t\tDecorators.setMetadata(context, CONTENT_PROPS, id ?? context.name);\n\t})\n}\n\n\n/** @layout to automatically assign a element id to a component property and add element to component content container layout (#layout) */\nexport function layout(id:string): (value: undefined, context: ClassFieldDecoratorContext) => void\nexport function layout(value: undefined, context: ClassFieldDecoratorContext): void\nexport function layout(id:string|undefined, context?: ClassFieldDecoratorContext) {\n\treturn handleClassFieldDecoratorWithOptionalArgs([id], context, ([id], context) => {\n\t\tDecorators.setMetadata(context, LAYOUT_PROPS, id ?? context.name);\n\t})\n}\n\n\n/** \\@child to automatically assign a element id to a component property and add element as a component child */\nexport function child(id:string): (value: undefined, context: ClassFieldDecoratorContext) => void\nexport function child(value: undefined, context: ClassFieldDecoratorContext): void\nexport function child(id:string|undefined, context?: ClassFieldDecoratorContext) {\n\treturn handleClassFieldDecoratorWithOptionalArgs([id], context, ([id], context) => {\n\t\tDecorators.setMetadata(context, CHILD_PROPS, id ?? context.name);\n\t})\n}\n\n/** \\@include to bind static properties */\nexport function include(resource?:string, export_name?:string): (value: undefined, context: ClassFieldDecoratorContext) => void\nexport function include(value: undefined, context: ClassFieldDecoratorContext): void\nexport function include(value: undefined|string, context?: ClassFieldDecoratorContext|string) {\n\t// resolve relative resource path\n\tif (typeof value == \"string\" && !Path.pathIsURL(value)) value = new Path(value, getCallerFile()).toString();\n\treturn handleClassFieldDecoratorWithOptionalArgs([value, context as string], context as ClassFieldDecoratorContext, \n\t\t([resource, export_name], context) => {\n\t\t\tDecorators.setMetadata(context, IMPORT_PROPS, [resource, export_name??context.name]);\n\t\t}\n\t)\n}\n\ntype frontendClassDecoratorOptions = {\n\tinheritedFields?: string[]\n}\n\n/** \n * \\@frontend \n * Exposes all methods of the class to the frontend context.\n */\nexport function standalone(value: Class, context: ClassDecoratorContext): void\n/** \n * \\@frontend \n * Exposes all methods of the class to the frontend context.\n * Optionally inherited properties and methods that should be exposed to the frontend can be specified.\n */\nexport function standalone(options: frontendClassDecoratorOptions): (value: Class, context: ClassDecoratorContext) => void\n/** \n * \\@frontend \n * Exposes the property or method to the frontend context.\n */\nexport function standalone(_value: undefined|((...args:any[])=>any), context: ClassFieldDecoratorContext|ClassMethodDecoratorContext): void\nexport function standalone(_value: undefined|Class|((...args:any[])=>any)|frontendClassDecoratorOptions, context?: ClassDecoratorContext|ClassFieldDecoratorContext|ClassMethodDecoratorContext): any {\n\t// class decorator\n\tif (!context || context.kind == \"class\") {\n\t\treturn handleClassDecoratorWithOptionalArgs(\n\t\t\t[_value as frontendClassDecoratorOptions|undefined], \n\t\t\t_value as Class, \n\t\t\tcontext as ClassDecoratorContext, \n\t\t\t([options], value, context) => {\n\t\t\t\tfor (const prop of [...Object.getOwnPropertyNames(value.prototype), ...options?.inheritedFields??[]]) {\n\t\t\t\t\tif (prop == \"constructor\") continue;\n\t\t\t\t\tDecorators.setMetadata({...(context as unknown as ClassFieldDecoratorContext), kind:\"field\",name:prop}, STANDALONE_PROPS, prop);\n\t\t\t\t}\n\t\t\t}\n\t\t)\n\t}\n\t// field/method decorator\n\telse {\n\t\tDecorators.setMetadata(context!, STANDALONE_PROPS, context!.name);\n\t}\n}\n\n// TODO: @frontend decorator for functions (equivalent to :frontend attributes)\n\n\n/** @bindOrigin to declare methods that work in a standlone context, but are executed in the original context */\nexport function bindOrigin(options:{datex:boolean}): (value: undefined, context: ClassFieldDecoratorContext|ClassMethodDecoratorContext) => void\nexport function bindOrigin(value: undefined, context: ClassFieldDecoratorContext|ClassMethodDecoratorContext): void\nexport function bindOrigin(options:{datex:boolean}|undefined, context?: ClassFieldDecoratorContext|ClassMethodDecoratorContext) {\n\treturn handleClassFieldDecoratorWithOptionalArgs([options], context as ClassFieldDecoratorContext, \n\t\t([options], context:ClassFieldDecoratorContext|ClassMethodDecoratorContext) => {\n\t\t\tDecorators.setMetadata(context, STANDALONE_PROPS, context.name);\n\t\t\tDecorators.setMetadata(context, ORIGIN_PROPS, options ?? {datex:false});\n\t\t}\n\t)\n}"],"names":["Datex","handleClassDecoratorWithOptionalArgs","handleClassFieldDecoratorWithOptionalArgs","Component","getCallerFile","domContext","domUtils","getTransformWrapper","client_type","Decorators","Path","initDefaultOptions","url","componentClass","defaultOptions","Object","hasOwn","_init_module","console","log","Error","stack","name","prototype","_module","_use_resources","preloadStylesheets","String","split","filter","t","map","toLowerCase","join","datex_type","Type","get","jsTypeDefModule","new_class","createTemplateClass","DX_TYPE","html_interface","interface_config","cast_no_tuple","serialize","value","html_serialized","p","pointer","Pointer","getByValue","key","visible_children","shadow_object","props","customElements","define","NoResources","context","ID_PROPS","Symbol","CONTENT_PROPS","CHILD_PROPS","LAYOUT_PROPS","IMPORT_PROPS","STANDALONE_PROPS","ORIGIN_PROPS","id","setMetadata","content","layout","child","include","pathIsURL","toString","resource","export_name","standalone","_value","kind","options","prop","getOwnPropertyNames","inheritedFields","bindOrigin","datex"],"mappings":"AAAA,SAASA,KAAK,EAAEC,oCAAoC,QAAQ,2BAA2B;AACvF,SAAuCC,yCAAyC,QAAQ,6CAA6C;AACrI,SAAuBC,SAAS,QAAQ,6BAA6B;AACrE,SAASC,aAAa,QAAQ,6CAA6C;AAC3E,SAASC,UAAU,EAAEC,QAAQ,QAAQ,wBAAwB;AAC7D,SAASC,mBAAmB,QAAQ,iDAAiD;AACrF,SAASC,WAAW,QAAQ,uCAAuC;AACnE,SAAgBC,UAAU,QAAQ,iCAAiC;AACnE,SAASC,IAAI,QAAQ,kCAAkC;AAQ9BH,oBAAoBD,UAAUD;AAEvD,OAAO,SAASM,mBAAsDC,GAAU,EAAEC,cAA8B,EAAEC,cAAwD;IAKzK,IAAI,CAJJF,CAAAA,MAAMG,OAAOC,MAAM,CAACH,gBAAgB,kBACnCA,eAAeI,YAAY,GAC3BL,GAAE,GAIF,MADAM,QAAQC,GAAG,CAAC,AAAIC,QAAQC,KAAK,GACvB,AAAID,MAAM,sDAAoDP,eAAeS,IAAI,GAAC;IAGzF,IAAIT,eAAeU,SAAS,YAAYpB,WAAW;QAG9CS,OAAOC,AAA2B,SAA3BA,eAAeW,OAAO,IAAWX,CAAAA,eAAeW,OAAO,GAAGZ,GAAE,GAElEG,OAAOC,MAAM,CAACH,gBAAgB,qBAAmBA,CAAAA,eAAeY,cAAc,GAAG,CAAA,CAAG,GAGzFZ,eAAea,kBAAkB;QAEjC,IAAMJ,OAAOK,OAAOd,eAAeS,IAAI,EAAEM,KAAK,CAAC,iBAAiBC,MAAM,CAACC,CAAAA,IAAG,CAAC,CAACA,GAAGC,GAAG,CAACD,CAAAA,IAAGA,EAAEE,WAAW,IAAIC,IAAI,CAAC,MAEtGC,aAAalC,MAAMmC,IAAI,CAACC,GAAG,CAAC,OAAO,OAAOd;QAG7B,UAAfd,eACH0B,CAAAA,WAAWG,eAAe,GAAG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