@commonpub/layer 0.21.10 → 0.21.11

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.
@@ -1,21 +1,30 @@
1
1
  <script setup lang="ts">
2
2
  const props = defineProps<{ content: Record<string, unknown> }>();
3
3
 
4
- const url = computed(() => {
4
+ // Translate common watch-page URLs into iframe-embeddable equivalents
5
+ // so authors who paste a YouTube/Vimeo URL into the generic Embed block
6
+ // don't end up with an iframe that the provider refuses to render
7
+ // (X-Frame-Options / CSP frame-ancestors). Mirrors BlockVideoView.
8
+ const embedUrl = computed(() => {
5
9
  const raw = (props.content.url as string) || '';
6
- // Only allow http/https URLs — block javascript:, data:, etc.
7
- if (raw && (raw.startsWith('https://') || raw.startsWith('http://'))) return raw;
10
+ if (!raw) return '';
11
+ const yt = raw.match(/(?:youtube\.com\/(?:watch\?v=|embed\/|v\/|shorts\/)|youtu\.be\/)([a-zA-Z0-9_-]{6,})/);
12
+ if (yt) return `https://www.youtube-nocookie.com/embed/${yt[1]}`;
13
+ const vimeo = raw.match(/vimeo\.com\/(\d+)/);
14
+ if (vimeo) return `https://player.vimeo.com/video/${vimeo[1]}`;
15
+ // Anything else: allow http(s) only (block javascript:, data:, etc.).
16
+ if (raw.startsWith('https://') || raw.startsWith('http://')) return raw;
8
17
  return '';
9
18
  });
10
19
  </script>
11
20
 
12
21
  <template>
13
- <div v-if="url" class="cpub-block-embed">
22
+ <div v-if="embedUrl" class="cpub-block-embed">
14
23
  <div class="cpub-embed-label">
15
24
  <i class="fa-solid fa-globe"></i> Embed
16
25
  </div>
17
26
  <div class="cpub-embed-wrap">
18
- <iframe :src="url" class="cpub-embed-iframe" frameborder="0" loading="lazy" title="Embedded content" />
27
+ <iframe :src="embedUrl" class="cpub-embed-iframe" frameborder="0" loading="lazy" title="Embedded content" />
19
28
  </div>
20
29
  </div>
21
30
  </template>
@@ -7,8 +7,8 @@ const embedUrl = computed(() => {
7
7
  const u = url.value;
8
8
  if (!u) return '';
9
9
 
10
- // YouTube — extract video ID and construct safe embed URL
11
- const ytMatch = u.match(/(?:youtube\.com\/watch\?v=|youtu\.be\/)([a-zA-Z0-9_-]+)/);
10
+ // YouTube — handle watch + youtu.be + /embed/ + /v/ + /shorts/.
11
+ const ytMatch = u.match(/(?:youtube\.com\/(?:watch\?v=|embed\/|v\/|shorts\/)|youtu\.be\/)([a-zA-Z0-9_-]{6,})/);
12
12
  if (ytMatch) return `https://www.youtube-nocookie.com/embed/${ytMatch[1]}`;
13
13
 
14
14
  // Vimeo — extract video ID and construct safe embed URL
@@ -33,6 +33,13 @@ const blockTypes: BlockTypeGroup[] = [
33
33
  { type: 'downloads', label: 'Downloads', icon: 'fa-download', description: 'File attachments' },
34
34
  ],
35
35
  },
36
+ {
37
+ name: 'Media',
38
+ blocks: [
39
+ { type: 'video', label: 'Video', icon: 'fa-film', description: 'YouTube, Vimeo embed' },
40
+ { type: 'embed', label: 'Embed', icon: 'fa-globe', description: 'External embed (translates YouTube/Vimeo URLs)' },
41
+ ],
42
+ },
36
43
  {
37
44
  name: 'Rich',
38
45
  blocks: [
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@commonpub/layer",
3
- "version": "0.21.10",
3
+ "version": "0.21.11",
4
4
  "type": "module",
5
5
  "main": "./nuxt.config.ts",
6
6
  "files": [
@@ -50,16 +50,16 @@
50
50
  "vue": "^3.4.0",
51
51
  "vue-router": "^4.3.0",
52
52
  "zod": "^4.3.6",
53
+ "@commonpub/auth": "0.6.0",
53
54
  "@commonpub/docs": "0.6.3",
54
- "@commonpub/explainer": "0.7.14",
55
- "@commonpub/editor": "0.7.10",
55
+ "@commonpub/protocol": "0.10.1",
56
+ "@commonpub/schema": "0.16.0",
56
57
  "@commonpub/learning": "0.5.2",
57
- "@commonpub/server": "2.54.1",
58
58
  "@commonpub/ui": "0.8.5",
59
+ "@commonpub/explainer": "0.7.15",
59
60
  "@commonpub/config": "0.13.0",
60
- "@commonpub/auth": "0.6.0",
61
- "@commonpub/schema": "0.16.0",
62
- "@commonpub/protocol": "0.10.1"
61
+ "@commonpub/server": "2.54.2",
62
+ "@commonpub/editor": "0.7.10"
63
63
  },
64
64
  "devDependencies": {
65
65
  "@testing-library/jest-dom": "^6.9.1",