@studiometa/ui 0.2.9 → 0.2.10
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.
|
@@ -1 +1 @@
|
|
|
1
|
-
import
|
|
1
|
+
import s from"../../primitives/Transition/Transition.js";const o=["a[href]:not([inert])","area[href]:not([inert])","input:not([disabled]):not([inert])","select:not([disabled]):not([inert])","textarea:not([disabled]):not([inert])","button:not([disabled]):not([inert])","iframe:not([inert])","audio:not([inert])","video:not([inert])","[contenteditable]:not([inert])","[tabindex]:not([inert])"].join(",");class n extends s{static config={...s.config,name:"MenuList",emits:["items-open","items-close","items-mouseleave"],components:{MenuList:n}};isOpen=!1;isHover=!1;get $options(){const e=super.$options;return e.leaveKeep=!0,e.enterKeep=!0,e}mounted(){this.__updateTabIndexes("close")}onMouseenter(){this.isHover=!0}onMouseleave(){this.isHover=!1}open(){if(this.isOpen)return;const e=t=>{this.$el.contains(t.target)||(document.removeEventListener("click",e),this.close())};document.addEventListener("click",e),this.__updateTabIndexes("open"),this.$el.setAttribute("aria-hidden","false"),this.isOpen=!0,this.enter(),this.$emit("items-open")}close(){!this.isOpen||(this.$children.MenuList.forEach(e=>{e.close()}),document.activeElement instanceof HTMLElement&&this.$el.contains(document.activeElement)&&document.activeElement.blur(),this.$el.setAttribute("aria-hidden","true"),this.__updateTabIndexes("close"),this.isOpen=!1,this.leave(),this.$emit("items-close"))}toggle(){this.isOpen?this.close():this.open()}__updateTabIndexes(e="open"){Array.from(this.$el.querySelectorAll(o)).filter(i=>this.__filterFocusableItems(i)).forEach(i=>{e==="close"?i.setAttribute("tabindex","-1"):i.removeAttribute("tabindex")})}__filterFocusableItems(e){let t=e.parentElement;for(;t&&(!t.__base__||!t.__base__.has(this.constructor));)t=t.parentElement;return t===null||t===this.$el}}export{n as default};
|
|
@@ -87,11 +87,11 @@ var _Frame = class extends import_js_toolkit.Base {
|
|
|
87
87
|
onWindowPopstate(event) {
|
|
88
88
|
this.goTo(window.location.href, event.state);
|
|
89
89
|
}
|
|
90
|
-
onFrameAnchorClick(
|
|
90
|
+
onFrameAnchorClick(index, event) {
|
|
91
91
|
if (!(0, import_js_toolkit.isDirectChild)(this, "Frame", "FrameAnchor", this.$children.FrameAnchor[index])) {
|
|
92
92
|
return;
|
|
93
93
|
}
|
|
94
|
-
this.$log("onAFrameClick",
|
|
94
|
+
this.$log("onAFrameClick", index, event);
|
|
95
95
|
event.preventDefault();
|
|
96
96
|
const anchor = this.$children.FrameAnchor[index];
|
|
97
97
|
if (anchor.href === window.location.href) {
|
|
@@ -99,11 +99,11 @@ var _Frame = class extends import_js_toolkit.Base {
|
|
|
99
99
|
}
|
|
100
100
|
this.goTo(anchor.href);
|
|
101
101
|
}
|
|
102
|
-
onFrameFormSubmit(
|
|
102
|
+
onFrameFormSubmit(index, event) {
|
|
103
103
|
if (!(0, import_js_toolkit.isDirectChild)(this, "Frame", "FrameForm", this.$children.FrameForm[index])) {
|
|
104
104
|
return;
|
|
105
105
|
}
|
|
106
|
-
this.$log("onFrameFormFrameSubmit", event);
|
|
106
|
+
this.$log("onFrameFormFrameSubmit", index, event);
|
|
107
107
|
event.preventDefault();
|
|
108
108
|
const form = this.$children.FrameForm[index];
|
|
109
109
|
const url = new URL(form.action);
|
|
@@ -192,7 +192,6 @@ __publicField(Frame, "config", {
|
|
|
192
192
|
"before-enter",
|
|
193
193
|
"after-enter"
|
|
194
194
|
],
|
|
195
|
-
log: true,
|
|
196
195
|
components: {
|
|
197
196
|
FrameAnchor: import_FrameAnchor.default,
|
|
198
197
|
FrameForm: import_FrameForm.default,
|
|
@@ -24,7 +24,6 @@ export default class Frame extends Base {
|
|
|
24
24
|
static config: {
|
|
25
25
|
name: string;
|
|
26
26
|
emits: string[];
|
|
27
|
-
log: boolean;
|
|
28
27
|
components: {
|
|
29
28
|
FrameAnchor: typeof FrameAnchor;
|
|
30
29
|
FrameForm: typeof FrameForm;
|
|
@@ -86,20 +85,20 @@ export default class Frame extends Base {
|
|
|
86
85
|
* Prevent click on `FrameAnchor`.
|
|
87
86
|
*
|
|
88
87
|
* @this {FrameInterface}
|
|
89
|
-
* @param {MouseEvent} event
|
|
90
88
|
* @param {number} index
|
|
89
|
+
* @param {MouseEvent} event
|
|
91
90
|
* @returns {void}
|
|
92
91
|
*/
|
|
93
|
-
onFrameAnchorClick(this: FrameInterface,
|
|
92
|
+
onFrameAnchorClick(this: FrameInterface, index: number, event: MouseEvent): void;
|
|
94
93
|
/**
|
|
95
94
|
* Prevent submit on forms.
|
|
96
95
|
*
|
|
97
96
|
* @this {FrameInterface}
|
|
98
|
-
* @param {SubmitEvent} event
|
|
99
97
|
* @param {number} index
|
|
98
|
+
* @param {SubmitEvent} event
|
|
100
99
|
* @returns {void}
|
|
101
100
|
*/
|
|
102
|
-
onFrameFormSubmit(this: FrameInterface,
|
|
101
|
+
onFrameFormSubmit(this: FrameInterface, index: number, event: SubmitEvent): void;
|
|
103
102
|
/**
|
|
104
103
|
* Parge an HTML string into a DOM object.
|
|
105
104
|
* @param {string} string
|
package/organisms/Frame/Frame.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{Base as f,isDirectChild as c,getDirectChildren as p}from"@studiometa/js-toolkit";import{nextFrame as m,historyPush as w}from"@studiometa/js-toolkit/utils";import g from"./FrameAnchor.js";import F from"./FrameForm.js";import u from"./FrameTarget.js";function $(){return{left:window.pageXOffset,top:window.pageYOffset}}const a=new Map;class s extends f{static config={name:"Frame",emits:["before-fetch","after-fetch","before-leave","after-leave","before-content","after-content","before-enter","after-enter"],
|
|
1
|
+
import{Base as f,isDirectChild as c,getDirectChildren as p}from"@studiometa/js-toolkit";import{nextFrame as m,historyPush as w}from"@studiometa/js-toolkit/utils";import g from"./FrameAnchor.js";import F from"./FrameForm.js";import u from"./FrameTarget.js";function $(){return{left:window.pageXOffset,top:window.pageYOffset}}const a=new Map;class s extends f{static config={name:"Frame",emits:["before-fetch","after-fetch","before-leave","after-leave","before-content","after-content","before-enter","after-enter"],components:{FrameAnchor:g,FrameForm:F,FrameTarget:u,Frame:s},options:{history:Boolean}};get id(){return this.$el.id}getDirectChild(e){return this.$children[e]?this.$children.Frame?this.$children[e].filter(r=>this.$children.Frame.every(t=>t.$children[e]?!t.$children[e].includes(r):!0)):this.$children[e]:[]}get directChildrenFrameTarget(){return p(this,"Frame","FrameTarget")}mounted(){this.$options.history&&window.addEventListener("popstate",this)}destroyed(){window.removeEventListener("popstate",this)}handleEvent(e){e.type==="popstate"&&this.onWindowPopstate(e),e.type==="beforeunload"&&this.onWindowUnload()}onWindowUnload(){const{history:e}=window;!e.state||e.replaceState({...e.state,scroll:$()},"")}onWindowPopstate(e){this.goTo(window.location.href,e.state)}onFrameAnchorClick(e,r){if(!c(this,"Frame","FrameAnchor",this.$children.FrameAnchor[e]))return;this.$log("onAFrameClick",e,r),r.preventDefault();const t=this.$children.FrameAnchor[e];t.href!==window.location.href&&this.goTo(t.href)}onFrameFormSubmit(e,r){if(!c(this,"Frame","FrameForm",this.$children.FrameForm[e]))return;this.$log("onFrameFormFrameSubmit",e,r),r.preventDefault();const t=this.$children.FrameForm[e],i=new URL(t.action);i.search=new URLSearchParams(new FormData(t.$el)).toString(),this.goTo(i.toString())}parseHTML(e=""){return new DOMParser().parseFromString(e,"text/html")}async goTo(e,r=null){this.$log("goTo",e);const t=new URL(e);if(t.origin!==window.location.origin)throw new Error("Cross origin request are not allowed.");this.$emit("before-fetch",e);const i=await this.fetch(e),n=this.parseHTML(i),l=n.querySelector(`#${this.id}`),h=new s(l);h.$children.registerAll(),this.$emit("after-fetch",e,i),this.$emit("before-leave"),await Promise.all(this.directChildrenFrameTarget.map(o=>o.leave())),this.$emit("after-leave"),this.$emit("before-content"),this.directChildrenFrameTarget.map((o,d)=>o.updateContent(h.directChildrenFrameTarget[d])),this.$options.history&&(document.title=n.title,w({path:t.pathname,search:t.searchParams})),r&&(document.scrollingElement.scrollTop=r.top,document.scrollingElement.scrollLeft=r.left),await m(),this.$root.$update(),await m(),this.$emit("after-content"),this.$emit("before-enter"),await Promise.all(this.directChildrenFrameTarget.map(o=>o.enter())),this.$emit("after-enter")}async fetch(e){const r=a.get(e);if(r)return r.status==="pending"?r.promise:r.content;const t=fetch(e);try{a.set(e,{promise:t,status:"pending",content:void 0});const i=await t.then(n=>n.text());return a.set(e,{promise:t,status:"resolved",content:i}),i}catch(i){return a.set(e,{promise:t,status:"error",content:i}),i}}}export{s as default};
|