collapse-panel.d.ts.map 4.2 KB

1
  1. {"version":3,"sources":["../src/collapse-panel/collapse-panel.ts"],"names":[],"mappings":"","file":"collapse-panel.d.ts","sourcesContent":["import TComponent from '../common/component';\nimport config from '../common/config';\n\nconst { prefix } = config;\nconst name = `${prefix}-collapse-panel`;\n\nconst nextTick = () => new Promise((resolve) => setTimeout(resolve, 20));\n\nTComponent({\n externalClasses: [`${prefix}-class`],\n relations: {\n '../collapse/collapse': {\n type: 'ancestor',\n linked(this, target: WechatMiniprogram.Component.TrivialInstance) {\n this.parent = target;\n },\n },\n },\n properties: {\n name: null,\n title: null,\n extra: null,\n icon: String,\n label: String,\n disabled: Boolean,\n clickable: Boolean,\n border: {\n type: Boolean,\n value: true,\n },\n isLink: {\n type: Boolean,\n value: true,\n },\n labelWidth: {\n type: Number,\n value: 80,\n },\n content: null,\n },\n\n data: {\n contentHeight: 0,\n expanded: false,\n transition: false,\n classPrefix: name,\n classBasePrefix: prefix,\n },\n methods: {\n ready() {\n this.updateExpanded();\n },\n set(data: Record<string, object | any>) {\n this.setData(data);\n\n return new Promise((resolve) => wx.nextTick(resolve));\n },\n updateExpanded() {\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, accordion } = this.parent.data;\n const { children = [] } = this.parent;\n const { name } = this.properties;\n\n const index = children.indexOf(this);\n const currentName = name == null ? index : name;\n\n const expanded = accordion\n ? value === currentName\n : (value || []).some((name: string | number) => name === currentName);\n\n // const stack: string[] = [];\n const stack: any = [];\n\n if (expanded !== this.data.expanded) {\n stack.push(this.updateStyle(expanded));\n }\n\n stack.push(this.set({ index, expanded }));\n return Promise.all(stack)\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 getRect(\n selector: string,\n all?: boolean,\n ): 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 if (this.disabled) {\n return;\n }\n const { name } = this.properties;\n const { expanded } = this.data;\n const index = this.parent.children.indexOf(this);\n const currentName = name == null ? index : name;\n this.parent.switch(currentName, !expanded);\n },\n\n onTransitionEnd() {\n if (this.data.expanded) {\n this.setData({\n contentHeight: 'auto',\n });\n }\n },\n },\n});\n"]}