tortoise-orm-studio 1.0.0__py3-none-any.whl

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.
Files changed (68) hide show
  1. tortoise_orm_studio/__init__.py +11 -0
  2. tortoise_orm_studio/adapters/__init__.py +1 -0
  3. tortoise_orm_studio/adapters/aiohttp_adapter.py +31 -0
  4. tortoise_orm_studio/adapters/asgi.py +89 -0
  5. tortoise_orm_studio/adapters/base.py +25 -0
  6. tortoise_orm_studio/adapters/django_adapter.py +84 -0
  7. tortoise_orm_studio/adapters/quart_adapter.py +32 -0
  8. tortoise_orm_studio/adapters/registry.py +39 -0
  9. tortoise_orm_studio/adapters/sanic_adapter.py +39 -0
  10. tortoise_orm_studio/auth.py +34 -0
  11. tortoise_orm_studio/cli.py +41 -0
  12. tortoise_orm_studio/core/__init__.py +1 -0
  13. tortoise_orm_studio/core/aerich.py +86 -0
  14. tortoise_orm_studio/core/ai.py +87 -0
  15. tortoise_orm_studio/core/audit.py +69 -0
  16. tortoise_orm_studio/core/config.py +58 -0
  17. tortoise_orm_studio/core/filters.py +94 -0
  18. tortoise_orm_studio/core/handler.py +249 -0
  19. tortoise_orm_studio/core/http.py +55 -0
  20. tortoise_orm_studio/core/i18n.py +18 -0
  21. tortoise_orm_studio/core/introspect.py +197 -0
  22. tortoise_orm_studio/core/manifest.py +128 -0
  23. tortoise_orm_studio/core/pagination.py +59 -0
  24. tortoise_orm_studio/core/permissions.py +46 -0
  25. tortoise_orm_studio/core/plugins.py +214 -0
  26. tortoise_orm_studio/core/ratelimit.py +32 -0
  27. tortoise_orm_studio/core/scoping.py +23 -0
  28. tortoise_orm_studio/core/serializers.py +61 -0
  29. tortoise_orm_studio/core/service.py +594 -0
  30. tortoise_orm_studio/plugins.py +8 -0
  31. tortoise_orm_studio/static/ALPINE_LICENSE.txt +11 -0
  32. tortoise_orm_studio/static/_types.d.ts +706 -0
  33. tortoise_orm_studio/static/a11y.js +115 -0
  34. tortoise_orm_studio/static/ai.js +66 -0
  35. tortoise_orm_studio/static/alpine.min.js +23 -0
  36. tortoise_orm_studio/static/app.css +514 -0
  37. tortoise_orm_studio/static/app.js +1443 -0
  38. tortoise_orm_studio/static/audit.js +171 -0
  39. tortoise_orm_studio/static/copy-as.js +118 -0
  40. tortoise_orm_studio/static/er-layout.js +227 -0
  41. tortoise_orm_studio/static/er.js +296 -0
  42. tortoise_orm_studio/static/filters.js +114 -0
  43. tortoise_orm_studio/static/i18n.en.js +190 -0
  44. tortoise_orm_studio/static/i18n.js +140 -0
  45. tortoise_orm_studio/static/i18n.zh-CN.js +189 -0
  46. tortoise_orm_studio/static/index.html +515 -0
  47. tortoise_orm_studio/static/inline-edit.js +107 -0
  48. tortoise_orm_studio/static/json-view.js +161 -0
  49. tortoise_orm_studio/static/migrations.js +139 -0
  50. tortoise_orm_studio/static/palette.js +141 -0
  51. tortoise_orm_studio/static/pending.js +240 -0
  52. tortoise_orm_studio/static/pickers.js +230 -0
  53. tortoise_orm_studio/static/playground.js +105 -0
  54. tortoise_orm_studio/static/query-history.js +84 -0
  55. tortoise_orm_studio/static/shortcuts.js +145 -0
  56. tortoise_orm_studio/static/state-hash.js +112 -0
  57. tortoise_orm_studio/static/tabs.js +368 -0
  58. tortoise_orm_studio/static/theme-init.js +33 -0
  59. tortoise_orm_studio/static/theme.js +106 -0
  60. tortoise_orm_studio/static/toasts.js +76 -0
  61. tortoise_orm_studio/static/views.js +70 -0
  62. tortoise_orm_studio/static/widgets.js +345 -0
  63. tortoise_orm_studio/studio.py +51 -0
  64. tortoise_orm_studio-1.0.0.dist-info/METADATA +177 -0
  65. tortoise_orm_studio-1.0.0.dist-info/RECORD +68 -0
  66. tortoise_orm_studio-1.0.0.dist-info/WHEEL +4 -0
  67. tortoise_orm_studio-1.0.0.dist-info/entry_points.txt +2 -0
  68. tortoise_orm_studio-1.0.0.dist-info/licenses/LICENSE +13 -0
