Updated file extensions, cleaned up dirty build files

This commit is contained in:
2024-09-05 12:41:34 +05:30
parent bdbab37c4b
commit ae83e30f4a
31 changed files with 0 additions and 322 deletions

View File

@@ -1,7 +0,0 @@
import { useRoutes } from "react-router-dom";
import * as pages from "./pages";
import Helper from "./utils/helper";
import ROUTES from "./routes";
Helper.populateComponentsInRoutes(ROUTES, pages);
var Router = function (props) { return useRoutes(ROUTES); };
export default Router;

View File

@@ -1 +0,0 @@
"use strict";

View File

@@ -1,4 +0,0 @@
import { useDispatch, useSelector } from "react-redux";
// Use throughout your app instead of plain `useDispatch` and `useSelector`
export var useAppDispatch = useDispatch;
export var useAppSelector = useSelector;

View File

@@ -1,2 +0,0 @@
/* PLOP_INJECT_IMPORT */
export {};

View File

@@ -1,8 +0,0 @@
var ROUTES = [
{
path: "/",
class: "landing",
element: "Home",
},
];
export default ROUTES;

View File

@@ -1,4 +0,0 @@
import { configureStore } from "@reduxjs/toolkit";
export var store = configureStore({
reducer: {},
});

View File

@@ -1,17 +0,0 @@
import { jsx as _jsx } from "react/jsx-runtime";
var Helper = /** @class */ (function () {
function Helper() {
}
Helper.populateComponentsInRoutes = function (routes, components) {
routes &&
routes.forEach(function (route) {
var Component = components[route.element];
route.element = _jsx(Component, {});
if (route.children) {
Helper.populateComponentsInRoutes(route.children, components);
}
});
};
return Helper;
}());
export default Helper;

View File

@@ -1,10 +0,0 @@
import { jsx as _jsx } from "react/jsx-runtime";
import React from "react";
import ReactDOM from "react-dom/client";
import { BrowserRouter } from "react-router-dom";
import { Provider } from "react-redux";
import { store } from "./app/store";
import Router from "./app/Router";
import "./app/static/styles/global.scss";
var root = ReactDOM.createRoot(document.getElementById("root"));
root.render(_jsx(React.StrictMode, { children: _jsx(BrowserRouter, { children: _jsx(Provider, { store: store, children: _jsx(Router, {}) }) }) }));

View File

@@ -1 +0,0 @@
"use strict";

View File

@@ -1 +0,0 @@
export * from "./utils";

View File

@@ -1,21 +0,0 @@
export function debounce(func, wait, immediate) {
if (immediate === void 0) { immediate = false; }
var timeout;
return function () {
var args = [];
for (var _i = 0; _i < arguments.length; _i++) {
args[_i] = arguments[_i];
}
var later = function () {
timeout = undefined;
if (!immediate) {
func.apply(void 0, args);
}
};
clearTimeout(timeout);
if (immediate && !timeout) {
func.apply(void 0, args);
}
timeout = setTimeout(later, wait || 1000);
};
}

View File

@@ -1 +0,0 @@
export * from "./helper";

View File

@@ -1 +0,0 @@
"use strict";

View File

