laif-ds
Version:
Design System di Laif con componenti React basati su principi di Atomic Design
54 lines (53 loc) • 1.48 kB
JavaScript
"use client";
import { jsxs as o } from "react/jsx-runtime";
import { useState as a, useEffect as u } from "react";
import { useLexicalComposerContext as d } from "../../../../node_modules/@lexical/react/LexicalComposerContext.prod.js";
import { $rootTextContent as f } from "../../../../node_modules/@lexical/text/LexicalText.prod.js";
let s = null;
function h() {
return window.TextEncoder === void 0 ? null : (s === null && (s = new window.TextEncoder()), s);
}
function g(t) {
const e = h();
if (e === null) {
const n = encodeURIComponent(t).match(/%[89ABab]/g);
return t.length + (n ? n.length : 0);
}
return e.encode(t).length;
}
const c = (t, e) => {
if (e === "UTF-8")
return g(t);
if (e === "UTF-16")
return t.length;
}, i = (t) => t.split(/\s+/).filter((e) => e.length > 0).length;
function T({
charset: t = "UTF-16"
}) {
const [e] = d(), [n, l] = a(() => {
const r = e.getEditorState().read(f);
return {
characters: c(r, t),
words: i(r)
};
});
return u(() => e.registerTextContentListener((r) => {
l({
characters: c(r, t),
words: i(r)
});
}), [e, t]), /* @__PURE__ */ o("div", { className: "flex gap-2 text-xs whitespace-nowrap text-gray-500", children: [
/* @__PURE__ */ o("p", { children: [
n.characters,
" characters"
] }),
"|",
/* @__PURE__ */ o("p", { children: [
n.words,
" words"
] })
] });
}
export {
T as CounterCharacterPlugin
};