classcard-ui 0.2.1486 → 0.2.1487

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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "classcard-ui",
3
- "version": "0.2.1486",
3
+ "version": "0.2.1487",
4
4
  "main": "dist/classcard-ui.umd.min.js",
5
5
  "scripts": {
6
6
  "serve": "vue-cli-service serve",
@@ -7,7 +7,7 @@
7
7
  <quill-editor
8
8
  ref="myQuillEditor"
9
9
  :class="`mt-1 rounded-md bg-white ${
10
- disabled ? 'opacity-50 cursor-not-allowed' : ''
10
+ disabled ? 'cursor-not-allowed opacity-50' : ''
11
11
  } text-sm shadow-sm`"
12
12
  :value="content"
13
13
  :options="editorOption"
@@ -23,45 +23,62 @@
23
23
  </p>
24
24
  </div>
25
25
  </template>
26
+
26
27
  <script>
27
28
  import "quill/dist/quill.core.css";
28
29
  import "quill/dist/quill.snow.css";
29
30
  import "quill/dist/quill.bubble.css";
30
31
  import { quillEditor } from "vue-quill-editor";
32
+ import {
33
+ EDITOR_FONT_WHITELIST,
34
+ buildEditorFontCss,
35
+ } from "./quill-font-setup";
36
+
37
+ const FONT_STYLE_ID = "c-editor-font-styles";
38
+ export { EDITOR_FONT_WHITELIST };
39
+
31
40
  export default {
32
41
  name: "CEditor",
33
42
  components: { quillEditor },
34
43
  props: {
35
- id: {
36
- type: String,
37
- },
38
- content: {
39
- type: String,
40
- },
41
- label: {
42
- type: String,
43
- },
44
- hint: {
45
- type: String,
46
- },
47
- helpText: {
48
- type: String,
49
- },
50
- toolbarOptions: {
51
- type: Array,
52
- },
53
- onEditorChange: {
54
- type: Function,
55
- },
56
- placeholder: {
57
- type: String,
58
- },
59
- disabled: {
60
- type: Boolean,
61
- default: false,
62
- },
44
+ id: { type: String },
45
+ content: { type: String },
46
+ label: { type: String },
47
+ hint: { type: String },
48
+ helpText: { type: String },
49
+ toolbarOptions: { type: Array, default: () => [] },
50
+ onEditorChange: { type: Function },
51
+ placeholder: { type: String },
52
+ disabled: { type: Boolean, default: false },
63
53
  },
64
54
  methods: {
55
+ /**
56
+ * Quill toolbar font options are separate from the attributor whitelist.
57
+ * Sync any font control to EDITOR_FONT_WHITELIST so custom fonts appear and apply.
58
+ */
59
+ normalizeToolbarOptions(toolbarOptions) {
60
+ if (!Array.isArray(toolbarOptions) || !JSON.stringify(toolbarOptions).includes('"font"')) {
61
+ return toolbarOptions;
62
+ }
63
+
64
+ return toolbarOptions.map((group) => {
65
+ if (!Array.isArray(group)) return group;
66
+
67
+ return group.map((item) => {
68
+ if (item === "font") {
69
+ return { font: EDITOR_FONT_WHITELIST };
70
+ }
71
+ if (
72
+ item &&
73
+ typeof item === "object" &&
74
+ Object.prototype.hasOwnProperty.call(item, "font")
75
+ ) {
76
+ return { font: EDITOR_FONT_WHITELIST };
77
+ }
78
+ return item;
79
+ });
80
+ });
81
+ },
65
82
  onChange(params) {
66
83
  this.$emit("onEditorChange", params);
67
84
  },
@@ -83,27 +100,34 @@ export default {
83
100
  return {
84
101
  modules: {
85
102
  toolbar: {
86
- container: this.toolbarOptions,
103
+ container: this.normalizeToolbarOptions(this.toolbarOptions),
87
104
  },
88
105
  },
89
106
  placeholder: this.placeholder,
90
107
  };
91
108
  },
92
109
  },
110
+ mounted() {
111
+ if (document.getElementById(FONT_STYLE_ID)) return;
112
+
113
+ const style = document.createElement("style");
114
+ style.id = FONT_STYLE_ID;
115
+ style.textContent = buildEditorFontCss();
116
+ document.head.appendChild(style);
117
+ },
93
118
  };
94
119
  </script>
120
+
95
121
  <style>
96
122
  .ql-toolbar.ql-snow {
97
123
  border-top-left-radius: 0.375rem;
98
124
  border-top-right-radius: 0.375rem;
99
125
  }
100
-
101
126
  .ql-container.ql-snow {
102
127
  border-bottom-left-radius: 0.375rem;
103
128
  border-bottom-right-radius: 0.375rem;
104
129
  min-height: 5rem;
105
130
  }
106
-
107
131
  .ql-editor {
108
132
  @apply text-sm text-gray-900;
109
133
  max-height: 150px;
@@ -111,4 +135,4 @@ export default {
111
135
  .ql-editor.ql-blank::before {
112
136
  @apply not-italic text-gray-500;
113
137
  }
114
- </style>
138
+ </style>
@@ -1,3 +1,7 @@
1
- import CEditor from './CEditor.vue'
1
+ import CEditor from "./CEditor.vue";
2
2
 
3
- export default CEditor
3
+ export default CEditor;
4
+ export {
5
+ EDITOR_FONT_WHITELIST,
6
+ EDITOR_FONT_FAMILIES,
7
+ } from "./quill-font-setup";
@@ -0,0 +1,134 @@
1
+ import { Quill } from "vue-quill-editor";
2
+
3
+ /** Short keys used by your toolbar option arrays */
4
+ export const EDITOR_FONT_WHITELIST = [
5
+ "sans-serif",
6
+ "serif",
7
+ "monospace",
8
+ "comic-sans",
9
+ "verdana",
10
+ ];
11
+
12
+ /** Fully resolved font stacks mapped to each key */
13
+ export const EDITOR_FONT_FAMILIES = {
14
+ "sans-serif": 'Arial, Helvetica, sans-serif',
15
+ "serif": 'Georgia, "Times New Roman", serif',
16
+ "monospace": '"Courier New", Courier, monospace',
17
+ "comic-sans": 'Comic Sans MS, cursive',
18
+ "verdana": 'Verdana, Geneva, sans-serif',
19
+ };
20
+
21
+ const cleanStack = (stack) => String(stack || "").replace(/["']/g, "");
22
+
23
+ const CLEANED_FONT_STACKS = Object.fromEntries(
24
+ Object.entries(EDITOR_FONT_FAMILIES).map(([key, stack]) => [key, cleanStack(stack)])
25
+ );
26
+
27
+ const EXACT_KEY_BY_CLEAN_STACK = Object.fromEntries(
28
+ Object.entries(CLEANED_FONT_STACKS).map(([key, cleanedStack]) => [cleanedStack, key])
29
+ );
30
+
31
+ const FONT_KEY_LOWER = Object.fromEntries(
32
+ EDITOR_FONT_WHITELIST.map((key) => [key, key.toLowerCase()])
33
+ );
34
+
35
+ function primaryFontName(stack) {
36
+ return stack.split(",")[0].trim().replace(/^["']|["']$/g, "");
37
+ }
38
+
39
+ function formatFontLabel(key) {
40
+ return key
41
+ .split("-")
42
+ .map((word) => word.charAt(0).toUpperCase() + word.slice(1))
43
+ .join(" ");
44
+ }
45
+
46
+ export function buildEditorFontCss() {
47
+ const editorRules = EDITOR_FONT_WHITELIST.map((key) => {
48
+ const stack = EDITOR_FONT_FAMILIES[key];
49
+ const primary = primaryFontName(stack);
50
+ return `
51
+ .ql-snow .ql-editor .ql-font-${key},
52
+ .ql-snow .ql-editor [style*="font-family: ${primary}"],
53
+ .ql-snow .ql-editor [style*='font-family: "${primary}"'] {
54
+ font-family: ${stack} !important;
55
+ }`;
56
+ }).join("\n");
57
+ const toolbarRules = EDITOR_FONT_WHITELIST.map((key) => {
58
+ const stack = EDITOR_FONT_FAMILIES[key];
59
+ const label = formatFontLabel(key);
60
+ return `
61
+ .ql-snow .ql-picker.ql-font .ql-picker-label[data-value="${key}"]::before,
62
+ .ql-snow .ql-picker.ql-font .ql-picker-item[data-value="${key}"]::before {
63
+ content: "${label}";
64
+ font-family: ${stack};
65
+ }`;
66
+ }).join("\n");
67
+ return `
68
+ .ql-snow .ql-picker.ql-font .ql-picker-label::before,
69
+ .ql-snow .ql-picker.ql-font .ql-picker-item::before {
70
+ content: "Default";
71
+ }
72
+ ${editorRules}
73
+ ${toolbarRules}`;
74
+ }
75
+
76
+ const Inline = Quill.import("blots/inline");
77
+
78
+ // 1. Define a completely custom Font Format Blot instead of standard Class/Style overrides
79
+ class CustomFontBlot extends Inline {
80
+ static create(value) {
81
+ const node = super.create();
82
+
83
+ // Check if the incoming value is a shorthand key or a fully resolved font stack
84
+ if (EDITOR_FONT_FAMILIES[value]) {
85
+ node.style.fontFamily = EDITOR_FONT_FAMILIES[value];
86
+ } else if (Object.values(EDITOR_FONT_FAMILIES).includes(value)) {
87
+ node.style.fontFamily = value;
88
+ } else {
89
+ // Fallback fallback if an unknown value leaks through
90
+ node.style.fontFamily = value;
91
+ }
92
+
93
+ return node;
94
+ }
95
+
96
+ static formats(node) {
97
+ const fontFamily = node.style.fontFamily || "";
98
+ const cleanFontFamily = cleanStack(fontFamily);
99
+
100
+ // Fast path: exact match by cleaned stack
101
+ const exactKey = EXACT_KEY_BY_CLEAN_STACK[cleanFontFamily];
102
+ if (exactKey) return exactKey;
103
+
104
+ // Fallback: preserve existing "includes(keyLower)" behavior
105
+ const lower = cleanFontFamily.toLowerCase();
106
+ const match = EDITOR_FONT_WHITELIST.find((key) =>
107
+ lower.includes(FONT_KEY_LOWER[key])
108
+ );
109
+
110
+ return match || (typeof fontFamily === "string" ? fontFamily : undefined);
111
+ }
112
+
113
+ format(name, value) {
114
+ if (name === 'font' && value) {
115
+ if (EDITOR_FONT_FAMILIES[value]) {
116
+ this.domNode.style.fontFamily = EDITOR_FONT_FAMILIES[value];
117
+ } else {
118
+ this.domNode.style.fontFamily = value;
119
+ }
120
+ } else {
121
+ super.format(name, value);
122
+ }
123
+ }
124
+ }
125
+
126
+ // 2. Set the internal registration configurations for Quill
127
+ CustomFontBlot.blotName = "font";
128
+ CustomFontBlot.tagName = "span";
129
+ CustomFontBlot.whitelist = EDITOR_FONT_WHITELIST;
130
+
131
+ // 3. Register your new blot directly to overwrite Quill's standard 'formats/font' handle
132
+ Quill.register(CustomFontBlot, true);
133
+
134
+ export default Quill;
@@ -1,4 +1,5 @@
1
1
  import CEditor from "../components/CEditor/CEditor.vue";
2
+ import { EDITOR_FONT_WHITELIST } from "../components/CEditor/quill-font-setup";
2
3
  import "./utils.css";
3
4
 
4
5
  export default {
@@ -25,6 +26,11 @@ Default.args = {
25
26
  label: "String",
26
27
  hint: "String",
27
28
  helpText: "String",
28
- toolbarOptions: ["bold", "italic"],
29
+ toolbarOptions: [
30
+ [{ font: EDITOR_FONT_WHITELIST }],
31
+ ["bold", "italic", "underline", "strike"],
32
+ [{ list: "ordered" }, { list: "bullet" }],
33
+ ["link", "image", "video"],
34
+ ],
29
35
  placeholder: "Please enter your text here...",
30
36
  };