mirror of
https://github.com/ionic-team/ionic-framework.git
synced 2026-03-13 10:22:08 +08:00
chore(react): adding prettier and formating files
This commit is contained in:
@@ -9,8 +9,15 @@ export const attachProps = (node: HTMLElement, newProps: any, oldProps: any = {}
|
||||
node.className = className;
|
||||
}
|
||||
|
||||
Object.keys(newProps).forEach(name => {
|
||||
if (name === 'children' || name === 'style' || name === 'ref' || name === 'class' || name === 'className' || name === 'forwardedRef') {
|
||||
Object.keys(newProps).forEach((name) => {
|
||||
if (
|
||||
name === 'children' ||
|
||||
name === 'style' ||
|
||||
name === 'ref' ||
|
||||
name === 'class' ||
|
||||
name === 'className' ||
|
||||
name === 'forwardedRef'
|
||||
) {
|
||||
return;
|
||||
}
|
||||
if (name.indexOf('on') === 0 && name[2] === name[2].toUpperCase()) {
|
||||
@@ -42,7 +49,7 @@ export const getClassName = (classList: DOMTokenList, newProps: any, oldProps: a
|
||||
const finalClassNames: string[] = [];
|
||||
// loop through each of the current classes on the component
|
||||
// to see if it should be a part of the classNames added
|
||||
currentClasses.forEach(currentClass => {
|
||||
currentClasses.forEach((currentClass) => {
|
||||
if (incomingPropClasses.has(currentClass)) {
|
||||
// add it as its already included in classnames coming in from newProps
|
||||
finalClassNames.push(currentClass);
|
||||
@@ -52,7 +59,7 @@ export const getClassName = (classList: DOMTokenList, newProps: any, oldProps: a
|
||||
finalClassNames.push(currentClass);
|
||||
}
|
||||
});
|
||||
incomingPropClasses.forEach(s => finalClassNames.push(s));
|
||||
incomingPropClasses.forEach((s) => finalClassNames.push(s));
|
||||
return finalClassNames.join(' ');
|
||||
};
|
||||
|
||||
@@ -77,7 +84,11 @@ export const isCoveredByReact = (eventNameSuffix: string) => {
|
||||
}
|
||||
};
|
||||
|
||||
export const syncEvent = (node: Element & { __events?: { [key: string]: ((e: Event) => any) | undefined; }; }, eventName: string, newEventHandler?: (e: Event) => any) => {
|
||||
export const syncEvent = (
|
||||
node: Element & { __events?: { [key: string]: ((e: Event) => any) | undefined } },
|
||||
eventName: string,
|
||||
newEventHandler?: (e: Event) => any
|
||||
) => {
|
||||
const eventStore = node.__events || (node.__events = {});
|
||||
const oldEventHandler = eventStore[eventName];
|
||||
|
||||
@@ -87,9 +98,14 @@ export const syncEvent = (node: Element & { __events?: { [key: string]: ((e: Eve
|
||||
}
|
||||
|
||||
// Bind new listener.
|
||||
node.addEventListener(eventName, eventStore[eventName] = function handler(e: Event) {
|
||||
if (newEventHandler) { newEventHandler.call(this, e); }
|
||||
});
|
||||
node.addEventListener(
|
||||
eventName,
|
||||
(eventStore[eventName] = function handler(e: Event) {
|
||||
if (newEventHandler) {
|
||||
newEventHandler.call(this, e);
|
||||
}
|
||||
})
|
||||
);
|
||||
};
|
||||
|
||||
const arrayToMap = (arr: string[] | DOMTokenList) => {
|
||||
|
||||
@@ -1,2 +1,8 @@
|
||||
export const dashToPascalCase = (str: string) => str.toLowerCase().split('-').map(segment => segment.charAt(0).toUpperCase() + segment.slice(1)).join('');
|
||||
export const camelToDashCase = (str: string) => str.replace(/([A-Z])/g, (m: string) => `-${m[0].toLowerCase()}`);
|
||||
export const dashToPascalCase = (str: string) =>
|
||||
str
|
||||
.toLowerCase()
|
||||
.split('-')
|
||||
.map((segment) => segment.charAt(0).toUpperCase() + segment.slice(1))
|
||||
.join('');
|
||||
export const camelToDashCase = (str: string) =>
|
||||
str.replace(/([A-Z])/g, (m: string) => `-${m[0].toLowerCase()}`);
|
||||
|
||||
@@ -1,12 +1,25 @@
|
||||
import { Config as CoreConfig, Platforms, getPlatforms as getPlatformsCore, isPlatform as isPlatformCore } from '@ionic/core';
|
||||
import {
|
||||
Config as CoreConfig,
|
||||
Platforms,
|
||||
getPlatforms as getPlatformsCore,
|
||||
isPlatform as isPlatformCore,
|
||||
} from '@ionic/core';
|
||||
import React from 'react';
|
||||
|
||||
import { IonicReactProps } from '../IonicReactProps';
|
||||
|
||||
export type IonicReactExternalProps<PropType, ElementType> = PropType & Omit<React.HTMLAttributes<ElementType>, 'style'> & IonicReactProps;
|
||||
export type IonicReactExternalProps<PropType, ElementType> = PropType &
|
||||
Omit<React.HTMLAttributes<ElementType>, 'style'> &
|
||||
IonicReactProps;
|
||||
|
||||
export const createForwardRef = <PropType, ElementType>(ReactComponent: any, displayName: string) => {
|
||||
const forwardRef = (props: IonicReactExternalProps<PropType, ElementType>, ref: React.Ref<ElementType>) => {
|
||||
export const createForwardRef = <PropType, ElementType>(
|
||||
ReactComponent: any,
|
||||
displayName: string
|
||||
) => {
|
||||
const forwardRef = (
|
||||
props: IonicReactExternalProps<PropType, ElementType>,
|
||||
ref: React.Ref<ElementType>
|
||||
) => {
|
||||
return <ReactComponent {...props} forwardedRef={ref} />;
|
||||
};
|
||||
forwardRef.displayName = displayName;
|
||||
|
||||
@@ -1,36 +1,43 @@
|
||||
import { SerializeDocumentOptions, renderToString } from '@ionic/core/hydrate';
|
||||
|
||||
export async function ionRenderToString(html: string, userAgent: string, options: SerializeDocumentOptions = {}) {
|
||||
export async function ionRenderToString(
|
||||
html: string,
|
||||
userAgent: string,
|
||||
options: SerializeDocumentOptions = {}
|
||||
) {
|
||||
const renderToStringOptions = Object.assign(
|
||||
{},
|
||||
{
|
||||
clientHydrateAnnotations: false,
|
||||
excludeComponents: [
|
||||
// overlays
|
||||
'ion-action-sheet',
|
||||
'ion-alert',
|
||||
'ion-loading',
|
||||
'ion-modal',
|
||||
'ion-picker',
|
||||
'ion-popover',
|
||||
'ion-toast',
|
||||
|
||||
const renderToStringOptions = Object.assign({}, {
|
||||
clientHydrateAnnotations: false,
|
||||
excludeComponents: [
|
||||
// overlays
|
||||
'ion-action-sheet',
|
||||
'ion-alert',
|
||||
'ion-loading',
|
||||
'ion-modal',
|
||||
'ion-picker',
|
||||
'ion-popover',
|
||||
'ion-toast',
|
||||
// navigation
|
||||
'ion-router',
|
||||
'ion-route',
|
||||
'ion-route-redirect',
|
||||
'ion-router-link',
|
||||
'ion-router-outlet',
|
||||
|
||||
// navigation
|
||||
'ion-router',
|
||||
'ion-route',
|
||||
'ion-route-redirect',
|
||||
'ion-router-link',
|
||||
'ion-router-outlet',
|
||||
// tabs
|
||||
'ion-tabs',
|
||||
'ion-tab',
|
||||
|
||||
// tabs
|
||||
'ion-tabs',
|
||||
'ion-tab',
|
||||
|
||||
// auxiliary
|
||||
'ion-picker-column',
|
||||
'ion-virtual-scroll'
|
||||
],
|
||||
userAgent
|
||||
}, options);
|
||||
// auxiliary
|
||||
'ion-picker-column',
|
||||
'ion-virtual-scroll',
|
||||
],
|
||||
userAgent,
|
||||
},
|
||||
options
|
||||
);
|
||||
|
||||
const ionHtml = await renderToString(html, renderToStringOptions);
|
||||
return ionHtml.html;
|
||||
|
||||
Reference in New Issue
Block a user