@@ -0,0 +1,368 @@
1
+ // @ts-check
2
+ /**
3
+ * Pure tab-state machine for the studio UI (program G1, v0.3.3).
4
+ *
5
+ * No DOM, no storage, no Alpine: every operation is a plain function over a
6
+ * plain object, so the whole feature is testable with `node --test`. Storage
7
+ * is done by `serialise`/`restore`, which whitelist state keys so **no row
8
+ * data is ever persisted** (only model keys, filters, sort, page, columns,
9
+ * selection and scroll position).
10
+ *
11
+ * Types: TabState, Tab, TabStore from _types.d.ts.
12
+ */
13
+ (function (/** @type {any} */ global) {
14
+ "use strict";
15
+
16
+ var DEFAULT_CAP = 12;
17
+
18
+ /** State keys that may be persisted or round-tripped through the URL hash. */
19
+ var STATE_KEYS = [
20
+ "view", "model", "filters", "sort", "page", "limit", "search",
21
+ "cols", "hiddenCols", "selectedPk", "scroll", "connection",
22
+ "playgroundModel", "playgroundFilters", "playgroundSearch", "playgroundSort",
23
+ ];
24
+
25
+ /**
26
+ * @param {any} state
27
+ * @returns {TabState}
28
+ */
29
+ function cleanState(state) {
30
+ /** @type {any} */
31
+ var out = {};
32
+ for (var key of STATE_KEYS) {
33
+ if (state && Object.prototype.hasOwnProperty.call(state, key)) {
34
+ var value = state[key];
35
+ // Never keep row objects, even if a caller tries to sneak them in.
36
+ if (key === "selectedPk" && value && typeof value === "object") {
37
+ // A caller may pass a whole row; keep only its primary key. Rows
38
+ // from the API carry `_pk`, but accept `pk`/`id` too.
39
+ out[key] = value._pk !== undefined ? value._pk
40
+ : value.pk !== undefined ? value.pk
41
+ : value.id !== undefined ? value.id : null;
42
+ } else if (key === "cols" && Array.isArray(value)) {
43
+ out[key] = value.filter(function (/** @type {any} */ x) { return typeof x === "string"; });
44
+ } else if (key === "filters" && Array.isArray(value)) {
45
+ out[key] = value.filter(function (/** @type {any} */ f) {
46
+ return f && typeof f.field === "string" && typeof f.op === "string";
47
+ });
48
+ } else {
49
+ out[key] = value;
50
+ }
51
+ }
52
+ }
53
+ return /** @type {TabState} */ (out);
54
+ }
55
+
56
+ /**
57
+ * @returns {string}
58
+ */
59
+ function newId() {
60
+ return "t" + Date.now().toString(36) + Math.random().toString(36).slice(2, 7);
61
+ }
62
+
63
+ /**
64
+ * @param {number} [cap]
65
+ * @returns {TabStore}
66
+ */
67
+ function create(cap) {
68
+ return {
69
+ tabs: [],
70
+ activeId: null,
71
+ split: false,
72
+ cap: typeof cap === "number" && cap > 0 ? cap : DEFAULT_CAP,
73
+ error: null,
74
+ };
75
+ }
76
+
77
+ /**
78
+ * @param {TabStore} store
79
+ * @returns {Tab | undefined}
80
+ */
81
+ function active(store) {
82
+ return store.tabs.find(function (/** @type {Tab} */ t) { return t.id === store.activeId; });
83
+ }
84
+
85
+ /**
86
+ * A short human title derived only from the whitelisted state.
87
+ * @param {TabState} state
88
+ * @returns {string}
89
+ */
90
+ function titleFor(state) {
91
+ if (state.view === "playground") return "Playground";
92
+ if (state.view === "er") return "ER diagram";
93
+ if (state.view === "migrations") return "Migrations";
94
+ if (state.view === "audit") return "Audit";
95
+ if (state.model) return state.model.split(".").pop() || state.model;
96
+ return "New tab";
97
+ }
98
+
99
+ /**
100
+ * Add a tab. Returns a NEW store (never mutates the argument), the new tab
101
+ * and an error message when the cap is reached.
102
+ * @param {TabStore} store
103
+ * @param {any} state
104
+ * @param {{ activate?: boolean, pane?: number, force?: boolean }} [opts]
105
+ * @returns {{ store: TabStore, tab: Tab | null, error: string | null }}
106
+ */
107
+ function add(store, state, opts) {
108
+ var options = opts || {};
109
+ if (store.tabs.length >= store.cap && !options.force) {
110
+ return {
111
+ store: store, tab: null,
112
+ error: "Tab limit reached (" + store.cap + "). Close a tab first.",
113
+ };
114
+ }
115
+ /** @type {Tab} */
116
+ var tab = {
117
+ id: newId(),
118
+ title: titleFor(cleanState(state)),
119
+ state: cleanState(state),
120
+ pinned: false,
121
+ pane: options.pane === 1 ? 1 : 0,
122
+ dirty: false,
123
+ };
124
+ var tabs = store.tabs.concat([tab]);
125
+ return {
126
+ store: {
127
+ tabs: tabs,
128
+ activeId: options.activate === false ? store.activeId : tab.id,
129
+ split: store.split,
130
+ cap: store.cap,
131
+ error: null,
132
+ },
133
+ tab: tab,
134
+ error: null,
135
+ };
136
+ }
137
+
138
+ /**
139
+ * Duplicate a tab with a deep-cloned state (state isolation between tabs).
140
+ * @param {TabStore} store
141
+ * @param {string} id
142
+ * @returns {{ store: TabStore, tab: Tab | null, error: string | null }}
143
+ */
144
+ function duplicate(store, id) {
145
+ var source = store.tabs.find(function (/** @type {Tab} */ t) { return t.id === id; });
146
+ if (!source) return { store: store, tab: null, error: "No such tab" };
147
+ return add(store, JSON.parse(JSON.stringify(source.state)), { pane: source.pane });
148
+ }
149
+
150
+ /**
151
+ * Close a tab. Pinned tabs are kept unless `force` is set. The active tab
152
+ * falls to its neighbour (left first, then right).
153
+ * @param {TabStore} store
154
+ * @param {string} id
155
+ * @param {{ force?: boolean }} [opts]
156
+ * @returns {{ store: TabStore, error: string | null }}
157
+ */
158
+ function close(store, id, opts) {
159
+ var tab = store.tabs.find(function (/** @type {Tab} */ t) { return t.id === id; });
160
+ if (!tab) return { store: store, error: "No such tab" };
161
+ if (tab.pinned && !(opts && opts.force)) {
162
+ return { store: store, error: "Tab is pinned" };
163
+ }
164
+ var index = store.tabs.indexOf(tab);
165
+ var tabs = store.tabs.filter(function (/** @type {Tab} */ t) { return t.id !== id; });
166
+ var nextActive = store.activeId;
167
+ if (store.activeId === id) {
168
+ // Prefer the left neighbour, then the right one.
169
+ var neighbour = tabs[index - 1] || tabs[index] || tabs[0];
170
+ nextActive = neighbour ? neighbour.id : null;
171
+ }
172
+ return {
173
+ store: {
174
+ tabs: tabs, activeId: nextActive, split: store.split,
175
+ cap: store.cap, error: null,
176
+ },
177
+ error: null,
178
+ };
179
+ }
180
+
181
+ /**
182
+ * Move a tab to a new index. Order is stable for all other tabs.
183
+ * @param {TabStore} store
184
+ * @param {string} id
185
+ * @param {number} toIndex
186
+ * @returns {TabStore}
187
+ */
188
+ function move(store, id, toIndex) {
189
+ var from = store.tabs.findIndex(function (/** @type {Tab} */ t) { return t.id === id; });
190
+ if (from < 0) return store;
191
+ var target = Math.max(0, Math.min(store.tabs.length - 1, toIndex));
192
+ var tabs = store.tabs.slice();
193
+ var item = /** @type {Tab} */ (tabs.splice(from, 1)[0]);
194
+ tabs.splice(target, 0, item);
195
+ return {
196
+ tabs: tabs, activeId: store.activeId, split: store.split,
197
+ cap: store.cap, error: null,
198
+ };
199
+ }
200
+
201
+ /** @param {TabStore} store @param {string} id @returns {TabStore} */
202
+ function togglePin(store, id) {
203
+ return {
204
+ tabs: store.tabs.map(function (/** @type {Tab} */ t) {
205
+ return t.id === id ? { id: t.id, title: t.title, state: t.state,
206
+ pinned: !t.pinned, pane: t.pane, dirty: t.dirty } : t;
207
+ }),
208
+ activeId: store.activeId, split: store.split, cap: store.cap, error: null,
209
+ };
210
+ }
211
+
212
+ /** @param {TabStore} store @param {string} id @returns {TabStore} */
213
+ function activate(store, id) {
214
+ if (!store.tabs.some(function (/** @type {Tab} */ t) { return t.id === id; })) return store;
215
+ return { tabs: store.tabs, activeId: id, split: store.split, cap: store.cap, error: null };
216
+ }
217
+
218
+ /** @param {TabStore} store @param {boolean} on @returns {TabStore} */
219
+ function setSplit(store, on) {
220
+ return { tabs: store.tabs, activeId: store.activeId,
221
+ split: !!on, cap: store.cap, error: null };
222
+ }
223
+
224
+ /**
225
+ * @param {TabStore} store @param {string} id @param {number} pane
226
+ * @returns {TabStore}
227
+ */
228
+ function setPane(store, id, pane) {
229
+ return {
230
+ tabs: store.tabs.map(function (/** @type {Tab} */ t) {
231
+ return t.id === id ? { id: t.id, title: t.title, state: t.state,
232
+ pinned: t.pinned, pane: pane === 1 ? 1 : 0, dirty: t.dirty } : t;
233
+ }),
234
+ activeId: store.activeId, split: store.split, cap: store.cap, error: null,
235
+ };
236
+ }
237
+
238
+ /**
239
+ * Patch a tab's state. Row objects are stripped by cleanState.
240
+ * @param {TabStore} store @param {string} id @param {any} patch
241
+ * @returns {TabStore}
242
+ */
243
+ function updateState(store, id, patch) {
244
+ return {
245
+ tabs: store.tabs.map(function (/** @type {Tab} */ t) {
246
+ if (t.id !== id) return t;
247
+ var merged = /** @type {any} */ ({});
248
+ for (var k of Object.keys(t.state)) merged[k] = /** @type {any} */ (t.state)[k];
249
+ for (var k2 of Object.keys(patch || {})) merged[k2] = patch[k2];
250
+ return { id: t.id, title: titleFor(cleanState(merged)), state: cleanState(merged),
251
+ pinned: t.pinned, pane: t.pane, dirty: t.dirty };
252
+ }),
253
+ activeId: store.activeId, split: store.split, cap: store.cap, error: null,
254
+ };
255
+ }
256
+
257
+ /**
258
+ * Mark a tab dirty/clean (hooks into the v0.5.0 staged-changes guard).
259
+ * @param {TabStore} store @param {string} id @param {boolean} dirty
260
+ * @returns {TabStore}
261
+ */
262
+ function setDirty(store, id, dirty) {
263
+ return {
264
+ tabs: store.tabs.map(function (/** @type {Tab} */ t) {
265
+ return t.id === id ? { id: t.id, title: t.title, state: t.state,
266
+ pinned: t.pinned, pane: t.pane, dirty: !!dirty } : t;
267
+ }),
268
+ activeId: store.activeId, split: store.split, cap: store.cap, error: null,
269
+ };
270
+ }
271
+
272
+ /**
273
+ * Persist only whitelisted data — never row values.
274
+ * @param {TabStore} store
275
+ * @returns {string}
276
+ */
277
+ function serialise(store) {
278
+ return JSON.stringify({
279
+ version: 1,
280
+ cap: store.cap,
281
+ split: store.split,
282
+ activeId: store.activeId,
283
+ tabs: store.tabs.map(function (/** @type {Tab} */ t) {
284
+ return { id: t.id, title: t.title, state: t.state, pinned: t.pinned, pane: t.pane };
285
+ }),
286
+ });
287
+ }
288
+
289
+ /**
290
+ * Restore from JSON. Tolerates malformed input and always returns a
291
+ * usable store. `dirty` is intentionally not persisted.
292
+ * @param {string | null} json
293
+ * @param {number} [cap]
294
+ * @returns {TabStore}
295
+ */
296
+ function restore(json, cap) {
297
+ var store = create(cap);
298
+ if (!json) return store;
299
+ /** @type {any} */
300
+ var data;
301
+ try { data = JSON.parse(json); } catch (e) { return store; }
302
+ if (!data || !Array.isArray(data.tabs)) return store;
303
+ var seen = Object.create(null);
304
+ /** @type {Tab[]} */
305
+ var tabs = [];
306
+ for (var t of data.tabs) {
307
+ if (!t || typeof t.id !== "string" || seen[t.id]) continue;
308
+ seen[t.id] = true;
309
+ if (tabs.length >= store.cap) break;
310
+ tabs.push({
311
+ id: t.id,
312
+ title: typeof t.title === "string" ? t.title : titleFor(cleanState(t.state)),
313
+ state: cleanState(t.state),
314
+ pinned: !!t.pinned,
315
+ pane: t.pane === 1 ? 1 : 0,
316
+ dirty: false,
317
+ });
318
+ }
319
+ var active = tabs.some(function (/** @type {Tab} */ t) { return t.id === data.activeId; })
320
+ ? data.activeId : (tabs[0] ? tabs[0].id : null);
321
+ return {
322
+ tabs: tabs, activeId: active, split: !!data.split,
323
+ cap: store.cap, error: null,
324
+ };
325
+ }
326
+
327
+ /**
328
+ * Save into a storage-like object, swallowing quota/permission errors.
329
+ * @param {TabStore} store
330
+ * @param {any} storage
331
+ * @param {string} [key]
332
+ * @returns {boolean}
333
+ */
334
+ function save(store, storage, key) {
335
+ try {
336
+ if (!storage) return false;
337
+ storage.setItem(key || "studio.tabs.v1", serialise(store));
338
+ return true;
339
+ } catch (e) {
340
+ return false;
341
+ }
342
+ }
343
+
344
+ /**
345
+ * Load from a storage-like object, swallowing errors.
346
+ * @param {any} storage
347
+ * @param {number} [cap]
348
+ * @param {string} [key]
349
+ * @returns {TabStore}
350
+ */
351
+ function load(storage, cap, key) {
352
+ try {
353
+ if (!storage) return create(cap);
354
+ return restore(storage.getItem(key || "studio.tabs.v1"), cap);
355
+ } catch (e) {
356
+ return create(cap);
357
+ }
358
+ }
359
+
360
+ global.StudioTabs = {
361
+ DEFAULT_CAP: DEFAULT_CAP, STATE_KEYS: STATE_KEYS,
362
+ create: create, active: active, add: add, duplicate: duplicate, close: close,
363
+ move: move, togglePin: togglePin, activate: activate, setSplit: setSplit,
364
+ setPane: setPane, updateState: updateState, setDirty: setDirty,
365
+ serialise: serialise, restore: restore, save: save, load: load,
366
+ cleanState: cleanState, titleFor: titleFor,
367
+ };
368
+ })(typeof window !== "undefined" ? window : globalThis);
@@ -0,0 +1,33 @@
1
+ // @ts-check
2
+ /**
3
+ * First-paint theme. Synchronous by design: it runs in <head> *before* the
4
+ * body is painted, so the user never sees a flash of the wrong theme. Keep it
5
+ * tiny, dependency-free and free of any work other than reading one storage
6
+ * key and setting one attribute.
7
+ *
8
+ * A separate file (not an inline <script>) because the CSP is
9
+ * `script-src 'self'` — inline script would be blocked.
10
+ *
11
+ * This file deliberately does not use StudioTheme: theme.js is deferred and
12
+ * has not run yet at this point.
13
+ */
14
+ (function (/** @type {any} */ g) {
15
+ "use strict";
16
+
17
+ var KEY = "studio.theme.v1";
18
+ /** @type {string} */
19
+ var choice = "system";
20
+ try {
21
+ var raw = g.localStorage.getItem(KEY);
22
+ if (raw === "light" || raw === "dark" || raw === "system") choice = raw;
23
+ } catch (e) {
24
+ // localStorage can throw (private mode, disabled storage): use the system.
25
+ }
26
+
27
+ var root = g.document.documentElement;
28
+ if (choice === "light" || choice === "dark") {
29
+ root.setAttribute("data-theme", choice);
30
+ } else {
31
+ root.removeAttribute("data-theme");
32
+ }
33
+ })(window);
@@ -0,0 +1,106 @@
1
+ // @ts-check
2
+ /**
3
+ * Theme choice: what the user picked (Light / Dark / System), and how it maps
4
+ * onto the document.
5
+ *
6
+ * Pure logic — no DOM lookups beyond the object handed to `apply()`, and every
7
+ * storage access is wrapped, because localStorage throws in Safari private
8
+ * mode and can be missing entirely (embedded webviews, disabled cookies).
9
+ *
10
+ * Loaded as a normal (deferred) script; the *first paint* is handled by
11
+ * `theme-init.js`, which must stay separate and synchronous.
12
+ */
13
+ (function (/** @type {Window & { StudioTheme?: ThemeAPI }} */ global) {
14
+ "use strict";
15
+
16
+ const KEY = "studio.theme.v1";
17
+ /** @type {ThemeChoice[]} */
18
+ const CHOICES = ["light", "dark", "system"];
19
+
20
+ /**
21
+ * Coerce arbitrary input (stored value, URL param, attribute) to a choice.
22
+ * @param {unknown} value
23
+ * @returns {ThemeChoice}
24
+ */
25
+ function normalize(value) {
26
+ if (typeof value !== "string") return "system";
27
+ const v = value.trim().toLowerCase();
28
+ return /** @type {ThemeChoice} */ (
29
+ CHOICES.indexOf(/** @type {ThemeChoice} */ (v)) >= 0 ? v : "system"
30
+ );
31
+ }
32
+
33
+ /**
34
+ * The theme that will actually be painted.
35
+ * @param {ThemeChoice} choice
36
+ * @param {boolean} prefersDark OS preference (matchMedia).
37
+ * @returns {"light" | "dark"}
38
+ */
39
+ function resolve(choice, prefersDark) {
40
+ const c = normalize(choice);
41
+ if (c === "system") return prefersDark ? "dark" : "light";
42
+ return c;
43
+ }
44
+
45
+ /**
46
+ * The `data-theme` value to set, or `null` to leave the attribute off so the
47
+ * `prefers-color-scheme` rule in app.css decides.
48
+ * @param {ThemeChoice} choice
49
+ * @returns {"light" | "dark" | null}
50
+ */
51
+ function attributeFor(choice) {
52
+ const c = normalize(choice);
53
+ return c === "system" ? null : c;
54
+ }
55
+
56
+ /**
57
+ * Next choice when the user activates the toggle.
58
+ * @param {ThemeChoice} choice
59
+ * @returns {ThemeChoice}
60
+ */
61
+ function next(choice) {
62
+ const i = CHOICES.indexOf(normalize(choice));
63
+ return CHOICES[(i + 1) % CHOICES.length];
64
+ }
65
+
66
+ /** @returns {ThemeChoice} */
67
+ function load() {
68
+ try {
69
+ return normalize(global.localStorage.getItem(KEY));
70
+ } catch {
71
+ return "system";
72
+ }
73
+ }
74
+
75
+ /** @param {ThemeChoice} choice */
76
+ function save(choice) {
77
+ try {
78
+ global.localStorage.setItem(KEY, normalize(choice));
79
+ } catch {
80
+ // storage unavailable or full: the choice simply does not persist
81
+ }
82
+ }
83
+
84
+ /**
85
+ * Paint a choice onto a document root.
86
+ * @param {{ documentElement: Element }} doc
87
+ * @param {ThemeChoice} choice
88
+ */
89
+ function apply(doc, choice) {
90
+ const attr = attributeFor(choice);
91
+ if (attr) doc.documentElement.setAttribute("data-theme", attr);
92
+ else doc.documentElement.removeAttribute("data-theme");
93
+ }
94
+
95
+ global.StudioTheme = {
96
+ KEY: KEY,
97
+ CHOICES: CHOICES,
98
+ normalize: normalize,
99
+ resolve: resolve,
100
+ attributeFor: attributeFor,
101
+ next: next,
102
+ load: load,
103
+ save: save,
104
+ apply: apply,
105
+ };
106
+ })(typeof window !== "undefined" ? window : /** @type {any} */ (globalThis));
@@ -0,0 +1,76 @@
1
+ // @ts-check
2
+ /**
3
+ * CSP-safe toast notifications.
4
+ *
5
+ * window.StudioToasts.show(message, kind) — kind is 'info'|'success'|'warn'|'error'.
6
+ * Auto-dismisses after 4s; caps visible at 5; × button to dismiss early.
7
+ * No eval, no inline handlers, textContent only.
8
+ *
9
+ * Type (ToastsAPI) lives in _types.d.ts.
10
+ */
11
+
12
+ (function (/** @type {Window & { StudioToasts?: ToastsAPI }} */ global) {
13
+ "use strict";
14
+
15
+ const DURATION_MS = 4000;
16
+ const MAX_VISIBLE = 5;
17
+ /** @type {HTMLElement|null} */
18
+ let container = null;
19
+
20
+ /** @returns {HTMLElement} */
21
+ function ensureContainer() {
22
+ if (container && document.body.contains(container)) return container;
23
+ container = document.createElement("div");
24
+ container.className = "toast-container";
25
+ container.setAttribute("role", "status");
26
+ container.setAttribute("aria-live", "polite");
27
+ document.body.appendChild(container);
28
+ return container;
29
+ }
30
+
31
+ /** @param {HTMLElement} el */
32
+ function dismiss(el) {
33
+ if (!el.parentNode) return;
34
+ el.classList.add("toast-out");
35
+ setTimeout(function () {
36
+ if (el.parentNode) el.parentNode.removeChild(el);
37
+ }, 220);
38
+ }
39
+
40
+ /**
41
+ * @param {string} message
42
+ * @param {"info"|"success"|"warn"|"error"} [kind]
43
+ * @returns {HTMLElement}
44
+ */
45
+ function show(message, kind) {
46
+ const c = ensureContainer();
47
+ while (c.children.length >= MAX_VISIBLE) {
48
+ c.removeChild(c.firstChild);
49
+ }
50
+ const el = document.createElement("div");
51
+ el.className = "toast toast-" + (kind || "info");
52
+ const msg = document.createElement("span");
53
+ msg.className = "toast-message";
54
+ msg.textContent = message;
55
+ const btn = document.createElement("button");
56
+ btn.type = "button";
57
+ btn.className = "toast-close";
58
+ btn.setAttribute("aria-label", "Dismiss");
59
+ btn.textContent = "×";
60
+ btn.addEventListener("click", function () { dismiss(el); });
61
+ el.appendChild(msg);
62
+ el.appendChild(btn);
63
+ c.appendChild(el);
64
+ setTimeout(function () { dismiss(el); }, DURATION_MS);
65
+ return el;
66
+ }
67
+
68
+ global.StudioToasts = {
69
+ show: show,
70
+ error: /** @param {string} m */ function (m) { return show(m, "error"); },
71
+ warn: /** @param {string} m */ function (m) { return show(m, "warn"); },
72
+ info: /** @param {string} m */ function (m) { return show(m, "info"); },
73
+ success: /** @param {string} m */ function (m) { return show(m, "success"); },
74
+ clear: function () { if (container) container.textContent = ""; },
75
+ };
76
+ })(window);
@@ -0,0 +1,70 @@
1
+ // @ts-check
2
+ /**
3
+ * Saved views — localStorage persistence only.
4
+ *
5
+ * The API is intentionally tiny: load/save/remove plus a serialize helper.
6
+ * No app state lives here; app.js owns the current state, calls these
7
+ * functions to persist or recall snapshots.
8
+ *
9
+ * Storage key: ``studio.savedViews.v1``
10
+ * Shape: ``{[name]: SavedView}`` — see _types.d.ts.
11
+ */
12
+
13
+ (function (/** @type {Window & { StudioViews?: ViewsAPI }} */ global) {
14
+ "use strict";
15
+
16
+ const KEY = "studio.savedViews.v1";
17
+
18
+ /** @returns {SavedViews} */
19
+ function load() {
20
+ try {
21
+ const raw = global.localStorage.getItem(KEY);
22
+ if (!raw) return {};
23
+ const parsed = JSON.parse(raw);
24
+ if (!parsed || typeof parsed !== "object" || Array.isArray(parsed)) return {};
25
+ return /** @type {SavedViews} */ (parsed);
26
+ } catch {
27
+ return {};
28
+ }
29
+ }
30
+
31
+ /** @param {SavedViews} views */
32
+ function save(views) {
33
+ try {
34
+ global.localStorage.setItem(KEY, JSON.stringify(views));
35
+ } catch {
36
+ // quota exceeded or unavailable — silent
37
+ }
38
+ }
39
+
40
+ /** @param {string} name */
41
+ function remove(name) {
42
+ const views = load();
43
+ delete views[name];
44
+ save(views);
45
+ }
46
+
47
+ /**
48
+ * @param {{
49
+ * name: string; current: string; filters: FilterPredicate[];
50
+ * sort: string; search: string; cols: string[];
51
+ * allCols: string[]; hiddenCols: Record<string, boolean>;
52
+ * }} state
53
+ * @returns {SavedView}
54
+ */
55
+ function serialize(state) {
56
+ return {
57
+ name: state.name,
58
+ model: state.current,
59
+ filters: (state.filters || []).slice(),
60
+ sort: state.sort || "",
61
+ search: state.search || "",
62
+ cols: (state.cols || []).slice(),
63
+ allCols: (state.allCols || []).slice(),
64
+ hiddenCols: { ...(state.hiddenCols || {}) },
65
+ savedAt: new Date().toISOString(),
66
+ };
67
+ }
68
+
69
+ global.StudioViews = { load: load, save: save, remove: remove, serialize: serialize };
70
+ })(window);