@arkyn/components 3.0.1-beta.27 → 3.0.1-beta.29

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.
@@ -0,0 +1,41 @@
1
+ type RichTextHiddenButtonKey = "headingOne" | "headingTwo" | "blockQuote" | "bold" | "italic" | "underline" | "code" | "left" | "right" | "center" | "justify" | "image";
2
+ type RichTextElementFormatType = "blockQuote" | "bulletedList" | "headingOne" | "headingTwo" | "listItem" | "numberedList" | "paragraph" | "image";
3
+ type RichTextAlignFormatType = "center" | "left" | "right" | "justify";
4
+ type RichTextMarkFormatType = "bold" | "italic" | "underline" | "code";
5
+ type RichTextInsertImageProps = {
6
+ action: string;
7
+ tabLabels?: [string, string];
8
+ modalTitle?: string;
9
+ modalInputUrlLabel?: string;
10
+ modalInputImageLabel?: string;
11
+ modalCancelButton?: string;
12
+ modalConfirmButton?: string;
13
+ };
14
+ type RichTextCustomElement = {
15
+ type: RichTextElementFormatType;
16
+ align?: RichTextAlignFormatType;
17
+ src?: string;
18
+ children?: RichTextValue;
19
+ };
20
+ type RichTextCustomText = {
21
+ bold?: boolean;
22
+ text: string;
23
+ italic?: boolean;
24
+ code?: boolean;
25
+ underline?: boolean;
26
+ };
27
+ type Descendant = RichTextCustomElement | RichTextCustomText;
28
+ type RichTextProps = {
29
+ name: string;
30
+ hiddenButtons?: RichTextHiddenButtonKey[];
31
+ maxLimit?: number;
32
+ enforceCharacterLimit?: boolean;
33
+ defaultValue?: string;
34
+ isError?: boolean;
35
+ imageConfig?: RichTextInsertImageProps;
36
+ onChangeCharactersCount?: (e: number) => void;
37
+ onChange?: (value: Descendant[]) => void;
38
+ };
39
+ type RichTextValue = Descendant[];
40
+ export type { Descendant, RichTextAlignFormatType, RichTextCustomElement, RichTextCustomText, RichTextElementFormatType, RichTextHiddenButtonKey, RichTextInsertImageProps, RichTextMarkFormatType, RichTextProps, RichTextValue, };
41
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 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,CAAC;AAEF,KAAK,UAAU,GAAG,qBAAqB,GAAG,kBAAkB,CAAC;AAE7D,KAAK,aAAa,GAAG;IACnB,IAAI,EAAE,MAAM,CAAC;IACb,aAAa,CAAC,EAAE,uBAAuB,EAAE,CAAC;IAC1C,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,qBAAqB,CAAC,EAAE,OAAO,CAAC;IAChC,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,WAAW,CAAC,EAAE,wBAAwB,CAAC;IACvC,uBAAuB,CAAC,EAAE,CAAC,CAAC,EAAE,MAAM,KAAK,IAAI,CAAC;IAC9C,QAAQ,CAAC,EAAE,CAAC,KAAK,EAAE,UAAU,EAAE,KAAK,IAAI,CAAC;CAC1C,CAAC;AAEF,KAAK,aAAa,GAAG,UAAU,EAAE,CAAC;AAElC,YAAY,EACV,UAAU,EACV,uBAAuB,EACvB,qBAAqB,EACrB,kBAAkB,EAClB,yBAAyB,EACzB,uBAAuB,EACvB,wBAAwB,EACxB,sBAAsB,EACtB,aAAa,EACb,aAAa,GACd,CAAC"}
@@ -0,0 +1 @@
1
+ export {};
package/dist/index.d.ts CHANGED
@@ -53,4 +53,6 @@ export { DrawerProvider } from "./providers/drawerProvider";
53
53
  export { FormProvider } from "./providers/formProvider";
54
54
  export { ModalProvider } from "./providers/modalProvider";
55
55
  export { ToastProvider } from "./providers/toastProvider";
