@clarusjs/editor 0.0.0 → 0.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +8 -1
- package/dist/behaviours/content.d.ts +12 -0
- package/dist/behaviours/content.js +27 -0
- package/dist/behaviours/editor.d.ts +9 -0
- package/dist/behaviours/editor.js +8 -0
- package/dist/behaviours/suggestion.d.ts +50 -0
- package/dist/behaviours/suggestion.js +198 -0
- package/dist/behaviours/toolbar.d.ts +12 -0
- package/dist/behaviours/toolbar.js +54 -0
- package/dist/core/editor.d.ts +71 -0
- package/dist/core/editor.js +170 -0
- package/dist/core/extension.d.ts +44 -0
- package/dist/core/extension.js +3 -0
- package/dist/core/from-text.d.ts +11 -0
- package/dist/core/from-text.js +67 -0
- package/dist/core/length.d.ts +8 -0
- package/dist/core/length.js +6 -0
- package/dist/core/plain-text.d.ts +7 -0
- package/dist/core/plain-text.js +30 -0
- package/dist/core/registry.d.ts +18 -0
- package/dist/core/registry.js +50 -0
- package/dist/core/schema.d.ts +27 -0
- package/dist/core/schema.js +104 -0
- package/dist/emoji.d.ts +15 -0
- package/dist/emoji.js +8 -0
- package/dist/extensions/base.d.ts +5 -0
- package/dist/extensions/base.js +10 -0
- package/dist/extensions/code-block.d.ts +6 -0
- package/dist/extensions/code-block.js +58 -0
- package/dist/extensions/composer.d.ts +14 -0
- package/dist/extensions/composer.js +19 -0
- package/dist/extensions/history.d.ts +5 -0
- package/dist/extensions/history.js +8 -0
- package/dist/extensions/link.d.ts +7 -0
- package/dist/extensions/link.js +45 -0
- package/dist/extensions/markdown-shortcuts.d.ts +5 -0
- package/dist/extensions/markdown-shortcuts.js +23 -0
- package/dist/extensions/marks.d.ts +15 -0
- package/dist/extensions/marks.js +36 -0
- package/dist/extensions/mention.d.ts +6 -0
- package/dist/extensions/mention.js +22 -0
- package/dist/extensions/placeholder.d.ts +8 -0
- package/dist/extensions/placeholder.js +11 -0
- package/dist/index.d.ts +18 -0
- package/dist/index.js +17 -0
- package/dist/server.d.ts +43 -0
- package/dist/server.js +133 -0
- package/package.json +98 -4
- package/src/components/count.tscl +40 -0
- package/src/components/field.tscl +115 -0
- package/src/components/files.tscl +23 -0
- package/src/components/send.tscl +49 -0
- package/src/components/suggestions.tscl +66 -0
- package/src/components/tool.tscl +12 -0
- package/src/components/toolbar.tscl +34 -0
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
{{--
|
|
2
|
+
Editor files (@clarusjs/editor): a button that opens a file picker; the files picked go to (files), as files pasted or
|
|
3
|
+
dropped into the field go to the field's (files). Uploading and showing them is yours.
|
|
4
|
+
|
|
5
|
+
<editor-files (files)="upload($event.files)" />
|
|
6
|
+
|
|
7
|
+
Headless: data-part="attach" (the button) and "files" (its hidden input).
|
|
8
|
+
--}}
|
|
9
|
+
@input label: string = 'Attach files'
|
|
10
|
+
@input accept: string = ''
|
|
11
|
+
@event files: { files: File[] }
|
|
12
|
+
|
|
13
|
+
<script>
|
|
14
|
+
let input
|
|
15
|
+
function picked(event) {
|
|
16
|
+
const files = [...event.target.files]
|
|
17
|
+
event.target.value = ''
|
|
18
|
+
if (files.length) emit('files', { files })
|
|
19
|
+
}
|
|
20
|
+
</script>
|
|
21
|
+
|
|
22
|
+
<button type="button" data-part="attach" [aria-label]="label" (click)="input?.click()">📎</button>
|
|
23
|
+
<input type="file" multiple hidden data-part="files" [accept]="accept || false" [use]="(el) => { input = el }" (change)="picked($event)" />
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
{{--
|
|
2
|
+
Editor send (@clarusjs/editor): a submit button that sends the field named by [field] (its (send) fires), disabled
|
|
3
|
+
past the field's limit. Before the field's editor runs it's a plain submit: the form posts the textarea.
|
|
4
|
+
|
|
5
|
+
<editor-send [field]="'msg'" label="Send" />
|
|
6
|
+
|
|
7
|
+
Headless: data-part="send".
|
|
8
|
+
--}}
|
|
9
|
+
@input field: string
|
|
10
|
+
@input label: string = 'Send'
|
|
11
|
+
|
|
12
|
+
<script>
|
|
13
|
+
import { effect, untrack } from 'clarusjs/runtime'
|
|
14
|
+
import { onEditor } from '@clarusjs/editor/registry'
|
|
15
|
+
let over = state(false)
|
|
16
|
+
let current
|
|
17
|
+
// sends the field [field] names, again whenever a parent changes it
|
|
18
|
+
function wire() {
|
|
19
|
+
let off
|
|
20
|
+
const stop = effect(() => {
|
|
21
|
+
const id = field
|
|
22
|
+
off?.()
|
|
23
|
+
off = untrack(() =>
|
|
24
|
+
onEditor(id, (editor) => {
|
|
25
|
+
current = editor
|
|
26
|
+
const watch = effect(() => {
|
|
27
|
+
over = editor.over.get()
|
|
28
|
+
})
|
|
29
|
+
return () => {
|
|
30
|
+
watch()
|
|
31
|
+
current = undefined
|
|
32
|
+
over = false
|
|
33
|
+
}
|
|
34
|
+
}),
|
|
35
|
+
)
|
|
36
|
+
})
|
|
37
|
+
return () => {
|
|
38
|
+
stop()
|
|
39
|
+
off?.()
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
function click(event) {
|
|
43
|
+
if (!current) return // no editor yet: the form posts the textarea, as with no JavaScript
|
|
44
|
+
event.preventDefault()
|
|
45
|
+
current.send()
|
|
46
|
+
}
|
|
47
|
+
</script>
|
|
48
|
+
|
|
49
|
+
<button type="submit" data-part="send" [disabled]="over" [use]="wire" (click)="click($event)">{{ label }}</button>
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
{{--
|
|
2
|
+
Editor suggestions (@clarusjs/editor): the list a character opens in the field named by [field], as a combobox (the
|
|
3
|
+
field keeps focus; ↑ ↓ move, Enter or Tab picks, Escape closes).
|
|
4
|
+
- char "@": people, from (search): answer with $event.respond(items) ({ id, label }); a pick becomes a mention.
|
|
5
|
+
- char "/": [commands] ({ id, label, keywords? }); a pick sends (command) with its id and the editor.
|
|
6
|
+
- char ":": emoji, by GitHub's shortcodes and their names; a pick inserts it.
|
|
7
|
+
|
|
8
|
+
<editor-suggestions [field]="'msg'" char="@" (search)="$event.respond(people($event.query, $event.signal))" />
|
|
9
|
+
<editor-suggestions [field]="'msg'" char="/" [commands]="commands" (command)="run($event)" />
|
|
10
|
+
<editor-suggestions [field]="'msg'" char=":" />
|
|
11
|
+
|
|
12
|
+
Headless: data-part="suggestions" (the list) and "suggestion" (each option).
|
|
13
|
+
--}}
|
|
14
|
+
@type Item = { id: string; label: string }
|
|
15
|
+
@type Command = { id: string; label: string; keywords?: string[] }
|
|
16
|
+
@input field: string
|
|
17
|
+
@input char: '@' | '/' | ':' = '@'
|
|
18
|
+
@input label: string = ''
|
|
19
|
+
@input commands: Command[] = []
|
|
20
|
+
@event search: { query: string; signal: AbortSignal; respond: (items: Item[] | Promise<Item[]>) => void }
|
|
21
|
+
@event command: { id: string; editor: any }
|
|
22
|
+
|
|
23
|
+
<script>
|
|
24
|
+
import { effect, untrack } from 'clarusjs/runtime'
|
|
25
|
+
import { onEditor } from '@clarusjs/editor/registry'
|
|
26
|
+
import { searchEmoji, suggestion } from '@clarusjs/editor/suggestion'
|
|
27
|
+
const names = { '@': 'People', '/': 'Commands', ':': 'Emoji' }
|
|
28
|
+
// (search): whoever listens answers with respond().
|
|
29
|
+
function ask(query, signal) {
|
|
30
|
+
let answer
|
|
31
|
+
emit('search', { query, signal, respond: (items) => (answer = items) })
|
|
32
|
+
return answer ?? []
|
|
33
|
+
}
|
|
34
|
+
const matching = (q) =>
|
|
35
|
+
commands.filter((c) => [c.label, ...(c.keywords ?? [])].some((w) => w.toLowerCase().includes(q.toLowerCase())))
|
|
36
|
+
const kinds = {
|
|
37
|
+
'@': { search: ask, pick: (item, range, e) => e.run('mention', item, range) },
|
|
38
|
+
'/': {
|
|
39
|
+
search: matching,
|
|
40
|
+
pick: (item, range, e) => {
|
|
41
|
+
e.view.dispatch(e.view.state.tr.delete(range.from, range.to))
|
|
42
|
+
emit('command', { id: item.id, editor: e })
|
|
43
|
+
},
|
|
44
|
+
},
|
|
45
|
+
':': {
|
|
46
|
+
search: (q) => searchEmoji(q),
|
|
47
|
+
pick: (item, range, e) => e.view.dispatch(e.view.state.tr.insertText(item.char, range.from, range.to)),
|
|
48
|
+
},
|
|
49
|
+
}
|
|
50
|
+
// a list for the field [field] names and its [char], again whenever a parent changes either
|
|
51
|
+
function wire(list) {
|
|
52
|
+
let off
|
|
53
|
+
const stop = effect(() => {
|
|
54
|
+
const id = field
|
|
55
|
+
const c = char
|
|
56
|
+
off?.()
|
|
57
|
+
off = untrack(() => onEditor(id, (_editor, el) => suggestion(list, { editor: el, char: c, ...kinds[c] })))
|
|
58
|
+
})
|
|
59
|
+
return () => {
|
|
60
|
+
stop()
|
|
61
|
+
off?.()
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
</script>
|
|
65
|
+
|
|
66
|
+
<ul data-part="suggestions" [aria-label]="label || names[char]" hidden [use]="wire"></ul>
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
{{--
|
|
2
|
+
Editor tool (@clarusjs/editor): a button in an <editor-toolbar> that runs a command: bold, italic, code, link,
|
|
3
|
+
codeBlock, undo, redo, or one an extension adds. Disabled until its field's editor runs.
|
|
4
|
+
|
|
5
|
+
<editor-tool command="bold" label="Bold"><b>B</b></editor-tool>
|
|
6
|
+
|
|
7
|
+
Headless: data-part="tool".
|
|
8
|
+
--}}
|
|
9
|
+
@input command: string
|
|
10
|
+
@input label: string
|
|
11
|
+
|
|
12
|
+
<button type="button" data-part="tool" [data-command]="command" [aria-label]="label" aria-pressed="false" disabled><slot /></button>
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
{{--
|
|
2
|
+
Editor toolbar (@clarusjs/editor): the buttons inside it (<editor-tool>, or your own with data-command) run commands
|
|
3
|
+
on the field named by [field]; aria-pressed and disabled follow the selection; one tab stop, arrow keys between.
|
|
4
|
+
|
|
5
|
+
<editor-toolbar [field]="'msg'">
|
|
6
|
+
<editor-tool command="bold" label="Bold">B</editor-tool>
|
|
7
|
+
<editor-tool command="italic" label="Italic">I</editor-tool>
|
|
8
|
+
</editor-toolbar>
|
|
9
|
+
|
|
10
|
+
Headless: data-part="toolbar".
|
|
11
|
+
--}}
|
|
12
|
+
@input field: string
|
|
13
|
+
@input label: string = 'Formatting'
|
|
14
|
+
|
|
15
|
+
<script>
|
|
16
|
+
import { effect, untrack } from 'clarusjs/runtime'
|
|
17
|
+
import { onEditor } from '@clarusjs/editor/registry'
|
|
18
|
+
import { toolbar } from '@clarusjs/editor/toolbar'
|
|
19
|
+
// wired to the field [field] names, again whenever a parent changes it
|
|
20
|
+
function wire(el) {
|
|
21
|
+
let off
|
|
22
|
+
const stop = effect(() => {
|
|
23
|
+
const id = field
|
|
24
|
+
off?.()
|
|
25
|
+
off = untrack(() => onEditor(id, (_editor, fieldEl) => toolbar(el, { editor: fieldEl })))
|
|
26
|
+
})
|
|
27
|
+
return () => {
|
|
28
|
+
stop()
|
|
29
|
+
off?.()
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
</script>
|
|
33
|
+
|
|
34
|
+
<div data-part="toolbar" role="toolbar" [aria-label]="label" [use]="wire"><slot /></div>
|