formstrap 0.4.9 → 0.4.10

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.
@@ -31,12 +31,12 @@ Redactor.add('plugin', 'linkstyles', {
31
31
  }
32
32
  },
33
33
  'link.change': function (e) {
34
- let link = e.params.element.nodes[0]
34
+ let link = e.data.element.nodes[0]
35
35
  link = this.ensureValidProtocol(link)
36
36
  this.applyStylingToLink(link)
37
37
  },
38
38
  'link.add': function (e) {
39
- let link = e.params.element.nodes[0]
39
+ let link = e.data.element.nodes[0]
40
40
  link = this.ensureValidProtocol(link)
41
41
  this.applyStylingToLink(link)
42
42
  }
@@ -14603,12 +14603,12 @@ Redactor.add("plugin", "linkstyles", {
14603
14603
  }
14604
14604
  },
14605
14605
  "link.change": function(e) {
14606
- let link = e.params.element.nodes[0];
14606
+ let link = e.data.element.nodes[0];
14607
14607
  link = this.ensureValidProtocol(link);
14608
14608
  this.applyStylingToLink(link);
14609
14609
  },
14610
14610
  "link.add": function(e) {
14611
- let link = e.params.element.nodes[0];
14611
+ let link = e.data.element.nodes[0];
14612
14612
  link = this.ensureValidProtocol(link);
14613
14613
  this.applyStylingToLink(link);
14614
14614
  }
