@yoopta/file 1.0.0-rc

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/README.md ADDED
@@ -0,0 +1,11 @@
1
+ # `@yoopta/code`
2
+
3
+ > TODO: description
4
+
5
+ ## Usage
6
+
7
+ ```
8
+ const blockquote = require('@yoopta/code');
9
+
10
+ // TODO: DEMONSTRATE API
11
+ ```
@@ -0,0 +1,10 @@
1
+ /// <reference types="react" />
2
+ import { RenderYooptaElementProps, YooEditor } from '@yoopta/editor';
3
+ import { FileElement, FilePluginOptions } from '../types';
4
+ type Props = RenderYooptaElementProps<FileElement> & {
5
+ editor: YooEditor;
6
+ onUpload?: FilePluginOptions['onUpload'];
7
+ accept?: FilePluginOptions['accept'];
8
+ };
9
+ declare const EditorPlaceholder: ({ element, accept, attributes, children, editor, onUpload }: Props) => JSX.Element;
10
+ export { EditorPlaceholder };
@@ -0,0 +1,10 @@
1
+ /// <reference types="react" />
2
+ declare const EditorUploader: ({ activeTab, style, switchTab, onChange, accept, onClose }: {
3
+ activeTab?: string | undefined;
4
+ style: any;
5
+ switchTab: any;
6
+ onChange: any;
7
+ accept: any;
8
+ onClose: any;
9
+ }) => JSX.Element;
10
+ export { EditorUploader };
@@ -0,0 +1,6 @@
1
+ /// <reference types="react" />
2
+ type Props = {
3
+ className?: string;
4
+ };
5
+ declare const Loader: ({ className }: Props) => JSX.Element;
6
+ export { Loader };
@@ -0,0 +1,11 @@
1
+ import { YooEditor } from '@yoopta/editor';
2
+ import { FileElement, FileElementData, FilePluginOptions } from './types';
3
+ declare module 'slate' {
4
+ interface CustomTypes {
5
+ Editor: YooEditor;
6
+ Element: FileElement;
7
+ }
8
+ }
9
+ declare const File: any;
10
+ export default File;
11
+ export { FileElement, FileElementData, FilePluginOptions };
package/dist/index.js ADDED
@@ -0,0 +1 @@
1
+ import{getElementClassname as e,UI_HELPERS as t,cx as i,createYooptaPlugin as n,getElementByPath as r,generateId as o}from"@yoopta/editor";import{Transforms as a,Element as s}from"slate";import{jsx as d,jsxs as l}from"react/jsx-runtime";import*as p from"react";import{useState as c,useRef as h}from"react";import{ReactEditor as g,useSelected as f,useReadOnly as x}from"slate-react";var u;function m(){return m=Object.assign?Object.assign.bind():function(e){for(var t=1;t<arguments.length;t++){var i=arguments[t];for(var n in i)Object.prototype.hasOwnProperty.call(i,n)&&(e[n]=i[n])}return e},m.apply(this,arguments)}var b=function(e){return p.createElement("svg",m({viewBox:"0 0 16 16"},e),u||(u=p.createElement("path",{d:"M4.356 15.468h7.28c1.464 0 2.222-.773 2.222-2.242v-6.2c0-.95-.123-1.388-.717-1.99l-3.59-3.65C8.979.805 8.507.668 7.652.668H4.356c-1.462 0-2.221.772-2.221 2.242v10.316c0 1.476.759 2.242 2.221 2.242Zm.11-1.34c-.663 0-.991-.349-.991-.984V2.992c0-.629.328-.984.99-.984h2.913v3.746c0 .977.485 1.45 1.456 1.45h3.685v5.94c0 .635-.335.984-.998.984H4.466Zm4.491-8.1c-.28 0-.396-.124-.396-.404V2.192l3.773 3.835H8.957Zm-.362 6.699v-2.1L8.54 9.563l.526.553.527.533a.531.531 0 0 0 .396.185c.308 0 .54-.219.54-.526a.49.49 0 0 0-.191-.404L8.45 8.167c-.157-.144-.287-.205-.458-.205-.164 0-.294.061-.451.205L5.655 9.903a.49.49 0 0 0-.191.404c0 .307.225.526.54.526a.543.543 0 0 0 .396-.185l.527-.533.526-.553-.055 1.066v2.099c0 .328.274.574.595.574.328 0 .602-.246.602-.574Z"})))};function w(e,t){void 0===t&&(t={});var i=t.insertAt;if(e&&"undefined"!=typeof document){var n=document.head||document.getElementsByTagName("head")[0],r=document.createElement("style");r.type="text/css","top"===i&&n.firstChild?n.insertBefore(r,n.firstChild):n.appendChild(r),r.styleSheet?r.styleSheet.cssText=e:r.appendChild(document.createTextNode(e))}}var v="eCBVJfAM",y="_1jrGaPHJ",j="_3xzPD4wO",P="_3jw0sAIy",k="gIQQGHaD";function N(e){if("number"!=typeof e||isNaN(e))return null;return(e/1024).toFixed(2)+" KB"}w(".eCBVJfAM{align-items:center;display:flex;justify-content:flex-start;margin:10px 0;position:relative;transition:background .1s cubic-bezier(.4,0,.2,1)}._1jrGaPHJ{border-radius:1px;max-width:100%;object-fit:cover;padding:6px 4px;pointer-events:auto;width:100%}._1jrGaPHJ:hover{background:rgba(35,131,226,.14)}._3xzPD4wO{display:flex}._3xzPD4wO svg{min-height:20px;min-width:20px}._3jw0sAIy{align-items:center;display:flex;font-weight:600;line-height:18px;margin-left:6px;overflow:hidden;text-overflow:ellipsis;white-space:pre-line}.gIQQGHaD{color:#8e8e93;font-size:12px;margin-left:10px}");"function"==typeof SuppressedError&&SuppressedError;w('._83eU-j-s{position:fixed}._6CLndPnr{background:#fff;box-shadow:0 0 0 1px hsla(0,0%,6%,.05),0 3px 6px hsla(0,0%,6%,.1),0 9px 24px hsla(0,0%,6%,.2);display:flex;flex-direction:column;height:100%;max-height:420px;max-width:calc(100vw - 24px);min-width:540px}._7JqczNzX{box-shadow:inset 0 -1px 0 rgba(55,53,47,.09);display:flex;height:40px;padding:0 8px;width:100%;z-index:1}._7JqczNzX,.sYo42svD{font-size:14px;position:relative}.sYo42svD{align-items:center;background-color:inherit;border:none;border-radius:4px;color:#37352f;cursor:pointer;display:inline-flex;flex-shrink:0;height:100%;line-height:1.2;min-width:0;padding:6px 8px;transition:height 20ms ease-in 0s;user-select:none;white-space:nowrap}.d7kPuF2M:after{background-color:#37352f;bottom:0;content:"";height:2px;left:0;position:absolute;width:100%}._3Hw9hXef{display:flex;justify-content:center;margin-left:12px;margin-right:12px;margin-top:4px;padding-bottom:6px;padding-top:6px}.PFlyte3h{border:1px solid rgba(55,53,47,.16);border-radius:4px;cursor:pointer;height:32px;padding-left:12px;padding-right:12px;transition:background 20ms ease-in 0s;user-select:none;white-space:nowrap;width:100%}.ciBcVyws{border:none!important;cursor:pointer!important;height:auto!important;padding-left:0!important;padding-right:0!important}.MIwvxioK{align-items:center;cursor:pointer;display:inline-flex;font-size:14px;font-weight:500;height:100%;justify-content:center;line-height:1.2;width:100%}.WBUFnuEP{left:0;position:absolute;top:0;visibility:hidden}.P5wQ7tuy{background:hsla(45,13%,94%,.6);box-shadow:inset 0 0 0 1px hsla(0,0%,6%,.1);cursor:text;height:32px;line-height:20px;padding:3px 6px;position:relative}.P5wQ7tuy,.RywjmYhg{align-items:center;border:none;border-radius:4px;display:flex;font-size:14px;width:100%}.RywjmYhg{fill:#fff;background:#2383e2;box-shadow:inset 0 0 0 1px hsla(0,0%,6%,.1),0 1px 2px hsla(0,0%,6%,.1);color:#fff;cursor:pointer;flex-shrink:0;font-weight:500;height:28px;justify-content:center;line-height:1.2;margin:12px auto 6px;max-width:300px;padding-left:12px;padding-right:12px;transition:background 20ms ease-in 0s;user-select:none;white-space:nowrap}');if("undefined"!=typeof window){var z={get passive(){!0}};window.addEventListener("testPassive",null,z),window.removeEventListener("testPassive",null,z)}"undefined"!=typeof window&&window.navigator&&window.navigator.platform&&(/iP(ad|hone|od)/.test(window.navigator.platform)||"MacIntel"===window.navigator.platform&&window.navigator.maxTouchPoints);w(".MwDZgdnr{margin:20px 0 10px;user-select:none}.MwDZgdnr,.o-YPlsho{position:relative;width:100%}.o-YPlsho{align-items:center;background-color:#efefef;border:none;border-radius:3px;color:rgba(55,53,47,.65);cursor:pointer;display:flex;font-size:14px;overflow:hidden;padding:12px 36px 12px 12px;text-align:left;transition:background-color .1s ease-in}.o-YPlsho:hover{background-color:#e3e3e3}.HbsQ6aF6{margin-right:8px;user-select:none}");var H={loader:"DG75gUwl","loader-first":"oyQ-X7Mi","loader-second":"wuPn2c-U","loader-third":"hwvNZHfN"};w('.DG75gUwl{animation:oyQ-X7Mi 3s linear infinite;display:block;height:24px;width:24px}@keyframes oyQ-X7Mi{0%{transform:rotate(0deg)}to{transform:rotate(1turn)}}.DG75gUwl span{clip:rect(16px,24px,24px,0);animation:wuPn2c-U 1.5s cubic-bezier(.77,0,.175,1) infinite;bottom:0;display:block;height:24px;left:0;margin:auto;position:absolute;right:0;top:0;width:24px}@keyframes wuPn2c-U{0%{transform:rotate(0deg)}to{transform:rotate(1turn)}}.DG75gUwl span:before{animation:hwvNZHfN 1.5s cubic-bezier(.77,0,.175,1) infinite;border:3px solid transparent;border-radius:50%;border-top-color:#fff;bottom:0;content:"";display:block;height:24px;left:0;margin:auto;position:absolute;right:0;top:0;width:24px}@keyframes hwvNZHfN{0%{transform:rotate(0deg)}to{transform:rotate(1turn)}}.DG75gUwl span:after{border:3px solid hsla(0,0%,100%,.5);border-radius:50%;bottom:0;content:"";display:block;height:24px;left:0;margin:auto;position:absolute;right:0;top:0;width:24px}');const D=({className:e})=>d("div",Object.assign({className:i(H.container,e)},{children:d("div",Object.assign({className:H.loader},{children:d("span",{})}))}));var O={root:"r29Aw2Hb",dotsOptions:"jgDPzrdW",loader:"dVPNllHs",dot:"Dmm1WXgb",loadingState:"fyMnhKHH"};w(".r29Aw2Hb{cursor:pointer;display:block;position:relative}.r29Aw2Hb:hover .jgDPzrdW{opacity:1}.dVPNllHs,.jgDPzrdW{position:absolute;right:10px;top:50%;transform:translateY(-50%)}.jgDPzrdW{align-items:center;background-color:#eee;border:none;border-radius:2px;cursor:pointer;display:flex;height:22px;justify-content:space-between;opacity:0;padding:0 4px;transition:opacity .15s ease-in 0s;width:22px;z-index:1}.Dmm1WXgb{background-color:gray;border-radius:50%;min-height:3px;min-width:3px}.fyMnhKHH{background:rgba(35,131,226,.14);opacity:.7;pointer-events:none}");function E(e){const{element:t,editor:n,plugin:r}=e,o=(f(),x()),[a,s]=c(null),p=!0;return console.log("isLoading",p),console.log("element.data",t.data),t.data.url,l("div",Object.assign({contentEditable:!1,draggable:!1,className:i(O.root,{[O.loadingState]:p})},{children:[r.renderer.render(e),d("div",Object.assign({className:O.loader},{children:d(D,{})})),!o&&!1]}),t.id)}const M=n({type:"file",shortcut:"file",renderer:{editor:(e,t)=>i=>d(E,Object.assign({editor:e,plugin:t},i)),render:({attributes:t,element:i,children:n,HTMLAttributes:r})=>i.data.url||i.data["data-url"]?l("div",Object.assign({},t,{className:v,contentEditable:!1,draggable:!1},{children:[d("a",Object.assign({target:"_blank",rel:"noopener noreferrer",href:i.data.url,className:e({element:i,HTMLAttributes:r,className:y})},{children:l("div",Object.assign({className:j},{children:[d(b,{height:20,width:20}),l("div",Object.assign({className:P},{children:[i.data.name,d("span",Object.assign({className:k},{children:N(i.data.size)}))]}))]}))})),n]})):d("div",Object.assign({},t))},extendEditor(e){const{isVoid:t}=e;return e.isVoid=e=>e.type===M.getPlugin.type||t(e),e},events:{onKeyDown:(e,{defaultNode:t,hotkeys:i})=>n=>{var o;if("file"===r(e,null===(o=e.selection)||void 0===o?void 0:o.anchor.path,"highest").type&&e.selection)return i.isEnter(n)?(n.preventDefault(),void a.insertNodes(e,t,{mode:"highest"})):void 0}},defineElement:()=>({id:o(),type:"file",nodeType:"void",data:{url:null,name:"",size:0},children:[{text:""}]}),createElement:(e,t)=>{var i;const n=Object.assign(Object.assign({},M.getPlugin.defineElement()),t);a.setNodes(e,n,{at:null===(i=e.selection)||void 0===i?void 0:i.anchor})},exports:{markdown:{serialize:(e,t)=>`![${e.data.name||""}](${e.data.url})\n`},html:{serialize:(e,t)=>(console.log("node",e),console.log("children",t),`<div><a href="${e.data.url}" target="_blank" rel="noopener noreferrer">${e.data.name}</a></div>`),deserialize:{nodeName:"A",parse:e=>({url:e.getAttribute("href"),name:e.textContent})}}},options:{searchString:"file url",displayLabel:"File"}});export{M as default};
@@ -0,0 +1,18 @@
1
+ import { YooptaBaseElement, Modify, YooptaPluginBaseOptions } from '@yoopta/editor';
2
+ export type FileUploadResponse = {
3
+ url: string;
4
+ preview?: string;
5
+ };
6
+ export type FilePluginOptions = {
7
+ accept?: string | undefined;
8
+ onUpload: (file: File) => Promise<FileUploadResponse>;
9
+ } & YooptaPluginBaseOptions;
10
+ export type FileElementData = {
11
+ 'data-url'?: string | null | undefined;
12
+ url: string | null | undefined;
13
+ name: string;
14
+ size: number;
15
+ };
16
+ export type FileElement = Modify<YooptaBaseElement<'file'>, {
17
+ data: FileElementData;
18
+ }>;
@@ -0,0 +1,8 @@
1
+ import { RenderYooptaElementProps } from '@yoopta/editor';
2
+ import { ReactNode } from 'react';
3
+ import { FileElement } from '../types';
4
+ type Props = RenderYooptaElementProps<FileElement> & {
5
+ children?: ReactNode;
6
+ };
7
+ declare const File: ({ attributes, element, children, HTMLAttributes }: Props) => JSX.Element;
8
+ export { File };
@@ -0,0 +1,7 @@
1
+ /// <reference types="react" />
2
+ declare const FileEditorFactory: (editor: YooEditor, plugin: YooptaPluginType<any, Modify<YooptaBaseElement<"file">, {
3
+ data: import("../types").FileElementData;
4
+ }>>) => (props: RenderYooptaElementProps<Modify<YooptaBaseElement<"file">, {
5
+ data: import("../types").FileElementData;
6
+ }>>) => JSX.Element;
7
+ export { FileEditorFactory };
package/package.json ADDED
@@ -0,0 +1,36 @@
1
+ {
2
+ "name": "@yoopta/file",
3
+ "version": "1.0.0-rc",
4
+ "description": "> TODO: description",
5
+ "author": "Darginec05 <devopsbanda@gmail.com>",
6
+ "homepage": "https://github.com/Darginec05/Editor-Yoopta#readme",
7
+ "license": "MIT",
8
+ "private": false,
9
+ "type": "module",
10
+ "main": "dist/index.js",
11
+ "module": "dist/index.js",
12
+ "types": "./dist/index.d.ts",
13
+ "files": [
14
+ "dist/"
15
+ ],
16
+ "peerDependencies": {
17
+ "@yoopta/editor": ">=1.9.18-rc",
18
+ "react": ">=17.0.2",
19
+ "react-dom": ">=17.0.2",
20
+ "slate": ">=0.72.3",
21
+ "slate-react": ">=0.95.0"
22
+ },
23
+ "publishConfig": {
24
+ "registry": "https://registry.yarnpkg.com"
25
+ },
26
+ "repository": {
27
+ "type": "git",
28
+ "url": "git+https://github.com/Darginec05/Editor-Yoopta.git"
29
+ },
30
+ "scripts": {
31
+ "test": "node ./__tests__/yoopta-code.test.js"
32
+ },
33
+ "bugs": {
34
+ "url": "https://github.com/Darginec05/Editor-Yoopta/issues"
35
+ }
36
+ }