@chisquare-tech/origine-ngx-apps-code 0.11.0 → 0.11.2

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.
@@ -1692,7 +1692,9 @@ function matchesPattern(pattern, branch) {
1692
1692
  }
1693
1693
  // The web editor's commit box (prototype code_file "Commit and open PR", DEV-13): a message, and
1694
1694
  // either the branch itself or a new branch with a pull request. A branch whose rules block direct
1695
- // pushes only offers the second.
1695
+ // pushes only offers the second. The rules load asynchronously: until they have, nothing can be
1696
+ // committed (a quick commit straight to a protected branch was refused by the server); when they
1697
+ // cannot be loaded, the change goes to a new branch with a pull request, which any branch takes.
1696
1698
  class CommitBox {
1697
1699
  constructor() {
1698
1700
  this.api = inject(CodeApi);
@@ -1707,8 +1709,14 @@ class CommitBox {
1707
1709
  this.toNew = signal(false, ...(ngDevMode ? [{ debugName: "toNew" }] : /* istanbul ignore next */ []));
1708
1710
  this.newBranch = signal('', ...(ngDevMode ? [{ debugName: "newBranch" }] : /* istanbul ignore next */ []));
1709
1711
  this.rules = signal([], ...(ngDevMode ? [{ debugName: "rules" }] : /* istanbul ignore next */ []));
1710
- /** Direct commits are refused: the rules block direct pushes, or require signed commits (a browser commit is unsigned). */
1711
- this.blocked = computed(() => this.rules().some((r) => (r.blockDirectPush || r.requireSignedCommits) && matchesPattern(r.pattern, this.branch())), ...(ngDevMode ? [{ debugName: "blocked" }] : /* istanbul ignore next */ []));
1712
+ /** Whether the branch's rules are known yet. */
1713
+ this.rulesState = signal('loading', ...(ngDevMode ? [{ debugName: "rulesState" }] : /* istanbul ignore next */ []));
1714
+ /**
1715
+ * Direct commits are refused (or may be): the rules block direct pushes, or require signed
1716
+ * commits (a browser commit is unsigned), or they could not be loaded.
1717
+ */
1718
+ this.blocked = computed(() => this.rulesState() === 'failed' || this.rules().some((r) => (r.blockDirectPush || r.requireSignedCommits) && matchesPattern(r.pattern, this.branch())), ...(ngDevMode ? [{ debugName: "blocked" }] : /* istanbul ignore next */ []));
1719
+ this.rulesFor = null;
1712
1720
  effect(() => {
1713
1721
  const m = this.defaultMessage();
1714
1722
  untracked(() => this.message.set(m));
@@ -1719,20 +1727,45 @@ class CommitBox {
1719
1727
  if (!p || !repo)
1720
1728
  return;
1721
1729
  untracked(() => {
1722
- this.api.protections(p.id, repo).subscribe({ next: (r) => this.rules.set(r), error: () => undefined });
1730
+ this.rulesFor = { project: p.id, repo };
1731
+ this.loadRules();
1723
1732
  const me = (this.host.people().find((x) => x.id === this.host.meId())?.name || 'patch').toLowerCase().replace(/[^a-z0-9]+/g, '-').replace(/^-|-$/g, '') || 'patch';
1724
1733
  this.newBranch.set(`${me}/patch-${Math.floor(Date.now() / 1000) % 100000}`);
1725
1734
  });
1726
1735
  });
1727
1736
  }
1737
+ loadRules() {
1738
+ const at = this.rulesFor;
1739
+ if (!at)
1740
+ return;
1741
+ this.rulesState.set('loading');
1742
+ this.api.protections(at.project, at.repo).subscribe({
1743
+ next: (r) => {
1744
+ if (this.rulesFor !== at)
1745
+ return;
1746
+ this.rules.set(r);
1747
+ this.rulesState.set('loaded');
1748
+ },
1749
+ error: () => {
1750
+ if (this.rulesFor === at)
1751
+ this.rulesState.set('failed');
1752
+ },
1753
+ });
1754
+ }
1728
1755
  send() {
1756
+ if (this.rulesState() === 'loading')
1757
+ return;
1729
1758
  const toNew = this.toNew() || this.blocked();
1730
1759
  this.commit.emit({ message: this.message().trim(), newBranch: toNew ? this.newBranch().trim() : undefined });
1731
1760
  }
1732
1761
  static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.2.12", ngImport: i0, type: CommitBox, deps: [], target: i0.ɵɵFactoryTarget.Component }); }
1733
1762
  static { this.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "17.0.0", version: "21.2.12", type: CommitBox, isStandalone: true, selector: "o-commit-box", inputs: { repo: { classPropertyName: "repo", publicName: "repo", isSignal: true, isRequired: true, transformFunction: null }, branch: { classPropertyName: "branch", publicName: "branch", isSignal: true, isRequired: true, transformFunction: null }, defaultMessage: { classPropertyName: "defaultMessage", publicName: "defaultMessage", isSignal: true, isRequired: false, transformFunction: null }, busy: { classPropertyName: "busy", publicName: "busy", isSignal: true, isRequired: false, transformFunction: null } }, outputs: { commit: "commit", cancel: "cancel" }, ngImport: i0, template: `
1734
1763
  <div class="o-col" style="gap:10px" data-testid="commit-box">
1735
- @if (blocked()) {<div class="o-note o-blu">Your change is committed to a new branch with a pull request because <b>{{ branch() }}</b> is protected.</div>}
1764
+ @switch (rulesState()) {
1765
+ @case ('loading') {<div class="o-note" role="status" data-testid="commit-rules">Checking the rules of {{ branch() }}…</div>}
1766
+ @case ('failed') {<div class="o-note o-amb" role="status">Could not check the rules of <b>{{ branch() }}</b>, so your change is committed to a new branch with a pull request. <button type="button" class="o-lnk" (click)="loadRules()" data-testid="commit-rules-retry">Retry</button></div>}
1767
+ @default {@if (blocked()) {<div class="o-note o-blu">Your change is committed to a new branch with a pull request because <b>{{ branch() }}</b> is protected.</div>}}
1768
+ }
1736
1769
  <div class="o-fld"><label for="cb-msg">Commit message</label><input id="cb-msg" class="o-in" [ngModel]="message()" (ngModelChange)="message.set($event)" data-testid="commit-message" /></div>
1737
1770
  @if (!blocked()) {
1738
1771
  <label class="o-flex o-sm"><input type="radio" name="cb-where" [checked]="!toNew()" (change)="toNew.set(false)" /> Commit directly to <b class="o-mono">{{ branch() }}</b></label>
@@ -1743,7 +1776,7 @@ class CommitBox {
1743
1776
  }
1744
1777
  <div class="o-flex">
1745
1778
  <button type="button" class="o-btn o-sm o-r" (click)="cancel.emit()">Cancel</button>
1746
- <button type="button" class="o-btn o-sm o-pri" [disabled]="busy() || !message().trim() || ((toNew() || blocked()) && !newBranch().trim())" (click)="send()" data-testid="commit-submit">{{ toNew() || blocked() ? 'Commit and open PR' : 'Commit changes' }}</button>
1779
+ <button type="button" class="o-btn o-sm o-pri" [disabled]="busy() || rulesState() === 'loading' || !message().trim() || ((toNew() || blocked()) && !newBranch().trim())" (click)="send()" data-testid="commit-submit">{{ toNew() || blocked() ? 'Commit and open PR' : 'Commit changes' }}</button>
1747
1780
  </div>
1748
1781
  </div>
1749
1782
  `, isInline: true, dependencies: [{ kind: "ngmodule", type: FormsModule }, { kind: "directive", type: i1.DefaultValueAccessor, selector: "input:not([type=checkbox])[formControlName],textarea[formControlName],input:not([type=checkbox])[formControl],textarea[formControl],input:not([type=checkbox])[ngModel],textarea[ngModel],[ngDefaultControl]" }, { kind: "directive", type: i1.NgControlStatus, selector: "[formControlName],[ngModel],[formControl]" }, { kind: "directive", type: i1.NgModel, selector: "[ngModel]:not([formControlName]):not([formControl])", inputs: ["name", "disabled", "ngModel", "ngModelOptions"], outputs: ["ngModelChange"], exportAs: ["ngModel"] }], changeDetection: i0.ChangeDetectionStrategy.OnPush }); }
@@ -1756,7 +1789,11 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.12", ngImpo
1756
1789
  changeDetection: ChangeDetectionStrategy.OnPush,
1757
1790
  template: `
1758
1791
  <div class="o-col" style="gap:10px" data-testid="commit-box">
1759
- @if (blocked()) {<div class="o-note o-blu">Your change is committed to a new branch with a pull request because <b>{{ branch() }}</b> is protected.</div>}
1792
+ @switch (rulesState()) {
1793
+ @case ('loading') {<div class="o-note" role="status" data-testid="commit-rules">Checking the rules of {{ branch() }}…</div>}
1794
+ @case ('failed') {<div class="o-note o-amb" role="status">Could not check the rules of <b>{{ branch() }}</b>, so your change is committed to a new branch with a pull request. <button type="button" class="o-lnk" (click)="loadRules()" data-testid="commit-rules-retry">Retry</button></div>}
1795
+ @default {@if (blocked()) {<div class="o-note o-blu">Your change is committed to a new branch with a pull request because <b>{{ branch() }}</b> is protected.</div>}}
1796
+ }
1760
1797
  <div class="o-fld"><label for="cb-msg">Commit message</label><input id="cb-msg" class="o-in" [ngModel]="message()" (ngModelChange)="message.set($event)" data-testid="commit-message" /></div>
1761
1798
  @if (!blocked()) {
1762
1799
  <label class="o-flex o-sm"><input type="radio" name="cb-where" [checked]="!toNew()" (change)="toNew.set(false)" /> Commit directly to <b class="o-mono">{{ branch() }}</b></label>
@@ -1767,7 +1804,7 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.12", ngImpo
1767
1804
  }
1768
1805
  <div class="o-flex">
1769
1806
  <button type="button" class="o-btn o-sm o-r" (click)="cancel.emit()">Cancel</button>
1770
- <button type="button" class="o-btn o-sm o-pri" [disabled]="busy() || !message().trim() || ((toNew() || blocked()) && !newBranch().trim())" (click)="send()" data-testid="commit-submit">{{ toNew() || blocked() ? 'Commit and open PR' : 'Commit changes' }}</button>
1807
+ <button type="button" class="o-btn o-sm o-pri" [disabled]="busy() || rulesState() === 'loading' || !message().trim() || ((toNew() || blocked()) && !newBranch().trim())" (click)="send()" data-testid="commit-submit">{{ toNew() || blocked() ? 'Commit and open PR' : 'Commit changes' }}</button>
1771
1808
  </div>
1772
1809
  </div>
1773
1810
  `,
@@ -1950,7 +1987,7 @@ class FilePage extends RepoPage {
1950
1987
  @if (b.markdown) {
1951
1988
  <div class="o-seg" role="group" aria-label="View"><button type="button" [class.o-on]="view() === 'preview'" (click)="view.set('preview')">Preview</button><button type="button" [class.o-on]="view() === 'code'" (click)="view.set('code')">Code</button></div>
1952
1989
  }
1953
- @if (!b.binary && !b.truncated) {<button type="button" class="o-btn o-xs" [class.o-on]="blaming()" [attr.aria-pressed]="blaming()" (click)="toggleBlame()">Blame</button>}
1990
+ @if (!b.binary && !b.truncated && !b.lfs) {<button type="button" class="o-btn o-xs" [class.o-on]="blaming()" [attr.aria-pressed]="blaming()" (click)="toggleBlame()">Blame</button>}
1954
1991
  @if (b.rawUrl) {<a class="o-btn o-xs" [href]="b.rawUrl" target="_blank" rel="noopener">Raw</a>}
1955
1992
  @if (!b.binary) {<button type="button" class="o-btn o-xs" (click)="copyText()">{{ copied() ? 'Copied' : 'Copy' }}</button>}
1956
1993
  @if (b.downloadUrl) {<a class="o-btn o-xs" [href]="b.downloadUrl">Download</a>}
@@ -2036,7 +2073,7 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.12", ngImpo
2036
2073
  @if (b.markdown) {
2037
2074
  <div class="o-seg" role="group" aria-label="View"><button type="button" [class.o-on]="view() === 'preview'" (click)="view.set('preview')">Preview</button><button type="button" [class.o-on]="view() === 'code'" (click)="view.set('code')">Code</button></div>
2038
2075
  }
2039
- @if (!b.binary && !b.truncated) {<button type="button" class="o-btn o-xs" [class.o-on]="blaming()" [attr.aria-pressed]="blaming()" (click)="toggleBlame()">Blame</button>}
2076
+ @if (!b.binary && !b.truncated && !b.lfs) {<button type="button" class="o-btn o-xs" [class.o-on]="blaming()" [attr.aria-pressed]="blaming()" (click)="toggleBlame()">Blame</button>}
2040
2077
  @if (b.rawUrl) {<a class="o-btn o-xs" [href]="b.rawUrl" target="_blank" rel="noopener">Raw</a>}
2041
2078
  @if (!b.binary) {<button type="button" class="o-btn o-xs" (click)="copyText()">{{ copied() ? 'Copied' : 'Copy' }}</button>}
2042
2079
  @if (b.downloadUrl) {<a class="o-btn o-xs" [href]="b.downloadUrl">Download</a>}