@dou-ui/code 0.0.0-stage → 0.1.0-alpha.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.
Files changed (158) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +10 -2
  3. package/dist/_virtual/_rolldown/runtime.js +12 -0
  4. package/dist/assets/default-BZBMZKf_.js.map +1 -0
  5. package/dist/code-diff.js +6 -0
  6. package/dist/code-diff.js.map +1 -0
  7. package/dist/code-diff.vue_vue_type_script_setup_true_lang.js +792 -0
  8. package/dist/code-diff.vue_vue_type_script_setup_true_lang.js.map +1 -0
  9. package/dist/code-editor.js +6 -0
  10. package/dist/code-editor.js.map +1 -0
  11. package/dist/code-editor.vue_vue_type_script_setup_true_lang.js +4917 -0
  12. package/dist/code-editor.vue_vue_type_script_setup_true_lang.js.map +1 -0
  13. package/dist/code-input.js +6 -0
  14. package/dist/code-input.js.map +1 -0
  15. package/dist/code-input.vue_vue_type_script_setup_true_lang.js +237 -0
  16. package/dist/code-input.vue_vue_type_script_setup_true_lang.js.map +1 -0
  17. package/dist/code-keys.js +42 -0
  18. package/dist/code-keys.js.map +1 -0
  19. package/dist/code-keys.vue_vue_type_script_setup_true_lang.js +168 -0
  20. package/dist/code-keys.vue_vue_type_script_setup_true_lang.js.map +1 -0
  21. package/dist/code-keys2.js +6 -0
  22. package/dist/code-keys2.js.map +1 -0
  23. package/dist/collaboration/index.js +255 -0
  24. package/dist/collaboration/index.js.map +1 -0
  25. package/dist/completion/match.js +55 -0
  26. package/dist/completion/match.js.map +1 -0
  27. package/dist/completion/snippet.js +71 -0
  28. package/dist/completion/snippet.js.map +1 -0
  29. package/dist/core/brackets.js +55 -0
  30. package/dist/core/brackets.js.map +1 -0
  31. package/dist/core/changes.js +185 -0
  32. package/dist/core/changes.js.map +1 -0
  33. package/dist/core/chars.js +130 -0
  34. package/dist/core/chars.js.map +1 -0
  35. package/dist/core/commands.js +910 -0
  36. package/dist/core/commands.js.map +1 -0
  37. package/dist/core/diff.js +215 -0
  38. package/dist/core/diff.js.map +1 -0
  39. package/dist/core/folding.js +87 -0
  40. package/dist/core/folding.js.map +1 -0
  41. package/dist/core/history.js +74 -0
  42. package/dist/core/history.js.map +1 -0
  43. package/dist/core/keymap.js +326 -0
  44. package/dist/core/keymap.js.map +1 -0
  45. package/dist/core/search.js +91 -0
  46. package/dist/core/search.js.map +1 -0
  47. package/dist/core/selection.js +88 -0
  48. package/dist/core/selection.js.map +1 -0
  49. package/dist/core/text.js +320 -0
  50. package/dist/core/text.js.map +1 -0
  51. package/dist/core/transaction.js +98 -0
  52. package/dist/core/transaction.js.map +1 -0
  53. package/dist/extension.js +16 -0
  54. package/dist/extension.js.map +1 -0
  55. package/dist/index.js +38 -0
  56. package/dist/index.js.map +1 -0
  57. package/dist/language/highlighter.js +336 -0
  58. package/dist/language/highlighter.js.map +1 -0
  59. package/dist/language/language.js +138 -0
  60. package/dist/language/language.js.map +1 -0
  61. package/dist/language/stream.js +112 -0
  62. package/dist/language/stream.js.map +1 -0
  63. package/dist/language/to-html.js +36 -0
  64. package/dist/language/to-html.js.map +1 -0
  65. package/dist/language/worker-client.js +198 -0
  66. package/dist/language/worker-client.js.map +1 -0
  67. package/dist/language/worker-protocol.js +48 -0
  68. package/dist/language/worker-protocol.js.map +1 -0
  69. package/dist/languages/css.js +128 -0
  70. package/dist/languages/css.js.map +1 -0
  71. package/dist/languages/html.js +175 -0
  72. package/dist/languages/html.js.map +1 -0
  73. package/dist/languages/javascript.js +300 -0
  74. package/dist/languages/javascript.js.map +1 -0
  75. package/dist/languages/json.js +45 -0
  76. package/dist/languages/json.js.map +1 -0
  77. package/dist/languages/markdown.js +82 -0
  78. package/dist/languages/markdown.js.map +1 -0
  79. package/dist/languages/python.js +88 -0
  80. package/dist/languages/python.js.map +1 -0
  81. package/dist/languages/shell.js +153 -0
  82. package/dist/languages/shell.js.map +1 -0
  83. package/dist/languages/sql.js +91 -0
  84. package/dist/languages/sql.js.map +1 -0
  85. package/dist/languages/yaml.js +85 -0
  86. package/dist/languages/yaml.js.map +1 -0
  87. package/dist/locale.js +164 -0
  88. package/dist/locale.js.map +1 -0
  89. package/dist/lsp/index.js +715 -0
  90. package/dist/lsp/index.js.map +1 -0
  91. package/dist/lsp/markup.js +139 -0
  92. package/dist/lsp/markup.js.map +1 -0
  93. package/dist/render-part.js +14 -0
  94. package/dist/render-part.js.map +1 -0
  95. package/dist/shiki/index.js +140 -0
  96. package/dist/shiki/index.js.map +1 -0
  97. package/dist/style.css +1 -0
  98. package/dist/style.d.ts +1 -0
  99. package/dist/style.js +4 -0
  100. package/dist/types/code-diff.vue.d.ts +45 -0
  101. package/dist/types/code-editor.vue.d.ts +43 -0
  102. package/dist/types/code-input.vue.d.ts +32 -0
  103. package/dist/types/code-keys.d.ts +9 -0
  104. package/dist/types/code-keys.vue.d.ts +8 -0
  105. package/dist/types/collaboration/index.d.ts +36 -0
  106. package/dist/types/completion/match.d.ts +13 -0
  107. package/dist/types/completion/snippet.d.ts +17 -0
  108. package/dist/types/core/brackets.d.ts +15 -0
  109. package/dist/types/core/changes.d.ts +52 -0
  110. package/dist/types/core/chars.d.ts +24 -0
  111. package/dist/types/core/commands.d.ts +199 -0
  112. package/dist/types/core/diff.d.ts +52 -0
  113. package/dist/types/core/folding.d.ts +23 -0
  114. package/dist/types/core/history.d.ts +24 -0
  115. package/dist/types/core/keymap.d.ts +29 -0
  116. package/dist/types/core/search.d.ts +37 -0
  117. package/dist/types/core/selection.d.ts +28 -0
  118. package/dist/types/core/text.d.ts +79 -0
  119. package/dist/types/core/transaction.d.ts +65 -0
  120. package/dist/types/extension.d.ts +321 -0
  121. package/dist/types/index.d.ts +159 -0
  122. package/dist/types/language/highlighter.d.ts +99 -0
  123. package/dist/types/language/language.d.ts +100 -0
  124. package/dist/types/language/stream.d.ts +56 -0
  125. package/dist/types/language/to-html.d.ts +17 -0
  126. package/dist/types/language/worker-client.d.ts +52 -0
  127. package/dist/types/language/worker-protocol.d.ts +50 -0
  128. package/dist/types/languages/css.d.ts +17 -0
  129. package/dist/types/languages/html.d.ts +34 -0
  130. package/dist/types/languages/javascript.d.ts +29 -0
  131. package/dist/types/languages/json.d.ts +7 -0
  132. package/dist/types/languages/markdown.d.ts +17 -0
  133. package/dist/types/languages/python.d.ts +9 -0
  134. package/dist/types/languages/shell.d.ts +11 -0
  135. package/dist/types/languages/sql.d.ts +9 -0
  136. package/dist/types/languages/yaml.d.ts +14 -0
  137. package/dist/types/locale.d.ts +79 -0
  138. package/dist/types/lsp/index.d.ts +119 -0
  139. package/dist/types/lsp/markup.d.ts +14 -0
  140. package/dist/types/render-part.d.ts +14 -0
  141. package/dist/types/shiki/index.d.ts +63 -0
  142. package/dist/types/types.d.ts +267 -0
  143. package/dist/types/view/input.d.ts +12 -0
  144. package/dist/types/view/layout.d.ts +55 -0
  145. package/dist/types/view/measure.d.ts +22 -0
  146. package/dist/types/worker/default.d.ts +1 -0
  147. package/dist/types/worker/index.d.ts +34 -0
  148. package/dist/view/input.js +27 -0
  149. package/dist/view/input.js.map +1 -0
  150. package/dist/view/layout.js +194 -0
  151. package/dist/view/layout.js.map +1 -0
  152. package/dist/view/measure.js +104 -0
  153. package/dist/view/measure.js.map +1 -0
  154. package/dist/worker/default.js +20 -0
  155. package/dist/worker/default.js.map +1 -0
  156. package/dist/worker/index.js +139 -0
  157. package/dist/worker/index.js.map +1 -0
  158. 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,KAAK;GAC3D,IAAI,CAAC,SAAS,KAAK,IAAI,GAAG;GAC1B,MAAM,eAAe;GACrB,MAAM,gBAAgB;GACtB,OAAO,MAAM,UAAU,OAAO,GAAG,iBAAiB,QAAQ,IAAI,CAAC,GAAG;IAChE,QAAQ;IACR,QAAQ;GACV,CAAC;EACH;EAGA,SAAS,cAAc,OAAmB;GACxC,IAAI,MAAM,WAAW;GACrB,IAAI,MAAM,cAA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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,168 @@
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 { useNamespace } from "dou-ui";
5
+ import { Fragment, computed, createBlock, createElementBlock, createElementVNode, createTextVNode, defineComponent, normalizeClass, onBeforeUnmount, openBlock, ref, renderList, resolveDynamicComponent, toDisplayString, unref, withModifiers } from "vue";
6
+ import { ChevronDownIcon, ChevronLeftIcon, ChevronRightIcon, ChevronUpIcon } from "@dou-ui/icons";
7
+ // src/code-keys.vue?vue&type=script&setup=true&lang.ts
8
+ var _hoisted_1 = ["aria-label"];
9
+ var _hoisted_2 = [
10
+ "aria-label",
11
+ "title",
12
+ "onPointerdown",
13
+ "onClick"
14
+ ];
15
+ var _hoisted_3 = [
16
+ "aria-label",
17
+ "title",
18
+ "onPointerdown",
19
+ "onClick"
20
+ ];
21
+ var SLOP = 8;
22
+ var code_keys_vue_vue_type_script_setup_true_lang_default = /*@__PURE__*/ defineComponent({
23
+ name: "DouCodeKeys",
24
+ __name: "code-keys",
25
+ props: {
26
+ editor: { default: void 0 },
27
+ keys: { default: void 0 },
28
+ messages: { default: void 0 }
29
+ },
30
+ setup(__props) {
31
+ const props = __props;
32
+ const ns = useNamespace("code-keys");
33
+ const messages = useCodeMessages(() => props.messages);
34
+ /** Keys that scroll; a string is a key that types itself. */
35
+ const symbolKeys = computed(() => (props.keys ?? defaultCodeKeys).map((key) => typeof key === "string" ? { label: key } : key));
36
+ /** Moving the cursor, always at hand at the end of the bar. */
37
+ const arrowKeys = computed(() => {
38
+ const m = messages.value;
39
+ return [
40
+ {
41
+ label: m.cursorLeft,
42
+ icon: ChevronLeftIcon,
43
+ command: cursorCharLeft,
44
+ repeat: true
45
+ },
46
+ {
47
+ label: m.cursorUp,
48
+ icon: ChevronUpIcon,
49
+ command: cursorLineUp,
50
+ repeat: true
51
+ },
52
+ {
53
+ label: m.cursorDown,
54
+ icon: ChevronDownIcon,
55
+ command: cursorLineDown,
56
+ repeat: true
57
+ },
58
+ {
59
+ label: m.cursorRight,
60
+ icon: ChevronRightIcon,
61
+ command: cursorCharRight,
62
+ repeat: true
63
+ }
64
+ ];
65
+ });
66
+ function fire(key) {
67
+ const command = key.command ?? typeText(key.text ?? key.label);
68
+ const { editor } = props;
69
+ if (!editor) return;
70
+ editor.run(command);
71
+ editor.focus?.();
72
+ }
73
+ /** How far a finger may slide on a key before it counts as scrolling the bar. */
74
+ const pressed = ref(null);
75
+ let press = null;
76
+ function stop() {
77
+ if (press) {
78
+ clearTimeout(press.timer);
79
+ clearInterval(press.timer);
80
+ }
81
+ press = null;
82
+ pressed.value = null;
83
+ }
84
+ function onPointerDown(event, key, id) {
85
+ if (event.button !== 0) return;
86
+ stop();
87
+ pressed.value = id;
88
+ press = {
89
+ id,
90
+ key,
91
+ pointer: event.pointerId,
92
+ x: event.clientX,
93
+ y: event.clientY,
94
+ timer: 0,
95
+ fired: false
96
+ };
97
+ if (!key.repeat) return;
98
+ press.timer = window.setTimeout(() => {
99
+ if (!press) return;
100
+ press.fired = true;
101
+ fire(key);
102
+ press.timer = window.setInterval(() => fire(key), 60);
103
+ }, 400);
104
+ }
105
+ function onPointerMove(event) {
106
+ if (!press || event.pointerId !== press.pointer || press.fired) return;
107
+ if (Math.hypot(event.clientX - press.x, event.clientY - press.y) > SLOP) stop();
108
+ }
109
+ function onPointerUp(event) {
110
+ if (!press || event.pointerId !== press.pointer) return;
111
+ const { key, fired } = press;
112
+ stop();
113
+ if (!fired) fire(key);
114
+ }
115
+ function onClick(event, key) {
116
+ if (event.detail === 0) fire(key);
117
+ }
118
+ onBeforeUnmount(stop);
119
+ return (_ctx, _cache) => {
120
+ return openBlock(), createElementBlock("div", {
121
+ class: normalizeClass(unref(ns).b()),
122
+ role: "toolbar",
123
+ "aria-label": unref(messages).keys,
124
+ onMousedown: _cache[0] || (_cache[0] = withModifiers(() => {}, ["prevent"])),
125
+ onContextmenu: _cache[1] || (_cache[1] = withModifiers(() => {}, ["prevent"]))
126
+ }, [createElementVNode("div", { class: normalizeClass(unref(ns).e("scroll")) }, [(openBlock(true), createElementBlock(Fragment, null, renderList(symbolKeys.value, (key, i) => {
127
+ return openBlock(), createElementBlock("button", {
128
+ key: `s${i}`,
129
+ type: "button",
130
+ class: normalizeClass([
131
+ unref(ns).e("key"),
132
+ unref(ns).is("pressed", pressed.value === `s${i}`),
133
+ unref(ns).is("icon", !!key.icon)
134
+ ]),
135
+ "aria-label": unref(keyName)(key, unref(messages)),
136
+ title: key.icon ? unref(keyName)(key, unref(messages)) : void 0,
137
+ onPointerdown: ($event) => onPointerDown($event, key, `s${i}`),
138
+ onPointermove: onPointerMove,
139
+ onPointerup: onPointerUp,
140
+ onPointercancel: stop,
141
+ onPointerleave: stop,
142
+ onClick: ($event) => onClick($event, key)
143
+ }, [key.icon ? (openBlock(), createBlock(resolveDynamicComponent(key.icon), { key: 0 })) : (openBlock(), createElementBlock(Fragment, { key: 1 }, [createTextVNode(toDisplayString(key.label), 1)], 64))], 42, _hoisted_2);
144
+ }), 128))], 2), createElementVNode("div", { class: normalizeClass(unref(ns).e("arrows")) }, [(openBlock(true), createElementBlock(Fragment, null, renderList(arrowKeys.value, (key, i) => {
145
+ return openBlock(), createElementBlock("button", {
146
+ key: `a${i}`,
147
+ type: "button",
148
+ class: normalizeClass([
149
+ unref(ns).e("key"),
150
+ unref(ns).is("pressed", pressed.value === `a${i}`),
151
+ unref(ns).is("icon", true)
152
+ ]),
153
+ "aria-label": key.label,
154
+ title: key.label,
155
+ onPointerdown: ($event) => onPointerDown($event, key, `a${i}`),
156
+ onPointermove: onPointerMove,
157
+ onPointerup: onPointerUp,
158
+ onPointercancel: stop,
159
+ onPointerleave: stop,
160
+ onClick: ($event) => onClick($event, key)
161
+ }, [(openBlock(), createBlock(resolveDynamicComponent(key.icon)))], 42, _hoisted_3);
162
+ }), 128))], 2)], 42, _hoisted_1);
163
+ };
164
+ }
165
+ });
166
+ export { code_keys_vue_vue_type_script_setup_true_lang_default as default };
167
+
168
+ //# 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"],"sources":["../src/code-keys.vue"],"sourcesContent":["<script setup lang=\"ts\">\nimport { ChevronDownIcon, ChevronLeftIcon, ChevronRightIcon, ChevronUpIcon } from '@dou-ui/icons'\nimport { useNamespace } from 'dou-ui'\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 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\n/** Moving the cursor, always at hand at the end of the bar. */\nconst arrowKeys = computed<CodeKey[]>(() => {\n const m = messages.value\n return [\n { label: m.cursorLeft, icon: ChevronLeftIcon, command: cursorCharLeft, repeat: true },\n { label: m.cursorUp, icon: ChevronUpIcon, command: cursorLineUp, repeat: true },\n { label: m.cursorDown, icon: ChevronDownIcon, command: cursorLineDown, repeat: true },\n { label: m.cursorRight, icon: ChevronRightIcon, command: cursorCharRight, repeat: true },\n ]\n})\n\nfunction fire(key: CodeKey) {\n const command: CodeCommand = key.command ?? typeText(key.text ?? key.label)\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 editor.focus?.()\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\nonBeforeUnmount(stop)\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 v-for=\"(key, i) in arrowKeys\"\n :key=\"`a${i}`\"\n type=\"button\"\n :class=\"[ns.e('key'), ns.is('pressed', pressed === `a${i}`), ns.is('icon', true)]\"\n :aria-label=\"key.label\"\n :title=\"key.label\"\n @pointerdown=\"onPointerDown($event, key, `a${i}`)\"\n @pointermove=\"onPointerMove\"\n @pointerup=\"onPointerUp\"\n @pointercancel=\"stop\"\n @pointerleave=\"stop\"\n @click=\"onClick($event, key)\"\n >\n <component :is=\"key.icon\" />\n </button>\n </div>\n </div>\n</template>\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAqDA,IAAM,OAAO;;;;;;;;;;EAnCb,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;;EAGA,MAAM,YAAY,eAA0B;GAC1C,MAAM,IAAI,SAAS;GACnB,OAAO;IACL;KAAE,OAAO,EAAE;KAAY,MAAM;KAAiB,SAAS;KAAgB,QAAQ;IAAK;IACpF;KAAE,OAAO,EAAE;KAAU,MAAM;KAAe,SAAS;KAAc,QAAQ;IAAK;IAC9E;KAAE,OAAO,EAAE;KAAY,MAAM;KAAiB,SAAS;KAAgB,QAAQ;IAAK;IACpF;KAAE,OAAO,EAAE;KAAa,MAAM;KAAkB,SAAS;KAAiB,QAAQ;I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CAAA,C;G,gBAGjCN,mBAiBM,OAAA,EAjBA,OAAKH,eAAEC,MAAA,EAAA,CAAE,CAAC,EAAC,QAAA,CAAA,E,KACfH,UAAA,IAAA,GAAAC,mBAeSK,UAAA,MAAAC,WAdY,UAAA,QAAX,KAAK,MAAC;IADhB,OAAAP,UAAA,GAAAC,mBAeS,UAAA;KAbN,KAAG,IAAM;KACV,MAAK;KACJ,OAAKC,eAAA;MAAGC,MAAA,EAAA,CAAE,CAAC,EAAC,KAAA;MAASA,MAAA,EAAA,CAAE,CAAC,GAAE,WAAY,QAAA,UAAO,IAAS,GAAC;MAAKA,MAAA,EAAA,CAAE,CAAC,GAAE,QAAA,IAAA;KAAA,CAAA;KACjE,cAAY,IAAI;KAChB,OAAO,IAAI;KACX,gBAAW,WAAE,cAAc,QAAQ,KAAG,IAAM,GAAC;KAC7C,eAAa;KACb,aAAW;KACX,iBAAe;KACf,gBAAc;KACd,UAAK,WAAE,QAAQ,QAAQ,GAAG;I,KAE3BH,UAAA,GAAAQ,YAA4BC,wBAAZ,IAAI,IAAI,CAAA,E"}
@@ -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 { ChevronDownIcon, ChevronLeftIcon, ChevronRightIcon, ChevronUpIcon } from '@dou-ui/icons'\nimport { useNamespace } from 'dou-ui'\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 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\n/** Moving the cursor, always at hand at the end of the bar. */\nconst arrowKeys = computed<CodeKey[]>(() => {\n const m = messages.value\n return [\n { label: m.cursorLeft, icon: ChevronLeftIcon, command: cursorCharLeft, repeat: true },\n { label: m.cursorUp, icon: ChevronUpIcon, command: cursorLineUp, repeat: true },\n { label: m.cursorDown, icon: ChevronDownIcon, command: cursorLineDown, repeat: true },\n { label: m.cursorRight, icon: ChevronRightIcon, command: cursorCharRight, repeat: true },\n ]\n})\n\nfunction fire(key: CodeKey) {\n const command: CodeCommand = key.command ?? typeText(key.text ?? key.label)\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 editor.focus?.()\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\nonBeforeUnmount(stop)\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 v-for=\"(key, i) in arrowKeys\"\n :key=\"`a${i}`\"\n type=\"button\"\n :class=\"[ns.e('key'), ns.is('pressed', pressed === `a${i}`), ns.is('icon', true)]\"\n :aria-label=\"key.label\"\n :title=\"key.label\"\n @pointerdown=\"onPointerDown($event, key, `a${i}`)\"\n @pointermove=\"onPointerMove\"\n @pointerup=\"onPointerUp\"\n @pointercancel=\"stop\"\n @pointerleave=\"stop\"\n @click=\"onClick($event, key)\"\n >\n <component :is=\"key.icon\" />\n </button>\n </div>\n </div>\n</template>\n"],"mappings":""}