@bagelink/vue 0.0.200 → 0.0.204

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 (57) hide show
  1. package/dist/components/Btn.vue.d.ts.map +1 -1
  2. package/dist/components/form/BglField.vue.d.ts +23 -0
  3. package/dist/components/form/BglField.vue.d.ts.map +1 -0
  4. package/dist/components/form/BglForm.vue.d.ts +36 -0
  5. package/dist/components/form/BglForm.vue.d.ts.map +1 -0
  6. package/dist/components/form/ItemRef.vue.d.ts +0 -1
  7. package/dist/components/form/ItemRef.vue.d.ts.map +1 -1
  8. package/dist/components/form/index.d.ts +2 -0
  9. package/dist/components/form/index.d.ts.map +1 -1
  10. package/dist/components/form/inputs/CheckInput.vue.d.ts +0 -1
  11. package/dist/components/form/inputs/CheckInput.vue.d.ts.map +1 -1
  12. package/dist/components/form/inputs/ColorPicker.vue.d.ts +0 -1
  13. package/dist/components/form/inputs/ColorPicker.vue.d.ts.map +1 -1
  14. package/dist/components/form/inputs/CurrencyInput.vue.d.ts +0 -1
  15. package/dist/components/form/inputs/CurrencyInput.vue.d.ts.map +1 -1
  16. package/dist/components/form/inputs/DateInput.vue.d.ts +0 -1
  17. package/dist/components/form/inputs/DateInput.vue.d.ts.map +1 -1
  18. package/dist/components/form/inputs/FileUpload.vue.d.ts +18 -0
  19. package/dist/components/form/inputs/FileUpload.vue.d.ts.map +1 -0
  20. package/dist/components/form/inputs/Password.vue.d.ts +0 -1
  21. package/dist/components/form/inputs/Password.vue.d.ts.map +1 -1
  22. package/dist/components/form/inputs/PlainText.vue.d.ts +0 -1
  23. package/dist/components/form/inputs/PlainText.vue.d.ts.map +1 -1
  24. package/dist/components/form/inputs/ReadOnlyInput.vue.d.ts +0 -1
  25. package/dist/components/form/inputs/ReadOnlyInput.vue.d.ts.map +1 -1
  26. package/dist/components/form/inputs/SelectField.vue.d.ts +4 -1
  27. package/dist/components/form/inputs/SelectField.vue.d.ts.map +1 -1
  28. package/dist/components/form/inputs/TextInput.vue.d.ts +13 -0
  29. package/dist/components/form/inputs/TextInput.vue.d.ts.map +1 -1
  30. package/dist/components/form/inputs/index.d.ts +1 -0
  31. package/dist/components/form/inputs/index.d.ts.map +1 -1
  32. package/dist/index.cjs +810 -579
  33. package/dist/index.mjs +810 -579
  34. package/dist/style.css +127 -67
  35. package/dist/types/BagelField.d.ts +1 -8
  36. package/dist/types/BagelField.d.ts.map +1 -1
  37. package/dist/types/BagelForm.d.ts +23 -0
  38. package/dist/types/BagelForm.d.ts.map +1 -0
  39. package/dist/types/index.d.ts +2 -2
  40. package/dist/types/index.d.ts.map +1 -1
  41. package/dist/utils/index.d.ts +2 -2
  42. package/dist/utils/index.d.ts.map +1 -1
  43. package/package.json +1 -1
  44. package/src/components/Btn.vue +7 -7
  45. package/src/components/form/BglField.vue +29 -0
  46. package/src/components/form/BglForm.vue +75 -0
  47. package/src/components/form/index.ts +2 -0
  48. package/src/components/form/inputs/FileUpload.vue +130 -0
  49. package/src/components/form/inputs/SelectField.vue +2 -0
  50. package/src/components/form/inputs/TextInput.vue +44 -8
  51. package/src/components/form/inputs/index.ts +1 -0
  52. package/src/types/BagelField.ts +1 -6
  53. package/src/types/BagelForm.ts +24 -0
  54. package/src/types/index.ts +11 -2
  55. package/src/utils/index.ts +10 -23
  56. package/dist/components/FileUploader.vue.d.ts +0 -60
  57. package/dist/components/FileUploader.vue.d.ts.map +0 -1
