(window: Window & typeof globalThis)
| 96 | } |
| 97 | |
| 98 | function createDataTransferStub(window: Window & typeof globalThis) { |
| 99 | return new (class DataTransferStub implements DataTransfer { |
| 100 | getData(format: string) { |
| 101 | const type = normalizeFormat(format) |
| 102 | const match = |
| 103 | this.items.find(getTypeMatcher(type, true)) ?? |
| 104 | this.items.find(getTypeMatcher(type, false)) |
| 105 | |
| 106 | let text = '' |
| 107 | match?.getAsString(t => { |
| 108 | text = t |
| 109 | }) |
| 110 | |
| 111 | return text |
| 112 | } |
| 113 | |
| 114 | setData(format: string, data: string) { |
| 115 | const type = normalizeFormat(format) |
| 116 | const matchIndex = this.items.findIndex(getTypeMatcher(type, true)) |
| 117 | |
| 118 | const item = new DataTransferItemStub(data, type) as DataTransferItem |
| 119 | if (matchIndex >= 0) { |
| 120 | this.items.splice(matchIndex, 1, item) |
| 121 | } else { |
| 122 | this.items.push(item) |
| 123 | } |
| 124 | } |
| 125 | |
| 126 | clearData(format?: string) { |
| 127 | if (format) { |
| 128 | const type = normalizeFormat(format) |
| 129 | const matchIndex = this.items.findIndex(getTypeMatcher(type, true)) |
| 130 | |
| 131 | if (matchIndex >= 0) { |
| 132 | this.items.remove(matchIndex) |
| 133 | } |
| 134 | } else { |
| 135 | this.items.clear() |
| 136 | } |
| 137 | } |
| 138 | |
| 139 | dropEffect: DataTransfer['dropEffect'] = 'none' |
| 140 | effectAllowed: DataTransfer['effectAllowed'] = 'uninitialized' |
| 141 | |
| 142 | readonly items = new DataTransferItemListStub() |
| 143 | readonly files = createFileList(window, []) |
| 144 | |
| 145 | get types() { |
| 146 | const t = [] |
| 147 | if (this.files.length) { |
| 148 | t.push('Files') |
| 149 | } |
| 150 | this.items.forEach(i => t.push(i.type)) |
| 151 | |
| 152 | Object.freeze(t) |
| 153 | |
| 154 | return t |
| 155 | } |
no outgoing calls
no test coverage detected