@sincpro/web-framework 1.1.0 → 2.1.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 (129) hide show
  1. package/README.md +188 -87
  2. package/dist/core/cache.d.ts +1 -2
  3. package/dist/core/cache.js +8 -5
  4. package/dist/core/explain.d.ts +15 -0
  5. package/dist/core/{transport.js → explain.js} +4 -26
  6. package/dist/core/form.d.ts +1 -1
  7. package/dist/core/form.js +1 -0
  8. package/dist/core/index.d.ts +9 -15
  9. package/dist/core/index.js +8 -14
  10. package/dist/core/list.d.ts +5 -4
  11. package/dist/core/list.js +1 -0
  12. package/dist/core/lookup.d.ts +1 -1
  13. package/dist/core/lookup.js +1 -0
  14. package/dist/core/present.d.ts +1 -0
  15. package/dist/core/present.js +54 -6
  16. package/dist/core/relation.d.ts +1 -1
  17. package/dist/core/relation.js +1 -1
  18. package/dist/core/summary.d.ts +1 -6
  19. package/dist/core/trail.d.ts +1 -1
  20. package/dist/core/trail.js +1 -0
  21. package/dist/errors/index.d.ts +48 -0
  22. package/dist/errors/index.js +56 -0
  23. package/dist/react/context.d.ts +6 -4
  24. package/dist/react/context.js +11 -3
  25. package/dist/react/index.d.ts +2 -0
  26. package/dist/react/index.js +2 -0
  27. package/dist/react/scope.d.ts +1 -1
  28. package/dist/react/scope.js +1 -1
  29. package/dist/react/useCommand.d.ts +1 -1
  30. package/dist/react/useCommand.js +1 -2
  31. package/dist/react/useContextValues.d.ts +15 -0
  32. package/dist/react/useContextValues.js +19 -0
  33. package/dist/react/useGroups.js +2 -2
  34. package/dist/react/useHistory.d.ts +1 -1
  35. package/dist/react/useHistory.js +3 -2
  36. package/dist/react/useListing.d.ts +4 -4
  37. package/dist/react/useListing.js +16 -7
  38. package/dist/react/useLookup.d.ts +1 -1
  39. package/dist/react/useLookup.js +3 -2
  40. package/dist/react/useNameOf.d.ts +1 -1
  41. package/dist/react/useNameOf.js +3 -3
  42. package/dist/react/usePivot.js +2 -2
  43. package/dist/react/useRecord.d.ts +1 -2
  44. package/dist/react/useRecord.js +18 -6
  45. package/dist/react/useRelated.d.ts +1 -1
  46. package/dist/react/useRelated.js +1 -0
  47. package/dist/react/useService.d.ts +38 -0
  48. package/dist/react/useService.js +66 -0
  49. package/dist/react/useSummary.d.ts +1 -1
  50. package/dist/react/useSummary.js +1 -0
  51. package/dist/telemetry/index.d.ts +45 -0
  52. package/dist/telemetry/index.js +55 -0
  53. package/dist/web/Refused.js +1 -1
  54. package/dist/web/index.d.ts +1 -1
  55. package/dist/web/index.js +1 -1
  56. package/dist/web/list/EntityList.d.ts +1 -1
  57. package/dist/web/list/EntityList.js +3 -3
  58. package/dist/web/list/EntitySearchBar.d.ts +2 -1
  59. package/dist/web/list/EntitySearchBar.js +17 -11
  60. package/dist/web/list/presentation.d.ts +1 -1
  61. package/dist/web/list/presentation.js +1 -0
  62. package/dist/web/list/rowCommands.d.ts +1 -1
  63. package/dist/web/list/rowCommands.js +1 -2
  64. package/dist/web/record/CommandButton.d.ts +1 -1
  65. package/dist/web/record/CommandButton.js +1 -0
  66. package/dist/web/record/EntityPicker.d.ts +8 -5
  67. package/dist/web/record/EntityPicker.js +6 -5
  68. package/dist/web/record/EntityTags.d.ts +1 -1
  69. package/dist/web/record/EntityTags.js +1 -0
  70. package/dist/web/record/RelatedList.d.ts +1 -1
  71. package/dist/web/record/RelatedList.js +1 -0
  72. package/dist/web/record/control.d.ts +4 -2
  73. package/dist/web/record/control.js +8 -5
  74. package/dist/web/record/edit.js +21 -1
  75. package/dist/web/record/lines.js +13 -2
  76. package/dist/web/record/opening.d.ts +1 -1
  77. package/dist/web/record/opening.js +1 -0
  78. package/dist/web/record/record.d.ts +12 -2
  79. package/dist/web/record/record.js +10 -2
  80. package/dist/web/workspace/SincproApp.d.ts +9 -20
  81. package/dist/web/workspace/SincproApp.js +17 -4
  82. package/dist/web/workspace/composer.d.ts +1 -2
  83. package/dist/web/workspace/composer.js +2 -2
  84. package/dist/web/workspace/open.d.ts +1 -1
  85. package/dist/web/workspace/open.js +1 -0
  86. package/dist/web/workspace/record.d.ts +60 -13
  87. package/dist/web/workspace/record.js +89 -28
  88. package/dist/web/workspace/workspace.d.ts +1 -1
  89. package/dist/web/workspace/workspace.js +1 -0
  90. package/package.json +45 -15
  91. package/dist/codegen/cli.d.ts +0 -2
  92. package/dist/codegen/cli.js +0 -82
  93. package/dist/codegen/client.d.ts +0 -14
  94. package/dist/codegen/client.js +0 -178
  95. package/dist/codegen/domain.d.ts +0 -14
  96. package/dist/codegen/domain.js +0 -195
  97. package/dist/codegen/entities.d.ts +0 -14
  98. package/dist/codegen/entities.js +0 -158
  99. package/dist/codegen/index.d.ts +0 -11
  100. package/dist/codegen/index.js +0 -9
  101. package/dist/codegen/metamodel.d.ts +0 -89
  102. package/dist/codegen/metamodel.js +0 -1
  103. package/dist/codegen/names.d.ts +0 -40
  104. package/dist/codegen/names.js +0 -114
  105. package/dist/codegen/rest.d.ts +0 -31
  106. package/dist/codegen/rest.js +0 -27
  107. package/dist/core/contract.d.ts +0 -34
  108. package/dist/core/contract.js +0 -41
  109. package/dist/core/discovery.d.ts +0 -47
  110. package/dist/core/discovery.js +0 -68
  111. package/dist/core/entity.d.ts +0 -227
  112. package/dist/core/entity.js +0 -187
  113. package/dist/core/ids.d.ts +0 -17
  114. package/dist/core/ids.js +0 -52
  115. package/dist/core/memory.d.ts +0 -46
  116. package/dist/core/memory.js +0 -108
  117. package/dist/core/meta.d.ts +0 -121
  118. package/dist/core/meta.js +0 -130
  119. package/dist/core/metas.d.ts +0 -17
  120. package/dist/core/metas.js +0 -7
  121. package/dist/core/rest.d.ts +0 -49
  122. package/dist/core/rest.js +0 -143
  123. package/dist/core/retry.d.ts +0 -24
  124. package/dist/core/retry.js +0 -25
  125. package/dist/core/schema.d.ts +0 -39
  126. package/dist/core/schema.js +0 -128
  127. package/dist/core/transport.d.ts +0 -90
  128. package/dist/core/zone.d.ts +0 -27
  129. package/dist/core/zone.js +0 -75
