You're Invited: Meet the Socket team at BSidesSF and RSAC - April 27 - May 1.RSVP
Socket
Sign inDemoInstall
Socket

@api-components/api-form-mixin

Package Overview
Dependencies
Maintainers
3
Versions
14
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@api-components/api-form-mixin - npm Package Compare versions

Comparing version

to
3.1.0

index.d.ts

15

api-form-mixin.d.ts

@@ -1,14 +0,1 @@

/**
* DO NOT EDIT
*
* This file was automatically generated by
* https://github.com/Polymer/tools/tree/master/packages/gen-typescript-declarations
*
* To modify these typings, edit the source file(s):
* api-form-mixin.js
*/
// tslint:disable:variable-name Describing an API that's defined elsewhere.
export {ApiFormMixin};
export {ApiFormMixin} from './src/ApiFormMixin';

@@ -1,362 +0,2 @@

/**
@license
Copyright 2018 The Advanced REST client authors <arc@mulesoft.com>
Licensed under the Apache License, Version 2.0 (the "License"); you may not
use this file except in compliance with the License. You may obtain a copy of
the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
License for the specific language governing permissions and limitations under
the License.
*/
/**
* A behavior to be implemented to elements that processes AMF data via form
* data model and displays forms from the model.
*
* It contains common methods used in forms.
*
* Use `api-form-styles` from this package to include common styles.
*
* @mixinFunction
* @param {Class} base
* @return {Class}
*/
export const ApiFormMixin = (base) => class extends base {
static get properties() {
return {
/**
* View model to use to render the form.
*/
model: { type: Array },
/**
* Set to true to show optional parameters (not required by the API).
*/
optionalOpened: {
type: Boolean,
reflect: true
},
/**
* Computed value from `allowHideOptional` and view model.
* `true` if current model has any optional property.
*/
hasOptional: { type: Boolean },
/**
* If set it computes `hasOptional` property and shows checkbox in the
* form to show / hide optional properties.
*/
allowHideOptional: { type: Boolean },
/**
* Computed flag to determine if optional checkbox can be rendered
*/
renderOptionalCheckbox: { type: Boolean },
/**
* If set, enable / disable param checkbox is rendered next to each
* form item.
*/
allowDisableParams: { type: Boolean },
/**
* When set, renders "add custom" item button.
* If the element is to be used withouth AMF model this should always
* be enabled. Otherwise users won't be able to add a parameter.
*/
allowCustom: { type: Boolean },
/**
* Renders items in "narrow" view
*/
narrow: { type: Boolean },
/**
* Computed value. The form renders empty message (if supported by
* the form element). It occurs when model is not set and allowCustom
* is not set
*/
renderEmptyMessage: { type: Boolean }
};
}
get model() {
return this._model;
}
set model(value) {
if (this._sop('model', value)) {
this._notifyChanged('model', value);
this.renderEmptyMessage = this._computeRenderEmptyMessage(this.allowCustom, value);
this.hasOptional = this._computeHasOptionalParameters(this.allowHideOptional, value);
}
}
get allowCustom() {
return this._allowCustom;
}
set allowCustom(value) {
if (this._sop('allowCustom', value)) {
this.renderEmptyMessage = this._computeRenderEmptyMessage(value, this.model);
}
}
get allowHideOptional() {
return this._allowHideOptional;
}
set allowHideOptional(value) {
if (this._sop('allowHideOptional', value)) {
this.hasOptional = this._computeHasOptionalParameters(value, this.model);
this.renderOptionalCheckbox = this._computeRenderCheckbox(value, this.hasOptional);
}
}
get hasOptional() {
return this._hasOptional;
}
set hasOptional(value) {
if (this._sop('hasOptional', value)) {
this._notifyChanged('hasOptional', value);
this.renderOptionalCheckbox = this._computeRenderCheckbox(this.allowHideOptional, value);
}
}
constructor() {
super();
this.renderEmptyMessage = true;
}
_sop(prop, value) {
const key = `_${prop}`;
const old = this[key];
if (old === value) {
return false;
}
this[key] = value;
if (this.requestUpdate) {
this.requestUpdate(prop, old);
}
return true;
}
_notifyChanged(prop, value) {
this.dispatchEvent(new CustomEvent(prop + '-changed', {
composed: true,
detail: {
value
}
}));
}
/**
* Computes class name for each form item depending on the item state.
*
* @param {Object} item Model item
* @param {Boolean} allowHideOptional
* @param {Boolean} optionalOpened True if optional parameters are rendered.
* @param {Boolean} allowDisableParams
* @return {String}
*/
computeFormRowClass(item, allowHideOptional, optionalOpened, allowDisableParams) {
let clazz = 'param-value';
if (item && item.required) {
clazz += ' required';
} else if (allowHideOptional) {
clazz += ' optional';
}
if (optionalOpened) {
clazz += ' with-optional';
}
if (allowDisableParams) {
clazz += ' has-enable-button';
}
return clazz;
}
/**
* Toggles visibility of optional parameters.
*/
toggleOptionalParams() {
if (!this.allowHideOptional) {
return;
}
this.optionalOpened = !this.optionalOpened;
}
/**
* Returns a reference to the form element, if the DOM is ready.
* This only works with `iron-form` that is in the DOM.
*
* @return {IronForm} Iron form element. It may be `undefined` if local
* DOM is not yet initialized.
*/
_getForm() {
if (!this.__form && this.shadowRoot) {
this.__form = this.shadowRoot.querySelector('iron-form');
}
return this.__form;
}
/**
* Validates the form. It uses `iron-form`'s `validate()` function to
* perform the validation.
* @return {Boolean} Validation result or `true` if DOM is not yet ready.
*/
_getValidity() {
const form = this._getForm();
if (!form) {
return true;
}
return form.validate();
}
/**
* Link to the form's serialize function.
* @return {Object} Serialized form values or `undefined` if DOM is not ready.
* Note, `undefined` is returned **only** if DOM is not yet ready.
*/
serializeForm() {
const form = this._getForm();
if (!form) {
return;
}
return form.serializeForm();
}
/**
* Computes if any of the parameters are required.
* It iterates over the model to find any first element that has `required`
* propeerty set to `false`.
*
* @param {Boolean} allowHideOptional State of `allowHideOptional` property.
* If `false` this function always returns `false`.
* @param {Object} model Current model
* @return {Boolean} `true` if model has at leas one alement that is not required.
*/
_computeHasOptionalParameters(allowHideOptional, model) {
if (!allowHideOptional || !model) {
return false;
}
return model.some((item) => item.required === false);
}
/**
* Computes value for `renderOptionalCheckbox` property.
*
* @param {Boolean} render Value of `allowHideOptional` property
* @param {Boolean} has Value of `hasOptional` property.
* @return {Boolean} True if both values are `true`.
*/
_computeRenderCheckbox(render, has) {
return render && has;
}
/**
* Computes if given model item is a custom property (not generated by
* AMF model transformation).
* @param {Object} model Model item.
* @return {Boolean} `true` if `isCustom` property is set on model's schema
* property.
*/
_computeIsCustom(model) {
if (!model || !model.schema || !model.schema.isCustom) {
return false;
}
return true;
}
/**
* Adds empty custom property to the list.
*
* It dispatches `api-property-model-build` custom event that is handled by
* `api-view-model-transformer` to build model item.
* This assumem that the transformer element is already in the DOM.
*
* After the transformation the element pushes or sets the data to the
* `model`.
*
* @param {String} binding Value if the `binding` property.
* @param {Object} opts Additional options:
* - inputLabel {String} - Forces a label of the input
*/
addCustom(binding, opts) {
if (!opts) {
opts = {};
}
const e = new CustomEvent('api-property-model-build', {
bubbles: true,
composed: true,
cancelable: true,
detail: {
name: opts.name || '',
value: opts.value || '',
binding: binding,
schema: {
enabled: true,
isCustom: true,
inputLabel: opts.inputLabel || undefined
}
}
});
this.dispatchEvent(e);
const model = this.model || [];
this.model = [...model, e.detail];
this.optionalOpened = true;
}
/**
* Removes custom item from the UI.
* This can only be called from `dom-repeat` element so it contain's
* `model` property.
*
* @param {CustomEvent} e
*/
_removeCustom(e) {
const index = Number(e.currentTarget.dataset.index);
if (index !== index) {
return;
}
const model = this.model;
if (!model || !model.length) {
return;
}
model.splice(index, 1);
this.model = Array.from(model);
}
/**
* Computes if model item is optional.
* The items is always optional if is not required and when `hasOptional`
* is set to `true`.
*
* @param {Boolean} hasOptional [description]
* @param {Object} model Model item.
* @return {Boolean} `true` if the model item is optional in the form.
*/
computeIsOptional(hasOptional, model) {
if (!hasOptional) {
return false;
}
if (!model || !model.required) {
return true;
}
return false;
}
/**
* Computes value for `renderEmptyMessage`.
*
* @param {Boolean} allowCustom True if the form allows to add custom values.
* @param {?Array} model Current model
* @return {Boolean} `true` when allowCustom is falsy set and model is empty
*/
_computeRenderEmptyMessage(allowCustom, model) {
return !allowCustom && !model;
}
/**
* Dispatches `send-analytics` for GA event.
* @param {String} category
* @param {String} action
* @param {String=} label
*/
_gaEvent(category, action, label) {
const e = new CustomEvent('send-analytics', {
bubbles: true,
composed: true,
detail: {
type: 'event',
category,
action,
label,
}
});
this.dispatchEvent(e);
}
};
// Left for compatibility
export { ApiFormMixin } from './src/ApiFormMixin.js';

