@innovastudio/contentbuilder 1.2.14 → 1.2.17

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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@innovastudio/contentbuilder",
3
- "version": "1.2.14",
3
+ "version": "1.2.17",
4
4
  "type": "module",
5
5
  "description": "",
6
6
  "main": "public/contentbuilder/contentbuilder.esm.js",
@@ -121,29 +121,40 @@ button:focus {
121
121
  display: flex;
122
122
  }
123
123
  }
124
+ /*
124
125
  .sortable-drag {
125
- background: transparent;
126
- outline: none !important;
127
- }
128
- .sortable-drag * {
129
- opacity: 0;
130
- }
131
- .sortable-drag .is-row-tool {
132
- opacity: 0;
126
+ background: transparent; // background:rgba(0,0,0,0.04);
127
+ outline:none !important;
128
+ * {
129
+ opacity:0;
130
+ }
131
+ .is-row-tool {
132
+ opacity:0;
133
+ }
133
134
  }
134
135
 
135
136
  .sortable-ghost {
136
- background: rgba(204, 204, 204, 0.15);
137
- width: 100%;
138
- outline: none !important;
139
- }
140
- .sortable-ghost * {
141
- outline: none !important;
142
- }
143
- .sortable-ghost .is-row-tool {
144
- display: none !important;
137
+ background: $ui-sortable-ghost-color;
138
+ width: 100%;
139
+ outline: none !important;
140
+ * {
141
+ outline: none !important;
142
+ }
143
+ .is-row-tool {
144
+ display:none !important;
145
+ }
145
146
  }
146
147
 
148
+ .sortable-drag::before {
149
+ content: ' ';
150
+ width: 100%;
151
+ height: 100%;
152
+ position: absolute;
153
+ top: 0; left:0;
154
+ background: rgba(0, 0, 0 , 0.03);
155
+ transform-origin: top left;
156
+ }
157
+ */
147
158
  #_cbhtml .snippet-item {
148
159
  cursor: move !important;
149
160
  }
@@ -4196,8 +4196,19 @@ class Util {
4196
4196
  dom.addClass(pop, 'deactive');
4197
4197
  }
4198
4198
 
4199
+ clearAllEventListener(pop) {
4200
+ for (let i = 0; i < 10; i++) {
4201
+ pop.removeEventListener('keydown', this.handlePopKeyDown);
4202
+ document.removeEventListener('click', this.handlePopClickOut);
4203
+ }
4204
+ }
4205
+
4199
4206
  showPop(pop, cancelCallback, btn) {
4200
4207
  const dom = this.dom;
4208
+ if (pop.style.display === 'flex') return; // important
4209
+
4210
+ this.clearAllEventListener(pop); // for safety of uncleared events as a result of closing without hidePop()
4211
+
4201
4212
  pop.style.display = 'flex';
4202
4213
  dom.addClass(pop, 'active');
4203
4214
  pop.setAttribute('aria-hidden', false);
@@ -4206,37 +4217,40 @@ class Util {
4206
4217
  preventScroll: true
4207
4218
  });
4208
4219
 