@@ -1,93 +0,0 @@
var __assign = (this && this.__assign) || function () {
__assign = Object.assign || function(t) {
for (var s, i = 1, n = arguments.length; i < n; i++) {
s = arguments[i];
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
t[p] = s[p];
}
return t;
};
return __assign.apply(this, arguments);
};
import { v4 as uuid } from "uuid";
export var findOverlappedChunksInSingleText = function (chunks, start, end) {
return Object.values(chunks).filter(function (chunk) { return chunk.end > start && chunk.start < end; });
};
export var findOverlappedChunks = function (contentRegistry, selectionInfo) {
var selectedNodes = selectionInfo.selectedNodes, startParentId = selectionInfo.startParentId, endParentId = selectionInfo.endParentId, startOffset = selectionInfo.startOffset, endOffset = selectionInfo.endOffset;
return Array.from(selectedNodes).reduce(function (acc, id) {
var _a;
var currentConfig = contentRegistry[id];
var start = id !== startParentId ? 0 : startOffset;
var end = id !== endParentId
? (((_a = currentConfig.text) === null || _a === void 0 ? void 0 : _a.length) || 0) - 1
: endOffset;
acc = acc.concat(findOverlappedChunksInSingleText(currentConfig.chunks, start, end));
return acc;
}, []);
};
export var isEntireSelectionFormatted = function (format, selectionInfo, contentRegistry) {
// Flatten all chunks from selected nodes
var allSelectedChunks = findOverlappedChunks(contentRegistry, selectionInfo);
// Check if all chunks in the selection already have the format
var entireSelectionFormatted = allSelectedChunks.length > 0 &&
allSelectedChunks.every(function (chunk) { return format in chunk.formats; });
return entireSelectionFormatted;
};
export var applyTool = function (format, formatValue, selectionInfo, contentState, callback) {
if (selectionInfo) {
var contentStateClone_1 = __assign({}, contentState);
var selectedNodes = selectionInfo.selectedNodes, startParentId_1 = selectionInfo.startParentId, endParentId_1 = selectionInfo.endParentId, startOffset_1 = selectionInfo.startOffset, endOffset_1 = selectionInfo.endOffset;
var entireSelectionFormatted_1 = isEntireSelectionFormatted(format, selectionInfo, contentStateClone_1.contentRegistry);
contentStateClone_1.entireSelectionFormatted = entireSelectionFormatted_1;
selectedNodes === null || selectedNodes === void 0 ? void 0 : selectedNodes.forEach(function (id) {
var _a;
var currentConfig = contentStateClone_1.contentRegistry[id];
handleNewChunk(currentConfig.chunks, [format, true], // TODO: Retain value as true, this will change for color, backgroundColor and fontSize
startParentId_1 === id ? startOffset_1 : 0, endParentId_1 === id
? endOffset_1
: ((_a = currentConfig.text) === null || _a === void 0 ? void 0 : _a.length) - 1, entireSelectionFormatted_1, currentConfig.text);
});
Array.from(selectedNodes).length > 0 &&
callback &&
callback(contentStateClone_1);
}
};
var handleNewChunk = function (chunksMap, formatDetails, start, end, entireSelectionFormatted, text) {
var format = formatDetails[0], value = formatDetails[1];
// Find all overlapped chunks, chunk out first and/or last chunks, splitting based on selection start and end and whether applied format is same or different
var overlappedChunks = findOverlappedChunksInSingleText(chunksMap, start, end);
overlappedChunks.sort(function (a, b) { return a.start - b.start; });
function createRestChunk(chunk, start, end, isLeftOverlap) {
var chunkId = uuid();
var restChunk = {
id: chunkId,
start: isLeftOverlap ? chunk.start : end,
end: isLeftOverlap ? start : chunk.end,
text: text.substring(isLeftOverlap ? chunk.start : end, isLeftOverlap ? start : chunk.end),
formats: __assign({}, chunk.formats),
parent: chunk.parent,
};
chunksMap[chunkId] = restChunk;
if (isLeftOverlap) {
chunk.start = start;
chunk.text = chunk.text.substring(start);
}
else {
chunk.end = end;
}
}
// entireSelectionFormatted && remove format from overlapped chunk, shrink the before/after chunks
// !entireSelectionFormatted && add format to all the chunks, if a chunk ends up becoming similar to previous one, extend the previous chunk, ignore current one
overlappedChunks.forEach(function (c) {
if (format in c.formats === entireSelectionFormatted) {
c.start < start && createRestChunk(c, c.start, start, true);
c.end > end && createRestChunk(c, end, c.end, false);
chunksMap[c.id] = c;
// Full contained or shrunk to be fully contained
entireSelectionFormatted
? delete c.formats[format]
: (c.formats[format] = value !== undefined ? value : true);
}
});
};

View File

@@ -1 +0,0 @@
"use strict";

View File

@@ -1 +0,0 @@
"use strict";

View File

@@ -1 +0,0 @@
"use strict";

View File

@@ -1,36 +0,0 @@
import { processCaret, processRange } from "./util";
var SelectionManager = /** @class */ (function () {
function SelectionManager() {
}
SelectionManager.getSelection = function (contentRegistry, doc, win, atomicContentSelector) {
var docObj = doc || document;
var selection = (win || window).getSelection();
atomicContentSelector = atomicContentSelector || "ar-Text";
if (selection) {
if (selection.type === "Range") {
return processRange(selection, docObj, contentRegistry, atomicContentSelector);
}
else if (selection.type === "Caret" && contentRegistry) {
return processCaret(selection, contentRegistry, atomicContentSelector);
}
}
return null;
};
SelectionManager.setSelection = function (range) {
throw new Error("Method not implemented.");
};
SelectionManager.clearSelection = function () {
throw new Error("Method not implemented.");
};
SelectionManager.selectAll = function () {
throw new Error("Method not implemented.");
};
SelectionManager.getSelectedText = function () {
throw new Error("Method not implemented.");
};
SelectionManager.hasSelection = function () {
throw new Error("Method not implemented.");
};
return SelectionManager;
}());
export default SelectionManager;

View File

