@epa-wg/custom-element-dist 0.0.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/.editorconfig +11 -0
- package/.gitignore +26 -0
- package/.idea/codeStyles/codeStyleConfig.xml +5 -0
- package/.idea/compiler.xml +6 -0
- package/.idea/custom-element-dist.iml +13 -0
- package/.idea/inspectionProfiles/Project_Default.xml +6 -0
- package/.idea/misc.xml +6 -0
- package/.idea/modules.xml +8 -0
- package/.idea/vcs.xml +6 -0
- package/.storybook/main.ts +21 -0
- package/.storybook/preview.ts +17 -0
- package/.vscode/settings.json +24 -0
- package/LICENSE +201 -0
- package/README.md +32 -0
- package/bin/build.sh +8 -0
- package/bin/clean.sh +5 -0
- package/bin/postinstall.sh +17 -0
- package/bin/start.sh +2 -0
- package/coverage/base.css +224 -0
- package/coverage/block-navigation.js +87 -0
- package/coverage/coverage-final.json +16 -0
- package/coverage/favicon.png +0 -0
- package/coverage/index.html +161 -0
- package/coverage/prettify.css +1 -0
- package/coverage/prettify.js +2 -0
- package/coverage/sort-arrow-sprite.png +0 -0
- package/coverage/sorter.js +196 -0
- package/coverage/src/coverage.svg +10 -0
- package/coverage/src/custom-element/coverage.svg +10 -0
- package/coverage/src/custom-element/custom-element.js/coverage.svg +10 -0
- package/coverage/src/custom-element/custom-element.js.html +2149 -0
- package/coverage/src/custom-element/http-request.js/coverage.svg +10 -0
- package/coverage/src/custom-element/http-request.js.html +352 -0
- package/coverage/src/custom-element/index.html +161 -0
- package/coverage/src/custom-element/local-storage.js/coverage.svg +10 -0
- package/coverage/src/custom-element/local-storage.js.html +346 -0
- package/coverage/src/custom-element/location-element.js/coverage.svg +10 -0
- package/coverage/src/custom-element/location-element.js.html +343 -0
- package/coverage/src/index.html +116 -0
- package/coverage/src/mocks/coverage.svg +10 -0
- package/coverage/src/mocks/handlers.ts/coverage.svg +10 -0
- package/coverage/src/mocks/handlers.ts.html +172 -0
- package/coverage/src/mocks/index.html +116 -0
- package/coverage/src/stories/attributes.stories.ts/coverage.svg +10 -0
- package/coverage/src/stories/attributes.stories.ts.html +481 -0
- package/coverage/src/stories/coverage.svg +10 -0
- package/coverage/src/stories/css.stories.ts/coverage.svg +10 -0
- package/coverage/src/stories/css.stories.ts.html +397 -0
- package/coverage/src/stories/dom-merge.stories.ts/coverage.svg +10 -0
- package/coverage/src/stories/dom-merge.stories.ts.html +424 -0
- package/coverage/src/stories/external-template.stories.ts/coverage.svg +10 -0
- package/coverage/src/stories/external-template.stories.ts.html +820 -0
- package/coverage/src/stories/http-request.stories.ts/coverage.svg +10 -0
- package/coverage/src/stories/http-request.stories.ts.html +817 -0
- package/coverage/src/stories/index.html +236 -0
- package/coverage/src/stories/local-storage.stories.ts/coverage.svg +10 -0
- package/coverage/src/stories/local-storage.stories.ts.html +1249 -0
- package/coverage/src/stories/location-element.stories.ts/coverage.svg +10 -0
- package/coverage/src/stories/location-element.stories.ts.html +484 -0
- package/coverage/src/stories/renderPlay.ts/coverage.svg +10 -0
- package/coverage/src/stories/renderPlay.ts.html +151 -0
- package/coverage/src/stories/slice-events.stories.ts/coverage.svg +10 -0
- package/coverage/src/stories/slice-events.stories.ts.html +436 -0
- package/coverage/src/sum.ts/coverage.svg +10 -0
- package/coverage/src/sum.ts.html +94 -0
- package/dist/confused.svg +37 -0
- package/dist/custom-element-B4v-KaIh.cjs +53 -0
- package/dist/custom-element-_g0GTup2.js +436 -0
- package/dist/custom-element-bundle.cjs +1 -0
- package/dist/custom-element-bundle.js +31 -0
- package/dist/embed-1.html +3 -0
- package/dist/html-template.html +126 -0
- package/dist/html-template.xhtml +45 -0
- package/dist/html-template.xml +45 -0
- package/dist/http-request-BOvP4KTl.js +56 -0
- package/dist/http-request-DPrY7mGh.cjs +1 -0
- package/dist/local-storage-Boafngui.cjs +1 -0
- package/dist/local-storage-BqDEu2kF.js +59 -0
- package/dist/location-element-2m0gWq_d.cjs +1 -0
- package/dist/location-element-nA_wsqBt.js +49 -0
- package/dist/mockServiceWorker.js +284 -0
- package/dist/tree.xsl +33 -0
- package/dist/vite.svg +1 -0
- package/index.html +17 -0
- package/package.json +97 -0
- package/public/confused.svg +37 -0
- package/public/embed-1.html +3 -0
- package/public/html-template.html +126 -0
- package/public/html-template.xhtml +45 -0
- package/public/html-template.xml +45 -0
- package/public/mockServiceWorker.js +284 -0
- package/public/tree.xsl +33 -0
- package/public/vite.svg +1 -0
- package/src/assets/lit.svg +1 -0
- package/src/custom-element/custom-element.d.ts +36 -0
- package/src/custom-element/custom-element.js +688 -0
- package/src/custom-element/demo/a.html +63 -0
- package/src/custom-element/demo/confused.svg +37 -0
- package/src/custom-element/demo/data-slices.html +184 -0
- package/src/custom-element/demo/dce-social-preview.png +0 -0
- package/src/custom-element/demo/demo.css +22 -0
- package/src/custom-element/demo/dom-merge.html +123 -0
- package/src/custom-element/demo/embed-1.html +3 -0
- package/src/custom-element/demo/external-template.html +179 -0
- package/src/custom-element/demo/hex-grid-dce.html +183 -0
- package/src/custom-element/demo/hex-grid-transform.png +0 -0
- package/src/custom-element/demo/hex-grid.html +66 -0
- package/src/custom-element/demo/html-template.html +126 -0
- package/src/custom-element/demo/html-template.xhtml +45 -0
- package/src/custom-element/demo/html-template.xml +45 -0
- package/src/custom-element/demo/http-request.html +143 -0
- package/src/custom-element/demo/local-storage.html +218 -0
- package/src/custom-element/demo/location-element.html +155 -0
- package/src/custom-element/demo/logo.png +0 -0
- package/src/custom-element/demo/parameters.html +70 -0
- package/src/custom-element/demo/s.xml +14 -0
- package/src/custom-element/demo/s.xslt +76 -0
- package/src/custom-element/demo/scoped-css.html +169 -0
- package/src/custom-element/demo/ss.html +57 -0
- package/src/custom-element/demo/table.xml +25 -0
- package/src/custom-element/demo/table.xsl +293 -0
- package/src/custom-element/demo/template.xsl +46 -0
- package/src/custom-element/demo/tree.xml +25 -0
- package/src/custom-element/demo/tree.xsl +33 -0
- package/src/custom-element/demo/wc-square.svg +1 -0
- package/src/custom-element/demo/xhtml-template.xhtml +45 -0
- package/src/custom-element/demo/z.html +62 -0
- package/src/custom-element/demo/z.xml +60 -0
- package/src/custom-element/http-request.js +89 -0
- package/src/custom-element/ide/IDE.md +31 -0
- package/src/custom-element/ide/customData-dce.json +112 -0
- package/src/custom-element/ide/customData-xsl.json +1018 -0
- package/src/custom-element/ide/web-types-dce.json +111 -0
- package/src/custom-element/ide/web-types-xsl.json +867 -0
- package/src/custom-element/index.html +168 -0
- package/src/custom-element/index.js +7 -0
- package/src/custom-element/local-storage.js +87 -0
- package/src/custom-element/location-element.js +87 -0
- package/src/custom-element.test.ts +10 -0
- package/src/index.css +38 -0
- package/src/mocks/handlers.ts +29 -0
- package/src/mocks/pokemons.mock.ts +13 -0
- package/src/stories/Configure.mdx +364 -0
- package/src/stories/assets/accessibility.png +0 -0
- package/src/stories/assets/accessibility.svg +5 -0
- package/src/stories/assets/addon-library.png +0 -0
- package/src/stories/assets/assets.png +0 -0
- package/src/stories/assets/avif-test-image.avif +0 -0
- package/src/stories/assets/context.png +0 -0
- package/src/stories/assets/discord.svg +15 -0
- package/src/stories/assets/docs.png +0 -0
- package/src/stories/assets/figma-plugin.png +0 -0
- package/src/stories/assets/github.svg +3 -0
- package/src/stories/assets/share.png +0 -0
- package/src/stories/assets/styling.png +0 -0
- package/src/stories/assets/testing.png +0 -0
- package/src/stories/assets/theming.png +0 -0
- package/src/stories/assets/tutorials.svg +12 -0
- package/src/stories/assets/youtube.svg +4 -0
- package/src/stories/attributes.stories.ts +132 -0
- package/src/stories/attributes.test.ts +14 -0
- package/src/stories/css.stories.ts +104 -0
- package/src/stories/css.test.ts +12 -0
- package/src/stories/dom-merge.stories.ts +113 -0
- package/src/stories/dom-merge.test.ts +12 -0
- package/src/stories/external-template.stories.ts +245 -0
- package/src/stories/external-template.test.ts +12 -0
- package/src/stories/http-request.stories.ts +244 -0
- package/src/stories/http-request.test.ts +29 -0
- package/src/stories/local-storage.stories.ts +388 -0
- package/src/stories/local-storage.test.ts +12 -0
- package/src/stories/location-element.stories.ts +133 -0
- package/src/stories/location-element.test.ts +14 -0
- package/src/stories/renderPlay.ts +22 -0
- package/src/stories/slice-events.stories.ts +117 -0
- package/src/stories/slice-events.test.ts +12 -0
- package/src/sum.test.ts +6 -0
- package/src/sum.ts +4 -0
- package/src/vite-env.d.ts +1 -0
- package/storybook-static/assets/Color-RQJUDNI5-C4yZhNbM.js +1 -0
- package/storybook-static/assets/Configure-C7d36rng.js +173 -0
- package/storybook-static/assets/DocsRenderer-K4EAMTCU-BLMupvSb.js +2 -0
- package/storybook-static/assets/WithTooltip-Y7J54OF7-BAQSPSFk.js +1 -0
- package/storybook-static/assets/accessibility-W_h2acOZ.png +0 -0
- package/storybook-static/assets/addon-library-BWUCAmyN.png +0 -0
- package/storybook-static/assets/attributes.stories-ZB0RTY1d.js +151 -0
- package/storybook-static/assets/context-C0qIqeS4.png +0 -0
- package/storybook-static/assets/css.stories-CLSX-Xxd.js +86 -0
- package/storybook-static/assets/custom-element-BLZZ00dz.js +53 -0
- package/storybook-static/assets/docs---vsFbMi.png +0 -0
- package/storybook-static/assets/dom-merge.stories-CgHZUABU.js +138 -0
- package/storybook-static/assets/entry-preview-CQqNFx4W.js +8 -0
- package/storybook-static/assets/entry-preview-docs-CWgqLfd3.js +2 -0
- package/storybook-static/assets/external-template.stories-DtSLMxvg.js +316 -0
- package/storybook-static/assets/figma-plugin-CH2hELiO.png +0 -0
- package/storybook-static/assets/formatter-B5HCVTEV-tKeEfJA9.js +58 -0
- package/storybook-static/assets/http-request.stories-CUzlXO89.js +300 -0
- package/storybook-static/assets/iframe-gCvlWuoC.js +2 -0
- package/storybook-static/assets/index-CBQwM6ST.js +508 -0
- package/storybook-static/assets/index-CDavW7r9.js +193 -0
- package/storybook-static/assets/index-CQA5dlr6.js +13 -0
- package/storybook-static/assets/index-Cc7K62zD.js +3 -0
- package/storybook-static/assets/index-DgaNIR0t.js +1 -0
- package/storybook-static/assets/index-Dkj0J1ds.js +1 -0
- package/storybook-static/assets/index-DnEJ_bKa.js +1 -0
- package/storybook-static/assets/index-DrFu-skq.js +6 -0
- package/storybook-static/assets/lit-element-B4_0akdT.js +19 -0
- package/storybook-static/assets/local-storage.stories-BkO6djDz.js +415 -0
- package/storybook-static/assets/location-element.stories-DCIOUd0D.js +108 -0
- package/storybook-static/assets/preview-B4GcaC1c.js +1 -0
- package/storybook-static/assets/preview-B63p-W8V.js +20 -0
- package/storybook-static/assets/preview-BAz7FMXc.js +396 -0
- package/storybook-static/assets/preview-BDY5ThwJ.js +1 -0
- package/storybook-static/assets/preview-C6t8KBFr.js +1 -0
- package/storybook-static/assets/preview-CYD85dwb.js +7 -0
- package/storybook-static/assets/preview-CkgAD_DE.js +2 -0
- package/storybook-static/assets/preview-D8LadFCz.js +48 -0
- package/storybook-static/assets/preview-DNpCpRPf.js +1 -0
- package/storybook-static/assets/preview-PxUn-cIn.js +1 -0
- package/storybook-static/assets/share-DGA-UcQf.png +0 -0
- package/storybook-static/assets/slice-events.stories-DXKjXI37.js +115 -0
- package/storybook-static/assets/styling-Bk6zjRzU.png +0 -0
- package/storybook-static/assets/syntaxhighlighter-JOJW2KGS-C04pIVD3.js +1 -0
- package/storybook-static/assets/testing-cbzR9l9r.png +0 -0
- package/storybook-static/assets/theming-D6WJLNoW.png +0 -0
- package/storybook-static/assets/tiny-invariant-BxWVcicq.js +1 -0
- package/storybook-static/confused.svg +37 -0
- package/storybook-static/embed-1.html +3 -0
- package/storybook-static/favicon.svg +7 -0
- package/storybook-static/html-template.html +126 -0
- package/storybook-static/html-template.xhtml +45 -0
- package/storybook-static/html-template.xml +45 -0
- package/storybook-static/iframe.html +492 -0
- package/storybook-static/index.html +163 -0
- package/storybook-static/index.json +1 -0
- package/storybook-static/mockServiceWorker.js +284 -0
- package/storybook-static/project.json +1 -0
- package/storybook-static/sb-addons/chromatic-com-storybook-9/manager-bundle.js +327 -0
- package/storybook-static/sb-addons/chromatic-com-storybook-9/manager-bundle.js.LEGAL.txt +40 -0
- package/storybook-static/sb-addons/essentials-actions-3/manager-bundle.js +3 -0
- package/storybook-static/sb-addons/essentials-actions-3/manager-bundle.js.LEGAL.txt +0 -0
- package/storybook-static/sb-addons/essentials-backgrounds-4/manager-bundle.js +12 -0
- package/storybook-static/sb-addons/essentials-backgrounds-4/manager-bundle.js.LEGAL.txt +0 -0
- package/storybook-static/sb-addons/essentials-controls-2/manager-bundle.js +60 -0
- package/storybook-static/sb-addons/essentials-controls-2/manager-bundle.js.LEGAL.txt +18 -0
- package/storybook-static/sb-addons/essentials-measure-7/manager-bundle.js +3 -0
- package/storybook-static/sb-addons/essentials-measure-7/manager-bundle.js.LEGAL.txt +0 -0
- package/storybook-static/sb-addons/essentials-outline-8/manager-bundle.js +3 -0
- package/storybook-static/sb-addons/essentials-outline-8/manager-bundle.js.LEGAL.txt +0 -0
- package/storybook-static/sb-addons/essentials-toolbars-6/manager-bundle.js +3 -0
- package/storybook-static/sb-addons/essentials-toolbars-6/manager-bundle.js.LEGAL.txt +0 -0
- package/storybook-static/sb-addons/essentials-viewport-5/manager-bundle.js +3 -0
- package/storybook-static/sb-addons/essentials-viewport-5/manager-bundle.js.LEGAL.txt +0 -0
- package/storybook-static/sb-addons/interactions-10/manager-bundle.js +33 -0
- package/storybook-static/sb-addons/interactions-10/manager-bundle.js.LEGAL.txt +0 -0
- package/storybook-static/sb-addons/links-1/manager-bundle.js +3 -0
- package/storybook-static/sb-addons/links-1/manager-bundle.js.LEGAL.txt +0 -0
- package/storybook-static/sb-addons/storybook-core-server-presets-0/common-manager-bundle.js +3 -0
- package/storybook-static/sb-addons/storybook-core-server-presets-0/common-manager-bundle.js.LEGAL.txt +0 -0
- package/storybook-static/sb-common-assets/fonts.css +31 -0
- package/storybook-static/sb-common-assets/nunito-sans-bold-italic.woff2 +0 -0
- package/storybook-static/sb-common-assets/nunito-sans-bold.woff2 +0 -0
- package/storybook-static/sb-common-assets/nunito-sans-italic.woff2 +0 -0
- package/storybook-static/sb-common-assets/nunito-sans-regular.woff2 +0 -0
- package/storybook-static/sb-manager/WithTooltip-Y7J54OF7-CEHQ77YF.js +1 -0
- package/storybook-static/sb-manager/chunk-E3WK6ZOZ.js +234 -0
- package/storybook-static/sb-manager/chunk-E6ABNH5R.js +183 -0
- package/storybook-static/sb-manager/chunk-FEE35O7J.js +9 -0
- package/storybook-static/sb-manager/chunk-S4VOIVUE.js +347 -0
- package/storybook-static/sb-manager/chunk-XCO5HRLK.js +6 -0
- package/storybook-static/sb-manager/chunk-XP3HGWTR.js +1 -0
- package/storybook-static/sb-manager/formatter-B5HCVTEV-7DCBOGO6.js +58 -0
- package/storybook-static/sb-manager/globals-module-info.js +1 -0
- package/storybook-static/sb-manager/globals-runtime.js +1 -0
- package/storybook-static/sb-manager/globals.js +1 -0
- package/storybook-static/sb-manager/index.js +1 -0
- package/storybook-static/sb-manager/runtime.js +1 -0
- package/storybook-static/sb-manager/syntaxhighlighter-JOJW2KGS-VF6EEVPI.js +1 -0
- package/storybook-static/sb-preview/globals.js +1 -0
- package/storybook-static/sb-preview/runtime.js +139 -0
- package/storybook-static/tree.xsl +33 -0
- package/storybook-static/vite.svg +1 -0
- package/tsconfig.json +25 -0
- package/vite.config.js +55 -0
|
@@ -0,0 +1,415 @@
|
|
|
1
|
+
import{w as x,e as o}from"./index-CDavW7r9.js";import"./custom-element-BLZZ00dz.js";const p=(l,t)=>{if(l==="text")return t;if(l==="json")try{return JSON.parse(t)}catch{return null}const a=document.createElement("input");return a.setAttribute("type",l),l==="number"?(a.value=t,a.valueAsNumber):l==="date"?t?(a.valueAsDate=new Date(t),a.value):null:(a.value=t,a.value)};let b,v,g;function w(){b||(b=localStorage.setItem,localStorage.setItem=function(l,t,...a){b.apply(this,[l,t,...a]),window.dispatchEvent(new CustomEvent("local-storage",{detail:{key:l,value:t}}))},v=localStorage.removeItem,localStorage.removeItem=function(l,...t){v.apply(this,[l,...t]),window.dispatchEvent(new CustomEvent("local-storage",{detail:{key:l}}))},g=localStorage.clear,localStorage.clear=function(...l){g.apply(this,[...l]),window.dispatchEvent(new CustomEvent("local-storage",{detail:{}}))})}function I(l,t){localStorage.setItem(l,t),window.dispatchEvent(new CustomEvent("local-storage",{detail:{key:l,value:t}}))}class T extends HTMLElement{static observedAttributes=["value","slice","key","type","live"];#e;get value(){return this.#e===null?void 0:this.#e}set value(t){return this.#e=t}async connectedCallback(){const t=c=>this.getAttribute(c),a=()=>{this.#e=p(t("type"),localStorage.getItem(t("key"))),this.dispatchEvent(new Event("change"))};if(this.#e=p(t("type"),localStorage.getItem(t("key"))),this.hasAttribute("value")?I(t("key"),this.#e=t("value")):a(),this.hasAttribute("live")){const c=e=>(e.detail.key===t("key")||!e.detail.key)&&a();window.addEventListener("local-storage",c),w(),this._destroy=()=>window.removeEventListener("local-storage",c)}}disconnectedCallback(){this._destroy?.()}}window.customElements.define("local-storage",T);const s={title:"",slice:"ls-slice",key:"sb-ls-key",value:"",live:"",body:""};function n(l){return new Promise(t=>setTimeout(t,l))}function V(l){const{title:t,slice:a,key:c,value:e,live:i,body:y}={...s,...l};return`
|
|
2
|
+
<fieldset>
|
|
3
|
+
<legend>${t}</legend>
|
|
4
|
+
|
|
5
|
+
<custom-element>
|
|
6
|
+
<template><!-- wrapping into template to prevent images loading within DCE declaration -->
|
|
7
|
+
<local-storage
|
|
8
|
+
key="${c}"
|
|
9
|
+
slice="${a}"
|
|
10
|
+
${i?`live="${i}"`:""}
|
|
11
|
+
${e?`value="${e}"`:""}
|
|
12
|
+
></local-storage>
|
|
13
|
+
|
|
14
|
+
<br/>
|
|
15
|
+
<var>${c}</var>:<code data-testid="slice-value">{ //slice/${a} }</code>
|
|
16
|
+
<br/>
|
|
17
|
+
${y}
|
|
18
|
+
</template>
|
|
19
|
+
</custom-element>
|
|
20
|
+
</fieldset>
|
|
21
|
+
`}const E={title:"local-storage",render:V},u={args:{title:"live value",live:"live",body:`
|
|
22
|
+
<input placeholder="value for localStorage" id="textinput"
|
|
23
|
+
slice="${s.slice}"
|
|
24
|
+
value="{ //${s.slice} ?? '${s.value}' }"/>
|
|
25
|
+
<button onclick="localStorage.setItem('${s.key}',textinput.value )">set</button>
|
|
26
|
+
<button onclick="localStorage.setItem('${s.key}','text value' )">text value</button>
|
|
27
|
+
<button onclick="localStorage.setItem('${s.key}','another text')">another text</button>
|
|
28
|
+
<button onclick="localStorage.removeItem('${s.key}' )">set blank</button>
|
|
29
|
+
`},play:async({canvasElement:l})=>{const t=x(l);await t.findByText(u.args.title);const a=()=>t.getByTestId("slice-value").textContent,c=e=>t.getByText(e);c("set blank").click(),o(localStorage.getItem(s.key)).toEqual(null,"from localStorage"),o(a()).toEqual(""),c("text value").click(),await n(10),o(a()).toEqual("text value"),window.textinput.value="textinput.value",c("set").click(),await n(10),o(a()).toEqual("textinput.value"),c("another text").click(),await n(10),o(a()).toEqual("another text"),c("set blank").click(),await n(10),o(a()).toEqual("")}},k={args:{title:"AlwaysOverride",live:"",value:"ABC",body:`
|
|
30
|
+
buttons are changing the localStorage value, but without 'live' attribute slice ^^ from <i>local-storage</i> is not updated<br/>
|
|
31
|
+
<button onclick="localStorage.setItem('${s.key}','text value' )">text value</button>
|
|
32
|
+
<button onclick="localStorage.removeItem('${s.key}' )">set blank</button>
|
|
33
|
+
`},play:async({canvasElement:l})=>{const t=x(l);await t.findByText(k.args.title);const a=()=>t.getByTestId("slice-value").textContent,c=e=>t.getByText(e);o(localStorage.getItem(s.key)).toEqual("ABC","from localStorage"),c("set blank").click(),o(localStorage.getItem(s.key)).toEqual(null,"from localStorage"),await n(10),o(a()).toEqual("ABC"),c("text value").click(),await n(10),o(localStorage.getItem(s.key)).toEqual("text value","from localStorage"),o(a()).toEqual("ABC"),c("set blank").click(),await n(10),o(a()).toEqual("ABC")}},m={args:{title:"live value with defaults",live:"",value:"ABC",body:`
|
|
34
|
+
|
|
35
|
+
<local-storage key="attr2Key" slice="attr2-key" type="text" live="live" slice-value="@value ?? 'DEF2'"></local-storage>
|
|
36
|
+
<button onclick="localStorage.removeItem('attr2Key')">clear key</button>
|
|
37
|
+
<button onclick="localStorage.setItem('attr2Key','attr2Key value')">update attr2-key value</button>
|
|
38
|
+
//attr2-key: <code data-testid="key2-value">{//attr2-key}</code><br/>
|
|
39
|
+
|
|
40
|
+
<local-storage key="attr3Key" slice="attr3-key" type="text" live="live" slice-value="@value ?? 'DEF3'"></local-storage>
|
|
41
|
+
<button onclick="localStorage.removeItem('attr3Key')">clear attr3-key key</button>
|
|
42
|
+
<button onclick="localStorage.setItem('attr3Key','attr3Key value')">update attr3-key value</button>
|
|
43
|
+
//attr3-key: <code data-testid="key3-value">{//attr3-key}</code><br/>
|
|
44
|
+
<button onclick="localStorage.clear()">clear localStorage</button>
|
|
45
|
+
`},play:async({canvasElement:l})=>{const t=x(l);await t.findByText(m.args.title);const a=c=>t.getByText(c);o(localStorage.getItem(s.key)).toEqual("ABC","from localStorage"),a("clear localStorage").click(),o(t.getByTestId("slice-value").textContent).toEqual("ABC"),o(t.getByTestId("key2-value").textContent).toEqual("DEF2"),o(t.getByTestId("key3-value").textContent).toEqual("DEF3"),a("update attr2-key value").click(),o(localStorage.getItem("attr2Key")).toEqual("attr2Key value","from localStorage"),await n(10),o(t.getByTestId("slice-value").textContent).toEqual("ABC"),o(t.getByTestId("key2-value").textContent).toEqual("attr2Key value"),o(t.getByTestId("key3-value").textContent).toEqual("DEF3"),a("update attr3-key value").click(),o(localStorage.getItem("attr3Key")).toEqual("attr3Key value","from localStorage"),await n(10),o(t.getByTestId("slice-value").textContent).toEqual("ABC"),o(t.getByTestId("key2-value").textContent).toEqual("attr2Key value"),o(t.getByTestId("key3-value").textContent).toEqual("attr3Key value")}},d={args:{title:"local-storage type attribute variations",body:`
|
|
46
|
+
|
|
47
|
+
<local-storage key="textKey" slice="text-key" type="text" live="live"></local-storage>
|
|
48
|
+
<local-storage key="dateKey" slice="date-key" type="date" live="live"></local-storage>
|
|
49
|
+
<local-storage key="timeKey" slice="time-key" type="time" live="live"></local-storage>
|
|
50
|
+
<local-storage key="localDateTimeKey" slice="local-date-time" type="datetime-local" live="live"></local-storage>
|
|
51
|
+
<local-storage key="numberKey" slice="number-key" type="number" live="live"></local-storage>
|
|
52
|
+
<local-storage key="jsonKey" slice="json-key" type="json" live="live"></local-storage>
|
|
53
|
+
<input id="typesinput" placeholder="set value"><button onclick="
|
|
54
|
+
'textKey,dateKey,timeKey,localDateTimeKey,numberKey,jsonKey'.split(',')
|
|
55
|
+
.map( k=> localStorage.setItem(k, typesinput.value) )
|
|
56
|
+
"> set to all</button><br>
|
|
57
|
+
<hr>
|
|
58
|
+
text-key:
|
|
59
|
+
<button onclick="localStorage.setItem('textKey', 'ABC' )">ABC</button>
|
|
60
|
+
<code data-testid="text-key">{//text-key }</code><br>
|
|
61
|
+
date-key:
|
|
62
|
+
<button onclick="localStorage.setItem('dateKey', '2024-04-20T03:58:42.131Z')">2024-04-21T03:58:42.131Z </button>
|
|
63
|
+
<button onclick="localStorage.setItem('dateKey', new Date(Date.now()).toISOString())">now </button>
|
|
64
|
+
<button onclick="localStorage.setItem('dateKey', 'ABC' )">date ABC - invalid </button>
|
|
65
|
+
<code data-testid="date-key">{//date-key }</code><br>
|
|
66
|
+
time-key:
|
|
67
|
+
<button onclick="localStorage.setItem('timeKey', '13:30')">13:30 </button>
|
|
68
|
+
<code data-testid="time-key">{//time-key }</code><br>
|
|
69
|
+
local-date-time:
|
|
70
|
+
<button onclick="localStorage.setItem('localDateTimeKey', '1977-04-01T14:00:30')">1977-04-01T14:00:30 - local </button>
|
|
71
|
+
<code data-testid="local-date-time">{//local-date-time}</code><br>
|
|
72
|
+
number-key:
|
|
73
|
+
<button onclick="localStorage.setItem('numberKey', '2024' )">2024 - number </button>
|
|
74
|
+
<button onclick="localStorage.setItem('numberKey', '24' )">24 - number </button>
|
|
75
|
+
<button onclick="localStorage.setItem('numberKey', '1.23456e+5' )">1.23456e+5 </button>
|
|
76
|
+
<button onclick="localStorage.setItem('numberKey', '0001' )">0001 </button>
|
|
77
|
+
<button onclick="localStorage.setItem('numberKey', '000' )">000 </button>
|
|
78
|
+
<button onclick="localStorage.setItem('numberKey', '0' )">0 </button>
|
|
79
|
+
<button onclick="localStorage.setItem('numberKey', 'ABC' )">ABC - invalid, NaN </button>
|
|
80
|
+
<code data-testid="number-key">{//number-key }</code> <br>
|
|
81
|
+
<fieldset>
|
|
82
|
+
<legend>json-key: </legend>
|
|
83
|
+
|
|
84
|
+
<button onclick="localStorage.setItem('jsonKey', JSON.stringify('ABC'))">'ABC' - string </button>
|
|
85
|
+
<button onclick="localStorage.setItem('jsonKey', JSON.stringify(12.345))">12.345 - number </button>
|
|
86
|
+
<button onclick="localStorage.setItem('jsonKey', JSON.stringify(window.JsonSample) )">a:1,b:'B' -json </button>
|
|
87
|
+
<button onclick="localStorage.setItem('jsonKey', 'ABC' )">ABC - invalid </button><br>
|
|
88
|
+
json-key:<code data-testid="json-key"><xsl:apply-templates select="//json-key/value/@*|//json-key/text()|//json-key/value/text()" mode="json"></xsl:apply-templates></code>
|
|
89
|
+
</fieldset>
|
|
90
|
+
<xsl:template mode="json" match="*|@*">
|
|
91
|
+
<div>{name()} : {.}</div>
|
|
92
|
+
</xsl:template>
|
|
93
|
+
`},play:async({canvasElement:l})=>{const t=x(l);await t.findByText(d.args.title);const a=r=>t.getByText(r),c=r=>t.getByTestId(r).textContent,e=(r,S)=>{o(c(r)).toEqual(S,r)};localStorage.clear(),await n(10),e("text-key",""),e("date-key",""),e("time-key",""),e("local-date-time",""),e("number-key","NaN"),e("json-key","");const i=l.querySelector("input");i.value="ABC",a("set to all").click(),await n(10),e("text-key","ABC"),e("date-key",""),e("time-key",""),e("local-date-time",""),e("number-key","NaN"),e("json-key",""),i.value="22",a("set to all").click(),await n(10),e("text-key","22"),e("date-key",""),e("time-key",""),e("local-date-time",""),e("number-key","22"),e("json-key","22"),i.value="2024",a("set to all").click(),await n(10),e("text-key","2024"),e("date-key","2024-01-01"),e("time-key",""),e("local-date-time",""),e("number-key","2024"),e("json-key","2024"),i.value="2024-04-20T03:58:42.131Z",a("set to all").click(),await n(10),e("text-key","2024-04-20T03:58:42.131Z"),e("date-key","2024-04-20"),e("time-key",""),e("local-date-time",""),e("number-key","NaN"),e("json-key","");const y=new Date(Date.now()).toISOString();i.value=y,a("set to all").click(),await n(10),e("text-key",y),e("date-key",y.substring(0,10)),e("time-key",""),e("local-date-time",""),e("number-key","NaN"),e("json-key",""),i.value="23:25",a("set to all").click(),await n(10),e("text-key","23:25"),e("date-key",""),e("time-key","23:25"),e("local-date-time",""),e("number-key","NaN"),e("json-key",""),i.value="1977-04-01T14:00:30",a("set to all").click(),await n(10),e("text-key","1977-04-01T14:00:30"),e("date-key","1977-04-01"),e("time-key",""),e("local-date-time","1977-04-01T14:00:30"),e("number-key","NaN"),e("json-key",""),i.value="1.23456e+5",a("set to all").click(),await n(10),e("text-key","1.23456e+5"),e("date-key",""),e("time-key",""),e("local-date-time",""),e("number-key","123456"),e("json-key","123456"),i.value="0001",a("set to all").click(),await n(10),e("text-key","0001"),e("date-key","0001-01-01"),e("time-key",""),e("local-date-time",""),e("number-key","1"),e("json-key",""),i.value="001",a("set to all").click(),await n(10),e("text-key","001"),e("date-key","2001-01-01"),e("time-key",""),e("local-date-time",""),e("number-key","1"),e("json-key",""),i.value="000",a("set to all").click(),await n(10),e("text-key","000"),e("date-key","2000-01-01"),e("time-key",""),e("local-date-time",""),e("number-key","0"),e("json-key",""),i.value="0",a("set to all").click(),await n(10),e("text-key","0"),e("date-key","2000-01-01"),e("time-key",""),e("local-date-time",""),e("number-key","0"),e("json-key","0"),i.value='"abc"',a("set to all").click(),await n(10),e("text-key",'"abc"'),e("date-key",""),e("time-key",""),e("local-date-time",""),e("number-key","NaN"),e("json-key","abc"),i.value="12.345",a("set to all").click(),await n(10),e("text-key","12.345"),e("date-key",""),e("time-key",""),e("local-date-time",""),e("number-key","12.345"),e("json-key","12.345"),i.value='{"a":1,"b":"B"}',a("set to all").click(),await n(10),e("text-key",'{"a":1,"b":"B"}'),e("date-key",""),e("time-key",""),e("local-date-time",""),e("number-key","NaN"),e("json-key",`
|
|
94
|
+
a : 1b : B`)}};u.parameters={...u.parameters,docs:{...u.parameters?.docs,source:{originalSource:`{
|
|
95
|
+
args: {
|
|
96
|
+
title: 'live value',
|
|
97
|
+
live: 'live',
|
|
98
|
+
body: \`
|
|
99
|
+
<input placeholder="value for localStorage" id="textinput"
|
|
100
|
+
slice="\${defs.slice}"
|
|
101
|
+
value="{ //\${defs.slice} ?? '\${defs.value}' }"/>
|
|
102
|
+
<button onclick="localStorage.setItem('\${defs.key}',textinput.value )">set</button>
|
|
103
|
+
<button onclick="localStorage.setItem('\${defs.key}','text value' )">text value</button>
|
|
104
|
+
<button onclick="localStorage.setItem('\${defs.key}','another text')">another text</button>
|
|
105
|
+
<button onclick="localStorage.removeItem('\${defs.key}' )">set blank</button>
|
|
106
|
+
\`
|
|
107
|
+
},
|
|
108
|
+
play: async ({
|
|
109
|
+
canvasElement
|
|
110
|
+
}) => {
|
|
111
|
+
const canvas = within(canvasElement);
|
|
112
|
+
await canvas.findByText((Demo.args!.title as string));
|
|
113
|
+
const val = () => canvas.getByTestId('slice-value').textContent,
|
|
114
|
+
byText = txt => canvas.getByText(txt);
|
|
115
|
+
byText('set blank').click();
|
|
116
|
+
expect(localStorage.getItem(defs.key)).toEqual(null, 'from localStorage');
|
|
117
|
+
expect(val()).toEqual('');
|
|
118
|
+
byText('text value').click();
|
|
119
|
+
await sleep(10);
|
|
120
|
+
expect(val()).toEqual('text value');
|
|
121
|
+
window['textinput'].value = 'textinput.value';
|
|
122
|
+
byText('set').click();
|
|
123
|
+
await sleep(10);
|
|
124
|
+
expect(val()).toEqual('textinput.value');
|
|
125
|
+
byText('another text').click();
|
|
126
|
+
await sleep(10);
|
|
127
|
+
expect(val()).toEqual('another text');
|
|
128
|
+
byText('set blank').click();
|
|
129
|
+
await sleep(10);
|
|
130
|
+
expect(val()).toEqual('');
|
|
131
|
+
}
|
|
132
|
+
}`,...u.parameters?.docs?.source}}};k.parameters={...k.parameters,docs:{...k.parameters?.docs,source:{originalSource:`{
|
|
133
|
+
args: {
|
|
134
|
+
title: 'AlwaysOverride',
|
|
135
|
+
live: '',
|
|
136
|
+
value: 'ABC',
|
|
137
|
+
body: \`
|
|
138
|
+
buttons are changing the localStorage value, but without 'live' attribute slice ^^ from <i>local-storage</i> is not updated<br/>
|
|
139
|
+
<button onclick="localStorage.setItem('\${defs.key}','text value' )">text value</button>
|
|
140
|
+
<button onclick="localStorage.removeItem('\${defs.key}' )">set blank</button>
|
|
141
|
+
\`
|
|
142
|
+
},
|
|
143
|
+
play: async ({
|
|
144
|
+
canvasElement
|
|
145
|
+
}) => {
|
|
146
|
+
const canvas = within(canvasElement);
|
|
147
|
+
await canvas.findByText((AlwaysOverride.args!.title as string));
|
|
148
|
+
const val = () => canvas.getByTestId('slice-value').textContent,
|
|
149
|
+
byText = txt => canvas.getByText(txt);
|
|
150
|
+
expect(localStorage.getItem(defs.key)).toEqual('ABC', 'from localStorage');
|
|
151
|
+
byText('set blank').click();
|
|
152
|
+
expect(localStorage.getItem(defs.key)).toEqual(null, 'from localStorage');
|
|
153
|
+
await sleep(10);
|
|
154
|
+
expect(val()).toEqual('ABC');
|
|
155
|
+
byText('text value').click();
|
|
156
|
+
await sleep(10);
|
|
157
|
+
expect(localStorage.getItem(defs.key)).toEqual('text value', 'from localStorage');
|
|
158
|
+
expect(val()).toEqual('ABC');
|
|
159
|
+
byText('set blank').click();
|
|
160
|
+
await sleep(10);
|
|
161
|
+
expect(val()).toEqual('ABC');
|
|
162
|
+
}
|
|
163
|
+
}`,...k.parameters?.docs?.source}}};m.parameters={...m.parameters,docs:{...m.parameters?.docs,source:{originalSource:`{
|
|
164
|
+
args: {
|
|
165
|
+
title: 'live value with defaults',
|
|
166
|
+
live: '',
|
|
167
|
+
value: 'ABC',
|
|
168
|
+
body: \`
|
|
169
|
+
|
|
170
|
+
<local-storage key="attr2Key" slice="attr2-key" type="text" live="live" slice-value="@value ?? 'DEF2'"></local-storage>
|
|
171
|
+
<button onclick="localStorage.removeItem('attr2Key')">clear key</button>
|
|
172
|
+
<button onclick="localStorage.setItem('attr2Key','attr2Key value')">update attr2-key value</button>
|
|
173
|
+
//attr2-key: <code data-testid="key2-value">{//attr2-key}</code><br/>
|
|
174
|
+
|
|
175
|
+
<local-storage key="attr3Key" slice="attr3-key" type="text" live="live" slice-value="@value ?? 'DEF3'"></local-storage>
|
|
176
|
+
<button onclick="localStorage.removeItem('attr3Key')">clear attr3-key key</button>
|
|
177
|
+
<button onclick="localStorage.setItem('attr3Key','attr3Key value')">update attr3-key value</button>
|
|
178
|
+
//attr3-key: <code data-testid="key3-value">{//attr3-key}</code><br/>
|
|
179
|
+
<button onclick="localStorage.clear()">clear localStorage</button>
|
|
180
|
+
\`
|
|
181
|
+
},
|
|
182
|
+
play: async ({
|
|
183
|
+
canvasElement
|
|
184
|
+
}) => {
|
|
185
|
+
const canvas = within(canvasElement);
|
|
186
|
+
await canvas.findByText((FromStorageWithDefault.args!.title as string));
|
|
187
|
+
const byText = txt => canvas.getByText(txt);
|
|
188
|
+
expect(localStorage.getItem(defs.key)).toEqual('ABC', 'from localStorage');
|
|
189
|
+
byText('clear localStorage').click();
|
|
190
|
+
expect(canvas.getByTestId('slice-value').textContent).toEqual('ABC');
|
|
191
|
+
expect(canvas.getByTestId('key2-value').textContent).toEqual('DEF2');
|
|
192
|
+
expect(canvas.getByTestId('key3-value').textContent).toEqual('DEF3');
|
|
193
|
+
byText('update attr2-key value').click();
|
|
194
|
+
expect(localStorage.getItem('attr2Key')).toEqual('attr2Key value', 'from localStorage');
|
|
195
|
+
await sleep(10);
|
|
196
|
+
expect(canvas.getByTestId('slice-value').textContent).toEqual('ABC');
|
|
197
|
+
expect(canvas.getByTestId('key2-value').textContent).toEqual('attr2Key value');
|
|
198
|
+
expect(canvas.getByTestId('key3-value').textContent).toEqual('DEF3');
|
|
199
|
+
byText('update attr3-key value').click();
|
|
200
|
+
expect(localStorage.getItem('attr3Key')).toEqual('attr3Key value', 'from localStorage');
|
|
201
|
+
await sleep(10);
|
|
202
|
+
expect(canvas.getByTestId('slice-value').textContent).toEqual('ABC');
|
|
203
|
+
expect(canvas.getByTestId('key2-value').textContent).toEqual('attr2Key value');
|
|
204
|
+
expect(canvas.getByTestId('key3-value').textContent).toEqual('attr3Key value');
|
|
205
|
+
}
|
|
206
|
+
}`,...m.parameters?.docs?.source}}};d.parameters={...d.parameters,docs:{...d.parameters?.docs,source:{originalSource:`{
|
|
207
|
+
args: {
|
|
208
|
+
title: 'local-storage type attribute variations',
|
|
209
|
+
body: \`
|
|
210
|
+
|
|
211
|
+
<local-storage key="textKey" slice="text-key" type="text" live="live"></local-storage>
|
|
212
|
+
<local-storage key="dateKey" slice="date-key" type="date" live="live"></local-storage>
|
|
213
|
+
<local-storage key="timeKey" slice="time-key" type="time" live="live"></local-storage>
|
|
214
|
+
<local-storage key="localDateTimeKey" slice="local-date-time" type="datetime-local" live="live"></local-storage>
|
|
215
|
+
<local-storage key="numberKey" slice="number-key" type="number" live="live"></local-storage>
|
|
216
|
+
<local-storage key="jsonKey" slice="json-key" type="json" live="live"></local-storage>
|
|
217
|
+
<input id="typesinput" placeholder="set value"><button onclick="
|
|
218
|
+
'textKey,dateKey,timeKey,localDateTimeKey,numberKey,jsonKey'.split(',')
|
|
219
|
+
.map( k=> localStorage.setItem(k, typesinput.value) )
|
|
220
|
+
"> set to all</button><br>
|
|
221
|
+
<hr>
|
|
222
|
+
text-key:
|
|
223
|
+
<button onclick="localStorage.setItem('textKey', 'ABC' )">ABC</button>
|
|
224
|
+
<code data-testid="text-key">{//text-key }</code><br>
|
|
225
|
+
date-key:
|
|
226
|
+
<button onclick="localStorage.setItem('dateKey', '2024-04-20T03:58:42.131Z')">2024-04-21T03:58:42.131Z </button>
|
|
227
|
+
<button onclick="localStorage.setItem('dateKey', new Date(Date.now()).toISOString())">now </button>
|
|
228
|
+
<button onclick="localStorage.setItem('dateKey', 'ABC' )">date ABC - invalid </button>
|
|
229
|
+
<code data-testid="date-key">{//date-key }</code><br>
|
|
230
|
+
time-key:
|
|
231
|
+
<button onclick="localStorage.setItem('timeKey', '13:30')">13:30 </button>
|
|
232
|
+
<code data-testid="time-key">{//time-key }</code><br>
|
|
233
|
+
local-date-time:
|
|
234
|
+
<button onclick="localStorage.setItem('localDateTimeKey', '1977-04-01T14:00:30')">1977-04-01T14:00:30 - local </button>
|
|
235
|
+
<code data-testid="local-date-time">{//local-date-time}</code><br>
|
|
236
|
+
number-key:
|
|
237
|
+
<button onclick="localStorage.setItem('numberKey', '2024' )">2024 - number </button>
|
|
238
|
+
<button onclick="localStorage.setItem('numberKey', '24' )">24 - number </button>
|
|
239
|
+
<button onclick="localStorage.setItem('numberKey', '1.23456e+5' )">1.23456e+5 </button>
|
|
240
|
+
<button onclick="localStorage.setItem('numberKey', '0001' )">0001 </button>
|
|
241
|
+
<button onclick="localStorage.setItem('numberKey', '000' )">000 </button>
|
|
242
|
+
<button onclick="localStorage.setItem('numberKey', '0' )">0 </button>
|
|
243
|
+
<button onclick="localStorage.setItem('numberKey', 'ABC' )">ABC - invalid, NaN </button>
|
|
244
|
+
<code data-testid="number-key">{//number-key }</code> <br>
|
|
245
|
+
<fieldset>
|
|
246
|
+
<legend>json-key: </legend>
|
|
247
|
+
|
|
248
|
+
<button onclick="localStorage.setItem('jsonKey', JSON.stringify('ABC'))">'ABC' - string </button>
|
|
249
|
+
<button onclick="localStorage.setItem('jsonKey', JSON.stringify(12.345))">12.345 - number </button>
|
|
250
|
+
<button onclick="localStorage.setItem('jsonKey', JSON.stringify(window.JsonSample) )">a:1,b:'B' -json </button>
|
|
251
|
+
<button onclick="localStorage.setItem('jsonKey', 'ABC' )">ABC - invalid </button><br>
|
|
252
|
+
json-key:<code data-testid="json-key"><xsl:apply-templates select="//json-key/value/@*|//json-key/text()|//json-key/value/text()" mode="json"></xsl:apply-templates></code>
|
|
253
|
+
</fieldset>
|
|
254
|
+
<xsl:template mode="json" match="*|@*">
|
|
255
|
+
<div>{name()} : {.}</div>
|
|
256
|
+
</xsl:template>
|
|
257
|
+
\`
|
|
258
|
+
},
|
|
259
|
+
play: async ({
|
|
260
|
+
canvasElement
|
|
261
|
+
}) => {
|
|
262
|
+
const canvas = within(canvasElement);
|
|
263
|
+
await canvas.findByText((TypeAttribute.args!.title as string));
|
|
264
|
+
const byText = txt => canvas.getByText(txt),
|
|
265
|
+
val = testId => canvas.getByTestId(testId).textContent,
|
|
266
|
+
expectVal = (key, value) => {
|
|
267
|
+
expect(val(key)).toEqual(value, key);
|
|
268
|
+
};
|
|
269
|
+
localStorage.clear(); // cleanup before test
|
|
270
|
+
await sleep(10);
|
|
271
|
+
expectVal('text-key', '');
|
|
272
|
+
expectVal('date-key', '');
|
|
273
|
+
expectVal('time-key', '');
|
|
274
|
+
expectVal('local-date-time', '');
|
|
275
|
+
expectVal('number-key', 'NaN');
|
|
276
|
+
expectVal('json-key', '');
|
|
277
|
+
const input = canvasElement.querySelector('input');
|
|
278
|
+
input.value = 'ABC';
|
|
279
|
+
byText('set to all').click();
|
|
280
|
+
await sleep(10);
|
|
281
|
+
expectVal('text-key', 'ABC');
|
|
282
|
+
expectVal('date-key', '');
|
|
283
|
+
expectVal('time-key', '');
|
|
284
|
+
expectVal('local-date-time', '');
|
|
285
|
+
expectVal('number-key', 'NaN');
|
|
286
|
+
expectVal('json-key', '');
|
|
287
|
+
input.value = '22';
|
|
288
|
+
byText('set to all').click();
|
|
289
|
+
await sleep(10);
|
|
290
|
+
expectVal('text-key', '22');
|
|
291
|
+
expectVal('date-key', '');
|
|
292
|
+
expectVal('time-key', '');
|
|
293
|
+
expectVal('local-date-time', '');
|
|
294
|
+
expectVal('number-key', '22');
|
|
295
|
+
expectVal('json-key', '22');
|
|
296
|
+
input.value = '2024';
|
|
297
|
+
byText('set to all').click();
|
|
298
|
+
await sleep(10);
|
|
299
|
+
expectVal('text-key', '2024');
|
|
300
|
+
expectVal('date-key', '2024-01-01');
|
|
301
|
+
expectVal('time-key', '');
|
|
302
|
+
expectVal('local-date-time', '');
|
|
303
|
+
expectVal('number-key', '2024');
|
|
304
|
+
expectVal('json-key', '2024');
|
|
305
|
+
input.value = '2024-04-20T03:58:42.131Z';
|
|
306
|
+
byText('set to all').click();
|
|
307
|
+
await sleep(10);
|
|
308
|
+
expectVal('text-key', '2024-04-20T03:58:42.131Z');
|
|
309
|
+
expectVal('date-key', '2024-04-20');
|
|
310
|
+
expectVal('time-key', '');
|
|
311
|
+
expectVal('local-date-time', '');
|
|
312
|
+
expectVal('number-key', 'NaN');
|
|
313
|
+
expectVal('json-key', '');
|
|
314
|
+
const nowStr = new Date(Date.now()).toISOString();
|
|
315
|
+
input.value = nowStr;
|
|
316
|
+
byText('set to all').click();
|
|
317
|
+
await sleep(10);
|
|
318
|
+
expectVal('text-key', nowStr);
|
|
319
|
+
expectVal('date-key', nowStr.substring(0, 10));
|
|
320
|
+
expectVal('time-key', '');
|
|
321
|
+
expectVal('local-date-time', '');
|
|
322
|
+
expectVal('number-key', 'NaN');
|
|
323
|
+
expectVal('json-key', '');
|
|
324
|
+
input.value = '23:25';
|
|
325
|
+
byText('set to all').click();
|
|
326
|
+
await sleep(10);
|
|
327
|
+
expectVal('text-key', '23:25');
|
|
328
|
+
expectVal('date-key', '');
|
|
329
|
+
expectVal('time-key', '23:25');
|
|
330
|
+
expectVal('local-date-time', '');
|
|
331
|
+
expectVal('number-key', 'NaN');
|
|
332
|
+
expectVal('json-key', '');
|
|
333
|
+
input.value = '1977-04-01T14:00:30';
|
|
334
|
+
byText('set to all').click();
|
|
335
|
+
await sleep(10);
|
|
336
|
+
expectVal('text-key', '1977-04-01T14:00:30');
|
|
337
|
+
expectVal('date-key', '1977-04-01');
|
|
338
|
+
expectVal('time-key', '');
|
|
339
|
+
expectVal('local-date-time', '1977-04-01T14:00:30');
|
|
340
|
+
expectVal('number-key', 'NaN');
|
|
341
|
+
expectVal('json-key', '');
|
|
342
|
+
input.value = '1.23456e+5';
|
|
343
|
+
byText('set to all').click();
|
|
344
|
+
await sleep(10);
|
|
345
|
+
expectVal('text-key', '1.23456e+5');
|
|
346
|
+
expectVal('date-key', '');
|
|
347
|
+
expectVal('time-key', '');
|
|
348
|
+
expectVal('local-date-time', '');
|
|
349
|
+
expectVal('number-key', '123456');
|
|
350
|
+
expectVal('json-key', '123456');
|
|
351
|
+
input.value = '0001'; // as YYYY for year
|
|
352
|
+
byText('set to all').click();
|
|
353
|
+
await sleep(10);
|
|
354
|
+
expectVal('text-key', '0001');
|
|
355
|
+
expectVal('date-key', '0001-01-01');
|
|
356
|
+
expectVal('time-key', '');
|
|
357
|
+
expectVal('local-date-time', '');
|
|
358
|
+
expectVal('number-key', '1');
|
|
359
|
+
expectVal('json-key', '');
|
|
360
|
+
input.value = '001'; // as 2001 year
|
|
361
|
+
byText('set to all').click();
|
|
362
|
+
await sleep(10);
|
|
363
|
+
expectVal('text-key', '001');
|
|
364
|
+
expectVal('date-key', '2001-01-01');
|
|
365
|
+
expectVal('time-key', '');
|
|
366
|
+
expectVal('local-date-time', '');
|
|
367
|
+
expectVal('number-key', '1');
|
|
368
|
+
expectVal('json-key', '');
|
|
369
|
+
input.value = '000'; // as 2001 year
|
|
370
|
+
byText('set to all').click();
|
|
371
|
+
await sleep(10);
|
|
372
|
+
expectVal('text-key', '000');
|
|
373
|
+
expectVal('date-key', '2000-01-01');
|
|
374
|
+
expectVal('time-key', '');
|
|
375
|
+
expectVal('local-date-time', '');
|
|
376
|
+
expectVal('number-key', '0');
|
|
377
|
+
expectVal('json-key', '');
|
|
378
|
+
input.value = '0'; // as 2000 year
|
|
379
|
+
byText('set to all').click();
|
|
380
|
+
await sleep(10);
|
|
381
|
+
expectVal('text-key', '0');
|
|
382
|
+
expectVal('date-key', '2000-01-01');
|
|
383
|
+
expectVal('time-key', '');
|
|
384
|
+
expectVal('local-date-time', '');
|
|
385
|
+
expectVal('number-key', '0');
|
|
386
|
+
expectVal('json-key', '0');
|
|
387
|
+
input.value = '"abc"';
|
|
388
|
+
byText('set to all').click();
|
|
389
|
+
await sleep(10);
|
|
390
|
+
expectVal('text-key', '"abc"');
|
|
391
|
+
expectVal('date-key', '');
|
|
392
|
+
expectVal('time-key', '');
|
|
393
|
+
expectVal('local-date-time', '');
|
|
394
|
+
expectVal('number-key', 'NaN');
|
|
395
|
+
expectVal('json-key', 'abc');
|
|
396
|
+
input.value = '12.345';
|
|
397
|
+
byText('set to all').click();
|
|
398
|
+
await sleep(10);
|
|
399
|
+
expectVal('text-key', '12.345');
|
|
400
|
+
expectVal('date-key', '');
|
|
401
|
+
expectVal('time-key', '');
|
|
402
|
+
expectVal('local-date-time', '');
|
|
403
|
+
expectVal('number-key', '12.345');
|
|
404
|
+
expectVal('json-key', '12.345');
|
|
405
|
+
input.value = '{"a":1,"b":"B"}';
|
|
406
|
+
byText('set to all').click();
|
|
407
|
+
await sleep(10);
|
|
408
|
+
expectVal('text-key', '{"a":1,"b":"B"}');
|
|
409
|
+
expectVal('date-key', '');
|
|
410
|
+
expectVal('time-key', '');
|
|
411
|
+
expectVal('local-date-time', '');
|
|
412
|
+
expectVal('number-key', 'NaN');
|
|
413
|
+
expectVal('json-key', '\\na : 1b : B');
|
|
414
|
+
}
|
|
415
|
+
}`,...d.parameters?.docs?.source}}};const f=["Demo","AlwaysOverride","FromStorageWithDefault","TypeAttribute"];export{k as AlwaysOverride,u as Demo,m as FromStorageWithDefault,d as TypeAttribute,f as __namedExportsOrder,E as default};
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
import{w as v,e as n}from"./index-CDavW7r9.js";import"./custom-element-BLZZ00dz.js";const x=(o,a)=>o.getAttribute(a);let m;function y(){m||(m={},"back,forward,go,pushState,replaceState".split(",").forEach(o=>{m[o]=history[o],history[o]=function(...a){m[o].apply(history,a),window.dispatchEvent(new CustomEvent("dce-location",{detail:{k:o}}))}}))}class b extends HTMLElement{static observedAttributes=["value","slice","href","type","live"];constructor(){super();const a={},t=()=>setTimeout(c,1),c=()=>{const l=x(this,"href");l||y();const i=l?new URL(l,window.location):window.location,e={},r=new URLSearchParams(i.search);for(const s of r.keys())e[s]=r.getAll(s);const d={params:e};for(const s in i)typeof i[s]=="string"&&(d[s]=i[s]);this.value=d,this.dispatchEvent(new Event("change"))};this.sliceInit=l=>(!a.listener&&this.hasAttribute("live")&&(a.listener=1,window.navigation?.addEventListener("navigate",t),window.addEventListener("popstate",t),window.addEventListener("hashchange",t),window.addEventListener("dce-location",t)),c(),l||{}),this._destroy=()=>{window.removeEventListener("popstate",t),window.removeEventListener("hashchange",t),window.removeEventListener("dce-location",t),delete a.listener}}attributeChangedCallback(a,t,c){a==="href"&&this.sliceInit&&this.sliceInit()}connectedCallback(){this.sliceInit()}disconnectedCallback(){this._destroy()}}window.customElements.define("location-element",b);const w={title:"",slice:"url-slice",href:"",live:"",body:""};function u(o){return new Promise(a=>setTimeout(a,o))}function E(o){const{title:a,slice:t,href:c,live:l,body:i}={...w,...o};return`
|
|
2
|
+
<fieldset>
|
|
3
|
+
<legend>${a}</legend>
|
|
4
|
+
|
|
5
|
+
<custom-element>
|
|
6
|
+
<template><!-- wrapping into template to prevent images loading within DCE declaration -->
|
|
7
|
+
<location-element
|
|
8
|
+
slice="${t}"
|
|
9
|
+
${c?`href="${c}"`:""}
|
|
10
|
+
live="${l}"
|
|
11
|
+
></location-element>
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
${i}
|
|
15
|
+
<xhtml:table>
|
|
16
|
+
<xhtml:tbody>
|
|
17
|
+
<xhtml:tr>
|
|
18
|
+
<xhtml:th><h3> URL properties </h3></xhtml:th>
|
|
19
|
+
<xhtml:td>{count(//value/@*)}</xhtml:td>
|
|
20
|
+
</xhtml:tr>
|
|
21
|
+
<apply-templates mode="attrs" select="//value/@*"></apply-templates>
|
|
22
|
+
</xhtml:tbody>
|
|
23
|
+
</xhtml:table>
|
|
24
|
+
<xhtml:table>
|
|
25
|
+
<h3> URL parameters </h3>
|
|
26
|
+
<apply-templates mode="attrs" select="//params/*/*"></apply-templates>
|
|
27
|
+
</xhtml:table>
|
|
28
|
+
<xsl:template mode="attrs" match="*|@*">
|
|
29
|
+
<xhtml:tr>
|
|
30
|
+
<xhtml:th>{name()}</xhtml:th>
|
|
31
|
+
<xhtml:td data-testid="param-{name()}">{.}</xhtml:td>
|
|
32
|
+
</xhtml:tr>
|
|
33
|
+
</xsl:template>
|
|
34
|
+
</template>
|
|
35
|
+
</custom-element>
|
|
36
|
+
</fieldset>
|
|
37
|
+
`}const q={title:"location-element",render:E},h={args:{title:"live value",live:"live",body:`
|
|
38
|
+
<button onclick="history.pushState( {'{}'},'', '/location.html?pushstate=p1&p2=P2#h1')">history.pushState</button>
|
|
39
|
+
<button onclick="history.replaceState( {'{}'},'', '/vacation.html?replaceState=r1&r2=R2#h2')">history.replaceState</button>
|
|
40
|
+
`},play:async({canvasElement:o})=>{const a=v(o);await a.findByText(h.args.title);const t=e=>a.getByTestId("param-"+e).textContent.trim(),c=e=>a.getByText(e),l=(e,r)=>n(t(r)).toEqual(e[r],r),i="href,origin,protocol,host,hostname,port,pathname,search,hash".split(",");i.forEach(e=>l(window.location,e)),c("history.pushState").click(),await u(100),n(t("pathname")).toEqual("/location.html"),n(t("search")).toEqual("?pushstate=p1&p2=P2"),i.forEach(e=>l(window.location,e)),c("history.replaceState").click(),await u(100),n(t("pathname")).toEqual("/vacation.html"),n(t("search")).toEqual("?replaceState=r1&r2=R2"),i.forEach(e=>l(window.location,e))}},p={args:{title:"scr attribute as URL",live:"live",href:"/some/path?param1=/story/location-element--href-attribute?p1=P1&p2=P2#h1",body:`
|
|
41
|
+
<button onclick="document.querySelector('location-element').setAttribute('href','/location.html?a1=A1&b2=B2#h2')">/location.html?a1=A1&b2=B2#h2</button>
|
|
42
|
+
<button onclick="document.querySelector('location-element').setAttribute('href','/vacation.html?c1=C1&d2=D2#h3')">/vacation.html?c1=C1&d2=D2#h3</button>
|
|
43
|
+
`},play:async({canvasElement:o})=>{const a=v(o);await a.findByText(p.args.title);const t=e=>a.getByTestId("param-"+e).textContent.trim(),c=e=>a.getByText(e),l=(e,r)=>n(t(r)).toEqual(e[r],r);"origin,protocol,host,hostname,port".split(",").forEach(e=>l(window.location,e)),c("/location.html?a1=A1&b2=B2#h2").click(),await u(10),n(t("pathname")).toEqual("/location.html","pathname #2"),n(t("search")).toEqual("?a1=A1&b2=B2"),n(t("hash")).toEqual("#h2"),n(t("a1")).toEqual("A1"),n(t("b2")).toEqual("B2"),c("/vacation.html?c1=C1&d2=D2#h3").click(),await u(10),n(t("pathname")).toEqual("/vacation.html","pathname #3"),n(t("search")).toEqual("?c1=C1&d2=D2"),n(t("hash")).toEqual("#h3"),n(t("c1")).toEqual("C1"),n(t("d2")).toEqual("D2")}};h.parameters={...h.parameters,docs:{...h.parameters?.docs,source:{originalSource:`{
|
|
44
|
+
args: {
|
|
45
|
+
title: 'live value',
|
|
46
|
+
live: 'live',
|
|
47
|
+
body: \`
|
|
48
|
+
<button onclick="history.pushState( {'{}'},'', '/location.html?pushstate=p1&p2=P2#h1')">history.pushState</button>
|
|
49
|
+
<button onclick="history.replaceState( {'{}'},'', '/vacation.html?replaceState=r1&r2=R2#h2')">history.replaceState</button>
|
|
50
|
+
\`
|
|
51
|
+
},
|
|
52
|
+
play: async ({
|
|
53
|
+
canvasElement
|
|
54
|
+
}) => {
|
|
55
|
+
const canvas = within(canvasElement);
|
|
56
|
+
await canvas.findByText((Demo.args!.title as string));
|
|
57
|
+
const val = prop => canvas.getByTestId('param-' + prop).textContent.trim(),
|
|
58
|
+
byText = txt => canvas.getByText(txt),
|
|
59
|
+
expectMatch = (l, prop) => expect(val(prop)).toEqual(l[prop], prop),
|
|
60
|
+
locationProps = 'href,origin,protocol,host,hostname,port,pathname,search,hash'.split(',');
|
|
61
|
+
locationProps.forEach(prop => expectMatch(window.location, prop));
|
|
62
|
+
byText('history.pushState').click();
|
|
63
|
+
await sleep(100);
|
|
64
|
+
expect(val('pathname')).toEqual('/location.html');
|
|
65
|
+
expect(val('search')).toEqual('?pushstate=p1&p2=P2');
|
|
66
|
+
locationProps.forEach(prop => expectMatch(window.location, prop));
|
|
67
|
+
byText('history.replaceState').click();
|
|
68
|
+
await sleep(100);
|
|
69
|
+
expect(val('pathname')).toEqual('/vacation.html');
|
|
70
|
+
expect(val('search')).toEqual('?replaceState=r1&r2=R2');
|
|
71
|
+
locationProps.forEach(prop => expectMatch(window.location, prop));
|
|
72
|
+
}
|
|
73
|
+
}`,...h.parameters?.docs?.source}}};p.parameters={...p.parameters,docs:{...p.parameters?.docs,source:{originalSource:`{
|
|
74
|
+
args: {
|
|
75
|
+
title: 'scr attribute as URL',
|
|
76
|
+
live: 'live',
|
|
77
|
+
href: '/some/path?param1=/story/location-element--href-attribute?p1=P1&p2=P2#h1',
|
|
78
|
+
body: \`
|
|
79
|
+
<button onclick="document.querySelector('location-element').setAttribute('href','/location.html?a1=A1&b2=B2#h2')">/location.html?a1=A1&b2=B2#h2</button>
|
|
80
|
+
<button onclick="document.querySelector('location-element').setAttribute('href','/vacation.html?c1=C1&d2=D2#h3')">/vacation.html?c1=C1&d2=D2#h3</button>
|
|
81
|
+
\`
|
|
82
|
+
},
|
|
83
|
+
play: async ({
|
|
84
|
+
canvasElement
|
|
85
|
+
}) => {
|
|
86
|
+
const canvas = within(canvasElement);
|
|
87
|
+
await canvas.findByText((SrcAttribute.args!.title as string));
|
|
88
|
+
const val = prop => canvas.getByTestId('param-' + prop).textContent.trim(),
|
|
89
|
+
byText = txt => canvas.getByText(txt),
|
|
90
|
+
expectMatch = (l, prop) => expect(val(prop)).toEqual(l[prop], prop),
|
|
91
|
+
locationProps = 'origin,protocol,host,hostname,port'.split(',');
|
|
92
|
+
locationProps.forEach(prop => expectMatch(window.location, prop));
|
|
93
|
+
byText('/location.html?a1=A1&b2=B2#h2').click();
|
|
94
|
+
await sleep(10);
|
|
95
|
+
expect(val('pathname')).toEqual('/location.html', 'pathname #2');
|
|
96
|
+
expect(val('search')).toEqual('?a1=A1&b2=B2');
|
|
97
|
+
expect(val('hash')).toEqual('#h2');
|
|
98
|
+
expect(val('a1')).toEqual('A1');
|
|
99
|
+
expect(val('b2')).toEqual('B2');
|
|
100
|
+
byText('/vacation.html?c1=C1&d2=D2#h3').click();
|
|
101
|
+
await sleep(10);
|
|
102
|
+
expect(val('pathname')).toEqual('/vacation.html', 'pathname #3');
|
|
103
|
+
expect(val('search')).toEqual('?c1=C1&d2=D2');
|
|
104
|
+
expect(val('hash')).toEqual('#h3');
|
|
105
|
+
expect(val('c1')).toEqual('C1');
|
|
106
|
+
expect(val('d2')).toEqual('D2');
|
|
107
|
+
}
|
|
108
|
+
}`,...p.parameters?.docs?.source}}};const S=["Demo","SrcAttribute"];export{h as Demo,p as SrcAttribute,S as __namedExportsOrder,q as default};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
var e={viewport:"reset",viewportRotated:!1};export{e as globals};
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import{d as _}from"./index-DrFu-skq.js";const{useMemo:f,useEffect:y}=__STORYBOOK_MODULE_PREVIEW_API__,{global:E}=__STORYBOOK_MODULE_GLOBAL__,{logger:M}=__STORYBOOK_MODULE_CLIENT_LOGGER__;var g="backgrounds",{document:l,window:h}=E,B=()=>h.matchMedia("(prefers-reduced-motion: reduce)").matches,x=(r,e=[],n)=>{if(r==="transparent")return"transparent";if(e.find(a=>a.value===r))return r;let d=e.find(a=>a.name===n);if(d)return d.value;if(n){let a=e.map(i=>i.name).join(", ");M.warn(_`
|
|
2
|
+
Backgrounds Addon: could not find the default color "${n}".
|
|
3
|
+
These are the available colors for your story based on your configuration:
|
|
4
|
+
${a}.
|
|
5
|
+
`)}return"transparent"},v=r=>{(Array.isArray(r)?r:[r]).forEach(O)},O=r=>{let e=l.getElementById(r);e&&e.parentElement?.removeChild(e)},S=(r,e)=>{let n=l.getElementById(r);if(n)n.innerHTML!==e&&(n.innerHTML=e);else{let d=l.createElement("style");d.setAttribute("id",r),d.innerHTML=e,l.head.appendChild(d)}},w=(r,e,n)=>{let d=l.getElementById(r);if(d)d.innerHTML!==e&&(d.innerHTML=e);else{let a=l.createElement("style");a.setAttribute("id",r),a.innerHTML=e;let i=`addon-backgrounds-grid${n?`-docs-${n}`:""}`,t=l.getElementById(i);t?t.parentElement?.insertBefore(a,t):l.head.appendChild(a)}},A=(r,e)=>{let{globals:n,parameters:d}=e,a=n[g]?.value,i=d[g],t=f(()=>i.disable?"transparent":x(a,i.values,i.default),[i,a]),o=f(()=>t&&t!=="transparent",[t]),s=e.viewMode==="docs"?`#anchor--${e.id} .docs-story`:".sb-show-main",p=f(()=>`
|
|
6
|
+
${s} {
|
|
7
|
+
background: ${t} !important;
|
|
8
|
+
${B()?"":"transition: background-color 0.3s;"}
|
|
9
|
+
}
|
|
10
|
+
`,[t,s]);return y(()=>{let u=e.viewMode==="docs"?`addon-backgrounds-docs-${e.id}`:"addon-backgrounds-color";if(!o){v(u);return}w(u,p,e.viewMode==="docs"?e.id:null)},[o,p,e]),r()},L=(r,e)=>{let{globals:n,parameters:d}=e,a=d[g].grid,i=n[g]?.grid===!0&&a.disable!==!0,{cellAmount:t,cellSize:o,opacity:s}=a,p=e.viewMode==="docs",u=d.layout===void 0||d.layout==="padded"?16:0,c=a.offsetX??(p?20:u),m=a.offsetY??(p?20:u),$=f(()=>{let b=e.viewMode==="docs"?`#anchor--${e.id} .docs-story`:".sb-show-main",k=[`${o*t}px ${o*t}px`,`${o*t}px ${o*t}px`,`${o}px ${o}px`,`${o}px ${o}px`].join(", ");return`
|
|
11
|
+
${b} {
|
|
12
|
+
background-size: ${k} !important;
|
|
13
|
+
background-position: ${c}px ${m}px, ${c}px ${m}px, ${c}px ${m}px, ${c}px ${m}px !important;
|
|
14
|
+
background-blend-mode: difference !important;
|
|
15
|
+
background-image: linear-gradient(rgba(130, 130, 130, ${s}) 1px, transparent 1px),
|
|
16
|
+
linear-gradient(90deg, rgba(130, 130, 130, ${s}) 1px, transparent 1px),
|
|
17
|
+
linear-gradient(rgba(130, 130, 130, ${s/2}) 1px, transparent 1px),
|
|
18
|
+
linear-gradient(90deg, rgba(130, 130, 130, ${s/2}) 1px, transparent 1px) !important;
|
|
19
|
+
}
|
|
20
|
+
`},[o]);return y(()=>{let b=e.viewMode==="docs"?`addon-backgrounds-grid-docs-${e.id}`:"addon-backgrounds-grid";if(!i){v(b);return}S(b,$)},[i,$,e]),r()},C=[L,A],I={[g]:{grid:{cellSize:20,opacity:.5,cellAmount:5},values:[{name:"light",value:"#F8F8F8"},{name:"dark",value:"#333333"}]}},R={[g]:null};export{C as decorators,R as globals,I as parameters};
|