init component

This commit is contained in:
Robin COuret
2026-02-16 17:28:37 +01:00
parent 460c7a25e0
commit e0e50af706
4557 changed files with 666911 additions and 8 deletions

View File

@@ -0,0 +1,36 @@
import { IO } from 'fp-ts/lib/IO';
import { VNode } from 'vue';
import { Transition, TransitionClasses } from '../../../types/Transition';
export interface NoticeOptions {
render: IO<VNode[]>;
duration: number;
shouldQueue: boolean;
transition: Transition;
}
export interface Notice {
id: number;
render: IO<VNode[] | undefined>;
transition: TransitionClasses;
onAfterLeave: IO<void>;
}
declare const BNoticeContainer: import("vue").DefineComponent<{}, {
rootZ: import("vue").ComputedRef<-1 | 999>;
showNotice: (params: NoticeOptions) => IO<void>;
notices: {
id: number;
render: IO<VNode[] | undefined>;
transition: {
css?: boolean | undefined;
name?: string | undefined;
'enter-from-class'?: string | undefined;
'enter-active-class'?: string | undefined;
'enter-to-class'?: string | undefined;
'leave-from-class'?: string | undefined;
'leave-active-class'?: string | undefined;
'leave-to-class'?: string | undefined;
};
onAfterLeave: IO<void>;
}[];
}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, import("vue").EmitsOptions, string, import("vue").VNodeProps & import("vue").AllowedComponentProps & import("vue").ComponentCustomProps, Readonly<{} & {}>, {}>;
export declare type NoticeContainer = InstanceType<typeof BNoticeContainer>;
export default BNoticeContainer;

View File

@@ -0,0 +1,84 @@
import { constVoid } from 'fp-ts/lib/function';
import { formatTransition } from '../../../composables/transition';
import { defineComponent, h, Transition as transition, computed, reactive, nextTick } from 'vue';
import { constEmptyArray } from '../../../utils/helpers';
let id = 0;
function generateNotice(notice) {
return h(transition, {
key: notice.id,
...notice.transition,
onAfterLeague: notice.onAfterLeave
}, notice.render);
}
const BNoticeContainer = defineComponent({
name: 'b-notice-container',
setup() {
const notices = reactive([]);
const rootZ = computed(() => notices.length ? 999 : -1);
function addNotice(options) {
const nId = id++;
function remove() {
const index = notices.findIndex(n => n.id === nId);
if (index > -1) {
notices.splice(index, 1);
}
}
const newNotice = reactive({
id: nId,
render: constEmptyArray,
transition: formatTransition(options.transition),
onAfterLeave: remove
});
notices.push(newNotice);
nextTick().then(() => {
newNotice.render = options.render;
});
return remove;
}
function showNotice(params) {
if (params.shouldQueue && notices.length > 0) {
let remove = constVoid;
setTimeout(() => {
remove = showNotice(params);
}, 250);
return () => {
remove();
};
}
const removeNotice = addNotice(params);
if (params.duration === 0) {
return removeNotice;
} else {
setTimeout(removeNotice, params.duration);
return removeNotice;
}
}
return {
rootZ,
showNotice,
notices
};
},
render() {
return h('div', {
style: {
'z-index': this.rootZ
}
}, this.notices.map(generateNotice));
}
});
export default BNoticeContainer;
//# sourceMappingURL=BNoticeContainer.js.map

View File

