@chelone/vue 0.5.0 → 0.6.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.
Files changed (37) hide show
  1. package/README.md +1 -0
  2. package/dist/components/admin/fields/api-key-field.vue.d.ts +1 -1
  3. package/dist/components/admin/fields/api-key-field.vue.js +2 -12
  4. package/dist/components/index.d.ts +0 -2
  5. package/dist/components/kanban/kanban-board.vue.js +260 -0
  6. package/dist/components/kanban/kanban-draggable-card.vue.d.ts +18 -0
  7. package/dist/components/kanban/kanban-draggable-card.vue.js +32 -0
  8. package/dist/components/kanban/kanban-draggable-card2.vue.js +4 -0
  9. package/dist/components/kanban/kanban-drop-area.vue.d.ts +15 -0
  10. package/dist/components/kanban/kanban-drop-area.vue.js +29 -0
  11. package/dist/components/kanban/kanban-drop-area2.vue.js +4 -0
  12. package/dist/components/ui/chart/chart-container.vue.d.ts +18 -0
  13. package/dist/components/ui/chart/chart-container.vue.js +40 -0
  14. package/dist/components/ui/chart/chart-container2.vue.js +4 -0
  15. package/dist/components/ui/chart/chart-legend-content.vue.d.ts +9 -0
  16. package/dist/components/ui/chart/chart-legend-content.vue.js +56 -0
  17. package/dist/components/ui/chart/chart-legend-content2.vue.js +4 -0
  18. package/dist/components/ui/chart/chart-style.vue.d.ts +7 -0
  19. package/dist/components/ui/chart/chart-style.vue.js +43 -0
  20. package/dist/components/ui/chart/chart-style2.vue.js +4 -0
  21. package/dist/components/ui/chart/chart-tooltip-content.vue.d.ts +7 -0
  22. package/dist/components/ui/chart/chart-tooltip-content.vue.js +122 -0
  23. package/dist/components/ui/chart/chart-tooltip-content2.vue.js +4 -0
  24. package/dist/components/ui/chart/index.d.ts +11 -0
  25. package/dist/components/ui/chart/utils.d.ts +81 -0
  26. package/dist/components/ui/chart/utils.js +52 -0
  27. package/dist/components/ui/index.d.ts +1 -0
  28. package/dist/data/create-chelone-hooks.d.ts +2 -1
  29. package/dist/data/queries.d.ts +6 -3
  30. package/dist/data/queries.js +8 -4
  31. package/dist/index.js +398 -387
  32. package/dist/kanban.d.ts +1 -0
  33. package/dist/kanban.js +4 -0
  34. package/package.json +18 -4
  35. package/dist/components/admin/list/kanban-board.vue.js +0 -275
  36. /package/dist/components/{admin/list → kanban}/kanban-board.vue.d.ts +0 -0
  37. /package/dist/components/{admin/list → kanban}/kanban-board2.vue.js +0 -0