4209
- const handleClickOut = e => {
4220
+ this.handlePopClickOut = e => {
4210
4221
  if (!pop.contains(e.target) && !btn.contains(e.target)) {
4211
4222
  // click outside
4212
4223
  // hide
4213
- this.hidePop(pop);
4214
- pop.removeEventListener('keydown', handleKeyDown);
4215
- document.removeEventListener('click', handleClickOut);
4224
+ this.hidePop(pop); // pop.removeEventListener('keydown', this.handlePopKeyDown);
4225
+ // document.removeEventListener('click', this.handlePopClickOut);
4226
+
4216
4227
  if (cancelCallback) cancelCallback();
4217
4228
  }
4218
4229
  };
4219
4230
 
4220
- const handleKeyDown = e => {
4231
+ this.handlePopKeyDown = e => {
4221
4232
  if (e.keyCode === 27) {
4222
4233
  // escape key
4223
4234
  // hide
4224
- this.hidePop(pop);
4225
- pop.removeEventListener('keydown', handleKeyDown);
4226
- document.removeEventListener('click', handleClickOut);
4235
+ this.hidePop(pop); // pop.removeEventListener('keydown', this.handlePopKeyDown);
4236
+ // document.removeEventListener('click', this.handlePopClickOut);
4237
+
4227
4238
  if (cancelCallback) cancelCallback();
4228
4239
  }
4229
4240
  };
4230
4241
 
4231
- pop.addEventListener('keydown', handleKeyDown);
4232
- document.addEventListener('click', handleClickOut);
4242
+ pop.addEventListener('keydown', this.handlePopKeyDown);
4243
+ document.addEventListener('click', this.handlePopClickOut);
4233
4244
  }
4234
4245
 
4235
4246
  hidePop(pop) {
4236
4247
  const dom = this.dom;
4237
4248
  pop.style.display = '';
4238
4249
  dom.removeClass(pop, 'active');
4239
- pop.setAttribute('aria-hidden', true);
4250
+ pop.setAttribute('aria-hidden', true); // pop.removeEventListener('keydown', this.handlePopKeyDown);
4251
+ // document.removeEventListener('click', this.handlePopClickOut);
4252
+
4253
+ this.clearAllEventListener(pop);
4240
4254
  }
4241
4255
 
4242
4256
  setupTabKeys(div) {
@@ -6844,6 +6858,17 @@ class Util {
6844
6858
 
6845
6859
  }
6846
6860
  class Dom {
6861
+ getScale(container) {
6862
+ let matrix = window.getComputedStyle(container).transform;
6863
+ let values = matrix.split('(')[1];
6864
+ values = values.split(')')[0];
6865
+ values = values.split(',');
6866
+ let a = values[0];
6867
+ let b = values[1];
6868
+ let scale = Math.sqrt(a * a + b * b);
6869
+ return scale;
6870
+ }
6871
+
6847
6872
  createElement(tag) {
6848
6873
  return document.createElement(tag);
6849
6874
  }
@@ -21575,12 +21600,12 @@ const renderSnippetPanel = builder => {
21575
21600
  let chromeAgent = userAgentString.indexOf('Chrome') > -1;
21576
21601
  if ((chromeAgent) && (safariAgent)) safariAgent = false;
21577
21602
  */
21603
+ // let safariAgent = false;
21578
21604
 
21579
21605
 
21580
- let safariAgent = false;
21581
21606
  let activeBuilderArea;
21582
21607
  new Sortable(snippetlist, {
21583
- forceFallback: safariAgent,
21608
+ // forceFallback: safariAgent,
21584
21609
  group: {
21585
21610
  name: 'shared',
21586
21611
  pull: 'clone',
@@ -21589,6 +21614,18 @@ const renderSnippetPanel = builder => {
21589
21614
  },
21590
21615
  sort: false,
21591
21616
  animation: 150,
21617
+ onChoose: () => {
21618
+ // Make moving draggable item scaled & positioned correctly (due to zoom value)
21619
+ // const newCss = `
21620
+ // <style id="css-scale">
21621
+ // .sortable-drag::before {
21622
+ // transform: scale(1);
21623
+ // }
21624
+ // </style>
21625
+ // `;
21626
+ const oldCss = builder.contentStuff.querySelector('#css-scale');
21627
+ if (oldCss) oldCss.parentNode.removeChild(oldCss); // builder.contentStuff.insertAdjacentHTML('afterbegin', newCss);
21628
+ },
21592
21629
  onMove: () => {
21593
21630
  let emptyinfo = document.querySelector('.row-add-initial'); // if there is empty info, remove it during snippet drag drop
21594
21631
  // if(emptyinfo) emptyinfo.parentNode.removeChild(emptyinfo);
@@ -56533,7 +56570,7 @@ class ColumnTool {
56533
56570
  const scale = elm.getAttribute('data-scale');
56534
56571
 
56535
56572
  if (scale) {
56536
- inpImageHorSlider.value = scale;
56573
+ inpImageScaleSlider.value = scale;
56537
56574
  }
56538
56575
 
56539
56576
  const posX = elm.getAttribute('data-x');
@@ -69600,8 +69637,23 @@ class ContentBuilder {
69600
69637
  ['column sixth', 'column two-sixth'], ['column fifth', 'column two-fifth'], ['column fourth', 'column two-fourth'], ['column third', 'column two-third'], ['column half', 'column half'], ['column two-third', 'column third'], ['column two-fourth', 'column fourth'], ['column two-fifth', 'column fifth'], ['column two-sixth', 'column sixth']]];
69601
69638
  }
69602
69639
  }
69640
+ } // Experimental for iframe
69641
+
69642
+
69643
+ let doc;
69644
+ if (this.iframeDocument) doc = this.iframeDocument;else doc = document;
69645
+ this.doc = doc; // Content stuff
69646
+
69647
+ let contentStuff = doc.querySelector('.content-stuff');
69648
+
69649
+ if (!contentStuff) {
69650
+ contentStuff = document.createElement('div');
69651
+ contentStuff.className = 'content-stuff is-ui';
69652
+ doc.body.appendChild(contentStuff);
69603
69653
  }
69604
69654
 
69655
+ this.contentStuff = contentStuff;
69656
+ this.addStuff();
69605
69657
  this.sortableObjects = [];
69606
69658
  const util = new Util(this); // General utilities
69607
69659
 
@@ -70139,12 +70191,40 @@ class ContentBuilder {
70139
70191
  scroll: true,
70140
70192
  // invertSwap: true, /* https://github.com/SortableJS/Sortable/wiki/Swap-Thresholds-and-Direction#swap-threshold */
70141
70193
  group: 'shared',
70142
- direction: 'dummy',
70194
+ // direction: 'dummy',
70143
70195
  animation: 300,
70144
70196
  handle: '.row-handle',
70145
70197
  // swapThreshold: 0.1, // this cause drag drop snippet sometimes difficult
70146
70198
  // invertedSwapThreshold: 0.1,
70147
70199
  sort: true,
70200
+ //new
70201
+ swapThreshold: 0.5,
70202
+ // & comment the direction setting above
70203
+ onChoose: () => {
70204
+ // Get zoom (scale) value
70205
+ let scale;
70206
+
70207
+ if (this.opts.page !== '') {
70208
+ const wrapper = this.doc.querySelector(this.opts.page);
70209
+ scale = dom.getScale(wrapper);
70210
+ } else {
70211
+ const area = this.doc.querySelector('.is-builder'); // get one of the builder area
70212
+
70213
+ scale = dom.getScale(area);
70214
+ } // Make moving draggable item scaled & positioned correctly (due to zoom value)
70215
+
70216
+
70217
+ const newCss = `
70218
+ <style id="css-scale">
70219
+ .sortable-drag::before {
70220
+ transform: scale(${scale});
70221
+ }
70222
+ </style>
70223
+ `;
70224
+ const oldCss = this.contentStuff.querySelector('#css-scale');
70225
+ if (oldCss) oldCss.parentNode.removeChild(oldCss);
70226
+ this.contentStuff.insertAdjacentHTML('afterbegin', newCss);
70227
+ },
70148
70228
  onStart: () => {
70149
70229
  this.uo.saveForUndo(); // Even if cancelled, saveForUndo will make sure not to save if there is no change
70150
70230
 
@@ -72466,6 +72546,45 @@ class ContentBuilder {
72466
72546
  // return currentScript.replace(currentScriptFile, '');
72467
72547
  }
72468
72548
 
72549
+ addStuff() {
72550
+ const css = `
72551
+ <style>
72552
+ /* sortable */
72553
+ .sortable-drag {
72554
+ background: transparent;
72555
+ outline:none !important;
72556
+ }
72557
+ .sortable-drag * {
72558
+ opacity:0;
72559
+ }
72560
+
72561
+ .sortable-ghost {
72562
+ background: rgba(0, 0, 0 , 0.03);
72563
+ width: 100%;
72564
+ outline: none !important;
72565
+ }
72566
+ .sortable-ghost * {
72567
+ outline: none !important;
72568
+
72569
+ }
72570
+ .sortable-ghost .is-row-tool {
72571
+ display:none !important;
72572
+ }
72573
+
72574
+ .sortable-drag::before {
72575
+ content: ' ';
72576
+ width: 100%;
72577
+ height: 100%;
72578
+ position: absolute;
72579
+ top: 0; left:0;
72580
+ background: rgba(0, 0, 0 , 0.03);
72581
+ transform-origin: top left;
72582
+ }
72583
+ </style>
72584
+ `;
72585
+ this.contentStuff.insertAdjacentHTML('afterbegin', css);
72586
+ }
72587
+
72469
72588
  }
72470
72589
  // var run = (opts = {}) => {
72471
72590
  // return new ContentBuilder(opts);