@ulu/frontend-vue 0.1.3-beta.9 → 0.2.0-beta.1

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 (47) hide show
  1. package/dist/frontend-vue.css +1 -1
  2. package/dist/frontend-vue.js +10056 -3612
  3. package/dist/types/components/collapsible/UluAccordionGroup.vue.d.ts +20 -0
  4. package/dist/types/components/collapsible/UluAccordionGroup.vue.d.ts.map +1 -1
  5. package/dist/types/components/layout/UluDataGrid.vue.d.ts +16 -1
  6. package/dist/types/components/layout/UluDataGrid.vue.d.ts.map +1 -1
  7. package/dist/types/components/layout/UluWhenBreakpoint.vue.d.ts.map +1 -1
  8. package/dist/types/components/systems/index.d.ts +4 -0
  9. package/dist/types/components/systems/scroll-anchors/UluScrollAnchors.vue.d.ts +20 -58
  10. package/dist/types/components/systems/scroll-anchors/UluScrollAnchors.vue.d.ts.map +1 -1
  11. package/dist/types/components/systems/scroll-anchors/UluScrollAnchorsHeadlessSection.vue.d.ts +27 -0
  12. package/dist/types/components/systems/scroll-anchors/UluScrollAnchorsHeadlessSection.vue.d.ts.map +1 -0
  13. package/dist/types/components/systems/scroll-anchors/UluScrollAnchorsNav.vue.d.ts +17 -13
  14. package/dist/types/components/systems/scroll-anchors/UluScrollAnchorsNav.vue.d.ts.map +1 -1
  15. package/dist/types/components/systems/scroll-anchors/UluScrollAnchorsNavAnimated.vue.d.ts +27 -30
  16. package/dist/types/components/systems/scroll-anchors/UluScrollAnchorsNavAnimated.vue.d.ts.map +1 -1
  17. package/dist/types/components/systems/scroll-anchors/UluScrollAnchorsSection.vue.d.ts +27 -45
  18. package/dist/types/components/systems/scroll-anchors/UluScrollAnchorsSection.vue.d.ts.map +1 -1
  19. package/dist/types/components/systems/scroll-anchors/useScrollAnchorSection.d.ts +9 -0
  20. package/dist/types/components/systems/scroll-anchors/useScrollAnchorSection.d.ts.map +1 -0
  21. package/dist/types/components/systems/scroll-anchors/useScrollAnchorSections.d.ts +8 -0
  22. package/dist/types/components/systems/scroll-anchors/useScrollAnchorSections.d.ts.map +1 -0
  23. package/dist/types/components/systems/scroll-anchors/useScrollAnchors.d.ts +14 -0
  24. package/dist/types/components/systems/scroll-anchors/useScrollAnchors.d.ts.map +1 -0
  25. package/dist/types/composables/useBreakpointManager.d.ts +2 -2
  26. package/dist/types/composables/useBreakpointManager.d.ts.map +1 -1
  27. package/lib/components/_index.scss +1 -0
  28. package/lib/components/collapsible/UluAccordionGroup.vue +39 -5
  29. package/lib/components/collapsible/UluModal.vue +2 -2
  30. package/lib/components/layout/UluDataGrid.vue +55 -15
  31. package/lib/components/layout/UluWhenBreakpoint.vue +11 -4
  32. package/lib/components/navigation/UluSkipLink.vue +1 -1
  33. package/lib/components/systems/index.js +4 -0
  34. package/lib/components/systems/scroll-anchors/UluScrollAnchors.vue +46 -145
  35. package/lib/components/systems/scroll-anchors/UluScrollAnchorsHeadlessSection.vue +50 -0
  36. package/lib/components/systems/scroll-anchors/UluScrollAnchorsNav.vue +18 -16
  37. package/lib/components/systems/scroll-anchors/UluScrollAnchorsNavAnimated.vue +100 -89
  38. package/lib/components/systems/scroll-anchors/UluScrollAnchorsSection.vue +65 -51
  39. package/lib/components/systems/scroll-anchors/_scroll-anchors-nav-animated.scss +67 -0
  40. package/lib/components/systems/scroll-anchors/useScrollAnchorSection.js +60 -0
  41. package/lib/components/systems/scroll-anchors/useScrollAnchorSections.js +15 -0
  42. package/lib/components/systems/scroll-anchors/useScrollAnchors.js +158 -0
  43. package/lib/composables/useBreakpointManager.js +2 -2
  44. package/package.json +5 -5
  45. package/dist/types/components/systems/scroll-anchors/symbols.d.ts +0 -7
  46. package/dist/types/components/systems/scroll-anchors/symbols.d.ts.map +0 -1
  47. package/lib/components/systems/scroll-anchors/symbols.js +0 -6