@@ -0,0 +1,122 @@
1
+ import { defineComponent, computed, openBlock, createElementBlock, normalizeClass, unref, toDisplayString, createCommentVNode, createElementVNode, Fragment, renderList, createBlock, resolveDynamicComponent, normalizeStyle, createTextVNode } from "vue";
2
+ import { cn } from "../../../lib/utils.js";
3
+ import { useChart } from "./utils.js";
4
+ const _hoisted_1 = {
5
+ key: 0,
6
+ class: "font-medium"
7
+ };
8
+ const _hoisted_2 = { class: "grid gap-1.5" };
9
+ const _hoisted_3 = { class: "grid gap-1.5" };
10
+ const _hoisted_4 = {
11
+ key: 0,
12
+ class: "font-medium"
13
+ };
14
+ const _hoisted_5 = { class: "text-muted-foreground" };
15
+ const _hoisted_6 = {
16
+ key: 0,
17
+ class: "font-mono font-medium text-foreground tabular-nums"
18
+ };
19
+ const _sfc_main = /* @__PURE__ */ defineComponent({
20
+ __name: "chart-tooltip-content",
21
+ props: {
22
+ class: {},
23
+ hideLabel: { type: Boolean },
24
+ hideIndicator: { type: Boolean },
25
+ indicator: { default: "dot" },
26
+ nameKey: {},
27
+ labelKey: {},
28
+ labelFormatter: {},
29
+ color: {},
30
+ payload: { default: () => ({}) },
31
+ x: {}
32
+ },
33
+ setup(__props) {
34
+ const props = __props;
35
+ const { config } = useChart();
36
+ const label = computed(() => {
37
+ if (props.hideLabel) return null;
38
+ if (props.labelKey && props.payload[props.labelKey] != null) {
39
+ return String(props.payload[props.labelKey]);
40
+ }
41
+ if (props.x === void 0) return null;
42
+ if (props.labelFormatter) return String(props.labelFormatter(props.x));
43
+ return props.x instanceof Date ? props.x.toISOString() : String(props.x);
44
+ });
45
+ const rows = computed(
46
+ () => Object.entries(props.payload).filter(([key]) => Object.hasOwn(config.value, key) && key !== props.labelKey).map(([key, value]) => {
47
+ const item = config.value[key];
48
+ const named = props.nameKey ? props.payload[props.nameKey] : void 0;
49
+ return {
50
+ key,
51
+ item,
52
+ name: item?.label ?? (named != null ? String(named) : key),
53
+ value: value == null ? null : typeof value === "number" ? value.toLocaleString() : String(value),
54
+ color: props.color ?? item?.color ?? `var(--color-${key})`
55
+ };
56
+ })
57
+ );
58
+ const nestLabel = computed(
59
+ () => rows.value.length === 1 && props.indicator !== "dot"
60
+ );
61
+ return (_ctx, _cache) => {
62
+ return openBlock(), createElementBlock("div", {
63
+ class: normalizeClass(
64
+ unref(cn)(
65
+ "grid min-w-[8rem] items-start gap-1.5 rounded-lg border border-border/50 bg-background px-2.5 py-1.5 text-xs shadow-xl",
66
+ props.class
67
+ )
68
+ )
69
+ }, [
70
+ label.value && !nestLabel.value ? (openBlock(), createElementBlock("div", _hoisted_1, toDisplayString(label.value), 1)) : createCommentVNode("", true),
71
+ createElementVNode("div", _hoisted_2, [
72
+ (openBlock(true), createElementBlock(Fragment, null, renderList(rows.value, (row) => {
73
+ return openBlock(), createElementBlock("div", {
74
+ key: row.key,
75
+ class: normalizeClass(
76
+ unref(cn)(
77
+ "flex w-full flex-wrap items-stretch gap-2 [&>svg]:h-2.5 [&>svg]:w-2.5 [&>svg]:text-muted-foreground",
78
+ props.indicator === "dot" && "items-center"
79
+ )
80
+ )
81
+ }, [
82
+ row.item?.icon ? (openBlock(), createBlock(resolveDynamicComponent(row.item?.icon), { key: 0 })) : !props.hideIndicator ? (openBlock(), createElementBlock("div", {
83
+ key: 1,
84
+ class: normalizeClass(
85
+ unref(cn)(
86
+ "shrink-0 rounded-[2px] border-(--color-border) bg-(--color-bg)",
87
+ props.indicator === "dot" && "h-2.5 w-2.5",
88
+ props.indicator === "line" && "w-1",
89
+ props.indicator === "dashed" && "w-0 border-[1.5px] border-dashed bg-transparent",
90
+ nestLabel.value && props.indicator === "dashed" && "my-0.5"
91
+ )
92
+ ),
93
+ style: normalizeStyle({ "--color-bg": row.color, "--color-border": row.color })
94
+ }, null, 6)) : createCommentVNode("", true),
95
+ createElementVNode("div", {
96
+ class: normalizeClass(
97
+ unref(cn)(
98
+ "flex flex-1 justify-between leading-none",
99
+ nestLabel.value ? "items-end" : "items-center"
100
+ )
101
+ )
102
+ }, [
103
+ createElementVNode("div", _hoisted_3, [
104
+ nestLabel.value && label.value ? (openBlock(), createElementBlock("div", _hoisted_4, toDisplayString(label.value), 1)) : createCommentVNode("", true),
105
+ createElementVNode("span", _hoisted_5, [
106
+ typeof row.name !== "string" ? (openBlock(), createBlock(resolveDynamicComponent(row.name), { key: 0 })) : (openBlock(), createElementBlock(Fragment, { key: 1 }, [
107
+ createTextVNode(toDisplayString(row.name), 1)
108
+ ], 64))
109
+ ])
110
+ ]),
111
+ row.value !== null ? (openBlock(), createElementBlock("span", _hoisted_6, toDisplayString(row.value), 1)) : createCommentVNode("", true)
112
+ ], 2)
113
+ ], 2);
114
+ }), 128))
115
+ ])
116
+ ], 2);
117
+ };
118
+ }
119
+ });
120
+ export {
121
+ _sfc_main as default
122
+ };
@@ -0,0 +1,4 @@
1
+ import _sfc_main from "./chart-tooltip-content.vue.js";
2
+ export {
3
+ _sfc_main as default
4
+ };
@@ -0,0 +1,11 @@
1
+ /**
2
+ * The dependency-free `chart` family barrel — the Vue analog of shadcn-vue's
3
+ * `ui/chart`, without its UI-primitive and utility dependencies. shadcn-vue's
4
+ * re-export of the tooltip and crosshair from the chart library is left out so
5
+ * nothing here imports one; the charts import those themselves.
6
+ */
7
+ export { default as ChartContainer } from "./chart-container.vue.js";
8
+ export { default as ChartLegendContent } from "./chart-legend-content.vue.js";
9
+ export { default as ChartStyle } from "./chart-style.vue.js";
10
+ export { default as ChartTooltipContent } from "./chart-tooltip-content.vue.js";
11
+ export { type ChartConfig, type ChartContextProps, type ChartDatum, type ChartDatumValue, type ChartTooltipOptions, type ChartTooltipRenderProps, componentToString, provideChartContext, THEMES, useChart, } from "./utils.js";
@@ -0,0 +1,81 @@
1
+ /**
2
+ * The non-component core of the dependency-free `chart` family: the config
3
+ * type, the theme map, the `useChart` context and `componentToString`.
4
+ *
5
+ * Ported from shadcn-vue's `ui/chart` without its context, id and client-check
6
+ * helper packages: the context is a typed `InjectionKey` as in
7
+ * `dropdown-menu/context.ts`, ids come from a module counter (Vue's peer range
8
+ * starts before Vue's own `useId`), and the client check is a `typeof window`
9
+ * test.
10
+ */
11
+ import { type Component, type Ref } from "vue";
12
+ /** Format: `{ THEME_NAME: CSS_SELECTOR }`. */
13
+ export declare const THEMES: {
14
+ readonly light: "";
15
+ readonly dark: ".dark";
16
+ };
17
+ export type ChartConfig = {
18
+ [key in string]: {
19
+ label?: string | Component;
20
+ icon?: string | Component;
21
+ } & ({
22
+ color?: string;
23
+ theme?: never;
24
+ } | {
25
+ color?: never;
26
+ theme: Record<keyof typeof THEMES, string>;
27
+ });
28
+ };
29
+ /** A value a tooltip can show; the datum's other fields are never read. */
30
+ export type ChartDatumValue = string | number | boolean | Date | null | undefined;
31
+ /** One hovered datum: field name to value. */
32
+ export type ChartDatum = Record<string, ChartDatumValue>;
33
+ /** unovis hands a tooltip either the datum or a node holding it as `data`. */
34
+ type ChartTooltipTarget = ChartDatum | {
35
+ data: ChartDatum;
36
+ };
37
+ /** What `componentToString` adds to the props it is given. */
38
+ export interface ChartTooltipRenderProps {
39
+ payload?: ChartDatum;
40
+ /** The hovered x value. */
41
+ x?: number | Date;
42
+ }
43
+ /** The props of `<ChartTooltipContent>` a caller sets. */
44
+ export interface ChartTooltipOptions {
45
+ class?: string;
46
+ hideLabel?: boolean;
47
+ hideIndicator?: boolean;
48
+ indicator?: "line" | "dot" | "dashed";
49
+ /** Payload key whose value names each row; defaults to the key itself. */
50
+ nameKey?: string;
51
+ /** Payload key shown as the heading in place of `x`. */
52
+ labelKey?: string;
53
+ labelFormatter?: (x: number | Date) => string | number;
54
+ color?: string;
55
+ }
56
+ /** The contract `<ChartContainer>` provides to the chart parts. */
57
+ export interface ChartContextProps {
58
+ id: string;
59
+ config: Ref<ChartConfig>;
60
+ }
61
+ /** Provide the chart context (called by `<ChartContainer>` in `setup`). */
62
+ export declare function provideChartContext(ctx: ChartContextProps): void;
63
+ /** Read the ambient chart context. Throws outside a `<ChartContainer>`. */
64
+ export declare function useChart(): ChartContextProps;
65
+ /**
66
+ * A page-unique id, safe to put in a selector. Inside a component it is Vue's
67
+ * own `useId` where the installed Vue has one (3.5+), which is per app and so
68
+ * matches between server render and hydration. Vue's peer range starts at 3.4,
69
+ * and `componentToString` calls this outside a component; both fall back to a
70
+ * module counter, which a server that renders several requests in one process
71
+ * does not reset, so on Vue 3.4 pass `id` to `<ChartContainer>` for SSR.
72
+ */
73
+ export declare function useId(): string;
74
+ /**
75
+ * Turn a tooltip component into a `(data, x?) => html` function, the shape
76
+ * unovis' tooltip `triggers` take. Returns nothing on the server, where
77
+ * there is no DOM to render into. The HTML comes from Vue's renderer, so text
78
+ * in the payload is escaped.
79
+ */
80
+ export declare function componentToString(config: ChartConfig, component: Component, props?: ChartTooltipOptions): ((data: ChartTooltipTarget, x?: number | Date) => string) | undefined;
81
+ export {};
@@ -0,0 +1,52 @@
1
+ import * as Vue from "vue";
2
+ import { getCurrentInstance, provide, inject, defineComponent, ref, h, createApp } from "vue";
3
+ const THEMES = { light: "", dark: ".dark" };
4
+ const ChartKey = /* @__PURE__ */ Symbol("chelone-chart");
5
+ function provideChartContext(ctx) {
6
+ provide(ChartKey, ctx);
7
+ }
8
+ function useChart() {
9
+ const ctx = inject(ChartKey, null);
10
+ if (!ctx) {
11
+ throw new Error("useChart: used outside a <ChartContainer> component.");
12
+ }
13
+ return ctx;
14
+ }
15
+ let idCounter = 0;
16
+ function useId() {
17
+ const vueUseId = Vue.useId;
18
+ if (vueUseId && getCurrentInstance()) {
19
+ return vueUseId().replace(/[^\w-]/g, "");
20
+ }
21
+ idCounter += 1;
22
+ return `chelone-${idCounter}`;
23
+ }
24
+ function isWrapped(target) {
25
+ return "data" in target && typeof target.data === "object" && target.data !== null && !(target.data instanceof Date);
26
+ }
27
+ function componentToString(config, component, props) {
28
+ if (typeof window === "undefined") return void 0;
29
+ const id = useId();
30
+ return (data, x) => {
31
+ const payload = isWrapped(data) ? data.data : data;
32
+ const host = defineComponent({
33
+ setup() {
34
+ provideChartContext({ id, config: ref(config) });
35
+ return () => h(component, { ...props, payload, x });
36
+ }
37
+ });
38
+ const app = createApp(host);
39
+ const el = document.createElement("div");
40
+ app.mount(el);
41
+ const html = el.innerHTML;
42
+ app.unmount();
43
+ return html;
44
+ };
45
+ }
46
+ export {
47
+ THEMES,
48
+ componentToString,
49
+ provideChartContext,
50
+ useChart,
51
+ useId
52
+ };
@@ -4,6 +4,7 @@ export { Badge, type BadgeVariant } from "./badge.js";
4
4
  export { default as Button } from "./button.vue.js";
