Skip to content

Commit

Permalink
merged changes from the main branch
Browse files Browse the repository at this point in the history
  • Loading branch information
ValeriaMaltseva committed Jan 8, 2025
2 parents a2ad250 + 688dbe6 commit 4df58e2
Show file tree
Hide file tree
Showing 576 changed files with 13,243 additions and 1,894 deletions.
2 changes: 1 addition & 1 deletion assets/.storybook/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ const config: StorybookConfig = {

reactDocgenTypescriptOptions: {
propFilter: (prop: any) => {
const res = /antd/.test(prop.parent?.fileName) || !/node_modules/.test(prop.parent?.fileName);
const res = /antd|rc-image/.test(prop.parent?.fileName) || !/node_modules/.test(prop.parent?.fileName);
return prop.parent ? res : true;
},
shouldExtractLiteralValuesFromEnum: true,
Expand Down
2 changes: 2 additions & 0 deletions assets/.storybook/preview.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,8 @@ const preview: Preview = {
)
}
],

tags: ['autodocs']
};

export default preview;
3 changes: 3 additions & 0 deletions assets/build/api/openapi-config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,9 @@ const config: ConfigFile = {
'../../js/src/core/modules/auth/user/user-api-slice.gen.ts': {
filterEndpoints: pathMatcher(/user/i)
},
'../../js/src/core/modules/user/user-api-slice.gen.ts': {
filterEndpoints: pathMatcher(/user/i)
},
'../../js/src/core/modules/element/editor/shared-tab-manager/tabs/versions/version-api-slice.gen.ts': {
filterEndpoints: pathMatcher(/version/i)
},
Expand Down
141 changes: 141 additions & 0 deletions assets/build/generate-icon-index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,141 @@
/**
* Pimcore
*
* This source file is available under two different licenses:
* - Pimcore Open Core License (POCL)
* - Pimcore Commercial License (PCL)
* Full copyright and license information is available in
* LICENSE.md which is distributed with this source code.
*
* @copyright Copyright (c) Pimcore GmbH (http://www.pimcore.org)
* @license https://github.com/pimcore/studio-ui-bundle/blob/1.x/LICENSE.md POCL and PCL
*
* HOW TO USE:
* 1. Place all the SVG files in the folder `./js/src/core/assets/icons`
* 2. Please remove any duplicates and add SVG file names that use a protected word to the `protectedNames` array,
* the script will append 'Icon' to the variable name.
* 3. Run the script using `npm run generate-icons`
* 4. The script will generate/replace the index file at `./js/src/core/modules/icon-library/index.ts`
* 5. The script will also update the SVG files to use `currentColor` as the stroke color or fill color (if stroke does not exist in the file).
*/

import * as fs from 'fs';
import * as path from 'path';

const SVG_FOLDER = path.resolve('./js/src/core/assets/icons');
const OUTPUT_FILE = path.resolve('./js/src/core/modules/icon-library/index.ts');
const protectedNames = new Set(['new', 'package', 'import', 'export']);

if (!fs.existsSync(SVG_FOLDER)) {
console.error(`Error: Directory ${SVG_FOLDER} does not exist.`);
process.exit(1);
}

const files: string[] = fs.readdirSync(SVG_FOLDER as string).filter(file => file.endsWith('.inline.svg'));

if (files.length === 0) {
console.log(`No SVG files found in ${SVG_FOLDER}`);
process.exit(0);
}

const generateVariableName = (fileName: string): string => {
const baseName = fileName.replace('.inline.svg', '');
let variableName = baseName
.replace(/[-_\s]+(.)?/g, (_, letter) => letter ? letter.toUpperCase() : '')
.replace(/^./, str => str.toLowerCase());

if (protectedNames.has(variableName)) {
variableName += 'Icon';
}

return variableName;
};

const generateIconEntry = (fileName: string): string => {
const iconName = fileName.replace('.inline.svg', '');

const variableName = generateVariableName(fileName)
return `
iconLibrary.register({
name: '${iconName}',
component: ${variableName}
});`;
};

const modifySvgAttributes = (filePath: string): void => {
let svgContent: string = fs.readFileSync(filePath, 'utf-8');
const hasStroke = /stroke="[^"]*"/.test(svgContent);

if (!hasStroke) {
svgContent = svgContent.replace(/fill="[^"]*"/g, 'fill="currentColor"');
}

svgContent = svgContent.replace(/stroke="[^"]*"/g, 'stroke="currentColor"');

fs.writeFileSync(filePath, svgContent, 'utf-8');
};

