diff --git a/.devcontainer/Dockerfile b/.devcontainer/Dockerfile deleted file mode 100644 index e99b43cb38..0000000000 --- a/.devcontainer/Dockerfile +++ /dev/null @@ -1,19 +0,0 @@ -# See here for image contents: https://github.com/microsoft/vscode-dev-containers/tree/v0.191.1/containers/javascript-node/.devcontainer/base.Dockerfile - -# [Choice] Node.js version: 18 -ARG VARIANT="18" -FROM mcr.microsoft.com/vscode/devcontainers/javascript-node:1-${VARIANT} - -# Install chromium and point the CHROME_BIN environment variable to it -# This allows running angular-material's tests in the dev container -RUN apt-get update && export DEBIAN_FRONTEND=noninteractive \ - && apt-get -y install --no-install-recommends chromium -ENV CHROME_BIN=/usr/bin/chromium - -# [Optional] Uncomment if you want to install an additional version of node using nvm -# ARG EXTRA_NODE_VERSION=10 -# RUN su node -c "source /usr/local/share/nvm/nvm.sh && nvm install ${EXTRA_NODE_VERSION}" - -# Install and configure pnpm -RUN su node -c "npm install -g pnpm@8" -RUN su node -c "pnpm config set store-dir /home/node/.pnpm-store" diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json deleted file mode 100644 index 41b81e3276..0000000000 --- a/.devcontainer/devcontainer.json +++ /dev/null @@ -1,26 +0,0 @@ -// For format details, see https://aka.ms/devcontainer.json. For config options, see the README at: -// https://github.com/microsoft/vscode-dev-containers/tree/v0.191.1/containers/javascript-node -{ - "name": "Node.js", - "build": { - "dockerfile": "Dockerfile", - // Update 'VARIANT' to pick a Node version: 18 - "args": { - "VARIANT": "18" - } - }, - // Set *default* container specific settings.json values on container create. - // Add the IDs of extensions you want installed when the container is created. - "customizations": { - "extensions": [ - "DavidAnson.vscode-markdownlint", - "dbaeumer.vscode-eslint", - "esbenp.prettier-vscode", - "vue.volar" - ] - }, - // Use 'postCreateCommand' to run commands after the container is created. - "postCreateCommand": "pnpm i --frozen-lockfile && pnpm run build", - // Comment out connect as root instead. More info: https://aka.ms/vscode-remote/containers/non-root. - "remoteUser": "node" -} diff --git a/.github/ISSUE_TEMPLATE/bug_report.yml b/.github/ISSUE_TEMPLATE/bug_report.yml deleted file mode 100644 index b4f3d1eb46..0000000000 --- a/.github/ISSUE_TEMPLATE/bug_report.yml +++ /dev/null @@ -1,63 +0,0 @@ -name: Bug report -description: Create a report to help us improve -body: - - type: markdown - attributes: - value: | - This issue form is for reporting bugs only! - - If you have a feature or enhancement request, please use the [feature request][fr] form. - - [fr]: https://github.com/eclipsesource/jsonforms/issues/new?assignees=&labels=&template=feature_request.yml - - type: textarea - validations: - required: true - attributes: - label: Describe the bug - description: A clear and concise description of what the bug is. - - type: textarea - validations: - required: true - attributes: - label: Expected behavior - description: A clear and concise description of what you expected to happen. - - type: textarea - validations: - required: true - attributes: - label: Steps to reproduce the issue - description: Steps to reproduce the behavior - value: | - 1. Go to '...' - 2. Click on '....' - 3. Scroll down to '....' - 4. See error - - type: textarea - attributes: - label: Screenshots - description: If applicable, add screenshots to help explain your problem. - - type: input - validations: - required: true - attributes: - label: Which Version of JSON Forms are you using? - placeholder: v3.0.0 - - type: dropdown - attributes: - label: Package - multiple: true - options: - - Core - - React Bindings - - React Material Renderers - - React Vanilla Renderers - - Angular Bindings - - Angular Material Renderers - - Vue Bindings - - Vue Vanilla Renderers - - Vue Vuetify Renderers - - Other (please specify in the Additional context field) - - type: textarea - attributes: - label: Additional context - description: Add any other context about the problem here. diff --git a/.github/ISSUE_TEMPLATE/config.yml b/.github/ISSUE_TEMPLATE/config.yml deleted file mode 100644 index 251a4147ed..0000000000 --- a/.github/ISSUE_TEMPLATE/config.yml +++ /dev/null @@ -1,8 +0,0 @@ -blank_issues_enabled: false -contact_links: - - name: JSON Forms board - url: https://jsonforms.discourse.group - about: For questions and discussions - - name: Professional support - url: https://jsonforms.io/support - about: Professional support by EclipseSource diff --git a/.github/ISSUE_TEMPLATE/feature_request.yml b/.github/ISSUE_TEMPLATE/feature_request.yml deleted file mode 100644 index c89a5d3d91..0000000000 --- a/.github/ISSUE_TEMPLATE/feature_request.yml +++ /dev/null @@ -1,52 +0,0 @@ -name: Feature request -description: Suggest an idea for this project -body: - - type: markdown - attributes: - value: | - This issue form is for requesting features only! - - If you want to report a bug, please use the [bug report][br] form. - - [br]: https://github.com/eclipsesource/jsonforms/issues/new?assignees=&labels=&template=bug_report.yml - - type: textarea - validations: - required: true - attributes: - label: Is your feature request related to a problem? Please describe. - description: A clear and concise description of what the problem is. Ex. I'm always frustrated when [...] - - type: textarea - validations: - required: true - attributes: - label: Describe the solution you'd like - description: A clear and concise description of what you want to happen. - - type: textarea - validations: - required: true - attributes: - label: Describe alternatives you've considered - description: A clear and concise description of any alternative solutions or features you've considered. - - type: markdown - attributes: - value: | - ## Describe for which setup you like to have the improvement - - type: dropdown - attributes: - label: Package - multiple: true - options: - - Core - - React Bindings - - React Material Renderers - - React Vanilla Renderers - - Angular Bindings - - Angular Material Renderers - - Vue Bindings - - Vue Vanilla Renderers - - Vue Vuetify Renderers - - Other (please specify in the Additional context field) - - type: textarea - attributes: - label: Additional context - description: Add any other context or screenshots about the feature request here. diff --git a/.github/config/changelog.json b/.github/config/changelog.json deleted file mode 100644 index 04256b89ce..0000000000 --- a/.github/config/changelog.json +++ /dev/null @@ -1,6 +0,0 @@ -{ - "sort": "DESC", - "pr_template": "- [${{LABELS}}] ${{TITLE}} (#${{NUMBER}})", - "template": "${{UNCATEGORIZED}}", - "ignore_labels": ["dependencies"] -} diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml deleted file mode 100644 index cefd493b07..0000000000 --- a/.github/workflows/ci.yaml +++ /dev/null @@ -1,67 +0,0 @@ -name: CI - -on: - push: - paths-ignore: - - '**.md' - pull_request: - paths-ignore: - - '**.md' - -jobs: - ci: - runs-on: ${{ matrix.os }} - timeout-minutes: 30 - strategy: - fail-fast: false - matrix: - os: - - ubuntu-latest - - macos-latest - - windows-latest - name: Run on ${{ matrix.os }} - steps: - - uses: actions/checkout@v3 - - - name: Setup node - uses: actions/setup-node@v3 - with: - node-version: 18 - - - uses: pnpm/action-setup@v4.0.0 - name: Install pnpm - id: pnpm-install - with: - version: 8 - run_install: false - - - name: Build - run: | - pnpm i --frozen-lockfile - pnpm run build - pnpm run doc - pnpm run bundle - - - name: Lint - if: matrix.os == 'ubuntu-latest' - run: pnpm run lint - - - name: Test - if: matrix.os == 'windows-latest' || matrix.os == 'macos-latest' - run: | - set NODE_OPTIONS=--max_old_space_size=4096 - pnpm run test - - - name: Test & Coverage - if: matrix.os == 'ubuntu-latest' - run: | - export NODE_OPTIONS=--max_old_space_size=4096 - pnpm run test-cov - pnpm run check-format - pnpm run merge-report && cat coverage/lcov.info - - - name: Upload Coveralls Report - if: success() && matrix.os == 'ubuntu-latest' - uses: coverallsapp/github-action@master - with: - github-token: ${{ secrets.GITHUB_TOKEN }} diff --git a/.github/workflows/publish.yaml b/.github/workflows/publish.yaml deleted file mode 100644 index b31dafa071..0000000000 --- a/.github/workflows/publish.yaml +++ /dev/null @@ -1,92 +0,0 @@ -name: "Publish" - -on: - workflow_dispatch: - inputs: - next_version: - type: "string" - description: "version (e.g. 3.4.0-alpha.0)" - required: true - skip_publish: - type: "boolean" - description: "mark in case only the version update shall be executed, skipping the release to npm" - required: true - skip_push: - type: "boolean" - description: "mark in case the version update shall not be pushed back to the repository" - required: true - stable_release: - type: "boolean" - description: "mark in case this is a full stable release (flag is ignored in case publish is skipped)" - required: true - -jobs: - publish: - permissions: - contents: "write" - id-token: "write" - runs-on: "ubuntu-latest" - steps: - - uses: "actions/checkout@v4" - with: - token: "${{ secrets.JSONFORMS_PUBLISH_PAT }}" - - - name: "Configure Git Credentials" - run: | - git config user.name "jsonforms-publish[bot]" - git config user.email "jsonforms-publish@eclipsesource.com" - - - name: "Setup node" - uses: "actions/setup-node@v3" - with: - node-version: "18" - registry-url: "https://registry.npmjs.org" - - - uses: pnpm/action-setup@v4.0.0 - name: Install pnpm - id: pnpm-install - with: - version: 8 - run_install: false - - - name: "Install Packages" - run: "pnpm i --frozen-lockfile" - - - name: "Build" - run: "pnpm run build" - - - name: "Test" - run: "pnpm run test" - - - name: "Versioning" - run: "pnpm exec lerna version ${{ github.event.inputs.next_version }} --no-push --force-publish --yes" - - - name: "Adjust PeerDependencies" - run: | - cd packages/angular && pnpm pkg set peerDependencies.@jsonforms/core="${{ github.event.inputs.next_version }}" - cd ../angular-material && pnpm pkg set peerDependencies.@jsonforms/core="${{ github.event.inputs.next_version }}" && pnpm pkg set peerDependencies.@jsonforms/angular="${{ github.event.inputs.next_version }}" - cd ../examples && pnpm pkg set peerDependencies.@jsonforms/core="${{ github.event.inputs.next_version }}" - cd ../material-renderers && pnpm pkg set peerDependencies.@jsonforms/core="${{ github.event.inputs.next_version }}" && pnpm pkg set peerDependencies.@jsonforms/react="${{ github.event.inputs.next_version }}" - cd ../react && pnpm pkg set peerDependencies.@jsonforms/core="${{ github.event.inputs.next_version }}" - cd ../vanilla-renderers && pnpm pkg set peerDependencies.@jsonforms/core="${{ github.event.inputs.next_version }}" && pnpm pkg set peerDependencies.@jsonforms/react="${{ github.event.inputs.next_version }}" - cd ../vue && pnpm pkg set peerDependencies.@jsonforms/core="${{ github.event.inputs.next_version }}" - cd ../vue-vanilla && pnpm pkg set peerDependencies.@jsonforms/core="${{ github.event.inputs.next_version }}" && pnpm pkg set peerDependencies.@jsonforms/vue="${{ github.event.inputs.next_version }}" - cd ../vue-vuetify && pnpm pkg set peerDependencies.@jsonforms/core="${{ github.event.inputs.next_version }}" && pnpm pkg set peerDependencies.@jsonforms/vue="${{ github.event.inputs.next_version }}" - - - name: "Tag and Commit" - run: | - git add -A && git commit --amend --no-edit - git tag v${{ github.event.inputs.next_version }} -f - - - name: "push" - if: "github.event.inputs.skip_push == 'false'" - run: | - git push - git push origin v${{ github.event.inputs.next_version }} - - - name: "Publish to npm" - if: "github.event.inputs.skip_publish == 'false'" - run: "pnpm publish --recursive ${{ github.event.inputs.stable_release == 'true' && ' ' || '--tag next' }}" - env: - NODE_AUTH_TOKEN: "${{ secrets.NPM_TOKEN }}" - NPM_CONFIG_PROVENANCE: "true" diff --git a/.vscode/extensions.json b/.vscode/extensions.json deleted file mode 100644 index 460ca3db3c..0000000000 --- a/.vscode/extensions.json +++ /dev/null @@ -1,13 +0,0 @@ -{ - // See http://go.microsoft.com/fwlink/?LinkId=827846 to learn about workspace recommendations. - // Extension identifier format: ${publisher}.${name}. Example: vscode.csharp - // List of extensions which should be recommended for users of this workspace. - "recommendations": [ - "DavidAnson.vscode-markdownlint", - "dbaeumer.vscode-eslint", - "esbenp.prettier-vscode", - "ms-vscode-remote.remote-containers" - ], - // List of extensions recommended by VS Code that should not be recommended for users of this workspace. - "unwantedRecommendations": [] -} diff --git a/.vscode/settings.json b/.vscode/settings.json deleted file mode 100644 index f3d841d8a9..0000000000 --- a/.vscode/settings.json +++ /dev/null @@ -1,29 +0,0 @@ -{ - "editor.formatOnSave": true, - "editor.defaultFormatter": "esbenp.prettier-vscode", - "eslint.validate": [ - "javascript", - "javascriptreact", - "typescript", - "typescriptreact", - "vue" - ], - "[json]": { - "editor.defaultFormatter": "esbenp.prettier-vscode" - }, - "[jsonc]": { - "editor.defaultFormatter": "esbenp.prettier-vscode" - }, - "search.exclude": { - "**/docs": true, - "**/node_modules": true, - "**/lib": true - }, - "typescript.tsdk": "node_modules/typescript/lib", - "[javascript][javascriptreact][typescript][typescriptreact][vue]": { - "editor.defaultFormatter": "esbenp.prettier-vscode", - "editor.codeActionsOnSave": { - "source.fixAll.eslint": "explicit" - } - } -} diff --git a/packages/angular-material/.eslintrc.js b/packages/angular-material/.eslintrc.js deleted file mode 100644 index 1eef8aa523..0000000000 --- a/packages/angular-material/.eslintrc.js +++ /dev/null @@ -1,53 +0,0 @@ -/* eslint-env node */ -/** @type {import('eslint').Linter.Config} */ -module.exports = { - root: true, - parser: '@typescript-eslint/parser', - parserOptions: { - /* Reset project because @angular-eslint/recommended sets this to an incompatible value */ - project: null, - }, - // There is no file include in ESLint. Thus, ignore all and include files via negative ignore (!) - ignorePatterns: ['/*', '!/src', '!/test', '!/example', '/example/dist'], - extends: [ - 'eslint:recommended', - 'plugin:@typescript-eslint/recommended', - 'plugin:import/recommended', - 'plugin:import/typescript', - 'plugin:@angular-eslint/recommended', - 'plugin:@angular-eslint/template/process-inline-templates', - 'plugin:prettier/recommended', - ], - rules: { - '@angular-eslint/component-class-suffix': 'off', - '@angular-eslint/directive-class-suffix': 'off', - '@angular-eslint/no-conflicting-lifecycle': 'warn', - '@typescript-eslint/no-explicit-any': 'off', - // Base rule must be disabled to avoid incorrect errors - 'no-unused-vars': 'off', - '@typescript-eslint/no-unused-vars': [ - 'warn', // or "error" - { - argsIgnorePattern: '^_', - varsIgnorePattern: '^_', - caughtErrorsIgnorePattern: '^_', - }, - ], - // workaround for - // https://github.com/import-js/eslint-plugin-import/issues/1810: - "import/no-unresolved": [ - "error", - { - ignore: [ - "@angular/cdk/.*", - "@angular/core/.*", - "@angular/material/.*", - "@angular/platform-browser/.*", - "@angular/platform-browser-dynamic/.*", - "core-js/es7/.*", - "zone.js/.*", - ] - } - ], - }, -}; diff --git a/packages/angular-material/.prettierrc.js b/packages/angular-material/.prettierrc.js deleted file mode 100644 index 2c26853c4a..0000000000 --- a/packages/angular-material/.prettierrc.js +++ /dev/null @@ -1,6 +0,0 @@ -module.exports = { - $schema: 'http://json.schemastore.org/prettierrc', - singleQuote: true, - jsxSingleQuote: true, - endOfLine: 'auto', -}; diff --git a/packages/angular-material/LICENSE b/packages/angular-material/LICENSE deleted file mode 100644 index 064ca1d9d2..0000000000 --- a/packages/angular-material/LICENSE +++ /dev/null @@ -1,22 +0,0 @@ -The MIT License - -Copyright (c) 2019 EclipseSource Munich -https://github.com/eclipsesource/jsonforms - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in -all copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN -THE SOFTWARE. diff --git a/packages/angular-material/README.md b/packages/angular-material/README.md deleted file mode 100644 index c8ab6e12af..0000000000 --- a/packages/angular-material/README.md +++ /dev/null @@ -1,137 +0,0 @@ -# JSON Forms - More Forms. Less Code - -_Complex forms in the blink of an eye_ - -JSON Forms eliminates the tedious task of writing fully-featured forms by hand by leveraging the capabilities of JSON, JSON Schema and Javascript. - -## Angular Material Renderers Package - -This is the JSONForms Angular Material renderers package. This package only contains renderers and must be combined with [JSON Forms Angular](https://github.com/eclipsesource/jsonforms/blob/master/packages/angular). - -See the official [documentation](https://jsonforms.io/docs/integrations/angular) and the JSON Forms Angular [seed repository](https://github.com/eclipsesource/jsonforms-angular-seed) for examples on how to integrate JSON Forms with your application. - -Check for all published JSON Forms packages. - -### Quick start - -Install JSON Forms Core, Angular and Angular Material Renderers - -```bash -npm i --save @jsonforms/core @jsonforms/angular @jsonforms/angular-material -``` - -Use the `json-forms` component for each form you want to render and hand over the renderer set. - -Example component file `app.component.ts`: - -```ts -import { Component } from '@angular/core'; -import { angularMaterialRenderers } from '@jsonforms/angular-material'; - -@Component({ - selector: 'app-root', - template: ``, -}) -export class AppComponent { - renderers = angularMaterialRenderers; - uischema = { - type: 'VerticalLayout', - elements: [ - { - type: 'Control', - label: false, - scope: '#/properties/done', - }, - { - type: 'Control', - scope: '#/properties/name', - }, - { - type: 'HorizontalLayout', - elements: [ - { - type: 'Control', - scope: '#/properties/due_date', - }, - { - type: 'Control', - scope: '#/properties/recurrence', - }, - ], - }, - ], - }; - schema = { - type: 'object', - properties: { - name: { - type: 'string', - minLength: 1, - }, - done: { - type: 'boolean', - }, - due_date: { - type: 'string', - format: 'date', - }, - recurrence: { - type: 'string', - enum: ['Never', 'Daily', 'Weekly', 'Monthly'], - }, - }, - required: ['name', 'due_date'], - }; - data = {}; -} -``` - -Example module file `app.module.ts`: - -```ts -import { NgModule } from '@angular/core'; -import { BrowserModule } from '@angular/platform-browser'; -import { BrowserAnimationsModule } from '@angular/platform-browser/animations'; -import { JsonFormsModule } from '@jsonforms/angular'; -import { JsonFormsAngularMaterialModule } from '@jsonforms/angular-material'; -import { AppComponent } from './app.component'; - -@NgModule({ - declarations: [AppComponent], - imports: [ - BrowserModule, - BrowserAnimationsModule, - JsonFormsModule, - JsonFormsAngularMaterialModule, - ], - schemas: [], - bootstrap: [AppComponent], -}) -export class AppModule {} -``` - -## License - -The JSON Forms project is licensed under the MIT License. See the [LICENSE file](https://github.com/eclipsesource/jsonforms/blob/master/LICENSE) for more information. - -## Roadmap - -Our current roadmap is available [here](https://github.com/eclipsesource/jsonforms/blob/master/ROADMAP.md). - -## Feedback, Help and Support - -JSON Forms is developed by [EclipseSource](https://eclipsesource.com). - -If you encounter any problems feel free to [open an issue](https://github.com/eclipsesource/jsonforms/issues/new/choose) on the repo. -For questions and discussions please use the [JSON Forms board](https://jsonforms.discourse.group). -You can also reach us via [email](mailto:jsonforms@eclipsesource.com?subject=JSON%20Forms). -In addition, EclipseSource also offers [professional support](https://jsonforms.io/support) for JSON Forms. - -## Migration - -See our [migration guide](https://github.com/eclipsesource/jsonforms/blob/master/MIGRATION.md) when updating JSON Forms. diff --git a/packages/angular-material/build-example.js b/packages/angular-material/build-example.js deleted file mode 100644 index 76ee52538c..0000000000 --- a/packages/angular-material/build-example.js +++ /dev/null @@ -1,73 +0,0 @@ -const path = require('path'); -const ngCore = require('@angular-devkit/core'); -const buildWebpackBrowser = require('@angular-devkit/build-angular/src/builders/browser').buildWebpackBrowser; - -const main = async () => new Promise((resolve, reject) => { - const project = 'angular-material'; - const target = 'build'; - const configuration = ''; - const workspaceRoot = path.join(process.cwd(), '../..'); - const root = `packages/${project}`; - const options = { - outputPath: root + '/example/dist', - tsConfig: root + '/tsconfig.example.json', - main: root + '/example/main.ts', - index: root + '/example/index.html', - styles: [ - root + '/node_modules/@angular/material/prebuilt-themes/indigo-pink.css' - ], - allowedCommonJsDependencies: [ - 'lodash', - 'hammerjs' - ], - watch: false, - buildOptimizer: false, - optimization: false, - outputHashing: 'none', - }; - const sourceRoot = root; - const teardownLogics = []; - const context = { - workspaceRoot, - logger: new ngCore.logging.Logger(`${project}:${target}:`), - target: { - project, - configuration, - target - }, - getProjectMetadata: (projectName) => Promise.resolve({ - root, - sourceRoot - }), - getBuilderNameForTarget: () => '@angular-devkit/build-angular:karma', - getTargetOptions: (target) => ({...options}), - validateOptions: (options) => options, - addTeardown: (teardown) => { - teardownLogics.push(teardown); - } - }; - let exitCode = 1; - buildWebpackBrowser(options, context, {}).subscribe({ - next: out => { - if (out.success) { - exitCode = 0; - } - }, - error: (err) => { - reject(err); - }, - complete: () => { - if (!exitCode) return resolve(); - reject(); - } - }); - return exitCode; -}); - -main() -.then(() => { - process.exit(0); -}) -.catch(err => { - process.exit(1); -}); \ No newline at end of file diff --git a/packages/angular-material/build-package.js b/packages/angular-material/build-package.js deleted file mode 100644 index aef214d1a9..0000000000 --- a/packages/angular-material/build-package.js +++ /dev/null @@ -1,11 +0,0 @@ -const ngPackage = require('ng-packagr'); - -ngPackage - .ngPackagr() - .forProject('ng-package.json') - .withTsConfig('tsconfig.json') - .build() - .catch(error => { - console.error(error); - process.exit(1); - }); \ No newline at end of file diff --git a/packages/angular-material/example/app/app.component.ts b/packages/angular-material/example/app/app.component.ts deleted file mode 100644 index 7ce9d2b8f9..0000000000 --- a/packages/angular-material/example/app/app.component.ts +++ /dev/null @@ -1,121 +0,0 @@ -/* - The MIT License - - Copyright (c) 2017-2020 EclipseSource Munich - https://github.com/eclipsesource/jsonforms - - Permission is hereby granted, free of charge, to any person obtaining a copy - of this software and associated documentation files (the "Software"), to deal - in the Software without restriction, including without limitation the rights - to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - copies of the Software, and to permit persons to whom the Software is - furnished to do so, subject to the following conditions: - - The above copyright notice and this permission notice shall be included in - all copies or substantial portions of the Software. - - THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - THE SOFTWARE. -*/ -import { Component } from '@angular/core'; -import { ExampleDescription, getExamples } from '@jsonforms/examples'; -import { - JsonFormsI18nState, - UISchemaElement, - UISchemaTester, -} from '@jsonforms/core'; -import { angularMaterialRenderers } from '../../lib'; - -const uiSchema = { - type: 'HorizontalLayout', - elements: [ - { - type: 'Control', - scope: '#/properties/buyer/properties/email', - }, - { - type: 'Control', - scope: '#/properties/status', - }, - ], -}; -const defaultI18n: JsonFormsI18nState = { - locale: 'en-US', -}; -const itemTester: UISchemaTester = (_schema, schemaPath, _path) => { - if (schemaPath === '#/properties/warehouseitems/items') { - return 10; - } - return -1; -}; -@Component({ - selector: 'app-root', - template: ` -

Angular Material Examples

- Data: {{ selectedExample.data | json }} -
- Example: - -
-
- - - Current locale: {{ i18n.locale }} - -
- - `, -}) -export class AppComponent { - readonly renderers = angularMaterialRenderers; - readonly examples = getExamples(); - selectedExample: ExampleDescription | undefined; - i18n: JsonFormsI18nState; - readonly = false; - data: any; - uischemas: { tester: UISchemaTester; uischema: UISchemaElement }[] = [ - { tester: itemTester, uischema: uiSchema }, - ]; - - constructor() { - this.selectedExample = this.examples[19]; - this.i18n = this.selectedExample.i18n ?? defaultI18n; - } - - onChange(ev: any) { - this.selectedExample = this.examples.find( - (e) => e.name === ev.target.value - ); - this.i18n = this.selectedExample?.i18n ?? defaultI18n; - } - - changeLocale(locale: string) { - this.i18n = { ...this.i18n, locale }; - } - - toggleReadonly() { - this.readonly = !this.readonly; - } -} diff --git a/packages/angular-material/example/app/app.module.ts b/packages/angular-material/example/app/app.module.ts deleted file mode 100644 index 9b532e27a1..0000000000 --- a/packages/angular-material/example/app/app.module.ts +++ /dev/null @@ -1,41 +0,0 @@ -/* - The MIT License - - Copyright (c) 2017-2020 EclipseSource Munich - https://github.com/eclipsesource/jsonforms - - Permission is hereby granted, free of charge, to any person obtaining a copy - of this software and associated documentation files (the "Software"), to deal - in the Software without restriction, including without limitation the rights - to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - copies of the Software, and to permit persons to whom the Software is - furnished to do so, subject to the following conditions: - - The above copyright notice and this permission notice shall be included in - all copies or substantial portions of the Software. - - THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - THE SOFTWARE. -*/ -import { BrowserModule } from '@angular/platform-browser'; -import { BrowserAnimationsModule } from '@angular/platform-browser/animations'; -import { CUSTOM_ELEMENTS_SCHEMA, NgModule } from '@angular/core'; -import { AppComponent } from './app.component'; -import { JsonFormsAngularMaterialModule } from '../../lib'; - -@NgModule({ - declarations: [AppComponent], - imports: [ - BrowserModule, - BrowserAnimationsModule, - JsonFormsAngularMaterialModule, - ], - bootstrap: [AppComponent], - schemas: [CUSTOM_ELEMENTS_SCHEMA], -}) -export class AppModule {} diff --git a/packages/angular-material/example/index.html b/packages/angular-material/example/index.html deleted file mode 100644 index 07875afcb5..0000000000 --- a/packages/angular-material/example/index.html +++ /dev/null @@ -1,28 +0,0 @@ - - - - - JSON Forms Angular Material RendererSet - - - - - - - - - - - - diff --git a/packages/angular-material/example/main.ts b/packages/angular-material/example/main.ts deleted file mode 100644 index 2a4879ee7b..0000000000 --- a/packages/angular-material/example/main.ts +++ /dev/null @@ -1,36 +0,0 @@ -/* - The MIT License - - Copyright (c) 2017-2019 EclipseSource Munich - https://github.com/eclipsesource/jsonforms - - Permission is hereby granted, free of charge, to any person obtaining a copy - of this software and associated documentation files (the "Software"), to deal - in the Software without restriction, including without limitation the rights - to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - copies of the Software, and to permit persons to whom the Software is - furnished to do so, subject to the following conditions: - - The above copyright notice and this permission notice shall be included in - all copies or substantial portions of the Software. - - THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - THE SOFTWARE. -*/ -import 'zone.js'; -import { platformBrowserDynamic } from '@angular/platform-browser-dynamic'; - -import { AppModule } from './app/app.module'; - -platformBrowserDynamic().bootstrapModule(AppModule); - -/* -Copyright 2017-2018 Google Inc. All Rights Reserved. -Use of this source code is governed by an MIT-style license that -can be found in the LICENSE file at http://angular.io/license -*/ diff --git a/packages/angular-material/karma.conf.js b/packages/angular-material/karma.conf.js deleted file mode 100644 index 31077a040b..0000000000 --- a/packages/angular-material/karma.conf.js +++ /dev/null @@ -1,54 +0,0 @@ -// Karma configuration file, see link for more information -// https://karma-runner.github.io/1.0/config/configuration-file.html - -module.exports = function (config) { - config.set({ - basePath: '', - frameworks: ['jasmine', '@angular-devkit/build-angular'], - plugins: [ - require('karma-jasmine'), - require('karma-chrome-launcher'), - require('karma-jasmine-html-reporter'), - require('karma-coverage'), - require('@angular-devkit/build-angular/plugins/karma') - ], - client: { - jasmine: { - // you can add configuration options for Jasmine here - // the possible options are listed at https://jasmine.github.io/api/edge/Configuration.html - // for example, you can disable the random execution with `random: false` - // or set a specific seed with `seed: 4321` - }, - clearContext: false // leave Jasmine Spec Runner output visible in browser - }, - jasmineHtmlReporter: { - suppressAll: true // removes the duplicated traces - }, - coverageReporter: { - subdir: '.', - reporters: [ - { type: 'lcov' }, - { type: 'text-summary' } - ] - }, - reporters: ['progress', 'kjhtml', 'dots'], - - browsers: [ config.singleRun ? 'ChromeHeadlessNoSandbox' : 'Chrome' ], - customLaunchers: { - ChromeHeadlessNoSandbox: { - base: 'ChromeHeadless', - flags: ['--no-sandbox'], - }, - }, - restartOnFileChange: true, - logLevel: config.LOG_INFO, - - webpackMiddleware: { - stats: 'detailed', - }, - - webpackServer: { - noInfo: true, - }, - }); -}; diff --git a/packages/angular-material/ng-package.json b/packages/angular-material/ng-package.json deleted file mode 100644 index e13258f5df..0000000000 --- a/packages/angular-material/ng-package.json +++ /dev/null @@ -1,10 +0,0 @@ -{ - "$schema": "./node_modules/ng-packagr/ng-package.schema.json", - "dest": "./lib", - "allowedNonPeerDependencies": [ - "@jsonforms/angular", - "@jsonforms/core", - "hammerjs", - "lodash" - ] -} \ No newline at end of file diff --git a/packages/angular-material/package.json b/packages/angular-material/package.json deleted file mode 100644 index cd4eb0b4bf..0000000000 --- a/packages/angular-material/package.json +++ /dev/null @@ -1,142 +0,0 @@ -{ - "name": "@jsonforms/angular-material", - "version": "3.4.1", - "description": "Material Renderer Set for Angular module of JSON Forms", - "repository": "https://github.com/eclipsesource/jsonforms", - "bugs": "https://github.com/eclipsesource/jsonforms/issues", - "homepage": "http://jsonforms.io/", - "license": "MIT", - "publishConfig": { - "access": "public" - }, - "directories": { - "src": "src", - "test": "test" - }, - "files": [ - "lib", - "src" - ], - "keywords": [ - "angular", - "material", - "form", - "forms", - "json", - "jsonforms", - "frontend", - "generator", - "input", - "renderengine", - "jsonschema", - "schema", - "uischema", - "layout", - "customization" - ], - "module": "./lib/fesm2022/jsonforms-angular-material.mjs", - "typings": "./lib/index.d.ts", - "scripts": { - "build": "node ./build-package.js", - "build:examples-app": "pnpm run build && node ./build-example.js", - "dev": "pnpm run build:examples-app && npx http-server ./example/dist/ -c-1 -o", - "clean": "rimraf lib coverage dist .nyc_output 2> /dev/null", - "lint": "eslint .", - "lint:fix": "eslint --fix .", - "report": "nyc report --reporter=html", - "doc": "typedoc --name 'JSON Forms Angular Material Renderers' --out docs src", - "test-dbg": "node ./test-runner", - "test": "node ./test-runner --single-run", - "test-ci": "node ./test-runner --single-run", - "test-cov": "node ./test-runner --coverage --single-run", - "e2e": "npm run e2e-update && npm run e2e-test", - "e2e-test": "protractor ./test-config/protractor.conf.js", - "e2e-update": "webdriver-manager update --standalone false --gecko false" - }, - "nyc": { - "reporter": [ - "lcov", - "text-summary" - ] - }, - "peerDependencies": { - "@angular/animations": "^17.0.0 || ^18.0.0", - "@angular/cdk": "^17.0.0 || ^18.0.0", - "@angular/common": "^17.0.0 || ^18.0.0", - "@angular/core": "^17.0.0 || ^18.0.0", - "@angular/forms": "^17.0.0 || ^18.0.0", - "@angular/material": "^17.0.0 || ^18.0.0", - "@angular/platform-browser": "^17.0.0 || ^18.0.0", - "@angular/router": "^17.0.0 || ^18.0.0", - "@jsonforms/angular": "3.4.1", - "@jsonforms/core": "3.4.1", - "dayjs": "^1.11.10", - "rxjs": "^6.6.0 || ^7.4.0" - }, - "dependencies": { - "hammerjs": "2.0.8", - "lodash": "^4.17.21" - }, - "devDependencies": { - "@angular-devkit/build-angular": "^17.0.0", - "@angular-devkit/core": "^17.0.0", - "@angular-eslint/eslint-plugin": "^17.0.0", - "@angular-eslint/eslint-plugin-template": "^17.0.0", - "@angular-eslint/schematics": "^17.0.0", - "@angular-eslint/template-parser": "^17.0.0", - "@angular/animations": "^17.0.0", - "@angular/cdk": "^17.0.0", - "@angular/common": "^17.0.0", - "@angular/compiler": "^17.0.0", - "@angular/compiler-cli": "^17.0.0", - "@angular/core": "^17.0.0", - "@angular/forms": "^17.0.0", - "@angular/material": "^17.0.0", - "@angular/platform-browser": "^17.0.0", - "@angular/platform-browser-dynamic": "^17.0.0", - "@angular/router": "^17.0.0", - "@babel/plugin-proposal-nullish-coalescing-operator": "^7.16.5", - "@babel/plugin-proposal-optional-chaining": "^7.16.5", - "@jsonforms/angular": "workspace:*", - "@jsonforms/core": "workspace:*", - "@jsonforms/examples": "workspace:*", - "@ngtools/webpack": "^17.0.0", - "@types/jasmine": "~3.8.0", - "@types/lodash": "4.14.149", - "@types/node": "^18.19.4", - "@typescript-eslint/eslint-plugin": "^5.54.1", - "@typescript-eslint/parser": "^5.54.1", - "babel-loader": "^8.0.6", - "copy-webpack-plugin": "^11.0.0", - "dayjs": "^1.11.10", - "eslint": "^8.56.0", - "eslint-config-prettier": "^8.7.0", - "eslint-plugin-import": "^2.27.5", - "eslint-plugin-prettier": "^4.2.1", - "html-loader": "^0.5.5", - "http-server": "^14.1.1", - "jasmine": "^3.99.0", - "jasmine-spec-reporter": "^4.2.1", - "karma": "^6.4.3", - "karma-chrome-launcher": "^3.2.0", - "karma-coverage": "~2.0.3", - "karma-jasmine": "^2.0.1", - "karma-jasmine-html-reporter": "^1.7.0", - "karma-sourcemap-loader": "^0.3.8", - "karma-webpack": "^5.0.0", - "ng-packagr": "^17.0.0", - "null-loader": "^0.1.1", - "nyc": "^15.1.0", - "prettier": "^2.8.4", - "protractor": "^7.0.0", - "rimraf": "^3.0.2", - "rxjs": "^6.6.0", - "ts-loader": "^9.5.1", - "tslib": "^2.5.0", - "typedoc": "~0.25.3", - "typescript": "~5.2.2", - "webpack": "^5.78.0", - "yargs": "^17.7.2", - "zone.js": "~0.14.0" - } -} diff --git a/packages/angular-material/src/index.ts b/packages/angular-material/src/index.ts deleted file mode 100644 index 4aaf8f92ed..0000000000 --- a/packages/angular-material/src/index.ts +++ /dev/null @@ -1 +0,0 @@ -export * from './public_api'; diff --git a/packages/angular-material/src/library/controls/autocomplete.renderer.ts b/packages/angular-material/src/library/controls/autocomplete.renderer.ts deleted file mode 100644 index 32742f9b0f..0000000000 --- a/packages/angular-material/src/library/controls/autocomplete.renderer.ts +++ /dev/null @@ -1,175 +0,0 @@ -/* - The MIT License - - Copyright (c) 2017-2019 EclipseSource Munich - https://github.com/eclipsesource/jsonforms - - Permission is hereby granted, free of charge, to any person obtaining a copy - of this software and associated documentation files (the "Software"), to deal - in the Software without restriction, including without limitation the rights - to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - copies of the Software, and to permit persons to whom the Software is - furnished to do so, subject to the following conditions: - - The above copyright notice and this permission notice shall be included in - all copies or substantial portions of the Software. - - THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - THE SOFTWARE. -*/ -import { - ChangeDetectionStrategy, - Component, - Input, - OnInit, -} from '@angular/core'; -import type { MatAutocompleteSelectedEvent } from '@angular/material/autocomplete'; -import { JsonFormsAngularService, JsonFormsControl } from '@jsonforms/angular'; -import { - Actions, - composeWithUi, - ControlElement, - isEnumControl, - OwnPropsOfControl, - RankedTester, - rankWith, -} from '@jsonforms/core'; -import type { Observable } from 'rxjs'; -import { map, startWith } from 'rxjs/operators'; - -/** - * To use this component you will need to add your own tester: - *

- * ...
- * export const AutocompleteControlRendererTester: RankedTester = rankWith(2, isEnumControl);
- * ...
- * 
- * Add the tester and renderer to JSONForms registry: - *

- * ...
- * { tester: AutocompleteControlRendererTester, renderer: AutocompleteControlRenderer },
- * ...
- * 
- * Furthermore you need to update your module. - *

- * ...
- * imports: [JsonFormsAngularMaterialModule, MatAutocompleteModule],
- * declarations: [AutocompleteControlRenderer]
- * ...
- * 
- * - */ -@Component({ - selector: 'AutocompleteControlRenderer', - template: ` - - {{ label }} - - - - {{ option }} - - - {{ - description - }} - {{ error }} - - `, - styles: [ - ` - :host { - display: flex; - flex-direction: row; - } - mat-form-field { - flex: 1 1 auto; - } - `, - ], - changeDetection: ChangeDetectionStrategy.OnPush, -}) -export class AutocompleteControlRenderer - extends JsonFormsControl - implements OnInit -{ - @Input() options: string[]; - filteredOptions: Observable; - shouldFilter: boolean; - focused = false; - - constructor(jsonformsService: JsonFormsAngularService) { - super(jsonformsService); - } - getEventValue = (event: any) => event.target.value; - - ngOnInit() { - super.ngOnInit(); - this.shouldFilter = false; - this.filteredOptions = this.form.valueChanges.pipe( - startWith(''), - map((val) => this.filter(val)) - ); - } - - updateFilter(event: any) { - // ENTER - if (event.keyCode === 13) { - this.shouldFilter = false; - } else { - this.shouldFilter = true; - } - } - - onSelect(ev: MatAutocompleteSelectedEvent) { - const path = composeWithUi(this.uischema as ControlElement, this.path); - this.shouldFilter = false; - this.jsonFormsService.updateCore( - Actions.update(path, () => ev.option.value) - ); - this.triggerValidation(); - } - - filter(val: string): string[] { - return (this.options || this.scopedSchema.enum || []).filter( - (option) => - !this.shouldFilter || - !val || - option.toLowerCase().indexOf(val.toLowerCase()) === 0 - ); - } - protected getOwnProps(): OwnPropsOfAutoComplete { - return { - ...super.getOwnProps(), - options: this.options, - }; - } -} - -export const enumControlTester: RankedTester = rankWith(2, isEnumControl); - -interface OwnPropsOfAutoComplete extends OwnPropsOfControl { - options: string[]; -} diff --git a/packages/angular-material/src/library/controls/boolean.renderer.ts b/packages/angular-material/src/library/controls/boolean.renderer.ts deleted file mode 100644 index f9e9e770e2..0000000000 --- a/packages/angular-material/src/library/controls/boolean.renderer.ts +++ /dev/null @@ -1,86 +0,0 @@ -/* - The MIT License - - Copyright (c) 2017-2019 EclipseSource Munich - https://github.com/eclipsesource/jsonforms - - Permission is hereby granted, free of charge, to any person obtaining a copy - of this software and associated documentation files (the "Software"), to deal - in the Software without restriction, including without limitation the rights - to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - copies of the Software, and to permit persons to whom the Software is - furnished to do so, subject to the following conditions: - - The above copyright notice and this permission notice shall be included in - all copies or substantial portions of the Software. - - THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - THE SOFTWARE. -*/ -import { - ChangeDetectionStrategy, - ChangeDetectorRef, - Component, - ViewRef, -} from '@angular/core'; -import { JsonFormsAngularService, JsonFormsControl } from '@jsonforms/angular'; -import { isBooleanControl, RankedTester, rankWith } from '@jsonforms/core'; - -@Component({ - selector: 'BooleanControlRenderer', - template: ` -
- - {{ label }} - - {{ - description - }} - {{ error }} -
- `, - styles: [ - ` - :host { - display: flex; - flex-direction: row; - } - .boolean-control { - flex: 1 1 auto; - display: flex; - flex-direction: column; - justify-content: center; - height: 100%; - } - `, - ], - changeDetection: ChangeDetectionStrategy.OnPush, -}) -export class BooleanControlRenderer extends JsonFormsControl { - constructor( - jsonformsService: JsonFormsAngularService, - private changeDetectionRef: ChangeDetectorRef - ) { - super(jsonformsService); - } - isChecked = () => this.data || false; - getEventValue = (event: any) => event.checked; - - mapAdditionalProps() { - if (!(this.changeDetectionRef as ViewRef).destroyed) { - this.changeDetectionRef.markForCheck(); - } - } -} - -export const booleanControlTester: RankedTester = rankWith(2, isBooleanControl); diff --git a/packages/angular-material/src/library/controls/date.renderer.ts b/packages/angular-material/src/library/controls/date.renderer.ts deleted file mode 100644 index b80ba352bf..0000000000 --- a/packages/angular-material/src/library/controls/date.renderer.ts +++ /dev/null @@ -1,178 +0,0 @@ -/* - The MIT License - - Copyright (c) 2017-2019 EclipseSource Munich - https://github.com/eclipsesource/jsonforms - - Permission is hereby granted, free of charge, to any person obtaining a copy - of this software and associated documentation files (the "Software"), to deal - in the Software without restriction, including without limitation the rights - to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - copies of the Software, and to permit persons to whom the Software is - furnished to do so, subject to the following conditions: - - The above copyright notice and this permission notice shall be included in - all copies or substantial portions of the Software. - - THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - THE SOFTWARE. -*/ -import { - Component, - ChangeDetectionStrategy, - Inject, - ViewEncapsulation, -} from '@angular/core'; -import { - defaultDateFormat, - isDateControl, - JsonFormsState, - RankedTester, - rankWith, - StatePropsOfControl, -} from '@jsonforms/core'; -import { JsonFormsAngularService, JsonFormsControl } from '@jsonforms/angular'; -import { DateAdapter, MAT_DATE_FORMATS } from '@angular/material/core'; -import { MyFormat } from '../util/date-format'; -import { DayJsDateAdapter } from '../util/dayjs-date-adapter'; -import { MatDatepicker } from '@angular/material/datepicker'; - -@Component({ - selector: 'DateControlRenderer', - template: ` - - {{ label }} - - - - {{ - description - }} - {{ error }} - - `, - styles: [ - ` - DateControlRenderer { - display: flex; - flex-direction: row; - } - .date-control-renderer { - flex: 1 1 auto; - } - .no-panel-navigation .mat-calendar-period-button { - pointer-events: none; - } - .no-panel-navigation .mat-calendar-arrow { - display: none; - } - `, - ], - encapsulation: ViewEncapsulation.None, - changeDetection: ChangeDetectionStrategy.OnPush, - providers: [ - { - provide: DateAdapter, - useClass: DayJsDateAdapter, - }, - { - provide: MAT_DATE_FORMATS, - useClass: MyFormat, - }, - ], -}) -export class DateControlRenderer extends JsonFormsControl { - focused = false; - views: string[] = []; - startView = ''; - panelClass = ''; - - constructor( - jsonformsService: JsonFormsAngularService, - @Inject(MAT_DATE_FORMATS) private dateFormat: MyFormat, - @Inject(DateAdapter) private dateAdapter: DayJsDateAdapter - ) { - super(jsonformsService); - } - - getEventValue = (event: any) => { - const value = event.value ? event.value : event; - return this.dateAdapter.toSaveFormat(value); - }; - - protected mapToProps(state: JsonFormsState): StatePropsOfControl { - const props = super.mapToProps(state); - const saveFormat = this.uischema?.options?.dateSaveFormat - ? this.uischema.options.dateSaveFormat - : defaultDateFormat; - this.views = this.uischema?.options?.views - ? this.uischema.options.views - : ['year', 'month', 'day']; - this.setViewProperties(); - - const dateFormat = this.uischema?.options?.dateFormat; - - if (dateFormat) { - this.dateFormat.setDisplayFormat(dateFormat); - } - - this.dateAdapter.setSaveFormat(saveFormat); - if (this.jsonFormsService.getLocale()) { - this.dateAdapter.setLocale(this.jsonFormsService.getLocale()); - } - const date = this.dateAdapter.parseSaveFormat(props.data); - return { ...props, data: date }; - } - - yearSelected($event: any, datepicker: MatDatepicker) { - if (!this.views.includes('day') && !this.views.includes('month')) { - this.onChange($event); - datepicker.close(); - } - } - monthSelected($event: any, datepicker: MatDatepicker) { - if (!this.views.includes('day')) { - this.onChange($event); - datepicker.close(); - } - } - - setViewProperties() { - if (!this.views.includes('day')) { - this.startView = 'multi-year'; - this.panelClass = 'no-panel-navigation'; - } else { - this.startView = 'month'; - } - } -} - -export const DateControlRendererTester: RankedTester = rankWith( - 2, - isDateControl -); diff --git a/packages/angular-material/src/library/controls/index.ts b/packages/angular-material/src/library/controls/index.ts deleted file mode 100644 index ec7666823b..0000000000 --- a/packages/angular-material/src/library/controls/index.ts +++ /dev/null @@ -1,32 +0,0 @@ -/* - The MIT License - - Copyright (c) 2017-2019 EclipseSource Munich - https://github.com/eclipsesource/jsonforms - - Permission is hereby granted, free of charge, to any person obtaining a copy - of this software and associated documentation files (the "Software"), to deal - in the Software without restriction, including without limitation the rights - to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - copies of the Software, and to permit persons to whom the Software is - furnished to do so, subject to the following conditions: - - The above copyright notice and this permission notice shall be included in - all copies or substantial portions of the Software. - - THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - THE SOFTWARE. -*/ -export * from './boolean.renderer'; -export * from './text.renderer'; -export * from './textarea.renderer'; -export * from './number.renderer'; -export * from './range.renderer'; -export * from './date.renderer'; -export * from './toggle.renderer'; -export * from './autocomplete.renderer'; diff --git a/packages/angular-material/src/library/controls/number.renderer.ts b/packages/angular-material/src/library/controls/number.renderer.ts deleted file mode 100644 index 829b9c347d..0000000000 --- a/packages/angular-material/src/library/controls/number.renderer.ts +++ /dev/null @@ -1,186 +0,0 @@ -/* - The MIT License - - Copyright (c) 2017-2019 EclipseSource Munich - https://github.com/eclipsesource/jsonforms - - Permission is hereby granted, free of charge, to any person obtaining a copy - of this software and associated documentation files (the "Software"), to deal - in the Software without restriction, including without limitation the rights - to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - copies of the Software, and to permit persons to whom the Software is - furnished to do so, subject to the following conditions: - - The above copyright notice and this permission notice shall be included in - all copies or substantial portions of the Software. - - THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - THE SOFTWARE. -*/ -import { ChangeDetectionStrategy, Component } from '@angular/core'; -import { JsonFormsAngularService, JsonFormsControl } from '@jsonforms/angular'; -import { - isIntegerControl, - isNumberControl, - or, - RankedTester, - rankWith, - StatePropsOfControl, -} from '@jsonforms/core'; -import merge from 'lodash/merge'; - -@Component({ - selector: 'NumberControlRenderer', - template: ` - - {{ label }} - - {{ - description - }} - {{ error }} - - `, - styles: [ - ` - :host { - display: flex; - flex-direction: row; - } - mat-form-field { - flex: 1 1 auto; - } - `, - ], - changeDetection: ChangeDetectionStrategy.OnPush, -}) -export class NumberControlRenderer extends JsonFormsControl { - private readonly MAXIMUM_FRACTIONAL_DIGITS = 20; - - oldValue: string; - min: number; - max: number; - multipleOf: number; - locale: string; - numberFormat: Intl.NumberFormat; - decimalSeparator: string; - focused = false; - - constructor(jsonformsService: JsonFormsAngularService) { - super(jsonformsService); - } - - onChange(ev: any) { - const data = this.oldValue - ? ev.target.value.replace(this.oldValue, '') - : ev.target.value; - // ignore these - if ( - data === '.' || - data === ',' || - data === ' ' || - // if the value is 0 and we already have a value then we ignore - (data === '0' && - this.getValue() !== '' && - // a 0 in the first place - ((ev.target.selectionStart === 1 && ev.target.selectionEnd === 1) || - // or in the last place as this doesn't change the value (when there is a separator) - (ev.target.selectionStart === ev.target.value.length && - ev.target.selectionEnd === ev.target.value.length && - ev.target.value.indexOf(this.decimalSeparator) !== -1))) - ) { - this.oldValue = ev.target.value; - return; - } - super.onChange(ev); - this.oldValue = this.getValue(); - } - - getEventValue = (event: any) => { - const cleanPattern = new RegExp(`[^-+0-9${this.decimalSeparator}]`, 'g'); - const cleaned = event.target.value.replace(cleanPattern, ''); - const normalized = cleaned.replace(this.decimalSeparator, '.'); - - if (normalized === '') { - return undefined; - } - - // convert to number - const number = +normalized; - // if not a number just return the string - if (Number.isNaN(number)) { - return event.target.value; - } - return number; - }; - - getValue = () => { - if (this.data !== undefined && this.data !== null) { - if (typeof this.data === 'number') { - return this.numberFormat.format(this.data); - } - return this.data; - } - return ''; - }; - - mapAdditionalProps(props: StatePropsOfControl) { - if (this.scopedSchema) { - const testerContext = { - rootSchema: this.rootSchema, - config: props.config, - }; - const defaultStep = isNumberControl( - this.uischema, - this.rootSchema, - testerContext - ) - ? 0.1 - : 1; - this.min = this.scopedSchema.minimum; - this.max = this.scopedSchema.maximum; - this.multipleOf = this.scopedSchema.multipleOf || defaultStep; - const appliedUiSchemaOptions = merge( - {}, - props.config, - this.uischema.options - ); - const currentLocale = this.jsonFormsService.getLocale(); - if (this.locale === undefined || this.locale !== currentLocale) { - this.locale = currentLocale; - this.numberFormat = new Intl.NumberFormat(this.locale, { - useGrouping: appliedUiSchemaOptions.useGrouping, - maximumFractionDigits: this.MAXIMUM_FRACTIONAL_DIGITS, - }); - this.determineDecimalSeparator(); - this.oldValue = this.getValue(); - } - this.form.setValue(this.getValue()); - } - } - - private determineDecimalSeparator(): void { - const example = this.numberFormat.format(1.1); - this.decimalSeparator = example.charAt(1); - } -} -export const NumberControlRendererTester: RankedTester = rankWith( - 2, - or(isNumberControl, isIntegerControl) -); diff --git a/packages/angular-material/src/library/controls/range.renderer.ts b/packages/angular-material/src/library/controls/range.renderer.ts deleted file mode 100644 index 38030b8768..0000000000 --- a/packages/angular-material/src/library/controls/range.renderer.ts +++ /dev/null @@ -1,98 +0,0 @@ -/* - The MIT License - - Copyright (c) 2017-2019 EclipseSource Munich - https://github.com/eclipsesource/jsonforms - - Permission is hereby granted, free of charge, to any person obtaining a copy - of this software and associated documentation files (the "Software"), to deal - in the Software without restriction, including without limitation the rights - to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - copies of the Software, and to permit persons to whom the Software is - furnished to do so, subject to the following conditions: - - The above copyright notice and this permission notice shall be included in - all copies or substantial portions of the Software. - - THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - THE SOFTWARE. -*/ -import { - ChangeDetectionStrategy, - Component, - ChangeDetectorRef, -} from '@angular/core'; -import { JsonFormsAngularService, JsonFormsControl } from '@jsonforms/angular'; -import { isRangeControl, RankedTester, rankWith } from '@jsonforms/core'; - -@Component({ - selector: 'RangeControlRenderer', - template: ` -
- - - - - {{ - description - }} - {{ error }} -
- `, - styles: [ - ` - :host { - display: flex; - flex-direction: row; - } - .range-control { - flex: 1 1 auto; - display: flex; - flex-direction: column; - } - `, - ], - changeDetection: ChangeDetectionStrategy.OnPush, -}) -export class RangeControlRenderer extends JsonFormsControl { - min: number; - max: number; - multipleOf: number; - focused = false; - - constructor( - jsonformsService: JsonFormsAngularService, - private changeDetectorRef: ChangeDetectorRef - ) { - super(jsonformsService); - } - getEventValue = (event: number) => Number(event); - mapAdditionalProps() { - if (this.scopedSchema) { - this.min = this.scopedSchema.minimum; - this.max = this.scopedSchema.maximum; - this.multipleOf = this.scopedSchema.multipleOf || 1; - } - this.changeDetectorRef.markForCheck(); - } -} -export const RangeControlRendererTester: RankedTester = rankWith( - 4, - isRangeControl -); diff --git a/packages/angular-material/src/library/controls/text.renderer.ts b/packages/angular-material/src/library/controls/text.renderer.ts deleted file mode 100644 index f6c0ae5fa6..0000000000 --- a/packages/angular-material/src/library/controls/text.renderer.ts +++ /dev/null @@ -1,88 +0,0 @@ -/* - The MIT License - - Copyright (c) 2017-2019 EclipseSource Munich - https://github.com/eclipsesource/jsonforms - - Permission is hereby granted, free of charge, to any person obtaining a copy - of this software and associated documentation files (the "Software"), to deal - in the Software without restriction, including without limitation the rights - to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - copies of the Software, and to permit persons to whom the Software is - furnished to do so, subject to the following conditions: - - The above copyright notice and this permission notice shall be included in - all copies or substantial portions of the Software. - - THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - THE SOFTWARE. -*/ -import { ChangeDetectionStrategy, Component } from '@angular/core'; -import { JsonFormsAngularService, JsonFormsControl } from '@jsonforms/angular'; -import { isStringControl, RankedTester, rankWith } from '@jsonforms/core'; - -@Component({ - selector: 'TextControlRenderer', - template: ` - - {{ label }} - - {{ - description - }} - {{ error }} - - `, - styles: [ - ` - :host { - display: flex; - flex-direction: row; - } - mat-form-field { - flex: 1 1 auto; - } - `, - ], - changeDetection: ChangeDetectionStrategy.OnPush, -}) -export class TextControlRenderer extends JsonFormsControl { - focused = false; - constructor(jsonformsService: JsonFormsAngularService) { - super(jsonformsService); - } - getEventValue = (event: any) => event.target.value || undefined; - getType = (): string => { - if (this.uischema.options && this.uischema.options.format) { - return this.uischema.options.format; - } - if (this.scopedSchema && this.scopedSchema.format) { - switch (this.scopedSchema.format) { - case 'email': - return 'email'; - case 'tel': - return 'tel'; - default: - return 'text'; - } - } - return 'text'; - }; -} -export const TextControlRendererTester: RankedTester = rankWith( - 1, - isStringControl -); diff --git a/packages/angular-material/src/library/controls/textarea.renderer.ts b/packages/angular-material/src/library/controls/textarea.renderer.ts deleted file mode 100644 index 7816d6700c..0000000000 --- a/packages/angular-material/src/library/controls/textarea.renderer.ts +++ /dev/null @@ -1,71 +0,0 @@ -/* - The MIT License - - Copyright (c) 2017-2019 EclipseSource Munich - https://github.com/eclipsesource/jsonforms - - Permission is hereby granted, free of charge, to any person obtaining a copy - of this software and associated documentation files (the "Software"), to deal - in the Software without restriction, including without limitation the rights - to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - copies of the Software, and to permit persons to whom the Software is - furnished to do so, subject to the following conditions: - - The above copyright notice and this permission notice shall be included in - all copies or substantial portions of the Software. - - THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - THE SOFTWARE. -*/ -import { ChangeDetectionStrategy, Component } from '@angular/core'; -import { JsonFormsAngularService, JsonFormsControl } from '@jsonforms/angular'; -import { isMultiLineControl, RankedTester, rankWith } from '@jsonforms/core'; - -@Component({ - selector: 'TextAreaRenderer', - template: ` - - {{ label }} - - {{ - description - }} - {{ error }} - - `, - styles: [ - ` - :host { - display: flex; - flex-direction: row; - } - mat-form-field { - flex: 1 1 auto; - } - `, - ], - changeDetection: ChangeDetectionStrategy.OnPush, -}) -export class TextAreaRenderer extends JsonFormsControl { - focused = false; - constructor(jsonformsService: JsonFormsAngularService) { - super(jsonformsService); - } - getEventValue = (event: any) => event.target.value || undefined; -} -export const TextAreaRendererTester: RankedTester = rankWith( - 2, - isMultiLineControl -); diff --git a/packages/angular-material/src/library/controls/toggle.renderer.ts b/packages/angular-material/src/library/controls/toggle.renderer.ts deleted file mode 100644 index abb41f3f31..0000000000 --- a/packages/angular-material/src/library/controls/toggle.renderer.ts +++ /dev/null @@ -1,76 +0,0 @@ -/* - The MIT License - - Copyright (c) 2017-2019 EclipseSource Munich - https://github.com/eclipsesource/jsonforms - - Permission is hereby granted, free of charge, to any person obtaining a copy - of this software and associated documentation files (the "Software"), to deal - in the Software without restriction, including without limitation the rights - to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - copies of the Software, and to permit persons to whom the Software is - furnished to do so, subject to the following conditions: - - The above copyright notice and this permission notice shall be included in - all copies or substantial portions of the Software. - - THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - THE SOFTWARE. -*/ -import { - ChangeDetectionStrategy, - Component, - ChangeDetectorRef, -} from '@angular/core'; -import { JsonFormsAngularService, JsonFormsControl } from '@jsonforms/angular'; -import { - and, - isBooleanControl, - optionIs, - RankedTester, - rankWith, -} from '@jsonforms/core'; - -@Component({ - selector: 'ToggleControlRenderer', - template: ` -
- - {{ label }} - - {{ - description - }} - {{ error }} -
- `, - changeDetection: ChangeDetectionStrategy.OnPush, -}) -export class ToggleControlRenderer extends JsonFormsControl { - constructor( - jsonformsService: JsonFormsAngularService, - private changeDetectorRef: ChangeDetectorRef - ) { - super(jsonformsService); - } - isChecked = () => this.data || false; - getEventValue = (event: any) => event.checked; - mapAdditionalProps() { - this.changeDetectorRef.markForCheck(); - } -} - -export const ToggleControlRendererTester: RankedTester = rankWith( - 3, - and(isBooleanControl, optionIs('toggle', true)) -); diff --git a/packages/angular-material/src/library/index.ts b/packages/angular-material/src/library/index.ts deleted file mode 100644 index 64c286e7d7..0000000000 --- a/packages/angular-material/src/library/index.ts +++ /dev/null @@ -1,121 +0,0 @@ -/* - The MIT License - - Copyright (c) 2017-2019 EclipseSource Munich - https://github.com/eclipsesource/jsonforms - - Permission is hereby granted, free of charge, to any person obtaining a copy - of this software and associated documentation files (the "Software"), to deal - in the Software without restriction, including without limitation the rights - to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - copies of the Software, and to permit persons to whom the Software is - furnished to do so, subject to the following conditions: - - The above copyright notice and this permission notice shall be included in - all copies or substantial portions of the Software. - - THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - THE SOFTWARE. -*/ -import 'hammerjs'; -import { RankedTester } from '@jsonforms/core'; -export * from './module'; -import { - BooleanControlRenderer, - booleanControlTester, -} from './controls/boolean.renderer'; -import { - TextControlRenderer, - TextControlRendererTester, -} from './controls/text.renderer'; -import { - TextAreaRenderer, - TextAreaRendererTester, -} from './controls/textarea.renderer'; -import { - NumberControlRenderer, - NumberControlRendererTester, -} from './controls/number.renderer'; -import { - RangeControlRenderer, - RangeControlRendererTester, -} from './controls/range.renderer'; -import { - DateControlRenderer, - DateControlRendererTester, -} from './controls/date.renderer'; -import { - ToggleControlRenderer, - ToggleControlRendererTester, -} from './controls/toggle.renderer'; -import { - AutocompleteControlRenderer, - enumControlTester, -} from './controls/autocomplete.renderer'; -import { - ObjectControlRenderer, - ObjectControlRendererTester, -} from './other/object.renderer'; -import { - VerticalLayoutRenderer, - verticalLayoutTester, -} from './layouts/vertical-layout.renderer'; -import { - HorizontalLayoutRenderer, - horizontalLayoutTester, -} from './layouts/horizontal-layout.renderer'; - -import { - CategorizationTabLayoutRenderer, - categorizationTester, -} from './layouts/categorization-layout.renderer'; - -import { LabelRenderer, LabelRendererTester } from './other/label.renderer'; -import { - masterDetailTester, - MasterListComponent, -} from './other/master-detail/master'; -import { - GroupLayoutRenderer, - groupLayoutTester, -} from './layouts/group-layout.renderer'; -import { TableRenderer, TableRendererTester } from './other/table.renderer'; -import { - ArrayLayoutRenderer, - ArrayLayoutRendererTester, -} from './layouts/array-layout.renderer'; - -export * from './controls'; -export * from './layouts'; -export * from './other'; - -export const angularMaterialRenderers: { - tester: RankedTester; - renderer: any; -}[] = [ - // controls - { tester: booleanControlTester, renderer: BooleanControlRenderer }, - { tester: TextControlRendererTester, renderer: TextControlRenderer }, - { tester: TextAreaRendererTester, renderer: TextAreaRenderer }, - { tester: NumberControlRendererTester, renderer: NumberControlRenderer }, - { tester: RangeControlRendererTester, renderer: RangeControlRenderer }, - { tester: DateControlRendererTester, renderer: DateControlRenderer }, - { tester: ToggleControlRendererTester, renderer: ToggleControlRenderer }, - { tester: enumControlTester, renderer: AutocompleteControlRenderer }, - { tester: ObjectControlRendererTester, renderer: ObjectControlRenderer }, - // layouts - { tester: verticalLayoutTester, renderer: VerticalLayoutRenderer }, - { tester: groupLayoutTester, renderer: GroupLayoutRenderer }, - { tester: horizontalLayoutTester, renderer: HorizontalLayoutRenderer }, - { tester: categorizationTester, renderer: CategorizationTabLayoutRenderer }, - { tester: LabelRendererTester, renderer: LabelRenderer }, - { tester: ArrayLayoutRendererTester, renderer: ArrayLayoutRenderer }, - // other - { tester: masterDetailTester, renderer: MasterListComponent }, - { tester: TableRendererTester, renderer: TableRenderer }, -]; diff --git a/packages/angular-material/src/library/layouts/array-layout.renderer.ts b/packages/angular-material/src/library/layouts/array-layout.renderer.ts deleted file mode 100644 index 3106d8ab1d..0000000000 --- a/packages/angular-material/src/library/layouts/array-layout.renderer.ts +++ /dev/null @@ -1,258 +0,0 @@ -/* - The MIT License - - Copyright (c) 2017-2020 EclipseSource Munich - https://github.com/eclipsesource/jsonforms - - Permission is hereby granted, free of charge, to any person obtaining a copy - of this software and associated documentation files (the "Software"), to deal - in the Software without restriction, including without limitation the rights - to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - copies of the Software, and to permit persons to whom the Software is - furnished to do so, subject to the following conditions: - - The above copyright notice and this permission notice shall be included in - all copies or substantial portions of the Software. - - THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - THE SOFTWARE. -*/ -import { ChangeDetectionStrategy, Component, OnInit } from '@angular/core'; -import { - JsonFormsAngularService, - JsonFormsAbstractControl, -} from '@jsonforms/angular'; -import { - arrayDefaultTranslations, - ArrayLayoutProps, - ArrayTranslations, - createDefaultValue, - defaultJsonFormsI18nState, - findUISchema, - getArrayTranslations, - isObjectArrayWithNesting, - JsonFormsState, - mapDispatchToArrayControlProps, - mapStateToArrayLayoutProps, - OwnPropsOfRenderer, - Paths, - RankedTester, - rankWith, - setReadonly, - StatePropsOfArrayLayout, - UISchemaElement, - UISchemaTester, - unsetReadonly, -} from '@jsonforms/core'; - -@Component({ - selector: 'app-array-layout-renderer', - template: ` -
-
-

{{ label }}

- - - error_outline - - - -
-

{{ translations.noDataMessage }}

-
- - - - - - - - - - -
-
- `, - styles: [ - ` - .array-layout { - display: flex; - flex-direction: column; - gap: 16px; - } - .array-layout > * { - flex: 1 1 auto; - } - .array-layout-toolbar { - display: flex; - align-items: center; - } - .array-layout-title { - margin: 0; - } - .array-layout-toolbar > span { - flex: 1 1 auto; - } - .array-item { - padding: 16px; - } - ::ng-deep .error-message-tooltip { - white-space: pre-line; - } - `, - ], - changeDetection: ChangeDetectionStrategy.OnPush, -}) -export class ArrayLayoutRenderer - extends JsonFormsAbstractControl - implements OnInit -{ - noData: boolean; - translations: ArrayTranslations = {}; - addItem: (path: string, value: any) => () => void; - moveItemUp: (path: string, index: number) => () => void; - moveItemDown: (path: string, index: number) => () => void; - removeItems: (path: string, toDelete: number[]) => () => void; - uischemas: { - tester: UISchemaTester; - uischema: UISchemaElement; - }[]; - constructor(jsonFormsService: JsonFormsAngularService) { - super(jsonFormsService); - } - mapToProps( - state: JsonFormsState - ): StatePropsOfArrayLayout & { translations: ArrayTranslations } { - const props = mapStateToArrayLayoutProps(state, this.getOwnProps()); - const t = - state.jsonforms.i18n?.translate ?? defaultJsonFormsI18nState.translate; - const translations = getArrayTranslations( - t, - arrayDefaultTranslations, - props.i18nKeyPrefix, - props.label - ); - return { ...props, translations }; - } - remove(index: number): void { - this.removeItems(this.propsPath, [index])(); - } - add(): void { - this.addItem( - this.propsPath, - createDefaultValue(this.scopedSchema, this.rootSchema) - )(); - } - up(index: number): void { - this.moveItemUp(this.propsPath, index)(); - } - down(index: number): void { - this.moveItemDown(this.propsPath, index)(); - } - ngOnInit() { - super.ngOnInit(); - const { addItem, removeItems, moveUp, moveDown } = - mapDispatchToArrayControlProps( - this.jsonFormsService.updateCore.bind(this.jsonFormsService) - ); - this.addItem = addItem; - this.moveItemUp = moveUp; - this.moveItemDown = moveDown; - this.removeItems = removeItems; - } - mapAdditionalProps( - props: ArrayLayoutProps & { translations: ArrayTranslations } - ) { - this.noData = !props.data || props.data === 0; - this.uischemas = props.uischemas; - this.translations = props.translations; - } - getProps(index: number): OwnPropsOfRenderer { - const uischema = findUISchema( - this.uischemas, - this.scopedSchema, - this.uischema.scope, - this.propsPath, - undefined, - this.uischema, - this.rootSchema - ); - if (this.isEnabled()) { - unsetReadonly(uischema); - } else { - setReadonly(uischema); - } - return { - schema: this.scopedSchema, - path: Paths.compose(this.propsPath, `${index}`), - uischema, - }; - } - trackByFn(index: number) { - return index; - } -} - -export const ArrayLayoutRendererTester: RankedTester = rankWith( - 4, - isObjectArrayWithNesting -); diff --git a/packages/angular-material/src/library/layouts/categorization-layout.renderer.ts b/packages/angular-material/src/library/layouts/categorization-layout.renderer.ts deleted file mode 100644 index 65ea94f773..0000000000 --- a/packages/angular-material/src/library/layouts/categorization-layout.renderer.ts +++ /dev/null @@ -1,107 +0,0 @@ -/* - The MIT License - - Copyright (c) 2017-2019 EclipseSource Munich - https://github.com/eclipsesource/jsonforms - - Permission is hereby granted, free of charge, to any person obtaining a copy - of this software and associated documentation files (the "Software"), to deal - in the Software without restriction, including without limitation the rights - to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - copies of the Software, and to permit persons to whom the Software is - furnished to do so, subject to the following conditions: - - The above copyright notice and this permission notice shall be included in - all copies or substantial portions of the Software. - - THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - THE SOFTWARE. -*/ -import { - and, - Categorization, - categorizationHasCategory, - Category, - defaultJsonFormsI18nState, - deriveLabelForUISchemaElement, - getAjv, - isVisible, - JsonFormsState, - Labelable, - mapStateToLayoutProps, - RankedTester, - rankWith, - uiTypeIs, -} from '@jsonforms/core'; -import { Component, OnInit } from '@angular/core'; -import { - JsonFormsAngularService, - JsonFormsBaseRenderer, -} from '@jsonforms/angular'; - -@Component({ - selector: 'jsonforms-categorization-layout', - template: ` - - -
- -
-
-
- `, -}) -export class CategorizationTabLayoutRenderer - extends JsonFormsBaseRenderer - implements OnInit -{ - hidden: boolean; - visibleCategories: (Category | Categorization)[]; - categoryLabels: string[]; - - constructor(private jsonFormsService: JsonFormsAngularService) { - super(); - } - - ngOnInit() { - this.addSubscription( - this.jsonFormsService.$state.subscribe({ - next: (state: JsonFormsState) => { - const props = mapStateToLayoutProps(state, this.getOwnProps()); - this.hidden = !props.visible; - this.visibleCategories = this.uischema.elements.filter( - (category: Category | Categorization) => - isVisible(category, props.data, undefined, getAjv(state)) - ); - this.categoryLabels = this.visibleCategories.map((element) => - deriveLabelForUISchemaElement( - element as Labelable, - state.jsonforms.i18n?.translate ?? - defaultJsonFormsI18nState.translate - ) - ); - }, - }) - ); - } -} - -export const categorizationTester: RankedTester = rankWith( - 2, - and(uiTypeIs('Categorization'), categorizationHasCategory) -); diff --git a/packages/angular-material/src/library/layouts/group-layout.renderer.ts b/packages/angular-material/src/library/layouts/group-layout.renderer.ts deleted file mode 100644 index 1b725df9aa..0000000000 --- a/packages/angular-material/src/library/layouts/group-layout.renderer.ts +++ /dev/null @@ -1,76 +0,0 @@ -/* - The MIT License - - Copyright (c) 2017-2019 EclipseSource Munich - https://github.com/eclipsesource/jsonforms - - Permission is hereby granted, free of charge, to any person obtaining a copy - of this software and associated documentation files (the "Software"), to deal - in the Software without restriction, including without limitation the rights - to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - copies of the Software, and to permit persons to whom the Software is - furnished to do so, subject to the following conditions: - - The above copyright notice and this permission notice shall be included in - all copies or substantial portions of the Software. - - THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - THE SOFTWARE. -*/ -import { - ChangeDetectionStrategy, - ChangeDetectorRef, - Component, -} from '@angular/core'; -import { GroupLayout, RankedTester, rankWith, uiTypeIs } from '@jsonforms/core'; -import { LayoutRenderer } from './layout.renderer'; -import { JsonFormsAngularService } from '@jsonforms/angular'; - -@Component({ - selector: 'GroupLayoutRenderer', - template: ` - - {{ label }} -
- -
-
- `, - styles: [ - ` - .group-layout { - display: flex; - flex-direction: column; - gap: 16px; - padding: 16px; - } - .group-layout > div { - flex: 1 1 auto; - } - `, - ], - changeDetection: ChangeDetectionStrategy.OnPush, -}) -export class GroupLayoutRenderer extends LayoutRenderer { - constructor( - jsonFormsService: JsonFormsAngularService, - changeDetectionRef: ChangeDetectorRef - ) { - super(jsonFormsService, changeDetectionRef); - } -} -export const groupLayoutTester: RankedTester = rankWith(1, uiTypeIs('Group')); diff --git a/packages/angular-material/src/library/layouts/horizontal-layout.renderer.ts b/packages/angular-material/src/library/layouts/horizontal-layout.renderer.ts deleted file mode 100644 index bd1c97ff11..0000000000 --- a/packages/angular-material/src/library/layouts/horizontal-layout.renderer.ts +++ /dev/null @@ -1,83 +0,0 @@ -/* - The MIT License - - Copyright (c) 2017-2019 EclipseSource Munich - https://github.com/eclipsesource/jsonforms - - Permission is hereby granted, free of charge, to any person obtaining a copy - of this software and associated documentation files (the "Software"), to deal - in the Software without restriction, including without limitation the rights - to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - copies of the Software, and to permit persons to whom the Software is - furnished to do so, subject to the following conditions: - - The above copyright notice and this permission notice shall be included in - all copies or substantial portions of the Software. - - THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - THE SOFTWARE. -*/ -import { - ChangeDetectionStrategy, - ChangeDetectorRef, - Component, -} from '@angular/core'; -import { - HorizontalLayout, - RankedTester, - rankWith, - uiTypeIs, -} from '@jsonforms/core'; -import { LayoutRenderer } from './layout.renderer'; -import { JsonFormsAngularService } from '@jsonforms/angular'; - -@Component({ - selector: 'HorizontalLayoutRenderer', - template: ` -
-
- -
-
- `, - styles: [ - ` - .horizontal-layout { - display: flex; - gap: 16px; - flex-flow: row wrap; - align-items: flex-start; - place-content: flex-start center; - } - .horizontal-layout > div { - flex: 1 1 auto; - } - `, - ], - changeDetection: ChangeDetectionStrategy.OnPush, -}) -export class HorizontalLayoutRenderer extends LayoutRenderer { - constructor( - jsonFormsService: JsonFormsAngularService, - changeDetectionRef: ChangeDetectorRef - ) { - super(jsonFormsService, changeDetectionRef); - } -} -export const horizontalLayoutTester: RankedTester = rankWith( - 1, - uiTypeIs('HorizontalLayout') -); diff --git a/packages/angular-material/src/library/layouts/index.ts b/packages/angular-material/src/library/layouts/index.ts deleted file mode 100644 index 61c0e338b8..0000000000 --- a/packages/angular-material/src/library/layouts/index.ts +++ /dev/null @@ -1,30 +0,0 @@ -/* - The MIT License - - Copyright (c) 2017-2019 EclipseSource Munich - https://github.com/eclipsesource/jsonforms - - Permission is hereby granted, free of charge, to any person obtaining a copy - of this software and associated documentation files (the "Software"), to deal - in the Software without restriction, including without limitation the rights - to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - copies of the Software, and to permit persons to whom the Software is - furnished to do so, subject to the following conditions: - - The above copyright notice and this permission notice shall be included in - all copies or substantial portions of the Software. - - THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - THE SOFTWARE. -*/ -export * from './array-layout.renderer'; -export * from './horizontal-layout.renderer'; -export * from './vertical-layout.renderer'; -export * from './categorization-layout.renderer'; -export * from './layout.renderer'; -export * from './group-layout.renderer'; diff --git a/packages/angular-material/src/library/layouts/layout.renderer.ts b/packages/angular-material/src/library/layouts/layout.renderer.ts deleted file mode 100644 index 109b1a269e..0000000000 --- a/packages/angular-material/src/library/layouts/layout.renderer.ts +++ /dev/null @@ -1,96 +0,0 @@ -/* - The MIT License - - Copyright (c) 2017-2019 EclipseSource Munich - https://github.com/eclipsesource/jsonforms - - Permission is hereby granted, free of charge, to any person obtaining a copy - of this software and associated documentation files (the "Software"), to deal - in the Software without restriction, including without limitation the rights - to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - copies of the Software, and to permit persons to whom the Software is - furnished to do so, subject to the following conditions: - - The above copyright notice and this permission notice shall be included in - all copies or substantial portions of the Software. - - THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - THE SOFTWARE. -*/ -import { - OnInit, - ChangeDetectorRef, - Component, - PipeTransform, - Pipe, -} from '@angular/core'; -import { - JsonFormsAngularService, - JsonFormsBaseRenderer, -} from '@jsonforms/angular'; -import { - JsonFormsState, - Layout, - mapStateToLayoutProps, - OwnPropsOfRenderer, - UISchemaElement, - JsonSchema, -} from '@jsonforms/core'; - -@Component({ - template: '', -}) -export class LayoutRenderer - extends JsonFormsBaseRenderer - implements OnInit -{ - hidden: boolean; - label: string | undefined; - - constructor( - private jsonFormsService: JsonFormsAngularService, - protected changeDetectionRef: ChangeDetectorRef - ) { - super(); - } - - ngOnInit() { - this.addSubscription( - this.jsonFormsService.$state.subscribe({ - next: (state: JsonFormsState) => { - const props = mapStateToLayoutProps(state, this.getOwnProps()); - this.label = props.label; - this.hidden = !props.visible; - this.changeDetectionRef.markForCheck(); - }, - }) - ); - } - - trackElement(_index: number, renderProp: OwnPropsOfRenderer): string { - return renderProp - ? renderProp.path + JSON.stringify(renderProp.uischema) - : null; - } -} - -@Pipe({ name: 'layoutChildrenRenderProps' }) -export class LayoutChildrenRenderPropsPipe implements PipeTransform { - transform( - uischema: Layout, - schema: JsonSchema, - path: string - ): OwnPropsOfRenderer[] { - const elements = (uischema.elements || []).map((el: UISchemaElement) => ({ - uischema: el, - schema: schema, - path: path, - })); - return elements; - } -} diff --git a/packages/angular-material/src/library/layouts/vertical-layout.renderer.ts b/packages/angular-material/src/library/layouts/vertical-layout.renderer.ts deleted file mode 100644 index 5426a08135..0000000000 --- a/packages/angular-material/src/library/layouts/vertical-layout.renderer.ts +++ /dev/null @@ -1,78 +0,0 @@ -/* - The MIT License - - Copyright (c) 2017-2019 EclipseSource Munich - https://github.com/eclipsesource/jsonforms - - Permission is hereby granted, free of charge, to any person obtaining a copy - of this software and associated documentation files (the "Software"), to deal - in the Software without restriction, including without limitation the rights - to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - copies of the Software, and to permit persons to whom the Software is - furnished to do so, subject to the following conditions: - - The above copyright notice and this permission notice shall be included in - all copies or substantial portions of the Software. - - THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - THE SOFTWARE. -*/ -import { - ChangeDetectionStrategy, - ChangeDetectorRef, - Component, -} from '@angular/core'; -import { - RankedTester, - rankWith, - uiTypeIs, - VerticalLayout, -} from '@jsonforms/core'; -import { LayoutRenderer } from './layout.renderer'; -import { JsonFormsAngularService } from '@jsonforms/angular'; - -@Component({ - selector: 'VerticalLayoutRenderer', - template: ` -
-
- -
-
- `, - styles: [ - ` - .vertical-layout { - display: flex; - flex-direction: column; - gap: 16px; - } - .vertical-layout > div { - flex: 1 1 auto; - } - `, - ], - changeDetection: ChangeDetectionStrategy.OnPush, -}) -export class VerticalLayoutRenderer extends LayoutRenderer { - constructor( - jsonFormsService: JsonFormsAngularService, - changeDetectionRef: ChangeDetectorRef - ) { - super(jsonFormsService, changeDetectionRef); - } -} -export const verticalLayoutTester: RankedTester = rankWith( - 1, - uiTypeIs('VerticalLayout') -); diff --git a/packages/angular-material/src/library/module.ts b/packages/angular-material/src/library/module.ts deleted file mode 100644 index 15866aeb2a..0000000000 --- a/packages/angular-material/src/library/module.ts +++ /dev/null @@ -1,138 +0,0 @@ -/* - The MIT License - - Copyright (c) 2017-2019 EclipseSource Munich - https://github.com/eclipsesource/jsonforms - - Permission is hereby granted, free of charge, to any person obtaining a copy - of this software and associated documentation files (the "Software"), to deal - in the Software without restriction, including without limitation the rights - to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - copies of the Software, and to permit persons to whom the Software is - furnished to do so, subject to the following conditions: - - The above copyright notice and this permission notice shall be included in - all copies or substantial portions of the Software. - - THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - THE SOFTWARE. -*/ -import { CommonModule } from '@angular/common'; -import { ReactiveFormsModule } from '@angular/forms'; -import { MatAutocompleteModule } from '@angular/material/autocomplete'; -import { MatButtonModule } from '@angular/material/button'; -import { MatBadgeModule } from '@angular/material/badge'; -import { MatCardModule } from '@angular/material/card'; -import { MatCheckboxModule } from '@angular/material/checkbox'; -import { MatDatepickerModule } from '@angular/material/datepicker'; -import { MatFormFieldModule } from '@angular/material/form-field'; -import { MatTooltipModule } from '@angular/material/tooltip'; -import { MatIconModule } from '@angular/material/icon'; -import { MatInputModule } from '@angular/material/input'; -import { MatListModule } from '@angular/material/list'; -import { MatNativeDateModule } from '@angular/material/core'; -import { MatSelectModule } from '@angular/material/select'; -import { MatSidenavModule } from '@angular/material/sidenav'; -import { MatSliderModule } from '@angular/material/slider'; -import { MatSlideToggleModule } from '@angular/material/slide-toggle'; -import { MatTableModule } from '@angular/material/table'; -import { MatTabsModule } from '@angular/material/tabs'; -import { MatToolbarModule } from '@angular/material/toolbar'; -import { CUSTOM_ELEMENTS_SCHEMA, NgModule } from '@angular/core'; -import { JsonFormsModule } from '@jsonforms/angular'; -import { AutocompleteControlRenderer } from './controls/autocomplete.renderer'; -import { BooleanControlRenderer } from './controls/boolean.renderer'; -import { DateControlRenderer } from './controls/date.renderer'; -import { NumberControlRenderer } from './controls/number.renderer'; -import { RangeControlRenderer } from './controls/range.renderer'; -import { TextAreaRenderer } from './controls/textarea.renderer'; -import { TextControlRenderer } from './controls/text.renderer'; -import { ToggleControlRenderer } from './controls/toggle.renderer'; -import { LabelRenderer } from './other/label.renderer'; -import { JsonFormsDetailComponent } from './other/master-detail/detail'; -import { MasterListComponent } from './other/master-detail/master'; -import { ObjectControlRenderer } from './other/object.renderer'; -import { TableRenderer, GetProps } from './other/table.renderer'; -import { CategorizationTabLayoutRenderer } from './layouts/categorization-layout.renderer'; -import { GroupLayoutRenderer } from './layouts/group-layout.renderer'; -import { HorizontalLayoutRenderer } from './layouts/horizontal-layout.renderer'; -import { VerticalLayoutRenderer } from './layouts/vertical-layout.renderer'; -import { ArrayLayoutRenderer } from './layouts/array-layout.renderer'; -import { LayoutChildrenRenderPropsPipe } from './layouts'; - -@NgModule({ - imports: [ - CommonModule, - JsonFormsModule, - MatFormFieldModule, - MatCheckboxModule, - MatInputModule, - MatSliderModule, - MatSlideToggleModule, - MatNativeDateModule, - MatDatepickerModule, - MatTabsModule, - MatSidenavModule, - MatListModule, - ReactiveFormsModule, - MatCardModule, - MatSelectModule, - MatButtonModule, - MatIconModule, - MatAutocompleteModule, - MatTableModule, - MatToolbarModule, - MatTooltipModule, - MatBadgeModule, - ], - declarations: [ - BooleanControlRenderer, - TextAreaRenderer, - TextControlRenderer, - NumberControlRenderer, - RangeControlRenderer, - DateControlRenderer, - ToggleControlRenderer, - VerticalLayoutRenderer, - HorizontalLayoutRenderer, - CategorizationTabLayoutRenderer, - GroupLayoutRenderer, - LabelRenderer, - MasterListComponent, - JsonFormsDetailComponent, - ObjectControlRenderer, - AutocompleteControlRenderer, - TableRenderer, - ArrayLayoutRenderer, - LayoutChildrenRenderPropsPipe, - GetProps, - ], - exports: [ - CommonModule, - JsonFormsModule, - MatFormFieldModule, - MatCheckboxModule, - MatInputModule, - MatSliderModule, - MatSlideToggleModule, - MatNativeDateModule, - MatDatepickerModule, - MatTabsModule, - MatSidenavModule, - MatListModule, - ReactiveFormsModule, - MatCardModule, - MatSelectModule, - MatButtonModule, - MatIconModule, - MatAutocompleteModule, - ], - schemas: [CUSTOM_ELEMENTS_SCHEMA], - providers: [], -}) -export class JsonFormsAngularMaterialModule {} diff --git a/packages/angular-material/src/library/other/index.ts b/packages/angular-material/src/library/other/index.ts deleted file mode 100644 index ecdab3c25d..0000000000 --- a/packages/angular-material/src/library/other/index.ts +++ /dev/null @@ -1,28 +0,0 @@ -/* - The MIT License - - Copyright (c) 2017-2019 EclipseSource Munich - https://github.com/eclipsesource/jsonforms - - Permission is hereby granted, free of charge, to any person obtaining a copy - of this software and associated documentation files (the "Software"), to deal - in the Software without restriction, including without limitation the rights - to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - copies of the Software, and to permit persons to whom the Software is - furnished to do so, subject to the following conditions: - - The above copyright notice and this permission notice shall be included in - all copies or substantial portions of the Software. - - THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - THE SOFTWARE. -*/ -export * from './label.renderer'; -export * from './master-detail'; -export * from './object.renderer'; -export * from './table.renderer'; diff --git a/packages/angular-material/src/library/other/label.renderer.ts b/packages/angular-material/src/library/other/label.renderer.ts deleted file mode 100644 index 3a049ec37c..0000000000 --- a/packages/angular-material/src/library/other/label.renderer.ts +++ /dev/null @@ -1,77 +0,0 @@ -/* - The MIT License - - Copyright (c) 2017-2019 EclipseSource Munich - https://github.com/eclipsesource/jsonforms - - Permission is hereby granted, free of charge, to any person obtaining a copy - of this software and associated documentation files (the "Software"), to deal - in the Software without restriction, including without limitation the rights - to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - copies of the Software, and to permit persons to whom the Software is - furnished to do so, subject to the following conditions: - - The above copyright notice and this permission notice shall be included in - all copies or substantial portions of the Software. - - THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - THE SOFTWARE. -*/ -import { Component, OnInit } from '@angular/core'; -import { - JsonFormsAngularService, - JsonFormsBaseRenderer, -} from '@jsonforms/angular'; -import { - JsonFormsState, - LabelElement, - mapStateToLabelProps, - OwnPropsOfLabel, - RankedTester, - rankWith, - uiTypeIs, -} from '@jsonforms/core'; - -@Component({ - selector: 'LabelRenderer', - template: ` `, - styles: [ - ` - :host { - flex: 1 1 auto; - } - `, - ], -}) -export class LabelRenderer - extends JsonFormsBaseRenderer - implements OnInit -{ - label: string; - visible: boolean; - - constructor(private jsonFormsService: JsonFormsAngularService) { - super(); - } - ngOnInit() { - this.addSubscription( - this.jsonFormsService.$state.subscribe({ - next: (state: JsonFormsState) => { - const props = mapStateToLabelProps( - state, - this.getOwnProps() as OwnPropsOfLabel - ); - this.visible = props.visible; - this.label = props.text; - }, - }) - ); - } -} - -export const LabelRendererTester: RankedTester = rankWith(4, uiTypeIs('Label')); diff --git a/packages/angular-material/src/library/other/master-detail/detail.ts b/packages/angular-material/src/library/other/master-detail/detail.ts deleted file mode 100644 index 9076a66675..0000000000 --- a/packages/angular-material/src/library/other/master-detail/detail.ts +++ /dev/null @@ -1,47 +0,0 @@ -/* - The MIT License - - Copyright (c) 2017-2019 EclipseSource Munich - https://github.com/eclipsesource/jsonforms - - Permission is hereby granted, free of charge, to any person obtaining a copy - of this software and associated documentation files (the "Software"), to deal - in the Software without restriction, including without limitation the rights - to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - copies of the Software, and to permit persons to whom the Software is - furnished to do so, subject to the following conditions: - - The above copyright notice and this permission notice shall be included in - all copies or substantial portions of the Software. - - THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - THE SOFTWARE. -*/ -import { Component, Input } from '@angular/core'; - -@Component({ - selector: 'jsonforms-detail', - template: ` -
- -
- `, -}) -export class JsonFormsDetailComponent { - _item: any; - _schema: any; - initialized = false; - - @Input() - set item(item: any) { - if (item) { - this._item = item; - this.initialized = true; - } - } -} diff --git a/packages/angular-material/src/library/other/master-detail/index.ts b/packages/angular-material/src/library/other/master-detail/index.ts deleted file mode 100644 index 60fb7a1b82..0000000000 --- a/packages/angular-material/src/library/other/master-detail/index.ts +++ /dev/null @@ -1,26 +0,0 @@ -/* - The MIT License - - Copyright (c) 2017-2019 EclipseSource Munich - https://github.com/eclipsesource/jsonforms - - Permission is hereby granted, free of charge, to any person obtaining a copy - of this software and associated documentation files (the "Software"), to deal - in the Software without restriction, including without limitation the rights - to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - copies of the Software, and to permit persons to whom the Software is - furnished to do so, subject to the following conditions: - - The above copyright notice and this permission notice shall be included in - all copies or substantial portions of the Software. - - THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - THE SOFTWARE. -*/ -export * from './detail'; -export * from './master'; diff --git a/packages/angular-material/src/library/other/master-detail/master.ts b/packages/angular-material/src/library/other/master-detail/master.ts deleted file mode 100644 index d50d4f092b..0000000000 --- a/packages/angular-material/src/library/other/master-detail/master.ts +++ /dev/null @@ -1,309 +0,0 @@ -/* - The MIT License - - Copyright (c) 2017-2019 EclipseSource Munich - https://github.com/eclipsesource/jsonforms - - Permission is hereby granted, free of charge, to any person obtaining a copy - of this software and associated documentation files (the "Software"), to deal - in the Software without restriction, including without limitation the rights - to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - copies of the Software, and to permit persons to whom the Software is - furnished to do so, subject to the following conditions: - - The above copyright notice and this permission notice shall be included in - all copies or substantial portions of the Software. - - THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - THE SOFTWARE. -*/ -import some from 'lodash/some'; -import get from 'lodash/get'; -import { - ChangeDetectionStrategy, - ChangeDetectorRef, - Component, - OnInit, -} from '@angular/core'; -import { - JsonFormsAngularService, - JsonFormsArrayControl, -} from '@jsonforms/angular'; -import { - ArrayControlProps, - arrayDefaultTranslations, - ArrayTranslations, - ControlElement, - createDefaultValue, - decode, - defaultJsonFormsI18nState, - findUISchema, - getArrayTranslations, - getFirstPrimitiveProp, - JsonFormsState, - mapDispatchToArrayControlProps, - mapStateToArrayControlProps, - RankedTester, - rankWith, - setReadonly, - StatePropsOfArrayControl, - uiTypeIs, -} from '@jsonforms/core'; - -const keywords = ['#', 'properties', 'items']; - -export const removeSchemaKeywords = (path: string) => { - return decode( - path - .split('/') - .filter((s) => !some(keywords, (key) => key === s)) - .join('.') - ); -}; - -@Component({ - selector: 'jsonforms-list-with-detail-master', - template: ` - - - - {{ - translations.noDataMessage - }} - - {{ item.label || 'No label set' }} - - - - - - - - - - `, - styles: [ - ` - /* TODO(mdc-migration): The following rule targets internal classes of list that may no longer apply for the MDC version. */ - mat-list-item.selected { - background: rgba(0, 0, 0, 0.04); - } - .container { - height: 100vh; - } - .content { - padding: 15px; - background-color: #fff; - } - .add-button { - float: right; - margin-top: 0.5em; - margin-right: 0.25em; - } - .button { - float: right; - margin-right: 0.25em; - } - .item-button { - position: absolute; - top: 0; - right: 0; - } - .hide { - display: none; - } - .show { - display: inline-block; - } - mat-sidenav { - width: 20%; - } - `, - ], - changeDetection: ChangeDetectionStrategy.OnPush, -}) -export class MasterListComponent - extends JsonFormsArrayControl - implements OnInit -{ - masterItems: any[]; - selectedItem: any; - selectedItemIdx: number; - addItem: (path: string, value: any) => () => void; - removeItems: (path: string, toDelete: number[]) => () => void; - highlightedIdx: number; - translations: ArrayTranslations; - - constructor( - jsonformsService: JsonFormsAngularService, - private changeDetectorRef: ChangeDetectorRef - ) { - super(jsonformsService); - } - - onListItemHover(idx: number) { - this.highlightedIdx = idx; - } - - trackElement(_index: number, element: any) { - return element ? element.label : null; - } - - ngOnInit() { - super.ngOnInit(); - const dispatch = this.jsonFormsService.updateCore.bind( - this.jsonFormsService - ); - const { addItem, removeItems } = mapDispatchToArrayControlProps(dispatch); - this.addItem = addItem; - this.removeItems = removeItems; - } - - mapAdditionalProps( - props: ArrayControlProps & { translations: ArrayTranslations } - ) { - const { data, path, schema, uischema } = props; - const controlElement = uischema as ControlElement; - this.propsPath = props.path; - const detailUISchema = findUISchema( - props.uischemas, - schema, - `${controlElement.scope}/items`, - props.path, - 'VerticalLayout', - controlElement, - props.rootSchema - ); - - if (!this.isEnabled()) { - setReadonly(detailUISchema); - } - - this.translations = props.translations; - - const masterItems = (data || []).map((d: any, index: number) => { - const labelRefInstancePath = - controlElement.options?.labelRef && - removeSchemaKeywords(controlElement.options.labelRef); - const isPrimitive = d !== undefined && typeof d !== 'object'; - const masterItem = { - label: isPrimitive - ? d.toString() - : get(d, labelRefInstancePath ?? getFirstPrimitiveProp(schema)), - data: d, - path: `${path}.${index}`, - schema, - uischema: detailUISchema, - }; - return masterItem; - }); - this.masterItems = masterItems; - let newSelectedIdx = -1; - let newSelectedItem; - if (this.masterItems.length === 0) { - // unset select if no elements anymore - this.selectedItem = undefined; - this.selectedItemIdx = -1; - } else if (this.selectedItemIdx >= this.masterItems.length) { - // the previous index is to high, reduce it to the maximal possible - newSelectedIdx = this.masterItems.length - 1; - newSelectedItem = this.masterItems[newSelectedIdx]; - } else if ( - this.selectedItemIdx !== -1 && - this.selectedItemIdx < this.masterItems.length - ) { - newSelectedIdx = this.selectedItemIdx; - newSelectedItem = this.masterItems[this.selectedItemIdx]; - } - - if ( - newSelectedItem !== undefined && - this.selectedItem !== undefined && - (newSelectedItem.label === this.selectedItem.label || - newSelectedItem.path === this.selectedItem.path) - ) { - // after checking that we are on the same path, set selection - this.selectedItem = newSelectedItem; - this.selectedItemIdx = newSelectedIdx; - } else if (this.masterItems.length > 0) { - // pre-select 1st entry if the previous selected element as fallback - this.selectedItem = this.masterItems[0]; - this.selectedItemIdx = 0; - } - this.changeDetectorRef.markForCheck(); - } - - onSelect(item: any, idx: number): void { - this.selectedItem = item; - this.selectedItemIdx = idx; - } - - onAddClick() { - this.addItem( - this.propsPath, - createDefaultValue(this.scopedSchema, this.rootSchema) - )(); - } - - onDeleteClick(item: number) { - this.removeItems(this.propsPath, [item])(); - } - - protected mapToProps( - state: JsonFormsState - ): StatePropsOfArrayControl & { translations: ArrayTranslations } { - const props = mapStateToArrayControlProps(state, this.getOwnProps()); - const t = - state.jsonforms.i18n?.translate ?? defaultJsonFormsI18nState.translate; - const translations = getArrayTranslations( - t, - arrayDefaultTranslations, - props.i18nKeyPrefix, - props.label - ); - return { ...props, translations }; - } -} - -export const masterDetailTester: RankedTester = rankWith( - 4, - uiTypeIs('ListWithDetail') -); diff --git a/packages/angular-material/src/library/other/object.renderer.ts b/packages/angular-material/src/library/other/object.renderer.ts deleted file mode 100644 index cdc0b2e4bc..0000000000 --- a/packages/angular-material/src/library/other/object.renderer.ts +++ /dev/null @@ -1,106 +0,0 @@ -/* - The MIT License - - Copyright (c) 2017-2019 EclipseSource Munich - https://github.com/eclipsesource/jsonforms - - Permission is hereby granted, free of charge, to any person obtaining a copy - of this software and associated documentation files (the "Software"), to deal - in the Software without restriction, including without limitation the rights - to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - copies of the Software, and to permit persons to whom the Software is - furnished to do so, subject to the following conditions: - - The above copyright notice and this permission notice shall be included in - all copies or substantial portions of the Software. - - THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - THE SOFTWARE. -*/ -import isEmpty from 'lodash/isEmpty'; -import startCase from 'lodash/startCase'; -import { ChangeDetectionStrategy, Component } from '@angular/core'; -import { - JsonFormsAngularService, - JsonFormsControlWithDetail, -} from '@jsonforms/angular'; -import { - ControlWithDetailProps, - findUISchema, - Generate, - GroupLayout, - isObjectControl, - RankedTester, - rankWith, - setReadonly, - UISchemaElement, -} from '@jsonforms/core'; -import { cloneDeep } from 'lodash'; - -@Component({ - selector: 'ObjectRenderer', - template: ` - - - - - `, - styles: [ - ` - .object-layout { - padding: 16px; - } - `, - ], - changeDetection: ChangeDetectionStrategy.OnPush, -}) -export class ObjectControlRenderer extends JsonFormsControlWithDetail { - detailUiSchema: UISchemaElement; - constructor(jsonformsService: JsonFormsAngularService) { - super(jsonformsService); - } - mapAdditionalProps(props: ControlWithDetailProps) { - this.detailUiSchema = findUISchema( - props.uischemas, - props.schema, - props.uischema.scope, - props.path, - () => { - const newSchema = cloneDeep(props.schema); - // delete unsupported operators - delete newSchema.oneOf; - delete newSchema.anyOf; - delete newSchema.allOf; - return Generate.uiSchema( - newSchema, - 'Group', - undefined, - this.rootSchema - ); - }, - props.uischema, - props.rootSchema - ); - if (isEmpty(props.path)) { - this.detailUiSchema.type = 'VerticalLayout'; - } else { - (this.detailUiSchema as GroupLayout).label = startCase(props.path); - } - if (!this.isEnabled()) { - setReadonly(this.detailUiSchema); - } - } -} -export const ObjectControlRendererTester: RankedTester = rankWith( - 2, - isObjectControl -); diff --git a/packages/angular-material/src/library/other/table.renderer.ts b/packages/angular-material/src/library/other/table.renderer.ts deleted file mode 100644 index 3be3d7aaa5..0000000000 --- a/packages/angular-material/src/library/other/table.renderer.ts +++ /dev/null @@ -1,285 +0,0 @@ -/* - The MIT License - - Copyright (c) 2017-2019 EclipseSource Munich - https://github.com/eclipsesource/jsonforms - - Permission is hereby granted, free of charge, to any person obtaining a copy - of this software and associated documentation files (the "Software"), to deal - in the Software without restriction, including without limitation the rights - to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - copies of the Software, and to permit persons to whom the Software is - furnished to do so, subject to the following conditions: - - The above copyright notice and this permission notice shall be included in - all copies or substantial portions of the Software. - - THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - THE SOFTWARE. -*/ -import startCase from 'lodash/startCase'; -import { Component, OnInit, Pipe, PipeTransform } from '@angular/core'; -import { - JsonFormsAngularService, - JsonFormsArrayControl, -} from '@jsonforms/angular'; -import { - ArrayControlProps, - ArrayTranslations, - ControlElement, - createDefaultValue, - deriveTypes, - encode, - isObjectArrayControl, - isPrimitiveArrayControl, - JsonSchema, - mapDispatchToArrayControlProps, - or, - OwnPropsOfRenderer, - Paths, - RankedTester, - rankWith, - setReadonly, - UISchemaElement, -} from '@jsonforms/core'; - -@Component({ - selector: 'TableRenderer', - template: ` -
- - - - - - - - - - - - - - - - - - -
- -
- - - -
{{ item.header }} - -
-
- `, - styles: [ - 'table {width: 100%;}', - '.cdk-column-action { width: 15%;}', - '.sort-column { min-width: 12vw;}', - '.table-container {max-width: 100%; overflow: auto;}', - ], -}) -export class TableRenderer extends JsonFormsArrayControl implements OnInit { - detailUiSchema: UISchemaElement; - displayedColumns: string[]; - items: ColumnDescription[]; - readonly columnsToIgnore = ['array', 'object']; - addItem: (path: string, value: any) => () => void; - moveItemUp: (path: string, index: number) => () => void; - moveItemDown: (path: string, index: number) => () => void; - removeItems: (path: string, toDelete: number[]) => () => void; - translations: ArrayTranslations = {}; - - constructor(jsonformsService: JsonFormsAngularService) { - super(jsonformsService); - } - trackElement(index: number, _element: any) { - return index ? index : null; - } - mapAdditionalProps( - props: ArrayControlProps & { translations: ArrayTranslations } - ) { - this.items = this.generateCells(props.schema, props.path); - this.displayedColumns = this.items.map((item) => item.property); - if (this.isEnabled()) { - this.displayedColumns.push('action'); - } - this.translations = props.translations; - } - - remove(index: number): void { - this.removeItems(this.propsPath, [index])(); - } - add(): void { - this.addItem( - this.propsPath, - createDefaultValue(this.scopedSchema, this.rootSchema) - )(); - } - up(index: number): void { - this.moveItemUp(this.propsPath, index)(); - } - down(index: number): void { - this.moveItemDown(this.propsPath, index)(); - } - ngOnInit() { - super.ngOnInit(); - - const { addItem, removeItems, moveUp, moveDown } = - mapDispatchToArrayControlProps( - this.jsonFormsService.updateCore.bind(this.jsonFormsService) - ); - this.addItem = addItem; - this.moveItemUp = moveUp; - this.moveItemDown = moveDown; - this.removeItems = removeItems; - } - - generateCells = ( - schema: JsonSchema, - rowPath: string - ): ColumnDescription[] => { - if (schema.type === 'object') { - return this.getValidColumnProps(schema).map((prop) => { - const encProp = encode(prop); - const uischema = controlWithoutLabel(`#/properties/${encProp}`); - if (!this.isEnabled()) { - setReadonly(uischema); - } - return { - property: prop, - header: startCase(prop), - props: { - schema: schema, - uischema, - path: rowPath, - }, - }; - }); - } - // needed to correctly render input control for multi attributes - return [ - { - property: 'DUMMY', - header: this.label, - props: { - schema: schema, - uischema: controlWithoutLabel(`#`), - path: rowPath, - }, - }, - ]; - }; - - getValidColumnProps = (scopedSchema: JsonSchema) => { - if (scopedSchema.type === 'object') { - return Object.keys(scopedSchema.properties).filter((prop) => { - const types = deriveTypes(scopedSchema.properties[prop]); - if (types.length > 1) { - return false; - } - return this.columnsToIgnore.indexOf(types[0]) === -1; - }); - } - // primitives - return ['']; - }; -} -export const TableRendererTester: RankedTester = rankWith( - 3, - or(isObjectArrayControl, isPrimitiveArrayControl) -); - -interface ColumnDescription { - property: string; - header: string; - props: OwnPropsOfRenderer; -} - -export const controlWithoutLabel = (scope: string): ControlElement => ({ - type: 'Control', - scope: scope, - label: false, -}); - -@Pipe({ name: 'getProps' }) -export class GetProps implements PipeTransform { - transform(index: number, props: OwnPropsOfRenderer) { - const rowPath = Paths.compose(props.path, `${index}`); - return { - schema: props.schema, - uischema: props.uischema, - path: rowPath, - }; - } -} diff --git a/packages/angular-material/src/library/other/util.ts b/packages/angular-material/src/library/other/util.ts deleted file mode 100644 index 7672002873..0000000000 --- a/packages/angular-material/src/library/other/util.ts +++ /dev/null @@ -1,52 +0,0 @@ -/* - The MIT License - - Copyright (c) 2017-2019 EclipseSource Munich - https://github.com/eclipsesource/jsonforms - - Permission is hereby granted, free of charge, to any person obtaining a copy - of this software and associated documentation files (the "Software"), to deal - in the Software without restriction, including without limitation the rights - to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - copies of the Software, and to permit persons to whom the Software is - furnished to do so, subject to the following conditions: - - The above copyright notice and this permission notice shall be included in - all copies or substantial portions of the Software. - - THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - THE SOFTWARE. -*/ -import { - ControlElement, - getAjv, - getData, - isVisible, - JsonFormsState, - OwnPropsOfRenderer, -} from '@jsonforms/core'; - -export const controlWithoutLabel = (scope: string): ControlElement => ({ - type: 'Control', - scope: scope, - label: false, -}); - -export const mapStateToVisible = ( - state: JsonFormsState, - ownProps: OwnPropsOfRenderer -) => { - const visible = - ownProps.visible !== undefined - ? ownProps.visible - : isVisible(ownProps.uischema, getData(state), undefined, getAjv(state)); - - return { - visible, - }; -}; diff --git a/packages/angular-material/src/library/util/date-format.ts b/packages/angular-material/src/library/util/date-format.ts deleted file mode 100644 index 95db12e74d..0000000000 --- a/packages/angular-material/src/library/util/date-format.ts +++ /dev/null @@ -1,24 +0,0 @@ -import { Injectable } from '@angular/core'; - -@Injectable() -export class MyFormat { - displayFormat = 'M/D/YYYY'; - - setDisplayFormat(displayFormat: string) { - this.displayFormat = displayFormat; - } - - get display() { - return { - monthYearLabel: 'YYYY-MM', - dateA11yLabel: 'YYYY-MM-DD', - monthYearA11yLabel: 'YYYY-MM', - dateInput: this.displayFormat, - }; - } - get parse() { - return { - dateInput: this.displayFormat, - }; - } -} diff --git a/packages/angular-material/src/library/util/dayjs-date-adapter.ts b/packages/angular-material/src/library/util/dayjs-date-adapter.ts deleted file mode 100644 index b1fbf3c152..0000000000 --- a/packages/angular-material/src/library/util/dayjs-date-adapter.ts +++ /dev/null @@ -1,101 +0,0 @@ -/* - The MIT License - - Copyright (c) 2017-2019 EclipseSource Munich - https://github.com/eclipsesource/jsonforms - - Permission is hereby granted, free of charge, to any person obtaining a copy - of this software and associated documentation files (the "Software"), to deal - in the Software without restriction, including without limitation the rights - to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - copies of the Software, and to permit persons to whom the Software is - furnished to do so, subject to the following conditions: - - The above copyright notice and this permission notice shall be included in - all copies or substantial portions of the Software. - - THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - THE SOFTWARE. -*/ - -import { Injectable } from '@angular/core'; -import { NativeDateAdapter } from '@angular/material/core'; -import { defaultDateFormat } from '@jsonforms/core'; -import dayjs from 'dayjs'; -import customParsing from 'dayjs/plugin/customParseFormat'; - -// allows to parse date strings with custom format -dayjs.extend(customParsing); - -/** - * date adapter for dayjs to parse and format dates - */ -@Injectable() -export class DayJsDateAdapter extends NativeDateAdapter { - saveFormat: string = defaultDateFormat; - - setSaveFormat(format: string) { - this.saveFormat = format; - } - - /** - * parses a given data prop string in the save-format into a date object - * @param value date string to be parsed - * @returns date object or null if parsing failed - */ - parseSaveFormat(value: string): Date | null { - return this.parse(value, this.saveFormat); - } - - parse(value: string, format: string): Date | null { - if (!value) { - return null; - } - const date = dayjs(value, format); - - if (date.isValid()) { - return date.toDate(); - } else { - return null; - } - } - - toSaveFormat(value: Date) { - if (!value) { - return undefined; - } - const date = dayjs(value); - if (date.isValid()) { - return date.format(this.saveFormat); - } else { - return undefined; - } - } - - /** - * transforms the date to a string representation for display - * @param date date to be formatted - * @param displayFormat format to be used for formatting the date e.g. YYYY-MM-DD - * @returns string representation of the date - */ - format(date: Date, displayFormat: string): string { - return dayjs(date).format(displayFormat); - } - - deserialize(value: any): Date | null { - if (!value) { - return null; - } - const date = dayjs(value); - if (date.isValid()) { - return date.toDate(); - } else { - return null; - } - } -} diff --git a/packages/angular-material/src/public_api.ts b/packages/angular-material/src/public_api.ts deleted file mode 100644 index 4b02e6973f..0000000000 --- a/packages/angular-material/src/public_api.ts +++ /dev/null @@ -1 +0,0 @@ -export * from './library'; diff --git a/packages/angular-material/test-runner.js b/packages/angular-material/test-runner.js deleted file mode 100644 index 26591cde8a..0000000000 --- a/packages/angular-material/test-runner.js +++ /dev/null @@ -1,129 +0,0 @@ -const yargs = require('yargs/yargs'); -const { hideBin } = require('yargs/helpers'); -const path = require('path'); -const ngCore = require('@angular-devkit/core'); -const execute = require('@angular-devkit/build-angular/src/builders/karma').execute; - -// Dumped from debug, subject to changes -const defaultWebpackOptions = { - assets: [], - scripts: [], - styles: [], - inlineStyleLanguage: 'css', - stylePreprocessorOptions: { - includePaths: [], - }, - include: [ - '../test/**/*.spec.ts' - ], - exclude: [], - sourceMap: true, - progress: true, - codeCoverage: false, - codeCoverageExclude: [], - fileReplacements: [], - reporters: [] -}; - -const normalizeOptions = (options, context) => { - return { - ...defaultWebpackOptions, - ...options - } -}; - -const webpackConfigTransform = (options, context, webpackConfig) => { - const projectRoot = context.getProjectMetadata().root; - webpackConfig.resolve.modules.push(projectRoot + '/node_modules'); - return webpackConfig; -}; - -const karmaConfigOptionsTransform = (options, context, karmaConfigOptions) => { - /* FYI - type KarmaConfigOptions = ConfigOptions & { - buildWebpack?: unknown; - configFile?: string; - }; - */ - return karmaConfigOptions; -}; -const main = async (params) => new Promise((resolve, reject) => { - const singleRun = !!params.singleRun; - const coverage = !!params.coverage; - const project = 'angular-material'; - const target = 'test'; - const configuration = ''; - const workspaceRoot = path.join(process.cwd(), '../..'); - const options = { - singleRun, - watch: !singleRun, // angular uses the opposite of watch as single run in karmaConfigOptions - coverage, - codeCoverage: coverage, - polyfills: [ - 'zone.js', - 'zone.js/testing' - ], - tsConfig: 'packages/angular-material/tsconfig.spec.json', - karmaConfig: 'packages/angular-material/karma.conf.js' - }; - const root = `packages/${project}`; - const sourceRoot = root + '/src'; - const teardownLogics = []; - const context = { - workspaceRoot, - logger: new ngCore.logging.Logger(`${project}:${target}:`), - target: { - project, - configuration, - target - }, - getProjectMetadata: (projectName) => ({ - root, - sourceRoot - }), - getBuilderNameForTarget: () => '@angular-devkit/build-angular:karma', - getTargetOptions: (target) => ({...options}), - validateOptions: (options) => options, - addTeardown: (teardown) => { - teardownLogics.push(teardown); - } - }; - - const transforms = { - webpackConfiguration: webpackConfigTransform.bind(null, options, context), - karmaOptions: karmaConfigOptionsTransform.bind(null, options, context) - }; - let exitCode = 1; - execute(normalizeOptions(options, context), context, transforms).subscribe({ - next: out => { - if (out.success) { - exitCode = 0; - } - }, - error: reject, - complete: () => { - if (!exitCode) return resolve(); - reject(); - } - }); - return exitCode; -}); - -main( - yargs(hideBin(process.argv)).options({ - singleRun: { - alias: 'single-run', - type: 'boolean' - }, - codeCoverage: { - alias: 'coverage', - type: 'boolean' - } - }).parseSync() -) -.then(() => { - process.exit(0); -}) -.catch(err => { - process.exit(1); -}); \ No newline at end of file diff --git a/packages/angular-material/test/autocomplete-control.spec.ts b/packages/angular-material/test/autocomplete-control.spec.ts deleted file mode 100644 index 4ced222838..0000000000 --- a/packages/angular-material/test/autocomplete-control.spec.ts +++ /dev/null @@ -1,375 +0,0 @@ -/* - The MIT License - - Copyright (c) 2017-2019 EclipseSource Munich - https://github.com/eclipsesource/jsonforms - - Permission is hereby granted, free of charge, to any person obtaining a copy - of this software and associated documentation files (the "Software"), to deal - in the Software without restriction, including without limitation the rights - to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - copies of the Software, and to permit persons to whom the Software is - furnished to do so, subject to the following conditions: - - The above copyright notice and this permission notice shall be included in - all copies or substantial portions of the Software. - - THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - THE SOFTWARE. -*/ -import { - MatAutocompleteModule, - MatAutocompleteSelectedEvent, -} from '@angular/material/autocomplete'; -import { MatError, MatFormFieldModule } from '@angular/material/form-field'; -import { MatInputModule } from '@angular/material/input'; -import { DebugElement } from '@angular/core'; -import { - ComponentFixture, - fakeAsync, - TestBed, - tick, - waitForAsync, -} from '@angular/core/testing'; -import { ReactiveFormsModule } from '@angular/forms'; -import { By } from '@angular/platform-browser'; -import { NoopAnimationsModule } from '@angular/platform-browser/animations'; -import { - ErrorTestExpectation, - setupMockStore, - getJsonFormsService, -} from './common'; -import { ControlElement, JsonSchema, Actions } from '@jsonforms/core'; -import { AutocompleteControlRenderer } from '../src'; -import { JsonFormsAngularService } from '@jsonforms/angular'; -import { ErrorObject } from 'ajv'; -import { initTestEnvironment } from './test'; -import { HarnessLoader } from '@angular/cdk/testing'; -import { TestbedHarnessEnvironment } from '@angular/cdk/testing/testbed'; -import { MatAutocompleteHarness } from '@angular/material/autocomplete/testing'; - -const data = { foo: 'A' }; -const schema: JsonSchema = { - type: 'object', - properties: { - foo: { - type: 'string', - enum: ['A', 'B', 'C'], - }, - }, -}; -const uischema: ControlElement = { - type: 'Control', - scope: '#/properties/foo', -}; - -const imports = [ - MatAutocompleteModule, - MatInputModule, - MatFormFieldModule, - NoopAnimationsModule, - ReactiveFormsModule, -]; -const providers = [JsonFormsAngularService]; -const componentUT: any = AutocompleteControlRenderer; -const errorTest: ErrorTestExpectation = { - errorInstance: MatError, - numberOfElements: 1, - indexOfElement: 0, -}; - -initTestEnvironment(); - -describe('Autocomplete control Base Tests', () => { - let fixture: ComponentFixture; - let component: AutocompleteControlRenderer; - let inputElement: HTMLInputElement; - beforeEach(waitForAsync(() => { - TestBed.configureTestingModule({ - declarations: [componentUT], - imports: imports, - providers: providers, - }).compileComponents(); - })); - beforeEach(() => { - fixture = TestBed.createComponent(componentUT); - component = fixture.componentInstance; - - inputElement = fixture.debugElement.query(By.css('input')).nativeElement; - }); - - it('should render', fakeAsync(() => { - setupMockStore(fixture, { uischema, schema, data }); - getJsonFormsService(component).updateCore( - Actions.init(data, schema, uischema) - ); - component.ngOnInit(); - fixture.detectChanges(); - tick(); - expect(component.data).toBe('A'); - expect(inputElement.value).toBe('A'); - expect(inputElement.disabled).toBe(false); - })); - - it('should support updating the state', fakeAsync(() => { - setupMockStore(fixture, { uischema, schema, data }); - getJsonFormsService(component).updateCore( - Actions.init(data, schema, uischema) - ); - component.ngOnInit(); - fixture.detectChanges(); - tick(); - getJsonFormsService(component).updateCore(Actions.update('foo', () => 'B')); - tick(); - fixture.detectChanges(); - expect(component.data).toBe('B'); - expect(inputElement.value).toBe('B'); - })); - - it('should update with undefined value', () => { - setupMockStore(fixture, { uischema, schema, data }); - getJsonFormsService(component).updateCore( - Actions.init(data, schema, uischema) - ); - component.ngOnInit(); - fixture.detectChanges(); - - getJsonFormsService(component).updateCore( - Actions.update('foo', () => undefined) - ); - fixture.detectChanges(); - expect(component.data).toBe(undefined); - expect(inputElement.value).toBe(''); - }); - it('should update with null value', () => { - setupMockStore(fixture, { uischema, schema, data }); - getJsonFormsService(component).updateCore( - Actions.init(data, schema, uischema) - ); - fixture.detectChanges(); - component.ngOnInit(); - - getJsonFormsService(component).updateCore( - Actions.update('foo', () => null) - ); - fixture.detectChanges(); - expect(component.data).toBe(null); - expect(inputElement.value).toBe(''); - }); - it('should not update with wrong ref', fakeAsync(() => { - setupMockStore(fixture, { uischema, schema, data }); - getJsonFormsService(component).updateCore( - Actions.init(data, schema, uischema) - ); - component.ngOnInit(); - fixture.detectChanges(); - tick(); - getJsonFormsService(component).updateCore(Actions.update('foo', () => 'A')); - getJsonFormsService(component).updateCore(Actions.update('bar', () => 'B')); - fixture.detectChanges(); - tick(); - expect(component.data).toBe('A'); - expect(inputElement.value).toBe('A'); - })); - // store needed as we evaluate the calculated enabled value to disable/enable the control - it('can be disabled', () => { - setupMockStore(fixture, { uischema, schema, data }); - getJsonFormsService(component).updateCore( - Actions.init(data, schema, uischema) - ); - component.disabled = true; - component.ngOnInit(); - fixture.detectChanges(); - expect(inputElement.disabled).toBe(true); - }); - it('can be hidden', () => { - setupMockStore(fixture, { uischema, schema, data }); - getJsonFormsService(component).updateCore( - Actions.init(data, schema, uischema) - ); - component.visible = false; - component.ngOnInit(); - fixture.detectChanges(); - const hasDisplayNone = - 'none' === fixture.nativeElement.children[0].style.display; - const hasHidden = fixture.nativeElement.children[0].hidden; - expect(hasDisplayNone || hasHidden).toBeTruthy(); - }); - - it('id should be present in output', () => { - setupMockStore(fixture, { uischema, schema, data }); - component.id = 'myId'; - getJsonFormsService(component).updateCore( - Actions.init(data, schema, uischema) - ); - - fixture.detectChanges(); - component.ngOnInit(); - expect(inputElement.id).toBe('myId'); - }); -}); -describe('AutoComplete control Input Event Tests', () => { - let fixture: ComponentFixture; - let component: AutocompleteControlRenderer; - let loader: HarnessLoader; - beforeEach(waitForAsync(() => { - TestBed.configureTestingModule({ - declarations: [componentUT], - imports: imports, - providers: [...providers], - }).compileComponents(); - })); - beforeEach(waitForAsync(() => { - fixture = TestBed.createComponent(componentUT); - component = fixture.componentInstance; - loader = TestbedHarnessEnvironment.loader(fixture); - })); - - it('should update via input event', fakeAsync(async () => { - setupMockStore(fixture, { uischema, schema, data }); - getJsonFormsService(component).updateCore( - Actions.init(data, schema, uischema) - ); - - component.ngOnInit(); - fixture.detectChanges(); - - const spy = spyOn(component, 'onSelect'); - - await (await loader.getHarness(MatAutocompleteHarness)).focus(); - fixture.detectChanges(); - - await ( - await loader.getHarness(MatAutocompleteHarness) - ).selectOption({ text: 'B' }); - tick(); - fixture.detectChanges(); - - expect(spy).toHaveBeenCalled(); - const event = spy.calls.mostRecent() - .args[0] as MatAutocompleteSelectedEvent; - - expect(event.option.value).toBe('B'); - })); - it('options should prefer own props', fakeAsync(async () => { - setupMockStore(fixture, { uischema, schema, data }); - getJsonFormsService(component).updateCore( - Actions.init(data, schema, uischema) - ); - component.options = ['X', 'Y', 'Z']; - - component.ngOnInit(); - fixture.detectChanges(); - const spy = spyOn(component, 'onSelect'); - - await (await loader.getHarness(MatAutocompleteHarness)).focus(); - fixture.detectChanges(); - - await ( - await loader.getHarness(MatAutocompleteHarness) - ).selectOption({ text: 'Y' }); - fixture.detectChanges(); - tick(); - - const event = spy.calls.mostRecent() - .args[0] as MatAutocompleteSelectedEvent; - expect(event.option.value).toBe('Y'); - })); -}); -describe('AutoComplete control Error Tests', () => { - let fixture: ComponentFixture; - let component: AutocompleteControlRenderer; - beforeEach(waitForAsync(() => { - TestBed.configureTestingModule({ - declarations: [componentUT], - imports: imports, - providers: providers, - }).compileComponents(); - })); - beforeEach(() => { - fixture = TestBed.createComponent(componentUT); - component = fixture.componentInstance; - }); - it('should display errors', () => { - const errors: ErrorObject[] = [ - { - instancePath: '/foo', - message: 'Hi, this is me, test error!', - params: {}, - keyword: '', - schemaPath: '', - }, - ]; - setupMockStore(fixture, { - uischema, - schema, - data, - }); - const formsService = getJsonFormsService(component); - formsService.updateCore(Actions.updateErrors(errors)); - formsService.refresh(); - - component.ngOnInit(); - fixture.detectChanges(); - const debugErrors: DebugElement[] = fixture.debugElement.queryAll( - By.directive(errorTest.errorInstance) - ); - expect(debugErrors.length).toBe(errorTest.numberOfElements); - expect( - debugErrors[errorTest.indexOfElement].nativeElement.textContent - ).toBe('Hi, this is me, test error!'); - }); -}); - -describe('AutoComplete control updateFilter function', () => { - let fixture: ComponentFixture; - let component: AutocompleteControlRenderer; - - beforeEach(waitForAsync(() => { - TestBed.configureTestingModule({ - declarations: [componentUT], - imports: imports, - providers: providers, - }).compileComponents(); - })); - - beforeEach(() => { - fixture = TestBed.createComponent(componentUT); - component = fixture.componentInstance; - }); - - it('should not filter options on ENTER key press', () => { - component.shouldFilter = false; - component.options = ['X', 'Y', 'Z']; - setupMockStore(fixture, { uischema, schema, data }); - getJsonFormsService(component).updateCore( - Actions.init(data, schema, uischema) - ); - component.ngOnInit(); - fixture.detectChanges(); - component.updateFilter({ keyCode: 13 }); - fixture.detectChanges(); - expect(component.shouldFilter).toBe(false); - }); - - it('should filter options when a key other than ENTER is pressed', () => { - component.shouldFilter = false; - component.options = ['X', 'Y', 'Z']; - setupMockStore(fixture, { uischema, schema, data }); - getJsonFormsService(component).updateCore( - Actions.init(data, schema, uischema) - ); - component.ngOnInit(); - fixture.detectChanges(); - - component.updateFilter({ keyCode: 65 }); - fixture.detectChanges(); - - expect(component.shouldFilter).toBe(true); - }); -}); diff --git a/packages/angular-material/test/boolean-control.spec.ts b/packages/angular-material/test/boolean-control.spec.ts deleted file mode 100644 index d0b4e7da83..0000000000 --- a/packages/angular-material/test/boolean-control.spec.ts +++ /dev/null @@ -1,82 +0,0 @@ -/* - The MIT License - - Copyright (c) 2017-2019 EclipseSource Munich - https://github.com/eclipsesource/jsonforms - - Permission is hereby granted, free of charge, to any person obtaining a copy - of this software and associated documentation files (the "Software"), to deal - in the Software without restriction, including without limitation the rights - to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - copies of the Software, and to permit persons to whom the Software is - furnished to do so, subject to the following conditions: - - The above copyright notice and this permission notice shall be included in - all copies or substantial portions of the Software. - - THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - THE SOFTWARE. -*/ -import { MatCheckbox, MatCheckboxModule } from '@angular/material/checkbox'; -import { MatError, MatFormFieldModule } from '@angular/material/form-field'; -import { - booleanBaseTest, - booleanErrorTest, - booleanInputEventTest, - ErrorTestExpectation, -} from './common'; -import { BooleanControlRenderer, booleanControlTester } from '../src'; -import { JsonFormsAngularService } from '@jsonforms/angular'; -import { initTestEnvironment } from './test'; - -initTestEnvironment(); - -describe('Material boolean field tester', () => { - const uischema = { - type: 'Control', - scope: '#/properties/foo', - }; - - it('should succeed', () => { - expect( - booleanControlTester( - uischema, - { - type: 'object', - properties: { - foo: { - type: 'boolean', - }, - }, - }, - undefined - ) - ).toBe(2); - }); -}); -const imports = [MatCheckboxModule, MatFormFieldModule]; -const providers = [JsonFormsAngularService]; -const componentUT: any = BooleanControlRenderer; -const errorTest: ErrorTestExpectation = { - errorInstance: MatError, - numberOfElements: 1, - indexOfElement: 0, -}; -const testConfig = { imports, providers, componentUT }; -describe( - 'Boolean control Base Tests', - booleanBaseTest(testConfig, MatCheckbox) -); -describe( - 'Boolean control Input Event Tests', - booleanInputEventTest(testConfig, MatCheckbox, 'label') -); -describe( - 'Boolean control Error Tests', - booleanErrorTest(testConfig, MatCheckbox, errorTest) -); diff --git a/packages/angular-material/test/categorization-tab-layout.spec.ts b/packages/angular-material/test/categorization-tab-layout.spec.ts deleted file mode 100644 index 717f78309d..0000000000 --- a/packages/angular-material/test/categorization-tab-layout.spec.ts +++ /dev/null @@ -1,332 +0,0 @@ -/* - The MIT License - - Copyright (c) 2017-2019 EclipseSource Munich - https://github.com/eclipsesource/jsonforms - - Permission is hereby granted, free of charge, to any person obtaining a copy - of this software and associated documentation files (the "Software"), to deal - in the Software without restriction, including without limitation the rights - to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - copies of the Software, and to permit persons to whom the Software is - furnished to do so, subject to the following conditions: - - The above copyright notice and this permission notice shall be included in - all copies or substantial portions of the Software. - - THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - THE SOFTWARE. -*/ -import { DebugElement } from '@angular/core'; -import { ComponentFixture, TestBed, waitForAsync } from '@angular/core/testing'; -import { - MatTab, - MatTabBody, - MatTabGroup, - MatTabsModule, -} from '@angular/material/tabs'; -import { By } from '@angular/platform-browser'; -import { NoopAnimationsModule } from '@angular/platform-browser/animations'; -import { - JsonFormsAngularService, - JsonFormsModule, - JsonFormsOutlet, -} from '@jsonforms/angular'; -import { - CategorizationTabLayoutRenderer, - TextControlRenderer, - TextControlRendererTester, -} from '../src'; -import { setupMockStore, getJsonFormsService } from './common'; -import { MatFormFieldModule } from '@angular/material/form-field'; -import { MatInputModule } from '@angular/material/input'; -import { ReactiveFormsModule } from '@angular/forms'; -import { CommonModule } from '@angular/common'; -import { initTestEnvironment } from './test'; - -const renderers = [ - { tester: TextControlRendererTester, renderer: TextControlRenderer }, -]; - -initTestEnvironment(); - -describe('Categorization tab layout', () => { - let fixture: ComponentFixture; - let component: any; - - const data = { foo: 'true' }; - const schema = { - type: 'object', - properties: { - foo: { - type: 'string', - }, - bar: { - type: 'string', - }, - }, - }; - - beforeEach(waitForAsync(() => { - TestBed.configureTestingModule({ - declarations: [CategorizationTabLayoutRenderer, TextControlRenderer], - imports: [ - CommonModule, - MatTabsModule, - NoopAnimationsModule, - JsonFormsModule, - MatFormFieldModule, - MatInputModule, - ReactiveFormsModule, - ], - providers: [JsonFormsAngularService], - }).compileComponents(); - - fixture = TestBed.createComponent(CategorizationTabLayoutRenderer); - component = fixture.componentInstance; - })); - - it('render categories initially', waitForAsync(() => { - const uischema = { - type: 'Categorization', - elements: [ - { - type: 'Category', - label: 'foo', - elements: [ - { - type: 'Control', - scope: '#/properties/foo', - }, - { - type: 'Control', - scope: '#/properties/bar', - }, - ], - }, - { - type: 'Category', - label: 'bar', - elements: [ - { - type: 'Control', - scope: '#/properties/bar', - }, - ], - }, - ], - }; - - setupMockStore(fixture, { uischema, schema, data }); - - fixture.detectChanges(); - fixture.whenRenderingDone().then(() => { - fixture.detectChanges(); - const tabGroupDE: DebugElement[] = fixture.debugElement.queryAll( - By.directive(MatTabGroup) - ); - expect(tabGroupDE.length).toBe(1); - const tabGroup: MatTabGroup = tabGroupDE[0].componentInstance; - expect(tabGroup._tabs.length).toBe(2); - const tab1: MatTab = tabGroup._tabs.first; - const tab2: MatTab = tabGroup._tabs.last; - expect(tab1.isActive).toBeTruthy(); - expect(tab2.isActive).toBeFalsy(); - expect(tab1.textLabel).toBe('foo'); - expect(tab2.textLabel).toBe('bar'); - expect(tab1.isActive).toBeTruthy(); - expect(tab2.isActive).toBeFalsy(); - expect(tab1.content.isAttached).toBeTruthy(); - expect(tab2.content.isAttached).toBeFalsy(); - - const contents: DebugElement[] = fixture.debugElement.queryAll( - By.directive(MatTabBody) - ); - const activeTabOutlets = contents[0].queryAll( - By.directive(JsonFormsOutlet) - ); - expect(activeTabOutlets.length).toBe(2); - - expect(fixture.nativeElement.children[0].style.display).not.toBe('none'); - }); - })); - - it('pass path and schema to children', waitForAsync(() => { - const uischema = { - type: 'Categorization', - elements: [ - { - type: 'Category', - label: 'foo', - elements: [ - { - type: 'Control', - scope: '#/properties/foo', - }, - ], - }, - ], - }; - setupMockStore(fixture, { uischema, schema, data }); - component.path = 'aa'; - const subSchema = { type: 'string' }; - component.schema = subSchema; - getJsonFormsService(component).init({ - renderers: renderers, - core: { - data: {}, - schema: schema, - uischema: undefined, - }, - }); - - fixture.detectChanges(); - fixture.whenRenderingDone().then(() => { - const contents: DebugElement[] = fixture.debugElement.queryAll( - By.directive(MatTabBody) - ); - const activeTabOutlets = contents[0].queryAll( - By.directive(TextControlRenderer) - ); - expect(activeTabOutlets[0].componentInstance.path).toBe('aa'); - expect(activeTabOutlets[0].componentInstance.schema).toBe(subSchema); - }); - })); - - it('add category', waitForAsync(() => { - const uischema = { - type: 'Categorization', - elements: [ - { - type: 'Category', - label: 'foo', - elements: [ - { - type: 'Control', - scope: '#/properties/foo', - }, - { - type: 'Control', - scope: '#/properties/bar', - }, - ], - }, - { - type: 'Category', - label: 'bar', - elements: [ - { - type: 'Control', - scope: '#/properties/bar', - }, - ], - }, - ], - }; - setupMockStore(fixture, { uischema, schema, data }); - fixture.detectChanges(); - fixture.whenRenderingDone().then(() => { - fixture.detectChanges(); - const tabGroupDE: DebugElement[] = fixture.debugElement.queryAll( - By.directive(MatTabGroup) - ); - const tabGroup: MatTabGroup = tabGroupDE[0].componentInstance; - expect(tabGroup._tabs.length).toBe(2); - - const newUischema = { - type: 'Categorization', - elements: [ - { - type: 'Category', - label: 'foo', - elements: [ - { - type: 'Control', - scope: '#/properties/foo', - }, - ], - }, - { - type: 'Category', - label: 'bar', - elements: [ - { - type: 'Control', - scope: '#/properties/bar', - }, - ], - }, - { - type: 'Category', - label: 'quux', - elements: [ - { - type: 'Control', - scope: '#/properties/bar', - }, - ], - }, - ], - }; - component.uischema = newUischema; - fixture.detectChanges(); - getJsonFormsService(component).setUiSchema(newUischema); - - fixture.whenRenderingDone().then(() => { - fixture.detectChanges(); - const tabGroupDE2: DebugElement[] = fixture.debugElement.queryAll( - By.directive(MatTabGroup) - ); - const tabGroup2: MatTabGroup = tabGroupDE2[0].componentInstance; - expect(tabGroup2._tabs.length).toBe(3); - const lastTab: MatTab = tabGroup2._tabs.last; - expect(lastTab.isActive).toBeFalsy(); - expect(lastTab.textLabel).toBe('quux'); - }); - }); - })); - - // TODO: broken due to https://github.com/angular/flex-layout/issues/848 - xit('can be hidden', waitForAsync(() => { - const uischema = { - type: 'Categorization', - elements: [ - { - type: 'Category', - label: 'foo', - elements: [ - { - type: 'Control', - scope: '#/properties/foo', - }, - { - type: 'Control', - scope: '#/properties/bar', - }, - ], - }, - { - type: 'Category', - label: 'bar', - elements: [ - { - type: 'Control', - scope: '#/properties/bar', - }, - ], - }, - ], - }; - setupMockStore(fixture, { uischema, schema, data }); - component.visible = false; - fixture.detectChanges(); - fixture.whenRenderingDone().then(() => { - expect(fixture.nativeElement.children[0].style.display).toBe('none'); - }); - })); -}); diff --git a/packages/angular-material/test/common/boolean.ts b/packages/angular-material/test/common/boolean.ts deleted file mode 100644 index 0e8a8b1975..0000000000 --- a/packages/angular-material/test/common/boolean.ts +++ /dev/null @@ -1,348 +0,0 @@ -/* - The MIT License - - Copyright (c) 2017-2019 EclipseSource Munich - https://github.com/eclipsesource/jsonforms - - Permission is hereby granted, free of charge, to any person obtaining a copy - of this software and associated documentation files (the "Software"), to deal - in the Software without restriction, including without limitation the rights - to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - copies of the Software, and to permit persons to whom the Software is - furnished to do so, subject to the following conditions: - - The above copyright notice and this permission notice shall be included in - all copies or substantial portions of the Software. - - THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - THE SOFTWARE. -*/ -import type { DebugElement, Type } from '@angular/core'; -import { By } from '@angular/platform-browser'; -import type { JsonFormsControl } from '@jsonforms/angular'; -import { ControlElement, JsonSchema, Actions } from '@jsonforms/core'; -import { - baseSetup, - ErrorTestExpectation, - TestConfig, - getJsonFormsService, -} from './util'; -import { ComponentFixture, TestBed } from '@angular/core/testing'; - -const prepareComponent = ( - testConfig: TestConfig, - instance: Type -) => { - const fixture = TestBed.createComponent(testConfig.componentUT); - const component = fixture.componentInstance; - const checkboxDebugElement = fixture.debugElement.query( - By.directive(instance) - ); - const checkboxInstance = checkboxDebugElement.componentInstance; - const checkboxNativeElement = checkboxDebugElement.nativeElement; - - return { fixture, component, checkboxInstance, checkboxNativeElement }; -}; - -const data = { foo: true }; -export const defaultBooleanTestSchema: JsonSchema = { - type: 'object', - properties: { - foo: { - type: 'boolean', - }, - }, -}; -const uischema: ControlElement = { - type: 'Control', - scope: '#/properties/foo', -}; -export const defaultBooleanTestData = { - data, - schema: defaultBooleanTestSchema, - uischema, -}; - -export const booleanBaseTest = - ( - testConfig: TestConfig, - instance: Type - ) => - () => { - let fixture: ComponentFixture; - let checkboxNativeElement: HTMLElement; - let checkboxInstance: any; - let component: C; - - baseSetup(testConfig); - - beforeEach(() => { - const preparedComponents = prepareComponent(testConfig, instance); - fixture = preparedComponents.fixture; - checkboxNativeElement = preparedComponents.checkboxNativeElement; - checkboxInstance = preparedComponents.checkboxInstance; - component = preparedComponents.component; - }); - - it('should render', () => { - component.uischema = uischema; - - getJsonFormsService(component).init({ - core: { - data: data, - schema: defaultBooleanTestSchema, - uischema: uischema, - }, - }); - component.ngOnInit(); - fixture.detectChanges(); - expect(component.data).toBe(true); - expect(checkboxInstance.checked).toBe(true); - expect(checkboxInstance.disabled).toBe(false); - // the component is wrapped in a div - const hasDisplayNone = - 'none' === fixture.nativeElement.children[0].style.display; - const hasHidden = fixture.nativeElement.children[0].hidden; - expect(hasDisplayNone || hasHidden).toBeFalsy(); - }); - it('should support updating the state', () => { - component.uischema = uischema; - - getJsonFormsService(component).init({ - core: { - data: data, - schema: defaultBooleanTestSchema, - uischema: uischema, - }, - }); - component.ngOnInit(); - fixture.detectChanges(); - - getJsonFormsService(component).updateCore( - Actions.update('foo', () => false) - ); - fixture.detectChanges(); - expect(component.data).toBe(false); - expect(checkboxInstance.checked).toBe(false); - }); - it('should update with undefined value', () => { - component.uischema = uischema; - - getJsonFormsService(component).init({ - core: { - data: data, - schema: defaultBooleanTestSchema, - uischema: uischema, - }, - }); - component.ngOnInit(); - fixture.detectChanges(); - - getJsonFormsService(component).updateCore( - Actions.update('foo', () => undefined) - ); - fixture.detectChanges(); - expect(component.data).toBe(undefined); - expect(checkboxInstance.checked).toBe(false); - }); - it('should update with null value', () => { - component.uischema = uischema; - - getJsonFormsService(component).init({ - core: { - data: data, - schema: defaultBooleanTestSchema, - uischema: uischema, - }, - }); - component.ngOnInit(); - fixture.detectChanges(); - - getJsonFormsService(component).updateCore( - Actions.update('foo', () => null) - ); - fixture.detectChanges(); - expect(component.data).toBe(null); - expect(checkboxInstance.checked).toBe(false); - }); - it('should not update with wrong ref', () => { - component.uischema = uischema; - - getJsonFormsService(component).init({ - core: { - data: data, - schema: defaultBooleanTestSchema, - uischema: uischema, - }, - }); - component.ngOnInit(); - fixture.detectChanges(); - - getJsonFormsService(component).updateCore( - Actions.update('foo', () => true) - ); - getJsonFormsService(component).updateCore( - Actions.update('bar', () => false) - ); - fixture.detectChanges(); - expect(component.data).toBe(true); - expect(checkboxInstance.checked).toBe(true); - }); - // store needed as we evaluate the calculated enabled value to disable/enable the control - it('can be disabled', () => { - component.uischema = uischema; - component.disabled = true; - - getJsonFormsService(component).init({ - core: { - data: data, - schema: defaultBooleanTestSchema, - uischema: uischema, - }, - }); - component.ngOnInit(); - fixture.detectChanges(); - expect(checkboxInstance.disabled).toBe(true); - }); - // store needed as we evaluate the calculated enabled value to disable/enable the control - it('can be hidden', () => { - component.uischema = uischema; - component.visible = false; - - getJsonFormsService(component).init({ - core: { - data: data, - schema: defaultBooleanTestSchema, - uischema: uischema, - }, - }); - component.ngOnInit(); - fixture.detectChanges(); - // the component is wrapped in a div - const hasDisplayNone = - 'none' === fixture.nativeElement.children[0].style.display; - const hasHidden = fixture.nativeElement.children[0].hidden; - expect(hasDisplayNone || hasHidden).toBeTruthy(); - }); - - it('id should be present in output', () => { - component.uischema = uischema; - component.id = 'myId'; - - getJsonFormsService(component).init({ - core: { - data: data, - schema: defaultBooleanTestSchema, - uischema: uischema, - }, - }); - component.ngOnInit(); - fixture.detectChanges(); - expect(checkboxNativeElement.id).toBe('myId'); - }); - }; -export const booleanInputEventTest = - ( - testConfig: TestConfig, - instance: Type, - selectorForClick: string - ) => - () => { - let fixture: ComponentFixture; - let checkboxNativeElement: HTMLElement; - let checkboxInstance: any; - let component: C & { onChange(evt: string): void }; - let elementToClick: any; - - baseSetup(testConfig); - - beforeEach(() => { - const preparedComponents = prepareComponent(testConfig, instance); - fixture = preparedComponents.fixture; - checkboxNativeElement = preparedComponents.checkboxNativeElement; - checkboxInstance = preparedComponents.checkboxInstance; - component = preparedComponents.component; - - elementToClick = checkboxNativeElement.querySelector(selectorForClick); - }); - - it('should update via input event', () => { - component.uischema = uischema; - getJsonFormsService(component).init({ - core: { - data: data, - schema: defaultBooleanTestSchema, - uischema: uischema, - }, - }); - fixture.detectChanges(); - component.ngOnInit(); - - const spy = spyOn(component, 'onChange'); - elementToClick.click(); - // trigger change detection - fixture.detectChanges(); - - expect(spy).toHaveBeenCalled(); - expect(checkboxInstance.checked).toBe(false); - }); - }; - -export const booleanErrorTest = - ( - testConfig: TestConfig, - instance: Type, - errorTestInformation: ErrorTestExpectation - ) => - () => { - let fixture: ComponentFixture; - let component: C; - - baseSetup(testConfig); - - beforeEach(() => { - const preparedComponents = prepareComponent(testConfig, instance); - fixture = preparedComponents.fixture; - component = preparedComponents.component; - }); - it('should display errors', () => { - component.uischema = uischema; - - const formsService = getJsonFormsService(component); - formsService.init({ - core: { - data, - schema: defaultBooleanTestSchema, - uischema: uischema, - }, - }); - formsService.updateCore( - Actions.updateErrors([ - { - instancePath: '/foo', - message: 'Hi, this is me, test error!', - keyword: '', - schemaPath: '', - params: {}, - }, - ]) - ); - formsService.refresh(); - - component.ngOnInit(); - fixture.detectChanges(); - const debugErrors: DebugElement[] = fixture.debugElement.queryAll( - By.directive(errorTestInformation.errorInstance) - ); - expect(debugErrors.length).toBe(errorTestInformation.numberOfElements); - expect( - debugErrors[errorTestInformation.indexOfElement].nativeElement - .textContent - ).toBe('Hi, this is me, test error!'); - }); - }; diff --git a/packages/angular-material/test/common/index.ts b/packages/angular-material/test/common/index.ts deleted file mode 100644 index 5739d05f88..0000000000 --- a/packages/angular-material/test/common/index.ts +++ /dev/null @@ -1,30 +0,0 @@ -/* - The MIT License - - Copyright (c) 2017-2019 EclipseSource Munich - https://github.com/eclipsesource/jsonforms - - Permission is hereby granted, free of charge, to any person obtaining a copy - of this software and associated documentation files (the "Software"), to deal - in the Software without restriction, including without limitation the rights - to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - copies of the Software, and to permit persons to whom the Software is - furnished to do so, subject to the following conditions: - - The above copyright notice and this permission notice shall be included in - all copies or substantial portions of the Software. - - THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - THE SOFTWARE. -*/ -export * from './boolean'; -export * from './text'; -export * from './number'; -export * from './range'; -export * from './util'; -export * from './layout'; diff --git a/packages/angular-material/test/common/layout.ts b/packages/angular-material/test/common/layout.ts deleted file mode 100644 index 8fbee8225e..0000000000 --- a/packages/angular-material/test/common/layout.ts +++ /dev/null @@ -1,42 +0,0 @@ -/* - The MIT License - - Copyright (c) 2017-2019 EclipseSource Munich - https://github.com/eclipsesource/jsonforms - - Permission is hereby granted, free of charge, to any person obtaining a copy - of this software and associated documentation files (the "Software"), to deal - in the Software without restriction, including without limitation the rights - to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - copies of the Software, and to permit persons to whom the Software is - furnished to do so, subject to the following conditions: - - The above copyright notice and this permission notice shall be included in - all copies or substantial portions of the Software. - - THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - THE SOFTWARE. -*/ -import { ComponentFixture, TestBed } from '@angular/core/testing'; -import { - JsonFormsAngularService, - JsonFormsOutlet, - UnknownRenderer, -} from '@jsonforms/angular'; - -export const beforeEachLayoutTest = ( - Renderer: any, - { declarations = [], imports = [], providers = [] }: any = {} -): ComponentFixture => { - TestBed.configureTestingModule({ - declarations: [Renderer, UnknownRenderer, JsonFormsOutlet, ...declarations], - imports, - providers: [JsonFormsAngularService, ...providers], - }).compileComponents(); - return TestBed.createComponent(Renderer); -}; diff --git a/packages/angular-material/test/common/number.ts b/packages/angular-material/test/common/number.ts deleted file mode 100644 index 6387d0419c..0000000000 --- a/packages/angular-material/test/common/number.ts +++ /dev/null @@ -1,443 +0,0 @@ -/* - The MIT License - - Copyright (c) 2017-2019 EclipseSource Munich - https://github.com/eclipsesource/jsonforms - - Permission is hereby granted, free of charge, to any person obtaining a copy - of this software and associated documentation files (the "Software"), to deal - in the Software without restriction, including without limitation the rights - to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - copies of the Software, and to permit persons to whom the Software is - furnished to do so, subject to the following conditions: - - The above copyright notice and this permission notice shall be included in - all copies or substantial portions of the Software. - - THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - THE SOFTWARE. -*/ -import type { DebugElement } from '@angular/core'; -import { By } from '@angular/platform-browser'; -import type { JsonFormsControl } from '@jsonforms/angular'; -import { Actions, ControlElement, JsonSchema } from '@jsonforms/core'; -import { - baseSetup, - ErrorTestExpectation, - getJsonFormsService, - setupMockStore, - TestConfig, - TestData, -} from './util'; -import { ComponentFixture, TestBed } from '@angular/core/testing'; - -interface ComponentResult { - fixture: ComponentFixture; - component: C; - numberElement?: DebugElement; - numberNativeElement?: any; -} - -export const prepareComponent = ( - testConfig: TestConfig, - instance?: string, - elementToUse?: (element: DebugElement) => any -): ComponentResult => { - const fixture = TestBed.createComponent(testConfig.componentUT); - const component = fixture.componentInstance; - const result: ComponentResult = { fixture, component }; - if (instance && elementToUse) { - const numberElement = fixture.debugElement.query(By.css(instance)); - const numberNativeElement = elementToUse(numberElement); - result.numberElement = numberElement; - result.numberNativeElement = numberNativeElement; - } - - return result; -}; -const defaultData = { foo: 123.123 }; -const defaultSchema: JsonSchema = { - type: 'object', - properties: { - foo: { - type: 'number', - }, - }, -}; -const defaultUischema: ControlElement = { - type: 'Control', - scope: '#/properties/foo', -}; -export const defaultNumberTestData: TestData = { - data: defaultData, - schema: defaultSchema, - uischema: defaultUischema, -}; -export const updateWithSiblingNumberValue = ( - fixture: ComponentFixture, - testData: TestData, - expectations: () => any -) => { - setupMockStore(fixture, testData); - getJsonFormsService(fixture.componentInstance).init({ - core: { - data: { foo: 123.123, bar: 456.456 }, - schema: testData.schema, - uischema: undefined, - }, - }); - fixture.componentInstance.ngOnInit(); - fixture.detectChanges(); - expectations(); -}; - -export const numberBaseTest = - ( - testConfig: TestConfig, - instance: string, - elementToUse: (element: DebugElement) => any, - testData: TestData = defaultNumberTestData - ) => - () => { - let fixture: ComponentFixture; - let numberElement: DebugElement; - let numberNativeElement: any; - let component: C; - - baseSetup(testConfig); - - beforeEach(() => { - const preparedComponents = prepareComponent( - testConfig, - instance, - elementToUse - ); - fixture = preparedComponents.fixture; - numberNativeElement = preparedComponents.numberNativeElement; - numberElement = preparedComponents.numberElement; - component = preparedComponents.component; - }); - - it('should render floats', () => { - component.uischema = testData.uischema; - getJsonFormsService(component).init({ core: testData }); - getJsonFormsService(component).updateCore( - Actions.init(testData.data, testData.schema) - ); - component.ngOnInit(); - fixture.detectChanges(); - expect(component.data).toBe(123.123); - expect(numberNativeElement.value).toBe('123.123'); - // step is of type string - expect(numberNativeElement.step).toBe('0.1'); - expect(numberNativeElement.disabled).toBe(false); - // the component is wrapped in a div - expect(fixture.nativeElement.children[0].style.display).not.toBe('none'); - }); - - it('should render integers', () => { - const state = { - data: { foo: 123 }, - schema: { - type: 'object', - properties: { - foo: { type: 'integer' }, - }, - }, - uischema: testData.uischema, - }; - component.uischema = testData.uischema; - getJsonFormsService(component).init({ core: state }); - getJsonFormsService(component).updateCore( - Actions.init(state.data, state.schema) - ); - component.ngOnInit(); - fixture.detectChanges(); - - expect(component.data).toBe(123); - expect(numberNativeElement.value).toBe('123'); - // step is of type string - expect(numberNativeElement.step).toBe('1'); - expect(numberNativeElement.disabled).toBe(false); - // the component is wrapped in a div - expect(fixture.nativeElement.children[0].style.display).not.toBe('none'); - }); - - it('should support updating the state', () => { - component.uischema = testData.uischema; - getJsonFormsService(component).init({ core: testData }); - getJsonFormsService(component).updateCore( - Actions.init(testData.data, testData.schema) - ); - component.ngOnInit(); - fixture.detectChanges(); - getJsonFormsService(fixture.componentInstance).updateCore( - Actions.update('foo', () => 456.456) - ); - fixture.detectChanges(); - expect(component.data).toBe(456.456); - expect(Number(numberNativeElement.value)).toBe(456.456); - }); - - it('should update with undefined value', () => { - component.uischema = testData.uischema; - getJsonFormsService(component).init({ core: testData }); - getJsonFormsService(component).updateCore( - Actions.init(testData.data, testData.schema) - ); - component.ngOnInit(); - fixture.detectChanges(); - getJsonFormsService(fixture.componentInstance).updateCore( - Actions.update('foo', () => undefined) - ); - fixture.detectChanges(); - - expect(component.data).toBe(undefined); - expect(numberNativeElement.value).toBe(''); - }); - - it('should update with null value', () => { - component.uischema = testData.uischema; - getJsonFormsService(component).init({ core: testData }); - getJsonFormsService(component).updateCore( - Actions.init(testData.data, testData.schema) - ); - component.ngOnInit(); - fixture.detectChanges(); - getJsonFormsService(fixture.componentInstance).updateCore( - Actions.update('foo', () => null) - ); - fixture.detectChanges(); - expect(component.data).toBe(null); - expect(numberNativeElement.value).toBe(''); - }); - - it('should not update with wrong ref', () => { - component.uischema = testData.uischema; - getJsonFormsService(component).init({ core: testData }); - getJsonFormsService(component).updateCore( - Actions.init(testData.data, testData.schema) - ); - component.ngOnInit(); - fixture.detectChanges(); - getJsonFormsService(fixture.componentInstance).updateCore( - Actions.update('bar', () => 456.456) - ); - fixture.detectChanges(); - expect(component.data).toBe(123.123); - expect(Number(numberNativeElement.value)).toBe(123.123); - }); - - // store needed as we evaluate the calculated enabled value to disable/enable the control - it('can be disabled', () => { - component.uischema = testData.uischema; - component.disabled = true; - - getJsonFormsService(component).init({ - core: { - data: testData.data, - schema: testData.schema, - uischema: testData.uischema, - }, - }); - component.ngOnInit(); - fixture.detectChanges(); - expect(numberNativeElement.disabled).toBe(true); - }); - // store needed as we evaluate the calculated enabled value to disable/enable the control - it('can be hidden', () => { - component.uischema = testData.uischema; - component.visible = false; - - getJsonFormsService(component).init({ - core: { - data: testData.data, - schema: testData.schema, - uischema: testData.uischema, - }, - }); - component.ngOnInit(); - fixture.detectChanges(); - const hasDisplayNone = - 'none' === fixture.nativeElement.children[0].style.display; - const hasHidden = fixture.nativeElement.children[0].hidden; - expect(hasDisplayNone || hasHidden).toBeTruthy(); - }); - - it('id should be present in output', () => { - component.uischema = testData.uischema; - component.id = 'myId'; - getJsonFormsService(component).init({ - core: { - data: testData.data, - schema: testData.schema, - uischema: testData.uischema, - }, - }); - component.ngOnInit(); - fixture.detectChanges(); - expect(numberElement.nativeElement.id).toBe('myId'); - }); - }; -export const numberInputEventTest = - ( - testConfig: TestConfig, - instance: string, - elementToUse: (element: DebugElement) => any, - testData: TestData = defaultNumberTestData - ) => - () => { - let fixture: ComponentFixture; - let numberNativeElement: any; - let component: C & { onChange(evt: string): void }; - - baseSetup(testConfig); - - beforeEach(() => { - const preparedComponents = prepareComponent( - testConfig, - instance, - elementToUse - ); - fixture = preparedComponents.fixture; - numberNativeElement = preparedComponents.numberNativeElement; - component = preparedComponents.component; - }); - - it('should update via input event', () => { - component.uischema = testData.uischema as ControlElement; - - getJsonFormsService(component).init({ - core: { - data: testData.data, - schema: testData.schema, - uischema: undefined, - }, - }); - fixture.detectChanges(); - component.ngOnInit(); - - const spy = spyOn(component, 'onChange'); - numberNativeElement.value = 456.456; - if (numberNativeElement.dispatchEvent) { - numberNativeElement.dispatchEvent(new Event('input')); - } - // trigger change detection - fixture.detectChanges(); - expect(spy).toHaveBeenCalled(); - expect(Number(numberNativeElement.value)).toBe(456.456); - }); - }; -export const numberErrorTest = - ( - testConfig: TestConfig, - errorTestInformation: ErrorTestExpectation, - testData: TestData = defaultNumberTestData - ) => - () => { - let fixture: ComponentFixture; - let component: C; - - baseSetup(testConfig); - - beforeEach(() => { - const preparedComponents = prepareComponent(testConfig); - fixture = preparedComponents.fixture; - component = preparedComponents.component; - }); - - it('should display errors', () => { - component.uischema = testData.uischema; - - const formsService = getJsonFormsService(component); - formsService.init({ - core: { - data: testData.data, - schema: testData.schema, - uischema: undefined, - }, - }); - formsService.updateCore( - Actions.updateErrors([ - { - instancePath: '/foo', - message: 'Hi, this is me, test error!', - keyword: '', - schemaPath: '', - params: {}, - }, - ]) - ); - formsService.refresh(); - component.ngOnInit(); - fixture.detectChanges(); - const debugErrors: DebugElement[] = fixture.debugElement.queryAll( - By.directive(errorTestInformation.errorInstance) - ); - expect(debugErrors.length).toBe(errorTestInformation.numberOfElements); - expect( - debugErrors[errorTestInformation.indexOfElement].nativeElement - .textContent - ).toBe('Hi, this is me, test error!'); - }); - }; - -const additionalSchema: JsonSchema = { - type: 'object', - properties: { - foo: { - type: 'number', - minimum: -42.42, - maximum: 42, - multipleOf: 3, - }, - }, -}; -export const additionalTestData: TestData = { - data: defaultData, - schema: additionalSchema, - uischema: defaultUischema, -}; - -export const numberAdditionalPropsTest = - ( - testConfig: TestConfig, - instance: string, - elementToUse: (element: DebugElement) => any, - testData: TestData = additionalTestData - ) => - () => { - let fixture: ComponentFixture; - let numberNativeElement: any; - - baseSetup(testConfig); - - beforeEach(() => { - const preparedComponents = prepareComponent( - testConfig, - instance, - elementToUse - ); - fixture = preparedComponents.fixture; - numberNativeElement = preparedComponents.numberNativeElement; - }); - - it('should respect min,max,multipleOf', () => { - setupMockStore(fixture, testData); - getJsonFormsService(fixture.componentInstance).updateCore( - Actions.init(testData.data, testData.schema) - ); - fixture.componentInstance.ngOnInit(); - fixture.detectChanges(); - - // step, min and max are of type string on an input control - expect(numberNativeElement.step).toBe('3'); - expect(numberNativeElement.min).toBe('-42.42'); - expect(numberNativeElement.max).toBe('42'); - }); - }; diff --git a/packages/angular-material/test/common/range.ts b/packages/angular-material/test/common/range.ts deleted file mode 100644 index 9f8f4baa77..0000000000 --- a/packages/angular-material/test/common/range.ts +++ /dev/null @@ -1,435 +0,0 @@ -/* - The MIT License - - Copyright (c) 2017-2019 EclipseSource Munich - https://github.com/eclipsesource/jsonforms - - Permission is hereby granted, free of charge, to any person obtaining a copy - of this software and associated documentation files (the "Software"), to deal - in the Software without restriction, including without limitation the rights - to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - copies of the Software, and to permit persons to whom the Software is - furnished to do so, subject to the following conditions: - - The above copyright notice and this permission notice shall be included in - all copies or substantial portions of the Software. - - THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - THE SOFTWARE. -*/ -import type { DebugElement, Type } from '@angular/core'; -import { ComponentFixture, TestBed } from '@angular/core/testing'; -import { By } from '@angular/platform-browser'; - -import type { JsonFormsControl } from '@jsonforms/angular'; -import { - baseSetup, - ErrorTestExpectation, - setupMockStore, - TestConfig, - TestData, - getJsonFormsService, -} from './util'; -import { ControlElement, JsonSchema, Actions } from '@jsonforms/core'; - -interface ComponentResult { - fixture: ComponentFixture; - component: C; - rangeElement: DebugElement; - thumbElement: DebugElement; -} - -const prepareComponent = ( - testConfig: TestConfig, - instance: Type -): ComponentResult => { - const fixture = TestBed.createComponent(testConfig.componentUT); - const component = fixture.componentInstance; - const rangeElement = fixture.debugElement.query(By.directive(instance)); - const thumbElement = fixture.debugElement.query(By.css('[matsliderthumb]')); //rangeElement.nativeElement.children[0]; // todo: find a safer way to get the 'matSliderThumb' - const result: ComponentResult = { - fixture, - component, - rangeElement, - thumbElement, - }; - return result; -}; -export const rangeDefaultData = { foo: 1.234 }; -export const rangeDefaultSchema: JsonSchema = { - type: 'object', - properties: { - foo: { - type: 'number', - minimum: -42.42, - maximum: 42.42, - default: 0.42, - }, - }, -}; -export const rangeDefaultUischema: ControlElement = { - type: 'Control', - scope: '#/properties/foo', - options: { slider: true }, -}; -export const rangeDefaultTestData: TestData = { - data: rangeDefaultData, - schema: rangeDefaultSchema, - uischema: rangeDefaultUischema, -}; - -export const rangeBaseTest = - ( - testConfig: TestConfig, - instance: Type - ) => - () => { - let fixture: ComponentFixture; - let rangeElement: DebugElement; - let thumbElement: DebugElement; - let component: C; - - baseSetup(testConfig); - - beforeEach(() => { - const preparedComponents = prepareComponent(testConfig, instance); - fixture = preparedComponents.fixture; - rangeElement = preparedComponents.rangeElement; - thumbElement = preparedComponents.thumbElement; - component = preparedComponents.component; - }); - - it('should render floats', () => { - component.uischema = rangeDefaultTestData.uischema; - component.schema = rangeDefaultTestData.schema; - - getJsonFormsService(component).init({ - core: { - data: rangeDefaultTestData.data, - schema: rangeDefaultTestData.schema, - uischema: rangeDefaultTestData.uischema, - }, - }); - component.ngOnInit(); - fixture.detectChanges(); - expect(component.data).toBe(1.234); - expect(thumbElement.componentInstance.data).toBe(1.234); - // step is of type string - expect(rangeElement.componentInstance.step).toBe(1); - expect(rangeElement.componentInstance.min).toBe(-42.42); - expect(rangeElement.componentInstance.max).toBe(42.42); - expect(rangeElement.componentInstance.disabled).toBe(false); - expect(fixture.nativeElement.children[0].style.display).not.toBe('none'); - }); - - it('should render integer', () => { - component.uischema = rangeDefaultTestData.uischema; - const schema = JSON.parse(JSON.stringify(rangeDefaultTestData.schema)); - schema.properties.foo.type = 'integer'; - schema.properties.foo.minimum = -42; - schema.properties.foo.maximum = 42; - schema.properties.foo.default = 1; - setupMockStore(fixture, { - uischema: rangeDefaultTestData.uischema, - schema, - data: { foo: 12 }, - }); - getJsonFormsService(component).updateCore( - Actions.init({ foo: 12 }, schema, rangeDefaultTestData.uischema) - ); - - fixture.componentInstance.ngOnInit(); - fixture.detectChanges(); - expect(component.data).toBe(12); - expect(thumbElement.componentInstance.data).toBe(12); - // step is of type string - expect(rangeElement.componentInstance.step).toBe(1); - expect(rangeElement.componentInstance.min).toBe(-42); - expect(rangeElement.componentInstance.max).toBe(42); - expect(rangeElement.componentInstance.disabled).toBe(false); - // the component is wrapped in a div - expect(fixture.nativeElement.children[0].style.display).not.toBe('none'); - }); - - it('should support updating the state', () => { - component.uischema = rangeDefaultTestData.uischema; - component.schema = rangeDefaultTestData.schema; - - getJsonFormsService(component).init({ - core: { - data: rangeDefaultTestData.data, - schema: rangeDefaultTestData.schema, - uischema: rangeDefaultTestData.uischema, - }, - }); - component.ngOnInit(); - fixture.detectChanges(); - - getJsonFormsService(component).updateCore( - Actions.update('foo', () => 4.56) - ); - fixture.detectChanges(); - expect(component.data).toBe(4.56); - expect(thumbElement.componentInstance.data).toBe(4.56); - }); - it('should update with undefined value', () => { - component.uischema = rangeDefaultTestData.uischema; - component.schema = rangeDefaultTestData.schema; - - getJsonFormsService(component).init({ - core: { - data: rangeDefaultTestData.data, - schema: rangeDefaultTestData.schema, - uischema: rangeDefaultTestData.uischema, - }, - }); - component.ngOnInit(); - fixture.detectChanges(); - - getJsonFormsService(component).updateCore( - Actions.update('foo', () => undefined) - ); - fixture.detectChanges(); - expect(component.data).toBe(undefined); - expect(thumbElement.componentInstance.data).toBe(undefined); - }); - it('should update with null value', () => { - component.uischema = rangeDefaultTestData.uischema; - component.schema = rangeDefaultTestData.schema; - - getJsonFormsService(component).init({ - core: { - data: rangeDefaultTestData.data, - schema: rangeDefaultTestData.schema, - uischema: rangeDefaultTestData.uischema, - }, - }); - component.ngOnInit(); - fixture.detectChanges(); - - getJsonFormsService(component).updateCore( - Actions.update('foo', () => null) - ); - fixture.detectChanges(); - expect(component.data).toBe(null); - expect(thumbElement.componentInstance.data).toBe(null); - }); - it('should not update with wrong ref', () => { - component.uischema = rangeDefaultTestData.uischema; - component.schema = rangeDefaultTestData.schema; - - getJsonFormsService(component).init({ - core: { - data: rangeDefaultTestData.data, - schema: rangeDefaultTestData.schema, - uischema: rangeDefaultTestData.uischema, - }, - }); - component.ngOnInit(); - fixture.detectChanges(); - - getJsonFormsService(component).updateCore( - Actions.update('foo', () => 1.234) - ); - getJsonFormsService(component).updateCore( - Actions.update('bar', () => 456.456) - ); - - fixture.detectChanges(); - expect(component.data).toBe(1.234); - expect(thumbElement.componentInstance.data).toBe(1.234); - }); - // store needed as we evaluate the calculated enabled value to disable/enable the control - it('can be disabled', () => { - component.uischema = rangeDefaultTestData.uischema; - component.schema = rangeDefaultTestData.schema; - component.disabled = true; - - getJsonFormsService(component).init({ - core: { - data: rangeDefaultTestData.data, - schema: rangeDefaultTestData.schema, - uischema: rangeDefaultTestData.uischema, - }, - }); - component.ngOnInit(); - fixture.detectChanges(); - expect(rangeElement.componentInstance.disabled).toBe(true); - }); - it('can be hidden', () => { - component.uischema = rangeDefaultTestData.uischema; - component.schema = rangeDefaultTestData.schema; - component.visible = false; - - getJsonFormsService(component).init({ - core: { - data: rangeDefaultTestData.data, - schema: rangeDefaultTestData.schema, - uischema: rangeDefaultTestData.uischema, - }, - }); - fixture.detectChanges(); - component.ngOnInit(); - expect(fixture.nativeElement.children[0].style.display).toBe('none'); - }); - it('id should be present in output', () => { - component.uischema = rangeDefaultTestData.uischema; - component.schema = rangeDefaultTestData.schema; - component.id = 'myId'; - getJsonFormsService(component).init({ - core: { - data: rangeDefaultTestData.data, - schema: rangeDefaultTestData.schema, - uischema: rangeDefaultTestData.uischema, - }, - }); - component.ngOnInit(); - fixture.detectChanges(); - expect(rangeElement.nativeElement.id).toBe('myId'); - }); - }; -export const rangeInputEventTest = - ( - testConfig: TestConfig, - instance: Type - ) => - () => { - let fixture: ComponentFixture; - let component: C & { onChange(evt: string): void }; - - baseSetup(testConfig); - - beforeEach(() => { - const preparedComponents = prepareComponent(testConfig, instance); - fixture = preparedComponents.fixture; - component = preparedComponents.component; - }); - - xit('should update via input event', async () => { - component.uischema = rangeDefaultTestData.uischema; - component.schema = rangeDefaultTestData.schema; - - getJsonFormsService(component).init({ - core: { - data: rangeDefaultTestData.data, - schema: rangeDefaultTestData.schema, - uischema: rangeDefaultTestData.uischema, - }, - }); - component.ngOnInit(); - fixture.detectChanges(); - - const spy = spyOn(component, 'onChange'); - - const sliderElement = fixture.debugElement.query( - By.css('.mat-slider') - ).nativeElement; - - const trackElement = fixture.debugElement.query( - By.css('.mat-slider-wrapper') - ).nativeElement; - const dimensions = trackElement.getBoundingClientRect(); - const x = dimensions.left + dimensions.width * 0.2; - const y = dimensions.top + dimensions.height * 0.2; - - dispatchEvent(sliderElement, createMouseEvent('mousedown', x, y, 0)); - - // trigger change detection - fixture.detectChanges(); - await fixture.whenStable(); - expect(spy).toHaveBeenCalled(); - }); - }; -export const rangeErrorTest = - ( - testConfig: TestConfig, - instance: Type, - errorTestInformation: ErrorTestExpectation - ) => - () => { - let fixture: ComponentFixture; - let component: C; - - baseSetup(testConfig); - - beforeEach(() => { - const preparedComponents = prepareComponent(testConfig, instance); - fixture = preparedComponents.fixture; - component = preparedComponents.component; - }); - it('should display errors', () => { - component.uischema = rangeDefaultTestData.uischema; - component.schema = rangeDefaultTestData.schema; - - const formsService = getJsonFormsService(component); - formsService.init({ - core: { - data: rangeDefaultTestData.data, - schema: rangeDefaultTestData.schema, - uischema: undefined, - }, - }); - formsService.updateCore( - Actions.updateErrors([ - { - instancePath: '/foo', - message: 'Hi, this is me, test error!', - keyword: '', - schemaPath: '', - params: {}, - }, - ]) - ); - formsService.refresh(); - - component.ngOnInit(); - fixture.detectChanges(); - const debugErrors: DebugElement[] = fixture.debugElement.queryAll( - By.directive(errorTestInformation.errorInstance) - ); - expect(debugErrors.length).toBe(errorTestInformation.numberOfElements); - expect( - debugErrors[errorTestInformation.indexOfElement].nativeElement - .textContent - ).toBe('Hi, this is me, test error!'); - }); - }; - -/** Creates a browser MouseEvent with the specified options. */ -const createMouseEvent = (type: string, x = 0, y = 0, button = 0) => { - const event = document.createEvent('MouseEvent'); - - event.initMouseEvent( - type, - true /* canBubble */, - false /* cancelable */, - window /* view */, - 0 /* detail */, - x /* screenX */, - y /* screenY */, - x /* clientX */, - y /* clientY */, - false /* ctrlKey */, - false /* altKey */, - false /* shiftKey */, - false /* metaKey */, - button /* button */, - null /* relatedTarget */ - ); - - // `initMouseEvent` doesn't allow us to pass the `buttons` and - // defaults it to 0 which looks like a fake event. - Object.defineProperty(event, 'buttons', { get: () => 1 }); - - return event; -}; -/** Utility to dispatch any event on a Node. */ -const dispatchEvent = (node: Node | Window, event: Event): Event => { - node.dispatchEvent(event); - return event; -}; diff --git a/packages/angular-material/test/common/text.ts b/packages/angular-material/test/common/text.ts deleted file mode 100644 index 2a29cf6659..0000000000 --- a/packages/angular-material/test/common/text.ts +++ /dev/null @@ -1,454 +0,0 @@ -/* - The MIT License - - Copyright (c) 2017-2019 EclipseSource Munich - https://github.com/eclipsesource/jsonforms - - Permission is hereby granted, free of charge, to any person obtaining a copy - of this software and associated documentation files (the "Software"), to deal - in the Software without restriction, including without limitation the rights - to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - copies of the Software, and to permit persons to whom the Software is - furnished to do so, subject to the following conditions: - - The above copyright notice and this permission notice shall be included in - all copies or substantial portions of the Software. - - THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - THE SOFTWARE. -*/ -import type { DebugElement } from '@angular/core'; -import { ComponentFixture, TestBed } from '@angular/core/testing'; -import { By } from '@angular/platform-browser'; -import type { JsonFormsControl } from '@jsonforms/angular'; -import { Actions, ControlElement, JsonSchema } from '@jsonforms/core'; -import { - baseSetup, - ErrorTestExpectation, - getJsonFormsService, - TestConfig, - TestData, -} from './util'; - -interface ComponentResult { - fixture: ComponentFixture; - component: C; - textElement?: DebugElement; - textNativeElement?: any; -} - -const prepareComponent = ( - testConfig: TestConfig, - instance?: string, - elementToUse?: (element: DebugElement) => any -): ComponentResult => { - const fixture = TestBed.createComponent(testConfig.componentUT); - const component = fixture.componentInstance; - const result: ComponentResult = { fixture, component }; - if (instance && elementToUse) { - const textElement = fixture.debugElement.query(By.css(instance)); - const textNativeElement = elementToUse(textElement); - result.textElement = textElement; - result.textNativeElement = textNativeElement; - } - return result; -}; -const defaultData = { foo: 'foo' }; -const defaultSchema: JsonSchema = { - type: 'object', - properties: { - foo: { - type: 'string', - }, - }, -}; -const defaultUischema: ControlElement = { - type: 'Control', - scope: '#/properties/foo', -}; -export const defaultTextTestData: TestData = { - data: defaultData, - schema: defaultSchema, - uischema: defaultUischema, -}; -export const textBaseTest = - ( - testConfig: TestConfig, - instance: string, - elementToUse: (element: DebugElement) => any, - testData: TestData = defaultTextTestData - ) => - () => { - let fixture: ComponentFixture; - let textElement: DebugElement; - let textNativeElement: any; - let component: C; - - baseSetup(testConfig); - - beforeEach(() => { - const preparedComponents = prepareComponent( - testConfig, - instance, - elementToUse - ); - fixture = preparedComponents.fixture; - textNativeElement = preparedComponents.textNativeElement; - textElement = preparedComponents.textElement; - component = preparedComponents.component; - }); - - it('should render', () => { - component.uischema = testData.uischema; - getJsonFormsService(component).init({ - core: { - data: testData.data, - schema: testData.schema, - uischema: testData.uischema, - }, - }); - component.ngOnInit(); - fixture.detectChanges(); - expect(component.data).toBe('foo'); - expect(textNativeElement.value).toBe('foo'); - expect(textNativeElement.disabled).toBe(false); - // the component is wrapped in a div - const hasDisplayNone = - 'none' === fixture.nativeElement.children[0].style.display; - const hasHidden = fixture.nativeElement.children[0].hidden; - expect(!hasDisplayNone && !hasHidden).toBeTruthy(); - }); - - it('should support updating the state', () => { - component.uischema = testData.uischema; - - getJsonFormsService(component).init({ - core: { - data: testData.data, - schema: testData.schema, - uischema: testData.uischema, - }, - }); - component.ngOnInit(); - fixture.detectChanges(); - - getJsonFormsService(component).updateCore( - Actions.update('foo', () => 'bar') - ); - fixture.detectChanges(); - expect(component.data).toBe('bar'); - expect(textNativeElement.value).toBe('bar'); - }); - it('should update with undefined value', () => { - component.uischema = testData.uischema; - - getJsonFormsService(component).init({ - core: { - data: testData.data, - schema: testData.schema, - uischema: testData.uischema, - }, - }); - component.ngOnInit(); - fixture.detectChanges(); - - getJsonFormsService(component).updateCore( - Actions.update('foo', () => undefined) - ); - fixture.detectChanges(); - expect(component.data).toBe(undefined); - expect(textNativeElement.value).toBe(''); - }); - it('should update with null value', () => { - component.uischema = testData.uischema; - - getJsonFormsService(component).init({ - core: { - data: testData.data, - schema: testData.schema, - uischema: testData.uischema, - }, - }); - component.ngOnInit(); - fixture.detectChanges(); - - getJsonFormsService(component).updateCore( - Actions.update('foo', () => null) - ); - fixture.detectChanges(); - expect(component.data).toBe(null); - expect(textNativeElement.value).toBe(''); - }); - it('should not update with wrong ref', () => { - component.uischema = testData.uischema; - - getJsonFormsService(component).init({ - core: { - data: testData.data, - schema: testData.schema, - uischema: testData.uischema, - }, - }); - component.ngOnInit(); - fixture.detectChanges(); - - getJsonFormsService(component).updateCore( - Actions.update('foo', () => 'foo') - ); - getJsonFormsService(component).updateCore( - Actions.update('bar', () => 'bar') - ); - fixture.detectChanges(); - expect(component.data).toBe('foo'); - expect(textNativeElement.value).toBe('foo'); - }); - // store needed as we evaluate the calculated enabled value to disable/enable the control - it('can be disabled', () => { - component.uischema = testData.uischema; - component.disabled = true; - - getJsonFormsService(component).init({ - core: { - data: testData.data, - schema: testData.schema, - uischema: testData.uischema, - }, - }); - component.ngOnInit(); - fixture.detectChanges(); - expect(textNativeElement.disabled).toBe(true); - }); - it('can be hidden', () => { - component.uischema = testData.uischema; - component.visible = false; - - getJsonFormsService(component).init({ - core: { - data: testData.data, - schema: testData.schema, - uischema: testData.uischema, - }, - }); - component.ngOnInit(); - fixture.detectChanges(); - const hasDisplayNone = - 'none' === fixture.nativeElement.children[0].style.display; - const hasHidden = fixture.nativeElement.children[0].hidden; - expect(hasDisplayNone || hasHidden).toBeTruthy(); - }); - it('id should be present in output', () => { - component.uischema = testData.uischema; - component.id = 'myId'; - getJsonFormsService(component).init({ - core: { - data: testData.data, - schema: testData.schema, - uischema: testData.uischema, - }, - }); - component.ngOnInit(); - fixture.detectChanges(); - expect(textElement.nativeElement.id).toBe('myId'); - }); - }; -export const textInputEventTest = - ( - testConfig: TestConfig, - instance: string, - elementToUse: (element: DebugElement) => any, - testData: TestData = defaultTextTestData - ) => - () => { - let fixture: ComponentFixture; - let textNativeElement: any; - let component: C & { onChange(evt: string): void }; - - baseSetup(testConfig); - - beforeEach(() => { - const preparedComponents = prepareComponent( - testConfig, - instance, - elementToUse - ); - fixture = preparedComponents.fixture; - textNativeElement = preparedComponents.textNativeElement; - component = preparedComponents.component; - }); - - it('should update via input event', () => { - component.uischema = testData.uischema; - - getJsonFormsService(component).init({ - core: { - data: testData.data, - schema: testData.schema, - uischema: testData.uischema, - }, - }); - component.ngOnInit(); - fixture.detectChanges(); - - const spy = spyOn(component, 'onChange'); - textNativeElement.value = 'bar'; - if (textNativeElement.dispatchEvent) { - textNativeElement.dispatchEvent(new Event('input')); - } - // trigger change detection - fixture.detectChanges(); - expect(spy).toHaveBeenCalled(); - expect(textNativeElement.value).toBe('bar'); - }); - }; -export const textErrorTest = - ( - testConfig: TestConfig, - errorTestInformation: ErrorTestExpectation, - testData: TestData = defaultTextTestData - ) => - () => { - let fixture: ComponentFixture; - let component: C; - - baseSetup(testConfig); - - beforeEach(() => { - const preparedComponents = prepareComponent(testConfig); - fixture = preparedComponents.fixture; - component = preparedComponents.component; - }); - it('should display errors', () => { - component.uischema = testData.uischema; - - const formsService = getJsonFormsService(component); - formsService.init({ - core: { - data: testData.data, - schema: testData.schema, - uischema: undefined, - }, - }); - formsService.updateCore( - Actions.updateErrors([ - { - instancePath: '/foo', - message: 'Hi, this is me, test error!', - keyword: '', - schemaPath: '', - params: {}, - }, - ]) - ); - formsService.refresh(); - component.ngOnInit(); - fixture.detectChanges(); - const debugErrors: DebugElement[] = fixture.debugElement.queryAll( - By.directive(errorTestInformation.errorInstance) - ); - expect(debugErrors.length).toBe(errorTestInformation.numberOfElements); - expect( - debugErrors[errorTestInformation.indexOfElement].nativeElement - .textContent - ).toBe('Hi, this is me, test error!'); - }); - }; -export const textTypeTest = - ( - testConfig: TestConfig, - instance: string, - elementToUse: (element: DebugElement) => any, - testData: TestData = defaultTextTestData - ) => - () => { - let fixture: ComponentFixture; - let component: C; - let textNativeElement: any; - - baseSetup(testConfig); - - beforeEach(() => { - const preparedComponents = prepareComponent( - testConfig, - instance, - elementToUse - ); - fixture = preparedComponents.fixture; - component = preparedComponents.component; - textNativeElement = preparedComponents.textNativeElement; - }); - it('should show password independent of schema', () => { - const uischema = JSON.parse(JSON.stringify(testData.uischema)); - uischema.options = { format: 'password' }; - const schema = JSON.parse(JSON.stringify(testData.schema)); - schema.properties.foo.format = 'email'; - - component.uischema = uischema; - component.schema = schema; - - getJsonFormsService(component).init({ - core: { data: testData.data, schema: schema, uischema: uischema }, - }); - component.ngOnInit(); - fixture.detectChanges(); - expect(textNativeElement.type).toBe('password'); - }); - it('should show email', () => { - const schema = JSON.parse(JSON.stringify(testData.schema)); - schema.properties.foo.format = 'email'; - - component.uischema = testData.uischema; - component.schema = schema; - - getJsonFormsService(component).init({ - core: { - data: testData.data, - schema: schema, - uischema: testData.uischema, - }, - }); - component.ngOnInit(); - fixture.detectChanges(); - expect(textNativeElement.type).toBe('email'); - }); - xit('should show tel', () => { - const schema = JSON.parse(JSON.stringify(testData.schema)); - schema.properties.foo.format = 'tel'; - - component.uischema = testData.uischema; - component.schema = schema; - - getJsonFormsService(component).init({ - core: { - data: testData.data, - schema: schema, - uischema: testData.uischema, - }, - }); - component.ngOnInit(); - fixture.detectChanges(); - expect(textNativeElement.type).toBe('tel'); - }); - xit('should fallback to text', () => { - const schema = JSON.parse(JSON.stringify(testData.schema)); - schema.properties.foo.format = 'foo'; - - component.uischema = testData.uischema; - component.schema = schema; - - getJsonFormsService(component).init({ - core: { - data: testData.data, - schema: schema, - uischema: testData.uischema, - }, - }); - component.ngOnInit(); - fixture.detectChanges(); - expect(textNativeElement.type).toBe('text'); - }); - }; diff --git a/packages/angular-material/test/common/util.ts b/packages/angular-material/test/common/util.ts deleted file mode 100644 index 044fc72910..0000000000 --- a/packages/angular-material/test/common/util.ts +++ /dev/null @@ -1,89 +0,0 @@ -/* - The MIT License - - Copyright (c) 2017-2019 EclipseSource Munich - https://github.com/eclipsesource/jsonforms - - Permission is hereby granted, free of charge, to any person obtaining a copy - of this software and associated documentation files (the "Software"), to deal - in the Software without restriction, including without limitation the rights - to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - copies of the Software, and to permit persons to whom the Software is - furnished to do so, subject to the following conditions: - - The above copyright notice and this permission notice shall be included in - all copies or substantial portions of the Software. - - THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - THE SOFTWARE. -*/ -import type { Type } from '@angular/core'; -import { ComponentFixture, TestBed, waitForAsync } from '@angular/core/testing'; -import { JsonFormsAngularService, JsonFormsControl } from '@jsonforms/angular'; -import type { - JsonFormsRendererRegistryEntry, - JsonSchema, - UISchemaElement, -} from '@jsonforms/core'; -import type { ErrorObject } from 'ajv'; - -export interface ErrorTestExpectation { - errorInstance: Type; - numberOfElements: number; - indexOfElement: number; -} -export interface TestConfig { - imports: any[]; - providers: any[]; - componentUT: Type; -} - -export const baseSetup = ( - testConfig: TestConfig -) => { - beforeEach(waitForAsync(() => { - TestBed.configureTestingModule({ - declarations: [testConfig.componentUT], - imports: testConfig.imports, - providers: [JsonFormsAngularService].concat(testConfig.providers), - }).compileComponents(); - })); -}; - -export interface TestData { - data: any; - schema: JsonSchema; - uischema: T; - errors?: ErrorObject[]; - renderers?: JsonFormsRendererRegistryEntry[]; -} - -export const getJsonFormsService = ( - component: JsonFormsControl -): JsonFormsAngularService => { - return (component as any).jsonFormsService as JsonFormsAngularService; -}; - -export const setupMockStore = ( - fixture: ComponentFixture, - testData: TestData -): void => { - const component = fixture.componentInstance; - component.uischema = testData.uischema; - component.schema = testData.schema; - - getJsonFormsService(component).init({ - core: { - data: testData.data, - schema: testData.schema, - errors: testData.errors, - uischema: testData.uischema, - }, - }); - getJsonFormsService(component).registerRenderers(testData.renderers); -}; diff --git a/packages/angular-material/test/date-control.spec.ts b/packages/angular-material/test/date-control.spec.ts deleted file mode 100644 index 5e8a957d29..0000000000 --- a/packages/angular-material/test/date-control.spec.ts +++ /dev/null @@ -1,323 +0,0 @@ -/* - The MIT License - - Copyright (c) 2017-2019 EclipseSource Munich - https://github.com/eclipsesource/jsonforms - - Permission is hereby granted, free of charge, to any person obtaining a copy - of this software and associated documentation files (the "Software"), to deal - in the Software without restriction, including without limitation the rights - to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - copies of the Software, and to permit persons to whom the Software is - furnished to do so, subject to the following conditions: - - The above copyright notice and this permission notice shall be included in - all copies or substantial portions of the Software. - - THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - THE SOFTWARE. -*/ -import { DebugElement } from '@angular/core'; -import { - ComponentFixture, - fakeAsync, - flush, - TestBed, - waitForAsync, -} from '@angular/core/testing'; -import { ReactiveFormsModule } from '@angular/forms'; -import { MatNativeDateModule } from '@angular/material/core'; -import { - MatDatepicker, - MatDatepickerModule, -} from '@angular/material/datepicker'; -import { MatError, MatFormFieldModule } from '@angular/material/form-field'; -import { MatInputModule } from '@angular/material/input'; -import { By } from '@angular/platform-browser'; -import { NoopAnimationsModule } from '@angular/platform-browser/animations'; -import { - ErrorTestExpectation, - getJsonFormsService, - setupMockStore, -} from './common'; -import { Actions, ControlElement, JsonSchema } from '@jsonforms/core'; -import { DateControlRenderer, DateControlRendererTester } from '../src'; -import { JsonFormsAngularService } from '@jsonforms/angular'; -import { createTesterContext } from './util'; -import { initTestEnvironment } from './test'; - -const data = { foo: '2018-01-01' }; -const schema: JsonSchema = { - type: 'object', - properties: { - foo: { - type: 'string', - format: 'date', - }, - }, -}; -const uischema: ControlElement = { - type: 'Control', - scope: '#/properties/foo', -}; - -initTestEnvironment(); - -describe('Material boolean field tester', () => { - it('should succeed', () => { - expect( - DateControlRendererTester(uischema, schema, createTesterContext(schema)) - ).toBe(2); - }); -}); -const imports = [ - MatDatepickerModule, - MatInputModule, - MatNativeDateModule, - MatFormFieldModule, - NoopAnimationsModule, - ReactiveFormsModule, -]; -const providers = [JsonFormsAngularService]; -const componentUT: any = DateControlRenderer; -const errorTest: ErrorTestExpectation = { - errorInstance: MatError, - numberOfElements: 1, - indexOfElement: 0, -}; - -describe('Date control Base Tests', () => { - let fixture: ComponentFixture; - let component: DateControlRenderer; - let inputElement: HTMLInputElement; - beforeEach(waitForAsync(() => { - TestBed.configureTestingModule({ - declarations: [componentUT], - imports: imports, - providers: providers, - }).compileComponents(); - })); - beforeEach(() => { - fixture = TestBed.createComponent(componentUT); - component = fixture.componentInstance; - - inputElement = fixture.debugElement.query(By.css('input')).nativeElement; - }); - - it('should render', () => { - setupMockStore(fixture, { uischema, schema, data }); - getJsonFormsService(component).updateCore( - Actions.init(data, schema, uischema) - ); - component.ngOnInit(); - fixture.detectChanges(); - expect(component.data.toString()).toEqual( - new Date('2018-01-01T00:00').toString() - ); - // auto? shown with US layout - expect(inputElement.value).toBe('1/1/2018'); - expect(inputElement.disabled).toBe(false); - // the component is wrapped in a div - expect(fixture.nativeElement.children[0].style.display).not.toBe('none'); - }); - - it('should support updating the state', () => { - setupMockStore(fixture, { uischema, schema, data }); - getJsonFormsService(component).updateCore( - Actions.init(data, schema, uischema) - ); - component.ngOnInit(); - fixture.detectChanges(); - - getJsonFormsService(component).updateCore( - Actions.update('foo', () => '2018-03-03') - ); - fixture.detectChanges(); - expect(component.data.toString()).toEqual( - new Date('2018-03-03T00:00').toString() - ); - expect(inputElement.value).toBe('3/3/2018'); - }); - it('should update with undefined value', () => { - setupMockStore(fixture, { uischema, schema, data }); - getJsonFormsService(component).updateCore( - Actions.init(data, schema, uischema) - ); - component.ngOnInit(); - fixture.detectChanges(); - - getJsonFormsService(component).updateCore( - Actions.update('foo', () => undefined) - ); - fixture.detectChanges(); - expect(component.data).toBe(null); - expect(inputElement.value).toBe(''); - }); - it('should update with null value', () => { - setupMockStore(fixture, { uischema, schema, data }); - getJsonFormsService(component).updateCore( - Actions.init(data, schema, uischema) - ); - component.ngOnInit(); - fixture.detectChanges(); - - getJsonFormsService(component).updateCore( - Actions.update('foo', () => null) - ); - fixture.detectChanges(); - expect(component.data).toBe(null); - expect(inputElement.value).toBe(''); - }); - it('should not update with wrong ref', () => { - setupMockStore(fixture, { uischema, schema, data }); - getJsonFormsService(component).updateCore( - Actions.init(data, schema, uischema) - ); - component.ngOnInit(); - fixture.detectChanges(); - - getJsonFormsService(component).updateCore( - Actions.update('foo', () => '2018-01-01') - ); - getJsonFormsService(component).updateCore( - Actions.update('bar', () => '2018-03-03') - ); - fixture.detectChanges(); - expect(component.data.toString()).toEqual( - new Date('2018-01-01T00:00').toString() - ); - expect(inputElement.value).toEqual('1/1/2018'); - }); - // store needed as we evaluate the calculated enabled value to disable/enable the control - it('can be disabled', () => { - setupMockStore(fixture, { uischema, schema, data }); - component.disabled = true; - getJsonFormsService(component).updateCore( - Actions.init(data, schema, uischema) - ); - - component.ngOnInit(); - fixture.detectChanges(); - expect(inputElement.disabled).toBe(true); - }); - // store needed as we evaluate the calculated enabled value to disable/enable the control - it('can be hidden', () => { - setupMockStore(fixture, { uischema, schema, data }); - component.visible = false; - getJsonFormsService(component).updateCore( - Actions.init(data, schema, uischema) - ); - - component.ngOnInit(); - fixture.detectChanges(); - // the component is wrapped in a div - expect(fixture.nativeElement.children[0].style.display).toBe('none'); - }); - it('id should be present in output', () => { - component.uischema = uischema; - component.id = 'myId'; - getJsonFormsService(component).init({ - core: { data: data, schema: schema, uischema: uischema }, - }); - - component.ngOnInit(); - fixture.detectChanges(); - expect(inputElement.id).toBe('myId'); - }); -}); -describe('Date control Input Event Tests', () => { - let fixture: ComponentFixture; - let component: DateControlRenderer; - let inputElement: HTMLInputElement; - beforeEach(waitForAsync(() => { - TestBed.configureTestingModule({ - declarations: [componentUT], - imports: imports, - providers: providers, - }).compileComponents(); - })); - beforeEach(() => { - fixture = TestBed.createComponent(componentUT); - component = fixture.componentInstance; - - inputElement = fixture.debugElement.query(By.css('input')).nativeElement; - }); - it('should update via input event', fakeAsync(() => { - setupMockStore(fixture, { uischema, schema, data }); - getJsonFormsService(component).updateCore( - Actions.init(data, schema, uischema) - ); - component.ngOnInit(); - fixture.detectChanges(); - - const spy = spyOn(component, 'onChange'); - - fixture.debugElement - .query(By.directive(MatDatepicker)) - .componentInstance.open(); - fixture.detectChanges(); - flush(); - - const cells = document.querySelectorAll('.mat-calendar-body-cell'); - const firstCell: HTMLElement = cells[1] as HTMLElement; - firstCell.click(); - fixture.detectChanges(); - flush(); - - inputElement.dispatchEvent(new Event('change')); - // trigger change detection - fixture.detectChanges(); - expect(spy).toHaveBeenCalled(); - expect(inputElement.value).toBe('1/2/2018'); - })); -}); -describe('Date control Error Tests', () => { - let fixture: ComponentFixture; - let component: DateControlRenderer; - beforeEach(waitForAsync(() => { - TestBed.configureTestingModule({ - declarations: [componentUT], - imports: imports, - providers: providers, - }).compileComponents(); - })); - beforeEach(() => { - fixture = TestBed.createComponent(componentUT); - component = fixture.componentInstance; - }); - it('should display errors', () => { - setupMockStore(fixture, { - uischema, - schema, - data, - }); - const formsService = getJsonFormsService(component); - formsService.updateCore( - Actions.updateErrors([ - { - instancePath: '/foo', - message: 'Hi, this is me, test error!', - params: {}, - keyword: '', - schemaPath: '', - }, - ]) - ); - formsService.refresh(); - - component.ngOnInit(); - fixture.detectChanges(); - const debugErrors: DebugElement[] = fixture.debugElement.queryAll( - By.directive(errorTest.errorInstance) - ); - expect(debugErrors.length).toBe(errorTest.numberOfElements); - expect( - debugErrors[errorTest.indexOfElement].nativeElement.textContent - ).toBe('Hi, this is me, test error!'); - }); -}); diff --git a/packages/angular-material/test/group-layout.spec.ts b/packages/angular-material/test/group-layout.spec.ts deleted file mode 100644 index 7704e88267..0000000000 --- a/packages/angular-material/test/group-layout.spec.ts +++ /dev/null @@ -1,104 +0,0 @@ -/* - The MIT License - - Copyright (c) 2017-2019 EclipseSource Munich - https://github.com/eclipsesource/jsonforms - - Permission is hereby granted, free of charge, to any person obtaining a copy - of this software and associated documentation files (the "Software"), to deal - in the Software without restriction, including without limitation the rights - to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - copies of the Software, and to permit persons to whom the Software is - furnished to do so, subject to the following conditions: - - The above copyright notice and this permission notice shall be included in - all copies or substantial portions of the Software. - - THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - THE SOFTWARE. -*/ -import { ComponentFixture, waitForAsync } from '@angular/core/testing'; -import { GroupLayout, UISchemaElement } from '@jsonforms/core'; -import { MatCard, MatCardTitle } from '@angular/material/card'; -import { By } from '@angular/platform-browser'; -import { DebugElement } from '@angular/core'; -import { beforeEachLayoutTest, setupMockStore } from './common'; -import { LayoutChildrenRenderPropsPipe } from '../src/library/layouts/layout.renderer'; -import { - GroupLayoutRenderer, - groupLayoutTester, -} from '../src/library/layouts/group-layout.renderer'; -import { initTestEnvironment } from './test'; - -initTestEnvironment(); - -describe('Group layout tester', () => { - it('should succeed', () => { - expect(groupLayoutTester({ type: 'Group' }, undefined, undefined)).toBe(1); - }); -}); -describe('Group layout', () => { - let fixture: ComponentFixture; - - beforeEach(waitForAsync(() => { - fixture = beforeEachLayoutTest(GroupLayoutRenderer, { - declarations: [LayoutChildrenRenderPropsPipe], - imports: [MatCard, MatCardTitle], - }); - })); - - it('render with undefined elements', () => { - const uischema: UISchemaElement = { - type: 'Group', - }; - setupMockStore(fixture, { data: {}, schema: {}, uischema }); - fixture.componentInstance.ngOnInit(); - fixture.detectChanges(); - const card: DebugElement[] = fixture.debugElement.queryAll( - By.directive(MatCard) - ); - // title - expect(card[0].nativeElement.children.length).toBe(1); - }); - - it('render with null elements', () => { - const uischema: GroupLayout = { - type: 'Group', - elements: null, - }; - setupMockStore(fixture, { data: {}, schema: {}, uischema }); - fixture.componentInstance.ngOnInit(); - fixture.detectChanges(); - const card: DebugElement[] = fixture.debugElement.queryAll( - By.directive(MatCard) - ); - // title - expect(card[0].nativeElement.children.length).toBe(1); - }); - - it('render with children', () => { - const uischema: GroupLayout = { - type: 'Group', - label: 'foo', - elements: [{ type: 'Control' }, { type: 'Control' }], - }; - setupMockStore(fixture, { data: {}, schema: {}, uischema }); - fixture.componentInstance.ngOnInit(); - fixture.detectChanges(); - const card: DebugElement[] = fixture.debugElement.queryAll( - By.directive(MatCard) - ); - const title: DebugElement = fixture.debugElement.query( - By.directive(MatCardTitle) - ); - - expect(title.nativeElement.textContent).toBe('foo'); - // title + 2 controls - expect(card[0].nativeElement.children.length).toBe(3); - }); -}); diff --git a/packages/angular-material/test/horizontal-layout.spec.ts b/packages/angular-material/test/horizontal-layout.spec.ts deleted file mode 100644 index aab7932d07..0000000000 --- a/packages/angular-material/test/horizontal-layout.spec.ts +++ /dev/null @@ -1,97 +0,0 @@ -/* - The MIT License - - Copyright (c) 2017-2019 EclipseSource Munich - https://github.com/eclipsesource/jsonforms - - Permission is hereby granted, free of charge, to any person obtaining a copy - of this software and associated documentation files (the "Software"), to deal - in the Software without restriction, including without limitation the rights - to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - copies of the Software, and to permit persons to whom the Software is - furnished to do so, subject to the following conditions: - - The above copyright notice and this permission notice shall be included in - all copies or substantial portions of the Software. - - THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - THE SOFTWARE. -*/ -import { ComponentFixture, waitForAsync } from '@angular/core/testing'; -import { HorizontalLayout, UISchemaElement } from '@jsonforms/core'; -import { beforeEachLayoutTest, setupMockStore } from './common'; -import { - HorizontalLayoutRenderer, - horizontalLayoutTester, -} from '../src/library/layouts/horizontal-layout.renderer'; -import { LayoutChildrenRenderPropsPipe } from '../src/library/layouts/layout.renderer'; -import { initTestEnvironment } from './test'; - -initTestEnvironment(); - -describe('Horizontal layout tester', () => { - it('should succeed', () => { - expect( - horizontalLayoutTester({ type: 'HorizontalLayout' }, undefined, undefined) - ).toBe(1); - }); -}); -describe('Horizontal layout', () => { - let fixture: ComponentFixture; - - beforeEach(waitForAsync(() => { - fixture = beforeEachLayoutTest(HorizontalLayoutRenderer, { - declarations: [LayoutChildrenRenderPropsPipe], - }); - })); - - it('render with undefined elements', () => { - const uischema: UISchemaElement = { - type: 'HorizontalLayout', - }; - setupMockStore(fixture, { - data: {}, - schema: {}, - uischema, - }); - fixture.componentInstance.ngOnInit(); - fixture.detectChanges(); - expect(fixture.nativeElement.children[0].children.length).toBe(0); - }); - - it('render with null elements', () => { - const uischema: HorizontalLayout = { - type: 'HorizontalLayout', - elements: null, - }; - setupMockStore(fixture, { - data: {}, - schema: {}, - uischema, - }); - fixture.componentInstance.ngOnInit(); - fixture.detectChanges(); - expect(fixture.nativeElement.children[0].children.length).toBe(0); - }); - - it('render with children', () => { - const uischema: HorizontalLayout = { - type: 'HorizontalLayout', - elements: [{ type: 'Control' }, { type: 'Control' }], - }; - setupMockStore(fixture, { - data: {}, - schema: {}, - uischema, - }); - fixture.componentInstance.ngOnInit(); - fixture.detectChanges(); - expect(fixture.nativeElement.children[0].children.length).toBe(2); - expect(fixture.nativeElement.children[0].hidden).toBe(false); - }); -}); diff --git a/packages/angular-material/test/label-renderer.spec.ts b/packages/angular-material/test/label-renderer.spec.ts deleted file mode 100644 index 3397edbad2..0000000000 --- a/packages/angular-material/test/label-renderer.spec.ts +++ /dev/null @@ -1,81 +0,0 @@ -/* - The MIT License - - Copyright (c) 2017-2019 EclipseSource Munich - https://github.com/eclipsesource/jsonforms - - Permission is hereby granted, free of charge, to any person obtaining a copy - of this software and associated documentation files (the "Software"), to deal - in the Software without restriction, including without limitation the rights - to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - copies of the Software, and to permit persons to whom the Software is - furnished to do so, subject to the following conditions: - - The above copyright notice and this permission notice shall be included in - all copies or substantial portions of the Software. - - THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - THE SOFTWARE. -*/ -import { ComponentFixture, TestBed, waitForAsync } from '@angular/core/testing'; -import { By } from '@angular/platform-browser'; -import { JsonSchema, LabelElement } from '@jsonforms/core'; - -import { LabelRenderer, LabelRendererTester } from '../src/library/other'; -import { setupMockStore } from './common'; -import { JsonFormsAngularService } from '@jsonforms/angular'; -import { initTestEnvironment } from './test'; - -const data = {}; -const schema: JsonSchema = { - type: 'object', - properties: { - foo: { - type: 'string', - }, - }, -}; -const uischema: LabelElement = { - type: 'Label', - text: 'FooBar', -}; - -initTestEnvironment(); - -describe('Material label field tester', () => { - it('should succeed', () => { - expect(LabelRendererTester(uischema, schema, undefined)).toBe(4); - }); -}); -const providers = [JsonFormsAngularService]; -const componentUT: any = LabelRenderer; - -describe('Label Renderer Base Tests', () => { - let fixture: ComponentFixture; - let component: LabelRenderer; - let labelElement: HTMLLabelElement; - beforeEach(waitForAsync(() => { - TestBed.configureTestingModule({ - declarations: [componentUT], - providers: providers, - }).compileComponents(); - })); - beforeEach(() => { - fixture = TestBed.createComponent(componentUT); - component = fixture.componentInstance; - - labelElement = fixture.debugElement.query(By.css('label')).nativeElement; - }); - - it('should render', () => { - setupMockStore(fixture, { uischema, schema, data }); - fixture.detectChanges(); - component.ngOnInit(); - expect(labelElement.innerText.trim()).toBe('FooBar'); - }); -}); diff --git a/packages/angular-material/test/master-detail.spec.ts b/packages/angular-material/test/master-detail.spec.ts deleted file mode 100644 index f0dc4c6dcf..0000000000 --- a/packages/angular-material/test/master-detail.spec.ts +++ /dev/null @@ -1,413 +0,0 @@ -/* - The MIT License - - Copyright (c) 2017-2019 EclipseSource Munich - https://github.com/eclipsesource/jsonforms - - Permission is hereby granted, free of charge, to any person obtaining a copy - of this software and associated documentation files (the "Software"), to deal - in the Software without restriction, including without limitation the rights - to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - copies of the Software, and to permit persons to whom the Software is - furnished to do so, subject to the following conditions: - - The above copyright notice and this permission notice shall be included in - all copies or substantial portions of the Software. - - THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - THE SOFTWARE. -*/ -import { ComponentFixture, TestBed, waitForAsync } from '@angular/core/testing'; -import { By } from '@angular/platform-browser'; -import { MatButtonModule } from '@angular/material/button'; -import { MatIconModule } from '@angular/material/icon'; -import { MatListItem, MatListModule } from '@angular/material/list'; -import { MatSidenavModule } from '@angular/material/sidenav'; -import { NoopAnimationsModule } from '@angular/platform-browser/animations'; -import { - JsonFormsAngularService, - JsonFormsOutlet, - UnknownRenderer, -} from '@jsonforms/angular'; -import { DebugElement } from '@angular/core'; -import { MasterListComponent } from '../src/library/other/master-detail/master'; -import { JsonFormsDetailComponent } from '../src/library/other/master-detail/detail'; -import { getJsonFormsService, setupMockStore } from './common'; -import { Actions } from '@jsonforms/core'; -import { MatTooltipModule } from '@angular/material/tooltip'; -import { initTestEnvironment } from './test'; - -initTestEnvironment(); - -describe('Master detail', () => { - let fixture: ComponentFixture; - let component: any; - - const data = { - orders: [ - { - customer: { - name: 'ACME', - }, - title: 'Carrots', - }, - ], - }; - const schema = { - definitions: { - order: { - type: 'object', - properties: { - customer: { - type: 'object', - properties: { - name: { type: 'string' }, - }, - }, - title: { - type: 'string', - }, - }, - }, - }, - type: 'object', - properties: { - orders: { - type: 'array', - items: { - $ref: '#/definitions/order', - }, - }, - }, - }; - const uischema = { - type: 'ListWithDetail', - scope: '#/properties/orders', - options: { - labelRef: '#/items/properties/customer/properties/name', - detail: { - type: 'VerticalLayout', - elements: [ - { - type: 'Control', - scope: '#/properties/customer/properties/name', - }, - ], - }, - }, - }; - - beforeEach(waitForAsync(() => { - TestBed.configureTestingModule({ - declarations: [ - JsonFormsOutlet, - MasterListComponent, - UnknownRenderer, - JsonFormsDetailComponent, - ], - imports: [ - MatListModule, - MatSidenavModule, - MatIconModule, - MatButtonModule, - NoopAnimationsModule, - MatTooltipModule, - ], - providers: [JsonFormsAngularService], - }).compileComponents(); - - fixture = TestBed.createComponent(MasterListComponent); - component = fixture.componentInstance; - })); - - it('should render', waitForAsync(() => { - setupMockStore(fixture, { uischema, schema, data }); - getJsonFormsService(component).updateCore(Actions.init(data, schema)); - component.ngOnInit(); - - fixture.detectChanges(); - fixture.whenStable().then(() => { - fixture.detectChanges(); - expect(component.masterItems.length).toBe(1); - expect( - fixture.debugElement.queryAll(By.directive(MatListItem)).length - ).toBe(1); - // the component is wrapped in a div - expect(fixture.nativeElement.children[0].style.display).not.toBe('none'); - }); - })); - - it('add a master item', waitForAsync(() => { - setupMockStore(fixture, { uischema, schema, data }); - getJsonFormsService(component).updateCore(Actions.init(data, schema)); - component.ngOnInit(); - fixture.detectChanges(); - - const spy = spyOn(component, 'addItem').and.returnValue(() => { - /* noop */ - }); - fixture.whenStable().then(() => { - const buttons: DebugElement[] = fixture.debugElement.queryAll( - By.css('button') - ); - buttons[1].nativeElement.click(); - fixture.detectChanges(); - fixture.whenRenderingDone().then(() => { - fixture.detectChanges(); - expect(spy).toHaveBeenCalled(); - }); - }); - })); - - it('remove an item', waitForAsync(() => { - setupMockStore(fixture, { uischema, schema, data }); - getJsonFormsService(component).updateCore(Actions.init(data, schema)); - component.ngOnInit(); - fixture.detectChanges(); - - const spy = spyOn(component, 'removeItems').and.returnValue(() => { - /* noop */ - }); - fixture.whenStable().then(() => { - const buttons: DebugElement[] = fixture.debugElement.queryAll( - By.css('button') - ); - buttons[0].nativeElement.click(); - fixture.whenStable().then(() => { - fixture.detectChanges(); - expect(spy).toHaveBeenCalled(); - }); - }); - })); - - it('remove an item with index < selected index', () => { - const moreData = { - orders: [ - { - customer: { name: 'Carrot Chipmunk' }, - title: 'Carrots', - }, - { - customer: { name: 'Banana Joe' }, - title: 'Bananas', - }, - { - customer: { name: 'Fry' }, - title: 'Slurm', - }, - ], - }; - - setupMockStore(fixture, { - uischema, - schema, - data: moreData, - }); - getJsonFormsService(component).updateCore(Actions.init(moreData, schema)); - component.ngOnInit(); - fixture.detectChanges(); - - // select last element - const listItems: DebugElement[] = fixture.debugElement.queryAll( - By.directive(MatListItem) - ); - listItems[2].nativeElement.click(); - fixture.detectChanges(); - expect(component.selectedItemIdx).toBe(2); - - // delete 1st item - spyOn(component, 'removeItems').and.callFake(() => () => { - getJsonFormsService(component).updateCore( - Actions.update('orders', () => moreData.orders.slice(1)) - ); - fixture.detectChanges(); - }); - const buttons: DebugElement[] = fixture.debugElement.queryAll( - By.css('button') - ); - buttons[0].nativeElement.click(); - - expect(component.selectedItemIdx).toBe(1); - expect(component.selectedItem.data.title).toBe('Slurm'); - }); - - it('remove an item with index > selected index', () => { - const moreData = { - orders: [ - { - customer: { name: 'Carrot Chipmunk' }, - title: 'Carrots', - }, - { - customer: { name: 'Banana Joe' }, - title: 'Bananas', - }, - { - customer: { name: 'Fry' }, - title: 'Slurm', - }, - ], - }; - setupMockStore(fixture, { - uischema, - schema, - data: moreData, - }); - getJsonFormsService(component).updateCore(Actions.init(moreData, schema)); - component.ngOnInit(); - fixture.detectChanges(); - - // delete 2nd item - spyOn(component, 'removeItems').and.callFake(() => () => { - const copy = moreData.orders.slice(); - copy.splice(1, 1); - getJsonFormsService(component).updateCore( - Actions.update('orders', () => copy) - ); - fixture.detectChanges(); - }); - const buttons: DebugElement[] = fixture.debugElement.queryAll( - By.css('button') - ); - buttons[1].nativeElement.click(); - - expect(component.selectedItemIdx).toBe(0); - expect(component.selectedItem.data.title).toBe('Carrots'); - }); - - it('remove an item with index == selected index', () => { - const moreData = { - orders: [ - { - customer: { name: 'Carrot Chipmunk' }, - title: 'Carrots', - }, - { - customer: { name: 'Banana Joe' }, - title: 'Bananas', - }, - { - customer: { name: 'Fry' }, - title: 'Slurm', - }, - ], - }; - setupMockStore(fixture, { - uischema, - schema, - data: moreData, - }); - getJsonFormsService(component).updateCore(Actions.init(moreData, schema)); - component.ngOnInit(); - fixture.detectChanges(); - - // delete 1st item - spyOn(component, 'removeItems').and.callFake(() => () => { - getJsonFormsService(component).updateCore( - Actions.update('orders', () => moreData.orders.slice(1)) - ); - fixture.detectChanges(); - }); - const buttons: DebugElement[] = fixture.debugElement.queryAll( - By.css('button') - ); - buttons[0].nativeElement.click(); - - expect(component.selectedItemIdx).toBe(0); - expect(component.selectedItem.data.title).toBe('Bananas'); - }); - - it('remove last item', () => { - const moreData = { - orders: [ - { - customer: { name: 'Carrot Chipmunk' }, - title: 'Carrots', - }, - ], - }; - setupMockStore(fixture, { - uischema, - schema, - data: moreData, - }); - getJsonFormsService(component).updateCore(Actions.init(moreData, schema)); - component.ngOnInit(); - fixture.detectChanges(); - - // delete item - spyOn(component, 'removeItems').and.callFake(() => () => { - getJsonFormsService(component).updateCore( - Actions.update('orders', () => []) - ); - fixture.detectChanges(); - }); - const buttons: DebugElement[] = fixture.debugElement.queryAll( - By.css('button') - ); - buttons[0].nativeElement.click(); - - expect(component.selectedItemIdx).toBe(-1); - expect(component.selectedItem).toBe(undefined); - }); - - it('setting detail on click', waitForAsync(() => { - setupMockStore(fixture, { uischema, schema, data }); - getJsonFormsService(component).updateCore(Actions.init(data, schema)); - component.ngOnInit(); - - fixture.detectChanges(); - fixture.whenStable().then(() => { - spyOn(component, 'onSelect'); - const select = fixture.debugElement.query( - By.directive(MatListItem) - ).nativeElement; - select.click(); - fixture.detectChanges(); - fixture.whenStable().then(() => { - fixture.detectChanges(); - expect( - fixture.debugElement.queryAll(By.directive(JsonFormsDetailComponent)) - .length - ).toBe(1); - expect(component.onSelect).toHaveBeenCalledWith( - { - label: 'ACME', - data: { - customer: { name: 'ACME' }, - title: 'Carrots', - }, - path: 'orders.0', - schema: schema.definitions.order, - uischema: { - type: 'VerticalLayout', - elements: [ - { - type: 'Control', - scope: '#/properties/customer/properties/name', - }, - ], - }, - }, - 0 - ); - }); - }); - })); - - it('can be hidden', waitForAsync(() => { - setupMockStore(fixture, { uischema, schema, data }); - getJsonFormsService(component).updateCore(Actions.init(data, schema)); - component.visible = false; - component.ngOnInit(); - fixture.detectChanges(); - fixture.whenRenderingDone().then(() => { - expect(fixture.nativeElement.children[0].style.display).toBe('none'); - }); - })); -}); diff --git a/packages/angular-material/test/middleware.spec.ts b/packages/angular-material/test/middleware.spec.ts deleted file mode 100644 index f0e934d005..0000000000 --- a/packages/angular-material/test/middleware.spec.ts +++ /dev/null @@ -1,88 +0,0 @@ -/* - The MIT License - - Copyright (c) 2023-2023 EclipseSource Munich - https://github.com/eclipsesource/jsonforms - - Permission is hereby granted, free of charge, to any person obtaining a copy - of this software and associated documentation files (the "Software"), to deal - in the Software without restriction, including without limitation the rights - to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - copies of the Software, and to permit persons to whom the Software is - furnished to do so, subject to the following conditions: - - The above copyright notice and this permission notice shall be included in - all copies or substantial portions of the Software. - - THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - THE SOFTWARE. -*/ - -import { ReactiveFormsModule } from '@angular/forms'; -import { MatFormFieldModule } from '@angular/material/form-field'; -import { MatInputModule } from '@angular/material/input'; -import { NoopAnimationsModule } from '@angular/platform-browser/animations'; -import { NumberControlRenderer } from '../src'; -import { JsonFormsAngularService, JsonFormsControl } from '@jsonforms/angular'; -import { baseSetup, getJsonFormsService, prepareComponent } from './common'; -import { initTestEnvironment } from './test'; - -const imports = [ - MatFormFieldModule, - MatInputModule, - NoopAnimationsModule, - ReactiveFormsModule, -]; -const providers = [JsonFormsAngularService]; -const componentUT: any = NumberControlRenderer; -const testConfig = { imports, providers, componentUT }; - -initTestEnvironment(); - -describe('middleware tests', () => { - let component: JsonFormsControl; - const startingValues = { - core: { - data: 'startValue', - schema: { type: 'string' }, - uischema: { - type: 'control', - }, - }, - }; - - baseSetup(testConfig); - - beforeEach(() => { - const preparedComponents = prepareComponent(testConfig, 'input'); - component = preparedComponents.component; - }); - - it('init using middleware', () => { - const jsonFormsService: JsonFormsAngularService = - getJsonFormsService(component); - const spyMiddleware = jasmine.createSpy('spy1').and.returnValue({ - data: 4, - schema: { type: 'number' }, - uischema: { - type: 'VerticalLayout', - elements: [ - { - type: 'Control', - }, - ], - }, - }); - jsonFormsService.init(startingValues, spyMiddleware); - expect(spyMiddleware).toHaveBeenCalled(); - const core = jsonFormsService.getState().jsonforms.core; - expect(core?.data).toBe(4); - expect(core?.schema.type).toBe('number'); - expect(core?.uischema.type).toBe('VerticalLayout'); - }); -}); diff --git a/packages/angular-material/test/number-control.spec.ts b/packages/angular-material/test/number-control.spec.ts deleted file mode 100644 index fea8b891e2..0000000000 --- a/packages/angular-material/test/number-control.spec.ts +++ /dev/null @@ -1,219 +0,0 @@ -/* - The MIT License - - Copyright (c) 2017-2019 EclipseSource Munich - https://github.com/eclipsesource/jsonforms - - Permission is hereby granted, free of charge, to any person obtaining a copy - of this software and associated documentation files (the "Software"), to deal - in the Software without restriction, including without limitation the rights - to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - copies of the Software, and to permit persons to whom the Software is - furnished to do so, subject to the following conditions: - - The above copyright notice and this permission notice shall be included in - all copies or substantial portions of the Software. - - THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - THE SOFTWARE. -*/ -import { DebugElement } from '@angular/core'; -import { ComponentFixture } from '@angular/core/testing'; -import { ReactiveFormsModule } from '@angular/forms'; -import { MatError, MatFormFieldModule } from '@angular/material/form-field'; -import { MatInputModule } from '@angular/material/input'; -import { NoopAnimationsModule } from '@angular/platform-browser/animations'; -import { JsonFormsAngularService, JsonFormsControl } from '@jsonforms/angular'; -import { - baseSetup, - ErrorTestExpectation, - getJsonFormsService, - numberAdditionalPropsTest, - numberBaseTest, - numberErrorTest, - numberInputEventTest, - prepareComponent, -} from './common'; -import { Actions, ControlElement, JsonFormsCore } from '@jsonforms/core'; -import { NumberControlRenderer, NumberControlRendererTester } from '../src'; -import { initTestEnvironment } from './test'; - -initTestEnvironment(); - -describe('Material number field tester', () => { - const uischema = { - type: 'Control', - scope: '#/properties/foo', - }; - - it('should succeed with floats', () => { - expect( - NumberControlRendererTester( - uischema, - { - type: 'object', - properties: { - foo: { - type: 'number', - }, - }, - }, - undefined - ) - ).toBe(2); - }); - it('should succeed with integers', () => { - expect( - NumberControlRendererTester( - uischema, - { - type: 'object', - properties: { - foo: { - type: 'integer', - }, - }, - }, - undefined - ) - ).toBe(2); - }); -}); - -const imports = [ - MatFormFieldModule, - MatInputModule, - NoopAnimationsModule, - ReactiveFormsModule, -]; -const providers = [JsonFormsAngularService]; -const componentUT: any = NumberControlRenderer; -const errorTest: ErrorTestExpectation = { - errorInstance: MatError, - numberOfElements: 1, - indexOfElement: 0, -}; -const toSelect = (el: DebugElement) => el.nativeElement; -const testConfig = { imports, providers, componentUT }; - -describe( - 'Number control Base Tests', - numberBaseTest(testConfig, 'input', toSelect) -); -describe( - 'Number control Input Event Tests', - numberInputEventTest(testConfig, 'input', toSelect) -); -describe('Number control Error Tests', numberErrorTest(testConfig, errorTest)); -describe( - 'Number control Additional Props Tests', - numberAdditionalPropsTest(testConfig, 'input', toSelect) -); - -describe('Number control custom', () => { - let fixture: ComponentFixture; - let numberNativeElement: any; - let component: JsonFormsControl; - baseSetup(testConfig); - - const defaultSchema = { - type: 'object', - properties: { - foo: { type: 'number' }, - }, - }; - const defaultData = { foo: 1000000 }; - const defaultUischema: ControlElement = { - type: 'Control', - scope: '#/properties/foo', - }; - - beforeEach(() => { - const preparedComponents = prepareComponent(testConfig, 'input', toSelect); - fixture = preparedComponents.fixture; - numberNativeElement = preparedComponents.numberNativeElement; - component = preparedComponents.component; - }); - - it('default grouping behavior', () => { - const uischema = Object.assign({}, defaultUischema); - component.uischema = uischema; - const state: JsonFormsCore = { - data: defaultData, - schema: defaultSchema, - uischema: uischema, - }; - getJsonFormsService(component).init({ - core: state, - i18n: { - locale: 'en', - }, - }); - getJsonFormsService(component).updateCore( - Actions.init(state.data, state.schema) - ); - component.ngOnInit(); - fixture.detectChanges(); - - expect(numberNativeElement.value).toBe('1,000,000'); - }); - - it('should use config for grouping', () => { - const uischema = Object.assign({}, defaultUischema); - component.uischema = uischema; - const state: JsonFormsCore = { - data: defaultData, - schema: defaultSchema, - uischema: uischema, - }; - getJsonFormsService(component).init({ - core: state, - i18n: { - locale: 'en', - }, - config: { - useGrouping: false, - }, - }); - getJsonFormsService(component).updateCore( - Actions.init(state.data, state.schema) - ); - component.ngOnInit(); - fixture.detectChanges(); - - expect(numberNativeElement.value).toBe('1000000'); - }); - it('should use uischema for grouping', () => { - const uischema = Object.assign({}, defaultUischema); - uischema.options = { - useGrouping: false, - }; - component.uischema = uischema; - const state: JsonFormsCore = { - data: defaultData, - schema: defaultSchema, - uischema: uischema, - }; - getJsonFormsService(component).init({ - core: state, - i18n: { - locale: 'en', - }, - config: { - useGrouping: true, - }, - }); - getJsonFormsService(component).updateCore( - Actions.init(state.data, state.schema) - ); - component.ngOnInit(); - fixture.detectChanges(); - - expect(numberNativeElement.value).toBe('1000000'); - }); -}); diff --git a/packages/angular-material/test/object-control.spec.ts b/packages/angular-material/test/object-control.spec.ts deleted file mode 100644 index a352dcb137..0000000000 --- a/packages/angular-material/test/object-control.spec.ts +++ /dev/null @@ -1,222 +0,0 @@ -/* - The MIT License - - Copyright (c) 2017-2019 EclipseSource Munich - https://github.com/eclipsesource/jsonforms - - Permission is hereby granted, free of charge, to any person obtaining a copy - of this software and associated documentation files (the "Software"), to deal - in the Software without restriction, including without limitation the rights - to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - copies of the Software, and to permit persons to whom the Software is - furnished to do so, subject to the following conditions: - - The above copyright notice and this permission notice shall be included in - all copies or substantial portions of the Software. - - THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - THE SOFTWARE. -*/ -import { CommonModule } from '@angular/common'; -import { ComponentFixture, TestBed, waitForAsync } from '@angular/core/testing'; -import { ReactiveFormsModule } from '@angular/forms'; -import { MatCardModule } from '@angular/material/card'; -import { MatFormFieldModule } from '@angular/material/form-field'; -import { MatInputModule } from '@angular/material/input'; -import { NoopAnimationsModule } from '@angular/platform-browser/animations'; -import { JsonFormsAngularService, JsonFormsModule } from '@jsonforms/angular'; -import { ControlElement } from '@jsonforms/core'; -import { - GroupLayoutRenderer, - groupLayoutTester, - TextControlRenderer, - TextControlRendererTester, - VerticalLayoutRenderer, - verticalLayoutTester, -} from '../src'; -import { - ObjectControlRenderer, - ObjectControlRendererTester, -} from '../src/library/other/object.renderer'; -import { getJsonFormsService } from './common'; -import { LayoutChildrenRenderPropsPipe } from '../src/library/layouts/layout.renderer'; -import { initTestEnvironment } from './test'; - -const uischema1: ControlElement = { type: 'Control', scope: '#' }; -const uischema2: ControlElement = { - type: 'Control', - scope: '#/properties/foo', -}; -const schema1 = { - type: 'object', - properties: { - foo: { type: 'string' }, - }, -}; -const schema2 = { - type: 'object', - properties: { - foo: { - type: 'object', - properties: { - foo_1: { type: 'string' }, - }, - }, - bar: { - type: 'object', - properties: { - bar_1: { type: 'string' }, - }, - }, - }, -}; -const renderers = [ - { tester: TextControlRendererTester, renderer: TextControlRenderer }, - { tester: verticalLayoutTester, renderer: VerticalLayoutRenderer }, - { tester: groupLayoutTester, renderer: GroupLayoutRenderer }, - { tester: ObjectControlRendererTester, renderer: ObjectControlRenderer }, -]; - -initTestEnvironment(); - -describe('Object Control tester', () => { - it('should succeed', () => { - expect(ObjectControlRendererTester(uischema1, schema1, undefined)).toBe(2); - expect(ObjectControlRendererTester(uischema2, schema2, undefined)).toBe(2); - }); -}); -describe('Object Control', () => { - let fixture: ComponentFixture; - let component: any; - - beforeEach(waitForAsync(() => { - TestBed.configureTestingModule({ - declarations: [ - ObjectControlRenderer, - TextControlRenderer, - VerticalLayoutRenderer, - GroupLayoutRenderer, - LayoutChildrenRenderPropsPipe, - ], - imports: [ - CommonModule, - JsonFormsModule, - MatCardModule, - NoopAnimationsModule, - MatFormFieldModule, - MatInputModule, - ReactiveFormsModule, - ], - providers: [JsonFormsAngularService], - }).compileComponents(); - - fixture = TestBed.createComponent(ObjectControlRenderer); - component = fixture.componentInstance; - })); - - it('object control creates group', waitForAsync(() => { - component.uischema = uischema2; - component.schema = schema2; - - getJsonFormsService(component).init({ - renderers: renderers, - core: { - data: {}, - schema: schema2, - uischema: undefined, - }, - }); - fixture.detectChanges(); - component.ngOnInit(); - fixture.whenStable().then(() => { - // one for the object renderer and one for the group - expect(fixture.nativeElement.querySelectorAll('mat-card').length).toBe(2); - expect( - fixture.nativeElement.querySelectorAll('mat-card-title')[0].textContent - ).toBe('Foo'); - }); - })); - - it('render all elements', waitForAsync(() => { - component.uischema = uischema1; - component.schema = schema2; - - getJsonFormsService(component).init({ - core: { - data: {}, - schema: schema2, - uischema: undefined, - }, - }); - getJsonFormsService(component).registerRenderers(renderers); - - fixture.detectChanges(); - component.ngOnInit(); - fixture.whenStable().then(() => { - expect(fixture.nativeElement.querySelectorAll('input').length).toBe(2); - }); - })); - - it('render only own elements', waitForAsync(() => { - component.uischema = uischema2; - component.schema = schema2; - - getJsonFormsService(component).init({ - core: { - data: {}, - schema: schema2, - uischema: undefined, - }, - }); - getJsonFormsService(component).registerRenderers(renderers); - fixture.detectChanges(); - component.ngOnInit(); - fixture.whenStable().then(() => { - expect(fixture.nativeElement.querySelectorAll('input').length).toBe(1); - }); - })); - - xit('can be disabled', waitForAsync(() => { - component.uischema = uischema1; - component.schema = schema1; - component.disabled = true; - - getJsonFormsService(component).init({ - core: { - data: {}, - schema: schema1, - uischema: undefined, - }, - }); - getJsonFormsService(component).registerRenderers(renderers); - fixture.detectChanges(); - component.ngOnInit(); - fixture.whenStable().then(() => { - expect(fixture.nativeElement.querySelector('input').disabled).toBe(true); - }); - })); - xit('should be enabled by default', waitForAsync(() => { - component.uischema = uischema1; - component.schema = schema1; - - getJsonFormsService(component).init({ - core: { - data: {}, - schema: schema1, - uischema: undefined, - }, - }); - getJsonFormsService(component).registerRenderers(renderers); - component.ngOnInit(); - fixture.detectChanges(); - fixture.whenRenderingDone().then(() => { - fixture.detectChanges(); - expect(fixture.nativeElement.querySelector('input').disabled).toBeFalsy(); - }); - })); -}); diff --git a/packages/angular-material/test/range-control.spec.ts b/packages/angular-material/test/range-control.spec.ts deleted file mode 100644 index e8f5fbd33f..0000000000 --- a/packages/angular-material/test/range-control.spec.ts +++ /dev/null @@ -1,113 +0,0 @@ -/* - The MIT License - - Copyright (c) 2017-2019 EclipseSource Munich - https://github.com/eclipsesource/jsonforms - - Permission is hereby granted, free of charge, to any person obtaining a copy - of this software and associated documentation files (the "Software"), to deal - in the Software without restriction, including without limitation the rights - to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - copies of the Software, and to permit persons to whom the Software is - furnished to do so, subject to the following conditions: - - The above copyright notice and this permission notice shall be included in - all copies or substantial portions of the Software. - - THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - THE SOFTWARE. -*/ -import { ReactiveFormsModule } from '@angular/forms'; -import { MatError, MatFormFieldModule } from '@angular/material/form-field'; -import { MatSlider, MatSliderModule } from '@angular/material/slider'; -import { NoopAnimationsModule } from '@angular/platform-browser/animations'; -import { - ErrorTestExpectation, - rangeBaseTest, - rangeErrorTest, - rangeInputEventTest, -} from './common'; -import { RangeControlRenderer, RangeControlRendererTester } from '../src'; -import { JsonFormsAngularService } from '@jsonforms/angular'; -import { initTestEnvironment } from './test'; - -initTestEnvironment(); - -describe('Material number field tester', () => { - const uischema = { - type: 'Control', - scope: '#/properties/foo', - options: { slider: true }, - }; - - it('should succeed with floats', () => { - expect( - RangeControlRendererTester( - uischema, - { - type: 'object', - properties: { - foo: { - type: 'number', - minimum: -42.42, - maximum: 42.42, - default: 0.42, - }, - }, - }, - undefined - ) - ).toBe(4); - }); - it('should succeed with integers', () => { - expect( - RangeControlRendererTester( - uischema, - { - type: 'object', - properties: { - foo: { - type: 'integer', - minimum: -42, - maximum: 42, - default: 1, - }, - }, - }, - undefined - ) - ).toBe(4); - }); -}); -const imports = [ - NoopAnimationsModule, - MatSliderModule, - MatFormFieldModule, - ReactiveFormsModule, -]; -const providers = [JsonFormsAngularService]; -const componentUT: any = RangeControlRenderer; -const errorTest: ErrorTestExpectation = { - errorInstance: MatError, - numberOfElements: 1, - indexOfElement: 0, -}; -const defaultTestConfig = { imports, providers, componentUT }; - -describe( - 'Range control Base Tests', - rangeBaseTest(defaultTestConfig, MatSlider) -); -describe( - 'Range control Input Event Tests', - rangeInputEventTest(defaultTestConfig, MatSlider) -); -describe( - 'Range control Error Tests', - rangeErrorTest(defaultTestConfig, MatSlider, errorTest) -); diff --git a/packages/angular-material/test/table-control.spec.ts b/packages/angular-material/test/table-control.spec.ts deleted file mode 100644 index dd370ffd70..0000000000 --- a/packages/angular-material/test/table-control.spec.ts +++ /dev/null @@ -1,391 +0,0 @@ -/* - The MIT License - - Copyright (c) 2017-2019 EclipseSource Munich - https://github.com/eclipsesource/jsonforms - - Permission is hereby granted, free of charge, to any person obtaining a copy - of this software and associated documentation files (the "Software"), to deal - in the Software without restriction, including without limitation the rights - to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - copies of the Software, and to permit persons to whom the Software is - furnished to do so, subject to the following conditions: - - The above copyright notice and this permission notice shall be included in - all copies or substantial portions of the Software. - - THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - THE SOFTWARE. -*/ -import { CommonModule } from '@angular/common'; -import { ComponentFixture, TestBed, waitForAsync } from '@angular/core/testing'; -import { ReactiveFormsModule } from '@angular/forms'; -import { MatCardModule } from '@angular/material/card'; -import { MatFormFieldModule } from '@angular/material/form-field'; -import { MatInputModule } from '@angular/material/input'; -import { MatIconModule } from '@angular/material/icon'; -import { MatTableModule } from '@angular/material/table'; -import { NoopAnimationsModule } from '@angular/platform-browser/animations'; -import { JsonFormsAngularService, JsonFormsModule } from '@jsonforms/angular'; -import { ControlElement } from '@jsonforms/core'; -import { TextControlRenderer, TextControlRendererTester } from '../src'; -import { - GetProps, - TableRenderer, - TableRendererTester, -} from '../src/library/other/table.renderer'; -import { setupMockStore } from './common'; -import { createTesterContext } from './util'; -import { MatTooltipModule } from '@angular/material/tooltip'; -import { initTestEnvironment } from './test'; - -const uischema1: ControlElement = { type: 'Control', scope: '#' }; -const uischema2: ControlElement = { - type: 'Control', - scope: '#/properties/my', -}; -const uischemaWithSorting: ControlElement = { - type: 'Control', - scope: '#', - options: { - showSortButtons: true, - }, -}; -const schema_object1 = { - type: 'array', - items: { - type: 'object', - properties: { - foo: { type: 'string' }, - bar: { type: 'string' }, - }, - }, -}; -const schema_object2 = { - type: 'object', - properties: { - my: { - type: 'array', - items: { - type: 'object', - properties: { - foo: { type: 'string' }, - bar: { type: 'string' }, - }, - }, - }, - }, -}; -const schema_simple1 = { - type: 'array', - items: { - type: 'string', - }, -}; -const schema_simple2 = { - type: 'object', - properties: { - my: { - type: 'array', - items: { - type: 'string', - }, - }, - }, -}; -const renderers = [ - { tester: TextControlRendererTester, renderer: TextControlRenderer }, - { tester: TableRendererTester, renderer: TableRenderer }, -]; - -initTestEnvironment(); - -describe('Table tester', () => { - it('should succeed', () => { - expect( - TableRendererTester( - uischema1, - schema_object1, - createTesterContext(schema_object1) - ) - ).toBe(3); - expect( - TableRendererTester( - uischema1, - schema_simple1, - createTesterContext(schema_simple1) - ) - ).toBe(3); - expect( - TableRendererTester( - uischema2, - schema_object2, - createTesterContext(schema_object2) - ) - ).toBe(3); - expect( - TableRendererTester( - uischema2, - schema_simple2, - createTesterContext(schema_simple2) - ) - ).toBe(3); - }); -}); -describe('Table', () => { - let fixture: ComponentFixture; - let component: any; - - beforeEach(waitForAsync(() => { - TestBed.configureTestingModule({ - declarations: [TableRenderer, TextControlRenderer, GetProps], - imports: [ - CommonModule, - JsonFormsModule, - MatCardModule, - NoopAnimationsModule, - MatFormFieldModule, - MatIconModule, - MatInputModule, - ReactiveFormsModule, - MatTableModule, - MatTooltipModule, - ], - providers: [JsonFormsAngularService], - }).compileComponents(); - - fixture = TestBed.createComponent(TableRenderer); - component = fixture.componentInstance; - })); - - it('renders object array on root', waitForAsync(() => { - setupMockStore(fixture, { - uischema: uischema1, - schema: schema_object1, - data: [ - { foo: 'foo_1', bar: 'bar_1' }, - { foo: 'foo_2', bar: 'bar_2' }, - ], - renderers, - }); - fixture.detectChanges(); - component.ngOnInit(); - fixture.whenStable().then(() => { - // 2 columns - expect(fixture.nativeElement.querySelectorAll('th').length).toBe(3); - // 1 head row and 2 data rows - expect(fixture.nativeElement.querySelectorAll('tr').length).toBe(1 + 2); - // 4 data entries - expect(fixture.nativeElement.querySelectorAll('td').length).toBe(6); - }); - })); - it('renders object array on path', waitForAsync(() => { - setupMockStore(fixture, { - uischema: uischema2, - schema: schema_object2, - data: { - my: [ - { foo: 'foo_1', bar: 'bar_1' }, - { foo: 'foo_2', bar: 'bar_2' }, - ], - }, - renderers, - }); - - fixture.detectChanges(); - component.ngOnInit(); - fixture.whenStable().then(() => { - // 2 columns - expect(fixture.nativeElement.querySelectorAll('th').length).toBe(3); - // 1 head row and 2 data rows - expect(fixture.nativeElement.querySelectorAll('tr').length).toBe(1 + 2); - // 4 data entries - expect(fixture.nativeElement.querySelectorAll('td').length).toBe(6); - }); - })); - - it('renders simple array on root', waitForAsync(() => { - setupMockStore(fixture, { - uischema: uischema1, - schema: schema_simple1, - data: ['foo', 'bar'], - renderers, - }); - fixture.detectChanges(); - component.ngOnInit(); - fixture.whenStable().then(() => { - // 1 column - expect(fixture.nativeElement.querySelectorAll('th').length).toBe(2); - // 1 head row and 2 data rows - expect(fixture.nativeElement.querySelectorAll('tr').length).toBe(1 + 2); - // 2 data entries - expect(fixture.nativeElement.querySelectorAll('td').length).toBe(4); - }); - })); - it('renders simple array on path', waitForAsync(() => { - setupMockStore(fixture, { - uischema: uischema2, - schema: schema_simple2, - data: { my: ['foo', 'bar'] }, - renderers, - }); - fixture.detectChanges(); - component.ngOnInit(); - fixture.whenStable().then(() => { - // 1 columns - expect(fixture.nativeElement.querySelectorAll('th').length).toBe(2); - // 1 head row and 2 data rows - expect(fixture.nativeElement.querySelectorAll('tr').length).toBe(1 + 2); - // 2 data entries - expect(fixture.nativeElement.querySelectorAll('td').length).toBe(4); - }); - })); - - it('can be disabled', waitForAsync(() => { - setupMockStore(fixture, { - uischema: uischema1, - schema: schema_object1, - data: [{ foo: 'foo_1', bar: 'bar_1' }], - renderers, - }); - component.disabled = true; - fixture.detectChanges(); - component.ngOnInit(); - fixture.whenStable().then(() => { - expect(fixture.nativeElement.querySelectorAll('input').length).toBe(2); - expect( - fixture.nativeElement.querySelectorAll('input')[0].disabled - ).toBeTruthy(); - expect( - fixture.nativeElement.querySelectorAll('input')[1].disabled - ).toBeTruthy(); - }); - })); - it('should be enabled by default', waitForAsync(() => { - setupMockStore(fixture, { - uischema: uischema1, - schema: schema_object1, - data: [{ foo: 'foo_1', bar: 'bar_1' }], - renderers, - }); - fixture.detectChanges(); - component.ngOnInit(); - fixture.whenStable().then(() => { - component.add(); - expect(fixture.nativeElement.querySelectorAll('input').length).toBe(2); - expect(fixture.nativeElement.querySelector('input').disabled).toBeFalsy(); - }); - })); - - it('renderer handles removing of rows', waitForAsync(() => { - setupMockStore(fixture, { - uischema: uischema1, - schema: schema_object1, - data: [ - { foo: 'foo_1', bar: 'bar_1' }, - { foo: 'foo_2', bar: 'bar_2' }, - ], - renderers, - }); - - fixture.detectChanges(); - component.ngOnInit(); - component.remove(0); - component.remove(0); - fixture.detectChanges(); - - fixture.whenStable().then(() => { - // 1 row - expect(fixture.nativeElement.querySelectorAll('tr').length).toBe(1 + 0); - }); - })); - - it('renderer handles adding of rows', waitForAsync(() => { - setupMockStore(fixture, { - uischema: uischema1, - schema: schema_object1, - data: [ - { foo: 'foo_1', bar: 'bar_1' }, - { foo: 'foo_2', bar: 'bar_2' }, - ], - renderers, - }); - - fixture.detectChanges(); - component.ngOnInit(); - - component.add(); - component.add(); - fixture.detectChanges(); - - fixture.whenStable().then(() => { - // 3 row - expect(fixture.nativeElement.querySelectorAll('tr').length).toBe(1 + 4); - }); - })); - - it('when disabled doesnt render `add` nor `remove` icons', waitForAsync(() => { - setupMockStore(fixture, { - uischema: uischema1, - schema: schema_object1, - data: [ - { foo: 'foo_1', bar: 'bar_1' }, - { foo: 'foo_2', bar: 'bar_2' }, - ], - renderers, - }); - component.disabled = true; - fixture.detectChanges(); - - component.ngOnInit(); - fixture.whenStable().then(() => { - // 2 columns - expect(fixture.nativeElement.querySelectorAll('th').length).toBe(2); - // 2 rows - expect(fixture.nativeElement.querySelectorAll('tr').length).toBe(1 + 2); - // 2 data entries - expect(fixture.nativeElement.querySelectorAll('td').length).toBe(4); - }); - })); - it('when options.showSortButtons is True, it should render sort buttons', waitForAsync(() => { - setupMockStore(fixture, { - uischema: uischemaWithSorting, - schema: schema_simple1, - data: ['foo', 'bar'], - renderers, - }); - component.disabled = false; - fixture.detectChanges(); - - component.ngOnInit(); - fixture.whenStable().then(() => { - expect(fixture.nativeElement.querySelectorAll('.item-up').length).toBe(2); - expect(fixture.nativeElement.querySelectorAll('.item-down').length).toBe( - 2 - ); - }); - })); - it('when options.showSortButtons is False, it should NOT render sort buttons', waitForAsync(() => { - setupMockStore(fixture, { - uischema: uischema1, - schema: schema_simple1, - data: ['foo', 'bar'], - renderers, - }); - component.disabled = false; - fixture.detectChanges(); - - component.ngOnInit(); - fixture.whenStable().then(() => { - expect(fixture.nativeElement.querySelectorAll('.item-up').length).toBe(0); - expect(fixture.nativeElement.querySelectorAll('.item-down').length).toBe( - 0 - ); - }); - })); -}); diff --git a/packages/angular-material/test/test.ts b/packages/angular-material/test/test.ts deleted file mode 100644 index e1632ec174..0000000000 --- a/packages/angular-material/test/test.ts +++ /dev/null @@ -1,19 +0,0 @@ -// This file is required by karma.conf.js and loads recursively all the .spec and framework files - -import 'zone.js/testing'; -import { TestBed } from '@angular/core/testing'; -import { - BrowserDynamicTestingModule, - platformBrowserDynamicTesting, -} from '@angular/platform-browser-dynamic/testing'; - -export function initTestEnvironment() { - TestBed.resetTestEnvironment(); - TestBed.initTestEnvironment( - BrowserDynamicTestingModule, - platformBrowserDynamicTesting(), - { - teardown: { destroyAfterEach: false }, - } - ); -} diff --git a/packages/angular-material/test/text-area.spec.ts b/packages/angular-material/test/text-area.spec.ts deleted file mode 100644 index 2b747bbc33..0000000000 --- a/packages/angular-material/test/text-area.spec.ts +++ /dev/null @@ -1,113 +0,0 @@ -/* - The MIT License - - Copyright (c) 2017-2019 EclipseSource Munich - https://github.com/eclipsesource/jsonforms - - Permission is hereby granted, free of charge, to any person obtaining a copy - of this software and associated documentation files (the "Software"), to deal - in the Software without restriction, including without limitation the rights - to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - copies of the Software, and to permit persons to whom the Software is - furnished to do so, subject to the following conditions: - - The above copyright notice and this permission notice shall be included in - all copies or substantial portions of the Software. - - THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - THE SOFTWARE. -*/ -import { DebugElement } from '@angular/core'; -import { ReactiveFormsModule } from '@angular/forms'; -import { MatError, MatFormFieldModule } from '@angular/material/form-field'; -import { MatInputModule } from '@angular/material/input'; -import { NoopAnimationsModule } from '@angular/platform-browser/animations'; -import { - ErrorTestExpectation, - TestData, - textBaseTest, - textErrorTest, - textInputEventTest, -} from './common'; -import { TextAreaRenderer, TextAreaRendererTester } from '../src'; -import { ControlElement, JsonSchema } from '@jsonforms/core'; -import { JsonFormsAngularService } from '@jsonforms/angular'; -import { initTestEnvironment } from './test'; - -initTestEnvironment(); - -describe('Material text field tester', () => { - const uischema = { - type: 'Control', - scope: '#/properties/foo', - options: { multi: true }, - }; - - it('should succeed', () => { - expect( - TextAreaRendererTester( - uischema, - { - type: 'object', - properties: { - foo: { - type: 'string', - }, - }, - }, - undefined - ) - ).toBe(2); - }); -}); -const imports = [ - MatFormFieldModule, - MatInputModule, - NoopAnimationsModule, - ReactiveFormsModule, -]; -const providers = [JsonFormsAngularService]; -const componentUT: any = TextAreaRenderer; -const errorTest: ErrorTestExpectation = { - errorInstance: MatError, - numberOfElements: 1, - indexOfElement: 0, -}; -const toSelect = (el: DebugElement) => el.nativeElement; -const testConfig = { imports, providers, componentUT }; -const defaultData = { foo: 'foo' }; -const defaultSchema: JsonSchema = { - type: 'object', - properties: { - foo: { - type: 'string', - }, - }, -}; -const defaultUischema: ControlElement = { - type: 'Control', - scope: '#/properties/foo', - options: { multi: true }, -}; -const defaultTestData: TestData = { - data: defaultData, - schema: defaultSchema, - uischema: defaultUischema, -}; -describe( - 'Text control Base Tests', - textBaseTest(testConfig, 'textarea', toSelect, defaultTestData) -); -describe( - 'Text control Input Event Tests', - textInputEventTest(testConfig, 'textarea', toSelect, defaultTestData) -); -describe( - 'Text control Error Tests', - textErrorTest(testConfig, errorTest, defaultTestData) -); diff --git a/packages/angular-material/test/text-control.spec.ts b/packages/angular-material/test/text-control.spec.ts deleted file mode 100644 index c6494cc1c2..0000000000 --- a/packages/angular-material/test/text-control.spec.ts +++ /dev/null @@ -1,94 +0,0 @@ -/* - The MIT License - - Copyright (c) 2017-2019 EclipseSource Munich - https://github.com/eclipsesource/jsonforms - - Permission is hereby granted, free of charge, to any person obtaining a copy - of this software and associated documentation files (the "Software"), to deal - in the Software without restriction, including without limitation the rights - to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - copies of the Software, and to permit persons to whom the Software is - furnished to do so, subject to the following conditions: - - The above copyright notice and this permission notice shall be included in - all copies or substantial portions of the Software. - - THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - THE SOFTWARE. -*/ -import { DebugElement } from '@angular/core'; -import { ReactiveFormsModule } from '@angular/forms'; -import { MatError, MatFormFieldModule } from '@angular/material/form-field'; -import { MatInputModule } from '@angular/material/input'; -import { NoopAnimationsModule } from '@angular/platform-browser/animations'; -import { - ErrorTestExpectation, - textBaseTest, - textErrorTest, - textInputEventTest, - textTypeTest, -} from './common'; -import { TextControlRenderer, TextControlRendererTester } from '../src'; -import { JsonFormsAngularService } from '@jsonforms/angular'; -import { initTestEnvironment } from './test'; - -initTestEnvironment(); - -describe('Material text field tester', () => { - const uischema = { - type: 'Control', - scope: '#/properties/foo', - }; - - it('should succeed', () => { - expect( - TextControlRendererTester( - uischema, - { - type: 'object', - properties: { - foo: { - type: 'string', - }, - }, - }, - undefined - ) - ).toBe(1); - }); -}); -const imports = [ - MatFormFieldModule, - MatInputModule, - NoopAnimationsModule, - ReactiveFormsModule, -]; -const providers = [JsonFormsAngularService]; -const componentUT: any = TextControlRenderer; -const errorTest: ErrorTestExpectation = { - errorInstance: MatError, - numberOfElements: 1, - indexOfElement: 0, -}; -const toSelect = (el: DebugElement) => el.nativeElement; -const testConfig = { imports, providers, componentUT }; - -describe( - 'Text control Base Tests', - textBaseTest(testConfig, 'input', toSelect) -); -describe( - 'Text control Input Event Tests', - textInputEventTest(testConfig, 'input', toSelect) -); -describe('Text control Error Tests', textErrorTest(testConfig, errorTest)); -describe( - 'Text control Type Tests', - textTypeTest(testConfig, 'input', toSelect) -); diff --git a/packages/angular-material/test/toggle-control.spec.ts b/packages/angular-material/test/toggle-control.spec.ts deleted file mode 100644 index 586d4400f9..0000000000 --- a/packages/angular-material/test/toggle-control.spec.ts +++ /dev/null @@ -1,86 +0,0 @@ -/* - The MIT License - - Copyright (c) 2017-2019 EclipseSource Munich - https://github.com/eclipsesource/jsonforms - - Permission is hereby granted, free of charge, to any person obtaining a copy - of this software and associated documentation files (the "Software"), to deal - in the Software without restriction, including without limitation the rights - to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - copies of the Software, and to permit persons to whom the Software is - furnished to do so, subject to the following conditions: - - The above copyright notice and this permission notice shall be included in - all copies or substantial portions of the Software. - - THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - THE SOFTWARE. -*/ -import { MatError, MatFormFieldModule } from '@angular/material/form-field'; -import { - MatSlideToggle, - MatSlideToggleModule, -} from '@angular/material/slide-toggle'; -import { - booleanBaseTest, - booleanErrorTest, - booleanInputEventTest, - ErrorTestExpectation, -} from './common'; -import { ToggleControlRenderer, ToggleControlRendererTester } from '../src'; -import { JsonFormsAngularService } from '@jsonforms/angular'; -import { initTestEnvironment } from './test'; - -initTestEnvironment(); - -describe('Material boolean field tester', () => { - const uischema = { - type: 'Control', - scope: '#/properties/foo', - options: { toggle: true }, - }; - - it('should succeed', () => { - expect( - ToggleControlRendererTester( - uischema, - { - type: 'object', - properties: { - foo: { - type: 'boolean', - }, - }, - }, - undefined - ) - ).toBe(3); - }); -}); -const imports = [MatSlideToggleModule, MatFormFieldModule]; -const providers = [JsonFormsAngularService]; -const componentUT: any = ToggleControlRenderer; -const errorTest: ErrorTestExpectation = { - errorInstance: MatError, - numberOfElements: 1, - indexOfElement: 0, -}; -const testConfig = { imports, providers, componentUT }; -describe( - 'Toggle control Base Tests', - booleanBaseTest(testConfig, MatSlideToggle) -); -describe( - 'Toggle control Input Event Tests', - booleanInputEventTest(testConfig, MatSlideToggle, 'label') -); -describe( - 'Toggle control Error Tests', - booleanErrorTest(testConfig, MatSlideToggle, errorTest) -); diff --git a/packages/angular-material/test/util.ts b/packages/angular-material/test/util.ts deleted file mode 100644 index c0bd9b7448..0000000000 --- a/packages/angular-material/test/util.ts +++ /dev/null @@ -1,30 +0,0 @@ -/* - The MIT License - - Copyright (c) 2022 EclipseSource - https://github.com/eclipsesource/jsonforms - - Permission is hereby granted, free of charge, to any person obtaining a copy - of this software and associated documentation files (the "Software"), to deal - in the Software without restriction, including without limitation the rights - to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - copies of the Software, and to permit persons to whom the Software is - furnished to do so, subject to the following conditions: - - The above copyright notice and this permission notice shall be included in - all copies or substantial portions of the Software. - - THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - THE SOFTWARE. -*/ -import { JsonSchema, TesterContext } from '@jsonforms/core'; - -export const createTesterContext = ( - rootSchema: JsonSchema, - config?: any -): TesterContext => ({ rootSchema, config }); diff --git a/packages/angular-material/test/vertical-layout.spec.ts b/packages/angular-material/test/vertical-layout.spec.ts deleted file mode 100644 index 16140f619f..0000000000 --- a/packages/angular-material/test/vertical-layout.spec.ts +++ /dev/null @@ -1,118 +0,0 @@ -/* - The MIT License - - Copyright (c) 2017-2019 EclipseSource Munich - https://github.com/eclipsesource/jsonforms - - Permission is hereby granted, free of charge, to any person obtaining a copy - of this software and associated documentation files (the "Software"), to deal - in the Software without restriction, including without limitation the rights - to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - copies of the Software, and to permit persons to whom the Software is - furnished to do so, subject to the following conditions: - - The above copyright notice and this permission notice shall be included in - all copies or substantial portions of the Software. - - THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - THE SOFTWARE. -*/ -import { ComponentFixture, waitForAsync } from '@angular/core/testing'; -import { UISchemaElement, VerticalLayout } from '@jsonforms/core'; -import { beforeEachLayoutTest, setupMockStore } from './common'; -import { - VerticalLayoutRenderer, - verticalLayoutTester, -} from '../src/library/layouts/vertical-layout.renderer'; -import { LayoutChildrenRenderPropsPipe } from '../src/library/layouts/layout.renderer'; -import { initTestEnvironment } from './test'; - -initTestEnvironment(); - -describe('Vertical layout tester', () => { - it('should succeed', () => { - expect( - verticalLayoutTester({ type: 'VerticalLayout' }, undefined, undefined) - ).toBe(1); - }); -}); -describe('Vertical layout', () => { - let fixture: ComponentFixture; - let component: any; - - beforeEach(waitForAsync(() => { - fixture = beforeEachLayoutTest(VerticalLayoutRenderer, { - declarations: [LayoutChildrenRenderPropsPipe], - }); - component = fixture.componentInstance; - })); - - it('render with undefined elements', () => { - const uischema: UISchemaElement = { - type: 'VerticalLayout', - }; - setupMockStore(fixture, { - data: {}, - schema: {}, - uischema, - }); - fixture.componentInstance.ngOnInit(); - fixture.detectChanges(); - expect(fixture.nativeElement.children[0].children.length).toBe(0); - // the component is wrapped in a div - expect(fixture.nativeElement.children[0].style.display).not.toBe('none'); - }); - - it('render with null elements', () => { - const uischema: VerticalLayout = { - type: 'VerticalLayout', - elements: null, - }; - - setupMockStore(fixture, { - data: {}, - schema: {}, - uischema, - }); - fixture.componentInstance.ngOnInit(); - fixture.detectChanges(); - expect(fixture.nativeElement.children[0].children.length).toBe(0); - }); - - it('render with children', () => { - const uischema: VerticalLayout = { - type: 'VerticalLayout', - elements: [{ type: 'Control' }, { type: 'Control' }], - }; - setupMockStore(fixture, { - data: {}, - schema: {}, - uischema, - }); - fixture.componentInstance.ngOnInit(); - fixture.detectChanges(); - expect(fixture.nativeElement.children[0].children.length).toBe(2); - expect(fixture.nativeElement.children[0].hidden).toBe(false); - }); - - // TODO: broken due to https://github.com/angular/flex-layout/issues/848 - xit('can be hidden', () => { - const uischema: VerticalLayout = { - type: 'VerticalLayout', - elements: [{ type: 'Control' }, { type: 'Control' }], - }; - component.visible = false; - setupMockStore(fixture, { - data: {}, - schema: {}, - uischema, - }); - component.ngOnInit(); - expect(fixture.nativeElement.children[0].style.display).toBe('none'); - }); -}); diff --git a/packages/angular-material/tsconfig.example.json b/packages/angular-material/tsconfig.example.json deleted file mode 100644 index 46c487ea84..0000000000 --- a/packages/angular-material/tsconfig.example.json +++ /dev/null @@ -1,13 +0,0 @@ -{ - "extends": "./tsconfig", - "compilerOptions": { - "outDir": "./example/dist" - }, - "files": ["./example/main.ts"], - "angularCompilerOptions": { - "compilationMode": "full", - "strictMetadataEmit": true, - "generateCodeForLibraries": false, - "skipTemplateCodegen": true - } -} diff --git a/packages/angular-material/tsconfig.json b/packages/angular-material/tsconfig.json deleted file mode 100644 index 64692753aa..0000000000 --- a/packages/angular-material/tsconfig.json +++ /dev/null @@ -1,17 +0,0 @@ -{ - "extends": "../../tsconfig.base", - "compilerOptions": { - "declaration": true, - "declarationMap": true, - "inlineSources": true, - "sourceMap": true, - }, - "exclude": ["node_modules"], - "files": ["src/index.ts"], - "angularCompilerOptions": { - "compilationMode": "partial", - "strictMetadataEmit": true, - "generateCodeForLibraries": false, - "skipTemplateCodegen": true - } -} diff --git a/packages/angular-material/tsconfig.spec.json b/packages/angular-material/tsconfig.spec.json deleted file mode 100644 index 3f8cb37ad1..0000000000 --- a/packages/angular-material/tsconfig.spec.json +++ /dev/null @@ -1,21 +0,0 @@ -{ - "extends": "../../tsconfig.base", - "compilerOptions": { - "outDir": "../../out-tsc/spec", - "inlineSourceMap": true, - "sourceMap": true, - "types": [ - "jasmine" - ] - }, - "include": [ - "**/*.spec.ts", - "**/*.d.ts" - ], - "angularCompilerOptions": { - "compilationMode": "partial", - "strictMetadataEmit": true, - "generateCodeForLibraries": false, - "skipTemplateCodegen": true - } -} diff --git a/packages/angular/.eslintrc.js b/packages/angular/.eslintrc.js deleted file mode 100644 index 80191b13e9..0000000000 --- a/packages/angular/.eslintrc.js +++ /dev/null @@ -1,44 +0,0 @@ -/* eslint-env node */ -/** @type {import('eslint').Linter.Config} */ -module.exports = { - root: true, - parser: '@typescript-eslint/parser', - parserOptions: { - /* Reset project because @angular-eslint/recommended sets this to an incompatible value */ - project: null, - }, - // There is no file include in ESLint. Thus, ignore all and include files via negative ignore (!) - ignorePatterns: ['/*', '!/src', '!/test'], - extends: [ - 'eslint:recommended', - 'plugin:@typescript-eslint/recommended', - 'plugin:import/recommended', - 'plugin:import/typescript', - 'plugin:@angular-eslint/recommended', - 'plugin:@angular-eslint/template/process-inline-templates', - 'plugin:prettier/recommended', - ], - rules: { - '@angular-eslint/component-class-suffix': 'off', - '@angular-eslint/directive-class-suffix': 'off', - '@angular-eslint/no-conflicting-lifecycle': 'warn', - '@typescript-eslint/no-explicit-any': 'off', - // Base rule must be disabled to avoid incorrect errors - 'no-unused-vars': 'off', - '@typescript-eslint/no-unused-vars': [ - 'warn', // or "error" - { - argsIgnorePattern: '^_', - varsIgnorePattern: '^_', - caughtErrorsIgnorePattern: '^_', - }, - ], - 'import/no-unresolved': [ - 'error', - { - // Ignore ava import because it is incorrectly reported as unresolved despite working as expected. - ignore: ['^ava$'], - }, - ], - }, -}; diff --git a/packages/angular/.prettierrc.js b/packages/angular/.prettierrc.js deleted file mode 100644 index 2c26853c4a..0000000000 --- a/packages/angular/.prettierrc.js +++ /dev/null @@ -1,6 +0,0 @@ -module.exports = { - $schema: 'http://json.schemastore.org/prettierrc', - singleQuote: true, - jsxSingleQuote: true, - endOfLine: 'auto', -}; diff --git a/packages/angular/LICENSE b/packages/angular/LICENSE deleted file mode 100644 index 064ca1d9d2..0000000000 --- a/packages/angular/LICENSE +++ /dev/null @@ -1,22 +0,0 @@ -The MIT License - -Copyright (c) 2019 EclipseSource Munich -https://github.com/eclipsesource/jsonforms - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in -all copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN -THE SOFTWARE. diff --git a/packages/angular/README.md b/packages/angular/README.md deleted file mode 100644 index c956524946..0000000000 --- a/packages/angular/README.md +++ /dev/null @@ -1,152 +0,0 @@ -# JSON Forms - More Forms. Less Code - -_Complex forms in the blink of an eye_ - -JSON Forms eliminates the tedious task of writing fully-featured forms by hand by leveraging the capabilities of JSON, JSON Schema and Javascript. - -## Angular Package - -This is the JSON Forms Angular package which provides the necessary bindings for Angular. It uses [JSON Forms Core](https://github.com/eclipsesource/jsonforms/blob/master/packages/core). - -You can combine the Angular package with any Angular-based renderer set you want, for example the [Material Renderers](https://github.com/eclipsesource/jsonforms/blob/master/packages/angular-material). - -See the official [documentation](https://jsonforms.io/docs/integrations/angular) and the JSON Forms Angular [seed repository](https://github.com/eclipsesource/jsonforms-angular-seed) for examples on how to integrate JSON Forms with your application. - -Check for all published JSON Forms packages. - -### Usage - -Use the `JsonForms` component to render a form for your data. - -Mandatory props: - -- `data: any` - the data to show -- `renderers: JsonFormsRendererRegistryEntry[]` - the Angular renderer set to use - -Optional props: - -- `schema: JsonSchema` - the data schema for the given data. Will be generated when not given. -- `uischema: UISchemaElement` - the UI schema for the given data schema. Will be generated when not given. -- `config: any` - form-wide options. May contain default ui schema options. -- `readonly: boolean` - whether all controls shall be readonly. -- `uischemas: JsonFormsUiSchemaEntry[]` - registry for dynamic ui schema dispatching -- `validationMode: 'ValidateAndShow' | 'ValidateAndHide' | 'NoValidation'` - the validation mode for the form -- `ajv: AJV` - custom Ajv instance for the form -- `middleware: Middleware` - can be used to hook into the form-wide data management. -- `i18n: JsonFormsI18nState` - can be used to internationalize the rendered form. -- `dataChange` - event emitter which is called on each data change, containing the updated data and the validation result. -- `errors` - event emitter which is called with all validations errors. - -Example component file `app.component.ts`: - -```ts -import { Component } from '@angular/core'; -import { angularMaterialRenderers } from '@jsonforms/angular-material'; - -@Component({ - selector: 'app-root', - template: ``, -}) -export class AppComponent { - renderers = angularMaterialRenderers; - uischema = { - type: 'VerticalLayout', - elements: [ - { - type: 'Control', - label: false, - scope: '#/properties/done', - }, - { - type: 'Control', - scope: '#/properties/name', - }, - { - type: 'HorizontalLayout', - elements: [ - { - type: 'Control', - scope: '#/properties/due_date', - }, - { - type: 'Control', - scope: '#/properties/recurrence', - }, - ], - }, - ], - }; - schema = { - type: 'object', - properties: { - name: { - type: 'string', - minLength: 1, - }, - done: { - type: 'boolean', - }, - due_date: { - type: 'string', - format: 'date', - }, - recurrence: { - type: 'string', - enum: ['Never', 'Daily', 'Weekly', 'Monthly'], - }, - }, - required: ['name', 'due_date'], - }; - data = {}; -} -``` - -Example module file: - -```ts -import { NgModule } from '@angular/core'; -import { BrowserModule } from '@angular/platform-browser'; -import { BrowserAnimationsModule } from '@angular/platform-browser/animations'; -import { JsonFormsModule } from '@jsonforms/angular'; -import { JsonFormsAngularMaterialModule } from '@jsonforms/angular-material'; -import { AppComponent } from './app.component'; - -@NgModule({ - declarations: [AppComponent], - imports: [ - BrowserModule, - BrowserAnimationsModule, - JsonFormsModule, - JsonFormsAngularMaterialModule, - ], - schemas: [], - bootstrap: [AppComponent], -}) -export class AppModule {} -``` - -## License - -The JSON Forms project is licensed under the MIT License. See the [LICENSE file](https://github.com/eclipsesource/jsonforms/blob/master/LICENSE) for more information. - -## Roadmap - -Our current roadmap is available [here](https://github.com/eclipsesource/jsonforms/blob/master/ROADMAP.md). - -## Feedback, Help and Support - -JSON Forms is developed by [EclipseSource](https://eclipsesource.com). - -If you encounter any problems feel free to [open an issue](https://github.com/eclipsesource/jsonforms/issues/new/choose) on the repo. -For questions and discussions please use the [JSON Forms board](https://jsonforms.discourse.group). -You can also reach us via [email](mailto:jsonforms@eclipsesource.com?subject=JSON%20Forms). -In addition, EclipseSource also offers [professional support](https://jsonforms.io/support) for JSON Forms. - -## Migration - -See our [migration guide](https://github.com/eclipsesource/jsonforms/blob/master/MIGRATION.md) when updating JSON Forms. diff --git a/packages/angular/build-package.js b/packages/angular/build-package.js deleted file mode 100644 index aef214d1a9..0000000000 --- a/packages/angular/build-package.js +++ /dev/null @@ -1,11 +0,0 @@ -const ngPackage = require('ng-packagr'); - -ngPackage - .ngPackagr() - .forProject('ng-package.json') - .withTsConfig('tsconfig.json') - .build() - .catch(error => { - console.error(error); - process.exit(1); - }); \ No newline at end of file diff --git a/packages/angular/ng-package.json b/packages/angular/ng-package.json deleted file mode 100644 index 84439008d2..0000000000 --- a/packages/angular/ng-package.json +++ /dev/null @@ -1,5 +0,0 @@ -{ - "$schema": "./node_modules/ng-packagr/ng-package.schema.json", - "dest": "./lib", - "allowedNonPeerDependencies": ["lodash"] -} \ No newline at end of file diff --git a/packages/angular/package.json b/packages/angular/package.json deleted file mode 100644 index 9510d59bad..0000000000 --- a/packages/angular/package.json +++ /dev/null @@ -1,103 +0,0 @@ -{ - "name": "@jsonforms/angular", - "version": "3.4.1", - "description": "Angular module of JSON Forms", - "repository": "https://github.com/eclipsesource/jsonforms", - "bugs": "https://github.com/eclipsesource/jsonforms/issues", - "homepage": "http://jsonforms.io/", - "license": "MIT", - "publishConfig": { - "access": "public" - }, - "directories": { - "src": "src", - "test": "test" - }, - "files": [ - "lib", - "src" - ], - "keywords": [ - "angular", - "form", - "forms", - "json", - "jsonforms", - "frontend", - "generator", - "input", - "renderengine", - "jsonschema", - "schema", - "uischema", - "layout", - "customization" - ], - "module": "./lib/fesm2022/jsonforms-angular.mjs", - "typings": "./lib/index.d.ts", - "scripts": { - "build": "node ./build-package.js", - "clean": "rimraf lib coverage dist .nyc_output 2> /dev/null", - "lint": "eslint .", - "lint:fix": "eslint --fix .", - "report": "nyc report --reporter=html", - "test": "ava", - "test-cov": "nyc ava", - "doc": "typedoc --name 'JSON Forms Angular Core' --out docs src" - }, - "nyc": { - "reporter": [ - "lcov", - "text-summary" - ] - }, - "ava": { - "files": [ - "test/**/*" - ], - "extensions": [ - "ts" - ], - "require": [ - "./test-config/ts-node.config.js", - "source-map-support/register.js" - ] - }, - "dependencies": { - "lodash": "^4.17.21" - }, - "peerDependencies": { - "@angular/core": "^17.0.0 || ^18.0.0", - "@angular/forms": "^17.0.0 || ^18.0.0", - "@jsonforms/core": "3.4.1", - "rxjs": "^6.6.0 || ^7.4.0" - }, - "devDependencies": { - "@angular-eslint/eslint-plugin": "^17.0.0", - "@angular-eslint/eslint-plugin-template": "^17.0.0", - "@angular-eslint/schematics": "^17.0.0", - "@angular-eslint/template-parser": "^17.0.0", - "@angular/compiler": "^17.0.0", - "@angular/compiler-cli": "^17.0.0", - "@angular/core": "^17.0.0", - "@angular/forms": "^17.0.0", - "@jsonforms/core": "workspace:*", - "@typescript-eslint/eslint-plugin": "^5.54.1", - "@typescript-eslint/parser": "^5.54.1", - "ava": "^6.1.2", - "copy-webpack-plugin": "^5.0.5", - "eslint": "^8.56.0", - "eslint-config-prettier": "^8.7.0", - "eslint-plugin-import": "^2.27.5", - "eslint-plugin-prettier": "^4.2.1", - "ng-packagr": "^17.0.0", - "nyc": "^15.1.0", - "prettier": "^2.8.4", - "rimraf": "^3.0.2", - "rxjs": "^6.6.0", - "source-map-support": "^0.5.21", - "tslib": "^2.3.0", - "typedoc": "~0.25.3", - "typescript": "~5.2.2" - } -} diff --git a/packages/angular/src/index.ts b/packages/angular/src/index.ts deleted file mode 100644 index 4aaf8f92ed..0000000000 --- a/packages/angular/src/index.ts +++ /dev/null @@ -1 +0,0 @@ -export * from './public_api'; diff --git a/packages/angular/src/library/abstract-control.ts b/packages/angular/src/library/abstract-control.ts deleted file mode 100644 index af43608ce0..0000000000 --- a/packages/angular/src/library/abstract-control.ts +++ /dev/null @@ -1,183 +0,0 @@ -/* - The MIT License - - Copyright (c) 2017-2019 EclipseSource Munich - https://github.com/eclipsesource/jsonforms - - Permission is hereby granted, free of charge, to any person obtaining a copy - of this software and associated documentation files (the "Software"), to deal - in the Software without restriction, including without limitation the rights - to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - copies of the Software, and to permit persons to whom the Software is - furnished to do so, subject to the following conditions: - - The above copyright notice and this permission notice shall be included in - all copies or substantial portions of the Software. - - THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - THE SOFTWARE. -*/ -import { - Actions, - computeLabel, - ControlElement, - JsonFormsState, - JsonSchema, - OwnPropsOfControl, - removeId, - StatePropsOfControl, -} from '@jsonforms/core'; -import { Component, Input, OnDestroy, OnInit } from '@angular/core'; -import { - AbstractControl, - FormControl, - ValidationErrors, - ValidatorFn, -} from '@angular/forms'; - -import { JsonFormsBaseRenderer } from './base.renderer'; -import { JsonFormsAngularService } from './jsonforms.service'; -import merge from 'lodash/merge'; -@Component({ - template: '', -}) -export abstract class JsonFormsAbstractControl< - Props extends StatePropsOfControl - > - extends JsonFormsBaseRenderer - implements OnInit, OnDestroy -{ - @Input() id: string; - @Input() disabled: boolean; - @Input() visible: boolean; - - form: FormControl; - data: any; - label: string; - description: string; - error: string | null; - scopedSchema: JsonSchema; - rootSchema: JsonSchema; - enabled: boolean; - hidden: boolean; - propsPath: string; - - constructor(protected jsonFormsService: JsonFormsAngularService) { - super(); - this.form = new FormControl( - { - value: '', - disabled: true, - }, - { - updateOn: 'change', - validators: this.validator.bind(this), - } - ); - } - - getEventValue = (event: any) => event.value; - - onChange(ev: any) { - this.jsonFormsService.updateCore( - Actions.update(this.propsPath, () => this.getEventValue(ev)) - ); - this.triggerValidation(); - } - - shouldShowUnfocusedDescription(): boolean { - const config = this.jsonFormsService.getConfig(); - const appliedUiSchemaOptions = merge({}, config, this.uischema.options); - return !!appliedUiSchemaOptions.showUnfocusedDescription; - } - - ngOnInit() { - this.addSubscription( - this.jsonFormsService.$state.subscribe({ - next: (state: JsonFormsState) => { - const props = this.mapToProps(state); - const { - data, - enabled, - errors, - label, - required, - schema, - rootSchema, - visible, - path, - config, - } = props; - this.label = computeLabel( - label, - required, - config ? config.hideRequiredAsterisk : false - ); - this.data = data; - this.error = errors; - this.enabled = enabled; - this.isEnabled() ? this.form.enable() : this.form.disable(); - this.hidden = !visible; - this.scopedSchema = schema; - this.rootSchema = rootSchema; - this.description = - this.scopedSchema !== undefined - ? this.scopedSchema.description - : ''; - this.id = props.id; - this.form.setValue(data); - this.propsPath = path; - this.mapAdditionalProps(props); - }, - }) - ); - this.triggerValidation(); - } - - validator: ValidatorFn = (_c: AbstractControl): ValidationErrors | null => { - return this.error ? { error: this.error } : null; - }; - - mapAdditionalProps(_props: Props) { - // do nothing by default - } - - ngOnDestroy() { - super.ngOnDestroy(); - removeId(this.id); - } - - isEnabled(): boolean { - return this.enabled; - } - - protected getOwnProps(): OwnPropsOfControl { - const props: OwnPropsOfControl = { - uischema: this.uischema, - schema: this.schema, - path: this.path, - id: this.id, - }; - if (this.disabled !== undefined) { - props.enabled = !this.disabled; - } - if (this.visible !== undefined) { - props.visible = this.visible; - } - return props; - } - - protected abstract mapToProps(state: JsonFormsState): Props; - - protected triggerValidation() { - // these cause the correct update of the error underline, seems to be - // related to ionic-team/ionic#11640 - this.form.markAsTouched(); - this.form.updateValueAndValidity(); - } -} diff --git a/packages/angular/src/library/array-control.ts b/packages/angular/src/library/array-control.ts deleted file mode 100644 index 5e0bfbc5e5..0000000000 --- a/packages/angular/src/library/array-control.ts +++ /dev/null @@ -1,55 +0,0 @@ -/* - The MIT License - - Copyright (c) 2017-2019 EclipseSource Munich - https://github.com/eclipsesource/jsonforms - - Permission is hereby granted, free of charge, to any person obtaining a copy - of this software and associated documentation files (the "Software"), to deal - in the Software without restriction, including without limitation the rights - to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - copies of the Software, and to permit persons to whom the Software is - furnished to do so, subject to the following conditions: - - The above copyright notice and this permission notice shall be included in - all copies or substantial portions of the Software. - - THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - THE SOFTWARE. -*/ -import { - arrayDefaultTranslations, - ArrayTranslations, - defaultJsonFormsI18nState, - getArrayTranslations, - JsonFormsState, - mapStateToArrayControlProps, - StatePropsOfArrayControl, -} from '@jsonforms/core'; -import type { OnDestroy, OnInit } from '@angular/core'; -import { JsonFormsAbstractControl } from './abstract-control'; - -export class JsonFormsArrayControl - extends JsonFormsAbstractControl - implements OnInit, OnDestroy -{ - protected mapToProps( - state: JsonFormsState - ): StatePropsOfArrayControl & { translations: ArrayTranslations } { - const props = mapStateToArrayControlProps(state, this.getOwnProps()); - const t = - state.jsonforms.i18n?.translate ?? defaultJsonFormsI18nState.translate; - const translations = getArrayTranslations( - t, - arrayDefaultTranslations, - props.i18nKeyPrefix, - props.label - ); - return { ...props, translations }; - } -} diff --git a/packages/angular/src/library/base.renderer.ts b/packages/angular/src/library/base.renderer.ts deleted file mode 100644 index 5b283ed03a..0000000000 --- a/packages/angular/src/library/base.renderer.ts +++ /dev/null @@ -1,61 +0,0 @@ -/* - The MIT License - - Copyright (c) 2017-2019 EclipseSource Munich - https://github.com/eclipsesource/jsonforms - - Permission is hereby granted, free of charge, to any person obtaining a copy - of this software and associated documentation files (the "Software"), to deal - in the Software without restriction, including without limitation the rights - to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - copies of the Software, and to permit persons to whom the Software is - furnished to do so, subject to the following conditions: - - The above copyright notice and this permission notice shall be included in - all copies or substantial portions of the Software. - - THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - THE SOFTWARE. -*/ -import { Directive, Input, OnDestroy } from '@angular/core'; -import { - JsonSchema, - OwnPropsOfRenderer, - UISchemaElement, -} from '@jsonforms/core'; -import { Subscription } from 'rxjs'; - -@Directive() -export class JsonFormsBaseRenderer - implements OnDestroy -{ - @Input() uischema: T; - @Input() schema: JsonSchema; - @Input() path: string; - protected subscriptions: Subscription = new Subscription(); - - protected addSubscription(subscription: Subscription | Subscription[]) { - if (Array.isArray(subscription)) { - subscription.forEach((sub) => this.subscriptions.add(sub)); - } else { - this.subscriptions.add(subscription); - } - } - - protected getOwnProps(): OwnPropsOfRenderer { - return { - uischema: this.uischema, - schema: this.schema, - path: this.path, - }; - } - - ngOnDestroy(): void { - this.subscriptions.unsubscribe(); - } -} diff --git a/packages/angular/src/library/control.ts b/packages/angular/src/library/control.ts deleted file mode 100644 index 80aa166648..0000000000 --- a/packages/angular/src/library/control.ts +++ /dev/null @@ -1,53 +0,0 @@ -/* - The MIT License - - Copyright (c) 2017-2019 EclipseSource Munich - https://github.com/eclipsesource/jsonforms - - Permission is hereby granted, free of charge, to any person obtaining a copy - of this software and associated documentation files (the "Software"), to deal - in the Software without restriction, including without limitation the rights - to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - copies of the Software, and to permit persons to whom the Software is - furnished to do so, subject to the following conditions: - - The above copyright notice and this permission notice shall be included in - all copies or substantial portions of the Software. - - THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - THE SOFTWARE. -*/ -import { - JsonFormsState, - mapStateToControlProps, - mapStateToControlWithDetailProps, - StatePropsOfControl, - StatePropsOfControlWithDetail, -} from '@jsonforms/core'; -import type { OnDestroy, OnInit } from '@angular/core'; -import { JsonFormsAbstractControl } from './abstract-control'; - -export class JsonFormsControl - extends JsonFormsAbstractControl - implements OnInit, OnDestroy -{ - protected mapToProps(state: JsonFormsState): StatePropsOfControl { - const props = mapStateToControlProps(state, this.getOwnProps()); - return { ...props }; - } -} - -export class JsonFormsControlWithDetail - extends JsonFormsAbstractControl - implements OnInit, OnDestroy -{ - protected mapToProps(state: JsonFormsState): StatePropsOfControlWithDetail { - const props = mapStateToControlWithDetailProps(state, this.getOwnProps()); - return { ...props }; - } -} diff --git a/packages/angular/src/library/index.ts b/packages/angular/src/library/index.ts deleted file mode 100644 index c68de6b6b5..0000000000 --- a/packages/angular/src/library/index.ts +++ /dev/null @@ -1,33 +0,0 @@ -/* - The MIT License - - Copyright (c) 2017-2020 EclipseSource Munich - https://github.com/eclipsesource/jsonforms - - Permission is hereby granted, free of charge, to any person obtaining a copy - of this software and associated documentation files (the "Software"), to deal - in the Software without restriction, including without limitation the rights - to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - copies of the Software, and to permit persons to whom the Software is - furnished to do so, subject to the following conditions: - - The above copyright notice and this permission notice shall be included in - all copies or substantial portions of the Software. - - THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - THE SOFTWARE. -*/ -export * from './base.renderer'; -export * from './control'; -export * from './array-control'; -export * from './jsonforms.component'; -export * from './jsonforms.module'; -export * from './unknown.component'; -export * from './jsonforms.service'; -export * from './jsonforms-root.component'; -export * from './abstract-control'; diff --git a/packages/angular/src/library/jsonforms-root.component.ts b/packages/angular/src/library/jsonforms-root.component.ts deleted file mode 100644 index 1150a75436..0000000000 --- a/packages/angular/src/library/jsonforms-root.component.ts +++ /dev/null @@ -1,209 +0,0 @@ -/* - The MIT License - - Copyright (c) 2017-2020 EclipseSource Munich - https://github.com/eclipsesource/jsonforms - - Permission is hereby granted, free of charge, to any person obtaining a copy - of this software and associated documentation files (the "Software"), to deal - in the Software without restriction, including without limitation the rights - to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - copies of the Software, and to permit persons to whom the Software is - furnished to do so, subject to the following conditions: - - The above copyright notice and this permission notice shall be included in - all copies or substantial portions of the Software. - - THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - THE SOFTWARE. -*/ -import { - Component, - DoCheck, - EventEmitter, - Input, - OnChanges, - OnDestroy, - OnInit, - Output, - SimpleChanges, -} from '@angular/core'; -import { - Actions, - JsonFormsI18nState, - JsonFormsRendererRegistryEntry, - JsonSchema, - Middleware, - UISchemaElement, - UISchemaTester, - ValidationMode, - defaultMiddleware, -} from '@jsonforms/core'; -import Ajv, { ErrorObject } from 'ajv'; -import { JsonFormsAngularService, USE_STATE_VALUE } from './jsonforms.service'; -import { Subscription } from 'rxjs'; - -// TODO Can this be rewritten to not use DoCheck and OnChanges? -/* eslint-disable @angular-eslint/no-conflicting-lifecycle */ -@Component({ - selector: 'jsonforms', - template: '', - providers: [JsonFormsAngularService], -}) -export class JsonForms implements DoCheck, OnChanges, OnInit, OnDestroy { - @Input() uischema: UISchemaElement; - @Input() schema: JsonSchema; - @Input() data: any; - @Input() renderers: JsonFormsRendererRegistryEntry[]; - @Input() uischemas: { tester: UISchemaTester; uischema: UISchemaElement }[]; - @Output() dataChange = new EventEmitter(); - @Input() readonly: boolean; - @Input() validationMode: ValidationMode; - @Input() ajv: Ajv; - @Input() config: any; - @Input() i18n: JsonFormsI18nState; - @Input() additionalErrors: ErrorObject[]; - @Input() middleware: Middleware = defaultMiddleware; - @Output() errors = new EventEmitter(); - - private previousData: any; - private previousErrors: ErrorObject[]; - subscription: Subscription; - - private initialized = false; - oldI18N: JsonFormsI18nState; - - constructor(private jsonformsService: JsonFormsAngularService) {} - - ngOnInit(): void { - this.jsonformsService.init( - { - core: { - data: this.data, - uischema: this.uischema, - schema: this.schema, - ajv: this.ajv, - validationMode: this.validationMode, - additionalErrors: this.additionalErrors, - }, - uischemas: this.uischemas, - i18n: this.i18n, - renderers: this.renderers, - config: this.config, - readonly: this.readonly, - }, - this.middleware - ); - this.subscription = this.jsonformsService.$state.subscribe((state) => { - const data = state?.jsonforms?.core?.data; - const errors = state?.jsonforms?.core?.errors; - if (this.previousData !== data) { - this.previousData = data; - this.dataChange.emit(data); - } - if (this.previousErrors !== errors) { - this.previousErrors = errors; - this.errors.emit(errors); - } - }); - this.oldI18N = this.i18n; - this.initialized = true; - } - - ngDoCheck(): void { - // we can't use ngOnChanges as then nested i18n changes will not be detected - // the update will result in a no-op when the parameters did not change - if ( - this.oldI18N?.locale !== this.i18n?.locale || - this.oldI18N?.translate !== this.i18n?.translate || - this.oldI18N?.translateError !== this.i18n?.translateError - ) { - this.jsonformsService.updateI18n( - Actions.updateI18n( - this.oldI18N?.locale === this.i18n?.locale - ? this.jsonformsService.getState().jsonforms.i18n.locale - : this.i18n?.locale, - this.oldI18N?.translate === this.i18n?.translate - ? this.jsonformsService.getState().jsonforms.i18n.translate - : this.i18n?.translate, - this.oldI18N?.translateError === this.i18n?.translateError - ? this.jsonformsService.getState().jsonforms.i18n.translateError - : this.i18n?.translateError - ) - ); - this.oldI18N = this.i18n; - } - } - - ngOnChanges(changes: SimpleChanges): void { - if (!this.initialized) { - return; - } - const newData = changes.data; - const newSchema = changes.schema; - const newUiSchema = changes.uischema; - const newRenderers = changes.renderers; - const newUischemas = changes.uischemas; - const newI18n = changes.i18n; - const newReadonly = changes.readonly; - const newValidationMode = changes.validationMode; - const newAjv = changes.ajv; - const newConfig = changes.config; - const newAdditionalErrors = changes.additionalErrors; - - if ( - newData || - newSchema || - newUiSchema || - newValidationMode || - newAjv || - newAdditionalErrors - ) { - this.jsonformsService.updateCoreState( - newData ? newData.currentValue : USE_STATE_VALUE, - newSchema ? newSchema.currentValue : USE_STATE_VALUE, - newUiSchema ? newUiSchema.currentValue : USE_STATE_VALUE, - newAjv ? newAjv.currentValue : USE_STATE_VALUE, - newValidationMode ? newValidationMode.currentValue : USE_STATE_VALUE, - newAdditionalErrors ? newAdditionalErrors.currentValue : USE_STATE_VALUE - ); - } - - if (newRenderers && !newRenderers.isFirstChange()) { - this.jsonformsService.setRenderers(newRenderers.currentValue); - } - - if (newUischemas && !newUischemas.isFirstChange()) { - this.jsonformsService.setUiSchemas(newUischemas.currentValue); - } - - if (newI18n && !newI18n.isFirstChange()) { - this.jsonformsService.updateI18n( - Actions.updateI18n( - newI18n.currentValue?.locale, - newI18n.currentValue?.translate, - newI18n.currentValue?.translateError - ) - ); - } - - if (newReadonly && !newReadonly.isFirstChange()) { - this.jsonformsService.setReadonly(newReadonly.currentValue); - } - - if (newConfig && !newConfig.isFirstChange()) { - this.jsonformsService.updateConfig( - Actions.setConfig(newConfig.currentValue) - ); - } - } - - ngOnDestroy(): void { - this.subscription.unsubscribe(); - } -} diff --git a/packages/angular/src/library/jsonforms.component.ts b/packages/angular/src/library/jsonforms.component.ts deleted file mode 100644 index 22a93264bf..0000000000 --- a/packages/angular/src/library/jsonforms.component.ts +++ /dev/null @@ -1,153 +0,0 @@ -/* - The MIT License - - Copyright (c) 2017-2019 EclipseSource Munich - https://github.com/eclipsesource/jsonforms - - Permission is hereby granted, free of charge, to any person obtaining a copy - of this software and associated documentation files (the "Software"), to deal - in the Software without restriction, including without limitation the rights - to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - copies of the Software, and to permit persons to whom the Software is - furnished to do so, subject to the following conditions: - - The above copyright notice and this permission notice shall be included in - all copies or substantial portions of the Software. - - THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - THE SOFTWARE. -*/ -import maxBy from 'lodash/maxBy'; -import { - ComponentFactoryResolver, - Directive, - Input, - OnInit, - Type, - ViewContainerRef, -} from '@angular/core'; -import { - createId, - isControl, - getConfig, - JsonFormsProps, - JsonFormsState, - JsonSchema, - mapStateToJsonFormsRendererProps, - OwnPropsOfRenderer, - StatePropsOfJsonFormsRenderer, - UISchemaElement, -} from '@jsonforms/core'; -import { UnknownRenderer } from './unknown.component'; -import { JsonFormsBaseRenderer } from './base.renderer'; -import { JsonFormsControl } from './control'; -import { JsonFormsAngularService } from './jsonforms.service'; - -import { get, isEqual } from 'lodash'; - -const areEqual = ( - prevProps: StatePropsOfJsonFormsRenderer, - nextProps: StatePropsOfJsonFormsRenderer -) => { - return ( - get(prevProps, 'renderers.length') === get(nextProps, 'renderers.length') && - get(prevProps, 'cells.length') === get(nextProps, 'cells.length') && - get(prevProps, 'uischemas.length') === get(nextProps, 'uischemas.length') && - get(prevProps, 'schema') === get(nextProps, 'schema') && - isEqual(get(prevProps, 'uischema'), get(nextProps, 'uischema')) && - get(prevProps, 'path') === get(nextProps, 'path') - ); -}; - -@Directive({ - selector: 'jsonforms-outlet', -}) -export class JsonFormsOutlet - extends JsonFormsBaseRenderer - implements OnInit -{ - private previousProps: StatePropsOfJsonFormsRenderer; - - constructor( - private viewContainerRef: ViewContainerRef, - private componentFactoryResolver: ComponentFactoryResolver, - private jsonformsService: JsonFormsAngularService - ) { - super(); - } - - @Input() - set renderProps(renderProps: OwnPropsOfRenderer) { - this.path = renderProps.path; - this.schema = renderProps.schema; - this.uischema = renderProps.uischema; - this.update(this.jsonformsService.getState()); - } - - ngOnInit(): void { - this.addSubscription( - this.jsonformsService.$state.subscribe({ - next: (state: JsonFormsState) => this.update(state), - }) - ); - } - - update(state: JsonFormsState) { - const props = mapStateToJsonFormsRendererProps(state, { - schema: this.schema, - uischema: this.uischema, - path: this.path, - }); - if (areEqual(this.previousProps, props)) { - return; - } else { - this.previousProps = props; - } - const { renderers } = props as JsonFormsProps; - const schema: JsonSchema = this.schema || props.schema; - const uischema = this.uischema || props.uischema; - const testerContext = { - rootSchema: props.rootSchema, - config: getConfig(state), - }; - - const renderer = maxBy(renderers, (r) => - r.tester(uischema, schema, testerContext) - ); - let bestComponent: Type = UnknownRenderer; - if ( - renderer !== undefined && - renderer.tester(uischema, schema, testerContext) !== -1 - ) { - bestComponent = renderer.renderer; - } - - const componentFactory = - this.componentFactoryResolver.resolveComponentFactory(bestComponent); - this.viewContainerRef.clear(); - const currentComponentRef = - this.viewContainerRef.createComponent(componentFactory); - - if (currentComponentRef.instance instanceof JsonFormsBaseRenderer) { - const instance = - currentComponentRef.instance as JsonFormsBaseRenderer; - instance.uischema = uischema; - instance.schema = schema; - instance.path = this.path; - if (instance instanceof JsonFormsControl) { - const controlInstance = instance as JsonFormsControl; - if (controlInstance.id === undefined) { - const id = isControl(props.uischema) - ? createId(props.uischema.scope) - : undefined; - (instance as JsonFormsControl).id = id; - } - } - } - } -} diff --git a/packages/angular/src/library/jsonforms.module.ts b/packages/angular/src/library/jsonforms.module.ts deleted file mode 100644 index 037af6bc2c..0000000000 --- a/packages/angular/src/library/jsonforms.module.ts +++ /dev/null @@ -1,34 +0,0 @@ -/* - The MIT License - - Copyright (c) 2017-2020 EclipseSource Munich - https://github.com/eclipsesource/jsonforms - - Permission is hereby granted, free of charge, to any person obtaining a copy - of this software and associated documentation files (the "Software"), to deal - in the Software without restriction, including without limitation the rights - to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - copies of the Software, and to permit persons to whom the Software is - furnished to do so, subject to the following conditions: - - The above copyright notice and this permission notice shall be included in - all copies or substantial portions of the Software. - - THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - THE SOFTWARE. -*/ -import { NgModule } from '@angular/core'; - -import { JsonForms } from './jsonforms-root.component'; -import { JsonFormsOutlet } from './jsonforms.component'; -import { UnknownRenderer } from './unknown.component'; -@NgModule({ - declarations: [JsonFormsOutlet, UnknownRenderer, JsonForms], - exports: [JsonFormsOutlet, JsonForms], -}) -export class JsonFormsModule {} diff --git a/packages/angular/src/library/jsonforms.service.ts b/packages/angular/src/library/jsonforms.service.ts deleted file mode 100644 index 4b299c65ab..0000000000 --- a/packages/angular/src/library/jsonforms.service.ts +++ /dev/null @@ -1,328 +0,0 @@ -/* - The MIT License - - Copyright (c) 2017-2020 EclipseSource Munich - https://github.com/eclipsesource/jsonforms - - Permission is hereby granted, free of charge, to any person obtaining a copy - of this software and associated documentation files (the "Software"), to deal - in the Software without restriction, including without limitation the rights - to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - copies of the Software, and to permit persons to whom the Software is - furnished to do so, subject to the following conditions: - - The above copyright notice and this permission notice shall be included in - all copies or substantial portions of the Software. - - THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - THE SOFTWARE. -*/ -import { - Actions, - configReducer, - CoreActions, - coreReducer, - generateDefaultUISchema, - generateJsonSchema, - i18nReducer, - JsonFormsRendererRegistryEntry, - JsonFormsState, - JsonFormsSubStates, - JsonSchema, - I18nActions, - RankedTester, - setConfig, - SetConfigAction, - UISchemaActions, - UISchemaElement, - uischemaRegistryReducer, - UISchemaTester, - ValidationMode, - updateI18n, - Middleware, - defaultMiddleware, -} from '@jsonforms/core'; -import { BehaviorSubject, Observable } from 'rxjs'; -import type { JsonFormsBaseRenderer } from './base.renderer'; - -import { cloneDeep } from 'lodash'; -import type Ajv from 'ajv'; -import type { ErrorObject } from 'ajv'; - -export const USE_STATE_VALUE = Symbol('Marker to use state value'); -export class JsonFormsAngularService { - private _state: JsonFormsSubStates; - private state: BehaviorSubject; - private middleware: Middleware; - - init( - initialState: JsonFormsSubStates = { - core: { - data: undefined, - schema: undefined, - uischema: undefined, - validationMode: 'ValidateAndShow', - additionalErrors: undefined, - }, - }, - middleware: Middleware = defaultMiddleware - ) { - this.middleware = middleware; - this._state = initialState; - this._state.config = configReducer( - undefined, - setConfig(this._state.config) - ); - this._state.i18n = i18nReducer( - this._state.i18n, - updateI18n( - this._state.i18n?.locale, - this._state.i18n?.translate, - this._state.i18n?.translateError - ) - ); - this.state = new BehaviorSubject({ jsonforms: this._state }); - const data = initialState.core.data; - const schema = initialState.core.schema ?? generateJsonSchema(data); - const uischema = - initialState.core.uischema ?? generateDefaultUISchema(schema); - this.updateCore(Actions.init(data, schema, uischema)); - } - - get $state(): Observable { - if (!this.state) { - throw new Error('Please call init first!'); - } - return this.state.asObservable(); - } - - /** - * @deprecated use {@link JsonFormsAngularService.addRenderer} - */ - registerRenderer( - renderer: JsonFormsBaseRenderer, - tester: RankedTester - ): void { - this.addRenderer(renderer, tester); - } - addRenderer( - renderer: JsonFormsBaseRenderer, - tester: RankedTester - ): void { - this._state.renderers.push({ renderer, tester }); - this.updateSubject(); - } - - /** - * @deprecated use {@link JsonFormsAngularService.setRenderer} - */ - registerRenderers(renderers: JsonFormsRendererRegistryEntry[]): void { - this.setRenderers(renderers); - } - setRenderers(renderers: JsonFormsRendererRegistryEntry[]): void { - this._state.renderers = renderers; - this.updateSubject(); - } - - /** - * @deprecated use {@link JsonFormsAngularService.removeRenderer} - */ - unregisterRenderer(tester: RankedTester): void { - this.removeRenderer(tester); - } - removeRenderer(tester: RankedTester): void { - const findIndex = this._state.renderers.findIndex( - (v) => v.tester === tester - ); - if (findIndex === -1) { - return; - } - const renderers = this._state.renderers.filter((v) => v.tester !== tester); - this._state.renderers = renderers; - this.updateSubject(); - } - - updateValidationMode(validationMode: ValidationMode): void { - const coreState = this.middleware( - this._state.core, - Actions.setValidationMode(validationMode), - coreReducer - ); - this._state.core = coreState; - this.updateSubject(); - } - - updateI18n(i18nAction: T): T { - const i18nState = i18nReducer(this._state.i18n, i18nAction); - if (i18nState !== this._state.i18n) { - this._state.i18n = i18nState; - this.updateSubject(); - } - return i18nAction; - } - - updateCore(coreAction: T): T { - const coreState = this.middleware( - this._state.core, - coreAction, - coreReducer - ); - if (coreState !== this._state.core) { - this._state.core = coreState; - this.updateSubject(); - } - return coreAction; - } - - /** - * @deprecated use {@link JsonFormsAngularService.setUiSchemas} - */ - updateUiSchema(uischemaAction: T): T { - const uischemaState = uischemaRegistryReducer( - this._state.uischemas, - uischemaAction - ); - this._state.uischemas = uischemaState; - this.updateSubject(); - return uischemaAction; - } - - setUiSchemas( - uischemas: { tester: UISchemaTester; uischema: UISchemaElement }[] - ): void { - this._state.uischemas = uischemas; - this.updateSubject(); - } - - updateConfig(setConfigAction: T): T { - const configState = configReducer(this._state.config, setConfigAction); - this._state.config = configState; - this.updateSubject(); - return setConfigAction; - } - - setUiSchema(uischema: UISchemaElement | undefined): void { - const newUiSchema = - uischema ?? generateDefaultUISchema(this._state.core.schema); - const coreState = this.middleware( - this._state.core, - Actions.updateCore( - this._state.core.data, - this._state.core.schema, - newUiSchema - ), - coreReducer - ); - if (coreState !== this._state.core) { - this._state.core = coreState; - this.updateSubject(); - } - } - - setSchema(schema: JsonSchema | undefined): void { - const coreState = this.middleware( - this._state.core, - Actions.updateCore( - this._state.core.data, - schema ?? generateJsonSchema(this._state.core.data), - this._state.core.uischema - ), - coreReducer - ); - if (coreState !== this._state.core) { - this._state.core = coreState; - this.updateSubject(); - } - } - - setData(data: any): void { - const coreState = this.middleware( - this._state.core, - Actions.updateCore( - data, - this._state.core.schema, - this._state.core.uischema - ), - coreReducer - ); - if (coreState !== this._state.core) { - this._state.core = coreState; - this.updateSubject(); - } - } - - getLocale(): string | undefined { - return this._state.i18n?.locale; - } - - setLocale(locale: string): void { - this._state.i18n.locale = locale; - this.updateSubject(); - } - - setReadonly(readonly: boolean): void { - this._state.readonly = readonly; - this.updateSubject(); - } - - setMiddleware(middleware: Middleware): void { - this._state.middleware = middleware; - this.updateSubject(); - } - - getState(): JsonFormsState { - return cloneDeep({ jsonforms: this._state }); - } - - getConfig(): any { - return cloneDeep(this._state.config); - } - - refresh(): void { - this.updateSubject(); - } - - updateCoreState( - data: any | typeof USE_STATE_VALUE, - schema: JsonSchema | typeof USE_STATE_VALUE, - uischema: UISchemaElement | typeof USE_STATE_VALUE, - ajv: Ajv | typeof USE_STATE_VALUE, - validationMode: ValidationMode | typeof USE_STATE_VALUE, - additionalErrors: ErrorObject[] | typeof USE_STATE_VALUE - ): void { - const newData = data === USE_STATE_VALUE ? this._state.core.data : data; - const newSchema = - schema === USE_STATE_VALUE - ? this._state.core.schema - : schema ?? generateJsonSchema(newData); - const newUischema = - uischema === USE_STATE_VALUE - ? this._state.core.uischema - : uischema ?? generateDefaultUISchema(newSchema); - const newAjv = ajv === USE_STATE_VALUE ? this._state.core.ajv : ajv; - const newValidationMode = - validationMode === USE_STATE_VALUE - ? this._state.core.validationMode - : validationMode; - const newAdditionalErrors = - additionalErrors === USE_STATE_VALUE - ? this._state.core.additionalErrors - : additionalErrors; - this.updateCore( - Actions.updateCore(newData, newSchema, newUischema, { - ajv: newAjv, - validationMode: newValidationMode, - additionalErrors: newAdditionalErrors, - }) - ); - } - - private updateSubject(): void { - this.state.next({ jsonforms: this._state }); - } -} diff --git a/packages/angular/src/library/unknown.component.ts b/packages/angular/src/library/unknown.component.ts deleted file mode 100644 index cb51fbe01f..0000000000 --- a/packages/angular/src/library/unknown.component.ts +++ /dev/null @@ -1,30 +0,0 @@ -/* - The MIT License - - Copyright (c) 2017-2019 EclipseSource Munich - https://github.com/eclipsesource/jsonforms - - Permission is hereby granted, free of charge, to any person obtaining a copy - of this software and associated documentation files (the "Software"), to deal - in the Software without restriction, including without limitation the rights - to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - copies of the Software, and to permit persons to whom the Software is - furnished to do so, subject to the following conditions: - - The above copyright notice and this permission notice shall be included in - all copies or substantial portions of the Software. - - THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - THE SOFTWARE. -*/ -import { Component } from '@angular/core'; -@Component({ - selector: 'unknown.renderer', - template: 'No applicable renderer found!', -}) -export class UnknownRenderer {} diff --git a/packages/angular/src/public_api.ts b/packages/angular/src/public_api.ts deleted file mode 100644 index 4b02e6973f..0000000000 --- a/packages/angular/src/public_api.ts +++ /dev/null @@ -1 +0,0 @@ -export * from './library'; diff --git a/packages/angular/test-config/ts-node.config.js b/packages/angular/test-config/ts-node.config.js deleted file mode 100644 index d2d154370e..0000000000 --- a/packages/angular/test-config/ts-node.config.js +++ /dev/null @@ -1,6 +0,0 @@ -// Register ts-node and override ts options for ava -require('ts-node').register({ - compilerOptions: { - module: 'commonjs', - }, -}); diff --git a/packages/angular/test/dummy.test.ts b/packages/angular/test/dummy.test.ts deleted file mode 100644 index 9936e607af..0000000000 --- a/packages/angular/test/dummy.test.ts +++ /dev/null @@ -1,26 +0,0 @@ -/* - The MIT License - - Copyright (c) 2017-2019 EclipseSource Munich - https://github.com/eclipsesource/jsonforms - - Permission is hereby granted, free of charge, to any person obtaining a copy - of this software and associated documentation files (the "Software"), to deal - in the Software without restriction, including without limitation the rights - to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - copies of the Software, and to permit persons to whom the Software is - furnished to do so, subject to the following conditions: - - The above copyright notice and this permission notice shall be included in - all copies or substantial portions of the Software. - - THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - THE SOFTWARE. -*/ -import test from 'ava'; -test.todo('dummy'); diff --git a/packages/angular/test/tsconfig.test.json b/packages/angular/test/tsconfig.test.json deleted file mode 100644 index 8b6cff6dc8..0000000000 --- a/packages/angular/test/tsconfig.test.json +++ /dev/null @@ -1,11 +0,0 @@ -{ - "extends": "../../../tsconfig.base.json", - "compilerOptions": { - "outDir": "../dist/test", - "target": "es6", - "inlineSourceMap": true - }, - "include": ["**/*.ts", "**/*.tsx"], - "exclude": ["node_modules"], - "files": ["../src/index.ts"] -} diff --git a/packages/angular/tsconfig.cjs.json b/packages/angular/tsconfig.cjs.json deleted file mode 100644 index b0c215c3d9..0000000000 --- a/packages/angular/tsconfig.cjs.json +++ /dev/null @@ -1,9 +0,0 @@ -{ - "extends": "./tsconfig", - "compilerOptions": { - "outDir": "./lib/cjs", - "sourceMap": true, - "target": "es5", - "module": "commonjs" - } -} diff --git a/packages/angular/tsconfig.json b/packages/angular/tsconfig.json deleted file mode 100644 index 64692753aa..0000000000 --- a/packages/angular/tsconfig.json +++ /dev/null @@ -1,17 +0,0 @@ -{ - "extends": "../../tsconfig.base", - "compilerOptions": { - "declaration": true, - "declarationMap": true, - "inlineSources": true, - "sourceMap": true, - }, - "exclude": ["node_modules"], - "files": ["src/index.ts"], - "angularCompilerOptions": { - "compilationMode": "partial", - "strictMetadataEmit": true, - "generateCodeForLibraries": false, - "skipTemplateCodegen": true - } -} diff --git a/packages/vue-vanilla/.eslintrc.js b/packages/vue-vanilla/.eslintrc.js deleted file mode 100644 index 1b64a113c9..0000000000 --- a/packages/vue-vanilla/.eslintrc.js +++ /dev/null @@ -1,35 +0,0 @@ -/* eslint-env node */ -/** @type {import('eslint').Linter.Config} */ -module.exports = { - root: true, - parser: 'vue-eslint-parser', - parserOptions: { - ecmaFeatures: { - jsx: true, - }, - }, - // There is no file include in ESLint. Thus, ignore all and include files via negative ignore (!) - ignorePatterns: ['/*', '!/src', '!/tests', '!/dev', '!/config'], - extends: [ - 'eslint:recommended', - 'plugin:@typescript-eslint/recommended', - 'plugin:import/recommended', - 'plugin:import/typescript', - 'plugin:vue/vue3-recommended', - '@vue/typescript/recommended', - 'plugin:prettier-vue/recommended', - ], - rules: { - '@typescript-eslint/no-explicit-any': 'off', - // Base rule must be disabled to avoid incorrect errors - 'no-unused-vars': 'off', - '@typescript-eslint/no-unused-vars': [ - 'warn', // or "error" - { - argsIgnorePattern: '^_', - varsIgnorePattern: '^_', - caughtErrorsIgnorePattern: '^_', - }, - ], - }, -}; diff --git a/packages/vue-vanilla/.prettierrc.js b/packages/vue-vanilla/.prettierrc.js deleted file mode 100644 index 2c26853c4a..0000000000 --- a/packages/vue-vanilla/.prettierrc.js +++ /dev/null @@ -1,6 +0,0 @@ -module.exports = { - $schema: 'http://json.schemastore.org/prettierrc', - singleQuote: true, - jsxSingleQuote: true, - endOfLine: 'auto', -}; diff --git a/packages/vue-vanilla/LICENSE b/packages/vue-vanilla/LICENSE deleted file mode 100644 index 064ca1d9d2..0000000000 --- a/packages/vue-vanilla/LICENSE +++ /dev/null @@ -1,22 +0,0 @@ -The MIT License - -Copyright (c) 2019 EclipseSource Munich -https://github.com/eclipsesource/jsonforms - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in -all copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN -THE SOFTWARE. diff --git a/packages/vue-vanilla/README.md b/packages/vue-vanilla/README.md deleted file mode 100644 index ef704d3b24..0000000000 --- a/packages/vue-vanilla/README.md +++ /dev/null @@ -1,207 +0,0 @@ -# JSON Forms - More Forms. Less Code - -_Complex Forms in the blink of an eye_ - -JSON Forms eliminates the tedious task of writing fully-featured forms by hand by leveraging the capabilities of JSON, JSON Schema and Javascript. - -## Vue Vanilla Renderers - -This is the JSON Forms Vue Vanilla renderers package which provides a HTML5-based renderer set for [JSON Forms Vue](https://github.com/eclipsesource/jsonforms/blob/master/packages/vue). - -### JSON Forms Vue seed app - -See our [JSON Forms Vue seed repository](https://github.com/eclipsesource/jsonforms-vue-seed) to get started as quickly as possible. - -### Quick start - -Install JSON Forms Core, Vue and Vue Vanilla Renderers - -```bash -npm i --save @jsonforms/core @jsonforms/vue @jsonforms/vue-vanilla -``` - -Also add the packages to the transpile dependencies in the `vue.config.js` file: - -```js -module.exports = { - transpileDependencies: [ - '@jsonforms/core', - '@jsonforms/vue', - '@jsonforms/vue-vanilla', - ], -}; -``` - -Use the `json-forms` component for each form you want to render and hand over the renderer set. - -```vue - - -``` - -By default the Vanilla Renderers don't apply any CSS at all. -For a quick start you can use `@jsonforms/vue-vanilla/vanilla.css`. - -For more information on how JSON Forms can be configured, please see the [README of `@jsonforms/vue`](https://github.com/eclipsesource/jsonforms/blob/master/packages/vue/README.md). - -### Styling - -Each rendered HTML element specifies a CSS class which can be used to style it. -This process can also be customized so that each element declares user-specified CSS classes. -Therefore JSON Forms Vue Vanilla can be integrated with any CSS-only UI framework quite easily. - -You can find the default CSS classes in `[defaultStyles.ts](https://github.com/eclipsesource/jsonforms/blob/master/packages/vue-vanilla/src/styles/defaultStyles.ts). - -To render your own classes simply `provide` them as `styles`. -These `styles` replace the `defaultStyles`. -If you want to fall back to `defaultStyles` or combine them with your own classes you'll need to do so programmatically, e.g.: - -```vue - - -``` - -You can also use specify styles in the ui schema via the `options.styles` property. -Attributes specified here override the respective `defaultStyles` or provided `styles`. -Attributes not specified here fall back to either the `defaultStyles` or provided `styles`. - -```js -{ - "type": "Control", - "scope": "#/properties/name", - "options": { - "styles": { - "control": { - "root": "my-control-root" - } - } - } -} -``` - -## License - -The JSONForms project is licensed under the MIT License. See the [LICENSE file](https://github.com/eclipsesource/jsonforms/blob/master/LICENSE) for more information. - -## Roadmap - -Our current roadmap is available [here](https://github.com/eclipsesource/jsonforms/blob/master/ROADMAP.md). - -## Migration - -See our [migration guide](https://github.com/eclipsesource/jsonforms/blob/master/MIGRATION.md) when updating JSON Forms. diff --git a/packages/vue-vanilla/babel.config.js b/packages/vue-vanilla/babel.config.js deleted file mode 100644 index 493d815d04..0000000000 --- a/packages/vue-vanilla/babel.config.js +++ /dev/null @@ -1,12 +0,0 @@ -const devPresets = ['@vue/cli-plugin-babel/preset']; -const buildPresets = ['@babel/preset-env', '@babel/preset-typescript']; -module.exports = { - presets: process.env.NODE_ENV === 'production' ? buildPresets : devPresets, - plugins: - process.env.NODE_ENV === 'test' - ? [ - '@babel/plugin-proposal-optional-chaining', - '@babel/plugin-proposal-nullish-coalescing-operator', - ] - : [], -}; diff --git a/packages/vue-vanilla/config/jsonforms.ts b/packages/vue-vanilla/config/jsonforms.ts deleted file mode 100644 index 7f996761ad..0000000000 --- a/packages/vue-vanilla/config/jsonforms.ts +++ /dev/null @@ -1 +0,0 @@ -export * from '@jsonforms/vue'; diff --git a/packages/vue-vanilla/dev/components/App.vue b/packages/vue-vanilla/dev/components/App.vue deleted file mode 100644 index 59dc1afd0b..0000000000 --- a/packages/vue-vanilla/dev/components/App.vue +++ /dev/null @@ -1,219 +0,0 @@ - - - - - - - - diff --git a/packages/vue-vanilla/dev/serve.ts b/packages/vue-vanilla/dev/serve.ts deleted file mode 100644 index 61d57934c4..0000000000 --- a/packages/vue-vanilla/dev/serve.ts +++ /dev/null @@ -1,4 +0,0 @@ -import { createApp } from 'vue'; -import App from './components/App.vue'; - -createApp(App).mount('#app'); diff --git a/packages/vue-vanilla/example/index.bundled.html b/packages/vue-vanilla/example/index.bundled.html deleted file mode 100644 index 43e5e652df..0000000000 --- a/packages/vue-vanilla/example/index.bundled.html +++ /dev/null @@ -1,14 +0,0 @@ - - - - - JSON Forms Vue Vanilla RendererSet - - - - - -
- - - diff --git a/packages/vue-vanilla/package.json b/packages/vue-vanilla/package.json deleted file mode 100644 index 840f749a7c..0000000000 --- a/packages/vue-vanilla/package.json +++ /dev/null @@ -1,100 +0,0 @@ -{ - "name": "@jsonforms/vue-vanilla", - "version": "3.4.1", - "description": "Vue 3 Vanilla renderers for JSON Forms", - "repository": "https://github.com/eclipsesource/jsonforms", - "bugs": "https://github.com/eclipsesource/jsonforms/issues", - "homepage": "http://jsonforms.io/", - "license": "MIT", - "publishConfig": { - "access": "public" - }, - "keywords": [ - "vue", - "vue3", - "vue 3", - "form", - "forms", - "json", - "jsonforms", - "frontend", - "generator", - "input", - "renderengine", - "jsonschema", - "schema", - "uischema", - "layout", - "customization", - "html5", - "css", - "tailwind" - ], - "main": "lib/jsonforms-vue-vanilla.cjs.js", - "module": "lib/jsonforms-vue-vanilla.esm.js", - "types": "lib/src/index.d.ts", - "files": [ - "lib/*", - "src/*", - "vanilla.css" - ], - "scripts": { - "serve": "vue-cli-service serve dev/serve.ts", - "build": "cross-env NODE_ENV=production rollup --config rollup.config.js", - "build:examples-app": "rollup -c rollup.example.config.js", - "clean": "rimraf lib example/dist", - "lint": "eslint .", - "lint:fix": "eslint --fix .", - "doc": "typedoc --name 'JSON Forms Vue Vanilla Renderers' --out docs src", - "test": "vue-cli-service test:unit" - }, - "dependencies": { - "lodash": "^4.17.21" - }, - "devDependencies": { - "@babel/core": "^7.9.0", - "@babel/preset-env": "^7.9.5", - "@babel/preset-typescript": "^7.9.0", - "@jsonforms/core": "workspace:*", - "@jsonforms/vue": "workspace:*", - "@types/chai": "^4.2.11", - "@types/jest": "^27.4.1", - "@types/mocha": "^5.2.4", - "@types/node": "^18.19.4", - "@typescript-eslint/eslint-plugin": "^5.54.1", - "@typescript-eslint/parser": "^5.54.1", - "@vue/cli-plugin-babel": "~5.0.8", - "@vue/cli-plugin-typescript": "~5.0.8", - "@vue/cli-plugin-unit-mocha": "~5.0.8", - "@vue/cli-service": "~5.0.8", - "@vue/eslint-config-typescript": "^11.0.2", - "@vue/test-utils": "^2.4.5", - "chai": "^4.1.2", - "cross-env": "^7.0.2", - "eslint": "^8.56.0", - "eslint-config-prettier": "^8.7.0", - "eslint-plugin-import": "^2.27.5", - "eslint-plugin-prettier-vue": "^4.2.0", - "eslint-plugin-vue": "^9.9.0", - "npm-run-all": "^4.1.5", - "prettier": "^2.8.4", - "rimraf": "^3.0.2", - "rollup": "^2.78.0", - "rollup-plugin-babel": "^4.4.0", - "rollup-plugin-cleanup": "^3.2.1", - "rollup-plugin-typescript2": "^0.34.1", - "rollup-plugin-visualizer": "^5.4.1", - "rollup-plugin-vue": "^6.0.0", - "symlink-dir": "^5.0.0", - "tslib": "^2.5.0", - "typedoc": "~0.25.3", - "typescript": "~5.2.2", - "vue": "^3.4.21", - "vue-jest": "^5.0.0-0" - }, - "peerDependencies": { - "@jsonforms/core": "3.4.1", - "@jsonforms/vue": "3.4.1", - "vue": "^3.2.26" - } -} diff --git a/packages/vue-vanilla/rollup.config.js b/packages/vue-vanilla/rollup.config.js deleted file mode 100644 index 7ff07e13b8..0000000000 --- a/packages/vue-vanilla/rollup.config.js +++ /dev/null @@ -1,84 +0,0 @@ -import vue from 'rollup-plugin-vue'; -import alias from '@rollup/plugin-alias'; -import babel from 'rollup-plugin-babel'; -import typescript from 'rollup-plugin-typescript2'; -import cleanup from 'rollup-plugin-cleanup'; -import { visualizer } from 'rollup-plugin-visualizer'; - -const packageJson = require('./package.json'); - -const baseConfig = { - input: 'src/index.ts', - external: [ - ...Object.keys(packageJson.dependencies), - ...Object.keys(packageJson.peerDependencies), - /^lodash\/.*/, - ], -}; - -const buildFormats = [ - { - ...baseConfig, - output: { - file: packageJson.module, - format: 'esm', - sourcemap: true, - }, - plugins: [ - typescript({ - tsconfigOverride: { - include: null, - exclude: ['node_modules', 'tests', 'dev'], - }, - }), - alias({ - resolve: ['.js', '.jsx', '.ts', '.tsx', '.vue'], - }), - vue({ - css: false, - template: { - isProduction: true, - }, - }), - babel({ - exclude: 'node_modules/**', - extensions: ['.js', '.jsx', '.ts', '.tsx', '.vue'], - }), - cleanup({ extensions: ['js', 'ts', 'jsx', 'tsx', 'vue'] }), - visualizer({ open: false }), - ], - }, - { - ...baseConfig, - output: { - file: packageJson.main, - format: 'cjs', - sourcemap: true, - }, - plugins: [ - typescript({ - tsconfigOverride: { - include: null, - exclude: ['node_modules', 'tests', 'dev'], - target: 'ES5', - }, - }), - alias({ - resolve: ['.js', '.jsx', '.ts', '.tsx', '.vue'], - }), - vue({ - css: false, - template: { - isProduction: true, - }, - }), - babel({ - exclude: 'node_modules/**', - extensions: ['.js', '.jsx', '.ts', '.tsx', '.vue'], - }), - cleanup({ extensions: ['js', 'ts', 'jsx', 'tsx', 'vue'] }), - ], - }, -]; - -export default buildFormats; diff --git a/packages/vue-vanilla/rollup.example.config.js b/packages/vue-vanilla/rollup.example.config.js deleted file mode 100644 index 54b0d6d5ae..0000000000 --- a/packages/vue-vanilla/rollup.example.config.js +++ /dev/null @@ -1,54 +0,0 @@ -import commonjs from '@rollup/plugin-commonjs'; -import json from '@rollup/plugin-json'; -import nodeResolve from '@rollup/plugin-node-resolve'; -import replace from '@rollup/plugin-replace'; -import copy from 'rollup-plugin-copy'; -import css from 'rollup-plugin-import-css'; -import typescript from 'rollup-plugin-typescript2'; -import vue from 'rollup-plugin-vue'; - -/** - * @type {import('rollup').RollupOptions} - */ -const config = { - input: 'dev/serve.ts', - output: { - file: 'example/dist/bundle.js', - format: 'iife', - sourcemap: true, - }, - plugins: [ - replace({ - 'process.env.NODE_ENV': JSON.stringify('production'), - preventAssignment: true, // recommended to be set by library to be forward compatible - }), - vue(), - nodeResolve({ browser: true }), - // Transform mixed because some JsonForms modules use import and require - commonjs({ transformMixedEsModules: true }), - css({ - output: 'bundle.css', - }), - json(), - typescript({ - tsconfigOverride: { - include: null, - compilerOptions: { - // Do not emit typescript declarations for our bundled example app - declaration: false, - }, - }, - }), - copy({ - targets: [ - { - src: 'example/index.bundled.html', - dest: 'example/dist', - rename: () => 'index.html', - }, - ], - }), - ], -}; - -export default config; diff --git a/packages/vue-vanilla/shims-vue.d.ts b/packages/vue-vanilla/shims-vue.d.ts deleted file mode 100644 index 907465b245..0000000000 --- a/packages/vue-vanilla/shims-vue.d.ts +++ /dev/null @@ -1,7 +0,0 @@ -declare module '*.vue' { - import type { DefineComponent } from 'vue'; - const component: DefineComponent<{}, {}, any>; - export default component; - - export const entry; -} diff --git a/packages/vue-vanilla/src/array/ArrayListElement.vue b/packages/vue-vanilla/src/array/ArrayListElement.vue deleted file mode 100644 index 01df843f55..0000000000 --- a/packages/vue-vanilla/src/array/ArrayListElement.vue +++ /dev/null @@ -1,125 +0,0 @@ - - - diff --git a/packages/vue-vanilla/src/array/ArrayListRenderer.vue b/packages/vue-vanilla/src/array/ArrayListRenderer.vue deleted file mode 100644 index b54376e682..0000000000 --- a/packages/vue-vanilla/src/array/ArrayListRenderer.vue +++ /dev/null @@ -1,141 +0,0 @@ - - - diff --git a/packages/vue-vanilla/src/array/index.ts b/packages/vue-vanilla/src/array/index.ts deleted file mode 100644 index 83d9c90291..0000000000 --- a/packages/vue-vanilla/src/array/index.ts +++ /dev/null @@ -1,5 +0,0 @@ -export { default as ArrayListRenderer } from './ArrayListRenderer.vue'; - -import { entry as arrayListRendererEntry } from './ArrayListRenderer.vue'; - -export const arrayRenderers = [arrayListRendererEntry]; diff --git a/packages/vue-vanilla/src/complex/EnumArrayRenderer.vue b/packages/vue-vanilla/src/complex/EnumArrayRenderer.vue deleted file mode 100644 index a0e0edcad8..0000000000 --- a/packages/vue-vanilla/src/complex/EnumArrayRenderer.vue +++ /dev/null @@ -1,95 +0,0 @@ - - - \ No newline at end of file diff --git a/packages/vue-vanilla/src/complex/ObjectRenderer.vue b/packages/vue-vanilla/src/complex/ObjectRenderer.vue deleted file mode 100644 index 7843f03fc0..0000000000 --- a/packages/vue-vanilla/src/complex/ObjectRenderer.vue +++ /dev/null @@ -1,89 +0,0 @@ - - - diff --git a/packages/vue-vanilla/src/complex/OneOfRenderer.vue b/packages/vue-vanilla/src/complex/OneOfRenderer.vue deleted file mode 100644 index b676662bb9..0000000000 --- a/packages/vue-vanilla/src/complex/OneOfRenderer.vue +++ /dev/null @@ -1,211 +0,0 @@ - - - diff --git a/packages/vue-vanilla/src/complex/components/CombinatorProperties.vue b/packages/vue-vanilla/src/complex/components/CombinatorProperties.vue deleted file mode 100644 index 39849b724e..0000000000 --- a/packages/vue-vanilla/src/complex/components/CombinatorProperties.vue +++ /dev/null @@ -1,74 +0,0 @@ - - - diff --git a/packages/vue-vanilla/src/complex/index.ts b/packages/vue-vanilla/src/complex/index.ts deleted file mode 100644 index 418e816cb9..0000000000 --- a/packages/vue-vanilla/src/complex/index.ts +++ /dev/null @@ -1,13 +0,0 @@ -export { default as ObjectRenderer } from './ObjectRenderer.vue'; -export { default as OneOfRenderer } from './OneOfRenderer.vue'; -export { default as EnumArrayRenderer } from './EnumArrayRenderer.vue'; - -import { entry as objectRendererEntry } from './ObjectRenderer.vue'; -import { entry as oneOfRendererEntry } from './OneOfRenderer.vue'; -import { entry as enumArrayRendererEntry } from './EnumArrayRenderer.vue'; - -export const complexRenderers = [ - objectRendererEntry, - oneOfRendererEntry, - enumArrayRendererEntry, -]; diff --git a/packages/vue-vanilla/src/controls/BooleanControlRenderer.vue b/packages/vue-vanilla/src/controls/BooleanControlRenderer.vue deleted file mode 100644 index d8332eb821..0000000000 --- a/packages/vue-vanilla/src/controls/BooleanControlRenderer.vue +++ /dev/null @@ -1,61 +0,0 @@ - - - diff --git a/packages/vue-vanilla/src/controls/ControlWrapper.vue b/packages/vue-vanilla/src/controls/ControlWrapper.vue deleted file mode 100644 index 7b28f06514..0000000000 --- a/packages/vue-vanilla/src/controls/ControlWrapper.vue +++ /dev/null @@ -1,86 +0,0 @@ - - - diff --git a/packages/vue-vanilla/src/controls/DateControlRenderer.vue b/packages/vue-vanilla/src/controls/DateControlRenderer.vue deleted file mode 100644 index 14ef0e8fff..0000000000 --- a/packages/vue-vanilla/src/controls/DateControlRenderer.vue +++ /dev/null @@ -1,61 +0,0 @@ - - - diff --git a/packages/vue-vanilla/src/controls/DateTimeControlRenderer.vue b/packages/vue-vanilla/src/controls/DateTimeControlRenderer.vue deleted file mode 100644 index 39b0400b04..0000000000 --- a/packages/vue-vanilla/src/controls/DateTimeControlRenderer.vue +++ /dev/null @@ -1,69 +0,0 @@ - - - diff --git a/packages/vue-vanilla/src/controls/EnumControlRenderer.vue b/packages/vue-vanilla/src/controls/EnumControlRenderer.vue deleted file mode 100644 index e2bf0ce6c2..0000000000 --- a/packages/vue-vanilla/src/controls/EnumControlRenderer.vue +++ /dev/null @@ -1,67 +0,0 @@ - - - diff --git a/packages/vue-vanilla/src/controls/EnumOneOfControlRenderer.vue b/packages/vue-vanilla/src/controls/EnumOneOfControlRenderer.vue deleted file mode 100644 index 0b520279d9..0000000000 --- a/packages/vue-vanilla/src/controls/EnumOneOfControlRenderer.vue +++ /dev/null @@ -1,67 +0,0 @@ - - - diff --git a/packages/vue-vanilla/src/controls/IntegerControlRenderer.vue b/packages/vue-vanilla/src/controls/IntegerControlRenderer.vue deleted file mode 100644 index 0e0654c5d5..0000000000 --- a/packages/vue-vanilla/src/controls/IntegerControlRenderer.vue +++ /dev/null @@ -1,61 +0,0 @@ - - - diff --git a/packages/vue-vanilla/src/controls/MultiStringControlRenderer.vue b/packages/vue-vanilla/src/controls/MultiStringControlRenderer.vue deleted file mode 100644 index 0d1b80e367..0000000000 --- a/packages/vue-vanilla/src/controls/MultiStringControlRenderer.vue +++ /dev/null @@ -1,62 +0,0 @@ -