-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.ts
74 lines (61 loc) · 2.22 KB
/
index.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
import { clearLines, colorMap, getWidgetTags } from "./common";
import config from "./config";
import icons from "./icons";
import { IMeta } from "./types";
miro.onReady(async () => {
await clearLines();
miro.addListener("SELECTION_UPDATED", async (widget) => {
await clearLines();
const enabled = localStorage.getItem(config.storageKeys.settings.miroPluginTagCrawlerEnabled) === "true";
if (!enabled) {
return;
}
if (widget.data.length !== 1) return;
const selectedWidget = widget.data[0];
const widgetTags = await getWidgetTags(selectedWidget.id);
const alreadyLinked: string[] = [];
const lineWidgets: SDK.WidgetToBeCreated[] = [];
for (let widgetTag of widgetTags) {
const otherWidgetIds = widgetTag.widgetIds.filter((id) => id !== selectedWidget.id);
for (let otherWidgetId of otherWidgetIds) {
if (alreadyLinked.includes(otherWidgetId)) continue;
alreadyLinked.push(otherWidgetId);
const otherWidget = await miro.board.widgets.get({ id: otherWidgetId });
if (otherWidget.length < 1) continue;
const storedColor = localStorage.getItem(config.storageKeys.settings.miroPluginTagCrawlerColor);
const lineColor = storedColor === "multi" ? widgetTag.color : `#${colorMap[storedColor]}`;
lineWidgets.push({
type: "LINE",
startWidgetId: selectedWidget.id,
endWidgetId: otherWidgetId,
captions: [{ text: widgetTag.title }],
metadata: {
[config.clientId]: {
isTagCrawlerLine: true,
} as IMeta,
},
style: {
lineColor,
lineEndStyle: miro.enums.lineArrowheadStyle.NONE,
lineStartStyle: miro.enums.lineArrowheadStyle.NONE,
lineStyle: miro.enums.lineStyle.NORMAL,
lineThickness: 2,
lineType: miro.enums.lineType.ARROW,
},
});
}
}
await miro.board.widgets.create(lineWidgets);
});
miro.initialize({
extensionPoints: {
bottomBar: {
title: "Tag crawler",
svgIcon: icons.tag_crawler,
onClick: async () => {
miro.board.ui.openLeftSidebar("sidebar.html");
},
},
},
});
});