Merge branch 'feat/plugins' of github.com:langgenius/dify into feat/plugins

pull/9940/head
Yi 2 years ago
commit 0e52971997

@ -1,19 +1,19 @@
import type { StorybookConfig } from '@storybook/nextjs' import type { StorybookConfig } from '@storybook/nextjs'
const config: StorybookConfig = { const config: StorybookConfig = {
// stories: ['../stories/**/*.mdx', '../stories/**/*.stories.@(js|jsx|mjs|ts|tsx)'], // stories: ['../stories/**/*.mdx', '../stories/**/*.stories.@(js|jsx|mjs|ts|tsx)'],
stories: ['../app/components/**/*.stories.@(js|jsx|mjs|ts|tsx)'], stories: ['../app/components/**/*.stories.@(js|jsx|mjs|ts|tsx)'],
addons: [ addons: [
'@storybook/addon-onboarding', '@storybook/addon-onboarding',
'@storybook/addon-links', '@storybook/addon-links',
'@storybook/addon-essentials', '@storybook/addon-essentials',
'@chromatic-com/storybook', '@chromatic-com/storybook',
'@storybook/addon-interactions', '@storybook/addon-interactions',
], ],
framework: { framework: {
name: '@storybook/nextjs', name: '@storybook/nextjs',
options: {}, options: {},
}, },
staticDirs: ['../public'], staticDirs: ['../public'],
} }
export default config export default config

@ -8,30 +8,30 @@ import '../app/styles/markdown.scss'
import './storybook.css' import './storybook.css'
export const decorators = [ export const decorators = [
withThemeByDataAttribute({ withThemeByDataAttribute({
themes: { themes: {
light: 'light', light: 'light',
dark: 'dark', dark: 'dark',
}, },
defaultTheme: 'light', defaultTheme: 'light',
attributeName: 'data-theme', attributeName: 'data-theme',
}), }),
(Story) => { (Story) => {
return <I18nServer> return <I18nServer>
<Story /> <Story />
</I18nServer> </I18nServer>
} },
] ]
const preview: Preview = { const preview: Preview = {
parameters: { parameters: {
controls: { controls: {
matchers: { matchers: {
color: /(background|color)$/i, color: /(background|color)$/i,
date: /Date$/i, date: /Date$/i,
}, },
},
}, },
},
} }
export default preview export default preview

@ -21,5 +21,6 @@
"editor.defaultFormatter": "vscode.json-language-features" "editor.defaultFormatter": "vscode.json-language-features"
}, },
"typescript.tsdk": "node_modules/typescript/lib", "typescript.tsdk": "node_modules/typescript/lib",
"typescript.enablePromptUseWorkspaceTsdk": true "typescript.enablePromptUseWorkspaceTsdk": true,
"npm.packageManager": "pnpm"
} }

