pukaad-ui-lib 1.43.0 → 1.45.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/dist/module.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "pukaad-ui-lib",
3
3
  "configKey": "pukaadUI",
4
- "version": "1.43.0",
4
+ "version": "1.45.0",
5
5
  "builder": {
6
6
  "@nuxt/module-builder": "1.0.2",
7
7
  "unbuild": "3.6.1"
@@ -2,6 +2,7 @@ export interface InputContentProps {
2
2
  height?: string | number;
3
3
  placeholder?: string;
4
4
  disabledBorder?: boolean;
5
+ disableMedia?: boolean;
5
6
  }
6
7
  type __VLS_Props = InputContentProps;
7
8
  type __VLS_ModelProps = {
@@ -14,6 +15,7 @@ declare const __VLS_export: import("vue").DefineComponent<__VLS_PublicProps, {},
14
15
  "onUpdate:modelValue"?: ((value: any) => any) | undefined;
15
16
  }>, {
16
17
  height: string | number;
18
+ disableMedia: boolean;
17
19
  }, {}, {}, {}, string, import("vue").ComponentProvideOptions, false, {}, any>;
18
20
  declare const _default: typeof __VLS_export;
19
21
  export default _default;
@@ -1,7 +1,12 @@
1
1
  <template>
2
2
  <div>
3
- <div class="quill-wrapper">
4
- <div ref="contentRef" :style="{ '--height': `${props.height}px` }" />
3
+ <div class="quill-wrapper" :class="{ 'drag-not-allowed': isDraggingMedia }">
4
+ <div
5
+ ref="contentRef"
6
+ :style="{
7
+ '--height': `${props.height}px`
8
+ }"
9
+ />
5
10
  </div>
6
11
  </div>
7
12
  </template>
@@ -15,9 +20,11 @@ let quillEditor = null;
15
20
  const props = defineProps({
16
21
  height: { type: [String, Number], required: false, default: 288 },
17
22
  placeholder: { type: String, required: false },
18
- disabledBorder: { type: Boolean, required: false }
23
+ disabledBorder: { type: Boolean, required: false },
24
+ disableMedia: { type: Boolean, required: false, default: false }
19
25
  });
20
26
  const modelValue = defineModel();
