@ukic/canary-react 2.0.0-canary.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,24 @@
1
+ var __rest = (this && this.__rest) || function (s, e) {
2
+ var t = {};
3
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
4
+ t[p] = s[p];
5
+ if (s != null && typeof Object.getOwnPropertySymbols === "function")
6
+ for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
7
+ if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
8
+ t[p[i]] = s[p[i]];
9
+ }
10
+ return t;
11
+ };
12
+ import React from "react";
13
+ const defaultProps = {
14
+ xmlns: "http://www.w3.org/2000/svg",
15
+ };
16
+ function slot(name = "") {
17
+ return { ref: (e) => (e ? e.setAttribute("slot", name) : null) };
18
+ }
19
+ export const SlottedSVG = (_a) => {
20
+ var { path, slot: slotName, children } = _a, props = __rest(_a, ["path", "slot", "children"]);
21
+ return (React.createElement("svg", Object.assign({}, slot(slotName), props, defaultProps),
22
+ !!path && React.createElement("path", { d: path }),
23
+ children));
24
+ };
@@ -0,0 +1,12 @@
1
+ export declare const attachProps: (node: HTMLElement, newProps: any, oldProps?: any) => void;
2
+ export declare const getClassName: (classList: DOMTokenList, newProps: any, oldProps: any) => string;
3
+ /**
4
+ * Checks if an event is supported in the current execution environment.
5
+ * @license Modernizr 3.0.0pre (Custom Build) | MIT
6
+ */
7
+ export declare const isCoveredByReact: (eventNameSuffix: string) => boolean;
8
+ export declare const syncEvent: (node: Element & {
9
+ __events?: {
10
+ [key: string]: (e: Event) => any;
11
+ };
12
+ }, eventName: string, newEventHandler?: (e: Event) => any) => void;
@@ -0,0 +1,97 @@
1
+ import { camelToDashCase } from './case';
2
+ export const attachProps = (node, newProps, oldProps = {}) => {
3
+ // some test frameworks don't render DOM elements, so we test here to make sure we are dealing with DOM first
4
+ if (node instanceof Element) {
5
+ // add any classes in className to the class list
6
+ const className = getClassName(node.classList, newProps, oldProps);
7
+ if (className !== '') {
8
+ node.className = className;
9
+ }
10
+ Object.keys(newProps).forEach((name) => {
11
+ if (name === 'children' ||
12
+ name === 'style' ||
13
+ name === 'ref' ||
14
+ name === 'class' ||
15
+ name === 'className' ||
16
+ name === 'forwardedRef') {
17
+ return;
18
+ }
19
+ if (name.indexOf('on') === 0 && name[2] === name[2].toUpperCase()) {
20
+ const eventName = name.substring(2);
21
+ const eventNameLc = eventName[0].toLowerCase() + eventName.substring(1);
22
+ if (!isCoveredByReact(eventNameLc)) {
23
+ syncEvent(node, eventNameLc, newProps[name]);
24
+ }
25
+ }
26
+ else {
27
+ node[name] = newProps[name];
28
+ const propType = typeof newProps[name];
29
+ if (propType === 'string') {
30
+ node.setAttribute(camelToDashCase(name), newProps[name]);
31
+ }
32
+ }
33
+ });
34
+ }
35
+ };
36
+ export const getClassName = (classList, newProps, oldProps) => {
37
+ const newClassProp = newProps.className || newProps.class;
38
+ const oldClassProp = oldProps.className || oldProps.class;
39
+ // map the classes to Maps for performance
40
+ const currentClasses = arrayToMap(classList);
41
+ const incomingPropClasses = arrayToMap(newClassProp ? newClassProp.split(' ') : []);
42
+ const oldPropClasses = arrayToMap(oldClassProp ? oldClassProp.split(' ') : []);
43
+ const finalClassNames = [];
44
+ // loop through each of the current classes on the component
45
+ // to see if it should be a part of the classNames added
46
+ currentClasses.forEach((currentClass) => {
47
+ if (incomingPropClasses.has(currentClass)) {
48
+ // add it as its already included in classnames coming in from newProps
49
+ finalClassNames.push(currentClass);
50
+ incomingPropClasses.delete(currentClass);
51
+ }
52
+ else if (!oldPropClasses.has(currentClass)) {
53
+ // add it as it has NOT been removed by user
54
+ finalClassNames.push(currentClass);
55
+ }
56
+ });
57
+ incomingPropClasses.forEach((s) => finalClassNames.push(s));
58
+ return finalClassNames.join(' ');
59
+ };
60
+ /**
61
+ * Checks if an event is supported in the current execution environment.
62
+ * @license Modernizr 3.0.0pre (Custom Build) | MIT
63
+ */
64
+ export const isCoveredByReact = (eventNameSuffix) => {
65
+ if (typeof document === 'undefined') {
66
+ return true;
67
+ }
68
+ else {
69
+ const eventName = 'on' + eventNameSuffix;
70
+ let isSupported = eventName in document;
71
+ if (!isSupported) {
72
+ const element = document.createElement('div');
73
+ element.setAttribute(eventName, 'return;');
74
+ isSupported = typeof element[eventName] === 'function';
75
+ }
76
+ return isSupported;
77
+ }
78
+ };
79
+ export const syncEvent = (node, eventName, newEventHandler) => {
80
+ const eventStore = node.__events || (node.__events = {});
81
+ const oldEventHandler = eventStore[eventName];
82
+ // Remove old listener so they don't double up.
83
+ if (oldEventHandler) {
84
+ node.removeEventListener(eventName, oldEventHandler);
85
+ }
86
+ // Bind new listener.
87
+ node.addEventListener(eventName, (eventStore[eventName] = function handler(e) {
88
+ if (newEventHandler) {
89
+ newEventHandler.call(this, e);
90
+ }
91
+ }));
92
+ };
93
+ const arrayToMap = (arr) => {
94
+ const map = new Map();
95
+ arr.forEach((s) => map.set(s, s));
96
+ return map;
97
+ };
@@ -0,0 +1,2 @@
1
+ export declare const dashToPascalCase: (str: string) => string;
2
+ export declare const camelToDashCase: (str: string) => string;
@@ -0,0 +1,6 @@
1
+ export const dashToPascalCase = (str) => str
2
+ .toLowerCase()
3
+ .split('-')
4
+ .map((segment) => segment.charAt(0).toUpperCase() + segment.slice(1))
5
+ .join('');
6
+ export const camelToDashCase = (str) => str.replace(/([A-Z])/g, (m) => `-${m[0].toLowerCase()}`);
@@ -0,0 +1,2 @@
1
+ export declare const isDevMode: () => boolean;
2
+ export declare const deprecationWarning: (key: string, message: string) => void;
@@ -0,0 +1,12 @@
1
+ export const isDevMode = () => {
2
+ return process && process.env && process.env.NODE_ENV === 'development';
3
+ };
4
+ const warnings = {};
5
+ export const deprecationWarning = (key, message) => {
6
+ if (isDevMode()) {
7
+ if (!warnings[key]) {
8
+ console.warn(message);
9
+ warnings[key] = true;
10
+ }
11
+ }
12
+ };
@@ -0,0 +1,10 @@
1
+ import React from 'react';
2
+ import type { StyleReactProps } from '../interfaces';
3
+ export type StencilReactExternalProps<PropType, ElementType> = PropType & Omit<React.HTMLAttributes<ElementType>, 'style'> & StyleReactProps;
4
+ export type StencilReactForwardedRef<T> = ((instance: T | null) => void) | React.MutableRefObject<T | null> | null;
5
+ export declare const setRef: (ref: StencilReactForwardedRef<any> | React.Ref<any> | undefined, value: any) => void;
6
+ export declare const mergeRefs: (...refs: (StencilReactForwardedRef<any> | React.Ref<any> | undefined)[]) => React.RefCallback<any>;
7
+ export declare const createForwardRef: <PropType, ElementType>(ReactComponent: any, displayName: string) => React.ForwardRefExoticComponent<React.PropsWithoutRef<PropType & Omit<React.HTMLAttributes<ElementType>, "style"> & StyleReactProps> & React.RefAttributes<ElementType>>;
8
+ export declare const defineCustomElement: (tagName: string, customElement: any) => void;
9
+ export * from './attachProps';
10
+ export * from './case';
@@ -0,0 +1,31 @@
1
+ import React from 'react';
2
+ export const setRef = (ref, value) => {
3
+ if (typeof ref === 'function') {
4
+ ref(value);
5
+ }
6
+ else if (ref != null) {
7
+ // Cast as a MutableRef so we can assign current
8
+ ref.current = value;
9
+ }
10
+ };
11
+ export const mergeRefs = (...refs) => {
12
+ return (value) => {
13
+ refs.forEach((ref) => {
14
+ setRef(ref, value);
15
+ });
16
+ };
17
+ };
18
+ export const createForwardRef = (ReactComponent, displayName) => {
19
+ const forwardRef = (props, ref) => {
20
+ return React.createElement(ReactComponent, Object.assign({}, props, { forwardedRef: ref }));
21
+ };
22
+ forwardRef.displayName = displayName;
23
+ return React.forwardRef(forwardRef);
24
+ };
25
+ export const defineCustomElement = (tagName, customElement) => {
26
+ if (customElement !== undefined && typeof customElements !== 'undefined' && !customElements.get(tagName)) {
27
+ customElements.define(tagName, customElement);
28
+ }
29
+ };
30
+ export * from './attachProps';
31
+ export * from './case';
package/package.json ADDED
@@ -0,0 +1,76 @@
1
+ {
2
+ "name": "@ukic/canary-react",
3
+ "sideEffects": false,
4
+ "version": "2.0.0-canary.0",
5
+ "description": "React-wrapped web components compiled using StencilJS",
6
+ "scripts": {
7
+ "build": "npm run clean && npm run compile && npm run copy:core-css && npm run copy:normalize-css",
8
+ "clean": "rimraf dist",
9
+ "compile": "npm run tsc",
10
+ "tsc": "tsc -p .",
11
+ "rollup": "rollup -c",
12
+ "storybook": "start-storybook -p 6007 --no-manager-cache",
13
+ "build-storybook": "rimraf ./storybook-static && build-storybook -s public",
14
+ "audit": "echo 'Audit for: @ukic/canary-react' && audit-ci -m --config ../../audit-ci.json",
15
+ "copy:core-css": "echo 'Copy core.css from: @ukic/canary-web-components' && mkdirp -p ./dist/core && ncp ../web-components/dist/core/core.css ./dist/core/core.css",
16
+ "copy:normalize-css": "echo 'Copy normalize.css from: @ukic/canary-web-components' && ncp ../web-components/dist/core/normalize.css ./dist/core/normalize.css"
17
+ },
18
+ "publishConfig": {
19
+ "access": "public"
20
+ },
21
+ "main": "./dist/index.js",
22
+ "module": "./dist/index.js",
23
+ "types": "./dist/index.d.ts",
24
+ "files": [
25
+ "dist/"
26
+ ],
27
+ "dependencies": {
28
+ "@ukic/canary-web-components": "^2.0.0-canary.0",
29
+ "@ukic/fonts": "^2.2.0"
30
+ },
31
+ "devDependencies": {
32
+ "@babel/core": "^7.16.0",
33
+ "@stencil/react-output-target": "^0.4.0",
34
+ "@storybook/addon-a11y": "^6.4.8",
35
+ "@storybook/addon-actions": "^6.4.8",
36
+ "@storybook/addon-docs": "^6.4.8",
37
+ "@storybook/addon-essentials": "^6.4.8",
38
+ "@storybook/addon-links": "^6.4.8",
39
+ "@storybook/addon-postcss": "^2.0.0",
40
+ "@storybook/builder-webpack5": "^6.5.14",
41
+ "@storybook/manager-webpack5": "^6.5.14",
42
+ "@storybook/react": "6.5.15",
43
+ "@types/jest": "27.0.3",
44
+ "@types/node": "^16.11.11",
45
+ "@types/react": "^17.0.37",
46
+ "@types/react-dom": "^17.0.11",
47
+ "babel-loader": "^8.2.3",
48
+ "jest": "^27.4.1",
49
+ "jest-dom": "^4.0.0",
50
+ "mkdirp": "^1.0.4",
51
+ "np": "^7.6.0",
52
+ "react": "^16.7.0",
53
+ "react-dom": "^16.7.0",
54
+ "react-hook-form": "^7.38.0",
55
+ "react-router-dom": "^6.3.0",
56
+ "typescript": "^4.5.2",
57
+ "webpack": "^5.76.0"
58
+ },
59
+ "overrides": {
60
+ "webpack": "^5.76.0"
61
+ },
62
+ "peerDependencies": {
63
+ "react": "^16.7.0 || ^17.0.2 || ^18.2.0",
64
+ "react-dom": "^16.7.0 || ^17.0.2 || ^18.2.0"
65
+ },
66
+ "jest": {
67
+ "preset": "ts-jest",
68
+ "setupTestFrameworkScriptFile": "<rootDir>/jest.setup.js",
69
+ "testPathIgnorePatterns": [
70
+ "node_modules",
71
+ "dist"
72
+ ]
73
+ },
74
+ "license": "MIT",
75
+ "gitHead": "7c98878b286939f371e498b79cfac7c8617b4a70"
76
+ }