@ulu/frontend-vue 0.1.0-beta.4 → 0.1.0-beta.5

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.
@@ -17,10 +17,10 @@
17
17
  </template>
18
18
 
19
19
  <script setup>
20
- import { ref, defineAsyncComponent, markRaw, watchEffect, computed } from "vue";
20
+ import { ref, defineAsyncComponent, markRaw, watchEffect, computed, inject } from "vue";
21
21
  import { useIcon } from "../../composables/useIcon.js";
22
- import { getSetting, getIconByType } from "../../settings.js";
23
22
 
23
+ const uluCore = inject('uluCore');
24
24
  const faIconComponent = ref(null);
25
25
  const { getIconProps, getClassesFromDefinition } = useIcon();
26
26
 
@@ -39,15 +39,15 @@
39
39
  });
40
40
 
41
41
  const useStaticFa = computed(() => {
42
- return getSetting("fontAwesomeStatic");
42
+ return uluCore.getSetting("fontAwesomeStatic");
43
43
  });
44
44
 
45
45
  const customIconComponent = computed(() => {
46
- return getSetting("iconComponent");
46
+ return uluCore.getSetting("iconComponent");
47
47
  });
48
48
 
49
49
  const iconPropResolver = computed(() => {
50
- return getSetting("iconPropResolver");
50
+ return uluCore.getSetting("iconPropResolver");
51
51
  });
52
52
 
53
53
  // Resolve the final icon definition, giving precedence to the `definition` prop
@@ -57,7 +57,7 @@
57
57
  }
