orcasvn-react-diagrams 0.2.10 → 0.2.11

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.
@@ -3484,55 +3484,96 @@ var labelStyleDemoConfig = {
3484
3484
  var createLinkColorPoolState = function () { return ({
3485
3485
  elements: [
3486
3486
  {
3487
- id: 'lc-off-source',
3488
- position: { x: 80, y: 170 },
3487
+ id: 'lc-load-missing-source',
3488
+ position: { x: 80, y: 160 },
3489
3489
  size: { width: 190, height: 120 },
3490
3490
  shapeId: 'default',
3491
3491
  },
3492
3492
  {
3493
- id: 'lc-off-target',
3494
- position: { x: 350, y: 170 },
3493
+ id: 'lc-load-missing-target',
3494
+ position: { x: 350, y: 160 },
3495
3495
  size: { width: 190, height: 120 },
3496
3496
  shapeId: 'default',
3497
3497
  },
3498
3498
  {
3499
- id: 'lc-default-source',
3500
- position: { x: 80, y: 360 },
3499
+ id: 'lc-load-blank-source',
3500
+ position: { x: 80, y: 350 },
3501
3501
  size: { width: 190, height: 120 },
3502
3502
  shapeId: 'panel',
3503
3503
  },
3504
3504
  {
3505
- id: 'lc-default-target',
3506
- position: { x: 350, y: 360 },
3505
+ id: 'lc-load-blank-target',
3506
+ position: { x: 350, y: 350 },
3507
3507
  size: { width: 190, height: 120 },
3508
3508
  shapeId: 'panel',
3509
3509
  },
3510
3510
  {
3511
- id: 'lc-custom-source',
3512
- position: { x: 620, y: 170 },
3511
+ id: 'lc-load-explicit-source',
3512
+ position: { x: 80, y: 540 },
3513
3513
  size: { width: 190, height: 120 },
3514
3514
  shapeId: 'default',
3515
3515
  },
3516
3516
  {
3517
- id: 'lc-custom-target',
3518
- position: { x: 620, y: 360 },
3517
+ id: 'lc-load-explicit-target',
3518
+ position: { x: 350, y: 540 },
3519
3519
  size: { width: 190, height: 120 },
3520
3520
  shapeId: 'default',
3521
3521
  },
3522
+ {
3523
+ id: 'lc-create-auto-source',
3524
+ position: { x: 620, y: 250 },
3525
+ size: { width: 190, height: 120 },
3526
+ shapeId: 'default',
3527
+ },
3528
+ {
3529
+ id: 'lc-create-auto-target',
3530
+ position: { x: 620, y: 420 },
3531
+ size: { width: 190, height: 120 },
3532
+ shapeId: 'default',
3533
+ },
3534
+ {
3535
+ id: 'lc-create-explicit-source',
3536
+ position: { x: 870, y: 250 },
3537
+ size: { width: 190, height: 120 },
3538
+ shapeId: 'panel',
3539
+ },
3540
+ {
3541
+ id: 'lc-create-explicit-target',
3542
+ position: { x: 870, y: 420 },
3543
+ size: { width: 190, height: 120 },
3544
+ shapeId: 'panel',
3545
+ },
3522
3546
  ],
3523
3547
  ports: [
3524
- { id: 'lc-off-source-port', elementId: 'lc-off-source', position: { x: 170, y: 60 }, shapeId: 'port-circle' },
3525
- { id: 'lc-off-target-port', elementId: 'lc-off-target', position: { x: 20, y: 60 }, shapeId: 'port-circle' },
3526
- { id: 'lc-default-source-port', elementId: 'lc-default-source', position: { x: 170, y: 60 }, shapeId: 'port-circle' },
3527
- { id: 'lc-default-target-port', elementId: 'lc-default-target', position: { x: 20, y: 60 }, shapeId: 'port-circle' },
3528
- { id: 'lc-custom-source-port', elementId: 'lc-custom-source', position: { x: 95, y: 110 }, shapeId: 'port-circle' },
3529
- { id: 'lc-custom-target-port', elementId: 'lc-custom-target', position: { x: 95, y: 10 }, shapeId: 'port-circle' },
3548
+ { id: 'lc-load-missing-source-port', elementId: 'lc-load-missing-source', position: { x: 170, y: 60 }, shapeId: 'port-circle' },
3549
+ { id: 'lc-load-missing-target-port', elementId: 'lc-load-missing-target', position: { x: 20, y: 60 }, shapeId: 'port-circle' },
3550
+ { id: 'lc-load-blank-source-port', elementId: 'lc-load-blank-source', position: { x: 170, y: 60 }, shapeId: 'port-circle' },
3551
+ { id: 'lc-load-blank-target-port', elementId: 'lc-load-blank-target', position: { x: 20, y: 60 }, shapeId: 'port-circle' },
3552
+ { id: 'lc-load-explicit-source-port', elementId: 'lc-load-explicit-source', position: { x: 170, y: 60 }, shapeId: 'port-circle' },
3553
+ { id: 'lc-load-explicit-target-port', elementId: 'lc-load-explicit-target', position: { x: 20, y: 60 }, shapeId: 'port-circle' },
3554
+ { id: 'lc-create-auto-source-port', elementId: 'lc-create-auto-source', position: { x: 95, y: 110 }, shapeId: 'port-circle' },
3555
+ { id: 'lc-create-auto-target-port', elementId: 'lc-create-auto-target', position: { x: 95, y: 10 }, shapeId: 'port-circle' },
3556
+ { id: 'lc-create-explicit-source-port', elementId: 'lc-create-explicit-source', position: { x: 95, y: 110 }, shapeId: 'port-circle' },
3557
+ { id: 'lc-create-explicit-target-port', elementId: 'lc-create-explicit-target', position: { x: 95, y: 10 }, shapeId: 'port-circle' },
3530
3558
  ],
3531
3559
  links: [
3532
3560
  {
3533
- id: 'lc-reference-link',
3534
- sourcePortId: 'lc-off-source-port',
3535
- targetPortId: 'lc-off-target-port',
3561
+ id: 'lc-loaded-missing-link',
3562
+ sourcePortId: 'lc-load-missing-source-port',
3563
+ targetPortId: 'lc-load-missing-target-port',
3564
+ points: [],
3565
+ },
3566
+ {
3567
+ id: 'lc-loaded-blank-link',
3568
+ sourcePortId: 'lc-load-blank-source-port',
3569
+ targetPortId: 'lc-load-blank-target-port',
3570
+ points: [],
3571
+ style: { stroke: ' ', strokeWidth: 2 },
3572
+ },
3573
+ {
3574
+ id: 'lc-loaded-explicit-link',
3575
+ sourcePortId: 'lc-load-explicit-source-port',
3576
+ targetPortId: 'lc-load-explicit-target-port',
3536
3577
  points: [],
3537
3578
  style: { stroke: '#374151', strokeWidth: 2 },
3538
3579
  },
@@ -3540,18 +3581,20 @@ var createLinkColorPoolState = function () { return ({
3540
3581
  texts: [
3541
3582
  {
3542
3583
  id: 'lc-intro',
3543
- content: 'Use Color Mode above: Off keeps baseline link color behavior. Default Pool enables random colors from the built-in 20-color pool. Custom Pool restricts random colors to #0b7285, #e8590c, #5f3dc4.',
3584
+ content: 'Change Color Mode, then use Reload Demo State to compare load-time fill. The left column loads one missing-stroke link, one blank-stroke link, and one explicit-stroke link. The right column actions add new links so you can compare creation-time color assignment with explicit-stroke preservation under the same policy.',
3544
3585
  position: { x: 80, y: 86 },
3545
3586
  },
3546
- { id: 'lc-off-label', content: 'Off scenario pair', ownerId: 'lc-off-source', position: { x: 10, y: -16 } },
3547
- { id: 'lc-default-label', content: 'Default-pool scenario pair', ownerId: 'lc-default-source', position: { x: 10, y: -16 } },
3548
- { id: 'lc-custom-label', content: 'Custom-pool scenario pair', ownerId: 'lc-custom-source', position: { x: 10, y: -16 } },
3587
+ { id: 'lc-load-missing-label', content: 'Loaded link with missing stroke', ownerId: 'lc-load-missing-source', position: { x: 10, y: -16 } },
3588
+ { id: 'lc-load-blank-label', content: 'Loaded link with blank stroke', ownerId: 'lc-load-blank-source', position: { x: 10, y: -16 } },
3589
+ { id: 'lc-load-explicit-label', content: 'Loaded link with explicit stroke', ownerId: 'lc-load-explicit-source', position: { x: 10, y: -16 } },
3590
+ { id: 'lc-create-auto-label', content: 'Add new unstyled links here', ownerId: 'lc-create-auto-source', position: { x: 10, y: -16 } },
3591
+ { id: 'lc-create-explicit-label', content: 'Add new explicit-stroke links here', ownerId: 'lc-create-explicit-source', position: { x: 10, y: -16 } },
3549
3592
  ],
3550
3593
  }); };
3551
3594
  var linkColorPoolDemoConfig = {
3552
3595
  id: 'link-color-pool',
3553
3596
  title: 'Link Color Pool',
3554
- description: 'Verify disabled/default/custom random link-color assignment on new links.',
3597
+ description: 'Verify off/default/custom load-time fill for missing link strokes and compare it with creation-time color assignment.',
3555
3598
  createState: createLinkColorPoolState,
3556
3599
  elementShapes: baseElementShapes,
3557
3600
  portShapes: basePortShapes,
@@ -3559,38 +3602,30 @@ var linkColorPoolDemoConfig = {
3559
3602
  defaultPortShapeId: 'port-circle',
3560
3603
  actions: [
3561
3604
  {
3562
- id: 'add-link-off-pair',
3563
- label: 'Add link (off pair)',
3564
- run: function (editor) {
3565
- editor.addLink({
3566
- id: "link-color-off-".concat(createId()),
3567
- sourcePortId: 'lc-off-source-port',
3568
- targetPortId: 'lc-off-target-port',
3569
- points: [],
3570
- });
3571
- },
3572
- },
3573
- {
3574
- id: 'add-link-default-pair',
3575
- label: 'Add link (default pair)',
3605
+ id: 'add-link-create-auto',
3606
+ label: 'Add new unstyled link',
3576
3607
  run: function (editor) {
3577
3608
  editor.addLink({
3578
- id: "link-color-default-".concat(createId()),
3579
- sourcePortId: 'lc-default-source-port',
3580
- targetPortId: 'lc-default-target-port',
3609
+ id: "link-color-create-auto-".concat(createId()),
3610
+ sourcePortId: 'lc-create-auto-source-port',
3611
+ targetPortId: 'lc-create-auto-target-port',
3581
3612
  points: [],
3582
3613
  });
3583
3614
  },
3584
3615
  },
3585
3616
  {
3586
- id: 'add-link-custom-pair',
3587
- label: 'Add link (custom pair)',
3617
+ id: 'add-link-create-explicit',
3618
+ label: 'Add new explicit-stroke link',
3588
3619
  run: function (editor) {
3589
3620
  editor.addLink({
3590
- id: "link-color-custom-".concat(createId()),
3591
- sourcePortId: 'lc-custom-source-port',
3592
- targetPortId: 'lc-custom-target-port',
3621
+ id: "link-color-create-explicit-".concat(createId()),
3622
+ sourcePortId: 'lc-create-explicit-source-port',
3623
+ targetPortId: 'lc-create-explicit-target-port',
3593
3624
  points: [],
3625
+ style: {
3626
+ stroke: '#111827',
3627
+ strokeWidth: 2,
3628
+ },
3594
3629
  });
3595
3630
  },
3596
3631
  },
@@ -8041,6 +8076,10 @@ var DEFAULT_LINK_COLOR_POOL = [
8041
8076
  '#9c755f',
8042
8077
  '#bab0ab',
8043
8078
  ];
8079
+ var hasUsableLinkStroke = function (style) {
8080
+ var stroke = style === null || style === void 0 ? void 0 : style.stroke;
8081
+ return stroke !== undefined && stroke !== null && "".concat(stroke).trim().length > 0;
8082
+ };
8044
8083
  var normalizeLinkColorPoolPolicy = function (policy) {
8045
8084
  var _a;
8046
8085
  var enabled = Boolean(policy === null || policy === void 0 ? void 0 : policy.enabled);
@@ -8048,7 +8087,11 @@ var normalizeLinkColorPoolPolicy = function (policy) {
8048
8087
  .map(function (color) { return color.trim(); })
8049
8088
  .filter(function (color) { return color.length > 0; });
8050
8089
  var colors = normalizedColors.length > 0 ? normalizedColors : __spreadArray([], DEFAULT_LINK_COLOR_POOL, true);
8051
- return { enabled: enabled, colors: colors };
8090
+ return {
8091
+ enabled: enabled,
8092
+ colors: colors,
8093
+ assignOnLoadWhenMissingStroke: Boolean(policy === null || policy === void 0 ? void 0 : policy.assignOnLoadWhenMissingStroke),
8094
+ };
8052
8095
  };
8053
8096
  var DiagramEngine = /** @class */ (function () {
8054
8097
  function DiagramEngine(config) {
@@ -8094,8 +8137,9 @@ var DiagramEngine = /** @class */ (function () {
8094
8137
  DiagramEngine.prototype.load = function (state) {
8095
8138
  var _this = this;
8096
8139
  var patches = this.commandQueue.run(createLoadCommand(state), this.model);
8140
+ var linkColorPatches = this.assignOptionalLinkColorsOnLoad();
8097
8141
  var mutationPatches = this.mutationPipeline.run({
8098
- basePatches: patches,
8142
+ basePatches: __spreadArray(__spreadArray([], patches, true), linkColorPatches, true),
8099
8143
  layoutSteps: [function () { return _this.applyAllLayouts(); }],
8100
8144
  includeEmptyLinkRouting: true,
8101
8145
  });
@@ -9453,21 +9497,41 @@ var DiagramEngine = /** @class */ (function () {
9453
9497
  return this.linkRoutingService.routeLinksWithEmptyPoints();
9454
9498
  };
9455
9499
  DiagramEngine.prototype.applyOptionalLinkColor = function (link) {
9456
- if (!this.linkColorPoolPolicy.enabled)
9457
- return link;
9458
- var existingStyle = link.style;
9459
- var hasExplicitStroke = existingStyle !== undefined &&
9460
- Object.prototype.hasOwnProperty.call(existingStyle, 'stroke') &&
9461
- existingStyle.stroke !== undefined &&
9462
- existingStyle.stroke !== null &&
9463
- "".concat(existingStyle.stroke).trim().length > 0;
9464
- if (hasExplicitStroke)
9500
+ var style = this.resolveOptionalLinkColorStyle(link.style);
9501
+ if (style === link.style)
9465
9502
  return link;
9503
+ return __assign(__assign({}, link), { style: style });
9504
+ };
9505
+ DiagramEngine.prototype.assignOptionalLinkColorsOnLoad = function () {
9506
+ var _this = this;
9507
+ if (!this.linkColorPoolPolicy.enabled || !this.linkColorPoolPolicy.assignOnLoadWhenMissingStroke) {
9508
+ return [];
9509
+ }
9510
+ var patches = [];
9511
+ this.model.links.forEach(function (link) {
9512
+ var style = _this.resolveOptionalLinkColorStyle(link.style);
9513
+ if (style === link.style)
9514
+ return;
9515
+ link.style = style;
9516
+ patches.push(patchUpdate('link', link.id, { style: style }));
9517
+ });
9518
+ return patches;
9519
+ };
9520
+ DiagramEngine.prototype.resolveOptionalLinkColorStyle = function (style) {
9521
+ if (!this.linkColorPoolPolicy.enabled || hasUsableLinkStroke(style)) {
9522
+ return style;
9523
+ }
9524
+ var stroke = this.pickOptionalLinkColor();
9525
+ if (!stroke)
9526
+ return style;
9527
+ return __assign(__assign({}, (style !== null && style !== void 0 ? style : {})), { stroke: stroke });
9528
+ };
9529
+ DiagramEngine.prototype.pickOptionalLinkColor = function () {
9466
9530
  var colors = this.linkColorPoolPolicy.colors;
9467
9531
  if (colors.length === 0)
9468
- return link;
9532
+ return undefined;
9469
9533
  var index = Math.max(0, Math.min(colors.length - 1, Math.floor(Math.random() * colors.length)));
9470
- return __assign(__assign({}, link), { style: __assign(__assign({}, (existingStyle !== null && existingStyle !== void 0 ? existingStyle : {})), { stroke: colors[index] }) });
9534
+ return colors[index];
9471
9535
  };
9472
9536
  DiagramEngine.prototype.refreshLinksForRenderCycle = function () {
9473
9537
  if (this.linkRouteRefreshPolicy.mode !== 'redraw-two-endpoint-change')
@@ -16491,9 +16555,10 @@ var LinkColorPoolDemo = function () {
16491
16555
  var linkColorPoolPolicy = useMemo(function () {
16492
16556
  if (mode === 'off')
16493
16557
  return undefined;
16494
- if (mode === 'default')
16495
- return { enabled: true };
16496
- return { enabled: true, colors: customPool };
16558
+ if (mode === 'default') {
16559
+ return { enabled: true, assignOnLoadWhenMissingStroke: true };
16560
+ }
16561
+ return { enabled: true, assignOnLoadWhenMissingStroke: true, colors: customPool };
16497
16562
  }, [mode]);
16498
16563
  return (React.createElement(SimpleDemo, { demo: linkColorPoolDemoConfig, linkColorPoolPolicy: linkColorPoolPolicy, beforeStage: React.createElement("div", { style: {
16499
16564
  marginBottom: 12,
@@ -16505,9 +16570,10 @@ var LinkColorPoolDemo = function () {
16505
16570
  React.createElement("label", { htmlFor: "link-color-mode", style: { display: 'inline-flex', alignItems: 'center', gap: 8, fontWeight: 600 } },
16506
16571
  "Color Mode",
16507
16572
  React.createElement("select", { id: "link-color-mode", value: mode, onChange: function (event) { return setMode(event.target.value); } },
16508
- React.createElement("option", { value: "off" }, "Off (default behavior)"),
16509
- React.createElement("option", { value: "default" }, "Default 20-color pool"),
16510
- React.createElement("option", { value: "custom" }, "Custom pool (#0b7285, #e8590c, #5f3dc4)")))) }));
16573
+ React.createElement("option", { value: "off" }, "Off (no load fill)"),
16574
+ React.createElement("option", { value: "default" }, "Default pool load fill"),
16575
+ React.createElement("option", { value: "custom" }, "Custom pool load fill (#0b7285, #e8590c, #5f3dc4)"))),
16576
+ React.createElement("p", { style: { margin: '8px 0 0', fontSize: 13 } }, "Switching modes recreates the demo so the seeded loaded links can prove whether missing and blank strokes are filled, while explicit loaded strokes stay untouched.")) }));
16511
16577
  };
16512
16578
 
16513
16579
  var sidePositions = {