@phis/ui 0.7.5 → 0.7.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.
Files changed (117) hide show
  1. package/components/controls/phi-form-control.d.ts +3 -1
  2. package/components/controls/phi-form-control.js +4 -4
  3. package/components/forms/auth-admin-settings-labels.d.ts +1 -1
  4. package/components/forms/auth-admin-settings-labels.js +2 -2
  5. package/components/forms/form-descriptor-contract.d.ts +1 -1
  6. package/components/forms/form-descriptor-contract.js +1 -1
  7. package/components/forms/form-descriptor-runtime-client.d.ts +4 -1
  8. package/components/forms/form-descriptor-runtime-client.js +33 -11
  9. package/components/forms/form-media-limits.d.ts +12 -0
  10. package/components/forms/form-media-limits.js +14 -0
  11. package/components/forms/form-provider-registry.d.ts +8 -0
  12. package/components/forms/form-record-title.d.ts +14 -0
  13. package/components/forms/form-record-title.js +38 -0
  14. package/components/forms/form-widget-config.d.ts +3 -0
  15. package/components/forms/form-widget-config.js +2 -0
  16. package/components/forms/phi-form-widget.d.ts +1 -1
  17. package/components/forms/phi-form-widget.js +4 -0
  18. package/components/overlays/phi-overlay-container-client.js +8 -8
  19. package/components/overlays/phi-overlay-title.d.ts +7 -0
  20. package/components/overlays/phi-overlay-title.js +21 -0
  21. package/components/tables/client/phi-table-binding.d.ts +3 -1
  22. package/components/tables/client/phi-table-binding.js +90 -49
  23. package/components/tables/client/phi-table-filter-options.d.ts +27 -0
  24. package/components/tables/client/phi-table-filter-options.js +35 -0
  25. package/components/widgets/accessible-areas.d.ts +1 -1
  26. package/components/widgets/accessible-areas.js +1 -1
  27. package/components/widgets/client/shared/phi-rendered-value.d.ts +10 -0
  28. package/components/widgets/client/shared/phi-rendered-value.js +49 -1
  29. package/components/widgets/client/shared/phi-table-provider.d.ts +10 -1
  30. package/components/widgets/client/shared/phi-table-provider.js +22 -0
  31. package/components/widgets/label-sets/admin-users.d.ts +15 -0
  32. package/components/widgets/label-sets/admin-users.js +31 -0
  33. package/constants/core-data-provider-keys.d.ts +7 -0
  34. package/constants/core-data-provider-keys.js +7 -0
  35. package/constants/phi-base-role-metadata.d.ts +2 -2
  36. package/constants/phi-base-role-metadata.js +1 -1
  37. package/constants/runtime-module-ownership.js +3 -0
  38. package/forms.d.ts +1 -1
  39. package/forms.js +1 -1
  40. package/gateway/capability-media-limits.d.ts +10 -0
  41. package/gateway/capability-media-limits.js +40 -0
  42. package/gateway/server-capabilities.js +4 -0
  43. package/helpers/preset-tree-contract-check.d.ts +3 -2
  44. package/helpers/preset-tree-contract-check.js +60 -0
  45. package/helpers/record-title.d.ts +7 -0
  46. package/helpers/record-title.js +25 -0
  47. package/helpers/record-widget.d.ts +15 -0
  48. package/helpers/record-widget.js +57 -0
  49. package/package.json +2 -2
  50. package/plugins/runtime-modules/accounting/client-data-providers.d.ts +7 -0
  51. package/plugins/runtime-modules/accounting/client-data-providers.js +9 -0
  52. package/plugins/runtime-modules/accounting/data-providers.d.ts +63 -0
  53. package/plugins/runtime-modules/accounting/data-providers.js +127 -0
  54. package/plugins/runtime-modules/accounting/definition.d.ts +54 -2
  55. package/plugins/runtime-modules/accounting/definition.js +5 -3
  56. package/plugins/runtime-modules/accounting/ids.d.ts +20 -0
  57. package/plugins/runtime-modules/accounting/ids.js +27 -0
  58. package/plugins/runtime-modules/accounting/module.d.ts +52 -0
  59. package/plugins/runtime-modules/accounting/presets.js +23 -4
  60. package/plugins/runtime-modules/accounting/services/products-table.d.ts +93 -0
  61. package/plugins/runtime-modules/accounting/services/products-table.js +158 -0
  62. package/plugins/runtime-modules/accounting/trees/accounting-products-label-set.d.ts +86 -0
  63. package/plugins/runtime-modules/accounting/trees/accounting-products-label-set.js +123 -0
  64. package/plugins/runtime-modules/accounting/trees/phi-default-accounting-products-page-tree.d.ts +21 -0
  65. package/plugins/runtime-modules/accounting/trees/phi-default-accounting-products-page-tree.js +435 -0
  66. package/plugins/runtime-modules/area-definitions.js +2 -2
  67. package/plugins/runtime-modules/asset/media-asset-field.d.ts +15 -0
  68. package/plugins/runtime-modules/asset/media-asset-field.js +21 -0
  69. package/plugins/runtime-modules/asset/media-asset-form-control.d.ts +4 -0
  70. package/plugins/runtime-modules/asset/media-asset-form-control.js +10 -5
  71. package/plugins/runtime-modules/asset/media-assets-field.d.ts +8 -0
  72. package/plugins/runtime-modules/asset/media-assets-field.js +10 -0
  73. package/plugins/runtime-modules/asset/media-assets-form-control.d.ts +5 -0
  74. package/plugins/runtime-modules/asset/media-assets-form-control.js +15 -6
  75. package/plugins/runtime-modules/auth/admin-settings-forms.js +1 -1
  76. package/plugins/runtime-modules/client-manifests/accounting.js +5 -1
  77. package/plugins/runtime-modules/core/cards.js +2 -2
  78. package/plugins/runtime-modules/core/client-data-providers.js +5 -0
  79. package/plugins/runtime-modules/core/data-providers.js +14 -0
  80. package/plugins/runtime-modules/core/services/site-members-options.d.ts +27 -0
  81. package/plugins/runtime-modules/core/services/site-members-options.js +55 -0
  82. package/plugins/runtime-modules/core/widgets/form/config.d.ts +5 -0
  83. package/plugins/runtime-modules/core/widgets/form/config.js +3 -0
  84. package/plugins/runtime-modules/core/widgets/record/actions.d.ts +20 -0
  85. package/plugins/runtime-modules/core/widgets/record/actions.js +77 -0
  86. package/plugins/runtime-modules/core/widgets/record/client.js +71 -8
  87. package/plugins/runtime-modules/core/widgets/record/config.d.ts +66 -1
  88. package/plugins/runtime-modules/core/widgets/record/config.js +71 -2
  89. package/plugins/runtime-modules/core/widgets/table/client.js +33 -29
  90. package/plugins/runtime-modules/core/widgets/table/config.js +5 -1
  91. package/plugins/runtime-modules/groups/data-providers.js +1 -1
  92. package/plugins/runtime-modules/groups/definition.js +1 -1
  93. package/plugins/runtime-modules/groups/page-visibility.d.ts +1 -1
  94. package/plugins/runtime-modules/groups/page-visibility.js +1 -1
  95. package/plugins/runtime-modules/groups/presets.js +1 -1
  96. package/plugins/runtime-modules/groups/services/options.js +1 -1
  97. package/plugins/runtime-modules/groups/services/table.js +1 -1
  98. package/plugins/runtime-modules/groups/trees/phi-default-app-groups-page-tree.js +2 -2
  99. package/plugins/runtime-modules/user-management/addon-roles.d.ts +60 -4
  100. package/plugins/runtime-modules/user-management/addon-roles.js +92 -8
  101. package/plugins/runtime-modules/user-management/addresses.d.ts +1 -1
  102. package/plugins/runtime-modules/user-management/controller/client.js +1 -1
  103. package/plugins/runtime-modules/user-management/data-providers.js +1 -0
  104. package/plugins/runtime-modules/user-management/forms.js +22 -0
  105. package/plugins/runtime-modules/user-management/presets.js +2 -2
  106. package/plugins/runtime-modules/user-management/services/options.d.ts +4 -0
  107. package/plugins/runtime-modules/user-management/services/options.js +14 -6
  108. package/plugins/runtime-modules/user-management/services/table.js +12 -3
  109. package/plugins/runtime-modules/user-management/trees/phi-default-admin-users-page-tree.js +9 -4
  110. package/types/access.d.ts +1 -1
  111. package/types/access.js +7 -7
  112. package/types/core-widget-placements.d.ts +7 -0
  113. package/types/form-descriptor.d.ts +1 -1
  114. package/types/record-widget.d.ts +35 -0
  115. package/types/server-capabilities.d.ts +1 -1
  116. package/types/table-widget.d.ts +20 -0
  117. package/types/table-widget.js +44 -0
