pager-widget 0.0.1

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/getVersion.js ADDED
@@ -0,0 +1,9 @@
1
+ import { loadPackageJson } from "json.macro";
2
+
3
+ const x = loadPackageJson();
4
+
5
+ export const data = x;
6
+
7
+ export const getPackageNameAndVersion = () => {
8
+ return { name: x.name, version: x.version };
9
+ };
Binary file
@@ -0,0 +1,150 @@
1
+ import React from "react";
2
+
3
+ const URL_REGEX = /[(http(s)?):\/\/(www\.)?a-zA-Z0-9@:%._\+~#=-]{2,256}\.[a-z]{2,6}\b([-a-zA-Z0-9@:%_\+.~#?&//=]*)/;
4
+
5
+ const normalStr = (str) => ({
6
+ type: "normal_str",
7
+ value: str,
8
+ });
9
+
10
+ const urlStr = (str) => ({
11
+ type: "url",
12
+ value: str,
13
+ });
14
+
15
+ const normalWrapper = (TagName) => ({ mdText }) => (
16
+ <TagName>
17
+ <AssistantMd mdText={mdText.value} />
18
+ </TagName>
19
+ );
20
+
21
+ const listWrapper = (TagName) => ({ mdText: { list } }) => (
22
+ <TagName>
23
+ {list.map((mdText) => (
24
+ <li>
25
+ <AssistantMd mdText={mdText} />
26
+ </li>
27
+ ))}
28
+ </TagName>
29
+ );
30
+
31
+ export function parseUrlAndString(str) {
32
+ const results = [];
33
+ let remaining = str;
34
+ while (remaining) {
35
+ let match = remaining.match(URL_REGEX);
36
+ if (!match) {
37
+ results.push(normalStr(remaining));
38
+ break;
39
+ }
40
+
41
+ if (match.index !== 0) {
42
+ results.push(normalStr(remaining.slice(0, match.index)));
43
+ results.push(
44
+ urlStr(remaining.slice(match.index, match.index + match[0].length))
45
+ );
46
+ remaining = remaining.slice(match.index + match[0].length);
47
+ continue;
48
+ }
49
+ results.push(urlStr(remaining.slice(0, match[0].length)));
50
+ remaining = remaining.slice(match[0].length);
51
+ }
52
+ return results;
53
+ }
54
+
55
+ const mdTypeRenderers = {
56
+ normal_text: NormalTextMd,
57
+ bold: normalWrapper("strong"),
58
+ italic: normalWrapper("em"),
59
+ underline: normalWrapper("u"),
60
+ hyperlink: HyperLinkMd,
61
+ ordered_list: listWrapper("ol"),
62
+ unordered_list: listWrapper("ul"),
63
+ newline: () => <br />,
64
+ join: JoinMd,
65
+ };
66
+
67
+ const DisplayWithSpace = ({ text }) => {
68
+ return <span style={{ whiteSpace: "pre-wrap" }}>{text}</span>;
69
+ };
70
+
71
+ const DisplayLineBreaks = ({ text }) => {
72
+ let texts = text.split("\n");
73
+ let lastOne = texts[texts.length - 1];
74
+ let exceptLastOne = texts.slice(0, texts.length - 1);
75
+ return (
76
+ <>
77
+ {exceptLastOne.reduce(
78
+ (arr, text) => [
79
+ ...arr,
80
+ <DisplayWithSpace text={text} key={"space" + arr.length} />,
81
+ <br key={arr.length} />,
82
+ ],
83
+ []
84
+ )}
85
+ {<DisplayWithSpace text={lastOne} />}
86
+ </>
87
+ );
88
+ };
89
+
90
+ const DisplayURL = ({ text }) => {
91
+ const parsed = parseUrlAndString(text);
92
+ return parsed.map(({ type, value }, i) =>
93
+ type === "url" ? (
94
+ <a href={value} target="_blank" key={i} rel="noreferrer">
95
+ {value}
96
+ </a>
97
+ ) : (
98
+ <DisplayLineBreaks text={value} key={i}></DisplayLineBreaks>
99
+ )
100
+ );
101
+ };
102
+
103
+ function NormalTextMd({ mdText }) {
104
+ return <DisplayURL text={mdText} />;
105
+ }
106
+
107
+ function HyperLinkMd({ mdText }) {
108
+ return (
109
+ <a href={mdText.link} target="_blank">
110
+ <AssistantMd mdText={mdText.value} />
111
+ </a>
112
+ );
113
+ }
114
+
115
+ export function evalNormalOrJoinText(mdText) {
116
+ return mdText.markdown_text === "normal_text"
117
+ ? mdText.normal_text
118
+ : mdText.markdown_text === "join"
119
+ ? joinAsNormalText(mdText.join.lhs, mdText.join.rhs)
120
+ : null;
121
+ }
122
+
123
+ function joinAsNormalText(lhs, rhs) {
124
+ let evaluatedLhs = evalNormalOrJoinText(lhs);
125
+ let evaluatedRhs = evalNormalOrJoinText(rhs);
126
+ return (
127
+ (evaluatedLhs !== null &&
128
+ evaluatedRhs !== null &&
129
+ `${evaluatedLhs}${evaluatedRhs}`) ||
130
+ null
131
+ );
132
+ }
133
+
134
+ function JoinMd({ mdText: { lhs, rhs } }) {
135
+ let normalText = joinAsNormalText(lhs, rhs);
136
+ console.log({ normalText });
137
+ return normalText ? (
138
+ <NormalTextMd mdText={normalText} />
139
+ ) : (
140
+ <>
141
+ <AssistantMd mdText={lhs} />
142
+ <AssistantMd mdText={rhs} />
143
+ </>
144
+ );
145
+ }
146
+
147
+ export default function AssistantMd({ mdText }) {
148
+ let RenderMd = mdTypeRenderers[mdText.markdown_text];
149
+ return <RenderMd mdText={mdText[mdText.markdown_text]} />;
150
+ }
@@ -0,0 +1,68 @@
1
+ export const convertToMDText = (md) => {
2
+
3
+ if (md.markdown_text) {
4
+
5
+ return md
6
+
7
+ }
8
+
9
+ if (typeof md == 'string') {
10
+
11
+ return {
12
+
13
+ markdown_text: 'normal_text',
14
+
15
+ normal_text: md
16
+
17
+ }
18
+
19
+ } else if (md.md_type === 'md_bold' || md.md_type === 'md_italic' || md.md_type === 'md_underline') {
20
+
21
+ return {
22
+
23
+ markdown_text: md.md_type.replace(/^md_/, ''),
24
+
25
+ [`${md.md_type.replace(/^md_/, '')}`]: { value: convertToMDText(md.value) }
26
+
27
+ }
28
+
29
+ } else if (md.md_type === 'md_normal') {
30
+
31
+ return {
32
+
33
+ markdown_text: 'normal_text',
34
+
35
+ normal_text: md.value
36
+
37
+ }
38
+
39
+ } else if (md.md_type == 'md_hyperlink') {
40
+
41
+ return {
42
+
43
+ markdown_text: md.md_type.replace(/^md_/, ''),
44
+
45
+ hyperlink: {
46
+
47
+ link: md.link,
48
+
49
+ value: convertToMDText(md.value)
50
+
51
+ }
52
+
53
+ }
54
+
55
+ } else {
56
+ return updateLhsRhs(md)
57
+ }
58
+
59
+ }
60
+
61
+ const updateLhsRhs = (obj) => {
62
+ if (obj.md_type != 'md_join') {
63
+ obj = { ...convertToMDText(obj) }
64
+ } else {
65
+ obj = { join: { lhs: convertToMDText(obj.lhs), rhs: updateLhsRhs(obj.rhs) }, markdown_text: 'join' }
66
+ }
67
+ return obj
68
+ }
package/package.json ADDED
@@ -0,0 +1,73 @@
1
+ {
2
+ "name": "pager-widget",
3
+ "version": "0.0.1",
4
+ "description": "",
5
+ "main": "index.js",
6
+ "targets": {
7
+ "default": {
8
+ "sourceMap": {
9
+ "inline": true
10
+ }
11
+ }
12
+ },
13
+ "scripts": {
14
+ "build:css": "postcss styles/global.pcss -o static/global.css",
15
+ "watch": "watch 'npm run build:css' .",
16
+ "build": "cross-env NODE_ENV=production parcel build lib.jsx --no-source-maps",
17
+ "test": "echo \"Error: no test specified\" && exit 1",
18
+ "dev": "cross-env NODE_ENV=development parcel index.html",
19
+ "format": "prettier --write --ignore-unknown",
20
+ "prebuild": "rimraf dist",
21
+ "prepublishOnly": "npm run build:css && npm run build",
22
+ "format_changed_files": "pretty-quick --staged",
23
+ "postinstall": "npm run build:css"
24
+ },
25
+ "keywords": [],
26
+ "author": "",
27
+ "license": "ISC",
28
+ "dependencies": {
29
+ "@fullhuman/postcss-purgecss": "^4.0.3",
30
+ "@skitter/assistant_md": "^1.0.1",
31
+ "autoprefixer": "^9.8.7",
32
+ "axios": "^0.21.1",
33
+ "broadcast-channel": "^4.9.0",
34
+ "deepmerge": "^4.3.1",
35
+ "jsonwebtoken": "^8.5.1",
36
+ "parcel": "^2.0.0-nightly.852",
37
+ "postcss": "^8.3.8",
38
+ "postcss-cli": "^9.0.1",
39
+ "postcss-loader": "^4.0.3",
40
+ "postcss-modules": "^4.2.2",
41
+ "postcss-scopify": "^0.1.9",
42
+ "react": "^17.0.2",
43
+ "react-dom": "^17.0.2",
44
+ "react-is": "^17.0.2",
45
+ "socket.io": "^4.0.0",
46
+ "socket.io-client": "^2.4.0",
47
+ "styled-components": "^5.3.0",
48
+ "tailwindcss": "npm:@tailwindcss/postcss7-compat@^2.2.17",
49
+ "url-parse": "^1.5.1",
50
+ "use-media": "^1.4.0",
51
+ "uuid": "^8.3.2",
52
+ "watch": "^1.0.2"
53
+ },
54
+ "devDependencies": {
55
+ "@babel/core": "^7.15.8",
56
+ "babel-plugin-macros": "^3.1.0",
57
+ "cross-env": "^7.0.3",
58
+ "cssnano": "^4.1.11",
59
+ "fast-glob": "^3.2.7",
60
+ "json.macro": "^1.3.0",
61
+ "parcel-bundler": "^1.12.5",
62
+ "prettier": "2.2.1",
63
+ "pretty-quick": "^3.1.0",
64
+ "rimraf": "^3.0.2"
65
+ },
66
+ "@parcel/transformer-js": {
67
+ "inlineFS": false,
68
+ "inlineEnvironment": false
69
+ },
70
+ "volta": {
71
+ "node": "14.19.3"
72
+ }
73
+ }
package/parse-url.js ADDED
@@ -0,0 +1,37 @@
1
+ const URL_REGEX = /[(http(s)?):\/\/(www\.)?a-zA-Z0-9@:%._\+~#=-]{2,256}\.[a-z]{2,6}\b([-a-zA-Z0-9@:%_\+.~#?&//=]*)/;
2
+
3
+ const normalStr = (str) => ({
4
+ type: "normal_str",
5
+ value: str,
6
+ });
7
+
8
+ const urlStr = (str) => ({
9
+ type: "url",
10
+ value: str,
11
+ });
12
+
13
+ export function parseUrlAndString(str) {
14
+ const results = [];
15
+ let remaining = str;
16
+ while (remaining) {
17
+ let match = remaining.match(URL_REGEX);
18
+ if (!match) {
19
+ results.push(normalStr(remaining));
20
+ break;
21
+ }
22
+
23
+ if (match.index !== 0) {
24
+ results.push(normalStr(remaining.slice(0, match.index)));
25
+ results.push(
26
+ urlStr(remaining.slice(match.index, match.index + match[0].length))
27
+ );
28
+ remaining = remaining.slice(match.index + match[0].length);
29
+ continue;
30
+ }
31
+ results.push(urlStr(remaining.slice(0, match[0].length)));
32
+ remaining = remaining.slice(match[0].length);
33
+ }
34
+ return results;
35
+ }
36
+
37
+ export default parseUrlAndString;
@@ -0,0 +1,18 @@
1
+ const purgecss = require("@fullhuman/postcss-purgecss");
2
+ const cssnano = require("cssnano");
3
+ var scopify = require("postcss-scopify");
4
+
5
+ module.exports = {
6
+ plugins: [
7
+ require("tailwindcss"),
8
+ require("autoprefixer"),
9
+ scopify(".workativ-widget"),
10
+ cssnano({
11
+ preset: "default",
12
+ }),
13
+ // purgecss({
14
+ // content: ['./lib.jsx'],
15
+ // defaultExtractor: content => content.match(/[\w-/:]+(?<!:)/g) || []
16
+ // })
17
+ ],
18
+ };
@@ -0,0 +1,29 @@
1
+ .workativ-widget *,
2
+ .workativ-widget ::after,
3
+ .workativ-widget ::before {
4
+ box-sizing: border-box;
5
+ border-width: 0;
6
+ border-style: solid;
7
+ border-color: #e5e7eb;
8
+ font-family: 'Open Sans', sans-serif;
9
+ }
10
+
11
+ .flex{
12
+ display: flex;
13
+ }
14
+
15
+ @import url('https://fonts.googleapis.com/css2?family=Open+Sans:wght@400;500;700&display=swap');
16
+
17
+ @font-face {
18
+ font-family: 'Gordita-Medium';
19
+ src: url('./fonts/Gordita-Medium.woff2') format('woff2'), url('./fonts/Gordita-Medium.woff2') format('woff');
20
+ font-weight: 500;
21
+ font-style: normal;
22
+ }
23
+
24
+ @font-face {
25
+ font-family: 'Gordita-Regular';
26
+ src: url('./fonts/Gordita-Regular.woff2') format('woff2'), url('./fonts/Gordita-Regular.woff2') format('woff');
27
+ font-weight: 500;
28
+ font-style: normal;
29
+ }
@@ -0,0 +1 @@
1
+ .workativ-widget *,.workativ-widget :after,.workativ-widget :before{--tw-border-opacity:1;border-color:rgba(229,231,235,var(--tw-border-opacity))}.workativ-widget .fixed{position:fixed}.workativ-widget .absolute{position:absolute}.workativ-widget .relative{position:relative}.workativ-widget .top-0{top:0}.workativ-widget .top-4{top:1rem}.workativ-widget .right-0{right:0}.workativ-widget .right-6{right:1.5rem}.workativ-widget .right-8{right:2rem}.workativ-widget .bottom-8{bottom:2rem}.workativ-widget .bottom-10{bottom:2.5rem}.workativ-widget .bottom-24{bottom:6rem}.workativ-widget .left-0{left:0}.workativ-widget .float-left{float:left}.workativ-widget .mt-2{margin-top:.5rem}.workativ-widget .mt-2\.5{margin-top:.625rem}.workativ-widget .mr-1{margin-right:.25rem}.workativ-widget .mr-2{margin-right:.5rem}.workativ-widget .mr-2\.5{margin-right:.625rem}.workativ-widget .ml-1{margin-left:.25rem}.workativ-widget .ml-2{margin-left:.5rem}.workativ-widget .ml-2\.5{margin-left:.625rem}.workativ-widget .inline-block{display:inline-block}.workativ-widget .flex{display:flex}.workativ-widget .inline-flex{display:inline-flex}.workativ-widget .table{display:table}.workativ-widget .grid{display:grid}.workativ-widget .hidden{display:none}.workativ-widget .h-4{height:1rem}.workativ-widget .h-8{height:2rem}.workativ-widget .h-11{height:2.75rem}.workativ-widget .h-auto{height:auto}.workativ-widget .h-full{height:100%}.workativ-widget .w-4{width:1rem}.workativ-widget .w-8{width:2rem}.workativ-widget .w-11{width:2.75rem}.workativ-widget .w-auto{width:auto}.workativ-widget .w-5\/6{width:83.333333%}.workativ-widget .w-2\/12{width:16.666667%}.workativ-widget .w-full{width:100%}.workativ-widget .w-max{width:-moz-max-content;width:max-content}.workativ-widget .flex-shrink{flex-shrink:1}.workativ-widget .transform{--tw-translate-x:0;--tw-translate-y:0;--tw-rotate:0;--tw-skew-x:0;--tw-skew-y:0;--tw-scale-x:1;--tw-scale-y:1;transform:translateX(var(--tw-translate-x)) translateY(var(--tw-translate-y)) rotate(var(--tw-rotate)) skewX(var(--tw-skew-x)) skewY(var(--tw-skew-y)) scaleX(var(--tw-scale-x)) scaleY(var(--tw-scale-y))}@keyframes spin{to{transform:rotate(1turn)}}@keyframes ping{75%,to{transform:scale(2);opacity:0}}@keyframes pulse{50%{opacity:.5}}@keyframes bounce{0%,to{transform:translateY(-25%);animation-timing-function:cubic-bezier(.8,0,1,1)}50%{transform:none;animation-timing-function:cubic-bezier(0,0,.2,1)}}.workativ-widget .cursor-default{cursor:default}.workativ-widget .cursor-pointer{cursor:pointer}.workativ-widget .grid-cols-2{grid-template-columns:repeat(2,minmax(0,1fr))}.workativ-widget .flex-row{flex-direction:row}.workativ-widget .flex-col{flex-direction:column}.workativ-widget .flex-wrap{flex-wrap:wrap}.workativ-widget .items-start{align-items:flex-start}.workativ-widget .items-end{align-items:flex-end}.workativ-widget .items-center{align-items:center}.workativ-widget .justify-start{justify-content:flex-start}.workativ-widget .justify-end{justify-content:flex-end}.workativ-widget .justify-center{justify-content:center}.workativ-widget .justify-between{justify-content:space-between}.workativ-widget .gap-2{gap:.5rem}.workativ-widget .gap-2\.5{gap:.625rem}.workativ-widget .self-center{align-self:center}.workativ-widget .overflow-y-scroll{overflow-y:scroll}.workativ-widget .truncate{overflow:hidden;text-overflow:ellipsis;white-space:nowrap}.workativ-widget .break-words{overflow-wrap:break-word}.workativ-widget .break-all{word-break:break-all}.workativ-widget .rounded{border-radius:.25rem}.workativ-widget .rounded-full{border-radius:9999px}.workativ-widget .rounded-b-md{border-bottom-right-radius:.375rem;border-bottom-left-radius:.375rem}.workativ-widget .rounded-tl-none{border-top-left-radius:0}.workativ-widget .rounded-tl-md{border-top-left-radius:.375rem}.workativ-widget .rounded-tr-none{border-top-right-radius:0}.workativ-widget .rounded-tr-md{border-top-right-radius:.375rem}.workativ-widget .rounded-br-md{border-bottom-right-radius:.375rem}.workativ-widget .rounded-bl-md{border-bottom-left-radius:.375rem}.workativ-widget .border{border-width:1px}.workativ-widget .bg-transparent{background-color:transparent}.workativ-widget .bg-white{--tw-bg-opacity:1;background-color:rgba(255,255,255,var(--tw-bg-opacity))}.workativ-widget .bg-gray-200{--tw-bg-opacity:1;background-color:rgba(229,231,235,var(--tw-bg-opacity))}.workativ-widget .bg-gray-900{--tw-bg-opacity:1;background-color:rgba(17,24,39,var(--tw-bg-opacity))}.workativ-widget .hover\:bg-white:hover{--tw-bg-opacity:1;background-color:rgba(255,255,255,var(--tw-bg-opacity))}.workativ-widget .object-cover{-o-object-fit:cover;object-fit:cover}.workativ-widget .object-center{-o-object-position:center;object-position:center}.workativ-widget .p-2{padding:.5rem}.workativ-widget .p-3{padding:.75rem}.workativ-widget .p-2\.5{padding:.625rem}.workativ-widget .px-2{padding-left:.5rem;padding-right:.5rem}.workativ-widget .px-4{padding-left:1rem;padding-right:1rem}.workativ-widget .px-2\.5{padding-left:.625rem;padding-right:.625rem}.workativ-widget .py-1{padding-top:.25rem;padding-bottom:.25rem}.workativ-widget .py-3{padding-top:.75rem;padding-bottom:.75rem}.workativ-widget .py-1\.5{padding-top:.375rem;padding-bottom:.375rem}.workativ-widget .pr-1{padding-right:.25rem}.workativ-widget .pr-2{padding-right:.5rem}.workativ-widget .pr-9{padding-right:2.25rem}.workativ-widget .pr-1\.5{padding-right:.375rem}.workativ-widget .pr-2\.5{padding-right:.625rem}.workativ-widget .pb-2{padding-bottom:.5rem}.workativ-widget .pb-2\.5{padding-bottom:.625rem}.workativ-widget .pl-2{padding-left:.5rem}.workativ-widget .pl-4{padding-left:1rem}.workativ-widget .pl-2\.5{padding-left:.625rem}.workativ-widget .text-left{text-align:left}.workativ-widget .font-sans{font-family:ui-sans-serif,system-ui,-apple-system,BlinkMacSystemFont,Segoe UI,Roboto,Helvetica Neue,Arial,Noto Sans,sans-serif,Apple Color Emoji,Segoe UI Emoji,Segoe UI Symbol,Noto Color Emoji}.workativ-widget .text-xs{font-size:.75rem;line-height:1rem}.workativ-widget .text-sm{font-size:.875rem;line-height:1.25rem}.workativ-widget .text-base{font-size:1rem;line-height:1.5rem}.workativ-widget .font-normal{font-weight:400}.workativ-widget .font-semibold{font-weight:600}.workativ-widget .font-bold{font-weight:700}.workativ-widget .text-black{--tw-text-opacity:1;color:rgba(0,0,0,var(--tw-text-opacity))}.workativ-widget .text-white{--tw-text-opacity:1;color:rgba(255,255,255,var(--tw-text-opacity))}.workativ-widget .text-gray-200{--tw-text-opacity:1;color:rgba(229,231,235,var(--tw-text-opacity))}.workativ-widget .hover\:text-black:hover{--tw-text-opacity:1;color:rgba(0,0,0,var(--tw-text-opacity))}.workativ-widget *,.workativ-widget :after,.workativ-widget :before{--tw-shadow:0 0 transparent}.workativ-widget .shadow-xl{--tw-shadow:0 20px 25px -5px rgba(0,0,0,0.1),0 10px 10px -5px rgba(0,0,0,0.04)}.workativ-widget .shadow-2xl,.workativ-widget .shadow-xl{box-shadow:var(--tw-ring-offset-shadow,0 0 transparent),var(--tw-ring-shadow,0 0 transparent),var(--tw-shadow)}.workativ-widget .shadow-2xl{--tw-shadow:0 25px 50px -12px rgba(0,0,0,0.25)}.workativ-widget .focus\:outline-none:focus{outline:2px solid transparent;outline-offset:2px}.workativ-widget *,.workativ-widget :after,.workativ-widget :before{--tw-ring-inset:var(--tw-empty,/*!*/ /*!*/);--tw-ring-offset-width:0px;--tw-ring-offset-color:#fff;--tw-ring-color:rgba(59,130,246,0.5);--tw-ring-offset-shadow:0 0 transparent;--tw-ring-shadow:0 0 transparent}.workativ-widget .transition{transition-property:background-color,border-color,color,fill,stroke,opacity,box-shadow,transform,filter,-webkit-backdrop-filter;transition-property:background-color,border-color,color,fill,stroke,opacity,box-shadow,transform,filter,backdrop-filter;transition-property:background-color,border-color,color,fill,stroke,opacity,box-shadow,transform,filter,backdrop-filter,-webkit-backdrop-filter;transition-timing-function:cubic-bezier(.4,0,.2,1);transition-duration:.15s}.workativ-widget .ease-linear{transition-timing-function:linear}.workativ-widget .ease-in-out{transition-timing-function:cubic-bezier(.4,0,.2,1)}@media (min-width:640px){.workativ-widget .sm\:right-0{right:0}.workativ-widget .sm\:bottom-0{bottom:0}}@media (min-width:1280px){.workativ-widget .xl\:right-6{right:1.5rem}.workativ-widget .xl\:bottom-32{bottom:8rem}}
@@ -0,0 +1,5 @@
1
+ @tailwind base;
2
+ @tailwind components;
3
+ @tailwind utilities;
4
+
5
+
@@ -0,0 +1,17 @@
1
+ module.exports = {
2
+ purge: {
3
+ enabled: true,
4
+ content: ["./lib.jsx"],
5
+ },
6
+ darkMode: false, // or 'media' or 'class'
7
+ theme: {
8
+ extend: {},
9
+ },
10
+ variants: {
11
+ extend: {},
12
+ },
13
+ plugins: [],
14
+ corePlugins: {
15
+ preflight: false,
16
+ },
17
+ };
@@ -0,0 +1,28 @@
1
+ import { useState } from "react";
2
+ import axios from "axios";
3
+
4
+ export const useFileUpload = (endpoint, sendMessage) => {
5
+ const [fileUploadStatus, setFileUploadStatus] = useState("initial");
6
+ const onFileUpload = (event) => {
7
+ const file = event.target.files[0];
8
+ const formData = new FormData();
9
+ formData.append("file", file, file.name);
10
+ formData.append(
11
+ "category",
12
+ file.type.split("/")[0] === "image"
13
+ ? "image"
14
+ : file.type.split("/")[0] === "video"
15
+ ? "video"
16
+ : "file"
17
+ );
18
+ setFileUploadStatus("uploading");
19
+ axios.post(`${endpoint}/public/file_upload`, formData).then(({ data }) => {
20
+ sendMessage("", data);
21
+ setFileUploadStatus("initial");
22
+ });
23
+ };
24
+ return {
25
+ status: fileUploadStatus,
26
+ onFileUpload,
27
+ };
28
+ };
package/useScale.js ADDED
@@ -0,0 +1,85 @@
1
+ import React, {
2
+ createContext, useContext, useReducer
3
+ } from "react";
4
+
5
+ const MIN_ZOOM_LEVEL = 60;
6
+ const MAX_ZOOM_LEVEL = 200;
7
+ const DEFAULT_ZOOM_LEVEL = 100;
8
+
9
+ const calculateScaleToTranslate = (zoomLevel) => {
10
+ const scaleInRatio = zoomLevel / 100;
11
+ return Math.abs(scaleInRatio);
12
+ };
13
+
14
+ export const ScaleContext = createContext({});
15
+
16
+ export const useScaleContext = () => useContext(ScaleContext);
17
+
18
+ const validateZoomLevel = (zoom) => {
19
+
20
+ if (zoom >= MIN_ZOOM_LEVEL && zoom <= MAX_ZOOM_LEVEL) {
21
+ // console.log(`zoom :: ${zoom}`)
22
+ return true;
23
+ } else {
24
+ // console.error(`invalid zoom :: ${zoom}`)
25
+ return false;
26
+ }
27
+ };
28
+
29
+ const setInitialZoom = (currentZoomValue) => {
30
+ if (validateZoomLevel(currentZoomValue)) {
31
+ return currentZoomValue
32
+ }
33
+ return DEFAULT_ZOOM_LEVEL
34
+ };
35
+
36
+ function zoomReducer(currentZoom, action) {
37
+ switch (action.type) {
38
+ case "increase": {
39
+ const toUpdate = currentZoom + action.by;
40
+ return validateZoomLevel(toUpdate) ? toUpdate : currentZoom;
41
+ }
42
+ case "decrease": {
43
+ const toUpdate = currentZoom - action.by;
44
+ return validateZoomLevel(toUpdate) ? toUpdate : currentZoom;
45
+ }
46
+ case "update": {
47
+ const toUpdate = action.to;
48
+ return validateZoomLevel(toUpdate) ? toUpdate : currentZoom;
49
+ }
50
+ default:
51
+ throw new Error();
52
+ }
53
+ }
54
+
55
+ export default function useSizeScale(defaultSize) {
56
+ // console.log("defaultSize", defaultSize)
57
+ const [zoomLevel, dispatchZoomAction] = useReducer(zoomReducer, defaultSize, setInitialZoom);
58
+ const scaleRatio = calculateScaleToTranslate(zoomLevel);
59
+
60
+ const updateZoomLevel = (zoom) => {
61
+ dispatchZoomAction({ type: 'update', to: zoom });
62
+ };
63
+
64
+ return [zoomLevel, scaleRatio, updateZoomLevel];
65
+ }
66
+
67
+ export const ScaleSizeProvider = ({ children, widgetSize }) => {
68
+ const [zoomLevel, scaleRatio, updateZoomLevel] = useSizeScale(
69
+ calculateDefaultScale(widgetSize)
70
+ );
71
+
72
+ return (
73
+ <ScaleContext.Provider
74
+ value={{ zoomLevel, scale: scaleRatio, updateZoomLevel }}
75
+ >
76
+ {children}
77
+ </ScaleContext.Provider>
78
+ );
79
+ };
80
+
81
+ const calculateDefaultScale = (size) => {
82
+ const parsed = parseInt(size, 10);
83
+ if (isNaN(parsed)) { return DEFAULT_ZOOM_LEVEL; }
84
+ return size;
85
+ };