@richscripts/richtexteditor 2.14.1 → 2.15.0
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/README.md +173 -10
- package/angular/build-manifest.json +23 -0
- package/angular/index.d.ts +71 -76
- package/angular/index.mjs +2 -0
- package/angular/package.json +4 -0
- package/headless/index.d.ts +3 -1
- package/headless/index.js +72 -16
- package/index.d.ts +33 -54
- package/integrations/initialization-scope.js +27 -0
- package/integrations/native-mount.js +30 -0
- package/integrations/shared.d.ts +23 -1
- package/integrations/shared.js +58 -22
- package/package.json +25 -3
- package/react/index.js +118 -37
- package/react/index.mjs +29 -0
- package/richtexteditor/all_plugins.js +7001 -1078
- package/richtexteditor/all_plugins.min.js +62 -59
- package/richtexteditor/lang/emoji/LICENSE-CLDR.txt +41 -0
- package/richtexteditor/lang/emoji/rte-emoji-de.js +3 -0
- package/richtexteditor/lang/emoji/rte-emoji-es.js +3 -0
- package/richtexteditor/lang/emoji/rte-emoji-fr.js +3 -0
- package/richtexteditor/lang/emoji/rte-emoji-it.js +3 -0
- package/richtexteditor/lang/emoji/rte-emoji-ja.js +3 -0
- package/richtexteditor/lang/emoji/rte-emoji-ko.js +3 -0
- package/richtexteditor/lang/emoji/rte-emoji-nl.js +3 -0
- package/richtexteditor/lang/emoji/rte-emoji-pt-pt.js +3 -0
- package/richtexteditor/lang/emoji/rte-emoji-pt.js +3 -0
- package/richtexteditor/lang/emoji/rte-emoji-ru.js +3 -0
- package/richtexteditor/lang/emoji/rte-emoji-zh-Hans.js +3 -0
- package/richtexteditor/lang/emoji/rte-emoji-zh-Hant.js +3 -0
- package/richtexteditor/lang/rte-lang-af.js +1 -0
- package/richtexteditor/lang/rte-lang-ar.js +1 -0
- package/richtexteditor/lang/rte-lang-bg.js +1 -0
- package/richtexteditor/lang/rte-lang-bn.js +1 -0
- package/richtexteditor/lang/rte-lang-bs.js +1 -0
- package/richtexteditor/lang/rte-lang-ca.js +1 -0
- package/richtexteditor/lang/rte-lang-cs.js +1 -0
- package/richtexteditor/lang/rte-lang-cy.js +1 -0
- package/richtexteditor/lang/rte-lang-da.js +1 -0
- package/richtexteditor/lang/rte-lang-de.js +1017 -2
- package/richtexteditor/lang/rte-lang-el.js +1 -0
- package/richtexteditor/lang/rte-lang-en.js +1 -0
- package/richtexteditor/lang/rte-lang-es.js +1023 -2
- package/richtexteditor/lang/rte-lang-et.js +1 -0
- package/richtexteditor/lang/rte-lang-fa.js +1 -0
- package/richtexteditor/lang/rte-lang-fi.js +1 -0
- package/richtexteditor/lang/rte-lang-fil.js +1 -0
- package/richtexteditor/lang/rte-lang-fj.js +1 -0
- package/richtexteditor/lang/rte-lang-fr.js +1023 -2
- package/richtexteditor/lang/rte-lang-ga.js +1 -0
- package/richtexteditor/lang/rte-lang-gu.js +1 -0
- package/richtexteditor/lang/rte-lang-he.js +1 -0
- package/richtexteditor/lang/rte-lang-hi.js +1 -0
- package/richtexteditor/lang/rte-lang-hr.js +1 -0
- package/richtexteditor/lang/rte-lang-ht.js +1 -0
- package/richtexteditor/lang/rte-lang-hu.js +1 -0
- package/richtexteditor/lang/rte-lang-id.js +1 -0
- package/richtexteditor/lang/rte-lang-is.js +1 -0
- package/richtexteditor/lang/rte-lang-it.js +1023 -2
- package/richtexteditor/lang/rte-lang-ja.js +1023 -2
- package/richtexteditor/lang/rte-lang-kn.js +1 -0
- package/richtexteditor/lang/rte-lang-ko.js +1023 -2
- package/richtexteditor/lang/rte-lang-lt.js +1 -0
- package/richtexteditor/lang/rte-lang-lv.js +1 -0
- package/richtexteditor/lang/rte-lang-mg.js +1 -0
- package/richtexteditor/lang/rte-lang-mi.js +1 -0
- package/richtexteditor/lang/rte-lang-ml.js +1 -0
- package/richtexteditor/lang/rte-lang-mr.js +1 -0
- package/richtexteditor/lang/rte-lang-ms.js +1 -0
- package/richtexteditor/lang/rte-lang-mt.js +1 -0
- package/richtexteditor/lang/rte-lang-mww.js +1 -0
- package/richtexteditor/lang/rte-lang-nb.js +1 -0
- package/richtexteditor/lang/rte-lang-nl.js +1023 -2
- package/richtexteditor/lang/rte-lang-otq.js +1 -0
- package/richtexteditor/lang/rte-lang-pa.js +1 -0
- package/richtexteditor/lang/rte-lang-pl.js +1 -0
- package/richtexteditor/lang/rte-lang-pt-pt.js +1023 -2
- package/richtexteditor/lang/rte-lang-pt.js +1023 -2
- package/richtexteditor/lang/rte-lang-ro.js +1 -0
- package/richtexteditor/lang/rte-lang-ru.js +1023 -2
- package/richtexteditor/lang/rte-lang-sk.js +1 -0
- package/richtexteditor/lang/rte-lang-sl.js +1 -0
- package/richtexteditor/lang/rte-lang-sm.js +1 -0
- package/richtexteditor/lang/rte-lang-sr-Cyrl.js +1 -0
- package/richtexteditor/lang/rte-lang-sr-Latn.js +1 -0
- package/richtexteditor/lang/rte-lang-sv.js +1 -0
- package/richtexteditor/lang/rte-lang-sw.js +1 -0
- package/richtexteditor/lang/rte-lang-ta.js +1 -0
- package/richtexteditor/lang/rte-lang-te.js +1 -0
- package/richtexteditor/lang/rte-lang-th.js +1 -0
- package/richtexteditor/lang/rte-lang-tlh-Latn.js +1 -0
- package/richtexteditor/lang/rte-lang-tlh-Piqd.js +1 -0
- package/richtexteditor/lang/rte-lang-to.js +1 -0
- package/richtexteditor/lang/rte-lang-tr.js +1 -0
- package/richtexteditor/lang/rte-lang-ty.js +1 -0
- package/richtexteditor/lang/rte-lang-uk.js +1 -0
- package/richtexteditor/lang/rte-lang-ur.js +1 -0
- package/richtexteditor/lang/rte-lang-vi.js +1 -0
- package/richtexteditor/lang/rte-lang-yua.js +1 -0
- package/richtexteditor/lang/rte-lang-zh-Hans.js +1017 -2
- package/richtexteditor/lang/rte-lang-zh-Hant.js +1017 -2
- package/richtexteditor/plugins/a11yenhance.js +2 -1
- package/richtexteditor/plugins/a11yenhance.min.js +1 -1
- package/richtexteditor/plugins/accessibilitychecker.js +252 -60
- package/richtexteditor/plugins/accessibilitychecker.min.js +1 -1
- package/richtexteditor/plugins/aitoolkit.js +966 -303
- package/richtexteditor/plugins/aitoolkit.min.js +7 -7
- package/richtexteditor/plugins/all_plugins.js +7001 -1078
- package/richtexteditor/plugins/all_plugins.min.js +62 -59
- package/richtexteditor/plugins/autocorrect.js +66 -31
- package/richtexteditor/plugins/autocorrect.min.js +1 -1
- package/richtexteditor/plugins/autoembed.js +17 -0
- package/richtexteditor/plugins/autoembed.min.js +1 -1
- package/richtexteditor/plugins/blocktypes.js +18 -9
- package/richtexteditor/plugins/blocktypes.min.js +1 -1
- package/richtexteditor/plugins/bookmarkcard.js +12 -5
- package/richtexteditor/plugins/bookmarkcard.min.js +2 -2
- package/richtexteditor/plugins/changecase.js +72 -19
- package/richtexteditor/plugins/changecase.min.js +1 -1
- package/richtexteditor/plugins/charlimit.js +62 -2
- package/richtexteditor/plugins/charlimit.min.js +2 -2
- package/richtexteditor/plugins/comments.js +458 -59
- package/richtexteditor/plugins/comments.min.js +4 -3
- package/richtexteditor/plugins/contentminimap.js +25 -6
- package/richtexteditor/plugins/contentminimap.min.js +1 -1
- package/richtexteditor/plugins/crossreference.js +1 -1
- package/richtexteditor/plugins/crossreference.min.js +1 -1
- package/richtexteditor/plugins/dialoga11y.js +26 -4
- package/richtexteditor/plugins/dialoga11y.min.js +1 -1
- package/richtexteditor/plugins/dictation.js +1 -1
- package/richtexteditor/plugins/documentimport.js +220 -51
- package/richtexteditor/plugins/documentimport.min.js +4 -4
- package/richtexteditor/plugins/documentoutline.js +47 -8
- package/richtexteditor/plugins/documentoutline.min.js +1 -1
- package/richtexteditor/plugins/docxexport.js +204 -32
- package/richtexteditor/plugins/docxexport.min.js +2 -2
- package/richtexteditor/plugins/draghandle.js +267 -3
- package/richtexteditor/plugins/draghandle.min.js +1 -1
- package/richtexteditor/plugins/emailtoolkit.js +28 -14
- package/richtexteditor/plugins/emailtoolkit.min.js +1 -1
- package/richtexteditor/plugins/emojiautocomplete.js +110 -56
- package/richtexteditor/plugins/emojiautocomplete.min.js +1 -1
- package/richtexteditor/plugins/footnotes.js +65 -11
- package/richtexteditor/plugins/footnotes.min.js +1 -1
- package/richtexteditor/plugins/formatpainter.js +10 -0
- package/richtexteditor/plugins/formatpainter.min.js +1 -1
- package/richtexteditor/plugins/formattingmarks.js +6 -6
- package/richtexteditor/plugins/formattingmarks.min.js +1 -1
- package/richtexteditor/plugins/gapcursor.js +60 -0
- package/richtexteditor/plugins/gapcursor.min.js +1 -1
- package/richtexteditor/plugins/ghostcomplete.js +1 -1
- package/richtexteditor/plugins/html2pdf.js +1 -1
- package/richtexteditor/plugins/html2pdf.min.js +1 -1
- package/richtexteditor/plugins/imageeditor.js +12 -6
- package/richtexteditor/plugins/imageeditor.min.js +1 -1
- package/richtexteditor/plugins/importstyles.js +1 -1
- package/richtexteditor/plugins/inlinecode.js +25 -0
- package/richtexteditor/plugins/inlinecode.min.js +1 -1
- package/richtexteditor/plugins/insertcode.js +21 -3
- package/richtexteditor/plugins/insertcode.min.js +4 -4
- package/richtexteditor/plugins/insertemoji.js +112 -15
- package/richtexteditor/plugins/insertemoji.min.js +1 -1
- package/richtexteditor/plugins/insertgallery.js +42 -36
- package/richtexteditor/plugins/insertgallery.min.js +1 -1
- package/richtexteditor/plugins/inserttemplate.js +33 -17
- package/richtexteditor/plugins/inserttemplate.min.js +1 -1
- package/richtexteditor/plugins/keyboarda11y.js +66 -3
- package/richtexteditor/plugins/keyboarda11y.min.js +1 -1
- package/richtexteditor/plugins/layouttable.js +20 -0
- package/richtexteditor/plugins/layouttable.min.js +1 -1
- package/richtexteditor/plugins/linkchecker.js +29 -9
- package/richtexteditor/plugins/linkchecker.min.js +1 -1
- package/richtexteditor/plugins/localdraft.js +51 -7
- package/richtexteditor/plugins/localdraft.min.js +1 -1
- package/richtexteditor/plugins/markdownexport.js +159 -0
- package/richtexteditor/plugins/markdownexport.min.js +2 -2
- package/richtexteditor/plugins/mathdialog.js +11 -5
- package/richtexteditor/plugins/mathdialog.min.js +1 -1
- package/richtexteditor/plugins/mentionplugin.js +88 -25
- package/richtexteditor/plugins/mentionplugin.min.js +1 -1
- package/richtexteditor/plugins/mermaiddiagram.js +9 -3
- package/richtexteditor/plugins/mermaiddiagram.min.js +2 -2
- package/richtexteditor/plugins/multilevellist.js +4 -0
- package/richtexteditor/plugins/multilevellist.min.js +1 -1
- package/richtexteditor/plugins/pdfexport.js +235 -35
- package/richtexteditor/plugins/pdfexport.min.js +12 -12
- package/richtexteditor/plugins/permanentpen.js +3 -3
- package/richtexteditor/plugins/permanentpen.min.js +1 -1
- package/richtexteditor/plugins/readabilitystats.js +25 -11
- package/richtexteditor/plugins/readabilitystats.min.js +1 -1
- package/richtexteditor/plugins/readaloud.js +29 -15
- package/richtexteditor/plugins/readaloud.min.js +1 -1
- package/richtexteditor/plugins/restrictedediting.js +166 -0
- package/richtexteditor/plugins/restrictedediting.min.js +2 -2
- package/richtexteditor/plugins/revisionhistory.js +169 -37
- package/richtexteditor/plugins/revisionhistory.min.js +3 -3
- package/richtexteditor/plugins/rubyannotation.js +19 -9
- package/richtexteditor/plugins/rubyannotation.min.js +1 -1
- package/richtexteditor/plugins/sanitizer.js +62 -3
- package/richtexteditor/plugins/sanitizer.min.js +1 -1
- package/richtexteditor/plugins/slashcommand.js +30 -16
- package/richtexteditor/plugins/slashcommand.min.js +2 -2
- package/richtexteditor/plugins/smartchips.js +36 -22
- package/richtexteditor/plugins/smartchips.min.js +2 -2
- package/richtexteditor/plugins/spellcheck.js +17 -8
- package/richtexteditor/plugins/spellcheck.min.js +2 -2
- package/richtexteditor/plugins/stateinspector.js +19 -9
- package/richtexteditor/plugins/stateinspector.min.js +2 -2
- package/richtexteditor/plugins/structured-content-bridge.js +56 -24
- package/richtexteditor/plugins/structured-content-bridge.min.js +7 -7
- package/richtexteditor/plugins/tableofcontents.js +5 -2
- package/richtexteditor/plugins/tableofcontents.min.js +1 -1
- package/richtexteditor/plugins/tabletools.js +388 -3
- package/richtexteditor/plugins/tabletools.min.js +1 -1
- package/richtexteditor/plugins/textdirection.js +18 -5
- package/richtexteditor/plugins/textdirection.min.js +1 -1
- package/richtexteditor/plugins/textpartlanguage.js +161 -32
- package/richtexteditor/plugins/textpartlanguage.min.js +1 -1
- package/richtexteditor/plugins/todolist.js +90 -6
- package/richtexteditor/plugins/todolist.min.js +1 -1
- package/richtexteditor/plugins/trackedchanges.js +1812 -25
- package/richtexteditor/plugins/trackedchanges.min.js +5 -3
- package/richtexteditor/plugins/wordexport.js +2 -2
- package/richtexteditor/plugins/yjscollab.js +9 -4
- package/richtexteditor/plugins/yjscollab.min.js +1 -1
- package/richtexteditor/plugins/zz_richtextbox_dialog_style.js +22 -13
- package/richtexteditor/plugins/zz_richtextbox_dialog_style.min.js +1 -1
- package/richtexteditor/rte-config.js +130 -50
- package/richtexteditor/rte-headless.js +19 -4
- package/richtexteditor/rte-webcomponent.js +89 -16
- package/richtexteditor/rte.js +132 -52
- package/scripts/build-angular.mjs +97 -0
- package/svelte/index.d.ts +2 -1
- package/svelte/index.js +80 -9
- package/vue/index.js +130 -34
- package/angular/component.ts +0 -297
- package/angular/index.ts +0 -24
|
@@ -1 +1 @@
|
|
|
1
|
-
window.RTE_DefaultConfig||(window.RTE_DefaultConfig={}),RTE_DefaultConfig.plugin_changecase=RTE_Plugin_ChangeCase,typeof RTE_DefaultConfig.titleCaseSmallWords>"u"&&(RTE_DefaultConfig.titleCaseSmallWords="a an and as at but by for if in nor of on or per so the to via vs with");function RTE_Plugin_ChangeCase(){var
|
|
1
|
+
window.RTE_DefaultConfig||(window.RTE_DefaultConfig={}),RTE_DefaultConfig.plugin_changecase=RTE_Plugin_ChangeCase,typeof RTE_DefaultConfig.titleCaseSmallWords>"u"&&(RTE_DefaultConfig.titleCaseSmallWords="a an and as at but by for if in nor of on or per so the to via vs with");function RTE_Plugin_ChangeCase(){var c=this,y,i;c.PluginName="ChangeCase",c.InitConfig=function(e){y=e},c.InitEditor=function(e){i=e,i.attachEvent("exec_command_changecase",function(t){t.returnValue=!0,c.Apply(t&&t.value?t.value:"upper")}),i.changeCase=function(t){return c.Apply(t)},i.getChangeCaseModes=function(){return["upper","lower","title","sentence","toggle"]},(i.bindDocumentEvent?function(t){i.bindDocumentEvent("keydown",t,!0)}:function(t){i.getDocument().addEventListener("keydown",t,!0)})(function(t){if(!(t.key!=="F3"||!t.shiftKey||t.ctrlKey||t.metaKey||t.altKey)){var n="";try{n=String(i.getSelection().toString()||"")}catch{n=""}if(/\S/.test(n)){t.preventDefault();var r=n===n.toUpperCase()?"lower":n===w(n,"title")?"upper":"title";c.Apply(r)}}})};function m(){try{return i.getDocument()}catch{return null}}function O(){try{return i.getEditable()}catch{return null}}function D(){var e={};return String(y.titleCaseSmallWords||"").split(/\s+/).forEach(function(t){t&&(e[t.toLowerCase()]=!0)}),e}function w(e,t){switch(t){case"lower":return e.toLowerCase();case"upper":return e.toUpperCase();case"toggle":return e.replace(/\S/g,function(n){var r=n.toUpperCase();return n===r?n.toLowerCase():r});case"sentence":return N(e);case"title":return A(e);default:return e}}function N(e){for(var t=e.toLowerCase(),n="",r=!0,o=0;o<t.length;o++){var a=t[o];r&&/\S/.test(a)?(n+=a.toUpperCase(),/[\p{L}\p{N}]/u.test(a)&&(r=!1)):n+=a,/[.!?]/.test(a)&&(r=!0)}return n}function A(e){var t=D(),n=e.split(/(\s+)/),r=0,o=0,a;for(a=0;a<n.length;a++)/^\s*$/.test(n[a])||o++;for(a=0;a<n.length;a++)if(!/^\s*$/.test(n[a])){var u=r===0||r===o-1;n[a]=k(n[a],t,u),r++}return n.join("")}function k(e,t,n){var r=e.toLowerCase(),o=r.replace(/[^\p{L}\p{N}']/gu,"");if(!n&&t[o])return r;for(var a=r.split(/([-\/])/),u=a.length-1,s=0;s<=u;s+=2){var l=a[s];if(l){var f=l.replace(/[^\p{L}\p{N}']/gu,"");s!==0&&s!==u&&t[f]||(a[s]=l.replace(/[\p{L}\p{N}]/u,function(p){return p.toUpperCase()}))}}return a.join("")}function b(e){var t=e.startContainer;if(!t||t.nodeType!==3)return!1;for(var n=t.nodeValue||"",r=e.startOffset,o=r;r>0&&/[\p{L}\p{N}'']/u.test(n[r-1]);)r--;for(;o<n.length&&/[\p{L}\p{N}'']/u.test(n[o]);)o++;return r===o?!1:(e.setStart(t,r),e.setEnd(t,o),!0)}function x(e,t){if(e.startContainer.nodeType===3&&e.startOffset>0){var n=e.startContainer.splitText(e.startOffset);e.setStart(n,0)}e.endContainer.nodeType===3&&e.endOffset<e.endContainer.nodeValue.length&&e.endContainer.splitText(e.endOffset);var r=e.commonAncestorContainer;if(r.nodeType===3)return[r];for(var o=[],a=t.createTreeWalker(r,4,null,!1),u;u=a.nextNode();)if(u.nodeValue&&(!e.intersectsNode||e.intersectsNode(u))){var s=t.createRange();s.selectNodeContents(u),e.compareBoundaryPoints(Range.END_TO_START,s)<0&&e.compareBoundaryPoints(Range.START_TO_END,s)>0&&o.push(u)}return o}c.Apply=function(e){e=String(e||"upper").toLowerCase();var t=m(),n;try{n=i.getSelection()}catch{return!1}if(!t||!n||n.rangeCount===0||i.__trackHook&&i.__trackHook("refuse",{message:"Suggesting is on, so the case was not changed. Turn suggesting off to change it."})===!0)return!1;var r=t.querySelectorAll("[__rte_selected_cell]");if(r.length>1){for(var o=!1,a=0;a<r.length;a++){var u=t.createRange();u.selectNodeContents(r[a]),T(u,t,e)&&(o=!0)}return o&&_(),o}var s=n.getRangeAt(0);if(s.collapsed&&!b(s))return!1;var l=T(s,t,e);if(!l)return!1;try{var f=t.createRange();f.setStart(l[0],0),f.setEnd(l[l.length-1],l[l.length-1].nodeValue.length),n.removeAllRanges(),n.addRange(f)}catch{}return _(),!0};function T(e,t,n){var r=x(e,t);if(!r.length)return null;for(var o="",a=0;a<r.length;a++)o+=r[a].nodeValue;for(var u="",s=0;s<o.length;s++){var l=o.charAt(s);u+=l.toUpperCase().length!==1||l.toLowerCase().length!==1?l===l.toLowerCase()?"x":"X":l}var f=w(u,n);if(f.length!==u.length)return null;for(var p=[],S=!1,d=0;d<o.length;d++){var v=o.charAt(d),E=u.charAt(d),R=f.charAt(d),h=v;R!==E&&(h=R===E.toUpperCase()?v.toUpperCase():v.toLowerCase()),h!==v&&(S=!0),p.push(h)}if(!S)return null;for(var C=0,g=0;g<r.length;g++){var L=r[g].nodeValue.length;r[g].nodeValue=p.slice(C,C+L).join(""),C+=L}return r}function _(){try{typeof i.updateDesign=="function"&&i.updateDesign()}catch{}try{typeof i.fireChange=="function"&&i.fireChange()}catch{}}}
|
|
@@ -38,6 +38,23 @@ function RTE_Plugin_CharLimit() {
|
|
|
38
38
|
|
|
39
39
|
if (!maxChars() && !maxWords()) return; // dormant unless a limit is configured
|
|
40
40
|
|
|
41
|
+
// The public insert obeys the cap too (a host's "insert snippet" button went straight past
|
|
42
|
+
// it). Over-long content is cut to what fits, as plain text, the same way a paste is.
|
|
43
|
+
if (config.charLimitEnforce !== false && typeof editor.insertHTML === "function") {
|
|
44
|
+
var origInsertHTML = editor.insertHTML;
|
|
45
|
+
editor.insertHTML = function (html) {
|
|
46
|
+
if (!maxChars()) return origInsertHTML.apply(this, arguments);
|
|
47
|
+
var probe = document.createElement("div");
|
|
48
|
+
probe.innerHTML = String(html == null ? "" : html);
|
|
49
|
+
var add = (probe.textContent || "").length;
|
|
50
|
+
var remaining = maxChars() - countChars() + selectionLength();
|
|
51
|
+
if (add <= remaining) return origInsertHTML.apply(this, arguments);
|
|
52
|
+
flash();
|
|
53
|
+
if (remaining <= 0) return false;
|
|
54
|
+
return origInsertHTML.call(this, escapeHtml((probe.textContent || "").slice(0, remaining)));
|
|
55
|
+
};
|
|
56
|
+
}
|
|
57
|
+
|
|
41
58
|
// The iframe editable may not exist at InitEditor time — bind setup now
|
|
42
59
|
// AND on "created", with an idempotency guard so we never double-bind.
|
|
43
60
|
setup();
|
|
@@ -60,6 +77,7 @@ function RTE_Plugin_CharLimit() {
|
|
|
60
77
|
if (config.charLimitEnforce !== false) {
|
|
61
78
|
doc.addEventListener("beforeinput", onBeforeInput, true);
|
|
62
79
|
doc.addEventListener("paste", onPaste, true);
|
|
80
|
+
doc.addEventListener("drop", onDrop, true);
|
|
63
81
|
}
|
|
64
82
|
doc.addEventListener("input", function () { refresh(); }, true);
|
|
65
83
|
mountCounter();
|
|
@@ -71,12 +89,27 @@ function RTE_Plugin_CharLimit() {
|
|
|
71
89
|
|
|
72
90
|
function plainText() {
|
|
73
91
|
try {
|
|
92
|
+
// 2026-10-15 ask getText(): it leaves out page-break labels (a two-word page plus a break counted five
|
|
93
|
+
// words) and plugins' on-screen-only text. tools/wordcount/page-break-not-text.mjs
|
|
94
|
+
if (typeof editor.getText === "function") { var gt = editor.getText(); if (typeof gt === "string") return gt; }
|
|
74
95
|
var ed = editor.getEditable();
|
|
75
96
|
return ed ? (ed.innerText || ed.textContent || "") : "";
|
|
76
97
|
} catch (e) { return ""; }
|
|
77
98
|
}
|
|
78
99
|
function countChars() { return plainText().replace(/\r\n/g, "\n").length; }
|
|
79
|
-
|
|
100
|
+
// Same rules as the core status bar: each CJK character is a word (those scripts have no
|
|
101
|
+
// spaces, so "你好世界" was 1), and a token of punctuation alone ("—", "!") is not a word.
|
|
102
|
+
function countWords() {
|
|
103
|
+
var t = plainText();
|
|
104
|
+
var cjk = /[\u3005\u3007\u3040-\u30ff\u3400-\u4dbf\u4e00-\u9fff\uf900-\ufaff]/g;
|
|
105
|
+
var m = t.match(cjk);
|
|
106
|
+
var n = m ? m.length : 0;
|
|
107
|
+
var tokens = t.replace(cjk, " ").split(/\s+/);
|
|
108
|
+
for (var i = 0; i < tokens.length; i++) {
|
|
109
|
+
if (/[^!-\/:-@\[-`{-~\xa1-\xbf\u2000-\u206f\u3000-\u303f\uff01-\uff0f]/.test(tokens[i])) n++;
|
|
110
|
+
}
|
|
111
|
+
return n;
|
|
112
|
+
}
|
|
80
113
|
|
|
81
114
|
function onBeforeInput(e) {
|
|
82
115
|
var t = e.inputType || "";
|
|
@@ -102,7 +135,9 @@ function RTE_Plugin_CharLimit() {
|
|
|
102
135
|
function onPaste(e) {
|
|
103
136
|
if (!maxChars()) return;
|
|
104
137
|
var remaining = maxChars() - countChars() + selectionLength();
|
|
105
|
-
|
|
138
|
+
// stopImmediatePropagation as well as preventDefault: the core paste handler inserts the
|
|
139
|
+
// clipboard itself and ignores defaultPrevented, so the full paste landed past the cap.
|
|
140
|
+
if (remaining <= 0) { e.preventDefault(); e.stopImmediatePropagation(); flash(); return; }
|
|
106
141
|
var cd = e.clipboardData || window.clipboardData;
|
|
107
142
|
if (!cd) return;
|
|
108
143
|
var text = "";
|
|
@@ -110,6 +145,7 @@ function RTE_Plugin_CharLimit() {
|
|
|
110
145
|
if (text.length > remaining) {
|
|
111
146
|
// Truncate the paste to what fits.
|
|
112
147
|
e.preventDefault();
|
|
148
|
+
e.stopImmediatePropagation();
|
|
113
149
|
var fit = text.slice(0, remaining);
|
|
114
150
|
try { if (typeof editor.insertHTML === "function") editor.insertHTML(escapeHtml(fit).replace(/\n/g, "<br>")); }
|
|
115
151
|
catch (e2) {}
|
|
@@ -117,6 +153,30 @@ function RTE_Plugin_CharLimit() {
|
|
|
117
153
|
}
|
|
118
154
|
}
|
|
119
155
|
|
|
156
|
+
// A drop has no caret to truncate at, so content that would pass the cap is refused whole
|
|
157
|
+
// (the core drop handler inserts it itself, so the event must not reach it).
|
|
158
|
+
function onDrop(e) {
|
|
159
|
+
if (!maxChars()) return;
|
|
160
|
+
var dt = e.dataTransfer;
|
|
161
|
+
if (!dt) return;
|
|
162
|
+
var add = 0;
|
|
163
|
+
try {
|
|
164
|
+
var text = dt.getData("text/plain");
|
|
165
|
+
if (!text) {
|
|
166
|
+
var probe = document.createElement("div");
|
|
167
|
+
probe.innerHTML = dt.getData("text/html") || "";
|
|
168
|
+
text = probe.textContent || "";
|
|
169
|
+
}
|
|
170
|
+
add = text.length;
|
|
171
|
+
} catch (er) { return; }
|
|
172
|
+
if (!add) return;
|
|
173
|
+
if (countChars() + add > maxChars()) {
|
|
174
|
+
e.preventDefault();
|
|
175
|
+
e.stopImmediatePropagation();
|
|
176
|
+
flash();
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
|
|
120
180
|
function hasSelection() {
|
|
121
181
|
try { var s = editor.getSelection(); return s && s.rangeCount > 0 && !s.isCollapsed; } catch (e) { return false; }
|
|
122
182
|
}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
window.RTE_DefaultConfig||(window.RTE_DefaultConfig={}),RTE_DefaultConfig.plugin_charlimit=RTE_Plugin_CharLimit;function RTE_Plugin_CharLimit(){var
|
|
2
|
-
`).length}function
|
|
1
|
+
window.RTE_DefaultConfig||(window.RTE_DefaultConfig={}),RTE_DefaultConfig.plugin_charlimit=RTE_Plugin_CharLimit;function RTE_Plugin_CharLimit(){var v=this,l,r,u=null;v.PluginName="CharLimit",v.InitConfig=function(t){l=t},v.InitEditor=function(t){if(r=t,r.getCharCount=function(){return c()},r.getWordCount=function(){return m()},r.getRemainingChars=function(){return a()?Math.max(0,a()-c()):null},r.isOverLimit=function(){return a()&&c()>a()||f()&&m()>f()},!(!a()&&!f())){if(l.charLimitEnforce!==!1&&typeof r.insertHTML=="function"){var e=r.insertHTML;r.insertHTML=function(n){if(!a())return e.apply(this,arguments);var i=document.createElement("div");i.innerHTML=String(n??"");var o=(i.textContent||"").length,s=a()-c()+g();return o<=s?e.apply(this,arguments):(d(),s<=0?!1:e.call(this,x((i.textContent||"").slice(0,s))))}}p();try{r.attachEvent("created",p)}catch{}try{r.attachEvent("ready",p)}catch{}try{r.attachEvent("aftersethtml",function(){p(),h()})}catch{}typeof setTimeout=="function"&&(setTimeout(p,0),setTimeout(p,300))}};function p(){var t=r.getDocument&&r.getDocument();if(!t||t.__rteCharLimitBound){C(),h();return}t.__rteCharLimitBound=!0,l.charLimitEnforce!==!1&&(t.addEventListener("beforeinput",L,!0),t.addEventListener("paste",E,!0),t.addEventListener("drop",D,!0)),t.addEventListener("input",function(){h()},!0),C(),h()}function a(){var t=parseInt(l.maxLength,10);return t>0?t:0}function f(){var t=parseInt(l.maxWords,10);return t>0?t:0}function y(){try{if(typeof r.getText=="function"){var t=r.getText();if(typeof t=="string")return t}var e=r.getEditable();return e&&(e.innerText||e.textContent)||""}catch{return""}}function c(){return y().replace(/\r\n/g,`
|
|
2
|
+
`).length}function m(){for(var t=y(),e=/[\u3005\u3007\u3040-\u30ff\u3400-\u4dbf\u4e00-\u9fff\uf900-\ufaff]/g,n=t.match(e),i=n?n.length:0,o=t.replace(e," ").split(/\s+/),s=0;s<o.length;s++)/[^!-\/:-@\[-`{-~\xa1-\xbf\u2000-\u206f\u3000-\u303f\uff01-\uff0f]/.test(o[s])&&i++;return i}function L(t){var e=t.inputType||"",n=e==="insertText"||e==="insertReplacementText"||e==="insertCompositionText"||e==="insertParagraph"||e==="insertLineBreak";if(n){var i=e==="insertParagraph"||e==="insertLineBreak"?1:(t.data||"").length||0;if(a()){var o=c();if((o>=a()||o+i>a())&&(!T()||o+i>a()+g())){t.preventDefault(),d();return}}if(f()&&e!=="insertParagraph"&&m()>=f()&&/\s$/.test(t.data||" ")&&m()>=f()){t.preventDefault(),d();return}}}function E(t){if(a()){var e=a()-c()+g();if(e<=0){t.preventDefault(),t.stopImmediatePropagation(),d();return}var n=t.clipboardData||window.clipboardData;if(n){var i="";try{i=n.getData("text/plain")||""}catch{return}if(i.length>e){t.preventDefault(),t.stopImmediatePropagation();var o=i.slice(0,e);try{typeof r.insertHTML=="function"&&r.insertHTML(x(o).replace(/\n/g,"<br>"))}catch{}d()}}}}function D(t){if(a()){var e=t.dataTransfer;if(e){var n=0;try{var i=e.getData("text/plain");if(!i){var o=document.createElement("div");o.innerHTML=e.getData("text/html")||"",i=o.textContent||""}n=i.length}catch{return}n&&c()+n>a()&&(t.preventDefault(),t.stopImmediatePropagation(),d())}}}function T(){try{var t=r.getSelection();return t&&t.rangeCount>0&&!t.isCollapsed}catch{return!1}}function g(){try{var t=r.getSelection();return t&&!t.isCollapsed?(t.toString()||"").length:0}catch{return 0}}function x(t){return String(t).replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">")}function C(){if(l.charLimitShowCounter!==!1&&!(u&&u.parentNode)){var t=b();t&&(S(t.ownerDocument),u=t.ownerDocument.createElement("div"),u.className="rte-charlimit-counter",u.setAttribute("aria-live","polite"),t.appendChild(u))}}function b(){try{var t=r.iframe||r.getDocument&&r.getDocument().defaultView&&r.getDocument().defaultView.frameElement;if(t){for(var e=t.parentNode;e&&e.nodeType===1;){var n=(e.ownerDocument.defaultView||window).getComputedStyle(e);if(n&&n.position!=="static")return e;if(e.className&&typeof e.className=="string"&&/rte[_-](outer|container|wrapper)/i.test(e.className)){try{n&&n.position==="static"&&(e.style.position="relative")}catch{}return e}e=e.parentNode}if(t.parentNode){try{t.parentNode.style.position=t.parentNode.style.position||"relative"}catch{}return t.parentNode}}return null}catch{return null}}function S(t){if(!t.querySelector("style[data-rte-charlimit]")){var e=t.createElement("style");e.setAttribute("data-rte-charlimit","1"),e.textContent=".rte-charlimit-counter{position:absolute;right:10px;bottom:6px;z-index:5;font:11px -apple-system,Segoe UI,sans-serif;color:#64748b;background:rgba(255,255,255,.85);padding:1px 7px;border-radius:9px;pointer-events:none}.rte-charlimit-counter.is-near{color:#b45309}.rte-charlimit-counter.is-over{color:#dc2626;font-weight:600}",(t.head||t.documentElement).appendChild(e),r&&typeof r.ensureStyleSheetLive=="function"&&r.ensureStyleSheetLive(t,e,"rte-charlimit-st",e.textContent)}}function h(){var t=c(),e=m(),n=a()?Math.max(0,t-a()):0,i=f()?Math.max(0,e-f()):0;if(u){var o="";a()?o=t+" / "+a():f()&&(o=e+" / "+f()+" words"),u.textContent=o,u.classList.remove("is-near","is-over"),a()&&t>a()||f()&&e>f()?u.classList.add("is-over"):(a()&&t>=a()*.9||f()&&e>=f()*.9)&&u.classList.add("is-near")}try{typeof r.fireEvent=="function"&&r.fireEvent("charlimit",{chars:t,words:e,overChars:n,overWords:i})}catch{}}function d(){if(u){u.classList.add("is-over");try{u.animate([{transform:"translateX(0)"},{transform:"translateX(-3px)"},{transform:"translateX(3px)"},{transform:"translateX(0)"}],{duration:160})}catch{}}}}
|