@arkyn/components 1.3.109 → 1.3.110

Sign up to get free protection for your applications and to get access to all the features.
Files changed (75) hide show
  1. package/dist/bundle.js +12318 -4286
  2. package/dist/bundle.umd.cjs +38 -23
  3. package/dist/components/RichText/components/BlockButton/intex.d.ts +10 -0
  4. package/dist/components/RichText/components/BlockButton/intex.d.ts.map +1 -0
  5. package/dist/components/RichText/components/BlockButton/intex.js +18 -0
  6. package/dist/components/RichText/components/Element/index.d.ts +5 -0
  7. package/dist/components/RichText/components/Element/index.d.ts.map +1 -0
  8. package/dist/components/RichText/components/Element/index.js +22 -0
  9. package/dist/components/RichText/components/Leaf/index.d.ts +3 -0
  10. package/dist/components/RichText/components/Leaf/index.d.ts.map +1 -0
  11. package/dist/components/RichText/components/Leaf/index.js +14 -0
  12. package/dist/components/RichText/components/MarkButton/index.d.ts +10 -0
  13. package/dist/components/RichText/components/MarkButton/index.d.ts.map +1 -0
  14. package/dist/components/RichText/components/MarkButton/index.js +16 -0
  15. package/dist/components/RichText/components/Toolbar/index.d.ts +8 -0
  16. package/dist/components/RichText/components/Toolbar/index.d.ts.map +1 -0
  17. package/dist/components/RichText/components/Toolbar/index.js +6 -0
  18. package/dist/components/RichText/functions/serialize.d.ts +3 -0
  19. package/dist/components/RichText/functions/serialize.d.ts.map +1 -0
  20. package/dist/components/RichText/functions/serialize.js +48 -0
  21. package/dist/components/RichText/functions/toggleBlock.d.ts +5 -0
  22. package/dist/components/RichText/functions/toggleBlock.d.ts.map +1 -0
  23. package/dist/components/RichText/functions/toggleBlock.js +33 -0
  24. package/dist/components/RichText/functions/toggleMark.d.ts +5 -0
  25. package/dist/components/RichText/functions/toggleMark.d.ts.map +1 -0
  26. package/dist/components/RichText/functions/toggleMark.js +10 -0
  27. package/dist/components/RichText/helpers/isBlockActive.d.ts +5 -0
  28. package/dist/components/RichText/helpers/isBlockActive.d.ts.map +1 -0
  29. package/dist/components/RichText/helpers/isBlockActive.js +15 -0
  30. package/dist/components/RichText/helpers/isMarkActive.d.ts +5 -0
  31. package/dist/components/RichText/helpers/isMarkActive.d.ts.map +1 -0
  32. package/dist/components/RichText/helpers/isMarkActive.js +6 -0
  33. package/dist/components/RichText/index.d.ts +12 -0
  34. package/dist/components/RichText/index.d.ts.map +1 -0
  35. package/dist/components/RichText/index.js +46 -0
  36. package/dist/components/RichText/template/HOTKEYS.d.ts +7 -0
  37. package/dist/components/RichText/template/HOTKEYS.d.ts.map +1 -0
  38. package/dist/components/RichText/template/HOTKEYS.js +7 -0
  39. package/dist/components/RichText/template/INITIAL_VALUE.d.ts +4 -0
  40. package/dist/components/RichText/template/INITIAL_VALUE.d.ts.map +1 -0
  41. package/dist/components/RichText/template/INITIAL_VALUE.js +7 -0
  42. package/dist/components/RichText/template/LIST_TYPES.d.ts +3 -0
  43. package/dist/components/RichText/template/LIST_TYPES.d.ts.map +1 -0
  44. package/dist/components/RichText/template/LIST_TYPES.js +2 -0
  45. package/dist/components/RichText/template/TEXT_ALIGN_TYPES.d.ts +3 -0
  46. package/dist/components/RichText/template/TEXT_ALIGN_TYPES.d.ts.map +1 -0
  47. package/dist/components/RichText/template/TEXT_ALIGN_TYPES.js +2 -0
  48. package/dist/index.d.ts +3 -2
  49. package/dist/index.d.ts.map +1 -1
  50. package/dist/index.js +3 -2
  51. package/dist/style.css +1 -1
  52. package/package.json +5 -1
  53. package/src/components/RichText/components/BlockButton/intex.tsx +41 -0
  54. package/src/components/RichText/components/BlockButton/styles.css +29 -0
  55. package/src/components/RichText/components/Element/index.tsx +57 -0
  56. package/src/components/RichText/components/Element/styles.css +23 -0
  57. package/src/components/RichText/components/Leaf/index.tsx +12 -0
  58. package/src/components/RichText/components/MarkButton/index.tsx +38 -0
  59. package/src/components/RichText/components/MarkButton/styles.css +41 -0
  60. package/src/components/RichText/components/Toolbar/index.tsx +12 -0
  61. package/src/components/RichText/components/Toolbar/styles.css +14 -0
  62. package/src/components/RichText/defineType.d.ts +38 -0
  63. package/src/components/RichText/functions/serialize.ts +54 -0
  64. package/src/components/RichText/functions/toggleBlock.ts +46 -0
  65. package/src/components/RichText/functions/toggleMark.ts +13 -0
  66. package/src/components/RichText/helpers/isBlockActive.ts +27 -0
  67. package/src/components/RichText/helpers/isMarkActive.ts +9 -0
  68. package/src/components/RichText/index.tsx +131 -0
  69. package/src/components/RichText/styles.css +25 -0
  70. package/src/components/RichText/template/HOTKEYS.ts +14 -0
  71. package/src/components/RichText/template/INITIAL_VALUE.ts +10 -0
  72. package/src/components/RichText/template/LIST_TYPES.ts +3 -0
  73. package/src/components/RichText/template/TEXT_ALIGN_TYPES.ts +3 -0
  74. package/src/index.ts +3 -2
  75. package/tsconfig.json +8 -0
@@ -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 };
@@ -0,0 +1,10 @@
1
+ import { Descendant } from "slate";
2
+
3
+ const INITIAL_VALUE: Descendant[] = [
4
+ {
5
+ type: "paragraph",
6
+ children: [{ text: "" }],
7
+ },
8
+ ];
9
+
10
+ export { INITIAL_VALUE };
@@ -0,0 +1,3 @@
1
+ const LIST_TYPES = ["listItem", "numberedList"];
2
+
3
+ export { LIST_TYPES };
@@ -0,0 +1,3 @@
1
+ const TEXT_ALIGN_TYPES = ["left", "center", "right", "justify"];
2
+
3
+ export { TEXT_ALIGN_TYPES };
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
@@ -1,4 +1,12 @@
1
1
  {
2
+ "include": [
3
+ "**/*.ts",
4
+ "**/*.tsx",
5
+ "**/.server/**/*.ts",
6
+ "**/.server/**/*.tsx",
7
+ "**/.client/**/*.ts",
8
+ "**/.client/**/*.tsx"
9
+ ],
2
10
  "exclude": ["node_modules", "dist"],
3
11
  "compilerOptions": {
4
12
  "outDir": "./dist",