corpushub-design-system 0.1.3 → 0.1.5

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.
Files changed (27) hide show
  1. package/dist/configs/localization/TreeTexts.d.ts +15 -0
  2. package/dist/configs/localization/TreeTexts.js +15 -0
  3. package/dist/features/CytoscapeMenu/CytoscapeMenuCanvas.d.ts +1 -1
  4. package/dist/features/CytoscapeMenu/CytoscapeMenuConstants.d.ts +66 -0
  5. package/dist/features/CytoscapeMenu/{constants.js → CytoscapeMenuConstants.js} +2 -0
  6. package/dist/features/CytoscapeMenu/{utils.d.ts → CytoscapeMenuUtils.d.ts} +5 -0
  7. package/dist/features/CytoscapeMenu/{utils.js → CytoscapeMenuUtils.js} +21 -0
  8. package/dist/features/CytoscapeMenu/context-menu.d.ts +2 -2
  9. package/dist/features/CytoscapeMenu/context-menu.js +17 -15
  10. package/dist/features/CytoscapeMenu/cytoscape-context-menus.d.ts +1 -1
  11. package/dist/features/CytoscapeMenu/cytoscape-context-menus.js +225 -38
  12. package/dist/features/CytoscapeMenu/favorites.d.ts +12 -0
  13. package/dist/features/CytoscapeMenu/favorites.js +77 -0
  14. package/dist/features/CytoscapeMenu/index.d.ts +1 -1
  15. package/dist/features/CytoscapeMenu/phrase-picker.d.ts +90 -0
  16. package/dist/features/CytoscapeMenu/phrase-picker.js +538 -0
  17. package/dist/features/CytoscapeMenu/style.scss +462 -19
  18. package/dist/features/TreeView/TreeView.d.ts +7 -1
  19. package/dist/features/TreeView/TreeView.js +40 -11
  20. package/dist/features/TreeView/TreeViewImportPenn/TreeViewImportPenn.d.ts +7 -0
  21. package/dist/features/TreeView/TreeViewImportPenn/TreeViewImportPenn.js +26 -0
  22. package/dist/features/TreeView/TreeViewImportPenn/index.d.ts +2 -0
  23. package/dist/features/TreeView/TreeViewImportPenn/index.js +2 -0
  24. package/dist/features/TreeView/TreeViewImportPenn/style.scss +22 -0
  25. package/dist/features/index.d.ts +1 -1
  26. package/package.json +4 -3
  27. package/dist/features/CytoscapeMenu/constants.d.ts +0 -38
