@websline/cms-view-utils 1.0.3 → 1.0.5

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@websline/cms-view-utils",
3
- "version": "1.0.3",
3
+ "version": "1.0.5",
4
4
  "type": "module",
5
5
  "files": [
6
6
  "src",
@@ -13,13 +13,13 @@
13
13
  children,
14
14
  color = "#000fff",
15
15
  isValidBlock = true,
16
+ locale = "de",
16
17
  position,
17
18
  textColor = "#F1F1F2",
18
19
  } = $props();
19
20
 
20
21
  let calcBarPosition = $derived.by(() => {
21
22
  if (typeof barPosition === "string") return barPosition;
22
-
23
23
  if (position === 0) return "inside";
24
24
 
25
25
  return "outside";
@@ -86,6 +86,20 @@
86
86
 
87
87
  let toolbarVisible = $derived(isHovered || isActive);
88
88
 
89
+ let activeTooltip = $state(null);
90
+ let tooltipLeaveTimer;
91
+
92
+ const showTooltip = (name) => {
93
+ clearTimeout(tooltipLeaveTimer);
94
+ activeTooltip = name;
95
+ };
96
+
97
+ const hideTooltip = () => {
98
+ tooltipLeaveTimer = setTimeout(() => {
99
+ activeTooltip = null;
100
+ }, 200);
101
+ };
102
+
89
103
  const handleLeave = () => {
90
104
  handleEnterDebounced.cancel();
91
105
  isHovered = false;
@@ -125,6 +139,35 @@
125
139
  : "before:top-0 before:-left-4 before:shadow-[6px_-6px_0_0_var(--block-color)] " +
126
140
  "after:top-0 after:-right-4 after:shadow-[-6px_-6px_0_0_var(--block-color)]",
127
141
  );
142
+
143
+ let tooltipClasses = $derived(
144
+ `tooltip absolute ${position === 0 ? "-top-9" : "-top-7.5"} bg-[var(--block-color)] leading-none text-xs p-1.5 rounded-tl rounded-tr left-0 whitespace-nowrap transition-opacity duration-150`,
145
+ );
146
+
147
+ const labels = {
148
+ de: {
149
+ add: "Hinzufügen",
150
+ position: "Anordnen",
151
+ delete: "Löschen",
152
+ edit: "Bearbeiten",
153
+ addAria: "Block hinzufügen",
154
+ positionAria: "Block anordnen",
155
+ deleteAria: "Block löschen",
156
+ editAria: "Block bearbeiten",
157
+ },
158
+ en: {
159
+ add: "Add",
160
+ position: "Arrange",
161
+ delete: "Delete",
162
+ edit: "Edit",
163
+ addAria: "Add block",
164
+ positionAria: "Arrange block",
165
+ deleteAria: "Delete block",
166
+ editAria: "Edit block",
167
+ },
168
+ };
169
+
170
+ let t = $derived(labels[locale] ?? labels.de);
128
171
  </script>
129
172
 
130
173
  <div
@@ -151,8 +194,10 @@
151
194
  class:opacity-100={toolbarVisible}
152
195
  class:opacity-0={!toolbarVisible}>
153
196
  <button
154
- aria-label="add block"
155
- class="cursor-pointer"
197
+ aria-label={t.addAria}
198
+ class="relative cursor-pointer"
199
+ onmouseenter={() => showTooltip("add")}
200
+ onmouseleave={hideTooltip}
156
201
  onclick={(event) => handleClick(event, CMS_ACTIONS.add)}>
157
202
  <svg
158
203
  width="24"
@@ -167,6 +212,13 @@
167
212
  stroke-linecap="round"
168
213
  stroke-linejoin="round" />
169
214
  </svg>
215
+ <div
216
+ class={tooltipClasses}
217
+ class:opacity-0={activeTooltip !== "add"}
218
+ class:opacity-100={activeTooltip === "add"}
219
+ class:pointer-events-none={activeTooltip !== "add"}>
220
+ {t.add}
221
+ </div>
170
222
  </button>
171
223
 
172
224
  <!-- {#if blockVisible}
@@ -244,8 +296,10 @@
244
296
  </button> -->
245
297
 
246
298
  <button
247
- aria-label="position block"
248
- class="cursor-pointer"
299
+ aria-label={t.positionAria}
300
+ class="relative cursor-pointer"
301
+ onmouseenter={() => showTooltip("position")}
302
+ onmouseleave={hideTooltip}
249
303
  onclick={(event) => handleClick(event, CMS_ACTIONS.position)}>
250
304
  <svg
251
305
  width="24"
@@ -260,11 +314,20 @@
260
314
  stroke-linecap="round"
261
315
  stroke-linejoin="round" />
262
316
  </svg>
317
+ <div
318
+ class={tooltipClasses}
319
+ class:opacity-0={activeTooltip !== "position"}
320
+ class:opacity-100={activeTooltip === "position"}
321
+ class:pointer-events-none={activeTooltip !== "position"}>
322
+ {t.position}
323
+ </div>
263
324
  </button>
264
325
 
265
326
  <button
266
- aria-label="delete block"
267
- class="cursor-pointer"
327
+ aria-label={t.deleteAria}
328
+ class="relative cursor-pointer"
329
+ onmouseenter={() => showTooltip("delete")}
330
+ onmouseleave={hideTooltip}
268
331
  onclick={(event) => handleClick(event, CMS_ACTIONS.delete)}>
269
332
  <svg
270
333
  width="24"
@@ -279,11 +342,20 @@
279
342
  stroke-linecap="round"
280
343
  stroke-linejoin="round" />
281
344
  </svg>
345
+ <div
346
+ class={tooltipClasses}
347
+ class:opacity-0={activeTooltip !== "delete"}
348
+ class:opacity-100={activeTooltip === "delete"}
349
+ class:pointer-events-none={activeTooltip !== "delete"}>
350
+ {t.delete}
351
+ </div>
282
352
  </button>
283
353
 
284
354
  <button
285
- aria-label="edit block"
286
- class="cursor-pointer"
355
+ aria-label={t.editAria}
356
+ class="relative cursor-pointer"
357
+ onmouseenter={() => showTooltip("edit")}
358
+ onmouseleave={hideTooltip}
287
359
  onclick={(event) => handleClick(event, CMS_ACTIONS.edit)}>
288
360
  <svg
289
361
  width="24"
@@ -298,6 +370,13 @@
298
370
  stroke-linecap="round"
299
371
  stroke-linejoin="round" />
300
372
  </svg>
373
+ <div
374
+ class={tooltipClasses}
375
+ class:opacity-0={activeTooltip !== "edit"}
376
+ class:opacity-100={activeTooltip === "edit"}
377
+ class:pointer-events-none={activeTooltip !== "edit"}>
378
+ {t.edit}
379
+ </div>
301
380
  </button>
302
381
  </div>
303
382
 
@@ -315,3 +394,14 @@
315
394
  {/if}
316
395
  </div>
317
396
  </div>
397
+
398
+ <style>
399
+ .tooltip::after {
400
+ content: "";
401
+ bottom: -8px;
402
+ height: 8px;
403
+ left: 0;
404
+ position: absolute;
405
+ right: 0;
406
+ }
407
+ </style>
@@ -43,6 +43,7 @@ const fetchPage = async (context) => {
43
43
 
44
44
  if (isCMSPreviewRoute) {
45
45
  context.locals._preview = true;
46
+ context.locals._cmsLocale = url.searchParams.get("cmsLocale");
46
47
  }
47
48
  if (isCMSEditRoute) {
48
49
  context.locals._edit = true;