@@ -1,5 +1,5 @@
1
1
  "use client";
2
- import { listRoute } from "../core/entity.js";
2
+ import { listRoute } from "@sincpro/client-framework";
3
3
  import { lookupOf } from "../core/lookup.js";
4
4
  import { useFramework } from "./context.js";
5
5
  import { useEffect, useState } from "react";
@@ -15,7 +15,7 @@ import { useEffect, useState } from "react";
15
15
  * const name = useNameOf(tenants, record.tenant_id) ?? record.tenant_id;
16
16
  */
17
17
  export function useNameOf(entity, id) {
18
- const { transport, metas } = useFramework();
18
+ const { transport, metas, context } = useFramework();
19
19
  const [named, setNamed] = useState(undefined);
20
20
  useEffect(() => {
21
21
  if (entity === undefined || id === "")
@@ -39,6 +39,6 @@ export function useNameOf(entity, id) {
39
39
  })
40
40
  .catch(() => undefined);
41
41
  return () => aborter.abort();
42
- }, [transport, metas, entity, id]);
42
+ }, [transport, metas, entity, id, context]);
43
43
  return named?.id === id ? named.name : undefined;
44
44
  }
@@ -5,7 +5,7 @@ import { useEffect, useState } from "react";
5
5
  /** The most groups an axis answers: a pivot of ten thousand rows is a list. */
6
6
  const MAX_KEYS = 100;
7
7
  export function usePivot(listing, axes) {
8
- const { transport } = useFramework();
8
+ const { transport, context } = useFramework();
9
9
  const [state, setState] = useState({
10
10
  status: "idle",
11
11
  crossed: [],
@@ -53,6 +53,6 @@ export function usePivot(listing, axes) {
53
53
  setState({ status: "failed", crossed: [], columns: [], error });
54
54
  });
55
55
  return () => aborter.abort();
56
- }, [transport, listing.route, question, shape, sums, waiting]);
56
+ }, [transport, listing.route, question, shape, sums, waiting, context]);
57
57
  return { ...state, measures };
58
58
  }
@@ -1,7 +1,6 @@
1
+ import { type Draft, type Entity, type EntityRef } from "@sincpro/client-framework";
1
2
  import type { AnyRecord, Meta } from "@sincpro/criteria";
2
3
  import { type Advice, type FieldState } from "../core/edit.js";
3
- import { type Entity, type EntityRef } from "../core/entity.js";
4
- import { type Draft } from "../core/transport.js";
5
4
  /**
6
5
  * ONE record of an entity, with the definition of its model — read, and edited.
7
6
  *
@@ -1,16 +1,13 @@
1
1
  "use client";
2
+ import { newEntityId, pathFor, retryKeys, startingValuesOf, TransportError, WITH_PARAM, } from "@sincpro/client-framework";
2
3
  import { changesOf, computedLocally, creationOf, defaultsOf, errorsByField, fieldStateOf, lineStatesOf, missingOf, needsPreview, } from "../core/edit.js";
3
- import { pathFor, startingValuesOf, WITH_PARAM, } from "../core/entity.js";
4
- import { newEntityId } from "../core/ids.js";
5
4
  import { linesAnswered } from "../core/lines.js";
6
- import { retryKeys } from "../core/retry.js";
7
- import { TransportError } from "../core/transport.js";
8
5
  import { useFramework } from "./context.js";
9
6
  import { useCallback, useEffect, useMemo, useRef, useState } from "react";
10
7
  /** How long typing has to pause before the server is asked what the record becomes. */
11
8
  const PREVIEW_PAUSE = 300;
