Skip to content

Commit

Permalink
feat: 💥 video 插件 & 优化icon
Browse files Browse the repository at this point in the history
  • Loading branch information
rojer95 committed Oct 22, 2024
1 parent 419b3c0 commit 468e6db
Show file tree
Hide file tree
Showing 12 changed files with 875 additions and 46 deletions.
2 changes: 1 addition & 1 deletion packages/antd/lib/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ export const DefaultToolbar = [
'line-height',
'divider',
'img',
'video',
'link',
'blockquote',
'hr',
Expand All @@ -81,7 +82,6 @@ export default forwardRef<DSlateRef, AntdStyleDSlateProps>(
const locales = context.locales ? context.locales : DefaultLocales;

return {
iconScriptUrl: '//at.alicdn.com/t/c/font_3062978_igshjiflyft.js',
...context,
locales: mergeLocalteFromPlugins(locales, plugins),
plugins,
Expand Down
37 changes: 20 additions & 17 deletions packages/component/lib/components/icon.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { ConfigContext } from "@dslate/core";
import { useContext, useEffect } from "react";
import { ConfigContext } from '@dslate/core';
import { useContext, useEffect } from 'react';

const inited: string[] = [];

Expand All @@ -12,17 +12,20 @@ const Icon = (props: IconProps) => {
const { iconScriptUrl } = useContext(ConfigContext);

const initScript = () => {
if (!iconScriptUrl) return;
let urls: any = iconScriptUrl;
if (typeof urls === "string") urls = [urls];

for (const url of urls) {
if (inited.includes(url)) continue;
let script = document.createElement("script");
script.type = "text/javascript";
script.async = true;
script.src = url;
document.head.appendChild(script);
inited.push(url);
if (typeof urls === 'string') urls = [urls];

if (urls?.length) {
for (const url of urls) {
if (inited.includes(url)) continue;
let script = document.createElement('script');
script.type = 'text/javascript';
script.async = true;
script.src = url;
document.head.appendChild(script);
inited.push(url);
}
}
};

Expand All @@ -33,11 +36,11 @@ const Icon = (props: IconProps) => {
return (
<svg
style={{
width: "1em",
height: "1em",
verticalAlign: "-0.15em",
fill: "currentColor",
overflow: "hidden",
width: '1em',
height: '1em',
verticalAlign: '-0.15em',
fill: 'currentColor',
overflow: 'hidden',
...(props?.style ?? {}),
}}
>
Expand Down
70 changes: 70 additions & 0 deletions packages/component/lib/iconfont.js

Large diffs are not rendered by default.

5 changes: 3 additions & 2 deletions packages/component/lib/index.tsx
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
export * from "./components";
export * from "./element";
import './iconfont.js';
export * from './components';
export * from './element';
13 changes: 0 additions & 13 deletions packages/core/lib/utils/base64file.ts

This file was deleted.

29 changes: 29 additions & 0 deletions packages/core/lib/utils/file.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import type { UploadFunc, UploadRequestOption } from '../typing';

export const base64file: UploadFunc = (option: UploadRequestOption) => {
const reader: FileReader = new FileReader();
reader.addEventListener(
'load',
() => {
option.onSuccess?.({ url: reader.result as string });
},
false,
);
reader.readAsDataURL(option.file);
};

export const blobfile: UploadFunc = (option: UploadRequestOption) => {
const reader: FileReader = new FileReader();
reader.addEventListener(
'load',
(event) => {
let blob = new Blob([event?.target?.result as any], {
type: option.file.type,
});
window.URL = window.URL || window.webkitURL;
option.onSuccess?.({ url: window.URL.createObjectURL(blob) });
},
false,
);
reader.readAsDataURL(option.file);
};
20 changes: 13 additions & 7 deletions packages/core/lib/utils/index.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,16 @@
export { mergeStyle, style2string } from './mergeStyle';
export {
clearBlockProps,
getBlockProps,
isBlockActive,
setBlockProps,
toggleBlock,
} from './block';
export { base64file, blobfile } from './file';
export { get } from './get';
export { getTextProps, setTextProps, toggleTextProps } from './text';
export { toggleBlock, getBlockProps, setBlockProps, isBlockActive, clearBlockProps } from './block';
export { withPlugins } from './withPlugins';
export { isEmpty } from './isEmpty';
export { isStart } from './isStart';
export { promiseUploadFunc } from './promiseUploadFunc';
export { base64file } from './base64file';
export { mergeLocalteFromPlugins } from './mergeLocalteFromPlugins';
export { isEmpty } from './isEmpty';
export { mergeStyle, style2string } from './mergeStyle';
export { promiseUploadFunc } from './promiseUploadFunc';
export { getTextProps, setTextProps, toggleTextProps } from './text';
export { withPlugins } from './withPlugins';
15 changes: 11 additions & 4 deletions packages/core/lib/utils/promiseUploadFunc.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
import type { UploadFunc, UploadRequestOption } from "../typing";
import { base64file } from ".";
import { base64file, blobfile } from '.';
import type { UploadFunc, UploadRequestOption } from '../typing';

export const promiseUploadFunc = (
options: UploadRequestOption,
customUploadRequest?: UploadFunc,
setPercent?: (p: number) => void
setPercent?: (p: number) => void,
defaultType: 'dataurl' | 'bloburl' | false = 'dataurl',
) => {
const { onProgress, onError, onSuccess } = options;
return new Promise<{ url?: string }>((resolve, reject) => {
setPercent?.(1);
const args = {
...options,
onProgress: (e: { percent?: number }) => {
Expand All @@ -29,7 +31,12 @@ export const promiseUploadFunc = (
if (customUploadRequest) {
customUploadRequest(args);
} else {
base64file(args);
if (defaultType === 'dataurl') base64file(args);
if (defaultType === 'bloburl') blobfile(args);
alert('not support upload function');
reject('not support upload function');
onError?.(new Error('not support upload function'));
setPercent?.(-1);
}
});
};
3 changes: 2 additions & 1 deletion packages/plugin/lib/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import { ListPlugin } from './plugins/list';
import { ParagraphPlugin } from './plugins/paragraph';
import { TextAlignPlugin } from './plugins/text-align';
import { TodoListPlugin } from './plugins/todo-list';

import { VideoPlugin } from './plugins/video';
export default {
HistoryPlugin,
ClearPlugin,
Expand All @@ -33,6 +33,7 @@ export default {
TextIndentPlugin,
TodoListPlugin,
ImgPlugin,
VideoPlugin,
LinkPlugin,
BlockquotePlugin,
HrPlugin,
Expand Down
Loading

0 comments on commit 468e6db

Please sign in to comment.