5
5
  export { type ButtonSize, type ButtonVariant, type ButtonVariantsOptions, buttonVariants, } from "./button-variants.js";
6
6
  export { Card, CardContent, CardFooter, CardHeader, CardTitle, } from "./card.js";
7
+ export { type ChartConfig, ChartContainer, type ChartContextProps, ChartLegendContent, ChartStyle, ChartTooltipContent, componentToString, provideChartContext, THEMES, useChart, } from "./chart/index.js";
7
8
  export { default as Checkbox } from "./checkbox.vue.js";
8
9
  export type { CommandContext, CommandDialogProps, CommandFilter, CommandItemEntry, CommandProps, } from "./command/index.js";
9
10
  export { Command, CommandDialog, CommandEmpty, CommandGroup, CommandInput, CommandItem, CommandKey, CommandList, CommandSeparator, CommandShortcut, defaultCommandFilter, provideCommand, useCommand, } from "./command/index.js";
@@ -7,6 +7,7 @@
7
7
  */
8
8
  import type { GetListParams, GetManyParams, GetManyReferenceParams, GetOneParams, MutationModeOptions, ResourceMap } from "@chelone/core";
9
9
  import type { MaybeRefOrGetter } from "vue";
10
+ import { type ListQueryOptions } from "./queries.js";
10
11
  type QueryOptions = {
11
12
  enabled?: MaybeRefOrGetter<boolean>;
12
13
  };
