@innovastudio/contentbox 1.5.73 → 1.5.74

Sign up to get free protection for your applications and to get access to all the features.
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@innovastudio/contentbox",
3
3
  "type": "module",
4
- "version": "1.5.73",
4
+ "version": "1.5.74",
5
5
  "description": "",
6
6
  "main": "public/contentbox/contentbox.esm.js",
7
7
  "files": [
@@ -109518,6 +109518,11 @@ class Lib {
109518
109518
  type: 'boolean',
109519
109519
  description: 'User request an information to be added to the current content.'
109520
109520
  },
109521
+ // Add new Column or Block (in General Mode)
109522
+ add_column_or_block: {
109523
+ type: 'boolean',
109524
+ description: 'User requests to add a column or a block.'
109525
+ },
109521
109526
 
109522
109527
  /*
109523
109528
  To make 2 columns not mixed with 2 boxes, each has to be identified separately
@@ -109644,6 +109649,23 @@ class Lib {
109644
109649
  type: 'string',
109645
109650
  description: 'User requests to align the whole text/content. Possible value: left, center or right'
109646
109651
  },
109652
+ // Block Mode (in General Mode)
109653
+ block_task: {
109654
+ type: 'string',
109655
+ description: 'User requests to move, duplicate, or delete block/row. Possible values: move-up, move-down, duplicate, remove'
109656
+ },
109657
+ column_task: {
109658
+ type: 'string',
109659
+ description: 'User requests to duplicate column, or delete column. Possible values: duplicate, remove'
109660
+ },
109661
+ move_column: {
109662
+ type: 'string',
109663
+ description: 'User requests to move column. Possible values: move-up, move-down, move-left, move-right'
109664
+ },
109665
+ increase_decrease_column: {
109666
+ type: 'string',
109667
+ description: 'User requests to increase/enlarge or decrease/reduce column size/width. Possible values: increase, decrease'
109668
+ },
109647
109669
  move_content_left: {
109648
109670
  type: 'boolean',
109649
109671
  description: 'Move content to the left'
@@ -110939,6 +110961,19 @@ Example: To create a block with a headline and a paragraph:
110939
110961
  </div>
110940
110962
 
110941
110963
  `;
110964
+ } else if (numberOfIntents === 1 && (args.new_column_onright || args.new_column_onleft)) {
110965
+ // single intent => no content details
110966
+ systemCmd = 'You will be asked to create a single HTML block/column and return the HTML without any additional explanation.';
110967
+ context = `To create a column, create single 'div.column' element and add a paragraph inside it.
110968
+
110969
+ Example:
110970
+
110971
+ <div class="column">
110972
+ <p>Paragraph here.</p>
110973
+ </div>
110974
+
110975
+ `;
110976
+ question = `${question}. No talk; just do. You must return only one 'div.column'.`;
110942
110977
  } else if (args.new_column_onright || args.new_column_onleft) {
110943
110978
  systemCmd = 'You will be asked to create content (in HTML) and return the HTML without any additional explanation.';
110944
110979
  context = `To add a column that contains a content:
@@ -111206,6 +111241,78 @@ ${answer}
111206
111241
  this.sendCommand('assistant', question, context, systemCmd, [], callback);
111207
111242
  };
111208
111243
 
111244
+ const numOfIntents = args => {
111245
+ let trueCount = 0;
111246
+
111247
+ for (const key in args) {
111248
+ if (args[key] === true) {
111249
+ trueCount++;
111250
+ }
111251
+ }
111252
+
111253
+ return trueCount;
111254
+ }; // Update Column or Block (in General Mode)
111255
+
111256
+
111257
+ const sendUpdateBlockCommand = async (question, args) => {
111258
+ let block = this.builder.editor.activeCol;
111259
+
111260
+ if (!block) {
111261
+ this.builder.showMessage(out('Please select a block or content.'));
111262
+ this.dictation.finish(); // Must be called after finished
111263
+
111264
+ return;
111265
+ }
111266
+
111267
+ let blockContent = block.innerHTML;
111268
+ const systemCmd = 'You will be asked to modify content (in HTML) and return only the modified HTML without any additional explanation.'; // Update prompt
111269
+
111270
+ question = `${question}. Modify my content according to this instruction and returns the modified content HTML.
111271
+
111272
+ This is my content:
111273
+
111274
+ ${blockContent}
111275
+ `; // let context = this.lib.elementContext(context, args);
111276
+
111277
+ let context = this.lib.addElementContext('', args);
111278
+
111279
+ if (this.builder.consoleLog) {
111280
+ console.log(systemCmd);
111281
+ console.log(question);
111282
+ console.log(context);
111283
+ }
111284
+
111285
+ const callback = answer => {
111286
+ if (this.builder.consoleLog) console.log(answer);
111287
+ html = this.fixHtmlBlock(answer);
111288
+
111289
+ if (!html) {
111290
+ this.dictation.finish(true);
111291
+ return false;
111292
+ }
111293
+
111294
+ this.builder.editor.saveForUndo();
111295
+ block.innerHTML = html;
111296
+ let elmActive = block.querySelector('.elm-active');
111297
+
111298
+ if (elmActive) {
111299
+ this.builder.editor.activeElement = elmActive;
111300
+ elmActive.focus();
111301
+ } // See addContent() in ContentBuilder's util.js
111302
+
111303
+
111304
+ let builderActive = this.builder.doc.querySelector('.builder-active');
111305
+ if (builderActive) this.builder.editor.applyBehaviorOn(builderActive); //Trigger Change event
111306
+
111307
+ this.builder.settings.onChange(); //Trigger Render event
111308
+
111309
+ this.builder.settings.onRender();
111310
+ this.dictation.finish();
111311
+ };
111312
+
111313
+ this.sendCommand('assistant', question, context, systemCmd, [], callback);
111314
+ };
111315
+
111209
111316
  const sendGeneralCommand = async question => {
111210
111317
  // Get Selected
111211
111318
  let activeBox = this.builder.activeBox;
@@ -111242,12 +111349,37 @@ ${answer}
111242
111349
  if (this.builder.consoleLog) console.log('write_based_on_the_current_content');
111243
111350
  sendRewriteCommand(question);
111244
111351
  return;
111245
- } // SIMPLE/SINGLE INTENT (like Short Commands)
111352
+ } // const numberOfIntents = Object.keys(args).length;
111246
111353
 
111247
111354
 
111248
- const numberOfIntents = Object.keys(args).length;
111355
+ const numberOfIntents = numOfIntents(args); // SIMPLE (1 or 2) INTENTS
111356
+
111357
+ const activeCol = this.builder.editor.activeCol;
111358
+
111359
+ if (activeCol) {
111360
+ // && numberOfIntents<=2) {
111361
+ // Update Column or Block (in General Mode)
111362
+ if (args.align_individual_text || args.font_size_individual_text || args.line_height_individual_text) {
111363
+ sendUpdateBlockCommand(question, args);
111364
+ return;
111365
+ } // Add new Column or Block (in General Mode)
111366
+
111367
+
111368
+ if (args.add_column_or_block) {
111369
+ sendBlockCommand(question);
111370
+ return;
111371
+ }
111372
+ } // SIMPLE/SINGLE INTENT (like Short Commands)
111373
+
111249
111374
 
111250
111375
  if (activeBox && numberOfIntents === 1) {
111376
+ // Block Mode (in General Mode)
111377
+ let result = this.blockAction(args);
111378
+
111379
+ if (result) {
111380
+ this.dictation.finish();
111381
+ return;
111382
+ }
111251
111383
  /*
111252
111384
  // If single intent creates new section:
111253
111385
  if(activeBox && (args.move_content_left || args.move_content_center || args.move_content_right ||
@@ -111268,6 +111400,8 @@ ${answer}
111268
111400
  return;
111269
111401
  }
111270
111402
  */
111403
+
111404
+
111271
111405
  const moveContent = this.lib.processContent(args, activeBox);
111272
111406
 
111273
111407
  if (moveContent) {
@@ -111480,7 +111614,7 @@ ${answer}
111480
111614
  }
111481
111615
  }