@@ -0,0 +1 @@
{"version":3,"sources":["../../../../src/components/notices/noticeContainer/BNoticeContainer.ts"],"names":[],"mappings":"AAAA,SAAS,SAAT,QAA0B,oBAA1B;AAGA,SAAS,gBAAT,QAAiC,iCAAjC;AAEA,SAAS,eAAT,EAA0B,CAA1B,EAA6B,UAAU,IAAI,UAA3C,EAAuD,QAAvD,EAAiE,QAAjE,EAA2E,QAA3E,QAA2F,KAA3F;AACA,SAAS,eAAT,QAAgC,wBAAhC;AAgBA,IAAI,EAAE,GAAG,CAAT;;AAEA,SAAS,cAAT,CAAwB,MAAxB,EAAsC;AACpC,SAAO,CAAC,CAAC,UAAD,EAAa;AAAE,IAAA,GAAG,EAAE,MAAM,CAAC,EAAd;AAAkB,OAAG,MAAM,CAAC,UAA5B;AAAwC,IAAA,aAAa,EAAE,MAAM,CAAC;AAA9D,GAAb,EAA2F,MAAM,CAAC,MAAlG,CAAR;AACD;;AAED,MAAM,gBAAgB,GAAG,eAAe,CAAC;AACvC,EAAA,IAAI,EAAE,oBADiC;;AAEvC,EAAA,KAAK,GAAA;AACH,UAAM,OAAO,GAAG,QAAQ,CAAC,EAAD,CAAxB;AAEA,UAAM,KAAK,GAAG,QAAQ,CAAC,MAAO,OAAO,CAAC,MAAR,GAAiB,GAAjB,GAAuB,CAAC,C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;;AAED,WAAO;AACL,MAAA,KADK;AAEL,MAAA,UAFK;AAGL,MAAA;AAHK,KAAP;AAKD,GApDsC;;AAqDvC,EAAA,MAAM,GAAA;AACJ,WAAO,CAAC,CAAC,KAAD,EAAQ;AAAE,MAAA,KAAK,EAAE;AAAE,mBAAW,KAAK;AAAlB;AAAT,KAAR,EAA8C,KAAK,OAAL,CAAa,GAAb,CAAiB,cAAjB,CAA9C,CAAR;AACD;;AAvDsC,CAAD,CAAxC;AA4DA,eAAe,gBAAf","sourcesContent":["import { constVoid } from 'fp-ts/lib/function';\nimport { IO } from 'fp-ts/lib/IO';\nimport { VNode } from 'vue';\nimport { formatTransition } from '../../../composables/transition';\nimport { Transition, TransitionClasses } from '../../../types/Transition';\nimport { defineComponent, h, Transition as transition, computed, reactive, nextTick } from 'vue';\nimport { constEmptyArray } from '../../../utils/helpers';\n\nexport interface NoticeOptions {\n render: IO<VNode[]>;\n duration: number;\n shouldQueue: boolean;\n transition: Transition;\n}\n\nexport interface Notice {\n id: number;\n render: IO<VNode[] | undefined>;\n transition: TransitionClasses;\n onAfterLeave: IO<void>;\n}\n\nlet id = 0;\n\nfunction generateNotice(notice: Notice): VNode {\n return h(transition, { key: notice.id, ...notice.transition, onAfterLeague: notice.onAfterLeave }, notice.render);\n}\n\nconst BNoticeContainer = defineComponent({\n name: 'b-notice-container',\n setup() {\n const notices = reactive([] as Notice[]);\n\n const rootZ = computed(() => (notices.length ? 999 : -1));\n\n function addNotice(options: NoticeOptions): IO<void> {\n const nId = id++;\n function remove() {\n const index = notices.findIndex(n => n.id === nId);\n if (index > -1) {\n notices.splice(index, 1);\n }\n }\n const newNotice: Notice = reactive({\n id: nId,\n render: constEmptyArray,\n transition: formatTransition(options.transition),\n onAfterLeave: remove\n });\n notices.push(newNotice);\n nextTick().then(() => {\n newNotice.render = options.render;\n });\n return remove;\n }\n\n function showNotice(params: NoticeOptions): IO<void> {\n if (params.shouldQueue && notices.length > 0) {\n let remove = constVoid;\n setTimeout(() => {\n remove = showNotice(params);\n }, 250);\n return () => {\n remove();\n };\n }\n const removeNotice = addNotice(params);\n if (params.duration === 0) {\n return removeNotice;\n } else {\n setTimeout(removeNotice, params.duration);\n return removeNotice;\n }\n }\n\n return {\n rootZ,\n showNotice,\n notices\n };\n },\n render() {\n return h('div', { style: { 'z-index': this.rootZ } }, this.notices.map(generateNotice));\n }\n});\n\nexport type NoticeContainer = InstanceType<typeof BNoticeContainer>;\n\nexport default BNoticeContainer;\n"],"sourceRoot":"","file":"BNoticeContainer.js"}

View File

@@ -0,0 +1,3 @@
import BNoticeContainer from './BNoticeContainer';
export { BNoticeContainer };
export default BNoticeContainer;

View File

@@ -0,0 +1,4 @@
import BNoticeContainer from './BNoticeContainer';
export { BNoticeContainer };
export default BNoticeContainer;
//# sourceMappingURL=index.js.map

View File

@@ -0,0 +1 @@
{"version":3,"sources":["../../../../src/components/notices/noticeContainer/index.ts"],"names":[],"mappings":"AAAA,OAAO,gBAAP,MAA6B,oBAA7B;AAEA,SAAS,gBAAT;AAEA,eAAe,gBAAf","sourcesContent":["import BNoticeContainer from './BNoticeContainer';\n\nexport { BNoticeContainer };\n\nexport default BNoticeContainer;\n"],"sourceRoot":"","file":"index.js"}