@@ -16,7 +17,7 @@ type QueryOptions = {
16
17
  * hooks.useGetList('posts') // data: Post[]; 'nope' rejects
17
18
  */
18
19
  export declare function createCheloneHooks<TResources extends ResourceMap>(): {
19
- useGetList: <TName extends keyof TResources & string>(resource: TName, params?: MaybeRefOrGetter<GetListParams>, options?: QueryOptions) => import("@tanstack/vue-query").UseQueryReturnType<import("@chelone/core").GetListResult<import("@chelone/core").RecordOf<TResources, TName>>, Error>;
20
+ useGetList: <TName extends keyof TResources & string>(resource: TName, params?: MaybeRefOrGetter<GetListParams>, options?: ListQueryOptions) => import("@tanstack/vue-query").UseQueryReturnType<import("@chelone/core").GetListResult<import("@chelone/core").RecordOf<TResources, TName>>, Error>;
20
21
  useGetOne: <TName extends keyof TResources & string>(resource: TName, params: MaybeRefOrGetter<GetOneParams>, options?: QueryOptions) => import("@tanstack/vue-query").UseQueryReturnType<import("@chelone/core").RecordOf<TResources, TName>, Error>;
21
22
  useGetMany: <TName extends keyof TResources & string>(resource: TName, params: MaybeRefOrGetter<GetManyParams>, options?: QueryOptions) => import("@tanstack/vue-query").UseQueryReturnType<import("@chelone/core").RecordOf<TResources, TName>[], Error>;
22
23
  useGetManyAggregate: <TName extends keyof TResources & string>(resource: TName, params: MaybeRefOrGetter<GetManyParams>, options?: QueryOptions) => import("@tanstack/vue-query").UseQueryReturnType<import("@chelone/core").RecordOf<TResources, TName>[], Error>;
@@ -36,13 +36,16 @@ export declare function useGetMany<TResources extends ResourceMap = ResourceMap,
36
36
  export declare function useGetManyAggregate<TResources extends ResourceMap = ResourceMap, TName extends keyof TResources & string = keyof TResources & string>(resource: TName, params: MaybeRefOrGetter<GetManyParams>, options?: {
37
37
  enabled?: MaybeRefOrGetter<boolean>;
38
38
  }): import("@tanstack/vue-query").UseQueryReturnType<import("@chelone/core").RecordOf<TResources, TName>[], Error>;
39
+ /** `refetchInterval` is in ms; `0`, a negative number or `false` turns polling off. */
40
+ export type ListQueryOptions = {
41
+ enabled?: MaybeRefOrGetter<boolean>;
42
+ refetchInterval?: MaybeRefOrGetter<number | false>;
43
+ };
39
44
  /**
40
45
  * Fetch a page of records, reactively. `resource` may be a ref or getter, so a
41
46
  * changing resource re-keys the query.
42
47
  */
43
- export declare function useGetList<TResources extends ResourceMap = ResourceMap, TName extends keyof TResources & string = keyof TResources & string>(resource: MaybeRefOrGetter<TName>, params?: MaybeRefOrGetter<GetListParams>, options?: {
44
- enabled?: MaybeRefOrGetter<boolean>;
45
- }): import("@tanstack/vue-query").UseQueryReturnType<import("@chelone/core").GetListResult<import("@chelone/core").RecordOf<TResources, TName>>, Error>;
48
+ export declare function useGetList<TResources extends ResourceMap = ResourceMap, TName extends keyof TResources & string = keyof TResources & string>(resource: MaybeRefOrGetter<TName>, params?: MaybeRefOrGetter<GetListParams>, options?: ListQueryOptions): import("@tanstack/vue-query").UseQueryReturnType<import("@chelone/core").GetListResult<import("@chelone/core").RecordOf<TResources, TName>>, Error>;
46
49
  /** Fetch the records whose `target` field equals `id`, reactively. */
47
50
  export declare function useGetManyReference<TResources extends ResourceMap = ResourceMap, TName extends keyof TResources & string = keyof TResources & string>(resource: TName, params: MaybeRefOrGetter<GetManyReferenceParams>, options?: {
48
51
  enabled?: MaybeRefOrGetter<boolean>;
@@ -32,10 +32,14 @@ function useGetManyAggregate(resource, params, options = {}) {
32
32
  function useGetList(resource, params = {}, options = {}) {
33
33
  const ctx = useCheloneContext();
34
34
  return useQuery(
35
- computed(() => ({
36
- ...getListOptions(ctx, toValue(resource), toValue(params)),
37
- enabled: options.enabled === void 0 ? true : toValue(options.enabled)
38
- }))
35
+ computed(() => {
36
+ const interval = toValue(options.refetchInterval);
37
+ return {
38
+ ...getListOptions(ctx, toValue(resource), toValue(params)),
39
+ enabled: options.enabled === void 0 ? true : toValue(options.enabled),
40
+ refetchInterval: typeof interval === "number" && interval > 0 ? interval : false
41
+ };
42
+ })
39
43
  );
40
44
  }
41
45
  function useGetManyReference(resource, params, options = {}) {