@aglyn/plugins-data 1.0.0-beta.143
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/LICENSE +201 -0
- package/README.md +7 -0
- package/package.json +47 -0
- package/src/index.d.ts +19 -0
- package/src/index.js +20 -0
- package/src/index.js.map +1 -0
- package/src/lib/components/data-console-page.d.ts +13 -0
- package/src/lib/components/data-console-page.js +63 -0
- package/src/lib/components/data-console-page.js.map +1 -0
- package/src/lib/components/dataset-record-dialog.component.d.ts +52 -0
- package/src/lib/components/dataset-record-dialog.component.js +249 -0
- package/src/lib/components/dataset-record-dialog.component.js.map +1 -0
- package/src/lib/components/dataset-schema-dialog.component.d.ts +51 -0
- package/src/lib/components/dataset-schema-dialog.component.js +979 -0
- package/src/lib/components/dataset-schema-dialog.component.js.map +1 -0
- package/src/lib/components/host-datasets-card.component.d.ts +39 -0
- package/src/lib/components/host-datasets-card.component.js +1831 -0
- package/src/lib/components/host-datasets-card.component.js.map +1 -0
- package/src/lib/constants/bundle-common.d.ts +8 -0
- package/src/lib/constants/bundle-common.js +9 -0
- package/src/lib/constants/bundle-common.js.map +1 -0
- package/src/lib/model/dataset-io.d.ts +43 -0
- package/src/lib/model/dataset-io.js +84 -0
- package/src/lib/model/dataset-io.js.map +1 -0
- package/src/lib/model/dataset-record-view.d.ts +157 -0
- package/src/lib/model/dataset-record-view.js +293 -0
- package/src/lib/model/dataset-record-view.js.map +1 -0
- package/src/lib/model/index.d.ts +22 -0
- package/src/lib/model/index.js +22 -0
- package/src/lib/model/index.js.map +1 -0
- package/src/lib/plugin.d.ts +35 -0
- package/src/lib/plugin.js +78 -0
- package/src/lib/plugin.js.map +1 -0
- package/src/lib/repeat/dataset-repeat-rows.d.ts +45 -0
- package/src/lib/repeat/dataset-repeat-rows.js +108 -0
- package/src/lib/repeat/dataset-repeat-rows.js.map +1 -0
- package/src/lib/repeat/dataset-repeat-source.d.ts +39 -0
- package/src/lib/repeat/dataset-repeat-source.js +95 -0
- package/src/lib/repeat/dataset-repeat-source.js.map +1 -0
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* Copyright 2026 Aglyn LLC
|
|
4
|
+
*
|
|
5
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
6
|
+
* you may not use this file except in compliance with the License.
|
|
7
|
+
* You may obtain a copy of the License at
|
|
8
|
+
*
|
|
9
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
10
|
+
*
|
|
11
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
12
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
13
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
14
|
+
* See the License for the specific language governing permissions and
|
|
15
|
+
* limitations under the License.
|
|
16
|
+
*/ import { datasetDisplayName, effectiveDatasetModel, REPEAT_MAX_RECORDS, scopeTokensForHost, visibleToHost } from "@aglyn/aglyn";
|
|
17
|
+
import { repeatRecordsFromPages } from "@aglyn/tenant-runtime/repeat-record-pages";
|
|
18
|
+
import { collection, doc, documentId, getDoc, getDocs, limit, orderBy, query, where } from "firebase/firestore";
|
|
19
|
+
/**
|
|
20
|
+
* A dataset's rows for the besigner's canvas preview, read the way the
|
|
21
|
+
* published page's composition reads them (`getDatasets` in the tenant
|
|
22
|
+
* runtime), with the client SDK instead of the Admin one (AGL-3111).
|
|
23
|
+
*
|
|
24
|
+
* - The key resolves as the page resolves it: an id first, then a display
|
|
25
|
+
* name within what this site may see. An id that exists but that this site
|
|
26
|
+
* cannot see does not fall through to the name — that would answer "which
|
|
27
|
+
* dataset is called X" for a key that already named a specific one.
|
|
28
|
+
* - A dataset shared with other sites but not this one, or deleted, answers
|
|
29
|
+
* `missing`: the page renders the element once, as written.
|
|
30
|
+
* - The rows are the two bounded reads and the one ordering rule the page
|
|
31
|
+
* uses, {@link repeatRecordsFromPages}, so a canvas copy is a row the page
|
|
32
|
+
* renders.
|
|
33
|
+
* - One reference hop (AGL-180) is loaded as the page loads it, so
|
|
34
|
+
* `{{item.author.name}}` previews too.
|
|
35
|
+
*/ export async function readDatasetRepeatRows(request) {
|
|
36
|
+
var _ref;
|
|
37
|
+
var _rows_model;
|
|
38
|
+
const { firestore, scope, hostId } = request;
|
|
39
|
+
const key = request.key.trim();
|
|
40
|
+
if (!key) return {
|
|
41
|
+
status: 'missing'
|
|
42
|
+
};
|
|
43
|
+
const datasets = collection(firestore, scope[0], scope[1], 'datasets');
|
|
44
|
+
const usable = (snapshot)=>Boolean(snapshot == null ? void 0 : snapshot.exists()) && !(snapshot == null ? void 0 : snapshot.get('deletedAt')) && visibleToHost(snapshot == null ? void 0 : snapshot.get('visibleTo'), hostId);
|
|
45
|
+
let dataset;
|
|
46
|
+
let resolvedById = false;
|
|
47
|
+
if (!key.includes('/')) {
|
|
48
|
+
const byId = await getDoc(doc(datasets, key));
|
|
49
|
+
if (byId.exists()) {
|
|
50
|
+
resolvedById = true;
|
|
51
|
+
dataset = usable(byId) ? byId : undefined;
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
if (!resolvedById) {
|
|
55
|
+
const byName = await getDocs(query(datasets, where('visibleTo', 'array-contains-any', scopeTokensForHost(hostId)), where('displayName', '==', key), limit(1)));
|
|
56
|
+
dataset = byName.docs.find((snapshot)=>usable(snapshot));
|
|
57
|
+
}
|
|
58
|
+
if (!dataset) return {
|
|
59
|
+
status: 'missing'
|
|
60
|
+
};
|
|
61
|
+
const load = async (snapshot)=>({
|
|
62
|
+
records: await readRepeatRows(snapshot.ref),
|
|
63
|
+
model: effectiveDatasetModel(snapshot.data())
|
|
64
|
+
});
|
|
65
|
+
const rows = await load(dataset);
|
|
66
|
+
const rowsByKey = {
|
|
67
|
+
[key]: rows,
|
|
68
|
+
[dataset.id]: rows
|
|
69
|
+
};
|
|
70
|
+
const targets = new Set();
|
|
71
|
+
for (const fieldId of (_ref = (_rows_model = rows.model) == null ? void 0 : _rows_model.order) != null ? _ref : []){
|
|
72
|
+
var _rows_model1, _field_reference;
|
|
73
|
+
const field = (_rows_model1 = rows.model) == null ? void 0 : _rows_model1.fields[fieldId];
|
|
74
|
+
const targetId = (field == null ? void 0 : field.type) === 'reference' ? (_field_reference = field.reference) == null ? void 0 : _field_reference.datasetId : undefined;
|
|
75
|
+
if (targetId && !targetId.includes('/') && !rowsByKey[targetId]) {
|
|
76
|
+
targets.add(targetId);
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
await Promise.all([
|
|
80
|
+
...targets
|
|
81
|
+
].map(async (targetId)=>{
|
|
82
|
+
// Per target, like the page: a hop that cannot be read leaves its
|
|
83
|
+
// tokens literal without costing the rows it hangs off.
|
|
84
|
+
try {
|
|
85
|
+
const target = await getDoc(doc(datasets, targetId));
|
|
86
|
+
if (usable(target)) rowsByKey[targetId] = await load(target);
|
|
87
|
+
} catch (error) {
|
|
88
|
+
console.error(error);
|
|
89
|
+
}
|
|
90
|
+
}));
|
|
91
|
+
return {
|
|
92
|
+
status: 'ready',
|
|
93
|
+
label: datasetDisplayName(dataset.data()) || key,
|
|
94
|
+
rowsByKey
|
|
95
|
+
};
|
|
96
|
+
}
|
|
97
|
+
/** Both bounded reads, the second only when the first came back short. */ async function readRepeatRows(datasetRef) {
|
|
98
|
+
const records = collection(datasetRef, 'records');
|
|
99
|
+
const page = (snapshot)=>snapshot.docs.map((record)=>({
|
|
100
|
+
id: record.id,
|
|
101
|
+
data: record.data()
|
|
102
|
+
}));
|
|
103
|
+
const byOrder = await getDocs(query(records, orderBy('order'), limit(REPEAT_MAX_RECORDS)));
|
|
104
|
+
const byId = byOrder.docs.length < REPEAT_MAX_RECORDS ? await getDocs(query(records, orderBy(documentId()), limit(REPEAT_MAX_RECORDS))) : undefined;
|
|
105
|
+
return repeatRecordsFromPages(page(byOrder), byId ? page(byId) : []);
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
//# sourceMappingURL=dataset-repeat-rows.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../../../../libs/plugins/data/src/lib/repeat/dataset-repeat-rows.ts"],"sourcesContent":["/**\n * @license\n * Copyright 2026 Aglyn LLC\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport {\n datasetDisplayName,\n effectiveDatasetModel,\n type HostDataset,\n type HostDatasetRecord,\n REPEAT_MAX_RECORDS,\n type RepeatableDataset,\n scopeTokensForHost,\n visibleToHost,\n} from '@aglyn/aglyn'\nimport type { RepeatRowsAnswer } from '@aglyn/aglyn/app-utils/repeat-sources'\nimport { repeatRecordsFromPages } from '@aglyn/tenant-runtime/repeat-record-pages'\nimport {\n collection,\n doc,\n type DocumentReference,\n type DocumentSnapshot,\n documentId,\n type Firestore,\n getDoc,\n getDocs,\n limit,\n orderBy,\n query,\n type QuerySnapshot,\n where,\n} from 'firebase/firestore'\n\nexport interface DatasetRepeatRowsRequest {\n firestore: Firestore\n /** `['orgs', orgId]` — where the site's organization keeps its datasets. */\n scope: readonly [string, string]\n /** The site the canvas edits. */\n hostId: string\n /** The dataset key exactly as the node stores it: an id or a display name. */\n key: string\n}\n\n/**\n * A dataset's rows for the besigner's canvas preview, read the way the\n * published page's composition reads them (`getDatasets` in the tenant\n * runtime), with the client SDK instead of the Admin one (AGL-3111).\n *\n * - The key resolves as the page resolves it: an id first, then a display\n * name within what this site may see. An id that exists but that this site\n * cannot see does not fall through to the name — that would answer \"which\n * dataset is called X\" for a key that already named a specific one.\n * - A dataset shared with other sites but not this one, or deleted, answers\n * `missing`: the page renders the element once, as written.\n * - The rows are the two bounded reads and the one ordering rule the page\n * uses, {@link repeatRecordsFromPages}, so a canvas copy is a row the page\n * renders.\n * - One reference hop (AGL-180) is loaded as the page loads it, so\n * `{{item.author.name}}` previews too.\n */\nexport async function readDatasetRepeatRows(\n request: DatasetRepeatRowsRequest,\n): Promise<RepeatRowsAnswer> {\n const { firestore, scope, hostId } = request\n const key = request.key.trim()\n if (!key) return { status: 'missing' }\n const datasets = collection(firestore, scope[0], scope[1], 'datasets')\n const usable = (snapshot: DocumentSnapshot | undefined) =>\n Boolean(snapshot?.exists()) &&\n !snapshot?.get('deletedAt') &&\n visibleToHost(snapshot?.get('visibleTo'), hostId)\n\n let dataset: DocumentSnapshot | undefined\n let resolvedById = false\n if (!key.includes('/')) {\n const byId = await getDoc(doc(datasets, key))\n if (byId.exists()) {\n resolvedById = true\n dataset = usable(byId) ? byId : undefined\n }\n }\n if (!resolvedById) {\n const byName = await getDocs(\n query(\n datasets,\n where('visibleTo', 'array-contains-any', scopeTokensForHost(hostId)),\n where('displayName', '==', key),\n limit(1),\n ),\n )\n dataset = byName.docs.find((snapshot) => usable(snapshot))\n }\n if (!dataset) return { status: 'missing' }\n\n const load = async (snapshot: DocumentSnapshot): Promise<RepeatableDataset> => ({\n records: await readRepeatRows(snapshot.ref),\n model: effectiveDatasetModel(snapshot.data() as HostDataset),\n })\n const rows = await load(dataset)\n const rowsByKey: Record<string, RepeatableDataset> = {\n [key]: rows,\n [dataset.id]: rows,\n }\n\n const targets = new Set<string>()\n for (const fieldId of rows.model?.order ?? []) {\n const field = rows.model?.fields[fieldId]\n const targetId =\n field?.type === 'reference' ? field.reference?.datasetId : undefined\n if (targetId && !targetId.includes('/') && !rowsByKey[targetId]) {\n targets.add(targetId)\n }\n }\n await Promise.all(\n [...targets].map(async (targetId) => {\n // Per target, like the page: a hop that cannot be read leaves its\n // tokens literal without costing the rows it hangs off.\n try {\n const target = await getDoc(doc(datasets, targetId))\n if (usable(target)) rowsByKey[targetId] = await load(target)\n } catch (error) {\n console.error(error)\n }\n }),\n )\n\n return {\n status: 'ready',\n label: datasetDisplayName(dataset.data() as HostDataset) || key,\n rowsByKey,\n }\n}\n\n/** Both bounded reads, the second only when the first came back short. */\nasync function readRepeatRows(\n datasetRef: DocumentReference,\n): Promise<Array<Record<string, unknown>>> {\n const records = collection(datasetRef, 'records')\n const page = (snapshot: QuerySnapshot) =>\n snapshot.docs.map((record) => ({\n id: record.id,\n data: record.data() as HostDatasetRecord,\n }))\n const byOrder = await getDocs(\n query(records, orderBy('order'), limit(REPEAT_MAX_RECORDS)),\n )\n const byId =\n byOrder.docs.length < REPEAT_MAX_RECORDS\n ? await getDocs(\n query(records, orderBy(documentId()), limit(REPEAT_MAX_RECORDS)),\n )\n : undefined\n return repeatRecordsFromPages(page(byOrder), byId ? page(byId) : [])\n}\n"],"names":["datasetDisplayName","effectiveDatasetModel","REPEAT_MAX_RECORDS","scopeTokensForHost","visibleToHost","repeatRecordsFromPages","collection","doc","documentId","getDoc","getDocs","limit","orderBy","query","where","readDatasetRepeatRows","request","rows","firestore","scope","hostId","key","trim","status","datasets","usable","snapshot","Boolean","exists","get","dataset","resolvedById","includes","byId","undefined","byName","docs","find","load","records","readRepeatRows","ref","model","data","rowsByKey","id","targets","Set","fieldId","order","field","fields","targetId","type","reference","datasetId","add","Promise","all","map","target","error","console","label","datasetRef","page","record","byOrder","length"],"mappings":"AAAA;;;;;;;;;;;;;;;CAeC,GAED,SACEA,kBAAkB,EAClBC,qBAAqB,EAGrBC,kBAAkB,EAElBC,kBAAkB,EAClBC,aAAa,QACR,eAAc;AAErB,SAASC,sBAAsB,QAAQ,4CAA2C;AAClF,SACEC,UAAU,EACVC,GAAG,EAGHC,UAAU,EAEVC,MAAM,EACNC,OAAO,EACPC,KAAK,EACLC,OAAO,EACPC,KAAK,EAELC,KAAK,QACA,qBAAoB;AAY3B;;;;;;;;;;;;;;;;CAgBC,GACD,OAAO,eAAeC,sBACpBC,OAAiC;;QA4CXC;IA1CtB,MAAM,EAAEC,SAAS,EAAEC,KAA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C,KAAKhC,QAAQ,EAAE;AACrE"}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* Copyright 2026 Aglyn LLC
|
|
4
|
+
*
|
|
5
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
6
|
+
* you may not use this file except in compliance with the License.
|
|
7
|
+
* You may obtain a copy of the License at
|
|
8
|
+
*
|
|
9
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
10
|
+
*
|
|
11
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
12
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
13
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
14
|
+
* See the License for the specific language governing permissions and
|
|
15
|
+
* limitations under the License.
|
|
16
|
+
*/
|
|
17
|
+
import type { RepeatRowsAnswer, RepeatRowsRequest, RepeatSource } from '@aglyn/aglyn/app-utils/repeat-sources';
|
|
18
|
+
/**
|
|
19
|
+
* The prop a repeat's dataset persists under (AGL-103). The published page's
|
|
20
|
+
* composition expands every node that carries it, whatever its component, so
|
|
21
|
+
* the Stack's stored repeats and any element's read as one shape. Persisted —
|
|
22
|
+
* never rename.
|
|
23
|
+
*/
|
|
24
|
+
export declare const DATASET_REPEAT_KEY_PROP = "repeatDataset";
|
|
25
|
+
/**
|
|
26
|
+
* A dataset's rows for the canvas, read once per key and site while a canvas
|
|
27
|
+
* element repeats over it.
|
|
28
|
+
*
|
|
29
|
+
* `missing` for a site with no organization: datasets belong to the
|
|
30
|
+
* organization, so there is nothing such a site can repeat over.
|
|
31
|
+
*/
|
|
32
|
+
export declare function useDatasetRepeatRows(request: RepeatRowsRequest): RepeatRowsAnswer;
|
|
33
|
+
/**
|
|
34
|
+
* Datasets as a repeat source (AGL-3111): what any element can repeat over,
|
|
35
|
+
* picked with the dataset picker and previewed on the canvas from the real
|
|
36
|
+
* rows. Registered by {@link registerDataConsole}, the function the console's
|
|
37
|
+
* plugin loader calls by name.
|
|
38
|
+
*/
|
|
39
|
+
export declare const DATASET_REPEAT_SOURCE: RepeatSource;
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* Copyright 2026 Aglyn LLC
|
|
4
|
+
*
|
|
5
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
6
|
+
* you may not use this file except in compliance with the License.
|
|
7
|
+
* You may obtain a copy of the License at
|
|
8
|
+
*
|
|
9
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
10
|
+
*
|
|
11
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
12
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
13
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
14
|
+
* See the License for the specific language governing permissions and
|
|
15
|
+
* limitations under the License.
|
|
16
|
+
*/ import { FieldComponentType } from "@aglyn/aglyn";
|
|
17
|
+
import { useFirestore, useOrgDataScope } from "@aglyn/tenant-feature-instance";
|
|
18
|
+
import { useEffect, useState } from "react";
|
|
19
|
+
import { readDatasetRepeatRows } from "./dataset-repeat-rows.js";
|
|
20
|
+
/**
|
|
21
|
+
* The prop a repeat's dataset persists under (AGL-103). The published page's
|
|
22
|
+
* composition expands every node that carries it, whatever its component, so
|
|
23
|
+
* the Stack's stored repeats and any element's read as one shape. Persisted —
|
|
24
|
+
* never rename.
|
|
25
|
+
*/ export const DATASET_REPEAT_KEY_PROP = 'repeatDataset';
|
|
26
|
+
/**
|
|
27
|
+
* A dataset's rows for the canvas, read once per key and site while a canvas
|
|
28
|
+
* element repeats over it.
|
|
29
|
+
*
|
|
30
|
+
* `missing` for a site with no organization: datasets belong to the
|
|
31
|
+
* organization, so there is nothing such a site can repeat over.
|
|
32
|
+
*/ export function useDatasetRepeatRows(request) {
|
|
33
|
+
const { hostId, key } = request;
|
|
34
|
+
const firestore = useFirestore();
|
|
35
|
+
const { scope, ready } = useOrgDataScope({
|
|
36
|
+
hostId
|
|
37
|
+
});
|
|
38
|
+
const [answer, setAnswer] = useState({
|
|
39
|
+
status: 'loading'
|
|
40
|
+
});
|
|
41
|
+
useEffect(()=>{
|
|
42
|
+
if (!ready) return undefined;
|
|
43
|
+
if (!scope) {
|
|
44
|
+
setAnswer({
|
|
45
|
+
status: 'missing'
|
|
46
|
+
});
|
|
47
|
+
return undefined;
|
|
48
|
+
}
|
|
49
|
+
let active = true;
|
|
50
|
+
setAnswer({
|
|
51
|
+
status: 'loading'
|
|
52
|
+
});
|
|
53
|
+
readDatasetRepeatRows({
|
|
54
|
+
firestore,
|
|
55
|
+
scope,
|
|
56
|
+
hostId,
|
|
57
|
+
key
|
|
58
|
+
}).then((next)=>{
|
|
59
|
+
if (active) setAnswer(next);
|
|
60
|
+
}, (error)=>{
|
|
61
|
+
console.error(error);
|
|
62
|
+
if (active) setAnswer({
|
|
63
|
+
status: 'error'
|
|
64
|
+
});
|
|
65
|
+
});
|
|
66
|
+
return ()=>{
|
|
67
|
+
active = false;
|
|
68
|
+
};
|
|
69
|
+
}, [
|
|
70
|
+
firestore,
|
|
71
|
+
scope,
|
|
72
|
+
ready,
|
|
73
|
+
hostId,
|
|
74
|
+
key
|
|
75
|
+
]);
|
|
76
|
+
return answer;
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* Datasets as a repeat source (AGL-3111): what any element can repeat over,
|
|
80
|
+
* picked with the dataset picker and previewed on the canvas from the real
|
|
81
|
+
* rows. Registered by {@link registerDataConsole}, the function the console's
|
|
82
|
+
* plugin loader calls by name.
|
|
83
|
+
*/ export const DATASET_REPEAT_SOURCE = {
|
|
84
|
+
id: 'dataset',
|
|
85
|
+
label: 'Dataset',
|
|
86
|
+
keyProp: DATASET_REPEAT_KEY_PROP,
|
|
87
|
+
keyAttribute: {
|
|
88
|
+
component: FieldComponentType.DATASET_SELECT,
|
|
89
|
+
label: 'Repeat over dataset',
|
|
90
|
+
description: 'Render this element once per record of a dataset on the published ' + 'site. Use {{item.field}} for a record value. Stored by dataset id — ' + 'renames never break the repeat.'
|
|
91
|
+
},
|
|
92
|
+
useRows: useDatasetRepeatRows
|
|
93
|
+
};
|
|
94
|
+
|
|
95
|
+
//# sourceMappingURL=dataset-repeat-source.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../../../../libs/plugins/data/src/lib/repeat/dataset-repeat-source.ts"],"sourcesContent":["/**\n * @license\n * Copyright 2026 Aglyn LLC\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { FieldComponentType } from '@aglyn/aglyn'\nimport type {\n RepeatRowsAnswer,\n RepeatRowsRequest,\n RepeatSource,\n} from '@aglyn/aglyn/app-utils/repeat-sources'\nimport { useFirestore, useOrgDataScope } from '@aglyn/tenant-feature-instance'\nimport { useEffect, useState } from 'react'\nimport { readDatasetRepeatRows } from './dataset-repeat-rows'\n\n/**\n * The prop a repeat's dataset persists under (AGL-103). The published page's\n * composition expands every node that carries it, whatever its component, so\n * the Stack's stored repeats and any element's read as one shape. Persisted —\n * never rename.\n */\nexport const DATASET_REPEAT_KEY_PROP = 'repeatDataset'\n\n/**\n * A dataset's rows for the canvas, read once per key and site while a canvas\n * element repeats over it.\n *\n * `missing` for a site with no organization: datasets belong to the\n * organization, so there is nothing such a site can repeat over.\n */\nexport function useDatasetRepeatRows(\n request: RepeatRowsRequest,\n): RepeatRowsAnswer {\n const { hostId, key } = request\n const firestore = useFirestore()\n const { scope, ready } = useOrgDataScope({ hostId })\n const [answer, setAnswer] = useState<RepeatRowsAnswer>({ status: 'loading' })\n useEffect(() => {\n if (!ready) return undefined\n if (!scope) {\n setAnswer({ status: 'missing' })\n return undefined\n }\n let active = true\n setAnswer({ status: 'loading' })\n readDatasetRepeatRows({ firestore, scope, hostId, key }).then(\n (next) => {\n if (active) setAnswer(next)\n },\n (error) => {\n console.error(error)\n if (active) setAnswer({ status: 'error' })\n },\n )\n return () => {\n active = false\n }\n }, [firestore, scope, ready, hostId, key])\n return answer\n}\n\n/**\n * Datasets as a repeat source (AGL-3111): what any element can repeat over,\n * picked with the dataset picker and previewed on the canvas from the real\n * rows. Registered by {@link registerDataConsole}, the function the console's\n * plugin loader calls by name.\n */\nexport const DATASET_REPEAT_SOURCE: RepeatSource = {\n id: 'dataset',\n label: 'Dataset',\n keyProp: DATASET_REPEAT_KEY_PROP,\n keyAttribute: {\n component: FieldComponentType.DATASET_SELECT,\n label: 'Repeat over dataset',\n description:\n 'Render this element once per record of a dataset on the published ' +\n 'site. Use {{item.field}} for a record value. Stored by dataset id — ' +\n 'renames never break the repeat.',\n },\n useRows: useDatasetRepeatRows,\n}\n"],"names":["FieldComponentType","useFirestore","useOrgDataScope","useEffect","useState","readDatasetRepeatRows","DATASET_REPEAT_KEY_PROP","useDatasetRepeatRows","request","hostId","key","firestore","scope","ready","answer","setAnswer","status","undefined","active","then","next","error","console","DATASET_REPEAT_SOURCE","id","label","keyProp","keyAttribute","component","DATASET_SELECT","description","useRows"],"mappings":"AAAA;;;;;;;;;;;;;;;CAeC,GAED,SAASA,kBAAkB,QAAQ,eAAc;AAMjD,SAASC,YAAY,EAAEC,eAAe,QAAQ,iCAAgC;AAC9E,SAASC,SAAS,EAAEC,QAAQ,QAAQ,QAAO;AAC3C,SAASC,qBAAqB,QAAQ,2BAAuB;AAE7D;;;;;CAKC,GACD,OAAO,MAAMC,0BAA0B,gBAAe;AAEtD;;;;;;CAMC,GACD,OAAO,SAASC,qBACdC,OAA0B;IAE1B,MAAM,EAAEC,MAAM,EAAEC,GAAG,EAAE,GAAGF;IACxB,MAAMG,YAAYV;IA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