leksy-editor 1.0.6 → 1.0.7

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.
Files changed (3) hide show
  1. package/index.js +6 -0
  2. package/package.json +1 -1
  3. package/plugin.js +57 -3
package/index.js CHANGED
@@ -144,6 +144,11 @@ class LeksyEditor {
144
144
  }
145
145
  return content
146
146
  },
147
+ handleFilePicker: async (mimeType,type) => {
148
+ if (editorRef.handleFilePicker instanceof Function) {return await editorRef.handleFilePicker(mimeType,type)}
149
+ return null
150
+
151
+ },
147
152
  updateBreadcumb: (parentTags) => {
148
153
  if (!options.hideNavigation && Array.isArray(parentTags)) {
149
154
  core.elements.breadcumb.innerHTML = ''
@@ -229,6 +234,7 @@ class LeksyEditor {
229
234
  onBlur: () => { },
230
235
  onAttachment: () => { },
231
236
  manuplateImage: async () => { },
237
+ handleFilePicker: async () => { },
232
238
  uploadVideo: async () => { },
233
239
  focus: () => { core.elements.editor.focus() },
234
240
  getCore: () => core,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "leksy-editor",
3
- "version": "1.0.6",
3
+ "version": "1.0.7",
4
4
  "description": "Leksy Editor is an alternative to traditional WYSIWYG editors, designed primarily for creating mail templates, blogs, and documents without any content manipulation.",
5
5
  "main": "index.js",
6
6
  "directories": {
package/plugin.js CHANGED
@@ -710,7 +710,7 @@ const PLUGINS = {
710
710
  { label: 'Upload from device', value: 'upload' },
711
711
  { label: 'Using Link', value: 'link' },
712
712
  ],
713
- click: (event, core, options) => {
713
+ click: async (event, core, options) => {
714
714
  if (event.target.getAttribute('data-value') === 'upload') {
715
715
 
716
716
  const onInputKeydown = (event) => {
@@ -719,12 +719,32 @@ const PLUGINS = {
719
719
  button.click();
720
720
  }
721
721
  };
722
-
723
722
  const body = document.createElement('div');
724
723
 
724
+
725
725
  const fileInput = document.createElement('input');
726
726
  fileInput.type = 'file';
727
727
  fileInput.accept = MIMETYPE.IMAGE;
728
+ fileInput.style.display = 'none';
729
+
730
+ // Create a label or button to trigger file input
731
+ const uploadBtn = document.createElement('button');
732
+ uploadBtn.innerText = 'Choose Image';
733
+ uploadBtn.type = 'button';
734
+ uploadBtn.style.border = '2px solid grey';
735
+ uploadBtn.style.padding = '4px';
736
+ uploadBtn.style.borderRadius = '8px';
737
+
738
+
739
+ // Span to show selected file name
740
+ const fileNameSpan = document.createElement('span');
741
+ fileNameSpan.style.marginLeft = '10px';
742
+ fileNameSpan.innerText = 'No file selected';
743
+
744
+ uploadBtn.addEventListener('click', () => {
745
+ fileInput.click(); // Trigger file input
746
+ });
747
+
728
748
 
729
749
  const altInput = document.createElement('input');
730
750
  altInput.type = 'text';
@@ -735,7 +755,7 @@ const PLUGINS = {
735
755
  const span = document.createElement('span');
736
756
  span.className = 'warning';
737
757
 
738
- body.append(fileInput, altInput, span);
758
+ body.append(fileInput, uploadBtn, fileNameSpan, altInput, span);
739
759
 
740
760
  const footer = document.createElement('div');
741
761
  const button = document.createElement('button');
@@ -766,7 +786,18 @@ const PLUGINS = {
766
786
  };
767
787
 
768
788
  reader.readAsDataURL(file);
789
+ fileNameSpan.innerText = file.name;
790
+ span.innerText = ""; // Clear warning if file is selected
791
+ }
792
+ });
793
+ fileInput.addEventListener('click', async () => {
794
+ let fileFromNative = await core.handleFilePicker(MIMETYPE.IMAGE.split(','), 'image');
795
+
796
+ if (fileFromNative) {
797
+ base64String = fileFromNative.data;
798
+ fileNameSpan.innerText = fileFromNative.name;
769
799
  span.innerText = ""; // Clear warning if file is selected
800
+
770
801
  }
771
802
  });
772
803
  button.onclick = async () => {
@@ -865,6 +896,23 @@ const PLUGINS = {
865
896
  }
866
897
  }
867
898
  });
899
+
900
+ fileInput.addEventListener('click', async () => {
901
+ let file = await core.handleFilePicker(MIMETYPE.VIDEO.split(','), 'video');
902
+ if (MIMETYPE.VIDEO.includes(file.type)) {
903
+ const url = await core.uploadVideo(file);
904
+ if (url) {
905
+ const a = document.createElement('a');
906
+ a.href = url.videoUrl
907
+ a.target = '_blank'
908
+ const img = document.createElement('img');
909
+ img.src = url.thumbnailUrl
910
+ a.appendChild(img)
911
+ core.insertNode(a);
912
+ }
913
+ }
914
+ });
915
+
868
916
  fileInput.click();
869
917
  core.updateCaretPosition()
870
918
  }
@@ -881,6 +929,12 @@ const PLUGINS = {
881
929
  fileInput.addEventListener('change', (event) => {
882
930
  core.onAttachment(event.target.files);
883
931
  });
932
+
933
+ fileInput.addEventListener('click', async () => {
934
+ let files = await core.handleFilePicker(["*"], 'attachment');
935
+ core.onAttachment(files);
936
+
937
+ });
884
938
  fileInput.click();
885
939
  core.updateCaretPosition()
886
940
  }