@nickpaustian/tela 0.1.2 → 0.2.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/CHANGELOG.md +34 -0
- package/README.md +1 -1
- package/bin/tela.ts +18 -2
- package/lib/index.js +172 -7
- package/package.json +5 -2
- package/scripts/check-components.ts +20 -0
- package/scripts/media-sync.ts +41 -0
- package/scripts/republish.ts +24 -0
- package/src/api.ts +3 -3
- package/src/components/EntryEditor.lsp +174 -11
- package/src/components/EntryList.lsp +8 -0
- package/src/components/Field.lsp +92 -2
- package/src/components/LinkField.lsp +477 -0
- package/src/components/MarkdownField.lsp +19 -24
- package/src/components/PersonField.lsp +255 -0
- package/src/components/ReferenceField.lsp +22 -1
- package/src/components/RepeaterField.lsp +141 -13
- package/src/components/ToggleField.lsp +63 -0
- package/src/config/fields.ts +134 -1
- package/src/config/seo.ts +4 -2
- package/src/config/types.ts +158 -7
- package/src/content/derive-values.ts +14 -3
- package/src/content/entries.ts +1 -1
- package/src/content/entry.ts +15 -1
- package/src/content/export.ts +173 -14
- package/src/content/git.ts +1 -1
- package/src/content/hooks.ts +75 -0
- package/src/content/link-address.ts +168 -0
- package/src/content/links.ts +13 -0
- package/src/content/person.ts +11 -0
- package/src/content/placement.ts +48 -0
- package/src/content/references.ts +48 -4
- package/src/content/rules.ts +24 -4
- package/src/content/shape.ts +192 -0
- package/src/content/store.ts +17 -0
- package/src/content/url.ts +15 -1
- package/src/content/users.ts +32 -0
- package/src/content/validate.ts +12 -2
- package/src/index.ts +4 -1
- package/src/keys.ts +47 -0
- package/src/media/index.ts +5 -0
- package/src/server/index.ts +168 -34
- package/src/server/library-routes.ts +11 -3
|
@@ -0,0 +1,477 @@
|
|
|
1
|
+
<view>
|
|
2
|
+
<Field $field="props.field" $path="props.path" $controlId="'f-' + props.path">
|
|
3
|
+
<div class="link-field">
|
|
4
|
+
<div class="link-chosen" $show="state.chosen">
|
|
5
|
+
<span class="icon icon-m" $class="'icon-' + state.chosenIcon" aria-hidden="true"></span>
|
|
6
|
+
<span class="link-chosen-words">
|
|
7
|
+
<span class="link-chosen-title">{{ state.chosenTitle }}</span>
|
|
8
|
+
<span class="link-chosen-meta">
|
|
9
|
+
<span $show="state.chosenWhere" class="badge badge-neutral">{{ state.chosenWhere }}</span>
|
|
10
|
+
<span $show="state.chosenHref" class="subtle">{{ state.chosenHref }}</span>
|
|
11
|
+
<span $show="state.chosenDraft" class="badge badge-warn">Not published</span>
|
|
12
|
+
</span>
|
|
13
|
+
<span $show="state.chosenGone" class="link-gone">No longer on the site. Choose again.</span>
|
|
14
|
+
</span>
|
|
15
|
+
<button
|
|
16
|
+
type="button"
|
|
17
|
+
class="btn btn-ghost btn-sm btn-icon"
|
|
18
|
+
$show="!state.readonly"
|
|
19
|
+
$aria-label="'Remove the link to ' + state.chosenTitle"
|
|
20
|
+
@click="unchoose"
|
|
21
|
+
>
|
|
22
|
+
<span class="icon icon-s icon-x" aria-hidden="true"></span>
|
|
23
|
+
</button>
|
|
24
|
+
</div>
|
|
25
|
+
|
|
26
|
+
<div class="link-entry" $show="!state.chosen">
|
|
27
|
+
<input
|
|
28
|
+
class="input"
|
|
29
|
+
type="text"
|
|
30
|
+
role="combobox"
|
|
31
|
+
autocomplete="off"
|
|
32
|
+
spellcheck="false"
|
|
33
|
+
aria-autocomplete="list"
|
|
34
|
+
$id="'f-' + props.path"
|
|
35
|
+
$aria-expanded="state.open ? 'true' : 'false'"
|
|
36
|
+
$aria-controls="'f-' + props.path + '-links'"
|
|
37
|
+
$aria-activedescendant="state.active >= 0 ? 'f-' + props.path + '-link-' + state.active : null"
|
|
38
|
+
$placeholder="state.placeholder"
|
|
39
|
+
$readonly="state.readonly"
|
|
40
|
+
$model="state.typed"
|
|
41
|
+
@input="typed"
|
|
42
|
+
@keydown="key"
|
|
43
|
+
@blur="blurred"
|
|
44
|
+
/>
|
|
45
|
+
<ul
|
|
46
|
+
class="menu link-options"
|
|
47
|
+
role="listbox"
|
|
48
|
+
$id="'f-' + props.path + '-links'"
|
|
49
|
+
$show="state.open"
|
|
50
|
+
>
|
|
51
|
+
<li
|
|
52
|
+
$for="one in state.results"
|
|
53
|
+
$key="one.key"
|
|
54
|
+
role="option"
|
|
55
|
+
class="menu-item link-option"
|
|
56
|
+
$class="{ active: one.index === state.active }"
|
|
57
|
+
$id="'f-' + props.path + '-link-' + one.index"
|
|
58
|
+
$aria-selected="one.index === state.active ? 'true' : 'false'"
|
|
59
|
+
@pointerdown="pick($event, one)"
|
|
60
|
+
>
|
|
61
|
+
<span class="icon icon-m" $class="'icon-' + one.icon" aria-hidden="true"></span>
|
|
62
|
+
<span class="link-option-words">
|
|
63
|
+
<span class="link-option-title">{{ one.title }}</span>
|
|
64
|
+
<span class="link-option-meta">
|
|
65
|
+
<span class="badge badge-neutral">{{ one.where }}</span>
|
|
66
|
+
<span $show="one.href" class="subtle">{{ one.href }}</span>
|
|
67
|
+
<span $show="one.draft" class="badge badge-warn">Not published</span>
|
|
68
|
+
</span>
|
|
69
|
+
</span>
|
|
70
|
+
</li>
|
|
71
|
+
<li class="link-none" $show="state.results.length === 0">{{ state.none }}</li>
|
|
72
|
+
</ul>
|
|
73
|
+
<p class="link-note" $show="state.note">
|
|
74
|
+
<span class="icon icon-s" $class="'icon-' + state.noteIcon" aria-hidden="true"></span>
|
|
75
|
+
<span>{{ state.note }}</span>
|
|
76
|
+
</p>
|
|
77
|
+
<p class="link-problem" $show="state.problem">
|
|
78
|
+
<span class="icon icon-s icon-alert" aria-hidden="true"></span>
|
|
79
|
+
<span>{{ state.problem }}</span>
|
|
80
|
+
</p>
|
|
81
|
+
</div>
|
|
82
|
+
</div>
|
|
83
|
+
</Field>
|
|
84
|
+
</view>
|
|
85
|
+
|
|
86
|
+
<logic lang="ts">
|
|
87
|
+
import { defineProps, onMounted, reactive, shared } from '@lightspeed-js/core'
|
|
88
|
+
import {
|
|
89
|
+
acceptedKinds,
|
|
90
|
+
comparablePath,
|
|
91
|
+
fragmentOf,
|
|
92
|
+
kindOfHref,
|
|
93
|
+
linkMessage,
|
|
94
|
+
linkPlaceholder,
|
|
95
|
+
readTypedLink,
|
|
96
|
+
refusedKind,
|
|
97
|
+
} from '../content/link-address.ts'
|
|
98
|
+
import { linkTo, parseLink } from '../content/links.ts'
|
|
99
|
+
|
|
100
|
+
/**
|
|
101
|
+
* Somewhere to go, the way an editor thinks of it: start typing a page's name
|
|
102
|
+
* and pick it, or paste an address. A page is held by id, so the link follows
|
|
103
|
+
* it; an address on this site is swapped for the page it names; anything else
|
|
104
|
+
* is tidied and kept. See `link()` in `config/fields.ts`.
|
|
105
|
+
*/
|
|
106
|
+
const props = defineProps({
|
|
107
|
+
field: { default: {} },
|
|
108
|
+
path: { default: '' },
|
|
109
|
+
})
|
|
110
|
+
|
|
111
|
+
const value = shared('entry:value:' + props.path)
|
|
112
|
+
const readonly = shared('entry:readonly')
|
|
113
|
+
const route = shared('route').value?.params ?? {}
|
|
114
|
+
const options = props.field.options || {}
|
|
115
|
+
const kinds = acceptedKinds(options.accepts)
|
|
116
|
+
const pages = kinds.includes('pages')
|
|
117
|
+
const files = kinds.includes('files')
|
|
118
|
+
const only = Array.isArray(options.collections) && options.collections.length ? '&in=' + options.collections.join(',') : ''
|
|
119
|
+
|
|
120
|
+
type Found = {
|
|
121
|
+
key: string
|
|
122
|
+
index: number
|
|
123
|
+
title: string
|
|
124
|
+
where: string
|
|
125
|
+
href: string
|
|
126
|
+
ref: string
|
|
127
|
+
draft: boolean
|
|
128
|
+
icon: string
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
const state = reactive({
|
|
132
|
+
typed: '',
|
|
133
|
+
chosen: false,
|
|
134
|
+
chosenTitle: '',
|
|
135
|
+
chosenWhere: '',
|
|
136
|
+
chosenHref: '',
|
|
137
|
+
chosenDraft: false,
|
|
138
|
+
chosenGone: false,
|
|
139
|
+
chosenIcon: 'page',
|
|
140
|
+
results: [] as Found[],
|
|
141
|
+
open: false,
|
|
142
|
+
active: -1,
|
|
143
|
+
none: '',
|
|
144
|
+
note: '',
|
|
145
|
+
noteIcon: 'link',
|
|
146
|
+
problem: '',
|
|
147
|
+
readonly: false,
|
|
148
|
+
placeholder: options.placeholder || linkPlaceholder(kinds),
|
|
149
|
+
})
|
|
150
|
+
|
|
151
|
+
let hosts: string[] = []
|
|
152
|
+
let asked = 0
|
|
153
|
+
let timer: ReturnType<typeof setTimeout> | undefined
|
|
154
|
+
let shown = ''
|
|
155
|
+
|
|
156
|
+
const api = () => (window as any).telaApi
|
|
157
|
+
|
|
158
|
+
async function learnHosts() {
|
|
159
|
+
const result = await api().get('/api/links?hosts=1')
|
|
160
|
+
if (result.ok && Array.isArray(result.data.hosts)) hosts = result.data.hosts
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
function choose(found: { title: string; where: string; href: string; ref: string; draft: boolean; icon: string }) {
|
|
164
|
+
shown = found.ref
|
|
165
|
+
value.value = found.ref
|
|
166
|
+
state.chosen = true
|
|
167
|
+
state.chosenTitle = found.title
|
|
168
|
+
state.chosenWhere = found.where
|
|
169
|
+
state.chosenHref = found.href
|
|
170
|
+
state.chosenDraft = found.draft
|
|
171
|
+
state.chosenGone = false
|
|
172
|
+
state.chosenIcon = found.icon
|
|
173
|
+
state.typed = ''
|
|
174
|
+
state.note = ''
|
|
175
|
+
state.problem = ''
|
|
176
|
+
close()
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
function unchoose() {
|
|
180
|
+
shown = ''
|
|
181
|
+
value.value = undefined
|
|
182
|
+
state.chosen = false
|
|
183
|
+
state.typed = ''
|
|
184
|
+
state.note = ''
|
|
185
|
+
requestAnimationFrame(() => document.getElementById('f-' + props.path)?.focus())
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
const isImage = (type: unknown) => typeof type === 'string' && type.startsWith('image/')
|
|
189
|
+
|
|
190
|
+
/** A stored link, shown as what it is: the page or file by name, or the address. */
|
|
191
|
+
async function show() {
|
|
192
|
+
state.readonly = Boolean(props.field.readOnly || readonly.value)
|
|
193
|
+
const stored = typeof value.value === 'string' ? value.value : ''
|
|
194
|
+
if (stored === shown) return
|
|
195
|
+
shown = stored
|
|
196
|
+
state.problem = ''
|
|
197
|
+
|
|
198
|
+
const target = parseLink(stored)
|
|
199
|
+
if (!target) {
|
|
200
|
+
state.chosen = false
|
|
201
|
+
state.typed = stored
|
|
202
|
+
describe(stored)
|
|
203
|
+
return
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
state.chosen = true
|
|
207
|
+
state.chosenGone = false
|
|
208
|
+
if (target.collection === 'media') {
|
|
209
|
+
const result = await api().get('/api/entries/media/' + encodeURIComponent(target.id))
|
|
210
|
+
if (shown !== stored) return
|
|
211
|
+
const data = result.ok ? result.data.entry?.data : null
|
|
212
|
+
state.chosenTitle = data?.title ?? 'A file'
|
|
213
|
+
state.chosenWhere = 'File'
|
|
214
|
+
state.chosenHref = ''
|
|
215
|
+
state.chosenDraft = false
|
|
216
|
+
state.chosenIcon = isImage(data?.contentType) ? 'image' : 'page'
|
|
217
|
+
state.chosenGone = !data
|
|
218
|
+
return
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
const result = await api().get('/api/links?ref=' + encodeURIComponent(stored))
|
|
222
|
+
if (shown !== stored) return
|
|
223
|
+
const page = result.ok ? result.data.links?.[0] : null
|
|
224
|
+
state.chosenTitle = page?.title ?? 'A page'
|
|
225
|
+
state.chosenWhere = page?.collectionLabel ?? ''
|
|
226
|
+
state.chosenHref = page?.href ?? ''
|
|
227
|
+
state.chosenDraft = Boolean(page && !page.published)
|
|
228
|
+
state.chosenIcon = 'page'
|
|
229
|
+
state.chosenGone = !page
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
/** Say what an address will do, so the editor can see it was understood. */
|
|
233
|
+
function describe(href: string) {
|
|
234
|
+
const read = readTypedLink(href, hosts)
|
|
235
|
+
if (read.kind !== 'address') {
|
|
236
|
+
state.note = ''
|
|
237
|
+
return
|
|
238
|
+
}
|
|
239
|
+
if (read.href.startsWith('mailto:')) {
|
|
240
|
+
state.noteIcon = 'write'
|
|
241
|
+
state.note = 'Writes an email to ' + read.label
|
|
242
|
+
} else if (read.href.startsWith('tel:')) {
|
|
243
|
+
state.noteIcon = 'phone'
|
|
244
|
+
state.note = 'Calls ' + read.label
|
|
245
|
+
} else if (read.own) {
|
|
246
|
+
state.noteIcon = 'link'
|
|
247
|
+
state.note = read.href.startsWith('#') ? 'A part of this page' : 'A page on this site: ' + read.href
|
|
248
|
+
} else {
|
|
249
|
+
state.noteIcon = 'off-site'
|
|
250
|
+
state.note = 'Another site: ' + read.label
|
|
251
|
+
}
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
function typed() {
|
|
255
|
+
state.problem = ''
|
|
256
|
+
clearTimeout(timer)
|
|
257
|
+
const read = readTypedLink(state.typed, hosts)
|
|
258
|
+
|
|
259
|
+
if (read.kind === 'empty') {
|
|
260
|
+
shown = ''
|
|
261
|
+
value.value = undefined
|
|
262
|
+
state.note = ''
|
|
263
|
+
close()
|
|
264
|
+
return
|
|
265
|
+
}
|
|
266
|
+
|
|
267
|
+
if (read.kind === 'address') {
|
|
268
|
+
const kind = kindOfHref(read.href)
|
|
269
|
+
close()
|
|
270
|
+
if (kind && !kinds.includes(kind)) {
|
|
271
|
+
shown = ''
|
|
272
|
+
value.value = undefined
|
|
273
|
+
state.note = ''
|
|
274
|
+
state.problem = refusedKind(kind)
|
|
275
|
+
return
|
|
276
|
+
}
|
|
277
|
+
shown = read.href
|
|
278
|
+
value.value = read.href
|
|
279
|
+
describe(read.href)
|
|
280
|
+
return
|
|
281
|
+
}
|
|
282
|
+
|
|
283
|
+
shown = ''
|
|
284
|
+
value.value = undefined
|
|
285
|
+
state.note = ''
|
|
286
|
+
if (pages || files) timer = setTimeout(() => search(read.words), 150)
|
|
287
|
+
}
|
|
288
|
+
|
|
289
|
+
async function search(words: string) {
|
|
290
|
+
const ask = ++asked
|
|
291
|
+
const not = route.id && route.id !== 'new' ? '¬=' + encodeURIComponent(route.id) : ''
|
|
292
|
+
const [entries, media] = await Promise.all([
|
|
293
|
+
pages ? api().get('/api/links?q=' + encodeURIComponent(words) + not + only) : Promise.resolve(null),
|
|
294
|
+
files ? api().get('/api/entries/media?limit=5&search=' + encodeURIComponent(words)) : Promise.resolve(null),
|
|
295
|
+
])
|
|
296
|
+
if (ask !== asked) return
|
|
297
|
+
|
|
298
|
+
const found = [
|
|
299
|
+
...(entries && entries.ok ? entries.data.links ?? [] : []).map((one: any) => ({
|
|
300
|
+
key: one.collection + ':' + one.id,
|
|
301
|
+
title: one.title,
|
|
302
|
+
where: one.collectionLabel,
|
|
303
|
+
href: one.href,
|
|
304
|
+
ref: one.ref,
|
|
305
|
+
draft: !one.published,
|
|
306
|
+
icon: 'page',
|
|
307
|
+
})),
|
|
308
|
+
...(media && media.ok ? media.data.entries ?? [] : []).map((one: any) => ({
|
|
309
|
+
key: 'media:' + one.id,
|
|
310
|
+
title: one.title,
|
|
311
|
+
where: 'File',
|
|
312
|
+
href: '',
|
|
313
|
+
ref: linkTo('media', one.id),
|
|
314
|
+
draft: false,
|
|
315
|
+
icon: isImage(one.contentType) ? 'image' : 'page',
|
|
316
|
+
})),
|
|
317
|
+
]
|
|
318
|
+
state.results = found.map((one, index) => ({ ...one, index }))
|
|
319
|
+
state.active = found.length ? 0 : -1
|
|
320
|
+
state.none = 'Nothing called “' + words + '”.' + (kinds.includes('web') ? ' Paste an address to link somewhere else.' : '')
|
|
321
|
+
state.open = true
|
|
322
|
+
}
|
|
323
|
+
|
|
324
|
+
/** An address on this site that is a page's: hold the page instead, so the link follows it. */
|
|
325
|
+
async function adoptPage(href: string) {
|
|
326
|
+
const path = comparablePath(href)
|
|
327
|
+
const result = await api().get('/api/links?q=' + encodeURIComponent(path) + only)
|
|
328
|
+
if (shown !== href || !result.ok) return
|
|
329
|
+
const page = (result.data.links ?? []).find((one: any) => comparablePath(one.href) === path)
|
|
330
|
+
if (!page) return
|
|
331
|
+
const ref = linkTo(page.collection, page.id, fragmentOf(href))
|
|
332
|
+
choose({ title: page.title, where: page.collectionLabel, href: page.href, ref, draft: !page.published, icon: 'page' })
|
|
333
|
+
}
|
|
334
|
+
|
|
335
|
+
/** Before the input loses focus, or the click would land on nothing. */
|
|
336
|
+
function pick(event: PointerEvent, one: Found) {
|
|
337
|
+
event.preventDefault()
|
|
338
|
+
choose(one)
|
|
339
|
+
}
|
|
340
|
+
|
|
341
|
+
function settle() {
|
|
342
|
+
const read = readTypedLink(state.typed, hosts)
|
|
343
|
+
if (read.kind === 'address') {
|
|
344
|
+
const kind = kindOfHref(read.href)
|
|
345
|
+
if (kind && !kinds.includes(kind)) return
|
|
346
|
+
state.typed = read.href
|
|
347
|
+
if (read.own && read.href.startsWith('/')) adoptPage(read.href)
|
|
348
|
+
} else if (read.kind === 'words' && !state.chosen) {
|
|
349
|
+
state.problem = linkMessage(kinds)
|
|
350
|
+
}
|
|
351
|
+
}
|
|
352
|
+
|
|
353
|
+
function key(event: KeyboardEvent) {
|
|
354
|
+
if (event.key === 'Enter') {
|
|
355
|
+
// Inside the entry's form, where Enter would save the page.
|
|
356
|
+
event.preventDefault()
|
|
357
|
+
if (state.open && state.active >= 0) choose(state.results[state.active]!)
|
|
358
|
+
else settle()
|
|
359
|
+
return
|
|
360
|
+
}
|
|
361
|
+
if (!state.open) return
|
|
362
|
+
const last = state.results.length - 1
|
|
363
|
+
if (event.key === 'ArrowDown') {
|
|
364
|
+
event.preventDefault()
|
|
365
|
+
state.active = state.active >= last ? 0 : state.active + 1
|
|
366
|
+
} else if (event.key === 'ArrowUp') {
|
|
367
|
+
event.preventDefault()
|
|
368
|
+
state.active = state.active <= 0 ? last : state.active - 1
|
|
369
|
+
} else if (event.key === 'Escape') {
|
|
370
|
+
event.preventDefault()
|
|
371
|
+
close()
|
|
372
|
+
}
|
|
373
|
+
}
|
|
374
|
+
|
|
375
|
+
function blurred() {
|
|
376
|
+
close()
|
|
377
|
+
settle()
|
|
378
|
+
}
|
|
379
|
+
|
|
380
|
+
function close() {
|
|
381
|
+
asked++
|
|
382
|
+
state.open = false
|
|
383
|
+
state.active = -1
|
|
384
|
+
}
|
|
385
|
+
|
|
386
|
+
onMounted(() => {
|
|
387
|
+
value.subscribe(show)
|
|
388
|
+
readonly.subscribe(show)
|
|
389
|
+
learnHosts().then(() => {
|
|
390
|
+
if (!state.chosen && state.typed) describe(state.typed)
|
|
391
|
+
})
|
|
392
|
+
show()
|
|
393
|
+
})
|
|
394
|
+
</logic>
|
|
395
|
+
|
|
396
|
+
<style>
|
|
397
|
+
.link-field {
|
|
398
|
+
position: relative;
|
|
399
|
+
}
|
|
400
|
+
|
|
401
|
+
.link-chosen {
|
|
402
|
+
display: flex;
|
|
403
|
+
gap: var(--sp-2);
|
|
404
|
+
align-items: center;
|
|
405
|
+
padding: var(--sp-2) var(--sp-3);
|
|
406
|
+
border: 1px solid var(--border);
|
|
407
|
+
border-radius: var(--r-m);
|
|
408
|
+
background: var(--surface);
|
|
409
|
+
}
|
|
410
|
+
|
|
411
|
+
.link-chosen-words,
|
|
412
|
+
.link-option-words {
|
|
413
|
+
display: grid;
|
|
414
|
+
flex: 1;
|
|
415
|
+
gap: 2px;
|
|
416
|
+
min-inline-size: 0;
|
|
417
|
+
}
|
|
418
|
+
|
|
419
|
+
.link-chosen-title,
|
|
420
|
+
.link-option-title {
|
|
421
|
+
font-weight: var(--fw-medium);
|
|
422
|
+
}
|
|
423
|
+
|
|
424
|
+
.link-chosen-meta,
|
|
425
|
+
.link-option-meta {
|
|
426
|
+
display: flex;
|
|
427
|
+
flex-wrap: wrap;
|
|
428
|
+
gap: var(--sp-2);
|
|
429
|
+
align-items: center;
|
|
430
|
+
font-size: 0.8125rem;
|
|
431
|
+
}
|
|
432
|
+
|
|
433
|
+
.link-gone {
|
|
434
|
+
color: var(--danger);
|
|
435
|
+
font-size: 0.8125rem;
|
|
436
|
+
}
|
|
437
|
+
|
|
438
|
+
.link-options {
|
|
439
|
+
position: absolute;
|
|
440
|
+
inset-inline: 0;
|
|
441
|
+
z-index: 10;
|
|
442
|
+
max-block-size: 320px;
|
|
443
|
+
margin: var(--sp-1) 0 0;
|
|
444
|
+
padding: var(--sp-1);
|
|
445
|
+
overflow: auto;
|
|
446
|
+
list-style: none;
|
|
447
|
+
}
|
|
448
|
+
|
|
449
|
+
.link-option {
|
|
450
|
+
display: flex;
|
|
451
|
+
gap: var(--sp-2);
|
|
452
|
+
align-items: flex-start;
|
|
453
|
+
}
|
|
454
|
+
|
|
455
|
+
.link-options .active {
|
|
456
|
+
background: var(--surface-hover);
|
|
457
|
+
}
|
|
458
|
+
|
|
459
|
+
.link-none {
|
|
460
|
+
padding: var(--sp-2) var(--sp-3);
|
|
461
|
+
color: var(--text-2);
|
|
462
|
+
}
|
|
463
|
+
|
|
464
|
+
.link-note,
|
|
465
|
+
.link-problem {
|
|
466
|
+
display: flex;
|
|
467
|
+
gap: var(--sp-1);
|
|
468
|
+
align-items: center;
|
|
469
|
+
margin: var(--sp-1) 0 0;
|
|
470
|
+
color: var(--text-2);
|
|
471
|
+
font-size: 0.8125rem;
|
|
472
|
+
}
|
|
473
|
+
|
|
474
|
+
.link-problem {
|
|
475
|
+
color: var(--danger);
|
|
476
|
+
}
|
|
477
|
+
</style>
|
|
@@ -165,7 +165,7 @@
|
|
|
165
165
|
<span $show="!state.compact">{{ state.count }}</span>
|
|
166
166
|
<span $class="{ 'rte-over': state.over }" $show="state.limit">{{ state.limit }}</span>
|
|
167
167
|
<span class="rte-foot-end" $show="state.slashable && !state.raw && !state.readOnly">
|
|
168
|
-
Type <span class="kbd">/</span> to insert · <span class="kbd">{{ state.keys.
|
|
168
|
+
Type <span class="kbd">/</span> to insert · <span class="kbd">{{ state.keys.shortcutKeys }}</span> for shortcuts
|
|
169
169
|
</span>
|
|
170
170
|
<span class="rte-foot-end" $show="state.expanded">Esc or Done returns you to the same place on the page</span>
|
|
171
171
|
|
|
@@ -276,7 +276,6 @@
|
|
|
276
276
|
<dd><span class="kbd" $for="key in row.keys" $key="key">{{ key }}</span></dd>
|
|
277
277
|
</div>
|
|
278
278
|
</dl>
|
|
279
|
-
<p class="subtle" $show="!state.mac">On a Mac, use ⌘ instead of Ctrl.</p>
|
|
280
279
|
</div>
|
|
281
280
|
</dialog>
|
|
282
281
|
</div>
|
|
@@ -288,6 +287,7 @@ import { defineProps, reactive, onMounted, onUpdate, shared } from '@lightspeed-
|
|
|
288
287
|
import { applyTool, buttonsFor, offersCaption, offersHeadings, offersLead, plainWords, readingNote, toolsFor } from '../content/markdown.ts'
|
|
289
288
|
import { createSurface, unrepresentable } from '../content/richtext.ts'
|
|
290
289
|
import { linkSearch } from '../content/url.ts'
|
|
290
|
+
import { keyLabel, keyParts, onMac } from '../keys.ts'
|
|
291
291
|
|
|
292
292
|
/**
|
|
293
293
|
* Long text, written as it will read.
|
|
@@ -305,8 +305,7 @@ const props = defineProps({
|
|
|
305
305
|
|
|
306
306
|
let seq = 0
|
|
307
307
|
|
|
308
|
-
const MAC =
|
|
309
|
-
const MOD = MAC ? '⌘' : 'Ctrl'
|
|
308
|
+
const MAC = onMac()
|
|
310
309
|
|
|
311
310
|
const offered = toolsFor(props.field).map((tool) => tool.name)
|
|
312
311
|
const offers = (name) => offered.includes(name)
|
|
@@ -321,7 +320,7 @@ const SLASH = [
|
|
|
321
320
|
{ name: 'lead', label: 'Lead paragraph', note: 'The larger opening paragraph', icon: '', glyph: 'P', hint: '^^', on: offers('lead') },
|
|
322
321
|
{ name: 'caption', label: 'Caption', note: 'Small print, such as who supported it', icon: '', glyph: 'c', hint: '^', on: offers('caption') },
|
|
323
322
|
{ name: 'divider', label: 'Divider', note: 'A line between two parts', icon: 'divider', hint: '---', on: offers('heading') },
|
|
324
|
-
{ name: 'link', label: 'Link', note: 'To a page or a web address', icon: 'link', hint:
|
|
323
|
+
{ name: 'link', label: 'Link', note: 'To a page or a web address', icon: 'link', hint: keyLabel('Mod+K'), on: offers('link') },
|
|
325
324
|
].filter((item) => item.on)
|
|
326
325
|
|
|
327
326
|
const state = reactive({
|
|
@@ -347,7 +346,7 @@ const state = reactive({
|
|
|
347
346
|
glyph: tool.glyph,
|
|
348
347
|
icon: tool.icon,
|
|
349
348
|
group: Boolean(tool.group),
|
|
350
|
-
title: tool.shortcut ? `${tool.label} (${
|
|
349
|
+
title: tool.shortcut ? `${tool.label} (${keyLabel('Mod+' + tool.shortcut)})` : tool.label,
|
|
351
350
|
/** Whether it applies to what is selected. Rendered mode only. */
|
|
352
351
|
active: false,
|
|
353
352
|
unavailable: false,
|
|
@@ -374,24 +373,23 @@ const state = reactive({
|
|
|
374
373
|
linkPageTitle: '',
|
|
375
374
|
linkPageDraft: false,
|
|
376
375
|
linked: false,
|
|
377
|
-
mac: MAC,
|
|
378
376
|
keys: {
|
|
379
|
-
|
|
380
|
-
undo: `Undo (${
|
|
381
|
-
redo: `Redo (${
|
|
382
|
-
shortcuts: `Keyboard shortcuts (${
|
|
383
|
-
expand: `Expand to write full screen (${
|
|
377
|
+
shortcutKeys: keyLabel('Mod+/'),
|
|
378
|
+
undo: `Undo (${keyLabel('Mod+Z')})`,
|
|
379
|
+
redo: `Redo (${keyLabel(MAC ? 'Mod+Shift+Z' : 'Mod+Y')})`,
|
|
380
|
+
shortcuts: `Keyboard shortcuts (${keyLabel('Mod+/')})`,
|
|
381
|
+
expand: `Expand to write full screen (${keyLabel('Mod+Shift+Enter')})`,
|
|
384
382
|
},
|
|
385
383
|
formatKeys: [
|
|
386
|
-
...(offers('bold') ? [{ label: 'Bold', keys:
|
|
387
|
-
...(offers('italic') ? [{ label: 'Italic', keys:
|
|
388
|
-
...(offers('underline') ? [{ label: 'Underline', keys:
|
|
389
|
-
...(offers('link') ? [{ label: 'Link', keys:
|
|
390
|
-
{ label: 'Paste as plain text', keys:
|
|
391
|
-
{ label: 'Undo', keys:
|
|
392
|
-
{ label: 'Move a block up or down', keys:
|
|
393
|
-
{ label: 'Go to the toolbar', keys:
|
|
394
|
-
{ label: 'Write full screen', keys:
|
|
384
|
+
...(offers('bold') ? [{ label: 'Bold', keys: keyParts('Mod+B') }] : []),
|
|
385
|
+
...(offers('italic') ? [{ label: 'Italic', keys: keyParts('Mod+I') }] : []),
|
|
386
|
+
...(offers('underline') ? [{ label: 'Underline', keys: keyParts('Mod+U') }] : []),
|
|
387
|
+
...(offers('link') ? [{ label: 'Link', keys: keyParts('Mod+K') }] : []),
|
|
388
|
+
{ label: 'Paste as plain text', keys: keyParts('Mod+Shift+V') },
|
|
389
|
+
{ label: 'Undo', keys: keyParts('Mod+Z') },
|
|
390
|
+
{ label: 'Move a block up or down', keys: keyParts('Mod+Shift+ArrowUp+ArrowDown') },
|
|
391
|
+
{ label: 'Go to the toolbar', keys: keyParts('Alt+F10') },
|
|
392
|
+
{ label: 'Write full screen', keys: keyParts('Mod+Shift+Enter') },
|
|
395
393
|
],
|
|
396
394
|
typeKeys: [
|
|
397
395
|
...(offers('heading')
|
|
@@ -539,9 +537,6 @@ onMounted(sync)
|
|
|
539
537
|
// usually empty. This is what fills it in.
|
|
540
538
|
onUpdate(sync)
|
|
541
539
|
|
|
542
|
-
function modifier() {
|
|
543
|
-
return MAC ? '⌘' : 'Ctrl+'
|
|
544
|
-
}
|
|
545
540
|
|
|
546
541
|
/** Keep the selection: a button taking focus would discard it. */
|
|
547
542
|
function hold(event) {
|