forty-cdk 0.3.0 → 0.4.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.
@@ -232,9 +232,27 @@ function injectTreeItemContext(piece) {
232
232
  * Library fallback for tree defaults, read at the root injector when no
233
233
  * consumer has called `provideForTreeDefaults`. Exported for the shared
234
234
  * defaults contract spec; not re-exported from the primitive's public entry.
235
+ *
236
+ * The drag announcement formatters mirror the lift / move / drop / cancel
237
+ * cadence the drag-drop and listbox coordinators use, so a consumer hears
238
+ * consistent reorder announcements across primitives. Defining them inside the
239
+ * tree's own defaults (rather than importing `FOR_DRAG_DROP_DEFAULTS` /
240
+ * `FOR_LISTBOX_DEFAULTS`) keeps `[forTreeNodeDrag]` from pulling in those
241
+ * primitives.
235
242
  */
236
243
  const FOR_TREE_FALLBACK_DEFAULTS = {
237
244
  selectionFollowsFocus: false,
245
+ dragAnnounceLift: (label) => `Picked up ${label}. Use arrow keys to move, Space to drop, Escape to cancel.`,
246
+ dragAnnounceMove: (label, parentLabel, position, total) => {
247
+ const parentPart = parentLabel ? `under ${parentLabel}, ` : 'at root, ';
248
+ return `${label}: ${parentPart}position ${position} of ${total}.`;
249
+ },
250
+ dragAnnounceDrop: (label, parentLabel, position, total) => {
251
+ const parentPart = parentLabel ? `under ${parentLabel}, ` : 'at root, ';
252
+ return `Dropped ${label} ${parentPart}position ${position} of ${total}.`;
253
+ },
254
+ dragAnnounceCancel: (label) => `Cancelled. ${label} returned to its original position.`,
255
+ dragAnnounceInvalid: (label) => `Cannot drop ${label} here.`,
238
256
  };
239
257
  const { token, provideDefaults } = createDefaults('FOR_TREE_DEFAULTS', FOR_TREE_FALLBACK_DEFAULTS);
240
258
  /** Token holding the resolved tree defaults for the current scope. */
@@ -881,34 +899,6 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.0.2", ngImpor
881
899
  }]
882
900
  }], ctorParameters: () => [], propDecorators: { value: [{ type: i0.Input, args: [{ isSignal: true, alias: "value", required: false }] }, { type: i0.Output, args: ["valueChange"] }], expanded: [{ type: i0.Input, args: [{ isSignal: true, alias: "expanded", required: false }] }, { type: i0.Output, args: ["expandedChange"] }], multiple: [{ type: i0.Input, args: [{ isSignal: true, alias: "multiple", required: false }] }], disabled: [{ type: i0.Input, args: [{ isSignal: true, alias: "disabled", required: false }] }], orientation: [{ type: i0.Input, args: [{ isSignal: true, alias: "orientation", required: false }] }], selectionMode: [{ type: i0.Input, args: [{ isSignal: true, alias: "selectionMode", required: false }] }], cascade: [{ type: i0.Input, args: [{ isSignal: true, alias: "cascade", required: false }] }], descendantsOf: [{ type: i0.Input, args: [{ isSignal: true, alias: "descendantsOf", required: false }] }], totalCount: [{ type: i0.Input, args: [{ isSignal: true, alias: "totalCount", required: false }] }], visibleRange: [{ type: i0.Input, args: [{ isSignal: true, alias: "visibleRange", required: false }] }], scrollToIndex: [{ type: i0.Output, args: ["scrollToIndex"] }], ariaLabel: [{ type: i0.Input, args: [{ isSignal: true, alias: "ariaLabel", required: false }] }], _dirInput: [{ type: i0.Input, args: [{ isSignal: true, alias: "dir", required: false }] }], selectionFollowsFocus: [{ type: i0.Input, args: [{ isSignal: true, alias: "selectionFollowsFocus", required: false }] }] } });
883
901
 
884
- /**
885
- * Screen-reader announcement strings for `ForTreeNodeDrag`. Kept framework-free and
886
- * separate from the directive so the live-region copy lives in one place and can be unit
887
- * tested without rendering the tree. Not part of the public API.
888
- */
889
- /** Spoken when a node is picked up (assertive). */
890
- function announceTreeLift(label) {
891
- return `Picked up ${label}. Use arrow keys to move, Space to drop, Escape to cancel.`;
892
- }
893
- /** Spoken on each intermediate move while a node is lifted (polite). */
894
- function announceTreeMove(label, parentLabel, position, total) {
895
- const parentPart = parentLabel ? `under ${parentLabel}, ` : 'at root, ';
896
- return `${label}: ${parentPart}position ${position} of ${total}.`;
897
- }
898
- /** Spoken when a node is committed to its new position (assertive). */
899
- function announceTreeDrop(label, parentLabel, position, total) {
900
- const parentPart = parentLabel ? `under ${parentLabel}, ` : 'at root, ';
901
- return `Dropped ${label} ${parentPart}position ${position} of ${total}.`;
902
- }
903
- /** Spoken when a lift is cancelled and the node returns to its origin (assertive). */
904
- function announceTreeCancel(label) {
905
- return `Cancelled. ${label} returned to its original position.`;
906
- }
907
- /** Spoken when a `canDrop` veto rejects the attempted drop (assertive). */
908
- function announceTreeInvalid(label) {
909
- return `Cannot drop ${label} here.`;
910
- }
911
-
912
902
  /**
913
903
  * Resolves the action for a key press while a node is lifted, honoring writing direction for
914
904
  * the depth keys (ArrowRight deepens in LTR, ArrowLeft deepens in RTL). Cancel / commit are
@@ -1056,6 +1046,7 @@ class ForTreeNodeDrag {
1056
1046
  #isBrowser = isPlatformBrowser(inject(PLATFORM_ID));
1057
1047
  #announcer = inject(LiveAnnouncer);
1058
1048
  #destroyRef = inject(DestroyRef);
1049
+ #defaults = inject(FOR_TREE_DEFAULTS);
1059
1050
  /** Disables all drag interactions on this tree. */
