@blinkk/root-cms 3.0.6 → 3.1.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/README.md +77 -0
- package/dist/app.js +6 -4
- package/dist/browser-client/browser-client.d.ts +148 -0
- package/dist/browser-client/embed-window.d.ts +66 -0
- package/dist/browser-client/emitter.d.ts +11 -0
- package/dist/browser-client.js +377 -0
- package/dist/{chunk-RXWDB3K4.js → chunk-4VZTYUQ7.js} +1 -1
- package/dist/{chunk-N4K6ICFR.js → chunk-AFBSITEO.js} +4 -6
- package/dist/{chunk-PNLLZXVY.js → chunk-AJDMNTZQ.js} +2 -2
- package/dist/chunk-J72JK4KR.js +8 -0
- package/dist/{chunk-7L5OI5ES.js → chunk-X5CNR4CK.js} +8 -4
- package/dist/cli.js +2 -1
- package/dist/client.js +2 -1
- package/dist/core/client.d.ts +5 -0
- package/dist/core/plugin.d.ts +1 -1
- package/dist/core/translations.d.ts +19 -4
- package/dist/core.js +4 -2
- package/dist/functions.js +4 -3
- package/dist/plugin.js +38 -7
- package/dist/shared/embed-protocol.d.ts +72 -0
- package/dist/shared/translation-languages.d.ts +67 -0
- package/dist/ui/AIPage-2N5UYBRX.js +1 -0
- package/dist/ui/AssetsPage-KLGNE6D6.js +1 -0
- package/dist/ui/CollectionPage-D7IG6526.js +1 -0
- package/dist/ui/ComparePage-726NIJW5.js +1 -0
- package/dist/ui/DataPage-YMSQCIVK.js +1 -0
- package/dist/ui/DataSourcePage-7VPFUG3K.js +1 -0
- package/dist/ui/DocTranslationsPage-FO7O76VK.js +1 -0
- package/dist/ui/DocumentPage-M7SJ4ITQ.js +1 -0
- package/dist/ui/EditDataSourcePage-Y7YK6IWT.js +1 -0
- package/dist/ui/EditReleasePage-XZ4RHHRT.js +1 -0
- package/dist/ui/EmbeddedAIPage-RJOUIPF2.js +1 -0
- package/dist/ui/EmbeddedDocumentPage-4TLMCDSO.js +1 -0
- package/dist/ui/{ImageEditorDialog-QEULJAT2.js → ImageEditorDialog-GGS4VFEA.js} +2 -2
- package/dist/ui/LogsPage-IGDDZGEI.js +1 -0
- package/dist/ui/NewDataSourcePage-YUPRHL7F.js +1 -0
- package/dist/ui/NewReleasePage-6HHLYOQP.js +1 -0
- package/dist/ui/NotFoundPage-A6OCYREA.js +1 -0
- package/dist/ui/ProjectPage-UHRXNN7O.js +1 -0
- package/dist/ui/ReleasePage-V2JMPWX7.js +1 -0
- package/dist/ui/ReleasesPage-SCR4SVKN.js +1 -0
- package/dist/ui/SettingsPage-5XKHPG6K.js +1 -0
- package/dist/ui/SidebarToolsPage-VXVRZ2C3.js +1 -0
- package/dist/ui/TaskPage-LDPRN3G6.js +1 -0
- package/dist/ui/TasksPage-DIXUWYXM.js +1 -0
- package/dist/ui/TranslationsArbPage-QPD3ZBT4.js +2 -0
- package/dist/ui/TranslationsEditPage-475Z7UPC.js +1 -0
- package/dist/ui/{TranslationsPage-OBN6CQZZ.js → TranslationsPage-674JU6L4.js} +32 -32
- package/dist/ui/{chunk-N4DFAIC5.js → chunk-2EPQJUGM.js} +1 -1
- package/dist/ui/{chunk-WKOX3VFN.js → chunk-2RAVKX2Z.js} +2 -2
- package/dist/ui/chunk-2S5HMST6.js +1 -0
- package/dist/ui/{chunk-V7RAXP2W.js → chunk-3E6CASIN.js} +1 -1
- package/dist/ui/chunk-4ALFT4ES.js +141 -0
- package/dist/ui/{chunk-KYKFNAX4.js → chunk-4FGASIIX.js} +1 -1
- package/dist/ui/chunk-4ISFTE2G.js +5 -0
- package/dist/ui/{chunk-SKEP5WYH.js → chunk-7SK47HHZ.js} +3 -3
- package/dist/ui/chunk-AAHM6RYJ.js +1 -0
- package/dist/ui/chunk-AGFPVTBA.js +1 -0
- package/dist/ui/chunk-BUNR5EU3.js +1 -0
- package/dist/ui/{chunk-N5Y5OWTV.js → chunk-BW2MKGNP.js} +1 -1
- package/dist/ui/{chunk-2225WAJ2.js → chunk-CAY5NM4Z.js} +1 -1
- package/dist/ui/{chunk-4KE2SZKH.js → chunk-D3UIZHRK.js} +1 -1
- package/dist/ui/{chunk-HYARD7BK.js → chunk-ENQKSLGJ.js} +1 -1
- package/dist/ui/chunk-FBSBL476.js +1 -0
- package/dist/ui/{chunk-NQB37NMX.js → chunk-FJLNXXE3.js} +1 -1
- package/dist/ui/chunk-GT5EQSEX.js +1 -0
- package/dist/ui/{chunk-KPJ53X55.js → chunk-HARRKJFZ.js} +1 -1
- package/dist/ui/{chunk-6E7PGMZX.js → chunk-HO3W4RVG.js} +1 -1
- package/dist/ui/{chunk-CVGYBXVH.js → chunk-J5E457OI.js} +1 -1
- package/dist/ui/{chunk-SEUH7LN2.js → chunk-JBHRZ4EX.js} +1 -1
- package/dist/ui/{chunk-W3HIZQ4Z.js → chunk-JS6TK4OP.js} +1 -1
- package/dist/ui/{chunk-BEDUTYQP.js → chunk-JTIQBW33.js} +1 -1
- package/dist/ui/{chunk-ORXEMIQC.js → chunk-KRNQ6L35.js} +1 -1
- package/dist/ui/chunk-LROR6N3B.js +7 -0
- package/dist/ui/{chunk-4CUWZQXT.js.LEGAL.txt → chunk-LROR6N3B.js.LEGAL.txt} +6 -1
- package/dist/ui/{chunk-6GPTGBA7.js → chunk-MSYTAJBV.js} +1 -1
- package/dist/ui/{chunk-RQKL4KXY.js → chunk-N3JSLTMV.js} +1 -1
- package/dist/ui/{chunk-NMBXHKIJ.js → chunk-NJMNOITA.js} +1 -1
- package/dist/ui/{chunk-D37DCENS.js → chunk-NSOTG64N.js} +1 -1
- package/dist/ui/chunk-NWHGT476.js +1 -0
- package/dist/ui/chunk-P2Z66DHV.js +1 -0
- package/dist/ui/{chunk-4IXGYXA2.js → chunk-PTPYMVFW.js} +1 -1
- package/dist/ui/{chunk-OVRTVMO5.js → chunk-Q7IU4QCY.js} +1 -1
- package/dist/ui/{chunk-XYBHH5L4.js → chunk-QF3GPZTI.js} +1 -1
- package/dist/ui/{chunk-AXETBZ6T.js → chunk-QHJOTXYB.js} +1 -1
- package/dist/ui/{chunk-UHWNLNP4.js → chunk-RHAJNURN.js} +1 -1
- package/dist/ui/chunk-SENZVSVZ.js +1 -0
- package/dist/ui/chunk-SKQECSUR.js +1 -0
- package/dist/ui/chunk-TOGLZDK3.js +1 -0
- package/dist/ui/chunk-TPJCPCRR.js +1 -0
- package/dist/ui/{chunk-EMYXSVTD.js → chunk-TVYAZN2Q.js} +1 -1
- package/dist/ui/{chunk-GDSSFO5R.js → chunk-UUVAD4U4.js} +1 -1
- package/dist/ui/{chunk-EGEB6N4J.js → chunk-VD6G5NV4.js} +11 -11
- package/dist/ui/{chunk-DXKEDMEI.js → chunk-VJUMFJIX.js} +1 -1
- package/dist/ui/chunk-W5DOO6ID.js +1 -0
- package/dist/ui/{chunk-6MOPIV5T.js → chunk-W6LP22IK.js} +1 -1
- package/dist/ui/{chunk-3XYCOR6Z.js → chunk-WFQU7V3W.js} +1 -1
- package/dist/ui/chunk-WMICEDOT.js +1 -0
- package/dist/ui/chunk-XMESZUC5.js +1 -0
- package/dist/ui/{chunk-T47V6AGW.js → chunk-XWX2622O.js} +1 -1
- package/dist/ui/chunk-YMBBWVBB.js +3 -0
- package/dist/ui/chunk-YXSXWFLZ.js +1 -0
- package/dist/ui/chunk-ZMS6NIGG.js +1 -0
- package/dist/ui/gcs-ECSDFCIU.js +1 -0
- package/dist/ui/ui.css +1 -1
- package/dist/ui/ui.js +1 -1
- package/package.json +7 -3
- package/dist/ui/AIPage-JPZ4QUB4.js +0 -1
- package/dist/ui/AssetsPage-GDJMKS3M.js +0 -1
- package/dist/ui/CollectionPage-5DVXJEET.js +0 -1
- package/dist/ui/ComparePage-LIXA6G66.js +0 -1
- package/dist/ui/DataPage-AP4Z5JPS.js +0 -1
- package/dist/ui/DataSourcePage-WO3ZKMFI.js +0 -1
- package/dist/ui/DocTranslationsPage-QKYFIVHP.js +0 -1
- package/dist/ui/DocumentPage-ON43I5KM.js +0 -1
- package/dist/ui/EditDataSourcePage-XVMEV2LJ.js +0 -1
- package/dist/ui/EditReleasePage-A2NB5TFG.js +0 -1
- package/dist/ui/LogsPage-4LZJX3O4.js +0 -1
- package/dist/ui/NewDataSourcePage-4YWX7IOG.js +0 -1
- package/dist/ui/NewReleasePage-HWLVTEXX.js +0 -1
- package/dist/ui/NotFoundPage-72AXQAYX.js +0 -1
- package/dist/ui/ProjectPage-L4GYDIA5.js +0 -1
- package/dist/ui/ReleasePage-43BSWL5B.js +0 -1
- package/dist/ui/ReleasesPage-CJXAZBP6.js +0 -1
- package/dist/ui/SettingsPage-SYXAMKSF.js +0 -1
- package/dist/ui/SidebarToolsPage-OFF5BOXP.js +0 -1
- package/dist/ui/TaskPage-HBDLHFI5.js +0 -1
- package/dist/ui/TasksPage-OLCDTQNB.js +0 -1
- package/dist/ui/TranslationsArbPage-E3NCMAMS.js +0 -2
- package/dist/ui/TranslationsEditPage-IWOI7Y5G.js +0 -1
- package/dist/ui/chunk-32LRQ5MJ.js +0 -1
- package/dist/ui/chunk-3HVDIPSS.js +0 -1
- package/dist/ui/chunk-3IDOZ4MG.js +0 -1
- package/dist/ui/chunk-4CUWZQXT.js +0 -7
- package/dist/ui/chunk-AOCBDKLV.js +0 -1
- package/dist/ui/chunk-DUJYIOLE.js +0 -5
- package/dist/ui/chunk-IDYKCAAL.js +0 -1
- package/dist/ui/chunk-IKED2IGU.js +0 -1
- package/dist/ui/chunk-J3EGGI57.js +0 -1
- package/dist/ui/chunk-MZP6RIG2.js +0 -1
- package/dist/ui/chunk-NQ5ARARP.js +0 -1
- package/dist/ui/chunk-RI2JWWU3.js +0 -141
- package/dist/ui/chunk-RPOP6MVJ.js +0 -1
- package/dist/ui/chunk-TDKVKTW4.js +0 -1
- package/dist/ui/chunk-TZEZEMRQ.js +0 -1
- package/dist/ui/chunk-UA7UCTX5.js +0 -1
- package/dist/ui/chunk-UFQSZ6J2.js +0 -3
- package/dist/ui/gcs-L33FIRZU.js +0 -1
- /package/dist/ui/{ImageEditorDialog-QEULJAT2.js.LEGAL.txt → ImageEditorDialog-GGS4VFEA.js.LEGAL.txt} +0 -0
- /package/dist/ui/{chunk-RI2JWWU3.js.LEGAL.txt → chunk-4ALFT4ES.js.LEGAL.txt} +0 -0
- /package/dist/ui/{chunk-SKEP5WYH.js.LEGAL.txt → chunk-7SK47HHZ.js.LEGAL.txt} +0 -0
- /package/dist/ui/{chunk-NMBXHKIJ.js.LEGAL.txt → chunk-NJMNOITA.js.LEGAL.txt} +0 -0
- /package/dist/ui/{chunk-EGEB6N4J.js.LEGAL.txt → chunk-VD6G5NV4.js.LEGAL.txt} +0 -0
|
@@ -0,0 +1,377 @@
|
|
|
1
|
+
import {
|
|
2
|
+
normalizeSlug
|
|
3
|
+
} from "./chunk-J72JK4KR.js";
|
|
4
|
+
import "./chunk-MLKGABMK.js";
|
|
5
|
+
|
|
6
|
+
// shared/embed-protocol.ts
|
|
7
|
+
var SaveState = /* @__PURE__ */ ((SaveState3) => {
|
|
8
|
+
SaveState3["NO_CHANGES"] = "NO_CHANGES";
|
|
9
|
+
SaveState3["UPDATES_PENDING"] = "UPDATE_PENDING";
|
|
10
|
+
SaveState3["SAVING"] = "SAVING";
|
|
11
|
+
SaveState3["SAVED"] = "SAVED";
|
|
12
|
+
SaveState3["ERROR"] = "ERROR";
|
|
13
|
+
return SaveState3;
|
|
14
|
+
})(SaveState || {});
|
|
15
|
+
var EMBED_MESSAGE_TYPES = ["ready", "saved", "published", "error"];
|
|
16
|
+
function isRootEmbedMessage(data) {
|
|
17
|
+
const root = data?.root;
|
|
18
|
+
return typeof root === "object" && root !== null && EMBED_MESSAGE_TYPES.includes(root.type);
|
|
19
|
+
}
|
|
20
|
+
function isHighlightNodeMessage(data) {
|
|
21
|
+
const req = data?.highlightNode;
|
|
22
|
+
return typeof req === "object" && req !== null && (typeof req.deepKey === "string" || req.deepKey === null);
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
// browser-client/emitter.ts
|
|
26
|
+
var Emitter = class {
|
|
27
|
+
constructor() {
|
|
28
|
+
this.listeners = /* @__PURE__ */ new Map();
|
|
29
|
+
}
|
|
30
|
+
/** Subscribes to an event. Returns an unsubscribe function. */
|
|
31
|
+
on(type, cb) {
|
|
32
|
+
let set = this.listeners.get(type);
|
|
33
|
+
if (!set) {
|
|
34
|
+
set = /* @__PURE__ */ new Set();
|
|
35
|
+
this.listeners.set(type, set);
|
|
36
|
+
}
|
|
37
|
+
set.add(cb);
|
|
38
|
+
return () => this.off(type, cb);
|
|
39
|
+
}
|
|
40
|
+
off(type, cb) {
|
|
41
|
+
this.listeners.get(type)?.delete(cb);
|
|
42
|
+
}
|
|
43
|
+
emit(type, payload) {
|
|
44
|
+
this.listeners.get(type)?.forEach((cb) => cb(payload));
|
|
45
|
+
}
|
|
46
|
+
removeAll() {
|
|
47
|
+
this.listeners.clear();
|
|
48
|
+
}
|
|
49
|
+
};
|
|
50
|
+
|
|
51
|
+
// browser-client/embed-window.ts
|
|
52
|
+
var POPUP_POLL_INTERVAL = 500;
|
|
53
|
+
var DEFAULT_POPUP_WIDTH = 480;
|
|
54
|
+
var DEFAULT_POPUP_HEIGHT = 720;
|
|
55
|
+
var EmbedWindow = class {
|
|
56
|
+
constructor(url, cmsOrigin, options) {
|
|
57
|
+
/** The iframe element (iframe mode only). */
|
|
58
|
+
this.element = null;
|
|
59
|
+
/** The pop-up window (popup mode only). */
|
|
60
|
+
this.window = null;
|
|
61
|
+
this.emitter = new Emitter();
|
|
62
|
+
this.ready = false;
|
|
63
|
+
this.closed = false;
|
|
64
|
+
this.outbox = [];
|
|
65
|
+
this.pollTimer = null;
|
|
66
|
+
this.onMessage = (event) => {
|
|
67
|
+
if (event.origin !== this.cmsOrigin) {
|
|
68
|
+
return;
|
|
69
|
+
}
|
|
70
|
+
if (!event.source || event.source !== this.contentWindow()) {
|
|
71
|
+
return;
|
|
72
|
+
}
|
|
73
|
+
if (!isRootEmbedMessage(event.data)) {
|
|
74
|
+
return;
|
|
75
|
+
}
|
|
76
|
+
const root = event.data.root;
|
|
77
|
+
if (root.type === "ready") {
|
|
78
|
+
this.ready = true;
|
|
79
|
+
const outbox = this.outbox;
|
|
80
|
+
this.outbox = [];
|
|
81
|
+
outbox.forEach((message) => this.post(message));
|
|
82
|
+
}
|
|
83
|
+
this.emitter.emit(root.type, root);
|
|
84
|
+
};
|
|
85
|
+
this.url = url;
|
|
86
|
+
this.cmsOrigin = cmsOrigin;
|
|
87
|
+
window.addEventListener("message", this.onMessage);
|
|
88
|
+
const mode = options?.mode || "popup";
|
|
89
|
+
if (mode === "iframe") {
|
|
90
|
+
if (!options?.container) {
|
|
91
|
+
throw new Error('`container` is required when mode is "iframe"');
|
|
92
|
+
}
|
|
93
|
+
const iframe = document.createElement("iframe");
|
|
94
|
+
iframe.className = "root-cms-embed";
|
|
95
|
+
iframe.src = url;
|
|
96
|
+
options.container.appendChild(iframe);
|
|
97
|
+
this.element = iframe;
|
|
98
|
+
} else {
|
|
99
|
+
const width = options?.width ?? DEFAULT_POPUP_WIDTH;
|
|
100
|
+
const height = options?.height ?? DEFAULT_POPUP_HEIGHT;
|
|
101
|
+
const popup = window.open(
|
|
102
|
+
url,
|
|
103
|
+
"_blank",
|
|
104
|
+
`popup,width=${width},height=${height}`
|
|
105
|
+
);
|
|
106
|
+
if (!popup) {
|
|
107
|
+
queueMicrotask(() => {
|
|
108
|
+
this.emitter.emit("error", {
|
|
109
|
+
error: "popup blocked (open the editor from a user gesture, e.g. a click handler)"
|
|
110
|
+
});
|
|
111
|
+
this.close();
|
|
112
|
+
});
|
|
113
|
+
} else {
|
|
114
|
+
this.window = popup;
|
|
115
|
+
this.pollTimer = setInterval(() => {
|
|
116
|
+
if (popup.closed) {
|
|
117
|
+
this.close();
|
|
118
|
+
}
|
|
119
|
+
}, POPUP_POLL_INTERVAL);
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
on(type, cb) {
|
|
124
|
+
return this.emitter.on(type, cb);
|
|
125
|
+
}
|
|
126
|
+
/**
|
|
127
|
+
* Posts a message to the embedded window, targeted at the CMS origin.
|
|
128
|
+
* Messages are buffered until the embedded page signals `ready`.
|
|
129
|
+
*/
|
|
130
|
+
post(message) {
|
|
131
|
+
if (this.closed) {
|
|
132
|
+
return;
|
|
133
|
+
}
|
|
134
|
+
if (!this.ready) {
|
|
135
|
+
this.outbox.push(message);
|
|
136
|
+
return;
|
|
137
|
+
}
|
|
138
|
+
this.contentWindow()?.postMessage(message, this.cmsOrigin);
|
|
139
|
+
}
|
|
140
|
+
/** Reloads the embedded page. */
|
|
141
|
+
reload() {
|
|
142
|
+
if (this.closed) {
|
|
143
|
+
return;
|
|
144
|
+
}
|
|
145
|
+
this.ready = false;
|
|
146
|
+
if (this.element) {
|
|
147
|
+
this.element.src = this.url;
|
|
148
|
+
} else if (this.window) {
|
|
149
|
+
this.window.location.href = this.url;
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
/** Closes the embedded window. Safe to call multiple times. */
|
|
153
|
+
close() {
|
|
154
|
+
if (this.closed) {
|
|
155
|
+
return;
|
|
156
|
+
}
|
|
157
|
+
this.closed = true;
|
|
158
|
+
window.removeEventListener("message", this.onMessage);
|
|
159
|
+
if (this.pollTimer !== null) {
|
|
160
|
+
clearInterval(this.pollTimer);
|
|
161
|
+
this.pollTimer = null;
|
|
162
|
+
}
|
|
163
|
+
this.element?.remove();
|
|
164
|
+
if (this.window && !this.window.closed) {
|
|
165
|
+
this.window.close();
|
|
166
|
+
}
|
|
167
|
+
this.emitter.emit("close", void 0);
|
|
168
|
+
this.emitter.removeAll();
|
|
169
|
+
}
|
|
170
|
+
contentWindow() {
|
|
171
|
+
return this.element ? this.element.contentWindow : this.window;
|
|
172
|
+
}
|
|
173
|
+
};
|
|
174
|
+
|
|
175
|
+
// browser-client/browser-client.ts
|
|
176
|
+
function isDotSegment(segment) {
|
|
177
|
+
return segment === "." || segment === "..";
|
|
178
|
+
}
|
|
179
|
+
var EmbeddedEditor = class {
|
|
180
|
+
constructor(docId, embedWindow) {
|
|
181
|
+
this.docId = docId;
|
|
182
|
+
this.embedWindow = embedWindow;
|
|
183
|
+
}
|
|
184
|
+
/** The iframe element (iframe mode only). */
|
|
185
|
+
get element() {
|
|
186
|
+
return this.embedWindow.element;
|
|
187
|
+
}
|
|
188
|
+
/** The pop-up window (popup mode only). */
|
|
189
|
+
get window() {
|
|
190
|
+
return this.embedWindow.window;
|
|
191
|
+
}
|
|
192
|
+
/** Subscribes to an editor event. Returns an unsubscribe function. */
|
|
193
|
+
on(type, cb) {
|
|
194
|
+
return this.embedWindow.on(type, cb);
|
|
195
|
+
}
|
|
196
|
+
/** Scrolls the editor to (focuses) a field, e.g. `hero.title`. */
|
|
197
|
+
focusField(deepKey) {
|
|
198
|
+
const message = { scrollToDeeplink: { deepKey } };
|
|
199
|
+
this.embedWindow.post(message);
|
|
200
|
+
}
|
|
201
|
+
/** Reloads the embedded editor. */
|
|
202
|
+
reload() {
|
|
203
|
+
this.embedWindow.reload();
|
|
204
|
+
}
|
|
205
|
+
/** Closes the embedded editor, discarding any unsaved changes. */
|
|
206
|
+
close() {
|
|
207
|
+
this.embedWindow.close();
|
|
208
|
+
}
|
|
209
|
+
/** Closes the embedded editor and reloads the host page. */
|
|
210
|
+
closeAndReload() {
|
|
211
|
+
this.close();
|
|
212
|
+
window.location.reload();
|
|
213
|
+
}
|
|
214
|
+
};
|
|
215
|
+
var EmbeddedAI = class {
|
|
216
|
+
constructor(embedWindow) {
|
|
217
|
+
this.embedWindow = embedWindow;
|
|
218
|
+
}
|
|
219
|
+
/** The iframe element (iframe mode only). */
|
|
220
|
+
get element() {
|
|
221
|
+
return this.embedWindow.element;
|
|
222
|
+
}
|
|
223
|
+
/** The pop-up window (popup mode only). */
|
|
224
|
+
get window() {
|
|
225
|
+
return this.embedWindow.window;
|
|
226
|
+
}
|
|
227
|
+
/** Subscribes to an event. Returns an unsubscribe function. */
|
|
228
|
+
on(type, cb) {
|
|
229
|
+
return this.embedWindow.on(type, cb);
|
|
230
|
+
}
|
|
231
|
+
/** Reloads the embedded chat (starts a fresh chat). */
|
|
232
|
+
reload() {
|
|
233
|
+
this.embedWindow.reload();
|
|
234
|
+
}
|
|
235
|
+
/** Closes the embedded chat. */
|
|
236
|
+
close() {
|
|
237
|
+
this.embedWindow.close();
|
|
238
|
+
}
|
|
239
|
+
/** Closes the embedded chat and reloads the host page. */
|
|
240
|
+
closeAndReload() {
|
|
241
|
+
this.close();
|
|
242
|
+
window.location.reload();
|
|
243
|
+
}
|
|
244
|
+
};
|
|
245
|
+
var PreviewConnection = class {
|
|
246
|
+
constructor() {
|
|
247
|
+
this.emitter = new Emitter();
|
|
248
|
+
this.onMessage = (event) => {
|
|
249
|
+
if (event.origin !== window.location.origin) {
|
|
250
|
+
return;
|
|
251
|
+
}
|
|
252
|
+
if (!isHighlightNodeMessage(event.data)) {
|
|
253
|
+
return;
|
|
254
|
+
}
|
|
255
|
+
const req = event.data.highlightNode;
|
|
256
|
+
this.emitter.emit("highlight", {
|
|
257
|
+
deepKey: req.deepKey,
|
|
258
|
+
scroll: req.options?.scroll ?? false
|
|
259
|
+
});
|
|
260
|
+
};
|
|
261
|
+
this.isEmbedded = RootCMSBrowserClient.isInPreviewIframe();
|
|
262
|
+
window.addEventListener("message", this.onMessage);
|
|
263
|
+
}
|
|
264
|
+
/**
|
|
265
|
+
* Requests that the doc editor scroll to (focus) a field, e.g.
|
|
266
|
+
* `hero.title`. Used to implement "click to edit".
|
|
267
|
+
*/
|
|
268
|
+
focusField(deepKey) {
|
|
269
|
+
if (window.parent === window) {
|
|
270
|
+
return;
|
|
271
|
+
}
|
|
272
|
+
const message = { scrollToDeeplink: { deepKey } };
|
|
273
|
+
window.parent.postMessage(message, window.location.origin);
|
|
274
|
+
}
|
|
275
|
+
/**
|
|
276
|
+
* Subscribes to field highlight requests from the doc editor (sent when the
|
|
277
|
+
* user hovers/focuses a field). Returns an unsubscribe function.
|
|
278
|
+
*/
|
|
279
|
+
on(type, cb) {
|
|
280
|
+
return this.emitter.on(type, cb);
|
|
281
|
+
}
|
|
282
|
+
/** Removes the message listener and all subscriptions. */
|
|
283
|
+
disconnect() {
|
|
284
|
+
window.removeEventListener("message", this.onMessage);
|
|
285
|
+
this.emitter.removeAll();
|
|
286
|
+
}
|
|
287
|
+
};
|
|
288
|
+
var RootCMSBrowserClient = class {
|
|
289
|
+
constructor(options) {
|
|
290
|
+
let url;
|
|
291
|
+
try {
|
|
292
|
+
url = new URL(options.cmsOrigin);
|
|
293
|
+
} catch {
|
|
294
|
+
throw new Error(
|
|
295
|
+
`invalid cmsOrigin: "${options?.cmsOrigin}" (expected e.g. "https://cms.example.com")`
|
|
296
|
+
);
|
|
297
|
+
}
|
|
298
|
+
if (url.protocol !== "https:" && url.protocol !== "http:") {
|
|
299
|
+
throw new Error(
|
|
300
|
+
`invalid cmsOrigin: "${options?.cmsOrigin}" (expected an http(s) origin, e.g. "https://cms.example.com")`
|
|
301
|
+
);
|
|
302
|
+
}
|
|
303
|
+
this.cmsOrigin = url.origin;
|
|
304
|
+
}
|
|
305
|
+
/**
|
|
306
|
+
* Opens the headless doc editor for a doc (e.g. `Pages/about`) in a pop-up
|
|
307
|
+
* or iframe. In popup mode, call from a user gesture (e.g. a click handler)
|
|
308
|
+
* to avoid pop-up blockers.
|
|
309
|
+
*
|
|
310
|
+
* The slug portion of the docId is normalized the same way the CMS
|
|
311
|
+
* normalizes slugs, so a URL-like path also works, e.g. `Pages/about/foo`
|
|
312
|
+
* -> `Pages/about--foo`.
|
|
313
|
+
*/
|
|
314
|
+
openEditor(docId, options) {
|
|
315
|
+
const [collection, ...slugParts] = docId.split("/");
|
|
316
|
+
const slug = normalizeSlug(slugParts.join("/"));
|
|
317
|
+
if (!collection || !slug || isDotSegment(collection) || isDotSegment(slug)) {
|
|
318
|
+
throw new Error(
|
|
319
|
+
`invalid docId: "${docId}" (expected "<collection>/<slug>")`
|
|
320
|
+
);
|
|
321
|
+
}
|
|
322
|
+
const normalizedDocId = `${collection}/${slug}`;
|
|
323
|
+
const url = new URL(
|
|
324
|
+
`${this.cmsOrigin}/cms/embed/content/${encodeURIComponent(
|
|
325
|
+
collection
|
|
326
|
+
)}/${encodeURIComponent(slug)}`
|
|
327
|
+
);
|
|
328
|
+
if (options?.deeplink) {
|
|
329
|
+
url.searchParams.set("deeplink", options.deeplink);
|
|
330
|
+
}
|
|
331
|
+
const embedWindow = new EmbedWindow(
|
|
332
|
+
url.toString(),
|
|
333
|
+
this.cmsOrigin,
|
|
334
|
+
options
|
|
335
|
+
);
|
|
336
|
+
return new EmbeddedEditor(normalizedDocId, embedWindow);
|
|
337
|
+
}
|
|
338
|
+
/**
|
|
339
|
+
* Opens the headless Root AI chat in a pop-up or iframe, optionally with a
|
|
340
|
+
* doc as context. In popup mode, call from a user gesture (e.g. a click
|
|
341
|
+
* handler) to avoid pop-up blockers.
|
|
342
|
+
*/
|
|
343
|
+
openRootAI(options) {
|
|
344
|
+
const url = new URL(`${this.cmsOrigin}/cms/embed/ai`);
|
|
345
|
+
if (options?.docId) {
|
|
346
|
+
url.searchParams.set("docId", options.docId);
|
|
347
|
+
}
|
|
348
|
+
const embedWindow = new EmbedWindow(
|
|
349
|
+
url.toString(),
|
|
350
|
+
this.cmsOrigin,
|
|
351
|
+
options
|
|
352
|
+
);
|
|
353
|
+
return new EmbeddedAI(embedWindow);
|
|
354
|
+
}
|
|
355
|
+
/**
|
|
356
|
+
* Connects to the doc editor from a site rendered inside the in-CMS preview
|
|
357
|
+
* pane, enabling "click to edit" ({@link PreviewConnection.focusField}) and
|
|
358
|
+
* field highlighting (`on('highlight', ...)`).
|
|
359
|
+
*/
|
|
360
|
+
static connectPreview() {
|
|
361
|
+
return new PreviewConnection();
|
|
362
|
+
}
|
|
363
|
+
/** Returns whether this page is rendered inside the in-CMS preview pane. */
|
|
364
|
+
static isInPreviewIframe() {
|
|
365
|
+
if (window.parent === window) {
|
|
366
|
+
return false;
|
|
367
|
+
}
|
|
368
|
+
return document.referrer.startsWith(`${window.location.origin}/cms`);
|
|
369
|
+
}
|
|
370
|
+
};
|
|
371
|
+
export {
|
|
372
|
+
EmbeddedAI,
|
|
373
|
+
EmbeddedEditor,
|
|
374
|
+
PreviewConnection,
|
|
375
|
+
RootCMSBrowserClient,
|
|
376
|
+
SaveState
|
|
377
|
+
};
|
|
@@ -1,3 +1,7 @@
|
|
|
1
|
+
import {
|
|
2
|
+
normalizeSlug
|
|
3
|
+
} from "./chunk-J72JK4KR.js";
|
|
4
|
+
|
|
1
5
|
// core/client.ts
|
|
2
6
|
import crypto from "node:crypto";
|
|
3
7
|
import {
|
|
@@ -5,11 +9,6 @@ import {
|
|
|
5
9
|
Timestamp as Timestamp2
|
|
6
10
|
} from "firebase-admin/firestore";
|
|
7
11
|
|
|
8
|
-
// shared/slug.ts
|
|
9
|
-
function normalizeSlug(slug) {
|
|
10
|
-
return slug.replace(/^[\s/]*/g, "").replace(/[\s/]*$/g, "").replace(/^\/+|\/+$/g, "").replaceAll("/", "--");
|
|
11
|
-
}
|
|
12
|
-
|
|
13
12
|
// core/translations-manager.ts
|
|
14
13
|
import {
|
|
15
14
|
FieldValue,
|
|
@@ -2432,7 +2431,6 @@ var BatchResponse = class {
|
|
|
2432
2431
|
};
|
|
2433
2432
|
|
|
2434
2433
|
export {
|
|
2435
|
-
normalizeSlug,
|
|
2436
2434
|
TranslationsManager,
|
|
2437
2435
|
buildTranslationsDbPath,
|
|
2438
2436
|
buildTranslationsLocaleDocDbPath,
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import {
|
|
2
2
|
SearchIndexService
|
|
3
|
-
} from "./chunk-
|
|
3
|
+
} from "./chunk-4VZTYUQ7.js";
|
|
4
4
|
import {
|
|
5
5
|
RootCMSClient,
|
|
6
6
|
getCmsPlugin
|
|
7
|
-
} from "./chunk-
|
|
7
|
+
} from "./chunk-AFBSITEO.js";
|
|
8
8
|
|
|
9
9
|
// core/cron.ts
|
|
10
10
|
import { Timestamp as Timestamp2 } from "firebase-admin/firestore";
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import {
|
|
2
2
|
SearchIndexService
|
|
3
|
-
} from "./chunk-
|
|
3
|
+
} from "./chunk-4VZTYUQ7.js";
|
|
4
4
|
import {
|
|
5
5
|
normalizeSlug
|
|
6
|
-
} from "./chunk-
|
|
6
|
+
} from "./chunk-J72JK4KR.js";
|
|
7
7
|
|
|
8
8
|
// core/ai.ts
|
|
9
9
|
import crypto from "node:crypto";
|
|
@@ -1198,7 +1198,7 @@ function extractJsonFromResponse(responseText) {
|
|
|
1198
1198
|
// package.json
|
|
1199
1199
|
var package_default = {
|
|
1200
1200
|
name: "@blinkk/root-cms",
|
|
1201
|
-
version: "3.
|
|
1201
|
+
version: "3.1.2",
|
|
1202
1202
|
author: "s@blinkk.com",
|
|
1203
1203
|
license: "MIT",
|
|
1204
1204
|
engines: {
|
|
@@ -1223,6 +1223,10 @@ var package_default = {
|
|
|
1223
1223
|
types: "./dist/core/core.d.ts",
|
|
1224
1224
|
import: "./dist/core.js"
|
|
1225
1225
|
},
|
|
1226
|
+
"./browser-client": {
|
|
1227
|
+
types: "./dist/browser-client/browser-client.d.ts",
|
|
1228
|
+
import: "./dist/browser-client.js"
|
|
1229
|
+
},
|
|
1226
1230
|
"./client": {
|
|
1227
1231
|
types: "./dist/core/client.d.ts",
|
|
1228
1232
|
import: "./dist/client.js"
|
|
@@ -1369,7 +1373,7 @@ var package_default = {
|
|
|
1369
1373
|
yjs: "13.6.27"
|
|
1370
1374
|
},
|
|
1371
1375
|
peerDependencies: {
|
|
1372
|
-
"@blinkk/root": "3.
|
|
1376
|
+
"@blinkk/root": "3.1.2",
|
|
1373
1377
|
"firebase-admin": ">=11",
|
|
1374
1378
|
"firebase-functions": ">=4"
|
|
1375
1379
|
},
|
package/dist/cli.js
CHANGED
package/dist/client.js
CHANGED
package/dist/core/client.d.ts
CHANGED
|
@@ -27,6 +27,11 @@ export interface Doc<Fields = any> {
|
|
|
27
27
|
until?: Timestamp;
|
|
28
28
|
};
|
|
29
29
|
locales?: string[];
|
|
30
|
+
/**
|
|
31
|
+
* Reverse index of asset library ids embedded in the doc's fields,
|
|
32
|
+
* (re)computed whenever the doc draft is saved in the CMS UI.
|
|
33
|
+
*/
|
|
34
|
+
assets?: string[];
|
|
30
35
|
};
|
|
31
36
|
fields: Fields;
|
|
32
37
|
}
|
package/dist/core/plugin.d.ts
CHANGED
|
@@ -12,7 +12,7 @@ export { translationsCheck } from './checks-translations.js';
|
|
|
12
12
|
export type { TranslationsCheckOptions } from './checks-translations.js';
|
|
13
13
|
export type { CMSService, CMSServiceContext } from './services.js';
|
|
14
14
|
export type { CMSNotificationService, NotificationResult, NotificationServiceContext, } from './services-notifications.js';
|
|
15
|
-
export type { CMSTranslationService, TranslationExportResult, TranslationImportResult, TranslationRow, TranslationServiceContext, } from './translations.js';
|
|
15
|
+
export type { CMSTranslationService, RootLocale, TranslationExportResult, TranslationImportResult, TranslationLanguage, TranslationRow, TranslationServiceContext, } from './translations.js';
|
|
16
16
|
/**
|
|
17
17
|
* Built-in sidebar tools that can be toggled on/off in the CMS UI.
|
|
18
18
|
*/
|
|
@@ -1,10 +1,17 @@
|
|
|
1
|
+
import type { RootLocale, TranslationLanguage } from '../shared/translation-languages.js';
|
|
1
2
|
import type { CMSService, CMSServiceContext } from './services.js';
|
|
2
|
-
|
|
3
|
+
export type { RootLocale, TranslationLanguage };
|
|
4
|
+
/** A row of translation data keyed by translation language. */
|
|
3
5
|
export interface TranslationRow {
|
|
4
6
|
/** The source string. */
|
|
5
7
|
source: string;
|
|
6
|
-
/**
|
|
7
|
-
|
|
8
|
+
/**
|
|
9
|
+
* Map of translation language to translated string. Translation languages
|
|
10
|
+
* are derived from the project's locales via the `i18n.translationLanguages`
|
|
11
|
+
* config in root.config.ts; when no mapping is configured, the keys are the
|
|
12
|
+
* locale ids themselves.
|
|
13
|
+
*/
|
|
14
|
+
translations: Record<TranslationLanguage, string>;
|
|
8
15
|
/** Optional translator notes/context for the source string. */
|
|
9
16
|
description?: string;
|
|
10
17
|
}
|
|
@@ -17,7 +24,15 @@ export interface TranslationServiceContext extends CMSServiceContext {
|
|
|
17
24
|
/** The slug, e.g. `index`. */
|
|
18
25
|
slug: string;
|
|
19
26
|
/** The locales configured for the project. */
|
|
20
|
-
locales:
|
|
27
|
+
locales: RootLocale[];
|
|
28
|
+
/**
|
|
29
|
+
* The translation languages for the project, derived from `locales` via the
|
|
30
|
+
* `i18n.translationLanguages` config in root.config.ts (deduped, since
|
|
31
|
+
* multiple locales may share a translation language). Equal to `locales`
|
|
32
|
+
* when no mapping is configured. The `translations` keys in
|
|
33
|
+
* `TranslationRow` data use these languages.
|
|
34
|
+
*/
|
|
35
|
+
translationLanguages: TranslationLanguage[];
|
|
21
36
|
/** The email of the user performing the action. */
|
|
22
37
|
user: {
|
|
23
38
|
email: string;
|
package/dist/core.js
CHANGED
|
@@ -10,13 +10,15 @@ import {
|
|
|
10
10
|
marshalArray,
|
|
11
11
|
marshalData,
|
|
12
12
|
normalizeData,
|
|
13
|
-
normalizeSlug,
|
|
14
13
|
parseDocId,
|
|
15
14
|
toArrayObject,
|
|
16
15
|
translationsForLocale,
|
|
17
16
|
unmarshalArray,
|
|
18
17
|
unmarshalData
|
|
19
|
-
} from "./chunk-
|
|
18
|
+
} from "./chunk-AFBSITEO.js";
|
|
19
|
+
import {
|
|
20
|
+
normalizeSlug
|
|
21
|
+
} from "./chunk-J72JK4KR.js";
|
|
20
22
|
import {
|
|
21
23
|
__export
|
|
22
24
|
} from "./chunk-MLKGABMK.js";
|
package/dist/functions.js
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import {
|
|
2
2
|
runCronJobs
|
|
3
|
-
} from "./chunk-
|
|
4
|
-
import "./chunk-
|
|
5
|
-
import "./chunk-
|
|
3
|
+
} from "./chunk-AJDMNTZQ.js";
|
|
4
|
+
import "./chunk-4VZTYUQ7.js";
|
|
5
|
+
import "./chunk-AFBSITEO.js";
|
|
6
|
+
import "./chunk-J72JK4KR.js";
|
|
6
7
|
import "./chunk-MLKGABMK.js";
|
|
7
8
|
|
|
8
9
|
// core/functions.ts
|
package/dist/plugin.js
CHANGED
|
@@ -13,18 +13,19 @@ import {
|
|
|
13
13
|
serializeAiConfig,
|
|
14
14
|
summarizeDiff,
|
|
15
15
|
translateString
|
|
16
|
-
} from "./chunk-
|
|
16
|
+
} from "./chunk-X5CNR4CK.js";
|
|
17
17
|
import {
|
|
18
18
|
runCronJobs
|
|
19
|
-
} from "./chunk-
|
|
19
|
+
} from "./chunk-AJDMNTZQ.js";
|
|
20
20
|
import {
|
|
21
21
|
SearchIndexService
|
|
22
|
-
} from "./chunk-
|
|
22
|
+
} from "./chunk-4VZTYUQ7.js";
|
|
23
23
|
import {
|
|
24
24
|
RootCMSClient,
|
|
25
25
|
parseDocId,
|
|
26
26
|
unmarshalData
|
|
27
|
-
} from "./chunk-
|
|
27
|
+
} from "./chunk-AFBSITEO.js";
|
|
28
|
+
import "./chunk-J72JK4KR.js";
|
|
28
29
|
import "./chunk-MLKGABMK.js";
|
|
29
30
|
|
|
30
31
|
// core/plugin.ts
|
|
@@ -60,6 +61,28 @@ import { promises as fs } from "node:fs";
|
|
|
60
61
|
import path from "node:path";
|
|
61
62
|
import { multipartMiddleware } from "@blinkk/root/middleware";
|
|
62
63
|
|
|
64
|
+
// shared/translation-languages.ts
|
|
65
|
+
function getTranslationLanguage(i18nConfig, locale) {
|
|
66
|
+
const mapping = i18nConfig.translationLanguages || {};
|
|
67
|
+
const localeLower = String(locale).toLowerCase();
|
|
68
|
+
for (const [key, lang] of Object.entries(mapping)) {
|
|
69
|
+
if (key.toLowerCase() === localeLower) {
|
|
70
|
+
return lang;
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
return locale;
|
|
74
|
+
}
|
|
75
|
+
function toTranslationLanguages(i18nConfig, locales) {
|
|
76
|
+
const languages = [];
|
|
77
|
+
for (const locale of locales) {
|
|
78
|
+
const lang = getTranslationLanguage(i18nConfig, locale);
|
|
79
|
+
if (!languages.includes(lang)) {
|
|
80
|
+
languages.push(lang);
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
return languages;
|
|
84
|
+
}
|
|
85
|
+
|
|
63
86
|
// core/csv.ts
|
|
64
87
|
import { parse as csvParse } from "csv-parse/sync";
|
|
65
88
|
import { stringify as csvStringify } from "csv-stringify/sync";
|
|
@@ -1050,7 +1073,9 @@ function api(server, options) {
|
|
|
1050
1073
|
}
|
|
1051
1074
|
try {
|
|
1052
1075
|
const cmsClient = new RootCMSClient(req.rootConfig);
|
|
1053
|
-
const
|
|
1076
|
+
const i18nConfig = req.rootConfig?.i18n || {};
|
|
1077
|
+
const locales = i18nConfig.locales || [];
|
|
1078
|
+
const translationLanguages = toTranslationLanguages(i18nConfig, locales);
|
|
1054
1079
|
const result = await handler(
|
|
1055
1080
|
{
|
|
1056
1081
|
rootConfig: req.rootConfig,
|
|
@@ -1059,6 +1084,7 @@ function api(server, options) {
|
|
|
1059
1084
|
collectionId,
|
|
1060
1085
|
slug,
|
|
1061
1086
|
locales,
|
|
1087
|
+
translationLanguages,
|
|
1062
1088
|
user: { email: req.user.email }
|
|
1063
1089
|
},
|
|
1064
1090
|
data
|
|
@@ -1091,8 +1117,13 @@ function sse(server) {
|
|
|
1091
1117
|
}
|
|
1092
1118
|
res.writeHead(200, {
|
|
1093
1119
|
"Content-Type": "text/event-stream",
|
|
1094
|
-
|
|
1095
|
-
|
|
1120
|
+
// `no-transform` opts out of the `compression()` middleware (used by
|
|
1121
|
+
// `root start` / `root preview`), which would otherwise hold SSE chunks
|
|
1122
|
+
// in a gzip/brotli window and never deliver them incrementally.
|
|
1123
|
+
"Cache-Control": "no-cache, no-transform",
|
|
1124
|
+
Connection: "keep-alive",
|
|
1125
|
+
// Disable buffering in nginx-style reverse proxies.
|
|
1126
|
+
"X-Accel-Buffering": "no"
|
|
1096
1127
|
});
|
|
1097
1128
|
sseClients.add(res);
|
|
1098
1129
|
const connectedMessage = formatMessage(
|