From 1054db3a8a3696a6c2e64205c3c4f7e20a132517 Mon Sep 17 00:00:00 2001 From: IRBorisov <8611739+IRBorisov@users.noreply.github.com> Date: Thu, 28 Sep 2023 13:05:43 +0300 Subject: [PATCH] Improve reference info --- .../src/components/RefsInput/index.tsx | 5 +++-- .../components/RefsInput/parse/highlight.ts | 2 ++ .../RefsInput/parse/parser.terms.ts | 3 ++- .../src/components/RefsInput/parse/parser.ts | 14 +++++++------- .../RefsInput/parse/refsText.grammar | 7 +++++-- .../src/components/RefsInput/tooltip.ts | 19 +++++++++++++++++-- rsconcept/frontend/src/utils/codemirror.ts | 18 +++++++++++++----- 7 files changed, 49 insertions(+), 19 deletions(-) diff --git a/rsconcept/frontend/src/components/RefsInput/index.tsx b/rsconcept/frontend/src/components/RefsInput/index.tsx index 00c88c1d..f9f6ab12 100644 --- a/rsconcept/frontend/src/components/RefsInput/index.tsx +++ b/rsconcept/frontend/src/components/RefsInput/index.tsx @@ -87,8 +87,9 @@ function RefsInput({ selection: colors.bgHover }, styles: [ - { tag: tags.name, color: colors.fgPurple, cursor: 'pointer' }, // GlobalID - { tag: tags.literal, color: colors.fgTeal }, // literals + { tag: tags.name, color: colors.fgPurple, cursor: 'default' }, // EntityReference + { tag: tags.literal, color: colors.fgTeal, cursor: 'default' }, // SyntacticReference + { tag: tags.comment, color: colors.fgRed }, // Error ] }), [editable, colors, darkMode]); diff --git a/rsconcept/frontend/src/components/RefsInput/parse/highlight.ts b/rsconcept/frontend/src/components/RefsInput/parse/highlight.ts index f8706409..15a0a06c 100644 --- a/rsconcept/frontend/src/components/RefsInput/parse/highlight.ts +++ b/rsconcept/frontend/src/components/RefsInput/parse/highlight.ts @@ -8,4 +8,6 @@ export const highlighting = styleTags({ RefSyntactic: tags.literal, Offset: tags.literal, Nominal: tags.literal, + + Error: tags.comment }); \ No newline at end of file diff --git a/rsconcept/frontend/src/components/RefsInput/parse/parser.terms.ts b/rsconcept/frontend/src/components/RefsInput/parse/parser.terms.ts index 6d5beffc..fa3d74ce 100644 --- a/rsconcept/frontend/src/components/RefsInput/parse/parser.terms.ts +++ b/rsconcept/frontend/src/components/RefsInput/parse/parser.terms.ts @@ -7,4 +7,5 @@ export const RefSyntactic = 5, Offset = 6, Nominal = 7, - Filler = 8 + Error = 8, + Filler = 9 diff --git a/rsconcept/frontend/src/components/RefsInput/parse/parser.ts b/rsconcept/frontend/src/components/RefsInput/parse/parser.ts index 16518a8a..17973ebe 100644 --- a/rsconcept/frontend/src/components/RefsInput/parse/parser.ts +++ b/rsconcept/frontend/src/components/RefsInput/parse/parser.ts @@ -3,16 +3,16 @@ import {LRParser} from "@lezer/lr" import {highlighting} from "./highlight.ts" export const parser = LRParser.deserialize({ version: 14, - states: "$[QVQPOOO_QQO'#C^OOQO'#Ck'#CkOgQPO'#CsOOQO'#Cd'#CdOOQO'#Cj'#CjOOQO'#Ce'#CeQVQPOOOrQPO,58xOwQPO,58{OOQO,59_,59_OOQO-E6c-E6cO|QSO1G.dO!RQPO1G.gO!WQQO'#CoOOQO'#C`'#C`O!`QPO7+$OOOQO'#Cf'#CfO!eQPO'#CcO!mQPO7+$RO|QSO,59ZOOQO< 0) { + const entities = findContainedNodes(end, view.state.doc.length, syntaxTree(view.state), [RefEntity]); + console.log(end); + if (ref.offset <= entities.length) { + const master = entities[ref.offset - 1]; + masterText = view.state.doc.sliceString(master.from, master.to); + } + } else { + const entities = findContainedNodes(0, start, syntaxTree(view.state), [RefEntity]); + if (-ref.offset <= entities.length) { + const master = entities[-ref.offset - 1]; + masterText = view.state.doc.sliceString(master.from, master.to); + } + } return { pos: start, end: end, above: false, - create: () => domTooltipSyntacticReference(ref) + create: () => domTooltipSyntacticReference(ref, masterText) } } }); diff --git a/rsconcept/frontend/src/utils/codemirror.ts b/rsconcept/frontend/src/utils/codemirror.ts index a2636237..5f455cf7 100644 --- a/rsconcept/frontend/src/utils/codemirror.ts +++ b/rsconcept/frontend/src/utils/codemirror.ts @@ -110,7 +110,7 @@ export function findContainedNodes(start: number, finish: number, tree: Tree, fi node => { if ( (!filter || filter.includes(node.type.id)) && - node.to <= start && node.from >= finish + node.to <= finish && node.from >= start ) { result.push({ type: node.type, @@ -164,17 +164,21 @@ export function domTooltipConstituenta(cst: IConstituenta) { */ export function domTooltipEntityReference(ref: IEntityReference, cst: IConstituenta | undefined, colors: IColorTheme) { const DIMENSIONS = 'max-h-[25rem] max-w-[25rem] min-w-[10rem] w-fit z-tooltip px-2 py-2'; - const LAYOUT = 'flex flex-col gap-1 overflow-y-auto' + const LAYOUT = 'flex flex-col overflow-y-auto'; const dom = document.createElement('div'); dom.className = `${DIMENSIONS} ${LAYOUT} border shadow-md text-sm select-none cursor-auto`; + const title = document.createElement('p'); + title.innerHTML = 'Ссылка на конституенту'; + dom.appendChild(title); + const term = document.createElement('p'); term.innerHTML = `${ref.entity}: ${describeConstituentaTerm(cst)}`; dom.appendChild(term); const grams = document.createElement('div'); - grams.className = 'flex flex-wrap gap-1'; + grams.className = 'flex flex-wrap gap-1 mt-1'; parseGrammemes(ref.form).forEach( gramStr => { const gram = document.createElement('div'); @@ -196,9 +200,9 @@ export function domTooltipEntityReference(ref: IEntityReference, cst: IConstitue /** * Create DOM tooltip for {@link ISyntacticReference}. */ -export function domTooltipSyntacticReference(ref: ISyntacticReference) { +export function domTooltipSyntacticReference(ref: ISyntacticReference, masterRef: string | undefined) { const DIMENSIONS = 'max-h-[25rem] max-w-[25rem] min-w-[10rem] w-fit z-tooltip px-2 py-2'; - const LAYOUT = 'flex flex-col gap-1 overflow-y-auto' + const LAYOUT = 'flex flex-col overflow-y-auto' const dom = document.createElement('div'); dom.className = `${DIMENSIONS} ${LAYOUT} border shadow-md text-sm select-none cursor-auto`; @@ -211,6 +215,10 @@ export function domTooltipSyntacticReference(ref: ISyntacticReference) { offset.innerHTML = `Смещение: ${ref.offset}`; dom.appendChild(offset); + const master = document.createElement('p'); + master.innerHTML = `Основная ссылка: ${masterRef ?? 'не определена'}`; + dom.appendChild(master); + const nominal = document.createElement('p'); nominal.innerHTML = `Начальная форма: ${ref.nominal}`; dom.appendChild(nominal);