@washingtonpost/subs-de-inputs 0.1.1 → 0.2.0-canary.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/components/DESelect/index.d.ts +0 -5
- package/dist/index.d.ts +1 -0
- package/dist/interfaces/index.d.ts +6 -0
- package/dist/interfaces/twpdeu.d.ts +11 -0
- package/dist/services/dataEnrichment.d.ts +17 -2
- package/dist/subs-de-inputs.cjs.development.js +150 -476
- package/dist/subs-de-inputs.cjs.development.js.map +1 -1
- package/dist/subs-de-inputs.cjs.production.min.js +1 -1
- package/dist/subs-de-inputs.cjs.production.min.js.map +1 -1
- package/dist/subs-de-inputs.esm.js +150 -478
- package/dist/subs-de-inputs.esm.js.map +1 -1
- package/package.json +21 -6
- package/CHANGELOG.md +0 -16
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"subs-de-inputs.esm.js","sources":["../src/interfaces/index.ts","../src/utils/hasRequiredPrivacyCookies.ts","../src/services/dataEnrichment.ts","../src/components/DESelect/index.tsx"],"sourcesContent":["export type AttributeValue = {\n name: string;\n date_created: Number;\n last_modified_date: Number;\n archived: boolean;\n order: number;\n};\n\nexport const CollectionBehaviors = {\n COLLECT: 'COLLECT',\n DO_NOT_COLLECT: 'DO_NOT_COLLECT',\n} as const;\n\nexport type Attribute = {\n name: string;\n approved_for_use?: boolean;\n collection_behavior?: (typeof CollectionBehaviors)[keyof typeof CollectionBehaviors];\n datatype: 'string';\n explicit: boolean;\n multiple_value: boolean;\n last_modified_date: Number;\n date_created: Number;\n values: Array<AttributeValue>;\n};\n\nexport const AttributesState = {\n SUCCESS: '100',\n} as const;\n\nexport const IngestResponseState = {\n SUCCESS: '100',\n SYSTEM_ERROR: '101',\n INVALID_TYPE: '102',\n INVALID_IDENTIFIER: '103',\n INVALID_DATA: '104',\n INVALID_ATTRIBUTE_DEFINITION: '105',\n INVALID_META_DEFINITION: '106',\n} as const;\n","import { WPGeo, getCookie } from '@washingtonpost/subs-sdk';\n\nexport const hasRequiredPrivacyCookies = () => {\n if (typeof window === 'undefined') {\n return false;\n }\n\n const wp_usp = getCookie('wp_usp');\n\n const countryCode = WPGeo()?.country_code;\n\n return !!(wp_usp && countryCode === 'US');\n};\n","import {\n ENDPOINTS,\n ResponseStatus,\n JSON_HEADERS,\n} from '@washingtonpost/subs-sdk';\n\nconst base = `${ENDPOINTS.base}/de/v1`;\n\nconst attributesCache: Record<string, any> = {};\nexport const getAttributes = async ({ fieldName }: { fieldName: string }) => {\n if (attributesCache[fieldName]) {\n return attributesCache[fieldName];\n }\n\n const fieldNames = [fieldName];\n\n try {\n const url = new URL(`${base}/attributes`);\n url.searchParams.set('attributes', fieldNames.join(','));\n\n const data = await fetch(url.toString(), {\n credentials: 'include',\n headers: JSON_HEADERS,\n });\n const json = await data.json();\n\n if (data.ok && json.status === ResponseStatus.SUCCESS) {\n const attributes = json.attributes || [];\n attributesCache[fieldName] = attributes;\n return attributes;\n } else {\n return [];\n }\n } catch (e) {\n console.debug(e);\n return [];\n }\n};\n","import React, { useState, useEffect } from 'react';\nimport { Select, styled, theme } from '@washingtonpost/wpds-ui-kit';\nimport { Attribute, AttributeValue } from '../../interfaces';\nimport { SubsWindow } from '@washingtonpost/subs-sdk';\nimport { getAttributes } from '../../services/dataEnrichment';\n\ndeclare global {\n interface Window extends SubsWindow {}\n}\n\ninterface DESelectProps {\n source: string;\n fieldName: string;\n label?: string;\n dataDictionaryConfig?: Attribute;\n defaultValue?: string;\n disabled?: boolean;\n submit: boolean;\n onChange?: ({ value }: { value: string }) => void;\n onFinished?: ({\n isFinished,\n isError,\n }: {\n isFinished: boolean;\n isError: boolean;\n }) => void;\n valuesFilter?: (value: AttributeValue) => boolean;\n selectProps?: {\n root?: any;\n trigger?: any;\n label?: any;\n value?: any;\n content?: any;\n item?: any;\n };\n children?: React.ReactNode;\n}\n\nexport const DESelect: React.FC<DESelectProps> = ({\n source,\n fieldName,\n label,\n dataDictionaryConfig,\n defaultValue,\n disabled,\n submit,\n onChange = () => {},\n onFinished = () => {},\n valuesFilter = () => true,\n children,\n}) => {\n const [config, setConfig] = useState(dataDictionaryConfig);\n\n const [selected, setSelected] = useState('');\n\n useEffect(() => {\n if (children) {\n if (__DEV__) {\n console.debug('childen props', children);\n }\n return;\n }\n\n if (!config) {\n (async () => {\n // TODO: Switch to window.__twpdeu.getFieldConfigs\n const config = await getAttributes({ fieldName });\n if (__DEV__) {\n console.debug('config from API', config);\n }\n setConfig(config[0]);\n })();\n }\n }, []);\n\n useEffect(() => {\n if (submit && selected) {\n if (__DEV__) {\n console.error('push not implemented', selected, source);\n }\n onFinished({ isFinished: true, isError: false });\n }\n }, [submit, selected]);\n\n if (!(children || config)) {\n return <span>loading</span>;\n }\n\n const defaultValueProp = defaultValue ? { defaultValue } : {};\n\n const disabledProp = disabled ? { disabled: true } : {};\n\n // sort and filter out archived values\n const values = config\n ? config.values\n .sort((a, b) => a.order - b.order)\n .filter((value) => value.archived !== true)\n .filter(valuesFilter)\n : [];\n\n return (\n <SelectWrapper>\n <Select.Root\n onValueChange={(e: string) => {\n onChange({ value: e });\n setSelected(e);\n }}\n {...defaultValueProp}\n {...disabledProp}\n >\n {children ? children : null}\n {!children && config && (\n <>\n <Select.Trigger data-test-id={`${config.name}-select-trigger`}>\n <Select.Label>{label || config.name}</Select.Label>\n <Select.Value />\n </Select.Trigger>\n <Select.Content\n css={{ zIndex: theme.zIndices.page }}\n data-test-id={`${config.name}-select-content`}\n >\n {values.map((value) => (\n <Select.Item value={value.name} key={value.name}>\n {value.name}\n </Select.Item>\n ))}\n </Select.Content>\n </>\n )}\n </Select.Root>\n </SelectWrapper>\n );\n};\n\nconst SelectWrapper = styled('div', {\n boxSizing: 'border-box',\n display: 'flex',\n marginBottom: '$100',\n flexDirection: 'column',\n '& button': {\n padding: '1px 6px',\n },\n '& *': { boxSizing: 'border-box' },\n});\n"],"names":["CollectionBehaviors","COLLECT","DO_NOT_COLLECT","AttributesState","SUCCESS","IngestResponseState","SYSTEM_ERROR","INVALID_TYPE","INVALID_IDENTIFIER","INVALID_DATA","INVALID_ATTRIBUTE_DEFINITION","INVALID_META_DEFINITION","hasRequiredPrivacyCookies","window","wp_usp","getCookie","countryCode","_WPGeo","WPGeo","country_code","base","ENDPOINTS","attributesCache","getAttributes","_ref2","_asyncToGenerator","_regeneratorRuntime","mark","_callee","_ref","fieldName","fieldNames","url","data","json","attributes","wrap","_callee$","_context","prev","next","abrupt","URL","searchParams","set","join","fetch","toString","credentials","headers","JSON_HEADERS","sent","ok","status","ResponseStatus","t0","console","debug","stop","_x","apply","arguments","DESelect","source","label","dataDictionaryConfig","defaultValue","disabled","submit","_ref$onChange","onChange","_ref$onFinished","onFinished","_ref$valuesFilter","valuesFilter","children","_useState","useState","config","setConfig","_useState2","selected","setSelected","useEffect","process","env","NODE_ENV","error","isFinished","isError","React","defaultValueProp","disabledProp","values","sort","a","b","order","filter","value","archived","SelectWrapper","Select","Root","_extends","onValueChange","e","Trigger","name","Label","Value","Content","css","zIndex","theme","zIndices","page","map","Item","key","styled","boxSizing","display","marginBottom","flexDirection","padding"],"mappings":";;;;IAQaA,mBAAmB,GAAG;EACjCC,OAAO,EAAE,SAAS;EAClBC,cAAc,EAAE;;IAeLC,eAAe,GAAG;EAC7BC,OAAO,EAAE;;IAGEC,mBAAmB,GAAG;EACjCD,OAAO,EAAE,KAAK;EACdE,YAAY,EAAE,KAAK;EACnBC,YAAY,EAAE,KAAK;EACnBC,kBAAkB,EAAE,KAAK;EACzBC,YAAY,EAAE,KAAK;EACnBC,4BAA4B,EAAE,KAAK;EACnCC,uBAAuB,EAAE;;;IClCdC,yBAAyB,GAAG,SAA5BA,yBAAyBA;;EACpC,IAAI,OAAOC,MAAM,KAAK,WAAW,EAAE;IACjC,OAAO,KAAK;;EAGd,IAAMC,MAAM,GAAGC,SAAS,CAAC,QAAQ,CAAC;EAElC,IAAMC,WAAW,IAAAC,MAAA,GAAGC,KAAK,EAAE,qBAAPD,M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QAAA;IACVC,aAAa,EAAE,SAAAA,cAACC,CAAS;MACvBpC,QAAQ,CAAC;QAAE6B,KAAK,EAAEO;OAAG,CAAC;MACtBxB,WAAW,CAACwB,CAAC,CAAC;;KAEZf,gBAAgB,EAChBC,YAAY,GAEfjB,QAAQ,GAAGA,QAAQ,GAAG,IAAI,EAC1B,CAACA,QAAQ,IAAIG,MAAM,IAClBY,0CACEA,oBAACY,MAAM,CAACK,OAAO;oBAAkB7B,MAAM,CAAC8B,IAAI;KAC1ClB,oBAACY,MAAM,CAACO,KAAK,QAAE7C,KAAK,IAAIc,MAAM,CAAC8B,IAAI,CAAgB,EACnDlB,oBAACY,MAAM,CAACQ,KAAK,OAAG,CACD,EACjBpB,oBAACY,MAAM,CAACS,OAAO;IACbC,GAAG,EAAE;MAAEC,MAAM,EAAEC,KAAK,CAACC,QAAQ,CAACC;KAAM;oBACnBtC,MAAM,CAAC8B,IAAI;KAE3Bf,MAAM,CAACwB,GAAG,CAAC,UAAClB,KAAK;IAAA,OAChBT,oBAACY,MAAM,CAACgB,IAAI;MAACnB,KAAK,EAAEA,KAAK,CAACS,IAAI;MAAEW,GAAG,EAAEpB,KAAK,CAACS;OACxCT,KAAK,CAACS,IAAI,CACC;GACf,CAAC,CACa,CAEpB,CACW,CACA;AAEpB,CAAC;AAED,IAAMP,aAAa,gBAAGmB,MAAM,CAAC,KAAK,EAAE;EAClCC,SAAS,EAAE,YAAY;EACvBC,OAAO,EAAE,MAAM;EACfC,YAAY,EAAE,MAAM;EACpBC,aAAa,EAAE,QAAQ;EACvB,UAAU,EAAE;IACVC,OAAO,EAAE;GACV;EACD,KAAK,EAAE;IAAEJ,SAAS,EAAE;;CACrB,CAAC;;;;"}
|
|
1
|
+
{"version":3,"file":"subs-de-inputs.esm.js","sources":["../src/interfaces/index.ts","../src/utils/hasRequiredPrivacyCookies.ts","../src/services/dataEnrichment.ts","../src/components/DESelect/index.tsx"],"sourcesContent":["export type AttributeValue = {\n name: string;\n date_created: Number;\n last_modified_date: Number;\n archived: boolean;\n order: number;\n};\n\nexport const CollectionBehaviors = {\n COLLECT: 'COLLECT',\n DO_NOT_COLLECT: 'DO_NOT_COLLECT',\n} as const;\n\nexport type Attribute = {\n name: string;\n approved_for_use?: boolean;\n collection_behavior?: (typeof CollectionBehaviors)[keyof typeof CollectionBehaviors];\n datatype: 'string';\n explicit: boolean;\n multiple_value: boolean;\n last_modified_date: Number;\n date_created: Number;\n values: Array<AttributeValue>;\n};\n\nexport const AttributesState = {\n SUCCESS: '100',\n} as const;\n\nexport const IngestType = {\n EXPLICIT: 'explicit',\n IMPLICIT: 'implicit',\n} as const;\n\nexport const IngestResponseState = {\n SUCCESS: '100',\n SYSTEM_ERROR: '101',\n INVALID_TYPE: '102',\n INVALID_IDENTIFIER: '103',\n INVALID_DATA: '104',\n INVALID_ATTRIBUTE_DEFINITION: '105',\n INVALID_META_DEFINITION: '106',\n UNAUTHENTICATED: '107',\n MISMATCHED_IDENTIFIER: '108',\n} as const;\n","import { WPGeo, getCookie } from '@washingtonpost/subs-sdk';\n\nexport const hasRequiredPrivacyCookies = () => {\n if (typeof window === 'undefined') {\n return false;\n }\n\n const wp_usp = getCookie('wp_usp');\n\n const countryCode = WPGeo()?.country_code;\n\n return !!(wp_usp && countryCode === 'US');\n};\n","import {\n ENDPOINTS,\n ResponseStatus,\n JSON_HEADERS,\n getCookie,\n} from '@washingtonpost/subs-sdk';\nimport {\n Attribute,\n CollectionBehaviors,\n IngestResponseState,\n IngestType,\n} from '../interfaces';\nimport { hasRequiredPrivacyCookies } from '../utils/hasRequiredPrivacyCookies';\n\nconst base = `${ENDPOINTS.base}/de/v1`;\n\nconst attributesCache: Record<string, any> = {};\nexport const getAttributes: GetAttributesType = async ({\n fieldName,\n}: {\n fieldName: string;\n}) => {\n if (attributesCache[fieldName]) {\n return attributesCache[fieldName];\n }\n\n const fieldNames = [fieldName];\n\n try {\n const url = new URL(`${base}/attributes`);\n url.searchParams.set('attributes', fieldNames.join(','));\n\n const data = await fetch(url.toString(), {\n credentials: 'include',\n headers: JSON_HEADERS,\n });\n const json = await data.json();\n\n if (data.ok && json.status === ResponseStatus.SUCCESS) {\n const attributes = json.attributes || [];\n attributesCache[fieldName] = attributes;\n return attributes;\n } else {\n return [];\n }\n } catch (e) {\n console.debug(e);\n return [];\n }\n};\n\ntype GetAttributesType = ({\n fieldName,\n}: {\n fieldName: string;\n}) => Promise<Attribute[]>;\n\nexport const ingest: IngestType = async ({\n submitData: { fieldName, value },\n source,\n}) => {\n const url = `${base}/ingest`;\n\n const wapo_login_id = getCookie('wapo_login_id');\n\n if (!hasRequiredPrivacyCookies()) {\n throw new Error('does not satisfy cookie check');\n }\n\n let attributeInfo = attributesCache[fieldName];\n if (!attributeInfo) {\n attributeInfo = await getAttributes({ fieldName });\n }\n\n if (\n attributeInfo[0] &&\n attributeInfo[0].name === fieldName &&\n attributeInfo[0].collection_behavior === CollectionBehaviors.DO_NOT_COLLECT\n ) {\n throw new Error('do not collect');\n }\n\n const jucid = localStorage.getItem('uuid');\n const ga = getCookie('_ga');\n\n const payload = {\n jucid,\n ga,\n type: IngestType.EXPLICIT,\n wapo_login_id, // TODO: move this to BE to read from cookie headers\n data: {\n fieldName,\n value,\n },\n metadata: { source },\n };\n\n try {\n const response = await fetch(url, {\n method: 'POST',\n credentials: 'include',\n headers: JSON_HEADERS,\n body: JSON.stringify(payload),\n });\n\n const json = await response.json();\n\n return json;\n } catch (e) {\n console.debug(e);\n return null;\n }\n};\n\ntype IngestType = ({\n submitData: { fieldName, value },\n source,\n}: {\n submitData: {\n fieldName: string;\n value: string;\n };\n source: string;\n}) => Promise<{\n status: ResponseStatus;\n state: (typeof IngestResponseState)[keyof typeof IngestResponseState];\n} | null>;\n","import React, { useState, useEffect } from 'react';\nimport { Select, styled, theme } from '@washingtonpost/wpds-ui-kit';\nimport { Attribute, AttributeValue } from '../../interfaces';\nimport { getAttributes, ingest } from '../../services/dataEnrichment';\nimport { ResponseStatus } from '@washingtonpost/subs-sdk';\n\ninterface DESelectProps {\n source: string;\n fieldName: string;\n label?: string;\n dataDictionaryConfig?: Attribute;\n defaultValue?: string;\n disabled?: boolean;\n submit: boolean;\n onChange?: ({ value }: { value: string }) => void;\n onFinished?: ({\n isFinished,\n isError,\n }: {\n isFinished: boolean;\n isError: boolean;\n }) => void;\n valuesFilter?: (value: AttributeValue) => boolean;\n selectProps?: {\n root?: any;\n trigger?: any;\n label?: any;\n value?: any;\n content?: any;\n item?: any;\n };\n children?: React.ReactNode;\n}\n\nexport const DESelect: React.FC<DESelectProps> = ({\n source,\n fieldName,\n label,\n dataDictionaryConfig,\n defaultValue,\n disabled,\n submit,\n onChange = () => {},\n onFinished = () => {},\n valuesFilter = () => true,\n children,\n}) => {\n const [config, setConfig] = useState(dataDictionaryConfig);\n\n const [selected, setSelected] = useState('');\n\n useEffect(() => {\n if (children) {\n if (__DEV__) {\n console.debug('childen props', children);\n }\n return;\n }\n\n if (!config) {\n (async () => {\n // TODO: Switch to window.__twpdeu.getFieldConfigs\n const config = await getAttributes({ fieldName });\n if (__DEV__) {\n console.debug('config from API', config);\n }\n setConfig(config[0]);\n })();\n }\n }, []);\n\n useEffect(() => {\n (async () => {\n if (submit && selected) {\n // TODO: Switch to window.__twpdeu.push\n // TODO: Log to GA\n // TODO: Differentiate between explicit and implicit inputs?\n const result = await ingest({\n submitData: { fieldName, value: selected },\n source,\n });\n const isError = result\n ? result.status !== ResponseStatus.SUCCESS\n : true;\n\n onFinished({\n isFinished: true,\n isError,\n });\n }\n })();\n }, [submit, selected]);\n\n if (!(children || config)) {\n return <span>loading</span>;\n }\n\n const defaultValueProp = defaultValue ? { defaultValue } : {};\n\n const disabledProp = disabled ? { disabled: true } : {};\n\n // sort and filter out archived values\n const values = config\n ? config.values\n .sort((a, b) => a.order - b.order)\n .filter((value) => value.archived !== true)\n .filter(valuesFilter)\n : [];\n\n return (\n <SelectWrapper>\n <Select.Root\n onValueChange={(e: string) => {\n onChange({ value: e });\n setSelected(e);\n }}\n {...defaultValueProp}\n {...disabledProp}\n >\n {children ? children : null}\n {!children && config && (\n <>\n <Select.Trigger data-test-id={`${config.name}-select-trigger`}>\n <Select.Label>{label || config.name}</Select.Label>\n <Select.Value />\n </Select.Trigger>\n <Select.Content\n css={{ zIndex: theme.zIndices.page }}\n data-test-id={`${config.name}-select-content`}\n >\n {values.map((value) => (\n <Select.Item value={value.name} key={value.name}>\n {value.name}\n </Select.Item>\n ))}\n </Select.Content>\n </>\n )}\n </Select.Root>\n </SelectWrapper>\n );\n};\n\nconst SelectWrapper = styled('div', {\n boxSizing: 'border-box',\n display: 'flex',\n marginBottom: '$100',\n flexDirection: 'column',\n '& button': {\n padding: '1px 6px',\n },\n '& *': { boxSizing: 'border-box' },\n});\n"],"names":["CollectionBehaviors","COLLECT","DO_NOT_COLLECT","AttributesState","SUCCESS","IngestType","EXPLICIT","IMPLICIT","IngestResponseState","SYSTEM_ERROR","INVALID_TYPE","INVALID_IDENTIFIER","INVALID_DATA","INVALID_ATTRIBUTE_DEFINITION","INVALID_META_DEFINITION","UNAUTHENTICATED","MISMATCHED_IDENTIFIER","hasRequiredPrivacyCookies","window","wp_usp","getCookie","countryCode","_WPGeo","WPGeo","country_code","base","ENDPOINTS","attributesCache","getAttributes","_ref","fieldName","fieldNames","url","URL","searchParams","set","join","data","fetch","toString","credentials","headers","JSON_HEADERS","json","ok","status","ResponseStatus","attributes","e","console","debug","ingest","_ref2","submitData","value","source","wapo_login_id","Error","attributeInfo","name","collection_behavior","jucid","localStorage","getItem","ga","payload","type","metadata","response","method","body","JSON","stringify","DESelect","label","dataDictionaryConfig","defaultValue","disabled","submit","onChange","onFinished","valuesFilter","children","config","setConfig","useState","selected","setSelected","useEffect","process","env","NODE_ENV","result","isError","isFinished","React","defaultValueProp","disabledProp","values","sort","a","b","order","filter","archived","SelectWrapper","Select","Root","onValueChange","Trigger","Label","Value","Content","css","zIndex","theme","zIndices","page","map","Item","key","styled","boxSizing","display","marginBottom","flexDirection","padding"],"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BAACU,aAAa,QACZV,oBAACW,MAAM,CAACC,IAAI;IACVC,aAAa,EAAG5D,CAAS;MACvB+B,QAAQ,CAAC;QAAEzB,KAAK,EAAEN;OAAG,CAAC;MACtBuC,WAAW,CAACvC,CAAC,CAAC;KACf;OACGgD,gBAAgB;OAChBC;KAEHf,QAAQ,GAAGA,QAAQ,GAAG,IAAI,EAC1B,CAACA,QAAQ,IAAIC,MAAM,IAClBY,0CACEA,oBAACW,MAAM,CAACG,OAAO;uBAAkB1B,MAAM,CAACxB;KACtCoC,oBAACW,MAAM,CAACI,KAAK,QAAEpC,KAAK,IAAIS,MAAM,CAACxB,IAAI,CAAgB,EACnDoC,oBAACW,MAAM,CAACK,KAAK,OAAG,CACD,EACjBhB,oBAACW,MAAM,CAACM,OAAO;IACbC,GAAG,EAAE;MAAEC,MAAM,EAAEC,KAAK,CAACC,QAAQ,CAACC;KAAM;uBACnBlC,MAAM,CAACxB;KAEvBuC,MAAM,CAACoB,GAAG,CAAEhE,KAAK,IAChByC,oBAACW,MAAM,CAACa,IAAI;IAACjE,KAAK,EAAEA,KAAK,CAACK,IAAI;IAAE6D,GAAG,EAAElE,KAAK,CAACK;KACxCL,KAAK,CAACK,IAAI,CAEd,CAAC,CACa,CAEpB,CACW,CACA;AAEpB,CAAC;AAED,MAAM8C,aAAa,gBAAGgB,MAAM,CAAC,KAAK,EAAE;EAClCC,SAAS,EAAE,YAAY;EACvBC,OAAO,EAAE,MAAM;EACfC,YAAY,EAAE,MAAM;EACpBC,aAAa,EAAE,QAAQ;EACvB,UAAU,EAAE;IACVC,OAAO,EAAE;GACV;EACD,KAAK,EAAE;IAAEJ,SAAS,EAAE;;CACrB,CAAC;;;;"}
|
package/package.json
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
{
|
|
2
|
-
"version": "0.
|
|
2
|
+
"version": "0.2.0-canary.1",
|
|
3
3
|
"license": "UNLICENSED",
|
|
4
4
|
"main": "dist/index.js",
|
|
5
5
|
"typings": "dist/index.d.ts",
|
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
],
|
|
10
10
|
"scripts": {
|
|
11
11
|
"start": "tsdx watch --verbose --noClean",
|
|
12
|
-
"build": "tsdx build",
|
|
12
|
+
"build": "tsdx build --format esm",
|
|
13
13
|
"test": "APP_ENV=test tsdx test",
|
|
14
14
|
"lint": "tsdx lint",
|
|
15
15
|
"size": "NODE_OPTIONS=--openssl-legacy-provider size-limit",
|
|
@@ -30,15 +30,24 @@
|
|
|
30
30
|
"name": "@washingtonpost/subs-de-inputs",
|
|
31
31
|
"author": "Subs FE",
|
|
32
32
|
"module": "dist/subs-de-inputs.esm.js",
|
|
33
|
+
"sideEffects": false,
|
|
33
34
|
"size-limit": [
|
|
34
35
|
{
|
|
35
|
-
"name": "
|
|
36
|
-
"path": "dist/subs-de-inputs.
|
|
37
|
-
"
|
|
36
|
+
"name": "de-inputs: utils",
|
|
37
|
+
"path": "dist/subs-de-inputs.esm.js",
|
|
38
|
+
"import": "{ getAttributes, ingest }",
|
|
39
|
+
"limit": "5 KB"
|
|
40
|
+
},
|
|
41
|
+
{
|
|
42
|
+
"name": "de-inputs: DESelect",
|
|
43
|
+
"path": "dist/subs-de-inputs.esm.js",
|
|
44
|
+
"import": "{ DESelect }",
|
|
45
|
+
"limit": "5 KB"
|
|
38
46
|
}
|
|
39
47
|
],
|
|
40
48
|
"devDependencies": {
|
|
41
49
|
"@babel/core": "^7.12.3",
|
|
50
|
+
"@babel/plugin-transform-optional-chaining": "^7.24.1",
|
|
42
51
|
"@size-limit/preset-small-lib": "^4.10.2",
|
|
43
52
|
"@testing-library/react-hooks": "^5.0.0",
|
|
44
53
|
"@types/enzyme": "^3.10.7",
|
|
@@ -55,5 +64,11 @@
|
|
|
55
64
|
"nock": "^13.0.5",
|
|
56
65
|
"react-test-renderer": "^17.0.1",
|
|
57
66
|
"tslib": "^2.0.3"
|
|
58
|
-
}
|
|
67
|
+
},
|
|
68
|
+
"browserslist": [
|
|
69
|
+
"last 2 Chrome versions",
|
|
70
|
+
"last 2 Safari versions",
|
|
71
|
+
"last 2 Firefox versions",
|
|
72
|
+
"last 2 Edge versions"
|
|
73
|
+
]
|
|
59
74
|
}
|
package/CHANGELOG.md
DELETED
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
# Change Log
|
|
2
|
-
|
|
3
|
-
All notable changes to this project will be documented in this file. See
|
|
4
|
-
[Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
|
5
|
-
|
|
6
|
-
**[0.1.1 - 2024-04-30]**:
|
|
7
|
-
* Fix build by removing unused file
|
|
8
|
-
|
|
9
|
-
**[0.1.0 - 2024-04-25]**:
|
|
10
|
-
* Add initial `<DESelect />` component
|
|
11
|
-
|
|
12
|
-
**[0.0.2 - 2024-04-24]**:
|
|
13
|
-
* Fix build error
|
|
14
|
-
|
|
15
|
-
**[0.0.1 - 2024-04-09]**:
|
|
16
|
-
* Initial setup
|