@resee-movies/nuxt-ux 0.6.0 → 0.7.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.
package/dist/module.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@resee-movies/nuxt-ux",
3
3
  "configKey": "ux",
4
- "version": "0.6.0",
4
+ "version": "0.7.1",
5
5
  "builder": {
6
6
  "@nuxt/module-builder": "1.0.2",
7
7
  "unbuild": "3.6.0"
@@ -145,5 +145,5 @@ const altText = computed(() => {
145
145
  </script>
146
146
 
147
147
  <style scoped>
148
- @reference "tailwindcss";.image{background-color:#fff;max-width:-moz-fit-content;max-width:fit-content;overflow:clip;position:relative;width:100%;@variant dark{background-color:#000}}.image.bordered{border:2px solid var(--color-global-background-accent)}.image.beveled{border-bottom-left-radius:var(--radius-xl);border-top-right-radius:var(--radius-xl)}.image.raised{box-shadow:var(--shadow-heavy)}.image.glass:after{background-image:linear-gradient(110deg,transparent 25%,hsla(0,0%,100%,.15) 80%,transparent);content:var(--zero-width-space);inset:0;position:absolute}.image .icon{color:var(--color-global-background-accent);left:50%;position:absolute;top:50%;transform:translateX(-50%) translateY(-50%)}
148
+ @reference "tailwindcss";.image{background-color:#fff;max-width:-moz-fit-content;max-width:fit-content;overflow:clip;position:relative;width:100%;@variant dark{background-color:#000}}.image.bordered{border:2px solid var(--color-global-background-accent)}.image.beveled{border-bottom-left-radius:var(--radius-xl);border-top-right-radius:var(--radius-xl)}.image.raised{box-shadow:var(--shadow-heavy)}.image.glass:after{background-image:linear-gradient(110deg,transparent 25%,hsla(0,0%,100%,.15) 80%,transparent);content:var(--zero-width-space);inset:0;position:absolute}.image :deep(.icon){color:var(--color-global-background-accent);left:50%;position:absolute;top:50%;transform:translateX(-50%) translateY(-50%)}
149
149
  </style>
@@ -7,7 +7,7 @@
7
7
  :validate-on-submit = "true"
8
8
  :validate-on-value-update = "true"
9
9
  :validate-on-blur = "false"
10
- :initial-values = "props.initialValues"
10
+ :initial-values = "values"
11
11
  :aria-disabled = "props.disabled"
12
12
  @submit = "handleFormSubmit"
13
13
  >
@@ -23,38 +23,44 @@ export * from "../../types/form";
23
23
  import PrimeForm, {} from "@primevue/forms/form";
24
24
  import { toNonNullableArray } from "@resee-movies/utilities/arrays/to-non-nullable-array";
25
25
  import { isPromiseLike } from "@resee-movies/utilities/objects/is-promise-like";
26
- import { syncRefs, watchDebounced } from "@vueuse/core";
27
- import { useTemplateRef, watchEffect } from "vue";
26
+ import { syncRefs, useDebounceFn } from "@vueuse/core";
27
+ import { useTemplateRef } from "vue";
28
+ import { useReactiveObjectsSync } from "../../composables/use-reactive-objects-sync";
28
29
  import { provideFormInstance, getValuesFromFormState } from "../../utils/form";
29
30
  const props = defineProps({
30
31
  disabled: { type: Boolean, required: false },
31
- initialValues: { type: Object, required: false },
32
32
  onSubmit: { type: [Function, Array], required: false },
33
- onChange: { type: Function, required: false },
34
- onChangeDebounce: { type: Number, required: false, default: 32 }
33
+ onChange: { type: Function, required: false }
35
34
  });
35
+ const form = useTemplateRef("form");
36
+ const values = defineModel("values", { type: null, ...{ default: void 0 } });
36
37
  defineEmits(["submit", "change"]);
37
38
  const formInstance = provideFormInstance();
38
39
  syncRefs(() => props.disabled, formInstance.isDisabled);
39
- const form = useTemplateRef("form");
40
- let oldValues = void 0;
41
- const changeHandles = watchDebounced(
42
- () => form.value?.states,
43
- (newState) => {
44
- const newValues = newState ? getValuesFromFormState(newState) : null;
45
- const stringify = JSON.stringify(newValues);
46
- if (stringify !== oldValues) {
47
- props.onChange?.(newValues);
48
- oldValues = stringify;
40
+ const emitOnChange = useDebounceFn(() => {
41
+ const state = form.value?.states;
42
+ if (state) {
43
+ props.onChange?.(getValuesFromFormState(state));
44
+ }
45
+ }, 1);
46
+ useReactiveObjectsSync({
47
+ left: () => form.value?.states,
48
+ right: () => values.value,
49
+ keySource: "left",
50
+ leftOptions: {
51
+ onChange: () => emitOnChange(),
52
+ getter(obj, key) {
53
+ return obj[key]?.value;
54
+ },
55
+ setter(obj, key, val) {
56
+ if (obj[key]) {
57
+ obj[key].value = val ?? null;
58
+ }
49
59
  }
50
60
  },
51
- {
52
- debounce: props.onChangeDebounce,
53
- deep: 2
61
+ rightOptions: {
62
+ onChange: () => emitOnChange()
54
63
  }
55
- );
56
- watchEffect(() => {
57
- changeHandles[props.onChange ? "resume" : "pause"]();
58
64
  });
59
65
  async function handleFormSubmit(event) {
60
66
  if (props.disabled) {
@@ -66,8 +72,8 @@ async function handleFormSubmit(event) {
66
72
  }
67
73
  if (props.onSubmit) {
68
74
  const handlers = toNonNullableArray(props.onSubmit);
69
- const values = getValuesFromFormState(event.states);
70
- const newEvent = { ...event, values };
75
+ const values2 = getValuesFromFormState(event.states);
76
+ const newEvent = { ...event, values: values2 };
71
77
  const results = handlers.map((handler) => handler(newEvent));
72
78
  if (!!results.find((result) => isPromiseLike(result))) {
73
79
  formInstance.isSubmitting.value = true;
@@ -2,16 +2,16 @@ import type { FormValues, FormSubmitHandler, FormSubmitEvent } from '../../types
2
2
  export * from '../../types/form.js';
3
3
  export interface FormProps<T extends FormValues = FormValues> {
4
4
  disabled?: boolean;
5
- initialValues?: Record<string, unknown>;
6
5
  onSubmit?: FormSubmitHandler<T> | FormSubmitHandler<T>[];
7
6
  onChange?: (values: T | null) => void;
8
- onChangeDebounce?: number;
9
7
  }
10
8
  declare const __VLS_export: <T extends FormValues>(__VLS_props: NonNullable<Awaited<typeof __VLS_setup>>["props"], __VLS_ctx?: __VLS_PrettifyLocal<Pick<NonNullable<Awaited<typeof __VLS_setup>>, "attrs" | "emit" | "slots">>, __VLS_expose?: NonNullable<Awaited<typeof __VLS_setup>>["expose"], __VLS_setup?: Promise<{
11
- props: __VLS_PrettifyLocal<FormProps<T> & __VLS_EmitsToProps<__VLS_NormalizeEmits<{
9
+ props: __VLS_PrettifyLocal<(FormProps<T> & {
10
+ values?: Partial<T> | undefined;
11
+ }) & __VLS_EmitsToProps<__VLS_NormalizeEmits<{
12
12
  (e: "submit", evt: FormSubmitEvent<T>): (void | Promise<void>);
13
13
  (e: "change", values: T): void;
14
- }>>> & import("vue").PublicProps & (typeof globalThis extends {
14
+ } & ((evt: "update:values", value: Partial<T> | undefined) => void)>>> & import("vue").PublicProps & (typeof globalThis extends {
15
15
  __VLS_PROPS_FALLBACK: infer P;
16
16
  } ? P : {});
17
17
  expose: (exposed: {}) => void;
@@ -24,7 +24,7 @@ declare const __VLS_export: <T extends FormValues>(__VLS_props: NonNullable<Awai
24
24
  emit: {
25
25
  (e: "submit", evt: FormSubmitEvent<T>): (void | Promise<void>);
26
26
  (e: "change", values: T): void;
27
- };
27
+ } & ((evt: "update:values", value: Partial<T> | undefined) => void);
28
28
  }>) => import("vue").VNode & {
29
29
  __ctx?: Awaited<typeof __VLS_setup>;
30
30
  };
@@ -1,11 +1,10 @@
1
1
  <template>
2
2
  <PrimeFormField
3
- v-slot = "$field"
4
- :as = "props.is"
5
- :name = "props.name"
6
- :resolver = "validatorFunction"
7
- :initial-value = "props.initialValue"
8
- :class = "['input-field', props.class, { disabled: isDisabled, readonly: isReadonly, required: props.required }]"
3
+ v-slot = "$field"
4
+ :as = "props.is"
5
+ :name = "props.name"
6
+ :resolver = "validatorFunction"
7
+ :class = "['input-field', props.class, { disabled: isDisabled, readonly: isReadonly, required: props.required }]"
9
8
  >
10
9
  <FormLabelInputPair
11
10
  :input-id = "inputId"
@@ -67,7 +66,6 @@ const props = defineProps({
67
66
  name: { type: String, required: true },
68
67
  label: { type: String, required: false, default: void 0 },
69
68
  is: { type: String, required: false, default: "div" },
70
- initialValue: { type: null, required: false, default: void 0 },
71
69
  required: { type: Boolean, required: false, default: false },
72
70
  disabled: { type: Boolean, required: false, default: false },
73
71
  readonly: { type: Boolean, required: false, default: false },
@@ -5,7 +5,6 @@ export interface FormFieldProps {
5
5
  name: string;
6
6
  label?: string;
7
7
  is?: HintedString<'div'>;
8
- initialValue?: unknown;
9
8
  required?: boolean;
10
9
  disabled?: boolean;
11
10
  readonly?: boolean;
@@ -41,7 +41,6 @@ const props = defineProps({
41
41
  name: { type: String, required: true },
42
42
  label: { type: String, required: false },
43
43
  is: { type: String, required: false },
44
- initialValue: { type: null, required: false, default: () => false },
45
44
  required: { type: Boolean, required: false },
46
45
  disabled: { type: Boolean, required: false },
47
46
  readonly: { type: Boolean, required: false },
@@ -64,7 +64,6 @@ const props = defineProps({
64
64
  name: { type: String, required: true },
65
65
  label: { type: String, required: false },
66
66
  is: { type: String, required: false },
67
- initialValue: { type: null, required: false },
68
67
  required: { type: Boolean, required: false },
69
68
  disabled: { type: Boolean, required: false },
70
69
  readonly: { type: Boolean, required: false },
@@ -44,7 +44,6 @@ const props = defineProps({
44
44
  name: { type: String, required: true },
45
45
  label: { type: String, required: false },
46
46
  is: { type: String, required: false },
47
- initialValue: { type: null, required: false },
48
47
  required: { type: Boolean, required: false },
49
48
  disabled: { type: Boolean, required: false },
50
49
  readonly: { type: Boolean, required: false },
@@ -36,7 +36,6 @@ const props = defineProps({
36
36
  name: { type: String, required: true },
37
37
  label: { type: String, required: false },
38
38
  is: { type: String, required: false },
39
- initialValue: { type: null, required: false },
40
39
  required: { type: Boolean, required: false },
41
40
  disabled: { type: Boolean, required: false },
42
41
  readonly: { type: Boolean, required: false },
@@ -32,7 +32,6 @@ const props = defineProps({
32
32
  name: { type: String, required: true },
33
33
  label: { type: String, required: false },
34
34
  is: { type: String, required: false },
35
- initialValue: { type: null, required: false, default: () => false },
36
35
  required: { type: Boolean, required: false },
37
36
  disabled: { type: Boolean, required: false },
38
37
  readonly: { type: Boolean, required: false },
@@ -88,9 +88,9 @@ function getSelectedOptionIndex(option) {
88
88
  const equalityKey = props.optionValue ? void 0 : props.optionDataKey;
89
89
  const optionValue = getOptionValue(option);
90
90
  if (Array.isArray(value.value)) {
91
- return value.value.findIndex((entry) => equals(getOptionValue(entry), optionValue, equalityKey));
91
+ return value.value.findIndex((entry) => equals(entry, optionValue, equalityKey));
92
92
  }
93
- return equals(getOptionValue(value.value), optionValue, equalityKey) ? 0 : -1;
93
+ return equals(value.value, optionValue, equalityKey) ? 0 : -1;
94
94
  }
95
95
  function handleToggleChange(option, pressed) {
96
96
  if (props.multiple) {
@@ -21,8 +21,10 @@
21
21
  checkbox-icon = "i-ph-check-bold"
22
22
  >
23
23
  <template #value="{ value, placeholder }">
24
- <template v-if="value">
25
- {{ toLabel(value) }}
24
+ <template v-if="value && (Array.isArray(value) ? value.length : true)">
25
+ <slot name="label">
26
+ {{ toLabel(value) || "\u200B" }}
27
+ </slot>
26
28
  </template>
27
29
 
28
30
  <span v-else class="placeholder">
@@ -9,6 +9,8 @@ export interface FormElementSelectOptionsProps extends Omit<PrimeSelectProps, 'i
9
9
  selectionLimit?: string | number;
10
10
  }
11
11
  declare const __VLS_export: __VLS_WithSlots<import("vue").DefineComponent<FormElementSelectOptionsProps, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").PublicProps, Readonly<FormElementSelectOptionsProps> & Readonly<{}>, {}, {}, {}, {}, string, import("vue").ComponentProvideOptions, false, {}, any>, {
12
+ label?: (props: {}) => any;
13
+ } & {
12
14
  option?: (props: {
13
15
  option: any;
14
16
  selected: any;
@@ -0,0 +1,18 @@
1
+ import { type MaybeRefOrGetter } from 'vue';
2
+ export type SyncObject = Record<string | number | symbol, unknown>;
3
+ export type KeyOf<S extends SyncObject> = keyof S;
4
+ export type Getter<S extends SyncObject> = <R>(obj: S, key: KeyOf<S>) => R;
5
+ export type Setter<S extends SyncObject> = (obj: S, key: KeyOf<S>, value: unknown) => void;
6
+ export type ComputedReadWriteOptions<S extends SyncObject> = {
7
+ getter?: Getter<S>;
8
+ setter?: Setter<S>;
9
+ onChange?: (key: KeyOf<S>, value: unknown) => void;
10
+ };
11
+ export type UseReactiveObjectsSyncOptions<L extends SyncObject, R extends SyncObject> = {
12
+ left: MaybeRefOrGetter<L | undefined>;
13
+ right: MaybeRefOrGetter<R | undefined>;
14
+ keySource?: 'left' | 'right' | (KeyOf<L> | KeyOf<R>)[];
15
+ leftOptions?: ComputedReadWriteOptions<L>;
16
+ rightOptions?: ComputedReadWriteOptions<R>;
17
+ };
18
+ export declare function useReactiveObjectsSync<L extends SyncObject, R extends SyncObject>(options: UseReactiveObjectsSyncOptions<L, R>): void;
@@ -0,0 +1,73 @@
1
+ import { syncRef } from "@vueuse/core";
2
+ import {
3
+ toValue,
4
+ watchEffect,
5
+ watch,
6
+ computed,
7
+ shallowRef
8
+ } from "vue";
9
+ export function useReactiveObjectsSync(options) {
10
+ const { left, right } = options;
11
+ const watchKeys = aggregateKeys(options);
12
+ const syncHandle = /* @__PURE__ */ new Map();
13
+ watch(watchKeys, (newKeys, oldKeys) => {
14
+ for (const key of oldKeys.difference(newKeys)) {
15
+ const handle = syncHandle.get(key);
16
+ if (handle) {
17
+ syncHandle.delete(key);
18
+ handle.stopSync();
19
+ }
20
+ }
21
+ for (const key of newKeys) {
22
+ if (syncHandle.has(key)) {
23
+ continue;
24
+ }
25
+ const leftRef = computedReadWrite(left, key, options?.leftOptions);
26
+ const rightRef = computedReadWrite(right, key, options?.rightOptions);
27
+ const stopSync = syncRef(leftRef, rightRef);
28
+ syncHandle.set(key, { leftRef, rightRef, stopSync });
29
+ }
30
+ });
31
+ }
32
+ function objectKeysRef(source) {
33
+ const keys = shallowRef([]);
34
+ watchEffect(() => {
35
+ const value = toValue(source);
36
+ keys.value = value ? Object.keys(value) : [];
37
+ });
38
+ return keys;
39
+ }
40
+ function aggregateKeys(options) {
41
+ const leftKeys = !options.keySource || options.keySource === "left" ? objectKeysRef(options.left) : void 0;
42
+ const rightKeys = !options.keySource || options.keySource === "right" ? objectKeysRef(options.right) : void 0;
43
+ return computed(() => {
44
+ if (Array.isArray(options.keySource)) {
45
+ return new Set(options.keySource);
46
+ }
47
+ return /* @__PURE__ */ new Set(
48
+ [...leftKeys?.value ?? [], ...rightKeys?.value ?? []]
49
+ );
50
+ });
51
+ }
52
+ function computedReadWrite(source, key, options) {
53
+ return computed({
54
+ get() {
55
+ const target = toValue(source);
56
+ if (target) {
57
+ return options?.getter ? options.getter(target, key) : target[key];
58
+ }
59
+ return void 0;
60
+ },
61
+ set(val) {
62
+ const target = toValue(source);
63
+ if (target) {
64
+ if (options?.setter) {
65
+ options.setter(target, key, val);
66
+ } else {
67
+ target[key] = val;
68
+ }
69
+ options?.onChange?.(key, val);
70
+ }
71
+ }
72
+ });
73
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@resee-movies/nuxt-ux",
3
- "version": "0.6.0",
3
+ "version": "0.7.1",
4
4
  "description": "The next-gen user experience library for ReSee Movies - currently in development. ",
5
5
  "repository": {
6
6
  "url": "https://github.com/ReSee-Movies/nuxt-ux.git"
@@ -35,7 +35,7 @@
35
35
  "dist"
36
36
  ],
37
37
  "scripts": {
38
- "dev": "npm run dev:prepare && nuxi dev playground",
38
+ "dev": "npm run dev:prepare && nuxi dev playground --local --port 3003",
39
39
  "dev:preview": "npm run dev:build && nuxi preview playground",
40
40
  "dev:build": "nuxi build playground",
41
41
  "dev:prepare": "nuxt-module-build build --stub && nuxt-module-build prepare && nuxi prepare playground",