Skip to content

Commit 31ca7a0

Browse files
authored
Merge pull request #33 from editor-js/feature/popover-improvements
Add new methods to Popover
2 parents 958f0c7 + 515e80e commit 31ca7a0

7 files changed

Lines changed: 34 additions & 4 deletions

File tree

.yarn/install-state.gz

7 Bytes
Binary file not shown.

packages/helpers/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"description": "Utils useful for Editor.js tools development",
44
"repository": "https://github.com/editor-js/utils/tree/main/packages/helpers",
55
"link": "https://github.com/editor-js/utils/tree/main/packages/helpers",
6-
"version": "1.2.0",
6+
"version": "1.2.1",
77
"main": "dist/index.js",
88
"type": "module",
99
"license": "MIT",

packages/helpers/src/Listeners/Listeners.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ export class Listeners {
7272

7373
const alreadyExist = this.findOne(element, eventType, handler);
7474

75-
if (alreadyExist !== undefined) {
75+
if (alreadyExist !== null) {
7676
return;
7777
}
7878

packages/ui-kit/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"name": "@editorjs/ui-kit",
33
"description": "UI Components for Editor.js",
44
"packageManager": "yarn@4.4.0",
5-
"version": "1.0.1",
5+
"version": "1.1.0",
66
"type": "module",
77
"main": "dist/index.js",
88
"types": "dist/src/index.d.ts",

packages/ui-kit/preview/index.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010
const popover = new PopoverDesktop(
1111
{
12-
items: [{ title: 'Item 1' }],
12+
items: [{ title: 'Item 1', onActivate: console.log }],
1313
scopeElement: document.body,
1414
searchable: true,
1515
}

packages/ui-kit/src/popover/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,5 @@ import { PopoverMobile } from './popover-mobile';
1111
export type Popover = PopoverDesktop | PopoverMobile | PopoverInline;
1212

1313
export { PopoverDesktop, PopoverMobile, PopoverInline };
14+
15+
export * from './types';

packages/ui-kit/src/popover/popover-abstract.ts

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,34 @@ export abstract class PopoverAbstract<Nodes extends PopoverNodes = PopoverNodes>
120120
return this.nodes.popover;
121121
}
122122

123+
/**
124+
* Adds a single item to the popover
125+
* @param params - item parameters
126+
*/
127+
public addItem(params: PopoverItemParams): void {
128+
const [item] = this.buildItems([params]);
129+
130+
this.items.push(item);
131+
this.nodes.items.appendChild(item.getElement());
132+
}
133+
134+
/**
135+
* Removes an item from the popover by its name
136+
* @param name - name of the item to be removed
137+
*/
138+
public removeItemByName(name: string): void {
139+
const foundItemIndex = this.items.findIndex(item => item.name === name);
140+
141+
if (foundItemIndex === -1) {
142+
return;
143+
}
144+
145+
const [removedItem] = this.items.splice(foundItemIndex, 1);
146+
147+
removedItem.destroy();
148+
removedItem.getElement().remove();
149+
}
150+
123151
/**
124152
* Open popover
125153
*/

0 commit comments

Comments
 (0)