Skip to content

Commit

Permalink
Remove element border reset (#6093)
Browse files Browse the repository at this point in the history
* Remove the border update in handleDrop. Fixes GrapesJS/mjml#338

* Allow custom parser options in component text view `disableEditing`

* Format
  • Loading branch information
artf authored Aug 26, 2024
1 parent ecfff9d commit 9ad4207
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 7 deletions.
3 changes: 3 additions & 0 deletions src/common/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import Backbone from 'backbone';
import { HTMLParserOptions } from '../parser/config/config';
export { default as $ } from '../utils/cash-dom';

interface NOOP {}
Expand All @@ -13,6 +14,8 @@ export type DisableOptions = { fromMove?: boolean };

export type LocaleOptions = { locale?: boolean };

export type WithHTMLParserOptions = { parserOptions?: HTMLParserOptions };

export type RemoveOptions = Backbone.Silenceable;

export type EventHandler = Backbone.EventHandler;
Expand Down
8 changes: 4 additions & 4 deletions src/dom_components/model/Components.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { isEmpty, isArray, isString, isFunction, each, includes, extend, flatten, keys } from 'underscore';
import Component from './Component';
import { AddOptions, Collection, OptionAsDocument } from '../../common';
import { AddOptions, Collection } from '../../common';
import { DomComponentsConfig } from '../config/config';
import EditorModel from '../../editor/model/Editor';
import ComponentManager from '..';
Expand All @@ -15,7 +15,7 @@ import {
} from './types';
import ComponentText from './ComponentText';
import ComponentWrapper from './ComponentWrapper';
import { ComponentsEvents } from '../types';
import { ComponentsEvents, ParseStringOptions } from '../types';
import { isSymbolInstance, isSymbolRoot, updateSymbolComps } from './SymbolUtils';

export const getComponentIds = (cmp?: Component | Component[] | Components, res: string[] = []) => {
Expand Down Expand Up @@ -252,11 +252,11 @@ Component> {
return new model(attrs, options) as Component;
}

parseString(value: string, opt: AddOptions & OptionAsDocument & { temporary?: boolean; keepIds?: string[] } = {}) {
parseString(value: string, opt: ParseStringOptions = {}) {
const { em, domc, parent } = this;
const asDocument = opt.asDocument && parent?.is('wrapper');
const cssc = em.Css;
const parsed = em.Parser.parseHtml(value, { asDocument });
const parsed = em.Parser.parseHtml(value, { asDocument, ...opt.parserOptions });
let components = parsed.html;

if (asDocument) {
Expand Down
5 changes: 5 additions & 0 deletions src/dom_components/types.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { AddOptions, OptionAsDocument, WithHTMLParserOptions } from '../common';
import Component from './model/Component';

export enum ActionLabelComponents {
Expand All @@ -16,6 +17,10 @@ export interface SymbolInfo {
relatives: Component[];
}

export interface ParseStringOptions extends AddOptions, OptionAsDocument, WithHTMLParserOptions {
keepIds?: string[];
}

export enum ComponentsEvents {
/**
* @event `component:add` New component added.
Expand Down
4 changes: 2 additions & 2 deletions src/dom_components/view/ComponentTextView.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { bindAll } from 'underscore';
import { AddOptions, DisableOptions, ObjectAny } from '../../common';
import { AddOptions, DisableOptions, ObjectAny, WithHTMLParserOptions } from '../../common';
import RichTextEditorModule from '../../rich_text_editor';
import RichTextEditor from '../../rich_text_editor/model/RichTextEditor';
import { off, on } from '../../utils/dom';
Expand Down Expand Up @@ -108,7 +108,7 @@ export default class ComponentTextView<TComp extends ComponentText = ComponentTe
* Disable element content editing
* @private
* */
async disableEditing(opts: DisableOptions = {}) {
async disableEditing(opts: DisableOptions & WithHTMLParserOptions = {}) {
const { model, rte, activeRte, em } = this;
// There are rare cases when disableEditing is called when the view is already removed
// so, we have to check for the model, this will avoid breaking stuff.
Expand Down
1 change: 0 additions & 1 deletion src/utils/Droppable.ts
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,6 @@ export default class Droppable {
const { dragContent } = this;
const dt = (ev as DragEvent).dataTransfer;
const content = this.getContentByData(dt).content;
(ev.target as HTMLElement).style.border = '';
content && dragContent && dragContent(content);
this.endDrop(!content, ev);
}
Expand Down

0 comments on commit 9ad4207

Please sign in to comment.