@sincpro/web-framework 0.1.0 → 0.3.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 (97) hide show
  1. package/README.md +298 -40
  2. package/dist/core/cache.js +2 -2
  3. package/dist/core/copy.d.ts +26 -0
  4. package/dist/core/copy.js +32 -0
  5. package/dist/core/edit.d.ts +48 -3
  6. package/dist/core/edit.js +79 -5
  7. package/dist/core/entity.d.ts +46 -0
  8. package/dist/core/entity.js +57 -0
  9. package/dist/core/form.d.ts +21 -0
  10. package/dist/core/form.js +30 -0
  11. package/dist/core/index.d.ts +11 -3
  12. package/dist/core/index.js +10 -2
  13. package/dist/core/lines.d.ts +53 -0
  14. package/dist/core/lines.js +120 -0
  15. package/dist/core/list.d.ts +64 -0
  16. package/dist/core/list.js +22 -0
  17. package/dist/core/lookup.d.ts +7 -2
  18. package/dist/core/lookup.js +8 -2
  19. package/dist/core/measure.d.ts +16 -0
  20. package/dist/core/measure.js +38 -0
  21. package/dist/core/memory.js +18 -4
  22. package/dist/core/relation.d.ts +28 -0
  23. package/dist/core/relation.js +30 -0
  24. package/dist/core/rest.d.ts +5 -9
  25. package/dist/core/rest.js +25 -7
  26. package/dist/core/retry.d.ts +24 -0
  27. package/dist/core/retry.js +25 -0
  28. package/dist/core/summary.d.ts +50 -0
  29. package/dist/core/summary.js +54 -0
  30. package/dist/core/trail.d.ts +44 -0
  31. package/dist/core/trail.js +70 -0
  32. package/dist/core/transport.d.ts +22 -2
  33. package/dist/react/context.d.ts +20 -1
  34. package/dist/react/context.js +10 -2
  35. package/dist/react/index.d.ts +5 -2
  36. package/dist/react/index.js +4 -1
  37. package/dist/react/useCommand.d.ts +3 -1
  38. package/dist/react/useCommand.js +12 -4
  39. package/dist/react/useGroups.d.ts +52 -0
  40. package/dist/react/useGroups.js +110 -0
  41. package/dist/react/useListing.d.ts +29 -7
  42. package/dist/react/useListing.js +49 -8
  43. package/dist/react/useLookup.d.ts +30 -5
  44. package/dist/react/useLookup.js +56 -3
  45. package/dist/react/usePivot.d.ts +33 -0
  46. package/dist/react/usePivot.js +59 -0
  47. package/dist/react/useRecord.d.ts +28 -9
  48. package/dist/react/useRecord.js +156 -18
  49. package/dist/react/useSummary.d.ts +15 -0
  50. package/dist/react/useSummary.js +22 -0
  51. package/dist/web/index.d.ts +15 -3
  52. package/dist/web/index.js +14 -2
  53. package/dist/web/list/EntityList.d.ts +69 -7
  54. package/dist/web/list/EntityList.js +281 -23
  55. package/dist/web/list/EntitySearchBar.d.ts +16 -8
  56. package/dist/web/list/EntitySearchBar.js +52 -4
  57. package/dist/web/list/columns.d.ts +0 -13
  58. package/dist/web/list/columns.js +20 -1
  59. package/dist/web/list/groups.d.ts +17 -0
  60. package/dist/web/list/groups.js +80 -0
  61. package/dist/web/list/openIn.d.ts +41 -0
  62. package/dist/web/list/openIn.js +55 -0
  63. package/dist/web/list/pivot.d.ts +23 -0
  64. package/dist/web/list/pivot.js +64 -0
  65. package/dist/web/list/presentation.d.ts +51 -0
  66. package/dist/web/list/presentation.js +20 -0
  67. package/dist/web/list/rowCommands.d.ts +41 -0
  68. package/dist/web/list/rowCommands.js +56 -0
  69. package/dist/web/record/EntityPicker.d.ts +45 -14
  70. package/dist/web/record/EntityPicker.js +64 -20
  71. package/dist/web/record/EntityTags.d.ts +38 -0
  72. package/dist/web/record/EntityTags.js +52 -0
  73. package/dist/web/record/RelatedList.d.ts +8 -1
  74. package/dist/web/record/RelatedList.js +37 -3
  75. package/dist/web/record/control.d.ts +42 -0
  76. package/dist/web/record/control.js +60 -0
  77. package/dist/web/record/edit.d.ts +27 -12
  78. package/dist/web/record/edit.js +92 -25
  79. package/dist/web/record/lines.d.ts +84 -0
  80. package/dist/web/record/lines.js +190 -0
  81. package/dist/web/record/opening.d.ts +34 -0
  82. package/dist/web/record/opening.js +10 -0
  83. package/dist/web/record/summary.d.ts +22 -0
  84. package/dist/web/record/summary.js +63 -0
  85. package/dist/web/workspace/SincproApp.d.ts +4 -1
  86. package/dist/web/workspace/SincproApp.js +2 -2
  87. package/dist/web/workspace/composer.d.ts +27 -4
  88. package/dist/web/workspace/composer.js +75 -7
  89. package/dist/web/workspace/open.d.ts +49 -0
  90. package/dist/web/workspace/open.js +51 -0
  91. package/dist/web/workspace/record.d.ts +30 -0
  92. package/dist/web/workspace/record.js +83 -0
  93. package/dist/web/workspace/skin.d.ts +0 -9
  94. package/dist/web/workspace/skin.js +25 -13
  95. package/dist/web/workspace/workspace.d.ts +33 -3
  96. package/dist/web/workspace/workspace.js +63 -4
  97. package/package.json +9 -9
