@firestitch/block-editor 12.3.21 → 12.3.23

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,7 +1,7 @@
1
1
  import * as i13 from '@angular/common';
2
2
  import { DOCUMENT, CommonModule } from '@angular/common';
3
3
  import * as i0 from '@angular/core';
4
- import { Injectable, Component, ChangeDetectionStrategy, Input, Inject, Pipe, ViewChild, HostBinding, Directive, EventEmitter, ContentChildren, Output, ViewChildren, ElementRef, HostListener, NgModule } from '@angular/core';
4
+ import { Injectable, Component, ChangeDetectionStrategy, Input, Directive, Inject, Pipe, ViewChild, HostBinding, EventEmitter, ContentChildren, Output, ViewChildren, ElementRef, HostListener, NgModule } from '@angular/core';
5
5
  import * as i16 from '@angular/forms';
6
6
  import { FormsModule } from '@angular/forms';
7
7
  import * as i15 from '@angular/material/input';
@@ -35,12 +35,12 @@ import * as i10 from '@firestitch/autocomplete';
35
35
  import { FsAutocompleteModule } from '@firestitch/autocomplete';
36
36
  import * as i1 from '@angular/common/http';
37
37
  import { throwError, Subject, BehaviorSubject, from, fromEvent } from 'rxjs';
38
- import { map, filter, groupBy, debounceTime, mergeAll, takeUntil, switchMap, delay } from 'rxjs/operators';
39
- import Moveable from 'moveable';
38
+ import { map, filter, groupBy, debounceTime, mergeAll, takeUntil, switchMap, tap, skip, delay } from 'rxjs/operators';
39
+ import { index, guid, round } from '@firestitch/common';
40
40
  import * as i1$1 from '@angular/material/dialog';
41
41
  import { MAT_DIALOG_DATA } from '@angular/material/dialog';
42
- import { index, guid, round } from '@firestitch/common';
43
42
  import * as i5 from '@angular/material/divider';
43
+ import Moveable from 'moveable';
44
44
  import * as i1$2 from '@firestitch/api';
45
45
  import * as i2$1 from '@firestitch/prompt';
46
46
  import * as i8 from '@angular/material/core';
@@ -106,6 +106,42 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.16", ngImpo
106
106
  type: Input
107
107
  }] } });
108
108
 
109
+ class FsBlockEditorMarginDirective {
110
+ constructor(_elementRef) {
111
+ this._elementRef = _elementRef;
112
+ }
113
+ get element() {
114
+ return this._elementRef.nativeElement;
115
+ }
116
+ }
117
+ FsBlockEditorMarginDirective.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.2.16", ngImport: i0, type: FsBlockEditorMarginDirective, deps: [{ token: i0.ElementRef }], target: i0.ɵɵFactoryTarget.Directive });
118
+ FsBlockEditorMarginDirective.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "12.0.0", version: "12.2.16", type: FsBlockEditorMarginDirective, selector: "[fsBlockEditorMargin]", ngImport: i0 });
119
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.16", ngImport: i0, type: FsBlockEditorMarginDirective, decorators: [{
120
+ type: Directive,
121
+ args: [{
122
+ selector: '[fsBlockEditorMargin]'
123
+ }]
124
+ }], ctorParameters: function () { return [{ type: i0.ElementRef }]; } });
125
+
126
+ class FsBlockEditorSidebarPanelDirective {
127
+ constructor(templateRef) {
128
+ this.templateRef = templateRef;
129
+ this.show = true;
130
+ }
131
+ }
132
+ FsBlockEditorSidebarPanelDirective.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.2.16", ngImport: i0, type: FsBlockEditorSidebarPanelDirective, deps: [{ token: i0.TemplateRef }], target: i0.ɵɵFactoryTarget.Directive });
133
+ FsBlockEditorSidebarPanelDirective.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "12.0.0", version: "12.2.16", type: FsBlockEditorSidebarPanelDirective, selector: "[fsBlockEditorSidebarPanel]", inputs: { label: "label", show: "show" }, ngImport: i0 });
134
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.16", ngImport: i0, type: FsBlockEditorSidebarPanelDirective, decorators: [{
135
+ type: Directive,
136
+ args: [{
137
+ selector: '[fsBlockEditorSidebarPanel]'
138
+ }]
139
+ }], ctorParameters: function () { return [{ type: i0.TemplateRef }]; }, propDecorators: { label: [{
140
+ type: Input
141
+ }], show: [{
142
+ type: Input
143
+ }] } });
144
+
109
145
  var BlockType;