56
+ export { toHtml } from "./services/toHtml";
57
+ export { toRichTextValue } from "./services/toRichTextValue";
56
58
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,cAAc,EAAE,MAAM,mCAAmC,CAAC;AACnE,OAAO,EAAE,YAAY,EAAE,MAAM,iCAAiC,CAAC;AAC/D,OAAO,EAAE,gBAAgB,EAAE,MAAM,qCAAqC,CAAC;AACvE,OAAO,EAA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EAAE,OAAO,EAAE,MAAM,sBAAsB,CAAC;AAG/C,OAAO,EAAE,SAAS,EAAE,MAAM,mBAAmB,CAAC;AAC9C,OAAO,EAAE,OAAO,EAAE,MAAM,iBAAiB,CAAC;AAC1C,OAAO,EAAE,WAAW,EAAE,MAAM,qBAAqB,CAAC;AAClD,OAAO,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AAC5C,OAAO,EAAE,eAAe,EAAE,MAAM,yBAAyB,CAAC;AAC1D,OAAO,EAAE,aAAa,EAAE,MAAM,uBAAuB,CAAC;AACtD,OAAO,EAAE,SAAS,EAAE,MAAM,mBAAmB,CAAC;AAG9C,OAAO,EAAE,cAAc,EAAE,MAAM,4BAA4B,CAAC;AAC5D,OAAO,EAAE,YAAY,EAAE,MAAM,0BAA0B,CAAC;AACxD,OAAO,EAAE,aAAa,EAAE,MAAM,2BAA2B,CAAC;AAC1D,OAAO,EAAE,aAAa,EAAE,MAAM,2BAA2B,CAAC;AAG1D,OAAO,EAAE,MAAM,EAAE,MAAM,mBAAmB,CAAC;AAC3C,OAAO,EAAE,eAAe,EAAE,MAAM,4BAA4B,CAAC"}
package/dist/index.js CHANGED
@@ -56,3 +56,6 @@ export { DrawerProvider } from "./providers/drawerProvider";
56
56
  export { FormProvider } from "./providers/formProvider";
57
57
  export { ModalProvider } from "./providers/modalProvider";
58
58
  export { ToastProvider } from "./providers/toastProvider";