@@ -1,5 +1,6 @@
1
- import type { AnyRecord } from "@sincpro/criteria";
2
- import type { WorkspaceApi } from "@sincpro/web-composer";
1
+ import { type AnyRecord } from "@sincpro/criteria";
2
+ import { type WorkspaceApi } from "@sincpro/web-composer";
3
+ import type { Entity } from "../../core/entity.js";
3
4
  import type { RecordReading } from "../../react/useRecord.js";
4
5
  /**
5
6
  * A record told to the workspace it is open in: its real name and whether it holds unsaved work.
@@ -10,7 +11,36 @@ import type { RecordReading } from "../../react/useRecord.js";
10
11
  * away what was typed. The record already knows both (its `display`, its `edit.dirty`), so the
11
12
  * screen only has to connect them — one line.
12
13
  *
13
- * const invoice = useRecord(invoices, resource.id);
14
+ * A NEW record (opened with `entity.newRef()`) reads «Facturas · nuevo» until it exists; the
15
+ * moment its create answers, the surface is REPLACED by the record it became (`api.replace`):
16
+ * no crumb leads back to an empty form, and the window, peek or page it was in stays. Opened
17
+ * to ANSWER (`api.pick(entity.newRef(…))` — «Agregar» on a record's one2many), it answers the
18
+ * record it became instead, and the surface closes: whoever asked reads it again.
19
+ *
20
+ * const invoice = useRecord(invoices, resource);
14
21
  * useRecordInWorkspace(api, invoice);
15
22
  */
16
23
  export declare function useRecordInWorkspace<T extends AnyRecord>(api: WorkspaceApi, record: RecordReading<T>): void;
24
+ /**
25
+ * «Browse everything» of an `EntityPicker` as the composer's chooser: the entity's own list
26
+ * opens in a window and the row clicked there answers the field.
27
+ *
28
+ * <EntityPicker entity={customers} onChange={set} onBrowseAll={chooserIn(api, customers, set)} />
29
+ */
30
+ export declare function chooserIn<T extends AnyRecord>(api: WorkspaceApi, entity: Entity<T>, onChange: (id: string) => void, options?: Parameters<WorkspaceApi["pick"]>[2]): (query?: unknown) => void;
31
+ /**
32
+ * The record of an entity the person is on right now — what a detail panel beside a list
33
+ * follows, without knowing the list.
34
+ *
35
+ * Context: a list publishes what is ticked (`api.select`) and the workspace knows what is
36
+ * focused; both are references (`domain:kind/id`). A panel that shows «the invoice I am on»
37
+ * only needs the last one of ITS entity: the last ticked, else the focused record. It redraws
38
+ * when either changes (composer's `useWorkspaceContext`), and is `undefined` when the person is
39
+ * on none — the panel says so.
40
+ *
41
+ * function Detail({ api }: ViewProps) {
42
+ * const id = useFollowed(api, invoices);
43
+ * const invoice = useRecord(invoices, id ?? ""); // or «tick an invoice»
44
+ * }
45
+ */
46
+ export declare function useFollowed<T extends AnyRecord>(api: WorkspaceApi, entity: Entity<T>): string | undefined;
@@ -1,4 +1,7 @@
1
1
  "use client";
2
+ import { nameOf } from "@sincpro/criteria";
3
+ import { useWorkspaceContext, } from "@sincpro/web-composer";
4
+ import { frameworkCopy } from "../../core/copy.js";
2
5
  import { textOf } from "../../core/present.js";
3
6
  import { useEffect } from "react";
4
7
  /**
@@ -10,15 +13,34 @@ import { useEffect } from "react";
10
13
  * away what was typed. The record already knows both (its `display`, its `edit.dirty`), so the
11
14
  * screen only has to connect them — one line.
12
15
  *
13
- * const invoice = useRecord(invoices, resource.id);
16
+ * A NEW record (opened with `entity.newRef()`) reads «Facturas · nuevo» until it exists; the
17
+ * moment its create answers, the surface is REPLACED by the record it became (`api.replace`):
18
+ * no crumb leads back to an empty form, and the window, peek or page it was in stays. Opened
19
+ * to ANSWER (`api.pick(entity.newRef(…))` — «Agregar» on a record's one2many), it answers the
20
+ * record it became instead, and the surface closes: whoever asked reads it again.
21
+ *
22
+ * const invoice = useRecord(invoices, resource);
14
23
  * useRecordInWorkspace(api, invoice);
15
24
  */
