@dou-ui/code 0.1.0-alpha.20 → 0.1.0-alpha.22

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.
@@ -105,6 +105,10 @@ var code_editor_vue_vue_type_script_setup_true_lang_default = /*@__PURE__*/ defi
105
105
  type: Boolean,
106
106
  default: true
107
107
  },
108
+ scrollY: {
109
+ type: Boolean,
110
+ default: true
111
+ },
108
112
  activeLine: {
109
113
  type: Boolean,
110
114
  default: true
@@ -3278,11 +3282,11 @@ var code_editor_vue_vue_type_script_setup_true_lang_default = /*@__PURE__*/ defi
3278
3282
  function autoScroll() {
3279
3283
  if (!drag || !scroller.value) return;
3280
3284
  const rect = scroller.value.getBoundingClientRect();
3281
- const dy = drag.y < rect.top ? drag.y - rect.top : drag.y > rect.bottom ? drag.y - rect.bottom : 0;
3285
+ const dy = props.scrollY ? drag.y < rect.top ? drag.y - rect.top : drag.y > rect.bottom ? drag.y - rect.bottom : 0 : 0;
3282
3286
  const dx = drag.x < rect.left + gutterWidth.value ? drag.x - rect.left - gutterWidth.value : drag.x > rect.right ? drag.x - rect.right : 0;
3283
3287
  if (dy || dx) {
3284
- scroller.value.scrollTop += dy / 2;
3285
- scroller.value.scrollLeft += dx / 2;
3288
+ if (dy) scroller.value.scrollTop += dy / 2;
3289
+ if (dx) scroller.value.scrollLeft += dx / 2;
3286
3290
  onScroll();
3287
3291
  extendTo(drag);
3288
3292
  }
@@ -4061,12 +4065,14 @@ var code_editor_vue_vue_type_script_setup_true_lang_default = /*@__PURE__*/ defi
4061
4065
  const bottom = view.top + view.height - covered;
4062
4066
  const visibleTop = Math.max(rect.top, view.top);
4063
4067
  const visibleBottom = Math.min(rect.bottom, bottom);
4064
- if (at.bottom + room > visibleBottom && visibleBottom - visibleTop >= lh * 3) {
4065
- el.scrollTop += (at.bottom + room - visibleBottom) / ratio.value;
4066
- onScroll();
4067
- } else if (at.top - lh / 2 < visibleTop && visibleBottom - visibleTop >= lh * 3) {
4068
- el.scrollTop -= (visibleTop - at.top + lh / 2) / ratio.value;
4069
- onScroll();
4068
+ if (props.scrollY) {
4069
+ if (at.bottom + room > visibleBottom && visibleBottom - visibleTop >= lh * 3) {
4070
+ el.scrollTop += (at.bottom + room - visibleBottom) / ratio.value;
4071
+ onScroll();
4072
+ } else if (at.top - lh / 2 < visibleTop && visibleBottom - visibleTop >= lh * 3) {
4073
+ el.scrollTop -= (visibleTop - at.top + lh / 2) / ratio.value;
4074
+ onScroll();
4075
+ }
4070
4076
  }
4071
4077
  const after = coordsAtPos(mainRange(state.value.selection).head);
4072
4078
  if (!after || after.bottom + room <= bottom) return;
@@ -4139,7 +4145,7 @@ var code_editor_vue_vue_type_script_setup_true_lang_default = /*@__PURE__*/ defi
4139
4145
  const minimapCanvas = ref();
4140
4146
  /** The editor's own width, minimap included. */
4141
4147
  const rootWidth = ref(0);
4142
- const minimapOn = computed(() => !!props.minimap && mounted.value && rootWidth.value >= 480);
4148
+ const minimapOn = computed(() => !!props.minimap && props.scrollY && mounted.value && rootWidth.value >= 480);
4143
4149
  /** Where the minimap is: the row at its top (fractional), and the part in view as a box. */
4144
4150
  const minimap = computed(() => {
4145
4151
  if (!minimapOn.value) return null;
@@ -4335,8 +4341,9 @@ var code_editor_vue_vue_type_script_setup_true_lang_default = /*@__PURE__*/ defi
4335
4341
  function onScroll() {
4336
4342
  const el = scroller.value;
4337
4343
  if (!el) return;
4344
+ if (!props.scrollY && el.scrollTop !== 0) el.scrollTop = 0;
4338
4345
  const { top, left } = scrollPositionOf(el);
4339
- scrollTop.value = top;
4346
+ scrollTop.value = props.scrollY ? top : 0;
4340
4347
  scrollLeft.value = left;
4341
4348
  updateClip();
4342
4349
  }
@@ -4349,17 +4356,27 @@ var code_editor_vue_vue_type_script_setup_true_lang_default = /*@__PURE__*/ defi
4349
4356
  const view = el.clientHeight;
4350
4357
  if (view < lh * 3) return;
4351
4358
  const at = place(line.number, line.text, pos - line.from);
4352
- const y = at.top - shift.value;
4353
- const top = el.scrollTop * ratio.value;
4354
- const margin = Math.min(lh, view / 4);
4355
- if (y - margin < top) el.scrollTop = Math.max(0, (y - margin) / ratio.value);
4356
- else if (y + lh + margin > top + view) el.scrollTop = (y + lh + margin - view) / ratio.value;
4359
+ if (props.scrollY) {
4360
+ const y = at.top - shift.value;
4361
+ const top = el.scrollTop * ratio.value;
4362
+ const margin = Math.min(lh, view / 4);
4363
+ if (y - margin < top) el.scrollTop = Math.max(0, (y - margin) / ratio.value);
4364
+ else if (y + lh + margin > top + view) el.scrollTop = (y + lh + margin - view) / ratio.value;
4365
+ }
4357
4366
  const x = pad.x + at.x;
4358
4367
  const width = el.clientWidth - gutterWidth.value;
4359
4368
  if (x - measure.cell * 2 < el.scrollLeft) el.scrollLeft = Math.max(0, x - measure.cell * 4);
4360
4369
  else if (x + measure.cell * 2 > el.scrollLeft + width) el.scrollLeft = x + measure.cell * 4 - width;
4361
4370
  onScroll();
4362
4371
  }
4372
+ watch(() => props.scrollY, (enabled) => {
4373
+ const el = scroller.value;
4374
+ if (!enabled && el) {
4375
+ if (el.scrollTop !== 0) el.scrollTop = 0;
4376
+ scrollTop.value = 0;
4377
+ updateClip();
4378
+ }
4379
+ });
4363
4380
  let clipFrame = 0;
4364
4381
  /** For an editor taller than the window, draws only the lines inside the window. */
4365
4382
  function updateClip() {
@@ -4571,7 +4588,8 @@ var code_editor_vue_vue_type_script_setup_true_lang_default = /*@__PURE__*/ defi
4571
4588
  unref(ns).is("disabled", !!__props.disabled),
4572
4589
  unref(ns).is("foldable", __props.foldable),
4573
4590
  unref(ns).is("wrap", __props.wrap),
4574
- unref(ns).is("bordered", __props.bordered)
4591
+ unref(ns).is("bordered", __props.bordered),
4592
+ unref(ns).is("scroll-y", __props.scrollY)
4575
4593
  ]),
4576
4594
  style: normalizeStyle({
4577
4595
  "--dou-code-editor-gutter": `${gutterWidth.value}px`,