@innovastudio/contentbuilder 1.5.163 → 1.5.165

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,7 +1,7 @@
1
1
  {
2
2
  "name": "@innovastudio/contentbuilder",
3
3
  "type": "module",
4
- "version": "1.5.163",
4
+ "version": "1.5.165",
5
5
  "description": "",
6
6
  "main": "public/contentbuilder/contentbuilder.esm.js",
7
7
  "types": "index.d.ts",
@@ -8,11 +8,6 @@
8
8
  font-weight: 300;
9
9
  line-height: 1.4;
10
10
  /* Default Elements */
11
- /* Built-in Grid */
12
- margin: 0 auto;
13
- width: 100%;
14
- padding: 0 20px;
15
- box-sizing: border-box;
16
11
  }
17
12
  .is-container h1, .is-container h2, .is-container h3, .is-container h4, .is-container h5, .is-container h6 {
18
13
  font-weight: 500;
@@ -122,72 +117,100 @@
122
117
  .is-container a {
123
118
  box-sizing: border-box;
124
119
  }
125
- .is-container .column {
120
+
121
+ /* Built-in Grid */
122
+ .is-container {
123
+ margin: 0 auto;
124
+ width: 100%;
125
+ padding: 0 20px;
126
+ box-sizing: border-box;
127
+ }
128
+
129
+ .column {
126
130
  position: relative;
127
131
  box-sizing: border-box;
128
132
  width: 100%;
129
133
  }
134
+
130
135
  @media (min-width: 761px) {
131
- .is-container .row {
136
+ .row {
132
137
  display: flex;
133
138
  }
134
- .is-container .column {
139
+
140
+ .column {
135
141
  padding-left: 1rem;
136
142
  padding-right: 1rem;
137
143
  }
138
- .is-container .column.full {
144
+
145
+ .column.full {
139
146
  width: 100%;
140
147
  }
141
- .is-container .column.two-third {
148
+
149
+ .column.two-third {
142
150
  width: 66.7%;
143
151
  }
144
- .is-container .column.two-fourth {
152
+
153
+ .column.two-fourth {
145
154
  width: 75%;
146
155
  }
147
- .is-container .column.two-fifth {
156
+
157
+ .column.two-fifth {
148
158
  width: 80%;
149
159
  }
150
- .is-container .column.two-sixth {
160
+
161
+ .column.two-sixth {
151
162
  width: 83.3%;
152
163
  }
153
- .is-container .column.half {
164
+
165
+ .column.half {
154
166
  width: 50%;
155
167
  }
156
- .is-container .column.third {
168
+
169
+ .column.third {
157
170
  width: 33.3%;
158
171
  }
159
- .is-container .column.fourth {
172
+
173
+ .column.fourth {
160
174
  width: 25%;
161
175
  }
162
- .is-container .column.fifth {
176
+
177
+ .column.fifth {
163
178
  width: 20%;
164
179
  }
165
- .is-container .column.sixth {
180
+
181
+ .column.sixth {
166
182
  width: 16.6%;
167
183
  }
168
- .is-container .column.seventh {
184
+
185
+ .column.seventh {
169
186
  width: 14.2857142857%;
170
187
  }
171
- .is-container .column.eighth {
188
+
189
+ .column.eighth {
172
190
  width: 12.5%;
173
191
  }
174
- .is-container .column.ninth {
192
+
193
+ .column.ninth {
175
194
  width: 11.1111111111%;
176
195
  }
177
- .is-container .column.tenth {
196
+
197
+ .column.tenth {
178
198
  width: 10%;
179
199
  }
180
- .is-container .column.eleventh {
200
+
201
+ .column.eleventh {
181
202
  width: 9.0909090909%;
182
203
  }
183
- .is-container .column.twelfth {
204
+
205
+ .column.twelfth {
184
206
  width: 8.3333333333%;
185
207
  }
186
- .is-container .column.flow-opposite {
208
+
209
+ .column.flow-opposite {
187
210
  float: right;
188
211
  }
189
212
  }
190
- .is-container .is-row-overlay {
213
+ .is-row-overlay {
191
214
  position: absolute;
192
215
  top: 0;
193
216
  left: 0;
@@ -2359,7 +2359,7 @@ button:focus-visible {
2359
2359
  .is-ui .is-modal.is-modal-content,
2360
2360
  .is-ui .is-modal .is-modal-content {
2361
2361
  background: #fff;
2362
- border: 1px solid #e3e3e3;
2362
+ border: 1px solid #dadada;
2363
2363
  box-shadow: 6px 14px 20px 0px rgba(95, 95, 95, 0.11);
2364
2364
  border-radius: 11px;
2365
2365
  overflow: hidden;
@@ -2375,7 +2375,7 @@ button:focus-visible {
2375
2375
  #_cbhtml .is-modal:not(.is-modal-content) > div:not(.is-modal-overlay),
2376
2376
  .is-ui .is-modal:not(.is-modal-content) > div:not(.is-modal-overlay) {
2377
2377
  background: #fff;
2378
- border: 1px solid #e3e3e3;
2378
+ border: 1px solid #dadada;
2379
2379
  box-shadow: 6px 14px 20px 0px rgba(95, 95, 95, 0.11);
2380
2380
  position: relative;
2381
2381
  width: 100%;
@@ -2416,9 +2416,10 @@ button:focus-visible {
2416
2416
  box-sizing: border-box;
2417
2417
  text-align: center;
2418
2418
  font-family: sans-serif;
2419
- font-size: 13px;
2419
+ font-size: 14px;
2420
+ font-weight: 500;
2420
2421
  letter-spacing: 1px;
2421
- color: #545454;
2422
+ color: #828282;
2422
2423
  touch-action: none;
2423
2424
  user-select: none;
2424
2425
  z-index: 1;
@@ -2431,17 +2432,17 @@ button:focus-visible {
2431
2432
  width: 32px;
2432
2433
  height: 32px;
2433
2434
  position: absolute;
2434
- top: 2px;
2435
- right: 2px;
2435
+ top: 0px;
2436
+ right: 0px;
2436
2437
  box-sizing: border-box;
2437
2438
  padding: 0;
2438
2439
  line-height: 32px;
2439
2440
  font-size: 12px;
2440
- color: #545454;
2441
+ color: #828282;
2441
2442
  text-align: center;
2442
2443
  cursor: pointer;
2443
2444
  box-shadow: none;
2444
- background: transparent;
2445
+ background-color: transparent !important;
2445
2446
  border: none;
2446
2447
  }
2447
2448
  #_cbhtml .is-modal div.is-modal-footer button,
@@ -2640,19 +2641,6 @@ button:focus-visible {
2640
2641
  flex-direction: row;
2641
2642
  align-items: flex-start;
2642
2643
  }
2643
- #_cbhtml .is-modal.pluginsettings .is-modal-bar,
2644
- .is-ui .is-modal.pluginsettings .is-modal-bar {
2645
- line-height: 30px;
2646
- height: 30px;
2647
- background-color: #fafafa;
2648
- }
2649
- #_cbhtml .is-modal.pluginsettings .is-modal-bar .is-modal-close,
2650
- .is-ui .is-modal.pluginsettings .is-modal-bar .is-modal-close {
2651
- width: 20px;
2652
- height: 20px;
2653
- line-height: 20px;
2654
- font-size: 10px;
2655
- }
2656
2644
  #_cbhtml .is-modal.pluginsettings.active,
2657
2645
  .is-ui .is-modal.pluginsettings.active {
2658
2646
  display: flex;
@@ -2683,17 +2671,8 @@ button:focus-visible {
2683
2671
  }
2684
2672
  #_cbhtml .is-modal.edittable .is-modal-bar,
2685
2673
  .is-ui .is-modal.edittable .is-modal-bar {
2686
- line-height: 30px;
2687
- height: 30px;
2688
2674
  background-color: #fafafa;
2689
2675
  }
2690
- #_cbhtml .is-modal.edittable .is-modal-bar .is-modal-close,
2691
- .is-ui .is-modal.edittable .is-modal-bar .is-modal-close {
2692
- width: 20px;
2693
- height: 20px;
2694
- line-height: 20px;
2695
- font-size: 10px;
2696
- }
2697
2676
  #_cbhtml .is-modal.edittable.active,
2698
2677
  .is-ui .is-modal.edittable.active {
2699
2678
  display: flex;
@@ -2738,18 +2717,6 @@ button:focus-visible {
2738
2717
  flex-direction: row;
2739
2718
  align-items: flex-start;
2740
2719
  }
2741
- #_cbhtml .is-modal.editblock .is-modal-bar,
2742
- .is-ui .is-modal.editblock .is-modal-bar {
2743
- line-height: 30px;
2744
- height: 30px;
2745
- }
2746
- #_cbhtml .is-modal.editblock .is-modal-bar .is-modal-close,
2747
- .is-ui .is-modal.editblock .is-modal-bar .is-modal-close {
2748
- width: 20px;
2749
- height: 20px;
2750
- line-height: 20px;
2751
- font-size: 10px;
2752
- }
2753
2720
  #_cbhtml .is-modal.editblock.active,
2754
2721
  .is-ui .is-modal.editblock.active {
2755
2722
  display: flex;
@@ -2959,19 +2926,6 @@ button:focus-visible {
2959
2926
  .is-ui .is-modal.buttoneditor .is-modal-overlay {
2960
2927
  display: none !important;
2961
2928
  }
2962
- #_cbhtml .is-modal.buttoneditor .is-modal-bar,
2963
- .is-ui .is-modal.buttoneditor .is-modal-bar {
2964
- line-height: 30px;
2965
- height: 30px;
2966
- background-color: #fafafa;
2967
- }
2968
- #_cbhtml .is-modal.buttoneditor .is-modal-bar .is-modal-close,
2969
- .is-ui .is-modal.buttoneditor .is-modal-bar .is-modal-close {
2970
- width: 20px;
2971
- height: 20px;
2972
- line-height: 20px;
2973
- font-size: 10px;
2974
- }
2975
2929
  #_cbhtml .is-modal.buttoneditor.active,
2976
2930
  .is-ui .is-modal.buttoneditor.active {
2977
2931
  display: flex;
@@ -5469,18 +5469,21 @@ class Util {
5469
5469
  let builderActive = this.builder.doc.querySelector('.builder-active');
5470
5470
  if (builderActive) this.builder.applyBehaviorOn(builderActive);
5471
5471
  this.fixLayout(row);
5472
-
5473
- // cellElement.click(); //change active block to the newly created
5474
- if (element && element.tagName.toLowerCase() === 'img') {
5475
- element.onload = () => {
5472
+ try {
5473
+ // cellElement.click(); //change active block to the newly created
5474
+ if (element && element.tagName.toLowerCase() === 'img') {
5475
+ element.onload = () => {
5476
+ element.click();
5477
+ element.onload = null;
5478
+ setTimeout(() => {
5479
+ this.builder.element.image.repositionImageTool();
5480
+ }, 100);
5481
+ };
5482
+ } else if (element) {
5476
5483
  element.click();
5477
- element.onload = null;
5478
- setTimeout(() => {
5479
- this.builder.element.image.repositionImageTool();
5480
- }, 100);
5481
- };
5482
- } else if (element) {
5483
- element.click();
5484
+ }
5485
+ } catch (e) {
5486
+ // Do Nothing
5484
5487
  }
5485
5488
  }
5486
5489
  if (mode === 'row') {
@@ -5598,6 +5601,12 @@ class Util {
5598
5601
 
5599
5602
  //Trigger Render event
5600
5603
  this.builder.opts.onRender();
5604
+
5605
+ // Reinit after drag drop block
5606
+ if (this.builder.win.builderRuntime) this.builder.win.builderRuntime.reinitialize();
5607
+ setTimeout(() => {
5608
+ this.builder.makeSortable(this.builder.doc);
5609
+ }, 400);
5601
5610
  }
5602
5611
 
5603
5612
  // https://stackoverflow.com/questions/494143/creating-a-new-dom-element-from-an-html-string-using-built-in-dom-methods-or-pro
@@ -5690,6 +5699,11 @@ class Util {
5690
5699
 
5691
5700
  //Hide Column tool (new!)
5692
5701
  this.builder.util.hideColumnTool();
5702
+
5703
+ // this.builder.makeSortable(rowElement); // cause other sortable not working
5704
+ setTimeout(() => {
5705
+ this.builder.makeSortable(this.builder.doc);
5706
+ }, 400);
5693
5707
  } else if (bSnippet) {
5694
5708
  if (noedit) {
5695
5709
  this.addContent(html, mode, 'data-noedit');
@@ -5863,6 +5877,9 @@ class Util {
5863
5877
  this.builder.doc.querySelectorAll('.dummy-module').forEach(module => {
5864
5878
  module.classList.remove('dummy-module');
5865
5879
  });
5880
+ setTimeout(() => {
5881
+ this.builder.makeSortable(this.builder.doc);
5882
+ }, 400);
5866
5883
 
5867
5884
  // Change to row selection
5868
5885
  rowElement.className = rowElement.className.replace('row-outline', '');
@@ -6080,6 +6097,11 @@ class Util {
6080
6097
  }
6081
6098
  }
6082
6099
 
6100
+ clearModals() {
6101
+ const builderStuff = this.builder.builderStuff;
6102
+ let modal = builderStuff.querySelector('.pluginsettings.active');
6103
+ this.hideModal(modal);
6104
+ }
6083
6105
  clearControls() {
6084
6106
  const dom = this.dom;
6085
6107
  const builderStuff = this.builder.builderStuff;
@@ -14489,6 +14511,7 @@ class HtmlUtil {
14489
14511
  // Re-init plugins
14490
14512
  if (this.builder.win.builderRuntime) await this.builder.win.builderRuntime.reinitialize();
14491
14513
  this.builder.hideModal(modal);
14514
+ this.builder.makeSortable(this.builder.doc);
14492
14515
  }
14493
14516
  viewHtmlExternal() {
14494
14517
  const util = this.builder.util;
@@ -15061,6 +15084,25 @@ class HtmlUtil {
15061
15084
  element.classList.remove(`cb-${type}`);
15062
15085
  }
15063
15086
  element.removeAttribute('data-cb-loaded');
15087
+ let grid;
15088
+ if (element.classList.contains('grid-sortable')) {
15089
+ grid = element;
15090
+ }
15091
+ if (element.querySelector('.grid-sortable')) {
15092
+ grid = element.querySelector('.grid-sortable');
15093
+ }
15094
+ element.removeAttribute('id');
15095
+ if (grid) {
15096
+ Array.from(grid.children).forEach(elm => {
15097
+ elm.removeAttribute('data-index');
15098
+ elm.removeAttribute('data-item-id');
15099
+ });
15100
+ }
15101
+ const elms = element.querySelectorAll('[data-scroll], [data-scroll-once]');
15102
+ elms.forEach(elm => {
15103
+ elm.removeAttribute('data-scroll');
15104
+ elm.removeAttribute('data-scroll-once');
15105
+ });
15064
15106
  });
15065
15107
  html = '';
15066
15108
  if (multiple) {
@@ -16193,6 +16235,9 @@ class Grid {
16193
16235
  this.builder.hideTools();
16194
16236
  cell.parentElement.insertBefore(cell, cell.previousElementSibling);
16195
16237
  this.builder.opts.onChange(true);
16238
+
16239
+ // Re-init plugins
16240
+ if (this.builder.win.builderRuntime) this.builder.win.builderRuntime.reinitialize(cell);
16196
16241
  }
16197
16242
  }
16198
16243
  moveColumnNext() {
@@ -16205,6 +16250,9 @@ class Grid {
16205
16250
  this.builder.hideTools();
16206
16251
  cell.parentElement.insertBefore(cellnext, cell);
16207
16252
  this.builder.opts.onChange(true);
16253
+
16254
+ // Re-init plugins
16255
+ if (this.builder.win.builderRuntime) this.builder.win.builderRuntime.reinitialize(cell);
16208
16256
  }
16209
16257
  }
16210
16258
  moveColumnUp() {
@@ -16234,6 +16282,9 @@ class Grid {
16234
16282
  //Move row up
16235
16283
  row.parentNode.insertBefore(row, row.previousElementSibling);
16236
16284
  this.builder.opts.onChange(true);
16285
+
16286
+ // Re-init plugins
16287
+ if (this.builder.win.builderRuntime) this.builder.win.builderRuntime.reinitialize(row);
16237
16288
  return;
16238
16289
  } else {
16239
16290
  this.builder.uo.saveForUndo();
@@ -16284,6 +16335,9 @@ class Grid {
16284
16335
  row = cell.parentNode; //update active row
16285
16336
  util.fixLayout(row);
16286
16337
  if (row.nextElementSibling) util.fixLayout(row.nextElementSibling);
16338
+
16339
+ // Re-init plugins
16340
+ if (this.builder.win.builderRuntime) this.builder.win.builderRuntime.reinitialize(row);
16287
16341
  }
16288
16342
  moveColumnDown() {
16289
16343
  let builder = this.builder;
@@ -16314,6 +16368,9 @@ class Grid {
16314
16368
  //Move row down
16315
16369
  row.parentNode.insertBefore(row.nextElementSibling, row);
16316
16370
  this.builder.opts.onChange(true);
16371
+
16372
+ // Re-init plugins
16373
+ if (this.builder.win.builderRuntime) this.builder.win.builderRuntime.reinitialize(row);
16317
16374
  return;
16318
16375
  } else {
16319
16376
  this.builder.uo.saveForUndo();
@@ -16364,6 +16421,9 @@ class Grid {
16364
16421
  row = cell.parentNode; //update active row
16365
16422
  util.fixLayout(row);
16366
16423
  if (row.previousElementSibling) util.fixLayout(row.previousElementSibling);
16424
+
16425
+ // Re-init plugins
16426
+ if (this.builder.win.builderRuntime) this.builder.win.builderRuntime.reinitialize(row);
16367
16427
  }
16368
16428
  duplicateColumn() {
16369
16429
  let builder = this.builder;
@@ -16405,6 +16465,7 @@ class Grid {
16405
16465
 
16406
16466
  // Re-init plugins
16407
16467
  if (this.builder.win.builderRuntime) this.builder.win.builderRuntime.reinitialize(cellElement);
16468
+ this.builder.makeSortable(cellElement);
16408
16469
  }
16409
16470
  removeColumn() {
16410
16471
  let util = this.util;
@@ -17067,6 +17128,9 @@ class Grid {
17067
17128
  row.parentNode.insertBefore(row, row.previousElementSibling);
17068
17129
  this.rowTool.position(row);
17069
17130
  this.builder.opts.onChange();
17131
+
17132
+ // Re-init plugins
17133
+ if (this.builder.win.builderRuntime) this.builder.win.builderRuntime.reinitialize(row);
17070
17134
  } else {
17071
17135
  // Move to previous container
17072
17136
 
@@ -17111,6 +17175,9 @@ class Grid {
17111
17175
  row.parentNode.insertBefore(row.nextElementSibling, row);
17112
17176
  this.rowTool.position(row);
17113
17177
  this.builder.opts.onChange();
17178
+
17179
+ // Re-init plugins
17180
+ if (this.builder.win.builderRuntime) this.builder.win.builderRuntime.reinitialize(row);
17114
17181
  } else {
17115
17182
  // Move to next container
17116
17183
 
@@ -17181,6 +17248,7 @@ class Grid {
17181
17248
 
17182
17249
  // Re-init plugins
17183
17250
  if (this.builder.win.builderRuntime) this.builder.win.builderRuntime.reinitialize(rowElement);
17251
+ this.builder.makeSortable(rowElement);
17184
17252
  }
17185
17253
  }
17186
17254
  class RowTool$1 {
@@ -53899,6 +53967,7 @@ class RowTool {
53899
53967
  const grid = new Grid(this.builder);
53900
53968
  grid.removeColumn();
53901
53969
  util.clearControls();
53970
+ util.clearModals();
53902
53971
  if (this.builder.onSelectChange) this.builder.onSelectChange();
53903
53972
  });
53904
53973
  let btnGridEditor = rowtool.querySelector('.row-grideditor');
@@ -54009,6 +54078,7 @@ class RowTool {
54009
54078
  if (elm) dom.addEventListener(elm, 'click', () => {
54010
54079
  this.grid.removeRow();
54011
54080
  util.clearControls();
54081
+ util.clearModals();
54012
54082
  if (this.builder.onSelectChange) this.builder.onSelectChange();
54013
54083
  });
54014
54084
  }
@@ -93406,6 +93476,9 @@ class BlockModal {
93406
93476
  new Tabs({
93407
93477
  element: modal
93408
93478
  });
93479
+ new Draggable$2({
93480
+ selector: '.is-modal.editblock .is-draggable'
93481
+ });
93409
93482
  } // constructor
93410
93483
 
93411
93484
  getPage() {
@@ -96014,6 +96087,7 @@ Add an image for each feature.`, 'Create a new content showcasing a photo galler
96014
96087
  }
96015
96088
  });
96016
96089
  });
96090
+ this.makeSortable(this.doc);
96017
96091
  }
96018
96092
 
96019
96093
  // Load plugins
@@ -97889,8 +97963,16 @@ Add an image for each feature.`, 'Create a new content showcasing a photo galler
97889
97963
  let newRow = newRows[0]; // get first added row
97890
97964
  if (newRow.children.length > 0) {
97891
97965
  const newCol = newRow.children[0];
97966
+ const isPlugin = newCol.querySelector('[data-cb-type]');
97892
97967
  if (newCol.children.length > 0) {
97893
- newCol.children[0].click(); // Focus on first element
97968
+ if (isPlugin) {
97969
+ setTimeout(() => {
97970
+ // give time for plugin to render (apply style) => for correct elm tool position
97971
+ newCol.children[0].click();
97972
+ }, 400);
97973
+ } else {
97974
+ newCol.children[0].click(); // Focus on first element
97975
+ }
97894
97976
  }
97895
97977
  }
97896
97978
  }
@@ -97991,6 +98073,9 @@ Add an image for each feature.`, 'Create a new content showcasing a photo galler
97991
98073
  });
97992
98074
  });
97993
98075
  });
98076
+ setTimeout(() => {
98077
+ this.makeSortable(this.doc);
98078
+ }, 400);
97994
98079
  this.doc.querySelectorAll('.dummy-module').forEach(module => {
97995
98080
  module.classList.remove('dummy-module');
97996
98081
  });
@@ -99655,6 +99740,7 @@ Add an image for each feature.`, 'Create a new content showcasing a photo galler
99655
99740
  this.rte.viewZoom();
99656
99741
  }
99657
99742
  async loadSnippets(source, snippetOpen) {
99743
+ this.snippetUrl = source;
99658
99744
  if (this.preview) return;
99659
99745
  if (this.opts.snippetList === '#divSnippetList') {
99660
99746
  let snippetPanel = document.querySelector(this.opts.snippetList);
@@ -99778,24 +99864,7 @@ Please obtain a license at: https://innovastudio.com/contentbox`);
99778
99864
  });
99779
99865
 
99780
99866
  // On Load HTML
99781
- const grids = this.doc.querySelectorAll('.grid-sortable');
99782
- grids.forEach(grid => {
99783
- if (grid.closest('.is-builder')) new Sortable(grid, {
99784
- animation: 600,
99785
- dragClass: 'hide-drag-class',
99786
- onStart: () => {
99787
- this.uo.saveForUndo(true);
99788
- },
99789
- onSort: () => {
99790
- if (grid.closest('[data-html]')) {
99791
- const moduleElm = grid.closest('[data-html]');
99792
- const encodedHtml = encodeURIComponent(moduleElm.innerHTML);
99793
- moduleElm.setAttribute('data-html', encodedHtml);
99794
- this.opts.onChange();
99795
- }
99796
- }
99797
- });
99798
- });
99867
+ this.makeSortable(this.doc, true);
99799
99868
  this.refresh();
99800
99869
  if (this.win.Block) {
99801
99870
  this.win.Block.render();
@@ -99835,24 +99904,7 @@ Please obtain a license at: https://innovastudio.com/contentbox`);
99835
99904
  this.applyBehavior();
99836
99905
 
99837
99906
  // On Load HTML
99838
- const grids = this.doc.querySelectorAll('.grid-sortable');
99839
- grids.forEach(grid => {
99840
- if (grid.closest('.is-builder')) new Sortable(grid, {
99841
- animation: 600,
99842
- dragClass: 'hide-drag-class',
99843
- onStart: () => {
99844
- this.uo.saveForUndo(true);
99845
- },
99846
- onSort: () => {
99847
- if (grid.closest('[data-html]')) {
99848
- const moduleElm = grid.closest('[data-html]');
99849
- const encodedHtml = encodeURIComponent(moduleElm.innerHTML);
99850
- moduleElm.setAttribute('data-html', encodedHtml);
99851
- this.opts.onChange();
99852
- }
99853
- }
99854
- });
99855
- });
99907
+ this.makeSortable(this.doc, true);
99856
99908
 
99857
99909
  // this.uo.saveForUndo(); //First time
99858
99910
 
@@ -102451,6 +102503,86 @@ Please obtain a license at: https://innovastudio.com/contentbox`);
102451
102503
  // this.doc.querySelectorAll('.elm-inspected').forEach(elm => elm.classList.remove('elm-inspected'));
102452
102504
  // this.doc.querySelectorAll('.elm-active').forEach(elm => elm.classList.remove('elm-active'));
102453
102505
  }
102506
+
102507
+ // Make list inside plugin element sortable
102508
+ makeSortable(container, module) {
102509
+ const grids = container.querySelectorAll('.grid-sortable');
102510
+ grids.forEach(grid => {
102511
+ const sortable = new Sortable(grid, {
102512
+ animation: 600,
102513
+ onStart: () => {
102514
+ this.uo.saveForUndo(true);
102515
+ },
102516
+ onSort: async () => {
102517
+ if (module) if (grid.closest('[data-html]')) {
102518
+ const moduleElm = grid.closest('[data-html]');
102519
+ const encodedHtml = encodeURIComponent(moduleElm.innerHTML);
102520
+ moduleElm.setAttribute('data-html', encodedHtml);
102521
+ this.onChange();
102522
+ }
102523
+ let plugin = grid.closest('[data-cb-original-content]');
102524
+ if (plugin) {
102525
+ // grid.setAttribute('data-cb-original-content', plugin.innerHTML); // don't do this!
102526
+ this.updateCleanContentOrder(grid); // use this!
102527
+
102528
+ this.onChange();
102529
+ grid.click();
102530
+ }
102531
+ }
102532
+ });
102533
+ // Store instance for later access
102534
+ grid._sortable = sortable;
102535
+ });
102536
+ }
102537
+ async updateCleanContentOrder(grid) {
102538
+ if (!grid) return;
102539
+ const plugin = grid.closest('[data-cb-original-content]');
102540
+ if (!plugin) return;
102541
+
102542
+ // 1. Get the current visual order of data-index from the actual DOM
102543
+ const newIndexOrder = Array.from(grid.children).map(child => child.dataset.index).filter(index => index !== undefined); // in case some lack data-index
102544
+
102545
+ // 2. Parse the *original clean* HTML
102546
+ const cleanHtml = plugin.dataset.cbOriginalContent;
102547
+ const parser = new DOMParser();
102548
+ const doc = parser.parseFromString(cleanHtml, 'text/html');
102549
+ let cleanGrid = doc.querySelector('.grid-sortable');
102550
+ let pluginIsSortableRoot = false;
102551
+ if (!cleanGrid) {
102552
+ // console.log('[step] .grid-sortable not found inside parsed clean HTML — creating wrapper from body children');
102553
+ cleanGrid = doc.createElement('div');
102554
+ cleanGrid.classList.add('grid-sortable');
102555
+ Array.from(doc.body.children).forEach(child => {
102556
+ if (child.nodeType === 1) cleanGrid.appendChild(child);
102557
+ });
102558
+ doc.body.innerHTML = '';
102559
+ doc.body.appendChild(cleanGrid);
102560
+ pluginIsSortableRoot = true;
102561
+ }
102562
+ const cleanItems = Array.from(cleanGrid.children).filter(el => el.nodeType === 1);
102563
+
102564
+ // 3. Build a map: data-index → clean node
102565
+ const cleanItemMap = new Map();
102566
+ cleanItems.forEach(item => {
102567
+ const idx = item.dataset.index;
102568
+ if (idx !== undefined) cleanItemMap.set(idx, item);
102569
+ });
102570
+
102571
+ // 4. Reorder clean items to match newIndexOrder
102572
+ const reorderedCleanItems = newIndexOrder.map(idx => cleanItemMap.get(idx)).filter(Boolean); // skip missing
102573
+
102574
+ // 5. Serialize back to HTML string
102575
+ const newCleanHtml = reorderedCleanItems.map(item => item.outerHTML).join('');
102576
+
102577
+ // 6. Update the clean source
102578
+ if (pluginIsSortableRoot) {
102579
+ plugin.setAttribute('data-cb-original-content', newCleanHtml);
102580
+ } else {
102581
+ cleanGrid.innerHTML = newCleanHtml;
102582
+ const newHTML = doc.body.innerHTML;
102583
+ plugin.setAttribute('data-cb-original-content', newHTML);
102584
+ }
102585
+ }
102454
102586
  }
102455
102587
 
102456
102588
  export { ContentBuilder as default };