12
9
  export function useRecord(entity, opened) {
13
- const { transport, locale, metas } = useFramework();
10
+ const { transport, locale, metas, context } = useFramework();
14
11
  const given = typeof opened === "string" ? opened : (opened.id ?? "");
15
12
  // As written in the reference: a text compares by value, so a new render with the same
16
13
  // reference is not a new start.
@@ -36,6 +33,8 @@ export function useRecord(entity, opened) {
36
33
  const [readFor, setReadFor] = useState(null);
37
34
  const [round, setRound] = useState(0);
38
35
  const [typed, setTyped] = useState({});
36
+ const typedNow = useRef(typed);
37
+ typedNow.current = typed;
39
38
  const [computed, setComputed] = useState({});
40
39
  const [fromServer, setFromServer] = useState({});
41
40
  const [advice, setAdvice] = useState([]);
@@ -139,6 +138,16 @@ export function useRecord(entity, opened) {
139
138
  };
140
139
  }, []);
141
140
  const reload = useCallback(() => setRound((n) => n + 1), []);
141
+ // Another company (the process's context changed): a record with nothing typed reads again;
142
+ // one being edited keeps what was typed — losing it is never the framework's decision.
143
+ const askedIn = useRef(context);
144
+ useEffect(() => {
145
+ if (askedIn.current === context)
146
+ return;
147
+ askedIn.current = context;
148
+ if (Object.keys(typedNow.current).length === 0)
149
+ reload();
150
+ }, [context, reload]);
142
151
  const record = useMemo(() => (state.record ?? {}), [state.record]);
143
152
  const values = useMemo(() => ({ ...record, ...computed, ...typed }), [record, computed, typed]);
144
153
  const changed = useMemo(() => changesOf(record, typed), [record, typed]);
