@namroodinc/liquid-editorial 0.15.0 → 0.16.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 (122) hide show
  1. package/README.md +283 -12
  2. package/UPGRADING.md +59 -0
  3. package/dist/chunks/EntryPicker-C7EBfpaw.cjs +2 -0
  4. package/dist/chunks/EntryPicker-C7EBfpaw.cjs.map +1 -0
  5. package/dist/chunks/{EntryPicker-BGWxiLJ_.js → EntryPicker-DBnDsgzi.js} +395 -395
  6. package/dist/chunks/EntryPicker-DBnDsgzi.js.map +1 -0
  7. package/dist/chunks/FormEditor-BG8bOXI8.js +35 -0
  8. package/dist/chunks/FormEditor-BG8bOXI8.js.map +1 -0
  9. package/dist/chunks/FormEditor-BJN0QuLI.cjs +2 -0
  10. package/dist/chunks/FormEditor-BJN0QuLI.cjs.map +1 -0
  11. package/dist/chunks/{NumberField-C90eJGny.js → NumberField-CVsK4l9P.js} +13 -13
  12. package/dist/chunks/{NumberField-C90eJGny.js.map → NumberField-CVsK4l9P.js.map} +1 -1
  13. package/dist/chunks/{NumberField-BrWFmPkW.cjs → NumberField-Ccjpa_1d.cjs} +2 -2
  14. package/dist/chunks/{NumberField-BrWFmPkW.cjs.map → NumberField-Ccjpa_1d.cjs.map} +1 -1
  15. package/dist/chunks/RichTextEditor-D4rNww9d.cjs +2 -0
  16. package/dist/chunks/RichTextEditor-D4rNww9d.cjs.map +1 -0
  17. package/dist/chunks/{RichTextEditor-CS2ED0HP.js → RichTextEditor-DSxiMLVd.js} +1147 -1017
  18. package/dist/chunks/RichTextEditor-DSxiMLVd.js.map +1 -0
  19. package/dist/components/Choice/index.cjs +1 -1
  20. package/dist/components/Choice/index.cjs.map +1 -1
  21. package/dist/components/Choice/index.js +5 -5
  22. package/dist/components/EntryPicker/index.cjs +1 -1
  23. package/dist/components/EntryPicker/index.js +1 -1
  24. package/dist/components/FormEditor/README.md +150 -161
  25. package/dist/components/FormEditor/control.d.cts +4 -4
  26. package/dist/components/FormEditor/control.d.cts.map +1 -1
  27. package/dist/components/FormEditor/control.d.ts +4 -4
  28. package/dist/components/FormEditor/control.d.ts.map +1 -1
  29. package/dist/components/FormEditor/form.d.cts +3 -3
  30. package/dist/components/FormEditor/form.d.cts.map +1 -1
  31. package/dist/components/FormEditor/form.d.ts +3 -3
  32. package/dist/components/FormEditor/form.d.ts.map +1 -1
  33. package/dist/components/FormEditor/index.cjs +1 -1
  34. package/dist/components/FormEditor/index.js +2 -2
  35. package/dist/components/FormEditor/model.d.cts +2 -0
  36. package/dist/components/FormEditor/model.d.cts.map +1 -1
  37. package/dist/components/FormEditor/model.d.ts +2 -0
  38. package/dist/components/FormEditor/model.d.ts.map +1 -1
  39. package/dist/components/FormEditor/rich-text-control.d.cts +1 -2
  40. package/dist/components/FormEditor/rich-text-control.d.cts.map +1 -1
  41. package/dist/components/FormEditor/rich-text-control.d.ts +1 -2
  42. package/dist/components/FormEditor/rich-text-control.d.ts.map +1 -1
  43. package/dist/components/ImageCropper/index.cjs +1 -1
  44. package/dist/components/ImageCropper/index.cjs.map +1 -1
  45. package/dist/components/ImageCropper/index.js +6 -6
  46. package/dist/components/NumberField/index.cjs +1 -1
  47. package/dist/components/NumberField/index.js +1 -1
  48. package/dist/components/RichTextEditor/block-plugins.d.cts +62 -0
  49. package/dist/components/RichTextEditor/block-plugins.d.cts.map +1 -0
  50. package/dist/components/RichTextEditor/block-plugins.d.ts +62 -0
  51. package/dist/components/RichTextEditor/block-plugins.d.ts.map +1 -0
  52. package/dist/components/RichTextEditor/content-block-view.d.cts +1 -1
  53. package/dist/components/RichTextEditor/content-block-view.d.cts.map +1 -1
  54. package/dist/components/RichTextEditor/content-block-view.d.ts +1 -1
  55. package/dist/components/RichTextEditor/content-block-view.d.ts.map +1 -1
  56. package/dist/components/RichTextEditor/content-block.d.cts +7 -21
  57. package/dist/components/RichTextEditor/content-block.d.cts.map +1 -1
  58. package/dist/components/RichTextEditor/content-block.d.ts +7 -21
  59. package/dist/components/RichTextEditor/content-block.d.ts.map +1 -1
  60. package/dist/components/RichTextEditor/document.d.cts +16 -3
  61. package/dist/components/RichTextEditor/document.d.cts.map +1 -1
  62. package/dist/components/RichTextEditor/document.d.ts +16 -3
  63. package/dist/components/RichTextEditor/document.d.ts.map +1 -1
  64. package/dist/components/RichTextEditor/index.cjs +1 -1
  65. package/dist/components/RichTextEditor/index.d.cts +6 -4
  66. package/dist/components/RichTextEditor/index.d.cts.map +1 -1
  67. package/dist/components/RichTextEditor/index.d.ts +6 -4
  68. package/dist/components/RichTextEditor/index.d.ts.map +1 -1
  69. package/dist/components/RichTextEditor/index.js +1 -1
  70. package/dist/components/RichTextEditor/picker-block.d.cts +25 -0
  71. package/dist/components/RichTextEditor/picker-block.d.cts.map +1 -0
  72. package/dist/components/RichTextEditor/picker-block.d.ts +25 -0
  73. package/dist/components/RichTextEditor/picker-block.d.ts.map +1 -0
  74. package/dist/components/RichTextEditor/use-blocks.d.cts +19 -0
  75. package/dist/components/RichTextEditor/use-blocks.d.cts.map +1 -0
  76. package/dist/components/RichTextEditor/use-blocks.d.ts +19 -0
  77. package/dist/components/RichTextEditor/use-blocks.d.ts.map +1 -0
  78. package/dist/components/SelectionCard/index.cjs +1 -1
  79. package/dist/components/SelectionCard/index.cjs.map +1 -1
  80. package/dist/components/SelectionCard/index.js +4 -4
  81. package/dist/components/SelectionCard/index.js.map +1 -1
  82. package/dist/index.cjs +1 -1
  83. package/dist/index.d.cts +2 -2
  84. package/dist/index.d.cts.map +1 -1
  85. package/dist/index.d.ts +2 -2
  86. package/dist/index.d.ts.map +1 -1
  87. package/dist/index.js +46 -46
  88. package/dist/internal/useStableValue.d.cts +8 -0
  89. package/dist/internal/useStableValue.d.cts.map +1 -0
  90. package/dist/internal/useStableValue.d.ts +8 -0
  91. package/dist/internal/useStableValue.d.ts.map +1 -0
  92. package/dist/rich-text-blocks.cjs +2 -0
  93. package/dist/rich-text-blocks.cjs.map +1 -0
  94. package/dist/rich-text-blocks.d.cts +20 -0
  95. package/dist/rich-text-blocks.d.cts.map +1 -0
  96. package/dist/rich-text-blocks.d.ts +20 -0
  97. package/dist/rich-text-blocks.d.ts.map +1 -0
  98. package/dist/rich-text-blocks.js +36 -0
  99. package/dist/rich-text-blocks.js.map +1 -0
  100. package/package.json +14 -1
  101. package/dist/chunks/EntryPicker-BGWxiLJ_.js.map +0 -1
  102. package/dist/chunks/EntryPicker-wVjzdlAO.cjs +0 -2
  103. package/dist/chunks/EntryPicker-wVjzdlAO.cjs.map +0 -1
  104. package/dist/chunks/FormEditor-BHVJG23r.js +0 -30
  105. package/dist/chunks/FormEditor-BHVJG23r.js.map +0 -1
  106. package/dist/chunks/FormEditor-DjUz7qQo.cjs +0 -2
  107. package/dist/chunks/FormEditor-DjUz7qQo.cjs.map +0 -1
  108. package/dist/chunks/RichTextEditor-BgfeOrEe.cjs +0 -2
  109. package/dist/chunks/RichTextEditor-BgfeOrEe.cjs.map +0 -1
  110. package/dist/chunks/RichTextEditor-CS2ED0HP.js.map +0 -1
  111. package/dist/components/RichTextEditor/embed-context.d.cts +0 -41
  112. package/dist/components/RichTextEditor/embed-context.d.cts.map +0 -1
  113. package/dist/components/RichTextEditor/embed-context.d.ts +0 -41
  114. package/dist/components/RichTextEditor/embed-context.d.ts.map +0 -1
  115. package/dist/components/RichTextEditor/embed-types.d.cts +0 -29
  116. package/dist/components/RichTextEditor/embed-types.d.cts.map +0 -1
  117. package/dist/components/RichTextEditor/embed-types.d.ts +0 -29
  118. package/dist/components/RichTextEditor/embed-types.d.ts.map +0 -1
  119. package/dist/components/RichTextEditor/use-embeds.d.cts +0 -31
  120. package/dist/components/RichTextEditor/use-embeds.d.cts.map +0 -1
  121. package/dist/components/RichTextEditor/use-embeds.d.ts +0 -31
  122. package/dist/components/RichTextEditor/use-embeds.d.ts.map +0 -1
