UNPKG

@oruga-ui/oruga-next

Version:

UI components for Vue.js and CSS framework agnostic

1 lines 4.22 kB
{"version":3,"file":"loading.cjs","sources":["../../src/components/loading/useLoadingProgrammatic.ts","../../src/components/loading/index.ts"],"sourcesContent":["import { type ComponentInternalInstance, type MaybeRefOrGetter } from \"vue\";\nimport {\n InstanceRegistry,\n ComponentProgrammatic,\n type ProgrammaticComponentOptions,\n type ProgrammaticExpose,\n} from \"../programmatic\";\n\nimport Loading from \"./Loading.vue\";\n\nimport type { LoadingProps } from \"./props\";\n\ndeclare module \"../../index\" {\n interface OrugaProgrammatic {\n loading: typeof LoadingProgrammatic;\n }\n}\n\n/** loading component programmatic instance registry **/\nconst registry = new InstanceRegistry<ComponentInternalInstance>();\n\n/** useLoadingProgrammatic composable options */\nexport type LoadingProgrammaticOptions = Readonly<LoadingProps> &\n ProgrammaticComponentOptions<typeof Loading>;\n\nconst LoadingProgrammatic = {\n /** Returns the number of registered active instances. */\n count: registry.count,\n /**\n * Create a new programmatic loading component instance.\n * @param options loading label string or loading component props object\n * @param target specify a target the component get rendered into\n * @returns ProgrammaticExpose\n */\n open(\n options: string | LoadingProgrammaticOptions,\n target?: MaybeRefOrGetter<string | HTMLElement | null>,\n ): ProgrammaticExpose<typeof Loading> {\n const _options: LoadingProgrammaticOptions =\n typeof options === \"string\" ? { label: options } : options;\n\n const componentProps: LoadingProps = {\n active: true, // set the active default state to true\n fullPage: false, // set the full page default state to false\n ...(_options as LoadingProps),\n };\n\n // create programmatic component\n return ComponentProgrammatic.open(Loading, {\n registry, // custom programmatic instance registry\n target, // target the component get rendered into\n props: componentProps, // component specific props\n onClose: _options.onClose, // on close event handler\n });\n },\n /** Close the last registred instance in the loading programmatic instance registry. */\n close(...args: unknown[]): void {\n registry.last()?.exposed?.close(...args);\n },\n /** Close all instances in the programmatic loading instance registry. */\n closeAll(...args: unknown[]): void {\n registry.walk((entry) => entry.exposed?.close(...args));\n },\n};\n\nexport default LoadingProgrammatic;\n","import type { App, Plugin } from \"vue\";\n\nimport Loading from \"./Loading.vue\";\nimport LoadingProgrammatic from \"./useLoadingProgrammatic\";\n\nimport {\n registerComponent,\n registerComponentProgrammatic,\n} from \"@/utils/plugins\";\n\n/** export loading specific types */\nexport type { LoadingProgrammaticOptions } from \"./useLoadingProgrammatic\";\n\n/** export loading plugin */\nexport default {\n install(app: App) {\n registerComponent(app, Loading);\n registerComponentProgrammatic(app, \"loading\", LoadingProgrammatic);\n },\n} as Plugin;\n\n/** export loading components & composables */\nexport { Loading as OLoading, LoadingProgrammatic };\n"],"names":["InstanceRegistry","ComponentProgrammatic","Loading","registerComponent","registerComponentProgrammatic"],"mappings":";;;;;;;AAmBA,MAAM,WAAW,IAAIA,gBAAAA,iBAA4C;AAMjE,MAAM,sBAAsB;AAAA;AAAA,EAExB,OAAO,SAAS;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAOhB,KACI,SACA,QACkC;AAClC,UAAM,WACF,OAAO,YAAY,WAAW,EAAE,OAAO,YAAY;AAEvD,UAAM,iBAA+B;AAAA,MACjC,QAAQ;AAAA;AAAA,MACR,UAAU;AAAA;AAAA,MACV,GAAI;AAAA,IACR;AAGO,WAAAC,gBAAA,sBAAsB,KAAKC,uDAAS;AAAA,MACvC;AAAA;AAAA,MACA;AAAA;AAAA,MACA,OAAO;AAAA;AAAA,MACP,SAAS,SAAS;AAAA;AAAA,IAAA,CACrB;AAAA,EACL;AAAA;AAAA,EAEA,SAAS,MAAuB;;AAC5B,yBAAS,KAAK,MAAd,mBAAiB,YAAjB,mBAA0B,MAAM,GAAG;AAAA,EACvC;AAAA;AAAA,EAEA,YAAY,MAAuB;AACtB,aAAA,KAAK,CAAC,UAAU;;AAAA,yBAAM,YAAN,mBAAe,MAAM,GAAG;AAAA,KAAK;AAAA,EAAA;AAE9D;ACjDA,MAAe,QAAA;AAAA,EACX,QAAQ,KAAU;AACdC,WAAA,kBAAkB,KAAKD,qDAAO;AACAE,yCAAA,KAAK,WAAW,mBAAmB;AAAA,EAAA;AAEzE;;;;"}