Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[DRAFT] Custom Event & File Polyfills #865

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions packages/php-wasm/progress/src/lib/custom-event.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
export const CustomEvent =
globalThis.CustomEvent ??
class extends globalThis.Event {
detail = null;
constructor(
name: string,
options: {
detail?: any;
bubbles?: boolean;
cancellable?: boolean;
composed?: boolean;
} = {}
) {
super(name, options);
this.detail = options.detail;
}
};
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { CustomEvent } from './custom-event';

/*
* An approximate total file size to use when the actual
* total number of bytes is missing.
Expand Down
1 change: 1 addition & 0 deletions packages/php-wasm/progress/src/lib/progress-observer.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { CustomEvent } from './custom-event';
import { DownloadProgress } from './emscripten-download-monitor';

export type ProgressMode =
Expand Down
1 change: 1 addition & 0 deletions packages/php-wasm/progress/src/lib/progress-tracker.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { CustomEvent } from './custom-event';
/**
* Options for customizing the progress tracker.
*/
Expand Down
26 changes: 26 additions & 0 deletions packages/playground/blueprints/src/lib/steps/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,32 @@ export async function fileToUint8Array(file: File) {
* Import the polyfilled File class below to ensure its buffer is available to
* functions like writeFile (./client-methods.ts) and fileToUint8Array (above).
*/

globalThis.File =
globalThis.File ||
class extends Blob {
_name: string;
lastModified: number | undefined;
constructor(
bits: any,
name: string,
options: { type?: string; lastModified?: number } = {}
) {
super(bits);
if (options.lastModified) {
this.lastModified = options.lastModified;
}
if (name) {
this._name = name;
} else {
this._name = '';
}
}
override get name() {
return this._name;
}
};

class FilePolyfill extends File {
buffers: BlobPart[];
constructor(buffers: BlobPart[], name: string) {
Expand Down
Loading