From 1355c9b331c51a29dad1cd73ec8cb2d7a24af27d Mon Sep 17 00:00:00 2001 From: "zhoulibin@xiaoxin" <125377187@qq.com> Date: Fri, 5 Jul 2024 16:44:34 +0800 Subject: [PATCH] lint --- addon/prefs.js | 2 +- src/component/PopupRoot.tsx | 1277 +++++++++++++++++------------------ 2 files changed, 637 insertions(+), 642 deletions(-) diff --git a/addon/prefs.js b/addon/prefs.js index 78f2fd4c..c7e24012 100644 --- a/addon/prefs.js +++ b/addon/prefs.js @@ -17,4 +17,4 @@ pref("__prefsPrefix__.split-nested-tags-keep-first", true); pref("__prefsPrefix__.split-nested-tags-keep-second", true); pref("__prefsPrefix__.show-query-href", false); -pref("__prefsPrefix__.google-scholar-mirroring", ""); +pref("__prefsPrefix__.google-scholar-mirroring", ""); diff --git a/src/component/PopupRoot.tsx b/src/component/PopupRoot.tsx index ae8a8b7b..b88290c9 100644 --- a/src/component/PopupRoot.tsx +++ b/src/component/PopupRoot.tsx @@ -538,7 +538,7 @@ export function PopupRoot({ const [configName, setConfigName] = useState(getPref("configName")); function selectConfig(config: Config) { setShowConfig(false); - setPref("show-config", false) + setPref("show-config", false); setConfigName(config.configName); setPref("configName", config.configName); setBgColor(config.bgColor); @@ -600,713 +600,712 @@ export function PopupRoot({ // setTimeout(() => setShowConfig(true)); } - const handleContentDiv = React.useCallback(() => ( -
+ const handleContentDiv = React.useCallback( + () => (
setIsPopoverOpen(!isPopoverOpen)} - onClick={() => setAutoCloseSeconds(-1)} > - {isShowConfig && ( -
-
- {ConfigTabArray.map((a) => ( - { - setPref("configTab", a); - setConfigTab(a); - }} - > - {a} - - ))} -
+
- - { - setBgColor(e); - setPref("bgColor", e); + // width: divMaxWidth + "px", + // minHeight: divMaxHeight + "px", + // overflowY: "scroll", + }} + // onClick={() => setIsPopoverOpen(!isPopoverOpen)} + onClick={() => setAutoCloseSeconds(-1)} + > + {isShowConfig && ( +
+
+ {ConfigTabArray.map((a) => ( + { + setPref("configTab", a); + setConfigTab(a); }} > - 调整背景颜色: - + ))} +
+ + {"面板配置" == configTab && ( + <> + + { + setBgColor(e); + setPref("bgColor", e); }} > - - - - - + 调整背景颜色: + + + + - - 面板最大宽度: - { - if (e.currentTarget.value) { - setPref("divMaxWidth", e.currentTarget.valueAsNumber); - setDivMaxWidth(e.currentTarget.valueAsNumber); - } - }} - /> - px。 - 面板最大高度: + 面板最大宽度: { if (e.currentTarget.value) { - setPref("divMaxHeight", e.currentTarget.valueAsNumber); - setDivMaxHeight(e.currentTarget.valueAsNumber); + setPref("divMaxWidth", e.currentTarget.valueAsNumber); + setDivMaxWidth(e.currentTarget.valueAsNumber); } }} /> px。 + + 面板最大高度: + { + if (e.currentTarget.value) { + setPref("divMaxHeight", e.currentTarget.valueAsNumber); + setDivMaxHeight(e.currentTarget.valueAsNumber); + } + }} + /> + px。 + - - - { - if (e.currentTarget.value) { - setAutoCloseSeconds(e.currentTarget.valueAsNumber); - setPref("autoCloseSeconds", e.currentTarget.valueAsNumber); - } - }} - /> - 秒后自动关闭。 - - {/* 当前配置:{configName} */} + + { + if (e.currentTarget.value) { + setAutoCloseSeconds(e.currentTarget.valueAsNumber); + setPref("autoCloseSeconds", e.currentTarget.valueAsNumber); + } + }} + /> + 秒后自动关闭。 + + {/* 当前配置:{configName} */} - - {ConfigTypeArray.map((a) => loadDefault(a)).map( - (config) => - config && ( - { - selectConfig(config); - }} - > - {config.configName} + + {ConfigTypeArray.map((a) => loadDefault(a)).map( + (config) => + config && ( + { + selectConfig(config); + }} + > + {config.configName} + + ), + )}{" "} + + + )} + {"固定位置" == configTab && ( +
+ + + + left: + { + if (e.currentTarget.value) { + setPref("pFixedContentLocationLeft", e.currentTarget.value); + setPFixedContentLocationLeft(e.currentTarget.valueAsNumber); + } + }} + /> + + + top: + { + if (e.currentTarget.value) { + setPFixedContentLocationTop(e.currentTarget.valueAsNumber); + } + }} + /> + +
+ )} + {"弹出框" == configTab && ( +
+ <> + + + 和颜色框的距离: + { + if (e.currentTarget.value) { + setPref("pPadding", e.currentTarget.value); + setPPadding(e.currentTarget.valueAsNumber); + } + }} + /> + + + 边缘检测距离: + { + if (e.currentTarget.value) { + setPref("pBoundaryInset", e.currentTarget.value); + setPBoundaryInset(e.currentTarget.valueAsNumber); + } + }} + /> + + + 三角大小: + { + if (e.currentTarget.value) { + setPref("pArrowSize", e.currentTarget.value); + setPArrowSize(e.currentTarget.valueAsNumber); + } + }} + />{" "} + + + 优先默认位置: + {("bottom,left,top,right".split(",") as PopoverPosition[]).sort(sortFixed(pPositions)).map((a, i) => ( + + [ + {i > 0 && i < pPositions.length && ( + { + updatePPositions((pPositions) => { + pPositions.splice(i - 1, 0, ...pPositions.splice(i, 1)); + setPref("pPositions", pPositions.join(",")); + }); + }} + > + ⬅️ + + )} + + {i < pPositions.length - 1 && ( + { + updatePPositions((pPositions) => { + pPositions.splice(i + 1, 0, ...pPositions.splice(i, 1)); + setPref("pPositions", pPositions.join(",")); + }); + }} + > + ➡️ + + )} + ] - ), - )}{" "} - - - )} - {"固定位置" == configTab && ( -
- + ))} + + +
+ )} - - left: - { - if (e.currentTarget.value) { - setPref("pFixedContentLocationLeft", e.currentTarget.value); - setPFixedContentLocationLeft(e.currentTarget.valueAsNumber); - } - }} - /> - - - top: - { - if (e.currentTarget.value) { - setPFixedContentLocationTop(e.currentTarget.valueAsNumber); - } - }} - /> - -
- )} - {"弹出框" == configTab && ( -
- <> + {"颜色栏" == configTab && ( + + +
+
+ )} + {"标签样式" == configTab && ( + <> - 和颜色框的距离: + 显示 { + setPref("showTagsLength", e.currentTarget.value); + setShowTagsLength(e.currentTarget.valueAsNumber); + }} + /> + 个。 + + + 字体大小: + { if (e.currentTarget.value) { - setPref("pPadding", e.currentTarget.value); - setPPadding(e.currentTarget.valueAsNumber); + setPref("fontSize", e.currentTarget.valueAsNumber); + setFontSize(e.currentTarget.valueAsNumber); } }} /> + px。 + + + 行高: + { + setPref("lineHeight", e.currentTarget.value); + setLineHeight(e.currentTarget.value); + }} + />{" "} - 边缘检测距离: + margin: { if (e.currentTarget.value) { - setPref("pBoundaryInset", e.currentTarget.value); - setPBoundaryInset(e.currentTarget.valueAsNumber); + setPref("buttonMarginTopBottom", e.currentTarget.valueAsNumber); + setButtonMarginTopBottom(e.currentTarget.valueAsNumber); } }} /> + { + if (e.currentTarget.value) { + setPref("buttonMarginLeftRight", e.currentTarget.valueAsNumber); + setButtonMarginLeftRight(e.currentTarget.valueAsNumber); + } + }} + />{" "} - 三角大小: + padding: { if (e.currentTarget.value) { - setPref("pArrowSize", e.currentTarget.value); - setPArrowSize(e.currentTarget.valueAsNumber); + setPref("buttonPaddingTopBottom", e.currentTarget.valueAsNumber); + setButtonPaddingTopBottom(e.currentTarget.valueAsNumber); + } + }} + /> + { + if (e.currentTarget.value) { + setPref("buttonPaddingLeftRight", e.currentTarget.valueAsNumber); + setButtonPaddingLeftRight(e.currentTarget.valueAsNumber); } }} />{" "} - 优先默认位置: - {("bottom,left,top,right".split(",") as PopoverPosition[]).sort(sortFixed(pPositions)).map((a, i) => ( - - [ - {i > 0 && i < pPositions.length && ( - { - updatePPositions((pPositions) => { - pPositions.splice(i - 1, 0, ...pPositions.splice(i, 1)); - setPref("pPositions", pPositions.join(",")); - }); - }} - > - ⬅️ - - )} - - {i < pPositions.length - 1 && ( - { - updatePPositions((pPositions) => { - pPositions.splice(i + 1, 0, ...pPositions.splice(i, 1)); - setPref("pPositions", pPositions.join(",")); - }); - }} - > - ➡️ - - )} - ] - - ))} + 圆角: + -
- )} - - {"颜色栏" == configTab && ( - - - -
-
- )} - {"标签样式" == configTab && ( - <> - - 显示 - { - setPref("showTagsLength", e.currentTarget.value); - setShowTagsLength(e.currentTarget.valueAsNumber); - }} - /> - 个。 - - - 字体大小: - { - if (e.currentTarget.value) { - setPref("fontSize", e.currentTarget.valueAsNumber); - setFontSize(e.currentTarget.valueAsNumber); - } - }} - /> - px。 - - - 行高: - { - setPref("lineHeight", e.currentTarget.value); - setLineHeight(e.currentTarget.value); - }} - />{" "} - - - margin: - { - if (e.currentTarget.value) { - setPref("buttonMarginTopBottom", e.currentTarget.valueAsNumber); - setButtonMarginTopBottom(e.currentTarget.valueAsNumber); - } - }} - /> - { - if (e.currentTarget.value) { - setPref("buttonMarginLeftRight", e.currentTarget.valueAsNumber); - setButtonMarginLeftRight(e.currentTarget.valueAsNumber); - } - }} - />{" "} - - - padding: - { - if (e.currentTarget.value) { - setPref("buttonPaddingTopBottom", e.currentTarget.valueAsNumber); - setButtonPaddingTopBottom(e.currentTarget.valueAsNumber); - } - }} - /> - { - if (e.currentTarget.value) { - setPref("buttonPaddingLeftRight", e.currentTarget.valueAsNumber); - setButtonPaddingLeftRight(e.currentTarget.valueAsNumber); - } - }} - />{" "} - - - 圆角: - - - - )} - {"标签设置" == configTab && ( - <> -
- 排序规则: - {SortTypeArray.map((a) => ( + )} + {"标签设置" == configTab && ( + <> +
+ 排序规则: + {SortTypeArray.map((a) => ( + + ))} +
+ + )} + {"待开发" == configTab && ( + <> +
+ 相关标签的范围:(未完成) - ))} -
- - )} - {"待开发" == configTab && ( - <> -
- 相关标签的范围:(未完成) - - - - -
-
Nest标签相关:(未完成)
-
Tag排除规则:(未完成)
- - )} -
- )} -
- + + 本条目所在文件夹[] + + + +
+
Nest标签相关:(未完成)
+
Tag排除规则:(未完成)
+ + )} +
+ )} +
{ - setPref("show-config", !isShowConfig); - setShowConfig(!isShowConfig); + display: "flex", + flexWrap: "wrap", + alignItems: "center", }} > - 设置 - - {existTags.length > 0 && ( { + setPref("show-config", !isShowConfig); + setShowConfig(!isShowConfig); }} > - 现有标签: - {groupBy(existTags, (a) => a) - .sort(sortValuesLength) - .map((a) => ( - { - updateDelTags((dt) => { - const i = dt.findIndex((f) => f == a.key); - if (i > -1) { - dt.splice(i, 1); - } else { - dt.push(a.key); - } - }); - }} - > - [{a.values.length}/{existAnnotations.length}]{a.key} - {delTags.includes(a.key) && [待删除]} - - ))} + 设置 - )} - {params.ids && ( - <> + {existTags.length > 0 && ( 0 ? "#990000" : "#009900", - color: "#fff", - }} - onClick={() => { - setIsPopoverOpen(false); - - saveAnnotationTags("", [], delTags, reader, params, doc); - root?.remove(); + display: "flex", + flexWrap: "wrap", + fontSize: fontSize + "px", + lineHeight: lineHeight, + alignItems: "center", }} > - {delTags.length == 0 ? (autoCloseSeconds > 0 ? autoCloseSeconds + "s" : "点击") + "关闭" : "确认删除"} + 现有标签: + {groupBy(existTags, (a) => a) + .sort(sortValuesLength) + .map((a) => ( + { + updateDelTags((dt) => { + const i = dt.findIndex((f) => f == a.key); + if (i > -1) { + dt.splice(i, 1); + } else { + dt.push(a.key); + } + }); + }} + > + [{a.values.length}/{existAnnotations.length}]{a.key} + {delTags.includes(a.key) && [待删除]} + + ))} - - )} - setSearchTag(e.currentTarget.value)} - style={{ ...inputWidth(searchTag), minWidth: "18ch" }} - placeholder="搜索标签,按回车添加" - onKeyDown={(e) => { - // ztoolkit.log(e) - if (autoCloseSeconds > 0) { - setAutoCloseSeconds(-1); - } - if (e.code == "Enter") { - setIsPopoverOpen(false); - saveAnnotationTags(searchTag, [], [], reader, params, doc); - if (params.ids) { + )} + {params.ids && ( + <> + 0 ? "#990000" : "#009900", + color: "#fff", + }} + onClick={() => { + setIsPopoverOpen(false); + + saveAnnotationTags("", [], delTags, reader, params, doc); + root?.remove(); + }} + > + {delTags.length == 0 ? (autoCloseSeconds > 0 ? autoCloseSeconds + "s" : "点击") + "关闭" : "确认删除"} + + + )} + setSearchTag(e.currentTarget.value)} + style={{ ...inputWidth(searchTag), minWidth: "18ch" }} + placeholder="搜索标签,按回车添加" + onKeyDown={(e) => { + // ztoolkit.log(e) + if (autoCloseSeconds > 0) { + setAutoCloseSeconds(-1); + } + if (e.code == "Enter") { + setIsPopoverOpen(false); + saveAnnotationTags(searchTag, [], [], reader, params, doc); + if (params.ids) { + root.remove(); + } + return; + } + if (e.code == "Escape") { + //@ts-ignore _onSetSelectionPopup + reader?._primaryView._onSetSelectionPopup(null); root.remove(); + return; } - return; - } - if (e.code == "Escape") { - //@ts-ignore _onSetSelectionPopup - reader?._primaryView._onSetSelectionPopup(null); - root.remove(); - return; - } - }} - /> - {/* + }} + /> + {/* 固定标签来自【{currentPosition}】 相关标签来自【{currentPosition}】 */} - - {" "} - {displayTags.length}/{searchResultLength}: - - {displayTags.map((tag) => ( - { - if (isShowConfig) return; - setIsPopoverOpen(false); - saveAnnotationTags(tag.key, [], [], reader, params, doc); - if (params.ids) { - root.remove(); - } - }} - > - [{tag.values.length}] - {tag.key} + + {" "} + {displayTags.length}/{searchResultLength}: + + {displayTags.map((tag) => ( + { + if (isShowConfig) return; + setIsPopoverOpen(false); + saveAnnotationTags(tag.key, [], [], reader, params, doc); + if (params.ids) { + root.remove(); + } + }} + > + [{tag.values.length}] + {tag.key} - {isShowConfig && ( - <> - {memFixedTags().includes(tag.key) ? ( - <> - { - updateDisplayTags((a) => { - for (const b of a) { - if (b.key == tag.key) { - b.color = e; + {isShowConfig && ( + <> + {memFixedTags().includes(tag.key) ? ( + <> + { + updateDisplayTags((a) => { + for (const b of a) { + if (b.key == tag.key) { + b.color = e; + } } - } - }); - }} - > - 颜色 - - {/* + 颜色 + + {/* 右移 */} - - ) : ( - - {/* 设置固定 */} - - )} - - )} - - ))} - + + ) : ( + + {/* 设置固定 */} + + )} + + )} + + ))} + +
-
- ), + ), [ configName, pSingleWindow, @@ -1380,7 +1379,7 @@ export function PopupRoot({ divMaxHeight, buttonBorderRadius, ], - ) + ); const handleContent = React.useCallback( (popoverState: PopoverState) => ( - {handleContentDiv()} - - ) + return <>{handleContentDiv()}; } return ( <>