@bpmnkit/plugins 0.0.18 → 0.0.23

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.
@@ -0,0 +1,223 @@
1
+ // ── DOM helpers ───────────────────────────────────────────────────────────────
2
+ function el(tag, attrs = {}, ...children) {
3
+ const node = document.createElement(tag);
4
+ for (const [k, v] of Object.entries(attrs))
5
+ node.setAttribute(k, v);
6
+ for (const child of children) {
7
+ if (typeof child === "string")
8
+ node.append(document.createTextNode(child));
9
+ else
10
+ node.append(child);
11
+ }
12
+ return node;
13
+ }
14
+ // ── Card rendering ────────────────────────────────────────────────────────────
15
+ function renderBuiltinCard(template, onUse) {
16
+ const card = el("div", { class: "bpmnkit-cc-card" });
17
+ // Icon
18
+ const iconWrap = el("div", { class: "bpmnkit-cc-card__icon" });
19
+ if (template.icon?.contents) {
20
+ iconWrap.innerHTML = template.icon.contents;
21
+ }
22
+ card.append(iconWrap);
23
+ // Text
24
+ const body = el("div", { class: "bpmnkit-cc-card__body" });
25
+ body.append(el("div", { class: "bpmnkit-cc-card__name" }, template.name));
26
+ if (template.description) {
27
+ body.append(el("div", { class: "bpmnkit-cc-card__desc" }, template.description));
28
+ }
29
+ card.append(body);
30
+ // Use button
31
+ const btn = el("button", { class: "bpmnkit-cc-card__use", type: "button" }, "Use");
32
+ btn.addEventListener("click", (e) => {
33
+ e.stopPropagation();
34
+ onUse(template);
35
+ });
36
+ card.append(btn);
37
+ // Whole card is also clickable
38
+ card.addEventListener("click", () => onUse(template));
39
+ return card;
40
+ }
41
+ function renderCommunityRow(entry, onLoad) {
42
+ const row = el("div", { class: "bpmnkit-cc-row" });
43
+ const body = el("div", { class: "bpmnkit-cc-row__body" });
44
+ body.append(el("div", { class: "bpmnkit-cc-row__name" }, entry.name));
45
+ if (entry.description) {
46
+ body.append(el("div", { class: "bpmnkit-cc-row__desc" }, entry.description));
47
+ }
48
+ row.append(body);
49
+ const btn = el("button", { class: "bpmnkit-cc-row__import", type: "button" }, "Import");
50
+ btn.addEventListener("click", (e) => {
51
+ e.stopPropagation();
52
+ onLoad(entry.id);
53
+ });
54
+ row.append(btn);
55
+ row.addEventListener("click", () => onLoad(entry.id));
56
+ return row;
57
+ }
58
+ // ── Panel ─────────────────────────────────────────────────────────────────────
59
+ export class CatalogPanel {
60
+ opts;
61
+ overlay = null;
62
+ activeTab = "builtin";
63
+ query = "";
64
+ constructor(opts) {
65
+ this.opts = opts;
66
+ }
67
+ open() {
68
+ if (this.overlay) {
69
+ this.overlay.style.display = "flex";
70
+ return;
71
+ }
72
+ this.overlay = this.build();
73
+ document.body.append(this.overlay);
74
+ // Focus search on next tick
75
+ setTimeout(() => {
76
+ const input = this.overlay?.querySelector(".bpmnkit-cc-panel__search-input");
77
+ input?.focus();
78
+ }, 0);
79
+ }
80
+ close() {
81
+ if (this.overlay) {
82
+ this.overlay.style.display = "none";
83
+ }
84
+ }
85
+ build() {
86
+ const overlay = el("div", {
87
+ class: "bpmnkit-cc-panel-overlay",
88
+ role: "dialog",
89
+ "aria-modal": "true",
90
+ "aria-label": "Connector catalog",
91
+ });
92
+ // Close on backdrop click
93
+ overlay.addEventListener("click", (e) => {
94
+ if (e.target === overlay)
95
+ this.close();
96
+ });
97
+ // Close on Escape
98
+ overlay.addEventListener("keydown", (e) => {
99
+ if (e.key === "Escape")
100
+ this.close();
101
+ });
102
+ const panel = el("div", { class: "bpmnkit-cc-panel" });
103
+ overlay.append(panel);
104
+ // Header
105
+ const header = el("div", { class: "bpmnkit-cc-panel__header" });
106
+ header.append(el("h2", { class: "bpmnkit-cc-panel__title" }, "Connectors"));
107
+ const closeBtn = el("button", {
108
+ class: "bpmnkit-cc-panel__close",
109
+ type: "button",
110
+ "aria-label": "Close",
111
+ }, "✕");
112
+ closeBtn.addEventListener("click", () => this.close());
113
+ header.append(closeBtn);
114
+ panel.append(header);
115
+ // Search
116
+ const searchWrap = el("div", { class: "bpmnkit-cc-panel__search" });
117
+ const searchInput = el("input", {
118
+ class: "bpmnkit-cc-panel__search-input",
119
+ type: "text",
120
+ placeholder: "Search connectors…",
121
+ autocomplete: "off",
122
+ });
123
+ searchInput.addEventListener("input", () => {
124
+ this.query = searchInput.value.toLowerCase().trim();
125
+ this.renderContent(content);
126
+ });
127
+ searchWrap.append(searchInput);
128
+ panel.append(searchWrap);
129
+ // Tabs
130
+ const tabs = el("div", { class: "bpmnkit-cc-panel__tabs", role: "tablist" });
131
+ const builtinTab = el("button", {
132
+ class: "bpmnkit-cc-tab bpmnkit-cc-tab--active",
133
+ role: "tab",
134
+ type: "button",
135
+ }, "Built-in Workers");
136
+ const communityTab = el("button", {
137
+ class: "bpmnkit-cc-tab",
138
+ role: "tab",
139
+ type: "button",
140
+ }, "Community APIs");
141
+ builtinTab.addEventListener("click", () => {
142
+ this.activeTab = "builtin";
143
+ builtinTab.classList.add("bpmnkit-cc-tab--active");
144
+ communityTab.classList.remove("bpmnkit-cc-tab--active");
145
+ this.renderContent(content);
146
+ });
147
+ communityTab.addEventListener("click", () => {
148
+ this.activeTab = "community";
149
+ communityTab.classList.add("bpmnkit-cc-tab--active");
150
+ builtinTab.classList.remove("bpmnkit-cc-tab--active");
151
+ this.renderContent(content);
152
+ });
153
+ tabs.append(builtinTab, communityTab);
154
+ panel.append(tabs);
155
+ // Content area
156
+ const content = el("div", { class: "bpmnkit-cc-panel__content" });
157
+ this.renderContent(content);
158
+ panel.append(content);
159
+ // Community footer actions
160
+ const footer = el("div", { class: "bpmnkit-cc-panel__footer" });
161
+ const urlBtn = el("button", { class: "bpmnkit-cc-footer-btn", type: "button" }, "Import from URL…");
162
+ urlBtn.addEventListener("click", () => {
163
+ this.close();
164
+ const url = window.prompt("Enter an OpenAPI 3.x spec URL:");
165
+ if (url?.trim())
166
+ this.opts.onLoadFromUrl(url.trim());
167
+ });
168
+ const fileBtn = el("button", { class: "bpmnkit-cc-footer-btn", type: "button" }, "Import from file…");
169
+ fileBtn.addEventListener("click", () => {
170
+ this.close();
171
+ this.opts.onLoadFromFile();
172
+ });
173
+ footer.append(urlBtn, fileBtn);
174
+ panel.append(footer);
175
+ return overlay;
176
+ }
177
+ renderContent(container) {
178
+ container.innerHTML = "";
179
+ if (this.activeTab === "builtin") {
180
+ this.renderBuiltins(container);
181
+ }
182
+ else {
183
+ this.renderCommunity(container);
184
+ }
185
+ }
186
+ renderBuiltins(container) {
187
+ const q = this.query;
188
+ const filtered = q
189
+ ? this.opts.builtinTemplates.filter((t) => t.name.toLowerCase().includes(q) || (t.description ?? "").toLowerCase().includes(q))
190
+ : this.opts.builtinTemplates;
191
+ if (filtered.length === 0) {
192
+ container.append(el("div", { class: "bpmnkit-cc-empty" }, `No workers match "${this.query}"`));
193
+ return;
194
+ }
195
+ const grid = el("div", { class: "bpmnkit-cc-grid" });
196
+ for (const template of filtered) {
197
+ grid.append(renderBuiltinCard(template, (t) => {
198
+ this.opts.onUseBuiltin(t);
199
+ this.close();
200
+ }));
201
+ }
202
+ container.append(grid);
203
+ }
204
+ renderCommunity(container) {
205
+ const q = this.query;
206
+ const filtered = q
207
+ ? this.opts.catalogEntries.filter((e) => e.name.toLowerCase().includes(q) || (e.description ?? "").toLowerCase().includes(q))
208
+ : this.opts.catalogEntries;
209
+ if (filtered.length === 0) {
210
+ container.append(el("div", { class: "bpmnkit-cc-empty" }, `No APIs match "${this.query}"`));
211
+ return;
212
+ }
213
+ const list = el("div", { class: "bpmnkit-cc-list" });
214
+ for (const entry of filtered) {
215
+ list.append(renderCommunityRow(entry, (id) => {
216
+ this.opts.onLoadCatalogEntry(id);
217
+ this.close();
218
+ }));
219
+ }
220
+ container.append(list);
221
+ }
222
+ }
223
+ //# sourceMappingURL=panel.js.map
@@ -0,0 +1,24 @@
1
+ import type { CanvasPlugin } from "@bpmnkit/canvas";
2
+ export interface PresentationApi {
3
+ enter(): void;
4
+ exit(): void;
5
+ }
6
+ export interface PresentationPlugin extends CanvasPlugin {
7
+ api: PresentationApi;
8
+ }
9
+ interface PaletteInput {
10
+ addCommands(cmds: Array<{
11
+ id: string;
12
+ title: string;
13
+ description?: string;
14
+ action(): void;
15
+ }>): () => void;
16
+ }
17
+ export interface PresentationOptions {
18
+ palette?: PaletteInput | null;
19
+ onEnter?: () => void;
20
+ onExit?: () => void;
21
+ }
22
+ export declare function createPresentationPlugin(options?: PresentationOptions): PresentationPlugin;
23
+ export {};
24
+ //# sourceMappingURL=index.d.ts.map