package/README.md CHANGED
@@ -1262,7 +1262,7 @@ export function ArticleBody() {
1262
1262
  }
1263
1263
  ```
1264
1264
 
1265
- Use `value`/`onChange` for controlled content or `defaultValue` for local content. Sizes are `sm`, `md` (default), and `lg`; `isDisabled` prevents editing. `toolbarExtra` appends app controls before the expand button. Unsupported JSON produces an error and remains uneditable until corrected.
1265
+ Use `value`/`onChange` for controlled content or `defaultValue` for local content. Sizes are `sm`, `md` (default), and `lg`; `isDisabled` prevents editing. `toolbarExtra` appends app controls before the expand button. `blockPlugins` adds your own block types, such as maps or embedded articles; see [Rich-text content blocks](#rich-text-content-blocks). Unsupported JSON produces an error and remains uneditable until corrected.
1266
1266
 
1267
1267
  Every editor includes Expand editor / Collapse editor controls. The expanded writing view is a headerless `Modal` (`hasHeader={false}`), so it shares Modal's scrim, frame, motion, focus trap, scroll lock and Escape handling. Set `expandedWidth="wide"` (default, Modal's 920px `wide` size) or `expandedWidth="full"` (Modal's `full` size: viewport width with 24px gutters). The existing `size` prop controls inline height. The same mounted TipTap editor, toolbar, `toolbarExtra` controls, selection, undo history and HTML/JSON callbacks remain in use; toggling alone does not emit changes. Both transitions bring the caret into view. Escape, the collapse control or a direct scrim press returns the editor inline. A nested link dialog closes first on Escape. Disabling the editor or loading unsupported content closes expansion and keeps focus in the nearest focusable container around the editor.
1268
1268
 
@@ -1272,6 +1272,288 @@ Escape typed in the editor is no longer swallowed: it closes the expanded view,
1272
1272
 
1273
1273
  Links open a URL modal from the toolbar or an existing body link. Saving preserves selected text/formatting; with no selection, the URL becomes linked text. Existing links offer Remove link. The application owns storage and any server-side processing of editor output.
1274
1274
 
1275
+ ### Rich-text content blocks
1276
+
1277
+ A content block is a self-contained block in a rich-text document, such as a
1278
+ map, an embedded article or a call to action. It stores a type, an alignment
1279
+ and a JSON `data` payload. The editor draws every block in the same frame, with
1280
+ a title bar, selection, dragging, alignment, removal and undo. Your application
1281
+ adds block types as plug-ins. Each plug-in validates its payload, renders a
1282
+ preview, and supplies the dialog that inserts or edits a block.
1283
+
1284
+ #### Add a block type
1285
+
1286
+ This example adds a map block that stores coordinates. The Map Content Block
1287
+ story in Storybook runs the same code.
1288
+
1289
+ **1. Define the type.** A definition names the type and validates its payload.
1290
+ Keep it in a module without React or browser code, so the editor, FormEditor
1291
+ and your server can share it. Type names start with a lowercase letter and
1292
+ use lowercase letters, digits and hyphens. The editor reserves `table`.
1293
+
1294
+ `map-definition.ts`:
1295
+
1296
+ ```ts
1297
+ import type { ContentBlockDefinition } from "@namroodinc/liquid-editorial/rich-text-blocks";
1298
+
1299
+ export const isCoordinate = (value: unknown, limit: number): value is number =>
1300
+ typeof value === "number" && Math.abs(value) <= limit;
1301
+
1302
+ export const mapDefinition: ContentBlockDefinition = {
1303
+ type: "map",
1304
+ validate: ({ latitude, longitude }) => isCoordinate(latitude, 90) && isCoordinate(longitude, 180),
1305
+ };
1306
+ ```
1307
+
1308
+ **2. Write the plug-in.** `renderEditor` renders the dialog that inserts or
1309
+ edits a block. The dialog calls `target.commit(data)` to save and
1310
+ `target.close()` to cancel. `renderPreview` renders the block inside the
1311
+ frame. Define the plug-in once, outside render, or memoize it. A new plug-in
1312
+ object makes its blocks render again.
1313
+
1314
+ `map-block.tsx`:
1315
+
1316
+ ```tsx
1317
+ import { useState } from "react";
1318
+ import {
1319
+ Button,
1320
+ Modal,
1321
+ NumberField,
1322
+ Stack,
1323
+ type ContentBlockPlugin,
1324
+ type ContentBlockSession,
1325
+ } from "@namroodinc/liquid-editorial";
1326
+ import { isCoordinate, mapDefinition } from "./map-definition";
1327
+
1328
+ function MapDialog({ mode, data, target, isDisabled }: ContentBlockSession) {
1329
+ const [latitude, setLatitude] = useState<number | "">(
1330
+ isCoordinate(data?.latitude, 90) ? data.latitude : "",
1331
+ );
1332
+ const [longitude, setLongitude] = useState<number | "">(
1333
+ isCoordinate(data?.longitude, 180) ? data.longitude : "",
1334
+ );
1335
+ const coordinates = { latitude, longitude };
1336
+ return (
1337
+ <Modal
1338
+ isOpen
1339
+ title={mode === "insert" ? "Insert map" : "Edit map"}
1340
+ onClose={target.close}
1341
+ footer={
1342
+ <Button
1343
+ variant="primary"
1344
+ isDisabled={isDisabled || !mapDefinition.validate(coordinates)}
1345
+ onClick={() => target.commit(coordinates)}
1346
+ >
1347
+ Save coordinates
1348
+ </Button>
1349
+ }
1350
+ >
1351
+ <Stack gap="md">
1352
+ <NumberField
1353
+ aria-label="Latitude"
1354
+ min={-90}
1355
+ max={90}
1356
+ step="any"
1357
+ value={latitude}
1358
+ onValueChange={setLatitude}
1359
+ />
1360
+ <NumberField
1361
+ aria-label="Longitude"
1362
+ min={-180}
1363
+ max={180}
1364
+ step="any"
1365
+ value={longitude}
1366
+ onValueChange={setLongitude}
1367
+ />
1368
+ </Stack>
1369
+ </Modal>
1370
+ );
1371
+ }
1372
+
1373
+ export const mapBlockPlugin: ContentBlockPlugin = {
1374
+ definition: mapDefinition,
1375
+ label: "Map",
1376
+ icon: "globe",
1377
+ insertLabel: "Insert map",
1378
+ editLabel: "Edit map",
1379
+ renderPreview: (data, frame) =>
1380
+ frame({
1381
+ title: `Map at ${String(data.latitude)}, ${String(data.longitude)}`,
1382
+ body: (
1383
+ <div className="ds-content-block__body">
1384
+ {String(data.latitude)}, {String(data.longitude)}
1385
+ </div>
1386
+ ),
1387
+ }),
1388
+ renderEditor: (session) => <MapDialog {...session} />,
1389
+ };
1390
+ ```
1391
+
1392
+ **3. Register it.** An Insert map button joins the editor's toolbar, and each
1393
+ map block's actions menu offers Edit map.
1394
+
1395
+ ```tsx
1396
+ import { RichTextEditor } from "@namroodinc/liquid-editorial";
1397
+ import { mapBlockPlugin } from "./map-block";
1398
+
1399
+ export function StoryBody() {
1400
+ return (
1401
+ <RichTextEditor
1402
+ label="Story body"
1403
+ format="json"
1404
+ blockPlugins={[mapBlockPlugin]}
1405
+ />
1406
+ );
1407
+ }
1408
+ ```
1409
+
1410
+ In FormEditor, list the same definition objects on the field and pass the
1411
+ plug-ins by field ID. Validation then uses the field's definitions:
1412
+
1413
+ ```tsx
1414
+ <FormEditor
1415
+ schema={{
1416
+ fields: [{ id: "body", type: "richText", label: "Body", blockDefinitions: [mapDefinition] }],
1417
+ }}
1418
+ blockPlugins={{ body: [mapBlockPlugin] }}
1419
+ />
1420
+ ```
1421
+
1422
+ **4. Accept it wherever documents go.** JSON stores the block as
1423
+ `{ "type": "contentBlock", "attrs": { "type": "map", "align": "full", "data": { "latitude": 51.5, "longitude": -0.12 } } }`.
1424
+ HTML stores a `div` with `data-content-block`, `data-content-block-type`,
1425
+ `data-content-block-align` and the payload as a JSON string in
1426
+ `data-content-block-data`. Keep those attributes in HTML sanitizers.
1427
+ Validate saved documents on your server with the same definition, from the
1428
+ browser-independent `rich-text-blocks` entry point:
1429
+
1430
+ ```ts
1431
+ import {
1432
+ contentBlockRegistry,
1433
+ validContentBlock,
1434
+ } from "@namroodinc/liquid-editorial/rich-text-blocks";
1435
+ import { mapDefinition } from "./map-definition";
1436
+
1437
+ const registry = contentBlockRegistry([mapDefinition]);
1438
+
1439
+ interface StoredNode {
1440
+ type?: string;
1441
+ attrs?: unknown;
1442
+ content?: StoredNode[] | null;
1443
+ }
1444
+
1445
+ /** Whether every content block in a stored JSON document is registered and valid. */
1446
+ export function blocksAreValid(node: StoredNode): boolean {
1447
+ return (
1448
+ (node.type !== "contentBlock" || validContentBlock(node.attrs, registry)) &&
1449
+ (node.content ?? []).every(blocksAreValid)
1450
+ );
1451
+ }
1452
+ ```
1453
+
1454
+ Your delivery renderer decides how each block type is published, reading
1455
+ `attrs.type` and `attrs.data`.
1456
+
1457
+ Register a plug-in for every block type a document can contain. A document
1458
+ with an unregistered or invalid block shows an unsupported content error and
1459
+ keeps its value until the plug-in is registered. A plug-in without
1460
+ `renderEditor` displays stored blocks without offering to insert or edit them.
1461
+
1462
+ #### Plug-in reference
1463
+
1464
+ | `ContentBlockPlugin` field | Purpose |
1465
+ | --- | --- |
1466
+ | `definition` | The type and its payload validation. |
1467
+ | `label` | The block's name in its title bar. |
1468
+ | `icon` | The icon on the toolbar's insert button. |
1469
+ | `insertLabel` | Adds an insert button to the toolbar. Needs `renderEditor`. |
1470
+ | `editLabel` | Adds an edit action to each block's menu. Needs `renderEditor`. |
1471
+ | `replaceLabel` | Adds a replace action to each block's menu, for blocks whose data is chosen rather than edited. Needs `renderEditor`. |
1472
+ | `renderPreview(data, frame)` | Renders a block: call `frame` and return its result. Without it, the frame shows only the label. |
1473
+ | `renderEditor(session)` | Renders the dialog for an insert, edit or replace session. |
1474
+ | `isDialogHidden` | The dialog is hidden for now, for example behind an upload drawer. Blocks of this type lock, and no other block dialog opens. |
1475
+ | `isCreating` | The plug-in is finishing an asynchronous creation. Its session and commit continue while the application holds the editor read only. |
1476
+
1477
+ `renderEditor` receives a `ContentBlockSession`:
1478
+
1479
+ | Field | Purpose |
1480
+ | --- | --- |
1481
+ | `mode` | `"insert"`, `"edit"` or `"replace"`. |
1482
+ | `data` | The block's data when editing or replacing. |
1483
+ | `target.commit(data)` | Inserts the block, or updates the block being edited or replaced. An insertion can commit an array of payloads in one undo step. Returns `false` if the data fails validation, which keeps the dialog open, or if the block or editor is gone. |
1484
+ | `target.close()` | Ends the session without changes. |
1485
+ | `target.available()` | Whether a commit can still land, for creations that finish later. |
1486
+ | `isDisabled` | The editor is read only. Disable saving. |
1487
+ | `fieldLabel` | The editor's label, for dialog text. |
1488
+
1489
+ `frame` accepts the block's `body` and these optional fields. Wrap the body in
1490
+ an element with the `ds-content-block__body` class for the frame's padding and
1491
+ type size. A preview that needs hooks can return a component that calls
1492
+ `frame` itself.
1493
+
1494
+ | Field | Purpose |
1495
+ | --- | --- |
1496
+ | `title` | Names the block's actions menu, such as "Block actions for Map at 51.5, -0.12". Defaults to the label. |
1497
+ | `tone` | `"draft"` or `"removed"`, shown on the title bar. |
1498
+ | `missing` | Shows the block as unavailable, with the removed tone. |
1499
+ | `onEdit` | Adds an edit action that opens your own resource editor without changing the block. |
1500
+ | `replaceLabel` | Renames the replace action, such as "Choose another article". |
1501
+
1502
+ #### Blocks chosen from a picker
1503
+
1504
+ For blocks that refer to records, such as articles or images,
1505
+ `createPickerBlockPlugin` supplies the dialog and preview from an EntryPicker
1506
+ source. Map each picked item to block data with `toData`, and each block back to
1507
+ its item ID with `itemId`. The source lists choices with `items` or `loadPage`.
1508
+ It describes stored blocks with `resolveItem`. It can also open a record with
1509
+ `onEditItem` and create one with `onCreate`. Call the helper on every render
1510
+ with the current source.
1511
+
1512
+ ```tsx
1513
+ import {
1514
+ RichTextEditor,
1515
+ createPickerBlockPlugin,
1516
+ type PickerBlockSource,
1517
+ } from "@namroodinc/liquid-editorial";
1518
+ import type { ContentBlockDefinition } from "@namroodinc/liquid-editorial/rich-text-blocks";
1519
+
1520
+ export const articleDefinition: ContentBlockDefinition = {
1521
+ type: "article",
1522
+ validate: ({ articleId }) => typeof articleId === "string" && articleId.trim() !== "",
1523
+ };
1524
+
1525
+ export function ArticleBody({ articles }: { articles: PickerBlockSource }) {
1526
+ const article = createPickerBlockPlugin({
1527
+ definition: articleDefinition,
1528
+ itemLabel: "article",
1529
+ itemsLabel: "articles",
1530
+ icon: "file-text",
1531
+ source: articles,
1532
+ toData: (item) => ({ articleId: item.id }),
1533
+ itemId: (data) => String(data.articleId),
1534
+ });
1535
+ return (
1536
+ <RichTextEditor
1537
+ label="Body"
1538
+ format="json"
1539
+ blockPlugins={[article]}
1540
+ />
1541
+ );
1542
+ }
1543
+ ```
1544
+
1545
+ The packaged FormEditor reference covers batch insertion, refreshes and
1546
+ delayed creation.
1547
+
1548
+ #### Tables and other editable content
1549
+
1550
+ A content block is atomic. Writers can't place the caret inside one, and its
1551
+ data changes only through its dialog. Content that writers edit in place needs
1552
+ schema support in the editor, which plug-ins can't add. Tables work that way:
1553
+ they are TableKit nodes with editable cells, not plug-ins. They reuse the
1554
+ block frame, title bar and actions menu, and the editor reserves the `table`
1555
+ type name for them. Turn them off with `tables={false}`.
1556
+
1275
1557
  ### FormEditor
1276
1558
 
1277
1559
  The [FormEditor reference for agents](src/components/FormEditor/README.md) contains every schema option, default, value shape, examples, and the extension checklist. Installed packages include the same guide at `dist/components/FormEditor/README.md` ([packaged reference](dist/components/FormEditor/README.md)). Read it before integrating or extending the editor.
@@ -2158,14 +2440,3 @@ bars keep their compact spacing. General Grid and Stack defaults are unchanged.
2158
2440
  Wizard progress uses Stepper's `orientation="auto"`, stacking vertically when its
2159
2441
  available width is below 28rem so step labels and descriptions stay readable in
2160
2442
  narrow dialogs.
2161
-
2162
- ### Rich-text content blocks
2163
-
2164
- Pass optional entry/asset sources through `RichTextEditor.embeds` or per-field
2165
- `FormEditor.embedSources`. The editor reuses EntryPicker paging, static items and
2166
- rows, and supports insert, replace, alignment, editing callbacks and removal. Open a
2167
- block’s ⋯ button to reveal alignment and actions. Entry blocks
2168
- store the readable model API ID in `attrs.id` and the selected entry identifier in
2169
- `attrs.entryId`; assets use `attrs.assetId`. Applications own data, restrictions,
2170
- creation and delivery resolution. See the packaged FormEditor reference for the
2171
- complete source, stored-value and guarded-creation contracts.
package/UPGRADING.md CHANGED
@@ -2,6 +2,65 @@
2
2
 
3
3
  ## Unreleased
4
4
 
5
+ ## 0.16.0
6
+
7
+ ### Breaking changes
8
+
9
+ - Replace `RichTextEditor.embeds`, `FormEditor.embedSources`, the
10
+ `RichTextEmbed*` types, and `ContentBlockIdentity` with the content block
11
+ plug-in types and registration props.
12
+ - Rich-text blocks now use `attrs: { type, align, data }` and the HTML
13
+ `data-content-block-data` attribute. Flat entry and asset attributes and
14
+ `storyblock` documents require conversion before they can be opened.
15
+
16
+ ### Changes
17
+
18
+ - Application plug-ins define content types, payloads, previews and editing.
19
+ Tables use the shared block frame and continue to use TableKit.
20
+ - `createPickerBlockPlugin` supplies the picker workflow with application-owned
21
+ item sources and mappings. The `rich-text-blocks` package entry point exports
22
+ browser-independent registration and validation.
23
+ - The editor refuses any change that would add an unregistered or invalid block,
24
+ including toolbar commands and attribute updates, and remains editable. Block
25
+ HTML is read only from its `data-content-block-*` attributes.
26
+ - `ContentBlockAttributes.align` is optional: a missing `align` reads as `full`.
27
+ A JSON document whose `content` is null reads as empty.
28
+ - A FormEditor schema whose `blockDefinitions` is not an array or contains an
29
+ invalid or duplicate type throws an error naming the field.
30
+ - The README's Rich-text content blocks guide builds a complete map block
31
+ type, and `.ds-content-block__body` is the supported class for preview
32
+ bodies. Tables remain built-in TableKit nodes, not plug-ins.
33
+
34
+ ### Adoption
35
+
36
+ 1. Build each plug-in with a definition, validation, and the preview and editor
37
+ actions the type needs, following the README's Rich-text content blocks
38
+ guide. Use the optional picker helper for record selection.
39
+ 2. Register the plug-ins on the editor. For FormEditor, also assign their
40
+ definition objects to each rich-text field's `blockDefinitions`. Define
41
+ application plug-ins and definitions outside render or memoize them. Call
42
+ `createPickerBlockPlugin` on every render with the current source.
43
+ 3. Update readers, write validation, delivery renderers and HTML sanitizers
44
+ that consume these documents to use the new payload. When retaining existing
45
+ documents, convert their block attributes before opening them in the editor.
46
+
47
+ ### Compatibility
48
+
49
+ A field whose document requires an unavailable plug-in displays an unsupported
50
+ content error and keeps its value, including after a `tables` change. When
51
+ definitions change, the current document is checked again. Existing table JSON
52
+ and HTML use their TableKit schema. A server-rendered HTML editor reports an
53
+ unregistered block after hydration, so server and client markup match.
54
+
55
+ ### Verification
56
+
57
+ 1. Insert, edit, move, remove and undo a registered block. Save and reopen JSON
58
+ and HTML, then check that the app renders the same payload on delivery.
59
+ 2. Verify the field is protected if a type is unregistered or invalid. Try a
60
+ batch and a replacement with the picker helper, including a delayed creation
61
+ that completes after the source's refresh key changes.
62
+ 3. Run the host's form and server validation with the same block definitions.
63
+
5
64
  ## 0.15.0
6
65
 
7
66
  ### Breaking changes
@@ -0,0 +1,2 @@
1
+ const e=require("./Icon-QLZH31JA.cjs"),t=require("../components/Button/index.cjs"),n=require("./overlayLayer-CPd3zj_u.cjs"),r=require("../components/Badge/index.cjs"),i=require("./limit-BNo4dlRj.cjs"),a=require("../components/LimitReading/index.cjs"),o=require("../components/Modal/index.cjs"),s=require("./style-nulIa2_8.cjs"),c=require("../components/Grid/index.cjs"),l=require("./LoadState-BXLG-SkQ.cjs"),u=require("../components/SearchField/index.cjs"),d=require("../components/Choice/index.cjs"),f=require("../components/SortableList/index.cjs");let p=require("react"),m=require("react/jsx-runtime");function h(e,t,n,r){let i=l.n(t,n,r);return t!==`error`&&i.state!==`pending`?null:(0,m.jsx)(l.r,{title:e,error:i.error,onRetry:i.retry,retryState:i.state})}function g({query:e,itemLabel:t,itemsLabel:n,canCreate:r}){let i=e.trim();return(0,m.jsxs)(`div`,{className:`ds-entry-picker__no-results`,children:[(0,m.jsx)(`p`,{children:i?`No ${n} match “${i}”`:`No ${n} yet`}),i&&(0,m.jsxs)(`p`,{children:[`Try a different search.`,r?` Or create the ${t} you need.`:``]})]})}function _(e,t){let r=e.closest(`.ds-entry-picker__scroll`)??e.parentElement,i=Array.from(r?.querySelectorAll(`.ds-entry-picker__result`)??[]);for(let e of[...i.slice(t),...i.slice(0,t).reverse()]){let t=n.b(e)[0];if(t)return t}}function v(e){let t=(0,p.useRef)(null),r=(0,p.useRef)(null),{more:i,offset:a}=e;return(0,p.useEffect)(()=>{let e=r.current,a=t.current;e!==null&&i.status!==`loading`&&(r.current=null,a&&n.h(document.activeElement)&&(i.status===`error`?n.b(a)[0]:_(a,e))?.focus())},[i.status,a]),{pagingRef:t,load:()=>{r.current=t.current?.contains(document.activeElement)?a:null,i.load()}}}function y(e,t){let r=(0,p.useRef)(t);(0,p.useEffect)(()=>{if(r.current===t)return;r.current=t;let i=e.current;i&&n.h(document.activeElement)&&(n.b(i)[0]??_(i,1/0))?.focus()},[e,t])}function b({count:e,total:n,isRemote:r,pageSize:i,remote:a,itemsLabel:o}){let{more:s}=a,{pagingRef:c,load:l}=v(a),u=h(`Couldn't load more ${o}`,s.status,s.error,l);return y(c,u?`failure`:r&&a.hasMore?`more`:`none`),n===0?null:(0,m.jsxs)(`div`,{ref:c,className:`ds-entry-picker__paging`,children:[u??(r&&a.hasMore&&(0,m.jsxs)(t.Button,{isPending:s.status===`loading`,isFocusableWhenDisabled:!0,isDisabled:!s.isAvailable,onClick:l,children:[`Load `,Math.min(i,n-a.offset),` more`]})),(0,m.jsx)(`span`,{children:e<n?`Showing ${e} of ${n}`:`All ${e} shown`})]})}function x(e,t,{isDisabled:n,searching:r,atMax:i}){if(n||r)return`inactive`;if(e.isDisabled)return`restricted`;if(!t&&i)return`full`}function S(e){return e.isDisabled?e.disabledReason:void 0}function C(e){return e.tone===`removed`}function w(e){return C(e)?void 0:S(e)}function T({item:t,reasonId:n}){let i=S(t);return(0,m.jsxs)(m.Fragment,{children:[(0,m.jsx)(`span`,{className:`ds-entry__thumb`,children:t.imageUrl?(0,m.jsx)(`img`,{src:t.imageUrl,alt:``,loading:`lazy`}):(0,m.jsx)(e.t,{name:`file-text`,size:20})}),(0,m.jsxs)(`span`,{className:`ds-entry__body`,children:[(0,m.jsx)(`span`,{className:`ds-entry__title`,"data-unavailable":t.isUnavailable||void 0,children:t.title}),t.metadata!=null&&(0,m.jsx)(`span`,{className:`ds-entry__meta`,children:t.metadata}),i&&(0,m.jsxs)(`span`,{id:n,className:`ds-entry__reason`,children:[(0,m.jsx)(r.Badge,{shape:`tag`,size:`sm`,children:i.label}),` `,(0,m.jsx)(`span`,{children:i.description})]})]})]})}function E({item:e,reasonId:t}){return C(e)?(0,m.jsxs)(`span`,{className:`ds-entry__removed`,children:[(0,m.jsx)(`strong`,{children:e.title}),` `,e.metadata??(0,m.jsx)(`code`,{children:e.id})]}):(0,m.jsx)(T,{item:e,reasonId:t})}function D({item:e}){return C(e)?(0,m.jsx)(r.Badge,{shape:`tag`,children:e.removedLabel??`Removed on save`}):null}function O({item:e,onEdit:n,isDisabled:r}){return!n||e.isUnavailable||e.isDisabled?null:(0,m.jsx)(t.Button,{variant:`simple`,size:`sm`,isIconOnly:!0,iconStart:`pencil`,"aria-label":`Edit ${e.title}`,isDisabled:r,onClick:()=>n(e)})}function k({items:e,selected:t,block:n,onToggle:r,onEdit:i}){let a=(0,p.useId)(),o=`${a}-full`;return(0,m.jsxs)(m.Fragment,{children:[(0,m.jsx)(`span`,{id:o,hidden:!0,children:`The selection is full. Remove one to choose another.`}),(0,m.jsx)(`ul`,{className:`ds-entry-picker__results`,"data-searching":n.searching||void 0,children:e.map((e,s)=>{let c=t.includes(e.id),l=x(e,c,n),u=S(e)?`${a}-reason-${s}`:void 0;return(0,m.jsxs)(`li`,{className:`ds-entry-picker__result ds-field-surface`,"data-selected":c||void 0,"data-blocked":l?!0:void 0,onClick:t=>{let n=t.target instanceof Element?t.target.closest(`button, input, label, a, select, textarea, summary, [tabindex]`):null;(!n||!t.currentTarget.contains(n))&&r(e.id)},children:[(0,m.jsx)(d.Checkbox,{checked:c,"aria-checked":c,"aria-label":`Select ${e.title}`,"aria-describedby":l===`full`?o:u,disabled:!!l,isFocusableWhenDisabled:l!==`inactive`,onChange:()=>r(e.id)}),(0,m.jsx)(`span`,{className:`ds-entry`,children:(0,m.jsx)(T,{item:e,reasonId:u})}),(0,m.jsx)(O,{item:e,onEdit:i,isDisabled:l===`inactive`})]},e.id)})})]})}function A(){let e=(0,p.useRef)(null),[t,n]=(0,p.useState)(!1);return{ref:e,scrolled:t,toTop:()=>{n(!1),e.current&&(e.current.scrollTop=0)},onScroll:e=>{n(e.currentTarget.scrollTop>0)}}}function j(e,t){return e&&t?(0,m.jsxs)(c.Stack,{gap:`sm`,children:[e,t]}):e||t}function M({isOpen:e,onClose:n,query:r,onQuery:i,selected:s,results:c,cap:u,block:d,isRemote:f,pageSize:p,remote:_,onToggle:v,onEdit:y,confirm:x,selectionNotice:S,selectionFailure:C,isCreateDisabled:w,itemLabel:T,itemsLabel:E,addLabel:D,onCreate:O,isCreating:A,dialogTitle:M,dialogDescription:P,isDialogHidden:F}){let I=h(`Couldn't refresh ${E}`,_.refresh.status,_.refresh.error,_.refresh.retry);return(0,m.jsx)(o.Modal,{isOpen:e,isHidden:F,onClose:n,title:M??D,description:P??u.description,className:`ds-entry-picker__dialog`,footer:(0,m.jsxs)(m.Fragment,{children:[(0,m.jsxs)(`span`,{className:`ds-entry-picker__selection`,role:`status`,children:[u.reading?(0,m.jsx)(a.LimitReading,{...u.reading,size:`lg`}):`${s.length} selected`,S&&`. ${S}`]}),(0,m.jsx)(t.Button,{variant:`primary`,isDisabled:x?.isDisabled,onClick:x?.onClick??n,children:x?.label??`Done`})]}),children:(0,m.jsx)(N,{query:r,onQuery:i,itemsLabel:E,isSearching:_.loading,action:O&&(0,m.jsx)(t.Button,{variant:`primary`,isPending:A,isFocusableWhenDisabled:!0,iconStart:`plus`,isDisabled:d.isDisabled||u.atMax||w,onClick:O,children:`New ${T}`}),banner:j(I,C),isBusy:_.loading||_.more.status===`loading`||_.refresh.status===`loading`,children:(0,m.jsxs)(l.t,{status:_.status,errorTitle:`Couldn't load ${E}`,error:_.error,onRetry:_.retry,children:[(0,m.jsx)(k,{items:c,selected:s,block:d,onToggle:v,onEdit:y}),!_.searching&&c.length===0&&(0,m.jsx)(g,{query:r,itemLabel:T,itemsLabel:E,canCreate:!!O}),(0,m.jsx)(b,{count:c.length,total:f?_.total:c.length,isRemote:f,pageSize:p,remote:_,itemsLabel:E})]})})})}function N({query:e,onQuery:t,itemsLabel:n,isSearching:r,action:i,banner:a,isBusy:o,children:s}){let{ref:c,scrolled:l,onScroll:d,toTop:f}=A(),p=e=>{f(),t(e)};return(0,m.jsxs)(m.Fragment,{children:[(0,m.jsxs)(`div`,{className:`ds-entry-picker__search ds-field-surface`,"data-scrolled":l||void 0,children:[(0,m.jsx)(u.SearchField,{"aria-label":`Search ${n}`,value:e,isBusy:r,placeholder:`Search ${n}`,onChange:e=>p(e.target.value),onClear:()=>p(``)}),i]}),a&&(0,m.jsx)(`div`,{className:`ds-entry-picker__refresh`,children:a}),(0,m.jsx)(`div`,{className:`ds-entry-picker__scroll`,ref:c,onScroll:d,"aria-busy":o,children:s})]})}function P({items:e,selected:n,onChange:r,onEdit:i,isDisabled:a,canReorder:o,emptyLabel:s}){let c=(0,p.useId)(),l=(e,t)=>w(e)?`${c}-reason-${t}`:void 0,u=(e,o)=>(0,m.jsxs)(`span`,{className:`ds-entry-picker__item-actions`,children:[(0,m.jsx)(D,{item:e}),(0,m.jsx)(O,{item:e,onEdit:e.tone===`removed`?void 0:i,isDisabled:a}),(0,m.jsx)(t.Button,{variant:`simple`,size:`sm`,isIconOnly:!0,iconStart:`x`,"aria-label":`Remove ${e.title}`,"aria-describedby":o,isDisabled:a,onClick:()=>r(n.filter(t=>t!==e.id))})]});return e.length===0?(0,m.jsx)(`p`,{className:`ds-entry-picker__empty`,children:s}):o?(0,m.jsx)(f.SortableList,{items:n,onReorder:r,isDisabled:a,children:e.map((e,t)=>(0,m.jsx)(f.SortableListItem,{id:e.id,label:e.title,"data-tone":e.tone,handleDescribedBy:l(e,t),action:u(e,l(e,t)),children:(0,m.jsx)(`div`,{className:`ds-entry`,children:(0,m.jsx)(E,{item:e,reasonId:l(e,t)})})},e.id))}):(0,m.jsx)(`ul`,{className:`ds-entry-picker__list`,children:e.map((e,t)=>(0,m.jsxs)(`li`,{className:`ds-entry-picker__row ds-field-surface`,"data-tone":e.tone,children:[(0,m.jsx)(`div`,{className:`ds-entry`,children:(0,m.jsx)(E,{item:e,reasonId:l(e,t)})}),u(e,l(e,t))]},e.id))})}function F(e,t,n){return{id:e,title:t,metadata:n,isUnavailable:!0}}function I({selected:e,items:t,pageItems:n,known:r,failures:i,hasResolver:a,itemLabel:o}){let s=new Map(t.map(e=>[e.id,e])),c=new Map(n.map(e=>[e.id,e]));return e.map(e=>(s.get(e)??(r.has(e)?r.get(e):c.get(e)))||(r.has(e)?F(e,`${`${o.charAt(0).toUpperCase()}${o.slice(1)}`} no longer available`,`Replace or clear this selection.`):a?F(e,i.has(e)?`Couldn't load ${o}`:`Loading…`):{id:e,title:e}))}function L(e,t){return e===`single`||t===1}function R(e,t,n){return L(e,n)?{count:t,max:1,tone:`neutral`}:e===`multiple`&&n!==void 0?{count:t,max:n}:void 0}function z(e,t,n){return L(e,n)?void 0:t}function B(e,t,n,{itemLabel:r,itemsLabel:a}){let o=R(e,t,n),s=e===`multiple`&&o&&Number.isFinite(o.max)?o.max:void 0,c=`Choose as many ${a} as you need.`;return e===`single`||s===1?c=`Choose one ${r}.`:s!==void 0&&(c=`Choose up to ${s} ${a}.`),{limit:o,atMax:s!==void 0&&t>=s,description:c,reading:e===`multiple`&&i.r(o)?o:void 0}}function V(e){return e instanceof Error?e:null}function H(e,t){if(!t.some(t=>e.has(t)))return e;let n=new Map(e);for(let e of t)n.delete(e);return n}function U(e,t,n){let r=n?t.flatMap(t=>{let r=n(t);return r?.item.id===t&&e.seeds.get(t)!==r?[r]:[]}):[];if(r.length===0)return e;let i=r.filter(t=>Object.is(t.revision,e.refreshKey)),a=r.filter(t=>!Object.is(t.revision,e.refreshKey)&&!e.known.has(t.item.id)&&!e.stale.has(t.item.id)),o=e=>e.map(e=>[e.item.id,e.item]);return{...e,seeds:new Map([...e.seeds,...r.map(e=>[e.item.id,e])]),known:i.length?new Map([...e.known,...o(i)]):e.known,stale:a.length?new Map([...e.stale,...o(a)]):e.stale,failures:H(e.failures,i.map(e=>e.item.id))}}function W(e,t){return e!==t&&(e.length!==t.length||t.some(t=>!e.includes(t)))}function G(e,t,n,r){let i=e;if(Object.is(i.refreshKey,n)||(i={...i,refreshKey:n,known:new Map,stale:new Map([...i.stale,...i.known]),failures:new Map}),W(i.selected,t)){let e=i.selected.filter(e=>!t.includes(e));i={...i,selected:t,known:H(i.known,e),stale:H(i.stale,e),failures:H(i.failures,e),seeds:H(i.seeds,e)}}return U(i,t,r)}function K(e,t,r,i,a){let o=n.u(r),s=n.u(e),[c,l]=(0,p.useState)(()=>U({refreshKey:i,selected:e,known:new Map,stale:new Map,failures:new Map,seeds:new Map},e,a)),u=G(c,e,i,a);u!==c&&l(u);let{known:d,stale:f,failures:m}=u,h=(0,p.useMemo)(()=>f.size===0?d:new Map([...f,...d]),[f,d]),g=(e,t,n=s.current)=>{let r=e.filter(e=>e!==void 0&&n.includes(e.id)).map(e=>[e.id,e]);r.length!==0&&l(e=>{if(Object.is(e.refreshKey,t))return{...e,known:new Map([...e.known,...r])};let n=r.filter(([t])=>!e.known.has(t)&&!e.stale.has(t));return n.length===0?e:{...e,stale:new Map([...e.stale,...n])}})},_=new Set(t.map(e=>e.id)),v=r?e.filter(e=>!_.has(e)&&!d.has(e)&&!m.has(e)):[],y=JSON.stringify(v),b=(0,p.useRef)({refreshKey:i,tokens:new Map});(0,p.useEffect)(()=>{let e=o.current;if(!e)return;let t=JSON.parse(y);Object.is(b.current.refreshKey,i)||(b.current={refreshKey:i,tokens:new Map});let{tokens:n}=b.current;for(let e of n.keys())t.includes(e)||n.delete(e);for(let r of t.filter(e=>!n.has(e))){let t=Symbol(r);n.set(r,t);let a=e=>{b.current.tokens.get(r)===t&&(b.current.tokens.delete(r),l(t=>Object.is(t.refreshKey,i)&&t.selected.includes(r)?e(t):t))};Promise.resolve().then(()=>e(r)).then(e=>a(t=>t.known.has(r)?t:{...t,known:new Map(t.known).set(r,e??null)}),e=>a(t=>({...t,failures:new Map(t.failures).set(r,V(e))})))}},[y,i,o]);let x=e.filter(e=>m.has(e)&&!d.has(e));return{known:h,current:d,failures:m,remember:g,status:v.length>0?`loading`:x.length>0?`error`:`ready`,error:x.length>0?m.get(x[0])??null:null,retry:()=>l(e=>({...e,failures:H(e.failures,x)}))}}var q=250;function J(e){return Array.from(new Map(e.map(e=>[e.id,e])).values())}var Y={items:[],offset:0,total:0},X={...Y,key:null,revision:void 0,status:`ready`,error:null};function Z(e,t){let n=e?.status===`error`&&t;return{status:e?.status===`loading`?`loading`:n?`error`:`ready`,error:n?e.error??null:null,isAvailable:t}}function Q(e,t){return{items:J([...e.items,...t.items]),offset:e.offset+t.items.length,total:t.items.length===0?Math.min(t.total,e.offset):t.total}}function ee(e,t,n,r){return e.key!==t||e.offset!==n?e:{...e,...Q(e,r)}}async function te(e,t,n,r,i){let a=Math.max(1,Math.ceil(r/n)),o=await Promise.all(Array.from({length:a},(r,i)=>e({offset:i*n,limit:n},{query:t}))),s=Y;for(let[e,t]of o.entries()){if(s.offset!==e*n)break;s=Q(s,t)}for(;s.offset<r&&s.offset<s.total&&i();)s=Q(s,await e({offset:s.offset,limit:n},{query:t}));return s}function ne(e,t,n,r){let i=e!==null&&t.key===e,a=i&&Object.is(t.revision,n),o=e!==null&&!a&&(!i||t.status===`error`),s=o&&t.key!==null&&t.status===`ready`,c=o&&!s?`loading`:t.status===`error`?`error`:`ready`,l=t.status===`ready`&&t.offset<t.total,u=i&&!a&&t.status===`ready`,d=u&&r?.key===e&&Object.is(r.revision,n);return{loading:o,searching:s,status:c,hasMore:l,refresh:u?d?`error`:`loading`:`ready`,refreshFailed:d}}function re(e,t,r,i,a,o){let s=n.u(e),c=n.u(a),l=n.u(o),[u,d]=(0,p.useState)(0),[f,m]=(0,p.useState)(X),[h,g]=(0,p.useState)(null),[_,v]=(0,p.useState)(null),[y,b]=(0,p.useState)(i);y!==i&&(b(i),i||(m(X),g(null),v(null),d(e=>e+1)));let x=r.trim(),S=e&&i?JSON.stringify([x,t,u]):null,C=n.u(f),w=(0,p.useRef)(null),T=(0,p.useRef)(x),{loading:E,searching:D,status:O,hasMore:k,refresh:A,refreshFailed:j}=ne(S,f,o,_),M=!E&&A===`ready`,N=E?`load`:A===`loading`?`refresh`:null;(0,p.useEffect)(()=>{if(S===null)return;let e=N===`load`&&x!==T.current?q:0;if(T.current=x,N===null)return;let n=N===`refresh`?C.current.offset+(w.current?t:0):0,r=!0,i=window.setTimeout(()=>{let e=s.current;e&&te(e,x,t,n,()=>r).then(e=>{r&&(w.current=null,m({...e,key:S,revision:o,status:`ready`,error:null}),g(null),v(null),c.current?.(e.items,o))},e=>{r&&(N===`refresh`?v({key:S,revision:o,error:V(e)}):(w.current=null,m({...X,key:S,revision:o,status:`error`,error:V(e)}),g(null)))})},e);return()=>{r=!1,window.clearTimeout(i)}},[S,N,o,x,t,s,c,C]);let P=()=>{let e=s.current,n=f.key,{offset:r}=f;if(!e||n===null||!M||!k||w.current)return;let i=Symbol(`load more`),a=o;w.current=i,g({token:i,status:`loading`,error:null});let u=()=>w.current===i&&C.current.key===n&&C.current.offset===r&&Object.is(l.current,a),d=e=>{w.current===i&&(w.current=null),g(t=>t?.token===i?e:t)};Promise.resolve().then(()=>e({offset:r,limit:t},{query:x})).then(e=>{u()&&(m(t=>ee(t,n,r,e)),c.current?.(e.items,a)),d(null)},e=>d(u()?{token:i,status:`error`,error:V(e)}:null))};return{items:f.items,total:f.total,offset:f.offset,hasMore:k,pageRevision:f.revision,loading:E,searching:D,status:O,error:f.error,retry:()=>d(e=>e+1),more:{...Z(h,M),load:P},refresh:{status:A,error:j?_?.error??null:null,retry:()=>v(null)}}}var $=[];function ie(e,t){return!!(e.isDisabled||t?.(e))}function ae(e,t){return t?e.map(e=>{let n=e.isDisabled?void 0:t(e);return n?{...e,isDisabled:!0,disabledReason:n}:e}):e}function oe(e,t,n,{isOpen:r,isDisabled:i,itemLabel:a,itemsLabel:o,close:s,recheckSelection:c,restrict:l}){let[u,d]=(0,p.useState)(``),{resolveItem:f,refreshKey:m,loadPage:h,pageSize:g=10,mode:_=`multiple`,max:v,onEditItem:y}=n,b=!!h,S=c&&b&&!!f,C=K(e,S?$:t,f,m),w=re(h,g,u,r,S?(e,t)=>C.remember(e.filter(e=>ie(e,l)),t):C.remember,m),T=(0,p.useMemo)(()=>{let e=u.trim().toLowerCase();return b?$:t.filter(t=>!e||[t.title,...t.keywords??[]].join(` `).toLowerCase().includes(e))},[b,t,u]),E=b?w.items:T,D=(0,p.useMemo)(()=>ae(E,l),[E,l]),O=B(_,e.length,v,{itemLabel:a,itemsLabel:o}),k={isDisabled:i,searching:w.searching,atMax:O.atMax},A=y?e=>{y(e)===!1&&s()}:void 0;return{selection:C,remote:w,isRemote:b,results:D,cap:O,block:k,editItem:A,revision:b?w.pageRevision:m,choice:t=>{let n=D.find(e=>e.id===t);return n&&!x(n,e.includes(t),k)?n:void 0},dialog:{query:u,onQuery:d,selected:e,results:D,cap:O,block:k,isRemote:b,pageSize:g,remote:w,onEdit:A,itemLabel:a,itemsLabel:o}}}var se=[];function ce({items:e=se,value:n,defaultValue:r=[],onValueChange:i,mode:a=`multiple`,max:o,label:c=`Entries`,emptyLabel:l=`Nothing selected yet.`,addLabel:u=`Choose entries`,itemLabel:d=`entry`,itemsLabel:f=`entries`,isReorderable:g=!0,isDisabled:_=!1,loadPage:v,pageSize:y=10,resolveItem:b,onEditItem:x,onCreate:S,isCreating:C=!1,refreshKey:w,dialogTitle:T,dialogDescription:E,isDialogHidden:D=!1,className:O,...k}){let[A,j]=(0,p.useState)(r),N=n??A,[F,L]=(0,p.useState)(!1),R=oe(N,e,{resolveItem:b,refreshKey:w,loadPage:v,pageSize:y,mode:a,max:o,onEditItem:x},{isOpen:F,isDisabled:_,itemLabel:d,itemsLabel:f,close:()=>L(!1)}),{selection:B,remote:V,cap:H,editItem:U}=R,W=h(`Couldn't load selected ${f}`,B.status,B.error,B.retry),G=e=>{_||(n===void 0&&j(e),i?.(e))},K=(e,t)=>{B.remember([t],R.revision,e),G(e)},q=e=>{let t=R.choice(e);t&&(a===`single`?(K(N[0]===e?[]:[e],t),L(!1)):N.includes(e)?G(N.filter(t=>t!==e)):K([...N,e],t))},{known:J,failures:Y}=B,X=!!b,Z=(0,p.useMemo)(()=>I({selected:N,items:e,pageItems:V.items,known:J,failures:Y,hasResolver:X,itemLabel:d}),[N,e,V.items,J,Y,X,d]);return(0,m.jsxs)(s.t,{...k,className:[`ds-entry-picker`,O].filter(Boolean).join(` `),label:c,count:z(a,N.length,o),limit:k.limit===void 0?H.limit:k.limit,children:[(0,m.jsx)(P,{items:Z,selected:N,onChange:G,onEdit:U,isDisabled:_,canReorder:g&&a===`multiple`&&Z.length>1,emptyLabel:l}),W,(0,m.jsxs)(`div`,{className:`ds-entry-picker__actions`,children:[(0,m.jsx)(t.Button,{variant:`neutral`,size:`sm`,iconStart:`plus`,isDisabled:_,onClick:()=>L(!0),children:u}),N.length>0&&(0,m.jsx)(t.Button,{variant:`simple`,size:`sm`,isDisabled:_,onClick:()=>G([]),children:`Clear`})]}),(0,m.jsx)(M,{...R.dialog,isOpen:F,onClose:()=>L(!1),onToggle:q,addLabel:u,onCreate:S,isCreating:C,dialogTitle:T,dialogDescription:E,isDialogHidden:D})]})}Object.defineProperty(exports,"a",{enumerable:!0,get:function(){return R}}),Object.defineProperty(exports,"c",{enumerable:!0,get:function(){return T}}),Object.defineProperty(exports,"i",{enumerable:!0,get:function(){return z}}),Object.defineProperty(exports,"l",{enumerable:!0,get:function(){return h}}),Object.defineProperty(exports,"n",{enumerable:!0,get:function(){return oe}}),Object.defineProperty(exports,"o",{enumerable:!0,get:function(){return I}}),Object.defineProperty(exports,"r",{enumerable:!0,get:function(){return K}}),Object.defineProperty(exports,"s",{enumerable:!0,get:function(){return M}}),Object.defineProperty(exports,"t",{enumerable:!0,get:function(){return ce}});
2
+ //# sourceMappingURL=EntryPicker-C7EBfpaw.cjs.map