1
0
Fork 0
mirror of https://github.com/DanielnetoDotCom/YouPHPTube synced 2025-10-05 02:39:46 +02:00
This commit is contained in:
DanieL 2023-02-13 14:41:08 -03:00
parent 64c36d9f4e
commit 0d0338876d
1197 changed files with 121461 additions and 179724 deletions

View file

@ -1,6 +1,6 @@
import { Annotation, Facet, combineConfig, StateField, EditorSelection, Transaction, ChangeSet, ChangeDesc, StateEffect, Text, findClusterBreak, countColumn, CharCategory } from '@codemirror/state';
import { EditorView, Direction } from '@codemirror/view';
import { IndentContext, getIndentation, indentString, indentUnit, getIndentUnit, matchBrackets, syntaxTree } from '@codemirror/language';
import { IndentContext, getIndentation, indentString, matchBrackets, syntaxTree, getIndentUnit, indentUnit } from '@codemirror/language';
import { NodeProp } from '@lezer/common';
/**
@ -28,35 +28,35 @@ The line comment syntax is taken from the
[`commentTokens`](https://codemirror.net/6/docs/ref/#commands.CommentTokens) [language
data](https://codemirror.net/6/docs/ref/#state.EditorState.languageDataAt).
*/
const toggleLineComment = /*@__PURE__*/command(changeLineComment, 0 /* Toggle */);
const toggleLineComment = /*@__PURE__*/command(changeLineComment, 0 /* CommentOption.Toggle */);
/**
Comment the current selection using line comments.
*/
const lineComment = /*@__PURE__*/command(changeLineComment, 1 /* Comment */);
const lineComment = /*@__PURE__*/command(changeLineComment, 1 /* CommentOption.Comment */);
/**
Uncomment the current selection using line comments.
*/
const lineUncomment = /*@__PURE__*/command(changeLineComment, 2 /* Uncomment */);
const lineUncomment = /*@__PURE__*/command(changeLineComment, 2 /* CommentOption.Uncomment */);
/**
Comment or uncomment the current selection using block comments.
The block comment syntax is taken from the
[`commentTokens`](https://codemirror.net/6/docs/ref/#commands.CommentTokens) [language
data](https://codemirror.net/6/docs/ref/#state.EditorState.languageDataAt).
*/
const toggleBlockComment = /*@__PURE__*/command(changeBlockComment, 0 /* Toggle */);
const toggleBlockComment = /*@__PURE__*/command(changeBlockComment, 0 /* CommentOption.Toggle */);
/**
Comment the current selection using block comments.
*/
const blockComment = /*@__PURE__*/command(changeBlockComment, 1 /* Comment */);
const blockComment = /*@__PURE__*/command(changeBlockComment, 1 /* CommentOption.Comment */);
/**
Uncomment the current selection using block comments.
*/
const blockUncomment = /*@__PURE__*/command(changeBlockComment, 2 /* Uncomment */);
const blockUncomment = /*@__PURE__*/command(changeBlockComment, 2 /* CommentOption.Uncomment */);
/**
Comment or uncomment the lines around the current selection using
block comments.
*/
const toggleBlockCommentByLine = /*@__PURE__*/command((o, s) => changeBlockComment(o, s, selectedLineRanges(s)), 0 /* Toggle */);
const toggleBlockCommentByLine = /*@__PURE__*/command((o, s) => changeBlockComment(o, s, selectedLineRanges(s)), 0 /* CommentOption.Toggle */);
function getConfig(state, pos = state.selection.main.head) {
let data = state.languageDataAt("commentTokens", pos);
return data.length ? data[0] : {};
@ -115,14 +115,14 @@ function changeBlockComment(option, state, ranges = state.selection.ranges) {
if (!tokens.every(c => c))
return null;
let comments = ranges.map((r, i) => findBlockComment(state, tokens[i], r.from, r.to));
if (option != 2 /* Uncomment */ && !comments.every(c => c)) {
if (option != 2 /* CommentOption.Uncomment */ && !comments.every(c => c)) {
return { changes: state.changes(ranges.map((range, i) => {
if (comments[i])
return [];
return [{ from: range.from, insert: tokens[i].open + " " }, { from: range.to, insert: " " + tokens[i].close }];
})) };
}
else if (option != 1 /* Comment */ && comments.some(c => c)) {
else if (option != 1 /* CommentOption.Comment */ && comments.some(c => c)) {
let changes = [];
for (let i = 0, comment; i < comments.length; i++)
if (comment = comments[i]) {
@ -162,7 +162,7 @@ function changeLineComment(option, state, ranges = state.selection.ranges) {
if (lines.length == startI + 1)
lines[startI].single = true;
}
if (option != 2 /* Uncomment */ && lines.some(l => l.comment < 0 && (!l.empty || l.single))) {
if (option != 2 /* CommentOption.Uncomment */ && lines.some(l => l.comment < 0 && (!l.empty || l.single))) {
let changes = [];
for (let { line, token, indent, empty, single } of lines)
if (single || !empty)
@ -170,7 +170,7 @@ function changeLineComment(option, state, ranges = state.selection.ranges) {
let changeSet = state.changes(changes);
return { changes: changeSet, selection: state.selection.map(changeSet, 1) };
}
else if (option != 1 /* Comment */ && lines.some(l => l.comment >= 0)) {
else if (option != 1 /* CommentOption.Comment */ && lines.some(l => l.comment >= 0)) {
let changes = [];
for (let { line, comment, token } of lines)
if (comment >= 0) {
@ -205,8 +205,13 @@ const historyConfig = /*@__PURE__*/Facet.define({
combine(configs) {
return combineConfig(configs, {
minDepth: 100,
newGroupDelay: 500
}, { minDepth: Math.max, newGroupDelay: Math.min });
newGroupDelay: 500,
joinToEvent: (_t, isAdjacent) => isAdjacent,
}, {
minDepth: Math.max,
newGroupDelay: Math.min,
joinToEvent: (a, b) => (tr, adj) => a(tr, adj) || b(tr, adj)
});
}
});
function changeEnd(changes) {
@ -224,12 +229,12 @@ const historyField_ = /*@__PURE__*/StateField.define({
if (fromHist) {
let selection = tr.docChanged ? EditorSelection.single(changeEnd(tr.changes)) : undefined;
let item = HistEvent.fromTransaction(tr, selection), from = fromHist.side;
let other = from == 0 /* Done */ ? state.undone : state.done;
let other = from == 0 /* BranchName.Done */ ? state.undone : state.done;
if (item)
other = updateBranch(other, other.length, config.minDepth, item);
else
other = addSelection(other, tr.startState.selection);
return new HistoryState(from == 0 /* Done */ ? fromHist.rest : other, from == 0 /* Done */ ? other : fromHist.rest);
return new HistoryState(from == 0 /* BranchName.Done */ ? fromHist.rest : other, from == 0 /* BranchName.Done */ ? other : fromHist.rest);
}
let isolate = tr.annotation(isolateHistory);
if (isolate == "full" || isolate == "before")
@ -239,7 +244,7 @@ const historyField_ = /*@__PURE__*/StateField.define({
let event = HistEvent.fromTransaction(tr);
let time = tr.annotation(Transaction.time), userEvent = tr.annotation(Transaction.userEvent);
if (event)
state = state.addChanges(event, time, userEvent, config.newGroupDelay, config.minDepth);
state = state.addChanges(event, time, userEvent, config, tr);
else if (tr.selection)
state = state.addSelection(tr.startState.selection, time, userEvent, config.newGroupDelay);
if (isolate == "full" || isolate == "after")
@ -297,37 +302,37 @@ function cmd(side, selection) {
Undo a single group of history events. Returns false if no group
was available.
*/
const undo = /*@__PURE__*/cmd(0 /* Done */, false);
const undo = /*@__PURE__*/cmd(0 /* BranchName.Done */, false);
/**
Redo a group of history events. Returns false if no group was
available.
*/
const redo = /*@__PURE__*/cmd(1 /* Undone */, false);
const redo = /*@__PURE__*/cmd(1 /* BranchName.Undone */, false);
/**
Undo a change or selection change.
*/
const undoSelection = /*@__PURE__*/cmd(0 /* Done */, true);
const undoSelection = /*@__PURE__*/cmd(0 /* BranchName.Done */, true);
/**
Redo a change or selection change.
*/
const redoSelection = /*@__PURE__*/cmd(1 /* Undone */, true);
const redoSelection = /*@__PURE__*/cmd(1 /* BranchName.Undone */, true);
function depth(side) {
return function (state) {
let histState = state.field(historyField_, false);
if (!histState)
return 0;
let branch = side == 0 /* Done */ ? histState.done : histState.undone;
let branch = side == 0 /* BranchName.Done */ ? histState.done : histState.undone;
return branch.length - (branch.length && !branch[0].changes ? 1 : 0);
};
}
/**
The amount of undoable change events available in a given state.
*/
const undoDepth = /*@__PURE__*/depth(0 /* Done */);
const undoDepth = /*@__PURE__*/depth(0 /* BranchName.Done */);
/**
The amount of redoable change events available in a given state.
*/
const redoDepth = /*@__PURE__*/depth(1 /* Undone */);
const redoDepth = /*@__PURE__*/depth(1 /* BranchName.Undone */);
// History events store groups of changes or effects that need to be
// undone/redone together.
class HistEvent {
@ -339,7 +344,10 @@ class HistEvent {
// changes == startSelection == undefined
changes,
// The effects associated with this event
effects, mapped,
effects,
// Accumulated mapping (from addToHistory==false) that should be
// applied to events below this one.
mapped,
// The selection before this event
startSelection,
// Stores selection changes after this event, to be used for
@ -473,19 +481,19 @@ class HistoryState {
isolate() {
return this.prevTime ? new HistoryState(this.done, this.undone) : this;
}
addChanges(event, time, userEvent, newGroupDelay, maxLen) {
addChanges(event, time, userEvent, config, tr) {
let done = this.done, lastEvent = done[done.length - 1];
if (lastEvent && lastEvent.changes && !lastEvent.changes.empty && event.changes &&
(!userEvent || joinableUserEvent.test(userEvent)) &&
((!lastEvent.selectionsAfter.length &&
time - this.prevTime < newGroupDelay &&
isAdjacent(lastEvent.changes, event.changes)) ||
time - this.prevTime < config.newGroupDelay &&
config.joinToEvent(tr, isAdjacent(lastEvent.changes, event.changes))) ||
// For compose (but not compose.start) events, always join with previous event
userEvent == "input.type.compose")) {
done = updateBranch(done, done.length - 1, maxLen, new HistEvent(event.changes.compose(lastEvent.changes), conc(event.effects, lastEvent.effects), lastEvent.mapped, lastEvent.startSelection, none));
done = updateBranch(done, done.length - 1, config.minDepth, new HistEvent(event.changes.compose(lastEvent.changes), conc(event.effects, lastEvent.effects), lastEvent.mapped, lastEvent.startSelection, none));
}
else {
done = updateBranch(done, done.length, maxLen, event);
done = updateBranch(done, done.length, config.minDepth, event);
}
return new HistoryState(done, none, time, userEvent);
}
@ -502,7 +510,7 @@ class HistoryState {
return new HistoryState(addMappingToBranch(this.done, mapping), addMappingToBranch(this.undone, mapping), this.prevTime, this.prevUserEvent);
}
pop(side, state, selection) {
let branch = side == 0 /* Done */ ? this.done : this.undone;
let branch = side == 0 /* BranchName.Done */ ? this.done : this.undone;
if (branch.length == 0)
return null;
let event = branch[branch.length - 1];
@ -510,7 +518,7 @@ class HistoryState {
return state.update({
selection: event.selectionsAfter[event.selectionsAfter.length - 1],
annotations: fromHistory.of({ side, rest: popSelection(branch) }),
userEvent: side == 0 /* Done */ ? "select.undo" : "select.redo",
userEvent: side == 0 /* BranchName.Done */ ? "select.undo" : "select.redo",
scrollIntoView: true
});
}
@ -527,7 +535,7 @@ class HistoryState {
effects: event.effects,
annotations: fromHistory.of({ side, rest }),
filter: false,
userEvent: side == 0 /* Done */ ? "undo" : "redo",
userEvent: side == 0 /* BranchName.Done */ ? "undo" : "redo",
scrollIntoView: true
});
}
@ -538,13 +546,14 @@ HistoryState.empty = /*@__PURE__*/new HistoryState(none, none);
Default key bindings for the undo history.
- Mod-z: [`undo`](https://codemirror.net/6/docs/ref/#commands.undo).
- Mod-y (Mod-Shift-z on macOS): [`redo`](https://codemirror.net/6/docs/ref/#commands.redo).
- Mod-y (Mod-Shift-z on macOS) + Ctrl-Shift-z on Linux: [`redo`](https://codemirror.net/6/docs/ref/#commands.redo).
- Mod-u: [`undoSelection`](https://codemirror.net/6/docs/ref/#commands.undoSelection).
- Alt-u (Mod-Shift-u on macOS): [`redoSelection`](https://codemirror.net/6/docs/ref/#commands.redoSelection).
*/
const historyKeymap = [
{ key: "Mod-z", run: undo, preventDefault: true },
{ key: "Mod-y", mac: "Mod-Shift-z", run: redo, preventDefault: true },
{ linux: "Ctrl-Shift-z", run: redo, preventDefault: true },
{ key: "Mod-u", run: undoSelection, preventDefault: true },
{ key: "Alt-u", mac: "Mod-Shift-u", run: redoSelection, preventDefault: true }
];
@ -758,6 +767,14 @@ end of the indentation instead of the start of the line.
*/
const cursorLineBoundaryBackward = view => moveSel(view, range => moveByLineBoundary(view, range, false));
/**
Move the selection one line wrap point to the left.
*/
const cursorLineBoundaryLeft = view => moveSel(view, range => moveByLineBoundary(view, range, !ltrAtCursor(view)));
/**
Move the selection one line wrap point to the right.
*/
const cursorLineBoundaryRight = view => moveSel(view, range => moveByLineBoundary(view, range, ltrAtCursor(view)));
/**
Move the selection to the start of the line.
*/
const cursorLineStart = view => moveSel(view, range => EditorSelection.cursor(view.lineBlockAt(range.head).from, 1));
@ -795,7 +812,7 @@ const selectMatchingBracket = ({ state, dispatch }) => toMatchingBracket(state,
function extendSel(view, how) {
let selection = updateSel(view.state.selection, range => {
let head = how(range);
return EditorSelection.range(range.anchor, head.head, head.goalColumn);
return EditorSelection.range(range.anchor, head.head, head.goalColumn, head.bidiLevel || undefined);
});
if (selection.eq(view.state.selection))
return false;
@ -892,6 +909,14 @@ Move the selection head to the previous line boundary.
*/
const selectLineBoundaryBackward = view => extendSel(view, range => moveByLineBoundary(view, range, false));
/**
Move the selection head one line boundary to the left.
*/
const selectLineBoundaryLeft = view => extendSel(view, range => moveByLineBoundary(view, range, !ltrAtCursor(view)));
/**
Move the selection head one line boundary to the right.
*/
const selectLineBoundaryRight = view => extendSel(view, range => moveByLineBoundary(view, range, ltrAtCursor(view)));
/**
Move the selection head to the start of the line.
*/
const selectLineStart = view => extendSel(view, range => EditorSelection.cursor(view.lineBlockAt(range.head).from));
@ -977,26 +1002,38 @@ const simplifySelection = ({ state, dispatch }) => {
dispatch(setSel(state, selection));
return true;
};
function deleteBy({ state, dispatch }, by) {
if (state.readOnly)
function deleteBy(target, by) {
if (target.state.readOnly)
return false;
let event = "delete.selection";
let event = "delete.selection", { state } = target;
let changes = state.changeByRange(range => {
let { from, to } = range;
if (from == to) {
let towards = by(from);
if (towards < from)
if (towards < from) {
event = "delete.backward";
else if (towards > from)
towards = skipAtomic(target, towards, false);
}
else if (towards > from) {
event = "delete.forward";
towards = skipAtomic(target, towards, true);
}
from = Math.min(from, towards);
to = Math.max(to, towards);
}
else {
from = skipAtomic(target, from, false);
to = skipAtomic(target, to, true);
}
return from == to ? { range } : { changes: { from, to }, range: EditorSelection.cursor(from) };
});
if (changes.changes.empty)
return false;
dispatch(state.update(changes, { scrollIntoView: true, userEvent: event }));
target.dispatch(state.update(changes, {
scrollIntoView: true,
userEvent: event,
effects: event == "delete.selection" ? EditorView.announce.of(state.phrase("Selection deleted")) : undefined
}));
return true;
}
function skipAtomic(target, pos, forward) {
@ -1024,7 +1061,7 @@ const deleteByChar = (target, forward) => deleteBy(target, pos => {
if (targetPos == pos && line.number != (forward ? state.doc.lines : 1))
targetPos += forward ? 1 : -1;
}
return skipAtomic(target, targetPos, forward);
return targetPos;
});
/**
Delete the selection, or, for cursor selections, the character
@ -1053,7 +1090,7 @@ const deleteByGroup = (target, forward) => deleteBy(target, start => {
cat = nextCat;
pos = next;
}
return skipAtomic(target, pos, forward);
return pos;
});
/**
Delete the selection or backward until the end of the next
@ -1072,7 +1109,7 @@ line, delete the line break after it.
*/
const deleteToLineEnd = view => deleteBy(view, pos => {
let lineEnd = view.lineBlockAt(pos).to;
return skipAtomic(view, pos < lineEnd ? lineEnd : Math.min(view.state.doc.length, pos + 1), true);
return pos < lineEnd ? lineEnd : Math.min(view.state.doc.length, pos + 1);
});
/**
Delete the selection, or, if it is a cursor selection, delete to
@ -1081,7 +1118,7 @@ line, delete the line break before it.
*/
const deleteToLineStart = view => deleteBy(view, pos => {
let lineStart = view.lineBlockAt(pos).from;
return skipAtomic(view, pos > lineStart ? lineStart : Math.max(0, pos - 1), false);
return pos > lineStart ? lineStart : Math.max(0, pos - 1);
});
/**
Delete all whitespace directly before a line end from the
@ -1456,11 +1493,11 @@ property changed to `mac`.)
*/
const standardKeymap = /*@__PURE__*/[
{ key: "ArrowLeft", run: cursorCharLeft, shift: selectCharLeft, preventDefault: true },
{ key: "Mod-ArrowLeft", mac: "Alt-ArrowLeft", run: cursorGroupLeft, shift: selectGroupLeft },
{ mac: "Cmd-ArrowLeft", run: cursorLineBoundaryBackward, shift: selectLineBoundaryBackward },
{ key: "Mod-ArrowLeft", mac: "Alt-ArrowLeft", run: cursorGroupLeft, shift: selectGroupLeft, preventDefault: true },
{ mac: "Cmd-ArrowLeft", run: cursorLineBoundaryLeft, shift: selectLineBoundaryLeft, preventDefault: true },
{ key: "ArrowRight", run: cursorCharRight, shift: selectCharRight, preventDefault: true },
{ key: "Mod-ArrowRight", mac: "Alt-ArrowRight", run: cursorGroupRight, shift: selectGroupRight },
{ mac: "Cmd-ArrowRight", run: cursorLineBoundaryForward, shift: selectLineBoundaryForward },
{ key: "Mod-ArrowRight", mac: "Alt-ArrowRight", run: cursorGroupRight, shift: selectGroupRight, preventDefault: true },
{ mac: "Cmd-ArrowRight", run: cursorLineBoundaryRight, shift: selectLineBoundaryRight, preventDefault: true },
{ key: "ArrowUp", run: cursorLineUp, shift: selectLineUp, preventDefault: true },
{ mac: "Cmd-ArrowUp", run: cursorDocStart, shift: selectDocStart },
{ mac: "Ctrl-ArrowUp", run: cursorPageUp, shift: selectPageUp },
@ -1531,4 +1568,4 @@ this.
*/
const indentWithTab = { key: "Tab", run: indentMore, shift: indentLess };
export { blockComment, blockUncomment, copyLineDown, copyLineUp, cursorCharBackward, cursorCharForward, cursorCharLeft, cursorCharRight, cursorDocEnd, cursorDocStart, cursorGroupBackward, cursorGroupForward, cursorGroupLeft, cursorGroupRight, cursorLineBoundaryBackward, cursorLineBoundaryForward, cursorLineDown, cursorLineEnd, cursorLineStart, cursorLineUp, cursorMatchingBracket, cursorPageDown, cursorPageUp, cursorSubwordBackward, cursorSubwordForward, cursorSyntaxLeft, cursorSyntaxRight, defaultKeymap, deleteCharBackward, deleteCharForward, deleteGroupBackward, deleteGroupForward, deleteLine, deleteToLineEnd, deleteToLineStart, deleteTrailingWhitespace, emacsStyleKeymap, history, historyField, historyKeymap, indentLess, indentMore, indentSelection, indentWithTab, insertBlankLine, insertNewline, insertNewlineAndIndent, insertTab, invertedEffects, isolateHistory, lineComment, lineUncomment, moveLineDown, moveLineUp, redo, redoDepth, redoSelection, selectAll, selectCharBackward, selectCharForward, selectCharLeft, selectCharRight, selectDocEnd, selectDocStart, selectGroupBackward, selectGroupForward, selectGroupLeft, selectGroupRight, selectLine, selectLineBoundaryBackward, selectLineBoundaryForward, selectLineDown, selectLineEnd, selectLineStart, selectLineUp, selectMatchingBracket, selectPageDown, selectPageUp, selectParentSyntax, selectSubwordBackward, selectSubwordForward, selectSyntaxLeft, selectSyntaxRight, simplifySelection, splitLine, standardKeymap, toggleBlockComment, toggleBlockCommentByLine, toggleComment, toggleLineComment, transposeChars, undo, undoDepth, undoSelection };
export { blockComment, blockUncomment, copyLineDown, copyLineUp, cursorCharBackward, cursorCharForward, cursorCharLeft, cursorCharRight, cursorDocEnd, cursorDocStart, cursorGroupBackward, cursorGroupForward, cursorGroupLeft, cursorGroupRight, cursorLineBoundaryBackward, cursorLineBoundaryForward, cursorLineBoundaryLeft, cursorLineBoundaryRight, cursorLineDown, cursorLineEnd, cursorLineStart, cursorLineUp, cursorMatchingBracket, cursorPageDown, cursorPageUp, cursorSubwordBackward, cursorSubwordForward, cursorSyntaxLeft, cursorSyntaxRight, defaultKeymap, deleteCharBackward, deleteCharForward, deleteGroupBackward, deleteGroupForward, deleteLine, deleteToLineEnd, deleteToLineStart, deleteTrailingWhitespace, emacsStyleKeymap, history, historyField, historyKeymap, indentLess, indentMore, indentSelection, indentWithTab, insertBlankLine, insertNewline, insertNewlineAndIndent, insertTab, invertedEffects, isolateHistory, lineComment, lineUncomment, moveLineDown, moveLineUp, redo, redoDepth, redoSelection, selectAll, selectCharBackward, selectCharForward, selectCharLeft, selectCharRight, selectDocEnd, selectDocStart, selectGroupBackward, selectGroupForward, selectGroupLeft, selectGroupRight, selectLine, selectLineBoundaryBackward, selectLineBoundaryForward, selectLineBoundaryLeft, selectLineBoundaryRight, selectLineDown, selectLineEnd, selectLineStart, selectLineUp, selectMatchingBracket, selectPageDown, selectPageUp, selectParentSyntax, selectSubwordBackward, selectSubwordForward, selectSyntaxLeft, selectSyntaxRight, simplifySelection, splitLine, standardKeymap, toggleBlockComment, toggleBlockCommentByLine, toggleComment, toggleLineComment, transposeChars, undo, undoDepth, undoSelection };