@aglyn/plugins-data 1.13.0 → 1.14.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 (26) hide show
  1. package/package.json +10 -10
  2. package/src/lib/artifact/dataset-schema-artifact.server.js +6 -3
  3. package/src/lib/artifact/dataset-schema-artifact.server.js.map +1 -1
  4. package/src/lib/components/dataset-schema-dialog.component.js +173 -128
  5. package/src/lib/components/dataset-schema-dialog.component.js.map +1 -1
  6. package/src/lib/components/host-datasets-card.component.js +1 -1
  7. package/src/lib/components/host-datasets-card.component.js.map +1 -1
  8. package/src/lib/components/use-dataset-writes-blocked.d.ts +5 -4
  9. package/src/lib/components/use-dataset-writes-blocked.js +11 -12
  10. package/src/lib/components/use-dataset-writes-blocked.js.map +1 -1
  11. package/src/lib/model/dataset-record.js +8 -3
  12. package/src/lib/model/dataset-record.js.map +1 -1
  13. package/src/lib/server/dataset-access.server.d.ts +4 -3
  14. package/src/lib/server/dataset-access.server.js +7 -5
  15. package/src/lib/server/dataset-access.server.js.map +1 -1
  16. package/src/lib/server/dataset-site-erasure.d.ts +2 -2
  17. package/src/lib/server/dataset-site-erasure.js +4 -26
  18. package/src/lib/server/dataset-site-erasure.js.map +1 -1
  19. package/src/lib/server/datasets-route.d.ts +2 -0
  20. package/src/lib/server/datasets-route.js +123 -18
  21. package/src/lib/server/datasets-route.js.map +1 -1
  22. package/src/lib/site-bundle/datasets-site-bundle.server.d.ts +4 -2
  23. package/src/lib/site-bundle/datasets-site-bundle.server.js +8 -4
  24. package/src/lib/site-bundle/datasets-site-bundle.server.js.map +1 -1
  25. package/src/lib/transfer/dataset-transfer-access.server.js +3 -3
  26. package/src/lib/transfer/dataset-transfer-access.server.js.map +1 -1
@@ -16,12 +16,14 @@
16
16
  */ 'use client';
17
17
  import { _ as _extends } from "@swc/helpers/_/_extends";
18
18
  import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
19
- import { getCustomFieldType, listCustomFieldTypes, describeScope, HOST_ACCESS_ROLES, hostScopeToken, narrowsScope, scopeCovers, ORG_SCOPE_TOKEN, scopeToStore, storedScope, visibleToHost } from "@aglyn/aglyn";
19
+ import { getCustomFieldType, listCustomFieldTypes, describeSharing, HOST_ACCESS_ROLES, narrowsScope, scopeSharingOf, sharingCovers, sharingFromChoice, storedScope, visibleToHost } from "@aglyn/aglyn";
20
20
  import { useConfirmationContext } from "@aglyn/shared-ui-jsx";
21
+ import { SiteSharingField } from "@aglyn/shared-ui-jsx/components/site-sharing-field.component";
22
+ import { authorizedFetch } from "@aglyn/shared-util-http/authorized-token";
21
23
  import { useSnackbar } from "@aglyn/shared-ui-snackstack";
22
- import { Button, Checkbox, Alert, Box, Chip, Dialog, DialogActions, DialogContent, DialogTitle, FormControlLabel, IconButton, MenuItem, Select, Stack, TextField, Typography } from "@mui/material";
24
+ import { Button, Checkbox, Alert, Box, Chip, Dialog, DialogActions, DialogContent, DialogTitle, FormControlLabel, IconButton, MenuItem, Stack, TextField, Typography } from "@mui/material";
23
25
  import { collection, doc, limit, query, updateDoc, where } from "firebase/firestore";
24
- import { useCallback, useEffect, useState } from "react";
26
+ import { useCallback, useEffect, useMemo, useState } from "react";
25
27
  import { useFirestore, useFirestoreCollection, useOrgDataScope, useScopeTokens, useUser, writeGuardedBySeed } from "@aglyn/tenant-feature-instance";
26
28
  import { DATASET_AUTHORABLE_FIELD_TYPES, DATASET_FIELD_TYPES, DATASET_FIELD_TYPE_LABELS, effectiveDatasetModel } from "../model/dataset-models.js";
27
29
  import { datasetDisplayName, defaultDatasetFieldId, validateDatasetFieldId } from "../model/datasets.js";
@@ -42,6 +44,33 @@ import { RECORD_PAGE_ADDRESS_FIELD_TYPE, isRecordAddressField } from "../record-
42
44
  children: props.children
