@dou-ui/code 0.1.0-alpha.0 → 0.1.0-alpha.10

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.
@@ -1,8 +1,9 @@
1
1
  import { cursorCharLeft, cursorCharRight, cursorLineDown, cursorLineUp, typeText } from "./core/commands.js";
2
2
  import { useCodeMessages } from "./locale.js";
3
3
  import { defaultCodeKeys, keyName } from "./code-keys.js";
4
+ import { visibleViewport } from "./view/viewport.js";
4
5
  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 { Fragment, computed, createBlock, createElementBlock, createElementVNode, createTextVNode, createVNode, defineComponent, normalizeClass, normalizeStyle, onBeforeUnmount, openBlock, ref, renderList, resolveDynamicComponent, toDisplayString, unref, withModifiers } from "vue";
6
7
  import { ChevronDownIcon, ChevronLeftIcon, ChevronRightIcon, ChevronUpIcon } from "@dou-ui/icons";
7
8
  // src/code-keys.vue?vue&type=script&setup=true&lang.ts
8
9
  var _hoisted_1 = ["aria-label"];
@@ -12,13 +13,10 @@ var _hoisted_2 = [
12
13
  "onPointerdown",
13
14
  "onClick"
14
15
  ];
15
- var _hoisted_3 = [
16
- "aria-label",
17
- "title",
18
- "onPointerdown",
19
- "onClick"
20
- ];
16
+ var _hoisted_3 = ["aria-label", "title"];
21
17
  var SLOP = 8;
18
+ var STICK_REACH = 26;
19
+ var STICK_REST = 8;
22
20
  var code_keys_vue_vue_type_script_setup_true_lang_default = /*@__PURE__*/ defineComponent({
23
21
  name: "DouCodeKeys",
24
22
  __name: "code-keys",
@@ -33,42 +31,8 @@ var code_keys_vue_vue_type_script_setup_true_lang_default = /*@__PURE__*/ define
33
31
  const messages = useCodeMessages(() => props.messages);
34
32
  /** Keys that scroll; a string is a key that types itself. */
35
33
  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
34
  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?.();
35
+ run(key.command ?? typeText(key.text ?? key.label));
72
36
  }
73
37
  /** How far a finger may slide on a key before it counts as scrolling the bar. */
74
38
  const pressed = ref(null);
@@ -115,7 +79,112 @@ var code_keys_vue_vue_type_script_setup_true_lang_default = /*@__PURE__*/ define
115
79
  function onClick(event, key) {
116
80
  if (event.detail === 0) fire(key);
117
81
  }
118
- onBeforeUnmount(stop);
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
+ });
119
188
  return (_ctx, _cache) => {
120
189
  return openBlock(), createElementBlock("div", {
121
190
  class: normalizeClass(unref(ns).b()),
@@ -141,25 +210,32 @@ var code_keys_vue_vue_type_script_setup_true_lang_default = /*@__PURE__*/ define
141
210
  onPointerleave: stop,
142
211
  onClick: ($event) => onClick($event, key)
143
212
  }, [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);
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);
163
239
  };
164
240
  }
165
241
  });
@@ -1 +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;IAAK;GACzF;EACF,CAAC;EAED,SAAS,KAAK,KAAc;GAC1B,MAAM,UAAuB,IAAI,WAAW,SAAS,IAAI,QAAQ,IAAI,KAAK;GAC1E,MAAM,EAAE,WAAW;GACnB,IAAI,CAAC,QAAQ;GACb,OAAO,IAAI,OAAO;GAElB,OAAO,QAAQ;EACjB;;EAIA,MAAM,UAAU,IAAmB,IAAI;EACvC,IAAI,QASO;EAEX,SAAS,OAAO;GACd,IAAI,OAAO;IACT,aAAa,MAAM,KAAK;IACxB,cAAc,MAAM,KAAK;GAC3B;GACA,QAAQ;GACR,QA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AAS,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"}
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,IAAmB,IAAI;EACvC,IAAI,QASO;EAEX,SAAS,OAAO;GACd,IAAI,OAAO;IACT,aAAa,MAAM,KAAK;IACxB,cAAc,MAAM,KAAK;GAC3B;GACA,QAAQ;GACR,QAAQ,QAAQ;EAClB;EAEA,SAAS,cAAc,OAAqB,KAAc,IAAY;GACpE,IAAI,MAAM,WAAW,GAAG;GACxB,KAAK;GACL,QAAQ,QAAQ;GAChB,QAAQ;IACN;IACA;IACA,SAAS,MAAM;IACf,GAAG,MAAM;IACT,GAAG,MAAM;IACT,OAAO;IACP,OAAO;GACT;GACA,IAAI,CAAC,IAAI,QAAQ;GAEjB,MAAM,QAAQ,OAAO,iBAAiB;IACpC,IAAI,CAAC,OAAO;IACZ,MAAM,QAAQ;IACd,KAAK,GAAG;IACR,MAAM,QA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,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"}
@@ -1 +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":""}
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":""}
package/dist/extension.js CHANGED
@@ -5,12 +5,17 @@ function defineCodeExtension(extension) {
5
5
  return extension;
6
6
  }
7
7
  var CODE_EDITOR_KEY = Symbol("DouCodeEditor");
8
+ /**
9
+ * Internal: told each widget height an editor measures, by `extension/id`;
10
+ * DouCodeDiff leaves a blank of the same height across from it.
11
+ */
12
+ var WIDGET_HEIGHT_KEY = Symbol("DouCodeWidgetHeight");
8
13
  /** The editor a panel or gutter component is drawn in. */
9
14
  function useCodeEditor() {
10
15
  const context = inject(CODE_EDITOR_KEY, null);
11
16
  if (!context) throw new Error("[@dou-ui/code] useCodeEditor() must be called inside <DouCodeEditor>");
12
17
  return context;
13
18
  }
14
- export { CODE_EDITOR_KEY, defineCodeExtension, useCodeEditor };
19
+ export { CODE_EDITOR_KEY, WIDGET_HEIGHT_KEY, defineCodeExtension, useCodeEditor };
15
20
 