@@ -0,0 +1,130 @@
1
+ <template>
2
+ <div class="bagel-input">
3
+ <label>
4
+ {{ label }}
5
+ </label>
6
+ <div @click="browse" @dragover="dragenter" @drop="drop" @dragleave="dragleave" class="fileUploadWrap" :class="{fileDropZone: !files.length, dragover: isDragOver}">
7
+ <div v-if="files.length && !multiple">
8
+ <div class="imagePreviewWrap">
9
+ <img class="preview" :src="fileToUrl(files[0])" alt="" >
10
+ </div>
11
+ <div class="previewName">
12
+ <p class="no-margin">
13
+ {{files[0].name}}
14
+ </p>
15
+ <Btn thin @click.stop="removeFile(files[0])" flat icon="delete" color="red"/>
16
+ </div>
17
+ </div>
18
+ </div>
19
+ </div>
20
+ </template>
21
+
22
+ <script setup lang="ts">
23
+ import { Btn } from '@bagelink/vue';
24
+
25
+ const props = defineProps<{label:string, multiple?: boolean}>();
26
+ const files = $ref<File[]>([]);
27
+ const fileQueue = $ref<File[]>([]);
28
+ let isDragOver = $ref(false);
29
+
30
+ const preventDefault = (e: Event) => {
31
+ e.preventDefault();
32
+ e.stopPropagation();
33
+ };
34
+
35
+ const fileToUrl = (file: File) => URL.createObjectURL(file);
36
+ const removeFile = (file:File) => {
37
+ const index = files.indexOf(file);
38
+ files.splice(index, 1);
39
+ };
40
+ const flushQueue = () => {
41
+ fileQueue.forEach((file:File, i) => {
42
+ if (props.multiple) { if (!files.includes(file)) files.push(file); } else files.splice(0, 1, file);
43
+ console.log(files);
44
+ fileQueue.splice(i, 1);
45
+ });
46
+ };
47
+
48
+ const browse = () => {
49
+ const input = document.createElement('input');
50
+ input.type = 'file';
51
+ input.multiple = props.multiple;
52
+ input.onchange = (e: Event) => {
53
+ const target = e?.target as HTMLInputElement;
54
+ if (target?.files) fileQueue.push(...Array.from(target.files));
55
+ flushQueue();
56
+ };
57
+ input.click();
58
+ };
59
+
60
+ const dragleave = (e: DragEvent) => {
61
+ preventDefault(e);
62
+ if (e.dataTransfer) isDragOver = false;
63
+ else isDragOver = false;
64
+ };
65
+
66
+ const dragenter = (e: DragEvent) => {
67
+ preventDefault(e);
68
+ if (e.dataTransfer) isDragOver = true;
69
+ else isDragOver = false;
70
+ };
71
+
72
+ const drop = (e: DragEvent) => {
73
+ preventDefault(e);
74
+ if (e.dataTransfer) fileQueue.push(...Array.from(e.dataTransfer.files));
75
+ isDragOver = false;
76
+ flushQueue();
77
+ };
78
+ </script>
79
+
80
+ <style scoped>
81
+ .bagel-input .fileUploadWrap {
82
+ outline: 1px solid var(--border-color);
83
+ border-radius: var(--input-border-radius);
84
+ text-align: center;
85
+ cursor: pointer;
86
+ transition: var(--bgl-transition);
87
+ position: relative;
88
+ height: 132px;
89
+ font-size: var(--input-font-size);
90
+ }
91
+ .previewName{
92
+ padding: 0.5rem;
93
+ text-align: start;
94
+ color: var(--input-color);
95
+ display: grid;
96
+ grid-template-columns: 1fr 22px;
97
+ align-items: center;
98
+
99
+ }
100
+ .previewName p{
101
+ overflow: hidden;
102
+ text-overflow: ellipsis;
103
+ white-space: nowrap;
104
+ }
105
+ .imagePreviewWrap{
106
+ background: var(--input-bg);
107
+ border-radius: var(--input-border-radius);
108
+ height: 90px;
109
+ padding: 5px;
110
+ }
111
+
112
+ img.preview {
113
+ height: 80px;
114
+ border-radius: var(--input-border-radius);
115
+ object-fit: contain;
116
+ }
117
+ .fileUploadWrap.dragover, .fileUploadWrap:hover{
118
+ box-shadow: inset 0 0 10px #00000012;
119
+ }
120
+ .bagel-input .fileUploadWrap.fileDropZone{
121
+ background: var(--input-bg);
122
+ display: flex;
123
+ align-items: center;
124
+ justify-content: center;
125
+ color:var(--bgl-gray);
126
+ }
127
+ .bagel-input .fileUploadWrap.fileDropZone:after {
128
+ content: "Drop files here or click to upload";
129
+ }
130
+ </style>
@@ -62,6 +62,8 @@ const props = withDefaults(
62
62
  field: SelectBagelField;
63
63
  modelValue: any;
64
64
  small?: boolean;
65
+ label?: string;
66
+ description?: string;
65
67
  }
