@kubex/zinc 1.1.86 → 1.1.88
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/custom-elements.json +368 -358
- package/dist/vscode.html-custom-data.json +15 -15
- package/dist/web-types.json +39 -39
- package/dist/zn.d.ts +8 -32
- package/dist/zn.min.js +230 -247
- package/package.json +1 -1
- package/src/components/editor/modules/context-menu/context-menu-tool.test.ts +36 -7
- package/src/components/editor/modules/context-menu/context-menu.ts +108 -118
- package/src/components/editor/modules/toolbar/toolbar.ts +4 -1
- package/src/components/slash-menu/slash-menu.component.ts +24 -5
- package/src/components/slash-menu/slash-menu.scss +2 -2
- package/src/components/slash-menu/slash-menu.test.ts +13 -1
- package/src/components/editor/modules/context-menu/context-menu-component.ts +0 -116
- package/src/components/editor/modules/context-menu/context-menu.scss +0 -49
|
@@ -1,116 +0,0 @@
|
|
|
1
|
-
import {type CSSResultGroup, html, type PropertyValues, unsafeCSS} from 'lit';
|
|
2
|
-
import {property, state} from 'lit/decorators.js';
|
|
3
|
-
import ZincElement from "../../../../internal/zinc-element";
|
|
4
|
-
|
|
5
|
-
import styles from './context-menu.scss';
|
|
6
|
-
|
|
7
|
-
export interface ResultItem {
|
|
8
|
-
icon: string;
|
|
9
|
-
label: string;
|
|
10
|
-
format?: string;
|
|
11
|
-
key?: string;
|
|
12
|
-
value?: string | boolean;
|
|
13
|
-
order?: number;
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
export default class ContextMenuComponent extends ZincElement {
|
|
17
|
-
static styles: CSSResultGroup = unsafeCSS(styles);
|
|
18
|
-
|
|
19
|
-
@property({type: Boolean, reflect: true}) open = false;
|
|
20
|
-
@property({type: String}) query = '';
|
|
21
|
-
@property({type: Array}) results: ResultItem[] = [];
|
|
22
|
-
|
|
23
|
-
@state() private _activeIndex = -1;
|
|
24
|
-
|
|
25
|
-
public show() {
|
|
26
|
-
this.open = true;
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
public hide() {
|
|
30
|
-
this.open = false;
|
|
31
|
-
this._activeIndex = -1;
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
setPosition(left: number, top: number) {
|
|
35
|
-
this.style.left = `${Math.max(0, left)}px`;
|
|
36
|
-
this.style.top = `${top}px`;
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
setActiveIndex(index: number) {
|
|
40
|
-
const len = this.results?.length ?? 0;
|
|
41
|
-
if (!len) {
|
|
42
|
-
this._activeIndex = -1;
|
|
43
|
-
return;
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
if (index < 0) {
|
|
47
|
-
index = len - 1;
|
|
48
|
-
}
|
|
49
|
-
if (index >= len) {
|
|
50
|
-
index = 0;
|
|
51
|
-
}
|
|
52
|
-
this._activeIndex = index;
|
|
53
|
-
this.requestUpdate();
|
|
54
|
-
|
|
55
|
-
requestAnimationFrame(() => {
|
|
56
|
-
const items = Array.from(this.renderRoot.querySelectorAll<HTMLButtonElement>('[data-toolbar-option]'));
|
|
57
|
-
const active = items[this._activeIndex];
|
|
58
|
-
active?.scrollIntoView?.({block: 'nearest'});
|
|
59
|
-
});
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
getActiveIndex() {
|
|
63
|
-
return this._activeIndex;
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
private _onClickItem = (e: MouseEvent) => {
|
|
67
|
-
const target = e.currentTarget as HTMLElement | null;
|
|
68
|
-
if (!target) return;
|
|
69
|
-
|
|
70
|
-
const idx = parseInt(target.dataset.index || '-1', 10);
|
|
71
|
-
if (Number.isNaN(idx)) return;
|
|
72
|
-
|
|
73
|
-
this.setActiveIndex(idx);
|
|
74
|
-
|
|
75
|
-
const item = this.results?.[idx];
|
|
76
|
-
if (!item) return;
|
|
77
|
-
|
|
78
|
-
this.dispatchEvent(new CustomEvent('zn-format-select', {
|
|
79
|
-
bubbles: true,
|
|
80
|
-
composed: true,
|
|
81
|
-
detail: {icon: item.icon, label: item.label, format: item.format, value: item.value, key: item.key}
|
|
82
|
-
}));
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
protected willUpdate(changed: PropertyValues) {
|
|
86
|
-
if (changed.has('results')) {
|
|
87
|
-
// Reset active index when results change
|
|
88
|
-
this._activeIndex = this.results?.length ? 0 : -1;
|
|
89
|
-
}
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
render() {
|
|
93
|
-
return html`
|
|
94
|
-
<div class="header">${this.query ? `Search: ${this.query}` : 'Options'}</div>
|
|
95
|
-
${Array.isArray(this.results) && this.results.length > 0 ? (
|
|
96
|
-
this.results.slice(0, 20).map((res, i) => html`
|
|
97
|
-
<button
|
|
98
|
-
type="button"
|
|
99
|
-
class="item"
|
|
100
|
-
role="option"
|
|
101
|
-
aria-selected="${String(i === this._activeIndex)}"
|
|
102
|
-
data-toolbar-option
|
|
103
|
-
data-index="${i}"
|
|
104
|
-
@click="${this._onClickItem}"
|
|
105
|
-
>
|
|
106
|
-
<zn-icon src="${res.icon}" size="16"></zn-icon>
|
|
107
|
-
<span class="label">${res.label}</span>
|
|
108
|
-
</button>
|
|
109
|
-
`)
|
|
110
|
-
) : html`
|
|
111
|
-
<div class="empty">${this.query ? 'No results' : 'Type something'}</div>`}
|
|
112
|
-
`;
|
|
113
|
-
}
|
|
114
|
-
}
|
|
115
|
-
|
|
116
|
-
ContextMenuComponent.define('zn-context-menu');
|
|
@@ -1,49 +0,0 @@
|
|
|
1
|
-
:host {
|
|
2
|
-
position: absolute;
|
|
3
|
-
z-index: var(--zn-z-index-editor-action);
|
|
4
|
-
display: none;
|
|
5
|
-
background: var(--zn-panel-background-color);
|
|
6
|
-
border: 1px solid var(--zn-border-color);
|
|
7
|
-
border-radius: 8px;
|
|
8
|
-
box-shadow: var(--zn-shadow-medium);
|
|
9
|
-
padding: 6px 0;
|
|
10
|
-
max-height: 220px;
|
|
11
|
-
overflow-y: auto;
|
|
12
|
-
min-width: 360px;
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
:host([open]) {
|
|
16
|
-
display: block;
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
.header {
|
|
20
|
-
padding: 4px 6px;
|
|
21
|
-
font-size: var(--zn-font-size-x-small);
|
|
22
|
-
opacity: 0.6;
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
.item {
|
|
26
|
-
display: flex;
|
|
27
|
-
align-items: center;
|
|
28
|
-
gap: 8px;
|
|
29
|
-
padding: 8px;
|
|
30
|
-
width: 100%;
|
|
31
|
-
border: none;
|
|
32
|
-
background: transparent;
|
|
33
|
-
cursor: pointer;
|
|
34
|
-
font: inherit;
|
|
35
|
-
|
|
36
|
-
&[aria-selected="true"],
|
|
37
|
-
&:hover {
|
|
38
|
-
background: var(--zn-input-background-color-hover);
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
.label {
|
|
43
|
-
opacity: 0.7;
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
.empty {
|
|
47
|
-
padding: 8px;
|
|
48
|
-
opacity: 0.7;
|
|
49
|
-
}
|