@lvce-editor/preview-worker 1.4.0 → 1.5.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.
@@ -1826,6 +1826,23 @@ const EndCommentTag = 19;
1826
1826
  const Text = 20;
1827
1827
  const CommentStart = 21;
1828
1828
 
1829
+ const isDefaultAllowedAttribute = (attributeName, defaultAllowedAttributes) => {
1830
+ // Allow data-* attributes
1831
+ if (attributeName.startsWith('data-')) {
1832
+ return true;
1833
+ }
1834
+ // Allow aria-* attributes
1835
+ if (attributeName.startsWith('aria-')) {
1836
+ return true;
1837
+ }
1838
+ // Allow role attribute
1839
+ if (attributeName === 'role') {
1840
+ return true;
1841
+ }
1842
+ // Check if in default list
1843
+ return defaultAllowedAttributes.includes(attributeName);
1844
+ };
1845
+
1829
1846
  const isSelfClosingTag = tag => {
1830
1847
  switch (tag) {
1831
1848
  case Br:
@@ -2100,9 +2117,14 @@ const tokenizeHtml = text => {
2100
2117
  return tokens;
2101
2118
  };
2102
2119
 
2103
- const parseHtml = (html, allowedAttributes) => {
2120
+ const parseHtml = (html, allowedAttributes = [], defaultAllowedAttributes = []) => {
2104
2121
  string(html);
2105
2122
  array(allowedAttributes);
2123
+ array(defaultAllowedAttributes);
2124
+
2125
+ // Combine default allowed attributes with any additional ones provided
2126
+ const allAllowedAttributes = new Set([...defaultAllowedAttributes, ...allowedAttributes]);
2127
+ const useBuiltInDefaults = allowedAttributes.length === 0;
2106
2128
  const tokens = tokenizeHtml(html);
2107
2129
  const dom = [];
2108
2130
  const root = {
@@ -2119,7 +2141,7 @@ const parseHtml = (html, allowedAttributes) => {
2119
2141
  attributeName = token.text;
2120
2142
  break;
2121
2143
  case AttributeValue:
2122
- if (allowedAttributes.includes(attributeName)) {
2144
+ if (allAllowedAttributes.has(attributeName) || useBuiltInDefaults && isDefaultAllowedAttribute(attributeName, defaultAllowedAttributes)) {
2123
2145
  const finalAttributeName = attributeName === 'class' ? 'className' : attributeName;
2124
2146
  current[finalAttributeName] = token.text;
2125
2147
  }
@@ -2127,7 +2149,7 @@ const parseHtml = (html, allowedAttributes) => {
2127
2149
  break;
2128
2150
  case ClosingAngleBracket:
2129
2151
  // Handle boolean attributes (attributes without values)
2130
- if (attributeName && allowedAttributes.includes(attributeName)) {
2152
+ if (attributeName && (allAllowedAttributes.has(attributeName) || useBuiltInDefaults && isDefaultAllowedAttribute(attributeName, defaultAllowedAttributes))) {
2131
2153
  const finalAttributeName = attributeName === 'class' ? 'className' : attributeName;
2132
2154
  current[finalAttributeName] = attributeName;
2133
2155
  }
@@ -2163,7 +2185,7 @@ const parseHtml = (html, allowedAttributes) => {
2163
2185
  break;
2164
2186
  case WhitespaceInsideOpeningTag:
2165
2187
  // Handle boolean attributes (attributes without values)
2166
- if (attributeName && allowedAttributes.includes(attributeName)) {
2188
+ if (attributeName && (allAllowedAttributes.has(attributeName) || useBuiltInDefaults && isDefaultAllowedAttribute(attributeName, defaultAllowedAttributes))) {
2167
2189
  const finalAttributeName = attributeName === 'class' ? 'className' : attributeName;
2168
2190
  current[finalAttributeName] = attributeName;
2169
2191
  }
@@ -2272,7 +2294,7 @@ const updateContent = async (state, uri) => {
2272
2294
  const content = await readFile(uri);
2273
2295
 
2274
2296
  // Parse the content into virtual DOM
2275
- const parsedDom = parseHtml(content, []);
2297
+ const parsedDom = parseHtml(content);
2276
2298
  const parsedNodesChildNodeCount = getParsedNodesChildNodeCount(parsedDom);
2277
2299
  return {
2278
2300
  content,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lvce-editor/preview-worker",
3
- "version": "1.4.0",
3
+ "version": "1.5.0",
4
4
  "description": "Preview Worker",
5
5
  "repository": {
6
6
  "type": "git",