@@ -1,63 +1,77 @@
1
1
  <template>
2
- <div :class="[wrapperClass, { [activeClass] : activeClass && section?.active }]" ref="element">
2
+ <component
3
+ :is="element"
4
+ :class="[wrapperClass, { [activeClass]: activeClass && isActive }]"
5
+ :data-scrollpoint-state="sectionState"
6
+ ref="sectionRef"
7
+ >
3
8
  <component :is="titleElement" :class="titleClass" :id="titleId">
4
- {{ title }}
9
+ <slot name="title">
10
+ {{ title }}
11
+ </slot>
5
12
  </component>
6
13
  <slot :section="section"></slot>
7
- </div>
14
+ </component>
8
15
  </template>
9
16
 
10
- <script>
17
+ <script setup>
11
18
  import { computed } from "vue";
12
- import { urlize } from "@ulu/utils/string.js";
13
- import { REGISTER, UNREGISTER, SECTIONS } from "./symbols.js";
14
- export default {
15
- name: "ScrollAnchorsSection",
16
- props: {
17
- title: String,
18
- titleElement: {
19
- type: String,
20
- default: "h2"
21
- },
22
- titleClass: {
23
- type: String,
24
- default: "h2"
25
- },
26
- anchorId: String,
27
- wrapperClass: {
28
- type: String,
29
- default: "scroll-anchors__section"
30
- },
31
- activeClass: {
32
- type: String,
33
- default: 'is-active'
34
- }
35
- },
36
- inject: {
37
- register: { from: REGISTER },
38
- unregister: { from: UNREGISTER },
39
- sections: { from: SECTIONS, default: () => computed(() => []) }
19
+ import { useScrollAnchorSection } from "./useScrollAnchorSection";
20
+
21
+ const props = defineProps({
22
+ /**
23
+ * The title of the section, used for navigation and generating a default ID
24
+ */
25
+ title: String,
26
+ /**
27
+ * The HTML element to use for the title
28
+ */
29
+ titleElement: {
30
+ type: String,
31
+ default: "h2"
40
32
  },
41
- data() {
42
- const { anchorId, title } = this;
43
- return {
44
- titleId: anchorId || `sas-title-${ urlize(title) }`
45
- };
33
+ /**
34
+ * The class to apply to the title element
35
+ */
36
+ titleClass: {
37
+ type: String,
38
+ default: "h2"
46
39
  },
47
- computed: {
48
- section() {
49
- return this.sections.find(s => s.instance === this);
50
- }
40
+ /**
41
+ * A custom ID to use for the section anchor, overriding the auto-generated one
42
+ */
43
+ customTitleId: String,
44
+ /**
45
+ * The class to apply to the section's wrapper div
46
+ */
47
+ wrapperClass: {
48
+ type: String,
49
+ default: "scroll-anchors__section"
51
50
  },
52
- mounted() {
53
- if (this.register) {
54
- this.register(this);
55
- }
51
+ /**
52
+ * The class to apply to the wrapper div when the section is active
53
+ */
54
+ activeClass: {
55
+ type: String,
56
+ default: 'is-active'
56
57
  },
57
- unmounted() {
58
- if (this.unregister) {
59
- this.unregister(this);
60
- }
58
+ /**
59
+ * The HTML element to use for the section root
60
+ */
61
+ element: {
62
+ type: String,
63
+ default: 'section'
64
+ }
65
+ });
66
+
67
+ const { sectionRef, titleId, isActive, inactiveFrom, activeFrom, section } = useScrollAnchorSection(props);
68
+
69
+ const sectionState = computed(() => {
70
+ if (isActive.value) {
71
+ if (activeFrom.value) return `enter-${activeFrom.value}`;
72
+ } else {
73
+ if (inactiveFrom.value) return `exit-${inactiveFrom.value}`;
61
74
  }
62
- };
63
- </script>
75
+ return null;
76
+ });
77
+ </script>
@@ -0,0 +1,67 @@
1
+ ////
2
+ /// @group scroll-anchors-nav-animated
3
+ /// For use with UluScrollAnchorsNavAnimated vue component.
4
+ ////
5
+
6
+ @use "sass:map";
7
+ @use "sass:meta";
8
+
9
+ @use "@ulu/frontend/scss/selector";
10
+ @use "@ulu/frontend/scss/utils";
11
+ @use "@ulu/frontend/scss/color";
12
+
13
+ // Used for function fallback
14
+ $-fallbacks: () !default;
15
+
16
+ /// Module Settings
17
+ /// @type Map
18
+ $config: (
19
+ "rail-border-color": #dcdcdc,
20
+ "rail-padding": 1rem,
21
+ "indicator-color": #000,
22
+ "indicator-clip-path": null,
23
+ "transition-duration": 250ms,
24
+ "transition-timing-function": ease-in-out
25
+ ) !default;
26
+
27
+ /// Change modules $config
28
+ /// @param {Map} $changes Map of changes
29
+ @mixin set($changes) {
30
+ $config: map.merge($config, $changes) !global;
31
+ }
32
+
33
+ /// Get a config option
34
+ /// @param {Map} $name Name of property
35
+ @function get($name) {
36
+ $value: utils.require-map-get($config, $name, "scroll-anchors-nav-animated [config]");
37
+ @return utils.function-fallback($name, $value, $-fallbacks);
38
+ }
39
+
40
+ /// Prints component styles
41
+ /// @demo scroll-anchors-nav-animated
42
+ /// @example scss
43
+ /// @include ulu.component-scroll-anchors-nav-animated-styles();
44
+
45
+ @mixin styles {
46
+ $prefix: selector.class("scroll-anchors-nav-animated");
47
+
48
+ #{ $prefix } {
49
+ position: relative;
50
+ }
51
+ #{ $prefix }__rail {
52
+ border-left: var(--ulu-sa-nav-rail-width, 3px) solid color.get(get("rail-border-color"));
53
+ padding-left: get("rail-padding");
54
+ }
55
+ #{ $prefix }__indicator {
56
+ position: absolute;
57
+ top: 0;
58
+ left: 0;
59
+ background-color: color.get(get("indicator-color"));
60
+ clip-path: get("indicator-clip-path");
61
+ }
62
+ #{ $prefix }__indicator--can-transition {
63
+ transition-property: height, transform, width;
64
+ transition-timing-function: get("transition-timing-function");
65
+ transition-duration: get("transition-duration");
66
+ }
67
+ }
@@ -0,0 +1,60 @@
1
+ import { ref, onMounted, onUnmounted, inject, computed, reactive, watch } from 'vue';
2
+ import { urlize } from '@ulu/utils/string.js';
3
+
4
+ /**
5
+ * Composable for a component that acts as a section within the Scroll Anchors system.
6
+ * It handles registering the section with the parent `UluScrollAnchors` component,
7
+ * manages its active state, and provides reactive properties for use in the template.
8
+ * @param {object} props The component props, requires `title` and optional `customTitleId`.
9
+ * @returns {object} An object with reactive properties for the section: `sectionRef` (the ref to bind), `titleId`, `isActive`, and the raw `section` object.
10
+ */
11
+ export function useScrollAnchorSection(props) {
12
+ const sectionRef = ref(null); // for the user to bind to their root element
13
+
14
+ const register = inject('uluScrollAnchorsRegister');
15
+ const unregister = inject('uluScrollAnchorsUnregister');
16
+ const newId = title => `ulu-sa-${ urlize(title) }`;
17
+
18
+ const titleId = computed(() => props.customTitleId || newId(props.title));
19
+
20
+ const section = reactive({
21
+ id: Symbol('section-id'),
22
+ title: props.title,
23
+ titleId: titleId.value,
24
+ element: null, // will be set on mount
25
+ active: false,
26
+ inactiveFrom: null,
27
+ activeFrom: null
28
+ });
29
+
30
+ // Keep title and titleId in sync with props
31
+ watch(() => props.title, (newTitle) => {
32
+ section.title = newTitle;
33
+ section.titleId = props.customTitleId || newId(newTitle);
34
+ });
35
+ watch(() => props.customTitleId, (newTitleId) => {
36
+ section.titleId = newTitleId || newId(props.title);
37
+ });
38
+
39
+ onMounted(() => {
40
+ if (register && sectionRef.value) {
41
+ section.element = sectionRef.value;
42
+ register(section);
43
+ }
44
+ });
45
+
46
+ onUnmounted(() => {
47
+ if (unregister) {
48
+ unregister(section.id);
49
+ }
50
+ });
51
+
52
+ return {
53
+ sectionRef, // the ref for the user to attach
54
+ titleId,
55
+ isActive: computed(() => section.active),
56
+ inactiveFrom: computed(() => section.inactiveFrom),
57
+ activeFrom: computed(() => section.activeFrom),
58
+ section
59
+ };
60
+ }
@@ -0,0 +1,15 @@
1
+ import { inject } from 'vue';
2
+
3
+ /**
4
+ * Composable that provides a reactive list of all registered scroll anchor sections.
5
+ * This is the recommended way to access section data for building custom navigation.
6
+ * Must be used within a component that is a descendant of `UluScrollAnchors`.
7
+ * @returns {object} A reactive ref containing an array of section objects.
8
+ */
9
+ export function useScrollAnchorSections() {
10
+ const sections = inject('uluScrollAnchorsSections');
11
+ if (!sections) {
12
+ console.warn('useScrollAnchorSections() must be used within an UluScrollAnchors component provider.');
13
+ }
14
+ return sections;
15
+ }
@@ -0,0 +1,158 @@
1
+ import { onMounted, onUnmounted, nextTick, watch } from "vue";
2
+ import { getScrollParent } from "@ulu/utils/browser/dom.js";
3
+
4
+ /**
5
+ * The main composable that contains the core "engine" for the Scroll Anchors system.
6
+ * It encapsulates the IntersectionObserver logic to track sections and manage their active state.
7
+ * This is intended for advanced use cases where a developer needs to build a custom provider
8
+ * component instead of using the default `UluScrollAnchors`.
9
+ * @param {{sections: object, props: object, emit: Function, componentElRef: object}} options
10
+ */
11
+ export function useScrollAnchors({ sections, props, emit, componentElRef }) {
12
+ let observer = null;
13
+
14
+ function getSectionIndex(el) {
15
+ return sections.value.findIndex(({ element }) => el === element);
16
+ }
17
+
18
+ function removeActive(except = null, scrollDirection = 'down') {
19
+ sections.value.forEach(s => {
20
+ if (s !== except) {
21
+ if (s.active) {
22
+ s.inactiveFrom = scrollDirection === 'down' ? 'forward' : 'reverse';
23
+ s.activeFrom = null;
24
+ }
25
+ s.active = false;
26
+ }
27
+ });
28
+ }
29
+
30
+ function createObserver() {
31
+ let lastScrollY = 0;
32
+ let isInitialObservation = true;
33
+
34
+ const onObserve = (entries) => {
35
+ const { root } = observer;
36
+ const currentScrollY = root ? root.scrollTop : document.documentElement.scrollTop || window.scrollY;
37
+
38
+ if (props.debug) {
39
+ console.group("useScrollAnchors: onObserve");
40
+ console.log("Observer:", observer);
41
+ console.log("Last/Current Y:", `${ lastScrollY }/${ currentScrollY }`);
42
+ console.log("Entries:", entries.map(e => ({ el: e.target, is: e.isIntersecting })));
43
+ }
44
+
45
+ if (isInitialObservation && props.firstItemActive) {
46
+ if (props.debug) console.log("Initial observation, respecting `firstItemActive`.");
47
+ isInitialObservation = false;
48
+ lastScrollY = currentScrollY;
49
+ if (props.debug) console.groupEnd();
50
+ return;
51
+ }
52
+ isInitialObservation = false;
53
+
54
+ const scrollDirection = currentScrollY > lastScrollY ? 'down' : 'up';
55
+ lastScrollY = currentScrollY;
56
+ if (props.debug) console.log(`Scroll direction: ${scrollDirection}`);
57
+
58
+ const intersectingEntries = entries.filter(entry => entry.isIntersecting);
59
+ if (props.debug) console.log("Intersecting entries:", intersectingEntries.map(e => e.target));
60
+
61
+ if (intersectingEntries.length > 0) {
62
+ intersectingEntries.sort((a, b) => getSectionIndex(a.target) - getSectionIndex(b.target));
63
+
64
+ const targetEntry = scrollDirection === 'down'
65
+ ? intersectingEntries[intersectingEntries.length - 1]
66
+ : intersectingEntries[0];
67
+ if (props.debug) console.log("Chosen target entry:", targetEntry.target);
68
+
69
+ const sectionToActivate = sections.value[getSectionIndex(targetEntry.target)];
70
+
71
+ if (sectionToActivate && !sectionToActivate.active) {
72
+ if (props.debug) console.log("Activating section:", sectionToActivate.title);
73
+ nextTick(() => {
74
+ removeActive(sectionToActivate, scrollDirection);
75
+ sectionToActivate.active = true;
76
+ sectionToActivate.inactiveFrom = null;
77
+ sectionToActivate.activeFrom = scrollDirection === 'down' ? 'forward' : 'reverse';
78
+ emit("section-change", { section: sectionToActivate, sections: sections.value, active: true });
79
+ });
80
+ }
81
+ } else {
82
+ if (props.debug) console.log("No intersecting entries. Checking edge cases.");
83
+ const activeSection = sections.value.find(s => s.active);
84
+ if (activeSection) {
85
+ const entryForActive = entries.find(e => e.target === activeSection.element);
86
+ if (entryForActive && !entryForActive.isIntersecting) {
87
+ const index = getSectionIndex(entryForActive.target);
88
+ const isFirst = index === 0;
89
+ const isLast = index === sections.value.length - 1;
90
+ if ((isFirst && scrollDirection === 'up' && !props.firstItemActive) || (isLast && scrollDirection === 'down')) {
91
+ if (props.debug) console.log("Deactivating section at edge:", activeSection.title);
92
+ nextTick(() => {
93
+ removeActive(null, scrollDirection);
94
+ emit("section-change", { section: activeSection, sections: sections.value, active: false });
95
+ });
96
+ }
97
+ }
98
+ }
99
+ }
100
+ if (props.debug) console.groupEnd();
101
+ };
102
+
103
+ let root = null;
104
+ if (props.observerOptions && props.observerOptions.root) {
105
+ root = props.observerOptions.root;
106
+ } else if (componentElRef.value) {
107
+ root = getScrollParent(componentElRef.value);
108
+ if (root === document.scrollingElement) {
109
+ root = null;
110
+ }
111
+ }
112
+
113
+ const finalObserverOptions = {
114
+ ...props.observerOptions,
115
+ root
116
+ };
117
+
118
+ observer = new IntersectionObserver(onObserve, finalObserverOptions);
119
+ }
120
+
121
+ function observeItems() {
122
+ if (!observer) return;
123
+ observer.disconnect();
124
+ sections.value.forEach(({ element }) => {
125
+ if (element) {
126
+ observer.observe(element);
127
+ }
128
+ });
129
+ }
130
+
131
+ function destroyObserver() {
132
+ if (observer) {
133
+ observer.disconnect();
134
+ observer = null;
135
+ }
136
+ }
137
+
138
+ onMounted(() => {
139
+ if (props.firstItemActive && sections.value.length > 0) {
140
+ const first = sections.value[0];
141
+ if (first) {
142
+ first.active = true;
143
+ }
144
+ }
145
+ createObserver();
146
+ observeItems();
147
+ });
148
+
149
+ onUnmounted(() => {
150
+ destroyObserver();
151
+ });
152
+
153
+ watch(() => sections.value.length, () => {
154
+ nextTick(() => {
155
+ observeItems();
156
+ });
157
+ });
158
+ }
@@ -28,7 +28,7 @@ const defaults = {
28
28
  * @param {Function} [options.onReady] - A callback function that receives the `BreakpointManager` instance once it's initialized.
29
29
  * @param {object} [options.plugin] - Options to pass directly to the underlying `BreakpointManager` library.
30
30
  * @returns {{
31
- * breakpointManager: import('vue').Ref<import('@ulu/frontend/js/ui/breakpoints.js').BreakpointManager | null>,
31
+ * breakpointManager: import('vue').Ref<import('@ulu/frontend').BreakpointManager | null>,
32
32
  * breakpointActive: import('vue').Ref<string | null>,
33
33
  * breakpointDirection: import('vue').Ref<string | null>
34
34
  * }} An object containing reactive refs for:
@@ -55,7 +55,7 @@ export function useBreakpointManager(options) {
55
55
  }
56
56
  });
