@naptics/vue-collection 0.3.2 → 1.0.0-beta.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.
Files changed (129) hide show
  1. package/eslint.config.cjs +0 -2
  2. package/package.json +31 -30
  3. package/postcss.config.js +1 -4
  4. package/src/demo/App.css +47 -3
  5. package/src/demo/components/ComponentSection.tsx +1 -1
  6. package/src/demo/views/NavigationView.tsx +1 -1
  7. package/src/demo/views/presentation/TooltipView.tsx +1 -1
  8. package/src/lib/components/NAlert.tsx +3 -3
  9. package/src/lib/components/NBadge.tsx +1 -1
  10. package/src/lib/components/NButton.tsx +6 -4
  11. package/src/lib/components/NCheckbox.tsx +2 -2
  12. package/src/lib/components/NDialog.tsx +2 -2
  13. package/src/lib/components/NDropdown.tsx +11 -9
  14. package/src/lib/components/NDropzone.tsx +4 -4
  15. package/src/lib/components/NIconButton.tsx +2 -2
  16. package/src/lib/components/NInput.tsx +1 -1
  17. package/src/lib/components/NLink.tsx +1 -1
  18. package/src/lib/components/NModal.tsx +4 -4
  19. package/src/lib/components/NPagination.css +4 -2
  20. package/src/lib/components/NPagination.tsx +1 -1
  21. package/src/lib/components/NSearchbar.tsx +1 -1
  22. package/src/lib/components/NSelect.tsx +1 -1
  23. package/src/lib/components/NSuggestionList.tsx +1 -1
  24. package/src/lib/components/NTable.css +2 -0
  25. package/src/lib/components/NTableAction.tsx +1 -1
  26. package/src/lib/components/NTextArea.tsx +1 -1
  27. package/src/lib/components/NTooltip.css +2 -0
  28. package/src/lib/components/NTooltip.tsx +1 -1
  29. package/src/lib/utils/component.tsx +1 -1
  30. package/tsconfig.lib.json +1 -0
  31. package/vite.config.ts +2 -0
  32. package/components/NAlert.d.ts +0 -29
  33. package/components/NAlert.js +0 -84
  34. package/components/NBadge.d.ts +0 -73
  35. package/components/NBadge.js +0 -64
  36. package/components/NBreadcrub.d.ts +0 -69
  37. package/components/NBreadcrub.js +0 -71
  38. package/components/NButton.d.ts +0 -64
  39. package/components/NButton.js +0 -72
  40. package/components/NCheckbox.d.ts +0 -20
  41. package/components/NCheckbox.js +0 -43
  42. package/components/NCheckboxLabel.d.ts +0 -26
  43. package/components/NCheckboxLabel.js +0 -42
  44. package/components/NCrudModal.d.ts +0 -118
  45. package/components/NCrudModal.js +0 -120
  46. package/components/NDialog.d.ts +0 -81
  47. package/components/NDialog.js +0 -161
  48. package/components/NDropdown.d.ts +0 -67
  49. package/components/NDropdown.js +0 -115
  50. package/components/NDropzone.d.ts +0 -61
  51. package/components/NDropzone.js +0 -218
  52. package/components/NForm.d.ts +0 -21
  53. package/components/NForm.js +0 -29
  54. package/components/NFormModal.d.ts +0 -75
  55. package/components/NFormModal.js +0 -59
  56. package/components/NIconButton.d.ts +0 -83
  57. package/components/NIconButton.js +0 -88
  58. package/components/NIconCircle.d.ts +0 -49
  59. package/components/NIconCircle.js +0 -67
  60. package/components/NInput.css +0 -11
  61. package/components/NInput.d.ts +0 -94
  62. package/components/NInput.js +0 -110
  63. package/components/NInputPhone.d.ts +0 -58
  64. package/components/NInputPhone.js +0 -47
  65. package/components/NInputSelect.d.ts +0 -103
  66. package/components/NInputSelect.js +0 -115
  67. package/components/NInputSuggestion.d.ts +0 -79
  68. package/components/NInputSuggestion.js +0 -64
  69. package/components/NLink.d.ts +0 -47
  70. package/components/NLink.js +0 -67
  71. package/components/NList.d.ts +0 -37
  72. package/components/NList.js +0 -40
  73. package/components/NLoadingIndicator.css +0 -46
  74. package/components/NLoadingIndicator.d.ts +0 -29
  75. package/components/NLoadingIndicator.js +0 -54
  76. package/components/NModal.d.ts +0 -133
  77. package/components/NModal.js +0 -232
  78. package/components/NPagination.css +0 -15
  79. package/components/NPagination.d.ts +0 -37
  80. package/components/NPagination.js +0 -105
  81. package/components/NSearchbar.d.ts +0 -39
  82. package/components/NSearchbar.js +0 -64
  83. package/components/NSearchbarList.d.ts +0 -33
  84. package/components/NSearchbarList.js +0 -41
  85. package/components/NSelect.d.ts +0 -82
  86. package/components/NSelect.js +0 -101
  87. package/components/NSuggestionList.d.ts +0 -153
  88. package/components/NSuggestionList.js +0 -160
  89. package/components/NTable.css +0 -3
  90. package/components/NTable.d.ts +0 -97
  91. package/components/NTable.js +0 -128
  92. package/components/NTableAction.d.ts +0 -30
  93. package/components/NTableAction.js +0 -50
  94. package/components/NTextArea.d.ts +0 -96
  95. package/components/NTextArea.js +0 -133
  96. package/components/NTooltip.css +0 -37
  97. package/components/NTooltip.d.ts +0 -152
  98. package/components/NTooltip.js +0 -241
  99. package/components/NValInput.d.ts +0 -159
  100. package/components/NValInput.js +0 -113
  101. package/components/ValidatedForm.d.ts +0 -39
  102. package/components/ValidatedForm.js +0 -35
  103. package/i18n/de/vue-collection.json +0 -58
  104. package/i18n/en/vue-collection.json +0 -58
  105. package/i18n/index.d.ts +0 -40
  106. package/i18n/index.js +0 -31
  107. package/index.d.ts +0 -2
  108. package/index.js +0 -2
  109. package/tailwind.config.js +0 -38
  110. package/utils/breakpoints.d.ts +0 -18
  111. package/utils/breakpoints.js +0 -40
  112. package/utils/component.d.ts +0 -57
  113. package/utils/component.js +0 -79
  114. package/utils/deferred.d.ts +0 -13
  115. package/utils/deferred.js +0 -17
  116. package/utils/identifiable.d.ts +0 -56
  117. package/utils/identifiable.js +0 -81
  118. package/utils/stringMaxLength.d.ts +0 -14
  119. package/utils/stringMaxLength.js +0 -23
  120. package/utils/tailwind.d.ts +0 -4
  121. package/utils/tailwind.js +0 -1
  122. package/utils/utils.d.ts +0 -47
  123. package/utils/utils.js +0 -56
  124. package/utils/vModel.d.ts +0 -182
  125. package/utils/vModel.js +0 -224
  126. package/utils/validation.d.ts +0 -90
  127. package/utils/validation.js +0 -147
  128. package/utils/vue.d.ts +0 -13
  129. package/utils/vue.js +0 -21
