@veltra/desktop 1.2.17 → 1.2.18
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/components/action/action-group.vue.d.ts +2 -2
- package/dist/components/action/action.vue.d.ts +1 -1
- package/dist/components/auto-complete/auto-complete.vue.d.ts +1 -1
- package/dist/components/batch-edit/batch-edit.vue.d.ts +2 -2
- package/dist/components/cascade/cascade.vue.d.ts +7 -7
- package/dist/components/checkbox/checkbox-button.vue.d.ts +1 -1
- package/dist/components/checkbox-group/checkbox-group.vue.d.ts +1 -1
- package/dist/components/code-editor/basic-setup.js +1 -1
- package/dist/components/code-editor/code-editor.js +13 -8
- package/dist/components/code-editor/code-editor.js.map +1 -1
- package/dist/components/date-panel/date-panel.vue.d.ts +1 -1
- package/dist/components/date-picker/date-picker.vue.d.ts +2 -2
- package/dist/components/date-range-picker/date-range-picker.vue.d.ts +2 -2
- package/dist/components/empty/empty.vue.d.ts +1 -1
- package/dist/components/input/input.vue.d.ts +3 -3
- package/dist/components/multi-select/multi-select.vue.d.ts +3 -3
- package/dist/components/multi-tree-select/multi-tree-select.vue.d.ts +6 -6
- package/dist/components/number-input/number-input.vue.d.ts +3 -3
- package/dist/components/pop-confirm/pop-confirm.vue.d.ts +1 -1
- package/dist/components/progress-nodes/progress-nodes.vue.d.ts +1 -1
- package/dist/components/radio-group/radio-group.vue.d.ts +1 -1
- package/dist/components/select/select.vue.d.ts +2 -2
- package/dist/components/steps/steps.vue.d.ts +2 -2
- package/dist/components/tabs/tabs-horizontal.vue.d.ts +1 -1
- package/dist/components/tabs/tabs.vue.d.ts +1 -1
- package/dist/components/textarea/textarea.vue.d.ts +3 -3
- package/dist/components/tip/tip.vue.d.ts +1 -1
- package/dist/components/tree/tree.vue.d.ts +2 -2
- package/dist/components/tree-select/tree-select.vue.d.ts +5 -5
- package/dist/components/watermark/watermark.vue.d.ts +1 -1
- package/dist/node_modules/.bun/@codemirror_autocomplete@6.20.3/node_modules/@codemirror/autocomplete/dist/index.js +1 -1
- package/dist/node_modules/.bun/@codemirror_commands@6.10.4/node_modules/@codemirror/commands/dist/index.js +2 -2
- package/dist/node_modules/.bun/@codemirror_lang-java@6.0.2/node_modules/@codemirror/lang-java/dist/index.js +1 -1
- package/dist/node_modules/.bun/@codemirror_lang-javascript@6.2.5/node_modules/@codemirror/lang-javascript/dist/index.js +3 -3
- package/dist/node_modules/.bun/@codemirror_lang-sql@6.10.0/node_modules/@codemirror/lang-sql/dist/index.js +1 -1
- package/dist/node_modules/.bun/@codemirror_language@6.12.4/node_modules/@codemirror/language/dist/index.js +3 -3
- package/dist/node_modules/.bun/@codemirror_lint@6.9.7/node_modules/@codemirror/lint/dist/index.js +1 -1
- package/dist/node_modules/.bun/@codemirror_search@6.7.1/node_modules/@codemirror/search/dist/index.js +1 -1
- package/dist/node_modules/.bun/@codemirror_theme-one-dark@6.1.3/node_modules/@codemirror/theme-one-dark/dist/index.js +1 -1
- package/dist/node_modules/.bun/@codemirror_view@6.43.4/node_modules/@codemirror/view/dist/index.js +915 -1
- package/dist/node_modules/.bun/@codemirror_view@6.43.4/node_modules/@codemirror/view/dist/index.js.map +1 -1
- package/dist/node_modules/.bun/@lezer_java@1.1.3/node_modules/@lezer/java/dist/index.js +1 -1
- package/dist/node_modules/.bun/@lezer_javascript@1.5.4/node_modules/@lezer/javascript/dist/index.js +1 -1
- package/dist/node_modules/.bun/@lezer_json@1.0.3/node_modules/@lezer/json/dist/index.js +1 -1
- package/package.json +6 -6
- package/src/components/code-editor/code-editor.vue +12 -7
- package/dist/node_modules/.bun/@codemirror_view@6.43.3/node_modules/@codemirror/view/dist/index.js +0 -8862
- package/dist/node_modules/.bun/@codemirror_view@6.43.3/node_modules/@codemirror/view/dist/index.js.map +0 -1
package/dist/node_modules/.bun/@codemirror_view@6.43.4/node_modules/@codemirror/view/dist/index.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { Annotation, ChangeSet, CharCategory, EditorSelection, EditorState, Facet, MapMode, Prec, RangeSet, RangeSetBuilder, RangeValue, StateEffect, StateField, Text, Transaction, codePointAt, codePointSize, combineConfig, countColumn, findClusterBreak, findColumn } from "../../../../../@codemirror_state@6.7.0/node_modules/@codemirror/state/dist/index.js";
|
|
2
2
|
import { StyleModule } from "../../../../../style-mod@4.1.3/node_modules/style-mod/src/style-mod.js";
|
|
3
3
|
import { base, keyName, shift } from "../../../../../w3c-keyname@2.2.8/node_modules/w3c-keyname/index.js";
|
|
4
|
+
import crelt from "../../../../../crelt@1.0.6/node_modules/crelt/index.js";
|
|
4
5
|
//#region ../../node_modules/.bun/@codemirror+view@6.43.4/node_modules/@codemirror/view/dist/index.js
|
|
5
6
|
let nav = typeof navigator != "undefined" ? navigator : {
|
|
6
7
|
userAgent: "",
|
|
@@ -7491,6 +7492,14 @@ function getKeymap(state) {
|
|
|
7491
7492
|
if (!map) Keymaps.set(bindings, map = buildKeymap(bindings.reduce((a, b) => a.concat(b), [])));
|
|
7492
7493
|
return map;
|
|
7493
7494
|
}
|
|
7495
|
+
/**
|
|
7496
|
+
Run the key handlers registered for a given scope. The event
|
|
7497
|
+
object should be a `"keydown"` event. Returns true if any of the
|
|
7498
|
+
handlers handled it.
|
|
7499
|
+
*/
|
|
7500
|
+
function runScopeHandlers(view, event, scope) {
|
|
7501
|
+
return runHandlers(getKeymap(view.state), event, view, scope);
|
|
7502
|
+
}
|
|
7494
7503
|
let storedPrefix = null;
|
|
7495
7504
|
const PrefixTimeout = 4e3;
|
|
7496
7505
|
function buildKeymap(bindings, platform = currentPlatform) {
|
|
@@ -8398,6 +8407,56 @@ function crosshairCursor(options = {}) {
|
|
|
8398
8407
|
return ((_a = view.plugin(plugin)) === null || _a === void 0 ? void 0 : _a.isDown) ? showCrosshair : null;
|
|
8399
8408
|
})];
|
|
8400
8409
|
}
|
|
8410
|
+
const Outside = "-10000px";
|
|
8411
|
+
var TooltipViewManager = class {
|
|
8412
|
+
constructor(view, facet, createTooltipView, removeTooltipView) {
|
|
8413
|
+
this.facet = facet;
|
|
8414
|
+
this.createTooltipView = createTooltipView;
|
|
8415
|
+
this.removeTooltipView = removeTooltipView;
|
|
8416
|
+
this.input = view.state.facet(facet);
|
|
8417
|
+
this.tooltips = this.input.filter((t) => t);
|
|
8418
|
+
let prev = null;
|
|
8419
|
+
this.tooltipViews = this.tooltips.map((t) => prev = createTooltipView(t, prev));
|
|
8420
|
+
}
|
|
8421
|
+
update(update, above) {
|
|
8422
|
+
var _a;
|
|
8423
|
+
let input = update.state.facet(this.facet);
|
|
8424
|
+
let tooltips = input.filter((x) => x);
|
|
8425
|
+
if (input === this.input) {
|
|
8426
|
+
for (let t of this.tooltipViews) if (t.update) t.update(update);
|
|
8427
|
+
return false;
|
|
8428
|
+
}
|
|
8429
|
+
let tooltipViews = [], newAbove = above ? [] : null;
|
|
8430
|
+
for (let i = 0; i < tooltips.length; i++) {
|
|
8431
|
+
let tip = tooltips[i], known = -1;
|
|
8432
|
+
if (!tip) continue;
|
|
8433
|
+
for (let i = 0; i < this.tooltips.length; i++) {
|
|
8434
|
+
let other = this.tooltips[i];
|
|
8435
|
+
if (other && other.create == tip.create) known = i;
|
|
8436
|
+
}
|
|
8437
|
+
if (known < 0) {
|
|
8438
|
+
tooltipViews[i] = this.createTooltipView(tip, i ? tooltipViews[i - 1] : null);
|
|
8439
|
+
if (newAbove) newAbove[i] = !!tip.above;
|
|
8440
|
+
} else {
|
|
8441
|
+
let tooltipView = tooltipViews[i] = this.tooltipViews[known];
|
|
8442
|
+
if (newAbove) newAbove[i] = above[known];
|
|
8443
|
+
if (tooltipView.update) tooltipView.update(update);
|
|
8444
|
+
}
|
|
8445
|
+
}
|
|
8446
|
+
for (let t of this.tooltipViews) if (tooltipViews.indexOf(t) < 0) {
|
|
8447
|
+
this.removeTooltipView(t);
|
|
8448
|
+
(_a = t.destroy) === null || _a === void 0 || _a.call(t);
|
|
8449
|
+
}
|
|
8450
|
+
if (above) {
|
|
8451
|
+
newAbove.forEach((val, i) => above[i] = val);
|
|
8452
|
+
above.length = newAbove.length;
|
|
8453
|
+
}
|
|
8454
|
+
this.input = input;
|
|
8455
|
+
this.tooltips = tooltips;
|
|
8456
|
+
this.tooltipViews = tooltipViews;
|
|
8457
|
+
return true;
|
|
8458
|
+
}
|
|
8459
|
+
};
|
|
8401
8460
|
/**
|
|
8402
8461
|
Creates an extension that configures tooltip behavior.
|
|
8403
8462
|
*/
|
|
@@ -8421,6 +8480,838 @@ const tooltipConfig = /*@__PURE__*/ Facet.define({ combine: (values) => {
|
|
|
8421
8480
|
tooltipSpace: ((_c = values.find((conf) => conf.tooltipSpace)) === null || _c === void 0 ? void 0 : _c.tooltipSpace) || windowSpace
|
|
8422
8481
|
};
|
|
8423
8482
|
} });
|
|
8483
|
+
const knownHeight = /*@__PURE__*/ new WeakMap();
|
|
8484
|
+
const tooltipPlugin = /*@__PURE__*/ ViewPlugin.fromClass(class {
|
|
8485
|
+
constructor(view) {
|
|
8486
|
+
this.view = view;
|
|
8487
|
+
this.above = [];
|
|
8488
|
+
this.inView = true;
|
|
8489
|
+
this.madeAbsolute = false;
|
|
8490
|
+
this.lastTransaction = 0;
|
|
8491
|
+
this.measureTimeout = -1;
|
|
8492
|
+
let config = view.state.facet(tooltipConfig);
|
|
8493
|
+
this.position = config.position;
|
|
8494
|
+
this.parent = config.parent;
|
|
8495
|
+
this.classes = view.themeClasses;
|
|
8496
|
+
this.createContainer();
|
|
8497
|
+
this.measureReq = {
|
|
8498
|
+
read: this.readMeasure.bind(this),
|
|
8499
|
+
write: this.writeMeasure.bind(this),
|
|
8500
|
+
key: this
|
|
8501
|
+
};
|
|
8502
|
+
this.resizeObserver = typeof ResizeObserver == "function" ? new ResizeObserver(() => this.measureSoon()) : null;
|
|
8503
|
+
this.manager = new TooltipViewManager(view, showTooltip, (t, p) => this.createTooltip(t, p), (t) => {
|
|
8504
|
+
if (this.resizeObserver) this.resizeObserver.unobserve(t.dom);
|
|
8505
|
+
t.dom.remove();
|
|
8506
|
+
});
|
|
8507
|
+
this.above = this.manager.tooltips.map((t) => !!t.above);
|
|
8508
|
+
this.intersectionObserver = typeof IntersectionObserver == "function" ? new IntersectionObserver((entries) => {
|
|
8509
|
+
if (Date.now() > this.lastTransaction - 50 && entries.length > 0 && entries[entries.length - 1].intersectionRatio < 1) this.measureSoon();
|
|
8510
|
+
}, { threshold: [1] }) : null;
|
|
8511
|
+
this.observeIntersection();
|
|
8512
|
+
view.win.addEventListener("resize", this.measureSoon = this.measureSoon.bind(this));
|
|
8513
|
+
this.maybeMeasure();
|
|
8514
|
+
}
|
|
8515
|
+
createContainer() {
|
|
8516
|
+
if (this.parent) {
|
|
8517
|
+
this.container = document.createElement("div");
|
|
8518
|
+
this.container.style.position = "relative";
|
|
8519
|
+
this.container.className = this.view.themeClasses;
|
|
8520
|
+
this.parent.appendChild(this.container);
|
|
8521
|
+
} else this.container = this.view.dom;
|
|
8522
|
+
}
|
|
8523
|
+
observeIntersection() {
|
|
8524
|
+
if (this.intersectionObserver) {
|
|
8525
|
+
this.intersectionObserver.disconnect();
|
|
8526
|
+
for (let tooltip of this.manager.tooltipViews) this.intersectionObserver.observe(tooltip.dom);
|
|
8527
|
+
}
|
|
8528
|
+
}
|
|
8529
|
+
measureSoon() {
|
|
8530
|
+
if (this.measureTimeout < 0) this.measureTimeout = setTimeout(() => {
|
|
8531
|
+
this.measureTimeout = -1;
|
|
8532
|
+
this.maybeMeasure();
|
|
8533
|
+
}, 50);
|
|
8534
|
+
}
|
|
8535
|
+
update(update) {
|
|
8536
|
+
if (update.transactions.length) this.lastTransaction = Date.now();
|
|
8537
|
+
let updated = this.manager.update(update, this.above);
|
|
8538
|
+
if (updated) this.observeIntersection();
|
|
8539
|
+
let shouldMeasure = updated || update.geometryChanged;
|
|
8540
|
+
let newConfig = update.state.facet(tooltipConfig);
|
|
8541
|
+
if (newConfig.position != this.position && !this.madeAbsolute) {
|
|
8542
|
+
this.position = newConfig.position;
|
|
8543
|
+
for (let t of this.manager.tooltipViews) t.dom.style.position = this.position;
|
|
8544
|
+
shouldMeasure = true;
|
|
8545
|
+
}
|
|
8546
|
+
if (newConfig.parent != this.parent) {
|
|
8547
|
+
if (this.parent) this.container.remove();
|
|
8548
|
+
this.parent = newConfig.parent;
|
|
8549
|
+
this.createContainer();
|
|
8550
|
+
for (let t of this.manager.tooltipViews) this.container.appendChild(t.dom);
|
|
8551
|
+
shouldMeasure = true;
|
|
8552
|
+
} else if (this.parent && this.view.themeClasses != this.classes) this.classes = this.container.className = this.view.themeClasses;
|
|
8553
|
+
if (shouldMeasure) this.maybeMeasure();
|
|
8554
|
+
}
|
|
8555
|
+
createTooltip(tooltip, prev) {
|
|
8556
|
+
let tooltipView = tooltip.create(this.view);
|
|
8557
|
+
let before = prev ? prev.dom : null;
|
|
8558
|
+
tooltipView.dom.classList.add("cm-tooltip");
|
|
8559
|
+
if (tooltip.arrow && !tooltipView.dom.querySelector(".cm-tooltip > .cm-tooltip-arrow")) {
|
|
8560
|
+
let arrow = document.createElement("div");
|
|
8561
|
+
arrow.className = "cm-tooltip-arrow";
|
|
8562
|
+
tooltipView.dom.appendChild(arrow);
|
|
8563
|
+
}
|
|
8564
|
+
tooltipView.dom.style.position = this.position;
|
|
8565
|
+
tooltipView.dom.style.top = Outside;
|
|
8566
|
+
tooltipView.dom.style.left = "0px";
|
|
8567
|
+
this.container.insertBefore(tooltipView.dom, before);
|
|
8568
|
+
if (tooltipView.mount) tooltipView.mount(this.view);
|
|
8569
|
+
if (this.resizeObserver) this.resizeObserver.observe(tooltipView.dom);
|
|
8570
|
+
return tooltipView;
|
|
8571
|
+
}
|
|
8572
|
+
destroy() {
|
|
8573
|
+
var _a, _b, _c;
|
|
8574
|
+
this.view.win.removeEventListener("resize", this.measureSoon);
|
|
8575
|
+
for (let tooltipView of this.manager.tooltipViews) {
|
|
8576
|
+
tooltipView.dom.remove();
|
|
8577
|
+
(_a = tooltipView.destroy) === null || _a === void 0 || _a.call(tooltipView);
|
|
8578
|
+
}
|
|
8579
|
+
if (this.parent) this.container.remove();
|
|
8580
|
+
(_b = this.resizeObserver) === null || _b === void 0 || _b.disconnect();
|
|
8581
|
+
(_c = this.intersectionObserver) === null || _c === void 0 || _c.disconnect();
|
|
8582
|
+
clearTimeout(this.measureTimeout);
|
|
8583
|
+
}
|
|
8584
|
+
readMeasure() {
|
|
8585
|
+
let scaleX = 1, scaleY = 1, makeAbsolute = false;
|
|
8586
|
+
if (this.position == "fixed" && this.manager.tooltipViews.length) {
|
|
8587
|
+
let { dom } = this.manager.tooltipViews[0];
|
|
8588
|
+
if (browser.safari) {
|
|
8589
|
+
let rect = dom.getBoundingClientRect();
|
|
8590
|
+
makeAbsolute = Math.abs(rect.top + 1e4) > 1 || Math.abs(rect.left) > 1;
|
|
8591
|
+
} else makeAbsolute = !!dom.offsetParent && dom.offsetParent != this.container.ownerDocument.body;
|
|
8592
|
+
}
|
|
8593
|
+
if (makeAbsolute || this.position == "absolute") if (this.parent) {
|
|
8594
|
+
let rect = this.parent.getBoundingClientRect();
|
|
8595
|
+
if (rect.width && rect.height) {
|
|
8596
|
+
scaleX = rect.width / this.parent.offsetWidth;
|
|
8597
|
+
scaleY = rect.height / this.parent.offsetHeight;
|
|
8598
|
+
}
|
|
8599
|
+
} else ({scaleX, scaleY} = this.view.viewState);
|
|
8600
|
+
let visible = this.view.scrollDOM.getBoundingClientRect(), margins = getScrollMargins(this.view);
|
|
8601
|
+
return {
|
|
8602
|
+
visible: {
|
|
8603
|
+
left: visible.left + margins.left,
|
|
8604
|
+
top: visible.top + margins.top,
|
|
8605
|
+
right: visible.right - margins.right,
|
|
8606
|
+
bottom: visible.bottom - margins.bottom
|
|
8607
|
+
},
|
|
8608
|
+
parent: this.parent ? this.container.getBoundingClientRect() : this.view.dom.getBoundingClientRect(),
|
|
8609
|
+
pos: this.manager.tooltips.map((t, i) => {
|
|
8610
|
+
let tv = this.manager.tooltipViews[i];
|
|
8611
|
+
return tv.getCoords ? tv.getCoords(t.pos) : this.view.coordsAtPos(t.pos);
|
|
8612
|
+
}),
|
|
8613
|
+
size: this.manager.tooltipViews.map(({ dom }) => dom.getBoundingClientRect()),
|
|
8614
|
+
space: this.view.state.facet(tooltipConfig).tooltipSpace(this.view),
|
|
8615
|
+
scaleX,
|
|
8616
|
+
scaleY,
|
|
8617
|
+
makeAbsolute
|
|
8618
|
+
};
|
|
8619
|
+
}
|
|
8620
|
+
writeMeasure(measured) {
|
|
8621
|
+
var _a;
|
|
8622
|
+
if (measured.makeAbsolute) {
|
|
8623
|
+
this.madeAbsolute = true;
|
|
8624
|
+
this.position = "absolute";
|
|
8625
|
+
for (let t of this.manager.tooltipViews) t.dom.style.position = "absolute";
|
|
8626
|
+
}
|
|
8627
|
+
let { visible, space, scaleX, scaleY } = measured;
|
|
8628
|
+
let others = [];
|
|
8629
|
+
for (let i = 0; i < this.manager.tooltips.length; i++) {
|
|
8630
|
+
let tooltip = this.manager.tooltips[i], tView = this.manager.tooltipViews[i], { dom } = tView;
|
|
8631
|
+
let pos = measured.pos[i], size = measured.size[i];
|
|
8632
|
+
if (!pos || tooltip.clip !== false && (pos.bottom <= Math.max(visible.top, space.top) || pos.top >= Math.min(visible.bottom, space.bottom) || pos.right < Math.max(visible.left, space.left) - .1 || pos.left > Math.min(visible.right, space.right) + .1)) {
|
|
8633
|
+
dom.style.top = Outside;
|
|
8634
|
+
continue;
|
|
8635
|
+
}
|
|
8636
|
+
let arrow = tooltip.arrow ? tView.dom.querySelector(".cm-tooltip-arrow") : null;
|
|
8637
|
+
let arrowHeight = arrow ? 7 : 0;
|
|
8638
|
+
let width = size.right - size.left, height = (_a = knownHeight.get(tView)) !== null && _a !== void 0 ? _a : size.bottom - size.top;
|
|
8639
|
+
let offset = tView.offset || noOffset, ltr = this.view.textDirection == Direction.LTR;
|
|
8640
|
+
let left = size.width > space.right - space.left ? ltr ? space.left : space.right - size.width : ltr ? Math.max(space.left, Math.min(pos.left - (arrow ? 14 : 0) + offset.x, space.right - width)) : Math.min(Math.max(space.left, pos.left - width + (arrow ? 14 : 0) - offset.x), space.right - width);
|
|
8641
|
+
let above = this.above[i];
|
|
8642
|
+
if (!tooltip.strictSide && (above ? pos.top - height - arrowHeight - offset.y < space.top : pos.bottom + height + arrowHeight + offset.y > space.bottom) && above == space.bottom - pos.bottom > pos.top - space.top) above = this.above[i] = !above;
|
|
8643
|
+
let spaceVert = (above ? pos.top - space.top : space.bottom - pos.bottom) - arrowHeight;
|
|
8644
|
+
if (spaceVert < height && tView.resize !== false) {
|
|
8645
|
+
if (spaceVert < this.view.defaultLineHeight) {
|
|
8646
|
+
dom.style.top = Outside;
|
|
8647
|
+
continue;
|
|
8648
|
+
}
|
|
8649
|
+
knownHeight.set(tView, height);
|
|
8650
|
+
dom.style.height = (height = spaceVert) / scaleY + "px";
|
|
8651
|
+
} else if (dom.style.height) dom.style.height = "";
|
|
8652
|
+
let top = above ? pos.top - height - arrowHeight - offset.y : pos.bottom + arrowHeight + offset.y;
|
|
8653
|
+
let right = left + width;
|
|
8654
|
+
if (tView.overlap !== true) {
|
|
8655
|
+
for (let r of others) if (r.left < right && r.right > left && r.top < top + height && r.bottom > top) top = above ? r.top - height - 2 - arrowHeight : r.bottom + arrowHeight + 2;
|
|
8656
|
+
}
|
|
8657
|
+
if (this.position == "absolute") {
|
|
8658
|
+
dom.style.top = (top - measured.parent.top) / scaleY + "px";
|
|
8659
|
+
setLeftStyle(dom, (left - measured.parent.left) / scaleX);
|
|
8660
|
+
} else {
|
|
8661
|
+
dom.style.top = top / scaleY + "px";
|
|
8662
|
+
setLeftStyle(dom, left / scaleX);
|
|
8663
|
+
}
|
|
8664
|
+
if (arrow) {
|
|
8665
|
+
let arrowLeft = pos.left + (ltr ? offset.x : -offset.x) - (left + 14 - 7);
|
|
8666
|
+
arrow.style.left = arrowLeft / scaleX + "px";
|
|
8667
|
+
}
|
|
8668
|
+
if (tView.overlap !== true) others.push({
|
|
8669
|
+
left,
|
|
8670
|
+
top,
|
|
8671
|
+
right,
|
|
8672
|
+
bottom: top + height
|
|
8673
|
+
});
|
|
8674
|
+
dom.classList.toggle("cm-tooltip-above", above);
|
|
8675
|
+
dom.classList.toggle("cm-tooltip-below", !above);
|
|
8676
|
+
if (tView.positioned) tView.positioned(measured.space);
|
|
8677
|
+
}
|
|
8678
|
+
}
|
|
8679
|
+
maybeMeasure() {
|
|
8680
|
+
if (this.manager.tooltips.length) {
|
|
8681
|
+
if (this.view.inView) this.view.requestMeasure(this.measureReq);
|
|
8682
|
+
if (this.inView != this.view.inView) {
|
|
8683
|
+
this.inView = this.view.inView;
|
|
8684
|
+
if (!this.inView) for (let tv of this.manager.tooltipViews) tv.dom.style.top = Outside;
|
|
8685
|
+
}
|
|
8686
|
+
}
|
|
8687
|
+
}
|
|
8688
|
+
}, { eventObservers: { scroll() {
|
|
8689
|
+
this.maybeMeasure();
|
|
8690
|
+
} } });
|
|
8691
|
+
function setLeftStyle(elt, value) {
|
|
8692
|
+
let current = parseInt(elt.style.left, 10);
|
|
8693
|
+
if (isNaN(current) || Math.abs(value - current) > 1) elt.style.left = value + "px";
|
|
8694
|
+
}
|
|
8695
|
+
const baseTheme = /*@__PURE__*/ EditorView.baseTheme({
|
|
8696
|
+
".cm-tooltip": {
|
|
8697
|
+
zIndex: 500,
|
|
8698
|
+
boxSizing: "border-box"
|
|
8699
|
+
},
|
|
8700
|
+
"&light .cm-tooltip": {
|
|
8701
|
+
border: "1px solid #bbb",
|
|
8702
|
+
backgroundColor: "#f5f5f5"
|
|
8703
|
+
},
|
|
8704
|
+
"&light .cm-tooltip-section:not(:first-child)": { borderTop: "1px solid #bbb" },
|
|
8705
|
+
"&dark .cm-tooltip": {
|
|
8706
|
+
backgroundColor: "#333338",
|
|
8707
|
+
color: "white"
|
|
8708
|
+
},
|
|
8709
|
+
".cm-tooltip-arrow": {
|
|
8710
|
+
height: `7px`,
|
|
8711
|
+
width: `14px`,
|
|
8712
|
+
position: "absolute",
|
|
8713
|
+
zIndex: -1,
|
|
8714
|
+
overflow: "hidden",
|
|
8715
|
+
"&:before, &:after": {
|
|
8716
|
+
content: "''",
|
|
8717
|
+
position: "absolute",
|
|
8718
|
+
width: 0,
|
|
8719
|
+
height: 0,
|
|
8720
|
+
borderLeft: `7px solid transparent`,
|
|
8721
|
+
borderRight: `7px solid transparent`
|
|
8722
|
+
},
|
|
8723
|
+
".cm-tooltip-above &": {
|
|
8724
|
+
bottom: `-7px`,
|
|
8725
|
+
"&:before": { borderTop: `7px solid #bbb` },
|
|
8726
|
+
"&:after": {
|
|
8727
|
+
borderTop: `7px solid #f5f5f5`,
|
|
8728
|
+
bottom: "1px"
|
|
8729
|
+
}
|
|
8730
|
+
},
|
|
8731
|
+
".cm-tooltip-below &": {
|
|
8732
|
+
top: `-7px`,
|
|
8733
|
+
"&:before": { borderBottom: `7px solid #bbb` },
|
|
8734
|
+
"&:after": {
|
|
8735
|
+
borderBottom: `7px solid #f5f5f5`,
|
|
8736
|
+
top: "1px"
|
|
8737
|
+
}
|
|
8738
|
+
}
|
|
8739
|
+
},
|
|
8740
|
+
"&dark .cm-tooltip .cm-tooltip-arrow": {
|
|
8741
|
+
"&:before": {
|
|
8742
|
+
borderTopColor: "#333338",
|
|
8743
|
+
borderBottomColor: "#333338"
|
|
8744
|
+
},
|
|
8745
|
+
"&:after": {
|
|
8746
|
+
borderTopColor: "transparent",
|
|
8747
|
+
borderBottomColor: "transparent"
|
|
8748
|
+
}
|
|
8749
|
+
}
|
|
8750
|
+
});
|
|
8751
|
+
const noOffset = {
|
|
8752
|
+
x: 0,
|
|
8753
|
+
y: 0
|
|
8754
|
+
};
|
|
8755
|
+
/**
|
|
8756
|
+
Facet to which an extension can add a value to show a tooltip.
|
|
8757
|
+
*/
|
|
8758
|
+
const showTooltip = /*@__PURE__*/ Facet.define({ enables: [tooltipPlugin, baseTheme] });
|
|
8759
|
+
const showHoverTooltip = /*@__PURE__*/ Facet.define({ combine: (inputs) => inputs.reduce((a, i) => a.concat(i), []) });
|
|
8760
|
+
var HoverTooltipHost = class HoverTooltipHost {
|
|
8761
|
+
static create(view) {
|
|
8762
|
+
return new HoverTooltipHost(view);
|
|
8763
|
+
}
|
|
8764
|
+
constructor(view) {
|
|
8765
|
+
this.view = view;
|
|
8766
|
+
this.mounted = false;
|
|
8767
|
+
this.dom = document.createElement("div");
|
|
8768
|
+
this.dom.classList.add("cm-tooltip-hover");
|
|
8769
|
+
this.manager = new TooltipViewManager(view, showHoverTooltip, (t, p) => this.createHostedView(t, p), (t) => t.dom.remove());
|
|
8770
|
+
}
|
|
8771
|
+
createHostedView(tooltip, prev) {
|
|
8772
|
+
let hostedView = tooltip.create(this.view);
|
|
8773
|
+
hostedView.dom.classList.add("cm-tooltip-section");
|
|
8774
|
+
this.dom.insertBefore(hostedView.dom, prev ? prev.dom.nextSibling : this.dom.firstChild);
|
|
8775
|
+
if (this.mounted && hostedView.mount) hostedView.mount(this.view);
|
|
8776
|
+
return hostedView;
|
|
8777
|
+
}
|
|
8778
|
+
mount(view) {
|
|
8779
|
+
for (let hostedView of this.manager.tooltipViews) if (hostedView.mount) hostedView.mount(view);
|
|
8780
|
+
this.mounted = true;
|
|
8781
|
+
}
|
|
8782
|
+
positioned(space) {
|
|
8783
|
+
for (let hostedView of this.manager.tooltipViews) if (hostedView.positioned) hostedView.positioned(space);
|
|
8784
|
+
}
|
|
8785
|
+
update(update) {
|
|
8786
|
+
this.manager.update(update);
|
|
8787
|
+
}
|
|
8788
|
+
destroy() {
|
|
8789
|
+
var _a;
|
|
8790
|
+
for (let t of this.manager.tooltipViews) (_a = t.destroy) === null || _a === void 0 || _a.call(t);
|
|
8791
|
+
}
|
|
8792
|
+
passProp(name) {
|
|
8793
|
+
let value = void 0;
|
|
8794
|
+
for (let view of this.manager.tooltipViews) {
|
|
8795
|
+
let given = view[name];
|
|
8796
|
+
if (given !== void 0) {
|
|
8797
|
+
if (value === void 0) value = given;
|
|
8798
|
+
else if (value !== given) return void 0;
|
|
8799
|
+
}
|
|
8800
|
+
}
|
|
8801
|
+
return value;
|
|
8802
|
+
}
|
|
8803
|
+
get offset() {
|
|
8804
|
+
return this.passProp("offset");
|
|
8805
|
+
}
|
|
8806
|
+
get getCoords() {
|
|
8807
|
+
return this.passProp("getCoords");
|
|
8808
|
+
}
|
|
8809
|
+
get overlap() {
|
|
8810
|
+
return this.passProp("overlap");
|
|
8811
|
+
}
|
|
8812
|
+
get resize() {
|
|
8813
|
+
return this.passProp("resize");
|
|
8814
|
+
}
|
|
8815
|
+
};
|
|
8816
|
+
const showHoverTooltipHost = /*@__PURE__*/ showTooltip.compute([showHoverTooltip], (state) => {
|
|
8817
|
+
let tooltips = state.facet(showHoverTooltip);
|
|
8818
|
+
if (tooltips.length === 0) return null;
|
|
8819
|
+
return {
|
|
8820
|
+
pos: Math.min(...tooltips.map((t) => t.pos)),
|
|
8821
|
+
end: Math.max(...tooltips.map((t) => {
|
|
8822
|
+
var _a;
|
|
8823
|
+
return (_a = t.end) !== null && _a !== void 0 ? _a : t.pos;
|
|
8824
|
+
})),
|
|
8825
|
+
create: HoverTooltipHost.create,
|
|
8826
|
+
above: tooltips[0].above,
|
|
8827
|
+
arrow: tooltips.some((t) => t.arrow)
|
|
8828
|
+
};
|
|
8829
|
+
});
|
|
8830
|
+
const hoverPlugin = /*@__PURE__*/ Facet.define();
|
|
8831
|
+
var HoverPlugin = class {
|
|
8832
|
+
constructor(view, source, field, locked, setHover, hoverTime) {
|
|
8833
|
+
this.view = view;
|
|
8834
|
+
this.source = source;
|
|
8835
|
+
this.field = field;
|
|
8836
|
+
this.locked = locked;
|
|
8837
|
+
this.setHover = setHover;
|
|
8838
|
+
this.hoverTime = hoverTime;
|
|
8839
|
+
this.hoverTimeout = -1;
|
|
8840
|
+
this.restartTimeout = -1;
|
|
8841
|
+
this.pending = null;
|
|
8842
|
+
this.lastMove = {
|
|
8843
|
+
x: 0,
|
|
8844
|
+
y: 0,
|
|
8845
|
+
target: view.dom,
|
|
8846
|
+
time: 0
|
|
8847
|
+
};
|
|
8848
|
+
this.checkHover = this.checkHover.bind(this);
|
|
8849
|
+
view.dom.addEventListener("mouseleave", this.mouseleave = this.mouseleave.bind(this));
|
|
8850
|
+
view.dom.addEventListener("mousemove", this.mousemove = this.mousemove.bind(this));
|
|
8851
|
+
}
|
|
8852
|
+
update(update) {
|
|
8853
|
+
if (this.pending) {
|
|
8854
|
+
this.pending = null;
|
|
8855
|
+
clearTimeout(this.restartTimeout);
|
|
8856
|
+
this.restartTimeout = setTimeout(() => this.startHover(), 20);
|
|
8857
|
+
}
|
|
8858
|
+
}
|
|
8859
|
+
get active() {
|
|
8860
|
+
return this.view.state.field(this.field);
|
|
8861
|
+
}
|
|
8862
|
+
checkHover() {
|
|
8863
|
+
this.hoverTimeout = -1;
|
|
8864
|
+
if (this.active.length) return;
|
|
8865
|
+
let hovered = Date.now() - this.lastMove.time;
|
|
8866
|
+
if (hovered < this.hoverTime) this.hoverTimeout = setTimeout(this.checkHover, this.hoverTime - hovered);
|
|
8867
|
+
else this.startHover();
|
|
8868
|
+
}
|
|
8869
|
+
startHover() {
|
|
8870
|
+
clearTimeout(this.restartTimeout);
|
|
8871
|
+
let { view, lastMove } = this;
|
|
8872
|
+
let tile = view.docView.tile.nearest(lastMove.target);
|
|
8873
|
+
if (!tile) return;
|
|
8874
|
+
let pos, side = 1;
|
|
8875
|
+
if (tile.isWidget()) pos = tile.posAtStart;
|
|
8876
|
+
else {
|
|
8877
|
+
pos = view.posAtCoords(lastMove);
|
|
8878
|
+
if (pos == null) return;
|
|
8879
|
+
let posCoords = view.coordsAtPos(pos);
|
|
8880
|
+
if (!posCoords || lastMove.y < posCoords.top || lastMove.y > posCoords.bottom || lastMove.x < posCoords.left - view.defaultCharacterWidth || lastMove.x > posCoords.right + view.defaultCharacterWidth) return;
|
|
8881
|
+
let bidi = view.bidiSpans(view.state.doc.lineAt(pos)).find((s) => s.from <= pos && s.to >= pos);
|
|
8882
|
+
let rtl = bidi && bidi.dir == Direction.RTL ? -1 : 1;
|
|
8883
|
+
side = lastMove.x < posCoords.left ? -rtl : rtl;
|
|
8884
|
+
}
|
|
8885
|
+
this.activateHover(view, pos, side);
|
|
8886
|
+
}
|
|
8887
|
+
activateHover(view, pos, side, locked) {
|
|
8888
|
+
let open = this.source(view, pos, side);
|
|
8889
|
+
let done = (value) => {
|
|
8890
|
+
if (value && !(Array.isArray(value) && !value.length)) {
|
|
8891
|
+
let tooltips = Array.isArray(value) ? value : [value];
|
|
8892
|
+
if (locked) this.locked.set(tooltips, locked);
|
|
8893
|
+
view.dispatch({ effects: this.setHover.of(tooltips) });
|
|
8894
|
+
}
|
|
8895
|
+
};
|
|
8896
|
+
if (open && "then" in open) {
|
|
8897
|
+
let pending = this.pending = { pos };
|
|
8898
|
+
open.then((result) => {
|
|
8899
|
+
if (this.pending == pending) {
|
|
8900
|
+
this.pending = null;
|
|
8901
|
+
done(result);
|
|
8902
|
+
}
|
|
8903
|
+
}, (e) => logException(view.state, e, "hover tooltip"));
|
|
8904
|
+
} else done(open);
|
|
8905
|
+
}
|
|
8906
|
+
get tooltip() {
|
|
8907
|
+
let plugin = this.view.plugin(tooltipPlugin);
|
|
8908
|
+
let index = plugin ? plugin.manager.tooltips.findIndex((t) => t.create == HoverTooltipHost.create) : -1;
|
|
8909
|
+
return index > -1 ? plugin.manager.tooltipViews[index] : null;
|
|
8910
|
+
}
|
|
8911
|
+
mousemove(event) {
|
|
8912
|
+
var _a, _b;
|
|
8913
|
+
this.lastMove = {
|
|
8914
|
+
x: event.clientX,
|
|
8915
|
+
y: event.clientY,
|
|
8916
|
+
target: event.target,
|
|
8917
|
+
time: Date.now()
|
|
8918
|
+
};
|
|
8919
|
+
if (this.hoverTimeout < 0) this.hoverTimeout = setTimeout(this.checkHover, this.hoverTime);
|
|
8920
|
+
let { active, tooltip } = this;
|
|
8921
|
+
if (active.length && !this.locked.has(active) && tooltip && !isInTooltip(tooltip.dom, event) || this.pending) {
|
|
8922
|
+
let { pos } = active[0] || this.pending, end = (_b = (_a = active[0]) === null || _a === void 0 ? void 0 : _a.end) !== null && _b !== void 0 ? _b : pos;
|
|
8923
|
+
if (pos == end ? this.view.posAtCoords(this.lastMove) != pos : !isOverRange(this.view, pos, end, event.clientX, event.clientY)) {
|
|
8924
|
+
this.view.dispatch({ effects: this.setHover.of([]) });
|
|
8925
|
+
this.pending = null;
|
|
8926
|
+
}
|
|
8927
|
+
}
|
|
8928
|
+
}
|
|
8929
|
+
mouseleave(event) {
|
|
8930
|
+
clearTimeout(this.hoverTimeout);
|
|
8931
|
+
this.hoverTimeout = -1;
|
|
8932
|
+
let { active } = this;
|
|
8933
|
+
if (active.length && !this.locked.has(active)) {
|
|
8934
|
+
let { tooltip } = this;
|
|
8935
|
+
if (!(tooltip && tooltip.dom.contains(event.relatedTarget))) this.view.dispatch({ effects: this.setHover.of([]) });
|
|
8936
|
+
else this.watchTooltipLeave(tooltip.dom);
|
|
8937
|
+
}
|
|
8938
|
+
}
|
|
8939
|
+
watchTooltipLeave(tooltip) {
|
|
8940
|
+
let watch = (event) => {
|
|
8941
|
+
tooltip.removeEventListener("mouseleave", watch);
|
|
8942
|
+
let { active } = this;
|
|
8943
|
+
if (active.length && !this.locked.has(active) && !this.view.dom.contains(event.relatedTarget)) this.view.dispatch({ effects: this.setHover.of([]) });
|
|
8944
|
+
};
|
|
8945
|
+
tooltip.addEventListener("mouseleave", watch);
|
|
8946
|
+
}
|
|
8947
|
+
destroy() {
|
|
8948
|
+
clearTimeout(this.hoverTimeout);
|
|
8949
|
+
clearTimeout(this.restartTimeout);
|
|
8950
|
+
this.view.dom.removeEventListener("mouseleave", this.mouseleave);
|
|
8951
|
+
this.view.dom.removeEventListener("mousemove", this.mousemove);
|
|
8952
|
+
}
|
|
8953
|
+
};
|
|
8954
|
+
const tooltipMargin = 4;
|
|
8955
|
+
function isInTooltip(tooltip, event) {
|
|
8956
|
+
let { left, right, top, bottom } = tooltip.getBoundingClientRect(), arrow;
|
|
8957
|
+
if (arrow = tooltip.querySelector(".cm-tooltip-arrow")) {
|
|
8958
|
+
let arrowRect = arrow.getBoundingClientRect();
|
|
8959
|
+
top = Math.min(arrowRect.top, top);
|
|
8960
|
+
bottom = Math.max(arrowRect.bottom, bottom);
|
|
8961
|
+
}
|
|
8962
|
+
return event.clientX >= left - tooltipMargin && event.clientX <= right + tooltipMargin && event.clientY >= top - tooltipMargin && event.clientY <= bottom + tooltipMargin;
|
|
8963
|
+
}
|
|
8964
|
+
function isOverRange(view, from, to, x, y, margin) {
|
|
8965
|
+
let rect = view.scrollDOM.getBoundingClientRect();
|
|
8966
|
+
let docBottom = view.documentTop + view.documentPadding.top + view.contentHeight;
|
|
8967
|
+
if (rect.left > x || rect.right < x || rect.top > y || Math.min(rect.bottom, docBottom) < y) return false;
|
|
8968
|
+
let pos = view.posAtCoords({
|
|
8969
|
+
x,
|
|
8970
|
+
y
|
|
8971
|
+
}, false);
|
|
8972
|
+
return pos >= from && pos <= to;
|
|
8973
|
+
}
|
|
8974
|
+
/**
|
|
8975
|
+
Set up a hover tooltip, which shows up when the pointer hovers
|
|
8976
|
+
over ranges of text. The callback is called when the mouse hovers
|
|
8977
|
+
over the document text. It should, if there is a tooltip
|
|
8978
|
+
associated with position `pos`, return the tooltip description
|
|
8979
|
+
(either directly or in a promise). The `side` argument indicates
|
|
8980
|
+
on which side of the position the pointer is—it will be -1 if the
|
|
8981
|
+
pointer is before the position, 1 if after the position.
|
|
8982
|
+
|
|
8983
|
+
Note that all hover tooltips are hosted within a single tooltip
|
|
8984
|
+
container element. This allows multiple tooltips over the same
|
|
8985
|
+
range to be "merged" together without overlapping.
|
|
8986
|
+
|
|
8987
|
+
The return value is a valid [editor extension](https://codemirror.net/6/docs/ref/#state.Extension)
|
|
8988
|
+
but also provides an `active` property holding a state field that
|
|
8989
|
+
can be used to read the currently active tooltips produced by this
|
|
8990
|
+
extension.
|
|
8991
|
+
*/
|
|
8992
|
+
function hoverTooltip(source, options = {}) {
|
|
8993
|
+
let setHover = StateEffect.define();
|
|
8994
|
+
let locked = /* @__PURE__ */ new WeakMap();
|
|
8995
|
+
let hoverState = StateField.define({
|
|
8996
|
+
create() {
|
|
8997
|
+
return [];
|
|
8998
|
+
},
|
|
8999
|
+
update(value, tr) {
|
|
9000
|
+
let lock = locked.get(value);
|
|
9001
|
+
if (value.length) {
|
|
9002
|
+
if (options.hideOnChange && (tr.docChanged || tr.selection)) value = [];
|
|
9003
|
+
else if (lock && lock(tr)) value = [];
|
|
9004
|
+
else if (options.hideOn) value = value.filter((v) => !options.hideOn(tr, v));
|
|
9005
|
+
}
|
|
9006
|
+
if (tr.docChanged && value.length) {
|
|
9007
|
+
let mapped = [];
|
|
9008
|
+
for (let tooltip of value) {
|
|
9009
|
+
let newPos = tr.changes.mapPos(tooltip.pos, -1, MapMode.TrackDel);
|
|
9010
|
+
if (newPos != null) {
|
|
9011
|
+
let copy = Object.assign(Object.create(null), tooltip);
|
|
9012
|
+
copy.pos = newPos;
|
|
9013
|
+
if (copy.end != null) copy.end = tr.changes.mapPos(copy.end);
|
|
9014
|
+
mapped.push(copy);
|
|
9015
|
+
}
|
|
9016
|
+
}
|
|
9017
|
+
value = mapped;
|
|
9018
|
+
}
|
|
9019
|
+
for (let effect of tr.effects) {
|
|
9020
|
+
if (effect.is(setHover)) {
|
|
9021
|
+
value = effect.value;
|
|
9022
|
+
lock = void 0;
|
|
9023
|
+
}
|
|
9024
|
+
if (effect.is(closeHoverTooltipEffect) && !effect.value || effect.value == hoverState) value = [];
|
|
9025
|
+
}
|
|
9026
|
+
if (value.length && lock) locked.set(value, lock);
|
|
9027
|
+
return value;
|
|
9028
|
+
},
|
|
9029
|
+
provide: (f) => showHoverTooltip.from(f)
|
|
9030
|
+
});
|
|
9031
|
+
const plugin = ViewPlugin.define((view) => new HoverPlugin(view, source, hoverState, locked, setHover, options.hoverTime || 300));
|
|
9032
|
+
return {
|
|
9033
|
+
active: hoverState,
|
|
9034
|
+
extension: [
|
|
9035
|
+
hoverState,
|
|
9036
|
+
plugin,
|
|
9037
|
+
hoverPlugin.of(plugin),
|
|
9038
|
+
showHoverTooltipHost
|
|
9039
|
+
]
|
|
9040
|
+
};
|
|
9041
|
+
}
|
|
9042
|
+
/**
|
|
9043
|
+
Activate hover tooltips for the given position and side. If you
|
|
9044
|
+
provide a specific hover tooltip (the value returned from
|
|
9045
|
+
[`hoverTooltip`](https://codemirror.net/6/docs/ref/#view.hoverTooltip)), only that one will be
|
|
9046
|
+
activated. If not given, all hover tooltips at the given position
|
|
9047
|
+
are triggered.
|
|
9048
|
+
|
|
9049
|
+
Note that tooltips opened this way don't close automatically, and
|
|
9050
|
+
you'll want to pass an `until` callback or use
|
|
9051
|
+
[`closeHoverTooltip`](https://codemirror.net/6/docs/ref/#view.closeHoverTooltip)/[`closeHoverTooltips`](https://codemirror.net/6/docs/ref/#view.closeHoverTooltips)
|
|
9052
|
+
to deactivate them.
|
|
9053
|
+
*/
|
|
9054
|
+
function activateHover(view, pos, side, options = {}) {
|
|
9055
|
+
var _a;
|
|
9056
|
+
let plugins = view.state.facet(hoverPlugin).map((p) => view.plugin(p)).filter((p) => !!p);
|
|
9057
|
+
if (options.tooltip && options.tooltip.active) {
|
|
9058
|
+
let found = plugins.find((p) => p.field == options.tooltip.active);
|
|
9059
|
+
if (found) plugins = [found];
|
|
9060
|
+
}
|
|
9061
|
+
for (let plugin of plugins) plugin.activateHover(view, pos, side, (_a = options.until) !== null && _a !== void 0 ? _a : (() => false));
|
|
9062
|
+
}
|
|
9063
|
+
/**
|
|
9064
|
+
Get the active tooltip view for a given tooltip, if available.
|
|
9065
|
+
*/
|
|
9066
|
+
function getTooltip(view, tooltip) {
|
|
9067
|
+
let plugin = view.plugin(tooltipPlugin);
|
|
9068
|
+
if (!plugin) return null;
|
|
9069
|
+
let found = plugin.manager.tooltips.indexOf(tooltip);
|
|
9070
|
+
return found < 0 ? null : plugin.manager.tooltipViews[found];
|
|
9071
|
+
}
|
|
9072
|
+
const closeHoverTooltipEffect = /*@__PURE__*/ StateEffect.define();
|
|
9073
|
+
const panelConfig = /*@__PURE__*/ Facet.define({ combine(configs) {
|
|
9074
|
+
let topContainer, bottomContainer;
|
|
9075
|
+
for (let c of configs) {
|
|
9076
|
+
topContainer = topContainer || c.topContainer;
|
|
9077
|
+
bottomContainer = bottomContainer || c.bottomContainer;
|
|
9078
|
+
}
|
|
9079
|
+
return {
|
|
9080
|
+
topContainer,
|
|
9081
|
+
bottomContainer
|
|
9082
|
+
};
|
|
9083
|
+
} });
|
|
9084
|
+
/**
|
|
9085
|
+
Get the active panel created by the given constructor, if any.
|
|
9086
|
+
This can be useful when you need access to your panels' DOM
|
|
9087
|
+
structure.
|
|
9088
|
+
*/
|
|
9089
|
+
function getPanel(view, panel) {
|
|
9090
|
+
let plugin = view.plugin(panelPlugin);
|
|
9091
|
+
let index = plugin ? plugin.specs.indexOf(panel) : -1;
|
|
9092
|
+
return index > -1 ? plugin.panels[index] : null;
|
|
9093
|
+
}
|
|
9094
|
+
const panelPlugin = /*@__PURE__*/ ViewPlugin.fromClass(class {
|
|
9095
|
+
constructor(view) {
|
|
9096
|
+
this.input = view.state.facet(showPanel);
|
|
9097
|
+
this.specs = this.input.filter((s) => s);
|
|
9098
|
+
this.panels = this.specs.map((spec) => spec(view));
|
|
9099
|
+
let conf = view.state.facet(panelConfig);
|
|
9100
|
+
this.top = new PanelGroup(view, true, conf.topContainer);
|
|
9101
|
+
this.bottom = new PanelGroup(view, false, conf.bottomContainer);
|
|
9102
|
+
this.top.sync(this.panels.filter((p) => p.top));
|
|
9103
|
+
this.bottom.sync(this.panels.filter((p) => !p.top));
|
|
9104
|
+
for (let p of this.panels) {
|
|
9105
|
+
p.dom.classList.add("cm-panel");
|
|
9106
|
+
if (p.mount) p.mount();
|
|
9107
|
+
}
|
|
9108
|
+
}
|
|
9109
|
+
update(update) {
|
|
9110
|
+
let conf = update.state.facet(panelConfig);
|
|
9111
|
+
if (this.top.container != conf.topContainer) {
|
|
9112
|
+
this.top.sync([]);
|
|
9113
|
+
this.top = new PanelGroup(update.view, true, conf.topContainer);
|
|
9114
|
+
}
|
|
9115
|
+
if (this.bottom.container != conf.bottomContainer) {
|
|
9116
|
+
this.bottom.sync([]);
|
|
9117
|
+
this.bottom = new PanelGroup(update.view, false, conf.bottomContainer);
|
|
9118
|
+
}
|
|
9119
|
+
this.top.syncClasses();
|
|
9120
|
+
this.bottom.syncClasses();
|
|
9121
|
+
let input = update.state.facet(showPanel);
|
|
9122
|
+
if (input != this.input) {
|
|
9123
|
+
let specs = input.filter((x) => x);
|
|
9124
|
+
let panels = [], top = [], bottom = [], mount = [];
|
|
9125
|
+
for (let spec of specs) {
|
|
9126
|
+
let known = this.specs.indexOf(spec), panel;
|
|
9127
|
+
if (known < 0) {
|
|
9128
|
+
panel = spec(update.view);
|
|
9129
|
+
mount.push(panel);
|
|
9130
|
+
} else {
|
|
9131
|
+
panel = this.panels[known];
|
|
9132
|
+
if (panel.update) panel.update(update);
|
|
9133
|
+
}
|
|
9134
|
+
panels.push(panel);
|
|
9135
|
+
(panel.top ? top : bottom).push(panel);
|
|
9136
|
+
}
|
|
9137
|
+
this.specs = specs;
|
|
9138
|
+
this.panels = panels;
|
|
9139
|
+
this.top.sync(top);
|
|
9140
|
+
this.bottom.sync(bottom);
|
|
9141
|
+
for (let p of mount) {
|
|
9142
|
+
p.dom.classList.add("cm-panel");
|
|
9143
|
+
if (p.mount) p.mount();
|
|
9144
|
+
}
|
|
9145
|
+
} else for (let p of this.panels) if (p.update) p.update(update);
|
|
9146
|
+
}
|
|
9147
|
+
destroy() {
|
|
9148
|
+
this.top.sync([]);
|
|
9149
|
+
this.bottom.sync([]);
|
|
9150
|
+
}
|
|
9151
|
+
}, { provide: (plugin) => EditorView.scrollMargins.of((view) => {
|
|
9152
|
+
let value = view.plugin(plugin);
|
|
9153
|
+
return value && {
|
|
9154
|
+
top: value.top.scrollMargin(),
|
|
9155
|
+
bottom: value.bottom.scrollMargin()
|
|
9156
|
+
};
|
|
9157
|
+
}) });
|
|
9158
|
+
var PanelGroup = class {
|
|
9159
|
+
constructor(view, top, container) {
|
|
9160
|
+
this.view = view;
|
|
9161
|
+
this.top = top;
|
|
9162
|
+
this.container = container;
|
|
9163
|
+
this.dom = void 0;
|
|
9164
|
+
this.classes = "";
|
|
9165
|
+
this.panels = [];
|
|
9166
|
+
this.syncClasses();
|
|
9167
|
+
}
|
|
9168
|
+
sync(panels) {
|
|
9169
|
+
for (let p of this.panels) if (p.destroy && panels.indexOf(p) < 0) p.destroy();
|
|
9170
|
+
this.panels = panels;
|
|
9171
|
+
this.syncDOM();
|
|
9172
|
+
}
|
|
9173
|
+
syncDOM() {
|
|
9174
|
+
if (this.panels.length == 0) {
|
|
9175
|
+
if (this.dom) {
|
|
9176
|
+
this.dom.remove();
|
|
9177
|
+
this.dom = void 0;
|
|
9178
|
+
}
|
|
9179
|
+
return;
|
|
9180
|
+
}
|
|
9181
|
+
if (!this.dom) {
|
|
9182
|
+
this.dom = document.createElement("div");
|
|
9183
|
+
this.dom.className = this.top ? "cm-panels cm-panels-top" : "cm-panels cm-panels-bottom";
|
|
9184
|
+
this.dom.style[this.top ? "top" : "bottom"] = "0";
|
|
9185
|
+
let parent = this.container || this.view.dom;
|
|
9186
|
+
parent.insertBefore(this.dom, this.top ? parent.firstChild : null);
|
|
9187
|
+
}
|
|
9188
|
+
let curDOM = this.dom.firstChild;
|
|
9189
|
+
for (let panel of this.panels) if (panel.dom.parentNode == this.dom) {
|
|
9190
|
+
while (curDOM != panel.dom) curDOM = rm(curDOM);
|
|
9191
|
+
curDOM = curDOM.nextSibling;
|
|
9192
|
+
} else this.dom.insertBefore(panel.dom, curDOM);
|
|
9193
|
+
while (curDOM) curDOM = rm(curDOM);
|
|
9194
|
+
}
|
|
9195
|
+
scrollMargin() {
|
|
9196
|
+
return !this.dom || this.container ? 0 : Math.max(0, this.top ? this.dom.getBoundingClientRect().bottom - Math.max(0, this.view.scrollDOM.getBoundingClientRect().top) : Math.min(innerHeight, this.view.scrollDOM.getBoundingClientRect().bottom) - this.dom.getBoundingClientRect().top);
|
|
9197
|
+
}
|
|
9198
|
+
syncClasses() {
|
|
9199
|
+
if (!this.container || this.classes == this.view.themeClasses) return;
|
|
9200
|
+
for (let cls of this.classes.split(" ")) if (cls) this.container.classList.remove(cls);
|
|
9201
|
+
for (let cls of (this.classes = this.view.themeClasses).split(" ")) if (cls) this.container.classList.add(cls);
|
|
9202
|
+
}
|
|
9203
|
+
};
|
|
9204
|
+
function rm(node) {
|
|
9205
|
+
let next = node.nextSibling;
|
|
9206
|
+
node.remove();
|
|
9207
|
+
return next;
|
|
9208
|
+
}
|
|
9209
|
+
/**
|
|
9210
|
+
Opening a panel is done by providing a constructor function for
|
|
9211
|
+
the panel through this facet. (The panel is closed again when its
|
|
9212
|
+
constructor is no longer provided.) Values of `null` are ignored.
|
|
9213
|
+
*/
|
|
9214
|
+
const showPanel = /*@__PURE__*/ Facet.define({ enables: panelPlugin });
|
|
9215
|
+
/**
|
|
9216
|
+
Show a panel above or below the editor to show the user a message
|
|
9217
|
+
or prompt them for input. Returns an effect that can be dispatched
|
|
9218
|
+
to close the dialog, and a promise that resolves when the dialog
|
|
9219
|
+
is closed or a form inside of it is submitted.
|
|
9220
|
+
|
|
9221
|
+
You are encouraged, if your handling of the result of the promise
|
|
9222
|
+
dispatches a transaction, to include the `close` effect in it. If
|
|
9223
|
+
you don't, this function will automatically dispatch a separate
|
|
9224
|
+
transaction right after.
|
|
9225
|
+
*/
|
|
9226
|
+
function showDialog(view, config) {
|
|
9227
|
+
let resolve;
|
|
9228
|
+
let promise = new Promise((r) => resolve = r);
|
|
9229
|
+
let panelCtor = (view) => createDialog(view, config, resolve);
|
|
9230
|
+
if (view.state.field(dialogField, false)) view.dispatch({ effects: openDialogEffect.of(panelCtor) });
|
|
9231
|
+
else view.dispatch({ effects: StateEffect.appendConfig.of(dialogField.init(() => [panelCtor])) });
|
|
9232
|
+
let close = closeDialogEffect.of(panelCtor);
|
|
9233
|
+
return {
|
|
9234
|
+
close,
|
|
9235
|
+
result: promise.then((form) => {
|
|
9236
|
+
(view.win.queueMicrotask || ((f) => view.win.setTimeout(f, 10)))(() => {
|
|
9237
|
+
if (view.state.field(dialogField).indexOf(panelCtor) > -1) view.dispatch({ effects: close });
|
|
9238
|
+
});
|
|
9239
|
+
return form;
|
|
9240
|
+
})
|
|
9241
|
+
};
|
|
9242
|
+
}
|
|
9243
|
+
const dialogField = /*@__PURE__*/ StateField.define({
|
|
9244
|
+
create() {
|
|
9245
|
+
return [];
|
|
9246
|
+
},
|
|
9247
|
+
update(dialogs, tr) {
|
|
9248
|
+
for (let e of tr.effects) if (e.is(openDialogEffect)) dialogs = [e.value].concat(dialogs);
|
|
9249
|
+
else if (e.is(closeDialogEffect)) dialogs = dialogs.filter((d) => d != e.value);
|
|
9250
|
+
return dialogs;
|
|
9251
|
+
},
|
|
9252
|
+
provide: (f) => showPanel.computeN([f], (state) => state.field(f))
|
|
9253
|
+
});
|
|
9254
|
+
const openDialogEffect = /*@__PURE__*/ StateEffect.define();
|
|
9255
|
+
const closeDialogEffect = /*@__PURE__*/ StateEffect.define();
|
|
9256
|
+
function createDialog(view, config, result) {
|
|
9257
|
+
let content = config.content ? config.content(view, () => done(null)) : null;
|
|
9258
|
+
if (!content) {
|
|
9259
|
+
content = crelt("form");
|
|
9260
|
+
if (config.input) {
|
|
9261
|
+
let input = crelt("input", config.input);
|
|
9262
|
+
if (/^(text|password|number|email|tel|url)$/.test(input.type)) input.classList.add("cm-textfield");
|
|
9263
|
+
if (!input.name) input.name = "input";
|
|
9264
|
+
content.appendChild(crelt("label", (config.label || "") + ": ", input));
|
|
9265
|
+
} else content.appendChild(document.createTextNode(config.label || ""));
|
|
9266
|
+
content.appendChild(document.createTextNode(" "));
|
|
9267
|
+
content.appendChild(crelt("button", {
|
|
9268
|
+
class: "cm-button",
|
|
9269
|
+
type: "submit"
|
|
9270
|
+
}, config.submitLabel || "OK"));
|
|
9271
|
+
}
|
|
9272
|
+
let forms = content.nodeName == "FORM" ? [content] : content.querySelectorAll("form");
|
|
9273
|
+
for (let i = 0; i < forms.length; i++) {
|
|
9274
|
+
let form = forms[i];
|
|
9275
|
+
form.addEventListener("keydown", (event) => {
|
|
9276
|
+
if (event.keyCode == 27) {
|
|
9277
|
+
event.preventDefault();
|
|
9278
|
+
done(null);
|
|
9279
|
+
} else if (event.keyCode == 13) {
|
|
9280
|
+
event.preventDefault();
|
|
9281
|
+
done(form);
|
|
9282
|
+
}
|
|
9283
|
+
});
|
|
9284
|
+
form.addEventListener("submit", (event) => {
|
|
9285
|
+
event.preventDefault();
|
|
9286
|
+
done(form);
|
|
9287
|
+
});
|
|
9288
|
+
}
|
|
9289
|
+
let panel = crelt("div", content, crelt("button", {
|
|
9290
|
+
onclick: () => done(null),
|
|
9291
|
+
"aria-label": view.state.phrase("close"),
|
|
9292
|
+
class: "cm-dialog-close",
|
|
9293
|
+
type: "button"
|
|
9294
|
+
}, ["×"]));
|
|
9295
|
+
if (config.class) panel.className = config.class;
|
|
9296
|
+
panel.classList.add("cm-dialog");
|
|
9297
|
+
function done(form) {
|
|
9298
|
+
if (panel.contains(panel.ownerDocument.activeElement)) view.focus();
|
|
9299
|
+
result(form);
|
|
9300
|
+
}
|
|
9301
|
+
return {
|
|
9302
|
+
dom: panel,
|
|
9303
|
+
top: config.top,
|
|
9304
|
+
mount: () => {
|
|
9305
|
+
if (config.focus) {
|
|
9306
|
+
let focus;
|
|
9307
|
+
if (typeof config.focus == "string") focus = content.querySelector(config.focus);
|
|
9308
|
+
else focus = content.querySelector("input") || content.querySelector("button");
|
|
9309
|
+
if (focus && "select" in focus) focus.select();
|
|
9310
|
+
else if (focus && "focus" in focus) focus.focus();
|
|
9311
|
+
}
|
|
9312
|
+
}
|
|
9313
|
+
};
|
|
9314
|
+
}
|
|
8424
9315
|
/**
|
|
8425
9316
|
A gutter marker represents a bit of information attached to a line
|
|
8426
9317
|
in a specific gutter. Your own custom markers have to extend this
|
|
@@ -8463,7 +9354,30 @@ Facet used to add a class to all gutter elements next to a widget.
|
|
|
8463
9354
|
Should not provide widgets with a `toDOM` method.
|
|
8464
9355
|
*/
|
|
8465
9356
|
const gutterWidgetClass = /*@__PURE__*/ Facet.define();
|
|
9357
|
+
const defaults = {
|
|
9358
|
+
class: "",
|
|
9359
|
+
renderEmptyElements: false,
|
|
9360
|
+
elementStyle: "",
|
|
9361
|
+
markers: () => RangeSet.empty,
|
|
9362
|
+
lineMarker: () => null,
|
|
9363
|
+
widgetMarker: () => null,
|
|
9364
|
+
lineMarkerChange: null,
|
|
9365
|
+
initialSpacer: null,
|
|
9366
|
+
updateSpacer: null,
|
|
9367
|
+
domEventHandlers: {},
|
|
9368
|
+
side: "before"
|
|
9369
|
+
};
|
|
8466
9370
|
const activeGutters = /*@__PURE__*/ Facet.define();
|
|
9371
|
+
/**
|
|
9372
|
+
Define an editor gutter. The order in which the gutters appear is
|
|
9373
|
+
determined by their extension priority.
|
|
9374
|
+
*/
|
|
9375
|
+
function gutter(config) {
|
|
9376
|
+
return [gutters(), activeGutters.of({
|
|
9377
|
+
...defaults,
|
|
9378
|
+
...config
|
|
9379
|
+
})];
|
|
9380
|
+
}
|
|
8467
9381
|
const unfixGutters = /*@__PURE__*/ Facet.define({ combine: (values) => values.some((x) => x) });
|
|
8468
9382
|
/**
|
|
8469
9383
|
The gutter-drawing plugin is automatically enabled when you add a
|
|
@@ -8851,6 +9765,6 @@ function highlightActiveLineGutter() {
|
|
|
8851
9765
|
return activeLineGutterHighlighter;
|
|
8852
9766
|
}
|
|
8853
9767
|
//#endregion
|
|
8854
|
-
export { EditorView, ViewPlugin, crosshairCursor, drawSelection, dropCursor, highlightActiveLine, highlightActiveLineGutter, highlightSpecialChars, keymap, lineNumbers, rectangularSelection, tooltips };
|
|
9768
|
+
export { Decoration, Direction, EditorView, GutterMarker, ViewPlugin, WidgetType, activateHover, crosshairCursor, drawSelection, dropCursor, getPanel, getTooltip, gutter, highlightActiveLine, highlightActiveLineGutter, highlightSpecialChars, hoverTooltip, keymap, lineNumbers, logException, rectangularSelection, runScopeHandlers, showDialog, showPanel, showTooltip, tooltips };
|
|
8855
9769
|
|
|
8856
9770
|
//# sourceMappingURL=index.js.map
|