@storyblok/js 6.3.0 → 6.3.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 +16 -8
- package/dist/index.cjs +180 -0
- package/dist/index.d.cts +82 -0
- package/dist/index.d.mts +82 -0
- package/dist/index.mjs +127 -0
- package/package.json +45 -39
- package/dist/api.d.ts +0 -3
- package/dist/bridge.d.ts +0 -1
- package/dist/editable.d.ts +0 -10
- package/dist/index-CtMAhUF-.js +0 -576
- package/dist/index.d.ts +0 -17
- package/dist/storyblok-js.js +0 -216
- package/dist/storyblok-js.mjs +0 -108
- package/dist/types/index.d.ts +0 -58
package/dist/index-CtMAhUF-.js
DELETED
|
@@ -1,576 +0,0 @@
|
|
|
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
DELETED
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
import { ISbStoryData, SbInitResult, SbSDKOptions, StoryblokBridgeConfigV2, StoryblokComponentType } from './types';
|
|
2
|
-
export interface StoryblokBridgeEvent {
|
|
3
|
-
action: string;
|
|
4
|
-
storyId: number;
|
|
5
|
-
story: ISbStoryData;
|
|
6
|
-
}
|
|
7
|
-
export declare const useStoryblokBridge: <T extends StoryblokComponentType<string> = any>(id: number, cb: (newStory: ISbStoryData<T>) => void, options?: StoryblokBridgeConfigV2) => void;
|
|
8
|
-
export declare const storyblokInit: (pluginOptions?: SbSDKOptions) => SbInitResult;
|
|
9
|
-
export declare const loadStoryblokBridge: () => Promise<void>;
|
|
10
|
-
export { useStoryblokBridge as registerStoryblokBridge };
|
|
11
|
-
export { default as apiPlugin } from './api';
|
|
12
|
-
export { default as storyblokEditable } from './editable';
|
|
13
|
-
export * from './types';
|
|
14
|
-
export type { BridgeParams } from '@storyblok/preview-bridge';
|
|
15
|
-
export { buildStoryblokImage, renderRichText, splitTableRows } from '@storyblok/richtext';
|
|
16
|
-
export type { SbRichTextDoc, SbRichTextImageOptions, SbRichTextMark, SbRichTextNode, SbRichTextProps, SbRichTextRenderContext, SbRichTextRendererMap, } from '@storyblok/richtext';
|
|
17
|
-
export { default as StoryblokClient } from 'storyblok-js-client';
|