@ai12z/react 2.0.3-alpha.2 → 2.0.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/README.md +2 -0
- package/dist/build/assets/lang/ar.json +9 -0
- package/dist/build/assets/lang/de.json +9 -0
- package/dist/build/assets/lang/en.json +9 -0
- package/dist/build/assets/lang/es.json +9 -0
- package/dist/build/assets/lang/fa.json +9 -0
- package/dist/build/assets/lang/fr.json +9 -0
- package/dist/build/assets/lang/hi.json +9 -0
- package/dist/build/assets/lang/it.json +9 -0
- package/dist/build/assets/lang/ja.json +9 -0
- package/dist/build/assets/lang/ko.json +9 -0
- package/dist/build/assets/lang/nl.json +9 -0
- package/dist/build/assets/lang/pl.json +9 -0
- package/dist/build/assets/lang/pt.json +9 -0
- package/dist/build/assets/lang/ro.json +9 -0
- package/dist/build/assets/lang/sv.json +9 -0
- package/dist/build/assets/lang/th.json +9 -0
- package/dist/build/assets/lang/tr.json +9 -0
- package/dist/build/assets/lang/uk.json +9 -0
- package/dist/build/assets/lang/vi.json +9 -0
- package/dist/build/assets/lang/zh.json +9 -0
- package/dist/components/stencil-generated/index.js +14 -0
- package/dist/components/stencil-generated/index.js.map +1 -0
- package/dist/components/stencil-generated/react-component-lib/attachProps.js +92 -0
- package/dist/components/stencil-generated/react-component-lib/attachProps.js.map +1 -0
- package/dist/components/stencil-generated/react-component-lib/case.js +7 -0
- package/dist/components/stencil-generated/react-component-lib/case.js.map +1 -0
- package/dist/components/stencil-generated/react-component-lib/createComponent.js +65 -0
- package/dist/components/stencil-generated/react-component-lib/createComponent.js.map +1 -0
- package/dist/components/stencil-generated/react-component-lib/createOverlayComponent.js +98 -0
- package/dist/components/stencil-generated/react-component-lib/createOverlayComponent.js.map +1 -0
- package/dist/components/stencil-generated/react-component-lib/dev.js +13 -0
- package/dist/components/stencil-generated/react-component-lib/dev.js.map +1 -0
- package/dist/components/stencil-generated/react-component-lib/index.js +3 -0
- package/dist/components/stencil-generated/react-component-lib/index.js.map +1 -0
- package/dist/components/stencil-generated/react-component-lib/interfaces.js +2 -0
- package/dist/components/stencil-generated/react-component-lib/interfaces.js.map +1 -0
- package/dist/components/stencil-generated/react-component-lib/utils/attachProps.js +92 -0
- package/dist/components/stencil-generated/react-component-lib/utils/attachProps.js.map +1 -0
- package/dist/components/stencil-generated/react-component-lib/utils/case.js +7 -0
- package/dist/components/stencil-generated/react-component-lib/utils/case.js.map +1 -0
- package/dist/components/stencil-generated/react-component-lib/utils/dev.js +13 -0
- package/dist/components/stencil-generated/react-component-lib/utils/dev.js.map +1 -0
- package/dist/components/stencil-generated/react-component-lib/utils/index.js +31 -0
- package/dist/components/stencil-generated/react-component-lib/utils/index.js.map +1 -0
- package/dist/index.js +31 -0
- package/dist/index.js.map +1 -0
- package/dist/lib/components/stencil-generated/react-component-lib/attachProps.js +92 -0
- package/dist/lib/components/stencil-generated/react-component-lib/attachProps.js.map +1 -0
- package/dist/lib/components/stencil-generated/react-component-lib/case.js +7 -0
- package/dist/lib/components/stencil-generated/react-component-lib/case.js.map +1 -0
- package/dist/lib/components/stencil-generated/react-component-lib/dev.js +13 -0
- package/dist/lib/components/stencil-generated/react-component-lib/dev.js.map +1 -0
- package/dist/lib/index.js.map +1 -1
- package/dist/package.json +2 -2
- package/dist/types/components/stencil-generated/index.d.ts +12 -0
- package/dist/types/components/stencil-generated/react-component-lib/attachProps.d.ts +9 -0
- package/dist/types/components/stencil-generated/react-component-lib/case.d.ts +2 -0
- package/dist/types/components/stencil-generated/react-component-lib/createComponent.d.ts +10 -0
- package/dist/types/components/stencil-generated/react-component-lib/createOverlayComponent.d.ts +21 -0
- package/dist/types/components/stencil-generated/react-component-lib/dev.d.ts +2 -0
- package/dist/types/components/stencil-generated/react-component-lib/index.d.ts +2 -0
- package/dist/types/components/stencil-generated/react-component-lib/interfaces.d.ts +29 -0
- package/dist/types/components/stencil-generated/react-component-lib/utils/attachProps.d.ts +9 -0
- package/dist/types/components/stencil-generated/react-component-lib/utils/case.d.ts +2 -0
- package/dist/types/components/stencil-generated/react-component-lib/utils/dev.d.ts +2 -0
- package/dist/types/components/stencil-generated/react-component-lib/utils/index.d.ts +10 -0
- package/dist/types/index.d.ts +2 -0
- package/dist/types/lib/components/stencil-generated/react-component-lib/attachProps.d.ts +9 -0
- package/dist/types/lib/components/stencil-generated/react-component-lib/case.d.ts +2 -0
- package/dist/types/lib/components/stencil-generated/react-component-lib/dev.d.ts +2 -0
- package/lib/components/stencil-generated/react-component-lib/attachProps.ts +125 -0
- package/lib/components/stencil-generated/react-component-lib/case.ts +7 -0
- package/lib/components/stencil-generated/react-component-lib/dev.ts +14 -0
- package/lib/components/stencil-generated/react-component-lib/index.tsx +50 -0
- package/lib/index.ts +0 -1
- package/package.json +3 -3
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
import { camelToDashCase } from './case';
|
|
2
|
+
|
|
3
|
+
export const attachProps = (node: HTMLElement, newProps: any, oldProps: any = {}) => {
|
|
4
|
+
// some test frameworks don't render DOM elements, so we test here to make sure we are dealing with DOM first
|
|
5
|
+
if (node instanceof Element) {
|
|
6
|
+
// add any classes in className to the class list
|
|
7
|
+
const className = getClassName(node.classList, newProps, oldProps);
|
|
8
|
+
if (className !== '') {
|
|
9
|
+
node.className = className;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
Object.keys(newProps).forEach((name) => {
|
|
13
|
+
if (
|
|
14
|
+
name === 'children' ||
|
|
15
|
+
name === 'style' ||
|
|
16
|
+
name === 'ref' ||
|
|
17
|
+
name === 'class' ||
|
|
18
|
+
name === 'className' ||
|
|
19
|
+
name === 'forwardedRef'
|
|
20
|
+
) {
|
|
21
|
+
return;
|
|
22
|
+
}
|
|
23
|
+
if (name.indexOf('on') === 0 && name[2] === name[2].toUpperCase()) {
|
|
24
|
+
const eventName = name.substring(2);
|
|
25
|
+
const eventNameLc = eventName[0].toLowerCase() + eventName.substring(1);
|
|
26
|
+
|
|
27
|
+
if (!isCoveredByReact(eventNameLc)) {
|
|
28
|
+
syncEvent(node, eventNameLc, newProps[name]);
|
|
29
|
+
}
|
|
30
|
+
} else {
|
|
31
|
+
(node as any)[name] = newProps[name];
|
|
32
|
+
const propType = typeof newProps[name];
|
|
33
|
+
if (propType === 'string') {
|
|
34
|
+
node.setAttribute(camelToDashCase(name), newProps[name]);
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
});
|
|
38
|
+
}
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
export const getClassName = (classList: DOMTokenList, newProps: any, oldProps: any) => {
|
|
42
|
+
const newClassProp: string = newProps.className || newProps.class;
|
|
43
|
+
const oldClassProp: string = oldProps.className || oldProps.class;
|
|
44
|
+
// map the classes to Maps for performance
|
|
45
|
+
const currentClasses = arrayToMap(classList);
|
|
46
|
+
const incomingPropClasses = arrayToMap(newClassProp ? newClassProp.split(' ') : []);
|
|
47
|
+
const oldPropClasses = arrayToMap(oldClassProp ? oldClassProp.split(' ') : []);
|
|
48
|
+
const finalClassNames: string[] = [];
|
|
49
|
+
// loop through each of the current classes on the component
|
|
50
|
+
// to see if it should be a part of the classNames added
|
|
51
|
+
currentClasses.forEach((currentClass) => {
|
|
52
|
+
if (incomingPropClasses.has(currentClass)) {
|
|
53
|
+
// add it as its already included in classnames coming in from newProps
|
|
54
|
+
finalClassNames.push(currentClass);
|
|
55
|
+
incomingPropClasses.delete(currentClass);
|
|
56
|
+
} else if (!oldPropClasses.has(currentClass)) {
|
|
57
|
+
// add it as it has NOT been removed by user
|
|
58
|
+
finalClassNames.push(currentClass);
|
|
59
|
+
}
|
|
60
|
+
});
|
|
61
|
+
incomingPropClasses.forEach((s) => finalClassNames.push(s));
|
|
62
|
+
return finalClassNames.join(' ');
|
|
63
|
+
};
|
|
64
|
+
|
|
65
|
+
/**
|
|
66
|
+
* Transforms a React event name to a browser event name.
|
|
67
|
+
*/
|
|
68
|
+
export const transformReactEventName = (eventNameSuffix: string) => {
|
|
69
|
+
switch (eventNameSuffix) {
|
|
70
|
+
case 'doubleclick':
|
|
71
|
+
return 'dblclick';
|
|
72
|
+
}
|
|
73
|
+
return eventNameSuffix;
|
|
74
|
+
};
|
|
75
|
+
|
|
76
|
+
/**
|
|
77
|
+
* Checks if an event is supported in the current execution environment.
|
|
78
|
+
* @license Modernizr 3.0.0pre (Custom Build) | MIT
|
|
79
|
+
*/
|
|
80
|
+
export const isCoveredByReact = (eventNameSuffix: string) => {
|
|
81
|
+
if (typeof document === 'undefined') {
|
|
82
|
+
return true;
|
|
83
|
+
} else {
|
|
84
|
+
const eventName = 'on' + transformReactEventName(eventNameSuffix);
|
|
85
|
+
let isSupported = eventName in document;
|
|
86
|
+
|
|
87
|
+
if (!isSupported) {
|
|
88
|
+
const element = document.createElement('div');
|
|
89
|
+
element.setAttribute(eventName, 'return;');
|
|
90
|
+
isSupported = typeof (element as any)[eventName] === 'function';
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
return isSupported;
|
|
94
|
+
}
|
|
95
|
+
};
|
|
96
|
+
|
|
97
|
+
export const syncEvent = (
|
|
98
|
+
node: Element & { __events?: { [key: string]: ((e: Event) => any) | undefined } },
|
|
99
|
+
eventName: string,
|
|
100
|
+
newEventHandler?: (e: Event) => any
|
|
101
|
+
) => {
|
|
102
|
+
const eventStore = node.__events || (node.__events = {});
|
|
103
|
+
const oldEventHandler = eventStore[eventName];
|
|
104
|
+
|
|
105
|
+
// Remove old listener so they don't double up.
|
|
106
|
+
if (oldEventHandler) {
|
|
107
|
+
node.removeEventListener(eventName, oldEventHandler);
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
// Bind new listener.
|
|
111
|
+
node.addEventListener(
|
|
112
|
+
eventName,
|
|
113
|
+
(eventStore[eventName] = function handler(e: Event) {
|
|
114
|
+
if (newEventHandler) {
|
|
115
|
+
newEventHandler.call(this, e);
|
|
116
|
+
}
|
|
117
|
+
})
|
|
118
|
+
);
|
|
119
|
+
};
|
|
120
|
+
|
|
121
|
+
const arrayToMap = (arr: string[] | DOMTokenList) => {
|
|
122
|
+
const map = new Map<string, string>();
|
|
123
|
+
(arr as string[]).forEach((s: string) => map.set(s, s));
|
|
124
|
+
return map;
|
|
125
|
+
};
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export const dashToPascalCase = (str: string) =>
|
|
2
|
+
str
|
|
3
|
+
.toLowerCase()
|
|
4
|
+
.split('-')
|
|
5
|
+
.map((segment) => segment.charAt(0).toUpperCase() + segment.slice(1))
|
|
6
|
+
.join('');
|
|
7
|
+
export const camelToDashCase = (str: string) => str.replace(/([A-Z])/g, (m: string) => `-${m[0].toLowerCase()}`);
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
export const isDevMode = () => {
|
|
2
|
+
return process && process.env && process.env.NODE_ENV === 'development';
|
|
3
|
+
};
|
|
4
|
+
|
|
5
|
+
const warnings: { [key: string]: boolean } = {};
|
|
6
|
+
|
|
7
|
+
export const deprecationWarning = (key: string, message: string) => {
|
|
8
|
+
if (isDevMode()) {
|
|
9
|
+
if (!warnings[key]) {
|
|
10
|
+
console.warn(message);
|
|
11
|
+
warnings[key] = true;
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
};
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
|
|
3
|
+
import type { StyleReactProps } from '../interfaces';
|
|
4
|
+
|
|
5
|
+
export type StencilReactExternalProps<PropType, ElementType> = PropType &
|
|
6
|
+
Omit<React.HTMLAttributes<ElementType>, 'style'> &
|
|
7
|
+
StyleReactProps;
|
|
8
|
+
|
|
9
|
+
// This will be replaced with React.ForwardedRef when react-output-target is upgraded to React v17
|
|
10
|
+
export type StencilReactForwardedRef<T> = ((instance: T | null) => void) | React.MutableRefObject<T | null> | null;
|
|
11
|
+
|
|
12
|
+
export const setRef = (ref: StencilReactForwardedRef<any> | React.Ref<any> | undefined, value: any) => {
|
|
13
|
+
if (typeof ref === 'function') {
|
|
14
|
+
ref(value);
|
|
15
|
+
} else if (ref != null) {
|
|
16
|
+
// Cast as a MutableRef so we can assign current
|
|
17
|
+
(ref as React.MutableRefObject<any>).current = value;
|
|
18
|
+
}
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
export const mergeRefs = (
|
|
22
|
+
...refs: (StencilReactForwardedRef<any> | React.Ref<any> | undefined)[]
|
|
23
|
+
): React.RefCallback<any> => {
|
|
24
|
+
return (value: any) => {
|
|
25
|
+
refs.forEach((ref) => {
|
|
26
|
+
setRef(ref, value);
|
|
27
|
+
});
|
|
28
|
+
};
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
export const createForwardRef = <PropType, ElementType>(ReactComponent: any, displayName: string) => {
|
|
32
|
+
const forwardRef = (
|
|
33
|
+
props: StencilReactExternalProps<PropType, ElementType>,
|
|
34
|
+
ref: StencilReactForwardedRef<ElementType>
|
|
35
|
+
) => {
|
|
36
|
+
return <ReactComponent {...props} forwardedRef={ref} />;
|
|
37
|
+
};
|
|
38
|
+
forwardRef.displayName = displayName;
|
|
39
|
+
|
|
40
|
+
return React.forwardRef(forwardRef);
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
export const defineCustomElement = (tagName: string, customElement: any) => {
|
|
44
|
+
if (customElement !== undefined && typeof customElements !== 'undefined' && !customElements.get(tagName)) {
|
|
45
|
+
customElements.define(tagName, customElement);
|
|
46
|
+
}
|
|
47
|
+
};
|
|
48
|
+
|
|
49
|
+
export * from './attachProps';
|
|
50
|
+
export * from './case';
|
package/lib/index.ts
CHANGED
|
@@ -3,7 +3,6 @@ export { defineCustomElements } from "ai12z/loader"
|
|
|
3
3
|
import { Ai12zBot, Ai12zCta, Ai12zKnowledgeBox } from "./components/stencil-generated"
|
|
4
4
|
import packageJson from "../package.json" // Adjust path as needed
|
|
5
5
|
|
|
6
|
-
// console.log(`Package version: ${packageJson.version}`)
|
|
7
6
|
Ai12zBot.defaultProps = { assetPath: `https://unpkg.com/@ai12z/react@${packageJson.version}/dist/build/assets` }
|
|
8
7
|
Ai12zCta.defaultProps = { assetPath: `https://unpkg.com/@ai12z/react@${packageJson.version}/dist/build/assets` }
|
|
9
8
|
// Ai12zKnowledgeBox.defaultProps = { assetPath: `https://unpkg.com/@ai12z/react@${packageJson.version}/dist/build/assets` }
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ai12z/react",
|
|
3
|
-
"version": "2.0.3
|
|
3
|
+
"version": "2.0.3",
|
|
4
4
|
"description": "ai12z React Library",
|
|
5
5
|
"author": "Alpesh Patel <alpesh@ai12z.com>",
|
|
6
6
|
"homepage": "",
|
|
@@ -22,7 +22,7 @@
|
|
|
22
22
|
"tsc": "tsc -p . --outDir ./dist"
|
|
23
23
|
},
|
|
24
24
|
"dependencies": {
|
|
25
|
-
"ai12z": "^2.0.3
|
|
25
|
+
"ai12z": "^2.0.3"
|
|
26
26
|
},
|
|
27
27
|
"devDependencies": {
|
|
28
28
|
"@types/react": "^18.2.55",
|
|
@@ -33,5 +33,5 @@
|
|
|
33
33
|
"publishConfig": {
|
|
34
34
|
"access": "public"
|
|
35
35
|
},
|
|
36
|
-
"gitHead": "
|
|
36
|
+
"gitHead": "8bf0e07332cbea16c79367fb2cf28b14bea49f1c"
|
|
37
37
|
}
|