@innovastudio/contentbox 1.5.72 → 1.5.74

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/contentbox",
3
3
  "type": "module",
4
- "version": "1.5.72",
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;
@@ -111224,9 +111331,9 @@ ${answer}
111224
111331
  if (activeSection) {
111225
111332
  if (activeSection.classList.contains('is-box')) sectionBox = true; // A single box section
111226
111333
  }
111227
- }
111334
+ } // if(this.builder.sendCommandUrl==='') return;
111335
+
111228
111336
 
111229
- if (this.builder.sendCommandUrl === '') return;
111230
111337
  this.sendCommand('analyze', `This is the command: "${question}"`, '', 'You will analyze the user\'s command and return what the user needs.', this.lib.getFunctions(), response => {
111231
111338
  const args = JSON.parse(response);
111232
111339
  if (this.builder.consoleLog) console.log(args);
@@ -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
 
@@ -114057,16 +114201,33 @@ ${currentHtml}
114057
114201
  };
114058
114202
 
114059
114203
  try {
114204
+ /*
114060
114205
  const response = await fetch(this.builder.sendCommandUrl, {
114061
- signal: this.signal,
114062
- // Abort
114063
- method: 'POST',
114064
- headers: {
114065
- 'Content-Type': 'application/json'
114066
- },
114067
- body: JSON.stringify(messages)
114206
+ signal: this.signal, // Abort
114207
+ method: 'POST',
114208
+ headers: {
114209
+ 'Content-Type': 'application/json',
114210
+ },
114211
+ body: JSON.stringify(messages),
114068
114212
  });
114069
- const data = await response.json();
114213
+ const data = await response.json();
114214
+ */
114215
+ let data;
114216
+
114217
+ if (this.builder.sendCommand) {
114218
+ data = await this.builder.sendCommand(messages);
114219
+ } else {
114220
+ const response = await fetch(this.builder.sendCommandUrl, {
114221
+ signal: this.signal,
114222
+ // Abort
114223
+ method: 'POST',
114224
+ headers: {
114225
+ 'Content-Type': 'application/json'
114226
+ },
114227
+ body: JSON.stringify(messages)
114228
+ });
114229
+ data = await response.json();
114230
+ }
114070
114231
 
114071
114232
  if (data.error) {
114072
114233
  // Error response from OpenAI goes here.
@@ -117265,6 +117426,7 @@ class ContentBox {
117265
117426
  speechTranscribeUrl: '',
117266
117427
  // http://localhost:8081
117267
117428
  autoSendDelay: 4000,
117429
+ // sendCommand: async (message)=>{ },
117268
117430
  onlineDemo: false,
117269
117431
  startAIAssistant: false,
117270
117432
  temperature: 0.6,
@@ -119110,7 +119272,7 @@ Add an image for each feature.`, 'Revise the headline, paragraph, and all the te
119110
119272
  let info = box.querySelector('.is-box-info');
119111
119273
  if (info) info.parentNode.removeChild(info);
119112
119274
 
119113
- if (this.sendCommandUrl && this.AIToolbar) {
119275
+ if ((this.sendCommandUrl || this.sendCommand) && this.AIToolbar) {
119114
119276
  dom.appendHtml(box, `<div class="is-box-info is-tool" style="transform-origin: right top;">
119115
119277
  <button data-title="${out('AI Rewrite')}" title="${out('AI Rewrite')}" class="input-box-rewrite" style="padding-left:3px">
119116
119278
  <svg class="is-icon-flex" style="width:15px;height:15px;flex:none;fill:#000;"><use xlink:href="#icon-pencil"></use></svg>
@@ -119319,17 +119481,19 @@ Add an image for each feature.`, 'Revise the headline, paragraph, and all the te
119319
119481
  let contentClass = contentCss.replace('.css', '');
119320
119482
  let contentStylePath = this.settings.contentStylePath; //Add contentCss
119321
119483
 
119322
- let exist = false;
119484
+ if (contentCss) {
119485
+ let exist = false;
119323
119486
 
119324
- let links = window.parent._cb.doc.getElementsByTagName('link');
119487
+ let links = window.parent._cb.doc.getElementsByTagName('link');
119325
119488
 
119326
- for (let i = 0; i < links.length; i++) {
119327
- let src = links[i].href.toLowerCase();
119328
- if (src.indexOf(contentCss.toLowerCase()) != -1) exist = true;
119329
- }
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
+ }
119330
119493
 
119331
- if (!exist) {
119332
- 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
+ }
119333
119497
  }
119334
119498
 
119335
119499
  return newSection;