lakelib 0.1.0 → 0.1.1

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/lib/lake.js CHANGED
@@ -4299,7 +4299,7 @@ class Dropdown {
4299
4299
  }
4300
4300
  }
4301
4301
 
4302
- var version = "0.1.0";
4302
+ var version = "0.1.1";
4303
4303
 
4304
4304
  // Inserts a box into the specified range.
4305
4305
  function insertBox(range, boxName, boxValue) {
@@ -4902,9 +4902,6 @@ const defaultConfig = {
4902
4902
  tabIndex: 0,
4903
4903
  indentWithTab: true,
4904
4904
  minChangeSize: 5,
4905
- imageRequestMethod: 'POST',
4906
- imageRequestAction: '/upload',
4907
- imageRequestTypes: ['image/gif', 'image/jpeg', 'image/png', 'image/svg+xml'],
4908
4905
  };
4909
4906
  class Editor {
4910
4907
  constructor(config) {
@@ -5038,7 +5035,10 @@ class Editor {
5038
5035
  }
5039
5036
  this.root = query(config.root);
5040
5037
  this.toolbar = config.toolbar;
5041
- this.config = Object.assign(Object.assign({}, defaultConfig), config);
5038
+ this.config = Object.assign({}, defaultConfig);
5039
+ for (const key of Object.keys(config)) {
5040
+ this.config[key] = config[key];
5041
+ }
5042
5042
  this.containerWrapper = query('<div class="lake-container-wrapper" />');
5043
5043
  this.container = query('<div class="lake-container" />');
5044
5044
  this.overlayContainer = query('<div class="lake-overlay" />');
@@ -5207,6 +5207,17 @@ class Editor {
5207
5207
  this.history.continue();
5208
5208
  this.history.save();
5209
5209
  }
5210
+ // Sets default config for a plugin.
5211
+ setPluginConfig(pluginName, pluginConfig) {
5212
+ if (!this.config[pluginName]) {
5213
+ this.config[pluginName] = {};
5214
+ }
5215
+ for (const key of Object.keys(pluginConfig)) {
5216
+ if (this.config[pluginName][key] === undefined) {
5217
+ this.config[pluginName][key] = pluginConfig[key];
5218
+ }
5219
+ }
5220
+ }
5210
5221
  // Sets focus on the editor area.
5211
5222
  focus() {
5212
5223
  this.container.focus();
@@ -6232,9 +6243,9 @@ const toolbarItems = [
6232
6243
 
6233
6244
  function uploadImage(config) {
6234
6245
  const { editor, file, onError, onSuccess } = config;
6235
- const { imageRequestMethod, imageRequestAction, imageRequestTypes } = editor.config;
6236
- if (imageRequestTypes.indexOf(file.type) < 0) {
6237
- throw new Error(`Cannot upload file because its type '${file.type}' is not found in ['${imageRequestTypes.join('\', \'')}'].`);
6246
+ const { requestMethod, requestAction, requestTypes } = editor.config.image;
6247
+ if (requestTypes.indexOf(file.type) < 0) {
6248
+ throw new Error(`Cannot upload file because its type '${file.type}' is not found in ['${requestTypes.join('\', \'')}'].`);
6238
6249
  }
6239
6250
  const box = editor.insertBox('image', {
6240
6251
  url: URL.createObjectURL(file),
@@ -6278,8 +6289,8 @@ function uploadImage(config) {
6278
6289
  }
6279
6290
  },
6280
6291
  file,
6281
- action: imageRequestAction,
6282
- method: imageRequestMethod,
6292
+ action: requestAction,
6293
+ method: requestMethod,
6283
6294
  });
6284
6295
  box.setData('xhr', xhr);
6285
6296
  return box;
@@ -7366,8 +7377,8 @@ function pasteFragment(editor, fragment) {
7366
7377
  editor.history.save();
7367
7378
  }
7368
7379
  var paste = (editor) => {
7369
- const { imageRequestTypes } = editor.config;
7370
7380
  editor.container.on('paste', event => {
7381
+ const { requestTypes } = editor.config.image;
7371
7382
  const range = editor.selection.range;
7372
7383
  if (range.isInsideBox) {
7373
7384
  return;
@@ -7381,7 +7392,7 @@ var paste = (editor) => {
7381
7392
  // upload file
7382
7393
  if (dataTransfer.files.length > 0) {
7383
7394
  for (const file of dataTransfer.files) {
7384
- if (imageRequestTypes.indexOf(file.type) >= 0) {
7395
+ if (requestTypes.indexOf(file.type) >= 0) {
7385
7396
  uploadImage({
7386
7397
  editor,
7387
7398
  file,
@@ -8184,6 +8195,10 @@ var hr = (editor) => {
8184
8195
  };
8185
8196
 
8186
8197
  var image = (editor) => {
8198
+ editor.setPluginConfig('image', {
8199
+ requestMethod: 'POST',
8200
+ requestTypes: ['image/gif', 'image/jpeg', 'image/png', 'image/svg+xml'],
8201
+ });
8187
8202
  editor.event.on('beforepaste', (nativeFragment) => {
8188
8203
  const fragment = new Fragment(nativeFragment);
8189
8204
  fragment.find('img').each(nativeNode => {