1060
1051
  disabled = input(false, { ...(ngDevMode ? { debugName: "disabled" } : /* istanbul ignore next */ {}), transform: booleanAttribute });
1061
1052
  /**
@@ -1270,7 +1261,7 @@ class ForTreeNodeDrag {
1270
1261
  this.#desiredLevel = entry.handle.level();
1271
1262
  this._dragging.set(true);
1272
1263
  this.#publishDropTarget(rows, this.#desiredLevel);
1273
- this.#announcer.announce(announceTreeLift(this.#label), 'assertive');
1264
+ this.#announcer.announce(this.#defaults.dragAnnounceLift(this.#label), 'assertive');
1274
1265
  }
1275
1266
  #publishDropTarget(rows, level) {
1276
1267
  this._dropTargetValid.set(true);
@@ -1294,19 +1285,20 @@ class ForTreeNodeDrag {
1294
1285
  };
1295
1286
  const veto = this.canDrop();
1296
1287
  if (veto !== undefined && !veto(event)) {
1297
- this.#announcer.announce(announceTreeInvalid(this.#label), 'assertive');
1298
- this.#cancelSession(true);
1288
+ this.#restoreExpansion();
1289
+ this.#announcer.announce(this.#defaults.dragAnnounceInvalid(this.#label), 'assertive');
1290
+ this.#clearSession();
1299
1291
  return;
1300
1292
  }
1301
1293
  this.#restoreExpansion();
1302
1294
  this.nodeDrop.emit(event);
1303
- this.#announcer.announce(announceTreeDrop(this.#label, parentLabel, target.index + 1, target.siblingCount + 1), 'assertive');
1295
+ this.#announcer.announce(this.#defaults.dragAnnounceDrop(this.#label, parentLabel, target.index + 1, target.siblingCount + 1), 'assertive');
1304
1296
  this.#clearSession();
1305
1297
  }
1306
1298
  #cancelSession(restore) {
1307
1299
  if (restore) {
1308
1300
  this.#restoreExpansion();
1309
- this.#announcer.announce(announceTreeCancel(this.#label), 'assertive');
1301
+ this.#announcer.announce(this.#defaults.dragAnnounceCancel(this.#label), 'assertive');
1310
1302
  }
1311
1303
  this.#clearSession();
1312
1304
  }
@@ -1340,7 +1332,7 @@ class ForTreeNodeDrag {
1340
1332
  this.#desiredLevel = target.level;
1341
1333
  this.#publishDropTarget(rows, target.level);
1342
1334
  const parentLabel = treeParentLabel(visible, target.parentValue);
1343
- this.#announcer.announce(announceTreeMove(this.#label, parentLabel, target.index + 1, target.siblingCount + 1), 'polite');
1335
+ this.#announcer.announce(this.#defaults.dragAnnounceMove(this.#label, parentLabel, target.index + 1, target.siblingCount + 1), 'polite');
1344
1336
  }
1345
1337
  static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "22.0.2", ngImport: i0, type: ForTreeNodeDrag, deps: [], target: i0.ɵɵFactoryTarget.Directive });
1346
1338
  static ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "17.1.0", version: "22.0.2", type: ForTreeNodeDrag, isStandalone: true, selector: "[forTreeNodeDrag]", inputs: { disabled: { classPropertyName: "disabled", publicName: "disabled", isSignal: true, isRequired: false, transformFunction: null }, canDrop: { classPropertyName: "canDrop", publicName: "canDrop", isSignal: true, isRequired: false, transformFunction: null } }, outputs: { nodeDrop: "nodeDrop" }, host: { properties: { "attr.data-dragging": "_dragging() ? \"\" : null", "attr.data-drop-target": "_dropTargetValid() ? \"\" : null", "style.--for-tree-drop-level": "_dropLevel()" } }, providers: [{ provide: FOR_TREE_NODE_DRAG_CONTEXT, useExisting: ForTreeNodeDrag }], exportAs: ["forTreeNodeDrag"], ngImport: i0 });