@dou-ui/code 0.0.0-stage → 0.1.0-alpha.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/LICENSE +21 -0
- package/README.md +10 -2
- package/dist/_virtual/_rolldown/runtime.js +12 -0
- package/dist/assets/default-BZBMZKf_.js.map +1 -0
- package/dist/code-diff.js +6 -0
- package/dist/code-diff.js.map +1 -0
- package/dist/code-diff.vue_vue_type_script_setup_true_lang.js +792 -0
- package/dist/code-diff.vue_vue_type_script_setup_true_lang.js.map +1 -0
- package/dist/code-editor.js +6 -0
- package/dist/code-editor.js.map +1 -0
- package/dist/code-editor.vue_vue_type_script_setup_true_lang.js +5078 -0
- package/dist/code-editor.vue_vue_type_script_setup_true_lang.js.map +1 -0
- package/dist/code-input.js +6 -0
- package/dist/code-input.js.map +1 -0
- package/dist/code-input.vue_vue_type_script_setup_true_lang.js +237 -0
- package/dist/code-input.vue_vue_type_script_setup_true_lang.js.map +1 -0
- package/dist/code-keys.js +42 -0
- package/dist/code-keys.js.map +1 -0
- package/dist/code-keys.vue_vue_type_script_setup_true_lang.js +244 -0
- package/dist/code-keys.vue_vue_type_script_setup_true_lang.js.map +1 -0
- package/dist/code-keys2.js +6 -0
- package/dist/code-keys2.js.map +1 -0
- package/dist/collaboration/index.js +255 -0
- package/dist/collaboration/index.js.map +1 -0
- package/dist/completion/match.js +55 -0
- package/dist/completion/match.js.map +1 -0
- package/dist/completion/snippet.js +71 -0
- package/dist/completion/snippet.js.map +1 -0
- package/dist/core/brackets.js +55 -0
- package/dist/core/brackets.js.map +1 -0
- package/dist/core/changes.js +185 -0
- package/dist/core/changes.js.map +1 -0
- package/dist/core/chars.js +130 -0
- package/dist/core/chars.js.map +1 -0
- package/dist/core/commands.js +910 -0
- package/dist/core/commands.js.map +1 -0
- package/dist/core/diff.js +215 -0
- package/dist/core/diff.js.map +1 -0
- package/dist/core/folding.js +87 -0
- package/dist/core/folding.js.map +1 -0
- package/dist/core/history.js +74 -0
- package/dist/core/history.js.map +1 -0
- package/dist/core/keymap.js +326 -0
- package/dist/core/keymap.js.map +1 -0
- package/dist/core/search.js +91 -0
- package/dist/core/search.js.map +1 -0
- package/dist/core/selection.js +88 -0
- package/dist/core/selection.js.map +1 -0
- package/dist/core/text.js +320 -0
- package/dist/core/text.js.map +1 -0
- package/dist/core/transaction.js +98 -0
- package/dist/core/transaction.js.map +1 -0
- package/dist/extension.js +16 -0
- package/dist/extension.js.map +1 -0
- package/dist/index.js +38 -0
- package/dist/index.js.map +1 -0
- package/dist/language/highlighter.js +336 -0
- package/dist/language/highlighter.js.map +1 -0
- package/dist/language/language.js +138 -0
- package/dist/language/language.js.map +1 -0
- package/dist/language/stream.js +112 -0
- package/dist/language/stream.js.map +1 -0
- package/dist/language/to-html.js +36 -0
- package/dist/language/to-html.js.map +1 -0
- package/dist/language/worker-client.js +198 -0
- package/dist/language/worker-client.js.map +1 -0
- package/dist/language/worker-protocol.js +48 -0
- package/dist/language/worker-protocol.js.map +1 -0
- package/dist/languages/css.js +128 -0
- package/dist/languages/css.js.map +1 -0
- package/dist/languages/html.js +175 -0
- package/dist/languages/html.js.map +1 -0
- package/dist/languages/javascript.js +300 -0
- package/dist/languages/javascript.js.map +1 -0
- package/dist/languages/json.js +45 -0
- package/dist/languages/json.js.map +1 -0
- package/dist/languages/markdown.js +82 -0
- package/dist/languages/markdown.js.map +1 -0
- package/dist/languages/python.js +88 -0
- package/dist/languages/python.js.map +1 -0
- package/dist/languages/shell.js +153 -0
- package/dist/languages/shell.js.map +1 -0
- package/dist/languages/sql.js +91 -0
- package/dist/languages/sql.js.map +1 -0
- package/dist/languages/yaml.js +85 -0
- package/dist/languages/yaml.js.map +1 -0
- package/dist/locale.js +158 -0
- package/dist/locale.js.map +1 -0
- package/dist/lsp/index.js +715 -0
- package/dist/lsp/index.js.map +1 -0
- package/dist/lsp/markup.js +139 -0
- package/dist/lsp/markup.js.map +1 -0
- package/dist/render-part.js +14 -0
- package/dist/render-part.js.map +1 -0
- package/dist/shiki/index.js +140 -0
- package/dist/shiki/index.js.map +1 -0
- package/dist/style.css +1 -0
- package/dist/style.d.ts +1 -0
- package/dist/style.js +4 -0
- package/dist/types/code-diff.vue.d.ts +45 -0
- package/dist/types/code-editor.vue.d.ts +43 -0
- package/dist/types/code-input.vue.d.ts +32 -0
- package/dist/types/code-keys.d.ts +9 -0
- package/dist/types/code-keys.vue.d.ts +8 -0
- package/dist/types/collaboration/index.d.ts +36 -0
- package/dist/types/completion/match.d.ts +13 -0
- package/dist/types/completion/snippet.d.ts +17 -0
- package/dist/types/core/brackets.d.ts +15 -0
- package/dist/types/core/changes.d.ts +52 -0
- package/dist/types/core/chars.d.ts +24 -0
- package/dist/types/core/commands.d.ts +199 -0
- package/dist/types/core/diff.d.ts +52 -0
- package/dist/types/core/folding.d.ts +23 -0
- package/dist/types/core/history.d.ts +24 -0
- package/dist/types/core/keymap.d.ts +29 -0
- package/dist/types/core/search.d.ts +37 -0
- package/dist/types/core/selection.d.ts +28 -0
- package/dist/types/core/text.d.ts +79 -0
- package/dist/types/core/transaction.d.ts +65 -0
- package/dist/types/extension.d.ts +321 -0
- package/dist/types/index.d.ts +159 -0
- package/dist/types/language/highlighter.d.ts +99 -0
- package/dist/types/language/language.d.ts +100 -0
- package/dist/types/language/stream.d.ts +56 -0
- package/dist/types/language/to-html.d.ts +17 -0
- package/dist/types/language/worker-client.d.ts +52 -0
- package/dist/types/language/worker-protocol.d.ts +50 -0
- package/dist/types/languages/css.d.ts +17 -0
- package/dist/types/languages/html.d.ts +34 -0
- package/dist/types/languages/javascript.d.ts +29 -0
- package/dist/types/languages/json.d.ts +7 -0
- package/dist/types/languages/markdown.d.ts +17 -0
- package/dist/types/languages/python.d.ts +9 -0
- package/dist/types/languages/shell.d.ts +11 -0
- package/dist/types/languages/sql.d.ts +9 -0
- package/dist/types/languages/yaml.d.ts +14 -0
- package/dist/types/locale.d.ts +79 -0
- package/dist/types/lsp/index.d.ts +119 -0
- package/dist/types/lsp/markup.d.ts +14 -0
- package/dist/types/render-part.d.ts +14 -0
- package/dist/types/shiki/index.d.ts +63 -0
- package/dist/types/types.d.ts +267 -0
- package/dist/types/view/input.d.ts +12 -0
- package/dist/types/view/layout.d.ts +55 -0
- package/dist/types/view/measure.d.ts +22 -0
- package/dist/types/view/viewport.d.ts +16 -0
- package/dist/types/view/viewport.test.d.ts +1 -0
- package/dist/types/worker/default.d.ts +1 -0
- package/dist/types/worker/index.d.ts +34 -0
- package/dist/view/input.js +27 -0
- package/dist/view/input.js.map +1 -0
- package/dist/view/layout.js +194 -0
- package/dist/view/layout.js.map +1 -0
- package/dist/view/measure.js +104 -0
- package/dist/view/measure.js.map +1 -0
- package/dist/view/viewport.js +31 -0
- package/dist/view/viewport.js.map +1 -0
- package/dist/worker/default.js +20 -0
- package/dist/worker/default.js.map +1 -0
- package/dist/worker/index.js +139 -0
- package/dist/worker/index.js.map +1 -0
- package/package.json +88 -4
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import code_input_vue_vue_type_script_setup_true_lang_default from "./code-input.vue_vue_type_script_setup_true_lang.js";
|
|
2
|
+
// src/code-input.vue
|
|
3
|
+
var code_input_default = code_input_vue_vue_type_script_setup_true_lang_default;
|
|
4
|
+
export { code_input_default as default };
|
|
5
|
+
|
|
6
|
+
//# sourceMappingURL=code-input.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"code-input.js","names":["_sfc_main"],"sources":["../src/code-input.vue"],"sourcesContent":["<script setup lang=\"ts\">\nimport { computed, ref, useAttrs, watchEffect } from 'vue'\nimport type { StyleValue } from 'vue'\nimport { useFormDisabled, useFormItem, useFormReadonly, useFormSize, useNamespace } from 'dou-ui'\nimport CodeEditor from './code-editor.vue'\nimport type { CodeKeymap } from './core/keymap'\nimport type { CodeTransactionResult } from './core/transaction'\nimport type { CodeEditorExpose, CodeInputEmits, CodeInputProps } from './types'\n\n/**\n * A code box the size of a text input, for expressions and formulas: one\n * line (or a few, with `multiline`), highlighted, with the editor's\n * completions and problems. Inside a form item it takes the item's id,\n * description and state, as DouInput does.\n */\ndefineOptions({ name: 'DouCodeInput', inheritAttrs: false })\n\nconst props = withDefaults(defineProps<CodeInputProps>(), {\n modelValue: '',\n multiline: false,\n autosize: () => ({}),\n invalid: false,\n disabled: undefined,\n readonly: false,\n language: undefined,\n closeBrackets: true,\n teleport: undefined,\n keys: false,\n messages: undefined,\n})\nconst emit = defineEmits<CodeInputEmits>()\n\nconst ns = useNamespace('code-input')\nconst attrs = useAttrs()\nconst { formItem } = useFormItem()\nconst size = useFormSize(() => props.size)\nconst disabled = useFormDisabled(() => props.disabled)\nconst readonly = useFormReadonly(() => props.readonly)\nconst invalid = computed(() => props.invalid || !!formItem?.invalid.value)\n\nconst editor = ref<CodeEditorExpose>()\nconst root = ref<HTMLElement>()\n\nfunction submit() {\n emit('enter')\n return true\n}\n\nconst keymap = computed<CodeKeymap>(() => {\n // One line: Enter hands over to the form. Several: Mod + Enter does.\n const own: CodeKeymap = props.multiline\n ? { 'mod+enter': submit }\n : { enter: submit, 'shift+enter': submit, 'mod+enter': submit }\n return { ...own, ...props.keymap }\n})\n\n/** One line only: line breaks typed, pasted or dropped become spaces. */\nconst flatten = (text: string) => text.replace(/[ \\t]*\\r?\\n[ \\t]*/g, ' ')\n\nfunction onPaste(event: ClipboardEvent) {\n if (props.multiline || !editor.value) return\n const text = event.clipboardData?.getData('text/plain') ?? ''\n if (!/[\\r\\n]/.test(text)) return\n event.preventDefault()\n event.stopPropagation()\n editor.value.transact((tr) => tr.replaceSelection(flatten(text)), {\n action: 'paste',\n scroll: true,\n })\n}\n\n// A phone's Enter key may come as input with no key event before it.\nfunction onBeforeInput(event: InputEvent) {\n if (props.multiline) return\n if (event.inputType !== 'insertLineBreak' && event.inputType !== 'insertParagraph') return\n event.preventDefault()\n event.stopPropagation()\n emit('enter')\n}\n\nfunction onTransaction(result: CodeTransactionResult) {\n emit('transaction', result)\n // Whatever else brought a line break in (a drop, an extension): one line again.\n if (props.multiline || result.meta.action === 'external' || result.state.doc.lines < 2) return\n const text = result.state.doc.toString()\n editor.value?.transact((tr) => tr.replace(0, text.length, flatten(text)), { history: false })\n}\n\n// The textarea is the control a label and a form item point at.\nwatchEffect(() => {\n const textarea = root.value?.querySelector('textarea')\n if (!textarea) return\n const set = (name: string, value: string | undefined) =>\n value === undefined ? textarea.removeAttribute(name) : textarea.setAttribute(name, value)\n set('id', (attrs.id as string | undefined) ?? formItem?.inputId)\n set(\n 'aria-describedby',\n (attrs['aria-describedby'] as string | undefined) ?? formItem?.describedBy.value,\n )\n set('aria-required', formItem?.required.value ? 'true' : undefined)\n set('aria-invalid', invalid.value ? 'true' : undefined)\n set('enterkeyhint', props.multiline ? 'enter' : 'done')\n})\n\nconst height = computed(() => {\n if (!props.multiline) return undefined\n const min = Math.max(1, props.autosize.minRows ?? 1)\n const max = Math.max(min, props.autosize.maxRows ?? 6)\n return { '--dou-code-input-min-rows': min, '--dou-code-input-max-rows': max }\n})\n\n// The same instance as the editor's.\nconst EXPOSED = [\n 'state',\n 'doc',\n 'selection',\n 'transact',\n 'run',\n 'undo',\n 'redo',\n 'canUndo',\n 'canRedo',\n 'select',\n 'scrollIntoView',\n 'coordsAtPos',\n 'posAtCoords',\n 'focus',\n 'blur',\n 'openSearch',\n 'closeSearch',\n 'fold',\n 'unfold',\n 'foldAll',\n 'unfoldAll',\n 'folds',\n 'diagnostics',\n] as const\nconst exposed = {} as CodeEditorExpose\nfor (const key of EXPOSED)\n Object.defineProperty(exposed, key, {\n enumerable: true,\n get: () => editor.value?.[key],\n })\ndefineExpose(exposed)\n</script>\n\n<template>\n <div\n ref=\"root\"\n :class=\"[\n ns.b(),\n ns.m(size),\n ns.is('multiline', multiline),\n ns.is('invalid', invalid),\n ns.is('disabled', disabled),\n attrs.class,\n ]\"\n :style=\"[attrs.style as StyleValue, height]\"\n @paste.capture=\"onPaste\"\n @beforeinput.capture=\"onBeforeInput\"\n >\n <CodeEditor\n ref=\"editor\"\n :model-value=\"modelValue\"\n :placeholder=\"placeholder\"\n :disabled=\"disabled\"\n :readonly=\"readonly\"\n :language=\"language\"\n :extensions=\"extensions\"\n :diagnostics=\"diagnostics\"\n :close-brackets=\"closeBrackets\"\n :tab-size=\"tabSize\"\n :messages=\"messages\"\n :keys=\"keys\"\n :keymap=\"keymap\"\n :teleport=\"teleport\"\n :aria-label=\"ariaLabel\"\n :autofocus=\"autofocus\"\n :gutter=\"false\"\n :active-line=\"false\"\n :foldable=\"false\"\n :searchable=\"false\"\n :tab-indents=\"false\"\n :wrap=\"multiline\"\n @update:model-value=\"\n (value: string) => {\n emit('update:modelValue', value)\n formItem?.trigger('change', { lazy: true })\n }\n \"\n @transaction=\"onTransaction\"\n @focus=\"emit('focus', $event)\"\n @blur=\"\n (event: FocusEvent) => {\n emit('blur', event)\n formItem?.trigger('blur')\n }\n \"\n />\n </div>\n</template>\n"],"mappings":""}
|
|
@@ -0,0 +1,237 @@
|
|
|
1
|
+
import code_editor_default from "./code-editor.js";
|
|
2
|
+
import { useFormDisabled, useFormItem, useFormReadonly, useFormSize, useNamespace } from "dou-ui";
|
|
3
|
+
import { computed, createElementBlock, createVNode, defineComponent, normalizeClass, normalizeStyle, openBlock, ref, unref, useAttrs, watchEffect } from "vue";
|
|
4
|
+
// src/code-input.vue?vue&type=script&setup=true&lang.ts
|
|
5
|
+
/**
|
|
6
|
+
* A code box the size of a text input, for expressions and formulas: one
|
|
7
|
+
* line (or a few, with `multiline`), highlighted, with the editor's
|
|
8
|
+
* completions and problems. Inside a form item it takes the item's id,
|
|
9
|
+
* description and state, as DouInput does.
|
|
10
|
+
*/
|
|
11
|
+
var code_input_vue_vue_type_script_setup_true_lang_default = /*@__PURE__*/ defineComponent({
|
|
12
|
+
name: "DouCodeInput",
|
|
13
|
+
inheritAttrs: false,
|
|
14
|
+
__name: "code-input",
|
|
15
|
+
props: {
|
|
16
|
+
modelValue: { default: "" },
|
|
17
|
+
placeholder: {},
|
|
18
|
+
multiline: {
|
|
19
|
+
type: Boolean,
|
|
20
|
+
default: false
|
|
21
|
+
},
|
|
22
|
+
autosize: { default: () => ({}) },
|
|
23
|
+
size: {},
|
|
24
|
+
invalid: {
|
|
25
|
+
type: Boolean,
|
|
26
|
+
default: false
|
|
27
|
+
},
|
|
28
|
+
disabled: {
|
|
29
|
+
type: Boolean,
|
|
30
|
+
default: void 0
|
|
31
|
+
},
|
|
32
|
+
readonly: {
|
|
33
|
+
type: Boolean,
|
|
34
|
+
default: false
|
|
35
|
+
},
|
|
36
|
+
language: { default: void 0 },
|
|
37
|
+
extensions: {},
|
|
38
|
+
diagnostics: {},
|
|
39
|
+
closeBrackets: {
|
|
40
|
+
type: Boolean,
|
|
41
|
+
default: true
|
|
42
|
+
},
|
|
43
|
+
tabSize: {},
|
|
44
|
+
keymap: {},
|
|
45
|
+
teleport: {
|
|
46
|
+
type: [String, Boolean],
|
|
47
|
+
default: void 0
|
|
48
|
+
},
|
|
49
|
+
keys: {
|
|
50
|
+
type: [Boolean, Array],
|
|
51
|
+
default: false
|
|
52
|
+
},
|
|
53
|
+
messages: { default: void 0 },
|
|
54
|
+
autofocus: { type: Boolean },
|
|
55
|
+
ariaLabel: {}
|
|
56
|
+
},
|
|
57
|
+
emits: [
|
|
58
|
+
"update:modelValue",
|
|
59
|
+
"enter",
|
|
60
|
+
"transaction",
|
|
61
|
+
"focus",
|
|
62
|
+
"blur"
|
|
63
|
+
],
|
|
64
|
+
setup(__props, { expose: __expose, emit: __emit }) {
|
|
65
|
+
const props = __props;
|
|
66
|
+
const emit = __emit;
|
|
67
|
+
const ns = useNamespace("code-input");
|
|
68
|
+
const attrs = useAttrs();
|
|
69
|
+
const { formItem } = useFormItem();
|
|
70
|
+
const size = useFormSize(() => props.size);
|
|
71
|
+
const disabled = useFormDisabled(() => props.disabled);
|
|
72
|
+
const readonly = useFormReadonly(() => props.readonly);
|
|
73
|
+
const invalid = computed(() => props.invalid || !!formItem?.invalid.value);
|
|
74
|
+
const editor = ref();
|
|
75
|
+
const root = ref();
|
|
76
|
+
function submit() {
|
|
77
|
+
emit("enter");
|
|
78
|
+
return true;
|
|
79
|
+
}
|
|
80
|
+
const keymap = computed(() => {
|
|
81
|
+
return {
|
|
82
|
+
...props.multiline ? { "mod+enter": submit } : {
|
|
83
|
+
enter: submit,
|
|
84
|
+
"shift+enter": submit,
|
|
85
|
+
"mod+enter": submit
|
|
86
|
+
},
|
|
87
|
+
...props.keymap
|
|
88
|
+
};
|
|
89
|
+
});
|
|
90
|
+
/** One line only: line breaks typed, pasted or dropped become spaces. */
|
|
91
|
+
const flatten = (text) => text.replace(/[ \t]*\r?\n[ \t]*/g, " ");
|
|
92
|
+
function onPaste(event) {
|
|
93
|
+
if (props.multiline || !editor.value) return;
|
|
94
|
+
const text = event.clipboardData?.getData("text/plain") ?? "";
|
|
95
|
+
if (!/[\r\n]/.test(text)) return;
|
|
96
|
+
event.preventDefault();
|
|
97
|
+
event.stopPropagation();
|
|
98
|
+
editor.value.transact((tr) => tr.replaceSelection(flatten(text)), {
|
|
99
|
+
action: "paste",
|
|
100
|
+
scroll: true
|
|
101
|
+
});
|
|
102
|
+
}
|
|
103
|
+
function onBeforeInput(event) {
|
|
104
|
+
if (props.multiline) return;
|
|
105
|
+
if (event.inputType !== "insertLineBreak" && event.inputType !== "insertParagraph") return;
|
|
106
|
+
event.preventDefault();
|
|
107
|
+
event.stopPropagation();
|
|
108
|
+
emit("enter");
|
|
109
|
+
}
|
|
110
|
+
function onTransaction(result) {
|
|
111
|
+
emit("transaction", result);
|
|
112
|
+
if (props.multiline || result.meta.action === "external" || result.state.doc.lines < 2) return;
|
|
113
|
+
const text = result.state.doc.toString();
|
|
114
|
+
editor.value?.transact((tr) => tr.replace(0, text.length, flatten(text)), { history: false });
|
|
115
|
+
}
|
|
116
|
+
watchEffect(() => {
|
|
117
|
+
const textarea = root.value?.querySelector("textarea");
|
|
118
|
+
if (!textarea) return;
|
|
119
|
+
const set = (name, value) => value === void 0 ? textarea.removeAttribute(name) : textarea.setAttribute(name, value);
|
|
120
|
+
set("id", attrs.id ?? formItem?.inputId);
|
|
121
|
+
set("aria-describedby", attrs["aria-describedby"] ?? formItem?.describedBy.value);
|
|
122
|
+
set("aria-required", formItem?.required.value ? "true" : void 0);
|
|
123
|
+
set("aria-invalid", invalid.value ? "true" : void 0);
|
|
124
|
+
set("enterkeyhint", props.multiline ? "enter" : "done");
|
|
125
|
+
});
|
|
126
|
+
const height = computed(() => {
|
|
127
|
+
if (!props.multiline) return void 0;
|
|
128
|
+
const min = Math.max(1, props.autosize.minRows ?? 1);
|
|
129
|
+
return {
|
|
130
|
+
"--dou-code-input-min-rows": min,
|
|
131
|
+
"--dou-code-input-max-rows": Math.max(min, props.autosize.maxRows ?? 6)
|
|
132
|
+
};
|
|
133
|
+
});
|
|
134
|
+
const EXPOSED = [
|
|
135
|
+
"state",
|
|
136
|
+
"doc",
|
|
137
|
+
"selection",
|
|
138
|
+
"transact",
|
|
139
|
+
"run",
|
|
140
|
+
"undo",
|
|
141
|
+
"redo",
|
|
142
|
+
"canUndo",
|
|
143
|
+
"canRedo",
|
|
144
|
+
"select",
|
|
145
|
+
"scrollIntoView",
|
|
146
|
+
"coordsAtPos",
|
|
147
|
+
"posAtCoords",
|
|
148
|
+
"focus",
|
|
149
|
+
"blur",
|
|
150
|
+
"openSearch",
|
|
151
|
+
"closeSearch",
|
|
152
|
+
"fold",
|
|
153
|
+
"unfold",
|
|
154
|
+
"foldAll",
|
|
155
|
+
"unfoldAll",
|
|
156
|
+
"folds",
|
|
157
|
+
"diagnostics"
|
|
158
|
+
];
|
|
159
|
+
const exposed = {};
|
|
160
|
+
for (const key of EXPOSED) Object.defineProperty(exposed, key, {
|
|
161
|
+
enumerable: true,
|
|
162
|
+
get: () => editor.value?.[key]
|
|
163
|
+
});
|
|
164
|
+
__expose(exposed);
|
|
165
|
+
return (_ctx, _cache) => {
|
|
166
|
+
return openBlock(), createElementBlock("div", {
|
|
167
|
+
ref_key: "root",
|
|
168
|
+
ref: root,
|
|
169
|
+
class: normalizeClass([
|
|
170
|
+
unref(ns).b(),
|
|
171
|
+
unref(ns).m(unref(size)),
|
|
172
|
+
unref(ns).is("multiline", __props.multiline),
|
|
173
|
+
unref(ns).is("invalid", invalid.value),
|
|
174
|
+
unref(ns).is("disabled", unref(disabled)),
|
|
175
|
+
unref(attrs).class
|
|
176
|
+
]),
|
|
177
|
+
style: normalizeStyle([unref(attrs).style, height.value]),
|
|
178
|
+
onPasteCapture: onPaste,
|
|
179
|
+
onBeforeinputCapture: onBeforeInput
|
|
180
|
+
}, [createVNode(code_editor_default, {
|
|
181
|
+
ref_key: "editor",
|
|
182
|
+
ref: editor,
|
|
183
|
+
"model-value": __props.modelValue,
|
|
184
|
+
placeholder: __props.placeholder,
|
|
185
|
+
disabled: unref(disabled),
|
|
186
|
+
readonly: unref(readonly),
|
|
187
|
+
language: __props.language,
|
|
188
|
+
extensions: __props.extensions,
|
|
189
|
+
diagnostics: __props.diagnostics,
|
|
190
|
+
"close-brackets": __props.closeBrackets,
|
|
191
|
+
"tab-size": __props.tabSize,
|
|
192
|
+
messages: __props.messages,
|
|
193
|
+
keys: __props.keys,
|
|
194
|
+
keymap: keymap.value,
|
|
195
|
+
teleport: __props.teleport,
|
|
196
|
+
"aria-label": __props.ariaLabel,
|
|
197
|
+
autofocus: __props.autofocus,
|
|
198
|
+
gutter: false,
|
|
199
|
+
"active-line": false,
|
|
200
|
+
foldable: false,
|
|
201
|
+
searchable: false,
|
|
202
|
+
"tab-indents": false,
|
|
203
|
+
wrap: __props.multiline,
|
|
204
|
+
"onUpdate:modelValue": _cache[0] || (_cache[0] = (value) => {
|
|
205
|
+
emit("update:modelValue", value);
|
|
206
|
+
unref(formItem)?.trigger("change", { lazy: true });
|
|
207
|
+
}),
|
|
208
|
+
onTransaction,
|
|
209
|
+
onFocus: _cache[1] || (_cache[1] = ($event) => emit("focus", $event)),
|
|
210
|
+
onBlur: _cache[2] || (_cache[2] = (event) => {
|
|
211
|
+
emit("blur", event);
|
|
212
|
+
unref(formItem)?.trigger("blur");
|
|
213
|
+
})
|
|
214
|
+
}, null, 8, [
|
|
215
|
+
"model-value",
|
|
216
|
+
"placeholder",
|
|
217
|
+
"disabled",
|
|
218
|
+
"readonly",
|
|
219
|
+
"language",
|
|
220
|
+
"extensions",
|
|
221
|
+
"diagnostics",
|
|
222
|
+
"close-brackets",
|
|
223
|
+
"tab-size",
|
|
224
|
+
"messages",
|
|
225
|
+
"keys",
|
|
226
|
+
"keymap",
|
|
227
|
+
"teleport",
|
|
228
|
+
"aria-label",
|
|
229
|
+
"autofocus",
|
|
230
|
+
"wrap"
|
|
231
|
+
])], 38);
|
|
232
|
+
};
|
|
233
|
+
}
|
|
234
|
+
});
|
|
235
|
+
export { code_input_vue_vue_type_script_setup_true_lang_default as default };
|
|
236
|
+
|
|
237
|
+
//# sourceMappingURL=code-input.vue_vue_type_script_setup_true_lang.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"code-input.vue_vue_type_script_setup_true_lang.js","names":["_openBlock","_createElementBlock","_normalizeClass","_unref","_normalizeStyle","_createVNode","CodeEditor"],"sources":["../src/code-input.vue"],"sourcesContent":["<script setup lang=\"ts\">\nimport { computed, ref, useAttrs, watchEffect } from 'vue'\nimport type { StyleValue } from 'vue'\nimport { useFormDisabled, useFormItem, useFormReadonly, useFormSize, useNamespace } from 'dou-ui'\nimport CodeEditor from './code-editor.vue'\nimport type { CodeKeymap } from './core/keymap'\nimport type { CodeTransactionResult } from './core/transaction'\nimport type { CodeEditorExpose, CodeInputEmits, CodeInputProps } from './types'\n\n/**\n * A code box the size of a text input, for expressions and formulas: one\n * line (or a few, with `multiline`), highlighted, with the editor's\n * completions and problems. Inside a form item it takes the item's id,\n * description and state, as DouInput does.\n */\ndefineOptions({ name: 'DouCodeInput', inheritAttrs: false })\n\nconst props = withDefaults(defineProps<CodeInputProps>(), {\n modelValue: '',\n multiline: false,\n autosize: () => ({}),\n invalid: false,\n disabled: undefined,\n readonly: false,\n language: undefined,\n closeBrackets: true,\n teleport: undefined,\n keys: false,\n messages: undefined,\n})\nconst emit = defineEmits<CodeInputEmits>()\n\nconst ns = useNamespace('code-input')\nconst attrs = useAttrs()\nconst { formItem } = useFormItem()\nconst size = useFormSize(() => props.size)\nconst disabled = useFormDisabled(() => props.disabled)\nconst readonly = useFormReadonly(() => props.readonly)\nconst invalid = computed(() => props.invalid || !!formItem?.invalid.value)\n\nconst editor = ref<CodeEditorExpose>()\nconst root = ref<HTMLElement>()\n\nfunction submit() {\n emit('enter')\n return true\n}\n\nconst keymap = computed<CodeKeymap>(() => {\n // One line: Enter hands over to the form. Several: Mod + Enter does.\n const own: CodeKeymap = props.multiline\n ? { 'mod+enter': submit }\n : { enter: submit, 'shift+enter': submit, 'mod+enter': submit }\n return { ...own, ...props.keymap }\n})\n\n/** One line only: line breaks typed, pasted or dropped become spaces. */\nconst flatten = (text: string) => text.replace(/[ \\t]*\\r?\\n[ \\t]*/g, ' ')\n\nfunction onPaste(event: ClipboardEvent) {\n if (props.multiline || !editor.value) return\n const text = event.clipboardData?.getData('text/plain') ?? ''\n if (!/[\\r\\n]/.test(text)) return\n event.preventDefault()\n event.stopPropagation()\n editor.value.transact((tr) => tr.replaceSelection(flatten(text)), {\n action: 'paste',\n scroll: true,\n })\n}\n\n// A phone's Enter key may come as input with no key event before it.\nfunction onBeforeInput(event: InputEvent) {\n if (props.multiline) return\n if (event.inputType !== 'insertLineBreak' && event.inputType !== 'insertParagraph') return\n event.preventDefault()\n event.stopPropagation()\n emit('enter')\n}\n\nfunction onTransaction(result: CodeTransactionResult) {\n emit('transaction', result)\n // Whatever else brought a line break in (a drop, an extension): one line again.\n if (props.multiline || result.meta.action === 'external' || result.state.doc.lines < 2) return\n const text = result.state.doc.toString()\n editor.value?.transact((tr) => tr.replace(0, text.length, flatten(text)), { history: false })\n}\n\n// The textarea is the control a label and a form item point at.\nwatchEffect(() => {\n const textarea = root.value?.querySelector('textarea')\n if (!textarea) return\n const set = (name: string, value: string | undefined) =>\n value === undefined ? textarea.removeAttribute(name) : textarea.setAttribute(name, value)\n set('id', (attrs.id as string | undefined) ?? formItem?.inputId)\n set(\n 'aria-describedby',\n (attrs['aria-describedby'] as string | undefined) ?? formItem?.describedBy.value,\n )\n set('aria-required', formItem?.required.value ? 'true' : undefined)\n set('aria-invalid', invalid.value ? 'true' : undefined)\n set('enterkeyhint', props.multiline ? 'enter' : 'done')\n})\n\nconst height = computed(() => {\n if (!props.multiline) return undefined\n const min = Math.max(1, props.autosize.minRows ?? 1)\n const max = Math.max(min, props.autosize.maxRows ?? 6)\n return { '--dou-code-input-min-rows': min, '--dou-code-input-max-rows': max }\n})\n\n// The same instance as the editor's.\nconst EXPOSED = [\n 'state',\n 'doc',\n 'selection',\n 'transact',\n 'run',\n 'undo',\n 'redo',\n 'canUndo',\n 'canRedo',\n 'select',\n 'scrollIntoView',\n 'coordsAtPos',\n 'posAtCoords',\n 'focus',\n 'blur',\n 'openSearch',\n 'closeSearch',\n 'fold',\n 'unfold',\n 'foldAll',\n 'unfoldAll',\n 'folds',\n 'diagnostics',\n] as const\nconst exposed = {} as CodeEditorExpose\nfor (const key of EXPOSED)\n Object.defineProperty(exposed, key, {\n enumerable: true,\n get: () => editor.value?.[key],\n })\ndefineExpose(exposed)\n</script>\n\n<template>\n <div\n ref=\"root\"\n :class=\"[\n ns.b(),\n ns.m(size),\n ns.is('multiline', multiline),\n ns.is('invalid', invalid),\n ns.is('disabled', disabled),\n attrs.class,\n ]\"\n :style=\"[attrs.style as StyleValue, height]\"\n @paste.capture=\"onPaste\"\n @beforeinput.capture=\"onBeforeInput\"\n >\n <CodeEditor\n ref=\"editor\"\n :model-value=\"modelValue\"\n :placeholder=\"placeholder\"\n :disabled=\"disabled\"\n :readonly=\"readonly\"\n :language=\"language\"\n :extensions=\"extensions\"\n :diagnostics=\"diagnostics\"\n :close-brackets=\"closeBrackets\"\n :tab-size=\"tabSize\"\n :messages=\"messages\"\n :keys=\"keys\"\n :keymap=\"keymap\"\n :teleport=\"teleport\"\n :aria-label=\"ariaLabel\"\n :autofocus=\"autofocus\"\n :gutter=\"false\"\n :active-line=\"false\"\n :foldable=\"false\"\n :searchable=\"false\"\n :tab-indents=\"false\"\n :wrap=\"multiline\"\n @update:model-value=\"\n (value: string) => {\n emit('update:modelValue', value)\n formItem?.trigger('change', { lazy: true })\n }\n \"\n @transaction=\"onTransaction\"\n @focus=\"emit('focus', $event)\"\n @blur=\"\n (event: FocusEvent) => {\n emit('blur', event)\n formItem?.trigger('blur')\n }\n \"\n />\n </div>\n</template>\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAiBA,MAAM,QAAQ;EAad,MAAM,OAAO;EAEb,MAAM,KAAK,aAAa,YAAY;EACpC,MAAM,QAAQ,SAAS;EACvB,MAAM,EAAE,aAAa,YAAY;EACjC,MAAM,OAAO,kBAAkB,MAAM,IAAI;EACzC,MAAM,WAAW,sBAAsB,MAAM,QAAQ;EACrD,MAAM,WAAW,sBAAsB,MAAM,QAAQ;EACrD,MAAM,UAAU,eAAe,MAAM,WAAW,CAAC,CAAC,UAAU,QAAQ,KAAK;EAEzE,MAAM,SAAS,IAAsB;EACrC,MAAM,OAAO,IAAiB;EAE9B,SAAS,SAAS;GAChB,KAAK,OAAO;GACZ,OAAO;EACT;EAEA,MAAM,SAAS,eAA2B;GAKxC,OAAO;IAAE,GAHe,MAAM,YAC1B,EAAE,aAAa,OAAO,IACtB;KAAE,OAAO;KAAQ,eAAe;KAAQ,aAAa;IAAO;IAC/C,GAAG,MAAM;GAAO;EACnC,CAAC;;EAGD,MAAM,WAAW,SAAiB,KAAK,QAAQ,sBAAsB,GAAG;EAExE,SAAS,QAAQ,OAAuB;GACtC,IAAI,MAAM,aAAa,CAAC,OAAO,OAAO;GACtC,MAAM,OAAO,MAAM,eAAe,QAAQ,YAAY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IACZ,eAAa;IACb,MAAM,QAAA;IACN,uBAAkB,OAAA,OAAA,OAAA,MAAY,UAAa;KAAiB,KAAI,qBAAsB,KAAK;KAAY,MAAA,QAAA,CAAQ,EAAE,QAAO,UAAA,EAAA,MAAA,KAAA,CAAA;;IAM3G;IACb,SAAK,OAAA,OAAA,OAAA,MAAA,WAAE,KAAI,SAAU,MAAM;IAC3B,QAAI,OAAA,OAAA,OAAA,MAAY,UAAiB;KAAiB,KAAI,QAAS,KAAK;KAAY,MAAA,QAAA,CAAQ,EAAE,QAAO,MAAA"}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { insertTab, redo, undo } from "./core/commands.js";
|
|
2
|
+
import { markRaw } from "vue";
|
|
3
|
+
import { RedoIcon, UndoIcon } from "@dou-ui/icons";
|
|
4
|
+
/**
|
|
5
|
+
* The keys of the bar that scroll: Tab, the symbols code is full of, then
|
|
6
|
+
* undo and redo. Spread it to add keys: `[...defaultCodeKeys, { label: '=>', text: ' => ' }]`.
|
|
7
|
+
*/
|
|
8
|
+
var defaultCodeKeys = Object.freeze([
|
|
9
|
+
{
|
|
10
|
+
label: "Tab",
|
|
11
|
+
command: insertTab
|
|
12
|
+
},
|
|
13
|
+
...[..."(){}[]<>=;:,.'\"`/\\|&!?+-*_$#%"].map((ch) => ({ label: ch })),
|
|
14
|
+
{
|
|
15
|
+
label: "Undo",
|
|
16
|
+
icon: markRaw(UndoIcon),
|
|
17
|
+
command: undo,
|
|
18
|
+
repeat: true
|
|
19
|
+
},
|
|
20
|
+
{
|
|
21
|
+
label: "Redo",
|
|
22
|
+
icon: markRaw(RedoIcon),
|
|
23
|
+
command: redo,
|
|
24
|
+
repeat: true
|
|
25
|
+
}
|
|
26
|
+
]);
|
|
27
|
+
/** Names read out for the built-in commands, in the bar's language. */
|
|
28
|
+
var NAMES = /* @__PURE__ */ new Map([
|
|
29
|
+
[insertTab, "indent"],
|
|
30
|
+
[undo, "undo"],
|
|
31
|
+
[redo, "redo"]
|
|
32
|
+
]);
|
|
33
|
+
/** What screen readers read for a key, when its label doesn't say it. */
|
|
34
|
+
function keyName(key, messages) {
|
|
35
|
+
if (key.ariaLabel) return key.ariaLabel;
|
|
36
|
+
const name = key.command && NAMES.get(key.command);
|
|
37
|
+
if (name) return messages[name];
|
|
38
|
+
return key.icon ? key.label : void 0;
|
|
39
|
+
}
|
|
40
|
+
export { defaultCodeKeys, keyName };
|
|
41
|
+
|
|
42
|
+
//# sourceMappingURL=code-keys.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"code-keys.js","names":[],"sources":["../src/code-keys.ts"],"sourcesContent":["import { RedoIcon, UndoIcon } from '@dou-ui/icons'\nimport { markRaw } from 'vue'\nimport { type CodeCommand, insertTab, redo, undo } from './core/commands'\nimport type { CodeMessages } from './locale'\nimport type { CodeKey } from './types'\n\nconst SYMBOLS = '(){}[]<>=;:,.\\'\"`/\\\\|&!?+-*_$#%'\n\n/**\n * The keys of the bar that scroll: Tab, the symbols code is full of, then\n * undo and redo. Spread it to add keys: `[...defaultCodeKeys, { label: '=>', text: ' => ' }]`.\n */\nexport const defaultCodeKeys: readonly CodeKey[] = Object.freeze([\n { label: 'Tab', command: insertTab },\n ...[...SYMBOLS].map((ch) => ({ label: ch })),\n { label: 'Undo', icon: markRaw(UndoIcon), command: undo, repeat: true },\n { label: 'Redo', icon: markRaw(RedoIcon), command: redo, repeat: true },\n])\n\n/** Names read out for the built-in commands, in the bar's language. */\nconst NAMES = new Map<CodeCommand, keyof CodeMessages>([\n [insertTab, 'indent'],\n [undo, 'undo'],\n [redo, 'redo'],\n])\n\n/** What screen readers read for a key, when its label doesn't say it. */\nexport function keyName(key: CodeKey, messages: CodeMessages): string | undefined {\n if (key.ariaLabel) return key.ariaLabel\n const name = key.command && NAMES.get(key.command)\n if (name) return messages[name]\n return key.icon ? key.label : undefined\n}\n"],"mappings":";;;;;;;AAYA,IAAa,kBAAsC,OAAO,OAAO;CAC/D;EAAE,OAAO;EAAO,SAAS;CAAU;CACnC,GAAG,CAAC,GAAG,iCAAO,CAAC,CAAC,KAAK,QAAQ,EAAE,OAAO,GAAG,EAAE;CAC3C;EAAE,OAAO;EAAQ,MAAM,QAAQ,QAAQ;EAAG,SAAS;EAAM,QAAQ;CAAK;CACtE;EAAE,OAAO;EAAQ,MAAM,QAAQ,QAAQ;EAAG,SAAS;EAAM,QAAQ;CAAK;AACxE,CAAC;;AAGD,IAAM,wBAAQ,IAAI,IAAqC;CACrD,CAAC,WAAW,QAAQ;CACpB,CAAC,MAAM,MAAM;CACb,CAAC,MAAM,MAAM;AACf,CAAC;;AAGD,SAAgB,QAAQ,KAAc,UAA4C;CAChF,IAAI,IAAI,WAAW,OAAO,IAAI;CAC9B,MAAM,OAAO,IAAI,WAAW,MAAM,IAAI,IAAI,OAAO;CACjD,IAAI,MAAM,OAAO,SAAS;CAC1B,OAAO,IAAI,OAAO,IAAI,QAAQ,KAAA;AAChC"}
|
|
@@ -0,0 +1,244 @@
|
|
|
1
|
+
import { cursorCharLeft, cursorCharRight, cursorLineDown, cursorLineUp, typeText } from "./core/commands.js";
|
|
2
|
+
import { useCodeMessages } from "./locale.js";
|
|
3
|
+
import { defaultCodeKeys, keyName } from "./code-keys.js";
|
|
4
|
+
import { visibleViewport } from "./view/viewport.js";
|
|
5
|
+
import { useNamespace } from "dou-ui";
|
|
6
|
+
import { Fragment, computed, createBlock, createElementBlock, createElementVNode, createTextVNode, createVNode, defineComponent, normalizeClass, normalizeStyle, onBeforeUnmount, openBlock, ref, renderList, resolveDynamicComponent, toDisplayString, unref, withModifiers } from "vue";
|
|
7
|
+
import { ChevronDownIcon, ChevronLeftIcon, ChevronRightIcon, ChevronUpIcon } from "@dou-ui/icons";
|
|
8
|
+
// src/code-keys.vue?vue&type=script&setup=true&lang.ts
|
|
9
|
+
var _hoisted_1 = ["aria-label"];
|
|
10
|
+
var _hoisted_2 = [
|
|
11
|
+
"aria-label",
|
|
12
|
+
"title",
|
|
13
|
+
"onPointerdown",
|
|
14
|
+
"onClick"
|
|
15
|
+
];
|
|
16
|
+
var _hoisted_3 = ["aria-label", "title"];
|
|
17
|
+
var SLOP = 8;
|
|
18
|
+
var STICK_REACH = 26;
|
|
19
|
+
var STICK_REST = 8;
|
|
20
|
+
var code_keys_vue_vue_type_script_setup_true_lang_default = /*@__PURE__*/ defineComponent({
|
|
21
|
+
name: "DouCodeKeys",
|
|
22
|
+
__name: "code-keys",
|
|
23
|
+
props: {
|
|
24
|
+
editor: { default: void 0 },
|
|
25
|
+
keys: { default: void 0 },
|
|
26
|
+
messages: { default: void 0 }
|
|
27
|
+
},
|
|
28
|
+
setup(__props) {
|
|
29
|
+
const props = __props;
|
|
30
|
+
const ns = useNamespace("code-keys");
|
|
31
|
+
const messages = useCodeMessages(() => props.messages);
|
|
32
|
+
/** Keys that scroll; a string is a key that types itself. */
|
|
33
|
+
const symbolKeys = computed(() => (props.keys ?? defaultCodeKeys).map((key) => typeof key === "string" ? { label: key } : key));
|
|
34
|
+
function fire(key) {
|
|
35
|
+
run(key.command ?? typeText(key.text ?? key.label));
|
|
36
|
+
}
|
|
37
|
+
/** How far a finger may slide on a key before it counts as scrolling the bar. */
|
|
38
|
+
const pressed = ref(null);
|
|
39
|
+
let press = null;
|
|
40
|
+
function stop() {
|
|
41
|
+
if (press) {
|
|
42
|
+
clearTimeout(press.timer);
|
|
43
|
+
clearInterval(press.timer);
|
|
44
|
+
}
|
|
45
|
+
press = null;
|
|
46
|
+
pressed.value = null;
|
|
47
|
+
}
|
|
48
|
+
function onPointerDown(event, key, id) {
|
|
49
|
+
if (event.button !== 0) return;
|
|
50
|
+
stop();
|
|
51
|
+
pressed.value = id;
|
|
52
|
+
press = {
|
|
53
|
+
id,
|
|
54
|
+
key,
|
|
55
|
+
pointer: event.pointerId,
|
|
56
|
+
x: event.clientX,
|
|
57
|
+
y: event.clientY,
|
|
58
|
+
timer: 0,
|
|
59
|
+
fired: false
|
|
60
|
+
};
|
|
61
|
+
if (!key.repeat) return;
|
|
62
|
+
press.timer = window.setTimeout(() => {
|
|
63
|
+
if (!press) return;
|
|
64
|
+
press.fired = true;
|
|
65
|
+
fire(key);
|
|
66
|
+
press.timer = window.setInterval(() => fire(key), 60);
|
|
67
|
+
}, 400);
|
|
68
|
+
}
|
|
69
|
+
function onPointerMove(event) {
|
|
70
|
+
if (!press || event.pointerId !== press.pointer || press.fired) return;
|
|
71
|
+
if (Math.hypot(event.clientX - press.x, event.clientY - press.y) > SLOP) stop();
|
|
72
|
+
}
|
|
73
|
+
function onPointerUp(event) {
|
|
74
|
+
if (!press || event.pointerId !== press.pointer) return;
|
|
75
|
+
const { key, fired } = press;
|
|
76
|
+
stop();
|
|
77
|
+
if (!fired) fire(key);
|
|
78
|
+
}
|
|
79
|
+
function onClick(event, key) {
|
|
80
|
+
if (event.detail === 0) fire(key);
|
|
81
|
+
}
|
|
82
|
+
/**
|
|
83
|
+
* The stick at the end of the bar moves the cursor. Pressed, it grows into a
|
|
84
|
+
* round pad over the bar, the way a number field's keys do, so a thumb has
|
|
85
|
+
* room to lean it: past its rest it steps the way it leans, and the further,
|
|
86
|
+
* the faster. Lifted, it shrinks back.
|
|
87
|
+
*/
|
|
88
|
+
const MOVES = {
|
|
89
|
+
left: cursorCharLeft,
|
|
90
|
+
right: cursorCharRight,
|
|
91
|
+
up: cursorLineUp,
|
|
92
|
+
down: cursorLineDown
|
|
93
|
+
};
|
|
94
|
+
const thumb = ref({
|
|
95
|
+
x: 0,
|
|
96
|
+
y: 0
|
|
97
|
+
});
|
|
98
|
+
const held = ref(false);
|
|
99
|
+
/** How far the pad moves in from the window's edge to fit, in px. */
|
|
100
|
+
const padShift = ref({
|
|
101
|
+
x: 0,
|
|
102
|
+
y: 0
|
|
103
|
+
});
|
|
104
|
+
let stick = null;
|
|
105
|
+
function leanOf(x, y) {
|
|
106
|
+
if (Math.hypot(x, y) < STICK_REST) return null;
|
|
107
|
+
return Math.abs(x) >= Math.abs(y) ? x < 0 ? "left" : "right" : y < 0 ? "up" : "down";
|
|
108
|
+
}
|
|
109
|
+
/** Steps while the stick leans: slowly near its rest, fast pushed all the way and beyond. */
|
|
110
|
+
function stepStick() {
|
|
111
|
+
if (!stick?.lean) return;
|
|
112
|
+
run(MOVES[stick.lean]);
|
|
113
|
+
stick.timer = window.setTimeout(stepStick, 280 - stick.far * 240);
|
|
114
|
+
}
|
|
115
|
+
function onStickDown(event) {
|
|
116
|
+
if (event.button !== 0) return;
|
|
117
|
+
event.preventDefault();
|
|
118
|
+
endStick();
|
|
119
|
+
const el = event.currentTarget;
|
|
120
|
+
el.setPointerCapture?.(event.pointerId);
|
|
121
|
+
const box = el.getBoundingClientRect();
|
|
122
|
+
const cx = box.left + box.width / 2;
|
|
123
|
+
const cy = box.top + box.height / 2;
|
|
124
|
+
const room = 56;
|
|
125
|
+
const view = visibleViewport();
|
|
126
|
+
padShift.value = {
|
|
127
|
+
x: Math.min(0, view.left + view.width - room - cx) + Math.max(0, view.left + room - cx),
|
|
128
|
+
y: Math.min(0, view.top + view.height - room - cy) + Math.max(0, view.top + room - cy)
|
|
129
|
+
};
|
|
130
|
+
held.value = true;
|
|
131
|
+
stick = {
|
|
132
|
+
pointer: event.pointerId,
|
|
133
|
+
x: event.clientX,
|
|
134
|
+
y: event.clientY,
|
|
135
|
+
timer: 0,
|
|
136
|
+
lean: null,
|
|
137
|
+
far: 0
|
|
138
|
+
};
|
|
139
|
+
}
|
|
140
|
+
function onStickMove(event) {
|
|
141
|
+
if (!stick || event.pointerId !== stick.pointer) return;
|
|
142
|
+
const x = event.clientX - stick.x;
|
|
143
|
+
const y = event.clientY - stick.y;
|
|
144
|
+
const d = Math.hypot(x, y);
|
|
145
|
+
const k = d > STICK_REACH ? STICK_REACH / d : 1;
|
|
146
|
+
thumb.value = {
|
|
147
|
+
x: x * k,
|
|
148
|
+
y: y * k
|
|
149
|
+
};
|
|
150
|
+
stick.far = Math.min(1, Math.max(0, d - STICK_REST) / (STICK_REACH * 1.5 - STICK_REST));
|
|
151
|
+
const lean = leanOf(x, y);
|
|
152
|
+
if (lean === stick.lean) return;
|
|
153
|
+
clearTimeout(stick.timer);
|
|
154
|
+
stick.lean = lean;
|
|
155
|
+
stepStick();
|
|
156
|
+
}
|
|
157
|
+
function endStick() {
|
|
158
|
+
if (stick) clearTimeout(stick.timer);
|
|
159
|
+
stick = null;
|
|
160
|
+
held.value = false;
|
|
161
|
+
thumb.value = {
|
|
162
|
+
x: 0,
|
|
163
|
+
y: 0
|
|
164
|
+
};
|
|
165
|
+
}
|
|
166
|
+
/** With the stick focused, the arrow keys move the cursor. */
|
|
167
|
+
function onStickKey(event) {
|
|
168
|
+
const lean = {
|
|
169
|
+
ArrowLeft: "left",
|
|
170
|
+
ArrowRight: "right",
|
|
171
|
+
ArrowUp: "up",
|
|
172
|
+
ArrowDown: "down"
|
|
173
|
+
}[event.key];
|
|
174
|
+
if (!lean) return;
|
|
175
|
+
event.preventDefault();
|
|
176
|
+
run(MOVES[lean], false);
|
|
177
|
+
}
|
|
178
|
+
function run(command, focus = true) {
|
|
179
|
+
const { editor } = props;
|
|
180
|
+
if (!editor) return;
|
|
181
|
+
editor.run(command);
|
|
182
|
+
if (focus) editor.focus?.();
|
|
183
|
+
}
|
|
184
|
+
onBeforeUnmount(() => {
|
|
185
|
+
stop();
|
|
186
|
+
endStick();
|
|
187
|
+
});
|
|
188
|
+
return (_ctx, _cache) => {
|
|
189
|
+
return openBlock(), createElementBlock("div", {
|
|
190
|
+
class: normalizeClass(unref(ns).b()),
|
|
191
|
+
role: "toolbar",
|
|
192
|
+
"aria-label": unref(messages).keys,
|
|
193
|
+
onMousedown: _cache[0] || (_cache[0] = withModifiers(() => {}, ["prevent"])),
|
|
194
|
+
onContextmenu: _cache[1] || (_cache[1] = withModifiers(() => {}, ["prevent"]))
|
|
195
|
+
}, [createElementVNode("div", { class: normalizeClass(unref(ns).e("scroll")) }, [(openBlock(true), createElementBlock(Fragment, null, renderList(symbolKeys.value, (key, i) => {
|
|
196
|
+
return openBlock(), createElementBlock("button", {
|
|
197
|
+
key: `s${i}`,
|
|
198
|
+
type: "button",
|
|
199
|
+
class: normalizeClass([
|
|
200
|
+
unref(ns).e("key"),
|
|
201
|
+
unref(ns).is("pressed", pressed.value === `s${i}`),
|
|
202
|
+
unref(ns).is("icon", !!key.icon)
|
|
203
|
+
]),
|
|
204
|
+
"aria-label": unref(keyName)(key, unref(messages)),
|
|
205
|
+
title: key.icon ? unref(keyName)(key, unref(messages)) : void 0,
|
|
206
|
+
onPointerdown: ($event) => onPointerDown($event, key, `s${i}`),
|
|
207
|
+
onPointermove: onPointerMove,
|
|
208
|
+
onPointerup: onPointerUp,
|
|
209
|
+
onPointercancel: stop,
|
|
210
|
+
onPointerleave: stop,
|
|
211
|
+
onClick: ($event) => onClick($event, key)
|
|
212
|
+
}, [key.icon ? (openBlock(), createBlock(resolveDynamicComponent(key.icon), { key: 0 })) : (openBlock(), createElementBlock(Fragment, { key: 1 }, [createTextVNode(toDisplayString(key.label), 1)], 64))], 42, _hoisted_2);
|
|
213
|
+
}), 128))], 2), createElementVNode("div", { class: normalizeClass(unref(ns).e("arrows")) }, [createElementVNode("button", {
|
|
214
|
+
type: "button",
|
|
215
|
+
class: normalizeClass([unref(ns).e("stick"), unref(ns).is("held", held.value)]),
|
|
216
|
+
"aria-label": unref(messages).moveCursor,
|
|
217
|
+
title: unref(messages).moveCursor,
|
|
218
|
+
"aria-keyshortcuts": "ArrowUp ArrowDown ArrowLeft ArrowRight",
|
|
219
|
+
onPointerdown: onStickDown,
|
|
220
|
+
onPointermove: onStickMove,
|
|
221
|
+
onPointerup: endStick,
|
|
222
|
+
onPointercancel: endStick,
|
|
223
|
+
onLostpointercapture: endStick,
|
|
224
|
+
onKeydown: onStickKey
|
|
225
|
+
}, [createElementVNode("span", {
|
|
226
|
+
class: normalizeClass(unref(ns).e("pad")),
|
|
227
|
+
style: normalizeStyle(held.value ? { translate: `${padShift.value.x}px ${padShift.value.y}px` } : void 0),
|
|
228
|
+
"aria-hidden": "true"
|
|
229
|
+
}, [
|
|
230
|
+
createVNode(unref(ChevronUpIcon), { class: normalizeClass([unref(ns).e("way"), unref(ns).is("up", true)]) }, null, 8, ["class"]),
|
|
231
|
+
createVNode(unref(ChevronRightIcon), { class: normalizeClass([unref(ns).e("way"), unref(ns).is("right", true)]) }, null, 8, ["class"]),
|
|
232
|
+
createVNode(unref(ChevronDownIcon), { class: normalizeClass([unref(ns).e("way"), unref(ns).is("down", true)]) }, null, 8, ["class"]),
|
|
233
|
+
createVNode(unref(ChevronLeftIcon), { class: normalizeClass([unref(ns).e("way"), unref(ns).is("left", true)]) }, null, 8, ["class"]),
|
|
234
|
+
createElementVNode("span", {
|
|
235
|
+
class: normalizeClass(unref(ns).e("thumb")),
|
|
236
|
+
style: normalizeStyle({ transform: `translate(${thumb.value.x}px, ${thumb.value.y}px)` })
|
|
237
|
+
}, null, 6)
|
|
238
|
+
], 6)], 42, _hoisted_3)], 2)], 42, _hoisted_1);
|
|
239
|
+
};
|
|
240
|
+
}
|
|
241
|
+
});
|
|
242
|
+
export { code_keys_vue_vue_type_script_setup_true_lang_default as default };
|
|
243
|
+
|
|
244
|
+
//# sourceMappingURL=code-keys.vue_vue_type_script_setup_true_lang.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"code-keys.vue_vue_type_script_setup_true_lang.js","names":["_openBlock","_createElementBlock","_normalizeClass","_unref","_withModifiers","_createElementVNode","_Fragment","_renderList","_createBlock","_resolveDynamicComponent","_createTextVNode","_toDisplayString","_normalizeStyle","_createVNode"],"sources":["../src/code-keys.vue"],"sourcesContent":["<script setup lang=\"ts\">\nimport { useNamespace } from 'dou-ui'\nimport { ChevronDownIcon, ChevronLeftIcon, ChevronRightIcon, ChevronUpIcon } from '@dou-ui/icons'\nimport { computed, onBeforeUnmount, ref } from 'vue'\nimport {\n type CodeCommand,\n cursorCharLeft,\n cursorCharRight,\n cursorLineDown,\n cursorLineUp,\n typeText,\n} from './core/commands'\nimport { defaultCodeKeys, keyName } from './code-keys'\nimport { useCodeMessages } from './locale'\nimport { visibleViewport } from './view/viewport'\nimport type { CodeKey, CodeKeysProps } from './types'\n\ndefineOptions({ name: 'DouCodeKeys' })\n\nconst props = withDefaults(defineProps<CodeKeysProps>(), {\n editor: undefined,\n keys: undefined,\n messages: undefined,\n})\n\nconst ns = useNamespace('code-keys')\nconst messages = useCodeMessages(() => props.messages)\n\n/** Keys that scroll; a string is a key that types itself. */\nconst symbolKeys = computed<CodeKey[]>(() =>\n (props.keys ?? defaultCodeKeys).map((key) => (typeof key === 'string' ? { label: key } : key)),\n)\n\nfunction fire(key: CodeKey) {\n run(key.command ?? typeText(key.text ?? key.label))\n}\n\n/** How far a finger may slide on a key before it counts as scrolling the bar. */\nconst SLOP = 8\nconst pressed = ref<string | null>(null)\nlet press: {\n id: string\n key: CodeKey\n pointer: number\n x: number\n y: number\n timer: number\n /** It already repeated, so lifting the finger types nothing more. */\n fired: boolean\n} | null = null\n\nfunction stop() {\n if (press) {\n clearTimeout(press.timer)\n clearInterval(press.timer)\n }\n press = null\n pressed.value = null\n}\n\nfunction onPointerDown(event: PointerEvent, key: CodeKey, id: string) {\n if (event.button !== 0) return\n stop()\n pressed.value = id\n press = {\n id,\n key,\n pointer: event.pointerId,\n x: event.clientX,\n y: event.clientY,\n timer: 0,\n fired: false,\n }\n if (!key.repeat) return\n // Held, a key goes on: after a pause, then quickly.\n press.timer = window.setTimeout(() => {\n if (!press) return\n press.fired = true\n fire(key)\n press.timer = window.setInterval(() => fire(key), 60)\n }, 400)\n}\n\nfunction onPointerMove(event: PointerEvent) {\n if (!press || event.pointerId !== press.pointer || press.fired) return\n if (Math.hypot(event.clientX - press.x, event.clientY - press.y) > SLOP) stop()\n}\n\nfunction onPointerUp(event: PointerEvent) {\n if (!press || event.pointerId !== press.pointer) return\n const { key, fired } = press\n stop()\n if (!fired) fire(key)\n}\n\n// A key pressed from the keyboard clicks with no pointer behind it.\nfunction onClick(event: MouseEvent, key: CodeKey) {\n if (event.detail === 0) fire(key)\n}\n\n/**\n * The stick at the end of the bar moves the cursor. Pressed, it grows into a\n * round pad over the bar, the way a number field's keys do, so a thumb has\n * room to lean it: past its rest it steps the way it leans, and the further,\n * the faster. Lifted, it shrinks back.\n */\nconst STICK_REACH = 26\nconst STICK_REST = 8\n/** The pad's radius once grown, and the room it keeps from the window's edge. */\nconst PAD_RADIUS = 52\nconst PAD_MARGIN = 4\nconst MOVES = {\n left: cursorCharLeft,\n right: cursorCharRight,\n up: cursorLineUp,\n down: cursorLineDown,\n} as const\ntype Lean = keyof typeof MOVES\nconst thumb = ref({ x: 0, y: 0 })\nconst held = ref(false)\n/** How far the pad moves in from the window's edge to fit, in px. */\nconst padShift = ref({ x: 0, y: 0 })\nlet stick: {\n pointer: number\n x: number\n y: number\n timer: number\n lean: Lean | null\n far: number\n} | null = null\n\nfunction leanOf(x: number, y: number): Lean | null {\n if (Math.hypot(x, y) < STICK_REST) return null\n return Math.abs(x) >= Math.abs(y) ? (x < 0 ? 'left' : 'right') : y < 0 ? 'up' : 'down'\n}\n\n/** Steps while the stick leans: slowly near its rest, fast pushed all the way and beyond. */\nfunction stepStick() {\n if (!stick?.lean) return\n run(MOVES[stick.lean])\n stick.timer = window.setTimeout(stepStick, 280 - stick.far * 240)\n}\n\nfunction onStickDown(event: PointerEvent) {\n if (event.button !== 0) return\n event.preventDefault()\n endStick()\n const el = event.currentTarget as HTMLElement\n el.setPointerCapture?.(event.pointerId)\n // Grown from its middle, the pad moves in as it grows wherever it would reach past the window's edge.\n const box = el.getBoundingClientRect()\n const cx = box.left + box.width / 2\n const cy = box.top + box.height / 2\n const room = PAD_RADIUS + PAD_MARGIN\n const view = visibleViewport()\n padShift.value = {\n x: Math.min(0, view.left + view.width - room - cx) + Math.max(0, view.left + room - cx),\n y: Math.min(0, view.top + view.height - room - cy) + Math.max(0, view.top + room - cy),\n }\n held.value = true\n stick = {\n pointer: event.pointerId,\n x: event.clientX,\n y: event.clientY,\n timer: 0,\n lean: null,\n far: 0,\n }\n}\n\nfunction onStickMove(event: PointerEvent) {\n if (!stick || event.pointerId !== stick.pointer) return\n const x = event.clientX - stick.x\n const y = event.clientY - stick.y\n const d = Math.hypot(x, y)\n const k = d > STICK_REACH ? STICK_REACH / d : 1\n thumb.value = { x: x * k, y: y * k }\n stick.far = Math.min(1, Math.max(0, d - STICK_REST) / (STICK_REACH * 1.5 - STICK_REST))\n const lean = leanOf(x, y)\n if (lean === stick.lean) return\n clearTimeout(stick.timer)\n stick.lean = lean\n // A new way steps at once, then goes on.\n stepStick()\n}\n\nfunction endStick() {\n if (stick) clearTimeout(stick.timer)\n stick = null\n held.value = false\n thumb.value = { x: 0, y: 0 }\n}\n\n/** With the stick focused, the arrow keys move the cursor. */\nfunction onStickKey(event: KeyboardEvent) {\n const lean = (\n { ArrowLeft: 'left', ArrowRight: 'right', ArrowUp: 'up', ArrowDown: 'down' } as const\n )[event.key as 'ArrowLeft']\n if (!lean) return\n event.preventDefault()\n // From the keyboard, the focus stays on the stick, for the next arrow.\n run(MOVES[lean], false)\n}\n\nfunction run(command: CodeCommand, focus = true) {\n const { editor } = props\n if (!editor) return\n editor.run(command)\n // A key pressed while the editor is away (beside it on a desktop) brings the cursor back into view.\n if (focus) editor.focus?.()\n}\n\nonBeforeUnmount(() => {\n stop()\n endStick()\n})\n</script>\n\n<template>\n <div\n :class=\"ns.b()\"\n role=\"toolbar\"\n :aria-label=\"messages.keys\"\n @mousedown.prevent\n @contextmenu.prevent\n >\n <div :class=\"ns.e('scroll')\">\n <button\n v-for=\"(key, i) in symbolKeys\"\n :key=\"`s${i}`\"\n type=\"button\"\n :class=\"[ns.e('key'), ns.is('pressed', pressed === `s${i}`), ns.is('icon', !!key.icon)]\"\n :aria-label=\"keyName(key, messages)\"\n :title=\"key.icon ? keyName(key, messages) : undefined\"\n @pointerdown=\"onPointerDown($event, key, `s${i}`)\"\n @pointermove=\"onPointerMove\"\n @pointerup=\"onPointerUp\"\n @pointercancel=\"stop\"\n @pointerleave=\"stop\"\n @click=\"onClick($event, key)\"\n >\n <component :is=\"key.icon\" v-if=\"key.icon\" />\n <template v-else>{{ key.label }}</template>\n </button>\n </div>\n <div :class=\"ns.e('arrows')\">\n <button\n type=\"button\"\n :class=\"[ns.e('stick'), ns.is('held', held)]\"\n :aria-label=\"messages.moveCursor\"\n :title=\"messages.moveCursor\"\n aria-keyshortcuts=\"ArrowUp ArrowDown ArrowLeft ArrowRight\"\n @pointerdown=\"onStickDown\"\n @pointermove=\"onStickMove\"\n @pointerup=\"endStick\"\n @pointercancel=\"endStick\"\n @lostpointercapture=\"endStick\"\n @keydown=\"onStickKey\"\n >\n <span\n :class=\"ns.e('pad')\"\n :style=\"held ? { translate: `${padShift.x}px ${padShift.y}px` } : undefined\"\n aria-hidden=\"true\"\n >\n <ChevronUpIcon :class=\"[ns.e('way'), ns.is('up', true)]\" />\n <ChevronRightIcon :class=\"[ns.e('way'), ns.is('right', true)]\" />\n <ChevronDownIcon :class=\"[ns.e('way'), ns.is('down', true)]\" />\n <ChevronLeftIcon :class=\"[ns.e('way'), ns.is('left', true)]\" />\n <span\n :class=\"ns.e('thumb')\"\n :style=\"{ transform: `translate(${thumb.x}px, ${thumb.y}px)` }\"\n />\n </span>\n </button>\n </div>\n </div>\n</template>\n"],"mappings":";;;;;;;;;;;;;;;;AAsCA,IAAM,OAAO;AAoEb,IAAM,cAAc;AACpB,IAAM,aAAa;;;;;;;;;;EAxFnB,MAAM,QAAQ;EAMd,MAAM,KAAK,aAAa,WAAW;EACnC,MAAM,WAAW,sBAAsB,MAAM,QAAQ;;EAGrD,MAAM,aAAa,gBAChB,MAAM,QAAQ,gBAAA,CAAiB,KAAK,QAAS,OAAO,QAAQ,WAAW,EAAE,OAAO,IAAI,IAAI,GAAI,CAC/F;EAEA,SAAS,KAAK,KAAc;GAC1B,IAAI,IAAI,WAAW,SAAS,IAAI,QAAQ,IAAI,KAAK,CAAC;EACpD;;EAIA,MAAM,UAAU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IACf,sBAAoB;IACpB,WAAS;G,IAEVE,mBAaO,QAAA;IAZJ,OAAKH,eAAEC,MAAA,EAAA,CAAE,CAAC,EAAC,KAAA,CAAA;IACX,OAAKS,eAAE,KAAA,QAAI,EAAA,WAAA,GAAmB,SAAA,MAAS,EAAC,KAAM,SAAA,MAAS,EAAC,IAAA,IAAS,KAAA,CAAS;IAC3E,eAAY;;IAEZC,YAA2DV,MAAA,aAAA,GAAA,EAA3C,OAAKD,eAAA,CAAGC,MAAA,EAAA,CAAE,CAAC,EAAC,KAAA,GAASA,MAAA,EAAA,CAAE,CAAC,GAAE,MAAA,IAAA,CAAA,CAAA,E;IAC1CU,YAAiEV,MAAA,gBAAA,GAAA,EAA9C,OAAKD,eAAA,CAAGC,MAAA,EAAA,CAAE,CAAC,EAAC,KAAA,GAASA,MAAA,EAAA,CAAE,CAAC,GAAE,SAAA,IAAA,CAAA,CAAA,E;IAC7CU,YAA+DV,MAAA,eAAA,GAAA,EAA7C,OAAKD,eAAA,CAAGC,MAAA,EAAA,CAAE,CAAC,EAAC,KAAA,GAASA,MAAA,EAAA,CAAE,CAAC,GAAE,QAAA,IAAA,CAAA,CAAA,E;IAC5CU,YAA+DV,MAAA,eAAA,GAAA,EAA7C,OAAKD,eAAA,CAAGC,MAAA,EAAA,CAAE,CAAC,EAAC,KAAA,GAASA,MAAA,EAAA,CAAE,CAAC,GAAE,QAAA,IAAA,CAAA,CAAA,E;IAC5CE,mBAGE,QAAA;KAFC,OAAKH,eAAEC,MAAA,EAAA,CAAE,CAAC,EAAC,OAAA,CAAA;KACX,OAAKS,eAAA,EAAA,WAAA,aAA4B,MAAA,MAAM,EAAC,MAAO,MAAA,MAAM,EAAC,KAAA,CAAA"}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import code_keys_vue_vue_type_script_setup_true_lang_default from "./code-keys.vue_vue_type_script_setup_true_lang.js";
|
|
2
|
+
// src/code-keys.vue
|
|
3
|
+
var code_keys_default = code_keys_vue_vue_type_script_setup_true_lang_default;
|
|
4
|
+
export { code_keys_default as default };
|
|
5
|
+
|
|
6
|
+
//# sourceMappingURL=code-keys2.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"code-keys2.js","names":["_sfc_main"],"sources":["../src/code-keys.vue"],"sourcesContent":["<script setup lang=\"ts\">\nimport { useNamespace } from 'dou-ui'\nimport { ChevronDownIcon, ChevronLeftIcon, ChevronRightIcon, ChevronUpIcon } from '@dou-ui/icons'\nimport { computed, onBeforeUnmount, ref } from 'vue'\nimport {\n type CodeCommand,\n cursorCharLeft,\n cursorCharRight,\n cursorLineDown,\n cursorLineUp,\n typeText,\n} from './core/commands'\nimport { defaultCodeKeys, keyName } from './code-keys'\nimport { useCodeMessages } from './locale'\nimport { visibleViewport } from './view/viewport'\nimport type { CodeKey, CodeKeysProps } from './types'\n\ndefineOptions({ name: 'DouCodeKeys' })\n\nconst props = withDefaults(defineProps<CodeKeysProps>(), {\n editor: undefined,\n keys: undefined,\n messages: undefined,\n})\n\nconst ns = useNamespace('code-keys')\nconst messages = useCodeMessages(() => props.messages)\n\n/** Keys that scroll; a string is a key that types itself. */\nconst symbolKeys = computed<CodeKey[]>(() =>\n (props.keys ?? defaultCodeKeys).map((key) => (typeof key === 'string' ? { label: key } : key)),\n)\n\nfunction fire(key: CodeKey) {\n run(key.command ?? typeText(key.text ?? key.label))\n}\n\n/** How far a finger may slide on a key before it counts as scrolling the bar. */\nconst SLOP = 8\nconst pressed = ref<string | null>(null)\nlet press: {\n id: string\n key: CodeKey\n pointer: number\n x: number\n y: number\n timer: number\n /** It already repeated, so lifting the finger types nothing more. */\n fired: boolean\n} | null = null\n\nfunction stop() {\n if (press) {\n clearTimeout(press.timer)\n clearInterval(press.timer)\n }\n press = null\n pressed.value = null\n}\n\nfunction onPointerDown(event: PointerEvent, key: CodeKey, id: string) {\n if (event.button !== 0) return\n stop()\n pressed.value = id\n press = {\n id,\n key,\n pointer: event.pointerId,\n x: event.clientX,\n y: event.clientY,\n timer: 0,\n fired: false,\n }\n if (!key.repeat) return\n // Held, a key goes on: after a pause, then quickly.\n press.timer = window.setTimeout(() => {\n if (!press) return\n press.fired = true\n fire(key)\n press.timer = window.setInterval(() => fire(key), 60)\n }, 400)\n}\n\nfunction onPointerMove(event: PointerEvent) {\n if (!press || event.pointerId !== press.pointer || press.fired) return\n if (Math.hypot(event.clientX - press.x, event.clientY - press.y) > SLOP) stop()\n}\n\nfunction onPointerUp(event: PointerEvent) {\n if (!press || event.pointerId !== press.pointer) return\n const { key, fired } = press\n stop()\n if (!fired) fire(key)\n}\n\n// A key pressed from the keyboard clicks with no pointer behind it.\nfunction onClick(event: MouseEvent, key: CodeKey) {\n if (event.detail === 0) fire(key)\n}\n\n/**\n * The stick at the end of the bar moves the cursor. Pressed, it grows into a\n * round pad over the bar, the way a number field's keys do, so a thumb has\n * room to lean it: past its rest it steps the way it leans, and the further,\n * the faster. Lifted, it shrinks back.\n */\nconst STICK_REACH = 26\nconst STICK_REST = 8\n/** The pad's radius once grown, and the room it keeps from the window's edge. */\nconst PAD_RADIUS = 52\nconst PAD_MARGIN = 4\nconst MOVES = {\n left: cursorCharLeft,\n right: cursorCharRight,\n up: cursorLineUp,\n down: cursorLineDown,\n} as const\ntype Lean = keyof typeof MOVES\nconst thumb = ref({ x: 0, y: 0 })\nconst held = ref(false)\n/** How far the pad moves in from the window's edge to fit, in px. */\nconst padShift = ref({ x: 0, y: 0 })\nlet stick: {\n pointer: number\n x: number\n y: number\n timer: number\n lean: Lean | null\n far: number\n} | null = null\n\nfunction leanOf(x: number, y: number): Lean | null {\n if (Math.hypot(x, y) < STICK_REST) return null\n return Math.abs(x) >= Math.abs(y) ? (x < 0 ? 'left' : 'right') : y < 0 ? 'up' : 'down'\n}\n\n/** Steps while the stick leans: slowly near its rest, fast pushed all the way and beyond. */\nfunction stepStick() {\n if (!stick?.lean) return\n run(MOVES[stick.lean])\n stick.timer = window.setTimeout(stepStick, 280 - stick.far * 240)\n}\n\nfunction onStickDown(event: PointerEvent) {\n if (event.button !== 0) return\n event.preventDefault()\n endStick()\n const el = event.currentTarget as HTMLElement\n el.setPointerCapture?.(event.pointerId)\n // Grown from its middle, the pad moves in as it grows wherever it would reach past the window's edge.\n const box = el.getBoundingClientRect()\n const cx = box.left + box.width / 2\n const cy = box.top + box.height / 2\n const room = PAD_RADIUS + PAD_MARGIN\n const view = visibleViewport()\n padShift.value = {\n x: Math.min(0, view.left + view.width - room - cx) + Math.max(0, view.left + room - cx),\n y: Math.min(0, view.top + view.height - room - cy) + Math.max(0, view.top + room - cy),\n }\n held.value = true\n stick = {\n pointer: event.pointerId,\n x: event.clientX,\n y: event.clientY,\n timer: 0,\n lean: null,\n far: 0,\n }\n}\n\nfunction onStickMove(event: PointerEvent) {\n if (!stick || event.pointerId !== stick.pointer) return\n const x = event.clientX - stick.x\n const y = event.clientY - stick.y\n const d = Math.hypot(x, y)\n const k = d > STICK_REACH ? STICK_REACH / d : 1\n thumb.value = { x: x * k, y: y * k }\n stick.far = Math.min(1, Math.max(0, d - STICK_REST) / (STICK_REACH * 1.5 - STICK_REST))\n const lean = leanOf(x, y)\n if (lean === stick.lean) return\n clearTimeout(stick.timer)\n stick.lean = lean\n // A new way steps at once, then goes on.\n stepStick()\n}\n\nfunction endStick() {\n if (stick) clearTimeout(stick.timer)\n stick = null\n held.value = false\n thumb.value = { x: 0, y: 0 }\n}\n\n/** With the stick focused, the arrow keys move the cursor. */\nfunction onStickKey(event: KeyboardEvent) {\n const lean = (\n { ArrowLeft: 'left', ArrowRight: 'right', ArrowUp: 'up', ArrowDown: 'down' } as const\n )[event.key as 'ArrowLeft']\n if (!lean) return\n event.preventDefault()\n // From the keyboard, the focus stays on the stick, for the next arrow.\n run(MOVES[lean], false)\n}\n\nfunction run(command: CodeCommand, focus = true) {\n const { editor } = props\n if (!editor) return\n editor.run(command)\n // A key pressed while the editor is away (beside it on a desktop) brings the cursor back into view.\n if (focus) editor.focus?.()\n}\n\nonBeforeUnmount(() => {\n stop()\n endStick()\n})\n</script>\n\n<template>\n <div\n :class=\"ns.b()\"\n role=\"toolbar\"\n :aria-label=\"messages.keys\"\n @mousedown.prevent\n @contextmenu.prevent\n >\n <div :class=\"ns.e('scroll')\">\n <button\n v-for=\"(key, i) in symbolKeys\"\n :key=\"`s${i}`\"\n type=\"button\"\n :class=\"[ns.e('key'), ns.is('pressed', pressed === `s${i}`), ns.is('icon', !!key.icon)]\"\n :aria-label=\"keyName(key, messages)\"\n :title=\"key.icon ? keyName(key, messages) : undefined\"\n @pointerdown=\"onPointerDown($event, key, `s${i}`)\"\n @pointermove=\"onPointerMove\"\n @pointerup=\"onPointerUp\"\n @pointercancel=\"stop\"\n @pointerleave=\"stop\"\n @click=\"onClick($event, key)\"\n >\n <component :is=\"key.icon\" v-if=\"key.icon\" />\n <template v-else>{{ key.label }}</template>\n </button>\n </div>\n <div :class=\"ns.e('arrows')\">\n <button\n type=\"button\"\n :class=\"[ns.e('stick'), ns.is('held', held)]\"\n :aria-label=\"messages.moveCursor\"\n :title=\"messages.moveCursor\"\n aria-keyshortcuts=\"ArrowUp ArrowDown ArrowLeft ArrowRight\"\n @pointerdown=\"onStickDown\"\n @pointermove=\"onStickMove\"\n @pointerup=\"endStick\"\n @pointercancel=\"endStick\"\n @lostpointercapture=\"endStick\"\n @keydown=\"onStickKey\"\n >\n <span\n :class=\"ns.e('pad')\"\n :style=\"held ? { translate: `${padShift.x}px ${padShift.y}px` } : undefined\"\n aria-hidden=\"true\"\n >\n <ChevronUpIcon :class=\"[ns.e('way'), ns.is('up', true)]\" />\n <ChevronRightIcon :class=\"[ns.e('way'), ns.is('right', true)]\" />\n <ChevronDownIcon :class=\"[ns.e('way'), ns.is('down', true)]\" />\n <ChevronLeftIcon :class=\"[ns.e('way'), ns.is('left', true)]\" />\n <span\n :class=\"ns.e('thumb')\"\n :style=\"{ transform: `translate(${thumb.x}px, ${thumb.y}px)` }\"\n />\n </span>\n </button>\n </div>\n </div>\n</template>\n"],"mappings":""}
|