Skip to content
This repository has been archived by the owner on May 3, 2022. It is now read-only.

Commit

Permalink
chore: adding manually defined types
Browse files Browse the repository at this point in the history
  • Loading branch information
jarrodek committed Apr 25, 2020
1 parent 93da83f commit fae6ac4
Show file tree
Hide file tree
Showing 9 changed files with 214 additions and 54 deletions.
15 changes: 1 addition & 14 deletions api-form-mixin.d.ts
Original file line number Diff line number Diff line change
@@ -1,14 +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';
16 changes: 2 additions & 14 deletions api-form-styles.d.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,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;
13 changes: 0 additions & 13 deletions gen-tsd.json

This file was deleted.

14 changes: 14 additions & 0 deletions index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
/**
* 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):
* index.js
*/


// tslint:disable:variable-name Describing an API that's defined elsewhere.

export {ApiFormMixin} from './src/ApiFormMixin.js';
6 changes: 3 additions & 3 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 2 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
"email": "[email protected]"
},
"dependencies": {
"@api-components/api-view-model-transformer": "^4.1.0",
"@api-components/api-view-model-transformer": "^4.1.1",
"lit-element": "^2.3.1"
},
"devDependencies": {
Expand All @@ -39,7 +39,6 @@
"@commitlint/config-conventional": "^8.3.4",
"@open-wc/testing": "^2.5.13",
"@open-wc/testing-karma": "^3.3.15",
"@polymer/gen-typescript-declarations": "^1.6.2",
"@polymer/iron-form": "^3.0.0",
"deepmerge": "^4.2.2",
"es-dev-server": "^1.46.5",
Expand All @@ -51,7 +50,7 @@
},
"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",
"start:compatibility": "es-dev-server --app-index demo/index.html --compatibility auto --node-resolve --open --watch",
"lint:eslint": "eslint --ext .js,.html .",
Expand Down
180 changes: 180 additions & 0 deletions src/ApiFormMixin.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,180 @@
import {ModelItem} from '@api-components/api-view-model-transformer/src/ApiViewModel';
import {IronFormElement} from '@polymer/iron-form';

export {ApiFormMixin};