16
21
  //# sourceMappingURL=extension.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"extension.js","names":[],"sources":["../src/extension.ts"],"sourcesContent":["import type { CodeMessages } from './locale'\nimport { type Component, type InjectionKey, type VNodeChild, inject } from 'vue'\nimport type { CodeKeymap } from './core/keymap'\nimport type { CodeSelection } from './core/selection'\nimport type { CodeText } from './core/text'\nimport type { CodeState, CodeTransaction, CodeTransactionResult } from './core/transaction'\nimport type { CodeEditorExpose } from './types'\n\n/** How bad a diagnostic is, worst first. */\nexport type CodeDiagnosticSeverity = 'error' | 'warning' | 'info' | 'hint'\n\n/** A fix offered with a diagnostic. */\nexport interface CodeDiagnosticAction {\n label: string\n /** Makes the fix, usually with `context.transact`. */\n run: (context: CodeExtensionContext, diagnostic: CodeDiagnostic) => void\n}\n\n/**\n * A problem found in the text, from `from` to `to` (offsets in the text,\n * the same as a language service's ranges). An empty range marks the\n * character after it.\n */\nexport interface CodeDiagnostic {\n from: number\n to: number\n severity: CodeDiagnosticSeverity\n message: string\n /** Who found it, shown after the message, e.g. the name of a linter. */\n source?: string\n /** Fixes, shown under the message and with `Mod` + `.`. */\n actions?: CodeDiagnosticAction[]\n}\n\n/**\n * How a part of the text is drawn. Marks and line classes only change how\n * the text looks (colors, backgrounds, underlines, borders), never its\n * size, so the cursor still lands where the characters are; an inline\n * widget takes its own room in the line.\n */\nexport type CodeDecoration =\n /**\n * Classes on the characters from `from` to `to`. `style` sets inline\n * styles on them as well, e.g. a CSS variable holding a person's color;\n * where marks overlap, the later one's styles win.\n */\n | {\n type: 'mark'\n from: number\n to: number\n class: string\n title?: string\n style?: Readonly<Record<string, string>>\n }\n /** A class on a whole line (`line` from 1), e.g. a tinted background. */\n | { type: 'line'; line: number; class: string }\n /**\n * Something drawn inside a line, before the character at `pos`, such as\n * a color swatch or a parameter's name. It isn't text: the cursor steps\n * over it and copying leaves it out. `width` in px saves measuring it;\n * without it the widget is measured once drawn, and the width is kept by\n * `id`.\n */\n | { type: 'inline'; pos: number; render: () => VNodeChild; width?: number; id?: string }\n\n/**\n * A component drawn between lines, across the editor, e.g. a review\n * comment. The lines below move down to make room, and it moves with the\n * text as lines are added or removed above it.\n */\nexport interface CodeWidget {\n /** Tells widgets apart, unique among one extension's; its measured height is kept by it. */\n id: string\n /**\n * Where it is: below the line of text position `pos`, or below line\n * `line` (from 1); above with `position: 'above'`. Give one of them.\n */\n pos?: number\n line?: number\n /** Defaults to `below`. */\n position?: 'above' | 'below'\n render: () => VNodeChild\n /** Its height in px before it has been drawn and measured; defaults to one line. */\n height?: number\n /** What it is, read out when the cursor moves onto its line, e.g. \"戴兜的评论\". */\n label?: string\n}\n\n/** Something drawn in a column beside the line numbers, on line `line` (from 1). */\nexport interface CodeGutterMarker {\n line: number\n /** Drawn in the middle of the column. */\n icon?: Component\n /** Short text, when there is no icon. */\n text?: string\n class?: string\n /** Shown on hover and read out. */\n title?: string\n}\n\n/** A column of the gutter, left of the line numbers. */\nexport interface CodeGutter {\n name: string\n /** In px. Defaults to 16. */\n width?: number\n /** The markers on the lines in view; reactive state read here updates them. */\n markers: (context: CodeExtensionContext) => CodeGutterMarker[]\n /** A press on the column, on line `line`, e.g. to set a breakpoint. */\n onPress?: (line: number, event: PointerEvent, context: CodeExtensionContext) => void\n}\n\n/** An undo history that takes the place of the editor's own, e.g. one shared with others. */\nexport interface CodeHistoryHandler {\n /** `false` when there is nothing to undo. */\n undo: () => boolean\n redo: () => boolean\n /** Read in templates and computed values: keep them reactive. */\n canUndo: () => boolean\n canRedo: () => boolean\n /** The next change starts a new undo step, e.g. when the editor loses focus. */\n close?: () => void\n}\n\n/** A bar above or below the text, inside the editor's frame. */\nexport interface CodePanel {\n /** Tells panels apart, unique among one extension's. */\n name: string\n /** Defaults to `bottom`. */\n position?: 'top' | 'bottom'\n render: () => VNodeChild\n}\n\n/** What a completion is, shown as its icon. */\nexport type CodeCompletionKind =\n | 'keyword'\n | 'function'\n | 'method'\n | 'variable'\n | 'property'\n | 'constant'\n | 'class'\n | 'type'\n | 'module'\n | 'snippet'\n | 'text'\n\n/** One entry of the completion list. */\nexport interface CodeCompletion {\n /** Shown, and matched against what was typed. */\n label: string\n kind?: CodeCompletionKind\n /** Short, after the label, e.g. a type. */\n detail?: string\n /** Longer, below the list while this entry is picked: text, or a function returning VNodes. */\n info?: string | (() => VNodeChild)\n /** What goes into the text, if not the label. */\n insert?: string\n /** Inserted as a snippet instead: `${1:name}` places to fill in, Tab to the next, `$0` where it ends. */\n snippet?: string\n /** Moves the entry up (positive) or down among equally good matches. */\n boost?: number\n}\n\n/** What a completion source is asked with. */\nexport interface CodeCompletionRequest {\n /** The cursor. */\n pos: number\n /** The word right before the cursor, by the language's word characters; empty when there is none. */\n word: { from: number; to: number; text: string }\n /** Asked for from the keyboard (`Ctrl` + `Space`, `Alt` + `Esc`) rather than by typing. */\n explicit: boolean\n /** Aborted when the answer is no longer wanted, so a slow source can stop. */\n signal: AbortSignal\n}\n\n/** What a hover or signature source is asked with. */\nexport interface CodePositionRequest {\n /** The position asked about: under the pointer, or the cursor. */\n pos: number\n /** Aborted when the answer is no longer wanted, so a slow source can stop. */\n signal: AbortSignal\n}\n\n/** What a completion source answers: entries to put in place of `from`–cursor. */\nexport interface CodeCompletionResult {\n from: number\n options: CodeCompletion[]\n}\n\n/** Text shown on hover, or with the cursor on it from the keyboard. */\nexport interface CodeHoverResult {\n /** What it is about, `from`–`to`; defaults to the word under the pointer. */\n from?: number\n to?: number\n /** Plain text, or a render function for anything else. */\n content: string | (() => VNodeChild)\n}\n\n/** The parameters of the call the cursor is in. */\nexport interface CodeSignatureResult {\n /** The whole signature, e.g. `slice(start, end)`. */\n label: string\n /** Each parameter as `[from, to]` in `label`. */\n params: Array<[number, number]>\n /** Which parameter the cursor is at, from 0. */\n active: number\n /** Shown under the signature: text, or a function returning VNodes. */\n info?: string | (() => VNodeChild)\n}\n\nexport interface CodeExtension {\n name: string\n /** Higher runs first: its keys and hooks come before others. Defaults to 100. */\n priority?: number\n /** Keys tried before the built-in ones, and after the `keymap` prop. */\n keymap?: (context: CodeExtensionContext) => CodeKeymap\n /**\n * How parts of the text look, read while drawing: reactive state read\n * here updates them. Asked for the lines in view (`context.visible`),\n * which is all that needs them.\n */\n decorations?: (context: CodeExtensionContext) => CodeDecoration[]\n /** Columns beside the line numbers. */\n gutters?: CodeGutter[]\n /**\n * Components between lines. Unlike decorations, these are asked for the\n * whole text, since their heights place every line after them; keep\n * them few (comments, not one per line).\n */\n widgets?: (context: CodeExtensionContext) => CodeWidget[]\n /**\n * Lines left out of view: line numbers (from 1, not text positions), from\n * line `from` to line `to`, both left out,\n * e.g. the unchanged lines of a diff. Unlike a fold, nothing marks the\n * spot; put a widget there for that. Asked for the whole text; reactive\n * state read here updates them. Moving up and down steps over them.\n */\n hide?: (context: CodeExtensionContext) => Array<{ from: number; to: number }>\n /** Bars above or below the text; reactive state read here updates them. */\n panels?: (context: CodeExtensionContext) => CodePanel[]\n /**\n * Finds problems in the text. Run when the editor mounts and again a\n * moment after the text stops changing; an answer that arrives after\n * the text changed again is dropped, and the next run follows it.\n * Meanwhile the problems found move with the text.\n */\n lint?: (\n context: CodeExtensionContext,\n ) => CodeDiagnostic[] | null | undefined | Promise<CodeDiagnostic[] | null | undefined>\n /**\n * Offers completions while typing (after a word character or one of\n * `completionTriggers`) and on `Ctrl` + `Space` or `Alt` + `Esc`. Answers from every\n * extension are put in one list; a Promise is waited for, and dropped\n * when the text has moved on.\n */\n completion?: (\n request: CodeCompletionRequest,\n context: CodeExtensionContext,\n ) => CodeCompletionResult | null | undefined | Promise<CodeCompletionResult | null | undefined>\n /** Characters that ask for completions when typed, such as `.`. */\n completionTriggers?: string[]\n /**\n * Text about a position, shown on hover and with `Mod` + `I`. A Promise\n * is waited for; `signal` aborts when the pointer moves on.\n */\n hover?: (\n request: CodePositionRequest,\n context: CodeExtensionContext,\n ) => CodeHoverResult | null | undefined | Promise<CodeHoverResult | null | undefined>\n /**\n * The parameters of the call around the cursor, shown while typing its\n * arguments. A Promise is waited for, and dropped when the cursor has\n * moved on.\n */\n signature?: (\n request: CodePositionRequest,\n context: CodeExtensionContext,\n ) => CodeSignatureResult | null | undefined | Promise<CodeSignatureResult | null | undefined>\n /**\n * Sees every change before it is applied, in priority order, and may add\n * to it (positions are in the text before the change). Undo, redo, new\n * `v-model` values and other people's changes (`action: 'remote'`) don't\n * come through here.\n */\n transaction?: (tr: CodeTransaction, context: CodeExtensionContext) => void\n /**\n * Runs after every step the editor took, with the text and selection\n * already updated: typing, commands, undo and redo, new `v-model`\n * values and other people's changes. `result.meta.action` tells them\n * apart.\n */\n update?: (result: CodeTransactionResult, context: CodeExtensionContext) => void\n /**\n * Replaces the editor's undo history; the first extension that has one\n * wins. Called once per list of extensions: return the same handler\n * each time.\n */\n history?: (context: CodeExtensionContext) => CodeHistoryHandler\n /**\n * Buttons added to the toolbar shown over the selection on touch screens,\n * after cut, copy, paste and select all. Read again as the selection\n * changes.\n */\n menu?: (context: CodeExtensionContext) => CodeMenuItem[]\n /** Runs once the editor is mounted. Return a function to run when it unmounts. */\n setup?: (context: CodeExtensionContext) => void | (() => void)\n}\n\n/** A button of the touch toolbar, from an extension's `menu`. */\nexport interface CodeMenuItem {\n label: string\n run: (context: CodeExtensionContext) => void\n}\n\n/** What an extension sees of the editor: its instance, plus a little more. */\nexport interface CodeExtensionContext extends CodeEditorExpose {\n /** The text and selection now; reading them in `decorations` or `panels` follows every change. */\n readonly state: CodeState\n readonly doc: CodeText\n readonly selection: CodeSelection\n /** The lines in view: line numbers (from 1, not text positions), both ends in view. */\n readonly visible: { readonly from: number; readonly to: number }\n /** The problems found now, by all linters and the `diagnostics` prop, in text order. */\n readonly diagnostics: readonly CodeDiagnostic[]\n /** Whether the editor has focus; reading it in reactive code follows it. */\n readonly focused: boolean\n /** The editor's texts, in DouUI's locale or as given by the `messages` prop. */\n readonly messages: CodeMessages\n /** Reads a message out to screen readers. */\n announce: (message: string) => void\n /**\n * Runs the linter of the extension named `name` again now (every linter\n * without a name), for problems that arrive by themselves, such as ones a\n * server pushes.\n */\n relint: (name?: string) => void\n}\n\n/** Types an extension; returns it as it is. */\nexport function defineCodeExtension(extension: CodeExtension): CodeExtension {\n return extension\n}\n\nexport const CODE_EDITOR_KEY: InjectionKey<CodeExtensionContext> = Symbol('DouCodeEditor')\n\n/** The editor a panel or gutter component is drawn in. */\nexport function useCodeEditor(): CodeExtensionContext {\n const context = inject(CODE_EDITOR_KEY, null)\n if (!context)\n throw new Error('[@dou-ui/code] useCodeEditor() must be called inside <DouCodeEditor>')\n return context\n}\n"],"mappings":";;;AAmVA,SAAgB,oBAAoB,WAAyC;CAC3E,OAAO;AACT;AAEA,IAAa,kBAAsD,OAAO,eAAe;;AAGzF,SAAgB,gBAAsC;CACpD,MAAM,UAAU,OAAO,iBAAiB,IAAI;CAC5C,IAAI,CAAC,SACH,MAAM,IAAI,MAAM,sEAAsE;CACxF,OAAO;AACT"}
