@storyblok/js 6.2.1 → 6.3.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/dist/bridge.d.ts +1 -1
- package/dist/index-CtMAhUF-.js +576 -0
- package/dist/index.d.ts +2 -1
- package/dist/storyblok-js.js +210 -1
- package/dist/storyblok-js.mjs +75 -68
- package/dist/types/index.d.ts +1 -1
- package/package.json +2 -1
package/dist/bridge.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const loadBridge: (
|
|
1
|
+
export declare const loadBridge: () => Promise<void>;
|
|
@@ -0,0 +1,576 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* name: @storyblok/js
|
|
3
|
+
* (c) 2026
|
|
4
|
+
* description: SDK to integrate Storyblok into your project using JavaScript.
|
|
5
|
+
* author: undefined
|
|
6
|
+
*/
|
|
7
|
+
const M = (o, t) => {
|
|
8
|
+
for (; o && o.nodeType === 1; ) {
|
|
9
|
+
if (o.hasAttribute(t)) return o;
|
|
10
|
+
o = o.parentNode;
|
|
11
|
+
}
|
|
12
|
+
return null;
|
|
13
|
+
}, y = (o) => {
|
|
14
|
+
const t = M(o, "data-blok-c");
|
|
15
|
+
if (!t) return null;
|
|
16
|
+
const e = t.getAttribute("data-blok-c");
|
|
17
|
+
return JSON.parse(e);
|
|
18
|
+
}, A = (o, t) => o.contains(t), l = (o) => document.querySelector(`[data-blok-uid="${o}"]`), g = (o) => {
|
|
19
|
+
const t = o.getBoundingClientRect();
|
|
20
|
+
return t.top < 0 && t.top + t.height >= 0 || t.top >= 0 && t.top <= (window.innerHeight || document.documentElement.clientHeight);
|
|
21
|
+
}, I = (o) => {
|
|
22
|
+
let t = {};
|
|
23
|
+
try {
|
|
24
|
+
const e = o.replace(/\\/g, "");
|
|
25
|
+
t = JSON.parse(e);
|
|
26
|
+
} catch {
|
|
27
|
+
console.error("Error parsing json", o);
|
|
28
|
+
}
|
|
29
|
+
return t;
|
|
30
|
+
}, N = (o) => {
|
|
31
|
+
const t = [], e = () => NodeFilter.FILTER_ACCEPT, n = document.createNodeIterator(o, NodeFilter.SHOW_COMMENT, e, !1);
|
|
32
|
+
let s = {};
|
|
33
|
+
for (; s = n.nextNode(); ) if (s.nodeValue.indexOf("#storyblok#") > -1) {
|
|
34
|
+
const r = s.nodeValue.replace("#storyblok#", ""), u = s.nextElementSibling || s.nextSibling, d = I(r);
|
|
35
|
+
d && t.push({ options: d, el: u });
|
|
36
|
+
}
|
|
37
|
+
return t;
|
|
38
|
+
}, f = (o) => {
|
|
39
|
+
let t = "";
|
|
40
|
+
return location.search.substr(1).split("&").forEach((e) => {
|
|
41
|
+
const n = e.split("=");
|
|
42
|
+
n[0] === o && (t = decodeURIComponent(n[1]));
|
|
43
|
+
}), t;
|
|
44
|
+
}, O = (o, t, e) => typeof o != "string" ? "" : o.toString().replace(/([A-Z])/g, " $1").trim().toLowerCase().replace(/[_-]/g, " ").replace(/(?:^|\s)\S/g, function(n, s) {
|
|
45
|
+
return n.toUpperCase();
|
|
46
|
+
}), E = (o) => o && o.display_name ? o.display_name : O(o.name), k = (o) => {
|
|
47
|
+
const t = document.createElementNS("http://www.w3.org/2000/svg", "svg");
|
|
48
|
+
t.setAttribute("viewBox", o.viewBox), t.setAttribute("class", o.svgClass);
|
|
49
|
+
const e = document.createElementNS(t.namespaceURI, "path");
|
|
50
|
+
return e.setAttribute("d", o.path), e.setAttribute("fill", o.pathFill), e.setAttribute("transform", o.pathTransform ? o.pathTransform : "translate(0 0)"), t.appendChild(e), t;
|
|
51
|
+
}, x = (o) => o, C = x, v = C`
|
|
52
|
+
@keyframes smoke {
|
|
53
|
+
from {
|
|
54
|
+
background-color: rgba(89, 197, 198, 0);
|
|
55
|
+
}
|
|
56
|
+
to {
|
|
57
|
+
background-color: rgba(89, 197, 198, 0.5);
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
.storyblok--outlined .storyblok__outline,
|
|
62
|
+
.storyblok--outlined [data-blok-c] {
|
|
63
|
+
outline: 1px dashed rgba(182, 186, 191, 0.5);
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
.storyblok--outlined .storyblok__outline[data-blok-focused='true'],
|
|
67
|
+
.storyblok--outlined [data-blok-c][data-blok-focused='true'] {
|
|
68
|
+
outline: 0;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
.storyblok__hint {
|
|
72
|
+
box-sizing: border-box;
|
|
73
|
+
outline: 1px solid #05807f;
|
|
74
|
+
pointer-events: none;
|
|
75
|
+
position: absolute;
|
|
76
|
+
transition: opacity 0.2s ease;
|
|
77
|
+
z-index: 16777272;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
.storyblok__highlight {
|
|
81
|
+
background: rgba(89, 197, 198, 0.2);
|
|
82
|
+
outline: 1px solid #05807f;
|
|
83
|
+
pointer-events: none;
|
|
84
|
+
position: absolute;
|
|
85
|
+
transition: opacity 0.2s ease;
|
|
86
|
+
z-index: 16777270;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
.storyblok__overlay {
|
|
90
|
+
box-shadow: 0 0 8px 2px rgba(34, 42, 69, 0.07);
|
|
91
|
+
box-sizing: border-box;
|
|
92
|
+
outline: 1px solid #05807f;
|
|
93
|
+
pointer-events: none;
|
|
94
|
+
position: absolute;
|
|
95
|
+
z-index: 16777273;
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
.storyblok__overlay-menu {
|
|
99
|
+
background-color: #05807f;
|
|
100
|
+
border-radius: 5px;
|
|
101
|
+
display: inline-flex;
|
|
102
|
+
font-family:
|
|
103
|
+
-apple-system, blinkmacsystemfont, 'Segoe UI', roboto, helvetica, arial,
|
|
104
|
+
sans-serif, 'Apple Color Emoji', 'Segoe UI Emoji', 'Segoe UI Symbol';
|
|
105
|
+
height: 30px;
|
|
106
|
+
left: -1px;
|
|
107
|
+
pointer-events: auto;
|
|
108
|
+
position: absolute;
|
|
109
|
+
top: -40px;
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
.storyblok__overlay-menu--simple .storyblok__overlay-menu-btn {
|
|
113
|
+
border-bottom-right-radius: 5px;
|
|
114
|
+
border-top-right-radius: 5px;
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
.storyblok__overlay-menu-label {
|
|
118
|
+
color: #fff;
|
|
119
|
+
font-size: 14px;
|
|
120
|
+
line-height: 30px;
|
|
121
|
+
margin-right: 20px;
|
|
122
|
+
max-width: 200px;
|
|
123
|
+
overflow-x: hidden;
|
|
124
|
+
text-overflow: ellipsis;
|
|
125
|
+
white-space: nowrap;
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
.storyblok__overlay-menu-label:first-child {
|
|
129
|
+
margin-left: 20px;
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
.storyblok__overlay-menu-btn {
|
|
133
|
+
align-items: center;
|
|
134
|
+
background-color: transparent;
|
|
135
|
+
border: 0;
|
|
136
|
+
display: flex;
|
|
137
|
+
justify-content: center;
|
|
138
|
+
outline: none;
|
|
139
|
+
padding: 0;
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
.storyblok__overlay-menu-btn:hover {
|
|
143
|
+
background-color: #0d5454;
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
.storyblok__overlay-menu-btn-action {
|
|
147
|
+
border-bottom-right-radius: 5px;
|
|
148
|
+
border-left: 1px solid #fff;
|
|
149
|
+
border-top-right-radius: 5px;
|
|
150
|
+
height: inherit;
|
|
151
|
+
margin: auto;
|
|
152
|
+
margin-right: 0;
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
.storyblok__overlay-menu-btn-parent {
|
|
156
|
+
border-bottom-left-radius: 5px;
|
|
157
|
+
border-top-left-radius: 5px;
|
|
158
|
+
cursor: pointer;
|
|
159
|
+
margin: 0;
|
|
160
|
+
width: auto;
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
.storyblok__overlay-menu-svg {
|
|
164
|
+
box-sizing: border-box;
|
|
165
|
+
cursor: pointer;
|
|
166
|
+
height: 24px;
|
|
167
|
+
margin: 0 3px;
|
|
168
|
+
width: 24px;
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
.storyblok__overlay--bottom .storyblok__overlay-menu {
|
|
172
|
+
bottom: -40px;
|
|
173
|
+
top: auto;
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
.storyblok__overlay--clicked {
|
|
177
|
+
animation-duration: 0.2s;
|
|
178
|
+
animation-iteration-count: 1;
|
|
179
|
+
animation-name: smoke;
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
.storyblok__actions-menu,
|
|
183
|
+
.storyblok__breadcrumbs-menu {
|
|
184
|
+
background-color: #fff;
|
|
185
|
+
border: 1px solid #dfe3e8;
|
|
186
|
+
border-radius: 5px;
|
|
187
|
+
box-shadow: 0 2px 17px 3px rgba(34, 42, 69, 0.07);
|
|
188
|
+
box-sizing: content-box;
|
|
189
|
+
display: none;
|
|
190
|
+
height: fit-content;
|
|
191
|
+
min-width: 156px;
|
|
192
|
+
overflow: hidden;
|
|
193
|
+
padding: 11px 0;
|
|
194
|
+
position: absolute;
|
|
195
|
+
top: 25px;
|
|
196
|
+
z-index: 2;
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
.storyblok__actions-menu hr,
|
|
200
|
+
.storyblok__breadcrumbs-menu hr {
|
|
201
|
+
background-color: #dfe3e8;
|
|
202
|
+
border: 0;
|
|
203
|
+
height: 1px;
|
|
204
|
+
margin: 11px 0 11px 20px;
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
.storyblok__actions-menu__menu-item,
|
|
208
|
+
.storyblok__breadcrumbs-menu__menu-item {
|
|
209
|
+
align-items: center;
|
|
210
|
+
appearance: none;
|
|
211
|
+
background: #fff;
|
|
212
|
+
border: 0;
|
|
213
|
+
color: #1b243f;
|
|
214
|
+
cursor: pointer;
|
|
215
|
+
display: flex;
|
|
216
|
+
font-family:
|
|
217
|
+
-apple-system, blinkmacsystemfont, 'Segoe UI', roboto, helvetica, arial,
|
|
218
|
+
sans-serif, 'Apple Color Emoji', 'Segoe UI Emoji', 'Segoe UI Symbol';
|
|
219
|
+
font-size: 14px;
|
|
220
|
+
padding: 8px 20px;
|
|
221
|
+
text-align: left;
|
|
222
|
+
width: 100%;
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
.storyblok__actions-menu__menu-item--delete,
|
|
226
|
+
.storyblok__breadcrumbs-menu__menu-item--delete {
|
|
227
|
+
color: #c11c14;
|
|
228
|
+
margin-bottom: 0;
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
.storyblok__actions-menu__menu-item--selected,
|
|
232
|
+
.storyblok__breadcrumbs-menu__menu-item--selected {
|
|
233
|
+
color: #05807f;
|
|
234
|
+
cursor: default;
|
|
235
|
+
margin-bottom: 0;
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
.storyblok__actions-menu__menu-item--selected:hover,
|
|
239
|
+
.storyblok__breadcrumbs-menu__menu-item--selected:hover {
|
|
240
|
+
background: transparent;
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
.storyblok__actions-menu__menu-item:hover,
|
|
244
|
+
.storyblok__breadcrumbs-menu__menu-item:hover {
|
|
245
|
+
background: #eff1f3;
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
.storyblok__actions-menu__menu-item:focus,
|
|
249
|
+
.storyblok__breadcrumbs-menu__menu-item:focus {
|
|
250
|
+
outline: none;
|
|
251
|
+
}
|
|
252
|
+
|
|
253
|
+
.storyblok__actions-menu {
|
|
254
|
+
left: calc(100% - 20px);
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
.storyblok__breadcrumbs-menu {
|
|
258
|
+
left: -10px;
|
|
259
|
+
}
|
|
260
|
+
`, i = { OUTLINE: "storyblok--outlined", STYLESHEET: "storyblok-bridge-stylesheet", HINT: "storyblok__hint", HIGHLIGHTER: "storyblok__highlight", OVERLAY: "storyblok__overlay", COMPONENT_BASE: "storyblok__overlay-menu", ACTIONS_MENU: "storyblok__actions-menu", BREADCRUMBS_MENU: "storyblok__breadcrumbs-menu" };
|
|
261
|
+
class w {
|
|
262
|
+
constructor(t) {
|
|
263
|
+
this.appVersion = "v1", this.inEditor = !0, this.initialized = !1, this.currentUid = null, this.storyId = "", this.componentNames = {}, this.outlineOnMoveInterval = null, this.calcInterval = null, this.canAddBlocks = !1, this.canMoveForward = !1, this.canMoveBackward = !1, this.canDeleteBlocks = !1, this.navigationBreadcrumbs = [], this.focusState = !1, this.actionsEnabled = !1, this.hinter = null, this.highlighter = null, this.overlay = null, this.componentBase = null, this.componentLabel = null, this.breadcrumbsButtonMenu = null, this.breadcrumbsMenu = null, this.actionsMenu = null, this.actionsMenuButton = null, this.actionsMenuItems = null, this.events = { input: [], change: [], published: [], unpublished: [], viewLiveVersion: [], enterEditmode: [], enterComponent: [], hoverComponent: [], highlightComponent: [], customEvent: [], pingBack: [], sessionReceived: [], editedBlok: [], deselectBlok: [], addedBlock: [], deletedBlock: [], movedBlock: [], duplicatedBlock: [] };
|
|
264
|
+
const e = { customParent: null, resolveRelations: null, resolveLinks: null, preventClicks: !1, initOnlyOnce: !0, fallbackLang: null };
|
|
265
|
+
this.config = { ...e, ...t }, this.init();
|
|
266
|
+
}
|
|
267
|
+
get isInIframe() {
|
|
268
|
+
return window.top !== window.self;
|
|
269
|
+
}
|
|
270
|
+
get csProtocol() {
|
|
271
|
+
let t = location.protocol.replace(":", "");
|
|
272
|
+
return t !== "http" && t !== "https" && (t = "https"), t;
|
|
273
|
+
}
|
|
274
|
+
get targetOrigin() {
|
|
275
|
+
return this.config.customParent ? this.config.customParent : f("_storyblok_env") === "stage" ? `${this.csProtocol}://app-beta.storyblok.com` : `${this.csProtocol}://app.storyblok.com`;
|
|
276
|
+
}
|
|
277
|
+
get lastBreadcrumbItem() {
|
|
278
|
+
return this.navigationBreadcrumbs[this.navigationBreadcrumbs.length - 1] || {};
|
|
279
|
+
}
|
|
280
|
+
isInEditor() {
|
|
281
|
+
return this.inEditor;
|
|
282
|
+
}
|
|
283
|
+
init() {
|
|
284
|
+
if (document.body === null) {
|
|
285
|
+
console.error("Body tag not found. Please install the Storyblok bridge script inside the body tag");
|
|
286
|
+
return;
|
|
287
|
+
}
|
|
288
|
+
this.config.initOnlyOnce && document.querySelectorAll(`.${i.HINT}`).length > 0 || this.isInIframe && (this.resetAllEvents(), this.addMessageListener(), this.outlineOnMove(), this.buildBridgeStyles(), this.on("enterEditmode", this.enterEditmode), this.isInIframe && this.sendDataToEditor({ action: "initialized", config: this.config }), this.initialized = !0);
|
|
289
|
+
}
|
|
290
|
+
keyPress(t, e) {
|
|
291
|
+
(e.key === "z" && e.metaKey || e.key === "z" && e.ctrlKey) && (e.preventDefault(), e.stopImmediatePropagation(), t.sendDataToEditor({ action: "undo" })), (e.key === "y" && e.metaKey || e.key === "y" && e.ctrlKey) && (e.preventDefault(), e.stopImmediatePropagation(), t.sendDataToEditor({ action: "redo" }));
|
|
292
|
+
}
|
|
293
|
+
sendDataToEditor(t) {
|
|
294
|
+
window.parent.postMessage(t, this.targetOrigin);
|
|
295
|
+
}
|
|
296
|
+
buildBridgeStyles() {
|
|
297
|
+
document.getElementById(i.STYLESHEET) ? (this.hinter = document.querySelector(`.${i.HINT}`), this.highlighter = document.querySelector(`.${i.HIGHLIGHTER}`), this.overlay = document.querySelector(`.${i.OVERLAY}`), this.componentBase = document.querySelector(`.${i.COMPONENT_BASE}`), this.breadcrumbsButtonMenu = document.querySelector(`.${i.COMPONENT_BASE}-btn-parent`), this.breadcrumbsMenu = document.querySelector(`.${i.BREADCRUMBS_MENU}`), this.actionsMenuButton = document.querySelector(`.${i.COMPONENT_BASE}-btn-action`), this.actionsMenu = document.querySelector(`.${i.ACTIONS_MENU}`), this.componentLabel = document.querySelector(`.${i.COMPONENT_BASE} > .${i.COMPONENT_BASE}-label`), this.createActionsMenuItems()) : (this.createBridgeStylesheet(), this.createHinter(), this.createHighlighter(), this.createOverlay(), this.createComponentContext());
|
|
298
|
+
}
|
|
299
|
+
createBridgeStylesheet() {
|
|
300
|
+
const t = document.createElement("style");
|
|
301
|
+
t.setAttribute("type", "text/css"), t.id = i.STYLESHEET, "textContent" in t ? t.textContent = v : t.styleSheet.cssText = v, document.getElementsByTagName("head")[0].appendChild(t);
|
|
302
|
+
}
|
|
303
|
+
createHinter() {
|
|
304
|
+
this.hinter = document.createElement("div"), this.hinter.className = i.HINT, this.hideElement(this.hinter), document.body.appendChild(this.hinter);
|
|
305
|
+
}
|
|
306
|
+
createHighlighter() {
|
|
307
|
+
this.highlighter = document.createElement("div"), this.highlighter.style.opacity = 0, this.hideElement(this.highlighter), document.body.appendChild(this.highlighter);
|
|
308
|
+
}
|
|
309
|
+
createOverlay() {
|
|
310
|
+
this.overlay = document.createElement("div"), this.overlay.setAttribute("class", i.OVERLAY), this.overlay.setAttribute("id", i.OVERLAY), this.hideElement(this.overlay), document.body.appendChild(this.overlay);
|
|
311
|
+
}
|
|
312
|
+
calculateElementPosition(t, e) {
|
|
313
|
+
if (!e) {
|
|
314
|
+
this.hideElement(t);
|
|
315
|
+
return;
|
|
316
|
+
}
|
|
317
|
+
const n = l(e);
|
|
318
|
+
if (n) {
|
|
319
|
+
const { left: s, top: r } = this.getElementOffset(n);
|
|
320
|
+
r <= 30 ? this.overlay.classList.add(`${i.OVERLAY}--bottom`) : this.overlay.classList.remove(`${i.OVERLAY}--bottom`), t.style.top = `${r}px`, t.style.left = `${s}px`, t.style.width = `${n.offsetWidth}px`, t.style.height = `${n.offsetHeight}px`, t.style.minHeight = "5px";
|
|
321
|
+
} else this.hideElement(t);
|
|
322
|
+
}
|
|
323
|
+
getElementOffset(t) {
|
|
324
|
+
const e = t.getBoundingClientRect(), n = window.pageXOffset || document.documentElement.scrollLeft, s = window.pageYOffset || document.documentElement.scrollTop;
|
|
325
|
+
return { top: e.top + s, left: e.left + n };
|
|
326
|
+
}
|
|
327
|
+
resetAllEvents() {
|
|
328
|
+
for (const t in this.events) this.events[t] = [];
|
|
329
|
+
}
|
|
330
|
+
addMessageListener() {
|
|
331
|
+
window.addEventListener && addEventListener("message", this.receiveMessageFromApp.bind(this), !1);
|
|
332
|
+
}
|
|
333
|
+
receiveMessageFromApp(t) {
|
|
334
|
+
t && t.data && t.data.action && this.emit(t.data.action, t.data);
|
|
335
|
+
}
|
|
336
|
+
emit(t, ...e) {
|
|
337
|
+
const n = this.events[t];
|
|
338
|
+
if (!(!t || !n || !n.length)) for (let s = 0; s < n.length; s++) n[s].apply(this, e);
|
|
339
|
+
}
|
|
340
|
+
outlineOnMoveHandler() {
|
|
341
|
+
document.body.classList.add(i.OUTLINE);
|
|
342
|
+
const t = () => {
|
|
343
|
+
document.body.classList.remove(i.OUTLINE), this.hinter && (this.hinter.style.opacity = 0);
|
|
344
|
+
};
|
|
345
|
+
this.outlineOnMoveInterval && clearTimeout(this.outlineOnMoveInterval), this.outlineOnMoveInterval = setTimeout(t, 800);
|
|
346
|
+
}
|
|
347
|
+
outlineOnMove() {
|
|
348
|
+
document.addEventListener("mousemove", this.outlineOnMoveHandler.bind(this), !1);
|
|
349
|
+
}
|
|
350
|
+
on(t, e) {
|
|
351
|
+
if (t.constructor === Array) {
|
|
352
|
+
for (const n of t) this.subscribeEvent(n, e);
|
|
353
|
+
return;
|
|
354
|
+
}
|
|
355
|
+
this.subscribeEvent(t, e);
|
|
356
|
+
}
|
|
357
|
+
subscribeEvent(t, e) {
|
|
358
|
+
t === "input" && (this.actionsEnabled = !0), this.events[t].indexOf(e) === -1 && this.events[t].push(e);
|
|
359
|
+
}
|
|
360
|
+
pingEditor(t) {
|
|
361
|
+
this.isInIframe ? this.sendDataToEditor({ action: "ping" }) : (this.inEditor = !1, t(this)), this.on("pingBack", this.handlePingBack(t));
|
|
362
|
+
}
|
|
363
|
+
handlePingBack(t) {
|
|
364
|
+
return () => {
|
|
365
|
+
this.inEditor = !0, t(this);
|
|
366
|
+
};
|
|
367
|
+
}
|
|
368
|
+
handleEditedBlok(t) {
|
|
369
|
+
this.navigationBreadcrumbs = t.breadcrumbs, this.canAddBlocks = t.canAddBlocks || !1, this.canMoveForward = t.canMoveForward || !1, this.canMoveBackward = t.canMoveBackward || !1, this.canDeleteBlocks = t.canDeleteBlocks || !1, this.updateComponentBase(t.blok);
|
|
370
|
+
}
|
|
371
|
+
handleAddMoveBlok(t) {
|
|
372
|
+
const e = l(`${this.storyId}-${t.blockId}`);
|
|
373
|
+
e && this.handleOpenBlok(e);
|
|
374
|
+
}
|
|
375
|
+
handleDeselectBlock() {
|
|
376
|
+
document.querySelectorAll("[data-blok-focused]").forEach((t) => t.removeAttribute("data-blok-focused")), this.hideElement(this.overlay);
|
|
377
|
+
}
|
|
378
|
+
handleDuplicatedBlok(t) {
|
|
379
|
+
this.handleDeselectBlock(), setTimeout(() => {
|
|
380
|
+
const e = l(`${this.storyId}-${t.blockId}`);
|
|
381
|
+
this.handleOpenBlok(e);
|
|
382
|
+
}, 500);
|
|
383
|
+
}
|
|
384
|
+
handleWindowClick(t) {
|
|
385
|
+
this.config.preventClicks && (t.preventDefault(), t.stopPropagation()), this.handleOpenBlok(t.target, t);
|
|
386
|
+
}
|
|
387
|
+
handleOpenBlok(t, e) {
|
|
388
|
+
const n = y(t);
|
|
389
|
+
if (n) {
|
|
390
|
+
e && n.uid !== this.currentUid && (e.preventDefault(), e.stopPropagation()), this.currentUid = n.uid, this.storyId = n.id, this.openBlok(n);
|
|
391
|
+
return;
|
|
392
|
+
}
|
|
393
|
+
e && this.toggleFocusElement(t, !0);
|
|
394
|
+
}
|
|
395
|
+
enterEditmode(t) {
|
|
396
|
+
const e = N(document.body);
|
|
397
|
+
t && t.appVersion && (this.appVersion = t.appVersion), t && t.componentNames && (this.componentNames = t.componentNames);
|
|
398
|
+
for (let n = 0; n < e.length; n++) {
|
|
399
|
+
const s = e[n].el, r = e[n].options;
|
|
400
|
+
!s || s.nodeType !== Node.ELEMENT_NODE || (r.name = this.componentNames[r.name] || r.name, s.setAttribute("data-blok-c", JSON.stringify(r)), s.setAttribute("data-blok-uid", `${r.id}-${r.uid}`), s.offsetHeight < 5 && (s.style["min-height"] = "5px"), s.classList.add("storyblok__outline"));
|
|
401
|
+
}
|
|
402
|
+
if (this.on("addedBlock", this.handleAddMoveBlok), this.on("duplicatedBlock", this.handleDuplicatedBlok), this.on("movedBlock", this.handleAddMoveBlok), this.on("enterComponent", this.enterComponent), this.on("highlightComponent", this.highlightComponent), this.on("hoverComponent", this.hoverComponent), this.on("editedBlok", this.handleEditedBlok), this.on("deselectBlok", this.handleDeselectBlock), t && t.blockId && this.config.setActiveBlock) {
|
|
403
|
+
const n = l(`${t.storyId}-${t.blockId}`);
|
|
404
|
+
this.handleOpenBlok(n);
|
|
405
|
+
}
|
|
406
|
+
window.addEventListener("click", this.handleWindowClick.bind(this)), this.calcInterval !== null && window.clearInterval(this.calcInterval), this.calcInterval = window.setInterval(() => {
|
|
407
|
+
this.calculateElementPosition(this.overlay, `${this.storyId}-${this.currentUid}`);
|
|
408
|
+
}, 300);
|
|
409
|
+
}
|
|
410
|
+
highlightComponent(t) {
|
|
411
|
+
this.highlighter.innerHTML = "", t.componentIds.length > 0 ? (this.highlighter.style.display = "block", this.highlighter.style.opacity = 1) : (this.highlighter.style.display = "none", this.highlighter.style.opacity = 0);
|
|
412
|
+
for (let e = 0; e < t.componentIds.length; e++) {
|
|
413
|
+
const n = `${t.storyId}-${t.componentIds[e]}`, s = l(n);
|
|
414
|
+
if (s) {
|
|
415
|
+
const r = document.createElement("div");
|
|
416
|
+
r.setAttribute("class", i.HIGHLIGHTER), this.highlighter.appendChild(r), this.calculateElementPosition(r, n), t.componentId === t.componentIds[e] && !g(s) && typeof s.scrollIntoView < "u" && s.scrollIntoView();
|
|
417
|
+
}
|
|
418
|
+
}
|
|
419
|
+
}
|
|
420
|
+
hoverComponent(t) {
|
|
421
|
+
this.calculateElementPosition(this.hinter, `${t.storyId}-${t.componentId}`), this.hinter.style.opacity = 1, this.hinter.style.display = "block";
|
|
422
|
+
}
|
|
423
|
+
toggleFocusElement(t, e = !1) {
|
|
424
|
+
if (!A(this.overlay, t)) {
|
|
425
|
+
if (this.handleDeselectBlock(), !e && this.storyId === f("_storyblok")) {
|
|
426
|
+
t.setAttribute("data-blok-focused", !0), this.showFocusedElement(this.overlay), this.focusState = !1;
|
|
427
|
+
return;
|
|
428
|
+
}
|
|
429
|
+
this.focusState || this.sendDataToEditor({ action: "noFocus" });
|
|
430
|
+
}
|
|
431
|
+
}
|
|
432
|
+
showFocusedElement(t) {
|
|
433
|
+
if (!this.currentUid) {
|
|
434
|
+
this.hideElement(t);
|
|
435
|
+
return;
|
|
436
|
+
}
|
|
437
|
+
this.showElement(t), this.calculateElementPosition(t, `${this.storyId}-${this.currentUid}`);
|
|
438
|
+
}
|
|
439
|
+
handleBlokActions(t) {
|
|
440
|
+
this.sendDataToEditor({ action: t, blok: this.lastBreadcrumbItem }), t === "addBlockBefore" || t === "addBlockAfter" || t === "copy" ? this.hideElement(this.actionsMenu) : this.hideElement(this.overlay), (t === "moveForward" || t === "moveBackward") && (this.focusState = !0);
|
|
441
|
+
}
|
|
442
|
+
hideElement(t) {
|
|
443
|
+
t.style.display = "none";
|
|
444
|
+
}
|
|
445
|
+
showElement(t) {
|
|
446
|
+
t.style.display = "block";
|
|
447
|
+
}
|
|
448
|
+
toggleElement(t) {
|
|
449
|
+
if (t.style.display === "block") {
|
|
450
|
+
this.hideElement(t);
|
|
451
|
+
return;
|
|
452
|
+
}
|
|
453
|
+
this.showElement(t);
|
|
454
|
+
}
|
|
455
|
+
enterComponent(t) {
|
|
456
|
+
const e = l(`${t.storyId}-${t.componentId}`), n = y(e);
|
|
457
|
+
n && (this.hinter.style.opacity = 0, this.hinter.style.display = "none", this.currentUid = n.uid, this.storyId = n.id, this.scrollIntoView(e), this.handleEditedBlok(t));
|
|
458
|
+
}
|
|
459
|
+
scrollIntoView(t) {
|
|
460
|
+
t && !g(t) && typeof t.scrollIntoView < "u" && setTimeout(() => {
|
|
461
|
+
t.scrollIntoView({ behavior: "smooth", block: "start" });
|
|
462
|
+
}, 100);
|
|
463
|
+
}
|
|
464
|
+
openBlok(t) {
|
|
465
|
+
this.sendDataToEditor({ action: "edit", dataC: t, config: this.config });
|
|
466
|
+
}
|
|
467
|
+
createComponentContext() {
|
|
468
|
+
this.createComponentBase(), this.createActionsMenu(), this.createActionsMenuItems(), this.createBreadcrumbsMenu(), this.createActionsMenuButton(), this.createBreadcrumbsMenuButton(), this.createComponentLabel(), this.createComponentButtonLabel();
|
|
469
|
+
}
|
|
470
|
+
createComponentBase() {
|
|
471
|
+
this.componentBase = document.createElement("div"), this.componentBase.setAttribute("class", i.COMPONENT_BASE), this.componentBase.setAttribute("id", i.COMPONENT_BASE), this.overlay.append(this.componentBase);
|
|
472
|
+
}
|
|
473
|
+
createComponentLabel() {
|
|
474
|
+
this.componentLabel = document.createElement("span"), this.componentLabel.setAttribute("class", `${i.COMPONENT_BASE}-label`), this.componentBase.prepend(this.componentLabel);
|
|
475
|
+
}
|
|
476
|
+
createComponentButtonLabel() {
|
|
477
|
+
const t = document.createElement("span");
|
|
478
|
+
t.setAttribute("class", `${i.COMPONENT_BASE}-label`), this.breadcrumbsButtonMenu.appendChild(t);
|
|
479
|
+
}
|
|
480
|
+
updateComponentLabel(t) {
|
|
481
|
+
document.querySelectorAll(`.${i.COMPONENT_BASE}-label`).forEach((e) => e.innerText = this.componentNames[t.name] || E(t));
|
|
482
|
+
}
|
|
483
|
+
updateComponentBase(t) {
|
|
484
|
+
this.hideElement(this.actionsMenu), this.hideElement(this.breadcrumbsMenu), this.overlay.classList.add(`${i.OVERLAY}--clicked`), setTimeout(() => {
|
|
485
|
+
this.overlay.classList.remove(`${i.OVERLAY}--clicked`);
|
|
486
|
+
}, 400), this.navigationBreadcrumbs.length > 1 ? (this.updateBreadcrumbsMenu(this.navigationBreadcrumbs), this.actionsEnabled ? this.updateActionsMenu() : (this.componentBase.setAttribute("class", `${i.COMPONENT_BASE} ${i.COMPONENT_BASE}--simple`), this.hideElement(this.actionsMenuButton)), this.hideElement(this.componentLabel)) : (this.hideElement(this.breadcrumbsButtonMenu), this.hideElement(this.actionsMenuButton), this.showElement(this.componentLabel)), this.updateComponentLabel(t);
|
|
487
|
+
const e = l(`${this.storyId}-${t.uid}`);
|
|
488
|
+
e && this.toggleFocusElement(e);
|
|
489
|
+
}
|
|
490
|
+
createBreadcrumbsMenuButton() {
|
|
491
|
+
this.breadcrumbsButtonMenu = document.createElement("button"), this.breadcrumbsButtonMenu.setAttribute("class", `${i.COMPONENT_BASE}-btn ${i.COMPONENT_BASE}-btn-parent`), this.breadcrumbsButtonMenu.prepend(k({ viewBox: "0 0 24 24", svgClass: `${i.COMPONENT_BASE}-svg`, path: "M13.73 14.284l-2.197-2.216 2.197-2.217a1.051 1.051 0 000-1.477 1.03 1.03 0 00-1.465 0l-2.93 2.955a1.043 1.043 0 00-.287.554l-.014.123v.123c.014.247.115.489.301.677l2.93 2.956a1.03 1.03 0 001.465 0 1.051 1.051 0 000-1.478z", pathFill: "#ffffff" })), this.breadcrumbsButtonMenu.addEventListener("click", () => {
|
|
492
|
+
this.toggleElement(this.breadcrumbsMenu), this.hideElement(this.actionsMenu);
|
|
493
|
+
}), this.componentBase.prepend(this.breadcrumbsButtonMenu);
|
|
494
|
+
}
|
|
495
|
+
createBreadcrumbsMenu() {
|
|
496
|
+
this.breadcrumbsMenu = document.createElement("div"), this.breadcrumbsMenu.setAttribute("class", i.BREADCRUMBS_MENU), this.breadcrumbsMenu.setAttribute("id", i.BREADCRUMBS_MENU), this.componentBase.append(this.breadcrumbsMenu);
|
|
497
|
+
}
|
|
498
|
+
updateBreadcrumbsMenu(t) {
|
|
499
|
+
this.breadcrumbsMenu.innerHTML = "";
|
|
500
|
+
const e = [];
|
|
501
|
+
for (let n = 0; n < t.length; n++) {
|
|
502
|
+
e[n] = document.createElement("button"), e[n].innerHTML = E({ display_name: this.componentNames[t[n].component], name: t[n].component });
|
|
503
|
+
const s = t[n];
|
|
504
|
+
e[n].addEventListener("click", (r) => {
|
|
505
|
+
r.stopPropagation(), this.currentUid = s._uid, this.openBlok({ id: this.storyId, uid: s._uid, name: s.component });
|
|
506
|
+
}), e[n].classList.add(`${i.BREADCRUMBS_MENU}__menu-item`), t[n]._uid === this.currentUid && (e[n].classList.add(`${i.BREADCRUMBS_MENU}__menu-item--selected`), e[n].setAttribute("disabled", !0)), this.breadcrumbsMenu.appendChild(e[n]), this.breadcrumbsButtonMenu.style.display = "flex";
|
|
507
|
+
}
|
|
508
|
+
}
|
|
509
|
+
createActionsMenuButton() {
|
|
510
|
+
this.actionsMenuButton = document.createElement("button"), this.actionsMenuButton.setAttribute("class", `${i.COMPONENT_BASE}-btn ${i.COMPONENT_BASE}-btn-action`), this.actionsMenuButton.prepend(k({ viewBox: "0 0 24 24", svgClass: `${i.COMPONENT_BASE}-svg`, path: "M7.5 11a1.5 1.5 0 110 3 1.5 1.5 0 010-3zm10 0a1.5 1.5 0 110 3 1.5 1.5 0 010-3zm-5 0a1.5 1.5 0 110 3 1.5 1.5 0 010-3z", pathFill: "#ffffff" })), this.actionsMenuButton.addEventListener("click", () => {
|
|
511
|
+
this.toggleElement(this.actionsMenu), this.breadcrumbsMenu && this.hideElement(this.breadcrumbsMenu);
|
|
512
|
+
}), this.componentBase.append(this.actionsMenuButton);
|
|
513
|
+
}
|
|
514
|
+
createActionsMenuItems() {
|
|
515
|
+
this.actionsMenuItems = [{ eventFunction: () => this.handleBlokActions.bind(this, "addBlockBefore"), innerHTML: "Add Block Before", order: 0, show: () => this.canAddBlocks }, { eventFunction: () => this.handleBlokActions.bind(this, "addBlockAfter"), innerHTML: "Add Block After", order: 1, show: () => this.canAddBlocks }, { eventFunction: () => this.handleBlokActions.bind(this, "duplicateBlock"), innerHTML: "Duplicate", order: 2, show: () => this.canAddBlocks }, { eventFunction: () => this.handleBlokActions.bind(this, "copy"), innerHTML: "Copy", order: 3, show: () => this.appVersion === "v2" }, { separator: !0, order: 4, show: () => this.canAddBlocks && this.canMoveForward || !!(this.canMoveBackward && this.lastBreadcrumbItem._parentindex) }, { eventFunction: () => this.handleBlokActions.bind(this, "moveForward"), innerHTML: "Move Forward", order: 5, show: () => this.canMoveForward }, { eventFunction: () => this.handleBlokActions.bind(this, "moveBackward"), innerHTML: "Move Backward", order: 6, show: () => this.canMoveBackward && this.lastBreadcrumbItem._parentindex }, { separator: !0, order: 7, show: () => this.canAddBlocks && this.canDeleteBlocks }, { eventFunction: () => this.handleBlokActions.bind(this, "deleteBlock"), className: `${i.ACTIONS_MENU}__menu-item--delete`, innerHTML: "Delete", order: 8, show: () => this.canDeleteBlocks }];
|
|
516
|
+
}
|
|
517
|
+
createActionsMenu() {
|
|
518
|
+
this.actionsMenu = document.createElement("div"), this.actionsMenu.setAttribute("class", i.ACTIONS_MENU), this.actionsMenu.setAttribute("id", i.ACTIONS_MENU), this.componentBase.append(this.actionsMenu);
|
|
519
|
+
}
|
|
520
|
+
updateActionsMenu() {
|
|
521
|
+
this.actionsMenu.innerHTML = "";
|
|
522
|
+
const t = `${i.ACTIONS_MENU}__menu-item`, e = "button", n = "click";
|
|
523
|
+
this.actionsMenuItems.sort((s, r) => s.order > r.order ? 1 : r.order > s.order ? -1 : 0).forEach((s) => {
|
|
524
|
+
if (s.separator && s.show()) {
|
|
525
|
+
this.actionsMenu.appendChild(document.createElement("hr"));
|
|
526
|
+
return;
|
|
527
|
+
}
|
|
528
|
+
const r = document.createElement(s.element ? s.element : e);
|
|
529
|
+
r.classList.add(t), s.className && r.classList.add(s.className), r.innerHTML = s.innerHTML, s.eventFunction && r.addEventListener(s.event ? s.event : n, s.eventFunction()), s.show() && this.actionsMenu.appendChild(r);
|
|
530
|
+
}), this.actionsMenuButton.style.display = "flex";
|
|
531
|
+
}
|
|
532
|
+
}
|
|
533
|
+
var S = Object.defineProperty, T = (o, t, e) => t in o ? S(o, t, { enumerable: !0, configurable: !0, writable: !0, value: e }) : o[t] = e, m = (o, t, e) => T(o, typeof t != "symbol" ? t + "" : t, e);
|
|
534
|
+
let j = class {
|
|
535
|
+
constructor(t) {
|
|
536
|
+
m(this, "isInEditor"), m(this, "enterEditmode"), m(this, "pingEditor"), m(this, "on");
|
|
537
|
+
const e = new w(t);
|
|
538
|
+
this.isInEditor = () => e.isInEditor(), this.enterEditmode = (n) => {
|
|
539
|
+
e.enterEditmode(n);
|
|
540
|
+
}, this.pingEditor = (n) => {
|
|
541
|
+
e.pingEditor(n);
|
|
542
|
+
}, this.on = (n, s) => {
|
|
543
|
+
e.on(n, s);
|
|
544
|
+
};
|
|
545
|
+
}
|
|
546
|
+
};
|
|
547
|
+
const h = (o) => ({ tag: "success", value: o }), c = (o) => ({ tag: "failure", error: o, path: [] }), B = (o, t) => ({ tag: "failure", error: o.error, path: [t, ...o.path] }), $ = (o) => typeof o > "u", L = (o) => typeof o == "string", P = (o) => typeof o == "object" && o !== null, b = Symbol("propertyAbsent"), _ = Symbol("omitProperty"), H = "Not an object", U = (o) => B(c("Property is missing"), { tag: "object", key: o }), D = (o) => {
|
|
548
|
+
const t = Object.entries(o);
|
|
549
|
+
return (e) => {
|
|
550
|
+
if (!P(e)) return c(H);
|
|
551
|
+
const n = {};
|
|
552
|
+
for (let s = 0; s < t.length; s++) {
|
|
553
|
+
const [r, u] = t[s], d = e[r];
|
|
554
|
+
if (d === void 0 && !e.hasOwnProperty(r)) {
|
|
555
|
+
const a = u(b);
|
|
556
|
+
if (a.tag === "failure" || a.value === b) return U(r);
|
|
557
|
+
a.value !== _ && (n[r] = a.value);
|
|
558
|
+
} else {
|
|
559
|
+
const a = u(d);
|
|
560
|
+
if (a.tag === "failure") return B(a, { tag: "object", key: r });
|
|
561
|
+
n[r] = a.value;
|
|
562
|
+
}
|
|
563
|
+
}
|
|
564
|
+
return h(n);
|
|
565
|
+
};
|
|
566
|
+
}, F = (o) => $(o) ? h(o) : c("Not undefined"), p = (o) => L(o) ? h(o) : c("Not a string"), R = (...o) => (t) => {
|
|
567
|
+
for (const e of o) {
|
|
568
|
+
const n = e(t);
|
|
569
|
+
if (n.tag === "success") return h(n.value);
|
|
570
|
+
}
|
|
571
|
+
return c("No parser in the union matched");
|
|
572
|
+
}, V = (o) => R(z, F, o), z = (o) => o === b ? h(_) : c("not optional");
|
|
573
|
+
D({ name: p, space: V(p), uid: p, id: p });
|
|
574
|
+
export {
|
|
575
|
+
j as default
|
|
576
|
+
};
|
package/dist/index.d.ts
CHANGED
|
@@ -6,11 +6,12 @@ export interface StoryblokBridgeEvent {
|
|
|
6
6
|
}
|
|
7
7
|
export declare const useStoryblokBridge: <T extends StoryblokComponentType<string> = any>(id: number, cb: (newStory: ISbStoryData<T>) => void, options?: StoryblokBridgeConfigV2) => void;
|
|
8
8
|
export declare const storyblokInit: (pluginOptions?: SbSDKOptions) => SbInitResult;
|
|
9
|
-
export declare const loadStoryblokBridge: () => Promise<
|
|
9
|
+
export declare const loadStoryblokBridge: () => Promise<void>;
|
|
10
10
|
export { useStoryblokBridge as registerStoryblokBridge };
|
|
11
11
|
export { default as apiPlugin } from './api';
|
|
12
12
|
export { default as storyblokEditable } from './editable';
|
|
13
13
|
export * from './types';
|
|
14
|
+
export type { BridgeParams } from '@storyblok/preview-bridge';
|
|
14
15
|
export { buildStoryblokImage, renderRichText, splitTableRows } from '@storyblok/richtext';
|
|
15
16
|
export type { SbRichTextDoc, SbRichTextImageOptions, SbRichTextMark, SbRichTextNode, SbRichTextProps, SbRichTextRenderContext, SbRichTextRendererMap, } from '@storyblok/richtext';
|
|
16
17
|
export { default as StoryblokClient } from 'storyblok-js-client';
|
package/dist/storyblok-js.js
CHANGED
|
@@ -4,4 +4,213 @@
|
|
|
4
4
|
* description: SDK to integrate Storyblok into your project using JavaScript.
|
|
5
5
|
* author: undefined
|
|
6
6
|
*/
|
|
7
|
-
(function(
|
|
7
|
+
(function(a,m){typeof exports=="object"&&typeof module<"u"?m(exports,require("storyblok-js-client"),require("@storyblok/richtext")):typeof define=="function"&&define.amd?define(["exports","storyblok-js-client","@storyblok/richtext"],m):(a=typeof globalThis<"u"?globalThis:a||self,m(a.storyblok={},a.StoryblokClient,a.StoryblokRichtext))})(this,(function(a,m,E){"use strict";let v=!1,p;const _=[],M=()=>typeof window>"u"?Promise.reject(new Error("Cannot load Storyblok bridge: window is undefined (server-side environment)")):(window.storyblokRegisterEvent=o=>{if(!window.location.search.includes("_storyblok")){console.warn("You are not in Draft Mode or in the Visual Editor.");return}v?o():_.push(o)},v?Promise.resolve():p||(p=Promise.resolve().then(()=>ae).then(({default:o})=>{window.StoryblokBridge=o,_.forEach(e=>e()),v=!0}).catch(o=>{throw p=void 0,o}),p)),L=(o={})=>{const{apiOptions:e}=o;if(!e||!e.accessToken){console.error("You need to provide an access token to interact with Storyblok API. Read https://www.storyblok.com/docs/api/content-delivery#topics/authentication");return}return{storyblokApi:new m(e)}},P=o=>{if(typeof o!="object"||typeof o._editable!="string")return{};try{const e=JSON.parse(o._editable.replace(/^<!--#storyblok#/,"").replace(/-->$/,""));return e?{"data-blok-c":JSON.stringify(e),"data-blok-uid":`${e.id}-${e.uid}`}:{}}catch{return{}}};function R(o){const{language:e,resolveRelations:t,...n}=o;return e&&console.warn("[Storyblok] The `language` bridge option is no longer supported by the bundled bridge. Language context is now passed automatically by the Visual Editor via the `_storyblok_lang` URL parameter."),{...n,...t!==void 0&&{resolveRelations:Array.isArray(t)?t:[t]}}}const w=(o,e,t={})=>{var l;const i=!(typeof window>"u")&&typeof window.storyblokRegisterEvent<"u",r=new URL((l=window.location)==null?void 0:l.href).searchParams.get("_storyblok"),h=r!==null&&+r===o;if(!(!i||!h)){if(!o){console.warn("Story ID is not defined. Please provide a valid ID.");return}window.storyblokRegisterEvent(()=>{new window.StoryblokBridge(R(t)).on(["input","published","change"],d=>{var g;d&&(d.action==="input"&&((g=d.story)==null?void 0:g.id)===o?e(d.story):(d.action==="change"||d.action==="published")&&d.storyId===o&&window.location.reload())})})}},U=(o={})=>{var g,$;const{bridge:e,accessToken:t,use:n=[],apiOptions:i={},bridgeUrl:r}=o;r&&console.warn("[Storyblok] The `bridgeUrl` option is deprecated and will be removed in a future major version. The Storyblok bridge is now bundled and is no longer loaded from a CDN URL."),i.accessToken=i.accessToken||t;const h={bridge:e,apiOptions:i};let l={};n.forEach(le=>{l={...l,...le(h)}});const d=!(typeof window>"u")&&(($=(g=window.location)==null?void 0:g.search)==null?void 0:$.includes("_storyblok_tk"));return e!==!1&&d&&M(),l},H=()=>M(),D=(o,e)=>{for(;o&&o.nodeType===1;){if(o.hasAttribute(e))return o;o=o.parentNode}return null},A=o=>{const e=D(o,"data-blok-c");if(!e)return null;const t=e.getAttribute("data-blok-c");return JSON.parse(t)},F=(o,e)=>o.contains(e),u=o=>document.querySelector(`[data-blok-uid="${o}"]`),S=o=>{const e=o.getBoundingClientRect();return e.top<0&&e.top+e.height>=0||e.top>=0&&e.top<=(window.innerHeight||document.documentElement.clientHeight)},j=o=>{let e={};try{const t=o.replace(/\\/g,"");e=JSON.parse(t)}catch{console.error("Error parsing json",o)}return e},V=o=>{const e=[],t=()=>NodeFilter.FILTER_ACCEPT,n=document.createNodeIterator(o,NodeFilter.SHOW_COMMENT,t,!1);let i={};for(;i=n.nextNode();)if(i.nodeValue.indexOf("#storyblok#")>-1){const r=i.nodeValue.replace("#storyblok#",""),h=i.nextElementSibling||i.nextSibling,l=j(r);l&&e.push({options:l,el:h})}return e},I=o=>{let e="";return location.search.substr(1).split("&").forEach(t=>{const n=t.split("=");n[0]===o&&(e=decodeURIComponent(n[1]))}),e},z=(o,e,t)=>typeof o!="string"?"":o.toString().replace(/([A-Z])/g," $1").trim().toLowerCase().replace(/[_-]/g," ").replace(/(?:^|\s)\S/g,function(n,i){return n.toUpperCase()}),O=o=>o&&o.display_name?o.display_name:z(o.name),N=o=>{const e=document.createElementNS("http://www.w3.org/2000/svg","svg");e.setAttribute("viewBox",o.viewBox),e.setAttribute("class",o.svgClass);const t=document.createElementNS(e.namespaceURI,"path");return t.setAttribute("d",o.path),t.setAttribute("fill",o.pathFill),t.setAttribute("transform",o.pathTransform?o.pathTransform:"translate(0 0)"),e.appendChild(t),e},q=o=>o,Y=q,T=Y`
|
|
8
|
+
@keyframes smoke {
|
|
9
|
+
from {
|
|
10
|
+
background-color: rgba(89, 197, 198, 0);
|
|
11
|
+
}
|
|
12
|
+
to {
|
|
13
|
+
background-color: rgba(89, 197, 198, 0.5);
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
.storyblok--outlined .storyblok__outline,
|
|
18
|
+
.storyblok--outlined [data-blok-c] {
|
|
19
|
+
outline: 1px dashed rgba(182, 186, 191, 0.5);
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
.storyblok--outlined .storyblok__outline[data-blok-focused='true'],
|
|
23
|
+
.storyblok--outlined [data-blok-c][data-blok-focused='true'] {
|
|
24
|
+
outline: 0;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
.storyblok__hint {
|
|
28
|
+
box-sizing: border-box;
|
|
29
|
+
outline: 1px solid #05807f;
|
|
30
|
+
pointer-events: none;
|
|
31
|
+
position: absolute;
|
|
32
|
+
transition: opacity 0.2s ease;
|
|
33
|
+
z-index: 16777272;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
.storyblok__highlight {
|
|
37
|
+
background: rgba(89, 197, 198, 0.2);
|
|
38
|
+
outline: 1px solid #05807f;
|
|
39
|
+
pointer-events: none;
|
|
40
|
+
position: absolute;
|
|
41
|
+
transition: opacity 0.2s ease;
|
|
42
|
+
z-index: 16777270;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
.storyblok__overlay {
|
|
46
|
+
box-shadow: 0 0 8px 2px rgba(34, 42, 69, 0.07);
|
|
47
|
+
box-sizing: border-box;
|
|
48
|
+
outline: 1px solid #05807f;
|
|
49
|
+
pointer-events: none;
|
|
50
|
+
position: absolute;
|
|
51
|
+
z-index: 16777273;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
.storyblok__overlay-menu {
|
|
55
|
+
background-color: #05807f;
|
|
56
|
+
border-radius: 5px;
|
|
57
|
+
display: inline-flex;
|
|
58
|
+
font-family:
|
|
59
|
+
-apple-system, blinkmacsystemfont, 'Segoe UI', roboto, helvetica, arial,
|
|
60
|
+
sans-serif, 'Apple Color Emoji', 'Segoe UI Emoji', 'Segoe UI Symbol';
|
|
61
|
+
height: 30px;
|
|
62
|
+
left: -1px;
|
|
63
|
+
pointer-events: auto;
|
|
64
|
+
position: absolute;
|
|
65
|
+
top: -40px;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
.storyblok__overlay-menu--simple .storyblok__overlay-menu-btn {
|
|
69
|
+
border-bottom-right-radius: 5px;
|
|
70
|
+
border-top-right-radius: 5px;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
.storyblok__overlay-menu-label {
|
|
74
|
+
color: #fff;
|
|
75
|
+
font-size: 14px;
|
|
76
|
+
line-height: 30px;
|
|
77
|
+
margin-right: 20px;
|
|
78
|
+
max-width: 200px;
|
|
79
|
+
overflow-x: hidden;
|
|
80
|
+
text-overflow: ellipsis;
|
|
81
|
+
white-space: nowrap;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
.storyblok__overlay-menu-label:first-child {
|
|
85
|
+
margin-left: 20px;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
.storyblok__overlay-menu-btn {
|
|
89
|
+
align-items: center;
|
|
90
|
+
background-color: transparent;
|
|
91
|
+
border: 0;
|
|
92
|
+
display: flex;
|
|
93
|
+
justify-content: center;
|
|
94
|
+
outline: none;
|
|
95
|
+
padding: 0;
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
.storyblok__overlay-menu-btn:hover {
|
|
99
|
+
background-color: #0d5454;
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
.storyblok__overlay-menu-btn-action {
|
|
103
|
+
border-bottom-right-radius: 5px;
|
|
104
|
+
border-left: 1px solid #fff;
|
|
105
|
+
border-top-right-radius: 5px;
|
|
106
|
+
height: inherit;
|
|
107
|
+
margin: auto;
|
|
108
|
+
margin-right: 0;
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
.storyblok__overlay-menu-btn-parent {
|
|
112
|
+
border-bottom-left-radius: 5px;
|
|
113
|
+
border-top-left-radius: 5px;
|
|
114
|
+
cursor: pointer;
|
|
115
|
+
margin: 0;
|
|
116
|
+
width: auto;
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
.storyblok__overlay-menu-svg {
|
|
120
|
+
box-sizing: border-box;
|
|
121
|
+
cursor: pointer;
|
|
122
|
+
height: 24px;
|
|
123
|
+
margin: 0 3px;
|
|
124
|
+
width: 24px;
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
.storyblok__overlay--bottom .storyblok__overlay-menu {
|
|
128
|
+
bottom: -40px;
|
|
129
|
+
top: auto;
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
.storyblok__overlay--clicked {
|
|
133
|
+
animation-duration: 0.2s;
|
|
134
|
+
animation-iteration-count: 1;
|
|
135
|
+
animation-name: smoke;
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
.storyblok__actions-menu,
|
|
139
|
+
.storyblok__breadcrumbs-menu {
|
|
140
|
+
background-color: #fff;
|
|
141
|
+
border: 1px solid #dfe3e8;
|
|
142
|
+
border-radius: 5px;
|
|
143
|
+
box-shadow: 0 2px 17px 3px rgba(34, 42, 69, 0.07);
|
|
144
|
+
box-sizing: content-box;
|
|
145
|
+
display: none;
|
|
146
|
+
height: fit-content;
|
|
147
|
+
min-width: 156px;
|
|
148
|
+
overflow: hidden;
|
|
149
|
+
padding: 11px 0;
|
|
150
|
+
position: absolute;
|
|
151
|
+
top: 25px;
|
|
152
|
+
z-index: 2;
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
.storyblok__actions-menu hr,
|
|
156
|
+
.storyblok__breadcrumbs-menu hr {
|
|
157
|
+
background-color: #dfe3e8;
|
|
158
|
+
border: 0;
|
|
159
|
+
height: 1px;
|
|
160
|
+
margin: 11px 0 11px 20px;
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
.storyblok__actions-menu__menu-item,
|
|
164
|
+
.storyblok__breadcrumbs-menu__menu-item {
|
|
165
|
+
align-items: center;
|
|
166
|
+
appearance: none;
|
|
167
|
+
background: #fff;
|
|
168
|
+
border: 0;
|
|
169
|
+
color: #1b243f;
|
|
170
|
+
cursor: pointer;
|
|
171
|
+
display: flex;
|
|
172
|
+
font-family:
|
|
173
|
+
-apple-system, blinkmacsystemfont, 'Segoe UI', roboto, helvetica, arial,
|
|
174
|
+
sans-serif, 'Apple Color Emoji', 'Segoe UI Emoji', 'Segoe UI Symbol';
|
|
175
|
+
font-size: 14px;
|
|
176
|
+
padding: 8px 20px;
|
|
177
|
+
text-align: left;
|
|
178
|
+
width: 100%;
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
.storyblok__actions-menu__menu-item--delete,
|
|
182
|
+
.storyblok__breadcrumbs-menu__menu-item--delete {
|
|
183
|
+
color: #c11c14;
|
|
184
|
+
margin-bottom: 0;
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
.storyblok__actions-menu__menu-item--selected,
|
|
188
|
+
.storyblok__breadcrumbs-menu__menu-item--selected {
|
|
189
|
+
color: #05807f;
|
|
190
|
+
cursor: default;
|
|
191
|
+
margin-bottom: 0;
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
.storyblok__actions-menu__menu-item--selected:hover,
|
|
195
|
+
.storyblok__breadcrumbs-menu__menu-item--selected:hover {
|
|
196
|
+
background: transparent;
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
.storyblok__actions-menu__menu-item:hover,
|
|
200
|
+
.storyblok__breadcrumbs-menu__menu-item:hover {
|
|
201
|
+
background: #eff1f3;
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
.storyblok__actions-menu__menu-item:focus,
|
|
205
|
+
.storyblok__breadcrumbs-menu__menu-item:focus {
|
|
206
|
+
outline: none;
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
.storyblok__actions-menu {
|
|
210
|
+
left: calc(100% - 20px);
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
.storyblok__breadcrumbs-menu {
|
|
214
|
+
left: -10px;
|
|
215
|
+
}
|
|
216
|
+
`,s={OUTLINE:"storyblok--outlined",STYLESHEET:"storyblok-bridge-stylesheet",HINT:"storyblok__hint",HIGHLIGHTER:"storyblok__highlight",OVERLAY:"storyblok__overlay",COMPONENT_BASE:"storyblok__overlay-menu",ACTIONS_MENU:"storyblok__actions-menu",BREADCRUMBS_MENU:"storyblok__breadcrumbs-menu"};class G{constructor(e){this.appVersion="v1",this.inEditor=!0,this.initialized=!1,this.currentUid=null,this.storyId="",this.componentNames={},this.outlineOnMoveInterval=null,this.calcInterval=null,this.canAddBlocks=!1,this.canMoveForward=!1,this.canMoveBackward=!1,this.canDeleteBlocks=!1,this.navigationBreadcrumbs=[],this.focusState=!1,this.actionsEnabled=!1,this.hinter=null,this.highlighter=null,this.overlay=null,this.componentBase=null,this.componentLabel=null,this.breadcrumbsButtonMenu=null,this.breadcrumbsMenu=null,this.actionsMenu=null,this.actionsMenuButton=null,this.actionsMenuItems=null,this.events={input:[],change:[],published:[],unpublished:[],viewLiveVersion:[],enterEditmode:[],enterComponent:[],hoverComponent:[],highlightComponent:[],customEvent:[],pingBack:[],sessionReceived:[],editedBlok:[],deselectBlok:[],addedBlock:[],deletedBlock:[],movedBlock:[],duplicatedBlock:[]};const t={customParent:null,resolveRelations:null,resolveLinks:null,preventClicks:!1,initOnlyOnce:!0,fallbackLang:null};this.config={...t,...e},this.init()}get isInIframe(){return window.top!==window.self}get csProtocol(){let e=location.protocol.replace(":","");return e!=="http"&&e!=="https"&&(e="https"),e}get targetOrigin(){return this.config.customParent?this.config.customParent:I("_storyblok_env")==="stage"?`${this.csProtocol}://app-beta.storyblok.com`:`${this.csProtocol}://app.storyblok.com`}get lastBreadcrumbItem(){return this.navigationBreadcrumbs[this.navigationBreadcrumbs.length-1]||{}}isInEditor(){return this.inEditor}init(){if(document.body===null){console.error("Body tag not found. Please install the Storyblok bridge script inside the body tag");return}this.config.initOnlyOnce&&document.querySelectorAll(`.${s.HINT}`).length>0||this.isInIframe&&(this.resetAllEvents(),this.addMessageListener(),this.outlineOnMove(),this.buildBridgeStyles(),this.on("enterEditmode",this.enterEditmode),this.isInIframe&&this.sendDataToEditor({action:"initialized",config:this.config}),this.initialized=!0)}keyPress(e,t){(t.key==="z"&&t.metaKey||t.key==="z"&&t.ctrlKey)&&(t.preventDefault(),t.stopImmediatePropagation(),e.sendDataToEditor({action:"undo"})),(t.key==="y"&&t.metaKey||t.key==="y"&&t.ctrlKey)&&(t.preventDefault(),t.stopImmediatePropagation(),e.sendDataToEditor({action:"redo"}))}sendDataToEditor(e){window.parent.postMessage(e,this.targetOrigin)}buildBridgeStyles(){document.getElementById(s.STYLESHEET)?(this.hinter=document.querySelector(`.${s.HINT}`),this.highlighter=document.querySelector(`.${s.HIGHLIGHTER}`),this.overlay=document.querySelector(`.${s.OVERLAY}`),this.componentBase=document.querySelector(`.${s.COMPONENT_BASE}`),this.breadcrumbsButtonMenu=document.querySelector(`.${s.COMPONENT_BASE}-btn-parent`),this.breadcrumbsMenu=document.querySelector(`.${s.BREADCRUMBS_MENU}`),this.actionsMenuButton=document.querySelector(`.${s.COMPONENT_BASE}-btn-action`),this.actionsMenu=document.querySelector(`.${s.ACTIONS_MENU}`),this.componentLabel=document.querySelector(`.${s.COMPONENT_BASE} > .${s.COMPONENT_BASE}-label`),this.createActionsMenuItems()):(this.createBridgeStylesheet(),this.createHinter(),this.createHighlighter(),this.createOverlay(),this.createComponentContext())}createBridgeStylesheet(){const e=document.createElement("style");e.setAttribute("type","text/css"),e.id=s.STYLESHEET,"textContent"in e?e.textContent=T:e.styleSheet.cssText=T,document.getElementsByTagName("head")[0].appendChild(e)}createHinter(){this.hinter=document.createElement("div"),this.hinter.className=s.HINT,this.hideElement(this.hinter),document.body.appendChild(this.hinter)}createHighlighter(){this.highlighter=document.createElement("div"),this.highlighter.style.opacity=0,this.hideElement(this.highlighter),document.body.appendChild(this.highlighter)}createOverlay(){this.overlay=document.createElement("div"),this.overlay.setAttribute("class",s.OVERLAY),this.overlay.setAttribute("id",s.OVERLAY),this.hideElement(this.overlay),document.body.appendChild(this.overlay)}calculateElementPosition(e,t){if(!t){this.hideElement(e);return}const n=u(t);if(n){const{left:i,top:r}=this.getElementOffset(n);r<=30?this.overlay.classList.add(`${s.OVERLAY}--bottom`):this.overlay.classList.remove(`${s.OVERLAY}--bottom`),e.style.top=`${r}px`,e.style.left=`${i}px`,e.style.width=`${n.offsetWidth}px`,e.style.height=`${n.offsetHeight}px`,e.style.minHeight="5px"}else this.hideElement(e)}getElementOffset(e){const t=e.getBoundingClientRect(),n=window.pageXOffset||document.documentElement.scrollLeft,i=window.pageYOffset||document.documentElement.scrollTop;return{top:t.top+i,left:t.left+n}}resetAllEvents(){for(const e in this.events)this.events[e]=[]}addMessageListener(){window.addEventListener&&addEventListener("message",this.receiveMessageFromApp.bind(this),!1)}receiveMessageFromApp(e){e&&e.data&&e.data.action&&this.emit(e.data.action,e.data)}emit(e,...t){const n=this.events[e];if(!(!e||!n||!n.length))for(let i=0;i<n.length;i++)n[i].apply(this,t)}outlineOnMoveHandler(){document.body.classList.add(s.OUTLINE);const e=()=>{document.body.classList.remove(s.OUTLINE),this.hinter&&(this.hinter.style.opacity=0)};this.outlineOnMoveInterval&&clearTimeout(this.outlineOnMoveInterval),this.outlineOnMoveInterval=setTimeout(e,800)}outlineOnMove(){document.addEventListener("mousemove",this.outlineOnMoveHandler.bind(this),!1)}on(e,t){if(e.constructor===Array){for(const n of e)this.subscribeEvent(n,t);return}this.subscribeEvent(e,t)}subscribeEvent(e,t){e==="input"&&(this.actionsEnabled=!0),this.events[e].indexOf(t)===-1&&this.events[e].push(t)}pingEditor(e){this.isInIframe?this.sendDataToEditor({action:"ping"}):(this.inEditor=!1,e(this)),this.on("pingBack",this.handlePingBack(e))}handlePingBack(e){return()=>{this.inEditor=!0,e(this)}}handleEditedBlok(e){this.navigationBreadcrumbs=e.breadcrumbs,this.canAddBlocks=e.canAddBlocks||!1,this.canMoveForward=e.canMoveForward||!1,this.canMoveBackward=e.canMoveBackward||!1,this.canDeleteBlocks=e.canDeleteBlocks||!1,this.updateComponentBase(e.blok)}handleAddMoveBlok(e){const t=u(`${this.storyId}-${e.blockId}`);t&&this.handleOpenBlok(t)}handleDeselectBlock(){document.querySelectorAll("[data-blok-focused]").forEach(e=>e.removeAttribute("data-blok-focused")),this.hideElement(this.overlay)}handleDuplicatedBlok(e){this.handleDeselectBlock(),setTimeout(()=>{const t=u(`${this.storyId}-${e.blockId}`);this.handleOpenBlok(t)},500)}handleWindowClick(e){this.config.preventClicks&&(e.preventDefault(),e.stopPropagation()),this.handleOpenBlok(e.target,e)}handleOpenBlok(e,t){const n=A(e);if(n){t&&n.uid!==this.currentUid&&(t.preventDefault(),t.stopPropagation()),this.currentUid=n.uid,this.storyId=n.id,this.openBlok(n);return}t&&this.toggleFocusElement(e,!0)}enterEditmode(e){const t=V(document.body);e&&e.appVersion&&(this.appVersion=e.appVersion),e&&e.componentNames&&(this.componentNames=e.componentNames);for(let n=0;n<t.length;n++){const i=t[n].el,r=t[n].options;!i||i.nodeType!==Node.ELEMENT_NODE||(r.name=this.componentNames[r.name]||r.name,i.setAttribute("data-blok-c",JSON.stringify(r)),i.setAttribute("data-blok-uid",`${r.id}-${r.uid}`),i.offsetHeight<5&&(i.style["min-height"]="5px"),i.classList.add("storyblok__outline"))}if(this.on("addedBlock",this.handleAddMoveBlok),this.on("duplicatedBlock",this.handleDuplicatedBlok),this.on("movedBlock",this.handleAddMoveBlok),this.on("enterComponent",this.enterComponent),this.on("highlightComponent",this.highlightComponent),this.on("hoverComponent",this.hoverComponent),this.on("editedBlok",this.handleEditedBlok),this.on("deselectBlok",this.handleDeselectBlock),e&&e.blockId&&this.config.setActiveBlock){const n=u(`${e.storyId}-${e.blockId}`);this.handleOpenBlok(n)}window.addEventListener("click",this.handleWindowClick.bind(this)),this.calcInterval!==null&&window.clearInterval(this.calcInterval),this.calcInterval=window.setInterval(()=>{this.calculateElementPosition(this.overlay,`${this.storyId}-${this.currentUid}`)},300)}highlightComponent(e){this.highlighter.innerHTML="",e.componentIds.length>0?(this.highlighter.style.display="block",this.highlighter.style.opacity=1):(this.highlighter.style.display="none",this.highlighter.style.opacity=0);for(let t=0;t<e.componentIds.length;t++){const n=`${e.storyId}-${e.componentIds[t]}`,i=u(n);if(i){const r=document.createElement("div");r.setAttribute("class",s.HIGHLIGHTER),this.highlighter.appendChild(r),this.calculateElementPosition(r,n),e.componentId===e.componentIds[t]&&!S(i)&&typeof i.scrollIntoView<"u"&&i.scrollIntoView()}}}hoverComponent(e){this.calculateElementPosition(this.hinter,`${e.storyId}-${e.componentId}`),this.hinter.style.opacity=1,this.hinter.style.display="block"}toggleFocusElement(e,t=!1){if(!F(this.overlay,e)){if(this.handleDeselectBlock(),!t&&this.storyId===I("_storyblok")){e.setAttribute("data-blok-focused",!0),this.showFocusedElement(this.overlay),this.focusState=!1;return}this.focusState||this.sendDataToEditor({action:"noFocus"})}}showFocusedElement(e){if(!this.currentUid){this.hideElement(e);return}this.showElement(e),this.calculateElementPosition(e,`${this.storyId}-${this.currentUid}`)}handleBlokActions(e){this.sendDataToEditor({action:e,blok:this.lastBreadcrumbItem}),e==="addBlockBefore"||e==="addBlockAfter"||e==="copy"?this.hideElement(this.actionsMenu):this.hideElement(this.overlay),(e==="moveForward"||e==="moveBackward")&&(this.focusState=!0)}hideElement(e){e.style.display="none"}showElement(e){e.style.display="block"}toggleElement(e){if(e.style.display==="block"){this.hideElement(e);return}this.showElement(e)}enterComponent(e){const t=u(`${e.storyId}-${e.componentId}`),n=A(t);n&&(this.hinter.style.opacity=0,this.hinter.style.display="none",this.currentUid=n.uid,this.storyId=n.id,this.scrollIntoView(t),this.handleEditedBlok(e))}scrollIntoView(e){e&&!S(e)&&typeof e.scrollIntoView<"u"&&setTimeout(()=>{e.scrollIntoView({behavior:"smooth",block:"start"})},100)}openBlok(e){this.sendDataToEditor({action:"edit",dataC:e,config:this.config})}createComponentContext(){this.createComponentBase(),this.createActionsMenu(),this.createActionsMenuItems(),this.createBreadcrumbsMenu(),this.createActionsMenuButton(),this.createBreadcrumbsMenuButton(),this.createComponentLabel(),this.createComponentButtonLabel()}createComponentBase(){this.componentBase=document.createElement("div"),this.componentBase.setAttribute("class",s.COMPONENT_BASE),this.componentBase.setAttribute("id",s.COMPONENT_BASE),this.overlay.append(this.componentBase)}createComponentLabel(){this.componentLabel=document.createElement("span"),this.componentLabel.setAttribute("class",`${s.COMPONENT_BASE}-label`),this.componentBase.prepend(this.componentLabel)}createComponentButtonLabel(){const e=document.createElement("span");e.setAttribute("class",`${s.COMPONENT_BASE}-label`),this.breadcrumbsButtonMenu.appendChild(e)}updateComponentLabel(e){document.querySelectorAll(`.${s.COMPONENT_BASE}-label`).forEach(t=>t.innerText=this.componentNames[e.name]||O(e))}updateComponentBase(e){this.hideElement(this.actionsMenu),this.hideElement(this.breadcrumbsMenu),this.overlay.classList.add(`${s.OVERLAY}--clicked`),setTimeout(()=>{this.overlay.classList.remove(`${s.OVERLAY}--clicked`)},400),this.navigationBreadcrumbs.length>1?(this.updateBreadcrumbsMenu(this.navigationBreadcrumbs),this.actionsEnabled?this.updateActionsMenu():(this.componentBase.setAttribute("class",`${s.COMPONENT_BASE} ${s.COMPONENT_BASE}--simple`),this.hideElement(this.actionsMenuButton)),this.hideElement(this.componentLabel)):(this.hideElement(this.breadcrumbsButtonMenu),this.hideElement(this.actionsMenuButton),this.showElement(this.componentLabel)),this.updateComponentLabel(e);const t=u(`${this.storyId}-${e.uid}`);t&&this.toggleFocusElement(t)}createBreadcrumbsMenuButton(){this.breadcrumbsButtonMenu=document.createElement("button"),this.breadcrumbsButtonMenu.setAttribute("class",`${s.COMPONENT_BASE}-btn ${s.COMPONENT_BASE}-btn-parent`),this.breadcrumbsButtonMenu.prepend(N({viewBox:"0 0 24 24",svgClass:`${s.COMPONENT_BASE}-svg`,path:"M13.73 14.284l-2.197-2.216 2.197-2.217a1.051 1.051 0 000-1.477 1.03 1.03 0 00-1.465 0l-2.93 2.955a1.043 1.043 0 00-.287.554l-.014.123v.123c.014.247.115.489.301.677l2.93 2.956a1.03 1.03 0 001.465 0 1.051 1.051 0 000-1.478z",pathFill:"#ffffff"})),this.breadcrumbsButtonMenu.addEventListener("click",()=>{this.toggleElement(this.breadcrumbsMenu),this.hideElement(this.actionsMenu)}),this.componentBase.prepend(this.breadcrumbsButtonMenu)}createBreadcrumbsMenu(){this.breadcrumbsMenu=document.createElement("div"),this.breadcrumbsMenu.setAttribute("class",s.BREADCRUMBS_MENU),this.breadcrumbsMenu.setAttribute("id",s.BREADCRUMBS_MENU),this.componentBase.append(this.breadcrumbsMenu)}updateBreadcrumbsMenu(e){this.breadcrumbsMenu.innerHTML="";const t=[];for(let n=0;n<e.length;n++){t[n]=document.createElement("button"),t[n].innerHTML=O({display_name:this.componentNames[e[n].component],name:e[n].component});const i=e[n];t[n].addEventListener("click",r=>{r.stopPropagation(),this.currentUid=i._uid,this.openBlok({id:this.storyId,uid:i._uid,name:i.component})}),t[n].classList.add(`${s.BREADCRUMBS_MENU}__menu-item`),e[n]._uid===this.currentUid&&(t[n].classList.add(`${s.BREADCRUMBS_MENU}__menu-item--selected`),t[n].setAttribute("disabled",!0)),this.breadcrumbsMenu.appendChild(t[n]),this.breadcrumbsButtonMenu.style.display="flex"}}createActionsMenuButton(){this.actionsMenuButton=document.createElement("button"),this.actionsMenuButton.setAttribute("class",`${s.COMPONENT_BASE}-btn ${s.COMPONENT_BASE}-btn-action`),this.actionsMenuButton.prepend(N({viewBox:"0 0 24 24",svgClass:`${s.COMPONENT_BASE}-svg`,path:"M7.5 11a1.5 1.5 0 110 3 1.5 1.5 0 010-3zm10 0a1.5 1.5 0 110 3 1.5 1.5 0 010-3zm-5 0a1.5 1.5 0 110 3 1.5 1.5 0 010-3z",pathFill:"#ffffff"})),this.actionsMenuButton.addEventListener("click",()=>{this.toggleElement(this.actionsMenu),this.breadcrumbsMenu&&this.hideElement(this.breadcrumbsMenu)}),this.componentBase.append(this.actionsMenuButton)}createActionsMenuItems(){this.actionsMenuItems=[{eventFunction:()=>this.handleBlokActions.bind(this,"addBlockBefore"),innerHTML:"Add Block Before",order:0,show:()=>this.canAddBlocks},{eventFunction:()=>this.handleBlokActions.bind(this,"addBlockAfter"),innerHTML:"Add Block After",order:1,show:()=>this.canAddBlocks},{eventFunction:()=>this.handleBlokActions.bind(this,"duplicateBlock"),innerHTML:"Duplicate",order:2,show:()=>this.canAddBlocks},{eventFunction:()=>this.handleBlokActions.bind(this,"copy"),innerHTML:"Copy",order:3,show:()=>this.appVersion==="v2"},{separator:!0,order:4,show:()=>this.canAddBlocks&&this.canMoveForward||!!(this.canMoveBackward&&this.lastBreadcrumbItem._parentindex)},{eventFunction:()=>this.handleBlokActions.bind(this,"moveForward"),innerHTML:"Move Forward",order:5,show:()=>this.canMoveForward},{eventFunction:()=>this.handleBlokActions.bind(this,"moveBackward"),innerHTML:"Move Backward",order:6,show:()=>this.canMoveBackward&&this.lastBreadcrumbItem._parentindex},{separator:!0,order:7,show:()=>this.canAddBlocks&&this.canDeleteBlocks},{eventFunction:()=>this.handleBlokActions.bind(this,"deleteBlock"),className:`${s.ACTIONS_MENU}__menu-item--delete`,innerHTML:"Delete",order:8,show:()=>this.canDeleteBlocks}]}createActionsMenu(){this.actionsMenu=document.createElement("div"),this.actionsMenu.setAttribute("class",s.ACTIONS_MENU),this.actionsMenu.setAttribute("id",s.ACTIONS_MENU),this.componentBase.append(this.actionsMenu)}updateActionsMenu(){this.actionsMenu.innerHTML="";const e=`${s.ACTIONS_MENU}__menu-item`,t="button",n="click";this.actionsMenuItems.sort((i,r)=>i.order>r.order?1:r.order>i.order?-1:0).forEach(i=>{if(i.separator&&i.show()){this.actionsMenu.appendChild(document.createElement("hr"));return}const r=document.createElement(i.element?i.element:t);r.classList.add(e),i.className&&r.classList.add(i.className),r.innerHTML=i.innerHTML,i.eventFunction&&r.addEventListener(i.event?i.event:n,i.eventFunction()),i.show()&&this.actionsMenu.appendChild(r)}),this.actionsMenuButton.style.display="flex"}}var J=Object.defineProperty,K=(o,e,t)=>e in o?J(o,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):o[e]=t,f=(o,e,t)=>K(o,typeof e!="symbol"?e+"":e,t);let W=class{constructor(e){f(this,"isInEditor"),f(this,"enterEditmode"),f(this,"pingEditor"),f(this,"on");const t=new G(e);this.isInEditor=()=>t.isInEditor(),this.enterEditmode=n=>{t.enterEditmode(n)},this.pingEditor=n=>{t.pingEditor(n)},this.on=(n,i)=>{t.on(n,i)}}};const y=o=>({tag:"success",value:o}),b=o=>({tag:"failure",error:o,path:[]}),C=(o,e)=>({tag:"failure",error:o.error,path:[e,...o.path]}),X=o=>typeof o>"u",Z=o=>typeof o=="string",Q=o=>typeof o=="object"&&o!==null,B=Symbol("propertyAbsent"),x=Symbol("omitProperty"),ee="Not an object",te=o=>C(b("Property is missing"),{tag:"object",key:o}),oe=o=>{const e=Object.entries(o);return t=>{if(!Q(t))return b(ee);const n={};for(let i=0;i<e.length;i++){const[r,h]=e[i],l=t[r];if(l===void 0&&!t.hasOwnProperty(r)){const c=h(B);if(c.tag==="failure"||c.value===B)return te(r);c.value!==x&&(n[r]=c.value)}else{const c=h(l);if(c.tag==="failure")return C(c,{tag:"object",key:r});n[r]=c.value}}return y(n)}},ne=o=>X(o)?y(o):b("Not undefined"),k=o=>Z(o)?y(o):b("Not a string"),ie=(...o)=>e=>{for(const t of o){const n=t(e);if(n.tag==="success")return y(n.value)}return b("No parser in the union matched")},se=o=>ie(re,ne,o),re=o=>o===B?y(x):b("not optional");oe({name:k,space:se(k),uid:k,id:k});const ae=Object.freeze(Object.defineProperty({__proto__:null,default:W},Symbol.toStringTag,{value:"Module"}));a.StoryblokClient=m,Object.defineProperty(a,"buildStoryblokImage",{enumerable:!0,get:()=>E.buildStoryblokImage}),Object.defineProperty(a,"renderRichText",{enumerable:!0,get:()=>E.renderRichText}),Object.defineProperty(a,"splitTableRows",{enumerable:!0,get:()=>E.splitTableRows}),a.apiPlugin=L,a.loadStoryblokBridge=H,a.registerStoryblokBridge=w,a.storyblokEditable=P,a.storyblokInit=U,a.useStoryblokBridge=w,Object.defineProperty(a,Symbol.toStringTag,{value:"Module"})}));
|
package/dist/storyblok-js.mjs
CHANGED
|
@@ -4,98 +4,105 @@
|
|
|
4
4
|
* description: SDK to integrate Storyblok into your project using JavaScript.
|
|
5
5
|
* author: undefined
|
|
6
6
|
*/
|
|
7
|
-
import
|
|
8
|
-
import { default as
|
|
9
|
-
import { buildStoryblokImage as
|
|
10
|
-
let
|
|
11
|
-
const
|
|
12
|
-
|
|
13
|
-
|
|
7
|
+
import g from "storyblok-js-client";
|
|
8
|
+
import { default as _ } from "storyblok-js-client";
|
|
9
|
+
import { buildStoryblokImage as P, renderRichText as x, splitTableRows as A } from "@storyblok/richtext";
|
|
10
|
+
let u = !1, a;
|
|
11
|
+
const y = [], f = () => typeof window > "u" ? Promise.reject(
|
|
12
|
+
new Error("Cannot load Storyblok bridge: window is undefined (server-side environment)")
|
|
13
|
+
) : (window.storyblokRegisterEvent = (o) => {
|
|
14
|
+
if (!window.location.search.includes("_storyblok")) {
|
|
15
|
+
console.warn("You are not in Draft Mode or in the Visual Editor.");
|
|
14
16
|
return;
|
|
15
17
|
}
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
return;
|
|
25
|
-
}
|
|
26
|
-
const r = document.createElement("script");
|
|
27
|
-
r.async = !0, r.src = e, r.id = "storyblok-javascript-bridge", r.onerror = (t) => n(t), r.onload = (t) => {
|
|
28
|
-
p.forEach((s) => s()), y = !0, o(t);
|
|
29
|
-
}, document.getElementsByTagName("head")[0].appendChild(r);
|
|
30
|
-
}), h = (e = {}) => {
|
|
31
|
-
const { apiOptions: o } = e;
|
|
32
|
-
if (!o || !o.accessToken) {
|
|
18
|
+
u ? o() : y.push(o);
|
|
19
|
+
}, u ? Promise.resolve() : a || (a = import("./index-CtMAhUF-.js").then(({ default: o }) => {
|
|
20
|
+
window.StoryblokBridge = o, y.forEach((e) => e()), u = !0;
|
|
21
|
+
}).catch((o) => {
|
|
22
|
+
throw a = void 0, o;
|
|
23
|
+
}), a)), S = (o = {}) => {
|
|
24
|
+
const { apiOptions: e } = o;
|
|
25
|
+
if (!e || !e.accessToken) {
|
|
33
26
|
console.error(
|
|
34
27
|
"You need to provide an access token to interact with Storyblok API. Read https://www.storyblok.com/docs/api/content-delivery#topics/authentication"
|
|
35
28
|
);
|
|
36
29
|
return;
|
|
37
30
|
}
|
|
38
|
-
return { storyblokApi: new
|
|
39
|
-
}, m = (
|
|
40
|
-
if (typeof
|
|
31
|
+
return { storyblokApi: new g(e) };
|
|
32
|
+
}, m = (o) => {
|
|
33
|
+
if (typeof o != "object" || typeof o._editable != "string")
|
|
41
34
|
return {};
|
|
42
35
|
try {
|
|
43
|
-
const
|
|
44
|
-
|
|
36
|
+
const e = JSON.parse(
|
|
37
|
+
o._editable.replace(/^<!--#storyblok#/, "").replace(/-->$/, "")
|
|
45
38
|
);
|
|
46
|
-
return
|
|
47
|
-
"data-blok-c": JSON.stringify(
|
|
48
|
-
"data-blok-uid": `${
|
|
39
|
+
return e ? {
|
|
40
|
+
"data-blok-c": JSON.stringify(e),
|
|
41
|
+
"data-blok-uid": `${e.id}-${e.uid}`
|
|
49
42
|
} : {};
|
|
50
43
|
} catch {
|
|
51
44
|
return {};
|
|
52
45
|
}
|
|
53
46
|
};
|
|
54
|
-
|
|
55
|
-
const
|
|
56
|
-
|
|
57
|
-
|
|
47
|
+
function k(o) {
|
|
48
|
+
const { language: e, resolveRelations: r, ...l } = o;
|
|
49
|
+
return e && console.warn(
|
|
50
|
+
"[Storyblok] The `language` bridge option is no longer supported by the bundled bridge. Language context is now passed automatically by the Visual Editor via the `_storyblok_lang` URL parameter."
|
|
51
|
+
), {
|
|
52
|
+
...l,
|
|
53
|
+
...r !== void 0 && {
|
|
54
|
+
resolveRelations: Array.isArray(r) ? r : [r]
|
|
55
|
+
}
|
|
56
|
+
};
|
|
57
|
+
}
|
|
58
|
+
const v = (o, e, r = {}) => {
|
|
59
|
+
var i;
|
|
60
|
+
const n = !(typeof window > "u") && typeof window.storyblokRegisterEvent < "u", d = new URL((i = window.location) == null ? void 0 : i.href).searchParams.get(
|
|
58
61
|
"_storyblok"
|
|
59
|
-
),
|
|
60
|
-
if (!(!
|
|
61
|
-
if (!
|
|
62
|
+
), c = d !== null && +d === o;
|
|
63
|
+
if (!(!n || !c)) {
|
|
64
|
+
if (!o) {
|
|
62
65
|
console.warn("Story ID is not defined. Please provide a valid ID.");
|
|
63
66
|
return;
|
|
64
67
|
}
|
|
65
68
|
window.storyblokRegisterEvent(() => {
|
|
66
|
-
new window.StoryblokBridge(
|
|
67
|
-
|
|
68
|
-
|
|
69
|
+
new window.StoryblokBridge(
|
|
70
|
+
k(r)
|
|
71
|
+
).on(["input", "published", "change"], (t) => {
|
|
72
|
+
var s;
|
|
73
|
+
t && (t.action === "input" && ((s = t.story) == null ? void 0 : s.id) === o ? e(t.story) : (t.action === "change" || t.action === "published") && t.storyId === o && window.location.reload());
|
|
69
74
|
});
|
|
70
75
|
});
|
|
71
76
|
}
|
|
72
|
-
},
|
|
73
|
-
var
|
|
77
|
+
}, R = (o = {}) => {
|
|
78
|
+
var s, b;
|
|
74
79
|
const {
|
|
75
|
-
bridge:
|
|
76
|
-
accessToken:
|
|
77
|
-
use:
|
|
78
|
-
apiOptions:
|
|
79
|
-
bridgeUrl:
|
|
80
|
-
} =
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
80
|
+
bridge: e,
|
|
81
|
+
accessToken: r,
|
|
82
|
+
use: l = [],
|
|
83
|
+
apiOptions: n = {},
|
|
84
|
+
bridgeUrl: d
|
|
85
|
+
} = o;
|
|
86
|
+
d && console.warn(
|
|
87
|
+
"[Storyblok] The `bridgeUrl` option is deprecated and will be removed in a future major version. The Storyblok bridge is now bundled and is no longer loaded from a CDN URL."
|
|
88
|
+
), n.accessToken = n.accessToken || r;
|
|
89
|
+
const c = { bridge: e, apiOptions: n };
|
|
90
|
+
let i = {};
|
|
91
|
+
l.forEach((w) => {
|
|
92
|
+
i = { ...i, ...w(c) };
|
|
93
|
+
});
|
|
94
|
+
const t = !(typeof window > "u") && ((b = (s = window.location) == null ? void 0 : s.search) == null ? void 0 : b.includes("_storyblok_tk"));
|
|
95
|
+
return e !== !1 && t && f(), i;
|
|
96
|
+
}, B = () => f();
|
|
90
97
|
export {
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
+
_ as StoryblokClient,
|
|
99
|
+
S as apiPlugin,
|
|
100
|
+
P as buildStoryblokImage,
|
|
101
|
+
B as loadStoryblokBridge,
|
|
102
|
+
v as registerStoryblokBridge,
|
|
103
|
+
x as renderRichText,
|
|
104
|
+
A as splitTableRows,
|
|
98
105
|
m as storyblokEditable,
|
|
99
|
-
|
|
100
|
-
|
|
106
|
+
R as storyblokInit,
|
|
107
|
+
v as useStoryblokBridge
|
|
101
108
|
};
|
package/dist/types/index.d.ts
CHANGED
|
@@ -37,7 +37,7 @@ export interface StoryblokBridgeConfigV2 {
|
|
|
37
37
|
preventClicks?: boolean;
|
|
38
38
|
language?: string;
|
|
39
39
|
resolveLinks?: 'url' | 'story' | '0' | '1' | 'link';
|
|
40
|
-
fallbackLang?:
|
|
40
|
+
fallbackLang?: string;
|
|
41
41
|
}
|
|
42
42
|
export interface StoryblokBridgeV2 {
|
|
43
43
|
pingEditor: (event: any) => void;
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@storyblok/js",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "6.
|
|
4
|
+
"version": "6.3.0",
|
|
5
5
|
"private": false,
|
|
6
6
|
"description": "SDK to integrate Storyblok into your project using JavaScript.",
|
|
7
7
|
"license": "MIT",
|
|
@@ -29,6 +29,7 @@
|
|
|
29
29
|
"dist"
|
|
30
30
|
],
|
|
31
31
|
"dependencies": {
|
|
32
|
+
"@storyblok/preview-bridge": "^2.1.6",
|
|
32
33
|
"@storyblok/richtext": "5.2.0",
|
|
33
34
|
"storyblok-js-client": "7.7.1"
|
|
34
35
|
},
|