From 1f15a6a53c0dd8a6462f49e9bd90bdcdf505cd4b Mon Sep 17 00:00:00 2001 From: Ivan <8611739+IRBorisov@users.noreply.github.com> Date: Sun, 13 Apr 2025 23:13:04 +0300 Subject: [PATCH] R: Remove unused dependencies --- .../frontend/src/components/input/index.tsx | 2 +- .../frontend/src/features/library/index.ts | 4 +- .../frontend/src/features/oss/backend/api.ts | 2 + rsconcept/frontend/src/features/oss/index.ts | 1 - .../oss/pages/oss-page/oss-edit-context.tsx | 2 +- .../src/features/rsform/backend/types.ts | 3 - .../rsform/components/refs-input/tooltip.ts | 2 +- .../dlg-cst-template/template-context.tsx | 2 +- .../frontend/src/features/rsform/index.ts | 1 - .../src/features/rsform/models/rsform.ts | 8 +- .../src/features/rsform/models/rslang-api.ts | 81 +++++++++---------- .../pages/rsform-page/rsedit-context.tsx | 2 +- rsconcept/frontend/src/utils/codemirror.ts | 26 ++---- rsconcept/frontend/src/utils/utils.ts | 23 ------ 14 files changed, 60 insertions(+), 99 deletions(-) diff --git a/rsconcept/frontend/src/components/input/index.tsx b/rsconcept/frontend/src/components/input/index.tsx index e8374ebe..59ffc40b 100644 --- a/rsconcept/frontend/src/components/input/index.tsx +++ b/rsconcept/frontend/src/components/input/index.tsx @@ -1,4 +1,4 @@ -export { Checkbox, type CheckboxProps } from './checkbox'; +export { Checkbox } from './checkbox'; export { CheckboxTristate } from './checkbox-tristate'; export { ErrorField } from './error-field'; export { FileInput } from './file-input'; diff --git a/rsconcept/frontend/src/features/library/index.ts b/rsconcept/frontend/src/features/library/index.ts index 4903a557..cfdad28c 100644 --- a/rsconcept/frontend/src/features/library/index.ts +++ b/rsconcept/frontend/src/features/library/index.ts @@ -5,9 +5,7 @@ export { type IUpdateLibraryItemDTO, type IVersionInfo, LibraryItemType, - schemaLibraryItem, - schemaUpdateLibraryItem, - schemaVersionInfo + schemaUpdateLibraryItem } from './backend/types'; export { BASIC_SCHEMAS, type CurrentVersion, type ILibraryItemReference, LocationHead } from './models/library'; export { useLibrarySearchStore } from './stores/library-search'; diff --git a/rsconcept/frontend/src/features/oss/backend/api.ts b/rsconcept/frontend/src/features/oss/backend/api.ts index 8dbfac5e..cd35c5ea 100644 --- a/rsconcept/frontend/src/features/oss/backend/api.ts +++ b/rsconcept/frontend/src/features/oss/backend/api.ts @@ -17,6 +17,7 @@ import { type IOssLayout, type ITargetOperation, schemaConstituentaReference, + schemaInputCreatedResponse, schemaOperationCreatedResponse, schemaOperationSchema } from './types'; @@ -68,6 +69,7 @@ export const ossApi = { }), inputCreate: ({ itemID, data }: { itemID: number; data: ITargetOperation }) => axiosPatch({ + schema: schemaInputCreatedResponse, endpoint: `/api/oss/${itemID}/create-input`, request: { data: data, diff --git a/rsconcept/frontend/src/features/oss/index.ts b/rsconcept/frontend/src/features/oss/index.ts index a7466876..4cd950a8 100644 --- a/rsconcept/frontend/src/features/oss/index.ts +++ b/rsconcept/frontend/src/features/oss/index.ts @@ -1,2 +1 @@ export { type IOperationSchemaDTO } from './backend/types'; -export { type IOperation } from './models/oss'; diff --git a/rsconcept/frontend/src/features/oss/pages/oss-page/oss-edit-context.tsx b/rsconcept/frontend/src/features/oss/pages/oss-page/oss-edit-context.tsx index 8860c010..7d315e1e 100644 --- a/rsconcept/frontend/src/features/oss/pages/oss-page/oss-edit-context.tsx +++ b/rsconcept/frontend/src/features/oss/pages/oss-page/oss-edit-context.tsx @@ -10,7 +10,7 @@ export const OssTabID = { } as const; export type OssTabID = (typeof OssTabID)[keyof typeof OssTabID]; -export interface IOssEditContext { +interface IOssEditContext { schema: IOperationSchema; selected: number[]; diff --git a/rsconcept/frontend/src/features/rsform/backend/types.ts b/rsconcept/frontend/src/features/rsform/backend/types.ts index 0d975e09..69980365 100644 --- a/rsconcept/frontend/src/features/rsform/backend/types.ts +++ b/rsconcept/frontend/src/features/rsform/backend/types.ts @@ -44,9 +44,6 @@ export type ParsingStatus = (typeof ParsingStatus)[keyof typeof ParsingStatus]; /** Represents Constituenta basic persistent data. */ export type IConstituentaBasicsDTO = z.infer; -/** Represents {@link IConstituenta} data from server. */ -export type IConstituentaDTO = z.infer; - /** Represents data for {@link IRSForm} provided by backend. */ export type IRSFormDTO = z.infer; diff --git a/rsconcept/frontend/src/features/rsform/components/refs-input/tooltip.ts b/rsconcept/frontend/src/features/rsform/components/refs-input/tooltip.ts index c23d9649..81b957eb 100644 --- a/rsconcept/frontend/src/features/rsform/components/refs-input/tooltip.ts +++ b/rsconcept/frontend/src/features/rsform/components/refs-input/tooltip.ts @@ -14,7 +14,7 @@ import { type IConstituenta, type IRSForm } from '../../models/rsform'; import { RefEntity } from './parse/parser.terms'; import { findReferenceAt } from './utils'; -export const tooltipProducer = (schema: IRSForm, canClick?: boolean) => { +const tooltipProducer = (schema: IRSForm, canClick?: boolean) => { return hoverTooltip((view, pos) => { const parse = findReferenceAt(pos, view.state); if (!parse) { diff --git a/rsconcept/frontend/src/features/rsform/dialogs/dlg-cst-template/template-context.tsx b/rsconcept/frontend/src/features/rsform/dialogs/dlg-cst-template/template-context.tsx index c80eab75..da3a896a 100644 --- a/rsconcept/frontend/src/features/rsform/dialogs/dlg-cst-template/template-context.tsx +++ b/rsconcept/frontend/src/features/rsform/dialogs/dlg-cst-template/template-context.tsx @@ -5,7 +5,7 @@ import { createContext, use } from 'react'; import { type IConstituenta } from '../../models/rsform'; import { type IArgumentValue } from '../../models/rslang'; -export interface ITemplateContext { +interface ITemplateContext { args: IArgumentValue[]; prototype: IConstituenta | null; templateID: number | null; diff --git a/rsconcept/frontend/src/features/rsform/index.ts b/rsconcept/frontend/src/features/rsform/index.ts index 14c93f8e..bbf51fd8 100644 --- a/rsconcept/frontend/src/features/rsform/index.ts +++ b/rsconcept/frontend/src/features/rsform/index.ts @@ -4,7 +4,6 @@ export { type IRSFormDTO, type IVersionCreatedResponse, ParsingStatus, - schemaCstSubstitute, schemaRSForm, schemaVersionCreatedResponse } from './backend/types'; diff --git a/rsconcept/frontend/src/features/rsform/models/rsform.ts b/rsconcept/frontend/src/features/rsform/models/rsform.ts index b3bcb144..1581324d 100644 --- a/rsconcept/frontend/src/features/rsform/models/rsform.ts +++ b/rsconcept/frontend/src/features/rsform/models/rsform.ts @@ -2,8 +2,12 @@ * Module: Models for formal representation for systems of concepts. */ -import { type ILibraryItemData, type IVersionInfo } from '@/features/library/backend/types'; -import { type CurrentVersion, type ILibraryItemReference } from '@/features/library/models/library'; +import { + type CurrentVersion, + type ILibraryItemData, + type ILibraryItemReference, + type IVersionInfo +} from '@/features/library'; import { type Graph } from '@/models/graph'; diff --git a/rsconcept/frontend/src/features/rsform/models/rslang-api.ts b/rsconcept/frontend/src/features/rsform/models/rslang-api.ts index 9a040a15..1afba909 100644 --- a/rsconcept/frontend/src/features/rsform/models/rslang-api.ts +++ b/rsconcept/frontend/src/features/rsform/models/rslang-api.ts @@ -18,29 +18,6 @@ const COMPLEX_SYMBOLS_REGEXP = /[∀∃×ℬ;|:]/g; const TYPIFICATION_SET = /^ℬ+\([ℬ\(X\d+\)×]*\)$/g; // cspell:enable -/** - * Text substitution guided by mapping and regular expression. - */ -export function applyPattern(text: string, mapping: AliasMapping, pattern: RegExp): string { - if (text === '' || pattern === null) { - return text; - } - let posInput = 0; - let output = ''; - const patternMatches = text.matchAll(pattern); - for (const segment of patternMatches) { - const entity = segment[0]; - const start = segment.index ?? 0; - if (entity in mapping) { - output += text.substring(posInput, start); - output += mapping[entity]; - posInput = start + segment[0].length; - } - } - output += text.substring(posInput); - return output; -} - /** * Extracts global variable names from a given expression. */ @@ -147,25 +124,6 @@ export function substituteTemplateArgs(expression: string, args: IArgumentValue[ } } -const ERROR_LEXER_MASK = 512; -const ERROR_PARSER_MASK = 1024; -const ERROR_SEMANTIC_MASK = 2048; - -/** - * Infers error class from error type (code). - */ -export function inferErrorClass(error: RSErrorType): RSErrorClass { - if ((error & ERROR_LEXER_MASK) !== 0) { - return RSErrorClass.LEXER; - } else if ((error & ERROR_PARSER_MASK) !== 0) { - return RSErrorClass.PARSER; - } else if ((error & ERROR_SEMANTIC_MASK) !== 0) { - return RSErrorClass.SEMANTIC; - } else { - return RSErrorClass.UNKNOWN; - } -} - /** * Generate ErrorID label. */ @@ -293,3 +251,42 @@ export function transformAST(tree: Tree): SyntaxTree { } return result; } + +// ====== Internals ========= +/** Text substitution guided by mapping and regular expression. */ +function applyPattern(text: string, mapping: AliasMapping, pattern: RegExp): string { + if (text === '' || pattern === null) { + return text; + } + let posInput = 0; + let output = ''; + const patternMatches = text.matchAll(pattern); + for (const segment of patternMatches) { + const entity = segment[0]; + const start = segment.index ?? 0; + if (entity in mapping) { + output += text.substring(posInput, start); + output += mapping[entity]; + posInput = start + segment[0].length; + } + } + output += text.substring(posInput); + return output; +} + +const ERROR_LEXER_MASK = 512; +const ERROR_PARSER_MASK = 1024; +const ERROR_SEMANTIC_MASK = 2048; + +/** Infers error class from error type (code). */ +function inferErrorClass(error: RSErrorType): RSErrorClass { + if ((error & ERROR_LEXER_MASK) !== 0) { + return RSErrorClass.LEXER; + } else if ((error & ERROR_PARSER_MASK) !== 0) { + return RSErrorClass.PARSER; + } else if ((error & ERROR_SEMANTIC_MASK) !== 0) { + return RSErrorClass.SEMANTIC; + } else { + return RSErrorClass.UNKNOWN; + } +} diff --git a/rsconcept/frontend/src/features/rsform/pages/rsform-page/rsedit-context.tsx b/rsconcept/frontend/src/features/rsform/pages/rsform-page/rsedit-context.tsx index 9e5f2d58..69007e54 100644 --- a/rsconcept/frontend/src/features/rsform/pages/rsform-page/rsedit-context.tsx +++ b/rsconcept/frontend/src/features/rsform/pages/rsform-page/rsedit-context.tsx @@ -13,7 +13,7 @@ export const RSTabID = { } as const; export type RSTabID = (typeof RSTabID)[keyof typeof RSTabID]; -export interface IRSEditContext { +interface IRSEditContext { schema: IRSForm; selected: number[]; focusCst: IConstituenta | null; diff --git a/rsconcept/frontend/src/utils/codemirror.ts b/rsconcept/frontend/src/utils/codemirror.ts index 2f89c17c..c5824e0b 100644 --- a/rsconcept/frontend/src/utils/codemirror.ts +++ b/rsconcept/frontend/src/utils/codemirror.ts @@ -5,18 +5,14 @@ import { syntaxTree } from '@codemirror/language'; import { type NodeType, type Tree, type TreeCursor } from '@lezer/common'; import { type ReactCodeMirrorRef, type SelectionRange } from '@uiw/react-codemirror'; -/** - * Represents syntax tree node data. - */ +/** Represents syntax tree node data. */ interface SyntaxNode { type: NodeType; from: number; to: number; } -/** - * Represents syntax tree cursor data. - */ +/** Represents syntax tree cursor data. */ interface CursorNode extends SyntaxNode { isLeaf: boolean; } @@ -31,10 +27,8 @@ interface TreeTraversalOptions { onLeave?: (node: CursorNode) => false | void; } -/** - * Implements depth-first traversal. - */ -export function traverseTree(tree: Tree, { beforeEnter, onEnter, onLeave }: TreeTraversalOptions) { +/** Implements depth-first traversal. */ +function traverseTree(tree: Tree, { beforeEnter, onEnter, onLeave }: TreeTraversalOptions) { const cursor = tree.cursor(); for (;;) { let node = cursorNode(cursor); @@ -59,9 +53,7 @@ export function traverseTree(tree: Tree, { beforeEnter, onEnter, onLeave }: Tree } } -/** - * Prints tree to compact string. - */ +/** Prints tree to compact string. */ export function printTree(tree: Tree): string { const state = { output: '', @@ -79,9 +71,7 @@ export function printTree(tree: Tree): string { return state.output; } -/** - * Retrieves a list of all nodes, containing given range and corresponding to a filter. - */ +/** Retrieves a list of all nodes, containing given range and corresponding to a filter. */ export function findEnvelopingNodes(start: number, finish: number, tree: Tree, filter?: number[]): SyntaxNode[] { const result: SyntaxNode[] = []; tree.cursor().iterate(node => { @@ -96,9 +86,7 @@ export function findEnvelopingNodes(start: number, finish: number, tree: Tree, f return result; } -/** - * Retrieves a list of all nodes, contained in given range and corresponding to a filter. - */ +/** Retrieves a list of all nodes, contained in given range and corresponding to a filter. */ export function findContainedNodes(start: number, finish: number, tree: Tree, filter?: number[]): SyntaxNode[] { const result: SyntaxNode[] = []; tree.cursor().iterate(node => { diff --git a/rsconcept/frontend/src/utils/utils.ts b/rsconcept/frontend/src/utils/utils.ts index 2a3e3c84..f73da02c 100644 --- a/rsconcept/frontend/src/utils/utils.ts +++ b/rsconcept/frontend/src/utils/utils.ts @@ -7,15 +7,6 @@ import { type AxiosError, type AxiosHeaderValue, type AxiosResponse, isAxiosErro import { infoMsg, promptText } from './labels'; -/** - * Checks if arguments is Node. - */ -export function assertIsNode(e: EventTarget | null): asserts e is Node { - if (e === null || !('nodeType' in e)) { - throw new TypeError(`Expected 'Node' but received '${e?.constructor.name ?? 'null'}'`); - } -} - /** * Wrapper class for generalized text matching. * @@ -88,20 +79,6 @@ export function isResponseHtml(response?: AxiosResponse) { return header.includes('text/html'); } -/** - * Convert base64 string to Blob uint8. - */ -export function convertBase64ToBlob(base64String: string): Uint8Array { - const arr = base64String.split(','); - const bstr = atob(arr[1]); - let n = bstr.length; - const uint8Array = new Uint8Array(n); - while (n--) { - uint8Array[n] = bstr.charCodeAt(n); - } - return uint8Array; -} - /** * Prompt user of confirming discarding changes before continue. */