@matdata/yasgui 4.6.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/package.json ADDED
@@ -0,0 +1,48 @@
1
+ {
2
+ "name": "@matdata/yasgui",
3
+ "description": "Yet Another SPARQL GUI",
4
+ "version": "4.6.1",
5
+ "main": "build/yasgui.min.js",
6
+ "types": "build/ts/src/index.d.ts",
7
+ "license": "MIT",
8
+ "author": "Triply <info@triply.cc>",
9
+ "homepage": "https://github.com/Matdata-eu/Yasgui",
10
+ "keywords": [
11
+ "JavaScript",
12
+ "SPARQL",
13
+ "Editor",
14
+ "Semantic Web",
15
+ "Linked Data"
16
+ ],
17
+ "bugs": "https://github.com/Matdata-eu/Yasgui/issues/",
18
+ "repository": {
19
+ "type": "git",
20
+ "url": "https://github.com/Matdata-eu/Yasgui.git",
21
+ "directory": "packages/yasgui"
22
+ },
23
+ "dependencies": {
24
+ "@tarekraafat/autocomplete.js": "^7.2.0",
25
+ "@matdata/yasgui-utils": "^4.6.1",
26
+ "@matdata/yasqe": "^4.6.1",
27
+ "@matdata/yasr": "^4.6.1",
28
+ "autosuggest-highlight": "^3.1.1",
29
+ "blueimp-md5": "^2.12.0",
30
+ "choices.js": "^9.0.1",
31
+ "dompurify": "^3.2.4",
32
+ "es6-object-assign": "^1.1.0",
33
+ "jsuri": "^1.3.1",
34
+ "lodash-es": "^4.17.15",
35
+ "sortablejs": "^1.10.2",
36
+ "@matdata/yasgui-graph-plugin": "^1.0.0"
37
+ },
38
+ "devDependencies": {
39
+ "@types/autosuggest-highlight": "^3.1.0",
40
+ "@types/blueimp-md5": "^2.7.0",
41
+ "@types/jsuri": "^1.3.30",
42
+ "@types/lodash-es": "^4.17.3",
43
+ "@types/node": "^22.5.4"
44
+ },
45
+ "publishConfig": {
46
+ "access": "public"
47
+ }
48
+ }
@@ -0,0 +1,159 @@
1
+ import { Storage as YStorage } from "@matdata/yasgui-utils";
2
+ import Yasgui from "./";
3
+ import * as Tab from "./Tab";
4
+ export var storageNamespace = "triply";
5
+ export interface PersistedJson {
6
+ endpointHistory: string[];
7
+ tabs: string[];
8
+ active: string | undefined;
9
+ tabConfig: { [tabId: string]: Tab.PersistedJson };
10
+ lastClosedTab: { index: number; tab: Tab.PersistedJson } | undefined;
11
+ prefixes?: string;
12
+ autoCaptureEnabled?: boolean;
13
+ }
14
+ function getDefaults(): PersistedJson {
15
+ return {
16
+ endpointHistory: [],
17
+ tabs: [],
18
+ active: undefined,
19
+ tabConfig: {},
20
+ lastClosedTab: undefined,
21
+ prefixes: "",
22
+ autoCaptureEnabled: true,
23
+ };
24
+ }
25
+
26
+ export default class PersistentConfig {
27
+ private persistedJson!: PersistedJson;
28
+ private storageId: string | undefined;
29
+ private yasgui: Yasgui;
30
+ private storage: YStorage;
31
+ constructor(yasgui: Yasgui) {
32
+ this.yasgui = yasgui;
33
+ this.storageId = this.yasgui.getStorageId(this.yasgui.config.persistenceLabelConfig);
34
+ this.storage = new YStorage(storageNamespace);
35
+ this.fromStorage();
36
+ this.registerListeners();
37
+ }
38
+
39
+ public setActive(id: string) {
40
+ this.persistedJson.active = id;
41
+ this.toStorage();
42
+ }
43
+ public getActiveId(): string | undefined {
44
+ return this.persistedJson.active;
45
+ }
46
+ public addToTabList(tabId: string, index?: number) {
47
+ if (index !== undefined && this.persistedJson.tabs.length > index) {
48
+ this.persistedJson.tabs.splice(index, 0, tabId);
49
+ } else {
50
+ this.persistedJson.tabs.push(tabId);
51
+ }
52
+
53
+ this.toStorage();
54
+ }
55
+ public setTabOrder(tabs: string[]) {
56
+ this.persistedJson.tabs = tabs;
57
+ this.toStorage();
58
+ }
59
+ public getEndpointHistory() {
60
+ return this.persistedJson.endpointHistory;
61
+ }
62
+ public retrieveLastClosedTab() {
63
+ const tabCopy = this.persistedJson.lastClosedTab;
64
+ if (tabCopy === undefined) return tabCopy;
65
+ this.persistedJson.lastClosedTab = undefined;
66
+ return tabCopy;
67
+ }
68
+ public hasLastClosedTab() {
69
+ return !!this.persistedJson.lastClosedTab;
70
+ }
71
+ public deleteTab(tabId: string) {
72
+ const i = this.persistedJson.tabs.indexOf(tabId);
73
+ if (i > -1) {
74
+ this.persistedJson.tabs.splice(i, 1);
75
+ }
76
+ if (this.tabIsActive(tabId)) {
77
+ this.persistedJson.active = undefined;
78
+ }
79
+ this.persistedJson.lastClosedTab = { index: i, tab: this.persistedJson.tabConfig[tabId] };
80
+ delete this.persistedJson.tabConfig[tabId];
81
+ this.toStorage();
82
+ }
83
+ private registerListeners() {
84
+ this.yasgui.on("tabChange", (_yasgui, tab) => {
85
+ this.persistedJson.tabConfig[tab.getId()] = tab.getPersistedJson();
86
+ this.toStorage();
87
+ });
88
+ this.yasgui.on("endpointHistoryChange", (_yasgui, history) => {
89
+ this.persistedJson.endpointHistory = history;
90
+ this.toStorage();
91
+ });
92
+ }
93
+
94
+ private toStorage() {
95
+ this.storage.set(
96
+ this.storageId,
97
+ this.persistedJson,
98
+ this.yasgui.config.persistencyExpire,
99
+ this.handleLocalStorageQuotaFull,
100
+ );
101
+ }
102
+ private fromStorage(): PersistedJson {
103
+ this.persistedJson = this.storage.get<PersistedJson>(this.storageId) || getDefaults();
104
+ /**
105
+ * Modify some settings for backwards compatability
106
+ */
107
+ if (!this.persistedJson.endpointHistory) {
108
+ this.persistedJson.endpointHistory = [];
109
+ }
110
+ return this.persistedJson;
111
+ }
112
+
113
+ private handleLocalStorageQuotaFull(_e: any) {
114
+ console.warn("Localstorage quota exceeded. Clearing all YASGUI configurations");
115
+ PersistentConfig.clear();
116
+ }
117
+
118
+ public getTabs() {
119
+ return this.persistedJson.tabs;
120
+ }
121
+ public getTab(tabId: string) {
122
+ return this.persistedJson.tabConfig[tabId];
123
+ }
124
+
125
+ /**
126
+ * We shouldnt normally need this (as this object simply listens to tab change events)
127
+ * Only exception is when we're loading a tab config from the url
128
+ * Then we'd like to forward that config to this object, so we can simply keep initializing from this persistence class
129
+ */
130
+ public setTab(tabId: string, tabConfig: Tab.PersistedJson) {
131
+ this.persistedJson.tabs.push(tabId);
132
+ this.persistedJson.tabConfig[tabId] = tabConfig;
133
+ this.persistedJson.active = tabId;
134
+ }
135
+ public tabIsActive(tabId: string) {
136
+ return tabId === this.persistedJson.active;
137
+ }
138
+ public currentId() {
139
+ return this.persistedJson.active;
140
+ }
141
+ public getPrefixes(): string {
142
+ return this.persistedJson.prefixes || "";
143
+ }
144
+ public setPrefixes(prefixes: string) {
145
+ this.persistedJson.prefixes = prefixes;
146
+ this.toStorage();
147
+ }
148
+ public getAutoCaptureEnabled(): boolean {
149
+ return this.persistedJson.autoCaptureEnabled !== false;
150
+ }
151
+ public setAutoCaptureEnabled(enabled: boolean) {
152
+ this.persistedJson.autoCaptureEnabled = enabled;
153
+ this.toStorage();
154
+ }
155
+ public static clear() {
156
+ const storage = new YStorage(storageNamespace);
157
+ storage.removeNamespace();
158
+ }
159
+ }