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.
- package/dist/configs/localization/TreeTexts.d.ts +15 -0
- package/dist/configs/localization/TreeTexts.js +15 -0
- 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/TreeView/TreeView.d.ts +7 -1
- package/dist/features/TreeView/TreeView.js +40 -11
- package/dist/features/TreeView/TreeViewImportPenn/TreeViewImportPenn.d.ts +7 -0
- package/dist/features/TreeView/TreeViewImportPenn/TreeViewImportPenn.js +26 -0
- package/dist/features/TreeView/TreeViewImportPenn/index.d.ts +2 -0
- package/dist/features/TreeView/TreeViewImportPenn/index.js +2 -0
- package/dist/features/TreeView/TreeViewImportPenn/style.scss +22 -0
- package/dist/features/index.d.ts +1 -1
- package/package.json +4 -3
- package/dist/features/CytoscapeMenu/constants.d.ts +0 -38
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
import * as utils from './
|
|
2
|
-
import { DEFAULT_OPTS, DIVIDER_CSS_CLASS, INDICATOR_CSS_CLASS, } from './
|
|
1
|
+
import * as utils from './CytoscapeMenuUtils';
|
|
2
|
+
import { DEFAULT_OPTS, DIVIDER_CSS_CLASS, INDICATOR_CSS_CLASS, } from './CytoscapeMenuConstants';
|
|
3
3
|
import { MenuItem, ContextMenu, MenuItemList } from './context-menu';
|
|
4
|
+
import { PhrasePickerController, partitionMenuItems, } from './phrase-picker';
|
|
4
5
|
export function contextMenus(opts) {
|
|
5
6
|
const cy = this;
|
|
6
7
|
if (!cy.scratch('cycontextmenus')) {
|
|
@@ -10,6 +11,15 @@ export function contextMenus(opts) {
|
|
|
10
11
|
const setScratchProp = (propname, value) => (cy.scratch('cycontextmenus')[propname] = value);
|
|
11
12
|
let cxtMenu = getScratchProp('cxtMenu');
|
|
12
13
|
let options = getScratchProp('options');
|
|
14
|
+
let phrasePicker = getScratchProp('phrasePicker');
|
|
15
|
+
const isPickerLayout = () => options?.layout === 'picker';
|
|
16
|
+
/** Background / core cxttap — phrase-picker when layout is picker. */
|
|
17
|
+
const isCoreTarget = (target) => target === cy;
|
|
18
|
+
/**
|
|
19
|
+
* Cascade (classic) items shown on nodes/edges. Picker primaries use
|
|
20
|
+
* coreAsWell and are rendered by PhrasePickerController on the core.
|
|
21
|
+
*/
|
|
22
|
+
const isElementCascadeItem = (item) => Boolean(item.selector) && !item.coreAsWell;
|
|
13
23
|
const getVariation = (position) => {
|
|
14
24
|
if (typeof position === 'undefined')
|
|
15
25
|
return { x: 0, y: 0 };
|
|
@@ -28,6 +38,54 @@ export function contextMenus(opts) {
|
|
|
28
38
|
event.renderedPosition = position;
|
|
29
39
|
}
|
|
30
40
|
};
|
|
41
|
+
const showCascadeMenu = (target) => {
|
|
42
|
+
for (const menuItem of cxtMenu.children) {
|
|
43
|
+
if (menuItem instanceof MenuItem) {
|
|
44
|
+
const shouldDisplay = target === cy
|
|
45
|
+
? menuItem.coreAsWell
|
|
46
|
+
: target.is(menuItem.selector);
|
|
47
|
+
if (shouldDisplay && menuItem.show) {
|
|
48
|
+
cxtMenu.display();
|
|
49
|
+
setScratchProp('anyVisibleChild', true);
|
|
50
|
+
menuItem.display();
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
const visibleItems = Array.from(cxtMenu.children).filter((item) => {
|
|
55
|
+
if (item instanceof MenuItem)
|
|
56
|
+
return item.isVisible();
|
|
57
|
+
return false;
|
|
58
|
+
});
|
|
59
|
+
const length = visibleItems.length;
|
|
60
|
+
visibleItems.forEach((item, index) => {
|
|
61
|
+
if (!(item instanceof MenuItem))
|
|
62
|
+
return;
|
|
63
|
+
if (index < length - 1 && item.getHasTrailingDivider()) {
|
|
64
|
+
item.classList.add(DIVIDER_CSS_CLASS);
|
|
65
|
+
}
|
|
66
|
+
else if (item.getHasTrailingDivider()) {
|
|
67
|
+
item.classList.remove(DIVIDER_CSS_CLASS);
|
|
68
|
+
}
|
|
69
|
+
});
|
|
70
|
+
if (!getScratchProp('anyVisibleChild') &&
|
|
71
|
+
utils.isElementVisible(cxtMenu)) {
|
|
72
|
+
cxtMenu.hide();
|
|
73
|
+
}
|
|
74
|
+
};
|
|
75
|
+
const showPickerMenu = (target) => {
|
|
76
|
+
if (!phrasePicker || !cxtMenu)
|
|
77
|
+
return;
|
|
78
|
+
const partition = partitionMenuItems(options.menuItems || [], cy, target);
|
|
79
|
+
const hasContent = phrasePicker.render(partition);
|
|
80
|
+
if (hasContent) {
|
|
81
|
+
cxtMenu.display();
|
|
82
|
+
setScratchProp('anyVisibleChild', true);
|
|
83
|
+
}
|
|
84
|
+
else if (utils.isElementVisible(cxtMenu)) {
|
|
85
|
+
cxtMenu.hide();
|
|
86
|
+
setScratchProp('anyVisibleChild', false);
|
|
87
|
+
}
|
|
88
|
+
};
|
|
31
89
|
const bindOnCxttap = () => {
|
|
32
90
|
const onCxttap = (event, position, someNode) => {
|
|
33
91
|
if (typeof someNode !== 'undefined') {
|
|
@@ -36,37 +94,13 @@ export function contextMenus(opts) {
|
|
|
36
94
|
setScratchProp('currentCyEvent', event);
|
|
37
95
|
adjustCxtMenu(event, position);
|
|
38
96
|
const target = event.target || event.cyTarget;
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
? menuItem.coreAsWell
|
|
43
|
-
: target.is(menuItem.selector);
|
|
44
|
-
if (shouldDisplay && menuItem.show) {
|
|
45
|
-
cxtMenu.display();
|
|
46
|
-
setScratchProp('anyVisibleChild', true);
|
|
47
|
-
menuItem.display();
|
|
48
|
-
}
|
|
49
|
-
}
|
|
97
|
+
if (isPickerLayout() && isCoreTarget(target)) {
|
|
98
|
+
cxtMenu?.hideMenuItems();
|
|
99
|
+
showPickerMenu(target);
|
|
50
100
|
}
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
return false;
|
|
55
|
-
});
|
|
56
|
-
const length = visibleItems.length;
|
|
57
|
-
visibleItems.forEach((item, index) => {
|
|
58
|
-
if (!(item instanceof MenuItem))
|
|
59
|
-
return;
|
|
60
|
-
if (index < length - 1 && item.getHasTrailingDivider()) {
|
|
61
|
-
item.classList.add(DIVIDER_CSS_CLASS);
|
|
62
|
-
}
|
|
63
|
-
else if (item.getHasTrailingDivider()) {
|
|
64
|
-
item.classList.remove(DIVIDER_CSS_CLASS);
|
|
65
|
-
}
|
|
66
|
-
});
|
|
67
|
-
if (!getScratchProp('anyVisibleChild') &&
|
|
68
|
-
utils.isElementVisible(cxtMenu)) {
|
|
69
|
-
cxtMenu.hide();
|
|
101
|
+
else {
|
|
102
|
+
phrasePicker?.clear();
|
|
103
|
+
showCascadeMenu(target);
|
|
70
104
|
}
|
|
71
105
|
};
|
|
72
106
|
cy.on(options.evtType, onCxttap);
|
|
@@ -89,17 +123,32 @@ export function contextMenus(opts) {
|
|
|
89
123
|
cy.on('viewport', eventCyViewport);
|
|
90
124
|
setScratchProp('onViewport', eventCyViewport);
|
|
91
125
|
};
|
|
126
|
+
const hideContextMenu = () => {
|
|
127
|
+
phrasePicker?.clear();
|
|
128
|
+
cxtMenu?.hide();
|
|
129
|
+
setScratchProp('cxtMenuPosition', undefined);
|
|
130
|
+
setScratchProp('currentCyEvent', undefined);
|
|
131
|
+
};
|
|
92
132
|
const bindHideCallbacks = () => {
|
|
93
133
|
const onClick = (event) => {
|
|
94
134
|
const cyContainer = cy.container();
|
|
95
135
|
if (!cyContainer.contains(event.target) &&
|
|
96
136
|
!cxtMenu.contains(event.target)) {
|
|
97
|
-
|
|
98
|
-
setScratchProp('cxtMenuPosition', undefined);
|
|
137
|
+
hideContextMenu();
|
|
99
138
|
}
|
|
100
139
|
};
|
|
140
|
+
const onKeyDown = (event) => {
|
|
141
|
+
if (event.key !== 'Escape')
|
|
142
|
+
return;
|
|
143
|
+
if (!cxtMenu || !utils.isElementVisible(cxtMenu))
|
|
144
|
+
return;
|
|
145
|
+
event.preventDefault();
|
|
146
|
+
hideContextMenu();
|
|
147
|
+
};
|
|
101
148
|
document.addEventListener('mouseup', onClick);
|
|
149
|
+
document.addEventListener('keydown', onKeyDown);
|
|
102
150
|
setScratchProp('hideOnNonCyClick', onClick);
|
|
151
|
+
setScratchProp('hideOnEscape', onKeyDown);
|
|
103
152
|
};
|
|
104
153
|
const adjustCxtMenu = (event, position) => {
|
|
105
154
|
const container = cy.container();
|
|
@@ -108,6 +157,7 @@ export function contextMenus(opts) {
|
|
|
108
157
|
const cyPos = event.position ||
|
|
109
158
|
event.cyPosition;
|
|
110
159
|
if (currentCxtMenuPosition != cyPos) {
|
|
160
|
+
phrasePicker?.clear();
|
|
111
161
|
cxtMenu.hideMenuItems();
|
|
112
162
|
setScratchProp('anyVisibleChild', false);
|
|
113
163
|
setScratchProp('cxtMenuPosition', cyPos);
|
|
@@ -124,7 +174,11 @@ export function contextMenus(opts) {
|
|
|
124
174
|
const containerWidth = container.clientWidth;
|
|
125
175
|
const horizontalSplit = containerHeight / 2;
|
|
126
176
|
const verticalSplit = containerWidth / 2;
|
|
127
|
-
const
|
|
177
|
+
const tapTarget = event.target ||
|
|
178
|
+
event.cyTarget;
|
|
179
|
+
const variation = isPickerLayout() && isCoreTarget(tapTarget ?? cy)
|
|
180
|
+
? { x: 0, y: 8 }
|
|
181
|
+
: getVariation(position);
|
|
128
182
|
if (renderedPos.y > horizontalSplit && renderedPos.x <= verticalSplit) {
|
|
129
183
|
cxtMenu.style.left = renderedPos.x - variation.x + 'px';
|
|
130
184
|
cxtMenu.style.bottom =
|
|
@@ -158,6 +212,25 @@ export function contextMenus(opts) {
|
|
|
158
212
|
}
|
|
159
213
|
};
|
|
160
214
|
const createAndAppendMenuItemComponent = (opts, parentID) => {
|
|
215
|
+
// Picker layout keeps the full item tree in options for PhrasePickerController.
|
|
216
|
+
if (isPickerLayout()) {
|
|
217
|
+
if (typeof parentID !== 'undefined') {
|
|
218
|
+
const parent = (options.menuItems || []).find((item) => item.id === parentID);
|
|
219
|
+
if (parent) {
|
|
220
|
+
parent.submenu = parent.submenu || [];
|
|
221
|
+
parent.submenu.push(opts);
|
|
222
|
+
}
|
|
223
|
+
}
|
|
224
|
+
else {
|
|
225
|
+
options.menuItems = options.menuItems || [];
|
|
226
|
+
options.menuItems.push(opts);
|
|
227
|
+
}
|
|
228
|
+
setScratchProp('options', options);
|
|
229
|
+
// Also mount cascade DOM for node/edge utilities (remove, auto-connect).
|
|
230
|
+
if (!isElementCascadeItem(opts) || typeof parentID !== 'undefined') {
|
|
231
|
+
return;
|
|
232
|
+
}
|
|
233
|
+
}
|
|
161
234
|
const menuItemComponent = createMenuItemComponent(opts);
|
|
162
235
|
if (typeof parentID !== 'undefined') {
|
|
163
236
|
const parent = asMenuItem(parentID);
|
|
@@ -180,11 +253,21 @@ export function contextMenus(opts) {
|
|
|
180
253
|
if (!getScratchProp('active')) {
|
|
181
254
|
return;
|
|
182
255
|
}
|
|
183
|
-
|
|
256
|
+
phrasePicker?.clear();
|
|
257
|
+
phrasePicker = undefined;
|
|
258
|
+
setScratchProp('phrasePicker', undefined);
|
|
259
|
+
if (cxtMenu) {
|
|
260
|
+
const hasMenuItems = Array.from(cxtMenu.children).some((child) => child instanceof MenuItem);
|
|
261
|
+
if (hasMenuItems) {
|
|
262
|
+
cxtMenu.removeAllMenuItems();
|
|
263
|
+
}
|
|
264
|
+
cxtMenu.replaceChildren();
|
|
265
|
+
}
|
|
184
266
|
cy.off('tapstart', getScratchProp('eventCyTapStart'));
|
|
185
267
|
cy.off(options.evtType, getScratchProp('onCxttap'));
|
|
186
268
|
cy.off('viewport', getScratchProp('onViewport'));
|
|
187
269
|
document.removeEventListener('mouseup', getScratchProp('hideOnNonCyClick'));
|
|
270
|
+
document.removeEventListener('keydown', getScratchProp('hideOnEscape'));
|
|
188
271
|
cxtMenu.parentNode.removeChild(cxtMenu);
|
|
189
272
|
cxtMenu = undefined;
|
|
190
273
|
setScratchProp('cxtMenu', undefined);
|
|
@@ -209,6 +292,10 @@ export function contextMenus(opts) {
|
|
|
209
292
|
}
|
|
210
293
|
throw new Error(`The item with id=${menuItemID} is not a menu item`);
|
|
211
294
|
};
|
|
295
|
+
const hidePickerAndClear = () => {
|
|
296
|
+
cxtMenu?.hide();
|
|
297
|
+
setScratchProp('cxtMenuPosition', undefined);
|
|
298
|
+
};
|
|
212
299
|
const getInstance = () => {
|
|
213
300
|
const getCxtMenu = () => getScratchProp('cxtMenu');
|
|
214
301
|
return {
|
|
@@ -222,6 +309,16 @@ export function contextMenus(opts) {
|
|
|
222
309
|
return cy;
|
|
223
310
|
},
|
|
224
311
|
removeMenuItem: (itemID) => {
|
|
312
|
+
if (isPickerLayout()) {
|
|
313
|
+
options.menuItems = (options.menuItems || []).filter((item) => item.id !== itemID);
|
|
314
|
+
for (const item of options.menuItems) {
|
|
315
|
+
if (item.submenu) {
|
|
316
|
+
item.submenu = item.submenu.filter((child) => child.id !== itemID);
|
|
317
|
+
}
|
|
318
|
+
}
|
|
319
|
+
setScratchProp('options', options);
|
|
320
|
+
return cy;
|
|
321
|
+
}
|
|
225
322
|
const item = asMenuItem(itemID);
|
|
226
323
|
getCxtMenu()?.removeMenuItem(item);
|
|
227
324
|
return cy;
|
|
@@ -230,6 +327,8 @@ export function contextMenus(opts) {
|
|
|
230
327
|
getCxtMenu()?.hide();
|
|
231
328
|
},
|
|
232
329
|
setTrailingDivider: (itemID, status) => {
|
|
330
|
+
if (isPickerLayout())
|
|
331
|
+
return cy;
|
|
233
332
|
const menuItem = asMenuItem(itemID);
|
|
234
333
|
menuItem.setHasTrailingDivider(status);
|
|
235
334
|
if (status) {
|
|
@@ -241,12 +340,27 @@ export function contextMenus(opts) {
|
|
|
241
340
|
return cy;
|
|
242
341
|
},
|
|
243
342
|
insertBeforeMenuItem: (item, existingItemID) => {
|
|
343
|
+
if (isPickerLayout()) {
|
|
344
|
+
const list = options.menuItems || [];
|
|
345
|
+
const index = list.findIndex((entry) => entry.id === existingItemID);
|
|
346
|
+
if (index >= 0) {
|
|
347
|
+
list.splice(index, 0, item);
|
|
348
|
+
}
|
|
349
|
+
else {
|
|
350
|
+
list.push(item);
|
|
351
|
+
}
|
|
352
|
+
options.menuItems = list;
|
|
353
|
+
setScratchProp('options', options);
|
|
354
|
+
return cy;
|
|
355
|
+
}
|
|
244
356
|
const menuItemComponent = createMenuItemComponent(item);
|
|
245
357
|
const existingItem = asMenuItem(existingItemID);
|
|
246
358
|
getCxtMenu()?.insertMenuItem(menuItemComponent, { before: existingItem });
|
|
247
359
|
return cy;
|
|
248
360
|
},
|
|
249
361
|
moveToSubmenu: (itemID, optionsParam) => {
|
|
362
|
+
if (isPickerLayout())
|
|
363
|
+
return cy;
|
|
250
364
|
const item = asMenuItem(itemID);
|
|
251
365
|
const menu = getCxtMenu();
|
|
252
366
|
if (optionsParam === undefined || optionsParam === null) {
|
|
@@ -267,27 +381,81 @@ export function contextMenus(opts) {
|
|
|
267
381
|
return cy;
|
|
268
382
|
},
|
|
269
383
|
moveBeforeOtherMenuItem: (itemID, existingItemID) => {
|
|
384
|
+
if (isPickerLayout())
|
|
385
|
+
return cy;
|
|
270
386
|
const item = asMenuItem(itemID);
|
|
271
387
|
const before = asMenuItem(existingItemID);
|
|
272
388
|
getCxtMenu()?.moveBefore(item, before);
|
|
273
389
|
return cy;
|
|
274
390
|
},
|
|
275
391
|
disableMenuItem: (itemID) => {
|
|
392
|
+
if (isPickerLayout()) {
|
|
393
|
+
const markDisabled = (items) => {
|
|
394
|
+
for (const item of items) {
|
|
395
|
+
if (item.id === itemID)
|
|
396
|
+
item.disabled = true;
|
|
397
|
+
if (item.submenu)
|
|
398
|
+
markDisabled(item.submenu);
|
|
399
|
+
}
|
|
400
|
+
};
|
|
401
|
+
markDisabled(options.menuItems || []);
|
|
402
|
+
setScratchProp('options', options);
|
|
403
|
+
return cy;
|
|
404
|
+
}
|
|
276
405
|
const menuItem = asMenuItem(itemID);
|
|
277
406
|
menuItem.disable();
|
|
278
407
|
return cy;
|
|
279
408
|
},
|
|
280
409
|
enableMenuItem: (itemID) => {
|
|
410
|
+
if (isPickerLayout()) {
|
|
411
|
+
const markEnabled = (items) => {
|
|
412
|
+
for (const item of items) {
|
|
413
|
+
if (item.id === itemID)
|
|
414
|
+
item.disabled = false;
|
|
415
|
+
if (item.submenu)
|
|
416
|
+
markEnabled(item.submenu);
|
|
417
|
+
}
|
|
418
|
+
};
|
|
419
|
+
markEnabled(options.menuItems || []);
|
|
420
|
+
setScratchProp('options', options);
|
|
421
|
+
return cy;
|
|
422
|
+
}
|
|
281
423
|
const menuItem = asMenuItem(itemID);
|
|
282
424
|
menuItem.enable();
|
|
283
425
|
return cy;
|
|
284
426
|
},
|
|
285
427
|
hideMenuItem: (itemID) => {
|
|
428
|
+
if (isPickerLayout()) {
|
|
429
|
+
const markHidden = (items) => {
|
|
430
|
+
for (const item of items) {
|
|
431
|
+
if (item.id === itemID)
|
|
432
|
+
item.show = false;
|
|
433
|
+
if (item.submenu)
|
|
434
|
+
markHidden(item.submenu);
|
|
435
|
+
}
|
|
436
|
+
};
|
|
437
|
+
markHidden(options.menuItems || []);
|
|
438
|
+
setScratchProp('options', options);
|
|
439
|
+
return cy;
|
|
440
|
+
}
|
|
286
441
|
const menuItem = asMenuItem(itemID);
|
|
287
442
|
menuItem.hide();
|
|
288
443
|
return cy;
|
|
289
444
|
},
|
|
290
445
|
showMenuItem: (itemID) => {
|
|
446
|
+
if (isPickerLayout()) {
|
|
447
|
+
const markShown = (items) => {
|
|
448
|
+
for (const item of items) {
|
|
449
|
+
if (item.id === itemID)
|
|
450
|
+
item.show = true;
|
|
451
|
+
if (item.submenu)
|
|
452
|
+
markShown(item.submenu);
|
|
453
|
+
}
|
|
454
|
+
};
|
|
455
|
+
markShown(options.menuItems || []);
|
|
456
|
+
setScratchProp('options', options);
|
|
457
|
+
return cy;
|
|
458
|
+
}
|
|
291
459
|
const menuItem = asMenuItem(itemID);
|
|
292
460
|
menuItem.display();
|
|
293
461
|
return cy;
|
|
@@ -316,9 +484,28 @@ export function contextMenus(opts) {
|
|
|
316
484
|
cxtMenu = new ContextMenu(onMenuItemClick, scratchpad);
|
|
317
485
|
setScratchProp('cxtMenu', cxtMenu);
|
|
318
486
|
cy.container().appendChild(cxtMenu);
|
|
487
|
+
utils.stopOverlayPointerEvents(cxtMenu);
|
|
319
488
|
setScratchProp('cxtMenuItemClasses', utils.getClassStr(options.menuItemClasses || DEFAULT_OPTS.menuItemClasses));
|
|
320
|
-
|
|
321
|
-
|
|
489
|
+
if (isPickerLayout()) {
|
|
490
|
+
phrasePicker = new PhrasePickerController(cxtMenu, {
|
|
491
|
+
favoritesStorageKey: options.favoritesStorageKey,
|
|
492
|
+
favoritesAdapter: options.favoritesAdapter,
|
|
493
|
+
labels: options.labels,
|
|
494
|
+
getCurrentEvent: () => getScratchProp('currentCyEvent'),
|
|
495
|
+
onApply: hidePickerAndClear,
|
|
496
|
+
});
|
|
497
|
+
setScratchProp('phrasePicker', phrasePicker);
|
|
498
|
+
// Keep full tree for picker; mount cascade DOM only for node/edge utilities.
|
|
499
|
+
options.menuItems = options.menuItems || [];
|
|
500
|
+
setScratchProp('options', options);
|
|
501
|
+
for (const item of options.menuItems.filter(isElementCascadeItem)) {
|
|
502
|
+
cxtMenu.insertMenuItem(createMenuItemComponent(item));
|
|
503
|
+
}
|
|
504
|
+
}
|
|
505
|
+
else {
|
|
506
|
+
const menuItems = options.menuItems || [];
|
|
507
|
+
createAndAppendMenuItemComponents(menuItems);
|
|
508
|
+
}
|
|
322
509
|
bindOnCxttap();
|
|
323
510
|
bindCyEvents();
|
|
324
511
|
bindHideCallbacks();
|
|
@@ -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
|
+
}
|