package/forms.js CHANGED
@@ -7,7 +7,7 @@ export { PHI_FORM_CONTROLLER_KEY, PHI_FORM_SIGNAL_CHANNELS, PHI_RUNTIME_FORM_CON
7
7
  export { PHI_FORM_BUILDER_CONTROLLER_INSTANCE_KEY, PHI_FORM_BUILDER_CONTROLLER_KEY, PHI_FORM_BUILDER_CONTROLLER_PLUGIN_KEY, PHI_FORM_BUILDER_CONTROLLER_TYPE, createPhiFormBuilderControllerAddress, } from "./components/forms/form-builder-controller-address";
8
8
  export { PHI_FORM_BUILDER_CONTROLLER_DEFINITION, parsePhiFormBuilderControllerConfig, } from "./components/forms/form-builder-controller-definition";
9
9
  export { PHI_AUTH_FORM_FIELD_PROVIDER_KEYS, PHI_FORM_FIELD_PROVIDER_KEYS, PHI_FORM_HANDLER_PROVIDER_KEYS, PHI_FORM_VALIDATION_PROVIDER_KEYS, PHI_SHARED_FORM_FIELD_TYPE_PROVIDER_DESCRIPTORS, PHI_SHARED_FORM_VALIDATION_PROVIDER_DESCRIPTORS, createPhiSharedFormProviderKey, } from "./components/forms/form-provider-contract";
10
- export { PHI_FORM_DEFAULT_LAYOUT, PHI_FORM_GRID_LAST_LINE, PHI_FORM_RESPONSIVE_MIN_WIDTH, PHI_FORM_RESPONSIVE_MODES, assertPhiFormLabelSetKey, createPhiFormLabelText, createPhiFormLiteralText, resolvePhiFormFieldExtent, resolvePhiFormFieldRanges, phiFormGridColumn, resolvePhiFormGridPlacement, phiFormGridRangesOverlap, resolvePhiFormLayout, resolvePhiFormResponsiveGridRange, resolvePhiFormText, parsePhiFormDescriptor, } from "./components/forms/form-descriptor-contract";
10
+ export { PHI_FORM_DEFAULT_LAYOUT, PHI_FORM_GRID_LAST_LINE, PHI_FORM_RESPONSIVE_MIN_WIDTH, PHI_FORM_RESPONSIVE_MODES, assertPhiFormLabelSetKey, createPhiFormLabelText, createPhiFormLiteralText, resolvePhiFormFieldExtent, resolvePhiFormFieldRanges, phiFormGridColumn, resolvePhiFormGridPlacement, phiFormGridRangesOverlap, resolvePhiFormLayout, resolvePhiFormResponsiveGridRange, resolvePhiFormErrorText, resolvePhiFormText, parsePhiFormDescriptor, } from "./components/forms/form-descriptor-contract";
11
11
  export { PHI_CONFIRM_FORM_DESCRIPTOR, PHI_CONTACT_FORM_DESCRIPTOR, PHI_FORM_LABEL_SET_KEYS, PHI_LOGIN_FORM_DESCRIPTOR, PHI_REGISTRATION_FORM_DESCRIPTOR, PHI_RESET_PASSWORD_CONFIRM_FORM_DESCRIPTOR, PHI_RESET_PASSWORD_FORM_DESCRIPTOR, PHI_UNSUBSCRIBE_FORM_DESCRIPTOR, } from "./components/forms/shared-form-descriptors";
12
12
  export { PHI_SHARED_FORM_IDS } from "./components/forms/shared-form-ids";
13
13
  /*
@@ -0,0 +1,10 @@
1
+ import type { PhiAddonMediaLimits } from "../types/server-capabilities";
2
+ /**
3
+ * The Media limits of a provider in the capability snapshot (`PhiCapabilityProvider.media`), read as
4
+ * strictly as phis-server admits them from the manifest: absent is no limit of the Add-on's own; anything
5
+ * stated is an object with no other keys, `maxFileBytes` and `maxPerField` positive whole numbers, and
6
+ * `kinds` a non-empty list of `PhiMediaKind` values without duplicates. Anything else throws, as every
7
+ * other malformed part of the snapshot does -- a limit read past would be a Media field that takes what
8
+ * the Add-on refuses on save.
9
+ */
10
+ export declare function readPhiCapabilityProviderMediaLimits(value: unknown): PhiAddonMediaLimits | undefined;
@@ -0,0 +1,40 @@
1
+ import { PhiMediaKind } from "../constants/media";
2
+ import { isPhiRecord } from "../helpers/is-record";
3
+ const MEDIA_LIMIT_KEYS = new Set(["maxFileBytes", "kinds", "maxPerField"]);
4
+ const MEDIA_KINDS = new Set(Object.values(PhiMediaKind));
5
+ function isPositiveWholeNumber(value) {
6
+ return typeof value === "number" && Number.isSafeInteger(value) && value > 0;
7
+ }
8
+ /**
9
+ * The Media limits of a provider in the capability snapshot (`PhiCapabilityProvider.media`), read as
10
+ * strictly as phis-server admits them from the manifest: absent is no limit of the Add-on's own; anything
11
+ * stated is an object with no other keys, `maxFileBytes` and `maxPerField` positive whole numbers, and
12
+ * `kinds` a non-empty list of `PhiMediaKind` values without duplicates. Anything else throws, as every
13
+ * other malformed part of the snapshot does -- a limit read past would be a Media field that takes what
14
+ * the Add-on refuses on save.
15
+ */
16
+ export function readPhiCapabilityProviderMediaLimits(value) {
17
+ if (value === undefined)
18
+ return undefined;
19
+ if (!isPhiRecord(value)) {
20
+ throw new Error("Invalid server capability provider media limits.");
21
+ }
22
+ const record = value;
23
+ if (Object.keys(record).some((key) => !MEDIA_LIMIT_KEYS.has(key))) {
24
+ throw new Error("Invalid server capability provider media limits.");
25
+ }
26
+ const { maxFileBytes, kinds, maxPerField } = record;
27
+ if ((maxFileBytes !== undefined && !isPositiveWholeNumber(maxFileBytes)) ||
28
+ (maxPerField !== undefined && !isPositiveWholeNumber(maxPerField)) ||
29
+ (kinds !== undefined && (!Array.isArray(kinds) ||
30
+ kinds.length === 0 ||
31
+ kinds.some((kind) => typeof kind !== "string" || !MEDIA_KINDS.has(kind)) ||
32
+ new Set(kinds).size !== kinds.length))) {
33
+ throw new Error("Invalid server capability provider media limits.");
34
+ }
35
+ return {
36
+ ...(maxFileBytes !== undefined ? { maxFileBytes } : {}),
37
+ ...(kinds !== undefined ? { kinds: [...kinds] } : {}),
38
+ ...(maxPerField !== undefined ? { maxPerField } : {}),
39
+ };
40
+ }
@@ -1,4 +1,5 @@
1
1
  import "server-only";
2
+ import { readPhiCapabilityProviderMediaLimits } from "./capability-media-limits";
2
3
  import { fetchPhiSiteApi } from "./site-api-request";
3
4
  import { readPhiSiteReadCache } from "./site-read-cache";
4
5
  const PROVIDER_ID_PATTERN = /^@[^/]+\/[^/]+(?:\/[^/]+)*$/;
@@ -40,11 +41,14 @@ function parseProvider(value) {
40
41
  !Array.isArray(record.capabilities)) {
41
42
  throw new Error("Invalid server capability provider.");
42
43
  }
44
+ // The Add-on's manifest `media`, which the Media fields of its Module apply (FORMS.md); absent for Core.
45
+ const media = readPhiCapabilityProviderMediaLimits(record.media);
43
46
  return {
44
47
  providerId: record.providerId,
45
48
  state: record.state,
46
49
  diagnosticCode: record.diagnosticCode,
47
50
  capabilities: record.capabilities.map(parseCapability),
51
+ ...(media ? { media } : {}),
48
52
  };
49
53
  }
