corpushub-design-system 0.1.3 → 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/index.d.ts +1 -1
- package/package.json +4 -3
- package/dist/features/CytoscapeMenu/constants.d.ts +0 -38
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import cytoscape, { Core } from 'cytoscape';
|
|
2
|
-
import type { CytoscapeContextMenuOptions, MenuItemOption } from './
|
|
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 './
|
|
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(
|
|
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 './
|
|
2
|
-
import { DIVIDER_CSS_CLASS } from './
|
|
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
|
|
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(
|
|
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
|
|
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
|
|
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
|
|
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
|
|
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
|
|
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
|
|
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(
|
|
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 './
|
|
2
|
+
import type { CytoscapeContextMenuOptions, MenuItemOption } from './CytoscapeMenuConstants';
|
|
3
3
|
export interface ContextMenusInstance {
|
|
4
4
|
isActive: () => boolean;
|
|
5
5
|
appendMenuItem: (item: MenuItemOption, parentID?: string) => Core;
|
|
@@ -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();
|