@juspay/svelte-ui-components 2.73.2 → 2.75.0

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.
@@ -0,0 +1,65 @@
1
+ <script lang="ts">
2
+ import { onMount, onDestroy } from 'svelte';
3
+ import type { IframeViewerProperties } from './properties';
4
+
5
+ let {
6
+ src,
7
+ title = 'Embedded Content',
8
+ allowedOrigins = [],
9
+ allow = 'fullscreen',
10
+ sandbox,
11
+ loading,
12
+ referrerpolicy,
13
+ testId,
14
+ classes,
15
+ onMessage = () => {}
16
+ }: IframeViewerProperties = $props();
17
+
18
+ let iframeEl: HTMLIFrameElement | null = $state(null);
19
+
20
+ const messageHandler = (event: MessageEvent): void => {
21
+ // Secure by default: forward a message only when its origin is allow-listed AND it
22
+ // originates from the embedded iframe's own window. An empty allowedOrigins list
23
+ // therefore processes nothing.
24
+ if (
25
+ allowedOrigins.length === 0 ||
26
+ !allowedOrigins.includes(event.origin) ||
27
+ event.source !== iframeEl?.contentWindow
28
+ ) {
29
+ return;
30
+ }
31
+ onMessage(event);
32
+ };
33
+
34
+ onMount(() => {
35
+ window.addEventListener('message', messageHandler);
36
+ });
37
+
38
+ onDestroy(() => {
39
+ if (typeof window !== 'undefined') {
40
+ window.removeEventListener('message', messageHandler);
41
+ }
42
+ });
43
+ </script>
44
+
45
+ <div class="iframe-viewer {classes ?? ''}" data-pw={testId}>
46
+ {#if src}
47
+ <iframe bind:this={iframeEl} {src} {title} {allow} {sandbox} {loading} {referrerpolicy}
48
+ ></iframe>
49
+ {/if}
50
+ </div>
51
+
52
+ <style>
53
+ .iframe-viewer {
54
+ width: var(--iframe-viewer-width, 100%);
55
+ height: var(--iframe-viewer-height, 100%);
56
+ display: flex;
57
+ }
58
+
59
+ iframe {
60
+ width: 100%;
61
+ height: 100%;
62
+ border: var(--iframe-viewer-border, none);
63
+ border-radius: var(--iframe-viewer-border-radius, 0);
64
+ }
65
+ </style>
@@ -0,0 +1,4 @@
1
+ import type { IframeViewerProperties } from './properties';
2
+ declare const IframeViewer: import("svelte").Component<IframeViewerProperties, {}, "">;
3
+ type IframeViewer = ReturnType<typeof IframeViewer>;
4
+ export default IframeViewer;
@@ -0,0 +1,33 @@
1
+ export type IframeViewerProperties = MandatoryIframeViewerProperties & OptionalIframeViewerProperties & IframeViewerEventProperties;
2
+ export type MandatoryIframeViewerProperties = {
3
+ /** URL loaded into the iframe. */
4
+ src: string;
5
+ };
6
+ export type OptionalIframeViewerProperties = {
7
+ /** Accessible title for the iframe (default: `'Embedded Content'`). */
8
+ title?: string;
9
+ /**
10
+ * Origins allowed to send `postMessage` events to `onMessage`. An empty array (the
11
+ * default) processes nothing — secure by default.
12
+ */
13
+ allowedOrigins?: string[];
14
+ /** Permissions policy for the iframe `allow` attribute (default: `'fullscreen'`). */
15
+ allow?: string;
16
+ /** Value for the iframe `sandbox` attribute. Omitted when not set. */
17
+ sandbox?: string;
18
+ /** Loading strategy for the iframe. Omitted when not set. */
19
+ loading?: 'eager' | 'lazy';
20
+ /** Referrer policy for the iframe. Omitted when not set. */
21
+ referrerpolicy?: ReferrerPolicy;
22
+ /** Test selector applied as `data-pw` on the container. */
23
+ testId?: string;
24
+ /** Additional CSS classes applied to the container. */
25
+ classes?: string;
26
+ };
27
+ export type IframeViewerEventProperties = {
28
+ /**
29
+ * Called with the `MessageEvent` for `postMessage` events whose origin is in
30
+ * `allowedOrigins` and whose source is the embedded iframe window.
31
+ */
32
+ onMessage?: (event: MessageEvent) => void;
33
+ };
@@ -0,0 +1 @@
1
+ export {};
@@ -254,6 +254,7 @@
254
254
  display: var(--modal-display, flex);
255
255
  overflow-y: var(--modal-overflow-y, scroll);
256
256
  scrollbar-width: var(--modal-scrollbar-width, none);
257
+ padding: var(--modal-content-padding, 0);
257
258
  }
258
259
 
259
260
  .slot-content::-webkit-scrollbar {
package/dist/index.d.ts CHANGED
@@ -52,6 +52,7 @@ export { default as ThemeSwitcher } from './ThemeSwitcher/ThemeSwitcher.svelte';
52
52
  export { default as Book } from './Book/Book.svelte';
53
53
  export { default as Browser } from './Browser/Browser.svelte';
54
54
  export { default as Phone } from './Phone/Phone.svelte';
55
+ export { default as IframeViewer } from './IframeViewer/IframeViewer.svelte';
55
56
  export { default as Card } from './Card/Card.svelte';
56
57
  export { default as EmptyState } from './EmptyState/EmptyState.svelte';
57
58
  export { default as Combobox } from './Combobox/Combobox.svelte';
@@ -114,6 +115,7 @@ export type * from './ThemeSwitcher/properties';
114
115
  export type * from './Book/properties';
115
116
  export type * from './Browser/properties';
116
117
  export type * from './Phone/properties';
118
+ export type * from './IframeViewer/properties';
117
119
  export type * from './Loader/properties';
118
120
  export type * from './Card/properties';
119
121
  export type * from './EmptyState/properties';
package/dist/index.js CHANGED
@@ -52,6 +52,7 @@ export { default as ThemeSwitcher } from './ThemeSwitcher/ThemeSwitcher.svelte';
52
52
  export { default as Book } from './Book/Book.svelte';
53
53
  export { default as Browser } from './Browser/Browser.svelte';
54
54
  export { default as Phone } from './Phone/Phone.svelte';
55
+ export { default as IframeViewer } from './IframeViewer/IframeViewer.svelte';
55
56
  export { default as Card } from './Card/Card.svelte';
56
57
  export { default as EmptyState } from './EmptyState/EmptyState.svelte';
57
58
  export { default as Combobox } from './Combobox/Combobox.svelte';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@juspay/svelte-ui-components",
3
- "version": "2.73.2",
3
+ "version": "2.75.0",
4
4
  "description": "A themeable Svelte 5 UI component library with CSS custom property driven styling",
5
5
  "keywords": [
6
6
  "svelte",