corpushub-design-system 0.1.2 → 0.1.4
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/dist/features/CytoscapeMenu/CytoscapeMenuCanvas.d.ts +1 -1
- package/dist/features/CytoscapeMenu/CytoscapeMenuConstants.d.ts +66 -0
- package/dist/features/CytoscapeMenu/{constants.js → CytoscapeMenuConstants.js} +2 -0
- package/dist/features/CytoscapeMenu/{utils.d.ts → CytoscapeMenuUtils.d.ts} +5 -0
- package/dist/features/CytoscapeMenu/{utils.js → CytoscapeMenuUtils.js} +21 -0
- package/dist/features/CytoscapeMenu/context-menu.d.ts +2 -2
- package/dist/features/CytoscapeMenu/context-menu.js +17 -15
- package/dist/features/CytoscapeMenu/cytoscape-context-menus.d.ts +1 -1
- package/dist/features/CytoscapeMenu/cytoscape-context-menus.js +225 -38
- package/dist/features/CytoscapeMenu/favorites.d.ts +12 -0
- package/dist/features/CytoscapeMenu/favorites.js +77 -0
- package/dist/features/CytoscapeMenu/index.d.ts +1 -1
- package/dist/features/CytoscapeMenu/phrase-picker.d.ts +90 -0
- package/dist/features/CytoscapeMenu/phrase-picker.js +538 -0
- package/dist/features/CytoscapeMenu/style.scss +462 -19
- package/dist/features/ServerErrorReport/ServerErrorReport.js +1 -1
- package/dist/features/ServerErrorReport/ServerErrorReportForm.js +9 -3
- package/dist/features/index.d.ts +1 -1
- package/package.json +4 -3
- package/dist/features/CytoscapeMenu/constants.d.ts +0 -38
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
declare const DEFAULT_STORAGE_KEY = "cy-phrase-picker-favorites";
|
|
2
|
+
/** branchId → favorite item ids */
|
|
3
|
+
export type FavoritesMap = Record<string, string[]>;
|
|
4
|
+
export type FavoritesAdapter = {
|
|
5
|
+
load: () => FavoritesMap;
|
|
6
|
+
save: (map: FavoritesMap) => void;
|
|
7
|
+
};
|
|
8
|
+
export declare function loadFavoritesMap(storageKey?: string, adapter?: FavoritesAdapter): FavoritesMap;
|
|
9
|
+
export declare function saveFavoritesMap(map: FavoritesMap, storageKey?: string, adapter?: FavoritesAdapter): void;
|
|
10
|
+
export declare function loadFavoriteIds(branchId: string, storageKey?: string, adapter?: FavoritesAdapter): string[];
|
|
11
|
+
export declare function toggleFavoriteId(branchId: string, id: string, storageKey?: string, adapter?: FavoritesAdapter): string[];
|
|
12
|
+
export { DEFAULT_STORAGE_KEY };
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
const DEFAULT_STORAGE_KEY = 'cy-phrase-picker-favorites';
|
|
2
|
+
function normalizeFavoritesMap(parsed) {
|
|
3
|
+
// Legacy: flat string[] → migrate under "_"
|
|
4
|
+
if (Array.isArray(parsed)) {
|
|
5
|
+
const ids = parsed.filter((id) => typeof id === 'string');
|
|
6
|
+
return ids.length ? { _: ids } : {};
|
|
7
|
+
}
|
|
8
|
+
if (!parsed || typeof parsed !== 'object')
|
|
9
|
+
return {};
|
|
10
|
+
const map = {};
|
|
11
|
+
for (const [key, value] of Object.entries(parsed)) {
|
|
12
|
+
if (Array.isArray(value)) {
|
|
13
|
+
map[key] = value.filter((id) => typeof id === 'string');
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
return map;
|
|
17
|
+
}
|
|
18
|
+
export function loadFavoritesMap(storageKey = DEFAULT_STORAGE_KEY, adapter) {
|
|
19
|
+
if (adapter) {
|
|
20
|
+
try {
|
|
21
|
+
return normalizeFavoritesMap(adapter.load());
|
|
22
|
+
}
|
|
23
|
+
catch {
|
|
24
|
+
return {};
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
try {
|
|
28
|
+
const raw = localStorage.getItem(storageKey);
|
|
29
|
+
if (!raw)
|
|
30
|
+
return {};
|
|
31
|
+
return normalizeFavoritesMap(JSON.parse(raw));
|
|
32
|
+
}
|
|
33
|
+
catch {
|
|
34
|
+
return {};
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
export function saveFavoritesMap(map, storageKey = DEFAULT_STORAGE_KEY, adapter) {
|
|
38
|
+
if (adapter) {
|
|
39
|
+
try {
|
|
40
|
+
adapter.save(map);
|
|
41
|
+
}
|
|
42
|
+
catch {
|
|
43
|
+
// Host persist failure — keep in-memory map for this session.
|
|
44
|
+
}
|
|
45
|
+
return;
|
|
46
|
+
}
|
|
47
|
+
try {
|
|
48
|
+
localStorage.setItem(storageKey, JSON.stringify(map));
|
|
49
|
+
}
|
|
50
|
+
catch {
|
|
51
|
+
// Quota / private mode — favorites stay session-only.
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
export function loadFavoriteIds(branchId, storageKey = DEFAULT_STORAGE_KEY, adapter) {
|
|
55
|
+
const map = loadFavoritesMap(storageKey, adapter);
|
|
56
|
+
const branch = map[branchId] ?? [];
|
|
57
|
+
// Legacy flat list falls back for unscoped catalogs
|
|
58
|
+
if (branch.length === 0 && branchId !== '_' && map._?.length) {
|
|
59
|
+
return map._;
|
|
60
|
+
}
|
|
61
|
+
return [...branch];
|
|
62
|
+
}
|
|
63
|
+
export function toggleFavoriteId(branchId, id, storageKey = DEFAULT_STORAGE_KEY, adapter) {
|
|
64
|
+
const map = loadFavoritesMap(storageKey, adapter);
|
|
65
|
+
const current = map[branchId] ?? [];
|
|
66
|
+
const next = current.includes(id)
|
|
67
|
+
? current.filter((x) => x !== id)
|
|
68
|
+
: [...current, id];
|
|
69
|
+
map[branchId] = next;
|
|
70
|
+
if (map._) {
|
|
71
|
+
// Drop legacy bucket once scoped writes begin
|
|
72
|
+
delete map._;
|
|
73
|
+
}
|
|
74
|
+
saveFavoritesMap(map, storageKey, adapter);
|
|
75
|
+
return next;
|
|
76
|
+
}
|
|
77
|
+
export { DEFAULT_STORAGE_KEY };
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import cytoscape from 'cytoscape';
|
|
2
2
|
import { contextMenus } from './cytoscape-context-menus';
|
|
3
|
-
export type { CytoscapeContextMenuOptions, MenuItemOption } from './
|
|
3
|
+
export type { CytoscapeContextMenuOptions, MenuItemOption, ContextMenuLayout, FavoritesAdapter, FavoritesMap, } from './CytoscapeMenuConstants';
|
|
4
4
|
export type { ContextMenusInstance } from './cytoscape-context-menus';
|
|
5
5
|
export { contextMenus };
|
|
6
6
|
export declare function registerCytoscapeContextMenus(cy?: typeof cytoscape): void;
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
import type { Collection, Core, EventObject } from 'cytoscape';
|
|
2
|
+
import type { MenuItemOption } from './CytoscapeMenuConstants';
|
|
3
|
+
import { type FavoritesAdapter } from './favorites';
|
|
4
|
+
export interface PhraseLeaf {
|
|
5
|
+
id: string;
|
|
6
|
+
content: string;
|
|
7
|
+
tooltipText?: string;
|
|
8
|
+
disabled?: boolean;
|
|
9
|
+
favoritable: boolean;
|
|
10
|
+
onClickFunction?: (event: EventObject) => void;
|
|
11
|
+
categoryId: string;
|
|
12
|
+
categoryTitle: string;
|
|
13
|
+
}
|
|
14
|
+
export interface PhraseCategory {
|
|
15
|
+
id: string;
|
|
16
|
+
content: string;
|
|
17
|
+
disabled?: boolean;
|
|
18
|
+
leaves: PhraseLeaf[];
|
|
19
|
+
}
|
|
20
|
+
export interface PrimaryCatalog {
|
|
21
|
+
kind: 'catalog';
|
|
22
|
+
id: string;
|
|
23
|
+
content: string;
|
|
24
|
+
disabled?: boolean;
|
|
25
|
+
categories: PhraseCategory[];
|
|
26
|
+
}
|
|
27
|
+
/** Flat choice list shown as select + confirm + star (e.g. add syntactic phrase). */
|
|
28
|
+
export interface PrimarySelect {
|
|
29
|
+
kind: 'select';
|
|
30
|
+
id: string;
|
|
31
|
+
content: string;
|
|
32
|
+
disabled?: boolean;
|
|
33
|
+
options: PhraseLeaf[];
|
|
34
|
+
}
|
|
35
|
+
export type PrimaryChoice = PrimaryCatalog | PrimarySelect;
|
|
36
|
+
export interface PartitionedMenu {
|
|
37
|
+
primaries: PrimaryChoice[];
|
|
38
|
+
}
|
|
39
|
+
export interface PhrasePickerOptions {
|
|
40
|
+
favoritesStorageKey?: string;
|
|
41
|
+
favoritesAdapter?: FavoritesAdapter;
|
|
42
|
+
labels?: {
|
|
43
|
+
favorites?: string;
|
|
44
|
+
};
|
|
45
|
+
onApply: () => void;
|
|
46
|
+
getCurrentEvent: () => EventObject | undefined;
|
|
47
|
+
}
|
|
48
|
+
/** Split root menu items into peer primaries (utilities ignored). */
|
|
49
|
+
export declare function partitionMenuItems(items: MenuItemOption[], cy: Core, target: Collection | Core): PartitionedMenu;
|
|
50
|
+
export declare class PhrasePickerController {
|
|
51
|
+
private root;
|
|
52
|
+
/** Isolated host so cascade MenuItem siblings survive clear/render. */
|
|
53
|
+
private host;
|
|
54
|
+
private options;
|
|
55
|
+
private primaries;
|
|
56
|
+
private activePrimaryId;
|
|
57
|
+
private activeCategoryId;
|
|
58
|
+
/** Selected option id inside an active PrimarySelect. */
|
|
59
|
+
private selectedOptionId;
|
|
60
|
+
private favoriteIdsByBranch;
|
|
61
|
+
private favoriteIndex;
|
|
62
|
+
constructor(root: HTMLElement, options: PhrasePickerOptions);
|
|
63
|
+
private ensureHost;
|
|
64
|
+
clear(): void;
|
|
65
|
+
render(partition: PartitionedMenu): boolean;
|
|
66
|
+
private storageKey;
|
|
67
|
+
private favoritesAdapter;
|
|
68
|
+
private rebuildFavoriteIndex;
|
|
69
|
+
private activeCatalogCategories;
|
|
70
|
+
private activeSelect;
|
|
71
|
+
private activeBranchId;
|
|
72
|
+
private build;
|
|
73
|
+
private buildPrimaries;
|
|
74
|
+
private buildSelectPanel;
|
|
75
|
+
private goBackToPrimaries;
|
|
76
|
+
private favoriteTargetsForBranch;
|
|
77
|
+
/**
|
|
78
|
+
* Selected-branch chrome: heading (back + title), then Favorites only when
|
|
79
|
+
* that branch has starred items. Navigation handlers unchanged.
|
|
80
|
+
*/
|
|
81
|
+
private buildSelectedHeader;
|
|
82
|
+
/** Catalog favorites include the category (e.g. NP-SBJ/*); select favorites stay as the option label. */
|
|
83
|
+
private favoriteLabel;
|
|
84
|
+
private buildFavoriteChip;
|
|
85
|
+
private buildBody;
|
|
86
|
+
private buildLeafRow;
|
|
87
|
+
private buildStarButton;
|
|
88
|
+
private rerender;
|
|
89
|
+
private applyLeaf;
|
|
90
|
+
}
|