@pseudolux-ui/media-library 0.0.0-stage → 0.1.0
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/LICENSE +21 -0
- package/package.json +22 -4
- package/src/components/AssetGrid.lsp +1777 -0
- package/src/components/AssetInspector.lsp +1622 -0
- package/src/components/BinDialog.lsp +208 -0
- package/src/components/CropEditor.lsp +616 -0
- package/src/components/ResponsiveImage.lsp +297 -0
- package/src/config.ts +137 -0
- package/src/index.ts +33 -0
- package/src/ladder.ts +82 -0
- package/src/port.ts +217 -0
- package/src/styles/px.css +177 -0
- package/README.md +0 -3
|
@@ -0,0 +1,208 @@
|
|
|
1
|
+
<view>
|
|
2
|
+
<dialog
|
|
3
|
+
class="px-dialog bin-dialog"
|
|
4
|
+
role="alertdialog"
|
|
5
|
+
aria-labelledby="px-bin-title"
|
|
6
|
+
aria-describedby="px-bin-warning"
|
|
7
|
+
$ref="dialog"
|
|
8
|
+
@close="closed"
|
|
9
|
+
>
|
|
10
|
+
<div class="px-dialog-head">
|
|
11
|
+
<h3 id="px-bin-title" class="title">Move “{{ state.label }}” to the bin?</h3>
|
|
12
|
+
</div>
|
|
13
|
+
|
|
14
|
+
<div class="body">
|
|
15
|
+
<div id="px-bin-warning">
|
|
16
|
+
<div class="px-callout px-callout-warn" $show="state.warnTitle">
|
|
17
|
+
<span><b>{{ state.warnTitle }}</b> {{ state.warnText }}</span>
|
|
18
|
+
</div>
|
|
19
|
+
<p class="px-subtle" $show="!state.warnTitle">{{ state.quietNote }}</p>
|
|
20
|
+
</div>
|
|
21
|
+
|
|
22
|
+
<label class="px-field">
|
|
23
|
+
<span class="px-label">Why? <span class="px-subtle quiet">Shown to anyone who finds it in the bin</span></span>
|
|
24
|
+
<select class="px-select" $model="state.reason">
|
|
25
|
+
<option $for="one in state.reasons" $key="one" $value="one" $text="one"></option>
|
|
26
|
+
</select>
|
|
27
|
+
</label>
|
|
28
|
+
|
|
29
|
+
<label class="px-field">
|
|
30
|
+
<span class="px-label">Note <span class="px-subtle quiet">Optional</span></span>
|
|
31
|
+
<input class="px-input" type="text" maxlength="400" $model="state.note" />
|
|
32
|
+
</label>
|
|
33
|
+
|
|
34
|
+
<div class="px-callout px-callout-danger" role="alert" $show="state.error"><span>{{ state.error }}</span></div>
|
|
35
|
+
</div>
|
|
36
|
+
|
|
37
|
+
<div class="px-dialog-foot foot">
|
|
38
|
+
<button class="px-btn px-btn-secondary" type="button" autofocus $disabled="state.busy" @click="keep">Keep it</button>
|
|
39
|
+
<button class="px-btn px-btn-danger" type="button" $disabled="state.busy" @click="confirm">{{ state.confirmLabel }}</button>
|
|
40
|
+
</div>
|
|
41
|
+
</dialog>
|
|
42
|
+
</view>
|
|
43
|
+
|
|
44
|
+
<logic lang="ts">
|
|
45
|
+
import { reactive, shared, defineRefs, onMounted } from '@lightspeed-js/core'
|
|
46
|
+
import { getLibrary, BIN_DIALOG, SELECTED, CHANGED } from '../config.ts'
|
|
47
|
+
|
|
48
|
+
const REASONS = ['Duplicate', 'Poor quality', 'Rights have ended', 'Other…']
|
|
49
|
+
|
|
50
|
+
const state = reactive({
|
|
51
|
+
label: '',
|
|
52
|
+
reasons: REASONS,
|
|
53
|
+
reason: REASONS[0],
|
|
54
|
+
note: '',
|
|
55
|
+
warnTitle: '',
|
|
56
|
+
warnText: '',
|
|
57
|
+
quietNote: '',
|
|
58
|
+
confirmLabel: 'Move to bin',
|
|
59
|
+
busy: false,
|
|
60
|
+
error: '',
|
|
61
|
+
})
|
|
62
|
+
|
|
63
|
+
const request = shared(BIN_DIALOG)
|
|
64
|
+
const selected = shared(SELECTED)
|
|
65
|
+
const changed = shared(CHANGED)
|
|
66
|
+
const refs = defineRefs()
|
|
67
|
+
|
|
68
|
+
let asked = null
|
|
69
|
+
let opener = null
|
|
70
|
+
|
|
71
|
+
function plural(n, one, many) {
|
|
72
|
+
return n + ' ' + (n === 1 ? one : many)
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
function moveLabel() {
|
|
76
|
+
const pages = (asked && asked.pages && asked.pages.length) || 0
|
|
77
|
+
return pages ? 'Move to bin and remove from ' + plural(pages, 'page', 'pages') : 'Move to bin'
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
function describeUse(next) {
|
|
81
|
+
const pages = next.pages || []
|
|
82
|
+
const seen = next.seen || 0
|
|
83
|
+
state.warnTitle = ''
|
|
84
|
+
state.warnText = ''
|
|
85
|
+
if (pages.length) {
|
|
86
|
+
state.warnTitle = plural(pages.length, 'page', 'pages') + ' will show a gap:'
|
|
87
|
+
state.warnText =
|
|
88
|
+
pages.map((one) => (one.site ? one.site + ' · ' : '') + one.title).join('; ') +
|
|
89
|
+
'. Pictures in the bin are no longer served, so those pages lose it until it is restored or their editors choose another.'
|
|
90
|
+
} else if (seen) {
|
|
91
|
+
state.warnTitle = 'Still being requested.'
|
|
92
|
+
state.warnText =
|
|
93
|
+
'No page has reported using it, but ' + plural(seen, 'site has', 'sites have') +
|
|
94
|
+
' asked for it in the last 30 days. Pictures in the bin are no longer served.'
|
|
95
|
+
}
|
|
96
|
+
state.quietNote = next.usageKnown
|
|
97
|
+
? 'No page has reported using it. Restore puts it back as it was.'
|
|
98
|
+
: 'Restore puts it back as it was.'
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
function reasonText() {
|
|
102
|
+
const reason = state.reason.replace(/…$/, '')
|
|
103
|
+
const note = state.note.trim()
|
|
104
|
+
return note ? reason + ': ' + note : reason
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
async function confirm() {
|
|
108
|
+
if (!asked || state.busy) return
|
|
109
|
+
const id = asked.id
|
|
110
|
+
const reason = reasonText()
|
|
111
|
+
state.busy = true
|
|
112
|
+
state.confirmLabel = 'Moving…'
|
|
113
|
+
state.error = ''
|
|
114
|
+
try {
|
|
115
|
+
const result = await getLibrary().remove(id, reason)
|
|
116
|
+
const deletedAt = (result && result.deletedAt) || new Date().toISOString()
|
|
117
|
+
const row = selected.value
|
|
118
|
+
if (row && row.id === id) selected.value = { ...row, deletedAt, deletedReason: reason }
|
|
119
|
+
changed.value = (changed.value || 0) + 1
|
|
120
|
+
close()
|
|
121
|
+
} catch (err) {
|
|
122
|
+
state.error = err && err.message ? err.message : 'Could not move it to the bin.'
|
|
123
|
+
} finally {
|
|
124
|
+
state.busy = false
|
|
125
|
+
state.confirmLabel = moveLabel()
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
function keep() {
|
|
130
|
+
close()
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
function close() {
|
|
134
|
+
const dialog = refs.dialog
|
|
135
|
+
if (dialog && dialog.open) dialog.close()
|
|
136
|
+
else closed()
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
function closed() {
|
|
140
|
+
if (opener && opener.isConnected && opener.focus) opener.focus()
|
|
141
|
+
opener = null
|
|
142
|
+
asked = null
|
|
143
|
+
if (request.value) request.value = null
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
function open(next) {
|
|
147
|
+
if (!next) {
|
|
148
|
+
const dialog = refs.dialog
|
|
149
|
+
if (dialog && dialog.open) dialog.close()
|
|
150
|
+
return
|
|
151
|
+
}
|
|
152
|
+
asked = next
|
|
153
|
+
state.label = next.label || next.id
|
|
154
|
+
state.reason = REASONS[0]
|
|
155
|
+
state.note = ''
|
|
156
|
+
state.error = ''
|
|
157
|
+
state.busy = false
|
|
158
|
+
describeUse(next)
|
|
159
|
+
state.confirmLabel = moveLabel()
|
|
160
|
+
const dialog = refs.dialog
|
|
161
|
+
if (dialog && !dialog.open && dialog.showModal) {
|
|
162
|
+
opener = document.activeElement
|
|
163
|
+
dialog.showModal()
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
request.subscribe(open)
|
|
168
|
+
|
|
169
|
+
onMounted(() => {
|
|
170
|
+
if (request.value) open(request.value)
|
|
171
|
+
})
|
|
172
|
+
</logic>
|
|
173
|
+
|
|
174
|
+
<style>
|
|
175
|
+
.bin-dialog {
|
|
176
|
+
width: min(520px, calc(100vw - 32px));
|
|
177
|
+
max-width: none;
|
|
178
|
+
padding: 0;
|
|
179
|
+
color: var(--px-text);
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
.bin-dialog:not([open]) {
|
|
183
|
+
display: none;
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
.bin-dialog::backdrop {
|
|
187
|
+
background: var(--px-scrim);
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
.title {
|
|
191
|
+
overflow-wrap: anywhere;
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
.body {
|
|
195
|
+
display: flex;
|
|
196
|
+
flex-direction: column;
|
|
197
|
+
gap: 14px;
|
|
198
|
+
padding: 16px;
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
.quiet {
|
|
202
|
+
font-weight: 400;
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
.foot {
|
|
206
|
+
justify-content: flex-end;
|
|
207
|
+
}
|
|
208
|
+
</style>
|