@sixbell-telco/sdk 1.2.1 → 1.4.0
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/CHANGELOG.md +93 -0
- package/README.md +210 -70
- package/_index.css +232 -55
- package/assets/styles/toast.css +8 -0
- package/components/data-table/expandable/expandable.component.d.ts +129 -0
- package/components/{forms/datepicker → data-table}/index.d.ts +1 -1
- package/components/data-table/public-api.d.ts +7 -0
- package/components/data-table/selection/selection.component.d.ts +41 -0
- package/components/data-table/sortable-header/sortable-header.component.d.ts +61 -0
- package/components/data-table/src/data-table-context.service.d.ts +18 -0
- package/components/data-table/src/data-table.component.d.ts +158 -0
- package/components/data-table/src/models.d.ts +58 -0
- package/components/data-table/sub-component-toggle/index.d.ts +1 -0
- package/components/data-table/sub-component-toggle/sub-component-toggle.component.d.ts +12 -0
- package/components/dropdown/dropdown-group/dropdown-group.component.d.ts +1 -1
- package/components/dropdown/dropdown-item-checkbox/dropdown-item-checkbox.component.d.ts +2 -2
- package/components/dropdown/dropdown-item-radio/dropdown-item-radio.component.d.ts +2 -2
- package/components/dropdown-menu/bar/dropdown-menu-bar-item-checkbox/dropdown-menu-bar-item-checkbox.component.d.ts +2 -2
- package/components/dropdown-menu/bar/dropdown-menu-bar-item-radio/dropdown-menu-bar-item-radio.component.d.ts +2 -2
- package/components/forms/date-picker/constants/date-picker.constants.d.ts +13 -0
- package/components/forms/date-picker/index.d.ts +5 -0
- package/components/forms/date-picker/public-api.d.ts +3 -0
- package/components/forms/date-picker/src/date-picker.component.d.ts +323 -0
- package/components/forms/date-picker/types/date-picker.types.d.ts +39 -0
- package/components/overlay/index.d.ts +5 -0
- package/components/overlay/overlay-content/overlay-content.component.d.ts +23 -0
- package/components/overlay/overlay-trigger/overlay-trigger.component.d.ts +48 -0
- package/components/overlay/public-api.d.ts +3 -0
- package/components/overlay/src/overlay.component.d.ts +158 -0
- package/components/paginator/components/pagination-item/pagination-item.component.d.ts +8 -3
- package/components/paginator/pipes/pagination.pipe.d.ts +40 -0
- package/components/paginator/public-api.d.ts +1 -0
- package/components/paginator/src/paginator.component.d.ts +14 -12
- package/components/sonner/index.d.ts +5 -0
- package/components/sonner/public-api.d.ts +2 -0
- package/components/sonner/src/sonner.component.d.ts +39 -0
- package/components/sonner/toaster/index.d.ts +5 -0
- package/components/sonner/toaster/public-api.d.ts +1 -0
- package/components/sonner/toaster/src/toaster.component.d.ts +89 -0
- package/components/table/src/table.component.d.ts +9 -6
- package/components/toast/public-api.d.ts +9 -0
- package/components/toast/services/toast.service.d.ts +3 -0
- package/components/toast/toast-message/toast-message.component.d.ts +3 -0
- package/components/toast/toasts-container/toasts-container.component.d.ts +3 -0
- package/fesm2022/sixbell-telco-sdk-components-data-table-sub-component-toggle.mjs +103 -0
- package/fesm2022/sixbell-telco-sdk-components-data-table-sub-component-toggle.mjs.map +1 -0
- package/fesm2022/sixbell-telco-sdk-components-data-table.mjs +1091 -0
- package/fesm2022/sixbell-telco-sdk-components-data-table.mjs.map +1 -0
- package/fesm2022/sixbell-telco-sdk-components-dropdown-menu-bar.mjs +6 -6
- package/fesm2022/sixbell-telco-sdk-components-dropdown-menu-bar.mjs.map +1 -1
- package/fesm2022/sixbell-telco-sdk-components-dropdown.mjs +12 -10
- package/fesm2022/sixbell-telco-sdk-components-dropdown.mjs.map +1 -1
- package/fesm2022/sixbell-telco-sdk-components-dual-list.mjs +4 -5
- package/fesm2022/sixbell-telco-sdk-components-dual-list.mjs.map +1 -1
- package/fesm2022/sixbell-telco-sdk-components-forms-date-picker.mjs +885 -0
- package/fesm2022/sixbell-telco-sdk-components-forms-date-picker.mjs.map +1 -0
- package/fesm2022/sixbell-telco-sdk-components-forms-form-error.mjs +2 -2
- package/fesm2022/sixbell-telco-sdk-components-forms-form-error.mjs.map +1 -1
- package/fesm2022/sixbell-telco-sdk-components-forms-input.mjs +3 -3
- package/fesm2022/sixbell-telco-sdk-components-forms-input.mjs.map +1 -1
- package/fesm2022/sixbell-telco-sdk-components-overlay.mjs +408 -0
- package/fesm2022/sixbell-telco-sdk-components-overlay.mjs.map +1 -0
- package/fesm2022/sixbell-telco-sdk-components-paginator.mjs +150 -35
- package/fesm2022/sixbell-telco-sdk-components-paginator.mjs.map +1 -1
- package/fesm2022/sixbell-telco-sdk-components-sonner-toaster.mjs +132 -0
- package/fesm2022/sixbell-telco-sdk-components-sonner-toaster.mjs.map +1 -0
- package/fesm2022/sixbell-telco-sdk-components-sonner.mjs +179 -0
- package/fesm2022/sixbell-telco-sdk-components-sonner.mjs.map +1 -0
- package/fesm2022/sixbell-telco-sdk-components-table.mjs +15 -6
- package/fesm2022/sixbell-telco-sdk-components-table.mjs.map +1 -1
- package/fesm2022/sixbell-telco-sdk-components-toast.mjs +14 -0
- package/fesm2022/sixbell-telco-sdk-components-toast.mjs.map +1 -1
- package/fesm2022/sixbell-telco-sdk-utils-date.mjs +242 -0
- package/fesm2022/sixbell-telco-sdk-utils-date.mjs.map +1 -0
- package/fesm2022/sixbell-telco-sdk-utils-sync.mjs +84 -0
- package/fesm2022/sixbell-telco-sdk-utils-sync.mjs.map +1 -0
- package/package.json +77 -47
- package/utils/date/index.d.ts +5 -0
- package/utils/date/public-api.d.ts +1 -0
- package/utils/date/src/date-utils.d.ts +125 -0
- package/utils/sync/index.d.ts +5 -0
- package/utils/sync/public-api.d.ts +1 -0
- package/utils/sync/src/sync.d.ts +37 -0
- package/components/forms/datepicker/public-api.d.ts +0 -2
- package/components/forms/datepicker/src/datepicker-format-month.pipe.d.ts +0 -10
- package/components/forms/datepicker/src/datepicker.component.d.ts +0 -54
- package/fesm2022/sixbell-telco-sdk-components-forms-datepicker.mjs +0 -212
- package/fesm2022/sixbell-telco-sdk-components-forms-datepicker.mjs.map +0 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"sixbell-telco-sdk-components-toast.mjs","sources":["../../../projects/sdk/components/toast/services/toast.service.ts","../../../projects/sdk/components/toast/toast-message/toast-message.component.ts","../../../projects/sdk/components/toast/toast-message/toast-message.component.html","../../../projects/sdk/components/toast/toasts-container/toasts-container.component.ts","../../../projects/sdk/components/toast/toasts-container/toasts-container.component.html","../../../projects/sdk/components/toast/sixbell-telco-sdk-components-toast.ts"],"sourcesContent":["import { computed, Injectable, signal } from '@angular/core';\nimport { generateUniqueId } from '@sixbell-telco/sdk/utils/generators/uuid';\n\nexport enum ToastTypes {\n\tSUCCESS = 'toast-success',\n\tERROR = 'toast-error',\n\tINFO = 'toast-info',\n\tWARNING = 'toast-warning',\n}\n\nexport type Toast = {\n\tid: string;\n\ttype: ToastTypes;\n\tmessage: string;\n\ttitle: string;\n\tduration: number;\n\tanimate: 'enter' | 'leave';\n};\n\n@Injectable({\n\tprovidedIn: 'root',\n})\nexport class ToastService {\n\tprivate toastsSignal = signal<Toast[]>([]);\n\tprivate expandedSignal = signal(false);\n\n\t// Create computed signals for derived state\n\treadonly toasts = computed(() => this.toastsSignal());\n\treadonly expanded = computed(() => this.expandedSignal());\n\treadonly isEmpty = computed(() => this.toasts().length === 0);\n\n\tnotify(type: ToastTypes, message: string, title: string = '', duration: number = 10000) {\n\t\tconst toast: Toast = {\n\t\t\tid: generateUniqueId(),\n\t\t\ttype,\n\t\t\tmessage,\n\t\t\ttitle,\n\t\t\tduration,\n\t\t\tanimate: 'enter',\n\t\t};\n\n\t\t// Create a new array reference to ensure change detection\n\t\tthis.toastsSignal.update((toasts) => [toast, ...toasts]);\n\n\t\tthis.scheduleDismiss(toast);\n\t}\n\n\tscheduleDismiss(toast: Toast) {\n\t\tsetTimeout(() => {\n\t\t\tthis.remove(toast);\n\t\t}, toast.duration);\n\t}\n\n\tanimateRemoval(toast: Toast) {\n\t\tthis.toastsSignal.update((toasts) => toasts.map((t) => (t.id === toast.id ? { ...t, animate: 'leave' } : t)));\n\t}\n\n\tremove(toast: Toast) {\n\t\tthis.toastsSignal.update((toasts) => toasts.filter((t) => t.id !== toast.id));\n\n\t\tif (this.isEmpty()) {\n\t\t\tthis.collapse();\n\t\t}\n\t}\n\n\tclear() {\n\t\tthis.toastsSignal.set([]);\n\t\tthis.collapse();\n\t}\n\n\ttoggle() {\n\t\tthis.expandedSignal.update((expanded) => !expanded);\n\t}\n\n\tcollapse() {\n\t\tthis.expandedSignal.set(false);\n\t}\n\n\texpand() {\n\t\tthis.expandedSignal.set(true);\n\t}\n}\n","import { NgClass } from '@angular/common';\nimport { Component, computed, input, output } from '@angular/core';\nimport { IconComponent } from '@sixbell-telco/sdk/components/icon';\nimport { matCheckCircleOutline, matErrorOutline, matInfoOutline, matWarningOutline } from '@sixbell-telco/sdk/components/icon/material/outline';\nimport { TypographyDirective } from '@sixbell-telco/sdk/directives/typography';\nimport { cn } from '@sixbell-telco/sdk/utils/cn';\nimport { cva } from 'class-variance-authority';\nimport { Toast, ToastTypes } from '../services/toast.service';\n\nexport const toastComponent = cva(\n\t[\n\t\t'toast-message relative mb-2 flex min-h-20 h-20 w-[400px] cursor-pointer items-center rounded-lg border-2 bg-base-200 p-2 transition-all duration-300 ease-ease-in-and-out-back',\n\t],\n\t{\n\t\tvariants: {\n\t\t\tvariant: {\n\t\t\t\tinfo: ['border-primary', 'text-primary'],\n\t\t\t\tsuccess: ['border-success', 'text-success'],\n\t\t\t\twarning: ['border-warning', 'text-warning'],\n\t\t\t\terror: ['border-error', 'text-error'],\n\t\t\t},\n\t\t},\n\t\tcompoundVariants: [],\n\t\tdefaultVariants: {\n\t\t\tvariant: 'info',\n\t\t},\n\t},\n);\n\nexport type ToastVariantProps = 'info' | 'success' | 'warning' | 'error' | null | undefined;\n\nexport type ToastProps = {\n\tvariant?: ToastVariantProps;\n};\n\n@Component({\n\tselector: 'st-toast-message',\n\timports: [TypographyDirective, IconComponent, NgClass],\n\ttemplateUrl: './toast-message.component.html',\n})\nexport class ToastMessageComponent {\n\tvariant = input<ToastVariantProps>();\n\tclasses = input<string>('');\n\ttypes = ToastTypes;\n\ttoast = input.required<Toast>();\n\ttoastAmount = input.required<number>();\n\ttoastIndex = input.required<number>();\n\tclicked = output<Toast>();\n\ticonCheckCircle = matCheckCircleOutline;\n\ticonWarning = matWarningOutline;\n\ticonError = matErrorOutline;\n\ticonInfo = matInfoOutline;\n\n\tcomponentClass = computed(() => {\n\t\tconst toast = this.toast();\n\t\tconst classes = this.classes();\n\n\t\tswitch (toast.type) {\n\t\t\tcase this.types.SUCCESS:\n\t\t\t\treturn cn(toastComponent({ variant: 'success', class: classes }));\n\t\t\tcase this.types.ERROR:\n\t\t\t\treturn cn(toastComponent({ variant: 'error', class: classes }));\n\t\t\tcase this.types.WARNING:\n\t\t\t\treturn cn(toastComponent({ variant: 'warning', class: classes }));\n\t\t\tcase this.types.INFO:\n\t\t\t\treturn cn(toastComponent({ variant: 'info', class: classes }));\n\t\t\tdefault:\n\t\t\t\treturn cn(toastComponent({ variant: 'info', class: classes }));\n\t\t}\n\t});\n\n\thandleClose() {\n\t\tthis.clicked.emit(this.toast());\n\t}\n}\n","<!-- eslint-disable @angular-eslint/template/click-events-have-key-events -->\n<li\n\t[class]=\"componentClass()\"\n\t[ngClass]=\"{\n\t\t'animate-toast-slide-out bottom-0': toast().animate === 'leave' && toastAmount() > 1,\n\t\t'animate-slide-out': toast().animate === 'leave' && toastAmount() === 1,\n\t\t'animate-fade-out': toast().animate === 'leave' && toastAmount() > 1 && toastIndex() === 0,\n\t\t'animate-slide-in': toast().animate === 'enter',\n\t}\"\n\t(click)=\"handleClose()\"\n\trole=\"button\"\n\ttabindex=\"0\"\n>\n\t<div class=\"flex flex-1 items-center justify-center\">\n\t\t@if (this.toast().type === this.types.SUCCESS) {\n\t\t\t<st-icon [icon]=\"iconCheckCircle\" color=\"inherit\" size=\"md\"></st-icon>\n\t\t} @else if (this.toast().type === this.types.WARNING) {\n\t\t\t<st-icon [icon]=\"iconWarning\" color=\"inherit\" size=\"md\"></st-icon>\n\t\t} @else if (this.toast().type === this.types.ERROR) {\n\t\t\t<st-icon [icon]=\"iconError\" color=\"inherit\" size=\"md\"></st-icon>\n\t\t} @else if (this.toast().type === this.types.INFO) {\n\t\t\t<st-icon [icon]=\"iconInfo\" color=\"inherit\" size=\"md\"></st-icon>\n\t\t}\n\t</div>\n\t<div class=\"flex-4\">\n\t\t<div class=\"grid grid-rows-[min-content_1fr]\">\n\t\t\t<div typography [tyVariant]=\"'body-sm'\" [tyColor]=\"'base'\" [tyFontWeight]=\"'semibold'\">{{ toast().title }}</div>\n\t\t\t<div typography [tyVariant]=\"'body-xs'\" [tyColor]=\"'base'\" [tyFontWeight]=\"'normal'\">\n\t\t\t\t{{ toast().message }}\n\t\t\t</div>\n\t\t</div>\n\t</div>\n</li>\n","import { NgClass } from '@angular/common';\nimport { Component, computed, inject } from '@angular/core';\nimport { Toast, ToastService } from '../services/toast.service';\nimport { ToastMessageComponent } from '../toast-message/toast-message.component';\n\n@Component({\n selector: 'st-toasts-container',\n imports: [ToastMessageComponent, NgClass],\n templateUrl: './toasts-container.component.html'\n})\nexport class ToastsContainerComponent {\n\ttoastService = inject(ToastService);\n\n\tprotected containerClasses = computed(() => {\n\t\tconst toastCount = this.toastService.toasts().length;\n\t\tconst isExpanded = this.toastService.expanded();\n\n\t\treturn {\n\t\t\t'min-h-64': toastCount === 3 && isExpanded,\n\t\t\t'min-h-48': toastCount === 2 && isExpanded,\n\t\t\t'h-24 min-h-24': toastCount === 1 && isExpanded,\n\t\t\t'h-28 min-h-28': toastCount > 0 && !isExpanded,\n\t\t\t'h-0 min-h-0': toastCount === 0 && !isExpanded,\n\t\t};\n\t});\n\n\thandleExpand(): void {\n\t\tthis.toastService.expand();\n\t}\n\n\thandleCollapse(): void {\n\t\tthis.toastService.collapse();\n\t}\n\n\thandleRemove(toast: Toast): void {\n\t\tthis.toastService.animateRemoval(toast);\n\t\tsetTimeout(() => {\n\t\t\tthis.toastService.remove(toast);\n\t\t}, 500);\n\t}\n\n\tgetToastIndex(toast: Toast): number {\n\t\treturn this.toastService.toasts().findIndex((t) => t.id === toast.id);\n\t}\n}\n","<section class=\"fixed right-4 bottom-2 z-[1001]\">\n\t<ol\n\t\tclass=\"toast-container group flex min-w-[400px] flex-col gap-2\"\n\t\t[ngClass]=\"containerClasses()\"\n\t\t[attr.aria-expanded]=\"toastService.expanded()\"\n\t\t(mouseenter)=\"handleExpand()\"\n\t\t(mouseleave)=\"handleCollapse()\"\n\t>\n\t\t@for (toast of toastService.toasts(); track toast.id) {\n\t\t\t<st-toast-message\n\t\t\t\t[toast]=\"toast\"\n\t\t\t\t[toastIndex]=\"getToastIndex(toast)\"\n\t\t\t\t[toastAmount]=\"toastService.toasts().length\"\n\t\t\t\t(clicked)=\"handleRemove($event)\"\n\t\t\t/>\n\t\t}\n\t</ol>\n</section>\n","/**\n * Generated bundle index. Do not edit.\n */\n\nexport * from './public-api';\n"],"names":[],"mappings":";;;;;;;;;;IAGY;AAAZ,CAAA,UAAY,UAAU,EAAA;AACrB,IAAA,UAAA,CAAA,SAAA,CAAA,GAAA,eAAyB;AACzB,IAAA,UAAA,CAAA,OAAA,CAAA,GAAA,aAAqB;AACrB,IAAA,UAAA,CAAA,MAAA,CAAA,GAAA,YAAmB;AACnB,IAAA,UAAA,CAAA,SAAA,CAAA,GAAA,eAAyB;AAC1B,CAAC,EALW,UAAU,KAAV,UAAU,GAKrB,EAAA,CAAA,CAAA;MAcY,YAAY,CAAA;AAChB,IAAA,YAAY,GAAG,MAAM,CAAU,EAAE,CAAC;AAClC,IAAA,cAAc,GAAG,MAAM,CAAC,KAAK,CAAC;;IAG7B,MAAM,GAAG,QAAQ,CAAC,MAAM,IAAI,CAAC,YAAY,EAAE,CAAC;IAC5C,QAAQ,GAAG,QAAQ,CAAC,MAAM,IAAI,CAAC,cAAc,EAAE,CAAC;AAChD,IAAA,OAAO,GAAG,QAAQ,CAAC,MAAM,IAAI,CAAC,MAAM,EAAE,CAAC,MAAM,KAAK,CAAC,CAAC;IAE7D,MAAM,CAAC,IAAgB,EAAE,OAAe,EAAE,KAAgB,GAAA,EAAE,EAAE,QAAA,GAAmB,KAAK,E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;kBALpC,SAAS;AACI,YAAA,IAAA,EAAA,CAAA,EAAA,QAAA,EAAA,qBAAqB,EACtB,OAAA,EAAA,CAAC,qBAAqB,EAAE,OAAO,CAAC,EAAA,QAAA,EAAA,4lBAAA,EAAA;;;AEP7C;;AAEG;;;;"}
|
|
1
|
+
{"version":3,"file":"sixbell-telco-sdk-components-toast.mjs","sources":["../../../projects/sdk/components/toast/services/toast.service.ts","../../../projects/sdk/components/toast/toast-message/toast-message.component.ts","../../../projects/sdk/components/toast/toast-message/toast-message.component.html","../../../projects/sdk/components/toast/toasts-container/toasts-container.component.ts","../../../projects/sdk/components/toast/toasts-container/toasts-container.component.html","../../../projects/sdk/components/toast/public-api.ts","../../../projects/sdk/components/toast/sixbell-telco-sdk-components-toast.ts"],"sourcesContent":["import { computed, Injectable, signal } from '@angular/core';\nimport { generateUniqueId } from '@sixbell-telco/sdk/utils/generators/uuid';\n\nexport enum ToastTypes {\n\tSUCCESS = 'toast-success',\n\tERROR = 'toast-error',\n\tINFO = 'toast-info',\n\tWARNING = 'toast-warning',\n}\n\nexport type Toast = {\n\tid: string;\n\ttype: ToastTypes;\n\tmessage: string;\n\ttitle: string;\n\tduration: number;\n\tanimate: 'enter' | 'leave';\n};\n\n/**\n * @deprecated This toast service is deprecated. Use @sixbell-telco/sdk/components/sonner instead.\n */\n@Injectable({\n\tprovidedIn: 'root',\n})\nexport class ToastService {\n\tprivate toastsSignal = signal<Toast[]>([]);\n\tprivate expandedSignal = signal(false);\n\n\t// Create computed signals for derived state\n\treadonly toasts = computed(() => this.toastsSignal());\n\treadonly expanded = computed(() => this.expandedSignal());\n\treadonly isEmpty = computed(() => this.toasts().length === 0);\n\n\tnotify(type: ToastTypes, message: string, title: string = '', duration: number = 10000) {\n\t\tconsole.warn('ToastService is deprecated. Migrate to @sixbell-telco/sdk/components/sonner.');\n\t\tconst toast: Toast = {\n\t\t\tid: generateUniqueId(),\n\t\t\ttype,\n\t\t\tmessage,\n\t\t\ttitle,\n\t\t\tduration,\n\t\t\tanimate: 'enter',\n\t\t};\n\n\t\t// Create a new array reference to ensure change detection\n\t\tthis.toastsSignal.update((toasts) => [toast, ...toasts]);\n\n\t\tthis.scheduleDismiss(toast);\n\t}\n\n\tscheduleDismiss(toast: Toast) {\n\t\tsetTimeout(() => {\n\t\t\tthis.remove(toast);\n\t\t}, toast.duration);\n\t}\n\n\tanimateRemoval(toast: Toast) {\n\t\tthis.toastsSignal.update((toasts) => toasts.map((t) => (t.id === toast.id ? { ...t, animate: 'leave' } : t)));\n\t}\n\n\tremove(toast: Toast) {\n\t\tthis.toastsSignal.update((toasts) => toasts.filter((t) => t.id !== toast.id));\n\n\t\tif (this.isEmpty()) {\n\t\t\tthis.collapse();\n\t\t}\n\t}\n\n\tclear() {\n\t\tthis.toastsSignal.set([]);\n\t\tthis.collapse();\n\t}\n\n\ttoggle() {\n\t\tthis.expandedSignal.update((expanded) => !expanded);\n\t}\n\n\tcollapse() {\n\t\tthis.expandedSignal.set(false);\n\t}\n\n\texpand() {\n\t\tthis.expandedSignal.set(true);\n\t}\n}\n","import { NgClass } from '@angular/common';\nimport { Component, computed, input, output } from '@angular/core';\nimport { IconComponent } from '@sixbell-telco/sdk/components/icon';\nimport { matCheckCircleOutline, matErrorOutline, matInfoOutline, matWarningOutline } from '@sixbell-telco/sdk/components/icon/material/outline';\nimport { TypographyDirective } from '@sixbell-telco/sdk/directives/typography';\nimport { cn } from '@sixbell-telco/sdk/utils/cn';\nimport { cva } from 'class-variance-authority';\nimport { Toast, ToastTypes } from '../services/toast.service';\n\nexport const toastComponent = cva(\n\t[\n\t\t'toast-message relative mb-2 flex min-h-20 h-20 w-[400px] cursor-pointer items-center rounded-lg border-2 bg-base-200 p-2 transition-all duration-300 ease-ease-in-and-out-back',\n\t],\n\t{\n\t\tvariants: {\n\t\t\tvariant: {\n\t\t\t\tinfo: ['border-primary', 'text-primary'],\n\t\t\t\tsuccess: ['border-success', 'text-success'],\n\t\t\t\twarning: ['border-warning', 'text-warning'],\n\t\t\t\terror: ['border-error', 'text-error'],\n\t\t\t},\n\t\t},\n\t\tcompoundVariants: [],\n\t\tdefaultVariants: {\n\t\t\tvariant: 'info',\n\t\t},\n\t},\n);\n\nexport type ToastVariantProps = 'info' | 'success' | 'warning' | 'error' | null | undefined;\n\nexport type ToastProps = {\n\tvariant?: ToastVariantProps;\n};\n\n/**\n * @deprecated This component is deprecated. Use @sixbell-telco/sdk/components/sonner instead.\n */\n@Component({\n\tselector: 'st-toast-message',\n\timports: [TypographyDirective, IconComponent, NgClass],\n\ttemplateUrl: './toast-message.component.html',\n})\nexport class ToastMessageComponent {\n\tvariant = input<ToastVariantProps>();\n\tclasses = input<string>('');\n\ttypes = ToastTypes;\n\ttoast = input.required<Toast>();\n\ttoastAmount = input.required<number>();\n\ttoastIndex = input.required<number>();\n\tclicked = output<Toast>();\n\ticonCheckCircle = matCheckCircleOutline;\n\ticonWarning = matWarningOutline;\n\ticonError = matErrorOutline;\n\ticonInfo = matInfoOutline;\n\n\tcomponentClass = computed(() => {\n\t\tconst toast = this.toast();\n\t\tconst classes = this.classes();\n\n\t\tswitch (toast.type) {\n\t\t\tcase this.types.SUCCESS:\n\t\t\t\treturn cn(toastComponent({ variant: 'success', class: classes }));\n\t\t\tcase this.types.ERROR:\n\t\t\t\treturn cn(toastComponent({ variant: 'error', class: classes }));\n\t\t\tcase this.types.WARNING:\n\t\t\t\treturn cn(toastComponent({ variant: 'warning', class: classes }));\n\t\t\tcase this.types.INFO:\n\t\t\t\treturn cn(toastComponent({ variant: 'info', class: classes }));\n\t\t\tdefault:\n\t\t\t\treturn cn(toastComponent({ variant: 'info', class: classes }));\n\t\t}\n\t});\n\n\thandleClose() {\n\t\tthis.clicked.emit(this.toast());\n\t}\n}\n","<!-- eslint-disable @angular-eslint/template/click-events-have-key-events -->\n<li\n\t[class]=\"componentClass()\"\n\t[ngClass]=\"{\n\t\t'animate-toast-slide-out bottom-0': toast().animate === 'leave' && toastAmount() > 1,\n\t\t'animate-slide-out': toast().animate === 'leave' && toastAmount() === 1,\n\t\t'animate-fade-out': toast().animate === 'leave' && toastAmount() > 1 && toastIndex() === 0,\n\t\t'animate-slide-in': toast().animate === 'enter',\n\t}\"\n\t(click)=\"handleClose()\"\n\trole=\"button\"\n\ttabindex=\"0\"\n>\n\t<div class=\"flex flex-1 items-center justify-center\">\n\t\t@if (this.toast().type === this.types.SUCCESS) {\n\t\t\t<st-icon [icon]=\"iconCheckCircle\" color=\"inherit\" size=\"md\"></st-icon>\n\t\t} @else if (this.toast().type === this.types.WARNING) {\n\t\t\t<st-icon [icon]=\"iconWarning\" color=\"inherit\" size=\"md\"></st-icon>\n\t\t} @else if (this.toast().type === this.types.ERROR) {\n\t\t\t<st-icon [icon]=\"iconError\" color=\"inherit\" size=\"md\"></st-icon>\n\t\t} @else if (this.toast().type === this.types.INFO) {\n\t\t\t<st-icon [icon]=\"iconInfo\" color=\"inherit\" size=\"md\"></st-icon>\n\t\t}\n\t</div>\n\t<div class=\"flex-4\">\n\t\t<div class=\"grid grid-rows-[min-content_1fr]\">\n\t\t\t<div typography [tyVariant]=\"'body-sm'\" [tyColor]=\"'base'\" [tyFontWeight]=\"'semibold'\">{{ toast().title }}</div>\n\t\t\t<div typography [tyVariant]=\"'body-xs'\" [tyColor]=\"'base'\" [tyFontWeight]=\"'normal'\">\n\t\t\t\t{{ toast().message }}\n\t\t\t</div>\n\t\t</div>\n\t</div>\n</li>\n","import { NgClass } from '@angular/common';\nimport { Component, computed, inject } from '@angular/core';\nimport { Toast, ToastService } from '../services/toast.service';\nimport { ToastMessageComponent } from '../toast-message/toast-message.component';\n\n/**\n * @deprecated This component is deprecated. Use @sixbell-telco/sdk/components/sonner instead.\n */\n@Component({\n\tselector: 'st-toasts-container',\n\timports: [ToastMessageComponent, NgClass],\n\ttemplateUrl: './toasts-container.component.html',\n})\nexport class ToastsContainerComponent {\n\ttoastService = inject(ToastService);\n\n\tprotected containerClasses = computed(() => {\n\t\tconst toastCount = this.toastService.toasts().length;\n\t\tconst isExpanded = this.toastService.expanded();\n\n\t\treturn {\n\t\t\t'min-h-64': toastCount === 3 && isExpanded,\n\t\t\t'min-h-48': toastCount === 2 && isExpanded,\n\t\t\t'h-24 min-h-24': toastCount === 1 && isExpanded,\n\t\t\t'h-28 min-h-28': toastCount > 0 && !isExpanded,\n\t\t\t'h-0 min-h-0': toastCount === 0 && !isExpanded,\n\t\t};\n\t});\n\n\thandleExpand(): void {\n\t\tthis.toastService.expand();\n\t}\n\n\thandleCollapse(): void {\n\t\tthis.toastService.collapse();\n\t}\n\n\thandleRemove(toast: Toast): void {\n\t\tthis.toastService.animateRemoval(toast);\n\t\tsetTimeout(() => {\n\t\t\tthis.toastService.remove(toast);\n\t\t}, 500);\n\t}\n\n\tgetToastIndex(toast: Toast): number {\n\t\treturn this.toastService.toasts().findIndex((t) => t.id === toast.id);\n\t}\n}\n","<section class=\"fixed right-4 bottom-2 z-[1001]\">\n\t<ol\n\t\tclass=\"toast-container group flex min-w-[400px] flex-col gap-2\"\n\t\t[ngClass]=\"containerClasses()\"\n\t\t[attr.aria-expanded]=\"toastService.expanded()\"\n\t\t(mouseenter)=\"handleExpand()\"\n\t\t(mouseleave)=\"handleCollapse()\"\n\t>\n\t\t@for (toast of toastService.toasts(); track toast.id) {\n\t\t\t<st-toast-message\n\t\t\t\t[toast]=\"toast\"\n\t\t\t\t[toastIndex]=\"getToastIndex(toast)\"\n\t\t\t\t[toastAmount]=\"toastService.toasts().length\"\n\t\t\t\t(clicked)=\"handleRemove($event)\"\n\t\t\t/>\n\t\t}\n\t</ol>\n</section>\n","/**\n * @deprecated This toast system is deprecated. Use @sixbell-telco/sdk/components/sonner instead.\n */\nexport * from './services/toast.service';\n/**\n * @deprecated This toast system is deprecated. Use @sixbell-telco/sdk/components/sonner instead.\n */\nexport * from './toast-message/toast-message.component';\n/**\n * @deprecated This toast system is deprecated. Use @sixbell-telco/sdk/components/sonner instead.\n */\nexport * from './toasts-container/toasts-container.component';\n","/**\n *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Y-MM-DD` and convert to the chosen format for display.
|
|
6
|
+
*/
|
|
7
|
+
const SUPPORTED_DATE_FORMATS = [
|
|
8
|
+
'DD/MM/YYYY', // Day/Month/Year (European)
|
|
9
|
+
'MM/DD/YYYY', // Month/Day/Year (US)
|
|
10
|
+
'YYYY-MM-DD', // Year-Month-Day (ISO)
|
|
11
|
+
'DD-MM-YYYY', // Day-Month-Year (European with dashes)
|
|
12
|
+
'MM-DD-YYYY', // Month-Day-Year (US with dashes)
|
|
13
|
+
'YYYY/MM/DD', // Year/Month/Day (ISO with slashes)
|
|
14
|
+
'DD.MM.YYYY', // Day.Month.Year (German style)
|
|
15
|
+
'MM.DD.YYYY', // Month.Day.Year (US with dots)
|
|
16
|
+
'YYYY.MM.DD', // Year.Month.Day (ISO with dots)
|
|
17
|
+
];
|
|
18
|
+
/**
|
|
19
|
+
* Supported time-only formats
|
|
20
|
+
*/
|
|
21
|
+
const SUPPORTED_TIME_FORMATS = ['HH:mm', 'HH:mm:ss'];
|
|
22
|
+
// Commonly used format constants
|
|
23
|
+
const ISO_DATE_FORMAT = 'YYYY-MM-DD';
|
|
24
|
+
const TIME_MINUTES_FORMAT = 'HH:mm';
|
|
25
|
+
const TIME_SECONDS_FORMAT = 'HH:mm:ss';
|
|
26
|
+
// 12-hour time format constants
|
|
27
|
+
const TIME_12H_MINUTES_FORMAT = 'h:mm A';
|
|
28
|
+
const TIME_12H_SECONDS_FORMAT = 'h:mm:ss A';
|
|
29
|
+
/**
|
|
30
|
+
* Reusable date utility service for date operations across the SDK.
|
|
31
|
+
* Provides consistent date handling, formatting, and range operations.
|
|
32
|
+
*/
|
|
33
|
+
class DateUtils {
|
|
34
|
+
/**
|
|
35
|
+
* Convert a date string to ISO format (YYYY-MM-DD)
|
|
36
|
+
*/
|
|
37
|
+
static toISODate(date, format) {
|
|
38
|
+
if (!date)
|
|
39
|
+
return '';
|
|
40
|
+
// If already ISO, return as-is to avoid misparsing when a display format is provided
|
|
41
|
+
if (/^\d{4}-\d{2}-\d{2}$/.test(date))
|
|
42
|
+
return date;
|
|
43
|
+
if (format && format !== 'YYYY-MM-DD') {
|
|
44
|
+
const parsed = dayjs(date, format, true);
|
|
45
|
+
return parsed.isValid() ? parsed.format('YYYY-MM-DD') : dayjs(date).format('YYYY-MM-DD');
|
|
46
|
+
}
|
|
47
|
+
return dayjs(date).format('YYYY-MM-DD');
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* Convert ISO date to display format
|
|
51
|
+
*/
|
|
52
|
+
static toDisplayDate(isoDate, format) {
|
|
53
|
+
if (!isoDate)
|
|
54
|
+
return '';
|
|
55
|
+
return dayjs(isoDate).format(format);
|
|
56
|
+
}
|
|
57
|
+
/** Build a combined date-time format string, e.g. `YYYY-MM-DD HH:mm:ss` */
|
|
58
|
+
static buildDateTimeFormat(dateFmt, timeFmt) {
|
|
59
|
+
return `${dateFmt} ${timeFmt}`;
|
|
60
|
+
}
|
|
61
|
+
/** Infer time format from a time string (returns seconds precision if length is 8) */
|
|
62
|
+
static inferTimeFormat(time) {
|
|
63
|
+
return time && time.length === 8 ? TIME_SECONDS_FORMAT : TIME_MINUTES_FORMAT;
|
|
64
|
+
}
|
|
65
|
+
/** Current time formatted per the provided time format */
|
|
66
|
+
static timeNow(format = TIME_SECONDS_FORMAT) {
|
|
67
|
+
return dayjs().format(format);
|
|
68
|
+
}
|
|
69
|
+
/** Milliseconds since epoch for now */
|
|
70
|
+
static nowMillis() {
|
|
71
|
+
return dayjs().valueOf();
|
|
72
|
+
}
|
|
73
|
+
/** Convert ISO date + time string into epoch milliseconds using provided time format */
|
|
74
|
+
static toMillis(isoDate, time, timeFmt) {
|
|
75
|
+
if (!isoDate || !time)
|
|
76
|
+
return null;
|
|
77
|
+
const fmt = this.buildDateTimeFormat(ISO_DATE_FORMAT, timeFmt);
|
|
78
|
+
const dt = dayjs(`${isoDate} ${time}`, fmt);
|
|
79
|
+
return dt.isValid() ? dt.valueOf() : null;
|
|
80
|
+
}
|
|
81
|
+
/** Whether a given ISO date equals today (local) */
|
|
82
|
+
static isTodayISO(isoDate) {
|
|
83
|
+
return !!isoDate && isoDate === this.today();
|
|
84
|
+
}
|
|
85
|
+
/** End-of-day string for the given time format */
|
|
86
|
+
static endOfDay(format) {
|
|
87
|
+
return format === TIME_SECONDS_FORMAT ? '23:59:59' : '23:59';
|
|
88
|
+
}
|
|
89
|
+
/** Start-of-day string for the given time format */
|
|
90
|
+
static startOfDay(format) {
|
|
91
|
+
return format === TIME_SECONDS_FORMAT ? '00:00:00' : '00:00';
|
|
92
|
+
}
|
|
93
|
+
/** Checks if the provided time string represents end-of-day */
|
|
94
|
+
static isEndOfDay(time) {
|
|
95
|
+
return time === '23:59' || time === '23:59:59';
|
|
96
|
+
}
|
|
97
|
+
/**
|
|
98
|
+
* Convert 24-hour time format to 12-hour format with AM/PM
|
|
99
|
+
* @param time24h Time in HH:mm or HH:mm:ss format
|
|
100
|
+
* @param includeSeconds Whether to include seconds in the output
|
|
101
|
+
* @returns Time in 12-hour format (h:mm A or h:mm:ss A)
|
|
102
|
+
*/
|
|
103
|
+
static to12HourFormat(time24h, includeSeconds = false) {
|
|
104
|
+
if (!time24h)
|
|
105
|
+
return '';
|
|
106
|
+
// Parse the time using dayjs
|
|
107
|
+
const timeFormat = includeSeconds ? TIME_SECONDS_FORMAT : TIME_MINUTES_FORMAT;
|
|
108
|
+
const timeObj = dayjs(`2000-01-01 ${time24h}`, `YYYY-MM-DD ${timeFormat}`);
|
|
109
|
+
if (!timeObj.isValid())
|
|
110
|
+
return time24h;
|
|
111
|
+
const outputFormat = includeSeconds ? TIME_12H_SECONDS_FORMAT : TIME_12H_MINUTES_FORMAT;
|
|
112
|
+
return timeObj.format(outputFormat);
|
|
113
|
+
}
|
|
114
|
+
/**
|
|
115
|
+
* Generate range value string for calendar components (ISO/ISO format)
|
|
116
|
+
*/
|
|
117
|
+
static toRangeValue(range) {
|
|
118
|
+
if (!range?.start || !range?.end)
|
|
119
|
+
return '';
|
|
120
|
+
return `${range.start}/${range.end}`;
|
|
121
|
+
}
|
|
122
|
+
/**
|
|
123
|
+
* Parse range value string from calendar components (ISO/ISO format)
|
|
124
|
+
*/
|
|
125
|
+
static parseRangeValue(value) {
|
|
126
|
+
if (!value?.includes('/'))
|
|
127
|
+
return null;
|
|
128
|
+
const [start, end] = value.split('/');
|
|
129
|
+
if (!start || !end)
|
|
130
|
+
return null;
|
|
131
|
+
return { start, end };
|
|
132
|
+
}
|
|
133
|
+
/**
|
|
134
|
+
* Generate quick range based on preset
|
|
135
|
+
*/
|
|
136
|
+
static generateQuickRange(preset) {
|
|
137
|
+
const today = dayjs();
|
|
138
|
+
let startDate;
|
|
139
|
+
switch (preset) {
|
|
140
|
+
case 'last7Days':
|
|
141
|
+
startDate = today.subtract(6, 'day'); // inclusive of today => 7 days
|
|
142
|
+
break;
|
|
143
|
+
case 'last30Days':
|
|
144
|
+
startDate = today.subtract(29, 'day');
|
|
145
|
+
break;
|
|
146
|
+
case 'last6Months':
|
|
147
|
+
startDate = today.subtract(6, 'month');
|
|
148
|
+
break;
|
|
149
|
+
case 'lastYear':
|
|
150
|
+
startDate = today.subtract(1, 'year');
|
|
151
|
+
break;
|
|
152
|
+
default:
|
|
153
|
+
throw new Error(`Unknown preset: ${preset}`);
|
|
154
|
+
}
|
|
155
|
+
return {
|
|
156
|
+
start: startDate.format('YYYY-MM-DD'),
|
|
157
|
+
end: today.format('YYYY-MM-DD'),
|
|
158
|
+
};
|
|
159
|
+
}
|
|
160
|
+
/**
|
|
161
|
+
* Generate a range representing the last N hours relative to now, including times.
|
|
162
|
+
* Returns ISO date range plus HH:mm:ss start/end time strings.
|
|
163
|
+
*/
|
|
164
|
+
static generateLastHoursRange(hours) {
|
|
165
|
+
const now = dayjs();
|
|
166
|
+
const start = now.subtract(hours, 'hour');
|
|
167
|
+
return {
|
|
168
|
+
range: {
|
|
169
|
+
start: start.format('YYYY-MM-DD'),
|
|
170
|
+
end: now.format('YYYY-MM-DD'),
|
|
171
|
+
},
|
|
172
|
+
startTime: start.format('HH:mm:ss'),
|
|
173
|
+
endTime: now.format('HH:mm:ss'),
|
|
174
|
+
};
|
|
175
|
+
}
|
|
176
|
+
/**
|
|
177
|
+
* Validate date range
|
|
178
|
+
*/
|
|
179
|
+
static isValidRange(range) {
|
|
180
|
+
if (!range?.start || !range?.end)
|
|
181
|
+
return false;
|
|
182
|
+
return dayjs(range.start).isValid() && dayjs(range.end).isValid();
|
|
183
|
+
}
|
|
184
|
+
/**
|
|
185
|
+
* Check if a date is valid
|
|
186
|
+
*/
|
|
187
|
+
static isValidDate(date) {
|
|
188
|
+
return dayjs(date).isValid();
|
|
189
|
+
}
|
|
190
|
+
/**
|
|
191
|
+
* Get today's date in ISO format
|
|
192
|
+
*/
|
|
193
|
+
static today() {
|
|
194
|
+
return dayjs().format('YYYY-MM-DD');
|
|
195
|
+
}
|
|
196
|
+
/**
|
|
197
|
+
* Get yesterday's date in ISO format
|
|
198
|
+
*/
|
|
199
|
+
static yesterday() {
|
|
200
|
+
return dayjs().subtract(1, 'day').format('YYYY-MM-DD');
|
|
201
|
+
}
|
|
202
|
+
/**
|
|
203
|
+
* Get tomorrow's date in ISO format
|
|
204
|
+
*/
|
|
205
|
+
static tomorrow() {
|
|
206
|
+
return dayjs().add(1, 'day').format('YYYY-MM-DD');
|
|
207
|
+
}
|
|
208
|
+
/**
|
|
209
|
+
* Add/subtract time from a date
|
|
210
|
+
*/
|
|
211
|
+
static addTime(date, amount, unit) {
|
|
212
|
+
return dayjs(date).add(amount, unit).format('YYYY-MM-DD');
|
|
213
|
+
}
|
|
214
|
+
/**
|
|
215
|
+
* Get difference between two dates
|
|
216
|
+
*/
|
|
217
|
+
static diff(date1, date2, unit = 'day') {
|
|
218
|
+
return dayjs(date1).diff(dayjs(date2), unit);
|
|
219
|
+
}
|
|
220
|
+
/**
|
|
221
|
+
* Check if date is between two dates (inclusive)
|
|
222
|
+
*/
|
|
223
|
+
static isBetween(date, start, end) {
|
|
224
|
+
const dateObj = dayjs(date);
|
|
225
|
+
const startObj = dayjs(start);
|
|
226
|
+
const endObj = dayjs(end);
|
|
227
|
+
return (dateObj.isAfter(startObj) || dateObj.isSame(startObj)) && (dateObj.isBefore(endObj) || dateObj.isSame(endObj));
|
|
228
|
+
}
|
|
229
|
+
/**
|
|
230
|
+
* Format date with custom pattern
|
|
231
|
+
*/
|
|
232
|
+
static format(date, pattern) {
|
|
233
|
+
return dayjs(date).format(pattern);
|
|
234
|
+
}
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
/**
|
|
238
|
+
* Generated bundle index. Do not edit.
|
|
239
|
+
*/
|
|
240
|
+
|
|
241
|
+
export { DateUtils, ISO_DATE_FORMAT, SUPPORTED_DATE_FORMATS, SUPPORTED_TIME_FORMATS, TIME_12H_MINUTES_FORMAT, TIME_12H_SECONDS_FORMAT, TIME_MINUTES_FORMAT, TIME_SECONDS_FORMAT };
|
|
242
|
+
//# sourceMappingURL=sixbell-telco-sdk-utils-date.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sixbell-telco-sdk-utils-date.mjs","sources":["../../../projects/sdk/utils/date/src/date-utils.ts","../../../projects/sdk/utils/date/sixbell-telco-sdk-utils-date.ts"],"sourcesContent":["import dayjs from 'dayjs';\n\n/**\n * Supported display / parsing formats for date utilities.\n * Internally all calculations use ISO `YYYY-MM-DD` and convert to the chosen format for display.\n */\nexport const SUPPORTED_DATE_FORMATS = [\n\t'DD/MM/YYYY', // Day/Month/Year (European)\n\t'MM/DD/YYYY', // Month/Day/Year (US)\n\t'YYYY-MM-DD', // Year-Month-Day (ISO)\n\t'DD-MM-YYYY', // Day-Month-Year (European with dashes)\n\t'MM-DD-YYYY', // Month-Day-Year (US with dashes)\n\t'YYYY/MM/DD', // Year/Month/Day (ISO with slashes)\n\t'DD.MM.YYYY', // Day.Month.Year (German style)\n\t'MM.DD.YYYY', // Month.Day.Year (US with dots)\n\t'YYYY.MM.DD', // Year.Month.Day (ISO with dots)\n] as const;\n\n/** Union type of all supported format strings. */\nexport type SupportedDateFormat = (typeof SUPPORTED_DATE_FORMATS)[number];\n\n/**\n * Supported time-only formats\n */\nexport const SUPPORTED_TIME_FORMATS = ['HH:mm', 'HH:mm:ss'] as const;\nexport type SupportedTimeFormat = (typeof SUPPORTED_TIME_FORMATS)[number];\n\n// Commonly used format constants\nexport const ISO_DATE_FORMAT: SupportedDateFormat = 'YYYY-MM-DD';\nexport const TIME_MINUTES_FORMAT: SupportedTimeFormat = 'HH:mm';\nexport const TIME_SECONDS_FORMAT: SupportedTimeFormat = 'HH:mm:ss';\n\n// 12-hour time format constants\nexport const TIME_12H_MINUTES_FORMAT = 'h:mm A';\nexport const TIME_12H_SECONDS_FORMAT = 'h:mm:ss A';\n\n// Application-wide default UI date display format\n\n/**\n * Quick action types for range picker\n */\nexport type QuickRangePreset = 'last7Days' | 'last30Days' | 'last6Months' | 'lastYear';\n\n/**\n * Date range representation\n */\nexport interface DateRange {\n\tstart: string;\n\tend: string;\n}\n\n/**\n * Reusable date utility service for date operations across the SDK.\n * Provides consistent date handling, formatting, and range operations.\n */\nexport class DateUtils {\n\t/**\n\t * Convert a date string to ISO format (YYYY-MM-DD)\n\t */\n\tstatic toISODate(date: string, format?: SupportedDateFormat): string {\n\t\tif (!date) return '';\n\t\t// If already ISO, return as-is to avoid misparsing when a display format is provided\n\t\tif (/^\\d{4}-\\d{2}-\\d{2}$/.test(date)) return date;\n\t\tif (format && format !== 'YYYY-MM-DD') {\n\t\t\tconst parsed = dayjs(date, format, true);\n\t\t\treturn parsed.isValid() ? parsed.format('YYYY-MM-DD') : dayjs(date).format('YYYY-MM-DD');\n\t\t}\n\t\treturn dayjs(date).format('YYYY-MM-DD');\n\t}\n\n\t/**\n\t * Convert ISO date to display format\n\t */\n\tstatic toDisplayDate(isoDate: string, format: SupportedDateFormat): string {\n\t\tif (!isoDate) return '';\n\t\treturn dayjs(isoDate).format(format);\n\t}\n\n\t/** Build a combined date-time format string, e.g. `YYYY-MM-DD HH:mm:ss` */\n\tstatic buildDateTimeFormat(dateFmt: SupportedDateFormat, timeFmt: SupportedTimeFormat): string {\n\t\treturn `${dateFmt} ${timeFmt}`;\n\t}\n\n\t/** Infer time format from a time string (returns seconds precision if length is 8) */\n\tstatic inferTimeFormat(time: string | null | undefined): SupportedTimeFormat {\n\t\treturn time && time.length === 8 ? TIME_SECONDS_FORMAT : TIME_MINUTES_FORMAT;\n\t}\n\n\t/** Current time formatted per the provided time format */\n\tstatic timeNow(format: SupportedTimeFormat = TIME_SECONDS_FORMAT): string {\n\t\treturn dayjs().format(format);\n\t}\n\n\t/** Milliseconds since epoch for now */\n\tstatic nowMillis(): number {\n\t\treturn dayjs().valueOf();\n\t}\n\n\t/** Convert ISO date + time string into epoch milliseconds using provided time format */\n\tstatic toMillis(isoDate: string, time: string, timeFmt: SupportedTimeFormat): number | null {\n\t\tif (!isoDate || !time) return null;\n\t\tconst fmt = this.buildDateTimeFormat(ISO_DATE_FORMAT, timeFmt);\n\t\tconst dt = dayjs(`${isoDate} ${time}`, fmt);\n\t\treturn dt.isValid() ? dt.valueOf() : null;\n\t}\n\n\t/** Whether a given ISO date equals today (local) */\n\tstatic isTodayISO(isoDate: string): boolean {\n\t\treturn !!isoDate && isoDate === this.today();\n\t}\n\n\t/** End-of-day string for the given time format */\n\tstatic endOfDay(format: SupportedTimeFormat): string {\n\t\treturn format === TIME_SECONDS_FORMAT ? '23:59:59' : '23:59';\n\t}\n\n\t/** Start-of-day string for the given time format */\n\tstatic startOfDay(format: SupportedTimeFormat): string {\n\t\treturn format === TIME_SECONDS_FORMAT ? '00:00:00' : '00:00';\n\t}\n\n\t/** Checks if the provided time string represents end-of-day */\n\tstatic isEndOfDay(time: string | null | undefined): boolean {\n\t\treturn time === '23:59' || time === '23:59:59';\n\t}\n\n\t/**\n\t * Convert 24-hour time format to 12-hour format with AM/PM\n\t * @param time24h Time in HH:mm or HH:mm:ss format\n\t * @param includeSeconds Whether to include seconds in the output\n\t * @returns Time in 12-hour format (h:mm A or h:mm:ss A)\n\t */\n\tstatic to12HourFormat(time24h: string, includeSeconds: boolean = false): string {\n\t\tif (!time24h) return '';\n\n\t\t// Parse the time using dayjs\n\t\tconst timeFormat = includeSeconds ? TIME_SECONDS_FORMAT : TIME_MINUTES_FORMAT;\n\t\tconst timeObj = dayjs(`2000-01-01 ${time24h}`, `YYYY-MM-DD ${timeFormat}`);\n\n\t\tif (!timeObj.isValid()) return time24h;\n\n\t\tconst outputFormat = includeSeconds ? TIME_12H_SECONDS_FORMAT : TIME_12H_MINUTES_FORMAT;\n\t\treturn timeObj.format(outputFormat);\n\t}\n\n\t/**\n\t * Generate range value string for calendar components (ISO/ISO format)\n\t */\n\tstatic toRangeValue(range: DateRange | null): string {\n\t\tif (!range?.start || !range?.end) return '';\n\t\treturn `${range.start}/${range.end}`;\n\t}\n\n\t/**\n\t * Parse range value string from calendar components (ISO/ISO format)\n\t */\n\tstatic parseRangeValue(value: string): DateRange | null {\n\t\tif (!value?.includes('/')) return null;\n\t\tconst [start, end] = value.split('/');\n\t\tif (!start || !end) return null;\n\t\treturn { start, end };\n\t}\n\n\t/**\n\t * Generate quick range based on preset\n\t */\n\tstatic generateQuickRange(preset: QuickRangePreset): DateRange {\n\t\tconst today = dayjs();\n\t\tlet startDate: dayjs.Dayjs;\n\n\t\tswitch (preset) {\n\t\t\tcase 'last7Days':\n\t\t\t\tstartDate = today.subtract(6, 'day'); // inclusive of today => 7 days\n\t\t\t\tbreak;\n\t\t\tcase 'last30Days':\n\t\t\t\tstartDate = today.subtract(29, 'day');\n\t\t\t\tbreak;\n\t\t\tcase 'last6Months':\n\t\t\t\tstartDate = today.subtract(6, 'month');\n\t\t\t\tbreak;\n\t\t\tcase 'lastYear':\n\t\t\t\tstartDate = today.subtract(1, 'year');\n\t\t\t\tbreak;\n\t\t\tdefault:\n\t\t\t\tthrow new Error(`Unknown preset: ${preset}`);\n\t\t}\n\n\t\treturn {\n\t\t\tstart: startDate.format('YYYY-MM-DD'),\n\t\t\tend: today.format('YYYY-MM-DD'),\n\t\t};\n\t}\n\n\t/**\n\t * Generate a range representing the last N hours relative to now, including times.\n\t * Returns ISO date range plus HH:mm:ss start/end time strings.\n\t */\n\tstatic generateLastHoursRange(hours: number): { range: DateRange; startTime: string; endTime: string } {\n\t\tconst now = dayjs();\n\t\tconst start = now.subtract(hours, 'hour');\n\t\treturn {\n\t\t\trange: {\n\t\t\t\tstart: start.format('YYYY-MM-DD'),\n\t\t\t\tend: now.format('YYYY-MM-DD'),\n\t\t\t},\n\t\t\tstartTime: start.format('HH:mm:ss'),\n\t\t\tendTime: now.format('HH:mm:ss'),\n\t\t};\n\t}\n\n\t/**\n\t * Validate date range\n\t */\n\tstatic isValidRange(range: DateRange | null): boolean {\n\t\tif (!range?.start || !range?.end) return false;\n\t\treturn dayjs(range.start).isValid() && dayjs(range.end).isValid();\n\t}\n\n\t/**\n\t * Check if a date is valid\n\t */\n\tstatic isValidDate(date: string): boolean {\n\t\treturn dayjs(date).isValid();\n\t}\n\n\t/**\n\t * Get today's date in ISO format\n\t */\n\tstatic today(): string {\n\t\treturn dayjs().format('YYYY-MM-DD');\n\t}\n\n\t/**\n\t * Get yesterday's date in ISO format\n\t */\n\tstatic yesterday(): string {\n\t\treturn dayjs().subtract(1, 'day').format('YYYY-MM-DD');\n\t}\n\n\t/**\n\t * Get tomorrow's date in ISO format\n\t */\n\tstatic tomorrow(): string {\n\t\treturn dayjs().add(1, 'day').format('YYYY-MM-DD');\n\t}\n\n\t/**\n\t * Add/subtract time from a date\n\t */\n\tstatic addTime(date: string, amount: number, unit: dayjs.ManipulateType): string {\n\t\treturn dayjs(date).add(amount, unit).format('YYYY-MM-DD');\n\t}\n\n\t/**\n\t * Get difference between two dates\n\t */\n\tstatic diff(date1: string, date2: string, unit: dayjs.QUnitType = 'day'): number {\n\t\treturn dayjs(date1).diff(dayjs(date2), unit);\n\t}\n\n\t/**\n\t * Check if date is between two dates (inclusive)\n\t */\n\tstatic isBetween(date: string, start: string, end: string): boolean {\n\t\tconst dateObj = dayjs(date);\n\t\tconst startObj = dayjs(start);\n\t\tconst endObj = dayjs(end);\n\t\treturn (dateObj.isAfter(startObj) || dateObj.isSame(startObj)) && (dateObj.isBefore(endObj) || dateObj.isSame(endObj));\n\t}\n\n\t/**\n\t * Format date with custom pattern\n\t */\n\tstatic format(date: string, pattern: string): string {\n\t\treturn dayjs(date).format(pattern);\n\t}\n}\n","/**\n * Generated bundle index. Do not edit.\n */\n\nexport * from './public-api';\n"],"names":[],"mappings":";;AAEA;;;AAGG;AACU,MAAA,sBAAsB,GAAG;AACrC,IAAA,YAAY;AACZ,IAAA,YAAY;AACZ,IAAA,YAAY;AACZ,IAAA,YAAY;AACZ,IAAA,YAAY;AACZ,IAAA,YAAY;AACZ,IAAA,YAAY;AACZ,IAAA,YAAY;AACZ,IAAA,YAAY;;AAMb;;AAEG;MACU,sBAAsB,GAAG,CAAC,OAAO,EAAE,UAAU;AAG1D;AACO,MAAM,eAAe,GAAwB;AAC7C,MAAM,mBAAmB,GAAwB;AACjD,MAAM,mBAAmB,GAAwB;AAExD;AACO,MAAM,uBAAuB,GAAG;AAChC,MAAM,uBAAuB,GAAG;AAiBvC;;;AAGG;MACU,SAAS,CAAA;AACrB;;AAEG;AACH,IAAA,OAAO,SAAS,CAAC,IAAY,EAAE,MAA4B,EAAA;AAC1D,QAAA,IAAI,CAAC,IAAI;AAAE,YAAA,OAAO,EAAE;;AAEpB,QAAA,IAAI,qBAAqB,CAAC,IAAI,CAAC,IAAI,CAAC;AAAE,YAAA,OAAO,IAAI;AACjD,QAAA,IAAI,MAAM,IAAI,MAAM,KAAK,YAAY,EAAE;YACtC,MAAM,MAAM,GAAG,KAAK,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,CAAC;YACxC,OAAO,MAAM,CAAC,OAAO,EAAE,GAAG,MAAM,CAAC,MAAM,CAAC,YAAY,CAAC,GAAG,KAAK,CAAC,IAAI,CAAC,CAA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E,OAAwB,KAAK,EAAA;AACtE,QAAA,OAAO,KAAK,CAAC,KAAK,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,EAAE,IAAI,CAAC;;AAG7C;;AAEG;AACH,IAAA,OAAO,SAAS,CAAC,IAAY,EAAE,KAAa,EAAE,GAAW,EAAA;AACxD,QAAA,MAAM,OAAO,GAAG,KAAK,CAAC,IAAI,CAAC;AAC3B,QAAA,MAAM,QAAQ,GAAG,KAAK,CAAC,KAAK,CAAC;AAC7B,QAAA,MAAM,MAAM,GAAG,KAAK,CAAC,GAAG,CAAC;AACzB,QAAA,OAAO,CAAC,OAAO,CAAC,OAAO,CAAC,QAAQ,CAAC,IAAI,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAC,MAAM,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAC,IAAI,OAAO,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC;;AAGvH;;AAEG;AACH,IAAA,OAAO,MAAM,CAAC,IAAY,EAAE,OAAe,EAAA;QAC1C,OAAO,KAAK,CAAC,IAAI,CAAC,CAAC,MAAM,CAAC,OAAO,CAAC;;AAEnC;;ACpRD;;AAEG;;;;"}
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Async utility helpers for reliable DOM synchronization and timing control.
|
|
3
|
+
* These utilities provide browser-native timing mechanisms that are more reliable
|
|
4
|
+
* than hardcoded setTimeout values across different environments and platforms.
|
|
5
|
+
*/
|
|
6
|
+
class SyncUtils {
|
|
7
|
+
/**
|
|
8
|
+
* Wait for next microtask (more reliable than setTimeout(0))
|
|
9
|
+
* Useful for ensuring state updates are processed before DOM operations
|
|
10
|
+
*/
|
|
11
|
+
static nextTick() {
|
|
12
|
+
return new Promise((resolve) => queueMicrotask(resolve));
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* Wait for next animation frame (better for DOM updates)
|
|
16
|
+
* Ideal for synchronizing with browser rendering cycles
|
|
17
|
+
*/
|
|
18
|
+
static nextFrame() {
|
|
19
|
+
return new Promise((resolve) => requestAnimationFrame(() => resolve()));
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Wait for DOM element to be available
|
|
23
|
+
* Useful for web components or dynamically created elements
|
|
24
|
+
*/
|
|
25
|
+
static async waitForElement(selector, maxAttempts = 10) {
|
|
26
|
+
for (let i = 0; i < maxAttempts; i++) {
|
|
27
|
+
const element = document.querySelector(selector);
|
|
28
|
+
if (element)
|
|
29
|
+
return element;
|
|
30
|
+
await this.nextFrame();
|
|
31
|
+
}
|
|
32
|
+
return null;
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Wait for a condition to be met with timeout
|
|
36
|
+
* Generic utility for polling-based waiting
|
|
37
|
+
*/
|
|
38
|
+
static async waitForCondition(condition, maxAttempts = 20, delayStrategy = 'tick') {
|
|
39
|
+
for (let i = 0; i < maxAttempts; i++) {
|
|
40
|
+
const result = await condition();
|
|
41
|
+
if (result)
|
|
42
|
+
return true;
|
|
43
|
+
if (delayStrategy === 'frame') {
|
|
44
|
+
await this.nextFrame();
|
|
45
|
+
}
|
|
46
|
+
else {
|
|
47
|
+
await this.nextTick();
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
return false;
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* Debounce utility for preventing rapid successive calls
|
|
54
|
+
* Returns a debounced version of the provided function
|
|
55
|
+
*/
|
|
56
|
+
static debounce(func, wait) {
|
|
57
|
+
let timeout;
|
|
58
|
+
return (...args) => {
|
|
59
|
+
clearTimeout(timeout);
|
|
60
|
+
timeout = window.setTimeout(() => func(...args), wait);
|
|
61
|
+
};
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* Throttle utility for limiting function execution frequency
|
|
65
|
+
* Returns a throttled version of the provided function
|
|
66
|
+
*/
|
|
67
|
+
static throttle(func, limit) {
|
|
68
|
+
let inThrottle = false;
|
|
69
|
+
return (...args) => {
|
|
70
|
+
if (!inThrottle) {
|
|
71
|
+
func(...args);
|
|
72
|
+
inThrottle = true;
|
|
73
|
+
setTimeout(() => (inThrottle = false), limit);
|
|
74
|
+
}
|
|
75
|
+
};
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
/**
|
|
80
|
+
* Generated bundle index. Do not edit.
|
|
81
|
+
*/
|
|
82
|
+
|
|
83
|
+
export { SyncUtils };
|
|
84
|
+
//# sourceMappingURL=sixbell-telco-sdk-utils-sync.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sixbell-telco-sdk-utils-sync.mjs","sources":["../../../projects/sdk/utils/sync/src/sync.ts","../../../projects/sdk/utils/sync/sixbell-telco-sdk-utils-sync.ts"],"sourcesContent":["/**\n * Async utility helpers for reliable DOM synchronization and timing control.\n * These utilities provide browser-native timing mechanisms that are more reliable\n * than hardcoded setTimeout values across different environments and platforms.\n */\nexport class SyncUtils {\n\t/**\n\t * Wait for next microtask (more reliable than setTimeout(0))\n\t * Useful for ensuring state updates are processed before DOM operations\n\t */\n\tstatic nextTick(): Promise<void> {\n\t\treturn new Promise((resolve) => queueMicrotask(resolve));\n\t}\n\n\t/**\n\t * Wait for next animation frame (better for DOM updates)\n\t * Ideal for synchronizing with browser rendering cycles\n\t */\n\tstatic nextFrame(): Promise<void> {\n\t\treturn new Promise((resolve) => requestAnimationFrame(() => resolve()));\n\t}\n\n\t/**\n\t * Wait for DOM element to be available\n\t * Useful for web components or dynamically created elements\n\t */\n\tstatic async waitForElement(selector: string, maxAttempts = 10): Promise<HTMLElement | null> {\n\t\tfor (let i = 0; i < maxAttempts; i++) {\n\t\t\tconst element = document.querySelector(selector) as HTMLElement;\n\t\t\tif (element) return element;\n\t\t\tawait this.nextFrame();\n\t\t}\n\t\treturn null;\n\t}\n\n\t/**\n\t * Wait for a condition to be met with timeout\n\t * Generic utility for polling-based waiting\n\t */\n\tstatic async waitForCondition(\n\t\tcondition: () => boolean | Promise<boolean>,\n\t\tmaxAttempts = 20,\n\t\tdelayStrategy: 'tick' | 'frame' = 'tick',\n\t): Promise<boolean> {\n\t\tfor (let i = 0; i < maxAttempts; i++) {\n\t\t\tconst result = await condition();\n\t\t\tif (result) return true;\n\n\t\t\tif (delayStrategy === 'frame') {\n\t\t\t\tawait this.nextFrame();\n\t\t\t} else {\n\t\t\t\tawait this.nextTick();\n\t\t\t}\n\t\t}\n\t\treturn false;\n\t}\n\n\t/**\n\t * Debounce utility for preventing rapid successive calls\n\t * Returns a debounced version of the provided function\n\t */\n\tstatic debounce<T extends (...args: unknown[]) => unknown>(func: T, wait: number): (...args: Parameters<T>) => void {\n\t\tlet timeout: number | undefined;\n\t\treturn (...args: Parameters<T>): void => {\n\t\t\tclearTimeout(timeout);\n\t\t\ttimeout = window.setTimeout(() => func(...args), wait);\n\t\t};\n\t}\n\n\t/**\n\t * Throttle utility for limiting function execution frequency\n\t * Returns a throttled version of the provided function\n\t */\n\tstatic throttle<T extends (...args: unknown[]) => unknown>(func: T, limit: number): (...args: Parameters<T>) => void {\n\t\tlet inThrottle = false;\n\t\treturn (...args: Parameters<T>): void => {\n\t\t\tif (!inThrottle) {\n\t\t\t\tfunc(...args);\n\t\t\t\tinThrottle = true;\n\t\t\t\tsetTimeout(() => (inThrottle = false), limit);\n\t\t\t}\n\t\t};\n\t}\n}\n","/**\n * Generated bundle index. Do not edit.\n */\n\nexport * from './public-api';\n"],"names":[],"mappings":"AAAA;;;;AAIG;MACU,SAAS,CAAA;AACrB;;;AAGG;AACH,IAAA,OAAO,QAAQ,GAAA;AACd,QAAA,OAAO,IAAI,OAAO,CAAC,CAAC,OAAO,KAAK,cAAc,CAAC,OAAO,CAAC,CAAC;;AAGzD;;;AAGG;AACH,IAAA,OAAO,SAAS,GAAA;AACf,QAAA,OAAO,IAAI,OAAO,CAAC,CAAC,OAAO,KAAK,qBAAqB,CAAC,MAAM,OAAO,EAAE,CAAC,CAAC;;AAGxE;;;AAGG;IACH,aAAa,cAA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