@primer/view-components 0.0.93 → 0.0.95

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 (24) hide show
  1. package/app/assets/javascripts/primer_view_components.js +1 -1
  2. package/app/assets/javascripts/primer_view_components.js.map +1 -1
  3. package/app/components/primer/alpha/{modal-dialog-element.d.ts → modal_dialog.d.ts} +0 -0
  4. package/app/components/primer/alpha/{modal-dialog-element.js → modal_dialog.js} +0 -0
  5. package/app/components/primer/alpha/{toggle-switch-element.d.ts → toggle_switch.d.ts} +0 -0
  6. package/app/components/primer/alpha/{toggle-switch-element.js → toggle_switch.js} +7 -2
  7. package/app/components/primer/alpha/{tool-tip-element.d.ts → tool_tip.d.ts} +0 -0
  8. package/app/components/primer/alpha/{tool-tip-element.js → tool_tip.js} +17 -2
  9. package/app/components/primer/{clipboard_copy_component.d.ts → clipboard_copy.d.ts} +0 -0
  10. package/app/components/primer/{clipboard_copy_component.js → clipboard_copy.js} +1 -1
  11. package/app/components/primer/experimental/{overflow-menu-element.d.ts → action_bar.d.ts} +1 -0
  12. package/app/components/primer/experimental/action_bar.js +141 -0
  13. package/app/components/primer/primer.d.ts +7 -7
  14. package/app/components/primer/primer.js +7 -7
  15. package/package.json +9 -9
  16. package/static/arguments.json +2042 -0
  17. package/static/audited_at.json +84 -0
  18. package/static/constants.json +978 -0
  19. package/static/statuses.json +84 -0
  20. package/app/components/primer/experimental/action-bar-element.d.ts +0 -14
  21. package/app/components/primer/experimental/action-bar-element.js +0 -139
  22. package/app/components/primer/experimental/action-menu-element.d.ts +0 -31
  23. package/app/components/primer/experimental/action-menu-element.js +0 -334
  24. package/app/components/primer/experimental/overflow-menu-element.js +0 -113
@@ -1,5 +1,3 @@
1
- /* eslint-disable custom-elements/expose-class-on-global */
2
- /* eslint-disable custom-elements/define-tag-after-class-definition */
3
1
  var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