@@ -1,14 +0,2 @@

/**
* DO NOT EDIT
*
* This file was automatically generated by
* https://github.com/Polymer/tools/tree/master/packages/gen-typescript-declarations
*
* To modify these typings, edit the source file(s):
* api-form-styles.js
*/
// tslint:disable:variable-name Describing an API that's defined elsewhere.
import {css} from 'lit-element';
import styles from './src/ApiFormStyles';
export default styles;

@@ -1,69 +0,3 @@

import { css } from 'lit-element';
/**
Common styles for API forms.
Custom property | Description | Default
----------------|-------------|----------
`--api-form-action-button-color` | Color of the action button in the form. Action buttons should perform form's primary actions like "submit" or "add new". Use `--api-form-action-icon-*` for icons related styling | `--secondary-button-color` or `--accent-color`
`--api-form-action-button-background-color` | Similar to `--api-form-action-button-color` but it's background color | `--secondary-button-background`
`--api-form-action-button-hover-color` | Color of the action button in the form when hovering. | `--secondary-button-color` or `--accent-color`
`--api-form-action-button-hover-background-color` | Similar to `--api-form-action-button-hover-color` but it's background color | `--secondary-button-background`
`--hint-trigger-color` | Color of the form action icon button to dispay documentation for the item. | `rgba(0, 0, 0, 0.74)`
`--hint-trigger-hover-color` | Color of the form action icon button to dispay documentation for the item when hovered | `rgba(0, 0, 0, 0.74)`
`--api-form-action-icon-color` | Color of any other than documentation icon button in form row | `--icon-button-color` or `rgba(0, 0, 0, 0.74)`
`--api-form-action-icon-hover-color` | Color of any other than documentation icon button in form row when hovering | `--accent-color` or `rgba(0, 0, 0, 0.88)`
`--inline-documentation-background-color` | Background color of the documentation element. | `#FFF3E0`
`--inline-documentation-color` | Color of the documentation element | `rgba(0, 0, 0, 0.87)`
`--inline-documentation-font-size` | Font size of the documentaiton element | `13px`
*/
export default css`
.form-item {
display: flex;
flex-direction: row;
align-items: center;
}
:host([narrow]) .form-item,
.narrow .form-item {
display: block;
}
.form-item[data-optional] {
display: none;
}
:host([optionalopened]) [data-optional] {
display: flex;
flex-direction: row;
}
/* styling form inline markdown */
arc-marked {
background-color: var(--inline-documentation-background-color, #FFF3E0);
padding: 4px;
/* Default inputs margin */
margin: 0 8px;
}
/* wrapped for arc-marked */
.docs {
font-size: var(--arc-font-body1-font-size);
font-weight: var(--arc-font-body1-font-weight);
line-height: var(--arc-font-body1-line-height);
color: var(--inline-documentation-color, rgba(0, 0, 0, 0.87));
margin-right: 40px;
}
.markdown-body * {
font-size: var(--inline-documentation-font-size, 13px) !important;
}
.markdown-body p:first-child {
margin-top: 0;
padding-top: 0;
}
.markdown-body p:last-child {
margin-bottom: 0;
padding-bottom: 0;
}`;
// Left for compatibility
import styles from './src/ApiFormStyles.js';
export default styles;

