@selfcommunity/react-ui 0.7.30-alpha.0 → 0.7.30-alpha.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.
@@ -85,12 +85,56 @@ function CustomAdv(inProps) {
85
85
  }
86
86
  }
87
87
  });
88
+ const embedRef = (0, react_1.useRef)(null);
89
+ (0, react_1.useEffect)(() => {
90
+ const embedCode = scCustomAdv === null || scCustomAdv === void 0 ? void 0 : scCustomAdv.embed_code;
91
+ const container = embedRef.current;
92
+ if (container && embedCode) {
93
+ // Create a temporary container for parsing HTML
94
+ const tempDiv = document.createElement('div');
95
+ tempDiv.innerHTML = embedCode;
96
+ // Extract scripts from HTML content
97
+ const scripts = tempDiv.getElementsByTagName('script');
98
+ const scriptContents = [];
99
+ // eslint-disable-next-line @typescript-eslint/ban-ts-comment
100
+ // @ts-ignore
101
+ for (let script of scripts) {
102
+ if (script.src) {
103
+ // If the script has a src attribute, create a new script element and set its src
104
+ const newScript = document.createElement('script');
105
+ newScript.src = script.src;
106
+ document.body.appendChild(newScript);
107
+ }
108
+ else {
109
+ // If the script contains inline code, store its content for later execution
110
+ scriptContents.push(script.innerHTML);
111
+ }
112
+ // Remove the script tag from the tempDiv
113
+ script.parentNode.removeChild(script);
114
+ }
115
+ // Insert the HTML content into the container
116
+ // eslint-disable-next-line @typescript-eslint/ban-ts-comment
117
+ // @ts-ignore
118
+ container.innerHTML = tempDiv.innerHTML;
119
+ // Execute inline script contents
120
+ scriptContents.forEach((scriptContent) => {
121
+ try {
122
+ const newScript = document.createElement('script');
123
+ newScript.appendChild(document.createTextNode(scriptContent));
124
+ document.body.appendChild(newScript);
125
+ }
126
+ catch (e) {
127
+ console.error('Error executing script', e);
128
+ }
129
+ });
130
+ }
131
+ }, [scCustomAdv]);
88
132
  if (!scCustomAdv) {
89
133
  return react_1.default.createElement(HiddenPlaceholder_1.default, null);
90
134
  }
91
135
  const adv = (react_1.default.createElement(material_1.Box, { className: classes.wrap },
92
136
  scCustomAdv.image && (react_1.default.createElement("img", { src: scCustomAdv.image, alt: scCustomAdv.title, className: (0, classnames_1.default)(classes.image, { [classes.prefixedHeight]: Boolean(prefixedHeight) }) })),
93
- scCustomAdv.embed_code && (react_1.default.createElement(material_1.Box, { className: (0, classnames_1.default)(classes.embedCode, { [classes.prefixedHeight]: Boolean(prefixedHeight) }), dangerouslySetInnerHTML: { __html: scCustomAdv.embed_code } }))));
137
+ scCustomAdv.embed_code && (react_1.default.createElement(material_1.Box, { ref: embedRef, className: (0, classnames_1.default)(classes.embedCode, { [classes.prefixedHeight]: Boolean(prefixedHeight) }), dangerouslySetInnerHTML: { __html: scCustomAdv.embed_code } }))));
94
138
  return (react_1.default.createElement(Root, { id: id, className: (0, classnames_1.default)(classes.root, className), ref: ref, style: Object.assign({}, (prefixedHeight ? { paddingBottom: prefixedHeight } : { width: '100%' })) }, scCustomAdv.link ? (react_1.default.createElement("a", { href: scCustomAdv.link, title: scCustomAdv.title }, adv)) : (adv)));
95
139
  }
96
140
  exports.default = CustomAdv;
@@ -188,7 +188,7 @@ function NavigationSettingsIconButton(inProps) {
188
188
  ...(isModerator || isAdmin
189
189
  ? [
190
190
  react_1.default.createElement(material_1.Divider, { key: "moderation_divider" }),
191
- react_1.default.createElement(material_1.MenuItem, { className: classes.item, key: "moderation", onClick: () => fetchPlatform('/moderation') },
191
+ react_1.default.createElement(material_1.MenuItem, { className: classes.item, key: "moderation", onClick: () => fetchPlatform('/moderation/flags/') },
192
192
  react_1.default.createElement(react_intl_1.FormattedMessage, { id: "ui.navigationSettingsIconButton.moderation", defaultMessage: "ui.navigationSettingsIconButton.moderation" }))
193
193
  ]
194
194
  : []),
@@ -1,4 +1,4 @@
1
- import React, { useRef } from 'react';
1
+ import React, { useEffect, useRef } from 'react';
2
2
  import { styled } from '@mui/material/styles';
3
3
  import { Box } from '@mui/material';
4
4
  import { useIsComponentMountedRef, useSCFetchCustomAdv } from '@selfcommunity/react-core';
@@ -82,11 +82,55 @@ export default function CustomAdv(inProps) {
82
82
  }
83
83
  }
84
84
  });