58
58
  if (props.type) {
59
59
  try {
60
- return getIconByType(props.type);
60
+ return uluCore.getIcon(props.type);
61
61
  } catch (e) {
62
62
  console.warn(e);
63
63
  return null;
@@ -28,7 +28,6 @@ export { default as UluSpokeSpinner } from './elements/UluSpokeSpinner.vue';
28
28
  export { default as UluTag } from './elements/UluTag.vue';
29
29
  export { default as UluCheckboxMenu } from './forms/UluCheckboxMenu.vue';
30
30
  export { default as UluFileDisplay } from './forms/UluFileDisplay.vue';
31
- export { default as UluFormDropzone } from './forms/UluFormDropzone.vue';
32
31
  export { default as UluFormFile } from './forms/UluFormFile.vue';
33
32
  export { default as UluFormMessage } from './forms/UluFormMessage.vue';
34
33
  export { default as UluFormSelect } from './forms/UluFormSelect.vue';
package/lib/index.js CHANGED
@@ -7,4 +7,3 @@
7
7
  export * from './plugins/index.js';
8
8
  export * from './components/index.js';
9
9
  export * from './composables/index.js';
10
- export * from './settings.js';
@@ -0,0 +1,87 @@
1
+ /**
2
+ * @module plugins/core/index.js
3
+ * @description Core plugin for managing shared configuration for the library.
4
+ */
5
+ import { reactive } from 'vue';
6
+
7
+ const defaults = {
8
+ fontAwesomeStatic: false,
9
+ iconComponent: null,
10
+ iconPropResolver: (definition) => ({ icon: definition }),
11
+ icons: {
12
+ danger: "fas fa-triangle-exclamation",
13
+ warning: "fas fa-circle-exclamation",
14
+ info: "fas fa-circle-info",
15
+ success: "fas fa-circle-check",
16
+ externalLink: "fas fa-arrow-up-right-from-square",
17
+ close: "fas fa-xmark",
18
+ expand: "fas fa-plus",
19
+ collapse: "fas fa-minus",
20
+ resizeHorizontal: "fas fa-grip-lines-vertical",
21
+ resizeVertical: "fas fa-grip-lines",
22
+ resizeBoth: "fas fa-grip",
23
+ ellipsis: "fas fa-ellipsis",
24
+ pathSeparator: "fas fa-chevron-right"
25
+ }
26
+ };
27
+
28
+ export const iconKeys = Object.keys(defaults.icons);
29
+
30
+ export default function install(app, userSettings = {}) {
31
+ // A single reactive object for all settings
32
+ const settings = reactive({ ...defaults });
33
+
34
+ // Separate icon overrides from other options to handle them safely
35
+ const { icons: iconOverrides, ...otherOptions } = userSettings || {};
36
+
37
+ // Merge any user-provided options during installation
38
+ if (otherOptions) {
39
+ Object.assign(settings, otherOptions);
40
+ }
41
+
42
+ const api = {
43
+ // Methods to interact with settings
44
+ getSettings() {
45
+ return settings;
46
+ },
47
+ getDefaultSettings() {
48
+ return { ...defaults };
49
+ },
50
+ updateSettings(changes) {
51
+ return Object.assign(settings, changes);
52
+ },
53
+ getSetting(key) {
54
+ if (!settings.hasOwnProperty(key)) {
55
+ console.warn(`Attempted to access non-existent setting: ${key}`);
56
+ return;
57
+ }
58
+ return settings[key];
59
+ },
60
+ updateSetting(key, value) {
61
+ if (typeof key !== "string") {
62
+ throw new Error("Expected key to be string");
63
+ }
64
+ settings[key] = value;
65
+ },
66
+ getIcon(type) {
67
+ const icons = settings.icons;
68
+ if (!icons[type]) {
69
+ throw new Error(`Icon type "${type}" not found!`);
70
+ }
71
+ return icons[type];
72
+ },
73
+ setIcon(type, definition) {
74
+ settings.icons[type] = definition;
75
+ }
76
+ };
77
+
78
+ // Apply any individual icon overrides passed during installation
79
+ if (iconOverrides) {
80
+ for (const [type, definition] of Object.entries(iconOverrides)) {
81
+ api.setIcon(type, definition);
82
+ }
83
+ }
84
+
85
+ app.provide('uluCore', api);
86
+ app.config.globalProperties.$uluCore = api;
87
+ }
@@ -5,6 +5,7 @@
5
5
  */
6
6
 
7
7
 
8
+ export { default as corePlugin } from './core/index.js';
8
9
  export { default as popoversPlugin } from './popovers/index.js';
9
10
  export { default as modalsPlugin } from './modals/index.js';
10
11
  export { default as toastPlugin } from './toast/index.js';
package/package.json CHANGED
@@ -1,9 +1,9 @@
1
1
  {
2
2
  "name": "@ulu/frontend-vue",
3
- "version": "0.1.0-beta.4",
4
- "description": "Frontend theming library (Vue)",
3
+ "version": "0.1.0-beta.5",
4
+ "description": "A modular and tree-shakeable Vue 3 component library for the Ulu frontend",
5
5
  "type": "module",
6
- "files" : [
6
+ "files": [
7
7
  "lib",
8
8
  "dist"
9
9
  ],
@@ -28,7 +28,17 @@
28
28
  "build": "vite build",
29
29
  "deploy": "npm run build && npm run docs:build"
30
30
  },
31
- "keywords": [],
31
+ "keywords": [
32
+ "vue",
33
+ "vue3",
34
+ "ui",
35
+ "components",
36
+ "component-library",
37
+ "design-system",
38
+ "ulu",
39
+ "frontend",
40
+ "scss"
41
+ ],
32
42
  "author": "Joseph Scherben <jscherbe@gmail.com>",
33
43
  "license": "MIT",
34
44
  "bugs": {
@@ -49,7 +59,7 @@
49
59
  "dependencies": {
50
60
  "@floating-ui/vue": "^1.1.8",
51
61
  "@ulu/utils": "^0.0.30",
52
- "lodash-es" : "^4.17.21"
62
+ "lodash-es": "^4.17.21"
53
63
  },
54
64
  "devDependencies": {
55
65
  "@fortawesome/fontawesome-svg-core": "^6.7.2",
@@ -74,3 +84,4 @@
74
84
  "node": "22.17.0"
75
85
  }
76
86
  }
87
+
@@ -1,62 +0,0 @@
1
- <!-- Based on https://react-dropzone.js.org/#section-basic-example -->
2
- <template>
3
- <div
4
- class="site-dropzone site-form__item site-form__item--file"
5
- :class="{ 'is-danger' : fileErrors.length }"
6
- >
7
- <div
8
- class="site-dropzone__target"
9
- :class="{
10
- 'site-dropzone__target--dropping' : isDragActive
11
- }"
12
- v-bind="getRootProps()"
13
- >
14
- <input v-bind="getInputProps()" />
15
- <div class="site-dropzone__instructions">
16
- <strong class="type-normal">
17
- Drag 'n' drop files here, or click to select
18
- </strong>
19
- </div>
20
- </div>
21
- <p class="site-form__description">
22
- <em>Only images allowed (.jpg, .png)</em>
23
- </p>
24
- <div v-if="fileErrors.length" class="site-dropzone__errors site-form__description site-form__error">
25
- <ul class="list-unordered">
26
- <li v-for="(fileErr, index) in fileErrors" :key="index">
27
- <strong>{{ fileErr.file.name }}</strong>:
28
- <span>{{ fileErr.errors.map(e => e.message).join() }}</span>
29
- </li>
30
- </ul>
31
- </div>
32
- <div class="site-dropzone__display margin-top" v-if="files.length">
33
- <strong>Files</strong>
34
- <FilesDisplay class="site-dropzone__list" :files="files"/>
35
- </div>
36
- </div>
37
- </template>
38
-
39
- <script setup>
40
- import { ref } from "vue";
41
- import { useDropzone } from "vue3-dropzone";
42
-
43
- const files = ref([]);
44
- const fileErrors = ref([]);
45
-
46
- const $emit = defineEmits(["filesChange"]);
47
-
48
- const { getRootProps, getInputProps, isDragActive } = useDropzone({
49
- onDrop: (acceptFiles, rejectReasons) => {
50
- if (rejectReasons) {
51
- fileErrors.value = rejectReasons.map(err => err);
52
- } else {
53
- fileErrors.value = [];
54
- }
55
- if (acceptFiles.length) {
56
- files.value = acceptFiles.map(file => file);
57
- $emit("filesChange", files.value);
58
- }
59
- },
60
- accept: [".png", ".jpg", ".jpeg"]
61
- });
62
- </script>
package/lib/settings.js DELETED
@@ -1,119 +0,0 @@
1
- /**
2
- * @module settings
3
- * @description Manages shared configuration for the library.
4
- */
5
-
6
- import { reactive } from 'vue';
7
-
8
- /**
9
- * Default settings
10
- * @typedef {object} Defaults
11
- * @property {string} fontAwesomeStatic - Whether the default UluIcon should use fontawesome vue or fontawesome CSS classes (static)
12
- */
13
-
14
- /**
15
- * @type {Defaults}
16
- */
17
- const defaults = {
18
- /**
19
- * If set UluIcon will use global css classes instead of Font Awesome vue component
20
- */
21
- fontAwesomeStatic: false,
22
- /**
23
- * Use a different icon component (if using a library other than Font Awesome)
24
- * - Need to have this component map (iconsByType) to it's implementation
25
- * - All components internally use type, so only user defined components change definitions
26
- * - So you should only need to create definitions for the default types to replace this for the library
27
- */
28
- iconComponent: null,
29
- /**
30
- * Which prop in iconComponent should receive the resolved definition
31
- */
32
- iconPropResolver: (definition) => ({ icon: definition }),
33
- /**
34
- * Default icons by type
35
- */
36
- iconsByType: {
37
- danger: "fas fa-triangle-exclamation",
38
- warning: "fas fa-circle-exclamation",
39
- info: "fas fa-circle-info",
40
- success: "fas fa-circle-check",
41
- externalLink: "fas fa-arrow-up-right-from-square",
42
- close: "fas fa-xmark",
43
- expand: "fas fa-plus",
44
- collapse: "fas fa-minus",
45
- resizeHorizontal: "fas fa-grip-lines-vertical",
46
- resizeVertical: "fas fa-grip-lines",
47
- resizeBoth: "fas fa-grip",
48
- ellipsis: "fas fa-ellipsis",
49
- pathSeparator: "fas fa-chevron-right"
50
- }
51
- };
52
-
53
- // Current configuration, initialized with defaults and made reactive
54
- // We wrap `defaults` in `reactive` so `currentSettings` becomes a reactive object.
55
- let currentSettings = reactive({ ...defaults });
56
-
57
- /**
58
- * Retrieves a copy of the default settings.
59
- * @returns {object} A copy of the default settings object.
60
- */
61
- export function getDefaultSettings() {
62
- // Return a non-reactive copy of defaults
63
- return { ...defaults };
64
- }
65
-
66
- /**
67
- * Updates multiple configuration settings.
68
- * @param {object} changes An object containing the settings to update.
69
- */
70
- export function updateSettings(changes) {
71
- Object.assign(currentSettings, changes);
72
- }
73
-
74
- /**
75
- * Retrieves a copy of the current configuration settings.
76
- * @returns {object} A copy of the current settings object (vue reactive object)
77
- */
78
- export function getSettings() {
79
- return currentSettings;
80
- }
81
-
82
- /**
83
- * Retrieves a specific configuration setting by key.
84
- * @param {string} key The key of the setting to retrieve.
85
- * @returns {*} The value of the setting, or undefined if not found.
86
- */
87
- export function getSetting(key) {
88
- if (!currentSettings.hasOwnProperty(key)) {
89
- console.warn(`Attempted to access non-existent setting: ${key}`);
90
- return;
91
- }
92
- return currentSettings[key];
93
- }
94
-
95
- /**
96
- * Updates a specific configuration setting.
97
- * @param {string} key The key of the setting to update.
98
- * @param {*} value The new value for the setting.
99
- */
100
- export function updateSetting(key, value) {
101
- if (typeof key !== "string") {
102
- throw new Error("Expected key to be string");
103
- }
104
- currentSettings[key] = value;
105
- }
106
-
107
- /**
108
- * Retrieves the icon definition by type
109
- * @param {string} type - The type of icon to retrieve (e.g., 'error', 'info').
110
- * @returns {string} The icon definition
111
- * @throws {Error} If the specified icon type is not found
112
- */
113
- export function getIconByType(type) {
114
- const icons = currentSettings.iconsByType;
115
- if (!icons[type]) {
116
- throw new Error(`Icon type "${ type }" not found!`);
117
- }
118
- return icons[type];
119
- }