(selector: string)
| 6 | }, 300); |
| 7 | |
| 8 | export function restoreScroll(selector: string) { |
| 9 | return <ElemClass extends ReactiveElement>( |
| 10 | proto: ElemClass, |
| 11 | propertyKey: string |
| 12 | ) => { |
| 13 | if (typeof propertyKey === "object") { |
| 14 | throw new Error("This decorator does not support this compilation type."); |
| 15 | } |
| 16 | |
| 17 | const connectedCallback = proto.connectedCallback; |
| 18 | proto.connectedCallback = function () { |
| 19 | connectedCallback.call(this); |
| 20 | |
| 21 | const scrollPos = this[propertyKey]; |
| 22 | |
| 23 | if (scrollPos) { |
| 24 | this.updateComplete.then(() => { |
| 25 | const target = this.renderRoot.querySelector(selector); |
| 26 | if (!target) { |
| 27 | return; |
| 28 | } |
| 29 | setTimeout(() => { |
| 30 | target.scrollTop = scrollPos; |
| 31 | }, 0); |
| 32 | }); |
| 33 | } |
| 34 | }; |
| 35 | |
| 36 | const descriptor = Object.getOwnPropertyDescriptor(proto, propertyKey); |
| 37 | let newDescriptor: PropertyDescriptor; |
| 38 | if (descriptor === undefined) { |
| 39 | newDescriptor = { |
| 40 | get(this: ReactiveElement) { |
| 41 | return ( |
| 42 | this[`__${String(propertyKey)}`] || history.state?.scrollPosition |
| 43 | ); |
| 44 | }, |
| 45 | set(this: ReactiveElement, value) { |
| 46 | throttleReplaceState(value); |
| 47 | this[`__${String(propertyKey)}`] = value; |
| 48 | }, |
| 49 | configurable: true, |
| 50 | enumerable: true, |
| 51 | }; |
| 52 | } else { |
| 53 | const oldSetter = descriptor.set; |
| 54 | newDescriptor = { |
| 55 | ...descriptor, |
| 56 | set(this: ReactiveElement, value) { |
| 57 | throttleReplaceState(value); |
| 58 | this[`__${String(propertyKey)}`] = value; |
| 59 | oldSetter?.call(this, value); |
| 60 | }, |
| 61 | }; |
| 62 | } |
| 63 | Object.defineProperty(proto, propertyKey, newDescriptor); |
| 64 | }; |
| 65 | } |
no outgoing calls
no test coverage detected
searching dependent graphs…