Browse Source

Update TS

pull/5947/head
Artur Arseniev 2 years ago
parent
commit
a62f927394
  1. 2
      src/common/index.ts
  2. 5
      src/css_composer/index.ts
  3. 13
      src/dom_components/model/Component.ts
  4. 6
      src/domain_abstract/model/StyleableModel.ts
  5. 2
      src/navigator/index.ts

2
src/common/index.ts

@ -5,7 +5,7 @@ interface NOOP {}
export type Debounced = Function & { cancel(): void }; 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 }; export type AddOptions = Backbone.AddOptions & { temporary?: boolean; action?: string };

5
src/css_composer/index.ts

@ -39,6 +39,7 @@ import { ItemManagerModule } from '../abstract/Module';
import EditorModel from '../editor/model/Editor'; import EditorModel from '../editor/model/Editor';
import Component from '../dom_components/model/Component'; import Component from '../dom_components/model/Component';
import { ObjectAny, PrevToNewIdMap } from '../common'; import { ObjectAny, PrevToNewIdMap } from '../common';
import { UpdateStyleOptions } from '../domain_abstract/model/StyleableModel';
/** @private */ /** @private */
interface RuleOptions { interface RuleOptions {
@ -53,7 +54,7 @@ interface RuleOptions {
} }
/** @private */ /** @private */
interface SetRuleOptions extends RuleOptions { interface SetRuleOptions extends RuleOptions, UpdateStyleOptions {
/** /**
* If the rule exists already, merge passed styles instead of replacing them. * If the rule exists already, merge passed styles instead of replacing them.
*/ */
@ -61,7 +62,7 @@ interface SetRuleOptions extends RuleOptions {
} }
/** @private */ /** @private */
export interface GetSetRuleOptions { export interface GetSetRuleOptions extends UpdateStyleOptions {
state?: string; state?: string;
mediaText?: string; mediaText?: string;
addOpts?: ObjectAny; addOpts?: ObjectAny;

13
src/dom_components/model/Component.ts

@ -12,7 +12,7 @@ import {
keys, keys,
} from 'underscore'; } from 'underscore';
import { shallowDiff, capitalize, isEmptyObj, isObject, toLowerCase } from '../../utils/mixins'; 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 { Model } from 'backbone';
import Components from './Components'; import Components from './Components';
import Selector from '../../selector_manager/model/Selector'; import Selector from '../../selector_manager/model/Selector';
@ -22,7 +22,6 @@ import EditorModel from '../../editor/model/Editor';
import { import {
AddComponentsOption, AddComponentsOption,
ComponentAdd, ComponentAdd,
ComponentAddType,
ComponentDefinition, ComponentDefinition,
ComponentDefinitionDefined, ComponentDefinitionDefined,
ComponentOptions, ComponentOptions,
@ -44,6 +43,8 @@ import ItemView from '../../navigator/view/ItemView';
export interface IComponent extends ExtractMethods<Component> {} export interface IComponent extends ExtractMethods<Component> {}
export interface SetAttrOptions extends SetOptions, UpdateStyleOptions {}
const escapeRegExp = (str: string) => { const escapeRegExp = (str: string) => {
return str.replace(/[|\\{}()[\]^$+*?.]/g, '\\$&'); return str.replace(/[|\\{}()[\]^$+*?.]/g, '\\$&');
}; };
@ -541,7 +542,7 @@ export default class Component extends StyleableModel<ComponentProperties> {
* Emit changes for each updated attribute * Emit changes for each updated attribute
* @private * @private
*/ */
attrUpdated(m: any, v: any, opts: any = {}) { attrUpdated(m: any, v: any, opts: SetAttrOptions = {}) {
const attrs = this.get('attributes')!; const attrs = this.get('attributes')!;
// Handle classes // Handle classes
const classes = attrs.class; const classes = attrs.class;
@ -570,7 +571,7 @@ export default class Component extends StyleableModel<ComponentProperties> {
* @example * @example
* component.setAttributes({ id: 'test', 'data-key': 'value' }); * component.setAttributes({ id: 'test', 'data-key': 'value' });
*/ */
setAttributes(attrs: ObjectAny, opts: SetOptions = {}) { setAttributes(attrs: ObjectAny, opts: SetAttrOptions = {}) {
this.set('attributes', { ...attrs }, opts); this.set('attributes', { ...attrs }, opts);
return this; return this;
} }
@ -583,7 +584,7 @@ export default class Component extends StyleableModel<ComponentProperties> {
* @example * @example
* component.addAttributes({ 'data-key': 'value' }); * component.addAttributes({ 'data-key': 'value' });
*/ */
addAttributes(attrs: ObjectAny, opts: SetOptions = {}) { addAttributes(attrs: ObjectAny, opts: SetAttrOptions = {}) {
return this.setAttributes( return this.setAttributes(
{ {
...this.getAttributes({ noClass: true }), ...this.getAttributes({ noClass: true }),
@ -643,7 +644,7 @@ export default class Component extends StyleableModel<ComponentProperties> {
* @example * @example
* component.setStyle({ color: 'red' }); * component.setStyle({ color: 'red' });
*/ */
setStyle(prop: StyleProps = {}, opts: any = {}) { setStyle(prop: StyleProps = {}, opts: UpdateStyleOptions = {}) {
const { opt, em } = this; const { opt, em } = this;
if (avoidInline(em) && !opt.temporary && !opts.inline) { if (avoidInline(em) && !opt.temporary && !opts.inline) {

6
src/domain_abstract/model/StyleableModel.ts

@ -1,14 +1,16 @@
import { isArray, isString, keys } from 'underscore'; 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 ParserHtml from '../../parser/model/ParserHtml';
import Selectors from '../../selector_manager/model/Selectors'; import Selectors from '../../selector_manager/model/Selectors';
import { shallowDiff } from '../../utils/mixins'; import { shallowDiff } from '../../utils/mixins';
export type StyleProps = Record<string, string | string[]>; export type StyleProps = Record<string, string | string[]>;
export type UpdateStyleOptions = ObjectAny & { export type UpdateStyleOptions = SetOptions & {
partial?: boolean; partial?: boolean;
addStyle?: StyleProps; addStyle?: StyleProps;
inline?: boolean;
noEvent?: boolean;
}; };
const parserHtml = ParserHtml(); const parserHtml = ParserHtml();

2
src/navigator/index.ts

@ -195,7 +195,7 @@ export default class LayerManager extends Module<LayerManagerConfig> {
style.display = 'none'; style.display = 'none';
} }
component.setStyle(style, styleOpts); component.setStyle(style, styleOpts as any);
this.updateLayer(component); this.updateLayer(component);
this.em.trigger('component:toggled'); // Updates Style Manager #2938 this.em.trigger('component:toggled'); // Updates Style Manager #2938
} }

Loading…
Cancel
Save