Browse Source

Revert "Fix Css style classes were not correct"

This reverts commit 34ba911a97.
pull/4327/head
Alex Ritter 4 years ago
parent
commit
8fe59060ab
  1. 2
      src/abstract/DomainViews.ts
  2. 3
      src/abstract/View.ts
  3. 1
      src/canvas/index.ts
  4. 58
      src/canvas/view/CanvasView.ts
  5. 33
      src/canvas/view/FrameView.ts
  6. 40
      src/canvas/view/FrameWrapView.ts
  7. 12
      src/canvas/view/FramesView.ts

2
src/abstract/DomainViews.ts

@ -44,7 +44,7 @@ export default abstract class DomainViews<TCollection extends Backbone.Collectio
* @private * @private
* */ * */
private add(model: TModel<TCollection>, fragment?: DocumentFragment) { private add(model: TModel<TCollection>, fragment?: DocumentFragment) {
const { reuseView, viewCollection, itemsView = {} } = this; const { config, reuseView, viewCollection, itemsView = {} } = this;
var frag = fragment || null; var frag = fragment || null;
var typeField = model.get(this.itemType); var typeField = model.get(this.itemType);
let view; let view;

3
src/abstract/View.ts

@ -7,7 +7,7 @@ export default class View<
TElement extends Element = HTMLElement TElement extends Element = HTMLElement
> extends Backbone.View<TModel, TElement> { > extends Backbone.View<TModel, TElement> {
protected get pfx() { protected get pfx() {
return this.em.config.stylePrefix || ""; return (this.em.config as any).stylePrefix || "";
} }
protected get ppfx() { protected get ppfx() {
@ -15,6 +15,7 @@ export default class View<
} }
protected get module(): TModel extends Model<infer M>? M: unknown { protected get module(): TModel extends Model<infer M>? M: unknown {
//console.log((this.collection.first as any).module)
return this.model?.module ?? (this.collection as any).module; return this.model?.module ?? (this.collection as any).module;
} }

1
src/canvas/index.ts

@ -80,6 +80,7 @@ export default class CanvasModule extends Module<typeof defaults> {
*/ */
constructor(em: EditorModel) { constructor(em: EditorModel) {
super(em, "Canvas", defaults) super(em, "Canvas", defaults)
this.canvas = new Canvas(this); this.canvas = new Canvas(this);
this.model = this.canvas; this.model = this.canvas;
this.startAutoscroll = this.startAutoscroll.bind(this); this.startAutoscroll = this.startAutoscroll.bind(this);

58
src/canvas/view/CanvasView.ts

@ -26,10 +26,10 @@ export default class CanvasView extends View<Canvas> {
} }
template() { template() {
const { ppfx } = this; const { pfx } = this;
return ` return `
<div class="${ppfx}canvas__frames" data-frames></div> <div class="${pfx}canvas__frames" data-frames></div>
<div id="${ppfx}tools" class="${ppfx}canvas__tools" data-tools></div> <div id="${pfx}tools" class="${pfx}canvas__tools" data-tools></div>
`; `;
} }
/*get className(){ /*get className(){
@ -60,7 +60,7 @@ export default class CanvasView extends View<Canvas> {
constructor(model: Canvas) { constructor(model: Canvas) {
super({model}); super({model});
bindAll(this, 'clearOff', 'onKeyPress', 'onCanvasMove'); bindAll(this, 'clearOff', 'onKeyPress', 'onCanvasMove');
this.className = this.ppfx + 'canvas'; this.className = this.pfx + 'canvas';
const { em } = this; const { em } = this;
this._initFrames(); this._initFrames();
this.listenTo(em, 'change:canvasOffset', this.clearOff); this.listenTo(em, 'change:canvasOffset', this.clearOff);
@ -76,7 +76,7 @@ export default class CanvasView extends View<Canvas> {
} }
_initFrames() { _initFrames() {
const { frames, model, module, em } = this; const { frames, model, config, em } = this;
const collection = model.frames; const collection = model.frames;
em.set('readyCanvas', 0); em.set('readyCanvas', 0);
collection.once('loaded:all', () => em.set('readyCanvas', 1)); collection.once('loaded:all', () => em.set('readyCanvas', 1));
@ -84,7 +84,7 @@ export default class CanvasView extends View<Canvas> {
this.frames = new FramesView( this.frames = new FramesView(
{collection}, {collection},
{config: { {config: {
module, ...config,
canvasView: this, canvasView: this,
}, },
}); });
@ -375,7 +375,7 @@ export default class CanvasView extends View<Canvas> {
} }
render() { render() {
const { el, $el, pfx, config, em } = this; const { el, $el, ppfx, config, em } = this;
$el.html(this.template()); $el.html(this.template());
const $frames = $el.find('[data-frames]'); const $frames = $el.find('[data-frames]');
this.framesArea = $frames.get(0); this.framesArea = $frames.get(0);
@ -383,32 +383,32 @@ export default class CanvasView extends View<Canvas> {
const toolsWrp = $el.find('[data-tools]'); const toolsWrp = $el.find('[data-tools]');
this.toolsWrapper = toolsWrp.get(0); this.toolsWrapper = toolsWrp.get(0);
toolsWrp.append(` toolsWrp.append(`
<div class="${pfx}tools ${pfx}tools-gl" style="pointer-events:none"> <div class="${ppfx}tools ${ppfx}tools-gl" style="pointer-events:none">
<div class="${pfx}placeholder"> <div class="${ppfx}placeholder">
<div class="${pfx}placeholder-int"></div> <div class="${ppfx}placeholder-int"></div>
</div> </div>
</div> </div>
<div id="${pfx}tools" style="pointer-events:none"> <div id="${ppfx}tools" style="pointer-events:none">
${config.extHl ? `<div class="${pfx}highlighter-sel"></div>` : ''} ${config.extHl ? `<div class="${ppfx}highlighter-sel"></div>` : ''}
<div class="${pfx}badge"></div> <div class="${ppfx}badge"></div>
<div class="${pfx}ghost"></div> <div class="${ppfx}ghost"></div>
<div class="${pfx}toolbar" style="pointer-events:all"></div> <div class="${ppfx}toolbar" style="pointer-events:all"></div>
<div class="${pfx}resizer"></div> <div class="${ppfx}resizer"></div>
<div class="${pfx}offset-v"></div> <div class="${ppfx}offset-v"></div>
<div class="${pfx}offset-fixed-v"></div> <div class="${ppfx}offset-fixed-v"></div>
</div> </div>
`); `);
const toolsEl = el.querySelector<HTMLElement>(`#${pfx}tools`) ?? undefined; const toolsEl = el.querySelector(`#${ppfx}tools`);
this.hlEl = el.querySelector<HTMLElement>(`.${pfx}highlighter`) ?? undefined; this.hlEl = el.querySelector(`.${ppfx}highlighter`) as HTMLElement;
this.badgeEl = el.querySelector<HTMLElement>(`.${pfx}badge`) ?? undefined; this.badgeEl = el.querySelector(`.${ppfx}badge`) as HTMLElement;
this.placerEl = el.querySelector<HTMLElement>(`.${pfx}placeholder`) ?? undefined; this.placerEl = el.querySelector(`.${ppfx}placeholder`) as HTMLElement;
this.ghostEl = el.querySelector<HTMLElement>(`.${pfx}ghost`) ?? undefined; this.ghostEl = el.querySelector(`.${ppfx}ghost`) as HTMLElement;
this.toolbarEl = el.querySelector<HTMLElement>(`.${pfx}toolbar`) ?? undefined; this.toolbarEl = el.querySelector(`.${ppfx}toolbar`) as HTMLElement;
this.resizerEl = el.querySelector<HTMLElement>(`.${pfx}resizer`) ?? undefined; this.resizerEl = el.querySelector(`.${ppfx}resizer`) as HTMLElement;
this.offsetEl = el.querySelector<HTMLElement>(`.${pfx}offset-v`) ?? undefined; this.offsetEl = el.querySelector(`.${ppfx}offset-v`) as HTMLElement;
this.fixedOffsetEl = el.querySelector<HTMLElement>(`.${pfx}offset-fixed-v`) ?? undefined; this.fixedOffsetEl = el.querySelector(`.${ppfx}offset-fixed-v`) as HTMLElement;
this.toolsGlobEl = el.querySelector<HTMLElement>(`.${pfx}tools-gl`) ?? undefined; this.toolsGlobEl = el.querySelector(`.${ppfx}tools-gl`) as HTMLElement;
this.toolsEl = toolsEl; this.toolsEl = toolsEl as HTMLElement;
this.el.className = getUiClass(em, this.className); this.el.className = getUiClass(em, this.className);
this.ready = true; this.ready = true;
this._renderFrames(); this._renderFrames();

33
src/canvas/view/FrameView.ts

@ -32,6 +32,7 @@ export default class FrameView extends View<Frame, HTMLIFrameElement> {
super({model}); super({model});
bindAll(this, 'updateClientY', 'stopAutoscroll', 'autoscroll', '_emitUpdate'); bindAll(this, 'updateClientY', 'stopAutoscroll', 'autoscroll', '_emitUpdate');
const { el, em } = this; const { el, em } = this;
//el = em.config.el
//@ts-ignore //@ts-ignore
this.module._config = { this.module._config = {
...(this.config || {}), ...(this.config || {}),
@ -39,6 +40,7 @@ export default class FrameView extends View<Frame, HTMLIFrameElement> {
frameView: this, frameView: this,
//canvasView: view?.cv //canvasView: view?.cv
}; };
//console.log(this.config)
this.frameWrapView = view; this.frameWrapView = view;
this.showGlobalTools = debounce(this.showGlobalTools.bind(this), 50); this.showGlobalTools = debounce(this.showGlobalTools.bind(this), 50);
const cvModel = this.getCanvasModel(); const cvModel = this.getCanvasModel();
@ -109,7 +111,7 @@ export default class FrameView extends View<Frame, HTMLIFrameElement> {
getJsContainer() { getJsContainer() {
if (!this.jsContainer) { if (!this.jsContainer) {
this.jsContainer = createEl('div', { class: `${this.pfx}js-cont` }); this.jsContainer = createEl('div', { class: `${this.ppfx}js-cont` });
} }
return this.jsContainer; return this.jsContainer;
@ -253,8 +255,8 @@ export default class FrameView extends View<Frame, HTMLIFrameElement> {
} }
render() { render() {
const { $el, pfx } = this; const { $el, ppfx } = this;
$el.attr({ class: `${pfx}frame` }); $el.attr({ class: `${ppfx}frame` });
this.renderScripts(); this.renderScripts();
return this; return this;
} }
@ -324,7 +326,7 @@ export default class FrameView extends View<Frame, HTMLIFrameElement> {
} }
renderBody() { renderBody() {
const { config, em, model, pfx } = this; const { config, em, model, ppfx } = this;
const doc = this.getDoc(); const doc = this.getDoc();
const body = this.getBody(); const body = this.getBody();
const win = this.getWindow(); const win = this.getWindow();
@ -345,36 +347,36 @@ export default class FrameView extends View<Frame, HTMLIFrameElement> {
padding-top: 0.001em; padding-top: 0.001em;
} }
.${pfx}dashed *[data-gjs-highlightable] { .${ppfx}dashed *[data-gjs-highlightable] {
outline: 1px dashed rgba(170,170,170,0.7); outline: 1px dashed rgba(170,170,170,0.7);
outline-offset: -2px; outline-offset: -2px;
} }
.${pfx}selected { .${ppfx}selected {
outline: 2px solid #3b97e3 !important; outline: 2px solid #3b97e3 !important;
outline-offset: -2px; outline-offset: -2px;
} }
.${pfx}selected-parent { .${ppfx}selected-parent {
outline: 2px solid ${colorWarn} !important outline: 2px solid ${colorWarn} !important
} }
.${pfx}no-select { .${ppfx}no-select {
user-select: none; user-select: none;
-webkit-user-select:none; -webkit-user-select:none;
-moz-user-select: none; -moz-user-select: none;
} }
.${pfx}freezed { .${ppfx}freezed {
opacity: 0.5; opacity: 0.5;
pointer-events: none; pointer-events: none;
} }
.${pfx}no-pointer { .${ppfx}no-pointer {
pointer-events: none; pointer-events: none;
} }
.${pfx}plh-image { .${ppfx}plh-image {
background: #f5f5f5; background: #f5f5f5;
border: none; border: none;
height: 100px; height: 100px;
@ -385,17 +387,17 @@ export default class FrameView extends View<Frame, HTMLIFrameElement> {
outline-offset: -2px outline-offset: -2px
} }
.${pfx}grabbing { .${ppfx}grabbing {
cursor: grabbing; cursor: grabbing;
cursor: -webkit-grabbing; cursor: -webkit-grabbing;
} }
.${pfx}is__grabbing { .${ppfx}is__grabbing {
overflow-x: hidden; overflow-x: hidden;
} }
.${pfx}is__grabbing, .${ppfx}is__grabbing,
.${pfx}is__grabbing * { .${ppfx}is__grabbing * {
cursor: grabbing !important; cursor: grabbing !important;
} }
@ -409,7 +411,6 @@ export default class FrameView extends View<Frame, HTMLIFrameElement> {
model: component, model: component,
config: { config: {
...component.config, ...component.config,
em,
frameView: this, frameView: this,
}, },
}).render(); }).render();

40
src/canvas/view/FrameWrapView.ts

@ -29,7 +29,7 @@ export default class FrameWrapView extends View<Frame> {
}; };
this.cv = canvasView; this.cv = canvasView;
this.frame = new FrameView(model, this); this.frame = new FrameView(model, this);
this.classAnim = `${this.pfx}frame-wrapper--anim`; this.classAnim = `${this.ppfx}frame-wrapper--anim`;
this.updateOffset = debounce(this.updateOffset.bind(this), 0); this.updateOffset = debounce(this.updateOffset.bind(this), 0);
this.updateSize = debounce(this.updateSize.bind(this), 0); this.updateSize = debounce(this.updateSize.bind(this), 0);
this.listenTo(model, 'loaded', this.frameLoaded); this.listenTo(model, 'loaded', this.frameLoaded);
@ -164,48 +164,48 @@ export default class FrameWrapView extends View<Frame> {
} }
render() { render() {
const { frame, $el, pfx, cv, model, el } = this; const { frame, $el, ppfx, cv, model, el } = this;
const { onRender } = model.attributes; const { onRender } = model.attributes;
this.__clear(); this.__clear();
this.__handleSize(); this.__handleSize();
frame.render(); frame.render();
$el $el
.empty() .empty()
.attr({ class: `${pfx}frame-wrapper` }) .attr({ class: `${ppfx}frame-wrapper` })
.append( .append(
` `
<div class="${pfx}frame-wrapper__top gjs-two-color" data-frame-top> <div class="${ppfx}frame-wrapper__top gjs-two-color" data-frame-top>
<div class="${pfx}frame-wrapper__name" data-action-move> <div class="${ppfx}frame-wrapper__name" data-action-move>
${model.get('name') || ''} ${model.get('name') || ''}
</div> </div>
<div class="${pfx}frame-wrapper__top-r"> <div class="${ppfx}frame-wrapper__top-r">
<div class="${pfx}frame-wrapper__icon" data-action-remove style="display: none"> <div class="${ppfx}frame-wrapper__icon" data-action-remove style="display: none">
<svg viewBox="0 0 24 24"><path d="M19 4h-3.5l-1-1h-5l-1 1H5v2h14M6 19c0 1.1.9 2 2 2h8c1.1 0 2-.9 2-2V7H6v12z"></path></svg> <svg viewBox="0 0 24 24"><path d="M19 4h-3.5l-1-1h-5l-1 1H5v2h14M6 19c0 1.1.9 2 2 2h8c1.1 0 2-.9 2-2V7H6v12z"></path></svg>
</div> </div>
</div> </div>
</div> </div>
<div class="${pfx}frame-wrapper__right" data-frame-right></div> <div class="${ppfx}frame-wrapper__right" data-frame-right></div>
<div class="${pfx}frame-wrapper__left" data-frame-left></div> <div class="${ppfx}frame-wrapper__left" data-frame-left></div>
<div class="${pfx}frame-wrapper__bottom" data-frame-bottom></div> <div class="${ppfx}frame-wrapper__bottom" data-frame-bottom></div>
` `
) )
.append(frame.el); .append(frame.el);
const elTools = createEl( const elTools = createEl(
'div', 'div',
{ {
class: `${pfx}tools`, class: `${ppfx}tools`,
style: 'pointer-events:none; display: none', style: 'pointer-events:none; display: none',
}, },
` `
<div class="${pfx}highlighter" data-hl></div> <div class="${ppfx}highlighter" data-hl></div>
<div class="${pfx}badge" data-badge></div> <div class="${ppfx}badge" data-badge></div>
<div class="${pfx}placeholder"> <div class="${ppfx}placeholder">
<div class="${pfx}placeholder-int"></div> <div class="${ppfx}placeholder-int"></div>
</div> </div>
<div class="${pfx}ghost"></div> <div class="${ppfx}ghost"></div>
<div class="${pfx}toolbar" style="pointer-events:all"></div> <div class="${ppfx}toolbar" style="pointer-events:all"></div>
<div class="${pfx}resizer"></div> <div class="${ppfx}resizer"></div>
<div class="${pfx}offset-v" data-offset> <div class="${ppfx}offset-v" data-offset>
<div class="gjs-marginName" data-offset-m> <div class="gjs-marginName" data-offset-m>
<div class="gjs-margin-v-el gjs-margin-v-top" data-offset-m-t></div> <div class="gjs-margin-v-el gjs-margin-v-top" data-offset-m-t></div>
<div class="gjs-margin-v-el gjs-margin-v-bottom" data-offset-m-b></div> <div class="gjs-margin-v-el gjs-margin-v-bottom" data-offset-m-b></div>
@ -219,7 +219,7 @@ export default class FrameWrapView extends View<Frame> {
<div class="gjs-padding-v-el gjs-padding-v-right" data-offset-p-r></div> <div class="gjs-padding-v-el gjs-padding-v-right" data-offset-p-r></div>
</div> </div>
</div> </div>
<div class="${pfx}offset-fixed-v"></div> <div class="${ppfx}offset-fixed-v"></div>
` `
); );
this.elTools = elTools; this.elTools = elTools;

12
src/canvas/view/FramesView.ts

@ -1,21 +1,15 @@
import CanvasModule from '..';
import DomainViews from '../../abstract/DomainViews'; import DomainViews from '../../abstract/DomainViews';
import EditorModel from '../../editor/model/Editor';
import Frames from '../model/Frames'; import Frames from '../model/Frames';
import CanvasView from './CanvasView'; import CanvasView from './CanvasView';
import FrameWrapView from './FrameWrapView'; import FrameWrapView from './FrameWrapView';
export default class FramesView extends DomainViews<Frames, FrameWrapView> { export default class FramesView extends DomainViews<Frames, FrameWrapView> {
canvasView: CanvasView; canvasView: CanvasView;
private _module: CanvasModule;
/*get module(){
return this._module;
}*/
constructor(opts = {}, config: any) { constructor(opts = {}, config: any) {
super(opts, true); super(opts, true);
//console.log(this.collection)
this.listenTo(this.collection, 'reset', this.render); this.listenTo(this.collection, 'reset', this.render);
this.canvasView = config.canvasView this.canvasView = config.canvasView
this._module = config.module;
} }
onRemoveBefore(items: FrameWrapView[], opts = {}) { onRemoveBefore(items: FrameWrapView[], opts = {}) {
@ -23,8 +17,8 @@ export default class FramesView extends DomainViews<Frames, FrameWrapView> {
} }
onRender() { onRender() {
const { $el, pfx } = this; const { $el, em } = this;
$el.attr({ class: `${pfx}frames` }); em && $el.attr({ class: `${em.config.stylePrefix}frames` });
} }
protected renderView(item: any, type: string){return new FrameWrapView(item, this.canvasView)} protected renderView(item: any, type: string){return new FrameWrapView(item, this.canvasView)}
} }

Loading…
Cancel
Save