@helpdice/ui 1.7.9 → 1.8.3
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/dist/auto-complete/index.js +13 -4
- package/dist/breadcrumbs/index.js +4 -4
- package/dist/card/index.js +4 -4
- package/dist/carousal/index.js +2935 -7
- package/dist/image/index.js +4 -4
- package/dist/index.js +19 -11
- package/dist/link/index.js +4 -4
- package/dist/table/index.js +13 -4
- package/dist/user/index.js +4 -4
- package/esm/carousal/component/Thumbs.js +1 -1
- package/esm/link/link.js +4 -4
- package/esm/parser/HtmlParser.js +24 -0
- package/esm/parser/convertNodeToElement.js +13 -0
- package/esm/parser/dom/attributes/BooleanAttributes.js +9 -0
- package/esm/parser/dom/attributes/ReactAttributes.js +164 -0
- package/esm/parser/dom/elements/VoidElements.js +6 -0
- package/esm/parser/elementTypes/StyleElementType.js +24 -0
- package/esm/parser/elementTypes/TagElementType.js +34 -0
- package/esm/parser/elementTypes/TextElementType.js +10 -0
- package/esm/parser/elementTypes/UnsupportedElementType.js +9 -0
- package/esm/parser/elementTypes/index.js +13 -0
- package/esm/parser/index.js +7 -0
- package/esm/parser/processNodes.js +27 -0
- package/esm/parser/scripts/attributes-diff.js +26 -0
- package/esm/parser/utils/generatePropsFromAttributes.js +24 -0
- package/esm/parser/utils/htmlAttributesToReact.js +45 -0
- package/esm/parser/utils/inlineStyleToObject.js +43 -0
- package/esm/parser/utils/isEmptyTextNode.js +10 -0
- package/esm/parser/utils/isValidTagOrAttributeName.js +8 -0
- package/package.json +10 -9
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import htmlAttributesToReact from './htmlAttributesToReact';
|
|
2
|
+
import inlineStyleToObject from './inlineStyleToObject';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Generates props for a React element from an object of HTML attributes
|
|
6
|
+
*
|
|
7
|
+
* @param {Object} attributes The HTML attributes
|
|
8
|
+
* @param {String} key The key to give the react element
|
|
9
|
+
*/
|
|
10
|
+
export default function generatePropsFromAttributes(attributes, key) {
|
|
11
|
+
// generate props
|
|
12
|
+
var props = Object.assign({}, htmlAttributesToReact(attributes), {
|
|
13
|
+
key: key
|
|
14
|
+
});
|
|
15
|
+
|
|
16
|
+
// if there is an inline/string style prop then convert it to a React style object
|
|
17
|
+
// otherwise, it is invalid and omitted
|
|
18
|
+
if (typeof props.style === 'string' || props.style instanceof String) {
|
|
19
|
+
props.style = inlineStyleToObject(props.style);
|
|
20
|
+
} else {
|
|
21
|
+
delete props.style;
|
|
22
|
+
}
|
|
23
|
+
return props;
|
|
24
|
+
}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import BooleanAttributes from '../dom/attributes/BooleanAttributes';
|
|
2
|
+
import ReactAttributes from '../dom/attributes/ReactAttributes';
|
|
3
|
+
import isValidTagOrAttributeName from './isValidTagOrAttributeName';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Returns the parsed attribute value taking into account things like boolean attributes
|
|
7
|
+
*
|
|
8
|
+
* @param {String} attribute The name of the attribute
|
|
9
|
+
* @param {*} value The value of the attribute from the HTML
|
|
10
|
+
* @returns {*} The parsed attribute value
|
|
11
|
+
*/
|
|
12
|
+
var getParsedAttributeValue = function getParsedAttributeValue(attribute, value) {
|
|
13
|
+
// if the attribute if a boolean then it's value should be the same as it's name
|
|
14
|
+
// e.g. disabled="disabled"
|
|
15
|
+
var lowerBooleanAttributes = BooleanAttributes.map(function (attr) {
|
|
16
|
+
return attr.toLowerCase();
|
|
17
|
+
});
|
|
18
|
+
if (lowerBooleanAttributes.indexOf(attribute.toLowerCase()) >= 0) {
|
|
19
|
+
value = attribute;
|
|
20
|
+
}
|
|
21
|
+
return value;
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* Takes an object of standard HTML property names and converts them to their React counterpart. If the react
|
|
26
|
+
* version does not exist for an attribute then just use it as it is
|
|
27
|
+
*
|
|
28
|
+
* @param {Object} attributes The HTML attributes to convert
|
|
29
|
+
* @returns {Object} The React attributes
|
|
30
|
+
*/
|
|
31
|
+
export default function htmlAttributesToReact(attributes) {
|
|
32
|
+
return Object.keys(attributes).filter(function (attr) {
|
|
33
|
+
return isValidTagOrAttributeName(attr);
|
|
34
|
+
}).reduce(function (mappedAttributes, attribute) {
|
|
35
|
+
// lowercase the attribute name and find it in the react attribute map
|
|
36
|
+
var lowerCaseAttribute = attribute.toLowerCase();
|
|
37
|
+
|
|
38
|
+
// format the attribute name
|
|
39
|
+
var name = ReactAttributes[lowerCaseAttribute] || lowerCaseAttribute;
|
|
40
|
+
|
|
41
|
+
// add the parsed attribute value to the mapped attributes
|
|
42
|
+
mappedAttributes[name] = getParsedAttributeValue(name, attributes[attribute]);
|
|
43
|
+
return mappedAttributes;
|
|
44
|
+
}, {});
|
|
45
|
+
}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
|
|
2
|
+
/**
|
|
3
|
+
* Converts an inline style string into an object of React style properties
|
|
4
|
+
*
|
|
5
|
+
* @param {String} inlineStyle='' The inline style to convert
|
|
6
|
+
* @returns {Object} The converted style
|
|
7
|
+
*/
|
|
8
|
+
export default function InlineStyleToObject() {
|
|
9
|
+
var inlineStyle = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : '';
|
|
10
|
+
// just return empty object if the inlineStyle is empty
|
|
11
|
+
if (inlineStyle === '') {
|
|
12
|
+
return {};
|
|
13
|
+
}
|
|
14
|
+
return inlineStyle.split(';').reduce(function (styleObject, stylePropertyValue) {
|
|
15
|
+
// extract the style property name and value
|
|
16
|
+
var _stylePropertyValue$s = stylePropertyValue.split(/^([^:]+):/).filter(function (val, i) {
|
|
17
|
+
return i > 0;
|
|
18
|
+
}).map(function (item) {
|
|
19
|
+
return item.trim().toLowerCase();
|
|
20
|
+
}),
|
|
21
|
+
_stylePropertyValue$s2 = _slicedToArray(_stylePropertyValue$s, 2),
|
|
22
|
+
property = _stylePropertyValue$s2[0],
|
|
23
|
+
value = _stylePropertyValue$s2[1];
|
|
24
|
+
|
|
25
|
+
// if there is no value (i.e. no : in the style) then ignore it
|
|
26
|
+
if (value === undefined) {
|
|
27
|
+
return styleObject;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
// convert the property name into the correct React format
|
|
31
|
+
// remove all hyphens and convert the letter immediately after each hyphen to upper case
|
|
32
|
+
// additionally don't uppercase any -ms- prefix
|
|
33
|
+
// e.g. -ms-style-property = msStyleProperty
|
|
34
|
+
// -webkit-style-property = WebkitStyleProperty
|
|
35
|
+
property = property.replace(/^-ms-/, 'ms-').replace(/-(.)/g, function (_, character) {
|
|
36
|
+
return character.toUpperCase();
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
// add the new style property and value to the style object
|
|
40
|
+
styleObject[property] = value;
|
|
41
|
+
return styleObject;
|
|
42
|
+
}, {});
|
|
43
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Tests a htmlparser2 node and returns whether is it a text node at the start and end of the line containing only
|
|
3
|
+
* white space. This allows these node types to be excluded from the rendering because they are unnecessary.
|
|
4
|
+
*
|
|
5
|
+
* @param {Object} node The element object as created by htmlparser2
|
|
6
|
+
* @returns {boolean} Whether the node is an empty text node
|
|
7
|
+
*/
|
|
8
|
+
export default function isEmptyTextNode(node) {
|
|
9
|
+
return node.type === 'text' && /\r?\n/.test(node.data) && node.data.trim() === '';
|
|
10
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
var VALID_TAG_REGEX = /^[a-zA-Z][a-zA-Z:_\.\-\d]*$/;
|
|
2
|
+
var nameCache = {};
|
|
3
|
+
export default function isValidTagOrAttributeName(tagName) {
|
|
4
|
+
if (!nameCache.hasOwnProperty(tagName)) {
|
|
5
|
+
nameCache[tagName] = VALID_TAG_REGEX.test(tagName);
|
|
6
|
+
}
|
|
7
|
+
return nameCache[tagName];
|
|
8
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@helpdice/ui",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.8.3",
|
|
4
4
|
"main": "dist/index.js",
|
|
5
5
|
"types": "esm/index.d.ts",
|
|
6
6
|
"unpkg": "dist/index.min.js",
|
|
@@ -24,7 +24,8 @@
|
|
|
24
24
|
"build:after": "node scripts/move-built-in.js",
|
|
25
25
|
"build:types": "tsc -p ./scripts & tsc -p ./scripts --outDir ./esm",
|
|
26
26
|
"build:package": "yarn build:rollup && yarn build:babel && yarn build:types && yarn build:after",
|
|
27
|
-
"release": "yarn publish --access public --non-interactive"
|
|
27
|
+
"release": "yarn publish --access public --non-interactive",
|
|
28
|
+
"release:github": "yarn publish --registry=https://npm.pkg.github.com"
|
|
28
29
|
},
|
|
29
30
|
"license": "MIT",
|
|
30
31
|
"description": "Modern React UI library.",
|
|
@@ -36,6 +37,9 @@
|
|
|
36
37
|
"type": "git",
|
|
37
38
|
"url": "https://github.com/helpdice/ui"
|
|
38
39
|
},
|
|
40
|
+
"publishConfig": {
|
|
41
|
+
"registry": "https://registry.npmjs.org/"
|
|
42
|
+
},
|
|
39
43
|
"prettier": "@helpdice/prettier-config",
|
|
40
44
|
"keywords": [
|
|
41
45
|
"flux",
|
|
@@ -57,9 +61,7 @@
|
|
|
57
61
|
"@babel/preset-env": "^7.14.7",
|
|
58
62
|
"@babel/preset-react": "^7.14.5",
|
|
59
63
|
"@babel/preset-typescript": "^7.14.5",
|
|
60
|
-
"@helpdice/icons": "^1.1.
|
|
61
|
-
"@helpdice/pro": "^1.1.6",
|
|
62
|
-
"@helpdice/theme": "^1.0.3",
|
|
64
|
+
"@helpdice/icons": "^1.1.3",
|
|
63
65
|
"@mapbox/rehype-prism": "^0.9.0",
|
|
64
66
|
"@mdx-js/loader": "^3.1.0",
|
|
65
67
|
"@mdx-js/react": "^3.1.0",
|
|
@@ -74,7 +76,6 @@
|
|
|
74
76
|
"@types/react": "~18.3.1",
|
|
75
77
|
"@types/react-color": "^3.0.13",
|
|
76
78
|
"@types/react-dom": "~18.3.1",
|
|
77
|
-
"@types/react-html-parser": "^2.0.6",
|
|
78
79
|
"@types/react-syntax-highlighter": "^15.5.13",
|
|
79
80
|
"@types/react-transition-group": "^4.4.12",
|
|
80
81
|
"@types/warning": "^3.0.3",
|
|
@@ -104,12 +105,13 @@
|
|
|
104
105
|
},
|
|
105
106
|
"dependencies": {
|
|
106
107
|
"@floating-ui/react-dom": "^2.1.3",
|
|
107
|
-
"@helpdice/sdk": "^0.1.
|
|
108
|
+
"@helpdice/sdk": "^0.1.4",
|
|
108
109
|
"@helpdice/utils": "^0.1.3",
|
|
109
110
|
"@mapbox/rehype-prism": "^0.9.0",
|
|
110
111
|
"@types/hoist-non-react-statics": "^3.3.6",
|
|
111
112
|
"@types/styled-components": "^5.1.34",
|
|
112
113
|
"babel-plugin-transform-rename-import": "^2.3.0",
|
|
114
|
+
"classnames": "^2.5.1",
|
|
113
115
|
"clsx": "^2.1.1",
|
|
114
116
|
"css-box-model": "^1.2.1",
|
|
115
117
|
"date-fns": "^4.1.0",
|
|
@@ -123,7 +125,6 @@
|
|
|
123
125
|
"next-sitemap": "^4.2.3",
|
|
124
126
|
"polished": "^4.3.1",
|
|
125
127
|
"react-fast-compare": "^3.2.2",
|
|
126
|
-
"react-html-parser": "^2.0.2",
|
|
127
128
|
"react-is": "^19.0.0",
|
|
128
129
|
"react-syntax-highlighter": "^15.6.1",
|
|
129
130
|
"react-transition-group": "^4.4.5",
|
|
@@ -134,7 +135,7 @@
|
|
|
134
135
|
"tslib": "^2.8.1"
|
|
135
136
|
},
|
|
136
137
|
"peerDependencies": {
|
|
137
|
-
"@helpdice/theme": "^1.0.
|
|
138
|
+
"@helpdice/theme": "^1.0.5",
|
|
138
139
|
"react": "^18.3.1 || ^19.1.0",
|
|
139
140
|
"react-dom": "^18.3.1 || ^19.1.0"
|
|
140
141
|
},
|