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

fix(): Fix broken exports for filters that do not have a static defaults value. #10102

Merged
merged 4 commits into from
Aug 29, 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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

## [next]

- fix(): Fix broken exports for filters that do not have a static defaults value. [#10102](https://github.com/fabricjs/fabric.js/pull/10102)
- chore(): deprecate originX, originY [#10095](https://github.com/fabricjs/fabric.js/pull/10095)
- fix(SVGImport): Allow parsing of 'id' attribute that starts with a number [#10079](https://github.com/fabricjs/fabric.js/pull/10079)
- fix(filter): pixelate filter has non square pixels in webgl (#10081)
Expand Down
14 changes: 14 additions & 0 deletions src/filters/BaseFilter.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { BaseFilter } from './BaseFilter';

class SimpleFilter extends BaseFilter<'?'> {
static type = '?';
declare property: string;
}

describe('Extended filters', () => {
it('can export', () => {
const f = new SimpleFilter();
const serialized = f.toObject();
expect(serialized).toEqual({ type: '?' });
});
});
4 changes: 3 additions & 1 deletion src/filters/BaseFilter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -377,11 +377,13 @@ export class BaseFilter<

/**
* Returns object representation of an instance
* It will automatically export the default values of a filter,
* stored in the static defaults property.
* @return {Object} Object representation of an instance
*/
toObject(): { type: Name } & OwnProps {
const defaultKeys = Object.keys(
(this.constructor as typeof BaseFilter).defaults,
(this.constructor as typeof BaseFilter).defaults || {},
) as (keyof OwnProps)[];

return {
Expand Down
Loading