@ -216,8 +216,8 @@ const Chart: React.FC<IChartProps> = ({
return `<div style='color:#6B7280;font-size:12px'>${params.name}</div> return `<div style='color:#6B7280;font-size:12px'>${params.name}</div>
<div style='font-size:14px;color:#1F2A37'>${valueFormatter((params.data as any)[yField])} <div style='font-size:14px;color:#1F2A37'>${valueFormatter((params.data as any)[yField])}
${!CHART_TYPE_CONFIG[chartType].showTokens ${!CHART_TYPE_CONFIG[chartType].showTokens
? '' ? ''
: `<span style='font-size:12px'> : `<span style='font-size:12px'>
<span style='margin-left:4px;color:#6B7280'>(</span> <span style='margin-left:4px;color:#6B7280'>(</span>
<span style='color:#FF8A4C'>~$${get(params.data, 'total_price', 0)}</span> <span style='color:#FF8A4C'>~$${get(params.data, 'total_price', 0)}</span>
<span style='color:#6B7280'>)</span> <span style='color:#6B7280'>)</span>
@ -243,7 +243,7 @@ const Chart: React.FC<IChartProps> = ({
? '' ? ''
: <span>{t('appOverview.analysis.tokenUsage.consumed')} Tokens<span className='text-sm'> : <span>{t('appOverview.analysis.tokenUsage.consumed')} Tokens<span className='text-sm'>
<span className='ml-1 text-gray-500'>(</span> <span className='ml-1 text-gray-500'>(</span>
<span className='text-orange-400'>~{sum(statistics.map(item => parseFloat(get(item, 'total_price', '0')))).toLocaleString('en-US', { style: 'currency', currency: 'USD', minimumFractionDigits: 4 })}</span> <span className='text-orange-400'>~{sum(statistics.map(item => Number.parseFloat(get(item, 'total_price', '0')))).toLocaleString('en-US', { style: 'currency', currency: 'USD', minimumFractionDigits: 4 })}</span>
<span className='text-gray-500'>)</span> <span className='text-gray-500'>)</span>
</span></span>} </span></span>}
textStyle={{ main: `!text-3xl !font-normal ${sumData === 0 ? '!text-gray-300' : ''}` }} /> textStyle={{ main: `!text-3xl !font-normal ${sumData === 0 ? '!text-gray-300' : ''}` }} />

@ -35,12 +35,12 @@ const OPTION_MAP = {
`<script> `<script>
window.difyChatbotConfig = { window.difyChatbotConfig = {
token: '${token}'${isTestEnv token: '${token}'${isTestEnv
? `, ? `,
isDev: true` isDev: true`
: ''}${IS_CE_EDITION : ''}${IS_CE_EDITION
? `, ? `,
baseUrl: '${url}'` baseUrl: '${url}'`
: ''} : ''}
} }
</script> </script>
<script <script

@ -106,7 +106,7 @@ export function PortalToFollowElem({
} }
export const PortalToFollowElemTrigger = React.forwardRef< export const PortalToFollowElemTrigger = React.forwardRef<
HTMLElement, HTMLElement,
React.HTMLProps<HTMLElement> & { asChild?: boolean } React.HTMLProps<HTMLElement> & { asChild?: boolean }
>(({ children, asChild = false, ...props }, propRef) => { >(({ children, asChild = false, ...props }, propRef) => {
const context = usePortalToFollowElemContext() const context = usePortalToFollowElemContext()
@ -141,8 +141,8 @@ React.HTMLProps<HTMLElement> & { asChild?: boolean }
PortalToFollowElemTrigger.displayName = 'PortalToFollowElemTrigger' PortalToFollowElemTrigger.displayName = 'PortalToFollowElemTrigger'
export const PortalToFollowElemContent = React.forwardRef< export const PortalToFollowElemContent = React.forwardRef<
HTMLDivElement, HTMLDivElement,
React.HTMLProps<HTMLDivElement> React.HTMLProps<HTMLDivElement>
>(({ style, ...props }, propRef) => { >(({ style, ...props }, propRef) => {
const context = usePortalToFollowElemContext() const context = usePortalToFollowElemContext()
const ref = useMergeRefs([context.refs.setFloating, propRef]) const ref = useMergeRefs([context.refs.setFloating, propRef])

@ -264,7 +264,7 @@ const InstallFromGitHub: React.FC<InstallFromGitHubProps> = ({ onClose }) => {
className='min-w-[72px]' className='min-w-[72px]'
onClick={onClose} onClick={onClose}
> >
Close Close
</Button> </Button>
) )
: ( : (

@ -1,7 +1,7 @@
import { import {
GLOB_JSX, GLOB_TESTS, GLOB_TSX, combine, javascript, node, GLOB_TESTS, combine, javascript, node,
stylistic, typescript, unicorn stylistic, typescript, unicorn,
} from '@antfu/eslint-config' } from '@antfu/eslint-config'
import path from 'node:path' import path from 'node:path'
import { fileURLToPath } from 'node:url' import { fileURLToPath } from 'node:url'
import js from '@eslint/js' import js from '@eslint/js'
@ -21,27 +21,27 @@ const storybook = [
{ {
plugins: ['storybook'], plugins: ['storybook'],
files: ['*.stories.@(ts|tsx|js|jsx|mjs|cjs)', '*.story.@(ts|tsx|js|jsx|mjs|cjs)'], files: ['*.stories.@(ts|tsx|js|jsx|mjs|cjs)', '*.story.@(ts|tsx|js|jsx|mjs|cjs)'],
rules: { rules: {
'react-hooks/rules-of-hooks': 'off', 'react-hooks/rules-of-hooks': 'off',
'import/no-anonymous-default-export': 'off', 'import/no-anonymous-default-export': 'off',
'storybook/await-interactions': 'error', 'storybook/await-interactions': 'error',
'storybook/context-in-play-function': 'error', 'storybook/context-in-play-function': 'error',
'storybook/default-exports': 'error', 'storybook/default-exports': 'error',
'storybook/hierarchy-separator': 'warn', 'storybook/hierarchy-separator': 'warn',
'storybook/no-redundant-story-name': 'warn', 'storybook/no-redundant-story-name': 'warn',
'storybook/prefer-pascal-case': 'warn', 'storybook/prefer-pascal-case': 'warn',
'storybook/story-exports': 'error', 'storybook/story-exports': 'error',
'storybook/use-storybook-expect': 'error', 'storybook/use-storybook-expect': 'error',
'storybook/use-storybook-testing-library': 'error', 'storybook/use-storybook-testing-library': 'error',
} },
}, },
{ {
plugins: ['storybook'], plugins: ['storybook'],
files: ['*.stories.@(ts|tsx|js|jsx|mjs|cjs)', '*.story.@(ts|tsx|js|jsx|mjs|cjs)'], files: ['*.stories.@(ts|tsx|js|jsx|mjs|cjs)', '*.story.@(ts|tsx|js|jsx|mjs|cjs)'],
rules: { rules: {
'storybook/no-uninstalled-addons': 'error', 'storybook/no-uninstalled-addons': 'error',
} },
} },
] ]
export default combine( export default combine(
@ -49,27 +49,41 @@ export default combine(
lessOpinionated: true, lessOpinionated: true,
// original @antfu/eslint-config does not support jsx // original @antfu/eslint-config does not support jsx
jsx: false, jsx: false,
semi: false,
quotes: 'single',
overrides: { overrides: {
// original config // original config
"style/indent": "off", 'style/indent': ['error', 2],
'style/quotes': ['error', 'single'],
'curly': ['error', 'multi-line'],
'style/comma-spacing': ['error', { before: false, after: true }],
'style/quote-props': ['warn', 'consistent-as-needed'],
// these options does not exist in old version // these options does not exist in old version
// maybe useless // maybe useless
"style/indent-binary-ops": "off", 'style/indent-binary-ops': 'off',
"style/multiline-ternary": "off", 'style/multiline-ternary': 'off',
'antfu/top-level-function': 'off',
'antfu/curly': 'off',
'antfu/consistent-chaining': 'off',
// copy from eslint-config-antfu 0.36.0
'style/brace-style': ['error', 'stroustrup', { allowSingleLine: true }],
'style/dot-location': ['error', 'property'],
'style/object-curly-newline': ['error', { consistent: true, multiline: true }],
'style/object-property-newline': ['error', { allowMultiplePropertiesPerLine: true }],
'style/template-curly-spacing': ['error', 'never'],
'style/keyword-spacing': 'off',
// not exist in old version, and big change // not exist in old version, and big change
"style/quote-props": "off", 'style/member-delimiter-style': 'off',
"style/member-delimiter-style": "off", },
"style/quotes": "off",
"style/comma-dangle": "off",
}
}), }),
typescript({ typescript({
overrides: { overrides: {
// useful, but big change // useful, but big change
"ts/no-empty-object-type": "off", 'ts/no-empty-object-type': 'off',
} },
}), }),
javascript({ javascript({
overrides: { overrides: {
@ -77,8 +91,8 @@ export default combine(
'no-unused-vars': 'off', 'no-unused-vars': 'off',
// useless // useless
'no-use-before-define': 'warn' 'no-use-before-define': 'warn',
} },
}), }),
unicorn(), unicorn(),
node(), node(),
@ -96,30 +110,36 @@ export default combine(
'**/.next/', '**/.next/',
'**/public/*', '**/public/*',
'**/*.json', '**/*.json',
] ],
}, },
{ {
// orignal config // orignal config
rules: { rules: {
// from old version of antfu/eslint-config // from old version of antfu/eslint-config
// typescript will handle this, see https://typescript-eslint.io/troubleshooting/faqs/eslint/#i-get-errors-from-the-no-undef-rule-about-global-variables-not-being-defined-even-though-there-are-no-typescript-errors // typescript will handle this, see https://typescript-eslint.io/troubleshooting/faqs/eslint/#i-get-errors-from-the-no-undef-rule-about-global-variables-not-being-defined-even-though-there-are-no-typescript-errors
"no-undef": "off", 'no-undef': 'off',
'ts/consistent-type-definitions': ['error', 'type'], 'ts/consistent-type-definitions': ['error', 'type'],
// orignal ts/no-var-requires // orignal ts/no-var-requires
'ts/no-require-imports': 'off', 'ts/no-require-imports': 'off',
"no-console": 'off', 'no-console': 'off',
"react-hooks/exhaustive-deps": "warn", 'react-hooks/exhaustive-deps': 'warn',
"react/display-name": "off", 'react/display-name': 'off',
'array-callback-return': ['error', {
allowImplicit: false,
checkForEach: false,
}],
// orignal config, but removed in new version antfu/eslint-config // copy from eslint-config-antfu 0.36.0
// big change 'camelcase': 'off',
"curly": "off", 'curly': ['error', 'multi-or-nest', 'consistent'],
'default-case-last': 'error',
'dot-notation': ['error', { allowKeywords: true }],
'new-cap': ['error', { newIsCap: true, capIsNew: false, properties: true }],
// antfu use eslint-plugin-perfectionist to replace this // antfu use eslint-plugin-perfectionist to replace this
// will cause big change, so keep the original // will cause big change, so keep the original sort-imports
// sort-imports 'sort-imports': [
"sort-imports": [
'error', 'error',
{ {
ignoreCase: false, ignoreCase: false,
@ -131,8 +151,8 @@ export default combine(
], ],
// antfu migrate to eslint-plugin-unused-imports // antfu migrate to eslint-plugin-unused-imports
"unused-imports/no-unused-vars": "warn", 'unused-imports/no-unused-vars': 'warn',
"unused-imports/no-unused-imports": "warn", 'unused-imports/no-unused-imports': 'warn',
}, },
languageOptions: { languageOptions: {
@ -140,25 +160,25 @@ export default combine(
...globals.browser, ...globals.browser,
...globals.es2025, ...globals.es2025,
...globals.node, ...globals.node,
'React': 'readable', React: 'readable',
'JSX': 'readable', JSX: 'readable',
} },
} },
}, },
storybook, storybook,
// need futher research // need futher research
{ {
rules: { rules: {
// not exist in old version // not exist in old version
"antfu/consistent-list-newline": "off", 'antfu/consistent-list-newline': 'off',
'node/prefer-global/process': 'off', 'node/prefer-global/process': 'off',
'node/prefer-global/buffer': 'off', 'node/prefer-global/buffer': 'off',
'node/no-callback-literal': 'off', 'node/no-callback-literal': 'off',
// useful, but big change // useful, but big change
"unicorn/prefer-number-properties": "warn", 'unicorn/prefer-number-properties': 'warn',
"unicorn/no-new-array": "warn" 'unicorn/no-new-array': 'warn',
} },
}, },
// suppress error for `no-undef` rule // suppress error for `no-undef` rule
{ {

@ -9,22 +9,22 @@ export type metadataType = DocType | 'originInfo' | 'technicalParameters'
type MetadataMap = type MetadataMap =
Record< Record<
metadataType, metadataType,
{
text: string
allowEdit?: boolean
icon?: React.ReactNode
iconName?: string
subFieldsMap: Record<
string,
{ {
label: string text: string
inputType?: inputType allowEdit?: boolean
field?: string icon?: React.ReactNode
render?: (value: any, total?: number) => React.ReactNode | string iconName?: string
subFieldsMap: Record<
string,
{
label: string
inputType?: inputType
field?: string
render?: (value: any, total?: number) => React.ReactNode | string
}
>
} }
>
}
> >
const fieldPrefix = 'datasetDocuments.metadata.field' const fieldPrefix = 'datasetDocuments.metadata.field'

Loading…
Cancel
Save