const variableNameSet = new Set<string>();
files.forEach(file => {
const variableName = generateVariableName(file);

if (variableNameSet.has(variableName)) {
console.error(`Error: Duplicate SVG file detected with variable name '${variableName}'. File: '${file}'`);
process.exit(1);
}

variableNameSet.add(variableName);
});

let content = `
/**
* Pimcore
*
* This source file is available under two different licenses:
* - Pimcore Open Core License (POCL)
* - Pimcore Commercial License (PCL)
* Full copyright and license information is available in
* LICENSE.md which is distributed with this source code.
*
* @copyright Copyright (c) Pimcore GmbH
* @license https://github.com/pimcore/studio-ui-bundle/blob/1.x/LICENSE.md POCL and PCL
*/
/* eslint-disable max-lines */
import { container } from '@Pimcore/app/depency-injection';
import { moduleSystem } from '@Pimcore/app/module-system/module-system';
import { serviceIds } from '@Pimcore/app/config/services/service-ids';
import { type IconLibrary } from './services/icon-library';
`;

files.forEach((file: string) => {
const filePath: string = path.join(SVG_FOLDER as string, file);
modifySvgAttributes(filePath);

const variableName: string = generateVariableName(file);
content += `
import ${variableName} from '@Pimcore/assets/icons/${file}';`;
});

content += `
moduleSystem.registerModule({
onInit: () => {
const iconLibrary = container.get<IconLibrary>(serviceIds.iconLibrary);`;

files.forEach(file => {
content += generateIconEntry(file);
});

content += `
}
});
`;

