universal-plugin-hub 1.3.1 → 1.5.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 +14 -2
- package/README.zh.md +14 -2
- package/client/client.js +2597 -357
- package/package.json +1 -1
- package/src/at-plugins.js +823 -0
- package/src/icons.js +7 -0
- package/src/index.js +18 -0
- package/src/install.js +3415 -3088
- package/src/market.js +71 -46
- package/src/oauth-bridge.js +0 -1
- package/src/oauth-config.js +4 -0
- package/src/oauth-store.js +24 -11
- package/src/oauth.js +3 -3
- package/src/parser.js +31 -8
- package/src/routes.js +58 -26
- package/src/runtime.js +3 -1
- package/src/skills.js +4 -4
- package/src/store.js +93 -15
package/client/client.js
CHANGED
|
@@ -641,7 +641,7 @@ window.__ModuleLoader__.load({ id: "universal-plugin-hub", factory: (require) =>
|
|
|
641
641
|
--cpm-pill-bg: rgba(255, 255, 255, 0.08);
|
|
642
642
|
--cpm-pill-border: rgba(255, 255, 255, 0.12);
|
|
643
643
|
--cpm-pill-text: #f4f4f5;
|
|
644
|
-
--cpm-icon-btn-bg: #
|
|
644
|
+
--cpm-icon-btn-bg: #202023;
|
|
645
645
|
--cpm-icon-btn-border: rgba(255, 255, 255, 0.14);
|
|
646
646
|
--cpm-icon-btn-hover: rgba(255, 255, 255, 0.12);
|
|
647
647
|
--cpm-accent: #3b82f6;
|
|
@@ -653,10 +653,10 @@ window.__ModuleLoader__.load({ id: "universal-plugin-hub", factory: (require) =>
|
|
|
653
653
|
--cpm-toggle-knob-shadow: 0 1px 4px rgba(0, 0, 0, 0.45), 0 1px 1px rgba(0, 0, 0, 0.35);
|
|
654
654
|
--cpm-toggle-on: #2563eb;
|
|
655
655
|
--cpm-toggle-on-border: #2563eb;
|
|
656
|
-
--cpm-modal-bg: #
|
|
656
|
+
--cpm-modal-bg: #202023;
|
|
657
657
|
--cpm-modal-border: rgba(255, 255, 255, 0.14);
|
|
658
658
|
--cpm-shadow: 0 12px 36px rgba(0, 0, 0, 0.6);
|
|
659
|
-
--cpm-toast-bg: #
|
|
659
|
+
--cpm-toast-bg: #202023;
|
|
660
660
|
--cpm-toast-text: #f4f4f5;
|
|
661
661
|
--cpm-toast-border: rgba(255, 255, 255, 0.14);
|
|
662
662
|
--cpm-toast-shadow: 0 8px 30px rgba(0, 0, 0, 0.6);
|
|
@@ -1015,7 +1015,7 @@ window.__ModuleLoader__.load({ id: "universal-plugin-hub", factory: (require) =>
|
|
|
1015
1015
|
flex-direction: column;
|
|
1016
1016
|
}
|
|
1017
1017
|
.cpm-dark .cpm-preview-popover {
|
|
1018
|
-
background: rgba(
|
|
1018
|
+
background: rgba(32, 32, 35, 0.75);
|
|
1019
1019
|
backdrop-filter: blur(22px) saturate(180%);
|
|
1020
1020
|
-webkit-backdrop-filter: blur(22px) saturate(180%);
|
|
1021
1021
|
border: 1px solid var(--cpm-modal-border);
|
|
@@ -1266,12 +1266,43 @@ window.__ModuleLoader__.load({ id: "universal-plugin-hub", factory: (require) =>
|
|
|
1266
1266
|
overflow: hidden;
|
|
1267
1267
|
text-overflow: ellipsis;
|
|
1268
1268
|
}
|
|
1269
|
+
.cpm-root :is(.cpm-card-pill, .cpm-toggle) {
|
|
1270
|
+
border-radius: 9999px;
|
|
1271
|
+
corner-shape: initial;
|
|
1272
|
+
}
|
|
1273
|
+
@supports (border-shape: shape(from 0 0, line to 100% 100%, close)) {
|
|
1274
|
+
/* Each end keeps its middle 120° of circular arc. The cubic shoulders
|
|
1275
|
+
match the tangent and curvature of the straight edge and the arc. */
|
|
1276
|
+
.cpm-root :is(.cpm-card-pill, .cpm-toggle) {
|
|
1277
|
+
--cap-start: calc(var(--cap-radius) * 1.1);
|
|
1278
|
+
--cap-control-flat: calc(var(--cap-radius) * .947441);
|
|
1279
|
+
--cap-control-arc: calc(var(--cap-radius) * .732051);
|
|
1280
|
+
--cap-join-x: calc(var(--cap-radius) * .5);
|
|
1281
|
+
--cap-join-y: calc(var(--cap-radius) * .133975);
|
|
1282
|
+
border-shape: shape(
|
|
1283
|
+
from var(--cap-start) 0,
|
|
1284
|
+
line to calc(100% - var(--cap-start)) 0,
|
|
1285
|
+
curve to calc(100% - var(--cap-join-x)) var(--cap-join-y)
|
|
1286
|
+
with calc(100% - var(--cap-control-flat)) 0 / calc(100% - var(--cap-control-arc)) 0,
|
|
1287
|
+
arc to calc(100% - var(--cap-join-x)) calc(100% - var(--cap-join-y)) of var(--cap-radius) cw,
|
|
1288
|
+
curve to calc(100% - var(--cap-start)) 100%
|
|
1289
|
+
with calc(100% - var(--cap-control-arc)) 100% / calc(100% - var(--cap-control-flat)) 100%,
|
|
1290
|
+
line to var(--cap-start) 100%,
|
|
1291
|
+
curve to var(--cap-join-x) calc(100% - var(--cap-join-y))
|
|
1292
|
+
with var(--cap-control-flat) 100% / var(--cap-control-arc) 100%,
|
|
1293
|
+
arc to var(--cap-join-x) var(--cap-join-y) of var(--cap-radius) cw,
|
|
1294
|
+
curve to var(--cap-start) 0 with var(--cap-control-arc) 0 / var(--cap-control-flat) 0,
|
|
1295
|
+
close
|
|
1296
|
+
);
|
|
1297
|
+
}
|
|
1298
|
+
}
|
|
1269
1299
|
.cpm-card-pill {
|
|
1300
|
+
/* Radius of the border's centerline: half the line-height, padding and one border edge. */
|
|
1301
|
+
--cap-radius: calc(.7em + 3.5px);
|
|
1270
1302
|
display: inline-flex;
|
|
1271
1303
|
align-items: center;
|
|
1272
1304
|
justify-content: center;
|
|
1273
1305
|
padding: 3px 12px;
|
|
1274
|
-
border-radius: 9999px;
|
|
1275
1306
|
font-size: 12px;
|
|
1276
1307
|
font-weight: 500;
|
|
1277
1308
|
cursor: pointer;
|
|
@@ -1649,20 +1680,25 @@ window.__ModuleLoader__.load({ id: "universal-plugin-hub", factory: (require) =>
|
|
|
1649
1680
|
}
|
|
1650
1681
|
.cpm-meta {
|
|
1651
1682
|
display: flex;
|
|
1652
|
-
gap: 32px;
|
|
1653
|
-
margin-
|
|
1654
|
-
padding-
|
|
1655
|
-
border-
|
|
1683
|
+
gap: 12px 32px;
|
|
1684
|
+
margin-block: 14px 0;
|
|
1685
|
+
padding-block-end: 14px;
|
|
1686
|
+
border-block-end: 1px solid var(--cpm-border);
|
|
1656
1687
|
flex-wrap: wrap;
|
|
1657
1688
|
}
|
|
1658
|
-
.cpm-meta div { font-size: 13px; }
|
|
1689
|
+
.cpm-meta > div { font-size: 13px; min-inline-size: 0; }
|
|
1659
1690
|
.cpm-meta .k {
|
|
1660
1691
|
color: var(--cpm-muted);
|
|
1661
1692
|
display: block;
|
|
1662
1693
|
font-size: 11.5px;
|
|
1663
|
-
margin-
|
|
1694
|
+
margin-block-end: 2px;
|
|
1695
|
+
}
|
|
1696
|
+
.cpm-meta .v {
|
|
1697
|
+
margin-inline-start: 0;
|
|
1698
|
+
color: var(--cpm-text);
|
|
1699
|
+
font-weight: 500;
|
|
1700
|
+
overflow-wrap: anywhere;
|
|
1664
1701
|
}
|
|
1665
|
-
.cpm-meta .v { color: var(--cpm-text); font-weight: 500; }
|
|
1666
1702
|
.cpm-meta .v a { color: var(--cpm-accent); text-decoration: none; }
|
|
1667
1703
|
.cpm-skill-warning { color: #c26a24; font-size: 13px; }
|
|
1668
1704
|
.cpm-card-open { border: 0; padding: 0; background: transparent; color: inherit; font: inherit; text-align: left; cursor: pointer; }
|
|
@@ -1683,6 +1719,7 @@ window.__ModuleLoader__.load({ id: "universal-plugin-hub", factory: (require) =>
|
|
|
1683
1719
|
look like a cut-down copy. */
|
|
1684
1720
|
--sw-w: 40px;
|
|
1685
1721
|
--sw-h: 22px;
|
|
1722
|
+
--cap-radius: calc(var(--sw-h) / 2);
|
|
1686
1723
|
--sw-knob: calc(var(--sw-h) * 0.7);
|
|
1687
1724
|
--sw-inset: calc((var(--sw-h) - var(--sw-knob)) / 2);
|
|
1688
1725
|
position: relative;
|
|
@@ -1698,7 +1735,6 @@ window.__ModuleLoader__.load({ id: "universal-plugin-hub", factory: (require) =>
|
|
|
1698
1735
|
align-self: center;
|
|
1699
1736
|
padding: 0;
|
|
1700
1737
|
box-sizing: border-box;
|
|
1701
|
-
border-radius: 9999px;
|
|
1702
1738
|
background: var(--cpm-toggle-off);
|
|
1703
1739
|
/* The hairline is an inset box-shadow, not a border and not an outline.
|
|
1704
1740
|
A border pushes the box unless border-box survives a host reset; an
|
|
@@ -1720,16 +1756,10 @@ window.__ModuleLoader__.load({ id: "universal-plugin-hub", factory: (require) =>
|
|
|
1720
1756
|
.cpm-toggle:focus-visible {
|
|
1721
1757
|
box-shadow: inset 0 0 0 1px var(--cpm-toggle-off-border), 0 0 0 2px var(--cpm-toggle-on);
|
|
1722
1758
|
}
|
|
1723
|
-
|
|
1724
|
-
|
|
1725
|
-
|
|
1726
|
-
|
|
1727
|
-
* was the workaround — but clip-path clips the element's own box-shadow too,
|
|
1728
|
-
* which silently deleted the lift under the knob that makes the mockup read
|
|
1729
|
-
* as a physical control. The radius is kept here (Browsers honour it in every
|
|
1730
|
-
* panel surface now that the switch is out of the host's generic input rules)
|
|
1731
|
-
* so the drop shadow survives.
|
|
1732
|
-
*/
|
|
1759
|
+
.cpm-root .cpm-toggle::after {
|
|
1760
|
+
border-radius: 50%;
|
|
1761
|
+
corner-shape: initial;
|
|
1762
|
+
}
|
|
1733
1763
|
.cpm-toggle::after {
|
|
1734
1764
|
content: "";
|
|
1735
1765
|
position: absolute;
|
|
@@ -1740,7 +1770,6 @@ window.__ModuleLoader__.load({ id: "universal-plugin-hub", factory: (require) =>
|
|
|
1740
1770
|
left: var(--sw-inset);
|
|
1741
1771
|
width: var(--sw-knob);
|
|
1742
1772
|
height: var(--sw-knob);
|
|
1743
|
-
border-radius: 50%;
|
|
1744
1773
|
background: var(--cpm-toggle-knob);
|
|
1745
1774
|
/* Two stops, the same construction as the mockup: a tight contact shadow
|
|
1746
1775
|
under the knob plus a soft ambient one. This is the detail that reads
|
|
@@ -2053,12 +2082,18 @@ window.__ModuleLoader__.load({ id: "universal-plugin-hub", factory: (require) =>
|
|
|
2053
2082
|
.cpm-dialog {
|
|
2054
2083
|
position: fixed;
|
|
2055
2084
|
inset: 0;
|
|
2056
|
-
|
|
2085
|
+
box-sizing: border-box;
|
|
2086
|
+
padding-block: 16px;
|
|
2087
|
+
padding-left: calc(var(--cpm-dialog-inset-left, 0px) + 16px);
|
|
2088
|
+
padding-right: calc(var(--cpm-dialog-inset-right, 0px) + 16px);
|
|
2057
2089
|
background: rgba(15, 23, 42, 0.38);
|
|
2058
2090
|
z-index: 10000;
|
|
2059
2091
|
display: flex;
|
|
2060
2092
|
align-items: center;
|
|
2093
|
+
align-items: safe center;
|
|
2061
2094
|
justify-content: center;
|
|
2095
|
+
justify-content: safe center;
|
|
2096
|
+
overflow-y: auto;
|
|
2062
2097
|
overscroll-behavior: contain;
|
|
2063
2098
|
backdrop-filter: blur(8px) saturate(140%);
|
|
2064
2099
|
-webkit-backdrop-filter: blur(8px) saturate(140%);
|
|
@@ -2977,10 +3012,14 @@ window.__ModuleLoader__.load({ id: "universal-plugin-hub", factory: (require) =>
|
|
|
2977
3012
|
outline: 2px solid var(--cpm-accent, #3b82f6);
|
|
2978
3013
|
outline-offset: 2px;
|
|
2979
3014
|
}
|
|
3015
|
+
.cpm-radio-card > .cpm-custom-radio,
|
|
3016
|
+
.cpm-custom-radio > .cpm-custom-radio-inner {
|
|
3017
|
+
border-radius: 50%;
|
|
3018
|
+
corner-shape: initial;
|
|
3019
|
+
}
|
|
2980
3020
|
.cpm-custom-radio {
|
|
2981
3021
|
width: 17px;
|
|
2982
3022
|
height: 17px;
|
|
2983
|
-
border-radius: 50%;
|
|
2984
3023
|
border: 1.5px solid var(--cpm-border);
|
|
2985
3024
|
display: flex;
|
|
2986
3025
|
align-items: center;
|
|
@@ -2998,7 +3037,6 @@ window.__ModuleLoader__.load({ id: "universal-plugin-hub", factory: (require) =>
|
|
|
2998
3037
|
.cpm-custom-radio-inner {
|
|
2999
3038
|
width: 5px;
|
|
3000
3039
|
height: 5px;
|
|
3001
|
-
border-radius: 50%;
|
|
3002
3040
|
background: #ffffff;
|
|
3003
3041
|
transform: scale(0);
|
|
3004
3042
|
transition: transform 0.15s cubic-bezier(0.34, 1.56, 0.64, 1);
|
|
@@ -3145,14 +3183,18 @@ window.__ModuleLoader__.load({ id: "universal-plugin-hub", factory: (require) =>
|
|
|
3145
3183
|
|
|
3146
3184
|
/* ────────────────────────────── MCP Connector Modal Styles (Refined) ────────────────────────────── */
|
|
3147
3185
|
.cpm-mcp-modal {
|
|
3186
|
+
box-sizing: border-box;
|
|
3148
3187
|
width: 540px;
|
|
3149
|
-
max-width:
|
|
3188
|
+
max-width: 100%;
|
|
3150
3189
|
border-radius: var(--dsw-radius-lg, 16px);
|
|
3151
3190
|
background: #ffffff;
|
|
3152
3191
|
border: 1px solid rgba(0, 0, 0, 0.08);
|
|
3153
3192
|
box-shadow: 0 20px 50px rgba(0, 0, 0, 0.16), 0 4px 16px rgba(0, 0, 0, 0.06);
|
|
3154
3193
|
padding: 0;
|
|
3155
3194
|
overflow: visible;
|
|
3195
|
+
overscroll-behavior: contain;
|
|
3196
|
+
transform-origin: center 45%;
|
|
3197
|
+
animation: cpm-dialog-in 0.22s cubic-bezier(0.22, 1, 0.36, 1) both;
|
|
3156
3198
|
color: #18181b;
|
|
3157
3199
|
display: flex;
|
|
3158
3200
|
flex-direction: column;
|
|
@@ -4108,9 +4150,12 @@ window.__ModuleLoader__.load({ id: "universal-plugin-hub", factory: (require) =>
|
|
|
4108
4150
|
font-family: inherit;
|
|
4109
4151
|
box-sizing: border-box;
|
|
4110
4152
|
}
|
|
4153
|
+
.cpm-tooltip-surface,
|
|
4111
4154
|
.cpm-smart-hover {
|
|
4112
4155
|
border-radius: var(--dsw-radius-lg, 16px);
|
|
4113
4156
|
corner-shape: squircle;
|
|
4157
|
+
}
|
|
4158
|
+
.cpm-smart-hover {
|
|
4114
4159
|
user-select: text;
|
|
4115
4160
|
}
|
|
4116
4161
|
.cpm-root:has(.cpm-smart-hover[data-pointer-inside="true"]) :is(.cpm-card, .cpm-mcp-tool-dot) {
|
|
@@ -4126,7 +4171,7 @@ window.__ModuleLoader__.load({ id: "universal-plugin-hub", factory: (require) =>
|
|
|
4126
4171
|
overscroll-behavior: contain;
|
|
4127
4172
|
}
|
|
4128
4173
|
.cpm-dark .cpm-mcp-tool-popover {
|
|
4129
|
-
background: rgba(
|
|
4174
|
+
background: rgba(32, 32, 35, 0.75);
|
|
4130
4175
|
backdrop-filter: blur(22px) saturate(180%);
|
|
4131
4176
|
-webkit-backdrop-filter: blur(22px) saturate(180%);
|
|
4132
4177
|
border: 1px solid var(--cpm-modal-border);
|
|
@@ -4507,7 +4552,7 @@ window.__ModuleLoader__.load({ id: "universal-plugin-hub", factory: (require) =>
|
|
|
4507
4552
|
user-select: none;
|
|
4508
4553
|
}
|
|
4509
4554
|
.cpm-dark .cpm-toast {
|
|
4510
|
-
background: rgba(
|
|
4555
|
+
background: rgba(32, 32, 35, 0.75);
|
|
4511
4556
|
color: #f4f4f5;
|
|
4512
4557
|
backdrop-filter: blur(22px) saturate(180%);
|
|
4513
4558
|
-webkit-backdrop-filter: blur(22px) saturate(180%);
|
|
@@ -4657,37 +4702,136 @@ window.__ModuleLoader__.load({ id: "universal-plugin-hub", factory: (require) =>
|
|
|
4657
4702
|
animation: cpm-rot 0.75s linear infinite;
|
|
4658
4703
|
}
|
|
4659
4704
|
.cpm-tooltip {
|
|
4660
|
-
|
|
4661
|
-
|
|
4662
|
-
|
|
4705
|
+
position: fixed;
|
|
4706
|
+
padding: 0;
|
|
4707
|
+
border: 0;
|
|
4708
|
+
background: transparent;
|
|
4709
|
+
color: inherit;
|
|
4710
|
+
overflow: visible;
|
|
4711
|
+
pointer-events: none;
|
|
4712
|
+
z-index: 999999;
|
|
4713
|
+
width: fit-content;
|
|
4714
|
+
max-width: calc(100vw - 24px);
|
|
4715
|
+
transition:
|
|
4716
|
+
display 0.09s,
|
|
4717
|
+
overlay 0.09s;
|
|
4718
|
+
transition-behavior: allow-discrete;
|
|
4719
|
+
}
|
|
4720
|
+
.cpm-tooltip:not(:is(:popover-open, .\\:popover-open, [data-open="true"])) {
|
|
4721
|
+
display: none;
|
|
4722
|
+
}
|
|
4723
|
+
.cpm-tooltip-surface {
|
|
4724
|
+
--cpm-tip-y: 4px;
|
|
4725
|
+
--cpm-tip-origin-x: 50%;
|
|
4726
|
+
max-width: min(280px, calc(100vw - 24px));
|
|
4727
|
+
padding: 6px 12px;
|
|
4728
|
+
font-size: 12px;
|
|
4663
4729
|
font-weight: 500;
|
|
4664
4730
|
line-height: 1.35;
|
|
4731
|
+
letter-spacing: 0.005em;
|
|
4665
4732
|
white-space: nowrap;
|
|
4666
|
-
|
|
4667
|
-
|
|
4733
|
+
overflow: hidden;
|
|
4734
|
+
text-overflow: ellipsis;
|
|
4668
4735
|
color: #18181b;
|
|
4669
|
-
|
|
4670
|
-
|
|
4736
|
+
background: rgba(255, 255, 255, 0.88);
|
|
4737
|
+
background-clip: padding-box;
|
|
4738
|
+
border: 1px solid rgba(0, 0, 0, 0.08);
|
|
4739
|
+
box-shadow:
|
|
4740
|
+
0 6px 20px rgba(0, 0, 0, 0.1),
|
|
4741
|
+
0 2px 6px rgba(0, 0, 0, 0.05);
|
|
4742
|
+
backdrop-filter: blur(20px) saturate(180%);
|
|
4743
|
+
-webkit-backdrop-filter: blur(20px) saturate(180%);
|
|
4744
|
+
transform-origin: var(--cpm-tip-origin-x) bottom;
|
|
4745
|
+
opacity: 0;
|
|
4746
|
+
transform: translateY(var(--cpm-tip-y)) scale(0.94);
|
|
4747
|
+
will-change: opacity, transform;
|
|
4748
|
+
transition:
|
|
4749
|
+
opacity 0.09s cubic-bezier(0.22, 1, 0.36, 1),
|
|
4750
|
+
transform 0.09s cubic-bezier(0.22, 1, 0.36, 1);
|
|
4671
4751
|
}
|
|
4672
|
-
.cpm-root.cpm-dark .cpm-tooltip,
|
|
4673
|
-
|
|
4752
|
+
.cpm-root.cpm-dark .cpm-tooltip-surface,
|
|
4753
|
+
.cpm-tooltip.cpm-dark .cpm-tooltip-surface {
|
|
4674
4754
|
color: #f4f4f5;
|
|
4675
|
-
|
|
4676
|
-
|
|
4755
|
+
background: rgba(34, 34, 38, 0.88);
|
|
4756
|
+
border: 1px solid rgba(255, 255, 255, 0.12);
|
|
4757
|
+
box-shadow:
|
|
4758
|
+
0 8px 24px rgba(0, 0, 0, 0.5),
|
|
4759
|
+
0 2px 6px rgba(0, 0, 0, 0.32);
|
|
4677
4760
|
}
|
|
4678
|
-
|
|
4679
|
-
|
|
4761
|
+
.cpm-tooltip:is(:popover-open, .\\:popover-open, [data-open="true"]) .cpm-tooltip-surface {
|
|
4762
|
+
opacity: 1;
|
|
4763
|
+
transform: translateY(0) scale(1);
|
|
4764
|
+
transition:
|
|
4765
|
+
opacity 0.09s cubic-bezier(0.22, 1, 0.36, 1),
|
|
4766
|
+
transform 0.14s cubic-bezier(0.22, 1, 0.36, 1);
|
|
4767
|
+
transition:
|
|
4768
|
+
opacity 0.09s cubic-bezier(0.22, 1, 0.36, 1),
|
|
4769
|
+
transform 0.14s linear(0, 0.1293 3.6%, 0.2747 7.1%, 0.4206 10.7%, 0.5566 14.3%, 0.6768 17.9%, 0.7782 21.4%, 0.8602 25%, 0.9238 28.6%, 0.9709 32.1%, 1.004 35.7%, 1.0255 39.3%, 1.0379 42.9%, 1.0435 46.4%, 1.0443 50%, 1.0419 53.6%, 1.0374 57.1%, 1.0321 60.7%, 1.0264 64.3%, 1.021 67.9%, 1.016 71.4%, 1.0118 75%, 1.0083 78.6%, 1.0056 82.1%, 1.0035 85.7%, 1.002 89.3%, 1.001 92.9%, 1.0003 96.4%, 1);
|
|
4770
|
+
}
|
|
4771
|
+
@starting-style {
|
|
4772
|
+
.cpm-tooltip:is(:popover-open, .\\:popover-open, [data-open="true"]) .cpm-tooltip-surface {
|
|
4680
4773
|
opacity: 0;
|
|
4681
|
-
transform: translateY(
|
|
4774
|
+
transform: translateY(var(--cpm-tip-y)) scale(0.94);
|
|
4682
4775
|
}
|
|
4683
|
-
|
|
4684
|
-
|
|
4685
|
-
|
|
4776
|
+
}
|
|
4777
|
+
.cpm-tooltip[data-placement="bottom"] .cpm-tooltip-surface {
|
|
4778
|
+
--cpm-tip-y: -4px;
|
|
4779
|
+
transform-origin: var(--cpm-tip-origin-x) top;
|
|
4780
|
+
}
|
|
4781
|
+
.cpm-tooltip[data-anchored="false"] {
|
|
4782
|
+
position-area: none;
|
|
4783
|
+
position-anchor: auto;
|
|
4784
|
+
inset: auto;
|
|
4785
|
+
right: auto;
|
|
4786
|
+
bottom: auto;
|
|
4787
|
+
margin: 0;
|
|
4788
|
+
}
|
|
4789
|
+
@supports (position-area: block-start) and (anchor-name: --cpm-tip-anchor) {
|
|
4790
|
+
.cpm-tooltip:not([data-anchored="false"]) {
|
|
4791
|
+
position-anchor: --cpm-tip-anchor;
|
|
4792
|
+
position-area: block-start;
|
|
4793
|
+
position-try-fallbacks: flip-block;
|
|
4794
|
+
justify-self: anchor-center;
|
|
4795
|
+
margin-inline: 12px;
|
|
4796
|
+
margin-block-end: 8px;
|
|
4797
|
+
}
|
|
4798
|
+
}
|
|
4799
|
+
@supports (container-type: anchored) {
|
|
4800
|
+
.cpm-tooltip:not([data-anchored="false"]) {
|
|
4801
|
+
container-type: anchored;
|
|
4802
|
+
}
|
|
4803
|
+
@container anchored(fallback: flip-block) {
|
|
4804
|
+
.cpm-tooltip-surface {
|
|
4805
|
+
--cpm-tip-y: -4px;
|
|
4806
|
+
transform-origin: var(--cpm-tip-origin-x) top;
|
|
4807
|
+
}
|
|
4686
4808
|
}
|
|
4687
4809
|
}
|
|
4688
4810
|
@media (prefers-reduced-motion: reduce) {
|
|
4811
|
+
.cpm-tooltip {
|
|
4812
|
+
transition:
|
|
4813
|
+
display 0.1s,
|
|
4814
|
+
overlay 0.1s;
|
|
4815
|
+
transition-behavior: allow-discrete;
|
|
4816
|
+
}
|
|
4817
|
+
.cpm-tooltip-surface {
|
|
4818
|
+
--cpm-tip-y: 0px;
|
|
4819
|
+
transform: none;
|
|
4820
|
+
will-change: opacity;
|
|
4821
|
+
transition: opacity 0.1s ease;
|
|
4822
|
+
}
|
|
4823
|
+
.cpm-tooltip:is(:popover-open, .\\:popover-open, [data-open="true"]) .cpm-tooltip-surface {
|
|
4824
|
+
transform: none;
|
|
4825
|
+
transition: opacity 0.1s ease;
|
|
4826
|
+
}
|
|
4827
|
+
@starting-style {
|
|
4828
|
+
.cpm-tooltip:is(:popover-open, .\\:popover-open, [data-open="true"]) .cpm-tooltip-surface {
|
|
4829
|
+
opacity: 0;
|
|
4830
|
+
transform: none;
|
|
4831
|
+
}
|
|
4832
|
+
}
|
|
4689
4833
|
.cpm-dialog { animation-duration: 0.08s; }
|
|
4690
|
-
.cpm-dialog-box { animation-name: cpm-dialog-fade; animation-duration: 0.1s; }
|
|
4834
|
+
.cpm-dialog-box, .cpm-mcp-modal { animation-name: cpm-dialog-fade; animation-duration: 0.1s; }
|
|
4691
4835
|
.cpm-source-dialog-box { transition: border-color 100ms ease, box-shadow 100ms ease; }
|
|
4692
4836
|
.cpm-source-drag-overlay,
|
|
4693
4837
|
.cpm-source-drag-content {
|
|
@@ -4723,6 +4867,28 @@ window.__ModuleLoader__.load({ id: "universal-plugin-hub", factory: (require) =>
|
|
|
4723
4867
|
.cpm-upload-progress:indeterminate::-moz-progress-bar { animation-duration: 10s; }
|
|
4724
4868
|
.cpm-upload-dialog .cpm-spin-ring { animation-duration: 3s; }
|
|
4725
4869
|
}
|
|
4870
|
+
@media (prefers-reduced-transparency: reduce) {
|
|
4871
|
+
.cpm-tooltip-surface {
|
|
4872
|
+
backdrop-filter: none;
|
|
4873
|
+
-webkit-backdrop-filter: none;
|
|
4874
|
+
background: #ffffff;
|
|
4875
|
+
}
|
|
4876
|
+
.cpm-root.cpm-dark .cpm-tooltip-surface,
|
|
4877
|
+
.cpm-tooltip.cpm-dark .cpm-tooltip-surface {
|
|
4878
|
+
background: #222226;
|
|
4879
|
+
}
|
|
4880
|
+
}
|
|
4881
|
+
@media (prefers-contrast: more) {
|
|
4882
|
+
.cpm-tooltip-surface {
|
|
4883
|
+
background: rgba(255, 255, 255, 0.96);
|
|
4884
|
+
border-color: rgba(0, 0, 0, 0.28);
|
|
4885
|
+
}
|
|
4886
|
+
.cpm-root.cpm-dark .cpm-tooltip-surface,
|
|
4887
|
+
.cpm-tooltip.cpm-dark .cpm-tooltip-surface {
|
|
4888
|
+
background: rgba(34, 34, 38, 0.96);
|
|
4889
|
+
border-color: rgba(255, 255, 255, 0.34);
|
|
4890
|
+
}
|
|
4891
|
+
}
|
|
4726
4892
|
@media (prefers-reduced-transparency: reduce), (prefers-contrast: more) {
|
|
4727
4893
|
.cpm-dialog {
|
|
4728
4894
|
backdrop-filter: none;
|
|
@@ -4734,11 +4900,19 @@ window.__ModuleLoader__.load({ id: "universal-plugin-hub", factory: (require) =>
|
|
|
4734
4900
|
border-color: var(--cpm-accent);
|
|
4735
4901
|
box-shadow: none;
|
|
4736
4902
|
}
|
|
4737
|
-
.cpm-dialog-box, .cpm-source-dialog-box { border-color: var(--cpm-text-sub); }
|
|
4903
|
+
.cpm-dialog-box, .cpm-source-dialog-box, .cpm-mcp-modal { border-color: var(--cpm-text-sub); }
|
|
4738
4904
|
.cpm-upload-dialog .cpm-dropzone { border-color: var(--cpm-text-sub); }
|
|
4739
4905
|
}
|
|
4740
4906
|
@media (forced-colors: active) {
|
|
4741
|
-
.cpm-
|
|
4907
|
+
.cpm-tooltip-surface {
|
|
4908
|
+
backdrop-filter: none;
|
|
4909
|
+
-webkit-backdrop-filter: none;
|
|
4910
|
+
background: Canvas;
|
|
4911
|
+
color: CanvasText;
|
|
4912
|
+
border: 1px solid CanvasText;
|
|
4913
|
+
box-shadow: none;
|
|
4914
|
+
}
|
|
4915
|
+
.cpm-dialog-box, .cpm-source-dialog-box, .cpm-mcp-modal {
|
|
4742
4916
|
border: 1px solid CanvasText;
|
|
4743
4917
|
box-shadow: none;
|
|
4744
4918
|
}
|
|
@@ -4878,9 +5052,13 @@ window.__ModuleLoader__.load({ id: "universal-plugin-hub", factory: (require) =>
|
|
|
4878
5052
|
err.status = res.status;
|
|
4879
5053
|
throw err;
|
|
4880
5054
|
}
|
|
4881
|
-
if (body?.ok !== false && !body?.error && /^(POST|PUT|PATCH|DELETE)
|
|
4882
|
-
|
|
4883
|
-
|
|
5055
|
+
if (typeof document !== "undefined" && body?.ok !== false && !body?.error && /^(POST|PUT|PATCH|DELETE)$/i.test(options?.method || "") &&
|
|
5056
|
+
!/\/(verify|oauth-status|inspect|tools\/toggle)$/.test(path) && path !== "/sources/ensure") {
|
|
5057
|
+
if (/^\/(plugins|mcps)(\/|$)/.test(path)) {
|
|
5058
|
+
document.dispatchEvent(new Event("uph-mcp-branding-changed"));
|
|
5059
|
+
} else if (/^\/(sources|marketplaces|market)(\/|$)/.test(path)) {
|
|
5060
|
+
document.dispatchEvent(new Event("uph-at-plugins-changed"));
|
|
5061
|
+
}
|
|
4884
5062
|
}
|
|
4885
5063
|
return body;
|
|
4886
5064
|
}
|
|
@@ -5941,26 +6119,349 @@ window.__ModuleLoader__.load({ id: "universal-plugin-hub", factory: (require) =>
|
|
|
5941
6119
|
);
|
|
5942
6120
|
}
|
|
5943
6121
|
|
|
5944
|
-
|
|
5945
|
-
|
|
5946
|
-
|
|
5947
|
-
|
|
5948
|
-
|
|
5949
|
-
|
|
5950
|
-
|
|
5951
|
-
|
|
6122
|
+
const CPM_TOOLTIP_MARGIN = 12;
|
|
6123
|
+
const CPM_TOOLTIP_MARGIN_Y = 8;
|
|
6124
|
+
const CPM_TOOLTIP_GAP = 8;
|
|
6125
|
+
|
|
6126
|
+
function getTooltipViewport(viewport) {
|
|
6127
|
+
return {
|
|
6128
|
+
width: viewport && viewport.width > 0 ? viewport.width : (typeof window !== "undefined" ? window.innerWidth : 1280),
|
|
6129
|
+
height: viewport && viewport.height > 0 ? viewport.height : (typeof window !== "undefined" ? window.innerHeight : 800),
|
|
6130
|
+
};
|
|
6131
|
+
}
|
|
6132
|
+
|
|
6133
|
+
/**
|
|
6134
|
+
* Compute viewport-safe coordinates and flip direction for a floating tooltip.
|
|
6135
|
+
* Keeps the tooltip horizontally centered over its trigger (clamped to margin)
|
|
6136
|
+
* and sets transform-origin to track the trigger's center across clamps/flips.
|
|
6137
|
+
*/
|
|
6138
|
+
function placeTooltip(anchorRect, tipWidth, tipHeight, viewport) {
|
|
6139
|
+
const { width: vw, height: vh } = getTooltipViewport(viewport);
|
|
6140
|
+
const anchorW = anchorRect.width != null ? anchorRect.width : (anchorRect.right - anchorRect.left);
|
|
6141
|
+
const anchorBottom = anchorRect.bottom != null ? anchorRect.bottom : anchorRect.top + (anchorRect.height || 0);
|
|
6142
|
+
const triggerCenterX = anchorRect.left + anchorW / 2;
|
|
6143
|
+
const maxLeft = Math.max(CPM_TOOLTIP_MARGIN, vw - tipWidth - CPM_TOOLTIP_MARGIN);
|
|
6144
|
+
const left = Math.round(Math.max(CPM_TOOLTIP_MARGIN, Math.min(maxLeft, triggerCenterX - tipWidth / 2)));
|
|
6145
|
+
const originPx = tipWidth > 0 ? Math.max(8, Math.min(tipWidth - 8, triggerCenterX - left)) : 0;
|
|
6146
|
+
const originX = tipWidth > 0 ? (Math.round((originPx / tipWidth) * 1000) / 10) + "%" : "50%";
|
|
6147
|
+
|
|
6148
|
+
const aboveTop = anchorRect.top - tipHeight - CPM_TOOLTIP_GAP;
|
|
6149
|
+
const belowTop = anchorBottom + CPM_TOOLTIP_GAP;
|
|
6150
|
+
const spaceAbove = anchorRect.top - CPM_TOOLTIP_MARGIN_Y;
|
|
6151
|
+
const spaceBelow = vh - CPM_TOOLTIP_MARGIN_Y - anchorBottom;
|
|
6152
|
+
|
|
6153
|
+
if (aboveTop >= CPM_TOOLTIP_MARGIN_Y) {
|
|
6154
|
+
return {
|
|
6155
|
+
left,
|
|
6156
|
+
top: Math.round(aboveTop),
|
|
6157
|
+
placement: "top",
|
|
6158
|
+
originX,
|
|
6159
|
+
originY: "100%",
|
|
6160
|
+
};
|
|
6161
|
+
}
|
|
6162
|
+
if (spaceBelow > spaceAbove) {
|
|
6163
|
+
const maxTop = Math.max(CPM_TOOLTIP_MARGIN_Y, vh - tipHeight - CPM_TOOLTIP_MARGIN_Y);
|
|
6164
|
+
return {
|
|
6165
|
+
left,
|
|
6166
|
+
top: Math.round(Math.min(maxTop, Math.max(CPM_TOOLTIP_MARGIN_Y, belowTop))),
|
|
6167
|
+
placement: "bottom",
|
|
6168
|
+
originX,
|
|
6169
|
+
originY: "0%",
|
|
6170
|
+
};
|
|
6171
|
+
}
|
|
6172
|
+
return {
|
|
6173
|
+
left,
|
|
6174
|
+
top: Math.round(CPM_TOOLTIP_MARGIN_Y),
|
|
6175
|
+
placement: "top",
|
|
6176
|
+
originX,
|
|
6177
|
+
originY: "100%",
|
|
6178
|
+
};
|
|
6179
|
+
}
|
|
6180
|
+
|
|
6181
|
+
/**
|
|
6182
|
+
* Verify CSS Anchor Positioning actually aligned the popover to its trigger.
|
|
6183
|
+
* Catches ancestor containment / anchor-scope isolation where CSS anchor fails silently.
|
|
6184
|
+
*/
|
|
6185
|
+
function isAnchoredTipAligned(anchorRect, tipRect, viewport) {
|
|
6186
|
+
if (!anchorRect || !tipRect || !(tipRect.width > 0) || !(tipRect.height > 0)) return false;
|
|
6187
|
+
const expected = placeTooltip(anchorRect, tipRect.width, tipRect.height, viewport);
|
|
6188
|
+
const anchorBottom = anchorRect.bottom != null ? anchorRect.bottom : anchorRect.top + (anchorRect.height || 0);
|
|
6189
|
+
const tipBottom = tipRect.bottom != null ? tipRect.bottom : tipRect.top + tipRect.height;
|
|
6190
|
+
const aboveGap = anchorRect.top - tipBottom;
|
|
6191
|
+
const belowGap = tipRect.top - anchorBottom;
|
|
6192
|
+
const horizOk = Math.abs(tipRect.left - expected.left) <= 4;
|
|
6193
|
+
const vertOk = Math.abs(aboveGap - CPM_TOOLTIP_GAP) <= 4 || Math.abs(belowGap - CPM_TOOLTIP_GAP) <= 4;
|
|
6194
|
+
return horizOk && vertOk;
|
|
6195
|
+
}
|
|
6196
|
+
|
|
6197
|
+
let _cachedTipReactDOM;
|
|
6198
|
+
function getTooltipReactDOM() {
|
|
6199
|
+
if (_cachedTipReactDOM !== undefined) return _cachedTipReactDOM;
|
|
6200
|
+
try {
|
|
6201
|
+
const mod = typeof require === "function" ? require("react-dom") : null;
|
|
6202
|
+
_cachedTipReactDOM = mod && typeof mod.createPortal === "function" ? mod : null;
|
|
6203
|
+
} catch {
|
|
6204
|
+
_cachedTipReactDOM = null;
|
|
6205
|
+
}
|
|
6206
|
+
return _cachedTipReactDOM;
|
|
6207
|
+
}
|
|
6208
|
+
|
|
6209
|
+
function restoreAnchorTarget(entry) {
|
|
6210
|
+
if (!entry || !entry.target) return;
|
|
6211
|
+
const target = entry.target;
|
|
6212
|
+
if (target.style && typeof target.style.setProperty === "function") {
|
|
6213
|
+
if (entry.prevAnchorName) {
|
|
6214
|
+
target.style.setProperty("anchor-name", entry.prevAnchorName, entry.prevAnchorPriority || "");
|
|
6215
|
+
} else if (typeof target.style.removeProperty === "function") {
|
|
6216
|
+
target.style.removeProperty("anchor-name");
|
|
6217
|
+
}
|
|
5952
6218
|
}
|
|
6219
|
+
}
|
|
5953
6220
|
|
|
5954
|
-
|
|
6221
|
+
function restoreDescribedBy(entry) {
|
|
6222
|
+
if (!entry || !entry.addedDescribedBy || !entry.target || typeof entry.target.getAttribute !== "function") return;
|
|
6223
|
+
const target = entry.target;
|
|
6224
|
+
const tokens = (target.getAttribute("aria-describedby") || "").split(/\s+/).filter((t) => t && t !== "cpm-tooltip");
|
|
6225
|
+
if (tokens.length === 0) {
|
|
6226
|
+
if (typeof target.removeAttribute === "function") target.removeAttribute("aria-describedby");
|
|
6227
|
+
} else if (typeof target.setAttribute === "function") {
|
|
6228
|
+
target.setAttribute("aria-describedby", tokens.join(" "));
|
|
6229
|
+
}
|
|
6230
|
+
}
|
|
6231
|
+
|
|
6232
|
+
function applyFallbackPlacement(el, target) {
|
|
6233
|
+
if (!el || !target || typeof target.getBoundingClientRect !== "function" || typeof el.getBoundingClientRect !== "function") return;
|
|
6234
|
+
const anchorRect = target.getBoundingClientRect();
|
|
6235
|
+
const tipRect = el.getBoundingClientRect();
|
|
6236
|
+
if (!(tipRect.width > 0) || !(tipRect.height > 0)) return;
|
|
6237
|
+
const pos = placeTooltip(anchorRect, tipRect.width, tipRect.height, getTooltipViewport());
|
|
6238
|
+
if (typeof el.setAttribute === "function") {
|
|
6239
|
+
el.setAttribute("data-anchored", "false");
|
|
6240
|
+
el.setAttribute("data-placement", pos.placement);
|
|
6241
|
+
}
|
|
6242
|
+
if (el.style) {
|
|
6243
|
+
el.style.left = pos.left + "px";
|
|
6244
|
+
el.style.top = pos.top + "px";
|
|
6245
|
+
if (typeof el.style.setProperty === "function") {
|
|
6246
|
+
el.style.setProperty("--cpm-tip-origin-x", pos.originX);
|
|
6247
|
+
}
|
|
6248
|
+
}
|
|
6249
|
+
}
|
|
6250
|
+
|
|
6251
|
+
function CustomTooltip({ tooltip, isDark }) {
|
|
6252
|
+
const popRef = useRef(null);
|
|
6253
|
+
const anchorSessionRef = useRef(null);
|
|
6254
|
+
const closingAnchorRef = useRef(null);
|
|
6255
|
+
const exitGenRef = useRef(0);
|
|
6256
|
+
const exitTimerRef = useRef(null);
|
|
6257
|
+
const lastTextRef = useRef("");
|
|
6258
|
+
|
|
6259
|
+
const target = tooltip && tooltip.target ? tooltip.target : null;
|
|
6260
|
+
const text = tooltip && tooltip.text ? tooltip.text : "";
|
|
6261
|
+
const isOpen = Boolean(target && text);
|
|
6262
|
+
// Retain last label text across close so the 0.16s exit fade never collapses to an empty box.
|
|
6263
|
+
if (isOpen) lastTextRef.current = text;
|
|
6264
|
+
const displayText = isOpen ? text : lastTextRef.current;
|
|
6265
|
+
|
|
6266
|
+
// Ensure popover="hint" attribute is wired once on mount.
|
|
6267
|
+
useSafeLayoutEffect(() => {
|
|
6268
|
+
const el = popRef.current;
|
|
6269
|
+
if (!el || typeof el.setAttribute !== "function") return;
|
|
6270
|
+
try {
|
|
6271
|
+
el.setAttribute("popover", "hint");
|
|
6272
|
+
} catch {
|
|
6273
|
+
// Ignore in non-DOM test renderers or browsers rejecting hint.
|
|
6274
|
+
}
|
|
6275
|
+
}, []);
|
|
6276
|
+
|
|
6277
|
+
useSafeLayoutEffect(() => {
|
|
6278
|
+
const el = popRef.current;
|
|
6279
|
+
const hasTargetDom = Boolean(target && typeof target.getAttribute === "function");
|
|
6280
|
+
|
|
6281
|
+
if (!isOpen || !hasTargetDom) {
|
|
6282
|
+
const prev = anchorSessionRef.current;
|
|
6283
|
+
anchorSessionRef.current = null;
|
|
6284
|
+
if (prev) restoreDescribedBy(prev);
|
|
6285
|
+
const exitGen = ++exitGenRef.current;
|
|
6286
|
+
if (exitTimerRef.current) {
|
|
6287
|
+
clearTimeout(exitTimerRef.current);
|
|
6288
|
+
exitTimerRef.current = null;
|
|
6289
|
+
}
|
|
6290
|
+
if (el && typeof HTMLElement !== "undefined" && typeof el.hidePopover === "function") {
|
|
6291
|
+
try {
|
|
6292
|
+
if (typeof el.matches === "function" && el.matches(":popover-open")) el.hidePopover();
|
|
6293
|
+
} catch {
|
|
6294
|
+
// Ignore hide errors if already closed or detached.
|
|
6295
|
+
}
|
|
6296
|
+
}
|
|
6297
|
+
if (prev) {
|
|
6298
|
+
if (closingAnchorRef.current && closingAnchorRef.current !== prev) {
|
|
6299
|
+
restoreAnchorTarget(closingAnchorRef.current);
|
|
6300
|
+
}
|
|
6301
|
+
closingAnchorRef.current = prev;
|
|
6302
|
+
const finishClose = () => {
|
|
6303
|
+
if (exitGenRef.current !== exitGen) return;
|
|
6304
|
+
if (closingAnchorRef.current === prev) closingAnchorRef.current = null;
|
|
6305
|
+
restoreAnchorTarget(prev);
|
|
6306
|
+
};
|
|
6307
|
+
const anims = el && typeof el.getAnimations === "function" ? el.getAnimations({ subtree: true }) : [];
|
|
6308
|
+
if (anims.length > 0 && typeof Promise !== "undefined") {
|
|
6309
|
+
Promise.allSettled(anims.map((a) => a.finished)).then(finishClose);
|
|
6310
|
+
exitTimerRef.current = setTimeout(finishClose, 150);
|
|
6311
|
+
} else {
|
|
6312
|
+
finishClose();
|
|
6313
|
+
}
|
|
6314
|
+
}
|
|
6315
|
+
return;
|
|
6316
|
+
}
|
|
6317
|
+
|
|
6318
|
+
exitGenRef.current += 1;
|
|
6319
|
+
if (exitTimerRef.current) {
|
|
6320
|
+
clearTimeout(exitTimerRef.current);
|
|
6321
|
+
exitTimerRef.current = null;
|
|
6322
|
+
}
|
|
6323
|
+
|
|
6324
|
+
const existing = anchorSessionRef.current;
|
|
6325
|
+
if (existing && existing.target !== target) {
|
|
6326
|
+
restoreDescribedBy(existing);
|
|
6327
|
+
restoreAnchorTarget(existing);
|
|
6328
|
+
anchorSessionRef.current = null;
|
|
6329
|
+
}
|
|
6330
|
+
|
|
6331
|
+
const attachTarget = (sessionEntry) => {
|
|
6332
|
+
const tokens = (target.getAttribute("aria-describedby") || "").split(/\s+/).filter(Boolean);
|
|
6333
|
+
const addedDescribedBy = !tokens.includes("cpm-tooltip");
|
|
6334
|
+
if (addedDescribedBy) {
|
|
6335
|
+
tokens.push("cpm-tooltip");
|
|
6336
|
+
target.setAttribute("aria-describedby", tokens.join(" "));
|
|
6337
|
+
}
|
|
6338
|
+
if (target.style && typeof target.style.setProperty === "function") {
|
|
6339
|
+
target.style.setProperty("anchor-name", "--cpm-tip-anchor");
|
|
6340
|
+
}
|
|
6341
|
+
sessionEntry.addedDescribedBy = sessionEntry.addedDescribedBy || addedDescribedBy;
|
|
6342
|
+
anchorSessionRef.current = sessionEntry;
|
|
6343
|
+
};
|
|
6344
|
+
|
|
6345
|
+
const pendingClose = closingAnchorRef.current;
|
|
6346
|
+
if (pendingClose) {
|
|
6347
|
+
if (pendingClose.target === target && !anchorSessionRef.current) {
|
|
6348
|
+
// Reclaim original saved anchor state before restoring if re-hovered mid-exit.
|
|
6349
|
+
closingAnchorRef.current = null;
|
|
6350
|
+
attachTarget(pendingClose);
|
|
6351
|
+
} else {
|
|
6352
|
+
closingAnchorRef.current = null;
|
|
6353
|
+
restoreAnchorTarget(pendingClose);
|
|
6354
|
+
}
|
|
6355
|
+
}
|
|
6356
|
+
|
|
6357
|
+
if (!anchorSessionRef.current) {
|
|
6358
|
+
const prevAnchorName = target.style && typeof target.style.getPropertyValue === "function"
|
|
6359
|
+
? target.style.getPropertyValue("anchor-name")
|
|
6360
|
+
: "";
|
|
6361
|
+
const prevAnchorPriority = target.style && typeof target.style.getPropertyPriority === "function"
|
|
6362
|
+
? target.style.getPropertyPriority("anchor-name")
|
|
6363
|
+
: "";
|
|
6364
|
+
attachTarget({ target, prevAnchorName, prevAnchorPriority, addedDescribedBy: false });
|
|
6365
|
+
}
|
|
6366
|
+
|
|
6367
|
+
if (!el) return;
|
|
6368
|
+
|
|
6369
|
+
const supportsAnchorPos = typeof window !== "undefined" && Boolean(
|
|
6370
|
+
window.CSS &&
|
|
6371
|
+
typeof window.CSS.supports === "function" &&
|
|
6372
|
+
window.CSS.supports("position-area", "block-start") &&
|
|
6373
|
+
window.CSS.supports("anchor-name", "--cpm-tip-anchor")
|
|
6374
|
+
);
|
|
6375
|
+
|
|
6376
|
+
if (supportsAnchorPos) {
|
|
6377
|
+
if (typeof el.removeAttribute === "function") {
|
|
6378
|
+
el.removeAttribute("data-anchored");
|
|
6379
|
+
el.removeAttribute("data-placement");
|
|
6380
|
+
}
|
|
6381
|
+
if (el.style) {
|
|
6382
|
+
el.style.left = "";
|
|
6383
|
+
el.style.top = "";
|
|
6384
|
+
if (typeof el.style.removeProperty === "function") {
|
|
6385
|
+
el.style.removeProperty("--cpm-tip-origin-x");
|
|
6386
|
+
}
|
|
6387
|
+
}
|
|
6388
|
+
} else if (typeof el.setAttribute === "function") {
|
|
6389
|
+
el.setAttribute("data-anchored", "false");
|
|
6390
|
+
}
|
|
6391
|
+
|
|
6392
|
+
if (typeof el.showPopover === "function") {
|
|
6393
|
+
try {
|
|
6394
|
+
if (typeof el.matches !== "function" || !el.matches(":popover-open")) {
|
|
6395
|
+
el.showPopover();
|
|
6396
|
+
}
|
|
6397
|
+
} catch {
|
|
6398
|
+
// Ignore if browser rejects showPopover in current state.
|
|
6399
|
+
}
|
|
6400
|
+
}
|
|
6401
|
+
|
|
6402
|
+
if (typeof target.getBoundingClientRect === "function" && typeof el.getBoundingClientRect === "function") {
|
|
6403
|
+
if (!supportsAnchorPos || !isAnchoredTipAligned(target.getBoundingClientRect(), el.getBoundingClientRect(), getTooltipViewport())) {
|
|
6404
|
+
applyFallbackPlacement(el, target);
|
|
6405
|
+
}
|
|
6406
|
+
}
|
|
6407
|
+
}, [isOpen, target, text]);
|
|
6408
|
+
|
|
6409
|
+
// Keep fallback position synced on window resize or live size/text changes.
|
|
6410
|
+
useEffect(() => {
|
|
6411
|
+
const el = popRef.current;
|
|
6412
|
+
if (!isOpen || !el || !target) return;
|
|
6413
|
+
const syncIfFallback = () => {
|
|
6414
|
+
if (!el.getAttribute || el.getAttribute("data-anchored") !== "false") return;
|
|
6415
|
+
applyFallbackPlacement(el, target);
|
|
6416
|
+
};
|
|
6417
|
+
let ro = null;
|
|
6418
|
+
if (typeof window !== "undefined" && typeof window.ResizeObserver === "function") {
|
|
6419
|
+
ro = new window.ResizeObserver(syncIfFallback);
|
|
6420
|
+
ro.observe(el);
|
|
6421
|
+
if (typeof target.getBoundingClientRect === "function") ro.observe(target);
|
|
6422
|
+
}
|
|
6423
|
+
if (typeof window !== "undefined" && typeof window.addEventListener === "function") {
|
|
6424
|
+
window.addEventListener("resize", syncIfFallback);
|
|
6425
|
+
}
|
|
6426
|
+
return () => {
|
|
6427
|
+
if (ro) ro.disconnect();
|
|
6428
|
+
if (typeof window !== "undefined" && typeof window.removeEventListener === "function") {
|
|
6429
|
+
window.removeEventListener("resize", syncIfFallback);
|
|
6430
|
+
}
|
|
6431
|
+
};
|
|
6432
|
+
}, [isOpen, target, text]);
|
|
6433
|
+
|
|
6434
|
+
// Restore trigger attributes if CustomTooltip itself unmounts mid-display.
|
|
6435
|
+
useEffect(() => {
|
|
6436
|
+
return () => {
|
|
6437
|
+
if (exitTimerRef.current) clearTimeout(exitTimerRef.current);
|
|
6438
|
+
const pendingClose = closingAnchorRef.current;
|
|
6439
|
+
closingAnchorRef.current = null;
|
|
6440
|
+
if (pendingClose) restoreAnchorTarget(pendingClose);
|
|
6441
|
+
const current = anchorSessionRef.current;
|
|
6442
|
+
anchorSessionRef.current = null;
|
|
6443
|
+
if (current) {
|
|
6444
|
+
restoreDescribedBy(current);
|
|
6445
|
+
restoreAnchorTarget(current);
|
|
6446
|
+
}
|
|
6447
|
+
};
|
|
6448
|
+
}, []);
|
|
6449
|
+
|
|
6450
|
+
const node = h("div", {
|
|
6451
|
+
id: "cpm-tooltip",
|
|
6452
|
+
ref: popRef,
|
|
6453
|
+
role: "tooltip",
|
|
5955
6454
|
className: "cpm-tooltip" + (isDark ? " cpm-dark" : ""),
|
|
5956
|
-
|
|
5957
|
-
|
|
5958
|
-
|
|
5959
|
-
|
|
5960
|
-
|
|
5961
|
-
|
|
5962
|
-
|
|
5963
|
-
|
|
6455
|
+
"data-open": isOpen ? "true" : "false",
|
|
6456
|
+
"aria-hidden": isOpen ? undefined : "true",
|
|
6457
|
+
}, h("div", { className: "cpm-tooltip-surface" }, displayText));
|
|
6458
|
+
|
|
6459
|
+
const needsBodyPortal = typeof HTMLElement === "undefined" || typeof HTMLElement.prototype?.showPopover !== "function";
|
|
6460
|
+
const ReactDOM = needsBodyPortal ? getTooltipReactDOM() : null;
|
|
6461
|
+
if (needsBodyPortal && ReactDOM && typeof document !== "undefined" && document.body) {
|
|
6462
|
+
return ReactDOM.createPortal(node, document.body);
|
|
6463
|
+
}
|
|
6464
|
+
return node;
|
|
5964
6465
|
}
|
|
5965
6466
|
|
|
5966
6467
|
let currentTabAnim = null;
|
|
@@ -6116,6 +6617,114 @@ window.__ModuleLoader__.load({ id: "universal-plugin-hub", factory: (require) =>
|
|
|
6116
6617
|
return {};
|
|
6117
6618
|
}
|
|
6118
6619
|
|
|
6620
|
+
function normalizePanelInset(value) {
|
|
6621
|
+
if (!Number.isFinite(value) || value < 0.01) return 0;
|
|
6622
|
+
return Math.round(value * 100) / 100;
|
|
6623
|
+
}
|
|
6624
|
+
|
|
6625
|
+
function computePanelHorizontalInsets(rootEl, doc = rootEl?.ownerDocument || globalThis.document) {
|
|
6626
|
+
if (!rootEl || typeof rootEl.getBoundingClientRect !== "function") {
|
|
6627
|
+
return { left: 0, right: 0 };
|
|
6628
|
+
}
|
|
6629
|
+
const rect = rootEl.getBoundingClientRect();
|
|
6630
|
+
const win = doc?.defaultView;
|
|
6631
|
+
const docWidth = doc?.documentElement?.clientWidth;
|
|
6632
|
+
const viewportWidth = Number.isFinite(docWidth) && docWidth > 0
|
|
6633
|
+
? docWidth
|
|
6634
|
+
: (Number.isFinite(win?.innerWidth) && win.innerWidth > 0 ? win.innerWidth : 0);
|
|
6635
|
+
if (!rect || !(rect.width > 0) || !(viewportWidth > 0)) {
|
|
6636
|
+
return { left: 0, right: 0 };
|
|
6637
|
+
}
|
|
6638
|
+
const left = normalizePanelInset(rect.left);
|
|
6639
|
+
const right = normalizePanelInset(Number.isFinite(rect.right) ? viewportWidth - rect.right : 0);
|
|
6640
|
+
// Guard degenerate narrow/transient rects so dialog padding never collapses usable width below 32px
|
|
6641
|
+
if (left + right >= viewportWidth - 32) {
|
|
6642
|
+
return { left: 0, right: 0 };
|
|
6643
|
+
}
|
|
6644
|
+
return { left, right };
|
|
6645
|
+
}
|
|
6646
|
+
|
|
6647
|
+
function usePanelHorizontalInsets(rootRef) {
|
|
6648
|
+
useSafeLayoutEffect(() => {
|
|
6649
|
+
const rootEl = rootRef?.current;
|
|
6650
|
+
if (!rootEl || typeof rootEl.style?.setProperty !== "function") return undefined;
|
|
6651
|
+
const doc = rootEl.ownerDocument || (typeof document !== "undefined" ? document : null);
|
|
6652
|
+
const win = doc?.defaultView || (typeof window !== "undefined" ? window : null);
|
|
6653
|
+
let lastLeft = "";
|
|
6654
|
+
let lastRight = "";
|
|
6655
|
+
let rafId = 0;
|
|
6656
|
+
|
|
6657
|
+
const sync = () => {
|
|
6658
|
+
const { left, right } = computePanelHorizontalInsets(rootEl, doc);
|
|
6659
|
+
const nextLeft = `${left}px`;
|
|
6660
|
+
const nextRight = `${right}px`;
|
|
6661
|
+
if (nextLeft !== lastLeft) {
|
|
6662
|
+
rootEl.style.setProperty("--cpm-dialog-inset-left", nextLeft);
|
|
6663
|
+
lastLeft = nextLeft;
|
|
6664
|
+
}
|
|
6665
|
+
if (nextRight !== lastRight) {
|
|
6666
|
+
rootEl.style.setProperty("--cpm-dialog-inset-right", nextRight);
|
|
6667
|
+
lastRight = nextRight;
|
|
6668
|
+
}
|
|
6669
|
+
};
|
|
6670
|
+
|
|
6671
|
+
const scheduleSync = () => {
|
|
6672
|
+
if (rafId || typeof win?.requestAnimationFrame !== "function") {
|
|
6673
|
+
if (!rafId) sync();
|
|
6674
|
+
return;
|
|
6675
|
+
}
|
|
6676
|
+
rafId = win.requestAnimationFrame(() => {
|
|
6677
|
+
rafId = 0;
|
|
6678
|
+
sync();
|
|
6679
|
+
});
|
|
6680
|
+
};
|
|
6681
|
+
|
|
6682
|
+
sync();
|
|
6683
|
+
|
|
6684
|
+
const ResizeObserverCtor = win?.ResizeObserver || globalThis.ResizeObserver;
|
|
6685
|
+
let observer = null;
|
|
6686
|
+
const p1 = rootEl.parentElement;
|
|
6687
|
+
const p2 = p1?.parentElement;
|
|
6688
|
+
const p3 = p2?.parentElement;
|
|
6689
|
+
const frameRoot = p3 || p2 || p1 || rootEl;
|
|
6690
|
+
|
|
6691
|
+
if (typeof ResizeObserverCtor === "function") {
|
|
6692
|
+
observer = new ResizeObserverCtor(() => { sync(); });
|
|
6693
|
+
const targets = new Set([
|
|
6694
|
+
rootEl,
|
|
6695
|
+
p1,
|
|
6696
|
+
p1?.previousElementSibling,
|
|
6697
|
+
p1?.nextElementSibling,
|
|
6698
|
+
p2,
|
|
6699
|
+
p2?.previousElementSibling,
|
|
6700
|
+
p2?.nextElementSibling,
|
|
6701
|
+
p3,
|
|
6702
|
+
doc?.documentElement,
|
|
6703
|
+
]);
|
|
6704
|
+
for (const target of targets) {
|
|
6705
|
+
if (target) observer.observe(target);
|
|
6706
|
+
}
|
|
6707
|
+
}
|
|
6708
|
+
|
|
6709
|
+
if (typeof win?.addEventListener === "function") win.addEventListener("resize", sync);
|
|
6710
|
+
if (typeof frameRoot?.addEventListener === "function") frameRoot.addEventListener("transitionend", scheduleSync);
|
|
6711
|
+
|
|
6712
|
+
return () => {
|
|
6713
|
+
if (rafId && typeof win?.cancelAnimationFrame === "function") {
|
|
6714
|
+
win.cancelAnimationFrame(rafId);
|
|
6715
|
+
rafId = 0;
|
|
6716
|
+
}
|
|
6717
|
+
if (observer) observer.disconnect();
|
|
6718
|
+
if (typeof win?.removeEventListener === "function") win.removeEventListener("resize", sync);
|
|
6719
|
+
if (typeof frameRoot?.removeEventListener === "function") frameRoot.removeEventListener("transitionend", scheduleSync);
|
|
6720
|
+
if (typeof rootEl.style?.removeProperty === "function") {
|
|
6721
|
+
rootEl.style.removeProperty("--cpm-dialog-inset-left");
|
|
6722
|
+
rootEl.style.removeProperty("--cpm-dialog-inset-right");
|
|
6723
|
+
}
|
|
6724
|
+
};
|
|
6725
|
+
}, [rootRef]);
|
|
6726
|
+
}
|
|
6727
|
+
|
|
6119
6728
|
const SESSION_STORE = {
|
|
6120
6729
|
view: { type: "browse" },
|
|
6121
6730
|
sourceViews: {},
|
|
@@ -6140,6 +6749,7 @@ window.__ModuleLoader__.load({ id: "universal-plugin-hub", factory: (require) =>
|
|
|
6140
6749
|
// ────────────────────────────── Root App ──────────────────────────────
|
|
6141
6750
|
function MarketApp({ ctx }) {
|
|
6142
6751
|
const rootRef = useRef(null);
|
|
6752
|
+
usePanelHorizontalInsets(rootRef);
|
|
6143
6753
|
const getEffectiveTheme = useCallback(() => {
|
|
6144
6754
|
return isDarkMode(ctx, rootRef.current);
|
|
6145
6755
|
}, [ctx]);
|
|
@@ -6277,66 +6887,244 @@ window.__ModuleLoader__.load({ id: "universal-plugin-hub", factory: (require) =>
|
|
|
6277
6887
|
}, duration);
|
|
6278
6888
|
}, []);
|
|
6279
6889
|
|
|
6890
|
+
const [tipMounted, setTipMounted] = useState(false);
|
|
6280
6891
|
const [activeTooltip, setActiveTooltip] = useState(null);
|
|
6892
|
+
const activeTipTargetRef = useRef(null);
|
|
6893
|
+
activeTipTargetRef.current = activeTooltip ? activeTooltip.target : null;
|
|
6281
6894
|
const tipTimerRef = useRef(null);
|
|
6895
|
+
const pendingTipTargetRef = useRef(null);
|
|
6896
|
+
const tipPointerTypeRef = useRef("");
|
|
6282
6897
|
|
|
6283
|
-
const
|
|
6284
|
-
|
|
6285
|
-
if (
|
|
6286
|
-
|
|
6287
|
-
|
|
6898
|
+
const dismissTooltip = useCallback(() => {
|
|
6899
|
+
pendingTipTargetRef.current = null;
|
|
6900
|
+
if (tipTimerRef.current) {
|
|
6901
|
+
clearTimeout(tipTimerRef.current);
|
|
6902
|
+
tipTimerRef.current = null;
|
|
6903
|
+
}
|
|
6904
|
+
setActiveTooltip(null);
|
|
6905
|
+
}, []);
|
|
6906
|
+
|
|
6907
|
+
const scheduleTooltip = useCallback((target, delayMs, source) => {
|
|
6908
|
+
if (delayMs > 0 && tipTimerRef.current && pendingTipTargetRef.current === target) {
|
|
6288
6909
|
return;
|
|
6289
6910
|
}
|
|
6290
|
-
|
|
6291
|
-
if (
|
|
6911
|
+
pendingTipTargetRef.current = null;
|
|
6912
|
+
if (tipTimerRef.current) {
|
|
6913
|
+
clearTimeout(tipTimerRef.current);
|
|
6914
|
+
tipTimerRef.current = null;
|
|
6915
|
+
}
|
|
6916
|
+
const text = target && typeof target.getAttribute === "function" ? target.getAttribute("data-cpm-tip") : "";
|
|
6917
|
+
if (!target || !text) {
|
|
6292
6918
|
setActiveTooltip(null);
|
|
6293
6919
|
return;
|
|
6294
6920
|
}
|
|
6295
|
-
|
|
6921
|
+
setTipMounted(true);
|
|
6922
|
+
if (delayMs <= 0) {
|
|
6923
|
+
setActiveTooltip((prev) => (prev && prev.target === target && prev.text === text && prev.source === source ? prev : { target, text, source }));
|
|
6924
|
+
return;
|
|
6925
|
+
}
|
|
6926
|
+
pendingTipTargetRef.current = target;
|
|
6296
6927
|
tipTimerRef.current = setTimeout(() => {
|
|
6297
|
-
|
|
6298
|
-
|
|
6299
|
-
|
|
6928
|
+
tipTimerRef.current = null;
|
|
6929
|
+
pendingTipTargetRef.current = null;
|
|
6930
|
+
if (target.isConnected === false) return;
|
|
6931
|
+
const latestText = target.getAttribute("data-cpm-tip");
|
|
6932
|
+
if (!latestText) {
|
|
6933
|
+
setActiveTooltip(null);
|
|
6934
|
+
return;
|
|
6935
|
+
}
|
|
6936
|
+
setActiveTooltip((prev) => (prev && prev.target === target && prev.text === latestText && prev.source === source ? prev : { target, text: latestText, source }));
|
|
6937
|
+
}, delayMs);
|
|
6300
6938
|
}, []);
|
|
6301
6939
|
|
|
6302
|
-
const
|
|
6303
|
-
|
|
6304
|
-
if (related && related.closest && related.closest("[data-cpm-tip]")) {
|
|
6305
|
-
return;
|
|
6306
|
-
}
|
|
6307
|
-
if (tipTimerRef.current) clearTimeout(tipTimerRef.current);
|
|
6308
|
-
setActiveTooltip(null);
|
|
6940
|
+
const handleRootPointerOverCapture = useCallback((e) => {
|
|
6941
|
+
tipPointerTypeRef.current = e.pointerType || "";
|
|
6309
6942
|
}, []);
|
|
6310
6943
|
|
|
6311
|
-
const
|
|
6312
|
-
|
|
6313
|
-
|
|
6314
|
-
|
|
6315
|
-
|
|
6316
|
-
|
|
6317
|
-
|
|
6318
|
-
}, [
|
|
6944
|
+
const handleRootPointerDownCapture = useCallback((e) => {
|
|
6945
|
+
if (e.pointerType) tipPointerTypeRef.current = e.pointerType;
|
|
6946
|
+
if (e.pointerType === "touch") dismissTooltip();
|
|
6947
|
+
}, [dismissTooltip]);
|
|
6948
|
+
|
|
6949
|
+
const handleRootScrollCapture = useCallback(() => {
|
|
6950
|
+
if (tipTimerRef.current || activeTipTargetRef.current) dismissTooltip();
|
|
6951
|
+
}, [dismissTooltip]);
|
|
6952
|
+
|
|
6953
|
+
const handleRootMouseOver = useCallback((e) => {
|
|
6954
|
+
if (tipPointerTypeRef.current === "touch") return;
|
|
6955
|
+
const target = e.target && e.target.closest && e.target.closest("[data-cpm-tip]");
|
|
6956
|
+
if (!target) {
|
|
6957
|
+
dismissTooltip();
|
|
6958
|
+
return;
|
|
6959
|
+
}
|
|
6960
|
+
if (activeTipTargetRef.current === target) return;
|
|
6961
|
+
scheduleTooltip(target, 45, "pointer");
|
|
6962
|
+
}, [dismissTooltip, scheduleTooltip]);
|
|
6963
|
+
|
|
6964
|
+
const handleRootMouseOut = useCallback((e) => {
|
|
6965
|
+
const leaving = e.target && e.target.closest && e.target.closest("[data-cpm-tip]");
|
|
6966
|
+
const related = e.relatedTarget;
|
|
6967
|
+
const entering = related && related.closest && related.closest("[data-cpm-tip]");
|
|
6968
|
+
if (entering && (!leaving || entering === leaving)) return;
|
|
6969
|
+
dismissTooltip();
|
|
6970
|
+
}, [dismissTooltip]);
|
|
6971
|
+
|
|
6972
|
+
const handleRootFocus = useCallback((e) => {
|
|
6973
|
+
const target = e.target && e.target.closest && e.target.closest("[data-cpm-tip]");
|
|
6974
|
+
if (!target) return;
|
|
6975
|
+
let isFocusVisible = true;
|
|
6976
|
+
try {
|
|
6977
|
+
isFocusVisible = typeof target.matches === "function" ? target.matches(":focus-visible") : true;
|
|
6978
|
+
} catch {
|
|
6979
|
+
// Fallback to showing on focus when :focus-visible is unsupported.
|
|
6980
|
+
}
|
|
6981
|
+
if (!isFocusVisible) return;
|
|
6982
|
+
scheduleTooltip(target, 0, "focus");
|
|
6983
|
+
}, [scheduleTooltip]);
|
|
6984
|
+
|
|
6985
|
+
const handleRootBlur = useCallback((e) => {
|
|
6986
|
+
const related = e.relatedTarget;
|
|
6987
|
+
if (related && related.closest && related.closest("[data-cpm-tip]")) return;
|
|
6988
|
+
dismissTooltip();
|
|
6989
|
+
}, [dismissTooltip]);
|
|
6990
|
+
|
|
6991
|
+
useEffect(() => {
|
|
6992
|
+
const target = activeTooltip && activeTooltip.target;
|
|
6993
|
+
if (!target) return undefined;
|
|
6994
|
+
const rootEl = rootRef.current;
|
|
6995
|
+
|
|
6996
|
+
const handleScroll = () => dismissTooltip();
|
|
6997
|
+
const handleWindowBlur = () => dismissTooltip();
|
|
6998
|
+
const handleKeyDown = (e) => {
|
|
6999
|
+
if (e.key === "Escape") dismissTooltip();
|
|
7000
|
+
};
|
|
7001
|
+
|
|
7002
|
+
let attrObs = null;
|
|
7003
|
+
let treeObs = null;
|
|
7004
|
+
if (typeof window !== "undefined" && typeof window.MutationObserver === "function") {
|
|
7005
|
+
attrObs = new window.MutationObserver(() => {
|
|
7006
|
+
if (target.isConnected === false) {
|
|
7007
|
+
dismissTooltip();
|
|
7008
|
+
return;
|
|
7009
|
+
}
|
|
7010
|
+
const nextText = target.getAttribute("data-cpm-tip");
|
|
7011
|
+
if (!nextText) {
|
|
7012
|
+
dismissTooltip();
|
|
7013
|
+
return;
|
|
7014
|
+
}
|
|
7015
|
+
setActiveTooltip((prev) => (prev && prev.target === target && prev.text !== nextText ? { ...prev, text: nextText } : prev));
|
|
7016
|
+
});
|
|
7017
|
+
if (typeof target.nodeType === "number") {
|
|
7018
|
+
attrObs.observe(target, { attributes: true, attributeFilter: ["data-cpm-tip"] });
|
|
7019
|
+
}
|
|
7020
|
+
if (rootEl && typeof rootEl.nodeType === "number") {
|
|
7021
|
+
treeObs = new window.MutationObserver(() => {
|
|
7022
|
+
if (target.isConnected === false) dismissTooltip();
|
|
7023
|
+
});
|
|
7024
|
+
treeObs.observe(rootEl, { childList: true, subtree: true });
|
|
7025
|
+
}
|
|
7026
|
+
}
|
|
7027
|
+
|
|
7028
|
+
if (typeof window !== "undefined" && typeof window.addEventListener === "function") {
|
|
7029
|
+
window.addEventListener("scroll", handleScroll, { passive: true });
|
|
7030
|
+
window.addEventListener("blur", handleWindowBlur);
|
|
7031
|
+
window.addEventListener("keydown", handleKeyDown, true);
|
|
7032
|
+
}
|
|
7033
|
+
|
|
7034
|
+
return () => {
|
|
7035
|
+
if (attrObs) attrObs.disconnect();
|
|
7036
|
+
if (treeObs) treeObs.disconnect();
|
|
7037
|
+
if (typeof window !== "undefined" && typeof window.removeEventListener === "function") {
|
|
7038
|
+
window.removeEventListener("scroll", handleScroll);
|
|
7039
|
+
window.removeEventListener("blur", handleWindowBlur);
|
|
7040
|
+
window.removeEventListener("keydown", handleKeyDown, true);
|
|
7041
|
+
}
|
|
7042
|
+
};
|
|
7043
|
+
}, [activeTooltip && activeTooltip.target, dismissTooltip]);
|
|
7044
|
+
|
|
7045
|
+
useEffect(() => () => {
|
|
7046
|
+
if (tipTimerRef.current) clearTimeout(tipTimerRef.current);
|
|
7047
|
+
}, []);
|
|
7048
|
+
|
|
7049
|
+
const stateSeqRef = useRef(0);
|
|
7050
|
+
const mountedRef = useRef(true);
|
|
7051
|
+
useEffect(() => {
|
|
7052
|
+
mountedRef.current = true;
|
|
7053
|
+
return () => {
|
|
7054
|
+
mountedRef.current = false;
|
|
7055
|
+
};
|
|
7056
|
+
}, []);
|
|
7057
|
+
|
|
7058
|
+
const refreshState = useCallback(async ({ quiet = false, signal } = {}) => {
|
|
7059
|
+
const seq = ++stateSeqRef.current;
|
|
7060
|
+
try {
|
|
7061
|
+
const res = await api("/state", signal ? { signal } : undefined);
|
|
7062
|
+
if (mountedRef.current && !signal?.aborted && seq === stateSeqRef.current) {
|
|
7063
|
+
setState(res);
|
|
7064
|
+
if (typeof document !== "undefined") document.dispatchEvent(new Event("uph-at-plugins-changed"));
|
|
7065
|
+
}
|
|
7066
|
+
return res;
|
|
7067
|
+
} catch (e) {
|
|
7068
|
+
if (!quiet && mountedRef.current) showToast("加载状态失败", e.message, { restart: false });
|
|
7069
|
+
return null;
|
|
7070
|
+
}
|
|
7071
|
+
}, [showToast]);
|
|
7072
|
+
|
|
7073
|
+
const patchPluginInState = useCallback((updatedPlugin) => {
|
|
7074
|
+
if (!updatedPlugin || !updatedPlugin.name) return;
|
|
7075
|
+
const pluginName = updatedPlugin.name;
|
|
7076
|
+
stateSeqRef.current += 1;
|
|
7077
|
+
setState((prev) => ({
|
|
7078
|
+
...prev,
|
|
7079
|
+
plugins: Array.isArray(prev.plugins)
|
|
7080
|
+
? prev.plugins.map((p) => (p.name === pluginName ? updatedPlugin : p))
|
|
7081
|
+
: prev.plugins,
|
|
7082
|
+
}));
|
|
7083
|
+
if (typeof document !== "undefined") document.dispatchEvent(new Event("uph-at-plugins-changed"));
|
|
7084
|
+
}, []);
|
|
7085
|
+
|
|
7086
|
+
const hasPendingConnectors = (state.plugins || []).some(plugin =>
|
|
7087
|
+
plugin.enabled !== false && plugin.connectors?.some(connector => connector.pending));
|
|
7088
|
+
useEffect(() => {
|
|
7089
|
+
if (!hasPendingConnectors) return;
|
|
7090
|
+
const controller = new AbortController();
|
|
7091
|
+
let delay = 250;
|
|
7092
|
+
const refreshPending = async () => {
|
|
7093
|
+
await refreshState({ quiet: true, signal: controller.signal });
|
|
7094
|
+
if (controller.signal.aborted) return;
|
|
7095
|
+
delay = Math.min(delay * 2, 3000);
|
|
7096
|
+
timer = setTimeout(refreshPending, delay);
|
|
7097
|
+
};
|
|
7098
|
+
let timer = setTimeout(refreshPending, delay);
|
|
7099
|
+
return () => {
|
|
7100
|
+
controller.abort();
|
|
7101
|
+
clearTimeout(timer);
|
|
7102
|
+
};
|
|
7103
|
+
}, [hasPendingConnectors, refreshState]);
|
|
6319
7104
|
|
|
6320
7105
|
useEffect(() => {
|
|
6321
7106
|
refreshState();
|
|
6322
7107
|
}, [refreshState]);
|
|
6323
7108
|
|
|
6324
7109
|
// Read cached catalogs immediately, then update Git sources in the background.
|
|
6325
|
-
const
|
|
7110
|
+
const addedGitSourceIds = useRef(new Set());
|
|
7111
|
+
// Markets added in this panel already returned their catalog. Keep them
|
|
7112
|
+
// out of the startup refresh, which also pulls Git.
|
|
7113
|
+
const sourcesToWarm = (state.sources || []).filter((source) => !source.virtual && !addedGitSourceIds.current.has(source.id));
|
|
7114
|
+
const sourceIdsKey = sourcesToWarm.map((s) => s.id).sort().join(",");
|
|
6326
7115
|
useEffect(() => {
|
|
6327
|
-
if (
|
|
7116
|
+
if (sourcesToWarm.length === 0) return;
|
|
6328
7117
|
let isMounted = true;
|
|
6329
7118
|
(async () => {
|
|
6330
|
-
await Promise.allSettled(
|
|
6331
|
-
if (s.virtual) return;
|
|
7119
|
+
await Promise.allSettled(sourcesToWarm.map(async (s) => {
|
|
6332
7120
|
try {
|
|
6333
7121
|
const res = await api("/market?sourceId=" + encodeURIComponent(s.id));
|
|
6334
7122
|
if (isMounted && Array.isArray(res?.plugins)) setRows((prev) => ({ ...(prev || {}), [s.id]: res.plugins }));
|
|
6335
7123
|
} catch {}
|
|
6336
7124
|
}));
|
|
6337
|
-
for (const s of
|
|
7125
|
+
for (const s of sourcesToWarm) {
|
|
6338
7126
|
if (!isMounted) break;
|
|
6339
|
-
if (s.id === "local"
|
|
7127
|
+
if (s.id === "local") continue;
|
|
6340
7128
|
try {
|
|
6341
7129
|
const res = await api("/market/refresh", {
|
|
6342
7130
|
method: "POST",
|
|
@@ -6379,8 +7167,13 @@ window.__ModuleLoader__.load({ id: "universal-plugin-hub", factory: (require) =>
|
|
|
6379
7167
|
return h("div", {
|
|
6380
7168
|
ref: rootRef,
|
|
6381
7169
|
className: "cpm-root" + (isDark ? " cpm-dark" : ""),
|
|
7170
|
+
onPointerOverCapture: handleRootPointerOverCapture,
|
|
7171
|
+
onPointerDownCapture: handleRootPointerDownCapture,
|
|
7172
|
+
onScrollCapture: handleRootScrollCapture,
|
|
6382
7173
|
onMouseOver: handleRootMouseOver,
|
|
6383
7174
|
onMouseOut: handleRootMouseOut,
|
|
7175
|
+
onFocus: handleRootFocus,
|
|
7176
|
+
onBlur: handleRootBlur,
|
|
6384
7177
|
},
|
|
6385
7178
|
h(BrowseView, {
|
|
6386
7179
|
view,
|
|
@@ -6388,6 +7181,7 @@ window.__ModuleLoader__.load({ id: "universal-plugin-hub", factory: (require) =>
|
|
|
6388
7181
|
state,
|
|
6389
7182
|
setState,
|
|
6390
7183
|
refreshState,
|
|
7184
|
+
patchPluginInState,
|
|
6391
7185
|
showToast,
|
|
6392
7186
|
openManage,
|
|
6393
7187
|
onInstalled,
|
|
@@ -6402,6 +7196,7 @@ window.__ModuleLoader__.load({ id: "universal-plugin-hub", factory: (require) =>
|
|
|
6402
7196
|
setActiveSourceId,
|
|
6403
7197
|
rows,
|
|
6404
7198
|
setRows,
|
|
7199
|
+
addedGitSourceIds,
|
|
6405
7200
|
scrollTopRef,
|
|
6406
7201
|
}),
|
|
6407
7202
|
toast && h("div", {
|
|
@@ -6415,7 +7210,7 @@ window.__ModuleLoader__.load({ id: "universal-plugin-hub", factory: (require) =>
|
|
|
6415
7210
|
toast.body && h("div", { className: "cpm-toast-body" }, toast.body),
|
|
6416
7211
|
),
|
|
6417
7212
|
),
|
|
6418
|
-
activeTooltip && h(CustomTooltip, {
|
|
7213
|
+
(tipMounted || activeTooltip) && h(CustomTooltip, { tooltip: activeTooltip, isDark }),
|
|
6419
7214
|
);
|
|
6420
7215
|
}
|
|
6421
7216
|
|
|
@@ -7080,6 +7875,7 @@ window.__ModuleLoader__.load({ id: "universal-plugin-hub", factory: (require) =>
|
|
|
7080
7875
|
state,
|
|
7081
7876
|
setState,
|
|
7082
7877
|
refreshState,
|
|
7878
|
+
patchPluginInState,
|
|
7083
7879
|
showToast,
|
|
7084
7880
|
openManage: openManageView,
|
|
7085
7881
|
onInstalled,
|
|
@@ -7094,6 +7890,7 @@ window.__ModuleLoader__.load({ id: "universal-plugin-hub", factory: (require) =>
|
|
|
7094
7890
|
setActiveSourceId,
|
|
7095
7891
|
rows,
|
|
7096
7892
|
setRows,
|
|
7893
|
+
addedGitSourceIds,
|
|
7097
7894
|
scrollTopRef,
|
|
7098
7895
|
}) {
|
|
7099
7896
|
const [showFilter, setShowFilter] = useState(false);
|
|
@@ -7211,7 +8008,7 @@ window.__ModuleLoader__.load({ id: "universal-plugin-hub", factory: (require) =>
|
|
|
7211
8008
|
}, []);
|
|
7212
8009
|
|
|
7213
8010
|
useAutoMcpTools([
|
|
7214
|
-
...pluginMcpRows.map(row => ({ owner: row.owner, name: row.name, connected: row.conn.enabled === true, revision: JSON.stringify([row.record.installedAt, row.conn]) })),
|
|
8011
|
+
...pluginMcpRows.map(row => ({ owner: row.owner, name: row.name, connected: row.conn.enabled === true && !row.conn.pending, revision: JSON.stringify([row.record.installedAt, row.conn]) })),
|
|
7215
8012
|
...mcps.map(row => ({ owner: "user-mcp", name: row.name, connected: row.enabled === true, revision: JSON.stringify(row) })),
|
|
7216
8013
|
], loadGlobalTools);
|
|
7217
8014
|
|
|
@@ -7282,7 +8079,12 @@ window.__ModuleLoader__.load({ id: "universal-plugin-hub", factory: (require) =>
|
|
|
7282
8079
|
return;
|
|
7283
8080
|
}
|
|
7284
8081
|
if (canEdit) await refreshMcps();
|
|
7285
|
-
else
|
|
8082
|
+
else if (res?.plugin && patchPluginInState) {
|
|
8083
|
+
patchPluginInState(res.plugin);
|
|
8084
|
+
void refreshState();
|
|
8085
|
+
} else {
|
|
8086
|
+
await refreshState();
|
|
8087
|
+
}
|
|
7286
8088
|
} catch (err) {
|
|
7287
8089
|
setOptimisticMcp(prev => { const n = { ...prev }; delete n[key]; return n; });
|
|
7288
8090
|
showToast("操作失败", cleanError(err), { restart: false });
|
|
@@ -8506,19 +9308,16 @@ window.__ModuleLoader__.load({ id: "universal-plugin-hub", factory: (require) =>
|
|
|
8506
9308
|
return () => { alive = false; };
|
|
8507
9309
|
}, [view]);
|
|
8508
9310
|
|
|
8509
|
-
|
|
8510
|
-
if (
|
|
8511
|
-
|
|
8512
|
-
|
|
8513
|
-
|
|
8514
|
-
|
|
8515
|
-
|
|
8516
|
-
|
|
8517
|
-
|
|
8518
|
-
|
|
8519
|
-
window.addEventListener("keydown", onKey);
|
|
8520
|
-
return () => window.removeEventListener("keydown", onKey);
|
|
8521
|
-
}, [installFor, addDialog, confirmRemoveSource, mcpDialog]);
|
|
9311
|
+
useDialogEscape(!!(installFor || addDialog || confirmRemoveSource || mcpDialog), () => {
|
|
9312
|
+
if (installFor) setInstallFor(null);
|
|
9313
|
+
if (addDialog && !addDialogBusyRef.current) setAddDialog(false);
|
|
9314
|
+
if (confirmRemoveSource) setConfirmRemoveSource(null);
|
|
9315
|
+
if (mcpDialog) {
|
|
9316
|
+
setMcpDialog(false);
|
|
9317
|
+
setEditMcp(null);
|
|
9318
|
+
setEditMcpOwner(null);
|
|
9319
|
+
}
|
|
9320
|
+
});
|
|
8522
9321
|
|
|
8523
9322
|
const removePlugin = async (pluginName) => {
|
|
8524
9323
|
try {
|
|
@@ -8528,6 +9327,7 @@ window.__ModuleLoader__.load({ id: "universal-plugin-hub", factory: (require) =>
|
|
|
8528
9327
|
showToast("卸载失败", result.error || "卸载未能完成,请稍后重试", { restart: false });
|
|
8529
9328
|
return;
|
|
8530
9329
|
}
|
|
9330
|
+
clearMcpToolsCache((k) => k.startsWith(`${pluginName}::`));
|
|
8531
9331
|
void showApplicationToast(showToast, result, "已卸载插件", "插件副本与技能注册已实时移除并生效。");
|
|
8532
9332
|
setView({ type: "browse", sourceId: activeSourceId });
|
|
8533
9333
|
await refreshState();
|
|
@@ -8897,14 +9697,19 @@ window.__ModuleLoader__.load({ id: "universal-plugin-hub", factory: (require) =>
|
|
|
8897
9697
|
method: "POST",
|
|
8898
9698
|
body: JSON.stringify({ enabled }),
|
|
8899
9699
|
});
|
|
8900
|
-
|
|
9700
|
+
if (res?.ok !== false && res?.plugin && patchPluginInState) {
|
|
9701
|
+
patchPluginInState(res.plugin);
|
|
9702
|
+
void refreshState();
|
|
9703
|
+
} else {
|
|
9704
|
+
await refreshState();
|
|
9705
|
+
}
|
|
8901
9706
|
return res;
|
|
8902
9707
|
},
|
|
8903
9708
|
showToast,
|
|
8904
9709
|
}),
|
|
8905
9710
|
!mcpsOpen && view.type === "manage" && h(ManagePage, {
|
|
8906
9711
|
key: view.pluginName || manageRecord?.name,
|
|
8907
|
-
record: manageRecord || null, state, rows, isDark, refreshState, showToast,
|
|
9712
|
+
record: manageRecord || null, state, rows, isDark, refreshState, patchPluginInState, showToast,
|
|
8908
9713
|
containerRef: detailContainerRef,
|
|
8909
9714
|
initialTab: view.initialTab, initialConnector: view.initialConnector,
|
|
8910
9715
|
scrollState: view,
|
|
@@ -9073,8 +9878,18 @@ window.__ModuleLoader__.load({ id: "universal-plugin-hub", factory: (require) =>
|
|
|
9073
9878
|
initialPhase: addDialog.initialPhase,
|
|
9074
9879
|
onBusyChange: (v) => { addDialogBusyRef.current = !!v; },
|
|
9075
9880
|
onCancel: () => { if (!addDialogBusyRef.current) setAddDialog(false); },
|
|
9076
|
-
onAdded: async (newSourceId, keepOpen) => {
|
|
9881
|
+
onAdded: async (newSourceId, keepOpen, market) => {
|
|
9077
9882
|
if (!keepOpen) setAddDialog(false);
|
|
9883
|
+
if (newSourceId && market?.source?.id === newSourceId && Array.isArray(market.plugins)) {
|
|
9884
|
+
addedGitSourceIds.current.add(newSourceId);
|
|
9885
|
+
(SESSION_STORE.checkedCatalogs ||= new Set()).add(newSourceId);
|
|
9886
|
+
setRows((prev) => ({ ...prev, [newSourceId]: market.plugins }));
|
|
9887
|
+
setState((prev) => prev.sources.some((source) => source.id === newSourceId)
|
|
9888
|
+
? prev : { ...prev, sources: [...prev.sources, market.source] });
|
|
9889
|
+
if (newSourceId !== activeSourceId) setActiveSourceId(newSourceId);
|
|
9890
|
+
void refreshState({ quiet: true });
|
|
9891
|
+
return;
|
|
9892
|
+
}
|
|
9078
9893
|
await refreshState();
|
|
9079
9894
|
// The tab list and the rows both come from the server state.
|
|
9080
9895
|
if (newSourceId) {
|
|
@@ -9122,68 +9937,62 @@ window.__ModuleLoader__.load({ id: "universal-plugin-hub", factory: (require) =>
|
|
|
9122
9937
|
}),
|
|
9123
9938
|
|
|
9124
9939
|
confirmRemoveSource && h("div", { className: "cpm-dialog", ...backdropDismissProps(() => setConfirmRemoveSource(null)) },
|
|
9125
|
-
h(
|
|
9126
|
-
|
|
9127
|
-
|
|
9128
|
-
|
|
9129
|
-
|
|
9130
|
-
|
|
9131
|
-
|
|
9132
|
-
|
|
9133
|
-
|
|
9134
|
-
|
|
9135
|
-
|
|
9136
|
-
|
|
9137
|
-
|
|
9138
|
-
|
|
9139
|
-
|
|
9140
|
-
|
|
9141
|
-
|
|
9142
|
-
|
|
9143
|
-
|
|
9144
|
-
|
|
9145
|
-
|
|
9146
|
-
|
|
9147
|
-
|
|
9148
|
-
|
|
9149
|
-
|
|
9150
|
-
|
|
9151
|
-
|
|
9152
|
-
|
|
9153
|
-
|
|
9154
|
-
|
|
9155
|
-
|
|
9156
|
-
|
|
9157
|
-
|
|
9158
|
-
|
|
9159
|
-
|
|
9160
|
-
SESSION_STORE.filter = "all";
|
|
9161
|
-
setFilterRaw("all");
|
|
9162
|
-
const emptyView = { type: "browse" };
|
|
9163
|
-
SESSION_STORE.view = emptyView;
|
|
9164
|
-
setViewRaw(emptyView);
|
|
9165
|
-
}
|
|
9166
|
-
}
|
|
9167
|
-
for (const mapKey of ["sourceViews", "scrollTops", "sourceFilters", "browseSortSnapshots"]) {
|
|
9168
|
-
if (SESSION_STORE[mapKey]) delete SESSION_STORE[mapKey][toRemove.id];
|
|
9169
|
-
}
|
|
9170
|
-
if (SESSION_STORE.checkedCatalogs) SESSION_STORE.checkedCatalogs.delete(toRemove.id);
|
|
9171
|
-
savedTabScrolls.delete(toRemove.id);
|
|
9172
|
-
if (tabRefs?.current) delete tabRefs.current[toRemove.id];
|
|
9173
|
-
setRows((prev) => omitSourceKey(prev, toRemove.id));
|
|
9174
|
-
syncCachedStore("rows", STORAGE_KEY_ROWS, rows, (prev) => omitSourceKey(prev, toRemove.id));
|
|
9175
|
-
setState((prev) => stripDeletedSource(prev, toRemove.id));
|
|
9176
|
-
syncCachedStore("state", STORAGE_KEY_STATE, state, (prev) => stripDeletedSource(prev, toRemove.id));
|
|
9177
|
-
try { await refreshState(); } catch {}
|
|
9178
|
-
} catch (e) {
|
|
9179
|
-
showToast("删除失败", cleanError(e), { restart: false });
|
|
9180
|
-
} finally {
|
|
9181
|
-
setBusy(null);
|
|
9940
|
+
h(ConfirmDialogBox, {
|
|
9941
|
+
titleId: "cpm-confirm-remove-source-title",
|
|
9942
|
+
title: `删除插件源「${confirmRemoveSource.name}」`,
|
|
9943
|
+
description: "将从插件市场中移除该源及其分类标签。如需再次使用,可随时通过右上角「+」重新添加。",
|
|
9944
|
+
confirmLabel: "确认删除",
|
|
9945
|
+
confirmBusyLabel: "删除中…",
|
|
9946
|
+
confirmStyle: { background: "#dc2626", borderColor: "#dc2626", color: "#fff" },
|
|
9947
|
+
busy: !!busy,
|
|
9948
|
+
onCancel: () => setConfirmRemoveSource(null),
|
|
9949
|
+
onConfirm: async () => {
|
|
9950
|
+
const toRemove = confirmRemoveSource;
|
|
9951
|
+
setConfirmRemoveSource(null);
|
|
9952
|
+
setBusy("正在删除插件源…");
|
|
9953
|
+
try {
|
|
9954
|
+
await api("/sources/" + encodeURIComponent(toRemove.id), { method: "DELETE" });
|
|
9955
|
+
showToast("插件源已删除", `已移除分类「${toRemove.name}」`, { restart: false });
|
|
9956
|
+
invalidateSourceDetailCache(toRemove.id);
|
|
9957
|
+
const currentSources = Array.isArray(SESSION_STORE.state?.sources)
|
|
9958
|
+
? SESSION_STORE.state.sources
|
|
9959
|
+
: (Array.isArray(state?.sources) ? state.sources : []);
|
|
9960
|
+
const remainingSources = currentSources.filter((s) => s && s.id !== toRemove.id);
|
|
9961
|
+
const fallbackSourceId = remainingSources.some((s) => s.id === "anthropic")
|
|
9962
|
+
? "anthropic"
|
|
9963
|
+
: (remainingSources.find((s) => s.id !== "local" || hasLocalPlugins) || remainingSources[0])?.id;
|
|
9964
|
+
if (SESSION_STORE.activeSourceId === toRemove.id || activeSourceId === toRemove.id) {
|
|
9965
|
+
if (fallbackSourceId) {
|
|
9966
|
+
setActiveSourceId(fallbackSourceId, SESSION_STORE.sourceFilters?.[fallbackSourceId] || "all");
|
|
9967
|
+
} else {
|
|
9968
|
+
SESSION_STORE.activeSourceId = "";
|
|
9969
|
+
setActiveSourceIdRaw("");
|
|
9970
|
+
SESSION_STORE.filter = "all";
|
|
9971
|
+
setFilterRaw("all");
|
|
9972
|
+
const emptyView = { type: "browse" };
|
|
9973
|
+
SESSION_STORE.view = emptyView;
|
|
9974
|
+
setViewRaw(emptyView);
|
|
9182
9975
|
}
|
|
9183
|
-
}
|
|
9184
|
-
|
|
9185
|
-
|
|
9186
|
-
|
|
9976
|
+
}
|
|
9977
|
+
for (const mapKey of ["sourceViews", "scrollTops", "sourceFilters", "browseSortSnapshots"]) {
|
|
9978
|
+
if (SESSION_STORE[mapKey]) delete SESSION_STORE[mapKey][toRemove.id];
|
|
9979
|
+
}
|
|
9980
|
+
if (SESSION_STORE.checkedCatalogs) SESSION_STORE.checkedCatalogs.delete(toRemove.id);
|
|
9981
|
+
addedGitSourceIds.current.delete(toRemove.id);
|
|
9982
|
+
savedTabScrolls.delete(toRemove.id);
|
|
9983
|
+
if (tabRefs?.current) delete tabRefs.current[toRemove.id];
|
|
9984
|
+
setRows((prev) => omitSourceKey(prev, toRemove.id));
|
|
9985
|
+
syncCachedStore("rows", STORAGE_KEY_ROWS, rows, (prev) => omitSourceKey(prev, toRemove.id));
|
|
9986
|
+
setState((prev) => stripDeletedSource(prev, toRemove.id));
|
|
9987
|
+
syncCachedStore("state", STORAGE_KEY_STATE, state, (prev) => stripDeletedSource(prev, toRemove.id));
|
|
9988
|
+
try { await refreshState(); } catch {}
|
|
9989
|
+
} catch (e) {
|
|
9990
|
+
showToast("删除失败", cleanError(e), { restart: false });
|
|
9991
|
+
} finally {
|
|
9992
|
+
setBusy(null);
|
|
9993
|
+
}
|
|
9994
|
+
},
|
|
9995
|
+
}),
|
|
9187
9996
|
),
|
|
9188
9997
|
|
|
9189
9998
|
// ────────────────────────────── Modern Floating Drag Overlay (Zero Container Clipping) ──────────────────────────────
|
|
@@ -9220,15 +10029,82 @@ window.__ModuleLoader__.load({ id: "universal-plugin-hub", factory: (require) =>
|
|
|
9220
10029
|
};
|
|
9221
10030
|
}
|
|
9222
10031
|
|
|
10032
|
+
function useDialogEscape(open, onDismiss, capture = false) {
|
|
10033
|
+
const onDismissRef = useRef(onDismiss);
|
|
10034
|
+
onDismissRef.current = onDismiss;
|
|
10035
|
+
useEffect(() => {
|
|
10036
|
+
if (!open) return undefined;
|
|
10037
|
+
const onKey = (e) => {
|
|
10038
|
+
if (e.key !== "Escape") return;
|
|
10039
|
+
if (capture) {
|
|
10040
|
+
e.stopPropagation();
|
|
10041
|
+
e.preventDefault();
|
|
10042
|
+
}
|
|
10043
|
+
onDismissRef.current?.(e);
|
|
10044
|
+
};
|
|
10045
|
+
window.addEventListener("keydown", onKey, capture);
|
|
10046
|
+
return () => window.removeEventListener("keydown", onKey, capture);
|
|
10047
|
+
}, [open, capture]);
|
|
10048
|
+
}
|
|
10049
|
+
|
|
10050
|
+
function ConfirmDialogBox({
|
|
10051
|
+
titleId,
|
|
10052
|
+
title,
|
|
10053
|
+
description,
|
|
10054
|
+
descriptionStyle,
|
|
10055
|
+
cancelLabel = "取消",
|
|
10056
|
+
confirmLabel,
|
|
10057
|
+
confirmBusyLabel,
|
|
10058
|
+
confirmStyle,
|
|
10059
|
+
busy = false,
|
|
10060
|
+
cancelDisabled = false,
|
|
10061
|
+
onCancel,
|
|
10062
|
+
onConfirm,
|
|
10063
|
+
}) {
|
|
10064
|
+
return h("div", {
|
|
10065
|
+
className: "cpm-dialog-box",
|
|
10066
|
+
role: "dialog",
|
|
10067
|
+
"aria-modal": "true",
|
|
10068
|
+
"aria-labelledby": titleId,
|
|
10069
|
+
onClick: (e) => e.stopPropagation(),
|
|
10070
|
+
},
|
|
10071
|
+
h("div", { id: titleId, className: "cpm-dialog-title" }, title),
|
|
10072
|
+
description && h("div", {
|
|
10073
|
+
className: "cpm-field",
|
|
10074
|
+
style: descriptionStyle || { fontSize: 13, lineHeight: 1.6, color: "var(--cpm-muted)" },
|
|
10075
|
+
}, description),
|
|
10076
|
+
h("div", { className: "cpm-dialog-actions" },
|
|
10077
|
+
h("button", {
|
|
10078
|
+
className: "cpm-btn cpm-btn-secondary",
|
|
10079
|
+
disabled: !!cancelDisabled,
|
|
10080
|
+
onClick: onCancel,
|
|
10081
|
+
}, cancelLabel),
|
|
10082
|
+
h("button", {
|
|
10083
|
+
className: "cpm-btn cpm-btn-primary",
|
|
10084
|
+
style: confirmStyle,
|
|
10085
|
+
disabled: !!busy,
|
|
10086
|
+
onClick: onConfirm,
|
|
10087
|
+
}, busy && confirmBusyLabel ? confirmBusyLabel : confirmLabel),
|
|
10088
|
+
),
|
|
10089
|
+
);
|
|
10090
|
+
}
|
|
10091
|
+
|
|
9223
10092
|
// ────────────────────────────── Modern Install Dialog ──────────────────────────────
|
|
9224
10093
|
function InstallDialog({ plugin, isDark, onCancel, onConfirm }) {
|
|
9225
10094
|
const [busy, setBusy] = useState(false);
|
|
10095
|
+
const titleId = "cpm-install-dialog-title";
|
|
9226
10096
|
return h("div", { className: "cpm-dialog", ...backdropDismissProps(onCancel) },
|
|
9227
|
-
h("div", {
|
|
10097
|
+
h("div", {
|
|
10098
|
+
className: "cpm-dialog-box cpm-install-dialog",
|
|
10099
|
+
role: "dialog",
|
|
10100
|
+
"aria-modal": "true",
|
|
10101
|
+
"aria-labelledby": titleId,
|
|
10102
|
+
onClick: (e) => e.stopPropagation(),
|
|
10103
|
+
},
|
|
9228
10104
|
h("div", { className: "cpm-install-dialog-header" },
|
|
9229
10105
|
h(PluginIcon, { plugin, isDark }),
|
|
9230
10106
|
h("div", { className: "cpm-install-dialog-header-info" },
|
|
9231
|
-
h("div", { className: "cpm-install-dialog-title" }, `安装 ${plugin.displayName || plugin.name}`),
|
|
10107
|
+
h("div", { id: titleId, className: "cpm-install-dialog-title" }, `安装 ${plugin.displayName || plugin.name}`),
|
|
9232
10108
|
plugin.author && h("div", { className: "cpm-install-dialog-sub" }, `by ${plugin.author}`),
|
|
9233
10109
|
),
|
|
9234
10110
|
),
|
|
@@ -9808,65 +10684,6 @@ window.__ModuleLoader__.load({ id: "universal-plugin-hub", factory: (require) =>
|
|
|
9808
10684
|
return s.replace(/^https?:\/\//i, "").replace(/\.git$/i, "");
|
|
9809
10685
|
};
|
|
9810
10686
|
|
|
9811
|
-
const computeSmartSuggestedName = (rawInput, serverSuggested) => {
|
|
9812
|
-
const s = String(rawInput || "").trim().replace(/^['"]|['"]$/g, "");
|
|
9813
|
-
let owner = "";
|
|
9814
|
-
let repo = "";
|
|
9815
|
-
const sshMatch = s.match(/^git@[^:]+:([^/]+)\/(.+?)(\.git)?$/);
|
|
9816
|
-
if (sshMatch) {
|
|
9817
|
-
owner = sshMatch[1];
|
|
9818
|
-
repo = sshMatch[2];
|
|
9819
|
-
} else {
|
|
9820
|
-
const httpMatch = s.match(/^https?:\/\/[^/]+\/([^/]+)\/([^/]+?)(\.git)?$/i);
|
|
9821
|
-
if (httpMatch) {
|
|
9822
|
-
owner = httpMatch[1];
|
|
9823
|
-
repo = httpMatch[2];
|
|
9824
|
-
} else {
|
|
9825
|
-
const shortMatch = s.match(/^([a-zA-Z0-9._-]+)\/([a-zA-Z0-9._-]+?)(\.git)?$/);
|
|
9826
|
-
if (shortMatch) {
|
|
9827
|
-
owner = shortMatch[1];
|
|
9828
|
-
repo = shortMatch[2];
|
|
9829
|
-
} else {
|
|
9830
|
-
repo = s.replace(/^https?:\/\//i, "").replace(/\.git$/i, "").split("/").pop() || "";
|
|
9831
|
-
}
|
|
9832
|
-
}
|
|
9833
|
-
}
|
|
9834
|
-
|
|
9835
|
-
const ownerLower = (owner || "").toLowerCase();
|
|
9836
|
-
const repoLower = (repo || "").toLowerCase();
|
|
9837
|
-
|
|
9838
|
-
if (repoLower === "claude-plugins-official") return "Anthropic";
|
|
9839
|
-
if (repoLower === "claude-plugins-community") return "Community";
|
|
9840
|
-
|
|
9841
|
-
const genericWords = new Set([
|
|
9842
|
-
"skills", "skill", "plugins", "plugin", "agents", "agent", "tools", "tool",
|
|
9843
|
-
"marketplace", "hub", "claude-skills", "claude-plugins", "claude-agents",
|
|
9844
|
-
"dsh-plugins", "extensions", "packages", "repo", "repository", "custom"
|
|
9845
|
-
]);
|
|
9846
|
-
|
|
9847
|
-
if (serverSuggested && !genericWords.has(serverSuggested.toLowerCase())) {
|
|
9848
|
-
return serverSuggested;
|
|
9849
|
-
}
|
|
9850
|
-
|
|
9851
|
-
if (genericWords.has(repoLower) && owner) {
|
|
9852
|
-
return owner.charAt(0).toUpperCase() + owner.slice(1);
|
|
9853
|
-
}
|
|
9854
|
-
|
|
9855
|
-
const simplified = repo
|
|
9856
|
-
.replace(/^(claude|dsh|anthropic)[-_]?(plugins?)?[-_]?/i, "")
|
|
9857
|
-
.replace(/[-_]?(plugins?|skills?|agents?|official|marketplace)$/i, "");
|
|
9858
|
-
|
|
9859
|
-
const clean = simplified || repo;
|
|
9860
|
-
if (genericWords.has(clean.toLowerCase()) && owner) {
|
|
9861
|
-
return owner.charAt(0).toUpperCase() + owner.slice(1);
|
|
9862
|
-
}
|
|
9863
|
-
|
|
9864
|
-
if (clean) {
|
|
9865
|
-
return clean.charAt(0).toUpperCase() + clean.slice(1);
|
|
9866
|
-
}
|
|
9867
|
-
return serverSuggested || "Custom";
|
|
9868
|
-
};
|
|
9869
|
-
|
|
9870
10687
|
const cleanError = (err) => {
|
|
9871
10688
|
if (!err) return "操作失败";
|
|
9872
10689
|
let msg = String(err.message || err).replace(/^Error:\s*/i, "").trim();
|
|
@@ -9890,9 +10707,8 @@ window.__ModuleLoader__.load({ id: "universal-plugin-hub", factory: (require) =>
|
|
|
9890
10707
|
const body = await api("/sources/ensure", { method: "POST", body: JSON.stringify({ url: raw }) });
|
|
9891
10708
|
if (unmountedRef.current) return;
|
|
9892
10709
|
const finalRepoLabel = body.repoLabel || extractRepoLabel(raw);
|
|
9893
|
-
const finalSuggested = computeSmartSuggestedName(raw, body.suggestedName);
|
|
9894
10710
|
setRepoLabel(finalRepoLabel);
|
|
9895
|
-
setSuggested(
|
|
10711
|
+
setSuggested(body.suggestedName || finalRepoLabel.split("/").pop() || "Custom");
|
|
9896
10712
|
setCustomName("");
|
|
9897
10713
|
setMode("suggest");
|
|
9898
10714
|
setNormalizedUrl(body.normalizedUrl || raw);
|
|
@@ -9922,7 +10738,7 @@ window.__ModuleLoader__.load({ id: "universal-plugin-hub", factory: (require) =>
|
|
|
9922
10738
|
if (unmountedRef.current) return;
|
|
9923
10739
|
const count = res.pluginCount !== undefined ? res.pluginCount : pluginCount;
|
|
9924
10740
|
showToast("插件源已添加", `分类「${name}」已创建,成功导入 ${count} 个插件`, { restart: false });
|
|
9925
|
-
await onAdded(res.source?.id);
|
|
10741
|
+
await onAdded(res.source?.id, false, res);
|
|
9926
10742
|
} catch (e) {
|
|
9927
10743
|
if (unmountedRef.current) return;
|
|
9928
10744
|
showToast("添加源失败", cleanError(e), { restart: false });
|
|
@@ -9931,6 +10747,7 @@ window.__ModuleLoader__.load({ id: "universal-plugin-hub", factory: (require) =>
|
|
|
9931
10747
|
}
|
|
9932
10748
|
};
|
|
9933
10749
|
|
|
10750
|
+
const urlBusyLabel = isLocalPath(url) ? "正在解析…" : "正在安装…";
|
|
9934
10751
|
const inlineBusyProgress = () => busy && h("div", { className: "cpm-upload-inline-progress", key: "imp-prog" },
|
|
9935
10752
|
h("progress", { className: "cpm-upload-progress", "aria-label": "正在导入插件" }),
|
|
9936
10753
|
h("div", { className: "cpm-upload-status", role: "status", "aria-live": "polite", style: { marginTop: 0 } }, "正在导入文件,请勿关闭弹窗…"),
|
|
@@ -10108,7 +10925,7 @@ window.__ModuleLoader__.load({ id: "universal-plugin-hub", factory: (require) =>
|
|
|
10108
10925
|
),
|
|
10109
10926
|
h("div", { className: "cpm-dialog-actions", key: "a" },
|
|
10110
10927
|
h("button", { className: "cpm-btn cpm-btn-secondary", disabled: busy, onClick: onCancel }, "取消"),
|
|
10111
|
-
h("button", { className: "cpm-btn cpm-btn-primary", disabled: busy || !url.trim(), onClick: ensure }, busy ?
|
|
10928
|
+
h("button", { className: "cpm-btn cpm-btn-primary", disabled: busy || !url.trim(), onClick: ensure }, busy ? urlBusyLabel : "下一步"),
|
|
10112
10929
|
),
|
|
10113
10930
|
],
|
|
10114
10931
|
phase === "local-preview" && localPreview && localPreview.kind === "marketplace" && [
|
|
@@ -10149,7 +10966,7 @@ window.__ModuleLoader__.load({ id: "universal-plugin-hub", factory: (require) =>
|
|
|
10149
10966
|
value: "suggest",
|
|
10150
10967
|
selected: mode === "suggest",
|
|
10151
10968
|
onSelect: () => setMode("suggest"),
|
|
10152
|
-
title: "
|
|
10969
|
+
title: "使用推荐市场名",
|
|
10153
10970
|
desc: [
|
|
10154
10971
|
"分类标签名:",
|
|
10155
10972
|
// Only the market's own name: falling back to the local
|
|
@@ -10384,7 +11201,7 @@ window.__ModuleLoader__.load({ id: "universal-plugin-hub", factory: (require) =>
|
|
|
10384
11201
|
value: "suggest",
|
|
10385
11202
|
selected: mode === "suggest",
|
|
10386
11203
|
onSelect: () => setMode("suggest"),
|
|
10387
|
-
title: "
|
|
11204
|
+
title: "使用推荐市场名",
|
|
10388
11205
|
desc: ["分类标签名:", h("span", { className: "cpm-tag-preview", key: "tag" }, suggested)],
|
|
10389
11206
|
}),
|
|
10390
11207
|
renderChoiceCard({
|
|
@@ -10415,7 +11232,7 @@ window.__ModuleLoader__.load({ id: "universal-plugin-hub", factory: (require) =>
|
|
|
10415
11232
|
),
|
|
10416
11233
|
h("div", { className: "cpm-dialog-actions", key: "a" },
|
|
10417
11234
|
h("button", { className: "cpm-btn cpm-btn-secondary", type: "button", disabled: busy, onClick: () => setPhase("url") }, "上一步"),
|
|
10418
|
-
h("button", { className: "cpm-btn cpm-btn-primary", disabled: busy || (mode === "custom" && !customName.trim()), onClick: confirm }, busy ? "
|
|
11235
|
+
h("button", { className: "cpm-btn cpm-btn-primary", disabled: busy || (mode === "custom" && !customName.trim()), onClick: confirm }, busy ? "正在安装…" : "确认添加"),
|
|
10419
11236
|
),
|
|
10420
11237
|
],
|
|
10421
11238
|
),
|
|
@@ -10436,8 +11253,12 @@ window.__ModuleLoader__.load({ id: "universal-plugin-hub", factory: (require) =>
|
|
|
10436
11253
|
oauthScope: initial.oauthScope || "",
|
|
10437
11254
|
command: initial.command || "",
|
|
10438
11255
|
args: Array.isArray(initial.args) ? JSON.stringify(initial.args) : (initial.args || ""),
|
|
10439
|
-
headersList: Object.entries(initial.headers || {})
|
|
10440
|
-
|
|
11256
|
+
headersList: Object.entries(initial.headers || {})
|
|
11257
|
+
.filter(([, v]) => !hasUnresolvedVarPlaceholder(String(v ?? "")))
|
|
11258
|
+
.map(([k, v], i) => makeKvRow("header", `hi_${i}`, k, String(v))),
|
|
11259
|
+
envList: Object.entries(initial.env || {})
|
|
11260
|
+
.filter(([, v]) => !hasUnresolvedVarPlaceholder(String(v ?? "")))
|
|
11261
|
+
.map(([k, v], i) => makeKvRow("env", `ei_${i}`, k, String(v))),
|
|
10441
11262
|
} : { name: "", transport: "stdio", url: "", oauth: "none", oauthClientId: "", oauthClientSecret: "", oauthHasClientSecret: false, oauthCallbackPort: "", oauthScope: "", command: "", args: "", headersList: [], envList: [] });
|
|
10442
11263
|
const [oauthBaseline, setOauthBaseline] = useState(() => initial ? {
|
|
10443
11264
|
name: initial.name || "",
|
|
@@ -10456,17 +11277,7 @@ window.__ModuleLoader__.load({ id: "universal-plugin-hub", factory: (require) =>
|
|
|
10456
11277
|
// The confirmation renders inside this dialog, so it must handle Escape
|
|
10457
11278
|
// first: the outer handler would otherwise close the whole editor and
|
|
10458
11279
|
// discard the form behind it.
|
|
10459
|
-
|
|
10460
|
-
if (!confirmDelete) return;
|
|
10461
|
-
const onKey = (e) => {
|
|
10462
|
-
if (e.key !== "Escape") return;
|
|
10463
|
-
e.stopPropagation();
|
|
10464
|
-
e.preventDefault();
|
|
10465
|
-
setConfirmDelete(false);
|
|
10466
|
-
};
|
|
10467
|
-
window.addEventListener("keydown", onKey, true);
|
|
10468
|
-
return () => window.removeEventListener("keydown", onKey, true);
|
|
10469
|
-
}, [confirmDelete]);
|
|
11280
|
+
useDialogEscape(confirmDelete, () => setConfirmDelete(false), true);
|
|
10470
11281
|
const upd = (patch) => {
|
|
10471
11282
|
setForm((prev) => ({ ...prev, ...patch }));
|
|
10472
11283
|
setConnState((prev) => prev.status === "untested" ? prev : { status: "untested", statusMessage: "", lastResult: null });
|
|
@@ -10657,7 +11468,9 @@ window.__ModuleLoader__.load({ id: "universal-plugin-hub", factory: (require) =>
|
|
|
10657
11468
|
showToast("保存失败", res.error || "配置校验未通过,请检查填写内容", { restart: false });
|
|
10658
11469
|
return;
|
|
10659
11470
|
}
|
|
11471
|
+
clearMcpToolsCache(owner ? `${owner}::${data.name}` : `user-mcp::${data.name}`);
|
|
10660
11472
|
if (initial && data.previousName) {
|
|
11473
|
+
clearMcpToolsCache(`user-mcp::${data.previousName}`);
|
|
10661
11474
|
void showApplicationToast(showToast, res, "MCP 已重命名", `「${data.previousName}」已改名为「${data.name}」`);
|
|
10662
11475
|
} else {
|
|
10663
11476
|
void showApplicationToast(showToast, res, initial ? "MCP 已更新" : "MCP 已添加", `「${data.name}」已${initial ? "更新" : "注册为可用 MCP 服务"}`);
|
|
@@ -10674,11 +11487,7 @@ window.__ModuleLoader__.load({ id: "universal-plugin-hub", factory: (require) =>
|
|
|
10674
11487
|
setDeleting(true);
|
|
10675
11488
|
try {
|
|
10676
11489
|
const result = await api(`/mcps/${encodeURIComponent(initial.name)}`, { method: "DELETE" });
|
|
10677
|
-
|
|
10678
|
-
if (GLOBAL_MCP_TOOLS_CACHE[cacheKey]) {
|
|
10679
|
-
delete GLOBAL_MCP_TOOLS_CACHE[cacheKey];
|
|
10680
|
-
try { localStorage.setItem("cpm_mcp_tools_cache_v1", JSON.stringify(GLOBAL_MCP_TOOLS_CACHE)); } catch {}
|
|
10681
|
-
}
|
|
11490
|
+
clearMcpToolsCache(`user-mcp::${initial.name}`);
|
|
10682
11491
|
setConfirmDelete(false);
|
|
10683
11492
|
void showApplicationToast(showToast, result, "MCP 已删除", `「${initial.name}」已从服务器列表移除`);
|
|
10684
11493
|
await onSaved();
|
|
@@ -10689,7 +11498,13 @@ window.__ModuleLoader__.load({ id: "universal-plugin-hub", factory: (require) =>
|
|
|
10689
11498
|
};
|
|
10690
11499
|
|
|
10691
11500
|
return h("div", { className: "cpm-dialog" },
|
|
10692
|
-
h("div", {
|
|
11501
|
+
h("div", {
|
|
11502
|
+
className: "cpm-mcp-modal",
|
|
11503
|
+
role: "dialog",
|
|
11504
|
+
"aria-modal": "true",
|
|
11505
|
+
"aria-label": initial?.name ? `编辑 MCP「${initial.name}」` : "添加 MCP",
|
|
11506
|
+
onClick: (e) => e.stopPropagation(),
|
|
11507
|
+
},
|
|
10693
11508
|
h("button", { type: "button", className: "cpm-mcp-close-top", "aria-label": "关闭", onClick: onCancel }, h(IconClose, { size: 14 })),
|
|
10694
11509
|
h("div", { className: "cpm-mcp-body" },
|
|
10695
11510
|
h("div", { className: "cpm-mcp-row" },
|
|
@@ -10850,24 +11665,17 @@ window.__ModuleLoader__.load({ id: "universal-plugin-hub", factory: (require) =>
|
|
|
10850
11665
|
),
|
|
10851
11666
|
),
|
|
10852
11667
|
confirmDelete && h("div", { className: "cpm-dialog", ...backdropDismissProps(() => setConfirmDelete(false)) },
|
|
10853
|
-
h(
|
|
10854
|
-
|
|
10855
|
-
|
|
10856
|
-
|
|
10857
|
-
|
|
10858
|
-
|
|
10859
|
-
|
|
10860
|
-
|
|
10861
|
-
|
|
10862
|
-
|
|
10863
|
-
|
|
10864
|
-
className: "cpm-btn cpm-btn-primary",
|
|
10865
|
-
style: { background: "#dc2626", borderColor: "#dc2626", color: "#fff" },
|
|
10866
|
-
disabled: deleting,
|
|
10867
|
-
onClick: removeMcp,
|
|
10868
|
-
}, deleting ? "删除中…" : "确认删除"),
|
|
10869
|
-
),
|
|
10870
|
-
),
|
|
11668
|
+
h(ConfirmDialogBox, {
|
|
11669
|
+
titleId: "cpm-confirm-delete-mcp-title",
|
|
11670
|
+
title: `删除 MCP「${initial.name}」`,
|
|
11671
|
+
description: "将移除它的连接配置、已保存的授权和工具开关记录。如需再次使用,可在「添加」里重新配置。",
|
|
11672
|
+
confirmLabel: "确认删除",
|
|
11673
|
+
confirmBusyLabel: "删除中…",
|
|
11674
|
+
confirmStyle: { background: "#dc2626", borderColor: "#dc2626", color: "#fff" },
|
|
11675
|
+
busy: deleting,
|
|
11676
|
+
onCancel: () => setConfirmDelete(false),
|
|
11677
|
+
onConfirm: removeMcp,
|
|
11678
|
+
}),
|
|
10871
11679
|
),
|
|
10872
11680
|
);
|
|
10873
11681
|
}
|
|
@@ -10997,6 +11805,7 @@ window.__ModuleLoader__.load({ id: "universal-plugin-hub", factory: (require) =>
|
|
|
10997
11805
|
const [optimisticEnabled, setOptimisticEnabled] = useState(null);
|
|
10998
11806
|
const { detailRef, maskClass: detailMaskClass, updateMask: updateDetailMask } = useDetailScrollMask(plugin?.name, containerRef, plugin, scrollState);
|
|
10999
11807
|
useEffect(() => { setOptimisticEnabled(null); }, [plugin?.name]);
|
|
11808
|
+
useDialogEscape(confirmRemove, () => { if (!busy) setConfirmRemove(false); });
|
|
11000
11809
|
|
|
11001
11810
|
if (!plugin) return null;
|
|
11002
11811
|
const dark = typeof isDark === "boolean" ? isDark : (typeof isDarkMode === "function" ? isDarkMode() : false);
|
|
@@ -11219,28 +12028,28 @@ window.__ModuleLoader__.load({ id: "universal-plugin-hub", factory: (require) =>
|
|
|
11219
12028
|
),
|
|
11220
12029
|
|
|
11221
12030
|
confirmRemove && h("div", { className: "cpm-dialog", ...backdropDismissProps(() => { if (!busy) setConfirmRemove(false); }) },
|
|
11222
|
-
h(
|
|
11223
|
-
|
|
11224
|
-
|
|
11225
|
-
|
|
11226
|
-
|
|
11227
|
-
|
|
11228
|
-
|
|
11229
|
-
|
|
11230
|
-
|
|
11231
|
-
|
|
11232
|
-
|
|
11233
|
-
|
|
11234
|
-
|
|
11235
|
-
|
|
11236
|
-
|
|
11237
|
-
|
|
11238
|
-
|
|
11239
|
-
|
|
11240
|
-
|
|
11241
|
-
}
|
|
11242
|
-
|
|
11243
|
-
),
|
|
12031
|
+
h(ConfirmDialogBox, {
|
|
12032
|
+
titleId: "cpm-confirm-remove-detail-title",
|
|
12033
|
+
title: `卸载 ${plugin.displayName || plugin.name}?`,
|
|
12034
|
+
description: "将删除插件副本、技能与子代理注册及 MCP 配置。",
|
|
12035
|
+
descriptionStyle: { color: "var(--cpm-muted)", fontSize: "13px", lineHeight: 1.5, marginBottom: "20px" },
|
|
12036
|
+
confirmLabel: "卸载",
|
|
12037
|
+
confirmBusyLabel: "卸载中…",
|
|
12038
|
+
confirmStyle: { background: "#ef4444", borderColor: "#ef4444", color: "#ffffff" },
|
|
12039
|
+
busy,
|
|
12040
|
+
cancelDisabled: busy,
|
|
12041
|
+
onCancel: () => { if (!busy) setConfirmRemove(false); },
|
|
12042
|
+
onConfirm: async () => {
|
|
12043
|
+
if (busy) return;
|
|
12044
|
+
setBusy(true);
|
|
12045
|
+
try {
|
|
12046
|
+
await onRemove();
|
|
12047
|
+
} finally {
|
|
12048
|
+
setBusy(false);
|
|
12049
|
+
setConfirmRemove(false);
|
|
12050
|
+
}
|
|
12051
|
+
},
|
|
12052
|
+
}),
|
|
11244
12053
|
)
|
|
11245
12054
|
);
|
|
11246
12055
|
}
|
|
@@ -11262,6 +12071,20 @@ window.__ModuleLoader__.load({ id: "universal-plugin-hub", factory: (require) =>
|
|
|
11262
12071
|
} catch {}
|
|
11263
12072
|
}
|
|
11264
12073
|
|
|
12074
|
+
function clearMcpToolsCache(matcher) {
|
|
12075
|
+
const matchFn = typeof matcher === "function" ? matcher : (k) => k === matcher;
|
|
12076
|
+
let changed = false;
|
|
12077
|
+
for (const k of Object.keys(GLOBAL_MCP_TOOLS_CACHE)) {
|
|
12078
|
+
if (matchFn(k)) {
|
|
12079
|
+
delete GLOBAL_MCP_TOOLS_CACHE[k];
|
|
12080
|
+
changed = true;
|
|
12081
|
+
}
|
|
12082
|
+
}
|
|
12083
|
+
if (changed) {
|
|
12084
|
+
try { localStorage.setItem("cpm_mcp_tools_cache_v1", JSON.stringify(GLOBAL_MCP_TOOLS_CACHE)); } catch {}
|
|
12085
|
+
}
|
|
12086
|
+
}
|
|
12087
|
+
|
|
11265
12088
|
function useAutoMcpTools(servers, loadTools) {
|
|
11266
12089
|
const attempted = useRef(new Map());
|
|
11267
12090
|
useEffect(() => {
|
|
@@ -11444,7 +12267,21 @@ window.__ModuleLoader__.load({ id: "universal-plugin-hub", factory: (require) =>
|
|
|
11444
12267
|
return props.record ? h(ManagePageContent, props) : null;
|
|
11445
12268
|
}
|
|
11446
12269
|
|
|
11447
|
-
|
|
12270
|
+
/** Return the first non-empty author name that is not an unknown placeholder. */
|
|
12271
|
+
function resolveKnownAuthor(...candidates) {
|
|
12272
|
+
for (const candidate of candidates) {
|
|
12273
|
+
let raw = "";
|
|
12274
|
+
if (typeof candidate === "string") raw = candidate;
|
|
12275
|
+
else if (candidate && typeof candidate === "object" && typeof candidate.name === "string") raw = candidate.name;
|
|
12276
|
+
const trimmed = raw.trim();
|
|
12277
|
+
if (!trimmed) continue;
|
|
12278
|
+
if (trimmed === "未知" || trimmed.toLowerCase() === "unknown") continue;
|
|
12279
|
+
return trimmed;
|
|
12280
|
+
}
|
|
12281
|
+
return "";
|
|
12282
|
+
}
|
|
12283
|
+
|
|
12284
|
+
function ManagePageContent({ record, state, rows, isDark, refreshState, patchPluginInState, showToast, onBack, onClose, initialTab, initialConnector, containerRef, scrollState }) {
|
|
11448
12285
|
const dark = typeof isDark === "boolean" ? isDark : (typeof isDarkMode === "function" ? isDarkMode() : false);
|
|
11449
12286
|
const [tab, setTabRaw] = useState(scrollState?.manageTab || initialTab || "skills");
|
|
11450
12287
|
const setTab = (next) => { if (scrollState) scrollState.manageTab = next; setTabRaw(next); };
|
|
@@ -11550,11 +12387,18 @@ window.__ModuleLoader__.load({ id: "universal-plugin-hub", factory: (require) =>
|
|
|
11550
12387
|
args: parsedArgs, env: envMap,
|
|
11551
12388
|
};
|
|
11552
12389
|
};
|
|
11553
|
-
const persistAuthDialog = (payload = buildAuthPayload()) =>
|
|
11554
|
-
|
|
12390
|
+
const persistAuthDialog = async (payload = buildAuthPayload()) => {
|
|
12391
|
+
const connName = authDialog.connectorName;
|
|
12392
|
+
const res = await api(`/plugins/${encodeURIComponent(record.name)}/connectors/${encodeURIComponent(connName)}/auth`, {
|
|
11555
12393
|
method: "POST",
|
|
11556
12394
|
body: JSON.stringify(payload),
|
|
11557
12395
|
});
|
|
12396
|
+
if (res?.ok !== false && connName) {
|
|
12397
|
+
clearMcpToolsCache(`${record.name}::${connName}`);
|
|
12398
|
+
if (res?.plugin && patchPluginInState) patchPluginInState(res.plugin);
|
|
12399
|
+
}
|
|
12400
|
+
return res;
|
|
12401
|
+
};
|
|
11558
12402
|
const setAuthError = (message) => setAuthDialog((prev) => prev ? {
|
|
11559
12403
|
...prev, testing: false, status: "error", statusMessage: message,
|
|
11560
12404
|
lastResult: { ok: false, message, status: 500, server: prev.connectorName, transport: prev.transport, endpoint: prev.url, errorDetails: message },
|
|
@@ -11646,7 +12490,7 @@ window.__ModuleLoader__.load({ id: "universal-plugin-hub", factory: (require) =>
|
|
|
11646
12490
|
return;
|
|
11647
12491
|
}
|
|
11648
12492
|
await refreshState();
|
|
11649
|
-
if (connName) await loadConnectorTools(connName);
|
|
12493
|
+
if (connName) await loadConnectorTools(connName, true);
|
|
11650
12494
|
if (typeof showApplicationToast === "function") {
|
|
11651
12495
|
void showApplicationToast(showToast, saved, "配置成功", `已成功保存 ${connName} 认证信息并注册为可用 MCP 服务`);
|
|
11652
12496
|
}
|
|
@@ -11691,7 +12535,7 @@ window.__ModuleLoader__.load({ id: "universal-plugin-hub", factory: (require) =>
|
|
|
11691
12535
|
|
|
11692
12536
|
const autoLoadConnectorTools = useCallback((_owner, name) => loadConnectorTools(name), [loadConnectorTools]);
|
|
11693
12537
|
useAutoMcpTools((record.connectors || []).map(connector => ({
|
|
11694
|
-
owner: record.name, name: connector.name, connected: connector.enabled === true,
|
|
12538
|
+
owner: record.name, name: connector.name, connected: connector.enabled === true && !connector.pending,
|
|
11695
12539
|
revision: JSON.stringify([record.installedAt, connector]),
|
|
11696
12540
|
})), autoLoadConnectorTools);
|
|
11697
12541
|
|
|
@@ -11850,6 +12694,7 @@ window.__ModuleLoader__.load({ id: "universal-plugin-hub", factory: (require) =>
|
|
|
11850
12694
|
}, []);
|
|
11851
12695
|
|
|
11852
12696
|
const source = state.sources.find((s) => s.id === record.sourceId);
|
|
12697
|
+
const authorName = resolveKnownAuthor(record?.author, marketPlugin?.author, marketPlugin?.detail?.author);
|
|
11853
12698
|
const skills = (Array.isArray(record.skills) && record.skills.length > 0)
|
|
11854
12699
|
? record.skills
|
|
11855
12700
|
: (marketPlugin?.detail?.skills && Array.isArray(marketPlugin.detail.skills) && marketPlugin.detail.skills.length > 0)
|
|
@@ -11896,6 +12741,15 @@ window.__ModuleLoader__.load({ id: "universal-plugin-hub", factory: (require) =>
|
|
|
11896
12741
|
const serverEnabled = record.enabled !== false;
|
|
11897
12742
|
const pluginEnabled = optimisticEnabled !== null ? optimisticEnabled : serverEnabled;
|
|
11898
12743
|
|
|
12744
|
+
const applyToggleState = async (result) => {
|
|
12745
|
+
if (result?.plugin && patchPluginInState) {
|
|
12746
|
+
patchPluginInState(result.plugin);
|
|
12747
|
+
void refreshState();
|
|
12748
|
+
} else {
|
|
12749
|
+
await refreshState();
|
|
12750
|
+
}
|
|
12751
|
+
};
|
|
12752
|
+
|
|
11899
12753
|
const toggle = async () => {
|
|
11900
12754
|
if (toggling || updating || busy || togglingConn) return;
|
|
11901
12755
|
const next = !serverEnabled;
|
|
@@ -11912,7 +12766,7 @@ window.__ModuleLoader__.load({ id: "universal-plugin-hub", factory: (require) =>
|
|
|
11912
12766
|
showToast("操作失败", result.error || "插件状态已变更,请刷新后重试", { restart: false });
|
|
11913
12767
|
return;
|
|
11914
12768
|
}
|
|
11915
|
-
await
|
|
12769
|
+
await applyToggleState(result);
|
|
11916
12770
|
void showApplicationToast(showToast, result, next ? "已启用插件" : "已禁用插件", "插件状态已实时更新并生效。");
|
|
11917
12771
|
} catch (e) {
|
|
11918
12772
|
setOptimisticEnabled(null);
|
|
@@ -11939,7 +12793,7 @@ window.__ModuleLoader__.load({ id: "universal-plugin-hub", factory: (require) =>
|
|
|
11939
12793
|
showToast("操作失败", result.error || "请检查 MCP 配置后重试", { restart: false });
|
|
11940
12794
|
return;
|
|
11941
12795
|
}
|
|
11942
|
-
await
|
|
12796
|
+
await applyToggleState(result);
|
|
11943
12797
|
void showApplicationToast(showToast, result, nextConnected ? "已连接 Connector" : "已断开 Connector", `MCP 服务 ${connectorName} 配置已实时更新。`);
|
|
11944
12798
|
} catch (e) {
|
|
11945
12799
|
setOptimisticConn((prev) => { const n = { ...prev }; delete n[connectorName]; return n; });
|
|
@@ -11960,6 +12814,7 @@ window.__ModuleLoader__.load({ id: "universal-plugin-hub", factory: (require) =>
|
|
|
11960
12814
|
showToast("更新失败", result.error || "更新未能完成,请刷新后重试", { restart: false });
|
|
11961
12815
|
return;
|
|
11962
12816
|
}
|
|
12817
|
+
clearMcpToolsCache((k) => k.startsWith(`${record.name}::`));
|
|
11963
12818
|
await refreshState();
|
|
11964
12819
|
void showApplicationToast(showToast, result, "更新完成", `${(result.skills || []).length} 个技能已实时重新就绪并生效。`);
|
|
11965
12820
|
} catch (e) {
|
|
@@ -11979,14 +12834,7 @@ window.__ModuleLoader__.load({ id: "universal-plugin-hub", factory: (require) =>
|
|
|
11979
12834
|
showToast("卸载失败", result.error || "卸载未能完成,请稍后重试", { restart: false });
|
|
11980
12835
|
return;
|
|
11981
12836
|
}
|
|
11982
|
-
|
|
11983
|
-
if (k.startsWith(`${record.name}::`)) {
|
|
11984
|
-
delete GLOBAL_MCP_TOOLS_CACHE[k];
|
|
11985
|
-
}
|
|
11986
|
-
}
|
|
11987
|
-
try {
|
|
11988
|
-
localStorage.setItem("cpm_mcp_tools_cache_v1", JSON.stringify(GLOBAL_MCP_TOOLS_CACHE));
|
|
11989
|
-
} catch {}
|
|
12837
|
+
clearMcpToolsCache((k) => k.startsWith(`${record.name}::`));
|
|
11990
12838
|
await refreshState();
|
|
11991
12839
|
void showApplicationToast(showToast, result, "已卸载插件", "插件副本与技能注册已实时移除并生效。");
|
|
11992
12840
|
onClose();
|
|
@@ -12116,17 +12964,10 @@ window.__ModuleLoader__.load({ id: "universal-plugin-hub", factory: (require) =>
|
|
|
12116
12964
|
openAuthDialog(initialConnector, found);
|
|
12117
12965
|
}, [record, connectors, initialConnector]);
|
|
12118
12966
|
|
|
12119
|
-
|
|
12120
|
-
if (
|
|
12121
|
-
|
|
12122
|
-
|
|
12123
|
-
if (authDialog) closeAuthDialog();
|
|
12124
|
-
if (confirmRemove && !busy) setConfirmRemove(false);
|
|
12125
|
-
}
|
|
12126
|
-
};
|
|
12127
|
-
window.addEventListener("keydown", onKey);
|
|
12128
|
-
return () => window.removeEventListener("keydown", onKey);
|
|
12129
|
-
}, [authDialog, confirmRemove, busy]);
|
|
12967
|
+
useDialogEscape(!!(authDialog || confirmRemove), () => {
|
|
12968
|
+
if (authDialog) closeAuthDialog();
|
|
12969
|
+
if (confirmRemove && !busy) setConfirmRemove(false);
|
|
12970
|
+
});
|
|
12130
12971
|
|
|
12131
12972
|
return h(React.Fragment, null,
|
|
12132
12973
|
h("div", {
|
|
@@ -12146,12 +12987,12 @@ window.__ModuleLoader__.load({ id: "universal-plugin-hub", factory: (require) =>
|
|
|
12146
12987
|
...marketPlugin,
|
|
12147
12988
|
...record,
|
|
12148
12989
|
icons: (record?.icons && (record.icons.light?.length || record.icons.dark?.length)) ? record.icons : marketPlugin.icons,
|
|
12149
|
-
author:
|
|
12990
|
+
author: authorName || undefined,
|
|
12150
12991
|
homepage: record?.homepage || marketPlugin.homepage,
|
|
12151
12992
|
description: record?.description || marketPlugin.description,
|
|
12152
12993
|
displayName: record?.displayName || marketPlugin.displayName,
|
|
12153
12994
|
source: record?.source || marketPlugin.source,
|
|
12154
|
-
} : record,
|
|
12995
|
+
} : { ...record, author: authorName || undefined },
|
|
12155
12996
|
isDark: dark,
|
|
12156
12997
|
eager: true,
|
|
12157
12998
|
}),
|
|
@@ -12175,23 +13016,23 @@ window.__ModuleLoader__.load({ id: "universal-plugin-hub", factory: (require) =>
|
|
|
12175
13016
|
}),
|
|
12176
13017
|
),
|
|
12177
13018
|
|
|
12178
|
-
h("
|
|
13019
|
+
h("dl", { className: "cpm-meta" },
|
|
12179
13020
|
h("div", null,
|
|
12180
|
-
h("
|
|
12181
|
-
h("
|
|
13021
|
+
h("dt", { className: "k" }, "Source"),
|
|
13022
|
+
h("dd", { className: "v" },
|
|
12182
13023
|
h("a", { href: source ? source.url : "#", target: "_blank", rel: "noreferrer" },
|
|
12183
13024
|
`Marketplace (${source ? source.name : record.sourceId})`,
|
|
12184
13025
|
),
|
|
12185
13026
|
),
|
|
12186
13027
|
),
|
|
12187
13028
|
h("div", null,
|
|
12188
|
-
h("
|
|
12189
|
-
h("
|
|
12190
|
-
),
|
|
12191
|
-
h("div", null,
|
|
12192
|
-
h("span", { className: "k" }, "Author"),
|
|
12193
|
-
h("span", { className: "v" }, record.author || "未知"),
|
|
13029
|
+
h("dt", { className: "k" }, "Version"),
|
|
13030
|
+
h("dd", { className: "v" }, record.version || "1.0.0"),
|
|
12194
13031
|
),
|
|
13032
|
+
authorName ? h("div", null,
|
|
13033
|
+
h("dt", { className: "k" }, "Author"),
|
|
13034
|
+
h("dd", { className: "v" }, authorName),
|
|
13035
|
+
) : null,
|
|
12195
13036
|
),
|
|
12196
13037
|
|
|
12197
13038
|
record.description && h("div", { className: "cpm-section" },
|
|
@@ -12498,7 +13339,13 @@ window.__ModuleLoader__.load({ id: "universal-plugin-hub", factory: (require) =>
|
|
|
12498
13339
|
),
|
|
12499
13340
|
|
|
12500
13341
|
authDialog && h("div", { className: "cpm-dialog" },
|
|
12501
|
-
h("div", {
|
|
13342
|
+
h("div", {
|
|
13343
|
+
className: "cpm-mcp-modal",
|
|
13344
|
+
role: "dialog",
|
|
13345
|
+
"aria-modal": "true",
|
|
13346
|
+
"aria-label": authDialog.connectorName ? `配置 MCP「${authDialog.connectorName}」` : "配置 MCP",
|
|
13347
|
+
onClick: (e) => e.stopPropagation(),
|
|
13348
|
+
},
|
|
12502
13349
|
h("button", {
|
|
12503
13350
|
type: "button",
|
|
12504
13351
|
className: "cpm-mcp-close-top",
|
|
@@ -12650,14 +13497,20 @@ window.__ModuleLoader__.load({ id: "universal-plugin-hub", factory: (require) =>
|
|
|
12650
13497
|
onClick: async () => {
|
|
12651
13498
|
setAuthDialog((prev) => prev ? { ...prev, saving: true } : null);
|
|
12652
13499
|
try {
|
|
13500
|
+
const connName = authDialog.connectorName;
|
|
12653
13501
|
const res = await persistAuthDialog();
|
|
12654
13502
|
if (res && res.ok === false) {
|
|
12655
13503
|
showToast("保存失败", res.error || "配置校验未通过,请检查填写内容", { restart: false });
|
|
12656
13504
|
setAuthDialog((prev) => prev ? { ...prev, saving: false } : null);
|
|
12657
13505
|
return;
|
|
12658
13506
|
}
|
|
12659
|
-
|
|
12660
|
-
|
|
13507
|
+
if (res?.plugin && patchPluginInState) {
|
|
13508
|
+
void refreshState();
|
|
13509
|
+
} else {
|
|
13510
|
+
await refreshState();
|
|
13511
|
+
}
|
|
13512
|
+
void loadConnectorTools(connName, true);
|
|
13513
|
+
void showApplicationToast(showToast, res, "配置成功", `已成功保存 ${connName} 认证信息并注册为可用 MCP 服务`);
|
|
12661
13514
|
closeAuthDialog();
|
|
12662
13515
|
} catch (err) {
|
|
12663
13516
|
const rawMsg = err?.message || err;
|
|
@@ -12690,14 +13543,19 @@ window.__ModuleLoader__.load({ id: "universal-plugin-hub", factory: (require) =>
|
|
|
12690
13543
|
),
|
|
12691
13544
|
|
|
12692
13545
|
confirmRemove && h("div", { className: "cpm-dialog", ...backdropDismissProps(() => { if (!busy) setConfirmRemove(false); }) },
|
|
12693
|
-
h(
|
|
12694
|
-
|
|
12695
|
-
|
|
12696
|
-
|
|
12697
|
-
|
|
12698
|
-
|
|
12699
|
-
|
|
12700
|
-
|
|
13546
|
+
h(ConfirmDialogBox, {
|
|
13547
|
+
titleId: "cpm-confirm-remove-manage-title",
|
|
13548
|
+
title: `卸载 ${record.displayName || record.name}?`,
|
|
13549
|
+
description: "将删除插件副本、技能与子代理注册及 MCP 配置。",
|
|
13550
|
+
descriptionStyle: { color: "var(--cpm-muted)", fontSize: "13px", lineHeight: 1.5, marginBottom: "20px" },
|
|
13551
|
+
confirmLabel: "卸载",
|
|
13552
|
+
confirmBusyLabel: "卸载中…",
|
|
13553
|
+
confirmStyle: { background: "#ef4444", borderColor: "#ef4444", color: "#ffffff" },
|
|
13554
|
+
busy,
|
|
13555
|
+
cancelDisabled: busy,
|
|
13556
|
+
onCancel: () => { if (!busy) setConfirmRemove(false); },
|
|
13557
|
+
onConfirm: remove,
|
|
13558
|
+
}),
|
|
12701
13559
|
),
|
|
12702
13560
|
|
|
12703
13561
|
hoveredTool && (() => {
|
|
@@ -13135,6 +13993,1387 @@ window.__ModuleLoader__.load({ id: "universal-plugin-hub", factory: (require) =>
|
|
|
13135
13993
|
);
|
|
13136
13994
|
}
|
|
13137
13995
|
|
|
13996
|
+
const AT_PLUGIN_SCHEME = "uph-plugin:";
|
|
13997
|
+
const AT_PLUGIN_WIRE_RE = /@\[([^\]\n]+)\]\(uph-plugin:([^)\s]+)\)/uy;
|
|
13998
|
+
const AT_PLUGIN_RAW_TOKEN_RE = /@([^\s\p{Script=Han}\p{Script=Hiragana}\p{Script=Katakana}\p{Script=Hangul},。;:、!?()【】《》“”‘’」』]+)/uy;
|
|
13999
|
+
const AT_PLUGIN_LEFT_ALLOWED_RE = /[\s(\[{"'“‘(【《,。;:、!?\p{Script=Han}\p{Script=Hiragana}\p{Script=Katakana}\p{Script=Hangul}]/u;
|
|
14000
|
+
const AT_PLUGIN_TRAILING_PUNCT_RE = /[.,;:!?,。;:!?)"'\]”’)】》]+$/u;
|
|
14001
|
+
const AT_PLUGINS_CSS = `
|
|
14002
|
+
[role="listbox"] button[id^="dsh-slash-option-plugins-"] {
|
|
14003
|
+
gap: 8px;
|
|
14004
|
+
}
|
|
14005
|
+
[role="listbox"] button[id^="dsh-slash-option-plugins-"] > span:first-child {
|
|
14006
|
+
width: 16px;
|
|
14007
|
+
height: 16px;
|
|
14008
|
+
border-radius: 4px;
|
|
14009
|
+
overflow: hidden;
|
|
14010
|
+
}
|
|
14011
|
+
[role="listbox"] button[id^="dsh-slash-option-plugins-"] > span:nth-child(2) {
|
|
14012
|
+
font-weight: 600;
|
|
14013
|
+
color: var(--dsw-alias-label-primary);
|
|
14014
|
+
}
|
|
14015
|
+
[role="listbox"] button[id^="dsh-slash-option-plugins-"] > span:nth-child(3) {
|
|
14016
|
+
text-align: left;
|
|
14017
|
+
}
|
|
14018
|
+
.cpm-at-plugin-icon,
|
|
14019
|
+
.cpm-at-plugin-chip-icon {
|
|
14020
|
+
position: relative;
|
|
14021
|
+
display: inline-flex;
|
|
14022
|
+
align-items: center;
|
|
14023
|
+
justify-content: center;
|
|
14024
|
+
width: 100%;
|
|
14025
|
+
height: 100%;
|
|
14026
|
+
flex: none;
|
|
14027
|
+
overflow: hidden;
|
|
14028
|
+
border-radius: 3px;
|
|
14029
|
+
}
|
|
14030
|
+
.cpm-at-plugin-icon .cpm-card-icon,
|
|
14031
|
+
.cpm-at-plugin-chip-icon .cpm-card-icon,
|
|
14032
|
+
.cpm-at-plugin-icon .cpm-icon-underlay > .cpm-card-icon,
|
|
14033
|
+
.cpm-at-plugin-chip-icon .cpm-icon-underlay > .cpm-card-icon {
|
|
14034
|
+
width: 100% !important;
|
|
14035
|
+
height: 100% !important;
|
|
14036
|
+
flex: none !important;
|
|
14037
|
+
margin: 0 !important;
|
|
14038
|
+
padding: 0 !important;
|
|
14039
|
+
border: none !important;
|
|
14040
|
+
border-radius: 3px !important;
|
|
14041
|
+
corner-shape: initial !important;
|
|
14042
|
+
box-shadow: none !important;
|
|
14043
|
+
background: transparent !important;
|
|
14044
|
+
display: flex;
|
|
14045
|
+
align-items: center;
|
|
14046
|
+
justify-content: center;
|
|
14047
|
+
position: relative;
|
|
14048
|
+
overflow: hidden;
|
|
14049
|
+
}
|
|
14050
|
+
.cpm-at-plugin-icon .cpm-card-icon img,
|
|
14051
|
+
.cpm-at-plugin-icon .cpm-card-icon svg,
|
|
14052
|
+
.cpm-at-plugin-icon > svg,
|
|
14053
|
+
.cpm-at-plugin-icon > img,
|
|
14054
|
+
.cpm-at-plugin-chip-icon .cpm-card-icon img,
|
|
14055
|
+
.cpm-at-plugin-chip-icon .cpm-card-icon svg,
|
|
14056
|
+
.cpm-at-plugin-chip-icon > svg,
|
|
14057
|
+
.cpm-at-plugin-chip-icon > img {
|
|
14058
|
+
width: 100% !important;
|
|
14059
|
+
height: 100% !important;
|
|
14060
|
+
border-radius: 3px !important;
|
|
14061
|
+
object-fit: contain !important;
|
|
14062
|
+
display: block;
|
|
14063
|
+
}
|
|
14064
|
+
[data-composer-chip="plugins"],
|
|
14065
|
+
.cpm-at-plugin-chip {
|
|
14066
|
+
display: inline-flex;
|
|
14067
|
+
align-items: baseline;
|
|
14068
|
+
gap: 4px;
|
|
14069
|
+
max-width: 240px;
|
|
14070
|
+
padding: 0 4px;
|
|
14071
|
+
border-radius: var(--dsw-radius-sm, 4px);
|
|
14072
|
+
color: var(--dsw-alias-label-primary, #18181b);
|
|
14073
|
+
background: transparent;
|
|
14074
|
+
font-weight: 600;
|
|
14075
|
+
line-height: inherit;
|
|
14076
|
+
vertical-align: baseline;
|
|
14077
|
+
user-select: none;
|
|
14078
|
+
cursor: default;
|
|
14079
|
+
transition: background-color 120ms ease;
|
|
14080
|
+
}
|
|
14081
|
+
body[data-ds-dark-theme] [data-composer-chip="plugins"],
|
|
14082
|
+
body[data-ds-dark-theme] .cpm-at-plugin-chip {
|
|
14083
|
+
color: var(--dsw-alias-label-primary, #f4f4f5);
|
|
14084
|
+
}
|
|
14085
|
+
@media (hover: hover) {
|
|
14086
|
+
[data-composer-chip="plugins"]:hover,
|
|
14087
|
+
.cpm-at-plugin-chip:hover {
|
|
14088
|
+
background: var(--dsw-alias-interactive-bg-hover, rgba(38, 49, 72, 0.06));
|
|
14089
|
+
}
|
|
14090
|
+
body[data-ds-dark-theme] [data-composer-chip="plugins"]:hover,
|
|
14091
|
+
body[data-ds-dark-theme] .cpm-at-plugin-chip:hover {
|
|
14092
|
+
background: var(--dsw-alias-interactive-bg-hover, rgba(255, 255, 255, 0.08));
|
|
14093
|
+
}
|
|
14094
|
+
}
|
|
14095
|
+
[data-composer-chip="plugins"] > span:not([data-uph-chip-icon]) {
|
|
14096
|
+
display: inline-flex;
|
|
14097
|
+
align-items: baseline;
|
|
14098
|
+
padding: 0 !important;
|
|
14099
|
+
margin: 0 !important;
|
|
14100
|
+
border-radius: 0 !important;
|
|
14101
|
+
background: transparent !important;
|
|
14102
|
+
color: inherit !important;
|
|
14103
|
+
font-weight: inherit !important;
|
|
14104
|
+
line-height: inherit !important;
|
|
14105
|
+
vertical-align: baseline !important;
|
|
14106
|
+
max-width: none !important;
|
|
14107
|
+
min-width: 0;
|
|
14108
|
+
overflow: hidden;
|
|
14109
|
+
}
|
|
14110
|
+
[data-composer-chip="plugins"][data-uph-plugin-resolved="true"] > span:not([data-uph-chip-icon]) > span:first-child:not(:last-child) {
|
|
14111
|
+
display: none !important;
|
|
14112
|
+
}
|
|
14113
|
+
[data-composer-chip="plugins"]:not([data-uph-plugin-resolved="true"]) > span:not([data-uph-chip-icon]) {
|
|
14114
|
+
gap: 3px;
|
|
14115
|
+
}
|
|
14116
|
+
.cpm-at-plugin-chip.is-unresolved {
|
|
14117
|
+
opacity: 0.72;
|
|
14118
|
+
font-weight: 500;
|
|
14119
|
+
}
|
|
14120
|
+
.cpm-at-plugin-chip-marker {
|
|
14121
|
+
flex: none;
|
|
14122
|
+
font-weight: 500;
|
|
14123
|
+
}
|
|
14124
|
+
.cpm-at-plugin-chip-icon-wrap {
|
|
14125
|
+
display: inline-flex;
|
|
14126
|
+
width: clamp(13px, 1em, 16px);
|
|
14127
|
+
height: clamp(13px, 1em, 16px);
|
|
14128
|
+
flex: none;
|
|
14129
|
+
align-items: center;
|
|
14130
|
+
justify-content: center;
|
|
14131
|
+
align-self: center;
|
|
14132
|
+
overflow: hidden;
|
|
14133
|
+
line-height: 1;
|
|
14134
|
+
position: relative;
|
|
14135
|
+
top: 0.05em;
|
|
14136
|
+
}
|
|
14137
|
+
.cpm-at-plugin-chip-label {
|
|
14138
|
+
overflow: hidden;
|
|
14139
|
+
text-overflow: ellipsis;
|
|
14140
|
+
white-space: nowrap;
|
|
14141
|
+
}
|
|
14142
|
+
.cpm-at-plugin-popover {
|
|
14143
|
+
position: fixed;
|
|
14144
|
+
inset: auto;
|
|
14145
|
+
right: auto;
|
|
14146
|
+
bottom: auto;
|
|
14147
|
+
margin: 0;
|
|
14148
|
+
z-index: 100040;
|
|
14149
|
+
width: max-content;
|
|
14150
|
+
min-width: 0;
|
|
14151
|
+
max-width: min(204px, calc(100vw - 24px));
|
|
14152
|
+
max-height: min(160px, 36vh);
|
|
14153
|
+
padding: 6px 10px;
|
|
14154
|
+
overflow-y: auto;
|
|
14155
|
+
overscroll-behavior: contain;
|
|
14156
|
+
box-sizing: border-box;
|
|
14157
|
+
border-radius: var(--dsw-radius-lg, 16px);
|
|
14158
|
+
corner-shape: squircle;
|
|
14159
|
+
background: rgba(255, 255, 255, 0.72);
|
|
14160
|
+
backdrop-filter: blur(20px) saturate(180%);
|
|
14161
|
+
-webkit-backdrop-filter: blur(20px) saturate(180%);
|
|
14162
|
+
border: 1px solid rgba(0, 0, 0, 0.08);
|
|
14163
|
+
box-shadow: 0 16px 36px -4px rgba(0, 0, 0, 0.10), 0 2px 8px rgba(0, 0, 0, 0.04);
|
|
14164
|
+
color: #18181b;
|
|
14165
|
+
font-size: 12px;
|
|
14166
|
+
line-height: 1.48;
|
|
14167
|
+
letter-spacing: -0.005em;
|
|
14168
|
+
overflow-wrap: break-word;
|
|
14169
|
+
user-select: text;
|
|
14170
|
+
}
|
|
14171
|
+
.cpm-at-plugin-popover:not(:popover-open):not(.\:popover-open):not([data-open="true"]) {
|
|
14172
|
+
display: none;
|
|
14173
|
+
}
|
|
14174
|
+
.cpm-at-plugin-popover:is(:popover-open, .\:popover-open, [data-open="true"]) {
|
|
14175
|
+
display: block;
|
|
14176
|
+
}
|
|
14177
|
+
body[data-ds-dark-theme] .cpm-at-plugin-popover,
|
|
14178
|
+
.cpm-at-plugin-popover.cpm-dark {
|
|
14179
|
+
background: rgba(32, 32, 35, 0.75);
|
|
14180
|
+
backdrop-filter: blur(22px) saturate(180%);
|
|
14181
|
+
-webkit-backdrop-filter: blur(22px) saturate(180%);
|
|
14182
|
+
border: 1px solid rgba(255, 255, 255, 0.14);
|
|
14183
|
+
box-shadow: 0 12px 36px rgba(0, 0, 0, 0.6);
|
|
14184
|
+
color: #f4f4f5;
|
|
14185
|
+
}
|
|
14186
|
+
.cpm-at-plugin-popover::-webkit-scrollbar {
|
|
14187
|
+
width: 0;
|
|
14188
|
+
height: 0;
|
|
14189
|
+
}
|
|
14190
|
+
.cpm-at-plugin-popover-desc {
|
|
14191
|
+
margin: 0;
|
|
14192
|
+
white-space: pre-wrap;
|
|
14193
|
+
text-wrap: pretty;
|
|
14194
|
+
color: inherit;
|
|
14195
|
+
}
|
|
14196
|
+
.cpm-at-plugin-popover[data-unresolved="true"] .cpm-at-plugin-popover-desc {
|
|
14197
|
+
opacity: 0.72;
|
|
14198
|
+
}
|
|
14199
|
+
@media (prefers-reduced-motion: no-preference) {
|
|
14200
|
+
.cpm-at-plugin-popover {
|
|
14201
|
+
opacity: 0;
|
|
14202
|
+
transform: translateY(4px) scale(0.96);
|
|
14203
|
+
transition:
|
|
14204
|
+
opacity 0.16s cubic-bezier(0.22, 1, 0.36, 1),
|
|
14205
|
+
transform 0.22s linear(0 0%, 0.049 2.9%, 0.1685 5.9%, 0.3235 8.8%, 0.4877 11.8%, 0.6428 14.7%, 0.7778 17.6%, 0.8871 20.6%, 0.9694 23.5%, 1.0265 26.5%, 1.0617 29.4%, 1.0792 32.4%, 1.0835 35.3%, 1.0787 38.2%, 1.0683 41.2%, 1.0551 44.1%, 1.0414 47.1%, 1.0286 50%, 1.0176 52.9%, 1.0086 55.9%, 1.002 58.8%, 0.9974 61.8%, 0.9946 64.7%, 0.9933 67.6%, 0.993 70.6%, 0.9935 73.5%, 0.9944 76.5%, 0.9955 79.4%, 0.9966 82.4%, 0.9977 85.3%, 0.9986 88.2%, 0.9993 91.2%, 0.9999 94.1%, 1 100%),
|
|
14206
|
+
display 0.16s,
|
|
14207
|
+
overlay 0.16s;
|
|
14208
|
+
transition-behavior: allow-discrete;
|
|
14209
|
+
}
|
|
14210
|
+
.cpm-at-plugin-popover[data-placement="bottom"] {
|
|
14211
|
+
transform: translateY(-4px) scale(0.96);
|
|
14212
|
+
}
|
|
14213
|
+
.cpm-at-plugin-popover:is(:popover-open, .\:popover-open, [data-open="true"]) {
|
|
14214
|
+
opacity: 1;
|
|
14215
|
+
transform: translateY(0) scale(1);
|
|
14216
|
+
}
|
|
14217
|
+
@starting-style {
|
|
14218
|
+
.cpm-at-plugin-popover:is(:popover-open, .\:popover-open, [data-open="true"]) {
|
|
14219
|
+
opacity: 0;
|
|
14220
|
+
transform: translateY(4px) scale(0.96);
|
|
14221
|
+
}
|
|
14222
|
+
.cpm-at-plugin-popover[data-placement="bottom"]:is(:popover-open, .\:popover-open, [data-open="true"]) {
|
|
14223
|
+
transform: translateY(-4px) scale(0.96);
|
|
14224
|
+
}
|
|
14225
|
+
}
|
|
14226
|
+
}
|
|
14227
|
+
@media (prefers-reduced-motion: reduce) {
|
|
14228
|
+
[data-composer-chip="plugins"],
|
|
14229
|
+
.cpm-at-plugin-chip,
|
|
14230
|
+
.cpm-at-plugin-popover {
|
|
14231
|
+
transition: none;
|
|
14232
|
+
}
|
|
14233
|
+
}
|
|
14234
|
+
@media (prefers-reduced-transparency: reduce) {
|
|
14235
|
+
.cpm-at-plugin-popover {
|
|
14236
|
+
background: #ffffff;
|
|
14237
|
+
backdrop-filter: none;
|
|
14238
|
+
-webkit-backdrop-filter: none;
|
|
14239
|
+
}
|
|
14240
|
+
body[data-ds-dark-theme] .cpm-at-plugin-popover,
|
|
14241
|
+
.cpm-at-plugin-popover.cpm-dark {
|
|
14242
|
+
background: #27272a;
|
|
14243
|
+
backdrop-filter: none;
|
|
14244
|
+
-webkit-backdrop-filter: none;
|
|
14245
|
+
}
|
|
14246
|
+
}
|
|
14247
|
+
@media (prefers-contrast: more) {
|
|
14248
|
+
.cpm-at-plugin-popover {
|
|
14249
|
+
border-color: rgba(0, 0, 0, 0.24);
|
|
14250
|
+
background: rgba(255, 255, 255, 0.94);
|
|
14251
|
+
}
|
|
14252
|
+
body[data-ds-dark-theme] .cpm-at-plugin-popover,
|
|
14253
|
+
.cpm-at-plugin-popover.cpm-dark {
|
|
14254
|
+
border-color: rgba(255, 255, 255, 0.32);
|
|
14255
|
+
background: rgba(39, 39, 42, 0.96);
|
|
14256
|
+
}
|
|
14257
|
+
}
|
|
14258
|
+
`;
|
|
14259
|
+
|
|
14260
|
+
function placePluginChipPopover(anchorRect, width, height, viewport) {
|
|
14261
|
+
const margin = 12, gap = 8;
|
|
14262
|
+
const vw = Math.max(margin * 2 + 80, Number(viewport?.width) || 0);
|
|
14263
|
+
const vh = Math.max(margin * 2 + 48, Number(viewport?.height) || 0);
|
|
14264
|
+
const w = Math.min(Number(width) || 0, vw - margin * 2);
|
|
14265
|
+
const h = Math.min(Number(height) || 0, vh - margin * 2);
|
|
14266
|
+
const anchorCenterX = anchorRect.left + anchorRect.width / 2;
|
|
14267
|
+
const left = Math.max(margin, Math.min(anchorCenterX - w / 2, vw - w - margin));
|
|
14268
|
+
const spaceAbove = anchorRect.top - gap - margin;
|
|
14269
|
+
const spaceBelow = vh - anchorRect.bottom - gap - margin;
|
|
14270
|
+
const preferBottom = anchorRect.top - h - gap < margin && spaceBelow > spaceAbove;
|
|
14271
|
+
const placement = preferBottom ? "bottom" : "top";
|
|
14272
|
+
const rawTop = preferBottom ? anchorRect.bottom + gap : anchorRect.top - h - gap;
|
|
14273
|
+
const top = Math.max(margin, Math.min(rawTop, vh - h - margin));
|
|
14274
|
+
const edgeInset = Math.min(12, Math.floor(w / 2));
|
|
14275
|
+
const originX = Math.max(edgeInset, Math.min(w - edgeInset, anchorCenterX - left));
|
|
14276
|
+
const originY = placement === "bottom" ? "0%" : "100%";
|
|
14277
|
+
return { left: Math.round(left), top: Math.round(top), placement, originX: Math.round(originX), originY };
|
|
14278
|
+
}
|
|
14279
|
+
|
|
14280
|
+
function formatAtPluginMention(pluginName, displayName) {
|
|
14281
|
+
const id = String(pluginName || "").trim();
|
|
14282
|
+
const label = String(displayName || id).replace(/[\r\n\[\]]+/g, " ").trim() || id;
|
|
14283
|
+
return `@[${label}](${AT_PLUGIN_SCHEME}${encodeURIComponent(id)})`;
|
|
14284
|
+
}
|
|
14285
|
+
|
|
14286
|
+
function parseAtPluginCandidateValue(value) {
|
|
14287
|
+
if (typeof value !== "string" || !value) return null;
|
|
14288
|
+
try {
|
|
14289
|
+
const parsed = JSON.parse(value);
|
|
14290
|
+
if (parsed && typeof parsed.name === "string" && parsed.name) {
|
|
14291
|
+
return { name: parsed.name, displayName: parsed.displayName || parsed.name };
|
|
14292
|
+
}
|
|
14293
|
+
} catch {}
|
|
14294
|
+
return null;
|
|
14295
|
+
}
|
|
14296
|
+
|
|
14297
|
+
function isAtPluginLeftBoundary(text, index) {
|
|
14298
|
+
return index === 0 || AT_PLUGIN_LEFT_ALLOWED_RE.test(text[index - 1]);
|
|
14299
|
+
}
|
|
14300
|
+
|
|
14301
|
+
function matchAtPluginMention(text, from, byLowerName, wireOnly = false) {
|
|
14302
|
+
if (typeof text !== "string" || !text.includes("@")) return undefined;
|
|
14303
|
+
let cursor = from;
|
|
14304
|
+
while (cursor < text.length) {
|
|
14305
|
+
const at = text.indexOf("@", cursor);
|
|
14306
|
+
if (at < 0) return undefined;
|
|
14307
|
+
AT_PLUGIN_WIRE_RE.lastIndex = at;
|
|
14308
|
+
const wire = AT_PLUGIN_WIRE_RE.exec(text);
|
|
14309
|
+
if (wire !== null) {
|
|
14310
|
+
if (isAtPluginLeftBoundary(text, at)) {
|
|
14311
|
+
try {
|
|
14312
|
+
const decoded = decodeURIComponent(wire[2]);
|
|
14313
|
+
const live = byLowerName?.get(decoded.toLowerCase()) || null;
|
|
14314
|
+
return {
|
|
14315
|
+
id: "uph-plugin",
|
|
14316
|
+
start: at,
|
|
14317
|
+
end: at + wire[0].length,
|
|
14318
|
+
data: { name: live?.name || decoded, label: live?.displayName || wire[1] },
|
|
14319
|
+
};
|
|
14320
|
+
} catch {}
|
|
14321
|
+
}
|
|
14322
|
+
cursor = at + wire[0].length;
|
|
14323
|
+
continue;
|
|
14324
|
+
}
|
|
14325
|
+
if (!wireOnly && isAtPluginLeftBoundary(text, at) && byLowerName && byLowerName.size > 0) {
|
|
14326
|
+
AT_PLUGIN_RAW_TOKEN_RE.lastIndex = at;
|
|
14327
|
+
const raw = AT_PLUGIN_RAW_TOKEN_RE.exec(text);
|
|
14328
|
+
if (raw !== null && !raw[1].startsWith("\"")) {
|
|
14329
|
+
const cleaned = raw[1].replace(AT_PLUGIN_TRAILING_PUNCT_RE, "");
|
|
14330
|
+
if (cleaned.length > 0) {
|
|
14331
|
+
const live = byLowerName.get(cleaned.toLowerCase());
|
|
14332
|
+
if (live) {
|
|
14333
|
+
return {
|
|
14334
|
+
id: "uph-plugin",
|
|
14335
|
+
start: at,
|
|
14336
|
+
end: at + 1 + cleaned.length,
|
|
14337
|
+
data: { name: live.name, label: live.displayName || live.name },
|
|
14338
|
+
};
|
|
14339
|
+
}
|
|
14340
|
+
}
|
|
14341
|
+
}
|
|
14342
|
+
}
|
|
14343
|
+
cursor = at + 1;
|
|
14344
|
+
}
|
|
14345
|
+
return undefined;
|
|
14346
|
+
}
|
|
14347
|
+
|
|
14348
|
+
function atPluginReference(mention, label) {
|
|
14349
|
+
return { source: "plugins", ref: mention, label, clipboardText: mention };
|
|
14350
|
+
}
|
|
14351
|
+
|
|
14352
|
+
function pasteAtPluginReferences(event, byLowerName) {
|
|
14353
|
+
const clipboard = event.clipboardData;
|
|
14354
|
+
if (event.defaultPrevented || !clipboard || clipboard.files?.length ||
|
|
14355
|
+
Array.from(clipboard.items || []).some((item) => item.kind === "file")) return;
|
|
14356
|
+
const root = event.target?.closest?.('[data-composer-input][contenteditable="true"]');
|
|
14357
|
+
if (!root || root.hasAttribute("data-composer-composing")) return;
|
|
14358
|
+
const text = clipboard.getData("text/plain");
|
|
14359
|
+
if (!text.includes("(uph-plugin:")) return;
|
|
14360
|
+
|
|
14361
|
+
// DSH bundles Lexical privately. Use the mounted editor and its registered
|
|
14362
|
+
// classes so the pasted nodes share the host's history and draft model.
|
|
14363
|
+
const editor = root.__lexicalEditor;
|
|
14364
|
+
if (editor?.getRootElement?.() !== root || !editor.isEditable?.() || editor.isComposing?.() ||
|
|
14365
|
+
typeof editor.update !== "function") return;
|
|
14366
|
+
const ReferenceChip = editor._nodes?.get?.("reference-chip")?.klass;
|
|
14367
|
+
const Text = editor._nodes?.get?.("text")?.klass;
|
|
14368
|
+
const LineBreak = editor._nodes?.get?.("linebreak")?.klass;
|
|
14369
|
+
if (!ReferenceChip || !Text || !LineBreak) return;
|
|
14370
|
+
|
|
14371
|
+
const clean = text.replace(/[\uE100-\uE11D\uFFFC]/gu, "").replace(/\r\n?/g, "\n");
|
|
14372
|
+
const first = matchAtPluginMention(clean, 0, byLowerName, true);
|
|
14373
|
+
if (!first) return;
|
|
14374
|
+
|
|
14375
|
+
let inserted = false;
|
|
14376
|
+
editor.update(() => {
|
|
14377
|
+
const selection = editor._pendingEditorState?._selection;
|
|
14378
|
+
if (!selection?.anchor || !selection?.focus || typeof selection.insertNodes !== "function") return;
|
|
14379
|
+
const nodes = [];
|
|
14380
|
+
const appendText = (segment) => {
|
|
14381
|
+
const lines = segment.split("\n");
|
|
14382
|
+
for (let i = 0; i < lines.length; i++) {
|
|
14383
|
+
if (i > 0) nodes.push(new LineBreak());
|
|
14384
|
+
if (lines[i]) nodes.push(new Text(lines[i]));
|
|
14385
|
+
}
|
|
14386
|
+
};
|
|
14387
|
+
let cursor = 0;
|
|
14388
|
+
for (let match = first; match; match = matchAtPluginMention(clean, cursor, byLowerName, true)) {
|
|
14389
|
+
appendText(clean.slice(cursor, match.start));
|
|
14390
|
+
const ref = atPluginReference(clean.slice(match.start, match.end), match.data.label);
|
|
14391
|
+
nodes.push(new ReferenceChip(ref));
|
|
14392
|
+
cursor = match.end;
|
|
14393
|
+
}
|
|
14394
|
+
appendText(clean.slice(cursor));
|
|
14395
|
+
selection.insertNodes(nodes);
|
|
14396
|
+
inserted = true;
|
|
14397
|
+
}, { tag: "paste", discrete: true });
|
|
14398
|
+
if (inserted) {
|
|
14399
|
+
event.preventDefault();
|
|
14400
|
+
event.stopPropagation();
|
|
14401
|
+
}
|
|
14402
|
+
}
|
|
14403
|
+
|
|
14404
|
+
function readComposerPluginReference(chip, byLowerName) {
|
|
14405
|
+
const editor = chip.closest?.("[data-composer-input]")?.__lexicalEditor;
|
|
14406
|
+
const state = editor?.getEditorState?.();
|
|
14407
|
+
const node = state?._nodeMap?.get?.(chip[`__lexicalKey_${editor.getKey?.()}`]);
|
|
14408
|
+
if (typeof node?.getReference !== "function" || typeof state.read !== "function") return undefined;
|
|
14409
|
+
return state.read(() => matchAtPluginMention(node.getReference(), 0, byLowerName, true));
|
|
14410
|
+
}
|
|
14411
|
+
|
|
14412
|
+
function filterAtPluginCandidates(plugins, query) {
|
|
14413
|
+
const q = String(query || "").trim().toLowerCase();
|
|
14414
|
+
if (!q) return plugins;
|
|
14415
|
+
const prefixed = [];
|
|
14416
|
+
const matched = [];
|
|
14417
|
+
for (const plugin of plugins) {
|
|
14418
|
+
const nameLower = String(plugin.name || "").toLowerCase();
|
|
14419
|
+
const titleLower = String(plugin.displayName || plugin.name || "").toLowerCase();
|
|
14420
|
+
if (titleLower.startsWith(q) || nameLower.startsWith(q)) prefixed.push(plugin);
|
|
14421
|
+
else if (titleLower.includes(q) || nameLower.includes(q)) matched.push(plugin);
|
|
14422
|
+
}
|
|
14423
|
+
return prefixed.length && matched.length ? [...prefixed, ...matched] : (prefixed.length ? prefixed : matched);
|
|
14424
|
+
}
|
|
14425
|
+
|
|
14426
|
+
function createAtPluginsStore(ctx) {
|
|
14427
|
+
let plugins = [];
|
|
14428
|
+
let byLowerName = new Map();
|
|
14429
|
+
let byDisplayNameLower = new Map();
|
|
14430
|
+
let lexiconNames = [];
|
|
14431
|
+
let currentSignature = "";
|
|
14432
|
+
let hydrated = false;
|
|
14433
|
+
let disposed = false;
|
|
14434
|
+
let checkedAt = -Infinity;
|
|
14435
|
+
let fetchSeq = 0;
|
|
14436
|
+
let inFlight = null;
|
|
14437
|
+
let inFlightController = null;
|
|
14438
|
+
const listeners = new Set();
|
|
14439
|
+
const themeListeners = new Set();
|
|
14440
|
+
const iconComponents = new Map();
|
|
14441
|
+
const iconPluginRefs = new Map();
|
|
14442
|
+
const recentPicks = [];
|
|
14443
|
+
const refreshInterval = 10000;
|
|
14444
|
+
|
|
14445
|
+
function readCurrentDark() {
|
|
14446
|
+
try {
|
|
14447
|
+
if (typeof document !== "undefined" && document.body?.hasAttribute?.("data-ds-dark-theme")) {
|
|
14448
|
+
return true;
|
|
14449
|
+
}
|
|
14450
|
+
} catch {}
|
|
14451
|
+
const root = typeof document !== "undefined" ? document.documentElement : null;
|
|
14452
|
+
return isDarkMode(ctx, root);
|
|
14453
|
+
}
|
|
14454
|
+
|
|
14455
|
+
let lastDark = readCurrentDark();
|
|
14456
|
+
const onThemePotentiallyChanged = () => {
|
|
14457
|
+
if (disposed) return;
|
|
14458
|
+
const nextDark = readCurrentDark();
|
|
14459
|
+
if (nextDark === lastDark) return;
|
|
14460
|
+
lastDark = nextDark;
|
|
14461
|
+
for (const listener of Array.from(themeListeners)) {
|
|
14462
|
+
try { listener(nextDark); } catch {}
|
|
14463
|
+
}
|
|
14464
|
+
};
|
|
14465
|
+
|
|
14466
|
+
let themeObserver = null;
|
|
14467
|
+
if (typeof document !== "undefined" && typeof MutationObserver === "function") {
|
|
14468
|
+
const watchAttrs = ["data-ds-dark-theme", "data-theme", "class"];
|
|
14469
|
+
themeObserver = new MutationObserver(onThemePotentiallyChanged);
|
|
14470
|
+
if (document.body) themeObserver.observe(document.body, { attributes: true, attributeFilter: watchAttrs });
|
|
14471
|
+
if (document.documentElement) themeObserver.observe(document.documentElement, { attributes: true, attributeFilter: watchAttrs });
|
|
14472
|
+
}
|
|
14473
|
+
const darkMedia = typeof window !== "undefined" && typeof window.matchMedia === "function"
|
|
14474
|
+
? window.matchMedia("(prefers-color-scheme: dark)")
|
|
14475
|
+
: null;
|
|
14476
|
+
darkMedia?.addEventListener?.("change", onThemePotentiallyChanged);
|
|
14477
|
+
|
|
14478
|
+
function applyList(list) {
|
|
14479
|
+
const normalized = Array.isArray(list) ? list.filter((p) => p && typeof p.name === "string" && p.name) : [];
|
|
14480
|
+
const signature = JSON.stringify(normalized);
|
|
14481
|
+
hydrated = true;
|
|
14482
|
+
if (signature === currentSignature) return false;
|
|
14483
|
+
currentSignature = signature;
|
|
14484
|
+
plugins = normalized;
|
|
14485
|
+
byLowerName = new Map(normalized.map((p) => [p.name.toLowerCase(), p]));
|
|
14486
|
+
byDisplayNameLower = new Map();
|
|
14487
|
+
for (const p of normalized) {
|
|
14488
|
+
const dKey = String(p.displayName || p.name || "").trim().toLowerCase();
|
|
14489
|
+
if (dKey && !byDisplayNameLower.has(dKey)) byDisplayNameLower.set(dKey, p);
|
|
14490
|
+
}
|
|
14491
|
+
lexiconNames = normalized.map((p) => p.name);
|
|
14492
|
+
for (const listener of Array.from(listeners)) {
|
|
14493
|
+
try { listener(); } catch {}
|
|
14494
|
+
}
|
|
14495
|
+
return true;
|
|
14496
|
+
}
|
|
14497
|
+
|
|
14498
|
+
function pruneRecentPicks(nowMs = Date.now()) {
|
|
14499
|
+
while (recentPicks.length && nowMs - recentPicks[0].at > 5000) {
|
|
14500
|
+
recentPicks.shift();
|
|
14501
|
+
}
|
|
14502
|
+
}
|
|
14503
|
+
|
|
14504
|
+
function recordPick(name, displayName) {
|
|
14505
|
+
if (!name) return;
|
|
14506
|
+
const nowMs = Date.now();
|
|
14507
|
+
pruneRecentPicks(nowMs);
|
|
14508
|
+
recentPicks.push({
|
|
14509
|
+
name: String(name),
|
|
14510
|
+
displayNameLower: String(displayName || name).trim().toLowerCase(),
|
|
14511
|
+
at: nowMs,
|
|
14512
|
+
});
|
|
14513
|
+
if (recentPicks.length > 24) recentPicks.shift();
|
|
14514
|
+
}
|
|
14515
|
+
|
|
14516
|
+
function resolveChipPlugin({ name, label, consumePick = false } = {}) {
|
|
14517
|
+
if (name) {
|
|
14518
|
+
const direct = byLowerName.get(String(name).trim().toLowerCase());
|
|
14519
|
+
if (direct) return direct;
|
|
14520
|
+
}
|
|
14521
|
+
const labelLower = String(label || "").trim().toLowerCase();
|
|
14522
|
+
if (!labelLower) return null;
|
|
14523
|
+
if (consumePick && recentPicks.length > 0) {
|
|
14524
|
+
pruneRecentPicks();
|
|
14525
|
+
for (let i = recentPicks.length - 1; i >= 0; i--) {
|
|
14526
|
+
if (recentPicks[i].displayNameLower === labelLower) {
|
|
14527
|
+
const candidate = byLowerName.get(recentPicks[i].name.toLowerCase()) || null;
|
|
14528
|
+
if (candidate) {
|
|
14529
|
+
recentPicks.splice(i, 1);
|
|
14530
|
+
return candidate;
|
|
14531
|
+
}
|
|
14532
|
+
}
|
|
14533
|
+
}
|
|
14534
|
+
}
|
|
14535
|
+
return byDisplayNameLower.get(labelLower) || byLowerName.get(labelLower) || null;
|
|
14536
|
+
}
|
|
14537
|
+
|
|
14538
|
+
function getDescription(plugin, resolved = true) {
|
|
14539
|
+
if (!resolved || !plugin) return "该插件当前未启用或未安装";
|
|
14540
|
+
return plugin.shortDescription || plugin.description || plugin.summary || (plugin.author ? `by ${plugin.author}` : "暂无插件描述");
|
|
14541
|
+
}
|
|
14542
|
+
|
|
14543
|
+
function getIconComponent(plugin) {
|
|
14544
|
+
const lower = String(plugin?.name || "").toLowerCase();
|
|
14545
|
+
if (iconPluginRefs.size >= 512 && !iconPluginRefs.has(lower)) iconPluginRefs.clear();
|
|
14546
|
+
iconPluginRefs.set(lower, plugin);
|
|
14547
|
+
let Comp = iconComponents.get(lower);
|
|
14548
|
+
if (!Comp) {
|
|
14549
|
+
Comp = function AtPluginMenuIcon() {
|
|
14550
|
+
const current = byLowerName.get(lower) || iconPluginRefs.get(lower) || plugin;
|
|
14551
|
+
return h("span", { className: "cpm-at-plugin-icon", "aria-hidden": "true" },
|
|
14552
|
+
h(PluginIcon, { plugin: current, isDark: readCurrentDark(), eager: true, preferPreview: true })
|
|
14553
|
+
);
|
|
14554
|
+
};
|
|
14555
|
+
if (iconComponents.size >= 512) iconComponents.clear();
|
|
14556
|
+
iconComponents.set(lower, Comp);
|
|
14557
|
+
}
|
|
14558
|
+
return Comp;
|
|
14559
|
+
}
|
|
14560
|
+
|
|
14561
|
+
async function fetchFresh(force = false) {
|
|
14562
|
+
if (disposed) return plugins;
|
|
14563
|
+
if (inFlight && !force) return inFlight;
|
|
14564
|
+
if (force && inFlightController) {
|
|
14565
|
+
inFlightController.abort();
|
|
14566
|
+
inFlightController = null;
|
|
14567
|
+
inFlight = null;
|
|
14568
|
+
}
|
|
14569
|
+
const seq = ++fetchSeq;
|
|
14570
|
+
const controller = typeof AbortController === "function" ? new AbortController() : null;
|
|
14571
|
+
inFlightController = controller;
|
|
14572
|
+
checkedAt = Date.now();
|
|
14573
|
+
const run = (async () => {
|
|
14574
|
+
try {
|
|
14575
|
+
const data = await api("/at-plugins", controller ? { cache: "no-store", signal: controller.signal } : { cache: "no-store" });
|
|
14576
|
+
if (!disposed && seq === fetchSeq && (!controller || !controller.signal.aborted) && Array.isArray(data?.plugins)) {
|
|
14577
|
+
applyList(data.plugins);
|
|
14578
|
+
checkedAt = Date.now();
|
|
14579
|
+
}
|
|
14580
|
+
} catch {
|
|
14581
|
+
// Keep the last known snapshot when a background refresh fails or aborts.
|
|
14582
|
+
} finally {
|
|
14583
|
+
if (inFlight === run) {
|
|
14584
|
+
inFlightController = null;
|
|
14585
|
+
inFlight = null;
|
|
14586
|
+
}
|
|
14587
|
+
}
|
|
14588
|
+
return plugins;
|
|
14589
|
+
})();
|
|
14590
|
+
inFlight = run;
|
|
14591
|
+
return run;
|
|
14592
|
+
}
|
|
14593
|
+
|
|
14594
|
+
function raceWithSignal(promise, signal) {
|
|
14595
|
+
if (!signal) return promise;
|
|
14596
|
+
if (signal.aborted) return Promise.resolve([]);
|
|
14597
|
+
return new Promise((resolve) => {
|
|
14598
|
+
const onAbort = () => {
|
|
14599
|
+
signal.removeEventListener?.("abort", onAbort);
|
|
14600
|
+
resolve([]);
|
|
14601
|
+
};
|
|
14602
|
+
signal.addEventListener?.("abort", onAbort, { once: true });
|
|
14603
|
+
void promise.then((value) => {
|
|
14604
|
+
signal.removeEventListener?.("abort", onAbort);
|
|
14605
|
+
resolve(signal.aborted ? [] : value);
|
|
14606
|
+
});
|
|
14607
|
+
});
|
|
14608
|
+
}
|
|
14609
|
+
|
|
14610
|
+
const boot = globalThis.__UPH_AT_PLUGINS__;
|
|
14611
|
+
if (Array.isArray(boot)) {
|
|
14612
|
+
delete globalThis.__UPH_AT_PLUGINS__;
|
|
14613
|
+
applyList(boot);
|
|
14614
|
+
checkedAt = Date.now();
|
|
14615
|
+
}
|
|
14616
|
+
|
|
14617
|
+
const onInvalidate = () => {
|
|
14618
|
+
if (disposed) return;
|
|
14619
|
+
checkedAt = -Infinity;
|
|
14620
|
+
void fetchFresh(true);
|
|
14621
|
+
};
|
|
14622
|
+
const onVisibility = () => {
|
|
14623
|
+
if (typeof document !== "undefined" && document.hidden) return;
|
|
14624
|
+
if (!hydrated || Date.now() - checkedAt >= refreshInterval) {
|
|
14625
|
+
void fetchFresh(false);
|
|
14626
|
+
}
|
|
14627
|
+
};
|
|
14628
|
+
|
|
14629
|
+
if (typeof document !== "undefined" && typeof document.addEventListener === "function") {
|
|
14630
|
+
document.addEventListener("uph-at-plugins-changed", onInvalidate);
|
|
14631
|
+
document.addEventListener("uph-mcp-branding-changed", onInvalidate);
|
|
14632
|
+
document.addEventListener("visibilitychange", onVisibility);
|
|
14633
|
+
}
|
|
14634
|
+
const offReset = ctx.on?.("connection/reset", onInvalidate);
|
|
14635
|
+
const offChanged = ctx.on?.("plugin-manager/changed", onInvalidate);
|
|
14636
|
+
|
|
14637
|
+
return {
|
|
14638
|
+
warm() {
|
|
14639
|
+
if (!hydrated || Date.now() - checkedAt >= refreshInterval) {
|
|
14640
|
+
void fetchFresh(false);
|
|
14641
|
+
}
|
|
14642
|
+
},
|
|
14643
|
+
async candidates({ query, quoted, signal } = {}) {
|
|
14644
|
+
if (quoted === true || signal?.aborted) return [];
|
|
14645
|
+
if (!hydrated) {
|
|
14646
|
+
await raceWithSignal(fetchFresh(false), signal);
|
|
14647
|
+
if (!hydrated && inFlight && !signal?.aborted) {
|
|
14648
|
+
await raceWithSignal(inFlight, signal);
|
|
14649
|
+
}
|
|
14650
|
+
if (signal?.aborted) return [];
|
|
14651
|
+
} else if (Date.now() - checkedAt >= refreshInterval) {
|
|
14652
|
+
void fetchFresh(false);
|
|
14653
|
+
}
|
|
14654
|
+
const matches = filterAtPluginCandidates(plugins, query);
|
|
14655
|
+
return matches.map((plugin) => {
|
|
14656
|
+
const title = plugin.displayName || plugin.name;
|
|
14657
|
+
const summary = plugin.summary || plugin.shortDescription || plugin.description || (plugin.author ? `by ${plugin.author}` : "");
|
|
14658
|
+
return {
|
|
14659
|
+
name: title,
|
|
14660
|
+
...(summary ? { description: summary } : {}),
|
|
14661
|
+
icon: getIconComponent(plugin),
|
|
14662
|
+
section: "插件",
|
|
14663
|
+
value: JSON.stringify({ name: plugin.name, displayName: title }),
|
|
14664
|
+
};
|
|
14665
|
+
});
|
|
14666
|
+
},
|
|
14667
|
+
lexicon() {
|
|
14668
|
+
return hydrated ? lexiconNames : undefined;
|
|
14669
|
+
},
|
|
14670
|
+
lexiconKey() {
|
|
14671
|
+
return lexiconNames.join("\0");
|
|
14672
|
+
},
|
|
14673
|
+
subscribe(listener) {
|
|
14674
|
+
listeners.add(listener);
|
|
14675
|
+
return () => { listeners.delete(listener); };
|
|
14676
|
+
},
|
|
14677
|
+
subscribeTheme(listener) {
|
|
14678
|
+
themeListeners.add(listener);
|
|
14679
|
+
return () => { themeListeners.delete(listener); };
|
|
14680
|
+
},
|
|
14681
|
+
getByLowerName() {
|
|
14682
|
+
return byLowerName;
|
|
14683
|
+
},
|
|
14684
|
+
isHydrated() {
|
|
14685
|
+
return hydrated;
|
|
14686
|
+
},
|
|
14687
|
+
recordPick,
|
|
14688
|
+
resolveChipPlugin,
|
|
14689
|
+
getDescription,
|
|
14690
|
+
isDark() {
|
|
14691
|
+
return readCurrentDark();
|
|
14692
|
+
},
|
|
14693
|
+
dispose() {
|
|
14694
|
+
disposed = true;
|
|
14695
|
+
fetchSeq += 1;
|
|
14696
|
+
inFlightController?.abort();
|
|
14697
|
+
inFlightController = null;
|
|
14698
|
+
inFlight = null;
|
|
14699
|
+
listeners.clear();
|
|
14700
|
+
themeListeners.clear();
|
|
14701
|
+
iconComponents.clear();
|
|
14702
|
+
iconPluginRefs.clear();
|
|
14703
|
+
recentPicks.length = 0;
|
|
14704
|
+
try { themeObserver?.disconnect?.(); } catch {}
|
|
14705
|
+
themeObserver = null;
|
|
14706
|
+
try { darkMedia?.removeEventListener?.("change", onThemePotentiallyChanged); } catch {}
|
|
14707
|
+
if (typeof document !== "undefined" && typeof document.removeEventListener === "function") {
|
|
14708
|
+
document.removeEventListener("uph-at-plugins-changed", onInvalidate);
|
|
14709
|
+
document.removeEventListener("uph-mcp-branding-changed", onInvalidate);
|
|
14710
|
+
document.removeEventListener("visibilitychange", onVisibility);
|
|
14711
|
+
}
|
|
14712
|
+
try { offReset?.(); } catch {}
|
|
14713
|
+
try { offChanged?.(); } catch {}
|
|
14714
|
+
},
|
|
14715
|
+
};
|
|
14716
|
+
}
|
|
14717
|
+
|
|
14718
|
+
const AT_PLUGINS_ACTIVE_DISPOSE_KEY = "__UPH_AT_PLUGINS_DISPOSE__";
|
|
14719
|
+
|
|
14720
|
+
function cleanupStaleAtPluginDom(preserveOwnedSlots) {
|
|
14721
|
+
if (typeof document === "undefined" || typeof document.querySelectorAll !== "function") return;
|
|
14722
|
+
const oldHosts = document.querySelectorAll("[data-uph-at-plugins-overlay]");
|
|
14723
|
+
for (let i = 0; i < oldHosts.length; i++) oldHosts[i]?.remove?.();
|
|
14724
|
+
const oldSlots = document.querySelectorAll("[data-uph-chip-icon]");
|
|
14725
|
+
for (let i = 0; i < oldSlots.length; i++) {
|
|
14726
|
+
if (!preserveOwnedSlots || !preserveOwnedSlots.has(oldSlots[i])) oldSlots[i]?.remove?.();
|
|
14727
|
+
}
|
|
14728
|
+
if (!preserveOwnedSlots) {
|
|
14729
|
+
const oldStyles = document.querySelectorAll("style[data-uph-at-plugins]");
|
|
14730
|
+
for (let i = 0; i < oldStyles.length; i++) oldStyles[i]?.remove?.();
|
|
14731
|
+
const oldChips = document.querySelectorAll('[data-composer-chip="plugins"]');
|
|
14732
|
+
for (let i = 0; i < oldChips.length; i++) {
|
|
14733
|
+
const chip = oldChips[i];
|
|
14734
|
+
if (chip.dataset) {
|
|
14735
|
+
delete chip.dataset.uphPluginResolved;
|
|
14736
|
+
delete chip.dataset.uphPluginName;
|
|
14737
|
+
delete chip.dataset.uphPluginLabel;
|
|
14738
|
+
} else {
|
|
14739
|
+
chip.removeAttribute?.("data-uph-plugin-resolved");
|
|
14740
|
+
chip.removeAttribute?.("data-uph-plugin-name");
|
|
14741
|
+
chip.removeAttribute?.("data-uph-plugin-label");
|
|
14742
|
+
}
|
|
14743
|
+
}
|
|
14744
|
+
const oldDescribed = document.querySelectorAll('[aria-describedby="uph-at-plugin-hover-popover"]');
|
|
14745
|
+
for (let i = 0; i < oldDescribed.length; i++) oldDescribed[i]?.removeAttribute?.("aria-describedby");
|
|
14746
|
+
}
|
|
14747
|
+
}
|
|
14748
|
+
|
|
14749
|
+
function installAtPlugins(ctx) {
|
|
14750
|
+
if (typeof globalThis !== "undefined" && typeof globalThis[AT_PLUGINS_ACTIVE_DISPOSE_KEY] === "function") {
|
|
14751
|
+
try { globalThis[AT_PLUGINS_ACTIVE_DISPOSE_KEY](); } catch {}
|
|
14752
|
+
}
|
|
14753
|
+
cleanupStaleAtPluginDom();
|
|
14754
|
+
let disposed = false;
|
|
14755
|
+
const disposers = [];
|
|
14756
|
+
const disposeAll = () => {
|
|
14757
|
+
if (disposed) return;
|
|
14758
|
+
disposed = true;
|
|
14759
|
+
if (typeof globalThis !== "undefined" && globalThis[AT_PLUGINS_ACTIVE_DISPOSE_KEY] === disposeAll) {
|
|
14760
|
+
delete globalThis[AT_PLUGINS_ACTIVE_DISPOSE_KEY];
|
|
14761
|
+
}
|
|
14762
|
+
for (let i = disposers.length - 1; i >= 0; i--) {
|
|
14763
|
+
try { disposers[i]?.(); } catch {}
|
|
14764
|
+
}
|
|
14765
|
+
};
|
|
14766
|
+
const collectDisposer = (handle) => {
|
|
14767
|
+
if (typeof handle === "function") disposers.push(handle);
|
|
14768
|
+
else if (typeof handle?.dispose === "function") disposers.push(() => handle.dispose());
|
|
14769
|
+
};
|
|
14770
|
+
if (typeof globalThis !== "undefined") globalThis[AT_PLUGINS_ACTIVE_DISPOSE_KEY] = disposeAll;
|
|
14771
|
+
try {
|
|
14772
|
+
const store = createAtPluginsStore(ctx);
|
|
14773
|
+
disposers.push(() => store.dispose());
|
|
14774
|
+
if (typeof document !== "undefined" && document.head) {
|
|
14775
|
+
const style = document.createElement("style");
|
|
14776
|
+
style.dataset.plugin = "universal-plugin-hub";
|
|
14777
|
+
style.dataset.uphAtPlugins = "";
|
|
14778
|
+
style.textContent = AT_PLUGINS_CSS;
|
|
14779
|
+
document.head.append(style);
|
|
14780
|
+
disposers.push(() => style.remove());
|
|
14781
|
+
}
|
|
14782
|
+
|
|
14783
|
+
const ReactDOM = (() => { try { return require("react-dom") || null; } catch { return null; } })();
|
|
14784
|
+
const ReactDOMClient = (() => { try { return require("react-dom/client") || null; } catch { return null; } })();
|
|
14785
|
+
|
|
14786
|
+
function PluginMentionChip({ node }) {
|
|
14787
|
+
const [revision, setRevision] = useState(0);
|
|
14788
|
+
useEffect(() => {
|
|
14789
|
+
const bump = () => setRevision((r) => r + 1);
|
|
14790
|
+
const offStore = store.subscribe(bump);
|
|
14791
|
+
const offTheme = store.subscribeTheme(bump);
|
|
14792
|
+
return () => {
|
|
14793
|
+
offStore();
|
|
14794
|
+
offTheme();
|
|
14795
|
+
};
|
|
14796
|
+
}, []);
|
|
14797
|
+
void revision;
|
|
14798
|
+
const live = store.getByLowerName().get(String(node?.data?.name || "").toLowerCase()) || null;
|
|
14799
|
+
const label = live?.displayName || node?.data?.label || node?.data?.name || "";
|
|
14800
|
+
return h("span", {
|
|
14801
|
+
className: "cpm-at-plugin-chip" + (live ? "" : " is-unresolved"),
|
|
14802
|
+
"data-uph-plugin-chip": "true",
|
|
14803
|
+
"data-uph-plugin-name": live?.name || node?.data?.name || "",
|
|
14804
|
+
"data-uph-plugin-label": label,
|
|
14805
|
+
},
|
|
14806
|
+
live
|
|
14807
|
+
? h("span", { className: "cpm-at-plugin-chip-icon-wrap", "aria-hidden": "true" },
|
|
14808
|
+
h("span", { className: "cpm-at-plugin-chip-icon" },
|
|
14809
|
+
h(PluginIcon, { plugin: live, isDark: store.isDark(), eager: true, preferPreview: true })
|
|
14810
|
+
)
|
|
14811
|
+
)
|
|
14812
|
+
: h("span", { className: "cpm-at-plugin-chip-marker", "aria-hidden": "true" }, "@"),
|
|
14813
|
+
h("span", { className: "cpm-at-plugin-chip-label" }, label)
|
|
14814
|
+
);
|
|
14815
|
+
}
|
|
14816
|
+
|
|
14817
|
+
function PluginChipHoverPopover({ hovered, isDark, session }) {
|
|
14818
|
+
const popRef = useRef(null);
|
|
14819
|
+
const [position, setPosition] = useState(null);
|
|
14820
|
+
const lastContentRef = useRef({ description: "", resolved: true });
|
|
14821
|
+
if (hovered) {
|
|
14822
|
+
lastContentRef.current = {
|
|
14823
|
+
description: hovered.description || "",
|
|
14824
|
+
resolved: hovered.resolved !== false,
|
|
14825
|
+
};
|
|
14826
|
+
}
|
|
14827
|
+
|
|
14828
|
+
useSafeLayoutEffect(() => {
|
|
14829
|
+
const popup = popRef.current;
|
|
14830
|
+
if (!popup) return;
|
|
14831
|
+
if (!popup.hasAttribute("popover")) {
|
|
14832
|
+
try { popup.setAttribute("popover", "hint"); } catch {}
|
|
14833
|
+
}
|
|
14834
|
+
if (!hovered?.anchor?.isConnected) {
|
|
14835
|
+
popup.removeAttribute("data-open");
|
|
14836
|
+
if (typeof popup.hidePopover === "function") {
|
|
14837
|
+
try { if (popup.matches?.(":popover-open")) popup.hidePopover(); } catch {}
|
|
14838
|
+
}
|
|
14839
|
+
setPosition(null);
|
|
14840
|
+
return;
|
|
14841
|
+
}
|
|
14842
|
+
|
|
14843
|
+
const anchor = hovered.anchor;
|
|
14844
|
+
const prevDescribedBy = anchor.getAttribute("aria-describedby");
|
|
14845
|
+
const ownsDescribedBy = prevDescribedBy === null;
|
|
14846
|
+
if (ownsDescribedBy) anchor.setAttribute("aria-describedby", "uph-at-plugin-hover-popover");
|
|
14847
|
+
|
|
14848
|
+
setPosition(null);
|
|
14849
|
+
popup.setAttribute("data-open", "true");
|
|
14850
|
+
if (typeof popup.showPopover === "function") {
|
|
14851
|
+
try { if (!popup.matches?.(":popover-open")) popup.showPopover(); } catch {}
|
|
14852
|
+
}
|
|
14853
|
+
|
|
14854
|
+
const measure = () => {
|
|
14855
|
+
if (!anchor.isConnected) return;
|
|
14856
|
+
const trigger = anchor.getBoundingClientRect();
|
|
14857
|
+
if (!trigger || (trigger.width <= 0 && trigger.height <= 0)) return;
|
|
14858
|
+
const measured = popup.getBoundingClientRect();
|
|
14859
|
+
const vw = typeof window !== "undefined" ? (window.innerWidth || 0) : 0;
|
|
14860
|
+
const vh = typeof window !== "undefined" ? (window.innerHeight || 0) : 0;
|
|
14861
|
+
setPosition(placePluginChipPopover(trigger, measured.width || 192, measured.height || 36, { width: vw, height: vh }));
|
|
14862
|
+
};
|
|
14863
|
+
measure();
|
|
14864
|
+
const observer = typeof ResizeObserver === "function" ? new ResizeObserver(measure) : null;
|
|
14865
|
+
observer?.observe(popup);
|
|
14866
|
+
const detach = session.attach(popup, anchor);
|
|
14867
|
+
return () => {
|
|
14868
|
+
observer?.disconnect();
|
|
14869
|
+
detach();
|
|
14870
|
+
if (ownsDescribedBy && anchor.getAttribute("aria-describedby") === "uph-at-plugin-hover-popover") {
|
|
14871
|
+
anchor.removeAttribute("aria-describedby");
|
|
14872
|
+
}
|
|
14873
|
+
};
|
|
14874
|
+
}, [hovered, session]);
|
|
14875
|
+
|
|
14876
|
+
const viewContent = hovered || lastContentRef.current;
|
|
14877
|
+
return h("div", {
|
|
14878
|
+
id: "uph-at-plugin-hover-popover",
|
|
14879
|
+
ref: popRef,
|
|
14880
|
+
role: "tooltip",
|
|
14881
|
+
className: "cpm-at-plugin-popover" + (isDark ? " cpm-dark" : ""),
|
|
14882
|
+
"data-placement": position?.placement || "top",
|
|
14883
|
+
"data-unresolved": viewContent.resolved === false ? "true" : undefined,
|
|
14884
|
+
style: {
|
|
14885
|
+
left: `${position?.left ?? 12}px`,
|
|
14886
|
+
top: `${position?.top ?? 12}px`,
|
|
14887
|
+
visibility: hovered && position ? "visible" : "hidden",
|
|
14888
|
+
pointerEvents: !hovered ? "none" : undefined,
|
|
14889
|
+
transformOrigin: position ? `${position.originX}px ${position.originY}` : "50% 100%",
|
|
14890
|
+
},
|
|
14891
|
+
onWheel: (e) => e.stopPropagation(),
|
|
14892
|
+
onScroll: (e) => e.stopPropagation(),
|
|
14893
|
+
},
|
|
14894
|
+
h("p", { className: "cpm-at-plugin-popover-desc" }, viewContent.description)
|
|
14895
|
+
);
|
|
14896
|
+
}
|
|
14897
|
+
|
|
14898
|
+
// Syncs DSH Lexical composer chips (`[data-composer-chip="plugins"]`): strips browser `title`,
|
|
14899
|
+
// replaces the default `@` marker with the crisp plugin icon without stretching line-height,
|
|
14900
|
+
// and shares one top-layer frosted glass description popover across composer + message chips.
|
|
14901
|
+
if (typeof document !== "undefined") {
|
|
14902
|
+
const chipIds = new WeakMap();
|
|
14903
|
+
const ownedSlots = new WeakSet();
|
|
14904
|
+
const selfRemovedSlots = new WeakSet();
|
|
14905
|
+
let nextChipId = 1;
|
|
14906
|
+
let knownComposerEl = null;
|
|
14907
|
+
let syncQueued = false;
|
|
14908
|
+
let blockDisposed = false;
|
|
14909
|
+
let activeOverlayState = { chips: [], hovered: null, isDark: store.isDark() };
|
|
14910
|
+
let setOverlayState = null;
|
|
14911
|
+
let hoverSession = null;
|
|
14912
|
+
|
|
14913
|
+
const getChipId = (el) => {
|
|
14914
|
+
let id = chipIds.get(el);
|
|
14915
|
+
if (!id) {
|
|
14916
|
+
id = `chip-${nextChipId++}`;
|
|
14917
|
+
chipIds.set(el, id);
|
|
14918
|
+
}
|
|
14919
|
+
return id;
|
|
14920
|
+
};
|
|
14921
|
+
|
|
14922
|
+
const stripNativeTitle = (el) => {
|
|
14923
|
+
if (el.hasAttribute?.("title")) el.removeAttribute("title");
|
|
14924
|
+
if (typeof el.querySelectorAll === "function") {
|
|
14925
|
+
const titled = el.querySelectorAll("[title]");
|
|
14926
|
+
for (let i = 0; i < titled.length; i++) titled[i].removeAttribute("title");
|
|
14927
|
+
}
|
|
14928
|
+
};
|
|
14929
|
+
|
|
14930
|
+
const readComposerChipLabel = (el) => {
|
|
14931
|
+
const children = Array.from(el.children || []);
|
|
14932
|
+
const reactSpan = children.find((c) => !c.hasAttribute?.("data-uph-chip-icon"));
|
|
14933
|
+
if (!reactSpan) return String(el.textContent || "").replace(/^@/, "").trim();
|
|
14934
|
+
const reactChildren = Array.from(reactSpan.children || []);
|
|
14935
|
+
if (reactChildren.length >= 2) {
|
|
14936
|
+
return String(reactChildren[reactChildren.length - 1]?.textContent || "").trim();
|
|
14937
|
+
}
|
|
14938
|
+
return String(reactSpan.textContent || "").replace(/^@/, "").trim();
|
|
14939
|
+
};
|
|
14940
|
+
|
|
14941
|
+
const syncComposerChips = () => {
|
|
14942
|
+
syncQueued = false;
|
|
14943
|
+
if (blockDisposed) return;
|
|
14944
|
+
const nodes = typeof document.querySelectorAll === "function"
|
|
14945
|
+
? Array.from(document.querySelectorAll('[data-composer-chip="plugins"]'))
|
|
14946
|
+
: [];
|
|
14947
|
+
if (nodes.length > 0 && !store.isHydrated()) store.warm();
|
|
14948
|
+
|
|
14949
|
+
const nextChips = [];
|
|
14950
|
+
for (const el of nodes) {
|
|
14951
|
+
stripNativeTitle(el);
|
|
14952
|
+
const label = readComposerChipLabel(el);
|
|
14953
|
+
const reference = readComposerPluginReference(el, store.getByLowerName());
|
|
14954
|
+
const prevName = el.dataset?.uphPluginName || el.getAttribute?.("data-uph-plugin-name") || "";
|
|
14955
|
+
const prevLabel = el.dataset?.uphPluginLabel || el.getAttribute?.("data-uph-plugin-label") || "";
|
|
14956
|
+
const reusedForDifferentLabel = Boolean(prevLabel && label && prevLabel.toLowerCase() !== label.toLowerCase());
|
|
14957
|
+
let live = (prevName && !reusedForDifferentLabel)
|
|
14958
|
+
? (store.getByLowerName().get(prevName.toLowerCase()) || null)
|
|
14959
|
+
: null;
|
|
14960
|
+
if (reference) {
|
|
14961
|
+
live = store.getByLowerName().get(reference.data.name.toLowerCase()) || null;
|
|
14962
|
+
} else if (!live) {
|
|
14963
|
+
live = store.resolveChipPlugin({ label, consumePick: true });
|
|
14964
|
+
}
|
|
14965
|
+
|
|
14966
|
+
const existingSlots = Array.from(el.children || []).filter((c) => c.hasAttribute?.("data-uph-chip-icon"));
|
|
14967
|
+
let ownedSlot = existingSlots.find((c) => ownedSlots.has(c)) || null;
|
|
14968
|
+
for (let i = 0; i < existingSlots.length; i++) {
|
|
14969
|
+
if (existingSlots[i] !== ownedSlot) {
|
|
14970
|
+
selfRemovedSlots.add(existingSlots[i]);
|
|
14971
|
+
existingSlots[i].remove?.();
|
|
14972
|
+
}
|
|
14973
|
+
}
|
|
14974
|
+
if (live) {
|
|
14975
|
+
if (el.dataset) {
|
|
14976
|
+
el.dataset.uphPluginResolved = "true";
|
|
14977
|
+
el.dataset.uphPluginName = live.name;
|
|
14978
|
+
el.dataset.uphPluginLabel = label || live.displayName || live.name;
|
|
14979
|
+
} else {
|
|
14980
|
+
el.setAttribute("data-uph-plugin-resolved", "true");
|
|
14981
|
+
el.setAttribute("data-uph-plugin-name", live.name);
|
|
14982
|
+
el.setAttribute("data-uph-plugin-label", label || live.displayName || live.name);
|
|
14983
|
+
}
|
|
14984
|
+
let iconSlot = ownedSlot;
|
|
14985
|
+
if (!iconSlot && typeof document.createElement === "function") {
|
|
14986
|
+
iconSlot = document.createElement("span");
|
|
14987
|
+
iconSlot.className = "cpm-at-plugin-chip-icon-wrap";
|
|
14988
|
+
iconSlot.setAttribute("data-uph-chip-icon", "");
|
|
14989
|
+
iconSlot.setAttribute("aria-hidden", "true");
|
|
14990
|
+
ownedSlots.add(iconSlot);
|
|
14991
|
+
el.prepend(iconSlot);
|
|
14992
|
+
} else if (iconSlot && el.children?.[0] !== iconSlot && typeof el.prepend === "function") {
|
|
14993
|
+
el.prepend(iconSlot);
|
|
14994
|
+
}
|
|
14995
|
+
if (iconSlot) {
|
|
14996
|
+
nextChips.push({ key: getChipId(el), chipEl: el, iconSlot, plugin: live });
|
|
14997
|
+
}
|
|
14998
|
+
} else {
|
|
14999
|
+
if (el.dataset) {
|
|
15000
|
+
delete el.dataset.uphPluginResolved;
|
|
15001
|
+
el.dataset.uphPluginName = "";
|
|
15002
|
+
el.dataset.uphPluginLabel = label;
|
|
15003
|
+
} else {
|
|
15004
|
+
el.removeAttribute?.("data-uph-plugin-resolved");
|
|
15005
|
+
el.setAttribute?.("data-uph-plugin-name", "");
|
|
15006
|
+
el.setAttribute?.("data-uph-plugin-label", label);
|
|
15007
|
+
}
|
|
15008
|
+
if (ownedSlot) {
|
|
15009
|
+
selfRemovedSlots.add(ownedSlot);
|
|
15010
|
+
ownedSlot.remove();
|
|
15011
|
+
}
|
|
15012
|
+
}
|
|
15013
|
+
}
|
|
15014
|
+
|
|
15015
|
+
const dark = (nextChips.length > 0 || activeOverlayState.chips.length > 0 || Boolean(activeOverlayState.hovered))
|
|
15016
|
+
? store.isDark()
|
|
15017
|
+
: activeOverlayState.isDark;
|
|
15018
|
+
const sameChips = activeOverlayState.isDark === dark &&
|
|
15019
|
+
activeOverlayState.chips.length === nextChips.length &&
|
|
15020
|
+
activeOverlayState.chips.every((prev, i) => (
|
|
15021
|
+
prev.chipEl === nextChips[i].chipEl &&
|
|
15022
|
+
prev.iconSlot === nextChips[i].iconSlot &&
|
|
15023
|
+
prev.plugin === nextChips[i].plugin
|
|
15024
|
+
));
|
|
15025
|
+
if (!sameChips) {
|
|
15026
|
+
activeOverlayState = { ...activeOverlayState, chips: nextChips, isDark: dark };
|
|
15027
|
+
setOverlayState?.(activeOverlayState);
|
|
15028
|
+
}
|
|
15029
|
+
if (activeOverlayState.hovered?.anchor && !activeOverlayState.hovered.anchor.isConnected) {
|
|
15030
|
+
hoverSession?.dismiss();
|
|
15031
|
+
}
|
|
15032
|
+
};
|
|
15033
|
+
|
|
15034
|
+
const scheduleChipSync = () => {
|
|
15035
|
+
if (blockDisposed || syncQueued) return;
|
|
15036
|
+
syncQueued = true;
|
|
15037
|
+
if (typeof queueMicrotask === "function") queueMicrotask(syncComposerChips);
|
|
15038
|
+
else Promise.resolve().then(syncComposerChips);
|
|
15039
|
+
};
|
|
15040
|
+
|
|
15041
|
+
const buildChipHoverPayload = (anchor) => {
|
|
15042
|
+
const name = anchor.dataset?.uphPluginName || anchor.getAttribute?.("data-uph-plugin-name") || "";
|
|
15043
|
+
const label = anchor.dataset?.uphPluginLabel || anchor.getAttribute?.("data-uph-plugin-label") || "";
|
|
15044
|
+
const live = store.resolveChipPlugin({ name, label });
|
|
15045
|
+
return live
|
|
15046
|
+
? { name: live.name, description: store.getDescription(live, true), resolved: true }
|
|
15047
|
+
: { name, description: store.getDescription(null, false), resolved: false };
|
|
15048
|
+
};
|
|
15049
|
+
|
|
15050
|
+
hoverSession = createHoverSession({
|
|
15051
|
+
initialDelay: 160,
|
|
15052
|
+
onChange(next) {
|
|
15053
|
+
if (blockDisposed) return;
|
|
15054
|
+
activeOverlayState = { ...activeOverlayState, hovered: next, isDark: store.isDark() };
|
|
15055
|
+
setOverlayState?.(activeOverlayState);
|
|
15056
|
+
},
|
|
15057
|
+
});
|
|
15058
|
+
|
|
15059
|
+
const findPluginChipAnchor = (target) => (
|
|
15060
|
+
target?.closest?.('[data-composer-chip="plugins"], .cpm-at-plugin-chip') || null
|
|
15061
|
+
);
|
|
15062
|
+
|
|
15063
|
+
const onPointerOver = (event) => {
|
|
15064
|
+
if (blockDisposed || event.pointerType === "touch") return;
|
|
15065
|
+
const anchor = findPluginChipAnchor(event.target);
|
|
15066
|
+
if (!anchor) return;
|
|
15067
|
+
hoverSession.enter(
|
|
15068
|
+
buildChipHoverPayload(anchor),
|
|
15069
|
+
anchor,
|
|
15070
|
+
{ x: event.clientX, y: event.clientY, buttons: event.buttons },
|
|
15071
|
+
false
|
|
15072
|
+
);
|
|
15073
|
+
};
|
|
15074
|
+
|
|
15075
|
+
const onFocusIn = (event) => {
|
|
15076
|
+
if (blockDisposed) return;
|
|
15077
|
+
const anchor = findPluginChipAnchor(event.target);
|
|
15078
|
+
if (!anchor) return;
|
|
15079
|
+
if (anchor === document.activeElement || anchor.contains?.(document.activeElement)) {
|
|
15080
|
+
hoverSession.enter(buildChipHoverPayload(anchor), anchor, null, true);
|
|
15081
|
+
}
|
|
15082
|
+
};
|
|
15083
|
+
|
|
15084
|
+
const onComposerKeyDown = (event) => {
|
|
15085
|
+
if (blockDisposed || !activeOverlayState.hovered) return;
|
|
15086
|
+
if (event.key === "Shift" || event.key === "Control" || event.key === "Alt" || event.key === "Meta") return;
|
|
15087
|
+
if (event.target?.closest?.("[data-composer-input]")) {
|
|
15088
|
+
hoverSession.dismiss();
|
|
15089
|
+
}
|
|
15090
|
+
};
|
|
15091
|
+
|
|
15092
|
+
const updateDarkOverlayState = () => {
|
|
15093
|
+
if (blockDisposed) return;
|
|
15094
|
+
const dark = store.isDark();
|
|
15095
|
+
if (dark !== activeOverlayState.isDark) {
|
|
15096
|
+
activeOverlayState = { ...activeOverlayState, isDark: dark };
|
|
15097
|
+
setOverlayState?.(activeOverlayState);
|
|
15098
|
+
}
|
|
15099
|
+
};
|
|
15100
|
+
|
|
15101
|
+
const isSelfOwnedIconMutation = (m) => {
|
|
15102
|
+
if (m.type !== "childList") return false;
|
|
15103
|
+
if (m.target?.getAttribute?.("data-composer-chip") !== "plugins") return false;
|
|
15104
|
+
const addedLen = m.addedNodes?.length || 0;
|
|
15105
|
+
const removedLen = m.removedNodes?.length || 0;
|
|
15106
|
+
if (addedLen === 0 && removedLen === 0) return false;
|
|
15107
|
+
for (let i = 0; i < addedLen; i++) {
|
|
15108
|
+
if (!ownedSlots.has(m.addedNodes[i])) return false;
|
|
15109
|
+
}
|
|
15110
|
+
for (let i = 0; i < removedLen; i++) {
|
|
15111
|
+
const rem = m.removedNodes[i];
|
|
15112
|
+
if (!selfRemovedSlots.has(rem) && !(addedLen > 0 && ownedSlots.has(rem))) return false;
|
|
15113
|
+
}
|
|
15114
|
+
return true;
|
|
15115
|
+
};
|
|
15116
|
+
|
|
15117
|
+
let domObserver = null;
|
|
15118
|
+
if (typeof MutationObserver === "function" && document.body) {
|
|
15119
|
+
knownComposerEl = document.querySelector?.("[data-composer-input]") || null;
|
|
15120
|
+
domObserver = new MutationObserver((mutations) => {
|
|
15121
|
+
if (blockDisposed) return;
|
|
15122
|
+
let needSync = false;
|
|
15123
|
+
let hasRemovals = false;
|
|
15124
|
+
let composerConnected = Boolean(knownComposerEl?.isConnected);
|
|
15125
|
+
let lookedUpComposer = false;
|
|
15126
|
+
const ensureComposer = () => {
|
|
15127
|
+
if (composerConnected) return knownComposerEl;
|
|
15128
|
+
if (!lookedUpComposer) {
|
|
15129
|
+
lookedUpComposer = true;
|
|
15130
|
+
knownComposerEl = document.querySelector?.("[data-composer-input]") || null;
|
|
15131
|
+
composerConnected = Boolean(knownComposerEl?.isConnected);
|
|
15132
|
+
if (composerConnected) needSync = true;
|
|
15133
|
+
}
|
|
15134
|
+
return composerConnected ? knownComposerEl : null;
|
|
15135
|
+
};
|
|
15136
|
+
for (const m of mutations) {
|
|
15137
|
+
if (m.target?.closest?.("[data-uph-chip-icon]")) continue;
|
|
15138
|
+
if (isSelfOwnedIconMutation(m)) continue;
|
|
15139
|
+
if (m.type === "attributes") {
|
|
15140
|
+
const tgt = m.target;
|
|
15141
|
+
if (tgt?.hasAttribute?.("title") && tgt.closest?.('[data-composer-chip="plugins"]')) {
|
|
15142
|
+
tgt.removeAttribute("title");
|
|
15143
|
+
}
|
|
15144
|
+
continue;
|
|
15145
|
+
}
|
|
15146
|
+
if (m.type === "childList") {
|
|
15147
|
+
if (m.removedNodes.length > 0) hasRemovals = true;
|
|
15148
|
+
if (composerConnected && knownComposerEl.contains(m.target)) {
|
|
15149
|
+
needSync = true;
|
|
15150
|
+
continue;
|
|
15151
|
+
}
|
|
15152
|
+
let hasAddedElement = false;
|
|
15153
|
+
for (let i = 0; i < m.addedNodes.length; i++) {
|
|
15154
|
+
const added = m.addedNodes[i];
|
|
15155
|
+
if (added?.nodeType !== 1) continue;
|
|
15156
|
+
hasAddedElement = true;
|
|
15157
|
+
if (
|
|
15158
|
+
added.getAttribute?.("data-composer-chip") === "plugins" ||
|
|
15159
|
+
added.getAttribute?.("data-composer-input") !== null ||
|
|
15160
|
+
added.querySelector?.('[data-composer-chip="plugins"]')
|
|
15161
|
+
) {
|
|
15162
|
+
needSync = true;
|
|
15163
|
+
break;
|
|
15164
|
+
}
|
|
15165
|
+
}
|
|
15166
|
+
if (!composerConnected && hasAddedElement && !needSync) {
|
|
15167
|
+
ensureComposer();
|
|
15168
|
+
}
|
|
15169
|
+
}
|
|
15170
|
+
}
|
|
15171
|
+
if (hasRemovals) {
|
|
15172
|
+
if (activeOverlayState.hovered?.anchor && !activeOverlayState.hovered.anchor.isConnected) {
|
|
15173
|
+
hoverSession?.dismiss();
|
|
15174
|
+
}
|
|
15175
|
+
if (!needSync && activeOverlayState.chips.some((c) => !c.chipEl.isConnected)) {
|
|
15176
|
+
needSync = true;
|
|
15177
|
+
}
|
|
15178
|
+
}
|
|
15179
|
+
if (needSync) scheduleChipSync();
|
|
15180
|
+
});
|
|
15181
|
+
domObserver.observe(document.body, {
|
|
15182
|
+
childList: true,
|
|
15183
|
+
subtree: true,
|
|
15184
|
+
attributes: true,
|
|
15185
|
+
attributeFilter: ["title"],
|
|
15186
|
+
});
|
|
15187
|
+
disposers.push(() => domObserver.disconnect());
|
|
15188
|
+
}
|
|
15189
|
+
|
|
15190
|
+
disposers.push(store.subscribeTheme(updateDarkOverlayState));
|
|
15191
|
+
|
|
15192
|
+
if (typeof document.addEventListener === "function") {
|
|
15193
|
+
const onPaste = (event) => pasteAtPluginReferences(event, store.getByLowerName());
|
|
15194
|
+
document.addEventListener("paste", onPaste, true);
|
|
15195
|
+
document.addEventListener("pointerover", onPointerOver, true);
|
|
15196
|
+
document.addEventListener("focusin", onFocusIn, true);
|
|
15197
|
+
document.addEventListener("keydown", onComposerKeyDown, true);
|
|
15198
|
+
disposers.push(() => {
|
|
15199
|
+
document.removeEventListener("paste", onPaste, true);
|
|
15200
|
+
document.removeEventListener("pointerover", onPointerOver, true);
|
|
15201
|
+
document.removeEventListener("focusin", onFocusIn, true);
|
|
15202
|
+
document.removeEventListener("keydown", onComposerKeyDown, true);
|
|
15203
|
+
});
|
|
15204
|
+
}
|
|
15205
|
+
|
|
15206
|
+
if (typeof window !== "undefined" && typeof window.addEventListener === "function" && typeof document.addEventListener === "function") {
|
|
15207
|
+
const unbindHover = hoverSession.bind(document, window);
|
|
15208
|
+
disposers.push(unbindHover);
|
|
15209
|
+
} else {
|
|
15210
|
+
disposers.push(() => hoverSession.dismiss(false));
|
|
15211
|
+
}
|
|
15212
|
+
|
|
15213
|
+
const offStoreSync = store.subscribe(() => {
|
|
15214
|
+
if (blockDisposed) return;
|
|
15215
|
+
syncComposerChips();
|
|
15216
|
+
const curHovered = activeOverlayState.hovered;
|
|
15217
|
+
if (curHovered?.anchor?.isConnected) {
|
|
15218
|
+
const refreshed = buildChipHoverPayload(curHovered.anchor);
|
|
15219
|
+
const dark = store.isDark();
|
|
15220
|
+
if (
|
|
15221
|
+
dark !== activeOverlayState.isDark ||
|
|
15222
|
+
refreshed.name !== curHovered.name ||
|
|
15223
|
+
refreshed.description !== curHovered.description ||
|
|
15224
|
+
refreshed.resolved !== curHovered.resolved
|
|
15225
|
+
) {
|
|
15226
|
+
activeOverlayState = {
|
|
15227
|
+
...activeOverlayState,
|
|
15228
|
+
isDark: dark,
|
|
15229
|
+
hovered: { ...curHovered, ...refreshed },
|
|
15230
|
+
};
|
|
15231
|
+
setOverlayState?.(activeOverlayState);
|
|
15232
|
+
}
|
|
15233
|
+
}
|
|
15234
|
+
});
|
|
15235
|
+
disposers.push(offStoreSync);
|
|
15236
|
+
|
|
15237
|
+
if (ReactDOM?.createPortal && ReactDOMClient?.createRoot && document.body && typeof document.createElement === "function") {
|
|
15238
|
+
const overlayHost = document.createElement("div");
|
|
15239
|
+
overlayHost.setAttribute("data-uph-at-plugins-overlay", "");
|
|
15240
|
+
overlayHost.style.display = "contents";
|
|
15241
|
+
document.body.append(overlayHost);
|
|
15242
|
+
|
|
15243
|
+
function AtPluginsOverlay() {
|
|
15244
|
+
const [overlayState, setLocalState] = useState(activeOverlayState);
|
|
15245
|
+
useEffect(() => {
|
|
15246
|
+
setOverlayState = setLocalState;
|
|
15247
|
+
setLocalState(activeOverlayState);
|
|
15248
|
+
return () => { if (setOverlayState === setLocalState) setOverlayState = null; };
|
|
15249
|
+
}, []);
|
|
15250
|
+
return h(React.Fragment, null,
|
|
15251
|
+
overlayState.chips.map((entry) => (
|
|
15252
|
+
entry.iconSlot?.isConnected
|
|
15253
|
+
? ReactDOM.createPortal(
|
|
15254
|
+
h("span", { className: "cpm-at-plugin-chip-icon" },
|
|
15255
|
+
h(PluginIcon, { plugin: entry.plugin, isDark: overlayState.isDark, eager: true, preferPreview: true })
|
|
15256
|
+
),
|
|
15257
|
+
entry.iconSlot,
|
|
15258
|
+
entry.key
|
|
15259
|
+
)
|
|
15260
|
+
: null
|
|
15261
|
+
)),
|
|
15262
|
+
h(PluginChipHoverPopover, {
|
|
15263
|
+
hovered: overlayState.hovered,
|
|
15264
|
+
isDark: overlayState.isDark,
|
|
15265
|
+
session: hoverSession,
|
|
15266
|
+
})
|
|
15267
|
+
);
|
|
15268
|
+
}
|
|
15269
|
+
|
|
15270
|
+
const overlayRoot = ReactDOMClient.createRoot(overlayHost);
|
|
15271
|
+
overlayRoot.render(h(AtPluginsOverlay));
|
|
15272
|
+
disposers.push(() => {
|
|
15273
|
+
setOverlayState = null;
|
|
15274
|
+
activeOverlayState = { chips: [], hovered: null, isDark: false };
|
|
15275
|
+
cleanupStaleAtPluginDom();
|
|
15276
|
+
try { overlayRoot.unmount(); } catch {}
|
|
15277
|
+
try { overlayHost.remove(); } catch {}
|
|
15278
|
+
});
|
|
15279
|
+
} else {
|
|
15280
|
+
disposers.push(() => cleanupStaleAtPluginDom());
|
|
15281
|
+
}
|
|
15282
|
+
disposers.push(() => {
|
|
15283
|
+
blockDisposed = true;
|
|
15284
|
+
syncQueued = false;
|
|
15285
|
+
});
|
|
15286
|
+
|
|
15287
|
+
syncComposerChips();
|
|
15288
|
+
}
|
|
15289
|
+
|
|
15290
|
+
const triggerSource = {
|
|
15291
|
+
trigger: "@",
|
|
15292
|
+
name: "plugins",
|
|
15293
|
+
order: -1,
|
|
15294
|
+
showGroupTitle: false,
|
|
15295
|
+
warm() {
|
|
15296
|
+
store.warm();
|
|
15297
|
+
},
|
|
15298
|
+
lexicon() {
|
|
15299
|
+
return store.lexicon();
|
|
15300
|
+
},
|
|
15301
|
+
subscribeLexicon(_session, listener) {
|
|
15302
|
+
return store.subscribe(listener);
|
|
15303
|
+
},
|
|
15304
|
+
candidates(_session, req) {
|
|
15305
|
+
return store.candidates(req);
|
|
15306
|
+
},
|
|
15307
|
+
onPick({ candidate }) {
|
|
15308
|
+
const picked = parseAtPluginCandidateValue(candidate?.value);
|
|
15309
|
+
if (!picked) return undefined;
|
|
15310
|
+
store.recordPick(picked.name, picked.displayName);
|
|
15311
|
+
const mention = formatAtPluginMention(picked.name, picked.displayName);
|
|
15312
|
+
return { insert: atPluginReference(mention, picked.displayName) };
|
|
15313
|
+
},
|
|
15314
|
+
codec: {
|
|
15315
|
+
clipboardText: (ref) => ref,
|
|
15316
|
+
serialize: (ref) => Promise.resolve(ref),
|
|
15317
|
+
},
|
|
15318
|
+
};
|
|
15319
|
+
|
|
15320
|
+
collectDisposer(ctx.inject?.(["inputTriggers"], (hostCtx) => {
|
|
15321
|
+
if (typeof hostCtx?.inputTriggers?.registerSource !== "function") return;
|
|
15322
|
+
hostCtx.effect?.(() => hostCtx.inputTriggers.registerSource(triggerSource), "universal-plugin-hub: @ plugins trigger");
|
|
15323
|
+
}));
|
|
15324
|
+
|
|
15325
|
+
collectDisposer(ctx.inject?.(["uiConversation"], (hostCtx) => {
|
|
15326
|
+
const registerRule = () => hostCtx?.uiConversation?.userText?.register?.({
|
|
15327
|
+
id: "uph-plugin",
|
|
15328
|
+
order: 15,
|
|
15329
|
+
match(text, from) {
|
|
15330
|
+
return matchAtPluginMention(text, from, store.getByLowerName());
|
|
15331
|
+
},
|
|
15332
|
+
});
|
|
15333
|
+
if (typeof hostCtx?.uiConversation?.userText?.register !== "function") return;
|
|
15334
|
+
hostCtx.effect?.(() => {
|
|
15335
|
+
let effectDisposed = false;
|
|
15336
|
+
let offRule = registerRule();
|
|
15337
|
+
let prevLexKey = store.lexiconKey();
|
|
15338
|
+
const offSub = store.subscribe(() => {
|
|
15339
|
+
if (effectDisposed) return;
|
|
15340
|
+
const nextLexKey = store.lexiconKey();
|
|
15341
|
+
if (nextLexKey === prevLexKey) return;
|
|
15342
|
+
prevLexKey = nextLexKey;
|
|
15343
|
+
try { offRule?.(); } catch {}
|
|
15344
|
+
offRule = registerRule();
|
|
15345
|
+
});
|
|
15346
|
+
return () => {
|
|
15347
|
+
effectDisposed = true;
|
|
15348
|
+
offSub();
|
|
15349
|
+
try { offRule?.(); } catch {}
|
|
15350
|
+
};
|
|
15351
|
+
}, "universal-plugin-hub: @ plugins user-text");
|
|
15352
|
+
}));
|
|
15353
|
+
|
|
15354
|
+
if (typeof ctx.slots?.inject === "function") {
|
|
15355
|
+
const offSlotInject = ctx.slots.inject("conversation.user.text.node", () => ctx.slots.register({
|
|
15356
|
+
name: "conversation.user.text.node",
|
|
15357
|
+
key: "uph-plugin",
|
|
15358
|
+
priority: 100,
|
|
15359
|
+
}, PluginMentionChip));
|
|
15360
|
+
collectDisposer(offSlotInject);
|
|
15361
|
+
} else if (typeof ctx.slots?.register === "function") {
|
|
15362
|
+
const offNodeSlot = ctx.slots.register({
|
|
15363
|
+
name: "conversation.user.text.node",
|
|
15364
|
+
key: "uph-plugin",
|
|
15365
|
+
priority: 100,
|
|
15366
|
+
}, PluginMentionChip);
|
|
15367
|
+
collectDisposer(offNodeSlot);
|
|
15368
|
+
}
|
|
15369
|
+
|
|
15370
|
+
return disposeAll;
|
|
15371
|
+
} catch (err) {
|
|
15372
|
+
disposeAll();
|
|
15373
|
+
throw err;
|
|
15374
|
+
}
|
|
15375
|
+
}
|
|
15376
|
+
|
|
13138
15377
|
const name = "universal-plugin-hub";
|
|
13139
15378
|
const inject = ["slots", "theme"];
|
|
13140
15379
|
|
|
@@ -13145,6 +15384,7 @@ window.__ModuleLoader__.load({ id: "universal-plugin-hub", factory: (require) =>
|
|
|
13145
15384
|
iconsReady = dispose.ready;
|
|
13146
15385
|
return dispose;
|
|
13147
15386
|
}, "universal-plugin-hub: tool call icons");
|
|
15387
|
+
ctx.effect?.(() => installAtPlugins(ctx), "universal-plugin-hub: @ plugins");
|
|
13148
15388
|
ctx.slots.inject("sidebar.panellist", () => ctx.slots.register({
|
|
13149
15389
|
name: "sidebar.panellist",
|
|
13150
15390
|
id: "universal-plugin-hub",
|