@pigment/auto-translate 1.6.0 → 1.6.1
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 +15 -8
- package/dist/collections/translationExclusions.js +101 -4
- package/dist/collections/translationExclusions.js.map +1 -1
- package/dist/components/LockTranslation/actions/lockTranslations.d.ts +1 -1
- package/dist/components/LockTranslation/actions/lockTranslations.js +2 -2
- package/dist/components/LockTranslation/actions/lockTranslations.js.map +1 -1
- package/dist/components/LockTranslation/index.js +6 -3
- package/dist/components/LockTranslation/index.js.map +1 -1
- package/dist/components/OpenAiModelField.js +7 -4
- package/dist/components/OpenAiModelField.js.map +1 -1
- package/dist/components/TranslationControl.js +45 -51
- package/dist/components/TranslationControl.js.map +1 -1
- package/dist/globals/translationSettings.js +10 -10
- package/dist/globals/translationSettings.js.map +1 -1
- package/dist/services/translationService.js +4 -7
- package/dist/services/translationService.js.map +1 -1
- package/dist/utilities/fieldHelpers.d.ts +0 -29
- package/dist/utilities/fieldHelpers.js +0 -152
- package/dist/utilities/fieldHelpers.js.map +1 -1
- package/dist/utilities/injectTranslationControls.d.ts +1 -1
- package/dist/utilities/injectTranslationControls.js +16 -11
- package/dist/utilities/injectTranslationControls.js.map +1 -1
- package/package.json +36 -65
- package/dist/components/TranslationSettingsLock.css +0 -87
- package/dist/components/TranslationSettingsLock.d.ts +0 -9
- package/dist/components/TranslationSettingsLock.js +0 -155
- package/dist/components/TranslationSettingsLock.js.map +0 -1
|
@@ -1,155 +0,0 @@
|
|
|
1
|
-
'use client';
|
|
2
|
-
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
|
-
import React, { useCallback, useEffect, useRef, useState } from 'react';
|
|
4
|
-
import './TranslationSettingsLock.css';
|
|
5
|
-
/**
|
|
6
|
-
* Component that provides lock/unlock functionality for translation settings
|
|
7
|
-
* - Fields are locked by default (read-only)
|
|
8
|
-
* - User must click "Unlock" to edit
|
|
9
|
-
* - After saving, fields automatically lock again
|
|
10
|
-
*/ export const TranslationSettingsLock = ()=>{
|
|
11
|
-
const [isLocked, setIsLocked] = useState(true);
|
|
12
|
-
const formRef = useRef(null);
|
|
13
|
-
const observerRef = useRef(null);
|
|
14
|
-
const debounceTimerRef = useRef(null);
|
|
15
|
-
// Find form element (memoized selector logic)
|
|
16
|
-
const findForm = useCallback(()=>{
|
|
17
|
-
if (formRef.current && document.contains(formRef.current)) {
|
|
18
|
-
return formRef.current;
|
|
19
|
-
}
|
|
20
|
-
const formElement = document.querySelector('form[id*="translation-settings"]') || document.querySelector('form[id*="Global"]') || document.querySelector('form.render-fields') || document.querySelector('form');
|
|
21
|
-
const form = formElement;
|
|
22
|
-
if (form) {
|
|
23
|
-
formRef.current = form;
|
|
24
|
-
}
|
|
25
|
-
return form;
|
|
26
|
-
}, []);
|
|
27
|
-
// Apply lock/unlock state to all form fields (optimized with caching)
|
|
28
|
-
const applyLockState = useCallback(()=>{
|
|
29
|
-
const form = findForm();
|
|
30
|
-
if (!form) {
|
|
31
|
-
return;
|
|
32
|
-
}
|
|
33
|
-
// Find all input fields - using more efficient selector
|
|
34
|
-
const inputs = form.querySelectorAll('input[type="text"], input[type="number"], textarea');
|
|
35
|
-
// Batch DOM updates for better performance
|
|
36
|
-
inputs.forEach((input)=>{
|
|
37
|
-
// Skip if this is the lock control itself
|
|
38
|
-
if (input.closest('.translation-settings-lock-container')) {
|
|
39
|
-
return;
|
|
40
|
-
}
|
|
41
|
-
// Use single operation to update multiple attributes
|
|
42
|
-
if (isLocked) {
|
|
43
|
-
input.setAttribute('readonly', 'true');
|
|
44
|
-
input.setAttribute('disabled', 'true');
|
|
45
|
-
input.classList.add('translation-settings-locked');
|
|
46
|
-
} else {
|
|
47
|
-
input.removeAttribute('readonly');
|
|
48
|
-
input.removeAttribute('disabled');
|
|
49
|
-
input.classList.remove('translation-settings-locked');
|
|
50
|
-
}
|
|
51
|
-
});
|
|
52
|
-
// Update the save button state
|
|
53
|
-
const saveButtonElement = document.querySelector('button#action-save');
|
|
54
|
-
const saveButton = saveButtonElement;
|
|
55
|
-
if (saveButton) {
|
|
56
|
-
if (isLocked) {
|
|
57
|
-
saveButton.setAttribute('disabled', 'true');
|
|
58
|
-
saveButton.classList.add('translation-settings-save-locked');
|
|
59
|
-
} else {
|
|
60
|
-
saveButton.removeAttribute('disabled');
|
|
61
|
-
saveButton.classList.remove('translation-settings-save-locked');
|
|
62
|
-
}
|
|
63
|
-
}
|
|
64
|
-
}, [
|
|
65
|
-
isLocked,
|
|
66
|
-
findForm
|
|
67
|
-
]);
|
|
68
|
-
// Debounced version of applyLockState for MutationObserver
|
|
69
|
-
const debouncedApplyLockState = useCallback(()=>{
|
|
70
|
-
if (debounceTimerRef.current) {
|
|
71
|
-
clearTimeout(debounceTimerRef.current);
|
|
72
|
-
}
|
|
73
|
-
debounceTimerRef.current = setTimeout(()=>{
|
|
74
|
-
applyLockState();
|
|
75
|
-
}, 100); // 100ms debounce
|
|
76
|
-
}, [
|
|
77
|
-
applyLockState
|
|
78
|
-
]);
|
|
79
|
-
// Setup MutationObserver for form changes
|
|
80
|
-
useEffect(()=>{
|
|
81
|
-
// Initial application
|
|
82
|
-
const initialTimeout = setTimeout(applyLockState, 100);
|
|
83
|
-
// Setup observer to watch for dynamic field additions
|
|
84
|
-
const form = findForm();
|
|
85
|
-
if (form) {
|
|
86
|
-
observerRef.current = new MutationObserver(debouncedApplyLockState);
|
|
87
|
-
// Only observe the form element, not the entire body (much more efficient)
|
|
88
|
-
observerRef.current.observe(form, {
|
|
89
|
-
attributes: false,
|
|
90
|
-
childList: true,
|
|
91
|
-
subtree: true
|
|
92
|
-
});
|
|
93
|
-
}
|
|
94
|
-
return ()=>{
|
|
95
|
-
clearTimeout(initialTimeout);
|
|
96
|
-
if (debounceTimerRef.current) {
|
|
97
|
-
clearTimeout(debounceTimerRef.current);
|
|
98
|
-
}
|
|
99
|
-
if (observerRef.current) {
|
|
100
|
-
observerRef.current.disconnect();
|
|
101
|
-
observerRef.current = null;
|
|
102
|
-
}
|
|
103
|
-
};
|
|
104
|
-
}, [
|
|
105
|
-
isLocked,
|
|
106
|
-
applyLockState,
|
|
107
|
-
debouncedApplyLockState,
|
|
108
|
-
findForm
|
|
109
|
-
]);
|
|
110
|
-
// Listen for form submission to auto-lock after save
|
|
111
|
-
useEffect(()=>{
|
|
112
|
-
const form = findForm();
|
|
113
|
-
if (!form) {
|
|
114
|
-
return;
|
|
115
|
-
}
|
|
116
|
-
const handleSubmit = ()=>{
|
|
117
|
-
// Lock after a delay to ensure save completes
|
|
118
|
-
setTimeout(()=>{
|
|
119
|
-
setIsLocked(true);
|
|
120
|
-
}, 2000);
|
|
121
|
-
};
|
|
122
|
-
form.addEventListener('submit', handleSubmit);
|
|
123
|
-
return ()=>{
|
|
124
|
-
form.removeEventListener('submit', handleSubmit);
|
|
125
|
-
};
|
|
126
|
-
}, [
|
|
127
|
-
findForm
|
|
128
|
-
]);
|
|
129
|
-
const toggleLock = useCallback(()=>{
|
|
130
|
-
setIsLocked((prev)=>!prev);
|
|
131
|
-
}, [
|
|
132
|
-
isLocked
|
|
133
|
-
]);
|
|
134
|
-
return /*#__PURE__*/ _jsx("div", {
|
|
135
|
-
className: "translation-settings-lock-container",
|
|
136
|
-
children: /*#__PURE__*/ _jsxs("button", {
|
|
137
|
-
className: `translation-settings-lock-button ${isLocked ? 'locked' : 'unlocked'}`,
|
|
138
|
-
onClick: toggleLock,
|
|
139
|
-
title: isLocked ? '🔒 Settings are locked to prevent accidental changes. Click to unlock and edit.' : '🔓 Settings are unlocked. Click to lock after saving your changes.',
|
|
140
|
-
type: "button",
|
|
141
|
-
children: [
|
|
142
|
-
/*#__PURE__*/ _jsx("span", {
|
|
143
|
-
className: "translation-settings-lock-icon",
|
|
144
|
-
children: isLocked ? '🔒' : '🔓'
|
|
145
|
-
}),
|
|
146
|
-
/*#__PURE__*/ _jsx("span", {
|
|
147
|
-
className: "translation-settings-lock-label",
|
|
148
|
-
children: isLocked ? 'Unlock Settings' : 'Lock Settings'
|
|
149
|
-
})
|
|
150
|
-
]
|
|
151
|
-
})
|
|
152
|
-
});
|
|
153
|
-
};
|
|
154
|
-
|
|
155
|
-
//# sourceMappingURL=TranslationSettingsLock.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/components/TranslationSettingsLock.tsx"],"sourcesContent":["'use client'\n\nimport React, { useCallback, useEffect, useRef, useState } from 'react'\n\nimport './TranslationSettingsLock.css'\n\n/**\n * Component that provides lock/unlock functionality for translation settings\n * - Fields are locked by default (read-only)\n * - User must click \"Unlock\" to edit\n * - After saving, fields automatically lock again\n */\nexport const TranslationSettingsLock: React.FC = () => {\n const [isLocked, setIsLocked] = useState(true)\n const formRef = useRef<HTMLFormElement | null>(null)\n const observerRef = useRef<MutationObserver | null>(null)\n const debounceTimerRef = useRef<NodeJS.Timeout | null>(null)\n\n // Find form element (memoized selector logic)\n const findForm = useCallback((): HTMLFormElement | null => {\n if (formRef.current && document.contains(formRef.current)) {\n return formRef.current\n }\n\n const formElement =\n document.querySelector('form[id*=\"translation-settings\"]') ||\n document.querySelector('form[id*=\"Global\"]') ||\n document.querySelector('form.render-fields') ||\n document.querySelector('form')\n\n const form = formElement as HTMLFormElement | null\n\n if (form) {\n formRef.current = form\n }\n\n return form\n }, [])\n\n // Apply lock/unlock state to all form fields (optimized with caching)\n const applyLockState = useCallback(() => {\n const form = findForm()\n\n if (!form) {\n return\n }\n\n // Find all input fields - using more efficient selector\n const inputs = form.querySelectorAll<HTMLInputElement | HTMLTextAreaElement>(\n 'input[type=\"text\"], input[type=\"number\"], textarea',\n )\n\n // Batch DOM updates for better performance\n inputs.forEach((input) => {\n // Skip if this is the lock control itself\n if (input.closest('.translation-settings-lock-container')) {\n return\n }\n\n // Use single operation to update multiple attributes\n if (isLocked) {\n input.setAttribute('readonly', 'true')\n input.setAttribute('disabled', 'true')\n input.classList.add('translation-settings-locked')\n } else {\n input.removeAttribute('readonly')\n input.removeAttribute('disabled')\n input.classList.remove('translation-settings-locked')\n }\n })\n\n // Update the save button state\n const saveButtonElement = document.querySelector('button#action-save')\n const saveButton = saveButtonElement as HTMLButtonElement | null\n\n if (saveButton) {\n if (isLocked) {\n saveButton.setAttribute('disabled', 'true')\n saveButton.classList.add('translation-settings-save-locked')\n } else {\n saveButton.removeAttribute('disabled')\n saveButton.classList.remove('translation-settings-save-locked')\n }\n }\n }, [isLocked, findForm])\n\n // Debounced version of applyLockState for MutationObserver\n const debouncedApplyLockState = useCallback(() => {\n if (debounceTimerRef.current) {\n clearTimeout(debounceTimerRef.current)\n }\n\n debounceTimerRef.current = setTimeout(() => {\n applyLockState()\n }, 100) // 100ms debounce\n }, [applyLockState])\n\n // Setup MutationObserver for form changes\n useEffect(() => {\n // Initial application\n const initialTimeout = setTimeout(applyLockState, 100)\n\n // Setup observer to watch for dynamic field additions\n const form = findForm()\n\n if (form) {\n observerRef.current = new MutationObserver(debouncedApplyLockState)\n\n // Only observe the form element, not the entire body (much more efficient)\n observerRef.current.observe(form, {\n attributes: false, // Don't watch attribute changes, only structure\n childList: true,\n subtree: true,\n })\n }\n\n return () => {\n clearTimeout(initialTimeout)\n if (debounceTimerRef.current) {\n clearTimeout(debounceTimerRef.current)\n }\n if (observerRef.current) {\n observerRef.current.disconnect()\n observerRef.current = null\n }\n }\n }, [isLocked, applyLockState, debouncedApplyLockState, findForm])\n\n // Listen for form submission to auto-lock after save\n useEffect(() => {\n const form = findForm()\n\n if (!form) {\n return\n }\n\n const handleSubmit = () => {\n // Lock after a delay to ensure save completes\n setTimeout(() => {\n setIsLocked(true)\n }, 2000)\n }\n\n form.addEventListener('submit', handleSubmit)\n\n return () => {\n form.removeEventListener('submit', handleSubmit)\n }\n }, [findForm])\n\n const toggleLock = useCallback(() => {\n setIsLocked((prev) => !prev)\n }, [isLocked])\n\n return (\n <div className=\"translation-settings-lock-container\">\n <button\n className={`translation-settings-lock-button ${isLocked ? 'locked' : 'unlocked'}`}\n onClick={toggleLock}\n title={\n isLocked\n ? '🔒 Settings are locked to prevent accidental changes. Click to unlock and edit.'\n : '🔓 Settings are unlocked. Click to lock after saving your changes.'\n }\n type=\"button\"\n >\n <span className=\"translation-settings-lock-icon\">{isLocked ? '🔒' : '🔓'}</span>\n <span className=\"translation-settings-lock-label\">\n {isLocked ? 'Unlock Settings' : 'Lock Settings'}\n </span>\n </button>\n </div>\n )\n}\n"],"names":["React","useCallback","useEffect","useRef","useState","TranslationSettingsLock","isLocked","setIsLocked","formRef","observerRef","debounceTimerRef","findForm","current","document","contains","formElement","querySelector","form","applyLockState","inputs","querySelectorAll","forEach","input","closest","setAttribute","classList","add","removeAttribute","remove","saveButtonElement","saveButton","debouncedApplyLockState","clearTimeout","setTimeout","initialTimeout","MutationObserver","observe","attributes","childList","subtree","disconnect","handleSubmit","addEventListener","removeEventListener","toggleLock","prev","div","className","button","onClick","title","type","span"],"mappings":"AAAA;;AAEA,OAAOA,SAASC,WAAW,EAAEC,SAAS,EAAEC,MAAM,EAAEC,QAAQ,QAAQ,QAAO;AAEvE,OAAO,gCAA+B;AAEtC;;;;;CAKC,GACD,OAAO,MAAMC,0BAAoC;IAC/C,MAAM,CAACC,UAAUC,YAAY,GAAGH,SAAS;IACzC,MAAMI,UAAUL,OAA+B;IAC/C,MAAMM,cAAcN,OAAgC;IACpD,MAAMO,mBAAmBP,OAA8B;IAEvD,8CAA8C;IAC9C,MAAMQ,WAAWV,YAAY;QAC3B,IAAIO,QAAQI,OAAO,IAAIC,SAASC,QAAQ,CAACN,QAAQI,OAAO,GAAG;YACzD,OAAOJ,QAAQI,OAAO;QACxB;QAEA,MAAMG,cACJF,SAASG,aAAa,CAAC,uCACvBH,SAASG,aAAa,CAAC,yBACvBH,SAASG,aAAa,CAAC,yBACvBH,SAASG,aAAa,CAAC;QAEzB,MAAMC,OAAOF;QAEb,IAAIE,MAAM;YACRT,QAAQI,OAAO,GAAGK;QACpB;QAEA,OAAOA;IACT,GAAG,EAAE;IAEL,sEAA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