Skip to content

Commit

Permalink
Merge branch 'main' into feature/8380-in-viewport
Browse files Browse the repository at this point in the history
  • Loading branch information
fungairino authored May 1, 2024
2 parents cece926 + afb4f9f commit 92b27f9
Show file tree
Hide file tree
Showing 8 changed files with 121 additions and 7 deletions.
5 changes: 2 additions & 3 deletions scripts/__snapshots__/manifest.test.js.snap

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion scripts/manifest.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ function updateManifestToV3(manifestV2) {

// Extract host permissions
const { permissions, origins } = normalizeManifestPermissions(manifest);
manifest.permissions = [...permissions, "scripting"];
manifest.permissions = [...permissions, "scripting", "offscreen"];
manifest.host_permissions = origins;
// Sidebar Panel open() is only available in Chrome 116+
// https://developer.chrome.com/docs/extensions/reference/api/sidePanel#method-open
Expand Down
40 changes: 40 additions & 0 deletions src/bricks/effects/exportFileEffect.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/*
* Copyright (C) 2024 PixieBrix, Inc.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

import ExportFileEffect from "@/bricks/effects/exportFileEffect";
import { unsafeAssumeValidArg } from "@/runtime/runtimeTypes";
import { brickOptionsFactory } from "@/testUtils/factories/runtimeFactories";
import download from "downloadjs";

jest.mock("downloadjs");

const downloadMock = jest.mocked(download);

describe("ExportFileEffect", () => {
it("downloads GIF file", async () => {
const brick = new ExportFileEffect();

await brick.run(
unsafeAssumeValidArg({
data: "data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7",
}),
brickOptionsFactory(),
);

expect(downloadMock).toHaveBeenCalledOnce();
});
});
73 changes: 73 additions & 0 deletions src/bricks/effects/exportFileEffect.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
/*
* Copyright (C) 2024 PixieBrix, Inc.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

import { EffectABC } from "@/types/bricks/effectTypes";
import type { BrickArgs } from "@/types/runtimeTypes";
import type { Schema } from "@/types/schemaTypes";
import type { PlatformCapability } from "@/platform/capabilities";
import { propertiesToSchema } from "@/utils/schemaUtils";

/**
* Brick to export a data URL as a file.
* @since 1.8.14
*/
class ExportFileEffect extends EffectABC {
constructor() {
super(
"@pixiebrix/export/file",
"[Experimental] Export as File",
"Export/download a data URL as a file",
);
}

inputSchema: Schema = propertiesToSchema(
{
data: {
type: "string",
description:
"A data URL: https://developer.mozilla.org/en-US/docs/Web/HTTP/Basics_of_HTTP/Data_URLs",
},
filename: {
type: "string",
description: "An optional filename, or exclude to generate",
},
},
["data"],
);

override async getRequiredCapabilities(): Promise<PlatformCapability[]> {
// XXX: might introduce a "download" capability in the future, e.g., to support making the file as an artifact
// from a headless platform run
return ["dom"];
}

async effect({
filename = "exported",
data,
}: BrickArgs<{
filename?: string;
data: string;
}>): Promise<void> {
const { default: download } = await import(
/* webpackChunkName: "downloadjs" */ "downloadjs"
);

download(data, filename);
}
}

export default ExportFileEffect;
2 changes: 2 additions & 0 deletions src/bricks/effects/getAllEffects.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ import SetToolbarBadge from "@/bricks/effects/setToolbarBadge";
import InsertAtCursorEffect from "@/bricks/effects/InsertAtCursorEffect";
import AddDynamicTextSnippet from "@/bricks/effects/AddDynamicTextSnippet";
import AddTextSnippets from "@/bricks/effects/AddTextSnippets";
import ExportFileEffect from "@/bricks/effects/exportFileEffect";

function getAllEffects(): Brick[] {
return [
Expand All @@ -80,6 +81,7 @@ function getAllEffects(): Brick[] {
new AssignModVariable(),
new HideEffect(),
new ExportCsv(),
new ExportFileEffect(),
new HideSidebar(),
new ShowSidebar(),
new ToggleSidebar(),
Expand Down
2 changes: 1 addition & 1 deletion src/development/headers.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import registerBuiltinBricks from "@/bricks/registerBuiltinBricks";
import registerContribBlocks from "@/contrib/registerContribBlocks";

// Maintaining this number is a simple way to ensure bricks don't accidentally get dropped
const EXPECTED_HEADER_COUNT = 136;
const EXPECTED_HEADER_COUNT = 137;

registerBuiltinBricks();
registerContribBlocks();
Expand Down
3 changes: 1 addition & 2 deletions src/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,7 @@
"webNavigation",
"contextMenus",
"<all_urls>",
"alarms",
"offscreen"
"alarms"
],
"devtools_page": "devtools.html",
"externally_connectable": {
Expand Down
1 change: 1 addition & 0 deletions src/tsconfig.strictNullChecks.json
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@
"./bricks/effects/error.ts",
"./bricks/effects/event.ts",
"./bricks/effects/exportCsv.ts",
"./bricks/effects/exportFileEffect.ts",
"./bricks/effects/forms.ts",
"./bricks/effects/hide.ts",
"./bricks/effects/highlight.ts",
Expand Down

0 comments on commit 92b27f9

Please sign in to comment.