@arkyn/components 1.3.108 → 1.3.110
Sign up to get free protection for your applications and to get access to all the features.
- package/dist/bundle.js +12318 -4286
- package/dist/bundle.umd.cjs +38 -23
- package/dist/components/GoogleSearchPlaces/index.js +1 -1
- package/dist/components/RichText/components/BlockButton/intex.d.ts +10 -0
- package/dist/components/RichText/components/BlockButton/intex.d.ts.map +1 -0
- package/dist/components/RichText/components/BlockButton/intex.js +18 -0
- package/dist/components/RichText/components/Element/index.d.ts +5 -0
- package/dist/components/RichText/components/Element/index.d.ts.map +1 -0
- package/dist/components/RichText/components/Element/index.js +22 -0
- package/dist/components/RichText/components/Leaf/index.d.ts +3 -0
- package/dist/components/RichText/components/Leaf/index.d.ts.map +1 -0
- package/dist/components/RichText/components/Leaf/index.js +14 -0
- package/dist/components/RichText/components/MarkButton/index.d.ts +10 -0
- package/dist/components/RichText/components/MarkButton/index.d.ts.map +1 -0
- package/dist/components/RichText/components/MarkButton/index.js +16 -0
- package/dist/components/RichText/components/Toolbar/index.d.ts +8 -0
- package/dist/components/RichText/components/Toolbar/index.d.ts.map +1 -0
- package/dist/components/RichText/components/Toolbar/index.js +6 -0
- package/dist/components/RichText/functions/serialize.d.ts +3 -0
- package/dist/components/RichText/functions/serialize.d.ts.map +1 -0
- package/dist/components/RichText/functions/serialize.js +48 -0
- package/dist/components/RichText/functions/toggleBlock.d.ts +5 -0
- package/dist/components/RichText/functions/toggleBlock.d.ts.map +1 -0
- package/dist/components/RichText/functions/toggleBlock.js +33 -0
- package/dist/components/RichText/functions/toggleMark.d.ts +5 -0
- package/dist/components/RichText/functions/toggleMark.d.ts.map +1 -0
- package/dist/components/RichText/functions/toggleMark.js +10 -0
- package/dist/components/RichText/helpers/isBlockActive.d.ts +5 -0
- package/dist/components/RichText/helpers/isBlockActive.d.ts.map +1 -0
- package/dist/components/RichText/helpers/isBlockActive.js +15 -0
- package/dist/components/RichText/helpers/isMarkActive.d.ts +5 -0
- package/dist/components/RichText/helpers/isMarkActive.d.ts.map +1 -0
- package/dist/components/RichText/helpers/isMarkActive.js +6 -0
- package/dist/components/RichText/index.d.ts +12 -0
- package/dist/components/RichText/index.d.ts.map +1 -0
- package/dist/components/RichText/index.js +46 -0
- package/dist/components/RichText/template/HOTKEYS.d.ts +7 -0
- package/dist/components/RichText/template/HOTKEYS.d.ts.map +1 -0
- package/dist/components/RichText/template/HOTKEYS.js +7 -0
- package/dist/components/RichText/template/INITIAL_VALUE.d.ts +4 -0
- package/dist/components/RichText/template/INITIAL_VALUE.d.ts.map +1 -0
- package/dist/components/RichText/template/INITIAL_VALUE.js +7 -0
- package/dist/components/RichText/template/LIST_TYPES.d.ts +3 -0
- package/dist/components/RichText/template/LIST_TYPES.d.ts.map +1 -0
- package/dist/components/RichText/template/LIST_TYPES.js +2 -0
- package/dist/components/RichText/template/TEXT_ALIGN_TYPES.d.ts +3 -0
- package/dist/components/RichText/template/TEXT_ALIGN_TYPES.d.ts.map +1 -0
- package/dist/components/RichText/template/TEXT_ALIGN_TYPES.js +2 -0
- package/dist/index.d.ts +3 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +3 -2
- package/dist/style.css +1 -1
- package/package.json +5 -1
- package/src/components/GoogleSearchPlaces/index.tsx +1 -1
- package/src/components/RichText/components/BlockButton/intex.tsx +41 -0
- package/src/components/RichText/components/BlockButton/styles.css +29 -0
- package/src/components/RichText/components/Element/index.tsx +57 -0
- package/src/components/RichText/components/Element/styles.css +23 -0
- package/src/components/RichText/components/Leaf/index.tsx +12 -0
- package/src/components/RichText/components/MarkButton/index.tsx +38 -0
- package/src/components/RichText/components/MarkButton/styles.css +41 -0
- package/src/components/RichText/components/Toolbar/index.tsx +12 -0
- package/src/components/RichText/components/Toolbar/styles.css +14 -0
- package/src/components/RichText/defineType.d.ts +38 -0
- package/src/components/RichText/functions/serialize.ts +54 -0
- package/src/components/RichText/functions/toggleBlock.ts +46 -0
- package/src/components/RichText/functions/toggleMark.ts +13 -0
- package/src/components/RichText/helpers/isBlockActive.ts +27 -0
- package/src/components/RichText/helpers/isMarkActive.ts +9 -0
- package/src/components/RichText/index.tsx +131 -0
- package/src/components/RichText/styles.css +25 -0
- package/src/components/RichText/template/HOTKEYS.ts +14 -0
- package/src/components/RichText/template/INITIAL_VALUE.ts +10 -0
- package/src/components/RichText/template/LIST_TYPES.ts +3 -0
- package/src/components/RichText/template/TEXT_ALIGN_TYPES.ts +3 -0
- package/src/index.ts +3 -2
- package/tsconfig.json +8 -0
@@ -0,0 +1,27 @@
|
|
1
|
+
import { Editor } from "slate";
|
2
|
+
import { Element as SlateElement } from "slate";
|
3
|
+
|
4
|
+
import { AlignFormatType, ElementFormatType } from "../defineType";
|
5
|
+
|
6
|
+
function isBlockActive(
|
7
|
+
editor: Editor,
|
8
|
+
format: ElementFormatType | AlignFormatType,
|
9
|
+
blockType: "type" | "align" = "type"
|
10
|
+
) {
|
11
|
+
const { selection } = editor;
|
12
|
+
if (!selection) return false;
|
13
|
+
|
14
|
+
const [match] = Array.from(
|
15
|
+
Editor.nodes(editor, {
|
16
|
+
at: Editor.unhangRange(editor, selection),
|
17
|
+
match: (n) =>
|
18
|
+
!Editor.isEditor(n) &&
|
19
|
+
SlateElement.isElement(n) &&
|
20
|
+
n[blockType] === format,
|
21
|
+
})
|
22
|
+
);
|
23
|
+
|
24
|
+
return !!match;
|
25
|
+
}
|
26
|
+
|
27
|
+
export { isBlockActive };
|
@@ -0,0 +1,9 @@
|
|
1
|
+
import { Editor } from "slate";
|
2
|
+
import { MarkFormatType } from "../defineType";
|
3
|
+
|
4
|
+
function isMarkActive(editor: Editor, format: MarkFormatType) {
|
5
|
+
const marks = Editor.marks(editor);
|
6
|
+
return marks ? marks[format] === true : false;
|
7
|
+
}
|
8
|
+
|
9
|
+
export { isMarkActive };
|
@@ -0,0 +1,131 @@
|
|
1
|
+
import isHotkey from "is-hotkey";
|
2
|
+
import {
|
3
|
+
AlignCenter,
|
4
|
+
AlignJustify,
|
5
|
+
AlignLeft,
|
6
|
+
AlignRight,
|
7
|
+
Bold,
|
8
|
+
Code,
|
9
|
+
Heading1,
|
10
|
+
Heading2,
|
11
|
+
Italic,
|
12
|
+
Quote,
|
13
|
+
Underline,
|
14
|
+
} from "lucide-react";
|
15
|
+
import { useCallback, useMemo, useRef, useState } from "react";
|
16
|
+
import { createEditor, Descendant } from "slate";
|
17
|
+
import { withHistory } from "slate-history";
|
18
|
+
import { Editable, Slate, withReact } from "slate-react";
|
19
|
+
|
20
|
+
import { BlockButton } from "./components/BlockButton/intex";
|
21
|
+
import { Element } from "./components/Element";
|
22
|
+
import { Leaf } from "./components/Leaf";
|
23
|
+
import { MarkButton } from "./components/MarkButton";
|
24
|
+
import { Toolbar } from "./components/Toolbar";
|
25
|
+
import { toggleMark } from "./functions/toggleMark";
|
26
|
+
import { HOTKEYS } from "./template/HOTKEYS";
|
27
|
+
import { INITIAL_VALUE } from "./template/INITIAL_VALUE";
|
28
|
+
|
29
|
+
import "./styles.css";
|
30
|
+
import { useFormController } from "../Form/FormController";
|
31
|
+
|
32
|
+
type RichTextProps = {
|
33
|
+
name: string;
|
34
|
+
defaultValue?: string;
|
35
|
+
isError?: boolean;
|
36
|
+
onChange?: (value: Descendant[]) => void;
|
37
|
+
onValueChange?: (value: string) => void;
|
38
|
+
};
|
39
|
+
|
40
|
+
function RichText({
|
41
|
+
name,
|
42
|
+
defaultValue,
|
43
|
+
onValueChange,
|
44
|
+
onChange,
|
45
|
+
isError: baseIsError,
|
46
|
+
}: RichTextProps) {
|
47
|
+
const [editorValue, setEditorValue] = useState<Descendant[]>([]);
|
48
|
+
const [onFocus, setOnFocus] = useState(false);
|
49
|
+
|
50
|
+
const { id, inputRef, error } = useFormController();
|
51
|
+
|
52
|
+
const baseRef = useRef<HTMLInputElement>(null);
|
53
|
+
|
54
|
+
const ref = inputRef || baseRef;
|
55
|
+
const isError = baseIsError || !!error;
|
56
|
+
|
57
|
+
const editor = useMemo(() => withHistory(withReact(createEditor())), []);
|
58
|
+
|
59
|
+
const renderLeaf = useCallback(Leaf, []);
|
60
|
+
const renderElement = useCallback(Element, []);
|
61
|
+
|
62
|
+
function handleChange(e: Descendant[]) {
|
63
|
+
setEditorValue(e);
|
64
|
+
onChange && onChange(e);
|
65
|
+
onValueChange && onValueChange(JSON.stringify(e));
|
66
|
+
}
|
67
|
+
|
68
|
+
const errorClass = isError ? "errorTrue" : "errorFalse";
|
69
|
+
const focusClass = onFocus ? "focusTrue" : "focusFalse";
|
70
|
+
|
71
|
+
const className = `arkynRichText ${errorClass} ${focusClass}`;
|
72
|
+
|
73
|
+
return (
|
74
|
+
<Slate
|
75
|
+
editor={editor}
|
76
|
+
initialValue={defaultValue ? JSON.parse(defaultValue) : INITIAL_VALUE}
|
77
|
+
onChange={handleChange}
|
78
|
+
onValueChange={handleChange}
|
79
|
+
>
|
80
|
+
<div className={className}>
|
81
|
+
<Toolbar>
|
82
|
+
<BlockButton format="headingOne" icon={Heading1} />
|
83
|
+
<BlockButton format="headingTwo" icon={Heading2} />
|
84
|
+
<BlockButton format="blockQuote" icon={Quote} />
|
85
|
+
{/* <BlockButton format="bulletedList" icon={ListVideo} /> */}
|
86
|
+
{/* <BlockButton format="listItem" icon={List} /> */}
|
87
|
+
{/* <BlockButton format="numberedList" icon={ListOrdered} /> */}
|
88
|
+
|
89
|
+
<MarkButton format="bold" icon={Bold} />
|
90
|
+
<MarkButton format="italic" icon={Italic} />
|
91
|
+
<MarkButton format="underline" icon={Underline} />
|
92
|
+
<MarkButton format="code" icon={Code} />
|
93
|
+
|
94
|
+
<BlockButton format="left" icon={AlignLeft} />
|
95
|
+
<BlockButton format="right" icon={AlignRight} />
|
96
|
+
<BlockButton format="center" icon={AlignCenter} />
|
97
|
+
<BlockButton format="justify" icon={AlignJustify} />
|
98
|
+
</Toolbar>
|
99
|
+
|
100
|
+
<Editable
|
101
|
+
className="editorContainer"
|
102
|
+
renderElement={renderElement}
|
103
|
+
renderLeaf={renderLeaf}
|
104
|
+
spellCheck
|
105
|
+
autoFocus
|
106
|
+
id={id}
|
107
|
+
onFocus={() => setOnFocus(true)}
|
108
|
+
onBlur={() => setOnFocus(false)}
|
109
|
+
onKeyDown={(event) => {
|
110
|
+
for (const hotkey in HOTKEYS) {
|
111
|
+
if (isHotkey(hotkey, event as any)) {
|
112
|
+
event.preventDefault();
|
113
|
+
const mark = HOTKEYS[hotkey as keyof typeof HOTKEYS];
|
114
|
+
toggleMark(editor, mark);
|
115
|
+
}
|
116
|
+
}
|
117
|
+
}}
|
118
|
+
/>
|
119
|
+
</div>
|
120
|
+
|
121
|
+
<input
|
122
|
+
ref={ref}
|
123
|
+
type="hidden"
|
124
|
+
name={name}
|
125
|
+
value={JSON.stringify(editorValue)}
|
126
|
+
/>
|
127
|
+
</Slate>
|
128
|
+
);
|
129
|
+
}
|
130
|
+
|
131
|
+
export { RichText };
|
@@ -0,0 +1,25 @@
|
|
1
|
+
.arkynRichText {
|
2
|
+
display: flex;
|
3
|
+
flex-direction: column;
|
4
|
+
|
5
|
+
background-color: rgba(var(--input-background), 1);
|
6
|
+
border: 1px solid var(--border);
|
7
|
+
border-radius: var(--rounded-inputs);
|
8
|
+
outline: 1px solid transparent;
|
9
|
+
}
|
10
|
+
|
11
|
+
.arkynRichText.errorTrue {
|
12
|
+
outline-color: rgba(var(--spotlight-danger), 1);
|
13
|
+
border-color: rgba(var(--spotlight-danger), 1);
|
14
|
+
}
|
15
|
+
|
16
|
+
.arkynRichText.focusTrue {
|
17
|
+
outline-color: rgba(var(--spotlight-primary), 1);
|
18
|
+
border-color: rgba(var(--spotlight-primary), 1);
|
19
|
+
}
|
20
|
+
|
21
|
+
.arkynRichText .editorContainer {
|
22
|
+
padding: 16px;
|
23
|
+
outline: none;
|
24
|
+
min-height: 300px;
|
25
|
+
}
|
@@ -0,0 +1,14 @@
|
|
1
|
+
import { MarkFormatType } from "../defineType";
|
2
|
+
|
3
|
+
type HotKeys = {
|
4
|
+
[key: string]: MarkFormatType;
|
5
|
+
};
|
6
|
+
|
7
|
+
const HOTKEYS: HotKeys = {
|
8
|
+
"mod+b": "bold",
|
9
|
+
"mod+i": "italic",
|
10
|
+
"mod+u": "underline",
|
11
|
+
"mod+`": "code",
|
12
|
+
};
|
13
|
+
|
14
|
+
export { HOTKEYS };
|
package/src/index.ts
CHANGED
@@ -23,13 +23,14 @@ export {
|
|
23
23
|
export { Button } from "./components/Button";
|
24
24
|
export { Checkbox } from "./components/Checkbox";
|
25
25
|
export { FormController, FormError, FormLabel } from "./components/Form";
|
26
|
+
export { GoogleSearchPlaces } from "./components/GoogleSearchPlaces";
|
26
27
|
export { IconButton } from "./components/IconButton";
|
27
28
|
export { Input } from "./components/Input";
|
28
29
|
export { RadioBox, RadioGroup } from "./components/Radio";
|
30
|
+
export { RichText } from "./components/RichText";
|
29
31
|
export { Select } from "./components/Select";
|
30
32
|
export { Switch } from "./components/Switch";
|
31
33
|
export { Textarea } from "./components/Textarea";
|
32
|
-
export { GoogleSearchPlaces } from "./components/GoogleSearchPlaces";
|
33
34
|
|
34
35
|
// Navigation
|
35
36
|
export { BreadcrumbContainer, BreadcrumbLink } from "./components/Breadcrumb";
|
@@ -51,7 +52,7 @@ export { useScopedParams } from "./hooks/useScopedParams";
|
|
51
52
|
export { useToast } from "./hooks/useToast";
|
52
53
|
|
53
54
|
// Providers
|
54
|
-
export { GoogleProvider } from "./provider/GoogleProvider";
|
55
55
|
export { DrawerProvider } from "./provider/DrawerProvider";
|
56
|
+
export { GoogleProvider } from "./provider/GoogleProvider";
|
56
57
|
export { ModalProvider } from "./provider/ModalProvider";
|
57
58
|
export { ToastProvider } from "./provider/ToastProvider";
|
package/tsconfig.json
CHANGED