try {
fs.writeFileSync(OUTPUT_FILE, content.trim());
console.log(`Index file generated successfully at: ${OUTPUT_FILE}`);
} catch (error) {
console.error('Error generating the index file:', error);
}
2 changes: 2 additions & 0 deletions assets/js/src/core/app/config/services/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ import { DynamicTypeObjectDataLastname } from '@Pimcore/modules/element/dynamic-
import { DynamicTypeObjectDataEmail } from '@Pimcore/modules/element/dynamic-types/defintinitions/objects/data-related/types/dynamic-type-object-data-email'
import { DynamicTypeObjectDataGender } from '@Pimcore/modules/element/dynamic-types/defintinitions/objects/data-related/types/dynamic-type-object-data-gender'
import { DynamicTypeObjectDataRgbaColor } from '@Pimcore/modules/element/dynamic-types/defintinitions/objects/data-related/types/dynamic-type-object-data-rgba-color'
import { DynamicTypeObjectDataEncryptedField } from '@Pimcore/modules/element/dynamic-types/defintinitions/objects/data-related/types/dynamic-type-object-data-encrypted-field'
import { DynamicTypeObjectDataCheckbox } from '@Pimcore/modules/element/dynamic-types/defintinitions/objects/data-related/types/dynamic-type-object-data-checkbox'
import { DynamicTypeObjectDataUrlSlug } from '@Pimcore/modules/element/dynamic-types/defintinitions/objects/data-related/types/dynamic-type-object-data-url-slug'
import { DynamicTypeObjectDataDate } from '@Pimcore/modules/element/dynamic-types/defintinitions/objects/data-related/types/dynamic-type-object-data-date'
Expand Down Expand Up @@ -245,6 +246,7 @@ container.bind(serviceIds['DynamicTypes/ObjectData/Lastname']).to(DynamicTypeObj
container.bind(serviceIds['DynamicTypes/ObjectData/Email']).to(DynamicTypeObjectDataEmail).inSingletonScope()
container.bind(serviceIds['DynamicTypes/ObjectData/Gender']).to(DynamicTypeObjectDataGender).inSingletonScope()
container.bind(serviceIds['DynamicTypes/ObjectData/RgbaColor']).to(DynamicTypeObjectDataRgbaColor).inSingletonScope()
container.bind(serviceIds['DynamicTypes/ObjectData/EncryptedField']).to(DynamicTypeObjectDataEncryptedField).inSingletonScope()
container.bind(serviceIds['DynamicTypes/ObjectData/Checkbox']).to(DynamicTypeObjectDataCheckbox).inSingletonScope()
container.bind(serviceIds['DynamicTypes/ObjectData/UrlSlug']).to(DynamicTypeObjectDataUrlSlug).inSingletonScope()
container.bind(serviceIds['DynamicTypes/ObjectData/Date']).to(DynamicTypeObjectDataDate).inSingletonScope()
Expand Down
1 change: 1 addition & 0 deletions assets/js/src/core/app/config/services/service-ids.ts
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,7 @@ export const serviceIds = {
'DynamicTypes/ObjectData/Email': 'DynamicTypes/ObjectData/Email',
'DynamicTypes/ObjectData/Gender': 'DynamicTypes/ObjectData/Gender',
'DynamicTypes/ObjectData/RgbaColor': 'DynamicTypes/ObjectData/RgbaColor',
'DynamicTypes/ObjectData/EncryptedField': 'DynamicTypes/ObjectData/EncryptedField',
'DynamicTypes/ObjectData/Checkbox': 'DynamicTypes/ObjectData/Checkbox',
'DynamicTypes/ObjectData/UrlSlug': 'DynamicTypes/ObjectData/UrlSlug',
'DynamicTypes/ObjectData/Date': 'DynamicTypes/ObjectData/Date',
Expand Down
8 changes: 4 additions & 4 deletions assets/js/src/core/app/plugin-system/plugin-system.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,17 @@ import { container } from '@Pimcore/app/depency-injection'
import { type Container } from 'inversify'
import { moduleSystem } from '../module-system/module-system'

export interface lifeCycleEvents {
export interface ILifeCycleEvents {
onInit?: (config: { container: Container }) => void
onStartup?: (config: { moduleSystem: typeof moduleSystem }) => void
}

export interface abstractPlugin extends lifeCycleEvents {
export interface IAbstractPlugin extends ILifeCycleEvents {
name: string
}

export class PluginSystem {
private registry: Record<string, abstractPlugin> = {}
private registry: Record<string, IAbstractPlugin> = {}

async loadPlugins (): Promise<void> {
const promises: any[] = []
Expand All @@ -48,7 +48,7 @@ export class PluginSystem {
await Promise.allSettled(promises)
}

registerPlugin (plugin: abstractPlugin): void {
registerPlugin (plugin: IAbstractPlugin): void {
this.registry[plugin.name] = plugin
}

Expand Down
12 changes: 8 additions & 4 deletions assets/js/src/core/app/store/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,11 @@ const slices: AnySliceLike[] = [
pimcoreApi
]

export let rootReducer = combineSlices({}, ...slices).withLazyLoadedSlices<LazyloadedSlices>()
const createRootReducer = (): CombinedSliceReducer<Record<string, any>, Record<string, any>> => {
return combineSlices({}, ...slices).withLazyLoadedSlices<LazyloadedSlices>()
}

export const rootReducer = createRootReducer()

export const store = configureStore({
reducer: rootReducer,
Expand All @@ -47,10 +51,10 @@ export const store = configureStore({
export const injectSliceWithState = (newSlice: AnySliceLike): CombinedSliceReducer<Record<string, any>, Record<string, any>> => {
slices.push(newSlice)

rootReducer = combineSlices({}, ...slices).withLazyLoadedSlices<LazyloadedSlices>()
store.replaceReducer(rootReducer)
const updatedRootReducer = createRootReducer()
store.replaceReducer(updatedRootReducer)

return rootReducer
return updatedRootReducer
}

export type AppStore = typeof store
Expand Down
3 changes: 0 additions & 3 deletions assets/js/src/core/assets/icons/AppstoreOutlined.inline.svg

This file was deleted.

5 changes: 0 additions & 5 deletions assets/js/src/core/assets/icons/DeleteOutlined.inline.svg

This file was deleted.

5 changes: 0 additions & 5 deletions assets/js/src/core/assets/icons/FileOutlined.inline.svg

This file was deleted.

8 changes: 0 additions & 8 deletions assets/js/src/core/assets/icons/PlusOutlined.inline.svg

This file was deleted.

5 changes: 0 additions & 5 deletions assets/js/src/core/assets/icons/ShopOutlined.inline.svg

This file was deleted.

This file was deleted.

5 changes: 0 additions & 5 deletions assets/js/src/core/assets/icons/ToolOutlined.inline.svg

This file was deleted.

Loading

0 comments on commit 4df58e2

Please sign in to comment.