@rkosafo/cai.components 0.0.31 → 0.0.33
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/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/dist/layout/ComponentCanvas/Canvas.svelte +40 -0
- package/dist/layout/ComponentCanvas/Canvas.svelte.d.ts +4 -0
- package/dist/layout/ComponentCanvas/ComponentRenderer.svelte +85 -0
- package/dist/layout/ComponentCanvas/ComponentRenderer.svelte.d.ts +6 -0
- package/dist/layout/ComponentCanvas/index.d.ts +2 -0
- package/dist/layout/ComponentCanvas/index.js +2 -0
- package/dist/types/index.d.ts +28 -0
- package/dist/ui/buttons/ActionButton.svelte +2 -0
- package/dist/utils/index.d.ts +5 -0
- package/dist/utils/index.js +17 -0
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -25,6 +25,7 @@ export * from './ui/tab/index.js';
|
|
|
25
25
|
export * from './ui/icons/index.js';
|
|
26
26
|
export * from './ui/box/index.js';
|
|
27
27
|
export * from './ui/breadcrumb/index.js';
|
|
28
|
+
export * from './layout/ComponentCanvas/index.js';
|
|
28
29
|
export * from './forms/input/index.js';
|
|
29
30
|
export * from './forms/label/index.js';
|
|
30
31
|
export * from './forms/datepicker/index.js';
|
package/dist/index.js
CHANGED
|
@@ -26,6 +26,7 @@ export * from './ui/tab/index.js';
|
|
|
26
26
|
export * from './ui/icons/index.js';
|
|
27
27
|
export * from './ui/box/index.js';
|
|
28
28
|
export * from './ui/breadcrumb/index.js';
|
|
29
|
+
export * from './layout/ComponentCanvas/index.js';
|
|
29
30
|
export * from './forms/input/index.js';
|
|
30
31
|
export * from './forms/label/index.js';
|
|
31
32
|
export * from './forms/datepicker/index.js';
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
<script lang="ts">
|
|
2
|
+
import { receive, type IComponentDescriptor, type IDocumentCanvasProps } from '../../index.js';
|
|
3
|
+
import { nanoid } from 'nanoid';
|
|
4
|
+
import ComponentRenderer from './ComponentRenderer.svelte';
|
|
5
|
+
|
|
6
|
+
let {
|
|
7
|
+
children = [],
|
|
8
|
+
close,
|
|
9
|
+
contextKey,
|
|
10
|
+
toggleCollapse,
|
|
11
|
+
showBackground
|
|
12
|
+
}: IDocumentCanvasProps = $props();
|
|
13
|
+
|
|
14
|
+
function updateChildren(children: IComponentDescriptor[]) {
|
|
15
|
+
return children.map((a) => {
|
|
16
|
+
if (!a.id) a.id = nanoid();
|
|
17
|
+
return a;
|
|
18
|
+
});
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
let toRender = $derived(updateChildren(children));
|
|
22
|
+
</script>
|
|
23
|
+
|
|
24
|
+
<div class="flex flex-grow flex-col gap-5">
|
|
25
|
+
{#each toRender as child (child.id)}
|
|
26
|
+
<div
|
|
27
|
+
class="flex p-3"
|
|
28
|
+
class:shadow={showBackground}
|
|
29
|
+
class:bg-white={showBackground}
|
|
30
|
+
in:receive={{ key: child.id }}
|
|
31
|
+
>
|
|
32
|
+
<ComponentRenderer descriptor={child} {contextKey} {close} {toggleCollapse} />
|
|
33
|
+
</div>
|
|
34
|
+
{/each}
|
|
35
|
+
{#if toRender.length === 0}
|
|
36
|
+
<!-- <Alert>
|
|
37
|
+
It is lonely here
|
|
38
|
+
</Alert> -->
|
|
39
|
+
{/if}
|
|
40
|
+
</div>
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
<script lang="ts" module>
|
|
2
|
+
let mappers: ((name: string) => ConstructorOfATypedSvelteComponent)[] = [];
|
|
3
|
+
function componentNameToType(name: string) {
|
|
4
|
+
for (let i = 0; i < mappers.length; i++) {
|
|
5
|
+
let cmp = mappers[i](name);
|
|
6
|
+
if (cmp != null) return cmp;
|
|
7
|
+
}
|
|
8
|
+
return null;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export function addMapper(f: (name: string) => ConstructorOfATypedSvelteComponent) {
|
|
12
|
+
mappers = [f, ...mappers];
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export function removeMapper(f: (name: string) => ConstructorOfATypedSvelteComponent) {
|
|
16
|
+
mappers = mappers.filter((x) => x != f);
|
|
17
|
+
}
|
|
18
|
+
</script>
|
|
19
|
+
|
|
20
|
+
<script lang="ts">
|
|
21
|
+
import {
|
|
22
|
+
IconifyIcon,
|
|
23
|
+
type IComponentDescriptor,
|
|
24
|
+
type IDocumentRendererProps
|
|
25
|
+
} from '../../index.js';
|
|
26
|
+
|
|
27
|
+
let {
|
|
28
|
+
descriptor,
|
|
29
|
+
showTitle = true,
|
|
30
|
+
contextKey,
|
|
31
|
+
toggleCollapse,
|
|
32
|
+
close
|
|
33
|
+
}: IDocumentRendererProps = $props();
|
|
34
|
+
|
|
35
|
+
function decode(descriptor: IComponentDescriptor) {
|
|
36
|
+
return {
|
|
37
|
+
compoent: componentNameToType(descriptor.type),
|
|
38
|
+
props: descriptor.props || {}
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
let data = $derived(decode(descriptor));
|
|
43
|
+
</script>
|
|
44
|
+
|
|
45
|
+
{#if data.compoent}
|
|
46
|
+
<div class="flex-grow">
|
|
47
|
+
{#if descriptor.title && showTitle}
|
|
48
|
+
<div class="flex items-center justify-between border-b border-dotted pb-1">
|
|
49
|
+
<h3 class="font-bold text-teal-500">
|
|
50
|
+
{descriptor.title || ''}
|
|
51
|
+
</h3>
|
|
52
|
+
<div class="flex items-center gap-2">
|
|
53
|
+
<button
|
|
54
|
+
aria-label="collapse"
|
|
55
|
+
onclick={(_) => toggleCollapse(descriptor.id!)}
|
|
56
|
+
class="grid place-content-center rounded-full p-1 hover:bg-gray-200"
|
|
57
|
+
class:hidden={!descriptor.collapsible}
|
|
58
|
+
>
|
|
59
|
+
<IconifyIcon
|
|
60
|
+
icon={descriptor.collapsed
|
|
61
|
+
? 'iconamoon:arrow-down-2-duotone'
|
|
62
|
+
: 'iconamoon:arrow-up-2-duotone'}
|
|
63
|
+
style="font-size: 20px;"
|
|
64
|
+
/>
|
|
65
|
+
</button>
|
|
66
|
+
<button
|
|
67
|
+
aria-label="close"
|
|
68
|
+
onclick={(e) => close({ id: descriptor.id!, data: e.detail })}
|
|
69
|
+
class="grid place-content-center rounded-full p-1 hover:bg-red-200 hover:text-red-400"
|
|
70
|
+
class:hidden={!descriptor.closable}
|
|
71
|
+
>
|
|
72
|
+
<iconify-icon icon="ic:round-close" style="font-size: 20px;"></iconify-icon>
|
|
73
|
+
</button>
|
|
74
|
+
</div>
|
|
75
|
+
</div>
|
|
76
|
+
{/if}
|
|
77
|
+
<div class:hidden={descriptor.collapsed}>
|
|
78
|
+
<data.compoent
|
|
79
|
+
{...data.props}
|
|
80
|
+
{contextKey}
|
|
81
|
+
close={(e: any) => close({ id: descriptor.id!, data: e.detail })}
|
|
82
|
+
/>
|
|
83
|
+
</div>
|
|
84
|
+
</div>
|
|
85
|
+
{/if}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export declare function addMapper(f: (name: string) => ConstructorOfATypedSvelteComponent): void;
|
|
2
|
+
export declare function removeMapper(f: (name: string) => ConstructorOfATypedSvelteComponent): void;
|
|
3
|
+
import { type IDocumentRendererProps } from '../../index.js';
|
|
4
|
+
declare const ComponentRenderer: import("svelte").Component<IDocumentRendererProps, {}, "">;
|
|
5
|
+
type ComponentRenderer = ReturnType<typeof ComponentRenderer>;
|
|
6
|
+
export default ComponentRenderer;
|
package/dist/types/index.d.ts
CHANGED
|
@@ -822,4 +822,32 @@ export interface ActionButtonProps {
|
|
|
822
822
|
href?: string | null;
|
|
823
823
|
kind?: keyof typeof ACTION_BUTTON_KINDS;
|
|
824
824
|
moreShadow?: boolean;
|
|
825
|
+
onclick?: () => void;
|
|
826
|
+
}
|
|
827
|
+
export interface IComponentDescriptor {
|
|
828
|
+
type: string;
|
|
829
|
+
title?: string;
|
|
830
|
+
collapsible?: boolean;
|
|
831
|
+
collapsed?: boolean;
|
|
832
|
+
closable?: boolean;
|
|
833
|
+
props?: unknown;
|
|
834
|
+
id?: string;
|
|
835
|
+
}
|
|
836
|
+
export interface IDocumentCanvasClose {
|
|
837
|
+
id: string;
|
|
838
|
+
data: any;
|
|
839
|
+
}
|
|
840
|
+
export interface IDocumentRendererProps {
|
|
841
|
+
descriptor: IComponentDescriptor;
|
|
842
|
+
showTitle?: boolean;
|
|
843
|
+
contextKey?: object;
|
|
844
|
+
toggleCollapse: (id: string) => void;
|
|
845
|
+
close: (val: IDocumentCanvasClose) => void;
|
|
846
|
+
}
|
|
847
|
+
export interface IDocumentCanvasProps {
|
|
848
|
+
children: IComponentDescriptor[];
|
|
849
|
+
showBackground?: boolean;
|
|
850
|
+
contextKey?: object;
|
|
851
|
+
close: (val: IDocumentCanvasClose) => void;
|
|
852
|
+
toggleCollapse: (id: string) => void;
|
|
825
853
|
}
|
|
@@ -129,6 +129,7 @@
|
|
|
129
129
|
href = null,
|
|
130
130
|
kind = 'generic',
|
|
131
131
|
moreShadow = false,
|
|
132
|
+
onclick,
|
|
132
133
|
...rest
|
|
133
134
|
}: ActionButtonProps = $props();
|
|
134
135
|
|
|
@@ -149,6 +150,7 @@
|
|
|
149
150
|
</script>
|
|
150
151
|
|
|
151
152
|
<Button
|
|
153
|
+
onclick={() => onclick?.()}
|
|
152
154
|
color="alternative"
|
|
153
155
|
href={href || ''}
|
|
154
156
|
class={cn(
|
package/dist/utils/index.d.ts
CHANGED
|
@@ -6,3 +6,8 @@ export declare function cn(...inputs: ClassValue[]): string;
|
|
|
6
6
|
export declare function saveToLocalStorage<T>(key: string, data: T): void;
|
|
7
7
|
export declare function loadFromLocalStorage<T>(key: string): T | undefined;
|
|
8
8
|
export declare function extractQueryParam(queryString: string, index?: string): string;
|
|
9
|
+
export declare const send: (node: any, params: import("svelte/transition").CrossfadeParams & {
|
|
10
|
+
key: any;
|
|
11
|
+
}) => () => import("svelte/transition").TransitionConfig, receive: (node: any, params: import("svelte/transition").CrossfadeParams & {
|
|
12
|
+
key: any;
|
|
13
|
+
}) => () => import("svelte/transition").TransitionConfig;
|
package/dist/utils/index.js
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import { browser } from '$app/environment';
|
|
2
2
|
import clsx, {} from 'clsx';
|
|
3
|
+
import { quintOut } from 'svelte/easing';
|
|
4
|
+
import { crossfade } from 'svelte/transition';
|
|
3
5
|
import { twMerge } from 'tailwind-merge';
|
|
4
6
|
export { default as Popper } from './Popper.svelte';
|
|
5
7
|
export * from './closeButton/index.js';
|
|
@@ -33,3 +35,18 @@ export function extractQueryParam(queryString, index = 'q') {
|
|
|
33
35
|
const warehouse = urlParams.get(index);
|
|
34
36
|
return warehouse ?? '';
|
|
35
37
|
}
|
|
38
|
+
export const [send, receive] = crossfade({
|
|
39
|
+
duration: (d) => Math.sqrt(d * 200),
|
|
40
|
+
fallback(node, params) {
|
|
41
|
+
const style = getComputedStyle(node);
|
|
42
|
+
const transform = style.transform === 'none' ? '' : style.transform;
|
|
43
|
+
return {
|
|
44
|
+
duration: 600,
|
|
45
|
+
easing: quintOut,
|
|
46
|
+
css: (t) => `
|
|
47
|
+
transform: ${transform} translateX(${(1 - t) * 100}%);
|
|
48
|
+
opacity: ${t}
|
|
49
|
+
`
|
|
50
|
+
};
|
|
51
|
+
}
|
|
52
|
+
});
|