27
+ const isDraggingMedia = ref(false);
21
28
  onMounted(() => {
22
29
  if (contentRef.value) {
23
30
  const toolbarOptions = [
@@ -28,15 +35,43 @@ onMounted(() => {
28
35
  [{ indent: "-1" }, { indent: "+1" }],
29
36
  [{ color: [] }, { background: [] }],
30
37
  [{ align: [] }],
31
- ["link", "image", "video"]
38
+ props.disableMedia ? ["link"] : ["link", "image", "video"]
32
39
  ];
40
+ const modules = {
41
+ toolbar: toolbarOptions
42
+ };
43
+ if (props.disableMedia) {
44
+ modules.clipboard = {
45
+ matchers: [
46
+ [
47
+ "IMG",
48
+ () => {
49
+ return { ops: [] };
50
+ }
51
+ ],
52
+ [
53
+ "VIDEO",
54
+ () => {
55
+ return { ops: [] };
56
+ }
57
+ ]
58
+ ]
59
+ };
60
+ }
33
61
  quillEditor = new $quill(contentRef.value, {
34
62
  theme: "snow",
35
63
  placeholder: props.placeholder,
36
- modules: {
37
- toolbar: toolbarOptions
38
- }
64
+ modules
39
65
  });
66
+ if (props.disableMedia) {
67
+ const toolbar = quillEditor.getModule("toolbar");
68
+ if (toolbar && toolbar.addHandler) {
69
+ toolbar.addHandler("image", () => {
70
+ });
71
+ toolbar.addHandler("video", () => {
72
+ });
73
+ }
74
+ }
40
75
  if (modelValue.value) {
41
76
  quillEditor.setContents(modelValue.value);
42
77
  }
@@ -44,14 +79,72 @@ onMounted(() => {
44
79
  if (source === "user") {
45
80
  if (!quillEditor) return;
46
81
  const currentDeltaJson = quillEditor.getContents();
47
- modelValue.value = currentDeltaJson;
82
+ if (props.disableMedia && currentDeltaJson.ops) {
83
+ const filteredOps = currentDeltaJson.ops.filter((op) => {
84
+ if (op.insert && typeof op.insert === "object") {
85
+ return !op.insert.image && !op.insert.video;
86
+ }
87
+ return true;
88
+ });
89
+ if (filteredOps.length !== currentDeltaJson.ops.length) {
90
+ quillEditor.setContents({ ops: filteredOps });
91
+ }
92
+ modelValue.value = { ops: filteredOps };
93
+ } else {
94
+ modelValue.value = currentDeltaJson;
95
+ }
48
96
  }
49
97
  });
98
+ if (props.disableMedia) {
99
+ const editorRoot = quillEditor.root;
100
+ editorRoot.addEventListener("dragenter", handleDragEnter);
101
+ editorRoot.addEventListener("dragover", handleDragOver);
102
+ editorRoot.addEventListener("dragleave", handleDragLeave);
103
+ editorRoot.addEventListener("drop", handleDrop);
104
+ }
50
105
  }
51
106
  });
107
+ const hasMediaFiles = (dataTransfer) => {
108
+ if (!dataTransfer) return false;
109
+ return Array.from(dataTransfer.items).some(
110
+ (item) => item.type.startsWith("image/") || item.type.startsWith("video/")
111
+ );
112
+ };
113
+ const handleDragEnter = (e) => {
114
+ if (hasMediaFiles(e.dataTransfer)) {
115
+ isDraggingMedia.value = true;
116
+ }
117
+ };
118
+ const handleDragOver = (e) => {
119
+ if (hasMediaFiles(e.dataTransfer)) {
120
+ e.preventDefault();
121
+ e.dataTransfer.dropEffect = "none";
122
+ isDraggingMedia.value = true;
123
+ }
124
+ };
125
+ const handleDragLeave = (e) => {
126
+ const relatedTarget = e.relatedTarget;
127
+ if (!relatedTarget || !quillEditor?.root.contains(relatedTarget)) {
128
+ isDraggingMedia.value = false;
129
+ }
130
+ };
131
+ const handleDrop = (e) => {
132
+ isDraggingMedia.value = false;
133
+ if (hasMediaFiles(e.dataTransfer)) {
134
+ e.preventDefault();
135
+ e.stopPropagation();
136
+ }
137
+ };
52
138
  onUnmounted(() => {
53
139
  if (quillEditor && contentRef.value) {
54
140
  quillEditor.off("text-change");
141
+ if (props.disableMedia) {
142
+ const editorRoot = quillEditor.root;
143
+ editorRoot.removeEventListener("dragenter", handleDragEnter);
144
+ editorRoot.removeEventListener("dragover", handleDragOver);
145
+ editorRoot.removeEventListener("dragleave", handleDragLeave);
146
+ editorRoot.removeEventListener("drop", handleDrop);
147
+ }
55
148
  const toolbar = contentRef.value.previousElementSibling;
56
149
  if (toolbar && toolbar.classList.contains("ql-toolbar")) {
57
150
  toolbar.remove();
@@ -63,5 +156,5 @@ onUnmounted(() => {
63
156
  </script>
64
157
 
65
158
  <style scoped>
66
- .quill-wrapper :deep(.ql-toolbar.ql-snow){background-color:#fafafa;border:none;border-radius:8px}.quill-wrapper :deep(.ql-container.ql-snow){border:none;border-bottom-left-radius:8px;border-bottom-right-radius:8px;overflow:hidden}.quill-wrapper :deep(.ql-editor){font-family:Sarabun-Regular;font-size:16px;margin-top:8px;min-height:var(--height)!important;padding:4px 12px}.quill-wrapper :deep(.ql-editor.ql-blank:before){color:#c4c4c4;content:attr(data-placeholder);font-size:16px;font-style:normal}
159
+ .quill-wrapper{border-bottom:1px solid #e8e8e8}.quill-wrapper :deep(.ql-toolbar.ql-snow){background-color:#fafafa;border:none;border-radius:8px}.quill-wrapper :deep(.ql-container.ql-snow){border:none;border-bottom-left-radius:8px;border-bottom-right-radius:8px;overflow:hidden}.quill-wrapper :deep(.ql-editor){font-family:Sarabun-Regular;font-size:16px;margin-top:8px;min-height:var(--height)!important;padding:4px 12px}.quill-wrapper :deep(.ql-editor.ql-blank:before){color:#c4c4c4;content:attr(data-placeholder);font-size:16px;font-style:normal}.quill-wrapper.drag-not-allowed :deep(.ql-editor){background-color:#fef2f2;border:2px dashed #ef4444;cursor:not-allowed}
67
160
  </style>
@@ -2,6 +2,7 @@ export interface InputContentProps {
2
2
  height?: string | number;
3
3
  placeholder?: string;
4
4
  disabledBorder?: boolean;
5
+ disableMedia?: boolean;
5
6
  }
6
7
  type __VLS_Props = InputContentProps;
7
8
  type __VLS_ModelProps = {
@@ -14,6 +15,7 @@ declare const __VLS_export: import("vue").DefineComponent<__VLS_PublicProps, {},
14
15
  "onUpdate:modelValue"?: ((value: any) => any) | undefined;
15
16
  }>, {
16
17
  height: string | number;
18
+ disableMedia: boolean;
17
19
  }, {}, {}, {}, string, import("vue").ComponentProvideOptions, false, {}, any>;
18
20
  declare const _default: typeof __VLS_export;
19
21
  export default _default;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pukaad-ui-lib",
3
- "version": "1.43.0",
3
+ "version": "1.45.0",
4
4
  "description": "pukaad-ui for MeMSG",
5
5
  "repository": {
6
6
  "type": "git",