@@ -1,58 +0,0 @@
1
- {
2
- "title": {},
3
- "subtitle": {},
4
- "text": {
5
- "loading-search-results": "Loading results...",
6
- "no-search-results": "No results found for «{input}».",
7
- "drag-n-drop-files": "Select a file or add it by drag & drop. | Select up to {n} files or add them by drag & drop.",
8
- "files-selected": "No file selected. | One file selected. | {n} files selected."
9
- },
10
- "property": {},
11
- "term": {},
12
- "action": {
13
- "search": "Search",
14
- "select": "Select",
15
- "remove": "Delete",
16
- "cancel": "Cancel",
17
- "all-right": "All right",
18
- "proceed": "Continue",
19
- "save": "Save",
20
- "clear-files": "Clear. | Clear all."
21
- },
22
- "enum": {},
23
- "error": {
24
- "file-type": "One file has not been added as it is in the wrong format. | {n} files have not been added as they are in the wrong format.",
25
- "file-size": "One file has not been added as it exceeds the maximum file size. | {n} files have not been added as they exceed the maximum file size.",
26
- "too-many-files": "Only one file can be added. | Can not add more than {max} files."
27
- },
28
- "validation": {
29
- "rules": {
30
- "email": "This field must be a valid email address.",
31
- "integer": "This field must be an integer.",
32
- "length": {
33
- "min": "The text must not have less than {min} characters.",
34
- "max": "The text must not have more than {max} characters.",
35
- "min-max": "The text must have a length between {min} and {max} characters."
36
- },
37
- "matches": "The fields don't match.",
38
- "number-range": {
39
- "nan": "This filed must be a number.",
40
- "min": "The number must not be smaller than {min}.",
41
- "max": "The number must not be bigger than {max}.",
42
- "min-max": "The number must be in the range from {min} to {max}."
43
- },
44
- "option": "This field has to be an option from the list.",
45
- "password": {
46
- "to-short": "The password must have at least 8 characters.",
47
- "no-lowercase": "The password must contain a lowercase letter.",
48
- "no-uppercase": "The password must contain an uppercase letter.",
49
- "no-digits": "The password must contain a digit.",
50
- "no-special-chars": "The password must contain a special character.",
51
- "unknown": "This field does not match the required password format."
52
- },
53
- "phone": "This field must be a valid phone number.",
54
- "required": "This field is required.",
55
- "regex": "This field does not conform to the required format."
56
- }
57
- }
58
- }
package/i18n/index.d.ts DELETED
@@ -1,40 +0,0 @@
1
- import type { Nullish } from '../utils/utils';
2
- /**
3
- * @see {@link trsl}
4
- */
5
- export type TranslationFunction = typeof trsl;
6
- /**
7
- * @see {@link trslc}
8
- */
9
- export type TranslationCountFunction = typeof trslc;
10
- /**
11
- * A `TranslationProvider` has to implement the two functions `trsl` and `trslc`.
12
- */
13
- export type TranslationProvider = {
14
- trsl: TranslationFunction;
15
- trslc: TranslationCountFunction;
16
- };
17
- /**
18
- * Registeres a new translation provider for vue-collection.
19
- * The translation provider should contain all vue-collection
20
- * texts located under `i18n/<lang>/vue-collection.json`.
21
- * @param newProvider
22
- */
23
- export declare function registerTranslationProvider(newProvider: TranslationProvider): void;
24
- /**
25
- * Translates the specified key with the according message.
26
- * @param key the key to translate.
27
- * @param params formatting parameters for the message.
28
- * @returns the translated message.
29
- */
30
- export declare function trsl(key: string, params?: Record<string, unknown>): string;
31
- /**
32
- * Translates the specified key using pluralization.
33
- * The provided `count`is automatically passed as the parameter `n` to the translation library.
34
- * @param key the key to translate.
35
- * @param count the count used for the pluralization.
36
- * @param params formatting parameters for the message.
37
- * @returns the translated message.
38
- * @see trsl
39
- */
40
- export declare function trslc(key: string, count: Nullish<number>, params?: Record<string, unknown>): string;
package/i18n/index.js DELETED
@@ -1,31 +0,0 @@
1
- let provider = undefined;
2
- /**
3
- * Registeres a new translation provider for vue-collection.
4
- * The translation provider should contain all vue-collection
5
- * texts located under `i18n/<lang>/vue-collection.json`.
6
- * @param newProvider
7
- */
8
- export function registerTranslationProvider(newProvider) {
9
- provider = newProvider;
10
- }
11
- /**
12
- * Translates the specified key with the according message.
13
- * @param key the key to translate.
14
- * @param params formatting parameters for the message.
15
- * @returns the translated message.
16
- */
17
- export function trsl(key, params) {
18
- return provider?.trsl(key, params) ?? key;
19
- }
20
- /**
21
- * Translates the specified key using pluralization.
22
- * The provided `count`is automatically passed as the parameter `n` to the translation library.
23
- * @param key the key to translate.
24
- * @param count the count used for the pluralization.
25
- * @param params formatting parameters for the message.
26
- * @returns the translated message.
27
- * @see trsl
28
- */
29
- export function trslc(key, count, params) {
30
- return provider?.trslc(key, count, params) ?? key;
31
- }
package/index.d.ts DELETED
@@ -1,2 +0,0 @@
1
- import { createComponent, createView } from './utils/component';
2
- export { createComponent, createView };
package/index.js DELETED
@@ -1,2 +0,0 @@
1
- import { createComponent, createView } from './utils/component';
2
- export { createComponent, createView };
@@ -1,38 +0,0 @@
1
- const colors = require('tailwindcss/colors')
2
-
3
- const unresolvedConfig = require('tailwindcss/defaultConfig')
4
- const resolveConfig = require('tailwindcss/resolveConfig')
5
- const config = resolveConfig(unresolvedConfig)
6
-
7
- const allShades = '50|100|200|300|400|500|600|700|800|900'
8
- const usedColors = 'default|primary|secondary|green|red|yellow|blue'
9
- const smallSizes = '1|2|3|4|5|6|7|8|9|10|11|12|14|16|18|20'
10
-
11
- /** @type {import('tailwindcss').Config} */
12
- module.exports = {
13
- content: ['./src/**/*.{tsx,ts}'],
14
- safelist: [
15
- {
16
- pattern: new RegExp(`^(bg|text)-(${usedColors})-(${allShades})$`),
17
- variants: ['hover'],
18
- },
19
- {
20
- pattern: new RegExp(`^ring-(${usedColors})-(${allShades})$`),
21
- variants: ['focus-visible'],
22
- },
23
- {
24
- pattern: new RegExp(`^(w|h)-(${smallSizes})$`),
25
- },
26
- ],
27
- theme: {
28
- extend: {
29
- colors: {
30
- default: colors.slate,
31
- primary: colors.violet,
32
- secondary: colors.fuchsia,
33
- },
34
- minHeight: config.theme.spacing,
35
- },
36
- },
37
- plugins: [require('@tailwindcss/forms')],
38
- }
@@ -1,18 +0,0 @@
1
- import { type ComputedRef } from 'vue';
2
- export type TWBreakpoint = 'sm' | 'md' | 'lg' | 'xl' | '2xl';
3
- export declare const breakpoints: Readonly<Record<TWBreakpoint, number>>;
4
- export declare const bodyWidth: import("vue").Ref<number, number>;
5
- /**
6
- * This function has to be called once in the app two ensure that the breakpoint utilities actually update.
7
- * It sets a `window.onresize` listener.
8
- */
9
- export declare function addDocumentResizeEventListener(): void;
10
- /**
11
- * Returns a ref whose value is `true` as long as the `document.body.clientWitdh` is above the specified breakpoint.
12
- */
13
- export declare function isWidthBreakpoint(breakpoint: TWBreakpoint): ComputedRef<boolean>;
14
- export declare const isWidth2xl: ComputedRef<boolean>;
15
- export declare const isWidthXl: ComputedRef<boolean>;
16
- export declare const isWidthLg: ComputedRef<boolean>;
17
- export declare const isWidthMd: ComputedRef<boolean>;
18
- export declare const isWidthSm: ComputedRef<boolean>;
@@ -1,40 +0,0 @@
1
- import { computed, ref } from 'vue';
2
- export const breakpoints = {
3
- sm: 640,
4
- md: 768,
5
- lg: 1024,
6
- xl: 1280,
7
- '2xl': 1536
8
- };
9
- export const bodyWidth = ref(document.body.clientWidth);
10
- /**
11
- * This function has to be called once in the app two ensure that the breakpoint utilities actually update.
12
- * It sets a `window.onresize` listener.
13
- */
14
- export function addDocumentResizeEventListener() {
15
- window.onresize = () => {
16
- bodyWidth.value = document.body.clientWidth;
17
- };
18
- }
19
- /**
20
- * Returns a ref whose value is `true` as long as the `document.body.clientWitdh` is above the specified breakpoint.
21
- */
22
- export function isWidthBreakpoint(breakpoint) {
23
- switch (breakpoint) {
24
- case 'sm':
25
- return isWidthSm;
26
- case 'md':
27
- return isWidthMd;
28
- case 'lg':
29
- return isWidthLg;
30
- case 'xl':
31
- return isWidthXl;
32
- case '2xl':
33
- return isWidth2xl;
34
- }
35
- }
36
- export const isWidth2xl = computed(() => bodyWidth.value > breakpoints['2xl']);
37
- export const isWidthXl = computed(() => bodyWidth.value > breakpoints.xl);
38
- export const isWidthLg = computed(() => bodyWidth.value > breakpoints.lg);
39
- export const isWidthMd = computed(() => bodyWidth.value > breakpoints.md);
40
- export const isWidthSm = computed(() => bodyWidth.value > breakpoints.sm);
@@ -1,57 +0,0 @@
1
- import type { LooseRequired } from '@vue/shared';
2
- import { type ComponentObjectPropsOptions, type ExtractPropTypes, type RenderFunction, type SetupContext, type ToRefs, type UnwrapNestedRefs } from 'vue';
3
- import type { AnyObject } from './utils';
4
- type Data = Record<string, unknown>;
5
- export type Props<T extends Data = Data> = ComponentObjectPropsOptions<T>;
6
- /**
7
- * `ExtractedProps` maps a prop object to the props, which are received in the `setup` function of a components.
8
- */
9
- export type ExtractedProps<T extends Props> = Readonly<LooseRequired<Readonly<ExtractPropTypes<T>>>>;
10
- /**
11
- * Components should be created using this helper function.
12
- * It only takes three arguments, the name and the props of the component and the setup function.
13
- * All other arguments which the {@link defineComponent} method of vue may provide,
14
- * should not be used for a better consistency across all components.
15
- * @param name the name of the component, should be more than one word.
16
- * @param props the props of the component.
17
- * @param setup the setup function, which will be called when the component is mounted.
18
- * @returns the created vue-component.
19
- */
20
- export declare function createComponent<T extends Props>(name: string, props: T, setup: (props: ExtractedProps<T>, context: SetupContext<never[]>) => RenderFunction | Promise<RenderFunction>): import("vue").DefineSetupFnComponent<Record<string, any>, {}, {}, Record<string, any> & {}, import("vue").PublicProps>;
21
- /**
22
- * When using this function, the created component will make available all props
23
- * specifiedin `slotPropKeys` as slot. In this way, they can be used by either setting
24
- * the prop directly or by using a slot with the same name. This is useful for older
25
- * components (in `.vue` files), because they are dependent on slots.
26
- * @see {@link createComponent}
27
- */
28
- export declare function createComponentWithSlots<T extends Props>(name: string, props: T, slotPropKeys: SlotPropsKeys<ExtractedProps<T>>, setup: (props: ExtractedProps<T>, context: SetupContext<never[]>) => RenderFunction | Promise<RenderFunction>): import("vue").DefineSetupFnComponent<Record<string, any>, {}, {}, Record<string, any> & {}, import("vue").PublicProps>;
29
- /**
30
- * Views should be created using this helper function. Views are special components, which don't have props.
31
- * They are often the parent objects in a view hierarchy and contain many components.
32
- * This function is syntactic sugar to create views and just calls {@link createComponent}.
33
- * @param name the name of the component, should be more than one word.
34
- * @param setup the setup function, which will be called when the component is mounted.
35
- * @returns the created vue-component.
36
- */
37
- export declare function createView(name: string, setup: (context: SetupContext<never[]>) => RenderFunction | Promise<RenderFunction>): import("vue").DefineComponent<{}, RenderFunction, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, never[], never, import("vue").PublicProps, Readonly<{}> & Readonly<{}>, {}, {}, {}, {}, string, import("vue").ComponentProvideOptions, true, {}, any>;
38
- /**
39
- * Extracts props from another prop object and returns a reactive object with the specified props.
40
- * @param props the props to extract from
41
- * @param keys the keys to extract from the props
42
- * @returns the new object with the specified props
43
- * @example
44
- * const parentProps = { title: 'hi', text: 'ho' }
45
- * const childProps = extractProps(parentProps, 'title')
46
- * console.log(childProps) // { title: 'hi' }
47
- */
48
- export declare function extractProps<T extends Record<string, unknown>>(props: T, ...keys: (keyof T)[]): UnwrapNestedRefs<Partial<ToRefs<T>>>;
49
- type SlotFunction<Args extends any[] = any[]> = (...args: Args) => JSX.Element;
50
- /**
51
- * Filters object T to only have properties of type K.
52
- */
53
- type FilterObject<T, K> = {
54
- [P in keyof T as T[P] extends K ? P : never]: T[P];
55
- };
56
- type SlotPropsKeys<T extends AnyObject> = (keyof FilterObject<T, SlotFunction | undefined>)[];
57
- export {};
@@ -1,79 +0,0 @@
1
- import { defineComponent, reactive, toRef, toRefs, ref, Fragment as _Fragment, createVNode as _createVNode } from 'vue';
2
- /**
3
- * Components should be created using this helper function.
4
- * It only takes three arguments, the name and the props of the component and the setup function.
5
- * All other arguments which the {@link defineComponent} method of vue may provide,
6
- * should not be used for a better consistency across all components.
7
- * @param name the name of the component, should be more than one word.
8
- * @param props the props of the component.
9
- * @param setup the setup function, which will be called when the component is mounted.
10
- * @returns the created vue-component.
11
- */
12
- export function createComponent(name, props, setup) {
13
- // Vue 3.5's defineComponent has strict type requirements that don't align with our simplified API.
14
- // The type assertion is necessary because the generic setup function signature doesn't match
15
- // Vue's complex overloaded defineComponent types, even though the runtime behavior is correct.
16
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
17
- return defineComponent({
18
- name,
19
- props,
20
- emits: [],
21
- setup
22
- });
23
- }
24
- /**
25
- * When using this function, the created component will make available all props
26
- * specifiedin `slotPropKeys` as slot. In this way, they can be used by either setting
27
- * the prop directly or by using a slot with the same name. This is useful for older
28
- * components (in `.vue` files), because they are dependent on slots.
29
- * @see {@link createComponent}
30
- */
31
- export function createComponentWithSlots(name, props, slotPropKeys, setup) {
32
- const newSetup = (props, context) => {
33
- const slottedProps = createSlotProps(props, context.slots, ...slotPropKeys);
34
- return setup(slottedProps, context);
35
- };
36
- return createComponent(name, props, newSetup);
37
- }
38
- /**
39
- * Views should be created using this helper function. Views are special components, which don't have props.
40
- * They are often the parent objects in a view hierarchy and contain many components.
41
- * This function is syntactic sugar to create views and just calls {@link createComponent}.
42
- * @param name the name of the component, should be more than one word.
43
- * @param setup the setup function, which will be called when the component is mounted.
44
- * @returns the created vue-component.
45
- */
46
- export function createView(name, setup) {
47
- return defineComponent({
48
- name,
49
- emits: [],
50
- setup: (props, context) => setup(context)
51
- });
52
- }
53
- /**
54
- * Extracts props from another prop object and returns a reactive object with the specified props.
55
- * @param props the props to extract from
56
- * @param keys the keys to extract from the props
57
- * @returns the new object with the specified props
58
- * @example
59
- * const parentProps = { title: 'hi', text: 'ho' }
60
- * const childProps = extractProps(parentProps, 'title')
61
- * console.log(childProps) // { title: 'hi' }
62
- */
63
- export function extractProps(props, ...keys) {
64
- const partial = {};
65
- for (const key of keys) partial[key] = toRef(props, key);
66
- return reactive(partial);
67
- }
68
- function createSlotProps(props, slots, ...keys) {
69
- // create refs, don't touch all props which are not slots
70
- const newProps = toRefs(props);
71
- keys.forEach(key => {
72
- // if a slot is set once, it is basically always set. The changing content is not a problem as it is inside the function.
73
- const slot = slots[key];
74
- // if the slot is set, overwrite the props
75
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
76
- if (slot) newProps[key] = (...args) => _createVNode(_Fragment, null, [slot?.(...args)]);
77
- });
78
- return ref(newProps).value;
79
- }
@@ -1,13 +0,0 @@
1
- type PromiseResolve<T> = (value: T | PromiseLike<T>) => void;
2
- type PromiseReject = (reason?: unknown) => void;
3
- export type DeferredPromise<T> = {
4
- promise: Promise<T>;
5
- resolve: PromiseResolve<T>;
6
- reject: PromiseReject;
7
- };
8
- /**
9
- * Utlitity to return a deferred promise, which can be resolved from outside.
10
- * @returns promise, resolve and reject
11
- */
12
- export declare function deferred<T>(): DeferredPromise<T>;
13
- export {};
package/utils/deferred.js DELETED
@@ -1,17 +0,0 @@
1
- /**
2
- * Utlitity to return a deferred promise, which can be resolved from outside.
3
- * @returns promise, resolve and reject
4
- */
5
- export function deferred() {
6
- let resolve;
7
- let reject;
8
- const promise = new Promise((_resolve, _reject) => {
9
- resolve = _resolve;
10
- reject = _reject;
11
- });
12
- return {
13
- promise,
14
- resolve,
15
- reject
16
- };
17
- }
@@ -1,56 +0,0 @@
1
- import { type Nullish } from './utils';
2
- export type Identifiable<Id = string> = Readonly<{
3
- id: Id;
4
- }>;
5
- export type MaybeIdentifiable<Id = string> = Readonly<{
6
- id?: Nullish<Id>;
7
- }>;
8
- /**
9
- * Looks for the `id` in the given array of `Identifiables`.
10
- * @param array The array to search the item in.
11
- * @param id The `id` of the desired item.
12
- * @returns The first item with the specified `id` or `undefined` if none exists.
13
- */
14
- declare function find<Id, Item extends Identifiable<Id>>(array: Nullish<Item[]>, id: Id): Item | undefined;
15
- /**
16
- * Checks if the given array contains an item with the `id`.
17
- * @param array The array to search the item in.
18
- * @param id The `id` to check the array for.
19
- * @returns `true` if there is at least one item in the array with the given `id`.
20
- */
21
- declare function contains<Id, Item extends Identifiable<Id>>(array: Item[], id: Id): boolean;
22
- /**
23
- * Inserts the items into the given array, replacing items with the same `id`.
24
- * If no item with the same `id` exists, the item is appended to the array.
25
- * If multiple items with the same `id` exist, just the first item is replaced.
26
- * @param array The array to insert the items into.
27
- * @param insertItems The items to insert into the array.
28
- * @returns The reference to the same array, which was passed.
29
- */
30
- declare function insert<Id, Item extends Identifiable<Id>>(array: Item[], ...insertItems: Item[]): Item[];
31
- /**
32
- * Removes all items with the specified `ids` from the given array.
33
- * @param array The array to remove the items from.
34
- * @param ids The `ids` of the items which should be removed.
35
- * @returns The reference to the same array, which was passed.
36
- */
37
- declare function remove<Id, Item extends Identifiable>(array: Item[], ...ids: Id[]): Item[];
38
- /**
39
- * Compares the two arrays and checks if they both have
40
- * items with the same `ids` in the same order.
41
- * @param first The first array to compare.
42
- * @param second The second array to compare.
43
- * @returns `true` if the arrays contain item with the same `ids` in the same order.
44
- */
45
- declare function areSameArrays<Id>(first: Identifiable<Id>[], second: Identifiable<Id>[]): boolean;
46
- /**
47
- * This object contains utility functions to deal with {@link Identifiable} objects.
48
- */
49
- export declare const Id: {
50
- readonly find: typeof find;
51
- readonly contains: typeof contains;
52
- readonly insert: typeof insert;
53
- readonly remove: typeof remove;
54
- readonly areSameArrays: typeof areSameArrays;
55
- };
56
- export {};
@@ -1,81 +0,0 @@
1
- import { isNullish } from './utils';
2
- /**
3
- * Looks for the `id` in the given array of `Identifiables`.
4
- * @param array The array to search the item in.
5
- * @param id The `id` of the desired item.
6
- * @returns The first item with the specified `id` or `undefined` if none exists.
7
- */
8
- function find(array, id) {
9
- if (isNullish(array)) return undefined;
10
- const filtered = array.filter(item => item.id === id);
11
- if (filtered.length > 0) return filtered[0];else return undefined;
12
- }
13
- /**
14
- * Checks if the given array contains an item with the `id`.
15
- * @param array The array to search the item in.
16
- * @param id The `id` to check the array for.
17
- * @returns `true` if there is at least one item in the array with the given `id`.
18
- */
19
- function contains(array, id) {
20
- return find(array, id) !== undefined;
21
- }
22
- function insertSingle(baseArray, insertItem) {
23
- const index = baseArray.findIndex(item => item.id === insertItem.id);
24
- if (index === -1) {
25
- baseArray.push(insertItem);
26
- } else {
27
- baseArray.splice(index, 1, insertItem);
28
- }
29
- }
30
- /**
31
- * Inserts the items into the given array, replacing items with the same `id`.
32
- * If no item with the same `id` exists, the item is appended to the array.
33
- * If multiple items with the same `id` exist, just the first item is replaced.
34
- * @param array The array to insert the items into.
35
- * @param insertItems The items to insert into the array.
36
- * @returns The reference to the same array, which was passed.
37
- */
38
- function insert(array, ...insertItems) {
39
- insertItems.forEach(item => insertSingle(array, item));
40
- return array;
41
- }
42
- /**
43
- * Removes all items with the specified `ids` from the given array.
44
- * @param array The array to remove the items from.
45
- * @param ids The `ids` of the items which should be removed.
46
- * @returns The reference to the same array, which was passed.
47
- */
48
- function remove(array, ...ids) {
49
- ids.forEach(id => {
50
- let noMatches = false;
51
- while (!noMatches) {
52
- const index = array.findIndex(item => item.id === id);
53
- if (index != -1) array.splice(index, 1);else noMatches = true;
54
- }
55
- });
56
- return array;
57
- }
58
- /**
59
- * Compares the two arrays and checks if they both have
60
- * items with the same `ids` in the same order.
61
- * @param first The first array to compare.
62
- * @param second The second array to compare.
63
- * @returns `true` if the arrays contain item with the same `ids` in the same order.
64
- */
65
- function areSameArrays(first, second) {
66
- if (first.length != second.length) return false;
67
- for (let i = 0; i < first.length; i++) {
68
- if (first[i]?.id !== second[i]?.id) return false;
69
- }
70
- return true;
71
- }
72
- /**
73
- * This object contains utility functions to deal with {@link Identifiable} objects.
74
- */
75
- export const Id = {
76
- find,
77
- contains,
78
- insert,
79
- remove,
80
- areSameArrays
81
- };
@@ -1,14 +0,0 @@
1
- /**
2
- * Returns a shortened string with '...' at the end if it is longer than the given `maxLength`.
3
- * @param input the string to shorten
4
- * @param maxLength the max length
5
- * @see maxLengthSplitCenter
6
- */
7
- export declare function maxLength(input: string | null, maxLength: number): string;
8
- /**
9
- * Returns a shortened string with '...' in the center of the string if it is longer than the given `maxLength`.
10
- * @param input the string to shorten
11
- * @param maxLength the max length
12
- * @see maxLength
13
- */
14
- export declare function maxLengthSplitCenter(input: string | null, maxLength: number): string;
@@ -1,23 +0,0 @@
1
- /**
2
- * Returns a shortened string with '...' at the end if it is longer than the given `maxLength`.
3
- * @param input the string to shorten
4
- * @param maxLength the max length
5
- * @see maxLengthSplitCenter
6
- */
7
- export function maxLength(input, maxLength) {
8
- if (input && input.length > maxLength) return `${input.substring(0, maxLength - 3).trim()}...`;else return input || '';
9
- }
10
- /**
11
- * Returns a shortened string with '...' in the center of the string if it is longer than the given `maxLength`.
12
- * @param input the string to shorten
13
- * @param maxLength the max length
14
- * @see maxLength
15
- */
16
- export function maxLengthSplitCenter(input, maxLength) {
17
- if (input && input.length > maxLength) {
18
- const chars = maxLength - 3;
19
- const charsAtStart = Math.ceil(chars / 2);
20
- const charsAtEnd = Math.floor(chars / 2);
21
- return `${input.substring(0, charsAtStart).trim()}...${input.substring(input.length - charsAtEnd).trim()}`;
22
- } else return input || '';
23
- }
@@ -1,4 +0,0 @@
1
- import type { FunctionalComponent, HTMLAttributes, VNodeProps } from 'vue';
2
- export type TWTextSize = 'text-xs' | 'text-sm' | 'text-base' | 'text-lg' | 'text-xl' | 'text-2xl' | 'text-3xl' | 'text-4xl' | 'text-5xl' | 'text-6xl' | 'text-7xl' | 'text-8xl' | 'text-9xl';
3
- export type TWMaxWidth = 'max-w-xs' | 'max-w-sm' | 'max-w-md' | 'max-w-lg' | 'max-w-xl' | 'max-w-2xl' | 'max-w-3xl' | 'max-w-4xl' | 'max-w-5xl' | 'max-w-6xl' | 'max-w-7xl' | 'max-w-full' | 'max-w-min' | 'max-w-max' | 'max-w-fit' | 'max-w-prose' | 'max-w-screen-sm' | 'max-w-screen-md' | 'max-w-screen-lg' | 'max-w-screen-xl' | 'max-w-screen-2xl';
4
- export type HeroIcon = FunctionalComponent<HTMLAttributes & VNodeProps>;
package/utils/tailwind.js DELETED
@@ -1 +0,0 @@
1
- export {};
package/utils/utils.d.ts DELETED
@@ -1,47 +0,0 @@
1
- import type { Ref } from 'vue';
2
- export type Optional<T> = T | undefined;
3
- export type Nullable<T> = T | null;
4
- export type Nullish<T> = T | null | undefined;
5
- /**
6
- * Determines if a value is not null or undefined.
7
- * @param value the value to check
8
- * @returns `true` if the value is anything but `null` or `undefined`.
9
- */
10
- export declare function notNullish<T>(value: Nullish<T>): value is T;
11
- /**
12
- * Determines if a value is null or undefined.
13
- * @param value the value to check
14
- * @returns `true` if the value is `null` or `undefined`.
15
- */
16
- export declare function isNullish(value: Nullish<unknown>): value is null | undefined;
17
- /**
18
- * Determines if the value of a ref is not nullish.
19
- * @param ref the ref to check
20
- * @returns `true` if the value of the ref is not nullish.
21
- * @see notNullish
22
- */
23
- export declare function notNullishRef<T>(ref: Ref<T>): ref is Ref<NonNullable<T>>;
24
- /**
25
- * Determines if the value of a ref is null or undefined.
26
- * @param ref the ref to check
27
- * @returns `true` if the value of the ref is `null` or `undefined`.
28
- * @see isNullish
29
- */
30
- export declare function isNullishRef(ref: Ref<Nullish<unknown>>): ref is Ref<null | undefined>;
31
- export type AnyObject = Record<string | number | symbol, unknown>;
32
- export type EmptyObject = Record<string | number | symbol, never>;
33
- export declare function isAnyObject(object: unknown): object is AnyObject;
34
- /**
35
- * Marks all properties of an object (including sub-objects) as readonly.
36
- */
37
- export type ReadonlyObject<T extends AnyObject> = {
38
- readonly [P in keyof T]: T[P] extends ReadonlyObject<infer _U> ? T[P] : T[P] extends AnyObject ? ReadonlyObject<T[P]> : T[P];
39
- };
40
- /**
41
- * Returns the same object casted to a {@link ReadonlyObject}.
42
- */
43
- export declare function readonlyObject<T extends AnyObject>(object: T): ReadonlyObject<T>;
44
- /**
45
- * Generates and returns a non random but unique id.
46
- */
47
- export declare function uniqueId(): number;