66
68
  >(),
67
69
  {
@@ -1,15 +1,18 @@
1
1
  <template>
2
2
  <div
3
- class="bagel-input"
4
- :class="{ small, shrink, toggleEdit, editMode, textInputIconWrap: icon, txtInputIconStart: iconStart }"
3
+ class="bagel-input text-input"
4
+ :class="{ small, shrink, toggleEdit, editMode, textInputIconWrap: icon, txtInputIconStart: iconStart, code }"
5
5
  :title="title"
6
6
  >
7
7
  <label :for="id">
8
8
  {{ label }}
9
9
  <input
10
+ :autocomplete="autocomplete"
11
+ v-if="!multiline && !autoheight && !code"
10
12
  :id="id"
11
13
  v-model="inputVal"
12
14
  :type="type"
15
+ :rows="1"
13
16
  ref="input"
14
17
  :placeholder="placeholder || label"
15
18
  :disabled="!editMode"
@@ -17,8 +20,21 @@
17
20
  :pattern="pattern"
18
21
  v-bind="nativeInputAttrs"
19
22
  @dblclick="toggleEditAction"
20
- @keydown.enter="toggleEditAction"
21
23
  >
24
+ <textarea
25
+ v-else
26
+ :id="id"
27
+ v-model="inputVal"
28
+ :type="type"
29
+ :rows="rows"
30
+ ref="input"
31
+ :placeholder="placeholder || label"
32
+ :disabled="!editMode"
33
+ :required="required"
34
+ :pattern="pattern"
35
+ v-bind="nativeInputAttrs"
36
+ @dblclick="toggleEditAction"
37
+ />
22
38
  </label>
23
39
 
24
40
  <MaterialIcon
@@ -64,11 +80,17 @@ const props = withDefaults(
64
80
  nativeInputAttrs?: Record<string, any>;
65
81
  icon?: MaterialIcons;
66
82
  iconStart?: MaterialIcons;
83
+ multiline?: boolean;
84
+ autoheight?: boolean;
85
+ code?: boolean;
86
+ lines?: number;
87
+ autocomplete?: string;
67
88
  }>(),
68
89
  {
69
90
  type: 'text',
70
91
  toggleEdit: false,
71
92
  modelValue: '',
93
+ autocomplete: 'off',
72
94
  },
73
95
  );
74
96
  let inputVal = $ref<string | number>();
@@ -87,6 +109,13 @@ const toggleEditAction = () => {
87
109
  }
88
110
  };
89
111
 
