forgepress 0.0.1 → 0.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/THIRD-PARTY-LICENSES.md +28 -83
- package/dist/_chunks/client.d.mts +1 -1
- package/dist/_chunks/config.mjs +61 -19
- package/dist/_chunks/{validate.mjs → content.mjs} +350 -217
- package/dist/_chunks/fetch.mjs +2 -2
- package/dist/_chunks/files.mjs +32 -0
- package/dist/_chunks/libs/diff.mjs +485 -0
- package/dist/_chunks/media.mjs +282 -0
- package/dist/_chunks/once.mjs +16 -0
- package/dist/_chunks/output.mjs +98 -252
- package/dist/_chunks/plugin.mjs +87 -0
- package/dist/_chunks/preview.mjs +248 -0
- package/dist/_chunks/project.d.mts +7 -0
- package/dist/_chunks/reader.mjs +5 -9
- package/dist/_chunks/reader2.mjs +150 -202
- package/dist/_chunks/references.mjs +8 -5
- package/dist/_chunks/resolve.d.mts +2 -0
- package/dist/_chunks/response.mjs +5 -0
- package/dist/_chunks/routes.mjs +9 -0
- package/dist/_chunks/serialize.mjs +82 -0
- package/dist/_chunks/settings.mjs +328 -0
- package/dist/_chunks/settings2.mjs +2 -0
- package/dist/_chunks/types.d.mts +229 -24
- package/dist/_chunks/types2.d.mts +25 -0
- package/dist/_chunks/value.mjs +123 -1
- package/dist/cli/bin.mjs +50 -37
- package/dist/editor/index.mjs +9961 -8653
- package/dist/index.d.mts +2 -3
- package/dist/index.mjs +14 -24
- package/dist/next/preview.d.mts +1 -0
- package/dist/next/preview.mjs +3 -0
- package/dist/next/reload.d.mts +1 -0
- package/dist/next/reload.mjs +20 -0
- package/dist/next/settings.d.mts +12 -0
- package/dist/next/settings.mjs +2 -0
- package/dist/plugin/next.d.mts +11 -0
- package/dist/plugin/next.mjs +213 -0
- package/dist/plugin/nuxt.d.mts +7 -0
- package/dist/plugin/nuxt.mjs +52 -0
- package/dist/plugin/watcher.d.mts +1 -0
- package/dist/plugin/watcher.mjs +23 -0
- package/dist/preview/index.d.mts +1 -2
- package/dist/preview/index.mjs +1 -243
- package/dist/preview/react.d.mts +1 -0
- package/dist/preview/react.mjs +34 -0
- package/dist/unplugin.d.mts +12 -17
- package/dist/unplugin.mjs +1 -500
- package/package.json +72 -8
- package/dist/_chunks/config.d.mts +0 -35
- package/dist/_chunks/entry.d.mts +0 -194
- package/dist/_chunks/libs/@oxc-project/types.d.mts +0 -1297
- package/dist/_chunks/libs/@rolldown/pluginutils.d.mts +0 -62
- package/dist/_chunks/libs/rolldown.d.mts +0 -4711
- package/dist/_chunks/output2.mjs +0 -333
- package/dist/_chunks/parse.mjs +0 -22
- package/dist/_chunks/types.mjs +0 -2
package/dist/preview/index.mjs
CHANGED
|
@@ -1,244 +1,2 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { errorMessage } from "../_chunks/error.mjs";
|
|
3
|
-
const TAG = "forgepress-preview";
|
|
4
|
-
const HIDING = "forgepress-preview-hiding";
|
|
5
|
-
const LABELS = {
|
|
6
|
-
loading: "Loading preview…",
|
|
7
|
-
ready: "Preview",
|
|
8
|
-
failed: "Preview unavailable"
|
|
9
|
-
};
|
|
10
|
-
const STYLE = `
|
|
11
|
-
:host {
|
|
12
|
-
all: initial;
|
|
13
|
-
position: fixed;
|
|
14
|
-
left: 16px;
|
|
15
|
-
bottom: 16px;
|
|
16
|
-
z-index: 2147483647;
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
.badge {
|
|
20
|
-
display: flex;
|
|
21
|
-
align-items: center;
|
|
22
|
-
gap: 8px;
|
|
23
|
-
padding: 4px 4px 4px 12px;
|
|
24
|
-
border-radius: 999px;
|
|
25
|
-
background: #13110e;
|
|
26
|
-
color: #fffcf8;
|
|
27
|
-
font: 500 13px/20px ui-sans-serif, system-ui, sans-serif;
|
|
28
|
-
box-shadow: 0 4px 16px rgb(19 17 14 / 0.3);
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
.dot {
|
|
32
|
-
width: 8px;
|
|
33
|
-
height: 8px;
|
|
34
|
-
border-radius: 50%;
|
|
35
|
-
background: #ffd27a;
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
[data-status="loading"] .dot {
|
|
39
|
-
animation: pulse 1s ease-in-out infinite;
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
[data-status="failed"] .dot {
|
|
43
|
-
background: #f87171;
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
button {
|
|
47
|
-
all: unset;
|
|
48
|
-
padding: 2px 10px;
|
|
49
|
-
border-radius: 999px;
|
|
50
|
-
color: #ffd27a;
|
|
51
|
-
cursor: pointer;
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
button:hover {
|
|
55
|
-
background: rgb(255 252 248 / 0.12);
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
button:focus-visible {
|
|
59
|
-
outline: 2px solid #ffd27a;
|
|
60
|
-
outline-offset: 2px;
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
@keyframes pulse {
|
|
64
|
-
50% {
|
|
65
|
-
opacity: 0.4;
|
|
66
|
-
}
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
@media (prefers-reduced-motion: reduce) {
|
|
70
|
-
[data-status="loading"] .dot {
|
|
71
|
-
animation: none;
|
|
72
|
-
}
|
|
73
|
-
}
|
|
74
|
-
`;
|
|
75
|
-
function createBadge(turnOff) {
|
|
76
|
-
let host;
|
|
77
|
-
let badge;
|
|
78
|
-
let label;
|
|
79
|
-
let latest;
|
|
80
|
-
function hideInEditor() {
|
|
81
|
-
if (document.getElementById(HIDING)) return;
|
|
82
|
-
const style = document.createElement("style");
|
|
83
|
-
style.id = HIDING;
|
|
84
|
-
style.textContent = `body:has([data-forgepress-editor]) > ${TAG} { display: none !important; }`;
|
|
85
|
-
document.head.append(style);
|
|
86
|
-
}
|
|
87
|
-
function mount() {
|
|
88
|
-
hideInEditor();
|
|
89
|
-
host = document.createElement(TAG);
|
|
90
|
-
badge = document.createElement("div");
|
|
91
|
-
label = document.createElement("span");
|
|
92
|
-
const root = host.attachShadow({ mode: "open" });
|
|
93
|
-
const style = document.createElement("style");
|
|
94
|
-
const dot = document.createElement("span");
|
|
95
|
-
const button = document.createElement("button");
|
|
96
|
-
style.textContent = STYLE;
|
|
97
|
-
badge.className = "badge";
|
|
98
|
-
badge.setAttribute("role", "status");
|
|
99
|
-
dot.className = "dot";
|
|
100
|
-
button.type = "button";
|
|
101
|
-
button.textContent = "Turn off";
|
|
102
|
-
button.setAttribute("aria-label", "Turn off preview");
|
|
103
|
-
button.addEventListener("click", turnOff);
|
|
104
|
-
badge.append(dot, label, button);
|
|
105
|
-
root.append(style, badge);
|
|
106
|
-
document.body.append(host);
|
|
107
|
-
}
|
|
108
|
-
function show(state) {
|
|
109
|
-
latest = state;
|
|
110
|
-
if (!document.body) {
|
|
111
|
-
document.addEventListener("DOMContentLoaded", () => latest && show(latest), { once: true });
|
|
112
|
-
return;
|
|
113
|
-
}
|
|
114
|
-
if (!host?.isConnected) mount();
|
|
115
|
-
badge.dataset.status = state.status;
|
|
116
|
-
label.textContent = LABELS[state.status];
|
|
117
|
-
badge.title = state.status === "failed" ? `${state.error}. The site shows published content.` : "";
|
|
118
|
-
}
|
|
119
|
-
return {
|
|
120
|
-
show,
|
|
121
|
-
hide: () => {
|
|
122
|
-
latest = void 0;
|
|
123
|
-
host?.remove();
|
|
124
|
-
}
|
|
125
|
-
};
|
|
126
|
-
}
|
|
127
|
-
const SETTINGS_KEY = "forgepress:preview";
|
|
128
|
-
const OFF_KEY = "forgepress:preview:off";
|
|
129
|
-
const CHANNEL = "forgepress:preview";
|
|
130
|
-
const listeners = /* @__PURE__ */ new Set();
|
|
131
|
-
let version = 0;
|
|
132
|
-
let channel;
|
|
133
|
-
let listening = false;
|
|
134
|
-
function read$1(key) {
|
|
135
|
-
try {
|
|
136
|
-
return localStorage.getItem(key);
|
|
137
|
-
} catch {
|
|
138
|
-
return null;
|
|
139
|
-
}
|
|
140
|
-
}
|
|
141
|
-
function write(key, value) {
|
|
142
|
-
try {
|
|
143
|
-
if (value === void 0) localStorage.removeItem(key);
|
|
144
|
-
else localStorage.setItem(key, value);
|
|
145
|
-
} catch {}
|
|
146
|
-
}
|
|
147
|
-
function emit() {
|
|
148
|
-
version += 1;
|
|
149
|
-
for (const listener of [...listeners]) listener();
|
|
150
|
-
}
|
|
151
|
-
function listen() {
|
|
152
|
-
if (listening || typeof window === "undefined") return;
|
|
153
|
-
listening = true;
|
|
154
|
-
window.addEventListener("storage", (event) => {
|
|
155
|
-
if (event.key === null || event.key === SETTINGS_KEY || event.key === OFF_KEY) emit();
|
|
156
|
-
});
|
|
157
|
-
if (typeof BroadcastChannel !== "undefined") {
|
|
158
|
-
channel = new BroadcastChannel(CHANNEL);
|
|
159
|
-
channel.addEventListener("message", emit);
|
|
160
|
-
}
|
|
161
|
-
}
|
|
162
|
-
function previewSettings() {
|
|
163
|
-
const text = read$1(SETTINGS_KEY);
|
|
164
|
-
try {
|
|
165
|
-
return text ? JSON.parse(text) : void 0;
|
|
166
|
-
} catch {
|
|
167
|
-
return;
|
|
168
|
-
}
|
|
169
|
-
}
|
|
170
|
-
function previewEnabled() {
|
|
171
|
-
return read$1(OFF_KEY) === null;
|
|
172
|
-
}
|
|
173
|
-
function previewing() {
|
|
174
|
-
return typeof window !== "undefined" && previewEnabled() && read$1(SETTINGS_KEY) !== null;
|
|
175
|
-
}
|
|
176
|
-
function previewVersion() {
|
|
177
|
-
return version;
|
|
178
|
-
}
|
|
179
|
-
function onPreviewChange(listener) {
|
|
180
|
-
listen();
|
|
181
|
-
listeners.add(listener);
|
|
182
|
-
return () => {
|
|
183
|
-
listeners.delete(listener);
|
|
184
|
-
};
|
|
185
|
-
}
|
|
186
|
-
function setPreviewEnabled(enabled) {
|
|
187
|
-
if (previewEnabled() === enabled) return;
|
|
188
|
-
write(OFF_KEY, enabled ? void 0 : "1");
|
|
189
|
-
emit();
|
|
190
|
-
}
|
|
191
|
-
let enabled = false;
|
|
192
|
-
let snapshot;
|
|
193
|
-
let selected;
|
|
194
|
-
const badge = createBadge(() => setPreviewEnabled(false));
|
|
195
|
-
function readerFor(settings) {
|
|
196
|
-
const key = JSON.stringify(settings);
|
|
197
|
-
if (selected?.key !== key) selected = {
|
|
198
|
-
key,
|
|
199
|
-
reader: import("../_chunks/reader2.mjs").then((module) => module.createPreviewReader(settings))
|
|
200
|
-
};
|
|
201
|
-
return selected.reader;
|
|
202
|
-
}
|
|
203
|
-
function load() {
|
|
204
|
-
const version = previewVersion();
|
|
205
|
-
if (snapshot?.version === version) return snapshot.files;
|
|
206
|
-
const settings = previewSettings();
|
|
207
|
-
const current = {
|
|
208
|
-
version,
|
|
209
|
-
files: (settings ? readerFor(settings).then((reader) => reader.build()) : Promise.reject(/* @__PURE__ */ new Error("[forgepress] sign in to the editor to preview unpublished content"))).then((files) => {
|
|
210
|
-
if (snapshot === current) badge.show({ status: "ready" });
|
|
211
|
-
return files;
|
|
212
|
-
}, (cause) => {
|
|
213
|
-
if (snapshot === current) badge.show({
|
|
214
|
-
status: "failed",
|
|
215
|
-
error: errorMessage(cause)
|
|
216
|
-
});
|
|
217
|
-
})
|
|
218
|
-
};
|
|
219
|
-
snapshot = current;
|
|
220
|
-
badge.show({ status: "loading" });
|
|
221
|
-
return current.files;
|
|
222
|
-
}
|
|
223
|
-
async function read(path, base) {
|
|
224
|
-
if (!previewing()) return base(path);
|
|
225
|
-
const files = await load();
|
|
226
|
-
if (!files) return base(path);
|
|
227
|
-
const text = files.get(path);
|
|
228
|
-
return text === void 0 ? void 0 : JSON.parse(text);
|
|
229
|
-
}
|
|
230
|
-
function refresh() {
|
|
231
|
-
if (previewing()) load();
|
|
232
|
-
else badge.hide();
|
|
233
|
-
}
|
|
234
|
-
function enablePreview() {
|
|
235
|
-
if (typeof window === "undefined") return false;
|
|
236
|
-
if (!enabled) {
|
|
237
|
-
enabled = true;
|
|
238
|
-
overlayContent(read);
|
|
239
|
-
onPreviewChange(refresh);
|
|
240
|
-
refresh();
|
|
241
|
-
}
|
|
242
|
-
return previewing();
|
|
243
|
-
}
|
|
1
|
+
import { enablePreview, onPreviewChange, previewing } from "../_chunks/preview.mjs";
|
|
244
2
|
export { enablePreview, onPreviewChange, previewing };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function usePreviewData<TData>(data: TData, load: () => Promise<TData>): TData;
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { enablePreview, onPreviewChange } from "../_chunks/preview.mjs";
|
|
2
|
+
import { useEffect, useRef, useState } from "react";
|
|
3
|
+
function usePreviewData(data, load) {
|
|
4
|
+
const [previewed, setPreviewed] = useState();
|
|
5
|
+
const loader = useRef(load);
|
|
6
|
+
useEffect(() => {
|
|
7
|
+
loader.current = load;
|
|
8
|
+
});
|
|
9
|
+
useEffect(() => {
|
|
10
|
+
let latest = 0;
|
|
11
|
+
let stopped = false;
|
|
12
|
+
function update() {
|
|
13
|
+
const run = ++latest;
|
|
14
|
+
if (!enablePreview()) {
|
|
15
|
+
setPreviewed(void 0);
|
|
16
|
+
return;
|
|
17
|
+
}
|
|
18
|
+
loader.current().then((result) => {
|
|
19
|
+
if (!stopped && run === latest) setPreviewed({
|
|
20
|
+
from: data,
|
|
21
|
+
data: result
|
|
22
|
+
});
|
|
23
|
+
});
|
|
24
|
+
}
|
|
25
|
+
update();
|
|
26
|
+
const stop = onPreviewChange(update);
|
|
27
|
+
return () => {
|
|
28
|
+
stopped = true;
|
|
29
|
+
stop();
|
|
30
|
+
};
|
|
31
|
+
}, [data]);
|
|
32
|
+
return previewed?.from === data ? previewed.data : data;
|
|
33
|
+
}
|
|
34
|
+
export { usePreviewData };
|
package/dist/unplugin.d.mts
CHANGED
|
@@ -1,18 +1,13 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import { UnpluginFactory } from "unplugin";
|
|
4
|
-
export interface Options {
|
|
5
|
-
root?: string;
|
|
6
|
-
write?: boolean;
|
|
7
|
-
media?: MediaConfig;
|
|
8
|
-
}
|
|
1
|
+
import { Options } from "./_chunks/project.mjs";
|
|
2
|
+
import { UnpluginFactory, UnpluginInstance } from "unplugin";
|
|
9
3
|
export declare const unpluginFactory: UnpluginFactory<Options | undefined>;
|
|
10
|
-
|
|
11
|
-
export declare const
|
|
12
|
-
export declare const
|
|
13
|
-
export declare const
|
|
14
|
-
export declare const
|
|
15
|
-
export declare const
|
|
16
|
-
export declare const
|
|
17
|
-
export declare const
|
|
18
|
-
export
|
|
4
|
+
type Instance = UnpluginInstance<Options | undefined, boolean>;
|
|
5
|
+
export declare const unplugin: Instance;
|
|
6
|
+
export declare const vitePlugin: Instance['vite'];
|
|
7
|
+
export declare const rollupPlugin: Instance['rollup'];
|
|
8
|
+
export declare const rolldownPlugin: Instance['rolldown'];
|
|
9
|
+
export declare const webpackPlugin: Instance['webpack'];
|
|
10
|
+
export declare const rspackPlugin: Instance['rspack'];
|
|
11
|
+
export declare const farmPlugin: Instance['farm'];
|
|
12
|
+
export declare const bunPlugin: Instance['bun'];
|
|
13
|
+
export { type Options, unplugin as default };
|