/**
* A mixin 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.
*/
interface ApiFormMixin {
/**
* View model to use to render the form.
*/
model: ModelItem[];
/**
* Set to true to show optional parameters (not required by the API).
*/
optionalOpened: boolean;
/**
* Computed value from `allowHideOptional` and view model.
* `true` if current model has any optional property.
*/
hasOptional: boolean;
/**
* If set it computes `hasOptional` property and shows checkbox in the
* form to show / hide optional properties.
*/
allowHideOptional: boolean;
/**
* Computed flag to determine if optional checkbox can be rendered
*/
renderOptionalCheckbox: boolean;
/**
* If set, enable / disable param checkbox is rendered next to each
* form item.
*/
allowDisableParams: 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: boolean;
/**
* Renders items in "narrow" view
*/
narrow: 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: boolean;

_sop(prop: string, value: any): boolean;

_notifyChanged(prop: string, value: any): void;

/**
* Computes class name for each form item depending on the item state.
*
* @param item Model item
* @param allowHideOptional
* @param optionalOpened True if optional parameters are rendered.
* @param allowDisableParams
*/
computeFormRowClass(item: ModelItem, allowHideOptional?: boolean, optionalOpened?: boolean, allowDisableParams?: boolean): string;

/**
* Toggles visibility of optional parameters.
*/
toggleOptionalParams(): void;

/**
* Returns a reference to the form element, if the DOM is ready.
* This only works with `iron-form` that is in the DOM.
*
* @returns Iron form element. It may be `undefined` if local
* DOM is not yet initialized.
*/
_getForm(): IronFormElement;

/**
* Validates the form. It uses `iron-form`'s `validate()` function to
* perform the validation.
* @returns Validation result or `true` if DOM is not yet ready.
*/
_getValidity(): boolean;

/**
* Link to the form's serialize function.
* @returns Serialized form values or `undefined` if DOM is not ready.
* Note, `undefined` is returned **only** if DOM is not yet ready.
*/
serializeForm(): object;

/**
* 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 allowHideOptional State of `allowHideOptional` property.
* If `false` this function always returns `false`.
* @param model Current model
* @returns `true` if model has at leas one alement that is not required.
*/
_computeHasOptionalParameters(allowHideOptional: boolean, model: ModelItem): boolean;

/**
* Computes value for `renderOptionalCheckbox` property.
*
* @param render Value of `allowHideOptional` property
* @param has Value of `hasOptional` property.
* @returns True if both values are `true`.
*/
_computeRenderCheckbox(render: boolean, has: boolean): boolean;

/**
* Computes if given model item is a custom property (not generated by
* AMF model transformation).
* @param model Model item.
* @returns `true` if `isCustom` property is set on model's schema
* property.
*/
_computeIsCustom(model: ModelItem): boolean;

/**
* 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 binding Value if the `binding` property.
* @param opts Default options for the ModelItem. See `ApiViewModel`
* for the details.
*/
addCustom(binding: string, opts?: object): void;

/**
* Removes custom item from the UI.
* This can only be called from `dom-repeat` element so it contain's
* `model` property.
*/
_removeCustom(e: CustomEvent): void;

/**
* Computes if model item is optional.
* The items is always optional if is not required and when `hasOptional`
* is set to `true`.
*
* @param hasOptional [description]
* @param model Model item.
* @returns `true` if the model item is optional in the form.
*/
computeIsOptional(hasOptional: boolean, model: ModelItem): boolean;

/**
* Computes value for `renderEmptyMessage`.
*
* @param allowCustom True if the form allows to add custom values.
* @param model Current model
* @returns `true` when allowCustom is falsy set and model is empty
*/
_computeRenderEmptyMessage(allowCustom: boolean, model?: ModelItem): boolean;

/**
* Dispatches `send-analytics` for GA event.
*/
_gaEvent(category: string, action: string, label?: string): void;
}

declare const ApiFormMixin: object;
16 changes: 9 additions & 7 deletions src/ApiFormMixin.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import { ApiViewModel } from '@api-components/api-view-model-transformer';
/** @typedef {import('@polymer/iron-form').IronFormElement} IronFormElement */
/** @typedef {import('@api-components/api-view-model-transformer/src/ApiViewModel').ModelItem} ModelItem */

/**
@license
Copyright 2018 The Advanced REST client authors <[email protected]>
Expand Down Expand Up @@ -150,10 +152,10 @@ export const ApiFormMixin = (base) => class extends base {
/**
* 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
* @param {ModelItem} 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) {
Expand Down Expand Up @@ -225,7 +227,7 @@ export const ApiFormMixin = (base) => class extends base {
*
* @param {Boolean} allowHideOptional State of `allowHideOptional` property.
* If `false` this function always returns `false`.
* @param {Object} model Current model
* @param {ModelItem[]} model Current model
* @return {Boolean} `true` if model has at leas one alement that is not required.
*/
_computeHasOptionalParameters(allowHideOptional, model) {
Expand All @@ -247,7 +249,7 @@ export const ApiFormMixin = (base) => class extends base {
/**
* Computes if given model item is a custom property (not generated by
* AMF model transformation).
* @param {Object} model Model item.
* @param {ModelItem} model Model item.
* @return {Boolean} `true` if `isCustom` property is set on model's schema
* property.
*/
Expand Down Expand Up @@ -315,7 +317,7 @@ export const ApiFormMixin = (base) => class extends base {
* is set to `true`.
*
* @param {Boolean} hasOptional [description]
* @param {Object} model Model item.
* @param {ModelItem} model Model item.
* @return {Boolean} `true` if the model item is optional in the form.
*/
computeIsOptional(hasOptional, model) {
Expand Down
3 changes: 3 additions & 0 deletions src/ApiFormStyles.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import {CSSResult} from 'lit-element';
declare const styles: CSSResult;
export default styles;

0 comments on commit fae6ac4

Please sign in to comment.