@bagelink/vue 0.0.22 → 0.0.32

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 (82) hide show
  1. package/package.json +32 -9
  2. package/src/components/Btn.vue +221 -0
  3. package/src/components/Comments.vue +265 -0
  4. package/src/components/ContactArray.vue +127 -0
  5. package/src/components/ContactSubmissions.vue +42 -0
  6. package/src/components/DataPreview.vue +72 -0
  7. package/src/components/DropDown.vue +122 -0
  8. package/src/components/FileUploader.vue +344 -0
  9. package/src/components/FormKitTable.vue +250 -0
  10. package/src/components/FormSchema.vue +65 -0
  11. package/src/components/LangText.vue +30 -0
  12. package/src/components/ListItem.vue +16 -0
  13. package/src/components/ListView.vue +39 -0
  14. package/src/components/MaterialIcon.vue +16 -0
  15. package/src/components/Modal.vue +50 -0
  16. package/src/components/ModalForm.vue +94 -0
  17. package/src/components/NavBar.vue +343 -0
  18. package/src/components/PageTitle.vue +17 -0
  19. package/src/components/PersonPreview.vue +205 -0
  20. package/src/components/PersonPreviewFormkit.vue +205 -0
  21. package/src/components/RTXEditor.vue +147 -0
  22. package/src/components/RouterWrapper.vue +9 -0
  23. package/src/components/TabbedLayout.vue +80 -0
  24. package/src/components/TableSchema.vue +213 -0
  25. package/src/components/TopBar.vue +5 -0
  26. package/src/components/charts/BarChart.vue +290 -0
  27. package/src/components/dashboard/Lineart.vue +165 -0
  28. package/src/components/form/ItemRef.vue +38 -0
  29. package/src/components/form/MaterialIcon.vue +19 -0
  30. package/src/components/form/PlainInputField.vue +80 -0
  31. package/src/components/form/inputs/CheckInput.vue +143 -0
  32. package/src/components/form/inputs/Checkbox.vue +69 -0
  33. package/src/components/form/inputs/ColorPicker.vue +37 -0
  34. package/src/components/form/inputs/CurrencyInput.vue +133 -0
  35. package/src/components/form/inputs/DateInput.vue +49 -0
  36. package/src/components/form/inputs/DatetimeInput.vue +46 -0
  37. package/src/components/form/inputs/DurationInput.vue +51 -0
  38. package/src/components/form/inputs/DynamicLinkField.vue +140 -0
  39. package/src/components/form/inputs/EmailInput.vue +53 -0
  40. package/src/components/form/inputs/FloatInput.vue +48 -0
  41. package/src/components/form/inputs/IntInput.vue +49 -0
  42. package/src/components/form/inputs/JSONInput.vue +51 -0
  43. package/src/components/form/inputs/LinkField.vue +293 -0
  44. package/src/components/form/inputs/Password.vue +89 -0
  45. package/src/components/form/inputs/PasswordInput.vue +89 -0
  46. package/src/components/form/inputs/PlainText.vue +52 -0
  47. package/src/components/form/inputs/ReadOnlyInput.vue +24 -0
  48. package/src/components/form/inputs/RichTextEditor.vue +54 -0
  49. package/src/components/form/inputs/SelectField.vue +253 -0
  50. package/src/components/form/inputs/TableField.vue +321 -0
  51. package/src/components/form/inputs/TextArea.vue +70 -0
  52. package/src/components/form/inputs/TextInput.vue +53 -0
  53. package/src/components/form/inputs/index.ts +17 -0
  54. package/src/components/formkit/AddressArray.vue +240 -0
  55. package/src/components/formkit/BankDetailsArray.vue +265 -0
  56. package/src/components/formkit/ContactArrayFormKit.vue +151 -0
  57. package/src/components/formkit/FileUploader.vue +391 -0
  58. package/src/components/formkit/MiscFields.vue +69 -0
  59. package/src/components/formkit/Toggle.vue +160 -0
  60. package/src/components/formkit/index.ts +29 -0
  61. package/src/components/index.ts +20 -0
  62. package/src/components/whatsapp/form/MsgTemplate.vue +220 -0
  63. package/src/components/whatsapp/form/TextVariableExamples.vue +74 -0
  64. package/src/components/whatsapp/interfaces.ts +58 -0
  65. package/src/index.ts +1 -26
  66. package/src/plugins/bagel.ts +26 -0
  67. package/src/styles/modal.css +90 -0
  68. package/src/types/BagelField.ts +57 -0
  69. package/src/types/BtnOptions.ts +14 -0
  70. package/src/types/Person.ts +51 -0
  71. package/src/types/file.ts +12 -0
  72. package/src/types/index.ts +4 -0
  73. package/src/types/materialIcons.d.ts +3005 -0
  74. package/src/utils/index.ts +57 -0
  75. package/src/utils/modal.ts +95 -0
  76. package/src/utils/objects.ts +81 -0
  77. package/src/utils/strings.ts +29 -0
  78. package/dist/index.cjs +0 -23
  79. package/dist/index.d.cts +0 -12
  80. package/dist/index.d.mts +0 -12
  81. package/dist/index.d.ts +0 -12
  82. package/dist/index.mjs +0 -19