@@ -14683,14 +14683,14 @@ Redactor.add("plugin", "linkstyles", {
14683
14683
  Redactor.add("plugin", "ai", {
14684
14684
  translations: {
14685
14685
  en: {
14686
- "ai": {
14686
+ ai: {
14687
14687
  "placeholder-image": "Describe the image you want to generate.",
14688
14688
  "placeholder-text": "Tell me what you want to write.",
14689
- "send": "Send",
14690
- "stop": "Stop",
14691
- "discard": "Discard",
14692
- "insert": "Insert",
14693
- "prompt": "Prompt",
14689
+ send: "Send",
14690
+ stop: "Stop",
14691
+ discard: "Discard",
14692
+ insert: "Insert",
14693
+ prompt: "Prompt",
14694
14694
  "image-style": "Image style",
14695
14695
  "change-tone": "Change tone"
14696
14696
  }
@@ -14771,7 +14771,7 @@ Redactor.add("plugin", "ai", {
14771
14771
  return obj;
14772
14772
  },
14773
14773
  popup(e, button) {
14774
- let uiState = this.app.ui.getState();
14774
+ const uiState = this.app.ui.getState();
14775
14775
  if (uiState.type !== "addbar") {
14776
14776
  this.app.dropdown.create("ai-tools", { items: this.opts.get("ai.items") || this.dropdowns.items });
14777
14777
  this.app.dropdown.open(e, button);
@@ -14783,8 +14783,8 @@ Redactor.add("plugin", "ai", {
14783
14783
  this._buildPrompt({ image: true });
14784
14784
  },
14785
14785
  popupTone(e, button) {
14786
- let buttons = {};
14787
- let items = this.opts.get("ai.tone") || this.defaults.tone;
14786
+ const buttons = {};
14787
+ const items = this.opts.get("ai.tone") || this.defaults.tone;
14788
14788
  const makeit = this.opts.get("ai.makeit") || this.defaults.makeit;
14789
14789
  for (let i = 0; i < items.length; i++) {
14790
14790
  buttons[i] = { title: items[i], command: "ai.set", params: { prompt: makeit + " " + items[i] } };
@@ -14793,8 +14793,8 @@ Redactor.add("plugin", "ai", {
14793
14793
  this.app.dropdown.open(e, button);
14794
14794
  },
14795
14795
  popupTranslate(e, button) {
14796
- let buttons = {};
14797
- let items = this.opts.get("ai.translate") || this.defaults.translate;
14796
+ const buttons = {};
14797
+ const items = this.opts.get("ai.translate") || this.defaults.translate;
14798
14798
  const translateto = this.opts.get("ai.translateto") || this.defaults.translateto;
14799
14799
  for (let i = 0; i < items.length; i++) {
14800
14800
  buttons[i] = { title: items[i], command: "ai.set", params: { prompt: translateto + " " + items[i] } };
@@ -14815,7 +14815,7 @@ Redactor.add("plugin", "ai", {
14815
14815
  this.promptButton.setIcon(this.defaults.spinner);
14816
14816
  }
14817
14817
  let message = params.prompt;
14818
- let event = this.app.broadcast("ai.create", { prompt: message });
14818
+ const event = this.app.broadcast("ai.create", { prompt: message });
14819
14819
  message = event.get("prompt");
14820
14820
  this.modifiedValue = message;
14821
14821
  this._setPrompt(text, html, message, params.empty);
@@ -14823,18 +14823,18 @@ Redactor.add("plugin", "ai", {
14823
14823
  sendPrompt(e) {
14824
14824
  e.preventDefault();
14825
14825
  e.stopPropagation();
14826
- let apimodel = this.opts.get("ai." + this.promptType + ".model");
14826
+ const apimodel = this.opts.get("ai." + this.promptType + ".model");
14827
14827
  let message = this._getMessage();
14828
- let event = this.app.broadcast("ai.create", { prompt: message });
14828
+ const event = this.app.broadcast("ai.create", { prompt: message });
14829
14829
  message = event.get("prompt");
14830
14830
  this.modifiedValue = message;
14831
14831
  if (message === "")
14832
14832
  return;
14833
- let tone = this._getTone(message);
14833
+ const tone = this._getTone(message);
14834
14834
  if (this.promptType === "text") {
14835
- this.conversation.push({ "role": "user", "content": message });
14835
+ this.conversation.push({ role: "user", content: message });
14836
14836
  if (tone) {
14837
- this.conversation.push({ "role": "user", "content": tone });
14837
+ this.conversation.push({ role: "user", content: tone });
14838
14838
  }
14839
14839
  }
14840
14840
  let request = {
@@ -14857,20 +14857,20 @@ Redactor.add("plugin", "ai", {
14857
14857
  insertPrompt(e) {
14858
14858
  e.preventDefault();
14859
14859
  e.stopPropagation();
14860
- let insertion = this.app.create("insertion");
14860
+ const insertion = this.app.create("insertion");
14861
14861
  let html = this.$preview.html();
14862
14862
  if (this.promptType === "image") {
14863
14863
  const tag = this.opts.get("image.tag");
14864
14864
  html = `<${tag}>${html}</${tag}>`;
14865
14865
  }
14866
- let event = this.app.broadcast("ai.before.insert", { html });
14866
+ const event = this.app.broadcast("ai.before.insert", { html });
14867
14867
  html = event.get("html");
14868
- let $target = this.savedInstance ? this.savedInstance.getBlock() : this.$prompt;
14869
- let position = this.savedInstance ? "after" : "before";
14870
- let remove = this.savedInstance ? false : true;
14868
+ const $target = this.savedInstance ? this.savedInstance.getBlock() : this.$prompt;
14869
+ const position = this.savedInstance ? "after" : "before";
14870
+ const remove = !this.savedInstance;
14871
14871
  setTimeout(function() {
14872
14872
  this.app.block.setTool(false);
14873
- let inserted = insertion.insert({ html, target: $target, position, remove });
14873
+ const inserted = insertion.insert({ html, target: $target, position, remove });
14874
14874
  this.$prompt.remove();
14875
14875
  this.conversation = [];
14876
14876
  this.app.broadcast("ai.insert", { nodes: inserted });
@@ -14890,9 +14890,9 @@ Redactor.add("plugin", "ai", {
14890
14890
  this.$insert.show();
14891
14891
  this.$stop.hide();
14892
14892
  this.$generate.show();
14893
- let eventName = e ? "ai.stop" : "ai.complete";
14894
- let prompt = this.$previewLabel.text();
14895
- let result = e ? { prompt } : { prompt, response: this._parseReply(reply) };
14893
+ const eventName = e ? "ai.stop" : "ai.complete";
14894
+ const prompt = this.$previewLabel.text();
14895
+ const result = e ? { prompt } : { prompt, response: this._parseReply(reply) };
14896
14896
  this.app.broadcast(eventName, result);
14897
14897
  },
14898
14898
  closePrompt(e) {
@@ -14907,7 +14907,7 @@ Redactor.add("plugin", "ai", {
14907
14907
  this.app.broadcast("ai.discard");
14908
14908
  },
14909
14909
  _getTone(message) {
14910
- let tone = this.$select.val();
14910
+ const tone = this.$select.val();
14911
14911
  if (tone === "0" || tone === "1") {
14912
14912
  return false;
14913
14913
  }
@@ -14916,7 +14916,7 @@ Redactor.add("plugin", "ai", {
14916
14916
  _getHtml() {
14917
14917
  let html = "";
14918
14918
  let instances = this.app.blocks.get({ selected: true, instances: true });
14919
- let instance = this.app.block.get();
14919
+ const instance = this.app.block.get();
14920
14920
  if (instances.length === 0 && instance) {
14921
14921
  instances = [instance];
14922
14922
  }
@@ -14928,13 +14928,14 @@ Redactor.add("plugin", "ai", {
14928
14928
  _getText() {
14929
14929
  let text = "";
14930
14930
  let instances = this.app.blocks.get({ selected: true, instances: true });
14931
- let instance = this.app.block.get();
14931
+ const instance = this.app.block.get();
14932
14932
  if (instances.length === 0 && instance) {
14933
14933
  instances = [instance];
14934
14934
  }
14935
14935
  for (let i = 0; i < instances.length; i++) {
14936
14936
  if (instances[i].isEditable()) {
14937
- let type = instances[i].getType(), prefix = type === "listitem" ? "- " : "";
14937
+ const type = instances[i].getType();
14938
+ const prefix = type === "listitem" ? "- " : "";
14938
14939
  text = text + prefix + instances[i].getPlainText() + "\n";
14939
14940
  }
14940
14941
  }
@@ -14946,7 +14947,7 @@ Redactor.add("plugin", "ai", {
14946
14947
  return this.$textarea.val().trim();
14947
14948
  },
14948
14949
  _getNode() {
14949
- let node = this.app.block.create();
14950
+ const node = this.app.block.create();
14950
14951
  let $node = node.getBlock();
14951
14952
  $node = this._buildNode($node, { traverse: true });
14952
14953
  return $node;
@@ -14963,13 +14964,13 @@ Redactor.add("plugin", "ai", {
14963
14964
  this.promptType = "text";
14964
14965
  this.promptText = text;
14965
14966
  this.promptHtml = html;
14966
- let messages = [{ "role": "user", "content": text }, { "role": "user", "content": prompt }];
14967
- let request = {
14967
+ const messages = [{ role: "user", content: text }, { role: "user", content: prompt }];
14968
+ const request = {
14968
14969
  model: this.opts.get("ai." + this.promptType + ".model"),
14969
14970
  messages
14970
14971
  };
14971
14972
  if (this.opts.is("ai.text.stream")) {
14972
- let $node = this._getInsertedNode();
14973
+ const $node = this._getInsertedNode();
14973
14974
  $node.html(this.defaults.spinner);
14974
14975
  this.app.dropdown.close();
14975
14976
  this.app.context.close();
@@ -14989,7 +14990,7 @@ Redactor.add("plugin", "ai", {
14989
14990
  url: this.opts.get("ai." + this.promptType + ".url"),
14990
14991
  data,
14991
14992
  before: function(xhr) {
14992
- let event = this.app.broadcast("ai.before.send", { xhr, data });
14993
+ const event = this.app.broadcast("ai.before.send", { xhr, data });
14993
14994
  if (event.isStopped()) {
14994
14995
  return false;
14995
14996
  }
@@ -15002,7 +15003,7 @@ Redactor.add("plugin", "ai", {
15002
15003
  const apimodel = this.opts.get("ai." + this.promptType + ".model");
15003
15004
  const apiurl = this.opts.get("ai." + this.promptType + ".endpoint");
15004
15005
  const serverurl = this.opts.get("ai." + this.promptType + ".url");
15005
- let request = {
15006
+ const request = {
15006
15007
  model: apimodel,
15007
15008
  stream: this.opts.get("ai.text.stream"),
15008
15009
  messages: preview ? this.conversation : message
@@ -15014,15 +15015,17 @@ Redactor.add("plugin", "ai", {
15014
15015
  const utils = this.app.create("utils");
15015
15016
  data = utils.extendData(data, this.opts.get("ai." + this.promptType + ".data"));
15016
15017
  let responseContent = "";
15017
- let source = this._createSource(serverurl, data);
15018
+ const source = this._createSource(serverurl, data);
15018
15019
  this.isEvent = source;
15019
15020
  this.currentIndex = 0;
15020
- let $target = this.app.scroll.getTarget();
15021
+ const $target = this.app.scroll.getTarget();
15021
15022
  $node.removeClass("rx-inserted-node-started");
15022
15023
  source.addEventListener("message", function(event) {
15023
15024
  this.app.dropdown.close();
15024
15025
  this.app.context.close();
15025
- let message2 = event.data, start2 = message2.indexOf(": ", "data") + 2, data2 = message2.slice(start2, message2.length);
15026
+ const message2 = event.data;
15027
+ const start2 = message2.indexOf(": ", "data") + 2;
15028
+ let data2 = message2.slice(start2, message2.length);
15026
15029
  if (data2 === "[DONE]") {
15027
15030
  this._sendStreamDone(source, $node, responseContent, preview);
15028
15031
  } else {
@@ -15033,7 +15036,7 @@ Redactor.add("plugin", "ai", {
15033
15036
  }
15034
15037
  const choices = data2.choices;
15035
15038
  if (choices && choices.length > 0) {
15036
- let content = choices[0].delta.content;
15039
+ const content = choices[0].delta.content;
15037
15040
  if (content) {
15038
15041
  if (!$node.hasClass("rx-inserted-node-started")) {
15039
15042
  $node.html("");
@@ -15060,11 +15063,11 @@ Redactor.add("plugin", "ai", {
15060
15063
  if (!preview) {
15061
15064
  this._insertAfterNode($node, responseContent);
15062
15065
  } else {
15063
- let checkInterval = setInterval(function() {
15066
+ const checkInterval = setInterval(function() {
15064
15067
  if (this.currentIndex === responseContent.length) {
15065
15068
  clearInterval(checkInterval);
15066
15069
  this.stopPrompt(false, responseContent);
15067
- this.conversation.push({ "role": "assistant", "content": responseContent });
15070
+ this.conversation.push({ role: "assistant", content: responseContent });
15068
15071
  }
15069
15072
  }.bind(this), 100);
15070
15073
  }
@@ -15074,7 +15077,7 @@ Redactor.add("plugin", "ai", {
15074
15077
  _sendStreamPreviewSet(preview) {
15075
15078
  if (!preview)
15076
15079
  return;
15077
- let value = this.modifiedValue || this.$textarea.val();
15080
+ const value = this.modifiedValue || this.$textarea.val();
15078
15081
  this.$progress.html("");
15079
15082
  this.$previewLabel.html(this._sanitize(value));
15080
15083
  this.$textarea.val("");
@@ -15092,7 +15095,7 @@ Redactor.add("plugin", "ai", {
15092
15095
  $last = $last.closest("[data-rx-first-level]");
15093
15096
  $last.before($node);
15094
15097
  }
15095
- let isAll = this.app.editor.isSelectAll();
15098
+ const isAll = this.app.editor.isSelectAll();
15096
15099
  $last = this.app.blocks.removeAll();
15097
15100
  if (isAll) {
15098
15101
  $node = $last;
@@ -15101,7 +15104,7 @@ Redactor.add("plugin", "ai", {
15101
15104
  this.instance = this.app.block.get();
15102
15105
  if (!this.instance) {
15103
15106
  this.instance = this.app.block.create();
15104
- let $first = this.app.blocks.get({ first: true });
15107
+ const $first = this.app.blocks.get({ first: true });
15105
15108
  $first.before(this.instance.getBlock());
15106
15109
  }
15107
15110
  if (this.instance.isType("listitem")) {
@@ -15123,7 +15126,7 @@ Redactor.add("plugin", "ai", {
15123
15126
  this.app.block.setTool("ai");
15124
15127
  }.bind(this));
15125
15128
  let instance = this.app.block.get();
15126
- let isMultiple = this.app.blocks.is();
15129
+ const isMultiple = this.app.blocks.is();
15127
15130
  this.app.dropdown.close();
15128
15131
  this.app.context.close();
15129
15132
  if (instance || isMultiple) {
@@ -15131,8 +15134,8 @@ Redactor.add("plugin", "ai", {
15131
15134
  instance = this.app.blocks.get({ last: true, selected: true, instances: true });
15132
15135
  }
15133
15136
  const types = ["layout", "table", "quote", "list", "todo", "image", "embed"];
15134
- let $parent = instance.getBlock().closest("[data-rx-type=" + types.join("],[data-rx-type=") + "]");
15135
- let $column = instance.getBlock().closest("[data-rx-type=column]");
15137
+ const $parent = instance.getBlock().closest("[data-rx-type=" + types.join("],[data-rx-type=") + "]");
15138
+ const $column = instance.getBlock().closest("[data-rx-type=column]");
15136
15139
  if ($parent.length !== 0) {
15137
15140
  if ($column.length !== 0) {
15138
15141
  this.savedInstance = instance;
@@ -15149,11 +15152,11 @@ Redactor.add("plugin", "ai", {
15149
15152
  this.app.editor.adjustHeight();
15150
15153
  },
15151
15154
  _error(error2, response) {
15152
- let $node = this.app.editor.getEditor().find(".rx-inserted-node");
15155
+ const $node = this.app.editor.getEditor().find(".rx-inserted-node");
15153
15156
  if ($node.length !== 0) {
15154
15157
  this.app.dropdown.close();
15155
15158
  this.app.context.close();
15156
- let insertion = this.app.create("insertion");
15159
+ const insertion = this.app.create("insertion");
15157
15160
  insertion.insert({ target: $node, remove: true, caret: "end", html: this.promptHtml });
15158
15161
  }
15159
15162
  if (this.$progress) {
@@ -15161,7 +15164,7 @@ Redactor.add("plugin", "ai", {
15161
15164
  this.$progress.html("").removeAttr("style");
15162
15165
  }.bind(this));
15163
15166
  }
15164
- this.app.broadcast("ai.error", error2 ? error2 : response);
15167
+ this.app.broadcast("ai.error", error2 || response);
15165
15168
  },
15166
15169
  _insert(response) {
15167
15170
  this.promptButton.setIcon("");
@@ -15169,20 +15172,20 @@ Redactor.add("plugin", "ai", {
15169
15172
  return this._error(response.error.message, response);
15170
15173
  if (!response.choices)
15171
15174
  return this._error(response);
15172
- let reply = response.choices[0].message.content;
15175
+ const reply = response.choices[0].message.content;
15173
15176
  let html = this._parseReply(reply);
15174
- let insertion = this.app.create("insertion");
15175
- let event = this.app.broadcast("ai.before.insert", { html });
15177
+ const insertion = this.app.create("insertion");
15178
+ const event = this.app.broadcast("ai.before.insert", { html });
15176
15179
  html = event.get("html");
15177
15180
  this.app.dropdown.close();
15178
15181
  this.app.context.close();
15179
15182
  let inserted;
15180
- let instanceType = this.instance && this.instance.isType(["listitem", "todoitem"]);
15183
+ const instanceType = this.instance && this.instance.isType(["listitem", "todoitem"]);
15181
15184
  if (instanceType) {
15182
15185
  this.instance.setContent(reply);
15183
15186
  inserted = this.instance.getBlock();
15184
15187
  } else {
15185
- let $node = this._getNode();
15188
+ const $node = this._getNode();
15186
15189
  this.app.block.set($node);
15187
15190
  inserted = insertion.insert({ html, caret: "end" });
15188
15191
  }
@@ -15192,7 +15195,7 @@ Redactor.add("plugin", "ai", {
15192
15195
  let reply;
15193
15196
  let html;
15194
15197
  let imageUrl;
15195
- let value = this.modifiedValue || this.$textarea.val();
15198
+ const value = this.modifiedValue || this.$textarea.val();
15196
15199
  let result;
15197
15200
  this.$progress.html("");
15198
15201
  this.$previewLabel.html("");
@@ -15214,7 +15217,7 @@ Redactor.add("plugin", "ai", {
15214
15217
  result = html;
15215
15218
  this.$preview.html(html);
15216
15219
  this.$insert.show();
15217
- let prompt = this.$previewLabel.text();
15220
+ const prompt = this.$previewLabel.text();
15218
15221
  this.app.broadcast("ai.complete", { prompt, response: result });
15219
15222
  this.app.editor.adjustHeight();
15220
15223
  } else if (this.promptType === "image") {
@@ -15232,7 +15235,7 @@ Redactor.add("plugin", "ai", {
15232
15235
  url: saveUrl,
15233
15236
  data,
15234
15237
  before: function(xhr) {
15235
- let event = this.app.broadcast("ai.before.save", { xhr, data });
15238
+ const event = this.app.broadcast("ai.before.save", { xhr, data });
15236
15239
  if (event.isStopped()) {
15237
15240
  return false;
15238
15241
  }
@@ -15249,17 +15252,17 @@ Redactor.add("plugin", "ai", {
15249
15252
  }
15250
15253
  },
15251
15254
  _completeImage(imageUrl) {
15252
- let $image = this.dom("<img>").attr("src", imageUrl);
15253
- let result = $image.get().outerHTML;
15255
+ const $image = this.dom("<img>").attr("src", imageUrl);
15256
+ const result = $image.get().outerHTML;
15254
15257
  this.$preview.html($image);
15255
15258
  this.$insert.show();
15256
- let prompt = this.$previewLabel.text();
15259
+ const prompt = this.$previewLabel.text();
15257
15260
  this.app.broadcast("ai.complete", { prompt, response: result });
15258
15261
  this.app.editor.adjustHeight();
15259
15262
  },
15260
15263
  _parseReply(reply) {
15261
- let utils = this.app.create("utils");
15262
- let cleaner = this.app.create("cleaner");
15264
+ const utils = this.app.create("utils");
15265
+ const cleaner = this.app.create("cleaner");
15263
15266
  let text = utils.parseMarkdown(reply);
15264
15267
  text = cleaner.store(text, "lists");
15265
15268
  text = cleaner.store(text, "headings");
@@ -15278,19 +15281,19 @@ Redactor.add("plugin", "ai", {
15278
15281
  _createPrompt(params) {
15279
15282
  params = Redactor.extend(true, {}, { image: false }, params);
15280
15283
  this.promptType = params.image ? "image" : "text";
15281
- let placeholder = this.lang.get("ai.placeholder-" + this.promptType);
15282
- let $editor = this.app.editor.getEditor();
15284
+ const placeholder = this.lang.get("ai.placeholder-" + this.promptType);
15285
+ const $editor = this.app.editor.getEditor();
15283
15286
  $editor.find(".rx-ai-main").remove();
15284
- let $main = this.dom('<div class="rx-in-tool rx-ai-main">').attr({ "contenteditable": false });
15285
- let $body = this.dom('<div class="rx-ai-body">');
15286
- let $footer = this.dom('<div class="rx-ai-footer">');
15287
- let $buttons = this.dom('<div class="rx-ai-buttons">');
15287
+ const $main = this.dom('<div class="rx-in-tool rx-ai-main">').attr({ contenteditable: false });
15288
+ const $body = this.dom('<div class="rx-ai-body">');
15289
+ const $footer = this.dom('<div class="rx-ai-footer">');
15290
+ const $buttons = this.dom('<div class="rx-ai-buttons">');
15288
15291
  this.$progress = this.dom('<div class="rx-ai-progress">');
15289
15292
  this.$previewLabel = this.dom('<div class="rx-ai-preview-label">');
15290
15293
  this.$preview = this.dom('<div class="rx-ai-preview">');
15291
15294
  this.$prompt = this.dom('<div class="rx-ai-prompt">');
15292
15295
  this.$label = this.dom('<label class="rx-ai-label">').html(this.lang.get("ai.prompt"));
15293
- this.$textarea = this.dom('<textarea class="rx-ai-textarea rx-form-textarea">').attr({ "placeholder": placeholder });
15296
+ this.$textarea = this.dom('<textarea class="rx-ai-textarea rx-form-textarea">').attr({ placeholder });
15294
15297
  this.$select = this.dom('<select class="rx-ai-select rx-form-select">');
15295
15298
  this.$size = this.dom('<select class="rx-ai-size rx-form-select">');
15296
15299
  this._createPromptFooter($footer, $buttons);
@@ -15318,14 +15321,14 @@ Redactor.add("plugin", "ai", {
15318
15321
  return this.dom('<button class="rx-ai-button rx-form-button">').html(label);
15319
15322
  },
15320
15323
  _createSize($size) {
15321
- let items = this.opts.get("ai.size");
15322
- for (let [key, name] of Object.entries(items)) {
15323
- let $option = this.dom("<option>").val(key).html(name);
15324
+ const items = this.opts.get("ai.size");
15325
+ for (const [key, name] of Object.entries(items)) {
15326
+ const $option = this.dom("<option>").val(key).html(name);
15324
15327
  $size.append($option);
15325
15328
  }
15326
15329
  },
15327
15330
  _createTone($select) {
15328
- let items = this.promptType === "image" ? this.opts.get("ai.style") || this.defaults.style : this.opts.get("ai.tone") || this.defaults.tone;
15331
+ const items = this.promptType === "image" ? this.opts.get("ai.style") || this.defaults.style : this.opts.get("ai.tone") || this.defaults.tone;
15329
15332
  let name = this.promptType === "image" ? this.lang.get("ai.image-style") : this.lang.get("ai.change-tone");
15330
15333
  let $option = this.dom("<option>").val(0).html(name);
15331
15334
  $select.append($option);
@@ -15349,19 +15352,20 @@ Redactor.add("plugin", "ai", {
15349
15352
  },
15350
15353
  _createSource(url, data) {
15351
15354
  const eventTarget = new EventTarget();
15352
- let ajax = this.ajax.post({
15355
+ const ajax = this.ajax.post({
15353
15356
  url,
15354
15357
  data,
15355
15358
  before: function(xhr2) {
15356
- let event = this.app.broadcast("ai.before.send", { xhr: xhr2, data });
15359
+ const event = this.app.broadcast("ai.before.send", { xhr: xhr2, data });
15357
15360
  if (event.isStopped()) {
15358
15361
  return false;
15359
15362
  }
15360
15363
  }.bind(this)
15361
15364
  });
15362
- let xhr = ajax.xhr;
15363
- let that = this;
15364
- var ongoing = false, start2 = 0;
15365
+ const xhr = ajax.xhr;
15366
+ const that = this;
15367
+ let ongoing = false;
15368
+ let start2 = 0;
15365
15369
  xhr.onprogress = function() {
15366
15370
  if (!ongoing) {
15367
15371
  ongoing = true;
@@ -15373,7 +15377,7 @@ Redactor.add("plugin", "ai", {
15373
15377
  }
15374
15378
  let i, chunk;
15375
15379
  if (that._isJsonString(xhr.responseText)) {
15376
- let response = JSON.parse(xhr.responseText);
15380
+ const response = JSON.parse(xhr.responseText);
15377
15381
  if (response.error) {
15378
15382
  that._error(response.error.message, response);
15379
15383
  eventTarget.close();
@@ -15394,7 +15398,9 @@ Redactor.add("plugin", "ai", {
15394
15398
  return eventTarget;
15395
15399
  },
15396
15400
  _isElementBottomBeyond(element) {
15397
- let $target = this.app.scroll.getTarget(), rect = element.getBoundingClientRect(), elementBottom = rect.top + rect.height;
15401
+ const $target = this.app.scroll.getTarget();
15402
+ const rect = element.getBoundingClientRect();
15403
+ const elementBottom = rect.top + rect.height;
15398
15404
  return elementBottom > $target.get().innerHeight;
15399
15405
  },
15400
15406
  _isJsonString(str) {
@@ -15407,16 +15413,16 @@ Redactor.add("plugin", "ai", {
15407
15413
  },
15408
15414
  _insertAfterNode($tmp, content) {
15409
15415
  let inserted;
15410
- let instanceType = this.instance && this.instance.isType(["listitem", "todoitem"]);
15411
- let event = this.app.broadcast("ai.before.insert", { html: content });
15416
+ const instanceType = this.instance && this.instance.isType(["listitem", "todoitem"]);
15417
+ const event = this.app.broadcast("ai.before.insert", { html: content });
15412
15418
  content = event.get("html");
15413
15419
  if (instanceType) {
15414
15420
  this.instance.setContent(content);
15415
15421
  inserted = this.instance.getBlock();
15416
15422
  } else {
15417
- let insertion = this.app.create("insertion");
15418
- let node = this.app.block.create();
15419
- let $node = node.getBlock();
15423
+ const insertion = this.app.create("insertion");
15424
+ const node = this.app.block.create();
15425
+ const $node = node.getBlock();
15420
15426
  content = this._parseReply(content);
15421
15427
  $tmp.after($node);
15422
15428
  $tmp.remove();
@@ -15426,7 +15432,7 @@ Redactor.add("plugin", "ai", {
15426
15432
  this.app.broadcast("ai.insert", { nodes: inserted });
15427
15433
  },
15428
15434
  _insertPrompt($prompt, current, params) {
15429
- let elm = this.app.create("element");
15435
+ const elm = this.app.create("element");
15430
15436
  let position = "after";
15431
15437
  if (!current) {
15432
15438
  if (this.opts.get("addPosition") === "top") {
@@ -15437,7 +15443,7 @@ Redactor.add("plugin", "ai", {
15437
15443
  position = "after";
15438
15444
  }
15439
15445
  }
15440
- let $current = current.getBlock();
15446
+ const $current = current.getBlock();
15441
15447
  $current[position]($prompt);
15442
15448
  elm.scrollTo($prompt);
15443
15449
  this.app.observer.observeUnset();
@@ -15497,8 +15503,8 @@ Redactor.add("plugin", "ai", {
15497
15503
  result += inCodeBlock ? this._escapeHtml(line) + "\n" : `<p>${this._escapeHtml(line)}</p>`;
15498
15504
  }
15499
15505
  }
15500
- let bTag = tags.b ? tags.b : "b";
15501
- let iTag = tags.i ? tags.i : "i";
15506
+ const bTag = tags.b ? tags.b : "b";
15507
+ const iTag = tags.i ? tags.i : "i";
15502
15508
  result = result.replace(/\*\*\_(.*?)\_\*\*/g, "<" + bTag + "><" + iTag + ">$1</" + iTag + "></" + bTag + ">");
15503
15509
  result = result.replace(/\*\*(.*?)\*\*/g, "<" + bTag + ">$1</" + bTag + ">");
15504
15510
  result = result.replace(/\*(.*?)\*/g, "<" + iTag + ">$1</" + iTag + ">");
@@ -15506,7 +15512,7 @@ Redactor.add("plugin", "ai", {
15506
15512
  },
15507
15513
  _replaceCodeLine(line) {
15508
15514
  return line.replace(/\`\`\`(([^\s]+))?/gm, function(match, p1, p2) {
15509
- let classAttribute = p2 ? ' class="' + p2 + '"' : "";
15515
+ const classAttribute = p2 ? ' class="' + p2 + '"' : "";
15510
15516
  return "<pre" + classAttribute + "><code>";
15511
15517
  });
15512
15518
  },
@@ -1,3 +1,3 @@
1
1
  module Formstrap
2
- VERSION = "0.4.9"
2
+ VERSION = "0.4.10"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: formstrap
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.9
4
+ version: 0.4.10
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jef Vlamings
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2025-02-17 00:00:00.000000000 Z
11
+ date: 2025-03-10 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: An extensive Bootstrap form library to power your Ruby On Rails application.
14
14
  email: