Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Edit Content: Explore the possibility to use web components for fields #25581

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions core-web/apps/contenttype-fields-builder-e2e/.eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"extends": ["plugin:cypress/recommended", "../../.eslintrc.json"],
"ignorePatterns": ["!**/*"],
"overrides": [
{
"files": ["*.ts", "*.tsx", "*.js", "*.jsx"],
"rules": {}
},
{
"files": ["src/plugins/index.js"],
"rules": {
"@typescript-eslint/no-var-requires": "off",
"no-undef": "off"
}
}
]
}
12 changes: 12 additions & 0 deletions core-web/apps/contenttype-fields-builder-e2e/cypress.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"fileServerFolder": ".",
"fixturesFolder": "./src/fixtures",
"integrationFolder": "./src/integration",
"modifyObstructiveCode": false,
"supportFile": "./src/support/index.ts",
"pluginsFile": "./src/plugins/index",
"video": true,
"videosFolder": "../../dist/cypress/apps/contenttype-fields-builder-e2e/videos",
"screenshotsFolder": "../../dist/cypress/apps/contenttype-fields-builder-e2e/screenshots",
"chromeWebSecurity": false
}
31 changes: 31 additions & 0 deletions core-web/apps/contenttype-fields-builder-e2e/project.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
{
"name": "contenttype-fields-builder-e2e",
"$schema": "../../node_modules/nx/schemas/project-schema.json",
"sourceRoot": "apps/contenttype-fields-builder-e2e/src",
"projectType": "application",
"targets": {
"e2e": {
"executor": "@nrwl/cypress:cypress",
"options": {
"cypressConfig": "apps/contenttype-fields-builder-e2e/cypress.json",
"devServerTarget": "contenttype-fields-builder:serve:development",
"testingType": "e2e",
"tsConfig": "apps/contenttype-fields-builder-e2e/tsconfig.json"
},
"configurations": {
"production": {
"devServerTarget": "contenttype-fields-builder:serve:production"
}
}
},
"lint": {
"executor": "@nrwl/linter:eslint",
"outputs": ["{options.outputFile}"],
"options": {
"lintFilePatterns": ["apps/contenttype-fields-builder-e2e/**/*.{js,ts}"]
}
}
},
"tags": [],
"implicitDependencies": ["contenttype-fields-builder"]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"name": "Using fixtures to represent data",
"email": "[email protected]"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { getGreeting } from '../support/app.po';

describe('contenttype-fields-builder', () => {
beforeEach(() => cy.visit('/'));

it('should display welcome message', () => {
// Custom command example, see `../support/commands.ts` file
cy.login('[email protected]', 'myPassword');

// Function helper example, see `../support/app.po.ts` file
getGreeting().contains('Welcome contenttype-fields-builder');
});
});
22 changes: 22 additions & 0 deletions core-web/apps/contenttype-fields-builder-e2e/src/plugins/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
// ***********************************************************
// This example plugins/index.js can be used to load plugins
//
// You can change the location of this file or turn off loading
// the plugins file with the 'pluginsFile' configuration option.
//
// You can read more here:
// https://on.cypress.io/plugins-guide
// ***********************************************************

// This function is called when a project is opened or re-opened (e.g. due to
// the project's config changing)

const { preprocessTypescript } = require('@nrwl/cypress/plugins/preprocessor');

module.exports = (on, config) => {
// `on` is used to hook into various events Cypress emits
// `config` is the resolved Cypress config

// Preprocess Typescript file using Nx helper
on('file:preprocessor', preprocessTypescript(config));
};
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export const getGreeting = () => cy.get('h1');
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
// ***********************************************
// This example commands.js shows you how to
// create various custom commands and overwrite
// existing commands.
//
// For more comprehensive examples of custom
// commands please read more here:
// https://on.cypress.io/custom-commands
// ***********************************************

// eslint-disable-next-line @typescript-eslint/no-namespace
declare namespace Cypress {
// eslint-disable-next-line @typescript-eslint/no-unused-vars
interface Chainable<Subject> {
login(email: string, password: string): void;
}
}
//
// -- This is a parent command --
Cypress.Commands.add('login', (email, password) => {
console.warn('Custom command example: Login', email, password);
});
//
// -- This is a child command --
// Cypress.Commands.add("drag", { prevSubject: 'element'}, (subject, options) => { ... })
//
//
// -- This is a dual command --
// Cypress.Commands.add("dismiss", { prevSubject: 'optional'}, (subject, options) => { ... })
//
//
// -- This will overwrite an existing command --
// Cypress.Commands.overwrite("visit", (originalFn, url, options) => { ... })
17 changes: 17 additions & 0 deletions core-web/apps/contenttype-fields-builder-e2e/src/support/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
// ***********************************************************
// This example support/index.ts is processed and
// loaded automatically before your test files.
//
// This is a great place to put global configuration and
// behavior that modifies Cypress.
//
// You can change the location of this file or turn off
// automatically serving support files with the
// 'supportFile' configuration option.
//
// You can read more here:
// https://on.cypress.io/configuration
// ***********************************************************

// Import commands.ts using ES2015 syntax:
import './commands';
22 changes: 22 additions & 0 deletions core-web/apps/contenttype-fields-builder-e2e/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{
"extends": "../../tsconfig.base.json",
"compilerOptions": {
"sourceMap": false,
"outDir": "../../dist/out-tsc",
"allowJs": true,
"types": ["cypress", "node"],
"forceConsistentCasingInFileNames": true,
"strict": true,
"noImplicitOverride": true,
"noPropertyAccessFromIndexSignature": true,
"noImplicitReturns": true,
"noFallthroughCasesInSwitch": true
},
"include": ["src/**/*.ts", "src/**/*.js"],
"angularCompilerOptions": {
"enableI18nLegacyMessageIdFormat": false,
"strictInjectionParameters": true,
"strictInputAccessModifiers": true,
"strictTemplates": true
}
}
36 changes: 36 additions & 0 deletions core-web/apps/contenttype-fields-builder/.eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
{
"extends": ["../../.eslintrc.json"],
"ignorePatterns": ["!**/*"],
"overrides": [
{
"files": ["*.ts"],
"rules": {
"@angular-eslint/directive-selector": [
"error",
{
"type": "attribute",
"prefix": "dotcms",
"style": "camelCase"
}
],
"@angular-eslint/component-selector": [
"error",
{
"type": "element",
"prefix": "dotcms",
"style": "kebab-case"
}
]
},
"extends": [
"plugin:@nrwl/nx/angular",
"plugin:@angular-eslint/template/process-inline-templates"
]
},
{
"files": ["*.html"],
"extends": ["plugin:@nrwl/nx/angular-template"],
"rules": {}
}
]
}
16 changes: 16 additions & 0 deletions core-web/apps/contenttype-fields-builder/karma.conf.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// Karma configuration file, see link for more information
// https://karma-runner.github.io/6.4/config/configuration-file.html

const { join } = require('path');
const getBaseKarmaConfig = require('../../karma.conf');

module.exports = function (config) {
const baseConfig = getBaseKarmaConfig();
config.set({
...baseConfig,
coverageReporter: {
...baseConfig.coverageReporter,
dir: join(__dirname, '../../coverage/apps/contenttype-fields-builder')
}
});
};
101 changes: 101 additions & 0 deletions core-web/apps/contenttype-fields-builder/project.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
{
"name": "contenttype-fields-builder",
"$schema": "../node_modules/nx/schemas/project-schema.json",
"projectType": "application",
"sourceRoot": "apps/contenttype-fields-builder/src",
"prefix": "dotcms",
"targets": {
"build": {
"executor": "@angular-devkit/build-angular:browser",
"outputs": ["{options.outputPath}"],
"options": {
"outputPath": "dist/apps/contenttype-fields-builder",
"index": "apps/contenttype-fields-builder/src/index.html",
"main": "apps/contenttype-fields-builder/src/main.ts",
"polyfills": ["zone.js"],
"tsConfig": "apps/contenttype-fields-builder/tsconfig.app.json",
"inlineStyleLanguage": "scss",
"assets": [
"apps/contenttype-fields-builder/src/favicon.ico",
"apps/contenttype-fields-builder/src/assets"
],
"styles": ["apps/contenttype-fields-builder/src/styles.scss"],
"stylePreprocessorOptions": {
"includePaths": ["libs/dotcms-scss/angular"]
},
"scripts": [
{
"bundleName": "generator-runtime",
"input": "node_modules/regenerator-runtime/runtime.js"
}
]
},
"configurations": {
"production": {
"budgets": [
{
"type": "initial",
"maximumWarning": "500kb",
"maximumError": "1mb"
},
{
"type": "anyComponentStyle",
"maximumWarning": "2kb",
"maximumError": "1mb"
}
],
"outputHashing": "all"
},
"development": {
"buildOptimizer": false,
"optimization": false,
"vendorChunk": true,
"extractLicenses": false,
"sourceMap": true,
"namedChunks": true
}
},
"defaultConfiguration": "production"
},
"serve": {
"executor": "@angular-devkit/build-angular:dev-server",
"configurations": {
"production": {
"browserTarget": "contenttype-fields-builder:build:production"
},
"development": {
"browserTarget": "contenttype-fields-builder:build:development"
}
},
"defaultConfiguration": "development"
},
"extract-i18n": {
"executor": "@angular-devkit/build-angular:extract-i18n",
"options": {
"browserTarget": "contenttype-fields-builder:build"
}
},
"lint": {
"executor": "@nrwl/linter:eslint",
"outputs": ["{options.outputFile}"],
"options": {
"lintFilePatterns": [
"apps/contenttype-fields-builder/**/*.ts",
"apps/contenttype-fields-builder/**/*.html"
]
}
},
"test": {
"executor": "@angular-devkit/build-angular:karma",
"options": {
"tsConfig": "apps/contenttype-fields-builder/tsconfig.spec.json",
"karmaConfig": "apps/contenttype-fields-builder/karma.conf.js",
"polyfills": ["zone.js", "zone.js/testing"],
"styles": [],
"scripts": [],
"assets": []
}
}
},
"tags": []
}
42 changes: 42 additions & 0 deletions core-web/apps/contenttype-fields-builder/src/app/app.module.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import { DoBootstrap, Injector, NgModule } from '@angular/core';
import { createCustomElement } from '@angular/elements';
import { BrowserModule } from '@angular/platform-browser';

import { ContenttypeFieldsModule, InputFieldComponent } from '@dotcms/contenttype-fields';

const CUSTOM_ELEMENTS = [
{
tag: 'custom-input-field',
component: InputFieldComponent
}
];

@NgModule({
declarations: [],
imports: [BrowserModule, ContenttypeFieldsModule],
providers: []
})
export class AppModule implements DoBootstrap {
constructor(private readonly injector: Injector) {}

ngDoBootstrap(): void {
try {
CUSTOM_ELEMENTS.forEach(({ tag, component }) => {
// prevent 'has already been defined as a custom element' error
if (customElements.get(tag)) {
return;
}

// create custom elements from angular components
const el = createCustomElement(component, {
injector: this.injector
});

// define in browser registry
customElements.define(tag, el);
});
} catch (err) {
console.error(err);
}
}
}
Empty file.
Binary file not shown.
11 changes: 11 additions & 0 deletions core-web/apps/contenttype-fields-builder/src/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<title>Contenttype Fields Builder</title>
<base href="/" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<link rel="icon" type="image/x-icon" href="favicon.ico" />
</head>
<body></body>
</html>
Loading