@editora/plugins 1.0.12 → 1.0.13
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/approval-workflow.cjs.js +14 -14
- package/dist/approval-workflow.esm.js +265 -262
- package/dist/blockquote.cjs.js +1 -1
- package/dist/blockquote.esm.js +177 -15
- package/dist/blocks-library.cjs.js +6 -6
- package/dist/blocks-library.esm.js +95 -92
- package/dist/bold.cjs.js +1 -1
- package/dist/bold.esm.js +10 -6
- package/dist/capitalization.cjs.js +1 -1
- package/dist/capitalization.esm.js +124 -44
- package/dist/checklist.cjs.js +1 -1
- package/dist/checklist.esm.js +251 -191
- package/dist/citations.cjs.js +4 -4
- package/dist/citations.esm.js +131 -128
- package/dist/clear-formatting.cjs.js +1 -1
- package/dist/clear-formatting.esm.js +68 -36
- package/dist/content-rules.cjs.js +5 -5
- package/dist/content-rules.esm.js +104 -101
- package/dist/data-binding.cjs.js +3 -3
- package/dist/data-binding.esm.js +51 -48
- package/dist/direction.cjs.js +1 -1
- package/dist/direction.esm.js +97 -74
- package/dist/doc-schema.cjs.js +4 -4
- package/dist/doc-schema.esm.js +104 -101
- package/dist/embed-iframe.cjs.js +21 -4
- package/dist/embed-iframe.esm.js +279 -116
- package/dist/heading.cjs.js +1 -1
- package/dist/heading.esm.js +239 -56
- package/dist/history.cjs.js +1 -1
- package/dist/history.esm.js +74 -89
- package/dist/inlineFormatting-DOYOJdnD.js +1 -0
- package/dist/inlineFormatting-DuVTGXYG.mjs +95 -0
- package/dist/italic.cjs.js +1 -1
- package/dist/italic.esm.js +12 -8
- package/dist/math.cjs.js +27 -21
- package/dist/math.esm.js +218 -146
- package/dist/merge-tag.cjs.js +8 -2
- package/dist/merge-tag.esm.js +130 -111
- package/dist/pii-redaction.cjs.js +6 -6
- package/dist/pii-redaction.esm.js +169 -166
- package/dist/smart-paste.cjs.js +5 -5
- package/dist/smart-paste.esm.js +120 -117
- package/dist/special-characters.cjs.js +6 -10
- package/dist/special-characters.esm.js +97 -75
- package/dist/strikethrough.cjs.js +1 -1
- package/dist/strikethrough.esm.js +11 -25
- package/dist/translation-workflow.cjs.js +7 -7
- package/dist/translation-workflow.esm.js +103 -100
- package/dist/underline.cjs.js +1 -1
- package/dist/underline.esm.js +7 -3
- package/package.json +3 -3
|
@@ -1,17 +1,17 @@
|
|
|
1
|
-
"use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const S=".rte-content, .editora-content",ke="[data-editora-editor], .rte-editor, .editora-editor, editora-editor",Te="__editoraCommandEditorRoot",ve="rte-translation-workflow-styles",u="rte-translation-workflow-panel",y="translation-workflow",$="translationWorkflow",h=':is([data-theme="dark"], .dark, .editora-theme-dark, .rte-theme-dark)',$e=["p","h1","h2","h3","h4","h5","h6","li","td","th","blockquote","figcaption"].join(", "),Me=new Set(["ArrowUp","ArrowDown","Home","End"]),Ee=[{locale:"en",label:"English",minLengthRatio:.6,maxLengthRatio:1.4,requireDifferentFromSource:!1,preserveTokens:!0},{locale:"fr",label:"French",minLengthRatio:.75,maxLengthRatio:1.7,requireDifferentFromSource:!0,preserveTokens:!0},{locale:"de",label:"German",minLengthRatio:.8,maxLengthRatio:1.9,requireDifferentFromSource:!0,preserveTokens:!0},{locale:"es",label:"Spanish",minLengthRatio:.7,maxLengthRatio:1.7,requireDifferentFromSource:!0,preserveTokens:!0},{locale:"it",label:"Italian",minLengthRatio:.7,maxLengthRatio:1.7,requireDifferentFromSource:!0,preserveTokens:!0},{locale:"ja",label:"Japanese",minLengthRatio:.45,maxLengthRatio:1.2,requireDifferentFromSource:!0,preserveTokens:!0},{locale:"zh",label:"Chinese",minLengthRatio:.4,maxLengthRatio:1.2,requireDifferentFromSource:!0,preserveTokens:!0}],Ne={panelTitle:"Translation Workflow",panelAriaLabel:"Translation workflow panel",sourceLocaleLabel:"Source Locale",targetLocaleLabel:"Target Locale",validateText:"Validate Locale",captureSourceText:"Capture Source",lockSelectedText:"Lock Selected",unlockSelectedText:"Unlock Selected",lockSegmentAriaLabel:"Lock segment",unlockSegmentAriaLabel:"Unlock segment",realtimeOnText:"Realtime On",realtimeOffText:"Realtime Off",closeText:"Close",summaryPrefix:"Locale QA",noIssuesText:"No locale validation issues.",issuesLabel:"Locale issues",segmentsLabel:"Segments",sourcePreviewLabel:"Source",targetPreviewLabel:"Target",helperText:"Select segments, lock finalized ones, and run locale validation before handoff.",shortcutText:"Shortcuts: Ctrl/Cmd+Alt+Shift+L (panel), Ctrl/Cmd+Alt+Shift+V (validate), Ctrl/Cmd+Alt+Shift+K (lock segment)",readonlySegmentMessage:"This segment is locked. Unlock before editing.",sourceCapturedMessage:"Source snapshot captured from current content.",selectedSegmentPrefix:"Selected Segment",missingTargetMessage:"Segment is empty in target locale.",tokenMismatchMessage:"Tokens/placeholders do not match source segment.",untranslatedMessage:"Segment appears untranslated (same as source).",lengthOutOfRangeMessage:"Translation length is outside expected locale range."},c=new WeakMap,re=new WeakMap,P=new WeakMap,p=new Map,j=new WeakMap,le=new WeakMap,U=new Set;let X=0,_e=0,Ae=0,Fe=0,k=null,x=null,D=null,z=null,O=null,N=null,I=null,_=null;function m(e){return e.replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">").replace(/"/g,""").replace(/'/g,"'")}function We(e){return e.replace(/\u00A0/g," ").replace(/\s+/g," ").trim()}function C(e,t,r){return Number.isFinite(e)?Math.max(t,Math.min(r,e)):t}function A(e){return(e||"").trim()||"en-US"}function W(e){return e.trim().toLowerCase()}function Ke(e){return e.replace(/"/g,""")}function Ve(e,t=120){return e.length<=t?e:`${e.slice(0,Math.max(0,t-1)).trimEnd()}…`}function Re(e){const t=e.match(/\{\{[^{}]+\}\}|%[A-Z0-9_]+%|\$\{[^{}]+\}/gi);return!t||t.length===0?[]:t.map(r=>r.trim()).filter(Boolean)}function je(e,t){const r=Re(e).sort(),n=Re(t).sort();if(r.length!==n.length)return!1;for(let a=0;a<r.length;a+=1)if(r[a]!==n[a])return!1;return!0}function Ue(e,t){const r=Array.isArray(t)&&t.length>0?t:Ee,n=[],a=new Set;return r.forEach(o=>{const l=W(o.locale||"");if(!l)return;const s=l;a.has(s)||(a.add(s),n.push({locale:s,label:(o.label||l).trim()||l,minLengthRatio:C(Number(o.minLengthRatio??.5),.1,3),maxLengthRatio:C(Number(o.maxLengthRatio??1.8),.2,4),requireDifferentFromSource:o.requireDifferentFromSource!==!1,preserveTokens:o.preserveTokens!==!1}))}),e.forEach(o=>{const l=W(o);if(a.has(l))return;const s=Ee.find(i=>l.startsWith(i.locale));n.push(s?{...s,locale:l,label:o}:{locale:l,label:o,minLengthRatio:.5,maxLengthRatio:1.8,requireDifferentFromSource:!0,preserveTokens:!0})}),n}function oe(e={}){const t=e.normalizeText||We,r=A(e.sourceLocale||"en-US"),n=A(e.targetLocale||"fr-FR"),a=new Set([r,n]);(Array.isArray(e.locales)?e.locales:[]).forEach(s=>{if(typeof s!="string")return;const i=A(s);a.add(i)});const o=Array.from(a),l=Ue(o,e.localeRules);return{sourceLocale:r,targetLocale:n,locales:o,localeRules:l,enableRealtime:e.enableRealtime!==!1,debounceMs:C(Number(e.debounceMs??260),60,2e3),maxIssues:C(Number(e.maxIssues??120),5,1e3),maxSegments:C(Number(e.maxSegments??600),20,3e3),minSourceLengthForRatio:C(Number(e.minSourceLengthForRatio??8),2,100),segmentSelector:(e.segmentSelector||$e).trim()||$e,labels:{...Ne,...e.labels||{}},normalizeText:t}}function Ge(e){return{sourceLocale:e.sourceLocale,targetLocale:e.targetLocale,locales:[...e.locales],localeRules:e.localeRules.map(t=>({locale:t.locale,label:t.label,minLengthRatio:t.minLengthRatio,maxLengthRatio:t.maxLengthRatio,requireDifferentFromSource:t.requireDifferentFromSource,preserveTokens:t.preserveTokens})),enableRealtime:e.enableRealtime,debounceMs:e.debounceMs,maxIssues:e.maxIssues,maxSegments:e.maxSegments,minSourceLengthForRatio:e.minSourceLengthForRatio,segmentSelector:e.segmentSelector,labels:{...e.labels},normalizeText:e.normalizeText}}function xe(e){return e.closest(ke)||e}function K(e){if(!e)return null;if(e.matches(S))return e;const t=e.querySelector(S);return t instanceof HTMLElement?t:null}function Ye(){if(typeof window>"u")return null;const e=window[Te];if(!(e instanceof HTMLElement))return null;window[Te]=null;const t=K(e);if(t)return t;const r=e.closest(ke);if(r){const a=K(r);if(a)return a}const n=e.closest(S);return n instanceof HTMLElement?n:null}function Ze(e){const t=e.closest("[data-editora-editor]");if(t&&K(t)===e)return t;let r=e;for(;r;){if(r.matches(ke)&&(r===e||K(r)===e))return r;r=r.parentElement}return xe(e)}function Ce(e){return e?e.nodeType===Node.ELEMENT_NODE?e:e.parentElement:null}function ee(e){return e?(e.getAttribute("data-theme")||e.getAttribute("theme")||"").toLowerCase()==="dark"?!0:e.classList.contains("dark")||e.classList.contains("editora-theme-dark")||e.classList.contains("rte-theme-dark"):!1}function Je(e){const t=xe(e);if(ee(t))return!0;const r=t.closest("[data-theme], [theme], .dark, .editora-theme-dark, .rte-theme-dark");return ee(r)?!0:ee(document.documentElement)||ee(document.body)}function ge(e,t){e.classList.remove("rte-translation-workflow-theme-dark"),Je(t)&&e.classList.add("rte-translation-workflow-theme-dark")}function Qe(e){for(let t=0;t<e.length;t+=1){const r=e[t];if(!(r.type!=="childList"||r.removedNodes.length===0))for(let n=0;n<r.removedNodes.length;n+=1){const a=r.removedNodes[n];if(a.nodeType!==Node.ELEMENT_NODE)continue;const o=a;if(o.matches?.(S)||o.matches?.(`.${u}`)||o.querySelector?.(S)||o.querySelector?.(`.${u}`))return!0}}return!1}function ae(){Array.from(U).forEach(t=>{t.isConnected||Se(t)})}function T(e,t=!0,r=!0){if(ae(),e?.contentElement instanceof HTMLElement)return e.contentElement;if(e?.editorElement instanceof HTMLElement){const s=K(e.editorElement);if(s)return s}const n=Ye();if(n)return n;const a=window.getSelection();if(a&&a.rangeCount>0){const s=Ce(a.getRangeAt(0).startContainer)?.closest(S);if(s)return s}const o=document.activeElement;if(o){if(o.matches(S))return o;const s=o.closest(S);if(s)return s}if(r&&x&&x.isConnected)return x;if(!t)return null;const l=document.querySelector(S);return l instanceof HTMLElement?l:null}function Xe(e){const t=e.target;if(t){const n=t.closest(`.${u}`);if(n){const o=Array.from(p.entries()).find(([,l])=>l===n);if(o)return o[0]}const a=t.closest(S);if(a)return a}const r=document.activeElement;if(r){const n=r.closest(`.${u}`);if(n){const o=Array.from(p.entries()).find(([,l])=>l===n);if(o)return o[0]}const a=r.closest(S);if(a)return a}return null}function fe(e,t,r){const n=Ze(e);Array.from(n.querySelectorAll(`.rte-toolbar-button[data-command="${t}"], .editora-toolbar-button[data-command="${t}"]`)).forEach(o=>{o.classList.toggle("active",r),o.setAttribute("data-active",r?"true":"false"),o.setAttribute("aria-pressed",r?"true":"false")})}function we(e){const t=le.get(e);typeof t=="number"&&(window.clearTimeout(t),le.delete(e))}function et(e,t){const r=W(t),n=e.localeRules.find(l=>W(l.locale)===r);if(n)return n;const a=r.split("-")[0],o=e.localeRules.find(l=>W(l.locale).split("-")[0]===a);return o||{locale:r,label:t,minLengthRatio:.5,maxLengthRatio:1.8,requireDifferentFromSource:!0,preserveTokens:!0}}function te(e,t,r,n={}){return Ae+=1,{id:`translation-workflow-issue-${Ae}`,type:e,severity:t,message:r,...n}}function ie(e,t){if(t){e.hasAttribute("data-translation-prev-contenteditable")||e.setAttribute("data-translation-prev-contenteditable",e.hasAttribute("contenteditable")&&e.getAttribute("contenteditable")||"inherit"),e.setAttribute("data-translation-locked","true"),e.setAttribute("contenteditable","false"),e.setAttribute("aria-readonly","true"),e.classList.add("rte-translation-segment-locked");return}if(e.removeAttribute("data-translation-locked"),e.removeAttribute("aria-readonly"),e.classList.remove("rte-translation-segment-locked"),e.hasAttribute("data-translation-prev-contenteditable")){const r=e.getAttribute("data-translation-prev-contenteditable")||"";r==="inherit"?e.setAttribute("contenteditable","true"):e.setAttribute("contenteditable",r),e.removeAttribute("data-translation-prev-contenteditable")}else e.setAttribute("contenteditable","true")}function ce(e,t){return e.querySelector(`[data-translation-segment-id="${Ke(t)}"]`)}function He(e){const t=window.getSelection();if(!t||t.rangeCount===0)return null;const r=Ce(t.getRangeAt(0).startContainer);return!r||!e.contains(r)?null:r.closest("[data-translation-segment-id]")}function tt(e,t){const r=Array.from(e.querySelectorAll(t));if(r.length<=1)return r;const n=new Set(r);return r.filter(a=>{let o=a.parentElement;for(;o&&o!==e;){if(n.has(o))return!1;o=o.parentElement}return!0})}function nt(e,t,r){let n=(r||"").trim();if(!n||t.has(n)){do n=`translation-segment-${_e++}`;while(t.has(n));e.setAttribute("data-translation-segment-id",n)}return n}function me(e,t){if(t.lockedSegmentIds.size===0)return!1;let r=!1;return t.lockedSegmentIds.forEach(n=>{const a=ce(e,n);if(!a)return;ie(a,!0);const o=t.lockedHtmlBySegmentId.get(n);if(typeof o=="string"){a.innerHTML!==o&&(a.innerHTML=o,r=!0);return}t.lockedHtmlBySegmentId.set(n,a.innerHTML)}),r}function M(e,t,r){const n=tt(e,t.segmentSelector),a=[],o=new Set;for(let l=0;l<n.length&&!(a.length>=t.maxSegments);l+=1){const s=n[l],i=nt(s,o,s.getAttribute("data-translation-segment-id")),d=r.lockedSegmentIds.has(i),g=s.getAttribute("data-translation-locked")==="true",w=d||g;if(w)if(r.lockedSegmentIds.add(i),ie(s,!0),!r.lockedHtmlBySegmentId.has(i))r.lockedHtmlBySegmentId.set(i,s.innerHTML);else{const q=r.lockedHtmlBySegmentId.get(i)||"";s.innerHTML!==q&&(s.innerHTML=q)}else r.lockedHtmlBySegmentId.delete(i);const v=t.normalizeText(s.textContent||"");if(!v)continue;r.sourceTextBySegmentId.has(i)||r.sourceTextBySegmentId.set(i,v);const G=r.sourceTextBySegmentId.get(i)||v;a.push({id:i,tagName:s.tagName.toLowerCase(),index:a.length,text:v,sourceText:G,locked:w}),o.add(i)}return Array.from(r.sourceTextBySegmentId.keys()).forEach(l=>{o.has(l)||r.sourceTextBySegmentId.delete(l)}),Array.from(r.lockedSegmentIds.keys()).forEach(l=>{o.has(l)||r.lockedSegmentIds.delete(l)}),Array.from(r.lockedHtmlBySegmentId.keys()).forEach(l=>{(!o.has(l)||!r.lockedSegmentIds.has(l))&&r.lockedHtmlBySegmentId.delete(l)}),(!r.selectedSegmentId||!a.some(l=>l.id===r.selectedSegmentId))&&(r.selectedSegmentId=a[0]?.id||null),a}function b(e,t){c.has(e)||c.set(e,t);let r=P.get(e);return r||(r={sourceLocale:t.sourceLocale,targetLocale:t.targetLocale,selectedSegmentId:null,realtimeEnabled:t.enableRealtime,segments:[],issues:[],sourceTextBySegmentId:new Map,lockedSegmentIds:new Set,lockedHtmlBySegmentId:new Map,snapshot:"",lastRunAt:null},P.set(e,r)),U.add(e),r}function Se(e){we(e);const t=p.get(e);t&&t.remove(),p.delete(e),j.delete(e);const r=P.get(e);r&&(r.lockedSegmentIds.forEach(n=>{const a=ce(e,n);a&&ie(a,!1)}),r.lockedHtmlBySegmentId.clear()),c.delete(e),re.delete(e),P.delete(e),U.delete(e),x===e&&(x=null)}function ye(e){return j.get(e)===!0}function be(e,t){if(!t.classList.contains("show"))return;const r=xe(e).getBoundingClientRect(),n=Math.min(window.innerWidth-20,520),a=Math.max(10,window.innerWidth-n-10),o=Math.min(Math.max(10,r.right-n),a),l=Math.max(10,Math.min(window.innerHeight-10,r.top+12));t.style.width=`${n}px`,t.style.left=`${o}px`,t.style.top=`${l}px`,t.style.maxHeight=`${Math.max(260,window.innerHeight-20)}px`}function H(e,t){const r=e.querySelector(".rte-translation-live");r&&(r.textContent=t)}function rt(e,t){return`${e.innerHTML}::${t.sourceLocale}::${t.targetLocale}::${Array.from(t.lockedSegmentIds).sort().join("|")}`}function ot(e,t,r){const n=[],a=et(r,t.targetLocale);for(let o=0;o<e.length&&!(n.length>=r.maxIssues);o+=1){const l=e[o],s=r.normalizeText(l.sourceText||""),i=r.normalizeText(l.text||"");if(!i){n.push(te("missing-target","error",r.labels.missingTargetMessage,{segmentId:l.id,sourceText:s,targetText:i,suggestion:"Provide translated content for this segment before export."}));continue}if(a.preserveTokens&&s&&!je(s,i)&&(n.push(te("token-mismatch","error",r.labels.tokenMismatchMessage,{segmentId:l.id,sourceText:s,targetText:i,suggestion:"Preserve placeholders/tokens exactly (for example {{name}}, %ID%, ${value})."})),n.length>=r.maxIssues)||a.requireDifferentFromSource&&s&&r.normalizeText(s)===r.normalizeText(i)&&(n.push(te("untranslated","warning",r.labels.untranslatedMessage,{segmentId:l.id,sourceText:s,targetText:i,suggestion:"Translate the segment or mark it intentionally unchanged."})),n.length>=r.maxIssues))break;if(s.length>=r.minSourceLengthForRatio){const d=i.length/Math.max(1,s.length);(d<a.minLengthRatio||d>a.maxLengthRatio)&&n.push(te("length-out-of-range","warning",r.labels.lengthOutOfRangeMessage,{segmentId:l.id,sourceText:s,targetText:i,suggestion:`Expected ratio for ${a.label}: ${a.minLengthRatio.toFixed(2)} - ${a.maxLengthRatio.toFixed(2)}.`}))}}return n}function Pe(e){const t=c.get(e)||k,r=P.get(e);return{sourceLocale:r?.sourceLocale||t?.sourceLocale||"en-US",targetLocale:r?.targetLocale||t?.targetLocale||"fr-FR",realtimeEnabled:r?.realtimeEnabled===!0,selectedSegmentId:r?.selectedSegmentId||null,segmentCount:r?.segments.length||0,lockedSegmentCount:r?r.segments.filter(n=>n.locked).length:0,issues:r?.issues?r.issues.map(n=>({...n})):[],segments:r?.segments.map(n=>({id:n.id,tagName:n.tagName,index:n.index,sourceLength:n.sourceText.length,targetLength:n.text.length,locked:n.locked}))||[],lastRunAt:r?.lastRunAt||null}}function E(e){const t=P.get(e),r=t&&t.selectedSegmentId?t.segments.find(n=>n.id===t.selectedSegmentId):null;fe(e,"toggleTranslationWorkflowPanel",ye(e)),fe(e,"toggleTranslationRealtime",t?.realtimeEnabled===!0),fe(e,"toggleTranslationSegmentLock",r?.locked===!0)}function at(e,t){const r=ce(e,t);if(!r)return;try{r.scrollIntoView({block:"nearest",inline:"nearest"})}catch{}const n=window.getSelection();if(!(!n||typeof document.createRange!="function"))try{const a=document.createRange();a.selectNodeContents(r),a.collapse(!0),n.removeAllRanges(),n.addRange(a),e.focus({preventScroll:!0})}catch{}}function R(e){const t=p.get(e);if(!t)return;const r=c.get(e)||k;if(!r)return;const n=b(e,r),a=t.querySelector(".rte-translation-source-label");a&&(a.textContent=r.labels.sourceLocaleLabel);const o=t.querySelector(".rte-translation-target-label");o&&(o.textContent=r.labels.targetLocaleLabel);const l=t.querySelector('[data-field="source-locale"]'),s=t.querySelector('[data-field="target-locale"]'),i=r.locales.map(f=>`<option value="${m(f)}">${m(f)}</option>`).join("");l&&(l.innerHTML=i,l.value=n.sourceLocale),s&&(s.innerHTML=i,s.value=n.targetLocale);const d=t.querySelector(".rte-translation-summary");if(d){const f=n.issues.length,B=n.selectedSegmentId?` • ${r.labels.selectedSegmentPrefix}: ${n.selectedSegmentId}`:"";d.textContent=`${r.labels.summaryPrefix}: ${n.sourceLocale} → ${n.targetLocale} • ${f} issue${f===1?"":"s"}${B}`}const g=t.querySelector(".rte-translation-helper");g&&(g.textContent=r.labels.helperText);const w=t.querySelector(".rte-translation-shortcut");w&&(w.textContent=r.labels.shortcutText);const v=t.querySelector('[data-action="run-validation"]');v&&(v.textContent=r.labels.validateText);const G=t.querySelector('[data-action="capture-source"]');G&&(G.textContent=r.labels.captureSourceText);const q=t.querySelector('[data-action="toggle-realtime"]');q&&(q.textContent=n.realtimeEnabled?r.labels.realtimeOnText:r.labels.realtimeOffText,q.setAttribute("aria-pressed",n.realtimeEnabled?"true":"false"));const Y=t.querySelector('[data-action="lock-selected"]'),ue=n.selectedSegmentId&&n.segments.find(f=>f.id===n.selectedSegmentId)||null;Y&&(Y.textContent=ue?.locked?r.labels.unlockSelectedText:r.labels.lockSelectedText,Y.disabled=!ue,Y.setAttribute("aria-pressed",ue?.locked?"true":"false"));const Le=t.querySelector('[data-action="close"]');Le&&Le.setAttribute("aria-label",r.labels.closeText);const Z=t.querySelector(".rte-translation-issues"),F=t.querySelector(".rte-translation-empty");Z&&(Z.setAttribute("aria-label",r.labels.issuesLabel),n.issues.length===0?(Z.innerHTML="",F&&(F.hidden=!1,F.textContent=r.labels.noIssuesText)):(F&&(F.hidden=!0),Z.innerHTML=n.issues.map(f=>`
|
|
1
|
+
"use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const S=".rte-content, .editora-content",ke="[data-editora-editor], .rte-editor, .editora-editor, editora-editor",ve="__editoraCommandEditorRoot",$e="rte-translation-workflow-styles",u="rte-translation-workflow-panel",y="translation-workflow",$="translationWorkflow",h=':is([data-theme="dark"], .dark, .editora-theme-dark, .rte-theme-dark)',Ee=["p","h1","h2","h3","h4","h5","h6","li","td","th","blockquote","figcaption"].join(", "),Ce=new Set(["ArrowUp","ArrowDown","Home","End"]),Ae=[{locale:"en",label:"English",minLengthRatio:.6,maxLengthRatio:1.4,requireDifferentFromSource:!1,preserveTokens:!0},{locale:"fr",label:"French",minLengthRatio:.75,maxLengthRatio:1.7,requireDifferentFromSource:!0,preserveTokens:!0},{locale:"de",label:"German",minLengthRatio:.8,maxLengthRatio:1.9,requireDifferentFromSource:!0,preserveTokens:!0},{locale:"es",label:"Spanish",minLengthRatio:.7,maxLengthRatio:1.7,requireDifferentFromSource:!0,preserveTokens:!0},{locale:"it",label:"Italian",minLengthRatio:.7,maxLengthRatio:1.7,requireDifferentFromSource:!0,preserveTokens:!0},{locale:"ja",label:"Japanese",minLengthRatio:.45,maxLengthRatio:1.2,requireDifferentFromSource:!0,preserveTokens:!0},{locale:"zh",label:"Chinese",minLengthRatio:.4,maxLengthRatio:1.2,requireDifferentFromSource:!0,preserveTokens:!0}],_e={panelTitle:"Translation Workflow",panelAriaLabel:"Translation workflow panel",sourceLocaleLabel:"Source Locale",targetLocaleLabel:"Target Locale",validateText:"Validate Locale",captureSourceText:"Capture Source",lockSelectedText:"Lock Selected",unlockSelectedText:"Unlock Selected",lockSegmentAriaLabel:"Lock segment",unlockSegmentAriaLabel:"Unlock segment",realtimeOnText:"Realtime On",realtimeOffText:"Realtime Off",closeText:"Close",summaryPrefix:"Locale QA",noIssuesText:"No locale validation issues.",issuesLabel:"Locale issues",segmentsLabel:"Segments",sourcePreviewLabel:"Source",targetPreviewLabel:"Target",helperText:"Select segments, lock finalized ones, and run locale validation before handoff.",shortcutText:"Shortcuts: Ctrl/Cmd+Alt+Shift+L (panel), Ctrl/Cmd+Alt+Shift+V (validate), Ctrl/Cmd+Alt+Shift+K (lock segment)",readonlySegmentMessage:"This segment is locked. Unlock before editing.",sourceCapturedMessage:"Source snapshot captured from current content.",selectedSegmentPrefix:"Selected Segment",missingTargetMessage:"Segment is empty in target locale.",tokenMismatchMessage:"Tokens/placeholders do not match source segment.",untranslatedMessage:"Segment appears untranslated (same as source).",lengthOutOfRangeMessage:"Translation length is outside expected locale range."},c=new WeakMap,re=new WeakMap,P=new WeakMap,p=new Map,j=new WeakMap,le=new WeakMap,U=new Set;let X=0,Fe=0,Re=0,We=0,k=null,x=null,D=null,z=null,O=null,N=null,I=null,_=null;function m(e){return e.replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">").replace(/"/g,""").replace(/'/g,"'")}function Ke(e){return e.replace(/\u00A0/g," ").replace(/\s+/g," ").trim()}function C(e,t,r){return Number.isFinite(e)?Math.max(t,Math.min(r,e)):t}function A(e){return(e||"").trim()||"en-US"}function W(e){return e.trim().toLowerCase()}function Ve(e){return e.replace(/"/g,""")}function je(e,t=120){return e.length<=t?e:`${e.slice(0,Math.max(0,t-1)).trimEnd()}…`}function Ie(e){const t=e.match(/\{\{[^{}]+\}\}|%[A-Z0-9_]+%|\$\{[^{}]+\}/gi);return!t||t.length===0?[]:t.map(r=>r.trim()).filter(Boolean)}function Ue(e,t){const r=Ie(e).sort(),n=Ie(t).sort();if(r.length!==n.length)return!1;for(let a=0;a<r.length;a+=1)if(r[a]!==n[a])return!1;return!0}function Ge(e,t){const r=Array.isArray(t)&&t.length>0?t:Ae,n=[],a=new Set;return r.forEach(o=>{const l=W(o.locale||"");if(!l)return;const s=l;a.has(s)||(a.add(s),n.push({locale:s,label:(o.label||l).trim()||l,minLengthRatio:C(Number(o.minLengthRatio??.5),.1,3),maxLengthRatio:C(Number(o.maxLengthRatio??1.8),.2,4),requireDifferentFromSource:o.requireDifferentFromSource!==!1,preserveTokens:o.preserveTokens!==!1}))}),e.forEach(o=>{const l=W(o);if(a.has(l))return;const s=Ae.find(i=>l.startsWith(i.locale));n.push(s?{...s,locale:l,label:o}:{locale:l,label:o,minLengthRatio:.5,maxLengthRatio:1.8,requireDifferentFromSource:!0,preserveTokens:!0})}),n}function oe(e={}){const t=e.normalizeText||Ke,r=A(e.sourceLocale||"en-US"),n=A(e.targetLocale||"fr-FR"),a=new Set([r,n]);(Array.isArray(e.locales)?e.locales:[]).forEach(s=>{if(typeof s!="string")return;const i=A(s);a.add(i)});const o=Array.from(a),l=Ge(o,e.localeRules);return{sourceLocale:r,targetLocale:n,locales:o,localeRules:l,enableRealtime:e.enableRealtime!==!1,debounceMs:C(Number(e.debounceMs??260),60,2e3),maxIssues:C(Number(e.maxIssues??120),5,1e3),maxSegments:C(Number(e.maxSegments??600),20,3e3),minSourceLengthForRatio:C(Number(e.minSourceLengthForRatio??8),2,100),segmentSelector:(e.segmentSelector||Ee).trim()||Ee,labels:{..._e,...e.labels||{}},normalizeText:t}}function Ye(e){return{sourceLocale:e.sourceLocale,targetLocale:e.targetLocale,locales:[...e.locales],localeRules:e.localeRules.map(t=>({locale:t.locale,label:t.label,minLengthRatio:t.minLengthRatio,maxLengthRatio:t.maxLengthRatio,requireDifferentFromSource:t.requireDifferentFromSource,preserveTokens:t.preserveTokens})),enableRealtime:e.enableRealtime,debounceMs:e.debounceMs,maxIssues:e.maxIssues,maxSegments:e.maxSegments,minSourceLengthForRatio:e.minSourceLengthForRatio,segmentSelector:e.segmentSelector,labels:{...e.labels},normalizeText:e.normalizeText}}function xe(e){return e.closest(ke)||e}function K(e){if(!e)return null;if(e.matches(S))return e;const t=e.querySelector(S);return t instanceof HTMLElement?t:null}function Ze(){if(typeof window>"u")return null;const e=window[ve];if(!(e instanceof HTMLElement))return null;window[ve]=null;const t=K(e);if(t)return t;const r=e.closest(ke);if(r){const a=K(r);if(a)return a}const n=e.closest(S);return n instanceof HTMLElement?n:null}function Je(e){const t=e.closest("[data-editora-editor]");if(t&&K(t)===e)return t;let r=e;for(;r;){if(r.matches(ke)&&(r===e||K(r)===e))return r;r=r.parentElement}return xe(e)}function He(e){return e?e.nodeType===Node.ELEMENT_NODE?e:e.parentElement:null}function ee(e){return e?(e.getAttribute("data-theme")||e.getAttribute("theme")||"").toLowerCase()==="dark"?!0:e.classList.contains("dark")||e.classList.contains("editora-theme-dark")||e.classList.contains("rte-theme-dark"):!1}function Qe(e){const t=xe(e);if(ee(t))return!0;const r=t.closest("[data-theme], [theme], .dark, .editora-theme-dark, .rte-theme-dark");return ee(r)?!0:ee(document.documentElement)||ee(document.body)}function ge(e,t){e.classList.remove("rte-translation-workflow-theme-dark"),Qe(t)&&e.classList.add("rte-translation-workflow-theme-dark")}function Xe(e){for(let t=0;t<e.length;t+=1){const r=e[t];if(!(r.type!=="childList"||r.removedNodes.length===0))for(let n=0;n<r.removedNodes.length;n+=1){const a=r.removedNodes[n];if(a.nodeType!==Node.ELEMENT_NODE)continue;const o=a;if(o.matches?.(S)||o.matches?.(`.${u}`)||o.querySelector?.(S)||o.querySelector?.(`.${u}`))return!0}}return!1}function ae(){Array.from(U).forEach(t=>{t.isConnected||Se(t)})}function T(e,t=!0,r=!0){if(ae(),e?.contentElement instanceof HTMLElement)return e.contentElement;if(e?.editorElement instanceof HTMLElement){const s=K(e.editorElement);if(s)return s}const n=Ze();if(n)return n;const a=window.getSelection();if(a&&a.rangeCount>0){const s=He(a.getRangeAt(0).startContainer)?.closest(S);if(s)return s}const o=document.activeElement;if(o){if(o.matches(S))return o;const s=o.closest(S);if(s)return s}if(r&&x&&x.isConnected)return x;if(!t)return null;const l=document.querySelector(S);return l instanceof HTMLElement?l:null}function et(e){const t=e.target;if(t){const n=t.closest(`.${u}`);if(n){const o=Array.from(p.entries()).find(([,l])=>l===n);if(o)return o[0]}const a=t.closest(S);if(a)return a}const r=document.activeElement;if(r){const n=r.closest(`.${u}`);if(n){const o=Array.from(p.entries()).find(([,l])=>l===n);if(o)return o[0]}const a=r.closest(S);if(a)return a}return null}function fe(e,t,r){const n=Je(e);Array.from(n.querySelectorAll(`.rte-toolbar-button[data-command="${t}"], .editora-toolbar-button[data-command="${t}"]`)).forEach(o=>{o.classList.toggle("active",r),o.setAttribute("data-active",r?"true":"false"),o.setAttribute("aria-pressed",r?"true":"false")})}function we(e){const t=le.get(e);typeof t=="number"&&(window.clearTimeout(t),le.delete(e))}function tt(e,t){const r=W(t),n=e.localeRules.find(l=>W(l.locale)===r);if(n)return n;const a=r.split("-")[0],o=e.localeRules.find(l=>W(l.locale).split("-")[0]===a);return o||{locale:r,label:t,minLengthRatio:.5,maxLengthRatio:1.8,requireDifferentFromSource:!0,preserveTokens:!0}}function te(e,t,r,n={}){return Re+=1,{id:`translation-workflow-issue-${Re}`,type:e,severity:t,message:r,...n}}function ie(e,t){if(t){e.hasAttribute("data-translation-prev-contenteditable")||e.setAttribute("data-translation-prev-contenteditable",e.hasAttribute("contenteditable")&&e.getAttribute("contenteditable")||"inherit"),e.setAttribute("data-translation-locked","true"),e.setAttribute("contenteditable","false"),e.setAttribute("aria-readonly","true"),e.classList.add("rte-translation-segment-locked");return}if(e.removeAttribute("data-translation-locked"),e.removeAttribute("aria-readonly"),e.classList.remove("rte-translation-segment-locked"),e.hasAttribute("data-translation-prev-contenteditable")){const r=e.getAttribute("data-translation-prev-contenteditable")||"";r==="inherit"?e.setAttribute("contenteditable","true"):e.setAttribute("contenteditable",r),e.removeAttribute("data-translation-prev-contenteditable")}else e.setAttribute("contenteditable","true")}function ce(e,t){return e.querySelector(`[data-translation-segment-id="${Ve(t)}"]`)}function Pe(e){const t=window.getSelection();if(!t||t.rangeCount===0)return null;const r=He(t.getRangeAt(0).startContainer);return!r||!e.contains(r)?null:r.closest("[data-translation-segment-id]")}function nt(e,t){const r=Array.from(e.querySelectorAll(t));if(r.length<=1)return r;const n=new Set(r);return r.filter(a=>{let o=a.parentElement;for(;o&&o!==e;){if(n.has(o))return!1;o=o.parentElement}return!0})}function rt(e,t,r){let n=(r||"").trim();if(!n||t.has(n)){do n=`translation-segment-${Fe++}`;while(t.has(n));e.setAttribute("data-translation-segment-id",n)}return n}function me(e,t){if(t.lockedSegmentIds.size===0)return!1;let r=!1;return t.lockedSegmentIds.forEach(n=>{const a=ce(e,n);if(!a)return;ie(a,!0);const o=t.lockedHtmlBySegmentId.get(n);if(typeof o=="string"){a.innerHTML!==o&&(a.innerHTML=o,r=!0);return}t.lockedHtmlBySegmentId.set(n,a.innerHTML)}),r}function M(e,t,r){const n=nt(e,t.segmentSelector),a=[],o=new Set;for(let l=0;l<n.length&&!(a.length>=t.maxSegments);l+=1){const s=n[l],i=rt(s,o,s.getAttribute("data-translation-segment-id")),d=r.lockedSegmentIds.has(i),g=s.getAttribute("data-translation-locked")==="true",w=d||g;if(w)if(r.lockedSegmentIds.add(i),ie(s,!0),!r.lockedHtmlBySegmentId.has(i))r.lockedHtmlBySegmentId.set(i,s.innerHTML);else{const q=r.lockedHtmlBySegmentId.get(i)||"";s.innerHTML!==q&&(s.innerHTML=q)}else r.lockedHtmlBySegmentId.delete(i);const v=t.normalizeText(s.textContent||"");if(!v)continue;r.sourceTextBySegmentId.has(i)||r.sourceTextBySegmentId.set(i,v);const G=r.sourceTextBySegmentId.get(i)||v;a.push({id:i,tagName:s.tagName.toLowerCase(),index:a.length,text:v,sourceText:G,locked:w}),o.add(i)}return Array.from(r.sourceTextBySegmentId.keys()).forEach(l=>{o.has(l)||r.sourceTextBySegmentId.delete(l)}),Array.from(r.lockedSegmentIds.keys()).forEach(l=>{o.has(l)||r.lockedSegmentIds.delete(l)}),Array.from(r.lockedHtmlBySegmentId.keys()).forEach(l=>{(!o.has(l)||!r.lockedSegmentIds.has(l))&&r.lockedHtmlBySegmentId.delete(l)}),(!r.selectedSegmentId||!a.some(l=>l.id===r.selectedSegmentId))&&(r.selectedSegmentId=a[0]?.id||null),a}function b(e,t){c.has(e)||c.set(e,t);let r=P.get(e);return r||(r={sourceLocale:t.sourceLocale,targetLocale:t.targetLocale,selectedSegmentId:null,realtimeEnabled:t.enableRealtime,segments:[],issues:[],sourceTextBySegmentId:new Map,lockedSegmentIds:new Set,lockedHtmlBySegmentId:new Map,snapshot:"",lastRunAt:null},P.set(e,r)),U.add(e),r}function Se(e){we(e);const t=p.get(e);t&&t.remove(),p.delete(e),j.delete(e);const r=P.get(e);r&&(r.lockedSegmentIds.forEach(n=>{const a=ce(e,n);a&&ie(a,!1)}),r.lockedHtmlBySegmentId.clear()),c.delete(e),re.delete(e),P.delete(e),U.delete(e),x===e&&(x=null)}function ye(e){return j.get(e)===!0}function be(e,t){if(!t.classList.contains("show"))return;const r=xe(e).getBoundingClientRect(),n=Math.min(window.innerWidth-20,520),a=Math.max(10,window.innerWidth-n-10),o=Math.min(Math.max(10,r.right-n),a),l=Math.max(10,Math.min(window.innerHeight-10,r.top+12));t.style.width=`${n}px`,t.style.left=`${o}px`,t.style.top=`${l}px`,t.style.maxHeight=`${Math.max(260,window.innerHeight-20)}px`}function H(e,t){const r=e.querySelector(".rte-translation-live");r&&(r.textContent=t)}function ot(e,t){return`${e.innerHTML}::${t.sourceLocale}::${t.targetLocale}::${Array.from(t.lockedSegmentIds).sort().join("|")}`}function at(e,t,r){const n=[],a=tt(r,t.targetLocale);for(let o=0;o<e.length&&!(n.length>=r.maxIssues);o+=1){const l=e[o],s=r.normalizeText(l.sourceText||""),i=r.normalizeText(l.text||"");if(!i){n.push(te("missing-target","error",r.labels.missingTargetMessage,{segmentId:l.id,sourceText:s,targetText:i,suggestion:"Provide translated content for this segment before export."}));continue}if(a.preserveTokens&&s&&!Ue(s,i)&&(n.push(te("token-mismatch","error",r.labels.tokenMismatchMessage,{segmentId:l.id,sourceText:s,targetText:i,suggestion:"Preserve placeholders/tokens exactly (for example {{name}}, %ID%, ${value})."})),n.length>=r.maxIssues)||a.requireDifferentFromSource&&s&&r.normalizeText(s)===r.normalizeText(i)&&(n.push(te("untranslated","warning",r.labels.untranslatedMessage,{segmentId:l.id,sourceText:s,targetText:i,suggestion:"Translate the segment or mark it intentionally unchanged."})),n.length>=r.maxIssues))break;if(s.length>=r.minSourceLengthForRatio){const d=i.length/Math.max(1,s.length);(d<a.minLengthRatio||d>a.maxLengthRatio)&&n.push(te("length-out-of-range","warning",r.labels.lengthOutOfRangeMessage,{segmentId:l.id,sourceText:s,targetText:i,suggestion:`Expected ratio for ${a.label}: ${a.minLengthRatio.toFixed(2)} - ${a.maxLengthRatio.toFixed(2)}.`}))}}return n}function qe(e){const t=c.get(e)||k,r=P.get(e);return{sourceLocale:r?.sourceLocale||t?.sourceLocale||"en-US",targetLocale:r?.targetLocale||t?.targetLocale||"fr-FR",realtimeEnabled:r?.realtimeEnabled===!0,selectedSegmentId:r?.selectedSegmentId||null,segmentCount:r?.segments.length||0,lockedSegmentCount:r?r.segments.filter(n=>n.locked).length:0,issues:r?.issues?r.issues.map(n=>({...n})):[],segments:r?.segments.map(n=>({id:n.id,tagName:n.tagName,index:n.index,sourceLength:n.sourceText.length,targetLength:n.text.length,locked:n.locked}))||[],lastRunAt:r?.lastRunAt||null}}function E(e){const t=P.get(e),r=t&&t.selectedSegmentId?t.segments.find(n=>n.id===t.selectedSegmentId):null;fe(e,"toggleTranslationWorkflowPanel",ye(e)),fe(e,"toggleTranslationRealtime",t?.realtimeEnabled===!0),fe(e,"toggleTranslationSegmentLock",r?.locked===!0)}function lt(e,t){const r=ce(e,t);if(!r)return;try{r.scrollIntoView({block:"nearest",inline:"nearest"})}catch{}const n=window.getSelection();if(!(!n||typeof document.createRange!="function"))try{const a=document.createRange();a.selectNodeContents(r),a.collapse(!0),n.removeAllRanges(),n.addRange(a),e.focus({preventScroll:!0})}catch{}}function R(e){const t=p.get(e);if(!t)return;const r=c.get(e)||k;if(!r)return;const n=b(e,r),a=t.querySelector(".rte-translation-source-label");a&&(a.textContent=r.labels.sourceLocaleLabel);const o=t.querySelector(".rte-translation-target-label");o&&(o.textContent=r.labels.targetLocaleLabel);const l=t.querySelector('[data-field="source-locale"]'),s=t.querySelector('[data-field="target-locale"]'),i=r.locales.map(f=>`<option value="${m(f)}">${m(f)}</option>`).join("");l&&(l.innerHTML=i,l.value=n.sourceLocale),s&&(s.innerHTML=i,s.value=n.targetLocale);const d=t.querySelector(".rte-translation-summary");if(d){const f=n.issues.length,B=n.selectedSegmentId?` • ${r.labels.selectedSegmentPrefix}: ${n.selectedSegmentId}`:"";d.textContent=`${r.labels.summaryPrefix}: ${n.sourceLocale} → ${n.targetLocale} • ${f} issue${f===1?"":"s"}${B}`}const g=t.querySelector(".rte-translation-helper");g&&(g.textContent=r.labels.helperText);const w=t.querySelector(".rte-translation-shortcut");w&&(w.textContent=r.labels.shortcutText);const v=t.querySelector('[data-action="run-validation"]');v&&(v.textContent=r.labels.validateText);const G=t.querySelector('[data-action="capture-source"]');G&&(G.textContent=r.labels.captureSourceText);const q=t.querySelector('[data-action="toggle-realtime"]');q&&(q.textContent=n.realtimeEnabled?r.labels.realtimeOnText:r.labels.realtimeOffText,q.setAttribute("aria-pressed",n.realtimeEnabled?"true":"false"));const Y=t.querySelector('[data-action="lock-selected"]'),ue=n.selectedSegmentId&&n.segments.find(f=>f.id===n.selectedSegmentId)||null;Y&&(Y.textContent=ue?.locked?r.labels.unlockSelectedText:r.labels.lockSelectedText,Y.disabled=!ue,Y.setAttribute("aria-pressed",ue?.locked?"true":"false"));const Te=t.querySelector('[data-action="close"]');Te&&Te.setAttribute("aria-label",r.labels.closeText);const Z=t.querySelector(".rte-translation-issues"),F=t.querySelector(".rte-translation-empty");Z&&(Z.setAttribute("aria-label",r.labels.issuesLabel),n.issues.length===0?(Z.innerHTML="",F&&(F.hidden=!1,F.textContent=r.labels.noIssuesText)):(F&&(F.hidden=!0),Z.innerHTML=n.issues.map(f=>`
|
|
2
2
|
<li class="rte-translation-issue ${f.severity==="error"?"error":f.severity==="warning"?"warning":"info"}" role="listitem" data-segment-id="${m(f.segmentId||"")}">
|
|
3
3
|
<p class="rte-translation-issue-message">${m(f.message)}</p>
|
|
4
4
|
${f.suggestion?`<p class="rte-translation-issue-suggestion">${m(f.suggestion)}</p>`:""}
|
|
5
5
|
</li>
|
|
6
|
-
`).join("")));const de=t.querySelector(".rte-translation-segments");de&&(de.setAttribute("aria-label",r.labels.segmentsLabel),de.innerHTML=n.segments.map(f=>{const B=f.id===n.selectedSegmentId?"selected":"",
|
|
7
|
-
<li class="rte-translation-segment-item ${B} ${
|
|
6
|
+
`).join("")));const de=t.querySelector(".rte-translation-segments");de&&(de.setAttribute("aria-label",r.labels.segmentsLabel),de.innerHTML=n.segments.map(f=>{const B=f.id===n.selectedSegmentId?"selected":"",Ne=f.locked?"locked":"";return`
|
|
7
|
+
<li class="rte-translation-segment-item ${B} ${Ne}" role="option" aria-selected="${f.id===n.selectedSegmentId?"true":"false"}" data-segment-id="${m(f.id)}">
|
|
8
8
|
<button type="button" class="rte-translation-segment-select" data-action="select-segment" data-segment-id="${m(f.id)}" title="${m(f.text)}">
|
|
9
9
|
<span class="rte-translation-segment-meta">#${f.index+1} • ${m(f.tagName)}</span>
|
|
10
|
-
<span class="rte-translation-segment-text">${m(
|
|
10
|
+
<span class="rte-translation-segment-text">${m(je(f.text,110))}</span>
|
|
11
11
|
</button>
|
|
12
12
|
<button type="button" class="rte-translation-segment-lock" data-action="toggle-lock" data-segment-id="${m(f.id)}" aria-label="${f.locked?r.labels.unlockSegmentAriaLabel:r.labels.lockSegmentAriaLabel}" aria-pressed="${f.locked?"true":"false"}"></button>
|
|
13
13
|
</li>
|
|
14
|
-
`}).join(""));const J=t.querySelector(".rte-translation-source-preview"),Q=t.querySelector(".rte-translation-target-preview");if(J||Q){const f=n.selectedSegmentId&&n.segments.find(B=>B.id===n.selectedSegmentId)||null;J&&(J.textContent=f?.sourceText||"—",J.setAttribute("aria-label",r.labels.sourcePreviewLabel)),Q&&(Q.textContent=f?.text||"—",Q.setAttribute("aria-label",r.labels.targetPreviewLabel))}t.setAttribute("aria-label",r.labels.panelAriaLabel)}function
|
|
14
|
+
`}).join(""));const J=t.querySelector(".rte-translation-source-preview"),Q=t.querySelector(".rte-translation-target-preview");if(J||Q){const f=n.selectedSegmentId&&n.segments.find(B=>B.id===n.selectedSegmentId)||null;J&&(J.textContent=f?.sourceText||"—",J.setAttribute("aria-label",r.labels.sourcePreviewLabel)),Q&&(Q.textContent=f?.text||"—",Q.setAttribute("aria-label",r.labels.targetPreviewLabel))}t.setAttribute("aria-label",r.labels.panelAriaLabel)}function Be(e){const t=c.get(e)||k;if(!t)return;we(e);const r=window.setTimeout(()=>{le.delete(e),L(e,"realtime",!1)},t.debounceMs);le.set(e,r)}function L(e,t,r){const n=c.get(e)||k;if(!n)return[];const a=b(e,n),o=me(e,a);a.segments=M(e,n,a);const l=ot(e,a);if(!r&&a.snapshot===l)return a.issues;a.issues=at(a.segments,a,n),a.lastRunAt=new Date().toISOString(),a.snapshot=l,R(e),E(e),e.dispatchEvent(new CustomEvent("editora:translation-workflow-validation",{bubbles:!0,detail:{reason:t,state:qe(e)}}));const s=p.get(e);if(s){if(o)return H(s,n.labels.readonlySegmentMessage),a.issues;H(s,a.issues.length===0?n.labels.noIssuesText:`${a.issues.length} issue${a.issues.length===1?"":"s"} detected.`)}return a.issues}function De(e){const t=c.get(e)||k;if(!t)return!1;const r=b(e,t),n=M(e,t,r);n.forEach(o=>{r.sourceTextBySegmentId.set(o.id,o.text)}),r.snapshot="",L(e,"capture-source",!0);const a=p.get(e);return a&&H(a,t.labels.sourceCapturedMessage),e.dispatchEvent(new CustomEvent("editora:translation-source-captured",{bubbles:!0,detail:{sourceLocale:r.sourceLocale,segmentCount:n.length}})),!0}function se(e,t,r){const n=c.get(e)||k;if(!n)return!1;const a=b(e,n);a.segments=M(e,n,a);const o=Pe(e)?.getAttribute("data-translation-segment-id")||null,l=t||o||a.selectedSegmentId||a.segments[0]?.id||null;if(!l)return!1;const s=ce(e,l);if(!s)return!1;const i=typeof r=="boolean"?r:!a.lockedSegmentIds.has(l);return i?(a.lockedSegmentIds.add(l),a.lockedHtmlBySegmentId.set(l,s.innerHTML)):(a.lockedSegmentIds.delete(l),a.lockedHtmlBySegmentId.delete(l)),ie(s,i),a.selectedSegmentId=l,a.snapshot="",L(e,"lock-segment",!0),e.dispatchEvent(new CustomEvent("editora:translation-segment-lock",{bubbles:!0,detail:{segmentId:l,locked:i}})),!0}function ze(e,t){const r=c.get(e)||k;if(!r)return!1;const n=b(e,r),a=typeof t=="boolean"?t:!n.realtimeEnabled;return n.realtimeEnabled=a,a?Be(e):we(e),R(e),E(e),!0}function pe(e,t,r=!0){const n=c.get(e)||k;if(!n)return!1;const a=b(e,n);return a.segments=M(e,n,a),a.segments.some(o=>o.id===t)?(a.selectedSegmentId=t,R(e),E(e),r&<(e,t),!0):!1}function ne(e,t){const r=c.get(e)||k;if(!r)return!1;const n=b(e,r);if(n.segments=M(e,r,n),n.segments.length===0)return!1;const a=Math.max(0,n.segments.findIndex(s=>s.id===n.selectedSegmentId));let o=a;t==="start"?o=0:t==="end"?o=n.segments.length-1:o=C(a+t,0,n.segments.length-1);const l=n.segments[o];return l?pe(e,l.id,!0):!1}function V(e,t=!1){const r=p.get(e);r&&(r.classList.remove("show"),j.set(e,!1),E(e),t&&e.focus({preventScroll:!0}))}function he(e){const t=dt(e);p.forEach((n,a)=>{a!==e&&V(a,!1)}),t.classList.add("show"),j.set(e,!0),L(e,"panel-open",!1),R(e),be(e,t),E(e),t.querySelector('[data-field="target-locale"]')?.focus()}function Oe(e,t){const r=ye(e);return(typeof t=="boolean"?t:!r)?he(e):V(e,!1),!0}function Le(e){return typeof e.key=="string"?e.key.toLowerCase():""}function st(e){const t=Le(e);return(e.metaKey||e.ctrlKey)&&e.altKey&&e.shiftKey&&t==="l"}function it(e){const t=Le(e);return(e.metaKey||e.ctrlKey)&&e.altKey&&e.shiftKey&&t==="v"}function ct(e){const t=Le(e);return(e.metaKey||e.ctrlKey)&&e.altKey&&e.shiftKey&&t==="k"}function ut(e){return e.key.length===1&&!e.metaKey&&!e.ctrlKey&&!e.altKey?!0:e.key==="Backspace"||e.key==="Delete"||e.key==="Enter"}function Me(e){return e instanceof HTMLElement?e.closest('[data-translation-locked="true"]'):null}function dt(e){const t=p.get(e);if(t)return t;const r=c.get(e)||k||oe();b(e,r);const n=`rte-translation-workflow-panel-${We++}`,a=`${n}-source`,o=`${n}-target`,l=document.createElement("section");return l.className=u,l.id=n,l.setAttribute("role","dialog"),l.setAttribute("aria-modal","false"),l.setAttribute("aria-label",r.labels.panelAriaLabel),l.innerHTML=`
|
|
15
15
|
<header class="rte-translation-header">
|
|
16
16
|
<h2 class="rte-translation-title">${m(r.labels.panelTitle)}</h2>
|
|
17
17
|
<button type="button" class="rte-translation-icon-btn" data-action="close" aria-label="${m(r.labels.closeText)}">✕</button>
|
|
@@ -60,7 +60,7 @@
|
|
|
60
60
|
</section>
|
|
61
61
|
</div>
|
|
62
62
|
<div class="rte-translation-live" aria-live="polite" aria-atomic="true"></div>
|
|
63
|
-
`,l.addEventListener("click",s=>{const i=s.target;if(!i)return;const d=i.closest("[data-action]");if(!d){const v=i.closest(".rte-translation-issue[data-segment-id]")?.getAttribute("data-segment-id")||"";v&&pe(e,v,!0);return}const g=d.getAttribute("data-action");if(g==="close"){V(e,!0);return}if(g==="run-validation"){L(e,"panel-button",!0);return}if(g==="capture-source"){
|
|
63
|
+
`,l.addEventListener("click",s=>{const i=s.target;if(!i)return;const d=i.closest("[data-action]");if(!d){const v=i.closest(".rte-translation-issue[data-segment-id]")?.getAttribute("data-segment-id")||"";v&&pe(e,v,!0);return}const g=d.getAttribute("data-action");if(g==="close"){V(e,!0);return}if(g==="run-validation"){L(e,"panel-button",!0);return}if(g==="capture-source"){De(e);return}if(g==="lock-selected"){se(e);return}if(g==="toggle-realtime"){ze(e);return}if(g==="select-segment"){const w=d.getAttribute("data-segment-id")||"";w&&pe(e,w,!0);return}if(g==="toggle-lock"){const w=d.getAttribute("data-segment-id")||"";w&&se(e,w)}}),l.addEventListener("change",s=>{const i=s.target;if(!(i instanceof HTMLSelectElement))return;const d=c.get(e)||k;if(!d)return;const g=b(e,d);if(i.getAttribute("data-field")==="source-locale"){g.sourceLocale=A(i.value),g.snapshot="",L(e,"source-locale-change",!0);return}i.getAttribute("data-field")==="target-locale"&&(g.targetLocale=A(i.value),g.snapshot="",L(e,"target-locale-change",!0))}),l.addEventListener("keydown",s=>{const i=s.target;if(s.key==="Escape"){s.preventDefault(),V(e,!0);return}!i?.closest(".rte-translation-segments")||!Ce.has(s.key)||(s.preventDefault(),s.key==="ArrowUp"?ne(e,-1):s.key==="ArrowDown"?ne(e,1):s.key==="Home"?ne(e,"start"):s.key==="End"&&ne(e,"end"))}),ge(l,e),document.body.appendChild(l),p.set(e,l),j.set(e,!1),R(e),l}function ft(e){k=e,D||(D=t=>{ae();const n=t.target?.closest(S);if(!n)return;const a=c.get(n)||e,o=b(n,a);c.set(n,a),x=n;const l=Pe(n)?.getAttribute("data-translation-segment-id")||null;l&&(o.selectedSegmentId=l),E(n);const s=p.get(n);s&&(ge(s,n),be(n,s),R(n))},document.addEventListener("focusin",D,!0)),z||(z=t=>{const n=t.target?.closest(S);if(!n)return;const a=c.get(n)||k;if(!a)return;const o=b(n,a),l=me(n,o);if(o.segments=M(n,a,o),!o.realtimeEnabled){if(l){const s=p.get(n);s&&H(s,a.labels.readonlySegmentMessage)}R(n),E(n);return}Be(n)},document.addEventListener("input",z,!0)),O||(O=t=>{const r=t,n=r.target,a=n?.closest(S);if(!a)return;const o=Me(n);if(!o||!a.contains(o))return;r.preventDefault();const l=p.get(a),s=c.get(a)||k;l&&s&&H(l,s.labels.readonlySegmentMessage)},document.addEventListener("beforeinput",O,!0)),N||(N=t=>{if(t.defaultPrevented)return;const r=t.target;if(r?.closest(`.${u}`)&&t.key!=="Escape"&&!Ce.has(t.key))return;const a=t.key==="Escape",o=st(t),l=it(t),s=ct(t),i=Me(r);if(!a&&!o&&!l&&!s&&!i)return;const d=et(t);if(!d)return;const g=c.get(d)||k||e;if(b(d,g),c.set(d,g),x=d,a&&ye(d)){t.preventDefault(),V(d,!0);return}if(i&&d.contains(i)&&ut(t)){t.preventDefault();const w=p.get(d);w&&H(w,g.labels.readonlySegmentMessage);return}if(o){t.preventDefault(),t.stopPropagation(),Oe(d);return}if(l){t.preventDefault(),t.stopPropagation(),L(d,"shortcut",!0);return}s&&(t.preventDefault(),t.stopPropagation(),se(d))},document.addEventListener("keydown",N,!0)),I||(I=()=>{ae(),p.forEach((t,r)=>{!r.isConnected||!t.isConnected||(ge(t,r),be(r,t))})},window.addEventListener("scroll",I,!0),window.addEventListener("resize",I)),!_&&typeof MutationObserver<"u"&&document.body&&(_=new MutationObserver(t=>{Xe(t)&&ae(),t.some(n=>n.type==="characterData"?!0:n.type==="childList"&&(n.addedNodes.length>0||n.removedNodes.length>0))&&U.forEach(n=>{const a=P.get(n);if(!a||a.lockedSegmentIds.size===0||!me(n,a))return;a.snapshot="";const l=c.get(n)||k,s=p.get(n);s&&l&&H(s,l.labels.readonlySegmentMessage),l&&(a.segments=M(n,l,a),R(n),E(n))})}),_.observe(document.body,{childList:!0,subtree:!0,characterData:!0}))}function gt(){D&&(document.removeEventListener("focusin",D,!0),D=null),z&&(document.removeEventListener("input",z,!0),z=null),O&&(document.removeEventListener("beforeinput",O,!0),O=null),N&&(document.removeEventListener("keydown",N,!0),N=null),I&&(window.removeEventListener("scroll",I,!0),window.removeEventListener("resize",I),I=null),_&&(_.disconnect(),_=null),p.forEach(t=>t.remove()),p.clear(),Array.from(U).forEach(t=>Se(t)),k=null,x=null}function mt(){if(typeof document>"u"||document.getElementById($e))return;const e=document.createElement("style");e.id=$e,e.textContent=`
|
|
64
64
|
.rte-toolbar-group-items.${y},
|
|
65
65
|
.editora-toolbar-group-items.${y},
|
|
66
66
|
.rte-toolbar-group-items.${$},
|
|
@@ -623,4 +623,4 @@
|
|
|
623
623
|
grid-template-columns: 1fr;
|
|
624
624
|
}
|
|
625
625
|
}
|
|
626
|
-
`,document.head.appendChild(e)}const
|
|
626
|
+
`,document.head.appendChild(e)}const bt=(e={})=>{const t=oe(e),r=new Set;return mt(),{name:"translationWorkflow",toolbar:[{id:"translationWorkflowGroup",label:"Translation Workflow",type:"group",command:"translationWorkflow",items:[{id:"toggleTranslationWorkflowPanel",label:"Translation Workflow",command:"toggleTranslationWorkflowPanel",shortcut:"Mod-Alt-Shift-l",icon:'<svg width="24" height="24" viewBox="0 0 24 24" fill="none" focusable="false" aria-hidden="true"><path d="M4 6.5a2 2 0 0 1 2-2h8a2 2 0 0 1 2 2v4a2 2 0 0 1-2 2H8l-4 3V6.5Z" stroke="currentColor" stroke-width="1.6"/><path d="M20 17.5a2 2 0 0 1-2 2h-8a2 2 0 0 1-2-2v-1.5" stroke="currentColor" stroke-width="1.6"/><path d="m13 8 2 2m0 0 2-2m-2 2V4" stroke="currentColor" stroke-width="1.6" stroke-linecap="round" stroke-linejoin="round"/></svg>'},{id:"runTranslationLocaleValidation",label:"Run Locale Validation",command:"runTranslationLocaleValidation",shortcut:"Mod-Alt-Shift-v",icon:'<svg width="24" height="24" viewBox="0 0 24 24" fill="none" focusable="false" aria-hidden="true"><rect x="4.5" y="4" width="12" height="16" rx="2" stroke="currentColor" stroke-width="1.6"/><path d="M8 8h5.5M8 11h4M8 14h3" stroke="currentColor" stroke-width="1.6" stroke-linecap="round"/><path d="m15.5 15.5 1.7 1.7 3.3-3.3" stroke="currentColor" stroke-width="1.6" stroke-linecap="round" stroke-linejoin="round"/></svg>'},{id:"toggleTranslationSegmentLock",label:"Toggle Segment Lock",command:"toggleTranslationSegmentLock",shortcut:"Mod-Alt-Shift-k",icon:'<svg width="24" height="24" viewBox="0 0 24 24" fill="none" focusable="false" aria-hidden="true"><rect x="5" y="10" width="14" height="10" rx="2" stroke="currentColor" stroke-width="1.6"/><path d="M8.5 10V7.5a3.5 3.5 0 1 1 7 0V10" stroke="currentColor" stroke-width="1.6"/><circle cx="12" cy="15" r="1.2" fill="currentColor"/></svg>'},{id:"toggleTranslationRealtime",label:"Toggle Translation Realtime",command:"toggleTranslationRealtime",icon:'<svg width="24" height="24" viewBox="0 0 24 24" fill="none" focusable="false" aria-hidden="true"><path d="M4.5 12a7.5 7.5 0 1 1 7.5 7.5" stroke="currentColor" stroke-width="1.6" stroke-linecap="round"/><path d="M9.5 19.5H5.5v-4" stroke="currentColor" stroke-width="1.6" stroke-linecap="round" stroke-linejoin="round"/><path d="M12 8v4l2.5 2" stroke="currentColor" stroke-width="1.6" stroke-linecap="round" stroke-linejoin="round"/></svg>'}]}],commands:{translationWorkflow:(n,a)=>{const o=T(a,!1,!1);if(!o)return!1;const l=c.get(o)||t;return b(o,l),c.set(o,l),x=o,he(o),!0},openTranslationWorkflowPanel:(n,a)=>{const o=T(a,!1,!1);if(!o)return!1;const l=c.get(o)||t;return b(o,l),c.set(o,l),x=o,he(o),!0},toggleTranslationWorkflowPanel:(n,a)=>{const o=T(a,!1,!1);if(!o)return!1;const l=c.get(o)||t;return b(o,l),c.set(o,l),x=o,Oe(o,typeof n=="boolean"?n:void 0)},runTranslationLocaleValidation:(n,a)=>{const o=T(a,!1,!1);if(!o)return!1;const l=c.get(o)||t;return b(o,l),c.set(o,l),x=o,L(o,"command",!0),!0},toggleTranslationRealtime:(n,a)=>{const o=T(a,!1,!1);if(!o)return!1;const l=c.get(o)||t;return b(o,l),c.set(o,l),x=o,ze(o,typeof n=="boolean"?n:void 0)},toggleTranslationSegmentLock:(n,a)=>{const o=T(a,!1,!1);if(!o)return!1;const l=c.get(o)||t;b(o,l),c.set(o,l),x=o;const s=typeof n=="boolean"?n:n?.locked,i=typeof n=="object"?n?.segmentId:void 0;return se(o,i,s)},setTranslationLocales:(n,a)=>{const o=T(a,!1,!1);if(!o||!n||typeof n!="object")return!1;const l=c.get(o)||t,s=b(o,l);return c.set(o,l),typeof n.sourceLocale=="string"&&n.sourceLocale.trim()&&(s.sourceLocale=A(n.sourceLocale)),typeof n.targetLocale=="string"&&n.targetLocale.trim()&&(s.targetLocale=A(n.targetLocale)),s.snapshot="",L(o,"set-locales",!0),!0},captureTranslationSourceSnapshot:(n,a)=>{const o=T(a,!1,!1);if(!o)return!1;const l=c.get(o)||t;return b(o,l),c.set(o,l),x=o,De(o)},setTranslationWorkflowOptions:(n,a)=>{const o=T(a,!1,!1);if(!o||!n||typeof n!="object")return!1;const l=c.get(o)||t,s=re.get(o)||Ye(l),i={...s,...n,labels:{...s.labels||{},...n.labels||{}},localeRules:Array.isArray(n.localeRules)?n.localeRules:s.localeRules,locales:Array.isArray(n.locales)?n.locales:s.locales,normalizeText:n.normalizeText||l.normalizeText},d=oe(i);c.set(o,d),re.set(o,i);const g=b(o,d);return typeof n.enableRealtime=="boolean"&&(g.realtimeEnabled=n.enableRealtime),typeof n.sourceLocale=="string"&&n.sourceLocale.trim()&&(g.sourceLocale=A(n.sourceLocale)),typeof n.targetLocale=="string"&&n.targetLocale.trim()&&(g.targetLocale=A(n.targetLocale)),g.snapshot="",L(o,"set-options",!0),R(o),E(o),!0},getTranslationWorkflowState:(n,a)=>{const o=T(a,!1,!1);if(!o)return!1;const l=c.get(o)||t;b(o,l);const s=qe(o);if(typeof n=="function")try{n(s)}catch{}return o.__translationWorkflowState=s,o.dispatchEvent(new CustomEvent("editora:translation-workflow-state",{bubbles:!0,detail:s})),!0}},keymap:{"Mod-Alt-Shift-l":"toggleTranslationWorkflowPanel","Mod-Alt-Shift-L":"toggleTranslationWorkflowPanel","Mod-Alt-Shift-v":"runTranslationLocaleValidation","Mod-Alt-Shift-V":"runTranslationLocaleValidation","Mod-Alt-Shift-k":"toggleTranslationSegmentLock","Mod-Alt-Shift-K":"toggleTranslationSegmentLock"},init:function(a){X+=1;const o=this&&typeof this.__pluginConfig=="object"?{...e,...this.__pluginConfig}:e,l=oe(o);ft(l);const s=T(a?.editorElement?{editorElement:a.editorElement}:void 0,!1,!1);if(!s)return;x=s,r.add(s);const i=b(s,l);c.set(s,l),re.set(s,o),i.segments=M(s,l,i),L(s,"init",!0),E(s)},destroy:()=>{r.forEach(n=>Se(n)),r.clear(),X=Math.max(0,X-1),!(X>0)&>()}}};exports.TranslationWorkflowPlugin=bt;
|