43
45
  });
44
46
  }
47
+ /**
48
+ * How a dataset is shared, as the choice the sharing field edits, or null where
49
+ * it stores no sharing (AGL-1484). The seed and the save both read it from here,
50
+ * so a dialog nobody touched compares equal to its own document and writes none.
51
+ */ function sharingChoiceOf(dataset) {
52
+ const sharing = scopeSharingOf(dataset);
53
+ if (sharing.mode === 'all') return {
54
+ mode: 'all'
55
+ };
56
+ if (sharing.mode === 'selected') return {
57
+ mode: 'selected',
58
+ hostIds: sharing.hostIds
59
+ };
60
+ if (sharing.mode === 'allExcept') return {
61
+ mode: 'allExcept',
62
+ exceptHostIds: sharing.exceptHostIds
63
+ };
64
+ return null;
65
+ }
66
+ /** Two choices compare by what they pick, in any order. */ function sharingChoiceKey(choice) {
67
+ if (!choice) return 'unset';
68
+ if (choice.mode === 'all') return 'all';
69
+ const picked = choice.mode === 'selected' ? choice.hostIds : choice.exceptHostIds;
70
+ return `${choice.mode}:${[
71
+ ...picked
72
+ ].sort().join(',')}`;
73
+ }
45
74
  /**
46
75
  * Model builder (AGL-178): edits the AGL-177 typed model on a dataset —
47
76
  * singular/plural display names (dod.ts Schema.Name), add/edit/remove/
@@ -52,7 +81,7 @@ import { RECORD_PAGE_ADDRESS_FIELD_TYPE, isRecordAddressField } from "../record-
52
81
  * lazily on next document save; fieldIds are stable keys — only display
53
82
  * names rename.
54
83
  */ export function DatasetSchemaDialog(props) {
55
- var _ref, _ref1, _ref2, _ref3, _ref4, _editorDefinition_slugFrom, _ref5, _ref6, _find, _ref7, _ref8, _ref9, _ref10;
84
+ var _ref, _ref1, _ref2, _ref3, _ref4, _ref5, _editorDefinition_slugFrom, _ref6, _ref7, _find, _ref8, _ref9, _ref10, _ref11;
56
85
  var _editorDefinition_reference, _editorDefinition_reference1, _editorDefinition_reference2, _editorDefinition_reference3, _editorDefinition_validation;
57
86
  const { hostId, dataset, datasets, recordCount, seedFromCache, seedUnreadable, seedListen, canChangeSharing = true, sharingOnlyReason, onClose } = props;
58
87
  // Org-shared data root (AGL-237/239). Null until the async org lookup
@@ -70,7 +99,7 @@ import { RECORD_PAGE_ADDRESS_FIELD_TYPE, isRecordAddressField } from "../record-
70
99
  // Sharing scope (AGL-1044) — org datasets only; the legacy host path is
71
100
  // site-private by construction.
72
101
  // `orgWide` reads TRUE while the member doc loads (AGL-1047), which would
73
- // offer a scoped collaborator the scope Select for a beat before replacing
102
+ // offer a scoped collaborator the sharing field for a beat before replacing
74
103
  // it with the read-only summary — and offering a control the AGL-1041
75
104
  // rules will reject is the thing the branch below exists to avoid. Hold
76
105
  // the whole block until `loaded` rather than flash the wrong one.
@@ -101,10 +130,22 @@ import { RECORD_PAGE_ADDRESS_FIELD_TYPE, isRecordAddressField } from "../record-
101
130
  ], {
102
131
  idField: '$id'
103
132
  });
