vite-plugin-refresh-guard 0.1.2 → 0.1.3
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/CHANGELOG.md +4 -0
- package/README.en.md +23 -0
- package/README.md +23 -0
- package/dist/react/UpdatePrompt.js +23 -18
- package/dist/vue/UpdatePrompt.vue +32 -24
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,9 @@
|
|
|
1
1
|
# 更新日志
|
|
2
2
|
|
|
3
|
+
## v0.1.3 (2026-08-09)
|
|
4
|
+
|
|
5
|
+
`UpdatePrompt` 默认样式全部改成 `var(--rg-*, 默认值)` 的写法,颜色/圆角都能被外部 CSS 变量覆盖,不用改包源码就能换成自己的品牌色(README 新增"样式定制"一节说明全部变量)。默认样式本身也精修了一版(更大的圆角、更细腻的阴影分层、按钮 hover/active 反馈、标题加了个 ✨),不设置任何变量也比之前顺眼。
|
|
6
|
+
|
|
3
7
|
## v0.1.2 (2026-08-09)
|
|
4
8
|
|
|
5
9
|
修 `UpdatePrompt` 两个实测踩到的问题(在一个真实项目里第一次接入后暴露的):
|
package/README.en.md
CHANGED
|
@@ -157,6 +157,29 @@ deciding "when do we reload" are different product decisions, and coupling them
|
|
|
157
157
|
of the projects this package was extracted from originally did) is how you end up with two
|
|
158
158
|
mechanisms fighting each other.
|
|
159
159
|
|
|
160
|
+
## Styling
|
|
161
|
+
|
|
162
|
+
`UpdatePrompt` ships with a generic blue-on-white look and doesn't assume your brand colors. Every color/radius reads a `--rg-*` CSS custom property first, falling back to a default — set these anywhere in your own global styles (`:root` or any ancestor) to make the modal match your product without touching the package source:
|
|
163
|
+
|
|
164
|
+
```css
|
|
165
|
+
:root {
|
|
166
|
+
--rg-accent: var(--brand); /* primary button color, default #2563eb */
|
|
167
|
+
--rg-accent-fg: #fff; /* primary button text color */
|
|
168
|
+
--rg-radius: 16px; /* modal/toast corner radius */
|
|
169
|
+
--rg-modal-bg: #fff; /* modal background (light) */
|
|
170
|
+
--rg-modal-fg: #111827; /* modal text (light) */
|
|
171
|
+
--rg-modal-bg-dark: #1f2937; /* modal background (dark, paired with :dark or OS dark mode) */
|
|
172
|
+
--rg-modal-fg-dark: #f3f4f6;
|
|
173
|
+
--rg-body-fg: #4b5563; /* body text color */
|
|
174
|
+
--rg-body-fg-dark: #d1d5db;
|
|
175
|
+
--rg-overlay-bg: rgba(15, 15, 20, 0.55); /* backdrop behind the modal */
|
|
176
|
+
--rg-toast-bg: #1f2937; /* toast-auto mode's notice bar */
|
|
177
|
+
--rg-toast-fg: #fff;
|
|
178
|
+
}
|
|
179
|
+
```
|
|
180
|
+
|
|
181
|
+
You don't need to set all of them — override just `--rg-accent` for a quick brand match and leave the rest at their defaults.
|
|
182
|
+
|
|
160
183
|
## Why not just service workers?
|
|
161
184
|
|
|
162
185
|
`vite-plugin-pwa`'s `autoUpdate` mode is a perfectly good `silent` implementation if you're
|
package/README.md
CHANGED
|
@@ -146,6 +146,29 @@ import { latestVersion, latestContent } from 'virtual:refresh-guard-changelog'
|
|
|
146
146
|
|
|
147
147
|
从你的 `CHANGELOG.md` 里解析 `## vX.Y.Z (date)` 这种格式的标题(跟 Keep a Changelog 及大多数自动生成的更新日志一致),暴露最新一条的版本号和 markdown 正文。这个功能故意跟"什么时候刷新"的逻辑解耦——"展示更新了什么"和"什么时候该刷新"是两个不同的产品决策,本包最初就是从几个把这两件事强行绑死在一起的项目里抽出来的,绑死的下场就是两套机制互相打架。
|
|
148
148
|
|
|
149
|
+
## 样式定制
|
|
150
|
+
|
|
151
|
+
`UpdatePrompt` 默认是通用蓝白配色,不假设你的品牌色。所有颜色/圆角都先读一个 `--rg-*` CSS 变量,读不到才用默认值——在你自己项目的全局样式里(`:root` 或任意祖先节点)设置这些变量,就能让弹窗跟你的产品长一个样,不用改包的源码:
|
|
152
|
+
|
|
153
|
+
```css
|
|
154
|
+
:root {
|
|
155
|
+
--rg-accent: var(--brand); /* 主按钮颜色,默认 #2563eb */
|
|
156
|
+
--rg-accent-fg: #fff; /* 主按钮文字颜色 */
|
|
157
|
+
--rg-radius: 16px; /* 弹窗/toast 圆角 */
|
|
158
|
+
--rg-modal-bg: #fff; /* 弹窗背景(浅色) */
|
|
159
|
+
--rg-modal-fg: #111827; /* 弹窗文字(浅色) */
|
|
160
|
+
--rg-modal-bg-dark: #1f2937; /* 弹窗背景(深色,配合 :dark 或系统深色模式) */
|
|
161
|
+
--rg-modal-fg-dark: #f3f4f6;
|
|
162
|
+
--rg-body-fg: #4b5563; /* 正文文字颜色 */
|
|
163
|
+
--rg-body-fg-dark: #d1d5db;
|
|
164
|
+
--rg-overlay-bg: rgba(15, 15, 20, 0.55); /* 弹窗背后的遮罩 */
|
|
165
|
+
--rg-toast-bg: #1f2937; /* toast-auto 模式的提示条 */
|
|
166
|
+
--rg-toast-fg: #fff;
|
|
167
|
+
}
|
|
168
|
+
```
|
|
169
|
+
|
|
170
|
+
不需要全套都设,只想换主按钮颜色就只设 `--rg-accent` 即可,其余保持默认。
|
|
171
|
+
|
|
149
172
|
## 为什么不干脆只用 service worker
|
|
150
173
|
|
|
151
174
|
如果你已经在跑 service worker,`vite-plugin-pwa` 的 `autoUpdate` 模式本身就是一个很好的 `silent` 实现——本包不是要替代它。本包补的是:一套统一的方式,能拿到 `toast-auto` 或 `modal-blocking` 的体验(裸 service worker 想要这个得自己手写这整套管线);一个不需要 service worker 的、纯靠轮询 `version.json` 的兜底方案;以及独立的更新日志展示层。哪块需要用哪块,互相不绑定。
|
|
@@ -21,10 +21,10 @@ function UpdatePrompt({ visible, mode = "toast-auto", version = null, changelogH
|
|
|
21
21
|
return createPortal(
|
|
22
22
|
/* @__PURE__ */ jsx("div", { style: styles.overlay, role: "alertdialog", "aria-modal": "true", children: /* @__PURE__ */ jsxs("div", { style: modalStyle, children: [
|
|
23
23
|
/* @__PURE__ */ jsxs("h3", { style: styles.title, children: [
|
|
24
|
-
"\u6709\u65B0\u7248\u672C\u53EF\u7528",
|
|
24
|
+
"\u2728 \u6709\u65B0\u7248\u672C\u53EF\u7528",
|
|
25
25
|
version ? `\uFF1A${version}` : ""
|
|
26
26
|
] }),
|
|
27
|
-
changelogHtml ? /* @__PURE__ */ jsx("div", { style: bodyStyle, dangerouslySetInnerHTML: { __html: changelogHtml } }) : /* @__PURE__ */ jsx("p", { style: { ...bodyStyle, color: dark ? "#9ca3af" : "#6b7280" }, children: "\u5237\u65B0\u9875\u9762\u5373\u53EF\u4F7F\u7528\u6700\u65B0\u7248\u672C\u3002" }),
|
|
27
|
+
changelogHtml ? /* @__PURE__ */ jsx("div", { style: bodyStyle, dangerouslySetInnerHTML: { __html: changelogHtml } }) : /* @__PURE__ */ jsx("p", { style: { ...bodyStyle, color: dark ? "var(--rg-body-fg-dark, #9ca3af)" : "var(--rg-body-fg, #6b7280)" }, children: "\u5237\u65B0\u9875\u9762\u5373\u53EF\u4F7F\u7528\u6700\u65B0\u7248\u672C\u3002" }),
|
|
28
28
|
/* @__PURE__ */ jsx("button", { type: "button", style: styles.primaryBtn, onClick: onRefresh, children: "\u7ACB\u5373\u66F4\u65B0" })
|
|
29
29
|
] }) }),
|
|
30
30
|
document.body
|
|
@@ -40,9 +40,9 @@ var styles = {
|
|
|
40
40
|
alignItems: "center",
|
|
41
41
|
gap: 12,
|
|
42
42
|
padding: "10px 16px",
|
|
43
|
-
borderRadius:
|
|
44
|
-
background: "#1f2937",
|
|
45
|
-
color: "#fff",
|
|
43
|
+
borderRadius: "var(--rg-radius, 10px)",
|
|
44
|
+
background: "var(--rg-toast-bg, #1f2937)",
|
|
45
|
+
color: "var(--rg-toast-fg, #fff)",
|
|
46
46
|
fontSize: 13,
|
|
47
47
|
boxShadow: "0 4px 16px rgba(0,0,0,0.2)"
|
|
48
48
|
},
|
|
@@ -52,7 +52,7 @@ var styles = {
|
|
|
52
52
|
borderRadius: 6,
|
|
53
53
|
border: "1px solid rgba(255,255,255,0.3)",
|
|
54
54
|
background: "transparent",
|
|
55
|
-
color: "
|
|
55
|
+
color: "inherit",
|
|
56
56
|
fontSize: 12,
|
|
57
57
|
cursor: "pointer"
|
|
58
58
|
},
|
|
@@ -63,26 +63,31 @@ var styles = {
|
|
|
63
63
|
display: "flex",
|
|
64
64
|
alignItems: "center",
|
|
65
65
|
justifyContent: "center",
|
|
66
|
-
background: "rgba(
|
|
66
|
+
background: "var(--rg-overlay-bg, rgba(15,15,20,0.55))"
|
|
67
67
|
},
|
|
68
68
|
modal: {
|
|
69
69
|
width: "90vw",
|
|
70
70
|
maxWidth: 420,
|
|
71
|
-
padding:
|
|
72
|
-
borderRadius:
|
|
73
|
-
background: "#fff",
|
|
74
|
-
color: "#111827",
|
|
75
|
-
boxShadow: "0
|
|
71
|
+
padding: 28,
|
|
72
|
+
borderRadius: "var(--rg-radius, 16px)",
|
|
73
|
+
background: "var(--rg-modal-bg, #fff)",
|
|
74
|
+
color: "var(--rg-modal-fg, #111827)",
|
|
75
|
+
boxShadow: "0 20px 50px rgba(0,0,0,0.2), 0 2px 8px rgba(0,0,0,0.08)"
|
|
76
76
|
},
|
|
77
|
-
|
|
78
|
-
|
|
77
|
+
modalDark: {
|
|
78
|
+
background: "var(--rg-modal-bg-dark, #1f2937)",
|
|
79
|
+
color: "var(--rg-modal-fg-dark, #f3f4f6)"
|
|
80
|
+
},
|
|
81
|
+
title: { margin: "0 0 14px", fontSize: 17, fontWeight: 700, letterSpacing: "-0.01em" },
|
|
82
|
+
body: { margin: "0 0 22px", fontSize: 13.5, lineHeight: 1.7, color: "var(--rg-body-fg, #4b5563)", maxHeight: "40vh", overflowY: "auto" },
|
|
83
|
+
bodyDark: { color: "var(--rg-body-fg-dark, #d1d5db)" },
|
|
79
84
|
primaryBtn: {
|
|
80
85
|
width: "100%",
|
|
81
|
-
padding:
|
|
86
|
+
padding: 11,
|
|
82
87
|
border: "none",
|
|
83
|
-
borderRadius:
|
|
84
|
-
background: "#2563eb",
|
|
85
|
-
color: "#fff",
|
|
88
|
+
borderRadius: "var(--rg-btn-radius, 10px)",
|
|
89
|
+
background: "var(--rg-accent, #2563eb)",
|
|
90
|
+
color: "var(--rg-accent-fg, #fff)",
|
|
86
91
|
fontSize: 14,
|
|
87
92
|
fontWeight: 600,
|
|
88
93
|
cursor: "pointer"
|
|
@@ -39,7 +39,7 @@ const shown = computed(() => props.visible && props.mode !== 'silent')
|
|
|
39
39
|
|
|
40
40
|
<div v-if="shown && mode === 'modal-blocking'" class="rg-overlay" role="alertdialog" aria-modal="true">
|
|
41
41
|
<div class="rg-modal" :class="{ 'rg-dark': dark === true, 'rg-light': dark === false }">
|
|
42
|
-
<h3 class="rg-title"
|
|
42
|
+
<h3 class="rg-title">✨ 有新版本可用{{ version ? `:${version}` : '' }}</h3>
|
|
43
43
|
<div v-if="changelogHtml" class="rg-body" v-html="changelogHtml" />
|
|
44
44
|
<p v-else class="rg-body rg-body-empty">刷新页面即可使用最新版本。</p>
|
|
45
45
|
<button type="button" class="rg-primary-btn" @click="emit('refresh')">立即更新</button>
|
|
@@ -49,6 +49,11 @@ const shown = computed(() => props.visible && props.mode !== 'silent')
|
|
|
49
49
|
</template>
|
|
50
50
|
|
|
51
51
|
<style scoped>
|
|
52
|
+
/*
|
|
53
|
+
* Every color/radius here reads from a --rg-* custom property first, falling back to a
|
|
54
|
+
* reasonable default — set these on :root (or any ancestor) in your own app to re-skin the
|
|
55
|
+
* component to your brand instead of living with generic blue-on-white. See README "Styling".
|
|
56
|
+
*/
|
|
52
57
|
.rg-toast {
|
|
53
58
|
position: fixed;
|
|
54
59
|
right: 16px;
|
|
@@ -58,9 +63,9 @@ const shown = computed(() => props.visible && props.mode !== 'silent')
|
|
|
58
63
|
align-items: center;
|
|
59
64
|
gap: 12px;
|
|
60
65
|
padding: 10px 16px;
|
|
61
|
-
border-radius:
|
|
62
|
-
background: #1f2937;
|
|
63
|
-
color: #fff;
|
|
66
|
+
border-radius: var(--rg-radius, 10px);
|
|
67
|
+
background: var(--rg-toast-bg, #1f2937);
|
|
68
|
+
color: var(--rg-toast-fg, #fff);
|
|
64
69
|
font-size: 13px;
|
|
65
70
|
box-shadow: 0 4px 16px rgba(0, 0, 0, 0.2);
|
|
66
71
|
}
|
|
@@ -70,11 +75,12 @@ const shown = computed(() => props.visible && props.mode !== 'silent')
|
|
|
70
75
|
border: 1px solid rgba(255, 255, 255, 0.3);
|
|
71
76
|
border-radius: 6px;
|
|
72
77
|
background: transparent;
|
|
73
|
-
color:
|
|
78
|
+
color: inherit;
|
|
74
79
|
font-size: 12px;
|
|
75
80
|
cursor: pointer;
|
|
81
|
+
transition: background 0.15s ease;
|
|
76
82
|
}
|
|
77
|
-
.rg-toast-btn:hover { background: rgba(255, 255, 255, 0.
|
|
83
|
+
.rg-toast-btn:hover { background: rgba(255, 255, 255, 0.12); }
|
|
78
84
|
|
|
79
85
|
.rg-overlay {
|
|
80
86
|
position: fixed;
|
|
@@ -83,37 +89,39 @@ const shown = computed(() => props.visible && props.mode !== 'silent')
|
|
|
83
89
|
display: flex;
|
|
84
90
|
align-items: center;
|
|
85
91
|
justify-content: center;
|
|
86
|
-
background: rgba(
|
|
92
|
+
background: var(--rg-overlay-bg, rgba(15, 15, 20, 0.55));
|
|
87
93
|
}
|
|
88
94
|
.rg-modal {
|
|
89
95
|
width: 90vw;
|
|
90
96
|
max-width: 420px;
|
|
91
|
-
padding:
|
|
92
|
-
border-radius:
|
|
93
|
-
background: #fff;
|
|
94
|
-
color: #111827;
|
|
95
|
-
box-shadow: 0
|
|
97
|
+
padding: 28px;
|
|
98
|
+
border-radius: var(--rg-radius, 16px);
|
|
99
|
+
background: var(--rg-modal-bg, #fff);
|
|
100
|
+
color: var(--rg-modal-fg, #111827);
|
|
101
|
+
box-shadow: 0 20px 50px rgba(0, 0, 0, 0.2), 0 2px 8px rgba(0, 0, 0, 0.08);
|
|
96
102
|
}
|
|
97
|
-
.rg-title { margin: 0 0
|
|
98
|
-
.rg-body { margin: 0 0
|
|
99
|
-
.rg-body-empty { color: #6b7280; }
|
|
103
|
+
.rg-title { margin: 0 0 14px; font-size: 17px; font-weight: 700; letter-spacing: -0.01em; }
|
|
104
|
+
.rg-body { margin: 0 0 22px; font-size: 13.5px; line-height: 1.7; color: var(--rg-body-fg, #4b5563); max-height: 40vh; overflow-y: auto; }
|
|
105
|
+
.rg-body-empty { color: var(--rg-body-fg, #6b7280); }
|
|
100
106
|
.rg-primary-btn {
|
|
101
107
|
width: 100%;
|
|
102
|
-
padding:
|
|
108
|
+
padding: 11px;
|
|
103
109
|
border: none;
|
|
104
|
-
border-radius:
|
|
105
|
-
background: #2563eb;
|
|
106
|
-
color: #fff;
|
|
110
|
+
border-radius: var(--rg-btn-radius, 10px);
|
|
111
|
+
background: var(--rg-accent, #2563eb);
|
|
112
|
+
color: var(--rg-accent-fg, #fff);
|
|
107
113
|
font-size: 14px;
|
|
108
114
|
font-weight: 600;
|
|
109
115
|
cursor: pointer;
|
|
116
|
+
transition: filter 0.15s ease, transform 0.05s ease;
|
|
110
117
|
}
|
|
111
|
-
.rg-primary-btn:hover {
|
|
118
|
+
.rg-primary-btn:hover { filter: brightness(0.92); }
|
|
119
|
+
.rg-primary-btn:active { transform: scale(0.99); }
|
|
112
120
|
|
|
113
|
-
.rg-modal.rg-dark { background: #1f2937; color: #f3f4f6; }
|
|
114
|
-
.rg-modal.rg-dark .rg-body { color: #d1d5db; }
|
|
121
|
+
.rg-modal.rg-dark { background: var(--rg-modal-bg-dark, #1f2937); color: var(--rg-modal-fg-dark, #f3f4f6); }
|
|
122
|
+
.rg-modal.rg-dark .rg-body { color: var(--rg-body-fg-dark, #d1d5db); }
|
|
115
123
|
@media (prefers-color-scheme: dark) {
|
|
116
|
-
.rg-modal:not(.rg-light) { background: #1f2937; color: #f3f4f6; }
|
|
117
|
-
.rg-modal:not(.rg-light) .rg-body { color: #d1d5db; }
|
|
124
|
+
.rg-modal:not(.rg-light) { background: var(--rg-modal-bg-dark, #1f2937); color: var(--rg-modal-fg-dark, #f3f4f6); }
|
|
125
|
+
.rg-modal:not(.rg-light) .rg-body { color: var(--rg-body-fg-dark, #d1d5db); }
|
|
118
126
|
}
|
|
119
127
|
</style>
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "vite-plugin-refresh-guard",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.3",
|
|
4
4
|
"description": "Vite 应用的可配置版本更新检测+刷新方案:静默自动刷新 / 提示后自动刷新 / 弹窗阻断,按产品需要选档位,核心逻辑框架无关,附 Vue/React 适配层。Configurable new-version detection + refresh for Vite apps — silent / toast-auto / modal-blocking, framework-agnostic core with Vue and React adapters.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|