Skip to content

Commit

Permalink
Update TS
Browse files Browse the repository at this point in the history
  • Loading branch information
artf committed Jun 16, 2024
1 parent 7d94150 commit a62f927
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 12 deletions.
2 changes: 1 addition & 1 deletion src/common/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ interface NOOP {}

export type Debounced = Function & { cancel(): void };

export type SetOptions = Backbone.ModelSetOptions & { avoidStore?: boolean; inline?: boolean };
export type SetOptions = Backbone.ModelSetOptions & { avoidStore?: boolean };

export type AddOptions = Backbone.AddOptions & { temporary?: boolean; action?: string };

Expand Down
5 changes: 3 additions & 2 deletions src/css_composer/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ import { ItemManagerModule } from '../abstract/Module';
import EditorModel from '../editor/model/Editor';
import Component from '../dom_components/model/Component';
import { ObjectAny, PrevToNewIdMap } from '../common';
import { UpdateStyleOptions } from '../domain_abstract/model/StyleableModel';

/** @private */
interface RuleOptions {
Expand All @@ -53,15 +54,15 @@ interface RuleOptions {
}

/** @private */
interface SetRuleOptions extends RuleOptions {
interface SetRuleOptions extends RuleOptions, UpdateStyleOptions {
/**
* If the rule exists already, merge passed styles instead of replacing them.
*/
addStyles?: boolean;
}

/** @private */
export interface GetSetRuleOptions {
export interface GetSetRuleOptions extends UpdateStyleOptions {
state?: string;
mediaText?: string;
addOpts?: ObjectAny;
Expand Down
13 changes: 7 additions & 6 deletions src/dom_components/model/Component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import {
keys,
} from 'underscore';
import { shallowDiff, capitalize, isEmptyObj, isObject, toLowerCase } from '../../utils/mixins';
import StyleableModel, { StyleProps } from '../../domain_abstract/model/StyleableModel';
import StyleableModel, { StyleProps, UpdateStyleOptions } from '../../domain_abstract/model/StyleableModel';
import { Model } from 'backbone';
import Components from './Components';
import Selector from '../../selector_manager/model/Selector';
Expand All @@ -22,7 +22,6 @@ import EditorModel from '../../editor/model/Editor';
import {
AddComponentsOption,
ComponentAdd,
ComponentAddType,
ComponentDefinition,
ComponentDefinitionDefined,
ComponentOptions,
Expand All @@ -44,6 +43,8 @@ import ItemView from '../../navigator/view/ItemView';

export interface IComponent extends ExtractMethods<Component> {}

export interface SetAttrOptions extends SetOptions, UpdateStyleOptions {}

const escapeRegExp = (str: string) => {
return str.replace(/[|\\{}()[\]^$+*?.]/g, '\\$&');
};
Expand Down Expand Up @@ -541,7 +542,7 @@ export default class Component extends StyleableModel<ComponentProperties> {
* Emit changes for each updated attribute
* @private
*/
attrUpdated(m: any, v: any, opts: any = {}) {
attrUpdated(m: any, v: any, opts: SetAttrOptions = {}) {
const attrs = this.get('attributes')!;
// Handle classes
const classes = attrs.class;
Expand Down Expand Up @@ -570,7 +571,7 @@ export default class Component extends StyleableModel<ComponentProperties> {
* @example
* component.setAttributes({ id: 'test', 'data-key': 'value' });
*/
setAttributes(attrs: ObjectAny, opts: SetOptions = {}) {
setAttributes(attrs: ObjectAny, opts: SetAttrOptions = {}) {
this.set('attributes', { ...attrs }, opts);
return this;
}
Expand All @@ -583,7 +584,7 @@ export default class Component extends StyleableModel<ComponentProperties> {
* @example
* component.addAttributes({ 'data-key': 'value' });
*/
addAttributes(attrs: ObjectAny, opts: SetOptions = {}) {
addAttributes(attrs: ObjectAny, opts: SetAttrOptions = {}) {
return this.setAttributes(
{
...this.getAttributes({ noClass: true }),
Expand Down Expand Up @@ -643,7 +644,7 @@ export default class Component extends StyleableModel<ComponentProperties> {
* @example
* component.setStyle({ color: 'red' });
*/
setStyle(prop: StyleProps = {}, opts: any = {}) {
setStyle(prop: StyleProps = {}, opts: UpdateStyleOptions = {}) {
const { opt, em } = this;

if (avoidInline(em) && !opt.temporary && !opts.inline) {
Expand Down
6 changes: 4 additions & 2 deletions src/domain_abstract/model/StyleableModel.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
import { isArray, isString, keys } from 'underscore';
import { Model, ObjectAny, ObjectHash } from '../../common';
import { Model, ObjectAny, ObjectHash, SetOptions } from '../../common';
import ParserHtml from '../../parser/model/ParserHtml';
import Selectors from '../../selector_manager/model/Selectors';
import { shallowDiff } from '../../utils/mixins';

export type StyleProps = Record<string, string | string[]>;

export type UpdateStyleOptions = ObjectAny & {
export type UpdateStyleOptions = SetOptions & {
partial?: boolean;
addStyle?: StyleProps;
inline?: boolean;
noEvent?: boolean;
};

const parserHtml = ParserHtml();
Expand Down
2 changes: 1 addition & 1 deletion src/navigator/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ export default class LayerManager extends Module<LayerManagerConfig> {
style.display = 'none';
}

component.setStyle(style, styleOpts);
component.setStyle(style, styleOpts as any);
this.updateLayer(component);
this.em.trigger('component:toggled'); // Updates Style Manager #2938
}
Expand Down

0 comments on commit a62f927

Please sign in to comment.