@@ -0,0 +1,57 @@
1
+ import { inject } from 'vue';
2
+ import { useModal } from './modal';
3
+ import type { BagelField } from '@/types/BagelField';
4
+
5
+ let timeout: any;
6
+ const debounce = (fn: () => void, delay = 500) => {
7
+ clearTimeout(timeout);
8
+ timeout = setTimeout(fn, delay);
9
+ };
10
+
11
+ export const keyToLabel = (key: string) => key
12
+ .split('_')
13
+ .map((k) => k.charAt(0).toUpperCase() + k.slice(1))
14
+ .join(' ');
15
+
16
+ export function computeFields(modelValue: Record<string, any>): BagelField[] {
17
+ const fields = [];
18
+ for (const key of Object.keys(modelValue)) {
19
+ const field: BagelField = {
20
+ label: keyToLabel(key),
21
+ id: key,
22
+ inputType: 'PlainText',
23
+ };
24
+ if (typeof modelValue[key] === 'string') field.inputType = 'PlainText';
25
+ if (typeof modelValue[key] === 'number') field.inputType = 'NumberInput';
26
+ if (modelValue[key] === true || modelValue[key] === false) field.inputType = 'CheckInput';
27
+ if (
28
+ modelValue[key] instanceof Date
29
+ || !Number.isNaN(Date.parse(modelValue[key]))
30
+ ) field.inputType = 'DateInput';
31
+
32
+ fields.push(field);
33
+ }
34
+ return fields;
35
+ }
36
+
37
+ const copyText = async (text: string, cb?: (msg: string) => void) => {
38
+ await navigator.clipboard.writeText(text);
39
+ if (cb) cb('Copied to clipboard');
40
+ };
41
+
42
+ export const useFormkit = () => {
43
+ const formkit = inject('FormKitConfig');
44
+ return formkit;
45
+ };
46
+
47
+ export const initials = (...strArr: string[]) => strArr.map((str) => str?.charAt(0)).join('');
48
+
49
+ export const parseLocale = (str: string, $t = (str: string) => str) => {
50
+ const [_, w] = str.split(/\$t\('?"?|'?"?\)/);
51
+ if (!w) return str;
52
+ return $t(w);
53
+ };
54
+
55
+ export {
56
+ debounce, copyText, useModal,
57
+ };
@@ -0,0 +1,95 @@
1
+ import {
2
+ h, InjectionKey, ref, inject, defineComponent,
3
+ } from 'vue';
4
+ import type { Plugin } from 'vue';
5
+ import { Modal, ModalForm } from '@/components';
6
+ import { BtnOptions } from '../types/BtnOptions';
7
+
8
+ interface ModalOptions {
9
+ title?: string;
10
+ dismissable?: boolean;
11
+ side?: boolean;
12
+ actions?: BtnOptions[];
13
+ class?: string;
14
+ }
15
+
16
+ interface ModalFormOptions extends ModalOptions {
17
+ modelValue?: any;
18
+ 'onUpdate:modelValue'?: (val: any) => void;
19
+ onSubmit: (val: any) => void;
20
+ onDelete?: (id: string) => void;
21
+ schema: any;
22
+ }
23
+
24
+ interface ModalApi {
25
+ showModal: (options: ModalOptions, slots?: Record<string, any>) => void;
26
+ modalForm: (options: ModalFormOptions, slots?: Record<string, any>) => void;
27
+ hideModal: (index?: number) => void;
28
+ // modalOptions: Ref<ModalOptions | ModalFormOptions>;
29
+ }
30
+
31
+ const ModalSymbol: InjectionKey<ModalApi> = Symbol('modal');
32
+
33
+ export const useModal = (): ModalApi => {
34
+ const modalApi = inject(ModalSymbol);
35
+ if (!modalApi) throw new Error('Modal API not provided');
36
+ return modalApi;
37
+ };
38
+
39
+ interface ModalComponentProps {
40
+ componentSlots: Record<string, any>,
41
+ isModalForm: boolean,
42
+ modalOptions: ModalOptions | ModalFormOptions
43
+ }
44
+
45
+ export const ModalPlugin: Plugin = {
46
+ install: (app) => {
47
+ const modalStack = ref<ModalComponentProps[]>([]);
48
+ const showModal = (
49
+ isForm: boolean,
50
+ options: ModalOptions | ModalFormOptions,
51
+ slots: Record<string, any> = {},
52
+ ) => {
53
+ modalStack.value.push({
54
+ modalOptions: options,
55
+ isModalForm: isForm,
56
+ componentSlots: slots,
57
+ });
58
+ };
59
+
60
+ const hideModal = (index: number) => {
61
+ // console.log('hideModal', index);
62
+ modalStack.value.splice(index, 1);
63
+ };
64
+
65
+ app.provide(ModalSymbol, {
66
+ modalForm: (options: ModalFormOptions, slots?: Record<string, any>) => showModal(true, options, slots),
67
+ showModal: (options: ModalOptions, slots?: Record<string, any>) => showModal(false, options, slots),
68
+ hideModal: (index = modalStack.value.length - 1) => hideModal(index),
69
+ // modalOptions,
70
+ });
71
+ const ModalComponent = defineComponent({
72
+ data() {
73
+ return {
74
+ modalStack,
75
+ };
76
+ },
77
+ render() {
78
+ return modalStack.value.map((modal, index) => {
79
+ const renderComponent = modal.isModalForm ? ModalForm : Modal;
80
+ return h(
81
+ renderComponent,
82
+ {
83
+ ...modal.modalOptions,
84
+ 'onUpdate:isModalVisible': () => hideModal(index),
85
+ },
86
+ modal.componentSlots,
87
+ );
88
+ });
89
+ },
90
+ });
91
+ app.component('ModalContainer', ModalComponent);
92
+ },
93
+ };
94
+
95
+ export default ModalPlugin;
@@ -0,0 +1,81 @@
1
+ import { BagelField } from '@/types';
2
+
3
+ function returnTypes(bagelField?: BagelField) {
4
+ if (bagelField?.is_array) return [];
5
+ if (bagelField?.inputType === 'BagelForm') return {};
6
+ if (bagelField?.inputType === 'CheckInput') return false;
7
+ return '';
8
+ }
9
+
10
+ export function getPropByPath(
11
+ obj: Record<string, any>,
12
+ propPath?: string,
13
+ bagelField?: BagelField,
14
+ ) {
15
+ // Return the object if the path is empty or the object is not an 'object' type
16
+ if (!propPath || typeof obj !== 'object') return obj;
17
+
18
+ const props = propPath.split(/\.|\[(\d+)\]/).filter(Boolean);
19
+ let result = obj;
20
+ for (const prop of props) {
21
+ if (result !== null && typeof result === 'object' && prop in result) {
22
+ result = result[prop];
23
+ } else {
24
+ return bagelField ? returnTypes(bagelField) : '';
25
+ }
26
+ }
27
+ return result;
28
+ }
29
+
30
+ export function setPropByPath(
31
+ obj: Record<string, any>,
32
+ path?: string,
33
+ value?: any,
34
+ ) {
35
+ const keys = path?.split(/\.|\[(\d+)\]/)?.filter(Boolean) || [];
36
+ let current = obj;
37
+
38
+ for (let i = 0; i < keys.length - 1; i++) {
39
+ const key = keys[i];
40
+ const nextKey = keys[i + 1];
41
+
42
+ const nextIsArrayIndex = !Number.isNaN(parseInt(nextKey, 10));
43
+
44
+ if (!current[key]) {
45
+ current[key] = nextIsArrayIndex ? [] : {};
46
+ } else if (typeof current[key] !== 'object') {
47
+ throw new Error(
48
+ `Cannot set property '${keys
49
+ .slice(i)
50
+ .join('.')}', object or array expected`,
51
+ );
52
+ }
53
+ current = current[key];
54
+ }
55
+ current[keys[keys.length - 1]] = value;
56
+ }
57
+
58
+ // export function setPropByPath(
59
+ // obj: Record<string, any>,
60
+ // propPath: string,
61
+ // value: any,
62
+ // ) {
63
+ // // console.log('getPropByPath', obj, { propPath });
64
+ // if (!propPath || typeof obj !== 'object') return obj;
65
+
66
+ // const props = propPath.split(/\.|\[(\d+)\]/).filter(Boolean);
67
+ // let result = obj;
68
+ // console.log(props);
69
+ // for (let i = 0; i < props.length; i++) {
70
+ // const prop = props[i];
71
+ // if (i === props.length - 1) {
72
+ // result[prop] = value;
73
+ // } else if (result && prop in result) {
74
+ // result = result[prop];
75
+ // } else {
76
+ // return undefined;
77
+ // }
78
+ // }
79
+
80
+ // return result;
81
+ // }
@@ -0,0 +1,29 @@
1
+ export function formatString(
2
+ str: string,
3
+ format: 'pascal' | 'camel' | 'snake',
4
+ ): string {
5
+ if (format === 'pascal') {
6
+ return str
7
+ .split('_')
8
+ .map((word) => word[0].toUpperCase() + word.slice(1).toLocaleLowerCase())
9
+ .join('');
10
+ }
11
+ if (format === 'camel') {
12
+ return str
13
+ .split('_')
14
+ .map((word, index) => (index === 0 ? word : word[0].toUpperCase() + word.slice(1)))
15
+ .join('');
16
+ }
17
+ if (format === 'snake') {
18
+ return str
19
+ .split('')
20
+ .map((letter) => {
21
+ if (letter === letter.toUpperCase()) {
22
+ return `_${letter.toLowerCase()}`;
23
+ }
24
+ return letter;
25
+ })
26
+ .join('');
27
+ }
28
+ return str;
29
+ }
package/dist/index.cjs DELETED
@@ -1,23 +0,0 @@
1
- 'use strict';
2
-
3
- const vue = require('vue');
4
- const sdk = require('@bagelink/sdk');
5
-
6
- const bagelInjectionKey = Symbol("bagel");
7
- function useBagel() {
8
- const bagel = vue.inject(bagelInjectionKey);
9
- if (!bagel)
10
- throw new Error("No bagel provided");
11
- return bagel;
12
- }
13
- const BagelVue = {
14
- install: (app, options) => {
15
- const bagel = new sdk.Bagel({ host: options.host, onError: options.onError });
16
- app.config.globalProperties.$bagel = bagel;
17
- app.provide(bagelInjectionKey, bagel);
18
- }
19
- };
20
-
21
- exports.BagelVue = BagelVue;
22
- exports.bagelInjectionKey = bagelInjectionKey;
23
- exports.useBagel = useBagel;
package/dist/index.d.cts DELETED
@@ -1,12 +0,0 @@
1
- import { InjectionKey, Plugin } from 'vue';
2
- import { Bagel } from '@bagelink/sdk';
3
-
4
- declare const bagelInjectionKey: InjectionKey<Bagel>;
5
- declare function useBagel(): Bagel;
6
- interface BagelOptions {
7
- host: string;
8
- onError?: (err: Error) => void;
9
- }
10
- declare const BagelVue: Plugin;
11
-
12
- export { type BagelOptions, BagelVue, bagelInjectionKey, useBagel };
package/dist/index.d.mts DELETED
@@ -1,12 +0,0 @@
1
- import { InjectionKey, Plugin } from 'vue';
2
- import { Bagel } from '@bagelink/sdk';
3
-
4
- declare const bagelInjectionKey: InjectionKey<Bagel>;
5
- declare function useBagel(): Bagel;
6
- interface BagelOptions {
7
- host: string;
8
- onError?: (err: Error) => void;
9
- }
10
- declare const BagelVue: Plugin;
11
-
12
- export { type BagelOptions, BagelVue, bagelInjectionKey, useBagel };
package/dist/index.d.ts DELETED
@@ -1,12 +0,0 @@
1
- import { InjectionKey, Plugin } from 'vue';
2
- import { Bagel } from '@bagelink/sdk';
3
-
4
- declare const bagelInjectionKey: InjectionKey<Bagel>;
5
- declare function useBagel(): Bagel;
6
- interface BagelOptions {
7
- host: string;
8
- onError?: (err: Error) => void;
9
- }
10
- declare const BagelVue: Plugin;
11
-
12
- export { type BagelOptions, BagelVue, bagelInjectionKey, useBagel };
package/dist/index.mjs DELETED
@@ -1,19 +0,0 @@
1
- import { inject } from 'vue';
2
- import { Bagel } from '@bagelink/sdk';
3
-
4
- const bagelInjectionKey = Symbol("bagel");
5
- function useBagel() {
6
- const bagel = inject(bagelInjectionKey);
7
- if (!bagel)
8
- throw new Error("No bagel provided");
9
- return bagel;
10
- }
11
- const BagelVue = {
12
- install: (app, options) => {
13
- const bagel = new Bagel({ host: options.host, onError: options.onError });
14
- app.config.globalProperties.$bagel = bagel;
15
- app.provide(bagelInjectionKey, bagel);
16
- }
17
- };
18
-
19
- export { BagelVue, bagelInjectionKey, useBagel };