1 |
- {"version":3,"sources":["../src/collapse/collapse-panel.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAe,gBAAgB,EAAE,MAAM,qBAAqB,CAAC;AAGpF,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,QAAQ,CAAC;AAOnD,MAAM,WAAW,kBAAmB,SAAQ,oBAAoB;CAAG;AAEnE,MAAM,CAAC,OAAO,OAAO,aAAc,SAAQ,cAAc;IACvD,eAAe,WAAuB;IAEtC,SAAS,EAAE,gBAAgB,CAezB;IAEF,UAAU,uBAAS;IAEnB,IAAI;;;;;;;MAOF;IAEF,OAAO;kBACK,OAAO,MAAM,EAAE,MAAM,GAAG,GAAG,CAAC;;0BA0BpB,MAAM,QAAQ,OAAO,GAAG,QAAQ,kBAAkB,gCAAgC,CAAC;8BAiB/E,OAAO;;;MAgC7B;CACH","file":"collapse-panel.d.ts","sourcesContent":["import { SuperComponent, wxComponent, RelationsOptions } from '../common/src/index';\nimport config from '../common/config';\nimport props from './collapse-panel-props';\nimport type { TdCollapsePanelProps } from './type';\n\nconst { prefix } = config;\nconst name = `${prefix}-collapse-panel`;\n\nconst nextTick = () => new Promise((resolve) => setTimeout(resolve, 20));\n\nexport interface CollapsePanelProps extends TdCollapsePanelProps {}\n@wxComponent()\nexport default class CollapsePanel extends SuperComponent {\n externalClasses = [`${prefix}-class`];\n\n relations: RelationsOptions = {\n './collapse': {\n type: 'ancestor',\n linked(target: WechatMiniprogram.Component.TrivialInstance) {\n this.parent = target;\n const { value, defaultExpandAll, expandMutex, expandIcon, disabled } = target.properties;\n const activeValues = defaultExpandAll && !expandMutex ? [this.properties.value] : value;\n\n this.setData({\n ultimateExpandIcon: expandIcon || this.properties.expandIcon,\n ultimateDisabled: this.properties.disabled == null ? disabled : this.properties.disabled,\n });\n this.updateExpanded(activeValues);\n },\n },\n };\n\n properties = props;\n\n data = {\n contentHeight: 0,\n expanded: false,\n classPrefix: name,\n classBasePrefix: prefix,\n ultimateExpandIcon: false,\n ultimateDisabled: false,\n };\n\n methods = {\n set(data: Record<string, object | any>) {\n this.setData(data);\n\n return new Promise((resolve) => wx.nextTick(resolve));\n },\n updateExpanded(activeValues) {\n if (!this.parent) {\n return Promise.resolve()\n .then(nextTick)\n .then(() => {\n const data: Record<string, boolean | string> = { transition: true };\n if (this.data.expanded) {\n data.contentHeight = 'auto';\n }\n this.setData(data);\n });\n }\n\n const { value } = this.properties;\n const expanded = activeValues.includes(value);\n\n if (expanded === this.properties.expanded) return;\n\n this.setData({ expanded });\n this.updateStyle(expanded);\n },\n getRect(selector: string, all?: boolean): Promise<WechatMiniprogram.BoundingClientRectCallbackResult> {\n return new Promise((resolve) => {\n wx.createSelectorQuery()\n .in(this as WechatMiniprogram.Component.TrivialInstance)\n [all ? 'selectAll' : 'select'](selector)\n .boundingClientRect((rect) => {\n if (all && Array.isArray(rect) && rect.length) {\n resolve(rect);\n }\n\n if (!all && rect) {\n resolve(rect);\n }\n })\n .exec();\n });\n },\n updateStyle(expanded: boolean) {\n return this.getRect(`.${name}__content`)\n .then((rect: WechatMiniprogram.BoundingClientRectCallbackResult) => rect.height)\n .then((height: number) => {\n if (expanded) {\n return this.set({\n contentHeight: height ? `${height}px` : 'auto',\n });\n }\n\n return this.set({ contentHeight: `${height}px` })\n .then(nextTick)\n .then(() => this.set({ contentHeight: 0 }));\n });\n },\n\n onClick() {\n const { ultimateDisabled } = this.data;\n const { value } = this.properties;\n\n if (ultimateDisabled) return;\n\n this.parent.switch(value);\n },\n\n onTransitionEnd() {\n if (this.data.expanded) {\n this.setData({\n contentHeight: 'auto',\n });\n }\n },\n };\n}\n"]}
|