@oslokommune/punkt-react 16.14.0 → 16.15.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 (41) hide show
  1. package/CHANGELOG.md +17 -0
  2. package/dist/{dialog-polyfill.esm-1hPr0gl9-EorOF9Wq.js → dialog-polyfill.esm-BmVHGRTX-CuhXqEqJ.js} +1 -1
  3. package/dist/index.d.ts +50 -47
  4. package/dist/punkt-react.es.js +4482 -3014
  5. package/dist/punkt-react.umd.js +471 -76
  6. package/dist/shared-types/fileupload.d.ts +73 -0
  7. package/dist/shared-types/index.d.ts +2 -0
  8. package/dist/shared-utils/fileupload/announcements.d.ts +11 -0
  9. package/dist/shared-utils/fileupload/filename.d.ts +13 -0
  10. package/dist/shared-utils/fileupload/focus-trap.d.ts +12 -0
  11. package/dist/shared-utils/fileupload/formats.d.ts +30 -0
  12. package/dist/shared-utils/fileupload/index.d.ts +15 -0
  13. package/dist/shared-utils/fileupload/navigation.d.ts +5 -0
  14. package/dist/shared-utils/fileupload/size.d.ts +12 -0
  15. package/dist/shared-utils/fileupload/transfers.d.ts +17 -0
  16. package/dist/shared-utils/fileupload/truncate.d.ts +13 -0
  17. package/dist/shared-utils/fileupload/validation.d.ts +24 -0
  18. package/package.json +4 -4
  19. package/src/components/fileupload/DropZone.tsx +35 -22
  20. package/src/components/fileupload/FileUpload.test.tsx +165 -10
  21. package/src/components/fileupload/FileUpload.tsx +116 -184
  22. package/src/components/fileupload/QueueDisplay.test.tsx +51 -8
  23. package/src/components/fileupload/QueueDisplay.tsx +71 -99
  24. package/src/components/fileupload/QueueItemContent.tsx +120 -135
  25. package/src/components/fileupload/Subcomponents.tsx +175 -144
  26. package/src/components/fileupload/Truncate.test.tsx +65 -207
  27. package/src/components/fileupload/Truncate.tsx +24 -120
  28. package/src/components/fileupload/extensions/Comments.tsx +94 -106
  29. package/src/components/fileupload/extensions/Remove.tsx +3 -5
  30. package/src/components/fileupload/extensions/Rename.tsx +45 -42
  31. package/src/components/fileupload/hooks/index.ts +1 -0
  32. package/src/components/fileupload/hooks/useFileAttributes.ts +37 -29
  33. package/src/components/fileupload/hooks/useImagePreview.ts +3 -7
  34. package/src/components/fileupload/hooks/useOperationState.ts +29 -8
  35. package/src/components/fileupload/hooks/useRequiredFormValidation.ts +43 -0
  36. package/src/components/fileupload/hooks.ts +1 -0
  37. package/src/components/fileupload/types.ts +49 -32
  38. package/src/components/fileupload/utils.ts +3 -54
  39. package/src/components/modal/Modal.tsx +27 -15
  40. package/src/components/types.ts +1 -1
  41. package/src/components/fileupload/texts.ts +0 -20
package/CHANGELOG.md CHANGED
@@ -5,6 +5,23 @@ og skriver commits ca etter [Conventional Commits](https://conventionalcommits.o
5
5
 
6
6
  ---
7
7
 
8
+ ## [16.15.0](https://github.com/oslokommune/punkt/compare/16.14.0...16.15.0) (2026-05-11)
9
+
10
+ ### ⚠ BREAKING CHANGES
11
+ Ingen
12
+
13
+ ### Features
14
+ Ingen
15
+
16
+ ### Bug Fixes
17
+ Ingen
18
+
19
+ ### Chores
20
+ Ingen
21
+
22
+ ---
23
+
24
+
8
25
  ## [16.14.0](https://github.com/oslokommune/punkt/compare/16.13.3...16.14.0) (2026-05-08)
9
26
 
10
27
  ### ⚠ BREAKING CHANGES
@@ -33,7 +33,7 @@
33
33
  return [];
34
34
  };
35
35
  }
36
- //#region ../elements/dist/dialog-polyfill.esm-1hPr0gl9.js
36
+ //#region ../elements/dist/dialog-polyfill.esm-BmVHGRTX.js
37
37
  var e = window.CustomEvent;