57
57
 
58
- const mod = await import("@ulu/frontend/js/ui/breakpoints.js");
58
+ const mod = await import("@ulu/frontend");
59
59
  const { BreakpointManager } = mod;
60
60
  const manager = markRaw(new BreakpointManager(config.plugin));
61
61
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ulu/frontend-vue",
3
- "version": "0.1.3-beta.9",
3
+ "version": "0.2.0-beta.1",
4
4
  "description": "A modular and tree-shakeable Vue 3 component library for the Ulu frontend",
5
5
  "type": "module",
6
6
  "files": [
@@ -30,7 +30,7 @@
30
30
  "build": "vite build",
31
31
  "types": "vue-tsc",
32
32
  "deploy": "rm -rf dist && npm run types && npm run build && npm run docs:build",
33
- "update-contexts": "rm -rf .ctx && mkdir -p .ctx/frontend && cp -R node_modules/@ulu/frontend/scss node_modules/@ulu/frontend/js .ctx/frontend/"
33
+ "update-contexts": "rm -rf .ctx && mkdir -p .ctx/frontend && cp -R node_modules/@ulu/frontend/lib/scss node_modules/@ulu/frontend/lib/js .ctx/frontend/"
34
34
  },
35
35
  "keywords": [
36
36
  "vue",
@@ -52,7 +52,7 @@
52
52
  "peerDependencies": {
53
53
  "@formkit/auto-animate": "^0.9.0",
54
54
  "@headlessui/vue": "^1.7.23",
55
- "@ulu/frontend": "^0.1.0-beta.123",
55
+ "@ulu/frontend": "^0.2.0-beta.3",
56
56
  "@unhead/vue": "^2.0.11",
57
57
  "vue": "^3.5.17",
58
58
  "vue-router": "^4.5.1"
@@ -65,7 +65,7 @@
65
65
  },
66
66
  "dependencies": {
67
67
  "@floating-ui/vue": "^1.1.8",
68
- "@ulu/utils": "^0.0.30",
68
+ "@ulu/utils": "^0.0.33",
69
69
  "lodash-es": "^4.17.21"
70
70
  },
71
71
  "devDependencies": {
@@ -77,7 +77,7 @@
77
77
  "@storybook/addon-essentials": "^9.0.0-alpha.12",
78
78
  "@storybook/addon-links": "^9.1.1",
79
79
  "@storybook/vue3-vite": "^9.1.1",
80
- "@ulu/frontend": "^0.1.0-beta.123",
80
+ "@ulu/frontend": "^0.2.0-beta.3",
81
81
  "@unhead/vue": "^2.0.11",
82
82
  "@vitejs/plugin-vue": "^6.0.0",
83
83
  "ollama": "^0.5.16",
@@ -1,7 +0,0 @@
1
- /**
2
- * Symbol for register provide/inject
3
- */
4
- export const REGISTER: unique symbol;
5
- export const UNREGISTER: unique symbol;
6
- export const SECTIONS: unique symbol;
7
- //# sourceMappingURL=symbols.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"symbols.d.ts","sourceRoot":"","sources":["../../../../../lib/components/systems/scroll-anchors/symbols.js"],"names":[],"mappings":"AAAA;;GAEG;AACH,qCAAiC;AACjC,uCAAmC;AACnC,qCAAiC"}
@@ -1,6 +0,0 @@
1
- /**
2
- * Symbol for register provide/inject
3
- */
4
- export const REGISTER = Symbol();
5
- export const UNREGISTER = Symbol();
6
- export const SECTIONS = Symbol();