16
25
  export function useRecordInWorkspace(api, record) {
17
26
  const display = record.meta?.display || record.meta?.identity || "";
18
- const title = record.status === "ready" && display !== ""
19
- ? textOf(record.meta, display, record.record[display], record.locale)
20
- : null;
27
+ const title = record.isNew
28
+ ? newTitle(record.meta, record.locale)
29
+ : record.status === "ready" && display !== ""
30
+ ? textOf(record.meta, display, record.record[display], record.locale)
31
+ : null;
21
32
  const dirty = record.edit.dirty;
33
+ const opened = api.self.id ?? "";
34
+ const { entity, id } = record;
35
+ // Created here: show what it became in place of the form — or hand it to whoever asked.
36
+ useEffect(() => {
37
+ if (opened !== "" || id === "")
38
+ return;
39
+ if (api.choosing === null)
40
+ api.replace(entity.ref(id));
41
+ else
42
+ api.answer(entity.ref(id));
43
+ }, [api, opened, entity, id]);
22
44
  useEffect(() => {
23
45
  api.setTitle(title);
24
46
  }, [api, title]);
@@ -27,3 +49,40 @@ export function useRecordInWorkspace(api, record) {
27
49
  return () => api.setDirty(false);
28
50
  }, [api, dirty]);
29
51
  }
52
+ function newTitle(meta, locale) {
53
+ return frameworkCopy().record.creating(nameOf(meta, locale) || "");
54
+ }
55
+ /**
56
+ * «Browse everything» of an `EntityPicker` as the composer's chooser: the entity's own list
57
+ * opens in a window and the row clicked there answers the field.
58
+ *
59
+ * <EntityPicker entity={customers} onChange={set} onBrowseAll={chooserIn(api, customers, set)} />
60
+ */
61
+ export function chooserIn(api, entity, onChange, options) {
62
+ // A button's `onClick` hands it the event: only a text is what was typed.
63
+ return (query) => api.pick(entity.chooserRef(typeof query === "string" ? query : undefined), (ref) => ref.id === undefined || onChange(ref.id), options);
64
+ }
65
+ /**
66
+ * The record of an entity the person is on right now — what a detail panel beside a list
67
+ * follows, without knowing the list.
68
+ *
69
+ * Context: a list publishes what is ticked (`api.select`) and the workspace knows what is
70
+ * focused; both are references (`domain:kind/id`). A panel that shows «the invoice I am on»
71
+ * only needs the last one of ITS entity: the last ticked, else the focused record. It redraws
72
+ * when either changes (composer's `useWorkspaceContext`), and is `undefined` when the person is
73
+ * on none — the panel says so.
74
+ *
75
+ * function Detail({ api }: ViewProps) {
76
+ * const id = useFollowed(api, invoices);
77
+ * const invoice = useRecord(invoices, id ?? ""); // or «tick an invoice»
78
+ * }
79
+ */
80
+ export function useFollowed(api, entity) {
81
+ const { focused, selection } = useWorkspaceContext(api);
82
+ const mine = (ref) => ref != null &&
83
+ ref.domain === entity.domain &&
84
+ ref.kind === entity.kind &&
85
+ ref.id !== undefined;
86
+ const ticked = [...selection].reverse().find(mine);
87
+ return ticked?.id ?? (mine(focused) ? focused.id : undefined);
88
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sincpro/web-framework",
3
- "version": "0.1.0",
3
+ "version": "0.3.0",
4
4
  "description": "The web client of sincpro_framework: entities, lists and records bound to the metadata the server publishes, drawn with @sincpro/web-ui and arranged with @sincpro/web-composer.",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
@@ -23,19 +23,19 @@
23
23
  "printWidth": 94
24
24
  },
25
25
  "peerDependencies": {
26
- "@sincpro/criteria": "^0.3.0",
27
- "@sincpro/criteria-react": "^0.3.0",
28
- "@sincpro/web-composer": "^1.0.0",
29
- "@sincpro/web-ui": "^0.2.0",
26
+ "@sincpro/criteria": "^0.3.1",
27
+ "@sincpro/criteria-react": "^0.3.1",
28
+ "@sincpro/web-composer": "^1.5.0",
29
+ "@sincpro/web-ui": "^1.7.2",
30
30
  "react": ">=19",
31
31
  "react-dom": ">=19"
32
32
  },
33
33
  "devDependencies": {
34
34
  "@eslint/js": "^10.0.1",
35
- "@sincpro/criteria": "^0.3.0",
36
- "@sincpro/criteria-react": "^0.3.0",
37
- "@sincpro/web-composer": "^1.0.0",
38
- "@sincpro/web-ui": "^0.2.0",
35
+ "@sincpro/criteria": "^0.3.1",
36
+ "@sincpro/criteria-react": "^0.3.1",
37
+ "@sincpro/web-composer": "^1.5.0",
38
+ "@sincpro/web-ui": "^1.7.2",
39
39
  "@storybook/addon-a11y": "10.6.5",
40
40
  "@storybook/addon-docs": "10.6.5",
41
41
  "@storybook/addon-mcp": "10.6.5",