38
38
  (!e || typeof e == "object") && (e = function(e, t) {
39
39
  t ||= {};
package/dist/index.d.ts CHANGED
@@ -10,6 +10,9 @@ import { ForwardRefExoticComponent } from 'react';
10
10
  import { HTMLAttributes } from 'react';
11
11
  import { HTMLProps } from 'react';
12
12
  import { IDatepickerStrings } from './shared-types/datepicker';
13
+ import { IFileItem } from './shared-types';
14
+ import { IFileTransfer } from './shared-types';
15
+ import { IFileValidateDetail } from './shared-types';
13
16
  import { InputHTMLAttributes } from 'react';
14
17
  import { IPktComboboxOption } from './shared-types/combobox';
15
18
  import { IPktConsent as IPktConsent_2 } from '@oslokommune/punkt-elements';
@@ -33,6 +36,7 @@ import { TAlertSkin } from './shared-types';
33
36
  import { TAriaLive } from './shared-types';
34
37
  import { TCardSkin } from './shared-types';
35
38
  import { TextareaHTMLAttributes } from 'react';
39
+ import { TFileUploadStrategy } from './shared-types';
36
40
  import { THeaderMenu } from './shared-types';
37
41
  import { THeaderPosition } from './shared-types';
38
42
  import { THeaderScrollBehavior } from './shared-types';
@@ -78,20 +82,20 @@ declare type ExtendedLoader = IPktLoader_2 & PktElType;
78
82
  * Notes:
79
83
  * - A `fileId` is generated automatically if omitted.
80
84
  * - `attributes.targetFilename` is the filename shown in the queue and may be updated by extensions (e.g. rename).
85
+ *
86
+ * Implements the shared `IFileItem` type from `shared-types`.
81
87
  */
82
- export declare class FileItem implements FileItem {
88
+ export declare class FileItem implements IFileItem {
83
89
  fileId: TFileId;
84
90
  file: File;
85
- attributes: Record<string, any>;
91
+ attributes: {
92
+ targetFilename: string;
93
+ } & Record<string, unknown>;
86
94
  constructor(file: File, fileId?: TFileId);
87
95
  }
88
96
 
89
97
  /**
90
98
  * Shared props for `PktFileUpload` (both `form` and `custom` strategies).
91
- *
92
- * The component can be used as:
93
- * - **controlled**: pass `value` + `onFilesChanged`
94
- * - **uncontrolled**: pass `defaultValue` (internal state is not stored; you still receive new lists via callbacks)
95
99
  */
96
100
  declare interface IBaseFileUploadProps extends Omit<InputHTMLAttributes<HTMLInputElement>, 'checked' | 'size' | 'type' | 'value' | 'onChange' | 'width' | 'defaultValue'> {
97
101
  /** Called with the next file list when files are added/removed/updated. */
@@ -120,9 +124,9 @@ declare interface IBaseFileUploadProps extends Omit<InputHTMLAttributes<HTMLInpu
120
124
  /** Uncontrolled initial value (use either `value` or `defaultValue`, not both). */
121
125
  defaultValue?: TFileItemList;
122
126
  /** Extra operations appended after built-ins (rename/comment). */
123
- extraOperations?: Array<TQueueItemExtension>;
127
+ extraOperations?: Array<TQueueItemOperation>;
124
128
  /** Stretch to full container width (drop zone + queue). */
125
- fullWidth?: boolean;
129
+ fullwidth?: boolean;
126
130
  /** Allowed formats for built-in validation (extensions like `pdf`, or MIME patterns like `image/*`). */
127
131
  allowedFormats?: string[];
128
132
  /** Custom message for invalid format. Use `{formats}` placeholder. */
@@ -133,6 +137,11 @@ declare interface IBaseFileUploadProps extends Omit<InputHTMLAttributes<HTMLInpu
133
137
  sizeErrorMessage?: string;
134
138
  /** Optional additional validation hook (runs after built-in format/size checks). Return string to block. */
135
139
  onFileValidation?: (file: File) => string | null;
140
+ /**
141
+ * Low-level validation escape hatch — Lit parity with the `file-validate` CustomEvent.
142
+ * Receives a detail object whose `errorMessage` can be mutated; set it to reject the file.
143
+ */
144
+ onFileValidate?: (detail: TFileValidateDetail) => void;
136
145
  /** External/programmatic error message shown under the component. */
137
146
  errorMessage?: string;
138
147
  /** External error flag (combined with internal validation errors). */
@@ -165,19 +174,11 @@ declare interface ICardTag {
165
174
  text: string;
166
175
  }
167
176
 
168
- /** Props for `uploadStrategy="form"` (native file input submission). */
169
177
  declare interface IFileInputFileUploadProps extends IBaseFileUploadProps, Omit<HTMLAttributes<HTMLInputElement>, 'value' | 'onChange' | 'defaultValue'> {
170
178
  uploadStrategy?: 'form';
171
179
  onFileUploadRequested?: never;
172
180
  }
173
181
 
174
- /**
175
- * Props for `uploadStrategy="custom"` (upload handled externally).
176
- *
177
- * Requirements:
178
- * - `transfers` must be provided (to render status/progress)
179
- * - `onFileUploadRequested` is called for each added file
180
- */
181
182
  declare interface ImmediateFileUploadProps extends IBaseFileUploadProps {
182
183
  id: string;
183
184
  uploadStrategy: 'custom';
@@ -1192,20 +1193,11 @@ export declare type TFileId = string;
1192
1193
  /** The value type for `PktFileUpload` (`value` / `defaultValue`). */
1193
1194
  export declare type TFileItemList = Array<FileItem>;
1194
1195
 
1195
- /**
1196
- * Transfer status for a file when using `uploadStrategy="custom"`.
1197
- *
1198
- * - `progress`: `0..1` during upload, or a state (`queued`, `done`, `error`, `canceled`)
1199
- * - `showProgress`: if false, UI uses indeterminate "Laster opp..." style instead of progress bar
1200
- * - `lastProgress`: used to render a "failed at X%" bar when an upload errors
1201
- */
1202
- export declare type TFileTransfer = {
1203
- fileId: TFileId;
1204
- progress: number | 'done' | 'error' | 'canceled' | 'queued';
1205
- errorMessage?: string;
1206
- showProgress?: boolean;
1207
- lastProgress?: number;
1208
- };
1196
+ /** Transfer status for a file when using `uploadStrategy="custom"` — aliased from `shared-types`. */
1197
+ export declare type TFileTransfer = IFileTransfer;
1198
+
1199
+ /** Detail payload passed to the React `onFileValidate` escape hatch. */
1200
+ declare type TFileValidateDetail = IFileValidateDetail;
1209
1201
 
1210
1202
  declare type THeadingLevel = 1 | 2 | 3 | 4 | 5 | 6;
1211
1203
 
@@ -1224,29 +1216,40 @@ declare type TPktAccordionSkin = TAccordionSkin;
1224
1216
 
1225
1217
  declare type TPktAccordionSkin_2 = TAccordionSkin;
1226
1218
 
1227
- /** Factory that produces a queue item operation given access to file attributes. */
1228
- export declare type TQueueItemExtension = (attributes: TFileAttributes) => TQueueItemOperation;
1229
-
1230
1219
  /**
1231
1220
  * An operation that can be attached to a queue item (rename, comment, remove, etc).
1232
1221
  *
1233
- * An operation may:
1234
- * - be a simple action (`onClick`)
1235
- * - render inline UI (e.g. rename)
1236
- * - render extended UI (e.g. comments)
1237
- * - render hidden inputs for form submission (`renderHidden`)
1222
+ * Must carry a stable `id: string` — symbols are no longer supported.
1238
1223
  */
1239
1224
  export declare type TQueueItemOperation = {
1240
- title: string | ((fileItem: FileItem) => string);
1241
- ariaLabel?: string | ((fileItem: FileItem) => string);
1242
- onClick?: (transferItem: FileItem) => void;
1243
- renderInlineUI?: (fileItem: FileItem, closeOperationUi: () => void) => ReactNode;
1244
- renderExtendedUI?: (fileItem: FileItem, closeOperationUi: () => void) => ReactNode;
1245
- renderContent?: (fileItem: FileItem, activateOperation?: () => void, isOperationActive?: boolean) => ReactNode;
1246
- renderHidden?: (fileItem: FileItem) => ReactNode;
1247
- symbol: symbol;
1225
+ id: string;
1226
+ title: TQueueOperationLabel;
1227
+ ariaLabel?: TQueueOperationLabel;
1228
+ onClick?: (context: TQueueOperationContext) => void;
1229
+ renderInlineUI?: (context: TQueueOperationContext) => ReactNode;
1230
+ renderExtendedUI?: (context: TQueueOperationContext) => ReactNode;
1231
+ renderContent?: (context: TQueueOperationContext) => ReactNode;
1232
+ renderHidden?: (context: TQueueOperationContext) => ReactNode;
1248
1233
  };
1249
1234
 
1235
+ /**
1236
+ * Context passed to queue-item operations. Mirrors the Lit
1237
+ * `TQueueOperationContext` so operations authored for one runtime are
1238
+ * trivial to port to the other.
1239
+ */
1240
+ export declare type TQueueOperationContext = {
1241
+ file: FileItem;
1242
+ inputName: string;
1243
+ disabled: boolean;
1244
+ isActive: boolean;
1245
+ activate: () => void;
1246
+ close: () => void;
1247
+ getAttribute: <T>(name: string) => T | undefined;
1248
+ setAttribute: (name: string, value: unknown) => void;
1249
+ };
1250
+
1251
+ declare type TQueueOperationLabel = string | ((fileItem: FileItem) => string);
1252
+
1250
1253
  declare type TSkin = 'blue' | 'green' | 'red' | 'beige' | 'yellow' | 'grey' | 'gray' | 'blue-light';
1251
1254
 
1252
1255
  declare type TSkin_2 = IPktTag['skin'];
@@ -1260,7 +1263,7 @@ export declare type TTransferItemInProgress = TFileAndTransfer & {
1260
1263
  };
1261
1264
 
1262
1265
  /** Upload mode: `form` posts the files on submit, `custom` posts file IDs and uploads separately. */
1263
- export declare type TUploadStrategy = 'custom' | 'form';
1266
+ export declare type TUploadStrategy = TFileUploadStrategy;
1264
1267
 
1265
1268
  /** User object for header components */
1266
1269
  declare interface User {