85
+ const embedRef = useRef(null);
86
+ useEffect(() => {
87
+ const embedCode = scCustomAdv === null || scCustomAdv === void 0 ? void 0 : scCustomAdv.embed_code;
88
+ const container = embedRef.current;
89
+ if (container && embedCode) {
90
+ // Create a temporary container for parsing HTML
91
+ const tempDiv = document.createElement('div');
92
+ tempDiv.innerHTML = embedCode;
93
+ // Extract scripts from HTML content
94
+ const scripts = tempDiv.getElementsByTagName('script');
95
+ const scriptContents = [];
96
+ // eslint-disable-next-line @typescript-eslint/ban-ts-comment
97
+ // @ts-ignore
98
+ for (let script of scripts) {
99
+ if (script.src) {
100
+ // If the script has a src attribute, create a new script element and set its src
101
+ const newScript = document.createElement('script');
102
+ newScript.src = script.src;
103
+ document.body.appendChild(newScript);
104
+ }
105
+ else {
106
+ // If the script contains inline code, store its content for later execution
107
+ scriptContents.push(script.innerHTML);
108
+ }
109
+ // Remove the script tag from the tempDiv
110
+ script.parentNode.removeChild(script);
111
+ }
112
+ // Insert the HTML content into the container
113
+ // eslint-disable-next-line @typescript-eslint/ban-ts-comment
114
+ // @ts-ignore
115
+ container.innerHTML = tempDiv.innerHTML;
116
+ // Execute inline script contents
117
+ scriptContents.forEach((scriptContent) => {
118
+ try {
119
+ const newScript = document.createElement('script');
120
+ newScript.appendChild(document.createTextNode(scriptContent));
121
+ document.body.appendChild(newScript);
122
+ }
123
+ catch (e) {
124
+ console.error('Error executing script', e);
125
+ }
126
+ });
127
+ }
128
+ }, [scCustomAdv]);
85
129
  if (!scCustomAdv) {
86
130
  return React.createElement(HiddenPlaceholder, null);
87
131
  }
88
132
  const adv = (React.createElement(Box, { className: classes.wrap },
89
133
  scCustomAdv.image && (React.createElement("img", { src: scCustomAdv.image, alt: scCustomAdv.title, className: classNames(classes.image, { [classes.prefixedHeight]: Boolean(prefixedHeight) }) })),
90
- scCustomAdv.embed_code && (React.createElement(Box, { className: classNames(classes.embedCode, { [classes.prefixedHeight]: Boolean(prefixedHeight) }), dangerouslySetInnerHTML: { __html: scCustomAdv.embed_code } }))));
134
+ scCustomAdv.embed_code && (React.createElement(Box, { ref: embedRef, className: classNames(classes.embedCode, { [classes.prefixedHeight]: Boolean(prefixedHeight) }), dangerouslySetInnerHTML: { __html: scCustomAdv.embed_code } }))));
91
135
  return (React.createElement(Root, { id: id, className: classNames(classes.root, className), ref: ref, style: Object.assign({}, (prefixedHeight ? { paddingBottom: prefixedHeight } : { width: '100%' })) }, scCustomAdv.link ? (React.createElement("a", { href: scCustomAdv.link, title: scCustomAdv.title }, adv)) : (adv)));
92
136
  }
@@ -186,7 +186,7 @@ export default function NavigationSettingsIconButton(inProps) {
186
186
  ...(isModerator || isAdmin
187
187
  ? [
188
188
  React.createElement(Divider, { key: "moderation_divider" }),
189
- React.createElement(MenuItem, { className: classes.item, key: "moderation", onClick: () => fetchPlatform('/moderation') },
189
+ React.createElement(MenuItem, { className: classes.item, key: "moderation", onClick: () => fetchPlatform('/moderation/flags/') },
190
190
  React.createElement(FormattedMessage, { id: "ui.navigationSettingsIconButton.moderation", defaultMessage: "ui.navigationSettingsIconButton.moderation" }))
191
191
  ]
192
192
  : []),