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,515 @@
1
+ <!doctype html>
2
+ <html lang="en">
3
+ <head>
4
+ <meta charset="utf-8">
5
+ <meta name="viewport" content="width=device-width,initial-scale=1">
6
+ <title>Tortoise ORM Studio</title>
7
+ <link rel="stylesheet" href="static/app.css">
8
+ <!-- Synchronous, external (CSP: script-src 'self'), sets data-theme before first paint. -->
9
+ <script src="static/theme-init.js"></script>
10
+ <script src="static/theme.js" defer></script>
11
+ <script src="static/shortcuts.js" defer></script>
12
+ <script src="static/state-hash.js" defer></script>
13
+ <script src="static/tabs.js" defer></script>
14
+ <script src="static/palette.js" defer></script>
15
+ <script src="static/pending.js" defer></script>
16
+ <script src="static/query-history.js" defer></script>
17
+ <script src="static/widgets.js" defer></script>
18
+ <script src="static/filters.js" defer></script>
19
+ <script src="static/pickers.js" defer></script>
20
+ <script src="static/toasts.js" defer></script>
21
+ <script src="static/playground.js" defer></script>
22
+ <script src="static/er-layout.js" defer></script>
23
+ <script src="static/er.js" defer></script>
24
+ <script src="static/migrations.js" defer></script>
25
+ <script src="static/audit.js" defer></script>
26
+ <script src="static/views.js" defer></script>
27
+ <script src="static/a11y.js" defer></script>
28
+ <!-- v0.9.0 i18n: runtime first, then dictionaries, then the component that uses t(). -->
29
+ <script src="static/i18n.js" defer></script>
30
+ <script src="static/i18n.en.js" defer></script>
31
+ <script src="static/i18n.zh-CN.js" defer></script>
32
+ <script src="static/ai.js" defer></script>
33
+ <script src="static/inline-edit.js" defer></script>
34
+ <script src="static/copy-as.js" defer></script>
35
+ <script src="static/json-view.js" defer></script>
36
+ <script src="static/app.js" defer></script>
37
+ <script src="static/alpine.min.js" defer></script>
38
+ </head>
39
+ <body x-data="studio">
40
+ <a class="skip-link" href="#main-content" x-text="tr('a11y.skip')">Skip to content</a>
41
+ <aside :class="{ collapsed: sidebarCollapsed }" :aria-label="tr('a11y.models')">
42
+ <div class="side-head">
43
+ <input type="search" class="side-filter" :placeholder="tr('model.filterPlaceholder')"
44
+ :aria-label="tr('model.filter')" x-model="sideFilter">
45
+ <button type="button" class="side-collapse" :aria-label="tr('a11y.collapseSidebar')"
46
+ :aria-expanded="!sidebarCollapsed ? 'true' : 'false'"
47
+ @click="toggleSidebar" x-text="sidebarCollapsed ? '»' : '«'"></button>
48
+ </div>
49
+ <template x-for="app in groupedApps" :key="app">
50
+ <div class="side-group">
51
+ <div class="side-group-title" x-text="app"></div>
52
+ <template x-for="m in modelsForApp(app)" :key="m.key">
53
+ <div class="side-item">
54
+ <button type="button" class="side-pin" :aria-label="isPinned(m.key) ? tr('model.unpin') : tr('model.pin')"
55
+ :aria-pressed="isPinned(m.key) ? 'true' : 'false'"
56
+ @click="togglePinModel(m.key)" x-text="isPinned(m.key) ? '★' : '☆'"></button>
57
+ <button type="button" class="side-model" x-text="m.name"
58
+ :title="m.key" :class="sideClass(m.key)"
59
+ @click="pick(m.key)"
60
+ @click.meta="openModelTab(m.key)" @click.ctrl="openModelTab(m.key)"></button>
61
+ </div>
62
+ </template>
63
+ </div>
64
+ </template>
65
+ </aside>
66
+ <main id="main-content" tabindex="-1">
67
+ <div class="tabbar">
68
+ <div class="tablist" role="group" :aria-label="tr('a11y.openViews')">
69
+ <template x-for="t in tabList" :key="t.id">
70
+ <div class="tab"
71
+ :class="{ active: t.id === activeTabId, pinned: t.pinned, dirty: t.dirty }"
72
+ @auxclick.middle="closeTab(t.id)">
73
+ <button type="button" class="tab-select"
74
+ :aria-pressed="t.id === activeTabId ? 'true' : 'false'"
75
+ @click="activateTab(t.id)" x-text="t.title"></button>
76
+ <button type="button" class="tab-close" :aria-label="tr('tab.close', { title: t.title })"
77
+ @click.stop="closeTab(t.id)">×</button>
78
+ </div>
79
+ </template>
80
+ </div>
81
+ <button type="button" class="tab-add" :aria-label="tr('tab.new')" @click="newTab">+</button>
82
+ <button type="button" class="tab-split" :aria-pressed="tabSplit ? 'true' : 'false'"
83
+ @click="toggleSplit" x-text="tr('tab.split')">Split</button>
84
+ <span class="tab-error" x-text="tabError" role="status"></span>
85
+ </div>
86
+ <header class="topbar">
87
+ <nav class="view-switch">
88
+ <button @click="viewList()" :class="viewClass('list')" x-text="tr('nav.list')">List</button>
89
+ <button @click="openPlayground()" :class="viewClass('playground')" x-text="tr('nav.playground')">Playground</button>
90
+ <button @click="openEr()" :class="viewClass('er')" x-text="tr('nav.er')">ER Diagram</button>
91
+ <button @click="openMigrations()" :class="viewClass('migrations')" x-text="tr('nav.migrations')">Migrations</button>
92
+ <button @click="openAudit()" :class="viewClass('audit')" x-text="tr('nav.audit')">Audit</button>
93
+ <button type="button" x-show="pluginActions.length" @click="viewPlugin()"
94
+ :class="viewClass('plugin')" x-text="tr('nav.plugins')">Plugins</button>
95
+ </nav>
96
+ <div class="topbar-right">
97
+ <div class="theme-toggle" role="group" :aria-label="tr('theme.label')">
98
+ <template x-for="c in themeChoices" :key="c">
99
+ <button type="button"
100
+ class="theme-opt"
101
+ :class="{ on: c === themeChoice }"
102
+ :aria-pressed="c === themeChoice ? 'true' : 'false'"
103
+ @click="setTheme(c)"
104
+ x-text="c"></button>
105
+ </template>
106
+ </div>
107
+ <label class="locale-switch" :aria-label="tr('locale.label')">
108
+ <span class="sr-only" x-text="tr('locale.label')">Language</span>
109
+ <select :value="locale" @change="setLocale($event.target.value)">
110
+ <template x-for="l in localeChoices" :key="l">
111
+ <option :value="l" x-text="l"></option>
112
+ </template>
113
+ </select>
114
+ </label>
115
+ <div class="views-wrap">
116
+ <button type="button" class="views-toggle" @click="viewsToggle">
117
+ <span x-text="tr('views.saved')">Saved Views</span> <span x-show="hasSavedViews" x-text="'(' + savedViewNames.length + ')'"></span>
118
+ </button>
119
+ <div class="views-menu" x-show="viewsOpen" @click.outside="viewsOpen = false">
120
+ <button type="button" class="views-save" @click="saveCurrentView" x-text="tr('views.saveCurrent')">Save current…</button>
121
+ <template x-if="hasSavedViews">
122
+ <hr>
123
+ </template>
124
+ <template x-for="n in savedViewNames" :key="n">
125
+ <div class="views-item">
126
+ <button type="button" class="views-load" @click="loadView(n)" x-text="n"></button>
127
+ <button type="button" class="views-delete" @click.stop="deleteView(n)" :aria-label="tr('views.delete')">×</button>
128
+ </div>
129
+ </template>
130
+ </div>
131
+ </div>
132
+ </div>
133
+ <label x-show="showConnection">
134
+ <span x-text="tr('connection.label')">Connection</span>
135
+ <select x-model="connection" @change="connectionChanged">
136
+ <option value="" x-text="tr('connection.default')">(default)</option>
137
+ <template x-for="c in connections" :key="c">
138
+ <option :value="c" x-text="c"></option>
139
+ </template>
140
+ </select>
141
+ </label>
142
+ </header>
143
+
144
+ <section x-show="isList || isDetail">
145
+ <div class="bar">
146
+ <input :placeholder="tr('list.searchPlaceholder')" :aria-label="tr('a11y.search')" x-model="search" @keydown.enter="doSearch">
147
+ <span class="mut" x-text="countLabel"></span>
148
+ <button type="button" class="density-toggle" :aria-pressed="dense ? 'true' : 'false'"
149
+ @click="dense = !dense" x-text="dense ? tr('list.density.comfortable') : tr('list.density.compact')"></button>
150
+ <button x-show="canWrite" @click="newRow" x-text="tr('list.new')">New</button>
151
+ <button type="button" x-show="canWrite && inline.last" @click="undoInline"
152
+ :aria-label="tr('list.undoInline')" x-text="tr('list.undoInline')">Undo edit</button>
153
+ </div>
154
+ <div class="filters-bar">
155
+ <template x-for="(f, i) in filters" :key="i">
156
+ <span class="chip">
157
+ <span x-text="chipLabel(f)"></span>
158
+ <button type="button" @click="removeFilter(i)" :aria-label="tr('list.removeFilter')">×</button>
159
+ </span>
160
+ </template>
161
+ <button type="button" @click="toggleAddFilter" x-text="showAddFilter ? tr('list.filter.cancel') : tr('list.filter.add')"></button>
162
+ <button type="button" x-show="hasFilters" @click="clearFilters" x-text="tr('list.clear')">Clear</button>
163
+ </div>
164
+ <div class="add-filter" x-show="showAddFilter">
165
+ <select x-model="draftField" @change="onDraftFieldChange">
166
+ <template x-for="f in filterableFields" :key="f.name">
167
+ <option :value="f.name" x-text="f.name"></option>
168
+ </template>
169
+ </select>
170
+ <select x-model="draftOp">
171
+ <template x-for="op in draftOps" :key="op">
172
+ <option :value="op" x-text="op"></option>
173
+ </template>
174
+ </select>
175
+ <input x-show="draftNeedsValue" x-model="draftValue" :placeholder="tr('list.filter.value')" :aria-label="tr('a11y.filterValue')" @keydown.enter="addFilter">
176
+ <button type="button" @click="addFilter" x-text="tr('list.filter.addButton')">Add</button>
177
+ <span class="widget-error" x-text="draftError"></span>
178
+ </div>
179
+ <div class="bulk-bar" x-show="hasSelection">
180
+ <span x-text="tr('list.selected', { count: selectedCount })"></span>
181
+ <button @click="bulkDelete" x-text="tr('list.deleteSelected')">Delete selected</button>
182
+ <button @click="clearSelection" x-text="tr('list.clear')">Clear</button>
183
+ </div>
184
+ <details class="colchooser">
185
+ <summary x-text="tr('list.columns')">Columns</summary>
186
+ <div class="colchooser-list">
187
+ <template x-for="c in allCols" :key="c">
188
+ <label>
189
+ <input type="checkbox" :checked="!isHidden(c)" @change="toggleCol(c)">
190
+ <span x-text="c"></span>
191
+ </label>
192
+ </template>
193
+ </div>
194
+ </details>
195
+ <template x-if="rows.length === 0">
196
+ <div class="empty-state" data-i18n="list.emptyState">No rows match this view. Try clearing filters or search.</div>
197
+ </template>
198
+ <div class="table-scroll">
199
+ <table :class="{ dense: dense }">
200
+ <thead><tr>
201
+ <template x-if="canWrite">
202
+ <th class="bulk-cell">
203
+ <input type="checkbox" :checked="allVisibleSelected" :aria-label="tr('a11y.selectAll')" @change="toggleSelectAll">
204
+ </th>
205
+ </template>
206
+ <th class="copy-cell" :aria-label="tr('list.copyOptions')"></th>
207
+ <template x-for="c in cols" :key="c">
208
+ <th x-text="head(c)" tabindex="0" :aria-sort="ariaSort(c)"
209
+ @click="sortBy(c)" @keydown.enter.prevent="sortBy(c)" @keydown.space.prevent="sortBy(c)"></th>
210
+ </template>
211
+ </tr></thead>
212
+ <tbody>
213
+ <template x-for="row in rows" :key="row._pk">
214
+ <tr class="row" tabindex="0" :aria-label="tr('a11y.row', { pk: pkKey(row._pk) })"
215
+ @click="openRow(row)" @keydown.enter="openRow(row)">
216
+ <template x-if="canWrite">
217
+ <td class="bulk-cell" @click.stop>
218
+ <input type="checkbox" :checked="!!selectedPks[pkKey(row._pk)]"
219
+ :aria-label="tr('a11y.selectRow', { pk: pkKey(row._pk) })"
220
+ @change="toggleSelect(row._pk)">
221
+ </td>
222
+ </template>
223
+ <td class="copy-cell" @click.stop>
224
+ <button type="button" class="copy-menu-btn" :aria-label="tr('list.copyOptionsFor', { pk: pkKey(row._pk) }) + ' ' + tr('list.copyAs')"
225
+ :aria-expanded="copyMenuPk === pkKey(row._pk) ? 'true' : 'false'"
226
+ @click="toggleCopyMenu(row._pk)">Copy as</button>
227
+ <div class="copy-menu" x-show="copyMenuPk === pkKey(row._pk)" @click.outside="closeCopyMenu"
228
+ role="menu" :aria-label="tr('list.copyRowAs', { pk: pkKey(row._pk) })">
229
+ <button type="button" role="menuitem" @click="copyRow('json', row)" x-text="tr('list.copyJson')">JSON</button>
230
+ <button type="button" role="menuitem" @click="copyRow('create', row)" x-text="tr('list.copyCreate')">create()</button>
231
+ <button type="button" role="menuitem" @click="copyRow('csv', row)" x-text="tr('list.copyCsv')">CSV line</button>
232
+ </div>
233
+ </td>
234
+ <template x-for="c in cols" :key="c">
235
+ <td @dblclick="beginInline(row, c, $event)"
236
+ :title="canWrite ? tr('list.doubleClick') : null">
237
+ <span x-text="cell(row, c)"></span>
238
+ </td>
239
+ </template>
240
+ </tr>
241
+ </template>
242
+ </tbody>
243
+ </table>
244
+ </div>
245
+ <div class="bar">
246
+ <button @click="prev" :disabled="atFirst" x-text="tr('list.prev')">Prev</button>
247
+ <span x-text="pageLabel"></span>
248
+ <button @click="next" :disabled="atLast" x-text="tr('list.next')">Next</button>
249
+ </div>
250
+ </section>
251
+
252
+ <section class="ai-panel" x-show="aiEnabled" aria-label="AI filter">
253
+ <div class="panel-header"><h3 data-i18n="ai.title">Describe a filter</h3></div>
254
+ <div class="bar">
255
+ <input type="text" x-model="aiText" :placeholder="tr('ai.prompt')"
256
+ :aria-label="tr('ai.field')" @keydown.enter="runAi">
257
+ <button type="button" @click="runAi" x-text="tr('ai.suggest')">Suggest filters</button>
258
+ </div>
259
+ <p class="mut" x-show="aiError" x-text="aiError" role="alert"></p>
260
+ <div class="ai-chips" x-show="aiFilters.length">
261
+ <template x-for="(f, i) in aiFilters" :key="i">
262
+ <span class="ai-chip">
263
+ <span x-text="aiChipLabel(f)"></span>
264
+ <button type="button" @click="removeAiChip(i)" :aria-label="tr('ai.removeChip')">×</button>
265
+ </span>
266
+ </template>
267
+ </div>
268
+ <div class="bar" x-show="aiFilters.length">
269
+ <button type="button" @click="applyAi" x-text="tr('ai.apply')">Apply selected filters</button>
270
+ </div>
271
+ </section>
272
+
273
+ <!-- v0.5.0 detail side drawer: list stays visible behind it -->
274
+ <div class="drawer-backdrop" x-show="isDetail" @click="closeDrawer" aria-hidden="true"></div>
275
+ <section x-show="isDetail" x-ref="drawer" class="detail-drawer"
276
+ role="dialog" aria-modal="true" :aria-label="tr('detail.label')"
277
+ @keydown="onDrawerKeydown($event)">
278
+ <nav class="breadcrumbs" :aria-label="tr('detail.breadcrumb')" x-show="breadcrumbs.length">
279
+ <template x-for="(b, i) in breadcrumbs" :key="i">
280
+ <span class="crumb"><button type="button" @click="goCrumb(i)" x-text="b.label"></button></span>
281
+ </template>
282
+ </nav>
283
+ <div class="bar">
284
+ <button type="button" @click="closeDrawer" :aria-label="tr('detail.close')" x-text="tr('common.close')">Close</button>
285
+ <button x-show="canWrite" @click="save" x-text="tr('detail.save')">Save</button>
286
+ <button x-show="canDelete" @click="remove" x-text="tr('detail.delete')">Delete</button>
287
+ <button x-show="canWrite" @click="stageSave" x-text="tr('detail.stage')">Stage change</button>
288
+ <button x-show="canDelete" @click="stageDelete" x-text="tr('detail.stageDelete')">Stage delete</button>
289
+ <button @click="toggleFormMode" x-text="formModeLabel"></button>
290
+ <button type="button" @click="toggleJsonTree"
291
+ :aria-pressed="jsonTreeOpen ? 'true' : 'false'" x-text="tr('detail.jsonTree')">JSON tree</button>
292
+ </div>
293
+ <section class="json-tree-panel" x-show="jsonTreeOpen" aria-label="JSON tree">
294
+ <div class="bar">
295
+ <button type="button" @click="applyJsonTree(json)" x-text="tr('detail.applyEdits')">Apply edits</button>
296
+ <span class="mut" data-i18n="detail.jsonHint">Edit the JSON text above, then Apply edits.</span>
297
+ </div>
298
+ <div x-ref="jsonTreeBody" class="json-tree-body"></div>
299
+ </section>
300
+ <p class="drawer-dirty" x-show="drawerDirty" role="status">
301
+ <span x-text="tr('detail.dirty')">Unsaved changes</span> <span x-text="'(' + drawerDiff.length + ')'"></span>
302
+ </p>
303
+ <template x-if="drawerDirty">
304
+ <ul class="drawer-diff" :aria-label="tr('detail.changes')">
305
+ <template x-for="d in drawerDiff" :key="d.field">
306
+ <li><code x-text="d.field"></code>
307
+ <span x-text="show(d.before)"></span>
308
+ <span aria-hidden="true">→</span>
309
+ <span x-text="show(d.after)"></span></li>
310
+ </template>
311
+ </ul>
312
+ </template>
313
+ <div x-show="showWidgets" x-ref="form" class="form"></div>
314
+ <textarea x-show="showJson" x-model="json" :readonly="readOnly"
315
+ :aria-label="tr('detail.rowJson')"></textarea>
316
+ <div class="bar">
317
+ <template x-for="r in relations" :key="r.name">
318
+ <button x-text="relLabel(r)" @click="showRel(r)"></button>
319
+ </template>
320
+ </div>
321
+ <div x-show="hasRel">
322
+ <table>
323
+ <template x-for="it in relRows" :key="it._pk">
324
+ <tr class="row" @click="openRelated(it)">
325
+ <template x-for="c in relCols" :key="c">
326
+ <td x-text="cell(it, c)"></td>
327
+ </template>
328
+ </tr>
329
+ </template>
330
+ </table>
331
+ <div class="bar" x-show="canM2m">
332
+ <button type="button" @click="openM2mPicker('add')" x-text="tr('detail.add')">+ Add</button>
333
+ <button type="button" @click="openM2mPicker('remove')" x-text="tr('detail.remove')">Remove</button>
334
+ <button type="button" @click="stageM2m('add', relRows.map(r => r._pk))" x-text="tr('detail.stageAdd')">Stage add</button>
335
+ <button type="button" @click="stageM2m('remove', relRows.map(r => r._pk))" x-text="tr('detail.stageRemove')">Stage remove</button>
336
+ </div>
337
+ </div>
338
+ </section>
339
+
340
+ <section x-show="isPlayground">
341
+ <div class="panel-header">
342
+ <h3 data-i18n="playground.title">Query Playground</h3>
343
+ <p class="mut" data-i18n="playground.hint">Preview the Python call and generated SQL for a filter/sort combination.</p>
344
+ </div>
345
+ <div class="playground-form">
346
+ <label>
347
+ <span x-text="tr('playground.model')">Model</span>
348
+ <select x-model="playgroundModel">
349
+ <template x-for="m in models" :key="m.key">
350
+ <option :value="m.key" x-text="m.key"></option>
351
+ </template>
352
+ </select>
353
+ </label>
354
+ <label class="full">
355
+ <span x-text="tr('playground.filters')">Filters (JSON)</span>
356
+ <textarea x-model="playgroundFilters" rows="3" placeholder='[{"field":"age","op":"gte","value":18}]'></textarea>
357
+ </label>
358
+ <label><span x-text="tr('playground.search')">Search</span><input x-model="playgroundSearch" placeholder="(optional)"></label>
359
+ <label><span x-text="tr('playground.sort')">Sort</span><input x-model="playgroundSort" placeholder="-created_at,name"></label>
360
+ <label><span x-text="tr('playground.limit')">Limit</span><input type="number" x-model="playgroundLimit" min="1" max="200"></label>
361
+ <div class="full">
362
+ <button type="button" @click="runPlayground" x-text="tr('playground.run')">Run Preview</button>
363
+ <button type="button" @click="toggleQueryHistory"
364
+ :aria-expanded="queryHistoryOpen ? 'true' : 'false'" x-text="tr('playground.history')">History</button>
365
+ <button type="button" @click="openInList" x-text="tr('playground.openInList')">Open in list view</button>
366
+ <span class="mut" :aria-label="tr('playground.lastQuery')" x-text="playgroundLabel"></span>
367
+ <span class="widget-error" x-text="playgroundError"></span>
368
+ </div>
369
+ </div>
370
+ <section class="pg-history" x-show="queryHistoryOpen" aria-label="Query history">
371
+ <div class="bar">
372
+ <strong x-text="tr('playground.recent')">Recent queries</strong>
373
+ <button type="button" @click="clearQueryHistory" x-text="tr('playground.clear')">Clear</button>
374
+ </div>
375
+ <template x-if="!playgroundHistory.length">
376
+ <p class="mut" data-i18n="playground.none">No queries yet.</p>
377
+ </template>
378
+ <template x-for="(h, i) in playgroundHistory" :key="h.at + '-' + i">
379
+ <button type="button" class="pg-history-item" @click="loadHistoryQuery(i)">
380
+ <span x-text="h.model"></span>
381
+ <span class="mut" x-text="(h.search ? 'search: ' + h.search + ' · ' : '') + 'limit ' + h.limit"></span>
382
+ </button>
383
+ </template>
384
+ </section>
385
+ <div x-ref="playgroundBody" class="playground-body"></div>
386
+ </section>
387
+
388
+ <section x-show="isEr">
389
+ <div class="panel-header">
390
+ <h3 data-i18n="er.title">ER Diagram</h3>
391
+ <p class="mut"><span data-i18n="er.hint">Mermaid erDiagram text for all registered models.</span></p>
392
+ </div>
393
+ <div x-ref="erBody" class="er-body"></div>
394
+ </section>
395
+
396
+ <section x-show="isMigrations">
397
+ <div class="panel-header">
398
+ <h3 data-i18n="migrations.title">Migrations</h3>
399
+ <p class="mut" data-i18n="migrations.hint">Applied and pending Aerich migrations for the current connection.</p>
400
+ </div>
401
+ <div x-ref="migrationsBody" class="migrations-body"></div>
402
+ </section>
403
+
404
+ <section x-show="isAudit">
405
+ <div class="panel-header">
406
+ <h3 data-i18n="audit.title">Audit Log</h3>
407
+ <p class="mut" data-i18n="audit.hint">Every create / update / delete recorded by the audit hook.</p>
408
+ </div>
409
+ <div class="audit-filters">
410
+ <label><span x-text="tr('audit.action')">Action</span>
411
+ <select x-model="auditFilters.action">
412
+ <option value="" x-text="tr('audit.any')">(any)</option>
413
+ <option value="create">create</option>
414
+ <option value="update">update</option>
415
+ <option value="delete">delete</option>
416
+ <option value="m2m_add">m2m_add</option>
417
+ <option value="m2m_remove">m2m_remove</option>
418
+ </select>
419
+ </label>
420
+ <label><span x-text="tr('audit.model')">Model</span><input x-model="auditFilters.model" placeholder="models.Author"></label>
421
+ <label><span x-text="tr('audit.actor')">Actor</span><input x-model="auditFilters.actor" placeholder="alice"></label>
422
+ <button type="button" @click="applyAuditFilters" x-text="tr('audit.apply')">Apply</button>
423
+ <button type="button" @click="clearAuditFilters" x-text="tr('audit.clear')">Clear</button>
424
+ </div>
425
+ <div x-ref="auditBody" class="audit-body"></div>
426
+ </section>
427
+
428
+ <!-- v0.9.0 plugin panel: actions are declarative, output is text-only. -->
429
+ <section class="plugin-panel" x-show="isPlugin" aria-label="Plugin panel">
430
+ <div class="panel-header">
431
+ <h3 x-text="pluginTitle"></h3>
432
+ <p class="mut" data-i18n="plugin.hint">Actions contributed by installed plugins. Output is read-only.</p>
433
+ </div>
434
+ <div class="bar">
435
+ <template x-for="a in pluginActions" :key="a.key">
436
+ <button type="button" @click="runPluginAction(a)" x-text="a.label"></button>
437
+ </template>
438
+ </div>
439
+ <p class="widget-error" x-show="pluginError" x-text="pluginError" role="alert"></p>
440
+ <pre class="plugin-result" x-show="pluginText" x-text="pluginText"></pre>
441
+ </section>
442
+
443
+ <section class="pending-panel" x-show="pendingOpen || pendingDirty" aria-label="Pending changes">
444
+ <div class="panel-header">
445
+ <h3 x-text="tr('pending.title', { count: pendingCount })">Pending changes</h3>
446
+ <button type="button" @click="togglePending" x-text="pendingOpen ? tr('pending.hide') : tr('pending.show')"></button>
447
+ </div>
448
+ <div x-show="pendingOpen">
449
+ <template x-if="!pendingDirty">
450
+ <p class="mut" data-i18n="pending.empty">No staged changes.</p>
451
+ </template>
452
+ <template x-for="c in pendingStore.changes" :key="c.id">
453
+ <div class="pending-row">
454
+ <div class="pending-meta">
455
+ <span class="pending-op" x-text="c.op"></span>
456
+ <span x-text="c.model"></span>
457
+ <template x-if="c.pk !== undefined"><span x-text="'#' + c.pk"></span></template>
458
+ </div>
459
+ <div class="pending-diff">
460
+ <template x-for="d in pendingDiff(c)" :key="d.field">
461
+ <div class="pending-field">
462
+ <code x-text="d.field"></code>
463
+ <span x-text="show(d.before)"></span>
464
+ <span aria-hidden="true">→</span>
465
+ <span x-text="show(d.after)"></span>
466
+ </div>
467
+ </template>
468
+ <template x-if="c.op === 'delete'"><span class="mut" data-i18n="pending.deleteRow">delete row</span></template>
469
+ <template x-if="c.rel"><span x-text="c.rel + ': ' + c.ids.join(', ')"></span></template>
470
+ </div>
471
+ <button type="button" @click="removePending(c.id)" :aria-label="tr('pending.remove')">×</button>
472
+ </div>
473
+ </template>
474
+ <div class="bar">
475
+ <button type="button" x-show="canWrite" @click="saveAll" :disabled="!pendingDirty" x-text="tr('pending.saveAll')">Save all</button>
476
+ <button type="button" @click="undoPending" :disabled="!pendingDirty" x-text="tr('pending.undo')">Undo last</button>
477
+ <button type="button" @click="discardAllPending" :disabled="!pendingDirty" x-text="tr('pending.discard')">Discard all</button>
478
+ </div>
479
+ </div>
480
+ </section>
481
+
482
+ <footer class="statusbar" role="status" aria-live="polite">
483
+ <span class="status-conn" x-text="tr('status.db', { conn: connection || 'default' })"></span>
484
+ <span class="status-mode" :class="{ writable: canWrite }" x-text="readOnly ? tr('status.readOnly') : tr('status.writeEnabled')"></span>
485
+ <span class="status-filter" x-text="filterSummary"></span>
486
+ <span class="status-time" x-text="lastRequestLabel"></span>
487
+ <button type="button" class="status-help" @click="toggleHelp" :aria-label="tr('status.help')">?</button>
488
+ </footer>
489
+ </main>
490
+
491
+ <!-- Palette overlay. Rendered only when open; no x-html, no inline styles. -->
492
+ <div class="palette-overlay" x-show="paletteOpen" @click.self="closePalette"
493
+ @keydown.escape.window="closePalette" @keydown.tab="onPaletteKeydown($event)">
494
+ <div x-ref="paletteBody"></div>
495
+ </div>
496
+
497
+ <!-- Shortcut cheat sheet. -->
498
+ <div class="help-overlay" x-show="helpOpen" @click.self="toggleHelp"
499
+ @keydown.escape.window="helpOpen = false">
500
+ <div class="help-card" role="dialog" aria-modal="true" aria-label="Keyboard shortcuts">
501
+ <h2 data-i18n="help.title">Keyboard shortcuts</h2>
502
+ <dl>
503
+ <dt>Ctrl/Cmd + K</dt><dd data-i18n="help.palette">Command palette</dd>
504
+ <dt>/</dt><dd data-i18n="help.focusSearch">Focus search</dd>
505
+ <dt>j / k</dt><dd data-i18n="help.move">Move selection down / up</dd>
506
+ <dt>Enter</dt><dd data-i18n="help.open">Open selected row</dd>
507
+ <dt>Esc</dt><dd data-i18n="help.back">Back / close</dd>
508
+ <dt>g then m</dt><dd data-i18n="help.models">Go to models</dd>
509
+ <dt>?</dt><dd data-i18n="help.this">This help</dd>
510
+ </dl>
511
+ <button type="button" @click="toggleHelp" x-text="tr('common.close')">Close</button>
512
+ </div>
513
+ </div>
514
+ </body>
515
+ </html>
@@ -0,0 +1,107 @@
1
+ // @ts-check
2
+ /**
3
+ * Pure inline cell-edit state machine for v0.5.0 (UI program D).
4
+ *
5
+ * No DOM, no network: a double-clicked cell opens an edit session reusing the
6
+ * typed widgets; committing produces a pending-store `update` spec (so inline
7
+ * edits flow through the same staged-saves / batch path) or a revert spec on
8
+ * undo. Everything here is a plain function over a plain object, testable with
9
+ * `node --test`. Toast feedback and DOM rendering stay in app.js.
10
+ *
11
+ * Types: InlineEditState, InlineEditAPI in _types.d.ts.
12
+ */
13
+ (function (/** @type {any} */ global) {
14
+ "use strict";
15
+
16
+ /** @returns {{ active: any, last: any }} */
17
+ function create() {
18
+ return { active: null, last: null };
19
+ }
20
+
21
+ /** @param {{ active: any, last: any }} state */
22
+ function isEditing(state) {
23
+ return !!state.active;
24
+ }
25
+
26
+ /**
27
+ * Open an edit session for one cell.
28
+ * @param {{ active: any, last: any }} state
29
+ * @param {{ model: string, pk: any, col: string, value: any }} spec
30
+ * @returns {{ active: any, last: any }}
31
+ */
32
+ function begin(state, spec) {
33
+ if (!spec || !spec.model || spec.pk === null || spec.pk === undefined || !spec.col) {
34
+ throw new Error("model, pk and col are required to begin an inline edit");
35
+ }
36
+ return {
37
+ active: { model: spec.model, pk: spec.pk, col: spec.col, value: spec.value, before: spec.value },
38
+ last: state.last,
39
+ };
40
+ }
41
+
42
+ /**
43
+ * Update the in-progress value (fired by the typed widget's onChange).
44
+ * @param {{ active: any, last: any }} state
45
+ * @param {any} value
46
+ * @returns {{ active: any, last: any }}
47
+ */
48
+ function change(state, value) {
49
+ if (!state.active) return state;
50
+ return { active: Object.assign({}, state.active, { value: value }), last: state.last };
51
+ }
52
+
53
+ /**
54
+ * Close the current session without committing.
55
+ * @param {{ active: any, last: any }} state
56
+ * @returns {{ active: any, last: any }}
57
+ */
58
+ function cancel(state) {
59
+ return { active: null, last: state.last };
60
+ }
61
+
62
+ /**
63
+ * Commit the active cell. Returns a pending-store update spec, or null when
64
+ * the value is unchanged (no write needed).
65
+ * @param {{ active: any, last: any }} state
66
+ * @returns {{ state: { active: any, last: any }, spec: any, changed: boolean }}
67
+ */
68
+ function commit(state) {
69
+ var a = state.active;
70
+ if (!a) return { state: state, spec: null, changed: false };
71
+ /** @type {{ active: any, last: any }} */
72
+ var nextState = { active: null, last: Object.assign({}, a) };
73
+ if (JSON.stringify(a.value) === JSON.stringify(a.before)) {
74
+ return { state: nextState, spec: null, changed: false };
75
+ }
76
+ /** @type {any} */
77
+ var spec = {
78
+ op: "update", model: a.model, pk: a.pk,
79
+ data: {}, before: {},
80
+ };
81
+ spec.data[a.col] = a.value;
82
+ spec.before[a.col] = a.before;
83
+ return { state: nextState, spec: spec, changed: true };
84
+ }
85
+
86
+ /**
87
+ * Undo the last committed inline edit. Returns a pending-store update spec
88
+ * that restores the original value, or null when there is nothing to undo.
89
+ * Undo is single-level: the last commit is cleared after it is returned.
90
+ * @param {{ active: any, last: any }} state
91
+ * @returns {{ state: { active: any, last: any }, spec: any }}
92
+ */
93
+ function undo(state) {
94
+ var last = state.last;
95
+ if (!last) return { state: state, spec: null };
96
+ /** @type {any} */
97
+ var spec = { op: "update", model: last.model, pk: last.pk, data: {}, before: {} };
98
+ spec.data[last.col] = last.before;
99
+ spec.before[last.col] = last.value;
100
+ return { state: { active: null, last: null }, spec: spec };
101
+ }
102
+
103
+ global.StudioInlineEdit = {
104
+ create: create, isEditing: isEditing, begin: begin, change: change,
105
+ cancel: cancel, commit: commit, undo: undo,
106
+ };
107
+ })(typeof window !== "undefined" ? window : globalThis);