@storyblok/vue 11.2.0 → 11.2.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index-CtMAhUF--JC8YsZOI.js +576 -0
- package/dist/storyblok-vue.js +211 -2
- package/dist/storyblok-vue.mjs +130 -123
- package/package.json +2 -2
|
@@ -0,0 +1,576 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* name: @storyblok/vue
|
|
3
|
+
* (c) 2026
|
|
4
|
+
* description: SDK to integrate Storyblok into your project using Vue.
|
|
5
|
+
* author: Storyblok
|
|
6
|
+
*/
|
|
7
|
+
const M = (n, e) => {
|
|
8
|
+
for (; n && n.nodeType === 1; ) {
|
|
9
|
+
if (n.hasAttribute(e)) return n;
|
|
10
|
+
n = n.parentNode;
|
|
11
|
+
}
|
|
12
|
+
return null;
|
|
13
|
+
}, y = (n) => {
|
|
14
|
+
const e = M(n, "data-blok-c");
|
|
15
|
+
if (!e) return null;
|
|
16
|
+
const t = e.getAttribute("data-blok-c");
|
|
17
|
+
return JSON.parse(t);
|
|
18
|
+
}, A = (n, e) => n.contains(e), l = (n) => document.querySelector(`[data-blok-uid="${n}"]`), g = (n) => {
|
|
19
|
+
const e = n.getBoundingClientRect();
|
|
20
|
+
return e.top < 0 && e.top + e.height >= 0 || e.top >= 0 && e.top <= (window.innerHeight || document.documentElement.clientHeight);
|
|
21
|
+
}, I = (n) => {
|
|
22
|
+
let e = {};
|
|
23
|
+
try {
|
|
24
|
+
const t = n.replace(/\\/g, "");
|
|
25
|
+
e = JSON.parse(t);
|
|
26
|
+
} catch {
|
|
27
|
+
console.error("Error parsing json", n);
|
|
28
|
+
}
|
|
29
|
+
return e;
|
|
30
|
+
}, N = (n) => {
|
|
31
|
+
const e = [], t = () => NodeFilter.FILTER_ACCEPT, o = document.createNodeIterator(n, NodeFilter.SHOW_COMMENT, t, !1);
|
|
32
|
+
let i = {};
|
|
33
|
+
for (; i = o.nextNode(); ) if (i.nodeValue.indexOf("#storyblok#") > -1) {
|
|
34
|
+
const r = i.nodeValue.replace("#storyblok#", ""), u = i.nextElementSibling || i.nextSibling, d = I(r);
|
|
35
|
+
d && e.push({ options: d, el: u });
|
|
36
|
+
}
|
|
37
|
+
return e;
|
|
38
|
+
}, E = (n) => {
|
|
39
|
+
let e = "";
|
|
40
|
+
return location.search.substr(1).split("&").forEach((t) => {
|
|
41
|
+
const o = t.split("=");
|
|
42
|
+
o[0] === n && (e = decodeURIComponent(o[1]));
|
|
43
|
+
}), e;
|
|
44
|
+
}, x = (n, e, t) => typeof n != "string" ? "" : n.toString().replace(/([A-Z])/g, " $1").trim().toLowerCase().replace(/[_-]/g, " ").replace(/(?:^|\s)\S/g, function(o, i) {
|
|
45
|
+
return o.toUpperCase();
|
|
46
|
+
}), f = (n) => n && n.display_name ? n.display_name : x(n.name), k = (n) => {
|
|
47
|
+
const e = document.createElementNS("http://www.w3.org/2000/svg", "svg");
|
|
48
|
+
e.setAttribute("viewBox", n.viewBox), e.setAttribute("class", n.svgClass);
|
|
49
|
+
const t = document.createElementNS(e.namespaceURI, "path");
|
|
50
|
+
return t.setAttribute("d", n.path), t.setAttribute("fill", n.pathFill), t.setAttribute("transform", n.pathTransform ? n.pathTransform : "translate(0 0)"), e.appendChild(t), e;
|
|
51
|
+
}, O = (n) => n, C = O, 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
|
+
`, 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" };
|
|
261
|
+
class w {
|
|
262
|
+
constructor(e) {
|
|
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 t = { customParent: null, resolveRelations: null, resolveLinks: null, preventClicks: !1, initOnlyOnce: !0, fallbackLang: null };
|
|
265
|
+
this.config = { ...t, ...e }, this.init();
|
|
266
|
+
}
|
|
267
|
+
get isInIframe() {
|
|
268
|
+
return window.top !== window.self;
|
|
269
|
+
}
|
|
270
|
+
get csProtocol() {
|
|
271
|
+
let e = location.protocol.replace(":", "");
|
|
272
|
+
return e !== "http" && e !== "https" && (e = "https"), e;
|
|
273
|
+
}
|
|
274
|
+
get targetOrigin() {
|
|
275
|
+
return this.config.customParent ? this.config.customParent : E("_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(`.${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);
|
|
289
|
+
}
|
|
290
|
+
keyPress(e, t) {
|
|
291
|
+
(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" }));
|
|
292
|
+
}
|
|
293
|
+
sendDataToEditor(e) {
|
|
294
|
+
window.parent.postMessage(e, this.targetOrigin);
|
|
295
|
+
}
|
|
296
|
+
buildBridgeStyles() {
|
|
297
|
+
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());
|
|
298
|
+
}
|
|
299
|
+
createBridgeStylesheet() {
|
|
300
|
+
const e = document.createElement("style");
|
|
301
|
+
e.setAttribute("type", "text/css"), e.id = s.STYLESHEET, "textContent" in e ? e.textContent = v : e.styleSheet.cssText = v, document.getElementsByTagName("head")[0].appendChild(e);
|
|
302
|
+
}
|
|
303
|
+
createHinter() {
|
|
304
|
+
this.hinter = document.createElement("div"), this.hinter.className = s.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", s.OVERLAY), this.overlay.setAttribute("id", s.OVERLAY), this.hideElement(this.overlay), document.body.appendChild(this.overlay);
|
|
311
|
+
}
|
|
312
|
+
calculateElementPosition(e, t) {
|
|
313
|
+
if (!t) {
|
|
314
|
+
this.hideElement(e);
|
|
315
|
+
return;
|
|
316
|
+
}
|
|
317
|
+
const o = l(t);
|
|
318
|
+
if (o) {
|
|
319
|
+
const { left: i, top: r } = this.getElementOffset(o);
|
|
320
|
+
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 = `${o.offsetWidth}px`, e.style.height = `${o.offsetHeight}px`, e.style.minHeight = "5px";
|
|
321
|
+
} else this.hideElement(e);
|
|
322
|
+
}
|
|
323
|
+
getElementOffset(e) {
|
|
324
|
+
const t = e.getBoundingClientRect(), o = window.pageXOffset || document.documentElement.scrollLeft, i = window.pageYOffset || document.documentElement.scrollTop;
|
|
325
|
+
return { top: t.top + i, left: t.left + o };
|
|
326
|
+
}
|
|
327
|
+
resetAllEvents() {
|
|
328
|
+
for (const e in this.events) this.events[e] = [];
|
|
329
|
+
}
|
|
330
|
+
addMessageListener() {
|
|
331
|
+
window.addEventListener && addEventListener("message", this.receiveMessageFromApp.bind(this), !1);
|
|
332
|
+
}
|
|
333
|
+
receiveMessageFromApp(e) {
|
|
334
|
+
e && e.data && e.data.action && this.emit(e.data.action, e.data);
|
|
335
|
+
}
|
|
336
|
+
emit(e, ...t) {
|
|
337
|
+
const o = this.events[e];
|
|
338
|
+
if (!(!e || !o || !o.length)) for (let i = 0; i < o.length; i++) o[i].apply(this, t);
|
|
339
|
+
}
|
|
340
|
+
outlineOnMoveHandler() {
|
|
341
|
+
document.body.classList.add(s.OUTLINE);
|
|
342
|
+
const e = () => {
|
|
343
|
+
document.body.classList.remove(s.OUTLINE), this.hinter && (this.hinter.style.opacity = 0);
|
|
344
|
+
};
|
|
345
|
+
this.outlineOnMoveInterval && clearTimeout(this.outlineOnMoveInterval), this.outlineOnMoveInterval = setTimeout(e, 800);
|
|
346
|
+
}
|
|
347
|
+
outlineOnMove() {
|
|
348
|
+
document.addEventListener("mousemove", this.outlineOnMoveHandler.bind(this), !1);
|
|
349
|
+
}
|
|
350
|
+
on(e, t) {
|
|
351
|
+
if (e.constructor === Array) {
|
|
352
|
+
for (const o of e) this.subscribeEvent(o, t);
|
|
353
|
+
return;
|
|
354
|
+
}
|
|
355
|
+
this.subscribeEvent(e, t);
|
|
356
|
+
}
|
|
357
|
+
subscribeEvent(e, t) {
|
|
358
|
+
e === "input" && (this.actionsEnabled = !0), this.events[e].indexOf(t) === -1 && this.events[e].push(t);
|
|
359
|
+
}
|
|
360
|
+
pingEditor(e) {
|
|
361
|
+
this.isInIframe ? this.sendDataToEditor({ action: "ping" }) : (this.inEditor = !1, e(this)), this.on("pingBack", this.handlePingBack(e));
|
|
362
|
+
}
|
|
363
|
+
handlePingBack(e) {
|
|
364
|
+
return () => {
|
|
365
|
+
this.inEditor = !0, e(this);
|
|
366
|
+
};
|
|
367
|
+
}
|
|
368
|
+
handleEditedBlok(e) {
|
|
369
|
+
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);
|
|
370
|
+
}
|
|
371
|
+
handleAddMoveBlok(e) {
|
|
372
|
+
const t = l(`${this.storyId}-${e.blockId}`);
|
|
373
|
+
t && this.handleOpenBlok(t);
|
|
374
|
+
}
|
|
375
|
+
handleDeselectBlock() {
|
|
376
|
+
document.querySelectorAll("[data-blok-focused]").forEach((e) => e.removeAttribute("data-blok-focused")), this.hideElement(this.overlay);
|
|
377
|
+
}
|
|
378
|
+
handleDuplicatedBlok(e) {
|
|
379
|
+
this.handleDeselectBlock(), setTimeout(() => {
|
|
380
|
+
const t = l(`${this.storyId}-${e.blockId}`);
|
|
381
|
+
this.handleOpenBlok(t);
|
|
382
|
+
}, 500);
|
|
383
|
+
}
|
|
384
|
+
handleWindowClick(e) {
|
|
385
|
+
this.config.preventClicks && (e.preventDefault(), e.stopPropagation()), this.handleOpenBlok(e.target, e);
|
|
386
|
+
}
|
|
387
|
+
handleOpenBlok(e, t) {
|
|
388
|
+
const o = y(e);
|
|
389
|
+
if (o) {
|
|
390
|
+
t && o.uid !== this.currentUid && (t.preventDefault(), t.stopPropagation()), this.currentUid = o.uid, this.storyId = o.id, this.openBlok(o);
|
|
391
|
+
return;
|
|
392
|
+
}
|
|
393
|
+
t && this.toggleFocusElement(e, !0);
|
|
394
|
+
}
|
|
395
|
+
enterEditmode(e) {
|
|
396
|
+
const t = N(document.body);
|
|
397
|
+
e && e.appVersion && (this.appVersion = e.appVersion), e && e.componentNames && (this.componentNames = e.componentNames);
|
|
398
|
+
for (let o = 0; o < t.length; o++) {
|
|
399
|
+
const i = t[o].el, r = t[o].options;
|
|
400
|
+
!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"));
|
|
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), e && e.blockId && this.config.setActiveBlock) {
|
|
403
|
+
const o = l(`${e.storyId}-${e.blockId}`);
|
|
404
|
+
this.handleOpenBlok(o);
|
|
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(e) {
|
|
411
|
+
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);
|
|
412
|
+
for (let t = 0; t < e.componentIds.length; t++) {
|
|
413
|
+
const o = `${e.storyId}-${e.componentIds[t]}`, i = l(o);
|
|
414
|
+
if (i) {
|
|
415
|
+
const r = document.createElement("div");
|
|
416
|
+
r.setAttribute("class", s.HIGHLIGHTER), this.highlighter.appendChild(r), this.calculateElementPosition(r, o), e.componentId === e.componentIds[t] && !g(i) && typeof i.scrollIntoView < "u" && i.scrollIntoView();
|
|
417
|
+
}
|
|
418
|
+
}
|
|
419
|
+
}
|
|
420
|
+
hoverComponent(e) {
|
|
421
|
+
this.calculateElementPosition(this.hinter, `${e.storyId}-${e.componentId}`), this.hinter.style.opacity = 1, this.hinter.style.display = "block";
|
|
422
|
+
}
|
|
423
|
+
toggleFocusElement(e, t = !1) {
|
|
424
|
+
if (!A(this.overlay, e)) {
|
|
425
|
+
if (this.handleDeselectBlock(), !t && this.storyId === E("_storyblok")) {
|
|
426
|
+
e.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(e) {
|
|
433
|
+
if (!this.currentUid) {
|
|
434
|
+
this.hideElement(e);
|
|
435
|
+
return;
|
|
436
|
+
}
|
|
437
|
+
this.showElement(e), this.calculateElementPosition(e, `${this.storyId}-${this.currentUid}`);
|
|
438
|
+
}
|
|
439
|
+
handleBlokActions(e) {
|
|
440
|
+
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);
|
|
441
|
+
}
|
|
442
|
+
hideElement(e) {
|
|
443
|
+
e.style.display = "none";
|
|
444
|
+
}
|
|
445
|
+
showElement(e) {
|
|
446
|
+
e.style.display = "block";
|
|
447
|
+
}
|
|
448
|
+
toggleElement(e) {
|
|
449
|
+
if (e.style.display === "block") {
|
|
450
|
+
this.hideElement(e);
|
|
451
|
+
return;
|
|
452
|
+
}
|
|
453
|
+
this.showElement(e);
|
|
454
|
+
}
|
|
455
|
+
enterComponent(e) {
|
|
456
|
+
const t = l(`${e.storyId}-${e.componentId}`), o = y(t);
|
|
457
|
+
o && (this.hinter.style.opacity = 0, this.hinter.style.display = "none", this.currentUid = o.uid, this.storyId = o.id, this.scrollIntoView(t), this.handleEditedBlok(e));
|
|
458
|
+
}
|
|
459
|
+
scrollIntoView(e) {
|
|
460
|
+
e && !g(e) && typeof e.scrollIntoView < "u" && setTimeout(() => {
|
|
461
|
+
e.scrollIntoView({ behavior: "smooth", block: "start" });
|
|
462
|
+
}, 100);
|
|
463
|
+
}
|
|
464
|
+
openBlok(e) {
|
|
465
|
+
this.sendDataToEditor({ action: "edit", dataC: e, 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", s.COMPONENT_BASE), this.componentBase.setAttribute("id", s.COMPONENT_BASE), this.overlay.append(this.componentBase);
|
|
472
|
+
}
|
|
473
|
+
createComponentLabel() {
|
|
474
|
+
this.componentLabel = document.createElement("span"), this.componentLabel.setAttribute("class", `${s.COMPONENT_BASE}-label`), this.componentBase.prepend(this.componentLabel);
|
|
475
|
+
}
|
|
476
|
+
createComponentButtonLabel() {
|
|
477
|
+
const e = document.createElement("span");
|
|
478
|
+
e.setAttribute("class", `${s.COMPONENT_BASE}-label`), this.breadcrumbsButtonMenu.appendChild(e);
|
|
479
|
+
}
|
|
480
|
+
updateComponentLabel(e) {
|
|
481
|
+
document.querySelectorAll(`.${s.COMPONENT_BASE}-label`).forEach((t) => t.innerText = this.componentNames[e.name] || f(e));
|
|
482
|
+
}
|
|
483
|
+
updateComponentBase(e) {
|
|
484
|
+
this.hideElement(this.actionsMenu), this.hideElement(this.breadcrumbsMenu), this.overlay.classList.add(`${s.OVERLAY}--clicked`), setTimeout(() => {
|
|
485
|
+
this.overlay.classList.remove(`${s.OVERLAY}--clicked`);
|
|
486
|
+
}, 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);
|
|
487
|
+
const t = l(`${this.storyId}-${e.uid}`);
|
|
488
|
+
t && this.toggleFocusElement(t);
|
|
489
|
+
}
|
|
490
|
+
createBreadcrumbsMenuButton() {
|
|
491
|
+
this.breadcrumbsButtonMenu = document.createElement("button"), this.breadcrumbsButtonMenu.setAttribute("class", `${s.COMPONENT_BASE}-btn ${s.COMPONENT_BASE}-btn-parent`), this.breadcrumbsButtonMenu.prepend(k({ 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", () => {
|
|
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", s.BREADCRUMBS_MENU), this.breadcrumbsMenu.setAttribute("id", s.BREADCRUMBS_MENU), this.componentBase.append(this.breadcrumbsMenu);
|
|
497
|
+
}
|
|
498
|
+
updateBreadcrumbsMenu(e) {
|
|
499
|
+
this.breadcrumbsMenu.innerHTML = "";
|
|
500
|
+
const t = [];
|
|
501
|
+
for (let o = 0; o < e.length; o++) {
|
|
502
|
+
t[o] = document.createElement("button"), t[o].innerHTML = f({ display_name: this.componentNames[e[o].component], name: e[o].component });
|
|
503
|
+
const i = e[o];
|
|
504
|
+
t[o].addEventListener("click", (r) => {
|
|
505
|
+
r.stopPropagation(), this.currentUid = i._uid, this.openBlok({ id: this.storyId, uid: i._uid, name: i.component });
|
|
506
|
+
}), t[o].classList.add(`${s.BREADCRUMBS_MENU}__menu-item`), e[o]._uid === this.currentUid && (t[o].classList.add(`${s.BREADCRUMBS_MENU}__menu-item--selected`), t[o].setAttribute("disabled", !0)), this.breadcrumbsMenu.appendChild(t[o]), this.breadcrumbsButtonMenu.style.display = "flex";
|
|
507
|
+
}
|
|
508
|
+
}
|
|
509
|
+
createActionsMenuButton() {
|
|
510
|
+
this.actionsMenuButton = document.createElement("button"), this.actionsMenuButton.setAttribute("class", `${s.COMPONENT_BASE}-btn ${s.COMPONENT_BASE}-btn-action`), this.actionsMenuButton.prepend(k({ 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", () => {
|
|
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: `${s.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", s.ACTIONS_MENU), this.actionsMenu.setAttribute("id", s.ACTIONS_MENU), this.componentBase.append(this.actionsMenu);
|
|
519
|
+
}
|
|
520
|
+
updateActionsMenu() {
|
|
521
|
+
this.actionsMenu.innerHTML = "";
|
|
522
|
+
const e = `${s.ACTIONS_MENU}__menu-item`, t = "button", o = "click";
|
|
523
|
+
this.actionsMenuItems.sort((i, r) => i.order > r.order ? 1 : r.order > i.order ? -1 : 0).forEach((i) => {
|
|
524
|
+
if (i.separator && i.show()) {
|
|
525
|
+
this.actionsMenu.appendChild(document.createElement("hr"));
|
|
526
|
+
return;
|
|
527
|
+
}
|
|
528
|
+
const r = document.createElement(i.element ? i.element : t);
|
|
529
|
+
r.classList.add(e), i.className && r.classList.add(i.className), r.innerHTML = i.innerHTML, i.eventFunction && r.addEventListener(i.event ? i.event : o, i.eventFunction()), i.show() && this.actionsMenu.appendChild(r);
|
|
530
|
+
}), this.actionsMenuButton.style.display = "flex";
|
|
531
|
+
}
|
|
532
|
+
}
|
|
533
|
+
var S = Object.defineProperty, T = (n, e, t) => e in n ? S(n, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : n[e] = t, m = (n, e, t) => T(n, typeof e != "symbol" ? e + "" : e, t);
|
|
534
|
+
let j = class {
|
|
535
|
+
constructor(n) {
|
|
536
|
+
m(this, "isInEditor"), m(this, "enterEditmode"), m(this, "pingEditor"), m(this, "on");
|
|
537
|
+
const e = new w(n);
|
|
538
|
+
this.isInEditor = () => e.isInEditor(), this.enterEditmode = (t) => {
|
|
539
|
+
e.enterEditmode(t);
|
|
540
|
+
}, this.pingEditor = (t) => {
|
|
541
|
+
e.pingEditor(t);
|
|
542
|
+
}, this.on = (t, o) => {
|
|
543
|
+
e.on(t, o);
|
|
544
|
+
};
|
|
545
|
+
}
|
|
546
|
+
};
|
|
547
|
+
const h = (n) => ({ tag: "success", value: n }), c = (n) => ({ tag: "failure", error: n, path: [] }), B = (n, e) => ({ tag: "failure", error: n.error, path: [e, ...n.path] }), L = (n) => typeof n > "u", $ = (n) => typeof n == "string", P = (n) => typeof n == "object" && n !== null, b = Symbol("propertyAbsent"), _ = Symbol("omitProperty"), H = "Not an object", U = (n) => B(c("Property is missing"), { tag: "object", key: n }), D = (n) => {
|
|
548
|
+
const e = Object.entries(n);
|
|
549
|
+
return (t) => {
|
|
550
|
+
if (!P(t)) return c(H);
|
|
551
|
+
const o = {};
|
|
552
|
+
for (let i = 0; i < e.length; i++) {
|
|
553
|
+
const [r, u] = e[i], d = t[r];
|
|
554
|
+
if (d === void 0 && !t.hasOwnProperty(r)) {
|
|
555
|
+
const a = u(b);
|
|
556
|
+
if (a.tag === "failure" || a.value === b) return U(r);
|
|
557
|
+
a.value !== _ && (o[r] = a.value);
|
|
558
|
+
} else {
|
|
559
|
+
const a = u(d);
|
|
560
|
+
if (a.tag === "failure") return B(a, { tag: "object", key: r });
|
|
561
|
+
o[r] = a.value;
|
|
562
|
+
}
|
|
563
|
+
}
|
|
564
|
+
return h(o);
|
|
565
|
+
};
|
|
566
|
+
}, F = (n) => L(n) ? h(n) : c("Not undefined"), p = (n) => $(n) ? h(n) : c("Not a string"), R = (...n) => (e) => {
|
|
567
|
+
for (const t of n) {
|
|
568
|
+
const o = t(e);
|
|
569
|
+
if (o.tag === "success") return h(o.value);
|
|
570
|
+
}
|
|
571
|
+
return c("No parser in the union matched");
|
|
572
|
+
}, V = (n) => R(z, F, n), z = (n) => n === b ? h(_) : c("not optional");
|
|
573
|
+
D({ name: p, space: V(p), uid: p, id: p });
|
|
574
|
+
export {
|
|
575
|
+
j as default
|
|
576
|
+
};
|