1
+ {"version":3,"file":"extension.js","names":[],"sources":["../src/extension.ts"],"sourcesContent":["import type { CodeMessages } from './locale'\nimport { type Component, type InjectionKey, type VNodeChild, inject } from 'vue'\nimport type { CodeKeymap } from './core/keymap'\nimport type { CodeSelection } from './core/selection'\nimport type { CodeText } from './core/text'\nimport type { CodeState, CodeTransaction, CodeTransactionResult } from './core/transaction'\nimport type { CodeEditorExpose } from './types'\n\n/** How bad a diagnostic is, worst first. */\nexport type CodeDiagnosticSeverity = 'error' | 'warning' | 'info' | 'hint'\n\n/** A fix offered with a diagnostic. */\nexport interface CodeDiagnosticAction {\n label: string\n /** Makes the fix, usually with `context.transact`. */\n run: (context: CodeExtensionContext, diagnostic: CodeDiagnostic) => void\n}\n\n/**\n * A problem found in the text, from `from` to `to` (offsets in the text,\n * the same as a language service's ranges). An empty range marks the\n * character after it.\n */\nexport interface CodeDiagnostic {\n from: number\n to: number\n severity: CodeDiagnosticSeverity\n message: string\n /** Who found it, shown after the message, e.g. the name of a linter. */\n source?: string\n /** Fixes, shown under the message and with `Mod` + `.`. */\n actions?: CodeDiagnosticAction[]\n}\n\n/**\n * How a part of the text is drawn. Marks and line classes only change how\n * the text looks (colors, backgrounds, underlines, borders), never its\n * size, so the cursor still lands where the characters are; an inline\n * widget takes its own room in the line.\n */\nexport type CodeDecoration =\n /**\n * Classes on the characters from `from` to `to`. `style` sets inline\n * styles on them as well, e.g. a CSS variable holding a person's color;\n * where marks overlap, the later one's styles win.\n */\n | {\n type: 'mark'\n from: number\n to: number\n class: string\n title?: string\n style?: Readonly<Record<string, string>>\n }\n /** A class on a whole line (`line` from 1), e.g. a tinted background. */\n | { type: 'line'; line: number; class: string }\n /**\n * Something drawn inside a line, before the character at `pos`, such as\n * a color swatch or a parameter's name. It isn't text: the cursor steps\n * over it and copying leaves it out. `width` in px saves measuring it;\n * without it the widget is measured once drawn, and the width is kept by\n * `id`.\n */\n | { type: 'inline'; pos: number; render: () => VNodeChild; width?: number; id?: string }\n\n/**\n * A component drawn between lines, across the editor, e.g. a review\n * comment. The lines below move down to make room, and it moves with the\n * text as lines are added or removed above it.\n */\nexport interface CodeWidget {\n /** Tells widgets apart, unique among one extension's; its measured height is kept by it. */\n id: string\n /**\n * Where it is: below the line of text position `pos`, or below line\n * `line` (from 1); above with `position: 'above'`. Give one of them.\n */\n pos?: number\n line?: number\n /** Defaults to `below`. */\n position?: 'above' | 'below'\n render: () => VNodeChild\n /** Its height in px before it has been drawn and measured; defaults to one line. */\n height?: number\n /** What it is, read out when the cursor moves onto its line, e.g. \"戴兜的评论\". */\n label?: string\n}\n\n/** Something drawn in a column beside the line numbers, on line `line` (from 1). */\nexport interface CodeGutterMarker {\n line: number\n /** Drawn in the middle of the column. */\n icon?: Component\n /** Short text, when there is no icon. */\n text?: string\n class?: string\n /**\n * Shown on hover. Required when the column has `onPress`: the marker is\n * then a button, and this is its name.\n */\n title?: string\n /**\n * When the marker shows: `always`, or `hover`, out of sight until its\n * line is hovered, holds the cursor, or the marker has the focus, e.g. a\n * \"comment\" mark offered on every line. Defaults to `always`.\n */\n visible?: 'always' | 'hover'\n}\n\n/**\n * The marker a column shows on every line without one of its own, out of\n * sight until the line is hovered (as `visible: 'hover'`), e.g. \"add a\n * breakpoint\" offered on every line.\n */\nexport interface CodeGutterHoverMarker extends Pick<CodeGutterMarker, 'icon' | 'text' | 'class'> {\n /**\n * Its name, as a marker's `title`; a function names the marker of each\n * line, e.g. \"Add a breakpoint on line 3\". It is called for every line in\n * view, often: keep it quick.\n */\n title?: string | ((line: number) => string)\n}\n\n/** A column of the gutter, left of the line numbers. */\nexport interface CodeGutter {\n name: string\n /** In px. Defaults to 16. */\n width?: number\n /** The markers on the lines in view; reactive state read here updates them. */\n markers?: (context: CodeExtensionContext) => CodeGutterMarker[]\n /** A marker on every other line, shown on hover. */\n hoverMarker?: CodeGutterHoverMarker\n /**\n * Where `onPress` answers: `any` cell of the column (the default), e.g. to\n * set a breakpoint on an empty line, or only its `markers`.\n */\n pressOn?: 'any' | 'markers'\n /**\n * A press on the column, on line `line`, e.g. to set a breakpoint. A\n * marker in such a column is a button: the one on the cursor's line is\n * reached with Escape then Shift+Tab, and Enter or Space presses it. A\n * finger or pen presses when it lifts in place; a tap on a marker still\n * out of sight first moves the cursor to its line, which shows it.\n */\n onPress?: (\n line: number,\n event: PointerEvent | KeyboardEvent,\n context: CodeExtensionContext,\n ) => void\n}\n\n/** An undo history that takes the place of the editor's own, e.g. one shared with others. */\nexport interface CodeHistoryHandler {\n /** `false` when there is nothing to undo. */\n undo: () => boolean\n redo: () => boolean\n /** Read in templates and computed values: keep them reactive. */\n canUndo: () => boolean\n canRedo: () => boolean\n /** The next change starts a new undo step, e.g. when the editor loses focus. */\n close?: () => void\n}\n\n/** A bar above or below the text, inside the editor's frame. */\nexport interface CodePanel {\n /** Tells panels apart, unique among one extension's. */\n name: string\n /** Defaults to `bottom`. */\n position?: 'top' | 'bottom'\n render: () => VNodeChild\n}\n\n/** What a completion is, shown as its icon. */\nexport type CodeCompletionKind =\n | 'keyword'\n | 'function'\n | 'method'\n | 'variable'\n | 'property'\n | 'constant'\n | 'class'\n | 'type'\n | 'module'\n | 'snippet'\n | 'text'\n\n/** One entry of the completion list. */\nexport interface CodeCompletion {\n /** Shown, and matched against what was typed. */\n label: string\n kind?: CodeCompletionKind\n /** Short, after the label, e.g. a type. */\n detail?: string\n /** Longer, below the list while this entry is picked: text, or a function returning VNodes. */\n info?: string | (() => VNodeChild)\n /** What goes into the text, if not the label. */\n insert?: string\n /** Inserted as a snippet instead: `${1:name}` places to fill in, Tab to the next, `$0` where it ends. */\n snippet?: string\n /** Moves the entry up (positive) or down among equally good matches. */\n boost?: number\n}\n\n/** What a completion source is asked with. */\nexport interface CodeCompletionRequest {\n /** The cursor. */\n pos: number\n /** The word right before the cursor, by the language's word characters; empty when there is none. */\n word: { from: number; to: number; text: string }\n /** Asked for from the keyboard (`Ctrl` + `Space`, `Alt` + `Esc`) rather than by typing. */\n explicit: boolean\n /** Aborted when the answer is no longer wanted, so a slow source can stop. */\n signal: AbortSignal\n}\n\n/** What a hover or signature source is asked with. */\nexport interface CodePositionRequest {\n /** The position asked about: under the pointer, or the cursor. */\n pos: number\n /** Aborted when the answer is no longer wanted, so a slow source can stop. */\n signal: AbortSignal\n}\n\n/** What a completion source answers: entries to put in place of `from`–cursor. */\nexport interface CodeCompletionResult {\n from: number\n options: CodeCompletion[]\n}\n\n/** Text shown on hover, or with the cursor on it from the keyboard. */\nexport interface CodeHoverResult {\n /** What it is about, `from`–`to`; defaults to the word under the pointer. */\n from?: number\n to?: number\n /** Plain text, or a render function for anything else. */\n content: string | (() => VNodeChild)\n}\n\n/** The parameters of the call the cursor is in. */\nexport interface CodeSignatureResult {\n /** The whole signature, e.g. `slice(start, end)`. */\n label: string\n /** Each parameter as `[from, to]` in `label`. */\n params: Array<[number, number]>\n /** Which parameter the cursor is at, from 0. */\n active: number\n /** Shown under the signature: text, or a function returning VNodes. */\n info?: string | (() => VNodeChild)\n}\n\nexport interface CodeExtension {\n name: string\n /** Higher runs first: its keys and hooks come before others. Defaults to 100. */\n priority?: number\n /** Keys tried before the built-in ones, and after the `keymap` prop. */\n keymap?: (context: CodeExtensionContext) => CodeKeymap\n /**\n * How parts of the text look, read while drawing: reactive state read\n * here updates them. Asked for the lines in view (`context.visible`),\n * which is all that needs them.\n */\n decorations?: (context: CodeExtensionContext) => CodeDecoration[]\n /** Columns beside the line numbers. */\n gutters?: CodeGutter[]\n /**\n * Components between lines. Unlike decorations, these are asked for the\n * whole text, since their heights place every line after them; keep\n * them few (comments, not one per line).\n */\n widgets?: (context: CodeExtensionContext) => CodeWidget[]\n /**\n * Lines left out of view: line numbers (from 1, not text positions), from\n * line `from` to line `to`, both left out,\n * e.g. the unchanged lines of a diff. Unlike a fold, nothing marks the\n * spot; put a widget there for that. Asked for the whole text; reactive\n * state read here updates them. Moving up and down steps over them.\n */\n hide?: (context: CodeExtensionContext) => Array<{ from: number; to: number }>\n /** Bars above or below the text; reactive state read here updates them. */\n panels?: (context: CodeExtensionContext) => CodePanel[]\n /**\n * Finds problems in the text. Run when the editor mounts and again a\n * moment after the text stops changing; an answer that arrives after\n * the text changed again is dropped, and the next run follows it.\n * Meanwhile the problems found move with the text.\n */\n lint?: (\n context: CodeExtensionContext,\n ) => CodeDiagnostic[] | null | undefined | Promise<CodeDiagnostic[] | null | undefined>\n /**\n * Offers completions while typing (after a word character or one of\n * `completionTriggers`) and on `Ctrl` + `Space` or `Alt` + `Esc`. Answers from every\n * extension are put in one list; a Promise is waited for, and dropped\n * when the text has moved on.\n */\n completion?: (\n request: CodeCompletionRequest,\n context: CodeExtensionContext,\n ) => CodeCompletionResult | null | undefined | Promise<CodeCompletionResult | null | undefined>\n /** Characters that ask for completions when typed, such as `.`. */\n completionTriggers?: string[]\n /**\n * Text about a position, shown on hover and with `Mod` + `I`. A Promise\n * is waited for; `signal` aborts when the pointer moves on.\n */\n hover?: (\n request: CodePositionRequest,\n context: CodeExtensionContext,\n ) => CodeHoverResult | null | undefined | Promise<CodeHoverResult | null | undefined>\n /**\n * The parameters of the call around the cursor, shown while typing its\n * arguments. A Promise is waited for, and dropped when the cursor has\n * moved on.\n */\n signature?: (\n request: CodePositionRequest,\n context: CodeExtensionContext,\n ) => CodeSignatureResult | null | undefined | Promise<CodeSignatureResult | null | undefined>\n /**\n * Sees every change before it is applied, in priority order, and may add\n * to it (positions are in the text before the change). Undo, redo, new\n * `v-model` values and other people's changes (`action: 'remote'`) don't\n * come through here.\n */\n transaction?: (tr: CodeTransaction, context: CodeExtensionContext) => void\n /**\n * Runs after every step the editor took, with the text and selection\n * already updated: typing, commands, undo and redo, new `v-model`\n * values and other people's changes. `result.meta.action` tells them\n * apart.\n */\n update?: (result: CodeTransactionResult, context: CodeExtensionContext) => void\n /**\n * Replaces the editor's undo history; the first extension that has one\n * wins. Called once per list of extensions: return the same handler\n * each time.\n */\n history?: (context: CodeExtensionContext) => CodeHistoryHandler\n /**\n * Buttons added to the toolbar shown over the selection on touch screens,\n * after cut, copy, paste and select all. Read again as the selection\n * changes.\n */\n menu?: (context: CodeExtensionContext) => CodeMenuItem[]\n /** Runs once the editor is mounted. Return a function to run when it unmounts. */\n setup?: (context: CodeExtensionContext) => void | (() => void)\n}\n\n/** A button of the touch toolbar, from an extension's `menu`. */\nexport interface CodeMenuItem {\n label: string\n run: (context: CodeExtensionContext) => void\n}\n\n/** What an extension sees of the editor: its instance, plus a little more. */\nexport interface CodeExtensionContext extends CodeEditorExpose {\n /** The text and selection now; reading them in `decorations` or `panels` follows every change. */\n readonly state: CodeState\n readonly doc: CodeText\n readonly selection: CodeSelection\n /** The lines in view: line numbers (from 1, not text positions), both ends in view. */\n readonly visible: { readonly from: number; readonly to: number }\n /** The problems found now, by all linters and the `diagnostics` prop, in text order. */\n readonly diagnostics: readonly CodeDiagnostic[]\n /** Whether the editor has focus; reading it in reactive code follows it. */\n readonly focused: boolean\n /** The editor's texts, in DouUI's locale or as given by the `messages` prop. */\n readonly messages: CodeMessages\n /** Reads a message out to screen readers. */\n announce: (message: string) => void\n /**\n * Runs the linter of the extension named `name` again now (every linter\n * without a name), for problems that arrive by themselves, such as ones a\n * server pushes.\n */\n relint: (name?: string) => void\n}\n\n/** Types an extension; returns it as it is. */\nexport function defineCodeExtension(extension: CodeExtension): CodeExtension {\n return extension\n}\n\nexport const CODE_EDITOR_KEY: InjectionKey<CodeExtensionContext> = Symbol('DouCodeEditor')\n\n/**\n * Internal: told each widget height an editor measures, by `extension/id`;\n * DouCodeDiff leaves a blank of the same height across from it.\n */\nexport const WIDGET_HEIGHT_KEY: InjectionKey<((key: string, height: number) => void) | null> =\n Symbol('DouCodeWidgetHeight')\n\n/** The editor a panel or gutter component is drawn in. */\nexport function useCodeEditor(): CodeExtensionContext {\n const context = inject(CODE_EDITOR_KEY, null)\n if (!context)\n throw new Error('[@dou-ui/code] useCodeEditor() must be called inside <DouCodeEditor>')\n return context\n}\n"],"mappings":";;;AA2XA,SAAgB,oBAAoB,WAAyC;CAC3E,OAAO;AACT;AAEA,IAAa,kBAAsD,OAAO,eAAe;;;;;AAMzF,IAAa,oBACX,OAAO,qBAAqB;;AAG9B,SAAgB,gBAAsC;CACpD,MAAM,UAAU,OAAO,iBAAiB,IAAI;CAC5C,IAAI,CAAC,SACH,MAAM,IAAI,MAAM,sEAAsE;CACxF,OAAO;AACT"}
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","names":["CodeEditor","CodeKeys","CodeInput","CodeDiff"],"sources":["../src/index.ts"],"sourcesContent":["import { withInstall } from 'dou-ui'\nimport CodeEditor from './code-editor.vue'\nimport CodeDiff from './code-diff.vue'\nimport CodeInput from './code-input.vue'\nimport CodeKeys from './code-keys.vue'\n\nexport const DouCodeEditor = withInstall(CodeEditor)\nexport const DouCodeKeys = withInstall(CodeKeys)\nexport const DouCodeInput = withInstall(CodeInput)\nexport const DouCodeDiff = withInstall(CodeDiff)\nexport { diffText } from './core/diff'\nexport type { CodeDiffHunk, CodeDiffOptions, CodeDiffPart } from './core/diff'\nexport { defaultCodeKeys } from './code-keys'\nexport { defineCodeExtension, useCodeEditor } from './extension'\nexport type {\n CodeDecoration,\n CodeDiagnostic,\n CodeDiagnosticAction,\n CodeDiagnosticSeverity,\n CodeExtension,\n CodeExtensionContext,\n CodeGutter,\n CodeGutterMarker,\n CodeHistoryHandler,\n CodeCompletion,\n CodeCompletionKind,\n CodeCompletionRequest,\n CodePositionRequest,\n CodeCompletionResult,\n CodeHoverResult,\n CodeMenuItem,\n CodePanel,\n CodeSignatureResult,\n CodeWidget,\n} from './extension'\nexport default DouCodeEditor\n\nexport type {\n CodeDiffEmits,\n CodeDiffProps,\n CodeEditorEmits,\n CodeEditorExpose,\n CodeEditorProps,\n CodeInputEmits,\n CodeInputProps,\n CodeKey,\n CodeKeysProps,\n} from './types'\nexport { CodeText, splitLines } from './core/text'\nexport type { CodeLine } from './core/text'\nexport { ChangeSet } from './core/changes'\nexport type { CodeChange, CodeChangeSpec, MapAssoc } from './core/changes'\nexport {\n isEmptyRange,\n mainRange,\n mapSelection,\n normalizeSelection,\n rangeFrom,\n rangeTo,\n sameSelection,\n selectionOf,\n} from './core/selection'\nexport type { CodeRange, CodeSelection } from './core/selection'\nexport { CodeTransaction } from './core/transaction'\nexport type {\n CodeAction,\n CodeState,\n CodeTransactionMeta,\n CodeTransactionResult,\n} from './core/transaction'\nexport * as codeCommands from './core/commands'\nexport type { CodeCommand, CodeCommandTarget } from './core/commands'\nexport { defaultKeymap } from './core/keymap'\nexport { findPartner, matchBracket } from './core/brackets'\nexport type { BracketMatch } from './core/brackets'\nexport { CodeStream } from './language/stream'\nexport {\n copyPlain,\n defineCodeLanguage,\n languageFor,\n lineParts,\n samePlain,\n tokenizeLine,\n tokenTypes,\n} from './language/language'\nexport type {\n CodeLanguage,\n CodeLanguageSpec,\n CodeLineTokens,\n CodeTokenType,\n} from './language/language'\nexport { CodeHighlighter } from './language/highlighter'\nexport { createCodeHighlighter, highlightToHtml } from './language/to-html'\nexport { createJavaScript, javascript, jsx, tsx, typescript } from './languages/javascript'\nexport type { JavaScriptOptions, JavaScriptState } from './languages/javascript'\nexport { createCss, css, scss } from './languages/css'\nexport type { CssState } from './languages/css'\nexport { json } from './languages/json'\nexport type { JsonState } from './languages/json'\nexport { createHtml, html, vue } from './languages/html'\nexport type { HtmlState } from './languages/html'\nexport { createMarkdown, markdown } from './languages/markdown'\nexport type { MarkdownOptions, MarkdownState } from './languages/markdown'\nexport { python } from './languages/python'\nexport type { PythonState } from './languages/python'\nexport { shell } from './languages/shell'\nexport type { ShellState } from './languages/shell'\nexport { sql } from './languages/sql'\nexport type { SqlState } from './languages/sql'\nexport { yaml } from './languages/yaml'\nexport type { YamlState } from './languages/yaml'\nexport type { CodeKeyBinding, CodeKeymap } from './core/keymap'\nexport type { CodeAssistControl, CodeDiagnosticControl, CodeSearchControl } from './core/commands'\nexport { matchAfter, queryRegExp, replacementFor, searchText } from './core/search'\nexport type { CodeMatch, CodeSearchQuery, CodeSearchResult } from './core/search'\nexport { codeLocales } from './locale'\nexport type { CodeMessages } from './locale'\n\ndeclare module 'vue' {\n export interface GlobalComponents {\n DouCodeEditor: typeof DouCodeEditor\n DouCodeKeys: typeof DouCodeKeys\n DouCodeInput: typeof DouCodeInput\n DouCodeDiff: typeof DouCodeDiff\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAMA,IAAa,gBAAgB,YAAYA,mBAAU;AACnD,IAAa,cAAc,YAAYC,iBAAQ;AAC/C,IAAa,eAAe,YAAYC,kBAAS;AACjD,IAAa,cAAc,YAAYC,iBAAQ"}
1
+ {"version":3,"file":"index.js","names":["CodeEditor","CodeKeys","CodeInput","CodeDiff"],"sources":["../src/index.ts"],"sourcesContent":["import { withInstall } from 'dou-ui'\nimport CodeEditor from './code-editor.vue'\nimport CodeDiff from './code-diff.vue'\nimport CodeInput from './code-input.vue'\nimport CodeKeys from './code-keys.vue'\n\nexport const DouCodeEditor = withInstall(CodeEditor)\nexport const DouCodeKeys = withInstall(CodeKeys)\nexport const DouCodeInput = withInstall(CodeInput)\nexport const DouCodeDiff = withInstall(CodeDiff)\nexport { diffText } from './core/diff'\nexport type { CodeDiffHunk, CodeDiffOptions, CodeDiffPart } from './core/diff'\nexport { defaultCodeKeys } from './code-keys'\nexport { defineCodeExtension, useCodeEditor } from './extension'\nexport type {\n CodeDecoration,\n CodeDiagnostic,\n CodeDiagnosticAction,\n CodeDiagnosticSeverity,\n CodeExtension,\n CodeExtensionContext,\n CodeGutter,\n CodeGutterHoverMarker,\n CodeGutterMarker,\n CodeHistoryHandler,\n CodeCompletion,\n CodeCompletionKind,\n CodeCompletionRequest,\n CodePositionRequest,\n CodeCompletionResult,\n CodeHoverResult,\n CodeMenuItem,\n CodePanel,\n CodeSignatureResult,\n CodeWidget,\n} from './extension'\nexport default DouCodeEditor\n\nexport type {\n CodeDiffEmits,\n CodeDiffGutter,\n CodeDiffGutterMarker,\n CodeDiffHoverMarker,\n CodeDiffProps,\n CodeDiffSide,\n CodeDiffWidget,\n CodeEditorEmits,\n CodeEditorExpose,\n CodeEditorProps,\n CodeInputEmits,\n CodeInputProps,\n CodeKey,\n CodeKeysProps,\n} from './types'\nexport { CodeText, splitLines } from './core/text'\nexport type { CodeLine } from './core/text'\nexport { ChangeSet } from './core/changes'\nexport type { CodeChange, CodeChangeSpec, MapAssoc } from './core/changes'\nexport {\n isEmptyRange,\n mainRange,\n mapSelection,\n normalizeSelection,\n rangeFrom,\n rangeTo,\n sameSelection,\n selectionOf,\n} from './core/selection'\nexport type { CodeRange, CodeSelection } from './core/selection'\nexport { CodeTransaction } from './core/transaction'\nexport type {\n CodeAction,\n CodeState,\n CodeTransactionMeta,\n CodeTransactionResult,\n} from './core/transaction'\nexport * as codeCommands from './core/commands'\nexport type { CodeCommand, CodeCommandTarget } from './core/commands'\nexport { defaultKeymap } from './core/keymap'\nexport { findPartner, matchBracket } from './core/brackets'\nexport type { BracketMatch } from './core/brackets'\nexport { CodeStream } from './language/stream'\nexport {\n copyPlain,\n defineCodeLanguage,\n languageFor,\n lineParts,\n samePlain,\n tokenizeLine,\n tokenTypes,\n} from './language/language'\nexport type {\n CodeLanguage,\n CodeLanguageSpec,\n CodeLineTokens,\n CodeTokenType,\n} from './language/language'\nexport { CodeHighlighter } from './language/highlighter'\nexport { createCodeHighlighter, highlightToHtml } from './language/to-html'\nexport { createJavaScript, javascript, jsx, tsx, typescript } from './languages/javascript'\nexport type { JavaScriptOptions, JavaScriptState } from './languages/javascript'\nexport { createCss, css, scss } from './languages/css'\nexport type { CssState } from './languages/css'\nexport { json } from './languages/json'\nexport type { JsonState } from './languages/json'\nexport { createHtml, html, vue } from './languages/html'\nexport type { HtmlState } from './languages/html'\nexport { createMarkdown, markdown } from './languages/markdown'\nexport type { MarkdownOptions, MarkdownState } from './languages/markdown'\nexport { python } from './languages/python'\nexport type { PythonState } from './languages/python'\nexport { shell } from './languages/shell'\nexport type { ShellState } from './languages/shell'\nexport { sql } from './languages/sql'\nexport type { SqlState } from './languages/sql'\nexport { yaml } from './languages/yaml'\nexport type { YamlState } from './languages/yaml'\nexport type { CodeKeyBinding, CodeKeymap } from './core/keymap'\nexport type { CodeAssistControl, CodeDiagnosticControl, CodeSearchControl } from './core/commands'\nexport { matchAfter, queryRegExp, replacementFor, searchText } from './core/search'\nexport type { CodeMatch, CodeSearchQuery, CodeSearchResult } from './core/search'\nexport { codeLocales } from './locale'\nexport type { CodeMessages } from './locale'\n\ndeclare module 'vue' {\n export interface GlobalComponents {\n DouCodeEditor: typeof DouCodeEditor\n DouCodeKeys: typeof DouCodeKeys\n DouCodeInput: typeof DouCodeInput\n DouCodeDiff: typeof DouCodeDiff\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAMA,IAAa,gBAAgB,YAAYA,mBAAU;AACnD,IAAa,cAAc,YAAYC,iBAAQ;AAC/C,IAAa,eAAe,YAAYC,kBAAS;AACjD,IAAa,cAAc,YAAYC,iBAAQ"}
package/dist/locale.js CHANGED
@@ -14,11 +14,9 @@ var zhCN = {
14
14
  selectAll: "全选",
15
15
  goToDefinition: "跳到定义",
16
16
  keys: "符号栏",
17
+ moveKeys: "移动符号栏",
17
18
  indent: "缩进",
18
- cursorLeft: "光标左移",
19
- cursorRight: "光标右移",
20
- cursorUp: "光标上移",
21
- cursorDown: "光标下移",
19
+ moveCursor: "移动光标",
22
20
  undo: "撤销",
23
21
  redo: "重做",
24
22
  error: "错误",
@@ -60,11 +58,9 @@ var zhTW = {
60
58
  selectAll: "全選",
61
59
  goToDefinition: "跳至定義",
62
60
  keys: "符號列",
61
+ moveKeys: "移動符號列",
63
62
  indent: "縮排",
64
- cursorLeft: "游標左移",
65
- cursorRight: "游標右移",
66
- cursorUp: "游標上移",
67
- cursorDown: "游標下移",
63
+ moveCursor: "移動游標",
68
64
  undo: "復原",
69
65
  redo: "重做",
70
66
  error: "錯誤",
@@ -106,11 +102,9 @@ var en = {
106
102
  selectAll: "Select all",
107
103
  goToDefinition: "Go to definition",
108
104
  keys: "Symbols",
105
+ moveKeys: "Move symbols",
109
106
  indent: "Indent",
110
- cursorLeft: "Move left",
111
- cursorRight: "Move right",
112
- cursorUp: "Move up",
113
- cursorDown: "Move down",
107
+ moveCursor: "Move cursor",
114
108
  undo: "Undo",
115
109
  redo: "Redo",
116
110
  error: "Error",
@@ -1 +1 @@
1
- {"version":3,"file":"locale.js","names":[],"sources":["../src/locale.ts"],"sourcesContent":["import { useLocale } from 'dou-ui'\nimport { computed, toValue, type MaybeRefOrGetter } from 'vue'\n\nexport interface CodeMessages {\n /** The marker of a folded block, as a tooltip. */\n unfold: string\n /** Read out after folding: `{from}`, `{to}` are the hidden lines. */\n folded: string\n unfolded: string\n foldedAll: string\n unfoldedAll: string\n /** The toolbar over a selection on touch screens. */\n editMenu: string\n cut: string\n copy: string\n paste: string\n selectAll: string\n /** Toolbar button of a language server (`@dou-ui/code/lsp`): go to where the name is defined. */\n goToDefinition: string\n /** The bar of symbol keys above a phone's keyboard. */\n keys: string\n /** The Tab key on that bar. */\n indent: string\n cursorLeft: string\n cursorRight: string\n cursorUp: string\n cursorDown: string\n undo: string\n redo: string\n error: string\n warning: string\n info: string\n hint: string\n /** The box with the problems at a place in the text. */\n problems: string\n /** Read out when the cursor moves to a problem: `{line}`, `{severity}`, `{message}`. */\n problemAt: string\n /** Read out when a fix or a completion is picked: `{label}`, `{index}`, `{count}`. */\n itemAt: string\n /** The box with the text about a place, and its problems. */\n details: string\n /** The completion list. */\n completions: string\n /** The box with the parameters of a call. */\n signature: string\n /** The diff view's name. */\n diff: string\n /** The original side's label. */\n diffOriginal: string\n /** The modified side's label. */\n diffModified: string\n diffPrevious: string\n diffNext: string\n /** Shows the two sides next to each other. */\n diffSplit: string\n /** Shows the changes in one column. */\n diffInline: string\n /** Shows all the unchanged lines. */\n diffExpandAll: string\n /** Hides the unchanged lines again. */\n diffCollapse: string\n /** The bar over hidden unchanged lines: `{count}`. */\n diffUnchanged: string\n /** How many lines were added and removed: `{added}`, `{removed}`. */\n diffStats: string\n diffNoChanges: string\n /** A removed line, in the gutter. */\n diffRemoved: string\n /** An added line, in the gutter. */\n diffAdded: string\n /** Read out when moving to a change: `{index}`, `{count}`, `{line}`, `{removed}`, `{added}`. */\n diffChangeAt: string\n}\n\nexport const zhCN: CodeMessages = {\n unfold: '展开',\n folded: '已折叠第 {from}–{to} 行',\n unfolded: '已展开',\n foldedAll: '已全部折叠',\n unfoldedAll: '已全部展开',\n editMenu: '编辑',\n cut: '剪切',\n copy: '复制',\n paste: '粘贴',\n selectAll: '全选',\n goToDefinition: '跳到定义',\n keys: '符号栏',\n indent: '缩进',\n cursorLeft: '光标左移',\n cursorRight: '光标右移',\n cursorUp: '光标上移',\n cursorDown: '光标下移',\n undo: '撤销',\n redo: '重做',\n error: '错误',\n warning: '警告',\n info: '信息',\n hint: '提示',\n problems: '问题',\n problemAt: '第 {line} 行,{severity}:{message}',\n itemAt: '{label},第 {index} 项,共 {count} 项',\n details: '说明',\n completions: '补全',\n signature: '参数提示',\n diff: '对比',\n diffOriginal: '原文',\n diffModified: '修改后',\n diffPrevious: '上一处改动',\n diffNext: '下一处改动',\n diffSplit: '并排显示',\n diffInline: '行内显示',\n diffExpandAll: '展开全部',\n diffCollapse: '折叠未改动的行',\n diffUnchanged: '{count} 行未改动',\n diffStats: '新增 {added} 行,删除 {removed} 行',\n diffNoChanges: '没有改动',\n diffRemoved: '删除',\n diffAdded: '新增',\n diffChangeAt:\n '第 {index} 处改动,共 {count} 处,第 {line} 行:删除 {removed} 行,新增 {added} 行',\n}\n\nexport const zhTW: CodeMessages = {\n unfold: '展開',\n folded: '已摺疊第 {from}–{to} 行',\n unfolded: '已展開',\n foldedAll: '已全部摺疊',\n unfoldedAll: '已全部展開',\n editMenu: '編輯',\n cut: '剪下',\n copy: '拷貝',\n paste: '貼上',\n selectAll: '全選',\n goToDefinition: '跳至定義',\n keys: '符號列',\n indent: '縮排',\n cursorLeft: '游標左移',\n cursorRight: '游標右移',\n cursorUp: '游標上移',\n cursorDown: '游標下移',\n undo: '復原',\n redo: '重做',\n error: '錯誤',\n warning: '警告',\n info: '資訊',\n hint: '提示',\n problems: '問題',\n problemAt: '第 {line} 行,{severity}:{message}',\n itemAt: '{label},第 {index} 項,共 {count} 項',\n details: '說明',\n completions: '自動完成',\n signature: '參數提示',\n diff: '對比',\n diffOriginal: '原文',\n diffModified: '修改後',\n diffPrevious: '上一處改動',\n diffNext: '下一處改動',\n diffSplit: '並排顯示',\n diffInline: '行內顯示',\n diffExpandAll: '展開全部',\n diffCollapse: '摺疊未改動的行',\n diffUnchanged: '{count} 行未改動',\n diffStats: '新增 {added} 行,刪除 {removed} 行',\n diffNoChanges: '沒有改動',\n diffRemoved: '刪除',\n diffAdded: '新增',\n diffChangeAt:\n '第 {index} 處改動,共 {count} 處,第 {line} 行:刪除 {removed} 行,新增 {added} 行',\n}\n\nexport const en: CodeMessages = {\n unfold: 'Unfold',\n folded: 'Folded lines {from}–{to}',\n unfolded: 'Unfolded',\n foldedAll: 'Folded all',\n unfoldedAll: 'Unfolded all',\n editMenu: 'Edit',\n cut: 'Cut',\n copy: 'Copy',\n paste: 'Paste',\n selectAll: 'Select all',\n goToDefinition: 'Go to definition',\n keys: 'Symbols',\n indent: 'Indent',\n cursorLeft: 'Move left',\n cursorRight: 'Move right',\n cursorUp: 'Move up',\n cursorDown: 'Move down',\n undo: 'Undo',\n redo: 'Redo',\n error: 'Error',\n warning: 'Warning',\n info: 'Info',\n hint: 'Hint',\n problems: 'Problems',\n problemAt: 'Line {line}, {severity}: {message}',\n itemAt: '{label}, {index} of {count}',\n details: 'Details',\n completions: 'Suggestions',\n signature: 'Parameter hints',\n diff: 'Diff',\n diffOriginal: 'Original',\n diffModified: 'Modified',\n diffPrevious: 'Previous change',\n diffNext: 'Next change',\n diffSplit: 'Side by side',\n diffInline: 'Inline',\n diffExpandAll: 'Expand all',\n diffCollapse: 'Collapse unchanged lines',\n diffUnchanged: '{count} unchanged lines',\n diffStats: '{added} added, {removed} removed',\n diffNoChanges: 'No changes',\n diffRemoved: 'Removed',\n diffAdded: 'Added',\n diffChangeAt: 'Change {index} of {count}, line {line}: {removed} removed, {added} added',\n}\n\nexport const codeLocales: Record<string, CodeMessages> = {\n 'zh-CN': zhCN,\n 'zh-TW': zhTW,\n en,\n}\n\n/** The code editor's texts, picked by the name of DouUI's current locale. Pass `messages` to override any of them. */\nexport function useCodeMessages(override?: MaybeRefOrGetter<Partial<CodeMessages> | undefined>) {\n const { locale } = useLocale()\n return computed<CodeMessages>(() => {\n const name = locale.value.name\n const base =\n codeLocales[name] ?? codeLocales[name.split('-')[0]!] ?? (name.startsWith('zh') ? zhCN : en)\n const extra = toValue(override)\n if (!extra) return base\n const out = { ...base }\n for (const [key, value] of Object.entries(extra))\n if (value !== undefined) out[key as keyof CodeMessages] = value\n return out\n })\n}\n\n/** Fills `{name}` placeholders. */\nexport const format = (text: string, params: Record<string, string | number>) =>\n text.replace(/\\{(\\w+)\\}/g, (match, key: string) => String(params[key] ?? match))\n"],"mappings":";;;AA0EA,IAAa,OAAqB;CAChC,QAAQ;CACR,QAAQ;CACR,UAAU;CACV,WAAW;CACX,aAAa;CACb,UAAU;CACV,KAAK;CACL,MAAM;CACN,OAAO;CACP,WAAW;CACX,gBAAgB;CAChB,MAAM;CACN,QAAQ;CACR,YAAY;CACZ,aAAa;CACb,UAAU;CACV,YAAY;CACZ,MAAM;CACN,MAAM;CACN,OAAO;CACP,SAAS;CACT,MAAM;CACN,MAAM;CACN,UAAU;CACV,WAAW;CACX,QAAQ;CACR,SAAS;CACT,aAAa;CACb,WAAW;CACX,MAAM;CACN,cAAc;CACd,cAAc;CACd,cAAc;CACd,UAAU;CACV,WAAW;CACX,YAAY;CACZ,eAAe;CACf,cAAc;CACd,eAAe;CACf,WAAW;CACX,eAAe;CACf,aAAa;CACb,WAAW;CACX,cACE;AACJ;AAEA,IAAa,OAAqB;CAChC,QAAQ;CACR,QAAQ;CACR,UAAU;CACV,WAAW;CACX,aAAa;CACb,UAAU;CACV,KAAK;CACL,MAAM;CACN,OAAO;CACP,WAAW;CACX,gBAAgB;CAChB,MAAM;CACN,QAAQ;CACR,YAAY;CACZ,aAAa;CACb,UAAU;CACV,YAAY;CACZ,MAAM;CACN,MAAM;CACN,OAAO;CACP,SAAS;CACT,MAAM;CACN,MAAM;CACN,UAAU;CACV,WAAW;CACX,QAAQ;CACR,SAAS;CACT,aAAa;CACb,WAAW;CACX,MAAM;CACN,cAAc;CACd,cAAc;CACd,cAAc;CACd,UAAU;CACV,WAAW;CACX,YAAY;CACZ,eAAe;CACf,cAAc;CACd,eAAe;CACf,WAAW;CACX,eAAe;CACf,aAAa;CACb,WAAW;CACX,cACE;AACJ;AAEA,IAAa,KAAmB;CAC9B,QAAQ;CACR,QAAQ;CACR,UAAU;CACV,WAAW;CACX,aAAa;CACb,UAAU;CACV,KAAK;CACL,MAAM;CACN,OAAO;CACP,WAAW;CACX,gBAAgB;CAChB,MAAM;CACN,QAAQ;CACR,YAAY;CACZ,aAAa;CACb,UAAU;CACV,YAAY;CACZ,MAAM;CACN,MAAM;CACN,OAAO;CACP,SAAS;CACT,MAAM;CACN,MAAM;CACN,UAAU;CACV,WAAW;CACX,QAAQ;CACR,SAAS;CACT,aAAa;CACb,WAAW;CACX,MAAM;CACN,cAAc;CACd,cAAc;CACd,cAAc;CACd,UAAU;CACV,WAAW;CACX,YAAY;CACZ,eAAe;CACf,cAAc;CACd,eAAe;CACf,WAAW;CACX,eAAe;CACf,aAAa;CACb,WAAW;CACX,cAAc;AAChB;AAEA,IAAa,cAA4C;CACvD,SAAS;CACT,SAAS;CACT;AACF;;AAGA,SAAgB,gBAAgB,UAAgE;CAC9F,MAAM,EAAE,WAAW,UAAU;CAC7B,OAAO,eAA6B;EAClC,MAAM,OAAO,OAAO,MAAM;EAC1B,MAAM,OACJ,YAAY,SAAS,YAAY,KAAK,MAAM,GAAG,CAAC,CAAC,QAAS,KAAK,WAAW,IAAI,IAAI,OAAO;EAC3F,MAAM,QAAQ,QAAQ,QAAQ;EAC9B,IAAI,CAAC,OAAO,OAAO;EACnB,MAAM,MAAM,EAAE,GAAG,KAAK;EACtB,KAAK,MAAM,CAAC,KAAK,UAAU,OAAO,QAAQ,KAAK,GAC7C,IAAI,UAAU,KAAA,GAAW,IAAI,OAA6B;EAC5D,OAAO;CACT,CAAC;AACH;;AAGA,IAAa,UAAU,MAAc,WACnC,KAAK,QAAQ,eAAe,OAAO,QAAgB,OAAO,OAAO,QAAQ,KAAK,CAAC"}
1
+ {"version":3,"file":"locale.js","names":[],"sources":["../src/locale.ts"],"sourcesContent":["import { useLocale } from 'dou-ui'\nimport { computed, toValue, type MaybeRefOrGetter } from 'vue'\n\nexport interface CodeMessages {\n /** The marker of a folded block, as a tooltip. */\n unfold: string\n /** Read out after folding: `{from}`, `{to}` are the hidden lines. */\n folded: string\n unfolded: string\n foldedAll: string\n unfoldedAll: string\n /** The toolbar over a selection on touch screens. */\n editMenu: string\n cut: string\n copy: string\n paste: string\n selectAll: string\n /** Toolbar button of a language server (`@dou-ui/code/lsp`): go to where the name is defined. */\n goToDefinition: string\n /** The bar of symbol keys on a touch screen. */\n keys: string\n /** The grip that moves the bar of symbol keys. */\n moveKeys: string\n /** The Tab key on that bar. */\n indent: string\n /** The stick at the end of the bar of keys, which moves the cursor. */\n moveCursor: string\n undo: string\n redo: string\n error: string\n warning: string\n info: string\n hint: string\n /** The box with the problems at a place in the text. */\n problems: string\n /** Read out when the cursor moves to a problem: `{line}`, `{severity}`, `{message}`. */\n problemAt: string\n /** Read out when a fix or a completion is picked: `{label}`, `{index}`, `{count}`. */\n itemAt: string\n /** The box with the text about a place, and its problems. */\n details: string\n /** The completion list. */\n completions: string\n /** The box with the parameters of a call. */\n signature: string\n /** The diff view's name. */\n diff: string\n /** The original side's label. */\n diffOriginal: string\n /** The modified side's label. */\n diffModified: string\n diffPrevious: string\n diffNext: string\n /** Shows the two sides next to each other. */\n diffSplit: string\n /** Shows the changes in one column. */\n diffInline: string\n /** Shows all the unchanged lines. */\n diffExpandAll: string\n /** Hides the unchanged lines again. */\n diffCollapse: string\n /** The bar over hidden unchanged lines: `{count}`. */\n diffUnchanged: string\n /** How many lines were added and removed: `{added}`, `{removed}`. */\n diffStats: string\n diffNoChanges: string\n /** A removed line, in the gutter. */\n diffRemoved: string\n /** An added line, in the gutter. */\n diffAdded: string\n /** Read out when moving to a change: `{index}`, `{count}`, `{line}`, `{removed}`, `{added}`. */\n diffChangeAt: string\n}\n\nexport const zhCN: CodeMessages = {\n unfold: '展开',\n folded: '已折叠第 {from}–{to} 行',\n unfolded: '已展开',\n foldedAll: '已全部折叠',\n unfoldedAll: '已全部展开',\n editMenu: '编辑',\n cut: '剪切',\n copy: '复制',\n paste: '粘贴',\n selectAll: '全选',\n goToDefinition: '跳到定义',\n keys: '符号栏',\n moveKeys: '移动符号栏',\n indent: '缩进',\n moveCursor: '移动光标',\n undo: '撤销',\n redo: '重做',\n error: '错误',\n warning: '警告',\n info: '信息',\n hint: '提示',\n problems: '问题',\n problemAt: '第 {line} 行,{severity}:{message}',\n itemAt: '{label},第 {index} 项,共 {count} 项',\n details: '说明',\n completions: '补全',\n signature: '参数提示',\n diff: '对比',\n diffOriginal: '原文',\n diffModified: '修改后',\n diffPrevious: '上一处改动',\n diffNext: '下一处改动',\n diffSplit: '并排显示',\n diffInline: '行内显示',\n diffExpandAll: '展开全部',\n diffCollapse: '折叠未改动的行',\n diffUnchanged: '{count} 行未改动',\n diffStats: '新增 {added} 行,删除 {removed} 行',\n diffNoChanges: '没有改动',\n diffRemoved: '删除',\n diffAdded: '新增',\n diffChangeAt:\n '第 {index} 处改动,共 {count} 处,第 {line} 行:删除 {removed} 行,新增 {added} 行',\n}\n\nexport const zhTW: CodeMessages = {\n unfold: '展開',\n folded: '已摺疊第 {from}–{to} 行',\n unfolded: '已展開',\n foldedAll: '已全部摺疊',\n unfoldedAll: '已全部展開',\n editMenu: '編輯',\n cut: '剪下',\n copy: '拷貝',\n paste: '貼上',\n selectAll: '全選',\n goToDefinition: '跳至定義',\n keys: '符號列',\n moveKeys: '移動符號列',\n indent: '縮排',\n moveCursor: '移動游標',\n undo: '復原',\n redo: '重做',\n error: '錯誤',\n warning: '警告',\n info: '資訊',\n hint: '提示',\n problems: '問題',\n problemAt: '第 {line} 行,{severity}:{message}',\n itemAt: '{label},第 {index} 項,共 {count} 項',\n details: '說明',\n completions: '自動完成',\n signature: '參數提示',\n diff: '對比',\n diffOriginal: '原文',\n diffModified: '修改後',\n diffPrevious: '上一處改動',\n diffNext: '下一處改動',\n diffSplit: '並排顯示',\n diffInline: '行內顯示',\n diffExpandAll: '展開全部',\n diffCollapse: '摺疊未改動的行',\n diffUnchanged: '{count} 行未改動',\n diffStats: '新增 {added} 行,刪除 {removed} 行',\n diffNoChanges: '沒有改動',\n diffRemoved: '刪除',\n diffAdded: '新增',\n diffChangeAt:\n '第 {index} 處改動,共 {count} 處,第 {line} 行:刪除 {removed} 行,新增 {added} 行',\n}\n\nexport const en: CodeMessages = {\n unfold: 'Unfold',\n folded: 'Folded lines {from}–{to}',\n unfolded: 'Unfolded',\n foldedAll: 'Folded all',\n unfoldedAll: 'Unfolded all',\n editMenu: 'Edit',\n cut: 'Cut',\n copy: 'Copy',\n paste: 'Paste',\n selectAll: 'Select all',\n goToDefinition: 'Go to definition',\n keys: 'Symbols',\n moveKeys: 'Move symbols',\n indent: 'Indent',\n moveCursor: 'Move cursor',\n undo: 'Undo',\n redo: 'Redo',\n error: 'Error',\n warning: 'Warning',\n info: 'Info',\n hint: 'Hint',\n problems: 'Problems',\n problemAt: 'Line {line}, {severity}: {message}',\n itemAt: '{label}, {index} of {count}',\n details: 'Details',\n completions: 'Suggestions',\n signature: 'Parameter hints',\n diff: 'Diff',\n diffOriginal: 'Original',\n diffModified: 'Modified',\n diffPrevious: 'Previous change',\n diffNext: 'Next change',\n diffSplit: 'Side by side',\n diffInline: 'Inline',\n diffExpandAll: 'Expand all',\n diffCollapse: 'Collapse unchanged lines',\n diffUnchanged: '{count} unchanged lines',\n diffStats: '{added} added, {removed} removed',\n diffNoChanges: 'No changes',\n diffRemoved: 'Removed',\n diffAdded: 'Added',\n diffChangeAt: 'Change {index} of {count}, line {line}: {removed} removed, {added} added',\n}\n\nexport const codeLocales: Record<string, CodeMessages> = {\n 'zh-CN': zhCN,\n 'zh-TW': zhTW,\n en,\n}\n\n/** The code editor's texts, picked by the name of DouUI's current locale. Pass `messages` to override any of them. */\nexport function useCodeMessages(override?: MaybeRefOrGetter<Partial<CodeMessages> | undefined>) {\n const { locale } = useLocale()\n return computed<CodeMessages>(() => {\n const name = locale.value.name\n const base =\n codeLocales[name] ?? codeLocales[name.split('-')[0]!] ?? (name.startsWith('zh') ? zhCN : en)\n const extra = toValue(override)\n if (!extra) return base\n const out = { ...base }\n for (const [key, value] of Object.entries(extra))\n if (value !== undefined) out[key as keyof CodeMessages] = value\n return out\n })\n}\n\n/** Fills `{name}` placeholders. */\nexport const format = (text: string, params: Record<string, string | number>) =>\n text.replace(/\\{(\\w+)\\}/g, (match, key: string) => String(params[key] ?? match))\n"],"mappings":";;;AA0EA,IAAa,OAAqB;CAChC,QAAQ;CACR,QAAQ;CACR,UAAU;CACV,WAAW;CACX,aAAa;CACb,UAAU;CACV,KAAK;CACL,MAAM;CACN,OAAO;CACP,WAAW;CACX,gBAAgB;CAChB,MAAM;CACN,UAAU;CACV,QAAQ;CACR,YAAY;CACZ,MAAM;CACN,MAAM;CACN,OAAO;CACP,SAAS;CACT,MAAM;CACN,MAAM;CACN,UAAU;CACV,WAAW;CACX,QAAQ;CACR,SAAS;CACT,aAAa;CACb,WAAW;CACX,MAAM;CACN,cAAc;CACd,cAAc;CACd,cAAc;CACd,UAAU;CACV,WAAW;CACX,YAAY;CACZ,eAAe;CACf,cAAc;CACd,eAAe;CACf,WAAW;CACX,eAAe;CACf,aAAa;CACb,WAAW;CACX,cACE;AACJ;AAEA,IAAa,OAAqB;CAChC,QAAQ;CACR,QAAQ;CACR,UAAU;CACV,WAAW;CACX,aAAa;CACb,UAAU;CACV,KAAK;CACL,MAAM;CACN,OAAO;CACP,WAAW;CACX,gBAAgB;CAChB,MAAM;CACN,UAAU;CACV,QAAQ;CACR,YAAY;CACZ,MAAM;CACN,MAAM;CACN,OAAO;CACP,SAAS;CACT,MAAM;CACN,MAAM;CACN,UAAU;CACV,WAAW;CACX,QAAQ;CACR,SAAS;CACT,aAAa;CACb,WAAW;CACX,MAAM;CACN,cAAc;CACd,cAAc;CACd,cAAc;CACd,UAAU;CACV,WAAW;CACX,YAAY;CACZ,eAAe;CACf,cAAc;CACd,eAAe;CACf,WAAW;CACX,eAAe;CACf,aAAa;CACb,WAAW;CACX,cACE;AACJ;AAEA,IAAa,KAAmB;CAC9B,QAAQ;CACR,QAAQ;C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