50
54
  function parseSnapshot(value) {
@@ -11,8 +11,9 @@ import type { PhiCmsPageNode, PhiResolvedCmsPageTree } from "../types/cms";
11
11
  * The rules: every node a preset instance id, none twice, every parent, Region root, Overlay root and Page
12
12
  * root resolved; the base page layout node only as the canonical scaffold; an actions Footer the canonical
13
13
  * Flex preset; a modal's body and actions the dialog's (`helpers/cms-dialog.ts`), and a modal at the default
14
- * `PHI_DIALOG_WIDTH` not holding only Forms of one column. The findings come in the order the compiler used
15
- * to throw them, so its first is the error it always gave.
14
+ * `PHI_DIALOG_WIDTH` not holding only Forms of one column; a Form's or a record Widget's title from its
15
+ * record read, sent, and heard where it goes. The findings come in the order the compiler used to throw them, so its first is the
16
+ * error it always gave.
16
17
  *
17
18
  * `page` is the Page the tree was asked for: a tree whose Page or Regions belong to another is refused.
18
19
  * `forms` are the Forms the caller can see, by id or as definitions; a Form not among them -- one stored on
@@ -4,6 +4,8 @@ import { PhiCmsWidgetType } from "../constants/cms-widget-types";
4
4
  import { isPhiCmsInstanceId, readPhiCmsInstanceIdDescriptor } from "../types/cms-instance-id";
5
5
  import { PHI_DIALOG_BLEED_BODY_CONFIG, PHI_DIALOG_BODY_CONFIG, PHI_DIALOG_COMMANDS_CONFIG, PHI_DIALOG_WIDTH, isPhiFormSingleColumn, } from "./cms-dialog";
6
6
  import { resolvePhiLayoutCreationPreset } from "./cms-layout-defaults";
7
+ import { PHI_FORM_RECORD_TITLE_CAPABILITY, readPhiFormWidgetTitleFromRecord, } from "../components/forms/form-record-title";
8
+ import { readPhiRecordWidgetTitleFromRecord } from "./record-widget";
7
9
  function stablePresetNodeJson(value) {
8
10
  if (Array.isArray(value)) {
9
11
  return `[${value.map(stablePresetNodeJson).join(",")}]`;
@@ -112,6 +114,7 @@ export function checkPhiPresetTreeContract(tree, options = {}) {
112
114
  if (forms)
113
115
  checkDialogWidth(overlay, tree, forms, report);
114
116
  }
117
+ checkRecordTitles(tree, forms, report);
115
118
  for (const rootLayoutNodeId of [
116
119
  tree.page.heroRootLayoutNodeId,
117
120
  tree.page.headerBottomRootLayoutNodeId,
@@ -209,3 +212,60 @@ function checkDialogWidth(overlay, tree, forms, report) {
209
212
  "(PHI_DIALOG_WIDTH). Hand the Form to `dialog` as `body.form`, or state `width: PHI_DIALOG_WIDTH_SINGLE_COLUMN`.");
210
213
  }
211
214
  }
215
+ function readRoutes(config, side) {
216
+ const routes = config.signalRoutes?.[side];
217
+ return Array.isArray(routes) ? routes.filter((route) => route != null && typeof route === "object") : [];
218
+ }
219
+ /*
220
+ * A title from the record shown (`helpers/record-title.ts`), end to end, for the record Form and the record
221
+ * Widget alike, since every break is silent: no `source` reads nothing, no `recordTitle` route names
222
+ * nothing, a route without the option carries nothing, an Overlay not listening on `title` drops it. Where
223
+ * the Form is known, the field is one of its own -- a record answers for the Form's fields; a record
224
+ * Widget reads the whole row its Provider answers, so any field of it may name the dialog.
225
+ */
226
+ function checkRecordTitles(tree, forms, report) {
227
+ const overlaysById = new Map(tree.overlays.map((overlay) => [`cms:${overlay.id}`, overlay]));
228
+ for (const widget of tree.contentWidgets) {
229
+ const isForm = widget.widgetType === PhiCmsWidgetType.Form;
230
+ if (!isForm && widget.widgetType !== PhiCmsWidgetType.Record)
231
+ continue;
232
+ const name = `Preset ${isForm ? "Form" : "Record"} "${widget.id}"`;
233
+ const routes = readRoutes(widget.config, "emits").filter((route) => route.capabilityId === PHI_FORM_RECORD_TITLE_CAPABILITY);
234
+ let title;
235
+ try {
236
+ title = isForm
237
+ ? readPhiFormWidgetTitleFromRecord(widget.config.titleFromRecord)
238
+ : readPhiRecordWidgetTitleFromRecord(widget.config.titleFromRecord);
239
+ }
240
+ catch (error) {
241
+ report(widget.id, `${name}: ${error.message}`);
242
+ continue;
243
+ }
244
+ if (!title) {
245
+ if (routes.length > 0)
246
+ report(widget.id, `${name} routes "recordTitle" but takes no titleFromRecord, so it announces nothing.`);
247
+ continue;
248
+ }
249
+ if (widget.config.source == null)
250
+ report(widget.id, `${name} takes its title from a record it never reads: titleFromRecord needs a source.`);
251
+ if (routes.length === 0)
252
+ report(widget.id, `${name} takes a titleFromRecord that goes nowhere: no route on "recordTitle".`);
253
+ const formId = String(widget.config.formId);
254
+ const descriptor = isForm ? forms?.get(formId)?.descriptor : undefined;
255
+ if (descriptor && !descriptor.fields.some((field) => field.key === title.field)) {
256
+ report(widget.id, `${name} takes its title from "${title.field}", which is no field of "${formId}".`);
257
+ }
258
+ for (const route of routes) {
259
+ if (route.action !== "change" || route.valueType !== "string") {
260
+ report(widget.id, `${name} route "${String(route.routeKey)}" must carry "recordTitle" as change/string.`);
261
+ continue;
262
+ }
263
+ // An Overlay of this tree hears it on its `title` input; another receiver is the Page's choice.
264
+ const overlay = overlaysById.get(String(route.receiver));
265
+ const keys = ["receiver", "scope", "channel", "action", "valueType"];
266
+ if (overlay && !readRoutes(overlay.config, "listens").some((listen) => listen.capabilityId === "title" && keys.every((key) => listen[key] === route[key]))) {
267
+ report(widget.id, `${name} sends its title to Overlay "${overlay.id}", which has no "title" route on ${String(route.scope)} ${String(route.channel)}/change.`);
268
+ }
269
+ }
270
+ }
271
+ }
@@ -0,0 +1,7 @@
1
+ /** The sentence's rule: `%1` exactly once and no other placeholder, or the reason it is refused. */
2
+ export declare function checkPhiRecordTitleTemplate(source: string): string | null;
3
+ /**
4
+ * The sentence with the record's value in it, or "" where the record has no text or number there: an
5
+ * empty title is the Overlay's own. The value goes in as it is -- never translated, `$` and `%1` included.
6
+ */
7
+ export declare function fillPhiRecordTitle(template: string, value: unknown): string;
@@ -0,0 +1,25 @@
1
+ /*
2
+ * A dialog named by the record it shows ("Gallery: Private Cloud", "Terms: @acme/books:pro"): a sentence
3
+ * with `%1` once, and the value of one field of the record standing there. The record Form and the record
4
+ * Widget both announce it on `recordTitle` after every read (FORMS.md, TABLES.md); they differ only in
5
+ * where the sentence comes from -- a Form text, or the record Widget's own placement -- so the two rules
6
+ * they share are here.
7
+ */
8
+ /** The sentence's rule: `%1` exactly once and no other placeholder, or the reason it is refused. */
9
+ export function checkPhiRecordTitleTemplate(source) {
10
+ const placeholders = source.match(/%\d+/gu) ?? [];
11
+ return placeholders.length === 1 && placeholders[0] === "%1"
12
+ ? null
13
+ : `must hold %1 exactly once and no other placeholder: ${JSON.stringify(source)}.`;
14
+ }
15
+ /**
16
+ * The sentence with the record's value in it, or "" where the record has no text or number there: an
17
+ * empty title is the Overlay's own. The value goes in as it is -- never translated, `$` and `%1` included.
18
+ */
19
+ export function fillPhiRecordTitle(template, value) {
20
+ const text = typeof value === "string"
21
+ ? value.trim()
22
+ : typeof value === "number" && Number.isFinite(value) ? String(value) : "";
23
+ // A replacer, so a `$` in the value stays the value.
24
+ return text ? template.replace("%1", () => text) : "";
25
+ }
@@ -0,0 +1,15 @@
1
+ import type { PhiRecordWidgetConfig, PhiRecordWidgetTitleFromRecord } from "../types/record-widget";
2
+ import type { PhiTableProviderResourceDescriptor } from "../types/table-widget";
3
+ /**
4
+ * The placement's `titleFromRecord`, or null where it states none. Strict, as the Form's: no field, or a
5
+ * sentence without exactly one `%1`, is refused rather than read as no title.
6
+ */
7
+ export declare function readPhiRecordWidgetTitleFromRecord(value: unknown): PhiRecordWidgetTitleFromRecord | null;
8
+ /**
9
+ * What the record Widget's actions ask of its resource, as the errors it shows instead of the record --
10
+ * the Table's binding check (`validatePhiTableWidgetBinding`) for the one scope a record has. Each action
11
+ * is the resource's, of scope `row`, named once, and drawn as the danger a destructive one is. A
12
+ * confirmation the resource requires is not asked for here: the record on screen, named in the dialog's
13
+ * title, and the press beside it are that confirmation, and a `confirm` would ask a second time.
14
+ */
15
+ export declare function validatePhiRecordWidgetBinding(config: Pick<PhiRecordWidgetConfig, "actions">, resource: Pick<PhiTableProviderResourceDescriptor, "resourceKey" | "actions">): string[];
@@ -0,0 +1,57 @@
1
+ import { isPhiRecord } from "./is-record";
2
+ import { checkPhiRecordTitleTemplate } from "./record-title";
3
+ /*
4
+ * The record Widget's two readers that the descriptor compiler and the Widget share: its title from the
5
+ * record and its actions against the resource (TABLES.md, "The record Widget"). Apart from
6
+ * `types/record-widget.ts`, so the type stays a type for everything that only names it.
7
+ */
8
+ /**
9
+ * The placement's `titleFromRecord`, or null where it states none. Strict, as the Form's: no field, or a
10
+ * sentence without exactly one `%1`, is refused rather than read as no title.
11
+ */
12
+ export function readPhiRecordWidgetTitleFromRecord(value) {
13
+ if (value == null)
14
+ return null;
15
+ if (!isPhiRecord(value))
16
+ throw new Error(`Record titleFromRecord ${JSON.stringify(value)} is no { template, field }.`);
17
+ const field = typeof value.field === "string" ? value.field.trim() : "";
18
+ if (!field)
19
+ throw new Error("Record titleFromRecord.field must name the record field the title takes its value from.");
20
+ const template = typeof value.template === "string" ? value.template.trim() : "";
21
+ if (!template)
22
+ throw new Error("Record titleFromRecord.template must be the sentence the title is made of.");
23
+ const templateError = checkPhiRecordTitleTemplate(template);
24
+ if (templateError)
25
+ throw new Error(`Record titleFromRecord.template ${templateError}`);
26
+ return { template, field };
27
+ }
28
+ /**
29
+ * What the record Widget's actions ask of its resource, as the errors it shows instead of the record --
30
+ * the Table's binding check (`validatePhiTableWidgetBinding`) for the one scope a record has. Each action
31
+ * is the resource's, of scope `row`, named once, and drawn as the danger a destructive one is. A
32
+ * confirmation the resource requires is not asked for here: the record on screen, named in the dialog's
33
+ * title, and the press beside it are that confirmation, and a `confirm` would ask a second time.
34
+ */
35
+ export function validatePhiRecordWidgetBinding(config, resource) {
36
+ const errors = [];
37
+ const declared = new Map(resource.actions?.map((action) => [action.key, action]) ?? []);
38
+ const seen = new Set();
39
+ for (const action of config.actions) {
40
+ if (seen.has(action.key)) {
41
+ errors.push(`Record action "${action.key}" is configured more than once.`);
42
+ continue;
43
+ }
44
+ seen.add(action.key);
45
+ const capability = declared.get(action.key);
46
+ if (!capability) {
47
+ errors.push(`Record action "${action.key}" is not declared by resource "${resource.resourceKey}".`);
48
+ }
49
+ else if (capability.scope !== "row") {
50
+ errors.push(`Record action "${action.key}" cannot run on a record: its scope is "${capability.scope}".`);
51
+ }
52
+ else if (capability.intent === "destructive" && action.mode !== "danger") {
53
+ errors.push(`Destructive Record action "${action.key}" requires danger presentation.`);
54
+ }
55
+ }
56
+ return errors;
57
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@phis/ui",
3
- "version": "0.7.5",
3
+ "version": "0.7.7",
4
4
  "license": "Apache-2.0",
5
5
  "publishConfig": {
6
6
  "access": "public"
@@ -521,7 +521,7 @@
521
521
  "@lexical/rich-text": "0.50.0",
522
522
  "@lexical/selection": "0.50.0",
523
523
  "@lexical/utils": "0.50.0",
524
- "@phis/contracts": "^0.8.1",
524
+ "@phis/contracts": "^0.8.9",
525
525
  "dayjs": "^1.11.23",
526
526
  "dom-serializer": "^2.0.0",
527
527
  "htmlparser2": "^10.1.0",
@@ -0,0 +1,7 @@
1
+ export declare const PHI_ACCOUNTING_RUNTIME_DATA_PROVIDER_CLIENT_DEFINITIONS: readonly [{
2
+ readonly key: `${string}/${string}`;
3
+ readonly ownerModuleId: "@phis/ui/modules/accounting";
4
+ readonly loadLive: () => Promise<import("react").ComponentType<{
5
+ children: import("react").ReactNode;
6
+ }>>;
7
+ }];
@@ -0,0 +1,9 @@
1
+ "use client";
2
+ import { PHI_ACCOUNTING_PRODUCTS_DATA_PROVIDER_KEY, PHI_ACCOUNTING_RUNTIME_MODULE_ID } from "./ids";
3
+ export const PHI_ACCOUNTING_RUNTIME_DATA_PROVIDER_CLIENT_DEFINITIONS = [
4
+ {
5
+ key: PHI_ACCOUNTING_PRODUCTS_DATA_PROVIDER_KEY,
6
+ ownerModuleId: PHI_ACCOUNTING_RUNTIME_MODULE_ID,
7
+ loadLive: async () => (await import("./services/products-table")).PhiAccountingProductsTableProviderClient,
8
+ },
9
+ ];
@@ -0,0 +1,63 @@
1
+ import type { PhiTableProviderFieldDefinition } from "../../../types/table-widget";
2
+ /**
3
+ * The Site's product directory (phis-server SERVER_ADDONS.md, `products:v1`), as the operator
4
+ * administers it: every product of every supplier Add-on, in every state.
5
+ *
6
+ * `live` and `authoringMode: "none"`: the Builder has no business reading a Site's products while somebody
7
+ * composes a Page. The rows come from `GET /api/site/products` and the three acts go to
8
+ * `POST /api/site/products/{id}/release|lock|unlock`, behind Core's Accounting guard; Core refuses them to
9
+ * anybody else whatever a Table offers. Nothing a supplier says of its product -- title, summary, picture
10
+ * -- is edited here: that stays the supplier's.
11
+ */
12
+ export declare const PHI_ACCOUNTING_RUNTIME_DATA_PROVIDER_DESCRIPTORS: {
13
+ key: `${string}/${string}`;
14
+ ownerModuleId: "@phis/ui/modules/accounting";
15
+ kind: "table";
16
+ executionMode: "live";
17
+ authoringMode: "none";
18
+ title: string;
19
+ description: string;
20
+ resources: {
21
+ resourceKey: string;
22
+ title: string;
23
+ rowIdentityPath: string;
24
+ fields: PhiTableProviderFieldDefinition[];
25
+ query: {
26
+ search: true;
27
+ filterFields: string[];
28
+ sorting: "none";
29
+ pagination: "offset";
30
+ total: true;
31
+ };
32
+ recordRead: true;
33
+ actions: ({
34
+ key: string;
35
+ title: string;
36
+ scope: "row";
37
+ intent: "write";
38
+ confirmation: "required";
39
+ disabledWhen: {
40
+ match: "any";
41
+ conditions: {
42
+ source: "row";
43
+ valuePath: string;
44
+ operator: "falsy";
45
+ }[];
46
+ };
47
+ } | {
48
+ key: string;
49
+ title: string;
50
+ scope: "row";
51
+ intent: "destructive";
52
+ confirmation: "required";
53
+ disabledWhen: {
54
+ match: "any";
55
+ conditions: {
56
+ source: "row";
57
+ valuePath: string;
58
+ operator: "truthy";
59
+ }[];
60
+ };
61
+ })[];
62
+ }[];
63
+ }[];
@@ -0,0 +1,127 @@
1
+ import { PHI_ACCOUNTING_PRODUCTS_DATA_PROVIDER_KEY, PHI_ACCOUNTING_PRODUCTS_RESOURCE_KEY, PHI_ACCOUNTING_RUNTIME_MODULE_ID, } from "./ids";
2
+ const SALE_OPTIONS = [
3
+ { value: "own", label: "Own" },
4
+ { value: "referral", label: "Referral" },
5
+ { value: "payout", label: "Payout" },
6
+ ];
7
+ /**
8
+ * The terms the operator releases (`PhisProductReleasedTerms`), once as they are in force and once as
9
+ * they wait for the release, so a record can set the two side by side. A publisher's product never
10
+ * released has nothing in force yet; the Site's own has nothing waiting.
11
+ */
12
+ function termFields(prefix, title) {
13
+ return [
14
+ { key: `${prefix}Sale`, title: `Sale (${title})`, type: "enum", options: SALE_OPTIONS },
15
+ { key: `${prefix}ReferralUrl`, title: `Referral address (${title})`, type: "string" },
16
+ { key: `${prefix}Free`, title: `Free (${title})`, type: "boolean" },
17
+ { key: `${prefix}AccountRequired`, title: `Account required (${title})`, type: "boolean" },
18
+ { key: `${prefix}Parts`, title: `Bundle parts (${title})`, type: "json" },
19
+ ];
20
+ }
21
+ /**
22
+ * The Site's product directory (phis-server SERVER_ADDONS.md, `products:v1`), as the operator
23
+ * administers it: every product of every supplier Add-on, in every state.
24
+ *
25
+ * `live` and `authoringMode: "none"`: the Builder has no business reading a Site's products while somebody
26
+ * composes a Page. The rows come from `GET /api/site/products` and the three acts go to
27
+ * `POST /api/site/products/{id}/release|lock|unlock`, behind Core's Accounting guard; Core refuses them to
28
+ * anybody else whatever a Table offers. Nothing a supplier says of its product -- title, summary, picture
29
+ * -- is edited here: that stays the supplier's.
30
+ */
31
+ export const PHI_ACCOUNTING_RUNTIME_DATA_PROVIDER_DESCRIPTORS = [
32
+ {
33
+ key: PHI_ACCOUNTING_PRODUCTS_DATA_PROVIDER_KEY,
34
+ ownerModuleId: PHI_ACCOUNTING_RUNTIME_MODULE_ID,
35
+ kind: "table",
36
+ executionMode: "live",
37
+ authoringMode: "none",
38
+ title: "Products",
39
+ description: "The Site's product directory: every supplier's products, their terms and their state.",
40
+ resources: [
41
+ {
42
+ resourceKey: PHI_ACCOUNTING_PRODUCTS_RESOURCE_KEY,
43
+ title: "Products",
44
+ rowIdentityPath: "id",
45
+ fields: [
46
+ { key: "id", title: "ID", type: "string", required: true },
47
+ { key: "title", title: "Title", type: "string" },
48
+ { key: "summary", title: "Summary", type: "string" },
49
+ { key: "supplier", title: "Supplier", type: "string" },
50
+ { key: "publisher", title: "Publisher", type: "string" },
51
+ { key: "type", title: "Kind", type: "string" },
52
+ {
53
+ key: "state",
54
+ title: "State",
55
+ type: "enum",
56
+ options: [
57
+ { value: "draft", label: "Draft" },
58
+ { value: "active", label: "Active" },
59
+ { value: "withdrawn", label: "Withdrawn" },
60
+ { value: "locked", label: "Locked" },
61
+ ],
62
+ },
63
+ // The state as a mark, for the two acts that each apply to one side of it.
64
+ { key: "locked", title: "Locked", type: "boolean" },
65
+ { key: "sale", title: "Sale", type: "enum", options: SALE_OPTIONS },
66
+ { key: "referralUrl", title: "Referral address", type: "string" },
67
+ { key: "free", title: "Free", type: "boolean" },
68
+ { key: "accountRequired", title: "Account required", type: "boolean" },
69
+ { key: "counted", title: "Counted", type: "boolean" },
70
+ { key: "parts", title: "Bundle parts", type: "json" },
71
+ { key: "partCount", title: "Bundle parts", type: "number" },
72
+ { key: "released", title: "Released", type: "boolean" },
73
+ // Never released, or released with terms pending: what the release acts on.
74
+ { key: "awaitingRelease", title: "Terms waiting for release", type: "boolean" },
75
+ ...termFields("inForce", "in force"),
76
+ ...termFields("pending", "waiting for release"),
77
+ { key: "imagePath", title: "Picture", type: "string" },
78
+ { key: "iconPath", title: "Icon", type: "string" },
79
+ // The same two as the server's small `icon` variant, ready for a line of the list.
80
+ { key: "imageListPath", title: "Picture (list)", type: "string" },
81
+ { key: "iconListPath", title: "Icon (list)", type: "string" },
82
+ { key: "version", title: "Version", type: "number" },
83
+ ],
84
+ query: {
85
+ search: true,
86
+ filterFields: ["supplier", "state", "pendingTerms"],
87
+ sorting: "none",
88
+ pagination: "offset",
89
+ total: true,
90
+ },
91
+ recordRead: true,
92
+ actions: [
93
+ {
94
+ key: "release",
95
+ title: "Release terms",
96
+ scope: "row",
97
+ intent: "write",
98
+ confirmation: "required",
99
+ disabledWhen: { match: "any", conditions: [
100
+ { source: "row", valuePath: "awaitingRelease", operator: "falsy" },
101
+ ] },
102
+ },
103
+ {
104
+ key: "lock",
105
+ title: "Lock",
106
+ scope: "row",
107
+ intent: "destructive",
108
+ confirmation: "required",
109
+ disabledWhen: { match: "any", conditions: [
110
+ { source: "row", valuePath: "locked", operator: "truthy" },
111
+ ] },
112
+ },
113
+ {
114
+ key: "unlock",
115
+ title: "Unlock",
116
+ scope: "row",
117
+ intent: "write",
118
+ confirmation: "required",
119
+ disabledWhen: { match: "any", conditions: [
120
+ { source: "row", valuePath: "locked", operator: "falsy" },
121
+ ] },
122
+ },
123
+ ],
124
+ },
125
+ ],
126
+ },
127
+ ];
@@ -1,10 +1,62 @@
1
1
  export declare const PHI_ACCOUNTING_RUNTIME_MODULE_DEFINITION: Omit<{
2
- area: "accounting";
3
- moduleId: "@phis/ui/modules/accounting";
4
2
  serverBinding: import("../../../types").PhiRuntimeModuleServerBinding;
5
3
  description: string;
6
4
  category: "foundation";
7
5
  icon: string;
6
+ dataProviders: {
7
+ key: `${string}/${string}`;
8
+ ownerModuleId: "@phis/ui/modules/accounting";
9
+ kind: "table";
10
+ executionMode: "live";
11
+ authoringMode: "none";
12
+ title: string;
13
+ description: string;
14
+ resources: {
15
+ resourceKey: string;
16
+ title: string;
17
+ rowIdentityPath: string;
18
+ fields: import("../../../types").PhiTableProviderFieldDefinition[];
19
+ query: {
20
+ search: true;
21
+ filterFields: string[];
22
+ sorting: "none";
23
+ pagination: "offset";
24
+ total: true;
25
+ };
26
+ recordRead: true;
27
+ actions: ({
28
+ key: string;
29
+ title: string;
30
+ scope: "row";
31
+ intent: "write";
32
+ confirmation: "required";
33
+ disabledWhen: {
34
+ match: "any";
35
+ conditions: {
36
+ source: "row";
37
+ valuePath: string;
38
+ operator: "falsy";
39
+ }[];
40
+ };
41
+ } | {
42
+ key: string;
43
+ title: string;
44
+ scope: "row";
45
+ intent: "destructive";
46
+ confirmation: "required";
47
+ disabledWhen: {
48
+ match: "any";
49
+ conditions: {
50
+ source: "row";
51
+ valuePath: string;
52
+ operator: "truthy";
53
+ }[];
54
+ };
55
+ })[];
56
+ }[];
57
+ }[];
58
+ moduleId: "@phis/ui/modules/accounting";
59
+ area: "accounting";
8
60
  }, "area"> & {
9
61
  kind: "module";
10
62
  eligibleAreas: readonly ["public" | "app" | "admin" | "builder" | "editor" | "accounting"];
@@ -1,11 +1,13 @@
1
1
  import { definePhiAreaBaseRuntimeModuleDefinition } from "../area-base-definition";
2
- import { PHI_ACCOUNTING_RUNTIME_MODULE_ID } from "./ids";
2
+ import { PHI_ACCOUNTING_RUNTIME_MODULE_IDENTITY } from "./ids";
3
+ import { PHI_ACCOUNTING_RUNTIME_DATA_PROVIDER_DESCRIPTORS } from "./data-providers";
3
4
  import { PHI_CORE_SERVER_BINDING, } from "../../../types/server-capabilities";
4
5
  export const PHI_ACCOUNTING_RUNTIME_MODULE_DEFINITION = definePhiAreaBaseRuntimeModuleDefinition({
5
6
  area: "accounting",
6
- moduleId: PHI_ACCOUNTING_RUNTIME_MODULE_ID,
7
+ ...PHI_ACCOUNTING_RUNTIME_MODULE_IDENTITY,
7
8
  serverBinding: PHI_CORE_SERVER_BINDING,
8
- description: "Locked Accounting Area shell, navigation surface, and root route.",
9
+ description: "Locked Accounting Area shell, navigation surface, root route, and the Site's product directory.",
9
10
  category: "foundation",
10
11
  icon: "antd:profile",
12
+ dataProviders: PHI_ACCOUNTING_RUNTIME_DATA_PROVIDER_DESCRIPTORS,
11
13
  });
@@ -1 +1,21 @@
1
1
  export declare const PHI_ACCOUNTING_RUNTIME_MODULE_ID: "@phis/ui/modules/accounting";
2
+ /**
3
+ * The Module's identity as its Label Sets inherit it (`definePhiRuntimeModuleLabelSet`): the id and,
4
+ * where a Module declares one, its source locale. Stated here beside the id and spread into the
5
+ * definition, so a Label Set a tree reads does not import the definition that imports the tree.
6
+ */
7
+ export declare const PHI_ACCOUNTING_RUNTIME_MODULE_IDENTITY: {
8
+ readonly moduleId: "@phis/ui/modules/accounting";
9
+ };
10
+ /**
11
+ * The Site's product directory (phis-server SERVER_ADDONS.md, `products:v1`): every product of every
12
+ * supplier Add-on, as the Site operator administers it. A Page of the Accounting Area itself rather than
13
+ * of a shop, because every supplier's products land in it and it has to work with no shop at all.
14
+ */
15
+ export declare const PHI_ACCOUNTING_PRODUCTS_DATA_PROVIDER_KEY: `${string}/${string}`;
16
+ /** The one resource the directory's Provider answers. */
17
+ export declare const PHI_ACCOUNTING_PRODUCTS_RESOURCE_KEY = "products";
18
+ export declare const PHI_ACCOUNTING_PRODUCTS_PAGE_PRESET_KEY = "accounting-products-page";
19
+ export declare const PHI_ACCOUNTING_PRODUCTS_PAGE_LAYOUT_IDS: Readonly<Record<"layoutTerms" | "layoutTermsFooter", import("@phis/contracts/cms").PhiCmsInstanceId>>;
20
+ export declare const PHI_ACCOUNTING_PRODUCTS_PAGE_OVERLAY_IDS: Readonly<Record<"overlayTerms", import("@phis/contracts/cms").PhiCmsInstanceId>>;
21
+ export declare const PHI_ACCOUNTING_PRODUCTS_PAGE_WIDGET_IDS: Readonly<Record<"widgetTable" | "widgetTerms" | "widgetTermsNote" | "widgetTermsCommands", import("@phis/contracts/cms").PhiCmsInstanceId>>;