l-min-components 1.0.1098 → 1.0.1106

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "l-min-components",
3
- "version": "1.0.1098",
3
+ "version": "1.0.1106",
4
4
  "type": "module",
5
5
  "files": [
6
6
  "src/assets",
@@ -20,6 +20,7 @@
20
20
  "classnames": "^2.3.2",
21
21
  "dexie": "^4.0.8",
22
22
  "dexie-react-hooks": "^1.1.7",
23
+ "draft-convert": "^2.1.13",
23
24
  "draft-js": "^0.11.7",
24
25
  "draftjs-to-html": "^0.9.1",
25
26
  "emoji-picker-react": "^4.12.0",
@@ -1,34 +1,9 @@
1
1
  import React from "react";
2
2
  import { CirclePicker } from "react-color";
3
3
  import styled from "styled-components";
4
+ import { editorColors } from "./toalbarOptions";
4
5
 
5
6
  const ColorModal = ({ onChange, color }) => {
6
- const editorColors = [
7
- "#000000", // Black
8
- "#FFFFFF", // White
9
- "#F44336", // Red
10
- "#E91E63", // Pink
11
- "#9C27B0", // Purple
12
- "#3F51B5", // Indigo
13
- "#2196F3", // Blue
14
- "#03A9F4", // Light Blue
15
- "#00BCD4", // Cyan
16
- "#009688", // Teal
17
- "#4CAF50", // Green
18
- "#8BC34A", // Light Green
19
- "#CDDC39", // Lime
20
- "#FFEB3B", // Yellow
21
- "#FFC107", // Amber
22
- "#FF9800", // Orange
23
- "#FF5722", // Deep Orange
24
- "#795548", // Brown
25
- "#808080", // Grey
26
- "#FFB6C1", // Light Pink
27
- "#ADD8E6", // Light Blue
28
- "#90EE90", // Light Green
29
- "#FFD700", // Gold
30
- "#FF4500", // Orange Red
31
- ];
32
7
  return (
33
8
  <Container>
34
9
  <CirclePicker colors={editorColors} onChange={onChange} color={color} />
@@ -1,50 +1,33 @@
1
1
  import React, { useEffect, useState } from "react";
2
2
  import { Editor } from "react-draft-wysiwyg";
3
- import {
4
- EditorState,
5
- convertToRaw,
6
- ContentState,
7
- convertFromHTML,
8
- } from "draft-js";
3
+ import { EditorState, convertToRaw } from "draft-js";
9
4
  import "react-draft-wysiwyg/dist/react-draft-wysiwyg.css";
10
- import toalbarOptions from "./toalbarOptions";
5
+ import toalbarOptions, {
6
+ editorStateToHtml,
7
+ htmlToEditorState,
8
+ } from "./toalbarOptions";
11
9
  import { Container } from "./styled";
12
- import draftToHtml from "draftjs-to-html";
13
- // import htmlToDraft from "html-to-draftjs";
14
10
 
15
11
  function TextEditor({ onChange, defaultValue }) {
16
- let defaultState;
17
-
18
- if (defaultValue) {
19
- const contentBlock = convertFromHTML(defaultValue);
20
- if (contentBlock) {
21
- const contentState = ContentState?.createFromBlockArray(
22
- contentBlock?.contentBlocks,
23
- contentBlock?.entityMap
24
- );
25
- defaultState = EditorState?.createWithContent(contentState);
26
- }
27
- }
28
-
29
12
  const [editorState, setEditorState] = useState(
30
- defaultState || EditorState.createEmpty()
13
+ defaultValue ? htmlToEditorState(defaultValue) : EditorState.createEmpty()
31
14
  );
32
15
 
33
- const onEditorStateChange = (newState) => {
34
- setEditorState(newState);
35
- };
16
+ // draft data (has blocks)
17
+ const rawState = convertToRaw(editorState.getCurrentContent());
36
18
 
37
19
  useEffect(() => {
38
- const html = draftToHtml(convertToRaw(editorState?.getCurrentContent()));
39
- onChange && onChange(html);
40
- }, [editorState]);
20
+ onChange(editorStateToHtml(editorState));
21
+ }, [rawState]);
41
22
 
42
23
  return (
43
24
  <Container>
44
25
  <Editor
45
- toolbar={toalbarOptions}
46
26
  editorState={editorState}
47
- onEditorStateChange={onEditorStateChange}
27
+ toolbar={toalbarOptions}
28
+ // onContentStateChange={onContentStateChange}
29
+ onEditorStateChange={setEditorState}
30
+ // customStyleMap={styleMap}
48
31
  />
49
32
  </Container>
50
33
  );
@@ -1,8 +1,128 @@
1
1
  import { Inline, List, TextAlign, Colors, Emoji, Fontsize } from "./tools";
2
+ import { convertFromHTML, convertToHTML } from "draft-convert";
3
+ import { EditorState } from "draft-js";
2
4
 
3
5
  export const fontSizes = [
4
6
  8, 9, 10, 11, 12, 14, 16, 18, 24, 30, 36, 48, 60, 72, 96,
5
7
  ];
8
+
9
+ export const editorColors = [
10
+ "#000000", // Black
11
+ "#FFFFFF", // White
12
+ "#F44336", // Red
13
+ "#E91E63", // Pink
14
+ "#9C27B0", // Purple
15
+ "#3F51B5", // Indigo
16
+ "#2196F3", // Blue
17
+ "#03A9F4", // Light Blue
18
+ "#00BCD4", // Cyan
19
+ "#009688", // Teal
20
+ "#4CAF50", // Green
21
+ "#8BC34A", // Light Green
22
+ "#CDDC39", // Lime
23
+ "#FFEB3B", // Yellow
24
+ "#FFC107", // Amber
25
+ "#FF9800", // Orange
26
+ "#FF5722", // Deep Orange
27
+ "#795548", // Brown
28
+ "#808080", // Grey
29
+ "#FFB6C1", // Light Pink
30
+ "#ADD8E6", // Light Blue
31
+ "#90EE90", // Light Green
32
+ "#FFD700", // Gold
33
+ "#FF4500", // Orange Red
34
+ ];
35
+
36
+ const alignments = ["LEFT", "CENTER", "RIGHT"]; // Supported alignments
37
+
38
+ // Dynamically generate alignment styles
39
+ const generateAlignmentStyles = () => {
40
+ return alignments.reduce((acc, align) => {
41
+ acc[`TEXTALIGN-${align}`] = { textAlign: align.toLowerCase() };
42
+ return acc;
43
+ }, {});
44
+ };
45
+
46
+ const generateFontSizeStyles = () => {
47
+ return fontSizes.reduce((acc, size) => {
48
+ acc[`FONTSIZE-${size}`] = { fontSize: `${size}px` };
49
+ return acc;
50
+ }, {});
51
+ };
52
+
53
+ const generateColorStyles = () => {
54
+ return editorColors.reduce((acc, color) => {
55
+ acc[`COLOR-${color}`] = { color };
56
+ return acc;
57
+ }, {});
58
+ };
59
+
60
+ export const styleMap = {
61
+ ...generateFontSizeStyles(),
62
+ // ...generateColorStyles(),
63
+ ...generateAlignmentStyles(),
64
+ };
65
+
66
+ export const htmlToEditorState = (html) => {
67
+ const customHTML = convertFromHTML({
68
+ htmlToStyle: (nodeName, node, currentStyle) => {
69
+ if (nodeName === "span" && node.style.fontSize) {
70
+ const fontSize = parseInt(node.style.fontSize, 10);
71
+ return currentStyle.add(`fontsize-${fontSize}`);
72
+ }
73
+
74
+ return currentStyle;
75
+ },
76
+
77
+ htmlToBlock: (nodeName, node) => {
78
+ const align = node.style.textAlign;
79
+
80
+ if ((nodeName === "p" || nodeName === "li") && align) {
81
+ return {
82
+ type: nodeName === "p" ? "PARAGRAPH" : "unordered-list-item",
83
+ data: { "text-align": align },
84
+ };
85
+ }
86
+ return null; // Default behavior for other blocks
87
+ },
88
+
89
+ htmlToEntity: (nodeName, node, createEntity) => null,
90
+ });
91
+
92
+ const contentState = customHTML(html);
93
+ return EditorState.createWithContent(contentState);
94
+ };
95
+
96
+ export const editorStateToHtml = (editorState) => {
97
+ return convertToHTML({
98
+ styleToHTML: (style) => {
99
+ if (style.includes("fontsize")) {
100
+ const size = style.split("-")[1] + "px";
101
+ return <span style={{ fontSize: size }} />;
102
+ }
103
+ },
104
+ blockToHTML: (block) => {
105
+ const textAlign = block.data["text-align"];
106
+
107
+ if (block.type === "PARAGRAPH") {
108
+ if (textAlign) {
109
+ return <p style={{ textAlign: textAlign }} />;
110
+ }
111
+ return <p />;
112
+ }
113
+ if (block.type === "unstyled") {
114
+ if (block.data["text-align"]) {
115
+ return <p style={{ textAlign: textAlign }} />;
116
+ }
117
+ }
118
+ if (block.type === "unordered-list-item") {
119
+ if (block.data["text-align"]) {
120
+ return <li style={{ textAlign: textAlign }} />;
121
+ }
122
+ }
123
+ },
124
+ })(editorState.getCurrentContent());
125
+ };
6
126
  export default {
7
127
  options: ["emoji", "colorPicker", "fontSize", "inline", "textAlign", "list"],
8
128
  inline: {
@@ -2,11 +2,10 @@ import React, { useState, useEffect, useRef } from "react";
2
2
  import { MobileLayoutContainer } from "./index.styled";
3
3
  // import BackArrow from "./assets/svg/backArrow";
4
4
  import img from "./assets/images/bg_img.png";
5
- import play from "./assets/svg/playstore.svg";
6
- import apple from "./assets/svg/apple.svg";
5
+ // import play from "./assets/svg/playstore.svg";
6
+ // import apple from "./assets/svg/apple.svg";
7
7
 
8
8
  const MobileLayout = (props) => {
9
-
10
9
  return (
11
10
  <MobileLayoutContainer>
12
11
  <div className="mlc_header">
@@ -20,20 +19,25 @@ const MobileLayout = (props) => {
20
19
 
21
20
  <div className="mlc_note_container">
22
21
  <p className="mlc_note_title">
23
- {props?.findText("Sorry, you can’t access your account on a mobile browser.")}
22
+ {props?.findText(
23
+ "Sorry, you can’t access your account on a mobile browser."
24
+ )}
24
25
  </p>
25
26
  <p className="mlc_note_subtitle">
26
- {props?.findText("We know it's inconvenient. For better user accessibility, login with a desktop device or via our mobile app.")}
27
+ {props?.findText(
28
+ "We know it's inconvenient. For better user accessibility, login with a desktop device."
29
+ )}
30
+ {/* or via our mobile app */}
27
31
  </p>
28
32
 
29
- <div className="mlc_link_section">
33
+ {/* <div className="mlc_link_section">
30
34
  <a href="#">
31
35
  <img src={play} alt="play store" /> {props?.findText("Download on google play")}
32
36
  </a>
33
37
  <a href="#">
34
38
  <img src={apple} alt="apple store" /> {props?.findText("Download on apple store")}
35
39
  </a>
36
- </div>
40
+ </div> */}
37
41
  </div>
38
42
  </MobileLayoutContainer>
39
43
  );