@backstage-community/plugin-shortcuts 0.3.24 → 0.3.25
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/AddShortcut.esm.js +102 -0
- package/dist/AddShortcut.esm.js.map +1 -0
- package/dist/EditShortcut.esm.js +116 -0
- package/dist/EditShortcut.esm.js.map +1 -0
- package/dist/ShortcutForm.esm.js +147 -0
- package/dist/ShortcutForm.esm.js.map +1 -0
- package/dist/ShortcutIcon.esm.js +22 -0
- package/dist/ShortcutIcon.esm.js.map +1 -0
- package/dist/ShortcutItem.esm.js +76 -0
- package/dist/ShortcutItem.esm.js.map +1 -0
- package/dist/Shortcuts.esm.js +51 -0
- package/dist/Shortcuts.esm.js.map +1 -0
- package/dist/api/DefaultShortcutsApi.esm.js +64 -0
- package/dist/api/DefaultShortcutsApi.esm.js.map +1 -0
- package/dist/api/ShortcutApi.esm.js +8 -0
- package/dist/api/ShortcutApi.esm.js.map +1 -0
- package/dist/deprecated.esm.js +7 -0
- package/dist/deprecated.esm.js.map +1 -0
- package/dist/index.esm.js +4 -96
- package/dist/index.esm.js.map +1 -1
- package/dist/plugin.esm.js +23 -0
- package/dist/plugin.esm.js.map +1 -0
- package/package.json +12 -8
- package/dist/esm/Shortcuts-BtnNxS7L.esm.js +0 -478
- package/dist/esm/Shortcuts-BtnNxS7L.esm.js.map +0 -1
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import { pageTheme } from '@backstage/theme';
|
|
2
|
+
import { v4 } from 'uuid';
|
|
3
|
+
import ObservableImpl from 'zen-observable';
|
|
4
|
+
|
|
5
|
+
class DefaultShortcutsApi {
|
|
6
|
+
constructor(storageApi) {
|
|
7
|
+
this.storageApi = storageApi;
|
|
8
|
+
this.shortcuts = this.storageApi.snapshot("items").value ?? [];
|
|
9
|
+
this.storageApi.observe$("items").subscribe({
|
|
10
|
+
next: (next) => {
|
|
11
|
+
this.shortcuts = next.value ?? [];
|
|
12
|
+
this.notifyChanges();
|
|
13
|
+
}
|
|
14
|
+
});
|
|
15
|
+
}
|
|
16
|
+
shortcuts;
|
|
17
|
+
subscribers = /* @__PURE__ */ new Set();
|
|
18
|
+
observable = new ObservableImpl((subscriber) => {
|
|
19
|
+
subscriber.next(this.shortcuts);
|
|
20
|
+
this.subscribers.add(subscriber);
|
|
21
|
+
return () => {
|
|
22
|
+
this.subscribers.delete(subscriber);
|
|
23
|
+
};
|
|
24
|
+
});
|
|
25
|
+
shortcut$() {
|
|
26
|
+
return this.observable;
|
|
27
|
+
}
|
|
28
|
+
get() {
|
|
29
|
+
return this.shortcuts;
|
|
30
|
+
}
|
|
31
|
+
async add(shortcut) {
|
|
32
|
+
const shortcuts = this.sort([...this.get(), { ...shortcut, id: v4() }]);
|
|
33
|
+
await this.storageApi.set("items", shortcuts);
|
|
34
|
+
}
|
|
35
|
+
async remove(id) {
|
|
36
|
+
const shortcuts = this.get().filter((s) => s.id !== id);
|
|
37
|
+
await this.storageApi.set("items", shortcuts);
|
|
38
|
+
}
|
|
39
|
+
async update(shortcut) {
|
|
40
|
+
const shortcuts = this.get().filter((s) => s.id !== shortcut.id);
|
|
41
|
+
shortcuts.push(shortcut);
|
|
42
|
+
await this.storageApi.set("items", shortcuts);
|
|
43
|
+
}
|
|
44
|
+
getColor(url) {
|
|
45
|
+
const type = url.split("/")[1];
|
|
46
|
+
const theme = this.THEME_MAP[type] ?? (Object.keys(pageTheme).includes(type) ? type : "tool");
|
|
47
|
+
return pageTheme[theme].colors[0];
|
|
48
|
+
}
|
|
49
|
+
THEME_MAP = {
|
|
50
|
+
catalog: "home",
|
|
51
|
+
docs: "documentation"
|
|
52
|
+
};
|
|
53
|
+
sort(shortcuts) {
|
|
54
|
+
return shortcuts.slice().sort((a, b) => a.title >= b.title ? 1 : -1);
|
|
55
|
+
}
|
|
56
|
+
notifyChanges() {
|
|
57
|
+
for (const subscription of this.subscribers) {
|
|
58
|
+
subscription.next(this.shortcuts);
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
export { DefaultShortcutsApi };
|
|
64
|
+
//# sourceMappingURL=DefaultShortcutsApi.esm.js.map
|
|
@@ -0,0 +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 {\n ShortcutApi,\n type Shortcut,\n} from '@backstage-community/plugin-shortcuts';\nimport type { StorageApi } from '@backstage/core-plugin-api';\nimport type { Observable } from '@backstage/types';\nimport ObservableImpl from 'zen-observable';\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":";;;;AAsCO,MAAM,mBAA2C,CAAA;AAAA,EAgBtD,YAA6B,UAAwB,EAAA;AAAxB,IAAA,IAAA,CAAA,UAAA,GAAA,UAAA,CAAA;AAC3B,IAAA,IAAA,CAAK,YAAY,IAAK,CAAA,UAAA,CAAW,SAAqB,OAAO,CAAA,CAAE,SAAS,EAAC,CAAA;AACzE,IAAA,IAAA,CAAK,UAAW,CAAA,QAAA,CAAqB,OAAO,CAAA,CAAE,SAAU,CAAA;AAAA,MACtD,MAAM,CAAQ,IAAA,KAAA;AACZ,QAAK,IAAA,CAAA,SAAA,GAAY,IAAK,CAAA,KAAA,IAAS,EAAC,CAAA;AAChC,QAAA,IAAA,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*\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 { Shortcut } from '../types';\nimport { createApiRef } from '@backstage/core-plugin-api';\nimport { Observable } from '@backstage/types';\n\n/** @public */\nexport const shortcutsApiRef = createApiRef<ShortcutApi>({\n id: 'plugin.shortcuts.api',\n});\n\n/** @public */\nexport interface ShortcutApi {\n /**\n * Returns an Observable that will subscribe to changes.\n */\n shortcut$(): Observable<Shortcut[]>;\n\n /**\n * Returns an immediate snapshot of shortcuts, sorted by title\n */\n get(): Shortcut[];\n\n /**\n * Generates a unique id for the shortcut and then saves it.\n */\n add(shortcut: Omit<Shortcut, 'id'>): Promise<void>;\n\n /**\n * Removes the shortcut.\n */\n remove(id: string): Promise<void>;\n\n /**\n * Finds an existing shortcut that matches the ID of the\n * supplied shortcut and updates its values.\n */\n update(shortcut: Shortcut): Promise<void>;\n\n /**\n * Each shortcut should get a color for its icon based on the url.\n *\n * Preferably using some abstraction between the url and the actual\n * color value.\n */\n getColor(url: string): string;\n}\n"],"names":[],"mappings":";;AAqBO,MAAM,kBAAkB,YAA0B,CAAA;AAAA,EACvD,EAAI,EAAA,sBAAA;AACN,CAAC;;;;"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"deprecated.esm.js","sources":["../src/deprecated.ts"],"sourcesContent":["/*\n * Copyright 2023 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 { DefaultShortcutsApi } from './api';\n\n/**\n * @public\n * @deprecated Use {@link DefaultShortcutsApi} instead.\n */\nexport const LocalStoredShortcuts = DefaultShortcutsApi;\n"],"names":[],"mappings":";;;AAsBO,MAAM,oBAAuB,GAAA;;;;"}
|
package/dist/index.esm.js
CHANGED
|
@@ -1,97 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
var __defProp = Object.defineProperty;
|
|
7
|
-
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
8
|
-
var __publicField = (obj, key, value) => {
|
|
9
|
-
__defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
10
|
-
return value;
|
|
11
|
-
};
|
|
12
|
-
class DefaultShortcutsApi {
|
|
13
|
-
constructor(storageApi) {
|
|
14
|
-
this.storageApi = storageApi;
|
|
15
|
-
__publicField(this, "shortcuts");
|
|
16
|
-
__publicField(this, "subscribers", /* @__PURE__ */ new Set());
|
|
17
|
-
__publicField(this, "observable", new ObservableImpl((subscriber) => {
|
|
18
|
-
subscriber.next(this.shortcuts);
|
|
19
|
-
this.subscribers.add(subscriber);
|
|
20
|
-
return () => {
|
|
21
|
-
this.subscribers.delete(subscriber);
|
|
22
|
-
};
|
|
23
|
-
}));
|
|
24
|
-
__publicField(this, "THEME_MAP", {
|
|
25
|
-
catalog: "home",
|
|
26
|
-
docs: "documentation"
|
|
27
|
-
});
|
|
28
|
-
var _a;
|
|
29
|
-
this.shortcuts = (_a = this.storageApi.snapshot("items").value) != null ? _a : [];
|
|
30
|
-
this.storageApi.observe$("items").subscribe({
|
|
31
|
-
next: (next) => {
|
|
32
|
-
var _a2;
|
|
33
|
-
this.shortcuts = (_a2 = next.value) != null ? _a2 : [];
|
|
34
|
-
this.notifyChanges();
|
|
35
|
-
}
|
|
36
|
-
});
|
|
37
|
-
}
|
|
38
|
-
shortcut$() {
|
|
39
|
-
return this.observable;
|
|
40
|
-
}
|
|
41
|
-
get() {
|
|
42
|
-
return this.shortcuts;
|
|
43
|
-
}
|
|
44
|
-
async add(shortcut) {
|
|
45
|
-
const shortcuts = this.sort([...this.get(), { ...shortcut, id: v4() }]);
|
|
46
|
-
await this.storageApi.set("items", shortcuts);
|
|
47
|
-
}
|
|
48
|
-
async remove(id) {
|
|
49
|
-
const shortcuts = this.get().filter((s) => s.id !== id);
|
|
50
|
-
await this.storageApi.set("items", shortcuts);
|
|
51
|
-
}
|
|
52
|
-
async update(shortcut) {
|
|
53
|
-
const shortcuts = this.get().filter((s) => s.id !== shortcut.id);
|
|
54
|
-
shortcuts.push(shortcut);
|
|
55
|
-
await this.storageApi.set("items", shortcuts);
|
|
56
|
-
}
|
|
57
|
-
getColor(url) {
|
|
58
|
-
var _a;
|
|
59
|
-
const type = url.split("/")[1];
|
|
60
|
-
const theme = (_a = this.THEME_MAP[type]) != null ? _a : Object.keys(pageTheme).includes(type) ? type : "tool";
|
|
61
|
-
return pageTheme[theme].colors[0];
|
|
62
|
-
}
|
|
63
|
-
sort(shortcuts) {
|
|
64
|
-
return shortcuts.slice().sort((a, b) => a.title >= b.title ? 1 : -1);
|
|
65
|
-
}
|
|
66
|
-
notifyChanges() {
|
|
67
|
-
for (const subscription of this.subscribers) {
|
|
68
|
-
subscription.next(this.shortcuts);
|
|
69
|
-
}
|
|
70
|
-
}
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
const shortcutsApiRef = createApiRef({
|
|
74
|
-
id: "plugin.shortcuts.api"
|
|
75
|
-
});
|
|
76
|
-
|
|
77
|
-
const shortcutsPlugin = createPlugin({
|
|
78
|
-
id: "shortcuts",
|
|
79
|
-
apis: [
|
|
80
|
-
createApiFactory({
|
|
81
|
-
api: shortcutsApiRef,
|
|
82
|
-
deps: { storageApi: storageApiRef },
|
|
83
|
-
factory: ({ storageApi }) => new DefaultShortcutsApi(storageApi.forBucket("shortcuts"))
|
|
84
|
-
})
|
|
85
|
-
]
|
|
86
|
-
});
|
|
87
|
-
const Shortcuts = shortcutsPlugin.provide(
|
|
88
|
-
createComponentExtension({
|
|
89
|
-
name: "Shortcuts",
|
|
90
|
-
component: { lazy: () => import('./esm/Shortcuts-BtnNxS7L.esm.js').then((m) => m.Shortcuts) }
|
|
91
|
-
})
|
|
92
|
-
);
|
|
93
|
-
|
|
94
|
-
const LocalStoredShortcuts = DefaultShortcutsApi;
|
|
95
|
-
|
|
96
|
-
export { DefaultShortcutsApi, LocalStoredShortcuts, Shortcuts, shortcutsApiRef, shortcutsPlugin };
|
|
1
|
+
export { Shortcuts, shortcutsPlugin } from './plugin.esm.js';
|
|
2
|
+
export { DefaultShortcutsApi } from './api/DefaultShortcutsApi.esm.js';
|
|
3
|
+
export { shortcutsApiRef } from './api/ShortcutApi.esm.js';
|
|
4
|
+
export { LocalStoredShortcuts } from './deprecated.esm.js';
|
|
97
5
|
//# sourceMappingURL=index.esm.js.map
|
package/dist/index.esm.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.esm.js","sources":["../src/api/DefaultShortcutsApi.ts","../src/api/ShortcutApi.ts","../src/plugin.ts","../src/deprecated.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 {\n ShortcutApi,\n type Shortcut,\n} from '@backstage-community/plugin-shortcuts';\nimport type { StorageApi } from '@backstage/core-plugin-api';\nimport type { Observable } from '@backstage/types';\nimport ObservableImpl from 'zen-observable';\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","/*\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 { Shortcut } from '../types';\nimport { createApiRef } from '@backstage/core-plugin-api';\nimport { Observable } from '@backstage/types';\n\n/** @public */\nexport const shortcutsApiRef = createApiRef<ShortcutApi>({\n id: 'plugin.shortcuts.api',\n});\n\n/** @public */\nexport interface ShortcutApi {\n /**\n * Returns an Observable that will subscribe to changes.\n */\n shortcut$(): Observable<Shortcut[]>;\n\n /**\n * Returns an immediate snapshot of shortcuts, sorted by title\n */\n get(): Shortcut[];\n\n /**\n * Generates a unique id for the shortcut and then saves it.\n */\n add(shortcut: Omit<Shortcut, 'id'>): Promise<void>;\n\n /**\n * Removes the shortcut.\n */\n remove(id: string): Promise<void>;\n\n /**\n * Finds an existing shortcut that matches the ID of the\n * supplied shortcut and updates its values.\n */\n update(shortcut: Shortcut): Promise<void>;\n\n /**\n * Each shortcut should get a color for its icon based on the url.\n *\n * Preferably using some abstraction between the url and the actual\n * color value.\n */\n getColor(url: string): string;\n}\n","/*\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 { DefaultShortcutsApi, shortcutsApiRef } from './api';\nimport {\n createApiFactory,\n createComponentExtension,\n createPlugin,\n storageApiRef,\n} from '@backstage/core-plugin-api';\n\n/** @public */\nexport const shortcutsPlugin = createPlugin({\n id: 'shortcuts',\n apis: [\n createApiFactory({\n api: shortcutsApiRef,\n deps: { storageApi: storageApiRef },\n factory: ({ storageApi }) =>\n new DefaultShortcutsApi(storageApi.forBucket('shortcuts')),\n }),\n ],\n});\n\n/** @public */\nexport const Shortcuts = shortcutsPlugin.provide(\n createComponentExtension({\n name: 'Shortcuts',\n component: { lazy: () => import('./Shortcuts').then(m => m.Shortcuts) },\n }),\n);\n","/*\n * Copyright 2023 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 { DefaultShortcutsApi } from './api';\n\n/**\n * @public\n * @deprecated Use {@link DefaultShortcutsApi} instead.\n */\nexport const LocalStoredShortcuts = DefaultShortcutsApi;\n"],"names":["_a","uuid"],"mappings":";;;;;;;;;;;AAsCO,MAAM,mBAA2C,CAAA;AAAA,EAgBtD,YAA6B,UAAwB,EAAA;AAAxB,IAAA,IAAA,CAAA,UAAA,GAAA,UAAA,CAAA;AAf7B,IAAQ,aAAA,CAAA,IAAA,EAAA,WAAA,CAAA,CAAA;AACR,IAAiB,aAAA,CAAA,IAAA,EAAA,aAAA,sBAAkB,GAEjC,EAAA,CAAA,CAAA;AAEF,IAAiB,aAAA,CAA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
2
|
+
import { shortcutsApiRef } from './api/ShortcutApi.esm.js';
|
|
3
|
+
import { createPlugin, createApiFactory, storageApiRef, createComponentExtension } from '@backstage/core-plugin-api';
|
|
4
|
+
|
|
5
|
+
const shortcutsPlugin = createPlugin({
|
|
6
|
+
id: "shortcuts",
|
|
7
|
+
apis: [
|
|
8
|
+
createApiFactory({
|
|
9
|
+
api: shortcutsApiRef,
|
|
10
|
+
deps: { storageApi: storageApiRef },
|
|
11
|
+
factory: ({ storageApi }) => new DefaultShortcutsApi(storageApi.forBucket("shortcuts"))
|
|
12
|
+
})
|
|
13
|
+
]
|
|
14
|
+
});
|
|
15
|
+
const Shortcuts = shortcutsPlugin.provide(
|
|
16
|
+
createComponentExtension({
|
|
17
|
+
name: "Shortcuts",
|
|
18
|
+
component: { lazy: () => import('./Shortcuts.esm.js').then((m) => m.Shortcuts) }
|
|
19
|
+
})
|
|
20
|
+
);
|
|
21
|
+
|
|
22
|
+
export { Shortcuts, shortcutsPlugin };
|
|
23
|
+
//# sourceMappingURL=plugin.esm.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"plugin.esm.js","sources":["../src/plugin.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 { DefaultShortcutsApi, shortcutsApiRef } from './api';\nimport {\n createApiFactory,\n createComponentExtension,\n createPlugin,\n storageApiRef,\n} from '@backstage/core-plugin-api';\n\n/** @public */\nexport const shortcutsPlugin = createPlugin({\n id: 'shortcuts',\n apis: [\n createApiFactory({\n api: shortcutsApiRef,\n deps: { storageApi: storageApiRef },\n factory: ({ storageApi }) =>\n new DefaultShortcutsApi(storageApi.forBucket('shortcuts')),\n }),\n ],\n});\n\n/** @public */\nexport const Shortcuts = shortcutsPlugin.provide(\n createComponentExtension({\n name: 'Shortcuts',\n component: { lazy: () => import('./Shortcuts').then(m => m.Shortcuts) },\n }),\n);\n"],"names":[],"mappings":";;;;AAyBO,MAAM,kBAAkB,YAAa,CAAA;AAAA,EAC1C,EAAI,EAAA,WAAA;AAAA,EACJ,IAAM,EAAA;AAAA,IACJ,gBAAiB,CAAA;AAAA,MACf,GAAK,EAAA,eAAA;AAAA,MACL,IAAA,EAAM,EAAE,UAAA,EAAY,aAAc,EAAA;AAAA,MAClC,OAAA,EAAS,CAAC,EAAE,UAAW,EAAA,KACrB,IAAI,mBAAoB,CAAA,UAAA,CAAW,SAAU,CAAA,WAAW,CAAC,CAAA;AAAA,KAC5D,CAAA;AAAA,GACH;AACF,CAAC,EAAA;AAGM,MAAM,YAAY,eAAgB,CAAA,OAAA;AAAA,EACvC,wBAAyB,CAAA;AAAA,IACvB,IAAM,EAAA,WAAA;AAAA,IACN,SAAA,EAAW,EAAE,IAAA,EAAM,MAAM,OAAO,oBAAa,CAAA,CAAE,IAAK,CAAA,CAAA,CAAA,KAAK,CAAE,CAAA,SAAS,CAAE,EAAA;AAAA,GACvE,CAAA;AACH;;;;"}
|
package/package.json
CHANGED
|
@@ -1,9 +1,13 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@backstage-community/plugin-shortcuts",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.25",
|
|
4
4
|
"description": "A Backstage plugin that provides a shortcuts feature to the sidebar",
|
|
5
5
|
"backstage": {
|
|
6
|
-
"role": "frontend-plugin"
|
|
6
|
+
"role": "frontend-plugin",
|
|
7
|
+
"pluginId": "shortcuts",
|
|
8
|
+
"pluginPackages": [
|
|
9
|
+
"@backstage-community/plugin-shortcuts"
|
|
10
|
+
]
|
|
7
11
|
},
|
|
8
12
|
"publishConfig": {
|
|
9
13
|
"access": "public",
|
|
@@ -33,9 +37,9 @@
|
|
|
33
37
|
"test": "backstage-cli package test"
|
|
34
38
|
},
|
|
35
39
|
"dependencies": {
|
|
36
|
-
"@backstage/core-components": "^0.14.
|
|
37
|
-
"@backstage/core-plugin-api": "^1.9.
|
|
38
|
-
"@backstage/theme": "^0.5.
|
|
40
|
+
"@backstage/core-components": "^0.14.9",
|
|
41
|
+
"@backstage/core-plugin-api": "^1.9.3",
|
|
42
|
+
"@backstage/theme": "^0.5.6",
|
|
39
43
|
"@backstage/types": "^1.1.1",
|
|
40
44
|
"@material-ui/core": "^4.12.2",
|
|
41
45
|
"@material-ui/icons": "^4.9.1",
|
|
@@ -46,9 +50,9 @@
|
|
|
46
50
|
"zen-observable": "^0.10.0"
|
|
47
51
|
},
|
|
48
52
|
"devDependencies": {
|
|
49
|
-
"@backstage/cli": "^0.26.
|
|
50
|
-
"@backstage/dev-utils": "^1.0.
|
|
51
|
-
"@backstage/test-utils": "^1.5.
|
|
53
|
+
"@backstage/cli": "^0.26.11",
|
|
54
|
+
"@backstage/dev-utils": "^1.0.36",
|
|
55
|
+
"@backstage/test-utils": "^1.5.9",
|
|
52
56
|
"@testing-library/dom": "^10.0.0",
|
|
53
57
|
"@testing-library/jest-dom": "^6.0.0",
|
|
54
58
|
"@testing-library/react": "^15.0.0",
|