110
146
  (function (BlockType) {
111
147
  BlockType["Rectangle"] = "rectangle";
@@ -146,17 +182,17 @@ class LayersReorderDialogComponent {
146
182
  this._init(_dialogData);
147
183
  }
148
184
  swapItems(event) {
149
- moveItemInArray(this.blockComponents, event.previousIndex, event.currentIndex);
185
+ moveItemInArray(this.blocks, event.previousIndex, event.currentIndex);
150
186
  }
151
187
  done() {
152
- this._dialogRef.close(this.blockComponents);
188
+ this._dialogRef.close(this.blocks);
153
189
  }
154
190
  _init(data) {
155
- this.blockComponents = data.blockComponents;
191
+ this.blocks = data.blocks;
156
192
  }
157
193
  }
158
194
  LayersReorderDialogComponent.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.2.16", ngImport: i0, type: LayersReorderDialogComponent, deps: [{ token: MAT_DIALOG_DATA }, { token: i1$1.MatDialogRef }], target: i0.ɵɵFactoryTarget.Component });
159
- LayersReorderDialogComponent.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "12.0.0", version: "12.2.16", type: LayersReorderDialogComponent, selector: "ng-component", ngImport: i0, template: "<fs-dialog>\n <h1 mat-dialog-title><mat-icon>swap_vert</mat-icon> Reorder Fields</h1>\n <mat-dialog-content>\n <mat-list cdkDropList (cdkDropListDropped)=\"swapItems($event)\">\n <mat-divider></mat-divider>\n <ng-container *ngFor=\"let blockComponent of blockComponents\">\n <mat-list-item cdkDrag cdkDragLockAxis=\"y\">\n <mat-icon cdkDragHandle>drag_handle</mat-icon>\n <mat-icon>\n {{ blockTypeIcons[blockComponent.block.type] }}\n </mat-icon>\n <span class=\"block-label\">\n {{ blockComponent.block.label || blockComponent.block.content || 'No Content'}} \n </span>\n </mat-list-item>\n <mat-divider></mat-divider>\n </ng-container>\n </mat-list>\n </mat-dialog-content>\n <mat-dialog-actions>\n <button mat-button color=\"primary\" (click)=\"done()\">Done</button>\n </mat-dialog-actions>\n</fs-dialog>\n", styles: ["h1{display:flex}.mat-icon{margin-right:20px}.block-label{min-width:200px;white-space:nowrap;overflow:hidden;text-overflow:ellipsis;max-width:1000px}.cdk-drag-preview{display:flex;padding-left:15px!important;background:#fff;box-shadow:0 5px 5px -3px #0003,0 8px 10px 1px #00000024,0 3px 14px 2px #0000001f}.cdk-drag-preview ::ng-deep .mat-list-item-content{display:flex;flex-direction:row;align-items:center;font-size:16px}.cdk-drag-handle{cursor:grab}.cdk-drag-placeholder{opacity:.2}\n"], components: [{ type: i2.FsDialogComponent, selector: "fs-dialog", inputs: ["mobileMode"] }, { type: i3.MatIcon, selector: "mat-icon", inputs: ["color", "inline", "svgIcon", "fontSet", "fontIcon"], exportAs: ["matIcon"] }, { type: i4.MatList, selector: "mat-list, mat-action-list", inputs: ["disableRipple", "disabled"], exportAs: ["matList"] }, { type: i5.MatDivider, selector: "mat-divider", inputs: ["vertical", "inset"] }, { type: i4.MatListItem, selector: "mat-list-item, a[mat-list-item], button[mat-list-item]", inputs: ["disableRipple", "disabled"], exportAs: ["matListItem"] }, { type: i6.MatButton, selector: "button[mat-button], button[mat-raised-button], button[mat-icon-button], button[mat-fab], button[mat-mini-fab], button[mat-stroked-button], button[mat-flat-button]", inputs: ["disabled", "disableRipple", "color"], exportAs: ["matButton"] }], directives: [{ type: i1$1.MatDialogTitle, selector: "[mat-dialog-title], [matDialogTitle]", inputs: ["id"], exportAs: ["matDialogTitle"] }, { type: i1$1.MatDialogContent, selector: "[mat-dialog-content], mat-dialog-content, [matDialogContent]" }, { type: i7.CdkDropList, selector: "[cdkDropList], cdk-drop-list", inputs: ["cdkDropListConnectedTo", "id", "cdkDropListEnterPredicate", "cdkDropListSortPredicate", "cdkDropListDisabled", "cdkDropListSortingDisabled", "cdkDropListAutoScrollDisabled", "cdkDropListOrientation", "cdkDropListLockAxis", "cdkDropListData", "cdkDropListAutoScrollStep"], outputs: ["cdkDropListDropped", "cdkDropListEntered", "cdkDropListExited", "cdkDropListSorted"], exportAs: ["cdkDropList"] }, { type: i13.NgForOf, selector: "[ngFor][ngForOf]", inputs: ["ngForOf", "ngForTrackBy", "ngForTemplate"] }, { type: i7.CdkDrag, selector: "[cdkDrag]", inputs: ["cdkDragDisabled", "cdkDragStartDelay", "cdkDragLockAxis", "cdkDragConstrainPosition", "cdkDragPreviewClass", "cdkDragBoundary", "cdkDragRootElement", "cdkDragPreviewContainer", "cdkDragData", "cdkDragFreeDragPosition"], outputs: ["cdkDragStarted", "cdkDragReleased", "cdkDragEnded", "cdkDragEntered", "cdkDragExited", "cdkDragDropped", "cdkDragMoved"], exportAs: ["cdkDrag"] }, { type: i7.CdkDragHandle, selector: "[cdkDragHandle]", inputs: ["cdkDragHandleDisabled"] }, { type: i1$1.MatDialogActions, selector: "[mat-dialog-actions], mat-dialog-actions, [matDialogActions]" }], changeDetection: i0.ChangeDetectionStrategy.OnPush });
195
+ LayersReorderDialogComponent.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "12.0.0", version: "12.2.16", type: LayersReorderDialogComponent, selector: "ng-component", ngImport: i0, template: "<fs-dialog>\n <h1 mat-dialog-title><mat-icon>swap_vert</mat-icon> Reorder Blocks</h1>\n <mat-dialog-content>\n <mat-list cdkDropList (cdkDropListDropped)=\"swapItems($event)\">\n <mat-divider></mat-divider>\n <ng-container *ngFor=\"let block of blocks\">\n <mat-list-item cdkDrag cdkDragLockAxis=\"y\">\n <mat-icon cdkDragHandle>drag_handle</mat-icon>\n <mat-icon>\n {{ blockTypeIcons[block.type] }}\n </mat-icon>\n <span class=\"block-label\">\n {{ block.label || block.content || 'No Content'}} \n </span>\n </mat-list-item>\n <mat-divider></mat-divider>\n </ng-container>\n </mat-list>\n </mat-dialog-content>\n <mat-dialog-actions>\n <button mat-button color=\"primary\" (click)=\"done()\">Done</button>\n </mat-dialog-actions>\n</fs-dialog>\n", styles: ["h1{display:flex}.mat-icon{margin-right:20px}.block-label{min-width:200px;white-space:nowrap;overflow:hidden;text-overflow:ellipsis;max-width:1000px}.cdk-drag-preview{display:flex;padding-left:15px!important;background:#fff;box-shadow:0 5px 5px -3px #0003,0 8px 10px 1px #00000024,0 3px 14px 2px #0000001f}.cdk-drag-preview ::ng-deep .mat-list-item-content{display:flex;flex-direction:row;align-items:center;font-size:16px}.cdk-drag-handle{cursor:grab}.cdk-drag-placeholder{opacity:.2}\n"], components: [{ type: i2.FsDialogComponent, selector: "fs-dialog", inputs: ["mobileMode"] }, { type: i3.MatIcon, selector: "mat-icon", inputs: ["color", "inline", "svgIcon", "fontSet", "fontIcon"], exportAs: ["matIcon"] }, { type: i4.MatList, selector: "mat-list, mat-action-list", inputs: ["disableRipple", "disabled"], exportAs: ["matList"] }, { type: i5.MatDivider, selector: "mat-divider", inputs: ["vertical", "inset"] }, { type: i4.MatListItem, selector: "mat-list-item, a[mat-list-item], button[mat-list-item]", inputs: ["disableRipple", "disabled"], exportAs: ["matListItem"] }, { type: i6.MatButton, selector: "button[mat-button], button[mat-raised-button], button[mat-icon-button], button[mat-fab], button[mat-mini-fab], button[mat-stroked-button], button[mat-flat-button]", inputs: ["disabled", "disableRipple", "color"], exportAs: ["matButton"] }], directives: [{ type: i1$1.MatDialogTitle, selector: "[mat-dialog-title], [matDialogTitle]", inputs: ["id"], exportAs: ["matDialogTitle"] }, { type: i1$1.MatDialogContent, selector: "[mat-dialog-content], mat-dialog-content, [matDialogContent]" }, { type: i7.CdkDropList, selector: "[cdkDropList], cdk-drop-list", inputs: ["cdkDropListConnectedTo", "id", "cdkDropListEnterPredicate", "cdkDropListSortPredicate", "cdkDropListDisabled", "cdkDropListSortingDisabled", "cdkDropListAutoScrollDisabled", "cdkDropListOrientation", "cdkDropListLockAxis", "cdkDropListData", "cdkDropListAutoScrollStep"], outputs: ["cdkDropListDropped", "cdkDropListEntered", "cdkDropListExited", "cdkDropListSorted"], exportAs: ["cdkDropList"] }, { type: i13.NgForOf, selector: "[ngFor][ngForOf]", inputs: ["ngForOf", "ngForTrackBy", "ngForTemplate"] }, { type: i7.CdkDrag, selector: "[cdkDrag]", inputs: ["cdkDragDisabled", "cdkDragStartDelay", "cdkDragLockAxis", "cdkDragConstrainPosition", "cdkDragPreviewClass", "cdkDragBoundary", "cdkDragRootElement", "cdkDragPreviewContainer", "cdkDragData", "cdkDragFreeDragPosition"], outputs: ["cdkDragStarted", "cdkDragReleased", "cdkDragEnded", "cdkDragEntered", "cdkDragExited", "cdkDragDropped", "cdkDragMoved"], exportAs: ["cdkDrag"] }, { type: i7.CdkDragHandle, selector: "[cdkDragHandle]", inputs: ["cdkDragHandleDisabled"] }, { type: i1$1.MatDialogActions, selector: "[mat-dialog-actions], mat-dialog-actions, [matDialogActions]" }], changeDetection: i0.ChangeDetectionStrategy.OnPush });
160
196
  i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.16", ngImport: i0, type: LayersReorderDialogComponent, decorators: [{