@@ -237,7 +246,10 @@ export function useRecord(entity, opened) {
237
246
  changed,
238
247
  dirty: Object.keys(changed).length > 0,
239
248
  set: (name, value) => {
240
- const next = { ...typed, [name]: value };
249
+ // Over what was typed last, not this render's: two fields set in one gesture (a key and
250
+ // the record held beside it) both land.
251
+ const next = { ...typedNow.current, [name]: value };
252
+ typedNow.current = next;
241
253
  setTyped(next);
242
254
  ask(next, name);
243
255
  },
@@ -1,5 +1,5 @@
1
+ import { type Entity } from "@sincpro/client-framework";
1
2
  import type { AnyRecord, Criteria } from "@sincpro/criteria";
2
- import type { Entity } from "../core/entity.js";
3
3
  import type { Listing, ListingOptions } from "./useListing.js";
4
4
  import type { RecordReading } from "./useRecord.js";
5
5
  /**
@@ -1,4 +1,5 @@
1
1
  "use client";
2
+ import {} from "@sincpro/client-framework";
2
3
  import { useListing } from "./useListing.js";
3
4
  /**
4
5
  * The records a relation of ONE record points to, as a live listing of the related entity.
@@ -0,0 +1,38 @@
1
+ /**
2
+ * What a screen keeps of running one of the application's use cases.
3
+ *
4
+ * `run` answers what the use case answered, or `undefined` when it failed — the failure is in
5
+ * `error`, for the screen to say (`explain`, `Refused`); it never throws at the screen.
6
+ */
7
+ export type ServiceState<A extends unknown[], R> = {
8
+ run: (...args: A) => Promise<R | undefined>;
9
+ /** A run is on its way. */
10
+ busy: boolean;
11
+ /** What the last run answered, until another one starts or `reset`. */
12
+ answer: R | undefined;
13
+ error: unknown;
14
+ reset: () => void;
15
+ };
16
+ /** A use case as a screen runs it: a method of a service, read from its bounded context. */
17
+ type UseCase<A extends unknown[], R> = (...args: A) => R | Promise<R>;
18
+ /**
19
+ * One of the application's use cases, run from a screen.
20
+ *
21
+ * const close = useService(project.Issues.close);
22
+ * <Button disabled={close.busy} onPress={() => close.run({ issue_id })}>Cerrar</Button>
23
+ * {close.error ? <Refused error={close.error} /> : null}
24
+ *
25
+ * Context: all of an application's logic lives in its services (@sincpro/client-framework's
26
+ * `Feature` and `ApplicationService`, reached through their bounded context), traced and reported
27
+ * by its interceptors; what a screen adds is the state of running one — busy, the answer, the
28
+ * failure. Written by hand, that state is the 300-line context every mobile screen repeats; here
29
+ * it is one hook, the same for every use case. The span and the report are the service's: this
30
+ * hook neither opens one nor reports. A bounded context answers the same function every time a
31
+ * method is read, so `project.Issues.close` can be handed as it is.
32
+ *
33
+ * The last run wins: an answer that arrives after a newer run started is dropped, so a slow first
34
+ * click never overwrites the second. A run is never aborted — the server may have done it — but
35
+ * its answer does not land on a screen that left.
36
+ */
37
+ export declare function useService<A extends unknown[], R>(useCase: UseCase<A, R>): ServiceState<A, Awaited<R>>;
38
+ export {};
@@ -0,0 +1,66 @@
1
+ "use client";
2
+ import { useCallback, useEffect, useRef, useState } from "react";
3
+ /**
4
+ * One of the application's use cases, run from a screen.
5
+ *
6
+ * const close = useService(project.Issues.close);
7
+ * <Button disabled={close.busy} onPress={() => close.run({ issue_id })}>Cerrar</Button>
8
+ * {close.error ? <Refused error={close.error} /> : null}
9
+ *
10
+ * Context: all of an application's logic lives in its services (@sincpro/client-framework's
11
+ * `Feature` and `ApplicationService`, reached through their bounded context), traced and reported
12
+ * by its interceptors; what a screen adds is the state of running one — busy, the answer, the
13
+ * failure. Written by hand, that state is the 300-line context every mobile screen repeats; here
14
+ * it is one hook, the same for every use case. The span and the report are the service's: this
15
+ * hook neither opens one nor reports. A bounded context answers the same function every time a
16
+ * method is read, so `project.Issues.close` can be handed as it is.
17
+ *
18
+ * The last run wins: an answer that arrives after a newer run started is dropped, so a slow first
19
+ * click never overwrites the second. A run is never aborted — the server may have done it — but
20
+ * its answer does not land on a screen that left.
21
+ */
22
+ export function useService(useCase) {
23
+ const [busy, setBusy] = useState(false);
24
+ const [answer, setAnswer] = useState(undefined);
25
+ const [error, setError] = useState(null);
26
+ // The use case as the latest render gave it: a run started from an old callback still runs
27
+ // the one the screen holds now (`project.scoped(…)` changed, say).
28
+ const latest = useRef(useCase);
29
+ latest.current = useCase;
30
+ const mounted = useRef(true);
31
+ useEffect(() => {
32
+ mounted.current = true;
33
+ return () => void (mounted.current = false);
34
+ }, []);
35
+ const runs = useRef(0);
36
+ const run = useCallback(async (...args) => {
37
+ const mine = ++runs.current;
38
+ const current = () => mounted.current && runs.current === mine;
39
+ setBusy(true);
40
+ setError(null);
41
+ try {
42
+ const answered = (await latest.current(...args));
43
+ if (current())
44
+ setAnswer(answered);
45
+ return answered;
46
+ }
47
+ catch (failure) {
48
+ if (current()) {
49
+ setAnswer(undefined);
50
+ setError(failure);
51
+ }
52
+ return undefined;
53
+ }
54
+ finally {
55
+ if (current())
56
+ setBusy(false);
57
+ }
58
+ }, []);
59
+ const reset = useCallback(() => {
60
+ runs.current += 1;
61
+ setBusy(false);
62
+ setAnswer(undefined);
63
+ setError(null);
64
+ }, []);
65
+ return { run, busy, answer, error, reset };
66
+ }
@@ -1,5 +1,5 @@
1
+ import { type Entity } from "@sincpro/client-framework";
1
2
  import type { AnyRecord, Meta } from "@sincpro/criteria";
2
- import type { Entity } from "../core/entity.js";
3
3
  import { type RecordSummary } from "../core/summary.js";
4
4
  /**
5
5
  * The summary of any record of an entity, read with the model this application already knows
@@ -1,4 +1,5 @@
1
1
  "use client";
2
+ import {} from "@sincpro/client-framework";
2
3
  import { summaryOf } from "../core/summary.js";
3
4
  import { useFramework } from "./context.js";
4
5
  import { useCallback } from "react";
@@ -0,0 +1,45 @@
1
+ import type { Attributes, Tracer } from "@sincpro/client-framework";
2
+ /**
3
+ * A `Tracer` for the browser, built from the application's own settings: OpenTelemetry's SDK
4
+ * exporting OTLP/HTTP to the endpoint the application names.
5
+ *
6
+ * // the application — domains/common/infrastructure/telemetry.ts
7
+ * import { browserTracer } from "./index.js";
8
+ * const tracer = browserTracer({ endpoint: settings.otlp, service: "forge-web", release });
9
+ * configureProcess({ tracer, reporter }); // entrypoints/main.tsx
10
+ *
11
+ * Context: optional on every count. It is an entry of its own that nothing else in this package
12
+ * imports, and its SDK (`@opentelemetry/sdk-trace`, `@opentelemetry/exporter-trace-otlp-http`,
13
+ * `@opentelemetry/resources`, `@opentelemetry/api`) is an optional peer: an application that
14
+ * does not import it installs nothing and ships nothing. It is also only a convenience — an
15
+ * application that wants its own provider builds it and wraps its tracer with
16
+ * `openTelemetryTracer` (`@sincpro/client-framework/opentelemetry`), or hands any object that
17
+ * fulfils the `Tracer` port.
18
+ *
19
+ * Like sincpro_framework's optional extras, it never breaks what it serves: the SDK loads after
20
+ * the first render (`import()`), and until it is there — or if it is not installed, or fails —
21
+ * use cases run untraced and send no `traceparent`; a failure to load is said once on the
22
+ * console. Nothing is registered globally: the provider is this tracer's own.
23
+ */
24
+ export type BrowserTracerOptions = {
25
+ /** The application's OTLP/HTTP traces endpoint (`https://collector.example.com/v1/traces`). */
26
+ endpoint: string;
27
+ /** `service.name`: what this application is called in the traces. */
28
+ service: string;
29
+ /** `service.version`: the release running. */
30
+ release?: string;
31
+ /** `deployment.environment.name`: `production`, `staging`… */
32
+ environment?: string;
33
+ /** Headers the endpoint asks for. Never a secret: whatever ships to a browser is public. */
34
+ headers?: Readonly<Record<string, string>>;
35
+ /** Fraction of traces kept, 0 to 1. Default 1 — a backoffice is low volume; sample in the
36
+ * Collector, where a trace is decided whole. */
37
+ sampling?: number;
38
+ /** More resource attributes (`tenant.group`, …). */
39
+ attributes?: Attributes;
40
+ };
41
+ export type BrowserTracer = Tracer & {
42
+ /** Sends what is buffered now. Called by itself when the page is hidden or left. */
43
+ flush: () => Promise<void>;
44
+ };
45
+ export declare function browserTracer(options: BrowserTracerOptions): BrowserTracer;
@@ -0,0 +1,55 @@
1
+ const SILENT = {
2
+ traceId: "",
3
+ spanId: "",
4
+ sampled: false,
5
+ set: () => undefined,
6
+ end: () => undefined,
7
+ };
8
+ export function browserTracer(options) {
9
+ let ready = null;
10
+ let flush = () => Promise.resolve();
11
+ void (async () => {
12
+ try {
13
+ const [{ TracerProvider, BatchSpanProcessor, TraceIdRatioBasedSampler, ParentBasedSampler }, { OTLPTraceExporter }, { resourceFromAttributes }, { openTelemetryTracer },] = await Promise.all([
14
+ import("@opentelemetry/sdk-trace"),
15
+ import("@opentelemetry/exporter-trace-otlp-http"),
16
+ import("@opentelemetry/resources"),
17
+ import("@sincpro/client-framework/opentelemetry"),
18
+ ]);
19
+ const exporter = new OTLPTraceExporter({
20
+ url: options.endpoint,
21
+ ...(options.headers ? { headers: { ...options.headers } } : {}),
22
+ });
23
+ const provider = new TracerProvider({
24
+ resource: resourceFromAttributes({
25
+ "service.name": options.service,
26
+ ...(options.release ? { "service.version": options.release } : {}),
27
+ ...(options.environment
28
+ ? { "deployment.environment.name": options.environment }
29
+ : {}),
30
+ ...options.attributes,
31
+ }),
32
+ sampler: new ParentBasedSampler({
33
+ root: new TraceIdRatioBasedSampler(options.sampling ?? 1),
34
+ }),
35
+ spanProcessors: [new BatchSpanProcessor({ exporter })],
36
+ });
37
+ ready = openTelemetryTracer(provider.getTracer(options.service));
38
+ flush = () => provider.forceFlush();
39
+ // A page that is hidden may never come back: what is buffered goes now.
40
+ const leave = () => void flush().catch(() => undefined);
41
+ globalThis.addEventListener?.("pagehide", leave);
42
+ globalThis.document?.addEventListener("visibilitychange", () => {
43
+ if (globalThis.document?.visibilityState === "hidden")
44
+ leave();
45
+ });
46
+ }
47
+ catch (error) {
48
+ console.warn("@sincpro/web-framework/telemetry: tracing is off — OpenTelemetry's SDK did not load", error);
49
+ }
50
+ })();
51
+ return {
52
+ start: (name, startOptions) => ready === null ? SILENT : ready.start(name, startOptions),
53
+ flush: () => flush(),
54
+ };
55
+ }
@@ -1,7 +1,7 @@
1
1
  "use client";
2
2
  import { jsx as _jsx } from "react/jsx-runtime";
3
3
  import { frameworkCopy } from "../core/copy.js";
4
- import { explain } from "../core/transport.js";
4
+ import { explain } from "../core/explain.js";
5
5
  import { Button, Failed } from "@sincpro/web-ui";
6
6
  /**
7
7
  * A failure, said the way the server said it: its title, what happened and what to do —
@@ -23,7 +23,7 @@ export { cardOf, relationOf } from "./record/summary.js";
23
23
  export { Refused } from "./Refused.js";
24
24
  export { entityView, type EntityViewOptions, listView, type ListViewOptions, } from "./workspace/composer.js";
25
25
  export { openIn, openOptions, RECORD_SIZE, RelatedRecord, targetsFor, } from "./workspace/open.js";
26
- export { EntityRecord } from "./workspace/record.js";
26
+ export { EntityRecord, type Stamp, useRecordScreen, } from "./workspace/record.js";
27
27
  export { SincproApp } from "./workspace/SincproApp.js";
28
28
  export { webUiSkin } from "./workspace/skin.js";
29
29
  export { chooserIn, useFollowed, useRecordInWorkspace, } from "./workspace/workspace.js";
package/dist/web/index.js CHANGED
@@ -23,7 +23,7 @@ export { cardOf, relationOf } from "./record/summary.js";
23
23
  export { Refused } from "./Refused.js";
24
24
  export { entityView, listView, } from "./workspace/composer.js";
25
25
  export { openIn, openOptions, RECORD_SIZE, RelatedRecord, targetsFor, } from "./workspace/open.js";
26
- export { EntityRecord } from "./workspace/record.js";
26
+ export { EntityRecord, useRecordScreen, } from "./workspace/record.js";
27
27
  export { SincproApp } from "./workspace/SincproApp.js";
28
28
  export { webUiSkin } from "./workspace/skin.js";
29
29
  export { chooserIn, useFollowed, useRecordInWorkspace, } from "./workspace/workspace.js";
@@ -1,6 +1,6 @@
1
+ import { type CommandBodies } from "@sincpro/client-framework";
1
2
  import { type AnyRecord } from "@sincpro/criteria";
2
3
  import { type WorkspaceApi } from "@sincpro/web-composer";
3
- import { type CommandBodies } from "../../core/entity.js";
4
4
  import type { GroupLevel, NamedFilter } from "../../core/list.js";
5
5
  import type { Listing } from "../../react/useListing.js";
6
6
  import { type RowCommand } from "./rowCommands.js";
@@ -1,11 +1,11 @@
1
1
  "use client";
2
2
  import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
3
+ import { PICK_PARAM, QUERY_PARAM, TRAIL_PARAM, } from "@sincpro/client-framework";
3
4
  import { nameOf } from "@sincpro/criteria";
4
5
  import { RecordLink, useCrumbs } from "@sincpro/web-composer";
5
6
  import { frameworkCopy } from "../../core/copy.js";
6
- import { PICK_PARAM, QUERY_PARAM, TRAIL_PARAM, } from "../../core/entity.js";
7
+ import { explain } from "../../core/explain.js";
7
8
  import { textOf, viewOf } from "../../core/present.js";
8
- import { explain } from "../../core/transport.js";
9
9
  import { useFramework } from "../../react/context.js";
10
10
  import { useGroups } from "../../react/useGroups.js";
11
11
  import { usePivot } from "../../react/usePivot.js";
@@ -312,7 +312,7 @@ export function EntityList({ listing, api, columns: askedColumns, cells, views:
312
312
  error: failure === null
313
313
  ? null
314
314
  : [failure.heading, failure.sentence].filter(Boolean).join(". "),
315
- }, filtered: listing.where !== undefined || listing.text !== "", empty: {
315
+ }, filtered: listing.selection !== undefined || listing.text !== "", empty: {
316
316
  sentence: empty ?? copy.empty,
317
317
  whenFiltered: { sentence: copy.emptyFiltered },
318
318
  }, ...(selection === undefined ? {} : { selection }), ...(opening === undefined ? {} : { onOpen: opening }), ...(peeking === undefined ? {} : { onPeek: peeking, rowClick: "open" }), children: [_jsxs(List.Bar, { children: [trail === undefined || trail.length === 0 ? null : _jsx(List.Crumbs, { crumbs: trail }), embedded ? null : (_jsx(List.Identity, { title: title ?? nameOf(meta, locale), ...(description === undefined ? {} : { description }) })), search === "bar" ? (_jsx(List.Search, { children: _jsx(EntitySearchBar, { listing: listing, filters: filters, groups: groups, ...(asked === "" ? {} : { seed: asked }) }) })) : null, search === "box" && meta?.search != null ? (_jsx(List.Search, { children: _jsx(SearchField, { value: draft, onChange: (next) => {
@@ -15,7 +15,8 @@ import type { Listing } from "../../react/useListing.js";
15
15
  * - «search by name»: facets are the fields the entity's search template names first;
16
16
  * - a typed question («total > 5000») is checked against each field's operators;
17
17
  * - a named filter is one click; the builder writes what nobody foresaw (all/any/not);
18
- * - everything put becomes ONE `where` the SERVER answers (`listing.filter`);
18
+ * - everything put becomes ONE `selection` the SERVER answers (`listing.filter`) — web-ui
19
+ * writes it in criteria's own shape, a filter through a relation included;
19
20
  * - with `groups`, «Group by» offers the fields the model says may split the set, and the
20
21
  * SERVER counts the groups (`useGroups`).
21
22
  *
@@ -4,7 +4,7 @@ import { matching } from "@sincpro/criteria";
4
4
  import { frameworkCopy } from "../../core/copy.js";
5
5
  import { groupableOf } from "./groups.js";
6
6
  import { facetsOf, modelOf } from "./search.js";
7
- import { CriteriaBuilder, describeFilter, Dialog, fillCopy, filterCriteria, GroupingLevels, hasNamed, SearchBar, toggleNamed, useGroupingControl, useUiCopy, whereOf, } from "@sincpro/web-ui";
7
+ import { CriteriaBuilder, describeFilter, Dialog, fillCopy, filterCriteria, GroupingLevels, hasNamed, SearchBar, selectionOf, toggleNamed, useGroupingControl, useUiCopy, } from "@sincpro/web-ui";
8
8
  import { useEffect, useMemo, useRef, useState } from "react";
9
9
  /** No grouping: one constant, so the control is not handed a new array on every render. */
10
10
  const NO_LEVELS = [];
@@ -22,12 +22,12 @@ export function EntitySearchBar({ listing, filters = [], groups, seed, }) {
22
22
  if (seeded.current || seed === undefined || seed === "" || meta?.search == null)
23
23
  return;
24
24
  seeded.current = true;
25
- const where = matching(meta, seed).selection;
26
- if (where === undefined)
25
+ const literal = matching(meta, seed).selection;
26
+ if (literal === undefined)
27
27
  return;
28
- const chip = filterCriteria(where, fillCopy(ui.search.literalChip, { text: seed }));
28
+ const chip = filterCriteria(literal, fillCopy(ui.search.literalChip, { text: seed }));
29
29
  setPut([chip]);
30
- listing.filter(whereOf([chip]));
30
+ listing.filter(selectionOf([chip]));
31
31
  // Once the definition is known; what the person changes afterwards is theirs.
32
32
  // eslint-disable-next-line react-hooks/exhaustive-deps
33
33
  }, [meta, seed]);