112
+ const rows = $computed(() => {
113
+ if (props.lines) return props.lines;
114
+ if (props.autoheight) return `${inputVal}`?.split('\n').length || 1;
115
+ if (props.multiline || props.code) return 4;
116
+ return 1;
117
+ });
118
+
90
119
  watch(
91
120
  () => inputVal,
92
121
  (newVal) => {
@@ -115,10 +144,17 @@ watch(
115
144
  </style>
116
145
 
117
146
  <style scoped>
118
- .bagel-input input[disabled] {
119
- background: none;
147
+ .bagel-input textarea{
148
+ min-height: unset;
149
+ }
150
+ .bagel-input.text-input textarea{
151
+ resize: none;
152
+ }
153
+ .code textarea{
154
+ font-family: 'Inconsolata', monospace;
155
+ background: var(--bgl-black) !important;
156
+ color: var(--bgl-white) !important;
120
157
  }
121
-
122
158
  .bagel-input.toggleEdit:hover {
123
159
  background-color: var(--input-bg);
124
160
  }
@@ -155,7 +191,7 @@ watch(
155
191
  color: var(--bgl-gray);
156
192
  }
157
193
 
158
- .txtInputIconStart input {
194
+ .txtInputIconStart textarea {
159
195
  padding-inline-start: 2rem;
160
196
  }
161
197
 
@@ -164,7 +200,7 @@ watch(
164
200
  opacity: 1;
165
201
  }
166
202
 
167
- .bagel-input.small input {
203
+ .bagel-input.small textarea {
168
204
  height: 30px;
169
205
  }
170
206
  </style>
@@ -22,3 +22,4 @@ export { default as DynamicLinkField } from './DynamicLinkField.vue';
22
22
  export { default as PlainText } from './PlainText.vue';
23
23
  export { default as DatePicker } from './DatePicker.vue';
24
24
  export { default as RadioPillsInput } from './RadioPillsInput.vue';
25
+ export { default as FileUpload } from './FileUpload.vue';
@@ -49,9 +49,4 @@ export interface NestedBagelForm extends BaseBagelField {
49
49
  fields: NestedBagelFormFields;
50
50
  }
51
51
 
52
- export interface SelectBagelField extends BaseBagelField {
53
- inputType: 'SelectField';
54
- options: string | { label: string; value: string | number }[];
55
- }
56
-
57
- export type BagelField = BaseBagelField | SelectBagelField | NestedBagelForm;
52
+ export type BagelField = BaseBagelField | NestedBagelForm;
@@ -0,0 +1,24 @@
1
+ export type AttributeValue = string | number | boolean | null | undefined | Record<string, any>;
2
+
3
+ export type AttributeFn<T = Record<string, any>> = (field: any, row: T) => AttributeValue;
4
+
5
+ export interface Attributes<T = any> {
6
+ [key: string]: AttributeValue | AttributeFn<T>
7
+ }
8
+
9
+ export type Field<T = Record<string, any>> = {
10
+ $el?: any;
11
+ id?: string;
12
+ label?: string;
13
+ placeholder?: string;
14
+ children?: Field<T>[];
15
+ attrs?: Attributes<T>;
16
+ required?: boolean;
17
+ }
18
+
19
+ export interface SelectBagelField {
20
+ inputType: 'SelectField';
21
+ options: string | { label: string; value: string | number }[];
22
+ }
23
+
24
+ export type BglFormSchemaT<T = Record<string, any>> = Field<T>[];
@@ -2,7 +2,16 @@ export type { MaterialIcons } from './materialIcons';
2
2
  export type { BankDetailsInterface, NewPerson, Person } from './Person';
3
3
  export type { Tables, TableToTypeMapping } from '@bagelink/sdk';
4
4
  export type { StorageFile } from './file';
5
- export * from './BagelField';
5
+
6
6
  export * from './BtnOptions';
7
+ export * from './BagelForm';
7
8
 
8
- export type ThemeType = 'light' | 'red' | 'gray' | 'gray-light' | 'black' | 'green'| 'blue';
9
+ export type ThemeType = |
10
+ 'light'
11
+ | 'red'
12
+ | 'gray'
13
+ | 'gray-light'
14
+ | 'black'
15
+ | 'green'
16
+ | 'primary'
17
+ | 'blue' // ! blue does nothing
@@ -1,6 +1,5 @@
1
1
  import { inject } from 'vue';
2
-
3
- import type { BagelField } from '@bagelink/vue';
2
+ import { Attributes } from '../types';
4
3
 
5
4
  let timeout: any;
6
5
  export const debounce = (fn: () => void, delay = 500) => {
@@ -13,27 +12,6 @@ export const keyToLabel = (key: string) => key
13
12
  .map((k) => k.charAt(0).toUpperCase() + k.slice(1))
14
13
  .join(' ');
15
14
 
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
15
  export const copyText = async (
38
16
  text: string,
39
17
  // eslint-disable-next-line no-unused-vars
@@ -56,4 +34,13 @@ export function useEscape(event: KeyboardEvent, closeModel: () => void) {
56
34
  }
57
35
  }
58
36
 
37
+ export function bindAttrs<T = Record<string, any>>(attrs: Attributes, fieldVal: any, row: T) {
38
+ const arr = Object.entries(attrs).map(([key, value]) => [
39
+ key,
40
+ typeof value === 'function' ? value(fieldVal, row) : value,
41
+ ]);
42
+ const resolvedAttrs = Object.fromEntries(arr);
43
+ return resolvedAttrs;
44
+ }
45
+
59
46
  export { formatString } from './strings';
@@ -1,60 +0,0 @@
1
- declare const _default: import("vue").DefineComponent<__VLS_WithDefaults<__VLS_TypePropsToRuntimeProps<{
2
- id?: string | undefined;
3
- private?: 0 | 1 | undefined;
4
- singleFile?: boolean | undefined;
5
- beforeUpload?: (() => Promise<any>) | undefined;
6
- dragDropLabel?: string | undefined;
7
- browseLabel?: string | undefined;
8
- }>, {
9
- private: number;
10
- entity: string;
11
- id: string;
12
- beforeUpload: () => Promise<void>;
13
- dragDropLabel: string;
14
- browseLabel: string;
15
- }>, {}, unknown, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {
16
- done: (...args: any[]) => void;
17
- complete: (...args: any[]) => void;
18
- }, string, import("vue").VNodeProps & import("vue").AllowedComponentProps & import("vue").ComponentCustomProps, Readonly<import("vue").ExtractPropTypes<__VLS_WithDefaults<__VLS_TypePropsToRuntimeProps<{
19
- id?: string | undefined;
20
- private?: 0 | 1 | undefined;
21
- singleFile?: boolean | undefined;
22
- beforeUpload?: (() => Promise<any>) | undefined;
23
- dragDropLabel?: string | undefined;
24
- browseLabel?: string | undefined;
25
- }>, {
26
- private: number;
27
- entity: string;
28
- id: string;
29
- beforeUpload: () => Promise<void>;
30
- dragDropLabel: string;
31
- browseLabel: string;
32
- }>>> & {
33
- onDone?: ((...args: any[]) => any) | undefined;
34
- onComplete?: ((...args: any[]) => any) | undefined;
35
- }, {
36
- id: string;
37
- private: 1 | 0;
38
- beforeUpload: () => Promise<any>;
39
- dragDropLabel: string;
40
- browseLabel: string;
41
- }, {}>;
42
- export default _default;
43
- type __VLS_NonUndefinedable<T> = T extends undefined ? never : T;
44
- type __VLS_TypePropsToRuntimeProps<T> = {
45
- [K in keyof T]-?: {} extends Pick<T, K> ? {
46
- type: import('vue').PropType<__VLS_NonUndefinedable<T[K]>>;
47
- } : {
48
- type: import('vue').PropType<T[K]>;
49
- required: true;
50
- };
51
- };
52
- type __VLS_WithDefaults<P, D> = {
53
- [K in keyof Pick<P, keyof P>]: K extends keyof D ? __VLS_Prettify<P[K] & {
54
- default: D[K];
55
- }> : P[K];
56
- };
57
- type __VLS_Prettify<T> = {
58
- [K in keyof T]: T[K];
59
- } & {};
60
- //# sourceMappingURL=FileUploader.vue.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"FileUploader.vue.d.ts","sourceRoot":"","sources":["../../src/components/FileUploader.vue"],"names":[],"mappings":"AAiDA;;;;;0BA6YuB,QAAQ,GAAG,CAAC;;;;;;;;;;;;;;;;;0BAAZ,QAAQ,GAAG,CAAC;;;;;;;;;;;;;;QAJ5B,MAAM;aAED,CAAC,GAAG,CAAC;kBAEA,MAAM,QAAQ,GAAG,CAAC;mBACjB,MAAM;iBACR,MAAM;;AARtB,wBAeG;AAGH,KAAK,sBAAsB,CAAC,CAAC,IAAI,CAAC,SAAS,SAAS,GAAG,KAAK,GAAG,CAAC,CAAC;AACjE,KAAK,6BAA6B,CAAC,CAAC,IAAI;KAAG,CAAC,IAAI,MAAM,CAAC,CAAC,CAAC,GAAG,EAAE,SAAS,IAAI,CAAC,CAAC,EAAE,CAAC,CAAC,GAAG;QAAE,IAAI,EAAE,OAAO,KAAK,EAAE,QAAQ,CAAC,sBAAsB,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAA;KAAE,GAAG;QAAE,IAAI,EAAE,OAAO,KAAK,EAAE,QAAQ,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;QAAC,QAAQ,EAAE,IAAI,CAAA;KAAE;CAAE,CAAC;AAC9M,KAAK,kBAAkB,CAAC,CAAC,EAAE,CAAC,IAAI;KAE1B,CAAC,IAAI,MAAM,IAAI,CAAC,CAAC,EAAE,MAAM,CAAC,CAAC,GAAG,CAAC,SAAS,MAAM,CAAC,GAAG,cAAc,CAAC,CAAC,CAAC,CAAC,CAAC,GAAG;QACxE,OAAO,EAAE,CAAC,CAAC,CAAC,CAAC,CAAA;KACb,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC;CACT,CAAC;AACN,KAAK,cAAc,CAAC,CAAC,IAAI;KAAG,CAAC,IAAI,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC;CAAG,GAAG,EAAE,CAAC"}