@websline/cms-view-utils 1.0.3 → 1.0.4

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.4",
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,33 @@
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 = `tooltip absolute -top-9 bg-[var(--block-color)] leading-none text-xs p-1.5 rounded-tl rounded-tr left-0 whitespace-nowrap transition-opacity duration-150`;
144
+
145
+ const labels = {
146
+ de: {
147
+ add: "Hinzufügen",
148
+ position: "Anordnen",
149
+ delete: "Löschen",
150
+ edit: "Bearbeiten",
151
+ addAria: "Block hinzufügen",
152
+ positionAria: "Block anordnen",
153
+ deleteAria: "Block löschen",
154
+ editAria: "Block bearbeiten",
155
+ },
156
+ en: {
157
+ add: "Add",
158
+ position: "Arrange",
159
+ delete: "Delete",
160
+ edit: "Edit",
161
+ addAria: "Add block",
162
+ positionAria: "Arrange block",
163
+ deleteAria: "Delete block",
164
+ editAria: "Edit block",
165
+ },
166
+ };
167
+
168
+ let t = $derived(labels[locale] ?? labels.de);
128
169
  </script>
129
170
 
130
171
  <div
@@ -151,8 +192,10 @@
151
192
  class:opacity-100={toolbarVisible}
152
193
  class:opacity-0={!toolbarVisible}>
153
194
  <button
154
- aria-label="add block"
155
- class="cursor-pointer"
195
+ aria-label={t.addAria}
196
+ class="relative cursor-pointer"
197
+ onmouseenter={() => showTooltip("add")}
198
+ onmouseleave={hideTooltip}
156
199
  onclick={(event) => handleClick(event, CMS_ACTIONS.add)}>
157
200
  <svg
158
201
  width="24"
@@ -167,6 +210,13 @@
167
210
  stroke-linecap="round"
168
211
  stroke-linejoin="round" />
169
212
  </svg>
213
+ <div
214
+ class={tooltipClasses}
215
+ class:opacity-0={activeTooltip !== "add"}
216
+ class:opacity-100={activeTooltip === "add"}
217
+ class:pointer-events-none={activeTooltip !== "add"}>
218
+ {t.add}
219
+ </div>
170
220
  </button>
171
221
 
172
222
  <!-- {#if blockVisible}
@@ -244,8 +294,10 @@
244
294
  </button> -->
245
295
 
246
296
  <button
247
- aria-label="position block"
248
- class="cursor-pointer"
297
+ aria-label={t.positionAria}
298
+ class="relative cursor-pointer"
299
+ onmouseenter={() => showTooltip("position")}
300
+ onmouseleave={hideTooltip}
249
301
  onclick={(event) => handleClick(event, CMS_ACTIONS.position)}>
250
302
  <svg
251
303
  width="24"
@@ -260,11 +312,20 @@
260
312
  stroke-linecap="round"
261
313
  stroke-linejoin="round" />
262
314
  </svg>
315
+ <div
316
+ class={tooltipClasses}
317
+ class:opacity-0={activeTooltip !== "position"}
318
+ class:opacity-100={activeTooltip === "position"}
319
+ class:pointer-events-none={activeTooltip !== "position"}>
320
+ {t.position}
321
+ </div>
263
322
  </button>
264
323
 
265
324
  <button
266
- aria-label="delete block"
267
- class="cursor-pointer"
325
+ aria-label={t.deleteAria}
326
+ class="relative cursor-pointer"
327
+ onmouseenter={() => showTooltip("delete")}
328
+ onmouseleave={hideTooltip}
268
329
  onclick={(event) => handleClick(event, CMS_ACTIONS.delete)}>
269
330
  <svg
270
331
  width="24"
@@ -279,11 +340,20 @@
279
340
  stroke-linecap="round"
280
341
  stroke-linejoin="round" />
281
342
  </svg>
343
+ <div
344
+ class={tooltipClasses}
345
+ class:opacity-0={activeTooltip !== "delete"}
346
+ class:opacity-100={activeTooltip === "delete"}
347
+ class:pointer-events-none={activeTooltip !== "delete"}>
348
+ {t.delete}
349
+ </div>
282
350
  </button>
283
351
 
284
352
  <button
285
- aria-label="edit block"
286
- class="cursor-pointer"
353
+ aria-label={t.editAria}
354
+ class="relative cursor-pointer"
355
+ onmouseenter={() => showTooltip("edit")}
356
+ onmouseleave={hideTooltip}
287
357
  onclick={(event) => handleClick(event, CMS_ACTIONS.edit)}>
288
358
  <svg
289
359
  width="24"
@@ -298,6 +368,13 @@
298
368
  stroke-linecap="round"
299
369
  stroke-linejoin="round" />
300
370
  </svg>
371
+ <div
372
+ class={tooltipClasses}
373
+ class:opacity-0={activeTooltip !== "edit"}
374
+ class:opacity-100={activeTooltip === "edit"}
375
+ class:pointer-events-none={activeTooltip !== "edit"}>
376
+ {t.edit}
377
+ </div>
301
378
  </button>
302
379
  </div>
303
380
 
@@ -315,3 +392,14 @@
315
392
  {/if}
316
393
  </div>
317
394
  </div>
395
+
396
+ <style>
397
+ .tooltip::after {
398
+ content: "";
399
+ bottom: -8px;
400
+ height: 8px;
401
+ left: 0;
402
+ position: absolute;
403
+ right: 0;
404
+ }
405
+ </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;