Best JavaScript code snippet using storybook-root
presetUtils.js
Source:presetUtils.js
1/*2// Copyright © 2014 - 2018 Esri. All rights reserved.3TRADE SECRETS: ESRI PROPRIETARY AND CONFIDENTIAL4Unpublished material - all rights reserved under the5Copyright Laws of the United States and applicable international6laws, treaties, and conventions.7For additional information, contact:8Attn: Contracts and Legal Department9Environmental Systems Research Institute, Inc.10380 New York Street11Redlands, California, 9237312USA13email: contracts@esri.com14*/15define([16 "dojo/_base/lang",17 "dojo/_base/array",18 'dojo/dom-construct',19 'dijit/form/DateTextBox',20 'dijit/form/NumberSpinner',21 'dijit/form/NumberTextBox',22 'dijit/form/FilteringSelect',23 'dijit/form/TextBox',24 'dijit/form/ValidationTextBox',25 'dijit/form/TimeTextBox',26 "dijit/Editor",27 "dijit/form/SimpleTextarea",28 'dojo/store/Memory'29],30 function (31 lang,32 array,33 domConstruct,34 DateTextBox,35 NumberSpinner,36 NumberTextBox,37 FilteringSelect,38 TextBox,39 ValidationTextBox,40 TimeTextBox,41 Editor,42 SimpleTextarea,43 Memory44 ) {45 var mo = {};46 mo.integerFields = [47 "esriFieldTypeSmallInteger",48 "esriFieldTypeInteger",49 "esriFieldTypeSingle",50 "esriFieldTypeDouble"];51 mo.getFieldInfoByFieldName = function (fieldInfos, fieldName) {52 var fieldInfo = {};53 array.some(fieldInfos, function (field) {54 if (field.name === fieldName) {55 lang.mixin(fieldInfo, field);56 return true;57 }58 });59 return fieldInfo;60 };61 mo.getDateFieldValue = function (field, dijit) {62 var newFieldVal;63 // Convert to epoch time if fieldType is date/time64 if (field.type === "esriFieldTypeDate") {65 if (dijit instanceof Array) {66 var dateObj, timeObj;67 // Get individual date & time values for sync68 if (dijit.length > 0 && dijit[0]) {69 dateObj = dijit[0].getValue();70 }71 if (dijit.length > 1 && dijit[1]) {72 timeObj = dijit[1].getValue();73 }74 if (dateObj && timeObj) {75 newFieldVal = new Date(76 dateObj.getFullYear(),77 dateObj.getMonth(),78 dateObj.getDate(),79 timeObj.getHours(),80 timeObj.getMinutes(),81 timeObj.getSeconds(),82 timeObj.getMilliseconds()83 );84 }85 else {86 newFieldVal = dateObj || timeObj || null;87 }88 }89 else {90 newFieldVal = dijit.getValue();91 if (field.domain) {92 newFieldVal = Number(newFieldVal);93 }94 }95 newFieldVal = (newFieldVal && newFieldVal.getTime) ?96 newFieldVal.getTime()97 : (newFieldVal && newFieldVal.toGregorian ? newFieldVal.toGregorian().getTime() : newFieldVal);98 }99 return newFieldVal;100 };101 mo.isGuid = function (value) {102 if (value[0] === "{") {103 value = value.substring(1, value.length - 1);104 }105 var regexGuid = /^(\{){0,1}[0-9a-fA-F]{8}\-[0-9a-fA-F]{4}\-[0-9a-fA-F]{4}\-[0-9a-fA-F]{4}\-[0-9a-fA-F]{12}(\}){0,1}$/gi;106 return regexGuid.test(value);107 };108 mo.validateGUID = function (value, constraints) {109 constraints = constraints;110 return this.isGuid(value);111 };112 mo.isValidPresetValue = function (nodes) {113 var isValid = true;114 array.some(nodes, function (node) {115 if (node.isValid && !node.isValid()) {116 isValid = false;117 return true;118 }119 });120 return isValid;121 };122 mo.createPresetFieldContentNode = function (fieldInfo) {123 var nodes = [];124 var node;125 if (fieldInfo.domain) {126 // domain.type = codedValue127 if (fieldInfo.domain.type === "codedValue") {128 var domainValues = fieldInfo.domain.codedValues;129 var options = [];130 array.forEach(domainValues, function (dv) {131 options.push({ name: dv.name, id: dv.code });132 });133 node = new FilteringSelect({134 "class": "ee-inputField",135 name: fieldInfo.fieldName,136 store: new Memory({ data: options }),137 searchAttr: "name"138 }, domConstruct.create("div"));139 } else { //domain.type = range140 var cons = null;141 switch (fieldInfo.type) {142 case "esriFieldTypeSmallInteger":143 case "esriFieldTypeInteger":144 cons = {145 min: fieldInfo.domain.minValue,146 max: fieldInfo.domain.maxValue,147 places: 0148 };149 break;150 case "esriFieldTypeSingle":151 case "esriFieldTypeDouble":152 cons = {153 min: fieldInfo.domain.minValue,154 max: fieldInfo.domain.maxValue155 };156 break;157 }158 node = new NumberSpinner({159 "class": "ee-inputField",160 name: fieldInfo.fieldName,161 smallDelta: 1,162 constraints: cons163 }, domConstruct.create("div"));164 }165 nodes.push(node);166 } else {167 switch (fieldInfo.type) {168 case "esriFieldTypeGUID":169 node = new ValidationTextBox({170 "class": "ee-inputField",171 name: fieldInfo.fieldName172 }, domConstruct.create("div"));173 node.validator = lang.hitch(this, this.validateGUID);174 nodes.push(node);175 break;176 case "esriFieldTypeDate":177 node = new DateTextBox({178 "class": "ee-inputField",179 name: fieldInfo.fieldName180 }, domConstruct.create("div"));181 //value: new Date(),182 nodes.push(node);183 if (fieldInfo.format) {184 if (fieldInfo.format.time && fieldInfo.format.time === true) {185 var timeNode = new TimeTextBox({186 "class": "ee-inputField",187 "style": "margin-top:2px;"188 }, domConstruct.create("div"));189 nodes.push(timeNode);190 //value: new Date()191 }192 }193 break;194 case "esriFieldTypeString":195 var maxlength = null;196 if (fieldInfo.length &&197 Number(fieldInfo.length) &&198 Number(fieldInfo.length) > 0) {199 maxlength = fieldInfo.length;200 }201 if (fieldInfo.hasOwnProperty("stringFieldOption")) {202 if (fieldInfo.stringFieldOption === "richtext") {203 var params = {204 'class': 'ee-inputField ee-inputFieldRichText',205 trim: true,206 maxLength: maxlength207 };208 params['class'] += ' atiRichTextField';209 params.height = '100%';210 params.width = '100%';211 params.name = fieldInfo.fieldName;212 params.plugins = ['bold', 'italic', 'underline', 'foreColor', 'hiliteColor', '|', 'justifyLeft',213 'justifyCenter', 'justifyRight', 'justifyFull', '|', 'insertOrderedList', 'insertUnorderedList',214 'indent', 'outdent', '|', 'createLink'];215 node = new Editor(params, domConstruct.create("div"));216 node.startup();217 }218 else if (fieldInfo.stringFieldOption === "textarea") {219 node = new SimpleTextarea({220 "class": "ee-inputField ee-inputFieldTextArea",221 name: fieldInfo.fieldName,222 maxlength: maxlength223 }, domConstruct.create("div"));224 }225 else {226 node = new TextBox({227 "class": "ee-inputField",228 name: fieldInfo.fieldName,229 maxlength: maxlength230 }, domConstruct.create("div"));231 }232 }233 else {234 node = new TextBox({235 "class": "ee-inputField",236 name: fieldInfo.fieldName,237 maxlength: maxlength238 }, domConstruct.create("div"));239 }240 nodes.push(node);241 break;242 // todo: check for more types243 case "esriFieldTypeSmallInteger":244 case "esriFieldTypeInteger":245 node = new NumberTextBox({246 "class": "ee-inputField",247 name: fieldInfo.fieldName,248 constraints: { places: 0 }249 }, domConstruct.create("div"));250 nodes.push(node);251 break;252 case "esriFieldTypeSingle":253 case "esriFieldTypeDouble":254 node = new NumberTextBox({255 "class": "ee-inputField",256 name: fieldInfo.fieldName257 }, domConstruct.create("div"));258 nodes.push(node);259 break;260 default:261 node = new TextBox({262 "class": "ee-unsupportField",263 name: fieldInfo.fieldName,264 value: "N/A",265 readOnly: true266 }, domConstruct.create("div"));267 nodes.push(node);268 break;269 }270 }271 return nodes;272 };273 mo.changeFieldToMostRestrictive = function (existingField, newField) {274 if (!existingField.hasOwnProperty('type') && newField.hasOwnProperty('type')) {275 return newField;276 }277 if (newField.length && Number(newField.length) && Number(newField.length) > 0) {278 if (existingField.length && Number(existingField.length)) {279 if (newField.length < existingField.length) {280 existingField.length = newField.length;281 }282 }283 else {284 existingField.length = newField.length;285 }286 }287 if (existingField.type === newField.type) {288 switch (newField.type) {289 case "esriFieldTypeString":290 if (existingField.hasOwnProperty("stringFieldOption") && newField.hasOwnProperty("stringFieldOption")) {291 if (existingField.stringFieldOption === "richtext" && newField.stringFieldOption !== "richtext") {292 existingField.stringFieldOption = newField.stringFieldOption;293 }294 else if (existingField.stringFieldOption === "textarea" && newField.stringFieldOption === "textbox") {295 existingField.stringFieldOption = newField.stringFieldOption;296 }297 }298 break;299 }300 }301 return existingField;302 };303 return mo;...
FormAutofillStorage.jsm
Source:FormAutofillStorage.jsm
1/* This Source Code Form is subject to the terms of the Mozilla Public2 * License, v. 2.0. If a copy of the MPL was not distributed with this3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */4/*5 * Implements an interface of the storage of Form Autofill.6 */7"use strict";8// We expose a singleton from this module. Some tests may import the9// constructor via a backstage pass.10const EXPORTED_SYMBOLS = ["formAutofillStorage", "FormAutofillStorage"];11const { FormAutofill } = ChromeUtils.import(12 "resource://autofill/FormAutofill.jsm"13);14const {15 FormAutofillStorageBase,16 CreditCardsBase,17 AddressesBase,18} = ChromeUtils.import("resource://autofill/FormAutofillStorageBase.jsm");19const { XPCOMUtils } = ChromeUtils.importESModule(20 "resource://gre/modules/XPCOMUtils.sys.mjs"21);22const lazy = {};23XPCOMUtils.defineLazyModuleGetters(lazy, {24 CreditCard: "resource://gre/modules/CreditCard.jsm",25 FormAutofillUtils: "resource://autofill/FormAutofillUtils.jsm",26 JSONFile: "resource://gre/modules/JSONFile.jsm",27 OSKeyStore: "resource://gre/modules/OSKeyStore.jsm",28});29const PROFILE_JSON_FILE_NAME = "autofill-profiles.json";30class Addresses extends AddressesBase {31 /**32 * Merge new address into the specified address if mergeable.33 *34 * @param {string} guid35 * Indicates which address to merge.36 * @param {Object} address37 * The new address used to merge into the old one.38 * @param {boolean} strict39 * In strict merge mode, we'll treat the subset record with empty field40 * as unable to be merged, but mergeable if in non-strict mode.41 * @returns {Promise<boolean>}42 * Return true if address is merged into target with specific guid or false if not.43 */44 async mergeIfPossible(guid, address, strict) {45 this.log.debug(`mergeIfPossible: ${guid}`);46 let addressFound = this._findByGUID(guid);47 if (!addressFound) {48 throw new Error("No matching address.");49 }50 let addressToMerge = this._clone(address);51 this._normalizeRecord(addressToMerge, strict);52 let hasMatchingField = false;53 let country =54 addressFound.country ||55 addressToMerge.country ||56 FormAutofill.DEFAULT_REGION;57 let collators = lazy.FormAutofillUtils.getSearchCollators(country);58 for (let field of this.VALID_FIELDS) {59 let existingField = addressFound[field];60 let incomingField = addressToMerge[field];61 if (incomingField !== undefined && existingField !== undefined) {62 if (incomingField != existingField) {63 // Treat "street-address" as mergeable if their single-line versions64 // match each other.65 if (66 field == "street-address" &&67 lazy.FormAutofillUtils.compareStreetAddress(68 existingField,69 incomingField,70 collators71 )72 ) {73 // Keep the street-address in storage if its amount of lines is greater than74 // or equal to the incoming one.75 if (76 existingField.split("\n").length >=77 incomingField.split("\n").length78 ) {79 // Replace the incoming field with the one in storage so it will80 // be further merged back to storage.81 addressToMerge[field] = existingField;82 }83 } else if (84 field != "street-address" &&85 lazy.FormAutofillUtils.strCompare(86 existingField,87 incomingField,88 collators89 )90 ) {91 addressToMerge[field] = existingField;92 } else {93 this.log.debug("Conflicts: field", field, "has different value.");94 return false;95 }96 }97 hasMatchingField = true;98 }99 }100 // We merge the address only when at least one field has the same value.101 if (!hasMatchingField) {102 this.log.debug("Unable to merge because no field has the same value");103 return false;104 }105 // Early return if the data is the same or subset.106 let noNeedToUpdate = this.VALID_FIELDS.every(field => {107 // When addressFound doesn't contain a field, it's unnecessary to update108 // if the same field in addressToMerge is omitted or an empty string.109 if (addressFound[field] === undefined) {110 return !addressToMerge[field];111 }112 // When addressFound contains a field, it's unnecessary to update if113 // the same field in addressToMerge is omitted or a duplicate.114 return (115 addressToMerge[field] === undefined ||116 addressFound[field] === addressToMerge[field]117 );118 });119 if (noNeedToUpdate) {120 return true;121 }122 await this.update(guid, addressToMerge, true);123 return true;124 }125}126class CreditCards extends CreditCardsBase {127 constructor(store) {128 super(store);129 }130 async _encryptNumber(creditCard) {131 if (!("cc-number-encrypted" in creditCard)) {132 if ("cc-number" in creditCard) {133 let ccNumber = creditCard["cc-number"];134 if (lazy.CreditCard.isValidNumber(ccNumber)) {135 creditCard["cc-number"] = lazy.CreditCard.getLongMaskedNumber(136 ccNumber137 );138 } else {139 // Credit card numbers can be entered on versions of Firefox that don't validate140 // the number and then synced to this version of Firefox. Therefore, mask the141 // full number if the number is invalid on this version.142 creditCard["cc-number"] = "*".repeat(ccNumber.length);143 }144 creditCard["cc-number-encrypted"] = await lazy.OSKeyStore.encrypt(145 ccNumber146 );147 } else {148 creditCard["cc-number-encrypted"] = "";149 }150 }151 }152 /**153 * Merge new credit card into the specified record if cc-number is identical.154 * (Note that credit card records always do non-strict merge.)155 *156 * @param {string} guid157 * Indicates which credit card to merge.158 * @param {Object} creditCard159 * The new credit card used to merge into the old one.160 * @returns {boolean}161 * Return true if credit card is merged into target with specific guid or false if not.162 */163 async mergeIfPossible(guid, creditCard) {164 this.log.debug(`mergeIfPossible: ${guid}`);165 // Credit card number is required since it also must match.166 if (!creditCard["cc-number"]) {167 return false;168 }169 // Query raw data for comparing the decrypted credit card number170 let creditCardFound = await this.get(guid, { rawData: true });171 if (!creditCardFound) {172 throw new Error("No matching credit card.");173 }174 let creditCardToMerge = this._clone(creditCard);175 this._normalizeRecord(creditCardToMerge);176 for (let field of this.VALID_FIELDS) {177 let existingField = creditCardFound[field];178 // Make sure credit card field is existed and have value179 if (180 field == "cc-number" &&181 (!existingField || !creditCardToMerge[field])182 ) {183 return false;184 }185 if (!creditCardToMerge[field] && typeof existingField != "undefined") {186 creditCardToMerge[field] = existingField;187 }188 let incomingField = creditCardToMerge[field];189 if (incomingField && existingField) {190 if (incomingField != existingField) {191 this.log.debug("Conflicts: field", field, "has different value.");192 return false;193 }194 }195 }196 // Early return if the data is the same.197 let exactlyMatch = this.VALID_FIELDS.every(198 field => creditCardFound[field] === creditCardToMerge[field]199 );200 if (exactlyMatch) {201 return true;202 }203 await this.update(guid, creditCardToMerge, true);204 return true;205 }206}207class FormAutofillStorage extends FormAutofillStorageBase {208 constructor(path) {209 super(path);210 }211 getAddresses() {212 if (!this._addresses) {213 this._store.ensureDataReady();214 this._addresses = new Addresses(this._store);215 }216 return this._addresses;217 }218 getCreditCards() {219 if (!this._creditCards) {220 this._store.ensureDataReady();221 this._creditCards = new CreditCards(this._store);222 }223 return this._creditCards;224 }225 /**226 * Loads the profile data from file to memory.227 * @returns {JSONFile}228 * The JSONFile store.229 */230 _initializeStore() {231 return new lazy.JSONFile({232 path: this._path,233 dataPostProcessor: this._dataPostProcessor.bind(this),234 });235 }236 _dataPostProcessor(data) {237 data.version = this.version;238 if (!data.addresses) {239 data.addresses = [];240 }241 if (!data.creditCards) {242 data.creditCards = [];243 }244 return data;245 }246}247// The singleton exposed by this module.248const formAutofillStorage = new FormAutofillStorage(249 PathUtils.join(PathUtils.profileDir, PROFILE_JSON_FILE_NAME)...
Using AI Code Generation
1import React from 'react';2import { storiesOf } from '@storybook/react';3import { action } from '@storybook/addon-actions';4import { linkTo } from '@storybook/addon-links';5import { Button, Welcome } from '@storybook/react/demo';6import { withKnobs, text, boolean, number } from '@storybook/addon-knobs/react';7storiesOf('Button', module)8 .add('with text', () => (9 <Button onClick={action('clicked')}>Hello Button</Button>10 .add('with some emoji', () => (11 <Button onClick={action('clicked')}>😀 😎 👍 💯</Button>12 .add('with some emoji and action', () => (13 <Button onClick={action('clicked')}>😀 😎 👍 💯</Button>14 .add('with some emoji and action', () => (15 <Button onClick={action('clicked')}>😀 😎 👍 💯</Button>16 .add('with some emoji and action', () => (17 <Button onClick={action('clicked')}>😀 😎 👍 💯</Button>18 .add('with some emoji and action', () => (19 <Button onClick={action('clicked')}>😀 😎 👍 💯</Button>20 .add('with some emoji and action', () => (21 <Button onClick={action('clicked')}>😀 😎 👍 💯</Button>22 .add('with some emoji and action', () => (23 <Button onClick={action('clicked')}>😀 😎 👍 💯</Button>24 .add('with some emoji and action', () => (25 <Button onClick={action('clicked')}>😀 😎 👍 💯</Button>26 .add('with some emoji and action', () => (27 <Button onClick={action('clicked')}>😀 😎 👍 💯</Button>28 .add('with some emoji and action', () => (29 <Button onClick={action('clicked')}>😀 😎 👍 💯</Button>30 .add('with some emoji and action', () => (31 <Button onClick={action('clicked')}>😀 😎 👍 💯</Button>
Using AI Code Generation
1var storybook = require('storybook-root');2var storybook = new Storybook();3storybook.existingField('name', 'value');4var storybook = require('storybook-root');5var storybook = new Storybook();6storybook.existingField('name', 'value');7var storybook = require('storybook-root');8var storybook = new Storybook();9storybook.existingField('name', 'value');10var storybook = require('storybook-root');11var storybook = new Storybook();12storybook.existingField('name', 'value');13var storybook = require('storybook-root');14var storybook = new Storybook();15storybook.existingField('name', 'value');16var storybook = require('storybook-root');17var storybook = new Storybook();18storybook.existingField('name', 'value');19var storybook = require('storybook-root');20var storybook = new Storybook();21storybook.existingField('name', 'value');22var storybook = require('storybook-root');23var storybook = new Storybook();24storybook.existingField('name', 'value');25var storybook = require('storybook-root');26var storybook = new Storybook();27storybook.existingField('name', 'value');28var storybook = require('storybook-root');29var storybook = new Storybook();30storybook.existingField('name', 'value');31var storybook = require('storybook-root');32var storybook = new Storybook();33storybook.existingField('name', 'value');
Using AI Code Generation
1import { existingField } from 'storybook-root'2existingField('myField')3import { existingField } from 'storybook-root'4existingField('myField')5import { existingField } from 'storybook-root'6existingField('myField')7import { existingField } from 'storybook-root'8existingField('myField')9import { existingField } from 'storybook-root'10existingField('myField')11import { existingField } from 'storybook-root'12existingField('myField')13import { existingField } from 'storybook-root'14existingField('myField')15import { existingField } from 'storybook-root'16existingField('myField')17import { existingField } from 'storybook-root'18existingField('myField')19import { existingField } from 'storybook-root'20existingField('myField')21import { existingField } from 'storybook-root'22existingField('myField')23import { existingField } from 'storybook-root'24existingField('myField')
Using AI Code Generation
1const { existingField } = require('storybook-root');2const { Field } = require('storybook-root');3const field = existingField('test');4const field2 = new Field('test');5console.log(field);6console.log(field2);7const { Field } = require('storybook-field');8module.exports = {9 existingField: (name) => {10 return new Field(name);11 }12}13module.exports = {14 Field: class Field {15 constructor(name) {16 this.name = name;17 }18 }19}20const { existingField } = require('storybook-root');21const { Field } = require('storybook-root');22const field = existingField('test');23const field2 = new Field('test');24console.log(field);25console.log(field2);26const { Field } = require('storybook-field');27module.exports = {28 existingField: (name) => {29 return new Field(name);30 },31}32module.exports = {33 Field: class Field {34 constructor(name) {35 this.name = name;36 }37 }38}
Using AI Code Generation
1const { storybookRoot } = require('storybook-root');2const { existingField } = storybookRoot;3const { field } = existingField('test');4const { customField } = storybookRoot;5const { field } = customField({6 { label: 'test', value: 'test' },7 { label: 'test', value: 'test' },8});9const { customField } = storybookRoot;10const { field } = customField({11 { label: 'test', value: 'test' },12 { label: 'test', value: 'test' },13});14const { customField } = storybookRoot;15const { field } = customField({16 { label: 'test', value: 'test' },17 { label: 'test', value: 'test' },18});19const { customField } = storybookRoot;20const { field } = customField({21 { label: 'test', value: 'test' },22 { label: 'test', value: 'test' },23});24const { customField } = storybookRoot;25const { field } = customField({
Using AI Code Generation
1import { existingField } from 'storybook-root';2const myField = existingField('myField');3myField.setValue('myValue');4import { addDecorator } from '@storybook/react';5import { withStorybookRoot } from 'storybook-root';6addDecorator(withStorybookRoot);7import { addDecorator } from '@storybook/react';8import { withStorybookRoot } from 'storybook-root';9addDecorator(withStorybookRoot);10import { addons } from '@storybook/addons';11import { withStorybookRoot } from 'storybook-root';12addons.setConfig({13 sidebar: {14 },
Using AI Code Generation
1function existingField(){2 var field = document.getElementById("story");3 field.setAttribute("placeholder", "Tell your story here");4}5existingField();6function existingField(){7 var field = document.getElementById("story");8 field.setAttribute("placeholder", "Tell your story here");9}10existingField();11function existingField(){12 var field = document.getElementById("story");13 field.setAttribute("placeholder", "Tell your story here");14}15existingField();16function existingField(){17 var field = document.getElementById("story");18 field.setAttribute("placeholder", "Tell your story here");19}20existingField();21function existingField(){22 var field = document.getElementById("story");23 field.setAttribute("placeholder", "Tell your story here");24}25existingField();26function existingField(){27 var field = document.getElementById("story");28 field.setAttribute("placeholder", "Tell your story here");29}30existingField();31function existingField(){32 var field = document.getElementById("story");33 field.setAttribute("placeholder", "Tell your story here");34}35existingField();36function existingField(){37 var field = document.getElementById("story");38 field.setAttribute("placeholder", "
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!