Socket
Socket
Sign inDemoInstall

@neovici/cosmoz-datetime-input

Package Overview
Dependencies
Maintainers
4
Versions
7
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@neovici/cosmoz-datetime-input - npm Package Compare versions

Comparing version 3.1.0 to 3.2.0

339

cosmoz-datetime-input.js

@@ -1,237 +0,140 @@

import '@webcomponents/shadycss/entrypoints/apply-shim';
import { html, component, useEffect, useMemo } from 'haunted';
import { notifyProperty } from '@neovici/cosmoz-utils/hooks/use-notify-property';
import '@neovici/cosmoz-input';
import '@polymer/paper-input/paper-input-container';
/**
* The possible separators between date and time input values
*/
const separators = ['T', ' '];
import { PolymerElement } from '@polymer/polymer/polymer-element';
import { html } from '@polymer/polymer/lib/utils/html-tag';
/**
* Returns a [date, time] or [date] array via a dateTime string.
* @param {String} aDateTime - The datetime or date string.
* @return {undefined}
*/
const getDateTimeParts = (aDateTime) => {
if (!aDateTime) {
return;
}
let parts;
separators.some((split) => {
if (!aDateTime.match(split)) {
return false;
}
parts = aDateTime.split(split);
return true;
});
return parts || [aDateTime];
};
/**
* `cosmoz-datetime-input`
*
* Mimics `<input type="cosmoz-datetime-input">`
*
* @customElement
* @polymer
* @demo demo/index.html
* Gets the min/max-date/time properties via min/max-dateTime strings.
* @param {String} min - The min Date/DateTime.
* @param {String} max - the max Date/DateTime.
* @return {undefined}
*/
class CosmozDatetimeInput extends PolymerElement {
static get template() {
return html`
<style>
:host {
display: block;
}
.container {
display: -ms-flexbox;
display: -webkit-flex;
display: flex;
-ms-flex-direction: row;
-webkit-flex-direction: row;
flex-direction: row;
@apply --cosmoz-datetime-input-container;
}
input {
@apply --cosmoz-datetime-input-input;
}
label {
pointer-events: none;
@apply --cosmoz-datetime-input-label;
}
</style>
const getMinMax = (min, max) => {
const minParts = getDateTimeParts(min),
maxParts = getDateTimeParts(max);
<div class="container">
<paper-input-container always-float-label>
<label hidden$="[[ !dateLabel ]]" slot="label" aria-hidden="true" for="dateInput">[[ dateLabel ]]</label>
<input id="dateInput" type="date" slot="input" value="{{ date::input }}" min$="[[ _minDate ]]" max$="[[ _maxDate ]]">
</paper-input-container>
<paper-input-container always-float-label>
<label hidden$="[[ !timeLabel ]]" slot="label" aria-hidden="true" for="timeInput">[[ timeLabel ]]</label>
<input id="timeInput" type="time" slot="input" value="{{ time::input }}" step="[[ step ]]" min$="[[ _minTime ]]" max$="[[ _maxTime ]]">
</paper-input-container>
</div>
`;
}
return {
minDate: Array.isArray(minParts) ? minParts.shift() : null,
minTime: Array.isArray(minParts) ? minParts.shift() : null,
maxDate: Array.isArray(maxParts) ? maxParts.shift() : null,
maxTime: Array.isArray(maxParts) ? maxParts.shift() : null,
};
};
static get is() {
return 'cosmoz-datetime-input';
export const toValue = (date, time) => {
if (!date && !time) {
return;
}
/* eslint-disable-next-line max-lines-per-function */
static get properties() {
return {
/**
* The date part of the value
*/
date: {
type: String,
notify: true
},
/**
* The date part of the value
*/
time: {
type: String,
notify: true
},
/**
* The step of the time input
*/
step: {
type: String,
value: '1'
},
/**
* The date or datetime input value
*/
value: {
type: String,
notify: true,
observer: '_valueChanged'
},
/**
* The label of the time input
*/
timeLabel: {
type: String
},
/**
* The label of the date input
*/
dateLabel: {
type: String
},
/**
* The max date/datetime of the inputs
*/
max: {
type: String
},
/**
* The min date/datetime of the inputs
*/
min: {
type: String
},
_minDate: {
type: String
},
_maxDate: {
type: String
},
_minTime: {
type: String
},
_maxTime: {
type: String
},
/**
* The possible separators between date and time input values
*/
_separators: {
type: Array,
value() {
return ['T', ' '];
}
}
};
if (!date && time) {
return `T${time}`;
}
static get observers() {
return [
'_setValue(date, time)',
'_setMinMax(min, max)'
];
if (date && !time) {
return date;
}
return `${date}T${time}`;
};
/**
* Sets the value property via a date and time string.
* @param {String} date - The date string.
* @param {String} time - The time string.
* @return {undefined}
*/
_setValue(date, time) {
if (!date && !time) {
this.value = null;
return;
}
if (!date && time) {
this.value = `T${ time }`;
return;
}
if (date && !time) {
this.value = date;
return;
}
this.value = `${ date }T${ time }`;
export const fromValue = (value) => {
if (!value) {
return;
}
/**
* Sets the date and time property via a value string.
* @param {String} value - The input value. Either datetime or date string.
* @return {undefined}
*/
_valueChanged(value) {
if (!value) {
this.date = '';
this.time = '';
return;
for (const split of separators) {
if (value.match(split)) {
const parts = value.split(split);
return {
date: parts.shift(),
time: parts.shift(),
};
}
const isDatetime = this._separators.some(split => {
if (!value.match(split)) {
return false;
}
const parts = this._getDateTimeParts(value);
this.date = parts.shift();
this.time = parts.shift();
return true;
});
if (!isDatetime) {
this.date = value;
}
this.dispatchEvent(new CustomEvent('cosmoz-datetime-input-value-changed', {
bubbles: true,
composed: true
}));
}
return { date: value };
};
/**
* Returns a [date, time] or [date] array via a dateTime string.
* @param {String} aDateTime - The datetime or date string.
* @return {undefined}
*/
_getDateTimeParts(aDateTime) {
if (!aDateTime) {
return;
}
/**
* `cosmoz-datetime-input`
*
* Mimics `<input type="cosmoz-datetime-input">`
*
* @customElement
* @polymer
* @demo demo/index.html
*/
let parts;
const DateTimeInput = (host) => {
const { dateLabel, timeLabel, min, max, step = '1', value } = host;
const { minDate, maxDate, minTime, maxTime } = useMemo(
() => getMinMax(min, max),
[min, max],
);
const { date, time } = useMemo(() => fromValue(value) ?? {}, [value]);
useEffect(() => {
host.dispatchEvent(
new CustomEvent('cosmoz-datetime-input-value-changed', {
bubbles: true,
composed: true,
}),
);
}, [value]);
this._separators.some(split => {
if (!aDateTime.match(split)) {
return false;
return html`
<style>
:host {
display: flex;
flex-direction: row;
}
parts = aDateTime.split(split);
return true;
});
return parts || [aDateTime];
}
/**
* Sets the min/max-date/time properties via min/max-dateTime strings.
* @param {String} min - The min Date/DateTime.
* @param {String} max - the max Date/DateTime.
* @return {undefined}
*/
_setMinMax(min, max) {
const minParts = this._getDateTimeParts(min),
maxParts = this._getDateTimeParts(max);
this._minDate = Array.isArray(minParts) ? minParts.shift() : null;
this._minTime = Array.isArray(minParts) ? minParts.shift() : null;
this._maxDate = Array.isArray(maxParts) ? maxParts.shift() : null;
this._maxTime = Array.isArray(maxParts) ? maxParts.shift() : null;
}
}
customElements.define(CosmozDatetimeInput.is, CosmozDatetimeInput);
</style>
<cosmoz-input
label="${dateLabel}"
type="date"
.value="${date}"
@value-changed="${(e) =>
notifyProperty(host, 'value', toValue(e.target.value, time))}"
.min="${minDate}"
.max="${maxDate}"
></cosmoz-input>
<cosmoz-input
label="${timeLabel}"
type="time"
.value="${time}"
@value-changed="${(e) =>
notifyProperty(host, 'value', toValue(date, e.target.value))}"
step="${step}"
.min="${minTime}"
.max="${maxTime}"
></cosmoz-input>
`;
};
customElements.define(
'cosmoz-datetime-input',
component(DateTimeInput, {
observedAttributes: ['date-label', 'time-label', 'min', 'max', 'step'],
}),
);
{
"name": "@neovici/cosmoz-datetime-input",
"version": "3.1.0",
"description": "Mimics date input with broad browser support.",
"keywords": [
"datepicker",
"datetime local",
"polymer",
"web-components"
],
"repository": {
"type": "git",
"url": "git+https://github.com/Neovici/cosmoz-datetime-input.git"
},
"license": "Apache-2.0",
"author": "",
"main": "cosmoz-datetime-input.js",
"directories": {
"test": "test"
},
"files": [
"lib/",
"cosmoz-*.js"
],
"scripts": {
"lint": "eslint --cache --ext .js .",
"start": "es-dev-server",
"test": "karma start --coverage",
"test:watch": "karma start --auto-watch=true --single-run=false",
"test:update-snapshots": "karma start --update-snapshots",
"test:prune-snapshots": "karma start --prune-snapshots",
"test:compatibility": "karma start --compatibility all --auto-watch=true --single-run=false"
},
"release": {
"plugins": [
"@semantic-release/commit-analyzer",
"@semantic-release/release-notes-generator",
"@semantic-release/changelog",
"@semantic-release/github",
"@semantic-release/npm",
"@semantic-release/git"
],
"branch": "master",
"preset": "conventionalcommits"
},
"publishConfig": {
"access": "public"
},
"commitlint": {
"extends": [
"@commitlint/config-conventional"
]
},
"husky": {
"hooks": {
"commit-msg": "commitlint -E HUSKY_GIT_PARAMS"
}
},
"dependencies": {
"@polymer/paper-input": "^3.0.0",
"@polymer/polymer": "^3.0.0",
"@webcomponents/shadycss": "^1.9.1"
},
"devDependencies": {
"@commitlint/cli": "^18",
"@commitlint/config-conventional": "^18",
"@neovici/eslint-config": "^1.2.2",
"@open-wc/testing": "^2.5.16",
"@open-wc/testing-karma": "^3.3.28",
"@polymer/iron-component-page": "^4.0.0",
"@polymer/iron-demo-helpers": "^3.0.0",
"@semantic-release/changelog": "^6.0.0",
"@semantic-release/git": "^10.0.0",
"@webcomponents/webcomponentsjs": "^2.4.3",
"babel-eslint": "^10.1.0",
"chai": "^4.2.0",
"deepmerge": "^4.2.2",
"eslint": "^6.8.0",
"eslint-plugin-html": "^6.0.2",
"eslint-plugin-import": "^2.20.2",
"eslint-plugin-mocha": "^6.3.0",
"husky": "^8.0.3",
"karma": "^5.0.9",
"karma-firefox-launcher": "^1.3.0",
"karma-sauce-launcher": "^4.0.0",
"semantic-release": "^22",
"sinon": "^17"
}
"name": "@neovici/cosmoz-datetime-input",
"version": "3.2.0",
"description": "Mimics date input with broad browser support.",
"keywords": [
"datepicker",
"datetime local",
"polymer",
"web-components"
],
"repository": {
"type": "git",
"url": "git+https://github.com/Neovici/cosmoz-datetime-input.git"
},
"license": "Apache-2.0",
"author": "",
"main": "cosmoz-datetime-input.js",
"directories": {
"test": "test"
},
"files": [
"lib/",
"cosmoz-*.js"
],
"scripts": {
"lint": "eslint --cache .",
"start": "wds",
"test": "wtr --coverage",
"test:watch": "wtr --watch",
"prepare": "husky install",
"storybook:build": "build-storybook",
"storybook:deploy": "storybook-to-ghpages"
},
"release": {
"plugins": [
"@semantic-release/commit-analyzer",
"@semantic-release/release-notes-generator",
"@semantic-release/changelog",
"@semantic-release/github",
"@semantic-release/npm",
"@semantic-release/git"
],
"branch": "master",
"preset": "conventionalcommits"
},
"publishConfig": {
"access": "public"
},
"commitlint": {
"extends": [
"@commitlint/config-conventional"
]
},
"dependencies": {
"@neovici/cosmoz-input": "^3.16.0",
"@neovici/cosmoz-utils": "^5.39.0",
"haunted": "^5.0.0"
},
"devDependencies": {
"@commitlint/cli": "^18.0.0",
"@commitlint/config-conventional": "^18.0.0",
"@neovici/cfg": "^1.13.1",
"@open-wc/testing": "^3.0.0",
"@semantic-release/changelog": "^6.0.0",
"@semantic-release/git": "^10.0.0",
"@storybook/storybook-deployer": "^2.8.5",
"@types/mocha": "^10.0.3",
"@web/dev-server-storybook": "^1.0.0",
"husky": "^8.0.0",
"semantic-release": "^22.0.0",
"sinon": "^17.0.0"
}
}
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc