laif-ds
Version:
Design System di Laif con componenti React basati su principi di Atomic Design
237 lines (236 loc) • 7.52 kB
JavaScript
"use client";
import { addClassNamesToElement as d, $getAdjacentCaret as D, removeClassNamesFromElement as I } from "../utils/LexicalUtils.prod.js";
import { ElementNode as R, $createParagraphNode as T, $isTextNode as W, $isTabNode as $, $createTabNode as j, $createLineBreakNode as b, $applyNodeReplacement as A, isHTMLElement as B, $getSiblingCaret as q, TextNode as z } from "../../lexical/Lexical.prod.js";
import "../../../_virtual/prism.js";
import "../../prismjs/components/prism-clike.js";
import "../../prismjs/components/prism-javascript.js";
import "../../prismjs/components/prism-markup.js";
import "../../prismjs/components/prism-markdown.js";
import "../../prismjs/components/prism-c.js";
import "../../prismjs/components/prism-css.js";
import "../../prismjs/components/prism-objectivec.js";
import "../../prismjs/components/prism-sql.js";
import "../../prismjs/components/prism-powershell.js";
import "../../../_virtual/prism-python.js";
import "../../../_virtual/prism-rust.js";
import "../../prismjs/components/prism-swift.js";
import "../../../_virtual/prism-typescript.js";
import "../../../_virtual/prism-java.js";
import "../../../_virtual/prism-cpp.js";
const Q = globalThis.Prism || window.Prism, O = (n) => {
try {
return !!n && Q.languages.hasOwnProperty(n);
} catch {
return !1;
}
};
function J(n, e) {
for (const t of n.childNodes) {
if (B(t) && t.tagName === e) return !0;
J(t, e);
}
return !1;
}
const c = "data-language", p = "data-highlight-language";
class f extends R {
static getType() {
return "code";
}
static clone(e) {
return new f(e.__language, e.__key);
}
constructor(e, t) {
super(t), this.__language = e || void 0, this.__isSyntaxHighlightSupported = O(e);
}
createDOM(e) {
const t = document.createElement("code");
d(t, e.theme.code), t.setAttribute("spellcheck", "false");
const r = this.getLanguage();
return r && (t.setAttribute(c, r), this.getIsSyntaxHighlightSupported() && t.setAttribute(p, r)), t;
}
updateDOM(e, t, r) {
const i = this.__language, s = e.__language;
return i ? i !== s && (t.setAttribute(c, i), this.__isSyntaxHighlightSupported && t.setAttribute(p, i)) : s && (t.removeAttribute(c), e.__isSyntaxHighlightSupported && t.removeAttribute(p)), !1;
}
exportDOM(e) {
const t = document.createElement("pre");
d(t, e._config.theme.code), t.setAttribute("spellcheck", "false");
const r = this.getLanguage();
return r && (t.setAttribute(c, r), this.getIsSyntaxHighlightSupported() && t.setAttribute(p, r)), { element: t };
}
static importDOM() {
return { code: (e) => e.textContent != null && (/\r?\n/.test(e.textContent) || J(e, "BR")) ? { conversion: C, priority: 1 } : null, div: () => ({ conversion: X, priority: 1 }), pre: () => ({ conversion: C, priority: 0 }), table: (e) => y(e) ? { conversion: G, priority: 3 } : null, td: (e) => {
const t = e, r = t.closest("table");
return t.classList.contains("js-file-line") || r && y(r) ? { conversion: v, priority: 3 } : null;
}, tr: (e) => {
const t = e.closest("table");
return t && y(t) ? { conversion: v, priority: 3 } : null;
} };
}
static importJSON(e) {
return h().updateFromJSON(e);
}
updateFromJSON(e) {
return super.updateFromJSON(e).setLanguage(e.language);
}
exportJSON() {
return { ...super.exportJSON(), language: this.getLanguage() };
}
insertNewAfter(e, t = !0) {
const r = this.getChildren(), i = r.length;
if (i >= 2 && r[i - 1].getTextContent() === `
` && r[i - 2].getTextContent() === `
` && e.isCollapsed() && e.anchor.key === this.__key && e.anchor.offset === i) {
r[i - 1].remove(), r[i - 2].remove();
const o = T();
return this.insertAfter(o, t), o;
}
const { anchor: s, focus: u } = e, a = (s.isBefore(u) ? s : u).getNode();
if (W(a)) {
let o = V(a);
const g = [];
for (; ; ) if ($(o)) g.push(j()), o = o.getNextSibling();
else {
if (!F(o)) break;
{
let l = 0;
const w = o.getTextContent(), x = o.getTextContentSize();
for (; l < x && w[l] === " "; ) l++;
if (l !== 0 && g.push(L(" ".repeat(l))), l !== x) break;
o = o.getNextSibling();
}
}
const _ = a.splitText(s.offset)[0], E = s.offset === 0 ? 0 : 1, P = _.getIndexWithinParent() + E, M = a.getParentOrThrow(), k = [b(), ...g];
M.splice(P, 0, k);
const S = g[g.length - 1];
S ? S.select() : s.offset === 0 ? _.selectPrevious() : _.getNextSibling().selectNext(0, 0);
}
if (U(a)) {
const { offset: o } = e.anchor;
a.splice(o, 0, [b()]), a.select(o + 1, o + 1);
}
return null;
}
canIndent() {
return !1;
}
collapseAtStart() {
const e = T();
return this.getChildren().forEach((t) => e.append(t)), this.replace(e), !0;
}
setLanguage(e) {
const t = this.getWritable();
return t.__language = e || void 0, t.__isSyntaxHighlightSupported = O(e), t;
}
getLanguage() {
return this.getLatest().__language;
}
getIsSyntaxHighlightSupported() {
return this.getLatest().__isSyntaxHighlightSupported;
}
}
function h(n) {
return A(new f(n));
}
function U(n) {
return n instanceof f;
}
function C(n) {
return { node: h(n.getAttribute(c)) };
}
function X(n) {
const e = n, t = H(e);
return t || function(r) {
let i = r.parentElement;
for (; i !== null; ) {
if (H(i)) return !0;
i = i.parentElement;
}
return !1;
}(e) ? { node: t ? h() : null } : { node: null };
}
function G() {
return { node: h() };
}
function v() {
return { node: null };
}
function H(n) {
return n.style.fontFamily.match("monospace") !== null;
}
function y(n) {
return n.classList.contains("js-file-line-container");
}
class m extends z {
constructor(e = "", t, r) {
super(e, r), this.__highlightType = t;
}
static getType() {
return "code-highlight";
}
static clone(e) {
return new m(e.__text, e.__highlightType || void 0, e.__key);
}
getHighlightType() {
return this.getLatest().__highlightType;
}
setHighlightType(e) {
const t = this.getWritable();
return t.__highlightType = e || void 0, t;
}
canHaveFormat() {
return !1;
}
createDOM(e) {
const t = super.createDOM(e), r = N(e.theme, this.__highlightType);
return d(t, r), t;
}
updateDOM(e, t, r) {
const i = super.updateDOM(e, t, r), s = N(r.theme, e.__highlightType), u = N(r.theme, this.__highlightType);
return s !== u && (s && I(t, s), u && d(t, u)), i;
}
static importJSON(e) {
return L().updateFromJSON(e);
}
updateFromJSON(e) {
return super.updateFromJSON(e).setHighlightType(e.highlightType);
}
exportJSON() {
return { ...super.exportJSON(), highlightType: this.getHighlightType() };
}
setFormat(e) {
return this;
}
isParentRequired() {
return !0;
}
createParentElementNode() {
return h();
}
}
function N(n, e) {
return e && n && n.codeHighlight && n.codeHighlight[e];
}
function L(n = "", e) {
return A(new m(n, e));
}
function F(n) {
return n instanceof m;
}
function K(n, e) {
let t = n;
for (let r = q(n, e); r && (F(r.origin) || $(r.origin)); r = D(r)) t = r.origin;
return t;
}
function V(n) {
return K(n, "previous");
}
export {
L as $createCodeHighlightNode,
h as $createCodeNode,
V as $getFirstCodeNodeOfLine,
F as $isCodeHighlightNode,
U as $isCodeNode,
m as CodeHighlightNode,
f as CodeNode
};