59
+ // services
60
+ export { toHtml } from "./services/toHtml";
61
+ export { toRichTextValue } from "./services/toRichTextValue";
@@ -0,0 +1,20 @@
1
+ import { RichTextValue } from "../types/richTextTypes";
2
+ /**
3
+ * Converts a RichTextValue array to HTML string format.
4
+ *
5
+ * @param {RichTextValue} richTextValue - Array of Descendant objects representing rich text content
6
+ * @returns {string} HTML string representation of the rich text content
7
+ *
8
+ * @example
9
+ * ```typescript
10
+ * const richTextService = new RichTextService();
11
+ * const richText = [
12
+ * { type: 'paragraph', children: [{ text: 'Hello world', bold: true }] }
13
+ * ];
14
+ * const html = richTextService.toHtml(richText);
15
+ * // Returns: "<p><strong>Hello world</strong></p>"
16
+ * ```
17
+ */
18
+ declare function toHtml(richTextValue: RichTextValue): string;
19
+ export { toHtml };
20
+ //# sourceMappingURL=toHtml.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"toHtml.d.ts","sourceRoot":"","sources":["../../src/services/toHtml.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,wBAAwB,CAAC;AAGvD;;;;;;;;;;;;;;;GAeG;AAEH,iBAAS,MAAM,CAAC,aAAa,EAAE,aAAa,UAE3C;AAED,OAAO,EAAE,MAAM,EAAE,CAAC"}
@@ -0,0 +1,21 @@
1
+ import { serialize } from "../utils/richTextUtilities";
2
+ /**
3
+ * Converts a RichTextValue array to HTML string format.
4
+ *
5
+ * @param {RichTextValue} richTextValue - Array of Descendant objects representing rich text content
6
+ * @returns {string} HTML string representation of the rich text content
7
+ *
8
+ * @example
9
+ * ```typescript
10
+ * const richTextService = new RichTextService();
11
+ * const richText = [
12
+ * { type: 'paragraph', children: [{ text: 'Hello world', bold: true }] }
13
+ * ];
14
+ * const html = richTextService.toHtml(richText);
15
+ * // Returns: "<p><strong>Hello world</strong></p>"
16
+ * ```
17
+ */
18
+ function toHtml(richTextValue) {
19
+ return richTextValue.map((node) => serialize(node)).join("");
20
+ }
21
+ export { toHtml };
@@ -0,0 +1,28 @@
1
+ import { RichTextValue } from "../types/richTextTypes";
2
+ /**
3
+ * Converts an HTML string to RichTextValue format.
4
+ * Parses the HTML content and transforms it into an array of Descendant objects
5
+ * that can be used by the rich text editor.
6
+ *
7
+ * @param {string} html - HTML string to be converted to rich text format
8
+ * @returns {RichTextValue} Array of Descendant objects representing the parsed content
9
+ *
10
+ * @example
11
+ * ```typescript
12
+ * const richTextService = new RichTextService();
13
+ * const html = "<p><strong>Hello world</strong></p>";
14
+ * const richText = richTextService.toRichTextValue(html);
15
+ * // Returns: [{ type: 'paragraph', children: [{ text: 'Hello world', bold: true }] }]
16
+ * ```
17
+ *
18
+ * @example
19
+ * ```typescript
20
+ * // Handling plain text
21
+ * const plainText = "Simple text";
22
+ * const richText = richTextService.toRichTextValue(plainText);
23
+ * // Returns: [{ text: 'Simple text' }]
24
+ * ```
25
+ */
26
+ declare function toRichTextValue(html: string): RichTextValue;
27
+ export { toRichTextValue };
28
+ //# sourceMappingURL=toRichTextValue.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"toRichTextValue.d.ts","sourceRoot":"","sources":["../../src/services/toRichTextValue.ts"],"names":[],"mappings":"AAEA,OAAO,EAAgB,aAAa,EAAE,MAAM,wBAAwB,CAAC;AAGrE;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AAEH,iBAAS,eAAe,CAAC,IAAI,EAAE,MAAM,GAAG,aAAa,CAYpD;AAED,OAAO,EAAE,eAAe,EAAE,CAAC"}
@@ -0,0 +1,40 @@
1
+ import parse from "html-react-parser";
2
+ import { deserialize } from "../utils/richTextUtilities";
3
+ /**
4
+ * Converts an HTML string to RichTextValue format.
5
+ * Parses the HTML content and transforms it into an array of Descendant objects
6
+ * that can be used by the rich text editor.
7
+ *
8
+ * @param {string} html - HTML string to be converted to rich text format
9
+ * @returns {RichTextValue} Array of Descendant objects representing the parsed content
10
+ *
11
+ * @example
12
+ * ```typescript
13
+ * const richTextService = new RichTextService();
14
+ * const html = "<p><strong>Hello world</strong></p>";
15
+ * const richText = richTextService.toRichTextValue(html);
16
+ * // Returns: [{ type: 'paragraph', children: [{ text: 'Hello world', bold: true }] }]
17
+ * ```
18
+ *
19
+ * @example
20
+ * ```typescript
21
+ * // Handling plain text
22
+ * const plainText = "Simple text";
23
+ * const richText = richTextService.toRichTextValue(plainText);
24
+ * // Returns: [{ text: 'Simple text' }]
25
+ * ```
26
+ */
27
+ function toRichTextValue(html) {
28
+ const parsed = parse(html);
29
+ if (Array.isArray(parsed)) {
30
+ return parsed.map((node) => {
31
+ if (typeof node === "string")
32
+ return { text: node };
33
+ return deserialize(node);
34
+ });
35
+ }
36
+ if (typeof parsed === "string")
37
+ return [{ text: parsed }];
38
+ return [deserialize(parsed)];
39
+ }
40
+ export { toRichTextValue };
@@ -0,0 +1,49 @@
1
+ type RichTextHiddenButtonKey = "headingOne" | "headingTwo" | "blockQuote" | "bold" | "italic" | "underline" | "code" | "left" | "right" | "center" | "justify" | "image";
2
+ type RichTextElementFormatType = "blockQuote" | "bulletedList" | "headingOne" | "headingTwo" | "listItem" | "numberedList" | "paragraph" | "image";
3
+ type RichTextAlignFormatType = "center" | "left" | "right" | "justify";
4
+ type RichTextMarkFormatType = "bold" | "italic" | "underline" | "code";
5
+ type RichTextInsertImageProps = {
6
+ action: string;
7
+ tabLabels?: [string, string];
8
+ modalTitle?: string;
9
+ modalInputUrlLabel?: string;
10
+ modalInputImageLabel?: string;
11
+ modalCancelButton?: string;
12
+ modalConfirmButton?: string;
13
+ };
14
+ type RichTextCustomElement = {
15
+ type: RichTextElementFormatType;
16
+ align?: RichTextAlignFormatType;
17
+ src?: string;
18
+ children?: RichTextValue;
19
+ };
20
+ type RichTextCustomText = {
21
+ bold?: boolean;
22
+ text: string;
23
+ italic?: boolean;
24
+ code?: boolean;
25
+ underline?: boolean;
26
+ };
27
+ type Descendant = RichTextCustomElement | RichTextCustomText;
28
+ type RichTextProps = {
29
+ name: string;
30
+ hiddenButtons?: RichTextHiddenButtonKey[];
31
+ maxLimit?: number;
32
+ enforceCharacterLimit?: boolean;
33
+ defaultValue?: string;
34
+ isError?: boolean;
35
+ imageConfig?: RichTextInsertImageProps;
36
+ onChangeCharactersCount?: (e: number) => void;
37
+ onChange?: (value: Descendant[]) => void;
38
+ };
39
+ type RichTextValue = Descendant[];
40
+ type ParseElement = {
41
+ type: string;
42
+ props: {
43
+ src?: string;
44
+ children: ParseElement[] | string;
45
+ className?: string;
46
+ };
47
+ };
48
+ export type { Descendant, ParseElement, RichTextAlignFormatType, RichTextCustomElement, RichTextCustomText, RichTextElementFormatType, RichTextHiddenButtonKey, RichTextInsertImageProps, RichTextMarkFormatType, RichTextProps, RichTextValue, };
49
+ //# sourceMappingURL=richTextTypes.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"richTextTypes.d.ts","sourceRoot":"","sources":["../../src/types/richTextTypes.ts"],"names":[],"mappings":"AAAA,KAAK,uBAAuB,GACxB,YAAY,GACZ,YAAY,GACZ,YAAY,GACZ,MAAM,GACN,QAAQ,GACR,WAAW,GACX,MAAM,GACN,MAAM,GACN,OAAO,GACP,QAAQ,GACR,SAAS,GACT,OAAO,CAAC;AAEZ,KAAK,yBAAyB,GAC1B,YAAY,GACZ,cAAc,GACd,YAAY,GACZ,YAAY,GACZ,UAAU,GACV,cAAc,GACd,WAAW,GACX,OAAO,CAAC;AAEZ,KAAK,uBAAuB,GAAG,QAAQ,GAAG,MAAM,GAAG,OAAO,GAAG,SAAS,CAAC;AAEvE,KAAK,sBAAsB,GAAG,MAAM,GAAG,QAAQ,GAAG,WAAW,GAAG,MAAM,CAAC;AAEvE,KAAK,wBAAwB,GAAG;IAC9B,MAAM,EAAE,MAAM,CAAC;IACf,SAAS,CAAC,EAAE,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAC7B,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,kBAAkB,CAAC,EAAE,MAAM,CAAC;IAC5B,oBAAoB,CAAC,EAAE,MAAM,CAAC;IAC9B,iBAAiB,CAAC,EAAE,MAAM,CAAC;IAC3B,kBAAkB,CAAC,EAAE,MAAM,CAAC;CAC7B,CAAC;AAEF,KAAK,qBAAqB,GAAG;IAC3B,IAAI,EAAE,yBAAyB,CAAC;IAChC,KAAK,CAAC,EAAE,uBAAuB,CAAC;IAChC,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,QAAQ,CAAC,EAAE,aAAa,CAAC;CAC1B,CAAC;AAEF,KAAK,kBAAkB,GAAG;IACxB,IAAI,CAAC,EAAE,OAAO,CAAC;IACf,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,CAAC,EAAE,OAAO,CAAC;IACjB,IAAI,CAAC,EAAE,OAAO,CAAC;IACf,SAAS,CAAC,EAAE,OAAO,CAAC;CACrB,CAAC;AAEF,KAAK,UAAU,GAAG,qBAAqB,GAAG,kBAAkB,CAAC;AAE7D,KAAK,aAAa,GAAG;IACnB,IAAI,EAAE,MAAM,CAAC;IACb,aAAa,CAAC,EAAE,uBAAuB,EAAE,CAAC;IAC1C,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,qBAAqB,CAAC,EAAE,OAAO,CAAC;IAChC,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,WAAW,CAAC,EAAE,wBAAwB,CAAC;IACvC,uBAAuB,CAAC,EAAE,CAAC,CAAC,EAAE,MAAM,KAAK,IAAI,CAAC;IAC9C,QAAQ,CAAC,EAAE,CAAC,KAAK,EAAE,UAAU,EAAE,KAAK,IAAI,CAAC;CAC1C,CAAC;AAEF,KAAK,aAAa,GAAG,UAAU,EAAE,CAAC;AAElC,KAAK,YAAY,GAAG;IAClB,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,EAAE;QACL,GAAG,CAAC,EAAE,MAAM,CAAC;QACb,QAAQ,EAAE,YAAY,EAAE,GAAG,MAAM,CAAC;QAClC,SAAS,CAAC,EAAE,MAAM,CAAC;KACpB,CAAC;CACH,CAAC;AAEF,YAAY,EACV,UAAU,EACV,YAAY,EACZ,uBAAuB,EACvB,qBAAqB,EACrB,kBAAkB,EAClB,yBAAyB,EACzB,uBAAuB,EACvB,wBAAwB,EACxB,sBAAsB,EACtB,aAAa,EACb,aAAa,GACd,CAAC"}
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,5 @@
1
+ import { ParseElement } from "../types/richTextTypes";
2
+ declare function serialize(node: any): string;
3
+ declare function deserialize(el: ParseElement): any;
4
+ export { deserialize, serialize };
5
+ //# sourceMappingURL=richTextUtilities.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"richTextUtilities.d.ts","sourceRoot":"","sources":["../../src/utils/richTextUtilities.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,YAAY,EAAE,MAAM,wBAAwB,CAAC;AAEtD,iBAAS,SAAS,CAAC,IAAI,EAAE,GAAG,GAAG,MAAM,CA6CpC;AAED,iBAAS,WAAW,CAAC,EAAE,EAAE,YAAY,GAAG,GAAG,CAgD1C;AAED,OAAO,EAAE,WAAW,EAAE,SAAS,EAAE,CAAC"}
@@ -0,0 +1,87 @@
1
+ import { Element, Text } from "slate";
2
+ function serialize(node) {
3
+ if (Text.isText(node)) {
4
+ let text = node?.text;
5
+ if (node?.bold) {
6
+ text = `<strong>${text}</strong>`;
7
+ }
8
+ if (node?.code) {
9
+ text = `<code>${text}</code>`;
10
+ }
11
+ if (node?.italic) {
12
+ text = `<em>${text}</em>`;
13
+ }
14
+ if (node?.underline) {
15
+ text = `<u>${text}</u>`;
16
+ }
17
+ return text;
18
+ }
19
+ if (Element.isElement(node)) {
20
+ const children = node.children.map((n) => serialize(n)).join("");
21
+ const alignStyle = node.align || "left";
22
+ switch (node.type) {
23
+ case "image":
24
+ return `<img src="${node.src}" class="align_${alignStyle}" />`;
25
+ case "paragraph":
26
+ return `<p class="align_${alignStyle}">${children}</p>`;
27
+ case "blockQuote":
28
+ return `<blockquote class="align_${alignStyle}">${children}</blockquote>`;
29
+ case "bulletedList":
30
+ return `<ul class="align_${alignStyle}">${children}</ul>`;
31
+ case "headingOne":
32
+ return `<h1 class="align_${alignStyle}">${children}</h1>`;
33
+ case "headingTwo":
34
+ return `<h2 class="align_${alignStyle}">${children}</h2>`;
35
+ case "listItem":
36
+ return `<li class="align_${alignStyle}">${children}</li>`;
37
+ case "numberedList":
38
+ return `<ol class="align_${alignStyle}">${children}</ol>`;
39
+ default:
40
+ return children;
41
+ }
42
+ }
43
+ return "";
44
+ }
45
+ function deserialize(el) {
46
+ if (typeof el === "string") {
47
+ return { text: el };
48
+ }
49
+ const children = Array.isArray(el.props.children)
50
+ ? el.props.children.map((child) => deserialize(child))
51
+ : [{ text: el.props.children || "" }];
52
+ const align = el.props.className?.replace("align_", "");
53
+ switch (el.type) {
54
+ case "img":
55
+ return {
56
+ type: "image",
57
+ align,
58
+ src: el.props.src,
59
+ children: [{ text: "" }],
60
+ };
61
+ case "p":
62
+ return { type: "paragraph", align, children };
63
+ case "blockquote":
64
+ return { type: "blockQuote", align, children };
65
+ case "ul":
66
+ return { type: "bulletedList", align, children };
67
+ case "ol":
68
+ return { type: "numberedList", align, children };
69
+ case "li":
70
+ return { type: "listItem", align, children };
71
+ case "h1":
72
+ return { type: "headingOne", align, children };
73
+ case "h2":
74
+ return { type: "headingTwo", align, children };
75
+ case "strong":
76
+ return { text: el.props.children, bold: true };
77
+ case "code":
78
+ return { text: el.props.children, code: true };
79
+ case "em":
80
+ return { text: el.props.children, italic: true };
81
+ case "u":
82
+ return { text: el.props.children, underline: true };
83
+ default:
84
+ return { text: el.props.children || "" };
85
+ }
86
+ }
87
+ export { deserialize, serialize };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@arkyn/components",
3
- "version": "3.0.1-beta.27",
3
+ "version": "3.0.1-beta.29",
4
4
  "main": "./dist/bundle.js",
5
5
  "types": "./dist/index.d.ts",
6
6
  "type": "module",