4
2
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
5
3
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
@@ -104,6 +102,9 @@ let ToggleSwitchElement = class ToggleSwitchElement extends HTMLElement {
104
102
  const response = await fetch(this.src, {
105
103
  credentials: 'same-origin',
106
104
  method: 'POST',
105
+ headers: {
106
+ 'Requested-With': 'XMLHttpRequest'
107
+ },
107
108
  body
108
109
  });
109
110
  if (response.ok) {
@@ -135,3 +136,7 @@ ToggleSwitchElement = __decorate([
135
136
  controller
136
137
  ], ToggleSwitchElement);
137
138
  export { ToggleSwitchElement };
139
+ if (!window.customElements.get('toggle-switch')) {
140
+ window.ToggleSwitchElement = ToggleSwitchElement;
141
+ window.customElements.define('toggle-switch', ToggleSwitchElement);
142
+ }
@@ -247,7 +247,12 @@ class ToolTipElement extends HTMLElement {
247
247
  if (this.type === 'label') {
248
248
  let labelledBy = this.control.getAttribute('aria-labelledby');
249
249
  if (labelledBy) {
250
- labelledBy = `${labelledBy} ${this.id}`;
250
+ if (!labelledBy.split(' ').includes(this.id)) {
251
+ labelledBy = `${labelledBy} ${this.id}`;
252
+ }
253
+ else {
254
+ labelledBy = `${labelledBy}`;
255
+ }
251
256
  }
252
257
  else {
253
258
  labelledBy = this.id;
@@ -258,7 +263,17 @@ class ToolTipElement extends HTMLElement {
258
263
  }
259
264
  else {
260
265
  let describedBy = this.control.getAttribute('aria-describedby');
261
- describedBy ? (describedBy = `${describedBy} ${this.id}`) : (describedBy = this.id);
266
+ if (describedBy) {
267
+ if (!describedBy.split(' ').includes(this.id)) {
268
+ describedBy = `${describedBy} ${this.id}`;
269
+ }
270
+ else {
271
+ describedBy = `${describedBy}`;
272
+ }
273
+ }
274
+ else {
275
+ describedBy = this.id;
276
+ }
262
277
  this.control.setAttribute('aria-describedby', describedBy);
263
278
  }
264
279
  }
@@ -23,7 +23,7 @@ function showCheck(button) {
23
23
  showSVG(checkIcon);
24
24
  }
25
25
  const clipboardCopyElementTimers = new WeakMap();
26
- document.addEventListener('clipboard-copy', function ({ target }) {
26
+ document.addEventListener('clipboard-copy', ({ target }) => {
27
27
  if (!(target instanceof HTMLElement))
28
28
  return;
29
29
  if (!target.hasAttribute('data-view-component'))
@@ -2,6 +2,7 @@ export declare class ActionBarElement extends HTMLElement {
2
2
  #private;
3
3
  items: HTMLElement[];
4
4
  menuItems: HTMLElement[];
5
+ itemContainer: HTMLElement;
5
6
  moreMenu: HTMLElement;
6
7
  connectedCallback(): void;
7
8
  disconnectedCallback(): void;
@@ -0,0 +1,141 @@
1
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
2
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
3
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
4
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
5
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
6
+ };
7
+ var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
8
+ if (kind === "m") throw new TypeError("Private method is not writable");
9
+ if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
10
+ if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
11
+ return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
12
+ };
13
+ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
14
+ if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
15
+ if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
16
+ return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
17
+ };
18
+ var _ActionBarElement_instances, _ActionBarElement_observer, _ActionBarElement_initialBarWidth, _ActionBarElement_previousBarWidth, _ActionBarElement_itemGap, _ActionBarElement_focusController, _ActionBarElement_focusSettings, _ActionBarElement_availableSpace, _ActionBarElement_shrinking, _ActionBarElement_growing;
19
+ import { controller, targets, target } from '@github/catalyst';
20
+ import { focusZone, FocusKeys } from '@primer/behaviors';
21
+ let ActionBarElement = class ActionBarElement extends HTMLElement {
22
+ constructor() {
23
+ super(...arguments);
24
+ _ActionBarElement_instances.add(this);
25
+ _ActionBarElement_observer.set(this, void 0);
26
+ _ActionBarElement_initialBarWidth.set(this, void 0);
27
+ _ActionBarElement_previousBarWidth.set(this, void 0);
28
+ _ActionBarElement_itemGap.set(this, void 0);
29
+ _ActionBarElement_focusController.set(this, void 0);
30
+ _ActionBarElement_focusSettings.set(this, {
31
+ bindKeys: FocusKeys.ArrowHorizontal | FocusKeys.HomeAndEnd
32
+ });
33
+ }
34
+ connectedCallback() {
35
+ var _a, _b, _c;
36
+ __classPrivateFieldSet(this, _ActionBarElement_initialBarWidth, this.offsetWidth, "f");
37
+ __classPrivateFieldSet(this, _ActionBarElement_previousBarWidth, this.offsetWidth, "f");
38
+ __classPrivateFieldSet(this, _ActionBarElement_itemGap, parseInt((_a = window.getComputedStyle(this.itemContainer)) === null || _a === void 0 ? void 0 : _a.columnGap, 10) || 0, "f");
39
+ // Calculate the width of all the items before hiding anything
40
+ for (const item of this.items) {
41
+ const width = item.getBoundingClientRect().width;
42
+ const marginLeft = parseInt((_b = window.getComputedStyle(item)) === null || _b === void 0 ? void 0 : _b.marginLeft, 10);
43
+ const marginRight = parseInt((_c = window.getComputedStyle(item)) === null || _c === void 0 ? void 0 : _c.marginRight, 10);
44
+ item.setAttribute('data-offset-width', `${width + marginLeft + marginRight}`);
45
+ }
46
+ __classPrivateFieldSet(this, _ActionBarElement_focusController, focusZone(this, __classPrivateFieldGet(this, _ActionBarElement_focusSettings, "f")), "f");
47
+ this.style.maxWidth = `${this.itemContainer.offsetWidth}px`;
48
+ // Calculate visible items on page load until there is enough space
49
+ // to show all items or the first item is hidden
50
+ while (__classPrivateFieldGet(this, _ActionBarElement_instances, "m", _ActionBarElement_availableSpace).call(this) < this.moreMenu.offsetWidth + __classPrivateFieldGet(this, _ActionBarElement_itemGap, "f") * 0.5 && !this.items[0].hidden) {
51
+ __classPrivateFieldGet(this, _ActionBarElement_instances, "m", _ActionBarElement_shrinking).call(this);
52
+ }
53
+ this.style.overflow = 'visible';
54
+ __classPrivateFieldSet(this, _ActionBarElement_observer, new ResizeObserver(entries => {
55
+ for (const entry of entries) {
56
+ // Only recalculate if the bar width changed
57
+ if (__classPrivateFieldGet(this, _ActionBarElement_initialBarWidth, "f") !== entry.contentRect.width) {
58
+ if (entry.contentRect.width < __classPrivateFieldGet(this, _ActionBarElement_previousBarWidth, "f")) {
59
+ __classPrivateFieldGet(this, _ActionBarElement_instances, "m", _ActionBarElement_shrinking).call(this);
60
+ }
61
+ else {
62
+ __classPrivateFieldGet(this, _ActionBarElement_instances, "m", _ActionBarElement_growing).call(this);
63
+ }
64
+ __classPrivateFieldSet(this, _ActionBarElement_previousBarWidth, entry.contentRect.width, "f");
65
+ }
66
+ }
67
+ }), "f");
68
+ __classPrivateFieldGet(this, _ActionBarElement_observer, "f").observe(this);
69
+ }
70
+ disconnectedCallback() {
71
+ var _a;
72
+ (_a = __classPrivateFieldGet(this, _ActionBarElement_focusController, "f")) === null || _a === void 0 ? void 0 : _a.abort();
73
+ __classPrivateFieldGet(this, _ActionBarElement_observer, "f").unobserve(this);
74
+ }
75
+ };
76
+ _ActionBarElement_observer = new WeakMap(), _ActionBarElement_initialBarWidth = new WeakMap(), _ActionBarElement_previousBarWidth = new WeakMap(), _ActionBarElement_itemGap = new WeakMap(), _ActionBarElement_focusController = new WeakMap(), _ActionBarElement_focusSettings = new WeakMap(), _ActionBarElement_instances = new WeakSet(), _ActionBarElement_availableSpace = function _ActionBarElement_availableSpace() {
77
+ // Get the offset of the item container from the container edge
78
+ return this.offsetWidth - this.itemContainer.offsetWidth;
79
+ }, _ActionBarElement_shrinking = function _ActionBarElement_shrinking() {
80
+ var _a;
81
+ if (this.items[0].hidden) {
82
+ return;
83
+ }
84
+ const gapSpace = __classPrivateFieldGet(this, _ActionBarElement_itemGap, "f") * 0.5;
85
+ if (__classPrivateFieldGet(this, _ActionBarElement_instances, "m", _ActionBarElement_availableSpace).call(this) < this.moreMenu.offsetWidth + gapSpace) {
86
+ const visibleItems = this.items.filter(item => !item.hidden);
87
+ const hiddenMenuItems = this.menuItems.filter(item => item.hidden);
88
+ visibleItems[visibleItems.length - 1].hidden = true;
89
+ hiddenMenuItems[hiddenMenuItems.length - 1].hidden = false;
90
+ if (this.moreMenu.hidden) {
91
+ this.moreMenu.hidden = false;
92
+ }
93
+ // Reset focus controller
94
+ (_a = __classPrivateFieldGet(this, _ActionBarElement_focusController, "f")) === null || _a === void 0 ? void 0 : _a.abort();
95
+ __classPrivateFieldSet(this, _ActionBarElement_focusController, focusZone(this, __classPrivateFieldGet(this, _ActionBarElement_focusSettings, "f")), "f");
96
+ }
97
+ }, _ActionBarElement_growing = function _ActionBarElement_growing() {
98
+ var _a;
99
+ if (this.moreMenu.hidden) {
100
+ return;
101
+ }
102
+ const gapSpace = __classPrivateFieldGet(this, _ActionBarElement_itemGap, "f") * 0.5;
103
+ const hiddenItems = this.items.filter(item => item.hidden);
104
+ if (hiddenItems.length === 0) {
105
+ return;
106
+ }
107
+ const hiddenItemWidth = Number(hiddenItems[0].getAttribute('data-offset-width'));
108
+ if (__classPrivateFieldGet(this, _ActionBarElement_instances, "m", _ActionBarElement_availableSpace).call(this) >= this.moreMenu.offsetWidth + hiddenItemWidth + gapSpace) {
109
+ const visibleMenuItems = this.menuItems.filter(item => !item.hidden);
110
+ hiddenItems[0].hidden = false;
111
+ visibleMenuItems[0].hidden = true;
112
+ if (hiddenItems.length === 2) {
113
+ hiddenItems[1].hidden = false;
114
+ visibleMenuItems[1].hidden = true;
115
+ }
116
+ // If there was only one item left, hide the more menu
117
+ if (hiddenItems.length <= 2) {
118
+ this.moreMenu.hidden = true;
119
+ }
120
+ // Reset focus controller
121
+ (_a = __classPrivateFieldGet(this, _ActionBarElement_focusController, "f")) === null || _a === void 0 ? void 0 : _a.abort();
122
+ __classPrivateFieldSet(this, _ActionBarElement_focusController, focusZone(this, __classPrivateFieldGet(this, _ActionBarElement_focusSettings, "f")), "f");
123
+ }
124
+ };
125
+ __decorate([
126
+ targets
127
+ ], ActionBarElement.prototype, "items", void 0);
128
+ __decorate([
129
+ targets
130
+ ], ActionBarElement.prototype, "menuItems", void 0);
131
+ __decorate([
132
+ target
133
+ ], ActionBarElement.prototype, "itemContainer", void 0);
134
+ __decorate([
135
+ target
136
+ ], ActionBarElement.prototype, "moreMenu", void 0);
137
+ ActionBarElement = __decorate([
138
+ controller
139
+ ], ActionBarElement);
140
+ export { ActionBarElement };
141
+ window.ActionBarElement = ActionBarElement;
@@ -1,10 +1,10 @@
1
+ import './alpha/modal_dialog';
2
+ import './alpha/toggle_switch';
3
+ import './alpha/tool_tip';
1
4
  import './beta/auto_complete/auto_complete';
2
- import './clipboard_copy_component';
5
+ import './clipboard_copy';
6
+ import './dropdown';
7
+ import './image_crop';
8
+ import './local_time';
3
9
  import './tab_container_component';
4
10
  import './time_ago_component';
5
- import './local_time';
6
- import './image_crop';
7
- import './dropdown';
8
- import './alpha/toggle-switch-element';
9
- import './alpha/tool-tip-element';
10
- import './alpha/modal-dialog-element';
@@ -1,10 +1,10 @@
1
+ import './alpha/modal_dialog';
2
+ import './alpha/toggle_switch';
3
+ import './alpha/tool_tip';
1
4
  import './beta/auto_complete/auto_complete';
2
- import './clipboard_copy_component';
5
+ import './clipboard_copy';
6
+ import './dropdown';
7
+ import './image_crop';
8
+ import './local_time';
3
9
  import './tab_container_component';
4
10
  import './time_ago_component';
5
- import './local_time';
6
- import './image_crop';
7
- import './dropdown';
8
- import './alpha/toggle-switch-element';
9
- import './alpha/tool-tip-element';
10
- import './alpha/modal-dialog-element';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@primer/view-components",
3
- "version": "0.0.93",
3
+ "version": "0.0.95",
4
4
  "description": "ViewComponents for the Primer Design System",
5
5
  "main": "app/assets/javascripts/primer_view_components.js",
6
6
  "module": "app/components/primer/primer.js",
@@ -20,6 +20,7 @@
20
20
  "url": "https://github.com/primer/view_components/issues"
21
21
  },
22
22
  "files": [
23
+ "static/*.json",
23
24
  "app/assets/**/*",
24
25
  "app/components/primer/**/*.js",
25
26
  "app/components/primer/**/*.css",
@@ -30,8 +31,8 @@
30
31
  "build:docs": "cd docs && yarn gatsby build --prefix-paths",
31
32
  "build:docs:preview": "cd docs && yarn gatsby build",
32
33
  "prepare": "rm -rf docs/static && mkdir -p docs/static && yarn build:js && yarn build:css && cp app/assets/**/primer_view_components.* docs/static/",
33
- "lint": "eslint 'app/components/**/*.ts' demo/.storybook",
34
- "lint:fix": "eslint 'app/components/**/*.ts' demo/.storybook --fix",
34
+ "lint": "eslint 'app/components/**/*.ts'",
35
+ "lint:fix": "eslint 'app/components/**/*.ts' --fix",
35
36
  "changeset:version": "changeset version && script/version",
36
37
  "build:js": "tsc && rollup -c",
37
38
  "build:css": "postcss -o app/assets/styles/primer_view_components.css app/components/primer/primer.pcss"
@@ -45,23 +46,25 @@
45
46
  "@github/mini-throttle": "^2.1.0",
46
47
  "@github/tab-container-element": "^3.1.2",
47
48
  "@github/time-elements": "^3.1.2",
48
- "@primer/behaviors": "^1.1.3"
49
+ "@primer/behaviors": "^1.2.0"
49
50
  },
50
51
  "devDependencies": {
51
52
  "@changesets/changelog-github": "^0.4.6",
52
53
  "@changesets/cli": "^2.24.1",
53
54
  "@github/prettier-config": "0.0.4",
54
- "@primer/css": "20.4.4",
55
+ "@primer/css": "20.4.5",
55
56
  "@primer/primitives": "^7.9.0",
56
57
  "@rollup/plugin-node-resolve": "^13.3.0",
57
58
  "@rollup/plugin-typescript": "^8.3.3",
58
59
  "@typescript-eslint/eslint-plugin": "^5.31.0",
59
60
  "@typescript-eslint/parser": "^5.31.0",
61
+ "chokidar-cli": "^3.0.0",
60
62
  "cssnano": "^5.1.13",
61
63
  "eslint": "^8.20.0",
62
64
  "eslint-plugin-custom-elements": "^0.0.6",
63
65
  "eslint-plugin-github": "^4.3.7",
64
66
  "eslint-plugin-prettier": "^4.2.1",
67
+ "markdownlint-cli": "^0.32.2",
65
68
  "mocha": "^10.0.0",
66
69
  "postcss": "^8.4.16",
67
70
  "postcss-cli": "^10.0.0",
@@ -74,8 +77,5 @@
74
77
  "tslib": "^2.4.0",
75
78
  "typescript": "^4.7.4"
76
79
  },
77
- "prettier": "@github/prettier-config",
78
- "storybook": {
79
- "url": "https://primer.style/view-components/stories/"
80
- }
80
+ "prettier": "@github/prettier-config"
81
81
  }