@@ -178,1 +178,66 @@ <a name="2.0.1"></a>

<a name="3.1.0"></a>
## [3.1.0](https://github.com/advanced-rest-client/api-form-mixin/compare/3.0.3...3.1.0) (2020-04-25)
### Build
* bumping version [3fc624a](https://github.com/advanced-rest-client/api-form-mixin/commit/3fc624a6e4e28e91a7268519ac779e3f177e32f3) by Pawel
* bump version [9409b72](https://github.com/advanced-rest-client/api-form-mixin/commit/9409b724cd7521b981db9d28f755fddae50b2a7c) by Pawel Psztyc
* bumping version [3e7f6ca](https://github.com/advanced-rest-client/api-form-mixin/commit/3e7f6ca3c0b5da9d0aff3d0e9e7a06f1925e0681) by Pawel
* bumping version [35d1ac2](https://github.com/advanced-rest-client/api-form-mixin/commit/35d1ac2c9a246ebc999dda3bd826ca5459759d97) by Pawel
### Update
* updating mixin's type [1b822b5](https://github.com/advanced-rest-client/api-form-mixin/commit/1b822b5a71585f88b3ebee7a93824aa61ce0d438) by Pawel
* adding manually defined types [fae6ac4](https://github.com/advanced-rest-client/api-form-mixin/commit/fae6ac463dc11aad8e6837536618fb947eb81a44) by Pawel
* adding `ApiViewModel` class support [cfb7556](https://github.com/advanced-rest-client/api-form-mixin/commit/cfb7556629be255051d1f4421bf916392bce0716) by Pawel
* bulk upgrade to latest ARC standards [2c7ac70](https://github.com/advanced-rest-client/api-form-mixin/commit/2c7ac70162c8c6c023334b33be196465ead61fa9) by Pawel
* upgrading dependnecies [999c0d8](https://github.com/advanced-rest-client/api-form-mixin/commit/999c0d86cb3f9724fee2cc6c88c4a6b4162bd5d9) by Pawel Psztyc
* upgrading dependencies to fix audit errors [22e2f40](https://github.com/advanced-rest-client/api-form-mixin/commit/22e2f402df548804f111ebe901d454e3d8d723fa) by Pawel Psztyc
### Features
* adding GA event dispatch [c9321f1](https://github.com/advanced-rest-client/api-form-mixin/commit/c9321f1461335a8ce19fa674ad9b4359424d90f8) by Pawel Psztyc
### Bug Fixes
* fixes styles export [6a78dba](https://github.com/advanced-rest-client/api-form-mixin/commit/6a78dba946a80f6d2389e3bf14c3b8ea51c5bbf6) by Pawel
* fixing optional CSS attribute name after the change [ddbb196](https://github.com/advanced-rest-client/api-form-mixin/commit/ddbb196affd21e067ed53df25d6ead21ca50bbf0) by Pawel
* fixing delete button index selection [9e55c64](https://github.com/advanced-rest-client/api-form-mixin/commit/9e55c64a2e73a403d6f5a45fb53077db318a7bbb) by Pawel
### Refactor
* moving sources to src/ folder [93da83f](https://github.com/advanced-rest-client/api-form-mixin/commit/93da83f181418a99ad4c8468707bd31c621726f1) by Pawel
* removing button/icon button classes [05cf5e9](https://github.com/advanced-rest-client/api-form-mixin/commit/05cf5e9d7239ad158de6071418ef02c9e556553b) by Pawel
* upgrading component to latest ARC standard [82db694](https://github.com/advanced-rest-client/api-form-mixin/commit/82db694419d38a228cff26d2b1b97d3a2da32a52) by Pawel
### Testing
* updating SL config file [bb09fbb](https://github.com/advanced-rest-client/api-form-mixin/commit/bb09fbba414262b346952752ddc9d8b51c9ec8ce) by Pawel Psztyc
* updating test commands [6d25c8f](https://github.com/advanced-rest-client/api-form-mixin/commit/6d25c8f3d2735173ad385b34aa5987a41af0c37e) by Pawel Psztyc
* removing old test [1ebc353](https://github.com/advanced-rest-client/api-form-mixin/commit/1ebc353e0868ca54ad95d2aa63e3526da3ebf03a) by Pawel Psztyc
### Other
* Breaking: Upgradig component to LitElement and new test framework
[0d956ed](https://github.com/advanced-rest-client/api-form-mixin/commit/0d956ed47fd9c888b3280aa1ddde5caf4f82ba11) by Pawel Psztyc
* Update: Updating import paths to match web spec
[58f3512](https://github.com/advanced-rest-client/api-form-mixin/commit/58f35122d1a64e0052f01db440301d0320283d26) by Pawel Psztyc
* New: Adding NPM ignore file
[107c486](https://github.com/advanced-rest-client/api-form-mixin/commit/107c4862c4f66ebef2761f8ffabedcf8067fccde) by Pawel Psztyc
* Docs: Updating Polymer docs and typpings
[754d079](https://github.com/advanced-rest-client/api-form-mixin/commit/754d079e2e8a4762d6271aad3cae16a24a39e25f) by Pawel Psztyc
* Breaking: Upgrading component to Polymer 3
[26d69cf](https://github.com/advanced-rest-client/api-form-mixin/commit/26d69cfe2ab9f5ab8dfa8b1d8bfeb76ee8d0647c) by Pawel Psztyc
* Docs: Updating documentation
[e30df73](https://github.com/advanced-rest-client/api-form-mixin/commit/e30df73834403aca732f967874960d0bd7495249) by Paweł Psztyć
* Update: Added sauce configuration for tests
[637e0f5](https://github.com/advanced-rest-client/api-form-mixin/commit/637e0f5f7f08e1164d66001743617c3893c4e4e8) by Pawel Psztyc
{
"name": "@api-components/api-form-mixin",
"description": "A mixin that contains common properties, methods and styles for components that implements AMF based forms",
"version": "3.0.4",
"version": "3.1.0",
"license": "Apache-2.0",

@@ -31,24 +31,25 @@ "main": "api-form-mixin.js",

"dependencies": {
"lit-element": "^2.2.1"
"@api-components/api-view-model-transformer": "^4.1.1",
"lit-element": "^2.3.1"
},
"devDependencies": {
"@advanced-rest-client/eslint-config": "^1.1.4",
"@advanced-rest-client/eslint-config": "^1.1.5",
"@advanced-rest-client/prettier-config": "^0.1.0",
"@advanced-rest-client/testing-karma-sl": "^1.1.0",
"@commitlint/cli": "^8.2.0",
"@commitlint/config-conventional": "^7.0.0",
"@open-wc/testing": "^2.4.2",
"@open-wc/testing-karma": "^3.2.14",
"@polymer/gen-typescript-declarations": "^1.6.2",
"@advanced-rest-client/testing-karma-sl": "^1.2.0",
"@commitlint/cli": "^8.3.5",
"@commitlint/config-conventional": "^8.3.4",
"@open-wc/testing": "^2.5.13",
"@open-wc/testing-karma": "^3.3.15",
"@polymer/iron-form": "^3.0.0",
"deepmerge": "^4.2.2",
"es-dev-server": "^1.30.0",
"husky": "^1.0.0",
"karma": "^4.4.1",
"lint-staged": "^9.5.0",
"sinon": "^7.5.0"
"es-dev-server": "^1.46.5",
"husky": "^4.2.5",
"lint-staged": "^10.1.7",
"sinon": "^9.0.2",
"typescript": "^3.8.3",
"typescript-lit-html-plugin": "^0.9.0"
},
"scripts": {
"test": "karma start --coverage",
"update-types": "gen-typescript-declarations --deleteExisting --outDir .",
"update-types": "echo \"please, edit types declarations manually\"",
"start": "es-dev-server --app-index demo/index.html --node-resolve --open --watch",

@@ -61,6 +62,5 @@ "start:compatibility": "es-dev-server --app-index demo/index.html --compatibility auto --node-resolve --open --watch",

"lint": "npm run lint:eslint && npm run lint:prettier",
"lint:types": "tsc",
"format": "npm run format:eslint && npm run format:prettier",
"test:watch": "karma start --auto-watch=true --single-run=false",
"test:legacy": "karma start --compatibility auto --coverage",
"test:legacy:watch": "karma start --compatibility auto --auto-watch=true --single-run=false",
"test:sl": "karma start karma.sl.config.js --compatibility auto --coverage",

@@ -71,6 +71,5 @@ "generate-model": "node demo/model.js"

"*.js": [
"eslint --fix",
"git add"
"eslint --fix"
]
}
}

@@ -1,4 +0,4 @@

[![Build Status](https://travis-ci.org/advanced-rest-client/api-form-mixin.svg?branch=stage)](https://travis-ci.org/advanced-rest-client/api-form-mixin)
[![Published on NPM](https://img.shields.io/npm/v/@api-components/api-form-mixin.svg)](https://www.npmjs.com/package/@api-components/api-form-mixin)
[![Published on webcomponents.org](https://img.shields.io/badge/webcomponents.org-published-blue.svg)](https://www.webcomponents.org/element/advanced-rest-client/api-form-mixin)
[![Build Status](https://travis-ci.com/advanced-rest-client/api-form-mixin.svg)](https://travis-ci.org/advanced-rest-client/api-form-mixin)

@@ -11,6 +11,2 @@ ## &lt;api-form-mixin&gt;

### API components
This components is a part of [API components ecosystem](https://elements.advancedrestclient.com/)
## Usage

@@ -31,3 +27,3 @@

class SampleElement extends PolymerElement {
class SampleElement extends LitElement {
static get styles() {

@@ -75,3 +71,3 @@ return [

### Installation
## Development

@@ -78,0 +74,0 @@ ```sh