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

[FEATURE] Add simple way to enable/disable layout fill #435

Merged
merged 4 commits into from
Mar 21, 2024
Merged
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
6 changes: 2 additions & 4 deletions packages/sdk/src/controllers/ClipboardController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ export class ClipboardController {
const result = await res.pasteFrames(clipboardData);

return getEditorResponseData<null>(result);
}
};

/**
* This method will get the content type of the OS clipboard
Expand All @@ -76,7 +76,5 @@ export class ClipboardController {
const result = await res.getClipboardContentType(clipboardData);

return getEditorResponseData<ClipboardContentType>(result);
}
};
}


1 change: 0 additions & 1 deletion packages/sdk/src/controllers/FrameController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -393,7 +393,6 @@ export class FrameController {
return res.duplicateFrames(ids).then((result) => getEditorResponseData<Id>(result));
};


/**
* This method sets or removes the image source to the ImageFrame
* @param imageFrameId the id of the imageFrame where an image needs to be assigned to
Expand Down
22 changes: 17 additions & 5 deletions packages/sdk/src/controllers/LayoutController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -219,26 +219,38 @@ export class LayoutController {

/**
* This method sets the fill color of a specific layout.
* Note: Depending on the layout intent, some colors might not be valid (eg opacity for digitalAnimated, any color for print)
*
* Note: Depending on the layout intent, some colors might not be valid (eg opacity for digitalAnimated, any color for print)
*
* @param id the id of a specific layout
* @param color the color that will be used for the layout
*/
setFillColor = async (id: Id, color: ColorUsage) => {
const res = await this.#editorAPI;
return res.setLayoutFillColor(id, JSON.stringify(color)).then((result) => getEditorResponseData<null>(result));
}
};

/**
* This is a convenience method to enable or disable the fill color of a specific layout.
* Note: Depending on the layout intent, disabling might not be valid (eg disabling for digitalAnimated)
*
* @param id the id of a specific layout
* @param enabled whether the fill color should be enabled or disabled
*/
setFillColorEnabled = async (id: Id, enabled: boolean) => {
const res = await this.#editorAPI;
return res.setLayoutFillColorEnabled(id, enabled).then((result) => getEditorResponseData<null>(result));
};

/**
* This method resets the fill color of a specific layout to its original (inherited) value.
* Note: Calling this on the top layout is not valid
*
*
* @param id The id of the (child) layout to reset the fill color for
*/
resetFillColor = async (id: Id) => {
const res = await this.#editorAPI;
return res.resetLayoutFillColor(id).then((result) => getEditorResponseData<null>(result));
}
};

/**
* This method sets the bleed value of a specific layout.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ describe('ClipboardController', () => {
let mockedClipboardController: ClipboardController;

const clipboardValue = 'a json string frame';
const writeText = jest.fn().mockResolvedValue('');;
const writeText = jest.fn().mockResolvedValue('');
const readText = jest.fn().mockResolvedValue(clipboardValue);

Object.assign(navigator, {
Expand All @@ -23,7 +23,6 @@ describe('ClipboardController', () => {
getClipboardContentType: async () => getEditorResponseData(castToEditorResponse(null)),
};


beforeEach(() => {
mockedClipboardController = new ClipboardController(mockEditorApi);
jest.spyOn(mockEditorApi, 'copyFrames');
Expand Down
10 changes: 10 additions & 0 deletions packages/sdk/src/tests/controllers/LayoutController.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ const mockedEditorApi: EditorAPI = {
setLayoutIntent: async () => getEditorResponseData(castToEditorResponse(null)),
resetLayoutIntent: async () => getEditorResponseData(castToEditorResponse(null)),
setLayoutFillColor: async () => getEditorResponseData(castToEditorResponse(null)),
setLayoutFillColorEnabled: async () => getEditorResponseData(castToEditorResponse(null)),
resetLayoutFillColor: async () => getEditorResponseData(castToEditorResponse(null)),
updateLayoutBleed: async () => getEditorResponseData(castToEditorResponse(null)),
};
Expand Down Expand Up @@ -56,6 +57,7 @@ beforeEach(() => {
jest.spyOn(mockedEditorApi, 'resetLayoutIntent');
jest.spyOn(mockedEditorApi, 'setLayoutFillColor');
jest.spyOn(mockedEditorApi, 'resetLayoutFillColor');
jest.spyOn(mockedEditorApi, 'setLayoutFillColorEnabled');
jest.spyOn(mockedEditorApi, 'updateLayoutBleed');

mockId = mockSelectPage.layoutId;
Expand Down Expand Up @@ -171,6 +173,14 @@ describe('LayoutController', () => {
await mockedLayoutController.resetFillColor('1');
expect(mockedEditorApi.resetLayoutFillColor).toHaveBeenCalledTimes(1);
});
it('Should be possible to set the layout fill color to disabled', async () => {
await mockedLayoutController.setFillColorEnabled('1', false);
expect(mockedEditorApi.setLayoutFillColorEnabled).toHaveBeenCalledTimes(1);
});
it('Should be possible to set the layout fill color to enabled', async () => {
await mockedLayoutController.setFillColorEnabled('1', true);
expect(mockedEditorApi.setLayoutFillColorEnabled).toHaveBeenCalledTimes(1);
});
describe('bleed', () => {
it('Should be possible set the combined bleed value', async () => {
await mockedLayoutController.setBleedValue('1', '5');
Expand Down
2 changes: 1 addition & 1 deletion packages/sdk/src/types/ClipboardTypes.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export enum ClipboardContentType {
frame = 'frame',
unknown = 'unknown'
unknown = 'unknown',
}
1 change: 1 addition & 0 deletions packages/sdk/src/types/LayoutTypes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ export type Layout = {
intent: PropertyState<LayoutIntent>;
bleed: PropertyState<LayoutBleed>;
fillColor: PropertyState<ColorUsage>;
fillColorEnabled: PropertyState<ColorUsage>;
};

// used by onLayoutsChanged
Expand Down
Loading