@@ -39,8 +39,10 @@ export function EntitySearchBar({ listing, filters = [], groups, seed, }) {
39
39
  return null;
40
40
  const place = (next) => {
41
41
  setPut(next);
42
- listing.filter(whereOf(next));
42
+ listing.filter(selectionOf(next));
43
43
  };
44
+ // What the bar holds, as one selection: what the builder opens on.
45
+ const current = selectionOf(put);
44
46
  return (_jsxs(_Fragment, { children: [_jsx(SearchBar, { facets: facets, model: model, criteria: put, onCriteriaChange: place, placeholder: copy.searchBar, ...(filters.length === 0
45
47
  ? {}
46
48
  : {
@@ -56,7 +58,11 @@ export function EntitySearchBar({ listing, filters = [], groups, seed, }) {
56
58
  onFilterSelect: (id) => {
57
59
  const named = filters.find((one) => one.id === id);
58
60
  if (named !== undefined)
59
- place(toggleNamed(put, { ...named, where: named.where }));
61
+ place(toggleNamed(put, {
62
+ id: named.id,
63
+ label: named.label,
64
+ selection: named.selection,
65
+ }));
60
66
  },
61
67
  }), ...(groups === undefined || groupable.length === 0
62
68
  ? {}
@@ -64,11 +70,11 @@ export function EntitySearchBar({ listing, filters = [], groups, seed, }) {
64
70
  ? {}
65
71
  : {
66
72
  literal: (text) => matching(meta, text).selection ?? null,
67
- }) }), building ? (_jsx(Dialog, { open: true, width: "lg", title: copy.builder, onClose: () => setBuilding(false), children: _jsx(CriteriaBuilder, { model: model, ...(whereOf(put) === undefined && listing.order.length === 0
73
+ }) }), building ? (_jsx(Dialog, { open: true, width: "lg", title: copy.builder, onClose: () => setBuilding(false), children: _jsx(CriteriaBuilder, { model: model, ...(current === undefined && listing.order.length === 0
68
74
  ? {}
69
75
  : {
70
76
  initial: {
71
- ...(whereOf(put) === undefined ? {} : { where: whereOf(put) }),
77
+ ...(current === undefined ? {} : { selection: current }),
72
78
  ...(listing.order.length === 0
73
79
  ? {}
74
80
  : {
@@ -79,9 +85,9 @@ export function EntitySearchBar({ listing, filters = [], groups, seed, }) {
79
85
  }),
80
86
  },
81
87
  }), onApply: (built) => {
82
- place(built?.where === undefined
88
+ place(built?.selection === undefined
83
89
  ? []
84
- : [filterCriteria(built.where, describeFilter(built.where, model))]);
90
+ : [filterCriteria(built.selection, describeFilter(built.selection, model))]);
85
91
  listing.orderBy((built?.order ?? []).map((one) => ({
86
92
  field: one.field,
87
93
  ...(one.descending === true ? { descending: true } : {}),
@@ -1,5 +1,5 @@
1
+ import { type CommandAnswers, type CommandBodies, type Entity } from "@sincpro/client-framework";
1
2
  import type { AnyRecord } from "@sincpro/criteria";
2
- import type { CommandAnswers, CommandBodies, Entity } from "../../core/entity.js";
3
3
  import { type ListDefinition } from "../../core/list.js";
4
4
  import type { PickerItem, RecordCard, RowOf } from "@sincpro/web-ui";
5
5
  import type { ComponentProps } from "react";
@@ -1,3 +1,4 @@
1
+ import {} from "@sincpro/client-framework";
1
2
  import { isList } from "../../core/list.js";
2
3
  /** The entity with how its records look: pass it wherever an entity goes. */
3
4
  export function presented(entity, presentation) {
@@ -1,5 +1,5 @@
1
+ import { type CommandBodies } from "@sincpro/client-framework";
1
2
  import { type AnyRecord, type Expression } from "@sincpro/criteria";
2
- import { type CommandBodies } from "../../core/entity.js";
3
3
  import type { Listing } from "../../react/useListing.js";
4
4
  import type { RowAction } from "@sincpro/web-ui";
5
5
  import type { LucideIcon } from "lucide-react";
@@ -1,7 +1,6 @@
1
1
  "use client";
2
+ import { bodyFor, pathFor, retryKeys } from "@sincpro/client-framework";
2
3
  import { matches } from "@sincpro/criteria";
3
- import { bodyFor, pathFor } from "../../core/entity.js";
4
- import { retryKeys } from "../../core/retry.js";
5
4
  import { useFramework } from "../../react/context.js";
6
5
  import { useCallback, useState } from "react";
7
6
  export function useRowCommands(listing, commands) {
@@ -1,5 +1,5 @@
1
+ import { type CommandAnswers, type CommandBodies, type Entity } from "@sincpro/client-framework";
1
2
  import type { AnyRecord } from "@sincpro/criteria";
2
- import type { CommandAnswers, CommandBodies, Entity } from "../../core/entity.js";
3
3
  import { type AnswerOf } from "../../react/useCommand.js";
4
4
  /**
5
5
  * An entity's Command as a button.
@@ -1,5 +1,6 @@
1
1
  "use client";
2
2
  import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
3
+ import {} from "@sincpro/client-framework";
3
4
  import { frameworkCopy } from "../../core/copy.js";
4
5
  import { useCommand } from "../../react/useCommand.js";
5
6
  import { Refused } from "../Refused.js";
@@ -1,5 +1,5 @@
1
+ import { type Entity } from "@sincpro/client-framework";
1
2
  import type { AnyRecord, Criteria } from "@sincpro/criteria";
2
- import type { Entity } from "../../core/entity.js";
3
3
  import { type ListDefinition } from "../../core/list.js";
4
4
  import { type OpenTarget } from "@sincpro/web-ui";
5
5
  /**
@@ -32,9 +32,9 @@ import { type OpenTarget } from "@sincpro/web-ui";
32
32
  * way to the server's literal search. The chooser is a table — the columns the list declares,
33
33
  * or `columns` — searched by the entity's literal search on the server.
34
34
  *
35
- * A field that may stay empty offers that as a choice (`none`): «Ninguno», or the screen's own
36
- * word («Sin tenant»), answered as `""`. web-ui's `Picker` has no way to clear a choice, so it
37
- * is the first option, while nothing is typed. `exclude` leaves keys out of the choices — the
35
+ * A field that may stay empty says so with `onClear`: a × beside the chosen name, or the name
36
+ * erased and the field left (web-ui's `Picker onClear`). Where the empty choice has a word of its
37
+ * own («Sin tenant»), `none` also offers it as the first option, answered as `""`. `exclude` leaves keys out of the choices — the
38
38
  * tenants a project is already shared with —, in the picker and its chooser, and the SERVER
39
39
  * leaves them out (`useLookup exclude`).
40
40
  *
@@ -42,7 +42,7 @@ import { type OpenTarget } from "@sincpro/web-ui";
42
42
  * <EntityPicker entity={activeCustomers} columns={["name", "tax_id", "city"]} … />
43
43
  * <EntityPicker entity={tenants} none="Sin tenant" exclude={sharedWith} … />
44
44
  */
45
- export declare function EntityPicker<T extends AnyRecord>({ entity, value, onChange, onOpen, openTargets, onBrowseAll, ownChooser, criteria, columns, browse, none, exclude, placeholder, disabled, "aria-label": ariaLabel, }: {
45
+ export declare function EntityPicker<T extends AnyRecord>({ entity, value, onChange, onOpen, openTargets, onBrowseAll, ownChooser, criteria, columns, browse, none, onClear, exclude, placeholder, disabled, "aria-label": ariaLabel, }: {
46
46
  /** What is chosen from: an entity, or a named list of it (its cut, columns and title). */
47
47
  entity: Entity<T> | ListDefinition<T>;
48
48
  /** The chooser's columns. Without it, the named list's, or every scalar field. */
@@ -54,6 +54,9 @@ export declare function EntityPicker<T extends AnyRecord>({ entity, value, onCha
54
54
  /** The field may stay empty: a first choice that answers `""` — `true` says «Ninguno», a
55
55
  * text is the screen's own word for it. */
56
56
  none?: boolean | string;
57
+ /** The choice can be removed: a × beside it, and erasing the name and leaving the field
58
+ * (web-ui's `Picker onClear`). A field that is not required passes it. */
59
+ onClear?: () => void;
57
60
  /** Keys never offered — those already chosen elsewhere. Left out by the server. */
58
61
  exclude?: readonly string[];
59
62
  value?: string;
@@ -1,5 +1,6 @@
1
1
  "use client";
2
2
  import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
3
+ import {} from "@sincpro/client-framework";
3
4
  import { nameOf } from "@sincpro/criteria";
4
5
  import { frameworkCopy } from "../../core/copy.js";
5
6
  import { isList } from "../../core/list.js";
@@ -42,9 +43,9 @@ import { useState } from "react";
42
43
  * way to the server's literal search. The chooser is a table — the columns the list declares,
43
44
  * or `columns` — searched by the entity's literal search on the server.
44
45
  *
45
- * A field that may stay empty offers that as a choice (`none`): «Ninguno», or the screen's own
46
- * word («Sin tenant»), answered as `""`. web-ui's `Picker` has no way to clear a choice, so it
47
- * is the first option, while nothing is typed. `exclude` leaves keys out of the choices — the
46
+ * A field that may stay empty says so with `onClear`: a × beside the chosen name, or the name
47
+ * erased and the field left (web-ui's `Picker onClear`). Where the empty choice has a word of its
48
+ * own («Sin tenant»), `none` also offers it as the first option, answered as `""`. `exclude` leaves keys out of the choices — the
48
49
  * tenants a project is already shared with —, in the picker and its chooser, and the SERVER
49
50
  * leaves them out (`useLookup exclude`).
50
51
  *
@@ -52,7 +53,7 @@ import { useState } from "react";
52
53
  * <EntityPicker entity={activeCustomers} columns={["name", "tax_id", "city"]} … />
53
54
  * <EntityPicker entity={tenants} none="Sin tenant" exclude={sharedWith} … />
54
55
  */
55
- export function EntityPicker({ entity, value, onChange, onOpen, openTargets, onBrowseAll, ownChooser = false, criteria, columns, browse = true, none, exclude, placeholder, disabled, "aria-label": ariaLabel, }) {
56
+ export function EntityPicker({ entity, value, onChange, onOpen, openTargets, onBrowseAll, ownChooser = false, criteria, columns, browse = true, none, onClear, exclude, placeholder, disabled, "aria-label": ariaLabel, }) {
56
57
  const base = isList(entity) ? entity.entity : entity;
57
58
  const { metas } = useFramework();
58
59
  const opening = useRecordOpening();
@@ -100,7 +101,7 @@ export function EntityPicker({ entity, value, onChange, onOpen, openTargets, onB
100
101
  : look(lookup.chosen.record).name) ?? lookup.chosen.label,
101
102
  }), onChange: (id) => onChange(id, lookup.options.find((one) => one.id === id)?.record), ...(lookup.searchable ? { onSearch: lookup.search } : {}),
102
103
  // «Loading» only before there is anything: refining keeps the ten on screen.
103
- loading: lookup.loading && lookup.options.length === 0, ...(opens === undefined || value === "" ? {} : { onOpen: opens }), ...(targets === undefined ? {} : { openTargets: targets }), onBrowseAll: browseAll, ...(placeholder === undefined ? {} : { placeholder }), ...(disabled === undefined ? {} : { disabled }), ...(ariaLabel === undefined ? {} : { "aria-label": ariaLabel }) }));
104
+ loading: lookup.loading && lookup.options.length === 0, ...(onClear === undefined || disabled === true ? {} : { onClear }), ...(opens === undefined || value === "" ? {} : { onOpen: opens }), ...(targets === undefined ? {} : { openTargets: targets }), onBrowseAll: browseAll, ...(placeholder === undefined ? {} : { placeholder }), ...(disabled === undefined ? {} : { disabled }), ...(ariaLabel === undefined ? {} : { "aria-label": ariaLabel }) }));
104
105
  return (_jsxs(_Fragment, { children: [browse ? (_jsxs("span", { className: "flex min-w-0 items-start gap-1", children: [_jsx("span", { className: "min-w-0 flex-1", children: picker }), _jsx(IconButton, { icon: TextSearch, label: frameworkCopy().picker.browse, onClick: () => browseAll(lookup.text), ...(disabled === undefined ? {} : { disabled }) })] })) : (picker), choosing ? (_jsx(Chooser, { entity: entity, ...(columns === undefined ? {} : { columns }), ...(scope === undefined ? {} : { criteria: scope }), onChoose: (id, row) => {
105
106
  onChange(id, row);
106
107
  setChoosing(false);