161
197
  type: Component,
162
198
  args: [{
@@ -174,6 +210,7 @@ var EventType;
174
210
  EventType["Add"] = "add";
175
211
  EventType["Change"] = "change";
176
212
  EventType["Remove"] = "remove";
213
+ EventType["Update"] = "update";
177
214
  })(EventType || (EventType = {}));
178
215
  class BlocksStore {
179
216
  constructor() {
@@ -198,6 +235,10 @@ class BlocksStore {
198
235
  return this._eventBus$
199
236
  .pipe(filter(({ type }) => type === EventType.Change), map(({ value }) => value));
200
237
  }
238
+ get blockUpdated$() {
239
+ return this._eventBus$
240
+ .pipe(filter(({ type }) => type === EventType.Update), map(({ value }) => value));
241
+ }
201
242
  get blockRemoved$() {
202
243
  return this._eventBus$
203
244
  .pipe(filter(({ type }) => type === EventType.Remove), map(({ value }) => value));
@@ -237,12 +278,13 @@ class BlocksStore {
237
278
  }
238
279
  blockUpload(block, fsFile) {
239
280
  if (!this._config.blockUpload) {
240
- console.warn('[BlockEditor] Config "blockUpload" is not defined');
241
- return;
281
+ return throwError('[BlockEditor] Config "blockUpload" is not defined');
242
282
  }
243
283
  const existing = this.blockExists(block);
244
- block = this._createBlock(block);
245
- from(fsFile.imageInfo)
284
+ if (!existing) {
285
+ block = this._createBlock(block);
286
+ }
287
+ return from(fsFile.imageInfo)
246
288
  .pipe(switchMap((imageInfo) => {
247
289
  if (!existing && (imageInfo === null || imageInfo === void 0 ? void 0 : imageInfo.height) && (imageInfo === null || imageInfo === void 0 ? void 0 : imageInfo.width)) {
248
290
  const ratio = imageInfo.height / imageInfo.width;
@@ -250,19 +292,21 @@ class BlocksStore {
250
292
  block.height = block.width * ratio;
251
293
  }
252
294
  return this._config.blockUpload(block, fsFile.file);
253
- }), takeUntil(this._destroy$))
254
- .subscribe((newBlock) => {
295
+ }), tap((newBlock) => {
255
296
  if (existing) {
256
- this.blockChange(newBlock);
297
+ this.blockUpdate(Object.assign(Object.assign({}, block), newBlock));
257
298
  }
258
299
  else {
259
300
  this._appendBlock(newBlock);
260
301
  }
261
- });
302
+ }), takeUntil(this._destroy$));
262
303
  }
263
304
  blockChange(block) {
264
305
  this._dispatchEvent(EventType.Change, block);
265
306
  }
307
+ blockUpdate(block) {
308
+ this._dispatchEvent(EventType.Update, block);
309
+ }
266
310
  blockRemove(targetBlocks) {
267
311
  const blocks = this.blocks;
268
312
  if (!Array.isArray(targetBlocks)) {
@@ -367,10 +411,6 @@ class BlockEditorService {
367
411
  get blockComponents() {
368
412
  return Array.from(this._blockComponents.values());
369
413
  }
370
- get selectedComponentBlocks() {
371
- return this.blockComponents
372
- .filter((blockComponent) => this.selectedBlocks.indexOf(blockComponent.block) !== -1);
373
- }
374
414
  init(config) {
375
415
  this.config = config;
376
416
  this._store.init(Object.assign({}, this.config));
@@ -379,7 +419,7 @@ class BlockEditorService {
379
419
  this._store.blockAdd(block);
380
420
  }
381
421
  blockUpload(block, fsFile) {
382
- this._store.blockUpload(block, fsFile);
422
+ return this._store.blockUpload(block, fsFile);
383
423
  }
384
424
  blockRemove(block) {
385
425
  this._store.blockRemove(block);
@@ -397,6 +437,9 @@ class BlockEditorService {
397
437
  get blockChanged$() {
398
438
  return this._store.blockChanged$;
399
439
  }
440
+ get blockUpdated$() {
441
+ return this._store.blockUpdated$;
442
+ }
400
443
  get blockClippable$() {
401
444
  return this._blockClippable$;
402
445
  }
@@ -419,7 +462,7 @@ class BlockEditorService {
419
462
  this._store.blockChange(block);
420
463
  }
421
464
  isSelectedBlock(block) {
422
- return this.selectedBlocks.indexOf(block.block) !== -1;
465
+ return this.selectedBlocks.indexOf(block) !== -1;
423
466
  }
424
467
  indexOf(block) {
425
468
  return this.blocks.map((e) => e.guid).indexOf(block.guid);
@@ -438,15 +481,6 @@ class BlockEditorService {
438
481
  this.selectedBlocks = [block];
439
482
  }
440
483
  set selectedBlocks(blocks) {
441
- this.blockComponents
442
- .forEach((blockComponent) => {
443
- if (blocks.indexOf(blockComponent.block) !== -1) {
444
- blockComponent.select();
445
- }
446
- else {
447
- blockComponent.deselect();
448
- }
449
- });
450
484
  this._selectedBlocks$.next(blocks);
451
485
  if (this.config.blocksSelected) {
452
486
  this.config.blocksSelected(blocks);
@@ -483,23 +517,23 @@ class BlockEditorService {
483
517
  this.margin = margin;
484
518
  }
485
519
  openReorderDialog() {
486
- const blockComponents = this.blockComponents
487
- .sort((blockCmpA, blockCmpB) => (blockCmpA.block.index - blockCmpB.block.index))
520
+ const blocks = this.blocks
521
+ .sort((blockA, blockB) => (blockA.index - blockB.index))
488
522
  .reverse();
489
523
  this._dialog
490
524
  .open(LayersReorderDialogComponent, {
491
525
  data: {
492
- blockComponents,
526
+ blocks,
493
527
  }
494
528
  })
495
529
  .afterClosed()
496
- .pipe(filter((blockComponents) => !!blockComponents), takeUntil(this._destroy$))
497
- .subscribe((blockComponents) => {
498
- blockComponents
530
+ .pipe(filter((blocks) => !!blocks), takeUntil(this._destroy$))
531
+ .subscribe((blocks) => {
532
+ blocks
499
533
  .reverse()
500
- .forEach((blockCmp, index) => {
501
- blockCmp.block.index = index;
502
- this._store.blockChange(blockCmp.block);
534
+ .forEach((block, index) => {
535
+ block.index = index;
536
+ this._store.blockChange(block);
503
537
  this._store.updateTabIndex(index);
504
538
  });
505
539
  });
@@ -542,12 +576,28 @@ class FsBlockComponent {
542
576
  this._transformable = false;
543
577
  this._destroy$ = new Subject();
544
578
  }
579
+ set block(block) {
580
+ this._block = block;
581
+ this._block.resizable = !this.hasType([BlockType.Checkbox, BlockType.RadioButton]);
582
+ this._block.rotatable = !this.hasType([BlockType.Checkbox, BlockType.RadioButton]);
583
+ this._block.scalable = !this.hasType([BlockType.Checkbox, BlockType.RadioButton]);
584
+ if (this.moveable) {
585
+ this._updateMoveable();
586
+ }
587
+ }
588
+ ;
589
+ get block() {
590
+ return this._block;
591
+ }
545
592
  get el() {
546
593
  return this.element.nativeElement;
547
594
  }
548
595
  get moveable() {
549
596
  return this._moveable;
550
597
  }
598
+ hasType(types) {
599
+ return types.includes(this.block.type);
600
+ }
551
601
  get editable() {
552
602
  return this._editable;
553
603
  }
@@ -648,13 +698,8 @@ class FsBlockComponent {
648
698
  return this._transformable;
649
699
  }
650
700
  set transformable(value) {
651
- if (this.block.lock) {
652
- value = false;
653
- }
654
701
  this._transformable = value;
655
- this.moveable.resizable = value;
656
- this.moveable.rotatable = value;
657
- this.moveable.scalable = value;
702
+ this._updateMoveable();
658
703
  }
659
704
  set rotate(value) {
660
705
  this.moveable.request('rotatable', { rotate: parseFloat(value) }, true);
@@ -675,9 +720,10 @@ class FsBlockComponent {
675
720
  this.block.shadowOpacity = this.block.shadowOpacity || 100;
676
721
  this._initFonts();
677
722
  this._blockEditor.selectedBlocks$
678
- .pipe(takeUntil(this._destroy$))
723
+ .pipe(skip(1), takeUntil(this._destroy$))
679
724
  .subscribe((blocks) => {
680
725
  this.selected = blocks.includes(this.block);
726
+ this.transformable = true;
681
727
  this._cdRef.markForCheck();
682
728
  });
683
729
  this._blockEditor.blockClippable$
@@ -691,12 +737,16 @@ class FsBlockComponent {
691
737
  .subscribe(() => {
692
738
  this._cdRef.markForCheck();
693
739
  });
740
+ this._blockEditor.blockUpdated$
741
+ .pipe(filter((block) => block.guid === this.block.guid), takeUntil(this._destroy$))
742
+ .subscribe((block) => {
743
+ this.block = block;
744
+ this._cdRef.markForCheck();
745
+ });
694
746
  this._blockEditor.blockChanged$
695
- .pipe(filter((block) => block === this.block), takeUntil(this._destroy$))
747
+ .pipe(filter((block) => block.guid === this.block.guid), takeUntil(this._destroy$))
696
748
  .subscribe((block) => {
697
- this.keepRatio = block.keepRatio;
698
- this.rotate = this.block.rotate;
699
- this._updateMoveable();
749
+ this.block = block;
700
750
  this._cdRef.markForCheck();
701
751
  });
702
752
  }
@@ -720,9 +770,6 @@ class FsBlockComponent {
720
770
  round(value, decimals) {
721
771
  return parseFloat(value.toFixed(decimals));
722
772
  }
723
- select() {
724
- this.transformable = true;
725
- }
726
773
  deselect() {
727
774
  this.editable = false;
728
775
  this.clippable = false;
@@ -742,7 +789,7 @@ class FsBlockComponent {
742
789
  }
743
790
  }
744
791
  }
745
- selectAll() {
792
+ selectTextAll() {
746
793
  const range = document.createRange();
747
794
  range.selectNodeContents(this.contentEditable.nativeElement);
748
795
  const sel = window.getSelection();
@@ -767,11 +814,12 @@ class FsBlockComponent {
767
814
  .filter((el) => !el.isSameNode(this.el));
768
815
  }
769
816
  _updateMoveable() {
770
- this._moveable.draggable = !this.block.lock;
771
- if (this.selected) {
772
- this._moveable.resizable = !this.block.lock;
773
- this._moveable.rotatable = !this.block.lock;
774
- }
817
+ const value = !this.block.lock && this.selected;
818
+ this.keepRatio = this.block.keepRatio;
819
+ this.rotate = this.block.rotate;
820
+ this.moveable.resizable = this.block.resizable && value;
821
+ this.moveable.rotatable = this.block.rotatable && value;
822
+ this.moveable.scalable = this.block.scalable && value;
775
823
  }
776
824
  _initMoveable() {
777
825
  this._moveable = new Moveable(this._elementRef.nativeElement, {
@@ -925,8 +973,14 @@ class FsBlockComponent {
925
973
  this._triggerChanged();
926
974
  });
927
975
  fromEvent(this.el, 'mousedown')
928
- .pipe(takeUntil(this._destroy$)).subscribe((event) => {
929
- if (!this.block.lock) {
976
+ .pipe(takeUntil(this._destroy$))
977
+ .subscribe((event) => {
978
+ if (this.block.lock) {
979
+ event.preventDefault();
980
+ event.stopImmediatePropagation();
981
+ event.stopPropagation();
982
+ }
983
+ else {
930
984
  this.zoompan.disable();
931
985
  }
932
986
  if (!this.moveable.clippable) {
@@ -956,7 +1010,7 @@ class FsBlockComponent {
956
1010
  this.editable = true;
957
1011
  this._cdRef.markForCheck();
958
1012
  setTimeout(() => {
959
- this.selectAll();
1013
+ this.selectTextAll();
960
1014
  });
961
1015
  }
962
1016
  });
@@ -968,7 +1022,7 @@ class FsBlockComponent {
968
1022
  }
969
1023
  }
970
1024
  FsBlockComponent.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.2.16", ngImport: i0, type: FsBlockComponent, deps: [{ token: BlockEditorService }, { token: i0.ElementRef }, { token: i0.ChangeDetectorRef }, { token: GoogleFontService }], target: i0.ɵɵFactoryTarget.Component });
971
- FsBlockComponent.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "12.0.0", version: "12.2.16", type: FsBlockComponent, selector: "fs-block", inputs: { block: "block", html: "html", zoompan: "zoompan" }, host: { properties: { "class.transforming": "this.transformating" } }, viewQueries: [{ propertyName: "element", first: true, predicate: ["element"], descendants: true, static: true }, { propertyName: "contentElement", first: true, predicate: ["contentElement"], descendants: true, static: true }, { propertyName: "contentEditable", first: true, predicate: ["contentEditable"], descendants: true, static: true }], ngImport: i0, template: "<div\n #element\n [class]=\"'block ' + 'block-' + block.type\"\n [style.top]=\"styleTop\"\n [style.left]=\"styleLeft\"\n [style.width]=\"styleWidth\"\n [style.height]=\"styleHeight\"\n [ngClass]=\"{ \n editable: editable, \n readonly: block.readonly,\n required: block.required,\n lock: block.lock,\n selected: selected\n }\"\n [style.zIndex]=\"block.index\">\n <div\n #contentElement\n class=\"content\"\n [style.borderColor]=\"block.borderColor\"\n [style.borderWidth]=\"block.borderWidth ? block.borderWidth + 'pt' : ''\"\n [style.borderStyle]=\"block.borderColor ? 'solid' : 'dashed'\"\n [style.textAlign]=\"block.horizontalAlign\"\n [style.fontStyle]=\"block.italic ? 'italic' : ''\"\n [style.fontFamily]=\"block.fontFamily || ''\"\n [style.fontSize]=\"block.fontSize ? block.fontSize + 'pt' : ''\"\n [style.lineHeight]=\"block.lineHeight ? block.lineHeight + 'pt' : ''\"\n [style.color]=\"block.fontColor\"\n [style.fontWeight]=\"block.bold ? 'bold' : ''\"\n [style.textDecoration]=\"block.underline ? 'underline' : ''\"\n [style.paddingTop]=\"block.paddingTop ? block.paddingTop + 'in' : ''\"\n [style.paddingBottom]=\"block.paddingBottom ? block.paddingBottom + 'in' : ''\"\n [style.paddingLeft]=\"block.paddingLeft ? block.paddingLeft + 'in' : ''\"\n [style.paddingRight]=\"block.paddingRight ? block.paddingRight + 'in' : ''\"\n [style.backgroundColor]=\"block.backgroundColor\"\n [style.borderBottomLeftRadius]=\"block.shapeRadius && block.shapeBottomLeft === 'round' ? block.shapeRadius + '%' : ''\"\n [style.borderBottomRightRadius]=\"block.shapeRadius && block.shapeBottomRight === 'round' ? block.shapeRadius + '%' : ''\"\n [style.borderTopRightRadius]=\"block.shapeRadius && block.shapeTopRight === 'round' ? block.shapeRadius + '%' : ''\"\n [style.borderTopLeftRadius]=\"block.shapeRadius && block.shapeTopLeft === 'round' ? block.shapeRadius + '%' : ''\"\n [style.boxShadow]=\"styleBoxShadow\"\n [ngClass]=\"{\n 'editable': editable,\n 'vertical-align-center': block.verticalAlign === 'center',\n 'vertical-align-bottom': block.verticalAlign === 'bottom'\n }\">\n <ng-container [ngSwitch]=\"block.type\">\n <ng-container *ngIf=\"block.imageUrl && ((block.imageUrl | createImageUrl) | async) as src\">\n <img \n [style.opacity]=\"block.imageOpacity ? block.imageOpacity/100 : 1\"\n [src]=\"src\">\n </ng-container>\n\n </ng-container>\n <ng-container *ngIf=\"block.type === BlockType.LongText || block.type === BlockType.ShortText || block.type === BlockType.RadioButton || block.type === BlockType.Checkbox || block.type === BlockType.Date\">\n {{block.label || block.name}}\n </ng-container>\n <div\n #contentEditable\n [contentEditable]=\"editable\"\n class=\"content-editable\"\n [innerHTML]=\"content\">\n </div>\n </div>\n <div class=\"outline\"></div>\n</div>\n", styles: [":host ::ng-deep .moveable-control{width:10px!important;height:10px!important;margin-top:-5px!important;margin-left:-5px!important}:host.transforming ::ng-deep .moveable-control,:host.transforming ::ng-deep .moveable-rotation{display:none}.block{position:absolute;display:block;outline:none;-webkit-user-select:none;user-select:none;cursor:pointer;box-sizing:border-box}.block.selected{border-color:#31a2ff95}.block.block-shorttext,.block.block-longtext,.block.block-date,.block.block-radiobutton,.block.block-signature,.block.block-checkbox{background-color:#aab5e1cc;color:#585555;font-size:12px}.block.block-radiobutton{border-radius:50%}.block.required{background-color:#f7adaa}.block .content-editable{outline:none;position:relative;margin:-1px}.block.editable .content-editable{cursor:text}.block .content{flex-direction:column;height:100%;display:flex;border:0px solid transparent;position:relative;box-sizing:border-box;overflow:hidden}.block .content fs-html-editor{width:100%}.block .content.vertical-align-center{justify-content:center}.block .content.vertical-align-bottom{justify-content:flex-end}.block .content img{width:100%;height:100%;position:absolute}.block.selected .outline,.block:hover .outline{border:1px solid rgba(68,170,255,.7);position:absolute;top:0;left:0;bottom:0;right:0}.block.selected.lock .outline,.block:hover.lock .outline{border-color:#e4181866;border-style:dashed}:host ::ng-deep fs-html-editor .bottom-line,:host ::ng-deep fs-html-editor .fr-toolbar{display:none!important}:host ::ng-deep fs-html-editor .fr-wrapper{background:none!important;border:none!important}:host ::ng-deep .moveable-line:not(.moveable-rotation-line):not(.moveable-guideline){background:transparent!important}\n"], directives: [{ type: i13.NgClass, selector: "[ngClass]", inputs: ["class", "ngClass"] }, { type: i13.NgSwitch, selector: "[ngSwitch]", inputs: ["ngSwitch"] }, { type: i13.NgIf, selector: "[ngIf]", inputs: ["ngIf", "ngIfThen", "ngIfElse"] }], pipes: { "async": i13.AsyncPipe, "createImageUrl": CreateImageUrlPipe }, changeDetection: i0.ChangeDetectionStrategy.OnPush });
1025
+ FsBlockComponent.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "12.0.0", version: "12.2.16", type: FsBlockComponent, selector: "fs-block", inputs: { block: "block", html: "html", zoompan: "zoompan" }, host: { properties: { "class.transforming": "this.transformating" } }, viewQueries: [{ propertyName: "element", first: true, predicate: ["element"], descendants: true, static: true }, { propertyName: "contentElement", first: true, predicate: ["contentElement"], descendants: true, static: true }, { propertyName: "contentEditable", first: true, predicate: ["contentEditable"], descendants: true, static: true }], ngImport: i0, template: "<div\n #element\n [class]=\"'block ' + 'block-' + block.type\"\n [style.top]=\"styleTop\"\n [style.left]=\"styleLeft\"\n [style.width]=\"styleWidth\"\n [style.height]=\"styleHeight\"\n [ngClass]=\"{ \n editable: editable, \n readonly: block.readonly,\n required: block.required,\n lock: block.lock,\n selected: selected\n }\"\n [style.zIndex]=\"block.index\">\n <div\n #contentElement\n class=\"content\"\n [style.borderColor]=\"block.borderColor\"\n [style.borderWidth]=\"block.borderWidth ? block.borderWidth + 'pt' : ''\"\n [style.borderStyle]=\"block.borderColor ? 'solid' : 'dashed'\"\n [style.textAlign]=\"block.horizontalAlign\"\n [style.fontStyle]=\"block.italic ? 'italic' : ''\"\n [style.fontFamily]=\"block.fontFamily || ''\"\n [style.fontSize]=\"block.fontSize ? block.fontSize + 'pt' : ''\"\n [style.lineHeight]=\"block.lineHeight ? block.lineHeight + 'pt' : ''\"\n [style.color]=\"block.fontColor\"\n [style.fontWeight]=\"block.bold ? 'bold' : ''\"\n [style.textDecoration]=\"block.underline ? 'underline' : ''\"\n [style.paddingTop]=\"block.paddingTop ? block.paddingTop + 'in' : ''\"\n [style.paddingBottom]=\"block.paddingBottom ? block.paddingBottom + 'in' : ''\"\n [style.paddingLeft]=\"block.paddingLeft ? block.paddingLeft + 'in' : ''\"\n [style.paddingRight]=\"block.paddingRight ? block.paddingRight + 'in' : ''\"\n [style.backgroundColor]=\"block.backgroundColor\"\n [style.borderBottomLeftRadius]=\"block.shapeRadius && block.shapeBottomLeft === 'round' ? block.shapeRadius + '%' : ''\"\n [style.borderBottomRightRadius]=\"block.shapeRadius && block.shapeBottomRight === 'round' ? block.shapeRadius + '%' : ''\"\n [style.borderTopRightRadius]=\"block.shapeRadius && block.shapeTopRight === 'round' ? block.shapeRadius + '%' : ''\"\n [style.borderTopLeftRadius]=\"block.shapeRadius && block.shapeTopLeft === 'round' ? block.shapeRadius + '%' : ''\"\n [style.boxShadow]=\"styleBoxShadow\"\n [ngClass]=\"{\n 'editable': editable,\n 'vertical-align-center': block.verticalAlign === 'center',\n 'vertical-align-bottom': block.verticalAlign === 'bottom'\n }\">\n <ng-container [ngSwitch]=\"block.type\">\n <ng-container *ngIf=\"block.imageUrl && ((block.imageUrl | createImageUrl) | async) as src\">\n <img \n [style.opacity]=\"block.imageOpacity ? block.imageOpacity/100 : 1\"\n [src]=\"src\">\n </ng-container>\n\n </ng-container>\n <ng-container *ngIf=\"block.type === BlockType.LongText || block.type === BlockType.ShortText || block.type === BlockType.RadioButton || block.type === BlockType.Checkbox || block.type === BlockType.Date\">\n {{block.label || block.name}}\n </ng-container>\n <div\n #contentEditable\n [contentEditable]=\"editable\"\n class=\"content-editable\"\n [innerHTML]=\"content\">\n </div>\n </div>\n <div class=\"outline\"></div>\n</div>\n", styles: [":host ::ng-deep .moveable-control{width:10px!important;height:10px!important;margin-top:-5px!important;margin-left:-5px!important}:host.transforming ::ng-deep .moveable-control,:host.transforming ::ng-deep .moveable-rotation{display:none}.block{position:absolute;display:block;outline:none;-webkit-user-select:none;user-select:none;cursor:pointer;box-sizing:border-box}.block.selected{border-color:#31a2ff95}.block.block-shorttext,.block.block-longtext,.block.block-date,.block.block-radiobutton,.block.block-signature,.block.block-checkbox{background-color:#aab5e1cc;color:#585555;font-size:12px}.block.block-radiobutton{border-radius:50%}.block.required{background-color:#f7adaa}.block .content-editable{outline:none;position:relative;height:100%;width:100%;z-index:100}.block.editable .content-editable{cursor:text}.block .content{flex-direction:column;height:100%;display:flex;border:0px solid transparent;position:relative;box-sizing:border-box;overflow:hidden}.block .content fs-html-editor{width:100%}.block .content.vertical-align-center{justify-content:center}.block .content.vertical-align-bottom{justify-content:flex-end}.block .content img{width:100%;height:100%;position:absolute}.block.selected .outline,.block:hover .outline{border:1px solid rgba(68,170,255,.7);position:absolute;top:0;left:0;bottom:0;right:0;-webkit-user-select:none;user-select:none}.block.selected.lock .outline,.block:hover.lock .outline{border-color:#e4181866;border-style:dashed}:host ::ng-deep fs-html-editor .bottom-line,:host ::ng-deep fs-html-editor .fr-toolbar{display:none!important}:host ::ng-deep fs-html-editor .fr-wrapper{background:none!important;border:none!important}:host ::ng-deep .moveable-line:not(.moveable-rotation-line):not(.moveable-guideline){background:transparent!important}\n"], directives: [{ type: i13.NgClass, selector: "[ngClass]", inputs: ["class", "ngClass"] }, { type: i13.NgSwitch, selector: "[ngSwitch]", inputs: ["ngSwitch"] }, { type: i13.NgIf, selector: "[ngIf]", inputs: ["ngIf", "ngIfThen", "ngIfElse"] }], pipes: { "async": i13.AsyncPipe, "createImageUrl": CreateImageUrlPipe }, changeDetection: i0.ChangeDetectionStrategy.OnPush });
972
1026
  i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.16", ngImport: i0, type: FsBlockComponent, decorators: [{
973
1027
  type: Component,
974
1028
  args: [{
@@ -987,7 +1041,8 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.16", ngImpo
987
1041
  type: ViewChild,
988
1042
  args: ['contentEditable', { static: true }]
989
1043
  }], block: [{
990
- type: Input
1044
+ type: Input,
1045
+ args: ['block']
991
1046
  }], html: [{
992
1047
  type: Input
993
1048
  }], zoompan: [{
@@ -997,42 +1052,6 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.16", ngImpo
997
1052
  args: ['class.transforming']
998
1053
  }] } });
999
1054
 
1000
- class FsBlockEditorSidebarPanelDirective {
1001
- constructor(templateRef) {
1002
- this.templateRef = templateRef;
1003
- this.show = true;
1004
- }
1005
- }
1006
- FsBlockEditorSidebarPanelDirective.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.2.16", ngImport: i0, type: FsBlockEditorSidebarPanelDirective, deps: [{ token: i0.TemplateRef }], target: i0.ɵɵFactoryTarget.Directive });
1007
- FsBlockEditorSidebarPanelDirective.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "12.0.0", version: "12.2.16", type: FsBlockEditorSidebarPanelDirective, selector: "[fsBlockEditorSidebarPanel]", inputs: { label: "label", show: "show" }, ngImport: i0 });
1008
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.16", ngImport: i0, type: FsBlockEditorSidebarPanelDirective, decorators: [{
1009
- type: Directive,
1010
- args: [{
1011
- selector: '[fsBlockEditorSidebarPanel]'
1012
- }]
1013
- }], ctorParameters: function () { return [{ type: i0.TemplateRef }]; }, propDecorators: { label: [{
1014
- type: Input
1015
- }], show: [{
1016
- type: Input
1017
- }] } });
1018
-
1019
- class FsBlockEditorMarginDirective {
1020
- constructor(_elementRef) {
1021
- this._elementRef = _elementRef;
1022
- }
1023
- get element() {
1024
- return this._elementRef.nativeElement;
1025
- }
1026
- }
1027
- FsBlockEditorMarginDirective.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.2.16", ngImport: i0, type: FsBlockEditorMarginDirective, deps: [{ token: i0.ElementRef }], target: i0.ɵɵFactoryTarget.Directive });
1028
- FsBlockEditorMarginDirective.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "12.0.0", version: "12.2.16", type: FsBlockEditorMarginDirective, selector: "[fsBlockEditorMargin]", ngImport: i0 });
1029
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.16", ngImport: i0, type: FsBlockEditorMarginDirective, decorators: [{
1030
- type: Directive,
1031
- args: [{
1032
- selector: '[fsBlockEditorMargin]'
1033
- }]
1034
- }], ctorParameters: function () { return [{ type: i0.ElementRef }]; } });
1035
-
1036
1055
  const BlockFormats = [
1037
1056
  { value: BlockFormat.Number, name: 'Number', blockTypes: [BlockType.ShortText, BlockType.LongText] },
1038
1057
  { value: BlockFormat.Currency, name: 'Currency', blockTypes: [BlockType.ShortText, BlockType.LongText] },
@@ -1170,8 +1189,9 @@ class SidebarComponent {
1170
1189
  }
1171
1190
  }
1172
1191
  blockUpload(block, fsFile) {
1173
- this._blockEditor
1174
- .blockUpload(block, fsFile);
1192
+ this._blockEditor.blockUpload(block, fsFile)
1193
+ .subscribe((newBlock) => {
1194
+ });
1175
1195
  }
1176
1196
  blockAdd(type) {
1177
1197
  if (type === BlockType.Pdf || type === BlockType.Image) {
@@ -1186,20 +1206,20 @@ class SidebarComponent {
1186
1206
  this._blockEditor.blockAdd(block);
1187
1207
  }
1188
1208
  layerMove(direction) {
1189
- this._blockEditor.blockComponents.forEach((blockComponent) => {
1190
- if (this._blockEditor.isSelectedBlock(blockComponent)) {
1191
- blockComponent.block.index += (999 * direction);
1209
+ this._blockEditor.blocks.forEach((block) => {
1210
+ if (this._blockEditor.isSelectedBlock(block)) {
1211
+ block.index += (999 * direction);
1192
1212
  }
1193
1213
  });
1194
- const sorted = this._blockEditor.blockComponents.sort((a, b) => {
1195
- return a.block.index > b.block.index ? 1 : -1;
1214
+ const sorted = this._blockEditor.blocks.sort((a, b) => {
1215
+ return a.index > b.index ? 1 : -1;
1196
1216
  });
1197
- sorted.forEach((item, index) => {
1198
- item.block.index = index;
1199
- item.markForCheck();
1217
+ sorted.forEach((block, index) => {
1218
+ block.index = index;
1219
+ this._blockEditor.blockChange(block);
1200
1220
  });
1201
1221
  if (this.config.blocksLevelChanged) {
1202
- this.config.blocksLevelChanged(sorted.map((item) => item.block));
1222
+ this.config.blocksLevelChanged(sorted.map((block) => block));
1203
1223
  }
1204
1224
  }
1205
1225
  layerUp() {
@@ -1291,23 +1311,23 @@ class ArtboardComponent {
1291
1311
  .subscribe((event) => {
1292
1312
  event.preventDefault();
1293
1313
  const inchPixel = 1 / 100;
1294
- this._blockEditor.selectedComponentBlocks
1295
- .forEach((blockComponent) => {
1314
+ this._blockEditor.selectedBlocks
1315
+ .forEach((block) => {
1296
1316
  switch (event.key) {
1297
1317
  case 'ArrowUp':
1298
- blockComponent.block.top = blockComponent.block.top - inchPixel;
1318
+ block.top = round(block.top - inchPixel, 2);
1299
1319
  break;
1300
1320
  case 'ArrowDown':
1301
- blockComponent.block.top = blockComponent.block.top + inchPixel;
1321
+ block.top = round(block.top + inchPixel, 2);
1302
1322
  break;
1303
1323
  case 'ArrowLeft':
1304
- blockComponent.block.left = blockComponent.block.left - inchPixel;
1324
+ block.left = round(block.left - inchPixel, 2);
1305
1325
  break;
1306
1326
  case 'ArrowRight':
1307
- blockComponent.block.left = blockComponent.block.left + inchPixel;
1327
+ block.left = round(block.left + inchPixel, 2);
1308
1328
  break;
1309
1329
  }
1310
- this._blockEditor.blockChange(blockComponent.block);
1330
+ this._blockEditor.blockChange(block);
1311
1331
  });
1312
1332
  });
1313
1333
  }