@backstage-community/plugin-shortcuts 0.25.0 → 0.25.1
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/CHANGELOG.md +6 -0
- package/dist/api/DefaultShortcutsApi.esm.js.map +1 -1
- package/dist/index.d.ts +29 -30
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"DefaultShortcutsApi.esm.js","sources":["../../src/api/DefaultShortcutsApi.ts"],"sourcesContent":["/*\n * Copyright 2021 The Backstage Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { pageTheme } from '@backstage/theme';\nimport { v4 as uuid } from 'uuid';\nimport
|
|
1
|
+
{"version":3,"file":"DefaultShortcutsApi.esm.js","sources":["../../src/api/DefaultShortcutsApi.ts"],"sourcesContent":["/*\n * Copyright 2021 The Backstage Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { pageTheme } from '@backstage/theme';\nimport { v4 as uuid } from 'uuid';\nimport type { StorageApi } from '@backstage/core-plugin-api';\nimport type { Observable } from '@backstage/types';\nimport ObservableImpl from 'zen-observable';\nimport { ShortcutApi } from './ShortcutApi';\nimport { Shortcut } from '../types';\n\n/**\n * Default implementation of the {@link ShortcutApi} that uses the\n * {@link @backstage/core-plugin-api#StorageApi} to store shortcuts.\n *\n * @remarks\n *\n * Note that the storage API given is used directly, as in, this implementation\n * does not itself dive into a sub-bucket. So you may want to provide a bucket\n * that is scoped to the plugin (default: 'shortcuts').\n *\n * @public\n */\nexport class DefaultShortcutsApi implements ShortcutApi {\n private shortcuts: Shortcut[];\n private readonly subscribers = new Set<\n ZenObservable.SubscriptionObserver<Shortcut[]>\n >();\n\n private readonly observable = new ObservableImpl<Shortcut[]>(subscriber => {\n // forward the the latest value\n subscriber.next(this.shortcuts);\n\n this.subscribers.add(subscriber);\n return () => {\n this.subscribers.delete(subscriber);\n };\n });\n\n constructor(private readonly storageApi: StorageApi) {\n this.shortcuts = this.storageApi.snapshot<Shortcut[]>('items').value ?? [];\n this.storageApi.observe$<Shortcut[]>('items').subscribe({\n next: next => {\n this.shortcuts = next.value ?? [];\n this.notifyChanges();\n },\n });\n }\n\n shortcut$(): Observable<Shortcut[]> {\n return this.observable;\n }\n\n get() {\n return this.shortcuts;\n }\n\n async add(shortcut: Omit<Shortcut, 'id'>) {\n const shortcuts = this.sort([...this.get(), { ...shortcut, id: uuid() }]);\n\n await this.storageApi.set('items', shortcuts);\n }\n\n async remove(id: string) {\n const shortcuts = this.get().filter(s => s.id !== id);\n\n await this.storageApi.set('items', shortcuts);\n }\n\n async update(shortcut: Shortcut) {\n const shortcuts = this.get().filter(s => s.id !== shortcut.id);\n shortcuts.push(shortcut);\n\n await this.storageApi.set('items', shortcuts);\n }\n\n getColor(url: string) {\n const type = url.split('/')[1];\n const theme =\n this.THEME_MAP[type] ??\n (Object.keys(pageTheme).includes(type) ? type : 'tool');\n\n return pageTheme[theme].colors[0];\n }\n\n private readonly THEME_MAP: Record<string, keyof typeof pageTheme> = {\n catalog: 'home',\n docs: 'documentation',\n };\n\n private sort(shortcuts: Shortcut[]): Shortcut[] {\n return shortcuts.slice().sort((a, b) => (a.title >= b.title ? 1 : -1));\n }\n\n private notifyChanges() {\n for (const subscription of this.subscribers) {\n subscription.next(this.shortcuts);\n }\n }\n}\n"],"names":["uuid"],"mappings":";;;;AAoCO,MAAM,mBAAA,CAA2C;AAAA,EAgBtD,YAA6B,UAAA,EAAwB;AAAxB,IAAA,IAAA,CAAA,UAAA,GAAA,UAAA;AAC3B,IAAA,IAAA,CAAK,YAAY,IAAA,CAAK,UAAA,CAAW,SAAqB,OAAO,CAAA,CAAE,SAAS,EAAC;AACzE,IAAA,IAAA,CAAK,UAAA,CAAW,QAAA,CAAqB,OAAO,CAAA,CAAE,SAAA,CAAU;AAAA,MACtD,MAAM,CAAA,IAAA,KAAQ;AACZ,QAAA,IAAA,CAAK,SAAA,GAAY,IAAA,CAAK,KAAA,IAAS,EAAC;AAChC,QAAA,IAAA,CAAK,aAAA,EAAc;AAAA,MACrB;AAAA,KACD,CAAA;AAAA,EACH;AAAA,EAvBQ,SAAA;AAAA,EACS,WAAA,uBAAkB,GAAA,EAEjC;AAAA,EAEe,UAAA,GAAa,IAAI,cAAA,CAA2B,CAAA,UAAA,KAAc;AAEzE,IAAA,UAAA,CAAW,IAAA,CAAK,KAAK,SAAS,CAAA;AAE9B,IAAA,IAAA,CAAK,WAAA,CAAY,IAAI,UAAU,CAAA;AAC/B,IAAA,OAAO,MAAM;AACX,MAAA,IAAA,CAAK,WAAA,CAAY,OAAO,UAAU,CAAA;AAAA,IACpC,CAAA;AAAA,EACF,CAAC,CAAA;AAAA,EAYD,SAAA,GAAoC;AAClC,IAAA,OAAO,IAAA,CAAK,UAAA;AAAA,EACd;AAAA,EAEA,GAAA,GAAM;AACJ,IAAA,OAAO,IAAA,CAAK,SAAA;AAAA,EACd;AAAA,EAEA,MAAM,IAAI,QAAA,EAAgC;AACxC,IAAA,MAAM,SAAA,GAAY,IAAA,CAAK,IAAA,CAAK,CAAC,GAAG,IAAA,CAAK,GAAA,EAAI,EAAG,EAAE,GAAG,QAAA,EAAU,EAAA,EAAIA,EAAA,EAAK,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AAE,KAAA,IAAS,CAAA,CAAE,KAAA,GAAQ,CAAA,GAAI,EAAG,CAAA;AAAA,EACvE;AAAA,EAEQ,aAAA,GAAgB;AACtB,IAAA,KAAA,MAAW,YAAA,IAAgB,KAAK,WAAA,EAAa;AAC3C,MAAA,YAAA,CAAa,IAAA,CAAK,KAAK,SAAS,CAAA;AAAA,IAClC;AAAA,EACF;AACF;;;;"}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
2
2
|
import * as _backstage_core_plugin_api from '@backstage/core-plugin-api';
|
|
3
3
|
import { IconComponent, StorageApi } from '@backstage/core-plugin-api';
|
|
4
|
-
import { ShortcutApi as ShortcutApi$1, Shortcut as Shortcut$1 } from '@backstage-community/plugin-shortcuts';
|
|
5
4
|
import { Observable } from '@backstage/types';
|
|
6
5
|
import * as _backstage_frontend_plugin_api from '@backstage/frontend-plugin-api';
|
|
7
6
|
|
|
@@ -20,35 +19,6 @@ declare const shortcutsPlugin: _backstage_core_plugin_api.BackstagePlugin<{}, {}
|
|
|
20
19
|
/** @public */
|
|
21
20
|
declare const Shortcuts: (props: ShortcutsProps) => react_jsx_runtime.JSX.Element;
|
|
22
21
|
|
|
23
|
-
/**
|
|
24
|
-
* Default implementation of the {@link ShortcutApi} that uses the
|
|
25
|
-
* {@link @backstage/core-plugin-api#StorageApi} to store shortcuts.
|
|
26
|
-
*
|
|
27
|
-
* @remarks
|
|
28
|
-
*
|
|
29
|
-
* Note that the storage API given is used directly, as in, this implementation
|
|
30
|
-
* does not itself dive into a sub-bucket. So you may want to provide a bucket
|
|
31
|
-
* that is scoped to the plugin (default: 'shortcuts').
|
|
32
|
-
*
|
|
33
|
-
* @public
|
|
34
|
-
*/
|
|
35
|
-
declare class DefaultShortcutsApi implements ShortcutApi$1 {
|
|
36
|
-
private readonly storageApi;
|
|
37
|
-
private shortcuts;
|
|
38
|
-
private readonly subscribers;
|
|
39
|
-
private readonly observable;
|
|
40
|
-
constructor(storageApi: StorageApi);
|
|
41
|
-
shortcut$(): Observable<Shortcut$1[]>;
|
|
42
|
-
get(): Shortcut$1[];
|
|
43
|
-
add(shortcut: Omit<Shortcut$1, 'id'>): Promise<void>;
|
|
44
|
-
remove(id: string): Promise<void>;
|
|
45
|
-
update(shortcut: Shortcut$1): Promise<void>;
|
|
46
|
-
getColor(url: string): string;
|
|
47
|
-
private readonly THEME_MAP;
|
|
48
|
-
private sort;
|
|
49
|
-
private notifyChanges;
|
|
50
|
-
}
|
|
51
|
-
|
|
52
22
|
/** @public */
|
|
53
23
|
type Shortcut = {
|
|
54
24
|
id: string;
|
|
@@ -90,6 +60,35 @@ interface ShortcutApi {
|
|
|
90
60
|
getColor(url: string): string;
|
|
91
61
|
}
|
|
92
62
|
|
|
63
|
+
/**
|
|
64
|
+
* Default implementation of the {@link ShortcutApi} that uses the
|
|
65
|
+
* {@link @backstage/core-plugin-api#StorageApi} to store shortcuts.
|
|
66
|
+
*
|
|
67
|
+
* @remarks
|
|
68
|
+
*
|
|
69
|
+
* Note that the storage API given is used directly, as in, this implementation
|
|
70
|
+
* does not itself dive into a sub-bucket. So you may want to provide a bucket
|
|
71
|
+
* that is scoped to the plugin (default: 'shortcuts').
|
|
72
|
+
*
|
|
73
|
+
* @public
|
|
74
|
+
*/
|
|
75
|
+
declare class DefaultShortcutsApi implements ShortcutApi {
|
|
76
|
+
private readonly storageApi;
|
|
77
|
+
private shortcuts;
|
|
78
|
+
private readonly subscribers;
|
|
79
|
+
private readonly observable;
|
|
80
|
+
constructor(storageApi: StorageApi);
|
|
81
|
+
shortcut$(): Observable<Shortcut[]>;
|
|
82
|
+
get(): Shortcut[];
|
|
83
|
+
add(shortcut: Omit<Shortcut, 'id'>): Promise<void>;
|
|
84
|
+
remove(id: string): Promise<void>;
|
|
85
|
+
update(shortcut: Shortcut): Promise<void>;
|
|
86
|
+
getColor(url: string): string;
|
|
87
|
+
private readonly THEME_MAP;
|
|
88
|
+
private sort;
|
|
89
|
+
private notifyChanges;
|
|
90
|
+
}
|
|
91
|
+
|
|
93
92
|
/**
|
|
94
93
|
* @public
|
|
95
94
|
* @deprecated Use {@link DefaultShortcutsApi} instead.
|