@@ -4,10 +4,15 @@ export declare const TreeTexts: {
4
4
  'button.recenter.tree': string;
5
5
  'button.download.tree': string;
6
6
  'button.download.penn': string;
7
+ 'button.import.penn': string;
8
+ 'button.import': string;
9
+ 'button.revision.tree': string;
7
10
  'button.info': string;
8
11
  'placeholder.sentence.notparsed': string;
9
12
  'date.parsed': string;
10
13
  'button.search': string;
14
+ 'modal.import.penn.title': string;
15
+ 'modal.import.penn.placeholder': string;
11
16
  'label.syntactic.category': string;
12
17
  'label.pos.tag': string;
13
18
  'label.token.addTag': string;
@@ -19,10 +24,15 @@ export declare const TreeTexts: {
19
24
  'button.recenter.tree': string;
20
25
  'button.download.tree': string;
21
26
  'button.download.penn': string;
27
+ 'button.import.penn': string;
28
+ 'button.import': string;
29
+ 'button.revision.tree': string;
22
30
  'button.info': string;
23
31
  'placeholder.sentence.notparsed': string;
24
32
  'date.parsed': string;
25
33
  'button.search': string;
34
+ 'modal.import.penn.title': string;
35
+ 'modal.import.penn.placeholder': string;
26
36
  'label.syntactic.category': string;
27
37
  'label.pos.tag': string;
28
38
  'label.token.addTag': string;
@@ -34,9 +44,14 @@ export declare const TreeTexts: {
34
44
  'button.recenter.tree': string;
35
45
  'button.download.tree': string;
36
46
  'button.download.penn': string;
47
+ 'button.import.penn': string;
48
+ 'button.import': string;
49
+ 'button.revision.tree': string;
37
50
  'button.info': string;
38
51
  'date.parsed': string;
39
52
  'button.search': string;
53
+ 'modal.import.penn.title': string;
54
+ 'modal.import.penn.placeholder': string;
40
55
  'label.syntactic.category': string;
41
56
  'label.pos.tag': string;
42
57
  'label.token.addTag': string;
@@ -4,10 +4,15 @@ export const TreeTexts = {
4
4
  'button.recenter.tree': 'Recenter tree',
5
5
  'button.download.tree': 'Download tree as image',
6
6
  'button.download.penn': 'Download in Penn Tree format',
7
+ 'button.import.penn': 'Import Penn Tree format',
8
+ 'button.import': 'Import',
9
+ 'button.revision.tree': 'Open revision tree',
7
10
  'button.info': 'Display translations and glosses',
8
11
  'placeholder.sentence.notparsed': 'This sentence has not been parsed.',
9
12
  'date.parsed': 'Parsing executed at:',
10
13
  'button.search': 'Search',
14
+ 'modal.import.penn.title': 'Import Penn Treebank',
15
+ 'modal.import.penn.placeholder': 'Paste a Penn Treebank expression…',
11
16
  'label.syntactic.category': 'Syntactic Category',
12
17
  'label.pos.tag': 'POS Tag',
13
18
  'label.token.addTag': 'add tag',
@@ -19,10 +24,15 @@ export const TreeTexts = {
19
24
  'button.recenter.tree': 'Recentralizar árvore',
20
25
  'button.download.tree': 'Baixar árvore como imagem',
21
26
  'button.download.penn': 'Baixar no formato Penn Tree',
27
+ 'button.import.penn': 'Importar formato Penn Tree',
28
+ 'button.import': 'Importar',
29
+ 'button.revision.tree': 'Abrir árvore de revisão',
22
30
  'button.info': 'Mostrar traduções e glosas',
23
31
  'placeholder.sentence.notparsed': 'O parser não foi realizado nesta sentença.',
24
32
  'date.parsed': 'Parser executado às:',
25
33
  'button.search': 'Buscar',
34
+ 'modal.import.penn.title': 'Importar Penn Treebank',
35
+ 'modal.import.penn.placeholder': 'Cole uma expressão Penn Treebank…',
26
36
  'label.syntactic.category': 'Categoria Sintática',
27
37
  'label.pos.tag': 'Etiqueta POS',
28
38
  'label.token.addTag': 'adicionar etiqueta',
@@ -34,9 +44,14 @@ export const TreeTexts = {
34
44
  'button.recenter.tree': 'Ricentra albero',
35
45
  'button.download.tree': 'Scarica albero come immagine',
36
46
  'button.download.penn': 'Scarica in formato Penn Tree',
47
+ 'button.import.penn': 'Importa formato Penn Tree',
48
+ 'button.import': 'Importa',
49
+ 'button.revision.tree': 'Apri albero di revisione',
37
50
  'button.info': 'Visualizza traduzioni e glosse',
38
51
  'date.parsed': 'Parser eseguito alle:',
39
52
  'button.search': 'Cerca',
53
+ 'modal.import.penn.title': 'Importa Penn Treebank',
54
+ 'modal.import.penn.placeholder': 'Incolla un’espressione Penn Treebank…',
40
55
  'label.syntactic.category': 'Categoria Sintattica',
41
56
  'label.pos.tag': 'Etichetta POS',
42
57
  'label.token.addTag': 'aggiungi etichetta',
@@ -1,5 +1,5 @@
1
1
  import cytoscape, { Core } from 'cytoscape';
2
- import type { CytoscapeContextMenuOptions, MenuItemOption } from './constants';
2
+ import type { CytoscapeContextMenuOptions, MenuItemOption } from './CytoscapeMenuConstants';
3
3
  import './style.scss';
4
4
  export interface CytoscapeMenuCanvasProps {
5
5
  /** Unique id for the container element */
@@ -0,0 +1,66 @@
1
+ export declare const CXT_MENU_CSS_CLASS = "cy-context-menus-cxt-menu";
2
+ export declare const MENUITEM_CSS_CLASS = "cy-context-menus-cxt-menuitem";
3
+ export declare const DIVIDER_CSS_CLASS = "cy-context-menus-divider";
4
+ export declare const INDICATOR_CSS_CLASS = "cy-context-menus-submenu-indicator";
5
+ export interface MenuItemImage {
6
+ src: string;
7
+ width: number;
8
+ height: number;
9
+ y: string;
10
+ x: string;
11
+ }
12
+ import type { EventObject } from 'cytoscape';
13
+ import type { FavoritesAdapter } from './favorites';
14
+ export type { FavoritesAdapter, FavoritesMap } from './favorites';
15
+ export interface MenuItemOption {
16
+ id: string;
17
+ content: string;
18
+ tooltipText?: string;
19
+ selector: string;
20
+ disabled?: boolean;
21
+ image?: MenuItemImage;
22
+ show?: boolean;
23
+ submenu?: MenuItemOption[];
24
+ coreAsWell?: boolean;
25
+ onClickFunction?: (event: EventObject) => void;
26
+ hasTrailingDivider?: boolean;
27
+ /** When true, terminal shows a favorites star (picker layout). Defaults to true for clickable leaves. */
28
+ favoritable?: boolean;
29
+ /**
30
+ * Picker layout role for root items without a submenu:
31
+ * - `utility` (default): compact action strip (e.g. remove, auto-connect)
32
+ * - `primary`: peer choice beside catalog branches (e.g. add syntactic phrase)
33
+ */
34
+ pickerRole?: 'utility' | 'primary';
35
+ }
36
+ export interface SubmenuIndicatorOption {
37
+ src: string;
38
+ width: number;
39
+ height: number;
40
+ }
41
+ export type ContextMenuLayout = 'cascade' | 'picker';
42
+ export interface CytoscapeContextMenuOptions {
43
+ evtType?: string;
44
+ menuItems?: MenuItemOption[];
45
+ menuItemClasses?: string[];
46
+ contextMenuClasses?: string[];
47
+ submenuIndicator?: SubmenuIndicatorOption;
48
+ /**
49
+ * `cascade` — classic nested flyout menus.
50
+ * `picker` — phrase panel on core/background; classic cascade items
51
+ * (selector, not coreAsWell) on nodes/edges.
52
+ */
53
+ layout?: ContextMenuLayout;
54
+ /** localStorage key for starred phrase leaves (picker layout). */
55
+ favoritesStorageKey?: string;
56
+ /**
57
+ * Optional host-owned persistence for favorites (e.g. User.settings).
58
+ * When set, localStorage is not used for load/save.
59
+ */
60
+ favoritesAdapter?: FavoritesAdapter;
61
+ /** Host-provided UI copy for picker layout (i18n). */
62
+ labels?: {
63
+ favorites?: string;
64
+ };
65
+ }
66
+ export declare const DEFAULT_OPTS: CytoscapeContextMenuOptions;
@@ -7,6 +7,8 @@ export const DEFAULT_OPTS = {
7
7
  menuItems: [],
8
8
  menuItemClasses: [MENUITEM_CSS_CLASS],
9
9
  contextMenuClasses: [CXT_MENU_CSS_CLASS],
10
+ layout: 'cascade',
11
+ favoritesStorageKey: 'cy-phrase-picker-favorites',
10
12
  submenuIndicator: {
11
13
  src: 'data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHdpZHRoPSIxMiIgaGVpZ2h0PSIxMiIgdmlld0JveD0iMCAwIDEyIDEyIj48cGF0aCBmaWxsPSIjNjY2IiBkPSJNNCA0IEw4IDggTDQgMTIiLz48L3N2Zz4=',
12
14
  width: 12,
@@ -8,6 +8,11 @@ export declare function isElementVisible(elem: HTMLElement): boolean;
8
8
  export declare function extend<T extends Record<string, unknown>>(defaults: T, options: Partial<T>): T;
9
9
  export declare function getClassStr(classes: string[]): string;
10
10
  export declare function preventDefaultContextTap(): void;
11
+ /**
12
+ * Keep HTML overlay interactions from reaching the Cytoscape container.
13
+ * Only stopPropagation — preventDefault breaks native controls (e.g. <select>).
14
+ */
15
+ export declare function stopOverlayPointerEvents(element: HTMLElement): void;
11
16
  export declare function setBooleanAttribute(element: Element, attribute: string, boolValue: boolean): void;
12
17
  export declare function isIn({ x, y }: {
13
18
  x: number;
@@ -45,6 +45,27 @@ export function preventDefaultContextTap() {
45
45
  cxtMenuArea.addEventListener('contextmenu', (e) => e.preventDefault());
46
46
  }
47
47
  }
48
+ const OVERLAY_POINTER_EVENTS = [
49
+ 'mousedown',
50
+ 'mouseup',
51
+ 'pointerdown',
52
+ 'pointerup',
53
+ 'touchstart',
54
+ 'touchend',
55
+ 'click',
56
+ ];
57
+ /**
58
+ * Keep HTML overlay interactions from reaching the Cytoscape container.
59
+ * Only stopPropagation — preventDefault breaks native controls (e.g. <select>).
60
+ */
61
+ export function stopOverlayPointerEvents(element) {
62
+ const stop = (event) => {
63
+ event.stopPropagation();
64
+ };
65
+ for (const type of OVERLAY_POINTER_EVENTS) {
66
+ element.addEventListener(type, stop);
67
+ }
68
+ }
48
69
  export function setBooleanAttribute(element, attribute, boolValue) {
49
70
  if (boolValue) {
50
71
  element.setAttribute(attribute, '');
@@ -1,5 +1,5 @@
1
1
  import type { EventObject } from 'cytoscape';
2
- import type { MenuItemOption } from './constants';
2
+ import type { MenuItemOption } from './CytoscapeMenuConstants';
3
3
  export interface Scratchpad {
4
4
  cxtMenuItemClasses: string;
5
5
  cxtMenuClasses: string;
@@ -36,7 +36,7 @@ export declare class MenuItem extends HTMLButtonElement {
36
36
  isVisible(): boolean;
37
37
  removeSubmenu(): void;
38
38
  detachSubmenu(): void;
39
- _onMouseEnter(_event: MouseEvent): void;
39
+ _onMouseEnter(): void;
40
40
  _onMouseLeave(event: MouseEvent): void;
41
41
  _createSubmenu(items?: MenuItemOption[]): void;
42
42
  _getMenuItemClassStr(classStr: string, hasTrailingDivider?: boolean): string;
@@ -1,5 +1,5 @@
1
- import { setBooleanAttribute, isIn, getDimensionsHidden, defineCustomElement, } from './utils';
2
- import { DIVIDER_CSS_CLASS } from './constants';
1
+ import { setBooleanAttribute, isIn, getDimensionsHidden, defineCustomElement, } from './CytoscapeMenuUtils';
2
+ import { DIVIDER_CSS_CLASS } from './CytoscapeMenuConstants';
3
3
  function stopEvent(event) {
4
4
  event.preventDefault();
5
5
  event.stopPropagation();
@@ -9,7 +9,7 @@ export class MenuItem extends HTMLButtonElement {
9
9
  super();
10
10
  this.clickFns = [];
11
11
  super.setAttribute('id', params.id);
12
- const className = this._getMenuItemClassStr(scratchpad['cxtMenuItemClasses'], params.hasTrailingDivider);
12
+ const className = this._getMenuItemClassStr(scratchpad.cxtMenuItemClasses, params.hasTrailingDivider);
13
13
  super.setAttribute('class', className);
14
14
  super.setAttribute('title', params.tooltipText ?? '');
15
15
  if (params.disabled) {
@@ -114,31 +114,31 @@ export class MenuItem extends HTMLButtonElement {
114
114
  this.indicator = undefined;
115
115
  }
116
116
  }
117
- _onMouseEnter(_event) {
117
+ _onMouseEnter() {
118
118
  const rect = this.getBoundingClientRect();
119
119
  const submenuRect = getDimensionsHidden(this.submenu);
120
120
  const exceedsRight = rect.right + submenuRect.width > window.innerWidth;
121
121
  const exceedsBottom = rect.top + submenuRect.height > window.innerHeight;
122
122
  if (!exceedsRight && !exceedsBottom) {
123
- this.submenu.style.left = this.clientWidth + 'px';
123
+ this.submenu.style.left = `${this.clientWidth}px`;
124
124
  this.submenu.style.top = '0px';
125
125
  this.submenu.style.right = 'auto';
126
126
  this.submenu.style.bottom = 'auto';
127
127
  }
128
128
  else if (exceedsRight && !exceedsBottom) {
129
- this.submenu.style.right = this.clientWidth + 'px';
129
+ this.submenu.style.right = `${this.clientWidth}px`;
130
130
  this.submenu.style.top = '0px';
131
131
  this.submenu.style.left = 'auto';
132
132
  this.submenu.style.bottom = 'auto';
133
133
  }
134
134
  else if (exceedsRight && exceedsBottom) {
135
- this.submenu.style.right = this.clientWidth + 'px';
135
+ this.submenu.style.right = `${this.clientWidth}px`;
136
136
  this.submenu.style.bottom = '0px';
137
137
  this.submenu.style.top = 'auto';
138
138
  this.submenu.style.left = 'auto';
139
139
  }
140
140
  else {
141
- this.submenu.style.left = this.clientWidth + 'px';
141
+ this.submenu.style.left = `${this.clientWidth}px`;
142
142
  this.submenu.style.bottom = '0px';
143
143
  this.submenu.style.right = 'auto';
144
144
  this.submenu.style.top = 'auto';
@@ -168,7 +168,7 @@ export class MenuItem extends HTMLButtonElement {
168
168
  }
169
169
  }
170
170
  _createSubmenu(items = []) {
171
- this.indicator = this.scratchpad['submenuIndicatorGen']();
171
+ this.indicator = this.scratchpad.submenuIndicatorGen();
172
172
  this.submenu = new MenuItemList(this.onMenuItemClick, this.scratchpad);
173
173
  this.appendChild(this.indicator);
174
174
  this.appendChild(this.submenu);
@@ -193,7 +193,7 @@ export class MenuItem extends HTMLButtonElement {
193
193
  export class MenuItemList extends HTMLDivElement {
194
194
  constructor(onMenuItemClick, scratchpad) {
195
195
  super();
196
- super.setAttribute('class', scratchpad['cxtMenuClasses']);
196
+ super.setAttribute('class', scratchpad.cxtMenuClasses);
197
197
  this.style.position = 'absolute';
198
198
  this.onMenuItemClick = onMenuItemClick;
199
199
  this.scratchpad = scratchpad;
@@ -216,7 +216,7 @@ export class MenuItemList extends HTMLDivElement {
216
216
  item.style.display = 'none';
217
217
  }
218
218
  else {
219
- console.warn(`${item} is not a HTMLElement`);
219
+ console.warn(`${String(item)} is not a HTMLElement`);
220
220
  }
221
221
  }
222
222
  }
@@ -292,7 +292,9 @@ export class MenuItemList extends HTMLDivElement {
292
292
  _performBindings(menuItem) {
293
293
  const callback = this._bindOnClick(menuItem.onClickFunction);
294
294
  menuItem.bindOnClickFunction(callback);
295
- menuItem.bindOnClickFunction(this.onMenuItemClick);
295
+ menuItem.bindOnClickFunction(() => {
296
+ this.onMenuItemClick(new Event('click'));
297
+ });
296
298
  }
297
299
  _bindOnClick(onClickFn) {
298
300
  return () => {
@@ -353,7 +355,7 @@ export class ContextMenu extends MenuItemList {
353
355
  }
354
356
  moveBefore(menuItem, before) {
355
357
  const parent = menuItem.parentElement;
356
- if (this.contains(parent)) {
358
+ if (parent !== null && this.contains(parent)) {
357
359
  if (this.contains(before)) {
358
360
  parent.removeChild(menuItem);
359
361
  this.insertMenuItem(menuItem, { before });
@@ -363,7 +365,7 @@ export class ContextMenu extends MenuItemList {
363
365
  }
364
366
  }
365
367
  else {
366
- throw new Error(`parent(id=${parent?.id}) is not in the context menu`);
368
+ throw new Error(`parent(id=${parent?.id ?? 'none'}) is not in the context menu`);
367
369
  }
368
370
  }
369
371
  moveToSubmenu(menuItem, parent = null, options = null) {
@@ -393,7 +395,7 @@ export class ContextMenu extends MenuItemList {
393
395
  }
394
396
  }
395
397
  else {
396
- throw new Error(`current parent(id=${oldParent?.id}) is not a submenu`);
398
+ throw new Error(`current parent(id=${oldParent?.id ?? 'none'}) is not a submenu`);
397
399
  }
398
400
  }
399
401
  ensureDoesntContain(id) {
@@ -1,5 +1,5 @@
1
1
  import type { Core } from 'cytoscape';
2
- import type { CytoscapeContextMenuOptions, MenuItemOption } from './constants';
2
+ import type { CytoscapeContextMenuOptions, MenuItemOption } from './CytoscapeMenuConstants';
3
3
  export interface ContextMenusInstance {
4
4
  isActive: () => boolean;
5
5
  appendMenuItem: (item: MenuItemOption, parentID?: string) => Core;