104
- const orgHostList = orgHostDocs != null ? orgHostDocs : [];
105
- const [visibleTo, setVisibleTo] = useState([]);
133
+ const orgHostList = useMemo(()=>orgHostDocs != null ? orgHostDocs : [], [
134
+ orgHostDocs
135
+ ]);
136
+ const sitesReady = Array.isArray(orgHostDocs);
137
+ const sharingSites = useMemo(()=>orgHostList.map((host)=>{
138
+ var _ref, _host_name;
139
+ return {
140
+ id: host.$id,
141
+ name: (_ref = (_host_name = host.name) != null ? _host_name : host.subdomain) != null ? _ref : host.$id
142
+ };
143
+ }), [
144
+ orgHostList
145
+ ]);
106
146
  /**
107
- * The dataset stores NO scope (AGL-1484) — as opposed to storing `['org']`.
147
+ * Who this dataset is shared with, as edited here. Null while the dataset
148
+ * stores NO scope (AGL-1484) — as opposed to storing `['org']`.
108
149
  *
109
150
  * The dialog used to render the two identically, which for a dataset is a
110
151
  * worse lie than it was for a media file: `orgs/{orgId}/datasets` is read
@@ -112,7 +153,34 @@ import { RECORD_PAGE_ADDRESS_FIELD_TYPE, isRecordAddressField } from "../record-
112
153
  * own `organizations.ts`, so an unstamped dataset is matched by no reader
113
154
  * in the product. It renders on no site and is missing from the reference
114
155
  * cards even for an org-wide member — while this control said "All sites".
115
- */ const [scopeUnset, setScopeUnset] = useState(false);
156
+ */ const [sharing, setSharing] = useState(null);
157
+ const scopeUnset = sharing === null;
158
+ /**
159
+ * What the choice would write, or why it cannot be. The same answer the
160
+ * `set-sharing` route gives from the workspace's sites, which it reads for
161
+ * itself: the sites a choice leaves out stay known here even where this member
162
+ * can't name them, so they aren't taken for sites that are gone.
163
+ */ const sharingDraft = useMemo(()=>{
164
+ if (!sharing) return null;
165
+ const leftOut = sharing.mode === 'allExcept' ? sharing.exceptHostIds : [];
166
+ return sharingFromChoice(sharing, [
167
+ ...orgHostList.map((host)=>host.$id),
168
+ ...leftOut
169
+ ]);
170
+ }, [
171
+ sharing,
172
+ orgHostList
173
+ ]);
174
+ // Nothing to say about leaving sites out until the sites have been read.
175
+ const sharingProblem = (sharing == null ? void 0 : sharing.mode) !== 'allExcept' || sitesReady ? (_ref = sharingDraft == null ? void 0 : sharingDraft.problem) != null ? _ref : null : null;
176
+ /** The dataset as this choice would leave it, for what depends on where it is. */ const sharingPreview = useMemo(()=>{
177
+ var _ref;
178
+ return (_ref = sharingDraft == null ? void 0 : sharingDraft.fields) != null ? _ref : {
179
+ visibleTo: []
180
+ };
181
+ }, [
182
+ sharingDraft
183
+ ]);
116
184
  const [model, setModel] = useState({
117
185
  fields: {},
118
186
  order: []
@@ -130,11 +198,9 @@ import { RECORD_PAGE_ADDRESS_FIELD_TYPE, isRecordAddressField } from "../record-
130
198
  // AGL-1466 ruled it out: opening a dialog would write, the AGL-1042
131
199
  // rules refuse that write from anyone who is not org-wide, and it
132
200
  // repairs only what somebody happens to look at — a repair mechanism
133
- // wearing a UI. `previousScope` in `handleSave` reads the SAME helper;
134
- // see the note there for why the pair is the safety property.
135
- const storedDatasetScope = storedScope(dataset.visibleTo);
136
- setVisibleTo(storedDatasetScope != null ? storedDatasetScope : []);
137
- setScopeUnset(!storedDatasetScope);
201
+ // wearing a UI. `handleSave` reads the SAME helper; see the note there
202
+ // for why the pair is the safety property.
203
+ setSharing(sharingChoiceOf(dataset));
138
204
  const effective = effectiveDatasetModel(dataset);
139
205
  setModel({
140
206
  fields: JSON.parse(JSON.stringify(effective.fields)),
@@ -270,7 +336,7 @@ import { RECORD_PAGE_ADDRESS_FIELD_TYPE, isRecordAddressField } from "../record-
270
336
  var _storedScope;
271
337
  if (!dataset || !dataScope) return;
272
338
  /**
273
- * What the document actually carries, `[]` when it carries nothing
339
+ * What the document actually carries, nothing when it carries nothing
274
340
  * (AGL-1484) — matching the seed above, through the same helper.
275
341
  *
276
342
  * The pairing is the whole safety property, not tidiness. Both sides
@@ -282,38 +348,37 @@ import { RECORD_PAGE_ADDRESS_FIELD_TYPE, isRecordAddressField } from "../record-
282
348
  * — one the AGL-1041 rules then reject for any member who is not
283
349
  * org-wide, failing the WHOLE schema save with it.
284
350
  *
285
- * `[]` is also the honest previous value in the other direction: a
351
+ * Nothing is also the honest previous value in the other direction: a
286
352
  * deliberate save of exactly `['org']` on an unset dataset used to
287
353
  * compare equal to the default and be dropped, and that is the one save
288
354
  * an unstamped dataset most needs to land.
289
- */ const previousScope = (_storedScope = storedScope(dataset.visibleTo)) != null ? _storedScope : [];
290
- const scopeChanged = JSON.stringify([
291
- ...previousScope
292
- ].sort()) !== JSON.stringify([
293
- ...visibleTo
294
- ].sort());
355
+ */ const scopeChanged = sharingChoiceKey(sharingChoiceOf(dataset)) !== sharingChoiceKey(sharing);
295
356
  /**
296
- * The scope this save writes, or null when it writes none.
357
+ * The sharing this save writes, or null when it writes none.
297
358
  *
298
- * Only an org-wide member may change the scope — the AGL-1041 rules deny
299
- * anyone else, and a rejected field fails the WHOLE write.
359
+ * Only an org-wide member may change it — the route and the AGL-1041 rules
360
+ * refuse anyone else, and it is written through the route because a marker
361
+ * is the server's alone (AGL-4047).
300
362
  *
301
- * A selection `scopeToStore` cannot store — "Selected sites…" with no site
302
- * picked, or more sites than one query can match — refuses the save rather
303
- * than substituting a scope: the org token would share the collection with
304
- * every site, and anything narrower would drop sites somebody picked.
305
- */ const scopeWrite = orgId && viewerOrgWide && canChangeSharing && scopeChanged ? scopeToStore(visibleTo) : null;
306
- if (scopeWrite == null ? void 0 : scopeWrite.problem) {
307
- return void enqueueSnackbar(scopeWrite.problem, {
363
+ * A choice that cannot be stored — "Selected sites" with no site picked, or
364
+ * more sites than one query can match, or nothing left out, or everything —
365
+ * refuses the save rather than substituting a scope: the org token would
366
+ * share the collection with every site, and anything narrower would drop
367
+ * sites somebody picked.
368
+ */ const sharingWrite = orgId && viewerOrgWide && canChangeSharing && scopeChanged ? sharing : null;
369
+ if (sharingWrite && (sharingDraft == null ? void 0 : sharingDraft.problem)) {
370
+ return void enqueueSnackbar(sharingDraft.problem, {
308
371
  variant: 'warning',
309
372
  persist: false
310
373
  });
311
374
  }
312
- if (scopeChanged && narrowsScope(previousScope, visibleTo)) {
375
+ const previousScope = (_storedScope = storedScope(dataset.visibleTo)) != null ? _storedScope : [];
376
+ const nextScope = sharingPreview.visibleTo;
377
+ if (scopeChanged && narrowsScope(previousScope, nextScope)) {
313
378
  // Narrowing takes a dataset away from sites whose pages may bind it,
314
379
  // and a repeatable bound to a dataset it can no longer see renders
315
380
  // nothing (AGL-1039). Name the cost before paying it.
316
- const losing = orgHostList.filter((host)=>visibleToHost(previousScope, host.$id)).filter((host)=>!visibleToHost(visibleTo, host.$id)).map((host)=>{
381
+ const losing = orgHostList.filter((host)=>visibleToHost(previousScope, host.$id)).filter((host)=>!visibleToHost(nextScope, host.$id)).map((host)=>{
317
382
  var _ref, _host_name;
318
383
  return (_ref = (_host_name = host.name) != null ? _host_name : host.subdomain) != null ? _ref : host.$id;
319
384
  });
@@ -325,7 +390,7 @@ import { RECORD_PAGE_ADDRESS_FIELD_TYPE, isRecordAddressField } from "../record-
325
390
  if (!proceed) return;
326
391
  }
327
392
  // Nothing of theirs to write when the sharing did not move.
328
- if (sharingOnlyReason && !(scopeWrite == null ? void 0 : scopeWrite.scope)) return void onClose();
393
+ if (sharingOnlyReason && !sharingWrite) return void onClose();
329
394
  if (!model.order.length) {
330
395
  return void enqueueSnackbar('A collection needs at least one field', {
331
396
  variant: 'warning',
@@ -347,28 +412,51 @@ import { RECORD_PAGE_ADDRESS_FIELD_TYPE, isRecordAddressField } from "../record-
347
412
  * not even warn about the sites it is really taking access from.
348
413
  * - `model` is the entire schema. A cached seed reinstates fields that
349
414
  * were deleted and drops fields that were added.
350
- */ await writeGuardedBySeed({
415
+ *
416
+ * The schema goes first, because who may write it depends on where the
417
+ * dataset sits as it stands, the question the rule asks of this one save.
418
+ */ let sharingRefusal = null;
419
+ await writeGuardedBySeed({
351
420
  subject: 'collection schema',
352
421
  unreadable: seedUnreadable,
353
422
  fromCache: seedFromCache,
354
423
  listen: seedListen
355
- }, async ()=>void await updateDoc(doc(firestore, dataScope[0], dataScope[1], 'datasets', dataset.$id), sharingOnlyReason ? (scopeWrite == null ? void 0 : scopeWrite.scope) ? {
356
- visibleTo: scopeWrite.scope
357
- } : {} : _extends({
358
- model,
359
- names: {
360
- singular: names.singular.trim(),
361
- plural: names.plural.trim()
424
+ }, async ()=>{
425
+ if (!sharingOnlyReason) {
426
+ await updateDoc(doc(firestore, dataScope[0], dataScope[1], 'datasets', dataset.$id), _extends({
427
+ model,
428
+ names: {
429
+ singular: names.singular.trim(),
430
+ plural: names.plural.trim()
431
+ }
432
+ }, names.plural.trim() ? {
433
+ displayName: names.plural.trim()
434
+ } : {}, {
435
+ // v1 compat: keep the flat column list mirroring the model order
436
+ // so unmigrated consumers (AGL-103 bindings) keep working.
437
+ fields: model.order
438
+ }));
439
+ }
440
+ if (sharingWrite) {
441
+ const response = await authorizedFetch(user, '/api/orgs/datasets', {
442
+ method: 'POST',
443
+ headers: {
444
+ 'Content-Type': 'application/json'
445
+ },
446
+ body: JSON.stringify({
447
+ orgId,
448
+ action: 'set-sharing',
449
+ datasetId: dataset.$id,
450
+ choice: sharingWrite
451
+ })
452
+ });
453
+ if (!response.ok) {
454
+ var _ref;
455
+ const payload = await response.json().catch(()=>({}));
456
+ sharingRefusal = String((_ref = payload == null ? void 0 : payload.error) != null ? _ref : 'The sharing could not be changed.');
362
457
  }
363
- }, names.plural.trim() ? {
364
- displayName: names.plural.trim()
365
- } : {}, {
366
- // v1 compat: keep the flat column list mirroring the model order
367
- // so unmigrated consumers (AGL-103 bindings) keep working.
368
- fields: model.order
369
- }, (scopeWrite == null ? void 0 : scopeWrite.scope) ? {
370
- visibleTo: scopeWrite.scope
371
- } : {}))).then((result)=>{
458
+ }
459
+ }).then((result)=>{
372
460
  // A refusal leaves the dialog open with the edited schema intact.
373
461
  if (!result.ok) {
374
462
  return void enqueueSnackbar(result.message, {
@@ -376,6 +464,12 @@ import { RECORD_PAGE_ADDRESS_FIELD_TYPE, isRecordAddressField } from "../record-
376
464
  persist: false
377
465
  });
378
466
  }
467
+ if (sharingRefusal) {
468
+ return void enqueueSnackbar(sharingOnlyReason ? sharingRefusal : `Schema saved. Its sharing didn’t change: ${sharingRefusal}`, {
469
+ variant: 'warning',
470
+ persist: false
471
+ });
472
+ }
379
473
  enqueueSnackbar(sharingOnlyReason ? 'Sharing saved' : 'Schema saved', {
380
474
  variant: 'success',
381
475
  persist: false
@@ -388,7 +482,10 @@ import { RECORD_PAGE_ADDRESS_FIELD_TYPE, isRecordAddressField } from "../record-
388
482
  dataset,
389
483
  model,
390
484
  names,
391
- visibleTo,
485
+ sharing,
486
+ sharingDraft,
487
+ sharingPreview,
488
+ user,
392
489
  viewerOrgWide,
393
490
  canChangeSharing,
394
491
  sharingOnlyReason,
@@ -478,77 +575,25 @@ import { RECORD_PAGE_ADDRESS_FIELD_TYPE, isRecordAddressField } from "../record-
478
575
  severity: "warning",
479
576
  children: 'This collection has never been shared. Nothing is ' + 'stored, so it is hidden from every site and any ' + 'page repeating over it renders nothing. Choose who ' + 'it is shared with to fix that.'
480
577
  }) : null,
481
- /*#__PURE__*/ _jsxs(Select, {
482
- size: "small",
483
- value: visibleTo.includes(ORG_SCOPE_TOKEN) ? 'org' : scopeUnset ? 'unset' : 'hosts',
484
- onChange: (event)=>{
485
- // Any choice ends the unset state — from here the
486
- // control shows what was picked, not what was (not)
487
- // stored.
488
- setScopeUnset(false);
489
- setVisibleTo(event.target.value === 'org' ? [
490
- ORG_SCOPE_TOKEN
491
- ] : []);
492
- },
493
- children: [
494
- scopeUnset ? /*#__PURE__*/ _jsx(MenuItem, {
495
- value: "unset",
496
- disabled: true,
497
- children: 'Not shared with any site'
498
- }) : null,
499
- /*#__PURE__*/ _jsx(MenuItem, {
500
- value: "org",
501
- children: 'All sites'
502
- }),
503
- /*#__PURE__*/ _jsx(MenuItem, {
504
- value: "hosts",
505
- children: 'Selected sites…'
506
- })
507
- ]
578
+ /*#__PURE__*/ _jsx(SiteSharingField, {
579
+ value: sharing,
580
+ onChange: setSharing,
581
+ sites: sharingSites,
582
+ sitesReady: sitesReady,
583
+ problem: sharingProblem
508
584
  }),
509
585
  /*#__PURE__*/ _jsx(Typography, {
510
586
  variant: "caption",
511
587
  color: "text.secondary",
512
588
  children: 'Sites you exclude cannot see or use this dataset — in the console or on their pages.'
513
- }),
514
- !scopeUnset && !visibleTo.includes(ORG_SCOPE_TOKEN) ? /*#__PURE__*/ _jsx(Stack, {
515
- direction: "row",
516
- spacing: 0.5,
517
- useFlexGap: true,
518
- sx: {
519
- flexWrap: 'wrap'
520
- },
521
- children: orgHostList.map((host)=>{
522
- var _ref, _host_name;
523
- const token = hostScopeToken(host.$id);
524
- const on = visibleTo.includes(token);
525
- return /*#__PURE__*/ _jsx(Chip, {
526
- size: "small",
527
- label: (_ref = (_host_name = host.name) != null ? _host_name : host.subdomain) != null ? _ref : host.$id,
528
- color: on ? 'primary' : 'default',
529
- variant: on ? 'filled' : 'outlined',
530
- onClick: ()=>setVisibleTo((prev)=>on ? prev.filter((t)=>t !== token) : [
531
- ...prev,
532
- token
533
- ])
534
- }, host.$id);
535
- })
536
- }) : null,
537
- !scopeUnset && scopeToStore(visibleTo).problem ? /*#__PURE__*/ _jsx(Typography, {
538
- variant: "caption",
539
- color: "error",
540
- children: scopeToStore(visibleTo).problem
541
- }) : null
589
+ })
542
590
  ]
543
591
  }) : /*#__PURE__*/ _jsx(Typography, {
544
592
  variant: "body2",
545
- children: scopeUnset ? 'Never shared — hidden from every site' : describeScope(visibleTo, Object.fromEntries(orgHostList.map((host)=>{
546
- var _ref, _host_name;
547
- return [
548
- host.$id,
549
- (_ref = (_host_name = host.name) != null ? _host_name : host.subdomain) != null ? _ref : host.$id
550
- ];
551
- })))
593
+ children: scopeUnset ? 'Never shared — hidden from every site' : describeSharing(dataset, Object.fromEntries(sharingSites.map((site)=>[
594
+ site.id,
595
+ site.name
596
+ ])))
552
597
  })
553
598
  ]
554
599
  }) : null,
@@ -689,7 +734,7 @@ import { RECORD_PAGE_ADDRESS_FIELD_TYPE, isRecordAddressField } from "../record-
689
734
  /*#__PURE__*/ _jsx(TextField, {
690
735
  size: "small",
691
736
  label: "Display name",
692
- value: (_ref = editorDefinition == null ? void 0 : editorDefinition.name) != null ? _ref : '',
737
+ value: (_ref1 = editorDefinition == null ? void 0 : editorDefinition.name) != null ? _ref1 : '',
693
738
  autoFocus: true,
694
739
  onChange: (event)=>{
695
740
  const name = event.target.value;
@@ -716,7 +761,7 @@ import { RECORD_PAGE_ADDRESS_FIELD_TYPE, isRecordAddressField } from "../record-
716
761
  /*#__PURE__*/ _jsx(TextField, {
717
762
  size: "small",
718
763
  label: "Reference ID",
719
- value: isNewField ? (_ref1 = fieldEditor == null ? void 0 : fieldEditor.idDraft) != null ? _ref1 : '' : (_ref2 = fieldEditor == null ? void 0 : fieldEditor.fieldId) != null ? _ref2 : '',
764
+ value: isNewField ? (_ref2 = fieldEditor == null ? void 0 : fieldEditor.idDraft) != null ? _ref2 : '' : (_ref3 = fieldEditor == null ? void 0 : fieldEditor.fieldId) != null ? _ref3 : '',
720
765
  disabled: !isNewField,
721
766
  onChange: (event)=>setFieldEditor((prev)=>prev ? _extends({}, prev, {
722
767
  idDraft: event.target.value,
@@ -730,7 +775,7 @@ import { RECORD_PAGE_ADDRESS_FIELD_TYPE, isRecordAddressField } from "../record-
730
775
  label: "Description",
731
776
  multiline: true,
732
777
  minRows: 2,
733
- value: (_ref3 = editorDefinition == null ? void 0 : editorDefinition.description) != null ? _ref3 : '',
778
+ value: (_ref4 = editorDefinition == null ? void 0 : editorDefinition.description) != null ? _ref4 : '',
734
779
  onChange: (event)=>setFieldEditor((prev)=>prev ? _extends({}, prev, {
735
780
  definition: _extends({}, prev.definition, {
736
781
  description: event.target.value
@@ -742,7 +787,7 @@ import { RECORD_PAGE_ADDRESS_FIELD_TYPE, isRecordAddressField } from "../record-
742
787
  select: true,
743
788
  size: "small",
744
789
  label: "Type",
745
- value: (editorDefinition == null ? void 0 : editorDefinition.customType) ? `custom:${editorDefinition.customType}` : (_ref4 = editorDefinition == null ? void 0 : editorDefinition.type) != null ? _ref4 : 'text',
790
+ value: (editorDefinition == null ? void 0 : editorDefinition.customType) ? `custom:${editorDefinition.customType}` : (_ref5 = editorDefinition == null ? void 0 : editorDefinition.type) != null ? _ref5 : 'text',
746
791
  onChange: (event)=>setFieldEditor((prev)=>{
747
792
  if (!prev) return prev;
748
793
  const selected = event.target.value;
@@ -817,7 +862,7 @@ import { RECORD_PAGE_ADDRESS_FIELD_TYPE, isRecordAddressField } from "../record-
817
862
  select: true,
818
863
  size: "small",
819
864
  label: "Target collection",
820
- value: (_ref5 = editorDefinition == null ? void 0 : (_editorDefinition_reference = editorDefinition.reference) == null ? void 0 : _editorDefinition_reference.datasetId) != null ? _ref5 : '',
865
+ value: (_ref6 = editorDefinition == null ? void 0 : (_editorDefinition_reference = editorDefinition.reference) == null ? void 0 : _editorDefinition_reference.datasetId) != null ? _ref6 : '',
821
866
  onChange: (event)=>setFieldEditor((prev)=>{
822
867
  var _prev_definition_reference;
823
868
  return prev ? _extends({}, prev, {
@@ -838,7 +883,7 @@ import { RECORD_PAGE_ADDRESS_FIELD_TYPE, isRecordAddressField } from "../record-
838
883
  // scope would silently blank an existing field.
839
884
  .filter((target)=>{
840
885
  var _editorDefinition_reference;
841
- return target.$id === (editorDefinition == null ? void 0 : (_editorDefinition_reference = editorDefinition.reference) == null ? void 0 : _editorDefinition_reference.datasetId) || scopeCovers(target.visibleTo, visibleTo);
886
+ return target.$id === (editorDefinition == null ? void 0 : (_editorDefinition_reference = editorDefinition.reference) == null ? void 0 : _editorDefinition_reference.datasetId) || sharingCovers(target, sharingPreview);
842
887
  }).map((target)=>/*#__PURE__*/ _jsx(MenuItem, {
843
888
  value: target.$id,
844
889
  children: datasetDisplayName(target) || target.$id
@@ -851,7 +896,7 @@ import { RECORD_PAGE_ADDRESS_FIELD_TYPE, isRecordAddressField } from "../record-
851
896
  // is not any more.
852
897
  const targetId = editorDefinition == null ? void 0 : (_editorDefinition_reference = editorDefinition.reference) == null ? void 0 : _editorDefinition_reference.datasetId;
853
898
  const target = (datasets != null ? datasets : []).find((d)=>d.$id === targetId);
854
- if (!target || scopeCovers(target.visibleTo, visibleTo)) {
899
+ if (!target || sharingCovers(target, sharingPreview)) {
855
900
  return null;
856
901
  }
857
902
  return /*#__PURE__*/ _jsx(Alert, {
@@ -863,7 +908,7 @@ import { RECORD_PAGE_ADDRESS_FIELD_TYPE, isRecordAddressField } from "../record-
863
908
  select: true,
864
909
  size: "small",
865
910
  label: "Display field",
866
- value: (_ref6 = editorDefinition == null ? void 0 : (_editorDefinition_reference1 = editorDefinition.reference) == null ? void 0 : _editorDefinition_reference1.displayFieldId) != null ? _ref6 : '',
911
+ value: (_ref7 = editorDefinition == null ? void 0 : (_editorDefinition_reference1 = editorDefinition.reference) == null ? void 0 : _editorDefinition_reference1.displayFieldId) != null ? _ref7 : '',
867
912
  onChange: (event)=>setFieldEditor((prev)=>(prev == null ? void 0 : prev.definition.reference) ? _extends({}, prev, {
868
913
  definition: _extends({}, prev.definition, {
869
914
  reference: _extends({}, prev.definition.reference, {
@@ -884,7 +929,7 @@ import { RECORD_PAGE_ADDRESS_FIELD_TYPE, isRecordAddressField } from "../record-
884
929
  select: true,
885
930
  size: "small",
886
931
  label: "When a referenced document is deleted",
887
- value: (_ref7 = editorDefinition == null ? void 0 : (_editorDefinition_reference2 = editorDefinition.reference) == null ? void 0 : _editorDefinition_reference2.onDelete) != null ? _ref7 : 'setNull',
932
+ value: (_ref8 = editorDefinition == null ? void 0 : (_editorDefinition_reference2 = editorDefinition.reference) == null ? void 0 : _editorDefinition_reference2.onDelete) != null ? _ref8 : 'setNull',
888
933
  onChange: (event)=>setFieldEditor((prev)=>(prev == null ? void 0 : prev.definition.reference) ? _extends({}, prev, {
889
934
  definition: _extends({}, prev.definition, {
890
935
  reference: _extends({}, prev.definition.reference, {
@@ -934,7 +979,7 @@ import { RECORD_PAGE_ADDRESS_FIELD_TYPE, isRecordAddressField } from "../record-
934
979
  /*#__PURE__*/ _jsx(TextField, {
935
980
  size: "small",
936
981
  label: "Default value",
937
- value: String((_ref8 = editorDefinition == null ? void 0 : editorDefinition.default) != null ? _ref8 : ''),
982
+ value: String((_ref9 = editorDefinition == null ? void 0 : editorDefinition.default) != null ? _ref9 : ''),
938
983
  onChange: (event)=>setFieldEditor((prev)=>prev ? _extends({}, prev, {
939
984
  definition: _extends({}, prev.definition, event.target.value ? {
940
985
  default: event.target.value
@@ -949,7 +994,7 @@ import { RECORD_PAGE_ADDRESS_FIELD_TYPE, isRecordAddressField } from "../record-
949
994
  /*#__PURE__*/ _jsx(TextField, {
950
995
  size: "small",
951
996
  label: "Pattern (regex)",
952
- value: (_ref9 = editorDefinition == null ? void 0 : (_editorDefinition_validation = editorDefinition.validation) == null ? void 0 : _editorDefinition_validation.regex) != null ? _ref9 : '',
997
+ value: (_ref10 = editorDefinition == null ? void 0 : (_editorDefinition_validation = editorDefinition.validation) == null ? void 0 : _editorDefinition_validation.regex) != null ? _ref10 : '',
953
998
  onChange: (event)=>setFieldEditor((prev)=>{
954
999
  var _prev_definition_validation;
955
1000
  return prev ? _extends({}, prev, {
@@ -966,7 +1011,7 @@ import { RECORD_PAGE_ADDRESS_FIELD_TYPE, isRecordAddressField } from "../record-
966
1011
  /*#__PURE__*/ _jsx(TextField, {
967
1012
  size: "small",
968
1013
  label: "Options",
969
- value: (_ref10 = fieldEditor == null ? void 0 : fieldEditor.optionsText) != null ? _ref10 : '',
1014
+ value: (_ref11 = fieldEditor == null ? void 0 : fieldEditor.optionsText) != null ? _ref11 : '',
970
1015
  onChange: (event)=>setFieldEditor((prev)=>prev ? _extends({}, prev, {
971
1016
  optionsText: event.target.value
972
1017
  }) : prev),