@@ -1,104 +0,0 @@
export var getTextContainerId = function (node, atomicContentSelector) {
var _a;
var textElementNode = node.nodeType === Node.TEXT_NODE
? (_a = node.parentElement) === null || _a === void 0 ? void 0 : _a.closest(atomicContentSelector)
: node;
return textElementNode === null || textElementNode === void 0 ? void 0 : textElementNode.id;
};
export var processRange = function (selection, docObj, contentRegistry, atomicContentSelector) {
var _a, _b, _c;
var selectionInfo = {
startOffset: -1,
endOffset: -1,
startParentId: "",
endParentId: "",
startChunkId: "",
endChunkId: "",
selectedNodes: new Set(),
raw: selection,
};
var range = selection.getRangeAt(0);
var content = range.cloneContents();
if (content.childNodes.length === 1 &&
((_a = content.firstChild) === null || _a === void 0 ? void 0 : _a.nodeType) === Node.TEXT_NODE) {
var parent_1 = (_c = (_b = range.startContainer.parentElement) === null || _b === void 0 ? void 0 : _b.closest(atomicContentSelector)) === null || _c === void 0 ? void 0 : _c.cloneNode(true);
parent_1 && content.replaceChild(parent_1, content.firstChild);
}
var startParentId = getTextContainerId(range.startContainer, atomicContentSelector);
var endParentId = getTextContainerId(range.endContainer, atomicContentSelector);
if (startParentId && endParentId) {
var startOffset = calculateOffset(range, range.startContainer, range.startOffset);
var endOffset = calculateOffset(range, range.endContainer, range.endOffset);
// Update selectionInfo properties
selectionInfo.startParentId = startParentId;
selectionInfo.endParentId = endParentId;
selectionInfo.startOffset = startOffset;
selectionInfo.endOffset = endOffset;
var walker = docObj.createTreeWalker(content, NodeFilter.SHOW_ELEMENT);
while (walker.nextNode()) {
var currNode = walker.currentNode;
var node = ((currNode === null || currNode === void 0 ? void 0 : currNode.closest(atomicContentSelector)) ||
range.commonAncestorContainer);
if (node) {
selectionInfo.selectedNodes.add(node.id);
}
}
}
return selectionInfo;
};
export var processCaret = function (selection, contentRegistry, atomicContentSelector) {
if (selection.anchorNode) {
var selectionInfo = {
startOffset: -1,
endOffset: -1,
startParentId: "",
endParentId: "",
startChunkId: "",
endChunkId: "",
selectedNodes: new Set(),
raw: selection,
};
var anchorNode = selection.anchorNode;
if (anchorNode.nodeType === Node.ELEMENT_NODE &&
anchorNode.classList.contains("ar-FlexContent")) {
// Implies there's no text yet, so we get first text config as
// at least 1 is always expected to be present
anchorNode = anchorNode.querySelector(atomicContentSelector);
}
var normalizedCursorPosition_1 = anchorNode &&
calculateOffset(selection.getRangeAt(0), anchorNode, selection.anchorOffset);
var activeText = anchorNode &&
contentRegistry[getTextContainerId(anchorNode, atomicContentSelector)];
var activeChunk = (activeText === null || activeText === void 0 ? void 0 : activeText.chunks) && normalizedCursorPosition_1 !== null
? Object.values(activeText.chunks).find(function (chunk) {
return chunk.start <= normalizedCursorPosition_1 &&
chunk.end >= normalizedCursorPosition_1;
})
: undefined;
if (normalizedCursorPosition_1) {
selectionInfo.startOffset = normalizedCursorPosition_1;
selectionInfo.endOffset = normalizedCursorPosition_1;
}
if (activeText && activeChunk) {
selectionInfo.startParentId = activeText.id;
selectionInfo.endParentId = activeText.id;
selectionInfo.startChunkId = activeChunk.id;
selectionInfo.endChunkId = activeChunk.id;
}
return selectionInfo;
}
return null;
};
export function calculateOffset(range, container, offset) {
var _a;
var relativeTo = container.nodeType === Node.TEXT_NODE
? (_a = container.parentElement) === null || _a === void 0 ? void 0 : _a.closest(".ar-Text")
: container.closest(".ar-Text");
if (relativeTo) {
var preCaretRange = range.cloneRange();
preCaretRange.selectNodeContents(relativeTo);
preCaretRange.setEnd(container, offset);
return preCaretRange.toString().length;
}
return -1;
}

View File

@@ -1 +0,0 @@
"use strict";

View File

@@ -1 +0,0 @@
"use strict";

View File

@@ -1 +0,0 @@
"use strict";

View File

@@ -1,5 +0,0 @@
// jest-dom adds custom jest matchers for asserting on DOM nodes.
// allows you to do things like:
// expect(element).toHaveTextContent(/react/i)
// learn more: https://github.com/testing-library/jest-dom
import "@testing-library/jest-dom";