@krak-stack/assets 0.1.6 → 0.1.7
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/CHANGELOG.md +14 -0
- package/README.md +1 -1
- package/dist/components/asset-input/html.d.ts +4 -2
- package/dist/components/asset-input/html.js +301 -276
- package/dist/components/asset-input/index.d.ts +51 -0
- package/dist/components/asset-input/react.d.ts +1 -1
- package/dist/components/asset-input/react.js +61 -33
- package/dist/components/asset-input/schema.d.ts +15 -0
- package/dist/components/asset-table/html.js +903 -843
- package/dist/components/asset-table/index.d.ts +99 -0
- package/dist/components/asset-table/react.d.ts +3 -2
- package/dist/components/asset-table/react.js +191 -115
- package/dist/services/assets/library.d.ts +55 -0
- package/dist/services/assets/library.d.ts.map +1 -1
- package/dist/services/assets/library.js +37 -16
- package/dist/services/assets/library.js.map +1 -1
- package/package.json +2 -2
|
@@ -2,6 +2,57 @@ import { Redacted, Schema } from "effect";
|
|
|
2
2
|
import { Command, Component, UiSchema } from "effect/ui";
|
|
3
3
|
import { type AssetLibraryRuntime, type AssetStagedUpload } from "../../services/assets/library.js";
|
|
4
4
|
import { AssetUploadJobSchema, type AssetInputSharedProps, type AssetKind, type AssetUploadProps } from "./schema.js";
|
|
5
|
+
export declare const assetInputPickerOptions: {
|
|
6
|
+
readonly name: "AssetInputPicker";
|
|
7
|
+
readonly props: Schema.Struct<{
|
|
8
|
+
readonly assets: Schema.optionalKey<Schema.$Array<Schema.Struct<{
|
|
9
|
+
readonly id: Schema.String;
|
|
10
|
+
readonly name: Schema.String;
|
|
11
|
+
readonly mimeType: Schema.String;
|
|
12
|
+
readonly url: Schema.optionalKey<Schema.String>;
|
|
13
|
+
readonly updatedAt: Schema.optionalKey<Schema.Date>;
|
|
14
|
+
}>>>;
|
|
15
|
+
readonly access: Schema.optionalKey<Schema.Struct<{
|
|
16
|
+
readonly scopeKey: Schema.NonEmptyString;
|
|
17
|
+
readonly permissions: Schema.$Array<Schema.Literals<readonly ["list", "read", "create", "update", "delete"]>>;
|
|
18
|
+
}>>;
|
|
19
|
+
readonly value: Schema.optionalKey<Schema.Union<readonly [Schema.String, Schema.$Array<Schema.String>]>>;
|
|
20
|
+
}>;
|
|
21
|
+
readonly model: Schema.Null;
|
|
22
|
+
readonly message: Schema.Never;
|
|
23
|
+
readonly restore: false;
|
|
24
|
+
readonly queries: {
|
|
25
|
+
readonly library: {
|
|
26
|
+
query: typeof import("../../services/assets/library.js").AssetList;
|
|
27
|
+
dropPrevious: boolean;
|
|
28
|
+
args: ({ props }: {
|
|
29
|
+
props: {
|
|
30
|
+
readonly assets?: readonly {
|
|
31
|
+
readonly id: string;
|
|
32
|
+
readonly name: string;
|
|
33
|
+
readonly mimeType: string;
|
|
34
|
+
readonly url?: string | undefined;
|
|
35
|
+
readonly updatedAt?: Date | undefined;
|
|
36
|
+
}[] | undefined;
|
|
37
|
+
readonly access?: {
|
|
38
|
+
readonly scopeKey: string;
|
|
39
|
+
readonly permissions: readonly ("create" | "delete" | "list" | "read" | "update")[];
|
|
40
|
+
} | undefined;
|
|
41
|
+
readonly value?: string | readonly string[] | undefined;
|
|
42
|
+
};
|
|
43
|
+
}) => {
|
|
44
|
+
readonly search?: string | undefined;
|
|
45
|
+
readonly kind?: "caption" | "document" | "image" | "video" | undefined;
|
|
46
|
+
readonly scopeKey: string;
|
|
47
|
+
readonly showFiles: boolean;
|
|
48
|
+
} | undefined;
|
|
49
|
+
};
|
|
50
|
+
};
|
|
51
|
+
};
|
|
52
|
+
export declare const assetInputPickerBehaviours: {
|
|
53
|
+
init: () => null;
|
|
54
|
+
update: () => null;
|
|
55
|
+
};
|
|
5
56
|
export declare const assetInputMessages: (locale: string, messages?: AssetInputSharedProps["messages"]) => {
|
|
6
57
|
placeholder: string;
|
|
7
58
|
multiplePlaceholder: string;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { type ReactNode } from "react";
|
|
2
2
|
import { type AssetUploadOptions } from "./upload.js";
|
|
3
|
-
import type
|
|
3
|
+
import { type AssetLibraryRuntime } from "../../services/assets/library.js";
|
|
4
4
|
import type { AssetInputSharedProps } from "./schema.js";
|
|
5
5
|
export type { AssetPublication, AssetUploadOptions } from "./upload.js";
|
|
6
6
|
export type { AssetKind, AssetInputItem } from "./schema.js";
|
|
@@ -1,8 +1,11 @@
|
|
|
1
1
|
// ../assets/src/components/asset-input/react.tsx
|
|
2
2
|
import { FolderOpen, X as X4 } from "lucide-react";
|
|
3
|
+
import { AsyncResult as AsyncResult2 } from "effect/reactivity";
|
|
4
|
+
import { Component as Component7 } from "effect/ui";
|
|
3
5
|
import {
|
|
4
6
|
useId as useId3,
|
|
5
7
|
useLayoutEffect as useLayoutEffect2,
|
|
8
|
+
useMemo as useMemo2,
|
|
6
9
|
useRef as useRef3,
|
|
7
10
|
useState as useState4
|
|
8
11
|
} from "react";
|
|
@@ -1392,7 +1395,7 @@ import {
|
|
|
1392
1395
|
DialogTitle,
|
|
1393
1396
|
DialogTrigger
|
|
1394
1397
|
} from "@/components/ui/dialog";
|
|
1395
|
-
import {
|
|
1398
|
+
import { React } from "@krak-stack/registry/effect-ui-adapter/react";
|
|
1396
1399
|
|
|
1397
1400
|
// ../assets/src/components/asset-input/index.ts
|
|
1398
1401
|
import { Effect as Effect2, Queue, Redacted as Redacted2, Schema as Schema10, Stream } from "effect";
|
|
@@ -1401,6 +1404,7 @@ import { Command, Component as Component5, UiSchema as UiSchema5 } from "effect/
|
|
|
1401
1404
|
// ../assets/src/services/assets/library.ts
|
|
1402
1405
|
import {
|
|
1403
1406
|
Context,
|
|
1407
|
+
Effect,
|
|
1404
1408
|
Schema as Schema8
|
|
1405
1409
|
} from "effect";
|
|
1406
1410
|
import { AsyncResult } from "effect/reactivity";
|
|
@@ -1448,7 +1452,19 @@ class AssetList extends Query.Service()("@krak-stack/assets/AssetList", {
|
|
|
1448
1452
|
staleTime: "30 seconds"
|
|
1449
1453
|
}) {
|
|
1450
1454
|
}
|
|
1455
|
+
var disabledAssetListLayer = AssetList.toLayer(() => Effect.fail("unavailable"));
|
|
1451
1456
|
var assetListArgs = (scopeKey, permissions, query = {}) => permissions.includes("list") ? { ...query, scopeKey, showFiles: permissions.includes("read") } : undefined;
|
|
1457
|
+
var assetLibraryQuery = (getAccess) => ({
|
|
1458
|
+
query: AssetList,
|
|
1459
|
+
dropPrevious: true,
|
|
1460
|
+
args: ({ props }) => {
|
|
1461
|
+
const access = getAccess(props);
|
|
1462
|
+
return access && assetListArgs(access.scopeKey, access.permissions);
|
|
1463
|
+
}
|
|
1464
|
+
});
|
|
1465
|
+
var AssetLibraryPropsSchema = Schema8.Struct({
|
|
1466
|
+
access: AssetLibraryAccessSchema
|
|
1467
|
+
}).annotate({ identifier: "AssetLibraryModelProps" });
|
|
1452
1468
|
var AssetLibrarySnapshot = Schema8.Struct({
|
|
1453
1469
|
data: Schema8.NullOr(AssetListSchema),
|
|
1454
1470
|
status: Schema8.Literals(["idle", "loading", "ready", "failed"])
|
|
@@ -1457,25 +1473,29 @@ var AssetLibraryMessage = UiSchema4.TaggedEnum({
|
|
|
1457
1473
|
LibraryChanged: { library: AssetLibrarySnapshot }
|
|
1458
1474
|
}).annotate({ identifier: "AssetLibraryMessage" });
|
|
1459
1475
|
var emptyAssetLibrary = { data: null, status: "idle" };
|
|
1460
|
-
var
|
|
1461
|
-
|
|
1462
|
-
|
|
1463
|
-
|
|
1476
|
+
var assetLibrarySnapshot = (result) => AsyncResult.isSuccess(result) ? { data: result.value, status: "ready" } : {
|
|
1477
|
+
data: null,
|
|
1478
|
+
status: AsyncResult.isFailure(result) ? "failed" : "loading"
|
|
1479
|
+
};
|
|
1480
|
+
var libraryQuery = (result) => AssetLibraryMessage.LibraryChanged({ library: assetLibrarySnapshot(result) });
|
|
1481
|
+
var assetLibraryOptions = {
|
|
1482
|
+
name: "AssetLibraryView",
|
|
1483
|
+
props: AssetLibraryPropsSchema,
|
|
1484
|
+
model: Schema8.Null,
|
|
1485
|
+
message: Schema8.Never,
|
|
1486
|
+
restore: false,
|
|
1487
|
+
queries: {
|
|
1488
|
+
library: assetLibraryQuery((props) => props.access)
|
|
1464
1489
|
}
|
|
1465
|
-
}
|
|
1490
|
+
};
|
|
1466
1491
|
var options = {
|
|
1492
|
+
...assetLibraryOptions,
|
|
1467
1493
|
name: "AssetLibraryModel",
|
|
1468
|
-
props: Schema8.Struct({ access: AssetLibraryAccessSchema }).annotate({
|
|
1469
|
-
identifier: "AssetLibraryModelProps"
|
|
1470
|
-
}),
|
|
1471
1494
|
model: AssetLibrarySnapshot,
|
|
1472
1495
|
message: AssetLibraryMessage,
|
|
1473
|
-
restore: false,
|
|
1474
1496
|
queries: {
|
|
1475
1497
|
library: {
|
|
1476
|
-
|
|
1477
|
-
dropPrevious: true,
|
|
1478
|
-
args: ({ props }) => assetListArgs(props.access.scopeKey, props.access.permissions),
|
|
1498
|
+
...assetLibraryOptions.queries.library,
|
|
1479
1499
|
onChange: libraryQuery
|
|
1480
1500
|
}
|
|
1481
1501
|
}
|
|
@@ -1554,6 +1574,7 @@ var AssetInputPropsSchema = Schema9.Struct({
|
|
|
1554
1574
|
}))),
|
|
1555
1575
|
uploader: Schema9.optionalKey(AssetUploadPropsSchema)
|
|
1556
1576
|
}).annotate({ identifier: "AssetInputProps" });
|
|
1577
|
+
var AssetInputPickerPropsSchema = AssetInputPropsSchema.mapFields(({ assets, access, value }) => ({ assets, access, value })).annotate({ identifier: "AssetInputPickerProps" });
|
|
1557
1578
|
var AssetUploadJobSchema = Schema9.Struct({
|
|
1558
1579
|
id: Schema9.Int,
|
|
1559
1580
|
file: Schema9.Redacted(Schema9.File),
|
|
@@ -1570,6 +1591,20 @@ var AssetUploadJobSchema = Schema9.Struct({
|
|
|
1570
1591
|
}).annotate({ identifier: "AssetUploadJob" });
|
|
1571
1592
|
|
|
1572
1593
|
// ../assets/src/components/asset-input/index.ts
|
|
1594
|
+
var assetInputPickerOptions = {
|
|
1595
|
+
name: "AssetInputPicker",
|
|
1596
|
+
props: AssetInputPickerPropsSchema,
|
|
1597
|
+
model: Schema10.Null,
|
|
1598
|
+
message: Schema10.Never,
|
|
1599
|
+
restore: false,
|
|
1600
|
+
queries: {
|
|
1601
|
+
library: assetLibraryQuery((props) => props.assets === undefined && props.value !== undefined ? props.access : undefined)
|
|
1602
|
+
}
|
|
1603
|
+
};
|
|
1604
|
+
var assetInputPickerBehaviours = {
|
|
1605
|
+
init: () => null,
|
|
1606
|
+
update: () => null
|
|
1607
|
+
};
|
|
1573
1608
|
var inputCopy = {
|
|
1574
1609
|
en: {
|
|
1575
1610
|
placeholder: "Choose asset",
|
|
@@ -1885,7 +1920,7 @@ var UploadSession = ({
|
|
|
1885
1920
|
const {
|
|
1886
1921
|
model: { files, jobs, open },
|
|
1887
1922
|
send
|
|
1888
|
-
} =
|
|
1923
|
+
} = React.useView(binding.component, {
|
|
1889
1924
|
label: title,
|
|
1890
1925
|
multiple,
|
|
1891
1926
|
...kind === undefined ? {} : { kind },
|
|
@@ -2054,26 +2089,12 @@ var assetImage = (asset) => {
|
|
|
2054
2089
|
return { imageSrc };
|
|
2055
2090
|
};
|
|
2056
2091
|
|
|
2057
|
-
// ../assets/src/services/assets/use-library.ts
|
|
2058
|
-
import { useMemo as useMemo2 } from "react";
|
|
2059
|
-
import { Effect as Effect3 } from "effect";
|
|
2060
|
-
import { Component as Component7 } from "effect/ui";
|
|
2061
|
-
import { useModel as useModel2 } from "@krak-stack/registry/effect-ui-adapter/react";
|
|
2062
|
-
var disabled = AssetLibraryModel.pipe(Component7.provide(AssetList.toLayer(() => Effect3.fail("unavailable"))));
|
|
2063
|
-
var noAccess = { scopeKey: "disabled", permissions: [] };
|
|
2064
|
-
var useAssetLibrary = (runtime, access) => {
|
|
2065
|
-
const scopeKey = access?.permissions.includes("list") ? access.scopeKey : undefined;
|
|
2066
|
-
const showFiles = access?.permissions.includes("read") ?? false;
|
|
2067
|
-
const model = useMemo2(() => runtime && scopeKey ? AssetLibraryModel.pipe(Component7.provide(runtime.layer)) : disabled, [runtime, scopeKey, showFiles]);
|
|
2068
|
-
const { model: snapshot } = useModel2(model, {
|
|
2069
|
-
access: runtime && scopeKey && access ? access : noAccess
|
|
2070
|
-
});
|
|
2071
|
-
return runtime && scopeKey ? snapshot : emptyAssetLibrary;
|
|
2072
|
-
};
|
|
2073
|
-
|
|
2074
2092
|
// ../assets/src/components/asset-input/react.tsx
|
|
2093
|
+
import { React as React2 } from "@krak-stack/registry/effect-ui-adapter/react";
|
|
2075
2094
|
import { jsx as jsx5, jsxs as jsxs5 } from "react/jsx-runtime";
|
|
2076
2095
|
"use client";
|
|
2096
|
+
var pickerModel = React2.component(assetInputPickerOptions).make(assetInputPickerBehaviours);
|
|
2097
|
+
var disabledPickerModel = pickerModel.pipe(Component7.provide(disabledAssetListLayer));
|
|
2077
2098
|
var AssetInput = (props) => /* @__PURE__ */ jsx5(AssetInputView, {
|
|
2078
2099
|
...props
|
|
2079
2100
|
}, props.access?.scopeKey);
|
|
@@ -2092,8 +2113,15 @@ var AssetInputView = (props) => {
|
|
|
2092
2113
|
uploadTrigger
|
|
2093
2114
|
} = props;
|
|
2094
2115
|
const { runtime, access, replaceId } = props;
|
|
2095
|
-
const
|
|
2096
|
-
const
|
|
2116
|
+
const listAccess = runtime && suppliedAssets === undefined && onChange && access?.permissions.includes("list") ? access : undefined;
|
|
2117
|
+
const listRuntime = listAccess ? runtime : undefined;
|
|
2118
|
+
const showFiles = listAccess?.permissions.includes("read");
|
|
2119
|
+
const component = useMemo2(() => listRuntime ? pickerModel.pipe(Component7.provide(listRuntime.layer)) : disabledPickerModel, [listRuntime, showFiles]);
|
|
2120
|
+
const { queries } = React2.useView(component, {
|
|
2121
|
+
...listAccess && props.value !== undefined ? { access: listAccess, value: props.value } : {}
|
|
2122
|
+
});
|
|
2123
|
+
const result = queries?.library ?? AsyncResult2.initial();
|
|
2124
|
+
const assets = suppliedAssets ?? (listAccess ? AsyncResult2.isSuccess(result) ? result.value.items : [] : undefined);
|
|
2097
2125
|
const id = useId3();
|
|
2098
2126
|
const [published, setPublished] = useState4([]);
|
|
2099
2127
|
const pendingIds = useRef3([]);
|
|
@@ -83,6 +83,21 @@ export declare const AssetInputPropsSchema: Schema.Struct<{
|
|
|
83
83
|
}>>;
|
|
84
84
|
}>;
|
|
85
85
|
export type AssetInputSharedProps = typeof AssetInputPropsSchema.Type;
|
|
86
|
+
export declare const AssetInputPickerPropsSchema: Schema.Struct<{
|
|
87
|
+
readonly assets: Schema.optionalKey<Schema.$Array<Schema.Struct<{
|
|
88
|
+
readonly id: Schema.String;
|
|
89
|
+
readonly name: Schema.String;
|
|
90
|
+
readonly mimeType: Schema.String;
|
|
91
|
+
readonly url: Schema.optionalKey<Schema.String>;
|
|
92
|
+
readonly updatedAt: Schema.optionalKey<Schema.Date>;
|
|
93
|
+
}>>>;
|
|
94
|
+
readonly access: Schema.optionalKey<Schema.Struct<{
|
|
95
|
+
readonly scopeKey: Schema.NonEmptyString;
|
|
96
|
+
readonly permissions: Schema.$Array<Schema.Literals<readonly ["list", "read", "create", "update", "delete"]>>;
|
|
97
|
+
}>>;
|
|
98
|
+
readonly value: Schema.optionalKey<Schema.Union<readonly [Schema.String, Schema.$Array<Schema.String>]>>;
|
|
99
|
+
}>;
|
|
100
|
+
export type AssetInputPickerProps = typeof AssetInputPickerPropsSchema.Type;
|
|
86
101
|
export declare const AssetUploadJobSchema: Schema.Struct<{
|
|
87
102
|
readonly id: Schema.Int;
|
|
88
103
|
readonly file: Schema.Redacted<Schema.File>;
|