111482
111616
 
111483
- const result = this.quickAction(args);
111617
+ result = this.quickAction(args);
111484
111618
 
111485
111619
  if (result) {
111486
111620
  this.dictation.finish();
@@ -113848,6 +113982,16 @@ ${currentHtml}
113848
113982
  imgs.forEach(img => {
113849
113983
  img.setAttribute('src', imageUrl);
113850
113984
  });
113985
+ const cols = doc.querySelectorAll('.column');
113986
+ cols.forEach(col => {
113987
+ // Add spacer in an empty column
113988
+ if (col.innerHTML.trim() === '') {
113989
+ const spacer = document.createElement('div');
113990
+ spacer.classList.add('spacer');
113991
+ spacer.classList.add('height-40');
113992
+ col.appendChild(spacer);
113993
+ }
113994
+ });
113851
113995
  return doc.documentElement.innerHTML;
113852
113996
  }
113853
113997
 
@@ -119337,17 +119481,19 @@ Add an image for each feature.`, 'Revise the headline, paragraph, and all the te
119337
119481
  let contentClass = contentCss.replace('.css', '');
119338
119482
  let contentStylePath = this.settings.contentStylePath; //Add contentCss
119339
119483
 
119340
- let exist = false;
119484
+ if (contentCss) {
119485
+ let exist = false;
119341
119486
 
119342
- let links = window.parent._cb.doc.getElementsByTagName('link');
119487
+ let links = window.parent._cb.doc.getElementsByTagName('link');
119343
119488
 
119344
- for (let i = 0; i < links.length; i++) {
119345
- let src = links[i].href.toLowerCase();
119346
- if (src.indexOf(contentCss.toLowerCase()) != -1) exist = true;
119347
- }
119489
+ for (let i = 0; i < links.length; i++) {
119490
+ let src = links[i].href.toLowerCase();
119491
+ if (src.indexOf(contentCss.toLowerCase()) != -1) exist = true;
119492
+ }
119348
119493
 
119349
- if (!exist) {
119350
- this.wrapperEl.insertAdjacentHTML('beforeend', '<link data-name="contentstyle" data-class="' + contentClass + '" href="' + contentStylePath + contentCss + '" rel="stylesheet">');
119494
+ if (!exist) {
119495
+ this.wrapperEl.insertAdjacentHTML('beforeend', '<link data-name="contentstyle" data-class="' + contentClass + '" href="' + contentStylePath + contentCss + '" rel="stylesheet">');
119496
+ }
119351
119497
  }
119352
119498
 
119353
119499
  return newSection;