UNPKG

@extclp/vexip-ui

Version:

A Vue 3 UI library, Highly customizability, full TypeScript, performance pretty good

1 lines 4.85 kB
{"version":3,"file":"table-summary.mjs","sources":["../../../components/table/table-summary.ts"],"sourcesContent":["import { defineComponent, inject, onBeforeUnmount, reactive, renderSlot, watch } from 'vue'\r\n\r\nimport { useProps } from '@vexip-ui/config'\r\nimport { isNull } from '@vexip-ui/utils'\r\nimport { tableSummaryProps } from './props'\r\nimport { TABLE_ACTIONS } from './symbol'\r\n\r\nimport type { SummaryWithKey } from './symbol'\r\n\r\ntype SummaryPropKey = keyof typeof tableSummaryProps\r\n\r\nconst propKeys = Object.keys(tableSummaryProps) as SummaryPropKey[]\r\nconst aliases: Partial<Record<SummaryPropKey, string>> = {\r\n idKey: 'key',\r\n}\r\nconst ignoredProps: SummaryPropKey[] = ['renderer']\r\nconst triggerProps: SummaryPropKey[] = ['idKey', 'cellSpan', 'order', 'above']\r\n\r\nconst funcProp = {\r\n default: null,\r\n isFunc: true,\r\n static: true,\r\n}\r\n\r\nexport default defineComponent({\r\n name: 'TableSummary',\r\n props: tableSummaryProps,\r\n setup(_props, { slots }) {\r\n const props = useProps('tableSummary', _props, {\r\n idKey: {\r\n default: null,\r\n validator: value => !isNull(value),\r\n static: true,\r\n },\r\n class: null,\r\n style: null,\r\n attrs: null,\r\n cellSpan: funcProp,\r\n order: {\r\n default: 0,\r\n static: true,\r\n },\r\n above: {\r\n default: false,\r\n static: true,\r\n },\r\n meta: null,\r\n renderer: funcProp,\r\n })\r\n\r\n const tableAction = inject(TABLE_ACTIONS, null)\r\n const options = reactive({}) as SummaryWithKey\r\n\r\n for (const key of propKeys) {\r\n if (ignoredProps.includes(key)) continue\r\n\r\n const aliasKey = (aliases[key] || key) as keyof SummaryWithKey\r\n const trigger = triggerProps.includes(key)\r\n\r\n ;(options[aliasKey] as any) = props[key]\r\n\r\n watch(\r\n () => props[key],\r\n value => {\r\n ;(options[aliasKey] as any) = value\r\n trigger\r\n ? tableAction?.updateSummaries()\r\n : tableAction?.setSummaryProp(options.key, key, value)\r\n },\r\n )\r\n }\r\n\r\n watch(() => props.renderer, setRenderer)\r\n\r\n setRenderer()\r\n tableAction?.increaseSummary(options)\r\n\r\n onBeforeUnmount(() => {\r\n tableAction?.decreaseSummary(options)\r\n })\r\n\r\n function setRenderer() {\r\n options.renderer = data => {\r\n if (typeof data.column.summaryRenderer === 'function') {\r\n return data.column.summaryRenderer({\r\n ...data,\r\n summary: options,\r\n })\r\n }\r\n\r\n if (typeof slots.default === 'function') {\r\n return renderSlot(slots, 'default', data)\r\n }\r\n\r\n if (typeof props.renderer === 'function') {\r\n return props.renderer(data)\r\n }\r\n\r\n return ''\r\n }\r\n }\r\n\r\n return () => null\r\n },\r\n})\r\n"],"names":["propKeys","tableSummaryProps","aliases","ignoredProps","triggerProps","funcProp","TableSummary","defineComponent","_props","slots","props","useProps","value","isNull","tableAction","inject","TABLE_ACTIONS","options","reactive","key","aliasKey","trigger","watch","setRenderer","onBeforeUnmount","data","renderSlot"],"mappings":";;;;;AAWA,MAAMA,IAAW,OAAO,KAAKC,CAAiB,GACxCC,IAAmD;AAAA,EACvD,OAAO;AACT,GACMC,IAAiC,CAAC,UAAU,GAC5CC,IAAiC,CAAC,SAAS,YAAY,SAAS,OAAO,GAEvEC,IAAW;AAAA,EACf,SAAS;AAAA,EACT,QAAQ;AAAA,EACR,QAAQ;AACV,GAEAC,IAAeC,EAAgB;AAAA,EAC7B,MAAM;AAAA,EACN,OAAON;AAAA,EACP,MAAMO,GAAQ,EAAE,OAAAC,KAAS;AACjB,UAAAC,IAAQC,EAAS,gBAAgBH,GAAQ;AAAA,MAC7C,OAAO;AAAA,QACL,SAAS;AAAA,QACT,WAAW,CAAAI,MAAS,CAACC,EAAOD,CAAK;AAAA,QACjC,QAAQ;AAAA,MACV;AAAA,MACA,OAAO;AAAA,MACP,OAAO;AAAA,MACP,OAAO;AAAA,MACP,UAAUP;AAAA,MACV,OAAO;AAAA,QACL,SAAS;AAAA,Q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