@bagelink/vue 0.0.25 → 0.0.35
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/package.json +34 -9
- package/src/components/Btn.vue +221 -0
- package/src/components/Comments.vue +284 -0
- package/src/components/ContactArray.vue +142 -0
- package/src/components/ContactSubmissions.vue +45 -0
- package/src/components/DataPreview.vue +85 -0
- package/src/components/DropDown.vue +122 -0
- package/src/components/FileUploader.vue +353 -0
- package/src/components/FormKitTable.vue +299 -0
- package/src/components/FormSchema.vue +79 -0
- package/src/components/LangText.vue +32 -0
- package/src/components/ListItem.vue +20 -0
- package/src/components/ListView.vue +54 -0
- package/src/components/MaterialIcon.vue +19 -0
- package/src/components/Modal.vue +62 -0
- package/src/components/ModalForm.vue +109 -0
- package/src/components/NavBar.vue +353 -0
- package/src/components/PageTitle.vue +17 -0
- package/src/components/PersonPreview.vue +203 -0
- package/src/components/PersonPreviewFormkit.vue +205 -0
- package/src/components/RTXEditor.vue +151 -0
- package/src/components/RouterWrapper.vue +17 -0
- package/src/components/TabbedLayout.vue +83 -0
- package/src/components/TableSchema.vue +248 -0
- package/src/components/TopBar.vue +5 -0
- package/src/components/charts/BarChart.vue +316 -0
- package/src/components/dashboard/Lineart.vue +197 -0
- package/src/components/form/ItemRef.vue +45 -0
- package/src/components/form/MaterialIcon.vue +19 -0
- package/src/components/form/PlainInputField.vue +79 -0
- package/src/components/form/inputs/CheckInput.vue +143 -0
- package/src/components/form/inputs/Checkbox.vue +77 -0
- package/src/components/form/inputs/ColorPicker.vue +47 -0
- package/src/components/form/inputs/CurrencyInput.vue +137 -0
- package/src/components/form/inputs/DateInput.vue +55 -0
- package/src/components/form/inputs/DatetimeInput.vue +50 -0
- package/src/components/form/inputs/DurationInput.vue +55 -0
- package/src/components/form/inputs/DynamicLinkField.vue +142 -0
- package/src/components/form/inputs/EmailInput.vue +57 -0
- package/src/components/form/inputs/FloatInput.vue +52 -0
- package/src/components/form/inputs/IntInput.vue +53 -0
- package/src/components/form/inputs/JSONInput.vue +55 -0
- package/src/components/form/inputs/LinkField.vue +300 -0
- package/src/components/form/inputs/Password.vue +91 -0
- package/src/components/form/inputs/PasswordInput.vue +92 -0
- package/src/components/form/inputs/PlainText.vue +63 -0
- package/src/components/form/inputs/ReadOnlyInput.vue +28 -0
- package/src/components/form/inputs/RichTextEditor.vue +56 -0
- package/src/components/form/inputs/SelectField.vue +258 -0
- package/src/components/form/inputs/TableField.vue +319 -0
- package/src/components/form/inputs/TextArea.vue +79 -0
- package/src/components/form/inputs/TextInput.vue +63 -0
- package/src/components/form/inputs/index.ts +16 -0
- package/src/components/formkit/AddressArray.vue +240 -0
- package/src/components/formkit/BankDetailsArray.vue +265 -0
- package/src/components/formkit/ContactArrayFormKit.vue +192 -0
- package/src/components/formkit/FileUploader.vue +391 -0
- package/src/components/formkit/MiscFields.vue +74 -0
- package/src/components/formkit/Toggle.vue +164 -0
- package/src/components/formkit/index.ts +29 -0
- package/src/components/index.ts +20 -0
- package/src/components/whatsapp/form/MsgTemplate.vue +227 -0
- package/src/components/whatsapp/form/TextVariableExamples.vue +79 -0
- package/src/components/whatsapp/interfaces.ts +58 -0
- package/src/index.ts +1 -26
- package/src/plugins/bagel.ts +26 -0
- package/src/styles/modal.css +90 -0
- package/src/types/BagelField.ts +57 -0
- package/src/types/BtnOptions.ts +14 -0
- package/src/types/Person.ts +51 -0
- package/src/types/file.ts +12 -0
- package/src/types/index.ts +4 -0
- package/src/types/materialIcons.d.ts +3005 -0
- package/src/utils/index.ts +62 -0
- package/src/utils/modal.ts +101 -0
- package/src/utils/objects.ts +81 -0
- package/src/utils/strings.ts +36 -0
- package/dist/index.cjs +0 -23
- package/dist/index.d.cts +0 -12
- package/dist/index.d.mts +0 -12
- package/dist/index.d.ts +0 -12
- package/dist/index.mjs +0 -19
|
@@ -0,0 +1,62 @@
|
|
|
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 (
|
|
38
|
+
text: string,
|
|
39
|
+
// eslint-disable-next-line no-unused-vars
|
|
40
|
+
cb?: (msg: string) => void,
|
|
41
|
+
) => {
|
|
42
|
+
await navigator.clipboard.writeText(text);
|
|
43
|
+
if (cb) cb('Copied to clipboard');
|
|
44
|
+
};
|
|
45
|
+
|
|
46
|
+
export const useFormkit = () => {
|
|
47
|
+
const formkit = inject('FormKitConfig');
|
|
48
|
+
return formkit;
|
|
49
|
+
};
|
|
50
|
+
|
|
51
|
+
export const initials = (...strArr: string[]) => strArr.map((str) => str?.charAt(0)).join('');
|
|
52
|
+
|
|
53
|
+
export const parseLocale = (str: string, $t = (_str: string) => _str) => {
|
|
54
|
+
// eslint-disable-next-line no-unused-vars, @typescript-eslint/no-unused-vars
|
|
55
|
+
const [_, w] = str.split(/\$t\('?"?|'?"?\)/);
|
|
56
|
+
if (!w) return str;
|
|
57
|
+
return $t(w);
|
|
58
|
+
};
|
|
59
|
+
|
|
60
|
+
export {
|
|
61
|
+
debounce, copyText, useModal,
|
|
62
|
+
};
|
|
@@ -0,0 +1,101 @@
|
|
|
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 type { 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
|
+
// eslint-disable-next-line no-unused-vars
|
|
19
|
+
'onUpdate:modelValue'?: (val: any) => void;
|
|
20
|
+
// eslint-disable-next-line no-unused-vars
|
|
21
|
+
onSubmit: (val: any) => void;
|
|
22
|
+
// eslint-disable-next-line no-unused-vars
|
|
23
|
+
onDelete?: (id: string) => void;
|
|
24
|
+
schema: any;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
interface ModalApi {
|
|
28
|
+
// eslint-disable-next-line no-unused-vars
|
|
29
|
+
showModal: (options: ModalOptions, slots?: Record<string, any>) => void;
|
|
30
|
+
// eslint-disable-next-line no-unused-vars
|
|
31
|
+
modalForm: (options: ModalFormOptions, slots?: Record<string, any>) => void;
|
|
32
|
+
// eslint-disable-next-line no-unused-vars
|
|
33
|
+
hideModal: (index?: number) => void;
|
|
34
|
+
// modalOptions: Ref<ModalOptions | ModalFormOptions>;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
const ModalSymbol: InjectionKey<ModalApi> = Symbol('modal');
|
|
38
|
+
|
|
39
|
+
export const useModal = (): ModalApi => {
|
|
40
|
+
const modalApi = inject(ModalSymbol);
|
|
41
|
+
if (!modalApi) throw new Error('Modal API not provided');
|
|
42
|
+
return modalApi;
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
interface ModalComponentProps {
|
|
46
|
+
componentSlots: Record<string, any>,
|
|
47
|
+
isModalForm: boolean,
|
|
48
|
+
modalOptions: ModalOptions | ModalFormOptions
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
export const ModalPlugin: Plugin = {
|
|
52
|
+
install: (app) => {
|
|
53
|
+
const modalStack = ref<ModalComponentProps[]>([]);
|
|
54
|
+
const showModal = (
|
|
55
|
+
isForm: boolean,
|
|
56
|
+
options: ModalOptions | ModalFormOptions,
|
|
57
|
+
slots: Record<string, any> = {},
|
|
58
|
+
) => {
|
|
59
|
+
modalStack.value.push({
|
|
60
|
+
modalOptions: options,
|
|
61
|
+
isModalForm: isForm,
|
|
62
|
+
componentSlots: slots,
|
|
63
|
+
});
|
|
64
|
+
};
|
|
65
|
+
|
|
66
|
+
const hideModal = (index: number) => {
|
|
67
|
+
// console.log('hideModal', index);
|
|
68
|
+
modalStack.value.splice(index, 1);
|
|
69
|
+
};
|
|
70
|
+
|
|
71
|
+
app.provide(ModalSymbol, {
|
|
72
|
+
modalForm: (options: ModalFormOptions, slots?: Record<string, any>) => showModal(true, options, slots),
|
|
73
|
+
showModal: (options: ModalOptions, slots?: Record<string, any>) => showModal(false, options, slots),
|
|
74
|
+
hideModal: (index = modalStack.value.length - 1) => hideModal(index),
|
|
75
|
+
// modalOptions,
|
|
76
|
+
});
|
|
77
|
+
const ModalComponent = defineComponent({
|
|
78
|
+
data() {
|
|
79
|
+
return {
|
|
80
|
+
modalStack,
|
|
81
|
+
};
|
|
82
|
+
},
|
|
83
|
+
render() {
|
|
84
|
+
return modalStack.value.map((modal, index) => {
|
|
85
|
+
const renderComponent = modal.isModalForm ? ModalForm : Modal;
|
|
86
|
+
return h(
|
|
87
|
+
renderComponent,
|
|
88
|
+
{
|
|
89
|
+
...modal.modalOptions,
|
|
90
|
+
'onUpdate:isModalVisible': () => hideModal(index),
|
|
91
|
+
},
|
|
92
|
+
modal.componentSlots,
|
|
93
|
+
);
|
|
94
|
+
});
|
|
95
|
+
},
|
|
96
|
+
});
|
|
97
|
+
app.component('ModalContainer', ModalComponent);
|
|
98
|
+
},
|
|
99
|
+
};
|
|
100
|
+
|
|
101
|
+
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,36 @@
|
|
|
1
|
+
export function formatString(
|
|
2
|
+
str: string,
|
|
3
|
+
format: 'pascal' | 'camel' | 'snake' | 'titleCase',
|
|
4
|
+
): string {
|
|
5
|
+
if (format === 'titleCase') {
|
|
6
|
+
return str
|
|
7
|
+
.split('_')
|
|
8
|
+
.map((word) => word[0].toUpperCase() + word.slice(1).toLocaleLowerCase())
|
|
9
|
+
.join(' ');
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
if (format === 'pascal') {
|
|
13
|
+
return str
|
|
14
|
+
.split('_')
|
|
15
|
+
.map((word) => word[0].toUpperCase() + word.slice(1).toLocaleLowerCase())
|
|
16
|
+
.join('');
|
|
17
|
+
}
|
|
18
|
+
if (format === 'camel') {
|
|
19
|
+
return str
|
|
20
|
+
.split('_')
|
|
21
|
+
.map((word, index) => (index === 0 ? word : word[0].toUpperCase() + word.slice(1)))
|
|
22
|
+
.join('');
|
|
23
|
+
}
|
|
24
|
+
if (format === 'snake') {
|
|
25
|
+
return str
|
|
26
|
+
.split('')
|
|
27
|
+
.map((letter) => {
|
|
28
|
+
if (letter === letter.toUpperCase()) {
|
|
29
|
+
return `_${letter.toLowerCase()}`;
|
|
30
|
+
}
|
|
31
|
+
return letter;
|
|
32
|
+
})
|
|
33
|
+
.join('');
|
|
34
|
+
}
|
|
35
|
+
return str;
|
|
36
|
+
}
|
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 };
|